@dremio/js-sdk 0.59.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.
@@ -16056,6 +16056,14 @@ var DremioEnterprise = (() => {
16056
16056
  var endOfStreamChunkSchema = object({
16057
16057
  chunkType: literal("endOfStream")
16058
16058
  });
16059
+ var endOfStreamInputSchema = object({
16060
+ chunkType: literal("endOfStream"),
16061
+ conversationId: string2(),
16062
+ createdAt: string2().check(iso_exports.datetime()),
16063
+ modelName: string2(),
16064
+ modelProviderId: string2(),
16065
+ runId: string2()
16066
+ });
16059
16067
  var interruptChunkSchema = object({
16060
16068
  chunkType: literal("interrupt")
16061
16069
  });
@@ -16075,6 +16083,14 @@ var DremioEnterprise = (() => {
16075
16083
  stepName: string2(),
16076
16084
  text: string2()
16077
16085
  });
16086
+ var sandboxStdoutChunkSchema = object({
16087
+ callId: string2().check(_trim(), _minLength(1)),
16088
+ chunkType: literal("sandboxStdout"),
16089
+ isFinal: boolean2(),
16090
+ text: string2()
16091
+ });
16092
+ var sandboxStdoutContentSchema = sandboxStdoutChunkSchema;
16093
+ var sandboxStdoutChatEventSchema = extend2(sandboxStdoutChunkSchema, chatEventSharedSchema);
16078
16094
  var toolPlanSchema = record(string2(), unknown());
16079
16095
  var toolRequestChunkSchema = object({
16080
16096
  arguments: record(string2(), unknown()),
@@ -16112,12 +16128,13 @@ var DremioEnterprise = (() => {
16112
16128
  ]);
16113
16129
  var chatEventInputSchema = discriminatedUnion("chunkType", [
16114
16130
  extend2(errorChunkV2Schema, chatEventSharedSchema),
16115
- extend2(endOfStreamChunkSchema, chatEventSharedSchema),
16131
+ endOfStreamInputSchema,
16116
16132
  extend2(interruptChunkSchema, chatEventSharedSchema),
16117
16133
  extend2(conversationUpdateChunkSchema, chatEventSharedSchema),
16118
16134
  extend2(jobUpdateChunkSchema, chatEventSharedSchema),
16119
16135
  extend2(modelChunkSchema, chatEventSharedSchema),
16120
16136
  extend2(sandboxProgressChunkSchema, chatEventSharedSchema),
16137
+ sandboxStdoutChatEventSchema,
16121
16138
  extend2(toolRequestChunkSchema, chatEventSharedSchema),
16122
16139
  extend2(toolResponseChunkSchema, chatEventSharedSchema),
16123
16140
  extend2(userMessageChunkSchema, chatEventSharedSchema)
@@ -16126,13 +16143,14 @@ var DremioEnterprise = (() => {
16126
16143
  createdAt: _instanceof(Xn.Instant),
16127
16144
  id: string2()
16128
16145
  });
16146
+ var endOfStreamOutputSchema = omit2(chatEventOutputSharedSchema, { id: true });
16129
16147
  var chatEventOutputSchema = union([
16130
16148
  extend2(chatEventOutputSharedSchema, {
16131
16149
  content: conversationUpdateChunkSchema,
16132
16150
  role: literal("agent")
16133
16151
  }),
16134
16152
  extend2(chatEventOutputSharedSchema, { content: errorChunkV2Schema, role: literal("agent") }),
16135
- extend2(chatEventOutputSharedSchema, {
16153
+ extend2(endOfStreamOutputSchema, {
16136
16154
  content: endOfStreamChunkSchema,
16137
16155
  role: literal("agent")
16138
16156
  }),
@@ -16149,6 +16167,10 @@ var DremioEnterprise = (() => {
16149
16167
  content: sandboxProgressChunkSchema,
16150
16168
  role: literal("agent")
16151
16169
  }),
16170
+ extend2(chatEventOutputSharedSchema, {
16171
+ content: sandboxStdoutContentSchema,
16172
+ role: literal("agent")
16173
+ }),
16152
16174
  extend2(chatEventOutputSharedSchema, {
16153
16175
  content: toolRequestChunkSchema,
16154
16176
  role: literal("agent")
@@ -16164,6 +16186,17 @@ var DremioEnterprise = (() => {
16164
16186
  ]);
16165
16187
  var chatEventCodec = codec(chatEventInputSchema, chatEventOutputSchema, {
16166
16188
  decode(v2) {
16189
+ if (v2.chunkType === "endOfStream") {
16190
+ return {
16191
+ content: { chunkType: "endOfStream" },
16192
+ conversationId: v2.conversationId,
16193
+ createdAt: Xn.Instant.from(v2.createdAt),
16194
+ modelName: v2.modelName,
16195
+ modelProviderId: v2.modelProviderId,
16196
+ role: "agent",
16197
+ runId: v2.runId
16198
+ };
16199
+ }
16167
16200
  const sharedProperties = {
16168
16201
  conversationId: v2.conversationId,
16169
16202
  createdAt: Xn.Instant.from(v2.createdAt),
@@ -16193,14 +16226,6 @@ var DremioEnterprise = (() => {
16193
16226
  },
16194
16227
  role: "agent"
16195
16228
  };
16196
- case "endOfStream":
16197
- return {
16198
- ...sharedProperties,
16199
- content: {
16200
- chunkType: "endOfStream"
16201
- },
16202
- role: "agent"
16203
- };
16204
16229
  case "interrupt":
16205
16230
  return {
16206
16231
  ...sharedProperties,
@@ -16241,6 +16266,17 @@ var DremioEnterprise = (() => {
16241
16266
  },
16242
16267
  role: "agent"
16243
16268
  };
16269
+ case "sandboxStdout":
16270
+ return {
16271
+ ...sharedProperties,
16272
+ content: {
16273
+ callId: v2.callId,
16274
+ chunkType: "sandboxStdout",
16275
+ isFinal: v2.isFinal,
16276
+ text: v2.text
16277
+ },
16278
+ role: "agent"
16279
+ };
16244
16280
  case "toolRequest":
16245
16281
  return {
16246
16282
  ...sharedProperties,
@@ -16277,10 +16313,21 @@ var DremioEnterprise = (() => {
16277
16313
  }
16278
16314
  },
16279
16315
  encode(v2) {
16316
+ if (v2.content.chunkType === "endOfStream") {
16317
+ return {
16318
+ chunkType: "endOfStream",
16319
+ conversationId: v2.conversationId,
16320
+ createdAt: v2.createdAt.toString(),
16321
+ modelName: v2.modelName,
16322
+ modelProviderId: v2.modelProviderId,
16323
+ runId: v2.runId
16324
+ };
16325
+ }
16326
+ const id = v2.id;
16280
16327
  return {
16281
16328
  conversationId: v2.conversationId,
16282
16329
  createdAt: v2.createdAt.toString(),
16283
- messageId: v2.id,
16330
+ messageId: id,
16284
16331
  modelName: v2.modelName,
16285
16332
  modelProviderId: v2.modelProviderId,
16286
16333
  runId: v2.runId,
@@ -17952,8 +17999,10 @@ var DremioEnterprise = (() => {
17952
17999
  case "error":
17953
18000
  case "model":
17954
18001
  case "sandboxProgress":
18002
+ case "sandboxStdout":
17955
18003
  case "userMessage": {
17956
- conversationExchange.messages.set(chatEvent.id, chatEvent);
18004
+ const event = chatEvent;
18005
+ conversationExchange.messages.set(event.id, event);
17957
18006
  break;
17958
18007
  }
17959
18008
  case "toolRequest":
@@ -21452,6 +21501,14 @@ ${err.message}`);
21452
21501
  }
21453
21502
 
21454
21503
  // dist/enterprise/ai/conversations/createConversationMachine.js
21504
+ var RETRIEVE_STATE_TIMEOUT_MS = 1e4;
21505
+ var STREAM_RETRY_DELAY_MS = 2500;
21506
+ var MAX_STREAM_RETRIES = 5;
21507
+ var STREAM_STATE_RESET = {
21508
+ receivedEndOfStream: false,
21509
+ streamRetryCount: 0,
21510
+ userRequestedStop: false
21511
+ };
21455
21512
  var createConversationMachine = (config3) => setup({
21456
21513
  actors: {
21457
21514
  createConversation: fromPromise2(({ input }) => createConversation(config3)(input).then((result) => {
@@ -21473,9 +21530,13 @@ ${err.message}`);
21473
21530
  return result.value;
21474
21531
  })),
21475
21532
  retrieveState: fromPromise2(async ({ input, signal }) => {
21533
+ const timeoutSignal = AbortSignal.any([
21534
+ signal,
21535
+ AbortSignal.timeout(RETRIEVE_STATE_TIMEOUT_MS)
21536
+ ]);
21476
21537
  const [conversationResult, historyResult] = await Promise.all([
21477
- retrieveConversation(config3)(input.conversationId, { signal }),
21478
- retrieveConversationHistory(config3)(input.conversationId, { signal })
21538
+ retrieveConversation(config3)(input.conversationId, { signal: timeoutSignal }),
21539
+ retrieveConversationHistory(config3)(input.conversationId, { signal: timeoutSignal })
21479
21540
  ]);
21480
21541
  if (conversationResult.isErr()) {
21481
21542
  throw conversationResult.error;
@@ -21502,6 +21563,9 @@ ${err.message}`);
21502
21563
  })),
21503
21564
  streamRun: fromObservable(({ input }) => fromTextEventStream(({ signal }) => streamRunEvents(config3)({ conversationId: input.conversationId, runId: input.runId }, { signal })).pipe(map((event) => decode(chatEventCodec, JSON.parse(event.data)))))
21504
21565
  },
21566
+ delays: {
21567
+ STREAM_RETRY_DELAY: STREAM_RETRY_DELAY_MS
21568
+ },
21505
21569
  types: {
21506
21570
  context: {},
21507
21571
  emitted: {},
@@ -21513,7 +21577,8 @@ ${err.message}`);
21513
21577
  conversationId: input.conversationId,
21514
21578
  conversationSnapshot: void 0,
21515
21579
  currentRunId: void 0,
21516
- messageAttempt: void 0
21580
+ messageAttempt: void 0,
21581
+ ...STREAM_STATE_RESET
21517
21582
  }),
21518
21583
  id: "agentConversation",
21519
21584
  initial: "uninitialized",
@@ -21540,7 +21605,8 @@ ${err.message}`);
21540
21605
  }
21541
21606
  ],
21542
21607
  currentRunId: ({ event }) => event.output.currentRunId,
21543
- messageAttempt: void 0
21608
+ messageAttempt: void 0,
21609
+ ...STREAM_STATE_RESET
21544
21610
  }),
21545
21611
  emit(({ event }) => ({
21546
21612
  id: event.output.id,
@@ -21603,7 +21669,8 @@ ${err.message}`);
21603
21669
  {
21604
21670
  actions: assign({
21605
21671
  conversationSnapshot: ({ context: context2, event }) => AgentConversation.reduceChatEvents(context2.conversationSnapshot, event.output.history.data),
21606
- currentRunId: ({ event }) => event.output.conversation.currentRunId
21672
+ currentRunId: ({ event }) => event.output.conversation.currentRunId,
21673
+ receivedEndOfStream: false
21607
21674
  }),
21608
21675
  guard: ({ event }) => !!event.output.conversation.currentRunId,
21609
21676
  target: "streaming"
@@ -21611,7 +21678,8 @@ ${err.message}`);
21611
21678
  {
21612
21679
  actions: assign({
21613
21680
  conversationSnapshot: ({ context: context2, event }) => AgentConversation.reduceChatEvents(context2.conversationSnapshot, event.output.history.data),
21614
- currentRunId: ({ event }) => event.output.conversation.currentRunId
21681
+ currentRunId: ({ event }) => event.output.conversation.currentRunId,
21682
+ ...STREAM_STATE_RESET
21615
21683
  }),
21616
21684
  target: "idle"
21617
21685
  }
@@ -21620,10 +21688,16 @@ ${err.message}`);
21620
21688
  {
21621
21689
  guard: ({ event }) => {
21622
21690
  const e2 = event.error;
21691
+ if (e2?.name === "TimeoutError")
21692
+ return false;
21623
21693
  return e2?.name === "AbortError" || e2?.message?.includes("aborted") || e2?.code === "ABORT_ERR";
21624
21694
  },
21625
21695
  target: "uninitialized"
21626
21696
  },
21697
+ {
21698
+ guard: ({ context: context2 }) => context2.streamRetryCount > 0,
21699
+ target: "stream_interrupted"
21700
+ },
21627
21701
  {
21628
21702
  actions: [
21629
21703
  assign({
@@ -21640,6 +21714,30 @@ ${err.message}`);
21640
21714
  src: "retrieveState"
21641
21715
  }
21642
21716
  },
21717
+ stream_interrupted: {
21718
+ after: {
21719
+ STREAM_RETRY_DELAY: [
21720
+ {
21721
+ actions: assign({
21722
+ streamRetryCount: ({ context: context2 }) => context2.streamRetryCount + 1
21723
+ }),
21724
+ guard: ({ context: context2 }) => context2.streamRetryCount < MAX_STREAM_RETRIES,
21725
+ target: "retrieving_history"
21726
+ },
21727
+ {
21728
+ target: "stream_recovery_failed"
21729
+ }
21730
+ ]
21731
+ }
21732
+ },
21733
+ stream_recovery_failed: {
21734
+ on: {
21735
+ REFRESH_HISTORY: {
21736
+ actions: assign({ lastError: void 0, streamRetryCount: 0 }),
21737
+ target: "retrieving_history"
21738
+ }
21739
+ }
21740
+ },
21643
21741
  streaming: {
21644
21742
  description: "Manages monitoring and canceling the current run",
21645
21743
  initial: "monitoring_replies",
@@ -21653,20 +21751,37 @@ ${err.message}`);
21653
21751
  runId: context2.currentRunId
21654
21752
  };
21655
21753
  },
21656
- onDone: {
21657
- actions: assign({ currentRunId: null }),
21658
- target: "idle"
21659
- },
21660
- onError: {
21661
- actions: assign({ currentRunId: null }),
21662
- target: "idle"
21663
- },
21754
+ onDone: [
21755
+ {
21756
+ actions: assign({ currentRunId: null, userRequestedStop: false }),
21757
+ guard: ({ context: context2 }) => !!context2.receivedEndOfStream || !!context2.userRequestedStop,
21758
+ target: "idle"
21759
+ },
21760
+ {
21761
+ actions: assign({ currentRunId: null }),
21762
+ target: "stream_interrupted"
21763
+ }
21764
+ ],
21765
+ onError: [
21766
+ {
21767
+ actions: assign({ currentRunId: null, userRequestedStop: false }),
21768
+ guard: ({ context: context2 }) => !!context2.receivedEndOfStream || !!context2.userRequestedStop,
21769
+ target: "idle"
21770
+ },
21771
+ {
21772
+ actions: assign({ currentRunId: null }),
21773
+ target: "stream_interrupted"
21774
+ }
21775
+ ],
21664
21776
  onSnapshot: {
21665
21777
  actions: enqueueActions(({ context: context2, enqueue, event }) => {
21666
21778
  const chatEvent = event.snapshot.context;
21667
21779
  if (!chatEvent) {
21668
21780
  return;
21669
21781
  }
21782
+ if (chatEvent.content.chunkType === "endOfStream" && !context2.receivedEndOfStream) {
21783
+ enqueue.assign({ receivedEndOfStream: true });
21784
+ }
21670
21785
  const nextSnapshot = AgentConversation.reduceChatEvents(context2.conversationSnapshot, [chatEvent]);
21671
21786
  enqueue.assign({
21672
21787
  conversationSnapshot: nextSnapshot
@@ -21684,6 +21799,7 @@ ${err.message}`);
21684
21799
  description: "Attached to the run event stream",
21685
21800
  on: {
21686
21801
  STOP_RUN: {
21802
+ actions: assign({ userRequestedStop: true }),
21687
21803
  target: "stopping"
21688
21804
  }
21689
21805
  }
@@ -21696,10 +21812,11 @@ ${err.message}`);
21696
21812
  runId: context2.currentRunId
21697
21813
  }),
21698
21814
  onDone: {
21699
- actions: assign({ currentRunId: void 0 }),
21815
+ actions: assign({ currentRunId: void 0, userRequestedStop: false }),
21700
21816
  target: "#agentConversation.idle"
21701
21817
  },
21702
21818
  onError: {
21819
+ actions: assign({ userRequestedStop: false }),
21703
21820
  target: "#agentConversation.retrieving_history"
21704
21821
  },
21705
21822
  src: "stopRun"
@@ -21741,7 +21858,8 @@ ${err.message}`);
21741
21858
  }
21742
21859
  ],
21743
21860
  currentRunId: ({ event }) => event.output.currentRunId,
21744
- messageAttempt: void 0
21861
+ messageAttempt: void 0,
21862
+ ...STREAM_STATE_RESET
21745
21863
  }),
21746
21864
  target: "streaming"
21747
21865
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dremio/js-sdk",
3
- "version": "0.59.0",
3
+ "version": "0.60.0",
4
4
  "description": "JavaScript library for the Dremio API",
5
5
  "keywords": [
6
6
  "dremio",