@babelbeez/sdk 0.3.2 → 0.3.3

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 CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  All notable changes to `@babelbeez/sdk` are documented here.
4
4
 
5
+ ## [0.3.3] - 2026-03-15
6
+
7
+ ### Fixed
8
+ - Added an explicit `hardDisconnect()` path for UI end-call actions and stabilized disconnect handling so explicit stop clicks no longer rely on promise chaining from `session.interrupt()`.
9
+ - Restored the intended AI end-call flow so the `end_conversation` tool triggers the configured localized goodbye turn from the SDK, instead of requiring the model to say goodbye before calling the tool.
10
+ - Added a `finalizing` button state to better represent in-progress disconnects for host UIs.
11
+
12
+
5
13
  ## [0.3.2] - 2026-01-30
6
14
 
7
15
  ### Fixed
package/README.md CHANGED
@@ -47,11 +47,18 @@ const client = new BabelbeezClient({
47
47
  publicChatbotId: 'YOUR_PUBLIC_CHATBOT_ID',
48
48
  });
49
49
 
50
- let currentState: 'idle' | 'loading' | 'active' | 'speaking' | 'error' | 'rag-retrieval' = 'idle';
50
+ let currentState:
51
+ | 'idle'
52
+ | 'loading'
53
+ | 'active'
54
+ | 'speaking'
55
+ | 'finalizing'
56
+ | 'error'
57
+ | 'rag-retrieval' = 'idle';
51
58
 
52
59
  // 2. Listen for state changes to drive your UI
53
60
  client.on('buttonState', (state) => {
54
- // state: 'idle' | 'loading' | 'active' | 'speaking' | 'error' | 'rag-retrieval'
61
+ // state: 'idle' | 'loading' | 'active' | 'speaking' | 'finalizing' | 'error' | 'rag-retrieval'
55
62
  console.log('Agent state:', state);
56
63
  currentState = state;
57
64
  updateMyButton(state); // implement this in your own UI
@@ -69,8 +76,8 @@ const startStopButton = document.getElementById('voice-button')!;
69
76
 
70
77
  startStopButton.addEventListener('click', async () => {
71
78
  if (currentState === 'active' || currentState === 'speaking' || currentState === 'rag-retrieval') {
72
- // Play nice goodbye UX (triggers configured farewell in Babelbeez)
73
- await client.disconnect('user_button_click');
79
+ // Immediate explicit stop for UI end-call actions
80
+ await client.hardDisconnect('user_button_click');
74
81
  } else if (currentState === 'idle' || currentState === 'error') {
75
82
  try {
76
83
  await client.connect(); // Browser will request microphone access
@@ -215,7 +222,7 @@ await client.connect();
215
222
 
216
223
  #### `disconnect(reason?: string): Promise<void>`
217
224
 
218
- Gracefully ends the current session and sends a final usage + transcript summary to Babelbeez.
225
+ Ends the current session and sends a final usage + transcript summary to Babelbeez. This method remains available as a compatibility wrapper.
219
226
 
220
227
  ```ts
221
228
  await client.disconnect();
@@ -224,7 +231,31 @@ await client.disconnect('user_button_click');
224
231
  ```
225
232
 
226
233
  - `reason` **(optional)** – String reason used for analytics and backend handling.
227
- - Passing `'user_button_click'` triggers the configured **goodbye message** before disconnecting.
234
+ - For explicit UI end-call actions, prefer `hardDisconnect('user_button_click')`.
235
+
236
+ ---
237
+
238
+ #### `hardDisconnect(reason?: string): Promise<void>`
239
+
240
+ Immediately ends the current session without waiting for assistant audio to finish.
241
+
242
+ ```ts
243
+ await client.hardDisconnect('user_button_click');
244
+ ```
245
+
246
+ Use this for explicit end-call buttons where the user expects an immediate stop.
247
+
248
+ ---
249
+
250
+ #### `gracefulDisconnect(reason?: string): Promise<void>`
251
+
252
+ Triggers the configured AI goodbye turn and then ends the session after that goodbye audio finishes.
253
+
254
+ ```ts
255
+ await client.gracefulDisconnect('ai_end_conversation_tool');
256
+ ```
257
+
258
+ This is primarily intended for SDK-managed end-of-call flows.
228
259
 
229
260
  ---
230
261
 
@@ -303,6 +334,7 @@ export type BabelbeezButtonState =
303
334
  | 'loading'
304
335
  | 'active'
305
336
  | 'speaking'
337
+ | 'finalizing'
306
338
  | 'error'
307
339
  | 'rag-retrieval';
308
340
  ```
@@ -3,6 +3,7 @@ export type BabelbeezButtonState =
3
3
  | 'loading'
4
4
  | 'active'
5
5
  | 'speaking'
6
+ | 'finalizing'
6
7
  | 'error'
7
8
  | 'rag-retrieval';
8
9
 
@@ -119,11 +120,26 @@ export class BabelbeezClient {
119
120
  connect(): Promise<void>;
120
121
 
121
122
  /**
122
- * Gracefully end the session and send /end-chat to the backend.
123
- * The optional reason is included in the payload.
123
+ * End the current session.
124
+ *
125
+ * For common UI stop actions, prefer `hardDisconnect('user_button_click')`
126
+ * for an immediate stop. This legacy wrapper remains available for
127
+ * compatibility and routes certain known reasons to the appropriate path.
124
128
  */
125
129
  disconnect(reason?: string): Promise<void>;
126
130
 
131
+ /**
132
+ * Immediately end the session without waiting for any active assistant
133
+ * audio to finish.
134
+ */
135
+ hardDisconnect(reason?: string): Promise<void>;
136
+
137
+ /**
138
+ * Trigger the configured AI goodbye turn and end the session after that
139
+ * goodbye audio finishes.
140
+ */
141
+ gracefulDisconnect(reason?: string): Promise<void>;
142
+
127
143
  /**
128
144
  * Optional helper to unlock the AudioContext (e.g. in response to a
129
145
  * user gesture) when running in a browser environment.