From 1a728a93c603260a2e9f8842ec91843dc4f1bcae Mon Sep 17 00:00:00 2001 From: Tat Dat Duong Date: Mon, 17 Mar 2025 17:22:03 +0100 Subject: [PATCH] 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. *