@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.
- package/README.md +490 -140
- package/dist/src/connection/index.d.ts +8 -0
- package/dist/src/connection/index.d.ts.map +1 -0
- package/dist/src/connection/index.js +7 -0
- package/dist/src/connection/interfaces/connection-manager.config.d.ts +3 -0
- package/dist/src/connection/interfaces/connection-manager.config.d.ts.map +1 -0
- package/dist/src/connection/interfaces/connection-send-params.interface.d.ts.map +1 -0
- package/dist/src/connection/interfaces/connection.config.d.ts +7 -0
- package/dist/src/connection/interfaces/connection.config.d.ts.map +1 -0
- package/dist/src/connection/interfaces/index.d.ts +5 -0
- package/dist/src/connection/interfaces/index.d.ts.map +1 -0
- package/dist/src/connection/interfaces/index.js +4 -0
- package/dist/src/connection/interfaces/request-state.enum.d.ts +7 -0
- package/dist/src/connection/interfaces/request-state.enum.d.ts.map +1 -0
- package/dist/src/connection/interfaces/request-state.enum.js +7 -0
- package/dist/src/connection/o-connection-manager.d.ts +19 -0
- package/dist/src/connection/o-connection-manager.d.ts.map +1 -0
- package/dist/src/connection/o-connection-manager.js +27 -0
- package/dist/src/connection/o-connection.d.ts +20 -0
- package/dist/src/connection/o-connection.d.ts.map +1 -0
- package/dist/src/connection/o-connection.js +45 -0
- package/dist/src/{core/lib → connection}/o-request.d.ts +5 -1
- package/dist/src/connection/o-request.d.ts.map +1 -0
- package/dist/src/{core/lib → connection}/o-request.js +8 -1
- package/dist/src/connection/o-response.d.ts.map +1 -0
- package/dist/src/core/defaults/config.d.ts +1 -1
- package/dist/src/core/defaults/config.d.ts.map +1 -1
- package/dist/src/core/defaults/config.js +1 -1
- package/dist/src/core/graceful-shutdown.d.ts +1 -1
- package/dist/src/core/graceful-shutdown.d.ts.map +1 -1
- package/dist/src/core/graceful-shutdown.js +1 -1
- package/dist/src/core/index.d.ts +3 -5
- package/dist/src/core/index.d.ts.map +1 -1
- package/dist/src/core/index.js +3 -5
- package/dist/src/core/interfaces/index.d.ts +1 -2
- package/dist/src/core/interfaces/index.d.ts.map +1 -1
- package/dist/src/core/interfaces/index.js +1 -2
- package/dist/src/core/interfaces/{core-config.interface.d.ts → o-core.config.d.ts} +4 -5
- package/dist/src/core/interfaces/o-core.config.d.ts.map +1 -0
- package/dist/src/core/interfaces/o-core.interface.d.ts +18 -0
- package/dist/src/core/interfaces/o-core.interface.d.ts.map +1 -0
- package/dist/src/core/lib/index.d.ts +3 -7
- package/dist/src/core/lib/index.d.ts.map +1 -1
- package/dist/src/core/lib/index.js +3 -7
- package/dist/src/core/lib/o-hierarchy.manager.d.ts +24 -0
- package/dist/src/core/lib/o-hierarchy.manager.d.ts.map +1 -0
- package/dist/src/core/lib/o-hierarchy.manager.js +57 -0
- package/dist/src/core/lib/o-metrics.d.ts +5 -0
- package/dist/src/core/lib/o-metrics.d.ts.map +1 -0
- package/dist/src/core/lib/o-metrics.js +6 -0
- package/dist/src/core/lib/o-request.manager.d.ts +10 -0
- package/dist/src/core/lib/o-request.manager.d.ts.map +1 -0
- package/dist/src/core/lib/o-request.manager.js +18 -0
- package/dist/src/core/o-core.d.ts +190 -0
- package/dist/src/core/o-core.d.ts.map +1 -0
- package/dist/src/core/o-core.js +334 -0
- package/dist/src/core/o-object.d.ts +7 -0
- package/dist/src/core/o-object.d.ts.map +1 -0
- package/dist/src/core/o-object.js +10 -0
- package/dist/src/error/enums/codes.error.d.ts +16 -14
- package/dist/src/error/enums/codes.error.d.ts.map +1 -1
- package/dist/src/error/enums/codes.error.js +18 -16
- package/dist/src/error/index.d.ts +1 -1
- package/dist/src/error/index.d.ts.map +1 -1
- package/dist/src/error/index.js +1 -1
- package/dist/src/error/interfaces/o-error.interface.d.ts +6 -0
- package/dist/src/error/interfaces/o-error.interface.d.ts.map +1 -0
- package/dist/src/error/o-error.d.ts +15 -0
- package/dist/src/error/o-error.d.ts.map +1 -0
- package/dist/src/error/{tool.error.js → o-error.js} +4 -4
- package/dist/src/index.d.ts +3 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -3
- package/dist/src/router/enums/restricted-addresses.enum.d.ts +8 -0
- package/dist/src/router/enums/restricted-addresses.enum.d.ts.map +1 -0
- package/dist/src/router/enums/restricted-addresses.enum.js +13 -0
- package/dist/src/router/index.d.ts +9 -0
- package/dist/src/router/index.d.ts.map +1 -0
- package/dist/src/router/index.js +8 -0
- package/dist/src/router/interfaces/resolve.request.d.ts +10 -0
- package/dist/src/router/interfaces/resolve.request.d.ts.map +1 -0
- package/dist/src/router/interfaces/route.response.d.ts +8 -0
- package/dist/src/router/interfaces/route.response.d.ts.map +1 -0
- package/dist/src/router/o-address-resolution.d.ts +12 -0
- package/dist/src/router/o-address-resolution.d.ts.map +1 -0
- package/dist/src/router/o-address-resolution.js +42 -0
- package/dist/src/router/o-address-resolver.d.ts +14 -0
- package/dist/src/router/o-address-resolver.d.ts.map +1 -0
- package/dist/src/router/o-address-resolver.js +19 -0
- package/dist/src/router/o-address.d.ts +33 -0
- package/dist/src/router/o-address.d.ts.map +1 -0
- package/dist/src/router/o-address.js +101 -0
- package/dist/src/router/o-request.router.d.ts +18 -0
- package/dist/src/router/o-request.router.d.ts.map +1 -0
- package/dist/src/router/o-request.router.js +12 -0
- package/dist/src/router/o-router.d.ts +19 -0
- package/dist/src/router/o-router.d.ts.map +1 -0
- package/dist/src/router/o-router.js +14 -0
- package/dist/src/transports/custom.transport.d.ts +6 -0
- package/dist/src/transports/custom.transport.d.ts.map +1 -0
- package/dist/src/transports/custom.transport.js +10 -0
- package/dist/src/transports/index.d.ts +4 -0
- package/dist/src/transports/index.d.ts.map +1 -0
- package/dist/src/transports/index.js +3 -0
- package/dist/src/transports/interfaces/transport-type.enum.d.ts +5 -0
- package/dist/src/transports/interfaces/transport-type.enum.d.ts.map +1 -0
- package/dist/src/transports/interfaces/transport-type.enum.js +5 -0
- package/dist/src/transports/o-transport.d.ts +10 -0
- package/dist/src/transports/o-transport.d.ts.map +1 -0
- package/dist/src/transports/o-transport.js +16 -0
- package/dist/src/{core/utils → utils}/core.utils.d.ts +4 -3
- package/dist/src/utils/core.utils.d.ts.map +1 -0
- package/dist/src/{core/utils → utils}/core.utils.js +17 -2
- package/dist/src/utils/index.d.ts +2 -0
- package/dist/src/utils/index.d.ts.map +1 -1
- package/dist/src/utils/index.js +2 -0
- package/dist/src/{core/utils → utils}/logger.d.ts +1 -0
- package/dist/src/utils/logger.d.ts.map +1 -0
- package/dist/src/{core/utils → utils}/logger.js +4 -1
- package/dist/test/server/in-process.spec.js +2 -14
- package/package.json +3 -3
- package/dist/src/core/core.node.d.ts +0 -79
- package/dist/src/core/core.node.d.ts.map +0 -1
- package/dist/src/core/core.node.js +0 -304
- package/dist/src/core/interfaces/connection-manager.config.d.ts +0 -7
- package/dist/src/core/interfaces/connection-manager.config.d.ts.map +0 -1
- package/dist/src/core/interfaces/connection-send-params.interface.d.ts.map +0 -1
- package/dist/src/core/interfaces/core-config.interface.d.ts.map +0 -1
- package/dist/src/core/interfaces/restricted-addresses.enum.d.ts +0 -13
- package/dist/src/core/interfaces/restricted-addresses.enum.d.ts.map +0 -1
- package/dist/src/core/interfaces/restricted-addresses.enum.js +0 -18
- package/dist/src/core/lib/o-address-resolution.d.ts +0 -9
- package/dist/src/core/lib/o-address-resolution.d.ts.map +0 -1
- package/dist/src/core/lib/o-address-resolution.js +0 -24
- package/dist/src/core/lib/o-address-resolver.d.ts +0 -17
- package/dist/src/core/lib/o-address-resolver.d.ts.map +0 -1
- package/dist/src/core/lib/o-address-resolver.js +0 -36
- package/dist/src/core/lib/o-connection-manager.d.ts +0 -22
- package/dist/src/core/lib/o-connection-manager.d.ts.map +0 -1
- package/dist/src/core/lib/o-connection-manager.js +0 -65
- package/dist/src/core/lib/o-connection.d.ts +0 -27
- package/dist/src/core/lib/o-connection.d.ts.map +0 -1
- package/dist/src/core/lib/o-connection.js +0 -84
- package/dist/src/core/lib/o-request.d.ts.map +0 -1
- package/dist/src/core/lib/o-response.d.ts.map +0 -1
- package/dist/src/core/lib/resolvers/anything.resolver.d.ts +0 -8
- package/dist/src/core/lib/resolvers/anything.resolver.d.ts.map +0 -1
- package/dist/src/core/lib/resolvers/anything.resolver.js +0 -15
- package/dist/src/core/lib/resolvers/index.d.ts +0 -5
- package/dist/src/core/lib/resolvers/index.d.ts.map +0 -1
- package/dist/src/core/lib/resolvers/index.js +0 -4
- package/dist/src/core/lib/resolvers/method.resolver.d.ts +0 -8
- package/dist/src/core/lib/resolvers/method.resolver.d.ts.map +0 -1
- package/dist/src/core/lib/resolvers/method.resolver.js +0 -18
- package/dist/src/core/lib/resolvers/next-hop.resolver.d.ts +0 -10
- package/dist/src/core/lib/resolvers/next-hop.resolver.d.ts.map +0 -1
- package/dist/src/core/lib/resolvers/next-hop.resolver.js +0 -59
- package/dist/src/core/lib/resolvers/storage.resolver.d.ts +0 -6
- package/dist/src/core/lib/resolvers/storage.resolver.d.ts.map +0 -1
- package/dist/src/core/lib/resolvers/storage.resolver.js +0 -10
- package/dist/src/core/o-address.d.ts +0 -20
- package/dist/src/core/o-address.d.ts.map +0 -1
- package/dist/src/core/o-address.js +0 -47
- package/dist/src/core/utils/core.utils.d.ts.map +0 -1
- package/dist/src/core/utils/index.d.ts +0 -4
- package/dist/src/core/utils/index.d.ts.map +0 -1
- package/dist/src/core/utils/index.js +0 -3
- package/dist/src/core/utils/logger.d.ts.map +0 -1
- package/dist/src/core/utils/network.utils.d.ts +0 -16
- package/dist/src/core/utils/network.utils.d.ts.map +0 -1
- package/dist/src/core/utils/network.utils.js +0 -35
- package/dist/src/error/tool.error.d.ts +0 -19
- package/dist/src/error/tool.error.d.ts.map +0 -1
- package/dist/src/node/index.d.ts +0 -4
- package/dist/src/node/index.d.ts.map +0 -1
- package/dist/src/node/index.js +0 -3
- package/dist/src/node/interfaces/route.request.d.ts +0 -14
- package/dist/src/node/interfaces/route.request.d.ts.map +0 -1
- package/dist/src/node/lib/local-search.lib.d.ts +0 -6
- package/dist/src/node/lib/local-search.lib.d.ts.map +0 -1
- package/dist/src/node/lib/local-search.lib.js +0 -10
- package/dist/src/node/lib/network-activity.lib.d.ts +0 -12
- package/dist/src/node/lib/network-activity.lib.d.ts.map +0 -1
- package/dist/src/node/lib/network-activity.lib.js +0 -29
- package/dist/src/node/node.d.ts +0 -45
- package/dist/src/node/node.d.ts.map +0 -1
- package/dist/src/node/node.js +0 -359
- package/dist/src/node-virtual/index.d.ts +0 -2
- package/dist/src/node-virtual/index.d.ts.map +0 -1
- package/dist/src/node-virtual/index.js +0 -1
- package/dist/src/node-virtual/virtual.node.d.ts +0 -10
- package/dist/src/node-virtual/virtual.node.d.ts.map +0 -1
- package/dist/src/node-virtual/virtual.node.js +0 -12
- package/dist/src/plan/agent.plan.d.ts +0 -28
- package/dist/src/plan/agent.plan.d.ts.map +0 -1
- package/dist/src/plan/agent.plan.js +0 -187
- package/dist/src/plan/index.d.ts +0 -5
- package/dist/src/plan/index.d.ts.map +0 -1
- package/dist/src/plan/index.js +0 -4
- package/dist/src/plan/interfaces/configure.result.d.ts +0 -6
- package/dist/src/plan/interfaces/configure.result.d.ts.map +0 -1
- package/dist/src/plan/interfaces/handshake.result.d.ts +0 -14
- package/dist/src/plan/interfaces/handshake.result.d.ts.map +0 -1
- package/dist/src/plan/interfaces/plan-config.interface.d.ts +0 -16
- package/dist/src/plan/interfaces/plan-config.interface.d.ts.map +0 -1
- package/dist/src/plan/interfaces/plan-result.interface.d.ts +0 -6
- package/dist/src/plan/interfaces/plan-result.interface.d.ts.map +0 -1
- package/dist/src/plan/interfaces/plan-type.enum.d.ts +0 -8
- package/dist/src/plan/interfaces/plan-type.enum.d.ts.map +0 -1
- package/dist/src/plan/interfaces/plan-type.enum.js +0 -8
- package/dist/src/plan/interfaces/plan.result.d.ts +0 -15
- package/dist/src/plan/interfaces/plan.result.d.ts.map +0 -1
- package/dist/src/plan/interfaces/plan.result.js +0 -1
- package/dist/src/plan/interfaces/query.config.d.ts +0 -6
- package/dist/src/plan/interfaces/query.config.d.ts.map +0 -1
- package/dist/src/plan/interfaces/query.config.js +0 -1
- package/dist/src/plan/interfaces/task.config.d.ts +0 -10
- package/dist/src/plan/interfaces/task.config.d.ts.map +0 -1
- package/dist/src/plan/interfaces/task.config.js +0 -1
- package/dist/src/plan/o-plan.d.ts +0 -36
- package/dist/src/plan/o-plan.d.ts.map +0 -1
- package/dist/src/plan/o-plan.js +0 -202
- package/dist/src/plan/plan.context.d.ts +0 -10
- package/dist/src/plan/plan.context.d.ts.map +0 -1
- package/dist/src/plan/plan.context.js +0 -28
- package/dist/src/plan/prompts/agent.prompt.d.ts +0 -2
- package/dist/src/plan/prompts/agent.prompt.d.ts.map +0 -1
- package/dist/src/plan/prompts/agent.prompt.js +0 -112
- package/dist/src/plan/prompts/configure.prompt.d.ts +0 -2
- package/dist/src/plan/prompts/configure.prompt.d.ts.map +0 -1
- package/dist/src/plan/prompts/configure.prompt.js +0 -40
- package/dist/src/plan/prompts/custom.prompt.d.ts +0 -2
- package/dist/src/plan/prompts/custom.prompt.d.ts.map +0 -1
- package/dist/src/plan/prompts/custom.prompt.js +0 -80
- package/dist/src/plan/search/prompts/search-analysis.prompt.d.ts +0 -2
- package/dist/src/plan/search/prompts/search-analysis.prompt.d.ts.map +0 -1
- package/dist/src/plan/search/prompts/search-analysis.prompt.js +0 -14
- package/dist/src/plan/search/search.plan.d.ts +0 -21
- package/dist/src/plan/search/search.plan.d.ts.map +0 -1
- package/dist/src/plan/search/search.plan.js +0 -53
- package/dist/src/plan/use/index.d.ts +0 -2
- package/dist/src/plan/use/index.d.ts.map +0 -1
- package/dist/src/plan/use/index.js +0 -1
- package/dist/src/plan/use/use.plan.d.ts +0 -16
- package/dist/src/plan/use/use.plan.d.ts.map +0 -1
- package/dist/src/plan/use/use.plan.js +0 -149
- /package/dist/src/{core → connection}/interfaces/connection-manager.config.js +0 -0
- /package/dist/src/{core → connection}/interfaces/connection-send-params.interface.d.ts +0 -0
- /package/dist/src/{core → connection}/interfaces/connection-send-params.interface.js +0 -0
- /package/dist/src/{core/interfaces/core-config.interface.js → connection/interfaces/connection.config.js} +0 -0
- /package/dist/src/{core/lib → connection}/o-response.d.ts +0 -0
- /package/dist/src/{core/lib → connection}/o-response.js +0 -0
- /package/dist/src/{node/interfaces/route.request.js → core/interfaces/o-core.config.js} +0 -0
- /package/dist/src/{plan/interfaces/configure.result.js → core/interfaces/o-core.interface.js} +0 -0
- /package/dist/src/{plan/interfaces/handshake.result.js → error/interfaces/o-error.interface.js} +0 -0
- /package/dist/src/{plan/interfaces/plan-config.interface.js → router/interfaces/resolve.request.js} +0 -0
- /package/dist/src/{plan/interfaces/plan-result.interface.js → router/interfaces/route.response.js} +0 -0
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import { oAddress } from '../core/index.js';
|
|
2
|
-
import { oPlan } from './o-plan.js';
|
|
3
|
-
import { oUsePlan } from './use/use.plan.js';
|
|
4
|
-
import { oSearchPlan } from './search/search.plan.js';
|
|
5
|
-
/**
|
|
6
|
-
* oAgentPlan is responsible for managing the execution of plans.
|
|
7
|
-
* General execution flow:
|
|
8
|
-
* 1. Analyze intent
|
|
9
|
-
* 2. Search for context
|
|
10
|
-
* 3. Use network tools + context to solve intent
|
|
11
|
-
* 4. Back to step 1
|
|
12
|
-
*/
|
|
13
|
-
export class oAgentPlan extends oPlan {
|
|
14
|
-
constructor(config) {
|
|
15
|
-
super(config);
|
|
16
|
-
this.MAX_ITERATIONS = 20;
|
|
17
|
-
this.contextIdHash = {};
|
|
18
|
-
}
|
|
19
|
-
async doTask(task, config) {
|
|
20
|
-
this.logger.debug('Doing task...', task);
|
|
21
|
-
const taskPlan = new oUsePlan({
|
|
22
|
-
...config,
|
|
23
|
-
intent: this.config.intent,
|
|
24
|
-
context: this.config.context,
|
|
25
|
-
receiver: new oAddress(task.address),
|
|
26
|
-
sequence: this.sequence,
|
|
27
|
-
});
|
|
28
|
-
const taskResult = await taskPlan.execute();
|
|
29
|
-
this.addSequencePlan(taskPlan);
|
|
30
|
-
this.logger.debug('Pushed task plan to sequence: ', taskResult.result);
|
|
31
|
-
if (taskResult.error) {
|
|
32
|
-
this.logger.debug('Task error: ', taskResult.error);
|
|
33
|
-
// const errorResult = await this.handleError(taskResult.error, config);
|
|
34
|
-
// if (errorResult.type === 'result') {
|
|
35
|
-
// return errorResult;
|
|
36
|
-
// }
|
|
37
|
-
// return this.doTask(task, config);
|
|
38
|
-
}
|
|
39
|
-
return taskResult;
|
|
40
|
-
}
|
|
41
|
-
async handleTasks(results, config) {
|
|
42
|
-
this.logger.debug('Handling task...', results);
|
|
43
|
-
const tasks = results.tasks;
|
|
44
|
-
if (!tasks) {
|
|
45
|
-
throw new Error('Invalid task passed to handleTask');
|
|
46
|
-
}
|
|
47
|
-
const taskResults = [];
|
|
48
|
-
for (const task of tasks) {
|
|
49
|
-
if (!task.address) {
|
|
50
|
-
throw new Error('Invalid address passed to handleTask');
|
|
51
|
-
}
|
|
52
|
-
// perform task if necessary
|
|
53
|
-
const result = await this.doTask(task, config);
|
|
54
|
-
taskResults.push(result);
|
|
55
|
-
}
|
|
56
|
-
return taskResults;
|
|
57
|
-
}
|
|
58
|
-
async handleSearch(queries, config) {
|
|
59
|
-
this.logger.debug('Handling searches...', queries);
|
|
60
|
-
if (queries.length === 0) {
|
|
61
|
-
throw new Error('No queries provided to handleSearch');
|
|
62
|
-
}
|
|
63
|
-
const results = [];
|
|
64
|
-
for (const query of queries) {
|
|
65
|
-
const searchPlan = new oSearchPlan({
|
|
66
|
-
...config,
|
|
67
|
-
intent: `Searching for context to help with the user intent`,
|
|
68
|
-
query: query?.query,
|
|
69
|
-
external: query?.provider === 'external',
|
|
70
|
-
});
|
|
71
|
-
const result = await searchPlan.execute();
|
|
72
|
-
this.addSequencePlan(searchPlan);
|
|
73
|
-
this.logger.debug('Search result: ', result.result);
|
|
74
|
-
results.push(result.result);
|
|
75
|
-
}
|
|
76
|
-
return results.flat();
|
|
77
|
-
}
|
|
78
|
-
// async handleError(error: any, config: oPlanConfig): Promise<oPlanResult> {
|
|
79
|
-
// this.logger.debug('Handling error...', error);
|
|
80
|
-
// const errorPlan = new oAgentPlan({
|
|
81
|
-
// ...config,
|
|
82
|
-
// intent: `If this error is already indicating that the user intent is solved, return a result otherwise solve it. The error is: ${error}`,
|
|
83
|
-
// context: this.config.context,
|
|
84
|
-
// sequence: this.sequence,
|
|
85
|
-
// parentId: this.id,
|
|
86
|
-
// });
|
|
87
|
-
// const result = await errorPlan.execute();
|
|
88
|
-
// this.addSequencePlan(errorPlan);
|
|
89
|
-
// return result;
|
|
90
|
-
// }
|
|
91
|
-
/**
|
|
92
|
-
* The analysis of the intent results in a list of steps and queries to complete the intent.
|
|
93
|
-
*/
|
|
94
|
-
async handleMultipleStep(output) {
|
|
95
|
-
const results = [];
|
|
96
|
-
for (const intent of output?.intents || []) {
|
|
97
|
-
const subPlan = new oAgentPlan({
|
|
98
|
-
...this.config,
|
|
99
|
-
intent: intent,
|
|
100
|
-
sequence: this.sequence,
|
|
101
|
-
parentId: this.id,
|
|
102
|
-
});
|
|
103
|
-
const response = await subPlan.execute();
|
|
104
|
-
this.addSequencePlan(subPlan);
|
|
105
|
-
results.push(JSON.stringify(response));
|
|
106
|
-
}
|
|
107
|
-
return {
|
|
108
|
-
result: results,
|
|
109
|
-
type: 'multiple_step',
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
async loop() {
|
|
113
|
-
if (!this.node) {
|
|
114
|
-
throw new Error('Node not set');
|
|
115
|
-
}
|
|
116
|
-
let iterations = 0;
|
|
117
|
-
while (iterations++ < this.MAX_ITERATIONS) {
|
|
118
|
-
this.logger.debug('Plan context size: ', this.config.context?.toString()?.length);
|
|
119
|
-
if (this.config.shouldContinue && !this.config.shouldContinue()) {
|
|
120
|
-
throw new Error('Cancelled');
|
|
121
|
-
}
|
|
122
|
-
// setup the plan config
|
|
123
|
-
const planConfig = {
|
|
124
|
-
...this.config,
|
|
125
|
-
currentNode: this.node,
|
|
126
|
-
caller: this.node?.address,
|
|
127
|
-
sequence: this.sequence,
|
|
128
|
-
};
|
|
129
|
-
// search or resolve the intent with tool usage
|
|
130
|
-
const plan = new oPlan(planConfig);
|
|
131
|
-
const response = await plan.execute();
|
|
132
|
-
// all plans are wrappers of AI around current state
|
|
133
|
-
const planResult = response;
|
|
134
|
-
const { error, result, type } = planResult;
|
|
135
|
-
// update the sequence to reflect state change
|
|
136
|
-
this.addSequencePlan(plan);
|
|
137
|
-
// handle the various result types
|
|
138
|
-
const resultType = type;
|
|
139
|
-
// if there is an answer, return it
|
|
140
|
-
if (resultType === 'result' ||
|
|
141
|
-
resultType === 'error' ||
|
|
142
|
-
resultType === 'handshake' ||
|
|
143
|
-
resultType === 'configure') {
|
|
144
|
-
return planResult;
|
|
145
|
-
}
|
|
146
|
-
// if there are intents, handle them
|
|
147
|
-
if (resultType === 'multiple_step') {
|
|
148
|
-
this.logger.debug('Handling multiple step...', planResult);
|
|
149
|
-
const multipleStepResult = await this.handleMultipleStep(planResult);
|
|
150
|
-
this.config.context?.add(JSON.stringify(multipleStepResult));
|
|
151
|
-
}
|
|
152
|
-
// handle search case
|
|
153
|
-
if (resultType === 'search' && planResult.queries) {
|
|
154
|
-
const searchResults = await this.handleSearch(planResult.queries, planConfig);
|
|
155
|
-
const filteredSearchResults = searchResults.filter((result) => !this.contextIdHash[result?.metadata?.id]);
|
|
156
|
-
let searchResultContext = `[Search Results Begin]`;
|
|
157
|
-
if (filteredSearchResults.length === 0) {
|
|
158
|
-
searchResultContext += `No more search results found!\n\n`;
|
|
159
|
-
}
|
|
160
|
-
// update the context with the search results
|
|
161
|
-
for (const searchResult of filteredSearchResults) {
|
|
162
|
-
// internal search results
|
|
163
|
-
if (searchResult?.metadata) {
|
|
164
|
-
// add the context data
|
|
165
|
-
this.contextIdHash[searchResult?.metadata?.id || '0'] = true;
|
|
166
|
-
searchResultContext += `Tool Address: ${searchResult?.metadata?.address || 'unknown'}\nTool Data: ${searchResult?.pageContent || 'unknown'}\n\n`;
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
searchResultContext += `External Search Result: ${searchResult?.message || 'unknown'}\n\n`;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
searchResultContext += `[Search Results End]`;
|
|
173
|
-
if (filteredSearchResults.length > 0) {
|
|
174
|
-
this.config.context?.add(searchResultContext);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
// if there is a task required, handle it
|
|
178
|
-
if (resultType === 'task') {
|
|
179
|
-
await this.handleTasks(planResult, planConfig);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
throw new Error('Plan failed, reached max iterations');
|
|
183
|
-
}
|
|
184
|
-
async run() {
|
|
185
|
-
return await this.loop();
|
|
186
|
-
}
|
|
187
|
-
}
|
package/dist/src/plan/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plan/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,uCAAuC,CAAC;AACtD,cAAc,uCAAuC,CAAC;AACtD,cAAc,gBAAgB,CAAC"}
|
package/dist/src/plan/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"configure.result.d.ts","sourceRoot":"","sources":["../../../../src/plan/interfaces/configure.result.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,WAAW,CAAC;CACnB"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { oMethod } from '@olane/o-protocol';
|
|
2
|
-
import { oPlanResult } from './plan.result';
|
|
3
|
-
import { oTaskConfig } from './task.config';
|
|
4
|
-
export interface oHandshakeResult {
|
|
5
|
-
tools: string[];
|
|
6
|
-
methods: {
|
|
7
|
-
[key: string]: oMethod;
|
|
8
|
-
};
|
|
9
|
-
successes: oPlanResult[];
|
|
10
|
-
failures: oPlanResult[];
|
|
11
|
-
task?: oTaskConfig;
|
|
12
|
-
type: 'handshake';
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=handshake.result.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handshake.result.d.ts","sourceRoot":"","sources":["../../../../src/plan/interfaces/handshake.result.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IACpC,SAAS,EAAE,WAAW,EAAE,CAAC;IACzB,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,IAAI,EAAE,WAAW,CAAC;CACnB"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { oAddress, oCoreNode } from '../../core/index.js';
|
|
2
|
-
import { oPlanContext } from '../plan.context.js';
|
|
3
|
-
export interface oPlanConfig {
|
|
4
|
-
intent: string;
|
|
5
|
-
context?: oPlanContext;
|
|
6
|
-
sequence?: any[];
|
|
7
|
-
streamTo?: oAddress;
|
|
8
|
-
currentNode: oCoreNode;
|
|
9
|
-
caller: oAddress;
|
|
10
|
-
receiver?: oAddress;
|
|
11
|
-
promptFunction?: (intent: string, context: string, agentHistory: string, extraInstructions: string) => string;
|
|
12
|
-
extraInstructions?: string;
|
|
13
|
-
parentId?: string;
|
|
14
|
-
shouldContinue?: () => boolean;
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=plan-config.interface.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plan-config.interface.d.ts","sourceRoot":"","sources":["../../../../src/plan/interfaces/plan-config.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,WAAW,WAAW;IAE1B,MAAM,EAAE,MAAM,CAAC;IAEf,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC;IAEjB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAGpB,WAAW,EAAE,SAAS,CAAC;IACvB,MAAM,EAAE,QAAQ,CAAC;IACjB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,cAAc,CAAC,EAAE,CACf,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,iBAAiB,EAAE,MAAM,KACtB,MAAM,CAAC;IACZ,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC;CAChC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plan-result.interface.d.ts","sourceRoot":"","sources":["../../../../src/plan/interfaces/plan-result.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEzD,MAAM,WAAW,mBAAmB;IAClC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plan-type.enum.d.ts","sourceRoot":"","sources":["../../../../src/plan/interfaces/plan-type.enum.ts"],"names":[],"mappings":"AAAA,oBAAY,SAAS;IACnB,QAAQ,aAAa;IACrB,MAAM,WAAW;IACjB,SAAS,cAAc;IACvB,GAAG,QAAQ;IACX,KAAK,UAAU;CAChB"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { oQueryConfig } from './query.config.js';
|
|
2
|
-
import { oTaskConfig } from './task.config.js';
|
|
3
|
-
import { oConfigureResult } from './configure.result.js';
|
|
4
|
-
export interface oPlanResult {
|
|
5
|
-
intents?: string[];
|
|
6
|
-
queries?: oQueryConfig[];
|
|
7
|
-
tasks?: oTaskConfig[];
|
|
8
|
-
handshake?: oTaskConfig;
|
|
9
|
-
result?: any;
|
|
10
|
-
reasoning?: string;
|
|
11
|
-
error?: any;
|
|
12
|
-
configure?: oConfigureResult;
|
|
13
|
-
type: 'result' | 'task' | 'search' | 'multiple_step' | 'error' | 'handshake' | 'configure';
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=plan.result.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plan.result.d.ts","sourceRoot":"","sources":["../../../../src/plan/interfaces/plan.result.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;IACzB,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;IACtB,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,IAAI,EACA,QAAQ,GACR,MAAM,GACN,QAAQ,GACR,eAAe,GACf,OAAO,GACP,WAAW,GACX,WAAW,CAAC;CACjB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"query.config.d.ts","sourceRoot":"","sources":["../../../../src/plan/interfaces/query.config.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,UAAU,GAAG,UAAU,CAAC;CACnC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"task.config.d.ts","sourceRoot":"","sources":["../../../../src/plan/interfaces/task.config.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE;QACP,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE;YAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;SAAE,CAAC;KAChC,CAAC;CACH"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { Logger, oAddress } from '../core/index.js';
|
|
2
|
-
import { oPlanConfig } from './interfaces/plan-config.interface.js';
|
|
3
|
-
import { CID } from 'multiformats';
|
|
4
|
-
import { oPlanResult } from './interfaces/plan.result.js';
|
|
5
|
-
export declare class oPlan {
|
|
6
|
-
protected readonly config: oPlanConfig;
|
|
7
|
-
protected logger: Logger;
|
|
8
|
-
sequence: oPlan[];
|
|
9
|
-
cid: CID | undefined;
|
|
10
|
-
id: string;
|
|
11
|
-
parentId: string | undefined;
|
|
12
|
-
result: oPlanResult | undefined;
|
|
13
|
-
constructor(config: oPlanConfig);
|
|
14
|
-
get caller(): oAddress;
|
|
15
|
-
get receiver(): oAddress | undefined;
|
|
16
|
-
get node(): import("../core/core.node.js").oCoreNode;
|
|
17
|
-
toCIDInput(): any;
|
|
18
|
-
type(): string;
|
|
19
|
-
toJSON(): {
|
|
20
|
-
config: any;
|
|
21
|
-
sequence: string[];
|
|
22
|
-
result: oPlanResult | undefined;
|
|
23
|
-
};
|
|
24
|
-
addSequencePlan(plan: oPlan): void;
|
|
25
|
-
toCID(): Promise<CID>;
|
|
26
|
-
storePlan(): Promise<void>;
|
|
27
|
-
get agentHistory(): string;
|
|
28
|
-
searchPlans(): Promise<any>;
|
|
29
|
-
preflight(): Promise<void>;
|
|
30
|
-
run(): Promise<oPlanResult>;
|
|
31
|
-
execute(): Promise<oPlanResult>;
|
|
32
|
-
handleNetworkChanges(): Promise<void>;
|
|
33
|
-
addReasoning(): Promise<void>;
|
|
34
|
-
postflight(response: oPlanResult): Promise<oPlanResult>;
|
|
35
|
-
}
|
|
36
|
-
//# sourceMappingURL=o-plan.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"o-plan.d.ts","sourceRoot":"","sources":["../../../src/plan/o-plan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACpE,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAInC,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAK1D,qBAAa,KAAK;IASJ,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,WAAW;IARlD,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,KAAK,EAAE,CAAM;IACvB,GAAG,EAAE,GAAG,GAAG,SAAS,CAAC;IACrB,EAAE,EAAE,MAAM,CAAY;IACtB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAE7B,MAAM,EAAE,WAAW,GAAG,SAAS,CAAC;gBAER,MAAM,EAAE,WAAW;IAMlD,IAAI,MAAM,aAET;IAED,IAAI,QAAQ,yBAEX;IAED,IAAI,IAAI,6CAEP;IAED,UAAU,IAAI,GAAG;IAQjB,IAAI;IAIJ,MAAM;;;;;IAQN,eAAe,CAAC,IAAI,EAAE,KAAK;IAyBrB,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC;IAUrB,SAAS;IAef,IAAI,YAAY,WA0Bf;IAEK,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC;IAmB3B,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAK1B,GAAG,IAAI,OAAO,CAAC,WAAW,CAAC;IAyC3B,OAAO,IAAI,OAAO,CAAC,WAAW,CAAC;IAQ/B,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;IAUrC,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAoB7B,UAAU,CAAC,QAAQ,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;CAc9D"}
|
package/dist/src/plan/o-plan.js
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
import { Logger, oAddress } from '../core/index.js';
|
|
2
|
-
import { CID } from 'multiformats';
|
|
3
|
-
import * as json from 'multiformats/codecs/json';
|
|
4
|
-
import { sha256 } from 'multiformats/hashes/sha2';
|
|
5
|
-
import { AGENT_PROMPT } from './prompts/agent.prompt.js';
|
|
6
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
7
|
-
import { RegexUtils } from '../utils/index.js';
|
|
8
|
-
export class oPlan {
|
|
9
|
-
constructor(config) {
|
|
10
|
-
this.config = config;
|
|
11
|
-
this.sequence = [];
|
|
12
|
-
this.id = uuidv4();
|
|
13
|
-
this.logger = new Logger('oPlan:' + `[${this.config.intent}]`);
|
|
14
|
-
this.sequence = Object.assign([], this.config.sequence || []);
|
|
15
|
-
this.parentId = this.config.parentId;
|
|
16
|
-
}
|
|
17
|
-
get caller() {
|
|
18
|
-
return this.config.caller;
|
|
19
|
-
}
|
|
20
|
-
get receiver() {
|
|
21
|
-
return this.config.receiver;
|
|
22
|
-
}
|
|
23
|
-
get node() {
|
|
24
|
-
return this.config.currentNode;
|
|
25
|
-
}
|
|
26
|
-
toCIDInput() {
|
|
27
|
-
return {
|
|
28
|
-
intent: this.config.intent,
|
|
29
|
-
address: this.config.caller?.toString(),
|
|
30
|
-
context: this.config.context?.toString() || '',
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
type() {
|
|
34
|
-
return 'unknown';
|
|
35
|
-
}
|
|
36
|
-
toJSON() {
|
|
37
|
-
return {
|
|
38
|
-
config: this.toCIDInput(),
|
|
39
|
-
sequence: this.sequence.map((s) => `o://plan/${s.cid?.toString()}`),
|
|
40
|
-
result: this.result,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
addSequencePlan(plan) {
|
|
44
|
-
this.sequence.push(plan);
|
|
45
|
-
if (this.config.streamTo) {
|
|
46
|
-
this.node
|
|
47
|
-
.use(this.config.streamTo, {
|
|
48
|
-
method: 'receive_stream',
|
|
49
|
-
params: {
|
|
50
|
-
data: plan.result || '',
|
|
51
|
-
},
|
|
52
|
-
})
|
|
53
|
-
.catch((error) => {
|
|
54
|
-
this.logger.error('Error sending agent stream: ', error);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
// console.log(
|
|
58
|
-
// `${this.parentId ? '--[Child ' : '['}Cycle ${this.sequence.length} - ${this.id}]\n ${JSON.stringify(
|
|
59
|
-
// {
|
|
60
|
-
// ...plan.result,
|
|
61
|
-
// },
|
|
62
|
-
// null,
|
|
63
|
-
// 2,
|
|
64
|
-
// )}\n${this.parentId ? '--[Child ' : '['}Cycle ${this.sequence.length} - ${this.id}]`,
|
|
65
|
-
// );
|
|
66
|
-
}
|
|
67
|
-
async toCID() {
|
|
68
|
-
if (this.cid) {
|
|
69
|
-
return this.cid;
|
|
70
|
-
}
|
|
71
|
-
const bytes = json.encode(this.toCIDInput());
|
|
72
|
-
const hash = await sha256.digest(bytes);
|
|
73
|
-
const cid = CID.create(1, json.code, hash);
|
|
74
|
-
return cid;
|
|
75
|
-
}
|
|
76
|
-
async storePlan() {
|
|
77
|
-
this.logger.debug('Storing plan...');
|
|
78
|
-
const cid = await this.toCID();
|
|
79
|
-
const params = {
|
|
80
|
-
key: cid.toString(),
|
|
81
|
-
value: JSON.stringify(this.toJSON()),
|
|
82
|
-
};
|
|
83
|
-
this.logger.debug('Storing plan params: ', params);
|
|
84
|
-
await this.node.use(new oAddress('o://plan'), {
|
|
85
|
-
method: 'put',
|
|
86
|
-
params: params,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
get agentHistory() {
|
|
90
|
-
const added = {};
|
|
91
|
-
return (this.sequence
|
|
92
|
-
?.filter((s) => {
|
|
93
|
-
if (added[s.id]) {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
added[s.id] = true;
|
|
97
|
-
return true;
|
|
98
|
-
})
|
|
99
|
-
?.map((s, index) => `[Cycle ${index + 1} Begin ${s.id}]\n
|
|
100
|
-
Cycle Intent: ${s.config.intent}\n
|
|
101
|
-
Cycle Result:\n
|
|
102
|
-
${JSON.stringify({
|
|
103
|
-
...s.result,
|
|
104
|
-
}, null, 2)} \n[Cycle ${index + 1} End ${s.id}]`)
|
|
105
|
-
.join('\n') || '');
|
|
106
|
-
}
|
|
107
|
-
async searchPlans() {
|
|
108
|
-
this.logger.debug('Searching for plans...');
|
|
109
|
-
const cid = await this.toCID();
|
|
110
|
-
const response = await this.node.use(new oAddress('o://plan'), {
|
|
111
|
-
method: 'get',
|
|
112
|
-
params: {
|
|
113
|
-
key: cid.toString(),
|
|
114
|
-
},
|
|
115
|
-
});
|
|
116
|
-
this.logger.debug('Search plans response: ', response);
|
|
117
|
-
const result = response.result;
|
|
118
|
-
const json = typeof result.data === 'string'
|
|
119
|
-
? JSON.parse(result.data)
|
|
120
|
-
: result.data;
|
|
121
|
-
return json;
|
|
122
|
-
}
|
|
123
|
-
async preflight() {
|
|
124
|
-
this.logger.debug('Preflight...');
|
|
125
|
-
this.cid = await this.toCID();
|
|
126
|
-
}
|
|
127
|
-
async run() {
|
|
128
|
-
this.logger.debug('Running plan...');
|
|
129
|
-
const ctxt = this.config.context?.toString() || '';
|
|
130
|
-
let prompt = null;
|
|
131
|
-
if (this.config.promptFunction) {
|
|
132
|
-
this.logger.debug('Using prompt function: ', this.config.promptFunction);
|
|
133
|
-
prompt = this.config.promptFunction(this.config.intent, ctxt, this.agentHistory, this.config.extraInstructions || '');
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
prompt = AGENT_PROMPT(this.config.intent, ctxt, this.agentHistory, this.config.extraInstructions || '');
|
|
137
|
-
}
|
|
138
|
-
// this.logger.debug('Prompt: ', prompt);
|
|
139
|
-
const response = await this.node.use(new oAddress('o://intelligence'), {
|
|
140
|
-
method: 'prompt',
|
|
141
|
-
params: {
|
|
142
|
-
prompt: prompt,
|
|
143
|
-
response_format: 'json_object',
|
|
144
|
-
},
|
|
145
|
-
});
|
|
146
|
-
const data = response.result.data;
|
|
147
|
-
this.logger.debug('Plan response: ', data);
|
|
148
|
-
const message = data.message;
|
|
149
|
-
if (!message) {
|
|
150
|
-
throw new Error('No message returned from intelligence');
|
|
151
|
-
}
|
|
152
|
-
const planResult = RegexUtils.extractResultFromAI(message);
|
|
153
|
-
return planResult;
|
|
154
|
-
}
|
|
155
|
-
async execute() {
|
|
156
|
-
this.logger.debug('Executing...');
|
|
157
|
-
await this.preflight();
|
|
158
|
-
this.result = await this.run();
|
|
159
|
-
return this.postflight(this.result);
|
|
160
|
-
}
|
|
161
|
-
async handleNetworkChanges() {
|
|
162
|
-
const cid = await this.toCID();
|
|
163
|
-
await this.node.use(new oAddress('o://leader'), {
|
|
164
|
-
method: 'save_plan',
|
|
165
|
-
params: {
|
|
166
|
-
plan: `o://plan/${cid}`,
|
|
167
|
-
},
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
async addReasoning() {
|
|
171
|
-
// if (this.result?.reasoning) {
|
|
172
|
-
// this.logger.debug('Adding knowledge: ', this.result?.reasoning);
|
|
173
|
-
// await this.node.use(new oAddress('o://vector-store'), {
|
|
174
|
-
// method: 'add_documents',
|
|
175
|
-
// params: {
|
|
176
|
-
// documents: [
|
|
177
|
-
// {
|
|
178
|
-
// pageContent: this.result?.reasoning,
|
|
179
|
-
// metadata: {
|
|
180
|
-
// address: this.caller?.toString(),
|
|
181
|
-
// id: uuidv4(),
|
|
182
|
-
// },
|
|
183
|
-
// },
|
|
184
|
-
// ],
|
|
185
|
-
// },
|
|
186
|
-
// });
|
|
187
|
-
// }
|
|
188
|
-
}
|
|
189
|
-
async postflight(response) {
|
|
190
|
-
this.logger.debug('Postflight...');
|
|
191
|
-
try {
|
|
192
|
-
await this.storePlan();
|
|
193
|
-
this.logger.debug('Saving plan...', response);
|
|
194
|
-
// TODO: handle network changes
|
|
195
|
-
await this.addReasoning();
|
|
196
|
-
}
|
|
197
|
-
catch (error) {
|
|
198
|
-
this.logger.error('Error in postflight: ', error);
|
|
199
|
-
}
|
|
200
|
-
return response;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plan.context.d.ts","sourceRoot":"","sources":["../../../src/plan/plan.context.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAY;IACvB,OAAO,CAAC,OAAO,CAAgB;gBACnB,OAAO,EAAE,GAAG;IAIxB,GAAG,CAAC,KAAK,EAAE,MAAM;IAIjB,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE;IAUzB,KAAK;IAIL,MAAM;IAIN,QAAQ;CAGT"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export class oPlanContext {
|
|
2
|
-
constructor(context) {
|
|
3
|
-
this.context = [];
|
|
4
|
-
this.context = context;
|
|
5
|
-
}
|
|
6
|
-
add(value) {
|
|
7
|
-
this.context.push(value);
|
|
8
|
-
}
|
|
9
|
-
addAll(contexts) {
|
|
10
|
-
try {
|
|
11
|
-
for (const context of contexts) {
|
|
12
|
-
this.context.push(context);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
catch (e) {
|
|
16
|
-
console.error('Error adding contexts: ', e);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
clear() {
|
|
20
|
-
this.context = [];
|
|
21
|
-
}
|
|
22
|
-
toJSON() {
|
|
23
|
-
return this.context;
|
|
24
|
-
}
|
|
25
|
-
toString() {
|
|
26
|
-
return '\n\n' + this.context.join('\n') + '\n\n';
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"agent.prompt.d.ts","sourceRoot":"","sources":["../../../../src/plan/prompts/agent.prompt.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY,GACvB,QAAQ,MAAM,EACd,SAAS,MAAM,EACf,cAAc,MAAM,EACpB,mBAAmB,MAAM,WAuHxB,CAAC"}
|