@burdenoff/microfe-healthybowl 2026.829.3 → 2026.829.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,79 +1,81 @@
1
1
  import { useTr as e } from "../../shared/hooks/useTr.js";
2
2
  import { AssistantExportMenu as t } from "./AssistantExportMenu.js";
3
3
  import { AssistantAutoSpeakToggle as n } from "./AssistantAutoSpeakToggle.js";
4
- import { History as r, PanelBottom as i, PanelRight as a, Plus as o, Sparkles as s, X as c } from "lucide-react";
5
- import { jsx as l, jsxs as u } from "react/jsx-runtime";
4
+ import { AssistantVoiceSelector as r } from "./composer/AssistantVoiceSelector.js";
5
+ import { History as i, PanelBottom as a, PanelRight as o, Plus as s, Sparkles as c, X as l } from "lucide-react";
6
+ import { jsx as u, jsxs as d } from "react/jsx-runtime";
6
7
  //#region src/components/assistant/AssistantHeader.tsx
7
- var d = ({ contextLabel: d, onNewConversation: f, onOpenHistory: p, historyOpen: m, onClose: h, docked: g, onToggleDock: _ }) => {
8
- let v = e();
9
- return /* @__PURE__ */ u("div", {
8
+ var f = ({ contextLabel: f, onNewConversation: p, onOpenHistory: m, historyOpen: h, onClose: g, docked: _, onToggleDock: v }) => {
9
+ let y = e();
10
+ return /* @__PURE__ */ d("div", {
10
11
  className: "flex items-center gap-2 border-b border-border-default bg-bg-elevated px-3 py-2.5",
11
- children: [/* @__PURE__ */ u("div", {
12
+ children: [/* @__PURE__ */ d("div", {
12
13
  className: "flex min-w-0 flex-1 items-center gap-2",
13
- children: [/* @__PURE__ */ l("span", {
14
+ children: [/* @__PURE__ */ u("span", {
14
15
  className: "flex size-7 flex-shrink-0 items-center justify-center rounded-lg bg-gradient-to-br from-action-primary-bg/25 to-action-primary-bg/5 text-action-primary-bg",
15
- children: /* @__PURE__ */ l(s, { className: "size-4" })
16
- }), /* @__PURE__ */ u("span", {
16
+ children: /* @__PURE__ */ u(c, { className: "size-4" })
17
+ }), /* @__PURE__ */ d("span", {
17
18
  className: "min-w-0 flex-1",
18
- children: [/* @__PURE__ */ l("span", {
19
+ children: [/* @__PURE__ */ u("span", {
19
20
  className: "block truncate text-[14px] font-semibold leading-tight text-text-primary",
20
- children: v("healthybowl.assistant.header.title", "HealthyBowl AI")
21
- }), /* @__PURE__ */ u("span", {
21
+ children: y("healthybowl.assistant.header.title", "HealthyBowl AI")
22
+ }), /* @__PURE__ */ d("span", {
22
23
  className: "block truncate text-[11px] leading-tight text-text-muted",
23
24
  children: [
24
- v("healthybowl.assistant.header.ready", "Ready"),
25
- /* @__PURE__ */ l("span", {
25
+ y("healthybowl.assistant.header.ready", "Ready"),
26
+ /* @__PURE__ */ u("span", {
26
27
  "aria-hidden": "true",
27
28
  children: " · "
28
29
  }),
29
- v("healthybowl.assistant.header.context", "Context: {{page}}", { page: d })
30
+ y("healthybowl.assistant.header.context", "Context: {{page}}", { page: f })
30
31
  ]
31
32
  })]
32
33
  })]
33
- }), /* @__PURE__ */ u("div", {
34
+ }), /* @__PURE__ */ d("div", {
34
35
  className: "flex flex-shrink-0 items-center gap-0.5",
35
36
  children: [
36
- /* @__PURE__ */ l("button", {
37
+ /* @__PURE__ */ u("button", {
37
38
  type: "button",
38
- onClick: f,
39
+ onClick: p,
39
40
  className: "rounded-lg p-1.5 text-text-secondary transition-colors hover:bg-bg-sunken hover:text-text-primary",
40
- "aria-label": v("healthybowl.assistant.header.newConversation", "New conversation"),
41
+ "aria-label": y("healthybowl.assistant.header.newConversation", "New conversation"),
41
42
  "data-testid": "assistant-new-conversation",
42
- children: /* @__PURE__ */ l(o, { className: "size-4" })
43
+ children: /* @__PURE__ */ u(s, { className: "size-4" })
43
44
  }),
44
- /* @__PURE__ */ l("button", {
45
+ /* @__PURE__ */ u("button", {
45
46
  type: "button",
46
- onClick: p,
47
- className: `rounded-lg p-1.5 transition-colors ${m ? "bg-action-primary-bg/15 text-action-primary-bg" : "text-text-secondary hover:bg-bg-sunken hover:text-text-primary"}`,
48
- "aria-label": v("healthybowl.assistant.header.history", "Conversation history"),
49
- "aria-pressed": m,
47
+ onClick: m,
48
+ className: `rounded-lg p-1.5 transition-colors ${h ? "bg-action-primary-bg/15 text-action-primary-bg" : "text-text-secondary hover:bg-bg-sunken hover:text-text-primary"}`,
49
+ "aria-label": y("healthybowl.assistant.header.history", "Conversation history"),
50
+ "aria-pressed": h,
50
51
  "data-testid": "assistant-open-history",
51
- children: /* @__PURE__ */ l(r, { className: "size-4" })
52
+ children: /* @__PURE__ */ u(i, { className: "size-4" })
52
53
  }),
53
- /* @__PURE__ */ l(n, {}),
54
- /* @__PURE__ */ l(t, {}),
55
- _ && /* @__PURE__ */ l("button", {
54
+ /* @__PURE__ */ u(n, {}),
55
+ /* @__PURE__ */ u(r, {}),
56
+ /* @__PURE__ */ u(t, {}),
57
+ v && /* @__PURE__ */ u("button", {
56
58
  type: "button",
57
- onClick: _,
59
+ onClick: v,
58
60
  className: "hidden rounded-lg p-1.5 text-text-secondary transition-colors hover:bg-bg-sunken hover:text-text-primary md:inline-flex",
59
- "aria-label": g ? v("healthybowl.assistant.header.float", "Float chat window") : v("healthybowl.assistant.header.dock", "Dock to side panel"),
60
- "aria-pressed": g,
61
+ "aria-label": _ ? y("healthybowl.assistant.header.float", "Float chat window") : y("healthybowl.assistant.header.dock", "Dock to side panel"),
62
+ "aria-pressed": _,
61
63
  "data-testid": "assistant-toggle-dock",
62
- children: l(g ? i : a, { className: "size-4" })
64
+ children: u(_ ? a : o, { className: "size-4" })
63
65
  }),
64
- /* @__PURE__ */ l("button", {
66
+ /* @__PURE__ */ u("button", {
65
67
  type: "button",
66
- onClick: h,
68
+ onClick: g,
67
69
  className: "rounded-lg p-1.5 text-text-secondary transition-colors hover:bg-bg-sunken hover:text-text-primary",
68
- "aria-label": v("healthybowl.assistant.header.close", "Close assistant"),
70
+ "aria-label": y("healthybowl.assistant.header.close", "Close assistant"),
69
71
  "data-testid": "assistant-close",
70
- children: /* @__PURE__ */ l(c, { className: "size-4" })
72
+ children: /* @__PURE__ */ u(l, { className: "size-4" })
71
73
  })
72
74
  ]
73
75
  })]
74
76
  });
75
77
  };
76
78
  //#endregion
77
- export { d as AssistantHeader };
79
+ export { f as AssistantHeader };
78
80
 
79
81
  //# sourceMappingURL=AssistantHeader.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AssistantHeader.js","names":[],"sources":["../../../src/components/assistant/AssistantHeader.tsx"],"sourcesContent":["import type { FC } from 'react';\nimport { Sparkles, Plus, History, PanelRight, PanelBottom, X } from 'lucide-react';\nimport { AssistantExportMenu } from './AssistantExportMenu';\nimport { AssistantAutoSpeakToggle } from './AssistantAutoSpeakToggle';\nimport { useTr } from '../../shared/hooks/useTr';\n\ninterface Props {\n /** Friendly label for the page the user is on (e.g. \"Inventory\"). */\n contextLabel: string;\n onNewConversation: () => void;\n onOpenHistory: () => void;\n /** True when the history drawer is currently open (drives the toggle state). */\n historyOpen: boolean;\n onClose: () => void;\n docked?: boolean;\n onToggleDock?: () => void;\n}\n\n/**\n * AssistantHeader — the v2 identity bar (per the ai-assistant-v2 mockups):\n * a ✦ brand mark + \"HealthyBowl AI\", a small availability/context subtitle\n * (\"Ready · Context: <page>\"), and a row of icon actions: New conversation,\n * History (opens the conversation list as an overlay drawer — NOT an accordion),\n * Export, Dock toggle, Close.\n *\n * Replaces the old \"Conversation History\" accordion header. HB semantic tokens\n * only; copy via useTr.\n */\nexport const AssistantHeader: FC<Props> = ({\n contextLabel,\n onNewConversation,\n onOpenHistory,\n historyOpen,\n onClose,\n docked,\n onToggleDock,\n}) => {\n const tr = useTr();\n\n return (\n <div className=\"flex items-center gap-2 border-b border-border-default bg-bg-elevated px-3 py-2.5\">\n {/* Brand + context subtitle */}\n <div className=\"flex min-w-0 flex-1 items-center gap-2\">\n <span className=\"flex size-7 flex-shrink-0 items-center justify-center rounded-lg bg-gradient-to-br from-action-primary-bg/25 to-action-primary-bg/5 text-action-primary-bg\">\n <Sparkles className=\"size-4\" />\n </span>\n <span className=\"min-w-0 flex-1\">\n <span className=\"block truncate text-[14px] font-semibold leading-tight text-text-primary\">\n {tr('healthybowl.assistant.header.title', 'HealthyBowl AI')}\n </span>\n <span className=\"block truncate text-[11px] leading-tight text-text-muted\">\n {tr('healthybowl.assistant.header.ready', 'Ready')}\n <span aria-hidden=\"true\"> · </span>\n {tr('healthybowl.assistant.header.context', 'Context: {{page}}', { page: contextLabel })}\n </span>\n </span>\n </div>\n\n {/* Actions */}\n <div className=\"flex flex-shrink-0 items-center gap-0.5\">\n <button\n type=\"button\"\n onClick={onNewConversation}\n className=\"rounded-lg p-1.5 text-text-secondary transition-colors hover:bg-bg-sunken hover:text-text-primary\"\n aria-label={tr('healthybowl.assistant.header.newConversation', 'New conversation')}\n data-testid=\"assistant-new-conversation\"\n >\n <Plus className=\"size-4\" />\n </button>\n <button\n type=\"button\"\n onClick={onOpenHistory}\n className={`rounded-lg p-1.5 transition-colors ${\n historyOpen\n ? 'bg-action-primary-bg/15 text-action-primary-bg'\n : 'text-text-secondary hover:bg-bg-sunken hover:text-text-primary'\n }`}\n aria-label={tr('healthybowl.assistant.header.history', 'Conversation history')}\n aria-pressed={historyOpen}\n data-testid=\"assistant-open-history\"\n >\n <History className=\"size-4\" />\n </button>\n {/* Renders nothing where the browser has no speech output. */}\n <AssistantAutoSpeakToggle />\n <AssistantExportMenu />\n {onToggleDock && (\n <button\n type=\"button\"\n onClick={onToggleDock}\n className=\"hidden rounded-lg p-1.5 text-text-secondary transition-colors hover:bg-bg-sunken hover:text-text-primary md:inline-flex\"\n aria-label={\n docked\n ? tr('healthybowl.assistant.header.float', 'Float chat window')\n : tr('healthybowl.assistant.header.dock', 'Dock to side panel')\n }\n aria-pressed={docked}\n data-testid=\"assistant-toggle-dock\"\n >\n {docked ? <PanelBottom className=\"size-4\" /> : <PanelRight className=\"size-4\" />}\n </button>\n )}\n <button\n type=\"button\"\n onClick={onClose}\n className=\"rounded-lg p-1.5 text-text-secondary transition-colors hover:bg-bg-sunken hover:text-text-primary\"\n aria-label={tr('healthybowl.assistant.header.close', 'Close assistant')}\n data-testid=\"assistant-close\"\n >\n <X className=\"size-4\" />\n </button>\n </div>\n </div>\n );\n};\n"],"mappings":";;;;;;AA4BA,IAAa,KAA8B,EACzC,iBACA,sBACA,kBACA,gBACA,YACA,WACA,sBACI;CACJ,IAAM,IAAK,EAAM;CAEjB,OACE,kBAAC,OAAD;EAAK,WAAU;YAAf,CAEE,kBAAC,OAAD;GAAK,WAAU;aAAf,CACE,kBAAC,QAAD;IAAM,WAAU;cACd,kBAAC,GAAD,EAAU,WAAU,SAAU,CAAA;GAC1B,CAAA,GACN,kBAAC,QAAD;IAAM,WAAU;cAAhB,CACE,kBAAC,QAAD;KAAM,WAAU;eACb,EAAG,sCAAsC,gBAAgB;IACtD,CAAA,GACN,kBAAC,QAAD;KAAM,WAAU;eAAhB;MACG,EAAG,sCAAsC,OAAO;MACjD,kBAAC,QAAD;OAAM,eAAY;iBAAO;MAAS,CAAA;MACjC,EAAG,wCAAwC,qBAAqB,EAAE,MAAM,EAAa,CAAC;KACnF;MACF;KACH;MAGL,kBAAC,OAAD;GAAK,WAAU;aAAf;IACE,kBAAC,UAAD;KACE,MAAK;KACL,SAAS;KACT,WAAU;KACV,cAAY,EAAG,gDAAgD,kBAAkB;KACjF,eAAY;eAEZ,kBAAC,GAAD,EAAM,WAAU,SAAU,CAAA;IACpB,CAAA;IACR,kBAAC,UAAD;KACE,MAAK;KACL,SAAS;KACT,WAAW,sCACT,IACI,mDACA;KAEN,cAAY,EAAG,wCAAwC,sBAAsB;KAC7E,gBAAc;KACd,eAAY;eAEZ,kBAAC,GAAD,EAAS,WAAU,SAAU,CAAA;IACvB,CAAA;IAER,kBAAC,GAAD,CAA2B,CAAA;IAC3B,kBAAC,GAAD,CAAsB,CAAA;IACrB,KACC,kBAAC,UAAD;KACE,MAAK;KACL,SAAS;KACT,WAAU;KACV,cACE,IACI,EAAG,sCAAsC,mBAAmB,IAC5D,EAAG,qCAAqC,oBAAoB;KAElE,gBAAc;KACd,eAAY;eAEF,EAAT,IAAU,IAAqC,GAAtC,EAAa,WAAU,SAAU,CAAoC;IACzE,CAAA;IAEV,kBAAC,UAAD;KACE,MAAK;KACL,SAAS;KACT,WAAU;KACV,cAAY,EAAG,sCAAsC,iBAAiB;KACtE,eAAY;eAEZ,kBAAC,GAAD,EAAG,WAAU,SAAU,CAAA;IACjB,CAAA;GACL;IACF;;AAET"}
1
+ {"version":3,"file":"AssistantHeader.js","names":[],"sources":["../../../src/components/assistant/AssistantHeader.tsx"],"sourcesContent":["import type { FC } from 'react';\nimport { Sparkles, Plus, History, PanelRight, PanelBottom, X } from 'lucide-react';\nimport { AssistantExportMenu } from './AssistantExportMenu';\nimport { AssistantAutoSpeakToggle } from './AssistantAutoSpeakToggle';\nimport { AssistantVoiceSelector } from './composer/AssistantVoiceSelector';\nimport { useTr } from '../../shared/hooks/useTr';\n\ninterface Props {\n /** Friendly label for the page the user is on (e.g. \"Inventory\"). */\n contextLabel: string;\n onNewConversation: () => void;\n onOpenHistory: () => void;\n /** True when the history drawer is currently open (drives the toggle state). */\n historyOpen: boolean;\n onClose: () => void;\n docked?: boolean;\n onToggleDock?: () => void;\n}\n\n/**\n * AssistantHeader — the v2 identity bar (per the ai-assistant-v2 mockups):\n * a ✦ brand mark + \"HealthyBowl AI\", a small availability/context subtitle\n * (\"Ready · Context: <page>\"), and a row of icon actions: New conversation,\n * History (opens the conversation list as an overlay drawer — NOT an accordion),\n * Export, Dock toggle, Close.\n *\n * Replaces the old \"Conversation History\" accordion header. HB semantic tokens\n * only; copy via useTr.\n */\nexport const AssistantHeader: FC<Props> = ({\n contextLabel,\n onNewConversation,\n onOpenHistory,\n historyOpen,\n onClose,\n docked,\n onToggleDock,\n}) => {\n const tr = useTr();\n\n return (\n <div className=\"flex items-center gap-2 border-b border-border-default bg-bg-elevated px-3 py-2.5\">\n {/* Brand + context subtitle */}\n <div className=\"flex min-w-0 flex-1 items-center gap-2\">\n <span className=\"flex size-7 flex-shrink-0 items-center justify-center rounded-lg bg-gradient-to-br from-action-primary-bg/25 to-action-primary-bg/5 text-action-primary-bg\">\n <Sparkles className=\"size-4\" />\n </span>\n <span className=\"min-w-0 flex-1\">\n <span className=\"block truncate text-[14px] font-semibold leading-tight text-text-primary\">\n {tr('healthybowl.assistant.header.title', 'HealthyBowl AI')}\n </span>\n <span className=\"block truncate text-[11px] leading-tight text-text-muted\">\n {tr('healthybowl.assistant.header.ready', 'Ready')}\n <span aria-hidden=\"true\"> · </span>\n {tr('healthybowl.assistant.header.context', 'Context: {{page}}', { page: contextLabel })}\n </span>\n </span>\n </div>\n\n {/* Actions */}\n <div className=\"flex flex-shrink-0 items-center gap-0.5\">\n <button\n type=\"button\"\n onClick={onNewConversation}\n className=\"rounded-lg p-1.5 text-text-secondary transition-colors hover:bg-bg-sunken hover:text-text-primary\"\n aria-label={tr('healthybowl.assistant.header.newConversation', 'New conversation')}\n data-testid=\"assistant-new-conversation\"\n >\n <Plus className=\"size-4\" />\n </button>\n <button\n type=\"button\"\n onClick={onOpenHistory}\n className={`rounded-lg p-1.5 transition-colors ${\n historyOpen\n ? 'bg-action-primary-bg/15 text-action-primary-bg'\n : 'text-text-secondary hover:bg-bg-sunken hover:text-text-primary'\n }`}\n aria-label={tr('healthybowl.assistant.header.history', 'Conversation history')}\n aria-pressed={historyOpen}\n data-testid=\"assistant-open-history\"\n >\n <History className=\"size-4\" />\n </button>\n {/* Renders nothing where the browser has no speech output. */}\n <AssistantAutoSpeakToggle />\n {/* Beside the auto-speak toggle rather than in the composer: it is a\n playback setting, and the composer row is already exactly full at\n 390px — a fourth chip there would push send off the edge. Renders\n nothing when the device offers fewer than two voices. */}\n <AssistantVoiceSelector />\n <AssistantExportMenu />\n {onToggleDock && (\n <button\n type=\"button\"\n onClick={onToggleDock}\n className=\"hidden rounded-lg p-1.5 text-text-secondary transition-colors hover:bg-bg-sunken hover:text-text-primary md:inline-flex\"\n aria-label={\n docked\n ? tr('healthybowl.assistant.header.float', 'Float chat window')\n : tr('healthybowl.assistant.header.dock', 'Dock to side panel')\n }\n aria-pressed={docked}\n data-testid=\"assistant-toggle-dock\"\n >\n {docked ? <PanelBottom className=\"size-4\" /> : <PanelRight className=\"size-4\" />}\n </button>\n )}\n <button\n type=\"button\"\n onClick={onClose}\n className=\"rounded-lg p-1.5 text-text-secondary transition-colors hover:bg-bg-sunken hover:text-text-primary\"\n aria-label={tr('healthybowl.assistant.header.close', 'Close assistant')}\n data-testid=\"assistant-close\"\n >\n <X className=\"size-4\" />\n </button>\n </div>\n </div>\n );\n};\n"],"mappings":";;;;;;;AA6BA,IAAa,KAA8B,EACzC,iBACA,sBACA,kBACA,gBACA,YACA,WACA,sBACI;CACJ,IAAM,IAAK,EAAM;CAEjB,OACE,kBAAC,OAAD;EAAK,WAAU;YAAf,CAEE,kBAAC,OAAD;GAAK,WAAU;aAAf,CACE,kBAAC,QAAD;IAAM,WAAU;cACd,kBAAC,GAAD,EAAU,WAAU,SAAU,CAAA;GAC1B,CAAA,GACN,kBAAC,QAAD;IAAM,WAAU;cAAhB,CACE,kBAAC,QAAD;KAAM,WAAU;eACb,EAAG,sCAAsC,gBAAgB;IACtD,CAAA,GACN,kBAAC,QAAD;KAAM,WAAU;eAAhB;MACG,EAAG,sCAAsC,OAAO;MACjD,kBAAC,QAAD;OAAM,eAAY;iBAAO;MAAS,CAAA;MACjC,EAAG,wCAAwC,qBAAqB,EAAE,MAAM,EAAa,CAAC;KACnF;MACF;KACH;MAGL,kBAAC,OAAD;GAAK,WAAU;aAAf;IACE,kBAAC,UAAD;KACE,MAAK;KACL,SAAS;KACT,WAAU;KACV,cAAY,EAAG,gDAAgD,kBAAkB;KACjF,eAAY;eAEZ,kBAAC,GAAD,EAAM,WAAU,SAAU,CAAA;IACpB,CAAA;IACR,kBAAC,UAAD;KACE,MAAK;KACL,SAAS;KACT,WAAW,sCACT,IACI,mDACA;KAEN,cAAY,EAAG,wCAAwC,sBAAsB;KAC7E,gBAAc;KACd,eAAY;eAEZ,kBAAC,GAAD,EAAS,WAAU,SAAU,CAAA;IACvB,CAAA;IAER,kBAAC,GAAD,CAA2B,CAAA;IAK3B,kBAAC,GAAD,CAAyB,CAAA;IACzB,kBAAC,GAAD,CAAsB,CAAA;IACrB,KACC,kBAAC,UAAD;KACE,MAAK;KACL,SAAS;KACT,WAAU;KACV,cACE,IACI,EAAG,sCAAsC,mBAAmB,IAC5D,EAAG,qCAAqC,oBAAoB;KAElE,gBAAc;KACd,eAAY;eAEF,EAAT,IAAU,IAAqC,GAAtC,EAAa,WAAU,SAAU,CAAoC;IACzE,CAAA;IAEV,kBAAC,UAAD;KACE,MAAK;KACL,SAAS;KACT,WAAU;KACV,cAAY,EAAG,sCAAsC,iBAAiB;KACtE,eAAY;eAEZ,kBAAC,GAAD,EAAG,WAAU,SAAU,CAAA;IACjB,CAAA;GACL;IACF;;AAET"}
@@ -2,29 +2,35 @@ import { useAssistantStore as e } from "../../store/assistantStore.js";
2
2
  import { useTr as t } from "../../shared/hooks/useTr.js";
3
3
  import { browserSpeechEngine as n } from "../../services/speech/browserSpeechEngine.js";
4
4
  import { chunkForSpeech as r, toSpeakableText as i } from "../../utils/speakableText.js";
5
- import { VOICE_LIST_TIMEOUT_MS as a, languageDisplayName as o, selectVoiceForLocale as s, speechGate as c, speechLangForLocale as l, voiceAvailability as u } from "../../utils/speechVoices.js";
5
+ import { VOICE_LIST_TIMEOUT_MS as a, languageDisplayName as o, selectVoiceForLocale as s, speechGate as ee, speechLangForLocale as c, voiceAvailability as l, voicesForLocale as u } from "../../utils/speechVoices.js";
6
6
  import { resolveSpeechLocale as d } from "../../utils/replyLanguage.js";
7
- import { findAssistantLanguage as f, resolveAssistantLanguage as p } from "../../config/assistantLanguages.js";
8
- import { IDLE_PLAYBACK as ee, isSpeakingMessage as m, speechPlaybackReducer as te } from "../../utils/speechPlayback.js";
9
- import { isTurnInFlight as ne } from "../../utils/assistantTurnState.js";
10
- import { parseToolActivity as re } from "./AssistantToolActivity.js";
11
- import { createContext as h, useCallback as g, useContext as _, useEffect as v, useMemo as y, useReducer as ie, useRef as b, useState as x } from "react";
12
- import { useI18n as ae } from "@burdenoff/fe-libs/shared/providers/shell/I18nProvider";
13
- import { jsx as oe } from "react/jsx-runtime";
7
+ import { findAssistantLanguage as f, resolveAssistantLanguage as te } from "../../config/assistantLanguages.js";
8
+ import { IDLE_PLAYBACK as ne, isSpeakingMessage as p, speechPlaybackReducer as re } from "../../utils/speechPlayback.js";
9
+ import { isTurnInFlight as ie } from "../../utils/assistantTurnState.js";
10
+ import { parseToolActivity as ae } from "./AssistantToolActivity.js";
11
+ import { createContext as m, useCallback as h, useContext as g, useEffect as _, useMemo as v, useReducer as oe, useRef as y, useState as b } from "react";
12
+ import { useI18n as se } from "@burdenoff/fe-libs/shared/providers/shell/I18nProvider";
13
+ import { jsx as ce } from "react/jsx-runtime";
14
14
  //#region src/components/assistant/AssistantSpeechProvider.tsx
15
- var se = {
15
+ var le = {
16
16
  codeBlock: "",
17
17
  image: "",
18
18
  link: "",
19
19
  largeTable: "",
20
20
  truncated: "",
21
+ emailAt: "at",
22
+ emailDot: "dot",
21
23
  nestedItem: ""
22
- }, S = h({
24
+ }, x = m({
23
25
  isSupported: !1,
24
26
  availability: "unsupported",
25
27
  isBlocked: !0,
26
28
  disabledReason: null,
27
29
  blockedFor: () => null,
30
+ voiceChoices: [],
31
+ activeVoiceName: null,
32
+ preferredVoiceName: null,
33
+ setVoice: () => {},
28
34
  speakingMessageId: null,
29
35
  isSpeaking: () => !1,
30
36
  toggle: () => {},
@@ -32,196 +38,215 @@ var se = {
32
38
  autoSpeakEnabled: !1,
33
39
  setAutoSpeak: () => {}
34
40
  });
35
- function C() {
36
- return _(S);
41
+ function S() {
42
+ return g(x);
37
43
  }
38
- var w = ({ children: h, visible: _ = !0, engine: C = n }) => {
39
- let w = t(), { locale: T } = ae(), [E, D] = ie(te, ee), [O, k] = x(() => C.listVoices()), [A, j] = x(!1), [M, N] = x(() => /* @__PURE__ */ new Map()), P = b(0), F = b(null), I = b(() => {}), L = g(() => {
40
- F.current?.(), F.current = null;
41
- }, []), R = e((e) => e.autoSpeakEnabled), z = e((e) => e.setAutoSpeak), ce = e((e) => e.activeConversationId), B = y(() => C.isSupported(), [C]);
42
- v(() => {
43
- if (!B) return;
44
+ var C = ({ children: m, visible: g = !0, engine: S = n }) => {
45
+ let C = t(), { locale: w } = se(), [T, E] = oe(re, ne), [D, O] = b(() => S.listVoices()), [k, A] = b(!1), [j, M] = b(() => /* @__PURE__ */ new Map()), N = y(0), P = y(null), F = y(() => {}), I = h(() => {
46
+ P.current?.(), P.current = null;
47
+ }, []), L = e((e) => e.autoSpeakEnabled), R = e((e) => e.setAutoSpeak), ue = e((e) => e.activeConversationId), z = v(() => S.isSupported(), [S]);
48
+ _(() => {
49
+ if (!z) return;
44
50
  let e = () => {
45
- k(C.listVoices()), N((e) => e.size === 0 ? e : /* @__PURE__ */ new Map());
51
+ O(S.listVoices()), M((e) => e.size === 0 ? e : /* @__PURE__ */ new Map());
46
52
  };
47
- return e(), C.subscribeVoices(e);
48
- }, [C, B]);
49
- let V = e((e) => e.assistantLanguage), H = y(() => p(V, T), [V, T]), U = H.code, W = g((e) => f(e)?.tag ?? l(e), []), G = y(() => u(B, O, H.tag, A), [
50
- B,
51
- O,
52
- H,
53
- A
54
- ]), K = y(() => ({
55
- codeBlock: w("healthybowl.assistant.speech.codeBlock", "Code block"),
56
- image: w("healthybowl.assistant.speech.image", "image"),
57
- link: w("healthybowl.assistant.speech.link", "link"),
58
- largeTable: w("healthybowl.assistant.speech.largeTable", "Table with {{rows}} rows and {{columns}} columns"),
59
- truncated: w("healthybowl.assistant.speech.truncated", "The rest of this message is not read aloud"),
60
- nestedItem: w("healthybowl.assistant.speech.nestedItem", "Sub-item {{ordinal}}")
61
- }), [w]), q = g(() => {
62
- L(), C.cancel(), D({ type: "stop" });
63
- }, [L, C]), J = g((e) => M.get(e) ?? null, [M]), Y = g((e, t, n) => {
64
- L();
53
+ return e(), S.subscribeVoices(e);
54
+ }, [S, z]);
55
+ let B = e((e) => e.assistantLanguage), V = e((e) => e.preferredVoices), H = e((e) => e.setPreferredVoice), U = v(() => te(B, w), [B, w]), W = U.code, G = h((e) => f(e)?.tag ?? c(e), []), K = h((e) => f(e)?.rate ?? .9, []), q = v(() => l(z, D, U.tag, k), [
56
+ z,
57
+ D,
58
+ U,
59
+ k
60
+ ]), J = v(() => ({
61
+ codeBlock: C("healthybowl.assistant.speech.codeBlock", "Code block"),
62
+ image: C("healthybowl.assistant.speech.image", "image"),
63
+ link: C("healthybowl.assistant.speech.link", "link"),
64
+ largeTable: C("healthybowl.assistant.speech.largeTable", "Table with {{rows}} rows and {{columns}} columns"),
65
+ truncated: C("healthybowl.assistant.speech.truncated", "The rest of this message is not read aloud"),
66
+ nestedItem: C("healthybowl.assistant.speech.nestedItem", "Sub-item {{ordinal}}"),
67
+ emailAt: C("healthybowl.assistant.speech.emailAt", "at"),
68
+ emailDot: C("healthybowl.assistant.speech.emailDot", "dot")
69
+ }), [C]), Y = h(() => {
70
+ I(), S.cancel(), E({ type: "stop" });
71
+ }, [I, S]), X = h((e) => j.get(e) ?? null, [j]), Z = h((e, t, n) => {
72
+ I();
65
73
  let r = !1, i = () => {}, o = (a) => {
66
74
  if (!r) {
67
- if (r = !0, F.current = null, clearTimeout(s), i(), a.length === 0) {
68
- j(!0);
75
+ if (r = !0, P.current = null, clearTimeout(s), i(), a.length === 0) {
76
+ A(!0);
69
77
  return;
70
78
  }
71
- k(a), I.current(e, t, a, n);
79
+ O(a), F.current(e, t, a, n);
72
80
  }
73
- }, s = setTimeout(() => o(C.listVoices()), a);
74
- i = C.subscribeVoices(() => o(C.listVoices())), F.current = () => {
75
- r || (r = !0, clearTimeout(s), i(), F.current = null);
81
+ }, s = setTimeout(() => o(S.listVoices()), a);
82
+ i = S.subscribeVoices(() => o(S.listVoices())), P.current = () => {
83
+ r || (r = !0, clearTimeout(s), i(), P.current = null);
76
84
  };
77
- }, [L, C]), X = g((e, t, n, i) => {
85
+ }, [I, S]), Q = h((e, t, n, i) => {
78
86
  let a = n;
79
87
  if (a.length === 0) {
80
- let e = C.listVoices();
81
- e.length > 0 && (a = e, k(e));
88
+ let e = S.listVoices();
89
+ e.length > 0 && (a = e, O(e));
82
90
  }
83
- let l = W(i), d = c(u(!0, a, i, A));
84
- if (d === "block") {
85
- let t = w("healthybowl.assistant.speech.noVoiceForReply", "This reply is in {{language}}, and no {{language}} voice is installed on this device.", { language: o(l, T) });
86
- N((n) => new Map(n).set(e, t));
91
+ let c = G(i), u = ee(l(!0, a, i, k));
92
+ if (u === "block") {
93
+ let t = C("healthybowl.assistant.speech.noVoiceForReply", "This reply is in {{language}}, and no {{language}} voice is installed on this device.", { language: o(c, w) });
94
+ M((n) => new Map(n).set(e, t));
87
95
  return;
88
96
  }
89
- if (d === "wait-for-voices") {
90
- Y(e, t, i);
97
+ if (u === "wait-for-voices") {
98
+ Z(e, t, i);
91
99
  return;
92
100
  }
93
- N((t) => {
101
+ M((t) => {
94
102
  if (!t.has(e)) return t;
95
103
  let n = new Map(t);
96
104
  return n.delete(e), n;
97
105
  });
98
- let f = P.current + 1;
99
- P.current = f, D({
106
+ let d = N.current + 1;
107
+ N.current = d, E({
100
108
  type: "start",
101
109
  messageId: e,
102
- requestId: f
103
- }), C.speak(r(t), {
104
- voice: s(a, l),
105
- lang: l
110
+ requestId: d
111
+ }), S.speak(r(t), {
112
+ voice: s(a, c, V[i]),
113
+ lang: c,
114
+ rate: K(i)
106
115
  }, {
107
- onEnd: () => D({
116
+ onEnd: () => E({
108
117
  type: "finished",
109
- requestId: f
118
+ requestId: d
110
119
  }),
111
- onError: () => D({
120
+ onError: () => E({
112
121
  type: "failed",
113
- requestId: f
122
+ requestId: d
114
123
  })
115
124
  });
116
125
  }, [
117
- C,
118
- T,
119
- W,
126
+ S,
120
127
  w,
121
- A,
122
- Y
128
+ V,
129
+ K,
130
+ G,
131
+ C,
132
+ k,
133
+ Z
123
134
  ]);
124
- v(() => {
125
- I.current = X;
126
- }, [X]);
127
- let Z = g((e, t, n) => {
128
- if (!B) return;
129
- let r = i(t, { labels: K });
130
- r && X(e, r, O, d(i(t, { labels: se }), n ?? U));
135
+ _(() => {
136
+ F.current = Q;
137
+ }, [Q]);
138
+ let $ = h((e, t, n) => {
139
+ if (!z) return;
140
+ let r = i(t, { labels: J });
141
+ r && Q(e, r, D, d(i(t, { labels: le }), n ?? W));
131
142
  }, [
132
- B,
133
- K,
134
- U,
135
- X,
136
- O
137
- ]), Q = g((e, t, n) => {
138
- if (m(E, e)) {
139
- q();
143
+ z,
144
+ J,
145
+ W,
146
+ Q,
147
+ D
148
+ ]), de = h((e, t, n) => {
149
+ if (p(T, e)) {
150
+ Y();
140
151
  return;
141
152
  }
142
- Z(e, t, n);
153
+ $(e, t, n);
143
154
  }, [
144
- E,
145
- Z,
146
- q
155
+ T,
156
+ $,
157
+ Y
147
158
  ]);
148
- v(() => {
149
- _ || q();
150
- }, [_, q]), v(() => {
151
- q(), N(/* @__PURE__ */ new Map());
152
- }, [ce, q]), v(() => {
153
- N((e) => e.size === 0 ? e : /* @__PURE__ */ new Map()), q();
154
- }, [U, q]), v(() => () => {
155
- F.current?.(), F.current = null, C.cancel();
156
- }, [C]), v(() => {
159
+ _(() => {
160
+ g || Y();
161
+ }, [g, Y]), _(() => {
162
+ Y(), M(/* @__PURE__ */ new Map());
163
+ }, [ue, Y]), _(() => {
164
+ M((e) => e.size === 0 ? e : /* @__PURE__ */ new Map()), Y();
165
+ }, [W, Y]), _(() => () => {
166
+ P.current?.(), P.current = null, S.cancel();
167
+ }, [S]), _(() => {
157
168
  if (typeof window > "u") return;
158
- let e = () => C.cancel();
169
+ let e = () => S.cancel();
159
170
  return window.addEventListener("pagehide", e), () => window.removeEventListener("pagehide", e);
160
- }, [C]), v(() => {
161
- if (typeof document > "u" || !B) return;
171
+ }, [S]), _(() => {
172
+ if (typeof document > "u" || !z) return;
162
173
  let e = () => {
163
174
  if (document.visibilityState !== "visible") return;
164
- let e = C.listVoices();
165
- e.length > 0 && L(), k(e), j(!1), N((e) => e.size === 0 ? e : /* @__PURE__ */ new Map());
175
+ let e = S.listVoices();
176
+ e.length > 0 && I(), O(e), A(!1), M((e) => e.size === 0 ? e : /* @__PURE__ */ new Map());
166
177
  };
167
178
  return document.addEventListener("visibilitychange", e), window.addEventListener("focus", e), () => {
168
179
  document.removeEventListener("visibilitychange", e), window.removeEventListener("focus", e);
169
180
  };
170
181
  }, [
171
- L,
172
- C,
173
- B
182
+ I,
183
+ S,
184
+ z
174
185
  ]);
175
- let $ = b(Z);
176
- v(() => {
177
- $.current = Z;
178
- }, [Z]), v(() => {
179
- if (!(!R || !_ || !B)) return e.subscribe((e, t) => {
186
+ let fe = y($);
187
+ _(() => {
188
+ fe.current = $;
189
+ }, [$]), _(() => {
190
+ if (!(!L || !g || !z)) return e.subscribe((e, t) => {
180
191
  let n = e.activeConversationId;
181
192
  if (!n || n !== t.activeConversationId) return;
182
193
  let r = e.processingByConversationId[n], i = t.processingByConversationId[n];
183
- if (r?.status !== "complete" || !ne(i?.status)) return;
194
+ if (r?.status !== "complete" || !ie(i?.status)) return;
184
195
  let a = r.messageId ?? i?.messageId ?? null;
185
196
  if (!a) return;
186
197
  let o = e.conversations.find((e) => e.id === n)?.messages.find((e) => e.id === a);
187
198
  if (!o || o.role !== "assistant") return;
188
- let { text: s } = re(o.content);
189
- s.trim() && $.current(a, s, o.metadata?.lang);
199
+ let { text: s } = ae(o.content);
200
+ s.trim() && fe.current(a, s, o.metadata?.lang);
190
201
  });
191
202
  }, [
192
- R,
193
- B,
194
- _
203
+ L,
204
+ z,
205
+ g
195
206
  ]);
196
- let le = y(() => ({
197
- isSupported: B,
198
- availability: G,
199
- isBlocked: G === "no-voices",
200
- disabledReason: G === "no-voices" ? w("healthybowl.assistant.speech.noVoicesOnDevice", "This device has no speech voices installed. Add one in your device speech or accessibility settings.") : null,
201
- blockedFor: J,
202
- speakingMessageId: E.status === "speaking" ? E.messageId : null,
203
- isSpeaking: (e) => m(E, e),
204
- toggle: Q,
205
- stop: q,
206
- autoSpeakEnabled: R,
207
- setAutoSpeak: z
207
+ let pe = v(() => u(D, U.tag), [D, U]), me = v(() => s(D, U.tag, V[W]), [
208
+ D,
209
+ U,
210
+ V,
211
+ W
212
+ ]), he = v(() => ({
213
+ isSupported: z,
214
+ availability: q,
215
+ isBlocked: q === "no-voices",
216
+ disabledReason: q === "no-voices" ? C("healthybowl.assistant.speech.noVoicesOnDevice", "This device has no speech voices installed. Add one in your device speech or accessibility settings.") : null,
217
+ blockedFor: X,
218
+ voiceChoices: pe,
219
+ activeVoiceName: me?.name ?? null,
220
+ preferredVoiceName: V[W] ?? null,
221
+ setVoice: (e) => H(W, e),
222
+ speakingMessageId: T.status === "speaking" ? T.messageId : null,
223
+ isSpeaking: (e) => p(T, e),
224
+ toggle: de,
225
+ stop: Y,
226
+ autoSpeakEnabled: L,
227
+ setAutoSpeak: R
208
228
  }), [
209
- B,
210
- G,
211
- J,
212
- E,
213
- Q,
229
+ z,
214
230
  q,
231
+ X,
232
+ pe,
233
+ me,
234
+ V,
235
+ H,
236
+ W,
237
+ T,
238
+ de,
239
+ Y,
240
+ L,
215
241
  R,
216
- z,
217
- w
242
+ C
218
243
  ]);
219
- return /* @__PURE__ */ oe(S.Provider, {
220
- value: le,
221
- children: h
244
+ return /* @__PURE__ */ ce(x.Provider, {
245
+ value: he,
246
+ children: m
222
247
  });
223
248
  };
224
249
  //#endregion
225
- export { w as AssistantSpeechProvider, C as useAssistantSpeech };
250
+ export { C as AssistantSpeechProvider, S as useAssistantSpeech };
226
251
 
227
252
  //# sourceMappingURL=AssistantSpeechProvider.js.map