mirror of
https://github.com/open-webui/computer.git
synced 2026-11-21 05:52:14 +03:00
refac
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
<script lang="ts">
|
||||
import MarkdownRenderer from '$lib/components/markdown/MarkdownRenderer.svelte';
|
||||
|
||||
let { content }: { content: string } = $props();
|
||||
</script>
|
||||
|
||||
<div class="h-full overflow-y-auto px-6 py-5">
|
||||
<div class="mx-auto max-w-3xl"><MarkdownRenderer {content} /></div>
|
||||
</div>
|
||||
@@ -8,7 +8,7 @@
|
||||
import MessageTimestamp from './MessageTimestamp.svelte';
|
||||
import ReasoningCollapsible from './ReasoningCollapsible.svelte';
|
||||
import ToolCallCollapsible from './ToolCallCollapsible.svelte';
|
||||
import { currentWorkspace, openArtifactTab, openFileTab } from '$lib/stores';
|
||||
import { currentWorkspace, openFileTab } from '$lib/stores';
|
||||
import { ttsConfigured, ttsEnabled } from '$lib/stores/audio';
|
||||
import { tooltip } from '$lib/tooltip';
|
||||
import { fileIconName } from '$lib/utils/fileIcon';
|
||||
@@ -159,7 +159,12 @@
|
||||
}
|
||||
|
||||
function openArtifact(artifact: any) {
|
||||
openArtifactTab(artifact.title || 'Artifact', artifact.content || '');
|
||||
const workspace = get(currentWorkspace);
|
||||
const path =
|
||||
workspace && artifact.path
|
||||
? `${workspace.path.replace(/\/$/, '')}/${artifact.path}`
|
||||
: artifact.path;
|
||||
if (path) openFileTab(path);
|
||||
}
|
||||
|
||||
/** Human-readable label for a tool call */
|
||||
|
||||
@@ -53,19 +53,9 @@ export interface FileSearchTarget {
|
||||
|
||||
export interface Tab {
|
||||
id: string;
|
||||
type:
|
||||
| 'home'
|
||||
| 'files'
|
||||
| 'terminal'
|
||||
| 'file'
|
||||
| 'artifact'
|
||||
| 'git'
|
||||
| 'chat'
|
||||
| 'preview'
|
||||
| 'browser'; // preview is migrated on load
|
||||
type: 'home' | 'files' | 'terminal' | 'file' | 'git' | 'chat' | 'preview' | 'browser'; // preview is migrated on load
|
||||
label: string;
|
||||
filePath?: string;
|
||||
content?: string;
|
||||
edit?: boolean;
|
||||
path?: string; // generic path (e.g. for chat)
|
||||
sessionId?: string;
|
||||
@@ -955,7 +945,10 @@ export function openFileTab(
|
||||
options: { edit?: boolean; searchTarget?: FileSearchTarget } = {}
|
||||
): void {
|
||||
const ws = get(currentWorkspace);
|
||||
if (!ws) return;
|
||||
if (!ws) {
|
||||
openHomeFileTab(filePath, targetGroupId, options);
|
||||
return;
|
||||
}
|
||||
|
||||
const gid = targetGroupId ?? ws.activeGroupId;
|
||||
const group = ws.groups.find((g) => g.id === gid);
|
||||
@@ -995,26 +988,35 @@ export function openFileTab(
|
||||
}));
|
||||
}
|
||||
|
||||
export function openArtifactTab(title: string, content: string): void {
|
||||
const workspace = get(currentWorkspace);
|
||||
const state = workspace ?? get(homeState);
|
||||
const group = state.groups.find((item) => item.id === state.activeGroupId);
|
||||
function openHomeFileTab(
|
||||
filePath: string,
|
||||
targetGroupId?: string,
|
||||
options: { edit?: boolean; searchTarget?: FileSearchTarget } = {}
|
||||
): void {
|
||||
const state = get(homeState);
|
||||
const groupId = targetGroupId ?? state.activeGroupId;
|
||||
const group = state.groups.find((item) => item.id === groupId);
|
||||
if (!group) return;
|
||||
|
||||
const existing = group.tabs.find((tab) => tab.type === 'artifact' && tab.content === content);
|
||||
const tab: Tab = existing ?? { id: nextId(), type: 'artifact', label: title, content };
|
||||
const existing = group.tabs.find((tab) => tab.type === 'file' && tab.filePath === filePath);
|
||||
const tab: Tab = existing ?? {
|
||||
id: nextId(),
|
||||
type: 'file',
|
||||
label: getPathDisplayName(filePath, filePath),
|
||||
filePath,
|
||||
edit: options.edit,
|
||||
searchTarget: options.searchTarget
|
||||
};
|
||||
const updateGroup = (group: EditorGroup) =>
|
||||
group.id === state.activeGroupId
|
||||
group.id === groupId
|
||||
? { ...group, tabs: existing ? group.tabs : [...group.tabs, tab], activeTabId: tab.id }
|
||||
: group;
|
||||
|
||||
if (workspace) {
|
||||
currentWorkspace.update((current) =>
|
||||
current ? { ...current, groups: current.groups.map(updateGroup) } : current
|
||||
);
|
||||
} else {
|
||||
homeState.update((current) => ({ ...current, groups: current.groups.map(updateGroup) }));
|
||||
}
|
||||
homeState.update((current) => ({
|
||||
...current,
|
||||
activeGroupId: groupId,
|
||||
groups: current.groups.map(updateGroup)
|
||||
}));
|
||||
}
|
||||
|
||||
export function openUntitledFileTab(targetGroupId?: string): void {
|
||||
|
||||
@@ -43,7 +43,6 @@
|
||||
import FileEditor from '$lib/components/FileEditor.svelte';
|
||||
import GitView from '$lib/components/GitView.svelte';
|
||||
import Terminal from '$lib/components/Terminal.svelte';
|
||||
import ArtifactViewer from '$lib/components/ArtifactViewer.svelte';
|
||||
import BrowserPreview from '$lib/components/BrowserPreview.svelte';
|
||||
import ChatPanel from '$lib/components/chat/ChatPanel.svelte';
|
||||
import DirectoryPicker from '$lib/components/DirectoryPicker.svelte';
|
||||
@@ -1050,9 +1049,14 @@
|
||||
/>
|
||||
</div>
|
||||
{/each}
|
||||
{#each homePane.tabs.filter((tab) => tab.type === 'artifact') as tab (tab.id)}
|
||||
{#each homePane.tabs.filter((tab) => tab.type === 'file' && tab.filePath) as tab (tab.id)}
|
||||
<div class="persisted-tab" class:persisted-tab-hidden={tab.id !== homePane.activeTabId}>
|
||||
<ArtifactViewer content={tab.content || ''} />
|
||||
<FileEditor
|
||||
filePath={tab.filePath!}
|
||||
tabId={tab.id}
|
||||
edit={tab.edit === true}
|
||||
searchTarget={tab.searchTarget}
|
||||
/>
|
||||
</div>
|
||||
{/each}
|
||||
{#each homePane.tabs.filter((tab) => tab.type === 'terminal' && tab.sessionId) as tab (tab.id)}
|
||||
@@ -1372,11 +1376,6 @@
|
||||
/>
|
||||
</div>
|
||||
{/each}
|
||||
{#each group.tabs.filter((tab) => tab.type === 'artifact') as tab (tab.id)}
|
||||
<div class="persisted-tab" class:persisted-tab-hidden={tab.id !== group.activeTabId}>
|
||||
<ArtifactViewer content={tab.content || ''} />
|
||||
</div>
|
||||
{/each}
|
||||
{#each group.tabs.filter((tab) => tab.type === 'chat') as tab (tab.id)}
|
||||
<div class="persisted-tab" class:persisted-tab-hidden={tab.id !== group.activeTabId}>
|
||||
<ChatPanel
|
||||
|
||||
@@ -167,7 +167,9 @@ PLAN_MODE_PROMPT = (
|
||||
"[Plan Mode] Research with read-only tools before planning. When a material decision "
|
||||
"cannot be discovered, use ask_user with one to three questions, two to three options "
|
||||
"each, and the recommended option first. Ask only after research and never alongside "
|
||||
"another tool call. Then present your plan using create_artifact. Wait for an explicit "
|
||||
"another tool call. Then present a concise plan in your response. Use create_artifact "
|
||||
"only when a substantial plan or analysis benefits from being saved for review. Wait for "
|
||||
"an explicit "
|
||||
"approval message before using write tools or implementing."
|
||||
)
|
||||
|
||||
@@ -1955,7 +1957,6 @@ async def run_chat_task(
|
||||
if plan_mode:
|
||||
tools = [t for t in tools if ALL_TOOLS.get(t["name"], {}).get("auto")]
|
||||
tools = [t for t in tools if t["name"] not in {"delegate_task", "update_memory"}]
|
||||
# Inject create_artifact (only available in plan mode)
|
||||
tools.append(_fn_to_schema("create_artifact", create_artifact))
|
||||
tools.append(ASK_USER_SCHEMA)
|
||||
messages.append({"role": "user", "content": PLAN_MODE_PROMPT})
|
||||
|
||||
Reference in New Issue
Block a user