From 9cf4d348327cc6c0900d249140e5ba87eae6fe12 Mon Sep 17 00:00:00 2001 From: Tim Baek Date: Fri, 6 Feb 2026 23:21:09 +0400 Subject: [PATCH] refac --- .../Messages/Markdown/MarkdownTokens.svelte | 11 +- src/lib/components/common/Collapsible.svelte | 159 --------------- .../components/common/ToolCallDisplay.svelte | 186 ++++++++++++++++++ 3 files changed, 196 insertions(+), 160 deletions(-) create mode 100644 src/lib/components/common/ToolCallDisplay.svelte diff --git a/src/lib/components/chat/Messages/Markdown/MarkdownTokens.svelte b/src/lib/components/chat/Messages/Markdown/MarkdownTokens.svelte index 305073fb8..355056054 100644 --- a/src/lib/components/chat/Messages/Markdown/MarkdownTokens.svelte +++ b/src/lib/components/chat/Messages/Markdown/MarkdownTokens.svelte @@ -17,6 +17,7 @@ import KatexRenderer from './KatexRenderer.svelte'; import AlertRenderer, { alertComponent } from './AlertRenderer.svelte'; import Collapsible from '$lib/components/common/Collapsible.svelte'; + import ToolCallDisplay from '$lib/components/common/ToolCallDisplay.svelte'; import Tooltip from '$lib/components/common/Tooltip.svelte'; import Download from '$lib/components/icons/Download.svelte'; @@ -323,7 +324,15 @@ .replace(/.*?<\/summary>/gi, '') .trim()} - {#if textContent.length > 0} + {#if token?.attributes?.type === 'tool_calls'} + + + {:else if textContent.length > 0}
- {#if attributes?.type === 'tool_calls'} - {@const args = decode(attributes?.arguments)} - {@const result = decode(attributes?.result ?? '')} - {@const files = parseJSONString(decode(attributes?.files ?? ''))} - {@const embeds = parseJSONString(decode(attributes?.embeds ?? ''))} - - {#if embeds && Array.isArray(embeds) && embeds.length > 0} -
-
-
- {attributes.name} -
-
- - {#each embeds as embed, idx} -
- -
- {/each} -
- {:else} -
{ - if (!disabled) { - open = !open; - } - }} - > -
- {#if attributes?.done && attributes?.done !== 'true'} -
- -
- {/if} - -
- {#if attributes?.done === 'true'} - - {:else} - - {/if} -
- -
- {#if open} - - {:else} - - {/if} -
-
-
- - {#if !grow} - {#if open && !hide} -
- {#if attributes?.type === 'tool_calls'} - {#if attributes?.done === 'true'} - \`\`\`json -> ${formatJSONString(args)} -> ${formatJSONString(result)} -> \`\`\``} - /> - {:else} - \`\`\`json -> ${formatJSONString(args)} -> \`\`\``} - /> - {/if} - {:else} - - {/if} -
- {/if} - {/if} - {/if} - - {#if attributes?.done === 'true'} - {#if typeof files === 'object'} - {#each files ?? [] as file, idx} - {#if typeof file === 'string'} - {#if file.startsWith('data:image/')} - Image - {/if} - {:else if typeof file === 'object'} - {#if (file.type === 'image' || (file?.content_type ?? '').startsWith('image/')) && file.url} - Image - {/if} - {/if} - {/each} - {/if} - {/if} - {:else} {#if title !== null} @@ -333,5 +175,4 @@
{/if} {/if} - {/if} diff --git a/src/lib/components/common/ToolCallDisplay.svelte b/src/lib/components/common/ToolCallDisplay.svelte new file mode 100644 index 000000000..d3495eab2 --- /dev/null +++ b/src/lib/components/common/ToolCallDisplay.svelte @@ -0,0 +1,186 @@ + + +
+ {#if embeds && Array.isArray(embeds) && embeds.length > 0} + +
+
+
+ {attributes.name} +
+
+ + {#each embeds as embed, idx} +
+ +
+ {/each} +
+ {:else} + +
{ + open = !open; + }} + > +
+ {#if isExecuting} +
+ +
+ {/if} + +
+ {#if isDone} + + {:else} + + {/if} +
+ +
+ {#if open} + + {:else} + + {/if} +
+
+
+ + {#if open} +
+ {#if isDone} + \`\`\`json +> ${formatJSONString(args)} +> ${formatJSONString(result)} +> \`\`\``} + /> + {:else} + \`\`\`json +> ${formatJSONString(args)} +> \`\`\``} + /> + {/if} +
+ {/if} + {/if} + + + {#if isDone} + {#if typeof files === 'object'} + {#each files ?? [] as file, idx} + {#if typeof file === 'string'} + {#if file.startsWith('data:image/')} + Image + {/if} + {:else if typeof file === 'object'} + {#if (file.type === 'image' || (file?.content_type ?? '').startsWith('image/')) && file.url} + Image + {/if} + {/if} + {/each} + {/if} + {/if} +