From 1a728a93c603260a2e9f8842ec91843dc4f1bcae Mon Sep 17 00:00:00 2001 From: Tat Dat Duong Date: Mon, 17 Mar 2025 17:22:03 +0100 Subject: [PATCH 1/7] feat(sdk-js): add bulkUpdateState method --- libs/sdk-js/src/client.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/libs/sdk-js/src/client.ts b/libs/sdk-js/src/client.ts index 84ef3d44c..4fef0bc71 100644 --- a/libs/sdk-js/src/client.ts +++ b/libs/sdk-js/src/client.ts @@ -638,6 +638,33 @@ export class ThreadsClient< ); } + /** + * Create a new thread from a batch states. + */ + async bulkUpdateState( + supersteps: Array<{ updates: Array<{ values: unknown; asNode: string }> }>, + options: { + threadId?: string; + metadata?: Metadata; + ifExists?: OnConflictBehavior; + }, + ): Promise> { + return this.fetch>("/threads/state/batch", { + method: "POST", + json: { + supersteps: supersteps.map((s) => ({ + updates: s.updates.map((u) => ({ + values: u.values, + as_node: u.asNode, + })), + })), + thread_id: options.threadId, + metadata: options.metadata, + if_exists: options.ifExists, + }, + }); + } + /** * Patch the metadata of a thread. * From 7ae47396305f00d11350fecee3a1c42bb6b8025a Mon Sep 17 00:00:00 2001 From: Tat Dat Duong Date: Mon, 17 Mar 2025 18:07:14 +0100 Subject: [PATCH 2/7] Make options optional --- libs/sdk-js/src/client.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/sdk-js/src/client.ts b/libs/sdk-js/src/client.ts index 4fef0bc71..00f340204 100644 --- a/libs/sdk-js/src/client.ts +++ b/libs/sdk-js/src/client.ts @@ -643,7 +643,7 @@ export class ThreadsClient< */ async bulkUpdateState( supersteps: Array<{ updates: Array<{ values: unknown; asNode: string }> }>, - options: { + options?: { threadId?: string; metadata?: Metadata; ifExists?: OnConflictBehavior; @@ -658,9 +658,9 @@ export class ThreadsClient< as_node: u.asNode, })), })), - thread_id: options.threadId, - metadata: options.metadata, - if_exists: options.ifExists, + thread_id: options?.threadId, + metadata: options?.metadata, + if_exists: options?.ifExists, }, }); } From 5104e31e35b5af64a1fca5dfeb69eaa550bd54ae Mon Sep 17 00:00:00 2001 From: Tat Dat Duong Date: Mon, 17 Mar 2025 18:14:33 +0100 Subject: [PATCH 3/7] feat(sdk-js): add bulkUpdateState method --- libs/sdk-js/src/client.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/sdk-js/src/client.ts b/libs/sdk-js/src/client.ts index 00f340204..ede19852f 100644 --- a/libs/sdk-js/src/client.ts +++ b/libs/sdk-js/src/client.ts @@ -644,6 +644,7 @@ export class ThreadsClient< async bulkUpdateState( supersteps: Array<{ updates: Array<{ values: unknown; asNode: string }> }>, options?: { + graphId?: string; threadId?: string; metadata?: Metadata; ifExists?: OnConflictBehavior; @@ -659,7 +660,10 @@ export class ThreadsClient< })), })), thread_id: options?.threadId, - metadata: options?.metadata, + metadata: { + ...options?.metadata, + graph_id: options?.graphId, + }, if_exists: options?.ifExists, }, }); From 4bff1df4b0ddb23743e750f6ac0c92a8c6c6f549 Mon Sep 17 00:00:00 2001 From: Tat Dat Duong Date: Mon, 17 Mar 2025 18:14:51 +0100 Subject: [PATCH 4/7] Bump to 0.0.58 --- libs/sdk-js/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/sdk-js/package.json b/libs/sdk-js/package.json index 2200fab34..a29a438b0 100644 --- a/libs/sdk-js/package.json +++ b/libs/sdk-js/package.json @@ -1,6 +1,6 @@ { "name": "@langchain/langgraph-sdk", - "version": "0.0.57", + "version": "0.0.58", "description": "Client library for interacting with the LangGraph API", "type": "module", "packageManager": "yarn@1.22.19", From b1a25abc73b0dc77bce2cce2dd919ed8bc5b7b7c Mon Sep 17 00:00:00 2001 From: Tat Dat Duong Date: Tue, 18 Mar 2025 21:22:40 +0100 Subject: [PATCH 5/7] Add command --- libs/sdk-js/src/client.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/sdk-js/src/client.ts b/libs/sdk-js/src/client.ts index ede19852f..7efc2e423 100644 --- a/libs/sdk-js/src/client.ts +++ b/libs/sdk-js/src/client.ts @@ -30,6 +30,7 @@ import type { StreamEvent, CronsCreatePayload, OnConflictBehavior, + Command, } from "./types.js"; import { mergeSignals } from "./utils/signals.js"; import { getEnvironmentVariable } from "./utils/env.js"; @@ -642,7 +643,7 @@ export class ThreadsClient< * Create a new thread from a batch states. */ async bulkUpdateState( - supersteps: Array<{ updates: Array<{ values: unknown; asNode: string }> }>, + supersteps: Array<{ updates: Array<{ values: unknown; command?: Command; asNode: string }> }>, options?: { graphId?: string; threadId?: string; @@ -656,6 +657,7 @@ export class ThreadsClient< supersteps: supersteps.map((s) => ({ updates: s.updates.map((u) => ({ values: u.values, + command: u.command, as_node: u.asNode, })), })), From 24bd0e1c1f9150afe1baf750c768f4bb7414f426 Mon Sep 17 00:00:00 2001 From: Tat Dat Duong Date: Wed, 19 Mar 2025 16:59:53 +0100 Subject: [PATCH 6/7] Fix formatting --- libs/sdk-js/src/client.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/sdk-js/src/client.ts b/libs/sdk-js/src/client.ts index 7efc2e423..52051f1e8 100644 --- a/libs/sdk-js/src/client.ts +++ b/libs/sdk-js/src/client.ts @@ -643,7 +643,9 @@ export class ThreadsClient< * Create a new thread from a batch states. */ async bulkUpdateState( - supersteps: Array<{ updates: Array<{ values: unknown; command?: Command; asNode: string }> }>, + supersteps: Array<{ + updates: Array<{ values: unknown; command?: Command; asNode: string }>; + }>, options?: { graphId?: string; threadId?: string; From 00855999d207a6cd3ac9b4c96dcf7c866bd07ff9 Mon Sep 17 00:00:00 2001 From: Tat Dat Duong Date: Wed, 19 Mar 2025 17:02:19 +0100 Subject: [PATCH 7/7] Bump to 0.0.59 --- libs/sdk-js/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/sdk-js/package.json b/libs/sdk-js/package.json index a29a438b0..6c3d5a06c 100644 --- a/libs/sdk-js/package.json +++ b/libs/sdk-js/package.json @@ -1,6 +1,6 @@ { "name": "@langchain/langgraph-sdk", - "version": "0.0.58", + "version": "0.0.59", "description": "Client library for interacting with the LangGraph API", "type": "module", "packageManager": "yarn@1.22.19",