From bc45731c6b1202c9b283d96f42746cf166afc73f Mon Sep 17 00:00:00 2001 From: Rolf Morgenstern Date: Wed, 4 Nov 2026 14:32:19 +0100 Subject: [PATCH] fix: support OpenCode 2.x web app and API OpenCode 2 replaced the per-project URL scheme and added authentication, which made the panel fail with "Cannot read properties of undefined (reading 'type')" (#74). - Server: pass OPENCODE_SERVER_PASSWORD and authenticate /api/* with HTTP Basic; probe /api/info instead of the removed /global/health. - URLs: open sessions at /server//session/ instead of /, which is no longer a route. - Embed: use an Electron and seed the server credential into the web app's localStorage (server pairings are client-side; the pairing-link cookie is SameSite=Lax and never sent from an iframe). - API: talk to the server through node:http; renderer fetch is CORS-blocked because OpenCode sends no allow-origin header for app://obsidian.md. - Client: /api/location, /api/session with location.directory and /api/session//synthetic for context injection. Closes #74 --- README.md | 21 ++++ src/client/OpenCodeClient.ts | 225 +++++++++++++++-------------------- src/lib/http.ts | 68 +++++++++++ src/lib/serverUrl.ts | 57 +++++++++ src/main.ts | 7 ++ src/server/ServerManager.ts | 99 +++++++++++---- src/ui/OpenCodeView.ts | 212 ++++++++++++++++++++++++++++----- src/ui/embed.ts | 115 ++++++++++++++++++ styles.css | 19 +++ tests/ServerManager.test.ts | 60 +++++----- tests/serverUrl.test.ts | 43 +++++++ 11 files changed, 712 insertions(+), 214 deletions(-) create mode 100644 src/lib/http.ts create mode 100644 src/lib/serverUrl.ts create mode 100644 src/ui/embed.ts create mode 100644 tests/serverUrl.test.ts diff --git a/README.md b/README.md index 7b0c8a8..788423e 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,27 @@ If you want to contribute or develop the plugin: - Server starts automatically when you open the panel +## How it works (OpenCode 2.x) + +OpenCode 2 changed both the shape of its web app and its HTTP API. The plugin now: + +- hands the server a password via `OPENCODE_SERVER_PASSWORD` and authenticates + every API call with HTTP Basic (`opencode:`), because 2.x requires + authentication for `/api/*`; +- opens the app at `/server//session/`, where + `` is the base64url encoding of the server URL - the old + `/` path is no longer a valid route (it made the app throw + `Unrecognised route!` / `Cannot read properties of undefined (reading 'type')`); +- creates the session for the vault, so file tree, `@`-mentions, terminal and git + are scoped to it; +- embeds the app in an Electron `` instead of an `