|
4 | 4 | import { buttonVariants } from '$lib/components/ui/button/index.js'; |
5 | 5 | import { Card } from '$lib/components/ui/card'; |
6 | 6 | import { createAutoScrollController } from '$lib/hooks/use-auto-scroll.svelte'; |
| 7 | + import { useThrottle } from '$lib/hooks/use-throttle.svelte'; |
| 8 | + import { formatReasoningPreview } from '$lib/utils'; |
| 9 | + import { config } from '$lib/stores/settings.svelte'; |
7 | 10 | import type { Snippet } from 'svelte'; |
8 | 11 | import type { Component } from 'svelte'; |
9 | 12 |
|
|
14 | 17 | iconClass?: string; |
15 | 18 | title: string; |
16 | 19 | subtitle?: string; |
| 20 | + preview?: string; |
| 21 | + rawContent?: string; |
17 | 22 | isStreaming?: boolean; |
18 | 23 | onToggle?: () => void; |
19 | 24 | children: Snippet; |
|
26 | 31 | iconClass = 'h-4 w-4', |
27 | 32 | title, |
28 | 33 | subtitle, |
| 34 | + preview, |
| 35 | + rawContent, |
29 | 36 | isStreaming = false, |
30 | 37 | onToggle, |
31 | 38 | children |
32 | 39 | }: Props = $props(); |
33 | 40 |
|
34 | 41 | let contentContainer: HTMLDivElement | undefined = $state(); |
35 | 42 |
|
| 43 | + const showThoughtInProgress = $derived(config().showThoughtInProgress as boolean); |
| 44 | +
|
| 45 | + let previewKey = useThrottle(() => rawContent ?? preview ?? '', 500); |
| 46 | + let displayedPreview = $state(''); |
| 47 | + let displayedOverflow = $state(0); |
| 48 | +
|
| 49 | + $effect(() => { |
| 50 | + void previewKey.key; |
| 51 | + const content = rawContent ?? preview ?? ''; |
| 52 | + const result = formatReasoningPreview(content); |
| 53 | + displayedPreview = result.preview; |
| 54 | + displayedOverflow = result.overflow; |
| 55 | + }); |
| 56 | +
|
36 | 57 | const autoScroll = createAutoScrollController(); |
37 | 58 |
|
38 | 59 | $effect(() => { |
|
58 | 79 | class={className} |
59 | 80 | > |
60 | 81 | <Card class="gap-0 border-muted bg-muted/30 py-0"> |
61 | | - <Collapsible.Trigger class="flex w-full cursor-pointer items-center justify-between p-3"> |
62 | | - <div class="flex items-center gap-2 text-muted-foreground"> |
63 | | - {#if IconComponent} |
64 | | - <IconComponent class={iconClass} /> |
65 | | - {/if} |
| 82 | + <Collapsible.Trigger class="flex w-full cursor-pointer items-start justify-between gap-2 p-3"> |
| 83 | + <div class="flex min-w-0 items-center gap-2"> |
| 84 | + <div class="flex items-center gap-2 text-muted-foreground"> |
| 85 | + {#if IconComponent} |
| 86 | + <IconComponent class={iconClass} /> |
| 87 | + {/if} |
| 88 | + |
| 89 | + <span class="font-mono text-sm font-medium">{title}</span> |
66 | 90 |
|
67 | | - <span class="font-mono text-sm font-medium">{title}</span> |
| 91 | + {#if subtitle} |
| 92 | + <span class="text-xs italic">{subtitle}</span> |
| 93 | + {/if} |
| 94 | + </div> |
68 | 95 |
|
69 | | - {#if subtitle} |
70 | | - <span class="text-xs italic">{subtitle}</span> |
| 96 | + {#if displayedPreview && !showThoughtInProgress} |
| 97 | + <div class="flex min-w-0 items-baseline justify-between gap-2"> |
| 98 | + <div class="w-3/4 truncate text-xs text-muted-foreground/80"> |
| 99 | + {displayedPreview} |
| 100 | + </div> |
| 101 | + {#if displayedOverflow > 0} |
| 102 | + <span class="shrink-0 text-xs text-muted-foreground/60" |
| 103 | + >{displayedOverflow}+ chars</span |
| 104 | + > |
| 105 | + {/if} |
| 106 | + </div> |
71 | 107 | {/if} |
72 | 108 | </div> |
73 | 109 |
|
|
0 commit comments