@langchain/langgraph-sdk 1.5.6 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/index.d.cts +5 -1
  2. package/dist/index.d.ts +5 -1
  3. package/dist/react/index.cjs +6 -0
  4. package/dist/react/index.d.cts +7 -2
  5. package/dist/react/index.d.ts +7 -2
  6. package/dist/react/index.js +2 -1
  7. package/dist/react/stream.cjs.map +1 -1
  8. package/dist/react/stream.custom.cjs +36 -7
  9. package/dist/react/stream.custom.cjs.map +1 -1
  10. package/dist/react/stream.custom.d.cts.map +1 -1
  11. package/dist/react/stream.custom.d.ts.map +1 -1
  12. package/dist/react/stream.custom.js +36 -7
  13. package/dist/react/stream.custom.js.map +1 -1
  14. package/dist/react/stream.d.cts +51 -31
  15. package/dist/react/stream.d.cts.map +1 -1
  16. package/dist/react/stream.d.ts +51 -31
  17. package/dist/react/stream.d.ts.map +1 -1
  18. package/dist/react/stream.js.map +1 -1
  19. package/dist/react/stream.lgp.cjs +45 -13
  20. package/dist/react/stream.lgp.cjs.map +1 -1
  21. package/dist/react/stream.lgp.js +45 -13
  22. package/dist/react/stream.lgp.js.map +1 -1
  23. package/dist/react/types.d.cts +5 -88
  24. package/dist/react/types.d.cts.map +1 -1
  25. package/dist/react/types.d.ts +5 -88
  26. package/dist/react/types.d.ts.map +1 -1
  27. package/dist/react-ui/client.cjs.map +1 -1
  28. package/dist/react-ui/client.d.cts +5 -3
  29. package/dist/react-ui/client.d.cts.map +1 -1
  30. package/dist/react-ui/client.d.ts +5 -3
  31. package/dist/react-ui/client.d.ts.map +1 -1
  32. package/dist/react-ui/client.js.map +1 -1
  33. package/dist/schema.d.cts.map +1 -1
  34. package/dist/schema.d.ts.map +1 -1
  35. package/dist/types.stream.d.ts.map +1 -1
  36. package/dist/ui/manager.cjs +140 -14
  37. package/dist/ui/manager.cjs.map +1 -1
  38. package/dist/ui/manager.js +140 -14
  39. package/dist/ui/manager.js.map +1 -1
  40. package/dist/ui/stream/agent.d.cts +143 -0
  41. package/dist/ui/stream/agent.d.cts.map +1 -0
  42. package/dist/ui/stream/agent.d.ts +143 -0
  43. package/dist/ui/stream/agent.d.ts.map +1 -0
  44. package/dist/ui/stream/base.d.cts +144 -0
  45. package/dist/ui/stream/base.d.cts.map +1 -0
  46. package/dist/ui/stream/base.d.ts +144 -0
  47. package/dist/ui/stream/base.d.ts.map +1 -0
  48. package/dist/ui/stream/deep-agent.d.cts +277 -0
  49. package/dist/ui/stream/deep-agent.d.cts.map +1 -0
  50. package/dist/ui/stream/deep-agent.d.ts +277 -0
  51. package/dist/ui/stream/deep-agent.d.ts.map +1 -0
  52. package/dist/ui/stream/index.d.cts +172 -0
  53. package/dist/ui/stream/index.d.cts.map +1 -0
  54. package/dist/ui/stream/index.d.ts +172 -0
  55. package/dist/ui/stream/index.d.ts.map +1 -0
  56. package/dist/ui/subagents.cjs +593 -0
  57. package/dist/ui/subagents.cjs.map +1 -0
  58. package/dist/ui/subagents.d.cts +291 -0
  59. package/dist/ui/subagents.d.cts.map +1 -0
  60. package/dist/ui/subagents.d.ts +291 -0
  61. package/dist/ui/subagents.d.ts.map +1 -0
  62. package/dist/ui/subagents.js +589 -0
  63. package/dist/ui/subagents.js.map +1 -0
  64. package/dist/ui/types.d.cts +384 -5
  65. package/dist/ui/types.d.cts.map +1 -1
  66. package/dist/ui/types.d.ts +384 -5
  67. package/dist/ui/types.d.ts.map +1 -1
  68. package/package.json +6 -3
@@ -0,0 +1,277 @@
1
+ import { DefaultToolCall } from "../../types.messages.js";
2
+ import { BagTemplate } from "../../types.template.js";
3
+ import { DefaultSubagentStates, SubagentStream } from "../types.js";
4
+ import { UseAgentStream, UseAgentStreamOptions } from "./agent.js";
5
+
6
+ //#region src/ui/stream/deep-agent.d.ts
7
+
8
+ /**
9
+ * Stream interface for DeepAgent instances created with `createDeepAgent`.
10
+ *
11
+ * Extends {@link UseAgentStream} with subagent streaming capabilities. Subagent
12
+ * streams are automatically typed based on the agent's subagent configuration,
13
+ * enabling type-safe access to subagent state and messages.
14
+ *
15
+ * Use this interface when streaming from an agent created with `createDeepAgent`
16
+ * that orchestrates multiple specialized subagents.
17
+ *
18
+ * @experimental This interface is subject to change.
19
+ *
20
+ * @template StateType - The agent's state type
21
+ * @template ToolCall - Tool call type from agent's tools
22
+ * @template SubagentStates - Map of subagent names to their state types
23
+ * @template Bag - Type configuration bag
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * import { createDeepAgent } from "deepagents";
28
+ * import { useStream } from "@langchain/langgraph-sdk/react";
29
+ *
30
+ * // Define subagents with typed middleware
31
+ * const agent = createDeepAgent({
32
+ * subagents: [
33
+ * {
34
+ * name: "researcher",
35
+ * description: "Research specialist",
36
+ * middleware: [ResearchMiddleware],
37
+ * },
38
+ * {
39
+ * name: "writer",
40
+ * description: "Content writer",
41
+ * middleware: [WriterMiddleware],
42
+ * },
43
+ * ] as const, // Important: use 'as const' for type inference
44
+ * });
45
+ *
46
+ * // In React component:
47
+ * function Chat() {
48
+ * const stream = useStream<typeof agent>({
49
+ * assistantId: "deep-agent",
50
+ * apiUrl: "http://localhost:2024",
51
+ * filterSubagentMessages: true, // Only show main agent messages
52
+ * });
53
+ *
54
+ * // Subagent streams are typed!
55
+ * const researchers = stream.getSubagentsByType("researcher");
56
+ * researchers.forEach(subagent => {
57
+ * // subagent.values.messages is typed as Message<ToolCall>[]
58
+ * // subagent.status is "pending" | "running" | "complete" | "error"
59
+ * console.log("Researcher status:", subagent.status);
60
+ * });
61
+ *
62
+ * // Track all active subagents
63
+ * stream.activeSubagents.forEach(subagent => {
64
+ * console.log(`${subagent.toolCall.args.subagent_type} is running...`);
65
+ * });
66
+ * }
67
+ * ```
68
+ *
69
+ * @remarks
70
+ * This interface adds subagent streaming on top of {@link UseAgentStream}:
71
+ * - `subagents` - Map of all subagent streams by tool call ID
72
+ * - `activeSubagents` - Array of currently running subagents
73
+ * - `getSubagent(id)` - Get a specific subagent by tool call ID
74
+ * - `getSubagentsByType(type)` - Get all subagents of a specific type with typed state
75
+ * - `getSubagentsByMessage(messageId)` - Get all subagents triggered by a specific AI message
76
+ *
77
+ * It also enables the `filterSubagentMessages` option to exclude subagent
78
+ * messages from the main `messages` array.
79
+ */
80
+ interface UseDeepAgentStream<StateType extends Record<string, unknown> = Record<string, unknown>, ToolCall = DefaultToolCall, SubagentStates extends Record<string, unknown> = DefaultSubagentStates, Bag extends BagTemplate = BagTemplate> extends UseAgentStream<StateType, ToolCall, Bag> {
81
+ /**
82
+ * All currently active and completed subagent streams.
83
+ *
84
+ * Keyed by tool call ID for easy lookup. Includes subagents in all states:
85
+ * pending, running, complete, and error.
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * // Iterate over all subagents
90
+ * stream.subagents.forEach((subagent, toolCallId) => {
91
+ * console.log(`Subagent ${toolCallId}: ${subagent.status}`);
92
+ * });
93
+ *
94
+ * // Get a specific subagent
95
+ * const specific = stream.subagents.get("call_abc123");
96
+ * ```
97
+ */
98
+ subagents: Map<string, SubagentStream<SubagentStates[keyof SubagentStates], ToolCall>>;
99
+ /**
100
+ * Currently active subagents (where status === "running").
101
+ *
102
+ * Use this to track and display subagents that are actively executing.
103
+ * Completed or errored subagents are not included.
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * // Show loading indicators for active subagents
108
+ * stream.activeSubagents.map(subagent => (
109
+ * <SubagentCard
110
+ * key={subagent.id}
111
+ * type={subagent.toolCall.args.subagent_type}
112
+ * isLoading={true}
113
+ * />
114
+ * ));
115
+ * ```
116
+ */
117
+ activeSubagents: SubagentStream<SubagentStates[keyof SubagentStates], ToolCall>[];
118
+ /**
119
+ * Get subagent stream by tool call ID.
120
+ *
121
+ * Use this when you have a specific tool call ID and need to access
122
+ * its corresponding subagent stream.
123
+ *
124
+ * @param toolCallId - The tool call ID that initiated the subagent
125
+ * @returns The subagent stream, or undefined if not found
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * // In a tool call component
130
+ * const subagent = stream.getSubagent(toolCall.id);
131
+ * if (subagent) {
132
+ * return <SubagentProgress subagent={subagent} />;
133
+ * }
134
+ * ```
135
+ */
136
+ getSubagent: (toolCallId: string) => SubagentStream<SubagentStates[keyof SubagentStates], ToolCall> | undefined;
137
+ /**
138
+ * Get all subagents of a specific type.
139
+ *
140
+ * Returns streams with properly inferred state types based on subagent name.
141
+ * When called with a literal string that matches a subagent name, TypeScript
142
+ * will infer the correct state type for that subagent.
143
+ *
144
+ * @param type - The subagent_type to filter by
145
+ * @returns Array of matching subagent streams with inferred state types
146
+ *
147
+ * @example
148
+ * ```typescript
149
+ * // Get all researcher subagents with typed state
150
+ * const researchers = stream.getSubagentsByType("researcher");
151
+ *
152
+ * researchers.forEach(researcher => {
153
+ * // researcher.values is typed based on ResearchMiddleware
154
+ * console.log("Research messages:", researcher.values.messages.length);
155
+ * console.log("Status:", researcher.status);
156
+ * });
157
+ *
158
+ * // Get all writer subagents
159
+ * const writers = stream.getSubagentsByType("writer");
160
+ * // writers have different state type based on WriterMiddleware
161
+ * ```
162
+ */
163
+ getSubagentsByType: {
164
+ /**
165
+ * Overload for known subagent names - returns typed streams.
166
+ * TypeScript infers the state type from SubagentStates[TName].
167
+ */
168
+ <TName extends keyof SubagentStates & string>(type: TName): SubagentStream<SubagentStates[TName], ToolCall>[];
169
+ /**
170
+ * Overload for unknown names - returns untyped streams.
171
+ * Used when the subagent name is not known at compile time.
172
+ */
173
+ (type: string): SubagentStream<Record<string, unknown>, ToolCall>[];
174
+ };
175
+ /**
176
+ * Get all subagents triggered by a specific AI message.
177
+ *
178
+ * Useful for rendering subagent activities grouped by conversation turn.
179
+ * Each AI message that contains subagent tool calls will have its triggered
180
+ * subagents returned by this method.
181
+ *
182
+ * @param messageId - The ID of the AI message that triggered the subagents
183
+ * @returns Array of subagent streams triggered by that message
184
+ *
185
+ * @example
186
+ * ```tsx
187
+ * // Render subagents inline after the AI message that triggered them
188
+ * {stream.messages.map((msg) => (
189
+ * <div key={msg.id}>
190
+ * <MessageBubble message={msg} />
191
+ * {msg.type === "ai" && "tool_calls" in msg && (
192
+ * <SubagentPipeline
193
+ * subagents={stream.getSubagentsByMessage(msg.id)}
194
+ * />
195
+ * )}
196
+ * </div>
197
+ * ))}
198
+ * ```
199
+ */
200
+ getSubagentsByMessage: (messageId: string) => SubagentStream<SubagentStates[keyof SubagentStates], ToolCall>[];
201
+ }
202
+ /**
203
+ * Options for configuring a deep agent stream.
204
+ *
205
+ * Use this options interface when calling `useStream` with a DeepAgent
206
+ * created via `createDeepAgent`. Includes all agent options plus
207
+ * subagent-specific configuration.
208
+ *
209
+ * @template StateType - The agent's state type
210
+ * @template Bag - Type configuration bag
211
+ *
212
+ * @example
213
+ * ```typescript
214
+ * const stream = useStream<typeof agent>({
215
+ * assistantId: "deep-agent",
216
+ * apiUrl: "http://localhost:2024",
217
+ *
218
+ * // DeepAgent-specific options
219
+ * subagentToolNames: ["task", "delegate"],
220
+ * filterSubagentMessages: true,
221
+ *
222
+ * onError: (error) => console.error(error),
223
+ * });
224
+ * ```
225
+ */
226
+ interface UseDeepAgentStreamOptions<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> extends UseAgentStreamOptions<StateType, Bag> {
227
+ /**
228
+ * Tool names that indicate subagent invocation.
229
+ *
230
+ * When an AI message contains tool calls with these names, they are
231
+ * automatically tracked as subagent executions. This enables the
232
+ * `subagents`, `activeSubagents`, `getSubagent()`, `getSubagentsByType()`, and `getSubagentsByMessage()`
233
+ * properties on the stream.
234
+ *
235
+ * @default ["task"]
236
+ *
237
+ * @example
238
+ * ```typescript
239
+ * const stream = useStream<typeof agent>({
240
+ * assistantId: "deep-agent",
241
+ * // Track both "task" and "delegate" as subagent tools
242
+ * subagentToolNames: ["task", "delegate", "spawn_agent"],
243
+ * });
244
+ *
245
+ * // Now stream.subagents will include executions from any of these tools
246
+ * ```
247
+ */
248
+ subagentToolNames?: string[];
249
+ /**
250
+ * Whether to filter out messages from subagent namespaces.
251
+ *
252
+ * When `true`, only messages from the main agent are included in
253
+ * the `messages` array. Subagent messages are still accessible via
254
+ * the `subagents` map and individual subagent streams.
255
+ *
256
+ * This is useful when you want to display subagent progress separately
257
+ * from the main conversation, or when subagent messages would be too
258
+ * verbose in the main message list.
259
+ *
260
+ * @default false
261
+ *
262
+ * @example
263
+ * ```typescript
264
+ * const stream = useStream<typeof agent>({
265
+ * assistantId: "deep-agent",
266
+ * filterSubagentMessages: true,
267
+ * });
268
+ *
269
+ * // stream.messages only contains main agent messages
270
+ * // Subagent messages are in stream.getSubagentsByType("researcher")[0].messages
271
+ * ```
272
+ */
273
+ filterSubagentMessages?: boolean;
274
+ }
275
+ //#endregion
276
+ export { UseDeepAgentStream, UseDeepAgentStreamOptions };
277
+ //# sourceMappingURL=deep-agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep-agent.d.ts","names":["DefaultToolCall","BagTemplate","SubagentStream","DefaultSubagentStates","UseAgentStream","UseAgentStreamOptions","UseDeepAgentStream","Record","StateType","ToolCall","Bag","SubagentStates","Map","TName","UseDeepAgentStreamOptions"],"sources":["../../../src/ui/stream/deep-agent.d.ts"],"sourcesContent":["/**\n * Stream types for DeepAgent instances created with `createDeepAgent`.\n *\n * This module provides the stream interface that adds subagent streaming\n * capabilities on top of agent streaming functionality.\n *\n * @module\n */\nimport type { DefaultToolCall } from \"../../types.messages.js\";\nimport type { BagTemplate } from \"../../types.template.js\";\nimport type { SubagentStream, DefaultSubagentStates } from \"../types.js\";\nimport type { UseAgentStream, UseAgentStreamOptions } from \"./agent.js\";\n/**\n * Stream interface for DeepAgent instances created with `createDeepAgent`.\n *\n * Extends {@link UseAgentStream} with subagent streaming capabilities. Subagent\n * streams are automatically typed based on the agent's subagent configuration,\n * enabling type-safe access to subagent state and messages.\n *\n * Use this interface when streaming from an agent created with `createDeepAgent`\n * that orchestrates multiple specialized subagents.\n *\n * @experimental This interface is subject to change.\n *\n * @template StateType - The agent's state type\n * @template ToolCall - Tool call type from agent's tools\n * @template SubagentStates - Map of subagent names to their state types\n * @template Bag - Type configuration bag\n *\n * @example\n * ```typescript\n * import { createDeepAgent } from \"deepagents\";\n * import { useStream } from \"@langchain/langgraph-sdk/react\";\n *\n * // Define subagents with typed middleware\n * const agent = createDeepAgent({\n * subagents: [\n * {\n * name: \"researcher\",\n * description: \"Research specialist\",\n * middleware: [ResearchMiddleware],\n * },\n * {\n * name: \"writer\",\n * description: \"Content writer\",\n * middleware: [WriterMiddleware],\n * },\n * ] as const, // Important: use 'as const' for type inference\n * });\n *\n * // In React component:\n * function Chat() {\n * const stream = useStream<typeof agent>({\n * assistantId: \"deep-agent\",\n * apiUrl: \"http://localhost:2024\",\n * filterSubagentMessages: true, // Only show main agent messages\n * });\n *\n * // Subagent streams are typed!\n * const researchers = stream.getSubagentsByType(\"researcher\");\n * researchers.forEach(subagent => {\n * // subagent.values.messages is typed as Message<ToolCall>[]\n * // subagent.status is \"pending\" | \"running\" | \"complete\" | \"error\"\n * console.log(\"Researcher status:\", subagent.status);\n * });\n *\n * // Track all active subagents\n * stream.activeSubagents.forEach(subagent => {\n * console.log(`${subagent.toolCall.args.subagent_type} is running...`);\n * });\n * }\n * ```\n *\n * @remarks\n * This interface adds subagent streaming on top of {@link UseAgentStream}:\n * - `subagents` - Map of all subagent streams by tool call ID\n * - `activeSubagents` - Array of currently running subagents\n * - `getSubagent(id)` - Get a specific subagent by tool call ID\n * - `getSubagentsByType(type)` - Get all subagents of a specific type with typed state\n * - `getSubagentsByMessage(messageId)` - Get all subagents triggered by a specific AI message\n *\n * It also enables the `filterSubagentMessages` option to exclude subagent\n * messages from the main `messages` array.\n */\nexport interface UseDeepAgentStream<StateType extends Record<string, unknown> = Record<string, unknown>, ToolCall = DefaultToolCall, SubagentStates extends Record<string, unknown> = DefaultSubagentStates, Bag extends BagTemplate = BagTemplate> extends UseAgentStream<StateType, ToolCall, Bag> {\n /**\n * All currently active and completed subagent streams.\n *\n * Keyed by tool call ID for easy lookup. Includes subagents in all states:\n * pending, running, complete, and error.\n *\n * @example\n * ```typescript\n * // Iterate over all subagents\n * stream.subagents.forEach((subagent, toolCallId) => {\n * console.log(`Subagent ${toolCallId}: ${subagent.status}`);\n * });\n *\n * // Get a specific subagent\n * const specific = stream.subagents.get(\"call_abc123\");\n * ```\n */\n subagents: Map<string, SubagentStream<SubagentStates[keyof SubagentStates], ToolCall>>;\n /**\n * Currently active subagents (where status === \"running\").\n *\n * Use this to track and display subagents that are actively executing.\n * Completed or errored subagents are not included.\n *\n * @example\n * ```typescript\n * // Show loading indicators for active subagents\n * stream.activeSubagents.map(subagent => (\n * <SubagentCard\n * key={subagent.id}\n * type={subagent.toolCall.args.subagent_type}\n * isLoading={true}\n * />\n * ));\n * ```\n */\n activeSubagents: SubagentStream<SubagentStates[keyof SubagentStates], ToolCall>[];\n /**\n * Get subagent stream by tool call ID.\n *\n * Use this when you have a specific tool call ID and need to access\n * its corresponding subagent stream.\n *\n * @param toolCallId - The tool call ID that initiated the subagent\n * @returns The subagent stream, or undefined if not found\n *\n * @example\n * ```typescript\n * // In a tool call component\n * const subagent = stream.getSubagent(toolCall.id);\n * if (subagent) {\n * return <SubagentProgress subagent={subagent} />;\n * }\n * ```\n */\n getSubagent: (toolCallId: string) => SubagentStream<SubagentStates[keyof SubagentStates], ToolCall> | undefined;\n /**\n * Get all subagents of a specific type.\n *\n * Returns streams with properly inferred state types based on subagent name.\n * When called with a literal string that matches a subagent name, TypeScript\n * will infer the correct state type for that subagent.\n *\n * @param type - The subagent_type to filter by\n * @returns Array of matching subagent streams with inferred state types\n *\n * @example\n * ```typescript\n * // Get all researcher subagents with typed state\n * const researchers = stream.getSubagentsByType(\"researcher\");\n *\n * researchers.forEach(researcher => {\n * // researcher.values is typed based on ResearchMiddleware\n * console.log(\"Research messages:\", researcher.values.messages.length);\n * console.log(\"Status:\", researcher.status);\n * });\n *\n * // Get all writer subagents\n * const writers = stream.getSubagentsByType(\"writer\");\n * // writers have different state type based on WriterMiddleware\n * ```\n */\n getSubagentsByType: {\n /**\n * Overload for known subagent names - returns typed streams.\n * TypeScript infers the state type from SubagentStates[TName].\n */\n <TName extends keyof SubagentStates & string>(type: TName): SubagentStream<SubagentStates[TName], ToolCall>[];\n /**\n * Overload for unknown names - returns untyped streams.\n * Used when the subagent name is not known at compile time.\n */\n (type: string): SubagentStream<Record<string, unknown>, ToolCall>[];\n };\n /**\n * Get all subagents triggered by a specific AI message.\n *\n * Useful for rendering subagent activities grouped by conversation turn.\n * Each AI message that contains subagent tool calls will have its triggered\n * subagents returned by this method.\n *\n * @param messageId - The ID of the AI message that triggered the subagents\n * @returns Array of subagent streams triggered by that message\n *\n * @example\n * ```tsx\n * // Render subagents inline after the AI message that triggered them\n * {stream.messages.map((msg) => (\n * <div key={msg.id}>\n * <MessageBubble message={msg} />\n * {msg.type === \"ai\" && \"tool_calls\" in msg && (\n * <SubagentPipeline\n * subagents={stream.getSubagentsByMessage(msg.id)}\n * />\n * )}\n * </div>\n * ))}\n * ```\n */\n getSubagentsByMessage: (messageId: string) => SubagentStream<SubagentStates[keyof SubagentStates], ToolCall>[];\n}\n/**\n * Options for configuring a deep agent stream.\n *\n * Use this options interface when calling `useStream` with a DeepAgent\n * created via `createDeepAgent`. Includes all agent options plus\n * subagent-specific configuration.\n *\n * @template StateType - The agent's state type\n * @template Bag - Type configuration bag\n *\n * @example\n * ```typescript\n * const stream = useStream<typeof agent>({\n * assistantId: \"deep-agent\",\n * apiUrl: \"http://localhost:2024\",\n *\n * // DeepAgent-specific options\n * subagentToolNames: [\"task\", \"delegate\"],\n * filterSubagentMessages: true,\n *\n * onError: (error) => console.error(error),\n * });\n * ```\n */\nexport interface UseDeepAgentStreamOptions<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> extends UseAgentStreamOptions<StateType, Bag> {\n /**\n * Tool names that indicate subagent invocation.\n *\n * When an AI message contains tool calls with these names, they are\n * automatically tracked as subagent executions. This enables the\n * `subagents`, `activeSubagents`, `getSubagent()`, `getSubagentsByType()`, and `getSubagentsByMessage()`\n * properties on the stream.\n *\n * @default [\"task\"]\n *\n * @example\n * ```typescript\n * const stream = useStream<typeof agent>({\n * assistantId: \"deep-agent\",\n * // Track both \"task\" and \"delegate\" as subagent tools\n * subagentToolNames: [\"task\", \"delegate\", \"spawn_agent\"],\n * });\n *\n * // Now stream.subagents will include executions from any of these tools\n * ```\n */\n subagentToolNames?: string[];\n /**\n * Whether to filter out messages from subagent namespaces.\n *\n * When `true`, only messages from the main agent are included in\n * the `messages` array. Subagent messages are still accessible via\n * the `subagents` map and individual subagent streams.\n *\n * This is useful when you want to display subagent progress separately\n * from the main conversation, or when subagent messages would be too\n * verbose in the main message list.\n *\n * @default false\n *\n * @example\n * ```typescript\n * const stream = useStream<typeof agent>({\n * assistantId: \"deep-agent\",\n * filterSubagentMessages: true,\n * });\n *\n * // stream.messages only contains main agent messages\n * // Subagent messages are in stream.getSubagentsByType(\"researcher\")[0].messages\n * ```\n */\n filterSubagentMessages?: boolean;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAlJiBM,qCAAqCC,0BAA0BA,oCAAoCP,wCAAwCO,0BAA0BJ,mCAAmCF,cAAcA,qBAAqBG,eAAeI,WAAWC,UAAUC;;;;;;;;;;;;;;;;;;aAkBjRE,YAAYV,eAAeS,qBAAqBA,iBAAiBF;;;;;;;;;;;;;;;;;;;mBAmB3DP,eAAeS,qBAAqBA,iBAAiBF;;;;;;;;;;;;;;;;;;;uCAmBjCP,eAAeS,qBAAqBA,iBAAiBF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBAgCjEE,+BAA+BE,QAAQX,eAAeS,eAAeE,QAAQJ;;;;;oBAKlFP,eAAeK,yBAAyBE;;;;;;;;;;;;;;;;;;;;;;;;;;;gDA2BdP,eAAeS,qBAAqBA,iBAAiBF;;;;;;;;;;;;;;;;;;;;;;;;;;UA0BtFK,4CAA4CP,0BAA0BA,qCAAqCN,cAAcA,qBAAqBI,sBAAsBG,WAAWE"}
@@ -0,0 +1,172 @@
1
+ import { DefaultToolCall } from "../../types.messages.cjs";
2
+ import { BagTemplate } from "../../types.template.cjs";
3
+ import { AgentTypeConfigLike, DeepAgentTypeConfigLike, DefaultSubagentStates, InferAgentState, InferAgentToolCalls, SubagentStateMap, UseStreamOptions } from "../types.cjs";
4
+ import { BaseStream } from "./base.cjs";
5
+ import { UseAgentStream, UseAgentStreamOptions } from "./agent.cjs";
6
+ import { UseDeepAgentStream, UseDeepAgentStreamOptions } from "./deep-agent.cjs";
7
+
8
+ //#region src/ui/stream/index.d.ts
9
+
10
+ /**
11
+ * Check if a type is a DeepAgent (has `~deepAgentTypes` phantom property).
12
+ */
13
+ type IsDeepAgent<T> = T extends {
14
+ "~deepAgentTypes": DeepAgentTypeConfigLike;
15
+ } ? true : false;
16
+ /**
17
+ * Check if a type is a ReactAgent (has `~agentTypes` but not `~deepAgentTypes`).
18
+ */
19
+ type IsReactAgent<T> = T extends {
20
+ "~agentTypes": AgentTypeConfigLike;
21
+ } ? T extends {
22
+ "~deepAgentTypes": unknown;
23
+ } ? false : true : false;
24
+ /**
25
+ * Infer the state type from an agent, graph, or direct state type.
26
+ *
27
+ * Detection order:
28
+ * 1. Agent-like (`~agentTypes`) → InferAgentState
29
+ * 2. CompiledGraph (`~RunOutput`) → Extract RunOutput
30
+ * 3. Pregel (`~OutputType`) → Extract OutputType
31
+ * 4. Direct state type → Return as-is
32
+ */
33
+ type InferStateType<T> = T extends {
34
+ "~agentTypes": unknown;
35
+ } ? InferAgentState<T> : T extends {
36
+ "~RunOutput": infer S;
37
+ } ? S extends Record<string, unknown> ? S : Record<string, unknown> : T extends {
38
+ "~OutputType": infer O;
39
+ } ? O extends Record<string, unknown> ? O : Record<string, unknown> : T extends Record<string, unknown> ? T : Record<string, unknown>;
40
+ /**
41
+ * Infer the node names from a compiled graph.
42
+ *
43
+ * Extracts the `~NodeType` phantom property from CompiledGraph instances,
44
+ * providing a union of all node names defined in the graph.
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * const graph = new StateGraph(StateAnnotation)
49
+ * .addNode("agent", agentFn)
50
+ * .addNode("tool", toolFn)
51
+ * .compile();
52
+ *
53
+ * type NodeNames = InferNodeNames<typeof graph>; // "agent" | "tool"
54
+ * ```
55
+ */
56
+ type InferNodeNames<T> = T extends {
57
+ "~NodeType": infer N;
58
+ } ? N extends string ? Exclude<N, "__start__"> : string : string;
59
+ /**
60
+ * Infer the per-node return types from a compiled graph.
61
+ *
62
+ * Extracts the `~NodeReturnType` phantom property from CompiledGraph instances,
63
+ * which is a mapped type of `{ [nodeName]: ReturnType }` for each node.
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const graph = new StateGraph(StateAnnotation)
68
+ * .addNode("dispatcher", async () => ({ topic: "foo" }))
69
+ * .addNode("researcher", async () => ({ research: "bar" }))
70
+ * .compile();
71
+ *
72
+ * type NodeReturns = InferNodeReturnTypes<typeof graph>;
73
+ * // { dispatcher: { topic: string }; researcher: { research: string } }
74
+ * ```
75
+ */
76
+ type InferNodeReturnTypes<T> = T extends {
77
+ "~NodeReturnType": infer R;
78
+ } ? R extends Record<string, unknown> ? R : Record<string, Record<string, unknown>> : Record<string, Record<string, unknown>>;
79
+ /**
80
+ * Infer tool call types from an agent.
81
+ *
82
+ * For agents, extracts typed tool calls from the agent's tools.
83
+ * For non-agents, returns DefaultToolCall.
84
+ */
85
+ type InferToolCalls<T> = T extends {
86
+ "~agentTypes": unknown;
87
+ } ? InferAgentToolCalls<T> : DefaultToolCall;
88
+ /**
89
+ * Infer subagent state map from a DeepAgent.
90
+ *
91
+ * For DeepAgent, creates a map of subagent names to their state types.
92
+ * For non-DeepAgent, returns DefaultSubagentStates.
93
+ */
94
+ type InferSubagentStates<T> = T extends {
95
+ "~deepAgentTypes": unknown;
96
+ } ? SubagentStateMap<T, InferAgentToolCalls<T>> : DefaultSubagentStates;
97
+ /**
98
+ * Resolves the appropriate stream interface based on the agent/graph type.
99
+ *
100
+ * This type automatically selects the correct stream interface based on
101
+ * the type of agent or graph passed to `useStream`:
102
+ *
103
+ * 1. **DeepAgent** (`~deepAgentTypes`) → {@link UseDeepAgentStream}
104
+ * - Includes: values, messages, toolCalls, subagents, getSubagentsByType, getSubagentsByMessage
105
+ *
106
+ * 2. **ReactAgent** (`~agentTypes`) → {@link UseAgentStream}
107
+ * - Includes: values, messages, toolCalls, getToolCalls
108
+ * - Excludes: subagents, getSubagentsByType
109
+ *
110
+ * 3. **CompiledGraph** (`~RunOutput`/`~OutputType`) → {@link UseGraphStream}
111
+ * - Includes: values, messages, submit, stop, nodes, getNodeStreamsByName
112
+ * - Excludes: toolCalls, subagents
113
+ * - Node names are inferred from `~NodeType` for type-safe access
114
+ *
115
+ * 4. **Default** → {@link UseGraphStream}
116
+ *
117
+ * @template T - The agent or graph type (use `typeof agent` or `typeof graph`)
118
+ * @template Bag - Type configuration bag for interrupts, configurable, etc.
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * // Automatic detection based on agent type
123
+ * type GraphStream = ResolveStreamInterface<typeof compiledGraph, BagTemplate>;
124
+ * // → UseGraphStream (with typed node names)
125
+ *
126
+ * type AgentStream = ResolveStreamInterface<typeof reactAgent, BagTemplate>;
127
+ * // → UseAgentStream (has toolCalls)
128
+ *
129
+ * type DeepStream = ResolveStreamInterface<typeof deepAgent, BagTemplate>;
130
+ * // → UseDeepAgentStream (has toolCalls AND subagents)
131
+ * ```
132
+ */
133
+ type ResolveStreamInterface<T, Bag extends BagTemplate = BagTemplate> = IsDeepAgent<T> extends true ? UseDeepAgentStream<InferStateType<T>, InferToolCalls<T>, InferSubagentStates<T>, Bag> : IsReactAgent<T> extends true ? UseAgentStream<InferStateType<T>, InferToolCalls<T>, Bag> : BaseStream<InferStateType<T>, InferToolCalls<T>, Bag>;
134
+ /**
135
+ * Resolves the appropriate options interface based on the agent/graph type.
136
+ *
137
+ * This type automatically selects the correct options interface based on
138
+ * the type of agent or graph:
139
+ *
140
+ * 1. **DeepAgent** → {@link UseDeepAgentStreamOptions}
141
+ * - Includes: `filterSubagentMessages` option
142
+ *
143
+ * 2. **ReactAgent** → {@link UseAgentStreamOptions}
144
+ *
145
+ * 3. **CompiledGraph** / **Default** → {@link UseGraphStreamOptions}
146
+ *
147
+ * @template T - The agent or graph type
148
+ * @template Bag - Type configuration bag
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * // Only DeepAgent options include filterSubagentMessages
153
+ * type DeepOptions = ResolveStreamOptions<typeof deepAgent, BagTemplate>;
154
+ * // DeepOptions.filterSubagentMessages exists
155
+ *
156
+ * type AgentOptions = ResolveStreamOptions<typeof reactAgent, BagTemplate>;
157
+ * // AgentOptions.filterSubagentMessages does NOT exist
158
+ * ```
159
+ */
160
+ type ResolveStreamOptions<T, Bag extends BagTemplate = BagTemplate> = IsDeepAgent<T> extends true ? UseDeepAgentStreamOptions<InferStateType<T>, Bag> : IsReactAgent<T> extends true ? UseAgentStreamOptions<InferStateType<T>, Bag> : UseStreamOptions<InferStateType<T>, Bag>;
161
+ /**
162
+ * Infer the Bag type from an agent, defaulting to the provided Bag.
163
+ *
164
+ * Currently returns the provided Bag for all types.
165
+ * Can be extended in the future to extract Bag from agent types.
166
+ */
167
+ type InferBag<T, B extends BagTemplate = BagTemplate> = T extends {
168
+ "~agentTypes": unknown;
169
+ } ? BagTemplate : B;
170
+ //#endregion
171
+ export { InferBag, InferNodeNames, InferNodeReturnTypes, InferStateType, InferSubagentStates, InferToolCalls, ResolveStreamInterface, ResolveStreamOptions };
172
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":["DefaultToolCall","BagTemplate","InferAgentState","InferAgentToolCalls","SubagentStateMap","DefaultSubagentStates","AgentTypeConfigLike","DeepAgentTypeConfigLike","UseStreamOptions","BaseStream","UseAgentStream","UseAgentStreamOptions","UseDeepAgentStream","UseDeepAgentStreamOptions","IsDeepAgent","T","IsReactAgent","InferStateType","S","Record","O","InferNodeNames","N","Exclude","InferNodeReturnTypes","R","InferToolCalls","InferSubagentStates","ResolveStreamInterface","Bag","ResolveStreamOptions","InferBag","B"],"sources":["../../../src/ui/stream/index.d.ts"],"sourcesContent":["/**\n * Unified stream type system for LangGraph.\n *\n * This module provides the type resolution system that automatically selects\n * the appropriate stream interface based on the agent/graph type:\n *\n * - **CompiledStateGraph** → {@link UseGraphStream}\n * - **ReactAgent** (createAgent) → {@link UseAgentStream}\n * - **DeepAgent** (createDeepAgent) → {@link UseDeepAgentStream}\n *\n * @module\n */\nimport type { DefaultToolCall } from \"../../types.messages.js\";\nimport type { BagTemplate } from \"../../types.template.js\";\nimport type { InferAgentState, InferAgentToolCalls, SubagentStateMap, DefaultSubagentStates, AgentTypeConfigLike, DeepAgentTypeConfigLike, UseStreamOptions } from \"../types.js\";\nimport type { BaseStream } from \"./base.js\";\nimport type { UseAgentStream, UseAgentStreamOptions } from \"./agent.js\";\nimport type { UseDeepAgentStream, UseDeepAgentStreamOptions } from \"./deep-agent.js\";\nexport type { BaseStream } from \"./base.js\";\nexport type { UseAgentStream, UseAgentStreamOptions } from \"./agent.js\";\nexport type { UseDeepAgentStream, UseDeepAgentStreamOptions, } from \"./deep-agent.js\";\n/**\n * Check if a type is a DeepAgent (has `~deepAgentTypes` phantom property).\n */\ntype IsDeepAgent<T> = T extends {\n \"~deepAgentTypes\": DeepAgentTypeConfigLike;\n} ? true : false;\n/**\n * Check if a type is a ReactAgent (has `~agentTypes` but not `~deepAgentTypes`).\n */\ntype IsReactAgent<T> = T extends {\n \"~agentTypes\": AgentTypeConfigLike;\n} ? T extends {\n \"~deepAgentTypes\": unknown;\n} ? false : true : false;\n/**\n * Infer the state type from an agent, graph, or direct state type.\n *\n * Detection order:\n * 1. Agent-like (`~agentTypes`) → InferAgentState\n * 2. CompiledGraph (`~RunOutput`) → Extract RunOutput\n * 3. Pregel (`~OutputType`) → Extract OutputType\n * 4. Direct state type → Return as-is\n */\nexport type InferStateType<T> = T extends {\n \"~agentTypes\": unknown;\n} ? InferAgentState<T> : T extends {\n \"~RunOutput\": infer S;\n} ? S extends Record<string, unknown> ? S : Record<string, unknown> : T extends {\n \"~OutputType\": infer O;\n} ? O extends Record<string, unknown> ? O : Record<string, unknown> : T extends Record<string, unknown> ? T : Record<string, unknown>;\n/**\n * Infer the node names from a compiled graph.\n *\n * Extracts the `~NodeType` phantom property from CompiledGraph instances,\n * providing a union of all node names defined in the graph.\n *\n * @example\n * ```typescript\n * const graph = new StateGraph(StateAnnotation)\n * .addNode(\"agent\", agentFn)\n * .addNode(\"tool\", toolFn)\n * .compile();\n *\n * type NodeNames = InferNodeNames<typeof graph>; // \"agent\" | \"tool\"\n * ```\n */\nexport type InferNodeNames<T> = T extends {\n \"~NodeType\": infer N;\n} ? N extends string ? Exclude<N, \"__start__\"> : string : string;\n/**\n * Infer the per-node return types from a compiled graph.\n *\n * Extracts the `~NodeReturnType` phantom property from CompiledGraph instances,\n * which is a mapped type of `{ [nodeName]: ReturnType }` for each node.\n *\n * @example\n * ```typescript\n * const graph = new StateGraph(StateAnnotation)\n * .addNode(\"dispatcher\", async () => ({ topic: \"foo\" }))\n * .addNode(\"researcher\", async () => ({ research: \"bar\" }))\n * .compile();\n *\n * type NodeReturns = InferNodeReturnTypes<typeof graph>;\n * // { dispatcher: { topic: string }; researcher: { research: string } }\n * ```\n */\nexport type InferNodeReturnTypes<T> = T extends {\n \"~NodeReturnType\": infer R;\n} ? R extends Record<string, unknown> ? R : Record<string, Record<string, unknown>> : Record<string, Record<string, unknown>>;\n/**\n * Infer tool call types from an agent.\n *\n * For agents, extracts typed tool calls from the agent's tools.\n * For non-agents, returns DefaultToolCall.\n */\nexport type InferToolCalls<T> = T extends {\n \"~agentTypes\": unknown;\n} ? InferAgentToolCalls<T> : DefaultToolCall;\n/**\n * Infer subagent state map from a DeepAgent.\n *\n * For DeepAgent, creates a map of subagent names to their state types.\n * For non-DeepAgent, returns DefaultSubagentStates.\n */\nexport type InferSubagentStates<T> = T extends {\n \"~deepAgentTypes\": unknown;\n} ? SubagentStateMap<T, InferAgentToolCalls<T>> : DefaultSubagentStates;\n/**\n * Resolves the appropriate stream interface based on the agent/graph type.\n *\n * This type automatically selects the correct stream interface based on\n * the type of agent or graph passed to `useStream`:\n *\n * 1. **DeepAgent** (`~deepAgentTypes`) → {@link UseDeepAgentStream}\n * - Includes: values, messages, toolCalls, subagents, getSubagentsByType, getSubagentsByMessage\n *\n * 2. **ReactAgent** (`~agentTypes`) → {@link UseAgentStream}\n * - Includes: values, messages, toolCalls, getToolCalls\n * - Excludes: subagents, getSubagentsByType\n *\n * 3. **CompiledGraph** (`~RunOutput`/`~OutputType`) → {@link UseGraphStream}\n * - Includes: values, messages, submit, stop, nodes, getNodeStreamsByName\n * - Excludes: toolCalls, subagents\n * - Node names are inferred from `~NodeType` for type-safe access\n *\n * 4. **Default** → {@link UseGraphStream}\n *\n * @template T - The agent or graph type (use `typeof agent` or `typeof graph`)\n * @template Bag - Type configuration bag for interrupts, configurable, etc.\n *\n * @example\n * ```typescript\n * // Automatic detection based on agent type\n * type GraphStream = ResolveStreamInterface<typeof compiledGraph, BagTemplate>;\n * // → UseGraphStream (with typed node names)\n *\n * type AgentStream = ResolveStreamInterface<typeof reactAgent, BagTemplate>;\n * // → UseAgentStream (has toolCalls)\n *\n * type DeepStream = ResolveStreamInterface<typeof deepAgent, BagTemplate>;\n * // → UseDeepAgentStream (has toolCalls AND subagents)\n * ```\n */\nexport type ResolveStreamInterface<T, Bag extends BagTemplate = BagTemplate> = IsDeepAgent<T> extends true ? UseDeepAgentStream<InferStateType<T>, InferToolCalls<T>, InferSubagentStates<T>, Bag> : IsReactAgent<T> extends true ? UseAgentStream<InferStateType<T>, InferToolCalls<T>, Bag> : BaseStream<InferStateType<T>, InferToolCalls<T>, Bag>;\n/**\n * Resolves the appropriate options interface based on the agent/graph type.\n *\n * This type automatically selects the correct options interface based on\n * the type of agent or graph:\n *\n * 1. **DeepAgent** → {@link UseDeepAgentStreamOptions}\n * - Includes: `filterSubagentMessages` option\n *\n * 2. **ReactAgent** → {@link UseAgentStreamOptions}\n *\n * 3. **CompiledGraph** / **Default** → {@link UseGraphStreamOptions}\n *\n * @template T - The agent or graph type\n * @template Bag - Type configuration bag\n *\n * @example\n * ```typescript\n * // Only DeepAgent options include filterSubagentMessages\n * type DeepOptions = ResolveStreamOptions<typeof deepAgent, BagTemplate>;\n * // DeepOptions.filterSubagentMessages exists\n *\n * type AgentOptions = ResolveStreamOptions<typeof reactAgent, BagTemplate>;\n * // AgentOptions.filterSubagentMessages does NOT exist\n * ```\n */\nexport type ResolveStreamOptions<T, Bag extends BagTemplate = BagTemplate> = IsDeepAgent<T> extends true ? UseDeepAgentStreamOptions<InferStateType<T>, Bag> : IsReactAgent<T> extends true ? UseAgentStreamOptions<InferStateType<T>, Bag> : UseStreamOptions<InferStateType<T>, Bag>;\n/**\n * Infer the Bag type from an agent, defaulting to the provided Bag.\n *\n * Currently returns the provided Bag for all types.\n * Can be extended in the future to extract Bag from agent types.\n */\nexport type InferBag<T, B extends BagTemplate = BagTemplate> = T extends {\n \"~agentTypes\": unknown;\n} ? BagTemplate : B;\n"],"mappings":"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"}
@@ -0,0 +1,172 @@
1
+ import { DefaultToolCall } from "../../types.messages.js";
2
+ import { BagTemplate } from "../../types.template.js";
3
+ import { AgentTypeConfigLike, DeepAgentTypeConfigLike, DefaultSubagentStates, InferAgentState, InferAgentToolCalls, SubagentStateMap, UseStreamOptions } from "../types.js";
4
+ import { BaseStream } from "./base.js";
5
+ import { UseAgentStream, UseAgentStreamOptions } from "./agent.js";
6
+ import { UseDeepAgentStream, UseDeepAgentStreamOptions } from "./deep-agent.js";
7
+
8
+ //#region src/ui/stream/index.d.ts
9
+
10
+ /**
11
+ * Check if a type is a DeepAgent (has `~deepAgentTypes` phantom property).
12
+ */
13
+ type IsDeepAgent<T> = T extends {
14
+ "~deepAgentTypes": DeepAgentTypeConfigLike;
15
+ } ? true : false;
16
+ /**
17
+ * Check if a type is a ReactAgent (has `~agentTypes` but not `~deepAgentTypes`).
18
+ */
19
+ type IsReactAgent<T> = T extends {
20
+ "~agentTypes": AgentTypeConfigLike;
21
+ } ? T extends {
22
+ "~deepAgentTypes": unknown;
23
+ } ? false : true : false;
24
+ /**
25
+ * Infer the state type from an agent, graph, or direct state type.
26
+ *
27
+ * Detection order:
28
+ * 1. Agent-like (`~agentTypes`) → InferAgentState
29
+ * 2. CompiledGraph (`~RunOutput`) → Extract RunOutput
30
+ * 3. Pregel (`~OutputType`) → Extract OutputType
31
+ * 4. Direct state type → Return as-is
32
+ */
33
+ type InferStateType<T> = T extends {
34
+ "~agentTypes": unknown;
35
+ } ? InferAgentState<T> : T extends {
36
+ "~RunOutput": infer S;
37
+ } ? S extends Record<string, unknown> ? S : Record<string, unknown> : T extends {
38
+ "~OutputType": infer O;
39
+ } ? O extends Record<string, unknown> ? O : Record<string, unknown> : T extends Record<string, unknown> ? T : Record<string, unknown>;
40
+ /**
41
+ * Infer the node names from a compiled graph.
42
+ *
43
+ * Extracts the `~NodeType` phantom property from CompiledGraph instances,
44
+ * providing a union of all node names defined in the graph.
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * const graph = new StateGraph(StateAnnotation)
49
+ * .addNode("agent", agentFn)
50
+ * .addNode("tool", toolFn)
51
+ * .compile();
52
+ *
53
+ * type NodeNames = InferNodeNames<typeof graph>; // "agent" | "tool"
54
+ * ```
55
+ */
56
+ type InferNodeNames<T> = T extends {
57
+ "~NodeType": infer N;
58
+ } ? N extends string ? Exclude<N, "__start__"> : string : string;
59
+ /**
60
+ * Infer the per-node return types from a compiled graph.
61
+ *
62
+ * Extracts the `~NodeReturnType` phantom property from CompiledGraph instances,
63
+ * which is a mapped type of `{ [nodeName]: ReturnType }` for each node.
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const graph = new StateGraph(StateAnnotation)
68
+ * .addNode("dispatcher", async () => ({ topic: "foo" }))
69
+ * .addNode("researcher", async () => ({ research: "bar" }))
70
+ * .compile();
71
+ *
72
+ * type NodeReturns = InferNodeReturnTypes<typeof graph>;
73
+ * // { dispatcher: { topic: string }; researcher: { research: string } }
74
+ * ```
75
+ */
76
+ type InferNodeReturnTypes<T> = T extends {
77
+ "~NodeReturnType": infer R;
78
+ } ? R extends Record<string, unknown> ? R : Record<string, Record<string, unknown>> : Record<string, Record<string, unknown>>;
79
+ /**
80
+ * Infer tool call types from an agent.
81
+ *
82
+ * For agents, extracts typed tool calls from the agent's tools.
83
+ * For non-agents, returns DefaultToolCall.
84
+ */
85
+ type InferToolCalls<T> = T extends {
86
+ "~agentTypes": unknown;
87
+ } ? InferAgentToolCalls<T> : DefaultToolCall;
88
+ /**
89
+ * Infer subagent state map from a DeepAgent.
90
+ *
91
+ * For DeepAgent, creates a map of subagent names to their state types.
92
+ * For non-DeepAgent, returns DefaultSubagentStates.
93
+ */
94
+ type InferSubagentStates<T> = T extends {
95
+ "~deepAgentTypes": unknown;
96
+ } ? SubagentStateMap<T, InferAgentToolCalls<T>> : DefaultSubagentStates;
97
+ /**
98
+ * Resolves the appropriate stream interface based on the agent/graph type.
99
+ *
100
+ * This type automatically selects the correct stream interface based on
101
+ * the type of agent or graph passed to `useStream`:
102
+ *
103
+ * 1. **DeepAgent** (`~deepAgentTypes`) → {@link UseDeepAgentStream}
104
+ * - Includes: values, messages, toolCalls, subagents, getSubagentsByType, getSubagentsByMessage
105
+ *
106
+ * 2. **ReactAgent** (`~agentTypes`) → {@link UseAgentStream}
107
+ * - Includes: values, messages, toolCalls, getToolCalls
108
+ * - Excludes: subagents, getSubagentsByType
109
+ *
110
+ * 3. **CompiledGraph** (`~RunOutput`/`~OutputType`) → {@link UseGraphStream}
111
+ * - Includes: values, messages, submit, stop, nodes, getNodeStreamsByName
112
+ * - Excludes: toolCalls, subagents
113
+ * - Node names are inferred from `~NodeType` for type-safe access
114
+ *
115
+ * 4. **Default** → {@link UseGraphStream}
116
+ *
117
+ * @template T - The agent or graph type (use `typeof agent` or `typeof graph`)
118
+ * @template Bag - Type configuration bag for interrupts, configurable, etc.
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * // Automatic detection based on agent type
123
+ * type GraphStream = ResolveStreamInterface<typeof compiledGraph, BagTemplate>;
124
+ * // → UseGraphStream (with typed node names)
125
+ *
126
+ * type AgentStream = ResolveStreamInterface<typeof reactAgent, BagTemplate>;
127
+ * // → UseAgentStream (has toolCalls)
128
+ *
129
+ * type DeepStream = ResolveStreamInterface<typeof deepAgent, BagTemplate>;
130
+ * // → UseDeepAgentStream (has toolCalls AND subagents)
131
+ * ```
132
+ */
133
+ type ResolveStreamInterface<T, Bag extends BagTemplate = BagTemplate> = IsDeepAgent<T> extends true ? UseDeepAgentStream<InferStateType<T>, InferToolCalls<T>, InferSubagentStates<T>, Bag> : IsReactAgent<T> extends true ? UseAgentStream<InferStateType<T>, InferToolCalls<T>, Bag> : BaseStream<InferStateType<T>, InferToolCalls<T>, Bag>;
134
+ /**
135
+ * Resolves the appropriate options interface based on the agent/graph type.
136
+ *
137
+ * This type automatically selects the correct options interface based on
138
+ * the type of agent or graph:
139
+ *
140
+ * 1. **DeepAgent** → {@link UseDeepAgentStreamOptions}
141
+ * - Includes: `filterSubagentMessages` option
142
+ *
143
+ * 2. **ReactAgent** → {@link UseAgentStreamOptions}
144
+ *
145
+ * 3. **CompiledGraph** / **Default** → {@link UseGraphStreamOptions}
146
+ *
147
+ * @template T - The agent or graph type
148
+ * @template Bag - Type configuration bag
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * // Only DeepAgent options include filterSubagentMessages
153
+ * type DeepOptions = ResolveStreamOptions<typeof deepAgent, BagTemplate>;
154
+ * // DeepOptions.filterSubagentMessages exists
155
+ *
156
+ * type AgentOptions = ResolveStreamOptions<typeof reactAgent, BagTemplate>;
157
+ * // AgentOptions.filterSubagentMessages does NOT exist
158
+ * ```
159
+ */
160
+ type ResolveStreamOptions<T, Bag extends BagTemplate = BagTemplate> = IsDeepAgent<T> extends true ? UseDeepAgentStreamOptions<InferStateType<T>, Bag> : IsReactAgent<T> extends true ? UseAgentStreamOptions<InferStateType<T>, Bag> : UseStreamOptions<InferStateType<T>, Bag>;
161
+ /**
162
+ * Infer the Bag type from an agent, defaulting to the provided Bag.
163
+ *
164
+ * Currently returns the provided Bag for all types.
165
+ * Can be extended in the future to extract Bag from agent types.
166
+ */
167
+ type InferBag<T, B extends BagTemplate = BagTemplate> = T extends {
168
+ "~agentTypes": unknown;
169
+ } ? BagTemplate : B;
170
+ //#endregion
171
+ export { InferBag, InferNodeNames, InferNodeReturnTypes, InferStateType, InferSubagentStates, InferToolCalls, ResolveStreamInterface, ResolveStreamOptions };
172
+ //# sourceMappingURL=index.d.ts.map