@burdenoff/microfe-healthybowl 2026.901.16 → 2026.902.1

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,147 +1,152 @@
1
1
  import { useAssistantStore as e } from "../../store/assistantStore.js";
2
2
  import { useTr as t } from "../../shared/hooks/useTr.js";
3
3
  import { ASSISTANT_MODES as n } from "../../types/assistant.js";
4
- import { useState as r } from "react";
5
- import { Check as i, MessageSquare as a, PanelLeftClose as o, Pencil as s, Plus as c, Trash2 as l } from "lucide-react";
6
- import { Fragment as u, jsx as d, jsxs as f } from "react/jsx-runtime";
4
+ import { chatTurns as r } from "../../utils/voiceTurnVisibility.js";
5
+ import { useState as i } from "react";
6
+ import { Check as a, MessageSquare as o, PanelLeftClose as s, Pencil as c, Plus as l, Trash2 as u } from "lucide-react";
7
+ import { Fragment as d, jsx as f, jsxs as p } from "react/jsx-runtime";
7
8
  //#region src/components/assistant/AssistantConversationList.tsx
8
- var p = () => {
9
- let p = t(), { conversations: m, activeConversationId: h, processingByConversationId: g, setActiveConversation: _, setMode: v, createConversation: y, deleteConversation: b, renameConversation: x, setConversationListOpen: S } = e(), [C, w] = r(null), [T, E] = r(""), D = () => {
10
- y(), S(!1);
11
- }, O = (e) => {
12
- let t = m.find((t) => t.id === e);
13
- _(e), t && v(t.mode), S(!1);
14
- }, k = (e, t) => {
15
- w(e), E(t);
16
- }, A = () => {
17
- C && T.trim() && x(C, T.trim()), w(null);
18
- }, j = (e, t) => {
19
- e.stopPropagation(), b(t);
9
+ var m = () => {
10
+ let m = t(), { conversations: h, activeConversationId: g, processingByConversationId: _, setActiveConversation: v, setMode: y, createConversation: b, deleteConversation: x, renameConversation: S, setConversationListOpen: C } = e(), [w, T] = i(null), [E, D] = i(""), O = () => {
11
+ b(), C(!1);
12
+ }, k = (e) => {
13
+ let t = h.find((t) => t.id === e);
14
+ v(e), t && y(t.mode), C(!1);
15
+ }, A = (e, t) => {
16
+ T(e), D(t);
17
+ }, j = () => {
18
+ w && E.trim() && S(w, E.trim()), T(null);
19
+ }, M = (e, t) => {
20
+ e.stopPropagation(), x(t);
20
21
  };
21
- return /* @__PURE__ */ f("div", {
22
+ return /* @__PURE__ */ p("div", {
22
23
  className: "absolute inset-0 z-10 flex flex-col bg-bg-surface animate-in slide-in-from-left-2 fade-in duration-200",
23
24
  "data-testid": "conversation-list",
24
- children: [/* @__PURE__ */ f("div", {
25
+ children: [/* @__PURE__ */ p("div", {
25
26
  className: "flex items-center justify-between px-4 py-3 border-b border-border-default bg-bg-elevated",
26
- children: [/* @__PURE__ */ d("span", {
27
+ children: [/* @__PURE__ */ f("span", {
27
28
  className: "text-[13px] font-semibold text-text-primary",
28
- children: p("healthybowl.assistant.conversations.title", "History")
29
- }), /* @__PURE__ */ f("div", {
29
+ children: m("healthybowl.assistant.conversations.title", "History")
30
+ }), /* @__PURE__ */ p("div", {
30
31
  className: "flex items-center gap-0.5",
31
- children: [/* @__PURE__ */ d("button", {
32
+ children: [/* @__PURE__ */ f("button", {
32
33
  type: "button",
33
- onClick: D,
34
+ onClick: O,
34
35
  className: "p-1.5 rounded-lg text-text-secondary hover:bg-bg-sunken transition-colors",
35
- "aria-label": p("healthybowl.assistant.conversations.new", "New conversation"),
36
+ "aria-label": m("healthybowl.assistant.conversations.new", "New conversation"),
36
37
  "data-testid": "new-conversation",
37
- children: /* @__PURE__ */ d(c, { className: "size-4" })
38
- }), /* @__PURE__ */ f("button", {
38
+ children: /* @__PURE__ */ f(l, { className: "size-4" })
39
+ }), /* @__PURE__ */ p("button", {
39
40
  type: "button",
40
- onClick: () => S(!1),
41
+ onClick: () => C(!1),
41
42
  className: "flex items-center gap-1 px-2 py-1.5 rounded-lg text-text-secondary hover:bg-bg-sunken transition-colors",
42
- "aria-label": p("healthybowl.assistant.conversations.collapse", "Collapse history"),
43
+ "aria-label": m("healthybowl.assistant.conversations.collapse", "Collapse history"),
43
44
  "data-testid": "collapse-conversation-list",
44
- children: [/* @__PURE__ */ d(o, { className: "size-4" }), /* @__PURE__ */ d("span", {
45
+ children: [/* @__PURE__ */ f(s, { className: "size-4" }), /* @__PURE__ */ f("span", {
45
46
  className: "text-[11px] font-medium",
46
- children: p("healthybowl.assistant.conversations.collapseLabel", "Collapse")
47
+ children: m("healthybowl.assistant.conversations.collapseLabel", "Collapse")
47
48
  })]
48
49
  })]
49
50
  })]
50
- }), /* @__PURE__ */ d("div", {
51
+ }), /* @__PURE__ */ f("div", {
51
52
  className: "flex-1 overflow-y-auto",
52
- children: m.length === 0 ? /* @__PURE__ */ f("div", {
53
+ children: h.length === 0 ? /* @__PURE__ */ p("div", {
53
54
  className: "flex flex-col items-center justify-center h-full text-center px-4",
54
55
  children: [
55
- /* @__PURE__ */ d(a, { className: "size-6 text-text-muted mb-2" }),
56
- /* @__PURE__ */ d("p", {
56
+ /* @__PURE__ */ f(o, { className: "size-6 text-text-muted mb-2" }),
57
+ /* @__PURE__ */ f("p", {
57
58
  className: "text-xs text-text-muted",
58
- children: p("healthybowl.assistant.conversations.empty", "No conversations yet")
59
+ children: m("healthybowl.assistant.conversations.empty", "No conversations yet")
59
60
  }),
60
- /* @__PURE__ */ d("button", {
61
+ /* @__PURE__ */ f("button", {
61
62
  type: "button",
62
- onClick: D,
63
+ onClick: O,
63
64
  className: "mt-2 text-xs text-action-primary-bg hover:underline",
64
- children: p("healthybowl.assistant.conversations.startNew", "Start a new conversation")
65
+ children: m("healthybowl.assistant.conversations.startNew", "Start a new conversation")
65
66
  })
66
67
  ]
67
- }) : /* @__PURE__ */ d("div", {
68
+ }) : /* @__PURE__ */ f("div", {
68
69
  className: "py-1",
69
- children: m.map((e) => {
70
- let t = e.id === h, r = e.id === C, a = n.find((t) => t.id === e.mode), o = e.messages[e.messages.length - 1], c = g[e.id];
71
- return /* @__PURE__ */ d("div", {
70
+ children: h.map((e) => {
71
+ let t = e.id === g, i = e.id === w, o = n.find((t) => t.id === e.mode), s = r(e.messages), l = s[s.length - 1], h = s.length === 0 && e.messages.length > 0, v = _[e.id];
72
+ return /* @__PURE__ */ f("div", {
72
73
  role: "button",
73
74
  tabIndex: 0,
74
75
  onKeyDown: (t) => {
75
- (t.key === "Enter" || t.key === " ") && (t.preventDefault(), !r && O(e.id));
76
+ (t.key === "Enter" || t.key === " ") && (t.preventDefault(), !i && k(e.id));
76
77
  },
77
- onClick: () => !r && O(e.id),
78
+ onClick: () => !i && k(e.id),
78
79
  className: `group px-3 py-2 cursor-pointer hover:bg-bg-elevated transition-colors ${t ? "bg-bg-elevated border-l-2 border-action-primary-bg" : ""}`,
79
- children: r ? /* @__PURE__ */ f("div", {
80
+ children: i ? /* @__PURE__ */ p("div", {
80
81
  className: "flex items-center gap-1",
81
- children: [/* @__PURE__ */ d("input", {
82
- "aria-label": p("healthybowl.assistant.conversations.renameLabel", "Conversation title"),
83
- value: T,
84
- onChange: (e) => E(e.target.value),
82
+ children: [/* @__PURE__ */ f("input", {
83
+ "aria-label": m("healthybowl.assistant.conversations.renameLabel", "Conversation title"),
84
+ value: E,
85
+ onChange: (e) => D(e.target.value),
85
86
  onKeyDown: (e) => {
86
- e.key === "Enter" && A(), e.key === "Escape" && w(null);
87
+ e.key === "Enter" && j(), e.key === "Escape" && T(null);
87
88
  },
88
89
  className: "flex-1 text-xs bg-bg-sunken border border-border-default rounded px-2 py-1 text-text-primary focus:outline-none focus:border-action-primary-bg",
89
90
  onClick: (e) => e.stopPropagation()
90
- }), /* @__PURE__ */ d("button", {
91
+ }), /* @__PURE__ */ f("button", {
91
92
  type: "button",
92
93
  onClick: (e) => {
93
- e.stopPropagation(), A();
94
+ e.stopPropagation(), j();
94
95
  },
95
96
  className: "p-1 hover:bg-bg-sunken rounded",
96
- "aria-label": p("healthybowl.assistant.conversations.saveTitle", "Save title"),
97
- children: /* @__PURE__ */ d(i, { className: "size-3 text-status-success-text" })
97
+ "aria-label": m("healthybowl.assistant.conversations.saveTitle", "Save title"),
98
+ children: /* @__PURE__ */ f(a, { className: "size-3 text-status-success-text" })
98
99
  })]
99
- }) : /* @__PURE__ */ f(u, { children: [
100
- /* @__PURE__ */ f("div", {
100
+ }) : /* @__PURE__ */ p(d, { children: [
101
+ /* @__PURE__ */ p("div", {
101
102
  className: "flex items-center justify-between",
102
- children: [/* @__PURE__ */ d("span", {
103
+ children: [/* @__PURE__ */ f("span", {
103
104
  className: "text-xs font-medium text-text-primary truncate flex-1",
104
105
  children: e.title
105
- }), /* @__PURE__ */ f("div", {
106
+ }), /* @__PURE__ */ p("div", {
106
107
  className: "hidden group-hover:flex group-focus-within:flex items-center gap-0.5 ml-1",
107
- children: [/* @__PURE__ */ d("button", {
108
+ children: [/* @__PURE__ */ f("button", {
108
109
  type: "button",
109
110
  onClick: (t) => {
110
- t.stopPropagation(), k(e.id, e.title);
111
+ t.stopPropagation(), A(e.id, e.title);
111
112
  },
112
113
  className: "p-0.5 hover:bg-bg-sunken rounded",
113
- "aria-label": p("healthybowl.assistant.conversations.rename", "Rename conversation"),
114
- children: /* @__PURE__ */ d(s, { className: "size-3 text-text-muted" })
115
- }), /* @__PURE__ */ d("button", {
114
+ "aria-label": m("healthybowl.assistant.conversations.rename", "Rename conversation"),
115
+ children: /* @__PURE__ */ f(c, { className: "size-3 text-text-muted" })
116
+ }), /* @__PURE__ */ f("button", {
116
117
  type: "button",
117
- onClick: (t) => j(t, e.id),
118
+ onClick: (t) => M(t, e.id),
118
119
  className: "p-0.5 hover:bg-bg-sunken rounded",
119
- "aria-label": p("healthybowl.assistant.conversations.delete", "Delete conversation"),
120
+ "aria-label": m("healthybowl.assistant.conversations.delete", "Delete conversation"),
120
121
  "data-testid": "delete-conversation",
121
- children: /* @__PURE__ */ d(l, { className: "size-3 text-status-error-text" })
122
+ children: /* @__PURE__ */ f(u, { className: "size-3 text-status-error-text" })
122
123
  })]
123
124
  })]
124
125
  }),
125
- /* @__PURE__ */ f("div", {
126
+ /* @__PURE__ */ p("div", {
126
127
  className: "flex items-center gap-1.5 mt-0.5",
127
128
  children: [
128
- /* @__PURE__ */ d("span", {
129
+ /* @__PURE__ */ f("span", {
129
130
  className: "text-[10px] text-text-muted px-1 py-0.5 bg-bg-sunken rounded",
130
- children: a?.label ?? e.mode
131
+ children: o?.label ?? e.mode
131
132
  }),
132
- /* @__PURE__ */ f("span", {
133
+ /* @__PURE__ */ p("span", {
133
134
  className: "text-[10px] text-text-muted",
134
- children: [e.messages.length, " msgs"]
135
+ children: [s.length, " msgs"]
135
136
  }),
136
- c && c.status !== "idle" && /* @__PURE__ */ d("span", {
137
+ v && v.status !== "idle" && /* @__PURE__ */ f("span", {
137
138
  className: "text-[10px] text-action-primary-bg px-1 py-0.5 bg-bg-sunken rounded",
138
- children: c.status
139
+ children: v.status
139
140
  })
140
141
  ]
141
142
  }),
142
- o && /* @__PURE__ */ d("p", {
143
+ l && /* @__PURE__ */ f("p", {
144
+ className: "text-[10px] text-text-muted truncate mt-0.5",
145
+ children: l.content.slice(0, 60)
146
+ }),
147
+ h && /* @__PURE__ */ f("p", {
143
148
  className: "text-[10px] text-text-muted truncate mt-0.5",
144
- children: o.content.slice(0, 60)
149
+ children: m("healthybowl.assistant.conversationList.voiceOnly", "Spoken conversation")
145
150
  })
146
151
  ] })
147
152
  }, e.id);
@@ -151,6 +156,6 @@ var p = () => {
151
156
  });
152
157
  };
153
158
  //#endregion
154
- export { p as AssistantConversationList };
159
+ export { m as AssistantConversationList };
155
160
 
156
161
  //# sourceMappingURL=AssistantConversationList.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AssistantConversationList.js","names":[],"sources":["../../../src/components/assistant/AssistantConversationList.tsx"],"sourcesContent":["import { useState, type FC } from 'react';\nimport { Plus, Trash2, MessageSquare, PanelLeftClose, Pencil, Check } from 'lucide-react';\nimport { useAssistantStore } from '@/store/assistantStore';\nimport { ASSISTANT_MODES } from '@/types/assistant';\nimport { useTr } from '../../shared/hooks/useTr';\n\nexport const AssistantConversationList: FC = () => {\n const tr = useTr();\n const {\n conversations,\n activeConversationId,\n processingByConversationId,\n setActiveConversation,\n setMode,\n createConversation,\n deleteConversation,\n renameConversation,\n setConversationListOpen,\n } = useAssistantStore();\n\n const [editingId, setEditingId] = useState<string | null>(null);\n const [editTitle, setEditTitle] = useState('');\n\n const handleCreate = () => {\n createConversation();\n setConversationListOpen(false);\n };\n\n const handleSelect = (id: string) => {\n const selectedConversation = conversations.find((conversation) => conversation.id === id);\n setActiveConversation(id);\n if (selectedConversation) {\n setMode(selectedConversation.mode);\n }\n setConversationListOpen(false);\n };\n\n const handleStartRename = (id: string, currentTitle: string) => {\n setEditingId(id);\n setEditTitle(currentTitle);\n };\n\n const handleConfirmRename = () => {\n if (editingId && editTitle.trim()) {\n renameConversation(editingId, editTitle.trim());\n }\n setEditingId(null);\n };\n\n const handleDelete = (e: React.MouseEvent, id: string) => {\n e.stopPropagation();\n deleteConversation(id);\n };\n\n return (\n <div\n className=\"absolute inset-0 z-10 flex flex-col bg-bg-surface animate-in slide-in-from-left-2 fade-in duration-200\"\n data-testid=\"conversation-list\"\n >\n {/* Header */}\n <div className=\"flex items-center justify-between px-4 py-3 border-b border-border-default bg-bg-elevated\">\n <span className=\"text-[13px] font-semibold text-text-primary\">\n {tr('healthybowl.assistant.conversations.title', 'History')}\n </span>\n <div className=\"flex items-center gap-0.5\">\n <button\n type=\"button\"\n onClick={handleCreate}\n className=\"p-1.5 rounded-lg text-text-secondary hover:bg-bg-sunken transition-colors\"\n aria-label={tr('healthybowl.assistant.conversations.new', 'New conversation')}\n data-testid=\"new-conversation\"\n >\n <Plus className=\"size-4\" />\n </button>\n <button\n type=\"button\"\n onClick={() => setConversationListOpen(false)}\n className=\"flex items-center gap-1 px-2 py-1.5 rounded-lg text-text-secondary hover:bg-bg-sunken transition-colors\"\n aria-label={tr('healthybowl.assistant.conversations.collapse', 'Collapse history')}\n data-testid=\"collapse-conversation-list\"\n >\n <PanelLeftClose className=\"size-4\" />\n <span className=\"text-[11px] font-medium\">\n {tr('healthybowl.assistant.conversations.collapseLabel', 'Collapse')}\n </span>\n </button>\n </div>\n </div>\n\n {/* List */}\n <div className=\"flex-1 overflow-y-auto\">\n {conversations.length === 0 ? (\n <div className=\"flex flex-col items-center justify-center h-full text-center px-4\">\n <MessageSquare className=\"size-6 text-text-muted mb-2\" />\n <p className=\"text-xs text-text-muted\">\n {tr('healthybowl.assistant.conversations.empty', 'No conversations yet')}\n </p>\n <button\n type=\"button\"\n onClick={handleCreate}\n className=\"mt-2 text-xs text-action-primary-bg hover:underline\"\n >\n {tr('healthybowl.assistant.conversations.startNew', 'Start a new conversation')}\n </button>\n </div>\n ) : (\n <div className=\"py-1\">\n {conversations.map((conv) => {\n const isActive = conv.id === activeConversationId;\n const isEditing = conv.id === editingId;\n const modeConfig = ASSISTANT_MODES.find((m) => m.id === conv.mode);\n const lastMessage = conv.messages[conv.messages.length - 1];\n const processing = processingByConversationId[conv.id];\n\n return (\n <div\n role=\"button\"\n tabIndex={0}\n onKeyDown={(e) => {\n if (e.key === 'Enter' || e.key === ' ') {\n e.preventDefault();\n (() => !isEditing && handleSelect(conv.id))();\n }\n }}\n key={conv.id}\n onClick={() => !isEditing && handleSelect(conv.id)}\n className={`group px-3 py-2 cursor-pointer hover:bg-bg-elevated transition-colors ${\n isActive ? 'bg-bg-elevated border-l-2 border-action-primary-bg' : ''\n }`}\n >\n {isEditing ? (\n <div className=\"flex items-center gap-1\">\n <input\n aria-label={tr('healthybowl.assistant.conversations.renameLabel', 'Conversation title')}\n value={editTitle}\n onChange={(e) => setEditTitle(e.target.value)}\n onKeyDown={(e) => {\n if (e.key === 'Enter') handleConfirmRename();\n if (e.key === 'Escape') setEditingId(null);\n }}\n className=\"flex-1 text-xs bg-bg-sunken border border-border-default rounded px-2 py-1 text-text-primary focus:outline-none focus:border-action-primary-bg\"\n onClick={(e) => e.stopPropagation()}\n />\n <button\n type=\"button\"\n onClick={(e) => {\n e.stopPropagation();\n handleConfirmRename();\n }}\n className=\"p-1 hover:bg-bg-sunken rounded\"\n aria-label={tr('healthybowl.assistant.conversations.saveTitle', 'Save title')}\n >\n <Check className=\"size-3 text-status-success-text\" />\n </button>\n </div>\n ) : (\n <>\n <div className=\"flex items-center justify-between\">\n <span className=\"text-xs font-medium text-text-primary truncate flex-1\">{conv.title}</span>\n <div className=\"hidden group-hover:flex group-focus-within:flex items-center gap-0.5 ml-1\">\n <button\n type=\"button\"\n onClick={(e) => {\n e.stopPropagation();\n handleStartRename(conv.id, conv.title);\n }}\n className=\"p-0.5 hover:bg-bg-sunken rounded\"\n aria-label={tr('healthybowl.assistant.conversations.rename', 'Rename conversation')}\n >\n <Pencil className=\"size-3 text-text-muted\" />\n </button>\n <button\n type=\"button\"\n onClick={(e) => handleDelete(e, conv.id)}\n className=\"p-0.5 hover:bg-bg-sunken rounded\"\n aria-label={tr('healthybowl.assistant.conversations.delete', 'Delete conversation')}\n data-testid=\"delete-conversation\"\n >\n <Trash2 className=\"size-3 text-status-error-text\" />\n </button>\n </div>\n </div>\n <div className=\"flex items-center gap-1.5 mt-0.5\">\n <span className=\"text-[10px] text-text-muted px-1 py-0.5 bg-bg-sunken rounded\">\n {modeConfig?.label ?? conv.mode}\n </span>\n <span className=\"text-[10px] text-text-muted\">{conv.messages.length} msgs</span>\n {processing && processing.status !== 'idle' && (\n <span className=\"text-[10px] text-action-primary-bg px-1 py-0.5 bg-bg-sunken rounded\">\n {processing.status}\n </span>\n )}\n </div>\n {lastMessage && (\n <p className=\"text-[10px] text-text-muted truncate mt-0.5\">\n {lastMessage.content.slice(0, 60)}\n </p>\n )}\n </>\n )}\n </div>\n );\n })}\n </div>\n )}\n </div>\n </div>\n );\n};\n"],"mappings":";;;;;;;AAMA,IAAa,UAAsC;CACjD,IAAM,IAAK,EAAM,GACX,EACJ,kBACA,yBACA,+BACA,0BACA,YACA,uBACA,uBACA,uBACA,+BACE,EAAkB,GAEhB,CAAC,GAAW,KAAgB,EAAwB,IAAI,GACxD,CAAC,GAAW,KAAgB,EAAS,EAAE,GAEvC,UAAqB;EAEzB,AADA,EAAmB,GACn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;SAAK,WAAU;mBAAf,CACE,kBAAC,UAAD;UACE,MAAK;UACL,UAAU,MAAM;WAEd,AADA,EAAE,gBAAgB,GAClB,EAAkB,EAAK,IAAI,EAAK,KAAK;UACvC;UACA,WAAU;UACV,cAAY,EAAG,8CAA8C,qBAAqB;oBAElF,kBAAC,GAAD,EAAQ,WAAU,yBAA0B,CAAA;SACtC,CAAA,GACR,kBAAC,UAAD;UACE,MAAK;UACL,UAAU,MAAM,EAAa,GAAG,EAAK,EAAE;UACvC,WAAU;UACV,cAAY,EAAG,8CAA8C,qBAAqB;UAClF,eAAY;oBAEZ,kBAAC,GAAD,EAAQ,WAAU,gCAAiC,CAAA;SAC7C,CAAA,CACL;UACF;;OACL,kBAAC,OAAD;QAAK,WAAU;kBAAf;SACE,kBAAC,QAAD;UAAM,WAAU;oBACb,GAAY,SAAS,EAAK;SACvB,CAAA;SACN,kBAAC,QAAD;UAAM,WAAU;oBAAhB,CAA+C,EAAK,SAAS,QAAO,OAAW;;SAC9E,KAAc,EAAW,WAAW,UACnC,kBAAC,QAAD;UAAM,WAAU;oBACb,EAAW;SACR,CAAA;QAEL;;OACJ,KACC,kBAAC,KAAD;QAAG,WAAU;kBACV,EAAY,QAAQ,MAAM,GAAG,EAAE;OAC/B,CAAA;MAEL,EAAA,CAAA;KAED,GA5EE,EAAK,EA4EP;IAET,CAAC;GACE,CAAA;EAEJ,CAAA,CACF;;AAET"}
1
+ {"version":3,"file":"AssistantConversationList.js","names":[],"sources":["../../../src/components/assistant/AssistantConversationList.tsx"],"sourcesContent":["import { useState, type FC } from 'react';\nimport { Plus, Trash2, MessageSquare, PanelLeftClose, Pencil, Check } from 'lucide-react';\nimport { useAssistantStore } from '@/store/assistantStore';\nimport { ASSISTANT_MODES } from '@/types/assistant';\nimport { useTr } from '../../shared/hooks/useTr';\nimport { chatTurns } from '../../utils/voiceTurnVisibility';\n\nexport const AssistantConversationList: FC = () => {\n const tr = useTr();\n const {\n conversations,\n activeConversationId,\n processingByConversationId,\n setActiveConversation,\n setMode,\n createConversation,\n deleteConversation,\n renameConversation,\n setConversationListOpen,\n } = useAssistantStore();\n\n const [editingId, setEditingId] = useState<string | null>(null);\n const [editTitle, setEditTitle] = useState('');\n\n const handleCreate = () => {\n createConversation();\n setConversationListOpen(false);\n };\n\n const handleSelect = (id: string) => {\n const selectedConversation = conversations.find((conversation) => conversation.id === id);\n setActiveConversation(id);\n if (selectedConversation) {\n setMode(selectedConversation.mode);\n }\n setConversationListOpen(false);\n };\n\n const handleStartRename = (id: string, currentTitle: string) => {\n setEditingId(id);\n setEditTitle(currentTitle);\n };\n\n const handleConfirmRename = () => {\n if (editingId && editTitle.trim()) {\n renameConversation(editingId, editTitle.trim());\n }\n setEditingId(null);\n };\n\n const handleDelete = (e: React.MouseEvent, id: string) => {\n e.stopPropagation();\n deleteConversation(id);\n };\n\n return (\n <div\n className=\"absolute inset-0 z-10 flex flex-col bg-bg-surface animate-in slide-in-from-left-2 fade-in duration-200\"\n data-testid=\"conversation-list\"\n >\n {/* Header */}\n <div className=\"flex items-center justify-between px-4 py-3 border-b border-border-default bg-bg-elevated\">\n <span className=\"text-[13px] font-semibold text-text-primary\">\n {tr('healthybowl.assistant.conversations.title', 'History')}\n </span>\n <div className=\"flex items-center gap-0.5\">\n <button\n type=\"button\"\n onClick={handleCreate}\n className=\"p-1.5 rounded-lg text-text-secondary hover:bg-bg-sunken transition-colors\"\n aria-label={tr('healthybowl.assistant.conversations.new', 'New conversation')}\n data-testid=\"new-conversation\"\n >\n <Plus className=\"size-4\" />\n </button>\n <button\n type=\"button\"\n onClick={() => setConversationListOpen(false)}\n className=\"flex items-center gap-1 px-2 py-1.5 rounded-lg text-text-secondary hover:bg-bg-sunken transition-colors\"\n aria-label={tr('healthybowl.assistant.conversations.collapse', 'Collapse history')}\n data-testid=\"collapse-conversation-list\"\n >\n <PanelLeftClose className=\"size-4\" />\n <span className=\"text-[11px] font-medium\">\n {tr('healthybowl.assistant.conversations.collapseLabel', 'Collapse')}\n </span>\n </button>\n </div>\n </div>\n\n {/* List */}\n <div className=\"flex-1 overflow-y-auto\">\n {conversations.length === 0 ? (\n <div className=\"flex flex-col items-center justify-center h-full text-center px-4\">\n <MessageSquare className=\"size-6 text-text-muted mb-2\" />\n <p className=\"text-xs text-text-muted\">\n {tr('healthybowl.assistant.conversations.empty', 'No conversations yet')}\n </p>\n <button\n type=\"button\"\n onClick={handleCreate}\n className=\"mt-2 text-xs text-action-primary-bg hover:underline\"\n >\n {tr('healthybowl.assistant.conversations.startNew', 'Start a new conversation')}\n </button>\n </div>\n ) : (\n <div className=\"py-1\">\n {conversations.map((conv) => {\n const isActive = conv.id === activeConversationId;\n const isEditing = conv.id === editingId;\n const modeConfig = ASSISTANT_MODES.find((m) => m.id === conv.mode);\n // ★ Preview the turns the thread will actually SHOW. Spoken turns\n // are deliberately kept out of the typed thread, so previewing the\n // raw array promised content the conversation then withheld: a\n // voice-only row displayed a title and a snippet, and opened onto\n // an empty screen. Filtering makes the row honest, and the badge\n // below says where the missing content went.\n const typedTurns = chatTurns(conv.messages);\n const lastMessage = typedTurns[typedTurns.length - 1];\n const spokenOnly = typedTurns.length === 0 && conv.messages.length > 0;\n const processing = processingByConversationId[conv.id];\n\n return (\n <div\n role=\"button\"\n tabIndex={0}\n onKeyDown={(e) => {\n if (e.key === 'Enter' || e.key === ' ') {\n e.preventDefault();\n (() => !isEditing && handleSelect(conv.id))();\n }\n }}\n key={conv.id}\n onClick={() => !isEditing && handleSelect(conv.id)}\n className={`group px-3 py-2 cursor-pointer hover:bg-bg-elevated transition-colors ${\n isActive ? 'bg-bg-elevated border-l-2 border-action-primary-bg' : ''\n }`}\n >\n {isEditing ? (\n <div className=\"flex items-center gap-1\">\n <input\n aria-label={tr('healthybowl.assistant.conversations.renameLabel', 'Conversation title')}\n value={editTitle}\n onChange={(e) => setEditTitle(e.target.value)}\n onKeyDown={(e) => {\n if (e.key === 'Enter') handleConfirmRename();\n if (e.key === 'Escape') setEditingId(null);\n }}\n className=\"flex-1 text-xs bg-bg-sunken border border-border-default rounded px-2 py-1 text-text-primary focus:outline-none focus:border-action-primary-bg\"\n onClick={(e) => e.stopPropagation()}\n />\n <button\n type=\"button\"\n onClick={(e) => {\n e.stopPropagation();\n handleConfirmRename();\n }}\n className=\"p-1 hover:bg-bg-sunken rounded\"\n aria-label={tr('healthybowl.assistant.conversations.saveTitle', 'Save title')}\n >\n <Check className=\"size-3 text-status-success-text\" />\n </button>\n </div>\n ) : (\n <>\n <div className=\"flex items-center justify-between\">\n <span className=\"text-xs font-medium text-text-primary truncate flex-1\">{conv.title}</span>\n <div className=\"hidden group-hover:flex group-focus-within:flex items-center gap-0.5 ml-1\">\n <button\n type=\"button\"\n onClick={(e) => {\n e.stopPropagation();\n handleStartRename(conv.id, conv.title);\n }}\n className=\"p-0.5 hover:bg-bg-sunken rounded\"\n aria-label={tr('healthybowl.assistant.conversations.rename', 'Rename conversation')}\n >\n <Pencil className=\"size-3 text-text-muted\" />\n </button>\n <button\n type=\"button\"\n onClick={(e) => handleDelete(e, conv.id)}\n className=\"p-0.5 hover:bg-bg-sunken rounded\"\n aria-label={tr('healthybowl.assistant.conversations.delete', 'Delete conversation')}\n data-testid=\"delete-conversation\"\n >\n <Trash2 className=\"size-3 text-status-error-text\" />\n </button>\n </div>\n </div>\n <div className=\"flex items-center gap-1.5 mt-0.5\">\n <span className=\"text-[10px] text-text-muted px-1 py-0.5 bg-bg-sunken rounded\">\n {modeConfig?.label ?? conv.mode}\n </span>\n <span className=\"text-[10px] text-text-muted\">{typedTurns.length} msgs</span>\n {processing && processing.status !== 'idle' && (\n <span className=\"text-[10px] text-action-primary-bg px-1 py-0.5 bg-bg-sunken rounded\">\n {processing.status}\n </span>\n )}\n </div>\n {lastMessage && (\n <p className=\"text-[10px] text-text-muted truncate mt-0.5\">\n {lastMessage.content.slice(0, 60)}\n </p>\n )}\n {spokenOnly && (\n <p className=\"text-[10px] text-text-muted truncate mt-0.5\">\n {tr('healthybowl.assistant.convers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V,EAAG,oDAAoD,qBAAqB;OAC5E,CAAA;MAEL,EAAA,CAAA;KAED,GAjFE,EAAK,EAiFP;IAET,CAAC;GACE,CAAA;EAEJ,CAAA,CACF;;AAET"}
@@ -35,13 +35,13 @@ var _ = ({ session: _, turns: b = [], notice: x = null, spoken: S, onInterrupt:
35
35
  L,
36
36
  B
37
37
  ]);
38
- let H = t(_), U = i({
38
+ let H = x !== null && M === null, U = t(_), W = i({
39
39
  snapshot: _,
40
40
  capturing: E,
41
41
  interrupting: D,
42
42
  awaitingEndpoint: O
43
- }), W = (() => {
44
- switch (U) {
43
+ }), G = (() => {
44
+ switch (W) {
45
45
  case "connecting": return k("healthybowl.assistant.voiceSession.connecting", "Starting the microphone…");
46
46
  case "endpoint-grace": return k("healthybowl.assistant.voiceSession.endpointGrace", "Still listening — take your time");
47
47
  case "interrupting": return k("healthybowl.assistant.voiceSession.interrupting", "Stopped — go ahead");
@@ -50,9 +50,9 @@ var _ = ({ session: _, turns: b = [], notice: x = null, spoken: S, onInterrupt:
50
50
  case "mic-error":
51
51
  case "ended": return "";
52
52
  case "listening": return j ? k("healthybowl.assistant.voiceSession.muted", "Microphone off") : k("healthybowl.assistant.voiceSession.listening", "Listening…");
53
- default: return U;
53
+ default: return W;
54
54
  }
55
- })(), G = j && U !== "listening" && W !== "" ? `${W} · ${k("healthybowl.assistant.voiceSession.muted", "Microphone off")}` : W;
55
+ })(), K = j && W !== "listening" && G !== "" ? `${G} · ${k("healthybowl.assistant.voiceSession.muted", "Microphone off")}` : G;
56
56
  return /* @__PURE__ */ g("div", {
57
57
  ref: P,
58
58
  className: `flex flex-col items-center justify-between bg-bg-sunken ${F === "full" ? "fixed inset-x-0 bottom-0 top-14 z-[60] px-6 py-8" : F === "panel" ? "absolute inset-0 z-20 px-4 py-6" : "absolute inset-x-0 bottom-0 z-20 h-[11.25rem] border-t border-border-subtle px-3 py-3 shadow-lg"}`,
@@ -61,18 +61,24 @@ var _ = ({ session: _, turns: b = [], notice: x = null, spoken: S, onInterrupt:
61
61
  "aria-label": k("healthybowl.assistant.voiceSession.title", "Voice conversation"),
62
62
  "data-testid": "assistant-voice-session",
63
63
  children: [
64
- /* @__PURE__ */ h("button", {
64
+ /* @__PURE__ */ g("button", {
65
65
  ref: N,
66
66
  type: "button",
67
67
  onClick: T,
68
- className: `absolute ${L ? "right-6 top-6 size-14" : R ? "right-2 top-2 size-8" : "right-3 top-3 size-11"} flex items-center justify-center rounded-full border border-border-default bg-bg-elevated text-text-secondary hover:bg-bg-sunken transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-border-strong`,
69
- "aria-label": k("healthybowl.assistant.voiceSession.end", "End the voice conversation"),
68
+ className: `absolute ${L ? "right-6 top-6 h-14 gap-2 px-5 text-base" : R ? "right-2 top-2 size-8" : "right-3 top-3 h-11 gap-2 px-4 text-sm"} flex items-center justify-center rounded-full border border-border-default bg-bg-elevated text-text-secondary hover:bg-bg-sunken transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-border-strong`,
69
+ "aria-label": R ? k("healthybowl.assistant.voiceSession.end", "End the voice conversation") : void 0,
70
70
  "data-testid": "assistant-voice-end",
71
- children: /* @__PURE__ */ h(m, { className: L ? "size-6" : R ? "size-4" : "size-5" })
71
+ children: [/* @__PURE__ */ h(m, {
72
+ className: L ? "size-6" : R ? "size-4" : "size-5",
73
+ "aria-hidden": "true"
74
+ }), R ? null : /* @__PURE__ */ h("span", {
75
+ className: "max-w-[7rem] truncate whitespace-nowrap font-medium",
76
+ children: k("healthybowl.assistant.voiceSession.endShort", "End")
77
+ })]
72
78
  }),
73
79
  /* @__PURE__ */ h("div", {
74
- className: `flex flex-col items-center ${R ? "px-3" : "min-h-[1.5rem] px-14"}`,
75
- children: x && M === null ? /* @__PURE__ */ h("p", {
80
+ className: `flex flex-col items-center ${R ? "px-3" : `min-h-[1.5rem] ${H ? L ? "pt-14" : "pt-10" : ""}`}`,
81
+ children: H ? /* @__PURE__ */ h("p", {
76
82
  className: "max-w-xs text-center text-xs text-status-warning",
77
83
  "data-testid": "assistant-voice-notice",
78
84
  children: v(x, k)
@@ -82,21 +88,21 @@ var _ = ({ session: _, turns: b = [], notice: x = null, spoken: S, onInterrupt:
82
88
  let e = /* @__PURE__ */ h(n, {
83
89
  session: _,
84
90
  compact: R,
85
- onPress: r(U) ? C : w,
86
- label: r(U) ? k("healthybowl.assistant.voiceSession.interrupt", "Stop the assistant and speak") : j ? k("healthybowl.assistant.voiceSession.unmute", "Turn the microphone on") : k("healthybowl.assistant.voiceSession.mute", "Turn the microphone off")
87
- }), t = r(U) ? S : H || null, i = M === null ? null : y(M, k);
91
+ onPress: r(W) ? C : w,
92
+ label: r(W) ? k("healthybowl.assistant.voiceSession.interrupt", "Stop the assistant and speak") : j ? k("healthybowl.assistant.voiceSession.unmute", "Turn the microphone on") : k("healthybowl.assistant.voiceSession.mute", "Turn the microphone off")
93
+ }), t = r(W) ? S : U || null, i = M === null ? null : y(M, k);
88
94
  return R ? /* @__PURE__ */ h(o, {
89
- state: U,
95
+ state: W,
90
96
  caption: t,
91
- statusText: G,
97
+ statusText: K,
92
98
  errorText: i,
93
99
  control: e
94
100
  }) : /* @__PURE__ */ h(a, {
95
- state: U,
96
- userCaption: H || null,
101
+ state: W,
102
+ userCaption: U || null,
97
103
  assistantCaption: S,
98
104
  expanded: L,
99
- statusText: G,
105
+ statusText: K,
100
106
  errorText: i,
101
107
  control: e
102
108
  });
@@ -1 +1 @@
1
- {"version":3,"file":"AssistantVoiceSession.js","names":[],"sources":["../../../../src/components/assistant/voice/AssistantVoiceSession.tsx"],"sourcesContent":["import { useEffect, useRef, useState, type FC } from 'react';\nimport { Maximize2, Minimize2, ScrollText, X } from 'lucide-react';\nimport { AssistantVoiceOrb } from './AssistantVoiceOrb';\nimport { VoiceStage } from './VoiceStage';\nimport { VoiceMiniController } from './VoiceMiniController';\nimport { VoiceTranscriptDrawer } from './VoiceTranscriptDrawer';\nimport { voiceStageState, micIsInterrupt } from '../../../utils/voiceStageState';\nimport { useTr } from '../../../shared/hooks/useTr';\nimport { spokenSoFar, type VoiceSessionSnapshot } from '../../../utils/voiceSession';\nimport type { VoiceSessionError } from '../../../utils/voiceSession';\nimport type { VoiceSessionNotice } from '../../../hooks/useVoiceSession';\n\n/** How much room the voice session takes: a strip, the panel, or the screen. */\nexport type VoiceView = 'mini' | 'panel' | 'full';\n\ninterface Props {\n session: VoiceSessionSnapshot;\n /** Recent exchanges, oldest first — the running conversation. */\n turns?: ReadonlyArray<{ id: string; role: 'user' | 'assistant'; text: string }>;\n /** Cut the assistant off mid-reply. */\n onInterrupt?: () => void;\n /** A recoverable problem to surface. Null when the microphone is healthy. */\n notice?: VoiceSessionNotice | null;\n /** The assistant's last reply, captioned while it is spoken. */\n spoken: string | null;\n onToggleMute: () => void;\n onEnd: () => void;\n /** Is the recogniser actually running? Distinguishes CONNECTING from LISTENING. */\n capturing?: boolean;\n /** The user has cut the assistant off and capture has not resumed yet. */\n interrupting?: boolean;\n /** Quiet has fallen and the two-second correction window is running. */\n awaitingEndpoint?: boolean;\n}\n\n/**\n * Full-screen voice conversation (BOFF-7120).\n *\n * ★ **Voice only, by explicit product decision.** The reference (Gemini Live)\n * also offers camera and screen sharing; those are deliberately absent here.\n * Attaching images is a separate, existing capability of the assistant and\n * stays in the composer, and screen sharing could not work on the primary\n * device anyway — `getDisplayMedia` is unsupported by every iOS browser, so\n * that control would be dead on an iPhone.\n *\n * The controls are therefore the two that a voice conversation actually needs:\n * mute, and end. Anything else would be a button the user has to think about\n * while talking.\n *\n * This component is presentational: every transition is owned by\n * `voiceSessionReducer`, which is pure and tested. That split exists because\n * this file cannot be tested at all in this repo — vitest runs in `node` with\n * no DOM and no audio.\n */\nexport const AssistantVoiceSession: FC<Props> = ({\n session,\n turns = [],\n notice = null,\n spoken,\n onInterrupt,\n onToggleMute,\n onEnd,\n capturing = true,\n interrupting = false,\n awaitingEndpoint = false,\n}) => {\n const tr = useTr();\n const { phase, muted, error } = session;\n const endRef = useRef<HTMLButtonElement>(null);\n const dialogRef = useRef<HTMLDivElement>(null);\n /**\n * Docked inside the assistant panel by default; full-screen only on request.\n *\n * A voice conversation is usually a glance-and-listen thing, so taking over\n * the whole screen for it is the wrong default — the user loses the page they\n * were asking about. Expanding is opt-in and per-session: reopening starts\n * docked again, which is the behaviour that matches \"default should be the\n * same size as the assistant\".\n */\n /**\n * ★ THREE sizes, not two.\n *\n * The compact controller was added so voice stops taking over the panel — but\n * making it the only docked size removed the in-panel stage that existed\n * before, which is a genuinely useful middle: big enough to read a reply,\n * without losing the page behind it.\n *\n * mini — a strip at the bottom; the assistant panel stays visible\n * panel — fills the assistant panel (what \"docked\" used to mean)\n * full — full screen\n *\n * One button steps mini → panel → full and wraps, with the label always\n * naming where it goes next, so a single control stays predictable.\n */\n const [view, setView] = useState<VoiceView>('mini');\n const expanded = view === 'full';\n const mini = view === 'mini';\n const nextView: VoiceView = view === 'mini' ? 'panel' : view === 'panel' ? 'full' : 'mini';\n /** History is secondary: the stage shows now, this shows the session. */\n const [transcriptOpen, setTranscriptOpen] = useState(false);\n\n // A full-screen `aria-modal` overlay that cannot be dismissed from the\n // keyboard is a trap. Escape ends the session, and focus starts on End so a\n // keyboard or screen-reader user lands somewhere useful rather than behind\n // the overlay.\n // Focus lands on End ONCE, on open. Keeping this in the keydown effect below\n // meant every expand/collapse re-ran it and silently stole focus from the\n // button just pressed — a Space or Enter a beat later would then end the\n // session instead of toggling the size again.\n useEffect(() => {\n endRef.current?.focus();\n }, []);\n\n useEffect(() => {\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n // ★ Escape closes the drawer first. Ending the whole conversation\n // because someone dismissed a panel would be a surprising amount of\n // destruction for one keypress.\n if (transcriptOpen) {\n setTranscriptOpen(false);\n return;\n }\n onEnd();\n return;\n }\n // Trapping focus is only correct when the overlay actually covers\n // everything. Docked, it sits inside the panel and the rest of the page\n // is legitimately reachable, so trapping there would be the bug rather\n // than the fix.\n if (event.key !== 'Tab' || !expanded) return;\n // `aria-modal` only TELLS assistive technology this is modal; it does not\n // make it so. Without this, Tab walks straight out of the overlay into the\n // page behind it, which is still fully interactive underneath — a\n // keyboard user ends up operating a screen they cannot see.\n // ★ Scope the trap to what is actually on screen. With the transcript\n // drawer open, a flat `button` query also collects the controls it covers,\n // so Tab walked into buttons the user could not see — the same class of\n // bug the trap exists to prevent.\n const scope = transcriptOpen\n ? dialogRef.current?.querySelector<HTMLElement>('[data-testid=\"assistant-voice-transcript\"]')\n : dialogRef.current;\n const focusable = scope?.querySelectorAll<HTMLElement>('button:not([disabled])');\n if (!focusable || focusable.length === 0) return;\n const first = focusable[0];\n const last = focusable[focusable.length - 1];\n if (!first || !last) return;\n if (event.shiftKey && document.activeElement === first) {\n event.preventDefault();\n last.focus();\n } else if (!event.shiftKey && document.activeElement === last) {\n event.preventDefault();\n first.focus();\n }\n };\n window.addEventListener('keydown', onKeyDown);\n return () => window.removeEventListener('keydown', onKeyDown);\n }, [onEnd, expanded, transcriptOpen]);\n\n // While speaking, the caption shows the REPLY; otherwise what we have heard.\n // Showing the stale transcript under the assistant's own voice reads as a\n // mis-transcription of the assistant, which is worse than showing nothing.\n const heard = spokenSoFar(session);\n\n // ★ ONE state, derived. The reducer's phase cannot tell \"listening\" from\n // \"the microphone has not started yet\", and the old overlay rendered every\n // signal at once — status, warning, transcript, caption and orb together.\n // ★ Both signals were accepted by `voiceStageState` and passed by nobody, so\n // `endpoint-grace` and `interrupting` were unreachable branches.\n const stage = voiceStageState({ snapshot: session, capturing, interrupting, awaitingEndpoint });\n\n /**\n * The label for the STAGE, not for the phase.\n *\n * ★ This used to read `phase`, which is why three derived stages were\n * invisible even once they were reachable: `connecting`, `endpoint-grace` and\n * `interrupting` are all `phase === 'listening'` underneath, so every one of\n * them said \"Listening…\". The stage exists precisely because the phase cannot\n * make these distinctions — deriving the caption from the phase threw that\n * away again, and told the user we were listening before the recogniser had\n * started, the exact lie `voiceStageState` was written to stop.\n */\n const stageText = (() => {\n switch (stage) {\n case 'connecting':\n return tr('healthybowl.assistant.voiceSession.connecting', 'Starting the microphone…');\n case 'endpoint-grace':\n // Reads as an invitation, not a countdown: the window exists so the\n // user can still correct themselves, and hurrying them defeats it.\n return tr('healthybowl.assistant.voiceSession.endpointGrace', 'Still listening — take your time');\n case 'interrupting':\n return tr('healthybowl.assistant.voiceSession.interrupting', 'Stopped — go ahead');\n case 'thinking':\n return tr('healthybowl.assistant.voiceSession.thinking', 'Thinking…');\n case 'speaking':\n return tr('healthybowl.assistant.voiceSession.speaking', 'Speaking — tap to stop');\n case 'mic-error':\n case 'ended':\n // Owned by the error branch of the stage, which gets it to itself.\n return '';\n case 'listening':\n return muted\n ? tr('healthybowl.assistant.voiceSession.muted', 'Microphone off')\n : tr('healthybowl.assistant.voiceSession.listening', 'Listening…');\n default: {\n // ★ Exhaustive on purpose, matching `errorMessage` and `noticeMessage`\n // below. A stage with no copy is the exact bug this change fixes, so a\n // new one without a label must fail the BUILD rather than silently\n // inherit \"Listening…\" the way three of them already did.\n const unhandled: never = stage;\n return unhandled;\n }\n }\n })();\n\n // Muted is reported ALONGSIDE the stage, not instead of it: the assistant may\n // still be speaking with the microphone off, and saying only \"Microphone off\"\n // would misreport that.\n //\n // ★ Gated on the STAGE, not the phase. `connecting`, `endpoint-grace` and\n // `interrupting` are all `phase === 'listening'` underneath, so a phase test\n // dropped the suffix on exactly the three stages this change introduced —\n // leaving \"Stopped — go ahead\" inviting someone to speak into a muted\n // microphone. The `!== ''` guard keeps ended/mic-error from rendering a bare\n // \" · Microphone off\".\n //\n // ★ No `error !== null` arm: `stageText` is already '' for `mic-error`, and\n // the message itself belongs to the stage's alert element. Testing the error\n // here printed the whole sentence TWICE on the one screen this change exists\n // to make visible — truncated in the status line, repeated below it, and\n // announced twice by a screen reader.\n const status =\n muted && stage !== 'listening' && stageText !== ''\n ? `${stageText} · ${tr('healthybowl.assistant.voiceSession.muted', 'Microphone off')}`\n : stageText;\n\n return (\n <div\n ref={dialogRef}\n className={`flex flex-col items-center justify-between bg-bg-sunken ${\n view === 'full'\n ? // ★ Below the app header, not behind it. The header is `z-[100]` and\n // this overlay was `z-[60]` at `inset-0`, so the top 56px sat behind\n // it — and the End button did not merely LOOK hidden, it was\n // unclickable (`elementFromPoint` returned the header). Starting at\n // `top-14` means nothing is ever behind the header, and the header\n // stays usable for orientation.\n 'fixed inset-x-0 bottom-0 top-14 z-[60] px-6 py-8'\n : view === 'panel'\n ? // The in-panel stage: covers the assistant panel, keeps the page.\n 'absolute inset-0 z-20 px-4 py-6'\n : // A strip at the bottom, ~180px, so the panel behind stays visible.\n 'absolute inset-x-0 bottom-0 z-20 h-[11.25rem] border-t border-border-subtle px-3 py-3 shadow-lg'\n }`}\n role=\"dialog\"\n // Only modal when it really is: docked, the page behind stays usable.\n // `undefined` rather than `false` — the ARIA default is already false, and\n // some older assistive technology treats an explicit \"false\" on a dialog\n // as still modal.\n aria-modal={expanded || undefined}\n aria-label={tr('healthybowl.assistant.voiceSession.title', 'Voice conversation')}\n data-testid=\"assistant-voice-session\"\n >\n {/* End sits top-right and expand bottom-left, out of the centre column.\n Absolute rather than part of the flow so the pill stays optically\n centred at both sizes — the overlay is already a positioning context\n (`fixed` when expanded, `absolute` when docked). */}\n <button\n ref={endRef}\n type=\"button\"\n onClick={onEnd}\n className={`absolute ${expanded ? 'right-6 top-6 size-14' : mini ? 'right-2 top-2 size-8' : 'right-3 top-3 size-11'} flex items-center justify-center rounded-full border border-border-default bg-bg-elevated text-text-secondary hover:bg-bg-sunken transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-border-strong`}\n aria-label={tr('healthybowl.assistant.voiceSession.end', 'End the voice conversation')}\n data-testid=\"assistant-voice-end\"\n >\n <X className={expanded ? 'size-6' : mini ? 'size-4' : 'size-5'} />\n </button>\n\n {/* ★ The notice is CHROME, not conversation. It used to sit above the\n transcript in the same column as the reply, which is why a microphone\n warning read as part of what the assistant said. The status line moved\n into the stage, where it labels the state it belongs to. */}\n <div className={`flex flex-col items-center ${mini ? 'px-3' : 'min-h-[1.5rem] px-14'}`}>\n {notice && error === null ? (\n <p className=\"max-w-xs text-center text-xs text-status-warning\" data-testid=\"assistant-voice-notice\">\n {noticeMessage(notice, tr)}\n </p>\n ) : null}\n </div>\n\n {/* ★ Two genuinely different surfaces, not one scaled. Expanded is a\n reading stage; docked is a controller. */}\n {(() => {\n const orb = (\n <AssistantVoiceOrb\n session={session}\n compact={mini}\n onPress={micIsInterrupt(stage) ? onInterrupt : onToggleMute}\n label={\n micIsInterrupt(stage)\n ? tr('healthybowl.assistant.voiceSession.interrupt', 'Stop the assistant and speak')\n : muted\n ? tr('healthybowl.assistant.voiceSession.unmute', 'Turn the microphone on')\n : tr('healthybowl.assistant.voiceSession.mute', 'Turn the microphone off')\n }\n />\n );\n const caption = micIsInterrupt(stage) ? spoken : heard || null;\n const errorText = error !== null ? errorMessage(error, tr) : null;\n return !mini ? (\n <VoiceStage\n state={stage}\n userCaption={heard || null}\n assistantCaption={spoken}\n // ★ `expanded` — the JSX shorthand — means `expanded={true}`, not\n // `expanded={expanded}`. This branch serves BOTH the docked panel and\n // full screen, so the panel was being styled as full screen: the\n // 34rem measure and the 24-34px caption clamp applied in a column far\n // too narrow for them, and VoiceCaption's non-expanded branch became\n // unreachable code. The variable it shadowed is right there on line 90.\n expanded={expanded}\n statusText={status}\n errorText={errorText}\n control={orb}\n />\n ) : (\n <VoiceMiniController\n state={stage}\n caption={caption}\n statusText={status}\n errorText={errorText}\n control={orb}\n />\n );\n })()}\n\n {transcriptOpen ? <VoiceTranscriptDrawer turns={turns} onClose={() => setTranscriptOpen(false)} /> : null}\n\n {/* History is SECONDARY — behind a button, never on the stage. */}\n <button\n type=\"button\"\n onClick={() => setTranscriptOpen((open) => !open)}\n className={`absolute ${expanded ? 'bottom-6 right-6 size-14' : mini ? 'right-11 top-2 size-8' : 'bottom-3 right-3 size-11'} flex items-center justify-center rounded-full bg-bg-elevated text-text-secondary transition-colors hover:bg-bg-raised hover:text-text-primary focus:outline-none focus-visible:ring-2 focus-visible:ring-border-strong`}\n aria-pressed={transcriptOpen}\n aria-label={tr('healthybowl.assistant.voiceSession.transcript', 'Voice transcript')}\n data-testid=\"assistant-voice-transcript-toggle\"\n >\n <ScrollText className={expanded ? 'size-6' : mini ? 'size-4' : 'size-5'} />\n </button>\n\n <button\n type=\"button\"\n onClick={() => setView(nextView)}\n className={`absolute ${expanded ? 'bottom-6 left-6 size-14' : mini ? 'left-2 top-2 size-8' : 'bottom-3 left-3 size-11'} flex items-center justify-center rounded-full bg-bg-elevated text-text-secondary transition-colors hover:bg-bg-raised hover:text-text-primary focus:outline-none focus-visible:ring-2 focus-visible:ring-border-strong`}\n // Not a toggle any more, so `aria-pressed` would be a lie. The label\n // names where the button GOES, which is what a stepping control needs.\n aria-label={\n nextView === 'panel'\n ? tr('healthybowl.assistant.voiceSession.expandPanel', 'Show the conversation in the panel')\n : nextView === 'full'\n ? tr('healthybowl.assistant.voiceSession.expand', 'Expand the conversation to full screen')\n : tr('healthybowl.assistant.voiceSession.collapse', 'Shrink to the compact controller')\n }\n data-testid=\"assistant-voice-expand\"\n >\n {expanded ? <Minimize2 className=\"size-5\" /> : <Maximize2 className={mini ? 'size-4' : 'size-5'} />}\n </button>\n </div>\n );\n};\n\n/**\n * Recoverable problems, shown WITHOUT ending the session.\n *\n * The bug these exist for: the overlay said \"Listening…\" while the recogniser\n * was dead, and nothing anywhere said otherwise.\n */\nfunction noticeMessage(notice: VoiceSessionNotice, tr: ReturnType<typeof useTr>): string {\n switch (notice) {\n case 'network':\n return tr(\n 'healthybowl.assistant.voiceSession.noticeNetwork',\n 'Speech recognition lost its connection. Check your network — it will retry.'\n );\n case 'not-capturing':\n return tr(\n 'healthybowl.assistant.voiceSession.noticeNotCapturing',\n 'The microphone did not start. Check that this site is allowed to use it, then try again.'\n );\n case 'recognition-failed':\n return tr(\n 'healthybowl.assistant.voiceSession.noticeRecognitionFailed',\n 'Speech recognition stopped unexpectedly. It will retry — if it keeps happening, reload the page.'\n );\n case 'nothing-heard':\n return tr(\n 'healthybowl.assistant.voiceSession.noticeNothingHeard',\n 'Nothing heard yet. Check your microphone is not muted or in use by another app.'\n );\n default: {\n const unhandled: never = notice;\n return unhandled;\n }\n }\n}\n\n/**\n * Every failure is explained rather than silently closing the session.\n *\n * A session that just vanishes is the dead-button bug in another shape — the\n * exact defect BOFF-7106 had to fix on the per-message speak control.\n */\nfunction errorMessage(error: VoiceSessionError, tr: ReturnType<typeof useTr>): string {\n switch (error) {\n case 'mic-denied':\n return tr(\n 'healthybowl.assistant.voiceSession.micDenied',\n 'Microphone access is blocked. Allow it in your browser settings to talk.'\n );\n case 'no-speech-support':\n return tr(\n 'healthybowl.assistant.voiceSession.noSpeechSupport',\n 'This browser cannot listen. Try a different browser, or type instead.'\n );\n case 'no-voice-support':\n return tr(\n 'healthybowl.assistant.voiceSession.noVoiceSupport',\n 'This device has no voice that can speak this language.'\n );\n default: {\n // Exhaustive: adding a variant without copy becomes a build error rather\n // than a silently empty status line.\n const unhandled: never = error;\n return unhandled;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AAsDA,IAAa,KAAoC,EAC/C,YACA,WAAQ,CAAC,GACT,YAAS,MACT,WACA,gBACA,iBACA,UACA,eAAY,IACZ,kBAAe,IACf,sBAAmB,SACf;CACJ,IAAM,IAAK,EAAM,GACX,EAAE,UAAO,UAAO,aAAU,GAC1B,IAAS,EAA0B,IAAI,GACvC,IAAY,EAAuB,IAAI,GAyBvC,CAAC,GAAM,KAAW,EAAoB,MAAM,GAC5C,IAAW,MAAS,QACpB,IAAO,MAAS,QAChB,IAAsB,MAAS,SAAS,UAAU,MAAS,UAAU,SAAS,QAE9E,CAAC,GAAgB,KAAqB,EAAS,EAAK;CAc1D,AAJA,QAAgB;EACd,EAAO,SAAS,MAAM;CACxB,GAAG,CAAC,CAAC,GAEL,QAAgB;EACd,IAAM,KAAa,MAAyB;GAC1C,IAAI,EAAM,QAAQ,UAAU;IAI1B,IA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2BAA2B;IAC3H,gBAAc;IACd,cAAY,EAAG,iDAAiD,kBAAkB;IAClF,eAAY;cAEZ,kBAAC,GAAD,EAAY,WAAW,IAAW,WAAW,IAAO,WAAW,SAAW,CAAA;GACpE,CAAA;GAER,kBAAC,UAAD;IACE,MAAK;IACL,eAAe,EAAQ,CAAQ;IAC/B,WAAW,YAAY,IAAW,4BAA4B,IAAO,wBAAwB,0BAA0B;IAGvH,cACE,MAAa,UACT,EAAG,kDAAkD,oCAAoC,IACzF,MAAa,SACX,EAAG,6CAA6C,wCAAwC,IACxF,EAAG,+CAA+C,kCAAkC;IAE5F,eAAY;cAEX,IAAW,kBAAC,GAAD,EAAW,WAAU,SAAU,CAAA,IAAI,kBAAC,GAAD,EAAW,WAAW,IAAO,WAAW,SAAW,CAAA;GAC5F,CAAA;EACL;;AAET;AAQA,SAAS,EAAc,GAA4B,GAAsC;CACvF,QAAQ,GAAR;EACE,KAAK,WACH,OAAO,EACL,oDACA,6EACF;EACF,KAAK,iBACH,OAAO,EACL,yDACA,0FACF;EACF,KAAK,sBACH,OAAO,EACL,8DACA,kGACF;EACF,KAAK,iBACH,OAAO,EACL,yDACA,iFACF;EACF,SAEE,OAAO;CAEX;AACF;AAQA,SAAS,EAAa,GAA0B,GAAsC;CACpF,QAAQ,GAAR;EACE,KAAK,cACH,OAAO,EACL,gDACA,0EACF;EACF,KAAK,qBACH,OAAO,EACL,sDACA,uEACF;EACF,KAAK,oBACH,OAAO,EACL,qDACA,wDACF;EACF,SAIE,OAAO;CAEX;AACF"}
1
+ {"version":3,"file":"AssistantVoiceSession.js","names":[],"sources":["../../../../src/components/assistant/voice/AssistantVoiceSession.tsx"],"sourcesContent":["import { useEffect, useRef, useState, type FC } from 'react';\nimport { Maximize2, Minimize2, ScrollText, X } from 'lucide-react';\nimport { AssistantVoiceOrb } from './AssistantVoiceOrb';\nimport { VoiceStage } from './VoiceStage';\nimport { VoiceMiniController } from './VoiceMiniController';\nimport { VoiceTranscriptDrawer } from './VoiceTranscriptDrawer';\nimport { voiceStageState, micIsInterrupt } from '../../../utils/voiceStageState';\nimport { useTr } from '../../../shared/hooks/useTr';\nimport { spokenSoFar, type VoiceSessionSnapshot } from '../../../utils/voiceSession';\nimport type { VoiceSessionError } from '../../../utils/voiceSession';\nimport type { VoiceSessionNotice } from '../../../hooks/useVoiceSession';\n\n/** How much room the voice session takes: a strip, the panel, or the screen. */\nexport type VoiceView = 'mini' | 'panel' | 'full';\n\ninterface Props {\n session: VoiceSessionSnapshot;\n /** Recent exchanges, oldest first — the running conversation. */\n turns?: ReadonlyArray<{ id: string; role: 'user' | 'assistant'; text: string }>;\n /** Cut the assistant off mid-reply. */\n onInterrupt?: () => void;\n /** A recoverable problem to surface. Null when the microphone is healthy. */\n notice?: VoiceSessionNotice | null;\n /** The assistant's last reply, captioned while it is spoken. */\n spoken: string | null;\n onToggleMute: () => void;\n onEnd: () => void;\n /** Is the recogniser actually running? Distinguishes CONNECTING from LISTENING. */\n capturing?: boolean;\n /** The user has cut the assistant off and capture has not resumed yet. */\n interrupting?: boolean;\n /** Quiet has fallen and the two-second correction window is running. */\n awaitingEndpoint?: boolean;\n}\n\n/**\n * Full-screen voice conversation (BOFF-7120).\n *\n * ★ **Voice only, by explicit product decision.** The reference (Gemini Live)\n * also offers camera and screen sharing; those are deliberately absent here.\n * Attaching images is a separate, existing capability of the assistant and\n * stays in the composer, and screen sharing could not work on the primary\n * device anyway — `getDisplayMedia` is unsupported by every iOS browser, so\n * that control would be dead on an iPhone.\n *\n * The controls are therefore the two that a voice conversation actually needs:\n * mute, and end. Anything else would be a button the user has to think about\n * while talking.\n *\n * This component is presentational: every transition is owned by\n * `voiceSessionReducer`, which is pure and tested. That split exists because\n * this file cannot be tested at all in this repo — vitest runs in `node` with\n * no DOM and no audio.\n */\nexport const AssistantVoiceSession: FC<Props> = ({\n session,\n turns = [],\n notice = null,\n spoken,\n onInterrupt,\n onToggleMute,\n onEnd,\n capturing = true,\n interrupting = false,\n awaitingEndpoint = false,\n}) => {\n const tr = useTr();\n const { phase, muted, error } = session;\n const endRef = useRef<HTMLButtonElement>(null);\n const dialogRef = useRef<HTMLDivElement>(null);\n /**\n * Docked inside the assistant panel by default; full-screen only on request.\n *\n * A voice conversation is usually a glance-and-listen thing, so taking over\n * the whole screen for it is the wrong default — the user loses the page they\n * were asking about. Expanding is opt-in and per-session: reopening starts\n * docked again, which is the behaviour that matches \"default should be the\n * same size as the assistant\".\n */\n /**\n * ★ THREE sizes, not two.\n *\n * The compact controller was added so voice stops taking over the panel — but\n * making it the only docked size removed the in-panel stage that existed\n * before, which is a genuinely useful middle: big enough to read a reply,\n * without losing the page behind it.\n *\n * mini — a strip at the bottom; the assistant panel stays visible\n * panel — fills the assistant panel (what \"docked\" used to mean)\n * full — full screen\n *\n * One button steps mini → panel → full and wraps, with the label always\n * naming where it goes next, so a single control stays predictable.\n */\n const [view, setView] = useState<VoiceView>('mini');\n const expanded = view === 'full';\n const mini = view === 'mini';\n const nextView: VoiceView = view === 'mini' ? 'panel' : view === 'panel' ? 'full' : 'mini';\n /** History is secondary: the stage shows now, this shows the session. */\n const [transcriptOpen, setTranscriptOpen] = useState(false);\n\n // A full-screen `aria-modal` overlay that cannot be dismissed from the\n // keyboard is a trap. Escape ends the session, and focus starts on End so a\n // keyboard or screen-reader user lands somewhere useful rather than behind\n // the overlay.\n // Focus lands on End ONCE, on open. Keeping this in the keydown effect below\n // meant every expand/collapse re-ran it and silently stole focus from the\n // button just pressed — a Space or Enter a beat later would then end the\n // session instead of toggling the size again.\n useEffect(() => {\n endRef.current?.focus();\n }, []);\n\n useEffect(() => {\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n // ★ Escape closes the drawer first. Ending the whole conversation\n // because someone dismissed a panel would be a surprising amount of\n // destruction for one keypress.\n if (transcriptOpen) {\n setTranscriptOpen(false);\n return;\n }\n onEnd();\n return;\n }\n // Trapping focus is only correct when the overlay actually covers\n // everything. Docked, it sits inside the panel and the rest of the page\n // is legitimately reachable, so trapping there would be the bug rather\n // than the fix.\n if (event.key !== 'Tab' || !expanded) return;\n // `aria-modal` only TELLS assistive technology this is modal; it does not\n // make it so. Without this, Tab walks straight out of the overlay into the\n // page behind it, which is still fully interactive underneath — a\n // keyboard user ends up operating a screen they cannot see.\n // ★ Scope the trap to what is actually on screen. With the transcript\n // drawer open, a flat `button` query also collects the controls it covers,\n // so Tab walked into buttons the user could not see — the same class of\n // bug the trap exists to prevent.\n const scope = transcriptOpen\n ? dialogRef.current?.querySelector<HTMLElement>('[data-testid=\"assistant-voice-transcript\"]')\n : dialogRef.current;\n const focusable = scope?.querySelectorAll<HTMLElement>('button:not([disabled])');\n if (!focusable || focusable.length === 0) return;\n const first = focusable[0];\n const last = focusable[focusable.length - 1];\n if (!first || !last) return;\n if (event.shiftKey && document.activeElement === first) {\n event.preventDefault();\n last.focus();\n } else if (!event.shiftKey && document.activeElement === last) {\n event.preventDefault();\n first.focus();\n }\n };\n window.addEventListener('keydown', onKeyDown);\n return () => window.removeEventListener('keydown', onKeyDown);\n }, [onEnd, expanded, transcriptOpen]);\n\n // While speaking, the caption shows the REPLY; otherwise what we have heard.\n // Showing the stale transcript under the assistant's own voice reads as a\n // mis-transcription of the assistant, which is worse than showing nothing.\n // A notice competes with the error for the same slot; the error owns the\n // stage, so they are never both shown.\n const showNotice = notice !== null && error === null;\n\n const heard = spokenSoFar(session);\n\n // ★ ONE state, derived. The reducer's phase cannot tell \"listening\" from\n // \"the microphone has not started yet\", and the old overlay rendered every\n // signal at once — status, warning, transcript, caption and orb together.\n // ★ Both signals were accepted by `voiceStageState` and passed by nobody, so\n // `endpoint-grace` and `interrupting` were unreachable branches.\n const stage = voiceStageState({ snapshot: session, capturing, interrupting, awaitingEndpoint });\n\n /**\n * The label for the STAGE, not for the phase.\n *\n * ★ This used to read `phase`, which is why three derived stages were\n * invisible even once they were reachable: `connecting`, `endpoint-grace` and\n * `interrupting` are all `phase === 'listening'` underneath, so every one of\n * them said \"Listening…\". The stage exists precisely because the phase cannot\n * make these distinctions — deriving the caption from the phase threw that\n * away again, and told the user we were listening before the recogniser had\n * started, the exact lie `voiceStageState` was written to stop.\n */\n const stageText = (() => {\n switch (stage) {\n case 'connecting':\n return tr('healthybowl.assistant.voiceSession.connecting', 'Starting the microphone…');\n case 'endpoint-grace':\n // Reads as an invitation, not a countdown: the window exists so the\n // user can still correct themselves, and hurrying them defeats it.\n return tr('healthybowl.assistant.voiceSession.endpointGrace', 'Still listening — take your time');\n case 'interrupting':\n return tr('healthybowl.assistant.voiceSession.interrupting', 'Stopped — go ahead');\n case 'thinking':\n return tr('healthybowl.assistant.voiceSession.thinking', 'Thinking…');\n case 'speaking':\n return tr('healthybowl.assistant.voiceSession.speaking', 'Speaking — tap to stop');\n case 'mic-error':\n case 'ended':\n // Owned by the error branch of the stage, which gets it to itself.\n return '';\n case 'listening':\n return muted\n ? tr('healthybowl.assistant.voiceSession.muted', 'Microphone off')\n : tr('healthybowl.assistant.voiceSession.listening', 'Listening…');\n default: {\n // ★ Exhaustive on purpose, matching `errorMessage` and `noticeMessage`\n // below. A stage with no copy is the exact bug this change fixes, so a\n // new one without a label must fail the BUILD rather than silently\n // inherit \"Listening…\" the way three of them already did.\n const unhandled: never = stage;\n return unhandled;\n }\n }\n })();\n\n // Muted is reported ALONGSIDE the stage, not instead of it: the assistant may\n // still be speaking with the microphone off, and saying only \"Microphone off\"\n // would misreport that.\n //\n // ★ Gated on the STAGE, not the phase. `connecting`, `endpoint-grace` and\n // `interrupting` are all `phase === 'listening'` underneath, so a phase test\n // dropped the suffix on exactly the three stages this change introduced —\n // leaving \"Stopped — go ahead\" inviting someone to speak into a muted\n // microphone. The `!== ''` guard keeps ended/mic-error from rendering a bare\n // \" · Microphone off\".\n //\n // ★ No `error !== null` arm: `stageText` is already '' for `mic-error`, and\n // the message itself belongs to the stage's alert element. Testing the error\n // here printed the whole sentence TWICE on the one screen this change exists\n // to make visible — truncated in the status line, repeated below it, and\n // announced twice by a screen reader.\n const status =\n muted && stage !== 'listening' && stageText !== ''\n ? `${stageText} · ${tr('healthybowl.assistant.voiceSession.muted', 'Microphone off')}`\n : stageText;\n\n return (\n <div\n ref={dialogRef}\n className={`flex flex-col items-center justify-between bg-bg-sunken ${\n view === 'full'\n ? // ★ Below the app header, not behind it. The header is `z-[100]` and\n // this overlay was `z-[60]` at `inset-0`, so the top 56px sat behind\n // it — and the End button did not merely LOOK hidden, it was\n // unclickable (`elementFromPoint` returned the header). Starting at\n // `top-14` means nothing is ever behind the header, and the header\n // stays usable for orientation.\n 'fixed inset-x-0 bottom-0 top-14 z-[60] px-6 py-8'\n : view === 'panel'\n ? // The in-panel stage: covers the assistant panel, keeps the page.\n 'absolute inset-0 z-20 px-4 py-6'\n : // A strip at the bottom, ~180px, so the panel behind stays visible.\n 'absolute inset-x-0 bottom-0 z-20 h-[11.25rem] border-t border-border-subtle px-3 py-3 shadow-lg'\n }`}\n role=\"dialog\"\n // Only modal when it really is: docked, the page behind stays usable.\n // `undefined` rather than `false` — the ARIA default is already false, and\n // some older assistive technology treats an explicit \"false\" on a dialog\n // as still modal.\n aria-modal={expanded || undefined}\n aria-label={tr('healthybowl.assistant.voiceSession.title', 'Voice conversation')}\n data-testid=\"assistant-voice-session\"\n >\n {/* End sits top-right and expand bottom-left, out of the centre column.\n Absolute rather than part of the flow so the pill stays optically\n centred at both sizes — the overlay is already a positioning context\n (`fixed` when expanded, `absolute` when docked). */}\n <button\n ref={endRef}\n type=\"button\"\n onClick={onEnd}\n // ★ Height + horizontal padding, never `size-*`. A fixed square cannot\n // grow to fit a word, so a label dropped into one spills outside its own\n // rounded border. The mini strip keeps the square: its transcript toggle\n // sits 4px away at `right-11`, and a wider button there would grow\n // leftward underneath it — which is precisely the defect the previous\n // commit on this file fixed (\"the close button was unclickable\").\n className={`absolute ${\n expanded\n ? 'right-6 top-6 h-14 gap-2 px-5 text-base'\n : mini\n ? 'right-2 top-2 size-8'\n : 'right-3 top-3 h-11 gap-2 px-4 text-sm'\n } flex items-center justify-center rounded-full border border-border-default bg-bg-elevated text-text-secondary hover:bg-bg-sunken transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-border-strong`}\n // ★ Only when the label is INVISIBLE. With visible text the accessible\n // name comes from that text, which keeps WCAG 2.5.3 (Label in Name)\n // true by construction in every locale — including before `endShort` is\n // seeded. An aria-label here would instead pin a translated sentence\n // against an untranslated visible word, and speech-input users say the\n // word they can see.\n aria-label={mini ? tr('healthybowl.assistant.voiceSession.end', 'End the voice conversation') : undefined}\n data-testid=\"assistant-voice-end\"\n >\n <X className={expanded ? 'size-6' : mini ? 'size-4' : 'size-5'} aria-hidden=\"true\" />\n {/* The glyph alone said \"close\" only to people who already knew.\n ★ Bounded: the width is a TRANSLATED string while the layout around\n it is fixed pixels — \"Beenden\" and \"Terminer\" are ~2.4x \"End\". The\n cap turns a future overflow into an ellipsis rather than a control\n that creeps over its neighbour. */}\n {!mini ? (\n <span className=\"max-w-[7rem] truncate whitespace-nowrap font-medium\">\n {tr('healthybowl.assistant.voiceSession.endShort', 'End')}\n </span>\n ) : null}\n </button>\n\n {/* ★ The notice is CHROME, not conversation. It used to sit above the\n transcript in the same column as the reply, which is why a microphone\n warning read as part of what the assistant said. The status line moved\n into the stage, where it labels the state it belongs to. */}\n {/* ★ Cleared VERTICALLY, not horizontally. This div is a flex item of a\n `flex flex-col items-center` column, so it is SHRINK-TO-FIT: side\n padding does not reserve space beside the End button, it eats the\n text's own measure — symmetrically, for a control on one side only.\n Widening `px-14` to match a labelled button collapsed the microphone\n warning to a 78px, nine-line column on a phone and in the docked\n panel, because 78px is the min-content width of the longest word in it.\n\n Dropping below the button instead makes the clearance independent of\n both the container width and the label's length — which matters\n because that label is TRANSLATED (\"Beenden\", \"Terminer\") while these\n offsets are fixed pixels. End occupies y=24..80 expanded (top-6 +\n h-14) and y=12..56 docked (top-3 + h-11); the column's own padding\n already starts content at 32 / 24, so these add the rest plus 8px.\n\n ★ NOT true of `mini`, where End, transcript and expand are ALL in the\n top band and this stays `px-3`. A notice there can still be painted\n over by those opaque buttons. Pre-existing and left alone: the strip is\n 180px tall and buying 32px of top padding would squeeze the stage. */}\n <div\n className={`flex flex-col items-center ${\n mini\n ? 'px-3'\n : // ★ The reserve is applied ONLY when there is something to clear.\n // `padding` is not subject to `min-h`, so an unconditional `pt-14`\n // would stand a permanent 56px column above an empty div and take\n // that height out of the `flex-1` stage on every session — paying\n // the cost of a warning that is not there.\n `min-h-[1.5rem] ${showNotice ? (expanded ? 'pt-14' : 'pt-10') : ''}`\n }`}\n >\n {showNotice ? (\n <p className=\"max-w-xs text-center text-xs text-status-warning\" data-testid=\"assistant-voice-notice\">\n {noticeMessage(notice, tr)}\n </p>\n ) : null}\n </div>\n\n {/* ★ Two genuinely different surfaces, not one scaled. Expanded is a\n reading stage; docked is a controller. */}\n {(() => {\n const orb = (\n <AssistantVoiceOrb\n session={session}\n compact={mini}\n onPress={micIsInterrupt(stage) ? onInterrupt : onToggleMute}\n label={\n micIsInterrupt(stage)\n ? tr('healthybowl.assistant.voiceSession.interrupt', 'Stop the assistant and speak')\n : muted\n ? tr('healthybowl.assistant.voiceSession.unmute', 'Turn the microphone on')\n : tr('healthybowl.assistant.voiceSession.mute', 'Turn the microphone off')\n }\n />\n );\n const caption = micIsInterrupt(stage) ? spoken : heard || null;\n const errorText = error !== null ? errorMessage(error, tr) : null;\n return !mini ? (\n <VoiceStage\n state={stage}\n userCaption={heard || null}\n assistantCaption={spoken}\n // ★ `expanded` — the JSX shorthand — means `expanded={true}`, not\n // `expanded={expanded}`. This branch serves BOTH the docked panel and\n // full screen, so the panel was being styled as full screen: the\n // full-screen caption measure and clamp applied in a column far\n // too narrow for them, and VoiceCaption's non-expanded branch became\n // unreachable code. The variable it shadowed is right there on line 90.\n expanded={expanded}\n statusText={status}\n errorText={errorText}\n control={orb}\n />\n ) : (\n <VoiceMiniController\n state={stage}\n caption={caption}\n statusText={status}\n errorText={errorText}\n control={orb}\n />\n );\n })()}\n\n {transcriptOpen ? <VoiceTranscriptDrawer turns={turns} onClose={() => setTranscriptOpen(false)} /> : null}\n\n {/* History is SECONDARY — behind a button, never on the stage. */}\n <button\n type=\"button\"\n onClick={() => setTranscriptOpen((open) => !open)}\n className={`absolute ${expanded ? 'bottom-6 right-6 size-14' : mini ? 'right-11 top-2 size-8' : 'bottom-3 right-3 size-11'} flex items-center justify-center rounded-full bg-bg-elevated text-text-secondary transition-colors hover:bg-bg-raised hover:text-text-primary focus:outline-none focus-visible:ring-2 focus-visible:ring-border-strong`}\n aria-pressed={transcriptOpen}\n aria-label={tr('healthybowl.assistant.voiceSession.transcript', 'Voice transcript')}\n data-testid=\"assistant-voice-transcript-toggle\"\n >\n <ScrollText className={expanded ? 'size-6' : mini ? 'size-4' : 'size-5'} />\n </button>\n\n <button\n type=\"button\"\n onClick={() => setView(nextView)}\n className={`absolute ${expanded ? 'bottom-6 left-6 size-14' : mini ? 'left-2 top-2 size-8' : 'bottom-3 left-3 size-11'} flex items-center justify-center rounded-full bg-bg-elevated text-text-secondary transition-colors hover:bg-bg-raised hover:text-text-primary focus:outline-none focus-visible:ring-2 focus-visible:ring-border-strong`}\n // Not a toggle any more, so `aria-pressed` would be a lie. The label\n // names where the button GOES, which is what a stepping control needs.\n aria-label={\n nextView === 'panel'\n ? tr('healthybowl.assistant.voiceSession.expandPanel', 'Show the conversation in the panel')\n : nextView === 'full'\n ? tr('healthybowl.assistant.voiceSession.expand', 'Expand the conversation to full screen')\n : tr('healthybowl.assistant.voiceSession.collapse', 'Shrink to the compact controller')\n }\n data-testid=\"assistant-voice-expand\"\n >\n {expanded ? <Minimize2 className=\"size-5\" /> : <Maximize2 className={mini ? 'size-4' : 'size-5'} />}\n </button>\n </div>\n );\n};\n\n/**\n * Recoverable problems, shown WITHOUT ending the session.\n *\n * The bug these exist for: the overlay said \"Listening…\" while the recogniser\n * was dead, and nothing anywhere said otherwise.\n */\nfunction noticeMessage(notice: VoiceSessionNotice, tr: ReturnType<typeof useTr>): string {\n switch (notice) {\n case 'network':\n return tr(\n 'healthybowl.assistant.voiceSession.noticeNetwork',\n 'Speech recognition lost its connection. Check your network — it will retry.'\n );\n case 'not-capturing':\n return tr(\n 'healthybowl.assistant.voiceSession.noticeNotCapturing',\n 'The microphone did not start. Check that this site is allowed to use it, then try again.'\n );\n case 'recognition-failed':\n return tr(\n 'healthybowl.assistant.voiceSession.noticeRecognitionFailed',\n 'Speech recognition stopped unexpectedly. It will retry — if it keeps happening, reload the page.'\n );\n case 'nothing-heard':\n return tr(\n 'healthybowl.assistant.voiceSession.noticeNothingHeard',\n 'Nothing heard yet. Check your microphone is not muted or in use by another app.'\n );\n default: {\n const unhandled: never = notice;\n return unhandled;\n }\n }\n}\n\n/**\n * Every failure is explained rather than silently closing the session.\n *\n * A session that just vanishes is the dead-button bug in another shape — the\n * exact defect BOFF-7106 had to fix on the per-message speak control.\n */\nfunction errorMessage(error: VoiceSessionError, tr: ReturnType<typeof useTr>): string {\n switch (error) {\n case 'mic-denied':\n return tr(\n 'healthybowl.assistant.voiceSession.micDenied',\n 'Microphone access is blocked. Allow it in your browser settings to talk.'\n );\n case 'no-speech-support':\n return tr(\n 'healthybowl.assistant.voiceSession.noSpeechSupport',\n 'This browser cannot listen. Try a different browser, or type instead.'\n );\n case 'no-voice-support':\n return tr(\n 'healthybowl.assistant.voiceSession.noVoiceSupport',\n 'This device has no voice that can speak this language.'\n );\n default: {\n // Exhaustive: adding a variant without copy becomes a build error rather\n // than a silently empty status line.\n const unhandled: never = error;\n return unhandled;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AAsDA,IAAa,KAAoC,EAC/C,YACA,WAAQ,CAAC,GACT,YAAS,MACT,WACA,gBACA,iBACA,UACA,eAAY,IACZ,kBAAe,IACf,sBAAmB,SACf;CACJ,IAAM,IAAK,EAAM,GACX,EAAE,UAAO,UAAO,aAAU,GAC1B,IAAS,EAA0B,IAAI,GACvC,IAAY,EAAuB,IAAI,GAyBvC,CAAC,GAAM,KAAW,E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AQ,GAAR;EACE,KAAK,cACH,OAAO,EACL,gDACA,0EACF;EACF,KAAK,qBACH,OAAO,EACL,sDACA,uEACF;EACF,KAAK,oBACH,OAAO,EACL,qDACA,wDACF;EACF,SAIE,OAAO;CAEX;AACF"}
@@ -6,10 +6,10 @@ var t = ({ text: t, role: n, expanded: r, testId: i }) => {
6
6
  className: "flex w-full justify-center",
7
7
  children: /* @__PURE__ */ e("p", {
8
8
  className: [
9
- "w-full whitespace-pre-wrap text-left",
10
- r ? "max-w-[34rem]" : "max-w-md",
9
+ "w-full whitespace-pre-wrap break-words text-left",
10
+ r ? "max-w-[45rem]" : "max-w-md",
11
11
  a ? "font-semibold text-text-primary" : "font-medium text-text-secondary",
12
- r ? a ? "text-[clamp(1.5rem,2.6vw,2.125rem)] leading-[1.5]" : "text-[clamp(1.125rem,1.8vw,1.375rem)] leading-[1.5]" : a ? "text-lg leading-relaxed" : "text-base leading-relaxed"
12
+ r ? a ? "text-[clamp(1.625rem,2.5vw,2.25rem)] leading-[1.5]" : "text-[clamp(1.125rem,1.8vw,1.375rem)] leading-[1.5]" : a ? "text-lg leading-relaxed" : "text-base leading-relaxed"
13
13
  ].join(" "),
14
14
  role: "status",
15
15
  "aria-live": "polite",
@@ -1 +1 @@
1
- {"version":3,"file":"VoiceCaption.js","names":[],"sources":["../../../../src/components/assistant/voice/VoiceCaption.tsx"],"sourcesContent":["import type { FC } from 'react';\n\n/**\n * One live caption — either what the user is saying or what the assistant is.\n *\n * Replaces the message-bubble list the voice overlay used to render. That list\n * was the chat transcript squeezed into a modal: bubbles, the whole scrollback,\n * and raw `##`/`**` because it printed the model's markdown as plain text.\n *\n * Three things here are deliberate and were all wrong before:\n *\n * ★ **Left-aligned, not centred.** Centring is fine for one short line and\n * unreadable for four — every line starts in a different place, so the eye has\n * to hunt for each beginning. Tamil/English mixed text makes it worse, because\n * the line lengths vary wildly. The BLOCK is centred on the stage; the text\n * inside it is not.\n *\n * ★ **Responsive type, not one fixed size.** `clamp()` so the same component is\n * legible in a 380px docked panel and from arm's length on a maximised desktop\n * window, without a second component or a transform.\n *\n * ★ **Bounded width.** ~34rem keeps the line length inside the range prose is\n * actually readable at; a caption spanning a 1440px window is one long line the\n * eye cannot track back from.\n */\n\ninterface Props {\n text: string;\n /** Who is speaking. The assistant's caption is the loud one. */\n role: 'user' | 'assistant';\n /** Full-screen rather than docked in the panel. */\n expanded: boolean;\n testId?: string;\n}\n\nexport const VoiceCaption: FC<Props> = ({ text, role, expanded, testId }) => {\n const assistant = role === 'assistant';\n return (\n <div className=\"flex w-full justify-center\">\n <p\n className={[\n // Left-aligned inside a centred block — see above.\n // ★ `toCaptionText` PRESERVES newlines; without pre-wrap they collapse\n // and a multi-paragraph answer renders as one wall of text.\n 'w-full whitespace-pre-wrap text-left',\n expanded ? 'max-w-[34rem]' : 'max-w-md',\n assistant ? 'font-semibold text-text-primary' : 'font-medium text-text-secondary',\n expanded\n ? assistant\n ? 'text-[clamp(1.5rem,2.6vw,2.125rem)] leading-[1.5]'\n : 'text-[clamp(1.125rem,1.8vw,1.375rem)] leading-[1.5]'\n : assistant\n ? 'text-lg leading-relaxed'\n : 'text-base leading-relaxed',\n ].join(' ')}\n // The stage's live region: the caption is what actually changes, so a\n // screen reader should hear it rather than only the status word.\n role=\"status\"\n aria-live=\"polite\"\n data-testid={testId}\n >\n {text}\n </p>\n </div>\n );\n};\n"],"mappings":";;AAmCA,IAAa,KAA2B,EAAE,SAAM,SAAM,aAAU,gBAAa;CAC3E,IAAM,IAAY,MAAS;CAC3B,OACE,kBAAC,OAAD;EAAK,WAAU;YACb,kBAAC,KAAD;GACE,WAAW;IAIT;IACA,IAAW,kBAAkB;IAC7B,IAAY,oCAAoC;IAChD,IACI,IACE,sDACA,wDACF,IACE,4BACA;GACR,EAAE,KAAK,GAAG;GAGV,MAAK;GACL,aAAU;GACV,eAAa;aAEZ;EACA,CAAA;CACA,CAAA;AAET"}
1
+ {"version":3,"file":"VoiceCaption.js","names":[],"sources":["../../../../src/components/assistant/voice/VoiceCaption.tsx"],"sourcesContent":["import type { FC } from 'react';\n\n/**\n * One live caption — either what the user is saying or what the assistant is.\n *\n * Replaces the message-bubble list the voice overlay used to render. That list\n * was the chat transcript squeezed into a modal: bubbles, the whole scrollback,\n * and raw `##`/`**` because it printed the model's markdown as plain text.\n *\n * Three things here are deliberate and were all wrong before:\n *\n * ★ **Left-aligned, not centred.** Centring is fine for one short line and\n * unreadable for four — every line starts in a different place, so the eye has\n * to hunt for each beginning. Tamil/English mixed text makes it worse, because\n * the line lengths vary wildly. The BLOCK is centred on the stage; the text\n * inside it is not.\n *\n * ★ **Responsive type, not one fixed size.** `clamp()` so the same component is\n * legible in a 380px docked panel and from arm's length on a maximised desktop\n * window, without a second component or a transform.\n *\n * ★ **Bounded width.** A caption spanning a 1440px window is one long line the\n * eye cannot track back from, so the measure is capped — 45rem / 720px on the\n * full-screen stage, the middle of the 680-760px the design calls for.\n *\n * ★ That measure is deliberately NOT the 60-75 characters typography usually\n * aims at: at 36px type 720px carries roughly 40. A voice caption is glanced at\n * from arm's length while someone is talking, not read as prose, and the size\n * is what makes it glanceable — so the two constraints are set independently\n * and the width follows the spec rather than the usual reading rule.\n */\n\ninterface Props {\n text: string;\n /** Who is speaking. The assistant's caption is the loud one. */\n role: 'user' | 'assistant';\n /** Full-screen rather than docked in the panel. */\n expanded: boolean;\n testId?: string;\n}\n\nexport const VoiceCaption: FC<Props> = ({ text, role, expanded, testId }) => {\n const assistant = role === 'assistant';\n return (\n <div className=\"flex w-full justify-center\">\n <p\n className={[\n // Left-aligned inside a centred block — see above.\n // ★ `toCaptionText` PRESERVES newlines; without pre-wrap they collapse\n // and a multi-paragraph answer renders as one wall of text.\n // ★ `break-words` because nothing else may break a long unbroken run\n // — a URL, or a Tamil compound — and `pre-wrap` alone will not. The\n // chat renderer already carries it; the caption did not.\n 'w-full whitespace-pre-wrap break-words text-left',\n // 45rem = 720px, mid-band. Arbitrary value on purpose: Tailwind's\n // max-w-2xl is 672px and max-w-3xl 768px, so neither preset lands\n // inside 680-760.\n expanded ? 'max-w-[45rem]' : 'max-w-md',\n assistant ? 'font-semibold text-text-primary' : 'font-medium text-text-secondary',\n expanded\n ? assistant\n ? // 26-36px. ★ The floor is coupled to VoiceStage's empty-caption\n // reserve, which is 3x this value (two lines at 1.5 leading) so\n // the control does not jump when the first words arrive — move\n // one and the other has to move with it.\n 'text-[clamp(1.625rem,2.5vw,2.25rem)] leading-[1.5]'\n : // The USER caption is deliberately quieter and is not part of\n // the 26-36px band, which specifies the assistant's line.\n 'text-[clamp(1.125rem,1.8vw,1.375rem)] leading-[1.5]'\n : assistant\n ? 'text-lg leading-relaxed'\n : 'text-base leading-relaxed',\n ].join(' ')}\n // The stage's live region: the caption is what actually changes, so a\n // screen reader should hear it rather than only the status word.\n role=\"status\"\n aria-live=\"polite\"\n data-testid={testId}\n >\n {text}\n </p>\n </div>\n );\n};\n"],"mappings":";;AAyCA,IAAa,KAA2B,EAAE,SAAM,SAAM,aAAU,gBAAa;CAC3E,IAAM,IAAY,MAAS;CAC3B,OACE,kBAAC,OAAD;EAAK,WAAU;YACb,kBAAC,KAAD;GACE,WAAW;IAOT;IAIA,IAAW,kBAAkB;IAC7B,IAAY,oCAAoC;IAChD,IACI,IAKE,uDAGA,wDACF,IACE,4BACA;GACR,EAAE,KAAK,GAAG;GAGV,MAAK;GACL,aAAU;GACV,eAAa;aAEZ;EACA,CAAA;CACA,CAAA;AAET"}
@@ -38,7 +38,7 @@ var l = ({ state: l, userCaption: u, assistantCaption: d, expanded: f, statusTex
38
38
  expanded: f
39
39
  })
40
40
  }), g ? /* @__PURE__ */ s("div", {
41
- className: f ? "mb-12 max-h-[46vh] w-full overflow-y-auto" : "mb-6 w-full",
41
+ className: f ? "mb-12 max-h-[46vh] w-full overflow-y-auto" : "mb-6 max-h-[38vh] w-full overflow-y-auto",
42
42
  children: /* @__PURE__ */ s(e, {
43
43
  text: g,
44
44
  role: n(l) ? "assistant" : "user",
@@ -46,7 +46,7 @@ var l = ({ state: l, userCaption: u, assistantCaption: d, expanded: f, statusTex
46
46
  testId: "assistant-voice-caption"
47
47
  })
48
48
  }) : /* @__PURE__ */ s("div", {
49
- className: f ? "mb-12 h-[4.5rem]" : "mb-6 h-12",
49
+ className: f ? "mb-12 h-[4.875rem]" : "mb-6 h-12",
50
50
  "aria-hidden": "true"
51
51
  })] }),
52
52
  m
@@ -1 +1 @@
1
- {"version":3,"file":"VoiceStage.js","names":[],"sources":["../../../../src/components/assistant/voice/VoiceStage.tsx"],"sourcesContent":["import type { FC, ReactNode } from 'react';\nimport { VoiceCaption } from './VoiceCaption';\nimport { VoiceWaveform } from './VoiceWaveform';\nimport {\n waveformIsActive,\n waveformIsSettled,\n showsAssistantCaption,\n showsUserCaption,\n type VoiceStageState,\n} from '../../../utils/voiceStageState';\n\n/**\n * The middle of the voice panel: exactly ONE state, rendered as itself.\n *\n * What this replaces is the whole problem the operator screenshotted. The old\n * overlay showed, simultaneously: \"Listening…\", a microphone warning, the last\n * six messages of the chat conversation as bubbles (markdown syntax and all),\n * the assistant's answer AGAIN as a caption, and the orb. Five things competing,\n * none of them readable.\n *\n * ★ A stage shows one thing because the session IS one thing at a time. The\n * state is derived in `voiceStageState`, which is pure and tested; this file is\n * presentational and cannot be tested in this repo (vitest runs in `node`, no\n * DOM), so it deliberately contains no logic worth testing.\n *\n * The microphone warning is NOT rendered here. Mixing a system message into the\n * conversation area is what made it read as part of the reply; it belongs to\n * the chrome around the stage.\n */\n\ninterface Props {\n state: VoiceStageState;\n /** What the user is saying (live) or last said. */\n userCaption: string | null;\n /** What the assistant is saying. */\n assistantCaption: string | null;\n expanded: boolean;\n /** Status words — already localised by the caller. */\n statusText: string;\n /** The microphone / interrupt control. */\n control: ReactNode;\n /** Shown in the mic-error state instead of a caption. */\n errorText?: string | null;\n}\n\nexport const VoiceStage: FC<Props> = ({\n state,\n userCaption,\n assistantCaption,\n expanded,\n statusText,\n control,\n errorText = null,\n}) => {\n const caption = showsAssistantCaption(state) ? assistantCaption : showsUserCaption(state) ? userCaption : null;\n\n return (\n <div\n className={[\n 'flex min-h-0 w-full flex-1 flex-col items-center',\n expanded ? 'px-8' : 'px-14',\n // ★ Expanded, the group is anchored just above the optical centre\n // rather than centred in the whole box. Measured at 1440x900 the\n // content was 314px of a 756px stage with 221px of dead air above AND\n // below — technically centred, visually adrift. Docked the box is\n // small enough that centring is right.\n expanded ? 'justify-start pt-[16vh]' : 'justify-center',\n ].join(' ')}\n data-testid=\"assistant-voice-stage\"\n data-state={state}\n >\n {/* Status first and small: it is the label for the state, not the content. */}\n <p\n className={[\n 'text-center text-text-muted',\n expanded ? 'text-base' : 'text-sm',\n // The status LABELS the waveform, so it sits close to it. A uniform\n // gap made status, waveform, caption and control read as four\n // items of equal weight, with no hierarchy at all.\n expanded ? 'mb-3' : 'mb-2',\n ].join(' ')}\n // The stage change IS the feedback; without this a screen-reader user\n // is told nothing when connecting becomes listening becomes thinking.\n aria-live=\"polite\"\n data-testid=\"assistant-voice-status\"\n >\n {statusText}\n </p>\n\n {state === 'mic-error' ? (\n // A failure gets the stage to itself — no caption, no waveform. It is\n // not part of the conversation and must not look like it.\n <p\n className={`max-w-md text-center text-status-warning ${expanded ? 'text-lg' : 'text-sm'}`}\n role=\"alert\"\n data-testid=\"assistant-voice-stage-error\"\n >\n {errorText}\n </p>\n ) : (\n <>\n <div className={expanded ? 'mb-10' : 'mb-5'}>\n <VoiceWaveform\n // ★ `endpoint-grace` keeps the waveform ALIVE. It is the two-second\n // window in which the user may still correct themselves, so it has\n // to look like a microphone that is still open — a frozen waveform\n // would read as \"it stopped listening\", which is the opposite of\n // what the window is for. `interrupting` stays still on purpose:\n // the assistant has just been cut off and capture has not resumed.\n active={waveformIsActive(state)}\n settled={waveformIsSettled(state)}\n tone={state === 'speaking' ? 'speaking' : 'listening'}\n expanded={expanded}\n />\n </div>\n\n {caption ? (\n <div\n className={\n expanded\n ? // ★ A long reply used to run off the bottom of the screen with\n // no way to reach it. The model is asked for one to four\n // sentences, but that is guidance, not a guarantee — so the\n // caption is bounded and scrolls rather than being lost.\n 'mb-12 max-h-[46vh] w-full overflow-y-auto'\n : 'mb-6 w-full'\n }\n >\n <VoiceCaption\n text={caption}\n role={showsAssistantCaption(state) ? 'assistant' : 'user'}\n expanded={expanded}\n testId=\"assistant-voice-caption\"\n />\n </div>\n ) : (\n // Reserve the caption's space so the control does not jump when the\n // first words arrive. Two lines' worth at each size, matching what\n // a typical utterance actually occupies.\n <div className={expanded ? 'mb-12 h-[4.5rem]' : 'mb-6 h-12'} aria-hidden=\"true\" />\n )}\n </>\n )}\n\n {control}\n </div>\n );\n};\n"],"mappings":";;;;;AA6CA,IAAa,KAAyB,EACpC,UACA,gBACA,qBACA,aACA,eACA,YACA,eAAY,WACR;CACJ,IAAM,IAAU,EAAsB,CAAK,IAAI,IAAmB,EAAiB,CAAK,IAAI,IAAc;CAE1G,OACE,kBAAC,OAAD;EACE,WAAW;GACT;GACA,IAAW,SAAS;GAMpB,IAAW,4BAA4B;EACzC,EAAE,KAAK,GAAG;EACV,eAAY;EACZ,cAAY;YAZd;GAeE,kBAAC,KAAD;IACE,WAAW;KACT;KACA,IAAW,cAAc;KAIzB,IAAW,SAAS;IACtB,EAAE,KAAK,GAAG;IAGV,aAAU;IACV,eAAY;cAEX;GACA,CAAA;GAEF,MAAU,cAGT,kBAAC,KAAD;IACE,WAAW,4CAA4C,IAAW,YAAY;IAC9E,MAAK;IACL,eAAY;cAEX;GACA,CAAA,IAEH,kBAAA,GAAA,EAAA,UAAA,CACE,kBAAC,OAAD;IAAK,WAAW,IAAW,UAAU;cACnC,kBAAC,GAAD;KAOE,QAAQ,EAAiB,CAAK;KAC9B,SAAS,EAAkB,CAAK;KAChC,MAAM,MAAU,aAAa,aAAa;KAChC;IACX,CAAA;GACE,CAAA,GAEJ,IACC,kBAAC,OAAD;IACE,WACE,IAKI,8CACA;cAGN,kBAAC,GAAD;KACE,MAAM;KACN,MAAM,EAAsB,CAAK,IAAI,cAAc;KACzC;KACV,QAAO;IACR,CAAA;GACE,CAAA,IAKL,kBAAC,OAAD;IAAK,WAAW,IAAW,qBAAqB;IAAa,eAAY;GAAQ,CAAA,CAEnF,EAAA,CAAA;GAGH;EACE;;AAET"}
1
+ {"version":3,"file":"VoiceStage.js","names":[],"sources":["../../../../src/components/assistant/voice/VoiceStage.tsx"],"sourcesContent":["import type { FC, ReactNode } from 'react';\nimport { VoiceCaption } from './VoiceCaption';\nimport { VoiceWaveform } from './VoiceWaveform';\nimport {\n waveformIsActive,\n waveformIsSettled,\n showsAssistantCaption,\n showsUserCaption,\n type VoiceStageState,\n} from '../../../utils/voiceStageState';\n\n/**\n * The middle of the voice panel: exactly ONE state, rendered as itself.\n *\n * What this replaces is the whole problem the operator screenshotted. The old\n * overlay showed, simultaneously: \"Listening…\", a microphone warning, the last\n * six messages of the chat conversation as bubbles (markdown syntax and all),\n * the assistant's answer AGAIN as a caption, and the orb. Five things competing,\n * none of them readable.\n *\n * ★ A stage shows one thing because the session IS one thing at a time. The\n * state is derived in `voiceStageState`, which is pure and tested; this file is\n * presentational and cannot be tested in this repo (vitest runs in `node`, no\n * DOM), so it deliberately contains no logic worth testing.\n *\n * The microphone warning is NOT rendered here. Mixing a system message into the\n * conversation area is what made it read as part of the reply; it belongs to\n * the chrome around the stage.\n */\n\ninterface Props {\n state: VoiceStageState;\n /** What the user is saying (live) or last said. */\n userCaption: string | null;\n /** What the assistant is saying. */\n assistantCaption: string | null;\n expanded: boolean;\n /** Status words — already localised by the caller. */\n statusText: string;\n /** The microphone / interrupt control. */\n control: ReactNode;\n /** Shown in the mic-error state instead of a caption. */\n errorText?: string | null;\n}\n\nexport const VoiceStage: FC<Props> = ({\n state,\n userCaption,\n assistantCaption,\n expanded,\n statusText,\n control,\n errorText = null,\n}) => {\n const caption = showsAssistantCaption(state) ? assistantCaption : showsUserCaption(state) ? userCaption : null;\n\n return (\n <div\n className={[\n 'flex min-h-0 w-full flex-1 flex-col items-center',\n expanded ? 'px-8' : 'px-14',\n // ★ Expanded, the group is anchored just above the optical centre\n // rather than centred in the whole box. Measured at 1440x900 the\n // content was 314px of a 756px stage with 221px of dead air above AND\n // below — technically centred, visually adrift. Docked the box is\n // small enough that centring is right.\n expanded ? 'justify-start pt-[16vh]' : 'justify-center',\n ].join(' ')}\n data-testid=\"assistant-voice-stage\"\n data-state={state}\n >\n {/* Status first and small: it is the label for the state, not the content. */}\n <p\n className={[\n 'text-center text-text-muted',\n expanded ? 'text-base' : 'text-sm',\n // The status LABELS the waveform, so it sits close to it. A uniform\n // gap made status, waveform, caption and control read as four\n // items of equal weight, with no hierarchy at all.\n expanded ? 'mb-3' : 'mb-2',\n ].join(' ')}\n // The stage change IS the feedback; without this a screen-reader user\n // is told nothing when connecting becomes listening becomes thinking.\n aria-live=\"polite\"\n data-testid=\"assistant-voice-status\"\n >\n {statusText}\n </p>\n\n {state === 'mic-error' ? (\n // A failure gets the stage to itself — no caption, no waveform. It is\n // not part of the conversation and must not look like it.\n <p\n className={`max-w-md text-center text-status-warning ${expanded ? 'text-lg' : 'text-sm'}`}\n role=\"alert\"\n data-testid=\"assistant-voice-stage-error\"\n >\n {errorText}\n </p>\n ) : (\n <>\n <div className={expanded ? 'mb-10' : 'mb-5'}>\n <VoiceWaveform\n // ★ `endpoint-grace` keeps the waveform ALIVE. It is the two-second\n // window in which the user may still correct themselves, so it has\n // to look like a microphone that is still open — a frozen waveform\n // would read as \"it stopped listening\", which is the opposite of\n // what the window is for. `interrupting` stays still on purpose:\n // the assistant has just been cut off and capture has not resumed.\n active={waveformIsActive(state)}\n settled={waveformIsSettled(state)}\n tone={state === 'speaking' ? 'speaking' : 'listening'}\n expanded={expanded}\n />\n </div>\n\n {caption ? (\n <div\n className={\n expanded\n ? // ★ A long reply used to run off the bottom of the screen with\n // no way to reach it. The model is asked for one to four\n // sentences, but that is guidance, not a guarantee — so the\n // caption is bounded and scrolls rather than being lost.\n 'mb-12 max-h-[46vh] w-full overflow-y-auto'\n : // ★ The SAME bound, which the docked panel never got. It is the\n // shorter surface of the two, so an unbounded caption there\n // pushed the orb — the only in-flow control — out of view and\n // clipped the rest of the answer with no way to scroll to it.\n 'mb-6 max-h-[38vh] w-full overflow-y-auto'\n }\n >\n <VoiceCaption\n text={caption}\n role={showsAssistantCaption(state) ? 'assistant' : 'user'}\n expanded={expanded}\n testId=\"assistant-voice-caption\"\n />\n </div>\n ) : (\n // Reserve the caption's space so the control does not jump when the\n // first words arrive. Two lines' worth at each size, matching what\n // a typical utterance actually occupies.\n //\n // ★ 4.875rem is 3x the assistant caption's MINIMUM (1.625rem at 1.5\n // leading = two lines), tracking the type floor as the old 4.5rem\n // tracked 1.5rem. Honest about what that does and does not buy: it\n // removes the jump only while the clamp is at its floor, i.e. up to\n // ~1040px viewport, and the reserve is sized to the ASSISTANT\n // caption while the common transition out of it is to the smaller\n // USER caption. It is a compromise between two captions of\n // different sizes, not a guarantee.\n <div className={expanded ? 'mb-12 h-[4.875rem]' : 'mb-6 h-12'} aria-hidden=\"true\" />\n )}\n </>\n )}\n\n {control}\n </div>\n );\n};\n"],"mappings":";;;;;AA6CA,IAAa,KAAyB,EACpC,UACA,gBACA,qBACA,aACA,eACA,YACA,eAAY,WACR;CACJ,IAAM,IAAU,EAAsB,CAAK,IAAI,IAAmB,EAAiB,CAAK,IAAI,IAAc;CAE1G,OACE,kBAAC,OAAD;EACE,WAAW;GACT;GACA,IAAW,SAAS;GAMpB,IAAW,4BAA4B;EACzC,EAAE,KAAK,GAAG;EACV,eAAY;EACZ,cAAY;YAZd;GAeE,kBAAC,KAAD;IACE,WAAW;KACT;KACA,IAAW,cAAc;KAIzB,IAAW,SAAS;IACtB,EAAE,KAAK,GAAG;IAGV,aAAU;IACV,eAAY;cAEX;GACA,CAAA;GAEF,MAAU,cAGT,kBAAC,KAAD;IACE,WAAW,4CAA4C,IAAW,YAAY;IAC9E,MAAK;IACL,eAAY;cAEX;GACA,CAAA,IAEH,kBAAA,GAAA,EAAA,UAAA,CACE,kBAAC,OAAD;IAAK,WAAW,IAAW,UAAU;cACnC,kBAAC,GAAD;KAOE,QAAQ,EAAiB,CAAK;KAC9B,SAAS,EAAkB,CAAK;KAChC,MAAM,MAAU,aAAa,aAAa;KAChC;IACX,CAAA;GACE,CAAA,GAEJ,IACC,kBAAC,OAAD;IACE,WACE,IAKI,8CAKA;cAGN,kBAAC,GAAD;KACE,MAAM;KACN,MAAM,EAAsB,CAAK,IAAI,cAAc;KACzC;KACV,QAAO;IACR,CAAA;GACE,CAAA,IAcL,kBAAC,OAAD;IAAK,WAAW,IAAW,uBAAuB;IAAa,eAAY;GAAQ,CAAA,CAErF,EAAA,CAAA;GAGH;EACE;;AAET"}
@@ -8,7 +8,7 @@ var a = ({ turns: a, onClose: o }) => {
8
8
  return /* @__PURE__ */ i("div", {
9
9
  className: "absolute inset-0 z-30 flex flex-col bg-bg-sunken/95 backdrop-blur-sm",
10
10
  role: "dialog",
11
- "aria-label": s("healthybowl.assistant.voiceSession.transcript", "Voice transcript"),
11
+ "aria-label": s("healthybowl.assistant.voiceSession.transcriptTitle", "Voice transcript"),
12
12
  "data-testid": "assistant-voice-transcript",
13
13
  children: [/* @__PURE__ */ i("div", {
14
14
  className: "flex items-center justify-between border-b border-border-subtle px-4 py-3",
@@ -19,7 +19,7 @@ var a = ({ turns: a, onClose: o }) => {
19
19
  children: s("healthybowl.assistant.voiceSession.transcript", "Voice conversation")
20
20
  }), /* @__PURE__ */ r("p", {
21
21
  className: "truncate text-xs text-text-muted",
22
- children: s("healthybowl.assistant.voiceSession.transcriptHint", "This session only — kept out of your typed chat.")
22
+ children: s("healthybowl.assistant.voiceSession.transcriptHint", "Spoken turns in this conversation — kept out of your typed chat.")
23
23
  })]
24
24
  }), /* @__PURE__ */ r("button", {
25
25
  type: "button",
@@ -1 +1 @@
1
- {"version":3,"file":"VoiceTranscriptDrawer.js","names":[],"sources":["../../../../src/components/assistant/voice/VoiceTranscriptDrawer.tsx"],"sourcesContent":["import type { FC } from 'react';\nimport { X } from 'lucide-react';\nimport { useTr } from '../../../shared/hooks/useTr';\nimport { VoiceConversationView } from './VoiceConversationView';\n\n/**\n * This session's spoken turns, on demand.\n *\n * The stage shows only what is happening NOW, which is right for a live\n * conversation and would otherwise mean the history is simply gone. This is\n * where it goes: secondary, behind a button, and explicitly a VOICE transcript\n * rather than the chat thread.\n *\n * ★ `z-30` is not decoration: the session container is `z-20` docked and\n * `z-[60]` expanded, and a child at `z-10` painted BEHIND its own parent — the\n * drawer opened and was invisible. Stacking contexts are per-parent, so this\n * only has to beat its siblings, not the overlay itself.\n *\n * ★ Session-scoped and ephemeral by design. It renders the turns it is handed —\n * which are already filtered to this voice session — so it can never resurrect\n * the typed conversation the old overlay used to paint.\n */\n\ninterface Props {\n turns: ReadonlyArray<{ id: string; role: 'user' | 'assistant'; text: string }>;\n onClose: () => void;\n}\n\nexport const VoiceTranscriptDrawer: FC<Props> = ({ turns, onClose }) => {\n const tr = useTr();\n return (\n <div\n className=\"absolute inset-0 z-30 flex flex-col bg-bg-sunken/95 backdrop-blur-sm\"\n role=\"dialog\"\n aria-label={tr('healthybowl.assistant.voiceSession.transcript', 'Voice transcript')}\n data-testid=\"assistant-voice-transcript\"\n >\n <div className=\"flex items-center justify-between border-b border-border-subtle px-4 py-3\">\n <div className=\"min-w-0\">\n <h2 className=\"text-sm font-semibold text-text-primary\">\n {tr('healthybowl.assistant.voiceSession.transcript', 'Voice conversation')}\n </h2>\n {/* Say plainly that this is NOT the typed thread, so nobody wonders\n why it is not in their chat history. */}\n <p className=\"truncate text-xs text-text-muted\">\n {tr(\n 'healthybowl.assistant.voiceSession.transcriptHint',\n 'This session only — kept out of your typed chat.'\n )}\n </p>\n </div>\n <button\n type=\"button\"\n onClick={onClose}\n className=\"flex size-8 items-center justify-center rounded-full text-text-secondary transition-colors hover:bg-bg-raised hover:text-text-primary focus:outline-none focus-visible:ring-2 focus-visible:ring-border-strong\"\n aria-label={tr('healthybowl.assistant.voiceSession.transcriptClose', 'Close the transcript')}\n data-testid=\"assistant-voice-transcript-close\"\n >\n <X className=\"size-4\" />\n </button>\n </div>\n\n <VoiceConversationView turns={turns} />\n </div>\n );\n};\n"],"mappings":";;;;;AA4BA,IAAa,KAAoC,EAAE,UAAO,iBAAc;CACtE,IAAM,IAAK,EAAM;CACjB,OACE,kBAAC,OAAD;EACE,WAAU;EACV,MAAK;EACL,cAAY,EAAG,iDAAiD,kBAAkB;EAClF,eAAY;YAJd,CAME,kBAAC,OAAD;GAAK,WAAU;aAAf,CACE,kBAAC,OAAD;IAAK,WAAU;cAAf,CACE,kBAAC,MAAD;KAAI,WAAU;eACX,EAAG,iDAAiD,oBAAoB;IACvE,CAAA,GAGJ,kBAAC,KAAD;KAAG,WAAU;eACV,EACC,qDACA,kDACF;IACC,CAAA,CACA;OACL,kBAAC,UAAD;IACE,MAAK;IACL,SAAS;IACT,WAAU;IACV,cAAY,EAAG,sDAAsD,sBAAsB;IAC3F,eAAY;cAEZ,kBAAC,GAAD,EAAG,WAAU,SAAU,CAAA;GACjB,CAAA,CACL;MAEL,kBAAC,GAAD,EAA8B,SAAQ,CAAA,CACnC;;AAET"}
1
+ {"version":3,"file":"VoiceTranscriptDrawer.js","names":[],"sources":["../../../../src/components/assistant/voice/VoiceTranscriptDrawer.tsx"],"sourcesContent":["import type { FC } from 'react';\nimport { X } from 'lucide-react';\nimport { useTr } from '../../../shared/hooks/useTr';\nimport { VoiceConversationView } from './VoiceConversationView';\n\n/**\n * This session's spoken turns, on demand.\n *\n * The stage shows only what is happening NOW, which is right for a live\n * conversation and would otherwise mean the history is simply gone. This is\n * where it goes: secondary, behind a button, and explicitly a VOICE transcript\n * rather than the chat thread.\n *\n * ★ `z-30` is not decoration: the session container is `z-20` docked and\n * `z-[60]` expanded, and a child at `z-10` painted BEHIND its own parent — the\n * drawer opened and was invisible. Stacking contexts are per-parent, so this\n * only has to beat its siblings, not the overlay itself.\n *\n * ★ Session-scoped and ephemeral by design. It renders the turns it is handed —\n * which are already filtered to this voice session — so it can never resurrect\n * the typed conversation the old overlay used to paint.\n */\n\ninterface Props {\n turns: ReadonlyArray<{ id: string; role: 'user' | 'assistant'; text: string }>;\n onClose: () => void;\n}\n\nexport const VoiceTranscriptDrawer: FC<Props> = ({ turns, onClose }) => {\n const tr = useTr();\n return (\n <div\n className=\"absolute inset-0 z-30 flex flex-col bg-bg-sunken/95 backdrop-blur-sm\"\n role=\"dialog\"\n // ★ Its OWN key. This shared `…voiceSession.transcript` with the heading\n // below while giving it a different English default, so once the key is\n // seeded one of the two silently changes to the other's wording.\n aria-label={tr('healthybowl.assistant.voiceSession.transcriptTitle', 'Voice transcript')}\n data-testid=\"assistant-voice-transcript\"\n >\n <div className=\"flex items-center justify-between border-b border-border-subtle px-4 py-3\">\n <div className=\"min-w-0\">\n <h2 className=\"text-sm font-semibold text-text-primary\">\n {tr('healthybowl.assistant.voiceSession.transcript', 'Voice conversation')}\n </h2>\n {/* Say plainly that this is NOT the typed thread, so nobody wonders\n why it is not in their chat history.\n\n ★ It used to say \"This session only\", which was not true:\n `voiceTurnsOnly` filters on a per-message marker, so it returns every\n spoken turn in the CONVERSATION, and a second voice session showed the\n first one's turns under a promise that it would not. Showing the whole\n conversation's spoken history is the more useful behaviour of the two,\n so the wording changed rather than the filter. */}\n <p className=\"truncate text-xs text-text-muted\">\n {tr(\n 'healthybowl.assistant.voiceSession.transcriptHint',\n 'Spoken turns in this conversation — kept out of your typed chat.'\n )}\n </p>\n </div>\n <button\n type=\"button\"\n onClick={onClose}\n className=\"flex size-8 items-center justify-center rounded-full text-text-secondary transition-colors hover:bg-bg-raised hover:text-text-primary focus:outline-none focus-visible:ring-2 focus-visible:ring-border-strong\"\n aria-label={tr('healthybowl.assistant.voiceSession.transcriptClose', 'Close the transcript')}\n data-testid=\"assistant-voice-transcript-close\"\n >\n <X className=\"size-4\" />\n </button>\n </div>\n\n <VoiceConversationView turns={turns} />\n </div>\n );\n};\n"],"mappings":";;;;;AA4BA,IAAa,KAAoC,EAAE,UAAO,iBAAc;CACtE,IAAM,IAAK,EAAM;CACjB,OACE,kBAAC,OAAD;EACE,WAAU;EACV,MAAK;EAIL,cAAY,EAAG,sDAAsD,kBAAkB;EACvF,eAAY;YAPd,CASE,kBAAC,OAAD;GAAK,WAAU;aAAf,CACE,kBAAC,OAAD;IAAK,WAAU;cAAf,CACE,kBAAC,MAAD;KAAI,WAAU;eACX,EAAG,iDAAiD,oBAAoB;IACvE,CAAA,GAUJ,kBAAC,KAAD;KAAG,WAAU;eACV,EACC,qDACA,kEACF;IACC,CAAA,CACA;OACL,kBAAC,UAAD;IACE,MAAK;IACL,SAAS;IACT,WAAU;IACV,cAAY,EAAG,sDAAsD,sBAAsB;IAC3F,eAAY;cAEZ,kBAAC,GAAD,EAAG,WAAU,SAAU,CAAA;GACjB,CAAA,CACL;MAEL,kBAAC,GAAD,EAA8B,SAAQ,CAAA,CACnC;;AAET"}
@@ -1,5 +1,15 @@
1
1
  //#region src/config/speechLabels.ts
2
2
  var e = {
3
+ en: {
4
+ codeBlock: "Code block",
5
+ image: "image",
6
+ link: "link",
7
+ largeTable: "Table with {{rows}} rows and {{columns}} columns",
8
+ truncated: "The rest of this message is not read aloud",
9
+ nestedItem: "Sub-item {{ordinal}}",
10
+ emailAt: "at",
11
+ emailDot: "dot"
12
+ },
3
13
  ta: {
4
14
  codeBlock: "நிரல் தொகுதி",
5
15
  image: "படம்",
@@ -1 +1 @@
1
- {"version":3,"file":"speechLabels.js","names":[],"sources":["../../src/config/speechLabels.ts"],"sourcesContent":["import type { SpeakableLabels } from '../utils/speakableText';\n\n/**\n * The spoken stand-ins, in the language of the REPLY (BOFF-7120).\n *\n * When a reply contains something that cannot be read aloud — an image, a link,\n * a fenced code block, a wide table — the reader substitutes a word. Those words\n * used to come from `tr()`, which resolves against the INTERFACE language. So an\n * English interface reading a Tamil answer said \"Code block\" and \"image\" in\n * English, dropped into the middle of a Tamil sentence. Exactly the complaint\n * that produced the translatable `at`/`dot` for email addresses; that fix was\n * applied there and nowhere else.\n *\n * ★ Why a static table rather than `tr()` with a locale argument: the i18n\n * provider only ever FETCHES the active locale. `I18nContextValue.translations`\n * holds that one dictionary, so there is nothing to ask for Tamil while the\n * interface is English — the strings simply are not in the client. These eight\n * are short, stable, and needed synchronously mid-utterance, so they are carried\n * here instead.\n *\n * Anything not listed falls back to the interface-language label, which is what\n * happens today — so this can only improve on the current behaviour, never\n * regress it.\n */\ntype PartialLabels = Partial<SpeakableLabels>;\n\n/** Keyed by primary language subtag, since the reply locale may carry a region. */\nconst LABELS_BY_LANGUAGE: Record<string, PartialLabels> = {\n ta: {\n codeBlock: 'நிரல் தொகுதி',\n image: 'படம்',\n link: 'இணைப்பு',\n largeTable: '{{rows}} வரிசைகள் மற்றும் {{columns}} நெடுவரிசைகள் கொண்ட அட்டவணை',\n truncated: 'இந்தச் செய்தியின் மீதமுள்ள பகுதி வாசிக்கப்படவில்லை',\n nestedItem: 'துணை உருப்படி {{ordinal}}',\n emailAt: 'அட்',\n emailDot: 'புள்ளி',\n },\n hi: {\n codeBlock: 'कोड ब्लॉक',\n image: 'छवि',\n link: 'लिंक',\n largeTable: '{{rows}} पंक्तियों और {{columns}} स्तंभों वाली तालिका',\n truncated: 'इस संदेश का शेष भाग नहीं पढ़ा जाता',\n nestedItem: 'उप-आइटम {{ordinal}}',\n emailAt: 'ऐट',\n emailDot: 'डॉट',\n },\n ar: {\n codeBlock: 'كتلة برمجية',\n image: 'صورة',\n link: 'رابط',\n largeTable: 'جدول من {{rows}} صفوف و {{columns}} أعمدة',\n truncated: 'لا تتم قراءة بقية هذه الرسالة بصوت عالٍ',\n nestedItem: 'عنصر فرعي {{ordinal}}',\n emailAt: 'أت',\n emailDot: 'نقطة',\n },\n es: {\n codeBlock: 'Bloque de código',\n image: 'imagen',\n link: 'enlace',\n largeTable: 'Tabla con {{rows}} filas y {{columns}} columnas',\n truncated: 'El resto de este mensaje no se lee en voz alta',\n nestedItem: 'Subelemento {{ordinal}}',\n emailAt: 'arroba',\n emailDot: 'punto',\n },\n zh: {\n codeBlock: '代码块',\n image: '图片',\n link: '链接',\n largeTable: '包含 {{rows}} 行 {{columns}} 列的表格',\n truncated: '此消息的其余部分不会朗读',\n nestedItem: '子项 {{ordinal}}',\n emailAt: 'at',\n emailDot: '点',\n },\n};\n\n/**\n * Labels to read a reply in `locale` with.\n *\n * `uiLabels` is the interface-language set, used both as the base and as the\n * fallback for any language not carried here — so English replies, and any\n * language we have no table for, behave exactly as before.\n */\nexport function speechLabelsFor(locale: string, uiLabels: SpeakableLabels): SpeakableLabels {\n const primary = locale.trim().toLowerCase().split(/[-_]/)[0];\n if (!primary) return uiLabels;\n const overrides = LABELS_BY_LANGUAGE[primary];\n return overrides ? { ...uiLabels, ...overrides } : uiLabels;\n}\n\n/** Exposed for tests: which languages have their own spoken labels. */\nexport const SPOKEN_LABEL_LANGUAGES = Object.keys(LABELS_BY_LANGUAGE);\n"],"mappings":";AA2BA,IAAM,IAAoD;CACxD,IAAI;EACF,WAAW;EACX,OAAO;EACP,MAAM;EACN,YAAY;EACZ,WAAW;EACX,YAAY;EACZ,SAAS;EACT,UAAU;CACZ;CACA,IAAI;EACF,WAAW;EACX,OAAO;EACP,MAAM;EACN,YAAY;EACZ,WAAW;EACX,YAAY;EACZ,SAAS;EACT,UAAU;CACZ;CACA,IAAI;EACF,WAAW;EACX,OAAO;EACP,MAAM;EACN,YAAY;EACZ,WAAW;EACX,YAAY;EACZ,SAAS;EACT,UAAU;CACZ;CACA,IAAI;EACF,WAAW;EACX,OAAO;EACP,MAAM;EACN,YAAY;EACZ,WAAW;EACX,YAAY;EACZ,SAAS;EACT,UAAU;CACZ;CACA,IAAI;EACF,WAAW;EACX,OAAO;EACP,MAAM;EACN,YAAY;EACZ,WAAW;EACX,YAAY;EACZ,SAAS;EACT,UAAU;CACZ;AACF;AASA,SAAgB,EAAgB,GAAgB,GAA4C;CAC1F,IAAM,IAAU,EAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,EAAE;CAC1D,IAAI,CAAC,GAAS,OAAO;CACrB,IAAM,IAAY,EAAmB;CACrC,OAAO,IAAY;EAAE,GAAG;EAAU,GAAG;CAAU,IAAI;AACrD"}
1
+ {"version":3,"file":"speechLabels.js","names":[],"sources":["../../src/config/speechLabels.ts"],"sourcesContent":["import type { SpeakableLabels } from '../utils/speakableText';\n\n/**\n * The spoken stand-ins, in the language of the REPLY (BOFF-7120).\n *\n * When a reply contains something that cannot be read aloud — an image, a link,\n * a fenced code block, a wide table — the reader substitutes a word. Those words\n * used to come from `tr()`, which resolves against the INTERFACE language. So an\n * English interface reading a Tamil answer said \"Code block\" and \"image\" in\n * English, dropped into the middle of a Tamil sentence. Exactly the complaint\n * that produced the translatable `at`/`dot` for email addresses; that fix was\n * applied there and nowhere else.\n *\n * ★ Why a static table rather than `tr()` with a locale argument: the i18n\n * provider only ever FETCHES the active locale. `I18nContextValue.translations`\n * holds that one dictionary, so there is nothing to ask for Tamil while the\n * interface is English — the strings simply are not in the client. These eight\n * are short, stable, and needed synchronously mid-utterance, so they are carried\n * here instead.\n *\n * Anything not listed falls back to the interface-language label, which is what\n * happens today — so this can only improve on the current behaviour, never\n * regress it.\n */\ntype PartialLabels = Partial<SpeakableLabels>;\n\n/** Keyed by primary language subtag, since the reply locale may carry a region. */\nconst LABELS_BY_LANGUAGE: Record<string, PartialLabels> = {\n /**\n * ★ English is carried explicitly, and it is not redundant.\n *\n * The fallback below is the INTERFACE language, so a language with no table of\n * its own inherits whatever the menu is set to. That is right for an unlisted\n * language, and exactly wrong for English: with a Tamil interface and an\n * English reply, `tr()` returned the Tamil words and spliced \"நிரல் தொகுதி\"\n * into an English sentence — the very defect this table exists to prevent,\n * running the other way. Naming English pins it regardless of the menu.\n *\n * These are the same strings as the English defaults in `speakableText.ts`;\n * unlike the others they need no translator, which is why this one entry is\n * here while the remaining locales are not.\n */\n en: {\n codeBlock: 'Code block',\n image: 'image',\n link: 'link',\n largeTable: 'Table with {{rows}} rows and {{columns}} columns',\n truncated: 'The rest of this message is not read aloud',\n nestedItem: 'Sub-item {{ordinal}}',\n emailAt: 'at',\n emailDot: 'dot',\n },\n ta: {\n codeBlock: 'நிரல் தொகுதி',\n image: 'படம்',\n link: 'இணைப்பு',\n largeTable: '{{rows}} வரிசைகள் மற்றும் {{columns}} நெடுவரிசைகள் கொண்ட அட்டவணை',\n truncated: 'இந்தச் செய்தியின் மீதமுள்ள பகுதி வாசிக்கப்படவில்லை',\n nestedItem: 'துணை உருப்படி {{ordinal}}',\n emailAt: 'அட்',\n emailDot: 'புள்ளி',\n },\n hi: {\n codeBlock: 'कोड ब्लॉक',\n image: 'छवि',\n link: 'लिंक',\n largeTable: '{{rows}} पंक्तियों और {{columns}} स्तंभों वाली तालिका',\n truncated: 'इस संदेश का शेष भाग नहीं पढ़ा जाता',\n nestedItem: 'उप-आइटम {{ordinal}}',\n emailAt: 'ऐट',\n emailDot: 'डॉट',\n },\n ar: {\n codeBlock: 'كتلة برمجية',\n image: 'صورة',\n link: 'رابط',\n largeTable: 'جدول من {{rows}} صفوف و {{columns}} أعمدة',\n truncated: 'لا تتم قراءة بقية هذه الرسالة بصوت عالٍ',\n nestedItem: 'عنصر فرعي {{ordinal}}',\n emailAt: 'أت',\n emailDot: 'نقطة',\n },\n es: {\n codeBlock: 'Bloque de código',\n image: 'imagen',\n link: 'enlace',\n largeTable: 'Tabla con {{rows}} filas y {{columns}} columnas',\n truncated: 'El resto de este mensaje no se lee en voz alta',\n nestedItem: 'Subelemento {{ordinal}}',\n emailAt: 'arroba',\n emailDot: 'punto',\n },\n zh: {\n codeBlock: '代码块',\n image: '图片',\n link: '链接',\n largeTable: '包含 {{rows}} 行 {{columns}} 列的表格',\n truncated: '此消息的其余部分不会朗读',\n nestedItem: '子项 {{ordinal}}',\n emailAt: 'at',\n emailDot: '点',\n },\n};\n\n/**\n * Labels to read a reply in `locale` with.\n *\n * `uiLabels` is the interface-language set, used both as the base and as the\n * fallback for any language not carried here — so English replies, and any\n * language we have no table for, behave exactly as before.\n */\nexport function speechLabelsFor(locale: string, uiLabels: SpeakableLabels): SpeakableLabels {\n const primary = locale.trim().toLowerCase().split(/[-_]/)[0];\n if (!primary) return uiLabels;\n const overrides = LABELS_BY_LANGUAGE[primary];\n return overrides ? { ...uiLabels, ...overrides } : uiLabels;\n}\n\n/** Exposed for tests: which languages have their own spoken labels. */\nexport const SPOKEN_LABEL_LANGUAGES = Object.keys(LABELS_BY_LANGUAGE);\n"],"mappings":";AA2BA,IAAM,IAAoD;CAexD,IAAI;EACF,WAAW;EACX,OAAO;EACP,MAAM;EACN,YAAY;EACZ,WAAW;EACX,YAAY;EACZ,SAAS;EACT,UAAU;CACZ;CACA,IAAI;EACF,WAAW;EACX,OAAO;EACP,MAAM;EACN,YAAY;EACZ,WAAW;EACX,YAAY;EACZ,SAAS;EACT,UAAU;CACZ;CACA,IAAI;EACF,WAAW;EACX,OAAO;EACP,MAAM;EACN,YAAY;EACZ,WAAW;EACX,YAAY;EACZ,SAAS;EACT,UAAU;CACZ;CACA,IAAI;EACF,WAAW;EACX,OAAO;EACP,MAAM;EACN,YAAY;EACZ,WAAW;EACX,YAAY;EACZ,SAAS;EACT,UAAU;CACZ;CACA,IAAI;EACF,WAAW;EACX,OAAO;EACP,MAAM;EACN,YAAY;EACZ,WAAW;EACX,YAAY;EACZ,SAAS;EACT,UAAU;CACZ;CACA,IAAI;EACF,WAAW;EACX,OAAO;EACP,MAAM;EACN,YAAY;EACZ,WAAW;EACX,YAAY;EACZ,SAAS;EACT,UAAU;CACZ;AACF;AASA,SAAgB,EAAgB,GAAgB,GAA4C;CAC1F,IAAM,IAAU,EAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,EAAE;CAC1D,IAAI,CAAC,GAAS,OAAO;CACrB,IAAM,IAAY,EAAmB;CACrC,OAAO,IAAY;EAAE,GAAG;EAAU,GAAG;CAAU,IAAI;AACrD"}
@@ -57,6 +57,8 @@ function c({ onFinalize: c, language: l }) {
57
57
  t !== "no-speech" && g(t);
58
58
  }, t.onend = () => {
59
59
  n === v.current && (_.current = null, f(!1), m(""));
60
+ }, t.onstart = () => {
61
+ n === v.current && f(!0);
60
62
  };
61
63
  try {
62
64
  t.start();
@@ -64,7 +66,7 @@ function c({ onFinalize: c, language: l }) {
64
66
  _.current = null, f(!1);
65
67
  return;
66
68
  }
67
- _.current = t, g(null), m(""), f(!0);
69
+ _.current = t, g(null), m("");
68
70
  }, [x]), C = e(() => {
69
71
  let e = _.current;
70
72
  _.current = null, v.current += 1, e?.stop(), f(!1), m("");
@@ -1 +1 @@
1
- {"version":3,"file":"useVoiceInput.js","names":[],"sources":["../../src/hooks/useVoiceInput.ts"],"sourcesContent":["/**\n * Speech-to-text for the assistant composer (Workstream 2 of the AI Assistant\n * V2 multimodal effort).\n *\n * Input-only, browser-native (Web Speech API). It degrades gracefully:\n * `isSupported` is false on engines without SpeechRecognition (notably Firefox),\n * and the composer hides the mic entirely in that case rather than showing a\n * dead control.\n *\n * ⚠️ This does NOT mean the audio stays on the device. Chrome's\n * `webkitSpeechRecognition` is a NETWORK service — the audio is streamed to the\n * browser vendor for recognition, and the supported language list is theirs, not\n * ours. We neither receive nor store it, which is all an earlier version of this\n * comment (\"no audio ever leaves the device through us\") actually claimed; read\n * literally it implied something stronger and untrue. Whether recording farmers'\n * speech this way needs disclosure or consent is a product/legal call, not a\n * code one.\n *\n * Output (reading replies aloud) is a separate concern and lives in\n * `AssistantSpeechProvider`; an earlier version of this note said the assistant\n * does not speak, which stopped being true when BOFF-6290 shipped.\n *\n * Differences from the fe-libs `assistantWidget/useVoiceInput` this is modelled\n * on, all of which the composer needs:\n * - **interim results are exposed**, so the user sees words appear while\n * speaking instead of staring at a silent button until a phrase finalises;\n * - **errors are surfaced** (`error`) so a denied mic permission can be\n * explained rather than looking like a no-op;\n * - **the recogniser language follows the app locale** (a Tamil or Hindi\n * farmer dictating into an `en-US` recogniser gets garbage);\n * - **`stop()` resolves the final transcript** through `onFinalize`, so the\n * composer can commit exactly once when the user stops.\n */\n\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';\nimport type { Locale } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';\n\ninterface SpeechRecognitionEventLike extends Event {\n results: SpeechRecognitionResultList;\n resultIndex: number;\n}\n\ninterface SpeechRecognitionErrorEventLike extends Event {\n error: string;\n message: string;\n}\n\ninterface SpeechRecognitionInstance extends EventTarget {\n continuous: boolean;\n interimResults: boolean;\n lang: string;\n start(): void;\n stop(): void;\n abort(): void;\n onresult: ((event: SpeechRecognitionEventLike) => void) | null;\n onerror: ((event: SpeechRecognitionErrorEventLike) => void) | null;\n onend: (() => void) | null;\n}\n\ntype SpeechRecognitionConstructor = new () => SpeechRecognitionInstance;\n\n/**\n * BCP-47 tag for the recogniser, per app locale. Regional choices follow where\n * HealthyBowl actually operates (India for ta/hi) rather than a generic tag,\n * because the recogniser's acoustic model is region-specific.\n */\nconst RECOGNITION_LANG: Record<Locale, string> = {\n en: 'en-US',\n es: 'es-ES',\n fr: 'fr-FR',\n de: 'de-DE',\n ja: 'ja-JP',\n zh: 'zh-CN',\n ta: 'ta-IN',\n hi: 'hi-IN',\n ar: 'ar-SA',\n};\n\nfunction getSpeechRecognitionConstructor(): SpeechRecognitionConstructor | null {\n if (typeof window === 'undefined') return null;\n const win = window as unknown as Record<string, unknown>;\n return (\n (win.SpeechRecognition as SpeechRecognitionConstructor | undefined) ??\n (win.webkitSpeechRecognition as SpeechRecognitionConstructor | undefined) ??\n null\n );\n}\n\nexport type VoiceInputError =\n 'not-allowed' | 'no-speech' | 'audio-capture' | 'network' | 'language-not-supported' | 'unknown';\n\n/**\n * Map the spec's `SpeechRecognitionErrorEvent.error` codes onto the cases the UI\n * actually distinguishes. Anything else is 'unknown' (generic copy).\n *\n * `language-not-supported` is called out separately because it is the single\n * most likely failure for the users this feature exists for: the recogniser's\n * language list belongs to the browser vendor, not to us, so a Tamil or Hindi\n * speaker can hit it on a browser that simply does not offer their language.\n * Folding it into 'unknown' produced \"Dictation stopped unexpectedly\", which\n * tells them nothing and reads like a bug in HealthyBowl.\n */\nfunction toVoiceInputError(code: string): VoiceInputError {\n switch (code) {\n case 'not-allowed':\n case 'service-not-allowed':\n return 'not-allowed';\n case 'no-speech':\n return 'no-speech';\n case 'audio-capture':\n return 'audio-capture';\n case 'network':\n return 'network';\n case 'language-not-supported':\n return 'language-not-supported';\n default:\n return 'unknown';\n }\n}\n\nexport interface UseVoiceInputOptions {\n /**\n * Called with each newly finalised phrase. The composer appends it to the\n * draft; keeping the committed text in the caller (rather than accumulating\n * here) means the user can freely edit while dictation continues.\n */\n onFinalize: (text: string) => void;\n /**\n * BCP-47 tag to listen for. Omit to follow the app locale, which is what this\n * hook did unconditionally before (BOFF-7108).\n *\n * The two are genuinely independent: a farmer whose interface is English may\n * well speak Tamil, and deriving the recogniser language from the UI meant the\n * only way to dictate Tamil was to translate the entire app.\n */\n language?: string;\n}\n\nexport interface UseVoiceInputResult {\n isSupported: boolean;\n isListening: boolean;\n /** Words recognised but not yet finalised — render as a live hint. */\n interim: string;\n error: VoiceInputError | null;\n /**\n * BCP-47 tag the recogniser was asked for. Exposed so error copy can name the\n * language that failed (\"Tamil dictation is not supported…\") rather than\n * leaving the user to guess which language the browser rejected.\n */\n language: string;\n start: () => void;\n stop: () => void;\n /** Start if idle, stop if listening — what the mic button binds to. */\n toggle: () => void;\n clearError: () => void;\n}\n\nexport function useVoiceInput({ onFinalize, language: requested }: UseVoiceInputOptions): UseVoiceInputResult {\n const { locale } = useI18n();\n const [isListening, setIsListening] = useState(false);\n const [interim, setInterim] = useState('');\n const [error, setError] = useState<VoiceInputError | null>(null);\n const recognitionRef = useRef<SpeechRecognitionInstance | null>(null);\n // Incremented on every stop. Handlers capture the session they were created\n // under and ignore events that arrive after it ends.\n const sessionRef = useRef(0);\n\n // Keep the newest callback reachable from the recogniser's long-lived event\n // handlers without re-creating the recogniser on every parent render.\n const onFinalizeRef = useRef(onFinalize);\n useEffect(() => {\n onFinalizeRef.current = onFinalize;\n }, [onFinalize]);\n\n const isSupported = getSpeechRecognitionConstructor() !== null;\n const language = requested ?? RECOGNITION_LANG[locale] ?? 'en-US';\n\n // Abort (not stop) on unmount: the panel is closing, so a trailing final\n // result would be committed into a draft nobody can see.\n useEffect(() => {\n return () => {\n recognitionRef.current?.abort();\n recognitionRef.current = null;\n };\n }, []);\n\n const start = useCallback(() => {\n const Ctor = getSpeechRecognitionConstructor();\n if (!Ctor || recognitionRef.current) return;\n\n const recognition = new Ctor();\n recognition.continuous = true;\n recognition.interimResults = true;\n recognition.lang = language;\n\n const session = sessionRef.current;\n\n recognition.onresult = (event) => {\n if (session !== sessionRef.current) return;\n let finalText = '';\n let interimText = '';\n for (let index = event.resultIndex; index < event.results.length; index += 1) {\n const result = event.results[index];\n const alternative = result[0]?.transcript ?? '';\n if (result.isFinal) {\n finalText += alternative;\n } else {\n interimText += alternative;\n }\n }\n if (finalText.trim()) onFinalizeRef.current(finalText.trim());\n setInterim(interimText.trim());\n };\n\n recognition.onerror = (event) => {\n if (session !== sessionRef.current) return;\n const mapped = toVoiceInputError(event.error);\n // 'no-speech' fires routinely during a natural pause and the recogniser\n // keeps running — surfacing it would flash a scary message mid-sentence.\n if (mapped !== 'no-speech') setError(mapped);\n };\n\n recognition.onend = () => {\n if (session !== sessionRef.current) return;\n recognitionRef.current = null;\n setIsListening(false);\n setInterim('');\n };\n\n try {\n recognition.start();\n } catch {\n // start() throws if a recogniser is somehow already running — treat the\n // session as not started rather than leaving the button stuck \"live\".\n recognitionRef.current = null;\n setIsListening(false);\n return;\n }\n\n recognitionRef.current = recognition;\n setError(null);\n setInterim('');\n setIsListening(true);\n }, [language]);\n\n const stop = useCallback(() => {\n // Detach BEFORE stopping. `onend` is what used to clear this ref, but it\n // arrives asynchronously — so a user who tapped stop and immediately tapped\n // the mic again hit `start()`'s `if (recognitionRef.current) return` guard\n // and got a silent no-op. Bumping the session also makes any trailing final\n // phrase the engine flushes on stop land on a dead session, instead of\n // reappearing in a draft the composer has already sent and cleared.\n const recognition = recognitionRef.current;\n recognitionRef.current = null;\n sessionRef.current += 1;\n recognition?.stop();\n setIsListening(false);\n setInterim('');\n }, []);\n\n // Changing language must END the session it no longer describes.\n //\n // A running recogniser keeps the `lang` it was constructed with, so after a\n // switch the in-flight session is still listening in the OLD language while\n // this hook already reports the new one. A late `language-not-supported` from\n // that session would then be rendered as though the browser had rejected the\n // language the user just picked. Clearing the error is not enough — the\n // session producing it has to go too.\n const languageRef = useRef(language);\n useEffect(() => {\n if (languageRef.current === language) return;\n languageRef.current = language;\n stop();\n setError(null);\n }, [language, stop]);\n\n const toggle = useCallback(() => {\n if (isListening) stop();\n else start();\n }, [isListening, start, stop]);\n\n const clearError = useCallback(() => setError(null), []);\n\n return { isSupported, isListening, interim, error, language, start, stop, toggle, clearError };\n}\n"],"mappings":";;;AAmEA,IAAM,IAA2C;CAC/C,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;AACN;AAEA,SAAS,IAAuE;CAC9E,IAAI,OAAO,SAAW,KAAa,OAAO;CAC1C,IAAM,IAAM;CACZ,OACG,EAAI,qBACJ,EAAI,2BACL;AAEJ;AAgBA,SAAS,EAAkB,GAA+B;CACxD,QAAQ,GAAR;EACE,KAAK;EACL,KAAK,uBACH,OAAO;EACT,KAAK,aACH,OAAO;EACT,KAAK,iBACH,OAAO;EACT,KAAK,WACH,OAAO;EACT,KAAK,0BACH,OAAO;EACT,SACE,OAAO;CACX;AACF;AAuCA,SAAgB,EAAc,EAAE,eAAY,UAAU,KAAwD;CAC5G,IAAM,EAAE,cAAW,EAAQ,GACrB,CAAC,GAAa,KAAkB,EAAS,EAAK,GAC9C,CAAC,GAAS,KAAc,EAAS,EAAE,GACnC,CAAC,GAAO,KAAY,EAAiC,IAAI,GACzD,IAAiB,EAA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GACb,EAAW,EAAE,GACb,EAAe,EAAI;CACrB,GAAG,CAAC,CAAQ,CAAC,GAEP,IAAO,QAAkB;EAO7B,IAAM,IAAc,EAAe;EAKnC,AAJA,EAAe,UAAU,MACzB,EAAW,WAAW,GACtB,GAAa,KAAK,GAClB,EAAe,EAAK,GACpB,EAAW,EAAE;CACf,GAAG,CAAC,CAAC,GAUC,IAAc,EAAO,CAAQ;CAenC,OAdA,QAAgB;EACV,EAAY,YAAY,MAC5B,EAAY,UAAU,GACtB,EAAK,GACL,EAAS,IAAI;CACf,GAAG,CAAC,GAAU,CAAI,CAAC,GASZ;EAAE;EAAa;EAAa;EAAS;EAAO;EAAU;EAAO;EAAM,QAP3D,QAAkB;GAC/B,AAAI,IAAa,EAAK,IACjB,EAAM;EACb,GAAG;GAAC;GAAa;GAAO;EAAI,CAI8C;EAAQ,YAF/D,QAAkB,EAAS,IAAI,GAAG,CAAC,CAE4B;CAAW;AAC/F"}
1
+ {"version":3,"file":"useVoiceInput.js","names":[],"sources":["../../src/hooks/useVoiceInput.ts"],"sourcesContent":["/**\n * Speech-to-text for the assistant composer (Workstream 2 of the AI Assistant\n * V2 multimodal effort).\n *\n * Input-only, browser-native (Web Speech API). It degrades gracefully:\n * `isSupported` is false on engines without SpeechRecognition (notably Firefox),\n * and the composer hides the mic entirely in that case rather than showing a\n * dead control.\n *\n * ⚠️ This does NOT mean the audio stays on the device. Chrome's\n * `webkitSpeechRecognition` is a NETWORK service — the audio is streamed to the\n * browser vendor for recognition, and the supported language list is theirs, not\n * ours. We neither receive nor store it, which is all an earlier version of this\n * comment (\"no audio ever leaves the device through us\") actually claimed; read\n * literally it implied something stronger and untrue. Whether recording farmers'\n * speech this way needs disclosure or consent is a product/legal call, not a\n * code one.\n *\n * Output (reading replies aloud) is a separate concern and lives in\n * `AssistantSpeechProvider`; an earlier version of this note said the assistant\n * does not speak, which stopped being true when BOFF-6290 shipped.\n *\n * Differences from the fe-libs `assistantWidget/useVoiceInput` this is modelled\n * on, all of which the composer needs:\n * - **interim results are exposed**, so the user sees words appear while\n * speaking instead of staring at a silent button until a phrase finalises;\n * - **errors are surfaced** (`error`) so a denied mic permission can be\n * explained rather than looking like a no-op;\n * - **the recogniser language follows the app locale** (a Tamil or Hindi\n * farmer dictating into an `en-US` recogniser gets garbage);\n * - **`stop()` resolves the final transcript** through `onFinalize`, so the\n * composer can commit exactly once when the user stops.\n */\n\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';\nimport type { Locale } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';\n\ninterface SpeechRecognitionEventLike extends Event {\n results: SpeechRecognitionResultList;\n resultIndex: number;\n}\n\ninterface SpeechRecognitionErrorEventLike extends Event {\n error: string;\n message: string;\n}\n\ninterface SpeechRecognitionInstance extends EventTarget {\n continuous: boolean;\n interimResults: boolean;\n lang: string;\n start(): void;\n stop(): void;\n abort(): void;\n onresult: ((event: SpeechRecognitionEventLike) => void) | null;\n onerror: ((event: SpeechRecognitionErrorEventLike) => void) | null;\n onend: (() => void) | null;\n /**\n * Fires when the service has actually begun listening — the only honest\n * \"capture has started\" signal. Absent from this declaration until now, which\n * is part of why capture was inferred from `start()` returning instead.\n */\n onstart: (() => void) | null;\n}\n\ntype SpeechRecognitionConstructor = new () => SpeechRecognitionInstance;\n\n/**\n * BCP-47 tag for the recogniser, per app locale. Regional choices follow where\n * HealthyBowl actually operates (India for ta/hi) rather than a generic tag,\n * because the recogniser's acoustic model is region-specific.\n */\nconst RECOGNITION_LANG: Record<Locale, string> = {\n en: 'en-US',\n es: 'es-ES',\n fr: 'fr-FR',\n de: 'de-DE',\n ja: 'ja-JP',\n zh: 'zh-CN',\n ta: 'ta-IN',\n hi: 'hi-IN',\n ar: 'ar-SA',\n};\n\nfunction getSpeechRecognitionConstructor(): SpeechRecognitionConstructor | null {\n if (typeof window === 'undefined') return null;\n const win = window as unknown as Record<string, unknown>;\n return (\n (win.SpeechRecognition as SpeechRecognitionConstructor | undefined) ??\n (win.webkitSpeechRecognition as SpeechRecognitionConstructor | undefined) ??\n null\n );\n}\n\nexport type VoiceInputError =\n 'not-allowed' | 'no-speech' | 'audio-capture' | 'network' | 'language-not-supported' | 'unknown';\n\n/**\n * Map the spec's `SpeechRecognitionErrorEvent.error` codes onto the cases the UI\n * actually distinguishes. Anything else is 'unknown' (generic copy).\n *\n * `language-not-supported` is called out separately because it is the single\n * most likely failure for the users this feature exists for: the recogniser's\n * language list belongs to the browser vendor, not to us, so a Tamil or Hindi\n * speaker can hit it on a browser that simply does not offer their language.\n * Folding it into 'unknown' produced \"Dictation stopped unexpectedly\", which\n * tells them nothing and reads like a bug in HealthyBowl.\n */\nfunction toVoiceInputError(code: string): VoiceInputError {\n switch (code) {\n case 'not-allowed':\n case 'service-not-allowed':\n return 'not-allowed';\n case 'no-speech':\n return 'no-speech';\n case 'audio-capture':\n return 'audio-capture';\n case 'network':\n return 'network';\n case 'language-not-supported':\n return 'language-not-supported';\n default:\n return 'unknown';\n }\n}\n\nexport interface UseVoiceInputOptions {\n /**\n * Called with each newly finalised phrase. The composer appends it to the\n * draft; keeping the committed text in the caller (rather than accumulating\n * here) means the user can freely edit while dictation continues.\n */\n onFinalize: (text: string) => void;\n /**\n * BCP-47 tag to listen for. Omit to follow the app locale, which is what this\n * hook did unconditionally before (BOFF-7108).\n *\n * The two are genuinely independent: a farmer whose interface is English may\n * well speak Tamil, and deriving the recogniser language from the UI meant the\n * only way to dictate Tamil was to translate the entire app.\n */\n language?: string;\n}\n\nexport interface UseVoiceInputResult {\n isSupported: boolean;\n isListening: boolean;\n /** Words recognised but not yet finalised — render as a live hint. */\n interim: string;\n error: VoiceInputError | null;\n /**\n * BCP-47 tag the recogniser was asked for. Exposed so error copy can name the\n * language that failed (\"Tamil dictation is not supported…\") rather than\n * leaving the user to guess which language the browser rejected.\n */\n language: string;\n start: () => void;\n stop: () => void;\n /** Start if idle, stop if listening — what the mic button binds to. */\n toggle: () => void;\n clearError: () => void;\n}\n\nexport function useVoiceInput({ onFinalize, language: requested }: UseVoiceInputOptions): UseVoiceInputResult {\n const { locale } = useI18n();\n const [isListening, setIsListening] = useState(false);\n const [interim, setInterim] = useState('');\n const [error, setError] = useState<VoiceInputError | null>(null);\n const recognitionRef = useRef<SpeechRecognitionInstance | null>(null);\n // Incremented on every stop. Handlers capture the session they were created\n // under and ignore events that arrive after it ends.\n const sessionRef = useRef(0);\n\n // Keep the newest callback reachable from the recogniser's long-lived event\n // handlers without re-creating the recogniser on every parent render.\n const onFinalizeRef = useRef(onFinalize);\n useEffect(() => {\n onFinalizeRef.current = onFinalize;\n }, [onFinalize]);\n\n const isSupported = getSpeechRecognitionConstructor() !== null;\n const language = requested ?? RECOGNITION_LANG[locale] ?? 'en-US';\n\n // Abort (not stop) on unmount: the panel is closing, so a trailing final\n // result would be committed into a draft nobody can see.\n useEffect(() => {\n return () => {\n recognitionRef.current?.abort();\n recognitionRef.current = null;\n };\n }, []);\n\n const start = useCallback(() => {\n const Ctor = getSpeechRecognitionConstructor();\n if (!Ctor || recognitionRef.current) return;\n\n const recognition = new Ctor();\n recognition.continuous = true;\n recognition.interimResults = true;\n recognition.lang = language;\n\n const session = sessionRef.current;\n\n recognition.onresult = (event) => {\n if (session !== sessionRef.current) return;\n let finalText = '';\n let interimText = '';\n for (let index = event.resultIndex; index < event.results.length; index += 1) {\n const result = event.results[index];\n const alternative = result[0]?.transcript ?? '';\n if (result.isFinal) {\n finalText += alternative;\n } else {\n interimText += alternative;\n }\n }\n if (finalText.trim()) onFinalizeRef.current(finalText.trim());\n setInterim(interimText.trim());\n };\n\n recognition.onerror = (event) => {\n if (session !== sessionRef.current) return;\n const mapped = toVoiceInputError(event.error);\n // 'no-speech' fires routinely during a natural pause and the recogniser\n // keeps running — surfacing it would flash a scary message mid-sentence.\n if (mapped !== 'no-speech') setError(mapped);\n };\n\n recognition.onend = () => {\n if (session !== sessionRef.current) return;\n recognitionRef.current = null;\n setIsListening(false);\n setInterim('');\n };\n\n /**\n * ★ The TRUE capture signal.\n *\n * This was set optimistically on the line after `start()` returned — which\n * is synchronous, and says only that the request was accepted, not that the\n * microphone is open. Everything downstream then believed capture had begun\n * while the permission prompt was still up: the stage showed \"Listening…\"\n * over a microphone that could not yet hear, so a user who started talking\n * immediately lost the first word or two; the `connecting` stage lasted a\n * single commit; and the 5s \"we aren't hearing your microphone\" notice\n * could never fire, because `capturing` was already true.\n */\n recognition.onstart = () => {\n if (session !== sessionRef.current) return;\n setIsListening(true);\n };\n\n try {\n recognition.start();\n } catch {\n // start() throws if a recogniser is somehow already running — treat the\n // session as not started rather than leaving the button stuck \"live\".\n recognitionRef.current = null;\n setIsListening(false);\n return;\n }\n\n recognitionRef.current = recognition;\n setError(null);\n setInterim('');\n }, [language]);\n\n const stop = useCallback(() => {\n // Detach BEFORE stopping. `onend` is what used to clear this ref, but it\n // arrives asynchronously — so a user who tapped stop and immediately tapped\n // the mic again hit `start()`'s `if (recognitionRef.current) return` guard\n // and got a silent no-op. Bumping the session also makes any trailing final\n // phrase the engine flushes on stop land on a dead session, instead of\n // reappearing in a draft the composer has already sent and cleared.\n const recognition = recognitionRef.current;\n recognitionRef.current = null;\n sessionRef.current += 1;\n recognition?.stop();\n setIsListening(false);\n setInterim('');\n }, []);\n\n // Changing language must END the session it no longer describes.\n //\n // A running recogniser keeps the `lang` it was constructed with, so after a\n // switch the in-flight session is still listening in the OLD language while\n // this hook already reports the new one. A late `language-not-supported` from\n // that session would then be rendered as though the browser had rejected the\n // language the user just picked. Clearing the error is not enough — the\n // session producing it has to go too.\n const languageRef = useRef(language);\n useEffect(() => {\n if (languageRef.current === language) return;\n languageRef.current = language;\n stop();\n setError(null);\n }, [language, stop]);\n\n const toggle = useCallback(() => {\n if (isListening) stop();\n else start();\n }, [isListening, start, stop]);\n\n const clearError = useCallback(() => setError(null), []);\n\n return { isSupported, isListening, interim, error, language, start, stop, toggle, clearError };\n}\n"],"mappings":";;;AAyEA,IAA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B,EAAS,IAAI,GAAG,CAAC,CAE4B;CAAW;AAC/F"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@burdenoff/microfe-healthybowl",
3
- "version": "2026.901.16",
3
+ "version": "2026.902.1",
4
4
  "description": "Burdenoff HealthyBowl Microfrontend - Comprehensive organic farming and agro-foods management platform",
5
5
  "type": "module",
6
6
  "files": [