@open1s/ezbos 1.0.5 → 1.1.1

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.js CHANGED
@@ -30,9 +30,6 @@ export class ToolBuilder {
30
30
  handle(callback) {
31
31
  const isAsync = callback.constructor.name === 'AsyncFunction' ||
32
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
33
  const properties = {};
37
34
  for (const [key, spec] of Object.entries(this._params)) {
38
35
  properties[key] = { type: spec.type };
@@ -46,13 +43,10 @@ export class ToolBuilder {
46
43
  properties,
47
44
  required: this._required.length > 0 ? this._required : Object.keys(this._params)
48
45
  };
49
- const wrappedCallback = (rawArgs) => {
46
+ const wrappedCallback = async (rawArgs) => {
50
47
  try {
51
48
  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
- }
49
+ const result = await callback(args);
56
50
  if (isErrorResult(result))
57
51
  return 'Error: ' + (result.error || 'Unknown error');
58
52
  if (result === undefined)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open1s/ezbos",
3
- "version": "1.0.5",
3
+ "version": "1.1.1",
4
4
  "description": "Simple BrainOS - Easy wrapper for @open1s/jsbos",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -38,7 +38,7 @@
38
38
  ],
39
39
  "license": "MIT",
40
40
  "dependencies": {
41
- "@open1s/jsbos": "^2.2.4"
41
+ "@open1s/jsbos": "^2.2.6"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@modelcontextprotocol/sdk": "^1.29.0",
@@ -0,0 +1,42 @@
1
+ import { describe, it } from 'node:test';
2
+ import assert from 'node:assert';
3
+ import { BrainOS } from '../index.js';
4
+
5
+ describe('AgentBuilder.stop()', () => {
6
+ it('should call stop on inner agent without error', async () => {
7
+ const brain = new BrainOS();
8
+ await brain.start();
9
+
10
+ const builder = brain.agent('test-stop');
11
+ const agent = await builder.start();
12
+
13
+ builder.stop();
14
+
15
+ await agent.close();
16
+ await brain.stop();
17
+ });
18
+
19
+ it('should handle stop when no inner agent', async () => {
20
+ const brain = new BrainOS();
21
+ await brain.start();
22
+
23
+ const builder = brain.agent('test-stop-empty');
24
+ builder.stop();
25
+ builder.stop();
26
+
27
+ await brain.stop();
28
+ });
29
+
30
+ it('should stop after start and allow close', async () => {
31
+ const brain = new BrainOS();
32
+ await brain.start();
33
+
34
+ const builder = brain.agent('test-stop-stream');
35
+ const agent = await builder.start();
36
+
37
+ builder.stop();
38
+ await agent.close();
39
+
40
+ await brain.stop();
41
+ });
42
+ });
package/src/agent.ts CHANGED
@@ -403,7 +403,12 @@ export class Agent {
403
403
  this._inner.resetPerfMetrics();
404
404
  }
405
405
 
406
+ async stop(): Promise<void> {
407
+ this._inner.stop();
408
+ }
409
+
406
410
  async close(): Promise<void> {
411
+ this._inner.stop();
407
412
  this._inner.close();
408
413
  }
409
414
  }
package/src/tool.ts CHANGED
@@ -57,9 +57,6 @@ export class ToolBuilder {
57
57
  handle(callback: (args: Record<string, any>) => any): InternalToolDef {
58
58
  const isAsync = callback.constructor.name === 'AsyncFunction' ||
59
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
60
 
64
61
  const properties: Record<string, any> = {};
65
62
  for (const [key, spec] of Object.entries(this._params)) {
@@ -74,14 +71,10 @@ export class ToolBuilder {
74
71
  required: this._required.length > 0 ? this._required : Object.keys(this._params)
75
72
  };
76
73
 
77
- const wrappedCallback = (rawArgs: any): string => {
74
+ const wrappedCallback = async (rawArgs: any): Promise<string> => {
78
75
  try {
79
76
  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
- }
77
+ const result = await callback(args);
85
78
 
86
79
  if (isErrorResult(result)) return 'Error: ' + (result.error || 'Unknown error');
87
80
  if (result === undefined) return '';