Skip to content

feat(opencode-go): add Opencode Go as a first-class provider (#172)#319

Open
proyectoauraorg wants to merge 5 commits into
Zoo-Code-Org:mainfrom
proyectoauraorg:feat/172-opencode-go
Open

feat(opencode-go): add Opencode Go as a first-class provider (#172)#319
proyectoauraorg wants to merge 5 commits into
Zoo-Code-Org:mainfrom
proyectoauraorg:feat/172-opencode-go

Conversation

@proyectoauraorg
Copy link
Copy Markdown
Contributor

@proyectoauraorg proyectoauraorg commented May 25, 2026

Closes #172

What

Adds Opencode Go as a first-class provider — an OpenAI-compatible gateway (https://opencode.ai/zen/go/v1) with an API key and a dynamic model list fetched from /v1/models. Models can be switched on the fly via the model picker, instead of configuring each one manually as a separate OpenAI-Compatible provider.

How

  • New OpencodeGoHandler (extends RouterProvider, mirrors VercelAiGatewayHandler): streams text / reasoning / tool calls / usage via chat/completions.
  • New fetcher getOpencodeGoModels (GET /v1/models with Bearer auth; permissive zod schema with sane defaults; fetched on demand since the endpoint needs a key, so it's not in the keyless prefetch list).
  • Wired through types (provider-settings, secret key in global-settings), RouterName / GetModelsOptions, modelCache dispatch, buildApiHandler, useSelectedModel, the settings UI (OpenCodeGo component + provider dropdown + ModelPicker), and i18n.

Scope / follow-ups

  • First pass covers the OpenAI-compatible models (GLM-5/5.1, Kimi K2.5/K2.6, MiMo, Qwen3.5/3.6 Plus, DeepSeek V4). The 4 Anthropic-format models on the Go plan (/v1/messages) can be a follow-up.
  • Pricing is intentionally not parsed — the /models pricing units aren't documented, so cost is left unknown rather than reported wrong. The default model id/info are only a fallback used before the live list resolves.

Tests

New fetcher spec (response mapping, metadata fallback, Bearer header, error → empty map). tsc / eslint / prettier and the affected webview/src suites pass locally.

Summary by CodeRabbit

  • New Features
    • Add Opencode Go provider: configure an Opencode Go API key (stored securely), pick models, and use Opencode Go for streaming and non-streaming completions with sensible defaults.
  • Bug Fixes / Validation
    • Require API key and model when Opencode Go is selected; refresh model list when key changes.
  • Localization
    • Added UI text for Opencode Go API key in many languages.
  • Tests
    • Added tests for model fetching/parsing, handler streaming, and settings UI.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 25, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4ec61c97-a8d8-4af7-a9c2-54390f371bef

📥 Commits

Reviewing files that changed from the base of the PR and between f2a4a0b and 8913414.

📒 Files selected for processing (5)
  • packages/types/src/providers/opencode-go.ts
  • src/api/providers/__tests__/opencode-go.spec.ts
  • src/api/providers/fetchers/__tests__/opencode-go.spec.ts
  • src/api/providers/fetchers/opencode-go.ts
  • src/api/providers/opencode-go.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/api/providers/fetchers/tests/opencode-go.spec.ts
  • packages/types/src/providers/opencode-go.ts
  • src/api/providers/fetchers/opencode-go.ts
  • src/api/providers/opencode-go.ts
  • src/api/providers/tests/opencode-go.spec.ts

📝 Walkthrough

Walkthrough

Adds Opencode Go provider end-to-end: types and schemas, provider defaults, model fetcher/parsing, API handler, model-cache and webview routing, frontend settings UI and i18n, validation updates, and tests.

Changes

Opencode Go Provider Integration

Layer / File(s) Summary
Type contracts and provider schemas
packages/types/src/global-settings.ts, packages/types/src/provider-settings.ts
Adds opencodeGoApiKey to secret keys and extends provider settings/validation to support opencode-go with opencodeGoApiKey and opencodeGoModelId.
Provider defaults and barrel
packages/types/src/providers/..., packages/types/src/providers/index.ts
Exports opencode-go defaults (default model id, default ModelInfo, default temperature) and wires provider default selection and barrel re-exports.
Model fetcher and parser
src/api/providers/fetchers/opencode-go.ts, src/api/providers/fetchers/__tests__/opencode-go.spec.ts
Parses /models responses with permissive Zod schemas, maps to ModelInfo with fallbacks, fetches with optional Bearer auth, logs validation errors, tolerates invalid payloads, and returns models keyed by id; tests cover headers, fallbacks, and error handling.
Model cache integration
src/api/providers/fetchers/modelCache.ts
Model cache branch added for opencode-go calling getOpencodeGoModels(options.apiKey).
API handler and routing
src/api/providers/opencode-go.ts, src/api/providers/index.ts, src/api/index.ts
OpencodeGoHandler implements streaming createMessage and completePrompt, emits reasoning/tool/usage events, and is wired into provider routing and exports.
Webview model routing & shared API
src/core/webview/webviewMessageHandler.ts, src/shared/api.ts
Webview handler includes opencode-go when opencodeGoApiKey is present (flushes cache on override); GetModelsOptions union includes opencode-go with apiKey.
Frontend settings UI and selection
webview-ui/src/components/settings/ApiOptions.tsx, webview-ui/src/components/settings/providers/OpenCodeGo.tsx, webview-ui/src/components/settings/providers/index.ts, webview-ui/src/components/settings/ModelPicker.tsx, webview-ui/src/components/settings/constants.ts, webview-ui/src/components/ui/hooks/useSelectedModel.ts, i18n files
Adds OpenCodeGo settings component with API key input and ModelPicker wiring; adds provider to PROVIDERS and provider→model-field mapping; extends ModelPicker/useSelectedModel to support opencodeGoModelId with fallback model info; adds translation keys across locales and updates validation tests.
Validation & tests
webview-ui/src/utils/validate.ts, src/core/webview/__tests__/*, webview-ui/src/components/settings/providers/__tests__/OpenCodeGo.spec.tsx, src/api/providers/__tests__/opencode-go.spec.ts
Validation requires opencodeGoApiKey for opencode-go; tests added/updated for fetchers, handler, webview router models, settings UI, and validation behavior.

Sequence Diagram

sequenceDiagram
  participant Webview
  participant ApiHandler
  participant ModelCache
  participant OpencodeGoAPI
  Webview->>ApiHandler: request models / send messages (provider: opencode-go, apiKey)
  ApiHandler->>ModelCache: fetchModels(provider: opencode-go, apiKey)
  ApiHandler->>OpencodeGoAPI: chat.completions.create (stream)
  OpencodeGoAPI->>ApiHandler: stream chunks (text, reasoning, tool_call_partial, usage)
  ApiHandler->>Webview: emit deltas/events
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • taltas
  • navedmerchant
  • hannesrudolph
  • JamesRobert20

Poem

A rabbit hops through schemas bright,
I added keys and models tight,
Fetchers hum and handlers stream,
UI shows an API-key beam 🐇,
Opencode Go now joins the night.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding Opencode Go as a first-class provider, with reference to the issue number.
Description check ✅ Passed The PR description follows the template structure with all required sections: Related GitHub Issue (Closes #172), Description (What/How), Scope/follow-ups, Tests, and Pre-Submission Checklist completed.
Linked Issues check ✅ Passed The PR implementation fully addresses issue #172 requirements: adds Opencode Go as a dedicated provider with dynamic model list fetching, enables on-the-fly model selection via model picker, and eliminates manual per-model configuration.
Out of Scope Changes check ✅ Passed All changes are directly scoped to adding Opencode Go provider support: types, handlers, fetchers, settings UI, i18n strings, and tests. Follow-ups for Anthropic-format models are explicitly noted as future work.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/types/src/providers/opencode-go.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

src/api/providers/__tests__/opencode-go.spec.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

src/api/providers/fetchers/__tests__/opencode-go.spec.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.

  • 2 others

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
webview-ui/src/components/ui/hooks/useSelectedModel.ts (1)

349-357: ⚡ Quick win

Use the provider fallback ModelInfo when Opencode Go model metadata is unavailable.

This branch can return info: undefined when /models is empty/unavailable, which drops capability-driven UI behavior. Prefer returning the existing Opencode Go fallback ModelInfo from @roo-code/types when router info is missing.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@webview-ui/src/components/ui/hooks/useSelectedModel.ts` around lines 349 -
357, In the "opencode-go" branch of useSelectedModel (where getValidatedModelId
is used with apiConfiguration.opencodeGoModelId, routerModels["opencode-go"],
and defaultModelId), ensure you return a fallback ModelInfo from `@roo-code/types`
when routerModels["opencode-go"] lacks metadata; import the Opencode Go fallback
ModelInfo from `@roo-code/types` and change the return to return { id, info: info
?? <OpencodeGoFallbackModelInfo> } so the UI keeps capability-driven behavior
when /models is empty or unavailable.
webview-ui/src/components/settings/providers/OpenCodeGo.tsx (1)

26-79: ⚡ Quick win

Add local UI tests for the new Opencode Go settings component.

This introduces new conditional UI/state wiring (API key input, CTA visibility, and model picker integration) but no colocated webview UI tests were added. Please add Vitest coverage for those flows to prevent regressions.

As per coding guidelines webview-ui/src/**/*.{ts,tsx}: "Prefer local webview-ui tests for React/webview behavior ... Add or update Vitest coverage under webview-ui/src/**/__tests__ instead of reaching for apps/vscode-e2e."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@webview-ui/src/components/settings/providers/OpenCodeGo.tsx` around lines 26
- 79, Add Vitest/React Testing Library unit tests for the OpenCodeGo component:
create tests under webview-ui/src/**/__tests__ that mount OpenCodeGo and assert
(1) the API key input (value bound to apiConfiguration.opencodeGoApiKey) updates
via the handleInputChange wiring, (2) the CTA link (VSCodeButtonLink with href
"https://opencode.ai/docs/go/") is shown only when
apiConfiguration.opencodeGoApiKey is falsy, and (3) the ModelPicker integration
receives the correct props (defaultModelId = opencodeGoDefaultModelId, models
from routerModels["opencode-go"], modelIdKey="opencodeGoModelId", plus
organizationAllowList and errorMessage). Use a mock setApiConfigurationField to
verify it is called on input change and shallow/render wrapper or RTL to query
by label/text/role; keep tests colocated under webview-ui/src/**/__tests__ to
satisfy coverage requirements.
webview-ui/src/utils/__tests__/validate.spec.ts (1)

49-50: ⚡ Quick win

Add explicit Opencode Go validation assertions in this suite.

Adding the fixture key is good, but this file still lacks direct tests for Opencode Go validation behavior (e.g., missing API key, missing/invalid opencodeGoModelId, allowed/blocked model cases).

As per coding guidelines **/{__tests__,tests,test}/**/*.{test,spec}.{ts,tsx,js}: "Use package-local unit tests for pure logic ... validation ... and error handling."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@webview-ui/src/utils/__tests__/validate.spec.ts` around lines 49 - 50, Add
explicit unit tests in validate.spec.ts that assert Opencode Go validation
behavior for the "opencode-go" fixture: write tests to cover missing API key
(expect specific validation error), missing or empty opencodeGoModelId (expect
validation error), invalid/unsupported opencodeGoModelId values (expect
rejection), and allowed/blocked model cases (assert success/failure). Target the
validation functions used by the suite (the existing validation utilities called
in this test file that validate provider settings and model IDs) and add
assertions that inspect returned error objects/messages so each scenario is
verified.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/api/providers/fetchers/opencode-go.ts`:
- Around line 44-46: The axios GET to `${OPENCODE_GO_BASE_URL}/models` in
src/api/providers/fetchers/opencode-go.ts lacks a timeout and can hang; update
the call in the function that performs this fetch (the axios.get(...) shown) to
pass a timeout option using the existing getApiRequestTimeout() utility (e.g.,
add timeout: getApiRequestTimeout() into the request config) while preserving
the conditional headers logic (headers: apiKey ? { Authorization: `Bearer
${apiKey}` } : undefined); if getApiRequestTimeout is not already imported in
this file, import it from its module.

---

Nitpick comments:
In `@webview-ui/src/components/settings/providers/OpenCodeGo.tsx`:
- Around line 26-79: Add Vitest/React Testing Library unit tests for the
OpenCodeGo component: create tests under webview-ui/src/**/__tests__ that mount
OpenCodeGo and assert (1) the API key input (value bound to
apiConfiguration.opencodeGoApiKey) updates via the handleInputChange wiring, (2)
the CTA link (VSCodeButtonLink with href "https://opencode.ai/docs/go/") is
shown only when apiConfiguration.opencodeGoApiKey is falsy, and (3) the
ModelPicker integration receives the correct props (defaultModelId =
opencodeGoDefaultModelId, models from routerModels["opencode-go"],
modelIdKey="opencodeGoModelId", plus organizationAllowList and errorMessage).
Use a mock setApiConfigurationField to verify it is called on input change and
shallow/render wrapper or RTL to query by label/text/role; keep tests colocated
under webview-ui/src/**/__tests__ to satisfy coverage requirements.

In `@webview-ui/src/components/ui/hooks/useSelectedModel.ts`:
- Around line 349-357: In the "opencode-go" branch of useSelectedModel (where
getValidatedModelId is used with apiConfiguration.opencodeGoModelId,
routerModels["opencode-go"], and defaultModelId), ensure you return a fallback
ModelInfo from `@roo-code/types` when routerModels["opencode-go"] lacks metadata;
import the Opencode Go fallback ModelInfo from `@roo-code/types` and change the
return to return { id, info: info ?? <OpencodeGoFallbackModelInfo> } so the UI
keeps capability-driven behavior when /models is empty or unavailable.

In `@webview-ui/src/utils/__tests__/validate.spec.ts`:
- Around line 49-50: Add explicit unit tests in validate.spec.ts that assert
Opencode Go validation behavior for the "opencode-go" fixture: write tests to
cover missing API key (expect specific validation error), missing or empty
opencodeGoModelId (expect validation error), invalid/unsupported
opencodeGoModelId values (expect rejection), and allowed/blocked model cases
(assert success/failure). Target the validation functions used by the suite (the
existing validation utilities called in this test file that validate provider
settings and model IDs) and add assertions that inspect returned error
objects/messages so each scenario is verified.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c4a8c5e9-83e5-4b43-94dd-abfe6eb6cdbc

📥 Commits

Reviewing files that changed from the base of the PR and between 9d022d4 and 82f9a2f.

📒 Files selected for processing (20)
  • packages/types/src/global-settings.ts
  • packages/types/src/provider-settings.ts
  • packages/types/src/providers/index.ts
  • packages/types/src/providers/opencode-go.ts
  • src/api/index.ts
  • src/api/providers/fetchers/__tests__/opencode-go.spec.ts
  • src/api/providers/fetchers/modelCache.ts
  • src/api/providers/fetchers/opencode-go.ts
  • src/api/providers/index.ts
  • src/api/providers/opencode-go.ts
  • src/core/webview/webviewMessageHandler.ts
  • src/shared/api.ts
  • webview-ui/src/components/settings/ApiOptions.tsx
  • webview-ui/src/components/settings/ModelPicker.tsx
  • webview-ui/src/components/settings/constants.ts
  • webview-ui/src/components/settings/providers/OpenCodeGo.tsx
  • webview-ui/src/components/settings/providers/index.ts
  • webview-ui/src/components/ui/hooks/useSelectedModel.ts
  • webview-ui/src/i18n/locales/en/settings.json
  • webview-ui/src/utils/__tests__/validate.spec.ts

Comment thread src/api/providers/fetchers/opencode-go.ts
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
webview-ui/src/components/ui/hooks/useSelectedModel.ts (1)

356-359: ⚡ Quick win

Add a focused hook test for the Opencode Go fallback path.

This branch changes selected-model behavior when /models is empty/unavailable; add a local Vitest for useSelectedModel asserting fallback to opencodeGoDefaultModelInfo so capability UI behavior stays locked.

As per coding guidelines webview-ui/src/**/*.{ts,tsx}: "Prefer local webview-ui tests for React/webview behavior ... Add or update Vitest coverage under webview-ui/src/**/__tests__ instead of reaching for apps/vscode-e2e."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@webview-ui/src/components/ui/hooks/useSelectedModel.ts` around lines 356 -
359, Add a focused Vitest hook test under webview-ui/src/**/__tests__ that
asserts useSelectedModel falls back to opencodeGoDefaultModelInfo when the
/models list is empty or unavailable: render the hook (useSelectedModel) with
routerModels mocked/empty (or ensure the module/state that supplies routerModels
returns an empty object), call/select the opencode-go model id, and assert the
returned info equals the exported opencodeGoDefaultModelInfo; reference the
symbols useSelectedModel, opencodeGoDefaultModelInfo and routerModels so the
test targets the exact fallback path changed in this diff.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@webview-ui/src/components/ui/hooks/useSelectedModel.ts`:
- Around line 356-359: Add a focused Vitest hook test under
webview-ui/src/**/__tests__ that asserts useSelectedModel falls back to
opencodeGoDefaultModelInfo when the /models list is empty or unavailable: render
the hook (useSelectedModel) with routerModels mocked/empty (or ensure the
module/state that supplies routerModels returns an empty object), call/select
the opencode-go model id, and assert the returned info equals the exported
opencodeGoDefaultModelInfo; reference the symbols useSelectedModel,
opencodeGoDefaultModelInfo and routerModels so the test targets the exact
fallback path changed in this diff.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f0daafe1-1a0b-467c-9b40-768b955fc12e

📥 Commits

Reviewing files that changed from the base of the PR and between 82f9a2f and fe7ae01.

📒 Files selected for processing (25)
  • src/api/providers/fetchers/__tests__/opencode-go.spec.ts
  • src/api/providers/fetchers/opencode-go.ts
  • src/core/webview/__tests__/ClineProvider.spec.ts
  • src/core/webview/__tests__/webviewMessageHandler.spec.ts
  • webview-ui/src/components/settings/providers/__tests__/OpenCodeGo.spec.tsx
  • webview-ui/src/components/ui/hooks/useSelectedModel.ts
  • webview-ui/src/i18n/locales/ca/settings.json
  • webview-ui/src/i18n/locales/de/settings.json
  • webview-ui/src/i18n/locales/es/settings.json
  • webview-ui/src/i18n/locales/fr/settings.json
  • webview-ui/src/i18n/locales/hi/settings.json
  • webview-ui/src/i18n/locales/id/settings.json
  • webview-ui/src/i18n/locales/it/settings.json
  • webview-ui/src/i18n/locales/ja/settings.json
  • webview-ui/src/i18n/locales/ko/settings.json
  • webview-ui/src/i18n/locales/nl/settings.json
  • webview-ui/src/i18n/locales/pl/settings.json
  • webview-ui/src/i18n/locales/pt-BR/settings.json
  • webview-ui/src/i18n/locales/ru/settings.json
  • webview-ui/src/i18n/locales/tr/settings.json
  • webview-ui/src/i18n/locales/vi/settings.json
  • webview-ui/src/i18n/locales/zh-CN/settings.json
  • webview-ui/src/i18n/locales/zh-TW/settings.json
  • webview-ui/src/utils/__tests__/validate.spec.ts
  • webview-ui/src/utils/validate.ts
✅ Files skipped from review due to trivial changes (12)
  • webview-ui/src/i18n/locales/ru/settings.json
  • webview-ui/src/i18n/locales/nl/settings.json
  • webview-ui/src/i18n/locales/vi/settings.json
  • webview-ui/src/i18n/locales/ja/settings.json
  • webview-ui/src/i18n/locales/zh-TW/settings.json
  • webview-ui/src/i18n/locales/pl/settings.json
  • webview-ui/src/i18n/locales/ko/settings.json
  • webview-ui/src/i18n/locales/zh-CN/settings.json
  • webview-ui/src/i18n/locales/pt-BR/settings.json
  • webview-ui/src/i18n/locales/it/settings.json
  • webview-ui/src/i18n/locales/fr/settings.json
  • webview-ui/src/i18n/locales/tr/settings.json

@codecov
Copy link
Copy Markdown

codecov Bot commented May 25, 2026

Codecov Report

❌ Patch coverage is 90.64516% with 29 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/api/providers/opencode-go.ts 85.55% 13 Missing ⚠️
src/core/webview/webviewMessageHandler.ts 18.18% 9 Missing ⚠️
src/api/providers/fetchers/modelCache.ts 25.00% 3 Missing ⚠️
src/api/index.ts 0.00% 2 Missing ⚠️
src/api/providers/fetchers/opencode-go.ts 96.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

proyectoauraorg added a commit to proyectoauraorg/Zoo-Code that referenced this pull request May 25, 2026
…pt (Zoo-Code-Org#172)

Adds unit tests for the handler: client init (base URL/key), fetchModel
(configured + default), createMessage streaming (text/reasoning/tool_call/
usage), and completePrompt (content + error wrapping). Raises patch coverage
to green CI on Zoo-Code-Org#319.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/api/providers/__tests__/opencode-go.spec.ts`:
- Around line 156-161: Update the test that constructs the OpencodeGo request to
assert the full request fields: after creating the handler and calling
handler.completePrompt("ping"), add an assertion that mockCreate was called with
an object containing temperature (use the test's mockOptions.temperature) and
max_completion_tokens set to 32768 in addition to the existing model and stream
checks (e.g., expect(mockCreate).toHaveBeenCalledWith(expect.objectContaining({
model: "glm-5.1", stream: false, temperature: mockOptions.temperature,
max_completion_tokens: 32768 })) so the test verifies both temperature and
max_completion_tokens are included in the request construction.
- Around line 138-152: The test for OpencodeGoHandler.createMessage should
assert the remaining request fields: verify that when
handler.supportsTemperature is true the outgoing request includes a temperature
field, assert max_completion_tokens equals the model info.maxTokens used by the
handler, and assert the messages payload is the correctly transformed Anthropic
-> OpenAI format; update the expect(mockCreate).toHaveBeenCalledWith(...) to
include temperature and max_completion_tokens and add an expectation that the
passed messages array matches the serialized form produced by createMessage (use
the same mockCreate call arguments to inspect the messages param), referencing
OpencodeGoHandler, createMessage, supportsTemperature, and info.maxTokens to
locate the logic to mirror in the assertions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8d3f76b3-3c66-410f-b0d6-ac7764e44df5

📥 Commits

Reviewing files that changed from the base of the PR and between fe7ae01 and 4ce91a1.

📒 Files selected for processing (1)
  • src/api/providers/__tests__/opencode-go.spec.ts

Comment thread src/api/providers/__tests__/opencode-go.spec.ts
Comment thread src/api/providers/__tests__/opencode-go.spec.ts
…e-Org#172)

Opencode Go's models were only usable by configuring each one manually as a
separate OpenAI-Compatible provider, with no on-the-fly model switching.

Add Opencode Go as a dedicated OpenAI-compatible gateway provider
(https://opencode.ai/zen/go/v1) with an API key and a dynamic model list
fetched from /v1/models, so models can be switched on the fly via the model
picker. Mirrors the VercelAiGateway provider (RouterProvider + fetcher).

Pricing is intentionally not parsed (units undocumented; cost shown as unknown
rather than wrong). First pass covers the OpenAI-compatible models; the
Anthropic-format models on the Go plan (/v1/messages) are a follow-up.

Adds a fetcher spec. tsc/eslint/prettier and affected suites pass.
- Add missing opencodeGo translation keys across all 17 non-English locales
  (check-translations was failing).
- Include the opencode-go entry in expected routerModels for the ClineProvider
  and webviewMessageHandler requestRouterModels suites (unit tests were failing).
- Add a request timeout to the /models fetch so it can't hang.
- Fall back to the default ModelInfo in useSelectedModel when the /models list
  is empty, keeping capability-driven UI working.
- Validate the Opencode Go API key and add validate.spec + OpenCodeGo component
  tests.
…pt (Zoo-Code-Org#172)

Adds unit tests for the handler: client init (base URL/key), fetchModel
(configured + default), createMessage streaming (text/reasoning/tool_call/
usage), and completePrompt (content + error wrapping). Raises patch coverage
to green CI on Zoo-Code-Org#319.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/api/providers/fetchers/opencode-go.ts`:
- Around line 50-58: The fallback assignment uses raw response.data?.data and
maps items directly into models, which can propagate malformed entries; instead
ensure each item is validated before mapping: when iterating over data from
result or response, check the item exists and has a valid id (e.g., typeof
model.id === 'string' and other required fields as appropriate), wrap
parseOpencodeGoModel usage in a try/catch or a guard so only successfully
parsed/validated results are assigned to models[model.id], and skip and
optionally log any invalid entries; update the loop around parseOpencodeGoModel,
result, response, and models to perform this validation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: bd6fe419-3608-4b8f-b96b-6ddf2206fea3

📥 Commits

Reviewing files that changed from the base of the PR and between 4ce91a1 and f2a4a0b.

📒 Files selected for processing (42)
  • packages/types/src/global-settings.ts
  • packages/types/src/provider-settings.ts
  • packages/types/src/providers/index.ts
  • packages/types/src/providers/opencode-go.ts
  • src/api/index.ts
  • src/api/providers/__tests__/opencode-go.spec.ts
  • src/api/providers/fetchers/__tests__/opencode-go.spec.ts
  • src/api/providers/fetchers/modelCache.ts
  • src/api/providers/fetchers/opencode-go.ts
  • src/api/providers/index.ts
  • src/api/providers/opencode-go.ts
  • src/core/webview/__tests__/ClineProvider.spec.ts
  • src/core/webview/__tests__/webviewMessageHandler.spec.ts
  • src/core/webview/webviewMessageHandler.ts
  • src/shared/api.ts
  • webview-ui/src/components/settings/ApiOptions.tsx
  • webview-ui/src/components/settings/ModelPicker.tsx
  • webview-ui/src/components/settings/constants.ts
  • webview-ui/src/components/settings/providers/OpenCodeGo.tsx
  • webview-ui/src/components/settings/providers/__tests__/OpenCodeGo.spec.tsx
  • webview-ui/src/components/settings/providers/index.ts
  • webview-ui/src/components/ui/hooks/useSelectedModel.ts
  • webview-ui/src/i18n/locales/ca/settings.json
  • webview-ui/src/i18n/locales/de/settings.json
  • webview-ui/src/i18n/locales/en/settings.json
  • webview-ui/src/i18n/locales/es/settings.json
  • webview-ui/src/i18n/locales/fr/settings.json
  • webview-ui/src/i18n/locales/hi/settings.json
  • webview-ui/src/i18n/locales/id/settings.json
  • webview-ui/src/i18n/locales/it/settings.json
  • webview-ui/src/i18n/locales/ja/settings.json
  • webview-ui/src/i18n/locales/ko/settings.json
  • webview-ui/src/i18n/locales/nl/settings.json
  • webview-ui/src/i18n/locales/pl/settings.json
  • webview-ui/src/i18n/locales/pt-BR/settings.json
  • webview-ui/src/i18n/locales/ru/settings.json
  • webview-ui/src/i18n/locales/tr/settings.json
  • webview-ui/src/i18n/locales/vi/settings.json
  • webview-ui/src/i18n/locales/zh-CN/settings.json
  • webview-ui/src/i18n/locales/zh-TW/settings.json
  • webview-ui/src/utils/__tests__/validate.spec.ts
  • webview-ui/src/utils/validate.ts
✅ Files skipped from review due to trivial changes (11)
  • webview-ui/src/i18n/locales/es/settings.json
  • webview-ui/src/i18n/locales/de/settings.json
  • webview-ui/src/i18n/locales/hi/settings.json
  • webview-ui/src/i18n/locales/pt-BR/settings.json
  • webview-ui/src/i18n/locales/ca/settings.json
  • webview-ui/src/i18n/locales/ja/settings.json
  • webview-ui/src/i18n/locales/nl/settings.json
  • webview-ui/src/i18n/locales/it/settings.json
  • webview-ui/src/i18n/locales/zh-CN/settings.json
  • webview-ui/src/i18n/locales/fr/settings.json
  • src/api/providers/fetchers/tests/opencode-go.spec.ts

Comment thread src/api/providers/fetchers/opencode-go.ts Outdated
…tronger assertions, JSDoc (Zoo-Code-Org#172)

- Add Array.isArray guard + per-model safeParse with console.warn in getOpencodeGoModels
- Assert max_completion_tokens and temperature in handler tests
- Add test cases for non-array response.data.data and invalid model entries
- Add JSDoc with @param/@returns to all public functions
@navedmerchant
Copy link
Copy Markdown
Contributor

Thank you for the contribution, reviewing this now as this coding plan is pretty popular

Copy link
Copy Markdown
Contributor

@edelauna edelauna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good - had 1 nit, and created some issues for follow up things I'd like to refactor

Comment on lines +16 to +17
inputPrice: 0,
outputPrice: 0,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since pricing is intentionally omitted (the PR description says "reporting a wrong cost is worse than reporting unknown"), could these be dropped entirely rather than set to 0?

ModelInfoView shows price when the field is !== undefined, so 0 will render as "$0.00 / 1M tokens" in the UI — implying the service is free. Fetched models from parseOpencodeGoModel correctly leave these fields absent; the fallback would be more consistent without them.

Copy link
Copy Markdown
Contributor

@navedmerchant navedmerchant May 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested and it does not show any UI. I agree it would better to leave ths out to be consistent

*/
override async *createMessage(
systemPrompt: string,
messages: Anthropic.Messages.MessageParam[],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created an issue for this: #337 - it's not urgent, but annoying that we have to do this for every provider.


const completion = await this.client.chat.completions.create(body)

for await (const chunk of completion) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unfortunate that this needed to be duplicated, created an issue to refactor this into a common util: #338

ModelInfoView renders a 0 price field as "$0.00 / 1M tokens", implying the
service is free. Drop inputPrice/outputPrice from the fallback so it stays
unknown until the live /v1/models list resolves, matching the fetched models
which leave price fields absent. Addresses PR Zoo-Code-Org#319 review (edelauna, navedmerchant).
@proyectoauraorg
Copy link
Copy Markdown
Contributor Author

Done — dropped inputPrice/outputPrice from the fallback opencodeGoDefaultModelInfo so the price stays unknown until the live /v1/models list resolves, matching the dynamically fetched models (which leave the fields absent). This avoids ModelInfoView rendering a misleading "$0.00 / 1M tokens". Thanks @edelauna and @navedmerchant! 🦓

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.

Opencode Go plan not available as provider

3 participants