@opencode-ai/plugin 0.9.10 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/example.js +13 -1
- package/dist/index.d.ts +5 -29
- package/dist/index.js +1 -0
- package/dist/tool.d.ts +20 -0
- package/dist/tool.js +5 -0
- package/package.json +7 -2
package/dist/example.js
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
import { tool } from "./tool";
|
|
2
|
+
export const ExamplePlugin = async (ctx) => {
|
|
2
3
|
return {
|
|
3
4
|
permission: {},
|
|
5
|
+
tool: {
|
|
6
|
+
mytool: tool({
|
|
7
|
+
description: "This is a custom tool tool",
|
|
8
|
+
args: {
|
|
9
|
+
foo: tool.schema.string().describe("foo"),
|
|
10
|
+
},
|
|
11
|
+
async execute(args) {
|
|
12
|
+
return `Hello ${args.foo}!`;
|
|
13
|
+
},
|
|
14
|
+
}),
|
|
15
|
+
},
|
|
4
16
|
async "chat.params"(_input, output) {
|
|
5
17
|
output.topP = 1;
|
|
6
18
|
},
|
package/dist/index.d.ts
CHANGED
|
@@ -1,38 +1,23 @@
|
|
|
1
1
|
import type { Event, createOpencodeClient, Project, Model, Provider, Permission, UserMessage, Part, Auth, Config } from "@opencode-ai/sdk";
|
|
2
2
|
import type { BunShell } from "./shell";
|
|
3
|
+
import { type ToolDefinition } from "./tool";
|
|
4
|
+
export * from "./tool";
|
|
3
5
|
export type PluginInput = {
|
|
4
6
|
client: ReturnType<typeof createOpencodeClient>;
|
|
5
7
|
project: Project;
|
|
6
8
|
directory: string;
|
|
7
9
|
worktree: string;
|
|
8
10
|
$: BunShell;
|
|
9
|
-
Tool: {
|
|
10
|
-
define(id: string, init: any | (() => Promise<any>)): any;
|
|
11
|
-
};
|
|
12
|
-
z: any;
|
|
13
11
|
};
|
|
14
12
|
export type Plugin = (input: PluginInput) => Promise<Hooks>;
|
|
15
|
-
export type HttpParamSpec = {
|
|
16
|
-
type: "string" | "number" | "boolean" | "array";
|
|
17
|
-
description?: string;
|
|
18
|
-
optional?: boolean;
|
|
19
|
-
items?: "string" | "number" | "boolean";
|
|
20
|
-
};
|
|
21
|
-
export type HttpToolRegistration = {
|
|
22
|
-
id: string;
|
|
23
|
-
description: string;
|
|
24
|
-
parameters: {
|
|
25
|
-
type: "object";
|
|
26
|
-
properties: Record<string, HttpParamSpec>;
|
|
27
|
-
};
|
|
28
|
-
callbackUrl: string;
|
|
29
|
-
headers?: Record<string, string>;
|
|
30
|
-
};
|
|
31
13
|
export interface Hooks {
|
|
32
14
|
event?: (input: {
|
|
33
15
|
event: Event;
|
|
34
16
|
}) => Promise<void>;
|
|
35
17
|
config?: (input: Config) => Promise<void>;
|
|
18
|
+
tool?: {
|
|
19
|
+
[key: string]: ToolDefinition;
|
|
20
|
+
};
|
|
36
21
|
auth?: {
|
|
37
22
|
provider: string;
|
|
38
23
|
loader?: (auth: () => Promise<Auth>, provider: Provider) => Promise<Record<string, any>>;
|
|
@@ -112,13 +97,4 @@ export interface Hooks {
|
|
|
112
97
|
output: string;
|
|
113
98
|
metadata: any;
|
|
114
99
|
}) => Promise<void>;
|
|
115
|
-
/**
|
|
116
|
-
* Allow plugins to register additional tools with the server.
|
|
117
|
-
* Use registerHTTP to add a tool that calls back to your plugin/service.
|
|
118
|
-
* Use register to add a native/local tool with direct function execution.
|
|
119
|
-
*/
|
|
120
|
-
"tool.register"?: (input: {}, output: {
|
|
121
|
-
registerHTTP: (tool: HttpToolRegistration) => void | Promise<void>;
|
|
122
|
-
register: (tool: any) => void | Promise<void>;
|
|
123
|
-
}) => Promise<void>;
|
|
124
100
|
}
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./tool";
|
package/dist/tool.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
export type ToolContext = {
|
|
3
|
+
sessionID: string;
|
|
4
|
+
messageID: string;
|
|
5
|
+
agent: string;
|
|
6
|
+
abort: AbortSignal;
|
|
7
|
+
};
|
|
8
|
+
export declare function tool<Args extends z.ZodRawShape>(input: {
|
|
9
|
+
description: string;
|
|
10
|
+
args: Args;
|
|
11
|
+
execute(args: z.infer<z.ZodObject<Args>>, context: ToolContext): Promise<string>;
|
|
12
|
+
}): {
|
|
13
|
+
description: string;
|
|
14
|
+
args: Args;
|
|
15
|
+
execute(args: z.infer<z.ZodObject<Args>>, context: ToolContext): Promise<string>;
|
|
16
|
+
};
|
|
17
|
+
export declare namespace tool {
|
|
18
|
+
var schema: typeof z;
|
|
19
|
+
}
|
|
20
|
+
export type ToolDefinition = ReturnType<typeof tool>;
|
package/dist/tool.js
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@opencode-ai/plugin",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.10.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"typecheck": "tsc --noEmit"
|
|
@@ -10,13 +10,18 @@
|
|
|
10
10
|
".": {
|
|
11
11
|
"development": "./src/index.ts",
|
|
12
12
|
"import": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./tool": {
|
|
15
|
+
"development": "./src/tool.ts",
|
|
16
|
+
"import": "./dist/tool.js"
|
|
13
17
|
}
|
|
14
18
|
},
|
|
15
19
|
"files": [
|
|
16
20
|
"dist"
|
|
17
21
|
],
|
|
18
22
|
"dependencies": {
|
|
19
|
-
"@opencode-ai/sdk": "0.
|
|
23
|
+
"@opencode-ai/sdk": "0.10.0",
|
|
24
|
+
"zod": "4.1.8"
|
|
20
25
|
},
|
|
21
26
|
"devDependencies": {
|
|
22
27
|
"@tsconfig/node22": "22.0.2",
|