@olane/o-core 0.6.13 → 0.7.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.
Files changed (257) hide show
  1. package/README.md +490 -140
  2. package/dist/src/connection/index.d.ts +8 -0
  3. package/dist/src/connection/index.d.ts.map +1 -0
  4. package/dist/src/connection/index.js +7 -0
  5. package/dist/src/connection/interfaces/connection-manager.config.d.ts +3 -0
  6. package/dist/src/connection/interfaces/connection-manager.config.d.ts.map +1 -0
  7. package/dist/src/connection/interfaces/connection-send-params.interface.d.ts.map +1 -0
  8. package/dist/src/connection/interfaces/connection.config.d.ts +7 -0
  9. package/dist/src/connection/interfaces/connection.config.d.ts.map +1 -0
  10. package/dist/src/connection/interfaces/index.d.ts +5 -0
  11. package/dist/src/connection/interfaces/index.d.ts.map +1 -0
  12. package/dist/src/connection/interfaces/index.js +4 -0
  13. package/dist/src/connection/interfaces/request-state.enum.d.ts +7 -0
  14. package/dist/src/connection/interfaces/request-state.enum.d.ts.map +1 -0
  15. package/dist/src/connection/interfaces/request-state.enum.js +7 -0
  16. package/dist/src/connection/o-connection-manager.d.ts +19 -0
  17. package/dist/src/connection/o-connection-manager.d.ts.map +1 -0
  18. package/dist/src/connection/o-connection-manager.js +27 -0
  19. package/dist/src/connection/o-connection.d.ts +20 -0
  20. package/dist/src/connection/o-connection.d.ts.map +1 -0
  21. package/dist/src/connection/o-connection.js +45 -0
  22. package/dist/src/{core/lib → connection}/o-request.d.ts +5 -1
  23. package/dist/src/connection/o-request.d.ts.map +1 -0
  24. package/dist/src/{core/lib → connection}/o-request.js +8 -1
  25. package/dist/src/connection/o-response.d.ts.map +1 -0
  26. package/dist/src/core/defaults/config.d.ts +1 -1
  27. package/dist/src/core/defaults/config.d.ts.map +1 -1
  28. package/dist/src/core/defaults/config.js +1 -1
  29. package/dist/src/core/graceful-shutdown.d.ts +1 -1
  30. package/dist/src/core/graceful-shutdown.d.ts.map +1 -1
  31. package/dist/src/core/graceful-shutdown.js +1 -1
  32. package/dist/src/core/index.d.ts +3 -5
  33. package/dist/src/core/index.d.ts.map +1 -1
  34. package/dist/src/core/index.js +3 -5
  35. package/dist/src/core/interfaces/index.d.ts +1 -2
  36. package/dist/src/core/interfaces/index.d.ts.map +1 -1
  37. package/dist/src/core/interfaces/index.js +1 -2
  38. package/dist/src/core/interfaces/{core-config.interface.d.ts → o-core.config.d.ts} +4 -5
  39. package/dist/src/core/interfaces/o-core.config.d.ts.map +1 -0
  40. package/dist/src/core/interfaces/o-core.interface.d.ts +18 -0
  41. package/dist/src/core/interfaces/o-core.interface.d.ts.map +1 -0
  42. package/dist/src/core/lib/index.d.ts +3 -7
  43. package/dist/src/core/lib/index.d.ts.map +1 -1
  44. package/dist/src/core/lib/index.js +3 -7
  45. package/dist/src/core/lib/o-hierarchy.manager.d.ts +24 -0
  46. package/dist/src/core/lib/o-hierarchy.manager.d.ts.map +1 -0
  47. package/dist/src/core/lib/o-hierarchy.manager.js +57 -0
  48. package/dist/src/core/lib/o-metrics.d.ts +5 -0
  49. package/dist/src/core/lib/o-metrics.d.ts.map +1 -0
  50. package/dist/src/core/lib/o-metrics.js +6 -0
  51. package/dist/src/core/lib/o-request.manager.d.ts +10 -0
  52. package/dist/src/core/lib/o-request.manager.d.ts.map +1 -0
  53. package/dist/src/core/lib/o-request.manager.js +18 -0
  54. package/dist/src/core/o-core.d.ts +190 -0
  55. package/dist/src/core/o-core.d.ts.map +1 -0
  56. package/dist/src/core/o-core.js +334 -0
  57. package/dist/src/core/o-object.d.ts +7 -0
  58. package/dist/src/core/o-object.d.ts.map +1 -0
  59. package/dist/src/core/o-object.js +10 -0
  60. package/dist/src/error/enums/codes.error.d.ts +16 -14
  61. package/dist/src/error/enums/codes.error.d.ts.map +1 -1
  62. package/dist/src/error/enums/codes.error.js +18 -16
  63. package/dist/src/error/index.d.ts +1 -1
  64. package/dist/src/error/index.d.ts.map +1 -1
  65. package/dist/src/error/index.js +1 -1
  66. package/dist/src/error/interfaces/o-error.interface.d.ts +6 -0
  67. package/dist/src/error/interfaces/o-error.interface.d.ts.map +1 -0
  68. package/dist/src/error/o-error.d.ts +15 -0
  69. package/dist/src/error/o-error.d.ts.map +1 -0
  70. package/dist/src/error/{tool.error.js → o-error.js} +4 -4
  71. package/dist/src/index.d.ts +3 -3
  72. package/dist/src/index.d.ts.map +1 -1
  73. package/dist/src/index.js +3 -3
  74. package/dist/src/router/enums/restricted-addresses.enum.d.ts +8 -0
  75. package/dist/src/router/enums/restricted-addresses.enum.d.ts.map +1 -0
  76. package/dist/src/router/enums/restricted-addresses.enum.js +13 -0
  77. package/dist/src/router/index.d.ts +9 -0
  78. package/dist/src/router/index.d.ts.map +1 -0
  79. package/dist/src/router/index.js +8 -0
  80. package/dist/src/router/interfaces/resolve.request.d.ts +10 -0
  81. package/dist/src/router/interfaces/resolve.request.d.ts.map +1 -0
  82. package/dist/src/router/interfaces/route.response.d.ts +8 -0
  83. package/dist/src/router/interfaces/route.response.d.ts.map +1 -0
  84. package/dist/src/router/o-address-resolution.d.ts +12 -0
  85. package/dist/src/router/o-address-resolution.d.ts.map +1 -0
  86. package/dist/src/router/o-address-resolution.js +42 -0
  87. package/dist/src/router/o-address-resolver.d.ts +14 -0
  88. package/dist/src/router/o-address-resolver.d.ts.map +1 -0
  89. package/dist/src/router/o-address-resolver.js +19 -0
  90. package/dist/src/router/o-address.d.ts +33 -0
  91. package/dist/src/router/o-address.d.ts.map +1 -0
  92. package/dist/src/router/o-address.js +101 -0
  93. package/dist/src/router/o-request.router.d.ts +18 -0
  94. package/dist/src/router/o-request.router.d.ts.map +1 -0
  95. package/dist/src/router/o-request.router.js +12 -0
  96. package/dist/src/router/o-router.d.ts +19 -0
  97. package/dist/src/router/o-router.d.ts.map +1 -0
  98. package/dist/src/router/o-router.js +14 -0
  99. package/dist/src/transports/custom.transport.d.ts +6 -0
  100. package/dist/src/transports/custom.transport.d.ts.map +1 -0
  101. package/dist/src/transports/custom.transport.js +10 -0
  102. package/dist/src/transports/index.d.ts +4 -0
  103. package/dist/src/transports/index.d.ts.map +1 -0
  104. package/dist/src/transports/index.js +3 -0
  105. package/dist/src/transports/interfaces/transport-type.enum.d.ts +5 -0
  106. package/dist/src/transports/interfaces/transport-type.enum.d.ts.map +1 -0
  107. package/dist/src/transports/interfaces/transport-type.enum.js +5 -0
  108. package/dist/src/transports/o-transport.d.ts +10 -0
  109. package/dist/src/transports/o-transport.d.ts.map +1 -0
  110. package/dist/src/transports/o-transport.js +16 -0
  111. package/dist/src/{core/utils → utils}/core.utils.d.ts +4 -3
  112. package/dist/src/utils/core.utils.d.ts.map +1 -0
  113. package/dist/src/{core/utils → utils}/core.utils.js +17 -2
  114. package/dist/src/utils/index.d.ts +2 -0
  115. package/dist/src/utils/index.d.ts.map +1 -1
  116. package/dist/src/utils/index.js +2 -0
  117. package/dist/src/{core/utils → utils}/logger.d.ts +1 -0
  118. package/dist/src/utils/logger.d.ts.map +1 -0
  119. package/dist/src/{core/utils → utils}/logger.js +4 -1
  120. package/dist/test/server/in-process.spec.js +2 -14
  121. package/package.json +3 -3
  122. package/dist/src/core/core.node.d.ts +0 -79
  123. package/dist/src/core/core.node.d.ts.map +0 -1
  124. package/dist/src/core/core.node.js +0 -304
  125. package/dist/src/core/interfaces/connection-manager.config.d.ts +0 -7
  126. package/dist/src/core/interfaces/connection-manager.config.d.ts.map +0 -1
  127. package/dist/src/core/interfaces/connection-send-params.interface.d.ts.map +0 -1
  128. package/dist/src/core/interfaces/core-config.interface.d.ts.map +0 -1
  129. package/dist/src/core/interfaces/restricted-addresses.enum.d.ts +0 -13
  130. package/dist/src/core/interfaces/restricted-addresses.enum.d.ts.map +0 -1
  131. package/dist/src/core/interfaces/restricted-addresses.enum.js +0 -18
  132. package/dist/src/core/lib/o-address-resolution.d.ts +0 -9
  133. package/dist/src/core/lib/o-address-resolution.d.ts.map +0 -1
  134. package/dist/src/core/lib/o-address-resolution.js +0 -24
  135. package/dist/src/core/lib/o-address-resolver.d.ts +0 -17
  136. package/dist/src/core/lib/o-address-resolver.d.ts.map +0 -1
  137. package/dist/src/core/lib/o-address-resolver.js +0 -36
  138. package/dist/src/core/lib/o-connection-manager.d.ts +0 -22
  139. package/dist/src/core/lib/o-connection-manager.d.ts.map +0 -1
  140. package/dist/src/core/lib/o-connection-manager.js +0 -65
  141. package/dist/src/core/lib/o-connection.d.ts +0 -27
  142. package/dist/src/core/lib/o-connection.d.ts.map +0 -1
  143. package/dist/src/core/lib/o-connection.js +0 -84
  144. package/dist/src/core/lib/o-request.d.ts.map +0 -1
  145. package/dist/src/core/lib/o-response.d.ts.map +0 -1
  146. package/dist/src/core/lib/resolvers/anything.resolver.d.ts +0 -8
  147. package/dist/src/core/lib/resolvers/anything.resolver.d.ts.map +0 -1
  148. package/dist/src/core/lib/resolvers/anything.resolver.js +0 -15
  149. package/dist/src/core/lib/resolvers/index.d.ts +0 -5
  150. package/dist/src/core/lib/resolvers/index.d.ts.map +0 -1
  151. package/dist/src/core/lib/resolvers/index.js +0 -4
  152. package/dist/src/core/lib/resolvers/method.resolver.d.ts +0 -8
  153. package/dist/src/core/lib/resolvers/method.resolver.d.ts.map +0 -1
  154. package/dist/src/core/lib/resolvers/method.resolver.js +0 -18
  155. package/dist/src/core/lib/resolvers/next-hop.resolver.d.ts +0 -10
  156. package/dist/src/core/lib/resolvers/next-hop.resolver.d.ts.map +0 -1
  157. package/dist/src/core/lib/resolvers/next-hop.resolver.js +0 -59
  158. package/dist/src/core/lib/resolvers/storage.resolver.d.ts +0 -6
  159. package/dist/src/core/lib/resolvers/storage.resolver.d.ts.map +0 -1
  160. package/dist/src/core/lib/resolvers/storage.resolver.js +0 -10
  161. package/dist/src/core/o-address.d.ts +0 -20
  162. package/dist/src/core/o-address.d.ts.map +0 -1
  163. package/dist/src/core/o-address.js +0 -47
  164. package/dist/src/core/utils/core.utils.d.ts.map +0 -1
  165. package/dist/src/core/utils/index.d.ts +0 -4
  166. package/dist/src/core/utils/index.d.ts.map +0 -1
  167. package/dist/src/core/utils/index.js +0 -3
  168. package/dist/src/core/utils/logger.d.ts.map +0 -1
  169. package/dist/src/core/utils/network.utils.d.ts +0 -16
  170. package/dist/src/core/utils/network.utils.d.ts.map +0 -1
  171. package/dist/src/core/utils/network.utils.js +0 -35
  172. package/dist/src/error/tool.error.d.ts +0 -19
  173. package/dist/src/error/tool.error.d.ts.map +0 -1
  174. package/dist/src/node/index.d.ts +0 -4
  175. package/dist/src/node/index.d.ts.map +0 -1
  176. package/dist/src/node/index.js +0 -3
  177. package/dist/src/node/interfaces/route.request.d.ts +0 -14
  178. package/dist/src/node/interfaces/route.request.d.ts.map +0 -1
  179. package/dist/src/node/lib/local-search.lib.d.ts +0 -6
  180. package/dist/src/node/lib/local-search.lib.d.ts.map +0 -1
  181. package/dist/src/node/lib/local-search.lib.js +0 -10
  182. package/dist/src/node/lib/network-activity.lib.d.ts +0 -12
  183. package/dist/src/node/lib/network-activity.lib.d.ts.map +0 -1
  184. package/dist/src/node/lib/network-activity.lib.js +0 -29
  185. package/dist/src/node/node.d.ts +0 -45
  186. package/dist/src/node/node.d.ts.map +0 -1
  187. package/dist/src/node/node.js +0 -359
  188. package/dist/src/node-virtual/index.d.ts +0 -2
  189. package/dist/src/node-virtual/index.d.ts.map +0 -1
  190. package/dist/src/node-virtual/index.js +0 -1
  191. package/dist/src/node-virtual/virtual.node.d.ts +0 -10
  192. package/dist/src/node-virtual/virtual.node.d.ts.map +0 -1
  193. package/dist/src/node-virtual/virtual.node.js +0 -12
  194. package/dist/src/plan/agent.plan.d.ts +0 -28
  195. package/dist/src/plan/agent.plan.d.ts.map +0 -1
  196. package/dist/src/plan/agent.plan.js +0 -187
  197. package/dist/src/plan/index.d.ts +0 -5
  198. package/dist/src/plan/index.d.ts.map +0 -1
  199. package/dist/src/plan/index.js +0 -4
  200. package/dist/src/plan/interfaces/configure.result.d.ts +0 -6
  201. package/dist/src/plan/interfaces/configure.result.d.ts.map +0 -1
  202. package/dist/src/plan/interfaces/handshake.result.d.ts +0 -14
  203. package/dist/src/plan/interfaces/handshake.result.d.ts.map +0 -1
  204. package/dist/src/plan/interfaces/plan-config.interface.d.ts +0 -16
  205. package/dist/src/plan/interfaces/plan-config.interface.d.ts.map +0 -1
  206. package/dist/src/plan/interfaces/plan-result.interface.d.ts +0 -6
  207. package/dist/src/plan/interfaces/plan-result.interface.d.ts.map +0 -1
  208. package/dist/src/plan/interfaces/plan-type.enum.d.ts +0 -8
  209. package/dist/src/plan/interfaces/plan-type.enum.d.ts.map +0 -1
  210. package/dist/src/plan/interfaces/plan-type.enum.js +0 -8
  211. package/dist/src/plan/interfaces/plan.result.d.ts +0 -15
  212. package/dist/src/plan/interfaces/plan.result.d.ts.map +0 -1
  213. package/dist/src/plan/interfaces/plan.result.js +0 -1
  214. package/dist/src/plan/interfaces/query.config.d.ts +0 -6
  215. package/dist/src/plan/interfaces/query.config.d.ts.map +0 -1
  216. package/dist/src/plan/interfaces/query.config.js +0 -1
  217. package/dist/src/plan/interfaces/task.config.d.ts +0 -10
  218. package/dist/src/plan/interfaces/task.config.d.ts.map +0 -1
  219. package/dist/src/plan/interfaces/task.config.js +0 -1
  220. package/dist/src/plan/o-plan.d.ts +0 -36
  221. package/dist/src/plan/o-plan.d.ts.map +0 -1
  222. package/dist/src/plan/o-plan.js +0 -202
  223. package/dist/src/plan/plan.context.d.ts +0 -10
  224. package/dist/src/plan/plan.context.d.ts.map +0 -1
  225. package/dist/src/plan/plan.context.js +0 -28
  226. package/dist/src/plan/prompts/agent.prompt.d.ts +0 -2
  227. package/dist/src/plan/prompts/agent.prompt.d.ts.map +0 -1
  228. package/dist/src/plan/prompts/agent.prompt.js +0 -112
  229. package/dist/src/plan/prompts/configure.prompt.d.ts +0 -2
  230. package/dist/src/plan/prompts/configure.prompt.d.ts.map +0 -1
  231. package/dist/src/plan/prompts/configure.prompt.js +0 -40
  232. package/dist/src/plan/prompts/custom.prompt.d.ts +0 -2
  233. package/dist/src/plan/prompts/custom.prompt.d.ts.map +0 -1
  234. package/dist/src/plan/prompts/custom.prompt.js +0 -80
  235. package/dist/src/plan/search/prompts/search-analysis.prompt.d.ts +0 -2
  236. package/dist/src/plan/search/prompts/search-analysis.prompt.d.ts.map +0 -1
  237. package/dist/src/plan/search/prompts/search-analysis.prompt.js +0 -14
  238. package/dist/src/plan/search/search.plan.d.ts +0 -21
  239. package/dist/src/plan/search/search.plan.d.ts.map +0 -1
  240. package/dist/src/plan/search/search.plan.js +0 -53
  241. package/dist/src/plan/use/index.d.ts +0 -2
  242. package/dist/src/plan/use/index.d.ts.map +0 -1
  243. package/dist/src/plan/use/index.js +0 -1
  244. package/dist/src/plan/use/use.plan.d.ts +0 -16
  245. package/dist/src/plan/use/use.plan.d.ts.map +0 -1
  246. package/dist/src/plan/use/use.plan.js +0 -149
  247. /package/dist/src/{core → connection}/interfaces/connection-manager.config.js +0 -0
  248. /package/dist/src/{core → connection}/interfaces/connection-send-params.interface.d.ts +0 -0
  249. /package/dist/src/{core → connection}/interfaces/connection-send-params.interface.js +0 -0
  250. /package/dist/src/{core/interfaces/core-config.interface.js → connection/interfaces/connection.config.js} +0 -0
  251. /package/dist/src/{core/lib → connection}/o-response.d.ts +0 -0
  252. /package/dist/src/{core/lib → connection}/o-response.js +0 -0
  253. /package/dist/src/{node/interfaces/route.request.js → core/interfaces/o-core.config.js} +0 -0
  254. /package/dist/src/{plan/interfaces/configure.result.js → core/interfaces/o-core.interface.js} +0 -0
  255. /package/dist/src/{plan/interfaces/handshake.result.js → error/interfaces/o-error.interface.js} +0 -0
  256. /package/dist/src/{plan/interfaces/plan-config.interface.js → router/interfaces/resolve.request.js} +0 -0
  257. /package/dist/src/{plan/interfaces/plan-result.interface.js → router/interfaces/route.response.js} +0 -0
@@ -1,29 +0,0 @@
1
- export const NETWORK_ACTIVITY_EVENTS = [
2
- 'peer:connect',
3
- 'peer:disconnect',
4
- 'peer:update',
5
- 'peer:discovery',
6
- 'peer:reconnect-failure',
7
- 'peer:identify',
8
- 'transport:listening',
9
- 'transport:close',
10
- 'connection:prune',
11
- 'connection:open',
12
- 'connection:close',
13
- 'certificate:provision',
14
- 'certificate:renew',
15
- ];
16
- export class NetworkActivity {
17
- constructor(logger, p2pNode) {
18
- this.logger = logger;
19
- this.p2pNode = p2pNode;
20
- this.setup();
21
- }
22
- setup() {
23
- for (const event of NETWORK_ACTIVITY_EVENTS) {
24
- this.p2pNode.addEventListener(event, (evt) => {
25
- this.logger.debug('Network activity: ', event, evt.detail);
26
- });
27
- }
28
- }
29
- }
@@ -1,45 +0,0 @@
1
- import { Libp2pConfig } from '@olane/o-config';
2
- import { oAddress, oCoreNode, oRequest, oResponse } from '../core/index.js';
3
- import { NetworkActivity } from './lib/network-activity.lib.js';
4
- import { CID } from 'multiformats';
5
- import { oHandshakeResult } from '../plan/interfaces/handshake.result.js';
6
- import { RouteRequest } from './interfaces/route.request.js';
7
- export declare abstract class oNode extends oCoreNode {
8
- networkActivity: NetworkActivity;
9
- childNodes: oNode[];
10
- childAddresses: oAddress[];
11
- validate(): void;
12
- _tool_handshake(handshake: oRequest): Promise<oHandshakeResult>;
13
- abstract configureTransports(): any[];
14
- myTools(obj?: any): string[];
15
- applyBridgeTransports(address: oAddress, request: oRequest): Promise<oResponse>;
16
- matchAgainstMethods(address: oAddress): Promise<boolean>;
17
- extractMethod(address: oAddress): string;
18
- _tool_route(request: RouteRequest): Promise<any>;
19
- /**
20
- * Where all intents go to be resolved.
21
- * @param request
22
- * @returns
23
- */
24
- _tool_intent(request: oRequest): Promise<any>;
25
- _tool_child_register(request: oRequest): Promise<any>;
26
- start(): Promise<void>;
27
- startChildren(): Promise<void>;
28
- validateJoinRequest(request: oRequest): Promise<any>;
29
- _tool_add_child(request: oRequest): Promise<any>;
30
- addChildNode(node: oNode): void;
31
- removeChildNode(node: oNode): void;
32
- /**
33
- * Configure the libp2p node
34
- * @returns The libp2p config
35
- */
36
- configure(): Promise<Libp2pConfig>;
37
- initialize(): Promise<void>;
38
- dhtProvide(value: CID): Promise<void>;
39
- advertiseValueToNetwork(value: CID): Promise<void>;
40
- get isServer(): boolean;
41
- advertiseToNetwork(): Promise<void>;
42
- listenForNetworkEvents(): void;
43
- teardown(): Promise<void>;
44
- }
45
- //# sourceMappingURL=node.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../src/node/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,YAAY,EAMb,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAIL,QAAQ,EAER,SAAS,EACT,QAAQ,EACR,SAAS,EACV,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAMhE,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAK7D,8BAAsB,KAAM,SAAQ,SAAS;IACpC,eAAe,EAAG,eAAe,CAAC;IAClC,UAAU,EAAE,KAAK,EAAE,CAAM;IACzB,cAAc,EAAE,QAAQ,EAAE,CAAM;IAEvC,QAAQ,IAAI,IAAI;IASV,eAAe,CAAC,SAAS,EAAE,QAAQ,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAkBrE,QAAQ,CAAC,mBAAmB,IAAI,GAAG,EAAE;IAErC,OAAO,CAAC,GAAG,CAAC,EAAE,GAAG,GAAG,MAAM,EAAE;IAOtB,qBAAqB,CACzB,OAAO,EAAE,QAAQ,EACjB,OAAO,EAAE,QAAQ,GAChB,OAAO,CAAC,SAAS,CAAC;IAOf,mBAAmB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;IAS9D,aAAa,CAAC,OAAO,EAAE,QAAQ,GAAG,MAAM;IAIlC,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC;IA8EtD;;;;OAIG;IACG,YAAY,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;IAiC7C,oBAAoB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;IASrD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAOtB,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IA2C9B,mBAAmB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;IAIpD,eAAe,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;IAYtD,YAAY,CAAC,IAAI,EAAE,KAAK,GAAG,IAAI;IAK/B,eAAe,CAAC,IAAI,EAAE,KAAK,GAAG,IAAI;IAIlC;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC,YAAY,CAAC;IAqFlC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAyB3B,UAAU,CAAC,KAAK,EAAE,GAAG;IAiBrB,uBAAuB,CAAC,KAAK,EAAE,GAAG;IAiBxC,IAAI,QAAQ,IAAI,OAAO,CAItB;IAEK,kBAAkB;IA6BxB,sBAAsB;IAIhB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAOhC"}
@@ -1,359 +0,0 @@
1
- import { bootstrap, createNode, defaultLibp2pConfig, multiaddr, pipe, pushable, } from '@olane/o-config';
2
- import { CoreUtils, NodeState, NodeType, oAddress, oConnectionManager, oCoreNode, oRequest, } from '../core/index.js';
3
- import { NextHopResolver } from '../core/lib/resolvers/next-hop.resolver.js';
4
- import { NetworkActivity } from './lib/network-activity.lib.js';
5
- import { oToolError } from '../error/tool.error.js';
6
- import { oToolErrorCodes } from '../error/enums/codes.error.js';
7
- import { oAgentPlan } from '../plan/agent.plan.js';
8
- import { oPlanContext } from '../plan/plan.context.js';
9
- import { v4 as uuidv4 } from 'uuid';
10
- // Enable default Node.js metrics
11
- // collectDefaultMetrics({ register: sharedRegistry });
12
- export class oNode extends oCoreNode {
13
- constructor() {
14
- super(...arguments);
15
- this.childNodes = [];
16
- this.childAddresses = [];
17
- }
18
- validate() {
19
- if (this.p2pNode && this.state !== NodeState.STOPPED) {
20
- throw new Error('Node is not in a valid state to be initialized');
21
- }
22
- if (!this.address.validate()) {
23
- throw new Error('Invalid address');
24
- }
25
- }
26
- async _tool_handshake(handshake) {
27
- this.logger.debug('Performing handshake with intent: ', handshake.params.intent);
28
- const mytools = await this.myTools();
29
- return {
30
- tools: mytools.filter((t) => t !== 'handshake' && t !== 'intent'),
31
- methods: this.methods,
32
- successes: [],
33
- failures: [],
34
- task: undefined,
35
- type: 'handshake',
36
- };
37
- }
38
- myTools(obj) {
39
- return Object.getOwnPropertyNames(obj || this.constructor.prototype)
40
- .filter((key) => key.startsWith('_tool_'))
41
- .filter((key) => !!key)
42
- .map((key) => key.replace('_tool_', ''));
43
- }
44
- async applyBridgeTransports(address, request) {
45
- throw new oToolError(oToolErrorCodes.TOOL_TRANSPORT_NOT_SUPPORTED, 'Bridge transports not implemented');
46
- }
47
- async matchAgainstMethods(address) {
48
- const methods = await this.myTools();
49
- this.logger.debug('Matching against methods: ', methods);
50
- const method = address
51
- .toString()
52
- .replace(this.address.toString() + '/', '');
53
- return methods.includes(method || '');
54
- }
55
- extractMethod(address) {
56
- return address.protocol.split('/').pop() || '';
57
- }
58
- async _tool_route(request) {
59
- const { payload } = request.params;
60
- const { address } = request.params;
61
- this.logger.debug('Routing request to: ', address);
62
- const destinationAddress = new oAddress(address);
63
- // determine the next hop address from the encapsulated address
64
- const nextHopAddress = await this.addressResolution.resolve(destinationAddress);
65
- this.logger.debug('Next hop address: ', nextHopAddress.toString(), nextHopAddress.transports);
66
- // prepare the request for the destination receiver
67
- let forwardRequest = new oRequest({
68
- params: payload.params,
69
- id: request.id,
70
- method: payload.method,
71
- });
72
- // if the next hop is not a libp2p address, we need to communicate to it another way
73
- if (this.addressResolution.supportsTransport(nextHopAddress)) {
74
- this.logger.debug('Bridge transports supported, applying custom transports...');
75
- this.logger.debug('Next hop address: BRENDON!');
76
- // attempt to resolve with bridge transports
77
- return this.applyBridgeTransports(nextHopAddress, forwardRequest);
78
- }
79
- // assume the next hop is a libp2p address, so we need to set the transports and dial it
80
- nextHopAddress.setTransports(this.getTransports(nextHopAddress));
81
- const isAtDestination = nextHopAddress.value === destinationAddress.value;
82
- // if we are at the destination, let's look for the closest tool that can service the request
83
- const transports = nextHopAddress.transports.filter((t) => typeof t !== 'string');
84
- const isMethodMatch = await this.matchAgainstMethods(destinationAddress);
85
- // handle address -> method resolution
86
- if (isMethodMatch) {
87
- this.logger.debug('Method match found, forwarding to self...');
88
- const extractedMethod = this.extractMethod(destinationAddress);
89
- try {
90
- const response = await this.use(this.address, {
91
- method: payload.method || extractedMethod,
92
- params: payload.params,
93
- });
94
- return response.result.data;
95
- }
96
- catch (error) {
97
- return error;
98
- }
99
- }
100
- const targetStream = await this.p2pNode.dialProtocol(transports, nextHopAddress.protocol);
101
- // if not at destination, we need to forward the request to the target
102
- if (!isAtDestination) {
103
- forwardRequest = new oRequest(request);
104
- }
105
- else {
106
- this.logger.debug('At destination!');
107
- }
108
- const pushableStream = pushable();
109
- pushableStream.push(new TextEncoder().encode(forwardRequest.toString()));
110
- pushableStream.end();
111
- await targetStream.sink(pushableStream);
112
- await pipe(targetStream.source, request.stream.sink);
113
- }
114
- /**
115
- * Where all intents go to be resolved.
116
- * @param request
117
- * @returns
118
- */
119
- async _tool_intent(request) {
120
- this.logger.debug('Intent resolution called: ', request.params);
121
- const { intent, context, streamTo } = request.params;
122
- const pc = new oAgentPlan({
123
- intent: intent,
124
- currentNode: this,
125
- caller: this.address,
126
- streamTo: new oAddress(streamTo),
127
- context: context
128
- ? new oPlanContext([
129
- `[Chat History Context Begin]\n${context}\n[Chat History Context End]`,
130
- ])
131
- : undefined,
132
- shouldContinue: () => {
133
- return !!this.requests[request.id];
134
- },
135
- });
136
- const response = await pc.execute();
137
- return {
138
- ...response,
139
- cycles: pc.sequence.length,
140
- sequence: pc.sequence.map((s) => {
141
- return {
142
- reasoning: s.result?.reasoning,
143
- result: s.result?.result,
144
- error: s.result?.error,
145
- type: s.result?.type,
146
- };
147
- }),
148
- };
149
- }
150
- async _tool_child_register(request) {
151
- const { address } = request.params;
152
- const childAddress = new oAddress(address);
153
- this.childAddresses.push(childAddress);
154
- return {
155
- message: 'Child node registered with parent!',
156
- };
157
- }
158
- async start() {
159
- await super.start();
160
- await this.startChildren();
161
- await this.advertiseToNetwork();
162
- }
163
- // deprecated virtual node startup
164
- async startChildren() {
165
- this.logger.debug('Initializing contained children nodes...', this.childNodes.length);
166
- await Promise.all(this.childNodes.map(async (node) => {
167
- try {
168
- if (node.state !== NodeState.STOPPED) {
169
- return;
170
- }
171
- node.config.parent = this.address;
172
- // forward the network leader address to the child node
173
- if (this.type === NodeType.LEADER) {
174
- node.config.leader = this.address;
175
- }
176
- else {
177
- node.config.leader = this.config.leader;
178
- }
179
- node.config.parent = this.address;
180
- // node.address = CoreUtils.childAddress(this.address, node.address);
181
- this.logger.debug('Starting virtual node: ' +
182
- node.address.toString() +
183
- ' with parent transports: ' +
184
- node.parentTransports.join(', '));
185
- await node.start();
186
- this.logger.debug('Child node started: ', node.address.toString());
187
- // test the connection to the child node to add it to the p2p network peer store
188
- await this.connect(node.address, node.address);
189
- }
190
- catch (error) {
191
- this.logger.error('Failed to start virtual node: ' + node.address.toString(), error);
192
- }
193
- }));
194
- // await new Promise((resolve) => setTimeout(resolve, 1_000));
195
- }
196
- async validateJoinRequest(request) {
197
- return true;
198
- }
199
- async _tool_add_child(request) {
200
- const { address, transports } = request.params;
201
- const childAddress = new oAddress(address, transports.map((t) => multiaddr(t)));
202
- this.childAddresses.push(childAddress);
203
- return {
204
- message: 'Child node registered with parent!',
205
- };
206
- }
207
- addChildNode(node) {
208
- this.logger.debug('Adding virtual node: ' + node.address.toString());
209
- this.childNodes.push(node);
210
- }
211
- removeChildNode(node) {
212
- this.childNodes = this.childNodes.filter((n) => n !== node);
213
- }
214
- /**
215
- * Configure the libp2p node
216
- * @returns The libp2p config
217
- */
218
- async configure() {
219
- const params = {
220
- ...this.networkConfig,
221
- transports: this.configureTransports(),
222
- connectionManager: {
223
- ...(this.networkConfig.connectionManager || {
224
- minConnections: 10, // Keep at least 10 connections
225
- maxConnections: 100, // Allow up to 100 connections
226
- pollInterval: 2000, // Check connections every 2 seconds
227
- autoDialInterval: 10000, // Auto-dial new peers every 10 seconds
228
- dialTimeout: 30000, // 30 second dial timeout
229
- }),
230
- },
231
- listeners: (this.config.network?.listeners ||
232
- defaultLibp2pConfig.listeners ||
233
- []).concat(`/memory/${uuidv4()}`), // ensure we allow for local in-memory communication
234
- };
235
- // if the seed is provided, use it to generate the private key
236
- if (this.config.seed) {
237
- this.logger.debug('Seed provided, generating private key...');
238
- const privateKey = await CoreUtils.generatePrivateKey(this.config.seed);
239
- params.privateKey = privateKey;
240
- }
241
- else {
242
- this.logger.debug('No seed provided, generating private key...');
243
- this.logger.debug('Without providing a seed, this node peer id will be destroyed after the node shuts down.');
244
- // TODO: add a link to documentation about how to setup a seed
245
- }
246
- // if config.bootstrapTransports is provided, use it to bootstrap the node
247
- const leaderTransports = this.config.leader?.transports;
248
- if (leaderTransports && leaderTransports.length > 0) {
249
- this.leaders = leaderTransports;
250
- }
251
- // this is a child node of the network, so communication is heavily restricted
252
- if (this.parentTransports.length > 0) {
253
- // peer discovery is only allowed through the parent transports
254
- params.peerDiscovery = [
255
- bootstrap({
256
- list: [...this.parentTransports.map((t) => t.toString())],
257
- }),
258
- ...(defaultLibp2pConfig.peerDiscovery || []),
259
- ];
260
- // // let's make sure we only allow communication through the parent transports
261
- params.connectionGater = {
262
- // who can call us?
263
- denyInboundEncryptedConnection: (peerId, maConn) => {
264
- // deny all inbound connections unless they are from a parent transport
265
- if (this.parentPeerId === peerId.toString()) {
266
- return false;
267
- }
268
- // allow leader inbounds
269
- if (this.config.type === NodeType.LEADER) {
270
- return false;
271
- }
272
- // deny everything else
273
- return true;
274
- },
275
- // allow the user to override the default connection gater
276
- ...(this.config.network?.connectionGater || {}),
277
- };
278
- }
279
- // handle the address encapsulation
280
- if (this.config.leader &&
281
- !this.address.protocol.includes(this.config.leader.protocol)) {
282
- const parentAddress = this.config.parent || this.config.leader;
283
- this.logger.debug('Encapsulating address: ' + this.address.toString(), parentAddress.toString());
284
- this.address = CoreUtils.childAddress(parentAddress, this.address);
285
- }
286
- return params;
287
- }
288
- async initialize() {
289
- this.logger.debug('Initializing node...');
290
- this.validate();
291
- const params = await this.configure();
292
- this.p2pNode = await createNode(params);
293
- this.logger.debug('Node initialized!', this.transports);
294
- this.address.setTransports(this.transports.map((t) => multiaddr(t)));
295
- this.peerId = this.p2pNode.peerId;
296
- // initialize connection manager
297
- this.connectionManager = new oConnectionManager({
298
- logger: this.logger,
299
- p2pNode: this.p2pNode,
300
- });
301
- // initialize address resolution
302
- this.addressResolution.addResolver(new NextHopResolver(this.address, this.p2pNode));
303
- // listen for network events
304
- // this.listenForNetworkEvents();
305
- }
306
- async dhtProvide(value) {
307
- if (!this.config.parent && !this.config.leader) {
308
- return;
309
- }
310
- for await (const event of this.p2pNode.services.dht.provide(value)) {
311
- if (event.name === 'PATH_ENDED' ||
312
- event.name === 'QUERY_ERROR' ||
313
- event.name === 'PEER_RESPONSE') {
314
- break;
315
- }
316
- }
317
- }
318
- async advertiseValueToNetwork(value) {
319
- if (!this.isServer) {
320
- return;
321
- }
322
- this.logger.debug('Advertising value to network: ', value.toString());
323
- const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error('Advertise Content routing provide timeout')), 5000));
324
- await Promise.race([this.dhtProvide(value), timeoutPromise]);
325
- this.logger.debug('Advertise complete!');
326
- }
327
- // if the node has any transports that are not memory, it is a server
328
- get isServer() {
329
- return (this.transports.filter((t) => t.includes('memory') === false).length > 0);
330
- }
331
- async advertiseToNetwork() {
332
- if (!this.isServer) {
333
- return;
334
- }
335
- this.logger.debug('Advertising to network our static and absolute addresses...');
336
- // advertise the absolute address to the network with timeout
337
- const absoluteAddressCid = await this.address.toCID();
338
- // Add timeout to prevent hanging
339
- this.advertiseValueToNetwork(absoluteAddressCid).catch((error) => {
340
- this.logger.warn('Failed to advertise absolute address (this is normal for isolated nodes):', error.message);
341
- });
342
- // advertise the static address to the network with timeout
343
- const staticAddressCid = await this.staticAddress.toCID();
344
- // Add timeout to prevent hanging
345
- this.advertiseValueToNetwork(staticAddressCid).catch((error) => {
346
- this.logger.warn('Failed to advertise absolute address (this is normal for isolated nodes):', error.message);
347
- });
348
- }
349
- listenForNetworkEvents() {
350
- this.networkActivity = new NetworkActivity(this.logger, this.p2pNode);
351
- }
352
- async teardown() {
353
- for (const node of this.childNodes) {
354
- await node.stop();
355
- }
356
- this.childNodes = [];
357
- return super.teardown();
358
- }
359
- }
@@ -1,2 +0,0 @@
1
- export * from './virtual.node.js';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/node-virtual/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
@@ -1 +0,0 @@
1
- export * from './virtual.node.js';
@@ -1,10 +0,0 @@
1
- import { oNode } from '../node/node.js';
2
- export declare class oVirtualNode extends oNode {
3
- /**
4
- * Virtual nodes are only used for local communication, so we need to configure
5
- * the transports to be in-memory.
6
- * @returns The transports for the virtual node
7
- */
8
- configureTransports(): any[];
9
- }
10
- //# sourceMappingURL=virtual.node.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"virtual.node.d.ts","sourceRoot":"","sources":["../../../src/node-virtual/virtual.node.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,qBAAa,YAAa,SAAQ,KAAK;IACrC;;;;OAIG;IACH,mBAAmB,IAAI,GAAG,EAAE;CAG7B"}
@@ -1,12 +0,0 @@
1
- import { defaultLibp2pConfig } from '@olane/o-config';
2
- import { oNode } from '../node/node.js';
3
- export class oVirtualNode extends oNode {
4
- /**
5
- * Virtual nodes are only used for local communication, so we need to configure
6
- * the transports to be in-memory.
7
- * @returns The transports for the virtual node
8
- */
9
- configureTransports() {
10
- return [...(defaultLibp2pConfig.transports || [])];
11
- }
12
- }
@@ -1,28 +0,0 @@
1
- import { oPlanResult } from './interfaces/plan.result.js';
2
- import { oPlanConfig } from './interfaces/plan-config.interface.js';
3
- import { oPlan } from './o-plan.js';
4
- import { oQueryConfig } from './interfaces/query.config.js';
5
- import { oTaskConfig } from './interfaces/task.config.js';
6
- /**
7
- * oAgentPlan is responsible for managing the execution of plans.
8
- * General execution flow:
9
- * 1. Analyze intent
10
- * 2. Search for context
11
- * 3. Use network tools + context to solve intent
12
- * 4. Back to step 1
13
- */
14
- export declare class oAgentPlan extends oPlan {
15
- private MAX_ITERATIONS;
16
- private contextIdHash;
17
- constructor(config: oPlanConfig);
18
- doTask(task: oTaskConfig, config: oPlanConfig): Promise<oPlanResult>;
19
- handleTasks(results: oPlanResult, config: oPlanConfig): Promise<oPlanResult[]>;
20
- handleSearch(queries: oQueryConfig[], config: oPlanConfig): Promise<any[]>;
21
- /**
22
- * The analysis of the intent results in a list of steps and queries to complete the intent.
23
- */
24
- handleMultipleStep(output: oPlanResult): Promise<oPlanResult>;
25
- loop(): Promise<oPlanResult>;
26
- run(): Promise<oPlanResult>;
27
- }
28
- //# sourceMappingURL=agent.plan.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"agent.plan.d.ts","sourceRoot":"","sources":["../../../src/plan/agent.plan.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACpE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGpC,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE1D;;;;;;;GAOG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACnC,OAAO,CAAC,cAAc,CAAM;IAC5B,OAAO,CAAC,aAAa,CAAkC;gBAE3C,MAAM,EAAE,WAAW;IAIzB,MAAM,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAuBpE,WAAW,CACf,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,WAAW,EAAE,CAAC;IAmBnB,YAAY,CAChB,OAAO,EAAE,YAAY,EAAE,EACvB,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,GAAG,EAAE,CAAC;IAmCjB;;OAEG;IACG,kBAAkB,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAmB7D,IAAI,IAAI,OAAO,CAAC,WAAW,CAAC;IAiG5B,GAAG,IAAI,OAAO,CAAC,WAAW,CAAC;CAGlC"}