@olane/o-tool 0.1.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.
Files changed (43) hide show
  1. package/README.md +1 -0
  2. package/dist/index.d.ts +10 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +10 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/interfaces/run-params.interface.d.ts +4 -0
  7. package/dist/interfaces/run-params.interface.d.ts.map +1 -0
  8. package/dist/interfaces/run-params.interface.js +2 -0
  9. package/dist/interfaces/run-params.interface.js.map +1 -0
  10. package/dist/interfaces/run-result.interface.d.ts +4 -0
  11. package/dist/interfaces/run-result.interface.d.ts.map +1 -0
  12. package/dist/interfaces/run-result.interface.js +2 -0
  13. package/dist/interfaces/run-result.interface.js.map +1 -0
  14. package/dist/interfaces/run-tool.interface.d.ts +6 -0
  15. package/dist/interfaces/run-tool.interface.d.ts.map +1 -0
  16. package/dist/interfaces/run-tool.interface.js +2 -0
  17. package/dist/interfaces/run-tool.interface.js.map +1 -0
  18. package/dist/interfaces/tool-result.interface.d.ts +4 -0
  19. package/dist/interfaces/tool-result.interface.d.ts.map +1 -0
  20. package/dist/interfaces/tool-result.interface.js +2 -0
  21. package/dist/interfaces/tool-result.interface.js.map +1 -0
  22. package/dist/interfaces/tool.interface.d.ts +4 -0
  23. package/dist/interfaces/tool.interface.d.ts.map +1 -0
  24. package/dist/interfaces/tool.interface.js +2 -0
  25. package/dist/interfaces/tool.interface.js.map +1 -0
  26. package/dist/node.tool.d.ts +74 -0
  27. package/dist/node.tool.d.ts.map +1 -0
  28. package/dist/node.tool.js +8 -0
  29. package/dist/node.tool.js.map +1 -0
  30. package/dist/o-tool.d.ts +71 -0
  31. package/dist/o-tool.d.ts.map +1 -0
  32. package/dist/o-tool.js +256 -0
  33. package/dist/o-tool.js.map +1 -0
  34. package/dist/tool.utils.d.ts +6 -0
  35. package/dist/tool.utils.d.ts.map +1 -0
  36. package/dist/tool.utils.js +18 -0
  37. package/dist/tool.utils.js.map +1 -0
  38. package/dist/tsconfig.tsbuildinfo +1 -0
  39. package/dist/virtual.tool.d.ts +74 -0
  40. package/dist/virtual.tool.d.ts.map +1 -0
  41. package/dist/virtual.tool.js +8 -0
  42. package/dist/virtual.tool.js.map +1 -0
  43. package/package.json +81 -0
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # o-tool
@@ -0,0 +1,10 @@
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';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mCAAmC,CAAC;AAClD,cAAc,mCAAmC,CAAC;AAClD,cAAc,iCAAiC,CAAC;AAChD,cAAc,aAAa,CAAC;AAC5B,cAAc,oCAAoC,CAAC;AACnD,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
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';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mCAAmC,CAAC;AAClD,cAAc,mCAAmC,CAAC;AAClD,cAAc,iCAAiC,CAAC;AAChD,cAAc,aAAa,CAAC;AAC5B,cAAc,oCAAoC,CAAC;AACnD,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export interface RunToolParams {
2
+ [key: string]: unknown;
3
+ }
4
+ //# sourceMappingURL=run-params.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-params.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/run-params.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=run-params.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-params.interface.js","sourceRoot":"","sources":["../../src/interfaces/run-params.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ export interface RunResult {
2
+ [key: string]: unknown;
3
+ }
4
+ //# sourceMappingURL=run-result.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-result.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/run-result.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=run-result.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-result.interface.js","sourceRoot":"","sources":["../../src/interfaces/run-result.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import { RequestParams } from '@olane/o-protocol';
2
+ export interface RunTool extends RequestParams {
3
+ tool: string;
4
+ [key: string]: unknown;
5
+ }
6
+ //# sourceMappingURL=run-tool.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-tool.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/run-tool.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,MAAM,WAAW,OAAQ,SAAQ,aAAa;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=run-tool.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-tool.interface.js","sourceRoot":"","sources":["../../src/interfaces/run-tool.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ export interface ToolResult {
2
+ [key: string]: any;
3
+ }
4
+ //# sourceMappingURL=tool-result.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-result.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/tool-result.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=tool-result.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-result.interface.js","sourceRoot":"","sources":["../../src/interfaces/tool-result.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import { CoreConfig } from '@olane/o-core';
2
+ export interface oToolConfig extends Omit<CoreConfig, 'address'> {
3
+ }
4
+ //# sourceMappingURL=tool.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/tool.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,WAAW,WAAY,SAAQ,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC;CAAG"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=tool.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.interface.js","sourceRoot":"","sources":["../../src/interfaces/tool.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,74 @@
1
+ import { oAddress, oHostNode } from '@olane/o-core';
2
+ import { oToolConfig } from './interfaces/tool.interface';
3
+ declare const oHostNodeTool_base: {
4
+ new (...args: any[]): {
5
+ validateToolCall(oRequest: import("@olane/o-core").oRequest): boolean;
6
+ handleProtocol(address: oAddress): Promise<void>;
7
+ initialize(): Promise<void>;
8
+ use(address: oAddress, data: {
9
+ [key: string]: unknown;
10
+ }, config?: import("@olane/o-core").UseOptions): Promise<import("@olane/o-core").oResponse>;
11
+ handleStream(streamData: import("@olane/o-config/dist").IncomingStreamData): Promise<void>;
12
+ execute(req: import("@olane/o-core").oRequest, stream?: import("@olane/o-config/dist").Stream): Promise<import(".").RunResult>;
13
+ run(request: import("@olane/o-core").oRequest, stream?: import("@olane/o-config/dist").Stream): Promise<import(".").RunResult>;
14
+ myTools(): string[];
15
+ myToolParams(tool: string): Record<string, any>;
16
+ callMyTool(request: import("@olane/o-core").oRequest, stream?: import("@olane/o-config/dist").Stream): Promise<import(".").ToolResult>;
17
+ index(): Promise<{
18
+ provider: string;
19
+ summary: string;
20
+ } | {
21
+ summary: string | null;
22
+ provider?: undefined;
23
+ }>;
24
+ _tool_index_network(request: import("@olane/o-core").oRequest): Promise<import(".").ToolResult>;
25
+ whoami(): Promise<{
26
+ tools: string[];
27
+ description: string;
28
+ }>;
29
+ findMissingParams(methodName: string, params: any): import("@olane/o-protocol/dist").oParameter[];
30
+ readonly config: import("@olane/o-core").CoreConfig;
31
+ p2pNode: import("@olane/o-config/dist").Libp2p;
32
+ logger: import("@olane/o-core").Logger;
33
+ networkConfig: import("@olane/o-config/dist").Libp2pConfig;
34
+ address: oAddress;
35
+ readonly staticAddress: oAddress;
36
+ peerId: import("@olane/o-config/dist").PeerId;
37
+ state: import("@olane/o-core").NodeState;
38
+ errors: Error[];
39
+ connectionManager: import("@olane/o-core").oConnectionManager;
40
+ leaders: import("@olane/o-config/dist").Multiaddr[];
41
+ addressResolution: import("@olane/o-core").oAddressResolution;
42
+ readonly description: string;
43
+ dependencies: import("@olane/o-core").oDependency[];
44
+ methods: {
45
+ [key: string]: import("@olane/o-protocol/dist").oMethod;
46
+ };
47
+ successCount: number;
48
+ errorCount: number;
49
+ get type(): import("@olane/o-core").NodeType;
50
+ get transports(): string[];
51
+ get parent(): oAddress | null;
52
+ get parentTransports(): import("@olane/o-config/dist").Multiaddr[];
53
+ getTransports(address: oAddress): import("@olane/o-config/dist").Multiaddr[];
54
+ handleStaticAddressTranslation(addressInput: oAddress): Promise<oAddress>;
55
+ translateAddress(addressWithLeaderTransports: oAddress): Promise<{
56
+ nextHopAddress: oAddress;
57
+ targetAddress: oAddress;
58
+ }>;
59
+ advertiseToNetwork(): Promise<void>;
60
+ connectToParent(): Promise<void>;
61
+ register(): Promise<void>;
62
+ connect(nextHopAddress: oAddress, targetAddress: oAddress): Promise<import("@olane/o-core").oConnection>;
63
+ teardown(): Promise<void>;
64
+ start(): Promise<void>;
65
+ stop(): Promise<void>;
66
+ };
67
+ } & typeof oHostNode;
68
+ export declare class oHostNodeTool extends oHostNodeTool_base {
69
+ constructor(config: oToolConfig & {
70
+ address: oAddress;
71
+ });
72
+ }
73
+ export {};
74
+ //# sourceMappingURL=node.tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.tool.d.ts","sourceRoot":"","sources":["../src/node.tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAS,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE1D,qBAAa,aAAc,SAAQ,kBAAgB;gBACrC,MAAM,EAAE,WAAW,GAAG;QAAE,OAAO,EAAE,QAAQ,CAAA;KAAE;CAGxD"}
@@ -0,0 +1,8 @@
1
+ import { oTool } from './o-tool';
2
+ import { oHostNode } from '@olane/o-core';
3
+ export class oHostNodeTool extends oTool(oHostNode) {
4
+ constructor(config) {
5
+ super(config);
6
+ }
7
+ }
8
+ //# sourceMappingURL=node.tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.tool.js","sourceRoot":"","sources":["../src/node.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAY,SAAS,EAAS,MAAM,eAAe,CAAC;AAG3D,MAAM,OAAO,aAAc,SAAQ,KAAK,CAAC,SAAS,CAAC;IACjD,YAAY,MAA2C;QACrD,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;CACF"}
@@ -0,0 +1,71 @@
1
+ import { NodeType, oAddress, oCoreNode, oDependency, oRequest, oResponse, UseOptions } from '@olane/o-core';
2
+ import { IncomingStreamData, Stream } from '@olane/o-config';
3
+ import { oParameter } from '@olane/o-protocol';
4
+ import { RunResult } from './interfaces/run-result.interface';
5
+ import { ToolResult } from './interfaces/tool-result.interface';
6
+ export declare function oTool<T extends new (...args: any[]) => oCoreNode>(Base: T): {
7
+ new (...args: any[]): {
8
+ validateToolCall(oRequest: oRequest): boolean;
9
+ handleProtocol(address: oAddress): Promise<void>;
10
+ initialize(): Promise<void>;
11
+ use(address: oAddress, data: {
12
+ [key: string]: unknown;
13
+ }, config?: UseOptions): Promise<oResponse>;
14
+ handleStream(streamData: IncomingStreamData): Promise<void>;
15
+ execute(req: oRequest, stream?: Stream): Promise<RunResult>;
16
+ run(request: oRequest, stream?: Stream): Promise<RunResult>;
17
+ myTools(): string[];
18
+ myToolParams(tool: string): Record<string, any>;
19
+ callMyTool(request: oRequest, stream?: Stream): Promise<ToolResult>;
20
+ index(): Promise<{
21
+ provider: string;
22
+ summary: string;
23
+ } | {
24
+ summary: string | null;
25
+ provider?: undefined;
26
+ }>;
27
+ _tool_index_network(request: oRequest): Promise<ToolResult>;
28
+ whoami(): Promise<{
29
+ tools: string[];
30
+ description: string;
31
+ }>;
32
+ findMissingParams(methodName: string, params: any): oParameter[];
33
+ readonly config: import("@olane/o-core").CoreConfig;
34
+ p2pNode: import("@olane/o-config").Libp2p;
35
+ logger: import("@olane/o-core").Logger;
36
+ networkConfig: import("@olane/o-config").Libp2pConfig;
37
+ address: oAddress;
38
+ readonly staticAddress: oAddress;
39
+ peerId: import("@olane/o-config").PeerId;
40
+ state: import("@olane/o-core").NodeState;
41
+ errors: Error[];
42
+ connectionManager: import("@olane/o-core").oConnectionManager;
43
+ leaders: import("@olane/o-config").Multiaddr[];
44
+ addressResolution: import("@olane/o-core").oAddressResolution;
45
+ readonly description: string;
46
+ dependencies: oDependency[];
47
+ methods: {
48
+ [key: string]: import("@olane/o-protocol").oMethod;
49
+ };
50
+ successCount: number;
51
+ errorCount: number;
52
+ get type(): NodeType;
53
+ get transports(): string[];
54
+ get parent(): oAddress | null;
55
+ get parentTransports(): import("@olane/o-config").Multiaddr[];
56
+ getTransports(address: oAddress): import("@olane/o-config").Multiaddr[];
57
+ handleStaticAddressTranslation(addressInput: oAddress): Promise<oAddress>;
58
+ translateAddress(addressWithLeaderTransports: oAddress): Promise<{
59
+ nextHopAddress: oAddress;
60
+ targetAddress: oAddress;
61
+ }>;
62
+ advertiseToNetwork(): Promise<void>;
63
+ connectToParent(): Promise<void>;
64
+ register(): Promise<void>;
65
+ connect(nextHopAddress: oAddress, targetAddress: oAddress): Promise<import("@olane/o-core").oConnection>;
66
+ teardown(): Promise<void>;
67
+ start(): Promise<void>;
68
+ stop(): Promise<void>;
69
+ };
70
+ } & T;
71
+ //# sourceMappingURL=o-tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"o-tool.d.ts","sourceRoot":"","sources":["../src/o-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,WAAW,EACX,QAAQ,EACR,SAAS,EAGT,UAAU,EACX,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAoB,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAShE,wBAAgB,KAAK,CAAC,CAAC,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,SAAS,EAAE,IAAI,EAAE,CAAC;kBAEjD,GAAG,EAAE;mCAKC,QAAQ,GAAG,OAAO;gCAYf,QAAQ;sBAKlB,OAAO,CAAC,IAAI,CAAC;qBAatB,QAAQ,QACX;YACJ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;SACxB,WACO,UAAU,GACjB,OAAO,CAAC,SAAS,CAAC;iCAqCU,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;qBAiC9C,QAAQ,WAAW,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;qBA8C9C,QAAQ,WAAW,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;mBA2BtD,MAAM,EAAE;2BAOA,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;4BAUrB,QAAQ,WAAW,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;;;;;;;;qCA4FtC,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;;;;;sCAenC,MAAM,UAAU,GAAG,GAAG,UAAU,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MA2BnE"}
package/dist/o-tool.js ADDED
@@ -0,0 +1,256 @@
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';
5
+ export function oTool(Base) {
6
+ return class extends Base {
7
+ constructor(...args) {
8
+ super(...args);
9
+ const config = args[0];
10
+ }
11
+ validateToolCall(oRequest) {
12
+ this.logger.debug('Validating tool call: ' + oRequest.method);
13
+ const method = oRequest.method;
14
+ if (!method) {
15
+ throw new Error('method parameter is required');
16
+ }
17
+ if (!this[`_tool_${method}`]) {
18
+ throw new Error(`Tool ${method} is not implemented`);
19
+ }
20
+ return true;
21
+ }
22
+ async handleProtocol(address) {
23
+ this.logger.debug('Handling protocol: ' + address.protocol);
24
+ await this.p2pNode.handle(address.protocol, this.handleStream.bind(this));
25
+ }
26
+ async initialize() {
27
+ await super.initialize();
28
+ this.logger.debug('Handling protocol: ' + this.address.protocol);
29
+ await this.handleProtocol(this.address);
30
+ if (this.staticAddress &&
31
+ this.staticAddress?.toString() !== this.address.toString()) {
32
+ await this.handleProtocol(this.staticAddress);
33
+ }
34
+ }
35
+ async use(address, data, config = {}) {
36
+ if (address.toString() === this.address.toString() ||
37
+ address.toString() === this.staticAddress.toString()) {
38
+ this.logger.debug('Calling ourselves, skipping...', data);
39
+ const request = new oRequest({
40
+ method: data.method,
41
+ params: {
42
+ _connectionId: 0,
43
+ _requestMethod: data.method,
44
+ ...data.params,
45
+ },
46
+ id: 0,
47
+ });
48
+ let success = true;
49
+ const result = await this.execute(request).catch((error) => {
50
+ this.logger.error('Error executing tool: ' + error);
51
+ success = false;
52
+ return {
53
+ error: error.message,
54
+ };
55
+ });
56
+ if (success) {
57
+ this.successCount++;
58
+ }
59
+ else {
60
+ this.errorCount++;
61
+ }
62
+ return ToolUtils.buildResponse(request, result, result?.error);
63
+ }
64
+ return super.use(address, data, config);
65
+ }
66
+ async handleStream(streamData) {
67
+ const { stream } = streamData;
68
+ const requestConfig = await CoreUtils.processStream(stream);
69
+ const request = new oRequest(requestConfig);
70
+ let success = true;
71
+ const result = await this.execute(request, stream).catch((error) => {
72
+ this.logger.error('Error executing tool: ' + error, typeof error);
73
+ success = false;
74
+ const responseError = error instanceof oToolError
75
+ ? error
76
+ : new oToolError(oToolErrorCodes.TOOL_ERROR, error.message);
77
+ return {
78
+ error: responseError,
79
+ };
80
+ });
81
+ if (success) {
82
+ this.successCount++;
83
+ }
84
+ else {
85
+ this.errorCount++;
86
+ }
87
+ const response = ToolUtils.buildResponse(request, result, result?.error);
88
+ return CoreUtils.sendResponse(response, streamData.stream);
89
+ }
90
+ async execute(req, stream) {
91
+ this.logger.debug('Tool handling incoming stream: ' + this.address.protocol);
92
+ let request = req;
93
+ const requestConfig = req.toJSON();
94
+ this.validateToolCall(request);
95
+ if (request.method === oProtocolMethods.ROUTE &&
96
+ request.params.address === this.address.value) {
97
+ const { payload } = request.params;
98
+ this.logger.debug('Reached destination, processing payload', payload);
99
+ request = new oRequest({
100
+ id: requestConfig.id,
101
+ method: payload.method,
102
+ params: {
103
+ _connectionId: requestConfig.params?._connectionId,
104
+ _requestMethod: payload.method,
105
+ ...(payload.params || {}),
106
+ },
107
+ });
108
+ this.logger.debug('Processed request: ', request);
109
+ }
110
+ const result = await this.run(request, stream);
111
+ return result;
112
+ }
113
+ async run(request, stream) {
114
+ const missingParams = this.findMissingParams(request.method, request.params || {});
115
+ if (missingParams.length > 0) {
116
+ this.logger.error('Missing required parameters: ', missingParams, ' with passed params: ', request.params);
117
+ throw new oToolError(oToolErrorCodes.TOOL_MISSING_PARAMETERS, 'Missing required parameters', {
118
+ parameters: missingParams,
119
+ toolAddress: this.address.toString(),
120
+ data: request.params,
121
+ });
122
+ }
123
+ return this.callMyTool(request, stream);
124
+ }
125
+ myTools() {
126
+ return Object.getOwnPropertyNames(this.constructor.prototype)
127
+ .filter((key) => key.startsWith('_tool_'))
128
+ .filter((key) => !!key)
129
+ .map((key) => key.replace('_tool_', ''));
130
+ }
131
+ myToolParams(tool) {
132
+ const func = Object.keys(this).find((key) => key.startsWith('_params_' + tool));
133
+ if (!func) {
134
+ throw new Error(`Tool ${tool} not found`);
135
+ }
136
+ return this[func]();
137
+ }
138
+ async callMyTool(request, stream) {
139
+ const method = request.method;
140
+ this.logger.debug('Calling tool: ' + method);
141
+ return this[`_tool_${method}`]({ ...request.toJSON(), stream });
142
+ }
143
+ async index() {
144
+ const metadata = await this.whoami();
145
+ if (!metadata.tools.length && !metadata.description) {
146
+ this.logger.warn('No metadata found, skipping...');
147
+ return {
148
+ provider: 'Empty node',
149
+ summary: 'Empty node',
150
+ };
151
+ }
152
+ for (const method in this.methods) {
153
+ const m = this.methods[method];
154
+ await this.use(new oAddress('o://vector-store'), {
155
+ method: 'add_documents',
156
+ params: {
157
+ documents: [
158
+ {
159
+ pageContent: m.description,
160
+ metadata: {
161
+ address: this.address?.toString() + '/' + method,
162
+ id: uuidv4(),
163
+ },
164
+ },
165
+ ],
166
+ },
167
+ });
168
+ }
169
+ let summary = metadata.description ? metadata.description : null;
170
+ if (!summary) {
171
+ this.logger.debug('No description found, generating summary...');
172
+ const response = await this.use(new oAddress('o://intelligence'), {
173
+ method: 'prompt',
174
+ params: {
175
+ 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
176
+ Format the output in JSON using this template:` +
177
+ JSON.stringify({
178
+ summary: 'string',
179
+ }) +
180
+ 'Do NOT include any other text other than the JSON response. The following is the JSON input of the service: ' +
181
+ JSON.stringify(metadata),
182
+ },
183
+ }, {
184
+ useCache: true,
185
+ });
186
+ const { result } = response;
187
+ const { success } = result;
188
+ if (!success) {
189
+ this.logger.error('Failed to index network: ', result);
190
+ throw new Error('Failed to index network');
191
+ }
192
+ const data = result.data;
193
+ const { message } = data;
194
+ const json = JSON.parse(message);
195
+ summary = json.summary;
196
+ }
197
+ try {
198
+ if (summary) {
199
+ await this.use(new oAddress('o://vector-store'), {
200
+ method: 'add_documents',
201
+ params: {
202
+ documents: [
203
+ {
204
+ pageContent: summary,
205
+ metadata: {
206
+ address: this.address?.toString(),
207
+ id: uuidv4(),
208
+ },
209
+ },
210
+ ],
211
+ },
212
+ });
213
+ }
214
+ return {
215
+ summary: summary,
216
+ };
217
+ }
218
+ catch (e) {
219
+ this.logger.error('Error indexing network: ', e);
220
+ throw e;
221
+ }
222
+ }
223
+ async _tool_index_network(request) {
224
+ this.logger.debug('Indexing network...');
225
+ return await this.index();
226
+ }
227
+ async whoami() {
228
+ const metadata = await super.whoami();
229
+ return {
230
+ tools: this.myTools(),
231
+ description: this.description,
232
+ };
233
+ }
234
+ findMissingParams(methodName, params) {
235
+ const method = this.methods[methodName];
236
+ const protectedMethods = Object.values(oProtocolMethods);
237
+ if (protectedMethods.includes(methodName)) {
238
+ return [];
239
+ }
240
+ if (!method) {
241
+ this.logger.warn('No parameter configuration found for method. This is expected for some methods, but may impact AI performance around improvisation.', methodName);
242
+ return [];
243
+ }
244
+ const requiredParams = method.parameters;
245
+ if (!requiredParams || !requiredParams.filter) {
246
+ this.logger.error('[Provider] No handshake parameters found for method: ', methodName);
247
+ return [];
248
+ }
249
+ const missingParams = requiredParams
250
+ .filter((p) => !params[p.name])
251
+ .filter((p) => p.required === undefined || p.required === true);
252
+ return missingParams;
253
+ }
254
+ };
255
+ }
256
+ //# sourceMappingURL=o-tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"o-tool.js","sourceRoot":"","sources":["../src/o-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAET,QAAQ,EAGR,QAAQ,EAER,UAAU,EACV,eAAe,GAEhB,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAc,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAGjE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAOpC,MAAM,UAAU,KAAK,CAA8C,IAAO;IACxE,OAAO,KAAM,SAAQ,IAAI;QACvB,YAAY,GAAG,IAAW;YACxB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YACf,MAAM,MAAM,GAAG,IAAI,CAAC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AC,CAAC,IAAI,CAAC,CAAC;iBAC9B,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,SAAS,IAAI,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC;YAClE,OAAO,aAAa,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { oResponse } from '@olane/o-core';
2
+ import { oRequest } from '@olane/o-protocol';
3
+ export declare class ToolUtils {
4
+ static buildResponse(request: oRequest, result: any, error: any): oResponse;
5
+ }
6
+ //# sourceMappingURL=tool.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.utils.d.ts","sourceRoot":"","sources":["../src/tool.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,qBAAa,SAAS;IACpB,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,GAAG,SAAS;CAc5E"}
@@ -0,0 +1,18 @@
1
+ import { oResponse } from '@olane/o-core';
2
+ export class ToolUtils {
3
+ static buildResponse(request, result, error) {
4
+ let success = true;
5
+ if (error) {
6
+ success = false;
7
+ }
8
+ return new oResponse({
9
+ id: request.id,
10
+ data: result,
11
+ error: result?.error,
12
+ ...{ success },
13
+ _requestMethod: request.method,
14
+ _connectionId: request.params?._connectionId,
15
+ });
16
+ }
17
+ }
18
+ //# sourceMappingURL=tool.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.utils.js","sourceRoot":"","sources":["../src/tool.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG1C,MAAM,OAAO,SAAS;IACpB,MAAM,CAAC,aAAa,CAAC,OAAiB,EAAE,MAAW,EAAE,KAAU;QAC7D,IAAI,OAAO,GAAG,IAAI,CAAC;QACnB,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,GAAG,KAAK,CAAC;QAClB,CAAC;QACD,OAAO,IAAI,SAAS,CAAC;YACnB,EAAE,EAAE,OAAO,CAAC,EAAE;YACd,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,MAAM,EAAE,KAAK;YACpB,GAAG,EAAE,OAAO,EAAE;YACd,cAAc,EAAE,OAAO,CAAC,MAAM;YAC9B,aAAa,EAAE,OAAO,CAAC,MAAM,EAAE,aAAa;SAC7C,CAAC,CAAC;IACL,CAAC;CACF"}