@olane/o-tool 0.7.12-alpha.3 → 0.7.12-alpha.30

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 { oAddress, oConnection, oCore, oRequest } from '@olane/o-core';
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(nextHopAddress: oAddress, targetAddress: oAddress): Promise<oConnection>;
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,EACL,QAAQ,EACR,WAAW,EACX,KAAK,EAGL,QAAQ,EAET,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;IAI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AO,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"}
@@ -26,7 +26,7 @@ export class oToolBase extends oCore {
26
26
  configureTransports() {
27
27
  return [];
28
28
  }
29
- connect(nextHopAddress, targetAddress) {
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.debug('Calling tool: ' + method);
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.debug('Tool already indexed, skipping...');
106
+ this.logger.verbose('Tool already indexed, skipping...');
104
107
  return {
105
108
  summary: 'Tool already indexed',
106
109
  };
@@ -1 +1 @@
1
- {"version":3,"file":"o-tool.d.ts","sourceRoot":"","sources":["../../src/o-tool.ts"],"names":[],"mappings":"AAUA,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,CAoH7E"}
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,CAqQ7E"}
@@ -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
@@ -75,7 +75,7 @@ export function oTool(Base) {
75
75
  async _tool_route(request) {
76
76
  if (request.params.address === this.address.toString() ||
77
77
  request.params.address === this.staticAddress.toString()) {
78
- this.logger.debug('Route to self, calling tool...');
78
+ this.logger.verbose('Route to self, calling tool...');
79
79
  const { payload } = request.params;
80
80
  return this.callMyTool(new oRequest({
81
81
  method: payload.method,
@@ -85,6 +85,12 @@ export function oTool(Base) {
85
85
  }
86
86
  return this.router.route(request, this);
87
87
  }
88
+ async _tool_register_leader(request) {
89
+ await this.registerLeader();
90
+ return {
91
+ message: 'Leader registered',
92
+ };
93
+ }
88
94
  async _tool_child_register(request) {
89
95
  throw new oError(oErrorCodes.NOT_IMPLEMENTED, 'Child register not implemented');
90
96
  }
@@ -96,5 +102,112 @@ export function oTool(Base) {
96
102
  message: 'Request cancelled',
97
103
  };
98
104
  }
105
+ /**
106
+ * Emit a notification event to all subscribers
107
+ * Can be called remotely to trigger events on this node
108
+ */
109
+ async _tool_notify(request) {
110
+ const { eventType, eventData } = request.params;
111
+ if (!eventType) {
112
+ throw new oError(oErrorCodes.MISSING_PARAMETERS, 'eventType is required');
113
+ }
114
+ this.logger.debug(`Received remote notification: ${eventType}`);
115
+ // Create a generic notification event from the data
116
+ if (this.notificationManager) {
117
+ // Create a custom event class
118
+ class CustomNotificationEvent extends oNotificationEvent {
119
+ constructor(type, source, data) {
120
+ super({
121
+ type,
122
+ source,
123
+ metadata: data || {},
124
+ });
125
+ }
126
+ }
127
+ // Emit as a custom event with the provided data
128
+ const sourceAddress = request.params.source
129
+ ? new oAddress(request.params.source)
130
+ : new oAddress('o://unknown');
131
+ const event = new CustomNotificationEvent(eventType, sourceAddress, eventData);
132
+ this.notificationManager.emit(event);
133
+ }
134
+ return {
135
+ success: true,
136
+ message: `Notification ${eventType} emitted`,
137
+ };
138
+ }
139
+ /**
140
+ * Get connection health status (for nodes with heartbeat monitoring)
141
+ */
142
+ async _tool_get_connection_health(request) {
143
+ // Check if this node has a connectionHeartbeatManager
144
+ const heartbeatManager = this.connectionHeartbeatManager;
145
+ if (!heartbeatManager) {
146
+ return {
147
+ enabled: false,
148
+ message: 'Connection heartbeat not enabled on this node',
149
+ };
150
+ }
151
+ const healthStatus = heartbeatManager.getHealthStatus();
152
+ return {
153
+ enabled: true,
154
+ connections: healthStatus.map((h) => ({
155
+ address: h.address.toString(),
156
+ peerId: h.peerId,
157
+ status: h.status,
158
+ lastSuccessfulPing: new Date(h.lastSuccessfulPing).toISOString(),
159
+ consecutiveFailures: h.consecutiveFailures,
160
+ averageLatencyMs: Math.round(h.averageLatency),
161
+ })),
162
+ };
163
+ }
164
+ /**
165
+ * Get leader health status and retry configuration
166
+ */
167
+ async _tool_get_leader_health(request) {
168
+ const heartbeatManager = this.connectionHeartbeatManager;
169
+ const leaderRequestWrapper = this.leaderRequestWrapper;
170
+ if (!heartbeatManager && !leaderRequestWrapper) {
171
+ return {
172
+ enabled: false,
173
+ message: 'Leader monitoring not available on this node',
174
+ };
175
+ }
176
+ const result = {
177
+ heartbeat: { enabled: false },
178
+ retry: { enabled: false },
179
+ };
180
+ // Get heartbeat health for leader
181
+ if (heartbeatManager) {
182
+ const config = heartbeatManager.getConfig();
183
+ result.heartbeat.enabled = config.checkLeader;
184
+ if (config.checkLeader) {
185
+ const healthStatus = heartbeatManager.getHealthStatus();
186
+ const leaderHealth = healthStatus.find((h) => h.address.toString().includes('leader'));
187
+ if (leaderHealth) {
188
+ result.heartbeat.status = leaderHealth.status;
189
+ result.heartbeat.lastSuccessfulPing = new Date(leaderHealth.lastSuccessfulPing).toISOString();
190
+ result.heartbeat.consecutiveFailures =
191
+ leaderHealth.consecutiveFailures;
192
+ result.heartbeat.averageLatencyMs = Math.round(leaderHealth.averageLatency);
193
+ }
194
+ else {
195
+ result.heartbeat.status = 'not_monitored';
196
+ }
197
+ }
198
+ }
199
+ // Get retry configuration
200
+ if (leaderRequestWrapper) {
201
+ const retryConfig = leaderRequestWrapper.getConfig();
202
+ result.retry = {
203
+ enabled: retryConfig.enabled,
204
+ maxAttempts: retryConfig.maxAttempts,
205
+ baseDelayMs: retryConfig.baseDelayMs,
206
+ maxDelayMs: retryConfig.maxDelayMs,
207
+ timeoutMs: retryConfig.timeoutMs,
208
+ };
209
+ }
210
+ return result;
211
+ }
99
212
  };
100
213
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@olane/o-tool",
3
- "version": "0.7.12-alpha.3",
3
+ "version": "0.7.12-alpha.30",
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.3",
58
- "@olane/o-core": "0.7.12-alpha.3",
59
- "@olane/o-protocol": "^0.7.12-alpha.3",
57
+ "@olane/o-config": "0.7.12-alpha.30",
58
+ "@olane/o-core": "0.7.12-alpha.30",
59
+ "@olane/o-protocol": "0.7.12-alpha.30",
60
60
  "debug": "^4.4.1",
61
61
  "dotenv": "^16.5.0"
62
62
  },
63
- "gitHead": "5c05e5f248001abc38f34c77bd97c9a325231503"
63
+ "gitHead": "066e6bda19e79a744779a797664481476b0ea655"
64
64
  }