@data-netmonk/mona-chat-widget 2.6.6 → 2.6.8

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 (4) hide show
  1. package/README.md +119 -104
  2. package/dist/index.cjs +56 -56
  3. package/dist/index.js +6613 -6497
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -18,7 +18,7 @@ Chat widget package developed by Netmonk data & solution team to be imported in
18
18
 
19
19
  ✅ **Previous Non-breaking Changes (`v2.6.1`):**
20
20
  1. **Built-in voice mode button** - Chat widget now includes a microphone button to toggle voice mode directly from the input area
21
- 2. **Speech-to-text flow for voice mode** - Recorded user audio is sent to the configured `VITE_STT_ENDPOINT`, then the transcription is forwarded as a normal chat message
21
+ 2. **Speech-to-text flow for voice mode** - Recorded user audio is sent to the configured STT endpoint, then the transcription is forwarded as a normal chat message
22
22
  3. **Phoneme-driven avatar animation** - The widget can animate Mona's avatar during TTS playback based on phoneme/viseme IDs returned by the backend
23
23
  4. **Supported phoneme IDs** - `A`, `BP`, `ChJ`, `E`, `FV`, `I`, `KG`, `L`, `M`, `O`, `SZ`, `U`
24
24
 
@@ -93,83 +93,97 @@ Chat widget package developed by Netmonk data & solution team to be imported in
93
93
 
94
94
  ## 🚅 Quick start
95
95
 
96
- ### Prerequisites
97
-
98
96
  ---
99
97
 
100
- 1. Install dependencies
101
- ```
102
- npm install --legacy-peer-deps
103
- ```
104
- 2. Copy .env.example
105
- ```
106
- cp .env.example .env
107
- ```
108
- 3. Populate .env
109
- 4. Optional speech endpoints
110
-
111
- To enable voice mode and phoneme-based avatar animation, set these environment variables in your `.env` file:
112
- ```
113
- VITE_STT_ENDPOINT=https://voice.netmonk-ai.tech/stt
114
- VITE_STT_API_KEY=
115
- VITE_STT_API_KEY_HEADER=x-api-key
116
- VITE_STT_API_KEY_PREFIX=
117
- VITE_TTS_ENDPOINT=https://your-tts-service.example.com/synthesize
118
- VITE_TTS_API_KEY=
119
- VITE_TTS_API_KEY_HEADER=Authorization
120
- VITE_TTS_API_KEY_PREFIX=Bearer
121
- VITE_PREFER_WEBHOOK_TTS=true
122
- VITE_TTS_MINIO_OBJECT_ENDPOINT=http://localhost:8000/minio/object
123
- VITE_TTS_MINIO_API_KEY=
124
- VITE_TTS_MINIO_API_KEY_HEADER=X-API-Key
125
- VITE_TTS_MINIO_API_KEY_PREFIX=
126
- VITE_TTS_MINIO_BUCKET=chatbot-tts
127
- VITE_TTS_MINIO_DOWNLOAD=false
128
- ```
129
-
130
- `VITE_STT_ENDPOINT` is used by the built-in mic button to transcribe recorded audio.
131
- For the Netmonk STT service, set `VITE_STT_API_KEY_HEADER=x-api-key` and leave `VITE_STT_API_KEY_PREFIX` empty so the widget sends the raw key value without `Bearer`.
132
- `VITE_PREFER_WEBHOOK_TTS=true` makes the widget prioritize TTS assets from webhook response (for example `tts_assets.items[].audio_object_key`) and use `VITE_TTS_ENDPOINT` only as fallback.
133
- Widget tidak lagi konek langsung ke MinIO. Object diambil lewat endpoint voice-engine:
134
- `GET /minio/object?object_key=<key>&bucket=<bucket>&download=<true|false>`.
135
- `VITE_TTS_MINIO_API_KEY` opsional. Jika diisi, widget mengirim header `X-API-Key` (atau header custom via `VITE_TTS_MINIO_API_KEY_HEADER`).
136
- `VITE_TTS_MINIO_BUCKET` dipakai sebagai default bucket bila payload webhook tidak mengirim bucket.
137
- Set `VITE_TTS_MINIO_DOWNLOAD=true` jika ingin force download mode saat fetch object.
138
- `VITE_TTS_ENDPOINT` is used for fallback TTS playback.
139
- The widget expects the TTS response body to contain raw audio binary such as `audio/wav`, and reads lip-sync metadata from `x-tts-visemes-b64`, `x-tts-phonemes-b64`, and `x-tts-phoneme-timeline-b64` response headers.
140
- If your TTS endpoint is called cross-origin, the server must expose those headers with `Access-Control-Expose-Headers`.
141
- If your TTS service uses a different header such as `x-api-key`, set `VITE_TTS_API_KEY_HEADER=x-api-key` and leave the prefix empty.
142
- If you are consuming the published package inside another project, prefer passing these values via the `voiceConfig` or `widgetConfig` props because the host app `.env` is not injected into an already-built library bundle.
143
- You can also set runtime defaults on the host page before mounting the widget via `window.__MONA_WIDGET_RUNTIME_CONFIG__`.
144
- Example:
145
- ```jsx
146
- <ChatWidget
147
- sourceId="source456"
148
- webhookUrl="https://api.example.com/webhook"
149
- voiceConfig={{
150
- sttEndpoint: "https://voice.netmonk-ai.tech/stt",
151
- sttApiKey: "your-key",
152
- sttApiKeyHeader: "x-api-key",
153
- sttApiKeyPrefix: "",
154
- ttsEndpoint: "https://voice.example.com/tts",
155
- ttsApiKey: "your-key",
156
- ttsApiKeyHeader: "Authorization",
157
- ttsApiKeyPrefix: "Bearer",
158
- }}
159
- />
160
- ```
161
- 5. Optional TTS debug logging
162
-
163
- To inspect TTS queue and playback lifecycle in browser console, set `VITE_DEBUG_TTS=true` in your `.env` file.
164
- Keep this disabled in production to avoid noisy logs.
165
- 6. Enable mock mode (optional)
166
-
167
- To test the chat widget without a backend server, set `VITE_USE_MOCK_RESPONSES=true` in your `.env` file. The widget will respond to messages like:
168
- - "start", "hello", "hi", "halo" - Greeting messages
169
- - "help", "bantuan" - Help information
170
- - "terima kasih", "thank you" - Acknowledgments
171
- - "bye", "goodbye" - Farewell messages
172
- - And more! Check `src/components/ChatWidget/utils/helpers.js` for full list
98
+ 1. Install the package
99
+ ```bash
100
+ npm install @data-netmonk/mona-chat-widget
101
+ ```
102
+ 2. Render the widget with the minimum required props
103
+ ```jsx
104
+ import { ChatWidget } from "@data-netmonk/mona-chat-widget";
105
+
106
+ export default function App() {
107
+ return (
108
+ <ChatWidget
109
+ sourceId="source-123"
110
+ webhookUrl="https://api.example.com/webhook"
111
+ />
112
+ );
113
+ }
114
+ ```
115
+ 3. Choose the usage mode you need
116
+
117
+ **1. Basic mode**
118
+
119
+ ```jsx
120
+ <ChatWidget
121
+ sourceId="source-123"
122
+ webhookUrl="https://api.example.com/webhook"
123
+ />
124
+ ```
125
+
126
+ **2. With auth mode**
127
+
128
+ ```jsx
129
+ <ChatWidget
130
+ sourceId="source-123"
131
+ webhookUrl="https://api.example.com/webhook"
132
+ userId="user-123"
133
+ username="John"
134
+ authUrl="https://api.example.com/login/chatwidget"
135
+ />
136
+ ```
137
+
138
+ **3. With voice mode**
139
+
140
+ ```jsx
141
+ <ChatWidget
142
+ sourceId="source-123"
143
+ webhookUrl="https://api.example.com/webhook"
144
+ voiceConfig={{
145
+ sttEndpoint: "https://voice.example.com/stt",
146
+ sttApiKey: "your-stt-key",
147
+ ttsEndpoint: "https://voice.example.com/tts",
148
+ ttsApiKey: "your-tts-key",
149
+ ttsMinioObjectEndpoint: "https://voice.example.com/minio/object",
150
+ ttsMinioApiKey: "your-minio-key",
151
+ ttsMinioBucket: "chatbot-tts",
152
+ }}
153
+ />
154
+ ```
155
+
156
+ **4. Full props example**
157
+
158
+ ```jsx
159
+ <ChatWidget
160
+ sourceId="source-123"
161
+ webhookUrl="https://api.example.com/webhook"
162
+ userId="user-123"
163
+ authUrl="https://api.example.com/login/chatwidget"
164
+ username="John Doe"
165
+ voiceConfig={{
166
+ sttEndpoint: "https://voice.example.com/stt",
167
+ sttApiKey: "your-stt-key",
168
+ ttsEndpoint: "https://voice.example.com/tts",
169
+ ttsApiKey: "your-tts-key",
170
+ ttsMinioObjectEndpoint: "https://voice.example.com/minio/object",
171
+ ttsMinioApiKey: "your-minio-key",
172
+ ttsMinioBucket: "chatbot-tts",
173
+ }}
174
+ />
175
+ ```
176
+
177
+ **Common optional props**
178
+
179
+ - `userId`: ID user login. Jika tidak diisi, widget akan memakai guest visitor ID.
180
+ - `username`: nama yang dikirim bersama session chat.
181
+ - `authUrl`: endpoint auth/refresh khusus chat widget.
182
+ - `data`: custom payload tambahan untuk backend.
183
+ - `voiceConfig`: aktifkan voice mode, STT, TTS, dan phoneme avatar bila dibutuhkan.
184
+ - `showLauncher`, `autoOpen`, `enabled`, `position`, `width`, `height`: untuk perilaku dan layout widget.
185
+
186
+ By default, STT and TTS requests send the API key using `x-api-key` without any prefix. MinIO object fetch uses `X-API-Key`. If your provider needs a different auth format, override it through `voiceConfig`.
173
187
 
174
188
  ---
175
189
 
@@ -180,8 +194,8 @@ Chat widget package developed by Netmonk data & solution team to be imported in
180
194
  The chat widget includes a built-in mock mode for testing and demonstrations without requiring a backend server.
181
195
 
182
196
  **To enable mock mode:**
183
- 1. Set `VITE_USE_MOCK_RESPONSES=true` in your `.env` file
184
- 2. Run the app normally with `npm run dev`
197
+ 1. Pass `widgetConfig={{ useMockResponses: true }}`
198
+ 2. Render the widget normally
185
199
 
186
200
  **Mock responses include:**
187
201
  - Greetings (hello, hi, halo, start) - with interactive buttons
@@ -353,9 +367,9 @@ For responses with buttons:
353
367
 
354
368
  ---
355
369
 
356
- The widget now includes a built-in microphone button in the input area. Clicking the button toggles voice mode, requests microphone access, records speech, sends the recorded audio to `VITE_STT_ENDPOINT`, and forwards the returned transcription as a regular user message.
370
+ The widget now includes a built-in microphone button in the input area. Clicking the button toggles voice mode, requests microphone access, records speech, sends the recorded audio to `voiceConfig.sttEndpoint`, and forwards the returned transcription as a regular user message.
357
371
 
358
- If `VITE_STT_API_KEY` is set, the STT request also includes the configured auth header. For `https://voice.netmonk-ai.tech/stt`, use `x-api-key` without any prefix. Other providers can still use `Authorization: Bearer <key>` or any custom header via `.env`.
372
+ If `voiceConfig.sttApiKey` is set, the STT request includes `x-api-key: <key>` by default. If another provider needs a different auth format, override it through `voiceConfig`.
359
373
 
360
374
  **Expected STT request/response shape:**
361
375
 
@@ -407,45 +421,46 @@ Phoneme IDs are normalized case-insensitively in the widget, so values such as `
407
421
  }
408
422
  ```
409
423
 
410
- When this payload is available, the widget resolves MinIO object keys first for audio and timeline metadata. If no usable asset is found, it falls back to `VITE_TTS_ENDPOINT`.
424
+ When this payload is available, the widget resolves MinIO object keys first for audio and timeline metadata. If no usable asset is found, it falls back to `voiceConfig.ttsEndpoint`.
411
425
 
412
426
  **Expected TTS response shape:**
413
427
 
414
428
  ```text
415
429
  body: <raw WAV or other audio binary>
416
430
  content-type: audio/wav
417
- x-tts-visemes-b64: W3siaWQiOiJNIiwic3RhcnRNcyI6MCwiZW5kTXMiOjEyMH1d
418
- x-tts-phonemes-b64: TSBBCg==
419
- x-tts-phoneme-timeline-b64: W3sicGhvbmVtZSI6Ik0iLCJzdGFydE1zIjowLCJlbmRNcyI6MTIwfV0=
431
+ x-tts-metadata-id: 7d8f6a0f0f684e97b7b8d8db67f4f3a1
432
+ x-tts-metadata-path: /tts/metadata/7d8f6a0f0f684e97b7b8d8db67f4f3a1
433
+ x-tts-duration-ms: 120
420
434
  ```
421
435
 
422
- `x-tts-phonemes-b64` is the legacy phoneme string, while `x-tts-phoneme-timeline-b64` is the timed phoneme timeline. The base64 headers should decode as:
423
-
424
- Decoded `x-tts-phonemes-b64`:
425
-
426
- ```text
427
- M A
428
- ```
429
-
430
- Decoded `x-tts-phoneme-timeline-b64`:
436
+ Metadata lengkap diambil dari endpoint metadata yang ditunjuk header tadi:
431
437
 
432
438
  ```json
433
- [
434
- { "phoneme": "M", "startMs": 0, "endMs": 120 }
435
- ]
439
+ GET /tts/metadata/7d8f6a0f0f684e97b7b8d8db67f4f3a1
440
+ {
441
+ "id": "7d8f6a0f0f684e97b7b8d8db67f4f3a1",
442
+ "phonemes": "M A",
443
+ "phoneme_timeline": [
444
+ { "phoneme": "M", "startMs": 0, "endMs": 120 }
445
+ ],
446
+ "visemes": [
447
+ { "id": "M", "startMs": 0, "endMs": 120 },
448
+ { "id": "A", "startMs": 121, "endMs": 260 },
449
+ { "id": "SZ", "startMs": 261, "endMs": 420 }
450
+ ],
451
+ "duration_ms": 420
452
+ }
436
453
  ```
437
454
 
438
- Decoded `x-tts-visemes-b64`:
455
+ Widget ini masih mendukung header base64 lama sebagai fallback:
439
456
 
440
- ```json
441
- [
442
- { "id": "M", "startMs": 0, "endMs": 120 },
443
- { "id": "A", "startMs": 121, "endMs": 260 },
444
- { "id": "SZ", "startMs": 261, "endMs": 420 }
445
- ]
457
+ ```text
458
+ x-tts-visemes-b64
459
+ x-tts-phonemes-b64
460
+ x-tts-phoneme-timeline-b64
446
461
  ```
447
462
 
448
- The widget still supports the older JSON body format as a fallback, but header-based metadata is now the preferred format for binary audio responses.
463
+ Widget juga masih mendukung format JSON body lama sebagai fallback, tetapi untuk audio binary format metadata endpoint di atas sekarang jadi jalur utama yang direkomendasikan.
449
464
 
450
465
  ---
451
466