@open1s/ezbos 1.0.2 → 1.0.3

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/tool.d.ts ADDED
@@ -0,0 +1,34 @@
1
+ import * as jsbos from '@open1s/jsbos';
2
+ export interface ToolResult {
3
+ success: boolean;
4
+ data?: any;
5
+ error?: string;
6
+ metadata?: Record<string, any>;
7
+ }
8
+ export declare function ok(data: any, metadata?: Record<string, any>): ToolResult;
9
+ export declare function err(error: string, metadata?: Record<string, any>): ToolResult;
10
+ export declare function isErrorResult(result: any): result is ToolResult;
11
+ export interface ToolParam {
12
+ type: 'string' | 'number' | 'boolean' | 'object' | 'array';
13
+ description?: string;
14
+ default?: any;
15
+ }
16
+ export interface InternalToolDef {
17
+ name: string;
18
+ description: string;
19
+ schema: Record<string, any>;
20
+ callback: (args: Record<string, any>) => string | Promise<string>;
21
+ }
22
+ export { jsbos };
23
+ export declare class ToolBuilder {
24
+ private _name;
25
+ private _description;
26
+ private _params;
27
+ private _required;
28
+ constructor(_name: string, _description: string);
29
+ param(name: string, type: ToolParam['type'], description?: string, defaultValue?: any): this;
30
+ required(name: string, type: ToolParam['type'], description?: string): this;
31
+ handle(callback: (args: Record<string, any>) => any): InternalToolDef;
32
+ }
33
+ export declare function defineTool(name: string, description: string): ToolBuilder;
34
+ export declare function tool(name: string, description: string, callback: (args: any) => any): InternalToolDef;
package/dist/tool.js ADDED
@@ -0,0 +1,81 @@
1
+ import * as jsbos from '@open1s/jsbos';
2
+ export function ok(data, metadata) {
3
+ return { success: true, data, metadata };
4
+ }
5
+ export function err(error, metadata) {
6
+ return { success: false, error, metadata };
7
+ }
8
+ export function isErrorResult(result) {
9
+ return result && typeof result.success === 'boolean' && !result.success;
10
+ }
11
+ export { jsbos };
12
+ export class ToolBuilder {
13
+ _name;
14
+ _description;
15
+ _params = {};
16
+ _required = [];
17
+ constructor(_name, _description) {
18
+ this._name = _name;
19
+ this._description = _description;
20
+ }
21
+ param(name, type, description, defaultValue) {
22
+ this._params[name] = { type, description, default: defaultValue };
23
+ return this;
24
+ }
25
+ required(name, type, description) {
26
+ this._params[name] = { type, description };
27
+ this._required.push(name);
28
+ return this;
29
+ }
30
+ handle(callback) {
31
+ const isAsync = callback.constructor.name === 'AsyncFunction' ||
32
+ callback.toString().startsWith('async ');
33
+ if (isAsync) {
34
+ throw new Error(`Tool "${this._name}" uses an async callback, but jsbos does not support async tool callbacks. Please use a synchronous callback instead.`);
35
+ }
36
+ const properties = {};
37
+ for (const [key, spec] of Object.entries(this._params)) {
38
+ properties[key] = { type: spec.type };
39
+ if (spec.description)
40
+ properties[key].description = spec.description;
41
+ if (spec.default !== undefined)
42
+ properties[key].default = spec.default;
43
+ }
44
+ const schema = {
45
+ type: 'object',
46
+ properties,
47
+ required: this._required.length > 0 ? this._required : Object.keys(this._params)
48
+ };
49
+ const wrappedCallback = (rawArgs) => {
50
+ try {
51
+ const args = typeof rawArgs === 'string' ? JSON.parse(rawArgs) : rawArgs;
52
+ const result = callback(args);
53
+ if (result instanceof Promise) {
54
+ throw new Error('Async tool callbacks are not supported. Use a sync callback instead.');
55
+ }
56
+ if (isErrorResult(result))
57
+ return 'Error: ' + (result.error || 'Unknown error');
58
+ if (result === undefined)
59
+ return '';
60
+ if (typeof result === 'string')
61
+ return result;
62
+ return JSON.stringify(result);
63
+ }
64
+ catch (e) {
65
+ return 'Error: ' + (e.message || String(e));
66
+ }
67
+ };
68
+ return {
69
+ name: this._name,
70
+ description: this._description,
71
+ schema,
72
+ callback: wrappedCallback
73
+ };
74
+ }
75
+ }
76
+ export function defineTool(name, description) {
77
+ return new ToolBuilder(name, description);
78
+ }
79
+ export function tool(name, description, callback) {
80
+ return new ToolBuilder(name, description).handle(callback);
81
+ }
@@ -0,0 +1,18 @@
1
+ import { HookEvent, HookDecision, PluginToolCallInfo } from '@open1s/jsbos';
2
+ export { HookEvent, HookDecision };
3
+ export type { PluginToolCallInfo };
4
+ export interface ToolParamSchema {
5
+ type: 'string' | 'number' | 'boolean' | 'object' | 'array';
6
+ description?: string;
7
+ default?: any;
8
+ required?: boolean;
9
+ }
10
+ export interface ToolResult {
11
+ success: boolean;
12
+ data?: any;
13
+ error?: string;
14
+ metadata?: Record<string, any>;
15
+ }
16
+ export declare function ok(data: any, metadata?: Record<string, any>): ToolResult;
17
+ export declare function err(error: string, metadata?: Record<string, any>): ToolResult;
18
+ export declare function isErrorResult(result: any): result is ToolResult;
package/dist/types.js ADDED
@@ -0,0 +1,9 @@
1
+ export function ok(data, metadata) {
2
+ return { success: true, data, metadata };
3
+ }
4
+ export function err(error, metadata) {
5
+ return { success: false, error, metadata };
6
+ }
7
+ export function isErrorResult(result) {
8
+ return result && typeof result.success === 'boolean' && !result.success;
9
+ }
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@open1s/ezbos",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Simple BrainOS - Easy wrapper for @open1s/jsbos",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",
9
+ "files": ["dist", "src", "skills"],
9
10
  "exports": {
10
11
  ".": {
11
12
  "import": "./dist/index.js",
@@ -1,34 +0,0 @@
1
- name: CI
2
-
3
- on:
4
- push:
5
- branches: [main]
6
- pull_request:
7
- branches: [main]
8
-
9
- jobs:
10
- build:
11
- runs-on: ubuntu-latest
12
-
13
- strategy:
14
- matrix:
15
- node-version: [20, 22]
16
-
17
- steps:
18
- - uses: actions/checkout@v4
19
-
20
- - name: Use Node.js ${{ matrix.node-version }}
21
- uses: actions/setup-node@v4
22
- with:
23
- node-version: ${{ matrix.node-version }}
24
-
25
- - name: Install dependencies
26
- run: npm ci
27
-
28
- - name: Build
29
- run: npm run build
30
-
31
- - name: Verify dist
32
- run: |
33
- test -f dist/index.js
34
- test -f dist/index.d.ts
@@ -1,33 +0,0 @@
1
- name: Publish
2
-
3
- on:
4
- release:
5
- types: [published]
6
-
7
- jobs:
8
- publish:
9
- runs-on: ubuntu-latest
10
-
11
- permissions:
12
- contents: read
13
- packages: write
14
-
15
- steps:
16
- - uses: actions/checkout@v4
17
-
18
- - name: Use Node.js
19
- uses: actions/setup-node@v4
20
- with:
21
- node-version: 20
22
- registry-url: 'https://registry.npmjs.org'
23
-
24
- - name: Install dependencies
25
- run: npm ci
26
-
27
- - name: Build
28
- run: npm run build
29
-
30
- - name: Publish to npm
31
- run: npm publish --access public
32
- env:
33
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}