@olane/o-tool 0.1.1 → 0.1.2

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/index.js CHANGED
@@ -1,25 +1,9 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./o-tool"), exports);
18
- __exportStar(require("./interfaces/tool.interface"), exports);
19
- __exportStar(require("./interfaces/run-result.interface"), exports);
20
- __exportStar(require("./interfaces/run-params.interface"), exports);
21
- __exportStar(require("./interfaces/run-tool.interface"), exports);
22
- __exportStar(require("./node.tool"), exports);
23
- __exportStar(require("./interfaces/tool-result.interface"), exports);
24
- __exportStar(require("./tool.utils"), exports);
25
- __exportStar(require("./virtual.tool"), exports);
1
+ export * from './o-tool';
2
+ export * from './interfaces/tool.interface';
3
+ export * from './interfaces/run-result.interface';
4
+ export * from './interfaces/run-params.interface';
5
+ export * from './interfaces/run-tool.interface';
6
+ export * from './node.tool';
7
+ export * from './interfaces/tool-result.interface';
8
+ export * from './tool.utils';
9
+ export * from './virtual.tool';
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -8,12 +8,12 @@ declare const oHostNodeTool_base: {
8
8
  use(address: oAddress, data: {
9
9
  [key: string]: unknown;
10
10
  }, config?: import("@olane/o-core").UseOptions): Promise<import("@olane/o-core").oResponse>;
11
- handleStream(streamData: import("@libp2p/interface", { with: { "resolution-mode": "import" } }).IncomingStreamData): Promise<void>;
12
- execute(req: import("@olane/o-core").oRequest, stream?: import("@libp2p/interface", { with: { "resolution-mode": "import" } }).Stream): Promise<import(".").RunResult>;
13
- run(request: import("@olane/o-core").oRequest, stream?: import("@libp2p/interface", { with: { "resolution-mode": "import" } }).Stream): Promise<import(".").RunResult>;
11
+ handleStream(streamData: import("@libp2p/interface").IncomingStreamData): Promise<void>;
12
+ execute(req: import("@olane/o-core").oRequest, stream?: import("@libp2p/interface").Stream): Promise<import(".").RunResult>;
13
+ run(request: import("@olane/o-core").oRequest, stream?: import("@libp2p/interface").Stream): Promise<import(".").RunResult>;
14
14
  myTools(): string[];
15
15
  myToolParams(tool: string): Record<string, any>;
16
- callMyTool(request: import("@olane/o-core").oRequest, stream?: import("@libp2p/interface", { with: { "resolution-mode": "import" } }).Stream): Promise<import(".").ToolResult>;
16
+ callMyTool(request: import("@olane/o-core").oRequest, stream?: import("@libp2p/interface").Stream): Promise<import(".").ToolResult>;
17
17
  index(): Promise<{
18
18
  provider: string;
19
19
  summary: string;
@@ -28,16 +28,16 @@ declare const oHostNodeTool_base: {
28
28
  }>;
29
29
  findMissingParams(methodName: string, params: any): import("@olane/o-protocol").oParameter[];
30
30
  readonly config: import("@olane/o-core").CoreConfig;
31
- p2pNode: import("libp2p", { with: { "resolution-mode": "import" } }).Libp2p;
31
+ p2pNode: import("@libp2p/interface").Libp2p;
32
32
  logger: import("@olane/o-core").Logger;
33
33
  networkConfig: import("@olane/o-config").Libp2pConfig;
34
34
  address: oAddress;
35
35
  readonly staticAddress: oAddress;
36
- peerId: import("@libp2p/interface-peer-id", { with: { "resolution-mode": "import" } }).PeerId;
36
+ peerId: import("@libp2p/interface-peer-id").PeerId;
37
37
  state: import("@olane/o-core").NodeState;
38
38
  errors: Error[];
39
39
  connectionManager: import("@olane/o-core").oConnectionManager;
40
- leaders: import("@multiformats/multiaddr", { with: { "resolution-mode": "import" } }).Multiaddr[];
40
+ leaders: import("@olane/o-config").Multiaddr[];
41
41
  addressResolution: import("@olane/o-core").oAddressResolution;
42
42
  readonly description: string;
43
43
  dependencies: import("@olane/o-core").oDependency[];
@@ -49,8 +49,8 @@ declare const oHostNodeTool_base: {
49
49
  get type(): import("@olane/o-core").NodeType;
50
50
  get transports(): string[];
51
51
  get parent(): oAddress | null;
52
- get parentTransports(): import("@multiformats/multiaddr", { with: { "resolution-mode": "import" } }).Multiaddr[];
53
- getTransports(address: oAddress): import("@multiformats/multiaddr", { with: { "resolution-mode": "import" } }).Multiaddr[];
52
+ get parentTransports(): import("@olane/o-config").Multiaddr[];
53
+ getTransports(address: oAddress): import("@olane/o-config").Multiaddr[];
54
54
  handleStaticAddressTranslation(addressInput: oAddress): Promise<oAddress>;
55
55
  translateAddress(addressWithLeaderTransports: oAddress): Promise<{
56
56
  nextHopAddress: oAddress;
package/dist/node.tool.js CHANGED
@@ -1,11 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.oHostNodeTool = void 0;
4
- const o_tool_1 = require("./o-tool");
5
- const o_core_1 = require("@olane/o-core");
6
- class oHostNodeTool extends (0, o_tool_1.oTool)(o_core_1.oHostNode) {
1
+ import { oTool } from './o-tool';
2
+ import { oHostNode } from '@olane/o-core';
3
+ export class oHostNodeTool extends oTool(oHostNode) {
7
4
  constructor(config) {
8
5
  super(config);
9
6
  }
10
7
  }
11
- exports.oHostNodeTool = oHostNodeTool;
package/dist/o-tool.d.ts CHANGED
@@ -36,16 +36,16 @@ export declare function oTool<T extends new (...args: any[]) => oCoreNode>(Base:
36
36
  }>;
37
37
  findMissingParams(methodName: string, params: any): oParameter[];
38
38
  readonly config: import("@olane/o-core").CoreConfig;
39
- p2pNode: import("@libp2p/interface", { with: { "resolution-mode": "import" } }).Libp2p;
39
+ p2pNode: import("@libp2p/interface").Libp2p;
40
40
  logger: import("@olane/o-core").Logger;
41
41
  networkConfig: import("@olane/o-config").Libp2pConfig;
42
42
  address: oAddress;
43
43
  readonly staticAddress: oAddress;
44
- peerId: import("@libp2p/interface-peer-id", { with: { "resolution-mode": "import" } }).PeerId;
44
+ peerId: import("@libp2p/interface-peer-id").PeerId;
45
45
  state: import("@olane/o-core").NodeState;
46
46
  errors: Error[];
47
47
  connectionManager: import("@olane/o-core").oConnectionManager;
48
- leaders: import("@multiformats/multiaddr", { with: { "resolution-mode": "import" } }).Multiaddr[];
48
+ leaders: import("@olane/o-config").Multiaddr[];
49
49
  addressResolution: import("@olane/o-core").oAddressResolution;
50
50
  readonly description: string;
51
51
  dependencies: oDependency[];
@@ -57,8 +57,8 @@ export declare function oTool<T extends new (...args: any[]) => oCoreNode>(Base:
57
57
  get type(): NodeType;
58
58
  get transports(): string[];
59
59
  get parent(): oAddress | null;
60
- get parentTransports(): import("@multiformats/multiaddr", { with: { "resolution-mode": "import" } }).Multiaddr[];
61
- getTransports(address: oAddress): import("@multiformats/multiaddr", { with: { "resolution-mode": "import" } }).Multiaddr[];
60
+ get parentTransports(): import("@olane/o-config").Multiaddr[];
61
+ getTransports(address: oAddress): import("@olane/o-config").Multiaddr[];
62
62
  handleStaticAddressTranslation(addressInput: oAddress): Promise<oAddress>;
63
63
  translateAddress(addressWithLeaderTransports: oAddress): Promise<{
64
64
  nextHopAddress: oAddress;
package/dist/o-tool.js CHANGED
@@ -1,16 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.oTool = oTool;
4
- const o_core_1 = require("@olane/o-core");
5
- const o_protocol_1 = require("@olane/o-protocol");
6
- const tool_utils_1 = require("./tool.utils");
7
- const uuid_1 = require("uuid");
1
+ import { CoreUtils, oAddress, oRequest, oToolError, oToolErrorCodes, } from '@olane/o-core';
2
+ import { oProtocolMethods } from '@olane/o-protocol';
3
+ import { ToolUtils } from './tool.utils';
4
+ import { v4 as uuidv4 } from 'uuid';
8
5
  /**
9
6
  * oTool is a mixin that extends the base class and implements the oTool interface
10
7
  * @param Base - The base class to extend
11
8
  * @returns A new class that extends the base class and implements the oTool interface
12
9
  */
13
- function oTool(Base) {
10
+ export function oTool(Base) {
14
11
  return class extends Base {
15
12
  constructor(...args) {
16
13
  super(...args);
@@ -47,7 +44,7 @@ function oTool(Base) {
47
44
  address.toString() === this.staticAddress.toString()) {
48
45
  // let's call our own tool
49
46
  this.logger.debug('Calling ourselves, skipping...', data);
50
- const request = new o_core_1.oRequest({
47
+ const request = new oRequest({
51
48
  method: data.method,
52
49
  params: {
53
50
  _connectionId: 0,
@@ -70,21 +67,21 @@ function oTool(Base) {
70
67
  else {
71
68
  this.errorCount++;
72
69
  }
73
- return tool_utils_1.ToolUtils.buildResponse(request, result, result?.error);
70
+ return ToolUtils.buildResponse(request, result, result?.error);
74
71
  }
75
72
  return super.use(address, data, config);
76
73
  }
77
74
  async handleStream(streamData) {
78
75
  const { stream } = streamData;
79
- const requestConfig = await o_core_1.CoreUtils.processStream(stream);
80
- const request = new o_core_1.oRequest(requestConfig);
76
+ const requestConfig = await CoreUtils.processStream(stream);
77
+ const request = new oRequest(requestConfig);
81
78
  let success = true;
82
79
  const result = await this.execute(request, stream).catch((error) => {
83
80
  this.logger.error('Error executing tool: ' + error, typeof error);
84
81
  success = false;
85
- const responseError = error instanceof o_core_1.oToolError
82
+ const responseError = error instanceof oToolError
86
83
  ? error
87
- : new o_core_1.oToolError(o_core_1.oToolErrorCodes.TOOL_ERROR, error.message);
84
+ : new oToolError(oToolErrorCodes.TOOL_ERROR, error.message);
88
85
  return {
89
86
  error: responseError,
90
87
  };
@@ -96,9 +93,9 @@ function oTool(Base) {
96
93
  this.errorCount++;
97
94
  }
98
95
  // compose the response & add the expected connection + request fields
99
- const response = tool_utils_1.ToolUtils.buildResponse(request, result, result?.error);
96
+ const response = ToolUtils.buildResponse(request, result, result?.error);
100
97
  // add the request method to the response
101
- return o_core_1.CoreUtils.sendResponse(response, streamData.stream);
98
+ return CoreUtils.sendResponse(response, streamData.stream);
102
99
  }
103
100
  async execute(req, stream) {
104
101
  this.logger.debug('Tool handling incoming stream: ' + this.address.protocol);
@@ -115,11 +112,11 @@ function oTool(Base) {
115
112
  // validate and run the tool
116
113
  this.validateToolCall(request);
117
114
  // check if it's a route and we have reached the destination
118
- if (request.method === o_protocol_1.oProtocolMethods.ROUTE &&
115
+ if (request.method === oProtocolMethods.ROUTE &&
119
116
  request.params.address === this.address.value) {
120
117
  const { payload } = request.params;
121
118
  this.logger.debug('Reached destination, processing payload', payload);
122
- request = new o_core_1.oRequest({
119
+ request = new oRequest({
123
120
  id: requestConfig.id,
124
121
  method: payload.method,
125
122
  params: {
@@ -139,7 +136,7 @@ function oTool(Base) {
139
136
  const missingParams = this.findMissingParams(request.method, request.params || {});
140
137
  if (missingParams.length > 0) {
141
138
  this.logger.error('Missing required parameters: ', missingParams, ' with passed params: ', request.params);
142
- throw new o_core_1.oToolError(o_core_1.oToolErrorCodes.TOOL_MISSING_PARAMETERS, 'Missing required parameters', {
139
+ throw new oToolError(oToolErrorCodes.TOOL_MISSING_PARAMETERS, 'Missing required parameters', {
143
140
  parameters: missingParams,
144
141
  toolAddress: this.address.toString(),
145
142
  data: request.params,
@@ -178,7 +175,7 @@ function oTool(Base) {
178
175
  }
179
176
  for (const method in this.methods) {
180
177
  const m = this.methods[method];
181
- await this.use(new o_core_1.oAddress('o://vector-store'), {
178
+ await this.use(new oAddress('o://vector-store'), {
182
179
  method: 'add_documents',
183
180
  params: {
184
181
  documents: [
@@ -186,7 +183,7 @@ function oTool(Base) {
186
183
  pageContent: m.description,
187
184
  metadata: {
188
185
  address: this.address?.toString() + '/' + method,
189
- id: (0, uuid_1.v4)(),
186
+ id: uuidv4(),
190
187
  },
191
188
  },
192
189
  ],
@@ -196,7 +193,7 @@ function oTool(Base) {
196
193
  let summary = metadata.description ? metadata.description : null;
197
194
  if (!summary) {
198
195
  this.logger.debug('No description found, generating summary...');
199
- const response = await this.use(new o_core_1.oAddress('o://intelligence'), {
196
+ const response = await this.use(new oAddress('o://intelligence'), {
200
197
  method: 'prompt',
201
198
  params: {
202
199
  prompt: `You are a helpful assistant that summarizes what a service does by looking at the service description and the details of the tools that the service contains. \n
@@ -223,7 +220,7 @@ function oTool(Base) {
223
220
  }
224
221
  try {
225
222
  if (summary) {
226
- await this.use(new o_core_1.oAddress('o://vector-store'), {
223
+ await this.use(new oAddress('o://vector-store'), {
227
224
  method: 'add_documents',
228
225
  params: {
229
226
  documents: [
@@ -231,7 +228,7 @@ function oTool(Base) {
231
228
  pageContent: summary,
232
229
  metadata: {
233
230
  address: this.address?.toString(),
234
- id: (0, uuid_1.v4)(),
231
+ id: uuidv4(),
235
232
  },
236
233
  },
237
234
  ],
@@ -262,7 +259,7 @@ function oTool(Base) {
262
259
  // ensure that the required parameters are present
263
260
  findMissingParams(methodName, params) {
264
261
  const method = this.methods[methodName];
265
- const protectedMethods = Object.values(o_protocol_1.oProtocolMethods);
262
+ const protectedMethods = Object.values(oProtocolMethods);
266
263
  if (protectedMethods.includes(methodName)) {
267
264
  return [];
268
265
  }
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ToolUtils = void 0;
4
- const o_core_1 = require("@olane/o-core");
5
- class ToolUtils {
1
+ import { oResponse } from '@olane/o-core';
2
+ export class ToolUtils {
6
3
  static buildResponse(request, result, error) {
7
4
  let success = true;
8
5
  if (error) {
9
6
  success = false;
10
7
  }
11
- return new o_core_1.oResponse({
8
+ return new oResponse({
12
9
  id: request.id,
13
10
  data: result,
14
11
  error: result?.error,
@@ -18,4 +15,3 @@ class ToolUtils {
18
15
  });
19
16
  }
20
17
  }
21
- exports.ToolUtils = ToolUtils;
@@ -8,12 +8,12 @@ declare const oVirtualTool_base: {
8
8
  use(address: oAddress, data: {
9
9
  [key: string]: unknown;
10
10
  }, config?: import("@olane/o-core").UseOptions): Promise<import("@olane/o-core").oResponse>;
11
- handleStream(streamData: import("@libp2p/interface", { with: { "resolution-mode": "import" } }).IncomingStreamData): Promise<void>;
12
- execute(req: import("@olane/o-core").oRequest, stream?: import("@libp2p/interface", { with: { "resolution-mode": "import" } }).Stream): Promise<import(".").RunResult>;
13
- run(request: import("@olane/o-core").oRequest, stream?: import("@libp2p/interface", { with: { "resolution-mode": "import" } }).Stream): Promise<import(".").RunResult>;
11
+ handleStream(streamData: import("@libp2p/interface").IncomingStreamData): Promise<void>;
12
+ execute(req: import("@olane/o-core").oRequest, stream?: import("@libp2p/interface").Stream): Promise<import(".").RunResult>;
13
+ run(request: import("@olane/o-core").oRequest, stream?: import("@libp2p/interface").Stream): Promise<import(".").RunResult>;
14
14
  myTools(): string[];
15
15
  myToolParams(tool: string): Record<string, any>;
16
- callMyTool(request: import("@olane/o-core").oRequest, stream?: import("@libp2p/interface", { with: { "resolution-mode": "import" } }).Stream): Promise<import(".").ToolResult>;
16
+ callMyTool(request: import("@olane/o-core").oRequest, stream?: import("@libp2p/interface").Stream): Promise<import(".").ToolResult>;
17
17
  index(): Promise<{
18
18
  provider: string;
19
19
  summary: string;
@@ -28,16 +28,16 @@ declare const oVirtualTool_base: {
28
28
  }>;
29
29
  findMissingParams(methodName: string, params: any): import("@olane/o-protocol").oParameter[];
30
30
  readonly config: import("@olane/o-core").CoreConfig;
31
- p2pNode: import("libp2p", { with: { "resolution-mode": "import" } }).Libp2p;
31
+ p2pNode: import("@libp2p/interface").Libp2p;
32
32
  logger: import("@olane/o-core").Logger;
33
33
  networkConfig: import("@olane/o-config").Libp2pConfig;
34
34
  address: oAddress;
35
35
  readonly staticAddress: oAddress;
36
- peerId: import("@libp2p/interface-peer-id", { with: { "resolution-mode": "import" } }).PeerId;
36
+ peerId: import("@libp2p/interface-peer-id").PeerId;
37
37
  state: import("@olane/o-core").NodeState;
38
38
  errors: Error[];
39
39
  connectionManager: import("@olane/o-core").oConnectionManager;
40
- leaders: import("@multiformats/multiaddr", { with: { "resolution-mode": "import" } }).Multiaddr[];
40
+ leaders: import("@olane/o-config").Multiaddr[];
41
41
  addressResolution: import("@olane/o-core").oAddressResolution;
42
42
  readonly description: string;
43
43
  dependencies: import("@olane/o-core").oDependency[];
@@ -49,8 +49,8 @@ declare const oVirtualTool_base: {
49
49
  get type(): import("@olane/o-core").NodeType;
50
50
  get transports(): string[];
51
51
  get parent(): oAddress | null;
52
- get parentTransports(): import("@multiformats/multiaddr", { with: { "resolution-mode": "import" } }).Multiaddr[];
53
- getTransports(address: oAddress): import("@multiformats/multiaddr", { with: { "resolution-mode": "import" } }).Multiaddr[];
52
+ get parentTransports(): import("@olane/o-config").Multiaddr[];
53
+ getTransports(address: oAddress): import("@olane/o-config").Multiaddr[];
54
54
  handleStaticAddressTranslation(addressInput: oAddress): Promise<oAddress>;
55
55
  translateAddress(addressWithLeaderTransports: oAddress): Promise<{
56
56
  nextHopAddress: oAddress;
@@ -1,11 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.oVirtualTool = void 0;
4
- const o_tool_1 = require("./o-tool");
5
- const o_core_1 = require("@olane/o-core");
6
- class oVirtualTool extends (0, o_tool_1.oTool)(o_core_1.oVirtualNode) {
1
+ import { oTool } from './o-tool';
2
+ import { oVirtualNode } from '@olane/o-core';
3
+ export class oVirtualTool extends oTool(oVirtualNode) {
7
4
  constructor(config) {
8
5
  super(config);
9
6
  }
10
7
  }
11
- exports.oVirtualTool = oVirtualTool;
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@olane/o-tool",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
+ "type": "module",
4
5
  "main": "dist/index.js",
5
6
  "types": "dist/index.d.ts",
6
7
  "exports": {
7
8
  ".": {
8
- "default": "./dist/index.js",
9
- "types": "./dist/index.d.ts"
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
10
11
  }
11
12
  },
12
13
  "files": [
@@ -37,9 +38,9 @@
37
38
  "@babel/preset-typescript": "^7.27.1",
38
39
  "@eslint/eslintrc": "^3.3.1",
39
40
  "@eslint/js": "^9.29.0",
40
- "@olane/o-config": "^0.1.1",
41
- "@olane/o-core": "^0.1.1",
42
- "@olane/o-protocol": "^0.1.1",
41
+ "@olane/o-config": "file:../o-config",
42
+ "@olane/o-core": "file:../..",
43
+ "@olane/o-protocol": "file:../o-protocol",
43
44
  "@tsconfig/node20": "^20.1.6",
44
45
  "@types/jest": "^30.0.0",
45
46
  "@typescript-eslint/eslint-plugin": "^8.34.1",
@@ -63,9 +64,9 @@
63
64
  "webpack-dev-server": "^5.2.2"
64
65
  },
65
66
  "peerDependencies": {
66
- "@olane/o-config": "^0.1.1",
67
- "@olane/o-core": "^0.1.1",
68
- "@olane/o-protocol": "^0.1.1"
67
+ "@olane/o-config": "^0.1.2",
68
+ "@olane/o-core": "^0.1.2",
69
+ "@olane/o-protocol": "^0.1.2"
69
70
  },
70
71
  "dependencies": {
71
72
  "debug": "^4.4.1",