diff --git a/ui/desktop/src/components/ToolInvocation.tsx b/ui/desktop/src/components/ToolInvocation.tsx index 52af1dbb95..9839b84ee5 100644 --- a/ui/desktop/src/components/ToolInvocation.tsx +++ b/ui/desktop/src/components/ToolInvocation.tsx @@ -1,7 +1,6 @@ -import React, { useState } from 'react'; +import React from 'react'; import { Card } from './ui/card'; -import { Button } from './ui/button'; -import { BoxIcon, GPSIcon } from './ui/icons' +import { BoxIcon } from './ui/icons' import ReactMarkdown from 'react-markdown' export default function ToolInvocation({ toolInvocation }) { @@ -26,6 +25,8 @@ interface ToolCallProps { } function ToolCall({ call }: ToolCallProps) { + const argsMarkdownContent = convertArgsToMarkdown(call.args); + return (
@@ -34,9 +35,9 @@ function ToolCall({ call }: ToolCallProps) {
{call.args && ( -
-          {JSON.stringify(call.args, null, 2)}
-        
+ + {argsMarkdownContent} + )}
) @@ -129,146 +130,36 @@ function ToolResult({ result }: ToolResultProps) { ) } +// Utils - - -interface ToolResponseFormProps { - result: { - message?: string - result?: string - state?: string - toolCallId?: string - toolName?: string - args?: any - input_todo?: any - } - onSubmitInput?: (input: string) => void -} - -interface JsonSchemaProperty { - type: string - title?: string - description?: string - enum?: string[] - format?: string - minimum?: number - maximum?: number - minLength?: number - maxLength?: number -} - -function getIconForSchemaType(schema: JsonSchemaProperty) { - if (schema.enum) return BoxIcon - if (schema.type === 'integer' || schema.type === 'number') return BoxIcon - if (schema.format === 'date' || schema.format === 'date-time') return BoxIcon - return BoxIcon -} - -function ToolResponseForm({ result, onSubmitInput }: ToolResponseFormProps) { - const [inputValues, setInputValues] = useState>({}) - const [submitted, setSubmitted] = useState(false) - - const handleSubmit = () => { - setSubmitted(true) - const inputString = Object.entries(inputValues) - .map(([key, value]) => `${key}: ${value}`) - .join('\n') - if (onSubmitInput) { - onSubmitInput(inputString) +const convertArgsToMarkdown = (args: Record): string => { + const lines: string[] = []; + + Object.entries(args).forEach(([key, value]) => { + // Add the parameter name as a heading + lines.push(`### ${key}`); + lines.push(''); + + // Handle different value types + if (typeof value === 'string') { + lines.push('```'); + lines.push(value); + lines.push('```'); + } else if (Array.isArray(value)) { + value.forEach((item, index) => { + lines.push(`${index + 1}. ${JSON.stringify(item)}`); + }); + } else if (typeof value === 'object' && value !== null) { + lines.push('```json'); + lines.push(JSON.stringify(value, null, 2)); + lines.push('```'); + } else { + lines.push('```'); + lines.push(String(value)); + lines.push('```'); } - } + lines.push(''); + }); - {result.input_todo && !submitted && ( -
-
- {Object.entries(result.input_todo.properties).map(([key, schema]: [key: string, schema: JsonSchemaProperty]) => { - const value = inputValues[key] || '' - const Icon = getIconForSchemaType(schema as JsonSchemaProperty) - - if (schema.enum) { - return ( -
-
- - {schema.title || key} -
-
- {schema.enum.map((option) => ( -
-
setInputValues({ ...inputValues, [key]: option })}> - {option} -
-
- ))} -
- {schema.description && ( -
{schema.description}
- )} -
- ) - } - - return ( -
-
- - {schema.title || key} -
- {schema.type === 'integer' || schema.type === 'number' ? ( - setInputValues({ ...inputValues, [key]: e.target.value })} - /> - ) : schema.format === 'date' ? ( - setInputValues({ ...inputValues, [key]: e.target.value })} - /> - ) : schema.format === 'date-time' ? ( - setInputValues({ ...inputValues, [key]: e.target.value })} - /> - ) : ( - schema.type === 'string' && ( - !schema.maxLength || schema.maxLength > 100 ? ( -
setInputValues({ ...inputValues, [key]: e.currentTarget.textContent || '' })} - suppressContentEditableWarning - /> - ) : ( - setInputValues({ ...inputValues, [key]: e.target.value })} - /> - ) - ) - )} - {schema.description && ( -
{schema.description}
- )} -
- )})} -
- -
- )} -} \ No newline at end of file + return lines.join('\n'); +}; \ No newline at end of file