]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/blob
9e6ef10919db6a72d06455efba81de2c0387d022
[pkg/ggml/sources/llama.cpp] /
1 <script lang="ts">
2 import { Info, Loader2 } from '@lucide/svelte';
3 import { AgenticSectionType } from '$lib/enums';
4 import { toolsStore } from '$lib/stores/tools.svelte';
5 import type { AgenticSection } from '$lib/types';
6 import { abbreviateHome } from '$lib/utils';
7
8 interface Props {
9 section: AgenticSection;
10 isStreaming?: boolean;
11 }
12
13 let { isStreaming = false, section }: Props = $props();
14
15 const isPending = $derived(section.type === AgenticSectionType.TOOL_CALL_PENDING);
16 const isStreamingCall = $derived(section.type === AgenticSectionType.TOOL_CALL_STREAMING);
17 const showSpinner = $derived(isPending || (isStreamingCall && isStreaming));
18
19 type GetInfoMeta = {
20 os?: string;
21 cwd?: string;
22 errorMessage?: string;
23 };
24
25 function parseGetInfoMeta(toolResultString: string | undefined): GetInfoMeta {
26 if (!toolResultString) return {};
27
28 try {
29 const parsed: unknown = JSON.parse(toolResultString);
30
31 if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
32 const obj = parsed as Record<string, unknown>;
33
34 if (typeof obj.error === 'string') return { errorMessage: obj.error };
35
36 return {
37 cwd: typeof obj.cwd === 'string' ? obj.cwd : undefined,
38 os: typeof obj.os === 'string' ? obj.os : undefined
39 };
40 }
41 } catch {
42 // not JSON - nothing to show
43 }
44
45 return {};
46 }
47
48 const infoMeta = $derived(parseGetInfoMeta(section.toolResult));
49 const home = $derived(toolsStore.serverHome);
50 const cwdDisplay = $derived(abbreviateHome(infoMeta.cwd ?? '', home));
51 </script>
52
53 <div class="text-muted-foreground flex items-center gap-2 py-1.5">
54 <Info class="text-muted-foreground/60 h-3.5 w-3.5 shrink-0" />
55 {#if showSpinner}
56 <span class="text-foreground/80 text-sm font-medium">Runtime info</span>
57 <Loader2 class="text-muted-foreground/70 h-3 w-3 animate-spin" />
58 {:else if infoMeta.errorMessage}
59 <span class="text-foreground/80 text-sm font-medium">Runtime info&nbsp;</span>
60 <span class="text-red-600 text-xs italic dark:text-red-400">-&nbsp;{infoMeta.errorMessage}</span
61 >
62 {:else if infoMeta.os || infoMeta.cwd}
63 <span class="text-foreground/80 text-sm font-medium">Runtime info&nbsp;</span>
64 {#if infoMeta.os}
65 <span class="font-mono text-foreground/90 text-sm">{infoMeta.os}</span>
66 {/if}
67 {#if infoMeta.cwd}
68 <span class="font-mono text-foreground/90 text-sm" title={infoMeta.cwd}>{cwdDisplay}</span>
69 {/if}
70 {:else}
71 <span class="text-foreground/80 text-sm font-medium">Runtime info</span>
72 {/if}
73 </div>