wecool-chat 0.4.0 → 0.6.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 (67) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.ja.md +609 -0
  3. package/README.md +215 -140
  4. package/dist/builtin-tools/get-current-page-info.d.ts +9 -0
  5. package/dist/builtin-tools/get-current-page-info.d.ts.map +1 -0
  6. package/dist/builtin-tools/index.d.ts +3 -0
  7. package/dist/builtin-tools/index.d.ts.map +1 -0
  8. package/dist/builtin-tools/merge-builtin-tools.d.ts +10 -0
  9. package/dist/builtin-tools/merge-builtin-tools.d.ts.map +1 -0
  10. package/dist/client.d.ts.map +1 -1
  11. package/dist/components/ChatFooter.d.ts +3 -1
  12. package/dist/components/ChatFooter.d.ts.map +1 -1
  13. package/dist/components/ChatHeader.d.ts.map +1 -1
  14. package/dist/components/ChatPanel.d.ts +8 -1
  15. package/dist/components/ChatPanel.d.ts.map +1 -1
  16. package/dist/components/ChatWidget.d.ts.map +1 -1
  17. package/dist/components/CopyIndicator.d.ts.map +1 -1
  18. package/dist/components/FloatButton.d.ts +6 -1
  19. package/dist/components/FloatButton.d.ts.map +1 -1
  20. package/dist/components/MessageActionsPopover.d.ts +2 -0
  21. package/dist/components/MessageActionsPopover.d.ts.map +1 -1
  22. package/dist/components/MessageBubble.d.ts +5 -8
  23. package/dist/components/MessageBubble.d.ts.map +1 -1
  24. package/dist/components/MessageCopyButton.d.ts +2 -0
  25. package/dist/components/MessageCopyButton.d.ts.map +1 -1
  26. package/dist/components/MessageEditor.d.ts +14 -0
  27. package/dist/components/MessageEditor.d.ts.map +1 -0
  28. package/dist/components/MessageList.d.ts +2 -1
  29. package/dist/components/MessageList.d.ts.map +1 -1
  30. package/dist/components/MessagePopoverButton.d.ts +16 -0
  31. package/dist/components/MessagePopoverButton.d.ts.map +1 -0
  32. package/dist/components/MessageRow.d.ts +4 -0
  33. package/dist/components/MessageRow.d.ts.map +1 -1
  34. package/dist/components/MessageRowActions.d.ts +18 -0
  35. package/dist/components/MessageRowActions.d.ts.map +1 -0
  36. package/dist/components/markdown/CodeBlock.d.ts.map +1 -1
  37. package/dist/components/message-row-handlers.d.ts +27 -0
  38. package/dist/components/message-row-handlers.d.ts.map +1 -0
  39. package/dist/hooks/use-editing-message.d.ts +13 -0
  40. package/dist/hooks/use-editing-message.d.ts.map +1 -0
  41. package/dist/hooks/use-menu-keyboard.d.ts +37 -0
  42. package/dist/hooks/use-menu-keyboard.d.ts.map +1 -0
  43. package/dist/hooks/use-send-message.d.ts +16 -1
  44. package/dist/hooks/use-send-message.d.ts.map +1 -1
  45. package/dist/hooks/useChatStream.d.ts +3 -1
  46. package/dist/hooks/useChatStream.d.ts.map +1 -1
  47. package/dist/hooks/useFocusTrap.d.ts +28 -0
  48. package/dist/hooks/useFocusTrap.d.ts.map +1 -0
  49. package/dist/hooks/useMediaQuery.d.ts +17 -0
  50. package/dist/hooks/useMediaQuery.d.ts.map +1 -0
  51. package/dist/hooks/useScrollToBottom.d.ts +6 -1
  52. package/dist/hooks/useScrollToBottom.d.ts.map +1 -1
  53. package/dist/i18n/messages-context.d.ts +10 -0
  54. package/dist/i18n/messages-context.d.ts.map +1 -0
  55. package/dist/i18n/messages.d.ts +45 -0
  56. package/dist/i18n/messages.d.ts.map +1 -0
  57. package/dist/index.css +1 -1
  58. package/dist/index.d.ts +1 -0
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +9866 -9347
  61. package/dist/mount.d.ts +19 -0
  62. package/dist/mount.d.ts.map +1 -0
  63. package/dist/types.d.ts +10 -0
  64. package/dist/types.d.ts.map +1 -1
  65. package/package.json +20 -16
  66. package/dist/components/MessageRegenerateButton.d.ts +0 -12
  67. package/dist/components/MessageRegenerateButton.d.ts.map +0 -1
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ **English** | [日本語](./README.ja.md)
2
+
1
3
  # wecool-chat
2
4
 
3
5
  [![npm version](https://img.shields.io/npm/v/wecool-chat.svg)](https://www.npmjs.com/package/wecool-chat)
@@ -5,47 +7,47 @@
5
7
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
8
  [![bundle size](https://img.shields.io/bundlephobia/minzip/wecool-chat.svg)](https://bundlephobia.com/package/wecool-chat)
7
9
 
8
- > 自然言語で UI を操作できる、どんなフレームワークでも使える LLM チャットウィジェット。
10
+ > A drop-in LLM chat widget that lets users operate your UI in natural language — works with any framework.
9
11
 
10
- ユーザーが「ダークモードにして」「新着順に並べて」のように話しかけると、LLM があなたの定義した JavaScript 関数を自動で選んで実行します。React でも Vue でも Vanilla JS でも、`npm install` だけで導入できます。
12
+ When a user says things like "switch to dark mode" or "sort by newest", the LLM picks the right JavaScript function you defined and runs it. Works with React, Vue, or Vanilla JS — a single `npm install` away.
11
13
 
12
14
  ![hero demo](./docs/screenshots/hero.gif)
13
15
 
14
- [ライブデモ](https://demo.wecool.dev) ・ [ダッシュボード](https://app.wecool.dev) ・ [npm](https://www.npmjs.com/package/wecool-chat)
16
+ [Live Demo](https://demo.wecool.dev) ・ [Dashboard](https://app.wecool.dev) ・ [npm](https://www.npmjs.com/package/wecool-chat)
15
17
 
16
18
  ---
17
19
 
18
- ## 特徴
20
+ ## Features
19
21
 
20
- - **自然言語で UI 操作** — ユーザーは普通の言葉でアプリを操作できる
21
- - **Tool Calling** — LLM が意図を解釈し、定義済みの JavaScript 関数を自動実行
22
- - **どんなフレームワークでも使える** — React は `<ChatWidget>`、Vue / Svelte / Astro / Vanilla JS は `initWecoolChat()` で導入
23
- - **追加の依存なし** — `npm install wecool-chat` だけで完結
24
- - **埋め込み先に影響しない** — Shadow DOM で隔離されているため、サイト側の CSS と干渉しない
25
- - **UI を自作可能** — 用意された UI ではなく、`ChatClient` を直接使って独自の UI を作ることもできる
22
+ - **Natural-language UI control** — users operate your app in plain language
23
+ - **Tool Calling** — the LLM interprets intent and runs your predefined JavaScript functions
24
+ - **Framework-agnostic** — `<ChatWidget>` for React, `initWecoolChat()` for Vue / Svelte / Astro / Vanilla JS
25
+ - **No extra dependencies** — `npm install wecool-chat` is all you need
26
+ - **Doesn't affect the host page** — Shadow DOM isolation prevents CSS conflicts with the host site
27
+ - **Bring your own UI** — use `ChatClient` directly to build a custom UI instead of the default one
26
28
 
27
29
  ---
28
30
 
29
- ## 想定ユースケース
31
+ ## Use Cases
30
32
 
31
- - **ダッシュボードの操作支援** — テーブルのソート、フィルタ、ページ遷移を「新着順に並べて」のように話しかけられる
32
- - **カスタマーサポート組み込み** — 質問に答えるだけでなく、ユーザー設定の変更や手続きの実行までその場で行う
33
- - **ドキュメントサイトのアシスタント** — 「導入手順を教えて」のような質問に答えつつ、目的のページまで自動遷移
34
- - **社内ツールの操作補助** — 既存 UI を変えずに、慣れない新人でも自然言語で操作できる窓口を追加
33
+ - **Dashboard assistance** — let users say "sort by newest" to trigger table sort, filter, or page navigation
34
+ - **Customer support embedding** — not just answering questions, but executing user setting changes and procedures on the spot
35
+ - **Documentation assistant** — answer questions like "how do I get started?" while auto-navigating to the right page
36
+ - **Internal tools** — add a natural-language operation entry point without changing the existing UI, so even new staff can operate it
35
37
 
36
38
  ---
37
39
 
38
- ## クイックスタート
40
+ ## Quick Start
39
41
 
40
- ### 1. インストール
42
+ ### 1. Install
41
43
 
42
44
  ```bash
43
45
  npm install wecool-chat
44
46
  ```
45
47
 
46
- `pnpm` / `yarn` / `bun` でも同様です。
48
+ `pnpm` / `yarn` / `bun` work the same way.
47
49
 
48
- ### 2. ツールを定義して `<ChatWidget />` を配置
50
+ ### 2. Define tools and place `<ChatWidget />`
49
51
 
50
52
  ```tsx
51
53
  import { ChatWidget } from "wecool-chat";
@@ -55,11 +57,11 @@ const tools = [
55
57
  {
56
58
  name: "toggle_dark_mode",
57
59
  description:
58
- "ダークモードを切り替えます。ユーザーが「ダークモードにして」「暗くして」「明るくして」と言った時に使用する。",
60
+ "Toggles dark mode. Use this when the user says things like 'switch to dark mode', 'make it dark', or 'make it light'.",
59
61
  parameters: {
60
62
  type: "object",
61
63
  properties: {
62
- enabled: { type: "boolean", description: "ダークモードを有効にするか" },
64
+ enabled: { type: "boolean", description: "Whether to enable dark mode" },
63
65
  },
64
66
  required: ["enabled"],
65
67
  },
@@ -75,7 +77,7 @@ function App() {
75
77
  <ChatWidget
76
78
  config={{
77
79
  endpoint: "https://api.wecool.dev",
78
- apiKey: "wecool_xxxxxxxx", // 後述の手順で発行
80
+ apiKey: "wecool_xxxxxxxx", // see steps below to issue
79
81
  tools,
80
82
  }}
81
83
  floating
@@ -84,105 +86,105 @@ function App() {
84
86
  }
85
87
  ```
86
88
 
87
- ### 3. 動作確認
89
+ ### 3. Verify
88
90
 
89
- ページ右下のチャットボタンをクリック → 「ダークモードにして」と入力 → ページがダークテーマに切り替わります。
91
+ Click the chat button (default: bottom-right) on the page → type "switch to dark mode" → the page changes to a dark theme.
90
92
 
91
- > Vue / Svelte / Astro / Vanilla JS での導入は [フレームワーク別ガイド](#フレームワーク別ガイド) を参照してください。
93
+ > For Vue / Svelte / Astro / Vanilla JS integration, see the [Framework Guides](#framework-guides) section.
92
94
 
93
- ### APIキーの取得(初回のみ)
95
+ ### Getting an API key (one-time)
94
96
 
95
- [ダッシュボード(app.wecool.dev)](https://app.wecool.dev) でアカウントを作成し、「API Keys」から新しいキーを発行してください。発行されたキーは再表示されないため、安全な場所に控えておきます。
97
+ Sign up at the [Dashboard (app.wecool.dev)](https://app.wecool.dev) and issue a new key from "API Keys". The key is shown only once, so save it somewhere safe.
96
98
 
97
- 本番では `apiKey` を環境変数から読み込んでください。使用するビルドツールによって書き方が異なります。
99
+ In production, load `apiKey` from environment variables. The syntax depends on the build tool you're using.
98
100
 
99
- | 環境 | 書き方 |
101
+ | Environment | Syntax |
100
102
  | ---------------- | ---------------------------------------- |
101
103
  | Next.js | `process.env.NEXT_PUBLIC_WECOOL_API_KEY` |
102
104
  | Vite (React/Vue) | `import.meta.env.VITE_WECOOL_API_KEY` |
103
105
  | Astro | `import.meta.env.PUBLIC_WECOOL_API_KEY` |
104
106
 
105
- クライアントから API キーが見えるため、ダッシュボードの「Allowed Origins」設定で**呼び出し元ドメインを制限**してください。
107
+ Since the API key is visible to the client, **restrict the calling origin** in the dashboard's "Allowed Origins" setting.
106
108
 
107
109
  ---
108
110
 
109
- ## 動作モード
111
+ ## Display Modes
110
112
 
111
- ウィジェットには 2 つの表示モードがあります。
113
+ The widget has two display modes.
112
114
 
113
- ### フローティング(推奨)
115
+ ### Floating (recommended)
114
116
 
115
- 画面の角に常駐するチャットボタン。クリックでパネルが開きます。サポート用途・ツアー的な体験に向きます。
117
+ A persistent chat button anchored to a corner of the screen. Clicking it opens the panel. Best for support and tour-like experiences.
116
118
 
117
119
  ![floating mode](./docs/screenshots/mode-floating.png)
118
120
 
119
- ### 埋め込み
121
+ ### Embedded
120
122
 
121
- 任意のコンテナ要素の中にパネルを直接配置します。ダッシュボードの一部にアシスタント枠として組み込む用途に向きます。
123
+ Place the panel directly inside any container element. Best for embedding as an assistant section within a dashboard.
122
124
 
123
- ### 切り替え方
125
+ ### How to switch
124
126
 
125
- | 用途 | React | 非 React |
126
- | -------------- | -------------------------------------- | ------------------------------------------- |
127
- | フローティング | `<ChatWidget config={...} floating />` | `initWecoolChat(config)` |
128
- | 埋め込み | `<ChatWidget config={...} />` | `initWecoolChat(config, "#chat-container")` |
127
+ | Use case | React | Non-React |
128
+ | -------- | -------------------------------------- | ------------------------------------------- |
129
+ | Floating | `<ChatWidget config={...} floating />` | `initWecoolChat(config)` |
130
+ | Embedded | `<ChatWidget config={...} />` | `initWecoolChat(config, "#chat-container")` |
129
131
 
130
- `initWecoolChat` は第二引数を省略するとフローティング、`HTMLElement` か CSS セレクタを渡すと埋め込みになります。
132
+ `initWecoolChat` is floating when the second argument is omitted, and embedded when an `HTMLElement` or CSS selector is passed.
131
133
 
132
134
  ---
133
135
 
134
- ## ツールを定義する
136
+ ## Defining Tools
135
137
 
136
- wecool-chat の核は「ツール定義」です。LLM はあなたが渡したツール一覧と `description` を読み、ユーザーの発話から最適なツールを選んで `handler` を呼びます。
138
+ The core of wecool-chat is the "tool definition". The LLM reads the list of tools you provide, along with each `description`, and picks the most appropriate one based on what the user says to call its `handler`.
137
139
 
138
- ### 基本形
140
+ ### Basic shape
139
141
 
140
- `Tool` 型は 4 フィールドからなります。
142
+ The `Tool` type has 4 fields.
141
143
 
142
144
  ```ts
143
145
  type Tool = {
144
- name: string; // 一意な識別子(例: "set_theme")
145
- description: string; // LLM がいつ使うかを判断する説明
146
- parameters: ToolParameters; // 引数の JSON Schema
146
+ name: string; // Unique identifier (e.g., "set_theme")
147
+ description: string; // What the LLM uses to decide when to call this tool
148
+ parameters: ToolParameters; // JSON Schema for arguments
147
149
  handler: (args: Record<string, unknown>) => unknown | Promise<unknown>;
148
150
  };
149
151
  ```
150
152
 
151
- ### `description` の書き方が精度を決める
153
+ ### How you write `description` determines accuracy
152
154
 
153
- LLM は `description` を読んで「いつこのツールを使うか」を判断します。**ユーザーがどう言いそうか**を例示すると精度が上がります。
155
+ The LLM reads the `description` to decide "when to use this tool". **Including examples of how the user might phrase it** improves accuracy.
154
156
 
155
157
  ```ts
156
158
  {
157
159
  name: "set_theme",
158
160
  description:
159
- "テーマを変更します。ユーザーが「ダークモードにして」「ライトモードにして」「暗くして」「明るくして」などと言った時に使用する。",
161
+ "Changes the theme. Use this when the user says things like 'switch to dark mode', 'switch to light mode', 'make it dark', or 'make it light'.",
160
162
  // ...
161
163
  }
162
164
  ```
163
165
 
164
- 機能名だけ(「テーマ変更」)より、ユーザー発話を 3〜4 例書く方が呼び出し率が高まります。
166
+ Listing 3–4 user phrasings yields a higher tool invocation rate than just naming the feature ("change theme").
165
167
 
166
- ### 複雑な引数
168
+ ### Complex arguments
167
169
 
168
- `enum`、配列、ネストオブジェクトもサポートします。
170
+ `enum`, arrays, and nested objects are supported.
169
171
 
170
172
  ```ts
171
173
  {
172
174
  name: "sort_table",
173
- description: "テーブルを並び替えます。ユーザーが「新着順に並べて」「タイトル順にして」と言った時に使用する。",
175
+ description: "Sorts the table. Use this when the user says things like 'sort by newest' or 'sort by title'.",
174
176
  parameters: {
175
177
  type: "object",
176
178
  properties: {
177
179
  column: {
178
180
  type: "string",
179
181
  enum: ["date", "title", "status"],
180
- description: "並び替えるカラム",
182
+ description: "The column to sort by",
181
183
  },
182
184
  order: {
183
185
  type: "string",
184
186
  enum: ["asc", "desc"],
185
- description: "並び順(asc: 昇順、desc: 降順)",
187
+ description: "Sort order (asc: ascending, desc: descending)",
186
188
  },
187
189
  },
188
190
  required: ["column"],
@@ -194,33 +196,75 @@ LLM は `description` を読んで「いつこのツールを使うか」を判
194
196
  }
195
197
  ```
196
198
 
197
- 各プロパティの `description` も書くと、LLM が引数を取り違えにくくなります。
199
+ Writing a `description` for each property as well makes it less likely for the LLM to mix up arguments.
198
200
 
199
- ### よくある実装パターン
201
+ ### Common implementation patterns
200
202
 
201
- `handler` には次のようなコードも書けます:
203
+ You can also write code like the following inside `handler`:
202
204
 
203
- - **API を呼び出して結果を返す** — `handler: async (args) => { ... }` のように `async` で書けば、`fetch` の結果を待ってから返せます
204
- - **エラーをユーザーに伝える** — `throw new Error("メッセージ")` で投げると `config.onError` が発火します。`return { ok: false, message: "..." }` で返すと LLM が結果を読み取り、ユーザーへ自然な日本語で説明します
205
+ - **Call an API and return the result** — write `handler: async (args) => { ... }` to await `fetch` results before returning
206
+ - **Surface errors to the user** — `throw new Error("message")` triggers `config.onError`. Returning `{ ok: false, message: "..." }` lets the LLM read the result and explain it back to the user in natural language
205
207
 
206
- ### タイムアウト(toolTimeout)
208
+ ### Timeout (toolTimeout)
207
209
 
208
- ツール実行は既定で **30 秒** でタイムアウトします。`config.toolTimeout` で上書き可能(ミリ秒、グローバル設定)。
210
+ Tool execution times out at **30 seconds** by default. Override with `config.toolTimeout` (milliseconds, global setting).
209
211
 
210
212
  ```ts
211
213
  const config = {
212
214
  endpoint: "https://api.wecool.dev",
213
215
  apiKey: "...",
214
216
  tools,
215
- toolTimeout: 60_000, // 60 秒
217
+ toolTimeout: 60_000, // 60 seconds
216
218
  };
217
219
  ```
218
220
 
219
- > **注意**: `handler` 内で `AbortSignal` を受け取って中断する仕組みは現バージョンでは未対応です。重い処理は handler 側で軽量化してください。
221
+ > **Note**: Receiving an `AbortSignal` inside `handler` to cancel work is not supported in the current version. Keep heavy work lightweight on the handler side.
222
+
223
+ ### Built-in tools
224
+
225
+ 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.
226
+
227
+ | Tool | What it does |
228
+ | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
229
+ | `getCurrentPageInfo` | Returns the URL / title / description / pathname / host / language of the embedding page so the LLM can answer "what page am I looking at?" style questions. |
230
+
231
+ ```ts
232
+ import { initWecoolChat } from "wecool-chat";
233
+
234
+ // getCurrentPageInfo is included automatically — no manual registration needed.
235
+ initWecoolChat({
236
+ endpoint: "https://api.example.com",
237
+ tools: [
238
+ myCustomTool, // only your own tools here
239
+ ],
240
+ });
241
+ ```
242
+
243
+ A `web_search` tool is also registered on the backend and offered to the LLM automatically — you don't need to add anything client-side. Note that backend `web_search` answers are produced from the LLM's own knowledge rather than a live web crawl, so treat the results as best-effort.
244
+
245
+ #### Overriding or disabling a built-in tool
246
+
247
+ To disable or replace a built-in tool, register a `Tool` with the same `name` — your tool wins.
248
+
249
+ ```ts
250
+ initWecoolChat({
251
+ endpoint: "https://api.example.com",
252
+ tools: [
253
+ {
254
+ name: "getCurrentPageInfo", // same name disables the built-in
255
+ description: "disabled",
256
+ parameters: { type: "object", properties: {} },
257
+ handler: () => ({ disabled: true }),
258
+ },
259
+ ],
260
+ });
261
+ ```
262
+
263
+ > ⚠️ **Security note for `getCurrentPageInfo`**: The handler exposes the full `window.location.href`, including query parameters and hash. On pages whose URLs carry secrets (password-reset tokens, OAuth `access_token` in the fragment, signed download links, etc.) override the built-in with a no-op tool as shown above, since the original value would otherwise reach the LLM provider as part of the tool result.
220
264
 
221
265
  ---
222
266
 
223
- ## フレームワーク別ガイド
267
+ ## Framework Guides
224
268
 
225
269
  ### Vue 3
226
270
 
@@ -242,7 +286,7 @@ onMounted(() => {
242
286
  });
243
287
  });
244
288
 
245
- // クリーンアップ忘れ注意
289
+ // Don't forget cleanup
246
290
  onUnmounted(() => dispose?.());
247
291
  </script>
248
292
  ```
@@ -255,7 +299,7 @@ onUnmounted(() => dispose?.());
255
299
  import { initWecoolChat } from "wecool-chat";
256
300
  import "wecool-chat/styles.css";
257
301
 
258
- // onMount の戻り値が dispose 関数として呼ばれる
302
+ // The return value of onMount is called as the dispose function
259
303
  onMount(() =>
260
304
  initWecoolChat({
261
305
  endpoint: "https://api.wecool.dev",
@@ -286,7 +330,7 @@ onUnmounted(() => dispose?.());
286
330
  tools: [/* ... */],
287
331
  });
288
332
 
289
- // SPA 遷移時など必要に応じて dispose() を呼ぶ
333
+ // Call dispose() when needed (e.g., SPA navigation)
290
334
  window.addEventListener("beforeunload", () => dispose());
291
335
  </script>
292
336
  </body>
@@ -316,9 +360,9 @@ onUnmounted(() => dispose?.());
316
360
  </html>
317
361
  ```
318
362
 
319
- ### Next.js(App Router)
363
+ ### Next.js (App Router)
320
364
 
321
- クライアント側でのみ動作する `"use client"` コンポーネントとして扱います。
365
+ Treat it as a `"use client"` component that runs only on the client side.
322
366
 
323
367
  ```tsx
324
368
  // app/_components/chat.tsx
@@ -339,7 +383,7 @@ export function Chat() {
339
383
  /* ... */
340
384
  ],
341
385
  });
342
- // クリーンアップ忘れ注意
386
+ // Don't forget cleanup
343
387
  return () => dispose.current?.();
344
388
  }, []);
345
389
 
@@ -347,7 +391,7 @@ export function Chat() {
347
391
  }
348
392
  ```
349
393
 
350
- `<ChatWidget>` を直接使う場合は、SSR 回避のため `dynamic` で `ssr: false` を指定します。
394
+ If you want to use `<ChatWidget>` directly, import it via `dynamic` with `ssr: false` to avoid SSR.
351
395
 
352
396
  ```tsx
353
397
  import dynamic from "next/dynamic";
@@ -358,13 +402,13 @@ const ChatWidget = dynamic(() => import("wecool-chat").then((m) => m.ChatWidget)
358
402
 
359
403
  ## ChatWidget Props
360
404
 
361
- | Prop | 型 | 必須 | デフォルト | 説明 |
362
- | ------------- | -------------------------------------------------------------- | ---- | ---------------- | -------------------------- |
363
- | `config` | `ChatConfig` | ✓ | — | 設定オブジェクト |
364
- | `tools` | `Tool[]` | | — | `config.tools` を上書き |
365
- | `floating` | `boolean` | | `false` | フローティングモード |
366
- | `defaultOpen` | `boolean` | | `false` | フローティング時の初期表示 |
367
- | `position` | `"bottom-right" \| "bottom-left" \| "top-right" \| "top-left"` | | `"bottom-right"` | フローティング時の配置 |
405
+ | Prop | Type | Required | Default | Description |
406
+ | ------------- | -------------------------------------------------------------- | -------- | ---------------- | ----------------------------------- |
407
+ | `config` | `ChatConfig` | ✓ | — | Configuration object |
408
+ | `tools` | `Tool[]` | | — | Overrides `config.tools` |
409
+ | `floating` | `boolean` | | `false` | Floating mode |
410
+ | `defaultOpen` | `boolean` | | `false` | Initial open state in floating mode |
411
+ | `position` | `"bottom-right" \| "bottom-left" \| "top-right" \| "top-left"` | | `"bottom-right"` | Position in floating mode |
368
412
 
369
413
  ```tsx
370
414
  <ChatWidget config={config} floating defaultOpen position="bottom-left" />
@@ -372,51 +416,80 @@ const ChatWidget = dynamic(() => import("wecool-chat").then((m) => m.ChatWidget)
372
416
 
373
417
  ---
374
418
 
375
- ## ChatConfig オプション
376
-
377
- | プロパティ | 型 | 必須 | デフォルト | 説明 |
378
- | ------------------ | ------------------------ | ---- | ----------------------- | ---------------------------------------- |
379
- | `endpoint` | `string` | ✓ | — | API エンドポイント URL |
380
- | `apiKey` | `string` | | — | ダッシュボードで発行した API キー |
381
- | `tools` | `Tool[]` | ✓ | — | ツール定義の配列 |
382
- | `locale` | `"ja" \| "en"` | | `"ja"` | UI 言語 |
383
- | `placeholder` | `string` | | `"メッセージを入力..."` | 入力欄のプレースホルダー |
384
- | `className` | `string` | | — | ルート要素に付与するクラス名 |
385
- | `toolTimeout` | `number` | | `30000` | ツール実行のタイムアウト (ms) |
386
- | `disableShadowDom` | `boolean` | | `false` | Shadow DOM を使わずに通常 DOM へマウント |
387
- | `onToolExecute` | `(name, args) => void` | | — | ツール実行直前のコールバック |
388
- | `onToolResult` | `(name, result) => void` | | — | ツール実行完了後のコールバック |
389
- | `onError` | `(error: Error) => void` | | — | エラー時のコールバック |
419
+ ## ChatConfig Options
420
+
421
+ | Property | Type | Required | Default | Description |
422
+ | ------------------ | ----------------------------- | -------- | ------------------- | ------------------------------------------------------------------------------------------------------- |
423
+ | `endpoint` | `string` | ✓ | — | API endpoint URL (must be HTTPS; `http://localhost` and `http://127.0.0.1` are allowed for development) |
424
+ | `apiKey` | `string` | | — | API key issued from the dashboard |
425
+ | `tools` | `Tool[]` | ✓ | — | Array of tool definitions |
426
+ | `locale` | `"ja" \| "en"` | | `"ja"` | UI language. Set `"en"` for English |
427
+ | `placeholder` | `string` | | depends on `locale` | Input field placeholder |
428
+ | `theme` | `"auto" \| "light" \| "dark"` | | `"light"` | Color theme. `"auto"` follows OS dark-mode |
429
+ | `className` | `string` | | — | Class name applied to the root element |
430
+ | `toolTimeout` | `number` | | `30000` | Tool execution timeout (ms) |
431
+ | `disableShadowDom` | `boolean` | | `false` | Mount to normal DOM instead of Shadow DOM |
432
+ | `onToolExecute` | `(name, args) => void` | | — | Callback fired right before tool execution |
433
+ | `onToolResult` | `(name, result) => void` | | — | Callback fired after tool execution finishes |
434
+ | `onError` | `(error: Error) => void` | | — | Callback fired on error |
390
435
 
391
436
  ---
392
437
 
393
- ## カスタマイズ
438
+ ## Customization
394
439
 
395
- ### 文言とロケール
440
+ ### Locale and labels
441
+
442
+ Setting `locale` switches all in-widget display strings at once: input placeholder, button `aria-label`s, error messages, and the empty-state label. Supports `"ja"` (default) and `"en"`.
396
443
 
397
444
  ```ts
398
445
  const config = {
399
446
  endpoint: "https://api.wecool.dev",
400
447
  apiKey: "...",
401
448
  tools,
402
- locale: "en", // UI ラベルを英語に
403
- placeholder: "Ask me anything...", // 入力欄プレースホルダー
449
+ locale: "en", // UI labels in English
450
+ placeholder: "Ask me anything...", // override only the input placeholder
404
451
  };
405
452
  ```
406
453
 
407
- ### 配色 / テーマ
454
+ If `placeholder` is provided, it takes precedence over the locale's default placeholder.
408
455
 
409
- 現バージョンでは外部から直接上書きできる公式テーマ変数は公開していません。配色を変えたい場合の選択肢:
456
+ ### Colors / theme
410
457
 
411
- - `className` でルート要素にクラスを付与し、Tailwind や独自 CSS で当てる
412
- - `disableShadowDom: true` を指定してホスト側 CSS を直接効かせる(Shadow による隔離は失われます)
413
- - 公式のテーマ変数公開は今後のバージョンで対応予定
458
+ Switch the built-in color theme with `config.theme`:
459
+
460
+ ```ts
461
+ initWecoolChat({
462
+ endpoint: "https://api.wecool.dev",
463
+ apiKey: "...",
464
+ tools,
465
+ theme: "auto", // "auto" follows OS prefers-color-scheme; "light" / "dark" force a theme
466
+ });
467
+ ```
468
+
469
+ - **`"light"` (default)**: light background, dark text. Backwards-compatible with existing integrations.
470
+ - **`"dark"`**: dark background, light text.
471
+ - **`"auto"`**: follows the host OS's `prefers-color-scheme`. Switching happens in CSS only, so there is no JS-mount flash.
472
+
473
+ For finer-grained customization beyond these presets, you still have these escape hatches:
474
+
475
+ - Apply a class to the root element via `className` and target it with Tailwind or your own CSS
476
+ - Set `disableShadowDom: true` to let the host site's CSS apply directly (Shadow DOM isolation is lost)
477
+ - Override the `--wecool-color-*` CSS variables on the Shadow Host (advanced)
478
+
479
+ ### Accessibility guidance for host pages
480
+
481
+ To stay compliant with WCAG 2.2 AA on the host page where you embed the widget, please keep the following in mind:
482
+
483
+ - **SC 2.4.11 Focus Not Obscured (AA)**: avoid placing other fixed-position elements (cookie banners, sticky footers) that fully cover the chat panel when it's open, or that cover keyboard-focused elements on the host page when the floating button is opened.
484
+ - **SC 3.2.6 Consistent Help (A)**: keep the floating widget at the same relative `position` (e.g. always `bottom-right`) across every page so users with cognitive disabilities can rely on muscle memory to find help.
485
+
486
+ See `docs/accessibility.md` in the repository for the full list of WCAG 2.2 success criteria covered by the widget and any known limitations.
414
487
 
415
488
  ---
416
489
 
417
- ## イベントコールバック
490
+ ## Event Callbacks
418
491
 
419
- ツール実行の各タイミングで独自の処理を差し込めます。
492
+ You can hook into each phase of tool execution to add your own logic.
420
493
 
421
494
  ```ts
422
495
  const config = {
@@ -427,7 +500,7 @@ const config = {
427
500
  console.log("[wecool] executing", name, args);
428
501
  },
429
502
  onToolResult: (name, result) => {
430
- // 監査ログ送信、Sentry breadcrumb、UI トースト表示など
503
+ // Audit log, Sentry breadcrumb, UI toast, etc.
431
504
  auditLog({ tool: name, result });
432
505
  },
433
506
  onError: (error) => {
@@ -436,23 +509,23 @@ const config = {
436
509
  };
437
510
  ```
438
511
 
439
- コールバック内で重い処理を行うとチャットの描画が止まる可能性があります。時間のかかる処理は `setTimeout` などで非同期にしてください。
512
+ Heavy work inside callbacks can block chat rendering. Wrap long-running work in `setTimeout` or similar to keep it asynchronous.
440
513
 
441
514
  ---
442
515
 
443
- ## UI を自作する(ChatClient)
516
+ ## Building Your Own UI (ChatClient)
444
517
 
445
- 用意された UI ではなく独自の UI を作りたい場合、`ChatClient` を直接使うとサーバーからの応答を逐次受け取れます。
518
+ If you want to build a custom UI instead of the bundled one, use `ChatClient` directly to consume server responses incrementally.
446
519
 
447
520
  ```ts
448
521
  import { ChatClient, createUserMessage } from "wecool-chat";
449
522
 
450
523
  const client = new ChatClient("https://api.wecool.dev", "<api-key>");
451
524
 
452
- const history = [createUserMessage("ダークモードにして")];
525
+ const history = [createUserMessage("switch to dark mode")];
453
526
 
454
527
  for await (const event of client.chat({
455
- message: "ダークモードにして",
528
+ message: "switch to dark mode",
456
529
  tools: [
457
530
  /* ToolDefinition[] */
458
531
  ],
@@ -472,22 +545,24 @@ for await (const event of client.chat({
472
545
  }
473
546
  ```
474
547
 
475
- `ChatEvent` は次の 6 種類のイベントのいずれかです:`thinking` / `tool_use` / `text` / `text_delta` / `error` / `done`。
548
+ `ChatEvent` is one of 6 event types: `thinking` / `tool_use` / `text` / `text_delta` / `error` / `done`.
549
+
550
+ > **When using individually exported components (`ChatPanel` / `ChatHeader` / `ChatFooter` / `MessageList` / `FloatButton`) directly**, `config.locale` is not auto-distributed. To use them in non-default locales, either wrap them with your own provider or go through `<ChatWidget>`.
476
551
 
477
- ヘルパー関数も用意しています:
552
+ Helper functions are also provided:
478
553
 
479
- - `createMessageId()` — 一意な `msg-<UUID>` を生成
480
- - `createUserMessage(content)` — ユーザー発話のメッセージオブジェクト
481
- - `createAssistantMessage(content)` — アシスタント応答
482
- - `createToolMessage(name, args, result)` — ツール実行結果
483
- - `createErrorMessage(content)` — エラー表示用
484
- - `client.getConversationId()` / `client.resetConversation()` — 会話 ID の取得・リセット
554
+ - `createMessageId()` — generates a unique `msg-<UUID>`
555
+ - `createUserMessage(content)` — message object for a user utterance
556
+ - `createAssistantMessage(content)` — assistant response
557
+ - `createToolMessage(name, args, result)` — tool execution result
558
+ - `createErrorMessage(content)` — for displaying errors
559
+ - `client.getConversationId()` / `client.resetConversation()` — get / reset the conversation ID
485
560
 
486
561
  ---
487
562
 
488
- ## TypeScript で使う
563
+ ## Using with TypeScript
489
564
 
490
- 型定義は同梱しているので、追加セットアップは不要です。
565
+ Type definitions are bundled, so no extra setup is required.
491
566
 
492
567
  ```ts
493
568
  import type {
@@ -505,30 +580,30 @@ import type {
505
580
 
506
581
  ---
507
582
 
508
- ## トラブルシューティング
583
+ ## Troubleshooting
509
584
 
510
- **ウィジェットが表示されない**
511
- DevTools の Elements パネルで `<wecool-chat-shadow-host>` を探し、Shadow Root 配下に React がマウントされているか確認してください。Shadow Root が空の場合は `endpoint` / `apiKey` の値や `console` のエラーを確認します。
585
+ **The widget doesn't show up**
586
+ Look for `<wecool-chat-shadow-host>` in the DevTools Elements panel and verify React is mounted under the Shadow Root. If the Shadow Root is empty, check the `endpoint` / `apiKey` values and any errors in the `console`.
512
587
 
513
- **ツールが呼ばれない(LLM が普通に会話で返してしまう)**
514
- `description` の品質を見直してください。ユーザーがどう言いそうか具体的に複数例示すると精度が上がります。`parameters.required` の漏れも確認してください。`onError` でログを取ると LLM が出した呼び出しを観測できます。
588
+ **Tools aren't called (the LLM just replies as plain conversation)**
589
+ Review the quality of `description`. Listing several concrete examples of how a user might phrase it improves accuracy. Also check for missing `parameters.required` entries. Logging from `onError` helps you observe the calls the LLM actually makes.
515
590
 
516
- **Next.js でビルドエラーになる**
517
- `<ChatWidget>` を `dynamic(() => import("wecool-chat").then((m) => m.ChatWidget), { ssr: false })` で読み込むか、`initWecoolChat` を `"use client"` のコンポーネントの `useEffect` 内で呼んでください。
591
+ **Build error in Next.js**
592
+ Either load `<ChatWidget>` via `dynamic(() => import("wecool-chat").then((m) => m.ChatWidget), { ssr: false })`, or call `initWecoolChat` inside a `useEffect` of a `"use client"` component.
518
593
 
519
- **埋め込み先サイトの CSS と干渉する**
520
- 既定で Shadow DOM 内に隔離されているため、通常は干渉しません。`config.disableShadowDom: true` を指定していないか確認してください。
594
+ **Conflicts with the host site's CSS**
595
+ The widget is isolated inside Shadow DOM by default, so conflicts shouldn't normally happen. Make sure `config.disableShadowDom: true` isn't set.
521
596
 
522
- **ツールが「タイムアウトしました」になる**
523
- `config.toolTimeout` の値(既定 30,000ms)を増やすか、`handler` を軽量化してください。`AbortSignal` でのキャンセルは現バージョンでは未対応です。
597
+ **Tools are timing out**
598
+ Increase `config.toolTimeout` (default 30,000ms) or make the `handler` lighter. Cancellation via `AbortSignal` is not supported in the current version.
524
599
 
525
- **自分のアプリの React と衝突しないか心配**
526
- wecool-chat は React をバンドルに同梱していますが、ウィジェット内部で隔離されているため、利用者側の React アプリには影響しません。バージョンが揃っていれば npm / pnpm の自動最適化により1つに統合されます。
600
+ **Worried about React conflicts with my own app**
601
+ wecool-chat bundles React internally, but it's isolated inside the widget, so it doesn't affect the host React app. If versions match, npm / pnpm's automatic optimization will deduplicate them into one.
527
602
 
528
603
  ---
529
604
 
530
- ## 変更履歴 / ライセンス
605
+ ## Changelog / License
531
606
 
532
- 変更履歴は [CHANGELOG.md](./CHANGELOG.md) を参照してください。
607
+ See [CHANGELOG.md](./CHANGELOG.md) for the changelog.
533
608
 
534
- ライセンス: MIT
609
+ License: MIT