@dremio/js-sdk 0.32.0 → 0.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/enterprise/ai/chat/eventWrappers/AgentChatExchange.d.ts +21 -0
- package/dist/enterprise/ai/chat/eventWrappers/AgentChatExchange.js +58 -0
- package/dist/enterprise/ai/chat/eventWrappers/AgentChatExchange.js.map +1 -0
- package/dist/enterprise/ai/chat/eventWrappers/AgentEndTurn.d.ts +42 -0
- package/dist/enterprise/ai/chat/eventWrappers/AgentEndTurn.js +56 -0
- package/dist/enterprise/ai/chat/eventWrappers/AgentEndTurn.js.map +1 -0
- package/dist/enterprise/ai/chat/eventWrappers/AgentToolCall.d.ts +18 -0
- package/dist/enterprise/ai/chat/eventWrappers/AgentToolCall.js +67 -0
- package/dist/enterprise/ai/chat/eventWrappers/AgentToolCall.js.map +1 -0
- package/dist/enterprise/ai/chat/eventWrappers/AgentToolCallGroup.d.ts +18 -0
- package/dist/enterprise/ai/chat/eventWrappers/AgentToolCallGroup.js +54 -0
- package/dist/enterprise/ai/chat/eventWrappers/AgentToolCallGroup.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AgentEndTurn } from "./AgentEndTurn.ts";
|
|
2
|
+
import { AgentChatResponse, UserChatMessage, type AgentResponseContent } from "@dremio/js-sdk/enterprise";
|
|
3
|
+
import { type Option } from "ts-results-es";
|
|
4
|
+
import { AgentToolCallGroup } from "./AgentToolCallGroup.ts";
|
|
5
|
+
import type { AgentToolCall } from "./AgentToolCall.ts";
|
|
6
|
+
/**
|
|
7
|
+
* Represents a single chat exchange, starting with a `UserChatMessage` and followed by
|
|
8
|
+
* 0 or more agent chat events. As chat events stream in, this class is updated
|
|
9
|
+
* immutably but maintains a stable `.id` property.
|
|
10
|
+
*/
|
|
11
|
+
export declare class AgentChatExchange {
|
|
12
|
+
readonly agentChatEvents: AgentChatExchangeEvent[];
|
|
13
|
+
readonly agentToolCallGroup: AgentToolCallGroup;
|
|
14
|
+
readonly id: string;
|
|
15
|
+
readonly userChatMessage: UserChatMessage;
|
|
16
|
+
constructor(userChatMessage: AgentChatExchange["userChatMessage"], agentChatEvents: AgentChatExchange["agentChatEvents"], agentToolCallGroup?: AgentToolCallGroup, id?: string);
|
|
17
|
+
get isComplete(): boolean;
|
|
18
|
+
get completeReason(): Option<AgentEndTurn["reason"]>;
|
|
19
|
+
addChatEvent(agentChatEvent: AgentChatExchangeEvent): AgentChatExchange;
|
|
20
|
+
}
|
|
21
|
+
export type AgentChatExchangeEvent = AgentChatResponse<AgentResponseContent> | AgentEndTurn | AgentToolCall | AgentToolCallGroup;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2024-2025 Dremio Corporation
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { nanoid } from "nanoid/non-secure";
|
|
17
|
+
import { AgentEndTurn } from "./AgentEndTurn.js";
|
|
18
|
+
import { AgentChatResponse, UserChatMessage, } from "@dremio/js-sdk/enterprise";
|
|
19
|
+
import { None, Some } from "ts-results-es";
|
|
20
|
+
import { AgentToolCallGroup } from "./AgentToolCallGroup.js";
|
|
21
|
+
import { isToolRequest, isToolResult } from "./AgentToolCall.js";
|
|
22
|
+
/**
|
|
23
|
+
* Represents a single chat exchange, starting with a `UserChatMessage` and followed by
|
|
24
|
+
* 0 or more agent chat events. As chat events stream in, this class is updated
|
|
25
|
+
* immutably but maintains a stable `.id` property.
|
|
26
|
+
*/
|
|
27
|
+
export class AgentChatExchange {
|
|
28
|
+
agentChatEvents;
|
|
29
|
+
agentToolCallGroup;
|
|
30
|
+
id;
|
|
31
|
+
userChatMessage;
|
|
32
|
+
constructor(userChatMessage, agentChatEvents, agentToolCallGroup = new AgentToolCallGroup([]), id = nanoid()) {
|
|
33
|
+
this.agentChatEvents = agentChatEvents;
|
|
34
|
+
this.agentToolCallGroup = agentToolCallGroup;
|
|
35
|
+
this.id = id;
|
|
36
|
+
this.userChatMessage = userChatMessage;
|
|
37
|
+
}
|
|
38
|
+
get isComplete() {
|
|
39
|
+
return this.agentChatEvents.at(-1) instanceof AgentEndTurn;
|
|
40
|
+
}
|
|
41
|
+
get completeReason() {
|
|
42
|
+
const lastEvent = this.agentChatEvents.at(-1);
|
|
43
|
+
if (lastEvent instanceof AgentEndTurn) {
|
|
44
|
+
return Some(lastEvent.reason);
|
|
45
|
+
}
|
|
46
|
+
return None;
|
|
47
|
+
}
|
|
48
|
+
addChatEvent(agentChatEvent) {
|
|
49
|
+
if (isToolRequest(agentChatEvent)) {
|
|
50
|
+
return new AgentChatExchange(this.userChatMessage, this.agentChatEvents, this.agentToolCallGroup.addRequest(agentChatEvent), this.id);
|
|
51
|
+
}
|
|
52
|
+
if (isToolResult(agentChatEvent)) {
|
|
53
|
+
return new AgentChatExchange(this.userChatMessage, this.agentChatEvents, this.agentToolCallGroup.addResult(agentChatEvent), this.id);
|
|
54
|
+
}
|
|
55
|
+
return new AgentChatExchange(this.userChatMessage, [...this.agentChatEvents, agentChatEvent], this.agentToolCallGroup, this.id);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=AgentChatExchange.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentChatExchange.js","sourceRoot":"","sources":["../../../../../src/enterprise/ai/chat/eventWrappers/AgentChatExchange.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EACL,iBAAiB,EACjB,eAAe,GAEhB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAe,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGjE;;;;GAIG;AACH,MAAM,OAAO,iBAAiB;IACnB,eAAe,CAA2B;IAC1C,kBAAkB,CAAqB;IACvC,EAAE,CAAS;IACX,eAAe,CAAkB;IAE1C,YACE,eAAqD,EACrD,eAAqD,EACrD,kBAAkB,GAAG,IAAI,kBAAkB,CAAC,EAAE,CAAC,EAC/C,EAAE,GAAG,MAAM,EAAE;QAEb,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;QAC7C,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IACzC,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,YAAY,YAAY,CAAC;IAC7D,CAAC;IAED,IAAI,cAAc;QAChB,MAAM,SAAS,GAAG,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAE9C,IAAI,SAAS,YAAY,YAAY,EAAE,CAAC;YACtC,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,YAAY,CAAC,cAAsC;QACjD,IAAI,aAAa,CAAC,cAAc,CAAC,EAAE,CAAC;YAClC,OAAO,IAAI,iBAAiB,CAC1B,IAAI,CAAC,eAAe,EACpB,IAAI,CAAC,eAAe,EACpB,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAAC,cAAc,CAAC,EAClD,IAAI,CAAC,EAAE,CACR,CAAC;QACJ,CAAC;QACD,IAAI,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;YACjC,OAAO,IAAI,iBAAiB,CAC1B,IAAI,CAAC,eAAe,EACpB,IAAI,CAAC,eAAe,EACpB,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,cAAc,CAAC,EACjD,IAAI,CAAC,EAAE,CACR,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,iBAAiB,CAC1B,IAAI,CAAC,eAAe,EACpB,CAAC,GAAG,IAAI,CAAC,eAAe,EAAE,cAAc,CAAC,EACzC,IAAI,CAAC,kBAAkB,EACvB,IAAI,CAAC,EAAE,CACR,CAAC;IACJ,CAAC;CACF","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { nanoid } from \"nanoid/non-secure\";\nimport { AgentEndTurn } from \"./AgentEndTurn.ts\";\nimport {\n AgentChatResponse,\n UserChatMessage,\n type AgentResponseContent,\n} from \"@dremio/js-sdk/enterprise\";\nimport { None, Some, type Option } from \"ts-results-es\";\nimport { AgentToolCallGroup } from \"./AgentToolCallGroup.ts\";\nimport { isToolRequest, isToolResult } from \"./AgentToolCall.ts\";\nimport type { AgentToolCall } from \"./AgentToolCall.ts\";\n\n/**\n * Represents a single chat exchange, starting with a `UserChatMessage` and followed by\n * 0 or more agent chat events. As chat events stream in, this class is updated\n * immutably but maintains a stable `.id` property.\n */\nexport class AgentChatExchange {\n readonly agentChatEvents: AgentChatExchangeEvent[];\n readonly agentToolCallGroup: AgentToolCallGroup;\n readonly id: string;\n readonly userChatMessage: UserChatMessage;\n\n constructor(\n userChatMessage: AgentChatExchange[\"userChatMessage\"],\n agentChatEvents: AgentChatExchange[\"agentChatEvents\"],\n agentToolCallGroup = new AgentToolCallGroup([]),\n id = nanoid(),\n ) {\n this.agentChatEvents = agentChatEvents;\n this.agentToolCallGroup = agentToolCallGroup;\n this.id = id;\n this.userChatMessage = userChatMessage;\n }\n\n get isComplete() {\n return this.agentChatEvents.at(-1) instanceof AgentEndTurn;\n }\n\n get completeReason(): Option<AgentEndTurn[\"reason\"]> {\n const lastEvent = this.agentChatEvents.at(-1);\n\n if (lastEvent instanceof AgentEndTurn) {\n return Some(lastEvent.reason);\n }\n\n return None;\n }\n\n addChatEvent(agentChatEvent: AgentChatExchangeEvent) {\n if (isToolRequest(agentChatEvent)) {\n return new AgentChatExchange(\n this.userChatMessage,\n this.agentChatEvents,\n this.agentToolCallGroup.addRequest(agentChatEvent),\n this.id,\n );\n }\n if (isToolResult(agentChatEvent)) {\n return new AgentChatExchange(\n this.userChatMessage,\n this.agentChatEvents,\n this.agentToolCallGroup.addResult(agentChatEvent),\n this.id,\n );\n }\n return new AgentChatExchange(\n this.userChatMessage,\n [...this.agentChatEvents, agentChatEvent],\n this.agentToolCallGroup,\n this.id,\n );\n }\n}\n\nexport type AgentChatExchangeEvent =\n | AgentChatResponse<AgentResponseContent>\n | AgentEndTurn\n | AgentToolCall\n | AgentToolCallGroup;\n"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as z from "zod/mini";
|
|
2
|
+
declare const endTurnReasonSchema: z.ZodMiniDiscriminatedUnion<[z.ZodMiniObject<{
|
|
3
|
+
error: z.ZodMiniUnknown;
|
|
4
|
+
type: z.ZodMiniLiteral<"error">;
|
|
5
|
+
}, z.core.$strip>, z.ZodMiniObject<{
|
|
6
|
+
type: z.ZodMiniLiteral<"reply_finished">;
|
|
7
|
+
}, z.core.$strip>, z.ZodMiniObject<{
|
|
8
|
+
type: z.ZodMiniLiteral<"user_canceled">;
|
|
9
|
+
}, z.core.$strip>], "type">;
|
|
10
|
+
/**
|
|
11
|
+
* A marker emitted from the Agent event stream to
|
|
12
|
+
* track when the Agent has completed its turn.
|
|
13
|
+
*/
|
|
14
|
+
export declare class AgentEndTurn {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly reason: z.input<typeof endTurnReasonSchema>;
|
|
17
|
+
constructor(reason: AgentEndTurn["reason"], id?: string);
|
|
18
|
+
toJSON(): {
|
|
19
|
+
id: string;
|
|
20
|
+
reason: {
|
|
21
|
+
error: unknown;
|
|
22
|
+
type: "error";
|
|
23
|
+
} | {
|
|
24
|
+
type: "reply_finished";
|
|
25
|
+
} | {
|
|
26
|
+
type: "user_canceled";
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
static fromJSON(data: unknown): AgentEndTurn;
|
|
30
|
+
static codec: z.ZodMiniCodec<z.ZodMiniObject<{
|
|
31
|
+
id: z.ZodMiniString<string>;
|
|
32
|
+
reason: z.ZodMiniDiscriminatedUnion<[z.ZodMiniObject<{
|
|
33
|
+
error: z.ZodMiniUnknown;
|
|
34
|
+
type: z.ZodMiniLiteral<"error">;
|
|
35
|
+
}, z.core.$strip>, z.ZodMiniObject<{
|
|
36
|
+
type: z.ZodMiniLiteral<"reply_finished">;
|
|
37
|
+
}, z.core.$strip>, z.ZodMiniObject<{
|
|
38
|
+
type: z.ZodMiniLiteral<"user_canceled">;
|
|
39
|
+
}, z.core.$strip>], "type">;
|
|
40
|
+
}, z.core.$strip>, z.ZodMiniCustom<AgentEndTurn, AgentEndTurn>>;
|
|
41
|
+
}
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2024-2025 Dremio Corporation
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { nanoid } from "nanoid/non-secure";
|
|
17
|
+
import * as z from "zod/mini";
|
|
18
|
+
const endTurnReasonSchema = z.discriminatedUnion("type", [
|
|
19
|
+
z.object({ error: z.unknown(), type: z.literal("error") }),
|
|
20
|
+
z.object({ type: z.literal("reply_finished") }),
|
|
21
|
+
z.object({ type: z.literal("user_canceled") }),
|
|
22
|
+
]);
|
|
23
|
+
/**
|
|
24
|
+
* A marker emitted from the Agent event stream to
|
|
25
|
+
* track when the Agent has completed its turn.
|
|
26
|
+
*/
|
|
27
|
+
export class AgentEndTurn {
|
|
28
|
+
id;
|
|
29
|
+
reason;
|
|
30
|
+
constructor(reason, id = nanoid()) {
|
|
31
|
+
this.reason = reason;
|
|
32
|
+
this.id = id;
|
|
33
|
+
}
|
|
34
|
+
toJSON() {
|
|
35
|
+
return z.encode(AgentEndTurn.codec, this);
|
|
36
|
+
}
|
|
37
|
+
static fromJSON(data) {
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
39
|
+
return z.decode(AgentEndTurn.codec, data);
|
|
40
|
+
}
|
|
41
|
+
static codec = z.codec(z.object({
|
|
42
|
+
id: z.string(),
|
|
43
|
+
reason: endTurnReasonSchema,
|
|
44
|
+
}), z.instanceof(AgentEndTurn), {
|
|
45
|
+
decode(v) {
|
|
46
|
+
return new AgentEndTurn(v.reason, v.id);
|
|
47
|
+
},
|
|
48
|
+
encode(v) {
|
|
49
|
+
return {
|
|
50
|
+
id: v.id,
|
|
51
|
+
reason: v.reason,
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=AgentEndTurn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentEndTurn.js","sourceRoot":"","sources":["../../../../../src/enterprise/ai/chat/eventWrappers/AgentEndTurn.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B,MAAM,mBAAmB,GAAG,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE;IACvD,CAAC,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;IAC1D,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAC;IAC/C,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,CAAC;CAC/C,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,OAAO,YAAY;IACd,EAAE,CAAC;IACH,MAAM,CAAsC;IAErD,YAAY,MAA8B,EAAE,EAAE,GAAG,MAAM,EAAE;QACvD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACf,CAAC;IAED,MAAM;QACJ,OAAO,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,IAAa;QAC3B,qGAAqG;QACrG,OAAO,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,IAAW,CAAC,CAAC;IACnD,CAAC;IAED,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CACpB,CAAC,CAAC,MAAM,CAAC;QACP,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;QACd,MAAM,EAAE,mBAAmB;KAC5B,CAAC,EACF,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC,EAC1B;QACE,MAAM,CAAC,CAAC;YACN,OAAO,IAAI,YAAY,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;QAC1C,CAAC;QACD,MAAM,CAAC,CAAC;YACN,OAAO;gBACL,EAAE,EAAE,CAAC,CAAC,EAAE;gBACR,MAAM,EAAE,CAAC,CAAC,MAAM;aACR,CAAC;QACb,CAAC;KACF,CACF,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { nanoid } from \"nanoid/non-secure\";\nimport * as z from \"zod/mini\";\n\nconst endTurnReasonSchema = z.discriminatedUnion(\"type\", [\n z.object({ error: z.unknown(), type: z.literal(\"error\") }),\n z.object({ type: z.literal(\"reply_finished\") }),\n z.object({ type: z.literal(\"user_canceled\") }),\n]);\n\n/**\n * A marker emitted from the Agent event stream to\n * track when the Agent has completed its turn.\n */\nexport class AgentEndTurn {\n readonly id;\n readonly reason: z.input<typeof endTurnReasonSchema>;\n\n constructor(reason: AgentEndTurn[\"reason\"], id = nanoid()) {\n this.reason = reason;\n this.id = id;\n }\n\n toJSON() {\n return z.encode(AgentEndTurn.codec, this);\n }\n\n static fromJSON(data: unknown) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any\n return z.decode(AgentEndTurn.codec, data as any);\n }\n\n static codec = z.codec(\n z.object({\n id: z.string(),\n reason: endTurnReasonSchema,\n }),\n z.instanceof(AgentEndTurn),\n {\n decode(v) {\n return new AgentEndTurn(v.reason, v.id);\n },\n encode(v) {\n return {\n id: v.id,\n reason: v.reason,\n } as const;\n },\n },\n );\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AgentChatResponse, AgentToolRequestResponseContent, AgentToolResultResponseContent } from "@dremio/js-sdk/enterprise";
|
|
2
|
+
/**
|
|
3
|
+
* Pairs a tool request with its associated tool result once completed.
|
|
4
|
+
*/
|
|
5
|
+
export declare class AgentToolCall {
|
|
6
|
+
readonly request: AgentChatResponse<AgentToolRequestResponseContent>;
|
|
7
|
+
readonly result?: AgentChatResponse<AgentToolResultResponseContent>;
|
|
8
|
+
constructor(request: AgentToolCall["request"], result?: AgentToolCall["result"]);
|
|
9
|
+
get id(): string;
|
|
10
|
+
get status(): "success" | "error" | "pending";
|
|
11
|
+
get isError(): boolean;
|
|
12
|
+
get isPending(): boolean;
|
|
13
|
+
get isSuccess(): boolean;
|
|
14
|
+
withResult(response: AgentChatResponse<AgentToolResultResponseContent>): AgentToolCall;
|
|
15
|
+
toJSON(): unknown;
|
|
16
|
+
}
|
|
17
|
+
export declare function isToolRequest(message: unknown): message is AgentChatResponse<AgentToolRequestResponseContent>;
|
|
18
|
+
export declare function isToolResult(message: unknown): message is AgentChatResponse<AgentToolResultResponseContent>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2024-2025 Dremio Corporation
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { AgentChatResponse, AgentToolRequestResponseContent, AgentToolResultResponseContent, } from "@dremio/js-sdk/enterprise";
|
|
17
|
+
/**
|
|
18
|
+
* Pairs a tool request with its associated tool result once completed.
|
|
19
|
+
*/
|
|
20
|
+
export class AgentToolCall {
|
|
21
|
+
request;
|
|
22
|
+
result;
|
|
23
|
+
constructor(request, result) {
|
|
24
|
+
this.request = request;
|
|
25
|
+
this.result = result;
|
|
26
|
+
}
|
|
27
|
+
get id() {
|
|
28
|
+
return this.request.content.callId;
|
|
29
|
+
}
|
|
30
|
+
get status() {
|
|
31
|
+
if (!this.result) {
|
|
32
|
+
return "pending";
|
|
33
|
+
}
|
|
34
|
+
if ("errorMessage" in this.result.content.result) {
|
|
35
|
+
return "error";
|
|
36
|
+
}
|
|
37
|
+
return "success";
|
|
38
|
+
}
|
|
39
|
+
get isError() {
|
|
40
|
+
return this.status === "error";
|
|
41
|
+
}
|
|
42
|
+
get isPending() {
|
|
43
|
+
return this.status === "pending";
|
|
44
|
+
}
|
|
45
|
+
get isSuccess() {
|
|
46
|
+
return this.status === "success";
|
|
47
|
+
}
|
|
48
|
+
withResult(response) {
|
|
49
|
+
return new AgentToolCall(this.request, response);
|
|
50
|
+
}
|
|
51
|
+
toJSON() {
|
|
52
|
+
return {
|
|
53
|
+
id: this.id,
|
|
54
|
+
request: this.request.toJSON(),
|
|
55
|
+
result: this.result?.toJSON(),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export function isToolRequest(message) {
|
|
60
|
+
return (message instanceof AgentChatResponse &&
|
|
61
|
+
message.content instanceof AgentToolRequestResponseContent);
|
|
62
|
+
}
|
|
63
|
+
export function isToolResult(message) {
|
|
64
|
+
return (message instanceof AgentChatResponse &&
|
|
65
|
+
message.content instanceof AgentToolResultResponseContent);
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=AgentToolCall.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentToolCall.js","sourceRoot":"","sources":["../../../../../src/enterprise/ai/chat/eventWrappers/AgentToolCall.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,iBAAiB,EACjB,+BAA+B,EAC/B,8BAA8B,GAC/B,MAAM,2BAA2B,CAAC;AAEnC;;GAEG;AACH,MAAM,OAAO,aAAa;IACf,OAAO,CAAqD;IAC5D,MAAM,CAAqD;IAEpE,YAAY,OAAiC,EAAE,MAAgC;QAC7E,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC;IACrC,CAAC;IAED,IAAI,MAAM;QACR,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,IAAI,cAAc,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;YACjD,OAAO,OAAO,CAAC;QACjB,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,MAAM,KAAK,OAAO,CAAC;IACjC,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC;IACnC,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC;IACnC,CAAC;IAED,UAAU,CAAC,QAA2D;QACpE,OAAO,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACnD,CAAC;IAED,MAAM;QACJ,OAAO;YACL,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YAC9B,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE;SACnB,CAAC;IACf,CAAC;CACF;AAED,MAAM,UAAU,aAAa,CAC3B,OAAgB;IAEhB,OAAO,CACL,OAAO,YAAY,iBAAiB;QACpC,OAAO,CAAC,OAAO,YAAY,+BAA+B,CAC3D,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,YAAY,CAC1B,OAAgB;IAEhB,OAAO,CACL,OAAO,YAAY,iBAAiB;QACpC,OAAO,CAAC,OAAO,YAAY,8BAA8B,CAC1D,CAAC;AACJ,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n AgentChatResponse,\n AgentToolRequestResponseContent,\n AgentToolResultResponseContent,\n} from \"@dremio/js-sdk/enterprise\";\n\n/**\n * Pairs a tool request with its associated tool result once completed.\n */\nexport class AgentToolCall {\n readonly request: AgentChatResponse<AgentToolRequestResponseContent>;\n readonly result?: AgentChatResponse<AgentToolResultResponseContent>;\n\n constructor(request: AgentToolCall[\"request\"], result?: AgentToolCall[\"result\"]) {\n this.request = request;\n this.result = result;\n }\n\n get id() {\n return this.request.content.callId;\n }\n\n get status() {\n if (!this.result) {\n return \"pending\";\n }\n\n if (\"errorMessage\" in this.result.content.result) {\n return \"error\";\n }\n\n return \"success\";\n }\n\n get isError() {\n return this.status === \"error\";\n }\n\n get isPending() {\n return this.status === \"pending\";\n }\n\n get isSuccess() {\n return this.status === \"success\";\n }\n\n withResult(response: AgentChatResponse<AgentToolResultResponseContent>) {\n return new AgentToolCall(this.request, response);\n }\n\n toJSON() {\n return {\n id: this.id,\n request: this.request.toJSON(),\n result: this.result?.toJSON(),\n } as unknown;\n }\n}\n\nexport function isToolRequest(\n message: unknown,\n): message is AgentChatResponse<AgentToolRequestResponseContent> {\n return (\n message instanceof AgentChatResponse &&\n message.content instanceof AgentToolRequestResponseContent\n );\n}\n\nexport function isToolResult(\n message: unknown,\n): message is AgentChatResponse<AgentToolResultResponseContent> {\n return (\n message instanceof AgentChatResponse &&\n message.content instanceof AgentToolResultResponseContent\n );\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AgentToolCall } from "./AgentToolCall.ts";
|
|
2
|
+
import type { AgentChatResponse, AgentToolRequestResponseContent, AgentToolResultResponseContent } from "@dremio/js-sdk/enterprise";
|
|
3
|
+
/**
|
|
4
|
+
* Contains a collection of `AgentToolCall` associated with an `AgentChatExchange`.
|
|
5
|
+
* As tool calls stream in, this class is updated immutably but maintains
|
|
6
|
+
* a stable `.id` property.
|
|
7
|
+
*/
|
|
8
|
+
export declare class AgentToolCallGroup {
|
|
9
|
+
readonly id: string;
|
|
10
|
+
readonly toolCalls: AgentToolCall[];
|
|
11
|
+
constructor(toolCalls: AgentToolCallGroup["toolCalls"], id?: AgentToolCallGroup["id"]);
|
|
12
|
+
addRequest(toolRequest: AgentChatResponse<AgentToolRequestResponseContent>): AgentToolCallGroup;
|
|
13
|
+
addResult(toolResult: AgentChatResponse<AgentToolResultResponseContent>): AgentToolCallGroup;
|
|
14
|
+
toJSON(): {
|
|
15
|
+
id: string;
|
|
16
|
+
toolCalls: unknown[];
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2024-2025 Dremio Corporation
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { nanoid } from "nanoid/non-secure";
|
|
17
|
+
import { AgentToolCall } from "./AgentToolCall.js";
|
|
18
|
+
/**
|
|
19
|
+
* Contains a collection of `AgentToolCall` associated with an `AgentChatExchange`.
|
|
20
|
+
* As tool calls stream in, this class is updated immutably but maintains
|
|
21
|
+
* a stable `.id` property.
|
|
22
|
+
*/
|
|
23
|
+
export class AgentToolCallGroup {
|
|
24
|
+
id = nanoid();
|
|
25
|
+
toolCalls;
|
|
26
|
+
constructor(toolCalls, id) {
|
|
27
|
+
this.toolCalls = toolCalls;
|
|
28
|
+
if (id) {
|
|
29
|
+
this.id = id;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
addRequest(toolRequest) {
|
|
33
|
+
return new AgentToolCallGroup([...this.toolCalls, new AgentToolCall(toolRequest)], this.id);
|
|
34
|
+
}
|
|
35
|
+
addResult(toolResult) {
|
|
36
|
+
const requestIndex = this.toolCalls.findLastIndex((toolCall) => toolCall.id === toolResult.content.callId);
|
|
37
|
+
if (requestIndex === -1) {
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
const toolCall = this.toolCalls.at(requestIndex);
|
|
41
|
+
return new AgentToolCallGroup([
|
|
42
|
+
...this.toolCalls.slice(0, requestIndex),
|
|
43
|
+
toolCall.withResult(toolResult),
|
|
44
|
+
...this.toolCalls.slice(requestIndex + 1),
|
|
45
|
+
]);
|
|
46
|
+
}
|
|
47
|
+
toJSON() {
|
|
48
|
+
return {
|
|
49
|
+
id: this.id,
|
|
50
|
+
toolCalls: this.toolCalls.map((toolCall) => toolCall.toJSON()),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=AgentToolCallGroup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentToolCallGroup.js","sourceRoot":"","sources":["../../../../../src/enterprise/ai/chat/eventWrappers/AgentToolCallGroup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAOnD;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IACpB,EAAE,GAAG,MAAM,EAAE,CAAC;IACd,SAAS,CAAkB;IAEpC,YAAY,SAA0C,EAAE,EAA6B;QACnF,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,EAAE,EAAE,CAAC;YACP,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACf,CAAC;IACH,CAAC;IAED,UAAU,CAAC,WAA+D;QACxE,OAAO,IAAI,kBAAkB,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,EAAE,IAAI,aAAa,CAAC,WAAW,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;IAC9F,CAAC;IAED,SAAS,CAAC,UAA6D;QACrE,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAC/C,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,KAAK,UAAU,CAAC,OAAO,CAAC,MAAM,CACxD,CAAC;QAEF,IAAI,YAAY,KAAK,CAAC,CAAC,EAAE,CAAC;YACxB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,YAAY,CAAE,CAAC;QAElD,OAAO,IAAI,kBAAkB,CAAC;YAC5B,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,YAAY,CAAC;YACxC,QAAQ,CAAC,UAAU,CAAC,UAAU,CAAC;YAC/B,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,YAAY,GAAG,CAAC,CAAC;SAC1C,CAAC,CAAC;IACL,CAAC;IAED,MAAM;QACJ,OAAO;YACL,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;SAC/D,CAAC;IACJ,CAAC;CACF","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { nanoid } from \"nanoid/non-secure\";\nimport { AgentToolCall } from \"./AgentToolCall.ts\";\nimport type {\n AgentChatResponse,\n AgentToolRequestResponseContent,\n AgentToolResultResponseContent,\n} from \"@dremio/js-sdk/enterprise\";\n\n/**\n * Contains a collection of `AgentToolCall` associated with an `AgentChatExchange`.\n * As tool calls stream in, this class is updated immutably but maintains\n * a stable `.id` property.\n */\nexport class AgentToolCallGroup {\n readonly id = nanoid();\n readonly toolCalls: AgentToolCall[];\n\n constructor(toolCalls: AgentToolCallGroup[\"toolCalls\"], id?: AgentToolCallGroup[\"id\"]) {\n this.toolCalls = toolCalls;\n if (id) {\n this.id = id;\n }\n }\n\n addRequest(toolRequest: AgentChatResponse<AgentToolRequestResponseContent>) {\n return new AgentToolCallGroup([...this.toolCalls, new AgentToolCall(toolRequest)], this.id);\n }\n\n addResult(toolResult: AgentChatResponse<AgentToolResultResponseContent>) {\n const requestIndex = this.toolCalls.findLastIndex(\n (toolCall) => toolCall.id === toolResult.content.callId,\n );\n\n if (requestIndex === -1) {\n return this;\n }\n\n const toolCall = this.toolCalls.at(requestIndex)!;\n\n return new AgentToolCallGroup([\n ...this.toolCalls.slice(0, requestIndex),\n toolCall.withResult(toolResult),\n ...this.toolCalls.slice(requestIndex + 1),\n ]);\n }\n\n toJSON() {\n return {\n id: this.id,\n toolCalls: this.toolCalls.map((toolCall) => toolCall.toJSON()),\n };\n }\n}\n"]}
|