@dremio/js-sdk 0.31.8 → 0.32.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/cloud/Dremio.d.ts +3 -2
- package/dist/cloud/Dremio.js +2 -2
- package/dist/cloud/Dremio.js.map +1 -1
- package/dist/cloud/ai/AIResource.d.ts +125 -0
- package/dist/cloud/ai/AIResource.js +113 -0
- package/dist/cloud/ai/AIResource.js.map +1 -0
- package/dist/cloud/ai/DremioModelProvider.d.ts +12 -0
- package/dist/cloud/ai/DremioModelProvider.js +49 -0
- package/dist/cloud/ai/DremioModelProvider.js.map +1 -0
- package/dist/cloud/ai/index.d.ts +4 -0
- package/dist/cloud/ai/index.js +20 -0
- package/dist/cloud/ai/index.js.map +1 -0
- package/dist/cloud/ai/modelProviderCodec.d.ts +180 -0
- package/dist/cloud/ai/modelProviderCodec.js +54 -0
- package/dist/cloud/ai/modelProviderCodec.js.map +1 -0
- package/dist/cloud/catalog/EnterpriseCatalogResource.d.ts +10 -3
- package/dist/cloud/catalog/EnterpriseCatalogResource.js +38 -0
- package/dist/cloud/catalog/EnterpriseCatalogResource.js.map +1 -1
- package/dist/cloud/catalog/FileUpload.d.ts +117 -0
- package/dist/cloud/catalog/FileUpload.js +103 -0
- package/dist/cloud/catalog/FileUpload.js.map +1 -0
- package/dist/cloud/getResourceConfig.d.ts +1 -0
- package/dist/cloud/getResourceConfig.js +3 -0
- package/dist/cloud/getResourceConfig.js.map +1 -1
- package/dist/cloud/interfaces.d.ts +3 -1
- package/dist/cloud/interfaces.js +3 -1
- package/dist/cloud/interfaces.js.map +1 -1
- package/dist/cloud/organizations/Organization.d.ts +10 -0
- package/dist/cloud/organizations/Organization.js +12 -0
- package/dist/cloud/organizations/Organization.js.map +1 -1
- package/dist/cloud/projects/Project.d.ts +1 -0
- package/dist/cloud/projects/Project.js +2 -0
- package/dist/cloud/projects/Project.js.map +1 -1
- package/dist/cloud/projects/projectPropertiesCodec.d.ts +6 -0
- package/dist/cloud/projects/projectPropertiesCodec.js +1 -0
- package/dist/cloud/projects/projectPropertiesCodec.js.map +1 -1
- package/dist/cloud/replaceOriginResource.js +6 -1
- package/dist/cloud/replaceOriginResource.js.map +1 -1
- package/dist/common/Config.d.ts +14 -0
- package/dist/common/Config.js.map +1 -1
- package/dist/common/createRequest.d.ts +1 -0
- package/dist/common/createRequest.js +1 -1
- package/dist/common/createRequest.js.map +1 -1
- package/dist/common/createXHR.d.ts +2 -0
- package/dist/common/createXHR.js +58 -0
- package/dist/common/createXHR.js.map +1 -0
- package/dist/enterprise/Dremio.d.ts +3 -1
- package/dist/enterprise/Dremio.js +3 -0
- package/dist/enterprise/Dremio.js.map +1 -1
- package/dist/enterprise/ai/AIResource.d.ts +118 -0
- package/dist/enterprise/ai/AIResource.js +123 -0
- package/dist/enterprise/ai/AIResource.js.map +1 -0
- package/dist/enterprise/ai/ModelProvider.d.ts +181 -0
- package/dist/enterprise/ai/ModelProvider.js +87 -0
- package/dist/enterprise/ai/ModelProvider.js.map +1 -0
- package/dist/enterprise/ai/chat/AgentChatPartialResponse.d.ts +42 -0
- package/dist/enterprise/ai/chat/AgentChatPartialResponse.js +65 -0
- package/dist/enterprise/ai/chat/AgentChatPartialResponse.js.map +1 -0
- package/dist/enterprise/ai/chat/AgentChatResponse.d.ts +87 -0
- package/dist/enterprise/ai/chat/AgentChatResponse.js +138 -0
- package/dist/enterprise/ai/chat/AgentChatResponse.js.map +1 -0
- package/dist/enterprise/ai/chat/AgentErrorResponseContent.d.ts +4 -0
- package/dist/enterprise/ai/chat/AgentErrorResponseContent.js +22 -0
- package/dist/enterprise/ai/chat/AgentErrorResponseContent.js.map +1 -0
- package/dist/enterprise/ai/chat/AgentModelResponseContent.d.ts +6 -0
- package/dist/enterprise/ai/chat/AgentModelResponseContent.js +24 -0
- package/dist/enterprise/ai/chat/AgentModelResponseContent.js.map +1 -0
- package/dist/enterprise/ai/chat/AgentToolRequestResponseContent.d.ts +9 -0
- package/dist/enterprise/ai/chat/AgentToolRequestResponseContent.js +35 -0
- package/dist/enterprise/ai/chat/AgentToolRequestResponseContent.js.map +1 -0
- package/dist/enterprise/ai/chat/AgentToolResultResponseContent.d.ts +8 -0
- package/dist/enterprise/ai/chat/AgentToolResultResponseContent.js +31 -0
- package/dist/enterprise/ai/chat/AgentToolResultResponseContent.js.map +1 -0
- package/dist/enterprise/ai/chat/ChatSession.d.ts +32 -0
- package/dist/enterprise/ai/chat/ChatSession.js +77 -0
- package/dist/enterprise/ai/chat/ChatSession.js.map +1 -0
- package/dist/enterprise/ai/chat/UserChatMessage.d.ts +30 -0
- package/dist/enterprise/ai/chat/UserChatMessage.js +68 -0
- package/dist/enterprise/ai/chat/UserChatMessage.js.map +1 -0
- package/dist/enterprise/ai/chat/UserChatMessageContent.d.ts +19 -0
- package/dist/enterprise/ai/chat/UserChatMessageContent.js +44 -0
- package/dist/enterprise/ai/chat/UserChatMessageContent.js.map +1 -0
- package/dist/enterprise/ai/chat/chatEventSchema.d.ts +35 -0
- package/dist/enterprise/ai/chat/chatEventSchema.js +52 -0
- package/dist/enterprise/ai/chat/chatEventSchema.js.map +1 -0
- package/dist/enterprise/ai/chat/index.d.ts +9 -0
- package/dist/enterprise/ai/chat/index.js +25 -0
- package/dist/enterprise/ai/chat/index.js.map +1 -0
- package/dist/enterprise/ai/index.d.ts +3 -0
- package/dist/enterprise/ai/index.js +19 -0
- package/dist/enterprise/ai/index.js.map +1 -0
- package/dist/enterprise/ai/modelProviderCodec.d.ts +465 -0
- package/dist/enterprise/ai/modelProviderCodec.js +154 -0
- package/dist/enterprise/ai/modelProviderCodec.js.map +1 -0
- package/dist/enterprise/ai/modelProviderConfigSchemas.d.ts +296 -0
- package/dist/enterprise/ai/modelProviderConfigSchemas.js +159 -0
- package/dist/enterprise/ai/modelProviderConfigSchemas.js.map +1 -0
- package/dist/enterprise/interfaces.d.ts +1 -0
- package/dist/enterprise/interfaces.js +1 -0
- package/dist/enterprise/interfaces.js.map +1 -1
- package/dist/enterprise/users/EnterpriseUsersResource.d.ts +7 -0
- package/dist/enterprise/users/EnterpriseUsersResource.js +31 -0
- package/dist/enterprise/users/EnterpriseUsersResource.js.map +1 -1
- package/dist/enterprise/users/ServiceUser.d.ts +85 -0
- package/dist/enterprise/users/ServiceUser.js +79 -0
- package/dist/enterprise/users/ServiceUser.js.map +1 -0
- package/dist/enterprise/users/serviceUserOauthCredentialsCodec.d.ts +43 -0
- package/dist/enterprise/users/serviceUserOauthCredentialsCodec.js +110 -0
- package/dist/enterprise/users/serviceUserOauthCredentialsCodec.js.map +1 -0
- package/package.json +1 -1
- package/dist/cloud/ai/AiResource.d.ts +0 -12
- package/dist/cloud/ai/AiResource.js +0 -52
- package/dist/cloud/ai/AiResource.js.map +0 -1
|
@@ -0,0 +1,138 @@
|
|
|
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 { AgentErrorResponseContent } from "./AgentErrorResponseContent.js";
|
|
18
|
+
import { AgentModelResponseContent } from "./AgentModelResponseContent.js";
|
|
19
|
+
import { AgentToolRequestResponseContent } from "./AgentToolRequestResponseContent.js";
|
|
20
|
+
import { AgentToolResultResponseContent } from "./AgentToolResultResponseContent.js";
|
|
21
|
+
import { ChatSession } from "./ChatSession.js";
|
|
22
|
+
import * as z from "zod/mini";
|
|
23
|
+
import { Temporal } from "temporal-polyfill";
|
|
24
|
+
import { chatEventSchema } from "./chatEventSchema.js";
|
|
25
|
+
export class AgentChatResponse {
|
|
26
|
+
createdAt = Temporal.Now.instant();
|
|
27
|
+
id = nanoid();
|
|
28
|
+
session;
|
|
29
|
+
content;
|
|
30
|
+
constructor(chatSession, content, createdAt, id) {
|
|
31
|
+
this.session = chatSession;
|
|
32
|
+
this.content = content;
|
|
33
|
+
if (createdAt) {
|
|
34
|
+
this.createdAt = createdAt;
|
|
35
|
+
}
|
|
36
|
+
if (id) {
|
|
37
|
+
this.id = id;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Creates a copy of the AgentResponse with a different content property.
|
|
42
|
+
* Preserves the original message's ID
|
|
43
|
+
*/
|
|
44
|
+
replaceContent(content) {
|
|
45
|
+
return new AgentChatResponse(this.session, content, this.createdAt, this.id);
|
|
46
|
+
}
|
|
47
|
+
toJSON() {
|
|
48
|
+
return z.encode(AgentChatResponse.codec, this);
|
|
49
|
+
}
|
|
50
|
+
static fromJSON(data) {
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
52
|
+
return z.decode(AgentChatResponse.codec, data);
|
|
53
|
+
}
|
|
54
|
+
static codec = z.codec(chatEventSchema, z.instanceof(AgentChatResponse), {
|
|
55
|
+
decode(chatEvent) {
|
|
56
|
+
const content = (() => {
|
|
57
|
+
switch (chatEvent.chunkType) {
|
|
58
|
+
case "error":
|
|
59
|
+
return new AgentErrorResponseContent(chatEvent.message);
|
|
60
|
+
case "model":
|
|
61
|
+
return new AgentModelResponseContent(chatEvent.name, chatEvent.result);
|
|
62
|
+
case "toolRequest": {
|
|
63
|
+
return new AgentToolRequestResponseContent(chatEvent.callId, chatEvent.name, Object.keys(chatEvent.arguments)
|
|
64
|
+
.sort()
|
|
65
|
+
.map((key) => chatEvent.arguments[key]), chatEvent.summarizedTitle || null, chatEvent.commentary || null);
|
|
66
|
+
}
|
|
67
|
+
case "toolResponse":
|
|
68
|
+
return new AgentToolResultResponseContent(chatEvent.callId, chatEvent.name, chatEvent.result);
|
|
69
|
+
}
|
|
70
|
+
})();
|
|
71
|
+
return new AgentChatResponse(new ChatSession({
|
|
72
|
+
...("modelName" in chatEvent && { modelName: chatEvent.modelName }),
|
|
73
|
+
...("modelProviderId" in chatEvent && {
|
|
74
|
+
modelProviderId: chatEvent.modelProviderId,
|
|
75
|
+
}),
|
|
76
|
+
...("sessionId" in chatEvent && {
|
|
77
|
+
sessionId: chatEvent.sessionId,
|
|
78
|
+
}),
|
|
79
|
+
}), content, "createdAt" in chatEvent
|
|
80
|
+
? Temporal.Instant.from(chatEvent.createdAt)
|
|
81
|
+
: Temporal.Now.instant());
|
|
82
|
+
},
|
|
83
|
+
encode(agentResponse) {
|
|
84
|
+
const createdAt = agentResponse.createdAt?.toString();
|
|
85
|
+
if (agentResponse.content instanceof AgentErrorResponseContent) {
|
|
86
|
+
return {
|
|
87
|
+
chunkType: "error",
|
|
88
|
+
...agentResponse.content,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
else if (agentResponse.content instanceof AgentModelResponseContent) {
|
|
92
|
+
return {
|
|
93
|
+
chunkType: "model",
|
|
94
|
+
createdAt: createdAt,
|
|
95
|
+
modelName: agentResponse.session.modelName || "",
|
|
96
|
+
modelProviderId: agentResponse.session.modelProviderId || "",
|
|
97
|
+
name: agentResponse.content.name,
|
|
98
|
+
result: agentResponse.content.result,
|
|
99
|
+
sessionId: agentResponse.session.sessionId,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
else if (agentResponse.content instanceof AgentToolRequestResponseContent) {
|
|
103
|
+
return {
|
|
104
|
+
arguments: agentResponse.content.arguments.reduce((accum, curr, i) => {
|
|
105
|
+
accum[`arg${i}`] = curr;
|
|
106
|
+
return accum;
|
|
107
|
+
}, {}),
|
|
108
|
+
callId: agentResponse.content.callId,
|
|
109
|
+
chunkType: "toolRequest",
|
|
110
|
+
commentary: agentResponse.content.commentary || undefined,
|
|
111
|
+
createdAt: createdAt,
|
|
112
|
+
modelName: agentResponse.session.modelName || "",
|
|
113
|
+
modelProviderId: agentResponse.session.modelProviderId || "",
|
|
114
|
+
name: agentResponse.content.name,
|
|
115
|
+
sessionId: agentResponse.session.sessionId,
|
|
116
|
+
summarizedTitle: agentResponse.content.summarizedTitle || undefined,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
else if (agentResponse.content instanceof AgentToolResultResponseContent) {
|
|
120
|
+
return {
|
|
121
|
+
callId: agentResponse.content.callId,
|
|
122
|
+
chunkType: "toolResponse",
|
|
123
|
+
commentary: agentResponse.content.commentary || undefined,
|
|
124
|
+
createdAt: createdAt,
|
|
125
|
+
modelName: agentResponse.session.modelName || "",
|
|
126
|
+
modelProviderId: agentResponse.session.modelProviderId || "",
|
|
127
|
+
name: agentResponse.content.name,
|
|
128
|
+
result: agentResponse.content.result,
|
|
129
|
+
sessionId: agentResponse.session.sessionId,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
throw new Error("Unknown content type");
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=AgentChatResponse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentChatResponse.js","sourceRoot":"","sources":["../../../../src/enterprise/ai/chat/AgentChatResponse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAC;AACvF,OAAO,EAA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CAAC,OAAO,CAAC,UAAU,IAAI,SAAS;oBACzD,SAAS,EAAE,SAAS;oBACpB,SAAS,EAAE,aAAa,CAAC,OAAO,CAAC,SAAS,IAAI,EAAE;oBAChD,eAAe,EAAE,aAAa,CAAC,OAAO,CAAC,eAAe,IAAI,EAAE;oBAC5D,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,IAAI;oBAChC,SAAS,EAAE,aAAa,CAAC,OAAO,CAAC,SAAU;oBAC3C,eAAe,EAAE,aAAa,CAAC,OAAO,CAAC,eAAe,IAAI,SAAS;iBACvC,CAAC;YACjC,CAAC;iBAAM,IAAI,aAAa,CAAC,OAAO,YAAY,8BAA8B,EAAE,CAAC;gBAC3E,OAAO;oBACL,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,MAAM;oBACpC,SAAS,EAAE,cAAc;oBACzB,UAAU,EAAE,aAAa,CAAC,OAAO,CAAC,UAAU,IAAI,SAAS;oBACzD,SAAS,EAAE,SAAS;oBACpB,SAAS,EAAE,aAAa,CAAC,OAAO,CAAC,SAAS,IAAI,EAAE;oBAChD,eAAe,EAAE,aAAa,CAAC,OAAO,CAAC,eAAe,IAAI,EAAE;oBAC5D,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,IAAI;oBAChC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,MAAM;oBACpC,SAAS,EAAE,aAAa,CAAC,OAAO,CAAC,SAAU;iBACf,CAAC;YACjC,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;YAC1C,CAAC;QACH,CAAC;KACF,CAAC,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 { AgentErrorResponseContent } from \"./AgentErrorResponseContent.ts\";\nimport { AgentModelResponseContent } from \"./AgentModelResponseContent.ts\";\nimport { AgentToolRequestResponseContent } from \"./AgentToolRequestResponseContent.ts\";\nimport { AgentToolResultResponseContent } from \"./AgentToolResultResponseContent.ts\";\nimport { ChatSession } from \"./ChatSession.ts\";\nimport * as z from \"zod/mini\";\nimport { Temporal } from \"temporal-polyfill\";\nimport { chatEventSchema, type ChatEvent } from \"./chatEventSchema.ts\";\n\nexport class AgentChatResponse<T extends AgentResponseContent> {\n readonly createdAt = Temporal.Now.instant();\n readonly id = nanoid();\n readonly session: ChatSession;\n readonly content: T;\n\n constructor(chatSession: ChatSession, content: T, createdAt?: Temporal.Instant, id?: string) {\n this.session = chatSession;\n this.content = content;\n\n if (createdAt) {\n this.createdAt = createdAt;\n }\n\n if (id) {\n this.id = id;\n }\n }\n\n /**\n * Creates a copy of the AgentResponse with a different content property.\n * Preserves the original message's ID\n */\n replaceContent<R extends AgentResponseContent>(content: R): AgentChatResponse<R> {\n return new AgentChatResponse(this.session, content, this.createdAt, this.id);\n }\n\n toJSON() {\n return z.encode(AgentChatResponse.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(AgentChatResponse.codec, data as any);\n }\n\n static codec = z.codec(chatEventSchema, z.instanceof(AgentChatResponse), {\n decode(chatEvent) {\n const content = (() => {\n switch (chatEvent.chunkType) {\n case \"error\":\n return new AgentErrorResponseContent(chatEvent.message);\n case \"model\":\n return new AgentModelResponseContent(chatEvent.name, chatEvent.result);\n case \"toolRequest\": {\n return new AgentToolRequestResponseContent(\n chatEvent.callId,\n chatEvent.name,\n Object.keys(chatEvent.arguments)\n .sort()\n .map((key) => chatEvent.arguments[key]!),\n chatEvent.summarizedTitle || null,\n chatEvent.commentary || null,\n );\n }\n case \"toolResponse\":\n return new AgentToolResultResponseContent(\n chatEvent.callId,\n chatEvent.name,\n chatEvent.result,\n );\n }\n })();\n return new AgentChatResponse(\n new ChatSession({\n ...(\"modelName\" in chatEvent && { modelName: chatEvent.modelName }),\n ...(\"modelProviderId\" in chatEvent && {\n modelProviderId: chatEvent.modelProviderId,\n }),\n ...(\"sessionId\" in chatEvent && {\n sessionId: chatEvent.sessionId,\n }),\n }),\n content,\n \"createdAt\" in chatEvent\n ? Temporal.Instant.from(chatEvent.createdAt)\n : Temporal.Now.instant(),\n );\n },\n encode(agentResponse) {\n const createdAt = agentResponse.createdAt?.toString();\n\n if (agentResponse.content instanceof AgentErrorResponseContent) {\n return {\n chunkType: \"error\",\n ...agentResponse.content,\n } as const satisfies ChatEvent;\n } else if (agentResponse.content instanceof AgentModelResponseContent) {\n return {\n chunkType: \"model\",\n createdAt: createdAt,\n modelName: agentResponse.session.modelName || \"\",\n modelProviderId: agentResponse.session.modelProviderId || \"\",\n name: agentResponse.content.name,\n result: agentResponse.content.result,\n sessionId: agentResponse.session.sessionId!,\n } as const satisfies ChatEvent;\n } else if (agentResponse.content instanceof AgentToolRequestResponseContent) {\n return {\n arguments: agentResponse.content.arguments.reduce(\n (accum, curr, i) => {\n accum[`arg${i}`] = curr;\n return accum;\n },\n {} as Record<string, unknown>,\n ) as Record<string, z.core.util.JSONType>,\n callId: agentResponse.content.callId,\n chunkType: \"toolRequest\",\n commentary: agentResponse.content.commentary || undefined,\n createdAt: createdAt,\n modelName: agentResponse.session.modelName || \"\",\n modelProviderId: agentResponse.session.modelProviderId || \"\",\n name: agentResponse.content.name,\n sessionId: agentResponse.session.sessionId!,\n summarizedTitle: agentResponse.content.summarizedTitle || undefined,\n } as const satisfies ChatEvent;\n } else if (agentResponse.content instanceof AgentToolResultResponseContent) {\n return {\n callId: agentResponse.content.callId,\n chunkType: \"toolResponse\",\n commentary: agentResponse.content.commentary || undefined,\n createdAt: createdAt,\n modelName: agentResponse.session.modelName || \"\",\n modelProviderId: agentResponse.session.modelProviderId || \"\",\n name: agentResponse.content.name,\n result: agentResponse.content.result,\n sessionId: agentResponse.session.sessionId!,\n } as const satisfies ChatEvent;\n } else {\n throw new Error(\"Unknown content type\");\n }\n },\n });\n}\n\nexport type AgentResponseContent =\n | AgentErrorResponseContent\n | AgentModelResponseContent\n | AgentToolRequestResponseContent\n | AgentToolResultResponseContent;\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
export class AgentErrorResponseContent {
|
|
17
|
+
message;
|
|
18
|
+
constructor(message) {
|
|
19
|
+
this.message = message;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=AgentErrorResponseContent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentErrorResponseContent.js","sourceRoot":"","sources":["../../../../src/enterprise/ai/chat/AgentErrorResponseContent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,OAAO,yBAAyB;IAC3B,OAAO,CAAS;IAEzB,YAAY,OAA6C;QACvD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,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\nexport class AgentErrorResponseContent {\n readonly message: string;\n\n constructor(message: AgentErrorResponseContent[\"message\"]) {\n this.message = message;\n }\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { z } from "zod/mini";
|
|
2
|
+
export declare class AgentModelResponseContent<N extends string = string, R extends Record<string, z.core.util.JSONType> = Record<string, z.core.util.JSONType>> {
|
|
3
|
+
readonly name: N;
|
|
4
|
+
readonly result: R;
|
|
5
|
+
constructor(name: N, result: R);
|
|
6
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
export class AgentModelResponseContent {
|
|
17
|
+
name;
|
|
18
|
+
result;
|
|
19
|
+
constructor(name, result) {
|
|
20
|
+
this.name = name;
|
|
21
|
+
this.result = result;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=AgentModelResponseContent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentModelResponseContent.js","sourceRoot":"","sources":["../../../../src/enterprise/ai/chat/AgentModelResponseContent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,MAAM,OAAO,yBAAyB;IAI3B,IAAI,CAAI;IACR,MAAM,CAAI;IAEnB,YAAY,IAAO,EAAE,MAAS;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,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 type { z } from \"zod/mini\";\n\nexport class AgentModelResponseContent<\n N extends string = string,\n R extends Record<string, z.core.util.JSONType> = Record<string, z.core.util.JSONType>,\n> {\n readonly name: N;\n readonly result: R;\n\n constructor(name: N, result: R) {\n this.name = name;\n this.result = result;\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as z from "zod/mini";
|
|
2
|
+
export declare class AgentToolRequestResponseContent {
|
|
3
|
+
readonly arguments: z.core.util.JSONType[];
|
|
4
|
+
readonly callId: string;
|
|
5
|
+
readonly commentary: string | null;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly summarizedTitle: string | null;
|
|
8
|
+
constructor(callId: AgentToolRequestResponseContent["callId"], name: AgentToolRequestResponseContent["name"], toolArguments: AgentToolRequestResponseContent["arguments"], summarizedTitle: AgentToolRequestResponseContent["summarizedTitle"], commentary: AgentToolRequestResponseContent["commentary"]);
|
|
9
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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 * as z from "zod/mini";
|
|
17
|
+
export class AgentToolRequestResponseContent {
|
|
18
|
+
arguments;
|
|
19
|
+
callId;
|
|
20
|
+
commentary = null;
|
|
21
|
+
name;
|
|
22
|
+
summarizedTitle = null;
|
|
23
|
+
constructor(callId, name, toolArguments, summarizedTitle, commentary) {
|
|
24
|
+
this.callId = callId;
|
|
25
|
+
this.name = name;
|
|
26
|
+
this.arguments = toolArguments;
|
|
27
|
+
if (summarizedTitle) {
|
|
28
|
+
this.summarizedTitle = summarizedTitle;
|
|
29
|
+
}
|
|
30
|
+
if (commentary) {
|
|
31
|
+
this.commentary = commentary;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=AgentToolRequestResponseContent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentToolRequestResponseContent.js","sourceRoot":"","sources":["../../../../src/enterprise/ai/chat/AgentToolRequestResponseContent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B,MAAM,OAAO,+BAA+B;IACjC,SAAS,CAAyB;IAClC,MAAM,CAAS;IACf,UAAU,GAAkB,IAAI,CAAC;IACjC,IAAI,CAAS;IACb,eAAe,GAAkB,IAAI,CAAC;IAE/C,YACE,MAAiD,EACjD,IAA6C,EAC7C,aAA2D,EAC3D,eAAmE,EACnE,UAAyD;QAEzD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,aAAa,CAAC;QAE/B,IAAI,eAAe,EAAE,CAAC;YACpB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACzC,CAAC;QAED,IAAI,UAAU,EAAE,CAAC;YACf,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC/B,CAAC;IACH,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 * as z from \"zod/mini\";\n\nexport class AgentToolRequestResponseContent {\n readonly arguments: z.core.util.JSONType[];\n readonly callId: string;\n readonly commentary: string | null = null;\n readonly name: string;\n readonly summarizedTitle: string | null = null;\n\n constructor(\n callId: AgentToolRequestResponseContent[\"callId\"],\n name: AgentToolRequestResponseContent[\"name\"],\n toolArguments: AgentToolRequestResponseContent[\"arguments\"],\n summarizedTitle: AgentToolRequestResponseContent[\"summarizedTitle\"],\n commentary: AgentToolRequestResponseContent[\"commentary\"],\n ) {\n this.callId = callId;\n this.name = name;\n this.arguments = toolArguments;\n\n if (summarizedTitle) {\n this.summarizedTitle = summarizedTitle;\n }\n\n if (commentary) {\n this.commentary = commentary;\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as z from "zod/mini";
|
|
2
|
+
export declare class AgentToolResultResponseContent {
|
|
3
|
+
readonly callId: string;
|
|
4
|
+
readonly commentary: string | null;
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly result: Record<string, z.core.util.JSONType>;
|
|
7
|
+
constructor(callId: AgentToolResultResponseContent["callId"], name: AgentToolResultResponseContent["name"], result: AgentToolResultResponseContent["result"], commentary?: string);
|
|
8
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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 * as z from "zod/mini";
|
|
17
|
+
export class AgentToolResultResponseContent {
|
|
18
|
+
callId;
|
|
19
|
+
commentary = null;
|
|
20
|
+
name;
|
|
21
|
+
result;
|
|
22
|
+
constructor(callId, name, result, commentary) {
|
|
23
|
+
this.callId = callId;
|
|
24
|
+
this.name = name;
|
|
25
|
+
this.result = result;
|
|
26
|
+
if (commentary) {
|
|
27
|
+
this.commentary = commentary;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=AgentToolResultResponseContent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentToolResultResponseContent.js","sourceRoot":"","sources":["../../../../src/enterprise/ai/chat/AgentToolResultResponseContent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B,MAAM,OAAO,8BAA8B;IAChC,MAAM,CAAS;IACf,UAAU,GAAkB,IAAI,CAAC;IACjC,IAAI,CAAS;IACb,MAAM,CAAuC;IAEtD,YACE,MAAgD,EAChD,IAA4C,EAC5C,MAAgD,EAChD,UAAmB;QAEnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,IAAI,UAAU,EAAE,CAAC;YACf,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC/B,CAAC;IACH,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 * as z from \"zod/mini\";\n\nexport class AgentToolResultResponseContent {\n readonly callId: string;\n readonly commentary: string | null = null;\n readonly name: string;\n readonly result: Record<string, z.core.util.JSONType>;\n\n constructor(\n callId: AgentToolResultResponseContent[\"callId\"],\n name: AgentToolResultResponseContent[\"name\"],\n result: AgentToolResultResponseContent[\"result\"],\n commentary?: string,\n ) {\n this.callId = callId;\n this.name = name;\n this.result = result;\n\n if (commentary) {\n this.commentary = commentary;\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as z from "zod/mini";
|
|
2
|
+
declare const chatSessionInputSchema: z.ZodMiniObject<{
|
|
3
|
+
modelName: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
4
|
+
modelProviderId: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
5
|
+
sessionId: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
6
|
+
}, z.core.$strip>;
|
|
7
|
+
/**
|
|
8
|
+
* Tracks an Agent chat session. Each field is optional and intentionally mutable
|
|
9
|
+
* so that if any of these fields become available during agent reply (such as which
|
|
10
|
+
* default model provider and name it picked, as well as the server-generated sessionId),
|
|
11
|
+
* they're mutated on the instance of the class.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ChatSession {
|
|
14
|
+
modelName?: string;
|
|
15
|
+
modelProviderId?: string;
|
|
16
|
+
sessionId?: string;
|
|
17
|
+
constructor(properties?: z.infer<typeof chatSessionInputSchema>);
|
|
18
|
+
toJSON(): {
|
|
19
|
+
modelName?: string | undefined;
|
|
20
|
+
modelProviderId?: string | undefined;
|
|
21
|
+
sessionId?: string | undefined;
|
|
22
|
+
};
|
|
23
|
+
assign(properties: z.infer<typeof chatSessionInputSchema>): void;
|
|
24
|
+
equals(other: ChatSession): boolean;
|
|
25
|
+
static fromJSON(data: z.input<typeof ChatSession.codec>): ChatSession;
|
|
26
|
+
static codec: z.ZodMiniCodec<z.ZodMiniObject<{
|
|
27
|
+
modelName: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
28
|
+
modelProviderId: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
29
|
+
sessionId: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
30
|
+
}, z.core.$strip>, z.ZodMiniCustom<ChatSession, ChatSession>>;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
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 * as z from "zod/mini";
|
|
17
|
+
const chatSessionInputSchema = z.object({
|
|
18
|
+
modelName: z.optional(z.string()),
|
|
19
|
+
modelProviderId: z.optional(z.string()),
|
|
20
|
+
sessionId: z.optional(z.string()),
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* Tracks an Agent chat session. Each field is optional and intentionally mutable
|
|
24
|
+
* so that if any of these fields become available during agent reply (such as which
|
|
25
|
+
* default model provider and name it picked, as well as the server-generated sessionId),
|
|
26
|
+
* they're mutated on the instance of the class.
|
|
27
|
+
*/
|
|
28
|
+
export class ChatSession {
|
|
29
|
+
modelName;
|
|
30
|
+
modelProviderId;
|
|
31
|
+
sessionId;
|
|
32
|
+
constructor(properties = {}) {
|
|
33
|
+
if (properties.modelName) {
|
|
34
|
+
this.modelName = properties.modelName;
|
|
35
|
+
}
|
|
36
|
+
if (properties.modelProviderId) {
|
|
37
|
+
this.modelProviderId = properties.modelProviderId;
|
|
38
|
+
}
|
|
39
|
+
if (properties.sessionId) {
|
|
40
|
+
this.sessionId = properties.sessionId;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
toJSON() {
|
|
44
|
+
return z.encode(ChatSession.codec, this);
|
|
45
|
+
}
|
|
46
|
+
assign(properties) {
|
|
47
|
+
if (properties.modelName) {
|
|
48
|
+
this.modelName = properties.modelName;
|
|
49
|
+
}
|
|
50
|
+
if (properties.modelProviderId) {
|
|
51
|
+
this.modelProviderId = properties.modelProviderId;
|
|
52
|
+
}
|
|
53
|
+
if (properties.sessionId) {
|
|
54
|
+
this.sessionId = properties.sessionId;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
equals(other) {
|
|
58
|
+
return (this === other ||
|
|
59
|
+
(this.sessionId === other.sessionId && (!!this.sessionId || !!other.sessionId)));
|
|
60
|
+
}
|
|
61
|
+
static fromJSON(data) {
|
|
62
|
+
return z.decode(ChatSession.codec, data);
|
|
63
|
+
}
|
|
64
|
+
static codec = z.codec(chatSessionInputSchema, z.instanceof(ChatSession), {
|
|
65
|
+
decode(v) {
|
|
66
|
+
return new ChatSession(v);
|
|
67
|
+
},
|
|
68
|
+
encode(v) {
|
|
69
|
+
return {
|
|
70
|
+
modelName: v.modelName,
|
|
71
|
+
modelProviderId: v.modelProviderId,
|
|
72
|
+
sessionId: v.sessionId,
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=ChatSession.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatSession.js","sourceRoot":"","sources":["../../../../src/enterprise/ai/chat/ChatSession.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,SAAS,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IACjC,eAAe,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IACvC,SAAS,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;CAClC,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,OAAO,WAAW;IACtB,SAAS,CAAU;IACnB,eAAe,CAAU;IACzB,SAAS,C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C,sBAAsB,EAAE,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE;QACxE,MAAM,CAAC,CAAC;YACN,OAAO,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC;QAC5B,CAAC;QACD,MAAM,CAAC,CAAC;YACN,OAAO;gBACL,SAAS,EAAE,CAAC,CAAC,SAAS;gBACtB,eAAe,EAAE,CAAC,CAAC,eAAe;gBAClC,SAAS,EAAE,CAAC,CAAC,SAAS;aACvB,CAAC;QACJ,CAAC;KACF,CAAC,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 * as z from \"zod/mini\";\n\nconst chatSessionInputSchema = z.object({\n modelName: z.optional(z.string()),\n modelProviderId: z.optional(z.string()),\n sessionId: z.optional(z.string()),\n});\n\n/**\n * Tracks an Agent chat session. Each field is optional and intentionally mutable\n * so that if any of these fields become available during agent reply (such as which\n * default model provider and name it picked, as well as the server-generated sessionId),\n * they're mutated on the instance of the class.\n */\nexport class ChatSession {\n modelName?: string;\n modelProviderId?: string;\n sessionId?: string;\n\n constructor(properties: z.infer<typeof chatSessionInputSchema> = {}) {\n if (properties.modelName) {\n this.modelName = properties.modelName;\n }\n if (properties.modelProviderId) {\n this.modelProviderId = properties.modelProviderId;\n }\n\n if (properties.sessionId) {\n this.sessionId = properties.sessionId;\n }\n }\n\n toJSON() {\n return z.encode(ChatSession.codec, this);\n }\n\n assign(properties: z.infer<typeof chatSessionInputSchema>) {\n if (properties.modelName) {\n this.modelName = properties.modelName;\n }\n if (properties.modelProviderId) {\n this.modelProviderId = properties.modelProviderId;\n }\n\n if (properties.sessionId) {\n this.sessionId = properties.sessionId;\n }\n }\n\n equals(other: ChatSession) {\n return (\n this === other ||\n (this.sessionId === other.sessionId && (!!this.sessionId || !!other.sessionId))\n );\n }\n\n static fromJSON(data: z.input<typeof ChatSession.codec>) {\n return z.decode(ChatSession.codec, data);\n }\n\n static codec = z.codec(chatSessionInputSchema, z.instanceof(ChatSession), {\n decode(v) {\n return new ChatSession(v);\n },\n encode(v) {\n return {\n modelName: v.modelName,\n modelProviderId: v.modelProviderId,\n sessionId: v.sessionId,\n };\n },\n });\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as z from "zod/mini";
|
|
2
|
+
import { Temporal } from "temporal-polyfill";
|
|
3
|
+
import { type UserChatMessageContent } from "./UserChatMessageContent.ts";
|
|
4
|
+
export declare class UserChatMessage {
|
|
5
|
+
readonly createdAt: Temporal.Instant;
|
|
6
|
+
readonly content: UserChatMessageContent;
|
|
7
|
+
readonly id: string;
|
|
8
|
+
readonly context?: Record<string, z.core.util.JSONType>;
|
|
9
|
+
constructor(content: UserChatMessage["content"], context?: UserChatMessage["context"], id?: string, createdAt?: Temporal.Instant);
|
|
10
|
+
withContext(context: UserChatMessage["context"]): UserChatMessage;
|
|
11
|
+
mergeContext(context: NonNullable<UserChatMessage["context"]>): UserChatMessage;
|
|
12
|
+
toString(): string;
|
|
13
|
+
toJSON(): {
|
|
14
|
+
content: {
|
|
15
|
+
content: string;
|
|
16
|
+
type: "string";
|
|
17
|
+
};
|
|
18
|
+
createdAt: string;
|
|
19
|
+
id: string;
|
|
20
|
+
};
|
|
21
|
+
static fromJSON(data: z.input<typeof UserChatMessage.codec>): UserChatMessage;
|
|
22
|
+
static codec: z.ZodMiniCodec<z.ZodMiniObject<{
|
|
23
|
+
content: z.ZodMiniObject<{
|
|
24
|
+
content: z.ZodMiniString<string>;
|
|
25
|
+
type: z.ZodMiniLiteral<"string">;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
createdAt: z.ZodMiniString<string>;
|
|
28
|
+
id: z.ZodMiniString<string>;
|
|
29
|
+
}, z.core.$strip>, z.ZodMiniCustom<UserChatMessage, UserChatMessage>>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
import { Temporal } from "temporal-polyfill";
|
|
19
|
+
import { userChatMessageContentCodec, } from "./UserChatMessageContent.js";
|
|
20
|
+
export class UserChatMessage {
|
|
21
|
+
createdAt = Temporal.Now.instant();
|
|
22
|
+
content;
|
|
23
|
+
id = nanoid();
|
|
24
|
+
context;
|
|
25
|
+
constructor(content, context, id, createdAt) {
|
|
26
|
+
this.content = content;
|
|
27
|
+
this.context = context;
|
|
28
|
+
if (id) {
|
|
29
|
+
this.id = id;
|
|
30
|
+
}
|
|
31
|
+
if (createdAt) {
|
|
32
|
+
this.createdAt = createdAt;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
withContext(context) {
|
|
36
|
+
return new UserChatMessage(this.content, context, this.id, this.createdAt);
|
|
37
|
+
}
|
|
38
|
+
mergeContext(context) {
|
|
39
|
+
return new UserChatMessage(this.content, { ...this.context, ...context }, this.id);
|
|
40
|
+
}
|
|
41
|
+
toString() {
|
|
42
|
+
return (this.content.content +
|
|
43
|
+
(this.context ? `\n\n<system-context>${JSON.stringify(this.context)}</system-context>` : ""));
|
|
44
|
+
}
|
|
45
|
+
toJSON() {
|
|
46
|
+
return z.encode(UserChatMessage.codec, this);
|
|
47
|
+
}
|
|
48
|
+
static fromJSON(data) {
|
|
49
|
+
return z.decode(UserChatMessage.codec, data);
|
|
50
|
+
}
|
|
51
|
+
static codec = z.codec(z.object({
|
|
52
|
+
content: userChatMessageContentCodec.def.in,
|
|
53
|
+
createdAt: z.string().check(z.iso.datetime()),
|
|
54
|
+
id: z.string(),
|
|
55
|
+
}), z.instanceof(UserChatMessage), {
|
|
56
|
+
decode(v) {
|
|
57
|
+
return new UserChatMessage(z.decode(userChatMessageContentCodec, v.content), undefined, v.id);
|
|
58
|
+
},
|
|
59
|
+
encode(v) {
|
|
60
|
+
return {
|
|
61
|
+
...v,
|
|
62
|
+
content: z.encode(userChatMessageContentCodec, v.content),
|
|
63
|
+
createdAt: v.createdAt.toString(),
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=UserChatMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserChatMessage.js","sourceRoot":"","sources":["../../../../src/enterprise/ai/chat/UserChatMessage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EACL,2BAA2B,GAE5B,MAAM,6BAA6B,CAAC;AAErC,MAAM,OAAO,eAAe;IACjB,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IACnC,OAAO,CAAyB;IAChC,EAAE,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C;QACP,OAAO,EAAE,2BAA2B,CAAC,GAAG,CAAC,EAAE;QAC3C,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;QAC7C,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;KACf,CAAC,EACF,CAAC,CAAC,UAAU,CAAC,eAAe,CAAC,EAC7B;QACE,MAAM,CAAC,CAAC;YACN,OAAO,IAAI,eAAe,CACxB,CAAC,CAAC,MAAM,CAAC,2BAA2B,EAAE,CAAC,CAAC,OAAO,CAAC,EAChD,SAAS,EACT,CAAC,CAAC,EAAE,CACL,CAAC;QACJ,CAAC;QACD,MAAM,CAAC,CAAC;YACN,OAAO;gBACL,GAAG,CAAC;gBACJ,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,2BAA2B,EAAE,CAAC,CAAC,OAAO,CAAC;gBACzD,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,QAAQ,EAAE;aACzB,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\";\nimport { Temporal } from \"temporal-polyfill\";\nimport {\n userChatMessageContentCodec,\n type UserChatMessageContent,\n} from \"./UserChatMessageContent.ts\";\n\nexport class UserChatMessage {\n readonly createdAt = Temporal.Now.instant();\n readonly content: UserChatMessageContent;\n readonly id = nanoid();\n readonly context?: Record<string, z.core.util.JSONType>;\n\n constructor(\n content: UserChatMessage[\"content\"],\n context?: UserChatMessage[\"context\"],\n id?: string,\n createdAt?: Temporal.Instant,\n ) {\n this.content = content;\n this.context = context;\n\n if (id) {\n this.id = id;\n }\n\n if (createdAt) {\n this.createdAt = createdAt;\n }\n }\n\n withContext(context: UserChatMessage[\"context\"]) {\n return new UserChatMessage(this.content, context, this.id, this.createdAt);\n }\n\n mergeContext(context: NonNullable<UserChatMessage[\"context\"]>) {\n return new UserChatMessage(this.content, { ...this.context, ...context }, this.id);\n }\n\n toString() {\n return (\n this.content.content +\n (this.context ? `\\n\\n<system-context>${JSON.stringify(this.context)}</system-context>` : \"\")\n );\n }\n\n toJSON() {\n return z.encode(UserChatMessage.codec, this);\n }\n\n static fromJSON(data: z.input<typeof UserChatMessage.codec>) {\n return z.decode(UserChatMessage.codec, data);\n }\n\n static codec = z.codec(\n z.object({\n content: userChatMessageContentCodec.def.in,\n createdAt: z.string().check(z.iso.datetime()),\n id: z.string(),\n }),\n z.instanceof(UserChatMessage),\n {\n decode(v) {\n return new UserChatMessage(\n z.decode(userChatMessageContentCodec, v.content),\n undefined,\n v.id,\n );\n },\n encode(v) {\n return {\n ...v,\n content: z.encode(userChatMessageContentCodec, v.content),\n createdAt: v.createdAt.toString(),\n } as const;\n },\n },\n );\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as z from "zod/mini";
|
|
2
|
+
export declare class UserChatMessageStringContent implements UserChatMessageContent {
|
|
3
|
+
readonly content: string;
|
|
4
|
+
constructor(content: string);
|
|
5
|
+
toJSON(): {
|
|
6
|
+
content: string;
|
|
7
|
+
type: "string";
|
|
8
|
+
};
|
|
9
|
+
static fromJSON(data: z.input<typeof UserChatMessageStringContent.codec>): UserChatMessageStringContent;
|
|
10
|
+
static codec: z.ZodMiniCodec<z.ZodMiniObject<{
|
|
11
|
+
content: z.ZodMiniString<string>;
|
|
12
|
+
type: z.ZodMiniLiteral<"string">;
|
|
13
|
+
}, z.core.$strip>, z.ZodMiniCustom<UserChatMessageStringContent, UserChatMessageStringContent>>;
|
|
14
|
+
}
|
|
15
|
+
export declare const userChatMessageContentCodec: z.ZodMiniCodec<z.ZodMiniObject<{
|
|
16
|
+
content: z.ZodMiniString<string>;
|
|
17
|
+
type: z.ZodMiniLiteral<"string">;
|
|
18
|
+
}, z.core.$strip>, z.ZodMiniCustom<UserChatMessageStringContent, UserChatMessageStringContent>>;
|
|
19
|
+
export type UserChatMessageContent = UserChatMessageStringContent;
|
|
@@ -0,0 +1,44 @@
|
|
|
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 * as z from "zod/mini";
|
|
17
|
+
export class UserChatMessageStringContent {
|
|
18
|
+
content;
|
|
19
|
+
constructor(content) {
|
|
20
|
+
this.content = content;
|
|
21
|
+
}
|
|
22
|
+
toJSON() {
|
|
23
|
+
return z.encode(UserChatMessageStringContent.codec, this);
|
|
24
|
+
}
|
|
25
|
+
static fromJSON(data) {
|
|
26
|
+
return z.decode(UserChatMessageStringContent.codec, data);
|
|
27
|
+
}
|
|
28
|
+
static codec = z.codec(z.object({
|
|
29
|
+
content: z.string(),
|
|
30
|
+
type: z.literal("string"),
|
|
31
|
+
}), z.instanceof(UserChatMessageStringContent), {
|
|
32
|
+
decode(v) {
|
|
33
|
+
return new UserChatMessageStringContent(v.content);
|
|
34
|
+
},
|
|
35
|
+
encode(v) {
|
|
36
|
+
return {
|
|
37
|
+
content: v.content,
|
|
38
|
+
type: "string",
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
export const userChatMessageContentCodec = UserChatMessageStringContent.codec;
|
|
44
|
+
//# sourceMappingURL=UserChatMessageContent.js.map
|