Skip to content

fix(agents): upgrade opencode to 2.2.1 - #2776

Draft
mattzcarey wants to merge 2 commits into
mainfrom
fix/opencode-2.2.1-provider
Draft

mattzcarey wants to merge 2 commits into
mainfrom
fix/opencode-2.2.1-provider

Conversation

@mattzcarey

Copy link
Copy Markdown
Member

Redoes #2767: moves agents/harness/opencode, agents/models/opencode and the OpenCode example to opencode 2.2.1. Draft until we replace the gitlab-ai-provider carrier with a proper way to supply the Cloudflare provider.

  • @opencode/core 2.2.1 no longer bundles @ai-sdk/vercel. OpenCode loaded that package in-process for us, and our language hook then swapped in our model (packages/agents/src/models/opencode/index.ts).
  • Any package OpenCode doesn't bundle goes to its npm installer, which can't run in workerd. On 2.2.1 every turn fails with provider.no-route.
  • For now this PR names gitlab-ai-provider, which works only because OpenCode's GitLab plugin loads it for any provider that names it. Using a GitLab package to carry Cloudflare models is a hack and depends on OpenCode internals. What we need is a way to supply an AI SDK model from a plugin without going through OpenCode's package loader.

Stacked on #2775 (the revert). Validated so far, with the current carrier: harness and model tests on 2.2.1 and 2.0.24, and a deployed Worker on the agents account running Workers AI, openai/gpt-5.5 and anthropic/claude-opus-4.8 through AI Gateway, including tool calls.

mattzcarey and others added 2 commits October 29, 2026 18:11
* fix(agents): upgrade opencode to 2.2.1

Move the @opencode/sdk and @opencode/plugin dev and example pins from
2.0.24 to 2.2.1 and regenerate pnpm-lock.yaml.

@opencode/core 2.2.1 no longer bundles @ai-sdk/vercel, the package
agents/models/opencode named so OpenCode loads it in-process; every turn
failed with provider.no-route. The provider now names gitlab-ai-provider,
which OpenCode 2.0.24 to 2.2.1 all load in-process. Peer range unchanged.

The Effect 4.0.1 Scalar stub path moves in the test config and example,
and the test config swaps OpenCode's 8 MB models.dev catalog for an
empty one so the test runtime can load it.

Supersedes #2725.

Gardener-Operation: op_01cd0a42d8cacef705791a2563f399f6f2ecfd9e224ab4bd67b0ca9942cc803e:90fbc03809c64d97ed870f4c44c25e8147b472a47fb479caa9877d85e9ebfa36

* docs(changeset): link the OpenCode example README from the carrier changeset

Gardener-Operation: op_1437d3ebe8d4d6923fc425988e7a04f125ee356ea2fef9384556708b30267bee:0f48d6f725a39c5bec490ab674abd418b4e3df574a103736d9e1c5b30863386a

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@changeset-bot

changeset-bot Bot commented Oct 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a974f5c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
agents Patch
@cloudflare/agent-think Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Oct 29, 2026

Copy link
Copy Markdown

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@2776

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@2776

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@2776

hono-agents

npm i https://pkg.pr.new/hono-agents@2776

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@2776

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@2776

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@2776

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@2776

commit: a974f5c

Base automatically changed from revert/2767-opencode-2.2.1 to main October 29, 2026 18:14
@mattzcarey

mattzcarey commented Oct 29, 2026 •

Copy link
Copy Markdown
Member Author

We're holding this until OpenCode lets a plugin supply its own AI SDK provider. We don't want to ship Cloudflare models carried by gitlab-ai-provider.

Why we can't do it today, on opencode 2.2.1 and main:

  • sdk hooks run in the order plugins register. OpenCode's built-in DynamicProviderPlugin comes before external plugins, so any package no built-in hook claims goes to its npm installer before our hook runs. That installer can't run in workerd, and on workerd importModule always rejects, so file:// doesn't work either.
  • Only two built-in hooks load packages in-process: gitlab-ai-provider and @ai-sdk/github-copilot.

What we'll ship once OpenCode runs the npm loader as a fallback, after plugin hooks:

const CARRIER_PACKAGE = "aisdk:agents/models/opencode";

await ctx.aisdk.hook("sdk", (event) => {
  event.sdk = {
    languageModel: (id: string) =>
      asLanguageModelV3(aiSdk.languageModel(id, models.get(id)))
  };
}, { providerID });

To test it, I ran this against opencode 2.2.1 with DynamicProviderPlugin removed from the built-in list:

  • Harness tests: 31/31. Model tests: 5/5.
  • Deployed Worker on the agents account: Workers AI, openai/gpt-5.5 and anthropic/claude-opus-4.8 all passed, including tool calls, through the default AI Gateway.

Until then, users on opencode 2.2.1 get provider.no-route from agents/models/opencode. Users on 2.0.24 through 2.2.0 are fine, because those releases still bundle @ai-sdk/vercel.

@mattzcarey

Copy link
Copy Markdown
Member Author

Tracking the OpenCode change we need in #2777.

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.

1 participant