Skip to content

Improve AI session handling - #441

Open
freekh wants to merge 1 commit into
mainfrom
improve-ai-chat-session-handling
Open

Improve AI session handling#441
freekh wants to merge 1 commit into
mainfrom
improve-ai-chat-session-handling

Conversation

@freekh

@freekh freekh commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@changeset-bot

changeset-bot Bot commented Jun 5, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 30472b8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 94 to 101
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 (
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants