@langchain/langgraph-api 1.2.2 → 1.2.3
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/experimental/embed/protocol.mjs +86 -15
- package/dist/protocol/service.d.mts +9 -1
- package/dist/protocol/service.mjs +65 -25
- package/package.json +6 -6
- package/dist/src/api/assistants.d.mts +0 -3
- package/dist/src/api/assistants.mjs +0 -194
- package/dist/src/api/meta.d.mts +0 -3
- package/dist/src/api/meta.mjs +0 -65
- package/dist/src/api/protocol.d.mts +0 -7
- package/dist/src/api/protocol.mjs +0 -157
- package/dist/src/api/runs.d.mts +0 -3
- package/dist/src/api/runs.mjs +0 -335
- package/dist/src/api/store.d.mts +0 -3
- package/dist/src/api/store.mjs +0 -111
- package/dist/src/api/threads.d.mts +0 -3
- package/dist/src/api/threads.mjs +0 -143
- package/dist/src/graph/load.utils.d.mts +0 -22
- package/dist/src/graph/load.utils.mjs +0 -59
- package/dist/src/protocol/service.d.mts +0 -101
- package/dist/src/protocol/service.mjs +0 -568
- package/dist/src/protocol/session/event-normalizers.d.mts +0 -52
- package/dist/src/protocol/session/index.d.mts +0 -261
- package/dist/src/protocol/session/index.mjs +0 -826
- package/dist/src/protocol/session/namespace.d.mts +0 -47
- package/dist/src/protocol/session/namespace.mjs +0 -62
- package/dist/src/protocol/types.d.mts +0 -121
- package/dist/src/protocol/types.mjs +0 -1
- package/dist/src/schemas.d.mts +0 -1552
- package/dist/src/semver/index.d.mts +0 -15
- package/dist/src/semver/index.mjs +0 -46
- package/dist/src/semver/satisfiesPeerRange.d.mts +0 -1
- package/dist/src/semver/satisfiesPeerRange.mjs +0 -19
- package/dist/src/state.d.mts +0 -3
- package/dist/src/state.mjs +0 -30
- package/dist/src/storage/context.d.mts +0 -3
- package/dist/src/storage/context.mjs +0 -11
- package/dist/src/storage/ops.mjs +0 -1281
- package/dist/src/stream.d.mts +0 -64
- package/dist/src/stream.mjs +0 -427
- package/dist/src/utils/hono.d.mts +0 -5
- package/dist/src/utils/hono.mjs +0 -24
- package/dist/src/utils/runnableConfig.d.mts +0 -3
- package/dist/src/utils/runnableConfig.mjs +0 -45
- package/dist/src/webhook.d.mts +0 -11
- package/dist/src/webhook.mjs +0 -30
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import type { AuthContext } from "../../auth/index.mjs";
|
|
2
|
-
import type { Run } from "../../storage/types.mjs";
|
|
3
|
-
import type { ProtocolCommand, ProtocolError, ProtocolResponseMeta, ProtocolSuccess, SourceStreamEvent } from "../types.mjs";
|
|
4
|
-
/**
|
|
5
|
-
* Normalizes one LangGraph run into protocol events and manages per-run
|
|
6
|
-
* subscriptions, buffering, and replay.
|
|
7
|
-
*
|
|
8
|
-
* This class is transport-agnostic: callers provide a `send()` function and an
|
|
9
|
-
* optional source stream, and the session handles command processing plus event
|
|
10
|
-
* fan-out for both direct run-scoped sockets and the shared `v2` session
|
|
11
|
-
* service.
|
|
12
|
-
*/
|
|
13
|
-
export declare class RunProtocolSession {
|
|
14
|
-
private readonly initialRun;
|
|
15
|
-
private readonly getRun;
|
|
16
|
-
private readonly getThreadState?;
|
|
17
|
-
private readonly send;
|
|
18
|
-
private readonly source?;
|
|
19
|
-
private readonly subscriptions;
|
|
20
|
-
private readonly namespaces;
|
|
21
|
-
private readonly abortController;
|
|
22
|
-
private readonly buffer;
|
|
23
|
-
private sendQueue;
|
|
24
|
-
private sourceTask?;
|
|
25
|
-
private nextSeq;
|
|
26
|
-
private rootGraphName;
|
|
27
|
-
private terminalLifecycleEmitted;
|
|
28
|
-
private readonly pendingInterruptIds;
|
|
29
|
-
/**
|
|
30
|
-
* When true, every event is sent unconditionally via {@link sendJson}
|
|
31
|
-
* regardless of subscription state. Used for SSE transports where
|
|
32
|
-
* per-connection filtering is handled by the outer service layer.
|
|
33
|
-
*/
|
|
34
|
-
private readonly passthrough;
|
|
35
|
-
/**
|
|
36
|
-
* Creates a run-scoped protocol session.
|
|
37
|
-
*
|
|
38
|
-
* @param options - Session construction options and transport bindings.
|
|
39
|
-
*/
|
|
40
|
-
constructor(options: {
|
|
41
|
-
runId: string;
|
|
42
|
-
threadId?: string;
|
|
43
|
-
auth?: AuthContext;
|
|
44
|
-
initialRun: Run;
|
|
45
|
-
getRun: () => Promise<Run | null>;
|
|
46
|
-
getThreadState?: () => Promise<{
|
|
47
|
-
tasks?: Array<{
|
|
48
|
-
interrupts?: unknown[];
|
|
49
|
-
}>;
|
|
50
|
-
} | null>;
|
|
51
|
-
send: (payload: string) => Promise<void> | void;
|
|
52
|
-
source?: AsyncIterable<SourceStreamEvent>;
|
|
53
|
-
startSeq?: number;
|
|
54
|
-
passthrough?: boolean;
|
|
55
|
-
});
|
|
56
|
-
/**
|
|
57
|
-
* Starts consuming the bound run source and seeds the root lifecycle state.
|
|
58
|
-
*/
|
|
59
|
-
start(): Promise<void>;
|
|
60
|
-
/**
|
|
61
|
-
* Stops consuming the run source and waits for queued writes to settle.
|
|
62
|
-
*/
|
|
63
|
-
close(): Promise<void>;
|
|
64
|
-
/**
|
|
65
|
-
* Parses and handles a raw JSON command coming from the transport.
|
|
66
|
-
*
|
|
67
|
-
* @param rawPayload - Raw JSON protocol command payload.
|
|
68
|
-
*/
|
|
69
|
-
handleCommand(rawPayload: string): Promise<void>;
|
|
70
|
-
/**
|
|
71
|
-
* Handles a structured protocol command and returns a typed response.
|
|
72
|
-
*
|
|
73
|
-
* When `options.deliverResponseInline` is `true`, a
|
|
74
|
-
* `subscription.subscribe` resolves to `null` — the success response
|
|
75
|
-
* has already been written through the shared transport queue ahead
|
|
76
|
-
* of the replay events (see `handleSubscribeForResponse` for
|
|
77
|
-
* rationale). Callers that forward the response onto a separate wire
|
|
78
|
-
* (the WS `onMessage` handler) must treat `null` as
|
|
79
|
-
* "nothing more to send".
|
|
80
|
-
*
|
|
81
|
-
* @param command - Parsed protocol command.
|
|
82
|
-
* @param meta - Optional response metadata from the outer transport.
|
|
83
|
-
* @param options - Server-internal delivery flags.
|
|
84
|
-
* @returns A typed success/error response, or `null` when the
|
|
85
|
-
* response was already sent inline.
|
|
86
|
-
*/
|
|
87
|
-
handleProtocolCommand(command: ProtocolCommand, meta?: ProtocolResponseMeta, options?: {
|
|
88
|
-
deliverResponseInline?: boolean;
|
|
89
|
-
}): Promise<ProtocolSuccess | ProtocolError | null>;
|
|
90
|
-
/**
|
|
91
|
-
* Injects a raw run stream event into the protocol session.
|
|
92
|
-
*
|
|
93
|
-
* @param event - Raw source stream event to normalize.
|
|
94
|
-
*/
|
|
95
|
-
ingestSourceEvent(event: SourceStreamEvent): Promise<void>;
|
|
96
|
-
/**
|
|
97
|
-
* Consumes the bound source stream until completion or cancellation.
|
|
98
|
-
*/
|
|
99
|
-
private consumeSource;
|
|
100
|
-
/**
|
|
101
|
-
* Emits the terminal root lifecycle event once the underlying run
|
|
102
|
-
* finishes. Child namespaces are cascaded upstream by core's
|
|
103
|
-
* `LifecycleTransformer` — the session only owns the root because
|
|
104
|
-
* terminal status depends on API-only signals (persisted run
|
|
105
|
-
* status, thread-level pending interrupts).
|
|
106
|
-
*/
|
|
107
|
-
private emitTerminalLifecycle;
|
|
108
|
-
/**
|
|
109
|
-
* Normalizes a single raw source event into protocol events.
|
|
110
|
-
*
|
|
111
|
-
* @param event - Raw source stream event.
|
|
112
|
-
*/
|
|
113
|
-
private handleSourceEvent;
|
|
114
|
-
/**
|
|
115
|
-
* Forwards events already converted by core's
|
|
116
|
-
* `streamEvents(..., { version: "v3" })` pipeline.
|
|
117
|
-
*
|
|
118
|
-
* Only events marked by `streamStateV2` after `convertToProtocolEvent` and
|
|
119
|
-
* the built-in stream transformers have run take this path.
|
|
120
|
-
*/
|
|
121
|
-
private forwardNormalizedSourceEvent;
|
|
122
|
-
/**
|
|
123
|
-
* Ensures the session is tracking each prefix of `namespace` so
|
|
124
|
-
* agent-tree queries and message routing can resolve it.
|
|
125
|
-
*
|
|
126
|
-
* Does **not** emit any wire events: authoritative
|
|
127
|
-
* `lifecycle.started` events are produced upstream by core's
|
|
128
|
-
* `LifecycleTransformer` and observed by the session's lifecycle
|
|
129
|
-
* handler in {@link RunProtocolSession.handleSourceEvent}. This
|
|
130
|
-
* method is a defensive fallback for event paths that reference a namespace
|
|
131
|
-
* before the corresponding `lifecycle` event has been ingested.
|
|
132
|
-
*
|
|
133
|
-
* @param namespace - Namespace whose prefixes should be tracked.
|
|
134
|
-
*/
|
|
135
|
-
private ensureNamespaces;
|
|
136
|
-
/**
|
|
137
|
-
* Updates cached namespace metadata used for lifecycle and tree responses.
|
|
138
|
-
*
|
|
139
|
-
* @param namespace - Namespace to update.
|
|
140
|
-
* @param status - New lifecycle status for the namespace.
|
|
141
|
-
* @param options - Optional graph name override.
|
|
142
|
-
*/
|
|
143
|
-
private setNamespaceInfo;
|
|
144
|
-
private createEvent;
|
|
145
|
-
/**
|
|
146
|
-
* Buffers an event and delivers it to all matching subscriptions.
|
|
147
|
-
* Applies the active flow-control strategy when the buffer is at capacity.
|
|
148
|
-
*
|
|
149
|
-
* @param event - Protocol event to buffer and fan out.
|
|
150
|
-
*/
|
|
151
|
-
private pushEvent;
|
|
152
|
-
/**
|
|
153
|
-
* Checks whether an event should be delivered to a subscription.
|
|
154
|
-
*
|
|
155
|
-
* @param subscription - Subscription to test.
|
|
156
|
-
* @param event - Candidate protocol event.
|
|
157
|
-
* @returns Whether the event matches channel and namespace filters.
|
|
158
|
-
*/
|
|
159
|
-
private matchesSubscription;
|
|
160
|
-
private hasStatePayload;
|
|
161
|
-
private emitInputRequestedEvents;
|
|
162
|
-
/**
|
|
163
|
-
* Builds the agent tree view rooted at a namespace.
|
|
164
|
-
*
|
|
165
|
-
* @param namespace - Namespace to build from.
|
|
166
|
-
* @returns A recursively assembled agent tree node.
|
|
167
|
-
*/
|
|
168
|
-
private buildTree;
|
|
169
|
-
/**
|
|
170
|
-
* Handles a subscribe command and writes the response to the transport.
|
|
171
|
-
*
|
|
172
|
-
* @param command - Subscribe command to process.
|
|
173
|
-
*/
|
|
174
|
-
private handleSubscribe;
|
|
175
|
-
/**
|
|
176
|
-
* Handles a subscribe command and (optionally) writes the
|
|
177
|
-
* success/error response inline through the shared transport
|
|
178
|
-
* queue, signalling to callers (via a `null` return) that no
|
|
179
|
-
* further send is required.
|
|
180
|
-
*
|
|
181
|
-
* When `options.deliverResponseInline` is `true`, the success
|
|
182
|
-
* response is emitted via `sendJson` BEFORE the replay events and
|
|
183
|
-
* the method returns `null`. This ordering is critical on
|
|
184
|
-
* single-channel transports like WebSocket where the command
|
|
185
|
-
* response and event frames share one ordered wire: if events
|
|
186
|
-
* preceded the response, the client would receive events whose
|
|
187
|
-
* `subscription_id` it hasn't yet registered (the awaiter in
|
|
188
|
-
* `#subscribeViaCommand` only adds the subscription to its local
|
|
189
|
-
* map after the response resolves) and drop them in the per-sub
|
|
190
|
-
* fan-out.
|
|
191
|
-
*
|
|
192
|
-
* When `deliverResponseInline` is absent/`false` (the default, used
|
|
193
|
-
* by HTTP `/commands`), the response is returned so the caller can
|
|
194
|
-
* place it in the HTTP response body, matching the prior behaviour.
|
|
195
|
-
* Input-validation errors always return normally regardless of the
|
|
196
|
-
* flag so they surface consistently in both modes.
|
|
197
|
-
*
|
|
198
|
-
* @param command - Subscribe command to process.
|
|
199
|
-
* @param meta - Optional response metadata from the outer transport.
|
|
200
|
-
* @param options - Server-internal delivery flags.
|
|
201
|
-
* @returns `null` when the response was sent inline; a typed
|
|
202
|
-
* success/error response otherwise.
|
|
203
|
-
*/
|
|
204
|
-
private handleSubscribeForResponse;
|
|
205
|
-
/**
|
|
206
|
-
* Handles an unsubscribe command and writes the response to the transport.
|
|
207
|
-
*
|
|
208
|
-
* @param command - Unsubscribe command to process.
|
|
209
|
-
*/
|
|
210
|
-
private handleUnsubscribe;
|
|
211
|
-
/**
|
|
212
|
-
* Handles an unsubscribe command and returns a typed response.
|
|
213
|
-
*
|
|
214
|
-
* @param command - Unsubscribe command to process.
|
|
215
|
-
* @param meta - Optional response metadata from the outer transport.
|
|
216
|
-
* @returns A typed success or error response.
|
|
217
|
-
*/
|
|
218
|
-
private handleUnsubscribeForResponse;
|
|
219
|
-
/**
|
|
220
|
-
* Sends a success response over the bound transport.
|
|
221
|
-
*
|
|
222
|
-
* @param id - Command identifier being acknowledged.
|
|
223
|
-
* @param result - Typed success payload.
|
|
224
|
-
*/
|
|
225
|
-
private sendSuccess;
|
|
226
|
-
/**
|
|
227
|
-
* Sends an error response over the bound transport.
|
|
228
|
-
*
|
|
229
|
-
* @param id - Command identifier, when available.
|
|
230
|
-
* @param error - Protocol error code.
|
|
231
|
-
* @param message - Human-readable error message.
|
|
232
|
-
* @param stacktrace - Optional stack trace for debugging.
|
|
233
|
-
*/
|
|
234
|
-
private sendError;
|
|
235
|
-
/**
|
|
236
|
-
* Serializes and writes a protocol payload using the session transport queue.
|
|
237
|
-
*
|
|
238
|
-
* @param message - Protocol message to send.
|
|
239
|
-
*/
|
|
240
|
-
private sendJson;
|
|
241
|
-
/**
|
|
242
|
-
* Creates a typed success response object.
|
|
243
|
-
*
|
|
244
|
-
* @param id - Command identifier being acknowledged.
|
|
245
|
-
* @param result - Typed success payload.
|
|
246
|
-
* @param meta - Optional response metadata from the outer transport.
|
|
247
|
-
* @returns A typed protocol success response.
|
|
248
|
-
*/
|
|
249
|
-
private success;
|
|
250
|
-
/**
|
|
251
|
-
* Creates a typed error response object.
|
|
252
|
-
*
|
|
253
|
-
* @param id - Command identifier, when available.
|
|
254
|
-
* @param error - Protocol error code.
|
|
255
|
-
* @param message - Human-readable error message.
|
|
256
|
-
* @param meta - Optional response metadata from the outer transport.
|
|
257
|
-
* @param stacktrace - Optional stack trace for debugging.
|
|
258
|
-
* @returns A typed protocol error response.
|
|
259
|
-
*/
|
|
260
|
-
private error;
|
|
261
|
-
}
|