@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.
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/react/index.cjs +6 -0
- package/dist/react/index.d.cts +7 -2
- package/dist/react/index.d.ts +7 -2
- package/dist/react/index.js +2 -1
- package/dist/react/stream.cjs.map +1 -1
- package/dist/react/stream.custom.cjs +36 -7
- package/dist/react/stream.custom.cjs.map +1 -1
- package/dist/react/stream.custom.d.cts.map +1 -1
- package/dist/react/stream.custom.d.ts.map +1 -1
- package/dist/react/stream.custom.js +36 -7
- package/dist/react/stream.custom.js.map +1 -1
- package/dist/react/stream.d.cts +51 -31
- package/dist/react/stream.d.cts.map +1 -1
- package/dist/react/stream.d.ts +51 -31
- package/dist/react/stream.d.ts.map +1 -1
- package/dist/react/stream.js.map +1 -1
- package/dist/react/stream.lgp.cjs +45 -13
- package/dist/react/stream.lgp.cjs.map +1 -1
- package/dist/react/stream.lgp.js +45 -13
- package/dist/react/stream.lgp.js.map +1 -1
- package/dist/react/types.d.cts +5 -88
- package/dist/react/types.d.cts.map +1 -1
- package/dist/react/types.d.ts +5 -88
- package/dist/react/types.d.ts.map +1 -1
- package/dist/react-ui/client.cjs.map +1 -1
- package/dist/react-ui/client.d.cts +5 -3
- package/dist/react-ui/client.d.cts.map +1 -1
- package/dist/react-ui/client.d.ts +5 -3
- package/dist/react-ui/client.d.ts.map +1 -1
- package/dist/react-ui/client.js.map +1 -1
- package/dist/schema.d.cts.map +1 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/types.stream.d.ts.map +1 -1
- package/dist/ui/manager.cjs +140 -14
- package/dist/ui/manager.cjs.map +1 -1
- package/dist/ui/manager.js +140 -14
- package/dist/ui/manager.js.map +1 -1
- package/dist/ui/stream/agent.d.cts +143 -0
- package/dist/ui/stream/agent.d.cts.map +1 -0
- package/dist/ui/stream/agent.d.ts +143 -0
- package/dist/ui/stream/agent.d.ts.map +1 -0
- package/dist/ui/stream/base.d.cts +144 -0
- package/dist/ui/stream/base.d.cts.map +1 -0
- package/dist/ui/stream/base.d.ts +144 -0
- package/dist/ui/stream/base.d.ts.map +1 -0
- package/dist/ui/stream/deep-agent.d.cts +277 -0
- package/dist/ui/stream/deep-agent.d.cts.map +1 -0
- package/dist/ui/stream/deep-agent.d.ts +277 -0
- package/dist/ui/stream/deep-agent.d.ts.map +1 -0
- package/dist/ui/stream/index.d.cts +172 -0
- package/dist/ui/stream/index.d.cts.map +1 -0
- package/dist/ui/stream/index.d.ts +172 -0
- package/dist/ui/stream/index.d.ts.map +1 -0
- package/dist/ui/subagents.cjs +593 -0
- package/dist/ui/subagents.cjs.map +1 -0
- package/dist/ui/subagents.d.cts +291 -0
- package/dist/ui/subagents.d.cts.map +1 -0
- package/dist/ui/subagents.d.ts +291 -0
- package/dist/ui/subagents.d.ts.map +1 -0
- package/dist/ui/subagents.js +589 -0
- package/dist/ui/subagents.js.map +1 -0
- package/dist/ui/types.d.cts +384 -5
- package/dist/ui/types.d.cts.map +1 -1
- package/dist/ui/types.d.ts +384 -5
- package/dist/ui/types.d.ts.map +1 -1
- package/package.json +6 -3
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { Interrupt, ThreadState } from "../../schema.js";
|
|
2
|
+
import { DefaultToolCall, Message } from "../../types.messages.js";
|
|
3
|
+
import { StreamMode } from "../../types.stream.js";
|
|
4
|
+
import { StreamEvent } from "../../types.js";
|
|
5
|
+
import { Client } from "../../client.js";
|
|
6
|
+
import { BagTemplate } from "../../types.template.js";
|
|
7
|
+
import { GetConfigurableType, GetInterruptType, GetUpdateType, MessageMetadata, SubmitOptions } from "../types.js";
|
|
8
|
+
import { Sequence } from "../branching.js";
|
|
9
|
+
|
|
10
|
+
//#region src/ui/stream/base.d.ts
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Base stream interface shared by all stream types.
|
|
14
|
+
*
|
|
15
|
+
* Contains core properties for state management, messaging, and stream control
|
|
16
|
+
* that are common to CompiledStateGraph, ReactAgent, and DeepAgent streams.
|
|
17
|
+
*
|
|
18
|
+
* This interface provides the foundation that all stream types build upon:
|
|
19
|
+
* - State management (`values`, `isLoading`, `error`)
|
|
20
|
+
* - Message handling (`messages`)
|
|
21
|
+
* - Interrupt handling (`interrupt`)
|
|
22
|
+
* - Stream lifecycle (`submit`, `stop`)
|
|
23
|
+
* - Branching and history (`branch`, `history`)
|
|
24
|
+
*
|
|
25
|
+
* @template StateType - The state type of the stream
|
|
26
|
+
* @template ToolCall - The tool call type for messages (inferred from agent tools)
|
|
27
|
+
* @template Bag - Type configuration bag for interrupts, configurable, updates, etc.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* // BaseStream is not used directly - use one of the specialized interfaces:
|
|
32
|
+
* // - UseGraphStream for CompiledStateGraph
|
|
33
|
+
* // - UseAgentStream for ReactAgent (createAgent)
|
|
34
|
+
* // - UseDeepAgentStream for DeepAgent (createDeepAgent)
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
interface BaseStream<StateType extends Record<string, unknown> = Record<string, unknown>, ToolCall = DefaultToolCall, Bag extends BagTemplate = BagTemplate> {
|
|
38
|
+
/**
|
|
39
|
+
* The current state values of the stream.
|
|
40
|
+
* Updated as streaming events are received.
|
|
41
|
+
*/
|
|
42
|
+
values: StateType;
|
|
43
|
+
/**
|
|
44
|
+
* Last seen error from the stream, if any.
|
|
45
|
+
* Reset to `undefined` when a new stream starts.
|
|
46
|
+
*/
|
|
47
|
+
error: unknown;
|
|
48
|
+
/**
|
|
49
|
+
* Whether the stream is currently running.
|
|
50
|
+
* `true` while streaming, `false` when idle or completed.
|
|
51
|
+
*/
|
|
52
|
+
isLoading: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Whether the thread is currently being loaded.
|
|
55
|
+
* `true` during initial thread data fetch.
|
|
56
|
+
*/
|
|
57
|
+
isThreadLoading: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Messages accumulated during the stream.
|
|
60
|
+
* Includes both human and AI messages.
|
|
61
|
+
* AI messages include typed tool calls based on the agent's tools.
|
|
62
|
+
*/
|
|
63
|
+
messages: Message<ToolCall>[];
|
|
64
|
+
/**
|
|
65
|
+
* Current interrupt, if the stream is interrupted.
|
|
66
|
+
* Convenience alias for `interrupts[0]`.
|
|
67
|
+
* For workflows with multiple concurrent interrupts, use `interrupts` instead.
|
|
68
|
+
*/
|
|
69
|
+
interrupt: Interrupt<GetInterruptType<Bag>> | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* All current interrupts from the stream.
|
|
72
|
+
* When using Send() fan-out with per-task interrupt() calls,
|
|
73
|
+
* multiple interrupts may be pending simultaneously.
|
|
74
|
+
*/
|
|
75
|
+
interrupts: Interrupt<GetInterruptType<Bag>>[];
|
|
76
|
+
/**
|
|
77
|
+
* Stops the currently running stream.
|
|
78
|
+
* @returns A promise that resolves when the stream is stopped.
|
|
79
|
+
*/
|
|
80
|
+
stop: () => Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Create and stream a run to the thread.
|
|
83
|
+
*
|
|
84
|
+
* @param values - The input values to send, or null/undefined for empty input
|
|
85
|
+
* @param options - Optional configuration for the submission
|
|
86
|
+
* @returns A promise that resolves when the stream completes
|
|
87
|
+
*/
|
|
88
|
+
submit: (values: GetUpdateType<Bag, StateType> | null | undefined, options?: SubmitOptions<StateType, GetConfigurableType<Bag>>) => Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* The current branch of the thread.
|
|
91
|
+
* Used for navigating between different conversation branches.
|
|
92
|
+
*/
|
|
93
|
+
branch: string;
|
|
94
|
+
/**
|
|
95
|
+
* Set the branch of the thread.
|
|
96
|
+
* @param branch - The branch identifier to switch to
|
|
97
|
+
*/
|
|
98
|
+
setBranch: (branch: string) => void;
|
|
99
|
+
/**
|
|
100
|
+
* Flattened history of thread states of a thread.
|
|
101
|
+
* Contains all states in the current branch's history.
|
|
102
|
+
*/
|
|
103
|
+
history: ThreadState<StateType>[];
|
|
104
|
+
/**
|
|
105
|
+
* Tree of all branches for the thread.
|
|
106
|
+
* @experimental This API is experimental and subject to change.
|
|
107
|
+
*/
|
|
108
|
+
experimental_branchTree: Sequence<StateType>;
|
|
109
|
+
/**
|
|
110
|
+
* Get the metadata for a message, such as first thread state the message
|
|
111
|
+
* was seen in and branch information.
|
|
112
|
+
*
|
|
113
|
+
* @param message - The message to get the metadata for
|
|
114
|
+
* @param index - The index of the message in the thread
|
|
115
|
+
* @returns The metadata for the message, or undefined if not found
|
|
116
|
+
*/
|
|
117
|
+
getMessagesMetadata: (message: Message<ToolCall>, index?: number) => MessageMetadata<StateType> | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* LangGraph SDK client used to send requests and receive responses.
|
|
120
|
+
*/
|
|
121
|
+
client: Client;
|
|
122
|
+
/**
|
|
123
|
+
* The ID of the assistant to use.
|
|
124
|
+
*/
|
|
125
|
+
assistantId: string;
|
|
126
|
+
/**
|
|
127
|
+
* Join an active stream that's already running.
|
|
128
|
+
*
|
|
129
|
+
* @param runId - The ID of the run to join
|
|
130
|
+
* @param lastEventId - Optional last event ID for resuming from a specific point
|
|
131
|
+
* @param options - Optional configuration for the stream
|
|
132
|
+
*/
|
|
133
|
+
joinStream: (runId: string, lastEventId?: string, options?: {
|
|
134
|
+
streamMode?: StreamMode | StreamMode[];
|
|
135
|
+
filter?: (event: {
|
|
136
|
+
id?: string;
|
|
137
|
+
event: StreamEvent;
|
|
138
|
+
data: unknown;
|
|
139
|
+
}) => boolean;
|
|
140
|
+
}) => Promise<void>;
|
|
141
|
+
}
|
|
142
|
+
//#endregion
|
|
143
|
+
export { BaseStream };
|
|
144
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","names":["Client","ThreadState","Interrupt","StreamMode","StreamEvent","Message","DefaultToolCall","BagTemplate","Sequence","GetUpdateType","GetConfigurableType","GetInterruptType","MessageMetadata","SubmitOptions","BaseStream","Record","StateType","ToolCall","Bag","Promise"],"sources":["../../../src/ui/stream/base.d.ts"],"sourcesContent":["/**\n * Base stream types shared by all stream interfaces.\n *\n * This module contains the foundational types that are common to all streaming\n * scenarios: CompiledStateGraph, ReactAgent (createAgent), and DeepAgent (createDeepAgent).\n *\n * @module\n */\nimport type { Client } from \"../../client.js\";\nimport type { ThreadState, Interrupt } from \"../../schema.js\";\nimport type { StreamMode } from \"../../types.stream.js\";\nimport type { StreamEvent } from \"../../types.js\";\nimport type { Message, DefaultToolCall } from \"../../types.messages.js\";\nimport type { BagTemplate } from \"../../types.template.js\";\nimport type { Sequence } from \"../branching.js\";\nimport type { GetUpdateType, GetConfigurableType, GetInterruptType, MessageMetadata, SubmitOptions } from \"../types.js\";\n/**\n * Base stream interface shared by all stream types.\n *\n * Contains core properties for state management, messaging, and stream control\n * that are common to CompiledStateGraph, ReactAgent, and DeepAgent streams.\n *\n * This interface provides the foundation that all stream types build upon:\n * - State management (`values`, `isLoading`, `error`)\n * - Message handling (`messages`)\n * - Interrupt handling (`interrupt`)\n * - Stream lifecycle (`submit`, `stop`)\n * - Branching and history (`branch`, `history`)\n *\n * @template StateType - The state type of the stream\n * @template ToolCall - The tool call type for messages (inferred from agent tools)\n * @template Bag - Type configuration bag for interrupts, configurable, updates, etc.\n *\n * @example\n * ```typescript\n * // BaseStream is not used directly - use one of the specialized interfaces:\n * // - UseGraphStream for CompiledStateGraph\n * // - UseAgentStream for ReactAgent (createAgent)\n * // - UseDeepAgentStream for DeepAgent (createDeepAgent)\n * ```\n */\nexport interface BaseStream<StateType extends Record<string, unknown> = Record<string, unknown>, ToolCall = DefaultToolCall, Bag extends BagTemplate = BagTemplate> {\n /**\n * The current state values of the stream.\n * Updated as streaming events are received.\n */\n values: StateType;\n /**\n * Last seen error from the stream, if any.\n * Reset to `undefined` when a new stream starts.\n */\n error: unknown;\n /**\n * Whether the stream is currently running.\n * `true` while streaming, `false` when idle or completed.\n */\n isLoading: boolean;\n /**\n * Whether the thread is currently being loaded.\n * `true` during initial thread data fetch.\n */\n isThreadLoading: boolean;\n /**\n * Messages accumulated during the stream.\n * Includes both human and AI messages.\n * AI messages include typed tool calls based on the agent's tools.\n */\n messages: Message<ToolCall>[];\n /**\n * Current interrupt, if the stream is interrupted.\n * Convenience alias for `interrupts[0]`.\n * For workflows with multiple concurrent interrupts, use `interrupts` instead.\n */\n interrupt: Interrupt<GetInterruptType<Bag>> | undefined;\n /**\n * All current interrupts from the stream.\n * When using Send() fan-out with per-task interrupt() calls,\n * multiple interrupts may be pending simultaneously.\n */\n interrupts: Interrupt<GetInterruptType<Bag>>[];\n /**\n * Stops the currently running stream.\n * @returns A promise that resolves when the stream is stopped.\n */\n stop: () => Promise<void>;\n /**\n * Create and stream a run to the thread.\n *\n * @param values - The input values to send, or null/undefined for empty input\n * @param options - Optional configuration for the submission\n * @returns A promise that resolves when the stream completes\n */\n submit: (values: GetUpdateType<Bag, StateType> | null | undefined, options?: SubmitOptions<StateType, GetConfigurableType<Bag>>) => Promise<void>;\n /**\n * The current branch of the thread.\n * Used for navigating between different conversation branches.\n */\n branch: string;\n /**\n * Set the branch of the thread.\n * @param branch - The branch identifier to switch to\n */\n setBranch: (branch: string) => void;\n /**\n * Flattened history of thread states of a thread.\n * Contains all states in the current branch's history.\n */\n history: ThreadState<StateType>[];\n /**\n * Tree of all branches for the thread.\n * @experimental This API is experimental and subject to change.\n */\n experimental_branchTree: Sequence<StateType>;\n /**\n * Get the metadata for a message, such as first thread state the message\n * was seen in and branch information.\n *\n * @param message - The message to get the metadata for\n * @param index - The index of the message in the thread\n * @returns The metadata for the message, or undefined if not found\n */\n getMessagesMetadata: (message: Message<ToolCall>, index?: number) => MessageMetadata<StateType> | undefined;\n /**\n * LangGraph SDK client used to send requests and receive responses.\n */\n client: Client;\n /**\n * The ID of the assistant to use.\n */\n assistantId: string;\n /**\n * Join an active stream that's already running.\n *\n * @param runId - The ID of the run to join\n * @param lastEventId - Optional last event ID for resuming from a specific point\n * @param options - Optional configuration for the stream\n */\n joinStream: (runId: string, lastEventId?: string, options?: {\n streamMode?: StreamMode | StreamMode[];\n filter?: (event: {\n id?: string;\n event: StreamEvent;\n data: unknown;\n }) => boolean;\n }) => Promise<void>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyHyFgB,UAhFxEF,UAgFwEE,CAAAA,kBAhF3CD,MAgF2CC,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,GAhFjBD,MAgFiBC,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,EAAAA,WAhFmBV,eAgFnBU,EAAAA,YAhFgDT,WAgFhDS,GAhF8DT,WAgF9DS,CAAAA,CAAAA;;;;;QAoBtEZ,EA/FPY,SA+FOZ;;;;;;;;;;;;;;;;;;;;;YA1ELC,QAAQY;;;;;;aAMPf,UAAUS,iBAAiBO;;;;;;cAM1BhB,UAAUS,iBAAiBO;;;;;cAK3BC;;;;;;;;mBAQKV,cAAcS,KAAKF,yCAAyCH,cAAcG,WAAWN,oBAAoBQ,UAAUC;;;;;;;;;;;;;;;WAe3HlB,YAAYe;;;;;2BAKIR,SAASQ;;;;;;;;;iCASHX,QAAQY,8BAA8BL,gBAAgBI;;;;UAI7EhB;;;;;;;;;;;;;iBAaSG,aAAaA;;;aAGfC;;;QAGTe"}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { DefaultToolCall } from "../../types.messages.cjs";
|
|
2
|
+
import { BagTemplate } from "../../types.template.cjs";
|
|
3
|
+
import { DefaultSubagentStates, SubagentStream } from "../types.cjs";
|
|
4
|
+
import { UseAgentStream, UseAgentStreamOptions } from "./agent.cjs";
|
|
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.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-agent.d.cts","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"}
|