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