@langchain/langgraph-sdk 1.3.1 → 1.4.5
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 +10 -6
- package/dist/auth/error.cjs.map +1 -1
- package/dist/auth/error.d.cts.map +1 -1
- package/dist/auth/error.d.ts.map +1 -1
- package/dist/auth/error.js.map +1 -1
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.d.cts +1 -3
- package/dist/auth/index.d.cts.map +1 -1
- package/dist/auth/index.d.ts +1 -3
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/types.d.cts +1 -1
- package/dist/auth/types.d.cts.map +1 -1
- package/dist/auth/types.d.ts +1 -1
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/client.cjs +15 -24
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +2 -6
- package/dist/client.d.cts.map +1 -1
- package/dist/client.d.ts +2 -6
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +15 -24
- package/dist/client.js.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/logging/index.cjs.map +1 -1
- package/dist/logging/index.d.cts +0 -1
- package/dist/logging/index.d.cts.map +1 -1
- package/dist/logging/index.d.ts +0 -1
- package/dist/logging/index.d.ts.map +1 -1
- package/dist/logging/index.js.map +1 -1
- package/dist/react/index.d.cts +3 -2
- package/dist/react/index.d.ts +3 -2
- package/dist/react/stream.cjs +1 -1
- package/dist/react/stream.cjs.map +1 -1
- package/dist/react/stream.custom.cjs +12 -6
- package/dist/react/stream.custom.cjs.map +1 -1
- package/dist/react/stream.custom.d.cts +3 -2
- package/dist/react/stream.custom.d.cts.map +1 -1
- package/dist/react/stream.custom.d.ts +3 -2
- package/dist/react/stream.custom.d.ts.map +1 -1
- package/dist/react/stream.custom.js +11 -5
- package/dist/react/stream.custom.js.map +1 -1
- package/dist/react/stream.d.cts +116 -34
- package/dist/react/stream.d.cts.map +1 -1
- package/dist/react/stream.d.ts +116 -34
- package/dist/react/stream.d.ts.map +1 -1
- package/dist/react/stream.js.map +1 -1
- package/dist/react/stream.lgp.cjs +15 -13
- package/dist/react/stream.lgp.cjs.map +1 -1
- package/dist/react/stream.lgp.js +14 -12
- package/dist/react/stream.lgp.js.map +1 -1
- package/dist/react/thread.cjs +1 -2
- package/dist/react/thread.cjs.map +1 -1
- package/dist/react/thread.js +0 -1
- package/dist/react/thread.js.map +1 -1
- package/dist/react/types.d.cts +73 -284
- package/dist/react/types.d.cts.map +1 -1
- package/dist/react/types.d.ts +73 -284
- package/dist/react/types.d.ts.map +1 -1
- package/dist/react-ui/client.cjs +8 -7
- package/dist/react-ui/client.cjs.map +1 -1
- package/dist/react-ui/client.d.cts +4 -21
- package/dist/react-ui/client.d.cts.map +1 -1
- package/dist/react-ui/client.d.ts +4 -21
- package/dist/react-ui/client.d.ts.map +1 -1
- package/dist/react-ui/client.js +2 -4
- package/dist/react-ui/client.js.map +1 -1
- package/dist/react-ui/index.cjs.map +1 -1
- package/dist/react-ui/index.js.map +1 -1
- package/dist/react-ui/server/server.cjs +1 -1
- package/dist/react-ui/server/server.cjs.map +1 -1
- package/dist/react-ui/server/server.d.cts.map +1 -1
- package/dist/react-ui/server/server.d.ts.map +1 -1
- package/dist/react-ui/server/server.js.map +1 -1
- package/dist/react-ui/types.cjs.map +1 -1
- package/dist/react-ui/types.d.cts.map +1 -1
- package/dist/react-ui/types.d.ts.map +1 -1
- package/dist/react-ui/types.js.map +1 -1
- package/dist/schema.d.cts +6 -6
- package/dist/schema.d.cts.map +1 -1
- package/dist/schema.d.ts +6 -6
- package/dist/schema.d.ts.map +1 -1
- package/dist/singletons/fetch.cjs.map +1 -1
- package/dist/singletons/fetch.js.map +1 -1
- package/dist/types.d.cts +1 -1
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.messages.d.cts +207 -34
- package/dist/types.messages.d.cts.map +1 -1
- package/dist/types.messages.d.ts +207 -34
- package/dist/types.messages.d.ts.map +1 -1
- package/dist/types.stream.d.cts +1 -3
- package/dist/types.stream.d.cts.map +1 -1
- package/dist/types.stream.d.ts +1 -3
- package/dist/types.stream.d.ts.map +1 -1
- package/dist/types.template.d.cts +19 -0
- package/dist/types.template.d.cts.map +1 -0
- package/dist/types.template.d.ts +19 -0
- package/dist/types.template.d.ts.map +1 -0
- package/dist/ui/branching.cjs.map +1 -1
- package/dist/ui/branching.d.cts +0 -3
- package/dist/ui/branching.d.cts.map +1 -1
- package/dist/ui/branching.d.ts +0 -3
- package/dist/ui/branching.d.ts.map +1 -1
- package/dist/ui/branching.js.map +1 -1
- package/dist/ui/errors.cjs.map +1 -1
- package/dist/ui/errors.js.map +1 -1
- package/dist/ui/manager.cjs +8 -2
- package/dist/ui/manager.cjs.map +1 -1
- package/dist/ui/manager.js +8 -2
- package/dist/ui/manager.js.map +1 -1
- package/dist/ui/messages.cjs +10 -10
- package/dist/ui/messages.cjs.map +1 -1
- package/dist/ui/messages.js.map +1 -1
- package/dist/ui/types.d.cts +420 -0
- package/dist/ui/types.d.cts.map +1 -0
- package/dist/ui/types.d.ts +420 -0
- package/dist/ui/types.d.ts.map +1 -0
- package/dist/ui/utils.cjs +0 -1
- package/dist/ui/utils.cjs.map +1 -1
- package/dist/ui/utils.js +0 -1
- package/dist/ui/utils.js.map +1 -1
- package/dist/utils/async_caller.cjs +12 -4
- package/dist/utils/async_caller.cjs.map +1 -1
- package/dist/utils/async_caller.d.cts +1 -3
- package/dist/utils/async_caller.d.cts.map +1 -1
- package/dist/utils/async_caller.d.ts +1 -3
- package/dist/utils/async_caller.d.ts.map +1 -1
- package/dist/utils/async_caller.js +8 -2
- package/dist/utils/async_caller.js.map +1 -1
- package/dist/utils/env.cjs +1 -1
- 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.map +1 -1
- package/dist/utils/error.js.map +1 -1
- package/dist/utils/signals.cjs.map +1 -1
- package/dist/utils/signals.js.map +1 -1
- package/dist/utils/sse.cjs.map +1 -1
- package/dist/utils/sse.js.map +1 -1
- package/dist/utils/stream.cjs +1 -3
- package/dist/utils/stream.cjs.map +1 -1
- package/dist/utils/stream.js +1 -3
- package/dist/utils/stream.js.map +1 -1
- package/dist/utils/tools.cjs +52 -0
- package/dist/utils/tools.cjs.map +1 -0
- package/dist/utils/tools.js +51 -0
- package/dist/utils/tools.js.map +1 -0
- package/package.json +5 -5
- package/CHANGELOG.md +0 -281
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
import { Checkpoint, Config, Metadata, ThreadState } from "../schema.js";
|
|
2
|
+
import { AIMessage, DefaultToolCall } from "../types.messages.js";
|
|
3
|
+
import { CheckpointsStreamEvent, CustomStreamEvent, DebugStreamEvent, EventsStreamEvent, MetadataStreamEvent, StreamMode, TasksStreamEvent, UpdatesStreamEvent } from "../types.stream.js";
|
|
4
|
+
import { Command, DisconnectMode, Durability, MultitaskStrategy, OnCompletionBehavior } from "../types.js";
|
|
5
|
+
import { Client, ClientConfig } from "../client.js";
|
|
6
|
+
import { BagTemplate } from "../types.template.js";
|
|
7
|
+
|
|
8
|
+
//#region src/ui/types.d.ts
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Minimal interface matching the structure of AgentTypeConfig from @langchain/langgraph.
|
|
12
|
+
* This allows type inference from ReactAgent without requiring the langchain dependency.
|
|
13
|
+
*/
|
|
14
|
+
interface AgentTypeConfigLike {
|
|
15
|
+
Response: unknown;
|
|
16
|
+
State: unknown;
|
|
17
|
+
Context: unknown;
|
|
18
|
+
Middleware: unknown;
|
|
19
|
+
Tools: unknown;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Check if a type is agent-like (has `~agentTypes` phantom property).
|
|
23
|
+
* This property is present on `ReactAgent` instances created with `createAgent`.
|
|
24
|
+
*/
|
|
25
|
+
type IsAgentLike<T> = T extends {
|
|
26
|
+
"~agentTypes": AgentTypeConfigLike;
|
|
27
|
+
} ? true : false;
|
|
28
|
+
/**
|
|
29
|
+
* Extract the AgentTypeConfig from an agent-like type.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const agent = createAgent({ ... });
|
|
34
|
+
* type Config = ExtractAgentConfig<typeof agent>;
|
|
35
|
+
* // Config is the AgentTypeConfig with Response, State, Context, Middleware, Tools
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
type ExtractAgentConfig<T> = T extends {
|
|
39
|
+
"~agentTypes": infer Config;
|
|
40
|
+
} ? Config extends AgentTypeConfigLike ? Config : never : never;
|
|
41
|
+
/**
|
|
42
|
+
* Helper type to infer schema input type, supporting both Zod v3 and v4.
|
|
43
|
+
* - Zod v4 uses `_zod.input` property
|
|
44
|
+
* - Zod v3 uses `_input` property
|
|
45
|
+
*/
|
|
46
|
+
type InferSchemaInput<S> = S extends {
|
|
47
|
+
_zod: {
|
|
48
|
+
input: infer Args;
|
|
49
|
+
};
|
|
50
|
+
} ? Args : S extends {
|
|
51
|
+
_input: infer Args;
|
|
52
|
+
} ? Args : never;
|
|
53
|
+
/**
|
|
54
|
+
* Helper type to extract the input type from a DynamicStructuredTool's _call method.
|
|
55
|
+
* This is more reliable than trying to infer from the schema directly because
|
|
56
|
+
* DynamicStructuredTool has the input type baked into its _call signature.
|
|
57
|
+
*/
|
|
58
|
+
type InferToolInput<T> = T extends {
|
|
59
|
+
_call: (arg: infer Args, ...rest: any[]) => any;
|
|
60
|
+
} ? Args : T extends {
|
|
61
|
+
schema: infer S;
|
|
62
|
+
} ? InferSchemaInput<S> : never;
|
|
63
|
+
/**
|
|
64
|
+
* Extract a tool call type from a single tool.
|
|
65
|
+
* Works with tools created via `tool()` from `@langchain/core/tools`.
|
|
66
|
+
*
|
|
67
|
+
* This extracts the literal name type from DynamicStructuredTool's NameT parameter
|
|
68
|
+
* and the args type from the _call method or schema's input property.
|
|
69
|
+
*/
|
|
70
|
+
type ToolCallFromAgentTool<T> = T extends {
|
|
71
|
+
name: infer N;
|
|
72
|
+
} ? N extends string ? InferToolInput<T> extends infer Args ? Args extends never ? never : Args extends Record<string, any> ? {
|
|
73
|
+
name: N;
|
|
74
|
+
args: Args;
|
|
75
|
+
id?: string;
|
|
76
|
+
type?: "tool_call";
|
|
77
|
+
} : never : never : never : never;
|
|
78
|
+
/**
|
|
79
|
+
* Extract tool calls type from an agent's tools.
|
|
80
|
+
* Converts the tools array to a discriminated union of tool calls.
|
|
81
|
+
*
|
|
82
|
+
* This handles both tuple types (e.g., `readonly [Tool1, Tool2]`) and
|
|
83
|
+
* array-of-union types (e.g., `readonly (Tool1 | Tool2)[]`) which is how
|
|
84
|
+
* `createAgent` captures tool types.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* const agent = createAgent({ tools: [getWeather, search], ... });
|
|
89
|
+
* type ToolCalls = InferAgentToolCalls<typeof agent>;
|
|
90
|
+
* // ToolCalls is:
|
|
91
|
+
* // | { name: "get_weather"; args: { location: string }; id?: string }
|
|
92
|
+
* // | { name: "search"; args: { query: string }; id?: string }
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
type InferAgentToolCalls<T> = ExtractAgentConfig<T>["Tools"] extends readonly (infer Tool)[] ? ToolCallFromAgentTool<Tool> extends never ? DefaultToolCall : ToolCallFromAgentTool<Tool> : DefaultToolCall;
|
|
96
|
+
/**
|
|
97
|
+
* Extract the tool call type parameter from an AIMessage in a message union.
|
|
98
|
+
* Returns `never` if the message is not an AIMessage or uses DefaultToolCall.
|
|
99
|
+
*
|
|
100
|
+
* The key distinction: custom tool calls have literal `name` types (e.g., "get_weather"),
|
|
101
|
+
* while DefaultToolCall has `name: string`. We check if `string extends TC["name"]` -
|
|
102
|
+
* if true, it's DefaultToolCall; if false, it's a custom type with literal names.
|
|
103
|
+
*/
|
|
104
|
+
type ExtractToolCallFromMessageUnion<M> = M extends AIMessage<infer TC> ? TC extends {
|
|
105
|
+
name: infer N;
|
|
106
|
+
} ? string extends N ? never : TC : never : never;
|
|
107
|
+
/**
|
|
108
|
+
* Extract the tool call type from a StateType's messages property.
|
|
109
|
+
* This is the primary way to specify tool call types when using useStream.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* // Define state with typed messages
|
|
114
|
+
* type MyToolCalls =
|
|
115
|
+
* | { name: "get_weather"; args: { location: string }; id?: string }
|
|
116
|
+
* | { name: "search"; args: { query: string }; id?: string };
|
|
117
|
+
*
|
|
118
|
+
* interface MyState {
|
|
119
|
+
* messages: Message<MyToolCalls>[];
|
|
120
|
+
* }
|
|
121
|
+
*
|
|
122
|
+
* // ExtractToolCallsFromState<MyState> = MyToolCalls
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
type ExtractToolCallsFromState<StateType extends Record<string, unknown>> = StateType extends {
|
|
126
|
+
messages: infer Messages;
|
|
127
|
+
} ? Messages extends readonly (infer M)[] ? ExtractToolCallFromMessageUnion<M> : Messages extends (infer M)[] ? ExtractToolCallFromMessageUnion<M> : never : never;
|
|
128
|
+
type MessageMetadata<StateType extends Record<string, unknown>> = {
|
|
129
|
+
/**
|
|
130
|
+
* The ID of the message used.
|
|
131
|
+
*/
|
|
132
|
+
messageId: string;
|
|
133
|
+
/**
|
|
134
|
+
* The first thread state the message was seen in.
|
|
135
|
+
*/
|
|
136
|
+
firstSeenState: ThreadState<StateType> | undefined;
|
|
137
|
+
/**
|
|
138
|
+
* The branch of the message.
|
|
139
|
+
*/
|
|
140
|
+
branch: string | undefined;
|
|
141
|
+
/**
|
|
142
|
+
* The list of branches this message is part of.
|
|
143
|
+
* This is useful for displaying branching controls.
|
|
144
|
+
*/
|
|
145
|
+
branchOptions: string[] | undefined;
|
|
146
|
+
/**
|
|
147
|
+
* Metadata sent alongside the message during run streaming.
|
|
148
|
+
* @remarks This metadata only exists temporarily in browser memory during streaming and is not persisted after completion.
|
|
149
|
+
*/
|
|
150
|
+
streamMetadata: Record<string, unknown> | undefined;
|
|
151
|
+
};
|
|
152
|
+
type GetUpdateType<Bag extends BagTemplate, StateType extends Record<string, unknown>> = Bag extends {
|
|
153
|
+
UpdateType: unknown;
|
|
154
|
+
} ? Bag["UpdateType"] : Partial<StateType>;
|
|
155
|
+
type GetConfigurableType<Bag extends BagTemplate> = Bag extends {
|
|
156
|
+
ConfigurableType: Record<string, unknown>;
|
|
157
|
+
} ? Bag["ConfigurableType"] : Record<string, unknown>;
|
|
158
|
+
type GetInterruptType<Bag extends BagTemplate> = Bag extends {
|
|
159
|
+
InterruptType: unknown;
|
|
160
|
+
} ? Bag["InterruptType"] : unknown;
|
|
161
|
+
type GetCustomEventType<Bag extends BagTemplate> = Bag extends {
|
|
162
|
+
CustomEventType: unknown;
|
|
163
|
+
} ? Bag["CustomEventType"] : unknown;
|
|
164
|
+
/**
|
|
165
|
+
* Extract the tool call type from a StateType's messages property.
|
|
166
|
+
* This is the canonical way to get typed tool calls in useStream.
|
|
167
|
+
*
|
|
168
|
+
* Tool call types are now extracted from the messages property of StateType,
|
|
169
|
+
* rather than being specified separately in the Bag.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* // Define state with typed messages
|
|
174
|
+
* type MyToolCalls =
|
|
175
|
+
* | { name: "get_weather"; args: { location: string }; id?: string }
|
|
176
|
+
* | { name: "search"; args: { query: string }; id?: string };
|
|
177
|
+
*
|
|
178
|
+
* interface MyState {
|
|
179
|
+
* messages: Message<MyToolCalls>[];
|
|
180
|
+
* }
|
|
181
|
+
*
|
|
182
|
+
* // GetToolCallsType<MyState> = MyToolCalls
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
type GetToolCallsType<StateType extends Record<string, unknown>> = ExtractToolCallsFromState<StateType> extends never ? DefaultToolCall : ExtractToolCallsFromState<StateType>;
|
|
186
|
+
interface RunCallbackMeta {
|
|
187
|
+
run_id: string;
|
|
188
|
+
thread_id: string;
|
|
189
|
+
}
|
|
190
|
+
interface UseStreamThread<StateType extends Record<string, unknown>> {
|
|
191
|
+
data: ThreadState<StateType>[] | null | undefined;
|
|
192
|
+
error: unknown;
|
|
193
|
+
isLoading: boolean;
|
|
194
|
+
mutate: (mutateId?: string) => Promise<ThreadState<StateType>[] | null | undefined>;
|
|
195
|
+
}
|
|
196
|
+
interface UseStreamOptions<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> {
|
|
197
|
+
/**
|
|
198
|
+
* The ID of the assistant to use.
|
|
199
|
+
*/
|
|
200
|
+
assistantId: string;
|
|
201
|
+
/**
|
|
202
|
+
* Client used to send requests.
|
|
203
|
+
*/
|
|
204
|
+
client?: Client;
|
|
205
|
+
/**
|
|
206
|
+
* The URL of the API to use.
|
|
207
|
+
*/
|
|
208
|
+
apiUrl?: ClientConfig["apiUrl"];
|
|
209
|
+
/**
|
|
210
|
+
* The API key to use.
|
|
211
|
+
*/
|
|
212
|
+
apiKey?: ClientConfig["apiKey"];
|
|
213
|
+
/**
|
|
214
|
+
* Custom call options, such as custom fetch implementation.
|
|
215
|
+
*/
|
|
216
|
+
callerOptions?: ClientConfig["callerOptions"];
|
|
217
|
+
/**
|
|
218
|
+
* Default headers to send with requests.
|
|
219
|
+
*/
|
|
220
|
+
defaultHeaders?: ClientConfig["defaultHeaders"];
|
|
221
|
+
/**
|
|
222
|
+
* Specify the key within the state that contains messages.
|
|
223
|
+
* Defaults to "messages".
|
|
224
|
+
*
|
|
225
|
+
* @default "messages"
|
|
226
|
+
*/
|
|
227
|
+
messagesKey?: string;
|
|
228
|
+
/**
|
|
229
|
+
* Callback that is called when an error occurs.
|
|
230
|
+
*/
|
|
231
|
+
onError?: (error: unknown, run: RunCallbackMeta | undefined) => void;
|
|
232
|
+
/**
|
|
233
|
+
* Callback that is called when the stream is finished.
|
|
234
|
+
*/
|
|
235
|
+
onFinish?: (state: ThreadState<StateType>, run: RunCallbackMeta | undefined) => void;
|
|
236
|
+
/**
|
|
237
|
+
* Callback that is called when a new stream is created.
|
|
238
|
+
*/
|
|
239
|
+
onCreated?: (run: RunCallbackMeta) => void;
|
|
240
|
+
/**
|
|
241
|
+
* Callback that is called when an update event is received.
|
|
242
|
+
*/
|
|
243
|
+
onUpdateEvent?: (data: UpdatesStreamEvent<GetUpdateType<Bag, StateType>>["data"], options: {
|
|
244
|
+
namespace: string[] | undefined;
|
|
245
|
+
mutate: (update: Partial<StateType> | ((prev: StateType) => Partial<StateType>)) => void;
|
|
246
|
+
}) => void;
|
|
247
|
+
/**
|
|
248
|
+
* Callback that is called when a custom event is received.
|
|
249
|
+
*/
|
|
250
|
+
onCustomEvent?: (data: CustomStreamEvent<GetCustomEventType<Bag>>["data"], options: {
|
|
251
|
+
namespace: string[] | undefined;
|
|
252
|
+
mutate: (update: Partial<StateType> | ((prev: StateType) => Partial<StateType>)) => void;
|
|
253
|
+
}) => void;
|
|
254
|
+
/**
|
|
255
|
+
* Callback that is called when a metadata event is received.
|
|
256
|
+
*/
|
|
257
|
+
onMetadataEvent?: (data: MetadataStreamEvent["data"]) => void;
|
|
258
|
+
/**
|
|
259
|
+
* Callback that is called when a LangChain event is received.
|
|
260
|
+
* @see https://langchain-ai.github.io/langgraph/cloud/how-tos/stream_events/#stream-graph-in-events-mode for more details.
|
|
261
|
+
*/
|
|
262
|
+
onLangChainEvent?: (data: EventsStreamEvent["data"]) => void;
|
|
263
|
+
/**
|
|
264
|
+
* Callback that is called when a debug event is received.
|
|
265
|
+
* @internal This API is experimental and subject to change.
|
|
266
|
+
*/
|
|
267
|
+
onDebugEvent?: (data: DebugStreamEvent["data"], options: {
|
|
268
|
+
namespace: string[] | undefined;
|
|
269
|
+
}) => void;
|
|
270
|
+
/**
|
|
271
|
+
* Callback that is called when a checkpoints event is received.
|
|
272
|
+
*/
|
|
273
|
+
onCheckpointEvent?: (data: CheckpointsStreamEvent<StateType>["data"], options: {
|
|
274
|
+
namespace: string[] | undefined;
|
|
275
|
+
}) => void;
|
|
276
|
+
/**
|
|
277
|
+
* Callback that is called when a tasks event is received.
|
|
278
|
+
*/
|
|
279
|
+
onTaskEvent?: (data: TasksStreamEvent<StateType, GetUpdateType<Bag, StateType>>["data"], options: {
|
|
280
|
+
namespace: string[] | undefined;
|
|
281
|
+
}) => void;
|
|
282
|
+
/**
|
|
283
|
+
* Callback that is called when the stream is stopped by the user.
|
|
284
|
+
* Provides a mutate function to update the stream state immediately
|
|
285
|
+
* without requiring a server roundtrip.
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* ```typescript
|
|
289
|
+
* onStop: ({ mutate }) => {
|
|
290
|
+
* mutate((prev) => ({
|
|
291
|
+
* ...prev,
|
|
292
|
+
* ui: prev.ui?.map(component =>
|
|
293
|
+
* component.props.isLoading
|
|
294
|
+
* ? { ...component, props: { ...component.props, stopped: true, isLoading: false }}
|
|
295
|
+
* : component
|
|
296
|
+
* )
|
|
297
|
+
* }));
|
|
298
|
+
* }
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
onStop?: (options: {
|
|
302
|
+
mutate: (update: Partial<StateType> | ((prev: StateType) => Partial<StateType>)) => void;
|
|
303
|
+
}) => void;
|
|
304
|
+
/**
|
|
305
|
+
* The ID of the thread to fetch history and current values from.
|
|
306
|
+
*/
|
|
307
|
+
threadId?: string | null;
|
|
308
|
+
/**
|
|
309
|
+
* Callback that is called when the thread ID is updated (ie when a new thread is created).
|
|
310
|
+
*/
|
|
311
|
+
onThreadId?: (threadId: string) => void;
|
|
312
|
+
/** Will reconnect the stream on mount */
|
|
313
|
+
reconnectOnMount?: boolean | (() => RunMetadataStorage);
|
|
314
|
+
/**
|
|
315
|
+
* Initial values to display immediately when loading a thread.
|
|
316
|
+
* Useful for displaying cached thread data while official history loads.
|
|
317
|
+
* These values will be replaced when official thread data is fetched.
|
|
318
|
+
*
|
|
319
|
+
* Note: UI components from initialValues will render immediately if they're
|
|
320
|
+
* predefined in LoadExternalComponent's components prop, providing instant
|
|
321
|
+
* cached UI display without server fetches.
|
|
322
|
+
*/
|
|
323
|
+
initialValues?: StateType | null;
|
|
324
|
+
/**
|
|
325
|
+
* Whether to fetch the history of the thread.
|
|
326
|
+
* If true, the history will be fetched from the server. Defaults to 10 entries.
|
|
327
|
+
* If false, only the last state will be fetched from the server.
|
|
328
|
+
* @default true
|
|
329
|
+
*/
|
|
330
|
+
fetchStateHistory?: boolean | {
|
|
331
|
+
limit: number;
|
|
332
|
+
};
|
|
333
|
+
/**
|
|
334
|
+
* Manage the thread state externally.
|
|
335
|
+
*/
|
|
336
|
+
thread?: UseStreamThread<StateType>;
|
|
337
|
+
/**
|
|
338
|
+
* Throttle the stream.
|
|
339
|
+
* If a number is provided, the stream will be throttled to the given number of milliseconds.
|
|
340
|
+
* If `true`, updates are batched in a single macrotask.
|
|
341
|
+
* If `false`, updates are not throttled or batched.
|
|
342
|
+
* @default true
|
|
343
|
+
*/
|
|
344
|
+
throttle?: number | boolean;
|
|
345
|
+
}
|
|
346
|
+
interface RunMetadataStorage {
|
|
347
|
+
getItem(key: `lg:stream:${string}`): string | null;
|
|
348
|
+
setItem(key: `lg:stream:${string}`, value: string): void;
|
|
349
|
+
removeItem(key: `lg:stream:${string}`): void;
|
|
350
|
+
}
|
|
351
|
+
type ConfigWithConfigurable<ConfigurableType extends Record<string, unknown>> = Config & {
|
|
352
|
+
configurable?: ConfigurableType;
|
|
353
|
+
};
|
|
354
|
+
interface SubmitOptions<StateType extends Record<string, unknown> = Record<string, unknown>, ContextType extends Record<string, unknown> = Record<string, unknown>> {
|
|
355
|
+
config?: ConfigWithConfigurable<ContextType>;
|
|
356
|
+
context?: ContextType;
|
|
357
|
+
checkpoint?: Omit<Checkpoint, "thread_id"> | null;
|
|
358
|
+
command?: Command;
|
|
359
|
+
interruptBefore?: "*" | string[];
|
|
360
|
+
interruptAfter?: "*" | string[];
|
|
361
|
+
metadata?: Metadata;
|
|
362
|
+
multitaskStrategy?: MultitaskStrategy;
|
|
363
|
+
onCompletion?: OnCompletionBehavior;
|
|
364
|
+
onDisconnect?: DisconnectMode;
|
|
365
|
+
feedbackKeys?: string[];
|
|
366
|
+
streamMode?: Array<StreamMode>;
|
|
367
|
+
runId?: string;
|
|
368
|
+
optimisticValues?: Partial<StateType> | ((prev: StateType) => Partial<StateType>);
|
|
369
|
+
/**
|
|
370
|
+
* Whether or not to stream the nodes of any subgraphs called
|
|
371
|
+
* by the assistant.
|
|
372
|
+
* @default false
|
|
373
|
+
*/
|
|
374
|
+
streamSubgraphs?: boolean;
|
|
375
|
+
/**
|
|
376
|
+
* Mark the stream as resumable. All events emitted during the run will be temporarily persisted
|
|
377
|
+
* in order to be re-emitted if the stream is re-joined.
|
|
378
|
+
* @default false
|
|
379
|
+
*/
|
|
380
|
+
streamResumable?: boolean;
|
|
381
|
+
/**
|
|
382
|
+
* Whether to checkpoint during the run (or only at the end/interruption).
|
|
383
|
+
* - `"async"`: Save checkpoint asynchronously while the next step executes (default).
|
|
384
|
+
* - `"sync"`: Save checkpoint synchronously before the next step starts.
|
|
385
|
+
* - `"exit"`: Save checkpoint only when the graph exits.
|
|
386
|
+
* @default "async"
|
|
387
|
+
*/
|
|
388
|
+
durability?: Durability;
|
|
389
|
+
/**
|
|
390
|
+
* The ID to use when creating a new thread. When provided, this ID will be used
|
|
391
|
+
* for thread creation when threadId is `null` or `undefined`.
|
|
392
|
+
* This enables optimistic UI updates where you know the thread ID
|
|
393
|
+
* before the thread is actually created.
|
|
394
|
+
*/
|
|
395
|
+
threadId?: string;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Transport used to stream the thread.
|
|
399
|
+
* Only applicable for custom endpoints using `toLangGraphEventStream` or `toLangGraphEventStreamResponse`.
|
|
400
|
+
*/
|
|
401
|
+
interface UseStreamTransport<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> {
|
|
402
|
+
stream: (payload: {
|
|
403
|
+
input: GetUpdateType<Bag, StateType> | null | undefined;
|
|
404
|
+
context: GetConfigurableType<Bag> | undefined;
|
|
405
|
+
command: Command | undefined;
|
|
406
|
+
config: ConfigWithConfigurable<GetConfigurableType<Bag>> | undefined;
|
|
407
|
+
signal: AbortSignal;
|
|
408
|
+
}) => Promise<AsyncGenerator<{
|
|
409
|
+
id?: string;
|
|
410
|
+
event: string;
|
|
411
|
+
data: unknown;
|
|
412
|
+
}>>;
|
|
413
|
+
}
|
|
414
|
+
type UseStreamCustomOptions<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> = Pick<UseStreamOptions<StateType, Bag>, "messagesKey" | "threadId" | "onThreadId" | "onError" | "onCreated" | "onUpdateEvent" | "onCustomEvent" | "onMetadataEvent" | "onLangChainEvent" | "onDebugEvent" | "onCheckpointEvent" | "onTaskEvent" | "onStop" | "initialValues" | "throttle"> & {
|
|
415
|
+
transport: UseStreamTransport<StateType, Bag>;
|
|
416
|
+
};
|
|
417
|
+
type CustomSubmitOptions<StateType extends Record<string, unknown> = Record<string, unknown>, ConfigurableType extends Record<string, unknown> = Record<string, unknown>> = Pick<SubmitOptions<StateType, ConfigurableType>, "optimisticValues" | "context" | "command" | "config">;
|
|
418
|
+
//#endregion
|
|
419
|
+
export { AgentTypeConfigLike, CustomSubmitOptions, ExtractAgentConfig, GetConfigurableType, GetInterruptType, GetToolCallsType, GetUpdateType, InferAgentToolCalls, IsAgentLike, MessageMetadata, RunCallbackMeta, SubmitOptions, UseStreamCustomOptions, UseStreamOptions, UseStreamThread, UseStreamTransport };
|
|
420
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":["Client","ClientConfig","ThreadState","Config","Checkpoint","Metadata","Command","MultitaskStrategy","OnCompletionBehavior","DisconnectMode","Durability","UpdatesStreamEvent","CustomStreamEvent","MetadataStreamEvent","EventsStreamEvent","DebugStreamEvent","CheckpointsStreamEvent","TasksStreamEvent","StreamMode","DefaultToolCall","AIMessage","BagTemplate","AgentTypeConfigLike","IsAgentLike","T","ExtractAgentConfig","InferSchemaInput","S","Args","InferToolInput","ToolCallFromAgentTool","N","Record","InferAgentToolCalls","Tool","ExtractToolCallFromMessageUnion","M","TC","ExtractToolCallsFromState","StateType","Messages","MessageMetadata","GetUpdateType","Bag","Partial","GetConfigurableType","GetInterruptType","GetCustomEventType","GetToolCallsType","RunCallbackMeta","UseStreamThread","Promise","UseStreamOptions","RunMetadataStorage","ConfigWithConfigurable","ConfigurableType","SubmitOptions","ContextType","Omit","Array","UseStreamTransport","AbortSignal","AsyncGenerator","UseStreamCustomOptions","Pick","CustomSubmitOptions"],"sources":["../../src/ui/types.d.ts"],"sourcesContent":["import type { Client, ClientConfig } from \"../client.js\";\nimport type { ThreadState, Config, Checkpoint, Metadata } from \"../schema.js\";\nimport type { Command, MultitaskStrategy, OnCompletionBehavior, DisconnectMode, Durability } from \"../types.js\";\nimport type { UpdatesStreamEvent, CustomStreamEvent, MetadataStreamEvent, EventsStreamEvent, DebugStreamEvent, CheckpointsStreamEvent, TasksStreamEvent, StreamMode } from \"../types.stream.js\";\nimport type { DefaultToolCall, AIMessage } from \"../types.messages.js\";\nimport type { BagTemplate } from \"../types.template.js\";\n/**\n * Minimal interface matching the structure of AgentTypeConfig from @langchain/langgraph.\n * This allows type inference from ReactAgent without requiring the langchain dependency.\n */\nexport interface AgentTypeConfigLike {\n Response: unknown;\n State: unknown;\n Context: unknown;\n Middleware: unknown;\n Tools: unknown;\n}\n/**\n * Check if a type is agent-like (has `~agentTypes` phantom property).\n * This property is present on `ReactAgent` instances created with `createAgent`.\n */\nexport type IsAgentLike<T> = T extends {\n \"~agentTypes\": AgentTypeConfigLike;\n} ? true : false;\n/**\n * Extract the AgentTypeConfig from an agent-like type.\n *\n * @example\n * ```ts\n * const agent = createAgent({ ... });\n * type Config = ExtractAgentConfig<typeof agent>;\n * // Config is the AgentTypeConfig with Response, State, Context, Middleware, Tools\n * ```\n */\nexport type ExtractAgentConfig<T> = T extends {\n \"~agentTypes\": infer Config;\n} ? Config extends AgentTypeConfigLike ? Config : never : never;\n/**\n * Helper type to infer schema input type, supporting both Zod v3 and v4.\n * - Zod v4 uses `_zod.input` property\n * - Zod v3 uses `_input` property\n */\ntype InferSchemaInput<S> = S extends {\n _zod: {\n input: infer Args;\n };\n} ? Args : S extends {\n _input: infer Args;\n} ? Args : never;\n/**\n * Helper type to extract the input type from a DynamicStructuredTool's _call method.\n * This is more reliable than trying to infer from the schema directly because\n * DynamicStructuredTool has the input type baked into its _call signature.\n */\ntype InferToolInput<T> = T extends {\n _call: (arg: infer Args, ...rest: any[]) => any;\n} ? Args : T extends {\n schema: infer S;\n} ? InferSchemaInput<S> : never;\n/**\n * Extract a tool call type from a single tool.\n * Works with tools created via `tool()` from `@langchain/core/tools`.\n *\n * This extracts the literal name type from DynamicStructuredTool's NameT parameter\n * and the args type from the _call method or schema's input property.\n */\ntype ToolCallFromAgentTool<T> = T extends {\n name: infer N;\n} ? N extends string ? InferToolInput<T> extends infer Args ? Args extends never ? never : Args extends Record<string, any> ? {\n name: N;\n args: Args;\n id?: string;\n type?: \"tool_call\";\n} : never : never : never : never;\n/**\n * Extract tool calls type from an agent's tools.\n * Converts the tools array to a discriminated union of tool calls.\n *\n * This handles both tuple types (e.g., `readonly [Tool1, Tool2]`) and\n * array-of-union types (e.g., `readonly (Tool1 | Tool2)[]`) which is how\n * `createAgent` captures tool types.\n *\n * @example\n * ```ts\n * const agent = createAgent({ tools: [getWeather, search], ... });\n * type ToolCalls = InferAgentToolCalls<typeof agent>;\n * // ToolCalls is:\n * // | { name: \"get_weather\"; args: { location: string }; id?: string }\n * // | { name: \"search\"; args: { query: string }; id?: string }\n * ```\n */\nexport type InferAgentToolCalls<T> = ExtractAgentConfig<T>[\"Tools\"] extends readonly (infer Tool)[] ? ToolCallFromAgentTool<Tool> extends never ? DefaultToolCall : ToolCallFromAgentTool<Tool> : DefaultToolCall;\n/**\n * Extract the tool call type parameter from an AIMessage in a message union.\n * Returns `never` if the message is not an AIMessage or uses DefaultToolCall.\n *\n * The key distinction: custom tool calls have literal `name` types (e.g., \"get_weather\"),\n * while DefaultToolCall has `name: string`. We check if `string extends TC[\"name\"]` -\n * if true, it's DefaultToolCall; if false, it's a custom type with literal names.\n */\ntype ExtractToolCallFromMessageUnion<M> = M extends AIMessage<infer TC> ? TC extends {\n name: infer N;\n} ? string extends N ? never : TC : never : never;\n/**\n * Extract the tool call type from a StateType's messages property.\n * This is the primary way to specify tool call types when using useStream.\n *\n * @example\n * ```ts\n * // Define state with typed messages\n * type MyToolCalls =\n * | { name: \"get_weather\"; args: { location: string }; id?: string }\n * | { name: \"search\"; args: { query: string }; id?: string };\n *\n * interface MyState {\n * messages: Message<MyToolCalls>[];\n * }\n *\n * // ExtractToolCallsFromState<MyState> = MyToolCalls\n * ```\n */\nexport type ExtractToolCallsFromState<StateType extends Record<string, unknown>> = StateType extends {\n messages: infer Messages;\n} ? Messages extends readonly (infer M)[] ? ExtractToolCallFromMessageUnion<M> : Messages extends (infer M)[] ? ExtractToolCallFromMessageUnion<M> : never : never;\nexport type MessageMetadata<StateType extends Record<string, unknown>> = {\n /**\n * The ID of the message used.\n */\n messageId: string;\n /**\n * The first thread state the message was seen in.\n */\n firstSeenState: ThreadState<StateType> | undefined;\n /**\n * The branch of the message.\n */\n branch: string | undefined;\n /**\n * The list of branches this message is part of.\n * This is useful for displaying branching controls.\n */\n branchOptions: string[] | undefined;\n /**\n * Metadata sent alongside the message during run streaming.\n * @remarks This metadata only exists temporarily in browser memory during streaming and is not persisted after completion.\n */\n streamMetadata: Record<string, unknown> | undefined;\n};\nexport type GetUpdateType<Bag extends BagTemplate, StateType extends Record<string, unknown>> = Bag extends {\n UpdateType: unknown;\n} ? Bag[\"UpdateType\"] : Partial<StateType>;\nexport type GetConfigurableType<Bag extends BagTemplate> = Bag extends {\n ConfigurableType: Record<string, unknown>;\n} ? Bag[\"ConfigurableType\"] : Record<string, unknown>;\nexport type GetInterruptType<Bag extends BagTemplate> = Bag extends {\n InterruptType: unknown;\n} ? Bag[\"InterruptType\"] : unknown;\nexport type GetCustomEventType<Bag extends BagTemplate> = Bag extends {\n CustomEventType: unknown;\n} ? Bag[\"CustomEventType\"] : unknown;\n/**\n * Extract the tool call type from a StateType's messages property.\n * This is the canonical way to get typed tool calls in useStream.\n *\n * Tool call types are now extracted from the messages property of StateType,\n * rather than being specified separately in the Bag.\n *\n * @example\n * ```ts\n * // Define state with typed messages\n * type MyToolCalls =\n * | { name: \"get_weather\"; args: { location: string }; id?: string }\n * | { name: \"search\"; args: { query: string }; id?: string };\n *\n * interface MyState {\n * messages: Message<MyToolCalls>[];\n * }\n *\n * // GetToolCallsType<MyState> = MyToolCalls\n * ```\n */\nexport type GetToolCallsType<StateType extends Record<string, unknown>> = ExtractToolCallsFromState<StateType> extends never ? DefaultToolCall : ExtractToolCallsFromState<StateType>;\nexport interface RunCallbackMeta {\n run_id: string;\n thread_id: string;\n}\nexport interface UseStreamThread<StateType extends Record<string, unknown>> {\n data: ThreadState<StateType>[] | null | undefined;\n error: unknown;\n isLoading: boolean;\n mutate: (mutateId?: string) => Promise<ThreadState<StateType>[] | null | undefined>;\n}\nexport interface UseStreamOptions<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> {\n /**\n * The ID of the assistant to use.\n */\n assistantId: string;\n /**\n * Client used to send requests.\n */\n client?: Client;\n /**\n * The URL of the API to use.\n */\n apiUrl?: ClientConfig[\"apiUrl\"];\n /**\n * The API key to use.\n */\n apiKey?: ClientConfig[\"apiKey\"];\n /**\n * Custom call options, such as custom fetch implementation.\n */\n callerOptions?: ClientConfig[\"callerOptions\"];\n /**\n * Default headers to send with requests.\n */\n defaultHeaders?: ClientConfig[\"defaultHeaders\"];\n /**\n * Specify the key within the state that contains messages.\n * Defaults to \"messages\".\n *\n * @default \"messages\"\n */\n messagesKey?: string;\n /**\n * Callback that is called when an error occurs.\n */\n onError?: (error: unknown, run: RunCallbackMeta | undefined) => void;\n /**\n * Callback that is called when the stream is finished.\n */\n onFinish?: (state: ThreadState<StateType>, run: RunCallbackMeta | undefined) => void;\n /**\n * Callback that is called when a new stream is created.\n */\n onCreated?: (run: RunCallbackMeta) => void;\n /**\n * Callback that is called when an update event is received.\n */\n onUpdateEvent?: (data: UpdatesStreamEvent<GetUpdateType<Bag, StateType>>[\"data\"], options: {\n namespace: string[] | undefined;\n mutate: (update: Partial<StateType> | ((prev: StateType) => Partial<StateType>)) => void;\n }) => void;\n /**\n * Callback that is called when a custom event is received.\n */\n onCustomEvent?: (data: CustomStreamEvent<GetCustomEventType<Bag>>[\"data\"], options: {\n namespace: string[] | undefined;\n mutate: (update: Partial<StateType> | ((prev: StateType) => Partial<StateType>)) => void;\n }) => void;\n /**\n * Callback that is called when a metadata event is received.\n */\n onMetadataEvent?: (data: MetadataStreamEvent[\"data\"]) => void;\n /**\n * Callback that is called when a LangChain event is received.\n * @see https://langchain-ai.github.io/langgraph/cloud/how-tos/stream_events/#stream-graph-in-events-mode for more details.\n */\n onLangChainEvent?: (data: EventsStreamEvent[\"data\"]) => void;\n /**\n * Callback that is called when a debug event is received.\n * @internal This API is experimental and subject to change.\n */\n onDebugEvent?: (data: DebugStreamEvent[\"data\"], options: {\n namespace: string[] | undefined;\n }) => void;\n /**\n * Callback that is called when a checkpoints event is received.\n */\n onCheckpointEvent?: (data: CheckpointsStreamEvent<StateType>[\"data\"], options: {\n namespace: string[] | undefined;\n }) => void;\n /**\n * Callback that is called when a tasks event is received.\n */\n onTaskEvent?: (data: TasksStreamEvent<StateType, GetUpdateType<Bag, StateType>>[\"data\"], options: {\n namespace: string[] | undefined;\n }) => void;\n /**\n * Callback that is called when the stream is stopped by the user.\n * Provides a mutate function to update the stream state immediately\n * without requiring a server roundtrip.\n *\n * @example\n * ```typescript\n * onStop: ({ mutate }) => {\n * mutate((prev) => ({\n * ...prev,\n * ui: prev.ui?.map(component =>\n * component.props.isLoading\n * ? { ...component, props: { ...component.props, stopped: true, isLoading: false }}\n * : component\n * )\n * }));\n * }\n * ```\n */\n onStop?: (options: {\n mutate: (update: Partial<StateType> | ((prev: StateType) => Partial<StateType>)) => void;\n }) => void;\n /**\n * The ID of the thread to fetch history and current values from.\n */\n threadId?: string | null;\n /**\n * Callback that is called when the thread ID is updated (ie when a new thread is created).\n */\n onThreadId?: (threadId: string) => void;\n /** Will reconnect the stream on mount */\n reconnectOnMount?: boolean | (() => RunMetadataStorage);\n /**\n * Initial values to display immediately when loading a thread.\n * Useful for displaying cached thread data while official history loads.\n * These values will be replaced when official thread data is fetched.\n *\n * Note: UI components from initialValues will render immediately if they're\n * predefined in LoadExternalComponent's components prop, providing instant\n * cached UI display without server fetches.\n */\n initialValues?: StateType | null;\n /**\n * Whether to fetch the history of the thread.\n * If true, the history will be fetched from the server. Defaults to 10 entries.\n * If false, only the last state will be fetched from the server.\n * @default true\n */\n fetchStateHistory?: boolean | {\n limit: number;\n };\n /**\n * Manage the thread state externally.\n */\n thread?: UseStreamThread<StateType>;\n /**\n * Throttle the stream.\n * If a number is provided, the stream will be throttled to the given number of milliseconds.\n * If `true`, updates are batched in a single macrotask.\n * If `false`, updates are not throttled or batched.\n * @default true\n */\n throttle?: number | boolean;\n}\ninterface RunMetadataStorage {\n getItem(key: `lg:stream:${string}`): string | null;\n setItem(key: `lg:stream:${string}`, value: string): void;\n removeItem(key: `lg:stream:${string}`): void;\n}\ntype ConfigWithConfigurable<ConfigurableType extends Record<string, unknown>> = Config & {\n configurable?: ConfigurableType;\n};\nexport interface SubmitOptions<StateType extends Record<string, unknown> = Record<string, unknown>, ContextType extends Record<string, unknown> = Record<string, unknown>> {\n config?: ConfigWithConfigurable<ContextType>;\n context?: ContextType;\n checkpoint?: Omit<Checkpoint, \"thread_id\"> | null;\n command?: Command;\n interruptBefore?: \"*\" | string[];\n interruptAfter?: \"*\" | string[];\n metadata?: Metadata;\n multitaskStrategy?: MultitaskStrategy;\n onCompletion?: OnCompletionBehavior;\n onDisconnect?: DisconnectMode;\n feedbackKeys?: string[];\n streamMode?: Array<StreamMode>;\n runId?: string;\n optimisticValues?: Partial<StateType> | ((prev: StateType) => Partial<StateType>);\n /**\n * Whether or not to stream the nodes of any subgraphs called\n * by the assistant.\n * @default false\n */\n streamSubgraphs?: boolean;\n /**\n * Mark the stream as resumable. All events emitted during the run will be temporarily persisted\n * in order to be re-emitted if the stream is re-joined.\n * @default false\n */\n streamResumable?: boolean;\n /**\n * Whether to checkpoint during the run (or only at the end/interruption).\n * - `\"async\"`: Save checkpoint asynchronously while the next step executes (default).\n * - `\"sync\"`: Save checkpoint synchronously before the next step starts.\n * - `\"exit\"`: Save checkpoint only when the graph exits.\n * @default \"async\"\n */\n durability?: Durability;\n /**\n * The ID to use when creating a new thread. When provided, this ID will be used\n * for thread creation when threadId is `null` or `undefined`.\n * This enables optimistic UI updates where you know the thread ID\n * before the thread is actually created.\n */\n threadId?: string;\n}\n/**\n * Transport used to stream the thread.\n * Only applicable for custom endpoints using `toLangGraphEventStream` or `toLangGraphEventStreamResponse`.\n */\nexport interface UseStreamTransport<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> {\n stream: (payload: {\n input: GetUpdateType<Bag, StateType> | null | undefined;\n context: GetConfigurableType<Bag> | undefined;\n command: Command | undefined;\n config: ConfigWithConfigurable<GetConfigurableType<Bag>> | undefined;\n signal: AbortSignal;\n }) => Promise<AsyncGenerator<{\n id?: string;\n event: string;\n data: unknown;\n }>>;\n}\nexport type UseStreamCustomOptions<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> = Pick<UseStreamOptions<StateType, Bag>, \"messagesKey\" | \"threadId\" | \"onThreadId\" | \"onError\" | \"onCreated\" | \"onUpdateEvent\" | \"onCustomEvent\" | \"onMetadataEvent\" | \"onLangChainEvent\" | \"onDebugEvent\" | \"onCheckpointEvent\" | \"onTaskEvent\" | \"onStop\" | \"initialValues\" | \"throttle\"> & {\n transport: UseStreamTransport<StateType, Bag>;\n};\nexport type CustomSubmitOptions<StateType extends Record<string, unknown> = Record<string, unknown>, ConfigurableType extends Record<string, unknown> = Record<string, unknown>> = Pick<SubmitOptions<StateType, ConfigurableType>, \"optimisticValues\" | \"context\" | \"command\" | \"config\">;\nexport {};\n"],"mappings":";;;;;;;;;;;AAUA;AAWA;AAAuB,UAXNsB,mBAAAA,CAWM;UAAME,EAAAA,OAAAA;OACVF,EAAAA,OAAAA;EAAmB,OAAA,EAAA,OAAA;EAY1BG,UAAAA,EAAAA,OAAAA;EAAkB,KAAA,EAAA,OAAA;;;;;;AAQzBC,KArBOH,WAqBS,CAAA,CAAA,CAAA,GArBQC,CAqBR,SAAA;EAAA,aAAA,EApBFF,mBAoBE;QAAMK,GAAAA,KAAAA;;;;;AAMnB;;;;;;AAUJD,KAxBQD,kBAwBRC,CAAAA,CAAAA,CAAAA,GAxBgCF,CAwBhCE,SAAAA;EAAgB,aAAA,EAAA,KAAA,OAAA;AAAA,CAAA,GAtBhBvB,MA8BC2B,SA9BcR,mBA8BO,GA9BenB,MA8Bf,GAAA,KAAA,GAAA,KAAA;;;;;;KAxBrBuB,gBA0ByDE,CAAAA,CAAAA,CAAAA,GA1BnCD,CA0BmCC,SAAAA;MAA6BA,EAAAA;IAAaI,KAAAA,EAAAA,KAAAA,KAAAA;;IAtBpGJ,IAwBMA,GAxBCD,CAwBDC,SAAAA;EAAI,MAAA,EAAA,KAAA,KAAA;AAqBd,CAAA,GA3CIA,IA2CQK,GAAAA,KAAAA;;;;;;KArCPJ,cAqC6IV,CAAAA,CAAAA,CAAAA,GArCzHK,CAqCyHL,SAAAA;OAAwCe,EAAAA,CAAAA,GAAAA,EAAAA,KAAAA,KAAAA,EAAAA,GAAAA,IAAAA,EAAAA,GAAAA,EAAAA,EAAAA,GAAAA,GAAAA;IAnCtLN,IAmCgKE,GA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;;;eAoBzD7B;;;;;;;;;;;;;UAaAkD,qCAAqC5B,0BAA0BA,qCAAqCX,cAAcA;;WAEpHqB,cAAcC,KAAKJ;aACjBM,oBAAoBF;aACpBrC;YACDgD,uBAAuBT,oBAAoBF;YAC3CkB;QACNV,QAAQW;;;;;;KAMNC,yCAAyC/B,0BAA0BA,qCAAqCX,cAAcA,eAAe2C,KAAKZ,iBAAiBb,WAAWI;aACnKiB,mBAAmBrB,WAAWI;;KAEjCsB,sCAAsCjC,0BAA0BA,kDAAkDA,0BAA0BA,2BAA2BgC,KAAKR,cAAcjB,WAAWgB"}
|
package/dist/ui/utils.cjs
CHANGED
package/dist/ui/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","names":[],"sources":["../../src/ui/utils.ts"],"sourcesContent":["export function unique<T>(array: T[]) {\n return [...new Set(array)] as T[];\n}\n\nexport function findLast<T>(array: T[], predicate: (item: T) => boolean) {\n for (let i = array.length - 1; i >= 0; i -= 1) {\n if (predicate(array[i])) return array[i];\n }\n return undefined;\n}\n"],"mappings":";;AAAA,SAAgB,OAAU,OAAY;AACpC,QAAO,CAAC,GAAG,IAAI,IAAI;;
|
|
1
|
+
{"version":3,"file":"utils.cjs","names":[],"sources":["../../src/ui/utils.ts"],"sourcesContent":["export function unique<T>(array: T[]) {\n return [...new Set(array)] as T[];\n}\n\nexport function findLast<T>(array: T[], predicate: (item: T) => boolean) {\n for (let i = array.length - 1; i >= 0; i -= 1) {\n if (predicate(array[i])) return array[i];\n }\n return undefined;\n}\n"],"mappings":";;AAAA,SAAgB,OAAU,OAAY;AACpC,QAAO,CAAC,GAAG,IAAI,IAAI,MAAM,CAAC;;AAG5B,SAAgB,SAAY,OAAY,WAAiC;AACvE,MAAK,IAAI,IAAI,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK,EAC1C,KAAI,UAAU,MAAM,GAAG,CAAE,QAAO,MAAM"}
|
package/dist/ui/utils.js
CHANGED
package/dist/ui/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":[],"sources":["../../src/ui/utils.ts"],"sourcesContent":["export function unique<T>(array: T[]) {\n return [...new Set(array)] as T[];\n}\n\nexport function findLast<T>(array: T[], predicate: (item: T) => boolean) {\n for (let i = array.length - 1; i >= 0; i -= 1) {\n if (predicate(array[i])) return array[i];\n }\n return undefined;\n}\n"],"mappings":";AAAA,SAAgB,OAAU,OAAY;AACpC,QAAO,CAAC,GAAG,IAAI,IAAI;;
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../../src/ui/utils.ts"],"sourcesContent":["export function unique<T>(array: T[]) {\n return [...new Set(array)] as T[];\n}\n\nexport function findLast<T>(array: T[], predicate: (item: T) => boolean) {\n for (let i = array.length - 1; i >= 0; i -= 1) {\n if (predicate(array[i])) return array[i];\n }\n return undefined;\n}\n"],"mappings":";AAAA,SAAgB,OAAU,OAAY;AACpC,QAAO,CAAC,GAAG,IAAI,IAAI,MAAM,CAAC;;AAG5B,SAAgB,SAAY,OAAY,WAAiC;AACvE,MAAK,IAAI,IAAI,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK,EAC1C,KAAI,UAAU,MAAM,GAAG,CAAE,QAAO,MAAM"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_fetch = require('../singletons/fetch.cjs');
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
let p_retry = require("p-retry");
|
|
4
|
+
p_retry = require_rolldown_runtime.__toESM(p_retry);
|
|
5
|
+
let p_queue = require("p-queue");
|
|
6
|
+
p_queue = require_rolldown_runtime.__toESM(p_queue);
|
|
5
7
|
|
|
6
8
|
//#region src/utils/async_caller.ts
|
|
7
9
|
const STATUS_NO_RETRY = [
|
|
@@ -80,9 +82,15 @@ var AsyncCaller = class {
|
|
|
80
82
|
else if (isResponse(error)) throw await HTTPError.fromResponse(error, { includeResponse: !!onFailedResponseHook });
|
|
81
83
|
else throw new Error(error);
|
|
82
84
|
}), {
|
|
83
|
-
async onFailedAttempt(error) {
|
|
84
|
-
|
|
85
|
+
async onFailedAttempt({ error }) {
|
|
86
|
+
const errorMessage = error.message ?? "";
|
|
87
|
+
if (errorMessage.startsWith("Cancel") || errorMessage.startsWith("TimeoutError") || errorMessage.startsWith("AbortError")) throw error;
|
|
85
88
|
if (error?.code === "ECONNABORTED") throw error;
|
|
89
|
+
if (errorMessage.includes("ECONNREFUSED") || errorMessage.includes("fetch failed") || errorMessage.includes("Failed to fetch") || errorMessage.includes("NetworkError")) {
|
|
90
|
+
const connectionError = /* @__PURE__ */ new Error(`Unable to connect to LangGraph server. Please ensure the server is running and accessible. Original error: ${errorMessage}`);
|
|
91
|
+
connectionError.name = "ConnectionError";
|
|
92
|
+
throw connectionError;
|
|
93
|
+
}
|
|
86
94
|
if (error instanceof HTTPError) {
|
|
87
95
|
if (STATUS_NO_RETRY.includes(error.status)) throw error;
|
|
88
96
|
if (onFailedResponseHook && error.response) await onFailedResponseHook(error.response);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async_caller.cjs","names":["PQueueMod","_getFetchImplementation"],"sources":["../../src/utils/async_caller.ts"],"sourcesContent":["import pRetry from \"p-retry\";\nimport PQueueMod from \"p-queue\";\nimport { _getFetchImplementation } from \"../singletons/fetch.js\";\n\nconst STATUS_NO_RETRY = [\n 400, // Bad Request\n 401, // Unauthorized\n 402, // Payment required\n 403, // Forbidden\n 404, // Not Found\n 405, // Method Not Allowed\n 406, // Not Acceptable\n 407, // Proxy Authentication Required\n 408, // Request Timeout\n 409, // Conflict\n 422, // Unprocessable Entity\n];\n\ntype ResponseCallback = (response?: Response) => Promise<boolean>;\n\nexport interface AsyncCallerParams {\n /**\n * The maximum number of concurrent calls that can be made.\n * Defaults to `Infinity`, which means no limit.\n */\n maxConcurrency?: number;\n /**\n * The maximum number of retries that can be made for a single call,\n * with an exponential backoff between each attempt. Defaults to 6.\n */\n maxRetries?: number;\n\n onFailedResponseHook?: ResponseCallback;\n\n /**\n * Specify a custom fetch implementation.\n *\n * By default we expect the `fetch` is available in the global scope.\n */\n fetch?: typeof fetch | ((...args: any[]) => any); // eslint-disable-line @typescript-eslint/no-explicit-any\n}\n\nexport interface AsyncCallerCallOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Do not rely on globalThis.Response, rather just\n * do duck typing\n */\nfunction isResponse(x: unknown): x is Response {\n if (x == null || typeof x !== \"object\") return false;\n return \"status\" in x && \"statusText\" in x && \"text\" in x;\n}\n\n/**\n * Utility error to properly handle failed requests\n */\nclass HTTPError extends Error {\n status: number;\n\n text: string;\n\n response?: Response;\n\n constructor(status: number, message: string, response?: Response) {\n super(`HTTP ${status}: ${message}`);\n this.status = status;\n this.text = message;\n this.response = response;\n }\n\n static async fromResponse(\n response: Response,\n options?: { includeResponse?: boolean }\n ): Promise<HTTPError> {\n try {\n return new HTTPError(\n response.status,\n await response.text(),\n options?.includeResponse ? response : undefined\n );\n } catch {\n return new HTTPError(\n response.status,\n response.statusText,\n options?.includeResponse ? response : undefined\n );\n }\n }\n}\n\n/**\n * A class that can be used to make async calls with concurrency and retry logic.\n *\n * This is useful for making calls to any kind of \"expensive\" external resource,\n * be it because it's rate-limited, subject to network issues, etc.\n *\n * Concurrent calls are limited by the `maxConcurrency` parameter, which defaults\n * to `Infinity`. This means that by default, all calls will be made in parallel.\n *\n * Retries are limited by the `maxRetries` parameter, which defaults to 5. This\n * means that by default, each call will be retried up to 5 times, with an\n * exponential backoff between each attempt.\n */\nexport class AsyncCaller {\n protected maxConcurrency: AsyncCallerParams[\"maxConcurrency\"];\n\n protected maxRetries: AsyncCallerParams[\"maxRetries\"];\n\n private queue: typeof import(\"p-queue\")[\"default\"][\"prototype\"];\n\n private onFailedResponseHook?: ResponseCallback;\n\n private customFetch?: typeof fetch;\n\n constructor(params: AsyncCallerParams) {\n this.maxConcurrency = params.maxConcurrency ?? Infinity;\n this.maxRetries = params.maxRetries ?? 4;\n\n if (\"default\" in PQueueMod) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.queue = new (PQueueMod.default as any)({\n concurrency: this.maxConcurrency,\n });\n } else {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.queue = new (PQueueMod as any)({ concurrency: this.maxConcurrency });\n }\n this.onFailedResponseHook = params?.onFailedResponseHook;\n this.customFetch = params.fetch;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n call<A extends any[], T extends (...args: A) => Promise<any>>(\n callable: T,\n ...args: Parameters<T>\n ): Promise<Awaited<ReturnType<T>>> {\n const { onFailedResponseHook } = this;\n return this.queue.add(\n () =>\n pRetry(\n () =>\n callable(...(args as Parameters<T>)).catch(async (error) => {\n // eslint-disable-next-line no-instanceof/no-instanceof\n if (error instanceof Error) {\n throw error;\n } else if (isResponse(error)) {\n throw await HTTPError.fromResponse(error, {\n includeResponse: !!onFailedResponseHook,\n });\n } else {\n throw new Error(error);\n }\n }),\n {\n async onFailedAttempt(error) {\n if (\n error.message.startsWith(\"Cancel\") ||\n error.message.startsWith(\"TimeoutError\") ||\n error.message.startsWith(\"AbortError\")\n ) {\n throw error;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((error as any)?.code === \"ECONNABORTED\") {\n throw error;\n }\n\n // eslint-disable-next-line no-instanceof/no-instanceof\n if (error instanceof HTTPError) {\n if (STATUS_NO_RETRY.includes(error.status)) {\n throw error;\n }\n if (onFailedResponseHook && error.response) {\n await onFailedResponseHook(error.response);\n }\n }\n },\n // If needed we can change some of the defaults here,\n // but they're quite sensible.\n retries: this.maxRetries,\n randomize: true,\n }\n ),\n { throwOnTimeout: true }\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(\n options: AsyncCallerCallOptions,\n callable: T,\n ...args: Parameters<T>\n ): Promise<Awaited<ReturnType<T>>> {\n // Note this doesn't cancel the underlying request,\n // when available prefer to use the signal option of the underlying call\n if (options.signal) {\n return Promise.race([\n this.call<A, T>(callable, ...args),\n new Promise<never>((_, reject) => {\n options.signal?.addEventListener(\"abort\", () => {\n reject(new Error(\"AbortError\"));\n });\n }),\n ]);\n }\n return this.call<A, T>(callable, ...args);\n }\n\n fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch> {\n const fetchFn =\n this.customFetch ?? (_getFetchImplementation() as typeof fetch);\n return this.call(() =>\n fetchFn(...args).then((res) => (res.ok ? res : Promise.reject(res)))\n );\n }\n}\n"],"mappings":";;;;;;AAIA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;;;;;AAmCF,SAAS,WAAW,GAA2B;AAC7C,KAAI,KAAK,QAAQ,OAAO,MAAM,SAAU,QAAO;AAC/C,QAAO,YAAY,KAAK,gBAAgB,KAAK,UAAU;;;;;AAMzD,IAAM,YAAN,MAAM,kBAAkB,MAAM;CAC5B;CAEA;CAEA;CAEA,YAAY,QAAgB,SAAiB,UAAqB;AAChE,QAAM,QAAQ,OAAO,IAAI;AACzB,OAAK,SAAS;AACd,OAAK,OAAO;AACZ,OAAK,WAAW;;CAGlB,aAAa,aACX,UACA,SACoB;AACpB,MAAI;AACF,UAAO,IAAI,UACT,SAAS,QACT,MAAM,SAAS,QACf,SAAS,kBAAkB,WAAW;UAElC;AACN,UAAO,IAAI,UACT,SAAS,QACT,SAAS,YACT,SAAS,kBAAkB,WAAW;;;;;;;;;;;;;;;;;AAmB9C,IAAa,cAAb,MAAyB;CACvB,AAAU;CAEV,AAAU;CAEV,AAAQ;CAER,AAAQ;CAER,AAAQ;CAER,YAAY,QAA2B;AACrC,OAAK,iBAAiB,OAAO,kBAAkB;AAC/C,OAAK,aAAa,OAAO,cAAc;AAEvC,MAAI,aAAaA,gBAEf,MAAK,QAAQ,IAAKA,gBAAU,QAAgB,EAC1C,aAAa,KAAK;MAIpB,MAAK,QAAQ,IAAKA,gBAAkB,EAAE,aAAa,KAAK;AAE1D,OAAK,uBAAuB,QAAQ;AACpC,OAAK,cAAc,OAAO;;CAI5B,KACE,UACA,GAAG,MAC8B;EACjC,MAAM,EAAE,yBAAyB;AACjC,SAAO,KAAK,MAAM,qCAIV,SAAS,GAAI,MAAwB,MAAM,OAAO,UAAU;AAE1D,OAAI,iBAAiB,MACnB,OAAM;YACG,WAAW,OACpB,OAAM,MAAM,UAAU,aAAa,OAAO,EACxC,iBAAiB,CAAC,CAAC;OAGrB,OAAM,IAAI,MAAM;MAGtB;GACE,MAAM,gBAAgB,OAAO;AAC3B,QACE,MAAM,QAAQ,WAAW,aACzB,MAAM,QAAQ,WAAW,mBACzB,MAAM,QAAQ,WAAW,cAEzB,OAAM;AAGR,QAAK,OAAe,SAAS,eAC3B,OAAM;AAIR,QAAI,iBAAiB,WAAW;AAC9B,SAAI,gBAAgB,SAAS,MAAM,QACjC,OAAM;AAER,SAAI,wBAAwB,MAAM,SAChC,OAAM,qBAAqB,MAAM;;;GAMvC,SAAS,KAAK;GACd,WAAW;MAGjB,EAAE,gBAAgB;;CAKtB,gBACE,SACA,UACA,GAAG,MAC8B;AAGjC,MAAI,QAAQ,OACV,QAAO,QAAQ,KAAK,CAClB,KAAK,KAAW,UAAU,GAAG,OAC7B,IAAI,SAAgB,GAAG,WAAW;AAChC,WAAQ,QAAQ,iBAAiB,eAAe;AAC9C,2BAAO,IAAI,MAAM;;;AAKzB,SAAO,KAAK,KAAW,UAAU,GAAG;;CAGtC,MAAM,GAAG,MAA0D;EACjE,MAAM,UACJ,KAAK,eAAgBC;AACvB,SAAO,KAAK,WACV,QAAQ,GAAG,MAAM,MAAM,QAAS,IAAI,KAAK,MAAM,QAAQ,OAAO"}
|
|
1
|
+
{"version":3,"file":"async_caller.cjs","names":["PQueueMod","_getFetchImplementation"],"sources":["../../src/utils/async_caller.ts"],"sourcesContent":["import pRetry from \"p-retry\";\nimport PQueueMod from \"p-queue\";\nimport { _getFetchImplementation } from \"../singletons/fetch.js\";\n\nconst STATUS_NO_RETRY = [\n 400, // Bad Request\n 401, // Unauthorized\n 402, // Payment required\n 403, // Forbidden\n 404, // Not Found\n 405, // Method Not Allowed\n 406, // Not Acceptable\n 407, // Proxy Authentication Required\n 408, // Request Timeout\n 409, // Conflict\n 422, // Unprocessable Entity\n];\n\ntype ResponseCallback = (response?: Response) => Promise<boolean>;\n\nexport interface AsyncCallerParams {\n /**\n * The maximum number of concurrent calls that can be made.\n * Defaults to `Infinity`, which means no limit.\n */\n maxConcurrency?: number;\n /**\n * The maximum number of retries that can be made for a single call,\n * with an exponential backoff between each attempt. Defaults to 6.\n */\n maxRetries?: number;\n\n onFailedResponseHook?: ResponseCallback;\n\n /**\n * Specify a custom fetch implementation.\n *\n * By default we expect the `fetch` is available in the global scope.\n */\n fetch?: typeof fetch | ((...args: any[]) => any); // eslint-disable-line @typescript-eslint/no-explicit-any\n}\n\nexport interface AsyncCallerCallOptions {\n signal?: AbortSignal;\n}\n\n/**\n * Do not rely on globalThis.Response, rather just\n * do duck typing\n */\nfunction isResponse(x: unknown): x is Response {\n if (x == null || typeof x !== \"object\") return false;\n return \"status\" in x && \"statusText\" in x && \"text\" in x;\n}\n\n/**\n * Utility error to properly handle failed requests\n */\nclass HTTPError extends Error {\n status: number;\n\n text: string;\n\n response?: Response;\n\n constructor(status: number, message: string, response?: Response) {\n super(`HTTP ${status}: ${message}`);\n this.status = status;\n this.text = message;\n this.response = response;\n }\n\n static async fromResponse(\n response: Response,\n options?: { includeResponse?: boolean }\n ): Promise<HTTPError> {\n try {\n return new HTTPError(\n response.status,\n await response.text(),\n options?.includeResponse ? response : undefined\n );\n } catch {\n return new HTTPError(\n response.status,\n response.statusText,\n options?.includeResponse ? response : undefined\n );\n }\n }\n}\n\n/**\n * A class that can be used to make async calls with concurrency and retry logic.\n *\n * This is useful for making calls to any kind of \"expensive\" external resource,\n * be it because it's rate-limited, subject to network issues, etc.\n *\n * Concurrent calls are limited by the `maxConcurrency` parameter, which defaults\n * to `Infinity`. This means that by default, all calls will be made in parallel.\n *\n * Retries are limited by the `maxRetries` parameter, which defaults to 5. This\n * means that by default, each call will be retried up to 5 times, with an\n * exponential backoff between each attempt.\n */\nexport class AsyncCaller {\n protected maxConcurrency: AsyncCallerParams[\"maxConcurrency\"];\n\n protected maxRetries: AsyncCallerParams[\"maxRetries\"];\n\n private queue: typeof import(\"p-queue\")[\"default\"][\"prototype\"];\n\n private onFailedResponseHook?: ResponseCallback;\n\n private customFetch?: typeof fetch;\n\n constructor(params: AsyncCallerParams) {\n this.maxConcurrency = params.maxConcurrency ?? Infinity;\n this.maxRetries = params.maxRetries ?? 4;\n\n if (\"default\" in PQueueMod) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.queue = new (PQueueMod.default as any)({\n concurrency: this.maxConcurrency,\n });\n } else {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.queue = new (PQueueMod as any)({ concurrency: this.maxConcurrency });\n }\n this.onFailedResponseHook = params?.onFailedResponseHook;\n this.customFetch = params.fetch;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n call<A extends any[], T extends (...args: A) => Promise<any>>(\n callable: T,\n ...args: Parameters<T>\n ): Promise<Awaited<ReturnType<T>>> {\n const { onFailedResponseHook } = this;\n return this.queue.add(\n () =>\n pRetry(\n () =>\n callable(...(args as Parameters<T>)).catch(async (error) => {\n // eslint-disable-next-line no-instanceof/no-instanceof\n if (error instanceof Error) {\n throw error;\n } else if (isResponse(error)) {\n throw await HTTPError.fromResponse(error, {\n includeResponse: !!onFailedResponseHook,\n });\n } else {\n throw new Error(error);\n }\n }),\n {\n async onFailedAttempt({ error }) {\n const errorMessage = error.message ?? \"\";\n if (\n errorMessage.startsWith(\"Cancel\") ||\n errorMessage.startsWith(\"TimeoutError\") ||\n errorMessage.startsWith(\"AbortError\")\n ) {\n throw error;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((error as any)?.code === \"ECONNABORTED\") {\n throw error;\n }\n\n // Check for connection refused errors (server not running)\n if (\n errorMessage.includes(\"ECONNREFUSED\") ||\n errorMessage.includes(\"fetch failed\") ||\n errorMessage.includes(\"Failed to fetch\") ||\n errorMessage.includes(\"NetworkError\")\n ) {\n const connectionError = new Error(\n `Unable to connect to LangGraph server. Please ensure the server is running and accessible. Original error: ${errorMessage}`\n );\n connectionError.name = \"ConnectionError\";\n throw connectionError;\n }\n\n // eslint-disable-next-line no-instanceof/no-instanceof\n if (error instanceof HTTPError) {\n if (STATUS_NO_RETRY.includes(error.status)) {\n throw error;\n }\n if (onFailedResponseHook && error.response) {\n await onFailedResponseHook(error.response);\n }\n }\n },\n // If needed we can change some of the defaults here,\n // but they're quite sensible.\n retries: this.maxRetries,\n randomize: true,\n }\n ),\n { throwOnTimeout: true }\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(\n options: AsyncCallerCallOptions,\n callable: T,\n ...args: Parameters<T>\n ): Promise<Awaited<ReturnType<T>>> {\n // Note this doesn't cancel the underlying request,\n // when available prefer to use the signal option of the underlying call\n if (options.signal) {\n return Promise.race([\n this.call<A, T>(callable, ...args),\n new Promise<never>((_, reject) => {\n options.signal?.addEventListener(\"abort\", () => {\n reject(new Error(\"AbortError\"));\n });\n }),\n ]);\n }\n return this.call<A, T>(callable, ...args);\n }\n\n fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch> {\n const fetchFn =\n this.customFetch ?? (_getFetchImplementation() as typeof fetch);\n return this.call(() =>\n fetchFn(...args).then((res) => (res.ok ? res : Promise.reject(res)))\n );\n }\n}\n"],"mappings":";;;;;;;;AAIA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;AAkCD,SAAS,WAAW,GAA2B;AAC7C,KAAI,KAAK,QAAQ,OAAO,MAAM,SAAU,QAAO;AAC/C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,aAAa,WAAW,eAAe,IACvC,aAAa,WAAW,aAAa,CAErC,OAAM;AAGR,QAAK,OAAe,SAAS,eAC3B,OAAM;AAIR,QACE,aAAa,SAAS,eAAe,IACrC,aAAa,SAAS,eAAe,IACrC,aAAa,SAAS,kBAAkB,IACxC,aAAa,SAAS,eAAe,EACrC;KACA,MAAM,kCAAkB,IAAI,MAC1B,8GAA8G,eAC/G;AACD,qBAAgB,OAAO;AACvB,WAAM;;AAIR,QAAI,iBAAiB,WAAW;AAC9B,SAAI,gBAAgB,SAAS,MAAM,OAAO,CACxC,OAAM;AAER,SAAI,wBAAwB,MAAM,SAChC,OAAM,qBAAqB,MAAM,SAAS;;;GAMhD,SAAS,KAAK;GACd,WAAW;GACZ,CACF,EACH,EAAE,gBAAgB,MAAM,CACzB;;CAIH,gBACE,SACA,UACA,GAAG,MAC8B;AAGjC,MAAI,QAAQ,OACV,QAAO,QAAQ,KAAK,CAClB,KAAK,KAAW,UAAU,GAAG,KAAK,EAClC,IAAI,SAAgB,GAAG,WAAW;AAChC,WAAQ,QAAQ,iBAAiB,eAAe;AAC9C,2BAAO,IAAI,MAAM,aAAa,CAAC;KAC/B;IACF,CACH,CAAC;AAEJ,SAAO,KAAK,KAAW,UAAU,GAAG,KAAK;;CAG3C,MAAM,GAAG,MAA0D;EACjE,MAAM,UACJ,KAAK,eAAgBC,uCAAyB;AAChD,SAAO,KAAK,WACV,QAAQ,GAAG,KAAK,CAAC,MAAM,QAAS,IAAI,KAAK,MAAM,QAAQ,OAAO,IAAI,CAAE,CACrE"}
|
|
@@ -17,7 +17,7 @@ interface AsyncCallerParams {
|
|
|
17
17
|
*
|
|
18
18
|
* By default we expect the `fetch` is available in the global scope.
|
|
19
19
|
*/
|
|
20
|
-
fetch?: typeof fetch | ((...args: any[]) => any);
|
|
20
|
+
fetch?: typeof fetch | ((...args: any[]) => any);
|
|
21
21
|
}
|
|
22
22
|
interface AsyncCallerCallOptions {
|
|
23
23
|
signal?: AbortSignal;
|
|
@@ -42,9 +42,7 @@ declare class AsyncCaller {
|
|
|
42
42
|
private onFailedResponseHook?;
|
|
43
43
|
private customFetch?;
|
|
44
44
|
constructor(params: AsyncCallerParams);
|
|
45
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
45
|
call<A extends any[], T extends (...args: A) => Promise<any>>(callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
|
|
47
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
46
|
callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(options: AsyncCallerCallOptions, callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
|
|
49
47
|
fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch>;
|
|
50
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async_caller.d.cts","names":["ResponseCallback","Response","Promise","AsyncCallerParams","fetch","AsyncCallerCallOptions","AbortSignal","AsyncCaller","A","T","Parameters","ReturnType","Awaited"],"sources":["../../src/utils/async_caller.d.ts"],"sourcesContent":["type ResponseCallback = (response?: Response) => Promise<boolean>;\nexport interface AsyncCallerParams {\n /**\n * The maximum number of concurrent calls that can be made.\n * Defaults to `Infinity`, which means no limit.\n */\n maxConcurrency?: number;\n /**\n * The maximum number of retries that can be made for a single call,\n * with an exponential backoff between each attempt. Defaults to 6.\n */\n maxRetries?: number;\n onFailedResponseHook?: ResponseCallback;\n /**\n * Specify a custom fetch implementation.\n *\n * By default we expect the `fetch` is available in the global scope.\n */\n fetch?: typeof fetch | ((...args: any[]) => any)
|
|
1
|
+
{"version":3,"file":"async_caller.d.cts","names":["ResponseCallback","Response","Promise","AsyncCallerParams","fetch","AsyncCallerCallOptions","AbortSignal","AsyncCaller","A","T","Parameters","ReturnType","Awaited"],"sources":["../../src/utils/async_caller.d.ts"],"sourcesContent":["type ResponseCallback = (response?: Response) => Promise<boolean>;\nexport interface AsyncCallerParams {\n /**\n * The maximum number of concurrent calls that can be made.\n * Defaults to `Infinity`, which means no limit.\n */\n maxConcurrency?: number;\n /**\n * The maximum number of retries that can be made for a single call,\n * with an exponential backoff between each attempt. Defaults to 6.\n */\n maxRetries?: number;\n onFailedResponseHook?: ResponseCallback;\n /**\n * Specify a custom fetch implementation.\n *\n * By default we expect the `fetch` is available in the global scope.\n */\n fetch?: typeof fetch | ((...args: any[]) => any);\n}\nexport interface AsyncCallerCallOptions {\n signal?: AbortSignal;\n}\n/**\n * A class that can be used to make async calls with concurrency and retry logic.\n *\n * This is useful for making calls to any kind of \"expensive\" external resource,\n * be it because it's rate-limited, subject to network issues, etc.\n *\n * Concurrent calls are limited by the `maxConcurrency` parameter, which defaults\n * to `Infinity`. This means that by default, all calls will be made in parallel.\n *\n * Retries are limited by the `maxRetries` parameter, which defaults to 5. This\n * means that by default, each call will be retried up to 5 times, with an\n * exponential backoff between each attempt.\n */\nexport declare class AsyncCaller {\n protected maxConcurrency: AsyncCallerParams[\"maxConcurrency\"];\n protected maxRetries: AsyncCallerParams[\"maxRetries\"];\n private queue;\n private onFailedResponseHook?;\n private customFetch?;\n constructor(params: AsyncCallerParams);\n call<A extends any[], T extends (...args: A) => Promise<any>>(callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;\n callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(options: AsyncCallerCallOptions, callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;\n fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch>;\n}\nexport {};\n"],"mappings":";KAAKA,gBAAAA,eAA+BC,aAAaC;AAA5CF,UACYG,iBAAAA,CADI;EAAA;;;;EACJA,cAAAA,CAAAA,EAAAA,MAAiB;EAAA;;;;EAmBjBE,UAAAA,CAAAA,EAAAA,MAAAA;EAgBIE,oBAAW,CAAA,EAxBLP,gBAwBK;EAAA;;;;;OAOoBE,CAAAA,EAAAA,OAzBjCE,KAyBiCF,GAAAA,CAAAA,CAAAA,GAAAA,IAAAA,EAAAA,GAAAA,EAAAA,EAAAA,GAAAA,GAAAA,CAAAA;;AAA+CO,UAvBlFJ,sBAAAA,CAuBkFI;QAAXC,CAAAA,EAtB3EJ,WAsB2EI;;;;;;;;;;;;;;;AAEnDN,cAThBG,WAAAA,CASgBH;YAAlBM,cAAAA,EARWP,iBAQXO,CAAAA,gBAAAA,CAAAA;YAA6CN,UAAAA,EAPtCD,iBAOsCC,CAAAA,YAAAA,CAAAA;UAAlBO,KAAAA;EAAU,QAAA,oBAAA;;sBAHhCR;4CACsBK,MAAMN,wBAAwBO,YAAYC,WAAWD,KAAKP,QAAQU,QAAQD,WAAWF;uDAC1ED,MAAMN,uBAAuBG,kCAAkCI,YAAYC,WAAWD,KAAKP,QAAQU,QAAQD,WAAWF;iBAC5JC,kBAAkBN,SAASO,kBAAkBP"}
|
|
@@ -17,7 +17,7 @@ interface AsyncCallerParams {
|
|
|
17
17
|
*
|
|
18
18
|
* By default we expect the `fetch` is available in the global scope.
|
|
19
19
|
*/
|
|
20
|
-
fetch?: typeof fetch | ((...args: any[]) => any);
|
|
20
|
+
fetch?: typeof fetch | ((...args: any[]) => any);
|
|
21
21
|
}
|
|
22
22
|
interface AsyncCallerCallOptions {
|
|
23
23
|
signal?: AbortSignal;
|
|
@@ -42,9 +42,7 @@ declare class AsyncCaller {
|
|
|
42
42
|
private onFailedResponseHook?;
|
|
43
43
|
private customFetch?;
|
|
44
44
|
constructor(params: AsyncCallerParams);
|
|
45
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
45
|
call<A extends any[], T extends (...args: A) => Promise<any>>(callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
|
|
47
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
46
|
callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(options: AsyncCallerCallOptions, callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
|
|
49
47
|
fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch>;
|
|
50
48
|
}
|