feat(plugin): support plugin-provided tools (#34619)
This commit is contained in:
@@ -1,7 +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"
|
||||
import { FetchHttpClient, HttpRouter, HttpServer } from "effect/unstable/http"
|
||||
@@ -9,18 +8,18 @@ import { FetchHttpClient, HttpRouter, HttpServer } from "effect/unstable/http"
|
||||
export const create = Effect.fn("OpenCode.create")(function* () {
|
||||
const scope = yield* Scope.Scope
|
||||
const memoMap = yield* Layer.makeMemoMap
|
||||
const sdkPlugins = SdkPlugins.makeStore()
|
||||
const context = yield* Layer.buildWithMemoMap(
|
||||
Layer.mergeAll(ApplicationTools.layer, PermissionSaved.defaultLayer, SdkPlugins.layer),
|
||||
Layer.mergeAll(PermissionSaved.defaultLayer, SdkPlugins.layerWithStore(sdkPlugins)),
|
||||
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(() =>
|
||||
HttpRouter.toWebHandler(
|
||||
createEmbeddedRoutes().pipe(
|
||||
createEmbeddedRoutes(sdkPlugins).pipe(
|
||||
HttpRouter.provideRequest(Layer.succeed(PermissionSaved.Service, permissions)),
|
||||
Layer.provide(HttpServer.layerServices),
|
||||
),
|
||||
@@ -38,7 +37,8 @@ export const create = Effect.fn("OpenCode.create")(function* () {
|
||||
)
|
||||
return {
|
||||
...client,
|
||||
tools: { register: tools.register },
|
||||
sessions: client.session,
|
||||
events: client.event,
|
||||
// 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
|
||||
|
||||
Reference in New Issue
Block a user