mirror of
https://github.com/open-webui/computer.git
synced 2026-11-24 06:20:21 -05:00
refac
This commit is contained in:
1 parent
936a614957
commit
c1e8636dd1
4 files changed
+52
-4
No files matched your search
@@ -197,9 +197,9 @@
|
||||
}
|
||||
|
||||
function handlePathKeydown(e: KeyboardEvent) {
|
||||
if (e.key === 'Enter') { e.preventDefault(); confirmPath(); }
|
||||
else if (e.key === 'Escape') { e.preventDefault(); cancelEditing(); }
|
||||
else if (e.key === 'Tab') { e.preventDefault(); tabComplete(); }
|
||||
if (e.key === 'Enter') { e.preventDefault(); e.stopPropagation(); confirmPath(); }
|
||||
else if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); cancelEditing(); }
|
||||
else if (e.key === 'Tab') { e.preventDefault(); e.stopPropagation(); tabComplete(); }
|
||||
}
|
||||
|
||||
function handleKeydown(e: KeyboardEvent) {
|
||||
|
||||
@@ -154,7 +154,12 @@
|
||||
item: any;
|
||||
}
|
||||
|
||||
type DisplayItem = ToolGroup | MessageItem;
|
||||
interface ArtifactItem {
|
||||
type: 'artifact_item';
|
||||
item: any;
|
||||
}
|
||||
|
||||
type DisplayItem = ToolGroup | MessageItem | ArtifactItem;
|
||||
|
||||
const displayItems = $derived.by((): DisplayItem[] => {
|
||||
if (!output?.length) return [];
|
||||
@@ -186,6 +191,9 @@
|
||||
} else if (item.type === 'message') {
|
||||
flushGroup();
|
||||
items.push({ type: 'message_item', item });
|
||||
} else if (item.type === 'artifact') {
|
||||
flushGroup();
|
||||
items.push({ type: 'artifact_item', item });
|
||||
}
|
||||
// function_call_output items are handled via outputMap, skip standalone render
|
||||
}
|
||||
@@ -269,6 +277,20 @@
|
||||
{#if displayItem.type === 'message_item'}
|
||||
<MarkdownRenderer content={displayItem.item.content?.map((c: any) => c.text).join('') || ''} />
|
||||
|
||||
{:else if displayItem.type === 'artifact_item'}
|
||||
{@const artifact = displayItem.item}
|
||||
<div class="w-full my-2 rounded-xl border border-gray-200 dark:border-white/10">
|
||||
<div class="flex items-center gap-2 px-4 py-2.5 border-b border-gray-200 dark:border-white/10">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-4 text-gray-400 dark:text-gray-500 shrink-0">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9Z" />
|
||||
</svg>
|
||||
<span class="text-sm font-medium text-gray-700 dark:text-gray-200">{artifact.title || 'Artifact'}</span>
|
||||
</div>
|
||||
<div class="px-4 py-3 max-h-[32rem] overflow-y-auto">
|
||||
<MarkdownRenderer content={artifact.content || ''} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{:else if displayItem.type === 'tool_group'}
|
||||
{@const calls = displayItem.calls}
|
||||
{@const outputs = displayItem.outputs}
|
||||
|
||||
@@ -353,6 +353,27 @@ async def run_chat_task(
|
||||
await emit(output=result_item)
|
||||
_sync_state()
|
||||
|
||||
# Artifact: write to artifacts dir and emit card
|
||||
args = event["arguments"]
|
||||
artifact_type = args.get("artifact_type", "")
|
||||
if artifact_type:
|
||||
from datetime import datetime, timezone
|
||||
ts = datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%S")
|
||||
artifact_dir = Path(workspace) / ".cptr" / "artifacts" / chat_id
|
||||
artifact_dir.mkdir(parents=True, exist_ok=True)
|
||||
artifact_path = artifact_dir / f"{ts}_{artifact_type}.md"
|
||||
artifact_path.write_text(args.get("content", ""))
|
||||
artifact_item = {
|
||||
"type": "artifact",
|
||||
"artifact_type": artifact_type,
|
||||
"title": Path(args.get("path", artifact_type)).stem.replace("_", " ").title(),
|
||||
"content": args.get("content", ""),
|
||||
"path": str(artifact_path.relative_to(Path(workspace))),
|
||||
}
|
||||
output_items.append(artifact_item)
|
||||
await emit(output=artifact_item)
|
||||
_sync_state()
|
||||
|
||||
# Append to messages for next iteration
|
||||
_append_tool_to_messages(messages, event, result, provider)
|
||||
restart = True
|
||||
|
||||
@@ -263,13 +263,18 @@ async def create_file(
|
||||
path: str,
|
||||
content: str,
|
||||
overwrite: bool = False,
|
||||
artifact_type: str = "",
|
||||
*,
|
||||
workspace: str,
|
||||
) -> str:
|
||||
"""Create a new file. Errors if file already exists unless overwrite is true.
|
||||
For non-trivial tasks (multi-file changes, ambiguous requirements, architectural decisions),
|
||||
create an implementation plan first with artifact_type='implementation_plan'. Write the plan
|
||||
as markdown, then wait for the user to review before making changes.
|
||||
:param path: Path relative to workspace root.
|
||||
:param content: File contents to write.
|
||||
:param overwrite: Set to true to overwrite an existing file.
|
||||
:param artifact_type: Set to 'implementation_plan' to present a plan for user review before coding.
|
||||
"""
|
||||
full = _resolve_path(path, workspace)
|
||||
if full.is_file() and not overwrite:
|
||||
|
||||
Reference in new issue
Block a user