Skip to content

Commit

Permalink
fix(sdk-js): allow passing checkpoint when creating a run
Browse files Browse the repository at this point in the history
  • Loading branch information
dqbd committed Oct 9, 2024
1 parent f9df0f4 commit 8df533b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
21 changes: 21 additions & 0 deletions libs/sdk-js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,12 @@ export class RunsClient extends BaseClient {
event: StreamEvent;
data: any;
}> {
if (!!payload?.checkpointId && !!payload?.checkpoint) {
throw new Error(
"Cannot specify both a checkpoint and a checkpoint ID in the payload.",
);
}

const json: Record<string, any> = {
input: payload?.input,
config: payload?.config,
Expand All @@ -674,6 +680,7 @@ export class RunsClient extends BaseClient {
assistant_id: assistantId,
interrupt_before: payload?.interruptBefore,
interrupt_after: payload?.interruptAfter,
checkpoint: payload?.checkpoint,
checkpoint_id: payload?.checkpointId,
webhook: payload?.webhook,
multitask_strategy: payload?.multitaskStrategy,
Expand Down Expand Up @@ -748,6 +755,12 @@ export class RunsClient extends BaseClient {
assistantId: string,
payload?: RunsCreatePayload,
): Promise<Run> {
if (!!payload?.checkpointId && !!payload?.checkpoint) {
throw new Error(
"Cannot specify both a checkpoint and a checkpoint ID in the payload.",
);
}

const json: Record<string, any> = {
input: payload?.input,
config: payload?.config,
Expand All @@ -756,6 +769,7 @@ export class RunsClient extends BaseClient {
interrupt_before: payload?.interruptBefore,
interrupt_after: payload?.interruptAfter,
webhook: payload?.webhook,
checkpoint: payload?.checkpoint,
checkpoint_id: payload?.checkpointId,
multitask_strategy: payload?.multitaskStrategy,
after_seconds: payload?.afterSeconds,
Expand Down Expand Up @@ -815,13 +829,20 @@ export class RunsClient extends BaseClient {
assistantId: string,
payload?: RunsWaitPayload,
): Promise<ThreadState["values"]> {
if (!!payload?.checkpointId && !!payload?.checkpoint) {
throw new Error(
"Cannot specify both a checkpoint and a checkpoint ID in the payload.",
);
}

const json: Record<string, any> = {
input: payload?.input,
config: payload?.config,
metadata: payload?.metadata,
assistant_id: assistantId,
interrupt_before: payload?.interruptBefore,
interrupt_after: payload?.interruptAfter,
checkpoint: payload?.checkpoint,
checkpoint_id: payload?.checkpointId,
webhook: payload?.webhook,
multitask_strategy: payload?.multitaskStrategy,
Expand Down
8 changes: 7 additions & 1 deletion libs/sdk-js/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config, Metadata } from "./schema.js";
import { Checkpoint, Config, Metadata } from "./schema.js";

export type StreamMode = "values" | "messages" | "updates" | "events" | "debug";
export type MultitaskStrategy = "reject" | "interrupt" | "rollback" | "enqueue";
Expand Down Expand Up @@ -34,9 +34,15 @@ interface RunsInvokePayload {

/**
* Checkpoint ID for when creating a new run.
* @deprecated Use `checkpoint` instead.
*/
checkpointId?: string;

/**
* Checkpoint for when creating a new run.
*/
checkpoint?: Omit<Checkpoint, "thread_id">;

/**
* Interrupt execution before entering these nodes.
*/
Expand Down

0 comments on commit 8df533b

Please sign in to comment.