Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensures searchParams.get doesn't throw errors and defaults to the cor… #5

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added Dockerfile
Empty file.
51 changes: 40 additions & 11 deletions src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { createRealtimeConnection } from "./lib/realtimeConnection";
// Agent configs
import { allAgentSets, defaultAgentSetKey } from "@/app/agentConfigs";


function App() {
const searchParams = useSearchParams();

Expand Down Expand Up @@ -74,6 +75,7 @@ function App() {
sendClientEvent,
setSelectedAgentName,
});


useEffect(() => {
let finalAgentConfig = searchParams.get("agentConfig");
Expand Down Expand Up @@ -125,20 +127,47 @@ function App() {
}, [isPTTActive]);

const fetchEphemeralKey = async (): Promise<string | null> => {
logClientEvent({ url: "/session" }, "fetch_session_token_request");
const tokenResponse = await fetch("/api/session");
const data = await tokenResponse.json();
logServerEvent(data, "fetch_session_token_response");

if (!data.client_secret?.value) {
logClientEvent(data, "error.no_ephemeral_key");
console.error("No ephemeral key provided by the server");
setSessionStatus("DISCONNECTED");
if (!process.env.OPENAI_API_KEY) {
console.error("Missing OPENAI_API_KEY environment variable.");
return null;
}

try {
logClientEvent({ url: "/session" }, "fetch_session_token_request");
const tokenResponse = await fetch("/api/session");
const data = await tokenResponse.json();
logServerEvent(data, "fetch_session_token_response");

if (!data.client_secret?.value) {
logClientEvent(data, "error.no_ephemeral_key");
console.error("No ephemeral key provided by the server");
setSessionStatus("DISCONNECTED");
return null;
}

return data.client_secret.value;
} catch (err) {
console.error("Failed to fetch ephemeral key:", err);
return null;
}

return data.client_secret.value;
};


// const fetchEphemeralKey = async (): Promise<string | null> => {
// logClientEvent({ url: "/session" }, "fetch_session_token_request");
// const tokenResponse = await fetch("/api/session");
// const data = await tokenResponse.json();
// logServerEvent(data, "fetch_session_token_response");

// if (!data.client_secret?.value) {
// logClientEvent(data, "error.no_ephemeral_key");
// console.error("No ephemeral key provided by the server");
// setSessionStatus("DISCONNECTED");
// return null;
// }

// return data.client_secret.value;
// };

const connectToRealtime = async () => {
if (sessionStatus !== "DISCONNECTED") return;
Expand Down