@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
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
import { StorageProviderTool } from '@olane/o-storage';
|
|
2
|
-
import { oAddress } from '@olane/o-core';
|
|
3
|
-
import { PROMPT_STORAGE_METHODS } from './methods/prompt-storage.methods.js';
|
|
4
|
-
/**
|
|
5
|
-
* Prompt-specific storage provider that isolates data per prompt/conversation
|
|
6
|
-
* Extends StorageProviderTool to provide namespace isolation by promptId
|
|
7
|
-
*
|
|
8
|
-
* Features:
|
|
9
|
-
* - Isolated storage namespaces per promptId
|
|
10
|
-
* - Standard CRUD operations (put, get, delete, has)
|
|
11
|
-
* - Prompt management (list, clear, stats)
|
|
12
|
-
* - Optional TTL-based cleanup for inactive prompts
|
|
13
|
-
* - Memory-efficient nested Map structure
|
|
14
|
-
*/
|
|
15
|
-
export class PromptStorageProvider extends StorageProviderTool {
|
|
16
|
-
constructor(config) {
|
|
17
|
-
const finalConfig = {
|
|
18
|
-
...config,
|
|
19
|
-
address: config.address || new oAddress('o://prompt-storage'),
|
|
20
|
-
methods: PROMPT_STORAGE_METHODS,
|
|
21
|
-
description: 'Prompt-specific storage provider with isolated namespaces per conversation',
|
|
22
|
-
};
|
|
23
|
-
super(finalConfig);
|
|
24
|
-
this.config = config;
|
|
25
|
-
this.config = finalConfig;
|
|
26
|
-
this.storage = new Map();
|
|
27
|
-
this.metadata = new Map();
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Initialize background cleanup task if TTL is configured
|
|
31
|
-
*/
|
|
32
|
-
async hookStartFinished() {
|
|
33
|
-
if (this.config.promptTTL) {
|
|
34
|
-
const interval = this.config.cleanupInterval || 60000; // Default 1 minute
|
|
35
|
-
this.cleanupTimer = setInterval(() => {
|
|
36
|
-
this.cleanupExpiredPrompts();
|
|
37
|
-
}, interval);
|
|
38
|
-
this.logger.info('Prompt storage cleanup enabled', {
|
|
39
|
-
ttl: this.config.promptTTL,
|
|
40
|
-
interval,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
await super.hookStartFinished();
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Store data in a prompt-specific namespace
|
|
47
|
-
* ✅ Throws errors for validation failures
|
|
48
|
-
* ✅ Returns raw data (base class wraps it)
|
|
49
|
-
*/
|
|
50
|
-
async _tool_put(request) {
|
|
51
|
-
const { promptId, key, value } = request.params;
|
|
52
|
-
// Validate required parameters
|
|
53
|
-
if (!promptId || typeof promptId !== 'string') {
|
|
54
|
-
throw new Error('promptId is required and must be a string');
|
|
55
|
-
}
|
|
56
|
-
if (!key || typeof key !== 'string') {
|
|
57
|
-
throw new Error('key is required and must be a string');
|
|
58
|
-
}
|
|
59
|
-
if (value === undefined || value === null) {
|
|
60
|
-
throw new Error('value is required');
|
|
61
|
-
}
|
|
62
|
-
// Ensure prompt namespace exists
|
|
63
|
-
if (!this.storage.has(promptId)) {
|
|
64
|
-
this.storage.set(promptId, new Map());
|
|
65
|
-
this.metadata.set(promptId, {
|
|
66
|
-
createdAt: Date.now(),
|
|
67
|
-
lastAccessed: Date.now(),
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
// Store value and update metadata
|
|
71
|
-
const promptStorage = this.storage.get(promptId);
|
|
72
|
-
promptStorage.set(key, String(value));
|
|
73
|
-
this.updateLastAccessed(promptId);
|
|
74
|
-
// Check max prompts limit
|
|
75
|
-
if (this.config.maxPrompts && this.storage.size > this.config.maxPrompts) {
|
|
76
|
-
this.evictOldestPrompt();
|
|
77
|
-
}
|
|
78
|
-
return {
|
|
79
|
-
success: true,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Retrieve data from a prompt-specific namespace
|
|
84
|
-
* ✅ Throws errors for validation failures
|
|
85
|
-
* ✅ Returns raw data with null for missing keys
|
|
86
|
-
*/
|
|
87
|
-
async _tool_get(request) {
|
|
88
|
-
const { promptId, key } = request.params;
|
|
89
|
-
// Validate required parameters
|
|
90
|
-
if (!promptId || typeof promptId !== 'string') {
|
|
91
|
-
throw new Error('promptId is required and must be a string');
|
|
92
|
-
}
|
|
93
|
-
if (!key || typeof key !== 'string') {
|
|
94
|
-
throw new Error('key is required and must be a string');
|
|
95
|
-
}
|
|
96
|
-
// Check if prompt exists
|
|
97
|
-
const promptStorage = this.storage.get(promptId);
|
|
98
|
-
if (!promptStorage) {
|
|
99
|
-
return {
|
|
100
|
-
value: null,
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
// Get value and update metadata
|
|
104
|
-
const value = promptStorage.get(key);
|
|
105
|
-
if (value !== undefined) {
|
|
106
|
-
this.updateLastAccessed(promptId);
|
|
107
|
-
}
|
|
108
|
-
return {
|
|
109
|
-
value: value ?? null,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Delete a specific key from a prompt namespace
|
|
114
|
-
* ✅ Throws errors for validation failures
|
|
115
|
-
* ✅ Returns raw data
|
|
116
|
-
*/
|
|
117
|
-
async _tool_delete(request) {
|
|
118
|
-
const { promptId, key } = request.params;
|
|
119
|
-
// Validate required parameters
|
|
120
|
-
if (!promptId || typeof promptId !== 'string') {
|
|
121
|
-
throw new Error('promptId is required and must be a string');
|
|
122
|
-
}
|
|
123
|
-
if (!key || typeof key !== 'string') {
|
|
124
|
-
throw new Error('key is required and must be a string');
|
|
125
|
-
}
|
|
126
|
-
// Get prompt storage
|
|
127
|
-
const promptStorage = this.storage.get(promptId);
|
|
128
|
-
if (!promptStorage) {
|
|
129
|
-
// Not an error - deleting non-existent key is idempotent
|
|
130
|
-
return {
|
|
131
|
-
success: true,
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
// Delete key and update metadata
|
|
135
|
-
promptStorage.delete(key);
|
|
136
|
-
this.updateLastAccessed(promptId);
|
|
137
|
-
// Clean up empty prompt namespace
|
|
138
|
-
if (promptStorage.size === 0) {
|
|
139
|
-
this.storage.delete(promptId);
|
|
140
|
-
this.metadata.delete(promptId);
|
|
141
|
-
}
|
|
142
|
-
return {
|
|
143
|
-
success: true,
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Check if a key exists in a prompt namespace
|
|
148
|
-
* ✅ Throws errors for validation failures
|
|
149
|
-
* ✅ Returns raw data
|
|
150
|
-
*/
|
|
151
|
-
async _tool_has(request) {
|
|
152
|
-
const { promptId, key } = request.params;
|
|
153
|
-
// Validate required parameters
|
|
154
|
-
if (!promptId || typeof promptId !== 'string') {
|
|
155
|
-
throw new Error('promptId is required and must be a string');
|
|
156
|
-
}
|
|
157
|
-
if (!key || typeof key !== 'string') {
|
|
158
|
-
throw new Error('key is required and must be a string');
|
|
159
|
-
}
|
|
160
|
-
// Check existence
|
|
161
|
-
const promptStorage = this.storage.get(promptId);
|
|
162
|
-
const exists = promptStorage ? promptStorage.has(key) : false;
|
|
163
|
-
if (exists) {
|
|
164
|
-
this.updateLastAccessed(promptId);
|
|
165
|
-
}
|
|
166
|
-
return {
|
|
167
|
-
success: exists,
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* List all prompt IDs with active storage
|
|
172
|
-
*/
|
|
173
|
-
async _tool_list_prompts(_request) {
|
|
174
|
-
const promptIds = Array.from(this.storage.keys());
|
|
175
|
-
return {
|
|
176
|
-
promptIds,
|
|
177
|
-
count: promptIds.length,
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Clear all data for a specific prompt namespace
|
|
182
|
-
*/
|
|
183
|
-
async _tool_clear_prompt(request) {
|
|
184
|
-
const { promptId } = request.params;
|
|
185
|
-
// Validate required parameter
|
|
186
|
-
if (!promptId || typeof promptId !== 'string') {
|
|
187
|
-
throw new Error('promptId is required and must be a string');
|
|
188
|
-
}
|
|
189
|
-
const promptStorage = this.storage.get(promptId);
|
|
190
|
-
if (!promptStorage) {
|
|
191
|
-
return {
|
|
192
|
-
success: true,
|
|
193
|
-
keysDeleted: 0,
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
const keysDeleted = promptStorage.size;
|
|
197
|
-
// Clear storage and metadata
|
|
198
|
-
this.storage.delete(promptId);
|
|
199
|
-
this.metadata.delete(promptId);
|
|
200
|
-
return {
|
|
201
|
-
success: true,
|
|
202
|
-
keysDeleted,
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Get all keys stored in a specific prompt namespace
|
|
207
|
-
*/
|
|
208
|
-
async _tool_get_prompt_keys(request) {
|
|
209
|
-
const { promptId } = request.params;
|
|
210
|
-
// Validate required parameter
|
|
211
|
-
if (!promptId || typeof promptId !== 'string') {
|
|
212
|
-
throw new Error('promptId is required and must be a string');
|
|
213
|
-
}
|
|
214
|
-
const promptStorage = this.storage.get(promptId);
|
|
215
|
-
if (!promptStorage) {
|
|
216
|
-
return {
|
|
217
|
-
keys: [],
|
|
218
|
-
count: 0,
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
const keys = Array.from(promptStorage.keys());
|
|
222
|
-
this.updateLastAccessed(promptId);
|
|
223
|
-
return {
|
|
224
|
-
keys,
|
|
225
|
-
count: keys.length,
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Get statistics for a specific prompt namespace
|
|
230
|
-
*/
|
|
231
|
-
async _tool_get_prompt_stats(request) {
|
|
232
|
-
const { promptId } = request.params;
|
|
233
|
-
// Validate required parameter
|
|
234
|
-
if (!promptId || typeof promptId !== 'string') {
|
|
235
|
-
throw new Error('promptId is required and must be a string');
|
|
236
|
-
}
|
|
237
|
-
const promptStorage = this.storage.get(promptId);
|
|
238
|
-
const meta = this.metadata.get(promptId);
|
|
239
|
-
if (!promptStorage || !meta) {
|
|
240
|
-
return {
|
|
241
|
-
promptId,
|
|
242
|
-
keyCount: 0,
|
|
243
|
-
lastAccessed: 0,
|
|
244
|
-
exists: false,
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
this.updateLastAccessed(promptId);
|
|
248
|
-
return {
|
|
249
|
-
promptId,
|
|
250
|
-
keyCount: promptStorage.size,
|
|
251
|
-
lastAccessed: meta.lastAccessed,
|
|
252
|
-
exists: true,
|
|
253
|
-
createdAt: meta.createdAt,
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* Cleanup resources on stop
|
|
258
|
-
*/
|
|
259
|
-
async stop() {
|
|
260
|
-
if (this.cleanupTimer) {
|
|
261
|
-
clearInterval(this.cleanupTimer);
|
|
262
|
-
this.cleanupTimer = undefined;
|
|
263
|
-
}
|
|
264
|
-
await super.stop();
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* Update last accessed timestamp for a prompt
|
|
268
|
-
*/
|
|
269
|
-
updateLastAccessed(promptId) {
|
|
270
|
-
const meta = this.metadata.get(promptId);
|
|
271
|
-
if (meta) {
|
|
272
|
-
meta.lastAccessed = Date.now();
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* Clean up prompts that haven't been accessed within TTL
|
|
277
|
-
*/
|
|
278
|
-
cleanupExpiredPrompts() {
|
|
279
|
-
if (!this.config.promptTTL)
|
|
280
|
-
return;
|
|
281
|
-
const now = Date.now();
|
|
282
|
-
const expiredPrompts = [];
|
|
283
|
-
for (const [promptId, meta] of this.metadata.entries()) {
|
|
284
|
-
if (now - meta.lastAccessed > this.config.promptTTL) {
|
|
285
|
-
expiredPrompts.push(promptId);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
if (expiredPrompts.length > 0) {
|
|
289
|
-
for (const promptId of expiredPrompts) {
|
|
290
|
-
this.storage.delete(promptId);
|
|
291
|
-
this.metadata.delete(promptId);
|
|
292
|
-
}
|
|
293
|
-
this.logger.info('Cleaned up expired prompts', {
|
|
294
|
-
count: expiredPrompts.length,
|
|
295
|
-
promptIds: expiredPrompts,
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* Evict the oldest prompt when max limit is reached
|
|
301
|
-
*/
|
|
302
|
-
evictOldestPrompt() {
|
|
303
|
-
let oldestPromptId;
|
|
304
|
-
let oldestTime = Infinity;
|
|
305
|
-
for (const [promptId, meta] of this.metadata.entries()) {
|
|
306
|
-
if (meta.lastAccessed < oldestTime) {
|
|
307
|
-
oldestTime = meta.lastAccessed;
|
|
308
|
-
oldestPromptId = promptId;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
if (oldestPromptId) {
|
|
312
|
-
this.storage.delete(oldestPromptId);
|
|
313
|
-
this.metadata.delete(oldestPromptId);
|
|
314
|
-
this.logger.info('Evicted oldest prompt', {
|
|
315
|
-
promptId: oldestPromptId,
|
|
316
|
-
lastAccessed: oldestTime,
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-seeder.spec.d.ts","sourceRoot":"","sources":["../../test/prompt-seeder.spec.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC"}
|
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import 'dotenv/config';
|
|
2
|
-
import { describe, it, before, after } from 'mocha';
|
|
3
|
-
import { expect } from 'chai';
|
|
4
|
-
import { PromptStorageProvider } from '../src/storage/prompt-storage-provider.tool.js';
|
|
5
|
-
import { PromptSeeder } from '../src/storage/prompt-seeder.js';
|
|
6
|
-
import { PromptLoader } from '../src/storage/prompt-loader.js';
|
|
7
|
-
import { PROMPT_KEYS, PROMPT_IDS, } from '../src/storage/prompt-schema.js';
|
|
8
|
-
import { AGENT_PROMPT } from '../src/prompts/agent.prompt.js';
|
|
9
|
-
import { CONFIGURE_INSTRUCTIONS } from '../src/prompts/configure.prompt.js';
|
|
10
|
-
import { TestEnvironment } from '@olane/o-node/test/helpers';
|
|
11
|
-
import { assertSuccess, assertDefined } from '@olane/o-test';
|
|
12
|
-
describe('Prompt Seeding and Loading', () => {
|
|
13
|
-
const env = new TestEnvironment();
|
|
14
|
-
let storage;
|
|
15
|
-
let seeder;
|
|
16
|
-
let loader;
|
|
17
|
-
before(async () => {
|
|
18
|
-
// @ts-ignore
|
|
19
|
-
storage = await env.createNode(PromptStorageProvider, {});
|
|
20
|
-
seeder = new PromptSeeder(storage);
|
|
21
|
-
loader = new PromptLoader(storage);
|
|
22
|
-
});
|
|
23
|
-
after(async () => {
|
|
24
|
-
await env.cleanup();
|
|
25
|
-
});
|
|
26
|
-
describe('PromptSeeder', () => {
|
|
27
|
-
it('should check if prompts are not seeded initially', async () => {
|
|
28
|
-
const isSeeded = await seeder.isSeeded();
|
|
29
|
-
expect(isSeeded).to.equal(false);
|
|
30
|
-
});
|
|
31
|
-
it('should seed all prompts successfully', async () => {
|
|
32
|
-
await seeder.seedAll();
|
|
33
|
-
// Verify all prompts are stored
|
|
34
|
-
const baseTemplateResponse = await storage.use(storage.address, {
|
|
35
|
-
method: 'has',
|
|
36
|
-
params: {
|
|
37
|
-
promptId: PROMPT_IDS.AGENT,
|
|
38
|
-
key: PROMPT_KEYS.BASE_TEMPLATE,
|
|
39
|
-
},
|
|
40
|
-
});
|
|
41
|
-
assertSuccess(baseTemplateResponse);
|
|
42
|
-
expect(baseTemplateResponse.result?.data?.exists).to.equal(true);
|
|
43
|
-
const cycleResponse = await storage.use(storage.address, {
|
|
44
|
-
method: 'has',
|
|
45
|
-
params: {
|
|
46
|
-
promptId: PROMPT_IDS.AGENT,
|
|
47
|
-
key: PROMPT_KEYS.CYCLE_INSTRUCTIONS,
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
assertSuccess(cycleResponse);
|
|
51
|
-
expect(cycleResponse.result?.data?.exists).to.equal(true);
|
|
52
|
-
const outputResponse = await storage.use(storage.address, {
|
|
53
|
-
method: 'has',
|
|
54
|
-
params: {
|
|
55
|
-
promptId: PROMPT_IDS.AGENT,
|
|
56
|
-
key: PROMPT_KEYS.OUTPUT_INSTRUCTIONS,
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
assertSuccess(outputResponse);
|
|
60
|
-
expect(outputResponse.result?.data?.exists).to.equal(true);
|
|
61
|
-
const configureResponse = await storage.use(storage.address, {
|
|
62
|
-
method: 'has',
|
|
63
|
-
params: {
|
|
64
|
-
promptId: PROMPT_IDS.AGENT,
|
|
65
|
-
key: PROMPT_KEYS.CONFIGURE_INSTRUCTIONS,
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
assertSuccess(configureResponse);
|
|
69
|
-
expect(configureResponse.result?.data?.exists).to.equal(true);
|
|
70
|
-
});
|
|
71
|
-
it('should confirm prompts are seeded after seeding', async () => {
|
|
72
|
-
const isSeeded = await seeder.isSeeded();
|
|
73
|
-
expect(isSeeded).to.equal(true);
|
|
74
|
-
});
|
|
75
|
-
it('should store prompts with correct metadata', async () => {
|
|
76
|
-
const response = await storage.use(storage.address, {
|
|
77
|
-
method: 'get',
|
|
78
|
-
params: {
|
|
79
|
-
promptId: PROMPT_IDS.AGENT,
|
|
80
|
-
key: PROMPT_KEYS.BASE_TEMPLATE,
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
assertSuccess(response);
|
|
84
|
-
const template = response.result?.data?.value;
|
|
85
|
-
assertDefined(template, 'template');
|
|
86
|
-
expect(template.content).to.exist;
|
|
87
|
-
expect(template.metadata).to.exist;
|
|
88
|
-
expect(template.metadata.version).to.equal('1.0.0');
|
|
89
|
-
expect(template.metadata.source).to.equal('custom.prompt.ts');
|
|
90
|
-
});
|
|
91
|
-
it('should store base template with placeholders', async () => {
|
|
92
|
-
const response = await storage.use(storage.address, {
|
|
93
|
-
method: 'get',
|
|
94
|
-
params: {
|
|
95
|
-
promptId: PROMPT_IDS.AGENT,
|
|
96
|
-
key: PROMPT_KEYS.BASE_TEMPLATE,
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
assertSuccess(response);
|
|
100
|
-
const template = response.result?.data?.value;
|
|
101
|
-
assertDefined(template, 'template');
|
|
102
|
-
expect(template.content).to.include('{{intent}}');
|
|
103
|
-
expect(template.content).to.include('{{context}}');
|
|
104
|
-
expect(template.content).to.include('{{agentHistory}}');
|
|
105
|
-
expect(template.content).to.include('{{cycleInstructions}}');
|
|
106
|
-
expect(template.content).to.include('{{outputInstructions}}');
|
|
107
|
-
expect(template.content).to.include('{{extraInstructions}}');
|
|
108
|
-
});
|
|
109
|
-
it('should store cycle instructions with step details', async () => {
|
|
110
|
-
const response = await storage.use(storage.address, {
|
|
111
|
-
method: 'get',
|
|
112
|
-
params: {
|
|
113
|
-
promptId: PROMPT_IDS.AGENT,
|
|
114
|
-
key: PROMPT_KEYS.CYCLE_INSTRUCTIONS,
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
|
-
assertSuccess(response);
|
|
118
|
-
const template = response.result?.data?.value;
|
|
119
|
-
assertDefined(template, 'template');
|
|
120
|
-
expect(template.content).to.include('Step 1 - Evaluate the intent');
|
|
121
|
-
expect(template.content).to.include('Step 2 - Search for tools and context');
|
|
122
|
-
expect(template.content).to.include('Step 3 - Filter Search Results');
|
|
123
|
-
expect(template.content).to.include('Step 4 - Configure the target tool address use');
|
|
124
|
-
expect(template.content).to.include('Step 5 - Use target tool address');
|
|
125
|
-
expect(template.content).to.include('Step 6 - Review the tool use results');
|
|
126
|
-
});
|
|
127
|
-
it('should store output instructions with return types', async () => {
|
|
128
|
-
const response = await storage.use(storage.address, {
|
|
129
|
-
method: 'get',
|
|
130
|
-
params: {
|
|
131
|
-
promptId: PROMPT_IDS.AGENT,
|
|
132
|
-
key: PROMPT_KEYS.OUTPUT_INSTRUCTIONS,
|
|
133
|
-
},
|
|
134
|
-
});
|
|
135
|
-
assertSuccess(response);
|
|
136
|
-
const template = response.result?.data?.value;
|
|
137
|
-
assertDefined(template, 'template');
|
|
138
|
-
expect(template.content).to.include('Complex Intent Results');
|
|
139
|
-
expect(template.content).to.include('Configure Response');
|
|
140
|
-
expect(template.content).to.include('Search Response');
|
|
141
|
-
expect(template.content).to.include('Stop Response');
|
|
142
|
-
expect(template.content).to.include('Error Response');
|
|
143
|
-
expect(template.content).to.include('Use Tool Response');
|
|
144
|
-
});
|
|
145
|
-
it('should clear all prompts', async () => {
|
|
146
|
-
await seeder.clearAll();
|
|
147
|
-
const isSeeded = await seeder.isSeeded();
|
|
148
|
-
expect(isSeeded).to.equal(false);
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
describe('PromptLoader', () => {
|
|
152
|
-
before(async () => {
|
|
153
|
-
// Ensure prompts are seeded for loader tests
|
|
154
|
-
await seeder.seedAll();
|
|
155
|
-
});
|
|
156
|
-
it('should load configure instructions from storage', async () => {
|
|
157
|
-
const instructions = await loader.loadConfigureInstructions();
|
|
158
|
-
expect(instructions).to.exist;
|
|
159
|
-
expect(instructions).to.include('Configure Request Instructions');
|
|
160
|
-
expect(instructions).to.include('Step 1 - Validate the intent');
|
|
161
|
-
});
|
|
162
|
-
it('should generate agent prompt from storage', async () => {
|
|
163
|
-
const prompt = await loader.generateAgentPrompt('test intent', 'test context', 'test history', 'test extra');
|
|
164
|
-
expect(prompt).to.exist;
|
|
165
|
-
expect(prompt).to.include('test intent');
|
|
166
|
-
expect(prompt).to.include('test context');
|
|
167
|
-
expect(prompt).to.include('test history');
|
|
168
|
-
expect(prompt).to.include('test extra');
|
|
169
|
-
expect(prompt).to.include('Step 1 - Evaluate the intent');
|
|
170
|
-
expect(prompt).to.include('Stop Response');
|
|
171
|
-
});
|
|
172
|
-
it('should generate prompt identical to hardcoded version', async () => {
|
|
173
|
-
const intent = 'Get user information';
|
|
174
|
-
const context = 'User ID: 123';
|
|
175
|
-
const history = 'Previous cycle: searched for user';
|
|
176
|
-
const extra = 'Be concise';
|
|
177
|
-
const storagePrompt = await loader.generateAgentPrompt(intent, context, history, extra);
|
|
178
|
-
const hardcodedPrompt = AGENT_PROMPT(intent, context, history, extra);
|
|
179
|
-
expect(storagePrompt).to.equal(hardcodedPrompt);
|
|
180
|
-
});
|
|
181
|
-
it('should cache loaded templates', async () => {
|
|
182
|
-
// Clear cache first
|
|
183
|
-
loader.clearCache();
|
|
184
|
-
// First load - should hit storage
|
|
185
|
-
const prompt1 = await loader.generateAgentPrompt('test', 'test', 'test', 'test');
|
|
186
|
-
// Second load - should use cache
|
|
187
|
-
const prompt2 = await loader.generateAgentPrompt('test', 'test', 'test', 'test');
|
|
188
|
-
expect(prompt1).to.equal(prompt2);
|
|
189
|
-
});
|
|
190
|
-
it('should fallback to hardcoded prompts when storage unavailable', async () => {
|
|
191
|
-
const loaderWithoutStorage = new PromptLoader();
|
|
192
|
-
const prompt = await loaderWithoutStorage.generateAgentPrompt('test intent', 'test context', 'test history', 'test extra');
|
|
193
|
-
expect(prompt).to.exist;
|
|
194
|
-
expect(prompt).to.include('test intent');
|
|
195
|
-
expect(prompt).to.include('Step 1 - Evaluate the intent');
|
|
196
|
-
});
|
|
197
|
-
it('should fallback to hardcoded configure instructions when storage unavailable', async () => {
|
|
198
|
-
const loaderWithoutStorage = new PromptLoader();
|
|
199
|
-
const instructions = await loaderWithoutStorage.loadConfigureInstructions();
|
|
200
|
-
expect(instructions).to.equal(CONFIGURE_INSTRUCTIONS);
|
|
201
|
-
});
|
|
202
|
-
it('should allow disabling storage usage', async () => {
|
|
203
|
-
loader.setUseStorage(false);
|
|
204
|
-
const prompt = await loader.generateAgentPrompt('test', 'test', 'test', 'test');
|
|
205
|
-
expect(prompt).to.exist;
|
|
206
|
-
// Re-enable for other tests
|
|
207
|
-
loader.setUseStorage(true);
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
describe('Integration', () => {
|
|
211
|
-
it('should handle complete seed-load-clear cycle', async () => {
|
|
212
|
-
// Clear first
|
|
213
|
-
await seeder.clearAll();
|
|
214
|
-
expect(await seeder.isSeeded()).to.equal(false);
|
|
215
|
-
// Seed
|
|
216
|
-
await seeder.seedAll();
|
|
217
|
-
expect(await seeder.isSeeded()).to.equal(true);
|
|
218
|
-
// Load and verify
|
|
219
|
-
loader.clearCache();
|
|
220
|
-
const prompt = await loader.generateAgentPrompt('test', 'test', 'test', 'test');
|
|
221
|
-
expect(prompt).to.include('test');
|
|
222
|
-
const instructions = await loader.loadConfigureInstructions();
|
|
223
|
-
expect(instructions).to.include('Configure Request Instructions');
|
|
224
|
-
// Clear again
|
|
225
|
-
await seeder.clearAll();
|
|
226
|
-
expect(await seeder.isSeeded()).to.equal(false);
|
|
227
|
-
});
|
|
228
|
-
it('should list all seeded prompts', async () => {
|
|
229
|
-
await seeder.seedAll();
|
|
230
|
-
const response = await storage.use(storage.address, {
|
|
231
|
-
method: 'get_prompt_keys',
|
|
232
|
-
params: {
|
|
233
|
-
promptId: PROMPT_IDS.AGENT,
|
|
234
|
-
},
|
|
235
|
-
});
|
|
236
|
-
assertSuccess(response);
|
|
237
|
-
expect(response.result?.data?.keys).to.include(PROMPT_KEYS.BASE_TEMPLATE);
|
|
238
|
-
expect(response.result?.data?.keys).to.include(PROMPT_KEYS.CYCLE_INSTRUCTIONS);
|
|
239
|
-
expect(response.result?.data?.keys).to.include(PROMPT_KEYS.OUTPUT_INSTRUCTIONS);
|
|
240
|
-
expect(response.result?.data?.keys).to.include(PROMPT_KEYS.CONFIGURE_INSTRUCTIONS);
|
|
241
|
-
expect(response.result?.data?.count).to.equal(4);
|
|
242
|
-
});
|
|
243
|
-
it('should get stats for seeded prompts', async () => {
|
|
244
|
-
const response = await storage.use(storage.address, {
|
|
245
|
-
method: 'get_prompt_stats',
|
|
246
|
-
params: {
|
|
247
|
-
promptId: PROMPT_IDS.AGENT,
|
|
248
|
-
},
|
|
249
|
-
});
|
|
250
|
-
assertSuccess(response);
|
|
251
|
-
expect(response.result?.data?.exists).to.equal(true);
|
|
252
|
-
expect(response.result?.data?.keyCount).to.equal(4);
|
|
253
|
-
expect(response.result?.data?.promptId).to.equal(PROMPT_IDS.AGENT);
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-storage-provider.spec.d.ts","sourceRoot":"","sources":["../../test/prompt-storage-provider.spec.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC"}
|