From 2064ea4793417c8ecb012e579f1f8dfec4e715fa Mon Sep 17 00:00:00 2001 From: Tat Dat Duong Date: Sat, 8 Feb 2025 10:32:28 -0800 Subject: [PATCH] fix(sdk-js): use `type` instead of `interface` to avoid TS errors Allow assigning `threadState?.checkpoint` to the `configurable` object without TSC throwing "Index signature for type 'string' is missing in type". --- libs/sdk-js/src/client.ts | 2 +- libs/sdk-js/src/schema.ts | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/libs/sdk-js/src/client.ts b/libs/sdk-js/src/client.ts index d7f0c42b3..da88c84df 100644 --- a/libs/sdk-js/src/client.ts +++ b/libs/sdk-js/src/client.ts @@ -649,7 +649,7 @@ export class ThreadsClient extends BaseClient { let threadId: string; if (typeof threadIdOrConfig !== "string") { - if (typeof threadIdOrConfig.configurable.thread_id !== "string") { + if (typeof threadIdOrConfig.configurable?.thread_id !== "string") { throw new Error( "Thread ID is required when updating state with a config.", ); diff --git a/libs/sdk-js/src/schema.ts b/libs/sdk-js/src/schema.ts index 6d6621012..b737d6a72 100644 --- a/libs/sdk-js/src/schema.ts +++ b/libs/sdk-js/src/schema.ts @@ -16,7 +16,7 @@ type MultitaskStrategy = "reject" | "interrupt" | "rollback" | "enqueue"; export type CancelAction = "interrupt" | "rollback"; -export interface Config { +export type Config = { /** * Tags for this call and any sub-calls (eg. a Chain calling an LLM). * You can use these to filter calls. @@ -32,19 +32,20 @@ export interface Config { /** * Runtime values for attributes previously made configurable on this Runnable. */ - configurable: { + configurable?: { /** * ID of the thread */ - thread_id?: string; + thread_id?: Optional; /** * Timestamp of the state checkpoint */ - checkpoint_id?: string; + checkpoint_id?: Optional; + [key: string]: unknown; }; -} +}; export interface GraphSchema { /** @@ -254,12 +255,12 @@ export interface Run { multitask_strategy: Optional; } -export interface Checkpoint { +export type Checkpoint = { thread_id: string; checkpoint_ns: string; checkpoint_id: Optional; checkpoint_map: Optional>; -} +}; export interface ListNamespaceResponse { namespaces: string[][];