mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-23 10:44:21 +01:00
feat: add dynamic tool registration for plugins and external services (#2420)
This commit is contained in:
@@ -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>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user