@langchain/langgraph-sdk 0.1.9 → 0.1.10

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @langchain/langgraph-sdk
2
2
 
3
+ ## 0.1.10
4
+
5
+ ### Patch Changes
6
+
7
+ - 47cdce7: Fix stale values being received by optimistic values callback in `stream.submit(...)`
8
+
3
9
  ## 0.1.9
4
10
 
5
11
  ### Patch Changes
@@ -250,20 +250,29 @@ function useStreamLGP(options) {
250
250
  setBranch(checkpointId != null
251
251
  ? branchContext.branchByCheckpoint[checkpointId]?.branch ?? ""
252
252
  : "");
253
+ // When `fetchStateHistory` is requested, thus we assume that branching
254
+ // is enabled. We then need to include the implicit branch.
255
+ const includeImplicitBranch = historyLimit === true || typeof historyLimit === "number";
256
+ const shouldRefetch =
257
+ // We're expecting the whole thread state in onFinish
258
+ options.onFinish != null ||
259
+ // We're fetching history, thus we need the latest checkpoint
260
+ // to ensure we're not accidentally submitting to a wrong branch
261
+ includeImplicitBranch;
253
262
  stream.setStreamValues(() => {
263
+ const prev = shouldRefetch
264
+ ? historyValues
265
+ : { ...historyValues, ...stream.values };
254
266
  if (submitOptions?.optimisticValues != null) {
255
267
  return {
256
- ...historyValues,
268
+ ...prev,
257
269
  ...(typeof submitOptions.optimisticValues === "function"
258
- ? submitOptions.optimisticValues(historyValues)
270
+ ? submitOptions.optimisticValues(prev)
259
271
  : submitOptions.optimisticValues),
260
272
  };
261
273
  }
262
- return { ...historyValues };
274
+ return { ...prev };
263
275
  });
264
- // When `fetchStateHistory` is requested, thus we assume that branching
265
- // is enabled. We then need to include the implicit branch.
266
- const includeImplicitBranch = historyLimit === true || typeof historyLimit === "number";
267
276
  let callbackMeta;
268
277
  let rejoinKey;
269
278
  let usableThreadId = threadId;
@@ -341,12 +350,6 @@ function useStreamLGP(options) {
341
350
  async onSuccess() {
342
351
  if (rejoinKey)
343
352
  runMetadataStorage?.removeItem(rejoinKey);
344
- const shouldRefetch =
345
- // We're expecting the whole thread state in onFinish
346
- options.onFinish != null ||
347
- // We're fetching history, thus we need the latest checkpoint
348
- // to ensure we're not accidentally submitting to a wrong branch
349
- includeImplicitBranch;
350
353
  if (shouldRefetch) {
351
354
  const newHistory = await history.mutate(usableThreadId);
352
355
  const lastHead = newHistory?.at(0);
@@ -246,20 +246,29 @@ export function useStreamLGP(options) {
246
246
  setBranch(checkpointId != null
247
247
  ? branchContext.branchByCheckpoint[checkpointId]?.branch ?? ""
248
248
  : "");
249
+ // When `fetchStateHistory` is requested, thus we assume that branching
250
+ // is enabled. We then need to include the implicit branch.
251
+ const includeImplicitBranch = historyLimit === true || typeof historyLimit === "number";
252
+ const shouldRefetch =
253
+ // We're expecting the whole thread state in onFinish
254
+ options.onFinish != null ||
255
+ // We're fetching history, thus we need the latest checkpoint
256
+ // to ensure we're not accidentally submitting to a wrong branch
257
+ includeImplicitBranch;
249
258
  stream.setStreamValues(() => {
259
+ const prev = shouldRefetch
260
+ ? historyValues
261
+ : { ...historyValues, ...stream.values };
250
262
  if (submitOptions?.optimisticValues != null) {
251
263
  return {
252
- ...historyValues,
264
+ ...prev,
253
265
  ...(typeof submitOptions.optimisticValues === "function"
254
- ? submitOptions.optimisticValues(historyValues)
266
+ ? submitOptions.optimisticValues(prev)
255
267
  : submitOptions.optimisticValues),
256
268
  };
257
269
  }
258
- return { ...historyValues };
270
+ return { ...prev };
259
271
  });
260
- // When `fetchStateHistory` is requested, thus we assume that branching
261
- // is enabled. We then need to include the implicit branch.
262
- const includeImplicitBranch = historyLimit === true || typeof historyLimit === "number";
263
272
  let callbackMeta;
264
273
  let rejoinKey;
265
274
  let usableThreadId = threadId;
@@ -337,12 +346,6 @@ export function useStreamLGP(options) {
337
346
  async onSuccess() {
338
347
  if (rejoinKey)
339
348
  runMetadataStorage?.removeItem(rejoinKey);
340
- const shouldRefetch =
341
- // We're expecting the whole thread state in onFinish
342
- options.onFinish != null ||
343
- // We're fetching history, thus we need the latest checkpoint
344
- // to ensure we're not accidentally submitting to a wrong branch
345
- includeImplicitBranch;
346
349
  if (shouldRefetch) {
347
350
  const newHistory = await history.mutate(usableThreadId);
348
351
  const lastHead = newHistory?.at(0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/langgraph-sdk",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "Client library for interacting with the LangGraph API",
5
5
  "type": "module",
6
6
  "scripts": {