()
| 268 | }; |
| 269 | |
| 270 | function App() { |
| 271 | const { exit } = useApp(); |
| 272 | const [question, setQuestion] = useState<string | null>(null); |
| 273 | const [agents, setAgents] = useState<Record<string, AgentState>>(initialAgents); |
| 274 | const [history, setHistory] = useState<string[]>(() => loadHistory()); |
| 275 | |
| 276 | useInput((input, key) => { |
| 277 | if (key.escape || (key.ctrl && input === 'c') || (key.ctrl && input === 'd')) { |
| 278 | exit(); |
| 279 | } |
| 280 | }); |
| 281 | |
| 282 | const createCallbacks = useCallback( |
| 283 | (agentKey: string): StreamCallbacks => ({ |
| 284 | onText: (chunk) => { |
| 285 | setAgents((prev) => { |
| 286 | const agent = prev[agentKey]; |
| 287 | const newText = agent.currentText + chunk; |
| 288 | |
| 289 | // If we hit a newline or enough text, flush to activity as response |
| 290 | const lines = newText.split('\n'); |
| 291 | if (lines.length > 1) { |
| 292 | // Flush complete lines to activity |
| 293 | const completeLines = lines.slice(0, -1); |
| 294 | const remaining = lines[lines.length - 1]; |
| 295 | const newActivity = [ |
| 296 | ...agent.activity, |
| 297 | ...completeLines |
| 298 | .filter((l) => l.trim()) |
| 299 | .map((l) => ({ type: 'response' as const, text: l })), |
| 300 | ]; |
| 301 | return { |
| 302 | ...prev, |
| 303 | [agentKey]: { |
| 304 | ...agent, |
| 305 | activity: newActivity, |
| 306 | currentText: remaining, |
| 307 | }, |
| 308 | }; |
| 309 | } |
| 310 | |
| 311 | return { |
| 312 | ...prev, |
| 313 | [agentKey]: { |
| 314 | ...agent, |
| 315 | currentText: newText, |
| 316 | }, |
| 317 | }; |
| 318 | }); |
| 319 | }, |
| 320 | onToolCall: (toolName, args) => { |
| 321 | setAgents((prev) => { |
| 322 | const agent = prev[agentKey]; |
| 323 | const argStr = Object.entries(args) |
| 324 | .slice(0, 2) |
| 325 | .map(([k, v]) => { |
| 326 | const val = typeof v === 'string' ? v : JSON.stringify(v); |
| 327 | return `${k}=${val.slice(0, 20)}${val.length > 20 ? '..' : ''}`; |
nothing calls this directly
no test coverage detected