feat: multi-session management (browse all + bind N sessions per notebook)
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>
This commit is contained in:
@@ -82,6 +82,54 @@ export interface OpenCodeMessagesResponse {
|
||||
messages: OpenCodeMessage[];
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Multi-session management types (1 notebook can bind N sessions, one active)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/** One session on the OpenCode Serve side (returned by GET /session). */
|
||||
export interface OpenCodeSessionMeta {
|
||||
id: string;
|
||||
title?: string;
|
||||
createdAt?: number;
|
||||
updatedAt?: number;
|
||||
[k: string]: unknown;
|
||||
}
|
||||
|
||||
/** Response from GET /opencode-bridge/sessions/all. */
|
||||
export interface OpenCodeAllSessionsResponse {
|
||||
ok: boolean;
|
||||
sessions: OpenCodeSessionMeta[];
|
||||
error?: string;
|
||||
}
|
||||
|
||||
/** One session bound to a notebook (returned by GET /sessions/notebook). */
|
||||
export interface OpenCodeNotebookSession {
|
||||
sessionId: string;
|
||||
title?: string;
|
||||
createdAt?: number;
|
||||
updatedAt?: number;
|
||||
isActive: boolean;
|
||||
}
|
||||
|
||||
/** Response from GET /opencode-bridge/sessions/notebook?notebook=... */
|
||||
export interface OpenCodeNotebookSessionsResponse {
|
||||
ok: boolean;
|
||||
notebookPath: string;
|
||||
activeSessionId: string | null;
|
||||
sessions: OpenCodeNotebookSession[];
|
||||
error?: string;
|
||||
}
|
||||
|
||||
/** Response from POST/PUT /sessions/notebook and PUT /sessions/active. */
|
||||
export interface OpenCodeSessionOpResponse {
|
||||
ok: boolean;
|
||||
notebookPath: string;
|
||||
sessionId?: string;
|
||||
activeSessionId?: string | null;
|
||||
deleted?: boolean;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
/** Response from GET /opencode-bridge/providers (proxies OpenCode /config/providers).
|
||||
* Each Provider.models is a Record keyed by modelID (NOT an array). */
|
||||
export interface OpenCodeModel {
|
||||
|
||||
Reference in New Issue
Block a user