diff --git a/packages/trace-viewer/src/ui/llm.tsx b/packages/trace-viewer/src/ui/llm.tsx index 216da2d55c..24f4d92b24 100644 --- a/packages/trace-viewer/src/ui/llm.tsx +++ b/packages/trace-viewer/src/ui/llm.tsx @@ -16,6 +16,7 @@ import * as React from 'react'; import { EventEmitter } from '@testIsomorphic/events'; +import { useCookies } from '@web/uiUtils'; export type LLMMessage = { role: 'user' | 'assistant' | 'developer'; @@ -198,22 +199,16 @@ class Conversation { const llmContext = React.createContext(undefined); -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 cookies = useCookies(); const chat = React.useMemo(() => { - for (const [name, value] of parseCookie(document.cookie)) { + for (const [name, value] of cookies) { if (name === 'openai_api_key') return new LLMChat(new OpenAI(value)); if (name === 'anthropic_api_key') return new LLMChat(new Anthropic(value)) } - }, []); + }, [cookies]); return {children}; }; diff --git a/packages/trace-viewer/src/ui/uiModeView.tsx b/packages/trace-viewer/src/ui/uiModeView.tsx index a9dfb8ff4b..441163c5d9 100644 --- a/packages/trace-viewer/src/ui/uiModeView.tsx +++ b/packages/trace-viewer/src/ui/uiModeView.tsx @@ -399,7 +399,7 @@ export const UIModeView: React.FC<{}> = ({ }); }, [closeInstallDialog, testServerConnection]); - return
+ return
{!hasBrowsers &&
Install browsers
diff --git a/packages/web/src/uiUtils.ts b/packages/web/src/uiUtils.ts index a0b7a59c36..57f32720cc 100644 --- a/packages/web/src/uiUtils.ts +++ b/packages/web/src/uiUtils.ts @@ -248,3 +248,10 @@ export function useFlash(): [boolean, EffectCallback] { }, [setFlash]); return [flash, trigger]; } + +export function useCookies() { + return document.cookie.split(";").filter(v => v.includes("=")).map(kv => { + const separator = kv.indexOf("="); + return [kv.substring(0, separator), kv.substring(separator + 1)]; + }) +}