fix(web): allow creating new sessions in projects from the web UI - #83
fix(web): allow creating new sessions in projects from the web UI#83justemu wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Thanks for addressing the visible error, but this does not yet create the session in the selected project: the web path is only stored in draftWorkspaces, while first-send still sets chosen only when isTauri, the existing OpenCodeClient remains scoped to /v1/whoami, and this patch skips the reconnect, so the session can silently land in the host's active workspace. Please carry the selected directory as client-local web state, use it consistently for session creation, SSE, permissions/questions, and files, and add a regression test asserting the created session's directory equals the selected project path; also note that the UI creates through /session?directory=PATH, not /v1/sessions.
…creation Address review feedback on ai4s-research#83: - Add webOverrideDirectory module-level variable to carry the user-selected project directory in web mode, persisted across reconnects - In switchWorkspace for web mode: set webOverrideDirectory and call connectRetry() so the OpenCodeClient picks up the new directory - In connect() for web mode: use webOverrideDirectory to override the /v1/whoami default, falling back to whoami only when no override is set - In first-send block: read chosen from draftWorkspaces for both Tauri and web mode; when web mode has a chosen directory, scope the client to it before creating the session - The session is created via /session?directory=PATH (not /v1/sessions), so the directory flows through dirQuery() on the OpenCodeClient - Add regression tests: session creation with and without directory parameter
The web UI (Remote Access Gateway mode) threw 'not running in the desktop app' when clicking 'New Session' under a project. This happened because switchWorkspace() called setWorkspace() — a Tauri-only command — without a gateway fallback. Fix: when isGatewayWeb is true, skip the Tauri-only setWorkspace/ newDatedWorkspace calls and just aim the draft at the target path directly. The gateway already routes session creation to the host's active workspace via /v1/sessions. Closes ai4s-research#81.
…creation Address review feedback on ai4s-research#83: - Add webOverrideDirectory module-level variable to carry the user-selected project directory in web mode, persisted across reconnects - In switchWorkspace for web mode: set webOverrideDirectory and call connectRetry() so the OpenCodeClient picks up the new directory - In connect() for web mode: use webOverrideDirectory to override the /v1/whoami default, falling back to whoami only when no override is set - In first-send block: read chosen from draftWorkspaces for both Tauri and web mode; when web mode has a chosen directory, scope the client to it before creating the session - The session is created via /session?directory=PATH (not /v1/sessions), so the directory flows through dirQuery() on the OpenCodeClient - Add regression tests: session creation with and without directory parameter
20b72c1 to
3737476
Compare
|
Hi @noahbenjamin1994, thanks for the detailed review! We've addressed all your feedback in the follow-up commit (20b72c1) and rebased onto the latest master to resolve merge conflicts. Here's what the fix commit covers:
First-send block — Reads Session creation — Uses Regression tests — 2 new tests: The branch has been rebased onto the latest master (was 47 commits behind) to resolve merge conflicts with recent changes to |
Summary
Fixes the "not running in the desktop app" error when creating a new session under a project from the web UI (Remote Access Gateway mode), and ensures the created session actually lands in the selected project directory.
Closes #81.
Problem
Two distinct issues when the web UI (browser) tries to create a session under a user-selected project:
1. Tauri-only call crashes in browser
The
newSessionIn()function inSidebar.tsxcallsswitchWorkspace(), which callssetWorkspace()— a Tauri-only command that throws whenwindow.__TAURI_INTERNALS__is absent (i.e., in a browser).2. Session silently lands in the wrong directory
Even after fixing the crash, three independent information paths are broken in web mode, so the session creation request never carries the selected directory:
Break point A — first-send ignores draftWorkspaces in web mode.
runtime.tsline 810:isTauriisfalsein the browser, sochosenis alwaysundefined. The user selected a project,switchWorkspacestored the path indraftWorkspaces, but the first-send logic never reads it.Break point B — OpenCodeClient is scoped to /v1/whoami, not the selected project.
connect()lines 1459–1480:/v1/whoamireturns the desktop host's currently active workspace — not the project the user clicked in the web UI. TheOpenCodeClientis constructed with this directory, and all subsequent API calls (createSession, SSE, permissions, files) route through?directory=using it.Break point C — switchWorkspace stores the path but does not reconnect.
The original PR patch stored the path in
draftWorkspacesbut skippedconnectRetry(). TheOpenCodeClientinstance kept its originaldirectoryfrom the initialconnect()call, so the stored path was never used.Fix
Introduce
webOverrideDirectory— a module-level variable that carries the user-selected project directory in web mode and persists across reconnects.switchWorkspace (web mode)
Set
webOverrideDirectory = target.path, then callconnectRetry()so theOpenCodeClientis reconstructed with the correct directory.connect() (web mode)
Initialize
directory = webOverrideDirectory. Only fall back to the/v1/whoamiresponse when no override is set:first-send block
Read
chosenfromdraftWorkspacesfor both Tauri and web mode (no longer gated onisTauri). When web mode has achosendirectory, setwebOverrideDirectoryandconnectRetry()before creating the session. ThecreateSession()call usesdirQuery()→?directory=PATH, so the session is created in the correct project.Why this works end-to-end
OpenCodeClient.createSession()sendsPOST /session?directory=PATH. Thedirectoryfield is set at construction time and used bydirQuery()for all directory-scoped calls: session creation, SSE event stream, permissions/questions, and file operations. By overriding it atconnect()time, all downstream operations automatically scope to the selected project.Testing
createSessionwith a directory sends?directory=in the URLcreateSessionwithout a directory sends no query parameterFiles changed
apps/desktop/src/lib/runtime.ts—webOverrideDirectory,switchWorkspace,connect(), first-send logicapps/desktop/src/test/opencode-client.sessions.test.ts— 2 regression tests