@burdenoff/fe-libs 2026.925.4 → 2026.925.6

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