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