@dremio/js-sdk 0.58.0 → 0.60.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.
Files changed (26) hide show
  1. package/README.md +9 -0
  2. package/dist/cloud/ai/AIResource.d.ts +93 -13
  3. package/dist/enterprise/ai/AIResource.d.ts +93 -13
  4. package/dist/enterprise/ai/chat/UserChatMessage.d.ts +0 -2
  5. package/dist/enterprise/ai/chat/UserChatMessage.js +0 -1
  6. package/dist/enterprise/ai/chat/UserChatMessage.js.map +1 -1
  7. package/dist/enterprise/ai/chat/chatEventSchema.d.ts +26 -3
  8. package/dist/enterprise/ai/chat/chatEventSchema.js +61 -11
  9. package/dist/enterprise/ai/chat/chatEventSchema.js.map +1 -1
  10. package/dist/enterprise/ai/conversations/AgentConversation.d.ts +30 -4
  11. package/dist/enterprise/ai/conversations/createConversationMachine.d.ts +97 -13
  12. package/dist/enterprise/ai/conversations/createConversationMachine.js +80 -11
  13. package/dist/enterprise/ai/conversations/createConversationMachine.js.map +1 -1
  14. package/dist/enterprise/ai/conversations/methods/createConversation.d.ts +0 -1
  15. package/dist/enterprise/ai/conversations/methods/createConversation.js +0 -2
  16. package/dist/enterprise/ai/conversations/methods/createConversation.js.map +1 -1
  17. package/dist/enterprise/ai/conversations/methods/retrieveConversationHistory.d.ts +15 -2
  18. package/dist/enterprise/ai/conversations/reduceChatEvents.d.ts +1 -1
  19. package/dist/enterprise/ai/conversations/reduceChatEvents.js +4 -1
  20. package/dist/enterprise/ai/conversations/reduceChatEvents.js.map +1 -1
  21. package/dist/enterprise/catalog/CatalogObjects/EnterpriseDatasetCatalogObject.d.ts +7 -0
  22. package/dist/enterprise/catalog/CatalogObjects/EnterpriseDatasetCatalogObject.js +3 -0
  23. package/dist/enterprise/catalog/CatalogObjects/EnterpriseDatasetCatalogObject.js.map +1 -1
  24. package/dist-iife/cloud.js +150 -32
  25. package/dist-iife/enterprise.js +150 -32
  26. package/package.json +1 -1
@@ -25,6 +25,14 @@ import { streamRunEvents } from "./methods/streamRunEvents.js";
25
25
  import { fromTextEventStream } from "../../../common/fromTextEventStream.js";
26
26
  import { map } from "rxjs";
27
27
  import { chatEventCodec } from "../chat/chatEventSchema.js";
28
+ const RETRIEVE_STATE_TIMEOUT_MS = 10_000;
29
+ const STREAM_RETRY_DELAY_MS = 2500;
30
+ export const MAX_STREAM_RETRIES = 5;
31
+ const STREAM_STATE_RESET = {
32
+ receivedEndOfStream: false,
33
+ streamRetryCount: 0,
34
+ userRequestedStop: false,
35
+ };
28
36
  export const createConversationMachine = (config) => setup({
29
37
  actors: {
30
38
  createConversation: fromPromise(({ input }) => createConversation(config)(input).then((result) => {
@@ -46,9 +54,13 @@ export const createConversationMachine = (config) => setup({
46
54
  return result.value;
47
55
  })),
48
56
  retrieveState: fromPromise(async ({ input, signal }) => {
57
+ const timeoutSignal = AbortSignal.any([
58
+ signal,
59
+ AbortSignal.timeout(RETRIEVE_STATE_TIMEOUT_MS),
60
+ ]);
49
61
  const [conversationResult, historyResult] = await Promise.all([
50
- retrieveConversation(config)(input.conversationId, { signal }),
51
- retrieveConversationHistory(config)(input.conversationId, { signal }),
62
+ retrieveConversation(config)(input.conversationId, { signal: timeoutSignal }),
63
+ retrieveConversationHistory(config)(input.conversationId, { signal: timeoutSignal }),
52
64
  ]);
53
65
  if (conversationResult.isErr()) {
54
66
  throw conversationResult.error;
@@ -75,6 +87,9 @@ export const createConversationMachine = (config) => setup({
75
87
  })),
76
88
  streamRun: fromObservable(({ input }) => fromTextEventStream(({ signal }) => streamRunEvents(config)({ conversationId: input.conversationId, runId: input.runId }, { signal })).pipe(map((event) => z.decode(chatEventCodec, JSON.parse(event.data))))),
77
89
  },
90
+ delays: {
91
+ STREAM_RETRY_DELAY: STREAM_RETRY_DELAY_MS,
92
+ },
78
93
  types: {
79
94
  context: {},
80
95
  emitted: {},
@@ -87,6 +102,7 @@ export const createConversationMachine = (config) => setup({
87
102
  conversationSnapshot: undefined,
88
103
  currentRunId: undefined,
89
104
  messageAttempt: undefined,
105
+ ...STREAM_STATE_RESET,
90
106
  }),
91
107
  id: "agentConversation",
92
108
  initial: "uninitialized",
@@ -114,6 +130,7 @@ export const createConversationMachine = (config) => setup({
114
130
  ],
115
131
  currentRunId: ({ event }) => event.output.currentRunId,
116
132
  messageAttempt: undefined,
133
+ ...STREAM_STATE_RESET,
117
134
  }),
118
135
  emit(({ event }) => ({
119
136
  id: event.output.id,
@@ -177,6 +194,7 @@ export const createConversationMachine = (config) => setup({
177
194
  actions: assign({
178
195
  conversationSnapshot: ({ context, event }) => AgentConversation.reduceChatEvents(context.conversationSnapshot, event.output.history.data),
179
196
  currentRunId: ({ event }) => event.output.conversation.currentRunId,
197
+ receivedEndOfStream: false,
180
198
  }),
181
199
  guard: ({ event }) => !!event.output.conversation.currentRunId,
182
200
  target: "streaming",
@@ -185,6 +203,7 @@ export const createConversationMachine = (config) => setup({
185
203
  actions: assign({
186
204
  conversationSnapshot: ({ context, event }) => AgentConversation.reduceChatEvents(context.conversationSnapshot, event.output.history.data),
187
205
  currentRunId: ({ event }) => event.output.conversation.currentRunId,
206
+ ...STREAM_STATE_RESET,
188
207
  }),
189
208
  target: "idle",
190
209
  },
@@ -193,12 +212,18 @@ export const createConversationMachine = (config) => setup({
193
212
  {
194
213
  guard: ({ event }) => {
195
214
  const e = event.error;
215
+ if (e?.name === "TimeoutError")
216
+ return false;
196
217
  return (e?.name === "AbortError" ||
197
218
  e?.message?.includes("aborted") ||
198
219
  e?.code === "ABORT_ERR");
199
220
  },
200
221
  target: "uninitialized",
201
222
  },
223
+ {
224
+ guard: ({ context }) => context.streamRetryCount > 0,
225
+ target: "stream_interrupted",
226
+ },
202
227
  {
203
228
  actions: [
204
229
  assign({
@@ -215,6 +240,30 @@ export const createConversationMachine = (config) => setup({
215
240
  src: "retrieveState",
216
241
  },
217
242
  },
243
+ stream_interrupted: {
244
+ after: {
245
+ STREAM_RETRY_DELAY: [
246
+ {
247
+ actions: assign({
248
+ streamRetryCount: ({ context }) => context.streamRetryCount + 1,
249
+ }),
250
+ guard: ({ context }) => context.streamRetryCount < MAX_STREAM_RETRIES,
251
+ target: "retrieving_history",
252
+ },
253
+ {
254
+ target: "stream_recovery_failed",
255
+ },
256
+ ],
257
+ },
258
+ },
259
+ stream_recovery_failed: {
260
+ on: {
261
+ REFRESH_HISTORY: {
262
+ actions: assign({ lastError: undefined, streamRetryCount: 0 }),
263
+ target: "retrieving_history",
264
+ },
265
+ },
266
+ },
218
267
  streaming: {
219
268
  description: "Manages monitoring and canceling the current run",
220
269
  initial: "monitoring_replies",
@@ -228,20 +277,37 @@ export const createConversationMachine = (config) => setup({
228
277
  runId: context.currentRunId,
229
278
  };
230
279
  },
231
- onDone: {
232
- actions: assign({ currentRunId: null }),
233
- target: "idle",
234
- },
235
- onError: {
236
- actions: assign({ currentRunId: null }),
237
- target: "idle",
238
- },
280
+ onDone: [
281
+ {
282
+ actions: assign({ currentRunId: null, userRequestedStop: false }),
283
+ guard: ({ context }) => !!context.receivedEndOfStream || !!context.userRequestedStop,
284
+ target: "idle",
285
+ },
286
+ {
287
+ actions: assign({ currentRunId: null }),
288
+ target: "stream_interrupted",
289
+ },
290
+ ],
291
+ onError: [
292
+ {
293
+ actions: assign({ currentRunId: null, userRequestedStop: false }),
294
+ guard: ({ context }) => !!context.receivedEndOfStream || !!context.userRequestedStop,
295
+ target: "idle",
296
+ },
297
+ {
298
+ actions: assign({ currentRunId: null }),
299
+ target: "stream_interrupted",
300
+ },
301
+ ],
239
302
  onSnapshot: {
240
303
  actions: enqueueActions(({ context, enqueue, event }) => {
241
304
  const chatEvent = event.snapshot.context;
242
305
  if (!chatEvent) {
243
306
  return;
244
307
  }
308
+ if (chatEvent.content.chunkType === "endOfStream" && !context.receivedEndOfStream) {
309
+ enqueue.assign({ receivedEndOfStream: true });
310
+ }
245
311
  const nextSnapshot = AgentConversation.reduceChatEvents(context.conversationSnapshot, [chatEvent]);
246
312
  enqueue.assign({
247
313
  conversationSnapshot: nextSnapshot,
@@ -259,6 +325,7 @@ export const createConversationMachine = (config) => setup({
259
325
  description: "Attached to the run event stream",
260
326
  on: {
261
327
  STOP_RUN: {
328
+ actions: assign({ userRequestedStop: true }),
262
329
  target: "stopping",
263
330
  },
264
331
  },
@@ -271,10 +338,11 @@ export const createConversationMachine = (config) => setup({
271
338
  runId: context.currentRunId,
272
339
  }),
273
340
  onDone: {
274
- actions: assign({ currentRunId: undefined }),
341
+ actions: assign({ currentRunId: undefined, userRequestedStop: false }),
275
342
  target: "#agentConversation.idle",
276
343
  },
277
344
  onError: {
345
+ actions: assign({ userRequestedStop: false }),
278
346
  target: "#agentConversation.retrieving_history",
279
347
  },
280
348
  src: "stopRun",
@@ -317,6 +385,7 @@ export const createConversationMachine = (config) => setup({
317
385
  ],
318
386
  currentRunId: ({ event }) => event.output.currentRunId,
319
387
  messageAttempt: undefined,
388
+ ...STREAM_STATE_RESET,
320
389
  }),
321
390
  target: "streaming",
322
391
  },
@@ -1 +1 @@
1
- {"version":3,"file":"createConversationMachine.js","sourceRoot":"","sources":["../../../../src/enterprise/ai/conversations/createConversationMachine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE1F,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAG3D,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC9F,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,2BAA2B,EAAE,MAAM,0CAA0C,CAAC;AACvF,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;A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E,MAAM,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;oBACzC,MAAM,EAAE,oBAAoB;iBAC7B;gBACD,mBAAmB,EAAE;oBACnB,OAAO,EAAE,MAAM,CAAC;wBACd,SAAS,EAAE,SAAS;wBACpB,cAAc,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO;qBAC7C,CAAC;oBACF,MAAM,EAAE,oBAAoB;iBAC7B;aACF;SACF;QACD,aAAa,EAAE;YACb,MAAM,EAAE;gBACN,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc;gBAChD,MAAM,EAAE,oBAAoB;aAC7B;YACD,WAAW,EACT,gFAAgF;YAClF,EAAE,EAAE;gBACF,mBAAmB,EAAE;oBACnB,OAAO,EAAE,MAAM,CAAC;wBACd,cAAc,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO;qBAC7C,CAAC;oBACF,MAAM,EAAE,uBAAuB;iBAChC;aACF;SACF;KACF;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 { setup, fromObservable, fromPromise, assign, enqueueActions, emit } from \"xstate\";\nimport type { UserChatMessage } from \"../chat/UserChatMessage.ts\";\nimport { AgentConversation } from \"./AgentConversation.ts\";\nimport type { ConversationExchange } from \"./reduceChatEvents.ts\";\nimport type { SonarV4Config } from \"../../../common/Config.ts\";\nimport { createConversation, createConversationCodec } from \"./methods/createConversation.ts\";\nimport * as z from \"zod/mini\";\nimport { retrieveConversation } from \"./methods/retrieveConversation.ts\";\nimport { retrieveConversationHistory } from \"./methods/retrieveConversationHistory.ts\";\nimport { createExchangeRun } from \"./methods/createExchangeRun.ts\";\nimport { stopExchangeRun } from \"./methods/stopExchangeRun.ts\";\nimport { streamRunEvents } from \"./methods/streamRunEvents.ts\";\nimport { fromTextEventStream } from \"../../../common/fromTextEventStream.ts\";\nimport { map } from \"rxjs\";\nimport { chatEventCodec, type ChatEvent } from \"../chat/chatEventSchema.ts\";\nimport type { HttpError } from \"../../../common/HttpError.ts\";\n\nexport type ConversationMachineInput = {\n conversationId: string | null;\n};\n\nexport type ConversationMachineContext = {\n conversationId: string | null;\n conversationSnapshot?: ConversationExchange[];\n currentRunId?: string | null;\n lastError?: unknown;\n messageAttempt?: UserChatMessage;\n};\nexport type ConversationMachineEvents =\n | { type: \"STOP_RUN\" }\n | { type: \"SUBMIT_USER_MESSAGE\"; message: UserChatMessage }\n | { type: \"RETRY_MESSAGE\" }\n | { type: \"REFRESH_HISTORY\" };\n\nexport type ConversationMachineEmitted =\n | {\n type: \"apiError\";\n error: HttpError;\n }\n | {\n type: \"chatEventReceived\";\n chatEvent: ChatEvent;\n }\n | {\n type: \"conversationCreated\";\n id: string;\n };\n\nexport const createConversationMachine = (config: SonarV4Config) =>\n setup({\n actors: {\n createConversation: fromPromise(\n ({ input }: { input: z.input<typeof createConversationCodec> }) =>\n createConversation(config)(input).then((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n }),\n ),\n retrieveConversation: fromPromise(\n ({ input, signal }: { input: { conversationId: string }; signal: AbortSignal }) =>\n retrieveConversation(config)(input.conversationId, { signal }).then((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n }),\n ),\n retrieveHistory: fromPromise(\n ({ input, signal }: { input: { conversationId: string }; signal: AbortSignal }) =>\n retrieveConversationHistory(config)(input.conversationId, { signal }).then((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n }),\n ),\n retrieveState: fromPromise(\n async ({ input, signal }: { input: { conversationId: string }; signal: AbortSignal }) => {\n const [conversationResult, historyResult] = await Promise.all([\n retrieveConversation(config)(input.conversationId, { signal }),\n retrieveConversationHistory(config)(input.conversationId, { signal }),\n ]);\n\n if (conversationResult.isErr()) {\n throw conversationResult.error;\n }\n\n if (historyResult.isErr()) {\n throw historyResult.error;\n }\n\n return {\n conversation: conversationResult.value,\n history: historyResult.value,\n };\n },\n ),\n startRun: fromPromise(\n ({ input }: { input: { conversationId: string; message: UserChatMessage } }) =>\n createExchangeRun(config)(input.conversationId, { message: input.message }).then(\n (result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n },\n ),\n ),\n stopRun: fromPromise(({ input }: { input: { conversationId: string; runId: string } }) =>\n stopExchangeRun(config)(input.conversationId, input.runId).then((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n }),\n ),\n streamRun: fromObservable(({ input }: { input: { conversationId: string; runId: string } }) =>\n fromTextEventStream(({ signal }) =>\n streamRunEvents(config)(\n { conversationId: input.conversationId, runId: input.runId },\n { signal },\n ),\n ).pipe(\n map((event) =>\n z.decode(chatEventCodec, JSON.parse(event.data) as z.input<typeof chatEventCodec>),\n ),\n ),\n ),\n },\n types: {\n context: {} as ConversationMachineContext,\n emitted: {} as ConversationMachineEmitted,\n events: {} as ConversationMachineEvents,\n input: {} as ConversationMachineInput,\n },\n }).createMachine({\n context: ({ input }) => ({\n conversationId: input.conversationId,\n conversationSnapshot: undefined,\n currentRunId: undefined,\n messageAttempt: undefined,\n }),\n id: \"agentConversation\",\n initial: \"uninitialized\",\n states: {\n creating_conversation: {\n description: \"Creating a new conversation object\",\n invoke: {\n input: ({ context }) => ({\n message: context.messageAttempt!,\n }),\n onDone: [\n {\n actions: [\n assign({\n conversationId: ({ event }) => event.output.id,\n // Add the message attempt into the snapshot manually\n conversationSnapshot: ({ context, event }) => [\n ...(context.conversationSnapshot ?? []),\n {\n id: event.output.currentRunId!,\n messages: new Map(),\n submittedUserMessage: context.messageAttempt,\n toolCalls: new Map(),\n } satisfies ConversationExchange,\n ],\n currentRunId: ({ event }) => event.output.currentRunId,\n messageAttempt: undefined,\n }),\n emit(({ event }) => ({\n id: event.output.id,\n type: \"conversationCreated\",\n })),\n ],\n // Don't transition to streaming in a situation where we didn't receive a currentRunId\n guard: ({ event }) => !!event.output.currentRunId,\n target: \"streaming\",\n },\n /**\n * Fall back to the retrieving_history state if we didn't receive a currentRunId\n */\n {\n actions: assign({\n conversationId: ({ event }) => event.output.id,\n currentRunId: ({ event }) => event.output.currentRunId,\n messageAttempt: undefined,\n }),\n target: \"retrieving_history\",\n },\n ],\n onError: {\n actions: emit(({ event }) => ({\n error: event.error as HttpError,\n type: \"apiError\",\n })),\n target: \"uninitialized\",\n },\n src: \"createConversation\",\n },\n },\n idle: {\n description: \"Waiting for user input to start the next reply stream\",\n on: {\n REFRESH_HISTORY: {\n target: \"retrieving_history\",\n },\n SUBMIT_USER_MESSAGE: {\n actions: assign({\n messageAttempt: ({ event }) => event.message,\n }),\n target: \"submitting_message\",\n },\n },\n },\n retrieve_history_failed: {\n on: {\n REFRESH_HISTORY: {\n actions: assign({ lastError: undefined }),\n target: \"retrieving_history\",\n },\n },\n },\n retrieving_history: {\n description: \"Retrieving latest copy of conversation history\",\n invoke: {\n input: ({ context }) => ({ conversationId: context.conversationId! }),\n onDone: [\n {\n actions: assign({\n conversationSnapshot: ({ context, event }) =>\n AgentConversation.reduceChatEvents(\n context.conversationSnapshot,\n event.output.history.data,\n ),\n currentRunId: ({ event }) => event.output.conversation.currentRunId,\n }),\n guard: ({ event }) => !!event.output.conversation.currentRunId,\n target: \"streaming\",\n },\n {\n actions: assign({\n conversationSnapshot: ({ context, event }) =>\n AgentConversation.reduceChatEvents(\n context.conversationSnapshot,\n event.output.history.data,\n ),\n currentRunId: ({ event }) => event.output.conversation.currentRunId,\n }),\n target: \"idle\",\n },\n ],\n onError: [\n {\n guard: ({ event }) => {\n const e = event.error as Error & { code?: string };\n return (\n e?.name === \"AbortError\" ||\n e?.message?.includes(\"aborted\") ||\n e?.code === \"ABORT_ERR\"\n );\n },\n target: \"uninitialized\",\n },\n {\n actions: [\n assign({\n lastError: ({ event }) => event.error,\n }),\n emit(({ event }) => ({\n error: event.error as HttpError,\n type: \"apiError\",\n })),\n ],\n target: \"retrieve_history_failed\",\n },\n ],\n src: \"retrieveState\",\n },\n },\n streaming: {\n description: \"Manages monitoring and canceling the current run\",\n initial: \"monitoring_replies\",\n invoke: {\n input: ({ context }) => {\n if (!context.currentRunId) {\n throw new Error(\"Attempted to stream without a runId\");\n }\n return {\n conversationId: context.conversationId!,\n runId: context.currentRunId,\n };\n },\n onDone: {\n actions: assign({ currentRunId: null }),\n target: \"idle\",\n },\n onError: {\n actions: assign({ currentRunId: null }),\n target: \"idle\",\n },\n onSnapshot: {\n actions: enqueueActions(({ context, enqueue, event }) => {\n const chatEvent = event.snapshot.context;\n if (!chatEvent) {\n return;\n }\n\n const nextSnapshot = AgentConversation.reduceChatEvents(\n context.conversationSnapshot,\n [chatEvent],\n );\n\n enqueue.assign({\n conversationSnapshot: nextSnapshot,\n });\n enqueue.emit({\n chatEvent,\n type: \"chatEventReceived\",\n });\n }),\n },\n src: \"streamRun\",\n },\n states: {\n monitoring_replies: {\n description: \"Attached to the run event stream\",\n on: {\n STOP_RUN: {\n target: \"stopping\",\n },\n },\n },\n stopping: {\n description: \"Background cancelation of the run stream\",\n invoke: {\n input: ({ context }) => ({\n conversationId: context.conversationId!,\n runId: context.currentRunId!,\n }),\n onDone: {\n actions: assign({ currentRunId: undefined }),\n target: \"#agentConversation.idle\",\n },\n onError: {\n target: \"#agentConversation.retrieving_history\",\n },\n src: \"stopRun\",\n },\n },\n },\n },\n submitting_message: {\n description: \"Submitting message to start a new reply stream\",\n invoke: {\n input: ({ context, event }) => {\n switch (event.type) {\n case \"RETRY_MESSAGE\":\n if (!context.messageAttempt) {\n throw new Error(\"Tried to resubmit nonexistent message\");\n }\n return {\n conversationId: context.conversationId!,\n message: context.messageAttempt,\n };\n case \"SUBMIT_USER_MESSAGE\":\n return {\n conversationId: context.conversationId!,\n message: event.message,\n };\n }\n throw new Error(`Unexpected event type received in submitting_message: ${event.type}`);\n },\n onDone: {\n actions: assign({\n // Add the message attempt into the snapshot manually\n conversationSnapshot: ({ context, event }) => [\n ...(context.conversationSnapshot ?? []),\n {\n id: event.output.currentRunId,\n messages: new Map(),\n submittedUserMessage: context.messageAttempt || undefined,\n toolCalls: new Map(),\n } satisfies ConversationExchange,\n ],\n currentRunId: ({ event }) => event.output.currentRunId,\n messageAttempt: undefined,\n }),\n target: \"streaming\",\n },\n onError: {\n actions: [\n assign({\n currentRunId: () => null,\n lastError: ({ event }) => event.error,\n }),\n emit(({ event }) => ({\n error: event.error as HttpError,\n type: \"apiError\",\n })),\n ],\n target: \"submitting_message_failed\",\n },\n src: \"startRun\",\n },\n },\n submitting_message_failed: {\n description: \"Failed to submit message\",\n on: {\n REFRESH_HISTORY: {\n actions: assign({ lastError: undefined }),\n target: \"retrieving_history\",\n },\n RETRY_MESSAGE: {\n actions: assign({ lastError: undefined }),\n target: \"submitting_message\",\n },\n SUBMIT_USER_MESSAGE: {\n actions: assign({\n lastError: undefined,\n messageAttempt: ({ event }) => event.message,\n }),\n target: \"submitting_message\",\n },\n },\n },\n uninitialized: {\n always: {\n guard: ({ context }) => !!context.conversationId,\n target: \"retrieving_history\",\n },\n description:\n \"Entry state that the machine remains in when no conversation has been provided\",\n on: {\n SUBMIT_USER_MESSAGE: {\n actions: assign({\n messageAttempt: ({ event }) => event.message,\n }),\n target: \"creating_conversation\",\n },\n },\n },\n },\n });\n\nexport type AgentConversationMachine = ReturnType<typeof createConversationMachine>;\n"]}
1
+ {"version":3,"file":"createConversationMachine.js","sourceRoot":"","sources":["../../../../src/enterprise/ai/conversations/createConversationMachine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;A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,MAAM,EAAE,2BAA2B;iBACpC;gBACD,GAAG,EAAE,UAAU;aAChB;SACF;QACD,yBAAyB,EAAE;YACzB,WAAW,EAAE,0BAA0B;YACvC,EAAE,EAAE;gBACF,eAAe,EAAE;oBACf,OAAO,EAAE,MAAM,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;oBACzC,MAAM,EAAE,oBAAoB;iBAC7B;gBACD,aAAa,EAAE;oBACb,OAAO,EAAE,MAAM,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;oBACzC,MAAM,EAAE,oBAAoB;iBAC7B;gBACD,mBAAmB,EAAE;oBACnB,OAAO,EAAE,MAAM,CAAC;wBACd,SAAS,EAAE,SAAS;wBACpB,cAAc,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO;qBAC7C,CAAC;oBACF,MAAM,EAAE,oBAAoB;iBAC7B;aACF;SACF;QACD,aAAa,EAAE;YACb,MAAM,EAAE;gBACN,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc;gBAChD,MAAM,EAAE,oBAAoB;aAC7B;YACD,WAAW,EACT,gFAAgF;YAClF,EAAE,EAAE;gBACF,mBAAmB,EAAE;oBACnB,OAAO,EAAE,MAAM,CAAC;wBACd,cAAc,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO;qBAC7C,CAAC;oBACF,MAAM,EAAE,uBAAuB;iBAChC;aACF;SACF;KACF;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 { setup, fromObservable, fromPromise, assign, enqueueActions, emit } from \"xstate\";\nimport type { UserChatMessage } from \"../chat/UserChatMessage.ts\";\nimport { AgentConversation } from \"./AgentConversation.ts\";\nimport type { ConversationExchange } from \"./reduceChatEvents.ts\";\nimport type { SonarV4Config } from \"../../../common/Config.ts\";\nimport { createConversation, createConversationCodec } from \"./methods/createConversation.ts\";\nimport * as z from \"zod/mini\";\nimport { retrieveConversation } from \"./methods/retrieveConversation.ts\";\nimport { retrieveConversationHistory } from \"./methods/retrieveConversationHistory.ts\";\nimport { createExchangeRun } from \"./methods/createExchangeRun.ts\";\nimport { stopExchangeRun } from \"./methods/stopExchangeRun.ts\";\nimport { streamRunEvents } from \"./methods/streamRunEvents.ts\";\nimport { fromTextEventStream } from \"../../../common/fromTextEventStream.ts\";\nimport { map } from \"rxjs\";\nimport { chatEventCodec, type ChatEvent } from \"../chat/chatEventSchema.ts\";\nimport type { HttpError } from \"../../../common/HttpError.ts\";\n\nexport type ConversationMachineInput = {\n conversationId: string | null;\n};\n\nexport type ConversationMachineContext = {\n conversationId: string | null;\n conversationSnapshot?: ConversationExchange[];\n currentRunId?: string | null;\n lastError?: unknown;\n messageAttempt?: UserChatMessage;\n receivedEndOfStream: boolean;\n streamRetryCount: number;\n userRequestedStop: boolean;\n};\nexport type ConversationMachineEvents =\n | { type: \"STOP_RUN\" }\n | { type: \"SUBMIT_USER_MESSAGE\"; message: UserChatMessage }\n | { type: \"RETRY_MESSAGE\" }\n | { type: \"REFRESH_HISTORY\" };\n\nexport type ConversationMachineEmitted =\n | {\n type: \"apiError\";\n error: HttpError;\n }\n | {\n type: \"chatEventReceived\";\n chatEvent: ChatEvent;\n }\n | {\n type: \"conversationCreated\";\n id: string;\n };\n\nconst RETRIEVE_STATE_TIMEOUT_MS = 10_000;\nconst STREAM_RETRY_DELAY_MS = 2500;\nexport const MAX_STREAM_RETRIES = 5;\nconst STREAM_STATE_RESET = {\n receivedEndOfStream: false,\n streamRetryCount: 0,\n userRequestedStop: false,\n};\n\nexport const createConversationMachine = (config: SonarV4Config) =>\n setup({\n actors: {\n createConversation: fromPromise(\n ({ input }: { input: z.input<typeof createConversationCodec> }) =>\n createConversation(config)(input).then((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n }),\n ),\n retrieveConversation: fromPromise(\n ({ input, signal }: { input: { conversationId: string }; signal: AbortSignal }) =>\n retrieveConversation(config)(input.conversationId, { signal }).then((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n }),\n ),\n retrieveHistory: fromPromise(\n ({ input, signal }: { input: { conversationId: string }; signal: AbortSignal }) =>\n retrieveConversationHistory(config)(input.conversationId, { signal }).then((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n }),\n ),\n retrieveState: fromPromise(\n async ({ input, signal }: { input: { conversationId: string }; signal: AbortSignal }) => {\n const timeoutSignal = AbortSignal.any([\n signal,\n AbortSignal.timeout(RETRIEVE_STATE_TIMEOUT_MS),\n ]);\n const [conversationResult, historyResult] = await Promise.all([\n retrieveConversation(config)(input.conversationId, { signal: timeoutSignal }),\n retrieveConversationHistory(config)(input.conversationId, { signal: timeoutSignal }),\n ]);\n\n if (conversationResult.isErr()) {\n throw conversationResult.error;\n }\n\n if (historyResult.isErr()) {\n throw historyResult.error;\n }\n\n return {\n conversation: conversationResult.value,\n history: historyResult.value,\n };\n },\n ),\n startRun: fromPromise(\n ({ input }: { input: { conversationId: string; message: UserChatMessage } }) =>\n createExchangeRun(config)(input.conversationId, { message: input.message }).then(\n (result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n },\n ),\n ),\n stopRun: fromPromise(({ input }: { input: { conversationId: string; runId: string } }) =>\n stopExchangeRun(config)(input.conversationId, input.runId).then((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n }),\n ),\n streamRun: fromObservable(({ input }: { input: { conversationId: string; runId: string } }) =>\n fromTextEventStream(({ signal }) =>\n streamRunEvents(config)(\n { conversationId: input.conversationId, runId: input.runId },\n { signal },\n ),\n ).pipe(\n map((event) =>\n z.decode(chatEventCodec, JSON.parse(event.data) as z.input<typeof chatEventCodec>),\n ),\n ),\n ),\n },\n delays: {\n STREAM_RETRY_DELAY: STREAM_RETRY_DELAY_MS,\n },\n types: {\n context: {} as ConversationMachineContext,\n emitted: {} as ConversationMachineEmitted,\n events: {} as ConversationMachineEvents,\n input: {} as ConversationMachineInput,\n },\n }).createMachine({\n context: ({ input }) => ({\n conversationId: input.conversationId,\n conversationSnapshot: undefined,\n currentRunId: undefined,\n messageAttempt: undefined,\n ...STREAM_STATE_RESET,\n }),\n id: \"agentConversation\",\n initial: \"uninitialized\",\n states: {\n creating_conversation: {\n description: \"Creating a new conversation object\",\n invoke: {\n input: ({ context }) => ({\n message: context.messageAttempt!,\n }),\n onDone: [\n {\n actions: [\n assign({\n conversationId: ({ event }) => event.output.id,\n // Add the message attempt into the snapshot manually\n conversationSnapshot: ({ context, event }) => [\n ...(context.conversationSnapshot ?? []),\n {\n id: event.output.currentRunId!,\n messages: new Map(),\n submittedUserMessage: context.messageAttempt,\n toolCalls: new Map(),\n } satisfies ConversationExchange,\n ],\n currentRunId: ({ event }) => event.output.currentRunId,\n messageAttempt: undefined,\n ...STREAM_STATE_RESET,\n }),\n emit(({ event }) => ({\n id: event.output.id,\n type: \"conversationCreated\",\n })),\n ],\n // Don't transition to streaming in a situation where we didn't receive a currentRunId\n guard: ({ event }) => !!event.output.currentRunId,\n target: \"streaming\",\n },\n /**\n * Fall back to the retrieving_history state if we didn't receive a currentRunId\n */\n {\n actions: assign({\n conversationId: ({ event }) => event.output.id,\n currentRunId: ({ event }) => event.output.currentRunId,\n messageAttempt: undefined,\n }),\n target: \"retrieving_history\",\n },\n ],\n onError: {\n actions: emit(({ event }) => ({\n error: event.error as HttpError,\n type: \"apiError\",\n })),\n target: \"uninitialized\",\n },\n src: \"createConversation\",\n },\n },\n idle: {\n description: \"Waiting for user input to start the next reply stream\",\n on: {\n REFRESH_HISTORY: {\n target: \"retrieving_history\",\n },\n SUBMIT_USER_MESSAGE: {\n actions: assign({\n messageAttempt: ({ event }) => event.message,\n }),\n target: \"submitting_message\",\n },\n },\n },\n retrieve_history_failed: {\n on: {\n REFRESH_HISTORY: {\n actions: assign({ lastError: undefined }),\n target: \"retrieving_history\",\n },\n },\n },\n retrieving_history: {\n description: \"Retrieving latest copy of conversation history\",\n invoke: {\n input: ({ context }) => ({ conversationId: context.conversationId! }),\n onDone: [\n {\n actions: assign({\n conversationSnapshot: ({ context, event }) =>\n AgentConversation.reduceChatEvents(\n context.conversationSnapshot,\n event.output.history.data,\n ),\n currentRunId: ({ event }) => event.output.conversation.currentRunId,\n receivedEndOfStream: false,\n }),\n guard: ({ event }) => !!event.output.conversation.currentRunId,\n target: \"streaming\",\n },\n {\n actions: assign({\n conversationSnapshot: ({ context, event }) =>\n AgentConversation.reduceChatEvents(\n context.conversationSnapshot,\n event.output.history.data,\n ),\n currentRunId: ({ event }) => event.output.conversation.currentRunId,\n ...STREAM_STATE_RESET,\n }),\n target: \"idle\",\n },\n ],\n onError: [\n {\n guard: ({ event }) => {\n const e = event.error as Error & { code?: string };\n if (e?.name === \"TimeoutError\") return false;\n return (\n e?.name === \"AbortError\" ||\n e?.message?.includes(\"aborted\") ||\n e?.code === \"ABORT_ERR\"\n );\n },\n target: \"uninitialized\",\n },\n {\n guard: ({ context }) => context.streamRetryCount > 0,\n target: \"stream_interrupted\",\n },\n {\n actions: [\n assign({\n lastError: ({ event }) => event.error,\n }),\n emit(({ event }) => ({\n error: event.error as HttpError,\n type: \"apiError\",\n })),\n ],\n target: \"retrieve_history_failed\",\n },\n ],\n src: \"retrieveState\",\n },\n },\n stream_interrupted: {\n after: {\n STREAM_RETRY_DELAY: [\n {\n actions: assign({\n streamRetryCount: ({ context }) => context.streamRetryCount + 1,\n }),\n guard: ({ context }) => context.streamRetryCount < MAX_STREAM_RETRIES,\n target: \"retrieving_history\",\n },\n {\n target: \"stream_recovery_failed\",\n },\n ],\n },\n },\n stream_recovery_failed: {\n on: {\n REFRESH_HISTORY: {\n actions: assign({ lastError: undefined, streamRetryCount: 0 }),\n target: \"retrieving_history\",\n },\n },\n },\n streaming: {\n description: \"Manages monitoring and canceling the current run\",\n initial: \"monitoring_replies\",\n invoke: {\n input: ({ context }) => {\n if (!context.currentRunId) {\n throw new Error(\"Attempted to stream without a runId\");\n }\n return {\n conversationId: context.conversationId!,\n runId: context.currentRunId,\n };\n },\n onDone: [\n {\n actions: assign({ currentRunId: null, userRequestedStop: false }),\n guard: ({ context }) => !!context.receivedEndOfStream || !!context.userRequestedStop,\n target: \"idle\",\n },\n {\n actions: assign({ currentRunId: null }),\n target: \"stream_interrupted\",\n },\n ],\n onError: [\n {\n actions: assign({ currentRunId: null, userRequestedStop: false }),\n guard: ({ context }) => !!context.receivedEndOfStream || !!context.userRequestedStop,\n target: \"idle\",\n },\n {\n actions: assign({ currentRunId: null }),\n target: \"stream_interrupted\",\n },\n ],\n onSnapshot: {\n actions: enqueueActions(({ context, enqueue, event }) => {\n const chatEvent = event.snapshot.context;\n if (!chatEvent) {\n return;\n }\n\n if (chatEvent.content.chunkType === \"endOfStream\" && !context.receivedEndOfStream) {\n enqueue.assign({ receivedEndOfStream: true });\n }\n\n const nextSnapshot = AgentConversation.reduceChatEvents(\n context.conversationSnapshot,\n [chatEvent],\n );\n\n enqueue.assign({\n conversationSnapshot: nextSnapshot,\n });\n enqueue.emit({\n chatEvent,\n type: \"chatEventReceived\",\n });\n }),\n },\n src: \"streamRun\",\n },\n states: {\n monitoring_replies: {\n description: \"Attached to the run event stream\",\n on: {\n STOP_RUN: {\n actions: assign({ userRequestedStop: true }),\n target: \"stopping\",\n },\n },\n },\n stopping: {\n description: \"Background cancelation of the run stream\",\n invoke: {\n input: ({ context }) => ({\n conversationId: context.conversationId!,\n runId: context.currentRunId!,\n }),\n onDone: {\n actions: assign({ currentRunId: undefined, userRequestedStop: false }),\n target: \"#agentConversation.idle\",\n },\n onError: {\n actions: assign({ userRequestedStop: false }),\n target: \"#agentConversation.retrieving_history\",\n },\n src: \"stopRun\",\n },\n },\n },\n },\n submitting_message: {\n description: \"Submitting message to start a new reply stream\",\n invoke: {\n input: ({ context, event }) => {\n switch (event.type) {\n case \"RETRY_MESSAGE\":\n if (!context.messageAttempt) {\n throw new Error(\"Tried to resubmit nonexistent message\");\n }\n return {\n conversationId: context.conversationId!,\n message: context.messageAttempt,\n };\n case \"SUBMIT_USER_MESSAGE\":\n return {\n conversationId: context.conversationId!,\n message: event.message,\n };\n }\n throw new Error(`Unexpected event type received in submitting_message: ${event.type}`);\n },\n onDone: {\n actions: assign({\n // Add the message attempt into the snapshot manually\n conversationSnapshot: ({ context, event }) => [\n ...(context.conversationSnapshot ?? []),\n {\n id: event.output.currentRunId,\n messages: new Map(),\n submittedUserMessage: context.messageAttempt || undefined,\n toolCalls: new Map(),\n } satisfies ConversationExchange,\n ],\n currentRunId: ({ event }) => event.output.currentRunId,\n messageAttempt: undefined,\n ...STREAM_STATE_RESET,\n }),\n target: \"streaming\",\n },\n onError: {\n actions: [\n assign({\n currentRunId: () => null,\n lastError: ({ event }) => event.error,\n }),\n emit(({ event }) => ({\n error: event.error as HttpError,\n type: \"apiError\",\n })),\n ],\n target: \"submitting_message_failed\",\n },\n src: \"startRun\",\n },\n },\n submitting_message_failed: {\n description: \"Failed to submit message\",\n on: {\n REFRESH_HISTORY: {\n actions: assign({ lastError: undefined }),\n target: \"retrieving_history\",\n },\n RETRY_MESSAGE: {\n actions: assign({ lastError: undefined }),\n target: \"submitting_message\",\n },\n SUBMIT_USER_MESSAGE: {\n actions: assign({\n lastError: undefined,\n messageAttempt: ({ event }) => event.message,\n }),\n target: \"submitting_message\",\n },\n },\n },\n uninitialized: {\n always: {\n guard: ({ context }) => !!context.conversationId,\n target: \"retrieving_history\",\n },\n description:\n \"Entry state that the machine remains in when no conversation has been provided\",\n on: {\n SUBMIT_USER_MESSAGE: {\n actions: assign({\n messageAttempt: ({ event }) => event.message,\n }),\n target: \"creating_conversation\",\n },\n },\n },\n },\n });\n\nexport type AgentConversationMachine = ReturnType<typeof createConversationMachine>;\n"]}
@@ -20,7 +20,6 @@ export declare const createConversationCodec: z.ZodMiniCodec<z.ZodMiniObject<{
20
20
  modelProviderId: z.ZodMiniOptional<z.ZodMiniString<string>>;
21
21
  prompt: z.ZodMiniObject<{
22
22
  acceptTaskNames: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
23
- approvalResponseOnly: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
24
23
  approvals: z.ZodMiniOptional<z.ZodMiniObject<{
25
24
  allToolsAllowed: z.ZodMiniBoolean<boolean>;
26
25
  approvalNonce: z.ZodMiniString<string>;
@@ -46,7 +46,6 @@ export const createConversationCodec = z.codec(createConversationInSchema, z.ext
46
46
  modelProviderId: v.modelProviderId,
47
47
  prompt: {
48
48
  acceptTaskNames: v.message.prompt?.acceptTaskNames,
49
- approvalResponseOnly: v.message.prompt?.approvalResponseOnly,
50
49
  approvals: v.message.prompt?.approvals,
51
50
  context: v.message.prompt?.context,
52
51
  skillIds: v.message.prompt?.skillIds,
@@ -58,7 +57,6 @@ export const createConversationCodec = z.codec(createConversationInSchema, z.ext
58
57
  return {
59
58
  message: UserChatMessage.new(v.prompt.text, {
60
59
  acceptTaskNames: v.prompt?.acceptTaskNames,
61
- approvalResponseOnly: v.prompt?.approvalResponseOnly,
62
60
  approvals: v.prompt?.approvals,
63
61
  context: v.prompt?.context,
64
62
  skillIds: v.prompt?.skillIds,
@@ -1 +1 @@
1
- {"version":3,"file":"createConversation.js","sourceRoot":"","sources":["../../../../../src/enterprise/ai/conversations/methods/createConversation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B,OAAO,EAAE,2BAA2B,EAAE,MAAM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ACtB,eAAe,EAAE,CAAC,CAAC,eAAe;YAClC,MAAM,EAAE;gBACN,eAAe,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,eAAe;gBAClD,oBAAoB,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,oBAAoB;gBAC5D,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,SAAS;gBACtC,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO;gBAClC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ;gBACpC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO;aACxB;SACF,CAAC;IACJ,CAAC;IACD,MAAM,CAAC,CAAC;QACN,OAAO;YACL,OAAO,EAAE,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE;gBAC1C,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE,eAAe;gBAC1C,oBAAoB,EAAE,CAAC,CAAC,MAAM,EAAE,oBAAoB;gBACpD,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,SAAS;gBAC9B,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,OAAO;gBAC1B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,QAAQ;aAC7B,CAAC;YACF,SAAS,EAAE,CAAC,CAAC,SAAS;YACtB,eAAe,EAAE,CAAC,CAAC,eAAe;SACnC,CAAC;IACJ,CAAC;CACF,CACF,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as z from \"zod/mini\";\nimport type { SonarV4Config } from \"../../../../common/Config.ts\";\nimport { conversationPropertiesCodec } from \"../conversationPropertiesCodec.ts\";\nimport { createConversationPromptSchema, UserChatMessage } from \"../../chat/UserChatMessage.ts\";\n\nexport const createConversation = (config: SonarV4Config) =>\n function createConversation(body: z.input<typeof createConversationCodec>) {\n return config\n .sonarV4Request(`agent/conversations`, {\n body: JSON.stringify(z.decode(createConversationCodec, body)),\n headers: {\n Accept: \"application/json\",\n \"Content-Type\": \"application/json\",\n },\n keepalive: true,\n method: \"POST\",\n })\n .map((res) => res.json() as Promise<z.input<typeof conversationPropertiesCodec>>)\n .map((entity) => z.decode(conversationPropertiesCodec, entity));\n };\n\nconst createConversationInSchema = z.strictObject({\n message: z.instanceof(UserChatMessage),\n modelName: z.optional(z.string()),\n modelProviderId: z.optional(z.string()),\n});\n\nexport const createConversationCodec = z.codec(\n createConversationInSchema,\n z.extend(\n z.omit(createConversationInSchema, {\n message: true,\n }),\n {\n prompt: createConversationPromptSchema,\n },\n ),\n {\n decode(v) {\n return {\n modelName: v.modelName,\n modelProviderId: v.modelProviderId,\n prompt: {\n acceptTaskNames: v.message.prompt?.acceptTaskNames,\n approvalResponseOnly: v.message.prompt?.approvalResponseOnly,\n approvals: v.message.prompt?.approvals,\n context: v.message.prompt?.context,\n skillIds: v.message.prompt?.skillIds,\n text: v.message.content,\n },\n };\n },\n encode(v) {\n return {\n message: UserChatMessage.new(v.prompt.text, {\n acceptTaskNames: v.prompt?.acceptTaskNames,\n approvalResponseOnly: v.prompt?.approvalResponseOnly,\n approvals: v.prompt?.approvals,\n context: v.prompt?.context,\n skillIds: v.prompt?.skillIds,\n }),\n modelName: v.modelName,\n modelProviderId: v.modelProviderId,\n };\n },\n },\n);\n"]}
1
+ {"version":3,"file":"createConversation.js","sourceRoot":"","sources":["../../../../../src/enterprise/ai/conversations/methods/createConversation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAE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F,EACD;IACE,MAAM,CAAC,CAAC;QACN,OAAO;YACL,SAAS,EAAE,CAAC,CAAC,SAAS;YACtB,eAAe,EAAE,CAAC,CAAC,eAAe;YAClC,MAAM,EAAE;gBACN,eAAe,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,eAAe;gBAClD,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,SAAS;gBACtC,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO;gBAClC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ;gBACpC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO;aACxB;SACF,CAAC;IACJ,CAAC;IACD,MAAM,CAAC,CAAC;QACN,OAAO;YACL,OAAO,EAAE,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE;gBAC1C,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE,eAAe;gBAC1C,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,SAAS;gBAC9B,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,OAAO;gBAC1B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,QAAQ;aAC7B,CAAC;YACF,SAAS,EAAE,CAAC,CAAC,SAAS;YACtB,eAAe,EAAE,CAAC,CAAC,eAAe;SACnC,CAAC;IACJ,CAAC;CACF,CACF,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as z from \"zod/mini\";\nimport type { SonarV4Config } from \"../../../../common/Config.ts\";\nimport { conversationPropertiesCodec } from \"../conversationPropertiesCodec.ts\";\nimport { createConversationPromptSchema, UserChatMessage } from \"../../chat/UserChatMessage.ts\";\n\nexport const createConversation = (config: SonarV4Config) =>\n function createConversation(body: z.input<typeof createConversationCodec>) {\n return config\n .sonarV4Request(`agent/conversations`, {\n body: JSON.stringify(z.decode(createConversationCodec, body)),\n headers: {\n Accept: \"application/json\",\n \"Content-Type\": \"application/json\",\n },\n keepalive: true,\n method: \"POST\",\n })\n .map((res) => res.json() as Promise<z.input<typeof conversationPropertiesCodec>>)\n .map((entity) => z.decode(conversationPropertiesCodec, entity));\n };\n\nconst createConversationInSchema = z.strictObject({\n message: z.instanceof(UserChatMessage),\n modelName: z.optional(z.string()),\n modelProviderId: z.optional(z.string()),\n});\n\nexport const createConversationCodec = z.codec(\n createConversationInSchema,\n z.extend(\n z.omit(createConversationInSchema, {\n message: true,\n }),\n {\n prompt: createConversationPromptSchema,\n },\n ),\n {\n decode(v) {\n return {\n modelName: v.modelName,\n modelProviderId: v.modelProviderId,\n prompt: {\n acceptTaskNames: v.message.prompt?.acceptTaskNames,\n approvals: v.message.prompt?.approvals,\n context: v.message.prompt?.context,\n skillIds: v.message.prompt?.skillIds,\n text: v.message.content,\n },\n };\n },\n encode(v) {\n return {\n message: UserChatMessage.new(v.prompt.text, {\n acceptTaskNames: v.prompt?.acceptTaskNames,\n approvals: v.prompt?.approvals,\n context: v.prompt?.context,\n skillIds: v.prompt?.skillIds,\n }),\n modelName: v.modelName,\n modelProviderId: v.modelProviderId,\n };\n },\n },\n);\n"]}
@@ -32,12 +32,11 @@ export declare const retrieveConversationHistory: (config: SonarV4Config) => (id
32
32
  };
33
33
  role: "agent";
34
34
  } | {
35
+ createdAt: import("temporal-polyfill").Temporal.Instant;
35
36
  conversationId: string;
36
37
  modelName: string;
37
38
  modelProviderId: string;
38
39
  runId: string;
39
- createdAt: import("temporal-polyfill").Temporal.Instant;
40
- id: string;
41
40
  content: {
42
41
  chunkType: "endOfStream";
43
42
  };
@@ -94,6 +93,20 @@ export declare const retrieveConversationHistory: (config: SonarV4Config) => (id
94
93
  text: string;
95
94
  };
96
95
  role: "agent";
96
+ } | {
97
+ conversationId: string;
98
+ modelName: string;
99
+ modelProviderId: string;
100
+ runId: string;
101
+ createdAt: import("temporal-polyfill").Temporal.Instant;
102
+ id: string;
103
+ content: {
104
+ callId: string;
105
+ chunkType: "sandboxStdout";
106
+ isFinal: boolean;
107
+ text: string;
108
+ };
109
+ role: "agent";
97
110
  } | {
98
111
  conversationId: string;
99
112
  modelName: string;
@@ -6,7 +6,7 @@ export type AgentToolCall = {
6
6
  request: ChatEventWithChunkType<"toolRequest"> | undefined;
7
7
  result: ChatEventWithChunkType<"toolResponse"> | undefined;
8
8
  };
9
- export type ConversationExchangeMessage = ChatEventWithChunkType<"error"> | ChatEventWithChunkType<"model"> | ChatEventWithChunkType<"sandboxProgress"> | ChatEventWithChunkType<"userMessage">;
9
+ export type ConversationExchangeMessage = ChatEventWithChunkType<"error"> | ChatEventWithChunkType<"model"> | ChatEventWithChunkType<"sandboxProgress"> | ChatEventWithChunkType<"sandboxStdout"> | ChatEventWithChunkType<"userMessage">;
10
10
  export type ConversationExchange = {
11
11
  id: string;
12
12
  messages: Map<string, ConversationExchangeMessage>;
@@ -40,8 +40,11 @@ function applyChatEventToConversationExchange(conversationExchange, chatEvent) {
40
40
  case "error":
41
41
  case "model":
42
42
  case "sandboxProgress":
43
+ case "sandboxStdout":
43
44
  case "userMessage": {
44
- conversationExchange.messages.set(chatEvent.id, chatEvent);
45
+ // TypeScript doesn't narrow outer union via nested content.chunkType; cast is sound here
46
+ const event = chatEvent;
47
+ conversationExchange.messages.set(event.id, event);
45
48
  break;
46
49
  }
47
50
  case "toolRequest":
@@ -1 +1 @@
1
- {"version":3,"file":"reduceChatEvents.js","sourceRoot":"","sources":["../../../../src/enterprise/ai/conversations/reduceChatEvents.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;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 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<\"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 \"userMessage\": {\n conversationExchange.messages.set(\n chatEvent.id,\n chatEvent as Draft<ConversationExchangeMessage>,\n );\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;AA2B9C,SAAS,4BAA4B,CACnC,KAAmC,EACnC,SAAoB;IAEpB,IAAI,oBAAoB,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,KAAK,SAAS,CAAC,KAAK,CAAC,CAAC;IAEzF,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC1B,oBAAoB,GAAG;YACrB,EAAE,EAAE,SAAS,CAAC,KAAK;Y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V,OAAO,EAAE,SAAS;oBAClB,MAAM,EAAE,SAAS;oBACjB,KAAK,EAAE,SAAS;iBACjB,CAAC,CAAC;YACL,CAAC;YAED,MAAM,QAAQ,GAAG,oBAAoB,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAE,CAAC;YAE7D,QAAQ,SAAS,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;gBACpC,KAAK,aAAa;oBAChB,QAAQ,CAAC,OAAO,GAAG,SAAoE,CAAC;oBACxF,MAAM;gBACR,KAAK,cAAc;oBACjB,QAAQ,CAAC,MAAM,GAAG,SAAqE,CAAC;oBACxF,IAAI,cAAc,IAAI,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;wBACrD,QAAQ,CAAC,KAAK,GAAG,OAAO,CAAC;oBAC3B,CAAC;yBAAM,CAAC;wBACN,QAAQ,CAAC,KAAK,GAAG,SAAS,CAAC;oBAC7B,CAAC;oBACD,MAAM;YACV,CAAC;QACH,CAAC;IACH,CAAC;AACH,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 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"]}
@@ -3,9 +3,14 @@ import { DatasetCatalogObject, type DatasetEntity } from "../../../oss/catalog/C
3
3
  import type { RetrieveByPath } from "../../../oss/catalog/CatalogReferences/BaseCatalogReference.ts";
4
4
  import type { Grantee } from "../../Grantee.ts";
5
5
  import { EnterpriseDatasetCatalogReference } from "../CatalogReferences/EnterpriseDatasetCatalogReference.ts";
6
+ export type VizAttributes = {
7
+ name?: string;
8
+ spec?: string;
9
+ };
6
10
  export declare class EnterpriseDatasetCatalogObject extends DatasetCatalogObject {
7
11
  catalogReference: EnterpriseDatasetCatalogReference;
8
12
  readonly owner?: Grantee;
13
+ readonly vizAttributes?: VizAttributes;
9
14
  constructor(properties: EnterpriseDatasetCatalogObjectProperties);
10
15
  grants(): Promise<import("ts-results-es").Result<import("../CatalogReferences/retrieveCatalogGrants.ts").CatalogGrants<"DELETE" | "ALTER" | "INSERT" | "MANAGE GRANTS" | "OWNERSHIP" | "SELECT" | "TRUNCATE" | "UPDATE">, unknown>>;
11
16
  }
@@ -17,6 +22,7 @@ type EnterpriseDatasetEntity = DatasetEntity & {
17
22
  ownerId: string;
18
23
  ownerType: "ROLE" | "USER";
19
24
  };
25
+ vizAttributes?: VizAttributes;
20
26
  };
21
27
  export declare const enterpriseDatasetEntityToProperties: (entity: EnterpriseDatasetEntity, config: SonarV3Config, retrieveByPath: RetrieveByPath) => {
22
28
  catalogReference: EnterpriseDatasetCatalogReference;
@@ -24,6 +30,7 @@ export declare const enterpriseDatasetEntityToProperties: (entity: EnterpriseDat
24
30
  id: string;
25
31
  type: "ROLE" | "USER";
26
32
  } | undefined;
33
+ vizAttributes: VizAttributes | undefined;
27
34
  createdAt: Date;
28
35
  datasetVersion: string | undefined;
29
36
  fields: {
@@ -17,9 +17,11 @@ import { DatasetCatalogObject, datasetEntityToProperties, } from "../../../oss/c
17
17
  import { EnterpriseDatasetCatalogReference } from "../CatalogReferences/EnterpriseDatasetCatalogReference.js";
18
18
  export class EnterpriseDatasetCatalogObject extends DatasetCatalogObject {
19
19
  owner;
20
+ vizAttributes;
20
21
  constructor(properties) {
21
22
  super(properties);
22
23
  this.owner = properties.owner;
24
+ this.vizAttributes = properties.vizAttributes;
23
25
  }
24
26
  grants() {
25
27
  return this.catalogReference.grants();
@@ -40,6 +42,7 @@ export const enterpriseDatasetEntityToProperties = (entity, config, retrieveByPa
40
42
  type: entity.owner.ownerType,
41
43
  }
42
44
  : undefined,
45
+ vizAttributes: entity.vizAttributes,
43
46
  };
44
47
  };
45
48
  //# sourceMappingURL=EnterpriseDatasetCatalogObject.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"EnterpriseDatasetCatalogObject.js","sourceRoot":"","sources":["../../../../src/enterprise/catalog/CatalogObjects/EnterpriseDatasetCatalogObject.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EACL,oBAAoB,EACpB,yBAAyB,GAE1B,MAAM,6DAA6D,CAAC;AAIrE,OAAO,EAAE,iCAAiC,EAAE,MAAM,2DAA2D,CAAC;AAE9G,MAAM,OAAO,8BAA+B,SAAQ,oBAAoB;IAE7D,KAAK,CAAW;IAEzB,YAAY,UAAoD;QAC9D,KAAK,CAAC,UAAU,CAAC,CAAC;QAClB,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC;IAChC,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,CAAC;IACxC,CAAC;CACF;AAUD,MAAM,CAAC,MAAM,mCAAmC,GAAG,CACjD,MAA+B,EAC/B,MAAqB,EACrB,cAA8B,EAC9B,EAAE;IACF,MAAM,iBAAiB,GAAG,yBAAyB,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC;IACpF,OAAO;QACL,GAAG,iBAAiB;QACpB,gBAAgB,EAAE,IAAI,iCAAiC,CACrD;YACE,EAAE,EAAE,MAAM,CAAC,EAAE;YACb,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,IAAI,EAAE,iBAAiB,CAAC,IAAI;SAC7B,EACD,MAAM,EACN,cAAc,CACf;QACD,KAAK,EAAE,MAAM,CAAC,KAAK;YACjB,CAAC,CAAC;gBACE,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO;gBACxB,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,SAAS;aAC7B;YACH,CAAC,CAAC,SAAS;KACd,CAAC;AACJ,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 type { SonarV3Config } from \"../../../common/Config.ts\";\nimport {\n DatasetCatalogObject,\n datasetEntityToProperties,\n type DatasetEntity,\n} from \"../../../oss/catalog/CatalogObjects/DatasetCatalogObject.ts\";\nimport type { RetrieveByPath } from \"../../../oss/catalog/CatalogReferences/BaseCatalogReference.ts\";\nimport type { Grantee } from \"../../Grantee.ts\";\n\nimport { EnterpriseDatasetCatalogReference } from \"../CatalogReferences/EnterpriseDatasetCatalogReference.ts\";\n\nexport class EnterpriseDatasetCatalogObject extends DatasetCatalogObject {\n declare catalogReference: EnterpriseDatasetCatalogReference;\n readonly owner?: Grantee;\n\n constructor(properties: EnterpriseDatasetCatalogObjectProperties) {\n super(properties);\n this.owner = properties.owner;\n }\n\n grants() {\n return this.catalogReference.grants();\n }\n}\n\nexport type EnterpriseDatasetCatalogObjectProperties = ReturnType<\n typeof enterpriseDatasetEntityToProperties\n> & { owner?: Grantee };\n\ntype EnterpriseDatasetEntity = DatasetEntity & {\n owner?: { ownerId: string; ownerType: \"ROLE\" | \"USER\" };\n};\n\nexport const enterpriseDatasetEntityToProperties = (\n entity: EnterpriseDatasetEntity,\n config: SonarV3Config,\n retrieveByPath: RetrieveByPath,\n) => {\n const datasetProperties = datasetEntityToProperties(entity, config, retrieveByPath);\n return {\n ...datasetProperties,\n catalogReference: new EnterpriseDatasetCatalogReference(\n {\n id: entity.id,\n path: entity.path,\n type: datasetProperties.type,\n },\n config,\n retrieveByPath,\n ),\n owner: entity.owner\n ? {\n id: entity.owner.ownerId,\n type: entity.owner.ownerType,\n }\n : undefined,\n };\n};\n"]}
1
+ {"version":3,"file":"EnterpriseDatasetCatalogObject.js","sourceRoot":"","sources":["../../../../src/enterprise/catalog/CatalogObjects/EnterpriseDatasetCatalogObject.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EACL,oBAAoB,EACpB,yBAAyB,GAE1B,MAAM,6DAA6D,CAAC;AAIrE,OAAO,EAAE,iCAAiC,EAAE,MAAM,2DAA2D,CAAC;AAO9G,MAAM,OAAO,8BAA+B,SAAQ,oBAAoB;IAE7D,KAAK,CAAW;IAChB,aAAa,CAAiB;IAEvC,YAAY,UAAoD;QAC9D,KAAK,CAAC,UAAU,CAAC,CAAC;QAClB,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC;QAC9B,IAAI,CAAC,aAAa,GAAG,UAAU,CAAC,aAAa,CAAC;IAChD,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,CAAC;IACxC,CAAC;CACF;AAWD,MAAM,CAAC,MAAM,mCAAmC,GAAG,CACjD,MAA+B,EAC/B,MAAqB,EACrB,cAA8B,EAC9B,EAAE;IACF,MAAM,iBAAiB,GAAG,yBAAyB,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC;IACpF,OAAO;QACL,GAAG,iBAAiB;QACpB,gBAAgB,EAAE,IAAI,iCAAiC,CACrD;YACE,EAAE,EAAE,MAAM,CAAC,EAAE;YACb,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,IAAI,EAAE,iBAAiB,CAAC,IAAI;SAC7B,EACD,MAAM,EACN,cAAc,CACf;QACD,KAAK,EAAE,MAAM,CAAC,KAAK;YACjB,CAAC,CAAC;gBACE,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO;gBACxB,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,SAAS;aAC7B;YACH,CAAC,CAAC,SAAS;QACb,aAAa,EAAE,MAAM,CAAC,aAAa;KACpC,CAAC;AACJ,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 type { SonarV3Config } from \"../../../common/Config.ts\";\nimport {\n DatasetCatalogObject,\n datasetEntityToProperties,\n type DatasetEntity,\n} from \"../../../oss/catalog/CatalogObjects/DatasetCatalogObject.ts\";\nimport type { RetrieveByPath } from \"../../../oss/catalog/CatalogReferences/BaseCatalogReference.ts\";\nimport type { Grantee } from \"../../Grantee.ts\";\n\nimport { EnterpriseDatasetCatalogReference } from \"../CatalogReferences/EnterpriseDatasetCatalogReference.ts\";\n\nexport type VizAttributes = {\n name?: string;\n spec?: string;\n};\n\nexport class EnterpriseDatasetCatalogObject extends DatasetCatalogObject {\n declare catalogReference: EnterpriseDatasetCatalogReference;\n readonly owner?: Grantee;\n readonly vizAttributes?: VizAttributes;\n\n constructor(properties: EnterpriseDatasetCatalogObjectProperties) {\n super(properties);\n this.owner = properties.owner;\n this.vizAttributes = properties.vizAttributes;\n }\n\n grants() {\n return this.catalogReference.grants();\n }\n}\n\nexport type EnterpriseDatasetCatalogObjectProperties = ReturnType<\n typeof enterpriseDatasetEntityToProperties\n> & { owner?: Grantee };\n\ntype EnterpriseDatasetEntity = DatasetEntity & {\n owner?: { ownerId: string; ownerType: \"ROLE\" | \"USER\" };\n vizAttributes?: VizAttributes;\n};\n\nexport const enterpriseDatasetEntityToProperties = (\n entity: EnterpriseDatasetEntity,\n config: SonarV3Config,\n retrieveByPath: RetrieveByPath,\n) => {\n const datasetProperties = datasetEntityToProperties(entity, config, retrieveByPath);\n return {\n ...datasetProperties,\n catalogReference: new EnterpriseDatasetCatalogReference(\n {\n id: entity.id,\n path: entity.path,\n type: datasetProperties.type,\n },\n config,\n retrieveByPath,\n ),\n owner: entity.owner\n ? {\n id: entity.owner.ownerId,\n type: entity.owner.ownerType,\n }\n : undefined,\n vizAttributes: entity.vizAttributes,\n };\n};\n"]}