@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.
Files changed (113) hide show
  1. package/dist/cloud/Dremio.d.ts +3 -2
  2. package/dist/cloud/Dremio.js +2 -2
  3. package/dist/cloud/Dremio.js.map +1 -1
  4. package/dist/cloud/ai/AIResource.d.ts +125 -0
  5. package/dist/cloud/ai/AIResource.js +113 -0
  6. package/dist/cloud/ai/AIResource.js.map +1 -0
  7. package/dist/cloud/ai/DremioModelProvider.d.ts +12 -0
  8. package/dist/cloud/ai/DremioModelProvider.js +49 -0
  9. package/dist/cloud/ai/DremioModelProvider.js.map +1 -0
  10. package/dist/cloud/ai/index.d.ts +4 -0
  11. package/dist/cloud/ai/index.js +20 -0
  12. package/dist/cloud/ai/index.js.map +1 -0
  13. package/dist/cloud/ai/modelProviderCodec.d.ts +180 -0
  14. package/dist/cloud/ai/modelProviderCodec.js +54 -0
  15. package/dist/cloud/ai/modelProviderCodec.js.map +1 -0
  16. package/dist/cloud/catalog/EnterpriseCatalogResource.d.ts +10 -3
  17. package/dist/cloud/catalog/EnterpriseCatalogResource.js +38 -0
  18. package/dist/cloud/catalog/EnterpriseCatalogResource.js.map +1 -1
  19. package/dist/cloud/catalog/FileUpload.d.ts +117 -0
  20. package/dist/cloud/catalog/FileUpload.js +103 -0
  21. package/dist/cloud/catalog/FileUpload.js.map +1 -0
  22. package/dist/cloud/getResourceConfig.d.ts +1 -0
  23. package/dist/cloud/getResourceConfig.js +3 -0
  24. package/dist/cloud/getResourceConfig.js.map +1 -1
  25. package/dist/cloud/interfaces.d.ts +3 -1
  26. package/dist/cloud/interfaces.js +3 -1
  27. package/dist/cloud/interfaces.js.map +1 -1
  28. package/dist/cloud/organizations/Organization.d.ts +10 -0
  29. package/dist/cloud/organizations/Organization.js +12 -0
  30. package/dist/cloud/organizations/Organization.js.map +1 -1
  31. package/dist/cloud/projects/Project.d.ts +1 -0
  32. package/dist/cloud/projects/Project.js +2 -0
  33. package/dist/cloud/projects/Project.js.map +1 -1
  34. package/dist/cloud/projects/projectPropertiesCodec.d.ts +6 -0
  35. package/dist/cloud/projects/projectPropertiesCodec.js +1 -0
  36. package/dist/cloud/projects/projectPropertiesCodec.js.map +1 -1
  37. package/dist/cloud/replaceOriginResource.js +6 -1
  38. package/dist/cloud/replaceOriginResource.js.map +1 -1
  39. package/dist/common/Config.d.ts +14 -0
  40. package/dist/common/Config.js.map +1 -1
  41. package/dist/common/createRequest.d.ts +1 -0
  42. package/dist/common/createRequest.js +1 -1
  43. package/dist/common/createRequest.js.map +1 -1
  44. package/dist/common/createXHR.d.ts +2 -0
  45. package/dist/common/createXHR.js +58 -0
  46. package/dist/common/createXHR.js.map +1 -0
  47. package/dist/enterprise/Dremio.d.ts +3 -1
  48. package/dist/enterprise/Dremio.js +3 -0
  49. package/dist/enterprise/Dremio.js.map +1 -1
  50. package/dist/enterprise/ai/AIResource.d.ts +118 -0
  51. package/dist/enterprise/ai/AIResource.js +123 -0
  52. package/dist/enterprise/ai/AIResource.js.map +1 -0
  53. package/dist/enterprise/ai/ModelProvider.d.ts +181 -0
  54. package/dist/enterprise/ai/ModelProvider.js +87 -0
  55. package/dist/enterprise/ai/ModelProvider.js.map +1 -0
  56. package/dist/enterprise/ai/chat/AgentChatPartialResponse.d.ts +42 -0
  57. package/dist/enterprise/ai/chat/AgentChatPartialResponse.js +65 -0
  58. package/dist/enterprise/ai/chat/AgentChatPartialResponse.js.map +1 -0
  59. package/dist/enterprise/ai/chat/AgentChatResponse.d.ts +87 -0
  60. package/dist/enterprise/ai/chat/AgentChatResponse.js +138 -0
  61. package/dist/enterprise/ai/chat/AgentChatResponse.js.map +1 -0
  62. package/dist/enterprise/ai/chat/AgentErrorResponseContent.d.ts +4 -0
  63. package/dist/enterprise/ai/chat/AgentErrorResponseContent.js +22 -0
  64. package/dist/enterprise/ai/chat/AgentErrorResponseContent.js.map +1 -0
  65. package/dist/enterprise/ai/chat/AgentModelResponseContent.d.ts +6 -0
  66. package/dist/enterprise/ai/chat/AgentModelResponseContent.js +24 -0
  67. package/dist/enterprise/ai/chat/AgentModelResponseContent.js.map +1 -0
  68. package/dist/enterprise/ai/chat/AgentToolRequestResponseContent.d.ts +9 -0
  69. package/dist/enterprise/ai/chat/AgentToolRequestResponseContent.js +35 -0
  70. package/dist/enterprise/ai/chat/AgentToolRequestResponseContent.js.map +1 -0
  71. package/dist/enterprise/ai/chat/AgentToolResultResponseContent.d.ts +8 -0
  72. package/dist/enterprise/ai/chat/AgentToolResultResponseContent.js +31 -0
  73. package/dist/enterprise/ai/chat/AgentToolResultResponseContent.js.map +1 -0
  74. package/dist/enterprise/ai/chat/ChatSession.d.ts +32 -0
  75. package/dist/enterprise/ai/chat/ChatSession.js +77 -0
  76. package/dist/enterprise/ai/chat/ChatSession.js.map +1 -0
  77. package/dist/enterprise/ai/chat/UserChatMessage.d.ts +30 -0
  78. package/dist/enterprise/ai/chat/UserChatMessage.js +68 -0
  79. package/dist/enterprise/ai/chat/UserChatMessage.js.map +1 -0
  80. package/dist/enterprise/ai/chat/UserChatMessageContent.d.ts +19 -0
  81. package/dist/enterprise/ai/chat/UserChatMessageContent.js +44 -0
  82. package/dist/enterprise/ai/chat/UserChatMessageContent.js.map +1 -0
  83. package/dist/enterprise/ai/chat/chatEventSchema.d.ts +35 -0
  84. package/dist/enterprise/ai/chat/chatEventSchema.js +52 -0
  85. package/dist/enterprise/ai/chat/chatEventSchema.js.map +1 -0
  86. package/dist/enterprise/ai/chat/index.d.ts +9 -0
  87. package/dist/enterprise/ai/chat/index.js +25 -0
  88. package/dist/enterprise/ai/chat/index.js.map +1 -0
  89. package/dist/enterprise/ai/index.d.ts +3 -0
  90. package/dist/enterprise/ai/index.js +19 -0
  91. package/dist/enterprise/ai/index.js.map +1 -0
  92. package/dist/enterprise/ai/modelProviderCodec.d.ts +465 -0
  93. package/dist/enterprise/ai/modelProviderCodec.js +154 -0
  94. package/dist/enterprise/ai/modelProviderCodec.js.map +1 -0
  95. package/dist/enterprise/ai/modelProviderConfigSchemas.d.ts +296 -0
  96. package/dist/enterprise/ai/modelProviderConfigSchemas.js +159 -0
  97. package/dist/enterprise/ai/modelProviderConfigSchemas.js.map +1 -0
  98. package/dist/enterprise/interfaces.d.ts +1 -0
  99. package/dist/enterprise/interfaces.js +1 -0
  100. package/dist/enterprise/interfaces.js.map +1 -1
  101. package/dist/enterprise/users/EnterpriseUsersResource.d.ts +7 -0
  102. package/dist/enterprise/users/EnterpriseUsersResource.js +31 -0
  103. package/dist/enterprise/users/EnterpriseUsersResource.js.map +1 -1
  104. package/dist/enterprise/users/ServiceUser.d.ts +85 -0
  105. package/dist/enterprise/users/ServiceUser.js +79 -0
  106. package/dist/enterprise/users/ServiceUser.js.map +1 -0
  107. package/dist/enterprise/users/serviceUserOauthCredentialsCodec.d.ts +43 -0
  108. package/dist/enterprise/users/serviceUserOauthCredentialsCodec.js +110 -0
  109. package/dist/enterprise/users/serviceUserOauthCredentialsCodec.js.map +1 -0
  110. package/package.json +1 -1
  111. package/dist/cloud/ai/AiResource.d.ts +0 -12
  112. package/dist/cloud/ai/AiResource.js +0 -52
  113. package/dist/cloud/ai/AiResource.js.map +0 -1
@@ -0,0 +1,123 @@
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 { catchError, map, of } from "rxjs";
17
+ import { ChatSession } from "./chat/ChatSession.js";
18
+ import { AgentChatResponse } from "./chat/AgentChatResponse.js";
19
+ import { fromTextEventStream } from "../../common/fromTextEventStream.js";
20
+ import { ModelProvider } from "./ModelProvider.js";
21
+ import * as z from "zod/mini";
22
+ import { modelProviderCreateCodec, modelProviderRetrieveCodec } from "./modelProviderCodec.js";
23
+ import { safeParseResultToResult } from "../../common/safeParseResultToResult.js";
24
+ import { Err, Ok } from "ts-results-es";
25
+ import { Problem } from "../../common/Problem.js";
26
+ export class AIResource {
27
+ #config;
28
+ constructor(config) {
29
+ this.#config = config;
30
+ }
31
+ createModelProvider(properties) {
32
+ const body = z.encode(modelProviderCreateCodec, properties);
33
+ return this.#config
34
+ .v4Request(`model-provider/config`, {
35
+ body: JSON.stringify(body),
36
+ headers: {
37
+ Accept: "application/json",
38
+ "Content-Type": "application/json",
39
+ },
40
+ keepalive: true,
41
+ method: "POST",
42
+ })
43
+ .map((res) => res.json())
44
+ .map((entity) => new ModelProvider(this.#config, z.decode(modelProviderRetrieveCodec, entity)));
45
+ }
46
+ listModelProviders() {
47
+ const getPage = ({ signal } = {}) => {
48
+ return this.#config
49
+ .v4Request("model-provider/config", {
50
+ headers: {
51
+ Accept: "application/json",
52
+ },
53
+ signal,
54
+ })
55
+ .map((res) => res.json())
56
+ .map((response) => ({
57
+ data: response.configs.map((entity) => safeParseResultToResult(z.safeDecode(modelProviderRetrieveCodec, entity)).map((properties) => new ModelProvider(this.#config, properties))),
58
+ }));
59
+ };
60
+ return {
61
+ async *data({ signal } = {}) {
62
+ yield* (await getPage({ signal }).promise).map((response) => response.data).unwrap();
63
+ },
64
+ getPage,
65
+ };
66
+ }
67
+ listAvailableModels(properties) {
68
+ return this.#config
69
+ .v4Request("model-provider:listModels", {
70
+ body: JSON.stringify({ access: properties }),
71
+ headers: {
72
+ Accept: "application/json",
73
+ "Content-Type": "application/json",
74
+ },
75
+ method: "POST",
76
+ })
77
+ .map((res) => res.json())
78
+ .map((result) => new Set(result.models));
79
+ }
80
+ retrieveModelProvider(id, { signal } = {}) {
81
+ return this.#config
82
+ .v4Request(`model-provider/config/${id}`, {
83
+ headers: {
84
+ Accept: "application/json",
85
+ },
86
+ signal,
87
+ })
88
+ .map((res) => res.json())
89
+ .map((entity) => new ModelProvider(this.#config, z.decode(modelProviderRetrieveCodec, entity)));
90
+ }
91
+ /**
92
+ * Sends a chat message to the Dremio AI Agent and returns an Observable containing
93
+ * Agent replies.
94
+ */
95
+ sendChatMessage(chatSession) {
96
+ return (chatMessage) => fromTextEventStream(({ signal }) => this.#config
97
+ .sonarV4Request("agent", {
98
+ body: JSON.stringify({
99
+ message: chatMessage.toString(),
100
+ sessionId: chatSession.sessionId,
101
+ }),
102
+ headers: {
103
+ Accept: "text/event-stream",
104
+ "Content-Type": "application/json",
105
+ },
106
+ method: "POST",
107
+ signal,
108
+ })
109
+ .promise.then((result) => {
110
+ if (result.isErr()) {
111
+ throw result.error;
112
+ }
113
+ return result.value;
114
+ })).pipe(map((event) => Ok(AgentChatResponse.fromJSON(JSON.parse(event.data)))), catchError((e) => of(Err(refineChatErrors(e)))));
115
+ }
116
+ }
117
+ function refineChatErrors(e) {
118
+ if (e.body instanceof Problem) {
119
+ return e.body;
120
+ }
121
+ return e;
122
+ }
123
+ //# sourceMappingURL=AIResource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AIResource.js","sourceRoot":"","sources":["../../../src/enterprise/ai/AIResource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,wBAAwB,EAAE,0BAA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C,EAAE,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAC3D,CAAC;IACN,CAAC;CACF;AAWD,SAAS,gBAAgB,CAAC,CAAY;IACpC,IAAI,CAAC,CAAC,IAAI,YAAY,OAAO,EAAE,CAAC;QAC9B,OAAO,CAAC,CAAC,IAA4C,CAAC;IACxD,CAAC;IACD,OAAO,CAAC,CAAC;AACX,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 { catchError, map, of } from \"rxjs\";\nimport { ChatSession } from \"./chat/ChatSession.ts\";\nimport type { UserChatMessage } from \"./chat/UserChatMessage.ts\";\nimport { AgentChatResponse } from \"./chat/AgentChatResponse.ts\";\nimport type { Logger, SonarV4Config, V4Config } from \"../../common/Config.ts\";\nimport { fromTextEventStream } from \"../../common/fromTextEventStream.ts\";\nimport { ModelProvider } from \"./ModelProvider.ts\";\n\nimport * as z from \"zod/mini\";\nimport { modelProviderCreateCodec, modelProviderRetrieveCodec } from \"./modelProviderCodec.js\";\nimport type { SignalParam } from \"../../common/Params.ts\";\nimport { safeParseResultToResult } from \"../../common/safeParseResultToResult.ts\";\nimport type { listModelsPropertiesSchema } from \"./modelProviderConfigSchemas.ts\";\nimport { Err, Ok } from \"ts-results-es\";\nimport type { HttpError } from \"../../common/HttpError.ts\";\nimport { Problem } from \"../../common/Problem.ts\";\nexport class AIResource {\n #config: Logger & V4Config & SonarV4Config;\n\n constructor(config: Logger & V4Config & SonarV4Config) {\n this.#config = config;\n }\n\n createModelProvider(properties: z.output<typeof modelProviderCreateCodec>) {\n const body = z.encode(modelProviderCreateCodec, properties);\n return this.#config\n .v4Request(`model-provider/config`, {\n body: JSON.stringify(body),\n headers: {\n Accept: \"application/json\",\n \"Content-Type\": \"application/json\",\n },\n keepalive: true,\n method: \"POST\",\n })\n .map((res) => res.json() as Promise<z.input<typeof modelProviderRetrieveCodec>>)\n .map(\n (entity) => new ModelProvider(this.#config, z.decode(modelProviderRetrieveCodec, entity)),\n );\n }\n\n listModelProviders() {\n const getPage = ({ signal }: SignalParam = {}) => {\n return this.#config\n .v4Request(\"model-provider/config\", {\n headers: {\n Accept: \"application/json\",\n },\n signal,\n })\n .map(\n (res) => res.json() as Promise<{ configs: z.input<typeof modelProviderRetrieveCodec>[] }>,\n )\n .map((response) => ({\n data: response.configs.map((entity) =>\n safeParseResultToResult(z.safeDecode(modelProviderRetrieveCodec, entity)).map(\n (properties) => new ModelProvider(this.#config, properties),\n ),\n ),\n }));\n };\n return {\n async *data({ signal }: SignalParam = {}) {\n yield* (await getPage({ signal }).promise).map((response) => response.data).unwrap();\n },\n getPage,\n };\n }\n\n listAvailableModels(properties: z.infer<typeof listModelsPropertiesSchema>) {\n return this.#config\n .v4Request(\"model-provider:listModels\", {\n body: JSON.stringify({ access: properties }),\n headers: {\n Accept: \"application/json\",\n \"Content-Type\": \"application/json\",\n },\n method: \"POST\",\n })\n .map((res) => res.json() as Promise<{ models: string[] }>)\n .map((result) => new Set(result.models));\n }\n\n retrieveModelProvider(id: string, { signal }: SignalParam = {}) {\n return this.#config\n .v4Request(`model-provider/config/${id}`, {\n headers: {\n Accept: \"application/json\",\n },\n signal,\n })\n .map((res) => res.json() as Promise<z.input<typeof modelProviderRetrieveCodec>>)\n .map(\n (entity) => new ModelProvider(this.#config, z.decode(modelProviderRetrieveCodec, entity)),\n );\n }\n\n /**\n * Sends a chat message to the Dremio AI Agent and returns an Observable containing\n * Agent replies.\n */\n sendChatMessage(chatSession: ChatSession) {\n return (chatMessage: UserChatMessage) =>\n fromTextEventStream(({ signal }) =>\n this.#config\n .sonarV4Request(\"agent\", {\n body: JSON.stringify({\n message: chatMessage.toString(),\n sessionId: chatSession.sessionId,\n } satisfies {\n message: string;\n modelProviderId?: string;\n sessionId?: string;\n }),\n headers: {\n Accept: \"text/event-stream\",\n \"Content-Type\": \"application/json\",\n },\n method: \"POST\",\n signal,\n })\n .promise.then((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n }),\n ).pipe(\n map((event) => Ok(AgentChatResponse.fromJSON(JSON.parse(event.data)))),\n catchError((e: HttpError) => of(Err(refineChatErrors(e)))),\n );\n }\n}\n\ntype SendChatMessageProblemCodes =\n | \"https://api.dremio.dev/problems/ai-agent/chat/agent-disabled\"\n | \"https://api.dremio.dev/problems/ai-agent/chat/input-too-large\"\n | \"https://api.dremio.dev/problems/ai-agent/chat/model-provider-not-found\"\n | \"https://api.dremio.dev/problems/ai-agent/chat/no-default-model-provider\"\n | \"https://api.dremio.dev/problems/ai-agent/chat/no-model-provider-privilege\"\n | \"https://api.dremio.dev/problems/ai-agent/chat/preview-disabled\"\n | \"https://api.dremio.dev/problems/ai-agent/chat/rate-limit-exceeded\";\n\nfunction refineChatErrors(e: HttpError) {\n if (e.body instanceof Problem) {\n return e.body as Problem<SendChatMessageProblemCodes>;\n }\n return e;\n}\n"]}
@@ -0,0 +1,181 @@
1
+ import type { V4Config } from "../../common/Config.ts";
2
+ import * as z from "zod/mini";
3
+ import { modelProviderRetrieveCodec, modelProviderUpdateCodec } from "./modelProviderCodec.ts";
4
+ import { VersionConflictError } from "../../common/problems.ts";
5
+ export declare class ModelProvider implements Omit<ModelProviderProperties, "tag"> {
6
+ #private;
7
+ readonly config: ModelProviderProperties["config"];
8
+ readonly createdAt: ModelProviderProperties["createdAt"];
9
+ readonly createdBy: ModelProviderProperties["createdBy"];
10
+ readonly defaultModelName: ModelProviderProperties["defaultModelName"];
11
+ readonly id: ModelProviderProperties["id"];
12
+ readonly isDefault: ModelProviderProperties["isDefault"];
13
+ readonly modifiedAt: ModelProviderProperties["modifiedAt"];
14
+ readonly modifiedBy: ModelProviderProperties["modifiedBy"];
15
+ readonly name: ModelProviderProperties["name"];
16
+ readonly sqlModelNames: ModelProviderProperties["sqlModelNames"];
17
+ constructor(config: V4Config, properties: z.output<typeof modelProviderRetrieveCodec>);
18
+ delete(): import("ts-results-es").AsyncResult<void, import("../index.ts").HttpError>;
19
+ setDefault(): import("ts-results-es").AsyncResult<ModelProvider, VersionConflictError | import("../index.ts").HttpError>;
20
+ update(fields: Partial<z.output<typeof modelProviderUpdateCodec>>): import("ts-results-es").AsyncResult<ModelProvider, VersionConflictError | import("../index.ts").HttpError>;
21
+ static createSchema: z.ZodMiniObject<{
22
+ name: z.ZodMiniString<string>;
23
+ config: z.ZodMiniUnion<readonly [z.ZodMiniObject<{
24
+ amazonBedrock: z.ZodMiniObject<{
25
+ auth: z.ZodMiniUnion<readonly [z.ZodMiniObject<{
26
+ accessKey: z.ZodMiniObject<{
27
+ accessKeyId: z.ZodMiniString<string>;
28
+ secretAccessKey: z.ZodMiniString<string>;
29
+ }, z.core.$strict>;
30
+ }, z.core.$strict>, z.ZodMiniObject<{
31
+ role: z.ZodMiniObject<{
32
+ roleArn: z.ZodMiniString<string>;
33
+ }, z.core.$strict>;
34
+ }, z.core.$strict>]>;
35
+ region: z.ZodMiniEnum<{
36
+ "ap-east-2": "ap-east-2";
37
+ "ap-northeast-1": "ap-northeast-1";
38
+ "ap-northeast-2": "ap-northeast-2";
39
+ "ap-northeast-3": "ap-northeast-3";
40
+ "ap-south-1": "ap-south-1";
41
+ "ap-south-2": "ap-south-2";
42
+ "ap-southeast-1": "ap-southeast-1";
43
+ "ap-southeast-2": "ap-southeast-2";
44
+ "ap-southeast-3": "ap-southeast-3";
45
+ "ap-southeast-4": "ap-southeast-4";
46
+ "ap-southeast-5": "ap-southeast-5";
47
+ "ap-southeast-7": "ap-southeast-7";
48
+ "ca-central-1": "ca-central-1";
49
+ "eu-central-1": "eu-central-1";
50
+ "eu-central-2": "eu-central-2";
51
+ "eu-north-1": "eu-north-1";
52
+ "eu-south-1": "eu-south-1";
53
+ "eu-south-2": "eu-south-2";
54
+ "eu-west-1": "eu-west-1";
55
+ "eu-west-2": "eu-west-2";
56
+ "eu-west-3": "eu-west-3";
57
+ "il-central-1": "il-central-1";
58
+ "me-central-1": "me-central-1";
59
+ "sa-east-1": "sa-east-1";
60
+ "us-east-1": "us-east-1";
61
+ "us-east-2": "us-east-2";
62
+ "us-gov-east-1": "us-gov-east-1";
63
+ "us-gov-west-1": "us-gov-west-1";
64
+ "us-west-1": "us-west-1";
65
+ "us-west-2": "us-west-2";
66
+ }>;
67
+ }, z.core.$strict>;
68
+ }, z.core.$strict>, z.ZodMiniObject<{
69
+ anthropic: z.ZodMiniObject<{
70
+ accessKey: z.ZodMiniString<string>;
71
+ }, z.core.$strict>;
72
+ }, z.core.$strict>, z.ZodMiniObject<{
73
+ azureOpenAi: z.ZodMiniObject<{
74
+ auth: z.ZodMiniObject<{
75
+ clientSecretAuth: z.ZodMiniObject<{
76
+ azureClientId: z.ZodMiniString<string>;
77
+ azureClientSecret: z.ZodMiniString<string>;
78
+ azureTenantId: z.ZodMiniString<string>;
79
+ }, z.core.$strict>;
80
+ }, z.core.$strict>;
81
+ resourceName: z.ZodMiniString<string>;
82
+ }, z.core.$strict>;
83
+ }, z.core.$strict>, z.ZodMiniObject<{
84
+ googleGemini: z.ZodMiniObject<{
85
+ accessKey: z.ZodMiniString<string>;
86
+ }, z.core.$strict>;
87
+ }, z.core.$strict>, z.ZodMiniObject<{
88
+ openAi: z.ZodMiniObject<{
89
+ accessKey: z.ZodMiniString<string>;
90
+ organizationId: z.ZodMiniString<string>;
91
+ }, z.core.$strict>;
92
+ }, z.core.$strict>]>;
93
+ defaultModelName: z.ZodMiniString<string>;
94
+ isDefault: z.ZodMiniBoolean<boolean>;
95
+ sqlModelNames: z.ZodMiniSet<z.ZodMiniString<string>>;
96
+ }, z.core.$strip>;
97
+ static updateSchema: z.ZodMiniObject<{
98
+ name: z.ZodMiniString<string>;
99
+ config: z.ZodMiniUnion<readonly [z.ZodMiniObject<{
100
+ amazonBedrock: z.ZodMiniObject<{
101
+ auth: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniObject<{
102
+ accessKey: z.ZodMiniObject<{
103
+ accessKeyId: z.ZodMiniString<string>;
104
+ secretAccessKey: z.ZodMiniOptional<z.ZodMiniString<string>>;
105
+ }, z.core.$strict>;
106
+ }, z.core.$strict>, z.ZodMiniObject<{
107
+ role: z.ZodMiniObject<{
108
+ roleArn: z.ZodMiniString<string>;
109
+ }, z.core.$strict>;
110
+ }, z.core.$strict>]>>;
111
+ region: z.ZodMiniOptional<z.ZodMiniEnum<{
112
+ "ap-east-2": "ap-east-2";
113
+ "ap-northeast-1": "ap-northeast-1";
114
+ "ap-northeast-2": "ap-northeast-2";
115
+ "ap-northeast-3": "ap-northeast-3";
116
+ "ap-south-1": "ap-south-1";
117
+ "ap-south-2": "ap-south-2";
118
+ "ap-southeast-1": "ap-southeast-1";
119
+ "ap-southeast-2": "ap-southeast-2";
120
+ "ap-southeast-3": "ap-southeast-3";
121
+ "ap-southeast-4": "ap-southeast-4";
122
+ "ap-southeast-5": "ap-southeast-5";
123
+ "ap-southeast-7": "ap-southeast-7";
124
+ "ca-central-1": "ca-central-1";
125
+ "eu-central-1": "eu-central-1";
126
+ "eu-central-2": "eu-central-2";
127
+ "eu-north-1": "eu-north-1";
128
+ "eu-south-1": "eu-south-1";
129
+ "eu-south-2": "eu-south-2";
130
+ "eu-west-1": "eu-west-1";
131
+ "eu-west-2": "eu-west-2";
132
+ "eu-west-3": "eu-west-3";
133
+ "il-central-1": "il-central-1";
134
+ "me-central-1": "me-central-1";
135
+ "sa-east-1": "sa-east-1";
136
+ "us-east-1": "us-east-1";
137
+ "us-east-2": "us-east-2";
138
+ "us-gov-east-1": "us-gov-east-1";
139
+ "us-gov-west-1": "us-gov-west-1";
140
+ "us-west-1": "us-west-1";
141
+ "us-west-2": "us-west-2";
142
+ }>>;
143
+ }, z.core.$strict>;
144
+ }, z.core.$strict>, z.ZodMiniObject<{
145
+ anthropic: z.ZodMiniObject<{
146
+ accessKey: z.ZodMiniOptional<z.ZodMiniString<string>>;
147
+ }, z.core.$strict>;
148
+ }, z.core.$strict>, z.ZodMiniObject<{
149
+ azureOpenAi: z.ZodMiniObject<{
150
+ auth: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniObject<{
151
+ clientSecretAuth: z.ZodMiniObject<{
152
+ azureClientId: z.ZodMiniString<string>;
153
+ azureClientSecret: z.ZodMiniString<string>;
154
+ azureTenantId: z.ZodMiniString<string>;
155
+ }, z.core.$strict>;
156
+ }, z.core.$strict>, z.ZodMiniObject<{
157
+ clientSecretAuth: z.ZodMiniObject<{
158
+ azureClientId: z.ZodMiniString<string>;
159
+ azureTenantId: z.ZodMiniString<string>;
160
+ azureClientSecret: z.ZodMiniOptional<z.ZodMiniString<string>>;
161
+ }, z.core.$strict>;
162
+ }, z.core.$strict>]>>;
163
+ resourceName: z.ZodMiniString<string>;
164
+ }, z.core.$strict>;
165
+ }, z.core.$strict>, z.ZodMiniObject<{
166
+ googleGemini: z.ZodMiniObject<{
167
+ accessKey: z.ZodMiniOptional<z.ZodMiniString<string>>;
168
+ }, z.core.$strict>;
169
+ }, z.core.$strict>, z.ZodMiniObject<{
170
+ openAi: z.ZodMiniObject<{
171
+ accessKey: z.ZodMiniOptional<z.ZodMiniString<string>>;
172
+ organizationId: z.ZodMiniOptional<z.ZodMiniString<string>>;
173
+ }, z.core.$strict>;
174
+ }, z.core.$strict>]>;
175
+ defaultModelName: z.ZodMiniString<string>;
176
+ isDefault: z.ZodMiniBoolean<boolean>;
177
+ sqlModelNames: z.ZodMiniSet<z.ZodMiniString<string>>;
178
+ }, z.core.$strip>;
179
+ }
180
+ type ModelProviderProperties = z.output<typeof modelProviderRetrieveCodec>;
181
+ export {};
@@ -0,0 +1,87 @@
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
+ import { modelProviderCreateCodec, modelProviderRetrieveCodec, modelProviderUpdateCodec, } from "./modelProviderCodec.js";
18
+ import { VersionConflictError } from "../../common/problems.js";
19
+ export class ModelProvider {
20
+ config;
21
+ createdAt;
22
+ createdBy;
23
+ defaultModelName;
24
+ id;
25
+ isDefault;
26
+ modifiedAt;
27
+ modifiedBy;
28
+ name;
29
+ sqlModelNames;
30
+ #config;
31
+ #tag;
32
+ constructor(config, properties) {
33
+ this.config = properties.config;
34
+ this.createdAt = properties.createdAt;
35
+ this.createdBy = properties.createdBy;
36
+ this.defaultModelName = properties.defaultModelName;
37
+ this.id = properties.id;
38
+ this.isDefault = properties.isDefault;
39
+ this.modifiedAt = properties.modifiedAt;
40
+ this.modifiedBy = properties.modifiedBy;
41
+ this.name = properties.name;
42
+ this.sqlModelNames = properties.sqlModelNames;
43
+ this.#config = config;
44
+ this.#tag = properties.tag;
45
+ }
46
+ delete() {
47
+ return this.#config
48
+ .v4Request(`model-provider/config/${this.id}`, {
49
+ keepalive: true,
50
+ method: "DELETE",
51
+ })
52
+ .map(() => undefined);
53
+ }
54
+ setDefault() {
55
+ return this.update({ isDefault: true });
56
+ }
57
+ update(fields) {
58
+ const body = z.encode(modelProviderUpdateCodec, {
59
+ config: fields.config ?? this.config,
60
+ defaultModelName: fields.defaultModelName ?? this.defaultModelName,
61
+ isDefault: fields.isDefault ?? this.isDefault,
62
+ name: fields.name ?? this.name,
63
+ sqlModelNames: fields.sqlModelNames ?? this.sqlModelNames,
64
+ });
65
+ return this.#config
66
+ .v4Request(`model-provider/config/${this.id}`, {
67
+ body: JSON.stringify({ ...body, tag: this.#tag }),
68
+ headers: {
69
+ Accept: "application/json",
70
+ "Content-Type": "application/json",
71
+ },
72
+ keepalive: true,
73
+ method: "PUT",
74
+ })
75
+ .map((res) => res.json())
76
+ .map((entity) => new ModelProvider(this.#config, z.decode(modelProviderRetrieveCodec, entity)))
77
+ .mapErr((val) => {
78
+ if (val.status === 409) {
79
+ return new VersionConflictError();
80
+ }
81
+ return val;
82
+ });
83
+ }
84
+ static createSchema = modelProviderCreateCodec.def.out;
85
+ static updateSchema = modelProviderUpdateCodec.def.out;
86
+ }
87
+ //# sourceMappingURL=ModelProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ModelProvider.js","sourceRoot":"","sources":["../../../src/enterprise/ai/ModelProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,EACL,wBAAwB,EACxB,0BAA0B,EAC1B,wBAAwB,GACzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhE,MAAM,OAAO,aAAa;IACf,MAAM,CAAoC;IAC1C,SAAS,CAAuC;IAChD,SAAS,CAAuC;IAChD,gBAAgB,CAA8C;IAC9D,EAAE,CAAgC;IAClC,SAAS,CAAuC;IAChD,UAAU,CAAwC;IAClD,UAAU,CAAwC;IAClD,IAAI,CAAkC;IACtC,aAAa,CAA2C;IAExD,OAAO,CAAW;IAClB,IAAI,CAAS;IAEtB,YAAY,MAAgB,EAAE,UAAuD;QACnF,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;QAChC,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC;QACtC,IAAI,CAAC,SAAS,GA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AAI,CAAC,aAAa;SAC1D,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,OAAO;aAChB,SAAS,CAAC,yBAAyB,IAAI,CAAC,EAAE,EAAE,EAAE;YAC7C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;YACjD,OAAO,EAAE;gBACP,MAAM,EAAE,kBAAkB;gBAC1B,cAAc,EAAE,kBAAkB;aACnC;YACD,SAAS,EAAE,IAAI;YACf,MAAM,EAAE,KAAK;SACd,CAAC;aACD,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAyD,CAAC;aAC/E,GAAG,CACF,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,0BAA0B,EAAE,MAAM,CAAC,CAAC,CAC1F;aACA,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE;YACd,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;gBACvB,OAAO,IAAI,oBAAoB,EAAE,CAAC;YACpC,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC,CAAC,CAAC;IACP,CAAC;IAED,MAAM,CAAC,YAAY,GAAG,wBAAwB,CAAC,GAAG,CAAC,GAAG,CAAC;IACvD,MAAM,CAAC,YAAY,GAAG,wBAAwB,CAAC,GAAG,CAAC,GAAG,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 type { V4Config } from \"../../common/Config.ts\";\nimport * as z from \"zod/mini\";\nimport {\n modelProviderCreateCodec,\n modelProviderRetrieveCodec,\n modelProviderUpdateCodec,\n} from \"./modelProviderCodec.ts\";\nimport { VersionConflictError } from \"../../common/problems.ts\";\n\nexport class ModelProvider implements Omit<ModelProviderProperties, \"tag\"> {\n readonly config: ModelProviderProperties[\"config\"];\n readonly createdAt: ModelProviderProperties[\"createdAt\"];\n readonly createdBy: ModelProviderProperties[\"createdBy\"];\n readonly defaultModelName: ModelProviderProperties[\"defaultModelName\"];\n readonly id: ModelProviderProperties[\"id\"];\n readonly isDefault: ModelProviderProperties[\"isDefault\"];\n readonly modifiedAt: ModelProviderProperties[\"modifiedAt\"];\n readonly modifiedBy: ModelProviderProperties[\"modifiedBy\"];\n readonly name: ModelProviderProperties[\"name\"];\n readonly sqlModelNames: ModelProviderProperties[\"sqlModelNames\"];\n\n readonly #config: V4Config;\n readonly #tag: string;\n\n constructor(config: V4Config, properties: z.output<typeof modelProviderRetrieveCodec>) {\n this.config = properties.config;\n this.createdAt = properties.createdAt;\n this.createdBy = properties.createdBy;\n this.defaultModelName = properties.defaultModelName;\n this.id = properties.id;\n this.isDefault = properties.isDefault;\n this.modifiedAt = properties.modifiedAt;\n this.modifiedBy = properties.modifiedBy;\n this.name = properties.name;\n this.sqlModelNames = properties.sqlModelNames;\n\n this.#config = config;\n this.#tag = properties.tag;\n }\n\n delete() {\n return this.#config\n .v4Request(`model-provider/config/${this.id}`, {\n keepalive: true,\n method: \"DELETE\",\n })\n .map(() => undefined as void);\n }\n\n setDefault() {\n return this.update({ isDefault: true });\n }\n\n update(fields: Partial<z.output<typeof modelProviderUpdateCodec>>) {\n const body = z.encode(modelProviderUpdateCodec, {\n config: fields.config ?? this.config,\n defaultModelName: fields.defaultModelName ?? this.defaultModelName,\n isDefault: fields.isDefault ?? this.isDefault,\n name: fields.name ?? this.name,\n sqlModelNames: fields.sqlModelNames ?? this.sqlModelNames,\n });\n\n return this.#config\n .v4Request(`model-provider/config/${this.id}`, {\n body: JSON.stringify({ ...body, tag: this.#tag }),\n headers: {\n Accept: \"application/json\",\n \"Content-Type\": \"application/json\",\n },\n keepalive: true,\n method: \"PUT\",\n })\n .map((res) => res.json() as Promise<z.input<typeof modelProviderRetrieveCodec>>)\n .map(\n (entity) => new ModelProvider(this.#config, z.decode(modelProviderRetrieveCodec, entity)),\n )\n .mapErr((val) => {\n if (val.status === 409) {\n return new VersionConflictError();\n }\n return val;\n });\n }\n\n static createSchema = modelProviderCreateCodec.def.out;\n static updateSchema = modelProviderUpdateCodec.def.out;\n}\n\ntype ModelProviderProperties = z.output<typeof modelProviderRetrieveCodec>;\n"]}
@@ -0,0 +1,42 @@
1
+ import { ChatSession } from "./ChatSession.ts";
2
+ import * as z from "zod/mini";
3
+ declare const agentPartialResponseTypeSchema: z.ZodMiniEnum<{
4
+ delta: "delta";
5
+ end: "end";
6
+ start: "start";
7
+ }>;
8
+ export declare class AgentChatPartialResponse {
9
+ readonly id: string;
10
+ readonly session: ChatSession;
11
+ readonly content: string;
12
+ readonly type: z.infer<typeof agentPartialResponseTypeSchema>;
13
+ constructor(chatSession: AgentChatPartialResponse["session"], type: AgentChatPartialResponse["type"], content: AgentChatPartialResponse["content"], id?: AgentChatPartialResponse["id"]);
14
+ concat(next: AgentChatPartialResponse): AgentChatPartialResponse;
15
+ toJSON(): {
16
+ content: string;
17
+ id: string;
18
+ session: {
19
+ modelName?: string | undefined;
20
+ modelProviderId?: string | undefined;
21
+ sessionId?: string | undefined;
22
+ };
23
+ type: "delta" | "end" | "start";
24
+ };
25
+ get isComplete(): boolean;
26
+ static fromJSON(data: unknown): AgentChatPartialResponse;
27
+ static codec: z.ZodMiniCodec<z.ZodMiniObject<{
28
+ content: z.ZodMiniString<string>;
29
+ id: z.ZodMiniString<string>;
30
+ session: z.ZodMiniObject<{
31
+ modelName: z.ZodMiniOptional<z.ZodMiniString<string>>;
32
+ modelProviderId: z.ZodMiniOptional<z.ZodMiniString<string>>;
33
+ sessionId: z.ZodMiniOptional<z.ZodMiniString<string>>;
34
+ }, z.core.$strip>;
35
+ type: z.ZodMiniEnum<{
36
+ delta: "delta";
37
+ end: "end";
38
+ start: "start";
39
+ }>;
40
+ }, z.core.$strip>, z.ZodMiniCustom<AgentChatPartialResponse, AgentChatPartialResponse>>;
41
+ }
42
+ export {};
@@ -0,0 +1,65 @@
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 { ChatSession } from "./ChatSession.js";
18
+ import * as z from "zod/mini";
19
+ const agentPartialResponseTypeSchema = z.enum(["delta", "end", "start"]);
20
+ export class AgentChatPartialResponse {
21
+ id = nanoid();
22
+ session;
23
+ content;
24
+ type;
25
+ constructor(chatSession, type, content, id) {
26
+ this.session = chatSession;
27
+ this.type = type;
28
+ this.content = content;
29
+ if (id) {
30
+ this.id = id;
31
+ }
32
+ }
33
+ concat(next) {
34
+ return new AgentChatPartialResponse(this.session, next.type, this.content + next.content, this.id);
35
+ }
36
+ toJSON() {
37
+ return z.encode(AgentChatPartialResponse.codec, this);
38
+ }
39
+ get isComplete() {
40
+ return this.type === "end";
41
+ }
42
+ static fromJSON(data) {
43
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
44
+ return z.decode(AgentChatPartialResponse.codec, data);
45
+ }
46
+ static codec = z.codec(z.object({
47
+ content: z.string(),
48
+ id: z.string(),
49
+ session: ChatSession.codec.def.in,
50
+ type: agentPartialResponseTypeSchema,
51
+ }), z.instanceof(AgentChatPartialResponse), {
52
+ decode(v) {
53
+ return new AgentChatPartialResponse(ChatSession.fromJSON(v.session), v.type, v.content, v.id);
54
+ },
55
+ encode(v) {
56
+ return {
57
+ content: v.content,
58
+ id: v.id,
59
+ session: v.session.toJSON(),
60
+ type: v.type,
61
+ };
62
+ },
63
+ });
64
+ }
65
+ //# sourceMappingURL=AgentChatPartialResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentChatPartialResponse.js","sourceRoot":"","sources":["../../../../src/enterprise/ai/chat/AgentChatPartialResponse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B,MAAM,8BAA8B,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;AAEzE,MAAM,OAAO,wBAAwB;IAC1B,EAAE,GAAG,MAAM,EAAE,CAAC;IACd,OAAO,CAAc;IACrB,OAAO,CAAS;IAChB,IAAI,CAAiD;IAE9D,YACE,WAAgD,EAChD,IAAsC,EACtC,OAA4C,EAC5C,EAAmC;QAEnC,IAAI,CAAC,OAAO,GAAG,WAAW,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,IAAI,EAAE,EAAE,CAAC;YACP,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACf,CAAC;IACH,CAAC;IAED,MAAM,CAAC,IAA8B;QACnC,OAAO,IAAI,wBAAwB,CACjC,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,EAC3B,IAAI,CAAC,EAAE,CACR,CAAC;IACJ,CAAC;IAED,MAAM;QACJ,OAAO,CAAC,CAAC,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACxD,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC;IAC7B,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,IAAa;QAC3B,qGAAqG;QACrG,OAAO,CAAC,CAAC,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,IAAW,CAAC,CAAC;IAC/D,CAAC;IAED,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CACpB,CAAC,CAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;QACnB,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;QACd,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;QACjC,IAAI,EAAE,8BAA8B;KACrC,CAAC,EACF,CAAC,CAAC,UAAU,CAAC,wBAAwB,CAAC,EACtC;QACE,MAAM,CAAC,CAAC;YACN,OAAO,IAAI,wBAAwB,CACjC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,EAC/B,CAAC,CAAC,IAAI,EACN,CAAC,CAAC,OAAO,EACT,CAAC,CAAC,EAAE,CACL,CAAC;QACJ,CAAC;QACD,MAAM,CAAC,CAAC;YACN,OAAO;gBACL,OAAO,EAAE,CAAC,CAAC,OAAO;gBAClB,EAAE,EAAE,CAAC,CAAC,EAAE;gBACR,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE;gBAC3B,IAAI,EAAE,CAAC,CAAC,IAAI;aACJ,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 { ChatSession } from \"./ChatSession.ts\";\nimport * as z from \"zod/mini\";\n\nconst agentPartialResponseTypeSchema = z.enum([\"delta\", \"end\", \"start\"]);\n\nexport class AgentChatPartialResponse {\n readonly id = nanoid();\n readonly session: ChatSession;\n readonly content: string;\n readonly type: z.infer<typeof agentPartialResponseTypeSchema>;\n\n constructor(\n chatSession: AgentChatPartialResponse[\"session\"],\n type: AgentChatPartialResponse[\"type\"],\n content: AgentChatPartialResponse[\"content\"],\n id?: AgentChatPartialResponse[\"id\"],\n ) {\n this.session = chatSession;\n this.type = type;\n this.content = content;\n\n if (id) {\n this.id = id;\n }\n }\n\n concat(next: AgentChatPartialResponse) {\n return new AgentChatPartialResponse(\n this.session,\n next.type,\n this.content + next.content,\n this.id,\n );\n }\n\n toJSON() {\n return z.encode(AgentChatPartialResponse.codec, this);\n }\n\n get isComplete() {\n return this.type === \"end\";\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(AgentChatPartialResponse.codec, data as any);\n }\n\n static codec = z.codec(\n z.object({\n content: z.string(),\n id: z.string(),\n session: ChatSession.codec.def.in,\n type: agentPartialResponseTypeSchema,\n }),\n z.instanceof(AgentChatPartialResponse),\n {\n decode(v) {\n return new AgentChatPartialResponse(\n ChatSession.fromJSON(v.session),\n v.type,\n v.content,\n v.id,\n );\n },\n encode(v) {\n return {\n content: v.content,\n id: v.id,\n session: v.session.toJSON(),\n type: v.type,\n } as const;\n },\n },\n );\n}\n"]}
@@ -0,0 +1,87 @@
1
+ import { AgentErrorResponseContent } from "./AgentErrorResponseContent.ts";
2
+ import { AgentModelResponseContent } from "./AgentModelResponseContent.ts";
3
+ import { AgentToolRequestResponseContent } from "./AgentToolRequestResponseContent.ts";
4
+ import { AgentToolResultResponseContent } from "./AgentToolResultResponseContent.ts";
5
+ import { ChatSession } from "./ChatSession.ts";
6
+ import * as z from "zod/mini";
7
+ import { Temporal } from "temporal-polyfill";
8
+ export declare class AgentChatResponse<T extends AgentResponseContent> {
9
+ readonly createdAt: Temporal.Instant;
10
+ readonly id: string;
11
+ readonly session: ChatSession;
12
+ readonly content: T;
13
+ constructor(chatSession: ChatSession, content: T, createdAt?: Temporal.Instant, id?: string);
14
+ /**
15
+ * Creates a copy of the AgentResponse with a different content property.
16
+ * Preserves the original message's ID
17
+ */
18
+ replaceContent<R extends AgentResponseContent>(content: R): AgentChatResponse<R>;
19
+ toJSON(): {
20
+ chunkType: "error";
21
+ message: string;
22
+ } | {
23
+ chunkType: "model";
24
+ name: string;
25
+ result: Record<string, z.core.util.JSONType>;
26
+ createdAt: string;
27
+ modelName: string;
28
+ modelProviderId: string;
29
+ sessionId: string;
30
+ } | {
31
+ arguments: Record<string, z.core.util.JSONType>;
32
+ callId: string;
33
+ chunkType: "toolRequest";
34
+ name: string;
35
+ createdAt: string;
36
+ modelName: string;
37
+ modelProviderId: string;
38
+ sessionId: string;
39
+ commentary?: string | undefined;
40
+ summarizedTitle?: string | undefined;
41
+ } | {
42
+ callId: string;
43
+ chunkType: "toolResponse";
44
+ name: string;
45
+ result: Record<string, z.core.util.JSONType>;
46
+ createdAt: string;
47
+ modelName: string;
48
+ modelProviderId: string;
49
+ sessionId: string;
50
+ commentary?: string | undefined;
51
+ };
52
+ static fromJSON(data: unknown): AgentChatResponse<AgentResponseContent>;
53
+ static codec: z.ZodMiniCodec<z.ZodMiniDiscriminatedUnion<[z.ZodMiniObject<{
54
+ chunkType: z.ZodMiniLiteral<"error">;
55
+ message: z.ZodMiniString<string>;
56
+ }, z.core.$strip>, z.ZodMiniObject<{
57
+ chunkType: z.ZodMiniLiteral<"model">;
58
+ name: z.ZodMiniString<string>;
59
+ result: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniJSONSchema>;
60
+ createdAt: z.ZodMiniString<string>;
61
+ modelName: z.ZodMiniString<string>;
62
+ modelProviderId: z.ZodMiniString<string>;
63
+ sessionId: z.ZodMiniString<string>;
64
+ }, z.core.$strip>, z.ZodMiniObject<{
65
+ arguments: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniJSONSchema>;
66
+ callId: z.ZodMiniString<string>;
67
+ chunkType: z.ZodMiniLiteral<"toolRequest">;
68
+ commentary: z.ZodMiniOptional<z.ZodMiniString<string>>;
69
+ name: z.ZodMiniString<string>;
70
+ summarizedTitle: z.ZodMiniOptional<z.ZodMiniString<string>>;
71
+ createdAt: z.ZodMiniString<string>;
72
+ modelName: z.ZodMiniString<string>;
73
+ modelProviderId: z.ZodMiniString<string>;
74
+ sessionId: z.ZodMiniString<string>;
75
+ }, z.core.$strip>, z.ZodMiniObject<{
76
+ callId: z.ZodMiniString<string>;
77
+ chunkType: z.ZodMiniLiteral<"toolResponse">;
78
+ commentary: z.ZodMiniOptional<z.ZodMiniString<string>>;
79
+ name: z.ZodMiniString<string>;
80
+ result: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniJSONSchema>;
81
+ createdAt: z.ZodMiniString<string>;
82
+ modelName: z.ZodMiniString<string>;
83
+ modelProviderId: z.ZodMiniString<string>;
84
+ sessionId: z.ZodMiniString<string>;
85
+ }, z.core.$strip>], "chunkType">, z.ZodMiniCustom<AgentChatResponse<AgentResponseContent>, AgentChatResponse<AgentResponseContent>>>;
86
+ }
87
+ export type AgentResponseContent = AgentErrorResponseContent | AgentModelResponseContent | AgentToolRequestResponseContent | AgentToolResultResponseContent;