Skip to content

Commit

Permalink
Add: support for abort signal in dust-client (#8570)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraggle authored Nov 9, 2024
1 parent 43bbbdc commit b6bde37
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sdks/js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type RequestArgsType = {
query?: URLSearchParams;
body?: Record<string, unknown>;
overrideWorkspaceId?: string;
signal?: AbortSignal;
};

export class DustAPI {
Expand Down Expand Up @@ -117,6 +118,10 @@ export class DustAPI {
return this._credentials.workspaceId;
}

setWorkspaceId(workspaceId: string) {
this._credentials.workspaceId = workspaceId;
}

apiUrl(): string {
if (this._urlOverride) {
return this._urlOverride;
Expand Down Expand Up @@ -186,6 +191,7 @@ export class DustAPI {
method: args.method,
headers,
body: args.body ? JSON.stringify(args.body) : undefined,
signal: args.signal,
});

return res;
Expand Down Expand Up @@ -565,9 +571,11 @@ export class DustAPI {
async streamAgentAnswerEvents({
conversation,
userMessageId,
signal,
}: {
conversation: ConversationPublicType;
userMessageId: string;
signal?: AbortSignal;
}) {
// find the agent message with the parentMessageId equal to the user message id
const agentMessages = conversation.content
Expand All @@ -588,6 +596,7 @@ export class DustAPI {
const res = await this.request({
method: "GET",
path: `assistant/conversations/${conversation.sId}/messages/${agentMessage.sId}/events`,
signal,
});

if (res.isErr()) {
Expand Down

0 comments on commit b6bde37

Please sign in to comment.