Improve AI session handling - #441
Conversation
|
There was a problem hiding this comment.
Pull request overview
This PR refactors AI chat session lifecycle handling so sessions are “unborn” until the user actually uses the chat, and it adds URL/sessionStorage plumbing so sessions can be preserved across navigation and between overlay ↔ studio.
Changes:
- Introduces an “unborn → born” session model in
useAI, with callbacks to sync session state to URL/sessionStorage and support loading an initial session id. - Preserves
?session=across in-studio navigations and adds a router API (useSessionParam) to read/update it. - Adds overlay session propagation via
sessionStorage, plus a loading UI state while fetching historical messages.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
packages/ui/spa/hooks/useAI.ts |
Adds options/callbacks for initial session loading and “born/cleared” transitions; implements lazy session id minting; adds isLoadingSession. |
packages/ui/spa/components/ValRouter.tsx |
Adds sessionParam tracking and mutation helpers; preserves ?session= during navigation and uses sessionStorage fallback in overlay. |
packages/ui/spa/components/ValOverlay.tsx |
Introduces overlay session context and sessionStorage mirroring; appends ?session= to studio links; wires useAI callbacks. |
packages/ui/spa/components/ToolsMenu.tsx |
Wires useAI options to URL/sessionStorage, and passes isLoadingSession into the chat UI. |
packages/ui/spa/components/AIChat.tsx |
Updates session id type to allow null (unborn) and shows a loading state while a session is being fetched. |
packages/shared/src/internal/sessionStorage.ts |
Adds VAL_AI_SESSION_STORAGE_KEY constant for cross-surface session persistence. |
| const [isErrorsView, setIsErrorsView] = useState(false); | ||
| const [errorFields, setErrorFields] = useState<SourcePath[]>([]); | ||
| const [sessionParam, setSessionParamState] = useState<string | null>(null); | ||
| const historyState = useRef<number[]>([]); | ||
| useEffect(() => { | ||
| const listener = () => { | ||
| setSessionParamState(new URLSearchParams(location.search).get("session")); | ||
| if ( |
No description provided.