@olane/o-tool 0.8.2 → 0.8.4

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.
Files changed (2) hide show
  1. package/README.md +72 -20
  2. package/package.json +6 -6
package/README.md CHANGED
@@ -20,7 +20,7 @@ The tool system layer of Olane OS. Transform generalist LLMs into specialists th
20
20
  ## Installation
21
21
 
22
22
  ```bash
23
- npm install @olane/o-tool
23
+ pnpm install @olane/o-tool
24
24
  ```
25
25
 
26
26
  ## Quick Start
@@ -65,7 +65,9 @@ const response = await calculator.use({
65
65
  params: { a: 5, b: 3 }
66
66
  });
67
67
 
68
- console.log(response.result); // { result: 8 }
68
+ // response.result.success === true
69
+ // response.result.data contains the tool's return value
70
+ console.log(response.result.data); // { result: 8 }
69
71
  ```
70
72
 
71
73
  ### Using the Mixin Pattern
@@ -156,14 +158,48 @@ Parameter validation happens automatically before tool execution:
156
158
 
157
159
  ```typescript
158
160
  // Missing required parameters trigger clear errors
159
- try {
160
- await tool.use({ method: 'add', params: { a: 5 } });
161
- } catch (error) {
161
+ const response = await tool.use({ method: 'add', params: { a: 5 } });
162
+
163
+ if (!response.result.success) {
162
164
  // Error: Missing required parameters: ["b"]
163
- console.log(error.message);
165
+ console.log(response.result.error);
164
166
  }
165
167
  ```
166
168
 
169
+ ### Response Structure
170
+
171
+ When calling tools via `node.use()`, responses follow a standard wrapped structure:
172
+
173
+ ```typescript
174
+ {
175
+ jsonrpc: "2.0",
176
+ id: "request-id",
177
+ result: {
178
+ success: boolean, // Whether the call succeeded
179
+ data: any, // The return value on success
180
+ error?: string // Error message on failure
181
+ }
182
+ }
183
+ ```
184
+
185
+ Always access response fields through the `result` property:
186
+
187
+ ```typescript
188
+ const response = await tool.use(tool.address, {
189
+ method: 'some_method',
190
+ params: { /* ... */ }
191
+ });
192
+
193
+ // Check success
194
+ if (response.result.success) {
195
+ const data = response.result.data; // Access return value
196
+ } else {
197
+ const error = response.result.error; // Access error message
198
+ }
199
+ ```
200
+
201
+ > **Common mistake**: Accessing `response.success` or `response.data` directly will not work. Always use `response.result.success`, `response.result.data`, and `response.result.error`.
202
+
167
203
  ## Examples
168
204
 
169
205
  ### Search Tool with Vector Store Integration
@@ -238,12 +274,16 @@ class AdvancedCalculatorTool extends oToolBase {
238
274
 
239
275
  async _tool_complex_calculation(request: oRequest): Promise<ToolResult> {
240
276
  // Can leverage parent tool capabilities
241
- const result = await this.use(new oAddress('o://calculator'), {
277
+ const response = await this.use(new oAddress('o://calculator'), {
242
278
  method: 'add',
243
279
  params: { a: 10, b: 20 }
244
280
  });
245
-
246
- return { result: result.result * 2 };
281
+
282
+ if (!response.result.success) {
283
+ throw new Error(response.result.error);
284
+ }
285
+
286
+ return { result: response.result.data.result * 2 };
247
287
  }
248
288
  }
249
289
  ```
@@ -352,29 +392,41 @@ async _tool_divide(request: oRequest): Promise<ToolResult> {
352
392
 
353
393
  ## Testing
354
394
 
395
+ This project uses Mocha/Chai via [aegir](https://github.com/ipfs/aegir) for testing. Do not use Jest.
396
+
355
397
  ```typescript
398
+ import { expect } from 'aegir/chai';
356
399
  import { oRequest } from '@olane/o-core';
357
400
 
358
401
  describe('CalculatorTool', () => {
359
402
  let tool: CalculatorTool;
360
-
361
- beforeEach(async () => {
403
+
404
+ before(async () => {
362
405
  tool = new CalculatorTool();
363
406
  await tool.start();
364
407
  });
365
-
408
+
366
409
  it('should add two numbers', async () => {
367
- const request = new oRequest({
410
+ const response = await tool.use(tool.address, {
368
411
  method: 'add',
369
- params: { a: 5, b: 3 },
370
- id: '123'
412
+ params: { a: 5, b: 3 }
371
413
  });
372
-
373
- const result = await tool.callMyTool(request);
374
- expect(result.result).toBe(8);
414
+
415
+ expect(response.result.success).to.be.true;
416
+ expect(response.result.data.result).to.equal(8);
375
417
  });
376
-
377
- afterEach(async () => {
418
+
419
+ it('should return error for missing params', async () => {
420
+ const response = await tool.use(tool.address, {
421
+ method: 'add',
422
+ params: { a: 5 }
423
+ });
424
+
425
+ expect(response.result.success).to.be.false;
426
+ expect(response.result.error).to.exist;
427
+ });
428
+
429
+ after(async () => {
378
430
  await tool.stop();
379
431
  });
380
432
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@olane/o-tool",
3
- "version": "0.8.2",
3
+ "version": "0.8.4",
4
4
  "type": "module",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "test:browser": "aegir test -t browser",
23
23
  "build": "rm -rf dist && tsc",
24
24
  "start:prod": "node dist/index.js",
25
- "prepublishOnly": "npm run build",
25
+ "prepublishOnly": "pnpm run build",
26
26
  "lint": "aegir lint"
27
27
  },
28
28
  "repository": {
@@ -54,11 +54,11 @@
54
54
  "typescript": "^5.8.3"
55
55
  },
56
56
  "dependencies": {
57
- "@olane/o-config": "0.8.2",
58
- "@olane/o-core": "0.8.2",
59
- "@olane/o-protocol": "0.8.2",
57
+ "@olane/o-config": "0.8.4",
58
+ "@olane/o-core": "0.8.4",
59
+ "@olane/o-protocol": "0.8.4",
60
60
  "debug": "^4.4.1",
61
61
  "dotenv": "^16.5.0"
62
62
  },
63
- "gitHead": "9e35c874d849d051bcffe483fd2a8c2b3ecf68cc"
63
+ "gitHead": "b53623b1ad4365133911722f80d5597a72b65bf2"
64
64
  }