wecool-chat 0.9.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.
- package/CHANGELOG.md +52 -0
- package/README.ja.md +78 -20
- package/README.md +145 -23
- package/dist/CopyIndicator-RR3hSsBA.js +51 -0
- package/dist/MarkdownBody-EIz0jnQy.js +14910 -0
- package/dist/VoiceControls-A7N4uPTo.js +146 -0
- package/dist/VoiceRuntime-DrYjNkZK.js +459 -0
- package/dist/blank-line-CUDmZ-mX.js +143 -0
- package/dist/{browser-D1aZQhQL.js → browser-M7mS-hAN.js} +5 -5
- package/dist/clsx-Cf23UI1w.js +16 -0
- package/dist/core/client.d.ts +11 -3
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/error-reporter.d.ts +1 -1
- package/dist/core/error-reporter.d.ts.map +1 -1
- package/dist/core/i18n/messages.d.ts +77 -1
- package/dist/core/i18n/messages.d.ts.map +1 -1
- package/dist/core/tool-runner.d.ts.map +1 -1
- package/dist/core/types.d.ts +23 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/createLucideIcon-C7wGkK-Q.js +43 -0
- package/dist/default-sNAxTmdF.js +8 -0
- package/dist/index.css +2 -2
- package/dist/index.js +5181 -4871
- package/dist/jsx-runtime-Cyy0mp0f.js +328 -0
- package/dist/lib-DG_DjiCr.js +15 -0
- package/dist/{messages-CveZLPSJ.js → messages-FvtWi3lI.js} +99 -27
- package/dist/plugins/qrcode.js +2 -2
- package/dist/remark-gfm-Bzy1u34W.js +1962 -0
- package/dist/remark-parse-BnwSmQr-.js +2486 -0
- package/dist/stable-prefix-BHsGj4tL.js +21 -0
- package/dist/ui/components/ChatFooter.d.ts +16 -2
- package/dist/ui/components/ChatFooter.d.ts.map +1 -1
- package/dist/ui/components/ChatHeader.d.ts +9 -2
- package/dist/ui/components/ChatHeader.d.ts.map +1 -1
- package/dist/ui/components/ChatHeaderMenu.d.ts +23 -2
- package/dist/ui/components/ChatHeaderMenu.d.ts.map +1 -1
- package/dist/ui/components/ChatPanel.d.ts +13 -3
- package/dist/ui/components/ChatPanel.d.ts.map +1 -1
- package/dist/ui/components/ChatWidget.d.ts.map +1 -1
- package/dist/ui/components/CommandConfirmationCard.d.ts +7 -1
- package/dist/ui/components/CommandConfirmationCard.d.ts.map +1 -1
- package/dist/ui/components/CommandOverlays.d.ts +13 -1
- package/dist/ui/components/CommandOverlays.d.ts.map +1 -1
- package/dist/ui/components/FooterActions.d.ts +18 -0
- package/dist/ui/components/FooterActions.d.ts.map +1 -0
- package/dist/ui/components/MessageList.d.ts +7 -1
- package/dist/ui/components/MessageList.d.ts.map +1 -1
- package/dist/ui/components/MessageRow.d.ts +7 -1
- package/dist/ui/components/MessageRow.d.ts.map +1 -1
- package/dist/ui/components/MessageRowActions.d.ts +9 -3
- package/dist/ui/components/MessageRowActions.d.ts.map +1 -1
- package/dist/ui/components/MicButton.d.ts +11 -0
- package/dist/ui/components/MicButton.d.ts.map +1 -0
- package/dist/ui/components/VoiceControls.d.ts +22 -0
- package/dist/ui/components/VoiceControls.d.ts.map +1 -0
- package/dist/ui/components/VoiceLoopStatusBar.d.ts +17 -0
- package/dist/ui/components/VoiceLoopStatusBar.d.ts.map +1 -0
- package/dist/ui/components/VoiceLoopToggle.d.ts +15 -0
- package/dist/ui/components/VoiceLoopToggle.d.ts.map +1 -0
- package/dist/ui/components/VoiceRuntime.d.ts +16 -0
- package/dist/ui/components/VoiceRuntime.d.ts.map +1 -0
- package/dist/ui/components/lazy-voice.d.ts +19 -0
- package/dist/ui/components/lazy-voice.d.ts.map +1 -0
- package/dist/ui/hooks/use-command-execution.d.ts +23 -1
- package/dist/ui/hooks/use-command-execution.d.ts.map +1 -1
- package/dist/ui/hooks/use-message-history.d.ts +14 -0
- package/dist/ui/hooks/use-message-history.d.ts.map +1 -1
- package/dist/ui/hooks/use-mic-button.d.ts +29 -0
- package/dist/ui/hooks/use-mic-button.d.ts.map +1 -0
- package/dist/ui/hooks/use-send-message.d.ts.map +1 -1
- package/dist/ui/hooks/use-speak-message.d.ts +26 -0
- package/dist/ui/hooks/use-speak-message.d.ts.map +1 -0
- package/dist/ui/hooks/use-visitor-id.d.ts +15 -3
- package/dist/ui/hooks/use-visitor-id.d.ts.map +1 -1
- package/dist/ui/hooks/use-voice-input.d.ts +38 -0
- package/dist/ui/hooks/use-voice-input.d.ts.map +1 -0
- package/dist/ui/hooks/use-voice-loop-speech.d.ts +38 -0
- package/dist/ui/hooks/use-voice-loop-speech.d.ts.map +1 -0
- package/dist/ui/hooks/use-voice-loop.d.ts +12 -0
- package/dist/ui/hooks/use-voice-loop.d.ts.map +1 -0
- package/dist/ui/hooks/use-voice-runtime-snapshot.d.ts +19 -0
- package/dist/ui/hooks/use-voice-runtime-snapshot.d.ts.map +1 -0
- package/dist/ui/hooks/use-voice-runtime.d.ts +29 -0
- package/dist/ui/hooks/use-voice-runtime.d.ts.map +1 -0
- package/dist/ui/hooks/useChatStream.d.ts +5 -0
- package/dist/ui/hooks/useChatStream.d.ts.map +1 -1
- package/dist/ui/hooks/useConversationList.d.ts +7 -0
- package/dist/ui/hooks/useConversationList.d.ts.map +1 -1
- package/dist/ui/utils/speech-text.d.ts +29 -0
- package/dist/ui/utils/speech-text.d.ts.map +1 -0
- package/dist/ui/utils/voice-locale.d.ts +3 -0
- package/dist/ui/utils/voice-locale.d.ts.map +1 -0
- package/dist/ui/utils/voice-loop-cue.d.ts +23 -0
- package/dist/ui/utils/voice-loop-cue.d.ts.map +1 -0
- package/dist/ui/utils/voice-loop-status.d.ts +17 -0
- package/dist/ui/utils/voice-loop-status.d.ts.map +1 -0
- package/dist/ui/utils/voice-loop-types.d.ts +40 -0
- package/dist/ui/utils/voice-loop-types.d.ts.map +1 -0
- package/dist/ui/utils/voice-runtime.d.ts +38 -0
- package/dist/ui/utils/voice-runtime.d.ts.map +1 -0
- package/dist/ui/utils/voice-support.d.ts +9 -0
- package/dist/ui/utils/voice-support.d.ts.map +1 -0
- package/dist/unified-DctkAd9P.js +518 -0
- package/dist/use-voice-input-LtJJz-zQ.js +102 -0
- package/dist/version.d.ts +17 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/voice-runtime-F5NxN_0m.js +11 -0
- package/dist/voice-support-BeOiOzcn.js +9 -0
- package/package.json +27 -25
- package/dist/CopyIndicator-D50ixqNB.js +0 -407
- package/dist/MarkdownBody-eopKrDot.js +0 -19983
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,57 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.10.0
|
|
4
|
+
|
|
5
|
+
**Bundle size**: Initial 115.5 KB gzip / 98.2 KB brotli · Total 259.6 KB gzip
|
|
6
|
+
|
|
7
|
+
### Minor Changes
|
|
8
|
+
|
|
9
|
+
- 6117d4f: **音声入出力(マイクボタン・読み上げボタン)**(issue #42、issue #261 でボタン方式へ再設計)。Web Speech API を使った音声入力・読み上げをコア機能として提供する。依存ライブラリなし。
|
|
10
|
+
|
|
11
|
+
- ホスト設定 `voice: true` で有効化する(既定は無効。opt-in)。プラグインの組み込みは不要
|
|
12
|
+
- **マイクボタン**(入力欄): 押すと即座に聞き取りを開始し、聞き取り中は視覚的な状態表示(枠の色変化)が出る。認識結果はテキスト入力と全く同じ経路で送信される(吹き出し表示・履歴保存・ホスト側の文言加工が同様に適用される)。単発モード(1回の発話で聞き取りを終える)。Chrome / Edge(Mac・Windows)/ Safari(macOS・iOS)対応、Firefox は非対応(ブラウザ非対応時はボタンごと非表示)
|
|
13
|
+
- **読み上げボタン**(assistant の発言メニュー): 押すとその発言本文をそのまま読み上げる。読み上げ中に再度押すと停止する。別メッセージの読み上げボタンを押すと前の読み上げを止めて新しい方を再生する。読み上げ非対応ブラウザでは項目ごと非表示。読み上げ対象のメッセージが編集・削除された、会話がクリアされた、ページから離脱した場合は読み上げを停止する
|
|
14
|
+
- 音声入力を開始する時点で読み上げが再生中なら、先に読み上げを停止する(マイクが自分の声を誤って拾うのを防ぐ最小限の配慮)
|
|
15
|
+
- 認識の失敗(無音・マイク権限拒否・非対応・通信エラー)は LLM を介さず、その場で画面上に短く表示する
|
|
16
|
+
|
|
17
|
+
旧 voice プラグイン(`wecool-chat/plugins/voice`、`start_voice_input` / `speak_text` tool)は撤去した。発話で LLM に音声入出力を依頼する経路は廃止され、ボタン操作のみで音声入力・読み上げが行える。これに伴い `ToolHandlerEnvelope.submitUserMessage`(tool 結果を正規のユーザー発話として再送する内部機構)も、唯一の利用者だった voice プラグインの撤去とあわせて削除した。voice プラグインはまだ一度も公開されていなかったため、これらは破壊的変更ではない。
|
|
18
|
+
|
|
19
|
+
- 1471b84: **継続音声モード(ハンズフリー会話ループ)**(issue #262)。マイクボタンの隣のトグルを押すと、聞き取り → 送信 → 応答の読み上げ → また聞き取り、を利用者の操作なしに繰り返す。`voice: true` を有効にしたうえで、聞き取りと読み上げの**双方**が使える環境でのみトグルを表示する。
|
|
20
|
+
|
|
21
|
+
- **状態表示**: 入力欄の上に、今どの段階か(聞いています / 考えています / 話しています / 確認をお待ちしています)と終了ボタンを出す。`role="status"` + `aria-live="polite"` で支援技術にも伝える
|
|
22
|
+
- **逐次読み上げ**: 応答の完成を待たず、段落が確定した順に読み上げ始める。道具の実行を挟んで応答が複数に分かれても順に読む
|
|
23
|
+
- **読み上げテキストの整形**: 強調記号・リンク先アドレス・絵文字は読まず、表とコードのかたまりは「表」「コードブロック」の一語に置き換える。1 応答あたり 2000 文字を超える分は読まず、省略した旨を一度だけ読む。この整形は既存の読み上げボタンにも適用される
|
|
24
|
+
- **実行前確認**(`requiresConfirmation` のツール)が出ている間はループを止め、自動終了もしない。承認・拒否の後に再開する
|
|
25
|
+
- **自動終了**: 2 分なにも聞き取れない / マイクが使えない・許可されていない / 通信に続けて失敗した場合に終了し、**理由を表示したうえで読み上げる**(画面を見ていない利用者に伝えるため)。通信の失敗のみ約 1.5 秒あけて 1 回だけやり直す
|
|
26
|
+
- 別タブへ移ると終了する。会話の切替・削除・再生成・編集・応答の停止でも終了する
|
|
27
|
+
- モードの入切は保存しない(訪問のたびに「切」から始まる)
|
|
28
|
+
|
|
29
|
+
ホスト設定 `voiceLoopStartCue?: string | Partial<Record<Locale, string>>` を追加した。トグルを入れた直後に読み上げる合図で、既定は ja「どうぞ」/ en "Go ahead"。文字列なら全ロケール共通、ロケール別のオブジェクトも受ける。**空文字を渡すと音は出ないが、無音の発話が 1 回だけ流れる** — iOS Safari は「利用者操作の中で一度も読み上げを呼んでいないページ」の読み上げを失敗も通知せず無視するため、この解錠を省くと以後のターンがすべて無音になる。
|
|
30
|
+
|
|
31
|
+
聞き取りの失敗分類を細かくした(`device_unavailable` / `language_unsupported` を追加)。やり直しても直らない失敗と、黙っていただけの状態を区別するためで、**単発マイクの失敗表示の文言も一部変わる**。
|
|
32
|
+
|
|
33
|
+
i18n キー追加(ja / en): `voiceLoopToggleStartAria` / `voiceLoopToggleStopAria` / `voiceLoopStopButton` / `voiceLoopStartCue` / `voiceLoopStatusListening` / `voiceLoopStatusThinking` / `voiceLoopStatusSpeaking` / `voiceLoopStatusAwaitingConfirmation` / `voiceLoopEndedSilence` / `voiceLoopEndedNetwork` / `voiceLoopEndedPermission` / `voiceLoopEndedDevice` / `voiceLoopEndedLanguage` / `speechCodeBlockLabel` / `speechTableLabel` / `speechTruncatedNotice` / `voiceInputErrorDeviceUnavailable` / `voiceInputErrorLanguageUnsupported`。
|
|
34
|
+
|
|
35
|
+
**表示の変更**: 入力欄の右にあった「クリア」(ゴミ箱)ボタンを、ヘッダーの設定メニュー「新しい会話を始める」へ移した。トグルが増えて入力欄が狭くなるのを避けるためで、動作はヘッダーの「+ 新しい会話」と同じ(削除ではなく新規開始)。ヘッダーを持たない `layout: "input-only"` では従来どおり入力欄の隣に残る。i18n キー `clearButton` は `newConversationAction` へ置き換えた。
|
|
36
|
+
|
|
37
|
+
**既知の制約(Android)**: 端末の音声認識エンジンが、認識セッションの開始・終了ごとにシステム音を鳴らす。継続モードは毎ターン聞き取りをやり直し、黙っている間も繰り返すため、この音が繰り返し鳴る。Web Speech API から抑止する手段は無く、`continuous = true` を指定しても認識エンジンが独自にセッションを区切るため減らない(実機で確認)。訪問者は端末の通知音・システム音の音量を下げれば消せる(読み上げはメディア音量なので残る)。
|
|
38
|
+
|
|
39
|
+
`voice: false` のホストの挙動は変わらない(後方互換)。
|
|
40
|
+
|
|
41
|
+
- 79bb22f: 会話単位の削除を追加(issue #84 追加スコープ)。会話を表示中のとき、ヘッダーの「⋮」メニューに「この会話を削除」項目が現れる(新規会話状態では非表示)。確認ダイアログを挟んで実行すると、表示中の会話を `DELETE /api/conversations/:sessionId` でサーバーから**完全に物理削除**し、一覧から消して新規会話状態へ切り替える。認可は会話復元 API と同じ「API キー + 訪問者 ID + セッション ID の全一致」で、両 UUID を知る本人のブラウザのみが削除できる(他人の会話は 404)。既に消えている(404)場合は成功扱い。進行中の応答は先に中断してから削除する。削除に失敗(通信断・5xx)した場合は画面状態を変えず、開発者向けにログのみ残す。別タブへの即時反映はせず、次の一覧再取得で追随する(既知の制約)。
|
|
42
|
+
|
|
43
|
+
あわせて既存の全削除メニューの文言を「履歴をこのブラウザから消す」→「すべての履歴をこのブラウザから消す」/ "Clear history from this browser" → "Clear all history from this browser" に強化し、2 操作(会話単位の完全削除 vs ブラウザからの紐付け切断)の違いを入口で明示した。新規 i18n キー `deleteConversationMenuItem` / `deleteConversationConfirmMessage` / `deleteConversationConfirmRegionLabel`(ja / en)を追加。`layout: "input-only"` はヘッダーを持たないため導線なし。公開 API(config / props / プラグイン接点)の破壊的変更はなし。
|
|
44
|
+
|
|
45
|
+
- 6eb51b4: 「履歴をこのブラウザから消す」導線を追加(issue #84)。ヘッダーの「⋮」メニューに項目を追加し、確認ダイアログを挟んで実行すると、ブラウザに保存された匿名の訪問者 ID(localStorage キー `wecool-chat:visitor-id`)を破棄・再発行する。実行後はこのブラウザから過去の会話一覧・入力欄の ↑/↓ 呼び戻し履歴(`wecool-chat:input-history:` 接頭辞)へ到達できなくなり、新規会話状態に切り替わる。進行中の応答は先に中断してからリセットするため、中断済みの応答が新会話に紛れ込まない。同一サイトを開いている別タブは `storage` イベントで追随し、自動で新規会話状態になる。サーバー上の会話ログは即時削除せず、既存の保持期間(365 日)経過後の自動削除に委ねる(旧識別子では到達不能になる)。localStorage 不可の環境(プライベートモード等)でもエラーなくそのタブ内の識別子が再発行される。`layout: "input-only"` はヘッダーを持たないため導線なし。`useVisitorId` の戻り値を `{ visitorId, resetVisitorId }` に拡張(内部 API)。新規 i18n キー `resetHistoryMenuItem` / `resetHistoryConfirmMessage` / `resetHistoryConfirmRegionLabel`(ja / en)を追加。公開 API(config / props / プラグイン接点)の破壊的変更はなし
|
|
46
|
+
|
|
47
|
+
### Patch Changes
|
|
48
|
+
|
|
49
|
+
- 6a48f3d: 依存パッケージ lucide-react を 0.460.0 から 1.25.0 に更新した(dependabot #281)。ウィジェットの外部仕様(設定項目・公開 API・アイコンの見え方)に変更はない。使用中の全アイコンは typecheck / build / test(CI green)で互換を確認済みで、bundle-size チェックも通過している。
|
|
50
|
+
- 1fde7a2: 依存パッケージの patch / minor 一括更新(dependabot #308)。ウィジェットのバンドルに入るランタイム依存は highlight.js 11.12.0 / react・react-dom 19.2.8。外部仕様に変更はない。wecool-cli の変更は devDependencies のみのためリリース対象外。
|
|
51
|
+
- 0f48434: 音声機能(マイク入力・読み上げ・継続音声モード)を動的 import に分離し、`config.voice` が無効なホストの初期バンドルから外した(issue #295)。初期バンドルは gzip 119.00 KB → 115.31 KB(brotli 100.88 KB → 97.91 KB。いずれも本変更の直前に同一環境で測り直した値で、issue #262 時点の記録 118.96 / 100.99 KB とはビルドの微差がある)。
|
|
52
|
+
|
|
53
|
+
外部仕様(設定項目・公開 API・画面の見え方)に変更はない。`voice: true` のホストではウィジェットのマウント直後に音声の chunk を先読みするため、利用者がボタンを押す時点の待ちは発生しない。
|
|
54
|
+
|
|
3
55
|
## 0.9.0
|
|
4
56
|
|
|
5
57
|
**Bundle size**: Initial 110.2 KB gzip / 93.8 KB brotli · Total 245.0 KB gzip
|
package/README.ja.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[](https://www.npmjs.com/package/wecool-chat)
|
|
6
6
|
[](https://www.npmjs.com/package/wecool-chat)
|
|
7
7
|
[](https://opensource.org/licenses/MIT)
|
|
8
|
-
[](https://www.npmjs.com/package/wecool-chat)
|
|
9
9
|
|
|
10
10
|
> 自然言語で UI を操作できる、どんなフレームワークでも使える LLM チャットウィジェット。
|
|
11
11
|
|
|
@@ -647,6 +647,62 @@ initWecoolChat({ endpoint, tools: [], observe: { http: true, errors: false } });
|
|
|
647
647
|
|
|
648
648
|
---
|
|
649
649
|
|
|
650
|
+
## 音声入出力(`voice`)
|
|
651
|
+
|
|
652
|
+
ブラウザ標準の Web Speech API を使い、入力欄への**マイクボタン**と assistant メッセージの操作メニューへの**読み上げ項目**を追加できます。外部ライブラリ不要・サーバー往復も発生しません。
|
|
653
|
+
|
|
654
|
+
- **既定は無効**。`voice: true` で有効化する opt-in 機能です。
|
|
655
|
+
- **マイクボタン**: 押すと即座に聞き取りを開始し(ボタンの見た目が変化して分かる)、1回の発話を認識したら聞き取りを終えます。認識結果は**テキストを打って送信した場合と全く同じ経路**で送信されます(吹き出し表示・履歴保存・ホスト側の文言加工が同様に適用される)。Chrome / Edge(Mac・Windows)・Safari(macOS・iOS)に対応。非対応ブラウザ(Firefox は `SpeechRecognition` 未実装)ではボタンごと非表示になります。
|
|
656
|
+
- **読み上げ項目**: assistant の発言のみに表示され、`SpeechSynthesis`(全主要ブラウザ対応)が使える場合に出ます。押すと LLM を介さずその発言本文を読み上げ、読み上げ中に再度押すと停止します。別メッセージの読み上げを押すと前の読み上げは止まります。読み上げ対象のメッセージが編集・削除された、会話がクリアされた、ウィジェットがアンマウントされた場合も読み上げは止まります。
|
|
657
|
+
- マイクを開始する時点で読み上げが再生中なら、先に読み上げを止めます(マイクが AI 自身の声を誤って拾わないための配慮)。
|
|
658
|
+
- 認識の失敗(無音・マイク権限拒否・通信エラー・非対応)は LLM を介さず、その場で画面上に短く表示されます。
|
|
659
|
+
|
|
660
|
+
```tsx
|
|
661
|
+
initWecoolChat({ endpoint, tools: [], voice: true });
|
|
662
|
+
```
|
|
663
|
+
|
|
664
|
+
**起動時固定の制約:** locale / プラグイン / observe と同様、`voice` はウィジェットのマウント時に解決されます。変更にはウィジェットの再初期化が必要です。
|
|
665
|
+
|
|
666
|
+
**「読み上げて」のような発話で LLM に依頼する経路は意図的に廃止しています**——音声入出力はボタン操作のみで起動し、LLM 起点の音声起動につきまとっていた既知の信頼性課題(issue #261 参照)を構造的に回避するためです。
|
|
667
|
+
|
|
668
|
+
### 継続音声モード(ハンズフリー会話)
|
|
669
|
+
|
|
670
|
+
マイクボタンの隣のトグルを押すと、**手を触れずに会話を続けられます**。聞き取り → 送信 → 応答の読み上げ → また聞き取り、を自動で繰り返します。`voice: true` にすると、聞き取りと読み上げの**双方**が使える環境でのみトグルが出ます。
|
|
671
|
+
|
|
672
|
+
- **状態表示**: 入力欄の上に、今どの段階か(聞いています / 考えています / 話しています / 確認をお待ちしています)と終了ボタンが出ます。支援技術にも `role="status"` で伝わります。
|
|
673
|
+
- **逐次読み上げ**: 応答の完成を待たず、段落が確定した順に読み上げ始めます。長い応答でも待たされません。
|
|
674
|
+
- **読み上げの整形**: 強調記号・リンク先アドレス・絵文字は読まれません。表とコードのかたまりは「表」「コードブロック」の一語に置き換わります。1 応答あたり 2000 文字を超える分は読まず、省略した旨を一度だけ読みます。
|
|
675
|
+
- **実行前確認**(`requiresConfirmation` のツール)が出ている間はループが止まり、承認・拒否の後に再開します。
|
|
676
|
+
- **自動終了**: 2 分なにも聞き取れない、マイクが使えない・許可されていない、通信に続けて失敗した場合は自動で終了し、**理由を画面に出したうえで読み上げます**(画面を見ていない利用者に伝えるため)。
|
|
677
|
+
- **モードの入切は保存されません**。訪問のたびに「切」から始まります。
|
|
678
|
+
|
|
679
|
+
#### `voiceLoopStartCue` — 開始の合図
|
|
680
|
+
|
|
681
|
+
トグルを入れた直後に読み上げる短い一言です。既定は ja「どうぞ」/ en "Go ahead"。文字列を渡すと全ロケール共通、ロケール別のオブジェクトも受け付けます。
|
|
682
|
+
|
|
683
|
+
```ts
|
|
684
|
+
initWecoolChat({ endpoint, tools: [], voice: true, voiceLoopStartCue: "お話しください" });
|
|
685
|
+
|
|
686
|
+
// ロケール別に分ける場合
|
|
687
|
+
initWecoolChat({
|
|
688
|
+
endpoint,
|
|
689
|
+
tools: [],
|
|
690
|
+
voice: true,
|
|
691
|
+
voiceLoopStartCue: { ja: "お話しください", en: "I'm listening" },
|
|
692
|
+
});
|
|
693
|
+
```
|
|
694
|
+
|
|
695
|
+
**空文字を渡すと音は出ませんが、無音の発話が 1 回だけ流れます。** これは省略できません。iOS Safari は「利用者操作の中で一度も読み上げを呼んでいないページ」の読み上げを、失敗も通知せず無視するためです。この無音の発話で解錠しておかないと、以後のターンの読み上げが**すべて無音になります**。
|
|
696
|
+
|
|
697
|
+
#### 既知の制限
|
|
698
|
+
|
|
699
|
+
- **iOS Safari**: 上記のとおり、開始操作の中で読み上げを 1 回呼ぶ必要があります。パッケージ側で対応済みなので利用者側の対応は不要ですが、`voiceLoopStartCue` を空にしても無音の発話が流れるのはこのためです。
|
|
700
|
+
- **非対応ブラウザ**: `SpeechRecognition` を実装していないブラウザ(Firefox など)ではトグルごと表示されません。読み上げだけが使えない環境でも同様です。
|
|
701
|
+
- **プラグインへ渡る locale は起動時固定**です。`/lang` での切替に追随するのは本体の表示文言と読み上げ・認識の言語までです。
|
|
702
|
+
- 読み上げ中の割り込み(話しかけて止める)には対応していません。止めるには終了ボタンかトグルを使ってください。
|
|
703
|
+
|
|
704
|
+
---
|
|
705
|
+
|
|
650
706
|
## フレームワーク別ガイド
|
|
651
707
|
|
|
652
708
|
### Vue 3
|
|
@@ -795,25 +851,27 @@ const ChatWidget = dynamic(() => import("wecool-chat").then((m) => m.ChatWidget)
|
|
|
795
851
|
|
|
796
852
|
## ChatConfig オプション
|
|
797
853
|
|
|
798
|
-
| プロパティ | 型
|
|
799
|
-
| -------------------- |
|
|
800
|
-
| `endpoint` | `string`
|
|
801
|
-
| `apiKey` | `string`
|
|
802
|
-
| `tools` | `Tool[]`
|
|
803
|
-
| `locale` | `"ja" \| "en"`
|
|
804
|
-
| `placeholder` | `string`
|
|
805
|
-
| `theme` | `"auto" \| "light" \| "dark"`
|
|
806
|
-
| `className` | `string`
|
|
807
|
-
| `toolTimeout` | `number`
|
|
808
|
-
| `disableShadowDom` | `boolean`
|
|
809
|
-
| `layout` | `LayoutPattern`
|
|
810
|
-
| `transparent` | `boolean`
|
|
811
|
-
| `narrateToolResults` | `boolean`
|
|
812
|
-
| `
|
|
813
|
-
| `
|
|
814
|
-
| `
|
|
815
|
-
| `
|
|
816
|
-
| `
|
|
854
|
+
| プロパティ | 型 | 必須 | デフォルト | 説明 |
|
|
855
|
+
| -------------------- | ------------------------------------------- | ---- | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
856
|
+
| `endpoint` | `string` | ✓ | — | API エンドポイント URL(HTTPS 必須。開発用に `http://localhost` / `http://127.0.0.1` のみ例外で許可) |
|
|
857
|
+
| `apiKey` | `string` | | — | ダッシュボードで発行した API キー |
|
|
858
|
+
| `tools` | `Tool[]` | ✓ | — | ツール定義の配列 |
|
|
859
|
+
| `locale` | `"ja" \| "en"` | | `"ja"` | UI 言語 |
|
|
860
|
+
| `placeholder` | `string` | | locale に応じて切替 | 入力欄のプレースホルダー |
|
|
861
|
+
| `theme` | `"auto" \| "light" \| "dark"` | | `"light"` | カラーテーマ。`"auto"` は OS のダークモード設定に追従 |
|
|
862
|
+
| `className` | `string` | | — | ルート要素に付与するクラス名 |
|
|
863
|
+
| `toolTimeout` | `number` | | `30000` | ツール実行のタイムアウト (ms) |
|
|
864
|
+
| `disableShadowDom` | `boolean` | | `false` | Shadow DOM を使わずに通常 DOM へマウント |
|
|
865
|
+
| `layout` | `LayoutPattern` | | `floating-bottom-right` | 9 種類のレイアウトパターンから 1 つ選ぶ。[動作モード](#動作モード-layout-パターン) 参照 |
|
|
866
|
+
| `transparent` | `boolean` | | `false` | `layout: "header-banner"` のときのみ意味を持つ。半透明背景で本文を透かす |
|
|
867
|
+
| `narrateToolResults` | `boolean` | | `false` | tool 実行ごとに `tool_choice: "none"` で追加の LLM 呼び出しを行い、短いナレーションテキストを取得する。詳細は[後述](#tool-結果のナレーション)。 |
|
|
868
|
+
| `voice` | `boolean` | | `false` | マイク入力・読み上げ・継続音声モードを有効化する。[音声入出力](#音声入出力voice) 参照 |
|
|
869
|
+
| `voiceLoopStartCue` | `string \| Partial<Record<Locale, string>>` | | ja「どうぞ」/ en "Go ahead" | 継続音声モード開始時に読み上げる合図。空文字でも iOS 解錠のため無音の発話が 1 回流れる |
|
|
870
|
+
| `plugins` | `ChatPlugin[]` | | `[]` | プラグイン配列。[プラグイン](#プラグイン) 参照 |
|
|
871
|
+
| `onToolExecute` | `(name, args) => void` | | — | ツール実行直前のコールバック |
|
|
872
|
+
| `onToolResult` | `(name, result) => void` | | — | ツール実行完了後のコールバック |
|
|
873
|
+
| `onMessagesChange` | `(messages: Message[]) => void` | | — | 内部の `messages` 配列が変化するたびに呼ばれる。ホスト側 UI へ会話列を同期する用途(`layout: "input-only"` と組み合わせる) |
|
|
874
|
+
| `onError` | `(error: Error) => void` | | — | エラー時のコールバック |
|
|
817
875
|
|
|
818
876
|
### Tool 結果のナレーション
|
|
819
877
|
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[](https://www.npmjs.com/package/wecool-chat)
|
|
6
6
|
[](https://www.npmjs.com/package/wecool-chat)
|
|
7
7
|
[](https://opensource.org/licenses/MIT)
|
|
8
|
-
[](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
|
|
|
@@ -699,6 +699,103 @@ signals.
|
|
|
699
699
|
|
|
700
700
|
---
|
|
701
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
|
+
|
|
797
|
+
---
|
|
798
|
+
|
|
702
799
|
## Framework Guides
|
|
703
800
|
|
|
704
801
|
### Vue 3
|
|
@@ -847,27 +944,29 @@ const ChatWidget = dynamic(() => import("wecool-chat").then((m) => m.ChatWidget)
|
|
|
847
944
|
|
|
848
945
|
## ChatConfig Options
|
|
849
946
|
|
|
850
|
-
| Property | Type
|
|
851
|
-
| --------------------- |
|
|
852
|
-
| `endpoint` | `string`
|
|
853
|
-
| `apiKey` | `string`
|
|
854
|
-
| `tools` | `Tool[]`
|
|
855
|
-
| `locale` | `"ja" \| "en"`
|
|
856
|
-
| `placeholder` | `string`
|
|
857
|
-
| `theme` | `"auto" \| "light" \| "dark"`
|
|
858
|
-
| `className` | `string`
|
|
859
|
-
| `toolTimeout` | `number`
|
|
860
|
-
| `disableShadowDom` | `boolean`
|
|
861
|
-
| `layout` | `LayoutPattern`
|
|
862
|
-
| `transparent` | `boolean`
|
|
863
|
-
| `narrateToolResults` | `boolean`
|
|
864
|
-
| `persistConversation` | `"tab"`
|
|
865
|
-
| `errorReporting` | `boolean`
|
|
866
|
-
| `
|
|
867
|
-
| `
|
|
868
|
-
| `
|
|
869
|
-
| `
|
|
870
|
-
| `
|
|
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 |
|
|
871
970
|
|
|
872
971
|
### Narrate tool results
|
|
873
972
|
|
|
@@ -911,7 +1010,7 @@ initWecoolChat({
|
|
|
911
1010
|
|
|
912
1011
|
### What is (and isn't) collected
|
|
913
1012
|
|
|
914
|
-
Reports are sent **only** to your configured `endpoint` (`POST /api/client-errors`), **only** when
|
|
1013
|
+
Reports are sent **only** to your configured `endpoint` (`POST /api/v1/client-errors`), **only** when
|
|
915
1014
|
an error actually occurs, and are **discarded on send failure** (no retry, no local storage — one
|
|
916
1015
|
error, one send attempt).
|
|
917
1016
|
|
|
@@ -979,6 +1078,29 @@ Typing `/` at the **start** of the input field opens a command palette. Type to
|
|
|
979
1078
|
|
|
980
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)).
|
|
981
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
|
+
|
|
982
1104
|
### Colors / theme
|
|
983
1105
|
|
|
984
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
|
+
};
|