@elevenlabs/react-native 0.1.0 → 0.1.2
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 +45 -0
- package/dist/ElevenLabsProvider.d.ts +1 -0
- package/dist/hooks/useConversationSession.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- 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 +7 -3
- package/dist/utils/tokenUtils.d.ts +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/ElevenLabsProvider.tsx +14 -2
- package/src/hooks/useConversationSession.ts +9 -3
- package/src/index.ts +1 -0
- package/src/types.ts +7 -3
- package/src/utils/overrides.ts +6 -2
- package/src/utils/tokenUtils.ts +5 -2
- package/src/version.ts +1 -1
|
@@ -13,6 +13,7 @@ import { LiveKitRoomWrapper } from './components/LiveKitRoomWrapper';
|
|
|
13
13
|
|
|
14
14
|
interface ConversationOptions extends Callbacks, Partial<ClientToolsConfig> {
|
|
15
15
|
serverUrl?: string;
|
|
16
|
+
tokenFetchUrl?: string;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
interface Conversation {
|
|
@@ -33,9 +34,11 @@ interface ElevenLabsContextType {
|
|
|
33
34
|
conversation: Conversation;
|
|
34
35
|
callbacksRef: { current: Callbacks };
|
|
35
36
|
serverUrl: string;
|
|
37
|
+
tokenFetchUrl?: string;
|
|
36
38
|
clientTools: ClientToolsConfig['clientTools'];
|
|
37
39
|
setCallbacks: (callbacks: Callbacks) => void;
|
|
38
40
|
setServerUrl: (url: string) => void;
|
|
41
|
+
setTokenFetchUrl: (url: string) => void;
|
|
39
42
|
setClientTools: (tools: ClientToolsConfig['clientTools']) => void;
|
|
40
43
|
}
|
|
41
44
|
|
|
@@ -47,7 +50,7 @@ export const useConversation = (options: ConversationOptions = {}): Conversation
|
|
|
47
50
|
throw new Error('useConversation must be used within ElevenLabsProvider');
|
|
48
51
|
}
|
|
49
52
|
|
|
50
|
-
const { serverUrl, clientTools, ...callbacks } = options;
|
|
53
|
+
const { serverUrl, tokenFetchUrl, clientTools, ...callbacks } = options;
|
|
51
54
|
|
|
52
55
|
React.useEffect(() => {
|
|
53
56
|
if (serverUrl) {
|
|
@@ -55,6 +58,12 @@ export const useConversation = (options: ConversationOptions = {}): Conversation
|
|
|
55
58
|
}
|
|
56
59
|
}, [context, serverUrl]);
|
|
57
60
|
|
|
61
|
+
React.useEffect(() => {
|
|
62
|
+
if (tokenFetchUrl) {
|
|
63
|
+
context.setTokenFetchUrl(tokenFetchUrl);
|
|
64
|
+
}
|
|
65
|
+
}, [context, tokenFetchUrl]);
|
|
66
|
+
|
|
58
67
|
if (clientTools) {
|
|
59
68
|
context.setClientTools(clientTools);
|
|
60
69
|
}
|
|
@@ -77,6 +86,7 @@ export const ElevenLabsProvider: React.FC<ElevenLabsProviderProps> = ({ children
|
|
|
77
86
|
const [connect, setConnect] = useState(false);
|
|
78
87
|
const [status, setStatus] = useState<ConversationStatus>('disconnected');
|
|
79
88
|
const [serverUrl, setServerUrl] = useState(DEFAULT_SERVER_URL);
|
|
89
|
+
const [tokenFetchUrl, setTokenFetchUrl] = useState<string | undefined>(undefined);
|
|
80
90
|
const [roomId, setRoomId] = useState<string>('');
|
|
81
91
|
const [isSpeaking, setIsSpeaking] = useState(false);
|
|
82
92
|
const [canSendFeedback, setCanSendFeedback] = useState(false);
|
|
@@ -109,7 +119,7 @@ export const ElevenLabsProvider: React.FC<ElevenLabsProviderProps> = ({ children
|
|
|
109
119
|
overrides,
|
|
110
120
|
customLlmExtraBody,
|
|
111
121
|
dynamicVariables,
|
|
112
|
-
} = useConversationSession(callbacksRef, setStatus, setConnect, setToken, setRoomId);
|
|
122
|
+
} = useConversationSession(callbacksRef, setStatus, setConnect, setToken, setRoomId, tokenFetchUrl);
|
|
113
123
|
|
|
114
124
|
const {
|
|
115
125
|
roomConnected,
|
|
@@ -230,9 +240,11 @@ export const ElevenLabsProvider: React.FC<ElevenLabsProviderProps> = ({ children
|
|
|
230
240
|
conversation,
|
|
231
241
|
callbacksRef,
|
|
232
242
|
serverUrl,
|
|
243
|
+
tokenFetchUrl,
|
|
233
244
|
clientTools: clientToolsRef.current,
|
|
234
245
|
setCallbacks,
|
|
235
246
|
setServerUrl,
|
|
247
|
+
setTokenFetchUrl: setTokenFetchUrl,
|
|
236
248
|
setClientTools,
|
|
237
249
|
};
|
|
238
250
|
|
|
@@ -14,7 +14,8 @@ export const useConversationSession = (
|
|
|
14
14
|
setStatus: (status: ConversationStatus) => void,
|
|
15
15
|
setConnect: (connect: boolean) => void,
|
|
16
16
|
setToken: (token: string) => void,
|
|
17
|
-
setRoomId: (roomId: string) => void
|
|
17
|
+
setRoomId: (roomId: string) => void,
|
|
18
|
+
tokenFetchUrl?: string
|
|
18
19
|
) => {
|
|
19
20
|
const [overrides, setOverrides] = useState<ConversationConfig["overrides"]>(
|
|
20
21
|
{}
|
|
@@ -44,7 +45,12 @@ export const useConversationSession = (
|
|
|
44
45
|
"Getting conversation token for agentId:",
|
|
45
46
|
config.agentId
|
|
46
47
|
);
|
|
47
|
-
|
|
48
|
+
// Use tokenFetchUrl from config first, then from hook parameter, then default
|
|
49
|
+
const urlToUse = config.tokenFetchUrl || tokenFetchUrl;
|
|
50
|
+
conversationToken = await getConversationToken(
|
|
51
|
+
config.agentId,
|
|
52
|
+
urlToUse
|
|
53
|
+
);
|
|
48
54
|
} else {
|
|
49
55
|
throw new Error("Either conversationToken or agentId is required");
|
|
50
56
|
}
|
|
@@ -62,7 +68,7 @@ export const useConversationSession = (
|
|
|
62
68
|
throw error;
|
|
63
69
|
}
|
|
64
70
|
},
|
|
65
|
-
[callbacksRef, setStatus, setConnect, setToken, setRoomId]
|
|
71
|
+
[callbacksRef, setStatus, setConnect, setToken, setRoomId, tokenFetchUrl]
|
|
66
72
|
);
|
|
67
73
|
|
|
68
74
|
const endSession = useCallback(async () => {
|
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -74,6 +74,7 @@ export type ClientToolsConfig = {
|
|
|
74
74
|
*/
|
|
75
75
|
export type ConversationOptions = {
|
|
76
76
|
serverUrl?: string;
|
|
77
|
+
tokenFetchUrl?: string;
|
|
77
78
|
clientTools?: Record<
|
|
78
79
|
string,
|
|
79
80
|
(
|
|
@@ -101,6 +102,7 @@ export type Callbacks = {
|
|
|
101
102
|
export type ConversationConfig = {
|
|
102
103
|
agentId?: string;
|
|
103
104
|
conversationToken?: string;
|
|
105
|
+
tokenFetchUrl?: string;
|
|
104
106
|
overrides?: {
|
|
105
107
|
agent?: {
|
|
106
108
|
prompt?: {
|
|
@@ -122,6 +124,7 @@ export type ConversationConfig = {
|
|
|
122
124
|
};
|
|
123
125
|
customLlmExtraBody?: unknown;
|
|
124
126
|
dynamicVariables?: Record<string, string | number | boolean>;
|
|
127
|
+
userId?: string;
|
|
125
128
|
};
|
|
126
129
|
|
|
127
130
|
export type InitiationClientDataEvent = {
|
|
@@ -140,11 +143,12 @@ export type InitiationClientDataEvent = {
|
|
|
140
143
|
conversation?: {
|
|
141
144
|
text_only?: boolean;
|
|
142
145
|
};
|
|
143
|
-
|
|
144
|
-
source?: string;
|
|
145
|
-
version?: string;
|
|
146
|
+
source_info?: {
|
|
147
|
+
source?: string | null;
|
|
148
|
+
version?: string | null;
|
|
146
149
|
};
|
|
147
150
|
};
|
|
148
151
|
custom_llm_extra_body?: unknown;
|
|
149
152
|
dynamic_variables?: Record<string, string | number | boolean>;
|
|
153
|
+
user_id?: string;
|
|
150
154
|
};
|
package/src/utils/overrides.ts
CHANGED
|
@@ -21,8 +21,8 @@ export function constructOverrides(
|
|
|
21
21
|
conversation: {
|
|
22
22
|
text_only: config.overrides.conversation?.textOnly,
|
|
23
23
|
},
|
|
24
|
-
|
|
25
|
-
source:
|
|
24
|
+
source_info: {
|
|
25
|
+
source: "react_native_sdk",
|
|
26
26
|
version: config.overrides?.client?.version || PACKAGE_VERSION,
|
|
27
27
|
},
|
|
28
28
|
};
|
|
@@ -36,5 +36,9 @@ export function constructOverrides(
|
|
|
36
36
|
overridesEvent.dynamic_variables = config.dynamicVariables;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
if (config.userId) {
|
|
40
|
+
overridesEvent.user_id = config.userId;
|
|
41
|
+
}
|
|
42
|
+
|
|
39
43
|
return overridesEvent;
|
|
40
44
|
}
|
package/src/utils/tokenUtils.ts
CHANGED
|
@@ -11,10 +11,13 @@ export const extractRoomIdFromToken = (token: string): string => {
|
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export const getConversationToken = async (
|
|
14
|
-
agentId: string
|
|
14
|
+
agentId: string,
|
|
15
|
+
tokenFetchUrl?: string
|
|
15
16
|
): Promise<string> => {
|
|
17
|
+
const baseUrl =
|
|
18
|
+
tokenFetchUrl || "https://api.elevenlabs.io/v1/convai/conversation/token";
|
|
16
19
|
const response = await fetch(
|
|
17
|
-
|
|
20
|
+
`${baseUrl}?agent_id=${agentId}&source=react_native_sdk&version=${PACKAGE_VERSION}`
|
|
18
21
|
);
|
|
19
22
|
|
|
20
23
|
const data = await response.json();
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is auto-generated during build
|
|
2
|
-
export const PACKAGE_VERSION = "0.1.
|
|
2
|
+
export const PACKAGE_VERSION = "0.1.2";
|