/* eslint-disable react-refresh/only-export-components -- renderer constant is co-located with its inline component by design */ import { useState } from 'react'; import { CornerLine, ToolStateIcon } from './_shared'; import type { TFunction, ToolCallWithResult, ToolRenderer } from './types'; import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible'; function parseInput(input: string): Record { try { return JSON.parse(input); } catch { return {}; } } /** * Collapsed: "TaskCreate Created 3 tasks ..." * Expanded: * TaskCreate Created 3 tasks * Research duck facts * Find five interesting facts about ducks * Write summary * Compile the research into a brief summary * Review code * Check for bugs and style issues */ function TaskCreateGroup({ calls, t }: { calls: ToolCallWithResult[]; t: TFunction }) { const [open, setOpen] = useState(false); return ( c.result?.state)} /> {t('tool.taskCreate.label')}{' '} {t('tool.taskCreate.count', { count: calls.length })} {!open && ...} {calls.map(({ call, result }) => { const input = parseInput(call.input); const subject = (input.subject as string) || '(untitled)'; const description = (input.description as string) || ''; // Extract the numeric task id from result text: // "Task (id=3) created successfully: ..." const resultText = typeof result?.output === 'string' ? result.output : Array.isArray(result?.output) ? result.output.map((b) => ('text' in b ? b.text : '')).join('') : ''; const idMatch = resultText.match(/^Task \(id=(\d+)\)/); const taskId = idMatch ? idMatch[1] : null; return (
{taskId && ( #{taskId} )} {taskId && ' '} {subject} {description && (
{description}
)}
); })}
); } export const TaskCreateRenderer: ToolRenderer = { getDisplayName: (_call, t) => t('tool.taskCreate.name'), renderCallArgs: (call) => { const input = parseInput(call.input); return (input.subject as string) || ''; }, renderGroup: (calls, t) => , };