feat: add dynamic tool registration for plugins and external services (#2420)

This commit is contained in:
Zack Jackson
2025-09-09 04:25:04 +08:00
committed by GitHub
parent f0f6e9cad7
commit ab3c22b77a
7 changed files with 727 additions and 12 deletions

View File

@@ -18,9 +18,34 @@ export type PluginInput = {
directory: string
worktree: string
$: BunShell
Tool: {
define(
id: string,
init: any | (() => Promise<any>)
): any
}
z: any // Zod instance for creating schemas
}
export type Plugin = (input: PluginInput) => Promise<Hooks>
// 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<string, HttpParamSpec>
}
callbackUrl: string
headers?: Record<string, string>
}
export interface Hooks {
event?: (input: { event: Event }) => Promise<void>
config?: (input: Config) => Promise<void>
@@ -99,4 +124,16 @@ export interface Hooks {
metadata: any
},
) => Promise<void>
/**
* 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<void>
register: (tool: any) => void | Promise<void> // Tool.Info type from opencode
},
) => Promise<void>
}