feat(sdk-js): add bulkUpdateState method (#3878)

This commit is contained in:
David Duong
2025-03-19 19:25:37 +01:00
committed by GitHub
2 changed files with 36 additions and 1 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@langchain/langgraph-sdk",
"version": "0.0.57",
"version": "0.0.59",
"description": "Client library for interacting with the LangGraph API",
"type": "module",
"packageManager": "yarn@1.22.19",
+35
View File
@@ -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";
@@ -638,6 +639,40 @@ export class ThreadsClient<
);
}
/**
* Create a new thread from a batch states.
*/
async bulkUpdateState(
supersteps: Array<{
updates: Array<{ values: unknown; command?: Command; asNode: string }>;
}>,
options?: {
graphId?: string;
threadId?: string;
metadata?: Metadata;
ifExists?: OnConflictBehavior;
},
): Promise<Thread<TStateType>> {
return this.fetch<Thread<TStateType>>("/threads/state/batch", {
method: "POST",
json: {
supersteps: supersteps.map((s) => ({
updates: s.updates.map((u) => ({
values: u.values,
command: u.command,
as_node: u.asNode,
})),
})),
thread_id: options?.threadId,
metadata: {
...options?.metadata,
graph_id: options?.graphId,
},
if_exists: options?.ifExists,
},
});
}
/**
* Patch the metadata of a thread.
*