@burdenoff/microfe-healthybowl 2026.902.22 → 2026.902.24

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