@burdenoff/fe-libs 2026.925.3 → 2026.925.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,195 +4,204 @@ 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 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";
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
- 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";
26
- import { parseToolActivity as He } from "./AssistantToolActivity.js";
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";
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";
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 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";
47
48
  //#region src/shared/assistant/ui/AssistantChatArea.tsx
48
- var pt = 600, mt = 2e4;
49
- function ht() {
49
+ var vt = 600, yt = 2e4;
50
+ function bt() {
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 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,
56
+ 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
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
+ 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");
83
84
  return;
84
85
  }
85
- Jt || (!G || G.requiresAdmin && !B) && j !== "assistant" && M("assistant");
86
+ en || (!q || q.requiresAdmin && !H) && N !== "assistant" && P("assistant");
86
87
  }, [
87
- j,
88
- G,
89
- B,
90
- Jt,
91
- M,
92
- zt
88
+ N,
89
+ q,
90
+ H,
91
+ en,
92
+ P,
93
+ Gt
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 = 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;
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, r, a, 3e5), await d(e, r, n, a, 9e4, () => {
104
+ t = !0;
105
+ }), K.current.markVerified(e), t && (re = !0), !0;
101
106
  } catch {
102
- return W.current.invalidate(e), on.current.add(e), !1;
107
+ return K.current.invalidate(e), fn.current.add(e), ae = !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 (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"));
109
114
  }
110
115
  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);
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);
114
119
  if (c.length > 0) {
115
120
  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);
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);
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
+ 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");
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);
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);
126
131
  if (e.mode !== n) throw Error(`Session mode mismatch: expected ${n}, received ${e.mode}`);
127
132
  } catch {
128
- Lt(e), l = null;
133
+ Ut(e), u = null;
129
134
  }
130
- return l || (K(e, t, "connecting", "preparingSession"), l = (await c(o, r, n, a)).sessionId, It(e, l), ne = !0), {
135
+ return u || (J(e, t, "connecting", "preparingSession"), u = (await c(o, r, n, a)).sessionId, Ht(e, u), ce = !0), {
131
136
  sandboxId: o,
132
- sessionId: l,
133
- sessionIsNew: ne
137
+ sessionId: u,
138
+ sessionIsNew: ce,
139
+ sandboxIsNew: ee,
140
+ sandboxProbed: ne,
141
+ sandboxAdopted: re,
142
+ deadSandboxProbe: ae
134
143
  };
135
144
  }, [
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;
145
+ Ut,
146
+ Wt,
147
+ A,
148
+ O,
149
+ Ht,
150
+ R,
151
+ J
152
+ ]), [gn, _n] = gt(null), Y = T(/* @__PURE__ */ new Set()), vn = T(null), yn = S(() => {
153
+ let e = y.getState(), t = e.activeConversationId;
145
154
  if (!t) return;
146
- let n = e.processingByConversationId[t], r = Ie(n?.status) ? n?.messageId ?? null : null;
147
- if (!Re({
155
+ let n = e.processingByConversationId[t], r = Fe(n?.status) ? n?.messageId ?? null : null;
156
+ if (!Le({
148
157
  interruptedTurnId: r,
149
158
  activeTurnId: r,
150
- alreadyRequested: r ? q.current.has(r) : !1
159
+ alreadyRequested: r ? Y.current.has(r) : !1
151
160
  }).send || !r) return;
152
- q.current.add(r);
153
- let i = Fe(e), o = qe(), s = e.conversations.find((e) => e.id === t)?.backendSessionId;
161
+ Y.current.add(r);
162
+ let i = Pe(e), o = Qe(), s = e.conversations.find((e) => e.id === t)?.backendSessionId;
154
163
  !i || !o || !s || a(i.sandboxId, o, s, i.mode, {
155
- accessToken: D(),
156
- workspaceToken: O(),
157
- userId: k,
158
- organizationId: Ke()
164
+ accessToken: A(),
165
+ workspaceToken: Et(),
166
+ userId: j,
167
+ organizationId: Ze()
159
168
  });
160
169
  }, [
161
- k,
162
- D,
163
- O
164
- ]), mn = y(async (e) => {
165
- let t = v.getState(), n = Fe(t), r = qe(), i = t.activeConversationId;
170
+ j,
171
+ A,
172
+ Et
173
+ ]), bn = S(async (e) => {
174
+ let t = y.getState(), n = Pe(t), r = Qe(), i = t.activeConversationId;
166
175
  if (!(!n || !r || !i)) {
167
- dn(e);
176
+ _n(e);
168
177
  try {
169
178
  await o(n.sandboxId, r, e, n.mode, {
170
- accessToken: D(),
171
- workspaceToken: O(),
172
- userId: k,
173
- organizationId: Ke()
179
+ accessToken: A(),
180
+ workspaceToken: Et(),
181
+ userId: j,
182
+ organizationId: Ze()
174
183
  });
175
184
  } catch (e) {
176
- dn(null), P(i, {
177
- id: ht(),
185
+ _n(null), I(i, {
186
+ id: bt(),
178
187
  role: "system",
179
188
  content: e instanceof Error ? e.message : "The change could not be approved.",
180
189
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
181
190
  });
182
191
  return;
183
192
  }
184
- dn(null), Y.current(w("pendingWrite.approvedPrompt", "I approved that change — go ahead."));
193
+ _n(null), Cn.current(D("pendingWrite.approvedPrompt", "I approved that change — go ahead."));
185
194
  }
186
195
  }, [
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;
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;
192
201
  if (a) {
193
- if (Ie(i.processingByConversationId[a]?.status)) {
202
+ if (Fe(i.processingByConversationId[a]?.status)) {
194
203
  let r = i.processingByConversationId[a]?.messageId ?? null;
195
- r && q.current.has(r) && (fn.current = {
204
+ r && Y.current.has(r) && (vn.current = {
196
205
  conversationId: a,
197
206
  content: e,
198
207
  attachments: t,
@@ -200,11 +209,11 @@ var gt = ({ visible: gt = !0, writeAccess: _t = "unknown" }) => {
200
209
  });
201
210
  return;
202
211
  }
203
- if (sn.current.has(a)) return;
212
+ if (pn.current.has(a)) return;
204
213
  }
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),
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),
208
217
  dictated: r,
209
218
  conversation: o ? {
210
219
  mode: o.mode,
@@ -212,228 +221,250 @@ var gt = ({ visible: gt = !0, writeAccess: _t = "unknown" }) => {
212
221
  hasHistory: o.messages.length > 0 || !!o.backendSessionId
213
222
  } : null
214
223
  }) : null;
215
- if (s && Yt.current.find((e) => e.id === s.mode)?.writeCapable && !Ee(i.acknowledgedWriteModes, s.mode)) {
216
- H.current = {
224
+ if (s && tn.current.find((e) => e.id === s.mode)?.writeCapable && !Te(i.acknowledgedWriteModes, s.mode)) {
225
+ W.current = {
217
226
  content: e,
218
227
  attachments: t,
219
228
  options: n
220
- }, tn(s.mode);
229
+ }, cn(s.mode);
221
230
  return;
222
231
  }
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 ? {
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 ? {
224
233
  mode: o.mode,
225
234
  backendSessionId: o.backendSessionId ?? null
226
235
  } : null;
227
- if (s) s.action === "new" || !o ? d = N(void 0, c, { routedBy: "auto" }) : (d = o.id, L(d, c));
236
+ if (s) s.action === "new" || !o ? l = F(void 0, c, { routedBy: "auto" }) : (l = o.id, z(l, c));
228
237
  else {
229
238
  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);
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);
231
240
  }
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(),
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()
248
+ }, ue = {
249
+ id: bt(),
241
250
  role: "user",
242
251
  content: e,
243
252
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
244
253
  metadata: {
245
254
  ...t.length ? { attachments: t.map(ye) } : {},
246
- ...m(n.voiceSessionId)
255
+ ...p(n.voiceSessionId)
247
256
  }
248
257
  };
249
- P(d, le);
250
- let g = ht();
251
- P(d, {
252
- id: g,
258
+ I(l, ue);
259
+ let h = bt();
260
+ I(l, {
261
+ id: h,
253
262
  role: "assistant",
254
263
  content: "",
255
264
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
256
265
  metadata: {
257
- lang: Dt,
258
- ...m(n.voiceSessionId)
266
+ lang: Nt,
267
+ ...p(n.voiceSessionId)
259
268
  }
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, {
269
+ }), Ke(h, {
270
+ channel: r ? "voice" : "chat",
271
+ mode: c,
272
+ product: O,
273
+ language: Nt,
274
+ device: qe(),
275
+ 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, {
263
279
  lang: a,
264
280
  ...t?.length ? { artifacts: t } : {},
265
281
  ...t?.length || r || i ? { mode: c } : {},
266
282
  ...r ? { sessionId: r } : {},
267
283
  ...i ? { sandboxId: i } : {},
268
- ...m(n.voiceSessionId)
284
+ ...p(n.voiceSessionId)
269
285
  });
270
- }, fe = async (n = 1) => {
286
+ }, g = async (n = 1) => {
287
+ x(h, "attemptStarted");
271
288
  let i = !1;
272
289
  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,
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
294
+ });
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,
277
299
  attachments: t,
278
300
  limits: ve(te),
279
- wrapPrompt: (e) => yt?.(c, e, Tt, Et, r) ?? e,
280
- requestBytes: (e, t) => ie({
301
+ wrapPrompt: (e) => wt?.(c, e, jt, Mt, r) ?? e,
302
+ requestBytes: (e, t) => oe({
281
303
  sandboxId: n,
282
- workspaceId: p,
304
+ workspaceId: f,
283
305
  sessionId: a,
284
306
  mode: c,
285
307
  prompt: e,
286
308
  parts: t,
287
- pageContext: f,
288
- authContext: h
309
+ pageContext: g,
310
+ authContext: m
289
311
  })
290
- }), le = he(m), fe = le > 0;
291
- i = me(t) > le;
312
+ }), ge = he(pe), _e = ge > 0;
313
+ i = me(t) > ge;
292
314
  try {
293
- await ae(n, p, a, oe, c, f, h, m?.length ? { parts: m } : void 0);
315
+ await u(n, f, a, _, c, g, m, pe?.length ? { parts: pe } : void 0);
294
316
  } catch (e) {
295
- if (!m || !rt(e)) throw e;
296
- await ae(n, p, a, oe, c, f, h, void 0), i ||= fe;
317
+ if (!pe || !ct(e)) throw e;
318
+ await u(n, f, a, _, c, g, m, void 0), i ||= _e;
297
319
  }
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
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({
322
+ turnId: h,
323
+ abortRequested: Y.current.has(h),
324
+ activeTurnId: y.getState().processingByConversationId[l]?.messageId ?? null
302
325
  });
303
- for (; Date.now() < pe;) {
304
- let e = ye();
326
+ for (; Date.now() < Se;) {
327
+ let e = Ee();
305
328
  if (e.abandon) {
306
- e.clearProcessing && Ft(d);
329
+ e.clearProcessing && Vt(l);
307
330
  return;
308
331
  }
309
- if (_ = Be(await ne(n, p, a, c, h, {
332
+ if (v = Be(await re(n, f, a, c, m, {
310
333
  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)));
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");
336
+ else {
337
+ let e = He(xe, v, Ye());
338
+ xe = e.tracker, e.confirmedAt !== null && x(h, "firstText", e.confirmedAt);
339
+ }
340
+ if (v.pendingWrite && Bt(l, h, { pendingWrite: v.pendingWrite }), v.done) {
341
+ x(h, "answerDone");
342
+ break;
343
+ }
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)));
314
345
  }
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 });
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 = {
348
+ ...v,
349
+ content: le(v.content, c, D, te)
350
+ }), i && (v = {
351
+ ...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 });
324
355
  try {
325
- await bt?.({
326
- workspaceId: p,
356
+ await Tt?.({
357
+ workspaceId: f,
327
358
  sessionId: a,
328
- messageId: _.messageId,
329
- model: _.model,
330
- tokens: _.tokens
331
- }), ot(T);
359
+ messageId: v.messageId,
360
+ model: v.model,
361
+ tokens: v.tokens
362
+ }), dt(O);
332
363
  } catch {}
333
364
  }
334
- let xe = ye();
335
- if (xe.abandon) {
336
- xe.clearProcessing && Ft(d);
365
+ let ke = Ee();
366
+ if (ke.abandon) {
367
+ ke.clearProcessing && Vt(l);
337
368
  return;
338
369
  }
339
- F(d, "complete", g, null);
370
+ x(h, "complete"), b(h, { outcome: "answered" }), L(l, "complete", h, null);
340
371
  } catch (e) {
341
- let t = Le({
342
- turnId: g,
343
- abortRequested: q.current.has(g),
344
- activeTurnId: v.getState().processingByConversationId[d]?.messageId ?? null
372
+ let t = Ie({
373
+ turnId: h,
374
+ abortRequested: Y.current.has(h),
375
+ activeTurnId: y.getState().processingByConversationId[l]?.messageId ?? null
345
376
  });
346
377
  if (t.abandon) {
347
- t.clearProcessing && Ft(d);
378
+ t.clearProcessing && Vt(l);
348
379
  return;
349
380
  }
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);
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);
353
384
  }
354
385
  throw e;
355
386
  }
356
- }, _ = d;
357
- sn.current.add(_);
387
+ }, _ = l;
388
+ pn.current.add(_);
358
389
  try {
359
- if (!p) throw Object.assign(/* @__PURE__ */ Error("Assistant backend is unavailable without an active workspace context."), { extensions: {
390
+ if (!f) throw Object.assign(/* @__PURE__ */ Error("Assistant backend is unavailable without an active workspace context."), { extensions: {
360
391
  code: "UNAUTHENTICATED",
361
392
  authFailure: "WORKSPACE_CONTEXT_MISSING"
362
393
  } });
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, {
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, {
366
397
  dictated: r,
367
- confirmsWrites: re(c)
398
+ confirmsWrites: ae(c)
368
399
  });
369
400
  if (t) throw new be(t, t === "confirm-write-mode" ? "Write mode not confirmed" : "Voice in a write mode");
370
- await fe();
401
+ x(h, "cleared"), await g();
371
402
  } catch (e) {
372
- W.current.invalidate(v.getState().sandboxesByMode[c]?.sandboxId ?? null);
403
+ K.current.invalidate(y.getState().sandboxesByMode[c]?.sandboxId ?? null);
373
404
  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)
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",
409
+ ...p(n.voiceSessionId)
379
410
  });
380
411
  } 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);
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);
386
417
  }
387
418
  }, [
419
+ M,
420
+ I,
421
+ wt,
422
+ Ut,
423
+ Wt,
424
+ Pt,
425
+ F,
426
+ hn,
427
+ Ct,
388
428
  A,
389
- P,
390
- yt,
391
- Lt,
392
- Rt,
393
- Ot,
394
- N,
395
- ln,
396
- vt,
397
- D,
398
- O,
399
- Nt,
400
- T,
401
- V,
402
- bt,
403
429
  Et,
404
- xt,
405
- Dt,
430
+ zt,
431
+ O,
432
+ U,
406
433
  Tt,
407
- L,
408
- It,
409
- At,
410
- F,
411
- Ft,
412
- w,
413
- K,
414
434
  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,
435
+ Dt,
436
+ Nt,
437
+ jt,
438
+ z,
439
+ Ht,
440
+ It,
441
+ L,
442
+ Vt,
443
+ D,
423
444
  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);
445
+ Rt,
446
+ j
447
+ ]), xn = S((e, t) => {
448
+ 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] ?? [] : [];
451
+ e && X(e.content, t);
452
+ }, [
453
+ Xt,
454
+ X,
455
+ M
456
+ ]), Cn = T(X);
457
+ C(() => {
458
+ Cn.current = X;
459
+ }, [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];
464
+ if (t?.role !== "assistant" || !f(t) || Y.current.has(t.id)) continue;
465
+ let n = Re(t, V, D);
435
466
  if (n.kind !== "output") return null;
436
- let r = He(n.text).text.trim();
467
+ let r = Ue(n.text).text.trim();
437
468
  return r ? {
438
469
  id: t.id,
439
470
  text: r
@@ -441,249 +472,255 @@ var gt = ({ visible: gt = !0, writeAccess: _t = "unknown" }) => {
441
472
  }
442
473
  return null;
443
474
  }, [
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) => ({
475
+ Xt,
476
+ 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) => ({
449
480
  id: e.id,
450
481
  role: e.role,
451
- text: We(e, z, w),
452
- sessionId: h(e),
482
+ text: Ge(e, V, D),
483
+ sessionId: m(e),
453
484
  timestamp: e.timestamp
454
485
  })).filter((e) => e.text.length > 0), [
455
- R.voice,
456
- z,
457
- w
458
- ]), bn = y(() => {
459
- if (X.length === 0) return;
486
+ B.voice,
487
+ V,
488
+ D
489
+ ]), Dn = S(() => {
490
+ if (Z.length === 0) return;
460
491
  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");
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");
469
500
  }, [
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();
501
+ O,
502
+ Z,
503
+ D
504
+ ]), Q = ft({ perFileChars: sn }), On = T(Q);
505
+ On.current = Q;
506
+ let $ = Xe({
507
+ onSubmit: S((e, t, n) => {
508
+ let r = () => {
509
+ let r = On.current, i = ge(r.attachments), a = {
510
+ ...n,
511
+ handedOver: Ye()
512
+ };
513
+ Cn.current(e, i, {
514
+ voiceSessionId: t,
515
+ voiceTiming: a
516
+ }), r.clear();
480
517
  };
481
- if (!xn.current.isBusy) {
482
- n();
518
+ if (!On.current.isBusy) {
519
+ r();
483
520
  return;
484
521
  }
485
- let r = Date.now(), i = window.setInterval(() => {
486
- xn.current.isBusy && Date.now() - r < mt || (window.clearInterval(i), n());
522
+ let i = Date.now(), a = window.setInterval(() => {
523
+ On.current.isBusy && Date.now() - i < yt || (window.clearInterval(a), r());
487
524
  }, 200);
488
525
  }, []),
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(),
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(),
495
532
  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 })
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 })
500
537
  }),
501
538
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
502
- metadata: { continuedVoiceTurns: $ }
503
- }), rn(!1), Q.end());
539
+ metadata: { continuedVoiceTurns: An }
540
+ }), un(!1), $.end());
504
541
  }, [
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();
542
+ Z,
543
+ An,
544
+ kn,
545
+ I,
546
+ D,
547
+ $
548
+ ]), Nn = T(0);
549
+ C(() => {
550
+ $.active && (Nn.current = An);
551
+ }, [$.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();
521
558
  }, [
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) => {
559
+ xt,
560
+ mn,
561
+ $
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) => {
530
567
  if (e.pendingPrompt && e.pendingPrompt !== t.pendingPrompt) {
531
- let e = v.getState().consumePendingPrompt();
532
- e && Y.current(e);
568
+ let e = y.getState().consumePendingPrompt();
569
+ e && Cn.current(e);
533
570
  }
534
571
  });
535
572
  }, []);
536
- let Dn = y((e) => {
537
- let t = A ? v.getState().conversations.find((e) => e.id === A) : void 0;
573
+ let Fn = S((e) => {
574
+ let t = M ? y.getState().conversations.find((e) => e.id === M) : void 0;
538
575
  if (t && (t.messages.length > 0 || t.backendSessionId)) {
539
576
  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);
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);
542
579
  }
543
- } else A && At(A, e);
544
- let n = v.getState().activeConversationId;
545
- n ? At(n, e) : Ht(!1), M(e);
580
+ } else M && It(M, e);
581
+ let n = y.getState().activeConversationId;
582
+ n ? It(n, e) : Jt(!1), P(e);
546
583
  }, [
547
- A,
548
- 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;
584
+ M,
585
+ F,
586
+ 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;
555
592
  if (!t) {
556
- Ht(!0), M(Oe);
593
+ Jt(!0), P(De);
557
594
  return;
558
595
  }
559
596
  if (t.routedBy === "auto") {
560
- Ht(!0);
597
+ Jt(!0);
561
598
  return;
562
599
  }
563
600
  if (t.messages.length === 0 && !t.backendSessionId) {
564
- L(t.id, Oe);
601
+ z(t.id, De);
565
602
  return;
566
603
  }
567
604
  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" });
605
+ n ? (Lt(n.id), z(n.id, De)) : F(void 0, De, { routedBy: "auto" });
569
606
  }, [
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);
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);
578
615
  return;
579
616
  }
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);
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);
587
624
  return;
588
625
  }
589
- Bt(e), Dn(e);
626
+ Kt(e), Fn(e);
590
627
  }, [
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, {
628
+ G,
629
+ Kt,
630
+ Fn,
631
+ 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, {
599
636
  ...e.options,
600
637
  autoIntent: "read"
601
638
  });
602
- }, [J]);
603
- return /* @__PURE__ */ ft("div", {
639
+ }, [X]);
640
+ return /* @__PURE__ */ _t("div", {
604
641
  className: "relative flex flex-1 flex-col overflow-hidden",
605
642
  children: [
606
- /* @__PURE__ */ ft("div", {
643
+ /* @__PURE__ */ _t("div", {
607
644
  className: "contents",
608
- inert: Q.active || void 0,
645
+ inert: $.active || void 0,
609
646
  children: [
610
- X.length > 0 && !Q.active ? /* @__PURE__ */ C(Ye, {
611
- count: X.length,
612
- onOpenTranscript: () => rn(!0)
647
+ Z.length > 0 && !$.active ? /* @__PURE__ */ E(et, {
648
+ count: Z.length,
649
+ onOpenTranscript: () => un(!0)
613
650
  }) : 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", {
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", {
620
657
  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
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
629
666
  })
630
667
  }),
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
668
+ /* @__PURE__ */ E(pt, {
669
+ onStartVoiceSession: $.available && mn ? $.start : void 0,
670
+ 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
644
681
  } : void 0
645
682
  })
646
683
  ]
647
684
  }),
648
- nn && !Q.active ? /* @__PURE__ */ C(Xe, {
649
- turns: X,
650
- onClose: () => rn(!1),
651
- onSave: bn,
652
- onContinueInChat: Cn ? wn : void 0,
685
+ ln && !$.active ? /* @__PURE__ */ E(tt, {
686
+ turns: Z,
687
+ onClose: () => un(!1),
688
+ onSave: Dn,
689
+ onContinueInChat: jn ? Mn : void 0,
653
690
  closeOnEscape: !0
654
691
  }) : 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,
692
+ $.active && /* @__PURE__ */ E(at, {
693
+ session: $.session,
694
+ notice: $.notice,
695
+ capturing: $.capturing,
696
+ interrupting: $.interrupting,
697
+ awaitingEndpoint: $.awaitingEndpoint,
698
+ turns: Z,
699
+ spokenChunks: $.spokenChunks,
700
+ attachments: Q.attachments,
701
+ onAttachFiles: Q.addFiles,
702
+ onRemoveAttachment: Q.remove,
703
+ onRetryAttachment: Q.retry,
704
+ canAttachMore: Q.canAddMore,
705
+ preparingAttachments: Q.preparingCount,
706
+ onSaveTranscript: Dn,
707
+ onContinueInChat: Mn,
671
708
  onInterrupt: () => {
672
- Q.interrupt(), pn();
709
+ $.interrupt(), yn();
673
710
  },
674
- spoken: vn,
675
- onToggleMute: Q.toggleMute,
676
- onEnd: En
711
+ spoken: Tn,
712
+ onToggleMute: $.toggleMute,
713
+ onEnd: Pn
677
714
  }),
678
- /* @__PURE__ */ C(ut, {
679
- open: U !== null,
680
- mode: jn,
681
- currentMode: G ?? { id: j },
682
- onConfirm: An,
683
- onCancel: Mn
715
+ /* @__PURE__ */ E(ht, {
716
+ open: G !== null,
717
+ mode: zn,
718
+ currentMode: q ?? { id: N },
719
+ onConfirm: Rn,
720
+ onCancel: Bn
684
721
  })
685
722
  ]
686
723
  });
687
724
  };
688
725
  //#endregion
689
- export { gt as AssistantChatArea };
726
+ export { xt as AssistantChatArea };