@olane/o-tool 0.7.12-alpha.4 → 0.7.12-alpha.41
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { oConnection, oCore, oRequest, oNotificationManager, oConnectionConfig } from '@olane/o-core';
|
|
2
2
|
import { Stream } from '@olane/o-config';
|
|
3
3
|
import { RunResult } from './interfaces/run-result.interface.js';
|
|
4
4
|
import { ToolResult } from './interfaces/tool-result.interface.js';
|
|
@@ -11,10 +11,11 @@ export declare class oToolBase extends oCore {
|
|
|
11
11
|
private indexed;
|
|
12
12
|
validateToolCall(oRequest: oRequest): boolean;
|
|
13
13
|
configureTransports(): any[];
|
|
14
|
-
connect(
|
|
14
|
+
connect(config: oConnectionConfig): Promise<oConnection>;
|
|
15
15
|
initializeRouter(): Promise<void>;
|
|
16
16
|
unregister(): Promise<void>;
|
|
17
17
|
register(): Promise<void>;
|
|
18
|
+
protected createNotificationManager(): oNotificationManager;
|
|
18
19
|
execute(req: oRequest, stream?: Stream): Promise<RunResult>;
|
|
19
20
|
run(request: oRequest, stream?: Stream): Promise<RunResult>;
|
|
20
21
|
myTools(obj?: any): Promise<string[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"o-tool.base.d.ts","sourceRoot":"","sources":["../../src/o-tool.base.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"o-tool.base.d.ts","sourceRoot":"","sources":["../../src/o-tool.base.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACX,KAAK,EAGL,QAAQ,EAER,oBAAoB,EACpB,iBAAiB,EAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AAInE;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAClC,OAAO,CAAC,OAAO,CAAkB;IAEjC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO;IAY7C,mBAAmB,IAAI,GAAG,EAAE;IAI5B,OAAO,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC;IAGxD,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAMjC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAG3B,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAIzB,SAAS,CAAC,yBAAyB,IAAI,oBAAoB;IAOrD,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IA8B3D,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IA2BjE,OAAO,CAAC,GAAG,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAS/B,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAIvD,UAAU,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAiBnE,KAAK;;;;;;;IA4FL,MAAM;;;;CAQb"}
|
package/dist/src/o-tool.base.js
CHANGED
|
@@ -26,7 +26,7 @@ export class oToolBase extends oCore {
|
|
|
26
26
|
configureTransports() {
|
|
27
27
|
return [];
|
|
28
28
|
}
|
|
29
|
-
connect(
|
|
29
|
+
connect(config) {
|
|
30
30
|
throw new oError(oErrorCodes.NOT_IMPLEMENTED, 'Connect not implemented');
|
|
31
31
|
}
|
|
32
32
|
initializeRouter() {
|
|
@@ -38,6 +38,9 @@ export class oToolBase extends oCore {
|
|
|
38
38
|
register() {
|
|
39
39
|
throw new oError(oErrorCodes.NOT_IMPLEMENTED, 'Register not implemented');
|
|
40
40
|
}
|
|
41
|
+
createNotificationManager() {
|
|
42
|
+
throw new oError(oErrorCodes.NOT_IMPLEMENTED, 'createNotificationManager not implemented');
|
|
43
|
+
}
|
|
41
44
|
async execute(req, stream) {
|
|
42
45
|
let request = req;
|
|
43
46
|
const requestConfig = req.toJSON();
|
|
@@ -84,7 +87,7 @@ export class oToolBase extends oCore {
|
|
|
84
87
|
}
|
|
85
88
|
async callMyTool(request, stream) {
|
|
86
89
|
const method = request.method;
|
|
87
|
-
this.logger.
|
|
90
|
+
this.logger.verbose('Calling tool: ' + method);
|
|
88
91
|
// TODO: implement this
|
|
89
92
|
// this.requests[request.id] = request;
|
|
90
93
|
// @ts-ignore
|
|
@@ -100,7 +103,7 @@ export class oToolBase extends oCore {
|
|
|
100
103
|
}
|
|
101
104
|
async index() {
|
|
102
105
|
if (this.indexed) {
|
|
103
|
-
this.logger.
|
|
106
|
+
this.logger.verbose('Tool already indexed, skipping...');
|
|
104
107
|
return {
|
|
105
108
|
summary: 'Tool already indexed',
|
|
106
109
|
};
|
package/dist/src/o-tool.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"o-tool.d.ts","sourceRoot":"","sources":["../../src/o-tool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"o-tool.d.ts","sourceRoot":"","sources":["../../src/o-tool.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAI7C;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,SAAS,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAuQ7E"}
|
package/dist/src/o-tool.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { oError, oErrorCodes, oRequest, } from '@olane/o-core';
|
|
1
|
+
import { oAddress, oError, oErrorCodes, oRequest, oNotificationEvent, } from '@olane/o-core';
|
|
2
2
|
/**
|
|
3
3
|
* oTool is a mixin that extends the base class and implements the oTool interface
|
|
4
4
|
* @param Base - The base class to extend
|
|
@@ -45,6 +45,8 @@ export function oTool(Base) {
|
|
|
45
45
|
await this.useChild(child, {
|
|
46
46
|
method: 'index_network',
|
|
47
47
|
params: {},
|
|
48
|
+
}).catch((error) => {
|
|
49
|
+
this.logger.error('Error indexing child: ', error);
|
|
48
50
|
});
|
|
49
51
|
}
|
|
50
52
|
this.logger.debug('Node + children indexed!');
|
|
@@ -67,7 +69,7 @@ export function oTool(Base) {
|
|
|
67
69
|
errorCount: this.metrics.errorCount,
|
|
68
70
|
activeRequests: this.requestManager.activeRequests.length,
|
|
69
71
|
state: this.state,
|
|
70
|
-
uptime:
|
|
72
|
+
uptime: 0,
|
|
71
73
|
memoryUsage: process.memoryUsage(),
|
|
72
74
|
children: this.hierarchyManager.getChildren().map((c) => c.toString()),
|
|
73
75
|
};
|
|
@@ -75,7 +77,7 @@ export function oTool(Base) {
|
|
|
75
77
|
async _tool_route(request) {
|
|
76
78
|
if (request.params.address === this.address.toString() ||
|
|
77
79
|
request.params.address === this.staticAddress.toString()) {
|
|
78
|
-
this.logger.
|
|
80
|
+
this.logger.verbose('Route to self, calling tool...');
|
|
79
81
|
const { payload } = request.params;
|
|
80
82
|
return this.callMyTool(new oRequest({
|
|
81
83
|
method: payload.method,
|
|
@@ -85,6 +87,12 @@ export function oTool(Base) {
|
|
|
85
87
|
}
|
|
86
88
|
return this.router.route(request, this);
|
|
87
89
|
}
|
|
90
|
+
async _tool_register_leader(request) {
|
|
91
|
+
await this.registerLeader();
|
|
92
|
+
return {
|
|
93
|
+
message: 'Leader registered',
|
|
94
|
+
};
|
|
95
|
+
}
|
|
88
96
|
async _tool_child_register(request) {
|
|
89
97
|
throw new oError(oErrorCodes.NOT_IMPLEMENTED, 'Child register not implemented');
|
|
90
98
|
}
|
|
@@ -96,5 +104,112 @@ export function oTool(Base) {
|
|
|
96
104
|
message: 'Request cancelled',
|
|
97
105
|
};
|
|
98
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Emit a notification event to all subscribers
|
|
109
|
+
* Can be called remotely to trigger events on this node
|
|
110
|
+
*/
|
|
111
|
+
async _tool_notify(request) {
|
|
112
|
+
const { eventType, eventData } = request.params;
|
|
113
|
+
if (!eventType) {
|
|
114
|
+
throw new oError(oErrorCodes.MISSING_PARAMETERS, 'eventType is required');
|
|
115
|
+
}
|
|
116
|
+
this.logger.debug(`Received remote notification: ${eventType}`);
|
|
117
|
+
// Create a generic notification event from the data
|
|
118
|
+
if (this.notificationManager) {
|
|
119
|
+
// Create a custom event class
|
|
120
|
+
class CustomNotificationEvent extends oNotificationEvent {
|
|
121
|
+
constructor(type, source, data) {
|
|
122
|
+
super({
|
|
123
|
+
type,
|
|
124
|
+
source,
|
|
125
|
+
metadata: data || {},
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// Emit as a custom event with the provided data
|
|
130
|
+
const sourceAddress = request.params.source
|
|
131
|
+
? new oAddress(request.params.source)
|
|
132
|
+
: new oAddress('o://unknown');
|
|
133
|
+
const event = new CustomNotificationEvent(eventType, sourceAddress, eventData);
|
|
134
|
+
this.notificationManager.emit(event);
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
success: true,
|
|
138
|
+
message: `Notification ${eventType} emitted`,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Get connection health status (for nodes with heartbeat monitoring)
|
|
143
|
+
*/
|
|
144
|
+
async _tool_get_connection_health(request) {
|
|
145
|
+
// Check if this node has a connectionHeartbeatManager
|
|
146
|
+
const heartbeatManager = this.connectionHeartbeatManager;
|
|
147
|
+
if (!heartbeatManager) {
|
|
148
|
+
return {
|
|
149
|
+
enabled: false,
|
|
150
|
+
message: 'Connection heartbeat not enabled on this node',
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
const healthStatus = heartbeatManager.getHealthStatus();
|
|
154
|
+
return {
|
|
155
|
+
enabled: true,
|
|
156
|
+
connections: healthStatus.map((h) => ({
|
|
157
|
+
address: h.address.toString(),
|
|
158
|
+
peerId: h.peerId,
|
|
159
|
+
status: h.status,
|
|
160
|
+
lastSuccessfulPing: new Date(h.lastSuccessfulPing).toISOString(),
|
|
161
|
+
consecutiveFailures: h.consecutiveFailures,
|
|
162
|
+
averageLatencyMs: Math.round(h.averageLatency),
|
|
163
|
+
})),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Get leader health status and retry configuration
|
|
168
|
+
*/
|
|
169
|
+
async _tool_get_leader_health(request) {
|
|
170
|
+
const heartbeatManager = this.connectionHeartbeatManager;
|
|
171
|
+
const leaderRequestWrapper = this.leaderRequestWrapper;
|
|
172
|
+
if (!heartbeatManager && !leaderRequestWrapper) {
|
|
173
|
+
return {
|
|
174
|
+
enabled: false,
|
|
175
|
+
message: 'Leader monitoring not available on this node',
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
const result = {
|
|
179
|
+
heartbeat: { enabled: false },
|
|
180
|
+
retry: { enabled: false },
|
|
181
|
+
};
|
|
182
|
+
// Get heartbeat health for leader
|
|
183
|
+
if (heartbeatManager) {
|
|
184
|
+
const config = heartbeatManager.getConfig();
|
|
185
|
+
result.heartbeat.enabled = config.checkLeader;
|
|
186
|
+
if (config.checkLeader) {
|
|
187
|
+
const healthStatus = heartbeatManager.getHealthStatus();
|
|
188
|
+
const leaderHealth = healthStatus.find((h) => h.address.toString().includes('leader'));
|
|
189
|
+
if (leaderHealth) {
|
|
190
|
+
result.heartbeat.status = leaderHealth.status;
|
|
191
|
+
result.heartbeat.lastSuccessfulPing = new Date(leaderHealth.lastSuccessfulPing).toISOString();
|
|
192
|
+
result.heartbeat.consecutiveFailures =
|
|
193
|
+
leaderHealth.consecutiveFailures;
|
|
194
|
+
result.heartbeat.averageLatencyMs = Math.round(leaderHealth.averageLatency);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
result.heartbeat.status = 'not_monitored';
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
// Get retry configuration
|
|
202
|
+
if (leaderRequestWrapper) {
|
|
203
|
+
const retryConfig = leaderRequestWrapper.getConfig();
|
|
204
|
+
result.retry = {
|
|
205
|
+
enabled: retryConfig.enabled,
|
|
206
|
+
maxAttempts: retryConfig.maxAttempts,
|
|
207
|
+
baseDelayMs: retryConfig.baseDelayMs,
|
|
208
|
+
maxDelayMs: retryConfig.maxDelayMs,
|
|
209
|
+
timeoutMs: retryConfig.timeoutMs,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
return result;
|
|
213
|
+
}
|
|
99
214
|
};
|
|
100
215
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@olane/o-tool",
|
|
3
|
-
"version": "0.7.12-alpha.
|
|
3
|
+
"version": "0.7.12-alpha.41",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -54,11 +54,11 @@
|
|
|
54
54
|
"typescript": "^5.8.3"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@olane/o-config": "0.7.12-alpha.
|
|
58
|
-
"@olane/o-core": "0.7.12-alpha.
|
|
59
|
-
"@olane/o-protocol": "0.7.12-alpha.
|
|
57
|
+
"@olane/o-config": "0.7.12-alpha.41",
|
|
58
|
+
"@olane/o-core": "0.7.12-alpha.41",
|
|
59
|
+
"@olane/o-protocol": "0.7.12-alpha.41",
|
|
60
60
|
"debug": "^4.4.1",
|
|
61
61
|
"dotenv": "^16.5.0"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "4d1ec96b34625cd8239e853411f0a970f4ea26e5"
|
|
64
64
|
}
|