@dremio/js-sdk 0.33.1 → 0.34.1

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.
@@ -10,12 +10,13 @@ import type { listModelsPropertiesSchema } from "./modelProviderConfigSchemas.ts
10
10
  import { Err, Ok } from "ts-results-es";
11
11
  import type { HttpError } from "../../common/HttpError.ts";
12
12
  import { Problem } from "../../common/Problem.ts";
13
+ import { AgentChatExchange } from "./chat/eventWrappers/AgentChatExchange.ts";
13
14
  export declare class AIResource {
14
15
  #private;
15
16
  constructor(config: Logger & V4Config & SonarV4Config);
16
17
  createModelProvider(properties: z.output<typeof modelProviderCreateCodec>): import("ts-results-es").AsyncResult<ModelProvider, HttpError>;
17
18
  listModelProviders(): {
18
- data({ signal }?: SignalParam): AsyncGenerator<Err<z.core.$ZodError<{
19
+ data({ signal }?: SignalParam): AsyncGenerator<Ok<ModelProvider> | Err<z.core.$ZodError<{
19
20
  name: string;
20
21
  id: string;
21
22
  tag: string;
@@ -58,9 +59,9 @@ export declare class AIResource {
58
59
  createdAt: import("temporal-polyfill").Temporal.Instant;
59
60
  modifiedAt: import("temporal-polyfill").Temporal.Instant;
60
61
  sqlModelNames: Set<string>;
61
- }>> | Ok<ModelProvider>, void, unknown>;
62
+ }>>, void, unknown>;
62
63
  getPage: ({ signal }?: SignalParam) => import("ts-results-es").AsyncResult<{
63
- data: (Err<z.core.$ZodError<{
64
+ data: (Ok<ModelProvider> | Err<z.core.$ZodError<{
64
65
  name: string;
65
66
  id: string;
66
67
  tag: string;
@@ -103,11 +104,16 @@ export declare class AIResource {
103
104
  createdAt: import("temporal-polyfill").Temporal.Instant;
104
105
  modifiedAt: import("temporal-polyfill").Temporal.Instant;
105
106
  sqlModelNames: Set<string>;
106
- }>> | Ok<ModelProvider>)[];
107
+ }>>)[];
107
108
  }, HttpError>;
108
109
  };
109
110
  listAvailableModels(properties: z.infer<typeof listModelsPropertiesSchema>): import("ts-results-es").AsyncResult<Set<string>, HttpError>;
110
111
  retrieveModelProvider(id: string, { signal }?: SignalParam): import("ts-results-es").AsyncResult<ModelProvider, HttpError>;
112
+ /**
113
+ * Creates an Observable that emits each time the `AgentChatExchange` is updated
114
+ * with events from the Agent.
115
+ */
116
+ createAgentChatExchange$(chatSession: ChatSession, userChatMessage: UserChatMessage): import("rxjs").Observable<AgentChatExchange>;
111
117
  /**
112
118
  * Sends a chat message to the Dremio AI Agent and returns an Observable containing
113
119
  * Agent replies.
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { catchError, map, of } from "rxjs";
16
+ import { catchError, endWith, map, of, scan, share, startWith } from "rxjs";
17
17
  import { ChatSession } from "./chat/ChatSession.js";
18
18
  import { AgentChatResponse } from "./chat/AgentChatResponse.js";
19
19
  import { fromTextEventStream } from "../../common/fromTextEventStream.js";
@@ -23,6 +23,8 @@ import { modelProviderCreateCodec, modelProviderRetrieveCodec } from "./modelPro
23
23
  import { safeParseResultToResult } from "../../common/safeParseResultToResult.js";
24
24
  import { Err, Ok } from "ts-results-es";
25
25
  import { Problem } from "../../common/Problem.js";
26
+ import { AgentChatExchange } from "./chat/eventWrappers/AgentChatExchange.js";
27
+ import { AgentEndTurn } from "../interfaces.js";
26
28
  export class AIResource {
27
29
  #config;
28
30
  constructor(config) {
@@ -88,6 +90,14 @@ export class AIResource {
88
90
  .map((res) => res.json())
89
91
  .map((entity) => new ModelProvider(this.#config, z.decode(modelProviderRetrieveCodec, entity)));
90
92
  }
93
+ /**
94
+ * Creates an Observable that emits each time the `AgentChatExchange` is updated
95
+ * with events from the Agent.
96
+ */
97
+ createAgentChatExchange$(chatSession, userChatMessage) {
98
+ const initialAgentChatExchange = new AgentChatExchange(userChatMessage, []);
99
+ return this.sendChatMessage(chatSession)(userChatMessage).pipe(map((eventResult) => eventResult.unwrap()), endWith(new AgentEndTurn({ type: "reply_finished" })), catchError((error) => of(new AgentEndTurn({ error, type: "error" }))), scan((agentChatExchange, agentChatEvent) => agentChatExchange.addChatEvent(agentChatEvent), initialAgentChatExchange), startWith(initialAgentChatExchange), share());
100
+ }
91
101
  /**
92
102
  * Sends a chat message to the Dremio AI Agent and returns an Observable containing
93
103
  * Agent replies.
@@ -1 +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,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAE/F,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAElF,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,MAAM,OAAO,UAAU;IACrB,OAAO,CAAoC;IAE3C,YAAY,MAAyC;QACnD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,mBAAmB,CAAC,UAAqD;QACvE,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,wBAAwB,EAAE,UAAU,CAAC,CAAC;QAC5D,OAAO,IAAI,CAAC,OAAO;aAChB,SAAS,CAAC,uBAAuB,EAAE;YAClC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;YAC1B,OAAO,EAAE;gBACP,MAAM,EAAE,kBAAkB;gBA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CAAC;gBACnB,OAAO,EAAE,WAAW,CAAC,QAAQ,EAAE;gBAC/B,SAAS,EAAE,WAAW,CAAC,SAAS;aAKjC,CAAC;YACF,OAAO,EAAE;gBACP,MAAM,EAAE,mBAAmB;gBAC3B,cAAc,EAAE,kBAAkB;aACnC;YACD,MAAM,EAAE,MAAM;YACd,MAAM;SACP,CAAC;aACD,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;YACvB,IAAI,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC;gBACnB,MAAM,MAAM,CAAC,KAAK,CAAC;YACrB,CAAC;YACD,OAAO,MAAM,CAAC,KAAK,CAAC;QACtB,CAAC,CAAC,CACL,CAAC,IAAI,CACJ,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,iBAAiB,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EACtE,UAAU,CAAC,CAAC,CAAY,EAAE,EAAE,CAAC,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"]}
1
+ {"version":3,"file":"AIResource.js","sourceRoot":"","sources":["../../../src/enterprise/ai/AIResource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAC5E,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,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAE/F,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAElF,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2CAA2C,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,MAAM,OAAO,UAAU;IACrB,OAAO,CAAoC;IAE3C,YAAY,MAAyC;QACnD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,mBAAmB,CAAC,UAAqD;QACvE,MAAM,IAAI,GAAG,CAAC,CA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EAAE,CAAC;gBACnB,MAAM,MAAM,CAAC,KAAK,CAAC;YACrB,CAAC;YACD,OAAO,MAAM,CAAC,KAAK,CAAC;QACtB,CAAC,CAAC,CACL,CAAC,IAAI,CACJ,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,iBAAiB,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EACtE,UAAU,CAAC,CAAC,CAAY,EAAE,EAAE,CAAC,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, endWith, map, of, scan, share, startWith } 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\";\nimport { AgentChatExchange } from \"./chat/eventWrappers/AgentChatExchange.ts\";\nimport { AgentEndTurn } from \"../interfaces.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 * Creates an Observable that emits each time the `AgentChatExchange` is updated\n * with events from the Agent.\n */\n createAgentChatExchange$(chatSession: ChatSession, userChatMessage: UserChatMessage) {\n const initialAgentChatExchange = new AgentChatExchange(userChatMessage, []);\n\n return this.sendChatMessage(chatSession)(userChatMessage).pipe(\n map((eventResult) => eventResult.unwrap()),\n endWith(new AgentEndTurn({ type: \"reply_finished\" })),\n catchError((error: unknown) => of(new AgentEndTurn({ error, type: \"error\" }))),\n scan(\n (agentChatExchange, agentChatEvent) => agentChatExchange.addChatEvent(agentChatEvent),\n initialAgentChatExchange,\n ),\n startWith(initialAgentChatExchange),\n share(),\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"]}
@@ -1,8 +1,9 @@
1
1
  import { AgentEndTurn } from "./AgentEndTurn.ts";
2
- import { AgentChatResponse, UserChatMessage, type AgentResponseContent } from "@dremio/js-sdk/enterprise";
3
2
  import { type Option } from "ts-results-es";
4
3
  import { AgentToolCallGroup } from "./AgentToolCallGroup.ts";
5
4
  import type { AgentToolCall } from "./AgentToolCall.ts";
5
+ import type { UserChatMessage } from "../UserChatMessage.ts";
6
+ import type { AgentChatResponse, AgentResponseContent } from "../AgentChatResponse.ts";
6
7
  /**
7
8
  * Represents a single chat exchange, starting with a `UserChatMessage` and followed by
8
9
  * 0 or more agent chat events. As chat events stream in, this class is updated
@@ -15,7 +15,6 @@
15
15
  */
16
16
  import { nanoid } from "nanoid/non-secure";
17
17
  import { AgentEndTurn } from "./AgentEndTurn.js";
18
- import { AgentChatResponse, UserChatMessage, } from "@dremio/js-sdk/enterprise";
19
18
  import { None, Some } from "ts-results-es";
20
19
  import { AgentToolCallGroup } from "./AgentToolCallGroup.js";
21
20
  import { isToolRequest, isToolResult } from "./AgentToolCall.js";
@@ -1 +1 @@
1
- {"version":3,"file":"AgentChatExchange.js","sourceRoot":"","sources":["../../../../../src/enterprise/ai/chat/eventWrappers/AgentChatExchange.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO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eAAe,EACpB,IAAI,CAAC,eAAe,EACpB,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAAC,cAAc,CAAC,EAClD,IAAI,CAAC,EAAE,CACR,CAAC;QACJ,CAAC;QACD,IAAI,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;YACjC,OAAO,IAAI,iBAAiB,CAC1B,IAAI,CAAC,eAAe,EACpB,IAAI,CAAC,eAAe,EACpB,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,cAAc,CAAC,EACjD,IAAI,CAAC,EAAE,CACR,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,iBAAiB,CAC1B,IAAI,CAAC,eAAe,EACpB,CAAC,GAAG,IAAI,CAAC,eAAe,EAAE,cAAc,CAAC,EACzC,IAAI,CAAC,kBAAkB,EACvB,IAAI,CAAC,EAAE,CACR,CAAC;IACJ,CAAC;CACF","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { nanoid } from \"nanoid/non-secure\";\nimport { AgentEndTurn } from \"./AgentEndTurn.ts\";\nimport {\n AgentChatResponse,\n UserChatMessage,\n type AgentResponseContent,\n} from \"@dremio/js-sdk/enterprise\";\nimport { None, Some, type Option } from \"ts-results-es\";\nimport { AgentToolCallGroup } from \"./AgentToolCallGroup.ts\";\nimport { isToolRequest, isToolResult } from \"./AgentToolCall.ts\";\nimport type { AgentToolCall } from \"./AgentToolCall.ts\";\n\n/**\n * Represents a single chat exchange, starting with a `UserChatMessage` and followed by\n * 0 or more agent chat events. As chat events stream in, this class is updated\n * immutably but maintains a stable `.id` property.\n */\nexport class AgentChatExchange {\n readonly agentChatEvents: AgentChatExchangeEvent[];\n readonly agentToolCallGroup: AgentToolCallGroup;\n readonly id: string;\n readonly userChatMessage: UserChatMessage;\n\n constructor(\n userChatMessage: AgentChatExchange[\"userChatMessage\"],\n agentChatEvents: AgentChatExchange[\"agentChatEvents\"],\n agentToolCallGroup = new AgentToolCallGroup([]),\n id = nanoid(),\n ) {\n this.agentChatEvents = agentChatEvents;\n this.agentToolCallGroup = agentToolCallGroup;\n this.id = id;\n this.userChatMessage = userChatMessage;\n }\n\n get isComplete() {\n return this.agentChatEvents.at(-1) instanceof AgentEndTurn;\n }\n\n get completeReason(): Option<AgentEndTurn[\"reason\"]> {\n const lastEvent = this.agentChatEvents.at(-1);\n\n if (lastEvent instanceof AgentEndTurn) {\n return Some(lastEvent.reason);\n }\n\n return None;\n }\n\n addChatEvent(agentChatEvent: AgentChatExchangeEvent) {\n if (isToolRequest(agentChatEvent)) {\n return new AgentChatExchange(\n this.userChatMessage,\n this.agentChatEvents,\n this.agentToolCallGroup.addRequest(agentChatEvent),\n this.id,\n );\n }\n if (isToolResult(agentChatEvent)) {\n return new AgentChatExchange(\n this.userChatMessage,\n this.agentChatEvents,\n this.agentToolCallGroup.addResult(agentChatEvent),\n this.id,\n );\n }\n return new AgentChatExchange(\n this.userChatMessage,\n [...this.agentChatEvents, agentChatEvent],\n this.agentToolCallGroup,\n this.id,\n );\n }\n}\n\nexport type AgentChatExchangeEvent =\n | AgentChatResponse<AgentResponseContent>\n | AgentEndTurn\n | AgentToolCall\n | AgentToolCallGroup;\n"]}
1
+ {"version":3,"file":"AgentChatExchange.js","sourceRoot":"","sources":["../../../../../src/enterprise/ai/chat/eventWrappers/AgentChatExchange.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EA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AE,CAAC;YACjC,OAAO,IAAI,iBAAiB,CAC1B,IAAI,CAAC,eAAe,EACpB,IAAI,CAAC,eAAe,EACpB,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,cAAc,CAAC,EACjD,IAAI,CAAC,EAAE,CACR,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,iBAAiB,CAC1B,IAAI,CAAC,eAAe,EACpB,CAAC,GAAG,IAAI,CAAC,eAAe,EAAE,cAAc,CAAC,EACzC,IAAI,CAAC,kBAAkB,EACvB,IAAI,CAAC,EAAE,CACR,CAAC;IACJ,CAAC;CACF","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { nanoid } from \"nanoid/non-secure\";\nimport { AgentEndTurn } from \"./AgentEndTurn.ts\";\nimport { None, Some, type Option } from \"ts-results-es\";\nimport { AgentToolCallGroup } from \"./AgentToolCallGroup.ts\";\nimport { isToolRequest, isToolResult } from \"./AgentToolCall.ts\";\nimport type { AgentToolCall } from \"./AgentToolCall.ts\";\nimport type { UserChatMessage } from \"../UserChatMessage.ts\";\nimport type { AgentChatResponse, AgentResponseContent } from \"../AgentChatResponse.ts\";\n\n/**\n * Represents a single chat exchange, starting with a `UserChatMessage` and followed by\n * 0 or more agent chat events. As chat events stream in, this class is updated\n * immutably but maintains a stable `.id` property.\n */\nexport class AgentChatExchange {\n readonly agentChatEvents: AgentChatExchangeEvent[];\n readonly agentToolCallGroup: AgentToolCallGroup;\n readonly id: string;\n readonly userChatMessage: UserChatMessage;\n\n constructor(\n userChatMessage: AgentChatExchange[\"userChatMessage\"],\n agentChatEvents: AgentChatExchange[\"agentChatEvents\"],\n agentToolCallGroup = new AgentToolCallGroup([]),\n id = nanoid(),\n ) {\n this.agentChatEvents = agentChatEvents;\n this.agentToolCallGroup = agentToolCallGroup;\n this.id = id;\n this.userChatMessage = userChatMessage;\n }\n\n get isComplete() {\n return this.agentChatEvents.at(-1) instanceof AgentEndTurn;\n }\n\n get completeReason(): Option<AgentEndTurn[\"reason\"]> {\n const lastEvent = this.agentChatEvents.at(-1);\n\n if (lastEvent instanceof AgentEndTurn) {\n return Some(lastEvent.reason);\n }\n\n return None;\n }\n\n addChatEvent(agentChatEvent: AgentChatExchangeEvent) {\n if (isToolRequest(agentChatEvent)) {\n return new AgentChatExchange(\n this.userChatMessage,\n this.agentChatEvents,\n this.agentToolCallGroup.addRequest(agentChatEvent),\n this.id,\n );\n }\n if (isToolResult(agentChatEvent)) {\n return new AgentChatExchange(\n this.userChatMessage,\n this.agentChatEvents,\n this.agentToolCallGroup.addResult(agentChatEvent),\n this.id,\n );\n }\n return new AgentChatExchange(\n this.userChatMessage,\n [...this.agentChatEvents, agentChatEvent],\n this.agentToolCallGroup,\n this.id,\n );\n }\n}\n\nexport type AgentChatExchangeEvent =\n | AgentChatResponse<AgentResponseContent>\n | AgentEndTurn\n | AgentToolCall\n | AgentToolCallGroup;\n"]}
@@ -1,4 +1,6 @@
1
- import { AgentChatResponse, AgentToolRequestResponseContent, AgentToolResultResponseContent } from "@dremio/js-sdk/enterprise";
1
+ import { AgentChatResponse } from "../AgentChatResponse.ts";
2
+ import { AgentToolRequestResponseContent } from "../AgentToolRequestResponseContent.ts";
3
+ import { AgentToolResultResponseContent } from "../AgentToolResultResponseContent.ts";
2
4
  /**
3
5
  * Pairs a tool request with its associated tool result once completed.
4
6
  */
@@ -13,7 +13,9 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { AgentChatResponse, AgentToolRequestResponseContent, AgentToolResultResponseContent, } from "@dremio/js-sdk/enterprise";
16
+ import { AgentChatResponse } from "../AgentChatResponse.js";
17
+ import { AgentToolRequestResponseContent } from "../AgentToolRequestResponseContent.js";
18
+ import { AgentToolResultResponseContent } from "../AgentToolResultResponseContent.js";
17
19
  /**
18
20
  * Pairs a tool request with its associated tool result once completed.
19
21
  */
@@ -1 +1 @@
1
- {"version":3,"file":"AgentToolCall.js","sourceRoot":"","sources":["../../../../../src/enterprise/ai/chat/eventWrappers/AgentToolCall.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,iBAAiB,EACjB,+BAA+B,EAC/B,8BAA8B,GAC/B,MAAM,2BAA2B,CAAC;AAEnC;;GAEG;AACH,MAAM,OAAO,aAAa;IACf,OAAO,CAAqD;IAC5D,MAAM,CAAqD;IAEpE,YAAY,OAAiC,EAAE,MAAgC;QAC7E,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC;IACrC,CAAC;IAED,IAAI,MAAM;QACR,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,IAAI,cAAc,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;YACjD,OAAO,OAAO,CAAC;QACjB,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,MAAM,KAAK,OAAO,CAAC;IACjC,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC;IACnC,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC;IACnC,CAAC;IAED,UAAU,CAAC,QAA2D;QACpE,OAAO,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACnD,CAAC;IAED,MAAM;QACJ,OAAO;YACL,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YAC9B,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE;SACnB,CAAC;IACf,CAAC;CACF;AAED,MAAM,UAAU,aAAa,CAC3B,OAAgB;IAEhB,OAAO,CACL,OAAO,YAAY,iBAAiB;QACpC,OAAO,CAAC,OAAO,YAAY,+BAA+B,CAC3D,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,YAAY,CAC1B,OAAgB;IAEhB,OAAO,CACL,OAAO,YAAY,iBAAiB;QACpC,OAAO,CAAC,OAAO,YAAY,8BAA8B,CAC1D,CAAC;AACJ,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n AgentChatResponse,\n AgentToolRequestResponseContent,\n AgentToolResultResponseContent,\n} from \"@dremio/js-sdk/enterprise\";\n\n/**\n * Pairs a tool request with its associated tool result once completed.\n */\nexport class AgentToolCall {\n readonly request: AgentChatResponse<AgentToolRequestResponseContent>;\n readonly result?: AgentChatResponse<AgentToolResultResponseContent>;\n\n constructor(request: AgentToolCall[\"request\"], result?: AgentToolCall[\"result\"]) {\n this.request = request;\n this.result = result;\n }\n\n get id() {\n return this.request.content.callId;\n }\n\n get status() {\n if (!this.result) {\n return \"pending\";\n }\n\n if (\"errorMessage\" in this.result.content.result) {\n return \"error\";\n }\n\n return \"success\";\n }\n\n get isError() {\n return this.status === \"error\";\n }\n\n get isPending() {\n return this.status === \"pending\";\n }\n\n get isSuccess() {\n return this.status === \"success\";\n }\n\n withResult(response: AgentChatResponse<AgentToolResultResponseContent>) {\n return new AgentToolCall(this.request, response);\n }\n\n toJSON() {\n return {\n id: this.id,\n request: this.request.toJSON(),\n result: this.result?.toJSON(),\n } as unknown;\n }\n}\n\nexport function isToolRequest(\n message: unknown,\n): message is AgentChatResponse<AgentToolRequestResponseContent> {\n return (\n message instanceof AgentChatResponse &&\n message.content instanceof AgentToolRequestResponseContent\n );\n}\n\nexport function isToolResult(\n message: unknown,\n): message is AgentChatResponse<AgentToolResultResponseContent> {\n return (\n message instanceof AgentChatResponse &&\n message.content instanceof AgentToolResultResponseContent\n );\n}\n"]}
1
+ {"version":3,"file":"AgentToolCall.js","sourceRoot":"","sources":["../../../../../src/enterprise/ai/chat/eventWrappers/AgentToolCall.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,+BAA+B,EAAE,MAAM,uCAAuC,CAAC;AACxF,OAAO,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AAEtF;;GAEG;AACH,MAAM,OAAO,aAAa;IACf,OAAO,CAAqD;IAC5D,MAAM,CAAqD;IAEpE,YAAY,OAAiC,EAAE,MAAgC;QAC7E,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC;IACrC,CAAC;IAED,IAAI,MAAM;QACR,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,IAAI,cAAc,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;YACjD,OAAO,OAAO,CAAC;QACjB,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,MAAM,KAAK,OAAO,CAAC;IACjC,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC;IACnC,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC;IACnC,CAAC;IAED,UAAU,CAAC,QAA2D;QACpE,OAAO,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACnD,CAAC;IAED,MAAM;QACJ,OAAO;YACL,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YAC9B,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE;SACnB,CAAC;IACf,CAAC;CACF;AAED,MAAM,UAAU,aAAa,CAC3B,OAAgB;IAEhB,OAAO,CACL,OAAO,YAAY,iBAAiB;QACpC,OAAO,CAAC,OAAO,YAAY,+BAA+B,CAC3D,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,YAAY,CAC1B,OAAgB;IAEhB,OAAO,CACL,OAAO,YAAY,iBAAiB;QACpC,OAAO,CAAC,OAAO,YAAY,8BAA8B,CAC1D,CAAC;AACJ,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { AgentChatResponse } from \"../AgentChatResponse.ts\";\nimport { AgentToolRequestResponseContent } from \"../AgentToolRequestResponseContent.ts\";\nimport { AgentToolResultResponseContent } from \"../AgentToolResultResponseContent.ts\";\n\n/**\n * Pairs a tool request with its associated tool result once completed.\n */\nexport class AgentToolCall {\n readonly request: AgentChatResponse<AgentToolRequestResponseContent>;\n readonly result?: AgentChatResponse<AgentToolResultResponseContent>;\n\n constructor(request: AgentToolCall[\"request\"], result?: AgentToolCall[\"result\"]) {\n this.request = request;\n this.result = result;\n }\n\n get id() {\n return this.request.content.callId;\n }\n\n get status() {\n if (!this.result) {\n return \"pending\";\n }\n\n if (\"errorMessage\" in this.result.content.result) {\n return \"error\";\n }\n\n return \"success\";\n }\n\n get isError() {\n return this.status === \"error\";\n }\n\n get isPending() {\n return this.status === \"pending\";\n }\n\n get isSuccess() {\n return this.status === \"success\";\n }\n\n withResult(response: AgentChatResponse<AgentToolResultResponseContent>) {\n return new AgentToolCall(this.request, response);\n }\n\n toJSON() {\n return {\n id: this.id,\n request: this.request.toJSON(),\n result: this.result?.toJSON(),\n } as unknown;\n }\n}\n\nexport function isToolRequest(\n message: unknown,\n): message is AgentChatResponse<AgentToolRequestResponseContent> {\n return (\n message instanceof AgentChatResponse &&\n message.content instanceof AgentToolRequestResponseContent\n );\n}\n\nexport function isToolResult(\n message: unknown,\n): message is AgentChatResponse<AgentToolResultResponseContent> {\n return (\n message instanceof AgentChatResponse &&\n message.content instanceof AgentToolResultResponseContent\n );\n}\n"]}
@@ -1,5 +1,7 @@
1
1
  import { AgentToolCall } from "./AgentToolCall.ts";
2
- import type { AgentChatResponse, AgentToolRequestResponseContent, AgentToolResultResponseContent } from "@dremio/js-sdk/enterprise";
2
+ import type { AgentChatResponse } from "../AgentChatResponse.ts";
3
+ import type { AgentToolRequestResponseContent } from "../AgentToolRequestResponseContent.ts";
4
+ import type { AgentToolResultResponseContent } from "../AgentToolResultResponseContent.ts";
3
5
  /**
4
6
  * Contains a collection of `AgentToolCall` associated with an `AgentChatExchange`.
5
7
  * As tool calls stream in, this class is updated immutably but maintains
@@ -1 +1 @@
1
- {"version":3,"file":"AgentToolCallGroup.js","sourceRoot":"","sources":["../../../../../src/enterprise/ai/chat/eventWrappers/AgentToolCallGroup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAOnD;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IACpB,EAAE,GAAG,MAAM,EAAE,CAAC;IACd,SAAS,CAAkB;IAEpC,YAAY,SAA0C,EAAE,EAA6B;QACnF,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,EAAE,EAAE,CAAC;YACP,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACf,CAAC;IACH,CAAC;IAED,UAAU,CAAC,WAA+D;QACxE,OAAO,IAAI,kBAAkB,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,EAAE,IAAI,aAAa,CAAC,WAAW,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;IAC9F,CAAC;IAED,SAAS,CAAC,UAA6D;QACrE,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAC/C,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,KAAK,UAAU,CAAC,OAAO,CAAC,MAAM,CACxD,CAAC;QAEF,IAAI,YAAY,KAAK,CAAC,CAAC,EAAE,CAAC;YACxB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,YAAY,CAAE,CAAC;QAElD,OAAO,IAAI,kBAAkB,CAAC;YAC5B,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,YAAY,CAAC;YACxC,QAAQ,CAAC,UAAU,CAAC,UAAU,CAAC;YAC/B,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,YAAY,GAAG,CAAC,CAAC;SAC1C,CAAC,CAAC;IACL,CAAC;IAED,MAAM;QACJ,OAAO;YACL,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;SAC/D,CAAC;IACJ,CAAC;CACF","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { nanoid } from \"nanoid/non-secure\";\nimport { AgentToolCall } from \"./AgentToolCall.ts\";\nimport type {\n AgentChatResponse,\n AgentToolRequestResponseContent,\n AgentToolResultResponseContent,\n} from \"@dremio/js-sdk/enterprise\";\n\n/**\n * Contains a collection of `AgentToolCall` associated with an `AgentChatExchange`.\n * As tool calls stream in, this class is updated immutably but maintains\n * a stable `.id` property.\n */\nexport class AgentToolCallGroup {\n readonly id = nanoid();\n readonly toolCalls: AgentToolCall[];\n\n constructor(toolCalls: AgentToolCallGroup[\"toolCalls\"], id?: AgentToolCallGroup[\"id\"]) {\n this.toolCalls = toolCalls;\n if (id) {\n this.id = id;\n }\n }\n\n addRequest(toolRequest: AgentChatResponse<AgentToolRequestResponseContent>) {\n return new AgentToolCallGroup([...this.toolCalls, new AgentToolCall(toolRequest)], this.id);\n }\n\n addResult(toolResult: AgentChatResponse<AgentToolResultResponseContent>) {\n const requestIndex = this.toolCalls.findLastIndex(\n (toolCall) => toolCall.id === toolResult.content.callId,\n );\n\n if (requestIndex === -1) {\n return this;\n }\n\n const toolCall = this.toolCalls.at(requestIndex)!;\n\n return new AgentToolCallGroup([\n ...this.toolCalls.slice(0, requestIndex),\n toolCall.withResult(toolResult),\n ...this.toolCalls.slice(requestIndex + 1),\n ]);\n }\n\n toJSON() {\n return {\n id: this.id,\n toolCalls: this.toolCalls.map((toolCall) => toolCall.toJSON()),\n };\n }\n}\n"]}
1
+ {"version":3,"file":"AgentToolCallGroup.js","sourceRoot":"","sources":["../../../../../src/enterprise/ai/chat/eventWrappers/AgentToolCallGroup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAKnD;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IACpB,EAAE,GAAG,MAAM,EAAE,CAAC;IACd,SAAS,CAAkB;IAEpC,YAAY,SAA0C,EAAE,EAA6B;QACnF,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,EAAE,EAAE,CAAC;YACP,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACf,CAAC;IACH,CAAC;IAED,UAAU,CAAC,WAA+D;QACxE,OAAO,IAAI,kBAAkB,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,EAAE,IAAI,aAAa,CAAC,WAAW,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;IAC9F,CAAC;IAED,SAAS,CAAC,UAA6D;QACrE,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAC/C,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,KAAK,UAAU,CAAC,OAAO,CAAC,MAAM,CACxD,CAAC;QAEF,IAAI,YAAY,KAAK,CAAC,CAAC,EAAE,CAAC;YACxB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,YAAY,CAAE,CAAC;QAElD,OAAO,IAAI,kBAAkB,CAAC;YAC5B,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,YAAY,CAAC;YACxC,QAAQ,CAAC,UAAU,CAAC,UAAU,CAAC;YAC/B,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,YAAY,GAAG,CAAC,CAAC;SAC1C,CAAC,CAAC;IACL,CAAC;IAED,MAAM;QACJ,OAAO;YACL,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;SAC/D,CAAC;IACJ,CAAC;CACF","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { nanoid } from \"nanoid/non-secure\";\nimport { AgentToolCall } from \"./AgentToolCall.ts\";\nimport type { AgentChatResponse } from \"../AgentChatResponse.ts\";\nimport type { AgentToolRequestResponseContent } from \"../AgentToolRequestResponseContent.ts\";\nimport type { AgentToolResultResponseContent } from \"../AgentToolResultResponseContent.ts\";\n\n/**\n * Contains a collection of `AgentToolCall` associated with an `AgentChatExchange`.\n * As tool calls stream in, this class is updated immutably but maintains\n * a stable `.id` property.\n */\nexport class AgentToolCallGroup {\n readonly id = nanoid();\n readonly toolCalls: AgentToolCall[];\n\n constructor(toolCalls: AgentToolCallGroup[\"toolCalls\"], id?: AgentToolCallGroup[\"id\"]) {\n this.toolCalls = toolCalls;\n if (id) {\n this.id = id;\n }\n }\n\n addRequest(toolRequest: AgentChatResponse<AgentToolRequestResponseContent>) {\n return new AgentToolCallGroup([...this.toolCalls, new AgentToolCall(toolRequest)], this.id);\n }\n\n addResult(toolResult: AgentChatResponse<AgentToolResultResponseContent>) {\n const requestIndex = this.toolCalls.findLastIndex(\n (toolCall) => toolCall.id === toolResult.content.callId,\n );\n\n if (requestIndex === -1) {\n return this;\n }\n\n const toolCall = this.toolCalls.at(requestIndex)!;\n\n return new AgentToolCallGroup([\n ...this.toolCalls.slice(0, requestIndex),\n toolCall.withResult(toolResult),\n ...this.toolCalls.slice(requestIndex + 1),\n ]);\n }\n\n toJSON() {\n return {\n id: this.id,\n toolCalls: this.toolCalls.map((toolCall) => toolCall.toJSON()),\n };\n }\n}\n"]}
@@ -48,7 +48,7 @@ export declare class EnterpriseUser extends User {
48
48
  source: string;
49
49
  constructor(properties: EnterpriseUserProperties, config: V3Config & SonarV3Config);
50
50
  save(properties: EnterpriseUserPatchableProperties): import("ts-results-es").AsyncResult<EnterpriseUser, import("../index.ts").HttpError>;
51
- grants({ signal }?: SignalParam): import("ts-results-es").AsyncResult<import("../index.ts").Grant[], import("../index.ts").HttpError>;
51
+ grants({ signal }?: SignalParam): import("ts-results-es").AsyncResult<import("../interfaces.ts").Grant[], import("../index.ts").HttpError>;
52
52
  tokens({ signal }?: SignalParam): Promise<import("ts-results-es").Result<{
53
53
  createdAt: Date;
54
54
  expiresAt: Date;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dremio/js-sdk",
3
- "version": "0.33.1",
3
+ "version": "0.34.1",
4
4
  "description": "JavaScript library for the Dremio API",
5
5
  "keywords": [
6
6
  "dremio",