@limo-labs/deity 0.1.0-alpha.0
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 +519 -0
- package/dist/src/component.d.ts +19 -0
- package/dist/src/component.d.ts.map +1 -0
- package/dist/src/component.js +2 -0
- package/dist/src/component.js.map +1 -0
- package/dist/src/context/context-scope.d.ts +24 -0
- package/dist/src/context/context-scope.d.ts.map +1 -0
- package/dist/src/context/context-scope.js +19 -0
- package/dist/src/context/context-scope.js.map +1 -0
- package/dist/src/context/memory-view.d.ts +62 -0
- package/dist/src/context/memory-view.d.ts.map +1 -0
- package/dist/src/context/memory-view.js +104 -0
- package/dist/src/context/memory-view.js.map +1 -0
- package/dist/src/context/scoped-context.d.ts +51 -0
- package/dist/src/context/scoped-context.d.ts.map +1 -0
- package/dist/src/context/scoped-context.js +74 -0
- package/dist/src/context/scoped-context.js.map +1 -0
- package/dist/src/context/scoped-execution-context.d.ts +55 -0
- package/dist/src/context/scoped-execution-context.d.ts.map +1 -0
- package/dist/src/context/scoped-execution-context.js +78 -0
- package/dist/src/context/scoped-execution-context.js.map +1 -0
- package/dist/src/conversation/conversation-manager.d.ts +272 -0
- package/dist/src/conversation/conversation-manager.d.ts.map +1 -0
- package/dist/src/conversation/conversation-manager.js +11 -0
- package/dist/src/conversation/conversation-manager.js.map +1 -0
- package/dist/src/conversation/conversation-pruner.d.ts +190 -0
- package/dist/src/conversation/conversation-pruner.d.ts.map +1 -0
- package/dist/src/conversation/conversation-pruner.js +274 -0
- package/dist/src/conversation/conversation-pruner.js.map +1 -0
- package/dist/src/conversation/conversation-tree.d.ts +185 -0
- package/dist/src/conversation/conversation-tree.d.ts.map +1 -0
- package/dist/src/conversation/conversation-tree.js +288 -0
- package/dist/src/conversation/conversation-tree.js.map +1 -0
- package/dist/src/conversation/file-conversation-store.d.ts +93 -0
- package/dist/src/conversation/file-conversation-store.d.ts.map +1 -0
- package/dist/src/conversation/file-conversation-store.js +284 -0
- package/dist/src/conversation/file-conversation-store.js.map +1 -0
- package/dist/src/conversation/in-memory-conversation-store.d.ts +36 -0
- package/dist/src/conversation/in-memory-conversation-store.d.ts.map +1 -0
- package/dist/src/conversation/in-memory-conversation-store.js +146 -0
- package/dist/src/conversation/in-memory-conversation-store.js.map +1 -0
- package/dist/src/copilot-adapter.d.ts +33 -0
- package/dist/src/copilot-adapter.d.ts.map +1 -0
- package/dist/src/copilot-adapter.js +119 -0
- package/dist/src/copilot-adapter.js.map +1 -0
- package/dist/src/file-trace-enhanced.d.ts +123 -0
- package/dist/src/file-trace-enhanced.d.ts.map +1 -0
- package/dist/src/file-trace-enhanced.js +177 -0
- package/dist/src/file-trace-enhanced.js.map +1 -0
- package/dist/src/file-trace.d.ts +24 -0
- package/dist/src/file-trace.d.ts.map +1 -0
- package/dist/src/file-trace.js +60 -0
- package/dist/src/file-trace.js.map +1 -0
- package/dist/src/index.d.ts +63 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +40 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/json-store.d.ts +27 -0
- package/dist/src/json-store.d.ts.map +1 -0
- package/dist/src/json-store.js +93 -0
- package/dist/src/json-store.js.map +1 -0
- package/dist/src/llm.d.ts +35 -0
- package/dist/src/llm.d.ts.map +1 -0
- package/dist/src/llm.js +2 -0
- package/dist/src/llm.js.map +1 -0
- package/dist/src/memory/cold-storage.d.ts +60 -0
- package/dist/src/memory/cold-storage.d.ts.map +1 -0
- package/dist/src/memory/cold-storage.js +132 -0
- package/dist/src/memory/cold-storage.js.map +1 -0
- package/dist/src/memory/compression.d.ts +161 -0
- package/dist/src/memory/compression.d.ts.map +1 -0
- package/dist/src/memory/compression.js +193 -0
- package/dist/src/memory/compression.js.map +1 -0
- package/dist/src/memory/hot-memory.d.ts +69 -0
- package/dist/src/memory/hot-memory.d.ts.map +1 -0
- package/dist/src/memory/hot-memory.js +116 -0
- package/dist/src/memory/hot-memory.js.map +1 -0
- package/dist/src/memory/memory-budget.d.ts +162 -0
- package/dist/src/memory/memory-budget.d.ts.map +1 -0
- package/dist/src/memory/memory-budget.js +241 -0
- package/dist/src/memory/memory-budget.js.map +1 -0
- package/dist/src/memory/memory-config.d.ts +419 -0
- package/dist/src/memory/memory-config.d.ts.map +1 -0
- package/dist/src/memory/memory-config.js +297 -0
- package/dist/src/memory/memory-config.js.map +1 -0
- package/dist/src/memory/prefetcher.d.ts +137 -0
- package/dist/src/memory/prefetcher.d.ts.map +1 -0
- package/dist/src/memory/prefetcher.js +186 -0
- package/dist/src/memory/prefetcher.js.map +1 -0
- package/dist/src/memory/tiered-memory.d.ts +116 -0
- package/dist/src/memory/tiered-memory.d.ts.map +1 -0
- package/dist/src/memory/tiered-memory.js +215 -0
- package/dist/src/memory/tiered-memory.js.map +1 -0
- package/dist/src/memory/warm-storage.d.ts +74 -0
- package/dist/src/memory/warm-storage.d.ts.map +1 -0
- package/dist/src/memory/warm-storage.js +207 -0
- package/dist/src/memory/warm-storage.js.map +1 -0
- package/dist/src/openai-adapter.d.ts +20 -0
- package/dist/src/openai-adapter.d.ts.map +1 -0
- package/dist/src/openai-adapter.js +73 -0
- package/dist/src/openai-adapter.js.map +1 -0
- package/dist/src/parser.d.ts +27 -0
- package/dist/src/parser.d.ts.map +1 -0
- package/dist/src/parser.js +76 -0
- package/dist/src/parser.js.map +1 -0
- package/dist/src/runtime.d.ts +172 -0
- package/dist/src/runtime.d.ts.map +1 -0
- package/dist/src/runtime.js +436 -0
- package/dist/src/runtime.js.map +1 -0
- package/dist/src/schema-utils.d.ts +7 -0
- package/dist/src/schema-utils.d.ts.map +1 -0
- package/dist/src/schema-utils.js +71 -0
- package/dist/src/schema-utils.js.map +1 -0
- package/dist/src/stage.d.ts +139 -0
- package/dist/src/stage.d.ts.map +1 -0
- package/dist/src/stage.js +2 -0
- package/dist/src/stage.js.map +1 -0
- package/dist/src/store.d.ts +51 -0
- package/dist/src/store.d.ts.map +1 -0
- package/dist/src/store.js +2 -0
- package/dist/src/store.js.map +1 -0
- package/dist/src/tool.d.ts +12 -0
- package/dist/src/tool.d.ts.map +1 -0
- package/dist/src/tool.js +2 -0
- package/dist/src/tool.js.map +1 -0
- package/dist/src/trace.d.ts +60 -0
- package/dist/src/trace.d.ts.map +1 -0
- package/dist/src/trace.js +2 -0
- package/dist/src/trace.js.map +1 -0
- package/dist/src/validator.d.ts +17 -0
- package/dist/src/validator.d.ts.map +1 -0
- package/dist/src/validator.js +21 -0
- package/dist/src/validator.js.map +1 -0
- package/dist/src/workflow.d.ts +192 -0
- package/dist/src/workflow.d.ts.map +1 -0
- package/dist/src/workflow.js +50 -0
- package/dist/src/workflow.js.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { TieredMemoryManager, } from "./tiered-memory.js";
|
|
3
|
+
/**
|
|
4
|
+
* Zod schema for hot memory configuration validation.
|
|
5
|
+
* @since 2.0.0
|
|
6
|
+
*/
|
|
7
|
+
export const HotMemoryConfigSchema = z.object({
|
|
8
|
+
maxItems: z.number().int().positive(),
|
|
9
|
+
maxSize: z.number().int().positive().optional(),
|
|
10
|
+
ttl: z.number().int().positive().optional(),
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Zod schema for warm storage configuration validation.
|
|
14
|
+
* @since 2.0.0
|
|
15
|
+
*/
|
|
16
|
+
export const WarmStorageConfigSchema = z.object({
|
|
17
|
+
enabled: z.boolean(),
|
|
18
|
+
maxSize: z.number().int().positive(),
|
|
19
|
+
compressionAlgorithm: z.enum(["gzip", "lz4", "none"]),
|
|
20
|
+
directory: z.string().min(1),
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* Zod schema for cold storage configuration validation.
|
|
24
|
+
* @since 2.0.0
|
|
25
|
+
*/
|
|
26
|
+
export const ColdStorageConfigSchema = z.object({
|
|
27
|
+
enabled: z.boolean(),
|
|
28
|
+
directory: z.string().min(1),
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* Zod schema for complete memory configuration validation.
|
|
32
|
+
* @since 2.0.0
|
|
33
|
+
*/
|
|
34
|
+
export const MemoryConfigSchema = z.object({
|
|
35
|
+
hot: HotMemoryConfigSchema,
|
|
36
|
+
warm: WarmStorageConfigSchema,
|
|
37
|
+
cold: ColdStorageConfigSchema,
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* Pre-configured memory settings for development environments.
|
|
41
|
+
*
|
|
42
|
+
* - Generous hot memory limits (2000 items, 200MB)
|
|
43
|
+
* - No compression (fast, no CPU overhead)
|
|
44
|
+
* - Warm and cold storage enabled
|
|
45
|
+
* - Short TTL for fast iteration
|
|
46
|
+
*
|
|
47
|
+
* @since 2.0.0
|
|
48
|
+
*/
|
|
49
|
+
export const MemoryPresets = {
|
|
50
|
+
/**
|
|
51
|
+
* Development preset: Fast and generous.
|
|
52
|
+
*
|
|
53
|
+
* Optimized for quick iteration and debugging with minimal overhead.
|
|
54
|
+
* Uses no compression for speed and has generous memory limits.
|
|
55
|
+
*/
|
|
56
|
+
development: {
|
|
57
|
+
hot: {
|
|
58
|
+
maxItems: 2000,
|
|
59
|
+
maxSize: 200 * 1024 * 1024, // 200MB
|
|
60
|
+
ttl: 30 * 60 * 1000, // 30 minutes
|
|
61
|
+
},
|
|
62
|
+
warm: {
|
|
63
|
+
enabled: true,
|
|
64
|
+
maxSize: 2 * 1024 * 1024 * 1024, // 2GB
|
|
65
|
+
compressionAlgorithm: "none",
|
|
66
|
+
directory: ".deity/cache-dev",
|
|
67
|
+
},
|
|
68
|
+
cold: {
|
|
69
|
+
enabled: true,
|
|
70
|
+
directory: ".deity/archive-dev",
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
/**
|
|
74
|
+
* Production preset: Balanced and reliable.
|
|
75
|
+
*
|
|
76
|
+
* Optimized for production use with good balance between performance
|
|
77
|
+
* and resource usage. Uses gzip compression for space efficiency.
|
|
78
|
+
*/
|
|
79
|
+
production: {
|
|
80
|
+
hot: {
|
|
81
|
+
maxItems: 1000,
|
|
82
|
+
maxSize: 100 * 1024 * 1024, // 100MB
|
|
83
|
+
ttl: 60 * 60 * 1000, // 1 hour
|
|
84
|
+
},
|
|
85
|
+
warm: {
|
|
86
|
+
enabled: true,
|
|
87
|
+
maxSize: 1024 * 1024 * 1024, // 1GB
|
|
88
|
+
compressionAlgorithm: "gzip",
|
|
89
|
+
directory: ".deity/cache",
|
|
90
|
+
},
|
|
91
|
+
cold: {
|
|
92
|
+
enabled: true,
|
|
93
|
+
directory: ".deity/archive",
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
/**
|
|
97
|
+
* Minimal preset: Lightweight with minimal disk usage.
|
|
98
|
+
*
|
|
99
|
+
* Optimized for resource-constrained environments or simple workflows.
|
|
100
|
+
* Warm storage disabled, only hot memory and cold storage used.
|
|
101
|
+
*/
|
|
102
|
+
minimal: {
|
|
103
|
+
hot: {
|
|
104
|
+
maxItems: 500,
|
|
105
|
+
maxSize: 50 * 1024 * 1024, // 50MB
|
|
106
|
+
ttl: 10 * 60 * 1000, // 10 minutes
|
|
107
|
+
},
|
|
108
|
+
warm: {
|
|
109
|
+
enabled: false,
|
|
110
|
+
maxSize: 1, // Dummy value (warm is disabled)
|
|
111
|
+
compressionAlgorithm: "none",
|
|
112
|
+
directory: ".deity/cache",
|
|
113
|
+
},
|
|
114
|
+
cold: {
|
|
115
|
+
enabled: true,
|
|
116
|
+
directory: ".deity/archive",
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Validates a memory configuration against the schema.
|
|
122
|
+
*
|
|
123
|
+
* Throws an error if the configuration is invalid.
|
|
124
|
+
*
|
|
125
|
+
* @param config - The configuration to validate
|
|
126
|
+
* @returns The validated configuration (typed)
|
|
127
|
+
* @throws {Error} If the configuration is invalid
|
|
128
|
+
* @since 2.0.0
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* try {
|
|
132
|
+
* const validated = validateMemoryConfig(userConfig);
|
|
133
|
+
* console.log("Configuration valid!");
|
|
134
|
+
* } catch (error) {
|
|
135
|
+
* console.error("Invalid configuration:", error.message);
|
|
136
|
+
* }
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export function validateMemoryConfig(config) {
|
|
140
|
+
return MemoryConfigSchema.parse(config);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Merges a partial configuration with a base configuration.
|
|
144
|
+
*
|
|
145
|
+
* Useful for applying user overrides on top of a preset.
|
|
146
|
+
* Performs deep merge of nested objects.
|
|
147
|
+
*
|
|
148
|
+
* @param base - The base configuration (preset or default)
|
|
149
|
+
* @param override - The partial configuration to merge
|
|
150
|
+
* @returns The merged configuration
|
|
151
|
+
* @since 2.0.0
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* const config = mergeMemoryConfig(
|
|
155
|
+
* MemoryPresets.production,
|
|
156
|
+
* {
|
|
157
|
+
* hot: { maxItems: 2000 }, // Override just maxItems
|
|
158
|
+
* }
|
|
159
|
+
* );
|
|
160
|
+
* // Result: production preset with 2000 hot items instead of 1000
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
export function mergeMemoryConfig(base, override) {
|
|
164
|
+
return {
|
|
165
|
+
hot: {
|
|
166
|
+
...base.hot,
|
|
167
|
+
...override.hot,
|
|
168
|
+
},
|
|
169
|
+
warm: {
|
|
170
|
+
...base.warm,
|
|
171
|
+
...override.warm,
|
|
172
|
+
},
|
|
173
|
+
cold: {
|
|
174
|
+
...base.cold,
|
|
175
|
+
...override.cold,
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Creates a memory configuration from a preset or custom config.
|
|
181
|
+
*
|
|
182
|
+
* Supports three modes:
|
|
183
|
+
* 1. Preset name ("development", "production", "minimal")
|
|
184
|
+
* 2. Full custom configuration
|
|
185
|
+
* 3. Preset with overrides
|
|
186
|
+
*
|
|
187
|
+
* @param config - Preset name, full config, or preset with overrides
|
|
188
|
+
* @returns Validated memory configuration
|
|
189
|
+
* @throws {Error} If the configuration is invalid
|
|
190
|
+
* @since 2.0.0
|
|
191
|
+
* @example
|
|
192
|
+
* ```typescript
|
|
193
|
+
* // Use preset
|
|
194
|
+
* const config1 = createMemoryConfig("production");
|
|
195
|
+
*
|
|
196
|
+
* // Use custom config
|
|
197
|
+
* const config2 = createMemoryConfig({
|
|
198
|
+
* hot: { maxItems: 1500 },
|
|
199
|
+
* warm: { enabled: true, maxSize: 1024 * 1024 * 1024, compressionAlgorithm: "gzip", directory: ".cache" },
|
|
200
|
+
* cold: { enabled: true, directory: ".archive" },
|
|
201
|
+
* });
|
|
202
|
+
*
|
|
203
|
+
* // Use preset with overrides
|
|
204
|
+
* const config3 = createMemoryConfig({
|
|
205
|
+
* preset: "production",
|
|
206
|
+
* override: { hot: { maxItems: 2000 } },
|
|
207
|
+
* });
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
export function createMemoryConfig(config) {
|
|
211
|
+
// Case 1: Preset name
|
|
212
|
+
if (typeof config === "string") {
|
|
213
|
+
if (!(config in MemoryPresets)) {
|
|
214
|
+
throw new Error(`Unknown memory preset: "${config}". Valid presets: ${Object.keys(MemoryPresets).join(", ")}`);
|
|
215
|
+
}
|
|
216
|
+
return MemoryPresets[config];
|
|
217
|
+
}
|
|
218
|
+
// Case 2: Preset with override
|
|
219
|
+
if ("preset" in config && "override" in config) {
|
|
220
|
+
const base = MemoryPresets[config.preset];
|
|
221
|
+
return validateMemoryConfig(mergeMemoryConfig(base, config.override));
|
|
222
|
+
}
|
|
223
|
+
// Case 3: Full custom config
|
|
224
|
+
return validateMemoryConfig(config);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Gets the default memory configuration.
|
|
228
|
+
*
|
|
229
|
+
* Uses the production preset by default.
|
|
230
|
+
*
|
|
231
|
+
* @returns Default memory configuration
|
|
232
|
+
* @since 2.0.0
|
|
233
|
+
*/
|
|
234
|
+
export function getDefaultMemoryConfig() {
|
|
235
|
+
return MemoryPresets.production;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Creates a TieredMemoryManager instance from a memory configuration.
|
|
239
|
+
*
|
|
240
|
+
* Converts the user-facing MemoryConfig (with validation and presets) into
|
|
241
|
+
* the internal TieredMemoryConfig format and creates a TieredMemoryManager.
|
|
242
|
+
*
|
|
243
|
+
* This is a synchronous wrapper - it uses require() internally which works
|
|
244
|
+
* because TieredMemoryManager is in the same package.
|
|
245
|
+
*
|
|
246
|
+
* @param config - Memory configuration (preset name, full config, or preset with override)
|
|
247
|
+
* @returns Configured TieredMemoryManager instance (call .init() before use)
|
|
248
|
+
* @throws {Error} If the configuration is invalid
|
|
249
|
+
* @since 2.0.0
|
|
250
|
+
* @example
|
|
251
|
+
* ```typescript
|
|
252
|
+
* // Create from preset name
|
|
253
|
+
* const manager1 = createTieredMemoryManager("production");
|
|
254
|
+
* await manager1.init();
|
|
255
|
+
*
|
|
256
|
+
* // Create from custom config
|
|
257
|
+
* const manager2 = createTieredMemoryManager({
|
|
258
|
+
* hot: { maxItems: 1000 },
|
|
259
|
+
* warm: { enabled: true, maxSize: 1024 * 1024 * 1024, compressionAlgorithm: "gzip", directory: ".cache" },
|
|
260
|
+
* cold: { enabled: true, directory: ".archive" },
|
|
261
|
+
* });
|
|
262
|
+
* await manager2.init();
|
|
263
|
+
*
|
|
264
|
+
* // Create from preset with overrides
|
|
265
|
+
* const manager3 = createTieredMemoryManager({
|
|
266
|
+
* preset: "production",
|
|
267
|
+
* override: { hot: { maxItems: 2000 } },
|
|
268
|
+
* });
|
|
269
|
+
* await manager3.init();
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
export function createTieredMemoryManager(config) {
|
|
273
|
+
// Normalize to MemoryConfig
|
|
274
|
+
const memoryConfig = createMemoryConfig(config);
|
|
275
|
+
// Convert to TieredMemoryConfig (internal format)
|
|
276
|
+
const tieredConfig = {
|
|
277
|
+
hot: {
|
|
278
|
+
maxItems: memoryConfig.hot.maxItems,
|
|
279
|
+
maxSize: memoryConfig.hot.maxSize,
|
|
280
|
+
ttl: memoryConfig.hot.ttl,
|
|
281
|
+
},
|
|
282
|
+
warm: memoryConfig.warm.enabled
|
|
283
|
+
? {
|
|
284
|
+
directory: memoryConfig.warm.directory,
|
|
285
|
+
maxSize: memoryConfig.warm.maxSize,
|
|
286
|
+
compressionAlgorithm: memoryConfig.warm.compressionAlgorithm,
|
|
287
|
+
}
|
|
288
|
+
: undefined,
|
|
289
|
+
cold: memoryConfig.cold.enabled
|
|
290
|
+
? {
|
|
291
|
+
directory: memoryConfig.cold.directory,
|
|
292
|
+
}
|
|
293
|
+
: undefined,
|
|
294
|
+
};
|
|
295
|
+
return new TieredMemoryManager(tieredConfig);
|
|
296
|
+
}
|
|
297
|
+
//# sourceMappingURL=memory-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-config.js","sourceRoot":"","sources":["../../../src/memory/memory-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,mBAAmB,GAEpB,MAAM,oBAAoB,CAAC;AAkF5B;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;IACrC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;IAC/C,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;CAC5C,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,u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AAY,CAAC,GAAG,CAAC,QAAQ;YACnC,OAAO,EAAE,YAAY,CAAC,GAAG,CAAC,OAAO;YACjC,GAAG,EAAE,YAAY,CAAC,GAAG,CAAC,GAAG;SAC1B;QACD,IAAI,EAAE,YAAY,CAAC,IAAI,CAAC,OAAO;YAC7B,CAAC,CAAC;gBACE,SAAS,EAAE,YAAY,CAAC,IAAI,CAAC,SAAS;gBACtC,OAAO,EAAE,YAAY,CAAC,IAAI,CAAC,OAAO;gBAClC,oBAAoB,EAAE,YAAY,CAAC,IAAI,CAAC,oBAAoB;aAC7D;YACH,CAAC,CAAC,SAAS;QACb,IAAI,EAAE,YAAY,CAAC,IAAI,CAAC,OAAO;YAC7B,CAAC,CAAC;gBACE,SAAS,EAAE,YAAY,CAAC,IAAI,CAAC,SAAS;aACvC;YACH,CAAC,CAAC,SAAS;KACd,CAAC;IAEF,OAAO,IAAI,mBAAmB,CAAC,YAAY,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory prefetcher for optimizing workflow execution.
|
|
3
|
+
*
|
|
4
|
+
* Analyzes workflow step dependencies and preloads data into hot memory
|
|
5
|
+
* before step execution to reduce latency.
|
|
6
|
+
*
|
|
7
|
+
* @module memory/prefetcher
|
|
8
|
+
* @since 2.0.0
|
|
9
|
+
*/
|
|
10
|
+
import type { Workflow } from "../workflow.js";
|
|
11
|
+
import type { TieredMemoryManager } from "./tiered-memory.js";
|
|
12
|
+
/**
|
|
13
|
+
* Dependency graph node representing a workflow step.
|
|
14
|
+
*/
|
|
15
|
+
interface DependencyNode {
|
|
16
|
+
stepId: string;
|
|
17
|
+
dependencies: Set<string>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Prefetch hint for manual optimization.
|
|
21
|
+
*/
|
|
22
|
+
export interface PrefetchHint {
|
|
23
|
+
/** Step ID that will need this data */
|
|
24
|
+
stepId: string;
|
|
25
|
+
/** Keys to prefetch into hot memory */
|
|
26
|
+
keys: string[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Memory prefetcher that analyzes workflow dependencies and preloads data.
|
|
30
|
+
*
|
|
31
|
+
* The prefetcher works by:
|
|
32
|
+
* 1. Analyzing which steps depend on outputs from previous steps
|
|
33
|
+
* 2. Before executing a step, promoting its dependencies to hot memory
|
|
34
|
+
* 3. Supporting manual prefetch hints for custom optimization
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const prefetcher = new MemoryPrefetcher(memory, workflow);
|
|
39
|
+
*
|
|
40
|
+
* // Before executing Step2, prefetch Step1's output
|
|
41
|
+
* await prefetcher.prefetchForStep("Step2");
|
|
42
|
+
*
|
|
43
|
+
* // Manual prefetch with custom keys
|
|
44
|
+
* await prefetcher.prefetch({
|
|
45
|
+
* stepId: "Step3",
|
|
46
|
+
* keys: ["stage:Step1", "stage:Step2"]
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @since 2.0.0
|
|
51
|
+
*/
|
|
52
|
+
export declare class MemoryPrefetcher {
|
|
53
|
+
private memory;
|
|
54
|
+
private workflow;
|
|
55
|
+
private dependencyGraph;
|
|
56
|
+
private prefetchHints;
|
|
57
|
+
constructor(memory: TieredMemoryManager, workflow: Workflow);
|
|
58
|
+
/**
|
|
59
|
+
* Build the dependency graph by analyzing workflow steps.
|
|
60
|
+
*
|
|
61
|
+
* This is a simple analysis - it assumes each step depends on all previous steps.
|
|
62
|
+
* More sophisticated analysis could inspect the buildPrompt() method to detect
|
|
63
|
+
* actual dependencies by checking for ctx.getOutput() calls.
|
|
64
|
+
*/
|
|
65
|
+
private buildDependencyGraph;
|
|
66
|
+
/**
|
|
67
|
+
* Analyze dependencies for a specific step.
|
|
68
|
+
*
|
|
69
|
+
* Returns the set of step IDs that this step depends on.
|
|
70
|
+
*
|
|
71
|
+
* @param stepId - The step to analyze
|
|
72
|
+
* @returns Array of dependent step IDs
|
|
73
|
+
*/
|
|
74
|
+
analyzeDependencies(stepId: string): string[];
|
|
75
|
+
/**
|
|
76
|
+
* Prefetch data for a specific step.
|
|
77
|
+
*
|
|
78
|
+
* Promotes all dependency outputs to hot memory before step execution.
|
|
79
|
+
* This is opportunistic - failures are logged but don't block execution.
|
|
80
|
+
*
|
|
81
|
+
* @param stepId - The step about to be executed
|
|
82
|
+
* @returns Promise that resolves when prefetch completes (or fails gracefully)
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* // Before executing Step2
|
|
87
|
+
* await prefetcher.prefetchForStep("Step2");
|
|
88
|
+
* // Now Step2 execution will find Step1 output in hot memory
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
prefetchForStep(stepId: string): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Add a manual prefetch hint for a step.
|
|
94
|
+
*
|
|
95
|
+
* This allows developers to optimize specific steps by explicitly
|
|
96
|
+
* declaring what data they need.
|
|
97
|
+
*
|
|
98
|
+
* @param hint - Prefetch hint with step ID and keys
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* prefetcher.addHint({
|
|
103
|
+
* stepId: "AnalyzeCode",
|
|
104
|
+
* keys: ["stage:ReadFiles", "conversation:main"]
|
|
105
|
+
* });
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
addHint(hint: PrefetchHint): void;
|
|
109
|
+
/**
|
|
110
|
+
* Prefetch using a manual hint.
|
|
111
|
+
*
|
|
112
|
+
* @param hint - Prefetch hint with keys to load
|
|
113
|
+
*/
|
|
114
|
+
prefetch(hint: PrefetchHint): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Get the dependency graph for debugging.
|
|
117
|
+
*
|
|
118
|
+
* @returns Map of step IDs to their dependency nodes
|
|
119
|
+
*/
|
|
120
|
+
getDependencyGraph(): Map<string, DependencyNode>;
|
|
121
|
+
/**
|
|
122
|
+
* Clear all prefetch hints.
|
|
123
|
+
*/
|
|
124
|
+
clearHints(): void;
|
|
125
|
+
/**
|
|
126
|
+
* Get statistics about the dependency graph.
|
|
127
|
+
*
|
|
128
|
+
* @returns Stats about steps and dependencies
|
|
129
|
+
*/
|
|
130
|
+
getStats(): {
|
|
131
|
+
totalSteps: number;
|
|
132
|
+
totalDependencies: number;
|
|
133
|
+
averageDependencies: number;
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
export {};
|
|
137
|
+
//# sourceMappingURL=prefetcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefetcher.d.ts","sourceRoot":"","sources":["../../../src/memory/prefetcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAG9D;;GAEG;AACH,UAAU,cAAc;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,uCAAuC;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,uCAAuC;IACvC,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,eAAe,CAA8B;IACrD,OAAO,CAAC,aAAa,CAAwB;gBAEjC,MAAM,EAAE,mBAAmB,EAAE,QAAQ,EAAE,QAAQ;IAU3D;;;;;;OAMG;IACH,OAAO,CAAC,oBAAoB;IAoB5B;;;;;;;OAOG;IACH,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE;IAS7C;;;;;;;;;;;;;;;OAeG;IACG,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA8BpD;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IAKjC;;;;OAIG;IACG,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAKjD;;;;OAIG;IACH,kBAAkB,IAAI,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC;IAIjD;;OAEG;IACH,UAAU,IAAI,IAAI;IAIlB;;;;OAIG;IACH,QAAQ,IAAI;QACV,UAAU,EAAE,MAAM,CAAC;QACnB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,mBAAmB,EAAE,MAAM,CAAC;KAC7B;CAcF"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory prefetcher for optimizing workflow execution.
|
|
3
|
+
*
|
|
4
|
+
* Analyzes workflow step dependencies and preloads data into hot memory
|
|
5
|
+
* before step execution to reduce latency.
|
|
6
|
+
*
|
|
7
|
+
* @module memory/prefetcher
|
|
8
|
+
* @since 2.0.0
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Memory prefetcher that analyzes workflow dependencies and preloads data.
|
|
12
|
+
*
|
|
13
|
+
* The prefetcher works by:
|
|
14
|
+
* 1. Analyzing which steps depend on outputs from previous steps
|
|
15
|
+
* 2. Before executing a step, promoting its dependencies to hot memory
|
|
16
|
+
* 3. Supporting manual prefetch hints for custom optimization
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const prefetcher = new MemoryPrefetcher(memory, workflow);
|
|
21
|
+
*
|
|
22
|
+
* // Before executing Step2, prefetch Step1's output
|
|
23
|
+
* await prefetcher.prefetchForStep("Step2");
|
|
24
|
+
*
|
|
25
|
+
* // Manual prefetch with custom keys
|
|
26
|
+
* await prefetcher.prefetch({
|
|
27
|
+
* stepId: "Step3",
|
|
28
|
+
* keys: ["stage:Step1", "stage:Step2"]
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @since 2.0.0
|
|
33
|
+
*/
|
|
34
|
+
export class MemoryPrefetcher {
|
|
35
|
+
memory;
|
|
36
|
+
workflow;
|
|
37
|
+
dependencyGraph;
|
|
38
|
+
prefetchHints;
|
|
39
|
+
constructor(memory, workflow) {
|
|
40
|
+
this.memory = memory;
|
|
41
|
+
this.workflow = workflow;
|
|
42
|
+
this.dependencyGraph = new Map();
|
|
43
|
+
this.prefetchHints = new Map();
|
|
44
|
+
// Build dependency graph on initialization
|
|
45
|
+
this.buildDependencyGraph();
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Build the dependency graph by analyzing workflow steps.
|
|
49
|
+
*
|
|
50
|
+
* This is a simple analysis - it assumes each step depends on all previous steps.
|
|
51
|
+
* More sophisticated analysis could inspect the buildPrompt() method to detect
|
|
52
|
+
* actual dependencies by checking for ctx.getOutput() calls.
|
|
53
|
+
*/
|
|
54
|
+
buildDependencyGraph() {
|
|
55
|
+
const steps = this.workflow.steps;
|
|
56
|
+
for (let i = 0; i < steps.length; i++) {
|
|
57
|
+
const step = steps[i];
|
|
58
|
+
const dependencies = new Set();
|
|
59
|
+
// Assume step depends on all previous steps
|
|
60
|
+
// (This is conservative but safe)
|
|
61
|
+
for (let j = 0; j < i; j++) {
|
|
62
|
+
dependencies.add(steps[j].id);
|
|
63
|
+
}
|
|
64
|
+
this.dependencyGraph.set(step.id, {
|
|
65
|
+
stepId: step.id,
|
|
66
|
+
dependencies,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Analyze dependencies for a specific step.
|
|
72
|
+
*
|
|
73
|
+
* Returns the set of step IDs that this step depends on.
|
|
74
|
+
*
|
|
75
|
+
* @param stepId - The step to analyze
|
|
76
|
+
* @returns Array of dependent step IDs
|
|
77
|
+
*/
|
|
78
|
+
analyzeDependencies(stepId) {
|
|
79
|
+
const node = this.dependencyGraph.get(stepId);
|
|
80
|
+
if (!node) {
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
return Array.from(node.dependencies);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Prefetch data for a specific step.
|
|
87
|
+
*
|
|
88
|
+
* Promotes all dependency outputs to hot memory before step execution.
|
|
89
|
+
* This is opportunistic - failures are logged but don't block execution.
|
|
90
|
+
*
|
|
91
|
+
* @param stepId - The step about to be executed
|
|
92
|
+
* @returns Promise that resolves when prefetch completes (or fails gracefully)
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* // Before executing Step2
|
|
97
|
+
* await prefetcher.prefetchForStep("Step2");
|
|
98
|
+
* // Now Step2 execution will find Step1 output in hot memory
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
async prefetchForStep(stepId) {
|
|
102
|
+
const dependencies = this.analyzeDependencies(stepId);
|
|
103
|
+
// Build list of keys to prefetch
|
|
104
|
+
const keysToFetch = [];
|
|
105
|
+
// Add dependency step outputs
|
|
106
|
+
for (const depId of dependencies) {
|
|
107
|
+
keysToFetch.push(`stage:${depId}`);
|
|
108
|
+
}
|
|
109
|
+
// Add manual hints if any
|
|
110
|
+
const hints = this.prefetchHints.get(stepId);
|
|
111
|
+
if (hints) {
|
|
112
|
+
keysToFetch.push(...hints);
|
|
113
|
+
}
|
|
114
|
+
// Prefetch all keys (opportunistically, don't fail on errors)
|
|
115
|
+
await Promise.allSettled(keysToFetch.map(async (key) => {
|
|
116
|
+
try {
|
|
117
|
+
await this.memory.promote(key);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
// Prefetch failure is not critical - log and continue
|
|
121
|
+
console.warn(`Prefetch failed for key "${key}":`, error);
|
|
122
|
+
}
|
|
123
|
+
}));
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Add a manual prefetch hint for a step.
|
|
127
|
+
*
|
|
128
|
+
* This allows developers to optimize specific steps by explicitly
|
|
129
|
+
* declaring what data they need.
|
|
130
|
+
*
|
|
131
|
+
* @param hint - Prefetch hint with step ID and keys
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* prefetcher.addHint({
|
|
136
|
+
* stepId: "AnalyzeCode",
|
|
137
|
+
* keys: ["stage:ReadFiles", "conversation:main"]
|
|
138
|
+
* });
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
addHint(hint) {
|
|
142
|
+
const existing = this.prefetchHints.get(hint.stepId) || [];
|
|
143
|
+
this.prefetchHints.set(hint.stepId, [...existing, ...hint.keys]);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Prefetch using a manual hint.
|
|
147
|
+
*
|
|
148
|
+
* @param hint - Prefetch hint with keys to load
|
|
149
|
+
*/
|
|
150
|
+
async prefetch(hint) {
|
|
151
|
+
this.addHint(hint);
|
|
152
|
+
await this.prefetchForStep(hint.stepId);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Get the dependency graph for debugging.
|
|
156
|
+
*
|
|
157
|
+
* @returns Map of step IDs to their dependency nodes
|
|
158
|
+
*/
|
|
159
|
+
getDependencyGraph() {
|
|
160
|
+
return new Map(this.dependencyGraph);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Clear all prefetch hints.
|
|
164
|
+
*/
|
|
165
|
+
clearHints() {
|
|
166
|
+
this.prefetchHints.clear();
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Get statistics about the dependency graph.
|
|
170
|
+
*
|
|
171
|
+
* @returns Stats about steps and dependencies
|
|
172
|
+
*/
|
|
173
|
+
getStats() {
|
|
174
|
+
const totalSteps = this.dependencyGraph.size;
|
|
175
|
+
let totalDependencies = 0;
|
|
176
|
+
for (const node of this.dependencyGraph.values()) {
|
|
177
|
+
totalDependencies += node.dependencies.size;
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
totalSteps,
|
|
181
|
+
totalDependencies,
|
|
182
|
+
averageDependencies: totalSteps > 0 ? totalDependencies / totalSteps : 0,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=prefetcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefetcher.js","sourceRoot":"","sources":["../../../src/memory/prefetcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAwBH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,OAAO,gBAAgB;IACnB,MAAM,CAAsB;IAC5B,QAAQ,CAAW;IACnB,eAAe,CAA8B;IAC7C,aAAa,CAAwB;IAE7C,YAAY,MAA2B,EAAE,QAAkB;QACzD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,eAAe,GAAG,IAAI,GAAG,EAAE,CAAC;QACjC,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,EAAE,CAAC;QAE/B,2CAA2C;QAC3C,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAC9B,CAAC;IAED;;;;;;OAMG;IACK,oBAAoB;QAC1B,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAElC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACtC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YACtB,MAAM,YAAY,GAAG,IAAI,GAAG,EAAU,CAAC;YAEvC,4CAA4C;YAC5C,kCAAkC;YAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,C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