@dremio/js-sdk 0.46.0 → 0.46.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,6 +10,7 @@ import type { SignalParam } from "../../common/Params.ts";
10
10
  import { type createConversationCodec } from "../../enterprise/ai/conversations/methods/createConversation.ts";
11
11
  import type { ChatEvent } from "../../enterprise/ai/chat/chatEventSchema.ts";
12
12
  import type { HttpError } from "../../common/HttpError.ts";
13
+ import { AgentConversation } from "../../enterprise/ai/conversations/AgentConversation.ts";
13
14
  export declare class AIResource {
14
15
  #private;
15
16
  constructor(config: Logger & V4Config & SonarV4Config);
@@ -84,11 +85,29 @@ export declare class AIResource {
84
85
  } | {
85
86
  type: "REFRESH_HISTORY";
86
87
  }, {
87
- [x: string]: import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<import("../../enterprise/interfaces.ts").AgentConversation, {
88
+ [x: string]: import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<{
89
+ createdAt: import("temporal-polyfill").Temporal.Instant;
90
+ currentRunId: string | null;
91
+ id: string;
92
+ modelName: string | null;
93
+ modelProviderId: string | null;
94
+ modifiedAt: import("temporal-polyfill").Temporal.Instant;
95
+ tag: string;
96
+ title: string | null;
97
+ }, {
88
98
  message: UserChatMessage;
89
99
  modelName?: string | undefined;
90
100
  modelProviderId?: string | undefined;
91
- }, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<import("../../enterprise/interfaces.ts").AgentConversation, {
101
+ }, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<{
102
+ createdAt: import("temporal-polyfill").Temporal.Instant;
103
+ currentRunId: string | null;
104
+ id: string;
105
+ modelName: string | null;
106
+ modelProviderId: string | null;
107
+ modifiedAt: import("temporal-polyfill").Temporal.Instant;
108
+ tag: string;
109
+ title: string | null;
110
+ }, {
92
111
  conversationId: string;
93
112
  }, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<{
94
113
  data: ({
@@ -199,7 +218,16 @@ export declare class AIResource {
199
218
  }, {
200
219
  conversationId: string;
201
220
  }, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<{
202
- conversation: import("../../enterprise/interfaces.ts").AgentConversation;
221
+ conversation: {
222
+ createdAt: import("temporal-polyfill").Temporal.Instant;
223
+ currentRunId: string | null;
224
+ id: string;
225
+ modelName: string | null;
226
+ modelProviderId: string | null;
227
+ modifiedAt: import("temporal-polyfill").Temporal.Instant;
228
+ tag: string;
229
+ title: string | null;
230
+ };
203
231
  history: {
204
232
  data: ({
205
233
  conversationId: string;
@@ -437,7 +465,16 @@ export declare class AIResource {
437
465
  }, import("xstate").EventObject>> | undefined;
438
466
  }, {
439
467
  src: "createConversation";
440
- logic: import("xstate").PromiseActorLogic<import("../../enterprise/interfaces.ts").AgentConversation, {
468
+ logic: import("xstate").PromiseActorLogic<{
469
+ createdAt: import("temporal-polyfill").Temporal.Instant;
470
+ currentRunId: string | null;
471
+ id: string;
472
+ modelName: string | null;
473
+ modelProviderId: string | null;
474
+ modifiedAt: import("temporal-polyfill").Temporal.Instant;
475
+ tag: string;
476
+ title: string | null;
477
+ }, {
441
478
  message: UserChatMessage;
442
479
  modelName?: string | undefined;
443
480
  modelProviderId?: string | undefined;
@@ -445,7 +482,16 @@ export declare class AIResource {
445
482
  id: string | undefined;
446
483
  } | {
447
484
  src: "retrieveConversation";
448
- logic: import("xstate").PromiseActorLogic<import("../../enterprise/interfaces.ts").AgentConversation, {
485
+ logic: import("xstate").PromiseActorLogic<{
486
+ createdAt: import("temporal-polyfill").Temporal.Instant;
487
+ currentRunId: string | null;
488
+ id: string;
489
+ modelName: string | null;
490
+ modelProviderId: string | null;
491
+ modifiedAt: import("temporal-polyfill").Temporal.Instant;
492
+ tag: string;
493
+ title: string | null;
494
+ }, {
449
495
  conversationId: string;
450
496
  }, import("xstate").EventObject>;
451
497
  id: string | undefined;
@@ -564,7 +610,16 @@ export declare class AIResource {
564
610
  } | {
565
611
  src: "retrieveState";
566
612
  logic: import("xstate").PromiseActorLogic<{
567
- conversation: import("../../enterprise/interfaces.ts").AgentConversation;
613
+ conversation: {
614
+ createdAt: import("temporal-polyfill").Temporal.Instant;
615
+ currentRunId: string | null;
616
+ id: string;
617
+ modelName: string | null;
618
+ modelProviderId: string | null;
619
+ modifiedAt: import("temporal-polyfill").Temporal.Instant;
620
+ tag: string;
621
+ title: string | null;
622
+ };
568
623
  history: {
569
624
  data: ({
570
625
  conversationId: string;
@@ -842,9 +897,9 @@ export declare class AIResource {
842
897
  readonly uninitialized: {};
843
898
  };
844
899
  }>;
845
- createConversation(body: z.input<typeof createConversationCodec>): import("ts-results-es").AsyncResult<import("../../enterprise/interfaces.ts").AgentConversation, HttpError>;
900
+ createConversation(body: z.input<typeof createConversationCodec>): import("ts-results-es").AsyncResult<AgentConversation, HttpError>;
846
901
  listConversations(): {
847
- data({ signal }?: SignalParam): AsyncGenerator<import("ts-results-es").Ok<import("../../enterprise/interfaces.ts").AgentConversation> | import("ts-results-es").Err<z.core.$ZodError<{
902
+ data({ signal }?: SignalParam): AsyncGenerator<import("ts-results-es").Err<z.core.$ZodError<{
848
903
  createdAt: import("temporal-polyfill").Temporal.Instant;
849
904
  currentRunId: string | null;
850
905
  id: string;
@@ -853,11 +908,11 @@ export declare class AIResource {
853
908
  modifiedAt: import("temporal-polyfill").Temporal.Instant;
854
909
  tag: string;
855
910
  title: string | null;
856
- }>>, void, unknown>;
911
+ }>> | import("ts-results-es").Ok<AgentConversation>, void, unknown>;
857
912
  getPage: (params: {
858
913
  maxResults: number;
859
914
  }, { signal }?: SignalParam) => import("ts-results-es").AsyncResult<{
860
- data: (import("ts-results-es").Ok<import("../../enterprise/interfaces.ts").AgentConversation> | import("ts-results-es").Err<z.core.$ZodError<{
915
+ data: (import("ts-results-es").Err<z.core.$ZodError<{
861
916
  createdAt: import("temporal-polyfill").Temporal.Instant;
862
917
  currentRunId: string | null;
863
918
  id: string;
@@ -866,10 +921,10 @@ export declare class AIResource {
866
921
  modifiedAt: import("temporal-polyfill").Temporal.Instant;
867
922
  tag: string;
868
923
  title: string | null;
869
- }>>)[];
924
+ }>> | import("ts-results-es").Ok<AgentConversation>)[];
870
925
  }, HttpError>;
871
926
  };
872
- retrieveConversation(id: string, { signal }?: SignalParam): import("ts-results-es").AsyncResult<import("../../enterprise/interfaces.ts").AgentConversation, HttpError | import("zod").ZodError<{
927
+ retrieveConversation(id: string, { signal }?: SignalParam): import("ts-results-es").AsyncResult<{
873
928
  createdAt: import("temporal-polyfill").Temporal.Instant;
874
929
  currentRunId: string | null;
875
930
  id: string;
@@ -878,7 +933,7 @@ export declare class AIResource {
878
933
  modifiedAt: import("temporal-polyfill").Temporal.Instant;
879
934
  tag: string;
880
935
  title: string | null;
881
- }>>;
936
+ }, HttpError>;
882
937
  retrieveConversationHistory(id: string): {
883
938
  data(): AsyncGenerator<ChatEvent, void, HttpError>;
884
939
  };
@@ -27,6 +27,7 @@ import { createConversation, } from "../../enterprise/ai/conversations/methods/c
27
27
  import { retrieveConversation } from "../../enterprise/ai/conversations/methods/retrieveConversation.js";
28
28
  import { retrieveConversationHistory } from "../../enterprise/ai/conversations/methods/retrieveConversationHistory.js";
29
29
  import { createConversationMachine } from "../../enterprise/ai/conversations/createConversationMachine.js";
30
+ import { AgentConversation } from "../../enterprise/ai/conversations/AgentConversation.js";
30
31
  export class AIResource {
31
32
  #config;
32
33
  constructor(config) {
@@ -51,7 +52,7 @@ export class AIResource {
51
52
  return createConversationMachine(this.#config);
52
53
  }
53
54
  createConversation(body) {
54
- return createConversation(this.#config)(body);
55
+ return createConversation(this.#config)(body).map((properties) => new AgentConversation(this.#config, properties));
55
56
  }
56
57
  listConversations() {
57
58
  const getPage = listConversations(this.#config);
@@ -1 +1 @@
1
- {"version":3,"file":"AIResource.js","sourceRoot":"","sources":["../../../src/cloud/ai/AIResource.ts"],"names":[],"m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;aACF,CAAC,CAAC,CAAC;QACR,CAAC,CAAC;QACF,OAAO;YACL,KAAK,CAAC,CAAC,IAAI,CAAC,EAAE,MAAM,KAAkB,EAAE;gBACtC,KAAK,CAAC,CAAC,CAAC,MAAM,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;YACvF,CAAC;YACD,OAAO;SACR,CAAC;IACJ,CAAC;IAED,mBAAmB,CAAC,GAAG,IAAwD;QAC7E,OAAO,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IACpD,CAAC;IAED,qBAAqB,CAAC,EAAU;QAC9B,OAAO,IAAI,CAAC,OAAO;aAChB,SAAS,CAAC,yBAAyB,EAAE,EAAE,EAAE;YACxC,OAAO,EAAE;gBACP,MAAM,EAAE,kBAAkB;aAC3B;SACF,CAAC;aACD,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAyD,CAAC;aAC/E,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,uBAAuB,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;IACxE,CAAC;IAED;;;;;OAKG;IACH,eAAe,CAAC,WAAwB,EAAE,eAAgC;QACxE,OAAO,qBAAqB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;IAC3E,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 { ChatSession } from \"../../enterprise/ai/chat/ChatSession.ts\";\nimport type { UserChatMessage } from \"../../enterprise/ai/chat/UserChatMessage.ts\";\nimport type { Logger, SonarV4Config, V4Config } from \"../../common/Config.ts\";\nimport { ModelProvider } from \"../../enterprise/ai/modelProvider/ModelProvider.ts\";\nimport * as z from \"zod/mini\";\nimport {\n dremioProvidedSchema,\n modelProviderCreateCodec,\n modelProviderRetrieveCodec,\n safeDecodeModelProvider,\n type SafeDecodeResultWithoutDremioLLM,\n} from \"./modelProviderCodec.js\";\nimport { modelProviderRetrieveCodec as baseModelProviderRetrieveCodec } from \"../../enterprise/ai/modelProvider/modelProviderCodec.ts\";\nimport { DremioModelProvider } from \"./DremioModelProvider.ts\";\nimport { safeParseResultToResult } from \"../../common/safeParseResultToResult.ts\";\nimport { listAvailableModels } from \"../../enterprise/ai/AIResource.ts\";\nimport type { SignalParam } from \"../../common/Params.ts\";\nimport { createSendChatMessage } from \"../../enterprise/ai/chat/methods/sendChatMessage.ts\";\nimport { listConversations } from \"../../enterprise/ai/conversations/methods/listConversations.ts\";\nimport {\n createConversation,\n type createConversationCodec,\n} from \"../../enterprise/ai/conversations/methods/createConversation.ts\";\nimport { retrieveConversation } from \"../../enterprise/ai/conversations/methods/retrieveConversation.ts\";\nimport { retrieveConversationHistory } from \"../../enterprise/ai/conversations/methods/retrieveConversationHistory.ts\";\nimport type { ChatEvent } from \"../../enterprise/ai/chat/chatEventSchema.ts\";\nimport type { HttpError } from \"../../common/HttpError.ts\";\nimport { createConversationMachine } from \"../../enterprise/ai/conversations/createConversationMachine.ts\";\n\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 .andThen(\n (entity) =>\n safeDecodeModelProvider(this.#config, entity) as SafeDecodeResultWithoutDremioLLM,\n );\n }\n\n get conversationMachine() {\n return createConversationMachine(this.#config);\n }\n\n createConversation(body: z.input<typeof createConversationCodec>) {\n return createConversation(this.#config)(body);\n }\n\n listConversations() {\n const getPage = listConversations(this.#config);\n return {\n async *data({ signal }: SignalParam = {}) {\n yield* (\n await getPage({ maxResults: 100 }, { signal }).map((response) => response.data).promise\n ).unwrap();\n },\n getPage,\n };\n }\n\n retrieveConversation(id: string, { signal }: SignalParam = {}) {\n return retrieveConversation(this.#config)(id, { signal });\n }\n\n retrieveConversationHistory(id: string) {\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n const getPage = (params: {}, { signal }: SignalParam = {}) =>\n retrieveConversationHistory(this.#config)(id, { signal });\n return {\n async *data(): AsyncGenerator<ChatEvent, void, HttpError> {\n const history = await getPage({}).then((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n });\n yield* history.data;\n },\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) => {\n if (\"dremioProvided\" in properties.config) {\n return new DremioModelProvider(\n this.#config,\n properties as z.infer<typeof dremioProvidedSchema>,\n );\n }\n return new ModelProvider(\n this.#config,\n properties as z.output<typeof baseModelProviderRetrieveCodec>,\n );\n },\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(...args: Parameters<ReturnType<typeof listAvailableModels>>) {\n return listAvailableModels(this.#config)(...args);\n }\n\n retrieveModelProvider(id: string) {\n return this.#config\n .v4Request(`model-provider/config/${id}`, {\n headers: {\n Accept: \"application/json\",\n },\n })\n .map((res) => res.json() as Promise<z.input<typeof modelProviderRetrieveCodec>>)\n .andThen((entity) => safeDecodeModelProvider(this.#config, entity));\n }\n\n /**\n * Sends a chat message to the Dremio AI Agent and returns an Observable containing\n * Agent replies.\n *\n * @deprecated\n */\n sendChatMessage(chatSession: ChatSession, userChatMessage: UserChatMessage) {\n return createSendChatMessage(this.#config)(chatSession, userChatMessage);\n }\n}\n"]}
1
+ {"version":3,"file":"AIResource.js","sourceRoot":"","sources":["../../../src/cloud/ai/AIResource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AAGtE,OAAO,EAAE,aAAa,EAAE,MAAM,oDAAoD,CAAC;AACnF,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,0BAA0B,EAC1B,uBAAuB,GAExB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,0BAA0B,IAAI,8BAA8B,EAAE,MAAM,yDAAyD,CAAC;AACvI,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAClF,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAExE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qDAAqD,CAAC;AAC5F,OAAO,EAAE,iBAAiB,EAAE,MAAM,gEAAgE,CAAC;AACnG,OAAO,EACL,kBAAkB,GAEnB,MAAM,iEAAiE,CAAC;AACz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QAC9B,OAAO,IAAI,CAAC,OAAO;aAChB,SAAS,CAAC,yBAAyB,EAAE,EAAE,EAAE;YACxC,OAAO,EAAE;gBACP,MAAM,EAAE,kBAAkB;aAC3B;SACF,CAAC;aACD,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAyD,CAAC;aAC/E,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,uBAAuB,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;IACxE,CAAC;IAED;;;;;OAKG;IACH,eAAe,CAAC,WAAwB,EAAE,eAAgC;QACxE,OAAO,qBAAqB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;IAC3E,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 { ChatSession } from \"../../enterprise/ai/chat/ChatSession.ts\";\nimport type { UserChatMessage } from \"../../enterprise/ai/chat/UserChatMessage.ts\";\nimport type { Logger, SonarV4Config, V4Config } from \"../../common/Config.ts\";\nimport { ModelProvider } from \"../../enterprise/ai/modelProvider/ModelProvider.ts\";\nimport * as z from \"zod/mini\";\nimport {\n dremioProvidedSchema,\n modelProviderCreateCodec,\n modelProviderRetrieveCodec,\n safeDecodeModelProvider,\n type SafeDecodeResultWithoutDremioLLM,\n} from \"./modelProviderCodec.js\";\nimport { modelProviderRetrieveCodec as baseModelProviderRetrieveCodec } from \"../../enterprise/ai/modelProvider/modelProviderCodec.ts\";\nimport { DremioModelProvider } from \"./DremioModelProvider.ts\";\nimport { safeParseResultToResult } from \"../../common/safeParseResultToResult.ts\";\nimport { listAvailableModels } from \"../../enterprise/ai/AIResource.ts\";\nimport type { SignalParam } from \"../../common/Params.ts\";\nimport { createSendChatMessage } from \"../../enterprise/ai/chat/methods/sendChatMessage.ts\";\nimport { listConversations } from \"../../enterprise/ai/conversations/methods/listConversations.ts\";\nimport {\n createConversation,\n type createConversationCodec,\n} from \"../../enterprise/ai/conversations/methods/createConversation.ts\";\nimport { retrieveConversation } from \"../../enterprise/ai/conversations/methods/retrieveConversation.ts\";\nimport { retrieveConversationHistory } from \"../../enterprise/ai/conversations/methods/retrieveConversationHistory.ts\";\nimport type { ChatEvent } from \"../../enterprise/ai/chat/chatEventSchema.ts\";\nimport type { HttpError } from \"../../common/HttpError.ts\";\nimport { createConversationMachine } from \"../../enterprise/ai/conversations/createConversationMachine.ts\";\nimport { AgentConversation } from \"../../enterprise/ai/conversations/AgentConversation.ts\";\n\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 .andThen(\n (entity) =>\n safeDecodeModelProvider(this.#config, entity) as SafeDecodeResultWithoutDremioLLM,\n );\n }\n\n get conversationMachine() {\n return createConversationMachine(this.#config);\n }\n\n createConversation(body: z.input<typeof createConversationCodec>) {\n return createConversation(this.#config)(body).map(\n (properties) => new AgentConversation(this.#config, properties),\n );\n }\n\n listConversations() {\n const getPage = listConversations(this.#config);\n return {\n async *data({ signal }: SignalParam = {}) {\n yield* (\n await getPage({ maxResults: 100 }, { signal }).map((response) => response.data).promise\n ).unwrap();\n },\n getPage,\n };\n }\n\n retrieveConversation(id: string, { signal }: SignalParam = {}) {\n return retrieveConversation(this.#config)(id, { signal });\n }\n\n retrieveConversationHistory(id: string) {\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n const getPage = (params: {}, { signal }: SignalParam = {}) =>\n retrieveConversationHistory(this.#config)(id, { signal });\n return {\n async *data(): AsyncGenerator<ChatEvent, void, HttpError> {\n const history = await getPage({}).then((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n });\n yield* history.data;\n },\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) => {\n if (\"dremioProvided\" in properties.config) {\n return new DremioModelProvider(\n this.#config,\n properties as z.infer<typeof dremioProvidedSchema>,\n );\n }\n return new ModelProvider(\n this.#config,\n properties as z.output<typeof baseModelProviderRetrieveCodec>,\n );\n },\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(...args: Parameters<ReturnType<typeof listAvailableModels>>) {\n return listAvailableModels(this.#config)(...args);\n }\n\n retrieveModelProvider(id: string) {\n return this.#config\n .v4Request(`model-provider/config/${id}`, {\n headers: {\n Accept: \"application/json\",\n },\n })\n .map((res) => res.json() as Promise<z.input<typeof modelProviderRetrieveCodec>>)\n .andThen((entity) => safeDecodeModelProvider(this.#config, entity));\n }\n\n /**\n * Sends a chat message to the Dremio AI Agent and returns an Observable containing\n * Agent replies.\n *\n * @deprecated\n */\n sendChatMessage(chatSession: ChatSession, userChatMessage: UserChatMessage) {\n return createSendChatMessage(this.#config)(chatSession, userChatMessage);\n }\n}\n"]}
@@ -7,8 +7,9 @@ import { modelProviderCreateCodec } from "./modelProvider/modelProviderCodec.ts"
7
7
  import type { SignalParam } from "../../common/Params.ts";
8
8
  import { listModelsPropertiesSchema } from "./modelProvider/modelProviderConfigSchemas.ts";
9
9
  import { createConversationCodec } from "./conversations/methods/createConversation.ts";
10
- import { AgentConversation, type ChatEvent } from "../interfaces.ts";
11
10
  import type { HttpError } from "../../common/HttpError.ts";
11
+ import { AgentConversation } from "./conversations/AgentConversation.ts";
12
+ import type { ChatEvent } from "./chat/chatEventSchema.ts";
12
13
  export declare function listAvailableModels(config: V4Config): (properties: z.infer<typeof listModelsPropertiesSchema>, { signal }?: SignalParam) => import("ts-results-es").AsyncResult<Set<{
13
14
  name: string;
14
15
  isRecommended: boolean;
@@ -26,11 +27,29 @@ export declare class AIResource {
26
27
  } | {
27
28
  type: "REFRESH_HISTORY";
28
29
  }, {
29
- [x: string]: import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<AgentConversation, {
30
+ [x: string]: import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<{
31
+ createdAt: import("temporal-polyfill").Temporal.Instant;
32
+ currentRunId: string | null;
33
+ id: string;
34
+ modelName: string | null;
35
+ modelProviderId: string | null;
36
+ modifiedAt: import("temporal-polyfill").Temporal.Instant;
37
+ tag: string;
38
+ title: string | null;
39
+ }, {
30
40
  message: UserChatMessage;
31
41
  modelName?: string | undefined;
32
42
  modelProviderId?: string | undefined;
33
- }, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<AgentConversation, {
43
+ }, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<{
44
+ createdAt: import("temporal-polyfill").Temporal.Instant;
45
+ currentRunId: string | null;
46
+ id: string;
47
+ modelName: string | null;
48
+ modelProviderId: string | null;
49
+ modifiedAt: import("temporal-polyfill").Temporal.Instant;
50
+ tag: string;
51
+ title: string | null;
52
+ }, {
34
53
  conversationId: string;
35
54
  }, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<{
36
55
  data: ({
@@ -141,7 +160,16 @@ export declare class AIResource {
141
160
  }, {
142
161
  conversationId: string;
143
162
  }, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<{
144
- conversation: AgentConversation;
163
+ conversation: {
164
+ createdAt: import("temporal-polyfill").Temporal.Instant;
165
+ currentRunId: string | null;
166
+ id: string;
167
+ modelName: string | null;
168
+ modelProviderId: string | null;
169
+ modifiedAt: import("temporal-polyfill").Temporal.Instant;
170
+ tag: string;
171
+ title: string | null;
172
+ };
145
173
  history: {
146
174
  data: ({
147
175
  conversationId: string;
@@ -379,7 +407,16 @@ export declare class AIResource {
379
407
  }, import("xstate").EventObject>> | undefined;
380
408
  }, {
381
409
  src: "createConversation";
382
- logic: import("xstate").PromiseActorLogic<AgentConversation, {
410
+ logic: import("xstate").PromiseActorLogic<{
411
+ createdAt: import("temporal-polyfill").Temporal.Instant;
412
+ currentRunId: string | null;
413
+ id: string;
414
+ modelName: string | null;
415
+ modelProviderId: string | null;
416
+ modifiedAt: import("temporal-polyfill").Temporal.Instant;
417
+ tag: string;
418
+ title: string | null;
419
+ }, {
383
420
  message: UserChatMessage;
384
421
  modelName?: string | undefined;
385
422
  modelProviderId?: string | undefined;
@@ -387,7 +424,16 @@ export declare class AIResource {
387
424
  id: string | undefined;
388
425
  } | {
389
426
  src: "retrieveConversation";
390
- logic: import("xstate").PromiseActorLogic<AgentConversation, {
427
+ logic: import("xstate").PromiseActorLogic<{
428
+ createdAt: import("temporal-polyfill").Temporal.Instant;
429
+ currentRunId: string | null;
430
+ id: string;
431
+ modelName: string | null;
432
+ modelProviderId: string | null;
433
+ modifiedAt: import("temporal-polyfill").Temporal.Instant;
434
+ tag: string;
435
+ title: string | null;
436
+ }, {
391
437
  conversationId: string;
392
438
  }, import("xstate").EventObject>;
393
439
  id: string | undefined;
@@ -506,7 +552,16 @@ export declare class AIResource {
506
552
  } | {
507
553
  src: "retrieveState";
508
554
  logic: import("xstate").PromiseActorLogic<{
509
- conversation: AgentConversation;
555
+ conversation: {
556
+ createdAt: import("temporal-polyfill").Temporal.Instant;
557
+ currentRunId: string | null;
558
+ id: string;
559
+ modelName: string | null;
560
+ modelProviderId: string | null;
561
+ modifiedAt: import("temporal-polyfill").Temporal.Instant;
562
+ tag: string;
563
+ title: string | null;
564
+ };
510
565
  history: {
511
566
  data: ({
512
567
  conversationId: string;
@@ -787,7 +842,7 @@ export declare class AIResource {
787
842
  createConversation(body: z.input<typeof createConversationCodec>): import("ts-results-es").AsyncResult<AgentConversation, HttpError>;
788
843
  createModelProvider(properties: z.output<typeof modelProviderCreateCodec>): import("ts-results-es").AsyncResult<ModelProvider, HttpError>;
789
844
  listConversations(): {
790
- data({ signal }?: SignalParam): AsyncGenerator<import("ts-results-es").Ok<AgentConversation> | import("ts-results-es").Err<z.core.$ZodError<{
845
+ data({ signal }?: SignalParam): AsyncGenerator<import("ts-results-es").Err<z.core.$ZodError<{
791
846
  createdAt: import("temporal-polyfill").Temporal.Instant;
792
847
  currentRunId: string | null;
793
848
  id: string;
@@ -796,11 +851,11 @@ export declare class AIResource {
796
851
  modifiedAt: import("temporal-polyfill").Temporal.Instant;
797
852
  tag: string;
798
853
  title: string | null;
799
- }>>, void, unknown>;
854
+ }>> | import("ts-results-es").Ok<AgentConversation>, void, unknown>;
800
855
  getPage: (params: {
801
856
  maxResults: number;
802
857
  }, { signal }?: SignalParam) => import("ts-results-es").AsyncResult<{
803
- data: (import("ts-results-es").Ok<AgentConversation> | import("ts-results-es").Err<z.core.$ZodError<{
858
+ data: (import("ts-results-es").Err<z.core.$ZodError<{
804
859
  createdAt: import("temporal-polyfill").Temporal.Instant;
805
860
  currentRunId: string | null;
806
861
  id: string;
@@ -809,7 +864,7 @@ export declare class AIResource {
809
864
  modifiedAt: import("temporal-polyfill").Temporal.Instant;
810
865
  tag: string;
811
866
  title: string | null;
812
- }>>)[];
867
+ }>> | import("ts-results-es").Ok<AgentConversation>)[];
813
868
  }, HttpError>;
814
869
  };
815
870
  listModelProviders(): {
@@ -922,16 +977,7 @@ export declare class AIResource {
922
977
  name: string;
923
978
  isRecommended: boolean;
924
979
  }>, HttpError>;
925
- retrieveConversation(id: string, { signal }?: SignalParam): import("ts-results-es").AsyncResult<AgentConversation, HttpError | import("zod").ZodError<{
926
- createdAt: import("temporal-polyfill").Temporal.Instant;
927
- currentRunId: string | null;
928
- id: string;
929
- modelName: string | null;
930
- modelProviderId: string | null;
931
- modifiedAt: import("temporal-polyfill").Temporal.Instant;
932
- tag: string;
933
- title: string | null;
934
- }>>;
980
+ retrieveConversation(id: string, { signal }?: SignalParam): import("ts-results-es").AsyncResult<AgentConversation, HttpError>;
935
981
  retrieveConversationHistory(id: string): {
936
982
  data(): AsyncGenerator<ChatEvent, void, HttpError>;
937
983
  };
@@ -942,5 +988,5 @@ export declare class AIResource {
942
988
  *
943
989
  * @deprecated
944
990
  */
945
- sendChatMessage(chatSession: ChatSession, userChatMessage: UserChatMessage): import("rxjs").Observable<import("ts-results-es").Ok<import("../interfaces.ts").AgentChatResponse<import("../interfaces.ts").AgentResponseContent>> | import("ts-results-es").Err<HttpError | import("../index.ts").Problem<"https://api.dremio.dev/problems/ai-agent/chat/agent-disabled" | "https://api.dremio.dev/problems/ai-agent/chat/input-too-large" | "https://api.dremio.dev/problems/ai-agent/chat/model-provider-not-found" | "https://api.dremio.dev/problems/ai-agent/chat/no-default-model-provider" | "https://api.dremio.dev/problems/ai-agent/chat/no-model-provider-privilege" | "https://api.dremio.dev/problems/ai-agent/chat/preview-disabled" | "https://api.dremio.dev/problems/ai-agent/chat/rate-limit-exceeded", undefined>>>;
991
+ sendChatMessage(chatSession: ChatSession, userChatMessage: UserChatMessage): import("rxjs").Observable<import("ts-results-es").Ok<import("./index.ts").AgentChatResponse<import("./index.ts").AgentResponseContent>> | import("ts-results-es").Err<HttpError | import("../index.ts").Problem<"https://api.dremio.dev/problems/ai-agent/chat/agent-disabled" | "https://api.dremio.dev/problems/ai-agent/chat/input-too-large" | "https://api.dremio.dev/problems/ai-agent/chat/model-provider-not-found" | "https://api.dremio.dev/problems/ai-agent/chat/no-default-model-provider" | "https://api.dremio.dev/problems/ai-agent/chat/no-model-provider-privilege" | "https://api.dremio.dev/problems/ai-agent/chat/preview-disabled" | "https://api.dremio.dev/problems/ai-agent/chat/rate-limit-exceeded", undefined>>>;
946
992
  }
@@ -23,9 +23,9 @@ import { createSendChatMessage } from "./chat/methods/sendChatMessage.js";
23
23
  import { listConversations } from "./conversations/methods/listConversations.js";
24
24
  import { createConversation, createConversationCodec, } from "./conversations/methods/createConversation.js";
25
25
  import { retrieveConversation } from "./conversations/methods/retrieveConversation.js";
26
- import { AgentConversation } from "../interfaces.js";
27
26
  import { retrieveConversationHistory } from "./conversations/methods/retrieveConversationHistory.js";
28
27
  import { createConversationMachine } from "./conversations/createConversationMachine.js";
28
+ import { AgentConversation } from "./conversations/AgentConversation.js";
29
29
  export function listAvailableModels(config) {
30
30
  return function listAvailableModels(properties, { signal } = {}) {
31
31
  return config
@@ -51,7 +51,7 @@ export class AIResource {
51
51
  return createConversationMachine(this.#config);
52
52
  }
53
53
  createConversation(body) {
54
- return createConversation(this.#config)(body);
54
+ return createConversation(this.#config)(body).map((properties) => new AgentConversation(this.#config, properties));
55
55
  }
56
56
  createModelProvider(properties) {
57
57
  const body = z.encode(modelProviderCreateCodec, properties);
@@ -1 +1 @@
1
- {"version":3,"file":"AIResource.js","sourceRoot":"","sources":["../../../src/enterprise/ai/AIResource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpD,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,KAAK,CAAC,MAAM,U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CAAC;IACN,CAAC;IAED;;;;;OAKG;IACH,eAAe,CAAC,WAAwB,EAAE,eAAgC;QACxE,OAAO,qBAAqB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;IAC3E,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 { ChatSession } from \"./chat/ChatSession.ts\";\nimport type { UserChatMessage } from \"./chat/UserChatMessage.ts\";\nimport type { Logger, SonarV4Config, V4Config } from \"../../common/Config.ts\";\nimport { ModelProvider } from \"./modelProvider/ModelProvider.ts\";\nimport * as z from \"zod/mini\";\nimport {\n modelProviderCreateCodec,\n modelProviderRetrieveCodec,\n} from \"./modelProvider/modelProviderCodec.ts\";\nimport type { SignalParam } from \"../../common/Params.ts\";\nimport { safeParseResultToResult } from \"../../common/safeParseResultToResult.ts\";\nimport { listModelsPropertiesSchema } from \"./modelProvider/modelProviderConfigSchemas.ts\";\nimport { createSendChatMessage } from \"./chat/methods/sendChatMessage.ts\";\nimport { listConversations } from \"./conversations/methods/listConversations.ts\";\nimport {\n createConversation,\n createConversationCodec,\n} from \"./conversations/methods/createConversation.ts\";\nimport { retrieveConversation } from \"./conversations/methods/retrieveConversation.ts\";\nimport { AgentConversation, type ChatEvent } from \"../interfaces.ts\";\nimport { retrieveConversationHistory } from \"./conversations/methods/retrieveConversationHistory.ts\";\nimport type { HttpError } from \"../../common/HttpError.ts\";\nimport { createConversationMachine } from \"./conversations/createConversationMachine.ts\";\n\nexport function listAvailableModels(config: V4Config) {\n return function listAvailableModels(\n properties: z.infer<typeof listModelsPropertiesSchema>,\n { signal }: SignalParam = {},\n ) {\n return config\n .v4Request(\"model-provider:listModels\", {\n body: JSON.stringify(z.parse(listModelsPropertiesSchema, properties)),\n headers: {\n Accept: \"application/json\",\n \"Content-Type\": \"application/json\",\n },\n method: \"POST\",\n signal,\n })\n .map((res) => res.json() as Promise<{ models: { name: string; isRecommended: boolean }[] }>)\n .map((result) => new Set(result.models));\n };\n}\n\nexport class AIResource {\n #config: Logger & V4Config & SonarV4Config;\n\n constructor(config: Logger & V4Config & SonarV4Config) {\n this.#config = config;\n }\n\n get conversationMachine() {\n return createConversationMachine(this.#config);\n }\n\n createConversation(body: z.input<typeof createConversationCodec>) {\n return createConversation(this.#config)(body);\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 listConversations() {\n const getPage = listConversations(this.#config);\n return {\n async *data({ signal }: SignalParam = {}) {\n yield* (\n await getPage({ maxResults: 100 }, { signal }).map((response) => response.data).promise\n ).unwrap();\n },\n getPage,\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 listAvailableModels(this.#config)(properties);\n }\n\n retrieveConversation(id: string, { signal }: SignalParam = {}) {\n return retrieveConversation(this.#config)(id, { signal }).map(\n (properties) => new AgentConversation(this.#config, properties),\n );\n }\n\n retrieveConversationHistory(id: string) {\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n const getPage = (params: {}, { signal }: SignalParam = {}) =>\n retrieveConversationHistory(this.#config)(id, { signal });\n return {\n async *data(): AsyncGenerator<ChatEvent, void, HttpError> {\n const history = await getPage({}).then((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n });\n yield* history.data;\n },\n };\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 * @deprecated\n */\n sendChatMessage(chatSession: ChatSession, userChatMessage: UserChatMessage) {\n return createSendChatMessage(this.#config)(chatSession, userChatMessage);\n }\n}\n"]}
1
+ {"version":3,"file":"AIResource.js","sourceRoot":"","sources":["../../../src/enterprise/ai/AIResource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpD,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,EACL,wBAAwB,EACxB,0BAA0B,GAC3B,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,uBAAu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AC1F,CAAC;IACN,CAAC;IAED;;;;;OAKG;IACH,eAAe,CAAC,WAAwB,EAAE,eAAgC;QACxE,OAAO,qBAAqB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;IAC3E,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 { ChatSession } from \"./chat/ChatSession.ts\";\nimport type { UserChatMessage } from \"./chat/UserChatMessage.ts\";\nimport type { Logger, SonarV4Config, V4Config } from \"../../common/Config.ts\";\nimport { ModelProvider } from \"./modelProvider/ModelProvider.ts\";\nimport * as z from \"zod/mini\";\nimport {\n modelProviderCreateCodec,\n modelProviderRetrieveCodec,\n} from \"./modelProvider/modelProviderCodec.ts\";\nimport type { SignalParam } from \"../../common/Params.ts\";\nimport { safeParseResultToResult } from \"../../common/safeParseResultToResult.ts\";\nimport { listModelsPropertiesSchema } from \"./modelProvider/modelProviderConfigSchemas.ts\";\nimport { createSendChatMessage } from \"./chat/methods/sendChatMessage.ts\";\nimport { listConversations } from \"./conversations/methods/listConversations.ts\";\nimport {\n createConversation,\n createConversationCodec,\n} from \"./conversations/methods/createConversation.ts\";\nimport { retrieveConversation } from \"./conversations/methods/retrieveConversation.ts\";\nimport { retrieveConversationHistory } from \"./conversations/methods/retrieveConversationHistory.ts\";\nimport type { HttpError } from \"../../common/HttpError.ts\";\nimport { createConversationMachine } from \"./conversations/createConversationMachine.ts\";\nimport { AgentConversation } from \"./conversations/AgentConversation.ts\";\nimport type { ChatEvent } from \"./chat/chatEventSchema.ts\";\n\nexport function listAvailableModels(config: V4Config) {\n return function listAvailableModels(\n properties: z.infer<typeof listModelsPropertiesSchema>,\n { signal }: SignalParam = {},\n ) {\n return config\n .v4Request(\"model-provider:listModels\", {\n body: JSON.stringify(z.parse(listModelsPropertiesSchema, properties)),\n headers: {\n Accept: \"application/json\",\n \"Content-Type\": \"application/json\",\n },\n method: \"POST\",\n signal,\n })\n .map((res) => res.json() as Promise<{ models: { name: string; isRecommended: boolean }[] }>)\n .map((result) => new Set(result.models));\n };\n}\n\nexport class AIResource {\n #config: Logger & V4Config & SonarV4Config;\n\n constructor(config: Logger & V4Config & SonarV4Config) {\n this.#config = config;\n }\n\n get conversationMachine() {\n return createConversationMachine(this.#config);\n }\n\n createConversation(body: z.input<typeof createConversationCodec>) {\n return createConversation(this.#config)(body).map(\n (properties) => new AgentConversation(this.#config, properties),\n );\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 listConversations() {\n const getPage = listConversations(this.#config);\n return {\n async *data({ signal }: SignalParam = {}) {\n yield* (\n await getPage({ maxResults: 100 }, { signal }).map((response) => response.data).promise\n ).unwrap();\n },\n getPage,\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 listAvailableModels(this.#config)(properties);\n }\n\n retrieveConversation(id: string, { signal }: SignalParam = {}) {\n return retrieveConversation(this.#config)(id, { signal }).map(\n (properties) => new AgentConversation(this.#config, properties),\n );\n }\n\n retrieveConversationHistory(id: string) {\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n const getPage = (params: {}, { signal }: SignalParam = {}) =>\n retrieveConversationHistory(this.#config)(id, { signal });\n return {\n async *data(): AsyncGenerator<ChatEvent, void, HttpError> {\n const history = await getPage({}).then((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n });\n yield* history.data;\n },\n };\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 * @deprecated\n */\n sendChatMessage(chatSession: ChatSession, userChatMessage: UserChatMessage) {\n return createSendChatMessage(this.#config)(chatSession, userChatMessage);\n }\n}\n"]}
@@ -1,5 +1,4 @@
1
1
  import type { UserChatMessage } from "../chat/UserChatMessage.ts";
2
- import { AgentConversation } from "./AgentConversation.ts";
3
2
  import type { ConversationExchange } from "./reduceChatEvents.ts";
4
3
  import type { SonarV4Config } from "../../../common/Config.ts";
5
4
  import { type ChatEvent } from "../chat/chatEventSchema.ts";
@@ -44,11 +43,29 @@ export declare const createConversationMachine: (config: SonarV4Config) => impor
44
43
  } | {
45
44
  type: "REFRESH_HISTORY";
46
45
  }, {
47
- [x: string]: import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<AgentConversation, {
46
+ [x: string]: import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<{
47
+ createdAt: import("temporal-polyfill").Temporal.Instant;
48
+ currentRunId: string | null;
49
+ id: string;
50
+ modelName: string | null;
51
+ modelProviderId: string | null;
52
+ modifiedAt: import("temporal-polyfill").Temporal.Instant;
53
+ tag: string;
54
+ title: string | null;
55
+ }, {
48
56
  message: UserChatMessage;
49
57
  modelName?: string | undefined;
50
58
  modelProviderId?: string | undefined;
51
- }, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<AgentConversation, {
59
+ }, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<{
60
+ createdAt: import("temporal-polyfill").Temporal.Instant;
61
+ currentRunId: string | null;
62
+ id: string;
63
+ modelName: string | null;
64
+ modelProviderId: string | null;
65
+ modifiedAt: import("temporal-polyfill").Temporal.Instant;
66
+ tag: string;
67
+ title: string | null;
68
+ }, {
52
69
  conversationId: string;
53
70
  }, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<{
54
71
  data: ({
@@ -159,7 +176,16 @@ export declare const createConversationMachine: (config: SonarV4Config) => impor
159
176
  }, {
160
177
  conversationId: string;
161
178
  }, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<{
162
- conversation: AgentConversation;
179
+ conversation: {
180
+ createdAt: import("temporal-polyfill").Temporal.Instant;
181
+ currentRunId: string | null;
182
+ id: string;
183
+ modelName: string | null;
184
+ modelProviderId: string | null;
185
+ modifiedAt: import("temporal-polyfill").Temporal.Instant;
186
+ tag: string;
187
+ title: string | null;
188
+ };
163
189
  history: {
164
190
  data: ({
165
191
  conversationId: string;
@@ -397,7 +423,16 @@ export declare const createConversationMachine: (config: SonarV4Config) => impor
397
423
  }, import("xstate").EventObject>> | undefined;
398
424
  }, {
399
425
  src: "createConversation";
400
- logic: import("xstate").PromiseActorLogic<AgentConversation, {
426
+ logic: import("xstate").PromiseActorLogic<{
427
+ createdAt: import("temporal-polyfill").Temporal.Instant;
428
+ currentRunId: string | null;
429
+ id: string;
430
+ modelName: string | null;
431
+ modelProviderId: string | null;
432
+ modifiedAt: import("temporal-polyfill").Temporal.Instant;
433
+ tag: string;
434
+ title: string | null;
435
+ }, {
401
436
  message: UserChatMessage;
402
437
  modelName?: string | undefined;
403
438
  modelProviderId?: string | undefined;
@@ -405,7 +440,16 @@ export declare const createConversationMachine: (config: SonarV4Config) => impor
405
440
  id: string | undefined;
406
441
  } | {
407
442
  src: "retrieveConversation";
408
- logic: import("xstate").PromiseActorLogic<AgentConversation, {
443
+ logic: import("xstate").PromiseActorLogic<{
444
+ createdAt: import("temporal-polyfill").Temporal.Instant;
445
+ currentRunId: string | null;
446
+ id: string;
447
+ modelName: string | null;
448
+ modelProviderId: string | null;
449
+ modifiedAt: import("temporal-polyfill").Temporal.Instant;
450
+ tag: string;
451
+ title: string | null;
452
+ }, {
409
453
  conversationId: string;
410
454
  }, import("xstate").EventObject>;
411
455
  id: string | undefined;
@@ -524,7 +568,16 @@ export declare const createConversationMachine: (config: SonarV4Config) => impor
524
568
  } | {
525
569
  src: "retrieveState";
526
570
  logic: import("xstate").PromiseActorLogic<{
527
- conversation: AgentConversation;
571
+ conversation: {
572
+ createdAt: import("temporal-polyfill").Temporal.Instant;
573
+ currentRunId: string | null;
574
+ id: string;
575
+ modelName: string | null;
576
+ modelProviderId: string | null;
577
+ modifiedAt: import("temporal-polyfill").Temporal.Instant;
578
+ tag: string;
579
+ title: string | null;
580
+ };
528
581
  history: {
529
582
  data: ({
530
583
  conversationId: string;
@@ -1,8 +1,16 @@
1
1
  import * as z from "zod/mini";
2
2
  import type { SonarV4Config } from "../../../../common/Config.ts";
3
- import { AgentConversation } from "../AgentConversation.ts";
4
3
  import { UserChatMessage } from "../../chat/UserChatMessage.ts";
5
- export declare const createConversation: (config: SonarV4Config) => (body: z.input<typeof createConversationCodec>) => import("ts-results-es").AsyncResult<AgentConversation, import("../../../index.ts").HttpError>;
4
+ export declare const createConversation: (config: SonarV4Config) => (body: z.input<typeof createConversationCodec>) => import("ts-results-es").AsyncResult<{
5
+ createdAt: import("temporal-polyfill").Temporal.Instant;
6
+ currentRunId: string | null;
7
+ id: string;
8
+ modelName: string | null;
9
+ modelProviderId: string | null;
10
+ modifiedAt: import("temporal-polyfill").Temporal.Instant;
11
+ tag: string;
12
+ title: string | null;
13
+ }, import("../../../index.ts").HttpError>;
6
14
  export declare const createConversationCodec: z.ZodMiniCodec<z.ZodMiniObject<{
7
15
  message: z.ZodMiniCustom<UserChatMessage, UserChatMessage>;
8
16
  modelName: z.ZodMiniOptional<z.ZodMiniString<string>>;
@@ -15,7 +15,6 @@
15
15
  */
16
16
  import * as z from "zod/mini";
17
17
  import { conversationPropertiesCodec } from "../conversationPropertiesCodec.js";
18
- import { AgentConversation } from "../AgentConversation.js";
19
18
  import { createConversationPromptSchema, UserChatMessage } from "../../chat/UserChatMessage.js";
20
19
  export const createConversation = (config) => function createConversation(body) {
21
20
  return config
@@ -29,7 +28,7 @@ export const createConversation = (config) => function createConversation(body)
29
28
  method: "POST",
30
29
  })
31
30
  .map((res) => res.json())
32
- .map((entity) => new AgentConversation(config, z.decode(conversationPropertiesCodec, entity)));
31
+ .map((entity) => z.decode(conversationPropertiesCodec, entity));
33
32
  };
34
33
  const createConversationInSchema = z.strictObject({
35
34
  message: z.instanceof(UserChatMessage),