@burdenoff/microfe-healthybowl 2026.904.16 → 2026.904.18

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.
@@ -1,53 +1,53 @@
1
1
  import { useAssistantStore as e } from "../../store/assistantStore.js";
2
- import { checkAssistantAiCredits as t, createAssistantSandbox as n, createAssistantSession as r, extendAssistantSandboxTTL as i, findExistingSandbox as a, getAssistantArtifacts as o, getAssistantMessages as s, getAssistantSession as ee, reportAssistantAiTokenUsage as c, sendAssistantPromptAsync as l, waitForAssistantServiceReady as u, waitForSandboxReady as d } from "../../services/assistantApi.js";
3
- import { gatherPageContext as te } from "../../utils/pageContext.js";
2
+ import { createAssistantSandbox as t, createAssistantSession as n, extendAssistantSandboxTTL as r, findExistingSandbox as i, getAssistantArtifacts as a, getAssistantMessages as o, getAssistantSession as ee, reportAssistantAiTokenUsage as s, sendAssistantPromptAsync as c, waitForAssistantServiceReady as l, waitForSandboxReady as u } from "../../services/assistantApi.js";
3
+ import { gatherPageContext as d } from "../../utils/pageContext.js";
4
4
  import { resolveAssistantLanguage as f } from "../../config/assistantLanguages.js";
5
5
  import { resolveLanguagePair as p } from "../../config/assistantLanguagePair.js";
6
6
  import { AssistantMessageList as m } from "./AssistantMessageList.js";
7
7
  import { AssistantApiCallsConsentDialog as h } from "./AssistantApiCallsConsentDialog.js";
8
8
  import { AssistantEmptyState as g } from "./AssistantEmptyState.js";
9
- import { AssistantSpokenTurnsNotice as ne } from "./AssistantSpokenTurnsNotice.js";
10
- import { VoiceTranscriptDrawer as _ } from "./voice/VoiceTranscriptDrawer.js";
11
- import { getActorId as v, getOrganizationId as re, getWorkspaceId as y } from "../../utils/assistantContext.js";
12
- import { buildPromptParts as ie, buildPromptWithAttachments as ae, countInlineImageCandidates as oe, countInlinedImageParts as se, getSendableAttachments as b, toMessageAttachment as ce } from "../../utils/assistantAttachments.js";
13
- import { useAssistantAttachments as x } from "../../hooks/useAssistantAttachments.js";
14
- import { AssistantComposer as le } from "./composer/AssistantComposer.js";
15
- import { AssistantVoiceSession as ue } from "./voice/AssistantVoiceSession.js";
16
- import { parseToolActivity as de } from "./AssistantToolActivity.js";
17
- import { useVoiceSession as fe } from "../../hooks/useVoiceSession.js";
18
- import { useAssistantApiAccess as pe } from "../../hooks/useAssistantApiAccess.js";
19
- import { useWorkspaceWriteAccess as me } from "../../hooks/useWorkspaceWriteAccess.js";
20
- import { isVoiceTurn as he, voiceMarker as S, voiceSessionIdOf as ge } from "../../utils/voiceTurnVisibility.js";
21
- import { useConversationTurns as _e } from "../../hooks/useConversationTurns.js";
22
- import { isQuotaExhaustedError as ve } from "../../utils/quotaUtils.js";
23
- import { dispatchAssistantQuotaExhausted as ye, notifyAiCreditsUpdated as be } from "../../utils/aiCredits.js";
24
- import { buildPromptForMode as xe } from "../../utils/assistantPrompt.js";
25
- import { isMultimodalBodyRejection as Se, isRecoverableAssistantError as Ce } from "../../utils/assistantTransportErrors.js";
26
- import { isTurnInFlight as we } from "../../utils/assistantTurnState.js";
27
- import { ASSISTANT_MODES as Te } from "../../types/assistant.js";
28
- import { pollDelayMs as Ee } from "../../utils/assistantPollSchedule.js";
29
- import { findPendingWrite as De } from "../../utils/pendingWrite.js";
30
- import { toCaptionText as Oe } from "../../utils/captionText.js";
31
- import { buildContinuedFromVoiceNote as ke, buildVoiceTranscriptMarkdown as Ae, voiceTranscriptFilename as je } from "../../utils/voiceTranscript.js";
32
- import { downloadFile as Me } from "../../services/assistantExportService.js";
33
- import { createReadinessTracker as Ne } from "../../utils/sandboxReadiness.js";
34
- import { useCallback as C, useEffect as w, useMemo as T, useRef as E, useState as Pe } from "react";
35
- import { useI18n as Fe } from "@burdenoff/fe-libs/shared/providers/shell/I18nProvider";
36
- import { jsx as D, jsxs as Ie } from "react/jsx-runtime";
37
- import { useGatewayClient as Le } from "@burdenoff/fe-libs/shared/graphql";
38
- import { useAuthToken as Re } from "@burdenoff/fe-libs/shared/providers/shell";
39
- import { getAssistantMedia as O, useAssistantTr as ze } from "@burdenoff/fe-libs/shared/assistant";
9
+ import { AssistantSpokenTurnsNotice as _ } from "./AssistantSpokenTurnsNotice.js";
10
+ import { VoiceTranscriptDrawer as v } from "./voice/VoiceTranscriptDrawer.js";
11
+ import { getActorId as te, getOrganizationId as y, getWorkspaceId as ne } from "../../utils/assistantContext.js";
12
+ import { buildPromptParts as re, buildPromptWithAttachments as ie, countInlineImageCandidates as ae, countInlinedImageParts as oe, getSendableAttachments as b, toMessageAttachment as x } from "../../utils/assistantAttachments.js";
13
+ import { useAssistantAttachments as S } from "../../hooks/useAssistantAttachments.js";
14
+ import { AssistantComposer as se } from "./composer/AssistantComposer.js";
15
+ import { AssistantVoiceSession as ce } from "./voice/AssistantVoiceSession.js";
16
+ import { parseToolActivity as le } from "./AssistantToolActivity.js";
17
+ import { useVoiceSession as ue } from "../../hooks/useVoiceSession.js";
18
+ import { useAssistantApiAccess as de } from "../../hooks/useAssistantApiAccess.js";
19
+ import { useWorkspaceWriteAccess as fe } from "../../hooks/useWorkspaceWriteAccess.js";
20
+ import { isVoiceTurn as pe, voiceMarker as me, voiceSessionIdOf as he } from "../../utils/voiceTurnVisibility.js";
21
+ import { useConversationTurns as ge } from "../../hooks/useConversationTurns.js";
22
+ import { isQuotaExhaustedError as _e } from "../../utils/quotaUtils.js";
23
+ import { dispatchAssistantQuotaExhausted as ve, notifyAiCreditsUpdated as ye } from "../../utils/aiCredits.js";
24
+ import { buildPromptForMode as be } from "../../utils/assistantPrompt.js";
25
+ import { isMultimodalBodyRejection as xe, isRecoverableAssistantError as Se } from "../../utils/assistantTransportErrors.js";
26
+ import { isTurnInFlight as Ce } from "../../utils/assistantTurnState.js";
27
+ import { ASSISTANT_MODES as we } from "../../types/assistant.js";
28
+ import { pollDelayMs as Te } from "../../utils/assistantPollSchedule.js";
29
+ import { findPendingWrite as Ee } from "../../utils/pendingWrite.js";
30
+ import { toCaptionText as De } from "../../utils/captionText.js";
31
+ import { buildContinuedFromVoiceNote as Oe, buildVoiceTranscriptMarkdown as ke, voiceTranscriptFilename as Ae } from "../../utils/voiceTranscript.js";
32
+ import { downloadFile as je } from "../../services/assistantExportService.js";
33
+ import { createReadinessTracker as Me } from "../../utils/sandboxReadiness.js";
34
+ import { useCallback as C, useEffect as w, useMemo as T, useRef as E, useState as Ne } from "react";
35
+ import { useI18n as Pe } from "@burdenoff/fe-libs/shared/providers/shell/I18nProvider";
36
+ import { jsx as D, jsxs as Fe } from "react/jsx-runtime";
37
+ import { useGatewayClient as Ie } from "@burdenoff/fe-libs/shared/graphql";
38
+ import { useAuthToken as Le } from "@burdenoff/fe-libs/shared/providers/shell";
39
+ import { getAssistantMedia as O, useAssistantTr as Re } from "@burdenoff/fe-libs/shared/assistant";
40
40
  //#region src/components/assistant/AssistantChatArea.tsx
41
- var Be = {
41
+ var ze = {
42
42
  general: 18e4,
43
43
  assistant: 18e4,
44
44
  "api-calls": 18e4,
45
45
  "vibe-plugins": 6e5
46
- }, Ve = 18e4, He = 2e4;
47
- function Ue() {
46
+ }, Be = 18e4, Ve = 2e4;
47
+ function He() {
48
48
  return `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
49
49
  }
50
- function We(e) {
50
+ function Ue(e) {
51
51
  return e.replace(/(Authorization\s*:\s*Bearer\s+)[^\s\n]+/gi, "$1[REDACTED]").replace(/(X-Workspace-Authorization\s*:\s*Bearer\s+)[^\s\n]+/gi, "$1[REDACTED]").replace(/\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9._-]+\.[A-Za-z0-9._-]+\b/g, "[REDACTED_JWT]").replace(/\bsk-ant-[A-Za-z0-9-]+\b/g, "[REDACTED_API_KEY]");
52
52
  }
53
53
  function k(e) {
@@ -62,13 +62,13 @@ function j(e) {
62
62
  return t === "completed" ? `Completed: ${n}` : t === "failed" ? `Failed: ${n}` : `Running: ${n}`;
63
63
  });
64
64
  }
65
- function Ge(e, t) {
65
+ function We(e, t) {
66
66
  let n = e.filter((e) => e.info?.role === "assistant" && k(e) > t).sort((e, t) => k(e) - k(t));
67
67
  if (n.length === 0) return {
68
68
  content: "Thinking...",
69
69
  done: !1
70
70
  };
71
- let r = n[n.length - 1], i = A(r.parts), a = O(r.parts), o = j(r.parts), s = De(r.parts);
71
+ let r = n[n.length - 1], i = A(r.parts), a = O(r.parts), o = j(r.parts), ee = Ee(r.parts);
72
72
  return {
73
73
  content: [
74
74
  i,
@@ -77,10 +77,10 @@ function Ge(e, t) {
77
77
  ].filter(Boolean).join("\n\n") || "Thinking...",
78
78
  done: !!r.info?.time?.completed && (!!i || a.length > 0 || o.length > 0),
79
79
  tokens: r.info?.tokens,
80
- ...s ? { pendingWrite: s } : {}
80
+ ...ee ? { pendingWrite: ee } : {}
81
81
  };
82
82
  }
83
- function Ke(e) {
83
+ function Ge(e) {
84
84
  switch (e) {
85
85
  case "provisioning": return "Starting assistant environment...";
86
86
  case "connecting": return "Connecting to assistant...";
@@ -88,375 +88,366 @@ function Ke(e) {
88
88
  default: return "";
89
89
  }
90
90
  }
91
- var qe = ({ visible: De = !0 }) => {
92
- let O = ze(), A = Le("workspace"), { getAccessToken: j, getWorkspaceToken: qe, userId: Je } = Re(), { locale: Ye } = Fe(), Xe = e((e) => e.assistantLanguage), Ze = e((e) => e.replyLanguage), Qe = T(() => p(Xe, Ze, Ye), [
91
+ var Ke = ({ visible: Ee = !0 }) => {
92
+ let O = Re(), A = Ie("workspace"), { getAccessToken: j, getWorkspaceToken: Ke, userId: qe } = Le(), { locale: Je } = Pe(), Ye = e((e) => e.assistantLanguage), Xe = e((e) => e.replyLanguage), Ze = T(() => p(Ye, Xe, Je), [
93
+ Ye,
93
94
  Xe,
94
- Ze,
95
- Ye
96
- ]), $e = Qe.reply.english, et = Qe.replyIsExplicit, tt = Qe.reply.code, { conversations: nt, activeConversationId: M, mode: N, processingByConversationId: rt, setMode: P, setConversationMode: F, setActiveConversation: it, createConversation: I, addMessage: L, updateMessage: at, patchMessage: R, mergeMessageMetadata: ot, setConversationProcessing: z, clearConversationProcessing: st, setBackendSessionId: ct, clearBackendSessionId: B, setSandbox: V, clearSandbox: lt, acknowledgeApiCalls: ut } = e(), H = _e(nt.find((e) => e.id === M)), U = H.all, W = M ? rt[M] : void 0, G = we(W?.status), dt = G ? W?.messageId ?? null : null, ft = W?.status === "error" ? W.messageId : null, { canUseApiCalls: pt, loading: mt } = pe(re()), ht = me(v(), y() || null), gt = T(() => Te.filter((e) => !e.requiresAdmin || pt), [pt]), [_t, vt] = Pe(null), [yt, bt] = Pe(!1), xt = E({}), St = E(Ne()), Ct = E(/* @__PURE__ */ new Set()), wt = T(() => Te.find((e) => e.id === N), [N]);
95
+ Je
96
+ ]), Qe = Ze.reply.english, $e = Ze.replyIsExplicit, et = Ze.reply.code, { conversations: tt, activeConversationId: M, mode: N, processingByConversationId: nt, setMode: P, setConversationMode: F, setActiveConversation: rt, createConversation: I, addMessage: L, updateMessage: it, patchMessage: R, mergeMessageMetadata: at, setConversationProcessing: z, clearConversationProcessing: ot, setBackendSessionId: st, clearBackendSessionId: B, setSandbox: V, clearSandbox: ct, acknowledgeApiCalls: lt } = e(), H = ge(tt.find((e) => e.id === M)), U = H.all, W = M ? nt[M] : void 0, G = Ce(W?.status), ut = G ? W?.messageId ?? null : null, dt = W?.status === "error" ? W.messageId : null, { canUseApiCalls: K, loading: ft } = de(y()), pt = fe(te(), ne() || null), mt = T(() => we.filter((e) => !e.requiresAdmin || K), [K]), [ht, gt] = Ne(null), [_t, vt] = Ne(!1), yt = E({}), q = E(Me()), bt = E(/* @__PURE__ */ new Set()), xt = T(() => we.find((e) => e.id === N), [N]);
97
97
  w(() => {
98
- mt || (!wt || wt.requiresAdmin && !pt) && N !== "assistant" && P("assistant");
98
+ ft || (!xt || xt.requiresAdmin && !K) && N !== "assistant" && P("assistant");
99
99
  }, [
100
100
  N,
101
- wt,
102
- pt,
103
- mt,
101
+ xt,
102
+ K,
103
+ ft,
104
104
  P
105
105
  ]);
106
- let K = C((e, t, n, r) => {
107
- z(e, n, t, null), r ? at(e, t, r) : at(e, t, Ke(n));
108
- }, [z, at]), Tt = C(async (t, i, o, s, c) => {
109
- let l = e.getState().sandboxesByMode[o]?.sandboxId ?? null, te = async (e) => {
110
- if (St.current.isFresh(e)) return !0;
106
+ let J = C((e, t, n, r) => {
107
+ z(e, n, t, null), r ? it(e, t, r) : it(e, t, Ge(n));
108
+ }, [z, it]), St = C(async (r, a, o, s, c) => {
109
+ let d = e.getState().sandboxesByMode[o]?.sandboxId ?? null, f = async (e) => {
110
+ if (q.current.isFresh(e)) return !0;
111
111
  try {
112
- return await d(A, e, s, c, 3e5, (e) => K(t, i, "provisioning", e)), await u(A, e, s, c, 9e4, (e) => K(t, i, "connecting", e)), St.current.markVerified(e), !0;
112
+ return await u(A, e, s, c, 3e5, (e) => J(r, a, "provisioning", e)), await l(A, e, s, c, 9e4, (e) => J(r, a, "connecting", e)), q.current.markVerified(e), !0;
113
113
  } catch {
114
- return St.current.invalidate(e), !1;
114
+ return q.current.invalidate(e), !1;
115
115
  }
116
116
  };
117
- if (l && (V(o, l, "provisioning"), K(t, i, "provisioning", "Reusing assistant environment..."), await te(l) || (V(o, null, "provisioning"), l = null)), !l) {
118
- K(t, i, "provisioning", "Looking for existing environment...");
119
- let e = await a(A, s, o, c);
120
- e && (V(o, e, "provisioning"), K(t, i, "provisioning", "Reusing assistant environment..."), await te(e) ? l = e : V(o, null, "provisioning"));
117
+ if (d && (V(o, d, "provisioning"), J(r, a, "provisioning", "Reusing assistant environment..."), await f(d) || (V(o, null, "provisioning"), d = null)), !d) {
118
+ J(r, a, "provisioning", "Looking for existing environment...");
119
+ let e = await i(A, s, o, c);
120
+ e && (V(o, e, "provisioning"), J(r, a, "provisioning", "Reusing assistant environment..."), await f(e) ? d = e : V(o, null, "provisioning"));
121
121
  }
122
- if (!l) {
122
+ if (!d) {
123
123
  if (o === "api-calls" && !j()) throw Error("API Calls mode requires an authenticated session. Please sign in again.");
124
- K(t, i, "provisioning", "Starting assistant environment..."), V(o, null, "provisioning"), l = await n(A, o, s, c), V(o, l, "provisioning"), await d(A, l, s, c, 3e5, (e) => K(t, i, "provisioning", e)), await u(A, l, s, c, 9e4, (e) => K(t, i, "connecting", e));
124
+ J(r, a, "provisioning", "Starting assistant environment..."), V(o, null, "provisioning"), d = await t(A, o, s, c), V(o, d, "provisioning"), await u(A, d, s, c, 3e5, (e) => J(r, a, "provisioning", e)), await l(A, d, s, c, 9e4, (e) => J(r, a, "connecting", e));
125
125
  }
126
- V(o, l, "running");
127
- let f = e.getState().conversations.find((e) => e.id === t)?.backendSessionId ?? null;
128
- if (f) try {
129
- let e = await ee(A, l, s, f, c);
126
+ V(o, d, "running");
127
+ let p = e.getState().conversations.find((e) => e.id === r)?.backendSessionId ?? null;
128
+ if (p) try {
129
+ let e = await ee(A, d, s, p, c);
130
130
  if (e.mode !== o) throw Error(`Session mode mismatch: expected ${o}, received ${e.mode}`);
131
131
  } catch {
132
- B(t), f = null;
132
+ B(r), p = null;
133
133
  }
134
- return f || (K(t, i, "connecting", "Preparing session..."), f = (await r(A, l, s, o, c)).sessionId, ct(t, f)), {
135
- sandboxId: l,
136
- sessionId: f
134
+ return p || (J(r, a, "connecting", "Preparing session..."), p = (await n(A, d, s, o, c)).sessionId, st(r, p)), {
135
+ sandboxId: d,
136
+ sessionId: p
137
137
  };
138
138
  }, [
139
139
  A,
140
140
  B,
141
141
  j,
142
- ct,
142
+ st,
143
143
  V,
144
- K
145
- ]), q = C(async (n, r = [], a = {}) => {
146
- let ee = a.voiceSessionId !== void 0, u = e.getState(), d = u.activeConversationId ?? M;
147
- if (d && (we(u.processingByConversationId[d]?.status) || Ct.current.has(d))) return;
148
- let f = u.mode, p = M, m = p ? e.getState().conversations.find((e) => e.id === p) : void 0;
144
+ J
145
+ ]), Y = C(async (t, n = [], i = {}) => {
146
+ let ee = i.voiceSessionId !== void 0, l = e.getState(), u = l.activeConversationId ?? M;
147
+ if (u && (Ce(l.processingByConversationId[u]?.status) || bt.current.has(u))) return;
148
+ let f = l.mode, p = M, m = p ? e.getState().conversations.find((e) => e.id === p) : void 0;
149
149
  if (p ? m && m.mode !== f && (m.messages.length > 0 || m.backendSessionId) ? p = I(void 0, f) : m && m.mode !== f && F(p, f) : p = I(void 0, f), !p) return;
150
- xt.current[p] = r;
151
- let h = y(), g = {
150
+ yt.current[p] = n;
151
+ let h = ne(), g = {
152
152
  accessToken: j(),
153
- workspaceToken: qe(),
154
- userId: Je,
155
- organizationId: re()
156
- }, ne = {
157
- id: Ue(),
153
+ workspaceToken: Ke(),
154
+ userId: qe,
155
+ organizationId: y()
156
+ }, _ = {
157
+ id: He(),
158
158
  role: "user",
159
- content: n,
159
+ content: t,
160
160
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
161
161
  metadata: {
162
- ...r.length ? { attachments: r.map(ce) } : {},
163
- ...S(a.voiceSessionId)
162
+ ...n.length ? { attachments: n.map(x) } : {},
163
+ ...me(i.voiceSessionId)
164
164
  }
165
165
  };
166
- L(p, ne);
167
- let _ = Ue();
166
+ L(p, _);
167
+ let v = He();
168
168
  L(p, {
169
- id: _,
169
+ id: v,
170
170
  role: "assistant",
171
171
  content: "",
172
172
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
173
173
  metadata: {
174
- lang: tt,
175
- ...S(a.voiceSessionId)
174
+ lang: et,
175
+ ...me(i.voiceSessionId)
176
176
  }
177
- }), z(p, "provisioning", _, null);
178
- let v = (e, t, n, r, i = tt) => {
179
- R(p, _, { content: We(e) }), ot(p, _, {
180
- lang: i,
177
+ }), z(p, "provisioning", v, null);
178
+ let te = (e, t, n, r, a = et) => {
179
+ R(p, v, { content: Ue(e) }), at(p, v, {
180
+ lang: a,
181
181
  ...t?.length ? { artifacts: t } : {},
182
182
  ...t?.length || n || r ? { mode: f } : {},
183
183
  ...n ? { sessionId: n } : {},
184
184
  ...r ? { sandboxId: r } : {},
185
- ...S(a.voiceSessionId)
185
+ ...me(i.voiceSessionId)
186
186
  });
187
187
  }, b = async (e = 1) => {
188
- let a = !1;
188
+ let i = !1;
189
189
  try {
190
- await t(A, h, g);
191
- } catch (e) {
192
- if (ve(e)) {
193
- ye("ai-credits"), v("You've run out of AI credits for this billing cycle. Upgrade your plan to keep chatting.", void 0, void 0, void 0, "en"), z(p, "error", _, null);
194
- return;
195
- }
196
- console.warn("[assistant] AI-credit pre-flight check failed with a non-quota error; proceeding — gateway @usage(checkQuota) still enforces the real budget downstream", e);
197
- }
198
- try {
199
- let { sandboxId: e, sessionId: t } = await Tt(p, _, f, h, g), u = (await s(A, e, h, t, g, 50).catch(() => [])).reduce((e, t) => Math.max(e, k(t)), 0);
200
- K(p, _, "streaming", "Thinking...");
201
- let d = xe(f, ae(n, r), $e, et, ee), m = ie(d, r), ne = se(m), re = ne > 0, y = te();
202
- a = oe(r) > ne;
190
+ let { sandboxId: e, sessionId: l } = await St(p, v, f, h, g), u = (await o(A, e, h, l, g, 50).catch(() => [])).reduce((e, t) => Math.max(e, k(t)), 0);
191
+ J(p, v, "streaming", "Thinking...");
192
+ let m = be(f, ie(t, n), Qe, $e, ee), _ = re(m, n), y = oe(_), ne = y > 0, b = d();
193
+ i = ae(n) > y;
203
194
  try {
204
- await l(A, e, h, t, d, f, y, g, m);
205
- } catch (n) {
206
- if (!m || !Se(n)) throw n;
207
- await l(A, e, h, t, d, f, y, g, void 0), a ||= re;
195
+ await c(A, e, h, l, m, f, b, g, _);
196
+ } catch (t) {
197
+ if (!_ || !xe(t)) throw t;
198
+ await c(A, e, h, l, m, f, b, g, void 0), i ||= ne;
208
199
  }
209
- let b = Ge([], u), ce = Date.now() + (Be[f] ?? Ve), x = Date.now(), le = Date.now();
210
- for (; Date.now() < ce && (b = Ge(await s(A, e, h, t, g, 50, u), u), R(p, _, { content: We(b.content) }), b.pendingWrite && ot(p, _, { pendingWrite: b.pendingWrite }), !b.done);) Date.now() - x > 3e4 && (await i(A, e, h, 600, g).catch(() => void 0), x = Date.now()), await new Promise((e) => setTimeout(e, Ee(Date.now() - le)));
211
- if (!b.done && f !== "vibe-plugins") throw Error("Assistant response timed out while streaming progress");
212
- let ue = f === "vibe-plugins" ? await o(A, e, h, t, g).catch(() => []) : void 0;
213
- if (b.done || (b = {
214
- ...b,
215
- 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._`
216
- }), a && (b = {
217
- ...b,
218
- content: `${b.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._")}`
219
- }), v(b.content, ue, t, e), b.tokens) {
220
- R(p, _, { tokens: b.tokens });
200
+ let x = We([], u), S = Date.now() + (ze[f] ?? Be), se = Date.now(), ce = Date.now();
201
+ for (; Date.now() < S && (x = We(await o(A, e, h, l, g, 50, u), u), R(p, v, { content: Ue(x.content) }), x.pendingWrite && at(p, v, { pendingWrite: x.pendingWrite }), !x.done);) Date.now() - se > 3e4 && (await r(A, e, h, 600, g).catch(() => void 0), se = Date.now()), await new Promise((e) => setTimeout(e, Te(Date.now() - ce)));
202
+ if (!x.done && f !== "vibe-plugins") throw Error("Assistant response timed out while streaming progress");
203
+ let le = f === "vibe-plugins" ? await a(A, e, h, l, g).catch(() => []) : void 0;
204
+ if (x.done || (x = {
205
+ ...x,
206
+ content: `${x.content}\n\n_Still building in the background — any artifacts below will finish shortly. Re-open this conversation to pick up the completed plugin._`
207
+ }), i && (x = {
208
+ ...x,
209
+ content: `${x.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._")}`
210
+ }), te(x.content, le, l, e), x.tokens) {
211
+ R(p, v, { tokens: x.tokens });
221
212
  try {
222
- await c(A, h, t, b.tokens, g), be();
213
+ await s(A, h, l, x.tokens, g), ye();
223
214
  } catch {}
224
215
  }
225
- z(p, "complete", _, null);
216
+ z(p, "complete", v, null);
226
217
  } catch (t) {
227
- if (e === 1 && Ce(t)) return B(p), lt(f), b(2);
218
+ if (e === 1 && Se(t)) return B(p), ct(f), b(2);
228
219
  throw t;
229
220
  }
230
- }, x = p;
231
- Ct.current.add(x);
221
+ }, S = p;
222
+ bt.current.add(S);
232
223
  try {
233
224
  if (!h) throw Error("Assistant backend is unavailable without an active workspace context.");
234
225
  await b();
235
226
  } catch (t) {
236
- if (St.current.invalidate(e.getState().sandboxesByMode[f]?.sandboxId ?? null), ve(t)) {
237
- ye("sandbox"), v("You've reached your sandbox limit on the current plan. Upgrade to start the AI assistant.", void 0, void 0, void 0, "en"), z(p, "error", _, null);
227
+ if (q.current.invalidate(e.getState().sandboxesByMode[f]?.sandboxId ?? null), _e(t)) {
228
+ ve("sandbox"), te("You've reached your sandbox limit on the current plan. Upgrade to start the AI assistant.", void 0, void 0, void 0, "en"), z(p, "error", v, null);
238
229
  return;
239
230
  }
240
231
  let n = t instanceof Error ? t.message : "Something went wrong";
241
- z(p, "error", _, n), R(p, _, { content: `Sorry, an error occurred: ${n}. Please try again.` }), ot(p, _, {
232
+ z(p, "error", v, n), R(p, v, { content: `Sorry, an error occurred: ${n}. Please try again.` }), at(p, v, {
242
233
  lang: "en",
243
- ...S(a.voiceSessionId)
234
+ ...me(i.voiceSessionId)
244
235
  });
245
236
  } finally {
246
- Ct.current.delete(x);
237
+ bt.current.delete(S);
247
238
  }
248
239
  }, [
249
240
  M,
250
241
  L,
251
242
  A,
252
243
  B,
253
- lt,
254
- nt,
244
+ ct,
245
+ tt,
255
246
  I,
256
- Tt,
247
+ St,
257
248
  j,
258
- qe,
249
+ Ke,
259
250
  R,
260
- et,
261
- tt,
262
251
  $e,
263
- ct,
252
+ et,
253
+ Qe,
254
+ st,
264
255
  F,
265
256
  z,
266
257
  O,
267
- K,
268
- Je
269
- ]), Et = C((e) => {
270
- q(e);
271
- }, [q]), Dt = C(() => {
272
- let e = [...H.chat].reverse().find((e) => e.role === "user"), t = M ? xt.current[M] ?? [] : [];
273
- e && q(e.content, t);
258
+ J,
259
+ qe
260
+ ]), Ct = C((e) => {
261
+ Y(e);
262
+ }, [Y]), wt = C(() => {
263
+ let e = [...H.chat].reverse().find((e) => e.role === "user"), t = M ? yt.current[M] ?? [] : [];
264
+ e && Y(e.content, t);
274
265
  }, [
275
266
  U,
276
- q,
267
+ Y,
277
268
  M
278
- ]), Ot = E(q);
269
+ ]), Tt = E(Y);
279
270
  w(() => {
280
- Ot.current = q;
281
- }, [q]);
282
- let J = T(() => {
271
+ Tt.current = Y;
272
+ }, [Y]);
273
+ let Et = T(() => {
283
274
  if (G) return null;
284
275
  for (let e = U.length - 1; e >= 0; --e) {
285
276
  let t = U[e];
286
- if (t?.role !== "assistant" || !he(t)) continue;
287
- let n = de(t.content).text.trim();
277
+ if (t?.role !== "assistant" || !pe(t)) continue;
278
+ let n = le(t.content).text.trim();
288
279
  return n ? {
289
280
  id: t.id,
290
281
  text: n
291
282
  } : null;
292
283
  }
293
284
  return null;
294
- }, [U, G]), kt = T(() => J ? Oe(J.text) : null, [J]), At = H.chat, Y = T(() => H.voice.filter((e) => e.role === "user" || e.role === "assistant").map((e) => ({
285
+ }, [U, G]), Dt = T(() => Et ? De(Et.text) : null, [Et]), Ot = H.chat, X = T(() => H.voice.filter((e) => e.role === "user" || e.role === "assistant").map((e) => ({
295
286
  id: e.id,
296
287
  role: e.role,
297
- text: de(e.content).text.trim(),
298
- sessionId: ge(e),
288
+ text: le(e.content).text.trim(),
289
+ sessionId: he(e),
299
290
  timestamp: e.timestamp
300
- })).filter((e) => e.text.length > 0), [H.voice]), jt = C(() => {
301
- if (Y.length === 0) return;
291
+ })).filter((e) => e.text.length > 0), [H.voice]), kt = C(() => {
292
+ if (X.length === 0) return;
302
293
  let e = /* @__PURE__ */ new Date();
303
- Me(Ae(Y, {
294
+ je(ke(X, {
304
295
  title: O("voiceSession.transcript", "Voice conversation"),
305
296
  savedAt: O("voiceSession.savedAt", "Saved"),
306
297
  session: O("voiceSession.sessionLabel", "Session"),
307
298
  earlier: O("voiceSession.earlierLabel", "Earlier"),
308
299
  you: O("voiceSession.speakerYou", "You"),
309
300
  assistant: O("voiceSession.speakerAssistant", "Assistant")
310
- }, e), je(e), "text/markdown");
311
- }, [Y, O]), X = x(), Z = E(X);
312
- Z.current = X;
313
- let Q = fe({
301
+ }, e), Ae(e), "text/markdown");
302
+ }, [X, O]), Z = S(), Q = E(Z);
303
+ Q.current = Z;
304
+ let $ = ue({
314
305
  onSubmit: C((e, t) => {
315
306
  let n = () => {
316
- let n = Z.current, r = b(n.attachments);
317
- Ot.current(e, r, { voiceSessionId: t }), n.clear();
307
+ let n = Q.current, r = b(n.attachments);
308
+ Tt.current(e, r, { voiceSessionId: t }), n.clear();
318
309
  };
319
- if (!Z.current.isBusy) {
310
+ if (!Q.current.isBusy) {
320
311
  n();
321
312
  return;
322
313
  }
323
314
  let r = Date.now(), i = window.setInterval(() => {
324
- Z.current.isBusy && Date.now() - r < He || (window.clearInterval(i), n());
315
+ Q.current.isBusy && Date.now() - r < Ve || (window.clearInterval(i), n());
325
316
  }, 200);
326
317
  }, []),
327
- latestReply: J,
328
- language: f(Xe, Ye).tag
329
- }), Mt = C(() => {
318
+ latestReply: Et,
319
+ language: f(Ye, Je).tag
320
+ }), At = C(() => {
330
321
  let t = e.getState().activeConversationId;
331
- !t || Y.length === 0 || (L(t, {
332
- id: Ue(),
322
+ !t || X.length === 0 || (L(t, {
323
+ id: He(),
333
324
  role: "system",
334
- content: ke(Y, {
325
+ content: Oe(X, {
335
326
  intro: O("voiceSession.continuedIntro", "Continued from a voice conversation. You asked about:"),
336
327
  nothing: O("voiceSession.continuedNothing", "Continued from a voice conversation."),
337
328
  more: (e) => O("voiceSession.continuedMore", "…and {{count}} more", { count: e })
338
329
  }),
339
330
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
340
- }), bt(!1), Q.end());
331
+ }), vt(!1), $.end());
341
332
  }, [
342
- Y,
333
+ X,
343
334
  L,
344
335
  O
345
336
  ]);
346
337
  w(() => {
347
- !De && Q.active && Q.end();
348
- }, [De, Q]), w(() => {
349
- Q.active || Z.current.clear();
350
- }, [Q.active]), w(() => {
338
+ !Ee && $.active && $.end();
339
+ }, [Ee, $]), w(() => {
340
+ $.active || Q.current.clear();
341
+ }, [$.active]), w(() => {
351
342
  let t = e.getState().consumePendingPrompt();
352
- return t && Ot.current(t), e.subscribe((t, n) => {
343
+ return t && Tt.current(t), e.subscribe((t, n) => {
353
344
  if (t.pendingPrompt && t.pendingPrompt !== n.pendingPrompt) {
354
345
  let t = e.getState().consumePendingPrompt();
355
- t && Ot.current(t);
346
+ t && Tt.current(t);
356
347
  }
357
348
  });
358
349
  }, []);
359
- let $ = C((t) => {
350
+ let jt = C((t) => {
360
351
  let n = M ? e.getState().conversations.find((e) => e.id === M) : void 0;
361
352
  if (n && (n.messages.length > 0 || n.backendSessionId)) {
362
353
  if (n.mode !== t) {
363
354
  let n = e.getState().conversations.find((n) => n.mode === t && n.messages.length === 0 && !n.backendSessionId && !e.getState().processingByConversationId[n.id]);
364
- n ? it(n.id) : I(void 0, t);
355
+ n ? rt(n.id) : I(void 0, t);
365
356
  }
366
357
  } else M && F(M, t);
367
358
  P(t);
368
359
  }, [
369
360
  M,
370
361
  I,
371
- it,
362
+ rt,
372
363
  F,
373
364
  P
374
- ]), Nt = C((t) => {
375
- if (Te.find((e) => e.id === t)?.writeCapable && !e.getState().apiCallsAcknowledged) {
376
- vt(t);
365
+ ]), Mt = C((t) => {
366
+ if (we.find((e) => e.id === t)?.writeCapable && !e.getState().apiCallsAcknowledged) {
367
+ gt(t);
377
368
  return;
378
369
  }
379
- $(t);
380
- }, [$]), Pt = C(() => {
381
- let e = _t;
382
- vt(null), ut(), e && $(e);
370
+ jt(t);
371
+ }, [jt]), Nt = C(() => {
372
+ let e = ht;
373
+ gt(null), lt(), e && jt(e);
383
374
  }, [
384
- _t,
385
- ut,
386
- $
387
- ]), Ft = C(() => {
388
- vt(null);
375
+ ht,
376
+ lt,
377
+ jt
378
+ ]), Pt = C(() => {
379
+ gt(null);
389
380
  }, []);
390
- return /* @__PURE__ */ Ie("div", {
381
+ return /* @__PURE__ */ Fe("div", {
391
382
  className: "relative flex flex-1 flex-col overflow-hidden",
392
383
  children: [
393
- /* @__PURE__ */ Ie("div", {
384
+ /* @__PURE__ */ Fe("div", {
394
385
  className: "contents",
395
- inert: Q.active || void 0,
386
+ inert: $.active || void 0,
396
387
  children: [
397
- Y.length > 0 && !Q.active ? /* @__PURE__ */ D(ne, {
398
- count: Y.length,
399
- onOpenTranscript: () => bt(!0)
388
+ X.length > 0 && !$.active ? /* @__PURE__ */ D(_, {
389
+ count: X.length,
390
+ onOpenTranscript: () => vt(!0)
400
391
  }) : null,
401
- At.length === 0 ? /* @__PURE__ */ D(g, {
392
+ Ot.length === 0 ? /* @__PURE__ */ D(g, {
402
393
  mode: N,
403
- onSuggestionClick: Et
394
+ onSuggestionClick: Ct
404
395
  }) : /* @__PURE__ */ D("div", {
405
396
  className: "flex min-h-0 flex-1 flex-col",
406
397
  children: /* @__PURE__ */ D(m, {
407
- messages: At,
408
- streamingMessageId: dt,
409
- failedMessageId: ft,
410
- onRetry: Dt
398
+ messages: Ot,
399
+ streamingMessageId: ut,
400
+ failedMessageId: dt,
401
+ onRetry: wt
411
402
  })
412
403
  }),
413
- /* @__PURE__ */ D(le, {
414
- onStartVoiceSession: Q.available && N !== "api-calls" ? Q.start : void 0,
415
- onSend: (e, t) => void q(e, t),
404
+ /* @__PURE__ */ D(se, {
405
+ onStartVoiceSession: $.available && N !== "api-calls" ? $.start : void 0,
406
+ onSend: (e, t) => void Y(e, t),
416
407
  disabled: G,
417
408
  placeholder: N === "api-calls" ? O("chatArea.placeholderActions", "What would you like me to do?") : O("chatArea.placeholderGeneral", "Ask HealthyBowl anything…"),
418
409
  mode: N,
419
- writeAccessDenied: ht === "denied" && !!wt?.writeCapable,
420
- availableModes: gt,
421
- onModeChange: Nt
410
+ writeAccessDenied: pt === "denied" && !!xt?.writeCapable,
411
+ availableModes: mt,
412
+ onModeChange: Mt
422
413
  })
423
414
  ]
424
415
  }),
425
- yt && !Q.active ? /* @__PURE__ */ D(_, {
426
- turns: Y,
427
- onClose: () => bt(!1),
428
- onSave: jt
416
+ _t && !$.active ? /* @__PURE__ */ D(v, {
417
+ turns: X,
418
+ onClose: () => vt(!1),
419
+ onSave: kt
429
420
  }) : null,
430
- Q.active && /* @__PURE__ */ D(ue, {
431
- session: Q.session,
432
- notice: Q.notice,
433
- capturing: Q.capturing,
434
- interrupting: Q.interrupting,
435
- awaitingEndpoint: Q.awaitingEndpoint,
436
- turns: Y,
437
- spokenChunks: Q.spokenChunks,
438
- attachments: X.attachments,
439
- onAttachFiles: X.addFiles,
440
- onRemoveAttachment: X.remove,
441
- onRetryAttachment: X.retry,
442
- canAttachMore: X.canAddMore,
443
- preparingAttachments: X.preparingCount,
444
- onSaveTranscript: jt,
445
- onContinueInChat: Mt,
446
- onInterrupt: Q.interrupt,
447
- spoken: kt,
448
- onToggleMute: Q.toggleMute,
449
- onEnd: Q.end
421
+ $.active && /* @__PURE__ */ D(ce, {
422
+ session: $.session,
423
+ notice: $.notice,
424
+ capturing: $.capturing,
425
+ interrupting: $.interrupting,
426
+ awaitingEndpoint: $.awaitingEndpoint,
427
+ turns: X,
428
+ spokenChunks: $.spokenChunks,
429
+ attachments: Z.attachments,
430
+ onAttachFiles: Z.addFiles,
431
+ onRemoveAttachment: Z.remove,
432
+ onRetryAttachment: Z.retry,
433
+ canAttachMore: Z.canAddMore,
434
+ preparingAttachments: Z.preparingCount,
435
+ onSaveTranscript: kt,
436
+ onContinueInChat: At,
437
+ onInterrupt: $.interrupt,
438
+ spoken: Dt,
439
+ onToggleMute: $.toggleMute,
440
+ onEnd: $.end
450
441
  }),
451
442
  /* @__PURE__ */ D(h, {
452
- open: _t !== null,
453
- onConfirm: Pt,
454
- onCancel: Ft
443
+ open: ht !== null,
444
+ onConfirm: Nt,
445
+ onCancel: Pt
455
446
  })
456
447
  ]
457
448
  });
458
449
  };
459
450
  //#endregion
460
- export { qe as AssistantChatArea };
451
+ export { Ke as AssistantChatArea };
461
452
 
462
453
  //# sourceMappingURL=AssistantChatArea.js.map