diff --git a/packages/sdk/src/LLM/Chat.class.ts b/packages/sdk/src/LLM/Chat.class.ts index 8268b9b1..52be2077 100644 --- a/packages/sdk/src/LLM/Chat.class.ts +++ b/packages/sdk/src/LLM/Chat.class.ts @@ -13,7 +13,10 @@ class LocalChatStore extends SDKObject implements ILLMContextStore { public get id() { return this._conversationId; } - constructor(private _conversationId: string, candidate: AccessCandidate) { + constructor( + private _conversationId: string, + candidate: AccessCandidate, + ) { super(); this._storage = new StorageInstance(null, null, candidate); } @@ -46,7 +49,11 @@ class LocalChatStore extends SDKObject implements ILLMContextStore { class ChatCommand { private _conversation: Conversation; - constructor(private prompt: string, private chat: Chat, private options?: PromptOptions) { + constructor( + private prompt: string, + private chat: Chat, + private options?: PromptOptions, + ) { this._conversation = chat._conversation; } @@ -57,7 +64,12 @@ class ChatCommand { private async run(): Promise { await this.chat.ready; await this._conversation.ready; //when we switch agent mode at runtime, we need to wait for the conversation to be ready - const result = await this._conversation.streamPrompt(this.prompt, this.options?.headers, this.options?.concurrentCalls); + const result = await this._conversation.streamPrompt( + this.prompt, + this.options?.headers, + this.options?.concurrentCalls, + this.options?.abortSignal, + ); return result; } @@ -151,9 +163,11 @@ class ChatCommand { this._conversation.on(TLLMEvent.Data, dataHandler); // Start the streaming process - don't await as we want to return the eventEmitter immediately - this._conversation.streamPrompt(this.prompt, this.options?.headers, this.options?.concurrentCalls).catch((error) => { - eventEmitter.emit(TLLMEvent.Error, error); - }); + this._conversation + .streamPrompt(this.prompt, this.options?.headers, this.options?.concurrentCalls, this.options?.abortSignal) + .catch((error) => { + eventEmitter.emit(TLLMEvent.Error, error); + }); return eventEmitter; } } @@ -187,7 +201,11 @@ export class Chat extends SDKObject { public get agentData() { return this._data; } - constructor(options: ChatOptions & { candidate: AccessCandidate }, private source?: Agent | Record, private _convOptions: any = {}) { + constructor( + options: ChatOptions & { candidate: AccessCandidate }, + private source?: Agent | Record, + private _convOptions: any = {}, + ) { super(); const _data = source?.data || source || {}; diff --git a/packages/sdk/src/types/SDKTypes.ts b/packages/sdk/src/types/SDKTypes.ts index d72cde81..11f0039f 100644 --- a/packages/sdk/src/types/SDKTypes.ts +++ b/packages/sdk/src/types/SDKTypes.ts @@ -63,6 +63,7 @@ export type ChatOptions = { export type PromptOptions = { headers?: Record; concurrentCalls?: number; + abortSignal?: AbortSignal; }; export enum Scope {