Open History to see the last commit
1import type { SubagentPartsProps, SubagentProps } from '@tanstack/ai-react/ui'
2import type { BlogChatOptions } from '@/chat-ui'
3
4// Only the researcher card draws this tool. The keys come from the
5// researcher's `tools`. The other parts use the root widgets from
6// `chat-ui.tsx`.
7const researcherTools: SubagentPartsProps<
8 BlogChatOptions,
9 'researcher'
10>['toolsComponents'] = {
11 lookupWikipedia: ({ part, result }) => (
12 <details className="mb-2 rounded border border-emerald-500/30 bg-emerald-500/5 p-2 text-xs text-emerald-300">
13 <summary className="cursor-pointer font-mono">
14 lookupWikipedia({part.arguments}) ({part.state})
15 </summary>
16 <pre className="mt-1 whitespace-pre-wrap text-gray-400">
17 {result === undefined
18 ? 'No result yet'
19 : typeof result.content === 'string'
20 ? result.content
21 : JSON.stringify(result.content)}
22 </pre>
23 </details>
24 ),
25}
26
27function AgentHeader({
28 name,
29 status,
30 onStop,
31}: {
32 name: string
33 status: string
34 onStop?: () => void
35}) {
36 return (
37 <header className="mb-3 flex flex-wrap items-center gap-2">
38 <strong className="text-sm uppercase tracking-wide">{name}</strong>
39 <span className="text-xs opacity-70">{status}</span>
40 {status === 'running' && onStop ? (
41 <button
42 type="button"
43 onClick={onStop}
44 className="rounded bg-red-600 px-2 py-1 text-xs font-medium text-white hover:bg-red-700"
45 >
46 Stop
47 </button>
48 ) : null}
49 </header>
50 )
51}
52
53export function Researcher({
54 subagent,
55 Parts,
56}: SubagentProps<BlogChatOptions, 'researcher'>) {
57 return (
58 <section className="mt-3 rounded-lg border border-orange-500/30 bg-gray-900/80 p-3 text-gray-100">
59 <AgentHeader
60 name={subagent.name}
61 status={subagent.status}
62 onStop={subagent.stop}
63 />
64 {subagent.error ? (
65 <p className="text-xs text-red-400">{subagent.error.message}</p>
66 ) : null}
67 <div className="mt-2">
68 <Parts toolsComponents={researcherTools} />
69 </div>
70 </section>
71 )
72}
73
74export function Seo({
75 subagent,
76 Parts,
77}: SubagentProps<BlogChatOptions, 'seo'>) {
78 return (
79 <section className="mt-3 rounded-lg border border-sky-500/40 bg-gray-900/80 p-3 text-gray-100">
80 <AgentHeader
81 name={subagent.name}
82 status={subagent.status}
83 onStop={subagent.stop}
84 />
85 {subagent.error ? (
86 <p className="text-xs text-red-400">{subagent.error.message}</p>
87 ) : null}
88 <div className="mt-2">
89 <Parts />
90 </div>
91 </section>
92 )
93}
94
95export function Writer({
96 subagent,
97 Parts,
98}: SubagentProps<BlogChatOptions, 'writer'>) {
99 return (
100 <article className="writer-article">
101 <AgentHeader
102 name={subagent.name}
103 status={subagent.status}
104 onStop={subagent.stop}
105 />
106 {subagent.error ? (
107 <p className="text-sm text-red-700">{subagent.error.message}</p>
108 ) : null}
109 <Parts />
110 </article>
111 )
112}