Skip to content

Commit 2ce935b

Browse files
committed
refac
1 parent 23b1e2c commit 2ce935b

1 file changed

Lines changed: 36 additions & 8 deletions

File tree

src/lib/components/common/ToolCallDisplay.svelte

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,26 @@
5757
}
5858
}
5959
60+
function parseArguments(str: string): Record<string, unknown> | null {
61+
try {
62+
const parsed = parseJSONString(str);
63+
if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)) {
64+
return parsed as Record<string, unknown>;
65+
}
66+
return null;
67+
} catch {
68+
return null;
69+
}
70+
}
71+
6072
$: args = decode(attributes?.arguments ?? '');
6173
$: result = decode(attributes?.result ?? '');
6274
$: files = parseJSONString(decode(attributes?.files ?? ''));
6375
$: embeds = parseJSONString(decode(attributes?.embeds ?? ''));
6476
$: isDone = attributes?.done === 'true';
6577
$: isExecuting = attributes?.done && attributes?.done !== 'true';
78+
79+
$: parsedArgs = parseArguments(args);
6680
</script>
6781

6882
<div {id} class={className}>
@@ -156,24 +170,38 @@
156170
{#if args}
157171
<div>
158172
<div
159-
class="text-[10px] uppercase tracking-wider font-semibold text-gray-400 dark:text-gray-500 mb-1.5 px-1"
173+
class="text-[10px] uppercase tracking-wider font-medium text-gray-400 dark:text-gray-500 mb-1.5 px-1"
160174
>
161175
{$i18n.t('Input')}
162176
</div>
163-
<div class="tool-call-body w-full max-w-none!">
164-
<Markdown
165-
id={`${componentId}-tool-call-args`}
166-
content={`\`\`\`json\n${formatJSONString(args)}\n\`\`\``}
167-
/>
168-
</div>
177+
178+
{#if parsedArgs}
179+
<div class="px-1 space-y-0.5">
180+
{#each Object.entries(parsedArgs) as [key, value]}
181+
<div class="flex gap-2 text-xs py-0.5">
182+
<span class="font-medium text-gray-600 dark:text-gray-400 shrink-0"
183+
>{key}</span
184+
>
185+
<span class="text-gray-800 dark:text-gray-200 break-all">{typeof value === 'object' ? JSON.stringify(value) : value}</span>
186+
</div>
187+
{/each}
188+
</div>
189+
{:else}
190+
<div class="tool-call-body w-full max-w-none!">
191+
<Markdown
192+
id={`${componentId}-tool-call-args`}
193+
content={`\`\`\`json\n${formatJSONString(args)}\n\`\`\``}
194+
/>
195+
</div>
196+
{/if}
169197
</div>
170198
{/if}
171199

172200
<!-- Output -->
173201
{#if isDone && result}
174202
<div>
175203
<div
176-
class="text-[10px] uppercase tracking-wider font-semibold text-gray-400 dark:text-gray-500 mb-1.5 px-1"
204+
class="text-[10px] uppercase tracking-wider font-medium text-gray-400 dark:text-gray-500 mb-1.5 px-1"
177205
>
178206
{$i18n.t('Output')}
179207
</div>

0 commit comments

Comments
 (0)