Capture the assessment of how opencode integrates the AI SDK today and
the phased plan to replace it with @opencode-ai/llm behind a feature flag.
Sections:
- Today's architecture, including the trace of one streamText call and
the existing native path's gate conditions
- Where the spaghetti actually lives (AI SDK type leakage in 11+ files,
scattered provider-specific transforms, the provider/sdk/copilot/* fork,
duplicated MessageV2 conversion)
- Target architecture (one flag, one decision point at layer construction)
- Phased migration: Decouple → Service swap → Native parity → Flag rollout
→ Delete AI SDK
- Suggested execution order, key files, risks and open questions
Push URL host knowledge from `Endpoint` (route layer) up to `model.baseURL`
(provider helper layer). The route just composes a path onto whatever
host the model already carries.
Endpoint:
- `Endpoint<Body>` shrinks to `{ path }`. No more `default`, `baseURL`,
or `required` fallback fields.
- `Endpoint.path(value)` replaces the old `Endpoint.baseURL({...})` factory.
- `Endpoint.render()` is now sync — `${model.baseURL}${path}` plus query
params. No fallback chain, no Effect wrapper.
ModelRef:
- `ModelRef.baseURL: Schema.String` (was optional). Every materialized
model carries a host.
- `RouteModelInput.baseURL?: string` stays optional so route defaults
can supply a canonical URL; routes without a default tighten it.
Provider helpers:
- Each protocol exports a `DEFAULT_BASE_URL` constant and bakes it into
`route.defaults.baseURL`. Provider helpers don't need to set baseURL.
- Azure uses a new `AtLeastOne<T>` helper from `auth-options.ts` to
require either `resourceName` or `baseURL` at the type level.
- Bedrock provider computes baseURL from `region` at construction time.
- OpenAI-compatible profiles now have required (not optional) `baseURL`
in their type — all 9 already supplied one.
- The `defaultBaseURL: string | false` knob on protocol endpoint
factories is gone.
Effects:
- Forgetting baseURL is now caught at compile time (TS) or model
construction time (modelWithDefaults runtime check), not request time.
- `Endpoint.render` no longer needs Effect wrapping in the transport
hot path.
Three small fixes for stale references after the recent
adapter→route rename and `model.protocol` field removal in
@opencode-ai/llm:
- Update three `@opencode-ai/llm/adapter` imports to `/route`.
- Switch `NATIVE_PROTOCOLS` filter on `model.protocol` to
`NATIVE_ROUTES` on `model.route`.
- Refresh test fixtures: `protocol:` → `route:`, drop `apiKey:`
/ `adapter:` assertions that reference fields no longer on
`ModelRef`, drop the `attachments` expectation that no longer
has a source-side handler.
- Default `key: "test-key"` on `ProviderTest.info` so prepare()
can resolve auth without per-test env setup.