@burdenoff/fe-libs 2026.925.3 → 2026.925.5

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 (31) hide show
  1. package/dist/shared/assistant/api.d.ts +19 -1
  2. package/dist/shared/assistant/api.d.ts.map +1 -1
  3. package/dist/shared/assistant/api.js +57 -46
  4. package/dist/shared/assistant/index.d.ts +1 -0
  5. package/dist/shared/assistant/index.d.ts.map +1 -1
  6. package/dist/shared/assistant/sandboxReadiness.d.ts +45 -6
  7. package/dist/shared/assistant/sandboxReadiness.d.ts.map +1 -1
  8. package/dist/shared/assistant/sandboxReadiness.js +25 -11
  9. package/dist/shared/assistant/speech/browserSpeechEngine.d.ts.map +1 -1
  10. package/dist/shared/assistant/speech/browserSpeechEngine.js +1 -1
  11. package/dist/shared/assistant/transportErrors.d.ts +2 -0
  12. package/dist/shared/assistant/transportErrors.d.ts.map +1 -1
  13. package/dist/shared/assistant/transportErrors.js +5 -1
  14. package/dist/shared/assistant/turnProgress.d.ts +38 -0
  15. package/dist/shared/assistant/turnProgress.d.ts.map +1 -1
  16. package/dist/shared/assistant/turnProgress.js +24 -2
  17. package/dist/shared/assistant/turnTimeline.d.ts +288 -0
  18. package/dist/shared/assistant/turnTimeline.d.ts.map +1 -0
  19. package/dist/shared/assistant/turnTimeline.js +291 -0
  20. package/dist/shared/assistant/ui/AssistantChatArea.d.ts.map +1 -1
  21. package/dist/shared/assistant/ui/AssistantChatArea.js +537 -468
  22. package/dist/shared/assistant/ui/AssistantSpeechProvider.d.ts.map +1 -1
  23. package/dist/shared/assistant/ui/AssistantSpeechProvider.js +190 -185
  24. package/dist/shared/assistant/ui/useVoiceSession.d.ts +7 -1
  25. package/dist/shared/assistant/ui/useVoiceSession.d.ts.map +1 -1
  26. package/dist/shared/assistant/ui/useVoiceSession.js +87 -80
  27. package/dist/shared/assistant/voice/voiceSession.d.ts +25 -0
  28. package/dist/shared/assistant/voice/voiceSession.d.ts.map +1 -1
  29. package/dist/shared/assistant/voice/voiceSession.js +29 -13
  30. package/dist/shared-assistant.js +122 -121
  31. package/package.json +1 -1
@@ -4,195 +4,231 @@ import "../../../shared-providers-shell.js";
4
4
  import { useAssistantProduct as n } from "../product.js";
5
5
  import { useAssistantTr as r } from "../i18n.js";
6
6
  import { isAssistantModeId as i } from "../modeIds.js";
7
- import { abortAssistantTurn as a, approvePendingWrite as o, createAssistantSandbox as s, createAssistantSession as c, extendAssistantSandboxTTL as ee, findExistingSandbox as te, getAssistantArtifacts as l, getAssistantMessages as ne, getAssistantSession as u, modeRequiresConfirmWrites as re, promptGatewayRequestBytes as ie, releaseSupersededAssistantSandboxes as d, sendAssistantPromptAsync as ae, waitForAssistantServiceReady as f, waitForSandboxRunning as oe } from "../api.js";
8
- import { sanitize as se } from "../progress.js";
9
- import { withIncompleteTurnNotice as ce } from "../streamBudget.js";
10
- import { isVoiceTurn as p, voiceMarker as m, voiceSessionIdOf as h } from "../voice/turnVisibility.js";
11
- import { buildContinuedFromVoiceNote as le, buildVoiceTranscriptMarkdown as g, voiceTranscriptFilename as ue } from "../voice/voiceTranscript.js";
12
- import { pollDelayMs as de } from "../voice/assistantPollSchedule.js";
13
- import { toCaptionText as fe } from "../voice/captionText.js";
7
+ import { abortAssistantTurn as a, approvePendingWrite as o, createAssistantSandbox as s, createAssistantSession as c, extendAssistantSandboxTTL as ee, findExistingSandboxWithStatus as te, getAssistantArtifacts as ne, getAssistantMessages as l, getAssistantSession as re, modeRequiresConfirmWrites as ie, promptGatewayRequestBytes as ae, releaseSupersededAssistantSandboxes as u, sendAssistantPromptAsync as oe, waitForAssistantServiceReady as d, waitForSandboxRunning as se } from "../api.js";
8
+ import { sanitize as ce } from "../progress.js";
9
+ import { withIncompleteTurnNotice as le } from "../streamBudget.js";
10
+ import { isVoiceTurn as f, voiceMarker as p, voiceSessionIdOf as m } from "../voice/turnVisibility.js";
11
+ import { buildContinuedFromVoiceNote as ue, buildVoiceTranscriptMarkdown as h, voiceTranscriptFilename as de } from "../voice/voiceTranscript.js";
12
+ import { pollDelayMs as fe } from "../voice/assistantPollSchedule.js";
13
+ import { toCaptionText as g } from "../voice/captionText.js";
14
14
  import { resolveAssistantLanguage as _ } from "../voice/languages.js";
15
15
  import { resolveLanguagePair as pe } from "../voice/languagePair.js";
16
16
  import { countInlineImageCandidates as me, countInlinedImageParts as he, getSendableAttachments as ge, largestInlineCharsPerFile as _e, resolveAssistantInlineLimits as ve, toMessageAttachment as ye } from "../attachments.js";
17
17
  import { AssistantSendRefusal as be, classifyTurnFailure as xe, turnOutcomeCopy as Se } from "../turnOutcome.js";
18
- import { createAdminModeAccessGate as Ce, resolveAssistantSendModeAfterAccess as we } from "../adminModeSendGate.js";
19
- import { buildBoundedAttachmentTurn as Te } from "../attachmentTurn.js";
20
- import { isWriteModeAcknowledged as Ee, writeModeSendRefusalReason as De } from "../writeModeConsent.js";
21
- import { AUTO_READ_MODE as Oe, autoCarryOverFor as ke, autoSuggestions as Ae, classifyAssistantIntent as je, escalationToUndo as Me, isAutoRoutingOffered as Ne, resolveAutoRoute as Pe } from "../autoRouting.js";
22
- import { resolveActiveModeSandbox as Fe, useAssistantStore as v } from "../store.js";
23
- import { isTurnInFlight as Ie, planAbandonedTurn as Le, planTurnAbort as Re } from "../turnState.js";
24
- import { getAssistantDisplayContent as ze } from "../displayContent.js";
25
- import { buildAssistantProgress as Be, snapshotReplyFloor as Ve } from "../turnProgress.js";
18
+ import { createAdminModeAccessGate as v, resolveAssistantSendModeAfterAccess as Ce } from "../adminModeSendGate.js";
19
+ import { buildBoundedAttachmentTurn as we } from "../attachmentTurn.js";
20
+ import { isWriteModeAcknowledged as Te, writeModeSendRefusalReason as Ee } from "../writeModeConsent.js";
21
+ import { AUTO_READ_MODE as y, autoCarryOverFor as De, autoSuggestions as Oe, classifyAssistantIntent as ke, escalationToUndo as Ae, isAutoRoutingOffered as je, resolveAutoRoute as Me } from "../autoRouting.js";
22
+ import { resolveActiveModeSandbox as Ne, useAssistantStore as b } from "../store.js";
23
+ import { isTurnInFlight as Pe, planAbandonedTurn as Fe, planTurnAbort as Ie } from "../turnState.js";
24
+ import { getAssistantDisplayContent as Le } from "../displayContent.js";
25
+ import { NO_FIRST_TEXT as Re, buildAssistantProgress as ze, snapshotReplyFloor as Be, trackFirstText as Ve } from "../turnProgress.js";
26
26
  import { parseToolActivity as He } from "./AssistantToolActivity.js";
27
27
  import { countSpokenTurns as Ue, spokenTurnText as We } from "../spokenTurns.js";
28
- import { useVoiceSession as Ge } from "./useVoiceSession.js";
29
- import { getOrganizationId as Ke, getWorkspaceId as qe } from "../context.js";
30
- import { createReadinessTracker as Je } from "../sandboxReadiness.js";
31
- import { AssistantSpokenTurnsNotice as Ye } from "./AssistantSpokenTurnsNotice.js";
32
- import { VoiceTranscriptDrawer as Xe } from "./voice/VoiceTranscriptDrawer.js";
33
- import { downloadFile as Ze } from "../exportConversation.js";
34
- import { AssistantEmptyState as Qe } from "./AssistantEmptyState.js";
35
- import { AssistantMessageList as $e } from "./AssistantMessageList.js";
36
- import { AssistantVoiceSession as et } from "./voice/AssistantVoiceSession.js";
37
- import { useAssistantApiAccess as tt } from "../useAssistantApiAccess.js";
38
- import { useConversationTurns as nt } from "../useConversationTurns.js";
39
- import { isMultimodalBodyRejection as rt, isRecoverableAssistantError as it } from "../transportErrors.js";
40
- import { dispatchAssistantQuotaExhausted as at, notifyAiCreditsUpdated as ot } from "../aiCredits.js";
41
- import { useAssistantAttachments as st } from "../useAssistantAttachments.js";
42
- import { AssistantComposer as ct } from "./composer/AssistantComposer.js";
43
- import { isProdRuntime as lt } from "../env.js";
44
- import { AssistantApiCallsConsentDialog as ut } from "./AssistantApiCallsConsentDialog.js";
45
- import { useCallback as y, useEffect as b, useMemo as x, useRef as S, useState as dt } from "react";
46
- import { jsx as C, jsxs as ft } from "react/jsx-runtime";
28
+ import { beginTurn as Ge, describeTurn as x, detectTurnDevice as Ke, markTurn as S, restartAttempt as qe, turnClockMs as Je } from "../turnTimeline.js";
29
+ import { useVoiceSession as Ye } from "./useVoiceSession.js";
30
+ import { getOrganizationId as Xe, getWorkspaceId as Ze } from "../context.js";
31
+ import { isMultimodalBodyRejection as Qe, isRecoverableAssistantError as $e } from "../transportErrors.js";
32
+ import { createReadinessTracker as et, planAfterTransportFailure as tt, planTrustedSandboxFailure as nt } from "../sandboxReadiness.js";
33
+ import { AssistantSpokenTurnsNotice as rt } from "./AssistantSpokenTurnsNotice.js";
34
+ import { VoiceTranscriptDrawer as it } from "./voice/VoiceTranscriptDrawer.js";
35
+ import { downloadFile as at } from "../exportConversation.js";
36
+ import { AssistantEmptyState as ot } from "./AssistantEmptyState.js";
37
+ import { AssistantMessageList as st } from "./AssistantMessageList.js";
38
+ import { AssistantVoiceSession as ct } from "./voice/AssistantVoiceSession.js";
39
+ import { useAssistantApiAccess as lt } from "../useAssistantApiAccess.js";
40
+ import { useConversationTurns as ut } from "../useConversationTurns.js";
41
+ import { dispatchAssistantQuotaExhausted as dt, notifyAiCreditsUpdated as ft } from "../aiCredits.js";
42
+ import { useAssistantAttachments as pt } from "../useAssistantAttachments.js";
43
+ import { AssistantComposer as mt } from "./composer/AssistantComposer.js";
44
+ import { isProdRuntime as ht } from "../env.js";
45
+ import { AssistantApiCallsConsentDialog as gt } from "./AssistantApiCallsConsentDialog.js";
46
+ import { useCallback as C, useEffect as w, useMemo as T, useRef as E, useState as _t } from "react";
47
+ import { jsx as D, jsxs as vt } from "react/jsx-runtime";
47
48
  //#region src/shared/assistant/ui/AssistantChatArea.tsx
48
- var pt = 600, mt = 2e4;
49
- function ht() {
49
+ var yt = 600, bt = 2e4;
50
+ function xt() {
50
51
  return `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
51
52
  }
52
- var gt = ({ visible: gt = !0, writeAccess: _t = "unknown" }) => {
53
- let w = r(), { product: T, modes: E, gatherPageContext: vt, buildPrompt: yt, reportTokenUsage: bt } = n(), { getAccessToken: D, getWorkspaceToken: O, userId: k } = t(), { locale: xt } = e(), St = v((e) => e.assistantLanguage), Ct = v((e) => e.replyLanguage), wt = x(() => pe(St, Ct, xt), [
54
- St,
55
- Ct,
56
- xt
57
- ]), Tt = wt.reply.english, Et = wt.replyIsExplicit, Dt = wt.reply.code, { conversations: Ot, activeConversationId: A, mode: j, processingByConversationId: kt, setMode: M, setConversationMode: At, setActiveConversation: jt, createConversation: N, addMessage: P, updateMessage: Mt, patchMessage: Nt, mergeMessageMetadata: Pt, setConversationProcessing: F, clearConversationProcessing: Ft, setBackendSessionId: It, clearBackendSessionId: Lt, setSandbox: I, clearSandbox: Rt, acknowledgedWriteModes: zt, acknowledgeWriteMode: Bt, autoRouting: Vt, setAutoRouting: Ht, routeConversation: L } = v(), Ut = Ot.find((e) => e.id === A), R = nt(Ut), Wt = R.all, z = A ? kt[A] : void 0, Gt = Ie(z?.status), Kt = Gt ? z?.messageId ?? null : null, qt = z?.status === "error" ? z.messageId : null, { canUseApiCalls: B, loading: Jt } = tt(Ke()), V = S(Ce({
58
- loading: Jt,
59
- canUseAdminModes: B
60
- })).current, Yt = S(E);
61
- b(() => {
62
- Yt.current = E;
63
- }, [E]), b(() => {
64
- V.update({
65
- loading: Jt,
66
- canUseAdminModes: B
53
+ var St = ({ visible: St = !0, writeAccess: Ct = "unknown" }) => {
54
+ let O = r(), { product: k, modes: A, gatherPageContext: wt, buildPrompt: Tt, reportTokenUsage: Et } = n(), { getAccessToken: j, getWorkspaceToken: Dt, userId: M } = t(), { locale: Ot } = e(), kt = b((e) => e.assistantLanguage), At = b((e) => e.replyLanguage), jt = T(() => pe(kt, At, Ot), [
55
+ kt,
56
+ At,
57
+ Ot
58
+ ]), Mt = jt.reply.english, Nt = jt.replyIsExplicit, Pt = jt.reply.code, { conversations: Ft, activeConversationId: N, mode: P, processingByConversationId: It, setMode: F, setConversationMode: Lt, setActiveConversation: Rt, createConversation: I, addMessage: L, updateMessage: zt, patchMessage: Bt, mergeMessageMetadata: Vt, setConversationProcessing: R, clearConversationProcessing: Ht, setBackendSessionId: Ut, clearBackendSessionId: Wt, setSandbox: z, clearSandbox: Gt, acknowledgedWriteModes: Kt, acknowledgeWriteMode: qt, autoRouting: Jt, setAutoRouting: Yt, routeConversation: B } = b(), Xt = Ft.find((e) => e.id === N), V = ut(Xt), Zt = V.all, H = N ? It[N] : void 0, Qt = Pe(H?.status), $t = Qt ? H?.messageId ?? null : null, en = H?.status === "error" ? H.messageId : null, { canUseApiCalls: U, loading: tn } = lt(Xe()), W = E(v({
59
+ loading: tn,
60
+ canUseAdminModes: U
61
+ })).current, nn = E(A);
62
+ w(() => {
63
+ nn.current = A;
64
+ }, [A]), w(() => {
65
+ W.update({
66
+ loading: tn,
67
+ canUseAdminModes: U
67
68
  });
68
69
  }, [
69
- V,
70
- Jt,
71
- B
72
- ]), b(() => () => {
73
- V.abandon();
74
- }, [V]);
75
- let Xt = x(() => E.filter((e) => !e.requiresAdmin || B), [E, B]), Zt = Ne(Xt), Qt = Vt && Zt, $t = S(Zt);
76
- b(() => {
77
- $t.current = Zt;
78
- }, [Zt]);
79
- let H = S(null), en = _e(E), [U, tn] = dt(null), [nn, rn] = dt(!1), an = S({}), W = S(Je()), on = S(/* @__PURE__ */ new Set()), sn = S(/* @__PURE__ */ new Set()), G = x(() => E.find((e) => e.id === j), [E, j]), cn = j === "assistant" || G !== void 0 && !G.writeCapable && !re(j);
80
- b(() => {
81
- if (j !== "assistant" && G?.writeCapable && !Ee(zt, j)) {
82
- M("assistant");
70
+ W,
71
+ tn,
72
+ U
73
+ ]), w(() => () => {
74
+ W.abandon();
75
+ }, [W]);
76
+ let rn = T(() => A.filter((e) => !e.requiresAdmin || U), [A, U]), an = je(rn), on = Jt && an, sn = E(an);
77
+ w(() => {
78
+ sn.current = an;
79
+ }, [an]);
80
+ let cn = E(null), ln = _e(A), [un, dn] = _t(null), [fn, pn] = _t(!1), mn = E({}), G = E(et()), K = E(/* @__PURE__ */ new Set()), hn = E(/* @__PURE__ */ new Set()), q = T(() => A.find((e) => e.id === P), [A, P]), gn = P === "assistant" || q !== void 0 && !q.writeCapable && !ie(P);
81
+ w(() => {
82
+ if (P !== "assistant" && q?.writeCapable && !Te(Kt, P)) {
83
+ F("assistant");
83
84
  return;
84
85
  }
85
- Jt || (!G || G.requiresAdmin && !B) && j !== "assistant" && M("assistant");
86
+ tn || (!q || q.requiresAdmin && !U) && P !== "assistant" && F("assistant");
86
87
  }, [
87
- j,
88
- G,
89
- B,
90
- Jt,
91
- M,
92
- zt
88
+ P,
89
+ q,
90
+ U,
91
+ tn,
92
+ F,
93
+ Kt
93
94
  ]);
94
- let K = y((e, t, n, r) => {
95
- F(e, n, t, null, r);
96
- }, [F]), ln = y(async (e, t, n, r, a) => {
97
- let o = v.getState().sandboxesByMode[n]?.sandboxId ?? null, ee = async (e) => {
98
- if (W.current.isFresh(e)) return !0;
95
+ let J = C((e, t, n, r) => {
96
+ R(e, n, t, null, r);
97
+ }, [R]), _n = C(async function e(t, n, r, a, o, ee = {}) {
98
+ let ne = ee.trustCache !== !1, l = b.getState().sandboxesByMode[r]?.sandboxId ?? null, ie = !1, ae = !1, oe = !1, ce = !1, le = !1, f = async (e) => {
99
+ if (ne && !K.current.has(e) && G.current.isFresh(e)) return ie = !0, !0;
100
+ oe = !0;
101
+ let t = !1;
99
102
  try {
100
- return await oe(e, r, a, 3e5), await f(e, r, n, a, 9e4), W.current.markVerified(e), !0;
103
+ return await se(e, a, o, 3e5), await d(e, a, r, o, 9e4, () => {
104
+ t = !0;
105
+ }), G.current.markVerified(e), t && (ce = !0), !0;
101
106
  } catch {
102
- return W.current.invalidate(e), on.current.add(e), !1;
107
+ return G.current.invalidate(e), K.current.add(e), le = !0, !1;
103
108
  }
104
109
  };
105
- if (o && (I(n, o, "provisioning"), K(e, t, "provisioning", "reusingEnvironment"), await ee(o) || (I(n, null, "provisioning"), o = null)), !o) {
106
- K(e, t, "provisioning", "lookingForEnvironment");
107
- let i = await te(r, T, n, lt(), a, on.current);
108
- i && (I(n, i, "provisioning"), K(e, t, "provisioning", "reusingEnvironment"), await ee(i) ? o = i : I(n, null, "provisioning"));
110
+ if (l && (z(r, l, "provisioning"), J(t, n, "provisioning", "reusingEnvironment"), await f(l) || (z(r, null, "provisioning"), l = null)), !l) {
111
+ J(t, n, "provisioning", "lookingForEnvironment");
112
+ let e = await te(a, k, r, ht(), o, K.current), i = e?.id ?? null;
113
+ i && (z(r, i, "provisioning"), J(t, n, "provisioning", "reusingEnvironment"), await f(i) ? (l = i, (e?.status === "PROVISIONING" || e?.status === "PENDING") && (ce = !0)) : z(r, null, "provisioning"));
109
114
  }
110
- if (!o) {
111
- if (n === "api-calls" && !D()) throw Error("API Calls mode requires an authenticated session. Please sign in again.");
112
- K(e, t, "provisioning", "startingEnvironment"), I(n, null, "provisioning");
113
- let c = await d(r, T, n, lt(), a, on.current);
114
- if (c.length > 0) {
115
- let e = new Set(c);
116
- for (let e of c) W.current.invalidate(e), on.current.add(e);
117
- let t = v.getState().sandboxesByMode;
118
- for (let [n, r] of Object.entries(t)) i(n) && r?.sandboxId && e.has(r.sandboxId) && Rt(n);
115
+ if (!l) {
116
+ if (S(n, "provisionStarted"), r === "api-calls" && !j()) throw Error("API Calls mode requires an authenticated session. Please sign in again.");
117
+ J(t, n, "provisioning", "startingEnvironment"), z(r, null, "provisioning");
118
+ let e = await u(a, k, r, ht(), o, K.current);
119
+ if (e.length > 0) {
120
+ let t = new Set(e);
121
+ for (let t of e) G.current.invalidate(t), K.current.add(t);
122
+ let n = b.getState().sandboxesByMode;
123
+ for (let [e, r] of Object.entries(n)) i(e) && r?.sandboxId && t.has(r.sandboxId) && Gt(e);
119
124
  }
120
- o = await s(T, n, r, lt(), pt, a), I(n, o, "provisioning"), await oe(o, r, a, 3e5), await f(o, r, n, a, 9e4);
125
+ S(n, "createRequested"), l = await s(k, r, a, ht(), yt, o), ae = !0, z(r, l, "provisioning"), await se(l, a, o, 3e5), S(n, "sandboxRunning"), await d(l, a, r, o, 9e4), S(n, "serviceReady"), G.current.markVerified(l);
121
126
  }
122
- I(n, o, "running");
123
- let l = v.getState().conversations.find((t) => t.id === e)?.backendSessionId ?? null, ne = !1;
124
- if (l) try {
125
- let e = await u(o, r, l, n, a);
126
- if (e.mode !== n) throw Error(`Session mode mismatch: expected ${n}, received ${e.mode}`);
127
+ z(r, l, "running");
128
+ let p = b.getState().conversations.find((e) => e.id === t)?.backendSessionId ?? null, m = !1;
129
+ if (p) try {
130
+ let e = await re(l, a, p, r, o);
131
+ if (e.mode !== r) throw Error(`Session mode mismatch: expected ${r}, received ${e.mode}`);
127
132
  } catch {
128
- Lt(e), l = null;
133
+ Wt(t), p = null;
134
+ }
135
+ if (!p) {
136
+ J(t, n, "connecting", "preparingSession");
137
+ let i;
138
+ try {
139
+ i = await c(l, a, r, o);
140
+ } catch (i) {
141
+ if (ie) {
142
+ G.current.invalidate(l);
143
+ let s = nt(i, ee.isAbandoned?.() ?? !1), c = s === "check-network";
144
+ if (s === "check-network" && (s = await tt(() => te(a, k, r, ht(), o, K.current))), s !== "rethrow" && ee.isAbandoned?.() && (s = "rethrow"), s !== "rethrow") {
145
+ c || x(n, { cacheProofFailed: !0 }), s === "replace" && (K.current.add(l), Wt(t), Gt(r));
146
+ let i = await e(t, n, r, a, o, {
147
+ ...ee,
148
+ trustCache: !1
149
+ });
150
+ return c && (i.deadSandboxProbe || i.sandboxId !== l) && x(n, { cacheProofFailed: !0 }), {
151
+ ...i,
152
+ sandboxProbed: i.sandboxProbed || oe,
153
+ sandboxAdopted: i.sandboxAdopted || ce,
154
+ deadSandboxProbe: i.deadSandboxProbe || le
155
+ };
156
+ }
157
+ }
158
+ throw i;
159
+ }
160
+ p = i.sessionId, Ut(t, p), m = !0;
129
161
  }
130
- return l || (K(e, t, "connecting", "preparingSession"), l = (await c(o, r, n, a)).sessionId, It(e, l), ne = !0), {
131
- sandboxId: o,
132
- sessionId: l,
133
- sessionIsNew: ne
162
+ return {
163
+ sandboxId: l,
164
+ sessionId: p,
165
+ sessionIsNew: m,
166
+ sandboxIsNew: ae,
167
+ sandboxProbed: oe,
168
+ sandboxAdopted: ce,
169
+ deadSandboxProbe: le
134
170
  };
135
171
  }, [
136
- Lt,
137
- Rt,
138
- D,
139
- T,
140
- It,
141
- I,
142
- K
143
- ]), [un, dn] = dt(null), q = S(/* @__PURE__ */ new Set()), fn = S(null), pn = y(() => {
144
- let e = v.getState(), t = e.activeConversationId;
172
+ Wt,
173
+ Gt,
174
+ j,
175
+ k,
176
+ Ut,
177
+ z,
178
+ J
179
+ ]), [vn, yn] = _t(null), Y = E(/* @__PURE__ */ new Set()), bn = E(null), xn = C(() => {
180
+ let e = b.getState(), t = e.activeConversationId;
145
181
  if (!t) return;
146
- let n = e.processingByConversationId[t], r = Ie(n?.status) ? n?.messageId ?? null : null;
147
- if (!Re({
182
+ let n = e.processingByConversationId[t], r = Pe(n?.status) ? n?.messageId ?? null : null;
183
+ if (!Ie({
148
184
  interruptedTurnId: r,
149
185
  activeTurnId: r,
150
- alreadyRequested: r ? q.current.has(r) : !1
186
+ alreadyRequested: r ? Y.current.has(r) : !1
151
187
  }).send || !r) return;
152
- q.current.add(r);
153
- let i = Fe(e), o = qe(), s = e.conversations.find((e) => e.id === t)?.backendSessionId;
188
+ Y.current.add(r);
189
+ let i = Ne(e), o = Ze(), s = e.conversations.find((e) => e.id === t)?.backendSessionId;
154
190
  !i || !o || !s || a(i.sandboxId, o, s, i.mode, {
155
- accessToken: D(),
156
- workspaceToken: O(),
157
- userId: k,
158
- organizationId: Ke()
191
+ accessToken: j(),
192
+ workspaceToken: Dt(),
193
+ userId: M,
194
+ organizationId: Xe()
159
195
  });
160
196
  }, [
161
- k,
162
- D,
163
- O
164
- ]), mn = y(async (e) => {
165
- let t = v.getState(), n = Fe(t), r = qe(), i = t.activeConversationId;
197
+ M,
198
+ j,
199
+ Dt
200
+ ]), Sn = C(async (e) => {
201
+ let t = b.getState(), n = Ne(t), r = Ze(), i = t.activeConversationId;
166
202
  if (!(!n || !r || !i)) {
167
- dn(e);
203
+ yn(e);
168
204
  try {
169
205
  await o(n.sandboxId, r, e, n.mode, {
170
- accessToken: D(),
171
- workspaceToken: O(),
172
- userId: k,
173
- organizationId: Ke()
206
+ accessToken: j(),
207
+ workspaceToken: Dt(),
208
+ userId: M,
209
+ organizationId: Xe()
174
210
  });
175
211
  } catch (e) {
176
- dn(null), P(i, {
177
- id: ht(),
212
+ yn(null), L(i, {
213
+ id: xt(),
178
214
  role: "system",
179
215
  content: e instanceof Error ? e.message : "The change could not be approved.",
180
216
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
181
217
  });
182
218
  return;
183
219
  }
184
- dn(null), Y.current(w("pendingWrite.approvedPrompt", "I approved that change — go ahead."));
220
+ yn(null), Tn.current(O("pendingWrite.approvedPrompt", "I approved that change — go ahead."));
185
221
  }
186
222
  }, [
187
- k,
188
- P,
189
- w
190
- ]), J = y(async (e, t = [], n = {}) => {
191
- let r = n.voiceSessionId !== void 0, i = v.getState(), a = i.activeConversationId ?? A;
223
+ M,
224
+ L,
225
+ O
226
+ ]), X = C(async (e, t = [], n = {}) => {
227
+ let r = n.voiceSessionId !== void 0, i = b.getState(), a = i.activeConversationId ?? N;
192
228
  if (a) {
193
- if (Ie(i.processingByConversationId[a]?.status)) {
229
+ if (Pe(i.processingByConversationId[a]?.status)) {
194
230
  let r = i.processingByConversationId[a]?.messageId ?? null;
195
- r && q.current.has(r) && (fn.current = {
231
+ r && Y.current.has(r) && (bn.current = {
196
232
  conversationId: a,
197
233
  content: e,
198
234
  attachments: t,
@@ -200,11 +236,11 @@ var gt = ({ visible: gt = !0, writeAccess: _t = "unknown" }) => {
200
236
  });
201
237
  return;
202
238
  }
203
- if (sn.current.has(a)) return;
239
+ if (hn.current.has(a)) return;
204
240
  }
205
- if (H.current) return;
206
- let o = i.activeConversationId ? i.conversations.find((e) => e.id === i.activeConversationId) : void 0, s = i.autoRouting && $t.current ? Pe({
207
- intent: n.autoIntent ?? je(e),
241
+ if (cn.current) return;
242
+ let o = i.activeConversationId ? i.conversations.find((e) => e.id === i.activeConversationId) : void 0, s = i.autoRouting && sn.current ? Me({
243
+ intent: n.autoIntent ?? ke(e),
208
244
  dictated: r,
209
245
  conversation: o ? {
210
246
  mode: o.mode,
@@ -212,226 +248,253 @@ var gt = ({ visible: gt = !0, writeAccess: _t = "unknown" }) => {
212
248
  hasHistory: o.messages.length > 0 || !!o.backendSessionId
213
249
  } : null
214
250
  }) : null;
215
- if (s && Yt.current.find((e) => e.id === s.mode)?.writeCapable && !Ee(i.acknowledgedWriteModes, s.mode)) {
216
- H.current = {
251
+ if (s && nn.current.find((e) => e.id === s.mode)?.writeCapable && !Te(i.acknowledgedWriteModes, s.mode)) {
252
+ cn.current = {
217
253
  content: e,
218
254
  attachments: t,
219
255
  options: n
220
- }, tn(s.mode);
256
+ }, dn(s.mode);
221
257
  return;
222
258
  }
223
- let c = s ? s.mode : i.mode, te, u, d = A, f = d ? v.getState().conversations.find((e) => e.id === d) : void 0, oe = s?.action === "escalate" && o ? {
259
+ let c = s ? s.mode : i.mode, te, re, u = N, d = u ? b.getState().conversations.find((e) => e.id === u) : void 0, se = s?.action === "escalate" && o ? {
224
260
  mode: o.mode,
225
261
  backendSessionId: o.backendSessionId ?? null
226
262
  } : null;
227
- if (s) s.action === "new" || !o ? d = N(void 0, c, { routedBy: "auto" }) : (d = o.id, L(d, c));
263
+ if (s) s.action === "new" || !o ? u = I(void 0, c, { routedBy: "auto" }) : (u = o.id, B(u, c));
228
264
  else {
229
265
  let e = i.autoRouting ? { routedBy: "auto" } : void 0;
230
- d ? f && f.mode !== c && (f.messages.length > 0 || f.backendSessionId) ? d = N(void 0, c, e) : f && f.mode !== c && (e ? L(d, c) : At(d, c)) : d = N(void 0, c, e);
266
+ u ? d && d.mode !== c && (d.messages.length > 0 || d.backendSessionId) ? u = I(void 0, c, e) : d && d.mode !== c && (e ? B(u, c) : Lt(u, c)) : u = I(void 0, c, e);
231
267
  }
232
- if (!d) return;
233
- an.current[d] = t;
234
- let p = qe(), h = {
235
- accessToken: D(),
236
- workspaceToken: O(),
237
- userId: k,
238
- organizationId: Ke()
239
- }, le = {
240
- id: ht(),
268
+ if (!u) return;
269
+ mn.current[u] = t;
270
+ let f = Ze(), m = {
271
+ accessToken: j(),
272
+ workspaceToken: Dt(),
273
+ userId: M,
274
+ organizationId: Xe()
275
+ }, ue = {
276
+ id: xt(),
241
277
  role: "user",
242
278
  content: e,
243
279
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
244
280
  metadata: {
245
281
  ...t.length ? { attachments: t.map(ye) } : {},
246
- ...m(n.voiceSessionId)
282
+ ...p(n.voiceSessionId)
247
283
  }
248
284
  };
249
- P(d, le);
250
- let g = ht();
251
- P(d, {
252
- id: g,
285
+ L(u, ue);
286
+ let h = xt();
287
+ L(u, {
288
+ id: h,
253
289
  role: "assistant",
254
290
  content: "",
255
291
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
256
292
  metadata: {
257
- lang: Dt,
258
- ...m(n.voiceSessionId)
293
+ lang: Pt,
294
+ ...p(n.voiceSessionId)
259
295
  }
260
- }), F(d, "provisioning", g, null);
261
- let ue = (e, t, r, i, a = Dt) => {
262
- Nt(d, g, { content: se(e) }), Pt(d, g, {
296
+ }), Ge(h, {
297
+ channel: r ? "voice" : "chat",
298
+ mode: c,
299
+ product: k,
300
+ language: Pt,
301
+ device: Ke(),
302
+ routedByAuto: !!s
303
+ }, n.voiceTiming), S(h, "accepted"), R(u, "provisioning", h, null);
304
+ let de = (e, t, r, i, a = Pt) => {
305
+ Bt(u, h, { content: ce(e) }), Vt(u, h, {
263
306
  lang: a,
264
307
  ...t?.length ? { artifacts: t } : {},
265
308
  ...t?.length || r || i ? { mode: c } : {},
266
309
  ...r ? { sessionId: r } : {},
267
310
  ...i ? { sandboxId: i } : {},
268
- ...m(n.voiceSessionId)
311
+ ...p(n.voiceSessionId)
269
312
  });
270
- }, fe = async (n = 1) => {
271
- let i = !1;
313
+ }, g = async (n = 1) => {
314
+ S(h, "attemptStarted");
315
+ let i = null, a = !1;
272
316
  try {
273
- let { sandboxId: n, sessionId: a, sessionIsNew: o } = await ln(d, g, c, p, h), s = ke(v.getState().conversations.find((e) => e.id === d), e, o), re = await Ve(() => ne(n, p, a, c, h, { limit: 50 }), o);
274
- K(d, g, "streaming", "thinking");
275
- let f = vt?.(), { prompt: oe, parts: m } = Te({
276
- content: s ? `${s}${e}` : e,
317
+ let { sandboxId: n, sessionId: o, sessionIsNew: s, sandboxIsNew: ie, sandboxProbed: d, sandboxAdopted: se, deadSandboxProbe: p } = await _n(u, h, c, f, m, { isAbandoned: () => Fe({
318
+ turnId: h,
319
+ abortRequested: Y.current.has(h),
320
+ activeTurnId: b.getState().processingByConversationId[u]?.messageId ?? null
321
+ }).abandon });
322
+ i = n, S(h, "runtimeReady"), x(h, {
323
+ runtime: ie ? "cold" : se ? "adopted" : d ? "probed" : s ? "new-session" : "warm",
324
+ deadSandboxProbe: p
325
+ });
326
+ let ue = De(b.getState().conversations.find((e) => e.id === u), e, s), g = await Be(() => l(n, f, o, c, m, { limit: 50 }), s);
327
+ J(u, h, "streaming", "thinking");
328
+ let _ = wt?.(), { prompt: pe, parts: ge } = we({
329
+ content: ue ? `${ue}${e}` : e,
277
330
  attachments: t,
278
331
  limits: ve(te),
279
- wrapPrompt: (e) => yt?.(c, e, Tt, Et, r) ?? e,
280
- requestBytes: (e, t) => ie({
332
+ wrapPrompt: (e) => Tt?.(c, e, Mt, Nt, r) ?? e,
333
+ requestBytes: (e, t) => ae({
281
334
  sandboxId: n,
282
- workspaceId: p,
283
- sessionId: a,
335
+ workspaceId: f,
336
+ sessionId: o,
284
337
  mode: c,
285
338
  prompt: e,
286
339
  parts: t,
287
- pageContext: f,
288
- authContext: h
340
+ pageContext: _,
341
+ authContext: m
289
342
  })
290
- }), le = he(m), fe = le > 0;
291
- i = me(t) > le;
343
+ }), _e = he(ge), ye = _e > 0;
344
+ a = me(t) > _e;
292
345
  try {
293
- await ae(n, p, a, oe, c, f, h, m?.length ? { parts: m } : void 0);
346
+ await oe(n, f, o, pe, c, _, m, ge?.length ? { parts: ge } : void 0);
294
347
  } catch (e) {
295
- if (!m || !rt(e)) throw e;
296
- await ae(n, p, a, oe, c, f, h, void 0), i ||= fe;
348
+ if (!ge || !Qe(e)) throw e;
349
+ await oe(n, f, o, pe, c, _, m, void 0), a ||= ye;
297
350
  }
298
- let _ = Be([], re), pe = Date.now() + u.streamBudgetMs, ge = Date.now(), _e = Date.now(), ye = () => Le({
299
- turnId: g,
300
- abortRequested: q.current.has(g),
301
- activeTurnId: v.getState().processingByConversationId[d]?.messageId ?? null
351
+ S(h, "promptSent");
352
+ let be = null, xe = !1, Se = Re, v = ze([], g), Ce = Date.now() + re.streamBudgetMs, Te = Date.now(), Ee = Date.now(), y = () => Fe({
353
+ turnId: h,
354
+ abortRequested: Y.current.has(h),
355
+ activeTurnId: b.getState().processingByConversationId[u]?.messageId ?? null
302
356
  });
303
- for (; Date.now() < pe;) {
304
- let e = ye();
357
+ for (; Date.now() < Ce;) {
358
+ let e = y();
305
359
  if (e.abandon) {
306
- e.clearProcessing && Ft(d);
360
+ e.clearProcessing && Ht(u);
307
361
  return;
308
362
  }
309
- if (_ = Be(await ne(n, p, a, c, h, {
363
+ if (v = ze(await l(n, f, o, c, m, {
310
364
  limit: 50,
311
- sinceMs: re
312
- }), re, { accumulateNarration: u.accumulatesNarration }), Nt(d, g, { content: se(_.content) }), _.pendingWrite && Pt(d, g, { pendingWrite: _.pendingWrite }), _.done) break;
313
- Date.now() - ge > 3e4 && (await ee(n, p, 600, h).catch(() => void 0), ge = Date.now()), await new Promise((e) => setTimeout(e, de(Date.now() - _e)));
365
+ sinceMs: g
366
+ }), g, { accumulateNarration: re.accumulatesNarration }), Bt(u, h, { content: ce(v.content) }), v.hasRenderableOutput ? xe || (xe = !0, be !== null && S(h, "lastQuietPoll", be), S(h, "firstOutput")) : be = Je(), re.accumulatesNarration) v.hasText && S(h, "firstText");
367
+ else {
368
+ let e = Ve(Se, v, Je());
369
+ Se = e.tracker, e.confirmedAt !== null && S(h, "firstText", e.confirmedAt);
370
+ }
371
+ if (v.pendingWrite && Vt(u, h, { pendingWrite: v.pendingWrite }), v.done) {
372
+ S(h, "answerDone"), G.current.markVerified(n);
373
+ break;
374
+ }
375
+ Date.now() - Te > 3e4 && (await ee(n, f, 600, m).catch(() => void 0), Te = Date.now()), await new Promise((e) => setTimeout(e, fe(Date.now() - Ee)));
314
376
  }
315
- let be = u.producesArtifacts ? await l(n, p, a, c, h).then((e) => e).catch(() => []) : void 0;
316
- if (_.done || (_ = {
317
- ..._,
318
- content: ce(_.content, c, w, te)
319
- }), i && (_ = {
320
- ..._,
321
- content: `${_.content}\n\n${w("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._")}`
322
- }), ue(_.content, be, a, n), _.tokens) {
323
- Nt(d, g, { tokens: _.tokens });
377
+ let Oe = re.producesArtifacts ? await ne(n, f, o, c, m).then((e) => e).catch(() => []) : void 0;
378
+ if (v.usedTools !== void 0 && x(h, { usedTools: v.usedTools }), v.done || (x(h, { outcome: "timedOut" }), v = {
379
+ ...v,
380
+ content: le(v.content, c, O, te)
381
+ }), a && (v = {
382
+ ...v,
383
+ content: `${v.content}\n\n${O("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._")}`
384
+ }), de(v.content, Oe, o, n), v.tokens) {
385
+ Bt(u, h, { tokens: v.tokens });
324
386
  try {
325
- await bt?.({
326
- workspaceId: p,
327
- sessionId: a,
328
- messageId: _.messageId,
329
- model: _.model,
330
- tokens: _.tokens
331
- }), ot(T);
387
+ await Et?.({
388
+ workspaceId: f,
389
+ sessionId: o,
390
+ messageId: v.messageId,
391
+ model: v.model,
392
+ tokens: v.tokens
393
+ }), ft(k);
332
394
  } catch {}
333
395
  }
334
- let xe = ye();
335
- if (xe.abandon) {
336
- xe.clearProcessing && Ft(d);
396
+ let ke = y();
397
+ if (ke.abandon) {
398
+ ke.clearProcessing && Ht(u);
337
399
  return;
338
400
  }
339
- F(d, "complete", g, null);
401
+ S(h, "complete"), x(h, { outcome: "answered" }), R(u, "complete", h, null);
340
402
  } catch (e) {
341
- let t = Le({
342
- turnId: g,
343
- abortRequested: q.current.has(g),
344
- activeTurnId: v.getState().processingByConversationId[d]?.messageId ?? null
403
+ G.current.invalidate(i ?? b.getState().sandboxesByMode[c]?.sandboxId ?? null);
404
+ let t = Fe({
405
+ turnId: h,
406
+ abortRequested: Y.current.has(h),
407
+ activeTurnId: b.getState().processingByConversationId[u]?.messageId ?? null
345
408
  });
346
409
  if (t.abandon) {
347
- t.clearProcessing && Ft(d);
410
+ t.clearProcessing && Ht(u);
348
411
  return;
349
412
  }
350
- if (n === 1 && it(e)) {
351
- let e = v.getState().sandboxesByMode[c]?.sandboxId ?? null;
352
- return e && (on.current.add(e), W.current.invalidate(e)), Lt(d), Rt(c), Mt(d, g, ""), Pt(d, g, { pendingWrite: void 0 }), fe(2);
413
+ if (n === 1 && $e(e)) {
414
+ let e = i ?? b.getState().sandboxesByMode[c]?.sandboxId ?? null;
415
+ return e && (K.current.add(e), G.current.invalidate(e)), Wt(u), Gt(c), zt(u, h, ""), Vt(u, h, { pendingWrite: void 0 }), qe(h), g(2);
353
416
  }
354
417
  throw e;
355
418
  }
356
- }, _ = d;
357
- sn.current.add(_);
419
+ }, _ = u;
420
+ hn.current.add(_);
358
421
  try {
359
- if (!p) throw Object.assign(/* @__PURE__ */ Error("Assistant backend is unavailable without an active workspace context."), { extensions: {
422
+ if (!f) throw Object.assign(/* @__PURE__ */ Error("Assistant backend is unavailable without an active workspace context."), { extensions: {
360
423
  code: "UNAUTHENTICATED",
361
424
  authFailure: "WORKSPACE_CONTEXT_MISSING"
362
425
  } });
363
- let e = await we(c, () => Yt.current.find((e) => e.id === c), V);
364
- te = e.config, u = e.capabilities;
365
- let t = De(c, te, v.getState().acknowledgedWriteModes, {
426
+ let e = await Ce(c, () => nn.current.find((e) => e.id === c), W);
427
+ te = e.config, re = e.capabilities;
428
+ let t = Ee(c, te, b.getState().acknowledgedWriteModes, {
366
429
  dictated: r,
367
- confirmsWrites: re(c)
430
+ confirmsWrites: ie(c)
368
431
  });
369
432
  if (t) throw new be(t, t === "confirm-write-mode" ? "Write mode not confirmed" : "Voice in a write mode");
370
- await fe();
433
+ S(h, "cleared"), await g();
371
434
  } catch (e) {
372
- W.current.invalidate(v.getState().sandboxesByMode[c]?.sandboxId ?? null);
435
+ G.current.invalidate(b.getState().sandboxesByMode[c]?.sandboxId ?? null);
373
436
  let t = xe(e);
374
- t.offersUpgrade && at(T, "sandbox");
375
- let r = Se(t, w);
376
- F(d, "error", g, r.headline), Nt(d, g, { content: r.text }), Pt(d, g, {
377
- lang: r.translated ? xt : "en",
378
- ...m(n.voiceSessionId)
437
+ x(h, { outcome: t.kind === "temporary" ? "failed" : "refused" }), t.offersUpgrade && dt(k, "sandbox");
438
+ let r = Se(t, O);
439
+ R(u, "error", h, r.headline), Bt(u, h, { content: r.text }), Vt(u, h, {
440
+ lang: r.translated ? Ot : "en",
441
+ ...p(n.voiceSessionId)
379
442
  });
380
443
  } finally {
381
- sn.current.delete(_);
382
- let e = v.getState(), t = Me(oe, c, e.conversations.find((e) => e.id === _), (t) => !!e.sandboxesByMode[t]?.sandboxId);
383
- t && (L(_, t.mode), t.backendSessionId && It(_, t.backendSessionId));
384
- let n = fn.current;
385
- fn.current = null, n && n.conversationId === _ && Y.current(n.content, n.attachments, n.options);
444
+ hn.current.delete(_), x(h, { outcome: "stopped" }), S(h, "complete");
445
+ let e = b.getState(), t = Ae(se, c, e.conversations.find((e) => e.id === _), (t) => !!e.sandboxesByMode[t]?.sandboxId);
446
+ t && (B(_, t.mode), t.backendSessionId && Ut(_, t.backendSessionId));
447
+ let n = bn.current;
448
+ bn.current = null, n && n.conversationId === _ && Tn.current(n.content, n.attachments, n.options);
386
449
  }
387
450
  }, [
388
- A,
389
- P,
390
- yt,
391
- Lt,
392
- Rt,
393
- Ot,
394
451
  N,
395
- ln,
396
- vt,
397
- D,
398
- O,
399
- Nt,
400
- T,
401
- V,
402
- bt,
403
- Et,
404
- xt,
405
- Dt,
406
- Tt,
407
452
  L,
408
- It,
409
- At,
410
- F,
453
+ Tt,
454
+ Wt,
455
+ Gt,
411
456
  Ft,
412
- w,
413
- K,
457
+ I,
458
+ _n,
459
+ wt,
460
+ j,
461
+ Dt,
462
+ Bt,
463
+ k,
464
+ W,
465
+ Et,
466
+ Nt,
467
+ Ot,
468
+ Pt,
414
469
  Mt,
415
- k
416
- ]), hn = y((e, t) => {
417
- J(e, [], t ? { autoIntent: t } : {});
418
- }, [J]), gn = y(() => {
419
- let e = [...R.chat].reverse().find((e) => e.role === "user"), t = A ? an.current[A] ?? [] : [];
420
- e && J(e.content, t);
421
- }, [
422
- Wt,
470
+ B,
471
+ Ut,
472
+ Lt,
473
+ R,
474
+ Ht,
475
+ O,
423
476
  J,
424
- A
425
- ]), Y = S(J);
426
- b(() => {
427
- Y.current = J;
428
- }, [J]);
429
- let _n = x(() => {
430
- if (Gt) return null;
431
- for (let e = Wt.length - 1; e >= 0; --e) {
432
- let t = Wt[e];
433
- if (t?.role !== "assistant" || !p(t) || q.current.has(t.id)) continue;
434
- let n = ze(t, z, w);
477
+ zt,
478
+ M
479
+ ]), Cn = C((e, t) => {
480
+ X(e, [], t ? { autoIntent: t } : {});
481
+ }, [X]), wn = C(() => {
482
+ let e = [...V.chat].reverse().find((e) => e.role === "user"), t = N ? mn.current[N] ?? [] : [];
483
+ e && X(e.content, t);
484
+ }, [
485
+ Zt,
486
+ X,
487
+ N
488
+ ]), Tn = E(X);
489
+ w(() => {
490
+ Tn.current = X;
491
+ }, [X]);
492
+ let En = T(() => {
493
+ if (Qt) return null;
494
+ for (let e = Zt.length - 1; e >= 0; --e) {
495
+ let t = Zt[e];
496
+ if (t?.role !== "assistant" || !f(t) || Y.current.has(t.id)) continue;
497
+ let n = Le(t, H, O);
435
498
  if (n.kind !== "output") return null;
436
499
  let r = He(n.text).text.trim();
437
500
  return r ? {
@@ -441,249 +504,255 @@ var gt = ({ visible: gt = !0, writeAccess: _t = "unknown" }) => {
441
504
  }
442
505
  return null;
443
506
  }, [
444
- Wt,
445
- Gt,
446
- z,
447
- w
448
- ]), vn = x(() => _n ? fe(_n.text) : null, [_n]), yn = R.chat, X = x(() => R.voice.filter((e) => e.role === "user" || e.role === "assistant").map((e) => ({
507
+ Zt,
508
+ Qt,
509
+ H,
510
+ O
511
+ ]), Dn = T(() => En ? g(En.text) : null, [En]), On = V.chat, Z = T(() => V.voice.filter((e) => e.role === "user" || e.role === "assistant").map((e) => ({
449
512
  id: e.id,
450
513
  role: e.role,
451
- text: We(e, z, w),
452
- sessionId: h(e),
514
+ text: We(e, H, O),
515
+ sessionId: m(e),
453
516
  timestamp: e.timestamp
454
517
  })).filter((e) => e.text.length > 0), [
455
- R.voice,
456
- z,
457
- w
458
- ]), bn = y(() => {
459
- if (X.length === 0) return;
518
+ V.voice,
519
+ H,
520
+ O
521
+ ]), kn = C(() => {
522
+ if (Z.length === 0) return;
460
523
  let e = /* @__PURE__ */ new Date();
461
- Ze(g(X, {
462
- title: w("voiceSession.transcript", "Voice conversation"),
463
- savedAt: w("voiceSession.savedAt", "Saved"),
464
- session: w("voiceSession.sessionLabel", "Session"),
465
- earlier: w("voiceSession.earlierLabel", "Earlier"),
466
- you: w("voiceSession.speakerYou", "You"),
467
- assistant: w("voiceSession.speakerAssistant", "Assistant")
468
- }, e), ue(T, e), "text/markdown");
524
+ at(h(Z, {
525
+ title: O("voiceSession.transcript", "Voice conversation"),
526
+ savedAt: O("voiceSession.savedAt", "Saved"),
527
+ session: O("voiceSession.sessionLabel", "Session"),
528
+ earlier: O("voiceSession.earlierLabel", "Earlier"),
529
+ you: O("voiceSession.speakerYou", "You"),
530
+ assistant: O("voiceSession.speakerAssistant", "Assistant")
531
+ }, e), de(k, e), "text/markdown");
469
532
  }, [
470
- T,
471
- X,
472
- w
473
- ]), Z = st({ perFileChars: en }), xn = S(Z);
474
- xn.current = Z;
475
- let Q = Ge({
476
- onSubmit: y((e, t) => {
477
- let n = () => {
478
- let n = xn.current, r = ge(n.attachments);
479
- Y.current(e, r, { voiceSessionId: t }), n.clear();
533
+ k,
534
+ Z,
535
+ O
536
+ ]), Q = pt({ perFileChars: ln }), An = E(Q);
537
+ An.current = Q;
538
+ let $ = Ye({
539
+ onSubmit: C((e, t, n) => {
540
+ let r = () => {
541
+ let r = An.current, i = ge(r.attachments), a = {
542
+ ...n,
543
+ handedOver: Je()
544
+ };
545
+ Tn.current(e, i, {
546
+ voiceSessionId: t,
547
+ voiceTiming: a
548
+ }), r.clear();
480
549
  };
481
- if (!xn.current.isBusy) {
482
- n();
550
+ if (!An.current.isBusy) {
551
+ r();
483
552
  return;
484
553
  }
485
- let r = Date.now(), i = window.setInterval(() => {
486
- xn.current.isBusy && Date.now() - r < mt || (window.clearInterval(i), n());
554
+ let i = Date.now(), a = window.setInterval(() => {
555
+ An.current.isBusy && Date.now() - i < bt || (window.clearInterval(a), r());
487
556
  }, 200);
488
557
  }, []),
489
- latestReply: _n,
490
- language: _(St, xt).tag
491
- }), Sn = x(() => (Ut?.messages ?? []).reduce((e, t) => Math.max(e, t.metadata?.continuedVoiceTurns ?? 0), 0), [Ut?.messages]), $ = Ue(R.voice, z, w), Cn = $ > Sn, wn = y(() => {
492
- let e = v.getState().activeConversationId;
493
- !e || X.length === 0 || (P(e, {
494
- id: ht(),
558
+ latestReply: En,
559
+ language: _(kt, Ot).tag
560
+ }), jn = T(() => (Xt?.messages ?? []).reduce((e, t) => Math.max(e, t.metadata?.continuedVoiceTurns ?? 0), 0), [Xt?.messages]), Mn = Ue(V.voice, H, O), Nn = Mn > jn, Pn = C(() => {
561
+ let e = b.getState().activeConversationId;
562
+ !e || Z.length === 0 || (L(e, {
563
+ id: xt(),
495
564
  role: "system",
496
- content: le(X.slice(Sn), {
497
- intro: w("voiceSession.continuedIntro", "Continued from a voice conversation. You asked about:"),
498
- nothing: w("voiceSession.continuedNothing", "Continued from a voice conversation."),
499
- more: (e) => w("voiceSession.continuedMore", "…and {{count}} more", { count: e })
565
+ content: ue(Z.slice(jn), {
566
+ intro: O("voiceSession.continuedIntro", "Continued from a voice conversation. You asked about:"),
567
+ nothing: O("voiceSession.continuedNothing", "Continued from a voice conversation."),
568
+ more: (e) => O("voiceSession.continuedMore", "…and {{count}} more", { count: e })
500
569
  }),
501
570
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
502
- metadata: { continuedVoiceTurns: $ }
503
- }), rn(!1), Q.end());
571
+ metadata: { continuedVoiceTurns: Mn }
572
+ }), pn(!1), $.end());
504
573
  }, [
505
- X,
506
- $,
507
- Sn,
508
- P,
509
- w,
510
- Q
511
- ]), Tn = S(0);
512
- b(() => {
513
- Q.active && (Tn.current = $);
514
- }, [Q.active]);
515
- let En = y(() => {
516
- let e = $ > Tn.current;
517
- Q.end(), e && rn(!0);
518
- }, [$, Q]);
519
- b(() => {
520
- (!gt || !cn) && Q.active && Q.end();
574
+ Z,
575
+ Mn,
576
+ jn,
577
+ L,
578
+ O,
579
+ $
580
+ ]), Fn = E(0);
581
+ w(() => {
582
+ $.active && (Fn.current = Mn);
583
+ }, [$.active]);
584
+ let In = C(() => {
585
+ let e = Mn > Fn.current;
586
+ $.end(), e && pn(!0);
587
+ }, [Mn, $]);
588
+ w(() => {
589
+ (!St || !gn) && $.active && $.end();
521
590
  }, [
522
- gt,
523
- cn,
524
- Q
525
- ]), b(() => {
526
- Q.active || (xn.current.clear(), fn.current = null);
527
- }, [Q.active]), b(() => {
528
- let e = v.getState().consumePendingPrompt();
529
- return e && Y.current(e), v.subscribe((e, t) => {
591
+ St,
592
+ gn,
593
+ $
594
+ ]), w(() => {
595
+ $.active || (An.current.clear(), bn.current = null);
596
+ }, [$.active]), w(() => {
597
+ let e = b.getState().consumePendingPrompt();
598
+ return e && Tn.current(e), b.subscribe((e, t) => {
530
599
  if (e.pendingPrompt && e.pendingPrompt !== t.pendingPrompt) {
531
- let e = v.getState().consumePendingPrompt();
532
- e && Y.current(e);
600
+ let e = b.getState().consumePendingPrompt();
601
+ e && Tn.current(e);
533
602
  }
534
603
  });
535
604
  }, []);
536
- let Dn = y((e) => {
537
- let t = A ? v.getState().conversations.find((e) => e.id === A) : void 0;
605
+ let Ln = C((e) => {
606
+ let t = N ? b.getState().conversations.find((e) => e.id === N) : void 0;
538
607
  if (t && (t.messages.length > 0 || t.backendSessionId)) {
539
608
  if (t.mode !== e) {
540
- let t = v.getState().conversations.find((t) => t.mode === e && t.messages.length === 0 && !t.backendSessionId && !v.getState().processingByConversationId[t.id]);
541
- t ? jt(t.id) : N(void 0, e);
609
+ let t = b.getState().conversations.find((t) => t.mode === e && t.messages.length === 0 && !t.backendSessionId && !b.getState().processingByConversationId[t.id]);
610
+ t ? Rt(t.id) : I(void 0, e);
542
611
  }
543
- } else A && At(A, e);
544
- let n = v.getState().activeConversationId;
545
- n ? At(n, e) : Ht(!1), M(e);
612
+ } else N && Lt(N, e);
613
+ let n = b.getState().activeConversationId;
614
+ n ? Lt(n, e) : Yt(!1), F(e);
546
615
  }, [
547
- A,
548
616
  N,
549
- jt,
550
- Ht,
551
- At,
552
- M
553
- ]), On = y(() => {
554
- let e = v.getState(), t = e.activeConversationId ? e.conversations.find((t) => t.id === e.activeConversationId) : void 0;
617
+ I,
618
+ Rt,
619
+ Yt,
620
+ Lt,
621
+ F
622
+ ]), Rn = C(() => {
623
+ let e = b.getState(), t = e.activeConversationId ? e.conversations.find((t) => t.id === e.activeConversationId) : void 0;
555
624
  if (!t) {
556
- Ht(!0), M(Oe);
625
+ Yt(!0), F(y);
557
626
  return;
558
627
  }
559
628
  if (t.routedBy === "auto") {
560
- Ht(!0);
629
+ Yt(!0);
561
630
  return;
562
631
  }
563
632
  if (t.messages.length === 0 && !t.backendSessionId) {
564
- L(t.id, Oe);
633
+ B(t.id, y);
565
634
  return;
566
635
  }
567
636
  let n = e.conversations.find((t) => t.routedBy === "auto" && t.messages.length === 0 && !t.backendSessionId && !e.processingByConversationId[t.id]);
568
- n ? (jt(n.id), L(n.id, Oe)) : N(void 0, Oe, { routedBy: "auto" });
637
+ n ? (Rt(n.id), B(n.id, y)) : I(void 0, y, { routedBy: "auto" });
569
638
  }, [
570
- N,
571
- L,
572
- jt,
573
- Ht,
574
- M
575
- ]), kn = y((e) => {
576
- if (E.find((t) => t.id === e)?.writeCapable && !Ee(v.getState().acknowledgedWriteModes, e)) {
577
- tn(e);
639
+ I,
640
+ B,
641
+ Rt,
642
+ Yt,
643
+ F
644
+ ]), zn = C((e) => {
645
+ if (A.find((t) => t.id === e)?.writeCapable && !Te(b.getState().acknowledgedWriteModes, e)) {
646
+ dn(e);
578
647
  return;
579
648
  }
580
- Dn(e);
581
- }, [Dn, E]), An = y(() => {
582
- let e = U;
583
- if (tn(null), !e) return;
584
- let t = H.current;
585
- if (H.current = null, t) {
586
- Bt(e), J(t.content, t.attachments, t.options);
649
+ Ln(e);
650
+ }, [Ln, A]), Bn = C(() => {
651
+ let e = un;
652
+ if (dn(null), !e) return;
653
+ let t = cn.current;
654
+ if (cn.current = null, t) {
655
+ qt(e), X(t.content, t.attachments, t.options);
587
656
  return;
588
657
  }
589
- Bt(e), Dn(e);
658
+ qt(e), Ln(e);
590
659
  }, [
591
- U,
592
- Bt,
593
- Dn,
594
- J
595
- ]), jn = U === null ? void 0 : E.find((e) => e.id === U) ?? { id: U }, Mn = y(() => {
596
- tn(null);
597
- let e = H.current;
598
- H.current = null, e && J(e.content, e.attachments, {
660
+ un,
661
+ qt,
662
+ Ln,
663
+ X
664
+ ]), Vn = un === null ? void 0 : A.find((e) => e.id === un) ?? { id: un }, Hn = C(() => {
665
+ dn(null);
666
+ let e = cn.current;
667
+ cn.current = null, e && X(e.content, e.attachments, {
599
668
  ...e.options,
600
669
  autoIntent: "read"
601
670
  });
602
- }, [J]);
603
- return /* @__PURE__ */ ft("div", {
671
+ }, [X]);
672
+ return /* @__PURE__ */ vt("div", {
604
673
  className: "relative flex flex-1 flex-col overflow-hidden",
605
674
  children: [
606
- /* @__PURE__ */ ft("div", {
675
+ /* @__PURE__ */ vt("div", {
607
676
  className: "contents",
608
- inert: Q.active || void 0,
677
+ inert: $.active || void 0,
609
678
  children: [
610
- X.length > 0 && !Q.active ? /* @__PURE__ */ C(Ye, {
611
- count: X.length,
612
- onOpenTranscript: () => rn(!0)
679
+ Z.length > 0 && !$.active ? /* @__PURE__ */ D(rt, {
680
+ count: Z.length,
681
+ onOpenTranscript: () => pn(!0)
613
682
  }) : null,
614
- yn.length === 0 ? /* @__PURE__ */ C(Qe, {
615
- mode: j,
616
- onSuggestionClick: hn,
617
- explainsAuto: Qt,
618
- suggestions: Qt && j === "assistant" ? Ae(E.find((e) => e.id === "assistant")?.suggestions ?? [], E.find((e) => e.id === "api-calls")?.suggestions ?? []) : void 0
619
- }) : /* @__PURE__ */ C("div", {
683
+ On.length === 0 ? /* @__PURE__ */ D(ot, {
684
+ mode: P,
685
+ onSuggestionClick: Cn,
686
+ explainsAuto: on,
687
+ suggestions: on && P === "assistant" ? Oe(A.find((e) => e.id === "assistant")?.suggestions ?? [], A.find((e) => e.id === "api-calls")?.suggestions ?? []) : void 0
688
+ }) : /* @__PURE__ */ D("div", {
620
689
  className: "flex min-h-0 flex-1 flex-col",
621
- children: /* @__PURE__ */ C($e, {
622
- onApprovePendingWrite: mn,
623
- approvingWriteRef: un,
624
- messages: yn,
625
- processing: z ?? null,
626
- streamingMessageId: Kt,
627
- failedMessageId: qt,
628
- onRetry: gn
690
+ children: /* @__PURE__ */ D(st, {
691
+ onApprovePendingWrite: Sn,
692
+ approvingWriteRef: vn,
693
+ messages: On,
694
+ processing: H ?? null,
695
+ streamingMessageId: $t,
696
+ failedMessageId: en,
697
+ onRetry: wn
629
698
  })
630
699
  }),
631
- /* @__PURE__ */ C(ct, {
632
- onStartVoiceSession: Q.available && cn ? Q.start : void 0,
633
- onSend: (e, t) => void J(e, t),
634
- disabled: Gt,
635
- placeholder: j === "api-calls" ? w("chatArea.placeholderActions", "What would you like me to do?") : w("chatArea.placeholderGeneral", "Ask me anything…"),
636
- mode: j,
637
- writeAccessDenied: _t === "denied" && !!G?.writeCapable,
638
- availableModes: Xt,
639
- attachmentCharsPerFile: en,
640
- onModeChange: kn,
641
- auto: Zt ? {
642
- active: Qt,
643
- onSelect: On
700
+ /* @__PURE__ */ D(mt, {
701
+ onStartVoiceSession: $.available && gn ? $.start : void 0,
702
+ onSend: (e, t) => void X(e, t),
703
+ disabled: Qt,
704
+ placeholder: P === "api-calls" ? O("chatArea.placeholderActions", "What would you like me to do?") : O("chatArea.placeholderGeneral", "Ask me anything…"),
705
+ mode: P,
706
+ writeAccessDenied: Ct === "denied" && !!q?.writeCapable,
707
+ availableModes: rn,
708
+ attachmentCharsPerFile: ln,
709
+ onModeChange: zn,
710
+ auto: an ? {
711
+ active: on,
712
+ onSelect: Rn
644
713
  } : void 0
645
714
  })
646
715
  ]
647
716
  }),
648
- nn && !Q.active ? /* @__PURE__ */ C(Xe, {
649
- turns: X,
650
- onClose: () => rn(!1),
651
- onSave: bn,
652
- onContinueInChat: Cn ? wn : void 0,
717
+ fn && !$.active ? /* @__PURE__ */ D(it, {
718
+ turns: Z,
719
+ onClose: () => pn(!1),
720
+ onSave: kn,
721
+ onContinueInChat: Nn ? Pn : void 0,
653
722
  closeOnEscape: !0
654
723
  }) : null,
655
- Q.active && /* @__PURE__ */ C(et, {
656
- session: Q.session,
657
- notice: Q.notice,
658
- capturing: Q.capturing,
659
- interrupting: Q.interrupting,
660
- awaitingEndpoint: Q.awaitingEndpoint,
661
- turns: X,
662
- spokenChunks: Q.spokenChunks,
663
- attachments: Z.attachments,
664
- onAttachFiles: Z.addFiles,
665
- onRemoveAttachment: Z.remove,
666
- onRetryAttachment: Z.retry,
667
- canAttachMore: Z.canAddMore,
668
- preparingAttachments: Z.preparingCount,
669
- onSaveTranscript: bn,
670
- onContinueInChat: wn,
724
+ $.active && /* @__PURE__ */ D(ct, {
725
+ session: $.session,
726
+ notice: $.notice,
727
+ capturing: $.capturing,
728
+ interrupting: $.interrupting,
729
+ awaitingEndpoint: $.awaitingEndpoint,
730
+ turns: Z,
731
+ spokenChunks: $.spokenChunks,
732
+ attachments: Q.attachments,
733
+ onAttachFiles: Q.addFiles,
734
+ onRemoveAttachment: Q.remove,
735
+ onRetryAttachment: Q.retry,
736
+ canAttachMore: Q.canAddMore,
737
+ preparingAttachments: Q.preparingCount,
738
+ onSaveTranscript: kn,
739
+ onContinueInChat: Pn,
671
740
  onInterrupt: () => {
672
- Q.interrupt(), pn();
741
+ $.interrupt(), xn();
673
742
  },
674
- spoken: vn,
675
- onToggleMute: Q.toggleMute,
676
- onEnd: En
743
+ spoken: Dn,
744
+ onToggleMute: $.toggleMute,
745
+ onEnd: In
677
746
  }),
678
- /* @__PURE__ */ C(ut, {
679
- open: U !== null,
680
- mode: jn,
681
- currentMode: G ?? { id: j },
682
- onConfirm: An,
683
- onCancel: Mn
747
+ /* @__PURE__ */ D(gt, {
748
+ open: un !== null,
749
+ mode: Vn,
750
+ currentMode: q ?? { id: P },
751
+ onConfirm: Bn,
752
+ onCancel: Hn
684
753
  })
685
754
  ]
686
755
  });
687
756
  };
688
757
  //#endregion
689
- export { gt as AssistantChatArea };
758
+ export { St as AssistantChatArea };