v2.0.0 — OpenCode SDK v2 Migration
What's Changed
Migrates the provider from OpenCode SDK v1 to v2 (@opencode-ai/sdk/v2), adding support for new v2 capabilities and hardening the implementation.
Core Migration
- SDK v2 API style: All SDK calls migrated from nested
{ path, body }to v2 flat parameter style ({ sessionID, directory, ... }) - Import path:
@opencode-ai/sdk→@opencode-ai/sdk/v2 - Dependency bumps:
@ai-sdk/provider^3.0.8,@ai-sdk/provider-utils^4.0.15,ai^6.0.85
New Features
- Permission/tool approval flow: Emits
tool-approval-requeststream parts frompermission.askedevents; handlestool-approval-responseparts viapermission.reply()API - Native structured output: JSON mode uses OpenCode's native
json_schemaformat withretryCountinstead of prompt-based instructions - File/source content streaming:
handleFilePart()fully implemented — handles data URLs, HTTP URLs, and source metadata - New settings:
permission(ruleset),variant,directory(per-request routing),outputFormatRetryCount - New error types:
ContextOverflowError→"length",StructuredOutputError→"error"
Hardening
- Question events:
question.askedemits a stream error part with warning; related events are known no-ops - Known v2 events/parts: All new v2 event and part types explicitly handled (no "Unknown" debug spam)
- Safe tool input serialization:
safeStringifyToolInput()with try/catch fallback - Typed approval client:
ApprovalClientinterface replaces loose typing - File part diagnostics: Debug logs when file parts are skipped
- Non-prefix tool input delta: Prevents data loss on non-incremental input changes
Deprecations
toolssetting → usepermissionrulesetcwdsetting → usedirectory
Tests
- 283 tests passing (up from 278)
Full Changelog: v1.0.0...v2.0.0