@olane/os 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.
Files changed (29) hide show
  1. package/dist/src/o-olane-os/o-os.d.ts.map +1 -1
  2. package/dist/src/o-olane-os/o-os.js +0 -1
  3. package/dist/test/basic/basic-usage.spec.d.ts +0 -1
  4. package/dist/test/basic/basic-usage.spec.js +134 -108
  5. package/dist/test/basic/playground.spec.d.ts +2 -0
  6. package/dist/test/basic/playground.spec.d.ts.map +1 -0
  7. package/dist/test/basic/playground.spec.js +33 -0
  8. package/dist/test/utils/tmp.node.d.ts +3 -0
  9. package/dist/test/utils/tmp.node.d.ts.map +1 -0
  10. package/dist/test/utils/tmp.node.js +8 -0
  11. package/package.json +12 -12
  12. package/dist/src/network/config/default.config.d.ts +0 -3
  13. package/dist/src/network/config/default.config.d.ts.map +0 -1
  14. package/dist/src/network/config/default.config.js +0 -32
  15. package/dist/src/network/index.d.ts +0 -5
  16. package/dist/src/network/index.d.ts.map +0 -1
  17. package/dist/src/network/index.js +0 -4
  18. package/dist/src/network/interfaces/network-status.enum.d.ts +0 -7
  19. package/dist/src/network/interfaces/network-status.enum.d.ts.map +0 -1
  20. package/dist/src/network/interfaces/network-status.enum.js +0 -7
  21. package/dist/src/network/interfaces/network.interface.d.ts +0 -18
  22. package/dist/src/network/interfaces/network.interface.d.ts.map +0 -1
  23. package/dist/src/network/interfaces/network.interface.js +0 -1
  24. package/dist/src/network/o-network.d.ts +0 -34
  25. package/dist/src/network/o-network.d.ts.map +0 -1
  26. package/dist/src/network/o-network.js +0 -247
  27. package/dist/test/utils/default.network.d.ts +0 -3
  28. package/dist/test/utils/default.network.d.ts.map +0 -1
  29. package/dist/test/utils/default.network.js +0 -33
@@ -1 +1 @@
1
- {"version":3,"file":"o-os.d.ts","sourceRoot":"","sources":["../../../src/o-olane-os/o-os.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAU,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAIzC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAK1C,KAAK,WAAW,GAAG,SAAS,GAAG,WAAW,CAAC;AAC3C,qBAAa,OAAQ,SAAQ,OAAO;IAClC,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,KAAK,CAAqB;IAC3B,UAAU,EAAE,WAAW,GAAG,IAAI,CAAQ;IACtC,MAAM,EAAG,mBAAmB,CAAC;IACpC,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,eAAe,CAAa;gBAExB,MAAM,EAAE,aAAa;IAKjC,SAAS,IAAI,SAAS,GAAG,WAAW;IAMpC,SAAS,CAAC,MAAM,EAAE,WAAW;IAOvB,OAAO,CAAC,IAAI,EAAE,WAAW;YAiBjB,UAAU;IAwClB,iBAAiB;IASjB,UAAU,CAAC,IAAI,EAAE,QAAQ;IAmDzB,aAAa;IA6Bb,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG;IAUnC,KAAK,IAAI,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,UAAU,EAAE,CAAA;KAAE,CAAC;IAiC9D,IAAI;IAwBJ,OAAO;CAKd"}
1
+ {"version":3,"file":"o-os.d.ts","sourceRoot":"","sources":["../../../src/o-olane-os/o-os.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAU,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAIzC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAK1C,KAAK,WAAW,GAAG,SAAS,GAAG,WAAW,CAAC;AAC3C,qBAAa,OAAQ,SAAQ,OAAO;IAClC,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,KAAK,CAAqB;IAC3B,UAAU,EAAE,WAAW,GAAG,IAAI,CAAQ;IACtC,MAAM,EAAG,mBAAmB,CAAC;IACpC,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,eAAe,CAAa;gBAExB,MAAM,EAAE,aAAa;IAKjC,SAAS,IAAI,SAAS,GAAG,WAAW;IAMpC,SAAS,CAAC,MAAM,EAAE,WAAW;IAOvB,OAAO,CAAC,IAAI,EAAE,WAAW;YAiBjB,UAAU;IAwClB,iBAAiB;IASjB,UAAU,CAAC,IAAI,EAAE,QAAQ;IAmDzB,aAAa;IA6Bb,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG;IASnC,KAAK,IAAI,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,UAAU,EAAE,CAAA;KAAE,CAAC;IAiC9D,IAAI;IAwBJ,OAAO;CAKd"}
@@ -163,7 +163,6 @@ export class OlaneOS extends oObject {
163
163
  if (!entryNode) {
164
164
  throw new Error('Entry node not found');
165
165
  }
166
- this.logger.debug('Using address: ' + oAddress.toString());
167
166
  const result = await entryNode.use(oAddress, params);
168
167
  return result;
169
168
  }
@@ -1,2 +1 @@
1
- export {};
2
1
  //# sourceMappingURL=basic-usage.spec.d.ts.map
@@ -1,118 +1,144 @@
1
- import { NodeState } from '@olane/o-core';
2
- import { expect } from 'chai';
3
- import dotenv from 'dotenv';
4
- import { defaultOSInstance } from '../utils/os.default.js';
5
- import { OlaneOSSystemStatus } from '../../src/o-olane-os/enum/o-os.status-enum.js';
6
- import { oNodeAddress, oNodeTransport } from '@olane/o-node';
7
- import { multiaddr } from '@olane/o-config';
8
- dotenv.config();
9
- const network = defaultOSInstance;
10
- describe('basic-usage @initialize', async () => {
11
- it('should be able to startup the network', async () => {
12
- await network.start();
13
- expect(network.status).to.equal(OlaneOSSystemStatus.RUNNING);
14
- });
15
- // disabled for now, to avoid unecessary indexing costs
16
- // it('should be able to index the network', async () => {
17
- // const entryNode = network.entryNode();
18
- // expect(entryNode).to.exist;
19
- // expect(entryNode.state).to.equal(NodeState.RUNNING);
20
- // const response = await entryNode.use(new oAddress('o://leader'), {
21
- // method: 'index_network',
22
- // params: {},
23
- // });
24
- // const data = response.result.data;
25
- // expect(data).to.exist;
26
- // expect(data.error).to.be.undefined;
27
- // expect(data.message).to.equal('Network indexed!');
28
- // });
29
- it('should be able to use olane remote services', async () => {
30
- const entryNode = network.entryNode();
31
- expect(entryNode).to.exist;
32
- expect(entryNode.state).to.equal(NodeState.RUNNING);
33
- // configure the intelligence tool
34
- // await entryNode.use(new oAddress('o://intelligence'), {
35
- // method: 'configure',
36
- // params: {
37
- // modelProvider: 'anthropic',
38
- // hostingProvider: 'olane',
39
- // accessToken: 'test',
40
- // address: 'o://leader/intelligence',
41
- // },
42
- // });
43
- // use the intelligence tool
44
- const response2 = await entryNode.use(new oNodeAddress('o://perplexity', [
45
- new oNodeTransport(multiaddr('/ip4/127.0.0.1/tcp/4000/ws/p2p/12D3KooWPHdsHhEdyBd9DS2zHJ1vRSyqSkZ97iT7F8ByYJ7U7bw8')),
46
- ]), {
47
- method: 'completion',
48
- params: {
49
- model: 'sonar',
50
- messages: [
51
- {
52
- role: 'user',
53
- content: 'What is the weather in Tokyo?',
54
- },
55
- ],
56
- },
57
- });
58
- console.log(response2.result.data);
59
- });
60
- });
61
- // describe('olane network usage', async () => {
62
- // it('should be able to use the olane network', async () => {
63
- // // let's dial the other network
64
- // const response = await network.use(
65
- // new oAddress('o://leader', [
66
- // multiaddr('/dns4/leader.olane.com/tcp/4000/tls/ws'),
67
- // ]),
1
+ "use strict";
2
+ // import { oAddress, NodeState } from '@olane/o-core';
3
+ // import { expect } from 'chai';
4
+ // import dotenv from 'dotenv';
5
+ // import { defaultOSInstance } from '../utils/os.default.js';
6
+ // import { OlaneOSSystemStatus } from '../../src/o-olane-os/enum/o-os.status-enum.js';
7
+ // import { oNodeAddress, oNodeTransport } from '@olane/o-node';
8
+ // import { multiaddr } from '@olane/o-config';
9
+ // dotenv.config();
10
+ // const network = defaultOSInstance;
11
+ // describe('basic-usage @initialize', async () => {
12
+ // it('should be able to startup the network', async () => {
13
+ // await network.start();
14
+ // expect(network.status).to.equal(OlaneOSSystemStatus.RUNNING);
15
+ // });
16
+ // // disabled for now, to avoid unecessary indexing costs
17
+ // // it('should be able to index the network', async () => {
18
+ // // const entryNode = network.entryNode();
19
+ // // expect(entryNode).to.exist;
20
+ // // expect(entryNode.state).to.equal(NodeState.RUNNING);
21
+ // // const response = await entryNode.use(new oAddress('o://leader'), {
22
+ // // method: 'index_network',
23
+ // // params: {},
24
+ // // });
25
+ // // const data = response.result.data;
26
+ // // expect(data).to.exist;
27
+ // // expect(data.error).to.be.undefined;
28
+ // // expect(data.message).to.equal('Network indexed!');
29
+ // // });
30
+ // it('should be able to use stream from a provider service', async () => {
31
+ // const entryNode = network.entryNode();
32
+ // expect(entryNode).to.exist;
33
+ // expect(entryNode.state).to.equal(NodeState.RUNNING);
34
+ // // configure the intelligence tool
35
+ // // await entryNode.use(new oAddress('o://intelligence'), {
36
+ // // method: 'configure',
37
+ // // params: {
38
+ // // modelProvider: 'anthropic',
39
+ // // hostingProvider: 'olane',
40
+ // // accessToken: 'test',
41
+ // // address: 'o://leader/intelligence',
42
+ // // },
43
+ // // });
44
+ // // console.log('Pinging relay');
45
+ // // await (entryNode.p2pNode.services as any).ping.ping(
46
+ // // multiaddr('/dns4/relay.olane.com/tcp/4000/tls/ws'),
47
+ // // );
48
+ // console.log('Pinged relay');
49
+ // // use the intelligence tool
50
+ // await entryNode.useStream(
51
+ // new oNodeAddress('o://leader', [new oNodeTransport('/ip4/127.0.0.1/tcp/4000/ws/p2p/12D3KooWPHdsHhEdyBd9DS2zHJ1vRSyqSkZ97iT7F8ByYJ7U7bw8')]),
68
52
  // {
69
53
  // method: 'intent',
70
54
  // params: {
71
- // intent: 'What can I do?',
55
+ // _isStream: true,
56
+ // intent: 'What is the official endpoint for github mcp server?',
72
57
  // },
73
58
  // },
74
- // );
75
- // console.log(response.result.data);
76
- // });
77
- // });
78
- // describe('external-networks', async () => {
79
- // it('should be able to use an external network', async () => {
80
- // const network2 = new oNetwork({
81
- // // configFilePath: path.join(os.homedir(), '.olane', 'config.json'),
82
- // nodes: [
83
- // {
84
- // type: NodeType.LEADER,
85
- // address: new oAddress('o://leader'),
86
- // leader: null,
87
- // parent: null,
88
- // },
89
- // {
90
- // type: NodeType.NODE,
91
- // address: new oAddress('o://node2'),
92
- // leader: null,
93
- // parent: null,
94
- // },
95
- // ],
96
- // plans: [],
97
- // noIndexNetwork: true,
98
- // });
99
- // await network2.start();
100
- // expect(network2.status).to.equal(NetworkStatus.RUNNING);
101
- // // let's dial the other network
102
- // await network2.use(
103
- // new oAddress('o://leader', [
104
- // ...(network?.rootLeader?.address.libp2pTransports || []),
105
- // ]),
106
59
  // {
107
- // method: 'index_network',
108
- // params: {},
60
+ // onChunk: (chunk) => {
61
+ // console.log(
62
+ // 'Received chunk: ',
63
+ // JSON.stringify(chunk.result.data, null, 2),
64
+ // );
65
+ // },
109
66
  // },
110
67
  // );
68
+ // // await entryNode.use(
69
+ // // new oNodeAddress('o://intelligence'),
70
+ // // {
71
+ // // method: 'prompt',
72
+ // // params: {
73
+ // // _isStream: true,
74
+ // // prompt: 'What is the capital of France?',
75
+ // // },
76
+ // // },
77
+ // // {
78
+ // // isStream: true,
79
+ // // onChunk: (chunk) => {
80
+ // // console.log('FINAL Received chunk: ', JSON.stringify(chunk, null, 2));
81
+ // // },
82
+ // // },
83
+ // // );
84
+ // // await new Promise((resolve) => setTimeout(resolve, 20_000));
85
+ // });
86
+ // });
87
+ // // describe('olane network usage', async () => {
88
+ // // it('should be able to use the olane network', async () => {
89
+ // // // let's dial the other network
90
+ // // const response = await network.use(
91
+ // // new oAddress('o://leader', [
92
+ // // multiaddr('/dns4/leader.olane.com/tcp/4000/tls/ws'),
93
+ // // ]),
94
+ // // {
95
+ // // method: 'intent',
96
+ // // params: {
97
+ // // intent: 'What can I do?',
98
+ // // },
99
+ // // },
100
+ // // );
101
+ // // console.log(response.result.data);
102
+ // // });
103
+ // // });
104
+ // // describe('external-networks', async () => {
105
+ // // it('should be able to use an external network', async () => {
106
+ // // const network2 = new oNetwork({
107
+ // // // configFilePath: path.join(os.homedir(), '.olane', 'config.json'),
108
+ // // nodes: [
109
+ // // {
110
+ // // type: NodeType.LEADER,
111
+ // // address: new oAddress('o://leader'),
112
+ // // leader: null,
113
+ // // parent: null,
114
+ // // },
115
+ // // {
116
+ // // type: NodeType.NODE,
117
+ // // address: new oAddress('o://node2'),
118
+ // // leader: null,
119
+ // // parent: null,
120
+ // // },
121
+ // // ],
122
+ // // plans: [],
123
+ // // noIndexNetwork: true,
124
+ // // });
125
+ // // await network2.start();
126
+ // // expect(network2.status).to.equal(NetworkStatus.RUNNING);
127
+ // // // let's dial the other network
128
+ // // await network2.use(
129
+ // // new oAddress('o://leader', [
130
+ // // ...(network?.rootLeader?.address.libp2pTransports || []),
131
+ // // ]),
132
+ // // {
133
+ // // method: 'index_network',
134
+ // // params: {},
135
+ // // },
136
+ // // );
137
+ // // });
138
+ // // });
139
+ // describe('basic-usage @stop-network', async () => {
140
+ // it('should be able to stop the network', async () => {
141
+ // await network.stop();
142
+ // expect(network.status).to.equal(OlaneOSSystemStatus.STOPPED);
111
143
  // });
112
144
  // });
113
- describe('basic-usage @stop-network', async () => {
114
- it('should be able to stop the network', async () => {
115
- await network.stop();
116
- expect(network.status).to.equal(OlaneOSSystemStatus.STOPPED);
117
- });
118
- });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=playground.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"playground.spec.d.ts","sourceRoot":"","sources":["../../../test/basic/playground.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,33 @@
1
+ import { NodeState } from '@olane/o-core';
2
+ import { expect } from 'chai';
3
+ import dotenv from 'dotenv';
4
+ import { defaultOSInstance } from '../utils/os.default.js';
5
+ import { oNodeAddress, oNodeTransport } from '@olane/o-node';
6
+ import { tmpNode } from '../utils/tmp.node.js';
7
+ dotenv.config();
8
+ const network = defaultOSInstance;
9
+ describe('playground running', async () => {
10
+ it('should be able to use stream from a provider service', async () => {
11
+ const entryNode = tmpNode;
12
+ await entryNode.start();
13
+ expect(entryNode).to.exist;
14
+ expect(entryNode.state).to.equal(NodeState.RUNNING);
15
+ console.log('Using intelligence tool');
16
+ const response = await entryNode.useStream(new oNodeAddress('o://leader', [
17
+ new oNodeTransport('/ip4/127.0.0.1/tcp/4000/ws/p2p/12D3KooWPHdsHhEdyBd9DS2zHJ1vRSyqSkZ97iT7F8ByYJ7U7bw8'),
18
+ ]), {
19
+ method: 'intent',
20
+ params: {
21
+ _isStreaming: true,
22
+ intent: 'Print the first paragraph of the Constitution of the United States',
23
+ _token: 'test',
24
+ },
25
+ }, {
26
+ onChunk: (chunk) => {
27
+ console.log('Received chunk:', JSON.stringify(chunk.result.data, null, 2));
28
+ },
29
+ });
30
+ console.log('Response:', response.result.data);
31
+ await entryNode.stop();
32
+ });
33
+ });
@@ -0,0 +1,3 @@
1
+ import { oLaneTool } from '@olane/o-lane';
2
+ export declare const tmpNode: oLaneTool;
3
+ //# sourceMappingURL=tmp.node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tmp.node.d.ts","sourceRoot":"","sources":["../../../test/utils/tmp.node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG1C,eAAO,MAAM,OAAO,WAKlB,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { oLaneTool } from '@olane/o-lane';
2
+ import { oNodeAddress } from '@olane/o-node';
3
+ export const tmpNode = new oLaneTool({
4
+ address: new oNodeAddress('o://tmp-node'),
5
+ leader: null,
6
+ parent: null,
7
+ description: 'temporary node',
8
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@olane/os",
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",
@@ -57,21 +57,21 @@
57
57
  "typescript": "5.4.5"
58
58
  },
59
59
  "dependencies": {
60
- "@olane/o-config": "^0.7.12-alpha.3",
61
- "@olane/o-core": "0.7.12-alpha.3",
62
- "@olane/o-intelligence": "0.7.12-alpha.3",
63
- "@olane/o-lane": "0.7.12-alpha.3",
64
- "@olane/o-leader": "0.7.12-alpha.3",
65
- "@olane/o-protocol": "^0.7.12-alpha.3",
66
- "@olane/o-storage": "0.7.12-alpha.3",
67
- "@olane/o-tool": "0.7.12-alpha.3",
68
- "@olane/o-tool-registry": "0.7.12-alpha.3",
69
- "@olane/o-tools-common": "0.7.12-alpha.3",
60
+ "@olane/o-config": "0.7.12-alpha.30",
61
+ "@olane/o-core": "0.7.12-alpha.30",
62
+ "@olane/o-intelligence": "0.7.12-alpha.30",
63
+ "@olane/o-lane": "0.7.12-alpha.30",
64
+ "@olane/o-leader": "0.7.12-alpha.30",
65
+ "@olane/o-protocol": "0.7.12-alpha.30",
66
+ "@olane/o-storage": "0.7.12-alpha.30",
67
+ "@olane/o-tool": "0.7.12-alpha.30",
68
+ "@olane/o-tool-registry": "0.7.12-alpha.30",
69
+ "@olane/o-tools-common": "0.7.12-alpha.30",
70
70
  "chalk": "^5.4.1",
71
71
  "debug": "^4.4.1",
72
72
  "dotenv": "^16.5.0",
73
73
  "fs-extra": "^11.3.0",
74
74
  "touch": "^3.1.1"
75
75
  },
76
- "gitHead": "5c05e5f248001abc38f34c77bd97c9a325231503"
76
+ "gitHead": "066e6bda19e79a744779a797664481476b0ea655"
77
77
  }
@@ -1,3 +0,0 @@
1
- import { NetworkConfigInterface } from '../interfaces/network.interface.js';
2
- export declare const defaultNetworkConfig: (port: number) => NetworkConfigInterface;
3
- //# sourceMappingURL=default.config.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"default.config.d.ts","sourceRoot":"","sources":["../../../../src/network/config/default.config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAG5E,eAAO,MAAM,oBAAoB,SAAU,MAAM,KAAG,sBAiCnD,CAAC"}
@@ -1,32 +0,0 @@
1
- import { DEFAULT_NETWORKS_PATH, NodeType, oAddress } from '@olane/o-core';
2
- import path from 'path';
3
- export const defaultNetworkConfig = (port) => {
4
- return {
5
- configFilePath: path.join(DEFAULT_NETWORKS_PATH, 'my-network', 'config.json'),
6
- network: {
7
- name: 'my-network-' + Math.random().toString(36).substring(2, 6),
8
- version: '0.0.1',
9
- description: 'my olane network',
10
- port: port,
11
- },
12
- nodes: [
13
- {
14
- type: NodeType.LEADER,
15
- address: new oAddress('o://leader'),
16
- leader: null,
17
- parent: null,
18
- network: {
19
- listeners: ['/ip4/0.0.0.0/tcp/' + port],
20
- },
21
- },
22
- {
23
- type: NodeType.NODE,
24
- address: new oAddress('o://node'),
25
- leader: null,
26
- parent: null,
27
- },
28
- ],
29
- lanes: [],
30
- inProgress: [],
31
- };
32
- };
@@ -1,5 +0,0 @@
1
- export * from './o-network.js';
2
- export * from './interfaces/network.interface.js';
3
- export * from './interfaces/network-status.enum.js';
4
- export * from './config/default.config.js';
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/network/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mCAAmC,CAAC;AAClD,cAAc,qCAAqC,CAAC;AACpD,cAAc,4BAA4B,CAAC"}
@@ -1,4 +0,0 @@
1
- export * from './o-network.js';
2
- export * from './interfaces/network.interface.js';
3
- export * from './interfaces/network-status.enum.js';
4
- export * from './config/default.config.js';
@@ -1,7 +0,0 @@
1
- export declare enum NetworkStatus {
2
- STARTING = "starting",
3
- RUNNING = "running",
4
- STOPPING = "stopping",
5
- STOPPED = "stopped"
6
- }
7
- //# sourceMappingURL=network-status.enum.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"network-status.enum.d.ts","sourceRoot":"","sources":["../../../../src/network/interfaces/network-status.enum.ts"],"names":[],"mappings":"AAAA,oBAAY,aAAa;IACvB,QAAQ,aAAa;IACrB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,OAAO,YAAY;CACpB"}
@@ -1,7 +0,0 @@
1
- export var NetworkStatus;
2
- (function (NetworkStatus) {
3
- NetworkStatus["STARTING"] = "starting";
4
- NetworkStatus["RUNNING"] = "running";
5
- NetworkStatus["STOPPING"] = "stopping";
6
- NetworkStatus["STOPPED"] = "stopped";
7
- })(NetworkStatus || (NetworkStatus = {}));
@@ -1,18 +0,0 @@
1
- import { oNodeConfig } from '@olane/o-node';
2
- export interface NetworkConfigInterface {
3
- configFilePath?: string;
4
- network?: {
5
- name?: string;
6
- version?: string;
7
- description?: string;
8
- icon?: string;
9
- website?: string;
10
- networkId?: string;
11
- port?: number;
12
- };
13
- nodes?: oNodeConfig[];
14
- lanes?: string[];
15
- noIndexNetwork?: boolean;
16
- inProgress?: string[];
17
- }
18
- //# sourceMappingURL=network.interface.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"network.interface.d.ts","sourceRoot":"","sources":["../../../../src/network/interfaces/network.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,WAAW,sBAAsB;IACrC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE;QACR,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;IACF,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,34 +0,0 @@
1
- import { NetworkStatus } from './interfaces/network-status.enum.js';
2
- import { NetworkConfigInterface } from './interfaces/network.interface.js';
3
- import { oLeaderNode } from '@olane/o-leader';
4
- import { oAddress, oTransport } from '@olane/o-core';
5
- import { NodeType } from '@olane/o-core';
6
- import { oLaneTool } from '@olane/o-lane';
7
- type oNetworkNode = oLaneTool | oLeaderNode;
8
- export declare class oNetwork {
9
- private leaders;
10
- private nodes;
11
- rootLeader: oLeaderNode | null;
12
- private logger;
13
- status: NetworkStatus;
14
- private config;
15
- private roundRobinIndex;
16
- private inFlightRequests;
17
- constructor(config: NetworkConfigInterface);
18
- entryNode(): oLaneTool | oLeaderNode;
19
- addLeader(leader: oLeaderNode): void;
20
- addNode(node: oNetworkNode): Promise<void>;
21
- private loadConfig;
22
- getNetworkName(): Promise<string | undefined>;
23
- startNodes(type: NodeType): Promise<void>;
24
- runSavedPlans(): Promise<void>;
25
- use(oAddress: oAddress, params: any): Promise<import("@olane/o-core").oResponse>;
26
- start(): Promise<{
27
- peerId: string;
28
- transports: oTransport[];
29
- }>;
30
- stop(): Promise<void>;
31
- restart(): Promise<void>;
32
- }
33
- export {};
34
- //# sourceMappingURL=o-network.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"o-network.d.ts","sourceRoot":"","sources":["../../../src/network/o-network.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAG3E,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAU,QAAQ,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAIzC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAI1C,KAAK,YAAY,GAAG,SAAS,GAAG,WAAW,CAAC;AAC5C,qBAAa,QAAQ;IACnB,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,KAAK,CAAsB;IAC5B,UAAU,EAAE,WAAW,GAAG,IAAI,CAAQ;IAC7C,OAAO,CAAC,MAAM,CAAS;IAChB,MAAM,EAAG,aAAa,CAAC;IAC9B,OAAO,CAAC,MAAM,CAAyB;IACvC,OAAO,CAAC,eAAe,CAAa;IACpC,OAAO,CAAC,gBAAgB,CAAa;gBAEzB,MAAM,EAAE,sBAAsB;IAK1C,SAAS,IAAI,SAAS,GAAG,WAAW;IAMpC,SAAS,CAAC,MAAM,EAAE,WAAW;IAOvB,OAAO,CAAC,IAAI,EAAE,YAAY;YAiBlB,UAAU;IAwClB,cAAc;IASd,UAAU,CAAC,IAAI,EAAE,QAAQ;IA2CzB,aAAa;IAUb,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG;IAiBnC,KAAK,IAAI,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,UAAU,EAAE,CAAA;KAAE,CAAC;IAgC9D,IAAI;IAiFJ,OAAO;CAKd"}
@@ -1,247 +0,0 @@
1
- import { NetworkStatus } from './interfaces/network-status.enum.js';
2
- import touch from 'touch';
3
- import { readFile } from 'fs/promises';
4
- import { oLeaderNode } from '@olane/o-leader';
5
- import { Logger, oAddress } from '@olane/o-core';
6
- import { NodeType } from '@olane/o-core';
7
- import { initCommonTools } from '@olane/o-tools-common';
8
- import { initRegistryTools } from '@olane/o-tool-registry';
9
- import { ConfigManager } from '../utils/config.js';
10
- import { oLaneTool } from '@olane/o-lane';
11
- import { oNodeAddress } from '@olane/o-node';
12
- export class oNetwork {
13
- constructor(config) {
14
- this.leaders = []; // clones of leader for scale
15
- this.nodes = []; // clones of node for scale
16
- this.rootLeader = null; // the root leader node
17
- this.roundRobinIndex = 0;
18
- this.inFlightRequests = [];
19
- this.logger = new Logger('oNetwork');
20
- this.config = config;
21
- }
22
- entryNode() {
23
- const node = this.nodes[this.roundRobinIndex];
24
- this.roundRobinIndex = (this.roundRobinIndex + 1) % this.nodes.length;
25
- return node;
26
- }
27
- addLeader(leader) {
28
- this.leaders.push(leader);
29
- if (!this.rootLeader) {
30
- this.rootLeader = leader;
31
- }
32
- }
33
- async addNode(node) {
34
- if (this.status !== NetworkStatus.RUNNING) {
35
- throw new Error('Network is not running, cannot add node');
36
- }
37
- // TODO: how do we handle multiple leaders?
38
- // TODO: how do we handle multiple nodes?
39
- if (this.nodes.length === 0) {
40
- throw new Error('No non-leader nodes found, cannot add node');
41
- }
42
- const selection = this.entryNode();
43
- selection.addChildNode(node);
44
- await selection.start();
45
- const parent = this.entryNode();
46
- parent.addChildNode(node);
47
- }
48
- async loadConfig() {
49
- // TODO make this a promise based function
50
- if (this.config.configFilePath) {
51
- try {
52
- await touch(this.config.configFilePath);
53
- this.logger.debug('Config file path: ' + this.config.configFilePath);
54
- // let's load the config
55
- const config = await readFile(this.config.configFilePath, 'utf8');
56
- this.logger.debug('Config file contents: ' + config);
57
- if (config?.length === 0) {
58
- // no contents, let's create a new config
59
- throw new Error('No config file found, cannot start network');
60
- }
61
- const json = JSON.parse(config);
62
- this.logger.debug('Config file parsed: ' + json);
63
- const networkConfig = json.oNetworkConfig;
64
- this.config = {
65
- ...networkConfig,
66
- nodes: (networkConfig.nodes || []).map((node) => ({
67
- ...node,
68
- address: new oNodeAddress(node.address.value),
69
- })),
70
- network: {
71
- ...networkConfig.network,
72
- port: networkConfig.network?.port || 4999,
73
- },
74
- configFilePath: this.config.configFilePath, // persist the config file path
75
- };
76
- }
77
- catch (error) {
78
- this.logger.error('Failed to initialize config folder', error);
79
- throw new Error('Failed to initialize config folder');
80
- }
81
- }
82
- else {
83
- this.logger.warn('No config file path provided, using default config');
84
- }
85
- }
86
- async getNetworkName() {
87
- if (this.config.configFilePath) {
88
- const networkConfig = await ConfigManager.getNetworkConfigFromPath(this.config.configFilePath);
89
- return networkConfig?.name;
90
- }
91
- }
92
- async startNodes(type) {
93
- this.logger.debug('Starting nodes');
94
- if (!this.config.nodes || this.config.nodes?.length === 0) {
95
- throw new Error('No nodes found in config, cannot start network');
96
- }
97
- const filtered = this.config.nodes.filter((node) => node.type === type);
98
- const networkName = await this.getNetworkName();
99
- // check the config for any leaders
100
- for (const node of filtered) {
101
- if (node.type === NodeType.LEADER) {
102
- this.logger.debug('Starting leader: ' + node.address.toString());
103
- const leaderNode = new oLeaderNode({
104
- ...node,
105
- networkName: networkName,
106
- });
107
- if (!this.rootLeader) {
108
- this.rootLeader = leaderNode;
109
- }
110
- await leaderNode.start();
111
- await initCommonTools(leaderNode);
112
- this.leaders.push(leaderNode);
113
- }
114
- else {
115
- this.logger.debug('Starting non-leader node: ' + node.address.toString());
116
- const commonNode = new oLaneTool({
117
- ...node,
118
- address: node.address,
119
- leader: this.rootLeader?.address || null,
120
- parent: this.rootLeader?.address || null,
121
- });
122
- await commonNode.start();
123
- this.rootLeader?.addChildNode(commonNode);
124
- await initCommonTools(commonNode);
125
- await initRegistryTools(commonNode);
126
- this.nodes.push(commonNode);
127
- }
128
- }
129
- }
130
- async runSavedPlans() {
131
- const plans = Array.from(new Set(this.config?.lanes || []));
132
- for (const plan of plans) {
133
- this.logger.debug('Running saved plan: ' + plan);
134
- await this.use(new oAddress(plan), {
135
- method: 'use',
136
- });
137
- }
138
- }
139
- async use(oAddress, params) {
140
- const entryNode = this.entryNode();
141
- if (!entryNode) {
142
- throw new Error('Entry node not found');
143
- }
144
- this.logger.debug('Using address: ' + oAddress.toString());
145
- return entryNode.use(oAddress, params);
146
- // TODO: experiment with this (the wrong way to enter the network)
147
- // const leader = this.leaders.find(
148
- // (leader) => leader.type === NodeType.LEADER,
149
- // );
150
- // if (!leader) {
151
- // throw new Error('Leader not found');
152
- // }
153
- // return leader.use(oAddress, params);
154
- }
155
- async start() {
156
- this.logger.debug('Starting o-network');
157
- this.status = NetworkStatus.STARTING;
158
- // initialize config folder
159
- await this.loadConfig();
160
- this.logger.debug('o-network config loaded');
161
- // start leaders (and consequentially, the rest of the network)
162
- await this.startNodes(NodeType.LEADER);
163
- this.logger.debug('Leaders started...');
164
- await this.startNodes(NodeType.NODE);
165
- this.logger.debug('Nodes started...');
166
- await this.runSavedPlans();
167
- this.logger.debug('Saved plans run...');
168
- this.logger.debug('o-network started...');
169
- // index the network
170
- if (!this.config.noIndexNetwork) {
171
- await this.use(oAddress.leader(), {
172
- method: 'index_network',
173
- params: {},
174
- });
175
- }
176
- this.status = NetworkStatus.RUNNING;
177
- return {
178
- peerId: this.rootLeader?.peerId.toString() || '',
179
- transports: this.rootLeader?.transports || [],
180
- };
181
- }
182
- async stop() {
183
- this.logger.debug('Stopping o-network');
184
- this.status = NetworkStatus.STOPPING;
185
- const stopPromises = [];
186
- try {
187
- // Stop all common nodes first
188
- if (this.nodes.length > 0) {
189
- stopPromises.push(Promise.allSettled(this.nodes.map(async (node) => {
190
- try {
191
- await node.stop();
192
- this.logger.debug(`Stopped node: ${node.address.toString()}`);
193
- }
194
- catch (error) {
195
- this.logger.error(`Error stopping node ${node.address.toString()}:`, error);
196
- }
197
- })).then(() => {
198
- this.nodes = [];
199
- this.logger.debug('All common nodes stopped');
200
- }));
201
- }
202
- // Stop all leader nodes
203
- if (this.leaders.length > 0) {
204
- stopPromises.push(Promise.allSettled(this.leaders.map(async (leader) => {
205
- try {
206
- await leader.stop();
207
- this.logger.debug(`Stopped leader: ${leader.address.toString()}`);
208
- }
209
- catch (error) {
210
- this.logger.error(`Error stopping leader ${leader.address.toString()}:`, error);
211
- }
212
- })).then(() => {
213
- this.leaders = [];
214
- this.logger.debug('All leader nodes stopped');
215
- }));
216
- }
217
- // Stop root leader last
218
- if (this.rootLeader) {
219
- this.logger.debug('Stopping root leader...');
220
- stopPromises.push(this.rootLeader
221
- .stop()
222
- .then(() => {
223
- this.logger.debug('Root leader stopped');
224
- this.rootLeader = null;
225
- })
226
- .catch((error) => {
227
- this.logger.error('Error stopping root leader:', error);
228
- }));
229
- }
230
- // Wait for all stop operations to complete
231
- await Promise.all(stopPromises);
232
- this.logger.debug('o-network stopped successfully');
233
- }
234
- catch (error) {
235
- this.logger.error('Error while stopping o-network:', error);
236
- }
237
- finally {
238
- this.status = NetworkStatus.STOPPED;
239
- this.roundRobinIndex = 0;
240
- }
241
- }
242
- async restart() {
243
- this.logger.debug('Restarting o-network');
244
- await this.stop();
245
- await this.start();
246
- }
247
- }
@@ -1,3 +0,0 @@
1
- import { oNetwork } from '../../src/index.js';
2
- export declare const defaultNetwork: oNetwork;
3
- //# sourceMappingURL=default.network.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"default.network.d.ts","sourceRoot":"","sources":["../../../test/utils/default.network.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,eAAO,MAAM,cAAc,UAoBzB,CAAC"}
@@ -1,33 +0,0 @@
1
- import { NodeType, oAddress, setupGracefulShutdown } from '@olane/o-core';
2
- import { oNetwork } from '../../src/index.js';
3
- export const defaultNetwork = new oNetwork({
4
- // configFilePath: path.join(os.homedir(), '.olane', 'config.json'),
5
- nodes: [
6
- {
7
- type: NodeType.LEADER,
8
- address: new oAddress('o://leader'),
9
- description: 'Leader for testing',
10
- leader: null,
11
- parent: null,
12
- },
13
- {
14
- type: NodeType.NODE,
15
- address: new oAddress('o://node'),
16
- description: 'Node for testing',
17
- leader: null,
18
- parent: null,
19
- },
20
- ],
21
- lanes: [],
22
- // noIndexNetwork: true,
23
- });
24
- setupGracefulShutdown(async () => {
25
- console.log('Stopping o-network...');
26
- await defaultNetwork.stop();
27
- console.log('o-network stopped successfully');
28
- }, {
29
- timeout: 30000, // 30 seconds timeout
30
- onTimeout: () => {
31
- console.error('Shutdown timeout reached, forcing exit');
32
- },
33
- });