Repository navigation
Support opencode 2.x servers alongside 1.x (per-connection API detection) - #51
Merged
Merged
Conversation
…dapter
Adds GET /api/info-based server detection (JSON {version:2.x} = v2, HTML = 1.x)
cached per server and re-probed on SSE reconnect, plus src/lib/sdk-v2.ts which
maps the 2.x API onto the existing Client surface: /api/* routes, {data}
envelopes, location[directory] scoping, paginated newest-first message lists,
session/revert/interrupt, permission and form (question) round trips, and the
granular session.* event stream accumulated back into message.part.updated
parts. Screens and stores are unchanged.
…mples
Adds tests/fixtures/mock-opencode-server-v2.ts (a 2.x-protocol stub behind
--v2: /api/* + {data} + location[directory] + desc/cursor paging + granular
session.* events, plus scripted permission/form asks) and sdk-v2.test.ts:
message mapping straight from sample-messages.json, event mapping replaying
sample-events.sse, part-id agreement between streaming and refetch, detection
against JSON/HTML/404 servers, and full permission and question round trips.
Also records real 2.0.29 permission and form events under
docs/opencode-v2-port/sample-{permission,form}-events.sse.
scripts/v2-live-{detect,check,permission,question,interrupt}.ts drive the
adapter against a real 2.0.29 server (both majors for the probe), covering
detection, session list/create, paging, streaming deltas, tool parts, the
permission and question round trips, and interrupt.
…without order+cursor Editing a sent message left the transcript frozen on a 2.x server: the app hides everything after the pending revert point, but 2.x commits that revert itself when the re-sent prompt lands and never tells the app over an API call — only in the stream (session.revert.staged/committed/cleared). Mapping those onto a session.revert event clears the banner and lifts the filter, and the commit's first dropped id prunes the pre-edit exchange the server removed. Also fixes GET /message paging: a 2.x cursor must not be combined with order (InvalidCursorError), which made any transcript that spanned more than one page fail to load.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Lets the app talk to opencode 2.x servers as well as 1.x, transparently. Each connection probes
GET /api/infoand routes every call to whichever implementation answered, so the 1.x path is unchanged and no screen or store needs to know about versions.How it works
src/lib/server-version.ts):/api/infoanswered as JSON with a2.xversion → 2.x; anything else → 1.x. Decided by content type, never status code — both majors serve their web app with 200 for routes they don't implement. A workspace that is only waking gets no cached verdict, and the SSE reconnect re-probes so an in-place server upgrade is picked up without restarting.src/lib/sdk-v2.ts): maps/api/*,{data}envelopes,location[directory]scoping, cursor-paginated newest-first transcripts and the granularsession.*event stream onto the 1.x shapes the stores already consume. Tool names are renamed (shell→bash,subagent→task,patch→apply_patch) and part IDs agree between the stream and aGET, so a refresh never duplicates a part.Found while building it
GET /messagepaging combinedorderwithcursor, which 2.x rejects — any transcript spanning more than one page failed to load./global/healthwith 200 + HTML, so200 OKis not evidence of a working API; diagnostics probe the API route for the detected major and classify an HTML answer as a failure.Verification
order+cursorlike the real server.scripts/v2-live-*.ts.Not covered
~expansion in the directory picker on 2.x (no server home is exposed).