@open1s/ezbos 1.0.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/.github/workflows/ci.yml +34 -0
- package/.github/workflows/publish.yml +33 -0
- package/.pnp.cjs +8400 -0
- package/.pnp.loader.mjs +2126 -0
- package/.yarn/install-state.gz +0 -0
- package/README.md +468 -0
- package/bun.lock +89 -0
- package/examples/00-pr.ts +1 -0
- package/examples/01-tools.ts +85 -0
- package/examples/02-hooks.ts +82 -0
- package/examples/03-plugins.ts +91 -0
- package/examples/04-mcp.ts +74 -0
- package/examples/05-skills.ts +45 -0
- package/examples/06-session.ts +72 -0
- package/examples/07-agent-advanced.ts +86 -0
- package/examples/08-brainos-messaging.ts +83 -0
- package/package.json +46 -0
- package/skills/code-review/SKILL.md +18 -0
- package/src/agent.ts +404 -0
- package/src/brainos.ts +357 -0
- package/src/hook.ts +73 -0
- package/src/index.ts +17 -0
- package/src/mcp.ts +40 -0
- package/src/plugin.ts +93 -0
- package/src/skills.ts +31 -0
- package/src/tool.ts +110 -0
- package/src/types.ts +30 -0
- package/tsconfig.json +21 -0
package/src/tool.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import * as jsbos from '@open1s/jsbos';
|
|
2
|
+
|
|
3
|
+
export interface ToolResult {
|
|
4
|
+
success: boolean;
|
|
5
|
+
data?: any;
|
|
6
|
+
error?: string;
|
|
7
|
+
metadata?: Record<string, any>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function ok(data: any, metadata?: Record<string, any>): ToolResult {
|
|
11
|
+
return { success: true, data, metadata };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function err(error: string, metadata?: Record<string, any>): ToolResult {
|
|
15
|
+
return { success: false, error, metadata };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function isErrorResult(result: any): result is ToolResult {
|
|
19
|
+
return result && typeof result.success === 'boolean' && !result.success;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ToolParam {
|
|
23
|
+
type: 'string' | 'number' | 'boolean' | 'object' | 'array';
|
|
24
|
+
description?: string;
|
|
25
|
+
default?: any;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface InternalToolDef {
|
|
29
|
+
name: string;
|
|
30
|
+
description: string;
|
|
31
|
+
schema: Record<string, any>;
|
|
32
|
+
callback: (args: Record<string, any>) => string | Promise<string>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { jsbos };
|
|
36
|
+
|
|
37
|
+
export class ToolBuilder {
|
|
38
|
+
private _params: Record<string, ToolParam> = {};
|
|
39
|
+
private _required: string[] = [];
|
|
40
|
+
|
|
41
|
+
constructor(
|
|
42
|
+
private _name: string,
|
|
43
|
+
private _description: string
|
|
44
|
+
) {}
|
|
45
|
+
|
|
46
|
+
param(name: string, type: ToolParam['type'], description?: string, defaultValue?: any): this {
|
|
47
|
+
this._params[name] = { type, description, default: defaultValue };
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
required(name: string, type: ToolParam['type'], description?: string): this {
|
|
52
|
+
this._params[name] = { type, description };
|
|
53
|
+
this._required.push(name);
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
handle(callback: (args: Record<string, any>) => any): InternalToolDef {
|
|
58
|
+
const isAsync = callback.constructor.name === 'AsyncFunction' ||
|
|
59
|
+
callback.toString().startsWith('async ');
|
|
60
|
+
if (isAsync) {
|
|
61
|
+
throw new Error(`Tool "${this._name}" uses an async callback, but jsbos does not support async tool callbacks. Please use a synchronous callback instead.`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const properties: Record<string, any> = {};
|
|
65
|
+
for (const [key, spec] of Object.entries(this._params)) {
|
|
66
|
+
properties[key] = { type: spec.type };
|
|
67
|
+
if (spec.description) properties[key].description = spec.description;
|
|
68
|
+
if (spec.default !== undefined) properties[key].default = spec.default;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const schema = {
|
|
72
|
+
type: 'object',
|
|
73
|
+
properties,
|
|
74
|
+
required: this._required.length > 0 ? this._required : Object.keys(this._params)
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const wrappedCallback = (rawArgs: any): string => {
|
|
78
|
+
try {
|
|
79
|
+
const args = typeof rawArgs === 'string' ? JSON.parse(rawArgs) : rawArgs;
|
|
80
|
+
const result = callback(args);
|
|
81
|
+
|
|
82
|
+
if (result instanceof Promise) {
|
|
83
|
+
throw new Error('Async tool callbacks are not supported. Use a sync callback instead.');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (isErrorResult(result)) return 'Error: ' + (result.error || 'Unknown error');
|
|
87
|
+
if (result === undefined) return '';
|
|
88
|
+
if (typeof result === 'string') return result;
|
|
89
|
+
return JSON.stringify(result);
|
|
90
|
+
} catch (e: any) {
|
|
91
|
+
return 'Error: ' + (e.message || String(e));
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
name: this._name,
|
|
97
|
+
description: this._description,
|
|
98
|
+
schema,
|
|
99
|
+
callback: wrappedCallback
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function defineTool(name: string, description: string): ToolBuilder {
|
|
105
|
+
return new ToolBuilder(name, description);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function tool(name: string, description: string, callback: (args: any) => any): InternalToolDef {
|
|
109
|
+
return new ToolBuilder(name, description).handle(callback);
|
|
110
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { HookEvent, HookDecision, PluginToolCallInfo } from '@open1s/jsbos';
|
|
2
|
+
|
|
3
|
+
export { HookEvent, HookDecision };
|
|
4
|
+
export type { PluginToolCallInfo };
|
|
5
|
+
|
|
6
|
+
export interface ToolParamSchema {
|
|
7
|
+
type: 'string' | 'number' | 'boolean' | 'object' | 'array';
|
|
8
|
+
description?: string;
|
|
9
|
+
default?: any;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ToolResult {
|
|
14
|
+
success: boolean;
|
|
15
|
+
data?: any;
|
|
16
|
+
error?: string;
|
|
17
|
+
metadata?: Record<string, any>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function ok(data: any, metadata?: Record<string, any>): ToolResult {
|
|
21
|
+
return { success: true, data, metadata };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function err(error: string, metadata?: Record<string, any>): ToolResult {
|
|
25
|
+
return { success: false, error, metadata };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function isErrorResult(result: any): result is ToolResult {
|
|
29
|
+
return result && typeof result.success === 'boolean' && !result.success;
|
|
30
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ES2022",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"ignoreDeprecations": "6.0",
|
|
7
|
+
"lib": ["ES2022"],
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"outDir": "./dist",
|
|
10
|
+
"rootDir": "./src",
|
|
11
|
+
"strict": true,
|
|
12
|
+
"experimentalDecorators": true,
|
|
13
|
+
"emitDecoratorMetadata": true,
|
|
14
|
+
"esModuleInterop": true,
|
|
15
|
+
"skipLibCheck": true,
|
|
16
|
+
"forceConsistentCasingInFileNames": true,
|
|
17
|
+
"types": ["node"]
|
|
18
|
+
},
|
|
19
|
+
"include": ["src/**/*"],
|
|
20
|
+
"exclude": ["node_modules", "dist"]
|
|
21
|
+
}
|