Open History to see the last commit
1import { toolDefinition } from '@tanstack/ai'
2import { z } from 'zod'
3
4/**
5 * Shared by `/api/subagents-test` (server) and `/subagents-test` (client).
6 * The client needs the definition to render the child's approval.
7 */
8export const deleteLogs = toolDefinition({
9 name: 'deleteLogs',
10 description: 'Delete old log files',
11 needsApproval: true,
12 inputSchema: z.object({ folder: z.string() }),
13})
14
15export const lookupFacts = toolDefinition({
16 name: 'lookupFacts',
17 description: 'Look up facts about a topic',
18 inputSchema: z.object({ topic: z.string() }),
19})
20
21export type SubagentScenario =
22 | 'route'
23 | 'approval'
24 | 'tool'
25 | 'brief'
26 | 'result'
27 | 'limits'
28 | 'session'
29 | 'keys'
30 | 'routed-brief'
31
32/** The key the `keys` scenario passes in `subagents.keys`. */
33export const SUBAGENT_E2E_KEY = 'sk-e2e-subagent-key'
34
35/** The user message for each scenario. It matches `fixtures/subagents`. */
36export const SUBAGENT_PROMPTS: Record<SubagentScenario, string> = {
37 route: '[subagent-route] research squids',
38 approval: '[subagent-approval] clean up the old logs',
39 tool: '[subagent-tool] research squids',
40 brief: '[subagent-brief] compare squid facts',
41 result: '[subagent-result] price vendor a',
42 limits: '[subagent-limits] research two topics',
43 session: '[subagent-session] take squid notes',
44 keys: '[subagent-keys] write a draft',
45 'routed-brief': '[subagent-routed-brief] compare squid facts',
46}
47
48export function isSubagentScenario(value: unknown): value is SubagentScenario {
49 return (
50 value === 'route' ||
51 value === 'approval' ||
52 value === 'tool' ||
53 value === 'brief' ||
54 value === 'result' ||
55 value === 'limits' ||
56 value === 'session' ||
57 value === 'keys' ||
58 value === 'routed-brief'
59 )
60}