@burdenoff/fe-libs 2026.908.1 → 2026.909.1

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, planAbandonedTurn as _e, planTurnAbort as ve } from "../turnState.js";
19
+ import { parseToolActivity as ye } from "./AssistantToolActivity.js";
20
+ import { useVoiceSession as be } from "./useVoiceSession.js";
21
+ import { getOrganizationId as xe, getWorkspaceId as Se } from "../context.js";
22
+ import { createReadinessTracker as Ce } from "../sandboxReadiness.js";
23
+ import { AssistantSpokenTurnsNotice as we } from "./AssistantSpokenTurnsNotice.js";
24
+ import { VoiceTranscriptDrawer as Te } from "./voice/VoiceTranscriptDrawer.js";
25
+ import { downloadFile as Ee } from "../exportConversation.js";
26
+ import { AssistantEmptyState as De } from "./AssistantEmptyState.js";
27
+ import { AssistantMessageList as Oe } from "./AssistantMessageList.js";
28
+ import { AssistantVoiceSession as ke } from "./voice/AssistantVoiceSession.js";
29
+ import { useAssistantApiAccess as Ae } from "../useAssistantApiAccess.js";
30
+ import { useConversationTurns as je } from "../useConversationTurns.js";
31
+ import { isMultimodalBodyRejection as Me, isRecoverableAssistantError as Ne } from "../transportErrors.js";
32
+ import { dispatchAssistantQuotaExhausted as Pe, notifyAiCreditsUpdated as Fe } from "../aiCredits.js";
33
+ import { useAssistantAttachments as Ie } from "../useAssistantAttachments.js";
34
+ import { AssistantComposer as Le } from "./composer/AssistantComposer.js";
35
+ import { isProdRuntime as Re } from "../env.js";
36
+ import { AssistantApiCallsConsentDialog as ze } from "./AssistantApiCallsConsentDialog.js";
37
+ import { useCallback as S, useEffect as C, useMemo as w, useRef as T, useState as Be } from "react";
38
+ import { jsx as E, jsxs as Ve } from "react/jsx-runtime";
39
39
  //#region src/shared/assistant/ui/AssistantChatArea.tsx
40
- var ze = {
40
+ var He = {
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
+ }, Ue = 18e4, We = 600, Ge = 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
- function Ge(e, t) {
62
- let n = e.filter((e) => e.info?.role === "assistant" && We(e) > t).sort((e, t) => We(e) - We(t));
61
+ function Ke(e, 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
@@ -78,7 +78,7 @@ function Ge(e, t) {
78
78
  ...s ? { pendingWrite: s } : {}
79
79
  };
80
80
  }
81
- function Ke(e) {
81
+ function qe(e) {
82
82
  switch (e) {
83
83
  case "provisioning": return "Starting assistant environment...";
84
84
  case "connecting": return "Connecting to assistant...";
@@ -86,424 +86,464 @@ 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), [
89
+ var j = ({ visible: h = !0, writeAccess: se = "unknown" }) => {
90
+ let k = le(), { product: A, modes: j, gatherPageContext: Je, buildPrompt: Ye, reportTokenUsage: Xe } = ce(), { getAccessToken: M, getWorkspaceToken: N, userId: P } = t(), { locale: Ze } = e(), Qe = x((e) => e.assistantLanguage), $e = x((e) => e.replyLanguage), et = w(() => oe(Qe, $e, Ze), [
91
+ Qe,
91
92
  $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]);
93
+ Ze
94
+ ]), tt = et.reply.english, nt = et.replyIsExplicit, rt = et.reply.code, { conversations: it, activeConversationId: F, mode: I, processingByConversationId: at, setMode: L, setConversationMode: R, setActiveConversation: ot, createConversation: z, addMessage: B, updateMessage: st, patchMessage: V, mergeMessageMetadata: ct, setConversationProcessing: H, clearConversationProcessing: lt, setBackendSessionId: ut, clearBackendSessionId: U, setSandbox: W, clearSandbox: dt, acknowledgeApiCalls: ft } = x(), pt = it.find((e) => e.id === F), G = je(pt), mt = G.all, ht = F ? at[F] : void 0, gt = ge(ht?.status), _t = gt ? ht?.messageId ?? null : null, vt = ht?.status === "error" ? ht.messageId : null, { canUseApiCalls: yt, loading: bt } = Ae(xe()), xt = w(() => j.filter((e) => !e.requiresAdmin || yt), [j, yt]), [St, Ct] = Be(null), [wt, Tt] = Be(!1), Et = T({}), Dt = T(Ce()), Ot = T(/* @__PURE__ */ new Set()), kt = w(() => j.find((e) => e.id === I), [j, I]);
95
95
  C(() => {
96
- vt || (!K || K.requiresAdmin && !U) && M !== "assistant" && st("assistant");
96
+ bt || (!kt || kt.requiresAdmin && !yt) && I !== "assistant" && L("assistant");
97
97
  }, [
98
- M,
99
- K,
100
- U,
101
- vt,
102
- st
98
+ I,
99
+ kt,
100
+ yt,
101
+ bt,
102
+ L
103
103
  ]);
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;
104
+ let K = S((e, t, n, r) => {
105
+ H(e, n, t, null), r ? st(e, t, r) : st(e, t, qe(n));
106
+ }, [H, st]), At = S(async (e, t, n, r, i) => {
107
+ let s = x.getState().sandboxesByMode[n]?.sandboxId ?? null, l = async (e) => {
108
+ if (Dt.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), Dt.current.markVerified(e), !0;
111
111
  } catch {
112
- return G.current.invalidate(e), !1;
112
+ return Dt.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) {
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"));
115
+ if (s && (W(n, s, "provisioning"), K(e, t, "provisioning", "Reusing assistant environment..."), await l(s) || (W(n, null, "provisioning"), s = null)), !s) {
116
+ K(e, t, "provisioning", "Looking for existing environment...");
117
+ let a = await c(r, A, n, Re(), i);
118
+ a && (W(n, a, "provisioning"), K(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
+ K(e, t, "provisioning", "Starting assistant environment..."), W(n, null, "provisioning"), await f(r, A, n, Re(), i), s = await a(A, n, r, Re(), We, 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 || (K(e, t, "connecting", "Preparing session..."), u = (await o(s, r, n, i)).sessionId, ut(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,
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);
140
+ ut,
141
+ W,
142
+ K
143
+ ]), [jt, Mt] = Be(null), Nt = T(/* @__PURE__ */ new Set()), Pt = 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 (!ve({
148
+ interruptedTurnId: i,
149
+ activeTurnId: i,
150
+ alreadyRequested: i ? Nt.current.has(i) : !1
151
+ }).send || !i) return;
152
+ let a = e.sandboxesByMode[e.mode]?.sandboxId, o = Se(), s = e.conversations.find((e) => e.id === t)?.backendSessionId;
153
+ !a || !o || !s || (Nt.current.add(i), r(a, o, s, {
154
+ accessToken: M(),
155
+ workspaceToken: N(),
156
+ userId: P,
157
+ organizationId: xe()
158
+ }));
159
+ }, [
160
+ P,
161
+ M,
162
+ N
163
+ ]), Ft = S(async (e) => {
164
+ let t = x.getState(), n = t.sandboxesByMode[t.mode]?.sandboxId, r = Se(), a = t.activeConversationId;
165
+ if (!(!n || !r || !a)) {
166
+ Mt(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: xe()
153
173
  });
154
174
  } catch (e) {
155
- Dt(null), F(a, {
156
- id: Ue(),
175
+ Mt(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
+ Mt(null), J.current(k("pendingWrite.approvedPrompt", "I approved that change — go ahead."));
164
184
  }
165
185
  }, [
166
- Ze,
167
- F,
168
- D
169
- ]), 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;
174
- 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(),
186
+ P,
187
+ B,
188
+ k
189
+ ]), q = S(async (e, t = [], r = {}) => {
190
+ let i = r.voiceSessionId !== void 0, a = x.getState(), o = a.activeConversationId ?? F;
191
+ if (o && (ge(a.processingByConversationId[o]?.status) || Ot.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;
194
+ Et.current[d] = t;
195
+ let p = Se(), m = {
196
+ accessToken: M(),
197
+ workspaceToken: N(),
198
+ userId: P,
199
+ organizationId: xe()
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: rt,
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 = rt) => {
223
+ V(d, g, { content: te(e) }), ct(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 At(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
+ K(d, g, "streaming", "Thinking...");
236
+ let f = de(e, t), h = Ye?.(c, f, tt, nt, i) ?? f, _ = ue(h, t), v = pe(_), y = v > 0, re = Je?.();
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 (!_ || !Me(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, {
226
- 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;
244
+ let b = Ke([], o), ae = Date.now() + (He[c] ?? Ue), oe = Date.now(), se = Date.now(), ce = () => _e({
245
+ turnId: g,
246
+ abortRequested: Nt.current.has(g),
247
+ activeTurnId: x.getState().processingByConversationId[d]?.messageId ?? null
248
+ });
249
+ for (; Date.now() < ae;) {
250
+ let e = ce();
251
+ if (e.abandon) {
252
+ e.clearProcessing && lt(d);
253
+ return;
254
+ }
255
+ if (b = Ke(await u(n, p, a, m, {
256
+ limit: 50,
257
+ sinceMs: o
258
+ }), o), V(d, g, { content: te(b.content) }), b.pendingWrite && ct(d, g, { pendingWrite: b.pendingWrite }), b.done) break;
259
+ 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)));
260
+ }
261
+ if (!b.done && c !== "vibe-plugins") throw Error("Assistant response timed out while streaming progress");
262
+ let le = c === "vibe-plugins" ? await l(n, p, a, m).then((e) => e).catch(() => []) : void 0;
231
263
  if (b.done || (b = {
232
264
  ...b,
233
265
  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
266
  }), r && (b = {
235
267
  ...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 });
268
+ 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._")}`
269
+ }), ne(b.content, le, a, n), b.tokens) {
270
+ V(d, g, { tokens: b.tokens });
239
271
  try {
240
- await Ye?.({
241
- workspaceId: m,
272
+ await Xe?.({
273
+ workspaceId: p,
242
274
  sessionId: a,
243
275
  messageId: b.messageId,
244
276
  model: b.model,
245
277
  tokens: b.tokens
246
- }), Me(O);
278
+ }), Fe(A);
247
279
  } catch {}
248
280
  }
249
- L(d, "complete", v, null);
281
+ let me = ce();
282
+ if (me.abandon) {
283
+ me.clearProcessing && lt(d);
284
+ return;
285
+ }
286
+ H(d, "complete", g, null);
250
287
  } catch (e) {
251
- if (n === 1 && Ae(e)) return ft(d), pt(u), y(2);
288
+ if (n === 1 && Ne(e)) return U(d), dt(c), v(2);
252
289
  throw e;
253
290
  }
254
- }, ne = d;
255
- wt.current.add(ne);
291
+ }, y = d;
292
+ Ot.current.add(y);
256
293
  try {
257
- if (!m) throw Error("Assistant backend is unavailable without an active workspace context.");
258
- await y();
294
+ if (!p) throw Error("Assistant backend is unavailable without an active workspace context.");
295
+ await v();
259
296
  } catch (e) {
260
- G.current.invalidate(x.getState().sandboxesByMode[u]?.sandboxId ?? null);
297
+ Dt.current.invalidate(x.getState().sandboxesByMode[c]?.sandboxId ?? null);
261
298
  let t = n(e);
262
299
  if (t) {
263
- t.refusal === "exhausted" && je(O, "sandbox");
300
+ t.refusal === "exhausted" && Pe(A, "sandbox");
264
301
  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);
302
+ ne(e ? `${n}\n\n${e}` : n, void 0, void 0, void 0, "en"), H(d, "error", g, null);
266
303
  return;
267
304
  }
268
305
  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, {
306
+ H(d, "error", g, i), V(d, g, { content: `Sorry, an error occurred: ${i}. Please try again.` }), ct(d, g, {
270
307
  lang: "en",
271
308
  ..._(r.voiceSessionId)
272
309
  });
273
310
  } finally {
274
- wt.current.delete(ne);
311
+ Ot.current.delete(y);
275
312
  }
276
313
  }, [
277
- j,
278
314
  F,
315
+ B,
316
+ Ye,
317
+ U,
318
+ dt,
319
+ it,
320
+ z,
321
+ At,
279
322
  Je,
280
- ft,
281
- pt,
282
- at,
283
- P,
284
- Tt,
285
- qe,
323
+ M,
324
+ N,
325
+ V,
286
326
  A,
287
327
  Xe,
288
- I,
289
- O,
290
- Ye,
291
- rt,
292
- it,
293
328
  nt,
294
- dt,
295
- N,
296
- L,
297
- D,
298
- q,
299
- Ze
300
- ]), kt = S((e) => {
301
- J(e);
302
- }, [J]), At = S(() => {
303
- let e = [...z.chat].reverse().find((e) => e.role === "user"), t = j ? Ct.current[j] ?? [] : [];
304
- e && J(e.content, t);
329
+ rt,
330
+ tt,
331
+ ut,
332
+ R,
333
+ H,
334
+ lt,
335
+ k,
336
+ K,
337
+ P
338
+ ]), It = S((e) => {
339
+ q(e);
340
+ }, [q]), Lt = S(() => {
341
+ let e = [...G.chat].reverse().find((e) => e.role === "user"), t = F ? Et.current[F] ?? [] : [];
342
+ e && q(e.content, t);
305
343
  }, [
306
- B,
307
- J,
308
- j
309
- ]), Y = T(J);
344
+ mt,
345
+ q,
346
+ F
347
+ ]), J = T(q);
310
348
  C(() => {
311
- Y.current = J;
312
- }, [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];
349
+ J.current = q;
350
+ }, [q]);
351
+ let Rt = w(() => {
352
+ if (gt) return null;
353
+ for (let e = mt.length - 1; e >= 0; --e) {
354
+ let t = mt[e];
317
355
  if (t?.role !== "assistant" || !g(t)) continue;
318
- let n = ge(t.content).text.trim();
356
+ let n = ye(t.content).text.trim();
319
357
  return n ? {
320
358
  id: t.id,
321
359
  text: n
322
360
  } : null;
323
361
  }
324
362
  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) => ({
363
+ }, [mt, gt]), zt = w(() => Rt ? b(Rt.text) : null, [Rt]), Bt = G.chat, Y = w(() => G.voice.filter((e) => e.role === "user" || e.role === "assistant").map((e) => ({
326
364
  id: e.id,
327
365
  role: e.role,
328
- text: ge(e.content).text.trim(),
329
- sessionId: v(e),
366
+ text: ye(e.content).text.trim(),
367
+ sessionId: ne(e),
330
368
  timestamp: e.timestamp
331
- })).filter((e) => e.text.length > 0), [z.voice]), Pt = S(() => {
332
- if (X.length === 0) return;
369
+ })).filter((e) => e.text.length > 0), [G.voice]), Vt = S(() => {
370
+ if (Y.length === 0) return;
333
371
  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");
372
+ Ee(y(Y, {
373
+ title: k("voiceSession.transcript", "Voice conversation"),
374
+ savedAt: k("voiceSession.savedAt", "Saved"),
375
+ session: k("voiceSession.sessionLabel", "Session"),
376
+ earlier: k("voiceSession.earlierLabel", "Earlier"),
377
+ you: k("voiceSession.speakerYou", "You"),
378
+ assistant: k("voiceSession.speakerAssistant", "Assistant")
379
+ }, e), re(A, e), "text/markdown");
342
380
  }, [
343
- O,
344
- X,
345
- D
346
- ]), Z = Ne(), Q = T(Z);
347
- Q.current = Z;
348
- let $ = _e({
381
+ A,
382
+ Y,
383
+ k
384
+ ]), X = Ie(), Z = T(X);
385
+ Z.current = X;
386
+ let Q = be({
349
387
  onSubmit: S((e, t) => {
350
388
  let n = () => {
351
- let n = Q.current, r = pe(n.attachments);
352
- Y.current(e, r, { voiceSessionId: t }), n.clear();
389
+ let n = Z.current, r = me(n.attachments);
390
+ J.current(e, r, { voiceSessionId: t }), n.clear();
353
391
  };
354
- if (!Q.current.isBusy) {
392
+ if (!Z.current.isBusy) {
355
393
  n();
356
394
  return;
357
395
  }
358
396
  let r = Date.now(), i = window.setInterval(() => {
359
- Q.current.isBusy && Date.now() - r < He || (window.clearInterval(i), n());
397
+ Z.current.isBusy && Date.now() - r < Ge || (window.clearInterval(i), n());
360
398
  }, 200);
361
399
  }, []),
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(() => {
400
+ latestReply: Rt,
401
+ language: ae(Qe, Ze).tag
402
+ }), Ht = w(() => (pt?.messages ?? []).reduce((e, t) => Math.max(e, t.metadata?.continuedVoiceTurns ?? 0), 0), [pt?.messages]), Ut = Y.length > Ht, Wt = S(() => {
365
403
  let e = x.getState().activeConversationId;
366
- !e || X.length === 0 || (F(e, {
367
- id: Ue(),
404
+ !e || Y.length === 0 || (B(e, {
405
+ id: D(),
368
406
  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 })
407
+ content: v(Y.slice(Ht), {
408
+ intro: k("voiceSession.continuedIntro", "Continued from a voice conversation. You asked about:"),
409
+ nothing: k("voiceSession.continuedNothing", "Continued from a voice conversation."),
410
+ more: (e) => k("voiceSession.continuedMore", "…and {{count}} more", { count: e })
373
411
  }),
374
412
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
375
- metadata: { continuedVoiceTurns: X.length }
376
- }), W(!1), $.end());
413
+ metadata: { continuedVoiceTurns: Y.length }
414
+ }), Tt(!1), Q.end());
377
415
  }, [
378
- X,
379
- Ft,
380
- F,
381
- D,
382
- $
383
- ]), Rt = T(0);
416
+ Y,
417
+ Ht,
418
+ B,
419
+ k,
420
+ Q
421
+ ]), Gt = T(0);
384
422
  C(() => {
385
- $.active && (Rt.current = X.length);
386
- }, [$.active]);
387
- let zt = S(() => {
388
- let e = X.length > Rt.current;
389
- $.end(), e && W(!0);
390
- }, [X, $]);
423
+ Q.active && (Gt.current = Y.length);
424
+ }, [Q.active]);
425
+ let Kt = S(() => {
426
+ let e = Y.length > Gt.current;
427
+ Q.end(), e && Tt(!0);
428
+ }, [Y, Q]);
391
429
  C(() => {
392
- !h && $.active && $.end();
393
- }, [h, $]), C(() => {
394
- $.active || Q.current.clear();
395
- }, [$.active]), C(() => {
430
+ !h && Q.active && Q.end();
431
+ }, [h, Q]), C(() => {
432
+ Q.active || Z.current.clear();
433
+ }, [Q.active]), C(() => {
396
434
  let e = x.getState().consumePendingPrompt();
397
- return e && Y.current(e), x.subscribe((e, t) => {
435
+ return e && J.current(e), x.subscribe((e, t) => {
398
436
  if (e.pendingPrompt && e.pendingPrompt !== t.pendingPrompt) {
399
437
  let e = x.getState().consumePendingPrompt();
400
- e && Y.current(e);
438
+ e && J.current(e);
401
439
  }
402
440
  });
403
441
  }, []);
404
- let Bt = S((e) => {
405
- let t = j ? x.getState().conversations.find((e) => e.id === j) : void 0;
442
+ let $ = S((e) => {
443
+ let t = F ? x.getState().conversations.find((e) => e.id === F) : void 0;
406
444
  if (t && (t.messages.length > 0 || t.backendSessionId)) {
407
445
  if (t.mode !== e) {
408
446
  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);
447
+ t ? ot(t.id) : z(void 0, e);
410
448
  }
411
- } else j && N(j, e);
412
- st(e);
449
+ } else F && R(F, e);
450
+ L(e);
413
451
  }, [
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);
452
+ F,
453
+ z,
454
+ ot,
455
+ R,
456
+ L
457
+ ]), qt = S((e) => {
458
+ if (j.find((t) => t.id === e)?.writeCapable && !x.getState().apiCallsAcknowledged) {
459
+ Ct(e);
422
460
  return;
423
461
  }
424
- Bt(e);
425
- }, [Bt, k]), Ht = S(() => {
426
- let e = bt;
427
- xt(null), mt(), e && Bt(e);
462
+ $(e);
463
+ }, [$, j]), Jt = S(() => {
464
+ let e = St;
465
+ Ct(null), ft(), e && $(e);
428
466
  }, [
429
- bt,
430
- mt,
431
- Bt
432
- ]), Ut = S(() => {
433
- xt(null);
467
+ St,
468
+ ft,
469
+ $
470
+ ]), Yt = S(() => {
471
+ Ct(null);
434
472
  }, []);
435
- return /* @__PURE__ */ Re("div", {
473
+ return /* @__PURE__ */ Ve("div", {
436
474
  className: "relative flex flex-1 flex-col overflow-hidden",
437
475
  children: [
438
- /* @__PURE__ */ Re("div", {
476
+ /* @__PURE__ */ Ve("div", {
439
477
  className: "contents",
440
- inert: $.active || void 0,
478
+ inert: Q.active || void 0,
441
479
  children: [
442
- X.length > 0 && !$.active ? /* @__PURE__ */ E(xe, {
443
- count: X.length,
444
- onOpenTranscript: () => W(!0)
480
+ Y.length > 0 && !Q.active ? /* @__PURE__ */ E(we, {
481
+ count: Y.length,
482
+ onOpenTranscript: () => Tt(!0)
445
483
  }) : null,
446
- Nt.length === 0 ? /* @__PURE__ */ E(we, {
447
- mode: M,
448
- onSuggestionClick: kt
484
+ Bt.length === 0 ? /* @__PURE__ */ E(De, {
485
+ mode: I,
486
+ onSuggestionClick: It
449
487
  }) : /* @__PURE__ */ E("div", {
450
488
  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
489
+ children: /* @__PURE__ */ E(Oe, {
490
+ onApprovePendingWrite: Ft,
491
+ approvingWriteRef: jt,
492
+ messages: Bt,
493
+ streamingMessageId: _t,
494
+ failedMessageId: vt,
495
+ onRetry: Lt
458
496
  })
459
497
  }),
460
- /* @__PURE__ */ E(Pe, {
461
- onStartVoiceSession: $.available && M !== "api-calls" ? $.start : void 0,
462
- 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
498
+ /* @__PURE__ */ E(Le, {
499
+ onStartVoiceSession: Q.available && I !== "api-calls" ? Q.start : void 0,
500
+ onSend: (e, t) => void q(e, t),
501
+ disabled: gt,
502
+ placeholder: I === "api-calls" ? k("chatArea.placeholderActions", "What would you like me to do?") : k("chatArea.placeholderGeneral", "Ask me anything…"),
503
+ mode: I,
504
+ writeAccessDenied: se === "denied" && !!kt?.writeCapable,
505
+ availableModes: xt,
506
+ onModeChange: qt
469
507
  })
470
508
  ]
471
509
  }),
472
- St && !$.active ? /* @__PURE__ */ E(Se, {
473
- turns: X,
474
- onClose: () => W(!1),
475
- onSave: Pt,
476
- onContinueInChat: It ? Lt : void 0,
510
+ wt && !Q.active ? /* @__PURE__ */ E(Te, {
511
+ turns: Y,
512
+ onClose: () => Tt(!1),
513
+ onSave: Vt,
514
+ onContinueInChat: Ut ? Wt : void 0,
477
515
  closeOnEscape: !0
478
516
  }) : null,
479
- $.active && /* @__PURE__ */ E(Ee, {
480
- session: $.session,
481
- notice: $.notice,
482
- capturing: $.capturing,
483
- interrupting: $.interrupting,
484
- awaitingEndpoint: $.awaitingEndpoint,
485
- turns: X,
486
- spokenChunks: $.spokenChunks,
487
- attachments: Z.attachments,
488
- onAttachFiles: Z.addFiles,
489
- onRemoveAttachment: Z.remove,
490
- onRetryAttachment: Z.retry,
491
- canAttachMore: Z.canAddMore,
492
- preparingAttachments: Z.preparingCount,
493
- onSaveTranscript: Pt,
494
- onContinueInChat: Lt,
495
- onInterrupt: $.interrupt,
496
- spoken: Mt,
497
- onToggleMute: $.toggleMute,
498
- onEnd: zt
517
+ Q.active && /* @__PURE__ */ E(ke, {
518
+ session: Q.session,
519
+ notice: Q.notice,
520
+ capturing: Q.capturing,
521
+ interrupting: Q.interrupting,
522
+ awaitingEndpoint: Q.awaitingEndpoint,
523
+ turns: Y,
524
+ spokenChunks: Q.spokenChunks,
525
+ attachments: X.attachments,
526
+ onAttachFiles: X.addFiles,
527
+ onRemoveAttachment: X.remove,
528
+ onRetryAttachment: X.retry,
529
+ canAttachMore: X.canAddMore,
530
+ preparingAttachments: X.preparingCount,
531
+ onSaveTranscript: Vt,
532
+ onContinueInChat: Wt,
533
+ onInterrupt: () => {
534
+ Q.interrupt(), Pt();
535
+ },
536
+ spoken: zt,
537
+ onToggleMute: Q.toggleMute,
538
+ onEnd: Kt
499
539
  }),
500
- /* @__PURE__ */ E(Ie, {
501
- open: bt !== null,
502
- onConfirm: Ht,
503
- onCancel: Ut
540
+ /* @__PURE__ */ E(ze, {
541
+ open: St !== null,
542
+ onConfirm: Jt,
543
+ onCancel: Yt
504
544
  })
505
545
  ]
506
546
  });
507
547
  };
508
548
  //#endregion
509
- export { k as AssistantChatArea };
549
+ export { j as AssistantChatArea };