@burdenoff/microfe-healthybowl 2026.902.32 → 2026.902.34

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