@dremio/js-sdk 0.46.0 → 0.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cloud/ai/AIResource.d.ts +68 -13
- package/dist/cloud/ai/AIResource.js +2 -1
- package/dist/cloud/ai/AIResource.js.map +1 -1
- package/dist/cloud/users/CloudUser.js +1 -1
- package/dist/cloud/users/CloudUser.js.map +1 -1
- package/dist/cloud/users/User.d.ts +3 -3
- package/dist/cloud/users/User.js +2 -2
- package/dist/cloud/users/User.js.map +1 -1
- package/dist/cloud/users/UsersResource.d.ts +33 -19
- package/dist/cloud/users/UsersResource.js +86 -24
- package/dist/cloud/users/UsersResource.js.map +1 -1
- package/dist/cloud/users/userPropertiesCodec.d.ts +19 -29
- package/dist/cloud/users/userPropertiesCodec.js +23 -23
- package/dist/cloud/users/userPropertiesCodec.js.map +1 -1
- package/dist/enterprise/ai/AIResource.d.ts +68 -22
- package/dist/enterprise/ai/AIResource.js +2 -2
- package/dist/enterprise/ai/AIResource.js.map +1 -1
- package/dist/enterprise/ai/conversations/AgentConversation.js +1 -1
- package/dist/enterprise/ai/conversations/AgentConversation.js.map +1 -1
- package/dist/enterprise/ai/conversations/createConversationMachine.d.ts +60 -7
- package/dist/enterprise/ai/conversations/methods/createConversation.d.ts +10 -2
- package/dist/enterprise/ai/conversations/methods/createConversation.js +1 -2
- package/dist/enterprise/ai/conversations/methods/createConversation.js.map +1 -1
- package/dist/enterprise/ai/conversations/methods/listConversations.d.ts +6 -3
- package/dist/enterprise/ai/conversations/methods/listConversations.js +6 -8
- package/dist/enterprise/ai/conversations/methods/listConversations.js.map +1 -1
- package/dist/enterprise/ai/conversations/methods/retrieveConversation.d.ts +2 -4
- package/dist/enterprise/ai/conversations/methods/retrieveConversation.js +2 -10
- package/dist/enterprise/ai/conversations/methods/retrieveConversation.js.map +1 -1
- package/dist/enterprise/ai/conversations/methods/retrieveConversationHistory.d.ts +4 -0
- package/dist/enterprise/ai/conversations/methods/retrieveConversationHistory.js +4 -0
- package/dist/enterprise/ai/conversations/methods/retrieveConversationHistory.js.map +1 -1
- package/dist-iife/cloud.js +1257 -11586
- package/dist-iife/enterprise.js +4400 -14727
- package/package.json +1 -1
|
@@ -14,43 +14,43 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import * as z from "zod/mini";
|
|
17
|
+
export const identityTypeSchema = z.enum(["REGULAR_USER", "SERVICE_USER"]);
|
|
17
18
|
const userPropertiesInSchema = z.object({
|
|
18
|
-
|
|
19
|
-
firstName: z.string(),
|
|
19
|
+
active: z.boolean(),
|
|
20
|
+
firstName: z.optional(z.nullable(z.string())),
|
|
20
21
|
id: z.string().check(z.minLength(1)),
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
name: z.string(),
|
|
25
|
-
type: z.enum(["INTERNAL", "EXTERNAL", "SYSTEM"]),
|
|
26
|
-
})),
|
|
27
|
-
status: z.enum(["ACTIVE", "INACTIVE"]),
|
|
28
|
-
username: z.string().check(z.trim(), z.minLength(1)),
|
|
22
|
+
identityType: z.optional(identityTypeSchema),
|
|
23
|
+
lastName: z.optional(z.nullable(z.string())),
|
|
24
|
+
name: z.string(),
|
|
29
25
|
});
|
|
30
|
-
export const userPropertiesCodec = z.codec(userPropertiesInSchema, z.
|
|
31
|
-
email:
|
|
32
|
-
firstName: true,
|
|
33
|
-
lastName: true,
|
|
34
|
-
}), {
|
|
35
|
-
email: z.nullable(z.string().check(z.email())),
|
|
26
|
+
export const userPropertiesCodec = z.codec(userPropertiesInSchema, z.object({
|
|
27
|
+
email: z.nullable(z.string()),
|
|
36
28
|
familyName: z.nullable(z.string().check(z.trim())),
|
|
37
29
|
givenName: z.nullable(z.string().check(z.trim())),
|
|
30
|
+
id: z.string().check(z.minLength(1)),
|
|
31
|
+
identityType: z.optional(identityTypeSchema),
|
|
32
|
+
status: z.enum(["ACTIVE", "INACTIVE"]),
|
|
33
|
+
username: z.string().check(z.trim(), z.minLength(1)),
|
|
38
34
|
}), {
|
|
39
35
|
decode(v) {
|
|
40
36
|
return {
|
|
41
|
-
|
|
42
|
-
email: v.email || null,
|
|
37
|
+
email: v.name || null,
|
|
43
38
|
familyName: v.lastName || null,
|
|
44
39
|
givenName: v.firstName || null,
|
|
40
|
+
id: v.id,
|
|
41
|
+
identityType: v.identityType,
|
|
42
|
+
status: v.active ? "ACTIVE" : "INACTIVE",
|
|
43
|
+
username: v.name,
|
|
45
44
|
};
|
|
46
45
|
},
|
|
47
46
|
encode(v) {
|
|
48
|
-
const { email, familyName, givenName, ...rest } = v;
|
|
49
47
|
return {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
active: v.status === "ACTIVE",
|
|
49
|
+
firstName: v.givenName || undefined,
|
|
50
|
+
id: v.id,
|
|
51
|
+
identityType: v.identityType,
|
|
52
|
+
lastName: v.familyName || undefined,
|
|
53
|
+
name: v.username,
|
|
54
54
|
};
|
|
55
55
|
},
|
|
56
56
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userPropertiesCodec.js","sourceRoot":"","sources":["../../../src/cloud/users/userPropertiesCodec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B,MAAM,
|
|
1
|
+
{"version":3,"file":"userPropertiesCodec.js","sourceRoot":"","sources":["../../../src/cloud/users/userPropertiesCodec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC,CAAC;AAE3E,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE;IACnB,SAAS,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ACE,MAAM,CAAC,CAAC;QACN,OAAO;YACL,KAAK,EAAE,CAAC,CAAC,IAAI,IAAI,IAAI;YACrB,UAAU,EAAE,CAAC,CAAC,QAAQ,IAAI,IAAI;YAC9B,SAAS,EAAE,CAAC,CAAC,SAAS,IAAI,IAAI;YAC9B,EAAE,EAAE,CAAC,CAAC,EAAE;YACR,YAAY,EAAE,CAAC,CAAC,YAAY;YAC5B,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAE,QAAkB,CAAC,CAAC,CAAE,UAAoB;YAC9D,QAAQ,EAAE,CAAC,CAAC,IAAI;SACjB,CAAC;IACJ,CAAC;IACD,MAAM,CAAC,CAAC;QACN,OAAO;YACL,MAAM,EAAE,CAAC,CAAC,MAAM,KAAK,QAAQ;YAC7B,SAAS,EAAE,CAAC,CAAC,SAAS,IAAI,SAAS;YACnC,EAAE,EAAE,CAAC,CAAC,EAAE;YACR,YAAY,EAAE,CAAC,CAAC,YAAY;YAC5B,QAAQ,EAAE,CAAC,CAAC,UAAU,IAAI,SAAS;YACnC,IAAI,EAAE,CAAC,CAAC,QAAQ;SACjB,CAAC;IACJ,CAAC;CACF,CACF,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as z from \"zod/mini\";\n\nexport const identityTypeSchema = z.enum([\"REGULAR_USER\", \"SERVICE_USER\"]);\n\nconst userPropertiesInSchema = z.object({\n active: z.boolean(),\n firstName: z.optional(z.nullable(z.string())),\n id: z.string().check(z.minLength(1)),\n identityType: z.optional(identityTypeSchema),\n lastName: z.optional(z.nullable(z.string())),\n name: z.string(),\n});\n\nexport const userPropertiesCodec = z.codec(\n userPropertiesInSchema,\n z.object({\n email: z.nullable(z.string()),\n familyName: z.nullable(z.string().check(z.trim())),\n givenName: z.nullable(z.string().check(z.trim())),\n id: z.string().check(z.minLength(1)),\n identityType: z.optional(identityTypeSchema),\n status: z.enum([\"ACTIVE\", \"INACTIVE\"]),\n username: z.string().check(z.trim(), z.minLength(1)),\n }),\n {\n decode(v) {\n return {\n email: v.name || null,\n familyName: v.lastName || null,\n givenName: v.firstName || null,\n id: v.id,\n identityType: v.identityType,\n status: v.active ? (\"ACTIVE\" as const) : (\"INACTIVE\" as const),\n username: v.name,\n };\n },\n encode(v) {\n return {\n active: v.status === \"ACTIVE\",\n firstName: v.givenName || undefined,\n id: v.id,\n identityType: v.identityType,\n lastName: v.familyName || undefined,\n name: v.username,\n };\n },\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<
|
|
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<
|
|
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:
|
|
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<
|
|
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<
|
|
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:
|
|
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").
|
|
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
|
-
}
|
|
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").
|
|
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
|
|
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("
|
|
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,kCAAk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0BAA0B,EAAE,MAAM,CAAC,CAAC,CAC1F,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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,MAAM,CAAC,0BAA0B,EAAE,MAAM,CAAC,CAAC,CAC1F,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"]}
|
|
@@ -91,7 +91,7 @@ export class AgentConversation {
|
|
|
91
91
|
});
|
|
92
92
|
if (attempt.isErr() &&
|
|
93
93
|
isProblem(attempt.error.body) &&
|
|
94
|
-
attempt.error.body.
|
|
94
|
+
attempt.error.body.type === "https://api.dremio.dev/problems/concurrent-modification") {
|
|
95
95
|
const remoteResult = await retrieveConversation(this.#config)(this.id);
|
|
96
96
|
if (remoteResult.isOk()) {
|
|
97
97
|
const remote = new AgentConversation(this.#config, remoteResult.value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentConversation.js","sourceRoot":"","sources":["../../../../src/enterprise/ai/conversations/AgentConversation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAE/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAC/F,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,2BAA2B,EAAE,MAAM,0CAA0C,CAAC;AAEvF,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAKzD;;GAEG;AACH,MAAM,OAAO,iBAAiB;IACnB,OAAO,CAAgB;IACvB,SAAS,CAA2C;IACpD,EAAE,CAAoC;IAC/C,aAAa,CAA8C;IAC3D,UAAU,CAA2C;IACrD,gBAAgB,CAAiD;IACjE,WAAW,CAA4C;IACvD,IAAI,CAAS;IACb,MAAM,C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GAAG,UAAU,CAAC,UAAU,CAAC;QAC3C,CAAC;QAED,IAAI,UAAU,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;YACjC,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC,GAAG,CAAC;QAC7B,CAAC;QAED,IAAI,UAAU,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YACnC,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC;QACjC,CAAC;IACH,CAAC;IAED,MAAM,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;IAC3C,MAAM,CAAC,YAAY,GAAG,wBAAwB,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as z from \"zod/mini\";\nimport { conversationPropertiesCodec } from \"./conversationPropertiesCodec.ts\";\nimport type { SonarV4Config } from \"../../../common/Config.ts\";\nimport { createExchangeRun } from \"./methods/createExchangeRun.ts\";\nimport { deleteConversation } from \"./methods/deleteConversation.ts\";\nimport { conversationUpdateSchema, updateConversation } from \"./methods/updateConversation.ts\";\nimport { map } from \"rxjs\";\nimport { stopExchangeRun } from \"./methods/stopExchangeRun.ts\";\nimport { chatEventCodec } from \"../chat/chatEventSchema.ts\";\nimport { fromTextEventStream } from \"../../../common/fromTextEventStream.ts\";\nimport { streamRunEvents } from \"./methods/streamRunEvents.ts\";\nimport { retrieveConversationHistory } from \"./methods/retrieveConversationHistory.ts\";\nimport type { SignalParam } from \"../../../common/Params.ts\";\nimport { reduceChatEvents } from \"./reduceChatEvents.ts\";\nimport type { ConflictResolver } from \"../../../common/ConflictResolver.ts\";\nimport { AsyncResult } from \"ts-results-es\";\nimport { retrieveConversation } from \"./methods/retrieveConversation.ts\";\nimport { isProblem } from \"../../../common/HttpError.ts\";\nimport type { createConversationCodec } from \"./methods/createConversation.ts\";\n\nexport type AgentConversationProperties = z.output<typeof conversationPropertiesCodec>;\n\n/**\n * Represents a saved conversation with the Dremio AI Agent.\n */\nexport class AgentConversation implements AgentConversationProperties {\n readonly #config: SonarV4Config;\n readonly createdAt: AgentConversationProperties[\"createdAt\"];\n readonly id: AgentConversationProperties[\"id\"];\n #currentRunId: AgentConversationProperties[\"currentRunId\"];\n #modelName: AgentConversationProperties[\"modelName\"];\n #modelProviderId: AgentConversationProperties[\"modelProviderId\"];\n #modifiedAt: AgentConversationProperties[\"modifiedAt\"];\n #tag: string;\n #title: string | null;\n\n constructor(config: SonarV4Config, properties: AgentConversationProperties) {\n this.#config = config;\n this.createdAt = properties.createdAt;\n this.id = properties.id;\n this.#currentRunId = properties.currentRunId;\n this.#modelName = properties.modelName;\n this.#modelProviderId = properties.modelProviderId;\n this.#modifiedAt = properties.modifiedAt;\n this.#tag = properties.tag;\n this.#title = properties.title;\n }\n\n get currentRunId() {\n return this.#currentRunId;\n }\n\n get modelName() {\n return this.#modelName;\n }\n\n get modelProviderId() {\n return this.#modelProviderId;\n }\n\n get modifiedAt() {\n return this.#modifiedAt;\n }\n\n get tag() {\n return this.#tag;\n }\n\n get title() {\n return this.#title;\n }\n\n clone() {\n return new AgentConversation(this.#config, this);\n }\n\n /**\n * Permanently deletes this conversation.\n */\n delete() {\n return deleteConversation(this.#config)(this.id);\n }\n\n /**\n * Patches properties for this `AgentConversation`, mutating instance properties after\n * a successful commit.\n */\n update(\n properties: z.infer<typeof AgentConversation.updateSchema>,\n options: {\n onConflict?: ConflictResolver<\n AgentConversationProperties,\n z.infer<typeof AgentConversation.updateSchema>\n >;\n } = {},\n ) {\n const { onConflict = () => null } = options;\n return new AsyncResult(\n (async () => {\n const attempt = await updateConversation(this.#config)(this.id, this.#tag, properties).map(\n (properties) => {\n this.#updateProperties(properties);\n },\n );\n\n if (\n attempt.isErr() &&\n isProblem(attempt.error.body) &&\n attempt.error.body.title === \"https://api.dremio.dev/problems/concurrent-modification\"\n ) {\n const remoteResult = await retrieveConversation(this.#config)(this.id);\n if (remoteResult.isOk()) {\n const remote = new AgentConversation(this.#config, remoteResult.value);\n const resolved = await onConflict(this.toJSON(), remote.toJSON(), properties);\n if (resolved !== null) {\n return updateConversation(this.#config)(this.id, remote.tag, resolved).map(\n (properties) => {\n this.#updateProperties(properties);\n },\n );\n }\n }\n }\n\n return attempt;\n })(),\n );\n }\n\n history({ signal }: SignalParam = {}) {\n return retrieveConversationHistory(this.#config)(this.id, { signal }).map(\n (response) => response.data,\n );\n }\n\n runEvents$(runId: string) {\n return fromTextEventStream(({ signal }) =>\n streamRunEvents(this.#config)({ conversationId: this.id, runId }, { signal }),\n ).pipe(\n map((event) =>\n z.decode(chatEventCodec, JSON.parse(event.data) as z.input<typeof chatEventCodec>),\n ),\n );\n }\n\n /**\n * Sends a message to the Agent, initiating a new run process.\n * @returns An `AsyncResult` containing the `runId` for the newly created run.\n */\n startRun(properties: z.input<typeof createConversationCodec>) {\n const asyncResult = createExchangeRun(this.#config)(this.id, properties);\n\n asyncResult\n .then((result) => {\n if (result.isOk()) {\n this.#updateProperties(result.value.conversationProperties);\n }\n })\n .catch(() => {});\n\n return asyncResult.map((properties) => properties.currentRunId);\n }\n\n /**\n * Only a single run can be active for a conversation, so for now\n * this method is kept private.\n */\n stopRun(id: string) {\n const asyncResult = stopExchangeRun(this.#config)(this.id, id);\n\n asyncResult\n .then((result) => {\n if (result.isOk() && this.#currentRunId === id) {\n this.#currentRunId = null;\n }\n })\n .catch(() => {});\n\n return asyncResult;\n }\n\n toJSON(): AgentConversationProperties {\n return {\n createdAt: this.createdAt,\n currentRunId: this.currentRunId,\n id: this.id,\n modelName: this.modelName,\n modelProviderId: this.modelProviderId,\n modifiedAt: this.modifiedAt,\n tag: this.tag,\n title: this.title,\n };\n }\n\n #updateProperties(properties: Partial<Omit<AgentConversationProperties, \"createdAt\" | \"id\">>) {\n if (properties.currentRunId !== undefined) {\n this.#currentRunId = properties.currentRunId;\n }\n\n if (properties.modelName !== undefined) {\n this.#modelName = properties.modelName;\n }\n\n if (properties.modelProviderId !== undefined) {\n this.#modelProviderId = properties.modelProviderId;\n }\n\n if (properties.modifiedAt !== undefined) {\n this.#modifiedAt = properties.modifiedAt;\n }\n\n if (properties.tag !== undefined) {\n this.#tag = properties.tag;\n }\n\n if (properties.title !== undefined) {\n this.#title = properties.title;\n }\n }\n\n static reduceChatEvents = reduceChatEvents;\n static updateSchema = conversationUpdateSchema;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"AgentConversation.js","sourceRoot":"","sources":["../../../../src/enterprise/ai/conversations/AgentConversation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAE/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAC/F,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,2BAA2B,EAAE,MAAM,0CAA0C,CAAC;AAEvF,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,WAAW,E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AAC;QAC/C,CAAC;QAED,IAAI,UAAU,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;YACvC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC,SAAS,CAAC;QACzC,CAAC;QAED,IAAI,UAAU,CAAC,eAAe,KAAK,SAAS,EAAE,CAAC;YAC7C,IAAI,CAAC,gBAAgB,GAAG,UAAU,CAAC,eAAe,CAAC;QACrD,CAAC;QAED,IAAI,UAAU,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;YACxC,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,UAAU,CAAC;QAC3C,CAAC;QAED,IAAI,UAAU,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;YACjC,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC,GAAG,CAAC;QAC7B,CAAC;QAED,IAAI,UAAU,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YACnC,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC;QACjC,CAAC;IACH,CAAC;IAED,MAAM,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;IAC3C,MAAM,CAAC,YAAY,GAAG,wBAAwB,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as z from \"zod/mini\";\nimport { conversationPropertiesCodec } from \"./conversationPropertiesCodec.ts\";\nimport type { SonarV4Config } from \"../../../common/Config.ts\";\nimport { createExchangeRun } from \"./methods/createExchangeRun.ts\";\nimport { deleteConversation } from \"./methods/deleteConversation.ts\";\nimport { conversationUpdateSchema, updateConversation } from \"./methods/updateConversation.ts\";\nimport { map } from \"rxjs\";\nimport { stopExchangeRun } from \"./methods/stopExchangeRun.ts\";\nimport { chatEventCodec } from \"../chat/chatEventSchema.ts\";\nimport { fromTextEventStream } from \"../../../common/fromTextEventStream.ts\";\nimport { streamRunEvents } from \"./methods/streamRunEvents.ts\";\nimport { retrieveConversationHistory } from \"./methods/retrieveConversationHistory.ts\";\nimport type { SignalParam } from \"../../../common/Params.ts\";\nimport { reduceChatEvents } from \"./reduceChatEvents.ts\";\nimport type { ConflictResolver } from \"../../../common/ConflictResolver.ts\";\nimport { AsyncResult } from \"ts-results-es\";\nimport { retrieveConversation } from \"./methods/retrieveConversation.ts\";\nimport { isProblem } from \"../../../common/HttpError.ts\";\nimport type { createConversationCodec } from \"./methods/createConversation.ts\";\n\nexport type AgentConversationProperties = z.output<typeof conversationPropertiesCodec>;\n\n/**\n * Represents a saved conversation with the Dremio AI Agent.\n */\nexport class AgentConversation implements AgentConversationProperties {\n readonly #config: SonarV4Config;\n readonly createdAt: AgentConversationProperties[\"createdAt\"];\n readonly id: AgentConversationProperties[\"id\"];\n #currentRunId: AgentConversationProperties[\"currentRunId\"];\n #modelName: AgentConversationProperties[\"modelName\"];\n #modelProviderId: AgentConversationProperties[\"modelProviderId\"];\n #modifiedAt: AgentConversationProperties[\"modifiedAt\"];\n #tag: string;\n #title: string | null;\n\n constructor(config: SonarV4Config, properties: AgentConversationProperties) {\n this.#config = config;\n this.createdAt = properties.createdAt;\n this.id = properties.id;\n this.#currentRunId = properties.currentRunId;\n this.#modelName = properties.modelName;\n this.#modelProviderId = properties.modelProviderId;\n this.#modifiedAt = properties.modifiedAt;\n this.#tag = properties.tag;\n this.#title = properties.title;\n }\n\n get currentRunId() {\n return this.#currentRunId;\n }\n\n get modelName() {\n return this.#modelName;\n }\n\n get modelProviderId() {\n return this.#modelProviderId;\n }\n\n get modifiedAt() {\n return this.#modifiedAt;\n }\n\n get tag() {\n return this.#tag;\n }\n\n get title() {\n return this.#title;\n }\n\n clone() {\n return new AgentConversation(this.#config, this);\n }\n\n /**\n * Permanently deletes this conversation.\n */\n delete() {\n return deleteConversation(this.#config)(this.id);\n }\n\n /**\n * Patches properties for this `AgentConversation`, mutating instance properties after\n * a successful commit.\n */\n update(\n properties: z.infer<typeof AgentConversation.updateSchema>,\n options: {\n onConflict?: ConflictResolver<\n AgentConversationProperties,\n z.infer<typeof AgentConversation.updateSchema>\n >;\n } = {},\n ) {\n const { onConflict = () => null } = options;\n return new AsyncResult(\n (async () => {\n const attempt = await updateConversation(this.#config)(this.id, this.#tag, properties).map(\n (properties) => {\n this.#updateProperties(properties);\n },\n );\n\n if (\n attempt.isErr() &&\n isProblem(attempt.error.body) &&\n attempt.error.body.type === \"https://api.dremio.dev/problems/concurrent-modification\"\n ) {\n const remoteResult = await retrieveConversation(this.#config)(this.id);\n if (remoteResult.isOk()) {\n const remote = new AgentConversation(this.#config, remoteResult.value);\n const resolved = await onConflict(this.toJSON(), remote.toJSON(), properties);\n if (resolved !== null) {\n return updateConversation(this.#config)(this.id, remote.tag, resolved).map(\n (properties) => {\n this.#updateProperties(properties);\n },\n );\n }\n }\n }\n\n return attempt;\n })(),\n );\n }\n\n history({ signal }: SignalParam = {}) {\n return retrieveConversationHistory(this.#config)(this.id, { signal }).map(\n (response) => response.data,\n );\n }\n\n runEvents$(runId: string) {\n return fromTextEventStream(({ signal }) =>\n streamRunEvents(this.#config)({ conversationId: this.id, runId }, { signal }),\n ).pipe(\n map((event) =>\n z.decode(chatEventCodec, JSON.parse(event.data) as z.input<typeof chatEventCodec>),\n ),\n );\n }\n\n /**\n * Sends a message to the Agent, initiating a new run process.\n * @returns An `AsyncResult` containing the `runId` for the newly created run.\n */\n startRun(properties: z.input<typeof createConversationCodec>) {\n const asyncResult = createExchangeRun(this.#config)(this.id, properties);\n\n asyncResult\n .then((result) => {\n if (result.isOk()) {\n this.#updateProperties(result.value.conversationProperties);\n }\n })\n .catch(() => {});\n\n return asyncResult.map((properties) => properties.currentRunId);\n }\n\n /**\n * Only a single run can be active for a conversation, so for now\n * this method is kept private.\n */\n stopRun(id: string) {\n const asyncResult = stopExchangeRun(this.#config)(this.id, id);\n\n asyncResult\n .then((result) => {\n if (result.isOk() && this.#currentRunId === id) {\n this.#currentRunId = null;\n }\n })\n .catch(() => {});\n\n return asyncResult;\n }\n\n toJSON(): AgentConversationProperties {\n return {\n createdAt: this.createdAt,\n currentRunId: this.currentRunId,\n id: this.id,\n modelName: this.modelName,\n modelProviderId: this.modelProviderId,\n modifiedAt: this.modifiedAt,\n tag: this.tag,\n title: this.title,\n };\n }\n\n #updateProperties(properties: Partial<Omit<AgentConversationProperties, \"createdAt\" | \"id\">>) {\n if (properties.currentRunId !== undefined) {\n this.#currentRunId = properties.currentRunId;\n }\n\n if (properties.modelName !== undefined) {\n this.#modelName = properties.modelName;\n }\n\n if (properties.modelProviderId !== undefined) {\n this.#modelProviderId = properties.modelProviderId;\n }\n\n if (properties.modifiedAt !== undefined) {\n this.#modifiedAt = properties.modifiedAt;\n }\n\n if (properties.tag !== undefined) {\n this.#tag = properties.tag;\n }\n\n if (properties.title !== undefined) {\n this.#title = properties.title;\n }\n }\n\n static reduceChatEvents = reduceChatEvents;\n static updateSchema = conversationUpdateSchema;\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<
|
|
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<
|
|
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:
|
|
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<
|
|
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<
|
|
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:
|
|
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<
|
|
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) =>
|
|
31
|
+
.map((entity) => z.decode(conversationPropertiesCodec, entity));
|
|
33
32
|
};
|
|
34
33
|
const createConversationInSchema = z.strictObject({
|
|
35
34
|
message: z.instanceof(UserChatMessage),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createConversation.js","sourceRoot":"","sources":["../../../../../src/enterprise/ai/conversations/methods/createConversation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B,OAAO,EAAE,2BAA2B,EAAE,MAAM,mCAAmC,CAAC;AAChF,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"createConversation.js","sourceRoot":"","sources":["../../../../../src/enterprise/ai/conversations/methods/createConversation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B,OAAO,EAAE,2BAA2B,EAAE,MAAM,mCAAmC,CAAC;AAChF,OAAO,EAAE,8BAA8B,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhG,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,MAAqB,EAAE,EAAE,CAC1D,SAAS,kBAAkB,CAAC,IAA6C;IACvE,OAAO,MAAM;SACV,cAAc,CAAC,qBAAqB,EAAE;QACrC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,uBAAuB,EAA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,CAAC;IACD,MAAM,CAAC,CAAC;QACN,OAAO;YACL,OAAO,EAAE,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE;gBAC1C,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,SAAS;gBAC9B,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,OAAO;gBAC1B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,QAAQ;aAC7B,CAAC;YACF,SAAS,EAAE,CAAC,CAAC,SAAS;YACtB,eAAe,EAAE,CAAC,CAAC,eAAe;SACnC,CAAC;IACJ,CAAC;CACF,CACF,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as z from \"zod/mini\";\nimport type { SonarV4Config } from \"../../../../common/Config.ts\";\nimport { conversationPropertiesCodec } from \"../conversationPropertiesCodec.ts\";\nimport { createConversationPromptSchema, UserChatMessage } from \"../../chat/UserChatMessage.ts\";\n\nexport const createConversation = (config: SonarV4Config) =>\n function createConversation(body: z.input<typeof createConversationCodec>) {\n return config\n .sonarV4Request(`agent/conversations`, {\n body: JSON.stringify(z.decode(createConversationCodec, 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 conversationPropertiesCodec>>)\n .map((entity) => z.decode(conversationPropertiesCodec, entity));\n };\n\nconst createConversationInSchema = z.strictObject({\n message: z.instanceof(UserChatMessage),\n modelName: z.optional(z.string()),\n modelProviderId: z.optional(z.string()),\n});\n\nexport const createConversationCodec = z.codec(\n createConversationInSchema,\n z.extend(\n z.omit(createConversationInSchema, {\n message: true,\n }),\n {\n prompt: createConversationPromptSchema,\n },\n ),\n {\n decode(v) {\n return {\n modelName: v.modelName,\n modelProviderId: v.modelProviderId,\n prompt: {\n approvals: v.message.prompt?.approvals,\n context: v.message.prompt?.context,\n skillIds: v.message.prompt?.skillIds,\n text: v.message.content,\n },\n };\n },\n encode(v) {\n return {\n message: UserChatMessage.new(v.prompt.text, {\n approvals: v.prompt?.approvals,\n context: v.prompt?.context,\n skillIds: v.prompt?.skillIds,\n }),\n modelName: v.modelName,\n modelProviderId: v.modelProviderId,\n };\n },\n },\n);\n"]}
|
|
@@ -2,11 +2,14 @@ import * as z from "zod/mini";
|
|
|
2
2
|
import type { SonarV4Config } from "../../../../common/Config.ts";
|
|
3
3
|
import type { SignalParam } from "../../../../common/Params.ts";
|
|
4
4
|
import { AgentConversation } from "../AgentConversation.ts";
|
|
5
|
-
import { Err, Ok } from "ts-results-es";
|
|
6
5
|
export declare const listConversations: (config: SonarV4Config) => (params: {
|
|
7
6
|
maxResults: number;
|
|
8
7
|
}, { signal }?: SignalParam) => import("ts-results-es").AsyncResult<{
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Safe parse individual list items so that the consumer has the option to still display and of the
|
|
10
|
+
* conversations that parsed successfully, while ignoring others that failed to parse.
|
|
11
|
+
*/
|
|
12
|
+
data: (import("ts-results-es").Err<z.core.$ZodError<{
|
|
10
13
|
createdAt: import("temporal-polyfill").Temporal.Instant;
|
|
11
14
|
currentRunId: string | null;
|
|
12
15
|
id: string;
|
|
@@ -15,5 +18,5 @@ export declare const listConversations: (config: SonarV4Config) => (params: {
|
|
|
15
18
|
modifiedAt: import("temporal-polyfill").Temporal.Instant;
|
|
16
19
|
tag: string;
|
|
17
20
|
title: string | null;
|
|
18
|
-
}>>)[];
|
|
21
|
+
}>> | import("ts-results-es").Ok<AgentConversation>)[];
|
|
19
22
|
}, import("../../../index.ts").HttpError>;
|