Commit graph

2 commits

Author SHA1 Message Date
Mourad Maatoug
57354ac6d7 feat(@omniroute/opencode-provider): model capabilities, agent block, mode block (UI helpers)
Adds three UI-surface helpers on top of T1–T8 in PR #2375:

A) Model capability flags
   - ModelCapabilities interface (label, attachment, reasoning, temperature, tool_call)
   - OMNIROUTE_DEFAULT_MODEL_CAPABILITIES seeds capabilities for all 7 default
     model ids
   - OmniRouteProviderOptions.modelCapabilities merges over defaults per id
   - createOmniRouteProvider emits capability flags inline in models[id], per
     OpenCode's ProviderConfig.models schema (snake_case JSON keys, optional)
   - Label precedence: modelCapabilities[id].label > modelLabels[id] > id

B) createOmniRouteAgentBlock
   - OmniRouteAgentRole + OmniRouteAgentBlockOptions + OpenCodeAgentEntry
   - Emits Record<role, { model: 'omniroute/<id>', temperature?, top_p?,
     tools?: Record<string, boolean>, prompt? }>
   - Only fields present in OpenCode's AgentConfig schema are emitted
   - Tools normalized to Record<string, boolean> per schema (not string[])
   - Roles with empty modelId are skipped

C) createOmniRouteModesBlock (deprecated alias)
   - Same shape as createOmniRouteAgentBlock since OpenCode treats top-level
     'mode' block identically to 'agent' (both reference AgentConfig)
   - Helper kept for back-compat; @deprecated tags steer callers to agent

Shared helper buildAgentEntry eliminates duplication between A/B helpers.

Schema validation
- All emitted keys verified against https://opencode.ai/config.json
- Removed initially-considered reasoningEffort + max_tokens fields (not in
  AgentConfig schema)
- tools shape changed from string[] to Record<string, boolean> per schema

Build hygiene
- tsconfig.json narrowed to lib: ['ES2022'] + types: ['node'] (no DOM lib
  leakage); @types/node added as devDep
- Tests: 32 → 45 green (+13 net)
- Build: ESM 10.39 KB / CJS 11.01 KB / DTS 18.87 KB
2026-05-18 17:06:13 +02:00
diegosouzapw
4b1e57443a refactor(@omniroute/opencode-provider): rewrite for schema correctness + publishability
The 1.0.0 release of the package was broken end-to-end:

  1. index.js re-exported from "./index.ts" — Node can't import .ts at runtime,
     so any consumer who `npm install`ed the package got ERR_UNKNOWN_FILE_EXTENSION.
  2. The emitted provider shape did not match the OpenCode schema
     (https://opencode.ai/config.json). It used a custom `{id, name, npm, options, auth}`
     instead of the schema's `{npm: "@ai-sdk/openai-compatible", name, options, models}`.
  3. README told users to pass `baseURL: "http://localhost:20128/v1"` but the code
     appended `/v1` again — every request would 404 at `/v1/v1/...`.
  4. No build step, no LICENSE file, no repository/author/engines fields, no tests.

This rewrite:

- Moves source under `src/`, adds a tsup build emitting CJS + ESM + .d.ts.
- `createOmniRouteProvider` now returns a schema-valid entry with
  `npm: "@ai-sdk/openai-compatible"` + `models: Record<string, { name }>`.
- Adds `buildOmniRouteOpenCodeConfig` for full-document scaffolding.
- `normalizeBaseURL` deduplicates trailing `/` and `/v1`, accepts both forms,
  and rejects malformed URLs and empty inputs.
- 13 unit tests covering URL normalisation, input validation, default model
  catalog, custom models + labels, dedup/trim behaviour, and JSON round-trip.
- Adds LICENSE, full package.json (repository, engines, scripts, exports),
  .gitignore, .npmignore, tsconfig.json, and a comprehensive README.
- Resets version to 0.1.0 to signal the pre-1.0 reset (1.0.0 was never on npm).

Documentation:

- New `docs/frameworks/OPENCODE.md` covering both integration paths (CLI vs npm),
  URL normalisation, auth modes, troubleshooting, and runtime flow.
- README.md links the package and points to the new doc.
- CHANGELOG entry under Unreleased > Changed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-14 16:58:33 -03:00