@burdenoff/fe-libs 2026.907.2 → 2026.908.2

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.
@@ -2,69 +2,69 @@ import { useI18n as e } from "../../providers/shell/I18nProvider.js";
2
2
  import { useAuthToken as t } from "../../providers/shell/AuthTokenProvider.js";
3
3
  import "../../../shared-providers-shell.js";
4
4
  import { describeQuotaError as n } from "../quota.js";
5
- import { approvePendingWrite as r, createAssistantSandbox as i, createAssistantSession as a, extendAssistantSandboxTTL as o, findExistingSandbox as s, getAssistantArtifacts as c, getAssistantMessages as l, getAssistantSession as u, releaseSupersededAssistantSandboxes as d, sendAssistantPromptAsync as f, waitForAssistantServiceReady as p, waitForSandboxRunning as m } from "../api.js";
6
- import { getAssistantMedia as h, sanitize as ee } from "../progress.js";
7
- import { isVoiceTurn as g, voiceMarker as _, voiceSessionIdOf as v } from "../voice/turnVisibility.js";
8
- import { buildContinuedFromVoiceNote as te, buildVoiceTranscriptMarkdown as y, voiceTranscriptFilename as ne } from "../voice/voiceTranscript.js";
9
- import { pollDelayMs as re } from "../voice/assistantPollSchedule.js";
10
- import { toCaptionText as ie } from "../voice/captionText.js";
11
- import { resolveAssistantLanguage as b } from "../voice/languages.js";
12
- import { resolveLanguagePair as ae } from "../voice/languagePair.js";
13
- import { findPendingWrite as oe } from "../pendingWrite.js";
14
- import { useAssistantProduct as se } from "../product.js";
15
- import { useAssistantTr as ce } from "../i18n.js";
16
- import { buildPromptParts as le, buildPromptWithAttachments as ue, countInlineImageCandidates as de, countInlinedImageParts as fe, getSendableAttachments as pe, toMessageAttachment as me } from "../attachments.js";
5
+ import { abortAssistantTurn as r, approvePendingWrite as i, createAssistantSandbox as a, createAssistantSession as o, extendAssistantSandboxTTL as s, findExistingSandbox as c, getAssistantArtifacts as l, getAssistantMessages as u, getAssistantSession as d, releaseSupersededAssistantSandboxes as f, sendAssistantPromptAsync as ee, waitForAssistantServiceReady as p, waitForSandboxRunning as m } from "../api.js";
6
+ import { getAssistantMedia as h, sanitize as te } from "../progress.js";
7
+ import { isVoiceTurn as g, voiceMarker as _, voiceSessionIdOf as ne } from "../voice/turnVisibility.js";
8
+ import { buildContinuedFromVoiceNote as v, buildVoiceTranscriptMarkdown as y, voiceTranscriptFilename as re } from "../voice/voiceTranscript.js";
9
+ import { pollDelayMs as ie } from "../voice/assistantPollSchedule.js";
10
+ import { toCaptionText as b } from "../voice/captionText.js";
11
+ import { resolveAssistantLanguage as ae } from "../voice/languages.js";
12
+ import { resolveLanguagePair as oe } from "../voice/languagePair.js";
13
+ import { findPendingWrite as se } from "../pendingWrite.js";
14
+ import { useAssistantProduct as ce } from "../product.js";
15
+ import { useAssistantTr as le } from "../i18n.js";
16
+ import { buildPromptParts as ue, buildPromptWithAttachments as de, countInlineImageCandidates as fe, countInlinedImageParts as pe, getSendableAttachments as me, toMessageAttachment as he } from "../attachments.js";
17
17
  import { useAssistantStore as x } from "../store.js";
18
- import { isTurnInFlight as he } from "../turnState.js";
19
- import { parseToolActivity as ge } from "./AssistantToolActivity.js";
20
- import { useVoiceSession as _e } from "./useVoiceSession.js";
21
- import { getOrganizationId as ve, getWorkspaceId as ye } from "../context.js";
22
- import { createReadinessTracker as be } from "../sandboxReadiness.js";
23
- import { AssistantSpokenTurnsNotice as xe } from "./AssistantSpokenTurnsNotice.js";
24
- import { VoiceTranscriptDrawer as Se } from "./voice/VoiceTranscriptDrawer.js";
25
- import { downloadFile as Ce } from "../exportConversation.js";
26
- import { AssistantEmptyState as we } from "./AssistantEmptyState.js";
27
- import { AssistantMessageList as Te } from "./AssistantMessageList.js";
28
- import { AssistantVoiceSession as Ee } from "./voice/AssistantVoiceSession.js";
29
- import { useAssistantApiAccess as De } from "../useAssistantApiAccess.js";
30
- import { useConversationTurns as Oe } from "../useConversationTurns.js";
31
- import { isMultimodalBodyRejection as ke, isRecoverableAssistantError as Ae } from "../transportErrors.js";
32
- import { dispatchAssistantQuotaExhausted as je, notifyAiCreditsUpdated as Me } from "../aiCredits.js";
33
- import { useAssistantAttachments as Ne } from "../useAssistantAttachments.js";
34
- import { AssistantComposer as Pe } from "./composer/AssistantComposer.js";
35
- import { isProdRuntime as Fe } from "../env.js";
36
- import { AssistantApiCallsConsentDialog as Ie } from "./AssistantApiCallsConsentDialog.js";
37
- import { useCallback as S, useEffect as C, useMemo as w, useRef as T, useState as Le } from "react";
38
- import { jsx as E, jsxs as Re } from "react/jsx-runtime";
18
+ import { isTurnInFlight as ge, planTurnAbort as _e } from "../turnState.js";
19
+ import { parseToolActivity as ve } from "./AssistantToolActivity.js";
20
+ import { useVoiceSession as ye } from "./useVoiceSession.js";
21
+ import { getOrganizationId as be, getWorkspaceId as xe } from "../context.js";
22
+ import { createReadinessTracker as Se } from "../sandboxReadiness.js";
23
+ import { AssistantSpokenTurnsNotice as Ce } from "./AssistantSpokenTurnsNotice.js";
24
+ import { VoiceTranscriptDrawer as we } from "./voice/VoiceTranscriptDrawer.js";
25
+ import { downloadFile as Te } from "../exportConversation.js";
26
+ import { AssistantEmptyState as Ee } from "./AssistantEmptyState.js";
27
+ import { AssistantMessageList as De } from "./AssistantMessageList.js";
28
+ import { AssistantVoiceSession as Oe } from "./voice/AssistantVoiceSession.js";
29
+ import { useAssistantApiAccess as ke } from "../useAssistantApiAccess.js";
30
+ import { useConversationTurns as Ae } from "../useConversationTurns.js";
31
+ import { isMultimodalBodyRejection as je, isRecoverableAssistantError as Me } from "../transportErrors.js";
32
+ import { dispatchAssistantQuotaExhausted as Ne, notifyAiCreditsUpdated as Pe } from "../aiCredits.js";
33
+ import { useAssistantAttachments as Fe } from "../useAssistantAttachments.js";
34
+ import { AssistantComposer as Ie } from "./composer/AssistantComposer.js";
35
+ import { isProdRuntime as Le } from "../env.js";
36
+ import { AssistantApiCallsConsentDialog as Re } from "./AssistantApiCallsConsentDialog.js";
37
+ import { useCallback as S, useEffect as C, useMemo as w, useRef as T, useState as ze } from "react";
38
+ import { jsx as E, jsxs as Be } from "react/jsx-runtime";
39
39
  //#region src/shared/assistant/ui/AssistantChatArea.tsx
40
- var ze = {
40
+ var Ve = {
41
41
  general: 18e4,
42
42
  assistant: 18e4,
43
43
  "api-calls": 18e4,
44
44
  "vibe-plugins": 6e5
45
- }, Be = 18e4, Ve = 600, He = 2e4;
46
- function Ue() {
45
+ }, He = 18e4, Ue = 600, We = 2e4;
46
+ function D() {
47
47
  return `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
48
48
  }
49
- function We(e) {
49
+ function O(e) {
50
50
  return e.info?.time?.created ?? 0;
51
51
  }
52
- function D(e) {
52
+ function k(e) {
53
53
  return (e ?? []).filter((e) => e.type === "text" && typeof e.text == "string").map((e) => e.text?.trim() ?? "").filter(Boolean).join("\n");
54
54
  }
55
- function O(e) {
55
+ function A(e) {
56
56
  return (e ?? []).filter((e) => e.type === "tool" && e.tool).map((e) => {
57
57
  let t = e.state?.status ?? "running", n = e.tool ?? "tool";
58
58
  return t === "completed" ? `Completed: ${n}` : t === "failed" ? `Failed: ${n}` : `Running: ${n}`;
59
59
  });
60
60
  }
61
61
  function Ge(e, t) {
62
- let n = e.filter((e) => e.info?.role === "assistant" && We(e) > t).sort((e, t) => We(e) - We(t));
62
+ let n = e.filter((e) => e.info?.role === "assistant" && O(e) > t).sort((e, t) => O(e) - O(t));
63
63
  if (n.length === 0) return {
64
64
  content: "Thinking...",
65
65
  done: !1
66
66
  };
67
- let r = n[n.length - 1], i = D(r.parts), a = h(r.parts), o = O(r.parts), s = oe(r.parts), c = [
67
+ let r = n[n.length - 1], i = k(r.parts), a = h(r.parts), o = A(r.parts), s = se(r.parts), c = [
68
68
  i,
69
69
  ...a,
70
70
  ...o
@@ -86,269 +86,289 @@ function Ke(e) {
86
86
  default: return "";
87
87
  }
88
88
  }
89
- var k = ({ visible: h = !0, writeAccess: oe = "unknown" }) => {
90
- let D = ce(), { product: O, modes: k, gatherPageContext: qe, buildPrompt: Je, reportTokenUsage: Ye } = se(), { getAccessToken: A, getWorkspaceToken: Xe, userId: Ze } = t(), { locale: Qe } = e(), $e = x((e) => e.assistantLanguage), et = x((e) => e.replyLanguage), tt = w(() => ae($e, et, Qe), [
91
- $e,
92
- et,
93
- Qe
94
- ]), nt = tt.reply.english, rt = tt.replyIsExplicit, it = tt.reply.code, { conversations: at, activeConversationId: j, mode: M, processingByConversationId: ot, setMode: st, setConversationMode: N, setActiveConversation: ct, createConversation: P, addMessage: F, updateMessage: lt, patchMessage: I, mergeMessageMetadata: ut, setConversationProcessing: L, setBackendSessionId: dt, clearBackendSessionId: ft, setSandbox: R, clearSandbox: pt, acknowledgeApiCalls: mt } = x(), ht = at.find((e) => e.id === j), z = Oe(ht), B = z.all, V = j ? ot[j] : void 0, H = he(V?.status), gt = H ? V?.messageId ?? null : null, _t = V?.status === "error" ? V.messageId : null, { canUseApiCalls: U, loading: vt } = De(ve()), yt = w(() => k.filter((e) => !e.requiresAdmin || U), [k, U]), [bt, xt] = Le(null), [St, W] = Le(!1), Ct = T({}), G = T(be()), wt = T(/* @__PURE__ */ new Set()), K = w(() => k.find((e) => e.id === M), [k, M]);
89
+ var j = ({ visible: h = !0, writeAccess: se = "unknown" }) => {
90
+ let k = le(), { product: A, modes: j, gatherPageContext: qe, buildPrompt: Je, reportTokenUsage: Ye } = ce(), { getAccessToken: M, getWorkspaceToken: N, userId: P } = t(), { locale: Xe } = e(), Ze = x((e) => e.assistantLanguage), Qe = x((e) => e.replyLanguage), $e = w(() => oe(Ze, Qe, Xe), [
91
+ Ze,
92
+ Qe,
93
+ Xe
94
+ ]), et = $e.reply.english, tt = $e.replyIsExplicit, nt = $e.reply.code, { conversations: rt, activeConversationId: F, mode: I, processingByConversationId: it, setMode: L, setConversationMode: R, setActiveConversation: at, createConversation: z, addMessage: B, updateMessage: ot, patchMessage: V, mergeMessageMetadata: st, setConversationProcessing: H, setBackendSessionId: ct, clearBackendSessionId: U, setSandbox: W, clearSandbox: lt, acknowledgeApiCalls: ut } = x(), dt = rt.find((e) => e.id === F), G = Ae(dt), K = G.all, ft = F ? it[F] : void 0, pt = ge(ft?.status), mt = pt ? ft?.messageId ?? null : null, ht = ft?.status === "error" ? ft.messageId : null, { canUseApiCalls: gt, loading: _t } = ke(be()), vt = w(() => j.filter((e) => !e.requiresAdmin || gt), [j, gt]), [yt, bt] = ze(null), [xt, St] = ze(!1), Ct = T({}), wt = T(Se()), Tt = T(/* @__PURE__ */ new Set()), Et = w(() => j.find((e) => e.id === I), [j, I]);
95
95
  C(() => {
96
- vt || (!K || K.requiresAdmin && !U) && M !== "assistant" && st("assistant");
96
+ _t || (!Et || Et.requiresAdmin && !gt) && I !== "assistant" && L("assistant");
97
97
  }, [
98
- M,
99
- K,
100
- U,
101
- vt,
102
- st
98
+ I,
99
+ Et,
100
+ gt,
101
+ _t,
102
+ L
103
103
  ]);
104
104
  let q = S((e, t, n, r) => {
105
- L(e, n, t, null), r ? lt(e, t, r) : lt(e, t, Ke(n));
106
- }, [L, lt]), Tt = S(async (e, t, n, r, o) => {
107
- let c = x.getState().sandboxesByMode[n]?.sandboxId ?? null, l = async (e) => {
108
- if (G.current.isFresh(e)) return !0;
105
+ H(e, n, t, null), r ? ot(e, t, r) : ot(e, t, Ke(n));
106
+ }, [H, ot]), Dt = S(async (e, t, n, r, i) => {
107
+ let s = x.getState().sandboxesByMode[n]?.sandboxId ?? null, l = async (e) => {
108
+ if (wt.current.isFresh(e)) return !0;
109
109
  try {
110
- return await m(e, r, o, 3e5), await p(e, r, o, 9e4), G.current.markVerified(e), !0;
110
+ return await m(e, r, i, 3e5), await p(e, r, i, 9e4), wt.current.markVerified(e), !0;
111
111
  } catch {
112
- return G.current.invalidate(e), !1;
112
+ return wt.current.invalidate(e), !1;
113
113
  }
114
114
  };
115
- if (c && (R(n, c, "provisioning"), q(e, t, "provisioning", "Reusing assistant environment..."), await l(c) || (R(n, null, "provisioning"), c = null)), !c) {
115
+ if (s && (W(n, s, "provisioning"), q(e, t, "provisioning", "Reusing assistant environment..."), await l(s) || (W(n, null, "provisioning"), s = null)), !s) {
116
116
  q(e, t, "provisioning", "Looking for existing environment...");
117
- let i = await s(r, O, n, Fe(), o);
118
- i && (R(n, i, "provisioning"), q(e, t, "provisioning", "Reusing assistant environment..."), await l(i) ? c = i : R(n, null, "provisioning"));
117
+ let a = await c(r, A, n, Le(), i);
118
+ a && (W(n, a, "provisioning"), q(e, t, "provisioning", "Reusing assistant environment..."), await l(a) ? s = a : W(n, null, "provisioning"));
119
119
  }
120
- if (!c) {
121
- if (n === "api-calls" && !A()) throw Error("API Calls mode requires an authenticated session. Please sign in again.");
122
- q(e, t, "provisioning", "Starting assistant environment..."), R(n, null, "provisioning"), await d(r, O, n, Fe(), o), c = await i(O, n, r, Fe(), Ve, o), R(n, c, "provisioning"), await m(c, r, o, 3e5), await p(c, r, o, 9e4);
120
+ if (!s) {
121
+ if (n === "api-calls" && !M()) throw Error("API Calls mode requires an authenticated session. Please sign in again.");
122
+ q(e, t, "provisioning", "Starting assistant environment..."), W(n, null, "provisioning"), await f(r, A, n, Le(), i), s = await a(A, n, r, Le(), Ue, i), W(n, s, "provisioning"), await m(s, r, i, 3e5), await p(s, r, i, 9e4);
123
123
  }
124
- R(n, c, "running");
125
- let f = x.getState().conversations.find((t) => t.id === e)?.backendSessionId ?? null;
126
- if (f) try {
127
- let e = await u(c, r, f, o);
124
+ W(n, s, "running");
125
+ let u = x.getState().conversations.find((t) => t.id === e)?.backendSessionId ?? null;
126
+ if (u) try {
127
+ let e = await d(s, r, u, i);
128
128
  if (e.mode !== n) throw Error(`Session mode mismatch: expected ${n}, received ${e.mode}`);
129
129
  } catch {
130
- ft(e), f = null;
130
+ U(e), u = null;
131
131
  }
132
- return f || (q(e, t, "connecting", "Preparing session..."), f = (await a(c, r, n, o)).sessionId, dt(e, f)), {
133
- sandboxId: c,
134
- sessionId: f
132
+ return u || (q(e, t, "connecting", "Preparing session..."), u = (await o(s, r, n, i)).sessionId, ct(e, u)), {
133
+ sandboxId: s,
134
+ sessionId: u
135
135
  };
136
136
  }, [
137
- ft,
137
+ U,
138
+ M,
138
139
  A,
139
- O,
140
- dt,
141
- R,
140
+ ct,
141
+ W,
142
142
  q
143
- ]), [Et, Dt] = Le(null), Ot = S(async (e) => {
144
- let t = x.getState(), n = t.sandboxesByMode[t.mode]?.sandboxId, i = ye(), a = t.activeConversationId;
145
- if (!(!n || !i || !a)) {
146
- Dt(e);
143
+ ]), [Ot, kt] = ze(null), At = T(/* @__PURE__ */ new Set()), jt = S(() => {
144
+ let e = x.getState(), t = e.activeConversationId;
145
+ if (!t) return;
146
+ let n = e.processingByConversationId[t], i = ge(n?.status) ? n?.messageId ?? null : null;
147
+ if (!_e({
148
+ interruptedTurnId: i,
149
+ activeTurnId: i,
150
+ alreadyRequested: i ? At.current.has(i) : !1
151
+ }).send || !i) return;
152
+ let a = e.sandboxesByMode[e.mode]?.sandboxId, o = xe(), s = e.conversations.find((e) => e.id === t)?.backendSessionId;
153
+ !a || !o || !s || (At.current.add(i), r(a, o, s, {
154
+ accessToken: M(),
155
+ workspaceToken: N(),
156
+ userId: P,
157
+ organizationId: be()
158
+ }));
159
+ }, [
160
+ P,
161
+ M,
162
+ N
163
+ ]), Mt = S(async (e) => {
164
+ let t = x.getState(), n = t.sandboxesByMode[t.mode]?.sandboxId, r = xe(), a = t.activeConversationId;
165
+ if (!(!n || !r || !a)) {
166
+ kt(e);
147
167
  try {
148
- await r(n, i, e, {
149
- accessToken: A(),
150
- workspaceToken: Xe(),
151
- userId: Ze,
152
- organizationId: ve()
168
+ await i(n, r, e, {
169
+ accessToken: M(),
170
+ workspaceToken: N(),
171
+ userId: P,
172
+ organizationId: be()
153
173
  });
154
174
  } catch (e) {
155
- Dt(null), F(a, {
156
- id: Ue(),
175
+ kt(null), B(a, {
176
+ id: D(),
157
177
  role: "system",
158
178
  content: e instanceof Error ? e.message : "The change could not be approved.",
159
179
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
160
180
  });
161
181
  return;
162
182
  }
163
- Dt(null), Y.current(D("pendingWrite.approvedPrompt", "I approved that change — go ahead."));
183
+ kt(null), Y.current(k("pendingWrite.approvedPrompt", "I approved that change — go ahead."));
164
184
  }
165
185
  }, [
166
- Ze,
167
- F,
168
- D
186
+ P,
187
+ B,
188
+ k
169
189
  ]), J = S(async (e, t = [], r = {}) => {
170
- let i = r.voiceSessionId !== void 0, a = x.getState(), s = a.activeConversationId ?? j;
171
- if (s && (he(a.processingByConversationId[s]?.status) || wt.current.has(s))) return;
172
- let u = a.mode, d = j, p = d ? x.getState().conversations.find((e) => e.id === d) : void 0;
173
- if (d ? p && p.mode !== u && (p.messages.length > 0 || p.backendSessionId) ? d = P(void 0, u) : p && p.mode !== u && N(d, u) : d = P(void 0, u), !d) return;
190
+ let i = r.voiceSessionId !== void 0, a = x.getState(), o = a.activeConversationId ?? F;
191
+ if (o && (ge(a.processingByConversationId[o]?.status) || Tt.current.has(o))) return;
192
+ let c = a.mode, d = F, f = d ? x.getState().conversations.find((e) => e.id === d) : void 0;
193
+ if (d ? f && f.mode !== c && (f.messages.length > 0 || f.backendSessionId) ? d = z(void 0, c) : f && f.mode !== c && R(d, c) : d = z(void 0, c), !d) return;
174
194
  Ct.current[d] = t;
175
- let m = ye(), h = {
176
- accessToken: A(),
177
- workspaceToken: Xe(),
178
- userId: Ze,
179
- organizationId: ve()
180
- }, g = {
181
- id: Ue(),
195
+ let p = xe(), m = {
196
+ accessToken: M(),
197
+ workspaceToken: N(),
198
+ userId: P,
199
+ organizationId: be()
200
+ }, h = {
201
+ id: D(),
182
202
  role: "user",
183
203
  content: e,
184
204
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
185
205
  metadata: {
186
- ...t.length ? { attachments: t.map(me) } : {},
206
+ ...t.length ? { attachments: t.map(he) } : {},
187
207
  ..._(r.voiceSessionId)
188
208
  }
189
209
  };
190
- F(d, g);
191
- let v = Ue();
192
- F(d, {
193
- id: v,
210
+ B(d, h);
211
+ let g = D();
212
+ B(d, {
213
+ id: g,
194
214
  role: "assistant",
195
215
  content: "",
196
216
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
197
217
  metadata: {
198
- lang: it,
218
+ lang: nt,
199
219
  ..._(r.voiceSessionId)
200
220
  }
201
- }), L(d, "provisioning", v, null);
202
- let te = (e, t, n, i, a = it) => {
203
- I(d, v, { content: ee(e) }), ut(d, v, {
221
+ }), H(d, "provisioning", g, null);
222
+ let ne = (e, t, n, i, a = nt) => {
223
+ V(d, g, { content: te(e) }), st(d, g, {
204
224
  lang: a,
205
225
  ...t?.length ? { artifacts: t } : {},
206
- ...t?.length || n || i ? { mode: u } : {},
226
+ ...t?.length || n || i ? { mode: c } : {},
207
227
  ...n ? { sessionId: n } : {},
208
228
  ...i ? { sandboxId: i } : {},
209
229
  ..._(r.voiceSessionId)
210
230
  });
211
- }, y = async (n = 1) => {
231
+ }, v = async (n = 1) => {
212
232
  let r = !1;
213
233
  try {
214
- let { sandboxId: n, sessionId: a } = await Tt(d, v, u, m, h), s = (await l(n, m, a, h, { limit: 50 }).catch(() => [])).reduce((e, t) => Math.max(e, We(t)), 0);
215
- q(d, v, "streaming", "Thinking...");
216
- let p = ue(e, t), g = Je?.(u, p, nt, rt, i) ?? p, _ = le(g, t), y = fe(_), ne = y > 0, ie = qe?.();
217
- r = de(t) > y;
234
+ let { sandboxId: n, sessionId: a } = await Dt(d, g, c, p, m), o = (await u(n, p, a, m, { limit: 50 }).catch(() => [])).reduce((e, t) => Math.max(e, O(t)), 0);
235
+ q(d, g, "streaming", "Thinking...");
236
+ let f = de(e, t), h = Je?.(c, f, et, tt, i) ?? f, _ = ue(h, t), v = pe(_), y = v > 0, re = qe?.();
237
+ r = fe(t) > v;
218
238
  try {
219
- await f(n, m, a, g, u, ie, h, _?.length ? { parts: _ } : void 0);
239
+ await ee(n, p, a, h, c, re, m, _?.length ? { parts: _ } : void 0);
220
240
  } catch (e) {
221
- if (!_ || !ke(e)) throw e;
222
- await f(n, m, a, g, u, ie, h, void 0), r ||= ne;
241
+ if (!_ || !je(e)) throw e;
242
+ await ee(n, p, a, h, c, re, m, void 0), r ||= y;
223
243
  }
224
- let b = Ge([], s), ae = Date.now() + (ze[u] ?? Be), oe = Date.now(), se = Date.now();
225
- for (; Date.now() < ae && (b = Ge(await l(n, m, a, h, {
244
+ let b = Ge([], o), ae = Date.now() + (Ve[c] ?? He), oe = Date.now(), se = Date.now();
245
+ for (; Date.now() < ae && (b = Ge(await u(n, p, a, m, {
226
246
  limit: 50,
227
- sinceMs: s
228
- }), s), I(d, v, { content: ee(b.content) }), b.pendingWrite && ut(d, v, { pendingWrite: b.pendingWrite }), !b.done);) Date.now() - oe > 3e4 && (await o(n, m, 600, h).catch(() => void 0), oe = Date.now()), await new Promise((e) => setTimeout(e, re(Date.now() - se)));
229
- if (!b.done && u !== "vibe-plugins") throw Error("Assistant response timed out while streaming progress");
230
- let ce = u === "vibe-plugins" ? await c(n, m, a, h).then((e) => e).catch(() => []) : void 0;
247
+ sinceMs: o
248
+ }), o), V(d, g, { content: te(b.content) }), b.pendingWrite && st(d, g, { pendingWrite: b.pendingWrite }), !b.done);) Date.now() - oe > 3e4 && (await s(n, p, 600, m).catch(() => void 0), oe = Date.now()), await new Promise((e) => setTimeout(e, ie(Date.now() - se)));
249
+ if (!b.done && c !== "vibe-plugins") throw Error("Assistant response timed out while streaming progress");
250
+ let ce = c === "vibe-plugins" ? await l(n, p, a, m).then((e) => e).catch(() => []) : void 0;
231
251
  if (b.done || (b = {
232
252
  ...b,
233
253
  content: `${b.content}\n\n_Still building in the background — any artifacts below will finish shortly. Re-open this conversation to pick up the completed plugin._`
234
254
  }), r && (b = {
235
255
  ...b,
236
- content: `${b.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._")}`
237
- }), te(b.content, ce, a, n), b.tokens) {
238
- I(d, v, { tokens: b.tokens });
256
+ content: `${b.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._")}`
257
+ }), ne(b.content, ce, a, n), b.tokens) {
258
+ V(d, g, { tokens: b.tokens });
239
259
  try {
240
260
  await Ye?.({
241
- workspaceId: m,
261
+ workspaceId: p,
242
262
  sessionId: a,
243
263
  messageId: b.messageId,
244
264
  model: b.model,
245
265
  tokens: b.tokens
246
- }), Me(O);
266
+ }), Pe(A);
247
267
  } catch {}
248
268
  }
249
- L(d, "complete", v, null);
269
+ H(d, "complete", g, null);
250
270
  } catch (e) {
251
- if (n === 1 && Ae(e)) return ft(d), pt(u), y(2);
271
+ if (n === 1 && Me(e)) return U(d), lt(c), v(2);
252
272
  throw e;
253
273
  }
254
- }, ne = d;
255
- wt.current.add(ne);
274
+ }, y = d;
275
+ Tt.current.add(y);
256
276
  try {
257
- if (!m) throw Error("Assistant backend is unavailable without an active workspace context.");
258
- await y();
277
+ if (!p) throw Error("Assistant backend is unavailable without an active workspace context.");
278
+ await v();
259
279
  } catch (e) {
260
- G.current.invalidate(x.getState().sandboxesByMode[u]?.sandboxId ?? null);
280
+ wt.current.invalidate(x.getState().sandboxesByMode[c]?.sandboxId ?? null);
261
281
  let t = n(e);
262
282
  if (t) {
263
- t.refusal === "exhausted" && je(O, "sandbox");
283
+ t.refusal === "exhausted" && Ne(A, "sandbox");
264
284
  let e = [t.quotaName, t.traceId ? `reference ${t.traceId}` : null].filter(Boolean).join(" · "), n = t.refusal === "exhausted" ? "You've reached your sandbox limit on the current plan. Upgrade to start the AI assistant." : "This workspace has no sandbox allowance provisioned, so the AI assistant cannot start. Upgrading will not help — ask an administrator to provision it.";
265
- te(e ? `${n}\n\n${e}` : n, void 0, void 0, void 0, "en"), L(d, "error", v, null);
285
+ ne(e ? `${n}\n\n${e}` : n, void 0, void 0, void 0, "en"), H(d, "error", g, null);
266
286
  return;
267
287
  }
268
288
  let i = e instanceof Error ? e.message : "Something went wrong";
269
- L(d, "error", v, i), I(d, v, { content: `Sorry, an error occurred: ${i}. Please try again.` }), ut(d, v, {
289
+ H(d, "error", g, i), V(d, g, { content: `Sorry, an error occurred: ${i}. Please try again.` }), st(d, g, {
270
290
  lang: "en",
271
291
  ..._(r.voiceSessionId)
272
292
  });
273
293
  } finally {
274
- wt.current.delete(ne);
294
+ Tt.current.delete(y);
275
295
  }
276
296
  }, [
277
- j,
278
297
  F,
298
+ B,
279
299
  Je,
280
- ft,
281
- pt,
282
- at,
283
- P,
284
- Tt,
300
+ U,
301
+ lt,
302
+ rt,
303
+ z,
304
+ Dt,
285
305
  qe,
306
+ M,
307
+ N,
308
+ V,
286
309
  A,
287
- Xe,
288
- I,
289
- O,
290
310
  Ye,
291
- rt,
292
- it,
311
+ tt,
293
312
  nt,
294
- dt,
295
- N,
296
- L,
297
- D,
313
+ et,
314
+ ct,
315
+ R,
316
+ H,
317
+ k,
298
318
  q,
299
- Ze
300
- ]), kt = S((e) => {
319
+ P
320
+ ]), Nt = S((e) => {
301
321
  J(e);
302
- }, [J]), At = S(() => {
303
- let e = [...z.chat].reverse().find((e) => e.role === "user"), t = j ? Ct.current[j] ?? [] : [];
322
+ }, [J]), Pt = S(() => {
323
+ let e = [...G.chat].reverse().find((e) => e.role === "user"), t = F ? Ct.current[F] ?? [] : [];
304
324
  e && J(e.content, t);
305
325
  }, [
306
- B,
326
+ K,
307
327
  J,
308
- j
328
+ F
309
329
  ]), Y = T(J);
310
330
  C(() => {
311
331
  Y.current = J;
312
332
  }, [J]);
313
- let jt = w(() => {
314
- if (H) return null;
315
- for (let e = B.length - 1; e >= 0; --e) {
316
- let t = B[e];
333
+ let Ft = w(() => {
334
+ if (pt) return null;
335
+ for (let e = K.length - 1; e >= 0; --e) {
336
+ let t = K[e];
317
337
  if (t?.role !== "assistant" || !g(t)) continue;
318
- let n = ge(t.content).text.trim();
338
+ let n = ve(t.content).text.trim();
319
339
  return n ? {
320
340
  id: t.id,
321
341
  text: n
322
342
  } : null;
323
343
  }
324
344
  return null;
325
- }, [B, H]), Mt = w(() => jt ? ie(jt.text) : null, [jt]), Nt = z.chat, X = w(() => z.voice.filter((e) => e.role === "user" || e.role === "assistant").map((e) => ({
345
+ }, [K, pt]), It = w(() => Ft ? b(Ft.text) : null, [Ft]), Lt = G.chat, X = w(() => G.voice.filter((e) => e.role === "user" || e.role === "assistant").map((e) => ({
326
346
  id: e.id,
327
347
  role: e.role,
328
- text: ge(e.content).text.trim(),
329
- sessionId: v(e),
348
+ text: ve(e.content).text.trim(),
349
+ sessionId: ne(e),
330
350
  timestamp: e.timestamp
331
- })).filter((e) => e.text.length > 0), [z.voice]), Pt = S(() => {
351
+ })).filter((e) => e.text.length > 0), [G.voice]), Rt = S(() => {
332
352
  if (X.length === 0) return;
333
353
  let e = /* @__PURE__ */ new Date();
334
- Ce(y(X, {
335
- title: D("voiceSession.transcript", "Voice conversation"),
336
- savedAt: D("voiceSession.savedAt", "Saved"),
337
- session: D("voiceSession.sessionLabel", "Session"),
338
- earlier: D("voiceSession.earlierLabel", "Earlier"),
339
- you: D("voiceSession.speakerYou", "You"),
340
- assistant: D("voiceSession.speakerAssistant", "Assistant")
341
- }, e), ne(O, e), "text/markdown");
354
+ Te(y(X, {
355
+ title: k("voiceSession.transcript", "Voice conversation"),
356
+ savedAt: k("voiceSession.savedAt", "Saved"),
357
+ session: k("voiceSession.sessionLabel", "Session"),
358
+ earlier: k("voiceSession.earlierLabel", "Earlier"),
359
+ you: k("voiceSession.speakerYou", "You"),
360
+ assistant: k("voiceSession.speakerAssistant", "Assistant")
361
+ }, e), re(A, e), "text/markdown");
342
362
  }, [
343
- O,
363
+ A,
344
364
  X,
345
- D
346
- ]), Z = Ne(), Q = T(Z);
365
+ k
366
+ ]), Z = Fe(), Q = T(Z);
347
367
  Q.current = Z;
348
- let $ = _e({
368
+ let $ = ye({
349
369
  onSubmit: S((e, t) => {
350
370
  let n = () => {
351
- let n = Q.current, r = pe(n.attachments);
371
+ let n = Q.current, r = me(n.attachments);
352
372
  Y.current(e, r, { voiceSessionId: t }), n.clear();
353
373
  };
354
374
  if (!Q.current.isBusy) {
@@ -356,37 +376,37 @@ var k = ({ visible: h = !0, writeAccess: oe = "unknown" }) => {
356
376
  return;
357
377
  }
358
378
  let r = Date.now(), i = window.setInterval(() => {
359
- Q.current.isBusy && Date.now() - r < He || (window.clearInterval(i), n());
379
+ Q.current.isBusy && Date.now() - r < We || (window.clearInterval(i), n());
360
380
  }, 200);
361
381
  }, []),
362
- latestReply: jt,
363
- language: b($e, Qe).tag
364
- }), Ft = w(() => (ht?.messages ?? []).reduce((e, t) => Math.max(e, t.metadata?.continuedVoiceTurns ?? 0), 0), [ht?.messages]), It = X.length > Ft, Lt = S(() => {
382
+ latestReply: Ft,
383
+ language: ae(Ze, Xe).tag
384
+ }), zt = w(() => (dt?.messages ?? []).reduce((e, t) => Math.max(e, t.metadata?.continuedVoiceTurns ?? 0), 0), [dt?.messages]), Bt = X.length > zt, Vt = S(() => {
365
385
  let e = x.getState().activeConversationId;
366
- !e || X.length === 0 || (F(e, {
367
- id: Ue(),
386
+ !e || X.length === 0 || (B(e, {
387
+ id: D(),
368
388
  role: "system",
369
- content: te(X.slice(Ft), {
370
- intro: D("voiceSession.continuedIntro", "Continued from a voice conversation. You asked about:"),
371
- nothing: D("voiceSession.continuedNothing", "Continued from a voice conversation."),
372
- more: (e) => D("voiceSession.continuedMore", "…and {{count}} more", { count: e })
389
+ content: v(X.slice(zt), {
390
+ intro: k("voiceSession.continuedIntro", "Continued from a voice conversation. You asked about:"),
391
+ nothing: k("voiceSession.continuedNothing", "Continued from a voice conversation."),
392
+ more: (e) => k("voiceSession.continuedMore", "…and {{count}} more", { count: e })
373
393
  }),
374
394
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
375
395
  metadata: { continuedVoiceTurns: X.length }
376
- }), W(!1), $.end());
396
+ }), St(!1), $.end());
377
397
  }, [
378
398
  X,
379
- Ft,
380
- F,
381
- D,
399
+ zt,
400
+ B,
401
+ k,
382
402
  $
383
- ]), Rt = T(0);
403
+ ]), Ht = T(0);
384
404
  C(() => {
385
- $.active && (Rt.current = X.length);
405
+ $.active && (Ht.current = X.length);
386
406
  }, [$.active]);
387
- let zt = S(() => {
388
- let e = X.length > Rt.current;
389
- $.end(), e && W(!0);
407
+ let Ut = S(() => {
408
+ let e = X.length > Ht.current;
409
+ $.end(), e && St(!0);
390
410
  }, [X, $]);
391
411
  C(() => {
392
412
  !h && $.active && $.end();
@@ -401,82 +421,82 @@ var k = ({ visible: h = !0, writeAccess: oe = "unknown" }) => {
401
421
  }
402
422
  });
403
423
  }, []);
404
- let Bt = S((e) => {
405
- let t = j ? x.getState().conversations.find((e) => e.id === j) : void 0;
424
+ let Wt = S((e) => {
425
+ let t = F ? x.getState().conversations.find((e) => e.id === F) : void 0;
406
426
  if (t && (t.messages.length > 0 || t.backendSessionId)) {
407
427
  if (t.mode !== e) {
408
428
  let t = x.getState().conversations.find((t) => t.mode === e && t.messages.length === 0 && !t.backendSessionId && !x.getState().processingByConversationId[t.id]);
409
- t ? ct(t.id) : P(void 0, e);
429
+ t ? at(t.id) : z(void 0, e);
410
430
  }
411
- } else j && N(j, e);
412
- st(e);
431
+ } else F && R(F, e);
432
+ L(e);
413
433
  }, [
414
- j,
415
- P,
416
- ct,
417
- N,
418
- st
419
- ]), Vt = S((e) => {
420
- if (k.find((t) => t.id === e)?.writeCapable && !x.getState().apiCallsAcknowledged) {
421
- xt(e);
434
+ F,
435
+ z,
436
+ at,
437
+ R,
438
+ L
439
+ ]), Gt = S((e) => {
440
+ if (j.find((t) => t.id === e)?.writeCapable && !x.getState().apiCallsAcknowledged) {
441
+ bt(e);
422
442
  return;
423
443
  }
424
- Bt(e);
425
- }, [Bt, k]), Ht = S(() => {
426
- let e = bt;
427
- xt(null), mt(), e && Bt(e);
444
+ Wt(e);
445
+ }, [Wt, j]), Kt = S(() => {
446
+ let e = yt;
447
+ bt(null), ut(), e && Wt(e);
428
448
  }, [
429
- bt,
430
- mt,
431
- Bt
432
- ]), Ut = S(() => {
433
- xt(null);
449
+ yt,
450
+ ut,
451
+ Wt
452
+ ]), qt = S(() => {
453
+ bt(null);
434
454
  }, []);
435
- return /* @__PURE__ */ Re("div", {
455
+ return /* @__PURE__ */ Be("div", {
436
456
  className: "relative flex flex-1 flex-col overflow-hidden",
437
457
  children: [
438
- /* @__PURE__ */ Re("div", {
458
+ /* @__PURE__ */ Be("div", {
439
459
  className: "contents",
440
460
  inert: $.active || void 0,
441
461
  children: [
442
- X.length > 0 && !$.active ? /* @__PURE__ */ E(xe, {
462
+ X.length > 0 && !$.active ? /* @__PURE__ */ E(Ce, {
443
463
  count: X.length,
444
- onOpenTranscript: () => W(!0)
464
+ onOpenTranscript: () => St(!0)
445
465
  }) : null,
446
- Nt.length === 0 ? /* @__PURE__ */ E(we, {
447
- mode: M,
448
- onSuggestionClick: kt
466
+ Lt.length === 0 ? /* @__PURE__ */ E(Ee, {
467
+ mode: I,
468
+ onSuggestionClick: Nt
449
469
  }) : /* @__PURE__ */ E("div", {
450
470
  className: "flex min-h-0 flex-1 flex-col",
451
- children: /* @__PURE__ */ E(Te, {
452
- onApprovePendingWrite: Ot,
453
- approvingWriteRef: Et,
454
- messages: Nt,
455
- streamingMessageId: gt,
456
- failedMessageId: _t,
457
- onRetry: At
471
+ children: /* @__PURE__ */ E(De, {
472
+ onApprovePendingWrite: Mt,
473
+ approvingWriteRef: Ot,
474
+ messages: Lt,
475
+ streamingMessageId: mt,
476
+ failedMessageId: ht,
477
+ onRetry: Pt
458
478
  })
459
479
  }),
460
- /* @__PURE__ */ E(Pe, {
461
- onStartVoiceSession: $.available && M !== "api-calls" ? $.start : void 0,
480
+ /* @__PURE__ */ E(Ie, {
481
+ onStartVoiceSession: $.available && I !== "api-calls" ? $.start : void 0,
462
482
  onSend: (e, t) => void J(e, t),
463
- disabled: H,
464
- placeholder: M === "api-calls" ? D("chatArea.placeholderActions", "What would you like me to do?") : D("chatArea.placeholderGeneral", "Ask me anything…"),
465
- mode: M,
466
- writeAccessDenied: oe === "denied" && !!K?.writeCapable,
467
- availableModes: yt,
468
- onModeChange: Vt
483
+ disabled: pt,
484
+ placeholder: I === "api-calls" ? k("chatArea.placeholderActions", "What would you like me to do?") : k("chatArea.placeholderGeneral", "Ask me anything…"),
485
+ mode: I,
486
+ writeAccessDenied: se === "denied" && !!Et?.writeCapable,
487
+ availableModes: vt,
488
+ onModeChange: Gt
469
489
  })
470
490
  ]
471
491
  }),
472
- St && !$.active ? /* @__PURE__ */ E(Se, {
492
+ xt && !$.active ? /* @__PURE__ */ E(we, {
473
493
  turns: X,
474
- onClose: () => W(!1),
475
- onSave: Pt,
476
- onContinueInChat: It ? Lt : void 0,
494
+ onClose: () => St(!1),
495
+ onSave: Rt,
496
+ onContinueInChat: Bt ? Vt : void 0,
477
497
  closeOnEscape: !0
478
498
  }) : null,
479
- $.active && /* @__PURE__ */ E(Ee, {
499
+ $.active && /* @__PURE__ */ E(Oe, {
480
500
  session: $.session,
481
501
  notice: $.notice,
482
502
  capturing: $.capturing,
@@ -490,20 +510,22 @@ var k = ({ visible: h = !0, writeAccess: oe = "unknown" }) => {
490
510
  onRetryAttachment: Z.retry,
491
511
  canAttachMore: Z.canAddMore,
492
512
  preparingAttachments: Z.preparingCount,
493
- onSaveTranscript: Pt,
494
- onContinueInChat: Lt,
495
- onInterrupt: $.interrupt,
496
- spoken: Mt,
513
+ onSaveTranscript: Rt,
514
+ onContinueInChat: Vt,
515
+ onInterrupt: () => {
516
+ $.interrupt(), jt();
517
+ },
518
+ spoken: It,
497
519
  onToggleMute: $.toggleMute,
498
- onEnd: zt
520
+ onEnd: Ut
499
521
  }),
500
- /* @__PURE__ */ E(Ie, {
501
- open: bt !== null,
502
- onConfirm: Ht,
503
- onCancel: Ut
522
+ /* @__PURE__ */ E(Re, {
523
+ open: yt !== null,
524
+ onConfirm: Kt,
525
+ onCancel: qt
504
526
  })
505
527
  ]
506
528
  });
507
529
  };
508
530
  //#endregion
509
- export { k as AssistantChatArea };
531
+ export { j as AssistantChatArea };