Spaces:
Running
Running
Update src/contexts/LiveAPIContext.tsx
Browse files
src/contexts/LiveAPIContext.tsx
CHANGED
|
@@ -16,13 +16,7 @@
|
|
| 16 |
|
| 17 |
import { createContext, FC, type ReactNode, useContext } from "react";
|
| 18 |
import { useLiveAPI, type UseLiveAPIResults } from "../hooks/use-live-api";
|
| 19 |
-
|
| 20 |
-
export type LiveConfig = {
|
| 21 |
-
model?: string;
|
| 22 |
-
systemInstruction?: {
|
| 23 |
-
parts: Array<{ text: string }>;
|
| 24 |
-
};
|
| 25 |
-
};
|
| 26 |
|
| 27 |
const LiveAPIContext = createContext<UseLiveAPIResults | undefined>(undefined);
|
| 28 |
|
|
@@ -30,6 +24,7 @@ export type LiveAPIProviderProps = {
|
|
| 30 |
children: ReactNode;
|
| 31 |
url?: string;
|
| 32 |
initialConfig?: LiveConfig;
|
|
|
|
| 33 |
};
|
| 34 |
|
| 35 |
export const LiveAPIProvider: FC<LiveAPIProviderProps> = ({
|
|
@@ -37,9 +32,10 @@ export const LiveAPIProvider: FC<LiveAPIProviderProps> = ({
|
|
| 37 |
? `${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//localhost:3001/ws`
|
| 38 |
: `${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${window.location.host}/ws`,
|
| 39 |
initialConfig,
|
|
|
|
| 40 |
children,
|
| 41 |
}) => {
|
| 42 |
-
const liveAPI = useLiveAPI({ url, initialConfig });
|
| 43 |
|
| 44 |
return (
|
| 45 |
<LiveAPIContext.Provider value={liveAPI}>
|
|
@@ -49,11 +45,9 @@ export const LiveAPIProvider: FC<LiveAPIProviderProps> = ({
|
|
| 49 |
};
|
| 50 |
|
| 51 |
export const useLiveAPIContext = () => {
|
| 52 |
-
console.log('🎯 LiveAPIContext: Hook being accessed');
|
| 53 |
const context = useContext(LiveAPIContext);
|
| 54 |
if (!context) {
|
| 55 |
throw new Error("useLiveAPIContext must be used within a LiveAPIProvider");
|
| 56 |
}
|
| 57 |
-
console.log('✅ LiveAPIContext successfully retrieved');
|
| 58 |
return context;
|
| 59 |
};
|
|
|
|
| 16 |
|
| 17 |
import { createContext, FC, type ReactNode, useContext } from "react";
|
| 18 |
import { useLiveAPI, type UseLiveAPIResults } from "../hooks/use-live-api";
|
| 19 |
+
import { LiveConfig } from "../multimodal-live-types";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
const LiveAPIContext = createContext<UseLiveAPIResults | undefined>(undefined);
|
| 22 |
|
|
|
|
| 24 |
children: ReactNode;
|
| 25 |
url?: string;
|
| 26 |
initialConfig?: LiveConfig;
|
| 27 |
+
apiKey?: string;
|
| 28 |
};
|
| 29 |
|
| 30 |
export const LiveAPIProvider: FC<LiveAPIProviderProps> = ({
|
|
|
|
| 32 |
? `${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//localhost:3001/ws`
|
| 33 |
: `${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${window.location.host}/ws`,
|
| 34 |
initialConfig,
|
| 35 |
+
apiKey,
|
| 36 |
children,
|
| 37 |
}) => {
|
| 38 |
+
const liveAPI = useLiveAPI({ url, apiKey, initialConfig });
|
| 39 |
|
| 40 |
return (
|
| 41 |
<LiveAPIContext.Provider value={liveAPI}>
|
|
|
|
| 45 |
};
|
| 46 |
|
| 47 |
export const useLiveAPIContext = () => {
|
|
|
|
| 48 |
const context = useContext(LiveAPIContext);
|
| 49 |
if (!context) {
|
| 50 |
throw new Error("useLiveAPIContext must be used within a LiveAPIProvider");
|
| 51 |
}
|
|
|
|
| 52 |
return context;
|
| 53 |
};
|