2 import { Clock, Loader2 } from '@lucide/svelte';
3 import { AgenticSectionType } from '$lib/enums';
4 import type { AgenticSection } from '$lib/utils';
7 section: AgenticSection;
11 let { section, isStreaming = false }: Props = $props();
13 const isPending = $derived(section.type === AgenticSectionType.TOOL_CALL_PENDING);
14 const isStreamingCall = $derived(section.type === AgenticSectionType.TOOL_CALL_STREAMING);
15 const showSpinner = $derived(isPending || (isStreamingCall && isStreaming));
17 type GetDatetimeMeta = {
19 errorMessage?: string;
22 function parseGetDatetimeMeta(toolResultString: string | undefined): GetDatetimeMeta {
23 if (!toolResultString) return {};
26 const parsed: unknown = JSON.parse(toolResultString);
27 if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
28 const obj = parsed as Record<string, unknown>;
29 if (typeof obj.error === 'string') return { errorMessage: obj.error };
30 if (typeof obj.result === 'string') return { dateString: obj.result.trim() };
33 return { dateString: toolResultString.trim() };
39 const dateMeta = $derived(parseGetDatetimeMeta(section.toolResult));
42 <div class="text-muted-foreground flex items-center gap-2 py-1.5">
43 <Clock class="text-muted-foreground/60 h-3.5 w-3.5 shrink-0" />
45 <span class="text-foreground/80 text-sm font-medium">Current time</span>
46 <Loader2 class="text-muted-foreground/70 h-3 w-3 animate-spin" />
47 {:else if dateMeta.errorMessage}
48 <span class="text-foreground/80 text-sm font-medium">Current time </span>
49 <span class="text-red-600 text-xs italic dark:text-red-400">- {dateMeta.errorMessage}</span
51 {:else if dateMeta.dateString}
52 <span class="text-foreground/80 text-sm font-medium">Current time is </span>
53 <span class="font-mono text-foreground/90 text-sm">{dateMeta.dateString}</span>
55 <span class="text-foreground/80 text-sm font-medium">Current time</span>