This commit is contained in:
Timothy Jaeryang Baek committed 2026-06-06 00:51:47 -04:00
1 parent e0badc879c
commit cdbd446813
3 files changed
+94 -30

No files matched your search

@@ -2,8 +2,10 @@
import { tick } from 'svelte';
import { slide } from 'svelte/transition';
import { quintOut } from 'svelte/easing';
import { get } from 'svelte/store';
import MarkdownRenderer from '$lib/components/markdown/MarkdownRenderer.svelte';
import OutputEditView from './OutputEditView.svelte';
import { currentWorkspace, openFileTab } from '$lib/stores';
interface Props {
content: string;
@@ -279,17 +281,32 @@
{: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">
{@const preview = (artifact.content || '').replace(/^#.*\n*/m, '').trim().slice(0, 200)}
<button
class="w-full text-left my-2 rounded-xl
border border-gray-200 dark:border-white/10
hover:border-gray-300 dark:hover:border-white/15
bg-gray-50/50 dark:bg-white/[0.02]
hover:bg-gray-50 dark:hover:bg-white/[0.04]
transition-colors duration-150 cursor-pointer"
onclick={() => {
const ws = get(currentWorkspace);
if (ws && artifact.path) {
const fullPath = ws.path.replace(/\/$/, '') + '/' + artifact.path;
openFileTab(fullPath);
}
}}
>
<div class="flex items-center gap-1.5 px-3 pt-2 pb-0.5">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-3.5 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>
<span class="text-sm font-medium text-gray-800 dark:text-gray-100">{artifact.title || 'Artifact'}</span>
</div>
<div class="px-4 py-3 max-h-[32rem] overflow-y-auto">
<MarkdownRenderer content={artifact.content || ''} />
</div>
</div>
{#if preview}
<p class="px-3 pb-2 pt-0.5 text-xs text-gray-500 dark:text-gray-400 line-clamp-2 leading-relaxed">{preview}{preview.length >= 200 ? '...' : ''}</p>
{/if}
</button>
{:else if displayItem.type === 'tool_group'}
{@const calls = displayItem.calls}
@@ -51,28 +51,75 @@
{:else if token.type === 'table'}
{@const table = token as Tokens.Table}
<table>
<thead>
<tr>
{#each table.header as cell, i}
<th style={table.align[i] ? `text-align:${table.align[i]}` : ''}>
<InlineRenderer items={cell.tokens} />
</th>
{/each}
</tr>
</thead>
<tbody>
{#each table.rows as row}
<tr>
{#each row as cell, i}
<td style={table.align[i] ? `text-align:${table.align[i]}` : ''}>
<InlineRenderer items={cell.tokens} />
</td>
<div class="not-prose relative w-full group/table">
<div class="overflow-x-auto max-w-full rounded-lg border border-gray-200/60 dark:border-white/8">
<table class="w-full text-[13px] text-left text-gray-600 dark:text-gray-300">
<thead class="text-xs text-gray-500 dark:text-gray-400 uppercase bg-gray-50/80 dark:bg-white/[0.03]">
<tr>
{#each table.header as cell, i}
<th
scope="col"
class="px-3 py-1.5 font-medium border-b border-gray-200/60 dark:border-white/8 whitespace-nowrap"
style={table.align[i] ? `text-align:${table.align[i]}` : ''}
>
<InlineRenderer items={cell.tokens} />
</th>
{/each}
</tr>
</thead>
<tbody>
{#each table.rows as row, rowIdx}
<tr class="bg-white dark:bg-transparent">
{#each row as cell, i}
<td
class="px-3 py-1.5 {rowIdx < table.rows.length - 1 ? 'border-b border-gray-100/60 dark:border-white/5' : ''}"
style={table.align[i] ? `text-align:${table.align[i]}` : ''}
>
<InlineRenderer items={cell.tokens} />
</td>
{/each}
</tr>
{/each}
</tr>
{/each}
</tbody>
</table>
</tbody>
</table>
</div>
<!-- Utility buttons (show on hover) -->
<div class="absolute top-1 right-1.5 invisible group-hover/table:visible flex gap-0.5">
<button
class="p-1 rounded text-gray-400 dark:text-gray-500 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-200/60 dark:hover:bg-white/8 transition-all duration-100"
title="Copy"
onclick={() => {
navigator.clipboard.writeText((token as Tokens.Table).raw?.trim() ?? '');
}}
>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-3.5">
<path stroke-linecap="round" stroke-linejoin="round" d="M15.75 17.25v3.375c0 .621-.504 1.125-1.125 1.125h-9.75a1.125 1.125 0 0 1-1.125-1.125V7.875c0-.621.504-1.125 1.125-1.125H6.75a9.06 9.06 0 0 1 1.5.124m7.5 10.376h3.375c.621 0 1.125-.504 1.125-1.125V11.25c0-4.46-3.243-8.161-7.5-8.876a9.06 9.06 0 0 0-1.5-.124H9.375c-.621 0-1.125.504-1.125 1.125v3.5m7.5 10.375H9.375a1.125 1.125 0 0 1-1.125-1.125v-9.25m12 6.625v-1.875a3.375 3.375 0 0 0-3.375-3.375h-1.5a1.125 1.125 0 0 1-1.125-1.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H9.75" />
</svg>
</button>
<button
class="p-1 rounded text-gray-400 dark:text-gray-500 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-200/60 dark:hover:bg-white/8 transition-all duration-100"
title="Download CSV"
onclick={() => {
const t = token as Tokens.Table;
const header = t.header.map(h => `"${h.text.replace(/"/g, '""')}"`);
const rows = t.rows.map(r => r.map(c => `"${c.text.replace(/"/g, '""')}"`));
const csv = [header, ...rows].map(r => r.join(',')).join('\n');
const blob = new Blob(['\uFEFF' + csv], { type: 'text/csv;charset=UTF-8' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'table.csv';
a.click();
URL.revokeObjectURL(url);
}}
>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-3.5">
<path stroke-linecap="round" stroke-linejoin="round" d="M3 16.5v2.25A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75V16.5M16.5 12 12 16.5m0 0L7.5 12m4.5 4.5V3" />
</svg>
</button>
</div>
</div>
{:else if token.type === 'hr'}
<hr class="border-gray-100/60 dark:border-gray-850/40" />
@@ -41,6 +41,6 @@
});
</script>
<div class="prose prose-sm dark:prose-invert max-w-none break-words leading-relaxed prose-p:my-2 prose-p:leading-relaxed prose-headings:mt-4 prose-headings:mb-2 prose-headings:font-semibold prose-headings:leading-snug prose-strong:font-semibold prose-th:font-semibold prose-code:before:content-none prose-code:after:content-none prose-ul:my-2 prose-ol:my-2 prose-li:my-0.5 prose-pre:my-3 prose-blockquote:my-3 prose-hr:my-4 prose-img:my-2 prose-table:my-3 [&>:first-child]:mt-0 [&>:last-child]:mb-0">
<div class="prose prose-sm dark:prose-invert max-w-none break-words leading-relaxed prose-p:my-2 prose-p:leading-relaxed prose-headings:mt-4 prose-headings:mb-2 prose-headings:font-semibold prose-headings:leading-snug prose-strong:font-semibold prose-code:before:content-none prose-code:after:content-none prose-ul:my-2 prose-ol:my-2 prose-li:my-0.5 prose-pre:my-3 prose-blockquote:my-3 prose-hr:my-4 prose-img:my-2 [&>:first-child]:mt-0 [&>:last-child]:mb-0">
<BlockRenderer {tokens} />
</div>