From 3b6c0ec0b3b4f2224311888d8f7be178ed2335da Mon Sep 17 00:00:00 2001 From: Dax Date: Thu, 18 Sep 2025 03:58:21 -0400 Subject: support custom tools (#2668) --- packages/plugin/src/index.ts | 42 ++++++++---------------------------------- 1 file changed, 8 insertions(+), 34 deletions(-) (limited to 'packages/plugin/src/index.ts') diff --git a/packages/plugin/src/index.ts b/packages/plugin/src/index.ts index f8b6d46f7..9c2647c60 100644 --- a/packages/plugin/src/index.ts +++ b/packages/plugin/src/index.ts @@ -10,7 +10,11 @@ import type { Auth, Config, } from "@opencode-ai/sdk" + import type { BunShell } from "./shell" +import { type ToolDefinition } from "./tool" + +export * from "./tool" export type PluginInput = { client: ReturnType @@ -18,34 +22,16 @@ export type PluginInput = { directory: string worktree: string $: BunShell - Tool: { - define(id: string, init: any | (() => Promise)): any - } - z: any // Zod instance for creating schemas } -export type Plugin = (input: PluginInput) => Promise -// Lightweight schema spec for HTTP-registered tools -export type HttpParamSpec = { - type: "string" | "number" | "boolean" | "array" - description?: string - optional?: boolean - items?: "string" | "number" | "boolean" -} -export type HttpToolRegistration = { - id: string - description: string - parameters: { - type: "object" - properties: Record - } - callbackUrl: string - headers?: Record -} +export type Plugin = (input: PluginInput) => Promise export interface Hooks { event?: (input: { event: Event }) => Promise config?: (input: Config) => Promise + tool?: { + [key: string]: ToolDefinition + } auth?: { provider: string loader?: (auth: () => Promise, provider: Provider) => Promise> @@ -121,16 +107,4 @@ export interface Hooks { metadata: any }, ) => Promise - /** - * Allow plugins to register additional tools with the server. - * Use registerHTTP to add a tool that calls back to your plugin/service. - * Use register to add a native/local tool with direct function execution. - */ - "tool.register"?: ( - input: {}, - output: { - registerHTTP: (tool: HttpToolRegistration) => void | Promise - register: (tool: any) => void | Promise // Tool.Info type from opencode - }, - ) => Promise } -- cgit v1.2.3