@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/README.md +12 -0
- package/dist/ElevenLabsProvider.d.ts +1 -0
- package/dist/components/LiveKitRoomWrapper.d.ts +1 -1
- package/dist/hooks/useConversationCallbacks.d.ts +1 -1
- package/dist/hooks/useConversationSession.d.ts +1 -0
- package/dist/lib.js +1 -1
- package/dist/lib.js.map +1 -1
- package/dist/lib.modern.js +1 -1
- package/dist/lib.modern.js.map +1 -1
- package/dist/lib.module.js +1 -1
- package/dist/lib.module.js.map +1 -1
- package/dist/lib.umd.js +1 -1
- package/dist/lib.umd.js.map +1 -1
- package/dist/types.d.ts +36 -1
- package/dist/version.d.ts +1 -1
- package/jest.config.cjs +1 -1
- package/package.json +5 -5
- package/src/ElevenLabsProvider.tsx +11 -1
- package/src/hooks/useConversationSession.ts +3 -0
- package/src/types.ts +54 -1
- package/src/utils/overrides.ts +1 -1
- package/src/version.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elevenlabs/react-native",
|
|
3
|
-
"version": "0.
|
|
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": "
|
|
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": "
|
|
58
|
-
"lint": "
|
|
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": "
|
|
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;
|
package/src/utils/overrides.ts
CHANGED
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
|
+
export const PACKAGE_VERSION = "0.3.1";
|