@burdenoff/microfe-healthybowl 2026.812.20 → 2026.812.22
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 +36 -32
- package/dist/components/assistant/AIAssistantPanel.js.map +1 -1
- package/dist/components/assistant/AssistantAutoSpeakToggle.js +27 -0
- package/dist/components/assistant/AssistantAutoSpeakToggle.js.map +1 -0
- package/dist/components/assistant/AssistantChatArea.js +161 -161
- package/dist/components/assistant/AssistantChatArea.js.map +1 -1
- package/dist/components/assistant/AssistantHeader.js +39 -37
- package/dist/components/assistant/AssistantHeader.js.map +1 -1
- package/dist/components/assistant/AssistantMessageItem.js +89 -78
- package/dist/components/assistant/AssistantMessageItem.js.map +1 -1
- package/dist/components/assistant/AssistantSpeakButton.js +22 -0
- package/dist/components/assistant/AssistantSpeakButton.js.map +1 -0
- package/dist/components/assistant/AssistantSpeechProvider.js +179 -0
- package/dist/components/assistant/AssistantSpeechProvider.js.map +1 -0
- package/dist/components/assistant/composer/AssistantAttachmentButton.js +19 -19
- package/dist/components/assistant/composer/AssistantAttachmentButton.js.map +1 -1
- package/dist/components/assistant/index.js +4 -1
- package/dist/hooks/useAssistantAttachments.js +82 -63
- package/dist/hooks/useAssistantAttachments.js.map +1 -1
- package/dist/node_modules/fflate/esm/browser.js +326 -0
- package/dist/node_modules/fflate/esm/browser.js.map +1 -0
- package/dist/node_modules/pdfjs-dist/build/pdf.js +16384 -0
- package/dist/node_modules/pdfjs-dist/build/pdf.js.map +1 -0
- package/dist/node_modules/pdfjs-dist/build/pdf.worker.min.js +52129 -0
- package/dist/node_modules/pdfjs-dist/build/pdf.worker.min.js.map +1 -0
- package/dist/services/speech/browserSpeechEngine.js +89 -0
- package/dist/services/speech/browserSpeechEngine.js.map +1 -0
- package/dist/store/assistantStore.js +7 -3
- package/dist/store/assistantStore.js.map +1 -1
- package/dist/utils/assistantAttachments.js +243 -61
- package/dist/utils/assistantAttachments.js.map +1 -1
- package/dist/utils/documentExtract.js +135 -0
- package/dist/utils/documentExtract.js.map +1 -0
- package/dist/utils/documentText.js +237 -0
- package/dist/utils/documentText.js.map +1 -0
- package/dist/utils/speakableText.js +302 -0
- package/dist/utils/speakableText.js.map +1 -0
- package/dist/utils/speechPlayback.js +27 -0
- package/dist/utils/speechPlayback.js.map +1 -0
- package/dist/utils/speechVoices.js +43 -0
- package/dist/utils/speechVoices.js.map +1 -0
- package/package.json +3 -1
|
@@ -3,42 +3,46 @@ import { useTr as t } from "../../shared/hooks/useTr.js";
|
|
|
3
3
|
import { useAssistantKeyboardShortcuts as n } from "../../hooks/useAssistantKeyboardShortcuts.js";
|
|
4
4
|
import { useAssistantHeartbeat as r } from "../../hooks/useAssistantHeartbeat.js";
|
|
5
5
|
import { describeCurrentPage as i } from "../../utils/pageContext.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
6
|
+
import { AssistantSpeechProvider as a } from "./AssistantSpeechProvider.js";
|
|
7
|
+
import { AssistantHeader as o } from "./AssistantHeader.js";
|
|
8
|
+
import { AssistantChatArea as s } from "./AssistantChatArea.js";
|
|
9
|
+
import { AssistantConversationList as c } from "./AssistantConversationList.js";
|
|
10
|
+
import { useMemo as l, useRef as u } from "react";
|
|
11
|
+
import { jsx as d, jsxs as f } from "react/jsx-runtime";
|
|
11
12
|
//#region src/components/assistant/AIAssistantPanel.tsx
|
|
12
|
-
var
|
|
13
|
-
let
|
|
14
|
-
r(
|
|
15
|
-
let
|
|
13
|
+
var p = ({ onClose: p, visible: m, docked: h, onToggleDock: g }) => {
|
|
14
|
+
let _ = t(), v = u(null), { conversations: y, activeConversationId: b, conversationListOpen: x, toggleConversationList: S, createConversation: C } = e(), w = y.find((e) => e.id === b);
|
|
15
|
+
r(w?.backendSessionId ?? null, w?.mode ?? null, m ?? !0);
|
|
16
|
+
let T = l(() => i(), []);
|
|
16
17
|
return n({
|
|
17
|
-
panelRef:
|
|
18
|
-
onClose:
|
|
19
|
-
}), /* @__PURE__ */ d(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
18
|
+
panelRef: v,
|
|
19
|
+
onClose: p
|
|
20
|
+
}), /* @__PURE__ */ d(a, {
|
|
21
|
+
visible: m ?? !0,
|
|
22
|
+
children: /* @__PURE__ */ f("div", {
|
|
23
|
+
ref: v,
|
|
24
|
+
className: "relative flex h-full w-full flex-col bg-bg-surface",
|
|
25
|
+
role: "complementary",
|
|
26
|
+
"aria-label": _("healthybowl.assistant.panel.ariaLabel", "AI Assistant"),
|
|
27
|
+
"data-testid": "ai-assistant-panel",
|
|
28
|
+
tabIndex: -1,
|
|
29
|
+
children: [
|
|
30
|
+
/* @__PURE__ */ d(o, {
|
|
31
|
+
contextLabel: T,
|
|
32
|
+
onNewConversation: () => C(),
|
|
33
|
+
onOpenHistory: S,
|
|
34
|
+
historyOpen: x,
|
|
35
|
+
onClose: p,
|
|
36
|
+
docked: h,
|
|
37
|
+
onToggleDock: g
|
|
38
|
+
}),
|
|
39
|
+
x && /* @__PURE__ */ d(c, {}),
|
|
40
|
+
/* @__PURE__ */ d(s, {})
|
|
41
|
+
]
|
|
42
|
+
})
|
|
39
43
|
});
|
|
40
44
|
};
|
|
41
45
|
//#endregion
|
|
42
|
-
export {
|
|
46
|
+
export { p as AIAssistantPanel };
|
|
43
47
|
|
|
44
48
|
//# sourceMappingURL=AIAssistantPanel.js.map
|
|
@@ -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 { 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 { 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 const contextLabel = useMemo(() => describeCurrentPage(), []);\n\n useAssistantKeyboardShortcuts({\n panelRef,\n onClose,\n });\n\n return (\n <div\n
|
|
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 { 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 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":";;;;;;;;;;;;AA+BA,IAAa,KAA+C,EAAE,YAAS,YAAS,WAAQ,sBAAmB;CACzG,IAAM,IAAK,GAAO,EACZ,IAAW,EAAuB,KAAK,EAEvC,EAAE,kBAAe,yBAAsB,yBAAsB,2BAAwB,0BACzF,GAAmB,EAEf,IAAqB,EAAc,MAAM,MAAM,EAAE,OAAO,EAAqB;AAInF,GAHwB,GAAoB,oBAAoB,MAGzB,GAAoB,QAAQ,MAAM,KAAW,GAAK;CAEzF,IAAM,IAAe,QAAc,GAAqB,EAAE,EAAE,CAAC;AAO7D,QALA,EAA8B;EAC5B;EACA;EACD,CAAC,EAMA,kBAAC,GAAD;EAAyB,SAAS,KAAW;YAC3C,kBAAC,OAAD;GACE,KAAK;GACL,WAAU;GACV,MAAK;GACL,cAAY,EAAG,yCAAyC,eAAe;GACvE,eAAY;GACZ,UAAU;aANZ;IAQE,kBAAC,GAAD;KACgB;KACd,yBAAyB,GAAoB;KAC7C,eAAe;KACf,aAAa;KACJ;KACD;KACM;KACd,CAAA;IAGD,KAAwB,kBAAC,GAAD,EAA6B,CAAA;IAEtD,kBAAC,GAAD,EAAqB,CAAA;IACjB;;EACkB,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useTr as e } from "../../shared/hooks/useTr.js";
|
|
2
|
+
import { useAssistantSpeech as t } from "./AssistantSpeechProvider.js";
|
|
3
|
+
import { Volume2 as n, VolumeX as r } from "lucide-react";
|
|
4
|
+
import { jsx as i } from "react/jsx-runtime";
|
|
5
|
+
//#region src/components/assistant/AssistantAutoSpeakToggle.tsx
|
|
6
|
+
var a = () => {
|
|
7
|
+
let a = e(), { isSupported: o, isBlocked: s, disabledReason: c, autoSpeakEnabled: l, setAutoSpeak: u, stop: d } = t();
|
|
8
|
+
if (!o) return null;
|
|
9
|
+
let f = s && !l, p = l ? a("healthybowl.assistant.header.autoSpeakOff", "Stop reading replies aloud") : a("healthybowl.assistant.header.autoSpeakOn", "Read replies aloud automatically");
|
|
10
|
+
return /* @__PURE__ */ i("button", {
|
|
11
|
+
type: "button",
|
|
12
|
+
onClick: () => {
|
|
13
|
+
l && d(), u(!l);
|
|
14
|
+
},
|
|
15
|
+
disabled: f,
|
|
16
|
+
className: `rounded-lg p-1.5 transition-colors disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:bg-transparent ${l ? "bg-action-primary-bg/15 text-action-primary-bg" : "text-text-secondary hover:bg-bg-sunken hover:text-text-primary"}`,
|
|
17
|
+
title: f ? c ?? p : p,
|
|
18
|
+
"aria-label": p,
|
|
19
|
+
"aria-pressed": l,
|
|
20
|
+
"data-testid": "assistant-auto-speak",
|
|
21
|
+
children: i(l ? n : r, { className: "size-4" })
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
export { a as AssistantAutoSpeakToggle };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=AssistantAutoSpeakToggle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AssistantAutoSpeakToggle.js","names":[],"sources":["../../../src/components/assistant/AssistantAutoSpeakToggle.tsx"],"sourcesContent":["import type { FC } from 'react';\nimport { Volume2, VolumeX } from 'lucide-react';\nimport { useAssistantSpeech } from './AssistantSpeechProvider';\nimport { useTr } from '../../shared/hooks/useTr';\n\n/**\n * Header toggle for \"read every reply aloud\" (BOFF-6290).\n *\n * Opt-in, persisted per profile, and **off by default** — the assistant must\n * never start talking on its own until someone has said they want that. Turning\n * it on affects the NEXT reply only; it does not start reading the transcript.\n *\n * Renders nothing when the platform has no speech output, so browsers without\n * `speechSynthesis` see no dead switch.\n *\n * Availability is checked here for the same reason the per-message button\n * checks it: with no installed voice for the app language, switching this on\n * would hand every reply to whatever voice the engine defaults to — a Tamil\n * answer read in English. So it is disabled, with the reason as its tooltip,\n * exactly like the Listen button. It stays operable while it is ON, because a\n * switch you cannot turn off is worse than one you cannot turn on.\n */\nexport const AssistantAutoSpeakToggle: FC = () => {\n const tr = useTr();\n const { isSupported, isBlocked, disabledReason, autoSpeakEnabled, setAutoSpeak, stop } = useAssistantSpeech();\n\n if (!isSupported) return null;\n\n const disabled = isBlocked && !autoSpeakEnabled;\n const label = autoSpeakEnabled\n ? tr('healthybowl.assistant.header.autoSpeakOff', 'Stop reading replies aloud')\n : tr('healthybowl.assistant.header.autoSpeakOn', 'Read replies aloud automatically');\n\n return (\n <button\n type=\"button\"\n onClick={() => {\n // Turning it off also silences whatever is talking right now.\n if (autoSpeakEnabled) stop();\n setAutoSpeak(!autoSpeakEnabled);\n }}\n disabled={disabled}\n className={`rounded-lg p-1.5 transition-colors disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:bg-transparent ${\n autoSpeakEnabled\n ? 'bg-action-primary-bg/15 text-action-primary-bg'\n : 'text-text-secondary hover:bg-bg-sunken hover:text-text-primary'\n }`}\n title={disabled ? (disabledReason ?? label) : label}\n aria-label={label}\n aria-pressed={autoSpeakEnabled}\n data-testid=\"assistant-auto-speak\"\n >\n {autoSpeakEnabled ? <Volume2 className=\"size-4\" /> : <VolumeX className=\"size-4\" />}\n </button>\n );\n};\n"],"mappings":";;;;;AAsBA,IAAa,UAAqC;CAChD,IAAM,IAAK,GAAO,EACZ,EAAE,gBAAa,cAAW,mBAAgB,qBAAkB,iBAAc,YAAS,GAAoB;AAE7G,KAAI,CAAC,EAAa,QAAO;CAEzB,IAAM,IAAW,KAAa,CAAC,GACzB,IAAQ,IACV,EAAG,6CAA6C,6BAA6B,GAC7E,EAAG,4CAA4C,mCAAmC;AAEtF,QACE,kBAAC,UAAD;EACE,MAAK;EACL,eAAe;AAGb,GADI,KAAkB,GAAM,EAC5B,EAAa,CAAC,EAAiB;;EAEvB;EACV,WAAW,oHACT,IACI,mDACA;EAEN,OAAO,IAAY,KAAkB,IAAS;EAC9C,cAAY;EACZ,gBAAc;EACd,eAAY;YAEQ,EAAnB,IAAoB,IAAiC,GAAlC,EAAS,WAAU,UAAW,CAAiC;EAC5E,CAAA"}
|
|
@@ -2,56 +2,56 @@ import { useAssistantStore as e } from "../../store/assistantStore.js";
|
|
|
2
2
|
import { useTr as t } from "../../shared/hooks/useTr.js";
|
|
3
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
4
|
import { gatherPageContext as m } from "../../utils/pageContext.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
5
|
+
import { isTurnInFlight as h } from "../../utils/assistantTurnState.js";
|
|
6
|
+
import { getOrganizationId as g, getWorkspaceId as ee } from "../../utils/assistantContext.js";
|
|
7
|
+
import { buildPromptParts as te, buildPromptWithAttachments as ne, countInlineImageCandidates as re, countInlinedImageParts as ie, toMessageAttachment as _ } from "../../utils/assistantAttachments.js";
|
|
8
|
+
import { AssistantMessageList as v } from "./AssistantMessageList.js";
|
|
9
|
+
import { AssistantApiCallsConsentDialog as y } from "./AssistantApiCallsConsentDialog.js";
|
|
10
|
+
import { ASSISTANT_MODES as b } from "../../types/assistant.js";
|
|
11
|
+
import { AssistantEmptyState as x } from "./AssistantEmptyState.js";
|
|
12
|
+
import { AssistantComposer as S } from "./composer/AssistantComposer.js";
|
|
13
|
+
import { useAssistantApiAccess as C } from "../../hooks/useAssistantApiAccess.js";
|
|
14
|
+
import { isQuotaExhaustedError as w } from "../../utils/quotaUtils.js";
|
|
15
|
+
import { dispatchAssistantQuotaExhausted as T, notifyAiCreditsUpdated as ae } from "../../utils/aiCredits.js";
|
|
15
16
|
import { buildPromptForMode as oe } from "../../utils/assistantPrompt.js";
|
|
16
17
|
import { isMultimodalBodyRejection as se, isRecoverableAssistantError as ce } from "../../utils/assistantTransportErrors.js";
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import { getAssistantMedia as k } from "@burdenoff/fe-libs/shared/assistant";
|
|
18
|
+
import { useCallback as E, useEffect as D, useMemo as le, useRef as O, useState as ue } from "react";
|
|
19
|
+
import { jsx as k, jsxs as de } from "react/jsx-runtime";
|
|
20
|
+
import { useGatewayClient as fe } from "@burdenoff/fe-libs/shared/graphql";
|
|
21
|
+
import { useAuthToken as pe } from "@burdenoff/fe-libs/shared/providers/shell";
|
|
22
|
+
import { getAssistantMedia as A } from "@burdenoff/fe-libs/shared/assistant";
|
|
23
23
|
//#region src/components/assistant/AssistantChatArea.tsx
|
|
24
|
-
var
|
|
24
|
+
var me = {
|
|
25
25
|
general: 18e4,
|
|
26
26
|
assistant: 18e4,
|
|
27
27
|
"api-calls": 18e4,
|
|
28
28
|
"vibe-plugins": 6e5
|
|
29
|
-
},
|
|
30
|
-
function
|
|
29
|
+
}, he = 18e4;
|
|
30
|
+
function ge() {
|
|
31
31
|
return `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function _e(e) {
|
|
34
34
|
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]");
|
|
35
35
|
}
|
|
36
|
-
function
|
|
36
|
+
function j(e) {
|
|
37
37
|
return e.info?.time?.created ?? 0;
|
|
38
38
|
}
|
|
39
|
-
function
|
|
39
|
+
function M(e) {
|
|
40
40
|
return (e ?? []).filter((e) => e.type === "text" && typeof e.text == "string").map((e) => e.text?.trim() ?? "").filter(Boolean).join("\n");
|
|
41
41
|
}
|
|
42
|
-
function
|
|
42
|
+
function N(e) {
|
|
43
43
|
return (e ?? []).filter((e) => e.type === "tool" && e.tool).map((e) => {
|
|
44
44
|
let t = e.state?.status ?? "running", n = e.tool ?? "tool";
|
|
45
45
|
return t === "completed" ? `Completed: ${n}` : t === "failed" ? `Failed: ${n}` : `Running: ${n}`;
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
|
-
function
|
|
49
|
-
let n = e.filter((e) => e.info?.role === "assistant" &&
|
|
48
|
+
function ve(e, t) {
|
|
49
|
+
let n = e.filter((e) => e.info?.role === "assistant" && j(e) > t).sort((e, t) => j(e) - j(t));
|
|
50
50
|
if (n.length === 0) return {
|
|
51
51
|
content: "Thinking...",
|
|
52
52
|
done: !1
|
|
53
53
|
};
|
|
54
|
-
let r = n[n.length - 1], i =
|
|
54
|
+
let r = n[n.length - 1], i = M(r.parts), a = A(r.parts), o = N(r.parts);
|
|
55
55
|
return {
|
|
56
56
|
content: [
|
|
57
57
|
i,
|
|
@@ -62,7 +62,7 @@ function ye(e, t) {
|
|
|
62
62
|
tokens: r.info?.tokens
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
-
function
|
|
65
|
+
function ye(e) {
|
|
66
66
|
switch (e) {
|
|
67
67
|
case "provisioning": return "Starting assistant environment...";
|
|
68
68
|
case "connecting": return "Connecting to assistant...";
|
|
@@ -70,85 +70,85 @@ function be(e) {
|
|
|
70
70
|
default: return "";
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
-
var
|
|
74
|
-
let
|
|
75
|
-
|
|
76
|
-
if (
|
|
77
|
-
let e =
|
|
78
|
-
(!e || e.requiresAdmin && !
|
|
73
|
+
var P = () => {
|
|
74
|
+
let A = t(), M = fe("workspace"), { getAccessToken: N, getWorkspaceToken: P, userId: be } = pe(), { conversations: xe, activeConversationId: F, mode: I, processingByConversationId: Se, setMode: L, setConversationMode: R, setActiveConversation: Ce, createConversation: z, addMessage: B, updateMessage: V, patchMessage: H, setConversationProcessing: U, clearConversationProcessing: we, setBackendSessionId: W, clearBackendSessionId: G, setSandbox: K, clearSandbox: Te, acknowledgeApiCalls: Ee } = e(), q = xe.find((e) => e.id === F)?.messages ?? [], J = F ? Se[F] : void 0, De = h(J?.status), Oe = De ? J?.messageId ?? null : null, ke = J?.status === "error" ? J.messageId : null, { canUseApiCalls: Y, loading: Ae } = C(g()), je = le(() => b.filter((e) => !e.requiresAdmin || Y), [Y]), [Me, Ne] = ue(null), Pe = O({}), Fe = O(/* @__PURE__ */ new Set());
|
|
75
|
+
D(() => {
|
|
76
|
+
if (Ae) return;
|
|
77
|
+
let e = b.find((e) => e.id === I);
|
|
78
|
+
(!e || e.requiresAdmin && !Y) && I !== "assistant" && L("assistant");
|
|
79
79
|
}, [
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
I,
|
|
81
|
+
Y,
|
|
82
|
+
Ae,
|
|
83
|
+
L
|
|
84
84
|
]);
|
|
85
|
-
let X =
|
|
86
|
-
|
|
87
|
-
}, [
|
|
85
|
+
let X = E((e, t, n, r) => {
|
|
86
|
+
U(e, n, t, null), r ? V(e, t, r) : V(e, t, ye(n));
|
|
87
|
+
}, [U, V]), Ie = E(async (t, n, a, s, c) => {
|
|
88
88
|
let u = e.getState().sandboxesByMode[a]?.sandboxId ?? null, d = async (e) => {
|
|
89
89
|
try {
|
|
90
|
-
return await p(
|
|
90
|
+
return await p(M, e, s, c, 3e5, (e) => X(t, n, "provisioning", e)), await f(M, e, s, c, 9e4, (e) => X(t, n, "connecting", e)), !0;
|
|
91
91
|
} catch {
|
|
92
92
|
return !1;
|
|
93
93
|
}
|
|
94
94
|
};
|
|
95
|
-
if (u && (
|
|
95
|
+
if (u && (K(a, u, "provisioning"), X(t, n, "provisioning", "Reusing assistant environment..."), await d(u) || (K(a, null, "provisioning"), u = null)), !u) {
|
|
96
96
|
X(t, n, "provisioning", "Looking for existing environment...");
|
|
97
|
-
let e = await o(
|
|
98
|
-
e && (
|
|
97
|
+
let e = await o(M, s, a, c);
|
|
98
|
+
e && (K(a, e, "provisioning"), X(t, n, "provisioning", "Reusing assistant environment..."), await d(e) ? u = e : K(a, null, "provisioning"));
|
|
99
99
|
}
|
|
100
100
|
if (!u) {
|
|
101
|
-
if (a === "api-calls" && !
|
|
102
|
-
X(t, n, "provisioning", "Starting assistant environment..."),
|
|
101
|
+
if (a === "api-calls" && !N()) throw Error("API Calls mode requires an authenticated session. Please sign in again.");
|
|
102
|
+
X(t, n, "provisioning", "Starting assistant environment..."), K(a, null, "provisioning"), u = await r(M, a, s, c), K(a, u, "provisioning"), await p(M, u, s, c, 3e5, (e) => X(t, n, "provisioning", e)), await f(M, u, s, c, 9e4, (e) => X(t, n, "connecting", e));
|
|
103
103
|
}
|
|
104
|
-
|
|
104
|
+
K(a, u, "running");
|
|
105
105
|
let m = e.getState().conversations.find((e) => e.id === t)?.backendSessionId ?? null;
|
|
106
106
|
if (m) try {
|
|
107
|
-
let e = await l(
|
|
107
|
+
let e = await l(M, u, s, m, c);
|
|
108
108
|
if (e.mode !== a) throw Error(`Session mode mismatch: expected ${a}, received ${e.mode}`);
|
|
109
109
|
} catch {
|
|
110
|
-
|
|
110
|
+
G(t), m = null;
|
|
111
111
|
}
|
|
112
|
-
return m || (X(t, n, "connecting", "Preparing session..."), m = (await i(
|
|
112
|
+
return m || (X(t, n, "connecting", "Preparing session..."), m = (await i(M, u, s, a, c)).sessionId, W(t, m)), {
|
|
113
113
|
sandboxId: u,
|
|
114
114
|
sessionId: m
|
|
115
115
|
};
|
|
116
116
|
}, [
|
|
117
|
-
j,
|
|
118
|
-
W,
|
|
119
117
|
M,
|
|
120
|
-
U,
|
|
121
118
|
G,
|
|
119
|
+
N,
|
|
120
|
+
W,
|
|
121
|
+
K,
|
|
122
122
|
X
|
|
123
|
-
]), Z =
|
|
124
|
-
let i = e.getState(), o = i.activeConversationId ??
|
|
125
|
-
if (o && (
|
|
126
|
-
let l = i.mode, f =
|
|
127
|
-
if (f ? p && p.mode !== l && (p.messages.length > 0 || p.backendSessionId) ? f =
|
|
123
|
+
]), Z = E(async (t, r = []) => {
|
|
124
|
+
let i = e.getState(), o = i.activeConversationId ?? F;
|
|
125
|
+
if (o && (h(i.processingByConversationId[o]?.status) || Fe.current.has(o))) return;
|
|
126
|
+
let l = i.mode, f = F, p = f ? e.getState().conversations.find((e) => e.id === f) : void 0;
|
|
127
|
+
if (f ? p && p.mode !== l && (p.messages.length > 0 || p.backendSessionId) ? f = z(void 0, l) : p && p.mode !== l && R(f, l) : f = z(void 0, l), !f) return;
|
|
128
128
|
Pe.current[f] = r;
|
|
129
|
-
let
|
|
130
|
-
accessToken:
|
|
131
|
-
workspaceToken:
|
|
132
|
-
userId:
|
|
133
|
-
organizationId:
|
|
134
|
-
},
|
|
135
|
-
id:
|
|
129
|
+
let v = ee(), y = {
|
|
130
|
+
accessToken: N(),
|
|
131
|
+
workspaceToken: P(),
|
|
132
|
+
userId: be,
|
|
133
|
+
organizationId: g()
|
|
134
|
+
}, b = {
|
|
135
|
+
id: ge(),
|
|
136
136
|
role: "user",
|
|
137
137
|
content: t,
|
|
138
138
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
139
|
-
metadata: r.length ? { attachments: r.map(
|
|
139
|
+
metadata: r.length ? { attachments: r.map(_) } : void 0
|
|
140
140
|
};
|
|
141
|
-
|
|
142
|
-
let
|
|
143
|
-
|
|
144
|
-
id:
|
|
141
|
+
B(f, b);
|
|
142
|
+
let x = ge();
|
|
143
|
+
B(f, {
|
|
144
|
+
id: x,
|
|
145
145
|
role: "assistant",
|
|
146
146
|
content: "",
|
|
147
147
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
148
|
-
}),
|
|
149
|
-
let
|
|
150
|
-
|
|
151
|
-
content:
|
|
148
|
+
}), U(f, "provisioning", x, null);
|
|
149
|
+
let S = (e, t, n, r) => {
|
|
150
|
+
H(f, x, {
|
|
151
|
+
content: _e(e),
|
|
152
152
|
metadata: t?.length || n || r ? {
|
|
153
153
|
artifacts: t,
|
|
154
154
|
mode: l,
|
|
@@ -156,96 +156,96 @@ var N = () => {
|
|
|
156
156
|
sandboxId: r
|
|
157
157
|
} : void 0
|
|
158
158
|
});
|
|
159
|
-
},
|
|
159
|
+
}, C = async (e = 1) => {
|
|
160
160
|
let i = !1;
|
|
161
161
|
try {
|
|
162
|
-
await n(
|
|
162
|
+
await n(M, v, y);
|
|
163
163
|
} catch (e) {
|
|
164
|
-
if (
|
|
165
|
-
|
|
164
|
+
if (w(e)) {
|
|
165
|
+
T("ai-credits"), S("You've run out of AI credits for this billing cycle. Upgrade your plan to keep chatting."), U(f, "error", x, null);
|
|
166
166
|
return;
|
|
167
167
|
}
|
|
168
168
|
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);
|
|
169
169
|
}
|
|
170
170
|
try {
|
|
171
|
-
let { sandboxId: e, sessionId: n } = await Ie(f,
|
|
172
|
-
X(f,
|
|
173
|
-
let p = oe(l,
|
|
174
|
-
i =
|
|
171
|
+
let { sandboxId: e, sessionId: n } = await Ie(f, x, l, v, y), o = (await c(M, e, v, n, y, 50).catch(() => [])).reduce((e, t) => Math.max(e, j(t)), 0);
|
|
172
|
+
X(f, x, "streaming", "Thinking...");
|
|
173
|
+
let p = oe(l, ne(t, r)), h = te(p, r), g = ie(h), ee = g > 0, _ = m();
|
|
174
|
+
i = re(r) > g;
|
|
175
175
|
try {
|
|
176
|
-
await d(
|
|
176
|
+
await d(M, e, v, n, p, l, _, y, h);
|
|
177
177
|
} catch (t) {
|
|
178
178
|
if (!h || !se(t)) throw t;
|
|
179
|
-
await d(
|
|
179
|
+
await d(M, e, v, n, p, l, _, y, void 0), i ||= ee;
|
|
180
180
|
}
|
|
181
|
-
let
|
|
182
|
-
for (; Date.now() < C && (
|
|
183
|
-
if (!
|
|
184
|
-
let
|
|
185
|
-
if (
|
|
186
|
-
...
|
|
187
|
-
content: `${
|
|
188
|
-
}), i && (
|
|
189
|
-
...
|
|
190
|
-
content: `${
|
|
191
|
-
}),
|
|
192
|
-
|
|
181
|
+
let b = ve([], o), C = Date.now() + (me[l] ?? he), w = Date.now();
|
|
182
|
+
for (; Date.now() < C && (b = ve(await c(M, e, v, n, y, 50), o), H(f, x, { content: _e(b.content) }), !b.done);) Date.now() - w > 3e4 && (await a(M, e, v, 600, y).catch(() => void 0), w = Date.now()), await new Promise((e) => setTimeout(e, 1500));
|
|
183
|
+
if (!b.done && l !== "vibe-plugins") throw Error("Assistant response timed out while streaming progress");
|
|
184
|
+
let T = l === "vibe-plugins" ? await s(M, e, v, n, y).catch(() => []) : void 0;
|
|
185
|
+
if (b.done || (b = {
|
|
186
|
+
...b,
|
|
187
|
+
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._`
|
|
188
|
+
}), i && (b = {
|
|
189
|
+
...b,
|
|
190
|
+
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._")}`
|
|
191
|
+
}), S(b.content, T, n, e), b.tokens) {
|
|
192
|
+
H(f, x, { tokens: b.tokens });
|
|
193
193
|
try {
|
|
194
|
-
await u(
|
|
194
|
+
await u(M, v, n, b.tokens, y), ae();
|
|
195
195
|
} catch {}
|
|
196
196
|
}
|
|
197
|
-
|
|
197
|
+
U(f, "complete", x, null);
|
|
198
198
|
} catch (t) {
|
|
199
|
-
if (e === 1 && ce(t)) return
|
|
199
|
+
if (e === 1 && ce(t)) return G(f), Te(l), C(2);
|
|
200
200
|
throw t;
|
|
201
201
|
}
|
|
202
|
-
},
|
|
203
|
-
Fe.current.add(
|
|
202
|
+
}, E = f;
|
|
203
|
+
Fe.current.add(E);
|
|
204
204
|
try {
|
|
205
|
-
if (!
|
|
206
|
-
await
|
|
205
|
+
if (!v) throw Error("Assistant backend is unavailable without an active workspace context.");
|
|
206
|
+
await C();
|
|
207
207
|
} catch (e) {
|
|
208
|
-
if (
|
|
209
|
-
|
|
208
|
+
if (w(e)) {
|
|
209
|
+
T("sandbox"), S("You've reached your sandbox limit on the current plan. Upgrade to start the AI assistant."), U(f, "error", x, null);
|
|
210
210
|
return;
|
|
211
211
|
}
|
|
212
212
|
let t = e instanceof Error ? e.message : "Something went wrong";
|
|
213
|
-
|
|
213
|
+
U(f, "error", x, t), V(f, x, `Sorry, an error occurred: ${t}. Please try again.`);
|
|
214
214
|
} finally {
|
|
215
|
-
Fe.current.delete(
|
|
215
|
+
Fe.current.delete(E);
|
|
216
216
|
}
|
|
217
217
|
}, [
|
|
218
|
-
|
|
218
|
+
F,
|
|
219
|
+
B,
|
|
220
|
+
M,
|
|
221
|
+
G,
|
|
222
|
+
Te,
|
|
223
|
+
xe,
|
|
219
224
|
z,
|
|
220
|
-
j,
|
|
221
|
-
W,
|
|
222
|
-
Ee,
|
|
223
|
-
Se,
|
|
224
|
-
R,
|
|
225
225
|
Ie,
|
|
226
|
-
M,
|
|
227
226
|
N,
|
|
228
|
-
|
|
229
|
-
U,
|
|
230
|
-
L,
|
|
227
|
+
P,
|
|
231
228
|
H,
|
|
232
|
-
|
|
229
|
+
W,
|
|
230
|
+
R,
|
|
231
|
+
U,
|
|
232
|
+
A,
|
|
233
233
|
X,
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
]), Le =
|
|
234
|
+
V,
|
|
235
|
+
be
|
|
236
|
+
]), Le = E((e) => {
|
|
237
237
|
Z(e);
|
|
238
|
-
}, [Z]), Re =
|
|
239
|
-
let e = [...
|
|
238
|
+
}, [Z]), Re = E(() => {
|
|
239
|
+
let e = [...q].reverse().find((e) => e.role === "user"), t = F ? Pe.current[F] ?? [] : [];
|
|
240
240
|
e && Z(e.content, t);
|
|
241
241
|
}, [
|
|
242
|
-
|
|
242
|
+
q,
|
|
243
243
|
Z,
|
|
244
|
-
|
|
245
|
-
]), Q =
|
|
246
|
-
|
|
244
|
+
F
|
|
245
|
+
]), Q = O(Z);
|
|
246
|
+
D(() => {
|
|
247
247
|
Q.current = Z;
|
|
248
|
-
}, [Z]),
|
|
248
|
+
}, [Z]), D(() => {
|
|
249
249
|
let t = e.getState().consumePendingPrompt();
|
|
250
250
|
return t && Q.current(t), e.subscribe((t, n) => {
|
|
251
251
|
if (t.pendingPrompt && t.pendingPrompt !== n.pendingPrompt) {
|
|
@@ -254,62 +254,62 @@ var N = () => {
|
|
|
254
254
|
}
|
|
255
255
|
});
|
|
256
256
|
}, []);
|
|
257
|
-
let $ =
|
|
258
|
-
let n =
|
|
257
|
+
let $ = E((t) => {
|
|
258
|
+
let n = F ? e.getState().conversations.find((e) => e.id === F) : void 0;
|
|
259
259
|
if (n && (n.messages.length > 0 || n.backendSessionId)) {
|
|
260
260
|
if (n.mode !== t) {
|
|
261
261
|
let n = e.getState().conversations.find((n) => n.mode === t && n.messages.length === 0 && !n.backendSessionId && !e.getState().processingByConversationId[n.id]);
|
|
262
|
-
n ?
|
|
262
|
+
n ? Ce(n.id) : z(void 0, t);
|
|
263
263
|
}
|
|
264
|
-
} else
|
|
265
|
-
|
|
264
|
+
} else F && R(F, t);
|
|
265
|
+
L(t);
|
|
266
266
|
}, [
|
|
267
|
-
|
|
267
|
+
F,
|
|
268
|
+
z,
|
|
269
|
+
Ce,
|
|
268
270
|
R,
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
]), ze = T((t) => {
|
|
273
|
-
if (y.find((e) => e.id === t)?.writeCapable && !e.getState().apiCallsAcknowledged) {
|
|
271
|
+
L
|
|
272
|
+
]), ze = E((t) => {
|
|
273
|
+
if (b.find((e) => e.id === t)?.writeCapable && !e.getState().apiCallsAcknowledged) {
|
|
274
274
|
Ne(t);
|
|
275
275
|
return;
|
|
276
276
|
}
|
|
277
277
|
$(t);
|
|
278
|
-
}, [$]), Be =
|
|
279
|
-
let e =
|
|
280
|
-
Ne(null),
|
|
278
|
+
}, [$]), Be = E(() => {
|
|
279
|
+
let e = Me;
|
|
280
|
+
Ne(null), Ee(), e && $(e);
|
|
281
281
|
}, [
|
|
282
|
-
|
|
283
|
-
|
|
282
|
+
Me,
|
|
283
|
+
Ee,
|
|
284
284
|
$
|
|
285
|
-
]), Ve =
|
|
285
|
+
]), Ve = E(() => {
|
|
286
286
|
Ne(null);
|
|
287
287
|
}, []);
|
|
288
|
-
return /* @__PURE__ */
|
|
288
|
+
return /* @__PURE__ */ de("div", {
|
|
289
289
|
className: "flex flex-1 flex-col overflow-hidden",
|
|
290
290
|
children: [
|
|
291
|
-
|
|
292
|
-
mode:
|
|
291
|
+
q.length === 0 ? /* @__PURE__ */ k(x, {
|
|
292
|
+
mode: I,
|
|
293
293
|
onSuggestionClick: Le
|
|
294
|
-
}) : /* @__PURE__ */
|
|
294
|
+
}) : /* @__PURE__ */ k("div", {
|
|
295
295
|
className: "flex min-h-0 flex-1 flex-col",
|
|
296
|
-
children: /* @__PURE__ */
|
|
297
|
-
messages:
|
|
298
|
-
streamingMessageId:
|
|
299
|
-
failedMessageId:
|
|
296
|
+
children: /* @__PURE__ */ k(v, {
|
|
297
|
+
messages: q,
|
|
298
|
+
streamingMessageId: Oe,
|
|
299
|
+
failedMessageId: ke,
|
|
300
300
|
onRetry: Re
|
|
301
301
|
})
|
|
302
302
|
}),
|
|
303
|
-
/* @__PURE__ */
|
|
303
|
+
/* @__PURE__ */ k(S, {
|
|
304
304
|
onSend: (e, t) => void Z(e, t),
|
|
305
|
-
disabled:
|
|
306
|
-
placeholder:
|
|
307
|
-
mode:
|
|
308
|
-
availableModes:
|
|
305
|
+
disabled: De,
|
|
306
|
+
placeholder: I === "api-calls" ? A("healthybowl.assistant.chatArea.placeholderActions", "What would you like me to do?") : A("healthybowl.assistant.chatArea.placeholderGeneral", "Ask HealthyBowl anything…"),
|
|
307
|
+
mode: I,
|
|
308
|
+
availableModes: je,
|
|
309
309
|
onModeChange: ze
|
|
310
310
|
}),
|
|
311
|
-
/* @__PURE__ */
|
|
312
|
-
open:
|
|
311
|
+
/* @__PURE__ */ k(y, {
|
|
312
|
+
open: Me !== null,
|
|
313
313
|
onConfirm: Be,
|
|
314
314
|
onCancel: Ve
|
|
315
315
|
})
|
|
@@ -317,6 +317,6 @@ var N = () => {
|
|
|
317
317
|
});
|
|
318
318
|
};
|
|
319
319
|
//#endregion
|
|
320
|
-
export {
|
|
320
|
+
export { P as AssistantChatArea };
|
|
321
321
|
|
|
322
322
|
//# sourceMappingURL=AssistantChatArea.js.map
|