summaryrefslogtreecommitdiffhomepage
path: root/packages/plugin/src
diff options
context:
space:
mode:
authorZack Jackson <[email protected]>2025-09-09 04:25:04 +0800
committerGitHub <[email protected]>2025-09-08 16:25:04 -0400
commitab3c22b77add395c4b63608c956394162d1ae0d6 (patch)
tree3aa4bd2b3cecdf2c6dcc99dfd15c6d5d4575297a /packages/plugin/src
parentf0f6e9cad7e1afe5c0899ce4db645be45c8b7748 (diff)
downloadopencode-ab3c22b77add395c4b63608c956394162d1ae0d6.tar.gz
opencode-ab3c22b77add395c4b63608c956394162d1ae0d6.zip
feat: add dynamic tool registration for plugins and external services (#2420)
Diffstat (limited to 'packages/plugin/src')
-rw-r--r--packages/plugin/src/index.ts37
1 files changed, 37 insertions, 0 deletions
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>)
+ ): 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>
}