From ab3c22b77add395c4b63608c956394162d1ae0d6 Mon Sep 17 00:00:00 2001 From: Zack Jackson <25274700+ScriptedAlchemy@users.noreply.github.com> Date: Tue, 9 Sep 2025 04:25:04 +0800 Subject: feat: add dynamic tool registration for plugins and external services (#2420) --- packages/plugin/src/index.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'packages/plugin/src') diff --git a/packages/plugin/src/index.ts b/packages/plugin/src/index.ts index a00b48d10..fca176f57 100644 --- a/packages/plugin/src/index.ts +++ b/packages/plugin/src/index.ts @@ -18,9 +18,34 @@ 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 interface Hooks { event?: (input: { event: Event }) => Promise config?: (input: Config) => Promise @@ -99,4 +124,16 @@ 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