create-donobu-plugin 1.2.1 → 1.3.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/README.md +55 -45
- package/index.js +42 -97
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -36,63 +36,73 @@ Provide the plugin name as the first argument. Names may include lowercase lette
|
|
|
36
36
|
|
|
37
37
|
## Generated project layout
|
|
38
38
|
|
|
39
|
-
| Item
|
|
40
|
-
|
|
|
41
|
-
| `package.json`
|
|
42
|
-
| `tsconfig.json`
|
|
43
|
-
| `esbuild.config.mjs`
|
|
44
|
-
| `src/index.ts`
|
|
45
|
-
| `
|
|
46
|
-
| `src/PluginDependencies.ts` | Strongly typed view of the objects Donobu injects into your plugin (`donobu` and `playwright`). |
|
|
47
|
-
| `README.md` | Template instructions for the team that owns the generated plugin. |
|
|
39
|
+
| Item | Description |
|
|
40
|
+
| -------------------- | ------------------------------------------------------------------------------------------------------ |
|
|
41
|
+
| `package.json` | Private ESM package whose `main`/`types` fields point to `dist/`. |
|
|
42
|
+
| `tsconfig.json` | NodeNext compiler settings that emit JS + declarations into `dist/`. |
|
|
43
|
+
| `esbuild.config.mjs` | Bundles the compiled JS into `dist/index.mjs`, keeping Donobu and Playwright as external dependencies. |
|
|
44
|
+
| `src/index.ts` | Entry point that must export `loadCustomTools(dependencies)` and return an array of tools. |
|
|
45
|
+
| `README.md` | Template instructions for the team that owns the generated plugin. |
|
|
48
46
|
|
|
49
47
|
Because the scaffold reuses the Donobu versions already on disk, regenerating the project after a Donobu upgrade is the fastest way to stay in lockstep.
|
|
50
48
|
|
|
51
49
|
## Authoring tools
|
|
52
50
|
|
|
53
|
-
Every plugin exports `loadCustomTools(dependencies)` and returns an array of `Tool` instances.
|
|
51
|
+
Every plugin's `index.ts` exports `loadCustomTools(dependencies)` and returns an array of `Tool` instances.
|
|
54
52
|
|
|
55
53
|
```ts
|
|
56
|
-
//
|
|
54
|
+
// Note that non-type imports from 'donobu' should be extracted from the given
|
|
55
|
+
// 'deps.donobu' parameter in 'loadCustomTools'.
|
|
56
|
+
import type { Tool, PluginDependencies } from 'donobu';
|
|
57
57
|
import { z } from 'zod/v4';
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
58
|
+
|
|
59
|
+
export async function loadCustomTools(
|
|
60
|
+
deps: PluginDependencies
|
|
61
|
+
): Promise<Tool<any, any>[]> {
|
|
62
|
+
// Register your custom tools here.
|
|
63
|
+
return [
|
|
64
|
+
// Here is a small example tool for reference.
|
|
65
|
+
deps.donobu.createTool(deps, {
|
|
66
|
+
// The tool name, description, and schema are shared with the Donobu agent
|
|
67
|
+
// to help it decide when, where, and how this tool will be called.
|
|
68
|
+
name: 'judgeWebpageTitle',
|
|
69
|
+
description: 'Judge the quality of a title to a webpage.',
|
|
70
|
+
schema: z.object({ webpageTitle: z.string() }),
|
|
71
|
+
// This example tool uses a GPT/LLM so we call it out here.
|
|
72
|
+
requiresGpt: true,
|
|
73
|
+
call: async (context, parameters) => {
|
|
74
|
+
// 'requiredGpt' is true, so we are guaranteed a valid gptClient handle.
|
|
75
|
+
const resp = await context.gptClient!.getMessage([
|
|
76
|
+
{
|
|
77
|
+
type: 'user',
|
|
78
|
+
items: [
|
|
79
|
+
{
|
|
80
|
+
type: 'text',
|
|
81
|
+
text: `Judge the quality of this webpage title on a scale of 1 (worst) to 10 (best) and explain why.
|
|
82
|
+
Title: ${parameters.webpageTitle}`,
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
]);
|
|
87
|
+
return {
|
|
88
|
+
// Returning false or throwing an exception will signal tool call failure.
|
|
89
|
+
isSuccessful: true,
|
|
90
|
+
// This is what is shared back with the Donobu agent.
|
|
91
|
+
forLlm: resp.text,
|
|
92
|
+
// Metadata is persisted with the tool call result, but is not shared
|
|
93
|
+
// with the Donobu agent, so this can be used to store large complex data.
|
|
94
|
+
metadata: null,
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
}),
|
|
98
|
+
];
|
|
83
99
|
}
|
|
84
100
|
```
|
|
85
101
|
|
|
86
|
-
Guidelines:
|
|
87
|
-
|
|
88
|
-
- Define Zod schemas for every tool so inputs from humans or the LLM are validated before your code runs.
|
|
89
|
-
- Use `callFromGpt` if the GPT path needs different behavior; otherwise the helper routes GPT calls through `call`.
|
|
90
|
-
- Request `requiresGpt: true` only when the tool cannot run without LLM assistance.
|
|
91
|
-
|
|
92
102
|
## Working with injected dependencies
|
|
93
103
|
|
|
94
|
-
- `
|
|
95
|
-
- `
|
|
104
|
+
- `deps.donobu` exposes the public SDK: the base `Tool` class, `PlaywrightUtils`, logging helpers, type definitions, etc.
|
|
105
|
+
- `deps.playwright` points to the same Playwright build Donobu uses, so your plugin and the core runtime stay aligned.
|
|
96
106
|
- Feel free to add your own dependencies; `esbuild` bundles everything except the packages listed in `external`.
|
|
97
107
|
|
|
98
108
|
## Build and install
|
|
@@ -102,7 +112,7 @@ npm run build
|
|
|
102
112
|
npm exec install-donobu-plugin
|
|
103
113
|
```
|
|
104
114
|
|
|
105
|
-
`npm run build` cleans `dist/`, reinstalls dependencies (to ensure version parity), runs TypeScript, and bundles the result. `npm exec install-donobu-plugin` validates the current folder, infers the plugin name (prefers `package.json`, falls back to the git repo name or `$USER`), and copies `dist/` into the Donobu plugins directory. Restart Donobu after
|
|
115
|
+
`npm run build` cleans `dist/`, reinstalls dependencies (to ensure version parity), runs TypeScript, and bundles the result. `npm exec install-donobu-plugin` validates the current folder, infers the plugin name (prefers `package.json`, falls back to the git repo name or `$USER`), and copies `dist/` into the Donobu plugins directory. Restart Donobu after installing so the new bundle is loaded.
|
|
106
116
|
|
|
107
117
|
## Recommended development loop
|
|
108
118
|
|
package/index.js
CHANGED
|
@@ -154,110 +154,55 @@ await build({
|
|
|
154
154
|
await writeFile(join(pluginDir, 'esbuild.config.mjs'), esbuildConfig);
|
|
155
155
|
|
|
156
156
|
// Create src/index.ts
|
|
157
|
-
const indexTs =
|
|
158
|
-
|
|
157
|
+
const indexTs = `// Note that non-type imports from 'donobu' should be extracted from the given
|
|
158
|
+
// 'deps.donobu' parameter in 'loadCustomTools'.
|
|
159
|
+
import type { Tool, PluginDependencies } from 'donobu';
|
|
160
|
+
import { z } from 'zod/v4';
|
|
159
161
|
|
|
160
162
|
export async function loadCustomTools(
|
|
161
|
-
|
|
163
|
+
deps: PluginDependencies
|
|
162
164
|
): Promise<Tool<any, any>[]> {
|
|
163
165
|
// Register your custom tools here.
|
|
164
|
-
return [
|
|
165
|
-
|
|
166
|
-
|
|
166
|
+
return [
|
|
167
|
+
// Here is a small example tool for reference.
|
|
168
|
+
deps.donobu.createTool(deps, {
|
|
169
|
+
// The tool name, description, and schema are shared with the Donobu agent
|
|
170
|
+
// to help it decide when, where, and how this tool will be called.
|
|
171
|
+
name: 'judgeWebpageTitle',
|
|
172
|
+
description: 'Judge the quality of a title to a webpage.',
|
|
173
|
+
schema: z.object({ webpageTitle: z.string() }),
|
|
174
|
+
// This example tool uses a GPT/LLM so we call it out here.
|
|
175
|
+
requiresGpt: true,
|
|
176
|
+
call: async (context, parameters) => {
|
|
177
|
+
// 'requiredGpt' is true, so we are guaranteed a valid gptClient handle.
|
|
178
|
+
const resp = await context.gptClient!.getMessage([
|
|
179
|
+
{
|
|
180
|
+
type: 'user',
|
|
181
|
+
items: [
|
|
182
|
+
{
|
|
183
|
+
type: 'text',
|
|
184
|
+
text: \`Judge the quality of this webpage title on a scale of 1 (worst) to 10 (best) and explain why.
|
|
185
|
+
Title: ${parameters.webpageTitle}\`,
|
|
186
|
+
},
|
|
187
|
+
],
|
|
188
|
+
},
|
|
189
|
+
]);
|
|
190
|
+
return {
|
|
191
|
+
// Returning false or throwing an exception will signal tool call failure.
|
|
192
|
+
isSuccessful: true,
|
|
193
|
+
// This is what is shared back with the Donobu agent.
|
|
194
|
+
forLlm: resp.text,
|
|
195
|
+
// Metadata is persisted with the tool call result, but is not shared
|
|
196
|
+
// with the Donobu agent, so this can be used to store large complex data.
|
|
197
|
+
metadata: null,
|
|
198
|
+
};
|
|
199
|
+
},
|
|
200
|
+
}),
|
|
201
|
+
];
|
|
202
|
+
}`;
|
|
167
203
|
|
|
168
204
|
await writeFile(join(pluginDir, 'src', 'index.ts'), indexTs);
|
|
169
205
|
|
|
170
|
-
// Create src/createTool.ts
|
|
171
|
-
const createToolTs = `import { z } from "zod/v4";
|
|
172
|
-
import type { ToolCallContext, ToolCallResult, Tool } from "donobu";
|
|
173
|
-
import { PluginDependencies } from "./PluginDependencies.js";
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Factory function to create a Donobu Tool instance.
|
|
177
|
-
*/
|
|
178
|
-
export function createTool<
|
|
179
|
-
CallSchema extends z.ZodObject<any>,
|
|
180
|
-
CallFromGptSchema extends z.ZodObject<any> = CallSchema,
|
|
181
|
-
>(
|
|
182
|
-
dependencies: PluginDependencies,
|
|
183
|
-
options: CreateToolOptions<CallSchema, CallFromGptSchema>
|
|
184
|
-
): Tool<CallSchema, CallFromGptSchema> {
|
|
185
|
-
class AnonymousTool extends dependencies.donobu.Tool<
|
|
186
|
-
CallSchema,
|
|
187
|
-
CallFromGptSchema
|
|
188
|
-
> {
|
|
189
|
-
public constructor() {
|
|
190
|
-
super(
|
|
191
|
-
options.name,
|
|
192
|
-
options.description,
|
|
193
|
-
options.schema,
|
|
194
|
-
(options.gptSchema ?? options.schema) as CallFromGptSchema,
|
|
195
|
-
options.requiresGpt
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
public override async call(
|
|
199
|
-
ctx: ToolCallContext,
|
|
200
|
-
params: z.infer<CallSchema>
|
|
201
|
-
): Promise<ToolCallResult> {
|
|
202
|
-
return options.call(ctx, params);
|
|
203
|
-
}
|
|
204
|
-
public override async callFromGpt(
|
|
205
|
-
ctx: ToolCallContext,
|
|
206
|
-
params: z.infer<CallFromGptSchema>
|
|
207
|
-
): Promise<ToolCallResult> {
|
|
208
|
-
return options.callFromGpt
|
|
209
|
-
? options.callFromGpt(ctx, params)
|
|
210
|
-
: this.call(ctx, params);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
return new AnonymousTool();
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
export interface CreateToolOptions<
|
|
218
|
-
CallSchema extends z.ZodObject<any>,
|
|
219
|
-
CallFromGptSchema extends z.ZodObject<any> = CallSchema,
|
|
220
|
-
> {
|
|
221
|
-
/**
|
|
222
|
-
* @param name This is the name for the tool that will be shared with the LLM when making requests.
|
|
223
|
-
* @param description This is the description that will be shared with the LLM when making requests.
|
|
224
|
-
* @param inputSchema This is the JSON-schema for the tool when it is invoked by a non-LLM.
|
|
225
|
-
* @param inputSchemaForGpt This is the JSON-schema that will be shared with the LLM when making
|
|
226
|
-
* requests during autonomous flows.
|
|
227
|
-
* @param requiresGpt Set to true if this tool requires the usage of a GPT.
|
|
228
|
-
* @param call This is the function that will be invoked when the tool is called by a non-LLM.
|
|
229
|
-
* @param callFromGpt This is the function that will be invoked when the tool is called by an LLM.
|
|
230
|
-
*/
|
|
231
|
-
name: string;
|
|
232
|
-
description: string;
|
|
233
|
-
requiresGpt: boolean;
|
|
234
|
-
schema: CallSchema;
|
|
235
|
-
gptSchema?: CallFromGptSchema;
|
|
236
|
-
call(
|
|
237
|
-
ctx: ToolCallContext,
|
|
238
|
-
params: z.infer<CallSchema>
|
|
239
|
-
): Promise<ToolCallResult> | ToolCallResult;
|
|
240
|
-
callFromGpt?(
|
|
241
|
-
ctx: ToolCallContext,
|
|
242
|
-
params: z.infer<CallFromGptSchema>
|
|
243
|
-
): Promise<ToolCallResult> | ToolCallResult;
|
|
244
|
-
}
|
|
245
|
-
`;
|
|
246
|
-
|
|
247
|
-
await writeFile(join(pluginDir, 'src', 'createTool.ts'), createToolTs);
|
|
248
|
-
|
|
249
|
-
// Create src/PluginDependencies.ts
|
|
250
|
-
const pluginDepsTs = `export interface PluginDependencies {
|
|
251
|
-
donobu: typeof import("donobu");
|
|
252
|
-
playwright: typeof import("playwright");
|
|
253
|
-
}
|
|
254
|
-
`;
|
|
255
|
-
|
|
256
|
-
await writeFile(
|
|
257
|
-
join(pluginDir, 'src', 'PluginDependencies.ts'),
|
|
258
|
-
pluginDepsTs
|
|
259
|
-
);
|
|
260
|
-
|
|
261
206
|
// Create a basic README
|
|
262
207
|
const readme = `# ${pluginName}
|
|
263
208
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-donobu-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Create a new Donobu plugin",
|
|
6
6
|
"author": "Donobu",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"index.js"
|
|
14
14
|
],
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"donobu": "^3.
|
|
16
|
+
"donobu": "^3.4.0"
|
|
17
17
|
},
|
|
18
18
|
"keywords": [
|
|
19
19
|
"donobu",
|