Skip to content

Commit 1cb74b0

Browse files
committed
refac
1 parent c303388 commit 1cb74b0

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

src/lib/components/common/ToolCallDisplay.svelte

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
3333
export let open = false;
3434
export let className = '';
35+
36+
const RESULT_PREVIEW_LIMIT = 10000;
37+
let expandedResult = false;
38+
39+
$: if (!open) expandedResult = false;
3540
export let buttonClassName =
3641
'w-fit text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 transition';
3742
@@ -216,10 +221,22 @@
216221
content={`\`\`\`json\n${JSON.stringify(parsedResult, null, 2)}\n\`\`\``}
217222
/>
218223
{:else}
224+
{@const resultStr = String(parsedResult)}
225+
{@const isTruncated = resultStr.length > RESULT_PREVIEW_LIMIT && !expandedResult}
219226
<pre
220-
class="text-xs text-gray-600 dark:text-gray-300 whitespace-pre-wrap break-words font-mono">{String(
221-
parsedResult
222-
)}</pre>
227+
class="text-xs text-gray-600 dark:text-gray-300 whitespace-pre-wrap break-words font-mono">{isTruncated ? resultStr.slice(0, RESULT_PREVIEW_LIMIT) : resultStr}</pre>
228+
{#if isTruncated}
229+
<button
230+
class="mt-1 text-xs text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 transition"
231+
on:click|stopPropagation={() => {
232+
expandedResult = true;
233+
}}
234+
>
235+
{$i18n.t('Show all ({{COUNT}} characters)', {
236+
COUNT: resultStr.length.toLocaleString()
237+
})}
238+
</button>
239+
{/if}
223240
{/if}
224241
</div>
225242
</div>

0 commit comments

Comments
 (0)