Uh oh!
There was an error while loading. Please reload this page.
feat(plugin): provide SDK v2 - #12042
Conversation
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
The following comment was made by an LLM, it may be inaccurate: Based on my search, I found one potentially related PR: PR #8380: feat(plugin): use SDK v2
This PR appears to be related as it addresses the same feature (SDK v2 plugin support). You may want to review its status and any discussion to understand how it relates to the current PR #12042. |
eXamadeus
commented
Feb 4, 2026
The bot is right, it's the same PR. I changed base repos so I can maintain my fork easier. |
Until this is merged, I have found a very hacky solution: import{OpencodeClientasV2OpencodeClient}from"@opencode-ai/sdk/v2";typeV2CtorInput=NonNullable<ConstructorParameters<typeofV2OpencodeClient>[0]>;typeV2RawClient=V2CtorInput["client"];functionisRecord(value: unknown): value is Record<string,unknown>{returntypeofvalue==="object"&&value!==null;}functiongetSharedRawClient(value: unknown): V2RawClient|undefined{if(!isRecord(value)){returnundefined;}constrawClient=value["_client"];if(!isRecord(rawClient)){returnundefined;}returnrawClientasV2RawClient;}/** * Attempts to extract a v2 OpencodeClient from plugin context client. * * The plugin system currently exposes v1 client structure which contains * an internal `_client` property. This helper bridges to v2 by wrapping * that raw client in a v2 OpencodeClient instance. * * @param client - Plugin ctx.client (v1 structure, unknown shape) * @returns v2 OpencodeClient instance, or undefined if extraction fails * * @deprecated Remove once plugin context exposes native v2 client directly. */exportfunctionunstable_getV2Client(client: unknown,): V2OpencodeClient|undefined{constrawClient=getSharedRawClient(client);if(!rawClient){returnundefined;}try{returnnewV2OpencodeClient({client: rawClient});}catch{returnundefined;}}This then enables stuff like auto-rejecting tools with a message if I am away: awaitv2Client.permission.reply({requestID: permissionID,reply: "reject",
message,}); |
a79486a to
09bc1e9Compare73d7d85 to
9474209CompareThe v2 SDK types `fetch` as `typeof fetch` which includes Bun's static `preconnect` property and the two-argument overload. Hono's .fetch() only accepts Request. Functionally compatible at runtime.
BugNotFoundX
commented
Apr 20, 2026
Is there any progress |
eXamadeus
commented
Apr 22, 2026
I was told the goal of the maintainers is to focus on V2 for OpenCode which will fix the SDK issues. It's likely this won't ever merge and version 2.0.0 of OpenCode will solve the SDK woes. |
What does this PR do?
Fixes#7641
Provides two SDK clients (v1 and v2) to avoid backwards-compatibility issues and allow plugin authors to utilize the latest SDK.
This keeps the original
clientintact, allowing plugin authors to adopt SDK v2 incrementally without forcing immediate migration. Breaking changes until the next major release.@aryasaatvik has closed#7639 in favor of working together on this one. Thanks for the help!
Important
This is not a breaking change. That said, we likely wouldn't want a
clientNextandclientforever. I would be glad to help plan out a full migration down the road, assuming this gets merged.How did you verify your code works?