@langchain/langgraph-sdk 1.6.5 → 1.7.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/_virtual/_rolldown/runtime.cjs +7 -13
- package/dist/auth/error.cjs +1 -2
- package/dist/auth/error.cjs.map +1 -1
- package/dist/auth/error.js +1 -1
- package/dist/auth/index.cjs +3 -4
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.js +1 -2
- package/dist/auth/index.js.map +1 -1
- package/dist/client.cjs +9 -9
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts.map +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +3 -3
- package/dist/client.js.map +1 -1
- package/dist/index.cjs +5 -6
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -2
- package/dist/logging/index.cjs +2 -3
- package/dist/logging/index.cjs.map +1 -1
- package/dist/logging/index.js +1 -1
- package/dist/react/index.cjs +46 -11
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +14 -11
- package/dist/react/index.d.cts.map +1 -0
- package/dist/react/index.d.ts +14 -11
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +13 -4
- package/dist/react/index.js.map +1 -0
- package/dist/react-ui/index.cjs +39 -15
- package/dist/react-ui/index.d.cts +1 -2
- package/dist/react-ui/index.d.ts +1 -2
- package/dist/react-ui/index.js +1 -8
- package/dist/react-ui/server/index.cjs +15 -6
- package/dist/react-ui/server/index.d.cts +1 -2
- package/dist/react-ui/server/index.d.ts +1 -2
- package/dist/react-ui/server/index.js +2 -4
- package/dist/singletons/fetch.cjs +1 -2
- package/dist/singletons/fetch.cjs.map +1 -1
- package/dist/singletons/fetch.js +1 -1
- package/dist/singletons/fetch.js.map +1 -1
- package/dist/types.messages.d.cts +5 -3
- package/dist/types.messages.d.cts.map +1 -1
- package/dist/types.messages.d.ts +5 -3
- package/dist/types.messages.d.ts.map +1 -1
- package/dist/ui/branching.cjs +25 -2
- package/dist/ui/branching.cjs.map +1 -1
- package/dist/ui/branching.d.cts +26 -1
- package/dist/ui/branching.d.cts.map +1 -1
- package/dist/ui/branching.d.ts +26 -1
- package/dist/ui/branching.d.ts.map +1 -1
- package/dist/ui/branching.js +25 -2
- package/dist/ui/branching.js.map +1 -1
- package/dist/ui/errors.cjs +1 -2
- package/dist/ui/errors.cjs.map +1 -1
- package/dist/ui/errors.js +1 -1
- package/dist/ui/index.cjs +30 -0
- package/dist/ui/index.d.cts +15 -0
- package/dist/ui/index.d.ts +15 -0
- package/dist/ui/index.js +10 -0
- package/dist/ui/interrupts.cjs +20 -0
- package/dist/ui/interrupts.cjs.map +1 -0
- package/dist/ui/interrupts.d.cts +11 -0
- package/dist/ui/interrupts.d.cts.map +1 -0
- package/dist/ui/interrupts.d.ts +11 -0
- package/dist/ui/interrupts.d.ts.map +1 -0
- package/dist/ui/interrupts.js +20 -0
- package/dist/ui/interrupts.js.map +1 -0
- package/dist/ui/manager.cjs +13 -15
- package/dist/ui/manager.cjs.map +1 -1
- package/dist/ui/manager.d.cts +224 -0
- package/dist/ui/manager.d.cts.map +1 -0
- package/dist/ui/manager.d.ts +224 -0
- package/dist/ui/manager.d.ts.map +1 -0
- package/dist/ui/manager.js +10 -12
- package/dist/ui/manager.js.map +1 -1
- package/dist/ui/messages.cjs +40 -3
- package/dist/ui/messages.cjs.map +1 -1
- package/dist/ui/messages.d.cts +56 -0
- package/dist/ui/messages.d.cts.map +1 -0
- package/dist/ui/messages.d.ts +56 -0
- package/dist/ui/messages.d.ts.map +1 -0
- package/dist/ui/messages.js +37 -3
- package/dist/ui/messages.js.map +1 -1
- package/dist/ui/queue.cjs +74 -0
- package/dist/ui/queue.cjs.map +1 -0
- package/dist/ui/queue.d.cts +72 -0
- package/dist/ui/queue.d.cts.map +1 -0
- package/dist/ui/queue.d.ts +72 -0
- package/dist/ui/queue.d.ts.map +1 -0
- package/dist/ui/queue.js +74 -0
- package/dist/ui/queue.js.map +1 -0
- package/dist/ui/stream/base.d.cts +11 -0
- package/dist/ui/stream/base.d.cts.map +1 -1
- package/dist/ui/stream/base.d.ts +11 -0
- package/dist/ui/stream/base.d.ts.map +1 -1
- package/dist/ui/stream/index.d.cts +4 -4
- package/dist/ui/stream/index.d.cts.map +1 -1
- package/dist/ui/stream/index.d.ts +4 -4
- package/dist/ui/stream/index.d.ts.map +1 -1
- package/dist/ui/subagents.cjs +7 -5
- package/dist/ui/subagents.cjs.map +1 -1
- package/dist/ui/subagents.d.cts +7 -0
- package/dist/ui/subagents.d.cts.map +1 -1
- package/dist/ui/subagents.d.ts +7 -0
- package/dist/ui/subagents.d.ts.map +1 -1
- package/dist/ui/subagents.js +5 -3
- package/dist/ui/subagents.js.map +1 -1
- package/dist/ui/transport.cjs +30 -0
- package/dist/ui/transport.cjs.map +1 -0
- package/dist/{react/stream.custom.d.cts → ui/transport.d.cts} +3 -3
- package/dist/ui/transport.d.cts.map +1 -0
- package/dist/{react/stream.custom.d.ts → ui/transport.d.ts} +3 -3
- package/dist/ui/transport.d.ts.map +1 -0
- package/dist/ui/transport.js +30 -0
- package/dist/ui/transport.js.map +1 -0
- package/dist/ui/types.d.cts +125 -16
- package/dist/ui/types.d.cts.map +1 -1
- package/dist/ui/types.d.ts +125 -16
- package/dist/ui/types.d.ts.map +1 -1
- package/dist/ui/utils.cjs +1 -2
- package/dist/ui/utils.cjs.map +1 -1
- package/dist/ui/utils.d.cts +7 -0
- package/dist/ui/utils.d.cts.map +1 -0
- package/dist/ui/utils.d.ts +7 -0
- package/dist/ui/utils.d.ts.map +1 -0
- package/dist/ui/utils.js +1 -1
- package/dist/utils/async_caller.cjs +3 -4
- package/dist/utils/async_caller.cjs.map +1 -1
- package/dist/utils/async_caller.js +1 -2
- package/dist/utils/async_caller.js.map +1 -1
- package/dist/utils/env.cjs +1 -2
- package/dist/utils/env.cjs.map +1 -1
- package/dist/utils/env.js +1 -1
- package/dist/utils/env.js.map +1 -1
- package/dist/utils/error.cjs +1 -2
- package/dist/utils/error.cjs.map +1 -1
- package/dist/utils/error.js +1 -1
- package/dist/utils/index.cjs +8 -0
- package/dist/utils/index.d.cts +4 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/signals.cjs +1 -2
- package/dist/utils/signals.cjs.map +1 -1
- package/dist/utils/signals.js +1 -1
- package/dist/utils/signals.js.map +1 -1
- package/dist/utils/sse.cjs +1 -2
- package/dist/utils/sse.cjs.map +1 -1
- package/dist/utils/sse.d.cts +11 -0
- package/dist/utils/sse.d.cts.map +1 -0
- package/dist/utils/sse.d.ts +11 -0
- package/dist/utils/sse.d.ts.map +1 -0
- package/dist/utils/sse.js +1 -1
- package/dist/utils/sse.js.map +1 -1
- package/dist/utils/stream.cjs +2 -3
- package/dist/utils/stream.cjs.map +1 -1
- package/dist/utils/stream.d.cts +19 -0
- package/dist/utils/stream.d.cts.map +1 -0
- package/dist/utils/stream.d.ts +19 -0
- package/dist/utils/stream.d.ts.map +1 -0
- package/dist/utils/stream.js +1 -2
- package/dist/utils/stream.js.map +1 -1
- package/dist/utils/tools.cjs +27 -19
- package/dist/utils/tools.cjs.map +1 -1
- package/dist/utils/tools.d.cts +7 -0
- package/dist/utils/tools.d.cts.map +1 -0
- package/dist/utils/tools.d.ts +7 -0
- package/dist/utils/tools.d.ts.map +1 -0
- package/dist/utils/tools.js +27 -18
- package/dist/utils/tools.js.map +1 -1
- package/package.json +41 -12
- package/dist/react/stream.cjs +0 -18
- package/dist/react/stream.cjs.map +0 -1
- package/dist/react/stream.custom.cjs +0 -164
- package/dist/react/stream.custom.cjs.map +0 -1
- package/dist/react/stream.custom.d.cts.map +0 -1
- package/dist/react/stream.custom.d.ts.map +0 -1
- package/dist/react/stream.custom.js +0 -162
- package/dist/react/stream.custom.js.map +0 -1
- package/dist/react/stream.d.cts +0 -174
- package/dist/react/stream.d.cts.map +0 -1
- package/dist/react/stream.d.ts +0 -174
- package/dist/react/stream.d.ts.map +0 -1
- package/dist/react/stream.js +0 -17
- package/dist/react/stream.js.map +0 -1
- package/dist/react/stream.lgp.cjs +0 -544
- package/dist/react/stream.lgp.cjs.map +0 -1
- package/dist/react/stream.lgp.js +0 -543
- package/dist/react/stream.lgp.js.map +0 -1
- package/dist/react/thread.cjs +0 -21
- package/dist/react/thread.cjs.map +0 -1
- package/dist/react/thread.js +0 -20
- package/dist/react/thread.js.map +0 -1
- package/dist/react/types.d.cts +0 -79
- package/dist/react/types.d.cts.map +0 -1
- package/dist/react/types.d.ts +0 -79
- package/dist/react/types.d.ts.map +0 -1
- package/dist/react-ui/client.cjs +0 -138
- package/dist/react-ui/client.cjs.map +0 -1
- package/dist/react-ui/client.d.cts +0 -76
- package/dist/react-ui/client.d.cts.map +0 -1
- package/dist/react-ui/client.d.ts +0 -76
- package/dist/react-ui/client.d.ts.map +0 -1
- package/dist/react-ui/client.js +0 -132
- package/dist/react-ui/client.js.map +0 -1
- package/dist/react-ui/index.cjs.map +0 -1
- package/dist/react-ui/index.js.map +0 -1
- package/dist/react-ui/server/server.cjs +0 -57
- package/dist/react-ui/server/server.cjs.map +0 -1
- package/dist/react-ui/server/server.d.cts +0 -54
- package/dist/react-ui/server/server.d.cts.map +0 -1
- package/dist/react-ui/server/server.d.ts +0 -54
- package/dist/react-ui/server/server.d.ts.map +0 -1
- package/dist/react-ui/server/server.js +0 -56
- package/dist/react-ui/server/server.js.map +0 -1
- package/dist/react-ui/types.cjs +0 -38
- package/dist/react-ui/types.cjs.map +0 -1
- package/dist/react-ui/types.d.cts +0 -25
- package/dist/react-ui/types.d.cts.map +0 -1
- package/dist/react-ui/types.d.ts +0 -25
- package/dist/react-ui/types.d.ts.map +0 -1
- package/dist/react-ui/types.js +0 -35
- package/dist/react-ui/types.js.map +0 -1
package/dist/react/stream.d.cts
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { BagTemplate } from "../types.template.cjs";
|
|
2
|
-
import { UseStreamCustomOptions } from "../ui/types.cjs";
|
|
3
|
-
import { InferBag, InferStateType, ResolveStreamInterface, ResolveStreamOptions } from "../ui/stream/index.cjs";
|
|
4
|
-
|
|
5
|
-
//#region src/react/stream.d.ts
|
|
6
|
-
/**
|
|
7
|
-
* A React hook that provides seamless integration with LangGraph streaming capabilities.
|
|
8
|
-
*
|
|
9
|
-
* The `useStream` hook handles all the complexities of streaming, state management, and branching logic,
|
|
10
|
-
* letting you focus on building great chat experiences. It provides automatic state management for
|
|
11
|
-
* messages, interrupts, loading states, subagent streams, and errors.
|
|
12
|
-
*
|
|
13
|
-
* ## Usage with ReactAgent (recommended for createAgent users)
|
|
14
|
-
*
|
|
15
|
-
* When using `createAgent` from `@langchain/langgraph`, you can pass `typeof agent` as the
|
|
16
|
-
* type parameter to automatically infer tool call types:
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
|
-
* // In your agent file (e.g., agent.ts)
|
|
21
|
-
* import { createAgent, tool } from "langchain";
|
|
22
|
-
* import { z } from "zod";
|
|
23
|
-
*
|
|
24
|
-
* const getWeather = tool(
|
|
25
|
-
* async ({ location }) => `Weather in ${location}`,
|
|
26
|
-
* { name: "get_weather", schema: z.object({ location: z.string() }) }
|
|
27
|
-
* );
|
|
28
|
-
*
|
|
29
|
-
* export const agent = createAgent({
|
|
30
|
-
* model: "openai:gpt-4o",
|
|
31
|
-
* tools: [getWeather],
|
|
32
|
-
* });
|
|
33
|
-
*
|
|
34
|
-
* // In your React component
|
|
35
|
-
* import { agent } from "./agent";
|
|
36
|
-
*
|
|
37
|
-
* function Chat() {
|
|
38
|
-
* // Tool calls are automatically typed from the agent's tools!
|
|
39
|
-
* const stream = useStream<typeof agent>({
|
|
40
|
-
* assistantId: "agent",
|
|
41
|
-
* apiUrl: "http://localhost:2024",
|
|
42
|
-
* });
|
|
43
|
-
*
|
|
44
|
-
* // stream.toolCalls[0].call.name is typed as "get_weather"
|
|
45
|
-
* // stream.toolCalls[0].call.args is typed as { location: string }
|
|
46
|
-
* }
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* ## Usage with StateGraph (for custom LangGraph applications)
|
|
50
|
-
*
|
|
51
|
-
* When building custom graphs with `StateGraph`, embed your tool call types directly
|
|
52
|
-
* in your state's messages property using `Message<MyToolCalls>`:
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```typescript
|
|
56
|
-
* import { Message } from "@langchain/langgraph-sdk";
|
|
57
|
-
*
|
|
58
|
-
* // Define your tool call types as a discriminated union
|
|
59
|
-
* type MyToolCalls =
|
|
60
|
-
* | { name: "search"; args: { query: string }; id?: string }
|
|
61
|
-
* | { name: "calculate"; args: { expression: string }; id?: string };
|
|
62
|
-
*
|
|
63
|
-
* // Embed tool call types in your state's messages
|
|
64
|
-
* interface MyGraphState {
|
|
65
|
-
* messages: Message<MyToolCalls>[];
|
|
66
|
-
* context?: string;
|
|
67
|
-
* }
|
|
68
|
-
*
|
|
69
|
-
* function Chat() {
|
|
70
|
-
* const stream = useStream<MyGraphState>({
|
|
71
|
-
* assistantId: "my-graph",
|
|
72
|
-
* apiUrl: "http://localhost:2024",
|
|
73
|
-
* });
|
|
74
|
-
*
|
|
75
|
-
* // stream.values is typed as MyGraphState
|
|
76
|
-
* // stream.toolCalls[0].call.name is typed as "search" | "calculate"
|
|
77
|
-
* }
|
|
78
|
-
* ```
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* ```typescript
|
|
82
|
-
* // With additional type configuration (interrupts, configurable)
|
|
83
|
-
* interface MyGraphState {
|
|
84
|
-
* messages: Message<MyToolCalls>[];
|
|
85
|
-
* }
|
|
86
|
-
*
|
|
87
|
-
* function Chat() {
|
|
88
|
-
* const stream = useStream<MyGraphState, {
|
|
89
|
-
* InterruptType: { question: string };
|
|
90
|
-
* ConfigurableType: { userId: string };
|
|
91
|
-
* }>({
|
|
92
|
-
* assistantId: "my-graph",
|
|
93
|
-
* apiUrl: "http://localhost:2024",
|
|
94
|
-
* });
|
|
95
|
-
*
|
|
96
|
-
* // stream.interrupt is typed as { question: string } | undefined
|
|
97
|
-
* }
|
|
98
|
-
* ```
|
|
99
|
-
*
|
|
100
|
-
* ## Usage with Deep Agents (subagent streaming, experimental)
|
|
101
|
-
*
|
|
102
|
-
* For agents that spawn subagents (nested graphs), use `filterSubagentMessages`
|
|
103
|
-
* to keep the main message stream clean while tracking subagent activity separately:
|
|
104
|
-
*
|
|
105
|
-
* @example
|
|
106
|
-
* ```typescript
|
|
107
|
-
* import { useStream, SubagentStream } from "@langchain/langgraph-sdk/react";
|
|
108
|
-
* import type { agent } from "./agent";
|
|
109
|
-
*
|
|
110
|
-
* function DeepAgentChat() {
|
|
111
|
-
* const stream = useStream<typeof agent>({
|
|
112
|
-
* assistantId: "deepagent",
|
|
113
|
-
* apiUrl: "http://localhost:2024",
|
|
114
|
-
* // Filter subagent messages from main stream
|
|
115
|
-
* filterSubagentMessages: true,
|
|
116
|
-
* });
|
|
117
|
-
*
|
|
118
|
-
* const handleSubmit = (content: string) => {
|
|
119
|
-
* stream.submit(
|
|
120
|
-
* { messages: [{ content, type: "human" }] },
|
|
121
|
-
* { streamSubgraphs: true } // Enable subgraph streaming
|
|
122
|
-
* );
|
|
123
|
-
* };
|
|
124
|
-
*
|
|
125
|
-
* // Access subagent streams via stream.subagents (Map<string, SubagentStream>)
|
|
126
|
-
* const subagentList = [...stream.subagents.values()];
|
|
127
|
-
*
|
|
128
|
-
* return (
|
|
129
|
-
* <div>
|
|
130
|
-
* {stream.messages.map((msg) => <Message key={msg.id} message={msg} />)}
|
|
131
|
-
*
|
|
132
|
-
* {subagentList.map((subagent) => (
|
|
133
|
-
* <SubagentCard
|
|
134
|
-
* key={subagent.id}
|
|
135
|
-
* status={subagent.status} // "pending" | "running" | "complete" | "error"
|
|
136
|
-
* messages={subagent.messages}
|
|
137
|
-
* toolCalls={subagent.toolCalls}
|
|
138
|
-
* />
|
|
139
|
-
* ))}
|
|
140
|
-
* </div>
|
|
141
|
-
* );
|
|
142
|
-
* }
|
|
143
|
-
* ```
|
|
144
|
-
*
|
|
145
|
-
* @template T Either a ReactAgent type (with `~agentTypes`) or a state type (`Record<string, unknown>`)
|
|
146
|
-
* @template Bag Type configuration bag containing:
|
|
147
|
-
* - `ConfigurableType`: Type for the `config.configurable` property
|
|
148
|
-
* - `InterruptType`: Type for interrupt values
|
|
149
|
-
* - `CustomEventType`: Type for custom events
|
|
150
|
-
* - `UpdateType`: Type for the submit function updates
|
|
151
|
-
*
|
|
152
|
-
* @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}
|
|
153
|
-
*/
|
|
154
|
-
declare function useStream<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(options: ResolveStreamOptions<T, InferBag<T, Bag>>): ResolveStreamInterface<T, InferBag<T, Bag>>;
|
|
155
|
-
/**
|
|
156
|
-
* A React hook that provides seamless integration with LangGraph streaming capabilities.
|
|
157
|
-
*
|
|
158
|
-
* The `useStream` hook handles all the complexities of streaming, state management, and branching logic,
|
|
159
|
-
* letting you focus on building great chat experiences. It provides automatic state management for
|
|
160
|
-
* messages, interrupts, loading states, and errors.
|
|
161
|
-
*
|
|
162
|
-
* @template T Either a ReactAgent type (with `~agentTypes`) or a state type (`Record<string, unknown>`)
|
|
163
|
-
* @template Bag Type configuration bag containing:
|
|
164
|
-
* - `ConfigurableType`: Type for the `config.configurable` property
|
|
165
|
-
* - `InterruptType`: Type for interrupt values
|
|
166
|
-
* - `CustomEventType`: Type for custom events
|
|
167
|
-
* - `UpdateType`: Type for the submit function updates
|
|
168
|
-
*
|
|
169
|
-
* @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}
|
|
170
|
-
*/
|
|
171
|
-
declare function useStream<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(options: UseStreamCustomOptions<InferStateType<T>, InferBag<T, Bag>>): ResolveStreamInterface<T, InferBag<T, Bag>>;
|
|
172
|
-
//#endregion
|
|
173
|
-
export { useStream };
|
|
174
|
-
//# sourceMappingURL=stream.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.cts","names":[],"sources":["../../src/react/stream.tsx"],"mappings":";;;;;;;AA4KA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAvBgB,SAAA,KACV,MAAA,+BACQ,WAAA,GAAc,WAAA,CAAA,CAE1B,OAAA,EAAS,oBAAA,CAAqB,CAAA,EAAG,QAAA,CAAS,CAAA,EAAG,GAAA,KAC5C,sBAAA,CAAuB,CAAA,EAAG,QAAA,CAAS,CAAA,EAAG,GAAA;;;;;;;;;;;;;;;;;iBAkBzB,SAAA,KACV,MAAA,+BACQ,WAAA,GAAc,WAAA,CAAA,CAE1B,OAAA,EAAS,sBAAA,CAAuB,cAAA,CAAe,CAAA,GAAI,QAAA,CAAS,CAAA,EAAG,GAAA,KAC9D,sBAAA,CAAuB,CAAA,EAAG,QAAA,CAAS,CAAA,EAAG,GAAA"}
|
package/dist/react/stream.d.ts
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { BagTemplate } from "../types.template.js";
|
|
2
|
-
import { UseStreamCustomOptions } from "../ui/types.js";
|
|
3
|
-
import { InferBag, InferStateType, ResolveStreamInterface, ResolveStreamOptions } from "../ui/stream/index.js";
|
|
4
|
-
|
|
5
|
-
//#region src/react/stream.d.ts
|
|
6
|
-
/**
|
|
7
|
-
* A React hook that provides seamless integration with LangGraph streaming capabilities.
|
|
8
|
-
*
|
|
9
|
-
* The `useStream` hook handles all the complexities of streaming, state management, and branching logic,
|
|
10
|
-
* letting you focus on building great chat experiences. It provides automatic state management for
|
|
11
|
-
* messages, interrupts, loading states, subagent streams, and errors.
|
|
12
|
-
*
|
|
13
|
-
* ## Usage with ReactAgent (recommended for createAgent users)
|
|
14
|
-
*
|
|
15
|
-
* When using `createAgent` from `@langchain/langgraph`, you can pass `typeof agent` as the
|
|
16
|
-
* type parameter to automatically infer tool call types:
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
|
-
* // In your agent file (e.g., agent.ts)
|
|
21
|
-
* import { createAgent, tool } from "langchain";
|
|
22
|
-
* import { z } from "zod";
|
|
23
|
-
*
|
|
24
|
-
* const getWeather = tool(
|
|
25
|
-
* async ({ location }) => `Weather in ${location}`,
|
|
26
|
-
* { name: "get_weather", schema: z.object({ location: z.string() }) }
|
|
27
|
-
* );
|
|
28
|
-
*
|
|
29
|
-
* export const agent = createAgent({
|
|
30
|
-
* model: "openai:gpt-4o",
|
|
31
|
-
* tools: [getWeather],
|
|
32
|
-
* });
|
|
33
|
-
*
|
|
34
|
-
* // In your React component
|
|
35
|
-
* import { agent } from "./agent";
|
|
36
|
-
*
|
|
37
|
-
* function Chat() {
|
|
38
|
-
* // Tool calls are automatically typed from the agent's tools!
|
|
39
|
-
* const stream = useStream<typeof agent>({
|
|
40
|
-
* assistantId: "agent",
|
|
41
|
-
* apiUrl: "http://localhost:2024",
|
|
42
|
-
* });
|
|
43
|
-
*
|
|
44
|
-
* // stream.toolCalls[0].call.name is typed as "get_weather"
|
|
45
|
-
* // stream.toolCalls[0].call.args is typed as { location: string }
|
|
46
|
-
* }
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* ## Usage with StateGraph (for custom LangGraph applications)
|
|
50
|
-
*
|
|
51
|
-
* When building custom graphs with `StateGraph`, embed your tool call types directly
|
|
52
|
-
* in your state's messages property using `Message<MyToolCalls>`:
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```typescript
|
|
56
|
-
* import { Message } from "@langchain/langgraph-sdk";
|
|
57
|
-
*
|
|
58
|
-
* // Define your tool call types as a discriminated union
|
|
59
|
-
* type MyToolCalls =
|
|
60
|
-
* | { name: "search"; args: { query: string }; id?: string }
|
|
61
|
-
* | { name: "calculate"; args: { expression: string }; id?: string };
|
|
62
|
-
*
|
|
63
|
-
* // Embed tool call types in your state's messages
|
|
64
|
-
* interface MyGraphState {
|
|
65
|
-
* messages: Message<MyToolCalls>[];
|
|
66
|
-
* context?: string;
|
|
67
|
-
* }
|
|
68
|
-
*
|
|
69
|
-
* function Chat() {
|
|
70
|
-
* const stream = useStream<MyGraphState>({
|
|
71
|
-
* assistantId: "my-graph",
|
|
72
|
-
* apiUrl: "http://localhost:2024",
|
|
73
|
-
* });
|
|
74
|
-
*
|
|
75
|
-
* // stream.values is typed as MyGraphState
|
|
76
|
-
* // stream.toolCalls[0].call.name is typed as "search" | "calculate"
|
|
77
|
-
* }
|
|
78
|
-
* ```
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* ```typescript
|
|
82
|
-
* // With additional type configuration (interrupts, configurable)
|
|
83
|
-
* interface MyGraphState {
|
|
84
|
-
* messages: Message<MyToolCalls>[];
|
|
85
|
-
* }
|
|
86
|
-
*
|
|
87
|
-
* function Chat() {
|
|
88
|
-
* const stream = useStream<MyGraphState, {
|
|
89
|
-
* InterruptType: { question: string };
|
|
90
|
-
* ConfigurableType: { userId: string };
|
|
91
|
-
* }>({
|
|
92
|
-
* assistantId: "my-graph",
|
|
93
|
-
* apiUrl: "http://localhost:2024",
|
|
94
|
-
* });
|
|
95
|
-
*
|
|
96
|
-
* // stream.interrupt is typed as { question: string } | undefined
|
|
97
|
-
* }
|
|
98
|
-
* ```
|
|
99
|
-
*
|
|
100
|
-
* ## Usage with Deep Agents (subagent streaming, experimental)
|
|
101
|
-
*
|
|
102
|
-
* For agents that spawn subagents (nested graphs), use `filterSubagentMessages`
|
|
103
|
-
* to keep the main message stream clean while tracking subagent activity separately:
|
|
104
|
-
*
|
|
105
|
-
* @example
|
|
106
|
-
* ```typescript
|
|
107
|
-
* import { useStream, SubagentStream } from "@langchain/langgraph-sdk/react";
|
|
108
|
-
* import type { agent } from "./agent";
|
|
109
|
-
*
|
|
110
|
-
* function DeepAgentChat() {
|
|
111
|
-
* const stream = useStream<typeof agent>({
|
|
112
|
-
* assistantId: "deepagent",
|
|
113
|
-
* apiUrl: "http://localhost:2024",
|
|
114
|
-
* // Filter subagent messages from main stream
|
|
115
|
-
* filterSubagentMessages: true,
|
|
116
|
-
* });
|
|
117
|
-
*
|
|
118
|
-
* const handleSubmit = (content: string) => {
|
|
119
|
-
* stream.submit(
|
|
120
|
-
* { messages: [{ content, type: "human" }] },
|
|
121
|
-
* { streamSubgraphs: true } // Enable subgraph streaming
|
|
122
|
-
* );
|
|
123
|
-
* };
|
|
124
|
-
*
|
|
125
|
-
* // Access subagent streams via stream.subagents (Map<string, SubagentStream>)
|
|
126
|
-
* const subagentList = [...stream.subagents.values()];
|
|
127
|
-
*
|
|
128
|
-
* return (
|
|
129
|
-
* <div>
|
|
130
|
-
* {stream.messages.map((msg) => <Message key={msg.id} message={msg} />)}
|
|
131
|
-
*
|
|
132
|
-
* {subagentList.map((subagent) => (
|
|
133
|
-
* <SubagentCard
|
|
134
|
-
* key={subagent.id}
|
|
135
|
-
* status={subagent.status} // "pending" | "running" | "complete" | "error"
|
|
136
|
-
* messages={subagent.messages}
|
|
137
|
-
* toolCalls={subagent.toolCalls}
|
|
138
|
-
* />
|
|
139
|
-
* ))}
|
|
140
|
-
* </div>
|
|
141
|
-
* );
|
|
142
|
-
* }
|
|
143
|
-
* ```
|
|
144
|
-
*
|
|
145
|
-
* @template T Either a ReactAgent type (with `~agentTypes`) or a state type (`Record<string, unknown>`)
|
|
146
|
-
* @template Bag Type configuration bag containing:
|
|
147
|
-
* - `ConfigurableType`: Type for the `config.configurable` property
|
|
148
|
-
* - `InterruptType`: Type for interrupt values
|
|
149
|
-
* - `CustomEventType`: Type for custom events
|
|
150
|
-
* - `UpdateType`: Type for the submit function updates
|
|
151
|
-
*
|
|
152
|
-
* @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}
|
|
153
|
-
*/
|
|
154
|
-
declare function useStream<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(options: ResolveStreamOptions<T, InferBag<T, Bag>>): ResolveStreamInterface<T, InferBag<T, Bag>>;
|
|
155
|
-
/**
|
|
156
|
-
* A React hook that provides seamless integration with LangGraph streaming capabilities.
|
|
157
|
-
*
|
|
158
|
-
* The `useStream` hook handles all the complexities of streaming, state management, and branching logic,
|
|
159
|
-
* letting you focus on building great chat experiences. It provides automatic state management for
|
|
160
|
-
* messages, interrupts, loading states, and errors.
|
|
161
|
-
*
|
|
162
|
-
* @template T Either a ReactAgent type (with `~agentTypes`) or a state type (`Record<string, unknown>`)
|
|
163
|
-
* @template Bag Type configuration bag containing:
|
|
164
|
-
* - `ConfigurableType`: Type for the `config.configurable` property
|
|
165
|
-
* - `InterruptType`: Type for interrupt values
|
|
166
|
-
* - `CustomEventType`: Type for custom events
|
|
167
|
-
* - `UpdateType`: Type for the submit function updates
|
|
168
|
-
*
|
|
169
|
-
* @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}
|
|
170
|
-
*/
|
|
171
|
-
declare function useStream<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(options: UseStreamCustomOptions<InferStateType<T>, InferBag<T, Bag>>): ResolveStreamInterface<T, InferBag<T, Bag>>;
|
|
172
|
-
//#endregion
|
|
173
|
-
export { useStream };
|
|
174
|
-
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","names":[],"sources":["../../src/react/stream.tsx"],"mappings":";;;;;;;AA4KA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAvBgB,SAAA,KACV,MAAA,+BACQ,WAAA,GAAc,WAAA,CAAA,CAE1B,OAAA,EAAS,oBAAA,CAAqB,CAAA,EAAG,QAAA,CAAS,CAAA,EAAG,GAAA,KAC5C,sBAAA,CAAuB,CAAA,EAAG,QAAA,CAAS,CAAA,EAAG,GAAA;;;;;;;;;;;;;;;;;iBAkBzB,SAAA,KACV,MAAA,+BACQ,WAAA,GAAc,WAAA,CAAA,CAE1B,OAAA,EAAS,sBAAA,CAAuB,cAAA,CAAe,CAAA,GAAI,QAAA,CAAS,CAAA,EAAG,GAAA,KAC9D,sBAAA,CAAuB,CAAA,EAAG,QAAA,CAAS,CAAA,EAAG,GAAA"}
|
package/dist/react/stream.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { useStreamLGP } from "./stream.lgp.js";
|
|
2
|
-
import { useStreamCustom } from "./stream.custom.js";
|
|
3
|
-
import { useState } from "react";
|
|
4
|
-
|
|
5
|
-
//#region src/react/stream.tsx
|
|
6
|
-
function isCustomOptions(options) {
|
|
7
|
-
return "transport" in options;
|
|
8
|
-
}
|
|
9
|
-
function useStream(options) {
|
|
10
|
-
const [isCustom] = useState(isCustomOptions(options));
|
|
11
|
-
if (isCustom) return useStreamCustom(options);
|
|
12
|
-
return useStreamLGP(options);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
//#endregion
|
|
16
|
-
export { useStream };
|
|
17
|
-
//# sourceMappingURL=stream.js.map
|
package/dist/react/stream.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream.js","names":[],"sources":["../../src/react/stream.tsx"],"sourcesContent":["import { useState } from \"react\";\nimport { useStreamLGP } from \"./stream.lgp.js\";\nimport { useStreamCustom } from \"./stream.custom.js\";\nimport type { UseStreamOptions } from \"../ui/types.js\";\nimport type { BagTemplate } from \"../types.template.js\";\nimport type { UseStreamCustomOptions } from \"./types.js\";\nimport type {\n ResolveStreamInterface,\n ResolveStreamOptions,\n InferBag,\n InferStateType,\n} from \"../ui/stream/index.js\";\n\nfunction isCustomOptions<\n StateType extends Record<string, unknown> = Record<string, unknown>,\n Bag extends BagTemplate = BagTemplate\n>(\n options:\n | UseStreamOptions<StateType, Bag>\n | UseStreamCustomOptions<StateType, Bag>\n): options is UseStreamCustomOptions<StateType, Bag> {\n return \"transport\" in options;\n}\n\n/**\n * A React hook that provides seamless integration with LangGraph streaming capabilities.\n *\n * The `useStream` hook handles all the complexities of streaming, state management, and branching logic,\n * letting you focus on building great chat experiences. It provides automatic state management for\n * messages, interrupts, loading states, subagent streams, and errors.\n *\n * ## Usage with ReactAgent (recommended for createAgent users)\n *\n * When using `createAgent` from `@langchain/langgraph`, you can pass `typeof agent` as the\n * type parameter to automatically infer tool call types:\n *\n * @example\n * ```typescript\n * // In your agent file (e.g., agent.ts)\n * import { createAgent, tool } from \"langchain\";\n * import { z } from \"zod\";\n *\n * const getWeather = tool(\n * async ({ location }) => `Weather in ${location}`,\n * { name: \"get_weather\", schema: z.object({ location: z.string() }) }\n * );\n *\n * export const agent = createAgent({\n * model: \"openai:gpt-4o\",\n * tools: [getWeather],\n * });\n *\n * // In your React component\n * import { agent } from \"./agent\";\n *\n * function Chat() {\n * // Tool calls are automatically typed from the agent's tools!\n * const stream = useStream<typeof agent>({\n * assistantId: \"agent\",\n * apiUrl: \"http://localhost:2024\",\n * });\n *\n * // stream.toolCalls[0].call.name is typed as \"get_weather\"\n * // stream.toolCalls[0].call.args is typed as { location: string }\n * }\n * ```\n *\n * ## Usage with StateGraph (for custom LangGraph applications)\n *\n * When building custom graphs with `StateGraph`, embed your tool call types directly\n * in your state's messages property using `Message<MyToolCalls>`:\n *\n * @example\n * ```typescript\n * import { Message } from \"@langchain/langgraph-sdk\";\n *\n * // Define your tool call types as a discriminated union\n * type MyToolCalls =\n * | { name: \"search\"; args: { query: string }; id?: string }\n * | { name: \"calculate\"; args: { expression: string }; id?: string };\n *\n * // Embed tool call types in your state's messages\n * interface MyGraphState {\n * messages: Message<MyToolCalls>[];\n * context?: string;\n * }\n *\n * function Chat() {\n * const stream = useStream<MyGraphState>({\n * assistantId: \"my-graph\",\n * apiUrl: \"http://localhost:2024\",\n * });\n *\n * // stream.values is typed as MyGraphState\n * // stream.toolCalls[0].call.name is typed as \"search\" | \"calculate\"\n * }\n * ```\n *\n * @example\n * ```typescript\n * // With additional type configuration (interrupts, configurable)\n * interface MyGraphState {\n * messages: Message<MyToolCalls>[];\n * }\n *\n * function Chat() {\n * const stream = useStream<MyGraphState, {\n * InterruptType: { question: string };\n * ConfigurableType: { userId: string };\n * }>({\n * assistantId: \"my-graph\",\n * apiUrl: \"http://localhost:2024\",\n * });\n *\n * // stream.interrupt is typed as { question: string } | undefined\n * }\n * ```\n *\n * ## Usage with Deep Agents (subagent streaming, experimental)\n *\n * For agents that spawn subagents (nested graphs), use `filterSubagentMessages`\n * to keep the main message stream clean while tracking subagent activity separately:\n *\n * @example\n * ```typescript\n * import { useStream, SubagentStream } from \"@langchain/langgraph-sdk/react\";\n * import type { agent } from \"./agent\";\n *\n * function DeepAgentChat() {\n * const stream = useStream<typeof agent>({\n * assistantId: \"deepagent\",\n * apiUrl: \"http://localhost:2024\",\n * // Filter subagent messages from main stream\n * filterSubagentMessages: true,\n * });\n *\n * const handleSubmit = (content: string) => {\n * stream.submit(\n * { messages: [{ content, type: \"human\" }] },\n * { streamSubgraphs: true } // Enable subgraph streaming\n * );\n * };\n *\n * // Access subagent streams via stream.subagents (Map<string, SubagentStream>)\n * const subagentList = [...stream.subagents.values()];\n *\n * return (\n * <div>\n * {stream.messages.map((msg) => <Message key={msg.id} message={msg} />)}\n *\n * {subagentList.map((subagent) => (\n * <SubagentCard\n * key={subagent.id}\n * status={subagent.status} // \"pending\" | \"running\" | \"complete\" | \"error\"\n * messages={subagent.messages}\n * toolCalls={subagent.toolCalls}\n * />\n * ))}\n * </div>\n * );\n * }\n * ```\n *\n * @template T Either a ReactAgent type (with `~agentTypes`) or a state type (`Record<string, unknown>`)\n * @template Bag Type configuration bag containing:\n * - `ConfigurableType`: Type for the `config.configurable` property\n * - `InterruptType`: Type for interrupt values\n * - `CustomEventType`: Type for custom events\n * - `UpdateType`: Type for the submit function updates\n *\n * @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}\n */\nexport function useStream<\n T = Record<string, unknown>,\n Bag extends BagTemplate = BagTemplate\n>(\n options: ResolveStreamOptions<T, InferBag<T, Bag>>\n): ResolveStreamInterface<T, InferBag<T, Bag>>;\n\n/**\n * A React hook that provides seamless integration with LangGraph streaming capabilities.\n *\n * The `useStream` hook handles all the complexities of streaming, state management, and branching logic,\n * letting you focus on building great chat experiences. It provides automatic state management for\n * messages, interrupts, loading states, and errors.\n *\n * @template T Either a ReactAgent type (with `~agentTypes`) or a state type (`Record<string, unknown>`)\n * @template Bag Type configuration bag containing:\n * - `ConfigurableType`: Type for the `config.configurable` property\n * - `InterruptType`: Type for interrupt values\n * - `CustomEventType`: Type for custom events\n * - `UpdateType`: Type for the submit function updates\n *\n * @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}\n */\nexport function useStream<\n T = Record<string, unknown>,\n Bag extends BagTemplate = BagTemplate\n>(\n options: UseStreamCustomOptions<InferStateType<T>, InferBag<T, Bag>>\n): ResolveStreamInterface<T, InferBag<T, Bag>>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function useStream(options: any): any {\n // Store this in useState to make sure we're not changing the implementation in re-renders\n const [isCustom] = useState(isCustomOptions(options));\n\n if (isCustom) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useStreamCustom(options);\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useStreamLGP(options);\n}\n"],"mappings":";;;;;AAaA,SAAS,gBAIP,SAGmD;AACnD,QAAO,eAAe;;AAsLxB,SAAgB,UAAU,SAAmB;CAE3C,MAAM,CAAC,YAAY,SAAS,gBAAgB,QAAQ,CAAC;AAErD,KAAI,SAEF,QAAO,gBAAgB,QAAQ;AAIjC,QAAO,aAAa,QAAQ"}
|