@olane/o-lane 0.7.18 → 0.7.19
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/src/capabilities/enums/o-capability.type-enum.d.ts +1 -0
- package/dist/src/capabilities/enums/o-capability.type-enum.d.ts.map +1 -1
- package/dist/src/capabilities/enums/o-capability.type-enum.js +1 -0
- package/dist/src/capabilities/index.d.ts +2 -1
- package/dist/src/capabilities/index.d.ts.map +1 -1
- package/dist/src/capabilities/index.js +2 -1
- package/dist/src/capabilities/interfaces/{o-capability.config.d.ts → o-capability.config-interface.d.ts} +5 -4
- package/dist/src/capabilities/interfaces/o-capability.config-interface.d.ts.map +1 -0
- package/dist/src/capabilities/interfaces/o-capability.result-interface.d.ts +1 -2
- package/dist/src/capabilities/interfaces/o-capability.result-interface.d.ts.map +1 -1
- package/dist/src/capabilities/o-capability.config.d.ts +24 -0
- package/dist/src/capabilities/o-capability.config.d.ts.map +1 -0
- package/dist/src/capabilities/o-capability.config.js +25 -0
- package/dist/src/capabilities/o-capability.d.ts +9 -5
- package/dist/src/capabilities/o-capability.d.ts.map +1 -1
- package/dist/src/capabilities/o-capability.intelligence.d.ts.map +1 -1
- package/dist/src/capabilities/o-capability.intelligence.js +4 -18
- package/dist/src/capabilities/o-capability.js +4 -5
- package/dist/src/capabilities/o-capability.result.d.ts +6 -12
- package/dist/src/capabilities/o-capability.result.d.ts.map +1 -1
- package/dist/src/capabilities/o-capability.result.js +2 -10
- package/dist/src/capabilities-all/o-capability.all.d.ts +2 -3
- package/dist/src/capabilities-all/o-capability.all.d.ts.map +1 -1
- package/dist/src/capabilities-all/o-capability.all.js +6 -8
- package/dist/src/capabilities-configure/interfaces/o-capability.configure-config.d.ts +2 -2
- package/dist/src/capabilities-configure/interfaces/o-capability.configure-config.d.ts.map +1 -1
- package/dist/src/capabilities-configure/o-capability.configure.d.ts +0 -15
- package/dist/src/capabilities-configure/o-capability.configure.d.ts.map +1 -1
- package/dist/src/capabilities-configure/o-capability.configure.js +61 -47
- package/dist/src/capabilities-evaluate/o-capability.evaluate.d.ts +1 -0
- package/dist/src/capabilities-evaluate/o-capability.evaluate.d.ts.map +1 -1
- package/dist/src/capabilities-evaluate/o-capability.evaluate.js +17 -2
- package/dist/src/capabilities-execute/execute.capability.d.ts +13 -0
- package/dist/src/capabilities-execute/execute.capability.d.ts.map +1 -0
- package/dist/src/capabilities-execute/execute.capability.js +111 -0
- package/dist/src/capabilities-execute/interfaces/o-capability.configure-config.d.ts +8 -0
- package/dist/src/capabilities-execute/interfaces/o-capability.configure-config.d.ts.map +1 -0
- package/dist/src/capabilities-multiple-step/interfaces/o-capability.multiple-step-config.d.ts +1 -1
- package/dist/src/capabilities-multiple-step/interfaces/o-capability.multiple-step-config.d.ts.map +1 -1
- package/dist/src/capabilities-multiple-step/o-capability.multiple-step.d.ts.map +1 -1
- package/dist/src/capabilities-multiple-step/o-capability.multiple-step.js +0 -1
- package/dist/src/capabilities-search/interfaces/o-capability.search-config.d.ts +1 -1
- package/dist/src/capabilities-search/interfaces/o-capability.search-config.d.ts.map +1 -1
- package/dist/src/capabilities-search/o-capability.search.d.ts.map +1 -1
- package/dist/src/capabilities-search/o-capability.search.js +0 -4
- package/dist/src/index.d.ts +1 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -2
- package/dist/src/interfaces/o-lane.config.d.ts +3 -0
- package/dist/src/interfaces/o-lane.config.d.ts.map +1 -1
- package/dist/src/o-lane.d.ts +6 -12
- package/dist/src/o-lane.d.ts.map +1 -1
- package/dist/src/o-lane.js +23 -180
- package/dist/src/o-lane.mixin.d.ts.map +1 -1
- package/dist/src/o-lane.mixin.js +9 -5
- package/dist/src/prompts/agent.prompt.d.ts +1 -12
- package/dist/src/prompts/agent.prompt.d.ts.map +1 -1
- package/dist/src/prompts/agent.prompt.js +80 -138
- package/dist/src/prompts/configure.prompt.d.ts +1 -8
- package/dist/src/prompts/configure.prompt.d.ts.map +1 -1
- package/dist/src/prompts/configure.prompt.js +68 -47
- package/dist/src/prompts/execute.prompt.d.ts +9 -0
- package/dist/src/prompts/execute.prompt.d.ts.map +1 -0
- package/dist/src/prompts/execute.prompt.js +47 -0
- package/dist/src/prompts/index.d.ts +3 -0
- package/dist/src/prompts/index.d.ts.map +1 -0
- package/dist/src/prompts/index.js +2 -0
- package/dist/src/prompts/interfaces/o-prompt.config.d.ts +8 -0
- package/dist/src/prompts/interfaces/o-prompt.config.d.ts.map +1 -0
- package/dist/src/prompts/interfaces/o-prompt.config.js +1 -0
- package/dist/src/prompts/o-prompt.d.ts +36 -0
- package/dist/src/prompts/o-prompt.d.ts.map +1 -0
- package/dist/src/prompts/o-prompt.js +92 -0
- package/dist/src/storage/default.prompt-loader.d.ts +14 -0
- package/dist/src/storage/default.prompt-loader.d.ts.map +1 -0
- package/dist/src/storage/default.prompt-loader.js +34 -0
- package/dist/src/storage/index.d.ts +1 -3
- package/dist/src/storage/index.d.ts.map +1 -1
- package/dist/src/storage/index.js +1 -5
- package/dist/src/storage/o-lane.storage-manager.d.ts +71 -0
- package/dist/src/storage/o-lane.storage-manager.d.ts.map +1 -0
- package/dist/src/storage/o-lane.storage-manager.js +208 -0
- package/dist/src/storage/prompt-loader.d.ts +10 -28
- package/dist/src/storage/prompt-loader.d.ts.map +1 -1
- package/dist/src/storage/prompt-loader.js +9 -112
- package/dist/test/index.d.ts +1 -0
- package/dist/test/index.d.ts.map +1 -0
- package/dist/test/index.js +2 -0
- package/package.json +12 -10
- package/dist/src/capabilities/interfaces/o-capability.config.d.ts.map +0 -1
- package/dist/src/capabilities-task/interfaces/o-capability.task-config.d.ts +0 -16
- package/dist/src/capabilities-task/interfaces/o-capability.task-config.d.ts.map +0 -1
- package/dist/src/capabilities-task/o-capability.task-result.d.ts +0 -5
- package/dist/src/capabilities-task/o-capability.task-result.d.ts.map +0 -1
- package/dist/src/capabilities-task/o-capability.task-result.js +0 -3
- package/dist/src/capabilities-task/o-capability.task.d.ts +0 -20
- package/dist/src/capabilities-task/o-capability.task.d.ts.map +0 -1
- package/dist/src/capabilities-task/o-capability.task.js +0 -124
- package/dist/src/storage/prompt-schema.d.ts +0 -42
- package/dist/src/storage/prompt-schema.d.ts.map +0 -1
- package/dist/src/storage/prompt-schema.js +0 -29
- package/dist/src/storage/prompt-seeder.d.ts +0 -42
- package/dist/src/storage/prompt-seeder.d.ts.map +0 -1
- package/dist/src/storage/prompt-seeder.js +0 -141
- package/dist/src/storage/prompt-storage-provider.tool.d.ts +0 -99
- package/dist/src/storage/prompt-storage-provider.tool.d.ts.map +0 -1
- package/dist/src/storage/prompt-storage-provider.tool.js +0 -320
- package/dist/test/prompt-seeder.spec.d.ts +0 -2
- package/dist/test/prompt-seeder.spec.d.ts.map +0 -1
- package/dist/test/prompt-seeder.spec.js +0 -256
- package/dist/test/prompt-storage-provider.spec.d.ts +0 -2
- package/dist/test/prompt-storage-provider.spec.d.ts.map +0 -1
- package/dist/test/prompt-storage-provider.spec.js +0 -457
- /package/dist/src/capabilities/interfaces/{o-capability.config.js → o-capability.config-interface.js} +0 -0
- /package/dist/src/{capabilities-task/interfaces/o-capability.task-config.js → capabilities-execute/interfaces/o-capability.configure-config.js} +0 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { oObject } from "@olane/o-core";
|
|
2
|
+
import Handlebars from "handlebars";
|
|
3
|
+
export class oPrompt extends oObject {
|
|
4
|
+
constructor(config) {
|
|
5
|
+
super();
|
|
6
|
+
if (!config.rawValue) {
|
|
7
|
+
throw new Error('rawValue is required in oPromptConfig');
|
|
8
|
+
}
|
|
9
|
+
this.rawValue = config.rawValue;
|
|
10
|
+
this.type = config.type;
|
|
11
|
+
this.provider = config.provider;
|
|
12
|
+
this.params = config.params || {};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Extracts all template variables from the rawValue template
|
|
16
|
+
* @returns Array of variable names found in the template
|
|
17
|
+
*/
|
|
18
|
+
getRequiredVariables() {
|
|
19
|
+
// Match handlebars variables: {{variable}} or {{object.property}}
|
|
20
|
+
const regex = /\{\{([^}]+)\}\}/g;
|
|
21
|
+
const matches = this.rawValue.matchAll(regex);
|
|
22
|
+
const variables = new Set();
|
|
23
|
+
for (const match of matches) {
|
|
24
|
+
// Extract the variable name (before any dots for nested properties)
|
|
25
|
+
const fullPath = match[1].trim();
|
|
26
|
+
const rootVariable = fullPath.split('.')[0];
|
|
27
|
+
variables.add(rootVariable);
|
|
28
|
+
}
|
|
29
|
+
return Array.from(variables);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Validates that all required template variables are present in params
|
|
33
|
+
* @throws Error if any required variables are missing
|
|
34
|
+
*/
|
|
35
|
+
validate() {
|
|
36
|
+
const requiredVariables = this.getRequiredVariables();
|
|
37
|
+
const providedKeys = Object.keys(this.params);
|
|
38
|
+
const missingVariables = requiredVariables.filter((variable) => !providedKeys.includes(variable));
|
|
39
|
+
if (missingVariables.length > 0) {
|
|
40
|
+
throw new Error(`Missing required template variables: ${missingVariables.join(', ')}. ` +
|
|
41
|
+
`Required: [${requiredVariables.join(', ')}], ` +
|
|
42
|
+
`Provided: [${providedKeys.join(', ')}]`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Compiles the template with provided params
|
|
47
|
+
* @returns The compiled template string
|
|
48
|
+
* @throws Error if template variables are missing or compilation fails
|
|
49
|
+
*/
|
|
50
|
+
compile() {
|
|
51
|
+
// Validate first to provide clear error messages
|
|
52
|
+
this.validate();
|
|
53
|
+
try {
|
|
54
|
+
// Compile template if not already compiled
|
|
55
|
+
if (!this.compiledTemplate) {
|
|
56
|
+
this.compiledTemplate = Handlebars.compile(this.rawValue, {
|
|
57
|
+
strict: true,
|
|
58
|
+
noEscape: true, // Don't HTML-escape variables
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
// Render the template with params
|
|
62
|
+
const result = this.compiledTemplate(this.params);
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
if (error instanceof Error) {
|
|
67
|
+
throw new Error(`Failed to compile template: ${error.message}. ` +
|
|
68
|
+
`Template type: ${this.type}, Provider: ${this.provider}`);
|
|
69
|
+
}
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Alias for compile() for clearer semantics
|
|
75
|
+
*/
|
|
76
|
+
render() {
|
|
77
|
+
return this.compile();
|
|
78
|
+
}
|
|
79
|
+
// Getters for config properties
|
|
80
|
+
getRawValue() {
|
|
81
|
+
return this.rawValue;
|
|
82
|
+
}
|
|
83
|
+
getType() {
|
|
84
|
+
return this.type;
|
|
85
|
+
}
|
|
86
|
+
getProvider() {
|
|
87
|
+
return this.provider;
|
|
88
|
+
}
|
|
89
|
+
getParams() {
|
|
90
|
+
return this.params;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { oCapabilityType } from "../capabilities/enums/o-capability.type-enum.js";
|
|
2
|
+
import { PromptLoader } from "./prompt-loader.js";
|
|
3
|
+
import { oPrompt } from "../prompts/o-prompt.js";
|
|
4
|
+
export declare class PromptLoaderDefault extends PromptLoader {
|
|
5
|
+
/**
|
|
6
|
+
* Load a prompt for the given capability type
|
|
7
|
+
* @param type The capability type
|
|
8
|
+
* @param params Parameters to populate the template
|
|
9
|
+
* @param provider Provider identifier (defaults to 'default')
|
|
10
|
+
* @returns oPrompt instance
|
|
11
|
+
*/
|
|
12
|
+
loadPromptForType(type: oCapabilityType, params?: any, provider?: string): Promise<oPrompt>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=default.prompt-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default.prompt-loader.d.ts","sourceRoot":"","sources":["../../../src/storage/default.prompt-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iDAAiD,CAAC;AAGlF,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEjD,qBAAa,mBAAoB,SAAQ,YAAY;IAEnD;;;;;;OAMG;IACG,iBAAiB,CACrB,IAAI,EAAE,eAAe,EACrB,MAAM,GAAE,GAAQ,EAChB,QAAQ,GAAE,MAAkB,GAC3B,OAAO,CAAC,OAAO,CAAC;CAqBpB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { oCapabilityType } from "../capabilities/enums/o-capability.type-enum.js";
|
|
2
|
+
import { AGENT_PROMPT_TEMPLATE } from "../prompts/agent.prompt.js";
|
|
3
|
+
import { CONFIGURE_PROMPT_TEMPLATE } from "../prompts/configure.prompt.js";
|
|
4
|
+
import { PromptLoader } from "./prompt-loader.js";
|
|
5
|
+
import { oPrompt } from "../prompts/o-prompt.js";
|
|
6
|
+
export class PromptLoaderDefault extends PromptLoader {
|
|
7
|
+
/**
|
|
8
|
+
* Load a prompt for the given capability type
|
|
9
|
+
* @param type The capability type
|
|
10
|
+
* @param params Parameters to populate the template
|
|
11
|
+
* @param provider Provider identifier (defaults to 'default')
|
|
12
|
+
* @returns oPrompt instance
|
|
13
|
+
*/
|
|
14
|
+
async loadPromptForType(type, params = {}, provider = 'default') {
|
|
15
|
+
// Get the raw template
|
|
16
|
+
let rawValue;
|
|
17
|
+
if (type === oCapabilityType.CONFIGURE) {
|
|
18
|
+
rawValue = CONFIGURE_PROMPT_TEMPLATE;
|
|
19
|
+
}
|
|
20
|
+
else if (type === oCapabilityType.EVALUATE) {
|
|
21
|
+
rawValue = AGENT_PROMPT_TEMPLATE;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
throw new Error(`Unsupported template type: ${type}`);
|
|
25
|
+
}
|
|
26
|
+
// Create and return oPrompt instance
|
|
27
|
+
return new oPrompt({
|
|
28
|
+
rawValue,
|
|
29
|
+
type,
|
|
30
|
+
provider,
|
|
31
|
+
params,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
export * from './prompt-storage-provider.tool.js';
|
|
2
1
|
export * from './interfaces/prompt-storage.interface.js';
|
|
3
2
|
export * from './methods/prompt-storage.methods.js';
|
|
4
|
-
export * from './prompt-schema.js';
|
|
5
|
-
export * from './prompt-seeder.js';
|
|
6
3
|
export * from './prompt-loader.js';
|
|
7
4
|
export * from './o-lane.storage.js';
|
|
5
|
+
export * from './o-lane.storage-manager.js';
|
|
8
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/index.ts"],"names":[],"mappings":"AACA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/index.ts"],"names":[],"mappings":"AACA,cAAc,0CAA0C,CAAC;AAGzD,cAAc,qCAAqC,CAAC;AAEpD,cAAc,oBAAoB,CAAC;AAGnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC"}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
// Prompt Storage Provider
|
|
2
|
-
export * from './prompt-storage-provider.tool.js';
|
|
3
1
|
// Interfaces
|
|
4
2
|
export * from './interfaces/prompt-storage.interface.js';
|
|
5
3
|
// Methods
|
|
6
4
|
export * from './methods/prompt-storage.methods.js';
|
|
7
|
-
// Prompt Management
|
|
8
|
-
export * from './prompt-schema.js';
|
|
9
|
-
export * from './prompt-seeder.js';
|
|
10
5
|
export * from './prompt-loader.js';
|
|
11
6
|
// Existing storage
|
|
12
7
|
export * from './o-lane.storage.js';
|
|
8
|
+
export * from './o-lane.storage-manager.js';
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* oLaneStorageManager
|
|
3
|
+
*
|
|
4
|
+
* Handles all storage operations for oLane instances including:
|
|
5
|
+
* - CID generation and caching
|
|
6
|
+
* - Serialization
|
|
7
|
+
* - Persistence to storage
|
|
8
|
+
* - Replay from storage
|
|
9
|
+
* - Config persistence for startup
|
|
10
|
+
*/
|
|
11
|
+
import { CID } from 'multiformats';
|
|
12
|
+
import { oCapabilityResult, oCapabilityType } from '../capabilities/index.js';
|
|
13
|
+
type oLane = any;
|
|
14
|
+
export declare class oLaneStorageManager {
|
|
15
|
+
private cid;
|
|
16
|
+
private lane;
|
|
17
|
+
constructor(lane: oLane);
|
|
18
|
+
/**
|
|
19
|
+
* Generate the input object for CID creation
|
|
20
|
+
* @returns Object containing intent, address, and context
|
|
21
|
+
*/
|
|
22
|
+
generateCIDInput(): any;
|
|
23
|
+
/**
|
|
24
|
+
* Serialize the lane to JSON
|
|
25
|
+
* @returns Serialized lane object
|
|
26
|
+
*/
|
|
27
|
+
serialize(): any;
|
|
28
|
+
/**
|
|
29
|
+
* Generate or retrieve cached CID for this lane
|
|
30
|
+
* @returns Content Identifier (CID) for this lane
|
|
31
|
+
*/
|
|
32
|
+
generateCID(): Promise<CID>;
|
|
33
|
+
/**
|
|
34
|
+
* Store the lane to persistent storage
|
|
35
|
+
* @returns CID of the stored lane
|
|
36
|
+
* @throws Error if node is not in valid state
|
|
37
|
+
*/
|
|
38
|
+
save(): Promise<CID>;
|
|
39
|
+
/**
|
|
40
|
+
* Persist lane CID to config storage for startup replay
|
|
41
|
+
* @param cid Content Identifier of the lane
|
|
42
|
+
* @param response Capability result containing addresses to index
|
|
43
|
+
*/
|
|
44
|
+
persistToConfig(cid: CID, response?: oCapabilityResult): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Replay a stored lane from storage by CID
|
|
47
|
+
* This method loads a lane's execution sequence and replays it to restore network state
|
|
48
|
+
* @param cid Content Identifier of the stored lane
|
|
49
|
+
* @returns Final capability result from replay
|
|
50
|
+
*/
|
|
51
|
+
replay(cid: string): Promise<oCapabilityResult | undefined>;
|
|
52
|
+
/**
|
|
53
|
+
* Determine if a capability should be re-executed during replay
|
|
54
|
+
* Execute and Configure capabilities are re-executed as they modify network state
|
|
55
|
+
* Other capabilities use cached results
|
|
56
|
+
* @param capabilityType The type of capability to check
|
|
57
|
+
* @returns True if capability should be re-executed
|
|
58
|
+
*/
|
|
59
|
+
shouldReplayCapability(capabilityType: oCapabilityType): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Get the cached CID if available
|
|
62
|
+
* @returns Cached CID or undefined
|
|
63
|
+
*/
|
|
64
|
+
getCachedCID(): CID | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Clear the cached CID
|
|
67
|
+
*/
|
|
68
|
+
clearCache(): void;
|
|
69
|
+
}
|
|
70
|
+
export {};
|
|
71
|
+
//# sourceMappingURL=o-lane.storage-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"o-lane.storage-manager.d.ts","sourceRoot":"","sources":["../../../src/storage/o-lane.storage-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAGnC,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAqB,MAAM,0BAA0B,CAAC;AAGjG,KAAK,KAAK,GAAG,GAAG,CAAC;AAEjB,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,GAAG,CAAkB;IAC7B,OAAO,CAAC,IAAI,CAAQ;gBAER,IAAI,EAAE,KAAK;IAIvB;;;OAGG;IACH,gBAAgB,IAAI,GAAG;IAQvB;;;OAGG;IACH,SAAS,IAAI,GAAG;IAQhB;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC;IAWjC;;;;OAIG;IACG,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC;IAyB1B;;;;OAIG;IACG,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAwC5E;;;;;OAKG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC;IAoEjE;;;;;;OAMG;IACH,sBAAsB,CAAC,cAAc,EAAE,eAAe,GAAG,OAAO;IAShE;;;OAGG;IACH,YAAY,IAAI,GAAG,GAAG,SAAS;IAI/B;;OAEG;IACH,UAAU,IAAI,IAAI;CAGnB"}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* oLaneStorageManager
|
|
3
|
+
*
|
|
4
|
+
* Handles all storage operations for oLane instances including:
|
|
5
|
+
* - CID generation and caching
|
|
6
|
+
* - Serialization
|
|
7
|
+
* - Persistence to storage
|
|
8
|
+
* - Replay from storage
|
|
9
|
+
* - Config persistence for startup
|
|
10
|
+
*/
|
|
11
|
+
import { oAddress, oError, oErrorCodes, NodeState } from '@olane/o-core';
|
|
12
|
+
import { CID } from 'multiformats';
|
|
13
|
+
import * as json from 'multiformats/codecs/json';
|
|
14
|
+
import { sha256 } from 'multiformats/hashes/sha2';
|
|
15
|
+
import { oCapabilityResult, oCapabilityType } from '../capabilities/index.js';
|
|
16
|
+
export class oLaneStorageManager {
|
|
17
|
+
constructor(lane) {
|
|
18
|
+
this.lane = lane;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Generate the input object for CID creation
|
|
22
|
+
* @returns Object containing intent, address, and context
|
|
23
|
+
*/
|
|
24
|
+
generateCIDInput() {
|
|
25
|
+
return {
|
|
26
|
+
intent: this.lane.config.intent.toString(),
|
|
27
|
+
address: this.lane.config.caller?.toString(),
|
|
28
|
+
context: this.lane.config.context?.toString() || '',
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Serialize the lane to JSON
|
|
33
|
+
* @returns Serialized lane object
|
|
34
|
+
*/
|
|
35
|
+
serialize() {
|
|
36
|
+
return {
|
|
37
|
+
config: this.generateCIDInput(),
|
|
38
|
+
sequence: this.lane.sequence,
|
|
39
|
+
result: this.lane.result,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Generate or retrieve cached CID for this lane
|
|
44
|
+
* @returns Content Identifier (CID) for this lane
|
|
45
|
+
*/
|
|
46
|
+
async generateCID() {
|
|
47
|
+
if (this.cid) {
|
|
48
|
+
return this.cid;
|
|
49
|
+
}
|
|
50
|
+
const bytes = json.encode(this.generateCIDInput());
|
|
51
|
+
const hash = await sha256.digest(bytes);
|
|
52
|
+
const cid = CID.create(1, json.code, hash);
|
|
53
|
+
this.cid = cid;
|
|
54
|
+
return cid;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Store the lane to persistent storage
|
|
58
|
+
* @returns CID of the stored lane
|
|
59
|
+
* @throws Error if node is not in valid state
|
|
60
|
+
*/
|
|
61
|
+
async save() {
|
|
62
|
+
this.lane.logger.debug('Storing lane...');
|
|
63
|
+
const cid = await this.generateCID();
|
|
64
|
+
if (this.lane.node.state !== NodeState.RUNNING) {
|
|
65
|
+
throw new oError(oErrorCodes.INVALID_STATE, 'Node is not in a valid state to store a lane');
|
|
66
|
+
}
|
|
67
|
+
const params = {
|
|
68
|
+
key: cid.toString(),
|
|
69
|
+
value: JSON.stringify(this.serialize()),
|
|
70
|
+
};
|
|
71
|
+
this.lane.logger.debug('Storing lane params: ', params);
|
|
72
|
+
await this.lane.node.use(oAddress.lane(), {
|
|
73
|
+
method: 'put',
|
|
74
|
+
params: params,
|
|
75
|
+
});
|
|
76
|
+
return cid;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Persist lane CID to config storage for startup replay
|
|
80
|
+
* @param cid Content Identifier of the lane
|
|
81
|
+
* @param response Capability result containing addresses to index
|
|
82
|
+
*/
|
|
83
|
+
async persistToConfig(cid, response) {
|
|
84
|
+
this.lane.logger.debug('Lane marked for persistence (auto-triggered by tool response or explicitly set), saving to config...');
|
|
85
|
+
try {
|
|
86
|
+
// Get the OS instance name from the node's system name
|
|
87
|
+
const systemName = this.lane.node.config.systemName || 'default-os';
|
|
88
|
+
await this.lane.node.use(new oAddress('o://os-config'), {
|
|
89
|
+
method: 'add_lane_to_config',
|
|
90
|
+
params: {
|
|
91
|
+
osName: systemName,
|
|
92
|
+
cid: cid.toString(),
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
// Index any addresses returned in the response
|
|
96
|
+
const data = response?.result;
|
|
97
|
+
if (data?.addresses_to_index) {
|
|
98
|
+
for (const address of data.addresses_to_index) {
|
|
99
|
+
this.lane.logger.debug('Indexing address: ', address.toString());
|
|
100
|
+
await this.lane.node
|
|
101
|
+
.use(new oAddress(address), {
|
|
102
|
+
method: 'index_network',
|
|
103
|
+
params: {},
|
|
104
|
+
})
|
|
105
|
+
.catch((error) => {
|
|
106
|
+
this.lane.logger.error('Error indexing address: ', error);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
this.lane.logger.debug('Lane CID added to startup config via o://os-config');
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
this.lane.logger.error('Failed to add lane to startup config: ', error);
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Replay a stored lane from storage by CID
|
|
119
|
+
* This method loads a lane's execution sequence and replays it to restore network state
|
|
120
|
+
* @param cid Content Identifier of the stored lane
|
|
121
|
+
* @returns Final capability result from replay
|
|
122
|
+
*/
|
|
123
|
+
async replay(cid) {
|
|
124
|
+
this.lane.logger.debug('Replaying lane from CID: ', cid);
|
|
125
|
+
try {
|
|
126
|
+
// Load the lane data from storage
|
|
127
|
+
const laneData = await this.lane.node.use(oAddress.lane(), {
|
|
128
|
+
method: 'get',
|
|
129
|
+
params: { key: cid },
|
|
130
|
+
});
|
|
131
|
+
if (!laneData || !laneData.result) {
|
|
132
|
+
throw new Error(`Lane not found in storage for CID: ${cid}`);
|
|
133
|
+
}
|
|
134
|
+
const data = laneData.result.data;
|
|
135
|
+
const storedLane = JSON.parse(data.value);
|
|
136
|
+
// Validate stored lane structure
|
|
137
|
+
if (!storedLane.sequence || !Array.isArray(storedLane.sequence)) {
|
|
138
|
+
throw new Error('Invalid lane data: missing or invalid sequence');
|
|
139
|
+
}
|
|
140
|
+
// Iterate through the stored sequence and replay capabilities
|
|
141
|
+
for (const sequenceItem of storedLane.sequence) {
|
|
142
|
+
const capabilityType = sequenceItem.type;
|
|
143
|
+
// Determine if this capability should be replayed
|
|
144
|
+
if (this.shouldReplayCapability(capabilityType)) {
|
|
145
|
+
this.lane.logger.debug(`Replaying capability: ${capabilityType}`);
|
|
146
|
+
// Create a capability result with replay flag
|
|
147
|
+
const replayStep = new oCapabilityResult({
|
|
148
|
+
type: capabilityType,
|
|
149
|
+
config: {
|
|
150
|
+
...sequenceItem.config,
|
|
151
|
+
isReplay: true,
|
|
152
|
+
node: this.lane.node,
|
|
153
|
+
history: this.lane.agentHistory,
|
|
154
|
+
},
|
|
155
|
+
result: sequenceItem.result,
|
|
156
|
+
error: sequenceItem.error,
|
|
157
|
+
});
|
|
158
|
+
// Execute the capability in replay mode
|
|
159
|
+
const result = await this.lane.doCapability(replayStep);
|
|
160
|
+
this.lane.addSequence(result);
|
|
161
|
+
// If the capability is STOP, end replay
|
|
162
|
+
if (result.type === oCapabilityType.STOP) {
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
this.lane.logger.debug(`Skipping capability (using cached result): ${capabilityType}`);
|
|
168
|
+
// Add the cached result to sequence without re-executing
|
|
169
|
+
this.lane.addSequence(sequenceItem);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
this.lane.logger.debug('Lane replay completed successfully');
|
|
173
|
+
return this.lane.result;
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
this.lane.logger.error('Error during lane replay: ', error);
|
|
177
|
+
throw error;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Determine if a capability should be re-executed during replay
|
|
182
|
+
* Execute and Configure capabilities are re-executed as they modify network state
|
|
183
|
+
* Other capabilities use cached results
|
|
184
|
+
* @param capabilityType The type of capability to check
|
|
185
|
+
* @returns True if capability should be re-executed
|
|
186
|
+
*/
|
|
187
|
+
shouldReplayCapability(capabilityType) {
|
|
188
|
+
const replayTypes = [
|
|
189
|
+
oCapabilityType.EXECUTE,
|
|
190
|
+
oCapabilityType.CONFIGURE,
|
|
191
|
+
oCapabilityType.MULTIPLE_STEP,
|
|
192
|
+
];
|
|
193
|
+
return replayTypes.includes(capabilityType);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Get the cached CID if available
|
|
197
|
+
* @returns Cached CID or undefined
|
|
198
|
+
*/
|
|
199
|
+
getCachedCID() {
|
|
200
|
+
return this.cid;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Clear the cached CID
|
|
204
|
+
*/
|
|
205
|
+
clearCache() {
|
|
206
|
+
this.cid = undefined;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
@@ -3,38 +3,20 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Loads and compiles prompts from PromptStorageProvider with fallback to hardcoded versions
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { oCapabilityType } from '../capabilities/index.js';
|
|
7
|
+
import { oPrompt } from '../prompts/o-prompt.js';
|
|
7
8
|
/**
|
|
8
|
-
* Loads prompts from storage and
|
|
9
|
+
* Loads prompts from storage and returns oPrompt instances
|
|
9
10
|
*/
|
|
10
11
|
export declare class PromptLoader {
|
|
11
|
-
|
|
12
|
-
private cache;
|
|
13
|
-
private useStorage;
|
|
14
|
-
constructor(storage?: PromptStorageProvider | undefined);
|
|
12
|
+
protected cache: Map<oCapabilityType, oPrompt>;
|
|
15
13
|
/**
|
|
16
|
-
*
|
|
14
|
+
* Load a prompt template for a given capability type
|
|
15
|
+
* @param type The capability type
|
|
16
|
+
* @param params Optional parameters to populate the template
|
|
17
|
+
* @param provider Optional provider identifier
|
|
18
|
+
* @returns oPrompt instance ready for compilation
|
|
17
19
|
*/
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Generate custom agent prompt (equivalent to CUSTOM_AGENT_PROMPT function)
|
|
21
|
-
*/
|
|
22
|
-
generateCustomAgentPrompt(intent: string, context: string, agentHistory: string, cycleInstructions: string, outputInstructions: string, extraInstructions: string): Promise<string>;
|
|
23
|
-
/**
|
|
24
|
-
* Load configure instructions
|
|
25
|
-
*/
|
|
26
|
-
loadConfigureInstructions(): Promise<string>;
|
|
27
|
-
/**
|
|
28
|
-
* Load a template from storage
|
|
29
|
-
*/
|
|
30
|
-
private loadTemplate;
|
|
31
|
-
/**
|
|
32
|
-
* Clear the template cache
|
|
33
|
-
*/
|
|
34
|
-
clearCache(): void;
|
|
35
|
-
/**
|
|
36
|
-
* Enable or disable storage usage
|
|
37
|
-
*/
|
|
38
|
-
setUseStorage(use: boolean): void;
|
|
20
|
+
loadPromptForType(type: oCapabilityType, params?: any, provider?: string): Promise<oPrompt>;
|
|
39
21
|
}
|
|
40
22
|
//# sourceMappingURL=prompt-loader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-loader.d.ts","sourceRoot":"","sources":["../../../src/storage/prompt-loader.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"prompt-loader.d.ts","sourceRoot":"","sources":["../../../src/storage/prompt-loader.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEjD;;GAEG;AACH,qBAAa,YAAY;IACvB,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,eAAe,EAAE,OAAO,CAAC,CAAuC;IAErF;;;;;;OAMG;IACG,iBAAiB,CACrB,IAAI,EAAE,eAAe,EACrB,MAAM,CAAC,EAAE,GAAG,EACZ,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,OAAO,CAAC;CAIpB"}
|
|
@@ -3,124 +3,21 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Loads and compiles prompts from PromptStorageProvider with fallback to hardcoded versions
|
|
5
5
|
*/
|
|
6
|
-
import { PROMPT_KEYS, PROMPT_IDS, } from './prompt-schema.js';
|
|
7
|
-
import { AGENT_PROMPT } from '../prompts/agent.prompt.js';
|
|
8
|
-
import { CUSTOM_AGENT_PROMPT } from '../prompts/custom.prompt.js';
|
|
9
|
-
import { CONFIGURE_INSTRUCTIONS } from '../prompts/configure.prompt.js';
|
|
10
6
|
/**
|
|
11
|
-
* Loads prompts from storage and
|
|
7
|
+
* Loads prompts from storage and returns oPrompt instances
|
|
12
8
|
*/
|
|
13
9
|
export class PromptLoader {
|
|
14
|
-
constructor(
|
|
15
|
-
this.storage = storage;
|
|
10
|
+
constructor() {
|
|
16
11
|
this.cache = new Map();
|
|
17
|
-
this.useStorage = true;
|
|
18
|
-
if (!storage) {
|
|
19
|
-
this.useStorage = false;
|
|
20
|
-
}
|
|
21
12
|
}
|
|
22
13
|
/**
|
|
23
|
-
*
|
|
14
|
+
* Load a prompt template for a given capability type
|
|
15
|
+
* @param type The capability type
|
|
16
|
+
* @param params Optional parameters to populate the template
|
|
17
|
+
* @param provider Optional provider identifier
|
|
18
|
+
* @returns oPrompt instance ready for compilation
|
|
24
19
|
*/
|
|
25
|
-
async
|
|
26
|
-
|
|
27
|
-
// Fallback to hardcoded version
|
|
28
|
-
return AGENT_PROMPT(intent, context, agentHistory, extraInstructions);
|
|
29
|
-
}
|
|
30
|
-
try {
|
|
31
|
-
// Load templates from storage
|
|
32
|
-
const cycleInstructions = await this.loadTemplate(PROMPT_IDS.AGENT, PROMPT_KEYS.CYCLE_INSTRUCTIONS);
|
|
33
|
-
const outputInstructions = await this.loadTemplate(PROMPT_IDS.AGENT, PROMPT_KEYS.OUTPUT_INSTRUCTIONS);
|
|
34
|
-
// Compile using custom agent prompt
|
|
35
|
-
return await this.generateCustomAgentPrompt(intent, context, agentHistory, cycleInstructions, outputInstructions, extraInstructions);
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
// Fallback to hardcoded version on error
|
|
39
|
-
console.warn('Failed to load prompts from storage, using fallback', error);
|
|
40
|
-
return AGENT_PROMPT(intent, context, agentHistory, extraInstructions);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Generate custom agent prompt (equivalent to CUSTOM_AGENT_PROMPT function)
|
|
45
|
-
*/
|
|
46
|
-
async generateCustomAgentPrompt(intent, context, agentHistory, cycleInstructions, outputInstructions, extraInstructions) {
|
|
47
|
-
if (!this.useStorage || !this.storage) {
|
|
48
|
-
// Fallback to hardcoded version
|
|
49
|
-
return CUSTOM_AGENT_PROMPT(intent, context, agentHistory, cycleInstructions, outputInstructions, extraInstructions);
|
|
50
|
-
}
|
|
51
|
-
try {
|
|
52
|
-
// Load base template from storage
|
|
53
|
-
const baseTemplate = await this.loadTemplate(PROMPT_IDS.AGENT, PROMPT_KEYS.BASE_TEMPLATE);
|
|
54
|
-
// Replace placeholders with actual values
|
|
55
|
-
return baseTemplate
|
|
56
|
-
.replace('{{intent}}', intent)
|
|
57
|
-
.replace('{{context}}', context)
|
|
58
|
-
.replace('{{agentHistory}}', agentHistory)
|
|
59
|
-
.replace('{{cycleInstructions}}', cycleInstructions)
|
|
60
|
-
.replace('{{outputInstructions}}', outputInstructions)
|
|
61
|
-
.replace('{{extraInstructions}}', extraInstructions);
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
// Fallback to hardcoded version on error
|
|
65
|
-
console.warn('Failed to load base template from storage, using fallback', error);
|
|
66
|
-
return CUSTOM_AGENT_PROMPT(intent, context, agentHistory, cycleInstructions, outputInstructions, extraInstructions);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Load configure instructions
|
|
71
|
-
*/
|
|
72
|
-
async loadConfigureInstructions() {
|
|
73
|
-
if (!this.useStorage || !this.storage) {
|
|
74
|
-
// Fallback to hardcoded version
|
|
75
|
-
return CONFIGURE_INSTRUCTIONS;
|
|
76
|
-
}
|
|
77
|
-
try {
|
|
78
|
-
return await this.loadTemplate(PROMPT_IDS.AGENT, PROMPT_KEYS.CONFIGURE_INSTRUCTIONS);
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
// Fallback to hardcoded version on error
|
|
82
|
-
console.warn('Failed to load configure instructions from storage, using fallback', error);
|
|
83
|
-
return CONFIGURE_INSTRUCTIONS;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Load a template from storage
|
|
88
|
-
*/
|
|
89
|
-
async loadTemplate(promptId, key) {
|
|
90
|
-
// Check cache first
|
|
91
|
-
const cacheKey = `${promptId}:${key}`;
|
|
92
|
-
if (this.cache.has(cacheKey)) {
|
|
93
|
-
return this.cache.get(cacheKey).content;
|
|
94
|
-
}
|
|
95
|
-
if (!this.storage) {
|
|
96
|
-
throw new Error('Storage not available');
|
|
97
|
-
}
|
|
98
|
-
// Load from storage
|
|
99
|
-
const response = await this.storage.use(this.storage.address, {
|
|
100
|
-
method: 'get',
|
|
101
|
-
params: { promptId, key },
|
|
102
|
-
});
|
|
103
|
-
if (!response.result.success) {
|
|
104
|
-
throw new Error(`Failed to load template: ${response.result.error}`);
|
|
105
|
-
}
|
|
106
|
-
const template = response.result?.data?.value;
|
|
107
|
-
if (!template || !template.content) {
|
|
108
|
-
throw new Error(`Template not found: ${promptId}/${key}`);
|
|
109
|
-
}
|
|
110
|
-
// Cache for future use
|
|
111
|
-
this.cache.set(cacheKey, template);
|
|
112
|
-
return template.content;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Clear the template cache
|
|
116
|
-
*/
|
|
117
|
-
clearCache() {
|
|
118
|
-
this.cache.clear();
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Enable or disable storage usage
|
|
122
|
-
*/
|
|
123
|
-
setUseStorage(use) {
|
|
124
|
-
this.useStorage = use && !!this.storage;
|
|
20
|
+
async loadPromptForType(type, params, provider) {
|
|
21
|
+
throw new Error('Not implemented');
|
|
125
22
|
}
|
|
126
23
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../test/index.ts"],"names":[],"mappings":""}
|