|
57 | 57 | } |
58 | 58 | } |
59 | 59 |
|
| 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 | +
|
60 | 72 | $: args = decode(attributes?.arguments ?? ''); |
61 | 73 | $: result = decode(attributes?.result ?? ''); |
62 | 74 | $: files = parseJSONString(decode(attributes?.files ?? '')); |
63 | 75 | $: embeds = parseJSONString(decode(attributes?.embeds ?? '')); |
64 | 76 | $: isDone = attributes?.done === 'true'; |
65 | 77 | $: isExecuting = attributes?.done && attributes?.done !== 'true'; |
| 78 | +
|
| 79 | + $: parsedArgs = parseArguments(args); |
66 | 80 | </script> |
67 | 81 |
|
68 | 82 | <div {id} class={className}> |
|
156 | 170 | {#if args} |
157 | 171 | <div> |
158 | 172 | <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" |
160 | 174 | > |
161 | 175 | {$i18n.t('Input')} |
162 | 176 | </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} |
169 | 197 | </div> |
170 | 198 | {/if} |
171 | 199 |
|
172 | 200 | <!-- Output --> |
173 | 201 | {#if isDone && result} |
174 | 202 | <div> |
175 | 203 | <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" |
177 | 205 | > |
178 | 206 | {$i18n.t('Output')} |
179 | 207 | </div> |
|
0 commit comments