@celljs/ta-web 4.9.1 → 4.10.0

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.
Files changed (302) hide show
  1. package/README.en.md +4 -3
  2. package/README.md +4 -3
  3. package/esm/browser/assistant/assistant-chat-list.js +8 -2
  4. package/esm/browser/assistant/assistant-extension.d.ts +8 -1
  5. package/esm/browser/assistant/assistant-extension.js +20 -0
  6. package/esm/browser/assistant/assistant-protocol.d.ts +3 -1
  7. package/esm/browser/assistant/assistant-task-util.d.ts +2 -0
  8. package/esm/browser/assistant/assistant-task-util.js +5 -3
  9. package/esm/browser/assistant/assistant-view.js +81 -56
  10. package/esm/browser/assistant/assistant.d.ts +10 -1
  11. package/esm/browser/assistant/assistant.js +44 -5
  12. package/esm/browser/chat/chat-packages.d.ts +39 -0
  13. package/esm/browser/chat/chat-packages.js +70 -0
  14. package/esm/browser/chat/chat-protocol.d.ts +23 -1
  15. package/esm/browser/chat/chat-stores.d.ts +59 -0
  16. package/esm/browser/chat/chat-stores.js +121 -0
  17. package/esm/browser/chat/chat-util.d.ts +17 -0
  18. package/esm/browser/chat/chat-util.js +61 -0
  19. package/esm/browser/chat/chat-view.js +33 -12
  20. package/esm/browser/chat/chat.d.ts +31 -39
  21. package/esm/browser/chat/chat.js +226 -175
  22. package/esm/browser/components/app-nav.d.ts +6 -3
  23. package/esm/browser/components/app-nav.js +19 -10
  24. package/esm/browser/components/app-shell-hooks.d.ts +2 -2
  25. package/esm/browser/components/app-shell-hooks.js +7 -3
  26. package/esm/browser/components/app-view.js +75 -21
  27. package/esm/browser/components/chat-list.d.ts +20 -2
  28. package/esm/browser/components/chat-list.js +138 -22
  29. package/esm/browser/components/composer-box.d.ts +5 -5
  30. package/esm/browser/components/composer-box.js +111 -4
  31. package/esm/browser/components/composer.d.ts +7 -0
  32. package/esm/browser/components/composer.js +5 -4
  33. package/esm/browser/components/connection-bar.js +50 -17
  34. package/esm/browser/components/context-menu.d.ts +30 -4
  35. package/esm/browser/components/context-menu.js +199 -37
  36. package/esm/browser/components/conversation-scroll.d.ts +129 -6
  37. package/esm/browser/components/conversation-scroll.js +429 -109
  38. package/esm/browser/components/earlier-messages.d.ts +2 -1
  39. package/esm/browser/components/earlier-messages.js +2 -17
  40. package/esm/browser/components/editor-area.d.ts +3 -1
  41. package/esm/browser/components/editor-area.js +6 -5
  42. package/esm/browser/components/empty-pictures.d.ts +0 -2
  43. package/esm/browser/components/empty-pictures.js +0 -16
  44. package/esm/browser/components/folder-picker.d.ts +5 -2
  45. package/esm/browser/components/folder-picker.js +26 -8
  46. package/esm/browser/components/held-talk.d.ts +28 -0
  47. package/esm/browser/components/held-talk.js +76 -0
  48. package/esm/browser/components/host-view.d.ts +1 -1
  49. package/esm/browser/components/icon.d.ts +2 -2
  50. package/esm/browser/components/icon.js +5 -6
  51. package/esm/browser/components/image-viewer.d.ts +124 -0
  52. package/esm/browser/components/image-viewer.js +397 -0
  53. package/esm/browser/components/lightbox.d.ts +11 -0
  54. package/esm/browser/components/lightbox.js +24 -0
  55. package/esm/browser/components/markdown.d.ts +6 -2
  56. package/esm/browser/components/markdown.js +24 -10
  57. package/esm/browser/components/media.js +1 -10
  58. package/esm/browser/components/message-footer.d.ts +16 -2
  59. package/esm/browser/components/message-footer.js +29 -12
  60. package/esm/browser/components/message-list.d.ts +24 -3
  61. package/esm/browser/components/message-list.js +149 -20
  62. package/esm/browser/components/message-menu.d.ts +3 -1
  63. package/esm/browser/components/message-menu.js +18 -3
  64. package/esm/browser/components/nav-places.d.ts +16 -1
  65. package/esm/browser/components/nav-places.js +12 -3
  66. package/esm/browser/components/phone-shell.d.ts +4 -1
  67. package/esm/browser/components/phone-shell.js +3 -1
  68. package/esm/browser/components/run-status.js +3 -3
  69. package/esm/browser/components/session-settings.d.ts +6 -0
  70. package/esm/browser/components/session-settings.js +14 -1
  71. package/esm/browser/components/session-view.js +8 -4
  72. package/esm/browser/components/settings-parts.d.ts +2 -2
  73. package/esm/browser/components/settings-parts.js +24 -1
  74. package/esm/browser/components/swipe-row.d.ts +2 -2
  75. package/esm/browser/components/swipe-row.js +7 -3
  76. package/esm/browser/components/tool-view.js +14 -12
  77. package/esm/browser/components/voice-button.d.ts +1 -1
  78. package/esm/browser/components/voice-button.js +1 -1
  79. package/esm/browser/components/voice-talk.d.ts +43 -0
  80. package/esm/browser/components/voice-talk.js +222 -0
  81. package/esm/browser/device/device.d.ts +3 -0
  82. package/esm/browser/device/device.js +11 -1
  83. package/esm/browser/device/hold.d.ts +42 -0
  84. package/esm/browser/device/hold.js +136 -0
  85. package/esm/browser/device/launch-screen.d.ts +1 -1
  86. package/esm/browser/device/launch-screen.js +1 -1
  87. package/esm/browser/device/long-press.d.ts +2 -0
  88. package/esm/browser/device/long-press.js +16 -1
  89. package/esm/browser/device/pull-down.d.ts +4 -2
  90. package/esm/browser/device/pull-down.js +64 -76
  91. package/esm/browser/device/row-swipe.d.ts +35 -10
  92. package/esm/browser/device/row-swipe.js +149 -71
  93. package/esm/browser/device/shake-undo.d.ts +16 -0
  94. package/esm/browser/device/shake-undo.js +59 -0
  95. package/esm/browser/device/sheet-swipe.d.ts +118 -18
  96. package/esm/browser/device/sheet-swipe.js +406 -107
  97. package/esm/browser/extension/web-extension-api.d.ts +97 -1
  98. package/esm/browser/extension/web-extension-code.d.ts +6 -0
  99. package/esm/browser/extension/web-extension-code.js +24 -0
  100. package/esm/browser/extension/web-extension-protocol.d.ts +23 -1
  101. package/esm/browser/extension/web-extension-protocol.js +8 -0
  102. package/esm/browser/extension/web-extensions.d.ts +14 -1
  103. package/esm/browser/extension/web-extensions.js +122 -23
  104. package/esm/browser/files/files-protocol.d.ts +25 -0
  105. package/esm/browser/files/files-protocol.js +2 -0
  106. package/esm/browser/files/files.d.ts +35 -0
  107. package/esm/browser/files/files.js +119 -0
  108. package/esm/browser/i18n/locales.d.ts +24 -2
  109. package/esm/browser/i18n/messages.d.ts +23 -1
  110. package/esm/browser/i18n/messages.js +48 -4
  111. package/esm/browser/index.d.ts +6 -0
  112. package/esm/browser/index.js +6 -0
  113. package/esm/browser/notices/notices-protocol.d.ts +9 -1
  114. package/esm/browser/notices/notices.d.ts +2 -0
  115. package/esm/browser/notices/notices.js +20 -10
  116. package/esm/browser/offline/device-values.d.ts +55 -0
  117. package/esm/browser/offline/device-values.js +142 -0
  118. package/esm/browser/offline/kept-chats-protocol.d.ts +17 -0
  119. package/esm/browser/offline/kept-chats-protocol.js +2 -0
  120. package/esm/browser/offline/kept-chats.d.ts +47 -0
  121. package/esm/browser/offline/kept-chats.js +146 -0
  122. package/esm/browser/offline/offline-reads.d.ts +44 -0
  123. package/esm/browser/offline/offline-reads.js +107 -0
  124. package/esm/browser/settings/settings-protocol.d.ts +2 -0
  125. package/esm/browser/settings/settings-protocol.js +2 -0
  126. package/esm/browser/style/conversation.d.ts +1 -1
  127. package/esm/browser/style/conversation.js +57 -17
  128. package/esm/browser/style/device.js +27 -4
  129. package/esm/browser/style/layout.d.ts +1 -1
  130. package/esm/browser/style/layout.js +67 -15
  131. package/esm/browser/style/pages.d.ts +1 -1
  132. package/esm/browser/style/pages.js +2 -1
  133. package/esm/browser/style/shell.d.ts +1 -1
  134. package/esm/browser/style/shell.js +46 -3
  135. package/esm/browser/util/frame.d.ts +5 -4
  136. package/esm/browser/util/frame.js +5 -4
  137. package/esm/browser/util/markdown.d.ts +18 -1
  138. package/esm/browser/util/markdown.js +119 -5
  139. package/esm/browser/util/process.d.ts +21 -0
  140. package/esm/browser/util/process.js +45 -1
  141. package/esm/browser/util/voice.d.ts +5 -2
  142. package/esm/browser/util/voice.js +6 -3
  143. package/esm/browser/util/zoom.d.ts +46 -0
  144. package/esm/browser/util/zoom.js +96 -0
  145. package/esm/browser/workbench-calls.d.ts +59 -0
  146. package/esm/browser/workbench-calls.js +141 -0
  147. package/esm/browser/workbench-protocol.d.ts +5 -1
  148. package/esm/browser/workbench-util.d.ts +7 -0
  149. package/esm/browser/workbench-util.js +9 -2
  150. package/esm/browser/workbench.d.ts +14 -5
  151. package/esm/browser/workbench.js +51 -31
  152. package/lib/browser/assistant/assistant-chat-list.js +8 -2
  153. package/lib/browser/assistant/assistant-extension.d.ts +8 -1
  154. package/lib/browser/assistant/assistant-extension.js +20 -0
  155. package/lib/browser/assistant/assistant-protocol.d.ts +3 -1
  156. package/lib/browser/assistant/assistant-task-util.d.ts +2 -0
  157. package/lib/browser/assistant/assistant-task-util.js +5 -3
  158. package/lib/browser/assistant/assistant-view.js +78 -53
  159. package/lib/browser/assistant/assistant.d.ts +10 -1
  160. package/lib/browser/assistant/assistant.js +44 -5
  161. package/lib/browser/chat/chat-packages.d.ts +40 -0
  162. package/lib/browser/chat/chat-packages.js +74 -0
  163. package/lib/browser/chat/chat-protocol.d.ts +23 -1
  164. package/lib/browser/chat/chat-stores.d.ts +60 -0
  165. package/lib/browser/chat/chat-stores.js +125 -0
  166. package/lib/browser/chat/chat-util.d.ts +18 -0
  167. package/lib/browser/chat/chat-util.js +64 -0
  168. package/lib/browser/chat/chat-view.js +33 -12
  169. package/lib/browser/chat/chat.d.ts +31 -39
  170. package/lib/browser/chat/chat.js +227 -176
  171. package/lib/browser/components/app-nav.d.ts +6 -3
  172. package/lib/browser/components/app-nav.js +17 -8
  173. package/lib/browser/components/app-shell-hooks.d.ts +2 -2
  174. package/lib/browser/components/app-shell-hooks.js +7 -3
  175. package/lib/browser/components/app-view.js +74 -20
  176. package/lib/browser/components/chat-list.d.ts +20 -2
  177. package/lib/browser/components/chat-list.js +137 -21
  178. package/lib/browser/components/composer-box.d.ts +5 -5
  179. package/lib/browser/components/composer-box.js +111 -4
  180. package/lib/browser/components/composer.d.ts +7 -0
  181. package/lib/browser/components/composer.js +5 -4
  182. package/lib/browser/components/connection-bar.js +48 -15
  183. package/lib/browser/components/context-menu.d.ts +30 -4
  184. package/lib/browser/components/context-menu.js +198 -36
  185. package/lib/browser/components/conversation-scroll.d.ts +129 -6
  186. package/lib/browser/components/conversation-scroll.js +431 -110
  187. package/lib/browser/components/earlier-messages.d.ts +2 -1
  188. package/lib/browser/components/earlier-messages.js +2 -17
  189. package/lib/browser/components/editor-area.d.ts +3 -1
  190. package/lib/browser/components/editor-area.js +5 -4
  191. package/lib/browser/components/empty-pictures.d.ts +0 -2
  192. package/lib/browser/components/empty-pictures.js +0 -17
  193. package/lib/browser/components/folder-picker.d.ts +5 -2
  194. package/lib/browser/components/folder-picker.js +26 -8
  195. package/lib/browser/components/held-talk.d.ts +29 -0
  196. package/lib/browser/components/held-talk.js +79 -0
  197. package/lib/browser/components/host-view.d.ts +1 -1
  198. package/lib/browser/components/icon.d.ts +2 -2
  199. package/lib/browser/components/icon.js +7 -6
  200. package/lib/browser/components/image-viewer.d.ts +125 -0
  201. package/lib/browser/components/image-viewer.js +435 -0
  202. package/lib/browser/components/lightbox.d.ts +12 -0
  203. package/lib/browser/components/lightbox.js +60 -0
  204. package/lib/browser/components/markdown.d.ts +6 -2
  205. package/lib/browser/components/markdown.js +24 -10
  206. package/lib/browser/components/media.js +2 -11
  207. package/lib/browser/components/message-footer.d.ts +16 -2
  208. package/lib/browser/components/message-footer.js +31 -12
  209. package/lib/browser/components/message-list.d.ts +24 -3
  210. package/lib/browser/components/message-list.js +146 -16
  211. package/lib/browser/components/message-menu.d.ts +3 -1
  212. package/lib/browser/components/message-menu.js +17 -2
  213. package/lib/browser/components/nav-places.d.ts +16 -1
  214. package/lib/browser/components/nav-places.js +13 -3
  215. package/lib/browser/components/phone-shell.d.ts +4 -1
  216. package/lib/browser/components/phone-shell.js +3 -1
  217. package/lib/browser/components/run-status.js +3 -3
  218. package/lib/browser/components/session-settings.d.ts +6 -0
  219. package/lib/browser/components/session-settings.js +14 -1
  220. package/lib/browser/components/session-view.js +7 -3
  221. package/lib/browser/components/settings-parts.d.ts +2 -2
  222. package/lib/browser/components/settings-parts.js +24 -1
  223. package/lib/browser/components/swipe-row.d.ts +2 -2
  224. package/lib/browser/components/swipe-row.js +7 -3
  225. package/lib/browser/components/tool-view.js +14 -12
  226. package/lib/browser/components/voice-button.d.ts +1 -1
  227. package/lib/browser/components/voice-button.js +1 -1
  228. package/lib/browser/components/voice-talk.d.ts +44 -0
  229. package/lib/browser/components/voice-talk.js +260 -0
  230. package/lib/browser/device/device.d.ts +3 -0
  231. package/lib/browser/device/device.js +11 -1
  232. package/lib/browser/device/hold.d.ts +43 -0
  233. package/lib/browser/device/hold.js +173 -0
  234. package/lib/browser/device/launch-screen.d.ts +1 -1
  235. package/lib/browser/device/launch-screen.js +1 -1
  236. package/lib/browser/device/long-press.d.ts +2 -0
  237. package/lib/browser/device/long-press.js +16 -1
  238. package/lib/browser/device/pull-down.d.ts +4 -2
  239. package/lib/browser/device/pull-down.js +63 -75
  240. package/lib/browser/device/row-swipe.d.ts +35 -10
  241. package/lib/browser/device/row-swipe.js +148 -70
  242. package/lib/browser/device/shake-undo.d.ts +17 -0
  243. package/lib/browser/device/shake-undo.js +63 -0
  244. package/lib/browser/device/sheet-swipe.d.ts +118 -18
  245. package/lib/browser/device/sheet-swipe.js +410 -108
  246. package/lib/browser/extension/web-extension-api.d.ts +97 -1
  247. package/lib/browser/extension/web-extension-code.d.ts +6 -0
  248. package/lib/browser/extension/web-extension-code.js +24 -0
  249. package/lib/browser/extension/web-extension-protocol.d.ts +23 -1
  250. package/lib/browser/extension/web-extension-protocol.js +9 -1
  251. package/lib/browser/extension/web-extensions.d.ts +14 -1
  252. package/lib/browser/extension/web-extensions.js +120 -21
  253. package/lib/browser/files/files-protocol.d.ts +26 -0
  254. package/lib/browser/files/files-protocol.js +5 -0
  255. package/lib/browser/files/files.d.ts +36 -0
  256. package/lib/browser/files/files.js +122 -0
  257. package/lib/browser/i18n/locales.d.ts +24 -2
  258. package/lib/browser/i18n/messages.d.ts +23 -1
  259. package/lib/browser/i18n/messages.js +48 -4
  260. package/lib/browser/index.d.ts +6 -0
  261. package/lib/browser/index.js +6 -0
  262. package/lib/browser/notices/notices-protocol.d.ts +9 -1
  263. package/lib/browser/notices/notices.d.ts +2 -0
  264. package/lib/browser/notices/notices.js +20 -10
  265. package/lib/browser/offline/device-values.d.ts +56 -0
  266. package/lib/browser/offline/device-values.js +148 -0
  267. package/lib/browser/offline/kept-chats-protocol.d.ts +18 -0
  268. package/lib/browser/offline/kept-chats-protocol.js +5 -0
  269. package/lib/browser/offline/kept-chats.d.ts +48 -0
  270. package/lib/browser/offline/kept-chats.js +149 -0
  271. package/lib/browser/offline/offline-reads.d.ts +45 -0
  272. package/lib/browser/offline/offline-reads.js +111 -0
  273. package/lib/browser/settings/settings-protocol.d.ts +2 -0
  274. package/lib/browser/settings/settings-protocol.js +2 -0
  275. package/lib/browser/style/conversation.d.ts +1 -1
  276. package/lib/browser/style/conversation.js +57 -17
  277. package/lib/browser/style/device.js +27 -4
  278. package/lib/browser/style/layout.d.ts +1 -1
  279. package/lib/browser/style/layout.js +67 -15
  280. package/lib/browser/style/pages.d.ts +1 -1
  281. package/lib/browser/style/pages.js +2 -1
  282. package/lib/browser/style/shell.d.ts +1 -1
  283. package/lib/browser/style/shell.js +46 -3
  284. package/lib/browser/util/frame.d.ts +5 -4
  285. package/lib/browser/util/frame.js +5 -4
  286. package/lib/browser/util/markdown.d.ts +18 -1
  287. package/lib/browser/util/markdown.js +119 -5
  288. package/lib/browser/util/process.d.ts +21 -0
  289. package/lib/browser/util/process.js +46 -2
  290. package/lib/browser/util/voice.d.ts +5 -2
  291. package/lib/browser/util/voice.js +6 -3
  292. package/lib/browser/util/zoom.d.ts +47 -0
  293. package/lib/browser/util/zoom.js +99 -0
  294. package/lib/browser/workbench-calls.d.ts +60 -0
  295. package/lib/browser/workbench-calls.js +145 -0
  296. package/lib/browser/workbench-protocol.d.ts +5 -1
  297. package/lib/browser/workbench-util.d.ts +7 -0
  298. package/lib/browser/workbench-util.js +10 -3
  299. package/lib/browser/workbench.d.ts +14 -5
  300. package/lib/browser/workbench.js +51 -31
  301. package/package.json +10 -10
  302. package/public/launch.svg +46 -42
@@ -22,6 +22,12 @@ export interface SessionSettingsHandlers {
22
22
  }
23
23
  export declare namespace SessionSettingsUtil {
24
24
  const EMPTY: SessionSettings;
25
+ /**
26
+ * Whether the settings are loaded again: at once, a run going or not, so that a conversation opened
27
+ * while it works (a new one, the first message just sent) lists its models from the start, and after
28
+ * each run, which an extension or another client may have changed them in.
29
+ */
30
+ function reloads(wasWorking: boolean | undefined, working: boolean): boolean;
25
31
  function modelRef(model?: {
26
32
  provider: string;
27
33
  id: string;
@@ -42,6 +42,15 @@ const model_picker_1 = require("./model-picker");
42
42
  var SessionSettingsUtil;
43
43
  (function (SessionSettingsUtil) {
44
44
  SessionSettingsUtil.EMPTY = { models: [], levels: [], commands: [] };
45
+ /**
46
+ * Whether the settings are loaded again: at once, a run going or not, so that a conversation opened
47
+ * while it works (a new one, the first message just sent) lists its models from the start, and after
48
+ * each run, which an extension or another client may have changed them in.
49
+ */
50
+ function reloads(wasWorking, working) {
51
+ return wasWorking === undefined || (wasWorking && !working);
52
+ }
53
+ SessionSettingsUtil.reloads = reloads;
45
54
  function modelRef(model) {
46
55
  return model ? `${model.provider}/${model.id}` : '';
47
56
  }
@@ -110,10 +119,14 @@ function useSessionSettings(server, settingsServer, store, working, t, onError)
110
119
  .then(([state, { models }, { levels }, { commands }]) => setSettings({ models, model: SessionSettingsUtil.modelRef(state.model), thinkingLevel: state.thinkingLevel, levels, commands }))
111
120
  .catch(() => undefined);
112
121
  }, [server, sessionId]);
122
+ // Whether the session worked when it was last looked at; none for a session not looked at yet.
123
+ const last = React.useRef(undefined);
113
124
  React.useEffect(() => {
114
- if (!working) {
125
+ var _a;
126
+ if (SessionSettingsUtil.reloads(((_a = last.current) === null || _a === void 0 ? void 0 : _a.load) === load ? last.current.working : undefined, working)) {
115
127
  load();
116
128
  }
129
+ last.current = { load, working };
117
130
  }, [load, working]);
118
131
  React.useEffect(() => store.onEvent(event => {
119
132
  if (event.type === 'session_reloaded') {
@@ -34,9 +34,11 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.SessionView = SessionView;
37
+ const react_1 = require("@celljs/react");
37
38
  const lucide_react_1 = require("lucide-react");
38
39
  const React = __importStar(require("react"));
39
40
  const device_1 = require("../device/device");
41
+ const files_protocol_1 = require("../files/files-protocol");
40
42
  const hooks_1 = require("../hooks");
41
43
  const use_t_1 = require("../i18n/use-t");
42
44
  const message_1 = require("../util/message");
@@ -130,7 +132,8 @@ function SessionView({ store, server, workspace, info, onClosed, onActivity, lea
130
132
  (_a = composer.current) === null || _a === void 0 ? void 0 : _a.setText(draftText);
131
133
  }
132
134
  }, [draftText]);
133
- const fileUrl = React.useCallback((path) => workspace.fileUrl(path, cwd), [workspace, cwd]);
135
+ const files = (0, react_1.useInject)(files_protocol_1.TaFiles);
136
+ const fileUrl = React.useCallback(async (path) => files.loadable(await workspace.fileUrl(path, cwd)), [workspace, cwd, files]);
134
137
  const openLink = (0, hooks_1.useOpenLink)(cwd);
135
138
  // biome-ignore lint/correctness/useExhaustiveDependencies: runs when a run starts or settles
136
139
  React.useEffect(() => onActivity(), [state.working, onActivity]);
@@ -146,6 +149,7 @@ function SessionView({ store, server, workspace, info, onClosed, onActivity, lea
146
149
  const title = (info === null || info === void 0 ? void 0 : info.sessionName) || (info ? message_1.MessageUtil.basename(info.cwd) : t('ta.session.title'));
147
150
  const conversation = React.useMemo(() => ({ sessionId: store.sessionId, sessionFile: info === null || info === void 0 ? void 0 : info.sessionFile, cwd: info === null || info === void 0 ? void 0 : info.cwd, kind: 'chat', group: info === null || info === void 0 ? void 0 : info.group, title }), [store.sessionId, info === null || info === void 0 ? void 0 : info.sessionFile, info === null || info === void 0 ? void 0 : info.cwd, info === null || info === void 0 ? void 0 : info.group, title]);
148
151
  const addons = (0, composer_addons_1.useComposerAddons)(conversation);
152
+ const outbox = React.useMemo(() => ({ resend: id => void store.resend(id), discard: id => store.discard(id) }), [store]);
149
153
  return (React.createElement("section", { className: `ta-session ${compact ? 'ta-session-compact' : ''}` },
150
154
  !compact && (React.createElement("header", { className: "ta-session-header" },
151
155
  leading,
@@ -155,14 +159,14 @@ function SessionView({ store, server, workspace, info, onClosed, onActivity, lea
155
159
  trailing)),
156
160
  React.createElement("div", { className: "ta-scroll ta-conversation", ref: scroller },
157
161
  React.createElement("div", { className: "ta-thread" },
158
- state.start > 0 && (React.createElement("div", { className: "ta-earlier", role: "status", "aria-label": t('ta.session.earlier') },
162
+ state.start > 0 && (React.createElement("div", { className: "ta-earlier", role: "status", "aria-label": t('ta.session.earlier'), ...conversation_scroll_1.SCROLL_SKIP },
159
163
  React.createElement("span", { className: "ta-spinner" }))),
160
164
  state.messages.length === 0 && (empty !== null && empty !== void 0 ? empty : React.createElement("div", { className: "ta-empty" }, t('ta.session.empty', { cwd: (_a = info === null || info === void 0 ? void 0 : info.cwd) !== null && _a !== void 0 ? _a : '.' }))),
161
165
  React.createElement(message_list_1.ConversationSession.Provider, { value: info },
162
166
  React.createElement(message_footer_1.MessageActions.Provider, { value: messageActions },
163
167
  React.createElement(media_1.FileUrls.Provider, { value: fileUrl },
164
168
  React.createElement(link_1.OpenLink.Provider, { value: openLink },
165
- React.createElement(message_list_1.MessageList, { state: state }))))))),
169
+ React.createElement(message_list_1.MessageList, { state: state, outbox: outbox }))))))),
166
170
  React.createElement("div", { className: "ta-bottom" },
167
171
  away && (React.createElement("button", { type: "button", className: "ta-to-bottom", "aria-label": t('ta.session.toBottom'), title: t('ta.session.toBottom'), onClick: toBottom },
168
172
  React.createElement(lucide_react_1.ArrowDown, { size: 18 }))),
@@ -1,11 +1,11 @@
1
1
  import type { TaSettingsScope } from '@celljs/ta-protocol';
2
- import { type LucideIcon } from 'lucide-react';
3
2
  import * as React from 'react';
3
+ import { type Glyph } from './icon';
4
4
  import { type RowEntry } from './settings-controls';
5
5
  export interface SectionEntry {
6
6
  id: string;
7
7
  title: string;
8
- icon: LucideIcon;
8
+ icon: Glyph;
9
9
  rows: RowEntry[];
10
10
  }
11
11
  export interface Part {
@@ -37,6 +37,8 @@ exports.useParts = useParts;
37
37
  const lucide_react_1 = require("lucide-react");
38
38
  const React = __importStar(require("react"));
39
39
  const device_1 = require("../device/device");
40
+ const extension_view_1 = require("../extension/extension-view");
41
+ const web_extension_protocol_1 = require("../extension/web-extension-protocol");
40
42
  const hooks_1 = require("../hooks");
41
43
  const use_t_1 = require("../i18n/use-t");
42
44
  const agent_settings_1 = require("../settings/agent-settings");
@@ -61,7 +63,7 @@ function useParts(scope, onScope, onClose, onDialog) {
61
63
  const [{ settings }, store] = (0, hooks_1.useSettings)();
62
64
  const settingsServer = (0, hooks_1.useSettingsServer)();
63
65
  const [workbench, bench] = (0, hooks_1.useWorkbench)();
64
- const [{ extensions, cwd, views }, host] = (0, hooks_1.useWebExtensions)();
66
+ const [{ extensions, cwd, views, settingsSections }, host] = (0, hooks_1.useWebExtensions)();
65
67
  const navigation = (0, app_nav_1.useNavigation)(views);
66
68
  const packageList = (0, settings_choices_1.usePackages)();
67
69
  const builtinPackages = packageList.packages.filter(pkg => pkg.origin === 'builtin');
@@ -160,6 +162,8 @@ function useParts(scope, onScope, onClose, onDialog) {
160
162
  rows: [
161
163
  (0, settings_controls_1.row)('speak', [t('ta.settings.speak'), t('ta.settings.speakHint')], React.createElement(settings_controls_1.Row, { label: t('ta.settings.speak'), description: t('ta.settings.speakHint') },
162
164
  React.createElement(settings_controls_1.Switch, { label: t('ta.settings.speak'), checked: settings.speak, onChange: speak => store.update({ speak }) }))),
165
+ (0, settings_controls_1.row)('speakTalk', [t('ta.settings.speakTalk'), t('ta.settings.speakTalkHint')], React.createElement(settings_controls_1.Row, { label: t('ta.settings.speakTalk'), description: t('ta.settings.speakTalkHint') },
166
+ React.createElement(settings_controls_1.Switch, { label: t('ta.settings.speakTalk'), checked: settings.speakTalk, onChange: speakTalk => store.update({ speakTalk }) }))),
163
167
  ],
164
168
  },
165
169
  ];
@@ -239,6 +243,7 @@ function useParts(scope, onScope, onClose, onDialog) {
239
243
  }),
240
244
  ],
241
245
  },
246
+ ...settingsSections.map(extensionSection),
242
247
  // Behind a gateway only: where the Ta of this account runs.
243
248
  ...(gateway.info
244
249
  ? [
@@ -333,4 +338,22 @@ function useParts(scope, onScope, onClose, onDialog) {
333
338
  { id: 'more', title: t('ta.settings.more'), sections: more },
334
339
  ];
335
340
  }
341
+ /** A section an extension added (WebExtensionAPI.registerSettings): its rows as Ta's, each control in a boundary of its own. */
342
+ function extensionSection({ id, section }) {
343
+ var _a;
344
+ const title = web_extension_protocol_1.WebLabelUtil.text(section.title);
345
+ return {
346
+ id: `extension-${id.replace(/[^\w-]+/g, '-')}`,
347
+ title,
348
+ icon: (_a = section.icon) !== null && _a !== void 0 ? _a : lucide_react_1.Puzzle,
349
+ rows: section.rows.map(item => {
350
+ const label = web_extension_protocol_1.WebLabelUtil.text(item.label);
351
+ const description = item.description === undefined ? undefined : web_extension_protocol_1.WebLabelUtil.text(item.description);
352
+ const Control = item.render;
353
+ return (0, settings_controls_1.row)(`${id}/${item.key}`, [label, description, title], React.createElement(settings_controls_1.Row, { label: label, description: description, stacked: item.stacked },
354
+ React.createElement(extension_view_1.ExtensionBoundary, { name: title, resetKey: Control },
355
+ React.createElement(Control, null))));
356
+ }),
357
+ };
358
+ }
336
359
  //# sourceMappingURL=settings-parts.js.map
@@ -11,7 +11,7 @@ export interface SwipeRowProps extends WebSwipeRowProps, Omit<React.HTMLAttribut
11
11
  * list of the page and of web extensions (`ui.SwipeRow`) takes it, so that they swipe as one. Open, a tap on
12
12
  * it closes it rather than opening what it is.
13
13
  */
14
- export declare function SwipeRow({ as, actions, className, overlay, children, ...rest }: SwipeRowProps): React.DetailedReactHTMLElement<{
14
+ export declare function SwipeRow({ as, actions, className, overlay, children, style, ...rest }: SwipeRowProps): React.DetailedReactHTMLElement<{
15
15
  dangerouslySetInnerHTML?: {
16
16
  __html: string | TrustedHTML;
17
17
  } | undefined;
@@ -254,7 +254,6 @@ export declare function SwipeRow({ as, actions, className, overlay, children, ..
254
254
  nonce?: string | undefined;
255
255
  slot?: string | undefined;
256
256
  spellCheck?: ("false" | "true" | boolean) | undefined;
257
- style?: React.CSSProperties | undefined;
258
257
  tabIndex?: number | undefined;
259
258
  title?: string | undefined;
260
259
  translate?: "yes" | "no" | undefined;
@@ -294,5 +293,6 @@ export declare function SwipeRow({ as, actions, className, overlay, children, ..
294
293
  className: string;
295
294
  'data-swipeable': string | undefined;
296
295
  'data-swiped': string | undefined;
296
+ style: React.CSSProperties | undefined;
297
297
  }, HTMLElement>;
298
298
  //# sourceMappingURL=swipe-row.d.ts.map
@@ -44,7 +44,7 @@ const ACTION_PX = 84;
44
44
  * list of the page and of web extensions (`ui.SwipeRow`) takes it, so that they swipe as one. Open, a tap on
45
45
  * it closes it rather than opening what it is.
46
46
  */
47
- function SwipeRow({ as = 'div', actions, className, overlay, children, ...rest }) {
47
+ function SwipeRow({ as = 'div', actions, className, overlay, children, style, ...rest }) {
48
48
  var _a;
49
49
  const row = React.useRef(null);
50
50
  const handheld = (0, device_1.useDevice)(device => device.handheld);
@@ -62,9 +62,13 @@ function SwipeRow({ as = 'div', actions, className, overlay, children, ...rest }
62
62
  className: className ? `ta-swipe-row ${className}` : 'ta-swipe-row',
63
63
  'data-swipeable': enabled ? '' : undefined,
64
64
  'data-swiped': open ? '' : undefined,
65
- }, enabled && (React.createElement("div", { className: "ta-swipe-actions", inert: !open }, actions === null || actions === void 0 ? void 0 : actions.map(action => (React.createElement("button", { key: action.key, type: "button", className: `ta-swipe-action${action.danger ? ' ta-danger' : ''}`, onClick: () => {
65
+ // How far the content slides open, and its actions come out from: theirs together.
66
+ style: enabled ? { ...style, '--ta-swipe-width': `${ACTION_PX * ((_a = actions === null || actions === void 0 ? void 0 : actions.length) !== null && _a !== void 0 ? _a : 0)}px` } : style,
67
+ }, enabled && (React.createElement("div", { className: "ta-swipe-actions", inert: !open }, actions === null || actions === void 0 ? void 0 : actions.map((action, index) => (React.createElement("button", { key: action.key, type: "button", className: `ta-swipe-action${action.danger ? ' ta-danger' : ''}`,
68
+ // Of the way the row is shown, how far it is pushed out while closed (RowSwipeUtil.shift).
69
+ style: { '--ta-swipe-share': 1 - index / actions.length }, onClick: () => {
66
70
  unswipe();
67
71
  action.run();
68
- } }, action.label))))), React.createElement("div", { className: "ta-swipe-content", style: enabled ? { '--ta-swipe-width': `${ACTION_PX * ((_a = actions === null || actions === void 0 ? void 0 : actions.length) !== null && _a !== void 0 ? _a : 0)}px` } : undefined, onClickCapture: open ? closeInstead : undefined }, children), overlay);
72
+ } }, action.label))))), React.createElement("div", { className: "ta-swipe-content", onClickCapture: open ? closeInstead : undefined }, children), overlay);
69
73
  }
70
74
  //# sourceMappingURL=swipe-row.js.map
@@ -69,10 +69,10 @@ function ToolRow({ name, args, status, trailing, details }) {
69
69
  React.createElement(StatusDot, { status: status }),
70
70
  React.createElement("span", { className: "ta-tool-verb" }, summary.verb ? t(summary.verb) : summary.name),
71
71
  summary.target && React.createElement("span", { className: `ta-tool-target ${summary.code ? 'ta-mono' : ''}` }, summary.target),
72
- details ? React.createElement(icon_1.Icon, { icon: lucide_react_1.ChevronRight, size: 13, className: "ta-tool-chevron" }) : React.createElement("span", { className: "ta-tool-chevron" })));
72
+ React.createElement(icon_1.Icon, { icon: lucide_react_1.ChevronRight, size: 13, className: "ta-tool-chevron" })));
73
73
  return (React.createElement("div", { className: `ta-tool ta-tool-${status}` },
74
74
  React.createElement("div", { className: "ta-tool-line" },
75
- details ? (React.createElement("button", { type: "button", className: "ta-tool-title", "aria-expanded": open, onClick: () => setOpen(!open) }, line)) : (React.createElement("div", { className: "ta-tool-title" }, line)),
75
+ React.createElement("button", { type: "button", className: "ta-tool-title", disabled: !details, "aria-expanded": details ? open : undefined, onClick: () => setOpen(!open) }, line),
76
76
  React.createElement("span", { className: "ta-tool-trailing" }, trailing)),
77
77
  details && open && React.createElement("div", { className: "ta-tool-body" }, details)));
78
78
  }
@@ -124,23 +124,25 @@ function CodemodeView({ id, args, output, status, runs }) {
124
124
  const script = (React.createElement(React.Fragment, null,
125
125
  React.createElement(markdown_1.CodeBlock, { code: code, language: "js" }),
126
126
  result && React.createElement(Output, { text: result })));
127
- if (!calls.length) {
128
- return React.createElement(ToolRow, { name: "codemode", args: args, status: status, details: script });
129
- }
130
127
  const label = t(showScript ? 'ta.tool.hideScript' : 'ta.tool.showScript');
131
- const toggle = (React.createElement("button", { type: "button", className: `ta-tool-script ${showScript ? 'ta-on' : ''}`, title: label, "aria-label": label, "aria-pressed": showScript, onClick: () => setShowScript(!showScript) },
128
+ const toggle = calls.length > 0 && (React.createElement("button", { type: "button", className: `ta-tool-script ${showScript ? 'ta-on' : ''}`, title: label, "aria-label": label, "aria-pressed": showScript, onClick: () => setShowScript(!showScript) },
132
129
  React.createElement(icon_1.Icon, { icon: lucide_react_1.FileCode2, size: 13 })));
130
+ // Before its first call the script is the one step; its calls then take its place, the first in the same
131
+ // element, so that the line changes rather than comes again. By place: the calls are in order, live or
132
+ // kept, and their ids are not the same in both.
133
+ const rows = calls.length ? calls.map(nestedRow) : [{ name: 'codemode', args, status, details: script }];
133
134
  // A script that failed after its calls went well: one more step, the script, whose output says what went wrong.
134
- const failedAlone = status === 'error' && !calls.some(call => call.status === 'error');
135
+ if (calls.length && status === 'error' && !calls.some(call => call.status === 'error')) {
136
+ rows.push({ name: 'codemode', args: { code }, status: 'error', details: result ? React.createElement(Output, { text: result }) : undefined });
137
+ }
135
138
  return (React.createElement("div", { className: "ta-tool-group" },
136
- calls.map((call, index) => (React.createElement(NestedRow, { key: call.key, call: call, trailing: index === 0 ? toggle : undefined }))),
137
- failedAlone && React.createElement(ToolRow, { name: "codemode", args: { code }, status: "error", details: result && React.createElement(Output, { text: result }) }),
138
- showScript && React.createElement("div", { className: "ta-tool-body" }, script)));
139
+ rows.map((row, index) => (React.createElement(ToolRow, { key: index, ...row, trailing: index === 0 ? toggle || undefined : undefined }))),
140
+ showScript && calls.length > 0 && React.createElement("div", { className: "ta-tool-body" }, script)));
139
141
  }
140
- function NestedRow({ call, trailing }) {
142
+ function nestedRow(call) {
141
143
  var _a;
142
144
  const shown = details(call.name, call.args, (_a = call.run) === null || _a === void 0 ? void 0 : _a.result, call.status);
143
145
  const error = call.status === 'error' && call.error ? React.createElement(Output, { text: call.error }) : undefined;
144
- return React.createElement(ToolRow, { name: call.name, args: call.args, status: call.status, trailing: trailing, details: shown || error || undefined });
146
+ return { name: call.name, args: call.args, status: call.status, details: shown || error || undefined };
145
147
  }
146
148
  //# sourceMappingURL=tool-view.js.map
@@ -7,6 +7,6 @@ export interface VoiceButtonProps {
7
7
  onListening?(listening: boolean): void;
8
8
  onError(error: unknown): void;
9
9
  }
10
- /** The microphone of a message box, where the browser can recognize speech: a click listens, a wave shows it, a click stops it. */
10
+ /** The microphone of a message box, where the browser can recognize speech: a click listens, a wave shows it, a click stops it (a finger held on it talks, which is the box's: voice-talk.ts). */
11
11
  export declare function VoiceButton(props: VoiceButtonProps): React.JSX.Element;
12
12
  //# sourceMappingURL=voice-button.d.ts.map
@@ -39,7 +39,7 @@ const React = __importStar(require("react"));
39
39
  const use_t_1 = require("../i18n/use-t");
40
40
  const voice_1 = require("../util/voice");
41
41
  const icon_1 = require("./icon");
42
- /** The microphone of a message box, where the browser can recognize speech: a click listens, a wave shows it, a click stops it. */
42
+ /** The microphone of a message box, where the browser can recognize speech: a click listens, a wave shows it, a click stops it (a finger held on it talks, which is the box's: voice-talk.ts). */
43
43
  function VoiceButton(props) {
44
44
  const t = (0, use_t_1.useT)();
45
45
  const language = (0, use_t_1.useLanguage)();
@@ -0,0 +1,44 @@
1
+ import * as React from 'react';
2
+ import type { TalkTarget } from './held-talk';
3
+ /** Where the finger is let go: on the bottom, the words go; over 取消 they are dropped; over 编辑 they stay in the box. */
4
+ export type TalkZone = 'send' | 'cancel' | 'edit';
5
+ export declare namespace VoiceTalkUtil {
6
+ /** How long a talk lasts for the words to count: shorter, a finger slipped on the box and nothing is given. */
7
+ const SHORT_MS = 600;
8
+ /** How long the end of a talk waits for recognition to say it ended before it ends anyway. */
9
+ const SETTLE_MS = 1500;
10
+ /** How long "too short" stays before the page comes back. */
11
+ const SHORT_NOTICE_MS = 700;
12
+ /** How long the overlay takes to fade out. */
13
+ const LEAVE_MS = 160;
14
+ /** What a talk gives; none when it was too short to be meant, or when nothing was heard. */
15
+ function given(words: string, heldMs: number): string | undefined;
16
+ /** The zone of the overlay under a point (`data-talk-zone`): the bottom, where the finger starts, sends. */
17
+ function zone(element: Element | null): TalkZone;
18
+ }
19
+ /** Where a talk is: listening, the finger let go and the last words coming, said too short, the page coming back. */
20
+ export type TalkPhase = 'idle' | 'listening' | 'released' | 'short' | 'leaving';
21
+ export interface VoiceTalk extends TalkTarget {
22
+ phase: TalkPhase;
23
+ /** Listening, or the finger let go and the last words still coming. */
24
+ active: boolean;
25
+ /** What has been heard so far. */
26
+ words: string;
27
+ /** Where the finger is. */
28
+ zone: TalkZone;
29
+ }
30
+ /**
31
+ * A conversation by voice as WeChat's: a finger held on the message box (or on an entry of the navigation) dims the
32
+ * page and a green bubble listens, the words coming as they are said. Let go on the bottom, they are sent; slid
33
+ * over 取消 they are dropped, over 编辑 they stay in the box to be read over. A talk too short to be meant, which a
34
+ * wrong touch is, says so and gives nothing, as one where nothing was heard does.
35
+ */
36
+ export declare function useVoiceTalk(onGive: (text: string, zone: 'send' | 'edit') => void, onError: (error: unknown) => void): VoiceTalk;
37
+ /**
38
+ * What a talk shows, over the whole page (above the keyboard): the page dimmed, a green bubble with the words as
39
+ * they come, 取消 and 编辑 to slide the finger onto, and the bottom it starts on, which says what letting go does.
40
+ */
41
+ export declare function VoiceTalkOverlay({ talk }: {
42
+ talk: VoiceTalk;
43
+ }): React.ReactPortal | null;
44
+ //# sourceMappingURL=voice-talk.d.ts.map
@@ -0,0 +1,260 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.VoiceTalkUtil = void 0;
37
+ exports.useVoiceTalk = useVoiceTalk;
38
+ exports.VoiceTalkOverlay = VoiceTalkOverlay;
39
+ const lucide_react_1 = require("lucide-react");
40
+ const React = __importStar(require("react"));
41
+ const react_dom_1 = require("react-dom");
42
+ const hold_1 = require("../device/hold");
43
+ const use_t_1 = require("../i18n/use-t");
44
+ const voice_1 = require("../util/voice");
45
+ const icon_1 = require("./icon");
46
+ var VoiceTalkUtil;
47
+ (function (VoiceTalkUtil) {
48
+ /** How long a talk lasts for the words to count: shorter, a finger slipped on the box and nothing is given. */
49
+ VoiceTalkUtil.SHORT_MS = 600;
50
+ /** How long the end of a talk waits for recognition to say it ended before it ends anyway. */
51
+ VoiceTalkUtil.SETTLE_MS = 1500;
52
+ /** How long "too short" stays before the page comes back. */
53
+ VoiceTalkUtil.SHORT_NOTICE_MS = 700;
54
+ /** How long the overlay takes to fade out. */
55
+ VoiceTalkUtil.LEAVE_MS = 160;
56
+ /** What a talk gives; none when it was too short to be meant, or when nothing was heard. */
57
+ function given(words, heldMs) {
58
+ const text = words.trim();
59
+ return text && heldMs >= VoiceTalkUtil.SHORT_MS ? text : undefined;
60
+ }
61
+ VoiceTalkUtil.given = given;
62
+ /** The zone of the overlay under a point (`data-talk-zone`): the bottom, where the finger starts, sends. */
63
+ function zone(element) {
64
+ var _a;
65
+ const zone = (_a = element === null || element === void 0 ? void 0 : element.closest('[data-talk-zone]')) === null || _a === void 0 ? void 0 : _a.getAttribute('data-talk-zone');
66
+ return zone === 'cancel' || zone === 'edit' ? zone : 'send';
67
+ }
68
+ VoiceTalkUtil.zone = zone;
69
+ })(VoiceTalkUtil || (exports.VoiceTalkUtil = VoiceTalkUtil = {}));
70
+ const IDLE = { phase: 'idle', words: '', zone: 'send' };
71
+ /**
72
+ * A conversation by voice as WeChat's: a finger held on the message box (or on an entry of the navigation) dims the
73
+ * page and a green bubble listens, the words coming as they are said. Let go on the bottom, they are sent; slid
74
+ * over 取消 they are dropped, over 编辑 they stay in the box to be read over. A talk too short to be meant, which a
75
+ * wrong touch is, says so and gives nothing, as one where nothing was heard does.
76
+ */
77
+ function useVoiceTalk(onGive, onError) {
78
+ const t = (0, use_t_1.useT)();
79
+ const language = (0, use_t_1.useLanguage)();
80
+ const [state, setState] = React.useState(IDLE);
81
+ // The phase as the finger and recognition find it, between renders.
82
+ const phase = React.useRef('idle');
83
+ const listening = React.useRef(undefined);
84
+ const heard = React.useRef('');
85
+ const since = React.useRef(0);
86
+ const held = React.useRef(0);
87
+ const zone = React.useRef('send');
88
+ /** Recognition ended while the finger was still down (a long silence): what it heard waits for the finger. */
89
+ const ended = React.useRef(false);
90
+ const timer = React.useRef(undefined);
91
+ // Recognition and the finger outlive a render: always to what the box is now.
92
+ const give = React.useRef(onGive);
93
+ give.current = onGive;
94
+ const fail = React.useRef(onError);
95
+ fail.current = onError;
96
+ // The box goes as it listens (another conversation, another page): what was said is not given to it.
97
+ React.useEffect(() => () => {
98
+ clearTimeout(timer.current);
99
+ const session = listening.current;
100
+ listening.current = undefined;
101
+ session === null || session === void 0 ? void 0 : session.stop();
102
+ }, []);
103
+ const go = (next, more) => {
104
+ phase.current = next;
105
+ setState(current => ({ ...current, ...more, phase: next }));
106
+ };
107
+ const later = (ms, then) => {
108
+ clearTimeout(timer.current);
109
+ timer.current = setTimeout(then, ms);
110
+ };
111
+ /** Stops listening, whatever it heard after. */
112
+ const quiet = () => {
113
+ const session = listening.current;
114
+ listening.current = undefined;
115
+ session === null || session === void 0 ? void 0 : session.stop();
116
+ };
117
+ /** The page comes back, the overlay fading out. */
118
+ const leave = () => {
119
+ quiet();
120
+ go('leaving');
121
+ later(VoiceTalkUtil.LEAVE_MS, () => {
122
+ phase.current = 'idle';
123
+ setState(IDLE);
124
+ });
125
+ };
126
+ /** The finger let go off 取消 and recognition said its last: the words go as the place it let go says. */
127
+ const deliver = () => {
128
+ const text = VoiceTalkUtil.given(heard.current, held.current);
129
+ const where = zone.current;
130
+ leave();
131
+ if (text && where !== 'cancel') {
132
+ give.current(text, where);
133
+ }
134
+ };
135
+ const start = () => {
136
+ if (phase.current === 'listening' || phase.current === 'released') {
137
+ return;
138
+ }
139
+ clearTimeout(timer.current);
140
+ since.current = Date.now();
141
+ held.current = 0;
142
+ heard.current = '';
143
+ zone.current = 'send';
144
+ ended.current = false;
145
+ // What a talk ended or dropped before still says it ended (onerror, then onend): not to the next one.
146
+ let session;
147
+ session = voice_1.Voice.listen(language, words => {
148
+ if (listening.current === session) {
149
+ heard.current = words;
150
+ setState(current => ({ ...current, words }));
151
+ }
152
+ }, failure => {
153
+ if (listening.current !== session) {
154
+ return;
155
+ }
156
+ if (failure) {
157
+ fail.current(new Error(t(voice_1.Voice.denied(failure) ? 'ta.composer.voiceDenied' : 'ta.composer.voiceFailed', { error: failure })));
158
+ leave();
159
+ }
160
+ else if (phase.current === 'released') {
161
+ listening.current = undefined;
162
+ deliver();
163
+ }
164
+ else {
165
+ ended.current = true;
166
+ }
167
+ },
168
+ // A finger held goes on past a pause: it stops when it lets go.
169
+ true);
170
+ if (session) {
171
+ listening.current = session;
172
+ go('listening', { words: '', zone: 'send' });
173
+ }
174
+ };
175
+ const point = (x, y) => {
176
+ if (phase.current !== 'listening') {
177
+ return;
178
+ }
179
+ const next = VoiceTalkUtil.zone(document.elementFromPoint(x, y));
180
+ if (next !== zone.current) {
181
+ zone.current = next;
182
+ setState(current => ({ ...current, zone: next }));
183
+ if (next !== 'send') {
184
+ hold_1.HeldUtil.tick();
185
+ }
186
+ }
187
+ };
188
+ const release = () => {
189
+ var _a;
190
+ if (phase.current !== 'listening') {
191
+ return;
192
+ }
193
+ held.current = Date.now() - since.current;
194
+ if (zone.current === 'cancel') {
195
+ leave();
196
+ }
197
+ else if (held.current < VoiceTalkUtil.SHORT_MS) {
198
+ // Too short to be meant: said so for a moment, and nothing is given.
199
+ quiet();
200
+ go('short');
201
+ later(VoiceTalkUtil.SHORT_NOTICE_MS, leave);
202
+ }
203
+ else if (ended.current) {
204
+ listening.current = undefined;
205
+ deliver();
206
+ }
207
+ else {
208
+ go('released');
209
+ (_a = listening.current) === null || _a === void 0 ? void 0 : _a.stop();
210
+ // Recognition that does not say it ended would leave the page dimmed: the talk ends with what was heard.
211
+ later(VoiceTalkUtil.SETTLE_MS, () => phase.current === 'released' && deliver());
212
+ }
213
+ };
214
+ const cancel = () => {
215
+ if (phase.current !== 'idle' && phase.current !== 'leaving') {
216
+ leave();
217
+ }
218
+ };
219
+ return { ...state, active: state.phase === 'listening' || state.phase === 'released', start, point, release, cancel };
220
+ }
221
+ /**
222
+ * What a talk shows, over the whole page (above the keyboard): the page dimmed, a green bubble with the words as
223
+ * they come, 取消 and 编辑 to slide the finger onto, and the bottom it starts on, which says what letting go does.
224
+ */
225
+ function VoiceTalkOverlay({ talk }) {
226
+ const t = (0, use_t_1.useT)();
227
+ const { phase, cancel } = talk;
228
+ const listening = phase === 'listening';
229
+ React.useEffect(() => {
230
+ if (!listening) {
231
+ return;
232
+ }
233
+ const onKey = (event) => event.key === 'Escape' && cancel();
234
+ document.addEventListener('keydown', onKey);
235
+ return () => document.removeEventListener('keydown', onKey);
236
+ }, [listening, cancel]);
237
+ if (phase === 'idle') {
238
+ return null;
239
+ }
240
+ const short = phase === 'short';
241
+ const hint = listening ? t(talk.zone === 'cancel' ? 'ta.talk.releaseCancel' : talk.zone === 'edit' ? 'ta.talk.releaseEdit' : 'ta.talk.releaseSend') : '';
242
+ return (0, react_dom_1.createPortal)(React.createElement("div", { className: `ta-talk ta-talk-${talk.zone} ta-talk-${phase}`, role: "dialog", "aria-modal": "true", "aria-label": t('ta.talk.listening') },
243
+ React.createElement("div", { className: "ta-talk-bubble", "aria-live": "polite" }, short ? (React.createElement("p", { className: "ta-talk-words" }, t('ta.talk.tooShort'))) : talk.words ? (React.createElement("p", { className: "ta-talk-words" }, talk.words)) : (React.createElement("span", { className: "ta-wave", "aria-hidden": "true" },
244
+ React.createElement("i", null),
245
+ React.createElement("i", null),
246
+ React.createElement("i", null),
247
+ React.createElement("i", null)))),
248
+ React.createElement("div", { className: "ta-talk-zones", "aria-hidden": !listening },
249
+ React.createElement("div", { className: `ta-talk-zone${talk.zone === 'cancel' ? ' ta-on' : ''}`, "data-talk-zone": "cancel" },
250
+ React.createElement("span", { className: "ta-talk-zone-label" }, t('ta.cancel')),
251
+ React.createElement("span", { className: "ta-talk-zone-circle" },
252
+ React.createElement(icon_1.Icon, { icon: lucide_react_1.X, size: 26 }))),
253
+ React.createElement("div", { className: `ta-talk-zone${talk.zone === 'edit' ? ' ta-on' : ''}`, "data-talk-zone": "edit" },
254
+ React.createElement("span", { className: "ta-talk-zone-label" }, t('ta.talk.edit')),
255
+ React.createElement("span", { className: "ta-talk-zone-circle" },
256
+ React.createElement(icon_1.Icon, { icon: lucide_react_1.PenLine, size: 24 })))),
257
+ React.createElement("div", { className: "ta-talk-base" },
258
+ React.createElement("span", { className: "ta-talk-hint" }, hint))), document.body);
259
+ }
260
+ //# sourceMappingURL=voice-talk.js.map
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { type DeviceLayout, type DeviceState } from './device-protocol';
3
3
  import { type NewLineBridge } from './new-line';
4
+ import { type ShakeUndoBridge } from './shake-undo';
4
5
  /** What the observer reads of the browser; tests give their own. */
5
6
  export interface DeviceEnvironment {
6
7
  matchMedia(query: string): {
@@ -33,6 +34,8 @@ export interface DeviceEnvironment {
33
34
  readonly keyboard?: (listener: (height: number) => void) => void;
34
35
  /** The edit menu of the app on iOS, which offers New Line in the message box (new-line.ts); none elsewhere. */
35
36
  readonly newLine?: NewLineBridge;
37
+ /** Shake to Undo of the app on iOS, offered only while a field has text (shake-undo.ts); none elsewhere. */
38
+ readonly shakeUndo?: ShakeUndoBridge;
36
39
  }
37
40
  export declare namespace DeviceUtil {
38
41
  /** Where the page is not in a browser (tests, the server). */