@dremio/js-sdk 0.61.0 → 0.62.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 CHANGED
@@ -409,6 +409,7 @@ The state of a conversation is represented as a stream of `ChatEvent` objects. T
409
409
  - `toolResponse` - The result of a tool execution
410
410
  - `error` - An error message
411
411
  - `conversationUpdate` - Updates to conversation metadata (title, summary)
412
+ - `selectedSkills` - Metadata for saved Skills selected for the run
412
413
  - `endOfStream` - Marks the end of a run's event stream
413
414
 
414
415
  #### Building a Conversation Snapshot
@@ -428,6 +429,7 @@ function reduceChatEvents(
428
429
 
429
430
  - **Groups events by exchange** - Each user-agent interaction (identified by `runId`) becomes a separate exchange
430
431
  - **Pairs tool calls** - Tool requests and responses are matched by `callId` and combined into a single object
432
+ - **Preserves run metadata** - Run-level metadata such as selected saved Skills is attached to the exchange
431
433
  - **Derives tool state** - Automatically determines if a tool call is `pending`, `success`, `error`, or `canceled`
432
434
  - `pending` - Tool request received but no response yet
433
435
  - `success` - Tool response received without error
@@ -457,8 +459,18 @@ Each exchange in the snapshot represents a single user-agent interaction:
457
459
  type ConversationExchange = {
458
460
  id: string; // The run ID
459
461
  messages: Map<string, ConversationExchangeMessage>;
460
- toolCalls: Map<string, AgentToolCall>;
462
+ runMetadata?: ConversationExchangeRunMetadata;
461
463
  submittedUserMessage?: UserChatMessage;
464
+ toolCalls: Map<string, AgentToolCall>;
465
+ };
466
+
467
+ type ConversationExchangeRunMetadata = {
468
+ selectedSkills?: SelectedSkillInfo[];
469
+ };
470
+
471
+ type SelectedSkillInfo = {
472
+ id: string;
473
+ name: string;
462
474
  };
463
475
 
464
476
  type ConversationExchangeMessage =
@@ -489,6 +501,10 @@ type ChatEvent = {
489
501
  | { chunkType: "endOfStream" }
490
502
  | { chunkType: "error"; message: string }
491
503
  | { chunkType: "model"; name: string; result: Record<string, unknown> }
504
+ | {
505
+ chunkType: "selectedSkills";
506
+ selectedSkills: { id: string; name: string }[];
507
+ }
492
508
  | { chunkType: "sandboxProgress"; stepName: string; text: string }
493
509
  | {
494
510
  chunkType: "sandboxStdout";
@@ -519,6 +535,17 @@ type ChatEventWithChunkType<T extends ChatEvent["content"]["chunkType"]> =
519
535
  Extract<ChatEvent, { content: { chunkType: T } }>;
520
536
  ```
521
537
 
538
+ Selected saved Skills are exposed as run metadata:
539
+
540
+ ```typescript
541
+ const selectedSkills = exchange.runMetadata?.selectedSkills ?? [];
542
+ ```
543
+
544
+ When additional events are reduced into an existing snapshot, `selectedSkills` is updated
545
+ from the newest `selectedSkills` event by `createdAt`. Equal timestamps use the event's
546
+ message position when available; otherwise they fall back to the order events are passed
547
+ to `reduceChatEvents` (later wins).
548
+
522
549
  #### UI Rendering and React Reconciliation
523
550
 
524
551
  The conversation snapshot produced by the reducer (and automatically managed by the `AgentConversationMachine`) is designed specifically for modern declarative UIs like React, Vue, Svelte, or Ink.
@@ -185,6 +185,21 @@ export declare class AIResource {
185
185
  result: Record<string, unknown>;
186
186
  };
187
187
  role: "agent";
188
+ } | {
189
+ conversationId: string;
190
+ modelName: string;
191
+ modelProviderId: string;
192
+ runId: string;
193
+ createdAt: import("temporal-polyfill").Temporal.Instant;
194
+ id: string;
195
+ content: {
196
+ chunkType: "selectedSkills";
197
+ selectedSkills: {
198
+ id: string;
199
+ name: string;
200
+ }[];
201
+ };
202
+ role: "agent";
188
203
  } | {
189
204
  conversationId: string;
190
205
  modelName: string;
@@ -347,6 +362,21 @@ export declare class AIResource {
347
362
  result: Record<string, unknown>;
348
363
  };
349
364
  role: "agent";
365
+ } | {
366
+ conversationId: string;
367
+ modelName: string;
368
+ modelProviderId: string;
369
+ runId: string;
370
+ createdAt: import("temporal-polyfill").Temporal.Instant;
371
+ id: string;
372
+ content: {
373
+ chunkType: "selectedSkills";
374
+ selectedSkills: {
375
+ id: string;
376
+ name: string;
377
+ }[];
378
+ };
379
+ role: "agent";
350
380
  } | {
351
381
  conversationId: string;
352
382
  modelName: string;
@@ -516,6 +546,21 @@ export declare class AIResource {
516
546
  result: Record<string, unknown>;
517
547
  };
518
548
  role: "agent";
549
+ } | {
550
+ conversationId: string;
551
+ modelName: string;
552
+ modelProviderId: string;
553
+ runId: string;
554
+ createdAt: import("temporal-polyfill").Temporal.Instant;
555
+ id: string;
556
+ content: {
557
+ chunkType: "selectedSkills";
558
+ selectedSkills: {
559
+ id: string;
560
+ name: string;
561
+ }[];
562
+ };
563
+ role: "agent";
519
564
  } | {
520
565
  conversationId: string;
521
566
  modelName: string;
@@ -702,6 +747,21 @@ export declare class AIResource {
702
747
  result: Record<string, unknown>;
703
748
  };
704
749
  role: "agent";
750
+ } | {
751
+ conversationId: string;
752
+ modelName: string;
753
+ modelProviderId: string;
754
+ runId: string;
755
+ createdAt: import("temporal-polyfill").Temporal.Instant;
756
+ id: string;
757
+ content: {
758
+ chunkType: "selectedSkills";
759
+ selectedSkills: {
760
+ id: string;
761
+ name: string;
762
+ }[];
763
+ };
764
+ role: "agent";
705
765
  } | {
706
766
  conversationId: string;
707
767
  modelName: string;
@@ -868,6 +928,21 @@ export declare class AIResource {
868
928
  result: Record<string, unknown>;
869
929
  };
870
930
  role: "agent";
931
+ } | {
932
+ conversationId: string;
933
+ modelName: string;
934
+ modelProviderId: string;
935
+ runId: string;
936
+ createdAt: import("temporal-polyfill").Temporal.Instant;
937
+ id: string;
938
+ content: {
939
+ chunkType: "selectedSkills";
940
+ selectedSkills: {
941
+ id: string;
942
+ name: string;
943
+ }[];
944
+ };
945
+ role: "agent";
871
946
  } | {
872
947
  conversationId: string;
873
948
  modelName: string;
@@ -1049,6 +1124,21 @@ export declare class AIResource {
1049
1124
  result: Record<string, unknown>;
1050
1125
  };
1051
1126
  role: "agent";
1127
+ } | {
1128
+ conversationId: string;
1129
+ modelName: string;
1130
+ modelProviderId: string;
1131
+ runId: string;
1132
+ createdAt: import("temporal-polyfill").Temporal.Instant;
1133
+ id: string;
1134
+ content: {
1135
+ chunkType: "selectedSkills";
1136
+ selectedSkills: {
1137
+ id: string;
1138
+ name: string;
1139
+ }[];
1140
+ };
1141
+ role: "agent";
1052
1142
  } | {
1053
1143
  conversationId: string;
1054
1144
  modelName: string;
@@ -127,6 +127,21 @@ export declare class AIResource {
127
127
  result: Record<string, unknown>;
128
128
  };
129
129
  role: "agent";
130
+ } | {
131
+ conversationId: string;
132
+ modelName: string;
133
+ modelProviderId: string;
134
+ runId: string;
135
+ createdAt: import("temporal-polyfill").Temporal.Instant;
136
+ id: string;
137
+ content: {
138
+ chunkType: "selectedSkills";
139
+ selectedSkills: {
140
+ id: string;
141
+ name: string;
142
+ }[];
143
+ };
144
+ role: "agent";
130
145
  } | {
131
146
  conversationId: string;
132
147
  modelName: string;
@@ -289,6 +304,21 @@ export declare class AIResource {
289
304
  result: Record<string, unknown>;
290
305
  };
291
306
  role: "agent";
307
+ } | {
308
+ conversationId: string;
309
+ modelName: string;
310
+ modelProviderId: string;
311
+ runId: string;
312
+ createdAt: import("temporal-polyfill").Temporal.Instant;
313
+ id: string;
314
+ content: {
315
+ chunkType: "selectedSkills";
316
+ selectedSkills: {
317
+ id: string;
318
+ name: string;
319
+ }[];
320
+ };
321
+ role: "agent";
292
322
  } | {
293
323
  conversationId: string;
294
324
  modelName: string;
@@ -458,6 +488,21 @@ export declare class AIResource {
458
488
  result: Record<string, unknown>;
459
489
  };
460
490
  role: "agent";
491
+ } | {
492
+ conversationId: string;
493
+ modelName: string;
494
+ modelProviderId: string;
495
+ runId: string;
496
+ createdAt: import("temporal-polyfill").Temporal.Instant;
497
+ id: string;
498
+ content: {
499
+ chunkType: "selectedSkills";
500
+ selectedSkills: {
501
+ id: string;
502
+ name: string;
503
+ }[];
504
+ };
505
+ role: "agent";
461
506
  } | {
462
507
  conversationId: string;
463
508
  modelName: string;
@@ -644,6 +689,21 @@ export declare class AIResource {
644
689
  result: Record<string, unknown>;
645
690
  };
646
691
  role: "agent";
692
+ } | {
693
+ conversationId: string;
694
+ modelName: string;
695
+ modelProviderId: string;
696
+ runId: string;
697
+ createdAt: import("temporal-polyfill").Temporal.Instant;
698
+ id: string;
699
+ content: {
700
+ chunkType: "selectedSkills";
701
+ selectedSkills: {
702
+ id: string;
703
+ name: string;
704
+ }[];
705
+ };
706
+ role: "agent";
647
707
  } | {
648
708
  conversationId: string;
649
709
  modelName: string;
@@ -810,6 +870,21 @@ export declare class AIResource {
810
870
  result: Record<string, unknown>;
811
871
  };
812
872
  role: "agent";
873
+ } | {
874
+ conversationId: string;
875
+ modelName: string;
876
+ modelProviderId: string;
877
+ runId: string;
878
+ createdAt: import("temporal-polyfill").Temporal.Instant;
879
+ id: string;
880
+ content: {
881
+ chunkType: "selectedSkills";
882
+ selectedSkills: {
883
+ id: string;
884
+ name: string;
885
+ }[];
886
+ };
887
+ role: "agent";
813
888
  } | {
814
889
  conversationId: string;
815
890
  modelName: string;
@@ -991,6 +1066,21 @@ export declare class AIResource {
991
1066
  result: Record<string, unknown>;
992
1067
  };
993
1068
  role: "agent";
1069
+ } | {
1070
+ conversationId: string;
1071
+ modelName: string;
1072
+ modelProviderId: string;
1073
+ runId: string;
1074
+ createdAt: import("temporal-polyfill").Temporal.Instant;
1075
+ id: string;
1076
+ content: {
1077
+ chunkType: "selectedSkills";
1078
+ selectedSkills: {
1079
+ id: string;
1080
+ name: string;
1081
+ }[];
1082
+ };
1083
+ role: "agent";
994
1084
  } | {
995
1085
  conversationId: string;
996
1086
  modelName: string;
@@ -1,5 +1,10 @@
1
1
  import { Temporal } from "temporal-polyfill";
2
2
  import * as z from "zod/mini";
3
+ declare const selectedSkillInfoSchema: z.ZodMiniObject<{
4
+ id: z.ZodMiniString<string>;
5
+ name: z.ZodMiniString<string>;
6
+ }, z.core.$strip>;
7
+ export type SelectedSkillInfo = z.infer<typeof selectedSkillInfoSchema>;
3
8
  /**
4
9
  * Captures all of the possible chunks of data that the Agent can reply
5
10
  * with. We're lenient to extra/unexpected fields being present (`z.object`
@@ -109,6 +114,18 @@ export declare const chatEventCodec: z.ZodMiniCodec<z.ZodMiniDiscriminatedUnion<
109
114
  modelName: z.ZodMiniString<string>;
110
115
  modelProviderId: z.ZodMiniString<string>;
111
116
  runId: z.ZodMiniString<string>;
117
+ }, z.core.$strip>, z.ZodMiniObject<{
118
+ chunkType: z.ZodMiniLiteral<"selectedSkills">;
119
+ selectedSkills: z.ZodMiniArray<z.ZodMiniObject<{
120
+ id: z.ZodMiniString<string>;
121
+ name: z.ZodMiniString<string>;
122
+ }, z.core.$strip>>;
123
+ conversationId: z.ZodMiniString<string>;
124
+ createdAt: z.ZodMiniString<string>;
125
+ messageId: z.ZodMiniString<string>;
126
+ modelName: z.ZodMiniString<string>;
127
+ modelProviderId: z.ZodMiniString<string>;
128
+ runId: z.ZodMiniString<string>;
112
129
  }, z.core.$strip>, z.ZodMiniObject<{
113
130
  chunkType: z.ZodMiniLiteral<"sandboxProgress">;
114
131
  stepName: z.ZodMiniString<string>;
@@ -247,6 +264,21 @@ export declare const chatEventCodec: z.ZodMiniCodec<z.ZodMiniDiscriminatedUnion<
247
264
  result: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
248
265
  }, z.core.$strip>;
249
266
  role: z.ZodMiniLiteral<"agent">;
267
+ }, z.core.$strict>, z.ZodMiniObject<{
268
+ conversationId: z.ZodMiniString<string>;
269
+ modelName: z.ZodMiniString<string>;
270
+ modelProviderId: z.ZodMiniString<string>;
271
+ runId: z.ZodMiniString<string>;
272
+ createdAt: z.ZodMiniCustom<Temporal.Instant, Temporal.Instant>;
273
+ id: z.ZodMiniString<string>;
274
+ content: z.ZodMiniObject<{
275
+ chunkType: z.ZodMiniLiteral<"selectedSkills">;
276
+ selectedSkills: z.ZodMiniArray<z.ZodMiniObject<{
277
+ id: z.ZodMiniString<string>;
278
+ name: z.ZodMiniString<string>;
279
+ }, z.core.$strip>>;
280
+ }, z.core.$strip>;
281
+ role: z.ZodMiniLiteral<"agent">;
250
282
  }, z.core.$strict>, z.ZodMiniObject<{
251
283
  conversationId: z.ZodMiniString<string>;
252
284
  modelName: z.ZodMiniString<string>;
@@ -326,3 +358,4 @@ export type ChatEventWithChunkType<T extends z.input<typeof chatEventCodec>["chu
326
358
  chunkType: T;
327
359
  };
328
360
  }>;
361
+ export {};
@@ -118,6 +118,14 @@ const jobUpdateChunkSchema = z.object({
118
118
  toolExecutionId: z.string(),
119
119
  toolName: z.string(),
120
120
  });
121
+ const selectedSkillInfoSchema = z.object({
122
+ id: z.string(),
123
+ name: z.string(),
124
+ });
125
+ const selectedSkillsChunkSchema = z.object({
126
+ chunkType: z.literal("selectedSkills"),
127
+ selectedSkills: z.array(selectedSkillInfoSchema),
128
+ });
121
129
  const userMessageChunkSchema = z.object({
122
130
  chunkType: z.literal("userMessage"),
123
131
  text: z.string(),
@@ -144,6 +152,7 @@ const chatEventInputSchema = z.discriminatedUnion("chunkType", [
144
152
  z.extend(conversationUpdateChunkSchema, chatEventSharedSchema),
145
153
  z.extend(jobUpdateChunkSchema, chatEventSharedSchema),
146
154
  z.extend(modelChunkSchema, chatEventSharedSchema),
155
+ z.extend(selectedSkillsChunkSchema, chatEventSharedSchema),
147
156
  z.extend(sandboxProgressChunkSchema, chatEventSharedSchema),
148
157
  sandboxStdoutChatEventSchema,
149
158
  z.extend(toolRequestChunkSchema, chatEventSharedSchema),
@@ -175,6 +184,10 @@ const chatEventOutputSchema = z.union([
175
184
  role: z.literal("agent"),
176
185
  }),
177
186
  z.extend(chatEventOutputSharedSchema, { content: modelChunkSchema, role: z.literal("agent") }),
187
+ z.extend(chatEventOutputSharedSchema, {
188
+ content: selectedSkillsChunkSchema,
189
+ role: z.literal("agent"),
190
+ }),
178
191
  z.extend(chatEventOutputSharedSchema, {
179
192
  content: sandboxProgressChunkSchema,
180
193
  role: z.literal("agent"),
@@ -268,6 +281,15 @@ export const chatEventCodec = z.codec(chatEventInputSchema, chatEventOutputSchem
268
281
  },
269
282
  role: "agent",
270
283
  };
284
+ case "selectedSkills":
285
+ return {
286
+ ...sharedProperties,
287
+ content: {
288
+ chunkType: "selectedSkills",
289
+ selectedSkills: v.selectedSkills,
290
+ },
291
+ role: "agent",
292
+ };
271
293
  case "sandboxProgress":
272
294
  return {
273
295
  ...sharedProperties,
@@ -1 +1 @@
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,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IACrD,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAC3D,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;CACtD,CAAC;AAEF;;GAEG;AACH,MAAM,qBAAqB,GAAG;IAC5B,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE;IAC1B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;IAC7C,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE;IAC3B,K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,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 errorChunkV2Schema = z.object({\n chunkType: z.literal(\"error\"),\n message: z.string().check(z.trim(), z.minLength(2)),\n type: z.string(),\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 endOfStreamChunkSchema = z.object({\n chunkType: z.literal(\"endOfStream\"),\n});\n\n// endOfStream omits messageId: the backend sends it absent or as \"\", neither maps to a meaningful id\nconst endOfStreamInputSchema = z.object({\n chunkType: z.literal(\"endOfStream\"),\n conversationId: z.string(),\n createdAt: z.string().check(z.iso.datetime()),\n modelName: z.string(),\n modelProviderId: z.string(),\n runId: z.string(),\n});\n\nconst interruptChunkSchema = z.object({\n chunkType: z.literal(\"interrupt\"),\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 sandboxProgressChunkSchema = z.object({\n chunkType: z.literal(\"sandboxProgress\"),\n stepName: z.string(),\n text: z.string(),\n});\n\nconst sandboxStdoutChunkSchema = z.object({\n callId: z.string().check(z.trim(), z.minLength(1)),\n chunkType: z.literal(\"sandboxStdout\"),\n isFinal: z.boolean(),\n text: z.string(),\n});\nconst sandboxStdoutContentSchema = sandboxStdoutChunkSchema;\nconst sandboxStdoutChatEventSchema = z.extend(sandboxStdoutChunkSchema, chatEventSharedSchema);\nconst toolPlanSchema = z.record(z.string(), z.unknown());\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 replacePlan: z.optional(toolPlanSchema),\n summarizedTitle: z.optional(z.string()),\n updatePlan: z.optional(toolPlanSchema),\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 jobUpdateChunkSchema = z.object({\n chunkType: z.literal(\"jobUpdate\"),\n jobId: z.string(),\n jobState: z.string(),\n toolExecutionId: z.string(),\n toolName: z.string(),\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 z.extend(errorChunkV2Schema, chatEventSharedSchema),\n endOfStreamInputSchema,\n z.extend(interruptChunkSchema, chatEventSharedSchema),\n z.extend(conversationUpdateChunkSchema, chatEventSharedSchema),\n z.extend(jobUpdateChunkSchema, chatEventSharedSchema),\n z.extend(modelChunkSchema, chatEventSharedSchema),\n z.extend(sandboxProgressChunkSchema, chatEventSharedSchema),\n sandboxStdoutChatEventSchema,\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\n// endOfStream has no meaningful messageId on input, so no id on output\nconst endOfStreamOutputSchema = z.omit(chatEventOutputSharedSchema, { id: true });\n\nconst chatEventOutputSchema = z.union([\n z.extend(chatEventOutputSharedSchema, {\n content: conversationUpdateChunkSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, { content: errorChunkV2Schema, role: z.literal(\"agent\") }),\n z.extend(endOfStreamOutputSchema, {\n content: endOfStreamChunkSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, {\n content: interruptChunkSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, {\n content: jobUpdateChunkSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, { content: modelChunkSchema, role: z.literal(\"agent\") }),\n z.extend(chatEventOutputSharedSchema, {\n content: sandboxProgressChunkSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, {\n content: sandboxStdoutContentSchema,\n role: z.literal(\"agent\"),\n }),\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 === \"endOfStream\") {\n return {\n content: { chunkType: \"endOfStream\" },\n conversationId: v.conversationId,\n createdAt: Temporal.Instant.from(v.createdAt),\n modelName: v.modelName,\n modelProviderId: v.modelProviderId,\n role: \"agent\",\n runId: v.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 };\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 \"error\":\n return {\n ...sharedProperties,\n content: {\n chunkType: \"error\",\n message: v.message,\n type: v.type,\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"interrupt\":\n return {\n ...sharedProperties,\n content: {\n chunkType: \"interrupt\",\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"jobUpdate\":\n return {\n ...sharedProperties,\n content: {\n chunkType: \"jobUpdate\",\n jobId: v.jobId,\n jobState: v.jobState,\n toolExecutionId: v.toolExecutionId,\n toolName: v.toolName,\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 \"sandboxProgress\":\n return {\n ...sharedProperties,\n content: {\n chunkType: \"sandboxProgress\",\n stepName: v.stepName,\n text: v.text,\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"sandboxStdout\":\n return {\n ...sharedProperties,\n content: {\n callId: v.callId,\n chunkType: \"sandboxStdout\",\n isFinal: v.isFinal,\n text: v.text,\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 replacePlan: v.replacePlan,\n summarizedTitle: v.summarizedTitle,\n updatePlan: v.updatePlan,\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 if (v.content.chunkType === \"endOfStream\") {\n return {\n chunkType: \"endOfStream\",\n conversationId: v.conversationId,\n createdAt: v.createdAt.toString(),\n modelName: v.modelName,\n modelProviderId: v.modelProviderId,\n runId: v.runId,\n } as const satisfies z.infer<typeof chatEventInputSchema>;\n }\n // Safe: endOfStream (the only variant without id) is handled by the early return above\n const id = (v as Extract<z.output<typeof chatEventOutputSchema>, { id: string }>).id;\n return {\n conversationId: v.conversationId,\n createdAt: v.createdAt.toString(),\n messageId: 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"]}
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,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IACrD,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAC3D,SAAS,EA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,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 errorChunkV2Schema = z.object({\n chunkType: z.literal(\"error\"),\n message: z.string().check(z.trim(), z.minLength(2)),\n type: z.string(),\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 endOfStreamChunkSchema = z.object({\n chunkType: z.literal(\"endOfStream\"),\n});\n\n// endOfStream omits messageId: the backend sends it absent or as \"\", neither maps to a meaningful id\nconst endOfStreamInputSchema = z.object({\n chunkType: z.literal(\"endOfStream\"),\n conversationId: z.string(),\n createdAt: z.string().check(z.iso.datetime()),\n modelName: z.string(),\n modelProviderId: z.string(),\n runId: z.string(),\n});\n\nconst interruptChunkSchema = z.object({\n chunkType: z.literal(\"interrupt\"),\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 sandboxProgressChunkSchema = z.object({\n chunkType: z.literal(\"sandboxProgress\"),\n stepName: z.string(),\n text: z.string(),\n});\n\nconst sandboxStdoutChunkSchema = z.object({\n callId: z.string().check(z.trim(), z.minLength(1)),\n chunkType: z.literal(\"sandboxStdout\"),\n isFinal: z.boolean(),\n text: z.string(),\n});\nconst sandboxStdoutContentSchema = sandboxStdoutChunkSchema;\nconst sandboxStdoutChatEventSchema = z.extend(sandboxStdoutChunkSchema, chatEventSharedSchema);\nconst toolPlanSchema = z.record(z.string(), z.unknown());\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 replacePlan: z.optional(toolPlanSchema),\n summarizedTitle: z.optional(z.string()),\n updatePlan: z.optional(toolPlanSchema),\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 jobUpdateChunkSchema = z.object({\n chunkType: z.literal(\"jobUpdate\"),\n jobId: z.string(),\n jobState: z.string(),\n toolExecutionId: z.string(),\n toolName: z.string(),\n});\n\nconst selectedSkillInfoSchema = z.object({\n id: z.string(),\n name: z.string(),\n});\n\nexport type SelectedSkillInfo = z.infer<typeof selectedSkillInfoSchema>;\n\nconst selectedSkillsChunkSchema = z.object({\n chunkType: z.literal(\"selectedSkills\"),\n selectedSkills: z.array(selectedSkillInfoSchema),\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 z.extend(errorChunkV2Schema, chatEventSharedSchema),\n endOfStreamInputSchema,\n z.extend(interruptChunkSchema, chatEventSharedSchema),\n z.extend(conversationUpdateChunkSchema, chatEventSharedSchema),\n z.extend(jobUpdateChunkSchema, chatEventSharedSchema),\n z.extend(modelChunkSchema, chatEventSharedSchema),\n z.extend(selectedSkillsChunkSchema, chatEventSharedSchema),\n z.extend(sandboxProgressChunkSchema, chatEventSharedSchema),\n sandboxStdoutChatEventSchema,\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\n// endOfStream has no meaningful messageId on input, so no id on output\nconst endOfStreamOutputSchema = z.omit(chatEventOutputSharedSchema, { id: true });\n\nconst chatEventOutputSchema = z.union([\n z.extend(chatEventOutputSharedSchema, {\n content: conversationUpdateChunkSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, { content: errorChunkV2Schema, role: z.literal(\"agent\") }),\n z.extend(endOfStreamOutputSchema, {\n content: endOfStreamChunkSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, {\n content: interruptChunkSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, {\n content: jobUpdateChunkSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, { content: modelChunkSchema, role: z.literal(\"agent\") }),\n z.extend(chatEventOutputSharedSchema, {\n content: selectedSkillsChunkSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, {\n content: sandboxProgressChunkSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, {\n content: sandboxStdoutContentSchema,\n role: z.literal(\"agent\"),\n }),\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 === \"endOfStream\") {\n return {\n content: { chunkType: \"endOfStream\" },\n conversationId: v.conversationId,\n createdAt: Temporal.Instant.from(v.createdAt),\n modelName: v.modelName,\n modelProviderId: v.modelProviderId,\n role: \"agent\",\n runId: v.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 };\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 \"error\":\n return {\n ...sharedProperties,\n content: {\n chunkType: \"error\",\n message: v.message,\n type: v.type,\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"interrupt\":\n return {\n ...sharedProperties,\n content: {\n chunkType: \"interrupt\",\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"jobUpdate\":\n return {\n ...sharedProperties,\n content: {\n chunkType: \"jobUpdate\",\n jobId: v.jobId,\n jobState: v.jobState,\n toolExecutionId: v.toolExecutionId,\n toolName: v.toolName,\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 \"selectedSkills\":\n return {\n ...sharedProperties,\n content: {\n chunkType: \"selectedSkills\",\n selectedSkills: v.selectedSkills,\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"sandboxProgress\":\n return {\n ...sharedProperties,\n content: {\n chunkType: \"sandboxProgress\",\n stepName: v.stepName,\n text: v.text,\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"sandboxStdout\":\n return {\n ...sharedProperties,\n content: {\n callId: v.callId,\n chunkType: \"sandboxStdout\",\n isFinal: v.isFinal,\n text: v.text,\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 replacePlan: v.replacePlan,\n summarizedTitle: v.summarizedTitle,\n updatePlan: v.updatePlan,\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 if (v.content.chunkType === \"endOfStream\") {\n return {\n chunkType: \"endOfStream\",\n conversationId: v.conversationId,\n createdAt: v.createdAt.toString(),\n modelName: v.modelName,\n modelProviderId: v.modelProviderId,\n runId: v.runId,\n } as const satisfies z.infer<typeof chatEventInputSchema>;\n }\n // Safe: endOfStream (the only variant without id) is handled by the early return above\n const id = (v as Extract<z.output<typeof chatEventOutputSchema>, { id: string }>).id;\n return {\n conversationId: v.conversationId,\n createdAt: v.createdAt.toString(),\n messageId: 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"]}
@@ -108,6 +108,21 @@ export declare class AgentConversation implements AgentConversationProperties {
108
108
  result: Record<string, unknown>;
109
109
  };
110
110
  role: "agent";
111
+ } | {
112
+ conversationId: string;
113
+ modelName: string;
114
+ modelProviderId: string;
115
+ runId: string;
116
+ createdAt: import("temporal-polyfill").Temporal.Instant;
117
+ id: string;
118
+ content: {
119
+ chunkType: "selectedSkills";
120
+ selectedSkills: {
121
+ id: string;
122
+ name: string;
123
+ }[];
124
+ };
125
+ role: "agent";
111
126
  } | {
112
127
  conversationId: string;
113
128
  modelName: string;
@@ -256,6 +271,21 @@ export declare class AgentConversation implements AgentConversationProperties {
256
271
  result: Record<string, unknown>;
257
272
  };
258
273
  role: "agent";
274
+ } | {
275
+ conversationId: string;
276
+ modelName: string;
277
+ modelProviderId: string;
278
+ runId: string;
279
+ createdAt: import("temporal-polyfill").Temporal.Instant;
280
+ id: string;
281
+ content: {
282
+ chunkType: "selectedSkills";
283
+ selectedSkills: {
284
+ id: string;
285
+ name: string;
286
+ }[];
287
+ };
288
+ role: "agent";
259
289
  } | {
260
290
  conversationId: string;
261
291
  modelName: string;
@@ -147,6 +147,21 @@ export declare const createConversationMachine: (config: SonarV4Config) => impor
147
147
  result: Record<string, unknown>;
148
148
  };
149
149
  role: "agent";
150
+ } | {
151
+ conversationId: string;
152
+ modelName: string;
153
+ modelProviderId: string;
154
+ runId: string;
155
+ createdAt: import("temporal-polyfill").Temporal.Instant;
156
+ id: string;
157
+ content: {
158
+ chunkType: "selectedSkills";
159
+ selectedSkills: {
160
+ id: string;
161
+ name: string;
162
+ }[];
163
+ };
164
+ role: "agent";
150
165
  } | {
151
166
  conversationId: string;
152
167
  modelName: string;
@@ -309,6 +324,21 @@ export declare const createConversationMachine: (config: SonarV4Config) => impor
309
324
  result: Record<string, unknown>;
310
325
  };
311
326
  role: "agent";
327
+ } | {
328
+ conversationId: string;
329
+ modelName: string;
330
+ modelProviderId: string;
331
+ runId: string;
332
+ createdAt: import("temporal-polyfill").Temporal.Instant;
333
+ id: string;
334
+ content: {
335
+ chunkType: "selectedSkills";
336
+ selectedSkills: {
337
+ id: string;
338
+ name: string;
339
+ }[];
340
+ };
341
+ role: "agent";
312
342
  } | {
313
343
  conversationId: string;
314
344
  modelName: string;
@@ -478,6 +508,21 @@ export declare const createConversationMachine: (config: SonarV4Config) => impor
478
508
  result: Record<string, unknown>;
479
509
  };
480
510
  role: "agent";
511
+ } | {
512
+ conversationId: string;
513
+ modelName: string;
514
+ modelProviderId: string;
515
+ runId: string;
516
+ createdAt: import("temporal-polyfill").Temporal.Instant;
517
+ id: string;
518
+ content: {
519
+ chunkType: "selectedSkills";
520
+ selectedSkills: {
521
+ id: string;
522
+ name: string;
523
+ }[];
524
+ };
525
+ role: "agent";
481
526
  } | {
482
527
  conversationId: string;
483
528
  modelName: string;
@@ -664,6 +709,21 @@ export declare const createConversationMachine: (config: SonarV4Config) => impor
664
709
  result: Record<string, unknown>;
665
710
  };
666
711
  role: "agent";
712
+ } | {
713
+ conversationId: string;
714
+ modelName: string;
715
+ modelProviderId: string;
716
+ runId: string;
717
+ createdAt: import("temporal-polyfill").Temporal.Instant;
718
+ id: string;
719
+ content: {
720
+ chunkType: "selectedSkills";
721
+ selectedSkills: {
722
+ id: string;
723
+ name: string;
724
+ }[];
725
+ };
726
+ role: "agent";
667
727
  } | {
668
728
  conversationId: string;
669
729
  modelName: string;
@@ -830,6 +890,21 @@ export declare const createConversationMachine: (config: SonarV4Config) => impor
830
890
  result: Record<string, unknown>;
831
891
  };
832
892
  role: "agent";
893
+ } | {
894
+ conversationId: string;
895
+ modelName: string;
896
+ modelProviderId: string;
897
+ runId: string;
898
+ createdAt: import("temporal-polyfill").Temporal.Instant;
899
+ id: string;
900
+ content: {
901
+ chunkType: "selectedSkills";
902
+ selectedSkills: {
903
+ id: string;
904
+ name: string;
905
+ }[];
906
+ };
907
+ role: "agent";
833
908
  } | {
834
909
  conversationId: string;
835
910
  modelName: string;
@@ -1011,6 +1086,21 @@ export declare const createConversationMachine: (config: SonarV4Config) => impor
1011
1086
  result: Record<string, unknown>;
1012
1087
  };
1013
1088
  role: "agent";
1089
+ } | {
1090
+ conversationId: string;
1091
+ modelName: string;
1092
+ modelProviderId: string;
1093
+ runId: string;
1094
+ createdAt: import("temporal-polyfill").Temporal.Instant;
1095
+ id: string;
1096
+ content: {
1097
+ chunkType: "selectedSkills";
1098
+ selectedSkills: {
1099
+ id: string;
1100
+ name: string;
1101
+ }[];
1102
+ };
1103
+ role: "agent";
1014
1104
  } | {
1015
1105
  conversationId: string;
1016
1106
  modelName: string;
@@ -80,6 +80,21 @@ export declare const retrieveConversationHistory: (config: SonarV4Config) => (id
80
80
  result: Record<string, unknown>;
81
81
  };
82
82
  role: "agent";
83
+ } | {
84
+ conversationId: string;
85
+ modelName: string;
86
+ modelProviderId: string;
87
+ runId: string;
88
+ createdAt: import("temporal-polyfill").Temporal.Instant;
89
+ id: string;
90
+ content: {
91
+ chunkType: "selectedSkills";
92
+ selectedSkills: {
93
+ id: string;
94
+ name: string;
95
+ }[];
96
+ };
97
+ role: "agent";
83
98
  } | {
84
99
  conversationId: string;
85
100
  modelName: string;
@@ -1,4 +1,4 @@
1
- import type { ChatEvent, ChatEventWithChunkType } from "../chat/chatEventSchema.ts";
1
+ import type { ChatEvent, ChatEventWithChunkType, SelectedSkillInfo } from "../chat/chatEventSchema.ts";
2
2
  import type { UserChatMessage } from "../chat/UserChatMessage.ts";
3
3
  export type AgentToolCall = {
4
4
  id: string;
@@ -7,9 +7,13 @@ export type AgentToolCall = {
7
7
  result: ChatEventWithChunkType<"toolResponse"> | undefined;
8
8
  };
9
9
  export type ConversationExchangeMessage = ChatEventWithChunkType<"error"> | ChatEventWithChunkType<"model"> | ChatEventWithChunkType<"sandboxProgress"> | ChatEventWithChunkType<"sandboxStdout"> | ChatEventWithChunkType<"userMessage">;
10
+ export type ConversationExchangeRunMetadata = {
11
+ selectedSkills?: SelectedSkillInfo[];
12
+ };
10
13
  export type ConversationExchange = {
11
14
  id: string;
12
15
  messages: Map<string, ConversationExchangeMessage>;
16
+ runMetadata?: ConversationExchangeRunMetadata;
13
17
  submittedUserMessage?: UserChatMessage;
14
18
  toolCalls: Map<string, AgentToolCall>;
15
19
  };
@@ -14,6 +14,10 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { create } from "mutative";
17
+ import { Temporal } from "temporal-polyfill";
18
+ // Mutative array drafts do not handle symbol-key reads reliably, so use a non-enumerable
19
+ // string key for reducer bookkeeping while keeping JSON/deep equality output clean.
20
+ const selectedSkillsCursorKey = "__dremioSelectedSkillsCursor";
17
21
  function applyChatEventToConversation(draft, chatEvent) {
18
22
  let conversationExchange = draft.findLast((exchange) => exchange.id === chatEvent.runId);
19
23
  if (!conversationExchange) {
@@ -37,6 +41,10 @@ function applyChatEventToConversationExchange(conversationExchange, chatEvent) {
37
41
  }
38
42
  break;
39
43
  }
44
+ case "selectedSkills": {
45
+ applySelectedSkillsMetadata(conversationExchange, chatEvent);
46
+ break;
47
+ }
40
48
  case "error":
41
49
  case "model":
42
50
  case "sandboxProgress":
@@ -76,6 +84,91 @@ function applyChatEventToConversationExchange(conversationExchange, chatEvent) {
76
84
  }
77
85
  }
78
86
  }
87
+ function applySelectedSkillsMetadata(conversationExchange, chatEvent) {
88
+ if (!isSelectedSkillsEventNewer(conversationExchange.runMetadata, chatEvent)) {
89
+ return;
90
+ }
91
+ conversationExchange.runMetadata ??= {};
92
+ // Clone before attaching reducer bookkeeping so the input event payload stays immutable.
93
+ const selectedSkills = [...chatEvent.content.selectedSkills];
94
+ setSelectedSkillsCursor(selectedSkills, {
95
+ messagePosition: parseMessagePosition(chatEvent.id),
96
+ updatedAt: chatEvent.createdAt,
97
+ });
98
+ conversationExchange.runMetadata.selectedSkills = selectedSkills;
99
+ }
100
+ function isSelectedSkillsEventNewer(runMetadata, chatEvent) {
101
+ // selectedSkills is singleton run metadata, so unlike messages and tool calls it is not keyed by
102
+ // event id. Keep newer live-stream metadata when an older history replay is reduced later.
103
+ const cursor = getSelectedSkillsCursor(runMetadata);
104
+ if (!cursor) {
105
+ return true;
106
+ }
107
+ const timestampComparison = Temporal.Instant.compare(chatEvent.createdAt, cursor.updatedAt);
108
+ if (timestampComparison !== 0) {
109
+ return timestampComparison > 0;
110
+ }
111
+ const messagePositionComparison = compareMessagePositions(parseMessagePosition(chatEvent.id), cursor.messagePosition);
112
+ if (messagePositionComparison !== undefined) {
113
+ return messagePositionComparison >= 0;
114
+ }
115
+ return true;
116
+ }
117
+ function getSelectedSkillsCursor(runMetadata) {
118
+ return runMetadata?.selectedSkills?.[selectedSkillsCursorKey];
119
+ }
120
+ function setSelectedSkillsCursor(selectedSkills, cursor) {
121
+ Object.defineProperty(selectedSkills, selectedSkillsCursorKey, {
122
+ configurable: true,
123
+ enumerable: false,
124
+ value: cursor,
125
+ writable: true,
126
+ });
127
+ }
128
+ // Run-events message ids are chunkId:messageSubId; split message parts append :partId.
129
+ function parseMessagePosition(messageId) {
130
+ const parts = messageId.split(":");
131
+ if (parts.length < 2 || parts.length > 3) {
132
+ return undefined;
133
+ }
134
+ const [chunkId, messageSubId, partId] = parts;
135
+ if (!chunkId) {
136
+ return undefined;
137
+ }
138
+ const parsedMessageSubId = parseNonNegativeInteger(messageSubId);
139
+ if (parsedMessageSubId === undefined) {
140
+ return undefined;
141
+ }
142
+ const parsedPartId = partId === undefined ? undefined : parseNonNegativeInteger(partId);
143
+ if (partId !== undefined && parsedPartId === undefined) {
144
+ return undefined;
145
+ }
146
+ return {
147
+ chunkId,
148
+ messageSubId: parsedMessageSubId,
149
+ partId: parsedPartId,
150
+ };
151
+ }
152
+ function parseNonNegativeInteger(value) {
153
+ if (value === undefined || !/^\d+$/.test(value)) {
154
+ return undefined;
155
+ }
156
+ const parsedValue = Number(value);
157
+ if (!Number.isSafeInteger(parsedValue)) {
158
+ return undefined;
159
+ }
160
+ return parsedValue;
161
+ }
162
+ function compareMessagePositions(incoming, current) {
163
+ if (!incoming || !current || incoming.chunkId !== current.chunkId) {
164
+ return undefined;
165
+ }
166
+ const messageSubIdComparison = incoming.messageSubId - current.messageSubId;
167
+ if (messageSubIdComparison !== 0) {
168
+ return messageSubIdComparison;
169
+ }
170
+ return (incoming.partId ?? 0) - (current.partId ?? 0);
171
+ }
79
172
  export function reduceChatEvents(state = [], chatEvents) {
80
173
  return create(state, (draft) => {
81
174
  for (const chatEvent of chatEvents) {
@@ -1 +1 @@
1
- {"version":3,"file":"reduce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I,UAAU,EAAE,CAAC;YACnC,4BAA4B,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;QAChE,CAAC;IACH,CAAC,CAAC,CAAC;AACL,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 { create, type Draft } from \"mutative\";\nimport type { ChatEvent, ChatEventWithChunkType } from \"../chat/chatEventSchema.ts\";\nimport type { UserChatMessage } from \"../chat/UserChatMessage.ts\";\n\nexport type AgentToolCall = {\n id: string;\n state: \"canceled\" | \"error\" | \"pending\" | \"success\";\n request: ChatEventWithChunkType<\"toolRequest\"> | undefined;\n result: ChatEventWithChunkType<\"toolResponse\"> | undefined;\n};\n\nexport type ConversationExchangeMessage =\n | ChatEventWithChunkType<\"error\">\n | ChatEventWithChunkType<\"model\">\n | ChatEventWithChunkType<\"sandboxProgress\">\n | ChatEventWithChunkType<\"sandboxStdout\">\n | ChatEventWithChunkType<\"userMessage\">;\n\nexport type ConversationExchange = {\n id: string;\n messages: Map<string, ConversationExchangeMessage>;\n submittedUserMessage?: UserChatMessage;\n toolCalls: Map<string, AgentToolCall>;\n};\n\nexport type ChatEventReducerState = ConversationExchange[];\n\nfunction applyChatEventToConversation(\n draft: Draft<ChatEventReducerState>,\n chatEvent: ChatEvent,\n): void {\n let conversationExchange = draft.findLast((exchange) => exchange.id === chatEvent.runId);\n\n if (!conversationExchange) {\n conversationExchange = {\n id: chatEvent.runId,\n messages: new Map(),\n toolCalls: new Map(),\n };\n draft.push(conversationExchange);\n conversationExchange = draft[draft.length - 1];\n }\n\n applyChatEventToConversationExchange(conversationExchange!, chatEvent);\n}\n\nfunction applyChatEventToConversationExchange(\n conversationExchange: Draft<ConversationExchange>,\n chatEvent: ChatEvent,\n): void {\n switch (chatEvent.content.chunkType) {\n case \"endOfStream\": {\n for (const [, toolCall] of conversationExchange.toolCalls) {\n if (!toolCall.result) {\n toolCall.state = \"canceled\";\n }\n }\n break;\n }\n case \"error\":\n case \"model\":\n case \"sandboxProgress\":\n case \"sandboxStdout\":\n case \"userMessage\": {\n // TypeScript doesn't narrow outer union via nested content.chunkType; cast is sound here\n const event = chatEvent as Extract<ChatEvent, { id: string }>;\n conversationExchange.messages.set(event.id, event as Draft<ConversationExchangeMessage>);\n break;\n }\n case \"toolRequest\":\n case \"toolResponse\": {\n const callId = chatEvent.content.callId;\n\n if (!conversationExchange.toolCalls.has(callId)) {\n conversationExchange.toolCalls.set(callId, {\n id: callId,\n request: undefined,\n result: undefined,\n state: \"pending\",\n });\n }\n\n const toolCall = conversationExchange.toolCalls.get(callId)!;\n\n switch (chatEvent.content.chunkType) {\n case \"toolRequest\":\n toolCall.request = chatEvent as unknown as Draft<ChatEventWithChunkType<\"toolRequest\">>;\n break;\n case \"toolResponse\":\n toolCall.result = chatEvent as unknown as Draft<ChatEventWithChunkType<\"toolResponse\">>;\n if (\"errorMessage\" in toolCall.result.content.result) {\n toolCall.state = \"error\";\n } else {\n toolCall.state = \"success\";\n }\n break;\n }\n }\n }\n}\n\nexport function reduceChatEvents(state: ChatEventReducerState = [], chatEvents: ChatEvent[]) {\n return create(state, (draft) => {\n for (const chatEvent of chatEvents) {\n applyChatEventToConversation(draft, Object.freeze(chatEvent));\n }\n });\n}\n"]}
1
+ {"version":3,"file":"reduceChatEvents.js","sourceRoot":"","sources":["../../../../src/enterprise/ai/conversations/reduceChatEvents.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,EAAc,MAAM,UAAU,CAAC;AAC9C,OAA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C,KAAK,CAAC,CAAC;IAClC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,EAAE,CAAC;QACvC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,SAAS,uBAAuB,CAC9B,QAAqC,EACrC,OAA2C;IAE3C,IAAI,CAAC,QAAQ,IAAI,CAAC,OAAO,IAAI,QAAQ,CAAC,OAAO,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC;QAClE,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,sBAAsB,GAAG,QAAQ,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAC5E,IAAI,sBAAsB,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO,sBAAsB,CAAC;IAChC,CAAC;IAED,OAAO,CAAC,QAAQ,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC;AACxD,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,QAA+B,EAAE,EAAE,UAAuB;IACzF,OAAO,MAAM,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;QAC7B,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,4BAA4B,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;QAChE,CAAC;IACH,CAAC,CAAC,CAAC;AACL,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 { create, type Draft } from \"mutative\";\nimport { Temporal } from \"temporal-polyfill\";\nimport type {\n ChatEvent,\n ChatEventWithChunkType,\n SelectedSkillInfo,\n} from \"../chat/chatEventSchema.ts\";\nimport type { UserChatMessage } from \"../chat/UserChatMessage.ts\";\n\nexport type AgentToolCall = {\n id: string;\n state: \"canceled\" | \"error\" | \"pending\" | \"success\";\n request: ChatEventWithChunkType<\"toolRequest\"> | undefined;\n result: ChatEventWithChunkType<\"toolResponse\"> | undefined;\n};\n\nexport type ConversationExchangeMessage =\n | ChatEventWithChunkType<\"error\">\n | ChatEventWithChunkType<\"model\">\n | ChatEventWithChunkType<\"sandboxProgress\">\n | ChatEventWithChunkType<\"sandboxStdout\">\n | ChatEventWithChunkType<\"userMessage\">;\n\n// Mutative array drafts do not handle symbol-key reads reliably, so use a non-enumerable\n// string key for reducer bookkeeping while keeping JSON/deep equality output clean.\nconst selectedSkillsCursorKey = \"__dremioSelectedSkillsCursor\";\n\ntype SelectedSkillsCursor = {\n messagePosition: MessagePosition | undefined;\n updatedAt: Temporal.Instant;\n};\n\ntype SelectedSkillsWithCursor = SelectedSkillInfo[] & {\n [selectedSkillsCursorKey]?: SelectedSkillsCursor;\n};\n\ntype MessagePosition = {\n chunkId: string;\n messageSubId: number;\n partId: number | undefined;\n};\n\nexport type ConversationExchangeRunMetadata = {\n selectedSkills?: SelectedSkillInfo[];\n};\n\nexport type ConversationExchange = {\n id: string;\n messages: Map<string, ConversationExchangeMessage>;\n runMetadata?: ConversationExchangeRunMetadata;\n submittedUserMessage?: UserChatMessage;\n toolCalls: Map<string, AgentToolCall>;\n};\n\nexport type ChatEventReducerState = ConversationExchange[];\n\nfunction applyChatEventToConversation(\n draft: Draft<ChatEventReducerState>,\n chatEvent: ChatEvent,\n): void {\n let conversationExchange = draft.findLast((exchange) => exchange.id === chatEvent.runId);\n\n if (!conversationExchange) {\n conversationExchange = {\n id: chatEvent.runId,\n messages: new Map(),\n toolCalls: new Map(),\n };\n draft.push(conversationExchange);\n conversationExchange = draft[draft.length - 1];\n }\n\n applyChatEventToConversationExchange(conversationExchange!, chatEvent);\n}\n\nfunction applyChatEventToConversationExchange(\n conversationExchange: Draft<ConversationExchange>,\n chatEvent: ChatEvent,\n): void {\n switch (chatEvent.content.chunkType) {\n case \"endOfStream\": {\n for (const [, toolCall] of conversationExchange.toolCalls) {\n if (!toolCall.result) {\n toolCall.state = \"canceled\";\n }\n }\n break;\n }\n case \"selectedSkills\": {\n applySelectedSkillsMetadata(\n conversationExchange,\n chatEvent as ChatEventWithChunkType<\"selectedSkills\">,\n );\n break;\n }\n case \"error\":\n case \"model\":\n case \"sandboxProgress\":\n case \"sandboxStdout\":\n case \"userMessage\": {\n // TypeScript doesn't narrow outer union via nested content.chunkType; cast is sound here\n const event = chatEvent as Extract<ChatEvent, { id: string }>;\n conversationExchange.messages.set(event.id, event as Draft<ConversationExchangeMessage>);\n break;\n }\n case \"toolRequest\":\n case \"toolResponse\": {\n const callId = chatEvent.content.callId;\n\n if (!conversationExchange.toolCalls.has(callId)) {\n conversationExchange.toolCalls.set(callId, {\n id: callId,\n request: undefined,\n result: undefined,\n state: \"pending\",\n });\n }\n\n const toolCall = conversationExchange.toolCalls.get(callId)!;\n\n switch (chatEvent.content.chunkType) {\n case \"toolRequest\":\n toolCall.request = chatEvent as unknown as Draft<ChatEventWithChunkType<\"toolRequest\">>;\n break;\n case \"toolResponse\":\n toolCall.result = chatEvent as unknown as Draft<ChatEventWithChunkType<\"toolResponse\">>;\n if (\"errorMessage\" in toolCall.result.content.result) {\n toolCall.state = \"error\";\n } else {\n toolCall.state = \"success\";\n }\n break;\n }\n }\n }\n}\n\nfunction applySelectedSkillsMetadata(\n conversationExchange: Draft<ConversationExchange>,\n chatEvent: ChatEventWithChunkType<\"selectedSkills\">,\n): void {\n if (!isSelectedSkillsEventNewer(conversationExchange.runMetadata, chatEvent)) {\n return;\n }\n\n conversationExchange.runMetadata ??= {};\n // Clone before attaching reducer bookkeeping so the input event payload stays immutable.\n const selectedSkills = [...chatEvent.content.selectedSkills];\n setSelectedSkillsCursor(selectedSkills, {\n messagePosition: parseMessagePosition(chatEvent.id),\n updatedAt: chatEvent.createdAt,\n });\n conversationExchange.runMetadata.selectedSkills = selectedSkills;\n}\n\nfunction isSelectedSkillsEventNewer(\n runMetadata: Draft<ConversationExchangeRunMetadata> | undefined,\n chatEvent: ChatEventWithChunkType<\"selectedSkills\">,\n): boolean {\n // selectedSkills is singleton run metadata, so unlike messages and tool calls it is not keyed by\n // event id. Keep newer live-stream metadata when an older history replay is reduced later.\n const cursor = getSelectedSkillsCursor(runMetadata);\n if (!cursor) {\n return true;\n }\n\n const timestampComparison = Temporal.Instant.compare(chatEvent.createdAt, cursor.updatedAt);\n if (timestampComparison !== 0) {\n return timestampComparison > 0;\n }\n\n const messagePositionComparison = compareMessagePositions(\n parseMessagePosition(chatEvent.id),\n cursor.messagePosition,\n );\n if (messagePositionComparison !== undefined) {\n return messagePositionComparison >= 0;\n }\n\n return true;\n}\n\nfunction getSelectedSkillsCursor(\n runMetadata: Draft<ConversationExchangeRunMetadata> | undefined,\n): Draft<SelectedSkillsCursor> | undefined {\n return (runMetadata?.selectedSkills as Draft<SelectedSkillsWithCursor> | undefined)?.[\n selectedSkillsCursorKey\n ];\n}\n\nfunction setSelectedSkillsCursor(\n selectedSkills: SelectedSkillInfo[],\n cursor: SelectedSkillsCursor,\n): void {\n Object.defineProperty(selectedSkills, selectedSkillsCursorKey, {\n configurable: true,\n enumerable: false,\n value: cursor,\n writable: true,\n });\n}\n\n// Run-events message ids are chunkId:messageSubId; split message parts append :partId.\nfunction parseMessagePosition(messageId: string): MessagePosition | undefined {\n const parts = messageId.split(\":\");\n if (parts.length < 2 || parts.length > 3) {\n return undefined;\n }\n\n const [chunkId, messageSubId, partId] = parts;\n if (!chunkId) {\n return undefined;\n }\n\n const parsedMessageSubId = parseNonNegativeInteger(messageSubId);\n if (parsedMessageSubId === undefined) {\n return undefined;\n }\n\n const parsedPartId = partId === undefined ? undefined : parseNonNegativeInteger(partId);\n if (partId !== undefined && parsedPartId === undefined) {\n return undefined;\n }\n\n return {\n chunkId,\n messageSubId: parsedMessageSubId,\n partId: parsedPartId,\n };\n}\n\nfunction parseNonNegativeInteger(value: string | undefined): number | undefined {\n if (value === undefined || !/^\\d+$/.test(value)) {\n return undefined;\n }\n\n const parsedValue = Number(value);\n if (!Number.isSafeInteger(parsedValue)) {\n return undefined;\n }\n\n return parsedValue;\n}\n\nfunction compareMessagePositions(\n incoming: MessagePosition | undefined,\n current: Draft<MessagePosition> | undefined,\n): number | undefined {\n if (!incoming || !current || incoming.chunkId !== current.chunkId) {\n return undefined;\n }\n\n const messageSubIdComparison = incoming.messageSubId - current.messageSubId;\n if (messageSubIdComparison !== 0) {\n return messageSubIdComparison;\n }\n\n return (incoming.partId ?? 0) - (current.partId ?? 0);\n}\n\nexport function reduceChatEvents(state: ChatEventReducerState = [], chatEvents: ChatEvent[]) {\n return create(state, (draft) => {\n for (const chatEvent of chatEvents) {\n applyChatEventToConversation(draft, Object.freeze(chatEvent));\n }\n });\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import { AgentConversation } from "./conversations/AgentConversation.ts";
2
2
  import { ModelProvider } from "./modelProvider/ModelProvider.ts";
3
- import { type ChatEvent, type ChatEventWithChunkType } from "./chat/chatEventSchema.ts";
4
- import type { ConversationExchange, ConversationExchangeMessage, AgentToolCall } from "./conversations/reduceChatEvents.ts";
3
+ import { type ChatEvent, type ChatEventWithChunkType, type SelectedSkillInfo } from "./chat/chatEventSchema.ts";
4
+ import type { ConversationExchange, ConversationExchangeMessage, ConversationExchangeRunMetadata, AgentToolCall } from "./conversations/reduceChatEvents.ts";
5
5
  import { type AgentConversationMachine } from "./conversations/createConversationMachine.ts";
6
6
  export * from "./chat/index.ts";
7
- export { AgentConversation, ModelProvider, type ChatEvent, type ChatEventWithChunkType, type ConversationExchange, type ConversationExchangeMessage, type AgentToolCall, type AgentConversationMachine, };
7
+ export { AgentConversation, ModelProvider, type ChatEvent, type ChatEventWithChunkType, type SelectedSkillInfo, type ConversationExchange, type ConversationExchangeMessage, type ConversationExchangeRunMetadata, type AgentToolCall, type AgentConversationMachine, };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/enterprise/ai/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAA+C,MAAM,2BAA2B,CAAC;AAMxF,OAAO,EAAiC,MAAM,8CAA8C,CAAC;AAC7F,cAAc,iBAAiB,CAAC;AAChC,OAAO,EACL,iBAAiB,EACjB,aAAa,GAOd,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 { AgentConversation } from \"./conversations/AgentConversation.ts\";\nimport { ModelProvider } from \"./modelProvider/ModelProvider.ts\";\nimport { type ChatEvent, type ChatEventWithChunkType } from \"./chat/chatEventSchema.ts\";\nimport type {\n ConversationExchange,\n ConversationExchangeMessage,\n AgentToolCall,\n} from \"./conversations/reduceChatEvents.ts\";\nimport { type AgentConversationMachine } from \"./conversations/createConversationMachine.ts\";\nexport * from \"./chat/index.ts\";\nexport {\n AgentConversation,\n ModelProvider,\n type ChatEvent,\n type ChatEventWithChunkType,\n type ConversationExchange,\n type ConversationExchangeMessage,\n type AgentToolCall,\n type AgentConversationMachine,\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/enterprise/ai/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAIN,MAAM,2BAA2B,CAAC;AAOnC,OAAO,EAAiC,MAAM,8CAA8C,CAAC;AAC7F,cAAc,iBAAiB,CAAC;AAChC,OAAO,EACL,iBAAiB,EACjB,aAAa,GASd,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 { AgentConversation } from \"./conversations/AgentConversation.ts\";\nimport { ModelProvider } from \"./modelProvider/ModelProvider.ts\";\nimport {\n type ChatEvent,\n type ChatEventWithChunkType,\n type SelectedSkillInfo,\n} from \"./chat/chatEventSchema.ts\";\nimport type {\n ConversationExchange,\n ConversationExchangeMessage,\n ConversationExchangeRunMetadata,\n AgentToolCall,\n} from \"./conversations/reduceChatEvents.ts\";\nimport { type AgentConversationMachine } from \"./conversations/createConversationMachine.ts\";\nexport * from \"./chat/index.ts\";\nexport {\n AgentConversation,\n ModelProvider,\n type ChatEvent,\n type ChatEventWithChunkType,\n type SelectedSkillInfo,\n type ConversationExchange,\n type ConversationExchangeMessage,\n type ConversationExchangeRunMetadata,\n type AgentToolCall,\n type AgentConversationMachine,\n};\n"]}
@@ -17251,6 +17251,14 @@ var DremioCloud = (() => {
17251
17251
  toolExecutionId: string2(),
17252
17252
  toolName: string2()
17253
17253
  });
17254
+ var selectedSkillInfoSchema = object({
17255
+ id: string2(),
17256
+ name: string2()
17257
+ });
17258
+ var selectedSkillsChunkSchema = object({
17259
+ chunkType: literal("selectedSkills"),
17260
+ selectedSkills: array(selectedSkillInfoSchema)
17261
+ });
17254
17262
  var userMessageChunkSchema = object({
17255
17263
  chunkType: literal("userMessage"),
17256
17264
  text: string2()
@@ -17268,6 +17276,7 @@ var DremioCloud = (() => {
17268
17276
  extend2(conversationUpdateChunkSchema, chatEventSharedSchema),
17269
17277
  extend2(jobUpdateChunkSchema, chatEventSharedSchema),
17270
17278
  extend2(modelChunkSchema, chatEventSharedSchema),
17279
+ extend2(selectedSkillsChunkSchema, chatEventSharedSchema),
17271
17280
  extend2(sandboxProgressChunkSchema, chatEventSharedSchema),
17272
17281
  sandboxStdoutChatEventSchema,
17273
17282
  extend2(toolRequestChunkSchema, chatEventSharedSchema),
@@ -17298,6 +17307,10 @@ var DremioCloud = (() => {
17298
17307
  role: literal("agent")
17299
17308
  }),
17300
17309
  extend2(chatEventOutputSharedSchema, { content: modelChunkSchema, role: literal("agent") }),
17310
+ extend2(chatEventOutputSharedSchema, {
17311
+ content: selectedSkillsChunkSchema,
17312
+ role: literal("agent")
17313
+ }),
17301
17314
  extend2(chatEventOutputSharedSchema, {
17302
17315
  content: sandboxProgressChunkSchema,
17303
17316
  role: literal("agent")
@@ -17391,6 +17404,15 @@ var DremioCloud = (() => {
17391
17404
  },
17392
17405
  role: "agent"
17393
17406
  };
17407
+ case "selectedSkills":
17408
+ return {
17409
+ ...sharedProperties,
17410
+ content: {
17411
+ chunkType: "selectedSkills",
17412
+ selectedSkills: v2.selectedSkills
17413
+ },
17414
+ role: "agent"
17415
+ };
17394
17416
  case "sandboxProgress":
17395
17417
  return {
17396
17418
  ...sharedProperties,
@@ -19457,6 +19479,7 @@ var DremioCloud = (() => {
19457
19479
  var constructorString = Object.prototype.constructor.toString();
19458
19480
 
19459
19481
  // dist/enterprise/ai/conversations/reduceChatEvents.js
19482
+ var selectedSkillsCursorKey = "__dremioSelectedSkillsCursor";
19460
19483
  function applyChatEventToConversation(draft, chatEvent) {
19461
19484
  let conversationExchange = draft.findLast((exchange) => exchange.id === chatEvent.runId);
19462
19485
  if (!conversationExchange) {
@@ -19480,6 +19503,10 @@ var DremioCloud = (() => {
19480
19503
  }
19481
19504
  break;
19482
19505
  }
19506
+ case "selectedSkills": {
19507
+ applySelectedSkillsMetadata(conversationExchange, chatEvent);
19508
+ break;
19509
+ }
19483
19510
  case "error":
19484
19511
  case "model":
19485
19512
  case "sandboxProgress":
@@ -19517,6 +19544,87 @@ var DremioCloud = (() => {
19517
19544
  }
19518
19545
  }
19519
19546
  }
19547
+ function applySelectedSkillsMetadata(conversationExchange, chatEvent) {
19548
+ if (!isSelectedSkillsEventNewer(conversationExchange.runMetadata, chatEvent)) {
19549
+ return;
19550
+ }
19551
+ conversationExchange.runMetadata ??= {};
19552
+ const selectedSkills = [...chatEvent.content.selectedSkills];
19553
+ setSelectedSkillsCursor(selectedSkills, {
19554
+ messagePosition: parseMessagePosition(chatEvent.id),
19555
+ updatedAt: chatEvent.createdAt
19556
+ });
19557
+ conversationExchange.runMetadata.selectedSkills = selectedSkills;
19558
+ }
19559
+ function isSelectedSkillsEventNewer(runMetadata, chatEvent) {
19560
+ const cursor = getSelectedSkillsCursor(runMetadata);
19561
+ if (!cursor) {
19562
+ return true;
19563
+ }
19564
+ const timestampComparison = Xn.Instant.compare(chatEvent.createdAt, cursor.updatedAt);
19565
+ if (timestampComparison !== 0) {
19566
+ return timestampComparison > 0;
19567
+ }
19568
+ const messagePositionComparison = compareMessagePositions(parseMessagePosition(chatEvent.id), cursor.messagePosition);
19569
+ if (messagePositionComparison !== void 0) {
19570
+ return messagePositionComparison >= 0;
19571
+ }
19572
+ return true;
19573
+ }
19574
+ function getSelectedSkillsCursor(runMetadata) {
19575
+ return runMetadata?.selectedSkills?.[selectedSkillsCursorKey];
19576
+ }
19577
+ function setSelectedSkillsCursor(selectedSkills, cursor) {
19578
+ Object.defineProperty(selectedSkills, selectedSkillsCursorKey, {
19579
+ configurable: true,
19580
+ enumerable: false,
19581
+ value: cursor,
19582
+ writable: true
19583
+ });
19584
+ }
19585
+ function parseMessagePosition(messageId) {
19586
+ const parts = messageId.split(":");
19587
+ if (parts.length < 2 || parts.length > 3) {
19588
+ return void 0;
19589
+ }
19590
+ const [chunkId, messageSubId, partId] = parts;
19591
+ if (!chunkId) {
19592
+ return void 0;
19593
+ }
19594
+ const parsedMessageSubId = parseNonNegativeInteger(messageSubId);
19595
+ if (parsedMessageSubId === void 0) {
19596
+ return void 0;
19597
+ }
19598
+ const parsedPartId = partId === void 0 ? void 0 : parseNonNegativeInteger(partId);
19599
+ if (partId !== void 0 && parsedPartId === void 0) {
19600
+ return void 0;
19601
+ }
19602
+ return {
19603
+ chunkId,
19604
+ messageSubId: parsedMessageSubId,
19605
+ partId: parsedPartId
19606
+ };
19607
+ }
19608
+ function parseNonNegativeInteger(value) {
19609
+ if (value === void 0 || !/^\d+$/.test(value)) {
19610
+ return void 0;
19611
+ }
19612
+ const parsedValue = Number(value);
19613
+ if (!Number.isSafeInteger(parsedValue)) {
19614
+ return void 0;
19615
+ }
19616
+ return parsedValue;
19617
+ }
19618
+ function compareMessagePositions(incoming, current2) {
19619
+ if (!incoming || !current2 || incoming.chunkId !== current2.chunkId) {
19620
+ return void 0;
19621
+ }
19622
+ const messageSubIdComparison = incoming.messageSubId - current2.messageSubId;
19623
+ if (messageSubIdComparison !== 0) {
19624
+ return messageSubIdComparison;
19625
+ }
19626
+ return (incoming.partId ?? 0) - (current2.partId ?? 0);
19627
+ }
19520
19628
  function reduceChatEvents(state = [], chatEvents) {
19521
19629
  return create(state, (draft) => {
19522
19630
  for (const chatEvent of chatEvents) {
@@ -16170,6 +16170,14 @@ var DremioEnterprise = (() => {
16170
16170
  toolExecutionId: string2(),
16171
16171
  toolName: string2()
16172
16172
  });
16173
+ var selectedSkillInfoSchema = object({
16174
+ id: string2(),
16175
+ name: string2()
16176
+ });
16177
+ var selectedSkillsChunkSchema = object({
16178
+ chunkType: literal("selectedSkills"),
16179
+ selectedSkills: array(selectedSkillInfoSchema)
16180
+ });
16173
16181
  var userMessageChunkSchema = object({
16174
16182
  chunkType: literal("userMessage"),
16175
16183
  text: string2()
@@ -16187,6 +16195,7 @@ var DremioEnterprise = (() => {
16187
16195
  extend2(conversationUpdateChunkSchema, chatEventSharedSchema),
16188
16196
  extend2(jobUpdateChunkSchema, chatEventSharedSchema),
16189
16197
  extend2(modelChunkSchema, chatEventSharedSchema),
16198
+ extend2(selectedSkillsChunkSchema, chatEventSharedSchema),
16190
16199
  extend2(sandboxProgressChunkSchema, chatEventSharedSchema),
16191
16200
  sandboxStdoutChatEventSchema,
16192
16201
  extend2(toolRequestChunkSchema, chatEventSharedSchema),
@@ -16217,6 +16226,10 @@ var DremioEnterprise = (() => {
16217
16226
  role: literal("agent")
16218
16227
  }),
16219
16228
  extend2(chatEventOutputSharedSchema, { content: modelChunkSchema, role: literal("agent") }),
16229
+ extend2(chatEventOutputSharedSchema, {
16230
+ content: selectedSkillsChunkSchema,
16231
+ role: literal("agent")
16232
+ }),
16220
16233
  extend2(chatEventOutputSharedSchema, {
16221
16234
  content: sandboxProgressChunkSchema,
16222
16235
  role: literal("agent")
@@ -16310,6 +16323,15 @@ var DremioEnterprise = (() => {
16310
16323
  },
16311
16324
  role: "agent"
16312
16325
  };
16326
+ case "selectedSkills":
16327
+ return {
16328
+ ...sharedProperties,
16329
+ content: {
16330
+ chunkType: "selectedSkills",
16331
+ selectedSkills: v2.selectedSkills
16332
+ },
16333
+ role: "agent"
16334
+ };
16313
16335
  case "sandboxProgress":
16314
16336
  return {
16315
16337
  ...sharedProperties,
@@ -18027,6 +18049,7 @@ var DremioEnterprise = (() => {
18027
18049
  var constructorString = Object.prototype.constructor.toString();
18028
18050
 
18029
18051
  // dist/enterprise/ai/conversations/reduceChatEvents.js
18052
+ var selectedSkillsCursorKey = "__dremioSelectedSkillsCursor";
18030
18053
  function applyChatEventToConversation(draft, chatEvent) {
18031
18054
  let conversationExchange = draft.findLast((exchange) => exchange.id === chatEvent.runId);
18032
18055
  if (!conversationExchange) {
@@ -18050,6 +18073,10 @@ var DremioEnterprise = (() => {
18050
18073
  }
18051
18074
  break;
18052
18075
  }
18076
+ case "selectedSkills": {
18077
+ applySelectedSkillsMetadata(conversationExchange, chatEvent);
18078
+ break;
18079
+ }
18053
18080
  case "error":
18054
18081
  case "model":
18055
18082
  case "sandboxProgress":
@@ -18087,6 +18114,87 @@ var DremioEnterprise = (() => {
18087
18114
  }
18088
18115
  }
18089
18116
  }
18117
+ function applySelectedSkillsMetadata(conversationExchange, chatEvent) {
18118
+ if (!isSelectedSkillsEventNewer(conversationExchange.runMetadata, chatEvent)) {
18119
+ return;
18120
+ }
18121
+ conversationExchange.runMetadata ??= {};
18122
+ const selectedSkills = [...chatEvent.content.selectedSkills];
18123
+ setSelectedSkillsCursor(selectedSkills, {
18124
+ messagePosition: parseMessagePosition(chatEvent.id),
18125
+ updatedAt: chatEvent.createdAt
18126
+ });
18127
+ conversationExchange.runMetadata.selectedSkills = selectedSkills;
18128
+ }
18129
+ function isSelectedSkillsEventNewer(runMetadata, chatEvent) {
18130
+ const cursor = getSelectedSkillsCursor(runMetadata);
18131
+ if (!cursor) {
18132
+ return true;
18133
+ }
18134
+ const timestampComparison = Xn.Instant.compare(chatEvent.createdAt, cursor.updatedAt);
18135
+ if (timestampComparison !== 0) {
18136
+ return timestampComparison > 0;
18137
+ }
18138
+ const messagePositionComparison = compareMessagePositions(parseMessagePosition(chatEvent.id), cursor.messagePosition);
18139
+ if (messagePositionComparison !== void 0) {
18140
+ return messagePositionComparison >= 0;
18141
+ }
18142
+ return true;
18143
+ }
18144
+ function getSelectedSkillsCursor(runMetadata) {
18145
+ return runMetadata?.selectedSkills?.[selectedSkillsCursorKey];
18146
+ }
18147
+ function setSelectedSkillsCursor(selectedSkills, cursor) {
18148
+ Object.defineProperty(selectedSkills, selectedSkillsCursorKey, {
18149
+ configurable: true,
18150
+ enumerable: false,
18151
+ value: cursor,
18152
+ writable: true
18153
+ });
18154
+ }
18155
+ function parseMessagePosition(messageId) {
18156
+ const parts = messageId.split(":");
18157
+ if (parts.length < 2 || parts.length > 3) {
18158
+ return void 0;
18159
+ }
18160
+ const [chunkId, messageSubId, partId] = parts;
18161
+ if (!chunkId) {
18162
+ return void 0;
18163
+ }
18164
+ const parsedMessageSubId = parseNonNegativeInteger(messageSubId);
18165
+ if (parsedMessageSubId === void 0) {
18166
+ return void 0;
18167
+ }
18168
+ const parsedPartId = partId === void 0 ? void 0 : parseNonNegativeInteger(partId);
18169
+ if (partId !== void 0 && parsedPartId === void 0) {
18170
+ return void 0;
18171
+ }
18172
+ return {
18173
+ chunkId,
18174
+ messageSubId: parsedMessageSubId,
18175
+ partId: parsedPartId
18176
+ };
18177
+ }
18178
+ function parseNonNegativeInteger(value) {
18179
+ if (value === void 0 || !/^\d+$/.test(value)) {
18180
+ return void 0;
18181
+ }
18182
+ const parsedValue = Number(value);
18183
+ if (!Number.isSafeInteger(parsedValue)) {
18184
+ return void 0;
18185
+ }
18186
+ return parsedValue;
18187
+ }
18188
+ function compareMessagePositions(incoming, current2) {
18189
+ if (!incoming || !current2 || incoming.chunkId !== current2.chunkId) {
18190
+ return void 0;
18191
+ }
18192
+ const messageSubIdComparison = incoming.messageSubId - current2.messageSubId;
18193
+ if (messageSubIdComparison !== 0) {
18194
+ return messageSubIdComparison;
18195
+ }
18196
+ return (incoming.partId ?? 0) - (current2.partId ?? 0);
18197
+ }
18090
18198
  function reduceChatEvents(state = [], chatEvents) {
18091
18199
  return create(state, (draft) => {
18092
18200
  for (const chatEvent of chatEvents) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dremio/js-sdk",
3
- "version": "0.61.0",
3
+ "version": "0.62.0",
4
4
  "description": "JavaScript library for the Dremio API",
5
5
  "keywords": [
6
6
  "dremio",