@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.
- package/dist/components/assistant/AIAssistantPanel.js +1 -1
- package/dist/components/assistant/AIAssistantPanel.js.map +1 -1
- package/dist/components/assistant/AssistantChatArea.js +208 -173
- package/dist/components/assistant/AssistantChatArea.js.map +1 -1
- package/dist/components/assistant/composer/AssistantComposer.js +26 -22
- package/dist/components/assistant/composer/AssistantComposer.js.map +1 -1
- package/dist/components/assistant/voice/AssistantVoiceOrb.js +20 -0
- package/dist/components/assistant/voice/AssistantVoiceOrb.js.map +1 -0
- package/dist/components/assistant/voice/AssistantVoiceSession.js +99 -0
- package/dist/components/assistant/voice/AssistantVoiceSession.js.map +1 -0
- package/dist/components/assistant/voice/AssistantVoiceSessionButton.js +21 -0
- package/dist/components/assistant/voice/AssistantVoiceSessionButton.js.map +1 -0
- package/dist/hooks/useVoiceSession.js +117 -0
- package/dist/hooks/useVoiceSession.js.map +1 -0
- package/dist/utils/voiceSession.js +101 -0
- package/dist/utils/voiceSession.js.map +1 -0
- package/package.json +1 -1
|
@@ -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,
|
|
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 {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
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
|
|
29
|
+
var Se = {
|
|
27
30
|
general: 18e4,
|
|
28
31
|
assistant: 18e4,
|
|
29
32
|
"api-calls": 18e4,
|
|
30
33
|
"vibe-plugins": 6e5
|
|
31
|
-
},
|
|
32
|
-
function
|
|
34
|
+
}, Ce = 18e4;
|
|
35
|
+
function we() {
|
|
33
36
|
return `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
|
|
34
37
|
}
|
|
35
|
-
function
|
|
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
|
|
41
|
+
function k(e) {
|
|
39
42
|
return e.info?.time?.created ?? 0;
|
|
40
43
|
}
|
|
41
|
-
function
|
|
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
|
|
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
|
|
51
|
-
let n = e.filter((e) => e.info?.role === "assistant" &&
|
|
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 =
|
|
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
|
|
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
|
|
76
|
-
let A = t(),
|
|
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 (
|
|
79
|
-
let e =
|
|
80
|
-
(!e || e.requiresAdmin && !
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
L,
|
|
86
|
+
J,
|
|
87
|
+
Ue,
|
|
88
|
+
R
|
|
86
89
|
]);
|
|
87
|
-
let
|
|
88
|
-
|
|
89
|
-
}, [
|
|
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(
|
|
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 && (
|
|
98
|
-
|
|
99
|
-
let e = await o(
|
|
100
|
-
e && (
|
|
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" && !
|
|
104
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
115
|
+
U(t), m = null;
|
|
113
116
|
}
|
|
114
|
-
return 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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
let i = e.getState()
|
|
127
|
-
if (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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(
|
|
144
|
+
metadata: r.length ? { attachments: r.map(b) } : void 0
|
|
142
145
|
};
|
|
143
|
-
|
|
144
|
-
let x =
|
|
145
|
-
|
|
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:
|
|
151
|
-
}),
|
|
152
|
-
let S = (e, t, n, r, i =
|
|
153
|
-
|
|
154
|
-
content:
|
|
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(
|
|
169
|
+
await n(j, h, g);
|
|
167
170
|
} catch (e) {
|
|
168
|
-
if (
|
|
169
|
-
|
|
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
|
|
176
|
-
|
|
177
|
-
let p =
|
|
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(
|
|
183
|
+
await d(j, e, h, n, p, l, y, g, _);
|
|
181
184
|
} catch (t) {
|
|
182
|
-
if (!_ || !
|
|
183
|
-
await d(
|
|
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 =
|
|
186
|
-
for (; Date.now() < C && (b =
|
|
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(
|
|
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
|
-
|
|
199
|
+
V(f, x, { tokens: b.tokens });
|
|
197
200
|
try {
|
|
198
|
-
await u(
|
|
201
|
+
await u(j, h, n, b.tokens, g), de();
|
|
199
202
|
} catch {}
|
|
200
203
|
}
|
|
201
|
-
|
|
204
|
+
H(f, "complete", x, null);
|
|
202
205
|
} catch (t) {
|
|
203
|
-
if (e === 1 &&
|
|
206
|
+
if (e === 1 && me(t)) return U(f), ze(l), C(2);
|
|
204
207
|
throw t;
|
|
205
208
|
}
|
|
206
209
|
}, w = f;
|
|
207
|
-
|
|
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 (
|
|
213
|
-
|
|
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
|
-
|
|
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
|
-
|
|
225
|
+
Je.current.delete(w);
|
|
223
226
|
}
|
|
224
227
|
}, [
|
|
225
|
-
|
|
228
|
+
I,
|
|
229
|
+
Fe,
|
|
230
|
+
j,
|
|
226
231
|
U,
|
|
227
|
-
|
|
228
|
-
K,
|
|
232
|
+
ze,
|
|
229
233
|
Me,
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
P,
|
|
235
|
-
W,
|
|
236
|
-
Te,
|
|
237
|
-
L,
|
|
238
|
-
we,
|
|
239
|
-
je,
|
|
234
|
+
B,
|
|
235
|
+
Ye,
|
|
236
|
+
M,
|
|
237
|
+
Oe,
|
|
240
238
|
V,
|
|
241
|
-
|
|
239
|
+
je,
|
|
240
|
+
F,
|
|
241
|
+
Ae,
|
|
242
|
+
Re,
|
|
243
|
+
z,
|
|
244
|
+
H,
|
|
242
245
|
A,
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
]),
|
|
246
|
-
|
|
247
|
-
}, [
|
|
248
|
-
let e = [...
|
|
249
|
-
e &&
|
|
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
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
]),
|
|
254
|
+
G,
|
|
255
|
+
X,
|
|
256
|
+
I
|
|
257
|
+
]), Z = he(X);
|
|
255
258
|
E(() => {
|
|
256
|
-
|
|
257
|
-
}, [
|
|
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 &&
|
|
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 &&
|
|
287
|
+
t && Z.current(t);
|
|
263
288
|
}
|
|
264
289
|
});
|
|
265
290
|
}, []);
|
|
266
291
|
let $ = T((t) => {
|
|
267
|
-
let n =
|
|
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 ?
|
|
296
|
+
n ? Pe(n.id) : B(void 0, t);
|
|
272
297
|
}
|
|
273
|
-
} else
|
|
274
|
-
|
|
298
|
+
} else I && z(I, t);
|
|
299
|
+
R(t);
|
|
275
300
|
}, [
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
]),
|
|
282
|
-
if (
|
|
283
|
-
|
|
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
|
-
}, [$]),
|
|
288
|
-
let e =
|
|
289
|
-
|
|
312
|
+
}, [$]), et = T(() => {
|
|
313
|
+
let e = Ge;
|
|
314
|
+
Ke(null), Be(), e && $(e);
|
|
290
315
|
}, [
|
|
291
|
-
|
|
292
|
-
|
|
316
|
+
Ge,
|
|
317
|
+
Be,
|
|
293
318
|
$
|
|
294
|
-
]),
|
|
295
|
-
|
|
319
|
+
]), tt = T(() => {
|
|
320
|
+
Ke(null);
|
|
296
321
|
}, []);
|
|
297
|
-
return /* @__PURE__ */
|
|
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
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
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__ */
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
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__ */
|
|
321
|
-
open:
|
|
322
|
-
onConfirm:
|
|
323
|
-
onCancel:
|
|
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 {
|
|
364
|
+
export { M as AssistantChatArea };
|
|
330
365
|
|
|
331
366
|
//# sourceMappingURL=AssistantChatArea.js.map
|