@burdenoff/microfe-healthybowl 2026.829.5 → 2026.830.2

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.
@@ -38,7 +38,7 @@ var m = ({ onClose: m, visible: h, docked: g, onToggleDock: _ }) => {
38
38
  onToggleDock: _
39
39
  }),
40
40
  S && /* @__PURE__ */ d(c, {}),
41
- /* @__PURE__ */ d(s, {})
41
+ /* @__PURE__ */ d(s, { visible: h ?? !0 })
42
42
  ]
43
43
  })
44
44
  });
@@ -1 +1 @@
1
- {"version":3,"file":"AIAssistantPanel.js","names":[],"sources":["../../../src/components/assistant/AIAssistantPanel.tsx"],"sourcesContent":["/**\n * AI Assistant Panel — top-level component for the in-page assistant.\n *\n * Layout (v2): a fixed identity header (AssistantHeader) with the brand mark,\n * an availability/context subtitle and icon actions (new conversation, history,\n * export, dock, close), an always-visible transcript, and the composer pinned\n * to the bottom. Conversation history opens as an overlay drawer over the panel\n * — never as an accordion over the transcript.\n *\n * The external prop contract ({ onClose, visible, docked, onToggleDock }) is\n * unchanged; the sandbox/session/transport logic lives in AssistantChatArea.\n */\n\nimport { useMemo, useRef, type FC } from 'react';\nimport type { PanelProps } from '@burdenoff/fe-libs/shared/plugins';\nimport { useFilesServiceWarmup } from '@burdenoff/fe-libs/storage';\nimport { useAssistantStore } from '@/store/assistantStore';\nimport { useAssistantKeyboardShortcuts } from '@/hooks/useAssistantKeyboardShortcuts';\nimport { useAssistantHeartbeat } from '@/hooks/useAssistantHeartbeat';\nimport { describeCurrentPage } from '@/utils/pageContext';\nimport { AssistantHeader } from './AssistantHeader';\nimport { AssistantChatArea } from './AssistantChatArea';\nimport { AssistantConversationList } from './AssistantConversationList';\nimport { AssistantSpeechProvider } from './AssistantSpeechProvider';\nimport { useTr } from '../../shared/hooks/useTr';\n\nexport type AIAssistantPanelProps = PanelProps & {\n /** When provided, renders a dock/float toggle in the header. */\n docked?: boolean;\n onToggleDock?: () => void;\n};\n\nexport const AIAssistantPanel: FC<AIAssistantPanelProps> = ({ onClose, visible, docked, onToggleDock }) => {\n const tr = useTr();\n const panelRef = useRef<HTMLDivElement>(null);\n\n const { conversations, activeConversationId, conversationListOpen, toggleConversationList, createConversation } =\n useAssistantStore();\n\n const activeConversation = conversations.find((c) => c.id === activeConversationId);\n const activeSessionId = activeConversation?.backendSessionId ?? null;\n\n // Keep sandbox alive while panel is open\n useAssistantHeartbeat(activeSessionId, activeConversation?.mode ?? null, visible ?? true);\n\n // Wake wspace-files-svc the moment the panel opens. It runs at minReplicas 0 and\n // needs >=51s to bind its port (prisma migrate deploy 26.0s + boot ~25.5s) against\n // the gateway's 15s budget, so the first attachment after any quiet period would\n // otherwise fail outright. Firing here means the container boots while the user is\n // still typing. Best-effort by construction: single-flighted, rate-limited, and it\n // never surfaces an error — see fe-libs `warmFilesService`.\n useFilesServiceWarmup(visible ?? true);\n\n const contextLabel = useMemo(() => describeCurrentPage(), []);\n\n useAssistantKeyboardShortcuts({\n panelRef,\n onClose,\n });\n\n return (\n // Speech output (BOFF-6290) is provided at the panel root so that hiding the\n // panel — not only unmounting it — stops the voice, and so the header toggle\n // and every message's speak button share one playback state.\n <AssistantSpeechProvider visible={visible ?? true}>\n <div\n ref={panelRef}\n className=\"relative flex h-full w-full flex-col bg-bg-surface\"\n role=\"complementary\"\n aria-label={tr('healthybowl.assistant.panel.ariaLabel', 'AI Assistant')}\n data-testid=\"ai-assistant-panel\"\n tabIndex={-1}\n >\n <AssistantHeader\n contextLabel={contextLabel}\n onNewConversation={() => createConversation()}\n onOpenHistory={toggleConversationList}\n historyOpen={conversationListOpen}\n onClose={onClose}\n docked={docked}\n onToggleDock={onToggleDock}\n />\n\n {/* Conversation history overlay drawer (switch between chats) */}\n {conversationListOpen && <AssistantConversationList />}\n\n <AssistantChatArea />\n </div>\n </AssistantSpeechProvider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;AAgCA,IAAa,KAA+C,EAAE,YAAS,YAAS,WAAQ,sBAAmB;CACzG,IAAM,IAAK,EAAM,GACX,IAAW,EAAuB,IAAI,GAEtC,EAAE,kBAAe,yBAAsB,yBAAsB,2BAAwB,0BACzF,EAAkB,GAEd,IAAqB,EAAc,MAAM,MAAM,EAAE,OAAO,CAAoB;CAYlF,AARA,EAHwB,GAAoB,oBAAoB,MAGzB,GAAoB,QAAQ,MAAM,KAAW,EAAI,GAQxF,EAAsB,KAAW,EAAI;CAErC,IAAM,IAAe,QAAc,EAAoB,GAAG,CAAC,CAAC;CAO5D,OALA,EAA8B;EAC5B;EACA;CACF,CAAC,GAMC,kBAAC,GAAD;EAAyB,SAAS,KAAW;YAC3C,kBAAC,OAAD;GACE,KAAK;GACL,WAAU;GACV,MAAK;GACL,cAAY,EAAG,yCAAyC,cAAc;GACtE,eAAY;GACZ,UAAU;aANZ;IAQE,kBAAC,GAAD;KACgB;KACd,yBAAyB,EAAmB;KAC5C,eAAe;KACf,aAAa;KACJ;KACD;KACM;IACf,CAAA;IAGA,KAAwB,kBAAC,GAAD,CAA4B,CAAA;IAErD,kBAAC,GAAD,CAAoB,CAAA;GACjB;;CACkB,CAAA;AAE7B"}
1
+ {"version":3,"file":"AIAssistantPanel.js","names":[],"sources":["../../../src/components/assistant/AIAssistantPanel.tsx"],"sourcesContent":["/**\n * AI Assistant Panel — top-level component for the in-page assistant.\n *\n * Layout (v2): a fixed identity header (AssistantHeader) with the brand mark,\n * an availability/context subtitle and icon actions (new conversation, history,\n * export, dock, close), an always-visible transcript, and the composer pinned\n * to the bottom. Conversation history opens as an overlay drawer over the panel\n * — never as an accordion over the transcript.\n *\n * The external prop contract ({ onClose, visible, docked, onToggleDock }) is\n * unchanged; the sandbox/session/transport logic lives in AssistantChatArea.\n */\n\nimport { useMemo, useRef, type FC } from 'react';\nimport type { PanelProps } from '@burdenoff/fe-libs/shared/plugins';\nimport { useFilesServiceWarmup } from '@burdenoff/fe-libs/storage';\nimport { useAssistantStore } from '@/store/assistantStore';\nimport { useAssistantKeyboardShortcuts } from '@/hooks/useAssistantKeyboardShortcuts';\nimport { useAssistantHeartbeat } from '@/hooks/useAssistantHeartbeat';\nimport { describeCurrentPage } from '@/utils/pageContext';\nimport { AssistantHeader } from './AssistantHeader';\nimport { AssistantChatArea } from './AssistantChatArea';\nimport { AssistantConversationList } from './AssistantConversationList';\nimport { AssistantSpeechProvider } from './AssistantSpeechProvider';\nimport { useTr } from '../../shared/hooks/useTr';\n\nexport type AIAssistantPanelProps = PanelProps & {\n /** When provided, renders a dock/float toggle in the header. */\n docked?: boolean;\n onToggleDock?: () => void;\n};\n\nexport const AIAssistantPanel: FC<AIAssistantPanelProps> = ({ onClose, visible, docked, onToggleDock }) => {\n const tr = useTr();\n const panelRef = useRef<HTMLDivElement>(null);\n\n const { conversations, activeConversationId, conversationListOpen, toggleConversationList, createConversation } =\n useAssistantStore();\n\n const activeConversation = conversations.find((c) => c.id === activeConversationId);\n const activeSessionId = activeConversation?.backendSessionId ?? null;\n\n // Keep sandbox alive while panel is open\n useAssistantHeartbeat(activeSessionId, activeConversation?.mode ?? null, visible ?? true);\n\n // Wake wspace-files-svc the moment the panel opens. It runs at minReplicas 0 and\n // needs >=51s to bind its port (prisma migrate deploy 26.0s + boot ~25.5s) against\n // the gateway's 15s budget, so the first attachment after any quiet period would\n // otherwise fail outright. Firing here means the container boots while the user is\n // still typing. Best-effort by construction: single-flighted, rate-limited, and it\n // never surfaces an error — see fe-libs `warmFilesService`.\n useFilesServiceWarmup(visible ?? true);\n\n const contextLabel = useMemo(() => describeCurrentPage(), []);\n\n useAssistantKeyboardShortcuts({\n panelRef,\n onClose,\n });\n\n return (\n // Speech output (BOFF-6290) is provided at the panel root so that hiding the\n // panel — not only unmounting it — stops the voice, and so the header toggle\n // and every message's speak button share one playback state.\n <AssistantSpeechProvider visible={visible ?? true}>\n <div\n ref={panelRef}\n className=\"relative flex h-full w-full flex-col bg-bg-surface\"\n role=\"complementary\"\n aria-label={tr('healthybowl.assistant.panel.ariaLabel', 'AI Assistant')}\n data-testid=\"ai-assistant-panel\"\n tabIndex={-1}\n >\n <AssistantHeader\n contextLabel={contextLabel}\n onNewConversation={() => createConversation()}\n onOpenHistory={toggleConversationList}\n historyOpen={conversationListOpen}\n onClose={onClose}\n docked={docked}\n onToggleDock={onToggleDock}\n />\n\n {/* Conversation history overlay drawer (switch between chats) */}\n {conversationListOpen && <AssistantConversationList />}\n\n <AssistantChatArea visible={visible ?? true} />\n </div>\n </AssistantSpeechProvider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;AAgCA,IAAa,KAA+C,EAAE,YAAS,YAAS,WAAQ,sBAAmB;CACzG,IAAM,IAAK,EAAM,GACX,IAAW,EAAuB,IAAI,GAEtC,EAAE,kBAAe,yBAAsB,yBAAsB,2BAAwB,0BACzF,EAAkB,GAEd,IAAqB,EAAc,MAAM,MAAM,EAAE,OAAO,CAAoB;CAYlF,AARA,EAHwB,GAAoB,oBAAoB,MAGzB,GAAoB,QAAQ,MAAM,KAAW,EAAI,GAQxF,EAAsB,KAAW,EAAI;CAErC,IAAM,IAAe,QAAc,EAAoB,GAAG,CAAC,CAAC;CAO5D,OALA,EAA8B;EAC5B;EACA;CACF,CAAC,GAMC,kBAAC,GAAD;EAAyB,SAAS,KAAW;YAC3C,kBAAC,OAAD;GACE,KAAK;GACL,WAAU;GACV,MAAK;GACL,cAAY,EAAG,yCAAyC,cAAc;GACtE,eAAY;GACZ,UAAU;aANZ;IAQE,kBAAC,GAAD;KACgB;KACd,yBAAyB,EAAmB;KAC5C,eAAe;KACf,aAAa;KACJ;KACD;KACM;IACf,CAAA;IAGA,KAAwB,kBAAC,GAAD,CAA4B,CAAA;IAErD,kBAAC,GAAD,EAAmB,SAAS,KAAW,GAAO,CAAA;GAC3C;;CACkB,CAAA;AAE7B"}
@@ -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";
9
- import { AssistantMessageList as b } from "./AssistantMessageList.js";
10
- import { AssistantApiCallsConsentDialog as x } from "./AssistantApiCallsConsentDialog.js";
11
- import { ASSISTANT_MODES as S } from "../../types/assistant.js";
12
- 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";
7
+ import { parseToolActivity as v } from "./AssistantToolActivity.js";
8
+ import { getOrganizationId as ee, getWorkspaceId as y } from "../../utils/assistantContext.js";
9
+ import { buildPromptParts as te, buildPromptWithAttachments as ne, countInlineImageCandidates as re, countInlinedImageParts as ie, toMessageAttachment as b } from "../../utils/assistantAttachments.js";
10
+ import { AssistantMessageList as x } from "./AssistantMessageList.js";
11
+ import { AssistantApiCallsConsentDialog as S } from "./AssistantApiCallsConsentDialog.js";
12
+ import { ASSISTANT_MODES as C } from "../../types/assistant.js";
13
+ import { AssistantEmptyState as w } from "./AssistantEmptyState.js";
14
+ import { AssistantComposer as ae } 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 { useCallback as T, useEffect as E, useMemo as D, useRef as he, 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 xe } 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 = xe(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());
78
+ var M = ({ visible: xe = !0 }) => {
79
+ let A = t(), j = ye("workspace"), { getAccessToken: M, getWorkspaceToken: Oe, userId: ke } = be(), { locale: N } = _e(), P = e((e) => e.assistantLanguage), Ae = D(() => g(P, N).english, [P, N]), je = h(P) !== null, F = D(() => g(P, N).code, [P, N]), { 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 } = ce(ee()), We = D(() => C.filter((e) => !e.requiresAdmin || J), [J]), [Ge, Ke] = ge(null), qe = he({}), Je = he(/* @__PURE__ */ new Set());
77
80
  E(() => {
78
- if (Le) return;
79
- let e = S.find((e) => e.id === z);
80
- (!e || e.requiresAdmin && !X) && z !== "assistant" && B("assistant");
81
+ if (Ue) return;
82
+ let e = C.find((e) => e.id === L);
83
+ (!e || e.requiresAdmin && !J) && L !== "assistant" && R("assistant");
81
84
  }, [
82
- z,
83
- X,
84
- Le,
85
- B
85
+ L,
86
+ J,
87
+ Ue,
88
+ R
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 = T((e, t, n, r) => {
91
+ H(e, n, t, null), r ? Ie(e, t, r) : Ie(e, t, De(n));
92
+ }, [H, Ie]), Ye = T(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(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;
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(j, 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" && !M()) 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(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));
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(j, 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(j, u, s, a, c)).sessionId, Re(t, m)), {
115
118
  sandboxId: u,
116
119
  sessionId: m
117
120
  };
118
121
  }, [
122
+ j,
123
+ U,
119
124
  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(),
125
+ Re,
126
+ W,
127
+ Y
128
+ ]), X = T(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 = y(), g = {
135
+ accessToken: M(),
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
- metadata: r.length ? { attachments: r.map(y) } : void 0
144
+ metadata: r.length ? { attachments: r.map(b) } : void 0
142
145
  };
143
- U(f, b);
144
- let x = ye();
145
- U(f, {
146
+ Fe(f, v);
147
+ let x = we();
148
+ Fe(f, {
146
149
  id: x,
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: F }
154
+ }), H(f, "provisioning", x, null);
155
+ let S = (e, t, n, r, i = F) => {
156
+ V(f, x, {
157
+ content: Te(e),
155
158
  metadata: {
156
159
  lang: i,
157
160
  ...t?.length ? { artifacts: t } : {},
@@ -163,29 +166,29 @@ var P = () => {
163
166
  }, C = async (e = 1) => {
164
167
  let i = !1;
165
168
  try {
166
- await n(M, h, g);
169
+ await n(j, 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 (le(e)) {
172
+ 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(f, "error", x, 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
+ let { sandboxId: e, sessionId: n } = await Ye(f, x, l, h, g), o = (await c(j, e, h, n, g, 50).catch(() => [])).reduce((e, t) => Math.max(e, k(t)), 0);
179
+ Y(f, x, "streaming", "Thinking...");
180
+ let p = fe(l, ne(t, r), Ae, je), _ = te(p, r), v = ie(_), ee = v > 0, y = m();
178
181
  i = re(r) > v;
179
182
  try {
180
- await d(M, e, h, n, p, l, y, g, _);
183
+ await d(j, e, h, n, p, l, y, 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 (!_ || !pe(t)) throw t;
186
+ await d(j, e, h, n, p, l, y, 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));
188
+ let b = Ee([], o), C = Date.now() + (Se[l] ?? Ce), w = Date.now();
189
+ for (; Date.now() < C && (b = Ee(await c(j, e, h, n, g, 50), o), V(f, x, { content: Te(b.content) }), !b.done);) Date.now() - w > 3e4 && (await a(j, e, h, 600, g).catch(() => void 0), w = Date.now()), await new Promise((e) => setTimeout(e, 1500));
187
190
  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;
191
+ let ae = l === "vibe-plugins" ? await s(j, e, h, n, g).catch(() => []) : void 0;
189
192
  if (b.done || (b = {
190
193
  ...b,
191
194
  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._`
@@ -193,139 +196,171 @@ var P = () => {
193
196
  ...b,
194
197
  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
198
  }), S(b.content, ae, n, e), b.tokens) {
196
- W(f, x, { tokens: b.tokens });
199
+ V(f, x, { tokens: b.tokens });
197
200
  try {
198
- await u(M, h, n, b.tokens, g), ce();
201
+ await u(j, h, n, b.tokens, g), de();
199
202
  } catch {}
200
203
  }
201
- G(f, "complete", x, null);
204
+ H(f, "complete", x, null);
202
205
  } catch (t) {
203
- if (e === 1 && de(t)) return K(f), Me(l), C(2);
206
+ if (e === 1 && me(t)) return U(f), ze(l), C(2);
204
207
  throw t;
205
208
  }
206
209
  }, w = f;
207
- He.current.add(w);
210
+ Je.current.add(w);
208
211
  try {
209
212
  if (!h) throw Error("Assistant backend is unavailable without an active workspace context.");
210
213
  await C();
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 (le(e)) {
216
+ 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(f, "error", x, 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", x, t), V(f, x, {
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
+ Je.current.delete(w);
223
226
  }
224
227
  }, [
225
- R,
228
+ I,
229
+ Fe,
230
+ j,
226
231
  U,
227
- M,
228
- K,
232
+ ze,
229
233
  Me,
230
- Ee,
231
- H,
232
- Ue,
233
- N,
234
- P,
235
- W,
236
- Te,
237
- L,
238
- we,
239
- je,
234
+ B,
235
+ Ye,
236
+ M,
237
+ Oe,
240
238
  V,
241
- G,
239
+ je,
240
+ F,
241
+ Ae,
242
+ Re,
243
+ z,
244
+ H,
242
245
  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);
246
+ Y,
247
+ ke
248
+ ]), Xe = T((e) => {
249
+ X(e);
250
+ }, [X]), Ze = T(() => {
251
+ let e = [...G].reverse().find((e) => e.role === "user"), t = I ? qe.current[I] ?? [] : [];
252
+ e && X(e.content, t);
250
253
  }, [
251
- J,
252
- Q,
253
- R
254
- ]), Ke = O(Q);
254
+ G,
255
+ X,
256
+ I
257
+ ]), Z = he(X);
255
258
  E(() => {
256
- Ke.current = Q;
257
- }, [Q]), E(() => {
259
+ Z.current = X;
260
+ }, [X]);
261
+ let Qe = D(() => {
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 = se({
274
+ onSubmit: T((e) => {
275
+ Z.current(e);
276
+ }, []),
277
+ latestReply: Qe,
278
+ language: g(P, N).tag
279
+ });
280
+ E(() => {
281
+ !xe && Q.active && Q.end();
282
+ }, [xe, Q]), E(() => {
258
283
  let t = e.getState().consumePendingPrompt();
259
- return t && Ke.current(t), e.subscribe((t, n) => {
284
+ return t && Z.current(t), e.subscribe((t, n) => {
260
285
  if (t.pendingPrompt && t.pendingPrompt !== n.pendingPrompt) {
261
286
  let t = e.getState().consumePendingPrompt();
262
- t && Ke.current(t);
287
+ t && Z.current(t);
263
288
  }
264
289
  });
265
290
  }, []);
266
291
  let $ = T((t) => {
267
- let n = R ? e.getState().conversations.find((e) => e.id === R) : void 0;
292
+ let n = I ? e.getState().conversations.find((e) => e.id === I) : void 0;
268
293
  if (n && (n.messages.length > 0 || n.backendSessionId)) {
269
294
  if (n.mode !== t) {
270
295
  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);
296
+ n ? Pe(n.id) : B(void 0, t);
272
297
  }
273
- } else R && V(R, t);
274
- B(t);
298
+ } else I && z(I, t);
299
+ R(t);
275
300
  }, [
276
- R,
277
- H,
278
- Oe,
279
- V,
280
- B
281
- ]), qe = T((t) => {
282
- if (S.find((e) => e.id === t)?.writeCapable && !e.getState().apiCallsAcknowledged) {
283
- Be(t);
301
+ I,
302
+ B,
303
+ Pe,
304
+ z,
305
+ R
306
+ ]), $e = T((t) => {
307
+ if (C.find((e) => e.id === t)?.writeCapable && !e.getState().apiCallsAcknowledged) {
308
+ Ke(t);
284
309
  return;
285
310
  }
286
311
  $(t);
287
- }, [$]), Je = T(() => {
288
- let e = ze;
289
- Be(null), Ne(), e && $(e);
312
+ }, [$]), et = T(() => {
313
+ let e = Ge;
314
+ Ke(null), Be(), e && $(e);
290
315
  }, [
291
- ze,
292
- Ne,
316
+ Ge,
317
+ Be,
293
318
  $
294
- ]), Ye = T(() => {
295
- Be(null);
319
+ ]), tt = T(() => {
320
+ Ke(null);
296
321
  }, []);
297
- return /* @__PURE__ */ me("div", {
298
- className: "flex flex-1 flex-col overflow-hidden",
322
+ return /* @__PURE__ */ ve("div", {
323
+ className: "relative flex flex-1 flex-col overflow-hidden",
299
324
  children: [
300
- J.length === 0 ? /* @__PURE__ */ k(C, {
301
- mode: z,
302
- onSuggestionClick: We
303
- }) : /* @__PURE__ */ k("div", {
304
- 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
310
- })
325
+ /* @__PURE__ */ ve("div", {
326
+ className: "contents",
327
+ inert: Q.active || void 0,
328
+ children: [G.length === 0 ? /* @__PURE__ */ O(w, {
329
+ mode: L,
330
+ onSuggestionClick: Xe
331
+ }) : /* @__PURE__ */ O("div", {
332
+ className: "flex min-h-0 flex-1 flex-col",
333
+ children: /* @__PURE__ */ O(x, {
334
+ messages: G,
335
+ streamingMessageId: Ve,
336
+ failedMessageId: He,
337
+ onRetry: Ze
338
+ })
339
+ }), /* @__PURE__ */ O(ae, {
340
+ onStartVoiceSession: Q.available && L !== "api-calls" ? Q.start : void 0,
341
+ onSend: (e, t) => void X(e, t),
342
+ disabled: q,
343
+ placeholder: L === "api-calls" ? A("healthybowl.assistant.chatArea.placeholderActions", "What would you like me to do?") : A("healthybowl.assistant.chatArea.placeholderGeneral", "Ask HealthyBowl anything…"),
344
+ mode: L,
345
+ availableModes: We,
346
+ onModeChange: $e
347
+ })]
311
348
  }),
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
349
+ Q.active && /* @__PURE__ */ O(oe, {
350
+ session: Q.session,
351
+ spoken: Qe?.text ?? null,
352
+ onToggleMute: Q.toggleMute,
353
+ onEnd: Q.end
319
354
  }),
320
- /* @__PURE__ */ k(x, {
321
- open: ze !== null,
322
- onConfirm: Je,
323
- onCancel: Ye
355
+ /* @__PURE__ */ O(S, {
356
+ open: Ge !== null,
357
+ onConfirm: et,
358
+ onCancel: tt
324
359
  })
325
360
  ]
326
361
  });
327
362
  };
328
363
  //#endregion
329
- export { P as AssistantChatArea };
364
+ export { M as AssistantChatArea };
330
365
 
331
366
  //# sourceMappingURL=AssistantChatArea.js.map