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