feat(sdk-next): let embedders contribute plugins via opencode.plugin (#34356)

This commit is contained in:
Kit Langton
2026-06-28 20:30:21 -04:00
committed by GitHub
parent 6067019434
commit 53b93b6991
3 changed files with 51 additions and 1 deletions
+9 -1
View File
@@ -1,5 +1,6 @@
import { OpenCode } from "@opencode-ai/client/effect"
import { PermissionSaved } from "@opencode-ai/core/permission/saved"
import { SdkPlugins } from "@opencode-ai/core/plugin/sdk"
import { ApplicationTools } from "@opencode-ai/core/tool/application-tools"
import { createEmbeddedRoutes } from "@opencode-ai/server/routes"
import { Context, Effect, Layer, Scope } from "effect"
@@ -9,11 +10,12 @@ export const create = Effect.fn("OpenCode.create")(function* () {
const scope = yield* Scope.Scope
const memoMap = yield* Layer.makeMemoMap
const context = yield* Layer.buildWithMemoMap(
Layer.merge(ApplicationTools.layer, PermissionSaved.defaultLayer),
Layer.mergeAll(ApplicationTools.layer, PermissionSaved.defaultLayer, SdkPlugins.layer),
memoMap,
scope,
)
const tools = Context.get(context, ApplicationTools.Service)
const plugins = Context.get(context, SdkPlugins.Service)
const permissions = Context.get(context, PermissionSaved.Service)
const web = yield* Effect.acquireRelease(
Effect.sync(() =>
@@ -37,6 +39,12 @@ export const create = Effect.fn("OpenCode.create")(function* () {
return {
...client,
tools: { register: tools.register },
// The embedded host contributes plugins through the ordinary discovery flow:
// each plugin's `effect` runs inside every Location with the real
// `PluginContext`, so `ctx.agent.transform` and every other hook behave exactly
// as they do for a config-discovered plugin. Define agent profiles here at
// startup, then select one per Session with `sessions.create({ agent })`.
plugin: plugins.register,
}
})