@langchain/langgraph-sdk 1.12.5 → 1.12.7
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/messages.cjs +23 -2
- package/dist/client/stream/messages.cjs.map +1 -1
- package/dist/client/stream/messages.d.cts +6 -1
- package/dist/client/stream/messages.d.cts.map +1 -1
- package/dist/client/stream/messages.d.ts +6 -1
- package/dist/client/stream/messages.d.ts.map +1 -1
- package/dist/client/stream/messages.js +23 -2
- package/dist/client/stream/messages.js.map +1 -1
- package/dist/stream/controller.cjs +100 -4
- 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 +100 -4
- package/dist/stream/controller.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.cts","names":[],"sources":["../../src/stream/controller.ts"],"mappings":";;;;;;;;;;;;;;AA6KA;;cAAa,kBAAA,WAA6B,OAAA;;
|
|
1
|
+
{"version":3,"file":"controller.d.cts","names":[],"sources":["../../src/stream/controller.ts"],"mappings":";;;;;;;;;;;;;;AA6KA;;cAAa,kBAAA,WAA6B,OAAA;;AAgD1C;;;;;;;;;;;;cAAa,gBAAA,4BACgB,MAAA,8EAEO,MAAA;EAAA;WAEzB,SAAA,EAAW,WAAA,CAAY,YAAA,CAAa,SAAA,EAAW,aAAA;EAAA,SAC/C,aAAA,EAAe,WAAA,CAAY,WAAA;EAAA,SAC3B,aAAA,EAAe,WAAA,CAAY,WAAA;EAAA,SAC3B,mBAAA,EAAqB,WAAA,CAAY,iBAAA;EAAA,SACjC,oBAAA,EAAsB,WAAA,CAAY,kBAAA;EAAA,SAClC,UAAA,EAAY,WAAA,CAAY,uBAAA,CAAwB,SAAA;EAAA,SAChD,QAAA,EAAU,eAAA;EAkM0B;;;;;EAA7C,WAAA,CAAY,OAAA,EAAS,uBAAA,CAAwB,SAAA;EAo2BF;;;;;;;EAAA,IA3tBvC,gBAAA,CAAA,GAAoB,OAAA;EA44BS;;;;;;;;EAn1B3B,OAAA,CAAQ,QAAA,mBAA2B,OAAA;EAykCpB;;;;;;;;;;;;;;EA7qBf,wBAAA,CAAyB,UAAA,WAAqB,OAAA;EAryB5B;;;;;;;;EAyiClB,MAAA,CACJ,KAAA,WACA,OAAA,GAAU,mBAAA,CAAoB,SAAA,EAAW,gBAAA,IACxC,OAAA;EAziC4B;;;;;;EAmjCzB,IAAA,CAAK,OAAA,GAAU,iBAAA,GAAoB,OAAA;EAjjCtB;;;;EA6kCb,UAAA,CAAA,GAAc,OAAA;EAlwBhB;;;;;;;;;;;EAq0BE,YAAA,CAAa,EAAA,WAAa,OAAA;EA1GW;;;;EAkHrC,UAAA,CAAA,GAAc,OAAA;EAvGT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoKL,OAAA,CACJ,QAAA,WACA,OAAA,GAAU,oBAAA,CAAqB,gBAAA,IAC9B,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmHG,UAAA,CACJ,aAAA,EAAe,MAAA,mBACf,OAAA,GAAU,uBAAA,CAAwB,gBAAA,IACjC,OAAA;;;;EA8DG,OAAA,CAAA,GAAW,OAAA;;;;;;;;;;;;;;;;EAyBjB,QAAA,CAAA;;;;;;EA4BA,SAAA,CAAA,GAAa,YAAA;;;;;;;;EAWb,eAAA,CACE,QAAA,GAAW,MAAA,EAAQ,YAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","names":[],"sources":["../../src/stream/controller.ts"],"mappings":";;;;;;;;;;;;;;;;cA6Ka,kBAAA,WAA6B,OAAA;;;;
|
|
1
|
+
{"version":3,"file":"controller.d.ts","names":[],"sources":["../../src/stream/controller.ts"],"mappings":";;;;;;;;;;;;;;;;cA6Ka,kBAAA,WAA6B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AA,CAAwB,gBAAA,IACjC,OAAA;;;;EA8DG,OAAA,CAAA,GAAW,OAAA;;;;;;;;;;;;;;;;EAyBjB,QAAA,CAAA;;;;;;EA4BA,SAAA,CAAA,GAAa,YAAA;;;;;;;;EAWb,eAAA,CACE,QAAA,GAAW,MAAA,EAAQ,YAAA;AAAA"}
|
|
@@ -185,6 +185,21 @@ var StreamController = class {
|
|
|
185
185
|
* from the newly-started run and must be accepted.
|
|
186
186
|
*/
|
|
187
187
|
#interruptReplayThroughSeq;
|
|
188
|
+
/**
|
|
189
|
+
* Command whose barrier is still to be found on the thread stream. The
|
|
190
|
+
* agent server answers HTTP commands from a fresh per-request manager,
|
|
191
|
+
* so `applied_through_seq` is 0 while the stream replays the whole
|
|
192
|
+
* history with positive seqs. The barrier is then the event before the
|
|
193
|
+
* `running` event of the run the command started: `run.start` names that
|
|
194
|
+
* run, and a resume starts the first root run after the answered
|
|
195
|
+
* interrupts were last requested. Unknown interrupts stay buffered until
|
|
196
|
+
* it is found.
|
|
197
|
+
*/
|
|
198
|
+
#awaitingRunBoundary;
|
|
199
|
+
/** Seq of each root run's `running` event, keyed by run id. */
|
|
200
|
+
#rootRunStartSeqs = /* @__PURE__ */ new Map();
|
|
201
|
+
/** Highest seq at which each interrupt was requested. */
|
|
202
|
+
#interruptRequestSeqs = /* @__PURE__ */ new Map();
|
|
188
203
|
/** Unknown inputs waiting to be classified as live or replayed history. */
|
|
189
204
|
#pendingHydrationInterruptEvents = [];
|
|
190
205
|
#settleParkedInterruptsPromise;
|
|
@@ -350,6 +365,7 @@ var StreamController = class {
|
|
|
350
365
|
awaitResumedRunTerminal: (signal) => this.#awaitResumedRunTerminal(signal),
|
|
351
366
|
onSubmitStart: () => {
|
|
352
367
|
this.#submitGeneration += 1;
|
|
368
|
+
this.#awaitingRunBoundary = void 0;
|
|
353
369
|
this.#interruptCommandPending = this.#hydratedActiveInterruptIds != null;
|
|
354
370
|
this.#pendingInterruptEvents = this.#pendingHydrationInterruptEvents;
|
|
355
371
|
this.#pendingHydrationInterruptEvents = [];
|
|
@@ -361,11 +377,12 @@ var StreamController = class {
|
|
|
361
377
|
for (const release of [...this.#heldLifecycleReleases]) release();
|
|
362
378
|
},
|
|
363
379
|
onRunCreated: (runId) => {
|
|
364
|
-
this.#advanceInterruptReplayBarrier();
|
|
380
|
+
this.#advanceInterruptReplayBarrier({ runId });
|
|
365
381
|
this.#notifyCreated(runId);
|
|
366
382
|
},
|
|
367
383
|
onRunCompleted: (reason, runId) => this.#notifyCompleted(reason, runId),
|
|
368
384
|
onRunEnd: () => {
|
|
385
|
+
this.#abandonRunBoundary();
|
|
369
386
|
this.#interruptCommandPending = false;
|
|
370
387
|
this.#markLocalRunEnd();
|
|
371
388
|
},
|
|
@@ -1099,7 +1116,7 @@ var StreamController = class {
|
|
|
1099
1116
|
config: options?.config,
|
|
1100
1117
|
metadata: options?.metadata
|
|
1101
1118
|
});
|
|
1102
|
-
this.#advanceInterruptReplayBarrier();
|
|
1119
|
+
this.#advanceInterruptReplayBarrier({ answeredInterruptIds: [resolved.interruptId] });
|
|
1103
1120
|
this.#markInterruptResolvedInRootStore(resolved.interruptId);
|
|
1104
1121
|
}, prepared?.handle);
|
|
1105
1122
|
} catch (error) {
|
|
@@ -1170,7 +1187,7 @@ var StreamController = class {
|
|
|
1170
1187
|
config: options?.config,
|
|
1171
1188
|
metadata: options?.metadata
|
|
1172
1189
|
});
|
|
1173
|
-
this.#advanceInterruptReplayBarrier();
|
|
1190
|
+
this.#advanceInterruptReplayBarrier({ answeredInterruptIds: responses.map((r) => r.interrupt_id) });
|
|
1174
1191
|
for (const { interrupt_id: interruptId } of responses) this.#markInterruptResolvedInRootStore(interruptId);
|
|
1175
1192
|
}, prepared?.handle);
|
|
1176
1193
|
} catch (error) {
|
|
@@ -1390,6 +1407,9 @@ var StreamController = class {
|
|
|
1390
1407
|
this.#hydratedActiveInterruptIds = null;
|
|
1391
1408
|
this.#hydratedCheckpointTime = void 0;
|
|
1392
1409
|
this.#interruptReplayThroughSeq = void 0;
|
|
1410
|
+
this.#awaitingRunBoundary = void 0;
|
|
1411
|
+
this.#rootRunStartSeqs.clear();
|
|
1412
|
+
this.#interruptRequestSeqs.clear();
|
|
1393
1413
|
this.#pendingHydrationInterruptEvents = [];
|
|
1394
1414
|
this.#discardPendingInterruptEvents();
|
|
1395
1415
|
this.queueStore.setState(() => EMPTY_QUEUE);
|
|
@@ -1606,10 +1626,70 @@ var StreamController = class {
|
|
|
1606
1626
|
* consumer. `ThreadStream.interrupts` is updated in parallel for
|
|
1607
1627
|
* resume targeting.
|
|
1608
1628
|
*/
|
|
1629
|
+
this.#observeRunBoundary(event);
|
|
1609
1630
|
this.#recordInterrupt(event);
|
|
1610
1631
|
this.#settleParkedInterruptsOnTerminal(event);
|
|
1611
1632
|
}
|
|
1612
1633
|
/**
|
|
1634
|
+
* Remember where each root run starts and where each interrupt was last
|
|
1635
|
+
* requested, then try to place a pending command barrier. Both the
|
|
1636
|
+
* content pump and the lifecycle watcher replay the same tape with the
|
|
1637
|
+
* same seqs, so recording either copy is enough.
|
|
1638
|
+
*/
|
|
1639
|
+
#observeRunBoundary(event) {
|
|
1640
|
+
const { seq } = event;
|
|
1641
|
+
if (typeof seq !== "number") return;
|
|
1642
|
+
if (event.method === "input.requested") {
|
|
1643
|
+
const id = event.params.data?.interrupt_id;
|
|
1644
|
+
if (typeof id !== "string") return;
|
|
1645
|
+
if (seq <= (this.#interruptRequestSeqs.get(id) ?? -1)) return;
|
|
1646
|
+
this.#interruptRequestSeqs.set(id, seq);
|
|
1647
|
+
} else if (event.method === "lifecycle" && isRootNamespace(event.params.namespace) && event.params.data?.event === "running") {
|
|
1648
|
+
const runId = synthesizedEventRunId(event.event_id);
|
|
1649
|
+
if (runId == null || this.#rootRunStartSeqs.has(runId)) return;
|
|
1650
|
+
this.#rootRunStartSeqs.set(runId, seq);
|
|
1651
|
+
} else return;
|
|
1652
|
+
this.#resolveRunBoundary();
|
|
1653
|
+
}
|
|
1654
|
+
/**
|
|
1655
|
+
* Place the barrier of a command that reported `applied_through_seq: 0`
|
|
1656
|
+
* once its run's `running` event has been seen, then classify the
|
|
1657
|
+
* interrupts buffered while it was unknown.
|
|
1658
|
+
*/
|
|
1659
|
+
#resolveRunBoundary() {
|
|
1660
|
+
const command = this.#awaitingRunBoundary;
|
|
1661
|
+
if (command == null) return;
|
|
1662
|
+
let runStartSeq;
|
|
1663
|
+
if ("runId" in command) runStartSeq = this.#rootRunStartSeqs.get(command.runId);
|
|
1664
|
+
else {
|
|
1665
|
+
let lastRequested = -1;
|
|
1666
|
+
for (const id of command.answeredInterruptIds) {
|
|
1667
|
+
const seq = this.#interruptRequestSeqs.get(id);
|
|
1668
|
+
if (seq == null) return;
|
|
1669
|
+
lastRequested = Math.max(lastRequested, seq);
|
|
1670
|
+
}
|
|
1671
|
+
for (const seq of this.#rootRunStartSeqs.values()) if (seq > lastRequested && (runStartSeq == null || seq < runStartSeq)) runStartSeq = seq;
|
|
1672
|
+
}
|
|
1673
|
+
if (runStartSeq == null) return;
|
|
1674
|
+
this.#awaitingRunBoundary = void 0;
|
|
1675
|
+
this.#interruptReplayThroughSeq = runStartSeq - 1;
|
|
1676
|
+
this.#interruptCommandPending = false;
|
|
1677
|
+
this.#flushPendingInterruptEvents();
|
|
1678
|
+
}
|
|
1679
|
+
/**
|
|
1680
|
+
* Give up on a barrier whose run never showed up on the stream: a run
|
|
1681
|
+
* cancelled before it started, or a resume whose answered interrupts
|
|
1682
|
+
* were trimmed from the tape. Stop buffering and let the parked
|
|
1683
|
+
* interrupt state check decide what was held.
|
|
1684
|
+
*/
|
|
1685
|
+
#abandonRunBoundary() {
|
|
1686
|
+
if (this.#awaitingRunBoundary == null) return;
|
|
1687
|
+
this.#awaitingRunBoundary = void 0;
|
|
1688
|
+
this.#interruptCommandPending = false;
|
|
1689
|
+
this.#flushPendingInterruptEvents();
|
|
1690
|
+
this.#settleParkedInterrupts();
|
|
1691
|
+
}
|
|
1692
|
+
/**
|
|
1613
1693
|
* Process one root-pump event and update all root projections.
|
|
1614
1694
|
*
|
|
1615
1695
|
* @param event - Event yielded by the root subscription.
|
|
@@ -1901,24 +1981,38 @@ var StreamController = class {
|
|
|
1901
1981
|
* Convert the hydrate-time allowlist into a replay barrier after a command
|
|
1902
1982
|
* is accepted. Built-in transports update `lastAppliedThroughSeq` from the
|
|
1903
1983
|
* command response before resolving `submitRun` / `respondInput`.
|
|
1984
|
+
*
|
|
1985
|
+
* @param command - The run the command started, used to find the barrier
|
|
1986
|
+
* on the thread stream when the response reports
|
|
1987
|
+
* `applied_through_seq: 0`.
|
|
1904
1988
|
*/
|
|
1905
|
-
#advanceInterruptReplayBarrier() {
|
|
1989
|
+
#advanceInterruptReplayBarrier(command) {
|
|
1906
1990
|
if (this.#hydratedActiveInterruptIds == null) {
|
|
1907
1991
|
this.#discardPendingInterruptEvents();
|
|
1908
1992
|
return;
|
|
1909
1993
|
}
|
|
1910
1994
|
const throughSeq = this.#thread?.ordering?.lastAppliedThroughSeq;
|
|
1995
|
+
if (throughSeq === 0 && command != null) {
|
|
1996
|
+
this.#awaitingRunBoundary = command;
|
|
1997
|
+
this.#resolveRunBoundary();
|
|
1998
|
+
return;
|
|
1999
|
+
}
|
|
1911
2000
|
if (typeof throughSeq === "number") this.#interruptReplayThroughSeq = throughSeq;
|
|
1912
2001
|
else {
|
|
1913
2002
|
this.#hydratedActiveInterruptIds = null;
|
|
1914
2003
|
this.#interruptReplayThroughSeq = void 0;
|
|
1915
2004
|
}
|
|
1916
2005
|
this.#interruptCommandPending = false;
|
|
2006
|
+
this.#flushPendingInterruptEvents();
|
|
2007
|
+
}
|
|
2008
|
+
/** Classify the interrupts buffered while a command was in flight. */
|
|
2009
|
+
#flushPendingInterruptEvents() {
|
|
1917
2010
|
const pendingEvents = this.#pendingInterruptEvents;
|
|
1918
2011
|
this.#pendingInterruptEvents = [];
|
|
1919
2012
|
for (const event of pendingEvents) this.#recordInterrupt(event);
|
|
1920
2013
|
}
|
|
1921
2014
|
#discardPendingInterruptEvents() {
|
|
2015
|
+
this.#awaitingRunBoundary = void 0;
|
|
1922
2016
|
this.#interruptCommandPending = false;
|
|
1923
2017
|
this.#pendingInterruptEvents = [];
|
|
1924
2018
|
}
|
|
@@ -2068,7 +2162,9 @@ var StreamController = class {
|
|
|
2068
2162
|
* `stream.interrupts` empty while the checkpoint still has siblings.
|
|
2069
2163
|
*/
|
|
2070
2164
|
async #awaitResumedRunTerminal(signal) {
|
|
2165
|
+
const generation = this.#submitGeneration;
|
|
2071
2166
|
const terminal = await this.#awaitRootTerminal(signal, { skipInterruptedUntilRunning: true });
|
|
2167
|
+
if (this.#submitGeneration === generation) this.#abandonRunBoundary();
|
|
2072
2168
|
if (!signal.aborted && !this.#disposed && (terminal.event === "interrupted" || terminal.event === "completed")) await this.#reconcilePendingInterruptsFromServer();
|
|
2073
2169
|
return terminal;
|
|
2074
2170
|
}
|