From 6dfed31a5e3f31164fe8e4a184679f5244c5dabb Mon Sep 17 00:00:00 2001 From: Tat Dat Duong Date: Wed, 19 Mar 2025 21:39:35 +0100 Subject: [PATCH] Update parameters --- libs/sdk-js/src/client.ts | 43 ++++++++--------- libs/sdk-py/langgraph_sdk/client.py | 72 +++++++++++++---------------- 2 files changed, 50 insertions(+), 65 deletions(-) diff --git a/libs/sdk-js/src/client.ts b/libs/sdk-js/src/client.ts index 6c654350d..f349a6587 100644 --- a/libs/sdk-js/src/client.ts +++ b/libs/sdk-js/src/client.ts @@ -503,35 +503,28 @@ export class ThreadsClient< * * Used for copying a thread between deployments. */ - fromSupersteps?: Array<{ + supersteps?: Array<{ updates: Array<{ values: unknown; command?: Command; asNode: string }>; }>; }): Promise> { - const json: Record = { - metadata: { - ...payload?.metadata, - graph_id: payload?.graphId, - }, - thread_id: payload?.threadId, - if_exists: payload?.ifExists, - }; - - if (payload?.fromSupersteps) { - json.supersteps = payload.fromSupersteps.map((s) => ({ - updates: s.updates.map((u) => ({ - values: u.values, - command: u.command, - as_node: u.asNode, + return this.fetch>(`/threads`, { + method: "POST", + json: { + metadata: { + ...payload?.metadata, + graph_id: payload?.graphId, + }, + thread_id: payload?.threadId, + if_exists: payload?.ifExists, + supersteps: payload?.supersteps?.map((s) => ({ + updates: s.updates.map((u) => ({ + values: u.values, + command: u.command, + as_node: u.asNode, + })), })), - })); - - return this.fetch>(`/threads/state/bulk`, { - method: "POST", - json, - }); - } - - return this.fetch>(`/threads`, { method: "POST", json }); + }, + }); } /** diff --git a/libs/sdk-py/langgraph_sdk/client.py b/libs/sdk-py/langgraph_sdk/client.py index f51477acb..4418e66de 100644 --- a/libs/sdk-py/langgraph_sdk/client.py +++ b/libs/sdk-py/langgraph_sdk/client.py @@ -839,7 +839,7 @@ class ThreadsClient: metadata: Json = None, thread_id: Optional[str] = None, if_exists: Optional[OnConflictBehavior] = None, - from_supersteps: Optional[Sequence[dict[str, Sequence[dict[str, Any]]]]] = None, + supersteps: Optional[Sequence[dict[str, Sequence[dict[str, Any]]]]] = None, graph_id: Optional[str] = None, ) -> Thread: """Create a new thread. @@ -850,7 +850,7 @@ class ThreadsClient: If None, ID will be a randomly generated UUID. if_exists: How to handle duplicate creation. Defaults to 'raise' under the hood. Must be either 'raise' (raise error if duplicate), or 'do_nothing' (return existing thread). - from_supersteps: Apply a list of supersteps when creating a thread, each containing a sequence of updates. + supersteps: Apply a list of supersteps when creating a thread, each containing a sequence of updates. Each update has `values` or `command` and `as_node`. Used for copying a thread between deployments. graph_id: Optional graph ID to associate with the thread. @@ -875,25 +875,21 @@ class ThreadsClient: } if if_exists: payload["if_exists"] = if_exists - if from_supersteps: - payload["supersteps"] = { - "supersteps": [ - { - "updates": [ - { - "values": u["values"], - "command": u.get("command"), - "as_node": u["as_node"], - } - for u in s["updates"] - ] - } - for s in from_supersteps - ], - } + if supersteps: + payload["supersteps"] = [ + { + "updates": [ + { + "values": u["values"], + "command": u.get("command"), + "as_node": u["as_node"], + } + for u in s["updates"] + ] + } + for s in supersteps + ] - if payload.get("supersteps") is not None: - return self.http.post("/threads/state/bulk", json=payload) return await self.http.post("/threads", json=payload) async def update(self, thread_id: str, *, metadata: dict[str, Any]) -> Thread: @@ -3063,7 +3059,7 @@ class SyncThreadsClient: metadata: Json = None, thread_id: Optional[str] = None, if_exists: Optional[OnConflictBehavior] = None, - from_supersteps: Optional[Sequence[dict[str, Sequence[dict[str, Any]]]]] = None, + supersteps: Optional[Sequence[dict[str, Sequence[dict[str, Any]]]]] = None, graph_id: Optional[str] = None, ) -> Thread: """Create a new thread. @@ -3074,7 +3070,7 @@ class SyncThreadsClient: If None, ID will be a randomly generated UUID. if_exists: How to handle duplicate creation. Defaults to 'raise' under the hood. Must be either 'raise' (raise error if duplicate), or 'do_nothing' (return existing thread). - from_supersteps: Apply a list of supersteps when creating a thread, each containing a sequence of updates. + supersteps: Apply a list of supersteps when creating a thread, each containing a sequence of updates. Each update has `values` or `command` and `as_node`. Used for copying a thread between deployments. graph_id: Optional graph ID to associate with the thread. @@ -3099,25 +3095,21 @@ class SyncThreadsClient: } if if_exists: payload["if_exists"] = if_exists - if from_supersteps: - payload["supersteps"] = { - "supersteps": [ - { - "updates": [ - { - "values": u["values"], - "command": u.get("command"), - "as_node": u["as_node"], - } - for u in s["updates"] - ] - } - for s in from_supersteps - ], - } + if supersteps: + payload["supersteps"] = [ + { + "updates": [ + { + "values": u["values"], + "command": u.get("command"), + "as_node": u["as_node"], + } + for u in s["updates"] + ] + } + for s in supersteps + ] - if payload.get("supersteps") is not None: - return self.http.post("/threads/state/bulk", json=payload) return self.http.post("/threads", json=payload) def update(self, thread_id: str, *, metadata: dict[str, Any]) -> Thread: