diff --git a/cptr/frontend/src/lib/components/ArtifactViewer.svelte b/cptr/frontend/src/lib/components/ArtifactViewer.svelte new file mode 100644 index 0000000..1e160dc --- /dev/null +++ b/cptr/frontend/src/lib/components/ArtifactViewer.svelte @@ -0,0 +1,9 @@ + + +
+
+
diff --git a/cptr/frontend/src/lib/components/chat/AssistantMessage.svelte b/cptr/frontend/src/lib/components/chat/AssistantMessage.svelte index a67294a..a78c418 100644 --- a/cptr/frontend/src/lib/components/chat/AssistantMessage.svelte +++ b/cptr/frontend/src/lib/components/chat/AssistantMessage.svelte @@ -8,7 +8,7 @@ import MessageTimestamp from './MessageTimestamp.svelte'; import ReasoningCollapsible from './ReasoningCollapsible.svelte'; import ToolCallCollapsible from './ToolCallCollapsible.svelte'; - import { currentWorkspace, openFileTab } from '$lib/stores'; + import { currentWorkspace, openArtifactTab, openFileTab } from '$lib/stores'; import { ttsConfigured, ttsEnabled } from '$lib/stores/audio'; import { tooltip } from '$lib/tooltip'; import { fileIconName } from '$lib/utils/fileIcon'; @@ -158,6 +158,10 @@ collapsedFiles = { ...collapsedFiles, [key]: !collapsedFiles[key] }; } + function openArtifact(artifact: any) { + openArtifactTab(artifact.title || 'Artifact', artifact.content || ''); + } + /** Human-readable label for a tool call */ function toolLabel(name: string, args: any): string { const _t = $t; @@ -464,13 +468,7 @@ hover:border-gray-300 dark:hover:border-white/12 hover:bg-gray-50/50 dark:hover:bg-white/[0.03] transition-colors duration-150 {preview ? 'h-[4.375rem]' : 'h-[2.375rem]'}" - onclick={() => { - const ws = get(currentWorkspace); - if (ws && artifact.path) { - const fullPath = ws.path.replace(/\/$/, '') + '/' + artifact.path; - openFileTab(fullPath); - } - }} + onclick={() => openArtifact(artifact)} >
item.id === state.activeGroupId); + 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 updateGroup = (group: EditorGroup) => + group.id === state.activeGroupId + ? { ...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) })); + } +} + export function openUntitledFileTab(targetGroupId?: string): void { // Find the lowest unused number across ALL groups const ws = get(currentWorkspace); diff --git a/cptr/frontend/src/routes/+page.svelte b/cptr/frontend/src/routes/+page.svelte index 22580fd..e8adc46 100644 --- a/cptr/frontend/src/routes/+page.svelte +++ b/cptr/frontend/src/routes/+page.svelte @@ -43,6 +43,7 @@ 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'; @@ -1049,6 +1050,11 @@ />
{/each} + {#each homePane.tabs.filter((tab) => tab.type === 'artifact') as tab (tab.id)} +
+ +
+ {/each} {#each homePane.tabs.filter((tab) => tab.type === 'terminal' && tab.sessionId) as tab (tab.id)}
@@ -1366,6 +1372,11 @@ />
{/each} + {#each group.tabs.filter((tab) => tab.type === 'artifact') as tab (tab.id)} +
+ +
+ {/each} {#each group.tabs.filter((tab) => tab.type === 'chat') as tab (tab.id)}