Skip to content

feat: support OpenCode V2 alongside V1 - #135

Open
haigithub wants to merge 1 commit into
tickernelz:masterfrom
haigithub:feat/opencode-v2-support
Open

haigithub wants to merge 1 commit into
tickernelz:masterfrom
haigithub:feat/opencode-v2-support

Conversation

@haigithub

Copy link
Copy Markdown

Closes #134.

Summary

One package now loads on both OpenCode V1 (1.18.29+) and OpenCode V2, using the dual-entrypoint shape from the V2 migration guide. The default export carries id, a V2 setup(ctx) and the V1 server(). V2 ignores server(); V1 ignores setup().

Both entrypoints share the account, auth and request machinery, which moved into src/runtime.ts. Kiro request handling (RequestHandler, streaming, effort mapping) is unchanged.

V2 entrypoint (src/plugin-v2.ts)

  • Provider and models: registers the kiro provider with the same model registry as V1. Thinking ladders become V2 variant settings (thinkingConfig.thinkingBudget), so kiro/claude-opus-5-thinking#xhigh reaches the existing budget-to-effort mapping.
  • Request routing: an aisdk sdk hook builds the OpenAI-compatible AI SDK provider with the plugin's fetch, so every request still goes through RequestHandler.
  • SDK package by file URL: the provider package is aisdk:file://…/v2-sdk.js, pinned on every model. V2 rewrites @ai-sdk/openai-compatible onto its native route, which never calls the sdk hook. Also, user config is applied after plugins, so a legacy provider.kiro.npm would replace a provider-level package. Both cases were reproduced against V2 2.2.1 before the fix.
  • Login: the Builder ID / IAM Identity Center device-code login is exposed as two integration OAuth methods for opencode auth login kiro. Form patterns let V2 reject bad input with a readable message before authorize runs. Accounts are still stored in kiro.db.
  • Web search: kiro_web_search is registered through a tool transform for Pro accounts and reloaded after kiro-cli sync or login.

V1

Behaviour is unchanged. src/plugin.ts now builds on runtime.ts, and the prompt validators in auth-handler.ts were extracted so V2 can reuse them. plugin-v2.js is imported lazily, so V1 never loads V2-only code.

Known V2 limitations (documented in the README)

  • V2 server plugins have no toast API. Usage summaries and re-auth notices go to ~/.config/opencode/kiro-logs/plugin.log.
  • In-request automatic re-authentication is V1-only. On V2, users run opencode auth login kiro or kiro-cli login.

Packaging

  • Adds exports (. and ./package.json). V2 resolves local plugin directories through it. This blocks deep imports into dist/, which may warrant a minor or major version bump.
  • New runtime dependency: @ai-sdk/openai-compatible@^2.0.87 (the AI SDK v6 line that V2's bridge expects).
  • @opencode/plugin is a dev dependency only; the built JS uses it for types.
  • zod range raised to ^3.25.76 to satisfy the new dependency's peer range. The lockfile already resolved that version.
  • package-lock.json is not regenerated. Doing so bumps unrelated transitive versions; CI uses bun install.

Testing

  • bun run typecheck passes; bun test: 191 pass, 0 fail.
    • New: src/__tests__/plugin-v2.test.ts covers model conversion, the SDK module, streaming reasoning, tool calls and body overlays.
    • New: src/__tests__/plugin-v2-setup.test.ts drives setupKiroV2 with a fake context.
  • Manual runs with real Kiro credentials in isolated HOME directories:
Check V1 1.19.4 V2 2.2.1
Model list (24 models) ✅ ✅
Request with thinking output ✅ ✅
Tool call (read) ✅ ✅
Variant to effort (#xhigh → xhigh, #high → high) ✅ ✅
Legacy provider.kiro.npm (both old README values) n/a ✅
providers.kiro.models override n/a ✅
kiro_web_search not run ✅
Invalid login input rejected with a readable message n/a ✅

The full V2 device-code login was not completed end to end, because it opens a browser to AWS. Method registration and input validation were verified.

Ship one package that loads on both OpenCode generations (tickernelz#134). The
default export now carries `id`, a V2 `setup(ctx)` and the V1 `server()`.
Both share the account, auth and request machinery, extracted into
src/runtime.ts.

The V2 entrypoint (src/plugin-v2.ts):
- registers the kiro provider and the same model registry as V1, with
  thinking ladders as V2 variant settings
- builds the AI SDK provider itself in an `aisdk` sdk hook, so requests
  still go through RequestHandler
- names that SDK by file URL (src/v2-sdk.ts) and pins it on every model;
  V2 otherwise rewrites `@ai-sdk/openai-compatible` onto its native
  route, and a legacy `provider.kiro.npm` would override a provider-level
  package
- exposes the Builder ID / Identity Center device login as integration
  OAuth methods, with form patterns so V2 rejects bad input up front
- registers kiro_web_search through a tool transform

V1 behaviour is unchanged; plugin-v2 is imported lazily so V1 never
loads V2-only code. V2 has no server toasts, so notices go to the plugin
log, and in-request re-authentication stays V1-only.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request the support for OpenCode V2

1 participant