@elevenlabs/react-native 0.1.1 → 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 +44 -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 +2 -0
- 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 +2 -0
- package/src/utils/tokenUtils.ts +5 -2
- package/src/version.ts +1 -1
|
@@ -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?: {
|
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";
|