wecool-chat 0.5.0 → 0.7.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 (202) hide show
  1. package/CHANGELOG.md +96 -1
  2. package/README.ja.md +354 -30
  3. package/README.md +359 -30
  4. package/dist/_commonjsHelpers-C6fGbg64.js +6 -0
  5. package/dist/browser-beO7dF90.js +1538 -0
  6. package/dist/core/cancellation-log.d.ts.map +1 -0
  7. package/dist/{client.d.ts → core/client.d.ts} +15 -3
  8. package/dist/core/client.d.ts.map +1 -0
  9. package/dist/{hooks → core}/consume-stream.d.ts +9 -5
  10. package/dist/core/consume-stream.d.ts.map +1 -0
  11. package/dist/{i18n → core/i18n}/messages.d.ts +9 -0
  12. package/dist/core/i18n/messages.d.ts.map +1 -0
  13. package/dist/core/index.d.ts +12 -0
  14. package/dist/core/index.d.ts.map +1 -0
  15. package/dist/core/run-conversation.d.ts +38 -0
  16. package/dist/core/run-conversation.d.ts.map +1 -0
  17. package/dist/core/sse-parser.d.ts.map +1 -0
  18. package/dist/{hooks → core}/stream-state.d.ts +14 -11
  19. package/dist/core/stream-state.d.ts.map +1 -0
  20. package/dist/{hooks → core}/tool-runner.d.ts +4 -5
  21. package/dist/core/tool-runner.d.ts.map +1 -0
  22. package/dist/core/types.d.ts +248 -0
  23. package/dist/core/types.d.ts.map +1 -0
  24. package/dist/index.css +1 -1
  25. package/dist/index.d.ts +32 -13
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +11481 -10535
  28. package/dist/plugin/context.d.ts +15 -0
  29. package/dist/plugin/context.d.ts.map +1 -0
  30. package/dist/plugin/define.d.ts +30 -0
  31. package/dist/plugin/define.d.ts.map +1 -0
  32. package/dist/plugin/id.d.ts +19 -0
  33. package/dist/plugin/id.d.ts.map +1 -0
  34. package/dist/plugin/index.d.ts +21 -0
  35. package/dist/plugin/index.d.ts.map +1 -0
  36. package/dist/plugin/logger.d.ts +11 -0
  37. package/dist/plugin/logger.d.ts.map +1 -0
  38. package/dist/plugin/registry.d.ts +21 -0
  39. package/dist/plugin/registry.d.ts.map +1 -0
  40. package/dist/plugin/types.d.ts +109 -0
  41. package/dist/plugin/types.d.ts.map +1 -0
  42. package/dist/plugin.d.ts +2 -0
  43. package/dist/plugin.js +4 -0
  44. package/dist/plugins/qrcode/__tests__/format-result.test.d.ts +2 -0
  45. package/dist/plugins/qrcode/__tests__/format-result.test.d.ts.map +1 -0
  46. package/dist/plugins/qrcode/__tests__/index.test.d.ts +2 -0
  47. package/dist/plugins/qrcode/__tests__/index.test.d.ts.map +1 -0
  48. package/dist/plugins/qrcode/__tests__/tool.test.d.ts +2 -0
  49. package/dist/plugins/qrcode/__tests__/tool.test.d.ts.map +1 -0
  50. package/dist/plugins/qrcode/format-result.d.ts +59 -0
  51. package/dist/plugins/qrcode/format-result.d.ts.map +1 -0
  52. package/dist/plugins/qrcode/index.d.ts +23 -0
  53. package/dist/plugins/qrcode/index.d.ts.map +1 -0
  54. package/dist/plugins/qrcode/tool.d.ts +50 -0
  55. package/dist/plugins/qrcode/tool.d.ts.map +1 -0
  56. package/dist/plugins/qrcode.d.ts +2 -0
  57. package/dist/plugins/qrcode.js +161 -0
  58. package/dist/ui/builtin-tools/get-current-page-info.d.ts +9 -0
  59. package/dist/ui/builtin-tools/get-current-page-info.d.ts.map +1 -0
  60. package/dist/ui/builtin-tools/index.d.ts +3 -0
  61. package/dist/ui/builtin-tools/index.d.ts.map +1 -0
  62. package/dist/ui/builtin-tools/merge-builtin-tools.d.ts +10 -0
  63. package/dist/ui/builtin-tools/merge-builtin-tools.d.ts.map +1 -0
  64. package/dist/ui/components/ChatFooter.d.ts +12 -0
  65. package/dist/ui/components/ChatFooter.d.ts.map +1 -0
  66. package/dist/ui/components/ChatHeader.d.ts +15 -0
  67. package/dist/ui/components/ChatHeader.d.ts.map +1 -0
  68. package/dist/ui/components/ChatHeaderMenu.d.ts +12 -0
  69. package/dist/ui/components/ChatHeaderMenu.d.ts.map +1 -0
  70. package/dist/ui/components/ChatPanel.d.ts +29 -0
  71. package/dist/ui/components/ChatPanel.d.ts.map +1 -0
  72. package/dist/ui/components/ChatWidget.d.ts +3 -0
  73. package/dist/ui/components/ChatWidget.d.ts.map +1 -0
  74. package/dist/{components → ui/components}/CopyIndicator.d.ts +1 -1
  75. package/dist/ui/components/CopyIndicator.d.ts.map +1 -0
  76. package/dist/ui/components/FloatButton.d.ts +13 -0
  77. package/dist/ui/components/FloatButton.d.ts.map +1 -0
  78. package/dist/{components → ui/components}/MessageActionsPopover.d.ts +3 -1
  79. package/dist/ui/components/MessageActionsPopover.d.ts.map +1 -0
  80. package/dist/ui/components/MessageAttachments.d.ts +21 -0
  81. package/dist/ui/components/MessageAttachments.d.ts.map +1 -0
  82. package/dist/ui/components/MessageBubble.d.ts +24 -0
  83. package/dist/ui/components/MessageBubble.d.ts.map +1 -0
  84. package/dist/{components → ui/components}/MessageCopyButton.d.ts +3 -1
  85. package/dist/ui/components/MessageCopyButton.d.ts.map +1 -0
  86. package/dist/{components → ui/components}/MessageEditor.d.ts +1 -1
  87. package/dist/ui/components/MessageEditor.d.ts.map +1 -0
  88. package/dist/{components → ui/components}/MessageList.d.ts +1 -1
  89. package/dist/ui/components/MessageList.d.ts.map +1 -0
  90. package/dist/{components → ui/components}/MessagePopoverButton.d.ts +1 -1
  91. package/dist/ui/components/MessagePopoverButton.d.ts.map +1 -0
  92. package/dist/ui/components/MessageRow.d.ts +18 -0
  93. package/dist/ui/components/MessageRow.d.ts.map +1 -0
  94. package/dist/{components → ui/components}/MessageRowActions.d.ts +2 -2
  95. package/dist/ui/components/MessageRowActions.d.ts.map +1 -0
  96. package/dist/{components → ui/components}/markdown/CodeBlock.d.ts +1 -1
  97. package/dist/ui/components/markdown/CodeBlock.d.ts.map +1 -0
  98. package/dist/{components → ui/components}/markdown/MarkdownMessage.d.ts +5 -1
  99. package/dist/ui/components/markdown/MarkdownMessage.d.ts.map +1 -0
  100. package/dist/ui/components/markdown/sanitize-clipboard.d.ts.map +1 -0
  101. package/dist/ui/components/markdown/stable-prefix.d.ts.map +1 -0
  102. package/dist/ui/components/markdown/strip-data-images.d.ts +2 -0
  103. package/dist/ui/components/markdown/strip-data-images.d.ts.map +1 -0
  104. package/dist/ui/components/markdown/url-transform.d.ts.map +1 -0
  105. package/dist/ui/components/message-row-handlers.d.ts.map +1 -0
  106. package/dist/ui/hooks/use-editing-message.d.ts.map +1 -0
  107. package/dist/ui/hooks/use-menu-keyboard.d.ts +37 -0
  108. package/dist/ui/hooks/use-menu-keyboard.d.ts.map +1 -0
  109. package/dist/ui/hooks/use-message-history.d.ts +20 -0
  110. package/dist/ui/hooks/use-message-history.d.ts.map +1 -0
  111. package/dist/{hooks → ui/hooks}/use-send-message.d.ts +8 -14
  112. package/dist/ui/hooks/use-send-message.d.ts.map +1 -0
  113. package/dist/ui/hooks/use-stream-lifecycle.d.ts.map +1 -0
  114. package/dist/{hooks → ui/hooks}/use-tool-runner.d.ts +2 -3
  115. package/dist/ui/hooks/use-tool-runner.d.ts.map +1 -0
  116. package/dist/ui/hooks/useActiveMessage.d.ts.map +1 -0
  117. package/dist/{hooks → ui/hooks}/useChatStream.d.ts +5 -3
  118. package/dist/ui/hooks/useChatStream.d.ts.map +1 -0
  119. package/dist/ui/hooks/useCopyToClipboard.d.ts.map +1 -0
  120. package/dist/ui/hooks/useDismissOnOutside.d.ts.map +1 -0
  121. package/dist/ui/hooks/useDraggablePanel.d.ts +32 -0
  122. package/dist/ui/hooks/useDraggablePanel.d.ts.map +1 -0
  123. package/dist/ui/hooks/useFocusTrap.d.ts +28 -0
  124. package/dist/ui/hooks/useFocusTrap.d.ts.map +1 -0
  125. package/dist/ui/hooks/useMediaQuery.d.ts +17 -0
  126. package/dist/ui/hooks/useMediaQuery.d.ts.map +1 -0
  127. package/dist/ui/hooks/useScrollToBottom.d.ts +22 -0
  128. package/dist/ui/hooks/useScrollToBottom.d.ts.map +1 -0
  129. package/dist/ui/i18n/format-time.d.ts +10 -0
  130. package/dist/ui/i18n/format-time.d.ts.map +1 -0
  131. package/dist/ui/i18n/locale-context.d.ts +10 -0
  132. package/dist/ui/i18n/locale-context.d.ts.map +1 -0
  133. package/dist/{i18n → ui/i18n}/messages-context.d.ts +1 -1
  134. package/dist/ui/i18n/messages-context.d.ts.map +1 -0
  135. package/dist/ui/mount.d.ts +19 -0
  136. package/dist/ui/mount.d.ts.map +1 -0
  137. package/dist/ui/styles/index.d.ts.map +1 -0
  138. package/dist/ui/types.d.ts +42 -0
  139. package/dist/ui/types.d.ts.map +1 -0
  140. package/package.json +39 -17
  141. package/dist/client.d.ts.map +0 -1
  142. package/dist/components/ChatFooter.d.ts +0 -10
  143. package/dist/components/ChatFooter.d.ts.map +0 -1
  144. package/dist/components/ChatHeader.d.ts +0 -7
  145. package/dist/components/ChatHeader.d.ts.map +0 -1
  146. package/dist/components/ChatPanel.d.ts +0 -16
  147. package/dist/components/ChatPanel.d.ts.map +0 -1
  148. package/dist/components/ChatWidget.d.ts +0 -3
  149. package/dist/components/ChatWidget.d.ts.map +0 -1
  150. package/dist/components/CopyIndicator.d.ts.map +0 -1
  151. package/dist/components/FloatButton.d.ts +0 -7
  152. package/dist/components/FloatButton.d.ts.map +0 -1
  153. package/dist/components/MessageActionsPopover.d.ts.map +0 -1
  154. package/dist/components/MessageBubble.d.ts +0 -15
  155. package/dist/components/MessageBubble.d.ts.map +0 -1
  156. package/dist/components/MessageCopyButton.d.ts.map +0 -1
  157. package/dist/components/MessageEditor.d.ts.map +0 -1
  158. package/dist/components/MessageList.d.ts.map +0 -1
  159. package/dist/components/MessagePopoverButton.d.ts.map +0 -1
  160. package/dist/components/MessageRow.d.ts +0 -17
  161. package/dist/components/MessageRow.d.ts.map +0 -1
  162. package/dist/components/MessageRowActions.d.ts.map +0 -1
  163. package/dist/components/markdown/CodeBlock.d.ts.map +0 -1
  164. package/dist/components/markdown/MarkdownMessage.d.ts.map +0 -1
  165. package/dist/components/markdown/sanitize-clipboard.d.ts.map +0 -1
  166. package/dist/components/markdown/stable-prefix.d.ts.map +0 -1
  167. package/dist/components/markdown/url-transform.d.ts.map +0 -1
  168. package/dist/components/message-row-handlers.d.ts.map +0 -1
  169. package/dist/hooks/cancellation-log.d.ts.map +0 -1
  170. package/dist/hooks/consume-stream.d.ts.map +0 -1
  171. package/dist/hooks/run-conversation.d.ts +0 -23
  172. package/dist/hooks/run-conversation.d.ts.map +0 -1
  173. package/dist/hooks/stream-state.d.ts.map +0 -1
  174. package/dist/hooks/tool-runner.d.ts.map +0 -1
  175. package/dist/hooks/use-editing-message.d.ts.map +0 -1
  176. package/dist/hooks/use-send-message.d.ts.map +0 -1
  177. package/dist/hooks/use-stream-lifecycle.d.ts.map +0 -1
  178. package/dist/hooks/use-tool-runner.d.ts.map +0 -1
  179. package/dist/hooks/useActiveMessage.d.ts.map +0 -1
  180. package/dist/hooks/useChatStream.d.ts.map +0 -1
  181. package/dist/hooks/useCopyToClipboard.d.ts.map +0 -1
  182. package/dist/hooks/useDismissOnOutside.d.ts.map +0 -1
  183. package/dist/hooks/useScrollToBottom.d.ts +0 -7
  184. package/dist/hooks/useScrollToBottom.d.ts.map +0 -1
  185. package/dist/i18n/messages-context.d.ts.map +0 -1
  186. package/dist/i18n/messages.d.ts.map +0 -1
  187. package/dist/sse-parser.d.ts.map +0 -1
  188. package/dist/styles/index.d.ts.map +0 -1
  189. package/dist/types.d.ts +0 -138
  190. package/dist/types.d.ts.map +0 -1
  191. /package/dist/{hooks → core}/cancellation-log.d.ts +0 -0
  192. /package/dist/{sse-parser.d.ts → core/sse-parser.d.ts} +0 -0
  193. /package/dist/{components → ui/components}/markdown/sanitize-clipboard.d.ts +0 -0
  194. /package/dist/{components → ui/components}/markdown/stable-prefix.d.ts +0 -0
  195. /package/dist/{components → ui/components}/markdown/url-transform.d.ts +0 -0
  196. /package/dist/{components → ui/components}/message-row-handlers.d.ts +0 -0
  197. /package/dist/{hooks → ui/hooks}/use-editing-message.d.ts +0 -0
  198. /package/dist/{hooks → ui/hooks}/use-stream-lifecycle.d.ts +0 -0
  199. /package/dist/{hooks → ui/hooks}/useActiveMessage.d.ts +0 -0
  200. /package/dist/{hooks → ui/hooks}/useCopyToClipboard.d.ts +0 -0
  201. /package/dist/{hooks → ui/hooks}/useDismissOnOutside.d.ts +0 -0
  202. /package/dist/{styles → ui/styles}/index.d.ts +0 -0
package/CHANGELOG.md CHANGED
@@ -5,13 +5,108 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## [Unreleased]
8
+ ## [0.7.0] - 2026-06-04
9
+
10
+ ### Added
11
+
12
+ - **公式 layout 9 パターンを整備**。`ChatConfig.layout` で `floating-bottom-right` / `floating-bottom-left` / `floating-top-right` / `floating-top-left` / `sidebar-left` / `sidebar-right` / `header-banner` / `footer-fixed` / `inline-custom` / `input-only` から選択可能。`layout` 未指定時は従来の右下フローティング互換(後方互換)。
13
+ - **`layout: "input-only"` モードを追加**。入力欄だけをマウントし、メッセージ列はホスト側 UI が描画する「ヘッドレス入力」用途。`onMessagesChange` callback と組み合わせて wecool-chat の messages をホスト側 store に同期する設計を可能にする。
14
+ - **`header-banner` 用 `transparent: boolean` オプション**。本文を透かす半透明バナーを描画する。
15
+ - **`onMessagesChange?: (messages: Message[]) => void` callback**。内部 `messages` 配列の変化(新規発話 / ストリーミング更新 / 削除)を全件ホストに通知する。`input-only` モードとの併用が主用途だが他 layout でも使える。
16
+ - **`initWecoolChat` の戻り値を callable controller object に拡張**。従来の `() => void`(unmount)を保持しつつ、`.sendMessage(text)` / `.editMessage(id, content)` / `.regenerate()` / `.clear()` メソッドを追加し、ホスト側 UI からチャットを駆動可能にした。既存コード(`const cleanup = initWecoolChat(...); cleanup()`)は無改修で動く(後方互換)。
17
+ - **`narrateToolResults?: boolean` opt-in を追加**。`true` のとき、tool 実行直後にもう 1 回 LLM へ `tool_choice: "none"` で問い合わせて短いナレーションテキストを取得し、画面に流す。`gpt-4o-mini` 等が tool 呼び出し時に content を省く挙動への対策。コスト / レイテンシは ~2 倍になるため既定は off。多段 tool フロー(Dining 注文等)で「次に何をするか」を会話的に伝えたい場面で使う。
18
+ - ナレーション利用時にループ予算が足りなくなる事故を防ぐため `MAX_TOOL_ITERATIONS` を 5 → 15 に拡張。
19
+ - **プラグインシステム基盤を導入**(issue #40)。第三者が `wecool-chat/plugin` サブパスから型と `definePlugin` を import するだけで独自プラグインを npm 公開でき、利用者は `npm install` + `config.plugins` への追加だけで使える。
20
+ - 公開 contract: `ChatPlugin` / `PluginContext` / `PluginTool` / `PluginToolInvocation` / `PluginLogger` / `PluginApiVersion` / `PluginId` 型
21
+ - `definePlugin` helper(identity 関数、型推論起点)
22
+ - サブパス export `wecool-chat/plugin`(gzipped ~90 bytes、React 非依存)
23
+ - `pluginApiVersion: 1` 必須。`wecool-chat` 本体の semver とは独立した SDK contract version。不一致時は plugin skip + warn
24
+ - `PluginRegistry` クラスで setup の例外隔離、同一 plugin 内重複 error / 別 plugin 間重複後勝ち / plugin id 重複先勝ち、cleanup の LIFO 実行を実装
25
+ - `ChatConfig.plugins?: ChatPlugin[]` を追加
26
+ - `PluginContext.disposeSignal` で plugin 寿命の AbortSignal を提供
27
+ - `PluginToolInvocation` で tool 呼び出しごとの signal / logger / locale を提供
28
+ - `ctx.registerTool<TArgs, TResult>({...})` の generics で args/result の型を narrow 可能
29
+ - 既存 `Tool.handler` に optional 第2引数 `ctx?: { signal: AbortSignal }` を追加。既存 user tools は無改修で動く(関数引数 contravariance で型互換)。Plugin 経由の handler はここから signal を受け取れる。
30
+ - main entry `wecool-chat` からも plugin 型・`definePlugin` を re-export(DX 用)。
31
+ - **公式プラグイン `wecool-chat/plugins/qrcode` を追加**(issue #43)。URL / Wi-Fi / vCard / 位置情報 などからスキャン可能な QR コードを生成する `generate_qrcode` tool を提供。
32
+ - QR 画像はチャットバブル内にインライン描画され、ダウンロードボタンが添えられる。handler 自体はファイル DL を発火しない (ユーザーがボタンを押した時にだけ DL が走る)。
33
+ - 画像 base64 は `attachments` 経路でクライアントだけに留め、LLM context / バックエンドには戻さない。
34
+ - 入口で危険プロトコル (`javascript:` / `vbscript:` / `data:` / `file:`) と制御文字を弾く Level 1 セキュリティチェック付き (`unsafe_content`)。URL レピュテーション照合は別 issue で扱う。
35
+ - factory `createQrcodePlugin({ defaultSize, defaultErrorCorrectionLevel, maxTextLength })` で既定値を設定可能(既定: 256 px / `"M"` / 2000 文字)。
36
+ - `qrcode` は handler 内動的 import で読み込み、`dist/plugins/qrcode.js` + 関連 chunk 内に閉じ込め。**コアバンドル `dist/index.js` には混入しない**。
37
+ - 戻り値は `{ ok: true | false, ... }` の discriminated union 形式。中断 (AbortError) のみ throw し、それ以外の失敗 (`text_too_long` / `invalid_args` / `browser_only` / `generation_failed` / `unsafe_content`) は `{ ok: false, error, message, hint? }` で返す。LLM がリトライ判断 (誤り訂正レベル↓・テキスト短縮等) しやすい形に統一。第三者プラグインの推奨パターンとしても提示。
38
+ - subpath export: `wecool-chat/plugins/qrcode`。
39
+ - 計測値: `dist/plugins/qrcode.js` 2.18 KB gzipped、関連 chunk 11.39 KB gzipped、合計 ~14 KB gzipped。
40
+ - `ToolHandlerEnvelope { forLLM, attachments }` を tool 戻り値形式として追加。「LLM 履歴に乗せる結果」と「クライアント表示用の添付物」を分離する。Tool が画像など重いペイロードを返したい場合に context 肥大を防ぐ。 envelope を返さない既存 user tools は破壊なし(戻り値そのまま forLLM 扱い)。
41
+ - `Message.attachments?: ToolAttachment[]` を追加。tool ロールメッセージが画像等を持ち、UI が直後の assistant バブル直下にまとめて描画する。
42
+ - `MessageAttachments` UI コンポーネント。画像 + DL ボタンを表示。mimeType ホワイトリスト (png/jpeg/gif/webp) と base64 regex の二重 validation 通過後しか DL が走らない。
43
+ - **チャット入力欄を `<textarea>` 化し、複数行入力と履歴呼び戻しに対応**(issue #118)。
44
+ - `Shift+Enter` で改行入力、`Enter` 単体は従来通り送信。IME 変換中の Enter / Esc / ↑ / ↓ は無視。
45
+ - 入力欄は 1 行スタート、入力量に応じて最大 2 行まで自動拡張、超えると内部スクロール。
46
+ - `↑` / `↓` キーで過去送信メッセージの呼び戻し。カーソルが 1 行目の先頭にあって上に動けないとき `↑` で履歴遡り、最終位置で `↓` で履歴 navigate。遡り開始前のドラフトは `↓` で最新を超えたタイミングで復元。
47
+ - 履歴は localStorage に永続化(リロード後も呼び戻せる)。1 スコープあたり 50 件 / 1 件 2,000 文字を上限とし、連続同一文面は 1 件に圧縮。localStorage 利用不可時はメモリのみで動作。
48
+ - **メッセージ送信時刻を発言バブル直下に常時表示**(issue #94)。user は送信時刻、assistant は応答完了時刻(ストリーミング完了時に上書き)。`<time datetime="ISO">{HH:mm}</time>` でセマンティクスを保ち、`config.locale` に応じてフォーマット切替(`ja` = 24 時間制 `14:32` / `en` = 12 時間制 + AM/PM `2:32 PM`)。
49
+ - `LocaleProvider` / `useLocale()` を追加し、文言取得 (`useMessages()`) とは独立に locale 値そのものを配信する経路を新設。日付・時刻フォーマット等、locale を直接必要とする UI が将来増えても流用できる。
50
+
51
+ ### Changed
52
+
53
+ - ツール解決順序を明示: `builtin tools < plugin tools (declared order) < config.tools (user)`。同名衝突時は後ろが勝つ。
54
+ - `tool-runner.ts` が `tool.handler(args, { signal })` の形で handler を呼び出すように変更(既存 handler は第2引数を無視可能)。
55
+
56
+ ### Fixed
57
+
58
+ - ストリーミング応答中にホストページが上方向へ勝手にスクロールするバグを修正。`useScrollToBottom` を `scrollIntoView` から container 自身の `scrollTo` 呼び出しに変更し、スクロール対象を `.wecool-message-list` 内部に限定(祖先 window へ伝播しない)。
59
+ - **継続ターンで user 発話が API リクエストの `body.history` から欠落する不具合を修正**。`useSendMessage.buildInitialHistory` が新規 user message を history に含めない仕様だったため、ナレーション後の継続ターンで LLM が直前のユーザー意図を読めない事故が起きていた。iter1 完了時に初回 user 発話を history に追記することで、iter2 以降の `body.history` にも必ず最新 user 発話が乗るようにした。
60
+ - **`narrateToolResults` 有効時に最終ターンで AI コメントが重複表示される問題を修正**。ナレーション直後の通常ラウンドが text のみで終わった場合、wecool-chat は新しい placeholder を `removeMessageById` で削除して重複を抑止する。
61
+
62
+ ### Migration
63
+
64
+ - 破壊的変更なし。既存 v0.6.0 利用者は何も書き換える必要がない。
65
+ - `layout` / `narrateToolResults` / `onMessagesChange` / `plugins` などの新機能は **全て optional**。未指定時は v0.6.0 と同じ挙動。
66
+ - `initWecoolChat` の戻り値は callable function のまま (= 旧 `() => void`) + メソッドを生やしたハイブリッド型。既存の `const cleanup = initWecoolChat(...); cleanup()` パターンはそのまま動く。
67
+
68
+ ## [0.6.0] - 2026-05-20
69
+
70
+ ### Added
71
+
72
+ - **組み込み Tool `getCurrentPageInfo` を自動登録**: 利用者が `tools` 配列に何も書かなくても、現在ページの URL / title / description / pathname / host / language を LLM が取得できる。`ChatWidget` 内で `mergeBuiltinTools()` を経由させているため、`initWecoolChat` 経由・React 直接利用どちらでも有効。同名 Tool を利用者が渡せば builtin はスキップされ、無効化・差し替え可能。
73
+ - `getCurrentPageInfo` / `mergeBuiltinTools` を `wecool-chat` 本体から export。手動 merge やカスタム ChatWidget 利用にも対応。
74
+ - `config.theme: "auto" | "light" | "dark"` を追加(デフォルト `"light"` で既存挙動維持)。`"auto"` 時は OS の `prefers-color-scheme` に追従し、CSS 側で完結することで JS マウント遅延に起因するフラッシュを回避。
75
+ - ダークモード対応の CSS 変数 (`--wecool-color-*`) を Shadow Host に定義。`@media (prefers-color-scheme: dark)` および `[data-wecool-theme="dark"]` で切替。
76
+ - `prefers-reduced-motion` 対応(WCAG 2.3.3)。CSS の `@media` で全アニメーション・トランジションを停止し、`useScrollToBottom` 内では `scrollIntoView({ behavior: "auto" })` に切替。
77
+ - `forced-colors` 対応(Windows 高コントラストモード)。ボタン・メッセージバブル・フォーカスリングをシステムカラーに切替。
78
+ - `useMediaQuery` フックを追加。`prefers-reduced-motion` 等を React 側で動的に判定する用途。
79
+ - ルート要素・Shadow Host・dialog に `lang` 属性を付与(WCAG 3.1.1 / 3.1.2)。`config.locale` から自動反映。
80
+
81
+ ### Security
82
+
83
+ - `ChatClient` の endpoint は HTTPS のみ受け付けるように検証を追加(`http://localhost` / `http://127.0.0.1` は開発用途で例外)。SSL stripping 攻撃対策。
84
+ - 文字列セレクタ経由でウィジェットをマウントする際に簡易バリデーションを追加。`*` や空文字など乱暴なセレクタを弾き、ホスト DOM の意図せぬ破壊を防ぐ。
85
+ - Shadow Root / Light Root のホスト DOM ID を `crypto.randomUUID()` ベースの動的 ID に変更。同一ページに複数ウィジェットを埋め込んでも衝突しない。
86
+ - 送信エラー時の `console.error` から `err` オブジェクト全体ではなくメッセージのみを出力(機密情報の漏洩防止)。詳細解析は `onError` コールバック経由で利用者側で行うこと。
87
+ - 本番ビルド時に `console.log` / `console.debug` / `debugger` を esbuild で除去(`console.error` / `console.warn` は維持)。
88
+
89
+ ### Changed
90
+
91
+ - カラーコントラスト修正: 空状態テキスト色を `#a1a1aa` → `#71717a`(WCAG AA 4.5:1 達成)。
92
+ - `chat.css` / `markdown.css` のハードコード色を `--wecool-` プレフィックスの CSS 変数へ全面置換。
93
+ - 主要操作ボタン(送信・閉じる・FloatButton)に `min-width/height: 2.75rem` (44 px) を保証(WCAG 2.5.5 AAA 達成)。
94
+ - 密集 UI(メッセージアクション ⋮・popover 内ボタン・コードコピー)に `min-width/height: 1.5rem` (24 px) を保証(WCAG 2.5.8 AA 達成)。
9
95
 
10
96
  ### Documentation
11
97
 
12
98
  - README を全面刷新。クイックスタート、想定ユースケース、フレームワーク別ガイド(Vue / Svelte / Astro / 素 HTML / Next.js)、ツール定義の詳細例、トラブルシューティング、ヘッドレス利用、TypeScript 型 export 一覧を追加。
99
+ - README に「Built-in tools」セクションを追加し、`getCurrentPageInfo` の自動組込・上書きで無効化する方法・URL に機密情報を含むページでの取扱注意を記載。
13
100
  - hero GIF / フローティング表示のスクリーンショットを追加(`docs/screenshots/`)。
14
101
  - `package.json` に `repository` / `bugs.url` を追加し、`keywords` に `widget` / `shadow-dom` / `chatbot` / `sse` / `vue` を追加。
102
+ - `theme` オプションと WCAG 2.2 SC 2.4.11 / 3.2.6 のホスト側ガイダンスを README に追記。
103
+ - `docs/accessibility.md` を新規作成。対応済み WCAG SC・既知の制約・ホスト側で守る事項を文書化。
104
+
105
+ ### Notes
106
+
107
+ - `theme` プロパティは optional のため既存利用コードに変更不要。明示しなければ従来どおりライトテーマで動作する。
108
+ - `getCurrentPageInfo` は `window.location.href` をクエリパラメータ・ハッシュ込みで LLM に渡す。URL 自体にシークレットを持つページ(パスワードリセットトークン、OAuth コールバックなど)では README に従い同名 no-op Tool で上書きすること。
109
+ - 利用ホスト側で SC 2.4.11 (Focus Not Obscured) と SC 3.2.6 (Consistent Help) を満たすには、フローティングウィジェットを他の固定要素に隠されない位置に配置し、全ページで同じ `position` を指定すること(README ガイダンス参照)。
15
110
 
16
111
  ## [0.4.0] - 2026-05-06
17
112
 
package/README.ja.md CHANGED
@@ -11,9 +11,11 @@
11
11
 
12
12
  ユーザーが「ダークモードにして」「新着順に並べて」のように話しかけると、LLM があなたの定義した JavaScript 関数を自動で選んで実行します。React でも Vue でも Vanilla JS でも、`npm install` だけで導入できます。
13
13
 
14
- ![hero demo](./docs/screenshots/hero.gif)
14
+ ![hero demo](https://unpkg.com/wecool-chat@latest/docs/screenshots/hero.gif)
15
15
 
16
- [ライブデモ](https://demo.wecool.dev) ・ [ダッシュボード](https://app.wecool.dev) ・ [npm](https://www.npmjs.com/package/wecool-chat)
16
+ [ライブデモ](https://demo.wecool.dev) ・ [LLM 駆動の Dining デモ](https://demo.wecool.dev/demo/living-thread/dining) ・ [ダッシュボード](https://app.wecool.dev) ・ [npm](https://www.npmjs.com/package/wecool-chat)
17
+
18
+ > 🍝 **会話だけで注文を完走するデモ**: [demo.wecool.dev/demo/living-thread/dining](https://demo.wecool.dev/demo/living-thread/dining) — 要望を入力すると LLM が 7 個の tool (料理選択 → 数量 → アレルゲン → 確定) を順番に実行します。`layout: "input-only"` + `narrateToolResults` を組み合わせた事例です。
17
19
 
18
20
  ---
19
21
 
@@ -108,28 +110,108 @@ function App() {
108
110
 
109
111
  ---
110
112
 
111
- ## 動作モード
113
+ ## 動作モード(Layout パターン)
112
114
 
113
- ウィジェットには 2 つの表示モードがあります。
115
+ wecool-chat は 9 種類の公式 layout を提供しています。`ChatConfig` の `layout` で選択します。
114
116
 
115
- ### フローティング(推奨)
117
+ ### Layout 一覧
116
118
 
117
- 画面の角に常駐するチャットボタン。クリックでパネルが開きます。サポート用途・ツアー的な体験に向きます。
119
+ | `layout` の値 | 配置 | 主な用途 |
120
+ | ----------------------- | -------------------------- | ---------------------------------------------------------------------------------- |
121
+ | `floating-bottom-right` | 画面右下 | 既定。クラシックなチャット bot |
122
+ | `floating-bottom-left` | 画面左下 | 上と同じだが左側 |
123
+ | `floating-top-right` | 画面右上 | 右下に他 UI がある場合 |
124
+ | `floating-top-left` | 画面左上 | 同上、左側 |
125
+ | `sidebar-left` | 画面左端、約 360px 幅 | 常駐アシスタント(学習・ドキュメント等) |
126
+ | `sidebar-right` | 画面右端、約 360px 幅 | 設定・ヘルプ |
127
+ | `header-banner` | 画面上端、約 80px 高 | コンシェルジュ型。`transparent` で透過表示も可 |
128
+ | `footer-fixed` | 画面下端、横幅いっぱい | 常に見える小さなドック |
129
+ | `inline-custom` | アプリ側が指定したコンテナ | レイアウト完全カスタム(Shadow DOM 無効、CSS は自前) |
130
+ | `input-only` | アプリ側が指定したコンテナ | 入力欄のみマウント。メッセージ列はホスト側で描画する(下記「ヘッドレス入力」参照) |
118
131
 
119
- ![floating mode](./docs/screenshots/mode-floating.png)
132
+ ### 切り替え方
120
133
 
121
- ### 埋め込み
134
+ ```ts
135
+ import { initWecoolChat } from "wecool-chat";
122
136
 
123
- 任意のコンテナ要素の中にパネルを直接配置します。ダッシュボードの一部にアシスタント枠として組み込む用途に向きます。
137
+ initWecoolChat({
138
+ endpoint: "https://your-api.example.com",
139
+ apiKey: "wlt_...",
140
+ tools: [],
141
+ layout: "sidebar-left",
142
+ });
143
+ ```
124
144
 
125
- ### 切り替え方
145
+ `header-banner` では `transparent: true` を追加すると半透明オーバーレイになります。
146
+
147
+ ### React で使う場合
148
+
149
+ `<ChatWidget />` を直接使うときは従来通り `floating` / `position` を渡します。`layout` は `initWecoolChat` 専用で、内部的に同等の props に変換されます。`sidebar-*` / `header-banner` / `footer-fixed` のような外殻が必要な layout は `initWecoolChat` 経由のみで提供します。
150
+
151
+ ### `inline-custom` を選ぶ場面
152
+
153
+ アプリ自身のレイアウトの中に入力欄や UI を「部品」として埋め込みたい場合に使います。wecool-chat は Shadow DOM を作らずホスト DOM に直接マウントするので:
154
+
155
+ - ホストサイトの CSS が効きます(好きにスタイル可能)
156
+ - コンテナのサイズや位置の制御はアプリ側責任
157
+
158
+ ```ts
159
+ initWecoolChat({ endpoint, apiKey, tools, layout: "inline-custom" }, "#my-chat-slot");
160
+ ```
161
+
162
+ ### ヘッドレス入力 + 独自スレッド(`input-only`)
163
+
164
+ メッセージ一覧をホスト側 UI で描画したいときに使います。たとえば、ユーザー発話・AI 応答・tool が描画した UI 部品を 1 本の時系列に積み上げて並べる、Living Thread 系のシーンで便利です。`layout: "input-only"` を指定すると入力欄だけがマウントされ、メッセージ配列は `onMessagesChange` で渡されます。
126
165
 
127
- | 用途 | React | 非 React |
128
- | -------------- | -------------------------------------- | ------------------------------------------- |
129
- | フローティング | `<ChatWidget config={...} floating />` | `initWecoolChat(config)` |
130
- | 埋め込み | `<ChatWidget config={...} />` | `initWecoolChat(config, "#chat-container")` |
166
+ ```ts
167
+ const controller = initWecoolChat(
168
+ {
169
+ endpoint: "https://your-api.example.com",
170
+ apiKey: "wlt_...",
171
+ tools,
172
+ layout: "input-only",
173
+ onMessagesChange: (messages) => {
174
+ // wecool-chat 内のメッセージ列。ホスト側 UI / store に同期する
175
+ hostStore.syncMessages(messages);
176
+ },
177
+ },
178
+ "#wecool-input-dock"
179
+ );
180
+
181
+ // ホスト側 UI からチャットを駆動できる
182
+ controller.sendMessage("こんにちは");
183
+ controller.editMessage("msg-123", "こんにちは(編集)");
184
+ controller.regenerate();
185
+ controller.clear();
186
+
187
+ // controller 自体は callable。呼ぶと unmount される(後方互換)
188
+ controller();
189
+ ```
190
+
191
+ `narrateToolResults`(後述)と組み合わせると、tool 実行ごとに短い説明テキストを差し挟めるので「次に何をするか」がユーザーに見えやすくなります。
192
+
193
+ ### Controller API(`initWecoolChat` の戻り値)
131
194
 
132
- `initWecoolChat` は第二引数を省略するとフローティング、`HTMLElement` か CSS セレクタを渡すと埋め込みになります。
195
+ `initWecoolChat` の戻り値は callable な controller オブジェクトです。**呼ぶとアンマウント**(旧 `() => void` と完全に同じ動き)。それに加えて以下のメソッドを持ち、ホスト側 UI からチャットを外側から駆動できます。
196
+
197
+ | メソッド | 動作 |
198
+ | ------------------------------------- | -------------------------------------------------- |
199
+ | `controller()` | ウィジェットをアンマウント(旧来の戻り値型と同じ) |
200
+ | `controller.sendMessage(s)` | ユーザーが入力したかのように送信 |
201
+ | `controller.editMessage(id, content)` | 既存のユーザー発話を書き換え、その時点から再実行 |
202
+ | `controller.regenerate()` | 直近の AI 応答を破棄して再生成 |
203
+ | `controller.clear()` | 履歴を全消去 |
204
+
205
+ controller は layout が floating か sidebar か input-only かに関わらず同じ形です。
206
+
207
+ ### 後方互換
208
+
209
+ `layout` は省略可能で、省略すると従来挙動と完全に一致します:
210
+
211
+ - `initWecoolChat(config)` → 右下フローティング
212
+ - `initWecoolChat(config, "#container")` → コンテナに埋め込み(Shadow DOM)
213
+
214
+ 戻り値は callable なので、`const cleanup = initWecoolChat(...); cleanup()` のような既存コードはそのまま動きます。
133
215
 
134
216
  ---
135
217
 
@@ -220,6 +302,193 @@ const config = {
220
302
 
221
303
  > **注意**: `handler` 内で `AbortSignal` を受け取って中断する仕組みは現バージョンでは未対応です。重い処理は handler 側で軽量化してください。
222
304
 
305
+ ### 組み込みツール(Built-in tools)
306
+
307
+ wecool-chat はすぐ使えるツールを同梱しており、**自動で登録されます**。利用者は `tools` 配列に追加する必要はありません(`ChatWidget` が内部で混ぜ込みます)。
308
+
309
+ | ツール | 役割 |
310
+ | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
311
+ | `getCurrentPageInfo` | 埋め込みページの URL / タイトル / description / pathname / host / 言語 を返します。「今見ているページは何?」のような問いに LLM が答えられるようになります。 |
312
+
313
+ ```ts
314
+ import { initWecoolChat } from "wecool-chat";
315
+
316
+ // getCurrentPageInfo は自動で組み込まれるため `tools` に書く必要なし。
317
+ initWecoolChat({
318
+ endpoint: "https://api.example.com",
319
+ tools: [
320
+ myCustomTool, // 独自ツールだけ書けば OK
321
+ ],
322
+ });
323
+ ```
324
+
325
+ バックエンド側にも `web_search` ツールが標準で登録されており、LLM へ自動的に提示されます(クライアント側で追加実装は不要)。なお `web_search` の結果は実際の Web 検索ではなく LLM 自身の知識から生成されるため、最新情報については参考程度に扱ってください。
326
+
327
+ #### 組み込みツールを上書き/無効化する
328
+
329
+ 組み込みツールを止めたい・差し替えたいときは、**同じ `name` の Tool を渡せばあなたの Tool が優先されます**。
330
+
331
+ ```ts
332
+ initWecoolChat({
333
+ endpoint: "https://api.example.com",
334
+ tools: [
335
+ {
336
+ name: "getCurrentPageInfo", // 同名で組み込みを無効化
337
+ description: "disabled",
338
+ parameters: { type: "object", properties: {} },
339
+ handler: () => ({ disabled: true }),
340
+ },
341
+ ],
342
+ });
343
+ ```
344
+
345
+ > ⚠️ **`getCurrentPageInfo` のセキュリティ注意**: handler は `window.location.href` を**クエリパラメータやハッシュ込みで**そのまま返します。URL 自体にシークレットを含むページ(パスワードリセットトークン、フラグメントに OAuth `access_token` を載せたコールバック、署名付きダウンロード URL など)では、上記のように同名 no-op Tool で必ず上書きしてください(そうしないとそれらの値が tool result として LLM プロバイダに送信されます)。
346
+
347
+ ---
348
+
349
+ ## プラグイン
350
+
351
+ プラグインは複数のツールと関連 cleanup を 1 つの再利用単位にまとめて npm 公開できる仕組みです。第三者は `wecool-chat/plugin` だけを参照して plugin パッケージを公開でき、利用者は `npm install` して `config.plugins` に渡すだけで組み込めます。
352
+
353
+ ### プラグインを作る
354
+
355
+ ```ts
356
+ // my-plugin/src/index.ts
357
+ import { definePlugin } from "wecool-chat/plugin";
358
+
359
+ export default definePlugin({
360
+ pluginApiVersion: 1,
361
+ id: "acme/clock", // "scope/name" 形式(小文字+ハイフン、npm 名と合わせる)
362
+ version: "0.1.0",
363
+ setup(ctx) {
364
+ ctx.registerTool({
365
+ name: "get_current_time",
366
+ description: "現在時刻を ISO 文字列で返す",
367
+ parameters: { type: "object", properties: {} },
368
+ handler: (_args, invocation) => {
369
+ // invocation.signal / invocation.locale / invocation.logger が使える
370
+ return { now: new Date().toISOString() };
371
+ },
372
+ });
373
+ ctx.onCleanup(() => ctx.logger.info("clock plugin disposed"));
374
+ },
375
+ });
376
+ ```
377
+
378
+ ### プラグインを使う
379
+
380
+ ```tsx
381
+ import { initWecoolChat } from "wecool-chat";
382
+ import clockPlugin from "@acme/wecool-plugin-clock";
383
+
384
+ initWecoolChat({
385
+ endpoint: "https://api.example.com/chat",
386
+ tools: [],
387
+ plugins: [clockPlugin],
388
+ });
389
+ ```
390
+
391
+ ### `PluginContext` の中身
392
+
393
+ | API | 用途 |
394
+ | -------------------- | ------------------------------------------------------------------------------------------------------------------------ |
395
+ | `registerTool(tool)` | Tool を登録。同一 plugin 内で同名は error、別 plugin 間は後勝ち + warn。`<TArgs, TResult>` generics で型を narrow できる |
396
+ | `onCleanup(fn)` | unmount 時に `fn` を実行(LIFO)。`removeEventListener` などの後片付け |
397
+ | `logger` | scope 付き logger(`[wecool-chat:<plugin-id>]` prefix)。`console.*` 直接利用より推奨 |
398
+ | `disposeSignal` | plugin 寿命の `AbortSignal`。長時間 `fetch` に渡してキャンセル連動 |
399
+ | `locale`, `pluginId` | i18n / 診断用の read-only 情報 |
400
+
401
+ `PluginToolInvocation`(`handler` の第 2 引数)には `signal`(tool 呼び出しごと)、`logger`、`locale` が入ります。
402
+
403
+ ### ツールの解決順序
404
+
405
+ 同名 tool が複数登場した場合、後ろの定義が勝ちます:
406
+
407
+ ```
408
+ builtin tools < plugin tools (宣言順) < config.tools (利用者定義)
409
+ ```
410
+
411
+ つまり `config.tools` は plugin の同名 tool を常に上書きできます。fork せずにプラグインの挙動をローカルで差し替える手段になります。
412
+
413
+ ### npm 公開時の package.json
414
+
415
+ ```json
416
+ {
417
+ "name": "@acme/wecool-plugin-clock",
418
+ "version": "0.1.0",
419
+ "type": "module",
420
+ "main": "./dist/index.js",
421
+ "types": "./dist/index.d.ts",
422
+ "files": ["dist"],
423
+ "peerDependencies": { "wecool-chat": "^0.7.0" },
424
+ "publishConfig": { "access": "public" }
425
+ }
426
+ ```
427
+
428
+ - import は `wecool-chat/plugin` だけにする(`wecool-chat` 本体を import しない)。サブパスは型と `definePlugin` ヘルパだけで ~90 bytes gzipped、React 等は引き込みません
429
+ - `wecool-chat` は `peerDependencies` 宣言。ホストの copy を共有するため
430
+
431
+ ### 互換性(`pluginApiVersion`)
432
+
433
+ `pluginApiVersion: 1` は**必須**。これは Plugin SDK の contract が破壊変更された時だけ bump される整数で、**`wecool-chat` 本体の semver とは独立**。
434
+
435
+ `pluginApiVersion: 1` を宣言したプラグインは、`wecool-chat` 側が SDK contract v1 を維持している限り将来の 0.7.x / 0.8.x / 1.x でも動き続けます。不一致時は plugin が skip + warn になります。
436
+
437
+ ### 公式プラグイン(Built-in official plugins)
438
+
439
+ `wecool-chat/plugins/*` 配下のプラグインは本体パッケージに同梱されています。**サブパスを明示的に import した時にだけ** バンドルに含まれ、コア entry には混入しません。
440
+
441
+ #### `wecool-chat/plugins/qrcode`
442
+
443
+ 任意のテキスト(URL / Wi-Fi 接続情報 / vCard / 位置情報など)から、スキャンできる QR コードを生成します。LLM がどの文字列を組み立てるかを判断します。
444
+
445
+ ```tsx
446
+ import { initWecoolChat } from "wecool-chat";
447
+ import { createQrcodePlugin } from "wecool-chat/plugins/qrcode";
448
+
449
+ initWecoolChat({
450
+ endpoint: "...",
451
+ tools: [],
452
+ plugins: [createQrcodePlugin()],
453
+ });
454
+ ```
455
+
456
+ プラグインは `generate_qrcode` という 1 つの tool を登録し、LLM が次のように呼び出します:
457
+
458
+ | 発話 | LLM の呼び出し |
459
+ | -------------------------------- | ----------------------------------------------------------------- |
460
+ | 「このURLをQRにして」 | `generate_qrcode({ text: url })` |
461
+ | 「Wi-Fiパスワードを QR にして」 | `generate_qrcode({ text: "WIFI:T:WPA;S:ssid;P:pw;;" })` |
462
+ | 「連絡先のQRコード(印刷したい)」 | `generate_qrcode({ text: "<vCard>", errorCorrectionLevel: "Q" })` |
463
+ | 「会社の住所をQRに、大きめで」 | `generate_qrcode({ text: "geo:35.6,139.7", size: 384 })` |
464
+
465
+ 生成された QR 画像はチャットバブル直下に表示され、ダウンロードボタンが添えられます。handler 自体は **ダウンロードを発火しません** — ユーザー操作起点でのみ保存されるため、LLM が勝手にファイル DL を引き起こす経路はありません。
466
+
467
+ `createQrcodePlugin` のオプション:
468
+
469
+ | オプション | 既定 | メモ |
470
+ | ----------------------------- | ------ | --------------------------------------------------- |
471
+ | `defaultSize` | `256` | QR コードの一辺サイズ (px) |
472
+ | `defaultErrorCorrectionLevel` | `"M"` | 印刷用途なら `"Q"` か `"H"` を推奨 |
473
+ | `maxTextLength` | `2000` | `Number.POSITIVE_INFINITY` で上限ガードを実質無効化 |
474
+
475
+ **LLM に渡される戻り値の形** (画像バイトは LLM context に乗らず、別経路の `attachments` でクライアント側だけで描画されます):
476
+
477
+ ```ts
478
+ // 成功
479
+ { ok: true, size, errorCorrectionLevel, contentLength,
480
+ mimeType: "image/png", displayed: true }
481
+
482
+ // 失敗 (LLM が error + hint を見て再試行できる)
483
+ { ok: false, error: "text_too_long" | "invalid_args"
484
+ | "browser_only" | "generation_failed" | "unsafe_content",
485
+ message, hint? }
486
+ ```
487
+
488
+ 中断 (AbortError) のみ throw で、それ以外の失敗はすべて `{ ok: false, ... }` を return します。LLM はこの形を見て、誤り訂正レベルを下げる・テキストを短くするといった再試行を自動で判断できます。
489
+
490
+ **バンドル影響**: `qrcode` ライブラリは `dist/plugins/qrcode.js` と関連 chunk (合計で約 14 KB gzipped) に閉じ込められ、コアバンドル (`dist/index.js`) には混入しません。プラグイン側も、tool が実際に呼ばれるまで `qrcode` を読み込みません。
491
+
223
492
  ---
224
493
 
225
494
  ## フレームワーク別ガイド
@@ -376,19 +645,44 @@ const ChatWidget = dynamic(() => import("wecool-chat").then((m) => m.ChatWidget)
376
645
 
377
646
  ## ChatConfig オプション
378
647
 
379
- | プロパティ | 型 | 必須 | デフォルト | 説明 |
380
- | ------------------ | ------------------------ | ---- | ------------------- | ---------------------------------------- |
381
- | `endpoint` | `string` | ✓ | — | API エンドポイント URL |
382
- | `apiKey` | `string` | | — | ダッシュボードで発行した API キー |
383
- | `tools` | `Tool[]` | ✓ | — | ツール定義の配列 |
384
- | `locale` | `"ja" \| "en"` | | `"ja"` | UI 言語 |
385
- | `placeholder` | `string` | | locale に応じて切替 | 入力欄のプレースホルダー |
386
- | `className` | `string` | | — | ルート要素に付与するクラス名 |
387
- | `toolTimeout` | `number` | | `30000` | ツール実行のタイムアウト (ms) |
388
- | `disableShadowDom` | `boolean` | | `false` | Shadow DOM を使わずに通常 DOM へマウント |
389
- | `onToolExecute` | `(name, args) => void` | | — | ツール実行直前のコールバック |
390
- | `onToolResult` | `(name, result) => void` | | — | ツール実行完了後のコールバック |
391
- | `onError` | `(error: Error) => void` | | — | エラー時のコールバック |
648
+ | プロパティ | 型 | 必須 | デフォルト | 説明 |
649
+ | -------------------- | ------------------------------- | ---- | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
650
+ | `endpoint` | `string` | ✓ | — | API エンドポイント URL(HTTPS 必須。開発用に `http://localhost` / `http://127.0.0.1` のみ例外で許可) |
651
+ | `apiKey` | `string` | | — | ダッシュボードで発行した API キー |
652
+ | `tools` | `Tool[]` | ✓ | — | ツール定義の配列 |
653
+ | `locale` | `"ja" \| "en"` | | `"ja"` | UI 言語 |
654
+ | `placeholder` | `string` | | locale に応じて切替 | 入力欄のプレースホルダー |
655
+ | `theme` | `"auto" \| "light" \| "dark"` | | `"light"` | カラーテーマ。`"auto"` は OS のダークモード設定に追従 |
656
+ | `className` | `string` | | — | ルート要素に付与するクラス名 |
657
+ | `toolTimeout` | `number` | | `30000` | ツール実行のタイムアウト (ms) |
658
+ | `disableShadowDom` | `boolean` | | `false` | Shadow DOM を使わずに通常 DOM へマウント |
659
+ | `layout` | `LayoutPattern` | | `floating-bottom-right` | 9 種類のレイアウトパターンから 1 つ選ぶ。[動作モード](#動作モード-layout-パターン) 参照 |
660
+ | `transparent` | `boolean` | | `false` | `layout: "header-banner"` のときのみ意味を持つ。半透明背景で本文を透かす |
661
+ | `narrateToolResults` | `boolean` | | `false` | tool 実行ごとに `tool_choice: "none"` で追加の LLM 呼び出しを行い、短いナレーションテキストを取得する。詳細は[後述](#tool-結果のナレーション)。 |
662
+ | `plugins` | `ChatPlugin[]` | | `[]` | プラグイン配列。[プラグイン](#プラグイン) 参照 |
663
+ | `onToolExecute` | `(name, args) => void` | | — | ツール実行直前のコールバック |
664
+ | `onToolResult` | `(name, result) => void` | | — | ツール実行完了後のコールバック |
665
+ | `onMessagesChange` | `(messages: Message[]) => void` | | — | 内部の `messages` 配列が変化するたびに呼ばれる。ホスト側 UI へ会話列を同期する用途(`layout: "input-only"` と組み合わせる) |
666
+ | `onError` | `(error: Error) => void` | | — | エラー時のコールバック |
667
+
668
+ ### Tool 結果のナレーション
669
+
670
+ `gpt-4o-mini` など一部のモデルは tool 呼び出し時に assistant テキストを省略するため、tool が連鎖する長いフロー(たとえば 6 ステップの注文)で「画面が黙ったまま」になります。`narrateToolResults: true` を指定すると、各 tool 実行後に追加の LLM 呼び出し(`tool_choice: "none"`)を行い、短い説明テキストを取得して画面に流します。
671
+
672
+ ```ts
673
+ initWecoolChat({
674
+ endpoint,
675
+ apiKey,
676
+ tools,
677
+ narrateToolResults: true,
678
+ });
679
+ ```
680
+
681
+ トレードオフ:
682
+
683
+ - **コスト / レイテンシ**: LLM 呼び出し回数がほぼ倍増します。既定は off。コンシェルジュ的に「次に何をするか」を語ってほしいフロー専用の opt-in と捉えてください。
684
+ - **重複応答の抑止**: ナレーション直後の通常ラウンドも text のみで終わる場合、wecool-chat は古いナレーションを自動で除去します(同じ趣旨のテキストが 2 つ並ばないようにする)。
685
+ - **ループ上限**: ナレーションでラウンド数が増えるため、内部の `MAX_TOOL_ITERATIONS` は 15 に拡張されています。7 個程度の tool チェーンまで余裕で完走します。
392
686
 
393
687
  ---
394
688
 
@@ -412,11 +706,35 @@ const config = {
412
706
 
413
707
  ### 配色 / テーマ
414
708
 
415
- 現バージョンでは外部から直接上書きできる公式テーマ変数は公開していません。配色を変えたい場合の選択肢:
709
+ `config.theme` で組み込みのカラーテーマを切り替えられます。
710
+
711
+ ```ts
712
+ initWecoolChat({
713
+ endpoint: "https://api.wecool.dev",
714
+ apiKey: "...",
715
+ tools,
716
+ theme: "auto", // "auto" は OS の prefers-color-scheme に追従、"light" / "dark" は強制指定
717
+ });
718
+ ```
719
+
720
+ - **`"light"`(既定)**: 明るい背景・暗い文字。既存の埋め込みコードと完全互換。
721
+ - **`"dark"`**: 暗い背景・明るい文字。
722
+ - **`"auto"`**: ホスト OS の `prefers-color-scheme` に追従。切替は CSS 内で完結するため JS マウント時のフラッシュは起きません。
723
+
724
+ それ以上の細かいカスタマイズが必要な場合は、これまでどおり以下の逃げ道があります:
416
725
 
417
726
  - `className` でルート要素にクラスを付与し、Tailwind や独自 CSS で当てる
418
727
  - `disableShadowDom: true` を指定してホスト側 CSS を直接効かせる(Shadow による隔離は失われます)
419
- - 公式のテーマ変数公開は今後のバージョンで対応予定
728
+ - Shadow Host 上の `--wecool-color-*` CSS 変数を上書きする(高度)
729
+
730
+ ### ホストページ側のアクセシビリティガイダンス
731
+
732
+ ウィジェットを埋め込んだホストページ全体で WCAG 2.2 AA を保つために、以下にご留意ください:
733
+
734
+ - **SC 2.4.11 Focus Not Obscured (AA)**: チャットパネルが開いているときに他の固定要素(cookie バナー、stick footer 等)で完全に隠れないよう配置してください。フローティングボタンが開いた際、ホストページのキーボードフォーカス対象要素を覆い隠さないようにすることも同様です。
735
+ - **SC 3.2.6 Consistent Help (A)**: 認知障害のあるユーザーが筋肉記憶でヘルプを探せるよう、フローティングウィジェットは全ページで同じ `position`(例: 常に `bottom-right`)に固定してください。
736
+
737
+ ウィジェット側で対応済みの WCAG 2.2 達成基準と既知の制約はリポジトリの `docs/accessibility.md` にまとめています。
420
738
 
421
739
  ---
422
740
 
@@ -436,6 +754,12 @@ const config = {
436
754
  // 監査ログ送信、Sentry breadcrumb、UI トースト表示など
437
755
  auditLog({ tool: name, result });
438
756
  },
757
+ onMessagesChange: (messages) => {
758
+ // wecool-chat 内のメッセージ配列が変化するたび呼ばれる
759
+ // (新着 user/assistant、ストリーミング更新、削除など)。
760
+ // ホスト側 UI に同期したいときに使う。
761
+ hostThreadStore.replaceMessages(messages);
762
+ },
439
763
  onError: (error) => {
440
764
  Sentry.captureException(error);
441
765
  },