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