@burdenoff/microfe-healthybowl 2026.901.14 → 2026.901.16

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