User can now see EVERY session on the OpenCode Serve side (not just
the per-notebook mapping) and bind multiple sessions to a single
notebook. One of the bound sessions is the "active" one (the one
the next /edit uses); the others are historical. The user can
switch, create, or delete via the new session selector UI in the
inline prompt.
Backend
-------
- SessionManager rewritten for 1-notebook-N-sessions: keeps both an
map and a map. New methods: create_new,
bind_existing, set_active, unbind, unbind_active, delete_session,
list_sessions_for_notebook. Existing get_or_create / peek /
invalidate / list_sessions / release semantics preserved
(release now deletes ALL bound sessions, not just the active).
- New route GET /opencode-bridge/sessions/all — list ALL OpenCode
sessions via /session.
- New route GET /opencode-bridge/sessions/notebook?notebook=... —
bound sessions for one notebook, enriched with title/createdAt
from the global list.
- POST .../sessions/notebook — create a new session, bind, set
active.
- PUT .../sessions/notebook — bind an existing sessionId, set
active (no OpenCode round-trip).
- DELETE .../sessions/notebook — delete the session on OpenCode
AND remove its binding.
- New route GET/PUT/DELETE /opencode-bridge/sessions/active —
read / switch / unbind the active session for one notebook.
- OpenCodeClient.list_all_sessions() — proxy OpenCode /session.
Frontend
-------
- SessionSelector dropdown in the inline prompt: lists ALL OpenCode
sessions with the active one selected, plus a "+ 新建会话"
sentinel entry. "+ 新建" button + "🔄" refresh button.
Switching calls onSwitchSession; selecting "+ 新建会话" or
clicking the new button calls onCreateSession. After both,
the prompt's history is reloaded for the new active session.
- New cell-action callbacks: onListSessions, onCreateSession,
onSwitchSession, onReloadHistory. Each closes the SSE first
so events for the OLD session don't bleed in during the switch.
- 8 new API client functions in api/opencode_client.ts.
- New types in types.ts: OpenCodeSessionMeta,
OpenCodeNotebookSession, OpenCodeAllSessionsResponse,
OpenCodeNotebookSessionsResponse, OpenCodeSessionOpResponse.
Tests
-----
- 73 backend pytest (was 64): +6 new SessionManager multi-session
unit tests + 7 new route tests (all-sessions, notebook GET/POST/
PUT/DELETE, active GET/PUT/DELETE).
- 76 frontend jest (was 72): +4 new prompt tests (session selector
rendered when callbacks wired, initialize() populates the list,
+ 新建 creates+binds, dropdown change switches and reloads).
- package.json version bumped 0.1.0 -> 0.1.1 to match the v0.1.1 tag
that was already published.
Co-Authored-By: Claude <noreply@anthropic.com>