2 import { parseWriteFileMeta } from './parsers/write-file';
3 import ToolCallBlock from './ToolCallBlock.svelte';
4 import { XCircle } from '@lucide/svelte';
5 import { SyntaxHighlightedCode } from '$lib/components/app';
6 import { MAX_HEIGHT_CODE_BLOCK, RESULT_STAT_SEPARATOR } from '$lib/constants';
7 import { toolsStore } from '$lib/stores/tools.svelte';
8 import type { AgenticSection } from '$lib/types';
9 import { abbreviateHome } from '$lib/utils';
12 section: AgenticSection;
15 onToggle?: () => void;
18 let { isStreaming, onToggle, open, section }: Props = $props();
20 const writeFileMeta = $derived(parseWriteFileMeta(section));
21 const home = $derived(toolsStore.serverHome);
24 <ToolCallBlock {section} {open} {isStreaming} meta={writeFileMeta} {onToggle}>
25 {#snippet titleSnippet()}
26 <span class="text-muted-foreground">Write file </span>
27 <span class="font-mono" title={writeFileMeta?.filePath}
28 >{abbreviateHome(writeFileMeta?.filePath ?? '', home)}</span
30 {#if writeFileMeta?.errorMessage}
31 <span class="ml-1 text-xs italic text-muted-foreground/70">(failed)</span>
35 {#snippet children(meta, ctx)}
36 {#if meta?.errorMessage}
38 class="flex items-start gap-2 rounded bg-red-500/10 p-2 text-xs text-red-600 italic dark:text-red-400"
40 <XCircle class="mt-0.5 h-3 w-3 shrink-0" />
41 <span>{meta.errorMessage}</span>
44 <SyntaxHighlightedCode
46 language={meta.language}
47 maxHeight={MAX_HEIGHT_CODE_BLOCK}
48 streaming={ctx.isCodeStreaming}
50 <div class="mt-1.5 text-xs text-muted-foreground/70 italic">
51 {#if meta.resultMessage}
52 {meta.resultMessage}{meta.bytesWritten != null ? RESULT_STAT_SEPARATOR : ''}{/if}
53 {#if meta.bytesWritten != null}
54 <span class="font-mono">{meta.bytesWritten}</span>