move into cookies
This commit is contained in:
parent
47086720c6
commit
9bc2c28847
|
|
@ -131,10 +131,6 @@ export async function installRootRedirect(server: HttpServer, traceUrls: string[
|
|||
params.append('project', project);
|
||||
for (const reporter of options.reporter || [])
|
||||
params.append('reporter', reporter);
|
||||
if (process.env.OPENAI_API_KEY)
|
||||
params.append('openai_api_key', process.env.OPENAI_API_KEY);
|
||||
if (process.env.ANTHROPIC_API_KEY)
|
||||
params.append('anthropic_api_key', process.env.ANTHROPIC_API_KEY);
|
||||
|
||||
let baseUrl = '.';
|
||||
if (process.env.PW_HMR) {
|
||||
|
|
@ -146,6 +142,13 @@ export async function installRootRedirect(server: HttpServer, traceUrls: string[
|
|||
server.routePath('/', (_, response) => {
|
||||
response.statusCode = 302;
|
||||
response.setHeader('Location', urlPath);
|
||||
|
||||
if (process.env.OPENAI_API_KEY)
|
||||
response.setHeader('Set-Cookie', `openai_api_key=${process.env.OPENAI_API_KEY}`);
|
||||
|
||||
if (process.env.ANTHROPIC_API_KEY)
|
||||
response.setHeader('Set-Cookie', `anthropic_api_key=${process.env.ANTHROPIC_API_KEY}`);
|
||||
|
||||
response.end();
|
||||
return true;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -198,16 +198,22 @@ class Conversation {
|
|||
|
||||
const llmContext = React.createContext<LLMChat | undefined>(undefined);
|
||||
|
||||
export function LLMProvider({ openai, anthropic, children }: React.PropsWithChildren<{ openai?: string, anthropic?: string }>) {
|
||||
const chat = React.useMemo(() => {
|
||||
let llm: LLM | undefined;
|
||||
if (openai)
|
||||
llm = new OpenAI(openai);
|
||||
if (anthropic)
|
||||
llm = new Anthropic(anthropic);
|
||||
if (llm)
|
||||
return new LLMChat(llm);
|
||||
}, [openai, anthropic]);
|
||||
function parseCookie(cookie: string): [name: string, value: string][] {
|
||||
return cookie.split(";").filter(v => v.includes("=")).map(kv => {
|
||||
const separator = kv.indexOf("=");
|
||||
return [kv.substring(0, separator), kv.substring(separator + 1)];
|
||||
})
|
||||
}
|
||||
|
||||
export function LLMProvider({ children }: React.PropsWithChildren<{}>) {
|
||||
const chat = React.useMemo(() => {
|
||||
for (const [name, value] of parseCookie(document.cookie)) {
|
||||
if (name === 'openai_api_key')
|
||||
return new LLMChat(new OpenAI(value));
|
||||
if (name === 'anthropic_api_key')
|
||||
return new LLMChat(new Anthropic(value))
|
||||
}
|
||||
}, []);
|
||||
return <llmContext.Provider value={chat}>{children}</llmContext.Provider>;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -62,8 +62,6 @@ const queryParams = {
|
|||
updateSnapshots: (searchParams.get('updateSnapshots') as 'all' | 'none' | 'missing' | undefined) || undefined,
|
||||
reporters: searchParams.has('reporter') ? searchParams.getAll('reporter') : undefined,
|
||||
pathSeparator: searchParams.get('pathSeparator') || '/',
|
||||
openai_api_key: searchParams.get('openai_api_key') || undefined,
|
||||
anthropic_api_key: searchParams.get('anthropic_api_key') || undefined,
|
||||
};
|
||||
if (queryParams.updateSnapshots && !['all', 'none', 'missing'].includes(queryParams.updateSnapshots))
|
||||
queryParams.updateSnapshots = undefined;
|
||||
|
|
|
|||
Loading…
Reference in a new issue