@olane/o-core 0.1.1 → 0.1.3
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.
- package/dist/core/core.node.js +33 -49
- package/dist/core/defaults/config.js +5 -11
- package/dist/core/defaults/index.d.ts +1 -1
- package/dist/core/defaults/index.d.ts.map +1 -1
- package/dist/core/defaults/index.js +1 -17
- package/dist/core/graceful-shutdown.d.ts +25 -0
- package/dist/core/graceful-shutdown.d.ts.map +1 -0
- package/dist/core/graceful-shutdown.js +84 -0
- package/dist/core/index.d.ts +10 -9
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +10 -25
- package/dist/core/interfaces/connection-manager.config.js +1 -2
- package/dist/core/interfaces/connection-send-params.interface.js +1 -2
- package/dist/core/interfaces/core-config.interface.js +1 -2
- package/dist/core/interfaces/index.d.ts +5 -5
- package/dist/core/interfaces/index.d.ts.map +1 -1
- package/dist/core/interfaces/index.js +5 -21
- package/dist/core/interfaces/node-type.enum.js +2 -5
- package/dist/core/interfaces/restricted-addresses.enum.js +11 -14
- package/dist/core/interfaces/state.enum.js +2 -5
- package/dist/core/interfaces/use-options.interface.js +1 -2
- package/dist/core/lib/index.d.ts +7 -7
- package/dist/core/lib/index.d.ts.map +1 -1
- package/dist/core/lib/index.js +7 -23
- package/dist/core/lib/o-address-resolution.js +6 -8
- package/dist/core/lib/o-address-resolver.js +5 -12
- package/dist/core/lib/o-connection-manager.js +4 -10
- package/dist/core/lib/o-connection.js +16 -26
- package/dist/core/lib/o-request.js +3 -11
- package/dist/core/lib/o-response.js +3 -10
- package/dist/core/lib/resolvers/anything.resolver.js +4 -8
- package/dist/core/lib/resolvers/index.d.ts +4 -4
- package/dist/core/lib/resolvers/index.d.ts.map +1 -1
- package/dist/core/lib/resolvers/index.js +4 -20
- package/dist/core/lib/resolvers/method.resolver.js +4 -8
- package/dist/core/lib/resolvers/next-hop.resolver.js +9 -13
- package/dist/core/lib/resolvers/storage.resolver.js +2 -6
- package/dist/core/o-address.d.ts +1 -1
- package/dist/core/o-address.d.ts.map +1 -1
- package/dist/core/o-address.js +5 -11
- package/dist/core/o-dependency.js +1 -7
- package/dist/core/o-parameter.js +1 -10
- package/dist/core/utils/core.utils.d.ts +1 -1
- package/dist/core/utils/core.utils.d.ts.map +1 -1
- package/dist/core/utils/core.utils.js +17 -54
- package/dist/core/utils/index.d.ts +3 -3
- package/dist/core/utils/index.d.ts.map +1 -1
- package/dist/core/utils/index.js +3 -19
- package/dist/core/utils/logger.js +9 -18
- package/dist/core/utils/network.utils.js +2 -6
- package/dist/error/enums/codes.error.js +2 -5
- package/dist/error/index.d.ts +2 -2
- package/dist/error/index.d.ts.map +1 -1
- package/dist/error/index.js +2 -18
- package/dist/error/tool.error.js +3 -8
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -22
- package/dist/node/index.d.ts +3 -3
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +3 -19
- package/dist/node/lib/local-search.lib.js +1 -5
- package/dist/node/lib/network-activity.lib.js +3 -9
- package/dist/node/node.js +42 -44
- package/dist/node-host/host.node.js +5 -9
- package/dist/node-host/index.d.ts +1 -1
- package/dist/node-host/index.d.ts.map +1 -1
- package/dist/node-host/index.js +1 -17
- package/dist/node-virtual/index.d.ts +1 -1
- package/dist/node-virtual/index.d.ts.map +1 -1
- package/dist/node-virtual/index.js +1 -17
- package/dist/node-virtual/virtual.node.js +4 -8
- package/dist/plan/agent.plan.js +13 -17
- package/dist/plan/configure/configure.plan.js +6 -10
- package/dist/plan/error/error.plan.js +6 -11
- package/dist/plan/index.d.ts +4 -4
- package/dist/plan/index.d.ts.map +1 -1
- package/dist/plan/index.js +4 -20
- package/dist/plan/interfaces/plan-config.interface.js +1 -2
- package/dist/plan/interfaces/plan-result.interface.js +1 -2
- package/dist/plan/interfaces/plan-type.enum.js +2 -5
- package/dist/plan/interfaces/plan.result.js +1 -2
- package/dist/plan/interfaces/query.config.js +1 -2
- package/dist/plan/interfaces/task.config.js +1 -2
- package/dist/plan/o-plan.d.ts +1 -1
- package/dist/plan/o-plan.d.ts.map +1 -1
- package/dist/plan/o-plan.js +19 -60
- package/dist/plan/plan.context.js +2 -6
- package/dist/plan/prompts/agent.prompt.js +2 -6
- package/dist/plan/prompts/configure.prompt.js +2 -6
- package/dist/plan/prompts/custom.prompt.js +1 -5
- package/dist/plan/prompts/error.prompt.js +1 -5
- package/dist/plan/prompts/search.prompt.js +1 -5
- package/dist/plan/search/prompts/search-analysis.prompt.js +1 -5
- package/dist/plan/search/search.plan.js +4 -10
- package/dist/plan/use/index.js +1 -17
- package/dist/plan/use/use.plan.js +9 -13
- package/package.json +6 -5
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NetworkUtils = void 0;
|
|
4
|
-
class NetworkUtils {
|
|
1
|
+
export class NetworkUtils {
|
|
5
2
|
static async findNode(p2pNode, address) {
|
|
6
3
|
const cid = await address.toCID();
|
|
7
4
|
const providers = await p2pNode.services.dht.findProviders(cid);
|
|
8
|
-
const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error('Content routing provide timeout')),
|
|
5
|
+
const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error('Content routing provide timeout')), 5000));
|
|
9
6
|
try {
|
|
10
7
|
const { value, done } = await Promise.race([
|
|
11
8
|
providers.next(),
|
|
@@ -40,4 +37,3 @@ class NetworkUtils {
|
|
|
40
37
|
}
|
|
41
38
|
}
|
|
42
39
|
}
|
|
43
|
-
exports.NetworkUtils = NetworkUtils;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.oToolErrorCodes = void 0;
|
|
4
|
-
var oToolErrorCodes;
|
|
1
|
+
export var oToolErrorCodes;
|
|
5
2
|
(function (oToolErrorCodes) {
|
|
6
3
|
oToolErrorCodes[oToolErrorCodes["TOOL_ERROR"] = 1001] = "TOOL_ERROR";
|
|
7
4
|
oToolErrorCodes[oToolErrorCodes["TOOL_NOT_FOUND"] = 1002] = "TOOL_NOT_FOUND";
|
|
@@ -16,4 +13,4 @@ var oToolErrorCodes;
|
|
|
16
13
|
oToolErrorCodes[oToolErrorCodes["TOOL_INVALID_ACTION"] = 1011] = "TOOL_INVALID_ACTION";
|
|
17
14
|
oToolErrorCodes[oToolErrorCodes["TOOL_INVALID_CREDENTIALS"] = 1012] = "TOOL_INVALID_CREDENTIALS";
|
|
18
15
|
oToolErrorCodes[oToolErrorCodes["TOOL_TRANSPORT_NOT_SUPPORTED"] = 1013] = "TOOL_TRANSPORT_NOT_SUPPORTED";
|
|
19
|
-
})(oToolErrorCodes || (
|
|
16
|
+
})(oToolErrorCodes || (oToolErrorCodes = {}));
|
package/dist/error/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './tool.error';
|
|
2
|
-
export * from './enums/codes.error';
|
|
1
|
+
export * from './tool.error.js';
|
|
2
|
+
export * from './enums/codes.error.js';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/error/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/error/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC"}
|
package/dist/error/index.js
CHANGED
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./tool.error"), exports);
|
|
18
|
-
__exportStar(require("./enums/codes.error"), exports);
|
|
1
|
+
export * from './tool.error.js';
|
|
2
|
+
export * from './enums/codes.error.js';
|
package/dist/error/tool.error.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.oToolError = void 0;
|
|
4
|
-
class oToolError extends Error {
|
|
5
|
-
code = 0;
|
|
6
|
-
details;
|
|
7
|
-
message = '';
|
|
1
|
+
export class oToolError extends Error {
|
|
8
2
|
constructor(code, message, details) {
|
|
9
3
|
super(message);
|
|
4
|
+
this.code = 0;
|
|
5
|
+
this.message = '';
|
|
10
6
|
this.code = code;
|
|
11
7
|
this.message = message;
|
|
12
8
|
this.details = details;
|
|
@@ -19,4 +15,3 @@ class oToolError extends Error {
|
|
|
19
15
|
};
|
|
20
16
|
}
|
|
21
17
|
}
|
|
22
|
-
exports.oToolError = oToolError;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from './core';
|
|
2
|
-
export * from './node';
|
|
3
|
-
export * from './node-virtual';
|
|
4
|
-
export * from './node-host';
|
|
5
|
-
export * from './error';
|
|
6
|
-
export * from './plan';
|
|
1
|
+
export * from './core/index.js';
|
|
2
|
+
export * from './node/index.js';
|
|
3
|
+
export * from './node-virtual/index.js';
|
|
4
|
+
export * from './node-host/index.js';
|
|
5
|
+
export * from './error/index.js';
|
|
6
|
+
export * from './plan/index.js';
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./core"), exports);
|
|
18
|
-
__exportStar(require("./node"), exports);
|
|
19
|
-
__exportStar(require("./node-virtual"), exports);
|
|
20
|
-
__exportStar(require("./node-host"), exports);
|
|
21
|
-
__exportStar(require("./error"), exports);
|
|
22
|
-
__exportStar(require("./plan"), exports);
|
|
1
|
+
export * from './core/index.js';
|
|
2
|
+
export * from './node/index.js';
|
|
3
|
+
export * from './node-virtual/index.js';
|
|
4
|
+
export * from './node-host/index.js';
|
|
5
|
+
export * from './error/index.js';
|
|
6
|
+
export * from './plan/index.js';
|
package/dist/node/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './node';
|
|
2
|
-
export * from './lib/local-search.lib';
|
|
3
|
-
export * from './lib/network-activity.lib';
|
|
1
|
+
export * from './node.js';
|
|
2
|
+
export * from './lib/local-search.lib.js';
|
|
3
|
+
export * from './lib/network-activity.lib.js';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/node/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC"}
|
package/dist/node/index.js
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./node"), exports);
|
|
18
|
-
__exportStar(require("./lib/local-search.lib"), exports);
|
|
19
|
-
__exportStar(require("./lib/network-activity.lib"), exports);
|
|
1
|
+
export * from './node.js';
|
|
2
|
+
export * from './lib/local-search.lib.js';
|
|
3
|
+
export * from './lib/network-activity.lib.js';
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LocalSearch = void 0;
|
|
4
|
-
class LocalSearch {
|
|
1
|
+
export class LocalSearch {
|
|
5
2
|
static async search(node, query) {
|
|
6
3
|
const results = await node.myTools();
|
|
7
4
|
// utilize local rag
|
|
@@ -11,4 +8,3 @@ class LocalSearch {
|
|
|
11
8
|
throw new Error('No tool found for query');
|
|
12
9
|
}
|
|
13
10
|
}
|
|
14
|
-
exports.LocalSearch = LocalSearch;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NetworkActivity = exports.NETWORK_ACTIVITY_EVENTS = void 0;
|
|
4
|
-
exports.NETWORK_ACTIVITY_EVENTS = [
|
|
1
|
+
export const NETWORK_ACTIVITY_EVENTS = [
|
|
5
2
|
'peer:connect',
|
|
6
3
|
'peer:disconnect',
|
|
7
4
|
'peer:update',
|
|
@@ -16,20 +13,17 @@ exports.NETWORK_ACTIVITY_EVENTS = [
|
|
|
16
13
|
'certificate:provision',
|
|
17
14
|
'certificate:renew',
|
|
18
15
|
];
|
|
19
|
-
class NetworkActivity {
|
|
20
|
-
logger;
|
|
21
|
-
p2pNode;
|
|
16
|
+
export class NetworkActivity {
|
|
22
17
|
constructor(logger, p2pNode) {
|
|
23
18
|
this.logger = logger;
|
|
24
19
|
this.p2pNode = p2pNode;
|
|
25
20
|
this.setup();
|
|
26
21
|
}
|
|
27
22
|
setup() {
|
|
28
|
-
for (const event of
|
|
23
|
+
for (const event of NETWORK_ACTIVITY_EVENTS) {
|
|
29
24
|
this.p2pNode.addEventListener(event, (evt) => {
|
|
30
25
|
this.logger.debug('Network activity: ', event, evt.detail);
|
|
31
26
|
});
|
|
32
27
|
}
|
|
33
28
|
}
|
|
34
29
|
}
|
|
35
|
-
exports.NetworkActivity = NetworkActivity;
|
package/dist/node/node.js
CHANGED
|
@@ -1,37 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const agent_plan_1 = require("../plan/agent.plan");
|
|
13
|
-
const plan_context_1 = require("../plan/plan.context");
|
|
14
|
-
const configure_plan_1 = require("../plan/configure/configure.plan");
|
|
1
|
+
import { createNode, defaultLibp2pConfig, multiaddr, pipe, pushable, } from '@olane/o-config';
|
|
2
|
+
import { CoreUtils, NodeState, NodeType, oAddress, oConnectionManager, oCoreNode, oRequest, } from '../core';
|
|
3
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
4
|
+
import { NextHopResolver } from '../core';
|
|
5
|
+
import { register } from 'prom-client';
|
|
6
|
+
import { NetworkActivity } from './lib/network-activity.lib';
|
|
7
|
+
import { oToolError } from '../error/tool.error';
|
|
8
|
+
import { oToolErrorCodes } from '../error/enums/codes.error';
|
|
9
|
+
import { oAgentPlan } from '../plan/agent.plan';
|
|
10
|
+
import { oPlanContext } from '../plan/plan.context';
|
|
11
|
+
import { oConfigurePlan } from '../plan/configure/configure.plan';
|
|
15
12
|
const started = false;
|
|
16
|
-
const sharedRegistry =
|
|
13
|
+
const sharedRegistry = register;
|
|
17
14
|
// Enable default Node.js metrics
|
|
18
15
|
// collectDefaultMetrics({ register: sharedRegistry });
|
|
19
|
-
class oNode extends
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
export class oNode extends oCoreNode {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(...arguments);
|
|
19
|
+
this.childNodes = [];
|
|
20
|
+
this.childAddresses = [];
|
|
21
|
+
}
|
|
23
22
|
validate() {
|
|
24
|
-
if (this.p2pNode && this.state !==
|
|
23
|
+
if (this.p2pNode && this.state !== NodeState.STOPPED) {
|
|
25
24
|
throw new Error('Node is not in a valid state to be initialized');
|
|
26
25
|
}
|
|
27
26
|
}
|
|
28
27
|
async _tool_handshake(handshake) {
|
|
29
28
|
this.logger.debug('Performing handshake with intent: ', handshake.params.intent);
|
|
30
|
-
const pc = new
|
|
29
|
+
const pc = new oConfigurePlan({
|
|
31
30
|
intent: `This is a handshake request. You have already found the tool to resolve the user's intent: ${this.address.toString()}. Configure the handshake for the request to use the tool with user intent: ${handshake.params.intent}`,
|
|
32
31
|
currentNode: this,
|
|
33
32
|
caller: this.address,
|
|
34
|
-
context: new
|
|
33
|
+
context: new oPlanContext([
|
|
35
34
|
`[Method Metadata Begin]\n${JSON.stringify(this.methods)}\n[Method Metadata End]`,
|
|
36
35
|
`[Method Options Begin]\n${this.myTools().join(', ')}\n[Method Options End]`,
|
|
37
36
|
]),
|
|
@@ -50,7 +49,7 @@ class oNode extends core_1.oCoreNode {
|
|
|
50
49
|
.map((key) => key.replace('_tool_', ''));
|
|
51
50
|
}
|
|
52
51
|
async applyBridgeTransports(address, request) {
|
|
53
|
-
throw new
|
|
52
|
+
throw new oToolError(oToolErrorCodes.TOOL_TRANSPORT_NOT_SUPPORTED, 'Bridge transports not implemented');
|
|
54
53
|
}
|
|
55
54
|
matchAgainstMethods(address) {
|
|
56
55
|
const methods = this.myTools();
|
|
@@ -69,11 +68,11 @@ class oNode extends core_1.oCoreNode {
|
|
|
69
68
|
});
|
|
70
69
|
counter?.increment();
|
|
71
70
|
const { address } = request.params;
|
|
72
|
-
const destinationAddress = new
|
|
71
|
+
const destinationAddress = new oAddress(address);
|
|
73
72
|
// determine the next hop address from the encapsulated address
|
|
74
73
|
const nextHopAddress = await this.addressResolution.resolve(destinationAddress);
|
|
75
74
|
// prepare the request for the destination receiver
|
|
76
|
-
let forwardRequest = new
|
|
75
|
+
let forwardRequest = new oRequest({
|
|
77
76
|
params: payload.params,
|
|
78
77
|
id: request.id,
|
|
79
78
|
method: payload.method,
|
|
@@ -98,20 +97,20 @@ class oNode extends core_1.oCoreNode {
|
|
|
98
97
|
});
|
|
99
98
|
if (response.result.error) {
|
|
100
99
|
const error = response.result.error;
|
|
101
|
-
throw new
|
|
100
|
+
throw new oToolError(error.code, error.message);
|
|
102
101
|
}
|
|
103
102
|
return response.result.data;
|
|
104
103
|
}
|
|
105
104
|
const targetStream = await this.p2pNode.dialProtocol(transports, nextHopAddress.protocol);
|
|
106
105
|
// if not at destination, we need to forward the request to the target
|
|
107
106
|
if (!isAtDestination) {
|
|
108
|
-
forwardRequest = new
|
|
107
|
+
forwardRequest = new oRequest(request);
|
|
109
108
|
}
|
|
110
|
-
const pushableStream =
|
|
109
|
+
const pushableStream = pushable();
|
|
111
110
|
pushableStream.push(new TextEncoder().encode(forwardRequest.toString()));
|
|
112
111
|
pushableStream.end();
|
|
113
112
|
await targetStream.sink(pushableStream);
|
|
114
|
-
await
|
|
113
|
+
await pipe(targetStream.source, request.stream.sink);
|
|
115
114
|
}
|
|
116
115
|
/**
|
|
117
116
|
* Where all intents go to be resolved.
|
|
@@ -121,12 +120,12 @@ class oNode extends core_1.oCoreNode {
|
|
|
121
120
|
async _tool_intent(request) {
|
|
122
121
|
this.logger.debug('Intent resolution called: ', request.params);
|
|
123
122
|
const { intent, context } = request.params;
|
|
124
|
-
const pc = new
|
|
123
|
+
const pc = new oAgentPlan({
|
|
125
124
|
intent: intent,
|
|
126
125
|
currentNode: this,
|
|
127
126
|
caller: this.address,
|
|
128
127
|
context: context
|
|
129
|
-
? new
|
|
128
|
+
? new oPlanContext([
|
|
130
129
|
`[Chat History Context Begin]\n${context}\n[Chat History Context End]`,
|
|
131
130
|
])
|
|
132
131
|
: undefined,
|
|
@@ -154,12 +153,12 @@ class oNode extends core_1.oCoreNode {
|
|
|
154
153
|
this.logger.debug('Initializing contained children nodes...', this.childNodes.length);
|
|
155
154
|
await Promise.all(this.childNodes.map(async (node) => {
|
|
156
155
|
try {
|
|
157
|
-
if (node.state !==
|
|
156
|
+
if (node.state !== NodeState.STOPPED) {
|
|
158
157
|
return;
|
|
159
158
|
}
|
|
160
159
|
node.config.parent = this.address;
|
|
161
160
|
// forward the network leader address to the child node
|
|
162
|
-
if (this.type ===
|
|
161
|
+
if (this.type === NodeType.LEADER) {
|
|
163
162
|
node.config.leader = this.address;
|
|
164
163
|
}
|
|
165
164
|
else {
|
|
@@ -184,7 +183,7 @@ class oNode extends core_1.oCoreNode {
|
|
|
184
183
|
}
|
|
185
184
|
async _tool_add_child(request) {
|
|
186
185
|
const { address, transports } = request.params;
|
|
187
|
-
const childAddress = new
|
|
186
|
+
const childAddress = new oAddress(address, transports.map((t) => multiaddr(t)));
|
|
188
187
|
this.childAddresses.push(childAddress);
|
|
189
188
|
return {
|
|
190
189
|
message: 'Child node registered with parent!',
|
|
@@ -206,8 +205,8 @@ class oNode extends core_1.oCoreNode {
|
|
|
206
205
|
...this.networkConfig,
|
|
207
206
|
transports: this.configureTransports(),
|
|
208
207
|
listeners: (this.config.network?.listeners ||
|
|
209
|
-
|
|
210
|
-
[]).concat(`/memory/${(
|
|
208
|
+
defaultLibp2pConfig.listeners ||
|
|
209
|
+
[]).concat(`/memory/${uuidv4()}`), // ensure we allow for local in-memory communication
|
|
211
210
|
};
|
|
212
211
|
// TODO: remove this once we have a proper metrics system
|
|
213
212
|
if (!started) {
|
|
@@ -218,7 +217,7 @@ class oNode extends core_1.oCoreNode {
|
|
|
218
217
|
}
|
|
219
218
|
// if the seed is provided, use it to generate the private key
|
|
220
219
|
if (this.config.seed) {
|
|
221
|
-
const privateKey = await
|
|
220
|
+
const privateKey = await CoreUtils.generatePrivateKey(this.config.seed);
|
|
222
221
|
params.privateKey = privateKey;
|
|
223
222
|
}
|
|
224
223
|
else {
|
|
@@ -291,7 +290,7 @@ class oNode extends core_1.oCoreNode {
|
|
|
291
290
|
!this.address.protocol.includes(this.config.leader.protocol)) {
|
|
292
291
|
const parentAddress = this.config.parent || this.config.leader;
|
|
293
292
|
this.logger.debug('Encapsulating address: ' + this.address.toString(), parentAddress.toString());
|
|
294
|
-
this.address =
|
|
293
|
+
this.address = CoreUtils.childAddress(parentAddress, this.address);
|
|
295
294
|
}
|
|
296
295
|
return params;
|
|
297
296
|
}
|
|
@@ -299,16 +298,16 @@ class oNode extends core_1.oCoreNode {
|
|
|
299
298
|
this.logger.debug('Initializing node...');
|
|
300
299
|
this.validate();
|
|
301
300
|
const params = await this.configure();
|
|
302
|
-
this.p2pNode = await
|
|
303
|
-
this.address.setTransports(this.transports.map((t) =>
|
|
301
|
+
this.p2pNode = await createNode(params);
|
|
302
|
+
this.address.setTransports(this.transports.map((t) => multiaddr(t)));
|
|
304
303
|
this.peerId = this.p2pNode.peerId;
|
|
305
304
|
// initialize connection manager
|
|
306
|
-
this.connectionManager = new
|
|
305
|
+
this.connectionManager = new oConnectionManager({
|
|
307
306
|
logger: this.logger,
|
|
308
307
|
p2pNode: this.p2pNode,
|
|
309
308
|
});
|
|
310
309
|
// initialize address resolution
|
|
311
|
-
this.addressResolution.addResolver(new
|
|
310
|
+
this.addressResolution.addResolver(new NextHopResolver(this.address, this.p2pNode));
|
|
312
311
|
// listen for network events
|
|
313
312
|
// this.listenForNetworkEvents();
|
|
314
313
|
// if (this.type === NodeType.LEADER && (this.config.metrics || true)) {
|
|
@@ -536,7 +535,7 @@ class oNode extends core_1.oCoreNode {
|
|
|
536
535
|
// }
|
|
537
536
|
}
|
|
538
537
|
listenForNetworkEvents() {
|
|
539
|
-
this.networkActivity = new
|
|
538
|
+
this.networkActivity = new NetworkActivity(this.logger, this.p2pNode);
|
|
540
539
|
}
|
|
541
540
|
async teardown() {
|
|
542
541
|
for (const node of this.childNodes) {
|
|
@@ -546,4 +545,3 @@ class oNode extends core_1.oCoreNode {
|
|
|
546
545
|
return super.teardown();
|
|
547
546
|
}
|
|
548
547
|
}
|
|
549
|
-
exports.oNode = oNode;
|
|
@@ -1,26 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.oHostNode = void 0;
|
|
4
|
-
const o_config_1 = require("@olane/o-config");
|
|
5
|
-
const node_1 = require("../node");
|
|
1
|
+
import { defaultLibp2pConfig, memory } from '@olane/o-config';
|
|
2
|
+
import { oNode } from '../node';
|
|
6
3
|
/**
|
|
7
4
|
* A standalone node that can be used to host other nodes.
|
|
8
5
|
* Can be useful for separating various buckets of functionality.
|
|
9
6
|
* Think about microservice best practices.
|
|
10
7
|
* These nodes are addressable via TCP/IP.
|
|
11
8
|
*/
|
|
12
|
-
class oHostNode extends
|
|
9
|
+
export class oHostNode extends oNode {
|
|
13
10
|
async initialize() {
|
|
14
11
|
// start the current node
|
|
15
12
|
await super.initialize();
|
|
16
13
|
}
|
|
17
14
|
configureTransports() {
|
|
18
15
|
return [
|
|
19
|
-
|
|
16
|
+
memory(),
|
|
20
17
|
...(this.config.network?.transports ||
|
|
21
|
-
|
|
18
|
+
defaultLibp2pConfig.transports ||
|
|
22
19
|
[]),
|
|
23
20
|
];
|
|
24
21
|
}
|
|
25
22
|
}
|
|
26
|
-
exports.oHostNode = oHostNode;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './host.node';
|
|
1
|
+
export * from './host.node.js';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node-host/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node-host/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
package/dist/node-host/index.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./host.node"), exports);
|
|
1
|
+
export * from './host.node.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './virtual.node';
|
|
1
|
+
export * from './virtual.node.js';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node-virtual/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node-virtual/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
|
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./virtual.node"), exports);
|
|
1
|
+
export * from './virtual.node.js';
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const o_config_1 = require("@olane/o-config");
|
|
5
|
-
const node_1 = require("../node");
|
|
6
|
-
class oVirtualNode extends node_1.oNode {
|
|
1
|
+
import { memory } from '@olane/o-config';
|
|
2
|
+
import { oNode } from '../node';
|
|
3
|
+
export class oVirtualNode extends oNode {
|
|
7
4
|
/**
|
|
8
5
|
* Virtual nodes are only used for local communication, so we need to configure
|
|
9
6
|
* the transports to be in-memory.
|
|
10
7
|
* @returns The transports for the virtual node
|
|
11
8
|
*/
|
|
12
9
|
configureTransports() {
|
|
13
|
-
return [
|
|
10
|
+
return [memory()];
|
|
14
11
|
}
|
|
15
12
|
}
|
|
16
|
-
exports.oVirtualNode = oVirtualNode;
|
package/dist/plan/agent.plan.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const use_plan_1 = require("./use/use.plan");
|
|
7
|
-
const search_plan_1 = require("./search/search.plan");
|
|
8
|
-
const error_plan_1 = require("./error/error.plan");
|
|
1
|
+
import { oAddress } from '../core';
|
|
2
|
+
import { oPlan } from './o-plan';
|
|
3
|
+
import { oUsePlan } from './use/use.plan';
|
|
4
|
+
import { oSearchPlan } from './search/search.plan';
|
|
5
|
+
import { oErrorPlan } from './error/error.plan';
|
|
9
6
|
/**
|
|
10
7
|
* oAgentPlan is responsible for managing the execution of plans.
|
|
11
8
|
* General execution flow:
|
|
@@ -14,11 +11,11 @@ const error_plan_1 = require("./error/error.plan");
|
|
|
14
11
|
* 3. Use network tools + context to solve intent
|
|
15
12
|
* 4. Back to step 1
|
|
16
13
|
*/
|
|
17
|
-
class oAgentPlan extends
|
|
18
|
-
MAX_ITERATIONS = 20;
|
|
19
|
-
contextIdHash = {};
|
|
14
|
+
export class oAgentPlan extends oPlan {
|
|
20
15
|
constructor(config) {
|
|
21
16
|
super(config);
|
|
17
|
+
this.MAX_ITERATIONS = 20;
|
|
18
|
+
this.contextIdHash = {};
|
|
22
19
|
}
|
|
23
20
|
async handleTasks(results, config) {
|
|
24
21
|
this.logger.debug('Handling task...', results);
|
|
@@ -32,11 +29,11 @@ class oAgentPlan extends o_plan_1.oPlan {
|
|
|
32
29
|
throw new Error('Invalid address passed to handleTask');
|
|
33
30
|
}
|
|
34
31
|
// perform task if necessary
|
|
35
|
-
const taskPlan = new
|
|
32
|
+
const taskPlan = new oUsePlan({
|
|
36
33
|
...config,
|
|
37
34
|
intent: this.config.intent,
|
|
38
35
|
context: this.config.context,
|
|
39
|
-
receiver: new
|
|
36
|
+
receiver: new oAddress(task.address),
|
|
40
37
|
});
|
|
41
38
|
const taskResult = await taskPlan.execute();
|
|
42
39
|
this.sequence.push(taskPlan);
|
|
@@ -53,7 +50,7 @@ class oAgentPlan extends o_plan_1.oPlan {
|
|
|
53
50
|
}
|
|
54
51
|
const results = [];
|
|
55
52
|
for (const query of queries) {
|
|
56
|
-
const searchPlan = new
|
|
53
|
+
const searchPlan = new oSearchPlan({
|
|
57
54
|
...config,
|
|
58
55
|
intent: `Searching for context to help with the user intent`,
|
|
59
56
|
query: query?.query,
|
|
@@ -68,7 +65,7 @@ class oAgentPlan extends o_plan_1.oPlan {
|
|
|
68
65
|
}
|
|
69
66
|
async handleError(error, config) {
|
|
70
67
|
this.logger.debug('Handling error...', error);
|
|
71
|
-
const errorPlan = new
|
|
68
|
+
const errorPlan = new oErrorPlan({
|
|
72
69
|
...config,
|
|
73
70
|
error: error,
|
|
74
71
|
});
|
|
@@ -112,7 +109,7 @@ class oAgentPlan extends o_plan_1.oPlan {
|
|
|
112
109
|
sequence: this.sequence,
|
|
113
110
|
};
|
|
114
111
|
// search or resolve the intent with tool usage
|
|
115
|
-
const plan = new
|
|
112
|
+
const plan = new oPlan(planConfig);
|
|
116
113
|
const response = await plan.execute();
|
|
117
114
|
// all plans are wrappers of AI around current state
|
|
118
115
|
const planResult = response;
|
|
@@ -163,4 +160,3 @@ class oAgentPlan extends o_plan_1.oPlan {
|
|
|
163
160
|
return await this.loop();
|
|
164
161
|
}
|
|
165
162
|
}
|
|
166
|
-
exports.oAgentPlan = oAgentPlan;
|