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