@burdenoff/fe-libs 2026.926.2 → 2026.926.4

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 (64) hide show
  1. package/dist/shared/assistant/autoRouting.d.ts +1 -0
  2. package/dist/shared/assistant/autoRouting.d.ts.map +1 -1
  3. package/dist/shared/assistant/autoRouting.js +1 -1
  4. package/dist/shared/assistant/capabilities.d.ts +5 -0
  5. package/dist/shared/assistant/capabilities.d.ts.map +1 -1
  6. package/dist/shared/assistant/capabilities.js +2 -1
  7. package/dist/shared/assistant/conversation.d.ts +29 -0
  8. package/dist/shared/assistant/conversation.d.ts.map +1 -1
  9. package/dist/shared/assistant/guardedStorage.d.ts +32 -0
  10. package/dist/shared/assistant/guardedStorage.d.ts.map +1 -0
  11. package/dist/shared/assistant/guardedStorage.js +36 -0
  12. package/dist/shared/assistant/i18nManifest.d.ts +7 -0
  13. package/dist/shared/assistant/i18nManifest.d.ts.map +1 -1
  14. package/dist/shared/assistant/i18nManifest.js +7 -0
  15. package/dist/shared/assistant/index.d.ts +5 -0
  16. package/dist/shared/assistant/index.d.ts.map +1 -1
  17. package/dist/shared/assistant/liveTurns.d.ts +145 -0
  18. package/dist/shared/assistant/liveTurns.d.ts.map +1 -0
  19. package/dist/shared/assistant/liveTurns.js +99 -0
  20. package/dist/shared/assistant/operations.d.ts +7 -0
  21. package/dist/shared/assistant/operations.d.ts.map +1 -1
  22. package/dist/shared/assistant/operations.js +2 -2
  23. package/dist/shared/assistant/prewarm.d.ts +32 -4
  24. package/dist/shared/assistant/prewarm.d.ts.map +1 -1
  25. package/dist/shared/assistant/prewarm.js +35 -15
  26. package/dist/shared/assistant/product.d.ts +11 -1
  27. package/dist/shared/assistant/product.d.ts.map +1 -1
  28. package/dist/shared/assistant/product.js +8 -6
  29. package/dist/shared/assistant/store.d.ts.map +1 -1
  30. package/dist/shared/assistant/store.js +11 -10
  31. package/dist/shared/assistant/turnState.d.ts +12 -0
  32. package/dist/shared/assistant/turnState.d.ts.map +1 -1
  33. package/dist/shared/assistant/turnState.js +4 -1
  34. package/dist/shared/assistant/turnTimeline.d.ts +37 -3
  35. package/dist/shared/assistant/turnTimeline.d.ts.map +1 -1
  36. package/dist/shared/assistant/turnTimeline.js +45 -33
  37. package/dist/shared/assistant/turnTimingReport.d.ts +86 -0
  38. package/dist/shared/assistant/turnTimingReport.d.ts.map +1 -0
  39. package/dist/shared/assistant/turnTimingReport.js +123 -0
  40. package/dist/shared/assistant/turnTimingReporter.d.ts +146 -0
  41. package/dist/shared/assistant/turnTimingReporter.d.ts.map +1 -0
  42. package/dist/shared/assistant/turnTimingReporter.js +321 -0
  43. package/dist/shared/assistant/ui/AssistantChatArea.d.ts.map +1 -1
  44. package/dist/shared/assistant/ui/AssistantChatArea.js +703 -544
  45. package/dist/shared/assistant/ui/AssistantMessageItem.d.ts +19 -0
  46. package/dist/shared/assistant/ui/AssistantMessageItem.d.ts.map +1 -1
  47. package/dist/shared/assistant/ui/AssistantMessageItem.js +92 -88
  48. package/dist/shared/assistant/ui/AssistantMessageList.d.ts +22 -2
  49. package/dist/shared/assistant/ui/AssistantMessageList.d.ts.map +1 -1
  50. package/dist/shared/assistant/ui/AssistantMessageList.js +37 -36
  51. package/dist/shared/assistant/ui/AssistantPendingWriteCard.d.ts +34 -0
  52. package/dist/shared/assistant/ui/AssistantPendingWriteCard.d.ts.map +1 -1
  53. package/dist/shared/assistant/ui/AssistantPendingWriteCard.js +31 -28
  54. package/dist/shared/assistant/ui/useVoiceSession.d.ts +1 -0
  55. package/dist/shared/assistant/ui/useVoiceSession.d.ts.map +1 -1
  56. package/dist/shared/assistant/ui/useVoiceSession.js +119 -117
  57. package/dist/shared/assistant/voice/voiceReopen.d.ts +117 -0
  58. package/dist/shared/assistant/voice/voiceReopen.d.ts.map +1 -0
  59. package/dist/shared/assistant/voice/voiceReopen.js +49 -0
  60. package/dist/shared/graphql/fetch.d.ts +10 -0
  61. package/dist/shared/graphql/fetch.d.ts.map +1 -1
  62. package/dist/shared/graphql/fetch.js +64 -62
  63. package/dist/shared-assistant.js +136 -131
  64. package/package.json +2 -2
@@ -6,352 +6,401 @@ import { useAssistantProduct as r } from "../product.js";
6
6
  import { useAssistantTr as i } from "../i18n.js";
7
7
  import { useAssistantNavigate as a } from "./AssistantMarkdownRenderer.js";
8
8
  import { isAssistantModeId as o } from "../modeIds.js";
9
- import { abortAssistantTurn as s, approvePendingWrite as c, createAssistantSandbox as l, createAssistantSession as u, extendAssistantSandboxTTL as d, findExistingSandboxWithStatus as f, getAssistantArtifacts as p, getAssistantMessages as ee, getAssistantSession as m, modeRequiresConfirmWrites as h, promptGatewayRequestBytes as te, releaseSupersededAssistantSandboxes as ne, sendAssistantPromptAsync as g, waitForAssistantServiceReady as _, waitForSandboxRunning as v } from "../api.js";
10
- import { sanitize as re } from "../progress.js";
11
- import { withIncompleteTurnNotice as ie } from "../streamBudget.js";
12
- import { isVoiceTurn as ae, voiceMarker as y, voiceSessionIdOf as b } from "../voice/turnVisibility.js";
13
- import { buildContinuedFromVoiceNote as oe, buildVoiceTranscriptMarkdown as se, voiceTranscriptFilename as x } from "../voice/voiceTranscript.js";
14
- import { pollDelayMs as ce } from "../voice/assistantPollSchedule.js";
15
- import { toCaptionText as le } from "../voice/captionText.js";
16
- import { resolveAssistantLanguage as ue } from "../voice/languages.js";
17
- import { resolveLanguagePair as de } from "../voice/languagePair.js";
18
- import { countInlineImageCandidates as fe, countInlinedImageParts as pe, getSendableAttachments as me, largestInlineCharsPerFile as he, resolveAssistantInlineLimits as ge, toMessageAttachment as _e } from "../attachments.js";
19
- import { AssistantSendRefusal as ve, classifyTurnFailure as ye, turnOutcomeCopy as S } from "../turnOutcome.js";
20
- import { createAdminModeAccessGate as be, resolveAssistantSendModeAfterAccess as xe } from "../adminModeSendGate.js";
21
- import { buildBoundedAttachmentTurn as Se } from "../attachmentTurn.js";
22
- import { isWriteModeAcknowledged as Ce, writeModeSendRefusalReason as we } from "../writeModeConsent.js";
23
- import { AUTO_READ_MODE as Te, autoCarryOverFor as Ee, autoSuggestions as De, classifyAssistantIntent as Oe, escalationToUndo as ke, isAutoRoutingOffered as Ae, resolveAutoRoute as je } from "../autoRouting.js";
24
- import { resolveActiveModeSandbox as Me, useAssistantStore as C } from "../store.js";
25
- import { isTurnInFlight as Ne, planAbandonedTurn as Pe, planTurnAbort as Fe } from "../turnState.js";
26
- import { getAssistantDisplayContent as Ie } from "../displayContent.js";
27
- import { NO_FIRST_TEXT as Le, buildAssistantProgress as Re, readAheadFor as ze, snapshotReplyFloor as Be, startSessionReadAhead as Ve, trackFirstText as He } from "../turnProgress.js";
28
- import { parseToolActivity as Ue } from "./AssistantToolActivity.js";
29
- import { countSpokenTurns as We, spokenTurnText as Ge } from "../spokenTurns.js";
30
- import { beginTurn as Ke, describeTurn as w, detectTurnDevice as qe, markTurn as T, restartAttempt as Je, turnClockMs as Ye } from "../turnTimeline.js";
31
- import { useAssistantSpeech as Xe } from "./AssistantSpeechProvider.js";
32
- import { useVoiceSession as Ze } from "./useVoiceSession.js";
33
- import { getOrganizationId as Qe, getWorkspaceId as $e } from "../context.js";
34
- import { isMultimodalBodyRejection as et, isRecoverableAssistantError as tt } from "../transportErrors.js";
35
- import { createReadinessTracker as nt, planAfterTransportFailure as rt, planTrustedSandboxFailure as it } from "../sandboxReadiness.js";
36
- import { AssistantSpokenTurnsNotice as at } from "./AssistantSpokenTurnsNotice.js";
37
- import { VoiceTranscriptDrawer as ot } from "./voice/VoiceTranscriptDrawer.js";
38
- import { downloadFile as st } from "../exportConversation.js";
39
- import { AssistantEmptyState as ct } from "./AssistantEmptyState.js";
40
- import { AssistantMessageList as lt } from "./AssistantMessageList.js";
41
- import { AssistantVoiceSession as ut } from "./voice/AssistantVoiceSession.js";
42
- import { useAssistantApiAccess as dt } from "../useAssistantApiAccess.js";
43
- import { useConversationTurns as ft } from "../useConversationTurns.js";
44
- import { WarmCancelled as pt, consumeWarm as mt, prewarmTarget as ht, settleWarmBeforeSend as gt, startWarm as _t, warmState as vt } from "../prewarm.js";
45
- import { isAlreadyThere as yt, matchLocalUiCommand as bt, navDestinations as xt, planThemeChange as St } from "../localUiCommands.js";
46
- import { chooseDestinationCopy as Ct, navigationCommandCopy as wt, themeCommandCopy as Tt } from "../localUiCommandCopy.js";
47
- import { dispatchAssistantQuotaExhausted as Et, notifyAiCreditsUpdated as Dt } from "../aiCredits.js";
48
- import { useAssistantAttachments as Ot } from "../useAssistantAttachments.js";
49
- import { AssistantComposer as kt } from "./composer/AssistantComposer.js";
50
- import { isProdRuntime as At } from "../env.js";
51
- import { AssistantApiCallsConsentDialog as jt } from "./AssistantApiCallsConsentDialog.js";
52
- import { useVisibleNavItems as Mt } from "../../../chrome/mobileTabBar/useVisibleNavItems.js";
53
- import { useCallback as E, useEffect as D, useMemo as O, useRef as k, useState as Nt } from "react";
54
- import { jsx as A, jsxs as Pt } from "react/jsx-runtime";
9
+ import { abortAssistantTurn as s, approvePendingWrite as c, createAssistantSandbox as l, createAssistantSession as u, extendAssistantSandboxTTL as ee, findExistingSandboxWithStatus as te, getAssistantArtifacts as d, getAssistantMessages as f, getAssistantSession as p, modeRequiresConfirmWrites as m, promptGatewayRequestBytes as ne, releaseSupersededAssistantSandboxes as h, sendAssistantPromptAsync as g, waitForAssistantServiceReady as _, waitForSandboxRunning as re } from "../api.js";
10
+ import { sanitize as ie } from "../progress.js";
11
+ import { withIncompleteTurnNotice as ae } from "../streamBudget.js";
12
+ import { chatTurns as v, isVoiceTurn as y, voiceMarker as oe, voiceSessionIdOf as b } from "../voice/turnVisibility.js";
13
+ import { buildContinuedFromVoiceNote as se, buildVoiceTranscriptMarkdown as ce, voiceTranscriptFilename as x } from "../voice/voiceTranscript.js";
14
+ import { pollDelayMs as le } from "../voice/assistantPollSchedule.js";
15
+ import { toCaptionText as ue } from "../voice/captionText.js";
16
+ import { resolveAssistantLanguage as de } from "../voice/languages.js";
17
+ import { resolveLanguagePair as fe } from "../voice/languagePair.js";
18
+ import { INITIAL_TRANSCRIPT_AUTO_OPEN as S, maySendSpokenTurn as pe, planTranscriptAutoOpen as me, planVoiceSessionBinding as he } from "../voice/voiceReopen.js";
19
+ import { beginApprovalInFlight as ge, endApprovalInFlight as _e, getApprovalInFlight as ve, markLiveTurn as ye, newestModelReplyId as be, resolveApprovablePendingWrite as C, resolveRetryableMessageId as xe, subscribeApprovalInFlight as Se } from "../liveTurns.js";
20
+ import { countInlineImageCandidates as Ce, countInlinedImageParts as we, getSendableAttachments as Te, largestInlineCharsPerFile as Ee, resolveAssistantInlineLimits as De, toMessageAttachment as Oe } from "../attachments.js";
21
+ import { AssistantSendRefusal as ke, classifyTurnFailure as Ae, turnOutcomeCopy as je } from "../turnOutcome.js";
22
+ import { createAdminModeAccessGate as Me, resolveAssistantSendModeAfterAccess as Ne } from "../adminModeSendGate.js";
23
+ import { buildBoundedAttachmentTurn as Pe } from "../attachmentTurn.js";
24
+ import { isWriteModeAcknowledged as Fe, writeModeSendRefusalReason as Ie } from "../writeModeConsent.js";
25
+ import { AUTO_READ_MODE as Le, autoCarryOverFor as Re, autoSuggestions as ze, classifyAssistantIntent as Be, escalationToUndo as Ve, isAutoRoutingOffered as He, resolveAutoRoute as Ue } from "../autoRouting.js";
26
+ import { resolveActiveModeSandbox as We, useAssistantStore as w } from "../store.js";
27
+ import { isTurnInFlight as Ge, planAbandonedTurn as Ke, planTurnAbort as qe } from "../turnState.js";
28
+ import { getAssistantDisplayContent as Je } from "../displayContent.js";
29
+ import { NO_FIRST_TEXT as Ye, buildAssistantProgress as Xe, readAheadFor as Ze, snapshotReplyFloor as Qe, startSessionReadAhead as $e, trackFirstText as et } from "../turnProgress.js";
30
+ import { parseToolActivity as tt } from "./AssistantToolActivity.js";
31
+ import { countSpokenTurns as nt, spokenTurnText as rt } from "../spokenTurns.js";
32
+ import { beginTurn as it, describeTurn as T, detectTurnDevice as at, markTurn as E, restartAttempt as ot, turnClockMs as st } from "../turnTimeline.js";
33
+ import { useAssistantSpeech as ct } from "./AssistantSpeechProvider.js";
34
+ import { useVoiceSession as lt } from "./useVoiceSession.js";
35
+ import { getOrganizationId as ut, getWorkspaceId as dt } from "../context.js";
36
+ import { isMultimodalBodyRejection as ft, isRecoverableAssistantError as pt } from "../transportErrors.js";
37
+ import { createReadinessTracker as mt, planAfterTransportFailure as ht, planTrustedSandboxFailure as gt } from "../sandboxReadiness.js";
38
+ import { AssistantSpokenTurnsNotice as _t } from "./AssistantSpokenTurnsNotice.js";
39
+ import { VoiceTranscriptDrawer as vt } from "./voice/VoiceTranscriptDrawer.js";
40
+ import { downloadFile as yt } from "../exportConversation.js";
41
+ import { AssistantEmptyState as bt } from "./AssistantEmptyState.js";
42
+ import { AssistantMessageList as xt } from "./AssistantMessageList.js";
43
+ import { AssistantVoiceSession as St } from "./voice/AssistantVoiceSession.js";
44
+ import { useAssistantApiAccess as Ct } from "../useAssistantApiAccess.js";
45
+ import { useConversationTurns as wt } from "../useConversationTurns.js";
46
+ import { sendAssistantTurnTimings as Tt, startTurnTimingReporting as Et } from "../turnTimingReporter.js";
47
+ import { WarmCancelled as Dt, consumeWarm as Ot, prewarmTarget as kt, settleWarmBeforeSend as At, startWarm as jt, warmState as Mt } from "../prewarm.js";
48
+ import { isAlreadyThere as Nt, matchLocalUiCommand as Pt, navDestinations as Ft, planThemeChange as It } from "../localUiCommands.js";
49
+ import { chooseDestinationCopy as Lt, navigationCommandCopy as Rt, themeCommandCopy as zt } from "../localUiCommandCopy.js";
50
+ import { dispatchAssistantQuotaExhausted as Bt, notifyAiCreditsUpdated as Vt } from "../aiCredits.js";
51
+ import { useAssistantAttachments as Ht } from "../useAssistantAttachments.js";
52
+ import { AssistantComposer as Ut } from "./composer/AssistantComposer.js";
53
+ import { isProdRuntime as Wt } from "../env.js";
54
+ import { AssistantApiCallsConsentDialog as Gt } from "./AssistantApiCallsConsentDialog.js";
55
+ import { useVisibleNavItems as Kt } from "../../../chrome/mobileTabBar/useVisibleNavItems.js";
56
+ import { useCallback as D, useEffect as O, useMemo as qt, useRef as k, useState as Jt, useSyncExternalStore as Yt } from "react";
57
+ import { jsx as A, jsxs as Xt } from "react/jsx-runtime";
55
58
  //#region src/shared/assistant/ui/AssistantChatArea.tsx
56
- var Ft = 600, It = 2e4;
57
- function Lt() {
59
+ var Zt = 600, Qt = 2e4;
60
+ function $t() {
58
61
  return `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
59
62
  }
60
- var Rt = ({ visible: Rt = !0, writeAccess: zt = "unknown" }) => {
61
- let j = i(), { product: M, modes: N, gatherPageContext: Bt, buildPrompt: Vt, reportTokenUsage: Ht, localUiCommands: Ut } = r(), { getAccessToken: P, getWorkspaceToken: F, userId: I } = n(), { locale: L } = t(), Wt = C((e) => e.assistantLanguage), Gt = C((e) => e.replyLanguage), Kt = O(() => de(Wt, Gt, L), [
62
- Wt,
63
- Gt,
63
+ var en = ({ visible: en = !0, writeAccess: tn = "unknown" }) => {
64
+ let j = i(), { product: M, modes: N, gatherPageContext: nn, buildPrompt: rn, reportTurnTimings: an, reportTokenUsage: on, localUiCommands: sn } = r(), { getAccessToken: P, getWorkspaceToken: F, userId: I } = n(), { locale: L } = t(), cn = w((e) => e.assistantLanguage), ln = w((e) => e.replyLanguage), un = qt(() => fe(cn, ln, L), [
65
+ cn,
66
+ ln,
64
67
  L
65
- ]), qt = Kt.reply.english, Jt = Kt.replyIsExplicit, Yt = Kt.reply.code, { conversations: Xt, activeConversationId: R, mode: z, processingByConversationId: Zt, setMode: B, setConversationMode: Qt, setActiveConversation: $t, createConversation: V, addMessage: H, updateMessage: en, patchMessage: tn, mergeMessageMetadata: nn, setConversationProcessing: rn, clearConversationProcessing: an, setBackendSessionId: on, clearBackendSessionId: sn, setSandbox: U, clearSandbox: W, acknowledgedWriteModes: cn, acknowledgeWriteMode: ln, autoRouting: un, setAutoRouting: dn, routeConversation: fn } = C(), pn = Xt.find((e) => e.id === R), mn = ft(pn), hn = mn.all, G = R ? Zt[R] : void 0, gn = Ne(G?.status), _n = gn ? G?.messageId ?? null : null, vn = G?.status === "error" ? G.messageId : null, { canUseApiCalls: yn, loading: bn } = dt(Qe()), K = k(be({
66
- loading: bn,
67
- canUseAdminModes: yn
68
- })).current, xn = k(N);
69
- D(() => {
70
- xn.current = N;
71
- }, [N]), D(() => {
72
- K.update({
73
- loading: bn,
74
- canUseAdminModes: yn
68
+ ]), dn = un.reply.english, fn = un.replyIsExplicit, pn = un.reply.code, { conversations: mn, activeConversationId: R, mode: z, processingByConversationId: hn, setMode: gn, setConversationMode: _n, setActiveConversation: vn, createConversation: B, addMessage: V, updateMessage: yn, patchMessage: bn, mergeMessageMetadata: xn, setConversationProcessing: Sn, clearConversationProcessing: Cn, setBackendSessionId: wn, clearBackendSessionId: Tn, setSandbox: H, clearSandbox: U, acknowledgedWriteModes: En, acknowledgeWriteMode: Dn, autoRouting: On, setAutoRouting: kn, routeConversation: An } = w(), jn = mn.find((e) => e.id === R), Mn = wt(jn), Nn = Mn.all, W = R ? hn[R] : void 0, Pn = Ge(W?.status), Fn = Pn ? W?.messageId ?? null : null, In = W?.status === "error" ? W.messageId : null, { canUseApiCalls: Ln, loading: Rn } = Ct(ut()), G = k(Me({
69
+ loading: Rn,
70
+ canUseAdminModes: Ln
71
+ })).current, zn = k(N);
72
+ O(() => {
73
+ zn.current = N;
74
+ }, [N]);
75
+ let Bn = k(P);
76
+ O(() => {
77
+ Bn.current = P;
78
+ }, [P]);
79
+ let Vn = !!M && an !== !1;
80
+ O(() => {
81
+ if (Vn) return Et({ send: (e) => Tt(e, {
82
+ workspaceId: dt(),
83
+ authContext: {
84
+ accessToken: Bn.current(),
85
+ organizationId: ut()
86
+ }
87
+ }) });
88
+ }, [Vn]), O(() => {
89
+ G.update({
90
+ loading: Rn,
91
+ canUseAdminModes: Ln
75
92
  });
76
93
  }, [
77
- K,
78
- bn,
79
- yn
80
- ]), D(() => () => {
81
- K.abandon();
82
- }, [K]);
83
- let Sn = O(() => N.filter((e) => !e.requiresAdmin || yn), [N, yn]), Cn = Ae(Sn), wn = un && Cn, Tn = k(Cn);
84
- D(() => {
85
- Tn.current = Cn;
86
- }, [Cn]);
87
- let En = k(null), Dn = he(N), [On, kn] = Nt(null), [An, jn] = Nt(!1), Mn = k({}), q = k(nt()), J = k(/* @__PURE__ */ new Set()), Nn = k(/* @__PURE__ */ new Set()), Y = O(() => N.find((e) => e.id === z), [N, z]), Pn = z === "assistant" || Y !== void 0 && !Y.writeCapable && !h(z);
88
- D(() => {
89
- if (z !== "assistant" && Y?.writeCapable && !Ce(cn, z)) {
90
- B("assistant");
94
+ G,
95
+ Rn,
96
+ Ln
97
+ ]), O(() => () => {
98
+ G.abandon();
99
+ }, [G]);
100
+ let Hn = qt(() => N.filter((e) => !e.requiresAdmin || Ln), [N, Ln]), Un = He(Hn), Wn = On && Un, Gn = k(Un);
101
+ O(() => {
102
+ Gn.current = Un;
103
+ }, [Un]);
104
+ let Kn = k(null), qn = Ee(N), [Jn, Yn] = Jt(null), [Xn, Zn] = Jt(null), Qn = Xn !== null && Xn === R, K = D((e) => {
105
+ Zn(e ? w.getState().activeConversationId : null);
106
+ }, []);
107
+ O(() => {
108
+ Zn((e) => e !== null && e !== R ? null : e);
109
+ }, [R]);
110
+ let $n = k(void 0), er = k({}), q = k(mt()), J = k(/* @__PURE__ */ new Set()), tr = k(/* @__PURE__ */ new Set()), Y = qt(() => N.find((e) => e.id === z), [N, z]), nr = z === "assistant" || Y !== void 0 && !Y.writeCapable && !m(z);
111
+ O(() => {
112
+ if (z !== "assistant" && Y?.writeCapable && !Fe(En, z)) {
113
+ gn("assistant");
91
114
  return;
92
115
  }
93
- bn || (!Y || Y.requiresAdmin && !yn) && z !== "assistant" && B("assistant");
116
+ Rn || (!Y || Y.requiresAdmin && !Ln) && z !== "assistant" && gn("assistant");
94
117
  }, [
95
118
  z,
96
119
  Y,
97
- yn,
98
- bn,
99
- B,
100
- cn
120
+ Ln,
121
+ Rn,
122
+ gn,
123
+ En
101
124
  ]);
102
- let Fn = E((e, t, n, r) => {
103
- rn(e, n, t, null, r);
104
- }, [rn]), In = E(async (e, t, n, r, i, a = null) => {
125
+ let rr = D((e, t, n, r) => {
126
+ Sn(e, n, t, null, r);
127
+ }, [Sn]), ir = D(async (e, t, n, r, i, a = null) => {
105
128
  let s = (e, t) => {
106
- r && Fn(r.conversationId, r.assistantMessageId, e, t), a && (a.step = t, a.onStep?.(t));
129
+ r && rr(r.conversationId, r.assistantMessageId, e, t), a && (a.step = t, a.onStep?.(t));
107
130
  }, c = (e) => {
108
- r && T(r.assistantMessageId, e);
109
- }, u = () => a !== null && (a.signal.aborted || $e() !== t), d = () => {
110
- if (u()) throw new pt("cancelled");
111
- }, p = C.getState().sandboxesByMode[e]?.sandboxId ?? null, ee = !1, m = !1, h = !1, te = !1, g = !1, re = async (r) => {
112
- if (i && !J.current.has(r) && q.current.isFresh(r)) return ee = !0, !0;
113
- h = !0;
131
+ r && E(r.assistantMessageId, e);
132
+ }, u = () => {
133
+ c("bootAdopted"), a?.beginBoot();
134
+ }, ee = () => a !== null && (a.signal.aborted || dt() !== t), d = () => {
135
+ if (ee()) throw new Dt("cancelled");
136
+ }, f = w.getState().sandboxesByMode[e]?.sandboxId ?? null, p = !1, m = !1, ne = !1, g = !1, ie = !1, ae = async (r) => {
137
+ if (i && !J.current.has(r) && q.current.isFresh(r)) return p = !0, !0;
138
+ ne = !0;
114
139
  let o = !1;
115
140
  try {
116
- await v(r, t, n, 3e5), await _(r, t, e, n, 9e4, () => {
117
- o = !0;
141
+ await re(r, t, n, 3e5), await _(r, t, e, n, 9e4, () => {
142
+ o = !0, u();
118
143
  });
119
144
  } catch {
120
- if (u()) throw new pt("cancelled");
121
- return q.current.invalidate(r), J.current.add(r), a?.dead.push(r), g = !0, !1;
145
+ if (ee()) throw new Dt("cancelled");
146
+ return q.current.invalidate(r), J.current.add(r), a?.dead.push(r), ie = !0, !1;
122
147
  }
123
- return d(), q.current.markVerified(r), o && (te = !0), !0;
148
+ return d(), q.current.markVerified(r), o && (g = !0), !0;
124
149
  };
125
- if (p && (U(e, p, "provisioning"), s("provisioning", "reusingEnvironment"), await re(p) || (U(e, null, "provisioning"), p = null)), !p) {
150
+ if (f && (H(e, f, "provisioning"), s("provisioning", "reusingEnvironment"), await ae(f) || (H(e, null, "provisioning"), f = null)), !f) {
126
151
  s("provisioning", "lookingForEnvironment");
127
- let r = await f(t, M, e, At(), n, J.current);
152
+ let r = await te(t, M, e, Wt(), n, J.current);
128
153
  d();
129
154
  let i = r?.id ?? null;
130
- i && (U(e, i, "provisioning"), s("provisioning", "reusingEnvironment"), await re(i) ? (p = i, (r?.status === "PROVISIONING" || r?.status === "PENDING") && (te = !0)) : U(e, null, "provisioning"));
155
+ if (i) {
156
+ H(e, i, "provisioning"), s("provisioning", "reusingEnvironment");
157
+ let t = r?.status === "PROVISIONING" || r?.status === "PENDING";
158
+ t && u(), await ae(i) ? (f = i, t && (g = !0)) : H(e, null, "provisioning");
159
+ }
131
160
  }
132
- if (!p) {
133
- if (a && !a.mayCreate) throw new pt("no-create");
161
+ if (!f) {
162
+ if (a && !a.mayCreate) throw new Dt("no-create");
134
163
  if (c("provisionStarted"), e === "api-calls" && !P()) throw Error("API Calls mode requires an authenticated session. Please sign in again.");
135
- s("provisioning", "startingEnvironment"), U(e, null, "provisioning");
136
- let r = a ? [] : await ne(t, M, e, At(), n, J.current);
164
+ s("provisioning", "startingEnvironment"), H(e, null, "provisioning");
165
+ let r = a ? [] : await h(t, M, e, Wt(), n, J.current);
137
166
  if (r.length > 0) {
138
167
  let e = new Set(r);
139
168
  for (let e of r) q.current.invalidate(e), J.current.add(e);
140
- let t = C.getState().sandboxesByMode;
141
- for (let [n, r] of Object.entries(t)) o(n) && r?.sandboxId && e.has(r.sandboxId) && W(n);
169
+ let t = w.getState().sandboxesByMode;
170
+ for (let [n, r] of Object.entries(t)) o(n) && r?.sandboxId && e.has(r.sandboxId) && U(n);
142
171
  }
143
172
  c("createRequested");
144
173
  let i = a?.beginCreate();
145
174
  try {
146
- p = await l(M, e, t, At(), Ft, n);
175
+ f = await l(M, e, t, Wt(), Zt, n);
147
176
  } finally {
148
177
  i?.();
149
178
  }
150
- m = !0, d(), U(e, p, "provisioning"), await v(p, t, n, 3e5), d(), c("sandboxRunning"), await _(p, t, e, n, 9e4), d(), c("serviceReady"), q.current.markVerified(p);
179
+ m = !0, d(), H(e, f, "provisioning"), await re(f, t, n, 3e5), d(), c("sandboxRunning"), await _(f, t, e, n, 9e4), d(), c("serviceReady"), q.current.markVerified(f);
151
180
  }
152
- return U(e, p, "running"), {
153
- sandboxId: p,
181
+ return H(e, f, "running"), {
182
+ sandboxId: f,
154
183
  sandboxIsNew: m,
155
- sandboxProbed: h,
156
- sandboxAdopted: te,
157
- deadSandboxProbe: g,
158
- trustedFromCache: ee
184
+ sandboxProbed: ne,
185
+ sandboxAdopted: g,
186
+ deadSandboxProbe: ie,
187
+ trustedFromCache: p
159
188
  };
160
189
  }, [
161
- W,
190
+ U,
162
191
  P,
163
192
  M,
164
- U,
165
- Fn
166
- ]), Ln = E(async function e(t, n, r, i, a, o = {}) {
167
- let s = await gt(i, r, (e) => Fn(t, n, "provisioning", e));
193
+ H,
194
+ rr
195
+ ]), ar = D(async function e(t, n, r, i, a, o = {}) {
196
+ let s = await At(i, r, (e) => rr(t, n, "provisioning", e), () => E(n, "prewarmJoined"));
168
197
  for (let e of s.dead) q.current.invalidate(e), J.current.add(e);
169
- s.verified && !J.current.has(s.verified) && q.current.markVerified(s.verified), s.joined && w(n, { prewarm: s.joined });
170
- let { sandboxId: c, sandboxIsNew: l, sandboxProbed: d, sandboxAdopted: p, deadSandboxProbe: h, trustedFromCache: te } = await In(r, i, a, {
198
+ s.verified && !J.current.has(s.verified) && q.current.markVerified(s.verified), s.joined && T(n, { prewarm: s.joined });
199
+ let { sandboxId: c, sandboxIsNew: l, sandboxProbed: ee, sandboxAdopted: d, deadSandboxProbe: m, trustedFromCache: ne } = await ir(r, i, a, {
171
200
  conversationId: t,
172
201
  assistantMessageId: n
173
- }, o.trustCache !== !1), ne = mt(i, r, c);
174
- !s.joined && ne && w(n, { prewarm: "hit" });
175
- let g = C.getState().conversations.find((e) => e.id === t)?.backendSessionId ?? null, _ = !1, v = null;
202
+ }, o.trustCache !== !1), h = Ot(i, r, c);
203
+ !s.waited && h && T(n, { prewarm: "hit" });
204
+ let g = w.getState().conversations.find((e) => e.id === t)?.backendSessionId ?? null, _ = !1, re = null;
176
205
  if (g) {
177
- let e = Ve(c, g, (e, t) => ee(e, i, t, r, a, { limit: 50 }));
206
+ let e = $e(c, g, (e, t) => f(e, i, t, r, a, { limit: 50 }));
178
207
  try {
179
- let t = await m(c, i, g, r, a);
208
+ let t = await p(c, i, g, r, a);
180
209
  if (t.mode !== r) throw Error(`Session mode mismatch: expected ${r}, received ${t.mode}`);
181
- v = e;
210
+ re = e;
182
211
  } catch {
183
- sn(t), g = null;
212
+ Tn(t), g = null;
184
213
  }
185
214
  }
186
215
  if (!g) {
187
- Fn(t, n, "connecting", "preparingSession");
216
+ rr(t, n, "connecting", "preparingSession");
188
217
  let s;
189
218
  try {
190
219
  s = await u(c, i, r, a);
191
220
  } catch (s) {
192
- if (te) {
221
+ if (ne) {
193
222
  q.current.invalidate(c);
194
- let l = it(s, o.isAbandoned?.() ?? !1), u = l === "check-network";
195
- if (l === "check-network" && (l = await rt(() => f(i, M, r, At(), a, J.current))), l !== "rethrow" && o.isAbandoned?.() && (l = "rethrow"), l !== "rethrow") {
196
- u || w(n, { cacheProofFailed: !0 }), l === "replace" && (J.current.add(c), sn(t), W(r));
223
+ let l = gt(s, o.isAbandoned?.() ?? !1), u = l === "check-network";
224
+ if (l === "check-network" && (l = await ht(() => te(i, M, r, Wt(), a, J.current))), l !== "rethrow" && o.isAbandoned?.() && (l = "rethrow"), l !== "rethrow") {
225
+ u || T(n, { cacheProofFailed: !0 }), l === "replace" && (J.current.add(c), Tn(t), U(r));
197
226
  let s = await e(t, n, r, i, a, {
198
227
  ...o,
199
228
  trustCache: !1
200
229
  });
201
- return u && (s.deadSandboxProbe || s.sandboxId !== c) && w(n, { cacheProofFailed: !0 }), {
230
+ return u && (s.deadSandboxProbe || s.sandboxId !== c) && T(n, { cacheProofFailed: !0 }), {
202
231
  ...s,
203
- sandboxProbed: s.sandboxProbed || d,
204
- sandboxAdopted: s.sandboxAdopted || p,
205
- deadSandboxProbe: s.deadSandboxProbe || h
232
+ sandboxProbed: s.sandboxProbed || ee,
233
+ sandboxAdopted: s.sandboxAdopted || d,
234
+ deadSandboxProbe: s.deadSandboxProbe || m
206
235
  };
207
236
  }
208
237
  }
209
238
  throw s;
210
239
  }
211
- g = s.sessionId, on(t, g), _ = !0;
240
+ g = s.sessionId, wn(t, g), _ = !0;
212
241
  }
213
242
  return {
214
243
  sandboxId: c,
215
244
  sessionId: g,
216
245
  sessionIsNew: _,
217
- readAhead: v,
246
+ readAhead: re,
218
247
  sandboxIsNew: l,
219
- sandboxProbed: d,
220
- sandboxAdopted: p,
221
- deadSandboxProbe: h
248
+ sandboxProbed: ee,
249
+ sandboxAdopted: d,
250
+ deadSandboxProbe: m
222
251
  };
223
252
  }, [
224
- In,
225
- sn,
226
- W,
253
+ ir,
254
+ Tn,
255
+ U,
227
256
  M,
228
- on,
229
- Fn
230
- ]), Rn = E((e) => {
231
- let t = $e();
257
+ wn,
258
+ rr
259
+ ]), or = D((e) => {
260
+ let t = dt();
232
261
  if (!t) return;
233
- let n = C.getState(), r = Date.now(), i = ht({
262
+ let n = w.getState(), r = Date.now(), i = kt({
234
263
  autoRouting: n.autoRouting,
235
- autoOffered: Tn.current,
264
+ autoOffered: Gn.current,
236
265
  active: n.activeConversationId ? n.conversations.find((e) => e.id === n.activeConversationId) : void 0,
237
266
  selectedMode: n.mode,
238
- autoReadMode: Te,
239
- modes: xn.current,
267
+ autoReadMode: Le,
268
+ modes: zn.current,
240
269
  acknowledgedWriteModes: n.acknowledgedWriteModes,
241
- adminAccess: K.read(),
270
+ adminAccess: G.read(),
242
271
  dictated: e,
243
- turnInFlight: Object.values(n.processingByConversationId).some((e) => Ne(e?.status)),
244
- ...vt(t),
272
+ turnInFlight: Object.values(n.processingByConversationId).some((e) => Ge(e?.status)),
273
+ ...Mt(t),
245
274
  now: r
246
275
  });
247
276
  if (!i) return;
248
- let a = _t(t, i, r), o = {
277
+ let a = jt(t, i, r), o = {
249
278
  accessToken: P(),
250
279
  workspaceToken: F(),
251
280
  userId: I,
252
- organizationId: Qe()
281
+ organizationId: ut()
253
282
  };
254
- In(i.mode, t, o, null, !0, a).then((e) => a.finish({
283
+ ir(i.mode, t, o, null, !0, a).then((e) => a.finish({
255
284
  ok: !0,
256
285
  sandboxId: e.sandboxId,
257
286
  didWork: !e.trustedFromCache && (e.sandboxIsNew || e.sandboxProbed || e.sandboxAdopted),
287
+ booted: e.sandboxIsNew || e.sandboxAdopted,
258
288
  dead: a.dead
259
289
  }), (e) => {
260
- if (!(e instanceof pt) && !a.signal.aborted && $e() === t) {
261
- let e = C.getState().sandboxesByMode[i.mode]?.sandboxId ?? null;
262
- e && (q.current.invalidate(e), J.current.add(e), a.dead.push(e), W(i.mode));
290
+ if (!(e instanceof Dt) && !a.signal.aborted && dt() === t) {
291
+ let e = w.getState().sandboxesByMode[i.mode]?.sandboxId ?? null;
292
+ e && (q.current.invalidate(e), J.current.add(e), a.dead.push(e), U(i.mode));
263
293
  }
264
294
  a.finish({
265
295
  ok: !1,
266
296
  didWork: !1,
297
+ booted: !1,
267
298
  dead: a.dead
268
299
  });
269
300
  });
270
301
  }, [
271
- In,
272
- K,
273
- W,
302
+ ir,
303
+ G,
304
+ U,
274
305
  P,
275
306
  F,
276
307
  I
277
- ]), zn = E(() => Rn(!1), [Rn]), [Bn, Vn] = Nt(null), Hn = k(/* @__PURE__ */ new Set()), Un = k(null), Wn = E(() => {
278
- let e = C.getState(), t = e.activeConversationId;
308
+ ]), sr = D(() => or(!1), [or]), cr = Yt(Se, ve, ve)?.reference ?? null, [lr, ur] = Jt(0), dr = k(/* @__PURE__ */ new Set()), fr = k(null), pr = D(() => {
309
+ let e = w.getState(), t = e.activeConversationId;
279
310
  if (!t) return;
280
- let n = e.processingByConversationId[t], r = Ne(n?.status) ? n?.messageId ?? null : null;
281
- if (!Fe({
311
+ let n = e.processingByConversationId[t], r = Ge(n?.status) ? n?.messageId ?? null : null;
312
+ if (!qe({
282
313
  interruptedTurnId: r,
283
314
  activeTurnId: r,
284
- alreadyRequested: r ? Hn.current.has(r) : !1
315
+ alreadyRequested: r ? dr.current.has(r) : !1
285
316
  }).send || !r) return;
286
- Hn.current.add(r);
287
- let i = Me(e), a = $e(), o = e.conversations.find((e) => e.id === t)?.backendSessionId;
317
+ dr.current.add(r);
318
+ let i = We(e), a = dt(), o = e.conversations.find((e) => e.id === t)?.backendSessionId;
288
319
  !i || !a || !o || s(i.sandboxId, a, o, i.mode, {
289
320
  accessToken: P(),
290
321
  workspaceToken: F(),
291
322
  userId: I,
292
- organizationId: Qe()
323
+ organizationId: ut()
293
324
  });
294
325
  }, [
295
326
  I,
296
327
  P,
297
328
  F
298
- ]), Gn = E(async (e) => {
299
- let t = C.getState(), n = Me(t), r = $e(), i = t.activeConversationId;
300
- if (!(!n || !r || !i)) {
301
- Vn(e);
302
- try {
303
- await c(n.sandboxId, r, e, n.mode, {
304
- accessToken: P(),
305
- workspaceToken: F(),
306
- userId: I,
307
- organizationId: Qe()
308
- });
309
- } catch (e) {
310
- Vn(null), H(i, {
311
- id: Lt(),
312
- role: "system",
313
- content: e instanceof Error ? e.message : "The change could not be approved.",
314
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
315
- });
316
- return;
317
- }
318
- Vn(null), er.current(j("pendingWrite.approvedPrompt", "I approved that change — go ahead."));
329
+ ]), mr = D(async (e) => {
330
+ let t = w.getState(), n = We(t), r = dt(), i = t.activeConversationId;
331
+ if (!n || !r || !i) return;
332
+ let a = t.conversations.find((e) => e.id === i), o = a ? C(v(a.messages), {
333
+ sessionId: a.backendSessionId,
334
+ sandboxId: n.sandboxId,
335
+ nowMs: Date.now()
336
+ }) : null;
337
+ if (o?.reference !== e) {
338
+ ur((e) => e + 1);
339
+ return;
319
340
  }
341
+ let s = {
342
+ conversationId: i,
343
+ reference: e
344
+ };
345
+ if (!ge(s)) return;
346
+ try {
347
+ await c(n.sandboxId, r, e, n.mode, {
348
+ accessToken: P(),
349
+ workspaceToken: F(),
350
+ userId: I,
351
+ organizationId: ut()
352
+ });
353
+ } catch (e) {
354
+ _e(s), V(i, {
355
+ id: $t(),
356
+ role: "system",
357
+ content: e instanceof Error ? e.message : "The change could not be approved.",
358
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
359
+ });
360
+ return;
361
+ }
362
+ _e(s), xn(i, o.messageId, { pendingWriteApprovedAt: (/* @__PURE__ */ new Date()).toISOString() });
363
+ let l = w.getState(), u = l.conversations.find((e) => e.id === i);
364
+ l.activeConversationId !== i || !u || l.mode !== n.mode || u.backendSessionId !== a?.backendSessionId || We(l)?.sandboxId !== n.sandboxId || Ge(l.processingByConversationId[i]?.status) || be(v(u.messages)) !== o.messageId || Cr.current(j("pendingWrite.approvedPrompt", "I approved that change — go ahead."), [], {
365
+ approvalFollowUp: { approvedReplyId: o.messageId },
366
+ targetConversationId: i
367
+ });
320
368
  }, [
321
369
  I,
322
- H,
370
+ V,
371
+ xn,
323
372
  j
324
- ]), Kn = e(), { speakFinishedReply: qn } = Xe(), Jn = a(), { items: Yn } = Mt(), Xn = k({
325
- theme: Kn,
326
- navigate: Jn,
327
- navItems: Yn,
328
- options: Ut ?? {}
373
+ ]), hr = e(), { speakFinishedReply: gr } = ct(), _r = a(), { items: vr } = Kt(), yr = k({
374
+ theme: hr,
375
+ navigate: _r,
376
+ navItems: vr,
377
+ options: sn ?? {}
329
378
  });
330
- D(() => {
331
- Xn.current = {
332
- theme: Kn,
333
- navigate: Jn,
334
- navItems: Yn,
335
- options: Ut ?? {}
379
+ O(() => {
380
+ yr.current = {
381
+ theme: hr,
382
+ navigate: _r,
383
+ navItems: vr,
384
+ options: sn ?? {}
336
385
  };
337
386
  }, [
338
- Kn,
339
- Jn,
340
- Yn,
341
- Ut
387
+ hr,
388
+ _r,
389
+ vr,
390
+ sn
342
391
  ]);
343
- let Zn = E((e, t, n) => {
344
- let { theme: r, navigate: i } = Xn.current, a, o;
392
+ let br = D((e, t, n) => {
393
+ let { theme: r, navigate: i } = yr.current, a, o;
345
394
  if (e.kind === "theme") {
346
395
  if (!r) return !1;
347
- let t = St(e.request, {
396
+ let t = It(e.request, {
348
397
  mode: r.mode,
349
398
  resolvedTheme: r.resolvedTheme
350
399
  });
351
400
  if (!t.alreadyApplied) try {
352
401
  r.setMode(t.mode);
353
402
  } catch {}
354
- a = Tt(j, t, e.request.kind === "family"), o = {
403
+ a = zt(j, t, e.request.kind === "family"), o = {
355
404
  kind: "theme",
356
405
  mode: t.mode,
357
406
  alreadyApplied: t.alreadyApplied
@@ -359,31 +408,31 @@ var Rt = ({ visible: Rt = !0, writeAccess: zt = "unknown" }) => {
359
408
  } else {
360
409
  if (!i) return !1;
361
410
  if (e.kind === "navigate") {
362
- let { destination: t } = e, n = yt(t, window.location.pathname + window.location.search, xt(Xn.current.navItems));
363
- n || i(t.path), a = wt(j, t.label, n), o = {
411
+ let { destination: t } = e, n = Nt(t, window.location.pathname + window.location.search, Ft(yr.current.navItems));
412
+ n || i(t.path), a = Rt(j, t.label, n), o = {
364
413
  kind: "navigate",
365
414
  destinationId: t.id,
366
415
  path: t.path,
367
416
  alreadyHere: n
368
417
  };
369
- } else a = Ct(j, e.candidates[0]?.label ?? e.query, e.candidates), o = {
418
+ } else a = Lt(j, e.candidates[0]?.label ?? e.query, e.candidates), o = {
370
419
  kind: "choose-destination",
371
420
  candidateIds: e.candidates.map((e) => e.id)
372
421
  };
373
422
  }
374
- let s = C.getState(), c = s.activeConversationId ?? V(void 0, s.autoRouting && Tn.current ? "assistant" : s.mode, s.autoRouting ? { routedBy: "auto" } : void 0), l = (/* @__PURE__ */ new Date()).toISOString();
375
- H(c, {
376
- id: Lt(),
423
+ let s = w.getState(), c = s.activeConversationId ?? B(void 0, s.autoRouting && Gn.current ? "assistant" : s.mode, s.autoRouting ? { routedBy: "auto" } : void 0), l = (/* @__PURE__ */ new Date()).toISOString();
424
+ V(c, {
425
+ id: $t(),
377
426
  role: "user",
378
427
  content: t,
379
428
  timestamp: l,
380
429
  metadata: {
381
430
  localAction: o,
382
- ...y(n)
431
+ ...oe(n)
383
432
  }
384
433
  });
385
- let u = Lt();
386
- return H(c, {
434
+ let u = $t();
435
+ return V(c, {
387
436
  id: u,
388
437
  role: "assistant",
389
438
  content: a.text,
@@ -391,21 +440,21 @@ var Rt = ({ visible: Rt = !0, writeAccess: zt = "unknown" }) => {
391
440
  metadata: {
392
441
  lang: a.translated ? L : "en",
393
442
  localAction: o,
394
- ...y(n)
443
+ ...oe(n)
395
444
  }
396
- }), qn(c, u), !0;
445
+ }), gr(c, u), !0;
397
446
  }, [
398
- H,
399
447
  V,
448
+ B,
400
449
  L,
401
- qn,
450
+ gr,
402
451
  j
403
- ]), X = E(async (e, t = [], n = {}) => {
404
- let r = n.voiceSessionId !== void 0, i = C.getState(), a = i.activeConversationId ?? R;
452
+ ]), X = D(async (e, t = [], n = {}) => {
453
+ let r = n.voiceSessionId !== void 0, i = w.getState(), a = i.activeConversationId ?? R;
405
454
  if (a) {
406
- if (Ne(i.processingByConversationId[a]?.status)) {
455
+ if (Ge(i.processingByConversationId[a]?.status)) {
407
456
  let r = i.processingByConversationId[a]?.messageId ?? null;
408
- r && Hn.current.has(r) && (Un.current = {
457
+ r && dr.current.has(r) && (fr.current = {
409
458
  conversationId: a,
410
459
  content: e,
411
460
  attachments: t,
@@ -413,272 +462,311 @@ var Rt = ({ visible: Rt = !0, writeAccess: zt = "unknown" }) => {
413
462
  });
414
463
  return;
415
464
  }
416
- if (Nn.current.has(a)) return;
465
+ if (tr.current.has(a)) return;
466
+ }
467
+ if (Kn.current || ve() !== null) return;
468
+ let o = n.targetConversationId;
469
+ if (o !== void 0) {
470
+ let e = i.conversations.find((e) => e.id === o);
471
+ if (i.activeConversationId !== o || !e || e.mode !== i.mode) return;
417
472
  }
418
- if (En.current) return;
419
473
  if (n.fromPerson && t.length === 0) {
420
- let t = bt(e, xt(Xn.current.navItems), Xn.current.options);
421
- if (t && Zn(t, e, n.voiceSessionId)) return;
474
+ let t = Pt(e, Ft(yr.current.navItems), yr.current.options);
475
+ if (t && br(t, e, n.voiceSessionId)) return;
422
476
  }
423
- let o = i.activeConversationId ? i.conversations.find((e) => e.id === i.activeConversationId) : void 0, s = i.autoRouting && Tn.current ? je({
424
- intent: n.autoIntent ?? Oe(e),
477
+ let c = i.activeConversationId ? i.conversations.find((e) => e.id === i.activeConversationId) : void 0, l = i.autoRouting && Gn.current && o === void 0 ? Ue({
478
+ intent: n.autoIntent ?? Be(e),
425
479
  dictated: r,
426
- conversation: o ? {
427
- mode: o.mode,
428
- routedBy: o.routedBy,
429
- hasHistory: o.messages.length > 0 || !!o.backendSessionId
480
+ conversation: c ? {
481
+ mode: c.mode,
482
+ routedBy: c.routedBy,
483
+ hasHistory: c.messages.length > 0 || !!c.backendSessionId
430
484
  } : null
431
485
  }) : null;
432
- if (s && xn.current.find((e) => e.id === s.mode)?.writeCapable && !Ce(i.acknowledgedWriteModes, s.mode)) {
433
- En.current = {
486
+ if (l && zn.current.find((e) => e.id === l.mode)?.writeCapable && !Fe(i.acknowledgedWriteModes, l.mode)) {
487
+ Kn.current = {
434
488
  content: e,
435
489
  attachments: t,
436
490
  options: n
437
- }, kn(s.mode);
491
+ }, Yn(l.mode);
438
492
  return;
439
493
  }
440
- let c = s ? s.mode : i.mode, l, u, f = R, m = f ? C.getState().conversations.find((e) => e.id === f) : void 0, ne = s?.action === "escalate" && o ? {
441
- mode: o.mode,
442
- backendSessionId: o.backendSessionId ?? null
494
+ let u = l ? l.mode : i.mode, te, p, h = o ?? R, _ = h ? w.getState().conversations.find((e) => e.id === h) : void 0, re = l?.action === "escalate" && c ? {
495
+ mode: c.mode,
496
+ backendSessionId: c.backendSessionId ?? null
443
497
  } : null;
444
- if (s) s.action === "new" || !o ? f = V(void 0, c, { routedBy: "auto" }) : (f = o.id, fn(f, c));
498
+ if (l) l.action === "new" || !c ? h = B(void 0, u, { routedBy: "auto" }) : (h = c.id, An(h, u));
445
499
  else {
446
500
  let e = i.autoRouting ? { routedBy: "auto" } : void 0;
447
- f ? m && m.mode !== c && (m.messages.length > 0 || m.backendSessionId) ? f = V(void 0, c, e) : m && m.mode !== c && (e ? fn(f, c) : Qt(f, c)) : f = V(void 0, c, e);
501
+ h ? _ && _.mode !== u && (_.messages.length > 0 || _.backendSessionId) ? h = B(void 0, u, e) : _ && _.mode !== u && (e ? An(h, u) : _n(h, u)) : h = B(void 0, u, e);
448
502
  }
449
- if (!f) return;
450
- Mn.current[f] = t;
451
- let _ = $e(), v = {
503
+ if (!h) return;
504
+ r && $n.current !== void 0 && h !== i.activeConversationId && ($n.current = h), n.approvalFollowUp || (er.current[h] = t);
505
+ let v = () => w.getState().conversations.some((e) => e.id === h), y = dt(), b = {
452
506
  accessToken: P(),
453
507
  workspaceToken: F(),
454
508
  userId: I,
455
- organizationId: Qe()
456
- }, ae = {
457
- id: Lt(),
509
+ organizationId: ut()
510
+ }, se = (e, t) => {
511
+ v() || !y || s(e, y, t, u, {
512
+ accessToken: P(),
513
+ workspaceToken: F(),
514
+ userId: I,
515
+ organizationId: ut()
516
+ });
517
+ }, ce = {
518
+ id: $t(),
458
519
  role: "user",
459
520
  content: e,
460
521
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
461
522
  metadata: {
462
- ...t.length ? { attachments: t.map(_e) } : {},
463
- ...y(n.voiceSessionId)
523
+ ...t.length ? { attachments: t.map(Oe) } : {},
524
+ ...n.approvalFollowUp ? {
525
+ approvalFollowUp: !0,
526
+ approvedReplyId: n.approvalFollowUp.approvedReplyId
527
+ } : {},
528
+ ...oe(n.voiceSessionId)
464
529
  }
465
530
  };
466
- H(f, ae);
467
- let b = Lt();
468
- H(f, {
469
- id: b,
531
+ V(h, ce);
532
+ let x = $t();
533
+ V(h, {
534
+ id: x,
470
535
  role: "assistant",
471
536
  content: "",
472
537
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
473
538
  metadata: {
474
- lang: Yt,
475
- ...y(n.voiceSessionId)
539
+ lang: pn,
540
+ ...oe(n.voiceSessionId)
476
541
  }
477
- }), Ke(b, {
542
+ }), it(x, {
478
543
  channel: r ? "voice" : "chat",
479
- mode: c,
544
+ mode: u,
480
545
  product: M,
481
- language: Yt,
482
- device: qe(),
483
- routedByAuto: !!s
484
- }, n.voiceTiming), T(b, "accepted"), rn(f, "provisioning", b, null);
485
- let oe = (e, t, r, i, a = Yt) => {
486
- tn(f, b, { content: re(e) }), nn(f, b, {
487
- lang: a,
546
+ language: pn,
547
+ device: at(),
548
+ routedByAuto: !!l
549
+ }, n.voiceTiming), E(x, "accepted"), Sn(h, "provisioning", x, null), ye(x);
550
+ let ue = () => Ke({
551
+ turnId: x,
552
+ abortRequested: dr.current.has(x),
553
+ activeTurnId: w.getState().processingByConversationId[h]?.messageId ?? null,
554
+ conversationExists: v()
555
+ }), de = (e, t, r, i, a = !1, o = pn) => {
556
+ bn(h, x, { content: ie(e) }), xn(h, x, {
557
+ lang: o,
488
558
  ...t?.length ? { artifacts: t } : {},
489
- ...t?.length || r || i ? { mode: c } : {},
559
+ ...t?.length || r || i ? { mode: u } : {},
490
560
  ...r ? { sessionId: r } : {},
491
561
  ...i ? { sandboxId: i } : {},
492
- ...y(n.voiceSessionId)
562
+ ...a ? { incomplete: !0 } : {},
563
+ ...oe(n.voiceSessionId)
493
564
  });
494
- }, se = async (n = 1) => {
495
- T(b, "attemptStarted");
496
- let i = null, a = !1;
565
+ }, fe = async (n = 1) => {
566
+ E(x, "attemptStarted");
567
+ let i = null, a = null, o = !1;
497
568
  try {
498
- let { sandboxId: n, sessionId: o, sessionIsNew: s, readAhead: m, sandboxIsNew: h, sandboxProbed: ne, sandboxAdopted: ae, deadSandboxProbe: y } = await Ln(f, b, c, _, v, { isAbandoned: () => Pe({
499
- turnId: b,
500
- abortRequested: Hn.current.has(b),
501
- activeTurnId: C.getState().processingByConversationId[f]?.messageId ?? null
569
+ let { sandboxId: n, sessionId: s, sessionIsNew: c, readAhead: l, sandboxIsNew: m, sandboxProbed: _, sandboxAdopted: re, deadSandboxProbe: oe } = await ar(h, x, u, y, b, { isAbandoned: () => Ke({
570
+ turnId: x,
571
+ abortRequested: dr.current.has(x),
572
+ activeTurnId: w.getState().processingByConversationId[h]?.messageId ?? null,
573
+ conversationExists: v()
502
574
  }).abandon });
503
- i = n, T(b, "runtimeReady"), w(b, {
504
- runtime: h ? "cold" : ae ? "adopted" : ne ? "probed" : s ? "new-session" : "warm",
505
- deadSandboxProbe: y
506
- });
507
- let se = Ee(C.getState().conversations.find((e) => e.id === f), e, s), x = await Be(() => ee(n, _, o, c, v, { limit: 50 }), s, ze(m, n, o));
508
- Fn(f, b, "streaming", "thinking");
509
- let le = Bt?.(), { prompt: ue, parts: de } = Se({
510
- content: se ? `${se}${e}` : e,
575
+ i = n, E(x, "runtimeReady"), T(x, {
576
+ runtime: m ? "cold" : re ? "adopted" : _ ? "probed" : c ? "new-session" : "warm",
577
+ deadSandboxProbe: oe
578
+ }), a = s;
579
+ let ce = Re(w.getState().conversations.find((e) => e.id === h), e, c), fe = await Qe(() => f(n, y, s, u, b, { limit: 50 }), c, Ze(l, n, s));
580
+ rr(h, x, "streaming", "thinking");
581
+ let S = nn?.(), { prompt: pe, parts: me } = Pe({
582
+ content: ce ? `${ce}${e}` : e,
511
583
  attachments: t,
512
- limits: ge(l),
513
- wrapPrompt: (e) => Vt?.(c, e, qt, Jt, r) ?? e,
514
- requestBytes: (e, t) => te({
584
+ limits: De(te),
585
+ wrapPrompt: (e) => rn?.(u, e, dn, fn, r) ?? e,
586
+ requestBytes: (e, t) => ne({
515
587
  sandboxId: n,
516
- workspaceId: _,
517
- sessionId: o,
518
- mode: c,
588
+ workspaceId: y,
589
+ sessionId: s,
590
+ mode: u,
519
591
  prompt: e,
520
592
  parts: t,
521
- pageContext: le,
522
- authContext: v
593
+ pageContext: S,
594
+ authContext: b
523
595
  })
524
- }), me = pe(de), he = me > 0;
525
- a = fe(t) > me;
596
+ }), he = we(me), ge = he > 0;
597
+ o = Ce(t) > he;
598
+ let _e = ue();
599
+ if (_e.abandon) {
600
+ _e.clearProcessing && Cn(h);
601
+ return;
602
+ }
526
603
  try {
527
- await g(n, _, o, ue, c, le, v, de?.length ? { parts: de } : void 0);
604
+ await g(n, y, s, pe, u, S, b, me?.length ? { parts: me } : void 0);
528
605
  } catch (e) {
529
- if (!de || !et(e)) throw e;
530
- await g(n, _, o, ue, c, le, v, void 0), a ||= he;
606
+ if (!me || !ft(e)) throw e;
607
+ await g(n, y, s, pe, u, S, b, void 0), o ||= ge;
531
608
  }
532
- T(b, "promptSent");
533
- let _e = null, ve = !1, ye = Le, S = Re([], x), be = Date.now() + u.streamBudgetMs, xe = Date.now(), Ce = Date.now(), we = () => Pe({
534
- turnId: b,
535
- abortRequested: Hn.current.has(b),
536
- activeTurnId: C.getState().processingByConversationId[f]?.messageId ?? null
537
- });
538
- for (; Date.now() < be;) {
539
- let e = we();
609
+ E(x, "promptSent");
610
+ let ve = null, ye = !1, be = Ye, C = Xe([], fe), xe = Date.now() + p.streamBudgetMs, Se = Date.now(), Te = Date.now();
611
+ for (; Date.now() < xe;) {
612
+ se(n, s);
613
+ let e = ue();
540
614
  if (e.abandon) {
541
- e.clearProcessing && an(f);
615
+ e.clearProcessing && Cn(h);
542
616
  return;
543
617
  }
544
- if (S = Re(await ee(n, _, o, c, v, {
618
+ if (C = Xe(await f(n, y, s, u, b, {
545
619
  limit: 50,
546
- sinceMs: x
547
- }), x, { accumulateNarration: u.accumulatesNarration }), tn(f, b, { content: re(S.content) }), S.hasRenderableOutput ? ve || (ve = !0, _e !== null && T(b, "lastQuietPoll", _e), T(b, "firstOutput")) : _e = Ye(), u.accumulatesNarration) S.hasText && T(b, "firstText");
620
+ sinceMs: fe
621
+ }), fe, { accumulateNarration: p.accumulatesNarration }), bn(h, x, { content: ie(C.content) }), C.hasRenderableOutput ? ye || (ye = !0, ve !== null && E(x, "lastQuietPoll", ve), E(x, "firstOutput")) : ve = st(), p.accumulatesNarration) C.hasText && E(x, "firstText");
548
622
  else {
549
- let e = He(ye, S, Ye());
550
- ye = e.tracker, e.confirmedAt !== null && T(b, "firstText", e.confirmedAt);
623
+ let e = et(be, C, st());
624
+ be = e.tracker, e.confirmedAt !== null && E(x, "firstText", e.confirmedAt);
551
625
  }
552
- if (S.pendingWrite && nn(f, b, { pendingWrite: S.pendingWrite }), S.done) {
553
- T(b, "answerDone"), q.current.markVerified(n);
626
+ if (C.pendingWrite && xn(h, x, { pendingWrite: C.pendingWrite }), C.done) {
627
+ E(x, "answerDone"), q.current.markVerified(n);
554
628
  break;
555
629
  }
556
- Date.now() - xe > 3e4 && (await d(n, _, 600, v).catch(() => void 0), xe = Date.now()), await new Promise((e) => setTimeout(e, ce(Date.now() - Ce)));
630
+ Date.now() - Se > 3e4 && (await ee(n, y, 600, b).catch(() => void 0), Se = Date.now()), await new Promise((e) => setTimeout(e, le(Date.now() - Te)));
557
631
  }
558
- let Te = u.producesArtifacts ? await p(n, _, o, c, v).then((e) => e).catch(() => []) : void 0;
559
- if (S.usedTools !== void 0 && w(b, { usedTools: S.usedTools }), S.done || (w(b, { outcome: "timedOut" }), S = {
560
- ...S,
561
- content: ie(S.content, c, j, l)
562
- }), a && (S = {
563
- ...S,
564
- content: `${S.content}\n\n${j("attachments.imagesNotSent", "_Your photo was too large to include with this message, so the answer above is from the text and the file link only. Try a smaller or more tightly cropped photo._")}`
565
- }), oe(S.content, Te, o, n), S.tokens) {
566
- tn(f, b, { tokens: S.tokens });
632
+ let Ee = p.producesArtifacts ? await d(n, y, s, u, b).then((e) => e).catch(() => []) : void 0;
633
+ C.usedTools !== void 0 && T(x, { usedTools: C.usedTools }), C.done || (T(x, { outcome: "timedOut" }), C = {
634
+ ...C,
635
+ content: ae(C.content, u, j, te)
636
+ }), o && (C = {
637
+ ...C,
638
+ content: `${C.content}\n\n${j("attachments.imagesNotSent", "_Your photo was too large to include with this message, so the answer above is from the text and the file link only. Try a smaller or more tightly cropped photo._")}`
639
+ });
640
+ let Oe = !C.done;
641
+ if (de(C.content, Ee, s, n, Oe), C.tokens) {
642
+ bn(h, x, { tokens: C.tokens });
567
643
  try {
568
- await Ht?.({
569
- workspaceId: _,
570
- sessionId: o,
571
- messageId: S.messageId,
572
- model: S.model,
573
- tokens: S.tokens
574
- }), Dt(M);
644
+ await on?.({
645
+ workspaceId: y,
646
+ sessionId: s,
647
+ messageId: C.messageId,
648
+ model: C.model,
649
+ tokens: C.tokens
650
+ }), Vt(M);
575
651
  } catch {}
576
652
  }
577
- let De = we();
578
- if (De.abandon) {
579
- De.clearProcessing && an(f);
653
+ C.done || se(n, s);
654
+ let ke = ue();
655
+ if (ke.abandon) {
656
+ ke.clearProcessing && Cn(h);
580
657
  return;
581
658
  }
582
- T(b, "complete"), w(b, { outcome: "answered" }), rn(f, "complete", b, null);
659
+ E(x, "complete"), T(x, { outcome: "answered" }), Sn(h, "complete", x, null);
583
660
  } catch (e) {
584
- q.current.invalidate(i ?? C.getState().sandboxesByMode[c]?.sandboxId ?? null);
585
- let t = Pe({
586
- turnId: b,
587
- abortRequested: Hn.current.has(b),
588
- activeTurnId: C.getState().processingByConversationId[f]?.messageId ?? null
661
+ q.current.invalidate(i ?? w.getState().sandboxesByMode[u]?.sandboxId ?? null);
662
+ let t = Ke({
663
+ turnId: x,
664
+ abortRequested: dr.current.has(x),
665
+ activeTurnId: w.getState().processingByConversationId[h]?.messageId ?? null,
666
+ conversationExists: v()
589
667
  });
590
- if (t.abandon) {
591
- t.clearProcessing && an(f);
668
+ if (i && a && se(i, a), t.abandon) {
669
+ t.clearProcessing && Cn(h);
592
670
  return;
593
671
  }
594
- if (n === 1 && tt(e)) {
595
- let e = i ?? C.getState().sandboxesByMode[c]?.sandboxId ?? null;
596
- return e && (J.current.add(e), q.current.invalidate(e)), sn(f), W(c), en(f, b, ""), nn(f, b, { pendingWrite: void 0 }), Je(b), se(2);
672
+ if (n === 1 && pt(e)) {
673
+ let e = i ?? w.getState().sandboxesByMode[u]?.sandboxId ?? null;
674
+ return e && (J.current.add(e), q.current.invalidate(e)), Tn(h), U(u), yn(h, x, ""), xn(h, x, { pendingWrite: void 0 }), ot(x), fe(2);
597
675
  }
598
676
  throw e;
599
677
  }
600
- }, x = f;
601
- Nn.current.add(x);
678
+ }, S = h;
679
+ tr.current.add(S);
602
680
  try {
603
- if (!_) throw Object.assign(/* @__PURE__ */ Error("Assistant backend is unavailable without an active workspace context."), { extensions: {
681
+ if (!y) throw Object.assign(/* @__PURE__ */ Error("Assistant backend is unavailable without an active workspace context."), { extensions: {
604
682
  code: "UNAUTHENTICATED",
605
683
  authFailure: "WORKSPACE_CONTEXT_MISSING"
606
684
  } });
607
- let e = await xe(c, () => xn.current.find((e) => e.id === c), K);
608
- l = e.config, u = e.capabilities;
609
- let t = we(c, l, C.getState().acknowledgedWriteModes, {
685
+ let e = await Ne(u, () => zn.current.find((e) => e.id === u), G);
686
+ te = e.config, p = e.capabilities;
687
+ let t = te, n = ue();
688
+ if (n.abandon) {
689
+ n.clearProcessing && Cn(h);
690
+ return;
691
+ }
692
+ let i = Ie(u, t, w.getState().acknowledgedWriteModes, {
610
693
  dictated: r,
611
- confirmsWrites: h(c)
694
+ confirmsWrites: m(u)
612
695
  });
613
- if (t) throw new ve(t, t === "confirm-write-mode" ? "Write mode not confirmed" : "Voice in a write mode");
614
- T(b, "cleared"), await se();
696
+ if (i) throw new ke(i, i === "confirm-write-mode" ? "Write mode not confirmed" : "Voice in a write mode");
697
+ E(x, "cleared"), await fe();
615
698
  } catch (e) {
616
- q.current.invalidate(C.getState().sandboxesByMode[c]?.sandboxId ?? null);
617
- let t = ye(e);
618
- w(b, { outcome: t.kind === "temporary" ? "failed" : "refused" }), t.offersUpgrade && Et(M, "sandbox");
619
- let r = S(t, j);
620
- rn(f, "error", b, r.headline), tn(f, b, { content: r.text }), nn(f, b, {
699
+ if (q.current.invalidate(w.getState().sandboxesByMode[u]?.sandboxId ?? null), !v()) {
700
+ Cn(h);
701
+ return;
702
+ }
703
+ let t = Ae(e);
704
+ T(x, { outcome: t.kind === "temporary" ? "failed" : "refused" }), t.offersUpgrade && Bt(M, "sandbox");
705
+ let r = je(t, j);
706
+ Sn(h, "error", x, r.headline), bn(h, x, { content: r.text }), xn(h, x, {
621
707
  lang: r.translated ? L : "en",
622
- ...y(n.voiceSessionId)
708
+ ...oe(n.voiceSessionId)
623
709
  });
624
710
  } finally {
625
- Nn.current.delete(x), w(b, { outcome: "stopped" }), T(b, "complete");
626
- let e = C.getState(), t = ke(ne, c, e.conversations.find((e) => e.id === x), (t) => !!e.sandboxesByMode[t]?.sandboxId);
627
- t && (fn(x, t.mode), t.backendSessionId && on(x, t.backendSessionId));
628
- let n = Un.current;
629
- Un.current = null, n && n.conversationId === x && er.current(n.content, n.attachments, n.options);
711
+ tr.current.delete(S), T(x, { outcome: "stopped" }), E(x, "complete");
712
+ let e = w.getState(), t = Ve(re, u, e.conversations.find((e) => e.id === S), (t) => !!e.sandboxesByMode[t]?.sandboxId);
713
+ t && (An(S, t.mode), t.backendSessionId && wn(S, t.backendSessionId));
714
+ let n = fr.current;
715
+ fr.current = null, n && n.conversationId === S && v() && Cr.current(n.content, n.attachments, n.options);
630
716
  }
631
717
  }, [
632
718
  R,
633
- H,
634
- Vt,
635
- sn,
636
- W,
637
- Xt,
638
719
  V,
639
- Ln,
640
- Bt,
720
+ rn,
721
+ Tn,
722
+ U,
723
+ mn,
724
+ B,
725
+ ar,
726
+ nn,
641
727
  P,
642
728
  F,
643
- tn,
729
+ bn,
644
730
  M,
645
- K,
646
- Ht,
647
- Jt,
648
- L,
649
- Yt,
650
- qt,
651
- fn,
652
- Zn,
731
+ G,
653
732
  on,
654
- Qt,
655
- rn,
656
- an,
733
+ fn,
734
+ L,
735
+ pn,
736
+ dn,
737
+ An,
738
+ br,
739
+ wn,
740
+ _n,
741
+ Sn,
742
+ Cn,
657
743
  j,
658
- Fn,
659
- en,
744
+ rr,
745
+ yn,
660
746
  I
661
- ]), Qn = E((e, t) => {
747
+ ]), xr = D((e, t) => {
662
748
  X(e, [], t ? { autoIntent: t } : {});
663
- }, [X]), $n = E(() => {
664
- let e = [...mn.chat].reverse().find((e) => e.role === "user" && !e.metadata?.localAction), t = R ? Mn.current[R] ?? [] : [];
665
- e && X(e.content, t);
749
+ }, [X]), Sr = D(() => {
750
+ let e = [...Mn.chat].reverse().find((e) => e.role === "user" && !e.metadata?.localAction);
751
+ if (!e || e.metadata?.approvalFollowUp) return;
752
+ let t = R ? er.current[R] ?? [] : [];
753
+ X(e.content, t);
666
754
  }, [
667
- hn,
755
+ Nn,
668
756
  X,
669
757
  R
670
- ]), er = k(X);
671
- D(() => {
672
- er.current = X;
758
+ ]), Cr = k(X);
759
+ O(() => {
760
+ Cr.current = X;
673
761
  }, [X]);
674
- let tr = O(() => {
675
- if (gn) return null;
676
- for (let e = hn.length - 1; e >= 0; --e) {
677
- let t = hn[e];
678
- if (t?.role !== "assistant" || !ae(t) || Hn.current.has(t.id)) continue;
679
- let n = Ie(t, G, j);
762
+ let wr = qt(() => {
763
+ if (Pn) return null;
764
+ for (let e = Nn.length - 1; e >= 0; --e) {
765
+ let t = Nn[e];
766
+ if (t?.role !== "assistant" || !y(t) || dr.current.has(t.id)) continue;
767
+ let n = Je(t, W, j);
680
768
  if (n.kind !== "output") return null;
681
- let r = Ue(n.text).text.trim();
769
+ let r = tt(n.text).text.trim();
682
770
  return r ? {
683
771
  id: t.id,
684
772
  text: r
@@ -686,24 +774,34 @@ var Rt = ({ visible: Rt = !0, writeAccess: zt = "unknown" }) => {
686
774
  }
687
775
  return null;
688
776
  }, [
689
- hn,
690
- gn,
691
- G,
777
+ Nn,
778
+ Pn,
779
+ W,
692
780
  j
693
- ]), nr = O(() => tr ? le(tr.text) : null, [tr]), rr = mn.chat, Z = O(() => mn.voice.filter((e) => e.role === "user" || e.role === "assistant").map((e) => ({
781
+ ]), Tr = qt(() => wr ? ue(wr.text) : null, [wr]), Er = Mn.chat, Dr = w((e) => We(e)?.sandboxId ?? null), Or = C(Er, {
782
+ sessionId: jn?.backendSessionId,
783
+ sandboxId: Dr,
784
+ nowMs: Date.now()
785
+ }), kr = xe(Er), Ar = Or?.expiresAtMs ?? null;
786
+ O(() => {
787
+ if (Ar === null) return;
788
+ let e = window.setTimeout(() => ur((e) => e + 1), Math.max(0, Ar - Date.now()));
789
+ return () => window.clearTimeout(e);
790
+ }, [Ar, lr]);
791
+ let Z = qt(() => Mn.voice.filter((e) => e.role === "user" || e.role === "assistant").map((e) => ({
694
792
  id: e.id,
695
793
  role: e.role,
696
- text: Ge(e, G, j),
794
+ text: rt(e, W, j),
697
795
  sessionId: b(e),
698
796
  timestamp: e.timestamp
699
797
  })).filter((e) => e.text.length > 0), [
700
- mn.voice,
701
- G,
798
+ Mn.voice,
799
+ W,
702
800
  j
703
- ]), ir = E(() => {
801
+ ]), jr = D(() => {
704
802
  if (Z.length === 0) return;
705
803
  let e = /* @__PURE__ */ new Date();
706
- st(se(Z, {
804
+ yt(ce(Z, {
707
805
  title: j("voiceSession.transcript", "Voice conversation"),
708
806
  savedAt: j("voiceSession.savedAt", "Saved"),
709
807
  session: j("voiceSession.sessionLabel", "Session"),
@@ -715,199 +813,260 @@ var Rt = ({ visible: Rt = !0, writeAccess: zt = "unknown" }) => {
715
813
  M,
716
814
  Z,
717
815
  j
718
- ]), Q = Ot({ perFileChars: Dn }), ar = k(Q);
719
- ar.current = Q;
720
- let $ = Ze({
721
- onSubmit: E((e, t, n) => {
722
- let r = () => {
723
- let r = ar.current, i = me(r.attachments), a = {
816
+ ]), Q = Ht({ perFileChars: qn }), Mr = k(Q);
817
+ Mr.current = Q;
818
+ let Nr = k(/* @__PURE__ */ new Set()), Pr = k(() => !1), $ = lt({
819
+ onSubmit: D((e, t, n) => {
820
+ let r = $n.current, i = () => {
821
+ let i = Mr.current, a = w.getState();
822
+ if (!pe({
823
+ sessionLive: Pr.current(t),
824
+ boundAtSubmit: r,
825
+ activeConversationId: a.activeConversationId,
826
+ boundConversationExists: a.conversations.some((e) => e.id === r)
827
+ })) {
828
+ i.clear();
829
+ return;
830
+ }
831
+ let o = Te(i.attachments), s = {
724
832
  ...n,
725
- handedOver: Ye()
833
+ handedOver: st()
726
834
  };
727
- er.current(e, i, {
835
+ Cr.current(e, o, {
728
836
  fromPerson: !0,
729
837
  voiceSessionId: t,
730
- voiceTiming: a
731
- }), r.clear();
838
+ voiceTiming: s
839
+ }), i.clear();
732
840
  };
733
- if (!ar.current.isBusy) {
734
- r();
841
+ if (!Mr.current.isBusy) {
842
+ i();
735
843
  return;
736
844
  }
737
- let i = Date.now(), a = window.setInterval(() => {
738
- ar.current.isBusy && Date.now() - i < It || (window.clearInterval(a), r());
845
+ let a = Date.now(), o = Nr.current, s = window.setInterval(() => {
846
+ Mr.current.isBusy && Date.now() - a < Qt || (window.clearInterval(s), o.delete(s), i());
739
847
  }, 200);
848
+ o.add(s);
740
849
  }, []),
741
- latestReply: tr,
742
- language: ue(Wt, L).tag
743
- }), or = $.start, sr = E(() => {
744
- Rn(!0), or();
745
- }, [Rn, or]), cr = O(() => (pn?.messages ?? []).reduce((e, t) => Math.max(e, t.metadata?.continuedVoiceTurns ?? 0), 0), [pn?.messages]), lr = We(mn.voice, G, j), ur = lr > cr, dr = E(() => {
746
- let e = C.getState().activeConversationId;
747
- !e || Z.length === 0 || (H(e, {
748
- id: Lt(),
850
+ latestReply: wr,
851
+ language: de(cn, L).tag
852
+ });
853
+ Pr.current = $.isCurrentSession;
854
+ let Fr = $.start, Ir = D(() => {
855
+ or(!0), Fr();
856
+ }, [or, Fr]), Lr = qt(() => (jn?.messages ?? []).reduce((e, t) => Math.max(e, t.metadata?.continuedVoiceTurns ?? 0), 0), [jn?.messages]), Rr = nt(Mn.voice, W, j), zr = Rr > Lr, Br = D(() => {
857
+ let e = w.getState().activeConversationId;
858
+ !e || Z.length === 0 || (V(e, {
859
+ id: $t(),
749
860
  role: "system",
750
- content: oe(Z.slice(cr), {
861
+ content: se(Z.slice(Lr), {
751
862
  intro: j("voiceSession.continuedIntro", "Continued from a voice conversation. You asked about:"),
752
863
  nothing: j("voiceSession.continuedNothing", "Continued from a voice conversation."),
753
864
  more: (e) => j("voiceSession.continuedMore", "…and {{count}} more", { count: e })
754
865
  }),
755
866
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
756
- metadata: { continuedVoiceTurns: lr }
757
- }), jn(!1), $.end());
867
+ metadata: { continuedVoiceTurns: Rr }
868
+ }), K(!1), $.end());
758
869
  }, [
759
870
  Z,
760
- lr,
761
- cr,
762
- H,
871
+ Rr,
872
+ Lr,
873
+ V,
763
874
  j,
764
- $
765
- ]), fr = k(0);
766
- D(() => {
767
- $.active && (fr.current = lr);
875
+ $,
876
+ K
877
+ ]), Vr = k(0);
878
+ O(() => {
879
+ $.active && (Vr.current = Rr);
768
880
  }, [$.active]);
769
- let pr = E(() => {
770
- let e = lr > fr.current;
771
- $.end(), e && jn(!0);
772
- }, [lr, $]);
773
- D(() => {
774
- (!Rt || !Pn) && $.active && $.end();
881
+ let Hr = D(() => {
882
+ let e = Rr > Vr.current;
883
+ $.end(), e && K(!0);
775
884
  }, [
776
- Rt,
777
- Pn,
885
+ Rr,
886
+ $,
887
+ K
888
+ ]);
889
+ O(() => {
890
+ (!en || !nr) && $.active && $.end();
891
+ }, [
892
+ en,
893
+ nr,
778
894
  $
779
- ]), D(() => {
780
- $.active || (ar.current.clear(), Un.current = null);
781
- }, [$.active]), D(() => {
782
- let e = C.getState().consumePendingPrompt();
783
- return e && er.current(e), C.subscribe((e, t) => {
895
+ ]), O(() => {
896
+ let e = $n.current, t = w.getState(), n = he({
897
+ sessionLive: $.active,
898
+ bound: e,
899
+ activeConversationId: t.activeConversationId,
900
+ boundConversationExists: t.conversations.some((t) => t.id === e)
901
+ });
902
+ $n.current = n.bound, n.end && $.end();
903
+ }, [
904
+ $,
905
+ R,
906
+ mn
907
+ ]);
908
+ let Ur = k(S);
909
+ O(() => {
910
+ let e = me(Ur.current, {
911
+ activeConversationId: R,
912
+ chatTurnCount: Er.length,
913
+ voiceTurnCount: Z.length,
914
+ sessionLive: $.active,
915
+ sessionBoundTo: $n.current,
916
+ turnInFlight: Pn
917
+ });
918
+ Ur.current = e.state, e.open && K(!0);
919
+ }, [
920
+ R,
921
+ Er.length,
922
+ Z.length,
923
+ $.active,
924
+ Pn,
925
+ K
926
+ ]), O(() => {
927
+ if (!$.active) {
928
+ Mr.current.clear(), fr.current = null;
929
+ for (let e of Nr.current) window.clearInterval(e);
930
+ Nr.current.clear();
931
+ }
932
+ }, [$.active]), O(() => {
933
+ let e = Nr.current;
934
+ return () => {
935
+ for (let t of e) window.clearInterval(t);
936
+ e.clear();
937
+ };
938
+ }, []), O(() => {
939
+ let e = w.getState().consumePendingPrompt();
940
+ return e && Cr.current(e), w.subscribe((e, t) => {
784
941
  if (e.pendingPrompt && e.pendingPrompt !== t.pendingPrompt) {
785
- let e = C.getState().consumePendingPrompt();
786
- e && er.current(e);
942
+ let e = w.getState().consumePendingPrompt();
943
+ e && Cr.current(e);
787
944
  }
788
945
  });
789
946
  }, []);
790
- let mr = E((e) => {
791
- let t = R ? C.getState().conversations.find((e) => e.id === R) : void 0;
947
+ let Wr = D((e) => {
948
+ let t = R ? w.getState().conversations.find((e) => e.id === R) : void 0;
792
949
  if (t && (t.messages.length > 0 || t.backendSessionId)) {
793
950
  if (t.mode !== e) {
794
- let t = C.getState().conversations.find((t) => t.mode === e && t.messages.length === 0 && !t.backendSessionId && !C.getState().processingByConversationId[t.id]);
795
- t ? $t(t.id) : V(void 0, e);
951
+ let t = w.getState().conversations.find((t) => t.mode === e && t.messages.length === 0 && !t.backendSessionId && !w.getState().processingByConversationId[t.id]);
952
+ t ? vn(t.id) : B(void 0, e);
796
953
  }
797
- } else R && Qt(R, e);
798
- let n = C.getState().activeConversationId;
799
- n ? Qt(n, e) : dn(!1), B(e);
954
+ } else R && _n(R, e);
955
+ let n = w.getState().activeConversationId;
956
+ n ? _n(n, e) : kn(!1), gn(e);
800
957
  }, [
801
958
  R,
802
- V,
803
- $t,
804
- dn,
805
- Qt,
806
- B
807
- ]), hr = E(() => {
808
- let e = C.getState(), t = e.activeConversationId ? e.conversations.find((t) => t.id === e.activeConversationId) : void 0;
959
+ B,
960
+ vn,
961
+ kn,
962
+ _n,
963
+ gn
964
+ ]), Gr = D(() => {
965
+ let e = w.getState(), t = e.activeConversationId ? e.conversations.find((t) => t.id === e.activeConversationId) : void 0;
809
966
  if (!t) {
810
- dn(!0), B(Te);
967
+ kn(!0), gn(Le);
811
968
  return;
812
969
  }
813
970
  if (t.routedBy === "auto") {
814
- dn(!0);
971
+ kn(!0);
815
972
  return;
816
973
  }
817
974
  if (t.messages.length === 0 && !t.backendSessionId) {
818
- fn(t.id, Te);
975
+ An(t.id, Le);
819
976
  return;
820
977
  }
821
978
  let n = e.conversations.find((t) => t.routedBy === "auto" && t.messages.length === 0 && !t.backendSessionId && !e.processingByConversationId[t.id]);
822
- n ? ($t(n.id), fn(n.id, Te)) : V(void 0, Te, { routedBy: "auto" });
979
+ n ? (vn(n.id), An(n.id, Le)) : B(void 0, Le, { routedBy: "auto" });
823
980
  }, [
824
- V,
825
- fn,
826
- $t,
827
- dn,
828
- B
829
- ]), gr = E((e) => {
830
- if (N.find((t) => t.id === e)?.writeCapable && !Ce(C.getState().acknowledgedWriteModes, e)) {
831
- kn(e);
981
+ B,
982
+ An,
983
+ vn,
984
+ kn,
985
+ gn
986
+ ]), Kr = D((e) => {
987
+ if (N.find((t) => t.id === e)?.writeCapable && !Fe(w.getState().acknowledgedWriteModes, e)) {
988
+ Yn(e);
832
989
  return;
833
990
  }
834
- mr(e);
835
- }, [mr, N]), _r = E(() => {
836
- let e = On;
837
- if (kn(null), !e) return;
838
- let t = En.current;
839
- if (En.current = null, t) {
840
- ln(e), X(t.content, t.attachments, t.options);
991
+ Wr(e);
992
+ }, [Wr, N]), qr = D(() => {
993
+ let e = Jn;
994
+ if (Yn(null), !e) return;
995
+ let t = Kn.current;
996
+ if (Kn.current = null, t) {
997
+ Dn(e), X(t.content, t.attachments, t.options);
841
998
  return;
842
999
  }
843
- ln(e), mr(e);
1000
+ Dn(e), Wr(e);
844
1001
  }, [
845
- On,
846
- ln,
847
- mr,
1002
+ Jn,
1003
+ Dn,
1004
+ Wr,
848
1005
  X
849
- ]), vr = On === null ? void 0 : N.find((e) => e.id === On) ?? { id: On }, yr = E(() => {
850
- kn(null);
851
- let e = En.current;
852
- En.current = null, e && X(e.content, e.attachments, {
1006
+ ]), Jr = Jn === null ? void 0 : N.find((e) => e.id === Jn) ?? { id: Jn }, Yr = D(() => {
1007
+ Yn(null);
1008
+ let e = Kn.current;
1009
+ Kn.current = null, e && X(e.content, e.attachments, {
853
1010
  ...e.options,
854
1011
  autoIntent: "read"
855
1012
  });
856
1013
  }, [X]);
857
- return /* @__PURE__ */ Pt("div", {
1014
+ return /* @__PURE__ */ Xt("div", {
858
1015
  className: "relative flex flex-1 flex-col overflow-hidden",
859
1016
  children: [
860
- /* @__PURE__ */ Pt("div", {
1017
+ /* @__PURE__ */ Xt("div", {
861
1018
  className: "contents",
862
1019
  inert: $.active || void 0,
863
1020
  children: [
864
- Z.length > 0 && !$.active ? /* @__PURE__ */ A(at, {
1021
+ Z.length > 0 && !$.active ? /* @__PURE__ */ A(_t, {
865
1022
  count: Z.length,
866
- onOpenTranscript: () => jn(!0)
1023
+ onOpenTranscript: () => K(!0)
867
1024
  }) : null,
868
- rr.length === 0 ? /* @__PURE__ */ A(ct, {
1025
+ Er.length === 0 ? /* @__PURE__ */ A(bt, {
869
1026
  mode: z,
870
- onSuggestionClick: Qn,
871
- explainsAuto: wn,
872
- suggestions: wn && z === "assistant" ? De(N.find((e) => e.id === "assistant")?.suggestions ?? [], N.find((e) => e.id === "api-calls")?.suggestions ?? []) : void 0
1027
+ onSuggestionClick: xr,
1028
+ explainsAuto: Wn,
1029
+ suggestions: Wn && z === "assistant" ? ze(N.find((e) => e.id === "assistant")?.suggestions ?? [], N.find((e) => e.id === "api-calls")?.suggestions ?? []) : void 0
873
1030
  }) : /* @__PURE__ */ A("div", {
874
1031
  className: "flex min-h-0 flex-1 flex-col",
875
- children: /* @__PURE__ */ A(lt, {
876
- onApprovePendingWrite: Gn,
877
- approvingWriteRef: Bn,
878
- messages: rr,
879
- processing: G ?? null,
880
- streamingMessageId: _n,
881
- failedMessageId: vn,
882
- onRetry: $n
1032
+ children: /* @__PURE__ */ A(xt, {
1033
+ onApprovePendingWrite: mr,
1034
+ approvingWriteRef: cr,
1035
+ approvableMessageId: Or?.messageId ?? null,
1036
+ retryableMessageId: kr,
1037
+ messages: Er,
1038
+ processing: W ?? null,
1039
+ streamingMessageId: Fn,
1040
+ failedMessageId: In,
1041
+ onRetry: cr === null ? Sr : void 0
883
1042
  })
884
1043
  }),
885
- /* @__PURE__ */ A(kt, {
886
- onStartVoiceSession: $.available && Pn ? sr : void 0,
1044
+ /* @__PURE__ */ A(Ut, {
1045
+ onStartVoiceSession: $.available && nr ? Ir : void 0,
887
1046
  onSend: (e, t) => void X(e, t, { fromPerson: !0 }),
888
- onDraftStart: zn,
889
- disabled: gn,
1047
+ onDraftStart: sr,
1048
+ disabled: Pn || cr !== null,
890
1049
  placeholder: z === "api-calls" ? j("chatArea.placeholderActions", "What would you like me to do?") : j("chatArea.placeholderGeneral", "Ask me anything…"),
891
1050
  mode: z,
892
- writeAccessDenied: zt === "denied" && !!Y?.writeCapable,
893
- availableModes: Sn,
894
- attachmentCharsPerFile: Dn,
895
- onModeChange: gr,
896
- auto: Cn ? {
897
- active: wn,
898
- onSelect: hr
1051
+ writeAccessDenied: tn === "denied" && !!Y?.writeCapable,
1052
+ availableModes: Hn,
1053
+ attachmentCharsPerFile: qn,
1054
+ onModeChange: Kr,
1055
+ auto: Un ? {
1056
+ active: Wn,
1057
+ onSelect: Gr
899
1058
  } : void 0
900
1059
  })
901
1060
  ]
902
1061
  }),
903
- An && !$.active ? /* @__PURE__ */ A(ot, {
1062
+ Qn && !$.active ? /* @__PURE__ */ A(vt, {
904
1063
  turns: Z,
905
- onClose: () => jn(!1),
906
- onSave: ir,
907
- onContinueInChat: ur ? dr : void 0,
1064
+ onClose: () => K(!1),
1065
+ onSave: jr,
1066
+ onContinueInChat: zr ? Br : void 0,
908
1067
  closeOnEscape: !0
909
1068
  }) : null,
910
- $.active && /* @__PURE__ */ A(ut, {
1069
+ $.active && /* @__PURE__ */ A(St, {
911
1070
  session: $.session,
912
1071
  notice: $.notice,
913
1072
  capturing: $.capturing,
@@ -921,24 +1080,24 @@ var Rt = ({ visible: Rt = !0, writeAccess: zt = "unknown" }) => {
921
1080
  onRetryAttachment: Q.retry,
922
1081
  canAttachMore: Q.canAddMore,
923
1082
  preparingAttachments: Q.preparingCount,
924
- onSaveTranscript: ir,
925
- onContinueInChat: dr,
1083
+ onSaveTranscript: jr,
1084
+ onContinueInChat: Br,
926
1085
  onInterrupt: () => {
927
- $.interrupt(), Wn();
1086
+ $.interrupt(), pr();
928
1087
  },
929
- spoken: nr,
1088
+ spoken: Tr,
930
1089
  onToggleMute: $.toggleMute,
931
- onEnd: pr
1090
+ onEnd: Hr
932
1091
  }),
933
- /* @__PURE__ */ A(jt, {
934
- open: On !== null,
935
- mode: vr,
1092
+ /* @__PURE__ */ A(Gt, {
1093
+ open: Jn !== null,
1094
+ mode: Jr,
936
1095
  currentMode: Y ?? { id: z },
937
- onConfirm: _r,
938
- onCancel: yr
1096
+ onConfirm: qr,
1097
+ onCancel: Yr
939
1098
  })
940
1099
  ]
941
1100
  });
942
1101
  };
943
1102
  //#endregion
944
- export { Rt as AssistantChatArea };
1103
+ export { en as AssistantChatArea };