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