diff --git a/libs/sdk-js/src/client.mts b/libs/sdk-js/src/client.mts index a39569a70..33db68e60 100644 --- a/libs/sdk-js/src/client.mts +++ b/libs/sdk-js/src/client.mts @@ -55,7 +55,7 @@ class BaseClient { options?: RequestInit & { json?: unknown; params?: Record; - }, + } ): [url: URL, init: RequestInit] { const mutatedOptions = { ...options, @@ -95,10 +95,10 @@ class BaseClient { options?: RequestInit & { json?: unknown; params?: Record; - }, + } ): Promise { const response = await this.asyncCaller.fetch( - ...this.prepareFetchOptions(path, options), + ...this.prepareFetchOptions(path, options) ); if (response.status === 202 || response.status === 204) { return undefined as T; @@ -118,7 +118,7 @@ export class CronsClient extends BaseClient { async createForThread( threadId: string, assistantId: string, - payload?: CronsCreatePayload, + payload?: CronsCreatePayload ): Promise { const json: Record = { schedule: payload?.schedule, @@ -144,7 +144,7 @@ export class CronsClient extends BaseClient { */ async create( assistantId: string, - payload?: CronsCreatePayload, + payload?: CronsCreatePayload ): Promise { const json: Record = { schedule: payload?.schedule, @@ -256,7 +256,7 @@ export class AssistantsClient extends BaseClient { graphId: string; config?: Config; metadata?: Metadata; - }, + } ): Promise { return this.fetch(`/assistants/${assistantId}`, { method: "PATCH", @@ -337,6 +337,17 @@ export class ThreadsClient extends BaseClient { }); } + /** + * Copy an existing thread + * @param threadId ID of the thread to be copied + * @returns Newly copied thread + */ + async copy(threadId: string): Promise { + return this.fetch(`/threads/${threadId}/copy`, { + method: "POST", + }); + } + /** * Update a thread. * @@ -351,7 +362,7 @@ export class ThreadsClient extends BaseClient { * Metadata for the thread. */ metadata?: Metadata; - }, + } ): Promise { return this.fetch(`/threads/${threadId}`, { method: "PATCH", @@ -409,12 +420,12 @@ export class ThreadsClient extends BaseClient { */ async getState( threadId: string, - checkpointId?: string, + checkpointId?: string ): Promise> { return this.fetch>( checkpointId != null ? `/threads/${threadId}/state/${checkpointId}` - : `/threads/${threadId}/state`, + : `/threads/${threadId}/state` ); } @@ -426,7 +437,7 @@ export class ThreadsClient extends BaseClient { */ async updateState( threadId: string, - options: { values: ValuesType; checkpointId?: string; asNode?: string }, + options: { values: ValuesType; checkpointId?: string; asNode?: string } ): Promise> { return this.fetch>( `/threads/${threadId}/state`, @@ -437,7 +448,7 @@ export class ThreadsClient extends BaseClient { checkpoint_id: options.checkpointId, as_node: options?.asNode, }, - }, + } ); } @@ -449,14 +460,14 @@ export class ThreadsClient extends BaseClient { */ async patchState( threadIdOrConfig: string | Config, - metadata: Metadata, + metadata: Metadata ): Promise { let threadId: string; if (typeof threadIdOrConfig !== "string") { if (typeof threadIdOrConfig.configurable.thread_id !== "string") { throw new Error( - "Thread ID is required when updating state with a config.", + "Thread ID is required when updating state with a config." ); } threadId = threadIdOrConfig.configurable.thread_id; @@ -483,7 +494,7 @@ export class ThreadsClient extends BaseClient { limit?: number; before?: Config; metadata?: Metadata; - }, + } ): Promise[]> { return this.fetch[]>( `/threads/${threadId}/history`, @@ -494,7 +505,7 @@ export class ThreadsClient extends BaseClient { before: options?.before, metadata: options?.metadata, }, - }, + } ); } } @@ -503,7 +514,7 @@ export class RunsClient extends BaseClient { stream( threadId: null, assistantId: string, - payload?: Omit, + payload?: Omit ): AsyncGenerator<{ event: StreamEvent; data: any; @@ -512,7 +523,7 @@ export class RunsClient extends BaseClient { stream( threadId: string, assistantId: string, - payload?: RunsStreamPayload, + payload?: RunsStreamPayload ): AsyncGenerator<{ event: StreamEvent; data: any; @@ -528,7 +539,7 @@ export class RunsClient extends BaseClient { async *stream( threadId: string | null, assistantId: string, - payload?: RunsStreamPayload, + payload?: RunsStreamPayload ): AsyncGenerator<{ event: StreamEvent; // TODO: figure out a better way to @@ -556,7 +567,7 @@ export class RunsClient extends BaseClient { method: "POST", json, signal: payload?.signal, - }), + }) ); let parser: EventSourceParser; @@ -587,7 +598,7 @@ export class RunsClient extends BaseClient { async transform(chunk) { parser.feed(textDecoder.decode(chunk)); }, - }), + }) ); yield* IterableReadableStream.fromReadableStream(stream); @@ -604,7 +615,7 @@ export class RunsClient extends BaseClient { async create( threadId: string, assistantId: string, - payload?: RunsCreatePayload, + payload?: RunsCreatePayload ): Promise { const json: Record = { input: payload?.input, @@ -628,13 +639,13 @@ export class RunsClient extends BaseClient { async wait( threadId: null, assistantId: string, - payload?: Omit, + payload?: Omit ): Promise; async wait( threadId: string, assistantId: string, - payload?: RunsWaitPayload, + payload?: RunsWaitPayload ): Promise; /** @@ -648,7 +659,7 @@ export class RunsClient extends BaseClient { async wait( threadId: string | null, assistantId: string, - payload?: RunsWaitPayload, + payload?: RunsWaitPayload ): Promise { const json: Record = { input: payload?.input, @@ -691,7 +702,7 @@ export class RunsClient extends BaseClient { * Defaults to 0. */ offset?: number; - }, + } ): Promise { return this.fetch(`/threads/${threadId}/runs`, { params: { @@ -723,7 +734,7 @@ export class RunsClient extends BaseClient { async cancel( threadId: string, runId: string, - wait: boolean = false, + wait: boolean = false ): Promise { return this.fetch(`/threads/${threadId}/runs/${runId}/cancel`, { method: "POST",