wecool-chat 0.8.0 → 0.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 (227) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/README.ja.md +234 -20
  3. package/README.md +419 -21
  4. package/dist/CopyIndicator-RR3hSsBA.js +51 -0
  5. package/dist/MarkdownBody-EIz0jnQy.js +14910 -0
  6. package/dist/VoiceControls-A7N4uPTo.js +146 -0
  7. package/dist/VoiceRuntime-DrYjNkZK.js +459 -0
  8. package/dist/abort-BjeyCmGn.js +6 -0
  9. package/dist/blank-line-CUDmZ-mX.js +143 -0
  10. package/dist/{browser-Cgo1GySj.js → browser-M7mS-hAN.js} +5 -5
  11. package/dist/clsx-Cf23UI1w.js +16 -0
  12. package/dist/core/client.d.ts +37 -4
  13. package/dist/core/client.d.ts.map +1 -1
  14. package/dist/core/consume-stream.d.ts.map +1 -1
  15. package/dist/core/error-reporter.d.ts +59 -0
  16. package/dist/core/error-reporter.d.ts.map +1 -0
  17. package/dist/core/global-error-capture.d.ts +10 -0
  18. package/dist/core/global-error-capture.d.ts.map +1 -0
  19. package/dist/core/i18n/messages.d.ts +139 -1
  20. package/dist/core/i18n/messages.d.ts.map +1 -1
  21. package/dist/core/sanitize-user-message.d.ts +11 -0
  22. package/dist/core/sanitize-user-message.d.ts.map +1 -0
  23. package/dist/core/stream-state.d.ts.map +1 -1
  24. package/dist/core/tool-confirmation.d.ts +35 -0
  25. package/dist/core/tool-confirmation.d.ts.map +1 -0
  26. package/dist/core/tool-runner.d.ts +8 -0
  27. package/dist/core/tool-runner.d.ts.map +1 -1
  28. package/dist/core/types.d.ts +123 -0
  29. package/dist/core/types.d.ts.map +1 -1
  30. package/dist/core/widget-origin.d.ts +33 -0
  31. package/dist/core/widget-origin.d.ts.map +1 -0
  32. package/dist/createLucideIcon-C7wGkK-Q.js +43 -0
  33. package/dist/default-sNAxTmdF.js +8 -0
  34. package/dist/index.css +2 -2
  35. package/dist/index.d.ts +3 -1
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +7548 -26290
  38. package/dist/jsx-runtime-Cyy0mp0f.js +328 -0
  39. package/dist/lib-DG_DjiCr.js +15 -0
  40. package/dist/loader.d.ts +12 -0
  41. package/dist/loader.d.ts.map +1 -0
  42. package/dist/messages-FvtWi3lI.js +247 -0
  43. package/dist/observe/__tests__/format.test.d.ts +2 -0
  44. package/dist/observe/__tests__/format.test.d.ts.map +1 -0
  45. package/dist/observe/__tests__/http.test.d.ts +2 -0
  46. package/dist/observe/__tests__/http.test.d.ts.map +1 -0
  47. package/dist/observe/__tests__/index.test.d.ts +2 -0
  48. package/dist/observe/__tests__/index.test.d.ts.map +1 -0
  49. package/dist/observe/__tests__/js-error.test.d.ts +2 -0
  50. package/dist/observe/__tests__/js-error.test.d.ts.map +1 -0
  51. package/dist/observe/__tests__/redact.test.d.ts +2 -0
  52. package/dist/observe/__tests__/redact.test.d.ts.map +1 -0
  53. package/dist/observe/__tests__/ring-buffer.test.d.ts +2 -0
  54. package/dist/observe/__tests__/ring-buffer.test.d.ts.map +1 -0
  55. package/dist/observe/format.d.ts +10 -0
  56. package/dist/observe/format.d.ts.map +1 -0
  57. package/dist/observe/index.d.ts +33 -0
  58. package/dist/observe/index.d.ts.map +1 -0
  59. package/dist/observe/observers/http.d.ts +24 -0
  60. package/dist/observe/observers/http.d.ts.map +1 -0
  61. package/dist/observe/observers/js-error.d.ts +22 -0
  62. package/dist/observe/observers/js-error.d.ts.map +1 -0
  63. package/dist/observe/redact.d.ts +27 -0
  64. package/dist/observe/redact.d.ts.map +1 -0
  65. package/dist/observe/ring-buffer.d.ts +20 -0
  66. package/dist/observe/ring-buffer.d.ts.map +1 -0
  67. package/dist/observe/types.d.ts +25 -0
  68. package/dist/observe/types.d.ts.map +1 -0
  69. package/dist/plugin/registry.d.ts.map +1 -1
  70. package/dist/plugin/types.d.ts +19 -1
  71. package/dist/plugin/types.d.ts.map +1 -1
  72. package/dist/plugins/page-reader/__tests__/get-meta.test.d.ts +2 -0
  73. package/dist/plugins/page-reader/__tests__/get-meta.test.d.ts.map +1 -0
  74. package/dist/plugins/page-reader/__tests__/index.test.d.ts +2 -0
  75. package/dist/plugins/page-reader/__tests__/index.test.d.ts.map +1 -0
  76. package/dist/plugins/page-reader/__tests__/read-content.test.d.ts +2 -0
  77. package/dist/plugins/page-reader/__tests__/read-content.test.d.ts.map +1 -0
  78. package/dist/plugins/page-reader/__tests__/scroll.test.d.ts +2 -0
  79. package/dist/plugins/page-reader/__tests__/scroll.test.d.ts.map +1 -0
  80. package/dist/plugins/page-reader/index.d.ts +18 -0
  81. package/dist/plugins/page-reader/index.d.ts.map +1 -0
  82. package/dist/plugins/page-reader/tools/get-meta.d.ts +29 -0
  83. package/dist/plugins/page-reader/tools/get-meta.d.ts.map +1 -0
  84. package/dist/plugins/page-reader/tools/read-content.d.ts +34 -0
  85. package/dist/plugins/page-reader/tools/read-content.d.ts.map +1 -0
  86. package/dist/plugins/page-reader/tools/scroll.d.ts +29 -0
  87. package/dist/plugins/page-reader/tools/scroll.d.ts.map +1 -0
  88. package/dist/plugins/page-reader.d.ts +2 -0
  89. package/dist/plugins/page-reader.js +230 -0
  90. package/dist/plugins/qrcode/tool.d.ts.map +1 -1
  91. package/dist/plugins/qrcode.js +52 -42
  92. package/dist/plugins/shared/abort.d.ts +7 -0
  93. package/dist/plugins/shared/abort.d.ts.map +1 -0
  94. package/dist/remark-gfm-Bzy1u34W.js +1962 -0
  95. package/dist/remark-parse-BnwSmQr-.js +2486 -0
  96. package/dist/stable-prefix-BHsGj4tL.js +21 -0
  97. package/dist/ui/builtin-tools/get-current-page-info.d.ts.map +1 -1
  98. package/dist/ui/builtin-tools/index.d.ts +1 -1
  99. package/dist/ui/builtin-tools/index.d.ts.map +1 -1
  100. package/dist/ui/builtin-tools/merge-builtin-tools.d.ts +9 -0
  101. package/dist/ui/builtin-tools/merge-builtin-tools.d.ts.map +1 -1
  102. package/dist/ui/commands/builtin-commands.d.ts +46 -0
  103. package/dist/ui/commands/builtin-commands.d.ts.map +1 -0
  104. package/dist/ui/components/ChatErrorBoundary.d.ts +30 -0
  105. package/dist/ui/components/ChatErrorBoundary.d.ts.map +1 -0
  106. package/dist/ui/components/ChatFooter.d.ts +32 -2
  107. package/dist/ui/components/ChatFooter.d.ts.map +1 -1
  108. package/dist/ui/components/ChatHeader.d.ts +13 -2
  109. package/dist/ui/components/ChatHeader.d.ts.map +1 -1
  110. package/dist/ui/components/ChatHeaderMenu.d.ts +28 -2
  111. package/dist/ui/components/ChatHeaderMenu.d.ts.map +1 -1
  112. package/dist/ui/components/ChatPanel.d.ts +38 -4
  113. package/dist/ui/components/ChatPanel.d.ts.map +1 -1
  114. package/dist/ui/components/ChatWidget.d.ts +1 -1
  115. package/dist/ui/components/ChatWidget.d.ts.map +1 -1
  116. package/dist/ui/components/CommandConfirmationCard.d.ts +28 -0
  117. package/dist/ui/components/CommandConfirmationCard.d.ts.map +1 -0
  118. package/dist/ui/components/CommandOverlays.d.ts +40 -0
  119. package/dist/ui/components/CommandOverlays.d.ts.map +1 -0
  120. package/dist/ui/components/CommandPalette.d.ts +25 -0
  121. package/dist/ui/components/CommandPalette.d.ts.map +1 -0
  122. package/dist/ui/components/FooterActions.d.ts +18 -0
  123. package/dist/ui/components/FooterActions.d.ts.map +1 -0
  124. package/dist/ui/components/HelpDialogContent.d.ts +7 -0
  125. package/dist/ui/components/HelpDialogContent.d.ts.map +1 -0
  126. package/dist/ui/components/MessageList.d.ts +12 -1
  127. package/dist/ui/components/MessageList.d.ts.map +1 -1
  128. package/dist/ui/components/MessageRow.d.ts +7 -1
  129. package/dist/ui/components/MessageRow.d.ts.map +1 -1
  130. package/dist/ui/components/MessageRowActions.d.ts +9 -3
  131. package/dist/ui/components/MessageRowActions.d.ts.map +1 -1
  132. package/dist/ui/components/MicButton.d.ts +11 -0
  133. package/dist/ui/components/MicButton.d.ts.map +1 -0
  134. package/dist/ui/components/ResizeHandles.d.ts +15 -0
  135. package/dist/ui/components/ResizeHandles.d.ts.map +1 -0
  136. package/dist/ui/components/ToolConfirmationCard.d.ts +22 -0
  137. package/dist/ui/components/ToolConfirmationCard.d.ts.map +1 -0
  138. package/dist/ui/components/ToolConfirmationRecord.d.ts +16 -0
  139. package/dist/ui/components/ToolConfirmationRecord.d.ts.map +1 -0
  140. package/dist/ui/components/ToolsDialogContent.d.ts +20 -0
  141. package/dist/ui/components/ToolsDialogContent.d.ts.map +1 -0
  142. package/dist/ui/components/VoiceControls.d.ts +22 -0
  143. package/dist/ui/components/VoiceControls.d.ts.map +1 -0
  144. package/dist/ui/components/VoiceLoopStatusBar.d.ts +17 -0
  145. package/dist/ui/components/VoiceLoopStatusBar.d.ts.map +1 -0
  146. package/dist/ui/components/VoiceLoopToggle.d.ts +15 -0
  147. package/dist/ui/components/VoiceLoopToggle.d.ts.map +1 -0
  148. package/dist/ui/components/VoiceRuntime.d.ts +16 -0
  149. package/dist/ui/components/VoiceRuntime.d.ts.map +1 -0
  150. package/dist/ui/components/WidgetDialog.d.ts +22 -0
  151. package/dist/ui/components/WidgetDialog.d.ts.map +1 -0
  152. package/dist/ui/components/lazy-voice.d.ts +19 -0
  153. package/dist/ui/components/lazy-voice.d.ts.map +1 -0
  154. package/dist/ui/components/markdown/MarkdownBody.d.ts +28 -0
  155. package/dist/ui/components/markdown/MarkdownBody.d.ts.map +1 -0
  156. package/dist/ui/components/markdown/MarkdownMessage.d.ts +12 -13
  157. package/dist/ui/components/markdown/MarkdownMessage.d.ts.map +1 -1
  158. package/dist/ui/hooks/conversationPersistence.d.ts +21 -0
  159. package/dist/ui/hooks/conversationPersistence.d.ts.map +1 -0
  160. package/dist/ui/hooks/resize-geometry.d.ts +42 -0
  161. package/dist/ui/hooks/resize-geometry.d.ts.map +1 -0
  162. package/dist/ui/hooks/use-command-execution.d.ts +60 -0
  163. package/dist/ui/hooks/use-command-execution.d.ts.map +1 -0
  164. package/dist/ui/hooks/use-command-palette.d.ts +45 -0
  165. package/dist/ui/hooks/use-command-palette.d.ts.map +1 -0
  166. package/dist/ui/hooks/use-fullscreen.d.ts +21 -0
  167. package/dist/ui/hooks/use-fullscreen.d.ts.map +1 -0
  168. package/dist/ui/hooks/use-global-error-capture.d.ts +16 -0
  169. package/dist/ui/hooks/use-global-error-capture.d.ts.map +1 -0
  170. package/dist/ui/hooks/use-locale-preference.d.ts +14 -0
  171. package/dist/ui/hooks/use-locale-preference.d.ts.map +1 -0
  172. package/dist/ui/hooks/use-menu-keyboard.d.ts +7 -1
  173. package/dist/ui/hooks/use-menu-keyboard.d.ts.map +1 -1
  174. package/dist/ui/hooks/use-message-history.d.ts +14 -0
  175. package/dist/ui/hooks/use-message-history.d.ts.map +1 -1
  176. package/dist/ui/hooks/use-mic-button.d.ts +29 -0
  177. package/dist/ui/hooks/use-mic-button.d.ts.map +1 -0
  178. package/dist/ui/hooks/use-send-message.d.ts +6 -0
  179. package/dist/ui/hooks/use-send-message.d.ts.map +1 -1
  180. package/dist/ui/hooks/use-speak-message.d.ts +26 -0
  181. package/dist/ui/hooks/use-speak-message.d.ts.map +1 -0
  182. package/dist/ui/hooks/use-tool-confirmation.d.ts +22 -0
  183. package/dist/ui/hooks/use-tool-confirmation.d.ts.map +1 -0
  184. package/dist/ui/hooks/use-tool-runner.d.ts +17 -2
  185. package/dist/ui/hooks/use-tool-runner.d.ts.map +1 -1
  186. package/dist/ui/hooks/use-visitor-id.d.ts +22 -0
  187. package/dist/ui/hooks/use-visitor-id.d.ts.map +1 -0
  188. package/dist/ui/hooks/use-voice-input.d.ts +38 -0
  189. package/dist/ui/hooks/use-voice-input.d.ts.map +1 -0
  190. package/dist/ui/hooks/use-voice-loop-speech.d.ts +38 -0
  191. package/dist/ui/hooks/use-voice-loop-speech.d.ts.map +1 -0
  192. package/dist/ui/hooks/use-voice-loop.d.ts +12 -0
  193. package/dist/ui/hooks/use-voice-loop.d.ts.map +1 -0
  194. package/dist/ui/hooks/use-voice-runtime-snapshot.d.ts +19 -0
  195. package/dist/ui/hooks/use-voice-runtime-snapshot.d.ts.map +1 -0
  196. package/dist/ui/hooks/use-voice-runtime.d.ts +29 -0
  197. package/dist/ui/hooks/use-voice-runtime.d.ts.map +1 -0
  198. package/dist/ui/hooks/useChatStream.d.ts +19 -0
  199. package/dist/ui/hooks/useChatStream.d.ts.map +1 -1
  200. package/dist/ui/hooks/useConversationList.d.ts +12 -1
  201. package/dist/ui/hooks/useConversationList.d.ts.map +1 -1
  202. package/dist/ui/hooks/useDraggablePanel.d.ts +2 -0
  203. package/dist/ui/hooks/useDraggablePanel.d.ts.map +1 -1
  204. package/dist/ui/hooks/useResizablePanel.d.ts +48 -0
  205. package/dist/ui/hooks/useResizablePanel.d.ts.map +1 -0
  206. package/dist/ui/utils/speech-text.d.ts +29 -0
  207. package/dist/ui/utils/speech-text.d.ts.map +1 -0
  208. package/dist/ui/utils/voice-locale.d.ts +3 -0
  209. package/dist/ui/utils/voice-locale.d.ts.map +1 -0
  210. package/dist/ui/utils/voice-loop-cue.d.ts +23 -0
  211. package/dist/ui/utils/voice-loop-cue.d.ts.map +1 -0
  212. package/dist/ui/utils/voice-loop-status.d.ts +17 -0
  213. package/dist/ui/utils/voice-loop-status.d.ts.map +1 -0
  214. package/dist/ui/utils/voice-loop-types.d.ts +40 -0
  215. package/dist/ui/utils/voice-loop-types.d.ts.map +1 -0
  216. package/dist/ui/utils/voice-runtime.d.ts +38 -0
  217. package/dist/ui/utils/voice-runtime.d.ts.map +1 -0
  218. package/dist/ui/utils/voice-support.d.ts +9 -0
  219. package/dist/ui/utils/voice-support.d.ts.map +1 -0
  220. package/dist/unified-DctkAd9P.js +518 -0
  221. package/dist/use-voice-input-LtJJz-zQ.js +102 -0
  222. package/dist/version.d.ts +17 -0
  223. package/dist/version.d.ts.map +1 -0
  224. package/dist/voice-runtime-F5NxN_0m.js +11 -0
  225. package/dist/voice-support-BeOiOzcn.js +9 -0
  226. package/package.json +41 -23
  227. package/dist/messages-B7Kpa6yx.js +0 -117
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![npm version](https://img.shields.io/npm/v/wecool-chat.svg)](https://www.npmjs.com/package/wecool-chat)
6
6
  [![npm downloads](https://img.shields.io/npm/dm/wecool-chat.svg)](https://www.npmjs.com/package/wecool-chat)
7
7
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
- [![bundle size](https://img.shields.io/bundlephobia/minzip/wecool-chat.svg)](https://bundlephobia.com/package/wecool-chat)
8
+ [![initial bundle](https://img.shields.io/badge/initial%20bundle-115.5_KB_gzip-brightgreen)](https://www.npmjs.com/package/wecool-chat)
9
9
 
10
10
  > A drop-in LLM chat widget that lets users operate your UI in natural language — works with any framework.
11
11
 
@@ -110,6 +110,59 @@ Since the API key is visible to the client, **restrict the calling origin** in t
110
110
 
111
111
  ---
112
112
 
113
+ ## Drop-in `<script>` tag (no build step)
114
+
115
+ For plain HTML sites, you don't need npm or a bundler. Paste a single `<script>` tag and the
116
+ widget self-initializes. The fastest way to get this snippet is `npx wecool-cli init`, which
117
+ registers your account, issues a key, and copies the tag to your clipboard.
118
+
119
+ ```html
120
+ <script src="https://api.wecool.dev/v1/widget.js" data-api-key="wlt_your_publishable_key"></script>
121
+ ```
122
+
123
+ The hosted bundle (`widget.js`) inlines the library, its styles, and the official plugins into one
124
+ self-contained file, so the widget renders inside a Shadow DOM without touching your page's CSS.
125
+
126
+ ### Attributes
127
+
128
+ | Attribute | Values | Default |
129
+ | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------ |
130
+ | `data-api-key` | your publishable key (`wlt_...`) — **required** | — |
131
+ | `data-locale` | `ja` \| `en` | `ja` |
132
+ | `data-theme` | `auto` \| `light` \| `dark` | `auto` |
133
+ | `data-layout` | `floating-bottom-right` \| `floating-bottom-left` \| `floating-top-right` \| `floating-top-left` \| `sidebar-left` \| `sidebar-right` \| `header-banner` \| `footer-fixed` | `floating-bottom-right` |
134
+ | `data-endpoint` | API base URL override (self-hosting) | `https://api.wecool.dev` |
135
+ | `data-plugins` | comma-separated list of official plugins (`qrcode`, `page-reader`). Empty string (`data-plugins=""`) disables all. | `qrcode,page-reader` |
136
+
137
+ ```html
138
+ <script
139
+ src="https://api.wecool.dev/v1/widget.js"
140
+ data-api-key="wlt_your_publishable_key"
141
+ data-locale="en"
142
+ data-theme="dark"
143
+ data-layout="floating-bottom-right"
144
+ ></script>
145
+ ```
146
+
147
+ ### Server-provided tools and official plugins work out of the box
148
+
149
+ The drop-in bundle enables the server-provided tools plus the bundled official plugins — **QR code
150
+ generation** and **page-content reading** — by default, so a pasted tag delivers the most value with
151
+ zero configuration. Toggle plugins with `data-plugins` (e.g. `data-plugins="qrcode"` for QR only, or
152
+ `data-plugins=""` to disable both).
153
+
154
+ ### Limitations
155
+
156
+ - **Custom JavaScript tools require the npm integration.** The `<script>` tag cannot register your own
157
+ functions — for user-defined tools, install `wecool-chat` from npm and pass `tools` to
158
+ `initWecoolChat` / `<ChatWidget>` as shown above.
159
+ - **Content Security Policy.** If the embedding site's CSP forbids external scripts, add
160
+ `https://api.wecool.dev` to `script-src` (and `connect-src` for the API calls), or self-host the
161
+ bundle and point `data-endpoint` at your API.
162
+ - Loading `widget.js` twice on the same page is a no-op — the second tag is ignored.
163
+
164
+ ---
165
+
113
166
  ## Display Modes (Layout Patterns)
114
167
 
115
168
  wecool-chat supports nine official layout patterns. Choose one with the `layout` option on `ChatConfig`.
@@ -144,6 +197,22 @@ initWecoolChat({
144
197
 
145
198
  For `header-banner`, you can add `transparent: true` to overlay the banner on the page content with a translucent background.
146
199
 
200
+ ### Fullscreen mode (floating patterns)
201
+
202
+ In the floating patterns, users can expand the panel to cover the entire viewport: open the header "⋮" menu and toggle **Fullscreen**. Pressing <kbd>Esc</kbd> exits fullscreen first; pressing <kbd>Esc</kbd> again closes the panel. The panel always reopens at its normal size — fullscreen is a transient view state and is never persisted.
203
+
204
+ Fullscreen is implemented as a CSS overlay (`position: fixed; inset: 0`) rather than the browser Fullscreen API, so the host page stays behind the panel and no browser permission prompt is involved. The height tracks `100dvh`, so it follows the collapsing URL bar on iOS Safari.
205
+
206
+ **Host page note**: if you pass a custom `container` element that sits inside an ancestor with `transform`, `filter`, or `contain` styles, `position: fixed` resolves against that ancestor instead of the viewport and fullscreen cannot cover the whole screen. The default mount (no `container` specified) appends the widget directly under `<body>` and is not affected.
207
+
208
+ ### Resizing the panel (floating patterns)
209
+
210
+ In the floating patterns, users can resize the panel by dragging any of its edges or corners with a mouse or pen, just like a browser window. The size is clamped between 320×400px and the viewport (minus a small margin), and follows the viewport when the browser window shrinks. The chosen size lasts for the current page session only — reloading restores the default size.
211
+
212
+ - **Keyboard**: the bottom-right corner handle is focusable; use arrow keys (8px), <kbd>Shift</kbd>+arrows (32px), and <kbd>Home</kbd> to reset the size.
213
+ - **Touch devices**: resizing is intentionally not offered on touch-primary devices (thin edge handles cannot be grabbed precisely and would conflict with scroll/pinch gestures). Handles are hidden there, and finger touches on hybrid devices (touch laptops) are ignored — use fullscreen mode instead for a larger view.
214
+ - **Reset**: the header "⋮" menu item **Reset position and size** restores both the dragged position and the resized dimensions.
215
+
147
216
  ### React equivalent
148
217
 
149
218
  When you use `<ChatWidget />` directly, pass `floating` / `position` as before; the `layout` field is consumed by `initWecoolChat` and translates to those props for you. The dedicated `sidebar-*` / `header-banner` / `footer-fixed` patterns are only available through `initWecoolChat` because they need a wrapper element on the host DOM.
@@ -222,7 +291,7 @@ The core of wecool-chat is the "tool definition". The LLM reads the list of tool
222
291
 
223
292
  ### Basic shape
224
293
 
225
- The `Tool` type has 4 fields.
294
+ The `Tool` type has 4 required fields.
226
295
 
227
296
  ```ts
228
297
  type Tool = {
@@ -230,9 +299,38 @@ type Tool = {
230
299
  description: string; // What the LLM uses to decide when to call this tool
231
300
  parameters: ToolParameters; // JSON Schema for arguments
232
301
  handler: (args: Record<string, unknown>) => unknown | Promise<unknown>;
302
+ requiresConfirmation?: boolean; // Ask the user before running (see below)
303
+ confirmationMessage?: string; // Text shown in the confirmation card
304
+ displayName?: LocalizedText; // Visitor-facing name shown in /tools (UI only, never sent to the LLM)
305
+ exampleQueries?: LocalizedText[]; // Example prompts shown in /tools (UI only, never sent to the LLM)
233
306
  };
234
307
  ```
235
308
 
309
+ ### Display metadata for `/tools`
310
+
311
+ `displayName` and `exampleQueries` power the [`/tools`](#slash-commands) list, which helps visitors discover "what they can ask". They are **UI-only** metadata — they are never included in the request body sent to the LLM (the request is built from `name` / `description` / `parameters` only), so it is safe to write them in the site's display language.
312
+
313
+ Both accept a `LocalizedText`, which is either a plain string or a per-locale map. Values are resolved in the order **current locale → the other locale**; if neither `displayName` is defined, the English `description` is shown as a fallback.
314
+
315
+ ```ts
316
+ type LocalizedText = string | Partial<Record<"ja" | "en", string>>;
317
+
318
+ {
319
+ name: "set_theme",
320
+ description: "Change the color theme. ...", // English (protocol string, sent to the LLM)
321
+ parameters: { /* ... */ },
322
+ handler: handleSetTheme,
323
+ // UI-only, follows /lang; safe to localize
324
+ displayName: { ja: "テーマの切り替え", en: "Switch theme" },
325
+ exampleQueries: [
326
+ { ja: "ダークモードにして", en: "Switch to dark mode" },
327
+ { ja: "明るいテーマにして", en: "Use a light theme" },
328
+ ],
329
+ }
330
+ ```
331
+
332
+ Clicking an example inserts it into the input field (it is **not** auto-sent), leaving the visitor free to edit before sending. Built-in utility tools (e.g. page-info) are excluded from `/tools`. Plugin tools may declare the same two fields.
333
+
236
334
  ### How you write `description` determines accuracy
237
335
 
238
336
  The LLM reads the `description` to decide "when to use this tool". **Including examples of how the user might phrase it** improves accuracy.
@@ -303,6 +401,37 @@ const config = {
303
401
 
304
402
  > **Note**: Receiving an `AbortSignal` inside `handler` to cancel work is not supported in the current version. Keep heavy work lightweight on the handler side.
305
403
 
404
+ ### Confirmation before destructive actions (`requiresConfirmation`)
405
+
406
+ LLMs occasionally misread instructions — especially negations like _"don't submit it yet"_ — and may call a tool the user did not intend. For tools whose effect is destructive or hard to undo, declare `requiresConfirmation: true`. Before running the handler, the widget shows an inline confirmation card ("Run" / "Cancel") in the chat:
407
+
408
+ ```ts
409
+ {
410
+ name: "clear_form",
411
+ description: "Clears the contact form. ...",
412
+ parameters: { type: "object", properties: {} },
413
+ handler: handleClearForm,
414
+ requiresConfirmation: true,
415
+ confirmationMessage: "This will clear everything you entered in the form. Do you want to continue?",
416
+ }
417
+ ```
418
+
419
+ - **Approve** → the handler runs as usual and the LLM narrates the result.
420
+ - Either way, the card is replaced by an **immutable record line** (the confirmation message plus "Approved" / "Cancelled") so the decision stays visible in the thread and cannot be re-triggered.
421
+ - **Cancel** → the handler is never called. The LLM receives a structured "the user declined" result and responds naturally; the conversation continues.
422
+ - Waiting for confirmation has **no timeout** (`toolTimeout` applies only after approval), and the Stop button still aborts the whole turn.
423
+ - Tools without the flag behave exactly as before.
424
+
425
+ **Which tools should require confirmation?**
426
+
427
+ | Declare `requiresConfirmation: true` | Leave it off |
428
+ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------- |
429
+ | Deleting or clearing user input (forms, carts, drafts), overwriting saved data, submitting/sending to external systems (orders, emails, payments), anything hard to undo | Read-only queries, display changes (theme, sort, filter, navigation), anything the user can trivially undo |
430
+
431
+ Do not gate everything: a confirmation on every tool call turns the assistant into a click-through dialog and users stop reading the prompts. Reserve it for actions with real cost.
432
+
433
+ **Always set `confirmationMessage`.** Tool names like `clear_form` are developer vocabulary; without a message the widget falls back to a generic prompt plus the tool name. Write a complete sentence in the language of your site (it is a UI string, so match `locale` — unlike tool `description`s, which should stay in English). The string is sanitized (control characters stripped, max 2,000 chars).
434
+
306
435
  ### Built-in tools
307
436
 
308
437
  wecool-chat ships ready-to-use tools that are **registered automatically**. You don't need to import or add them to the `tools` array — `ChatWidget` injects them for you.
@@ -490,6 +619,181 @@ Cancellation only throws `AbortError` — every other failure is returned as `{
490
619
 
491
620
  **Bundle impact**: the `qrcode` library lives inside `dist/plugins/qrcode.js` and its associated chunks under `dist/` (~14 KB gzipped in total). The core widget bundle (`dist/index.js`) does **not** pull it in. The plugin code itself loads `qrcode` only when the tool is actually invoked.
492
621
 
622
+ #### `wecool-chat/plugins/page-reader`
623
+
624
+ Read page content, retrieve meta/OGP information, and scroll the host page — all driven by natural language. The LLM decides which tool to invoke.
625
+
626
+ ```tsx
627
+ import { initWecoolChat } from "wecool-chat";
628
+ import { createPageReaderPlugin } from "wecool-chat/plugins/page-reader";
629
+
630
+ initWecoolChat({
631
+ endpoint: "https://your-api.example.com/chat",
632
+ plugins: [createPageReaderPlugin()],
633
+ });
634
+ ```
635
+
636
+ | Option | Type | Default | Description |
637
+ | ------------------ | -------- | ------- | --------------------------------------------------- |
638
+ | `defaultMaxLength` | `number` | `5000` | Max characters for `read_page_content` |
639
+ | `scrollAmount` | `number` | `0.5` | Viewport ratio for `up_a_bit` / `down_a_bit` scroll |
640
+
641
+ **Registered tools:**
642
+
643
+ | Tool | Description |
644
+ | ------------------- | --------------------------------------------------------------------- |
645
+ | `read_page_content` | Extract visible text from the current page (or a CSS-selected region) |
646
+ | `get_meta_info` | Retrieve URL, title, description, OGP tags, and canonical URL |
647
+ | `scroll_page` | Scroll to top/bottom, up/down a bit, or to a specific CSS selector |
648
+
649
+ **Limitations:**
650
+
651
+ - Shadow DOM and cross-origin iframe content cannot be read
652
+ - `scroll_page` targets the host page viewport only (not scrollable child elements)
653
+ - `scrollY` in the result may be a mid-scroll value when `behavior: "smooth"` is active
654
+
655
+ **Bundle impact**: `dist/plugins/page-reader.js` is ~2.4 KB gzipped with zero external dependencies. The core widget bundle is not affected.
656
+
657
+ ---
658
+
659
+ ## Page observation (`observe`) — automatic support context
660
+
661
+ The widget can observe client-side failure signals on the host page (HTTP `4xx`/`5xx`
662
+ responses and JavaScript errors — uncaught exceptions, unhandled rejections, and
663
+ `console.error`) and automatically attach a short summary of "what is currently going
664
+ wrong on this page" to the message sent to the LLM. This lets the assistant answer a vague
665
+ "the checkout button doesn't work" with an accurate first reply instead of many rounds of
666
+ questions.
667
+
668
+ - **On by default.** Using the widget enables observation. No extra flag.
669
+ - The background summary is attached to the message **sent to the LLM only** — the visitor's
670
+ chat transcript shows just their raw message.
671
+ - Only the **fact** of a failure is recorded (method/URL/status, error name/message). **Form
672
+ input values are never recorded.** URLs and error text are **redacted** (tokens, API keys,
673
+ email addresses, and token-like strings are masked) before being sent.
674
+ - Observation data is **not sent to any wecool server** — it is passed to the LLM once, at
675
+ send time, together with the visitor's message. Note this means the observed signals **are
676
+ sent to your configured LLM provider** as part of the chat request.
677
+
678
+ ```tsx
679
+ // default: observation on
680
+ initWecoolChat({ endpoint, tools: [] });
681
+
682
+ // turn it off entirely
683
+ initWecoolChat({ endpoint, tools: [], observe: false });
684
+
685
+ // per-channel
686
+ initWecoolChat({ endpoint, tools: [], observe: { http: true, errors: false } });
687
+ ```
688
+
689
+ **Privacy / consent (your responsibility):** because observation is on by default and not
690
+ gated on visitor consent, in regions where consent is required (GDPR / ePrivacy) you must
691
+ wire your own consent basis (e.g. a cookie banner) and set `observe: false` until consent is
692
+ granted. Flipping `observe` to `false` at runtime stops observation and discards the buffered
693
+ signals.
694
+
695
+ **Fixed-at-startup constraints:** the same startup-time constraints as locale/plugins apply —
696
+ `observe` is resolved when the widget mounts. Changing it requires re-initializing the widget.
697
+
698
+ **Bundle impact**: observation adds ~1.8 KB gzipped to the core bundle.
699
+
700
+ ---
701
+
702
+ ## Voice input & speech output (`voice`)
703
+
704
+ The widget can add a microphone button to the input area and a "read aloud" item to the
705
+ assistant message menu, backed by the browser's built-in Web Speech API. No external
706
+ dependency, no server round-trip for either feature.
707
+
708
+ - **Off by default.** Set `voice: true` to opt in.
709
+ - **Microphone button**: tapping it starts listening immediately (visible state change on
710
+ the button) and stops after a single utterance. The recognized text is submitted through
711
+ the **exact same path as typing and pressing send** — same bubble, same history, same
712
+ host-side message augmentation. Supported on Chrome / Edge (Mac, Windows) and Safari
713
+ (macOS, iOS); the button is hidden entirely on unsupported browsers (Firefox has no
714
+ `SpeechRecognition` implementation).
715
+ - **Read-aloud item**: appears on assistant messages only, when the browser supports
716
+ `SpeechSynthesis` (all major browsers). Pressing it reads that message's text aloud with
717
+ no LLM round-trip; pressing it again while speaking stops playback. Starting playback on a
718
+ different message stops the previous one. Playback also stops if its message is edited or
719
+ deleted, the conversation is cleared, or the widget unmounts.
720
+ - Starting the microphone stops any in-progress read-aloud playback first, so the microphone
721
+ doesn't pick up the assistant's own voice.
722
+ - Recognition failures (silence, microphone permission denied, network error, unsupported)
723
+ are shown briefly on-screen without going through the LLM.
724
+
725
+ ```tsx
726
+ initWecoolChat({ endpoint, tools: [], voice: true });
727
+ ```
728
+
729
+ **Fixed-at-startup constraint**: like `locale`/`plugins`/`observe`, `voice` is resolved when
730
+ the widget mounts.
731
+
732
+ Asking the assistant via speech to "read that back to me" no longer works by design — voice
733
+ input and output are button-triggered only, which avoids known reliability issues with
734
+ LLM-triggered speech (see the project's design notes for issue #261 if you're curious why).
735
+
736
+ ### Continuous voice mode (hands-free)
737
+
738
+ The toggle next to the mic button lets visitors **keep talking without touching anything**:
739
+ listen → send → speak the reply → listen again, repeated automatically. With `voice: true`
740
+ the toggle only appears where **both** recognition and speech synthesis are available.
741
+
742
+ - **Status bar**: above the input, showing the current stage (Listening / Thinking /
743
+ Speaking / Waiting for confirmation) plus a stop button. It is exposed to assistive tech
744
+ via `role="status"`.
745
+ - **Incremental speech**: paragraphs are spoken as soon as they are final, so long replies
746
+ do not keep the visitor waiting for the whole response.
747
+ - **Speech formatting**: emphasis markers, link targets and emoji are skipped; tables and
748
+ code blocks are replaced with a single word. Anything past 2000 characters per reply is
749
+ skipped, with a one-time notice.
750
+ - **Pre-execution confirmations** (`requiresConfirmation` tools) pause the loop; it resumes
751
+ after the visitor approves or declines.
752
+ - **Automatic end**: after 2 minutes of silence, when the mic is unavailable or denied, or
753
+ after a repeated network failure. The reason is shown **and spoken**, so visitors who are
754
+ not looking at the screen still learn why it stopped.
755
+ - **The on/off state is not persisted** — every visit starts with the mode off.
756
+
757
+ #### `voiceLoopStartCue` — the opening cue
758
+
759
+ A short phrase spoken right after the toggle is switched on. Defaults to "Go ahead" (en) /
760
+ 「どうぞ」 (ja). Pass a string to use it for every locale, or an object keyed by locale.
761
+
762
+ ```ts
763
+ initWecoolChat({ endpoint, tools: [], voice: true, voiceLoopStartCue: "I'm listening" });
764
+
765
+ // Per-locale
766
+ initWecoolChat({
767
+ endpoint,
768
+ tools: [],
769
+ voice: true,
770
+ voiceLoopStartCue: { ja: "お話しください", en: "I'm listening" },
771
+ });
772
+ ```
773
+
774
+ **Passing an empty string produces no audible cue, but one silent utterance is still
775
+ spoken.** This cannot be skipped: iOS Safari silently ignores speech synthesis on a page
776
+ that has never called it from within a user gesture. Without that silent unlock, **every
777
+ later turn would be silent** — with no error to tell you why.
778
+
779
+ #### Known limitations
780
+
781
+ - **iOS Safari**: as above, speech must be invoked once inside the starting gesture. The
782
+ package handles this for you; it is why an empty `voiceLoopStartCue` still emits a silent
783
+ utterance.
784
+ - **Android**: the device's speech recognition engine plays a short system sound whenever a
785
+ recognition session starts and ends. Continuous voice mode restarts recognition after every
786
+ turn — and repeatedly while the visitor stays silent — so those beeps recur. The Web Speech
787
+ API offers no way to suppress them, and setting `continuous = true` does not help: the engine
788
+ segments sessions on its own regardless. Visitors can silence them by lowering the device's
789
+ notification/system volume (the spoken replies use the media volume, so they stay audible).
790
+ - **Unsupported browsers**: browsers without `SpeechRecognition` (Firefox, for example) do
791
+ not render the toggle at all. The same applies where speech synthesis is unavailable.
792
+ - **The locale handed to plugins is fixed at startup.** Switching with `/lang` updates the
793
+ built-in UI strings and the speech/recognition language, not plugin-side strings.
794
+ - Barging in (talking over the reply to stop it) is not supported. Use the stop button or
795
+ the toggle instead.
796
+
493
797
  ---
494
798
 
495
799
  ## Framework Guides
@@ -640,25 +944,29 @@ const ChatWidget = dynamic(() => import("wecool-chat").then((m) => m.ChatWidget)
640
944
 
641
945
  ## ChatConfig Options
642
946
 
643
- | Property | Type | Required | Default | Description |
644
- | -------------------- | ------------------------------- | -------- | ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
645
- | `endpoint` | `string` | ✓ | — | API endpoint URL (must be HTTPS; `http://localhost` and `http://127.0.0.1` are allowed for development) |
646
- | `apiKey` | `string` | | — | API key issued from the dashboard |
647
- | `tools` | `Tool[]` | ✓ | — | Array of tool definitions |
648
- | `locale` | `"ja" \| "en"` | | `"ja"` | UI language. Set `"en"` for English |
649
- | `placeholder` | `string` | | depends on `locale` | Input field placeholder |
650
- | `theme` | `"auto" \| "light" \| "dark"` | | `"light"` | Color theme. `"auto"` follows OS dark-mode |
651
- | `className` | `string` | | — | Class name applied to the root element |
652
- | `toolTimeout` | `number` | | `30000` | Tool execution timeout (ms) |
653
- | `disableShadowDom` | `boolean` | | `false` | Mount to normal DOM instead of Shadow DOM |
654
- | `layout` | `LayoutPattern` | | `floating-bottom-right` | One of the nine layout patterns. See [Display Modes](#display-modes-layout-patterns). |
655
- | `transparent` | `boolean` | | `false` | Only meaningful for `layout: "header-banner"`. Renders a translucent background that overlays the page content. |
656
- | `narrateToolResults` | `boolean` | | `false` | After every tool result, make an extra LLM call with `tool_choice: "none"` so the model emits a short narration text. See [section](#narrate-tool-results) below for trade-offs. |
657
- | `plugins` | `ChatPlugin[]` | | `[]` | Plugins to load. See the [Plugins](#plugins) section. |
658
- | `onToolExecute` | `(name, args) => void` | | — | Callback fired right before tool execution |
659
- | `onToolResult` | `(name, result) => void` | | — | Callback fired after tool execution finishes |
660
- | `onMessagesChange` | `(messages: Message[]) => void` | | — | Fires whenever the internal `messages` list changes. Use this to mirror the conversation into your own host UI (often paired with `layout: "input-only"`). |
661
- | `onError` | `(error: Error) => void` | | — | Callback fired on error |
947
+ | Property | Type | Required | Default | Description |
948
+ | --------------------- | ------------------------------------------- | -------- | --------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
949
+ | `endpoint` | `string` | ✓ | — | API endpoint URL (must be HTTPS; `http://localhost` and `http://127.0.0.1` are allowed for development) |
950
+ | `apiKey` | `string` | | — | API key issued from the dashboard |
951
+ | `tools` | `Tool[]` | ✓ | — | Array of tool definitions |
952
+ | `locale` | `"ja" \| "en"` | | `"ja"` | UI language. Set `"en"` for English |
953
+ | `placeholder` | `string` | | depends on `locale` | Input field placeholder |
954
+ | `theme` | `"auto" \| "light" \| "dark"` | | `"light"` | Color theme. `"auto"` follows OS dark-mode |
955
+ | `className` | `string` | | — | Class name applied to the root element |
956
+ | `toolTimeout` | `number` | | `30000` | Tool execution timeout (ms) |
957
+ | `disableShadowDom` | `boolean` | | `false` | Mount to normal DOM instead of Shadow DOM |
958
+ | `layout` | `LayoutPattern` | | `floating-bottom-right` | One of the nine layout patterns. See [Display Modes](#display-modes-layout-patterns). |
959
+ | `transparent` | `boolean` | | `false` | Only meaningful for `layout: "header-banner"`. Renders a translucent background that overlays the page content. |
960
+ | `narrateToolResults` | `boolean` | | `false` | After every tool result, make an extra LLM call with `tool_choice: "none"` so the model emits a short narration text. See [section](#narrate-tool-results) below for trade-offs. |
961
+ | `persistConversation` | `"tab"` | | — | Keep the conversation across page navigations and reloads within the same tab (stored in `sessionStorage`, restored on mount). Closing the tab ends it; other tabs get their own conversation. |
962
+ | `errorReporting` | `boolean` | | `true` | Report widget-internal errors (warn+) to `POST /api/v1/client-errors`. No message content / raw API key / host activity is sent. Set `false` to disable. See [Error collection](#error-collection). |
963
+ | `voice` | `boolean` | | `false` | Enable mic input, speech output and continuous voice mode. See [Voice input & speech output](#voice-input--speech-output-voice). |
964
+ | `voiceLoopStartCue` | `string \| Partial<Record<Locale, string>>` | | "Go ahead" (en) / 「どうぞ」 (ja) | Cue spoken when continuous voice mode starts. An empty string still emits one silent utterance, required to unlock speech on iOS. |
965
+ | `plugins` | `ChatPlugin[]` | | `[]` | Plugins to load. See the [Plugins](#plugins) section. |
966
+ | `onToolExecute` | `(name, args) => void` | | — | Callback fired right before tool execution |
967
+ | `onToolResult` | `(name, result) => void` | | — | Callback fired after tool execution finishes |
968
+ | `onMessagesChange` | `(messages: Message[]) => void` | | — | Fires whenever the internal `messages` list changes. Use this to mirror the conversation into your own host UI (often paired with `layout: "input-only"`). |
969
+ | `onError` | `(error: Error) => void` | | — | Callback fired on error |
662
970
 
663
971
  ### Narrate tool results
664
972
 
@@ -685,6 +993,49 @@ Trade-offs:
685
993
 
686
994
  ---
687
995
 
996
+ ## Error collection
997
+
998
+ wecool-chat reports **widget-internal errors** (warning level and above) to your own API's
999
+ error-collection endpoint so you can correlate a user's symptom with a single backend log line.
1000
+ It is **enabled by default** and can be turned off with `errorReporting: false`.
1001
+
1002
+ ```ts
1003
+ initWecoolChat({
1004
+ endpoint: "https://api.wecool.dev",
1005
+ apiKey: "...",
1006
+ tools,
1007
+ errorReporting: false, // opt out of error collection entirely
1008
+ });
1009
+ ```
1010
+
1011
+ ### What is (and isn't) collected
1012
+
1013
+ Reports are sent **only** to your configured `endpoint` (`POST /api/v1/client-errors`), **only** when
1014
+ an error actually occurs, and are **discarded on send failure** (no retry, no local storage — one
1015
+ error, one send attempt).
1016
+
1017
+ Each request also carries an `X-Request-Id` header that wecool-chat generates per request; the same
1018
+ ID is used by the API in its logs and response, so you can trace "this screen's error" to the exact
1019
+ backend log entry.
1020
+
1021
+ Collected fields:
1022
+
1023
+ | Included | Not included (never sent) |
1024
+ | ------------------------------------------------------------------------------------------ | --------------------------------------------------- |
1025
+ | Error `message` / `name` / `stack` (truncated to 5KB), application `errorCode` | **Message content / chat history** (no PII) |
1026
+ | `version`, `requestId`, `sessionId`, `fingerprint` | **Raw API key** (only a masked `abcd…wxyz` is sent) |
1027
+ | `hostOrigin` (origin only), `userAgent`, `network` info, `messageCount`, `streamingActive` | **Host-site activity** (clicks, page navigation) |
1028
+ | | **Page URL / path** (path segments can carry PII) |
1029
+
1030
+ **Errors originating from the host site itself** (scripts outside the widget bundle) are **not**
1031
+ sent. Origin is determined from both the stack trace and the event source; when it can't be
1032
+ determined, the report is dropped rather than sent.
1033
+
1034
+ `sessionId` is kept in `localStorage`. If storage is unavailable (e.g. private browsing), a fresh
1035
+ ID is generated per report and sending still proceeds.
1036
+
1037
+ ---
1038
+
688
1039
  ## Customization
689
1040
 
690
1041
  ### Locale and labels
@@ -703,6 +1054,53 @@ const config = {
703
1054
 
704
1055
  If `placeholder` is provided, it takes precedence over the locale's default placeholder.
705
1056
 
1057
+ **Runtime language switching (`/lang`).** Visitors can switch the widget language at runtime with the `/lang ja` / `/lang en` slash commands (see [Slash commands](#slash-commands)). The chosen language is persisted per-site in the browser (`localStorage` key `wecool-chat:locale`). On the next visit the saved choice takes precedence over `config.locale`, so the initial locale resolves in this order:
1058
+
1059
+ 1. Saved value in `localStorage` (visitor's previous `/lang` choice)
1060
+ 2. `config.locale` (host default)
1061
+ 3. `"ja"` (fallback)
1062
+
1063
+ If `localStorage` is unavailable (e.g. private mode), the switch still applies for the current session but is not persisted. All display strings, `aria-label`s, `placeholder`, and the root `lang` attribute follow the switch immediately.
1064
+
1065
+ > **Known limitation.** The locale passed to plugins is fixed at startup and does **not** follow a `/lang` switch (the public plugin API shape is intentionally kept stable). Likewise, confirmation strings you bake into a tool definition (`confirmationMessage`) do not re-resolve on switch. These only surface during tool confirmation, so the impact is limited.
1066
+
1067
+ ### Slash commands
1068
+
1069
+ Typing `/` at the **start** of the input field opens a command palette. Type to filter (`/cl` narrows to `/clear`), navigate with ↑/↓, confirm with Enter, close with Esc (your input is kept), and complete the highlighted command with Tab. A `/`-prefixed input that matches no command is sent as a normal message. The palette does not open for a `/` in the middle of text, while an IME is composing, or while a response is generating.
1070
+
1071
+ | Command | Effect |
1072
+ | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
1073
+ | `/tools` | Show what visitors can ask, with a display name and example prompts per tool. Clicking an example inserts it into the input (it is **not** auto-sent). |
1074
+ | `/clear` | Ask for confirmation, then clear the current conversation from view and start a new one. Past conversations remain accessible from the conversation selector (this is not a server-side delete). |
1075
+ | `/new` | Start a new conversation immediately (no confirmation). |
1076
+ | `/lang ja` / `/lang en` | Switch the widget display language and persist the choice (see above). |
1077
+ | `/help` | Show the command list and how to use it. |
1078
+
1079
+ To make `/tools` useful, give each tool a visitor-facing display name and example prompts (see [Display metadata for `/tools`](#display-metadata-for-tools)).
1080
+
1081
+ ### Deleting a single conversation
1082
+
1083
+ When a saved conversation is on screen, the header **⋮** menu shows a **Delete this conversation** item (hidden in the new-conversation state). Unlike the two actions below, this is a **permanent server-side delete**: after a confirmation dialog it calls `DELETE /api/v1/conversations/:sessionId`, and the server removes that conversation for good.
1084
+
1085
+ - Only the current conversation is deleted from the server. Other conversations, the input recall history, and the visitor identifier are unchanged.
1086
+ - Any in-progress response is interrupted first, then the view switches to a fresh new-conversation state and the list is refetched.
1087
+ - Authorization is the same strength as conversation restore: only the browser that knows both the session ID and the visitor ID can delete it. Other visitors cannot delete someone else's conversation (the server returns 404). If the conversation was already gone (404), the result is treated as success.
1088
+ - **Not reflected in other tabs immediately** — there is no `storage` change to notify them. Other tabs pick up the removal on their next list refetch (same as existing list-freshness behavior).
1089
+
1090
+ ### Clearing all history from this browser
1091
+
1092
+ The header **⋮** menu includes a **Clear all history from this browser** item. Unlike deleting a single conversation (a server-side delete) or `/clear` (which only clears the current conversation from view), this discards the anonymous visitor identifier stored in the browser (`localStorage` key `wecool-chat:visitor-id`) and issues a fresh one. After a confirmation dialog, running it:
1093
+
1094
+ - Makes past conversations and the ↑/↓ input recall history unreachable **from this browser** (the conversation list becomes empty and a new conversation starts).
1095
+ - Interrupts any in-progress response first, so a cancelled reply does not leak into the new conversation.
1096
+ - Automatically syncs to other tabs of the same site (via the browser `storage` event), which also switch to a fresh new-conversation state.
1097
+
1098
+ > **Known behavior / limitations.**
1099
+ >
1100
+ > - **This is not a server-side delete.** Conversation logs already stored on the server are not removed immediately; they are automatically deleted after the retention period (see the service's privacy policy). Discarding the identifier simply makes them unreachable from this browser — the old identifier can no longer be used to list or restore them.
1101
+ > - **`localStorage`-unavailable environments** (e.g. private mode): the identifier is regenerated for the current tab only, and cross-tab sync does not occur (there is no shared identifier to sync).
1102
+ > - **`layout: "input-only"` has no entry point** for this action (nor for single-conversation delete), because that layout renders no header. Hosts that need it can trigger a reset through their own UI in a future extension.
1103
+
706
1104
  ### Colors / theme
707
1105
 
708
1106
  Switch the built-in color theme with `config.theme`:
@@ -0,0 +1,51 @@
1
+ import { a as s } from "./messages-FvtWi3lI.js";
2
+ import { i as n, r as u, t as l } from "./jsx-runtime-Cyy0mp0f.js";
3
+ import { t as o } from "./createLucideIcon-C7wGkK-Q.js";
4
+ var p = [["path", {
5
+ d: "M20 6 9 17l-5-5",
6
+ key: "1gmf2c"
7
+ }]], d = o("check", p), _ = [["rect", {
8
+ width: "14",
9
+ height: "14",
10
+ x: "8",
11
+ y: "8",
12
+ rx: "2",
13
+ ry: "2",
14
+ key: "17jyea"
15
+ }], ["path", {
16
+ d: "M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",
17
+ key: "zix9uf"
18
+ }]], f = o("copy", _), m = /!\[[^\]]*\]\(\s*data:[^)]*\)/gi, x = /!\[[^\]]*\]\(\s*data:[A-Za-z0-9+/=,;_\-.%\s]*/gi, w = (r) => {
19
+ let e = r.replace(m, "");
20
+ return e = e.replace(x, ""), e;
21
+ }, t = /* @__PURE__ */ s(n(), 1), v = /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, y = /[\u200b\u200c\u200d\u2060\ufeff]/g, g = (r) => r.replace(/\r\n?/g, `
22
+ `).replace(v, "").replace(y, ""), C = 2e3, A = () => {
23
+ const [r, e] = (0, t.useState)(!1), a = (0, t.useRef)(null);
24
+ return (0, t.useEffect)(() => () => {
25
+ a.current !== null && window.clearTimeout(a.current);
26
+ }, []), {
27
+ copied: r,
28
+ copy: (0, t.useCallback)(async (i) => {
29
+ if (navigator.clipboard)
30
+ try {
31
+ await navigator.clipboard.writeText(g(i)), e(!0), a.current !== null && window.clearTimeout(a.current), a.current = window.setTimeout(() => {
32
+ e(!1), a.current = null;
33
+ }, C);
34
+ } catch {
35
+ }
36
+ }, [])
37
+ };
38
+ }, c = l();
39
+ function E({ copied: r }) {
40
+ const e = u(), a = r ? d : f, i = r ? e.copiedLabel : e.copyLabel;
41
+ return /* @__PURE__ */ (0, c.jsxs)(c.Fragment, { children: [/* @__PURE__ */ (0, c.jsx)(a, {
42
+ className: "wecool-icon--xs",
43
+ "aria-hidden": "true"
44
+ }), /* @__PURE__ */ (0, c.jsx)("span", { children: i })] });
45
+ }
46
+ export {
47
+ d as i,
48
+ A as n,
49
+ w as r,
50
+ E as t
51
+ };