@langchain/langgraph-sdk 1.9.2 → 1.9.3-rc.0
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/client/stream/index.cjs +103 -14
- package/dist/client/stream/index.cjs.map +1 -1
- package/dist/client/stream/index.d.cts +21 -1
- package/dist/client/stream/index.d.cts.map +1 -1
- package/dist/client/stream/index.d.ts +21 -1
- package/dist/client/stream/index.d.ts.map +1 -1
- package/dist/client/stream/index.js +103 -14
- package/dist/client/stream/index.js.map +1 -1
- package/dist/client/stream/transport.d.cts +12 -0
- package/dist/client/stream/transport.d.cts.map +1 -1
- package/dist/client/stream/transport.d.ts +12 -0
- package/dist/client/stream/transport.d.ts.map +1 -1
- package/dist/stream/controller.cjs +163 -13
- package/dist/stream/controller.cjs.map +1 -1
- package/dist/stream/controller.d.cts.map +1 -1
- package/dist/stream/controller.d.ts.map +1 -1
- package/dist/stream/controller.js +163 -13
- package/dist/stream/controller.js.map +1 -1
- package/dist/stream/discovery/subagents.cjs +31 -0
- package/dist/stream/discovery/subagents.cjs.map +1 -1
- package/dist/stream/discovery/subagents.d.cts.map +1 -1
- package/dist/stream/discovery/subagents.d.ts.map +1 -1
- package/dist/stream/discovery/subagents.js +31 -0
- package/dist/stream/discovery/subagents.js.map +1 -1
- package/dist/stream/projections/runtime.cjs +3 -2
- package/dist/stream/projections/runtime.cjs.map +1 -1
- package/dist/stream/projections/runtime.js +3 -2
- package/dist/stream/projections/runtime.js.map +1 -1
- package/dist/stream/root-message-projection.cjs +98 -53
- package/dist/stream/root-message-projection.cjs.map +1 -1
- package/dist/stream/root-message-projection.js +98 -53
- package/dist/stream/root-message-projection.js.map +1 -1
- package/dist/stream/submit-coordinator.cjs +30 -4
- package/dist/stream/submit-coordinator.cjs.map +1 -1
- package/dist/stream/submit-coordinator.js +30 -4
- package/dist/stream/submit-coordinator.js.map +1 -1
- package/dist/ui/manager.cjs +3 -2
- package/dist/ui/manager.cjs.map +1 -1
- package/dist/ui/manager.d.cts.map +1 -1
- package/dist/ui/manager.d.ts.map +1 -1
- package/dist/ui/manager.js +3 -2
- package/dist/ui/manager.js.map +1 -1
- package/package.json +2 -2
|
@@ -322,6 +322,7 @@ var ThreadStream = class {
|
|
|
322
322
|
#terminalPauseSeq;
|
|
323
323
|
#lifecycleSubId = null;
|
|
324
324
|
#lifecycleStartPromise;
|
|
325
|
+
#runStartReady = null;
|
|
325
326
|
#lifecycleWatcherHandle = null;
|
|
326
327
|
#lifecycleWatcherStartPromise;
|
|
327
328
|
#onEventListeners = /* @__PURE__ */ new Set();
|
|
@@ -378,11 +379,13 @@ var ThreadStream = class {
|
|
|
378
379
|
this.#fetchOption = options.fetch;
|
|
379
380
|
this.run = { start: async (params) => {
|
|
380
381
|
this.#prepareForNextRun();
|
|
381
|
-
this.#
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
382
|
+
return await this.#withRunStartGate(() => {
|
|
383
|
+
this.#ensureLifecycleTracking();
|
|
384
|
+
this.values;
|
|
385
|
+
return this.#send("run.start", {
|
|
386
|
+
...params,
|
|
387
|
+
assistant_id: this.assistantId
|
|
388
|
+
});
|
|
386
389
|
});
|
|
387
390
|
} };
|
|
388
391
|
this.agent = { getTree: async (params = {}) => await this.#send("agent.getTree", params) };
|
|
@@ -440,6 +443,36 @@ var ThreadStream = class {
|
|
|
440
443
|
})().catch(() => void 0);
|
|
441
444
|
}
|
|
442
445
|
/**
|
|
446
|
+
* Run `operation` (a `run.start` send) while holding the run-start
|
|
447
|
+
* gate. Sets `#runStartReady` before invoking `operation` so any
|
|
448
|
+
* subscription kicked off synchronously inside it (e.g. the lifecycle
|
|
449
|
+
* watcher and the values projection) sees the gate when it eventually
|
|
450
|
+
* reaches `#startLifecycleWatcherSse` / `#reconcileStream` /
|
|
451
|
+
* `#subscribeViaCommand` and awaits it. The gate resolves the moment
|
|
452
|
+
* `operation` settles, so server-side subscribes land immediately
|
|
453
|
+
* after the thread is committed.
|
|
454
|
+
*/
|
|
455
|
+
async #withRunStartGate(operation) {
|
|
456
|
+
let resolveGate;
|
|
457
|
+
let rejectGate;
|
|
458
|
+
const gate = new Promise((resolve, reject) => {
|
|
459
|
+
resolveGate = resolve;
|
|
460
|
+
rejectGate = reject;
|
|
461
|
+
});
|
|
462
|
+
this.#runStartReady = gate;
|
|
463
|
+
gate.catch(() => void 0);
|
|
464
|
+
try {
|
|
465
|
+
const result = await operation();
|
|
466
|
+
resolveGate();
|
|
467
|
+
return result;
|
|
468
|
+
} catch (err) {
|
|
469
|
+
rejectGate(err);
|
|
470
|
+
throw err;
|
|
471
|
+
} finally {
|
|
472
|
+
if (this.#runStartReady === gate) this.#runStartReady = null;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
443
476
|
* Reset interrupt state and resume all paused user subscriptions.
|
|
444
477
|
* Called before `run.start()` and `input.respond()` so that
|
|
445
478
|
* iterators on the same handle pick up the next run's events.
|
|
@@ -782,10 +815,12 @@ var ThreadStream = class {
|
|
|
782
815
|
*/
|
|
783
816
|
async submitRun(params) {
|
|
784
817
|
this.#prepareForNextRun();
|
|
785
|
-
this.#
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
818
|
+
return await this.#withRunStartGate(() => {
|
|
819
|
+
this.#startLifecycleWatcher();
|
|
820
|
+
return this.#send("run.start", {
|
|
821
|
+
...params,
|
|
822
|
+
assistant_id: this.assistantId
|
|
823
|
+
});
|
|
789
824
|
});
|
|
790
825
|
}
|
|
791
826
|
/**
|
|
@@ -851,7 +886,32 @@ var ThreadStream = class {
|
|
|
851
886
|
}
|
|
852
887
|
this.#lifecycleWatcherStartPromise = this.#startLifecycleWatcherWebSocket();
|
|
853
888
|
}
|
|
889
|
+
/**
|
|
890
|
+
* Public, idempotent entry point to start the wildcard lifecycle
|
|
891
|
+
* watcher.
|
|
892
|
+
*
|
|
893
|
+
* The watcher is normally started lazily by `submitRun` /
|
|
894
|
+
* `respondInput` because for fresh (self-created) threads the SSE
|
|
895
|
+
* stream would 404 if opened before the server has the thread row.
|
|
896
|
+
* Callers that already know the thread exists server-side
|
|
897
|
+
* (`StreamController.hydrate` of an existing thread) can use this
|
|
898
|
+
* to start the watcher up front. The watcher subscribes to wildcard
|
|
899
|
+
* lifecycle events across every namespace, so it sees arbitrarily-
|
|
900
|
+
* nested subagent lifecycle messages that the narrow root content
|
|
901
|
+
* pump (running at `depth: 1`) wouldn't reach — that's what makes
|
|
902
|
+
* subagent discovery work for historical thread loads.
|
|
903
|
+
*
|
|
904
|
+
* Idempotent — repeat calls reuse the in-flight start promise.
|
|
905
|
+
*/
|
|
906
|
+
startLifecycleWatcher() {
|
|
907
|
+
this.#startLifecycleWatcher();
|
|
908
|
+
}
|
|
854
909
|
async #startLifecycleWatcherSse() {
|
|
910
|
+
if (this.#runStartReady != null) try {
|
|
911
|
+
await this.#runStartReady;
|
|
912
|
+
} catch {
|
|
913
|
+
return;
|
|
914
|
+
}
|
|
855
915
|
const filter = { channels: ["lifecycle", "input"] };
|
|
856
916
|
let handle;
|
|
857
917
|
try {
|
|
@@ -1125,6 +1185,17 @@ var ThreadStream = class {
|
|
|
1125
1185
|
if (this.#rotationState === "rotating") return;
|
|
1126
1186
|
const desired = this.#computeUnionFilter();
|
|
1127
1187
|
if (desired == null) return;
|
|
1188
|
+
if (this.#runStartReady != null) {
|
|
1189
|
+
try {
|
|
1190
|
+
await this.#runStartReady;
|
|
1191
|
+
} catch (err) {
|
|
1192
|
+
const normalized = err instanceof Error ? err : /* @__PURE__ */ new Error("run.start failed");
|
|
1193
|
+
this.#rejectUncoveredPending(normalized);
|
|
1194
|
+
return;
|
|
1195
|
+
}
|
|
1196
|
+
if (this.#closed) return;
|
|
1197
|
+
if (this.#rotationState === "rotating") return;
|
|
1198
|
+
}
|
|
1128
1199
|
if (this.#sharedStreamFilter != null && filterEqual(desired, this.#sharedStreamFilter) && this.#pendingSubResolves.length === 0) {
|
|
1129
1200
|
this.#resolvePending();
|
|
1130
1201
|
return;
|
|
@@ -1230,10 +1301,11 @@ var ThreadStream = class {
|
|
|
1230
1301
|
* matching buffered events on subscribe via the same WebSocket stream.
|
|
1231
1302
|
*/
|
|
1232
1303
|
async #subscribeViaCommand(params, transform) {
|
|
1233
|
-
const
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1304
|
+
const placeholderId = `pending:${this.#nextCommandId}:${Math.random().toString(36).slice(2, 10)}`;
|
|
1305
|
+
let resolvedId = placeholderId;
|
|
1306
|
+
const handle = new SubscriptionHandle(placeholderId, params, async () => {
|
|
1307
|
+
this.#subscriptions.delete(resolvedId);
|
|
1308
|
+
if (!this.#closed && resolvedId !== placeholderId) await this.#send("subscription.unsubscribe", { subscription_id: resolvedId }).catch((err) => {
|
|
1237
1309
|
if (err instanceof require_error.ProtocolError && err.code === "no_such_subscription") return;
|
|
1238
1310
|
throw err;
|
|
1239
1311
|
});
|
|
@@ -1243,7 +1315,24 @@ var ThreadStream = class {
|
|
|
1243
1315
|
registeredAfterSeq: this.ordering.lastSeenSeq,
|
|
1244
1316
|
seenEventIds: /* @__PURE__ */ new Set()
|
|
1245
1317
|
});
|
|
1246
|
-
this.#subscriptions.set(
|
|
1318
|
+
this.#subscriptions.set(placeholderId, subscription);
|
|
1319
|
+
if (this.#runStartReady != null) try {
|
|
1320
|
+
await this.#runStartReady;
|
|
1321
|
+
} catch (err) {
|
|
1322
|
+
this.#subscriptions.delete(placeholderId);
|
|
1323
|
+
throw err;
|
|
1324
|
+
}
|
|
1325
|
+
let result;
|
|
1326
|
+
try {
|
|
1327
|
+
result = await this.#send("subscription.subscribe", params);
|
|
1328
|
+
} catch (err) {
|
|
1329
|
+
this.#subscriptions.delete(placeholderId);
|
|
1330
|
+
throw err;
|
|
1331
|
+
}
|
|
1332
|
+
this.#subscriptions.delete(placeholderId);
|
|
1333
|
+
resolvedId = result.subscription_id;
|
|
1334
|
+
handle.subscriptionId = resolvedId;
|
|
1335
|
+
this.#subscriptions.set(resolvedId, subscription);
|
|
1247
1336
|
return handle;
|
|
1248
1337
|
}
|
|
1249
1338
|
async #consumeEvents() {
|