@elevenlabs/react-native 0.2.1 → 0.3.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elevenlabs/react-native",
3
- "version": "0.2.1",
3
+ "version": "0.3.1",
4
4
  "description": "ElevenLabs React Native SDK for Conversational AI",
5
5
  "main": "./dist/lib.js",
6
6
  "module": "./dist/lib.module.js",
@@ -51,13 +51,13 @@
51
51
  },
52
52
  "scripts": {
53
53
  "generate-version": "printf \"// This file is auto-generated during build\\nexport const PACKAGE_VERSION = \\\"%s\\\";\\n\" \"$npm_package_version\" > src/version.ts",
54
- "prebuild": "npm run generate-version",
54
+ "prebuild": "pnpm run generate-version",
55
55
  "build": "BROWSERSLIST_ENV=modern microbundle --jsx React.createElement --jsxFragment React.Fragment --jsxImportSource react src/index.ts",
56
56
  "clean": "rm -rf ./dist",
57
- "dev": "npm run clean && npm run generate-version && BROWSERSLIST_ENV=modern microbundle --jsx React.createElement --jsxFragment React.Fragment --jsxImportSource react src/index.ts -w --no-compress",
58
- "lint": "npm run lint:ts && npm run lint:es && npm run lint:prettier",
57
+ "dev": "pnpm run clean && pnpm run generate-version && BROWSERSLIST_ENV=modern microbundle --jsx React.createElement --jsxFragment React.Fragment --jsxImportSource react src/index.ts -w --no-compress",
58
+ "lint": "pnpm run lint:ts && pnpm run lint:es && pnpm run lint:prettier",
59
59
  "lint:ts": "tsc --noEmit --skipLibCheck",
60
- "lint:es": "npx eslint .",
60
+ "lint:es": "pnpm exec eslint .",
61
61
  "lint:prettier": "prettier 'src/**/*.ts' --check",
62
62
  "test": "jest"
63
63
  }
@@ -29,6 +29,7 @@ export interface Conversation {
29
29
  sendContextualUpdate: (text: string) => void;
30
30
  sendUserMessage: (text: string) => void;
31
31
  sendUserActivity: () => void;
32
+ setMicMuted: (muted: boolean) => void;
32
33
  }
33
34
 
34
35
  interface ElevenLabsContextType {
@@ -120,6 +121,7 @@ export const ElevenLabsProvider: React.FC<ElevenLabsProviderProps> = ({ children
120
121
  overrides,
121
122
  customLlmExtraBody,
122
123
  dynamicVariables,
124
+ userId,
123
125
  } = useConversationSession(callbacksRef, setStatus, setConnect, setToken, setConversationId, tokenFetchUrl);
124
126
 
125
127
  const {
@@ -187,6 +189,12 @@ export const ElevenLabsProvider: React.FC<ElevenLabsProviderProps> = ({ children
187
189
 
188
190
  const getId = () => conversationId;
189
191
 
192
+ const setMicMuted = React.useCallback((muted: boolean) => {
193
+ if (localParticipant) {
194
+ localParticipant.setMicrophoneEnabled(!muted);
195
+ }
196
+ }, [localParticipant]);
197
+
190
198
  // Update current event ID for feedback tracking
191
199
  const updateCurrentEventId = React.useCallback((eventId: number) => {
192
200
  currentEventIdRef.current = eventId;
@@ -202,10 +210,11 @@ export const ElevenLabsProvider: React.FC<ElevenLabsProviderProps> = ({ children
202
210
  overrides,
203
211
  customLlmExtraBody,
204
212
  dynamicVariables,
213
+ userId,
205
214
  });
206
215
  sendMessage(overridesEvent);
207
216
  }
208
- }, [handleParticipantReady, localParticipant, overrides, customLlmExtraBody, dynamicVariables, sendMessage]);
217
+ }, [handleParticipantReady, localParticipant, overrides, customLlmExtraBody, dynamicVariables, userId, sendMessage]);
209
218
 
210
219
  const conversation: Conversation = {
211
220
  startSession,
@@ -215,6 +224,7 @@ export const ElevenLabsProvider: React.FC<ElevenLabsProviderProps> = ({ children
215
224
  // setVolume,
216
225
  canSendFeedback,
217
226
  getId,
227
+ setMicMuted,
218
228
  sendFeedback,
219
229
  sendContextualUpdate: (text: string) => {
220
230
  sendMessage({
@@ -25,6 +25,7 @@ export const useConversationSession = (
25
25
  const [dynamicVariables, setDynamicVariables] = useState<
26
26
  ConversationConfig["dynamicVariables"]
27
27
  >({});
28
+ const [userId, setUserId] = useState<ConversationConfig["userId"]>(undefined);
28
29
 
29
30
  const startSession = useCallback(
30
31
  async (config: ConversationConfig) => {
@@ -35,6 +36,7 @@ export const useConversationSession = (
35
36
  setOverrides(config.overrides || {});
36
37
  setCustomLlmExtraBody(config.customLlmExtraBody || null);
37
38
  setDynamicVariables(config.dynamicVariables || {});
39
+ setUserId(config.userId);
38
40
 
39
41
  let conversationToken: string;
40
42
 
@@ -97,5 +99,6 @@ export const useConversationSession = (
97
99
  overrides,
98
100
  customLlmExtraBody,
99
101
  dynamicVariables,
102
+ userId,
100
103
  };
101
104
  };
package/src/types.ts CHANGED
@@ -134,6 +134,7 @@ export type AgentResponseCorrectionEvent = {
134
134
  corrected_agent_response: string;
135
135
  };
136
136
  };
137
+
137
138
  export type AgentAudioEvent = {
138
139
  type: "audio";
139
140
  audio_event: {
@@ -225,6 +226,13 @@ export type MCPToolApprovalResultEvent = {
225
226
  is_approved: boolean;
226
227
  };
227
228
 
229
+ export type VadScoreEvent = {
230
+ type: "vad_score";
231
+ vad_score_event: {
232
+ vad_score: number;
233
+ };
234
+ };
235
+
228
236
  export type InitiationClientDataEvent = {
229
237
  type: "conversation_initiation_client_data";
230
238
  conversation_config_override?: {
@@ -251,6 +259,49 @@ export type InitiationClientDataEvent = {
251
259
  user_id?: string;
252
260
  };
253
261
 
262
+ interface BaseMCPToolCallClientEventData {
263
+ service_id: string;
264
+ tool_call_id: string;
265
+ tool_name: string;
266
+ tool_description?: string;
267
+ parameters: Record<string, any>;
268
+ timestamp: string; // ISO string format
269
+ }
270
+
271
+ interface MCPToolCallClientEventLoadingData
272
+ extends BaseMCPToolCallClientEventData {
273
+ state: "loading";
274
+ }
275
+
276
+ interface MCPToolCallClientEventAwaitingApprovalData
277
+ extends BaseMCPToolCallClientEventData {
278
+ state: "awaiting_approval";
279
+ approval_timeout_secs: number;
280
+ }
281
+
282
+ interface MCPToolCallClientEventSuccessData
283
+ extends BaseMCPToolCallClientEventData {
284
+ state: "success";
285
+ result: any[];
286
+ }
287
+
288
+ interface MCPToolCallClientEventFailureData
289
+ extends BaseMCPToolCallClientEventData {
290
+ state: "failure";
291
+ error_message: string;
292
+ }
293
+
294
+ type MCPToolCallClientEventData =
295
+ | MCPToolCallClientEventLoadingData
296
+ | MCPToolCallClientEventAwaitingApprovalData
297
+ | MCPToolCallClientEventSuccessData
298
+ | MCPToolCallClientEventFailureData;
299
+
300
+ export type MCPToolCallClientEvent = {
301
+ type: "mcp_tool_call";
302
+ mcp_tool_call: MCPToolCallClientEventData;
303
+ };
304
+
254
305
  export type ConversationEvent =
255
306
  | UserTranscriptionEvent
256
307
  | AgentResponseEvent
@@ -260,4 +311,6 @@ export type ConversationEvent =
260
311
  | InternalTentativeAgentResponseEvent
261
312
  | ConfigEvent
262
313
  | PingEvent
263
- | ClientToolCallEvent;
314
+ | ClientToolCallEvent
315
+ | VadScoreEvent
316
+ | MCPToolCallClientEvent;
@@ -37,7 +37,7 @@ export function constructOverrides(
37
37
  }
38
38
 
39
39
  if (config.userId) {
40
- overridesEvent.user_id = config.userId;
40
+ overridesEvent.user_id = String(config.userId);
41
41
  }
42
42
 
43
43
  return overridesEvent;
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // This file is auto-generated during build
2
- export const PACKAGE_VERSION = "0.2.1";
2
+ export const PACKAGE_VERSION = "0.3.1";