@iota-uz/sdk 0.4.28 → 0.4.29

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.
@@ -1957,6 +1957,12 @@ function normalizeQuestionType(rawType) {
1957
1957
  const normalized = String(rawType || "").trim().toUpperCase().replace(/[\s-]+/g, "_");
1958
1958
  return normalized === "MULTIPLE_CHOICE" ? "MULTIPLE_CHOICE" : "SINGLE_CHOICE";
1959
1959
  }
1960
+ function isOpenQuestionStatus(status) {
1961
+ return status === "PENDING" || status === "ANSWER_SUBMITTED" || status === "REJECT_SUBMITTED" || status === "ANSWER_RESUME_FAILED" || status === "REJECT_RESUME_FAILED";
1962
+ }
1963
+ function shouldPromptForHumanInput(status) {
1964
+ return status === "PENDING" || status === "ANSWER_RESUME_FAILED" || status === "REJECT_RESUME_FAILED";
1965
+ }
1960
1966
  function pendingQuestionFromInterrupt(interrupt, fallbackTurnId) {
1961
1967
  if (!interrupt) {
1962
1968
  return null;
@@ -1984,7 +1990,7 @@ function pendingQuestionFromInterrupt(interrupt, fallbackTurnId) {
1984
1990
  };
1985
1991
  }
1986
1992
  function resolvePendingQuestionTurnIndex(turns, pendingQuestion) {
1987
- if (!pendingQuestion || pendingQuestion.status !== "PENDING" || turns.length === 0) {
1993
+ if (!pendingQuestion || !isOpenQuestionStatus(pendingQuestion.status) || turns.length === 0) {
1988
1994
  return -1;
1989
1995
  }
1990
1996
  const pendingTurnId = pendingQuestion.turnId?.trim();
@@ -2011,7 +2017,7 @@ function applyTurnLifecycleForPendingQuestion(turns, pendingQuestion) {
2011
2017
  let changed = false;
2012
2018
  const nextTurns = turns.map((turn, index) => {
2013
2019
  const shouldWaitForInput = pendingIndex === index;
2014
- const desiredLifecycle = shouldWaitForInput ? "waiting_for_human_input" : "complete";
2020
+ const desiredLifecycle = shouldWaitForInput ? shouldPromptForHumanInput(pendingQuestion?.status) ? "waiting_for_human_input" : "complete" : "complete";
2015
2021
  if (!turn.assistantTurn) {
2016
2022
  if (!shouldWaitForInput || !pendingQuestion) {
2017
2023
  return turn;
@@ -2187,7 +2193,9 @@ var ChatMachine = class {
2187
2193
  this.onSessionCreated = config.onSessionCreated;
2188
2194
  this.reasoningEffortOptions = this.buildReasoningEffortOptions();
2189
2195
  this.reasoningEffortOptionSet = this.reasoningEffortOptions ? new Set(this.reasoningEffortOptions) : null;
2190
- const initialReasoningEffort = this.sanitizeReasoningEffort(loadReasoningEffort() || void 0);
2196
+ const initialReasoningEffort = this.sanitizeReasoningEffort(
2197
+ loadReasoningEffort() || void 0
2198
+ );
2191
2199
  if (!initialReasoningEffort) {
2192
2200
  clearReasoningEffort();
2193
2201
  }
@@ -2455,7 +2463,9 @@ var ChatMachine = class {
2455
2463
  */
2456
2464
  _setTurnsFromFetch(fetchedTurns, pendingQuestion) {
2457
2465
  if (!Array.isArray(fetchedTurns)) {
2458
- console.warn("[ChatMachine] Ignoring malformed turns payload from fetchSession");
2466
+ console.warn(
2467
+ "[ChatMachine] Ignoring malformed turns payload from fetchSession"
2468
+ );
2459
2469
  return;
2460
2470
  }
2461
2471
  const prev = this.state.messaging.turns;
@@ -2466,7 +2476,10 @@ var ChatMachine = class {
2466
2476
  patch.pendingQuestion = pendingQuestion;
2467
2477
  }
2468
2478
  if (hasPendingUserOnly && (!fetchedTurns || fetchedTurns.length === 0)) {
2469
- const lifecycleTurns = applyTurnLifecycleForPendingQuestion(prev, effectivePendingQuestion);
2479
+ const lifecycleTurns = applyTurnLifecycleForPendingQuestion(
2480
+ prev,
2481
+ effectivePendingQuestion
2482
+ );
2470
2483
  if (lifecycleTurns !== prev) {
2471
2484
  patch.turns = lifecycleTurns;
2472
2485
  }
@@ -2475,7 +2488,10 @@ var ChatMachine = class {
2475
2488
  }
2476
2489
  return;
2477
2490
  }
2478
- patch.turns = applyTurnLifecycleForPendingQuestion(fetchedTurns ?? prev, effectivePendingQuestion);
2491
+ patch.turns = applyTurnLifecycleForPendingQuestion(
2492
+ fetchedTurns ?? prev,
2493
+ effectivePendingQuestion
2494
+ );
2479
2495
  this._updateMessaging(patch);
2480
2496
  }
2481
2497
  /**
@@ -2532,10 +2548,16 @@ var ChatMachine = class {
2532
2548
  this._updateMessaging({ generationInProgress: false });
2533
2549
  this.dataSource.fetchSession(sessionId).then((result) => {
2534
2550
  if (this.state.session.currentSessionId === sessionId && result) {
2535
- this._setTurnsFromFetch(result.turns, result.pendingQuestion ?? null);
2551
+ this._setTurnsFromFetch(
2552
+ result.turns,
2553
+ result.pendingQuestion ?? null
2554
+ );
2536
2555
  }
2537
2556
  }).catch((err) => {
2538
- console.error("[ChatMachine] fetchSession after stream inactive:", err);
2557
+ console.error(
2558
+ "[ChatMachine] fetchSession after stream inactive:",
2559
+ err
2560
+ );
2539
2561
  });
2540
2562
  }
2541
2563
  }).catch((err) => {
@@ -2596,7 +2618,10 @@ var ChatMachine = class {
2596
2618
  if (this.disposed) {
2597
2619
  return;
2598
2620
  }
2599
- console.warn("[ChatMachine] resumeStream failed, switching to status polling fallback:", err);
2621
+ console.warn(
2622
+ "[ChatMachine] resumeStream failed, switching to status polling fallback:",
2623
+ err
2624
+ );
2600
2625
  const getStreamStatus2 = this.dataSource.getStreamStatus;
2601
2626
  const status = getStreamStatus2 ? await getStreamStatus2(sessionId).catch(() => null) : null;
2602
2627
  if (!status?.active) {
@@ -2637,9 +2662,11 @@ var ChatMachine = class {
2637
2662
  if (typeof window === "undefined") {
2638
2663
  return;
2639
2664
  }
2640
- window.dispatchEvent(new CustomEvent("bichat:sessions-updated", {
2641
- detail: { reason, sessionId }
2642
- }));
2665
+ window.dispatchEvent(
2666
+ new CustomEvent("bichat:sessions-updated", {
2667
+ detail: { reason, sessionId }
2668
+ })
2669
+ );
2643
2670
  }
2644
2671
  _cancel() {
2645
2672
  if (this.abortController) {
@@ -2687,10 +2714,15 @@ var ChatMachine = class {
2687
2714
  this._setDebugModeForSession(key3, nextDebugMode);
2688
2715
  if (nextDebugMode && this.state.session.currentSessionId && this.state.session.currentSessionId !== "new") {
2689
2716
  try {
2690
- const result = await this.dataSource.fetchSession(this.state.session.currentSessionId);
2717
+ const result = await this.dataSource.fetchSession(
2718
+ this.state.session.currentSessionId
2719
+ );
2691
2720
  if (result) {
2692
2721
  this._updateSession({ session: result.session });
2693
- this._setTurnsFromFetch(result.turns, result.pendingQuestion || null);
2722
+ this._setTurnsFromFetch(
2723
+ result.turns,
2724
+ result.pendingQuestion || null
2725
+ );
2694
2726
  }
2695
2727
  } catch (err) {
2696
2728
  console.error("Failed to refresh session for debug mode:", err);
@@ -2718,7 +2750,10 @@ var ChatMachine = class {
2718
2750
  }
2719
2751
  this._updateMessaging({ codeOutputs: [] });
2720
2752
  } catch (err) {
2721
- const normalized = normalizeRPCError(err, "Failed to clear session history");
2753
+ const normalized = normalizeRPCError(
2754
+ err,
2755
+ "Failed to clear session history"
2756
+ );
2722
2757
  this._updateInput({ inputError: normalized.userMessage });
2723
2758
  } finally {
2724
2759
  this._updateMessaging({ loading: false, isStreaming: false });
@@ -2739,7 +2774,12 @@ var ChatMachine = class {
2739
2774
  }
2740
2775
  this._updateMessaging({
2741
2776
  turns: applyTurnLifecycleForPendingQuestion(
2742
- [createCompactedSystemTurn(curSessionId, "Compacting conversation history...")],
2777
+ [
2778
+ createCompactedSystemTurn(
2779
+ curSessionId,
2780
+ "Compacting conversation history..."
2781
+ )
2782
+ ],
2743
2783
  null
2744
2784
  ),
2745
2785
  pendingQuestion: null
@@ -2749,17 +2789,27 @@ var ChatMachine = class {
2749
2789
  const result = await this.dataSource.fetchSession(curSessionId);
2750
2790
  if (result) {
2751
2791
  this._updateSession({ session: result.session });
2752
- this._setTurnsFromFetch(result.turns, result.pendingQuestion || null);
2792
+ this._setTurnsFromFetch(
2793
+ result.turns,
2794
+ result.pendingQuestion || null
2795
+ );
2753
2796
  } else {
2754
2797
  this._setTurnsFromFetch([], null);
2755
2798
  }
2756
2799
  this._updateMessaging({ codeOutputs: [] });
2757
2800
  }
2758
2801
  } catch (err) {
2759
- const normalized = normalizeRPCError(err, "Failed to compact session history");
2802
+ const normalized = normalizeRPCError(
2803
+ err,
2804
+ "Failed to compact session history"
2805
+ );
2760
2806
  this._updateInput({ inputError: normalized.userMessage });
2761
2807
  } finally {
2762
- this._updateMessaging({ isCompacting: false, loading: false, isStreaming: false });
2808
+ this._updateMessaging({
2809
+ isCompacting: false,
2810
+ loading: false,
2811
+ isStreaming: false
2812
+ });
2763
2813
  }
2764
2814
  return true;
2765
2815
  }
@@ -2771,9 +2821,13 @@ var ChatMachine = class {
2771
2821
  this._updateMessaging({ turns: [...prevTurns, tempTurn] });
2772
2822
  return;
2773
2823
  }
2774
- const idx = prevTurns.findIndex((turn) => turn.userTurn.id === replaceFromMessageID);
2824
+ const idx = prevTurns.findIndex(
2825
+ (turn) => turn.userTurn.id === replaceFromMessageID
2826
+ );
2775
2827
  if (idx === -1) {
2776
- console.warn(`[ChatMachine] replaceFromMessageID "${replaceFromMessageID}" not found; appending as new turn`);
2828
+ console.warn(
2829
+ `[ChatMachine] replaceFromMessageID "${replaceFromMessageID}" not found; appending as new turn`
2830
+ );
2777
2831
  this._updateMessaging({ turns: [...prevTurns, tempTurn] });
2778
2832
  return;
2779
2833
  }
@@ -2857,7 +2911,10 @@ var ChatMachine = class {
2857
2911
  if (chunk.sessionId) {
2858
2912
  createdSessionId = chunk.sessionId;
2859
2913
  }
2860
- const pendingFromInterrupt = pendingQuestionFromInterrupt(chunk.interrupt, tempTurnId);
2914
+ const pendingFromInterrupt = pendingQuestionFromInterrupt(
2915
+ chunk.interrupt,
2916
+ tempTurnId
2917
+ );
2861
2918
  if (pendingFromInterrupt) {
2862
2919
  this._updateMessaging({
2863
2920
  pendingQuestion: pendingFromInterrupt,
@@ -2931,7 +2988,9 @@ var ChatMachine = class {
2931
2988
  this._updateInput({ message: content });
2932
2989
  this._clearStreamError();
2933
2990
  this._updateMessaging({
2934
- turns: this.state.messaging.turns.filter((turn) => turn.id !== tempTurnId)
2991
+ turns: this.state.messaging.turns.filter(
2992
+ (turn) => turn.id !== tempTurnId
2993
+ )
2935
2994
  });
2936
2995
  const sessionId = this.sendingSessionId ?? this.state.session.currentSessionId;
2937
2996
  if (sessionId && sessionId !== "new") {
@@ -2941,7 +3000,9 @@ var ChatMachine = class {
2941
3000
  return false;
2942
3001
  }
2943
3002
  this._updateMessaging({
2944
- turns: this.state.messaging.turns.filter((turn) => turn.id !== tempTurnId)
3003
+ turns: this.state.messaging.turns.filter(
3004
+ (turn) => turn.id !== tempTurnId
3005
+ )
2945
3006
  });
2946
3007
  const normalized = normalizeRPCError(err, "Failed to send message");
2947
3008
  this._updateInput({ inputError: normalized.userMessage });
@@ -3009,7 +3070,11 @@ var ChatMachine = class {
3009
3070
  const curSessionId = this.state.session.currentSessionId;
3010
3071
  const curDebugMode = deriveDebugMode(this.state);
3011
3072
  const replaceFromMessageID = options?.replaceFromMessageID;
3012
- const tempTurn = createPendingTurn(curSessionId || "new", content, attachments);
3073
+ const tempTurn = createPendingTurn(
3074
+ curSessionId || "new",
3075
+ content,
3076
+ attachments
3077
+ );
3013
3078
  this.lastSendAttempt = { content, attachments, options };
3014
3079
  const prevTurns = this.state.messaging.turns;
3015
3080
  this._insertOptimisticTurn(prevTurns, tempTurn, replaceFromMessageID);
@@ -3017,22 +3082,22 @@ var ChatMachine = class {
3017
3082
  try {
3018
3083
  const { activeSessionId, shouldNavigateAfter } = await this._resolveSendSession(curSessionId, curDebugMode);
3019
3084
  this.sendingSessionId = activeSessionId || null;
3020
- const {
3021
- createdSessionId,
3022
- sessionFetched,
3023
- stopped
3024
- } = await this._runSendStream({
3085
+ const { createdSessionId, sessionFetched, stopped } = await this._runSendStream({
3025
3086
  activeSessionId,
3026
3087
  content,
3027
3088
  attachments,
3028
3089
  debugMode: curDebugMode,
3029
3090
  replaceFromMessageID,
3030
- reasoningEffort: this.sanitizeReasoningEffort(this.state.session.reasoningEffort),
3091
+ reasoningEffort: this.sanitizeReasoningEffort(
3092
+ this.state.session.reasoningEffort
3093
+ ),
3031
3094
  tempTurnId: tempTurn.id
3032
3095
  });
3033
3096
  if (stopped) {
3034
3097
  this._updateMessaging({
3035
- turns: this.state.messaging.turns.filter((turn) => turn.id !== tempTurn.id)
3098
+ turns: this.state.messaging.turns.filter(
3099
+ (turn) => turn.id !== tempTurn.id
3100
+ )
3036
3101
  });
3037
3102
  this._updateInput({ message: content });
3038
3103
  this._clearStreamError();
@@ -3042,7 +3107,11 @@ var ChatMachine = class {
3042
3107
  });
3043
3108
  }
3044
3109
  } else {
3045
- await this._ensureSessionSyncAfterStream(activeSessionId, createdSessionId, sessionFetched);
3110
+ await this._ensureSessionSyncAfterStream(
3111
+ activeSessionId,
3112
+ createdSessionId,
3113
+ sessionFetched
3114
+ );
3046
3115
  const targetSessionId = createdSessionId || activeSessionId;
3047
3116
  this._finalizeSuccessfulSend(targetSessionId, shouldNavigateAfter);
3048
3117
  }
@@ -3080,7 +3149,9 @@ var ChatMachine = class {
3080
3149
  }
3081
3150
  this._updateMessaging({ thinkingContent: updated });
3082
3151
  const steps = this.state.messaging.activeSteps;
3083
- const existing = steps.find((s) => s.type === "thinking" && s.status === "active");
3152
+ const existing = steps.find(
3153
+ (s) => s.type === "thinking" && s.status === "active"
3154
+ );
3084
3155
  if (!existing) {
3085
3156
  const step = {
3086
3157
  id: `thinking-${Date.now()}`,
@@ -3111,7 +3182,9 @@ var ChatMachine = class {
3111
3182
  }
3112
3183
  _handleToolEnd(tool) {
3113
3184
  const steps = [...this.state.messaging.activeSteps];
3114
- const idx = steps.findIndex((s) => s.status === "active" && this._matchStep(s, tool));
3185
+ const idx = steps.findIndex(
3186
+ (s) => s.status === "active" && this._matchStep(s, tool)
3187
+ );
3115
3188
  if (idx !== -1) {
3116
3189
  steps[idx] = {
3117
3190
  ...steps[idx],
@@ -3142,7 +3215,11 @@ var ChatMachine = class {
3142
3215
  }
3143
3216
  this._clearStreamError();
3144
3217
  this._updateInput({ inputError: null });
3145
- await this._sendMessageDirect(lastAttempt.content, lastAttempt.attachments, lastAttempt.options);
3218
+ await this._sendMessageDirect(
3219
+ lastAttempt.content,
3220
+ lastAttempt.attachments,
3221
+ lastAttempt.options
3222
+ );
3146
3223
  }
3147
3224
  // ── Regenerate / Edit ───────────────────────────────────────────────────
3148
3225
  async _handleRegenerate(turnId) {
@@ -3155,9 +3232,13 @@ var ChatMachine = class {
3155
3232
  return;
3156
3233
  }
3157
3234
  this._updateSession({ error: null, errorRetryable: false });
3158
- await this._sendMessageDirect(turn.userTurn.content, turn.userTurn.attachments, {
3159
- replaceFromMessageID: turn.userTurn.id
3160
- });
3235
+ await this._sendMessageDirect(
3236
+ turn.userTurn.content,
3237
+ turn.userTurn.attachments,
3238
+ {
3239
+ replaceFromMessageID: turn.userTurn.id
3240
+ }
3241
+ );
3161
3242
  }
3162
3243
  async _handleEdit(turnId, newContent) {
3163
3244
  const curSessionId = this.state.session.currentSessionId;
@@ -3170,7 +3251,10 @@ var ChatMachine = class {
3170
3251
  }
3171
3252
  const turn = this.state.messaging.turns.find((t) => t.id === turnId);
3172
3253
  if (!turn) {
3173
- this._updateSession({ error: "Failed to edit message", errorRetryable: false });
3254
+ this._updateSession({
3255
+ error: "Failed to edit message",
3256
+ errorRetryable: false
3257
+ });
3174
3258
  return;
3175
3259
  }
3176
3260
  this._updateSession({ error: null, errorRetryable: false });
@@ -3208,8 +3292,17 @@ var ChatMachine = class {
3208
3292
  }
3209
3293
  if (result.success) {
3210
3294
  this._updateMessaging({
3211
- pendingQuestion: null,
3212
- turns: applyTurnLifecycleForPendingQuestion(this.state.messaging.turns, null)
3295
+ pendingQuestion: {
3296
+ ...previousPendingQuestion,
3297
+ status: "ANSWER_SUBMITTED"
3298
+ },
3299
+ turns: applyTurnLifecycleForPendingQuestion(
3300
+ this.state.messaging.turns,
3301
+ {
3302
+ ...previousPendingQuestion,
3303
+ status: "ANSWER_SUBMITTED"
3304
+ }
3305
+ )
3213
3306
  });
3214
3307
  if (result.data) {
3215
3308
  await this._resumeAcceptedRunOrPoll(curSessionId, result.data.runId);
@@ -3220,9 +3313,15 @@ var ChatMachine = class {
3220
3313
  }
3221
3314
  if (fetchResult) {
3222
3315
  this._updateSession({ session: fetchResult.session });
3223
- this._setTurnsFromFetch(fetchResult.turns, fetchResult.pendingQuestion || null);
3316
+ this._setTurnsFromFetch(
3317
+ fetchResult.turns,
3318
+ fetchResult.pendingQuestion || null
3319
+ );
3224
3320
  } else {
3225
- this._updateSession({ error: "Failed to load updated session", errorRetryable: true });
3321
+ this._updateSession({
3322
+ error: "Failed to load updated session",
3323
+ errorRetryable: true
3324
+ });
3226
3325
  }
3227
3326
  }
3228
3327
  } else if (curSessionId !== "new") {
@@ -3232,20 +3331,32 @@ var ChatMachine = class {
3232
3331
  }
3233
3332
  if (fetchResult) {
3234
3333
  this._updateSession({ session: fetchResult.session });
3235
- this._setTurnsFromFetch(fetchResult.turns, fetchResult.pendingQuestion || null);
3334
+ this._setTurnsFromFetch(
3335
+ fetchResult.turns,
3336
+ fetchResult.pendingQuestion || null
3337
+ );
3236
3338
  } else {
3237
- this._updateSession({ error: "Failed to load updated session", errorRetryable: true });
3339
+ this._updateSession({
3340
+ error: "Failed to load updated session",
3341
+ errorRetryable: true
3342
+ });
3238
3343
  }
3239
3344
  }
3240
3345
  } else {
3241
- this._updateSession({ error: result.error || "Failed to submit answers", errorRetryable: false });
3346
+ this._updateSession({
3347
+ error: result.error || "Failed to submit answers",
3348
+ errorRetryable: false
3349
+ });
3242
3350
  }
3243
3351
  } catch (err) {
3244
3352
  if (this.disposed) {
3245
3353
  return;
3246
3354
  }
3247
3355
  const normalized = normalizeRPCError(err, "Failed to submit answers");
3248
- this._updateSession({ error: normalized.userMessage, errorRetryable: normalized.retryable });
3356
+ this._updateSession({
3357
+ error: normalized.userMessage,
3358
+ errorRetryable: normalized.retryable
3359
+ });
3249
3360
  } finally {
3250
3361
  if (!this.disposed) {
3251
3362
  this._updateMessaging({ loading: false });
@@ -3264,12 +3375,37 @@ var ChatMachine = class {
3264
3375
  return;
3265
3376
  }
3266
3377
  if (result.success) {
3378
+ const submittedQuestion = {
3379
+ ...curPendingQuestion,
3380
+ status: "REJECT_SUBMITTED"
3381
+ };
3267
3382
  this._updateMessaging({
3268
- pendingQuestion: null,
3269
- turns: applyTurnLifecycleForPendingQuestion(this.state.messaging.turns, null)
3383
+ pendingQuestion: submittedQuestion,
3384
+ turns: applyTurnLifecycleForPendingQuestion(
3385
+ this.state.messaging.turns,
3386
+ submittedQuestion
3387
+ )
3270
3388
  });
3271
3389
  if (result.data) {
3272
3390
  await this._resumeAcceptedRunOrPoll(curSessionId, result.data.runId);
3391
+ if (!this.state.messaging.generationInProgress && curSessionId !== "new") {
3392
+ const fetchResult = await this.dataSource.fetchSession(curSessionId);
3393
+ if (this.disposed) {
3394
+ return;
3395
+ }
3396
+ if (fetchResult) {
3397
+ this._updateSession({ session: fetchResult.session });
3398
+ this._setTurnsFromFetch(
3399
+ fetchResult.turns,
3400
+ fetchResult.pendingQuestion || null
3401
+ );
3402
+ } else {
3403
+ this._updateSession({
3404
+ error: "Failed to load updated session",
3405
+ errorRetryable: true
3406
+ });
3407
+ }
3408
+ }
3273
3409
  } else if (curSessionId !== "new") {
3274
3410
  const fetchResult = await this.dataSource.fetchSession(curSessionId);
3275
3411
  if (this.disposed) {
@@ -3277,18 +3413,27 @@ var ChatMachine = class {
3277
3413
  }
3278
3414
  if (fetchResult) {
3279
3415
  this._updateSession({ session: fetchResult.session });
3280
- this._setTurnsFromFetch(fetchResult.turns, fetchResult.pendingQuestion || null);
3416
+ this._setTurnsFromFetch(
3417
+ fetchResult.turns,
3418
+ fetchResult.pendingQuestion || null
3419
+ );
3281
3420
  }
3282
3421
  }
3283
3422
  } else {
3284
- this._updateSession({ error: result.error || "Failed to reject question", errorRetryable: false });
3423
+ this._updateSession({
3424
+ error: result.error || "Failed to reject question",
3425
+ errorRetryable: false
3426
+ });
3285
3427
  }
3286
3428
  } catch (err) {
3287
3429
  if (this.disposed) {
3288
3430
  return;
3289
3431
  }
3290
3432
  const normalized = normalizeRPCError(err, "Failed to reject question");
3291
- this._updateSession({ error: normalized.userMessage, errorRetryable: normalized.retryable });
3433
+ this._updateSession({
3434
+ error: normalized.userMessage,
3435
+ errorRetryable: normalized.retryable
3436
+ });
3292
3437
  }
3293
3438
  }
3294
3439
  // ── Input / queue ───────────────────────────────────────────────────────
@@ -3335,7 +3480,10 @@ var ChatMachine = class {
3335
3480
  return false;
3336
3481
  }
3337
3482
  this._updateInput({
3338
- messageQueue: [...this.state.input.messageQueue, { content, attachments }]
3483
+ messageQueue: [
3484
+ ...this.state.input.messageQueue,
3485
+ { content, attachments }
3486
+ ]
3339
3487
  });
3340
3488
  return true;
3341
3489
  }
@@ -6854,7 +7002,9 @@ function DownloadCard({ artifact }) {
6854
7002
  );
6855
7003
  }
6856
7004
  init_useTranslation();
6857
- function InlineQuestionForm({ pendingQuestion }) {
7005
+ function InlineQuestionForm({
7006
+ pendingQuestion
7007
+ }) {
6858
7008
  const { handleSubmitQuestionAnswers, handleRejectPendingQuestion, loading } = useChatMessaging();
6859
7009
  const { t } = useTranslation();
6860
7010
  const [currentStep, setCurrentStep] = React.useState(0);
@@ -6865,6 +7015,7 @@ function InlineQuestionForm({ pendingQuestion }) {
6865
7015
  const isLastStep = currentStep === questions.length - 1;
6866
7016
  const isFirstStep = currentStep === 0;
6867
7017
  const totalSteps = questions.length;
7018
+ const isFailedRetry = pendingQuestion.status === "ANSWER_RESUME_FAILED" || pendingQuestion.status === "REJECT_RESUME_FAILED";
6868
7019
  const currentAnswer = answers[currentQuestion?.id];
6869
7020
  const currentOtherText = otherTexts[currentQuestion?.id] || "";
6870
7021
  const handleOptionChange = React.useCallback(
@@ -6993,7 +7144,13 @@ function InlineQuestionForm({ pendingQuestion }) {
6993
7144
  const canProceed = isCurrentAnswerValid();
6994
7145
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "animate-slide-up rounded-2xl border border-gray-200 dark:border-gray-700/50 bg-gradient-to-b from-primary-50/80 to-white dark:from-primary-950/30 dark:to-gray-900/80 shadow-sm overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: handleSubmit, children: [
6995
7146
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2.5 px-4 pt-4 pb-3", children: [
6996
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center w-7 h-7 rounded-lg bg-primary-100 dark:bg-primary-900/40", children: /* @__PURE__ */ jsxRuntime.jsx(react.ChatCircleDots, { className: "w-4 h-4 text-primary-600 dark:text-primary-400", weight: "fill" }) }),
7147
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center w-7 h-7 rounded-lg bg-primary-100 dark:bg-primary-900/40", children: /* @__PURE__ */ jsxRuntime.jsx(
7148
+ react.ChatCircleDots,
7149
+ {
7150
+ className: "w-4 h-4 text-primary-600 dark:text-primary-400",
7151
+ weight: "fill"
7152
+ }
7153
+ ) }),
6997
7154
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 min-w-0", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
6998
7155
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs font-semibold uppercase tracking-wide text-primary-600 dark:text-primary-400", children: t("BiChat.InlineQuestion.InputNeeded") }),
6999
7156
  totalSteps > 1 && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-[11px] tabular-nums text-gray-400 dark:text-gray-500", children: [
@@ -7014,6 +7171,10 @@ function InlineQuestionForm({ pendingQuestion }) {
7014
7171
  }
7015
7172
  )
7016
7173
  ] }),
7174
+ isFailedRetry && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mx-4 mb-3 rounded-xl border border-amber-200 dark:border-amber-700/40 bg-amber-50/80 dark:bg-amber-950/20 px-3 py-2", children: [
7175
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs font-medium text-amber-800 dark:text-amber-300", children: "Continuing after your last response failed." }),
7176
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-1 text-xs text-amber-700/80 dark:text-amber-200/80", children: "Review the answer and submit again, or dismiss the question if you want to skip it." })
7177
+ ] }),
7017
7178
  totalSteps > 1 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center gap-1.5 px-4 pb-3", children: questions.map((_, index) => {
7018
7179
  const isCompleted = index < currentStep;
7019
7180
  const isCurrent = index === currentStep;
@@ -7067,10 +7228,16 @@ function InlineQuestionForm({ pendingQuestion }) {
7067
7228
  className: "sr-only"
7068
7229
  }
7069
7230
  ),
7070
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: [
7071
- "text-sm transition-colors duration-150",
7072
- isSelected ? "text-gray-900 dark:text-gray-100 font-medium" : "text-gray-700 dark:text-gray-300"
7073
- ].join(" "), children: option.label })
7231
+ /* @__PURE__ */ jsxRuntime.jsx(
7232
+ "span",
7233
+ {
7234
+ className: [
7235
+ "text-sm transition-colors duration-150",
7236
+ isSelected ? "text-gray-900 dark:text-gray-100 font-medium" : "text-gray-700 dark:text-gray-300"
7237
+ ].join(" "),
7238
+ children: option.label
7239
+ }
7240
+ )
7074
7241
  ]
7075
7242
  },
7076
7243
  option.id
@@ -7107,10 +7274,16 @@ function InlineQuestionForm({ pendingQuestion }) {
7107
7274
  className: "sr-only"
7108
7275
  }
7109
7276
  ),
7110
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: [
7111
- "text-sm transition-colors duration-150",
7112
- isOtherSelected ? "text-gray-900 dark:text-gray-100 font-medium" : "text-gray-700 dark:text-gray-300"
7113
- ].join(" "), children: t("BiChat.InlineQuestion.OtherOption") })
7277
+ /* @__PURE__ */ jsxRuntime.jsx(
7278
+ "span",
7279
+ {
7280
+ className: [
7281
+ "text-sm transition-colors duration-150",
7282
+ isOtherSelected ? "text-gray-900 dark:text-gray-100 font-medium" : "text-gray-700 dark:text-gray-300"
7283
+ ].join(" "),
7284
+ children: t("BiChat.InlineQuestion.OtherOption")
7285
+ }
7286
+ )
7114
7287
  ]
7115
7288
  }
7116
7289
  ),
@@ -7542,7 +7715,9 @@ function DebugPanel({ trace }) {
7542
7715
  // ui/src/bichat/components/AssistantMessage.tsx
7543
7716
  init_useTranslation();
7544
7717
  var MarkdownRenderer2 = React.lazy(
7545
- () => Promise.resolve().then(() => (init_MarkdownRenderer(), MarkdownRenderer_exports)).then((module) => ({ default: module.MarkdownRenderer }))
7718
+ () => Promise.resolve().then(() => (init_MarkdownRenderer(), MarkdownRenderer_exports)).then((module) => ({
7719
+ default: module.MarkdownRenderer
7720
+ }))
7546
7721
  );
7547
7722
  var COPY_FEEDBACK_MS2 = 2e3;
7548
7723
  var defaultClassNames2 = {
@@ -7600,7 +7775,9 @@ function AssistantMessage({
7600
7775
  const { t } = useTranslation();
7601
7776
  const [explanationExpanded, setExplanationExpanded] = React.useState(false);
7602
7777
  const [isCopied, setIsCopied] = React.useState(false);
7603
- const copyFeedbackTimeoutRef = React.useRef(null);
7778
+ const copyFeedbackTimeoutRef = React.useRef(
7779
+ null
7780
+ );
7604
7781
  const classes = mergeClassNames2(defaultClassNames2, classNameOverrides);
7605
7782
  const isSystemMessage = turn.role === "system";
7606
7783
  const avatarClassName = isSystemMessage ? "flex-shrink-0 w-8 h-8 rounded-full bg-gray-500 dark:bg-gray-600 flex items-center justify-center text-white font-medium text-xs" : classes.avatar;
@@ -7616,8 +7793,11 @@ function AssistantMessage({
7616
7793
  const hasContent = turn.content?.trim().length > 0;
7617
7794
  const hasExplanation = !!turn.explanation?.trim();
7618
7795
  const isAwaitingHumanInput = turn.lifecycle === "waiting_for_human_input";
7619
- const pendingQuestionMatchesTurn = !!pendingQuestion && pendingQuestion.status === "PENDING" && (pendingQuestion.turnId === turnId || pendingQuestion.turnId === turn.id || !pendingQuestion.turnId && isLastTurn);
7796
+ const pendingQuestionStatus = pendingQuestion?.status;
7797
+ const pendingQuestionMatchesTurn = !!pendingQuestion && (pendingQuestionStatus === "PENDING" || pendingQuestionStatus === "ANSWER_SUBMITTED" || pendingQuestionStatus === "REJECT_SUBMITTED" || pendingQuestionStatus === "ANSWER_RESUME_FAILED" || pendingQuestionStatus === "REJECT_RESUME_FAILED") && (pendingQuestion.turnId === turnId || pendingQuestion.turnId === turn.id || !pendingQuestion.turnId && isLastTurn);
7620
7798
  const hasPendingQuestion = pendingQuestionMatchesTurn && !!pendingQuestion;
7799
+ const showQuestionForm = hasPendingQuestion && (pendingQuestionStatus === "PENDING" || pendingQuestionStatus === "ANSWER_RESUME_FAILED" || pendingQuestionStatus === "REJECT_RESUME_FAILED");
7800
+ const showResumeState = hasPendingQuestion && (pendingQuestionStatus === "ANSWER_SUBMITTED" || pendingQuestionStatus === "REJECT_SUBMITTED");
7621
7801
  const hasCodeOutputs = !!turn.codeOutputs?.length;
7622
7802
  const hasChart = !!turn.charts?.length;
7623
7803
  const hasTables = !!turn.renderTables?.length;
@@ -7626,7 +7806,7 @@ function AssistantMessage({
7626
7806
  const hasAnyRenderedContent = hasContent || hasExplanation || hasCodeOutputs || hasChart || hasTables || hasArtifacts || hasDebug;
7627
7807
  const canRegenerate = !!onRegenerate && !!turnId && !isSystemMessage && isLastTurn;
7628
7808
  const showInlineRetry = shouldRenderInlineRetry(turn, canRegenerate) && !hasAnyRenderedContent;
7629
- const renderMode = hasPendingQuestion ? "hitl_form" : isAwaitingHumanInput ? "hitl_waiting" : hasAnyRenderedContent ? "content" : showInlineRetry ? "retry" : "empty";
7809
+ const renderMode = showQuestionForm ? "hitl_form" : showResumeState ? "hitl_resuming" : isAwaitingHumanInput ? "hitl_waiting" : hasAnyRenderedContent ? "content" : showInlineRetry ? "retry" : "empty";
7630
7810
  const handleCopyClick = React.useCallback(async () => {
7631
7811
  try {
7632
7812
  if (onCopy) {
@@ -7653,7 +7833,9 @@ function AssistantMessage({
7653
7833
  }
7654
7834
  }, [onRegenerate, turnId]);
7655
7835
  const timestamp = formatRelativeTime(turn.createdAt, t);
7656
- const avatarSlotProps = { text: isSystemMessage ? "SYS" : "AI" };
7836
+ const avatarSlotProps = {
7837
+ text: isSystemMessage ? "SYS" : "AI"
7838
+ };
7657
7839
  const contentSlotProps = {
7658
7840
  content: turn.content,
7659
7841
  citations: turn.citations,
@@ -7696,11 +7878,21 @@ function AssistantMessage({
7696
7878
  return slot;
7697
7879
  };
7698
7880
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classes.root, children: [
7699
- !hideAvatar && /* @__PURE__ */ jsxRuntime.jsx("div", { className: avatarClassName, children: renderSlot(slots?.avatar, avatarSlotProps, isSystemMessage ? "SYS" : "AI") }),
7881
+ !hideAvatar && /* @__PURE__ */ jsxRuntime.jsx("div", { className: avatarClassName, children: renderSlot(
7882
+ slots?.avatar,
7883
+ avatarSlotProps,
7884
+ isSystemMessage ? "SYS" : "AI"
7885
+ ) }),
7700
7886
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classes.wrapper, children: [
7701
- /* @__PURE__ */ jsxRuntime.jsx(framerMotion.AnimatePresence, { children: showInlineRetry && /* @__PURE__ */ jsxRuntime.jsx(RetryActionArea, { onRetry: () => {
7702
- void handleRegenerateClick();
7703
- } }, "inline-retry") }),
7887
+ /* @__PURE__ */ jsxRuntime.jsx(framerMotion.AnimatePresence, { children: showInlineRetry && /* @__PURE__ */ jsxRuntime.jsx(
7888
+ RetryActionArea,
7889
+ {
7890
+ onRetry: () => {
7891
+ void handleRegenerateClick();
7892
+ }
7893
+ },
7894
+ "inline-retry"
7895
+ ) }),
7704
7896
  turn.codeOutputs && turn.codeOutputs.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.codeOutputs, children: renderSlot(
7705
7897
  slots?.codeOutputs,
7706
7898
  codeOutputsSlotProps,
@@ -7783,7 +7975,13 @@ function AssistantMessage({
7783
7975
  ]
7784
7976
  }
7785
7977
  ),
7786
- explanationExpanded && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pt-3 text-sm text-gray-600 dark:text-gray-400", children: /* @__PURE__ */ jsxRuntime.jsx(React.Suspense, { fallback: /* @__PURE__ */ jsxRuntime.jsx("div", { children: t("BiChat.Common.Loading") }), children: /* @__PURE__ */ jsxRuntime.jsx(MarkdownRenderer2, { content: turn.explanation }) }) })
7978
+ explanationExpanded && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pt-3 text-sm text-gray-600 dark:text-gray-400", children: /* @__PURE__ */ jsxRuntime.jsx(
7979
+ React.Suspense,
7980
+ {
7981
+ fallback: /* @__PURE__ */ jsxRuntime.jsx("div", { children: t("BiChat.Common.Loading") }),
7982
+ children: /* @__PURE__ */ jsxRuntime.jsx(MarkdownRenderer2, { content: turn.explanation })
7983
+ }
7984
+ ) })
7787
7985
  ] })
7788
7986
  ) }),
7789
7987
  showDebug && /* @__PURE__ */ jsxRuntime.jsx(DebugPanel, { trace: turn.debug })
@@ -7791,40 +7989,56 @@ function AssistantMessage({
7791
7989
  turn.artifacts && turn.artifacts.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: classes.artifacts, children: renderSlot(
7792
7990
  slots?.artifacts,
7793
7991
  artifactsSlotProps,
7794
- turn.artifacts.map((artifact, index) => /* @__PURE__ */ jsxRuntime.jsx(DownloadCard, { artifact }, `${artifact.filename}-${index}`))
7992
+ turn.artifacts.map((artifact, index) => /* @__PURE__ */ jsxRuntime.jsx(
7993
+ DownloadCard,
7994
+ {
7995
+ artifact
7996
+ },
7997
+ `${artifact.filename}-${index}`
7998
+ ))
7795
7999
  ) }),
7796
8000
  renderMode === "hitl_waiting" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "animate-slide-up rounded-2xl border border-primary-200 dark:border-primary-700/40 bg-gradient-to-b from-primary-50/70 to-white dark:from-primary-900/20 dark:to-gray-900/80 shadow-sm p-4", children: [
7797
8001
  /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-medium text-primary-700 dark:text-primary-300", children: t("BiChat.InlineQuestion.InputNeeded") }),
7798
8002
  /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-1 text-xs text-gray-500 dark:text-gray-400", children: t("BiChat.InlineQuestion.WaitingForDetails") })
7799
8003
  ] }),
8004
+ renderMode === "hitl_resuming" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "animate-slide-up rounded-2xl border border-emerald-200 dark:border-emerald-700/40 bg-gradient-to-b from-emerald-50/80 to-white dark:from-emerald-950/20 dark:to-gray-900/80 shadow-sm p-4", children: [
8005
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-medium text-emerald-700 dark:text-emerald-300", children: pendingQuestion?.status === "REJECT_SUBMITTED" ? "Dismissal submitted" : "Answer submitted" }),
8006
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-1 text-xs text-gray-500 dark:text-gray-400", children: "Continuing the run. This state will update automatically when the resume finishes." })
8007
+ ] }),
7800
8008
  renderMode === "hitl_form" && pendingQuestion && /* @__PURE__ */ jsxRuntime.jsx(InlineQuestionForm, { pendingQuestion }),
7801
- hasContent && !hideActions && /* @__PURE__ */ jsxRuntime.jsx("div", { className: `${classes.actions} ${isCopied ? "opacity-100" : ""}`, children: renderSlot(
7802
- slots?.actions,
7803
- actionsSlotProps,
7804
- /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
7805
- !hideTimestamp && /* @__PURE__ */ jsxRuntime.jsx("span", { className: classes.timestamp, children: timestamp }),
7806
- /* @__PURE__ */ jsxRuntime.jsx(
7807
- "button",
7808
- {
7809
- onClick: handleCopyClick,
7810
- className: `cursor-pointer ${classes.actionButton} ${isCopied ? "text-green-600 dark:text-green-400" : ""}`,
7811
- "aria-label": t("BiChat.Message.CopyMessage"),
7812
- title: isCopied ? t("BiChat.Message.Copied") : t("BiChat.Message.Copy"),
7813
- children: isCopied ? /* @__PURE__ */ jsxRuntime.jsx(react.Check, { size: 14, weight: "bold" }) : /* @__PURE__ */ jsxRuntime.jsx(react.Copy, { size: 14, weight: "regular" })
7814
- }
7815
- ),
7816
- canRegenerate && /* @__PURE__ */ jsxRuntime.jsx(
7817
- "button",
7818
- {
7819
- onClick: handleRegenerateClick,
7820
- className: `cursor-pointer ${classes.actionButton}`,
7821
- "aria-label": t("BiChat.Message.Regenerate"),
7822
- title: t("BiChat.Message.Regenerate"),
7823
- children: /* @__PURE__ */ jsxRuntime.jsx(react.ArrowsClockwise, { size: 14, weight: "regular" })
7824
- }
8009
+ hasContent && !hideActions && /* @__PURE__ */ jsxRuntime.jsx(
8010
+ "div",
8011
+ {
8012
+ className: `${classes.actions} ${isCopied ? "opacity-100" : ""}`,
8013
+ children: renderSlot(
8014
+ slots?.actions,
8015
+ actionsSlotProps,
8016
+ /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
8017
+ !hideTimestamp && /* @__PURE__ */ jsxRuntime.jsx("span", { className: classes.timestamp, children: timestamp }),
8018
+ /* @__PURE__ */ jsxRuntime.jsx(
8019
+ "button",
8020
+ {
8021
+ onClick: handleCopyClick,
8022
+ className: `cursor-pointer ${classes.actionButton} ${isCopied ? "text-green-600 dark:text-green-400" : ""}`,
8023
+ "aria-label": t("BiChat.Message.CopyMessage"),
8024
+ title: isCopied ? t("BiChat.Message.Copied") : t("BiChat.Message.Copy"),
8025
+ children: isCopied ? /* @__PURE__ */ jsxRuntime.jsx(react.Check, { size: 14, weight: "bold" }) : /* @__PURE__ */ jsxRuntime.jsx(react.Copy, { size: 14, weight: "regular" })
8026
+ }
8027
+ ),
8028
+ canRegenerate && /* @__PURE__ */ jsxRuntime.jsx(
8029
+ "button",
8030
+ {
8031
+ onClick: handleRegenerateClick,
8032
+ className: `cursor-pointer ${classes.actionButton}`,
8033
+ "aria-label": t("BiChat.Message.Regenerate"),
8034
+ title: t("BiChat.Message.Regenerate"),
8035
+ children: /* @__PURE__ */ jsxRuntime.jsx(react.ArrowsClockwise, { size: 14, weight: "regular" })
8036
+ }
8037
+ )
8038
+ ] })
7825
8039
  )
7826
- ] })
7827
- ) })
8040
+ }
8041
+ )
7828
8042
  ] })
7829
8043
  ] });
7830
8044
  }
@@ -17145,7 +17359,7 @@ function useHttpDataSourceConfigFromApplet(options) {
17145
17359
  streamEndpoint,
17146
17360
  csrfToken,
17147
17361
  rpcTimeoutMs: options?.rpcTimeoutMs ?? 12e4,
17148
- streamConnectTimeoutMs: options?.streamConnectTimeoutMs ?? 3e4
17362
+ streamConnectTimeoutMs: options?.streamConnectTimeoutMs
17149
17363
  };
17150
17364
  }, [options?.rpcTimeoutMs, options?.streamConnectTimeoutMs]);
17151
17365
  }
@@ -17554,7 +17768,10 @@ function toSession(session) {
17554
17768
  function toSessionArtifact(artifact) {
17555
17769
  const rawCreatedAt = readNonEmptyString(artifact.createdAt);
17556
17770
  if (!rawCreatedAt) {
17557
- warnMalformedSessionPayload("Artifact missing createdAt; defaulting to epoch", { id: artifact.id });
17771
+ warnMalformedSessionPayload(
17772
+ "Artifact missing createdAt; defaulting to epoch",
17773
+ { id: artifact.id }
17774
+ );
17558
17775
  }
17559
17776
  const createdAt = rawCreatedAt ?? "1970-01-01T00:00:00.000Z";
17560
17777
  return {
@@ -17576,6 +17793,21 @@ function normalizeQuestionType2(rawType) {
17576
17793
  const normalized = readString2(rawType).trim().toUpperCase().replace(/[\s-]+/g, "_");
17577
17794
  return normalized === "MULTIPLE_CHOICE" ? "MULTIPLE_CHOICE" : "SINGLE_CHOICE";
17578
17795
  }
17796
+ function normalizePendingQuestionStatus(rawStatus) {
17797
+ const normalized = readString2(rawStatus).trim().toUpperCase();
17798
+ switch (normalized) {
17799
+ case "ANSWER_SUBMITTED":
17800
+ case "REJECT_SUBMITTED":
17801
+ case "ANSWER_RESUME_FAILED":
17802
+ case "REJECT_RESUME_FAILED":
17803
+ case "ANSWERED":
17804
+ case "REJECTED":
17805
+ case "CANCELLED":
17806
+ return normalized;
17807
+ default:
17808
+ return "PENDING";
17809
+ }
17810
+ }
17579
17811
  function normalizeMessageRole(rawRole) {
17580
17812
  const normalized = readString2(rawRole).trim().toLowerCase();
17581
17813
  if (normalized === "user" /* User */) {
@@ -17591,11 +17823,17 @@ function normalizeMessageRole(rawRole) {
17591
17823
  }
17592
17824
  function sanitizeAttachment(rawAttachment, turnId, index) {
17593
17825
  if (!isRecord2(rawAttachment)) {
17594
- warnMalformedSessionPayload("Dropped malformed attachment entry", { turnId, index });
17826
+ warnMalformedSessionPayload("Dropped malformed attachment entry", {
17827
+ turnId,
17828
+ index
17829
+ });
17595
17830
  return null;
17596
17831
  }
17597
17832
  const filename = readString2(rawAttachment.filename, "attachment");
17598
- const mimeType = readString2(rawAttachment.mimeType, "application/octet-stream");
17833
+ const mimeType = readString2(
17834
+ rawAttachment.mimeType,
17835
+ "application/octet-stream"
17836
+ );
17599
17837
  const id = readNonEmptyString(rawAttachment.id) || void 0;
17600
17838
  const clientKey = readNonEmptyString(rawAttachment.clientKey) || id || `${turnId}-attachment-${index}`;
17601
17839
  return {
@@ -17631,7 +17869,10 @@ function sanitizeAssistantArtifacts(rawArtifacts, turnId) {
17631
17869
  for (let i = 0; i < rawArtifacts.length; i++) {
17632
17870
  const raw = rawArtifacts[i];
17633
17871
  if (!isRecord2(raw)) {
17634
- warnMalformedSessionPayload("Dropped malformed assistant artifact", { turnId, index: i });
17872
+ warnMalformedSessionPayload("Dropped malformed assistant artifact", {
17873
+ turnId,
17874
+ index: i
17875
+ });
17635
17876
  continue;
17636
17877
  }
17637
17878
  const type = readString2(raw.type).toLowerCase();
@@ -17640,7 +17881,10 @@ function sanitizeAssistantArtifacts(rawArtifacts, turnId) {
17640
17881
  }
17641
17882
  const url = readNonEmptyString(raw.url);
17642
17883
  if (!url) {
17643
- warnMalformedSessionPayload("Dropped assistant artifact without url", { turnId, index: i });
17884
+ warnMalformedSessionPayload("Dropped assistant artifact without url", {
17885
+ turnId,
17886
+ index: i
17887
+ });
17644
17888
  continue;
17645
17889
  }
17646
17890
  artifacts.push({
@@ -17659,12 +17903,16 @@ function sanitizeAssistantTurn(rawAssistantTurn, fallbackCreatedAt, turnId) {
17659
17903
  return void 0;
17660
17904
  }
17661
17905
  if (!isRecord2(rawAssistantTurn)) {
17662
- warnMalformedSessionPayload("Dropped malformed assistant turn payload", { turnId });
17906
+ warnMalformedSessionPayload("Dropped malformed assistant turn payload", {
17907
+ turnId
17908
+ });
17663
17909
  return void 0;
17664
17910
  }
17665
17911
  const assistantID = readNonEmptyString(rawAssistantTurn.id);
17666
17912
  if (!assistantID) {
17667
- warnMalformedSessionPayload("Dropped assistant turn without id", { turnId });
17913
+ warnMalformedSessionPayload("Dropped assistant turn without id", {
17914
+ turnId
17915
+ });
17668
17916
  return void 0;
17669
17917
  }
17670
17918
  const citations = Array.isArray(rawAssistantTurn.citations) ? rawAssistantTurn.citations.filter((item) => isRecord2(item)).map((item, index) => ({
@@ -17701,17 +17949,27 @@ function sanitizeAssistantTurn(rawAssistantTurn, fallbackCreatedAt, turnId) {
17701
17949
  schemaVersion: readNonEmptyString(rawAssistantTurn.debug.schemaVersion) || void 0,
17702
17950
  startedAt: readNonEmptyString(rawAssistantTurn.debug.startedAt) || void 0,
17703
17951
  completedAt: readNonEmptyString(rawAssistantTurn.debug.completedAt) || void 0,
17704
- generationMs: readOptionalFiniteNumber(rawAssistantTurn.debug.generationMs),
17952
+ generationMs: readOptionalFiniteNumber(
17953
+ rawAssistantTurn.debug.generationMs
17954
+ ),
17705
17955
  traceId: readNonEmptyString(rawAssistantTurn.debug.traceId) || void 0,
17706
17956
  traceUrl: readNonEmptyString(rawAssistantTurn.debug.traceUrl) || void 0,
17707
17957
  sessionId: readNonEmptyString(rawAssistantTurn.debug.sessionId) || void 0,
17708
17958
  thinking: readNonEmptyString(rawAssistantTurn.debug.thinking) || void 0,
17709
17959
  observationReason: readNonEmptyString(rawAssistantTurn.debug.observationReason) || void 0,
17710
17960
  usage: isRecord2(rawAssistantTurn.debug.usage) ? {
17711
- promptTokens: readFiniteNumber(rawAssistantTurn.debug.usage.promptTokens),
17712
- completionTokens: readFiniteNumber(rawAssistantTurn.debug.usage.completionTokens),
17713
- totalTokens: readFiniteNumber(rawAssistantTurn.debug.usage.totalTokens),
17714
- cachedTokens: readOptionalFiniteNumber(rawAssistantTurn.debug.usage.cachedTokens),
17961
+ promptTokens: readFiniteNumber(
17962
+ rawAssistantTurn.debug.usage.promptTokens
17963
+ ),
17964
+ completionTokens: readFiniteNumber(
17965
+ rawAssistantTurn.debug.usage.completionTokens
17966
+ ),
17967
+ totalTokens: readFiniteNumber(
17968
+ rawAssistantTurn.debug.usage.totalTokens
17969
+ ),
17970
+ cachedTokens: readOptionalFiniteNumber(
17971
+ rawAssistantTurn.debug.usage.cachedTokens
17972
+ ),
17715
17973
  cost: readOptionalFiniteNumber(rawAssistantTurn.debug.usage.cost)
17716
17974
  } : void 0,
17717
17975
  tools: Array.isArray(rawAssistantTurn.debug.tools) ? rawAssistantTurn.debug.tools.filter((tool) => isRecord2(tool)).map((tool) => ({
@@ -17729,7 +17987,9 @@ function sanitizeAssistantTurn(rawAssistantTurn, fallbackCreatedAt, turnId) {
17729
17987
  provider: readNonEmptyString(attempt.provider) || void 0,
17730
17988
  finishReason: readNonEmptyString(attempt.finishReason) || void 0,
17731
17989
  promptTokens: readOptionalFiniteNumber(attempt.promptTokens),
17732
- completionTokens: readOptionalFiniteNumber(attempt.completionTokens),
17990
+ completionTokens: readOptionalFiniteNumber(
17991
+ attempt.completionTokens
17992
+ ),
17733
17993
  totalTokens: readOptionalFiniteNumber(attempt.totalTokens),
17734
17994
  cachedTokens: readOptionalFiniteNumber(attempt.cachedTokens),
17735
17995
  cost: readOptionalFiniteNumber(attempt.cost),
@@ -17798,16 +18058,25 @@ function sanitizeAssistantTurn(rawAssistantTurn, fallbackCreatedAt, turnId) {
17798
18058
  }
17799
18059
  function sanitizeConversationTurn(rawTurn, index, fallbackSessionID) {
17800
18060
  if (!isRecord2(rawTurn)) {
17801
- warnMalformedSessionPayload("Dropped malformed turn payload (not an object)", { index });
18061
+ warnMalformedSessionPayload(
18062
+ "Dropped malformed turn payload (not an object)",
18063
+ { index }
18064
+ );
17802
18065
  return null;
17803
18066
  }
17804
18067
  if (!isRecord2(rawTurn.userTurn)) {
17805
- warnMalformedSessionPayload("Dropped malformed turn payload (missing user turn)", { index });
18068
+ warnMalformedSessionPayload(
18069
+ "Dropped malformed turn payload (missing user turn)",
18070
+ { index }
18071
+ );
17806
18072
  return null;
17807
18073
  }
17808
18074
  const userTurnID = readNonEmptyString(rawTurn.userTurn.id);
17809
18075
  if (!userTurnID) {
17810
- warnMalformedSessionPayload("Dropped malformed turn payload (missing user turn id)", { index });
18076
+ warnMalformedSessionPayload(
18077
+ "Dropped malformed turn payload (missing user turn id)",
18078
+ { index }
18079
+ );
17811
18080
  return null;
17812
18081
  }
17813
18082
  const turnID = readString2(rawTurn.id, userTurnID);
@@ -17821,17 +18090,27 @@ function sanitizeConversationTurn(rawTurn, index, fallbackSessionID) {
17821
18090
  userTurn: {
17822
18091
  id: userTurnID,
17823
18092
  content: readString2(rawTurn.userTurn.content),
17824
- attachments: sanitizeUserAttachments(rawTurn.userTurn.attachments, turnID),
18093
+ attachments: sanitizeUserAttachments(
18094
+ rawTurn.userTurn.attachments,
18095
+ turnID
18096
+ ),
17825
18097
  author: mapSessionUser(rawTurn.userTurn.author),
17826
18098
  createdAt: readString2(rawTurn.userTurn.createdAt, createdAt)
17827
18099
  },
17828
- assistantTurn: sanitizeAssistantTurn(rawTurn.assistantTurn, createdAt, turnID),
18100
+ assistantTurn: sanitizeAssistantTurn(
18101
+ rawTurn.assistantTurn,
18102
+ createdAt,
18103
+ turnID
18104
+ ),
17829
18105
  createdAt
17830
18106
  };
17831
18107
  }
17832
18108
  function sanitizeConversationTurns(rawTurns, sessionID) {
17833
18109
  if (!Array.isArray(rawTurns)) {
17834
- warnMalformedSessionPayload("Session payload contained non-array turns field", { sessionID });
18110
+ warnMalformedSessionPayload(
18111
+ "Session payload contained non-array turns field",
18112
+ { sessionID }
18113
+ );
17835
18114
  return [];
17836
18115
  }
17837
18116
  const turns = [];
@@ -17845,11 +18124,14 @@ function sanitizeConversationTurns(rawTurns, sessionID) {
17845
18124
  }
17846
18125
  }
17847
18126
  if (dropped > 0) {
17848
- warnMalformedSessionPayload("Dropped malformed turns from session payload", {
17849
- sessionID,
17850
- dropped,
17851
- total: rawTurns.length
17852
- });
18127
+ warnMalformedSessionPayload(
18128
+ "Dropped malformed turns from session payload",
18129
+ {
18130
+ sessionID,
18131
+ dropped,
18132
+ total: rawTurns.length
18133
+ }
18134
+ );
17853
18135
  }
17854
18136
  return turns;
17855
18137
  }
@@ -17859,39 +18141,57 @@ function sanitizePendingQuestion(rawPendingQuestion, sessionID) {
17859
18141
  }
17860
18142
  const checkpointID = readNonEmptyString(rawPendingQuestion.checkpointId);
17861
18143
  if (!checkpointID) {
17862
- warnMalformedSessionPayload("Dropped malformed pendingQuestion without checkpointId", { sessionID });
18144
+ warnMalformedSessionPayload(
18145
+ "Dropped malformed pendingQuestion without checkpointId",
18146
+ { sessionID }
18147
+ );
17863
18148
  return null;
17864
18149
  }
17865
18150
  if (!Array.isArray(rawPendingQuestion.questions)) {
17866
- warnMalformedSessionPayload("Pending question had non-array questions payload", {
17867
- sessionID,
17868
- checkpointID
17869
- });
18151
+ warnMalformedSessionPayload(
18152
+ "Pending question had non-array questions payload",
18153
+ {
18154
+ sessionID,
18155
+ checkpointID
18156
+ }
18157
+ );
17870
18158
  }
17871
18159
  const questions = Array.isArray(rawPendingQuestion.questions) ? rawPendingQuestion.questions.filter((question) => {
17872
18160
  if (!question || !isRecord2(question)) {
17873
- warnMalformedSessionPayload("Dropped malformed question from pendingQuestion", {
17874
- sessionID,
17875
- checkpointID
17876
- });
18161
+ warnMalformedSessionPayload(
18162
+ "Dropped malformed question from pendingQuestion",
18163
+ {
18164
+ sessionID,
18165
+ checkpointID
18166
+ }
18167
+ );
17877
18168
  return false;
17878
18169
  }
17879
18170
  return true;
17880
18171
  }).map((question, index) => {
17881
- const questionID = readString2(question.id, `${checkpointID}-q-${index}`);
18172
+ const questionID = readString2(
18173
+ question.id,
18174
+ `${checkpointID}-q-${index}`
18175
+ );
17882
18176
  const options = Array.isArray(question.options) ? question.options.filter((option) => {
17883
18177
  if (!option || !isRecord2(option)) {
17884
- warnMalformedSessionPayload("Dropped malformed pendingQuestion option", {
17885
- sessionID,
17886
- checkpointID,
17887
- questionID
17888
- });
18178
+ warnMalformedSessionPayload(
18179
+ "Dropped malformed pendingQuestion option",
18180
+ {
18181
+ sessionID,
18182
+ checkpointID,
18183
+ questionID
18184
+ }
18185
+ );
17889
18186
  return false;
17890
18187
  }
17891
18188
  return true;
17892
18189
  }).map((option, optionIndex) => {
17893
18190
  const label = readString2(option.label);
17894
- const id = readString2(option.id, `${questionID}-opt-${optionIndex}`);
18191
+ const id = readString2(
18192
+ option.id,
18193
+ `${questionID}-opt-${optionIndex}`
18194
+ );
17895
18195
  return {
17896
18196
  id,
17897
18197
  label,
@@ -17910,7 +18210,7 @@ function sanitizePendingQuestion(rawPendingQuestion, sessionID) {
17910
18210
  turnId: readString2(rawPendingQuestion.turnId),
17911
18211
  agentName: readNonEmptyString(rawPendingQuestion.agentName) || void 0,
17912
18212
  questions,
17913
- status: "PENDING"
18213
+ status: normalizePendingQuestionStatus(rawPendingQuestion.status)
17914
18214
  };
17915
18215
  }
17916
18216
  function formatSizeReadable(bytes) {
@@ -18119,7 +18419,9 @@ function attachArtifactsToTurns(turns, artifacts) {
18119
18419
  if (artifacts.length === 0) {
18120
18420
  return turns;
18121
18421
  }
18122
- const downloadArtifacts = artifacts.map((raw) => ({ raw, mapped: toDownloadArtifact(raw) })).filter((entry) => entry.mapped !== null).sort((a, b) => toMillis(a.raw.createdAt) - toMillis(b.raw.createdAt));
18422
+ const downloadArtifacts = artifacts.map((raw) => ({ raw, mapped: toDownloadArtifact(raw) })).filter(
18423
+ (entry) => entry.mapped !== null
18424
+ ).sort((a, b) => toMillis(a.raw.createdAt) - toMillis(b.raw.createdAt));
18123
18425
  const chartArtifacts = artifacts.filter((a) => a.type === "chart").sort((a, b) => toMillis(a.createdAt) - toMillis(b.createdAt));
18124
18426
  const tableArtifacts = artifacts.filter((a) => a.type === "table").sort((a, b) => toMillis(a.createdAt) - toMillis(b.createdAt));
18125
18427
  if (downloadArtifacts.length === 0 && chartArtifacts.length === 0 && tableArtifacts.length === 0) {
@@ -18208,14 +18510,19 @@ function attachArtifactsToTurns(turns, artifacts) {
18208
18510
  continue;
18209
18511
  }
18210
18512
  if (assistantTurn.renderTables === void 0) {
18211
- assistantTurn.renderTables = extractRenderTablesFromToolCalls(assistantTurn.toolCalls);
18513
+ assistantTurn.renderTables = extractRenderTablesFromToolCalls(
18514
+ assistantTurn.toolCalls
18515
+ );
18212
18516
  }
18213
18517
  const existing = assistantTurn.renderTables;
18214
18518
  const metadata = raw.metadata;
18215
18519
  if (!metadata || typeof metadata !== "object" || metadata === null) {
18216
18520
  continue;
18217
18521
  }
18218
- const tableData = parseRenderTableDataFromMetadata(metadata, raw.id);
18522
+ const tableData = parseRenderTableDataFromMetadata(
18523
+ metadata,
18524
+ raw.id
18525
+ );
18219
18526
  if (!tableData) {
18220
18527
  continue;
18221
18528
  }
@@ -19080,7 +19387,7 @@ var HttpDataSource = class {
19080
19387
  uploadEndpoint: "/api/uploads",
19081
19388
  ...config,
19082
19389
  rpcTimeoutMs: typeof config.rpcTimeoutMs === "number" ? config.rpcTimeoutMs : 12e4,
19083
- streamConnectTimeoutMs: typeof config.streamConnectTimeoutMs === "number" ? config.streamConnectTimeoutMs : 3e4
19390
+ streamConnectTimeoutMs: typeof config.streamConnectTimeoutMs === "number" ? config.streamConnectTimeoutMs : void 0
19084
19391
  };
19085
19392
  this.rpc = createAppletRPCClient({
19086
19393
  endpoint: `${this.config.baseUrl}${this.config.rpcEndpoint}`,