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

subagents-test.ts

63 lines1.8 KB

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-approval'
25 | 'tool'
26 | 'brief'
27 | 'result'
28 | 'limits'
29 | 'session'
30 | 'keys'
31 | 'routed-brief'
32​
33/** The key the `keys` scenario passes in `subagents.keys`. */
34export const SUBAGENT_E2E_KEY = 'sk-e2e-subagent-key'
35​
36/** The user message for each scenario. It matches `fixtures/subagents`. */
37export const SUBAGENT_PROMPTS: Record<SubagentScenario, string> = {
38 route: '[subagent-route] research squids',
39 approval: '[subagent-approval] clean up the old logs',
40 'tool-approval': '[subagent-tool-approval] clean up the old logs',
41 tool: '[subagent-tool] research squids',
42 brief: '[subagent-brief] compare squid facts',
43 result: '[subagent-result] price vendor a',
44 limits: '[subagent-limits] research two topics',
45 session: '[subagent-session] take squid notes',
46 keys: '[subagent-keys] write a draft',
47 'routed-brief': '[subagent-routed-brief] compare squid facts',
49​
50export function isSubagentScenario(value: unknown): value is SubagentScenario {
51 return (
52 value === 'route' ||
53 value === 'approval' ||
54 value === 'tool-approval' ||
55 value === 'tool' ||
56 value === 'brief' ||
57 value === 'result' ||
58 value === 'limits' ||
59 value === 'session' ||
60 value === 'keys' ||
61 value === 'routed-brief'
62 )