@dremio/js-sdk 0.42.0 → 0.43.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/README.md +209 -0
- package/dist/cloud/ai/AIResource.d.ts +716 -17
- package/dist/cloud/ai/AIResource.js +40 -18
- package/dist/cloud/ai/AIResource.js.map +1 -1
- package/dist/cloud/ai/DremioModelProvider.d.ts +1 -1
- package/dist/cloud/ai/DremioModelProvider.js +6 -13
- package/dist/cloud/ai/DremioModelProvider.js.map +1 -1
- package/dist/cloud/ai/modelProviderCodec.d.ts +12 -0
- package/dist/cloud/replaceOriginResource.js +4 -0
- package/dist/cloud/replaceOriginResource.js.map +1 -1
- package/dist/common/ConflictResolver.d.ts +9 -1
- package/dist/common/ConflictResolver.js +10 -1
- package/dist/common/ConflictResolver.js.map +1 -1
- package/dist/common/refineRfc9557Schema.d.ts +1 -0
- package/dist/common/refineRfc9557Schema.js +26 -0
- package/dist/common/refineRfc9557Schema.js.map +1 -0
- package/dist/common/sharedExports.d.ts +1 -0
- package/dist/common/sharedExports.js +1 -0
- package/dist/common/sharedExports.js.map +1 -1
- package/dist/enterprise/Dremio.d.ts +1 -1
- package/dist/enterprise/Dremio.js +3 -2
- package/dist/enterprise/Dremio.js.map +1 -1
- package/dist/enterprise/ai/AIResource.d.ts +699 -18
- package/dist/enterprise/ai/AIResource.js +41 -19
- package/dist/enterprise/ai/AIResource.js.map +1 -1
- package/dist/enterprise/ai/chat/ChatSession.d.ts +4 -25
- package/dist/enterprise/ai/chat/ChatSession.js +6 -55
- package/dist/enterprise/ai/chat/ChatSession.js.map +1 -1
- package/dist/enterprise/ai/chat/UserChatMessage.d.ts +38 -22
- package/dist/enterprise/ai/chat/UserChatMessage.js +33 -41
- package/dist/enterprise/ai/chat/UserChatMessage.js.map +1 -1
- package/dist/enterprise/ai/chat/chatEventSchema.d.ts +169 -11
- package/dist/enterprise/ai/chat/chatEventSchema.js +183 -35
- package/dist/enterprise/ai/chat/chatEventSchema.js.map +1 -1
- package/dist/enterprise/ai/chat/eventWrappers/AgentChatPartialResponse.d.ts +0 -6
- package/dist/enterprise/ai/chat/eventWrappers/AgentChatResponse.d.ts +6 -6
- package/dist/enterprise/ai/chat/eventWrappers/AgentChatResponse.js +2 -2
- package/dist/enterprise/ai/chat/eventWrappers/AgentChatResponse.js.map +1 -1
- package/dist/enterprise/ai/chat/index.d.ts +0 -3
- package/dist/enterprise/ai/chat/index.js +0 -1
- package/dist/enterprise/ai/chat/index.js.map +1 -1
- package/dist/enterprise/ai/chat/methods/sendChatMessage.js +4 -1
- package/dist/enterprise/ai/chat/methods/sendChatMessage.js.map +1 -1
- package/dist/enterprise/ai/chat/responseContent/AgentModelResponseContent.d.ts +1 -2
- package/dist/enterprise/ai/chat/responseContent/AgentModelResponseContent.js.map +1 -1
- package/dist/enterprise/ai/chat/responseContent/AgentToolRequestResponseContent.d.ts +1 -2
- package/dist/enterprise/ai/chat/responseContent/AgentToolRequestResponseContent.js +0 -1
- package/dist/enterprise/ai/chat/responseContent/AgentToolRequestResponseContent.js.map +1 -1
- package/dist/enterprise/ai/chat/responseContent/AgentToolResultResponseContent.d.ts +1 -2
- package/dist/enterprise/ai/chat/responseContent/AgentToolResultResponseContent.js +0 -1
- package/dist/enterprise/ai/chat/responseContent/AgentToolResultResponseContent.js.map +1 -1
- package/dist/enterprise/ai/conversations/AgentConversation.d.ts +215 -0
- package/dist/enterprise/ai/conversations/AgentConversation.js +180 -0
- package/dist/enterprise/ai/conversations/AgentConversation.js.map +1 -0
- package/dist/enterprise/ai/conversations/conversationPropertiesCodec.d.ts +22 -0
- package/dist/enterprise/ai/conversations/conversationPropertiesCodec.js +62 -0
- package/dist/enterprise/ai/conversations/conversationPropertiesCodec.js.map +1 -0
- package/dist/enterprise/ai/conversations/createConversationMachine.d.ts +682 -0
- package/dist/enterprise/ai/conversations/createConversationMachine.js +354 -0
- package/dist/enterprise/ai/conversations/createConversationMachine.js.map +1 -0
- package/dist/enterprise/ai/conversations/methods/createConversation.d.ts +28 -0
- package/dist/enterprise/ai/conversations/methods/createConversation.js +68 -0
- package/dist/enterprise/ai/conversations/methods/createConversation.js.map +1 -0
- package/dist/enterprise/ai/conversations/methods/createExchangeRun.d.ts +16 -0
- package/dist/enterprise/ai/conversations/methods/createExchangeRun.js +36 -0
- package/dist/enterprise/ai/conversations/methods/createExchangeRun.js.map +1 -0
- package/dist/enterprise/ai/conversations/methods/deleteConversation.d.ts +2 -0
- package/dist/enterprise/ai/conversations/methods/deleteConversation.js +24 -0
- package/dist/enterprise/ai/conversations/methods/deleteConversation.js.map +1 -0
- package/dist/enterprise/ai/conversations/methods/listConversations.d.ts +8 -0
- package/dist/enterprise/ai/conversations/methods/listConversations.js +30 -0
- package/dist/enterprise/ai/conversations/methods/listConversations.js.map +1 -0
- package/dist/enterprise/ai/conversations/methods/retrieveConversation.d.ts +12 -0
- package/dist/enterprise/ai/conversations/methods/retrieveConversation.js +29 -0
- package/dist/enterprise/ai/conversations/methods/retrieveConversation.js.map +1 -0
- package/dist/enterprise/ai/conversations/methods/retrieveConversationHistory.d.ts +86 -0
- package/dist/enterprise/ai/conversations/methods/retrieveConversationHistory.js +32 -0
- package/dist/enterprise/ai/conversations/methods/retrieveConversationHistory.js.map +1 -0
- package/dist/enterprise/ai/conversations/methods/stopExchangeRun.d.ts +2 -0
- package/dist/enterprise/ai/conversations/methods/stopExchangeRun.js +24 -0
- package/dist/enterprise/ai/conversations/methods/stopExchangeRun.js.map +1 -0
- package/dist/enterprise/ai/conversations/methods/streamRunEvents.d.ts +6 -0
- package/dist/enterprise/ai/conversations/methods/streamRunEvents.js +33 -0
- package/dist/enterprise/ai/conversations/methods/streamRunEvents.js.map +1 -0
- package/dist/enterprise/ai/conversations/methods/updateConversation.d.ts +15 -0
- package/dist/enterprise/ai/conversations/methods/updateConversation.js +35 -0
- package/dist/enterprise/ai/conversations/methods/updateConversation.js.map +1 -0
- package/dist/enterprise/ai/conversations/reduceChatEvents.d.ts +17 -0
- package/dist/enterprise/ai/conversations/reduceChatEvents.js +74 -0
- package/dist/enterprise/ai/conversations/reduceChatEvents.js.map +1 -0
- package/dist/enterprise/ai/index.d.ts +5 -1
- package/dist/enterprise/ai/index.js +4 -1
- package/dist/enterprise/ai/index.js.map +1 -1
- package/dist/enterprise/ai/modelProvider/ModelProvider.d.ts +15 -1
- package/dist/enterprise/ai/modelProvider/ModelProvider.js +12 -1
- package/dist/enterprise/ai/modelProvider/ModelProvider.js.map +1 -1
- package/dist/enterprise/ai/modelProvider/modelProviderCodec.d.ts +40 -0
- package/dist/enterprise/ai/modelProvider/modelProviderCodec.js +10 -1
- package/dist/enterprise/ai/modelProvider/modelProviderCodec.js.map +1 -1
- package/dist/enterprise/ai/modelProvider/modelProviderConfigSchemas.d.ts +21 -0
- package/dist/enterprise/ai/modelProvider/modelProviderConfigSchemas.js +17 -0
- package/dist/enterprise/ai/modelProvider/modelProviderConfigSchemas.js.map +1 -1
- package/dist/oss/catalog/CatalogReferences/DatasetCatalogReference.d.ts +1 -0
- package/dist/oss/catalog/CatalogReferences/DatasetCatalogReference.js +1 -0
- package/dist/oss/catalog/CatalogReferences/DatasetCatalogReference.js.map +1 -1
- package/dist-iife/cloud.js +21620 -6202
- package/dist-iife/community.js +14 -0
- package/dist-iife/enterprise.js +19404 -4038
- package/package.json +5 -2
- package/dist/enterprise/ai/chat/ChatSessionClient.d.ts +0 -18
- package/dist/enterprise/ai/chat/ChatSessionClient.js +0 -55
- package/dist/enterprise/ai/chat/ChatSessionClient.js.map +0 -1
- package/dist/enterprise/ai/chat/UserChatMessageContent.d.ts +0 -19
- package/dist/enterprise/ai/chat/UserChatMessageContent.js +0 -44
- package/dist/enterprise/ai/chat/UserChatMessageContent.js.map +0 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Temporal } from "temporal-polyfill";
|
|
1
2
|
import * as z from "zod/mini";
|
|
2
3
|
/**
|
|
3
4
|
* Captures all of the possible chunks of data that the Agent can reply
|
|
@@ -6,8 +7,9 @@ import * as z from "zod/mini";
|
|
|
6
7
|
* we validate that they match the most general type category they belong in.
|
|
7
8
|
* For example, it's good enough to validate that the `callId` is a string
|
|
8
9
|
* for type safety -- we don't need to verify that it's also a `z.uuid()`.
|
|
10
|
+
* @deprecated
|
|
9
11
|
*/
|
|
10
|
-
export declare const
|
|
12
|
+
export declare const chatEventV1Schema: z.ZodMiniDiscriminatedUnion<[z.ZodMiniObject<{
|
|
11
13
|
chunkType: z.ZodMiniLiteral<"error">;
|
|
12
14
|
/**
|
|
13
15
|
* If the message is not present or very short, it won't be useful to show
|
|
@@ -17,19 +19,13 @@ export declare const chatEventSchema: z.ZodMiniDiscriminatedUnion<[z.ZodMiniObje
|
|
|
17
19
|
}, z.core.$strip>, z.ZodMiniObject<{
|
|
18
20
|
chunkType: z.ZodMiniLiteral<"model">;
|
|
19
21
|
name: z.ZodMiniString<string>;
|
|
20
|
-
|
|
21
|
-
* It's useful to indicate (to the type system) that the result contents
|
|
22
|
-
* at this stage can only be data (de)serializable from JSON. Because
|
|
23
|
-
* model responses can vary depending on runtime flags and edition, we can
|
|
24
|
-
* leave this field generic and refine it more precisely in later stages.
|
|
25
|
-
*/
|
|
26
|
-
result: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniJSONSchema>;
|
|
22
|
+
result: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
|
|
27
23
|
createdAt: z.ZodMiniString<string>;
|
|
28
24
|
modelName: z.ZodMiniString<string>;
|
|
29
25
|
modelProviderId: z.ZodMiniString<string>;
|
|
30
26
|
sessionId: z.ZodMiniString<string>;
|
|
31
27
|
}, z.core.$strip>, z.ZodMiniObject<{
|
|
32
|
-
arguments: z.ZodMiniRecord<z.ZodMiniString<string>, z.
|
|
28
|
+
arguments: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
|
|
33
29
|
callId: z.ZodMiniString<string>;
|
|
34
30
|
chunkType: z.ZodMiniLiteral<"toolRequest">;
|
|
35
31
|
commentary: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
@@ -44,10 +40,172 @@ export declare const chatEventSchema: z.ZodMiniDiscriminatedUnion<[z.ZodMiniObje
|
|
|
44
40
|
chunkType: z.ZodMiniLiteral<"toolResponse">;
|
|
45
41
|
commentary: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
46
42
|
name: z.ZodMiniString<string>;
|
|
47
|
-
result: z.ZodMiniRecord<z.ZodMiniString<string>, z.
|
|
43
|
+
result: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
|
|
48
44
|
createdAt: z.ZodMiniString<string>;
|
|
49
45
|
modelName: z.ZodMiniString<string>;
|
|
50
46
|
modelProviderId: z.ZodMiniString<string>;
|
|
51
47
|
sessionId: z.ZodMiniString<string>;
|
|
52
48
|
}, z.core.$strip>], "chunkType">;
|
|
53
|
-
|
|
49
|
+
/**
|
|
50
|
+
* @deprecated
|
|
51
|
+
*/
|
|
52
|
+
export type ChatEventV1 = z.infer<typeof chatEventV1Schema>;
|
|
53
|
+
export declare const chatEventCodec: z.ZodMiniCodec<z.ZodMiniDiscriminatedUnion<[z.ZodMiniObject<{
|
|
54
|
+
chunkType: z.ZodMiniLiteral<"error">;
|
|
55
|
+
/**
|
|
56
|
+
* If the message is not present or very short, it won't be useful to show
|
|
57
|
+
* anyways, so the parser should throw to the generic response error handler.
|
|
58
|
+
*/
|
|
59
|
+
message: z.ZodMiniString<string>;
|
|
60
|
+
}, z.core.$strip>, z.ZodMiniObject<{
|
|
61
|
+
chunkType: z.ZodMiniLiteral<"conversationUpdate">;
|
|
62
|
+
summary: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
63
|
+
title: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
64
|
+
conversationId: z.ZodMiniString<string>;
|
|
65
|
+
createdAt: z.ZodMiniString<string>;
|
|
66
|
+
messageId: z.ZodMiniString<string>;
|
|
67
|
+
modelName: z.ZodMiniString<string>;
|
|
68
|
+
modelProviderId: z.ZodMiniString<string>;
|
|
69
|
+
runId: z.ZodMiniString<string>;
|
|
70
|
+
}, z.core.$strip>, z.ZodMiniObject<{
|
|
71
|
+
chunkType: z.ZodMiniLiteral<"model">;
|
|
72
|
+
name: z.ZodMiniString<string>;
|
|
73
|
+
result: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
|
|
74
|
+
conversationId: z.ZodMiniString<string>;
|
|
75
|
+
createdAt: z.ZodMiniString<string>;
|
|
76
|
+
messageId: z.ZodMiniString<string>;
|
|
77
|
+
modelName: z.ZodMiniString<string>;
|
|
78
|
+
modelProviderId: z.ZodMiniString<string>;
|
|
79
|
+
runId: z.ZodMiniString<string>;
|
|
80
|
+
}, z.core.$strip>, z.ZodMiniObject<{
|
|
81
|
+
arguments: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
|
|
82
|
+
callId: z.ZodMiniString<string>;
|
|
83
|
+
chunkType: z.ZodMiniLiteral<"toolRequest">;
|
|
84
|
+
commentary: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
85
|
+
name: z.ZodMiniString<string>;
|
|
86
|
+
summarizedTitle: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
87
|
+
conversationId: z.ZodMiniString<string>;
|
|
88
|
+
createdAt: z.ZodMiniString<string>;
|
|
89
|
+
messageId: z.ZodMiniString<string>;
|
|
90
|
+
modelName: z.ZodMiniString<string>;
|
|
91
|
+
modelProviderId: z.ZodMiniString<string>;
|
|
92
|
+
runId: z.ZodMiniString<string>;
|
|
93
|
+
}, z.core.$strip>, z.ZodMiniObject<{
|
|
94
|
+
callId: z.ZodMiniString<string>;
|
|
95
|
+
chunkType: z.ZodMiniLiteral<"toolResponse">;
|
|
96
|
+
commentary: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
97
|
+
name: z.ZodMiniString<string>;
|
|
98
|
+
result: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
|
|
99
|
+
conversationId: z.ZodMiniString<string>;
|
|
100
|
+
createdAt: z.ZodMiniString<string>;
|
|
101
|
+
messageId: z.ZodMiniString<string>;
|
|
102
|
+
modelName: z.ZodMiniString<string>;
|
|
103
|
+
modelProviderId: z.ZodMiniString<string>;
|
|
104
|
+
runId: z.ZodMiniString<string>;
|
|
105
|
+
}, z.core.$strip>, z.ZodMiniObject<{
|
|
106
|
+
chunkType: z.ZodMiniLiteral<"userMessage">;
|
|
107
|
+
text: z.ZodMiniString<string>;
|
|
108
|
+
conversationId: z.ZodMiniString<string>;
|
|
109
|
+
createdAt: z.ZodMiniString<string>;
|
|
110
|
+
messageId: z.ZodMiniString<string>;
|
|
111
|
+
modelName: z.ZodMiniString<string>;
|
|
112
|
+
modelProviderId: z.ZodMiniString<string>;
|
|
113
|
+
runId: z.ZodMiniString<string>;
|
|
114
|
+
}, z.core.$strip>], "chunkType">, z.ZodMiniUnion<readonly [z.ZodMiniObject<{
|
|
115
|
+
conversationId: z.ZodMiniString<string>;
|
|
116
|
+
modelName: z.ZodMiniString<string>;
|
|
117
|
+
modelProviderId: z.ZodMiniString<string>;
|
|
118
|
+
runId: z.ZodMiniString<string>;
|
|
119
|
+
createdAt: z.ZodMiniCustom<Temporal.Instant, Temporal.Instant>;
|
|
120
|
+
id: z.ZodMiniString<string>;
|
|
121
|
+
content: z.ZodMiniObject<{
|
|
122
|
+
chunkType: z.ZodMiniLiteral<"conversationUpdate">;
|
|
123
|
+
summary: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
124
|
+
title: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
125
|
+
}, z.core.$strip>;
|
|
126
|
+
role: z.ZodMiniLiteral<"agent">;
|
|
127
|
+
}, z.core.$strict>, z.ZodMiniObject<{
|
|
128
|
+
conversationId: z.ZodMiniString<string>;
|
|
129
|
+
modelName: z.ZodMiniString<string>;
|
|
130
|
+
modelProviderId: z.ZodMiniString<string>;
|
|
131
|
+
runId: z.ZodMiniString<string>;
|
|
132
|
+
createdAt: z.ZodMiniCustom<Temporal.Instant, Temporal.Instant>;
|
|
133
|
+
id: z.ZodMiniString<string>;
|
|
134
|
+
content: z.ZodMiniObject<{
|
|
135
|
+
chunkType: z.ZodMiniLiteral<"error">;
|
|
136
|
+
/**
|
|
137
|
+
* If the message is not present or very short, it won't be useful to show
|
|
138
|
+
* anyways, so the parser should throw to the generic response error handler.
|
|
139
|
+
*/
|
|
140
|
+
message: z.ZodMiniString<string>;
|
|
141
|
+
}, z.core.$strip>;
|
|
142
|
+
role: z.ZodMiniLiteral<"agent">;
|
|
143
|
+
}, z.core.$strict>, z.ZodMiniObject<{
|
|
144
|
+
conversationId: z.ZodMiniString<string>;
|
|
145
|
+
modelName: z.ZodMiniString<string>;
|
|
146
|
+
modelProviderId: z.ZodMiniString<string>;
|
|
147
|
+
runId: z.ZodMiniString<string>;
|
|
148
|
+
createdAt: z.ZodMiniCustom<Temporal.Instant, Temporal.Instant>;
|
|
149
|
+
id: z.ZodMiniString<string>;
|
|
150
|
+
content: z.ZodMiniObject<{
|
|
151
|
+
chunkType: z.ZodMiniLiteral<"model">;
|
|
152
|
+
name: z.ZodMiniString<string>;
|
|
153
|
+
/**
|
|
154
|
+
* It's useful to indicate (to the type system) that the result contents
|
|
155
|
+
* at this stage can only be data (de)serializable from JSON. Because
|
|
156
|
+
* model responses can vary depending on runtime flags and edition, we can
|
|
157
|
+
* leave this field generic and refine it more precisely in later stages.
|
|
158
|
+
*/
|
|
159
|
+
result: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
|
|
160
|
+
}, z.core.$strip>;
|
|
161
|
+
role: z.ZodMiniLiteral<"agent">;
|
|
162
|
+
}, z.core.$strict>, z.ZodMiniObject<{
|
|
163
|
+
conversationId: z.ZodMiniString<string>;
|
|
164
|
+
modelName: z.ZodMiniString<string>;
|
|
165
|
+
modelProviderId: z.ZodMiniString<string>;
|
|
166
|
+
runId: z.ZodMiniString<string>;
|
|
167
|
+
createdAt: z.ZodMiniCustom<Temporal.Instant, Temporal.Instant>;
|
|
168
|
+
id: z.ZodMiniString<string>;
|
|
169
|
+
content: z.ZodMiniObject<{
|
|
170
|
+
arguments: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
|
|
171
|
+
callId: z.ZodMiniString<string>;
|
|
172
|
+
chunkType: z.ZodMiniLiteral<"toolRequest">;
|
|
173
|
+
commentary: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
174
|
+
name: z.ZodMiniString<string>;
|
|
175
|
+
summarizedTitle: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
176
|
+
}, z.core.$strip>;
|
|
177
|
+
role: z.ZodMiniLiteral<"agent">;
|
|
178
|
+
}, z.core.$strict>, z.ZodMiniObject<{
|
|
179
|
+
conversationId: z.ZodMiniString<string>;
|
|
180
|
+
modelName: z.ZodMiniString<string>;
|
|
181
|
+
modelProviderId: z.ZodMiniString<string>;
|
|
182
|
+
runId: z.ZodMiniString<string>;
|
|
183
|
+
createdAt: z.ZodMiniCustom<Temporal.Instant, Temporal.Instant>;
|
|
184
|
+
id: z.ZodMiniString<string>;
|
|
185
|
+
content: z.ZodMiniObject<{
|
|
186
|
+
callId: z.ZodMiniString<string>;
|
|
187
|
+
chunkType: z.ZodMiniLiteral<"toolResponse">;
|
|
188
|
+
commentary: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
189
|
+
name: z.ZodMiniString<string>;
|
|
190
|
+
result: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
|
|
191
|
+
}, z.core.$strip>;
|
|
192
|
+
role: z.ZodMiniLiteral<"agent">;
|
|
193
|
+
}, z.core.$strict>, z.ZodMiniObject<{
|
|
194
|
+
conversationId: z.ZodMiniString<string>;
|
|
195
|
+
modelName: z.ZodMiniString<string>;
|
|
196
|
+
modelProviderId: z.ZodMiniString<string>;
|
|
197
|
+
runId: z.ZodMiniString<string>;
|
|
198
|
+
createdAt: z.ZodMiniCustom<Temporal.Instant, Temporal.Instant>;
|
|
199
|
+
id: z.ZodMiniString<string>;
|
|
200
|
+
content: z.ZodMiniObject<{
|
|
201
|
+
chunkType: z.ZodMiniLiteral<"userMessage">;
|
|
202
|
+
text: z.ZodMiniString<string>;
|
|
203
|
+
}, z.core.$strip>;
|
|
204
|
+
role: z.ZodMiniLiteral<"user">;
|
|
205
|
+
}, z.core.$strict>]>>;
|
|
206
|
+
export type ChatEvent = z.output<typeof chatEventCodec>;
|
|
207
|
+
export type ChatEventWithChunkType<T extends z.input<typeof chatEventCodec>["chunkType"]> = Extract<ChatEvent, {
|
|
208
|
+
content: {
|
|
209
|
+
chunkType: T;
|
|
210
|
+
};
|
|
211
|
+
}>;
|
|
@@ -13,16 +13,72 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
import { Temporal } from "temporal-polyfill";
|
|
16
17
|
import * as z from "zod/mini";
|
|
17
18
|
/**
|
|
18
19
|
* Shared chat event fields for all responses (except error response)
|
|
20
|
+
* @deprecated
|
|
19
21
|
*/
|
|
20
|
-
const
|
|
22
|
+
const chatEventV1SharedSchema = {
|
|
21
23
|
createdAt: z.string().check(z.iso.datetime()),
|
|
22
24
|
modelName: z.string().check(z.trim(), z.minLength(1)),
|
|
23
25
|
modelProviderId: z.string().check(z.trim(), z.minLength(1)),
|
|
24
26
|
sessionId: z.string().check(z.trim(), z.minLength(1)),
|
|
25
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* Shared chat event fields for all responses (except error response)
|
|
30
|
+
*/
|
|
31
|
+
const chatEventSharedSchema = {
|
|
32
|
+
conversationId: z.string(),
|
|
33
|
+
createdAt: z.string().check(z.iso.datetime()),
|
|
34
|
+
messageId: z.string(),
|
|
35
|
+
modelName: z.string(),
|
|
36
|
+
modelProviderId: z.string(),
|
|
37
|
+
runId: z.string(),
|
|
38
|
+
};
|
|
39
|
+
const errorChunkSchema = z.object({
|
|
40
|
+
chunkType: z.literal("error"),
|
|
41
|
+
/**
|
|
42
|
+
* If the message is not present or very short, it won't be useful to show
|
|
43
|
+
* anyways, so the parser should throw to the generic response error handler.
|
|
44
|
+
*/
|
|
45
|
+
message: z.string().check(z.trim(), z.minLength(2)),
|
|
46
|
+
});
|
|
47
|
+
const conversationUpdateChunkSchema = z.object({
|
|
48
|
+
chunkType: z.literal("conversationUpdate"),
|
|
49
|
+
summary: z.optional(z.string()),
|
|
50
|
+
title: z.optional(z.string()),
|
|
51
|
+
});
|
|
52
|
+
const modelChunkSchema = z.object({
|
|
53
|
+
chunkType: z.literal("model"),
|
|
54
|
+
name: z.string().check(z.trim(), z.minLength(1)),
|
|
55
|
+
/**
|
|
56
|
+
* It's useful to indicate (to the type system) that the result contents
|
|
57
|
+
* at this stage can only be data (de)serializable from JSON. Because
|
|
58
|
+
* model responses can vary depending on runtime flags and edition, we can
|
|
59
|
+
* leave this field generic and refine it more precisely in later stages.
|
|
60
|
+
*/
|
|
61
|
+
result: z.record(z.string(), z.unknown()),
|
|
62
|
+
});
|
|
63
|
+
const toolRequestChunkSchema = z.object({
|
|
64
|
+
arguments: z.record(z.string(), z.unknown()),
|
|
65
|
+
callId: z.string().check(z.trim(), z.minLength(1)),
|
|
66
|
+
chunkType: z.literal("toolRequest"),
|
|
67
|
+
commentary: z.optional(z.string()),
|
|
68
|
+
name: z.string(),
|
|
69
|
+
summarizedTitle: z.optional(z.string()),
|
|
70
|
+
});
|
|
71
|
+
const toolResponseChunkSchema = z.object({
|
|
72
|
+
callId: z.string(),
|
|
73
|
+
chunkType: z.literal("toolResponse"),
|
|
74
|
+
commentary: z.optional(z.string()),
|
|
75
|
+
name: z.string(),
|
|
76
|
+
result: z.record(z.string(), z.unknown()),
|
|
77
|
+
});
|
|
78
|
+
const userMessageChunkSchema = z.object({
|
|
79
|
+
chunkType: z.literal("userMessage"),
|
|
80
|
+
text: z.string(),
|
|
81
|
+
});
|
|
26
82
|
/**
|
|
27
83
|
* Captures all of the possible chunks of data that the Agent can reply
|
|
28
84
|
* with. We're lenient to extra/unexpected fields being present (`z.object`
|
|
@@ -30,44 +86,136 @@ const chatEventSharedSchema = {
|
|
|
30
86
|
* we validate that they match the most general type category they belong in.
|
|
31
87
|
* For example, it's good enough to validate that the `callId` is a string
|
|
32
88
|
* for type safety -- we don't need to verify that it's also a `z.uuid()`.
|
|
89
|
+
* @deprecated
|
|
33
90
|
*/
|
|
34
|
-
export const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
91
|
+
export const chatEventV1Schema = z.discriminatedUnion("chunkType", [
|
|
92
|
+
errorChunkSchema,
|
|
93
|
+
z.extend(modelChunkSchema, chatEventV1SharedSchema),
|
|
94
|
+
z.extend(toolRequestChunkSchema, chatEventV1SharedSchema),
|
|
95
|
+
z.extend(toolResponseChunkSchema, chatEventV1SharedSchema),
|
|
96
|
+
]);
|
|
97
|
+
const chatEventInputSchema = z.discriminatedUnion("chunkType", [
|
|
98
|
+
errorChunkSchema,
|
|
99
|
+
z.extend(conversationUpdateChunkSchema, chatEventSharedSchema),
|
|
100
|
+
z.extend(modelChunkSchema, chatEventSharedSchema),
|
|
101
|
+
z.extend(toolRequestChunkSchema, chatEventSharedSchema),
|
|
102
|
+
z.extend(toolResponseChunkSchema, chatEventSharedSchema),
|
|
103
|
+
z.extend(userMessageChunkSchema, chatEventSharedSchema),
|
|
104
|
+
]);
|
|
105
|
+
const chatEventOutputSharedSchema = z.extend(z.omit(z.strictObject(chatEventSharedSchema), { createdAt: true, messageId: true }), {
|
|
106
|
+
createdAt: z.instanceof(Temporal.Instant),
|
|
107
|
+
id: z.string(),
|
|
108
|
+
});
|
|
109
|
+
const chatEventOutputSchema = z.union([
|
|
110
|
+
z.extend(chatEventOutputSharedSchema, {
|
|
111
|
+
content: conversationUpdateChunkSchema,
|
|
112
|
+
role: z.literal("agent"),
|
|
42
113
|
}),
|
|
43
|
-
z.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
* It's useful to indicate (to the type system) that the result contents
|
|
49
|
-
* at this stage can only be data (de)serializable from JSON. Because
|
|
50
|
-
* model responses can vary depending on runtime flags and edition, we can
|
|
51
|
-
* leave this field generic and refine it more precisely in later stages.
|
|
52
|
-
*/
|
|
53
|
-
result: z.record(z.string(), z.json()),
|
|
114
|
+
z.extend(chatEventOutputSharedSchema, { content: errorChunkSchema, role: z.literal("agent") }),
|
|
115
|
+
z.extend(chatEventOutputSharedSchema, { content: modelChunkSchema, role: z.literal("agent") }),
|
|
116
|
+
z.extend(chatEventOutputSharedSchema, {
|
|
117
|
+
content: toolRequestChunkSchema,
|
|
118
|
+
role: z.literal("agent"),
|
|
54
119
|
}),
|
|
55
|
-
z.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
callId: z.string().check(z.trim(), z.minLength(1)),
|
|
59
|
-
chunkType: z.literal("toolRequest"),
|
|
60
|
-
commentary: z.optional(z.string()),
|
|
61
|
-
name: z.string(),
|
|
62
|
-
summarizedTitle: z.optional(z.string()),
|
|
120
|
+
z.extend(chatEventOutputSharedSchema, {
|
|
121
|
+
content: toolResponseChunkSchema,
|
|
122
|
+
role: z.literal("agent"),
|
|
63
123
|
}),
|
|
64
|
-
z.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
chunkType: z.literal("toolResponse"),
|
|
68
|
-
commentary: z.optional(z.string()),
|
|
69
|
-
name: z.string(),
|
|
70
|
-
result: z.record(z.string(), z.json()),
|
|
124
|
+
z.extend(chatEventOutputSharedSchema, {
|
|
125
|
+
content: userMessageChunkSchema,
|
|
126
|
+
role: z.literal("user"),
|
|
71
127
|
}),
|
|
72
128
|
]);
|
|
129
|
+
export const chatEventCodec = z.codec(chatEventInputSchema, chatEventOutputSchema, {
|
|
130
|
+
decode(v) {
|
|
131
|
+
if (v.chunkType === "error") {
|
|
132
|
+
return {
|
|
133
|
+
content: {
|
|
134
|
+
chunkType: "error",
|
|
135
|
+
message: v.message,
|
|
136
|
+
},
|
|
137
|
+
conversationId: "",
|
|
138
|
+
createdAt: Temporal.Now.instant(),
|
|
139
|
+
id: "",
|
|
140
|
+
modelName: "",
|
|
141
|
+
modelProviderId: "",
|
|
142
|
+
role: "agent",
|
|
143
|
+
runId: "",
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
const sharedProperties = {
|
|
147
|
+
conversationId: v.conversationId,
|
|
148
|
+
createdAt: Temporal.Instant.from(v.createdAt),
|
|
149
|
+
id: v.messageId,
|
|
150
|
+
modelName: v.modelName,
|
|
151
|
+
modelProviderId: v.modelProviderId,
|
|
152
|
+
runId: v.runId,
|
|
153
|
+
};
|
|
154
|
+
switch (v.chunkType) {
|
|
155
|
+
case "conversationUpdate":
|
|
156
|
+
return {
|
|
157
|
+
...sharedProperties,
|
|
158
|
+
content: {
|
|
159
|
+
chunkType: "conversationUpdate",
|
|
160
|
+
summary: v.summary,
|
|
161
|
+
title: v.title,
|
|
162
|
+
},
|
|
163
|
+
role: "agent",
|
|
164
|
+
};
|
|
165
|
+
case "model":
|
|
166
|
+
return {
|
|
167
|
+
...sharedProperties,
|
|
168
|
+
content: {
|
|
169
|
+
chunkType: "model",
|
|
170
|
+
name: v.name,
|
|
171
|
+
result: v.result,
|
|
172
|
+
},
|
|
173
|
+
role: "agent",
|
|
174
|
+
};
|
|
175
|
+
case "toolRequest":
|
|
176
|
+
return {
|
|
177
|
+
...sharedProperties,
|
|
178
|
+
content: {
|
|
179
|
+
arguments: v.arguments,
|
|
180
|
+
callId: v.callId,
|
|
181
|
+
chunkType: "toolRequest",
|
|
182
|
+
commentary: v.commentary,
|
|
183
|
+
name: v.name,
|
|
184
|
+
summarizedTitle: v.summarizedTitle,
|
|
185
|
+
},
|
|
186
|
+
role: "agent",
|
|
187
|
+
};
|
|
188
|
+
case "toolResponse":
|
|
189
|
+
return {
|
|
190
|
+
...sharedProperties,
|
|
191
|
+
content: {
|
|
192
|
+
callId: v.callId,
|
|
193
|
+
chunkType: "toolResponse",
|
|
194
|
+
commentary: v.commentary,
|
|
195
|
+
name: v.name,
|
|
196
|
+
result: v.result,
|
|
197
|
+
},
|
|
198
|
+
role: "agent",
|
|
199
|
+
};
|
|
200
|
+
case "userMessage":
|
|
201
|
+
return {
|
|
202
|
+
...sharedProperties,
|
|
203
|
+
content: { chunkType: "userMessage", text: v.text },
|
|
204
|
+
role: "user",
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
encode(v) {
|
|
209
|
+
return {
|
|
210
|
+
//@ts-ignore
|
|
211
|
+
conversationId: v.conversationId,
|
|
212
|
+
createdAt: v.createdAt.toString(),
|
|
213
|
+
messageId: v.id,
|
|
214
|
+
modelName: v.modelName,
|
|
215
|
+
modelProviderId: v.modelProviderId,
|
|
216
|
+
runId: v.runId,
|
|
217
|
+
...v.content,
|
|
218
|
+
};
|
|
219
|
+
},
|
|
220
|
+
});
|
|
73
221
|
//# sourceMappingURL=chatEventSchema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatEventSchema.js","sourceRoot":"","sources":["../../../../src/enterprise/ai/chat/chatEventSchema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B;;GAEG;AACH,MAAM,qBAAqB,GAAG;IAC5B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;IAC7C,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IACrD,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAA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U,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;QAClC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;QAChB,eAAe,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;KACxC,CAAC;IACF,CAAC,CAAC,MAAM,CAAC;QACP,GAAG,qBAAqB;QACxB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;QAClB,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC;QACpC,UAAU,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;QAClC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;QAChB,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;KACvC,CAAC;CACH,CAAC,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as z from \"zod/mini\";\n\n/**\n * Shared chat event fields for all responses (except error response)\n */\nconst chatEventSharedSchema = {\n createdAt: z.string().check(z.iso.datetime()),\n modelName: z.string().check(z.trim(), z.minLength(1)),\n modelProviderId: z.string().check(z.trim(), z.minLength(1)),\n sessionId: z.string().check(z.trim(), z.minLength(1)),\n};\n\n/**\n * Captures all of the possible chunks of data that the Agent can reply\n * with. We're lenient to extra/unexpected fields being present (`z.object`\n * instead of `z.strictObject`), but for the fields that are expected,\n * we validate that they match the most general type category they belong in.\n * For example, it's good enough to validate that the `callId` is a string\n * for type safety -- we don't need to verify that it's also a `z.uuid()`.\n */\nexport const chatEventSchema = z.discriminatedUnion(\"chunkType\", [\n z.object({\n chunkType: z.literal(\"error\"),\n /**\n * If the message is not present or very short, it won't be useful to show\n * anyways, so the parser should throw to the generic response error handler.\n */\n message: z.string().check(z.trim(), z.minLength(2)),\n }),\n z.object({\n ...chatEventSharedSchema,\n chunkType: z.literal(\"model\"),\n name: z.string().check(z.trim(), z.minLength(1)),\n /**\n * It's useful to indicate (to the type system) that the result contents\n * at this stage can only be data (de)serializable from JSON. Because\n * model responses can vary depending on runtime flags and edition, we can\n * leave this field generic and refine it more precisely in later stages.\n */\n result: z.record(z.string(), z.json()),\n }),\n z.object({\n ...chatEventSharedSchema,\n arguments: z.record(z.string(), z.json()),\n callId: z.string().check(z.trim(), z.minLength(1)),\n chunkType: z.literal(\"toolRequest\"),\n commentary: z.optional(z.string()),\n name: z.string(),\n summarizedTitle: z.optional(z.string()),\n }),\n z.object({\n ...chatEventSharedSchema,\n callId: z.string(),\n chunkType: z.literal(\"toolResponse\"),\n commentary: z.optional(z.string()),\n name: z.string(),\n result: z.record(z.string(), z.json()),\n }),\n]);\n\nexport type ChatEvent = z.infer<typeof chatEventSchema>;\n"]}
|
|
1
|
+
{"version":3,"file":"chatEventSchema.js","sourceRoot":"","sources":["../../../../src/enterprise/ai/chat/chatEventSchema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B;;;GAGG;AACH,MAAM,uBAAuB,GAAG;IAC9B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;IAC7C,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE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eAAe;qBACnC;oBACD,IAAI,EAAE,OAAO;iBAC4C,CAAC;YAC9D,KAAK,cAAc;gBACjB,OAAO;oBACL,GAAG,gBAAgB;oBACnB,OAAO,EAAE;wBACP,MAAM,EAAE,CAAC,CAAC,MAAM;wBAChB,SAAS,EAAE,cAAc;wBACzB,UAAU,EAAE,CAAC,CAAC,UAAU;wBACxB,IAAI,EAAE,CAAC,CAAC,IAAI;wBACZ,MAAM,EAAE,CAAC,CAAC,MAAM;qBACjB;oBACD,IAAI,EAAE,OAAO;iBAC4C,CAAC;YAC9D,KAAK,aAAa;gBAChB,OAAO;oBACL,GAAG,gBAAgB;oBACnB,OAAO,EAAE,EAAE,SAAS,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE;oBACnD,IAAI,EAAE,MAAM;iBAC6C,CAAC;QAChE,CAAC;IACH,CAAC;IACD,MAAM,CAAC,CAAC;QACN,OAAO;YACL,YAAY;YACZ,cAAc,EAAE,CAAC,CAAC,cAAc;YAChC,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,QAAQ,EAAE;YACjC,SAAS,EAAE,CAAC,CAAC,EAAE;YACf,SAAS,EAAE,CAAC,CAAC,SAAS;YACtB,eAAe,EAAE,CAAC,CAAC,eAAe;YAClC,KAAK,EAAE,CAAC,CAAC,KAAK;YACd,GAAG,CAAC,CAAC,OAAO;SAC2C,CAAC;IAC5D,CAAC;CACF,CAAC,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Temporal } from \"temporal-polyfill\";\nimport * as z from \"zod/mini\";\n\n/**\n * Shared chat event fields for all responses (except error response)\n * @deprecated\n */\nconst chatEventV1SharedSchema = {\n createdAt: z.string().check(z.iso.datetime()),\n modelName: z.string().check(z.trim(), z.minLength(1)),\n modelProviderId: z.string().check(z.trim(), z.minLength(1)),\n sessionId: z.string().check(z.trim(), z.minLength(1)),\n};\n\n/**\n * Shared chat event fields for all responses (except error response)\n */\nconst chatEventSharedSchema = {\n conversationId: z.string(),\n createdAt: z.string().check(z.iso.datetime()),\n messageId: z.string(),\n modelName: z.string(),\n modelProviderId: z.string(),\n runId: z.string(),\n};\n\nconst errorChunkSchema = z.object({\n chunkType: z.literal(\"error\"),\n /**\n * If the message is not present or very short, it won't be useful to show\n * anyways, so the parser should throw to the generic response error handler.\n */\n message: z.string().check(z.trim(), z.minLength(2)),\n});\n\nconst conversationUpdateChunkSchema = z.object({\n chunkType: z.literal(\"conversationUpdate\"),\n summary: z.optional(z.string()),\n title: z.optional(z.string()),\n});\n\nconst modelChunkSchema = z.object({\n chunkType: z.literal(\"model\"),\n name: z.string().check(z.trim(), z.minLength(1)),\n /**\n * It's useful to indicate (to the type system) that the result contents\n * at this stage can only be data (de)serializable from JSON. Because\n * model responses can vary depending on runtime flags and edition, we can\n * leave this field generic and refine it more precisely in later stages.\n */\n result: z.record(z.string(), z.unknown()),\n});\n\nconst toolRequestChunkSchema = z.object({\n arguments: z.record(z.string(), z.unknown()),\n callId: z.string().check(z.trim(), z.minLength(1)),\n chunkType: z.literal(\"toolRequest\"),\n commentary: z.optional(z.string()),\n name: z.string(),\n summarizedTitle: z.optional(z.string()),\n});\n\nconst toolResponseChunkSchema = z.object({\n callId: z.string(),\n chunkType: z.literal(\"toolResponse\"),\n commentary: z.optional(z.string()),\n name: z.string(),\n result: z.record(z.string(), z.unknown()),\n});\n\nconst userMessageChunkSchema = z.object({\n chunkType: z.literal(\"userMessage\"),\n text: z.string(),\n});\n\n/**\n * Captures all of the possible chunks of data that the Agent can reply\n * with. We're lenient to extra/unexpected fields being present (`z.object`\n * instead of `z.strictObject`), but for the fields that are expected,\n * we validate that they match the most general type category they belong in.\n * For example, it's good enough to validate that the `callId` is a string\n * for type safety -- we don't need to verify that it's also a `z.uuid()`.\n * @deprecated\n */\nexport const chatEventV1Schema = z.discriminatedUnion(\"chunkType\", [\n errorChunkSchema,\n z.extend(modelChunkSchema, chatEventV1SharedSchema),\n z.extend(toolRequestChunkSchema, chatEventV1SharedSchema),\n z.extend(toolResponseChunkSchema, chatEventV1SharedSchema),\n]);\n\n/**\n * @deprecated\n */\nexport type ChatEventV1 = z.infer<typeof chatEventV1Schema>;\n\nconst chatEventInputSchema = z.discriminatedUnion(\"chunkType\", [\n errorChunkSchema,\n z.extend(conversationUpdateChunkSchema, chatEventSharedSchema),\n z.extend(modelChunkSchema, chatEventSharedSchema),\n z.extend(toolRequestChunkSchema, chatEventSharedSchema),\n z.extend(toolResponseChunkSchema, chatEventSharedSchema),\n z.extend(userMessageChunkSchema, chatEventSharedSchema),\n]);\n\nconst chatEventOutputSharedSchema = z.extend(\n z.omit(z.strictObject(chatEventSharedSchema), { createdAt: true, messageId: true }),\n {\n createdAt: z.instanceof(Temporal.Instant),\n id: z.string(),\n },\n);\n\nconst chatEventOutputSchema = z.union([\n z.extend(chatEventOutputSharedSchema, {\n content: conversationUpdateChunkSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, { content: errorChunkSchema, role: z.literal(\"agent\") }),\n z.extend(chatEventOutputSharedSchema, { content: modelChunkSchema, role: z.literal(\"agent\") }),\n z.extend(chatEventOutputSharedSchema, {\n content: toolRequestChunkSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, {\n content: toolResponseChunkSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, {\n content: userMessageChunkSchema,\n role: z.literal(\"user\"),\n }),\n]);\n\nexport const chatEventCodec = z.codec(chatEventInputSchema, chatEventOutputSchema, {\n decode(v) {\n if (v.chunkType === \"error\") {\n return {\n content: {\n chunkType: \"error\",\n message: v.message,\n },\n conversationId: \"\",\n createdAt: Temporal.Now.instant(),\n id: \"\",\n modelName: \"\",\n modelProviderId: \"\",\n role: \"agent\",\n runId: \"\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n }\n\n const sharedProperties = {\n conversationId: v.conversationId,\n createdAt: Temporal.Instant.from(v.createdAt),\n id: v.messageId,\n modelName: v.modelName,\n modelProviderId: v.modelProviderId,\n runId: v.runId,\n } as const satisfies Omit<z.output<typeof chatEventOutputSchema>, \"content\" | \"role\">;\n\n switch (v.chunkType) {\n case \"conversationUpdate\":\n return {\n ...sharedProperties,\n content: {\n chunkType: \"conversationUpdate\",\n summary: v.summary,\n title: v.title,\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"model\":\n return {\n ...sharedProperties,\n content: {\n chunkType: \"model\",\n name: v.name,\n result: v.result,\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"toolRequest\":\n return {\n ...sharedProperties,\n content: {\n arguments: v.arguments,\n callId: v.callId,\n chunkType: \"toolRequest\",\n commentary: v.commentary,\n name: v.name,\n summarizedTitle: v.summarizedTitle,\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"toolResponse\":\n return {\n ...sharedProperties,\n content: {\n callId: v.callId,\n chunkType: \"toolResponse\",\n commentary: v.commentary,\n name: v.name,\n result: v.result,\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"userMessage\":\n return {\n ...sharedProperties,\n content: { chunkType: \"userMessage\", text: v.text },\n role: \"user\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n }\n },\n encode(v) {\n return {\n //@ts-ignore\n conversationId: v.conversationId,\n createdAt: v.createdAt.toString(),\n messageId: v.id,\n modelName: v.modelName,\n modelProviderId: v.modelProviderId,\n runId: v.runId,\n ...v.content,\n } as const satisfies z.infer<typeof chatEventInputSchema>;\n },\n});\n\nexport type ChatEvent = z.output<typeof chatEventCodec>;\nexport type ChatEventWithChunkType<T extends z.input<typeof chatEventCodec>[\"chunkType\"]> = Extract<\n ChatEvent,\n { content: { chunkType: T } }\n>;\n"]}
|
|
@@ -16,12 +16,9 @@ export declare class AgentChatPartialResponse {
|
|
|
16
16
|
content: string;
|
|
17
17
|
id: string;
|
|
18
18
|
session: {
|
|
19
|
-
createdAt: string;
|
|
20
19
|
id: string;
|
|
21
20
|
modelName: string;
|
|
22
21
|
modelProviderId: string;
|
|
23
|
-
updatedAt: string;
|
|
24
|
-
title?: string | undefined;
|
|
25
22
|
};
|
|
26
23
|
type: "delta" | "end" | "start";
|
|
27
24
|
};
|
|
@@ -31,12 +28,9 @@ export declare class AgentChatPartialResponse {
|
|
|
31
28
|
content: z.ZodMiniString<string>;
|
|
32
29
|
id: z.ZodMiniString<string>;
|
|
33
30
|
session: z.ZodMiniObject<{
|
|
34
|
-
createdAt: z.ZodMiniString<string>;
|
|
35
31
|
id: z.ZodMiniString<string>;
|
|
36
32
|
modelName: z.ZodMiniString<string>;
|
|
37
33
|
modelProviderId: z.ZodMiniString<string>;
|
|
38
|
-
title: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
39
|
-
updatedAt: z.ZodMiniString<string>;
|
|
40
34
|
}, z.core.$strip>;
|
|
41
35
|
type: z.ZodMiniEnum<{
|
|
42
36
|
delta: "delta";
|
|
@@ -22,13 +22,13 @@ export declare class AgentChatResponse<T extends AgentResponseContent> {
|
|
|
22
22
|
} | {
|
|
23
23
|
chunkType: "model";
|
|
24
24
|
name: string;
|
|
25
|
-
result: Record<string,
|
|
25
|
+
result: Record<string, unknown>;
|
|
26
26
|
createdAt: string;
|
|
27
27
|
modelName: string;
|
|
28
28
|
modelProviderId: string;
|
|
29
29
|
sessionId: string;
|
|
30
30
|
} | {
|
|
31
|
-
arguments: Record<string,
|
|
31
|
+
arguments: Record<string, unknown>;
|
|
32
32
|
callId: string;
|
|
33
33
|
chunkType: "toolRequest";
|
|
34
34
|
name: string;
|
|
@@ -42,7 +42,7 @@ export declare class AgentChatResponse<T extends AgentResponseContent> {
|
|
|
42
42
|
callId: string;
|
|
43
43
|
chunkType: "toolResponse";
|
|
44
44
|
name: string;
|
|
45
|
-
result: Record<string,
|
|
45
|
+
result: Record<string, unknown>;
|
|
46
46
|
createdAt: string;
|
|
47
47
|
modelName: string;
|
|
48
48
|
modelProviderId: string;
|
|
@@ -56,13 +56,13 @@ export declare class AgentChatResponse<T extends AgentResponseContent> {
|
|
|
56
56
|
}, z.core.$strip>, z.ZodMiniObject<{
|
|
57
57
|
chunkType: z.ZodMiniLiteral<"model">;
|
|
58
58
|
name: z.ZodMiniString<string>;
|
|
59
|
-
result: z.ZodMiniRecord<z.ZodMiniString<string>, z.
|
|
59
|
+
result: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
|
|
60
60
|
createdAt: z.ZodMiniString<string>;
|
|
61
61
|
modelName: z.ZodMiniString<string>;
|
|
62
62
|
modelProviderId: z.ZodMiniString<string>;
|
|
63
63
|
sessionId: z.ZodMiniString<string>;
|
|
64
64
|
}, z.core.$strip>, z.ZodMiniObject<{
|
|
65
|
-
arguments: z.ZodMiniRecord<z.ZodMiniString<string>, z.
|
|
65
|
+
arguments: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
|
|
66
66
|
callId: z.ZodMiniString<string>;
|
|
67
67
|
chunkType: z.ZodMiniLiteral<"toolRequest">;
|
|
68
68
|
commentary: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
@@ -77,7 +77,7 @@ export declare class AgentChatResponse<T extends AgentResponseContent> {
|
|
|
77
77
|
chunkType: z.ZodMiniLiteral<"toolResponse">;
|
|
78
78
|
commentary: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
79
79
|
name: z.ZodMiniString<string>;
|
|
80
|
-
result: z.ZodMiniRecord<z.ZodMiniString<string>, z.
|
|
80
|
+
result: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
|
|
81
81
|
createdAt: z.ZodMiniString<string>;
|
|
82
82
|
modelName: z.ZodMiniString<string>;
|
|
83
83
|
modelProviderId: z.ZodMiniString<string>;
|
|
@@ -21,7 +21,7 @@ import { AgentToolResultResponseContent } from "../responseContent/AgentToolResu
|
|
|
21
21
|
import { ChatSession } from "../ChatSession.js";
|
|
22
22
|
import * as z from "zod/mini";
|
|
23
23
|
import { Temporal } from "temporal-polyfill";
|
|
24
|
-
import {
|
|
24
|
+
import { chatEventV1Schema } from "../chatEventSchema.js";
|
|
25
25
|
export class AgentChatResponse {
|
|
26
26
|
createdAt = Temporal.Now.instant();
|
|
27
27
|
id = nanoid();
|
|
@@ -51,7 +51,7 @@ export class AgentChatResponse {
|
|
|
51
51
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
52
52
|
return z.decode(AgentChatResponse.codec, data);
|
|
53
53
|
}
|
|
54
|
-
static codec = z.codec(
|
|
54
|
+
static codec = z.codec(chatEventV1Schema, z.instanceof(AgentChatResponse), {
|
|
55
55
|
decode(chatEvent) {
|
|
56
56
|
const chatSession = ChatSession.new();
|
|
57
57
|
const content = (() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentChatResponse.js","sourceRoot":"","sources":["../../../../../src/enterprise/ai/chat/eventWrappers/AgentChatResponse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,iDAAiD,CAAC;AAC5F,OAAO,EAAE,yBAAyB,EAAE,MAAM,iDAAiD,CAAC;AAC5F,OAAO,EAAE,+BAA+B,EAAE,MAAM,uDAAuD,CAAC;AACxG,OAAO,EAAE,8BAA8B,EAAE,MAAM,sDAAsD,CAAC;AACtG,OAAO,EAAE,W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UAAU,EAAE,aAAa,CAAC,OAAO,CAAC,UAAU,IAAI,SAAS;oBACzD,SAAS,EAAE,SAAS;oBACpB,SAAS,EAAE,aAAa,CAAC,OAAO,CAAC,SAAS,IAAI,EAAE;oBAChD,eAAe,EAAE,aAAa,CAAC,OAAO,CAAC,eAAe,IAAI,EAAE;oBAC5D,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,IAAI;oBAChC,SAAS,EAAE,aAAa,CAAC,OAAO,CAAC,EAAG;oBACpC,eAAe,EAAE,aAAa,CAAC,OAAO,CAAC,eAAe,IAAI,SAAS;iBACvC,CAAC;YACjC,CAAC;iBAAM,IAAI,aAAa,CAAC,OAAO,YAAY,8BAA8B,EAAE,CAAC;gBAC3E,OAAO;oBACL,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,MAAM;oBACpC,SAAS,EAAE,cAAc;oBACzB,UAAU,EAAE,aAAa,CAAC,OAAO,CAAC,UAAU,IAAI,SAAS;oBACzD,SAAS,EAAE,SAAS;oBACpB,SAAS,EAAE,aAAa,CAAC,OAAO,CAAC,SAAS,IAAI,EAAE;oBAChD,eAAe,EAAE,aAAa,CAAC,OAAO,CAAC,eAAe,IAAI,EAAE;oBAC5D,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,IAAI;oBAChC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,MAAM;oBACpC,SAAS,EAAE,aAAa,CAAC,OAAO,CAAC,EAAG;iBACR,CAAC;YACjC,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;YAC1C,CAAC;QACH,CAAC;KACF,CAAC,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { nanoid } from \"nanoid/non-secure\";\nimport { AgentErrorResponseContent } from \"../responseContent/AgentErrorResponseContent.ts\";\nimport { AgentModelResponseContent } from \"../responseContent/AgentModelResponseContent.ts\";\nimport { AgentToolRequestResponseContent } from \"../responseContent/AgentToolRequestResponseContent.ts\";\nimport { AgentToolResultResponseContent } from \"../responseContent/AgentToolResultResponseContent.ts\";\nimport { ChatSession } from \"../ChatSession.ts\";\nimport * as z from \"zod/mini\";\nimport { Temporal } from \"temporal-polyfill\";\nimport { chatEventSchema, type ChatEvent } from \"../chatEventSchema.ts\";\n\nexport class AgentChatResponse<T extends AgentResponseContent> {\n readonly createdAt = Temporal.Now.instant();\n readonly id = nanoid();\n readonly session: ChatSession;\n readonly content: T;\n\n constructor(chatSession: ChatSession, content: T, createdAt?: Temporal.Instant, id?: string) {\n this.session = chatSession;\n this.content = content;\n\n if (createdAt) {\n this.createdAt = createdAt;\n }\n\n if (id) {\n this.id = id;\n }\n }\n\n /**\n * Creates a copy of the AgentResponse with a different content property.\n * Preserves the original message's ID\n */\n replaceContent<R extends AgentResponseContent>(content: R): AgentChatResponse<R> {\n return new AgentChatResponse(this.session, content, this.createdAt, this.id);\n }\n\n toJSON() {\n return z.encode(AgentChatResponse.codec, this);\n }\n\n static fromJSON(data: unknown) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any\n return z.decode(AgentChatResponse.codec, data as any);\n }\n\n static codec = z.codec(chatEventSchema, z.instanceof(AgentChatResponse), {\n decode(chatEvent) {\n const chatSession = ChatSession.new();\n const content = (() => {\n switch (chatEvent.chunkType) {\n case \"error\":\n return new AgentErrorResponseContent(chatEvent.message);\n case \"model\":\n return new AgentModelResponseContent(chatEvent.name, chatEvent.result);\n case \"toolRequest\": {\n return new AgentToolRequestResponseContent(\n chatEvent.callId,\n chatEvent.name,\n Object.keys(chatEvent.arguments)\n .sort()\n .map((key) => chatEvent.arguments[key]!),\n chatEvent.summarizedTitle || null,\n chatEvent.commentary || null,\n );\n }\n case \"toolResponse\":\n return new AgentToolResultResponseContent(\n chatEvent.callId,\n chatEvent.name,\n chatEvent.result,\n );\n }\n })();\n chatSession.assign({\n ...(\"modelName\" in chatEvent && { modelName: chatEvent.modelName }),\n ...(\"modelProviderId\" in chatEvent && {\n modelProviderId: chatEvent.modelProviderId,\n }),\n ...(\"sessionId\" in chatEvent && {\n id: chatEvent.sessionId,\n }),\n });\n return new AgentChatResponse(\n chatSession,\n content,\n \"createdAt\" in chatEvent\n ? Temporal.Instant.from(chatEvent.createdAt)\n : Temporal.Now.instant(),\n );\n },\n encode(agentResponse) {\n const createdAt = agentResponse.createdAt?.toString();\n\n if (agentResponse.content instanceof AgentErrorResponseContent) {\n return {\n chunkType: \"error\",\n ...agentResponse.content,\n } as const satisfies ChatEvent;\n } else if (agentResponse.content instanceof AgentModelResponseContent) {\n return {\n chunkType: \"model\",\n createdAt: createdAt,\n modelName: agentResponse.session.modelName || \"\",\n modelProviderId: agentResponse.session.modelProviderId || \"\",\n name: agentResponse.content.name,\n result: agentResponse.content.result,\n sessionId: agentResponse.session.id!,\n } as const satisfies ChatEvent;\n } else if (agentResponse.content instanceof AgentToolRequestResponseContent) {\n return {\n arguments: agentResponse.content.arguments.reduce(\n (accum, curr, i) => {\n accum[`arg${i}`] = curr;\n return accum;\n },\n {} as Record<string, unknown>,\n ) as Record<string, z.core.util.JSONType>,\n callId: agentResponse.content.callId,\n chunkType: \"toolRequest\",\n commentary: agentResponse.content.commentary || undefined,\n createdAt: createdAt,\n modelName: agentResponse.session.modelName || \"\",\n modelProviderId: agentResponse.session.modelProviderId || \"\",\n name: agentResponse.content.name,\n sessionId: agentResponse.session.id!,\n summarizedTitle: agentResponse.content.summarizedTitle || undefined,\n } as const satisfies ChatEvent;\n } else if (agentResponse.content instanceof AgentToolResultResponseContent) {\n return {\n callId: agentResponse.content.callId,\n chunkType: \"toolResponse\",\n commentary: agentResponse.content.commentary || undefined,\n createdAt: createdAt,\n modelName: agentResponse.session.modelName || \"\",\n modelProviderId: agentResponse.session.modelProviderId || \"\",\n name: agentResponse.content.name,\n result: agentResponse.content.result,\n sessionId: agentResponse.session.id!,\n } as const satisfies ChatEvent;\n } else {\n throw new Error(\"Unknown content type\");\n }\n },\n });\n}\n\nexport type AgentResponseContent =\n | AgentErrorResponseContent\n | AgentModelResponseContent\n | AgentToolRequestResponseContent\n | AgentToolResultResponseContent;\n"]}
|
|
1
|
+
{"version":3,"file":"AgentChatResponse.js","sourceRoot":"","sources":["../../../../../src/enterprise/ai/chat/eventWrappers/AgentChatResponse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,iDAAiD,CAAC;AAC5F,OAAO,EAAE,yBAAyB,EAAE,MAAM,iDAAiD,CAAC;AAC5F,OAAO,EAAE,+BAA+B,EAAE,MAAM,uDAAuD,CAAC;AACxG,OAAO,EAAE,8BAA8B,EAAE,MAAM,sDAAsD,CAAC;AACtG,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAoB,MAAM,uBAAuB,CAAC;AAE5E,MAAM,OAAO,iBAAiB;IACnB,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IACnC,EAAE,GAAG,MAAM,EAAE,CAAC;IACd,OAAO,CAAc;IACrB,OAAO,CAAI;IAEpB,YAAY,WAAwB,EAAE,OAAU,EAAE,SAA4B,EAAE,EAAW;QACzF,IAAI,CAAC,OAAO,GAAG,WAAW,CAAC;QAC3B,I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CAAC;gBAC3E,OAAO;oBACL,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,MAAM;oBACpC,SAAS,EAAE,cAAc;oBACzB,UAAU,EAAE,aAAa,CAAC,OAAO,CAAC,UAAU,IAAI,SAAS;oBACzD,SAAS,EAAE,SAAS;oBACpB,SAAS,EAAE,aAAa,CAAC,OAAO,CAAC,SAAS,IAAI,EAAE;oBAChD,eAAe,EAAE,aAAa,CAAC,OAAO,CAAC,eAAe,IAAI,EAAE;oBAC5D,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,IAAI;oBAChC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,MAAM;oBACpC,SAAS,EAAE,aAAa,CAAC,OAAO,CAAC,EAAG;iBACN,CAAC;YACnC,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;YAC1C,CAAC;QACH,CAAC;KACF,CAAC,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { nanoid } from \"nanoid/non-secure\";\nimport { AgentErrorResponseContent } from \"../responseContent/AgentErrorResponseContent.ts\";\nimport { AgentModelResponseContent } from \"../responseContent/AgentModelResponseContent.ts\";\nimport { AgentToolRequestResponseContent } from \"../responseContent/AgentToolRequestResponseContent.ts\";\nimport { AgentToolResultResponseContent } from \"../responseContent/AgentToolResultResponseContent.ts\";\nimport { ChatSession } from \"../ChatSession.ts\";\nimport * as z from \"zod/mini\";\nimport { Temporal } from \"temporal-polyfill\";\nimport { chatEventV1Schema, type ChatEventV1 } from \"../chatEventSchema.ts\";\n\nexport class AgentChatResponse<T extends AgentResponseContent> {\n readonly createdAt = Temporal.Now.instant();\n readonly id = nanoid();\n readonly session: ChatSession;\n readonly content: T;\n\n constructor(chatSession: ChatSession, content: T, createdAt?: Temporal.Instant, id?: string) {\n this.session = chatSession;\n this.content = content;\n\n if (createdAt) {\n this.createdAt = createdAt;\n }\n\n if (id) {\n this.id = id;\n }\n }\n\n /**\n * Creates a copy of the AgentResponse with a different content property.\n * Preserves the original message's ID\n */\n replaceContent<R extends AgentResponseContent>(content: R): AgentChatResponse<R> {\n return new AgentChatResponse(this.session, content, this.createdAt, this.id);\n }\n\n toJSON() {\n return z.encode(AgentChatResponse.codec, this);\n }\n\n static fromJSON(data: unknown) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any\n return z.decode(AgentChatResponse.codec, data as any);\n }\n\n static codec = z.codec(chatEventV1Schema, z.instanceof(AgentChatResponse), {\n decode(chatEvent) {\n const chatSession = ChatSession.new();\n const content = (() => {\n switch (chatEvent.chunkType) {\n case \"error\":\n return new AgentErrorResponseContent(chatEvent.message);\n case \"model\":\n return new AgentModelResponseContent(chatEvent.name, chatEvent.result);\n case \"toolRequest\": {\n return new AgentToolRequestResponseContent(\n chatEvent.callId,\n chatEvent.name,\n Object.keys(chatEvent.arguments)\n .sort()\n .map((key) => chatEvent.arguments[key]!),\n chatEvent.summarizedTitle || null,\n chatEvent.commentary || null,\n );\n }\n case \"toolResponse\":\n return new AgentToolResultResponseContent(\n chatEvent.callId,\n chatEvent.name,\n chatEvent.result,\n );\n }\n })();\n chatSession.assign({\n ...(\"modelName\" in chatEvent && { modelName: chatEvent.modelName }),\n ...(\"modelProviderId\" in chatEvent && {\n modelProviderId: chatEvent.modelProviderId,\n }),\n ...(\"sessionId\" in chatEvent && {\n id: chatEvent.sessionId,\n }),\n });\n return new AgentChatResponse(\n chatSession,\n content,\n \"createdAt\" in chatEvent\n ? Temporal.Instant.from(chatEvent.createdAt)\n : Temporal.Now.instant(),\n );\n },\n encode(agentResponse) {\n const createdAt = agentResponse.createdAt?.toString();\n\n if (agentResponse.content instanceof AgentErrorResponseContent) {\n return {\n chunkType: \"error\",\n ...agentResponse.content,\n } as const satisfies ChatEventV1;\n } else if (agentResponse.content instanceof AgentModelResponseContent) {\n return {\n chunkType: \"model\",\n createdAt: createdAt,\n modelName: agentResponse.session.modelName || \"\",\n modelProviderId: agentResponse.session.modelProviderId || \"\",\n name: agentResponse.content.name,\n result: agentResponse.content.result,\n sessionId: agentResponse.session.id!,\n } as const satisfies ChatEventV1;\n } else if (agentResponse.content instanceof AgentToolRequestResponseContent) {\n return {\n arguments: agentResponse.content.arguments.reduce(\n (accum: Record<string, unknown>, curr, i) => {\n accum[`arg${i}`] = curr;\n return accum;\n },\n {} as Record<string, unknown>,\n ),\n callId: agentResponse.content.callId,\n chunkType: \"toolRequest\",\n commentary: agentResponse.content.commentary || undefined,\n createdAt: createdAt,\n modelName: agentResponse.session.modelName || \"\",\n modelProviderId: agentResponse.session.modelProviderId || \"\",\n name: agentResponse.content.name,\n sessionId: agentResponse.session.id!,\n summarizedTitle: agentResponse.content.summarizedTitle || undefined,\n } as const satisfies ChatEventV1;\n } else if (agentResponse.content instanceof AgentToolResultResponseContent) {\n return {\n callId: agentResponse.content.callId,\n chunkType: \"toolResponse\",\n commentary: agentResponse.content.commentary || undefined,\n createdAt: createdAt,\n modelName: agentResponse.session.modelName || \"\",\n modelProviderId: agentResponse.session.modelProviderId || \"\",\n name: agentResponse.content.name,\n result: agentResponse.content.result,\n sessionId: agentResponse.session.id!,\n } as const satisfies ChatEventV1;\n } else {\n throw new Error(\"Unknown content type\");\n }\n },\n });\n}\n\nexport type AgentResponseContent =\n | AgentErrorResponseContent\n | AgentModelResponseContent\n | AgentToolRequestResponseContent\n | AgentToolResultResponseContent;\n"]}
|