2 import { XCircle, Terminal } from '@lucide/svelte';
3 import { SyntaxHighlightedCode } from '$lib/components/app';
4 import { FileTypeText } from '$lib/enums';
5 import { MAX_HEIGHT_CODE_BLOCK } from '$lib/constants';
6 import { getBuiltinToolUi, type AgenticSection } from '$lib/utils';
7 import { parseRunJavascriptMeta } from './parsers/run-javascript';
8 import ToolCallBlock from './ToolCallBlock.svelte';
11 section: AgenticSection;
14 onToggle?: () => void;
17 let { section, open, isStreaming, onToggle }: Props = $props();
19 const runJsMeta = $derived(parseRunJavascriptMeta(section));
20 const title = $derived(getBuiltinToolUi(section.toolName)?.label ?? section.toolName ?? '');
23 <ToolCallBlock {section} {open} {isStreaming} meta={runJsMeta} {title} {onToggle}>
24 {#snippet children(meta, ctx)}
26 <div class="rounded bg-muted/20 p-2 text-xs text-muted-foreground/70 italic">Running...</div>
27 {:else if meta?.errorMessage}
29 class="flex items-start gap-2 rounded bg-red-500/10 p-2 text-xs text-red-600 italic dark:text-red-400"
31 <XCircle class="mt-0.5 h-3 w-3 shrink-0" />
32 <span>{meta.errorMessage}</span>
35 <SyntaxHighlightedCode
37 language={FileTypeText.JAVASCRIPT}
38 maxHeight={MAX_HEIGHT_CODE_BLOCK}
39 streaming={ctx.isCodeStreaming}
43 <SyntaxHighlightedCode
45 language={FileTypeText.JAVASCRIPT}
46 maxHeight={MAX_HEIGHT_CODE_BLOCK}
47 streaming={ctx.isCodeStreaming}
49 <div class="mb-2 mt-3 flex items-center gap-2 text-xs text-muted-foreground/70">
50 <Terminal class="h-3 w-3" />
52 {#if meta.timeoutMs != null}
53 <span class="font-mono">· timeout {meta.timeoutMs} ms</span>
56 {#if section.toolResult}
58 <SyntaxHighlightedCode
59 code={section.toolResult}
60 language={FileTypeText.JAVASCRIPT}
61 maxHeight={MAX_HEIGHT_CODE_BLOCK}
65 <div class="rounded bg-muted/20 p-2 text-xs text-muted-foreground/70 italic">No output</div>