The inline prompt now shows the current session's full message
history (user + assistant), scrollable, replacing the single-output
display from the previous commit. The user can scroll back through
prior exchanges in the same notebook's OpenCode session.
Server (opencode_bridge/):
- New route: GET /opencode-bridge/session-messages?notebook=<path>
- Resolves notebook to session via SessionManager.peek (no create).
- If no session: {"messages": []} (no OpenCode call).
- Else: GET /session/{id}/message on OpenCode Serve, project the
raw {info, parts}[] into a frontend-friendly {role, content}[].
- OpenCodeClient.list_session_messages(sid).
- SessionManager.peek(notebook_path) -> Optional[str] (read without
creating, to avoid spawning a session just to report emptiness).
- Wired the new route in setup_route_handlers.
Client (src/):
- types.ts: OpenCodeMessage { role, content } + OpenCodeMessagesResponse.
- api/opencode_client.ts: callOpenCodeSessionMessages(notebook, serverSettings).
- components/opencode_inline_prompt.ts:
- Replaces the single .opencode-inline-output area with a
scrollable .opencode-inline-history (max-height 320px, overflow-y
auto, auto-scrolls to bottom on update).
- setMessages(messages): renders user messages as plain text,
assistant messages via marked.parse. No more setOutput/hideOutput.
- components/opencode_cell_actions.ts:
- _showPrompt now fires a _refreshHistory(notebookPath) which
fetches and calls prompt.setMessages.
- _handleResponse on success also calls _refreshHistory (the new
assistant message appears as the last item in the history).
- Cell source is still NOT replaced.
- api/opencode_client module is mocked in the cell_actions test to
avoid jsdom network calls.
style/base.css:
- .opencode-inline-output* rules replaced with .opencode-inline-history
(max-height 320px, overflow-y auto, border, padding) and
.opencode-msg / .opencode-msg-user / .opencode-msg-assistant.
- pre/code/p/h1-3 content styling scoped under .opencode-inline-history.
Tests:
- pytest 37/37: FakeOpenCodeClient.list_session_messages + 3 new
session_messages route tests (no session, projects messages, 400).
- jest 29/29: setMessages renders user/assistant + history area tests.
- FakeSessionManager.peek (returns None when session_id is falsy).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
83 lines
2.1 KiB
TypeScript
83 lines
2.1 KiB
TypeScript
/**
|
|
* Shared types for the opencode-bridge frontend.
|
|
*
|
|
* These mirror the Python server's `CellContext` / `OpenCodeRequest` / `OpenCodeResponse`
|
|
* shapes in `opencode_bridge/routes.py`. Keep them in sync.
|
|
*
|
|
* v3-final: the JupyterLab plugin settings have been removed entirely.
|
|
* All connection config lives in startup environment variables (see
|
|
* `opencode_bridge/config.py`); the inline model picker is fully dynamic.
|
|
*/
|
|
|
|
export interface ErrorOutput {
|
|
ename: string;
|
|
evalue: string;
|
|
traceback: string[];
|
|
}
|
|
|
|
export interface CellContext {
|
|
notebookPath: string;
|
|
cellId: string;
|
|
language: string;
|
|
cellIndex: number;
|
|
totalCells: number;
|
|
source: string;
|
|
previousCode: string | null;
|
|
error: ErrorOutput | null;
|
|
}
|
|
|
|
export interface OpenCodeRequest {
|
|
prompt: string;
|
|
context: CellContext;
|
|
providerId?: string;
|
|
modelId?: string;
|
|
}
|
|
|
|
export interface OpenCodeSuccess {
|
|
ok: true;
|
|
/** The AI's reply as markdown (code in ```fences```, optional explanation).
|
|
* Render with marked. The cell source is NOT replaced. */
|
|
markdown: string;
|
|
sessionId: string;
|
|
notebookPath: string;
|
|
}
|
|
|
|
export interface OpenCodeFailure {
|
|
ok: false;
|
|
error: string;
|
|
}
|
|
|
|
export type OpenCodeResponse = OpenCodeSuccess | OpenCodeFailure;
|
|
|
|
/** Response from GET /opencode-bridge/session-messages?notebook=... .
|
|
* Projected from OpenCode's {info, parts}[] by the server into a
|
|
* frontend-friendly {role, content}[]. */
|
|
export interface OpenCodeMessage {
|
|
role: "user" | "assistant";
|
|
content: string;
|
|
}
|
|
|
|
export interface OpenCodeMessagesResponse {
|
|
messages: OpenCodeMessage[];
|
|
}
|
|
|
|
/** 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 {
|
|
id: string;
|
|
name?: string;
|
|
[k: string]: unknown;
|
|
}
|
|
|
|
export interface OpenCodeProvider {
|
|
id: string;
|
|
name?: string;
|
|
source?: string;
|
|
models: { [modelID: string]: OpenCodeModel };
|
|
}
|
|
|
|
export interface OpenCodeProvidersResponse {
|
|
providers: OpenCodeProvider[];
|
|
default?: { [providerID: string]: string };
|
|
}
|