Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

devtools-subagents.tsx

48 lines1.6 KB

1import { createFileRoute } from '@tanstack/react-router'
2import { fetchServerSentEvents, useChat } from '@tanstack/ai-react'
3import { DevtoolsHarness } from '@/components/DevtoolsHarness'
4import { parseDevtoolsRouteSearch } from '@/lib/devtools-test'
5import { SUBAGENT_PROMPTS } from '@/lib/subagents-test'
6​
7/**
8 * The `route` subagent scenario with the AI devtools panel. The researcher
9 * child thinks, calls `lookupFacts`, then answers. The panel must show that
10 * work the same way it shows the root agent's work.
11 */
12function DevtoolsSubagentsRoute() {
13 const { testId, aimockPort } = Route.useSearch()
14 const chat = useChat({
15 threadId: `devtools-subagents-${testId ?? 'manual'}`,
16 connection: fetchServerSentEvents('/api/subagents-test'),
17 body: { scenario: 'route', testId, aimockPort },
18 devtools: { name: 'Blog Desk' },
19 })
20 const cards = chat.messages.flatMap((message) =>
21 message.parts.flatMap((part) =>
22 part.type === 'subagent' ? [part.subagent] : [],
23 ),
24 )
25​
26 return (
27 <DevtoolsHarness>
28 <button
29 type="button"
30 data-testid="run"
31 onClick={() => void chat.sendMessage(SUBAGENT_PROMPTS.route)}
32 >
33 Run
34 </button>
35 <div data-testid="message-count">{chat.messages.length}</div>
36 {cards.map((card) => (
37 <span key={card.id} data-testid={`card-status-${card.name}`}>
38 {card.status}
39 </span>
40 ))}
41 </DevtoolsHarness>
42 )
44​
45export const Route = createFileRoute('/devtools-subagents')({
46 component: DevtoolsSubagentsRoute,
47 validateSearch: parseDevtoolsRouteSearch,
48})