@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,116 @@
|
|
|
1
|
+
import { HotMemoryConfig } from "./hot-memory.js";
|
|
2
|
+
import { WarmStorageConfig } from "./warm-storage.js";
|
|
3
|
+
import { ColdStorageConfig } from "./cold-storage.js";
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for tiered memory system.
|
|
6
|
+
*/
|
|
7
|
+
export interface TieredMemoryConfig {
|
|
8
|
+
hot?: HotMemoryConfig;
|
|
9
|
+
warm?: WarmStorageConfig;
|
|
10
|
+
cold?: ColdStorageConfig;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Statistics for the entire tiered memory system.
|
|
14
|
+
*/
|
|
15
|
+
export interface MemoryStats {
|
|
16
|
+
hot: {
|
|
17
|
+
itemCount: number;
|
|
18
|
+
estimatedSize: number;
|
|
19
|
+
hitCount: number;
|
|
20
|
+
missCount: number;
|
|
21
|
+
evictionCount: number;
|
|
22
|
+
};
|
|
23
|
+
warm: {
|
|
24
|
+
fileCount: number;
|
|
25
|
+
totalSize: number;
|
|
26
|
+
compressionRatio: number;
|
|
27
|
+
};
|
|
28
|
+
cold: {
|
|
29
|
+
fileCount: number;
|
|
30
|
+
totalSize: number;
|
|
31
|
+
};
|
|
32
|
+
promotions: number;
|
|
33
|
+
demotions: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Tiered memory manager coordinating hot/warm/cold storage.
|
|
37
|
+
* Automatically promotes frequently accessed data and demotes cold data.
|
|
38
|
+
*/
|
|
39
|
+
export declare class TieredMemoryManager {
|
|
40
|
+
private hot;
|
|
41
|
+
private warm;
|
|
42
|
+
private cold;
|
|
43
|
+
private pinnedKeys;
|
|
44
|
+
private accessPatterns;
|
|
45
|
+
private promotionCount;
|
|
46
|
+
private demotionCount;
|
|
47
|
+
private evictionQueue;
|
|
48
|
+
constructor(config?: TieredMemoryConfig);
|
|
49
|
+
/**
|
|
50
|
+
* Initialize storage layers.
|
|
51
|
+
*/
|
|
52
|
+
init(): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Get a value from tiered memory.
|
|
55
|
+
* Automatically promotes from cold → warm → hot on access.
|
|
56
|
+
*/
|
|
57
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
58
|
+
/**
|
|
59
|
+
* Set a value in tiered memory.
|
|
60
|
+
* Always starts in hot memory.
|
|
61
|
+
*/
|
|
62
|
+
set<T>(key: string, value: T): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Check if a key exists in any tier.
|
|
65
|
+
*/
|
|
66
|
+
has(key: string): Promise<boolean>;
|
|
67
|
+
/**
|
|
68
|
+
* Delete a value from all tiers.
|
|
69
|
+
*/
|
|
70
|
+
delete(key: string): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Pin a key to prevent eviction and ensure persistence.
|
|
73
|
+
* Pinned keys are always saved to cold storage.
|
|
74
|
+
*/
|
|
75
|
+
pin(key: string): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Unpin a key.
|
|
78
|
+
*/
|
|
79
|
+
unpin(key: string): void;
|
|
80
|
+
/**
|
|
81
|
+
* Manually promote a key to hot memory.
|
|
82
|
+
*/
|
|
83
|
+
promote(key: string): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Manually demote a key to cold storage.
|
|
86
|
+
*/
|
|
87
|
+
demote(key: string): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Get statistics for all tiers.
|
|
90
|
+
*/
|
|
91
|
+
stats(): Promise<MemoryStats>;
|
|
92
|
+
/**
|
|
93
|
+
* Clear all tiers.
|
|
94
|
+
*/
|
|
95
|
+
clear(): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Process queued evictions from hot memory.
|
|
98
|
+
* Move to warm storage unless pinned.
|
|
99
|
+
*/
|
|
100
|
+
private processEvictionQueue;
|
|
101
|
+
/**
|
|
102
|
+
* Update access pattern for a key.
|
|
103
|
+
*/
|
|
104
|
+
private updateAccessPattern;
|
|
105
|
+
/**
|
|
106
|
+
* Determine if a key should be promoted to hot memory.
|
|
107
|
+
* Promotes if accessed more than 2 times.
|
|
108
|
+
*/
|
|
109
|
+
private shouldPromoteToHot;
|
|
110
|
+
/**
|
|
111
|
+
* Determine if a key should be promoted to warm storage.
|
|
112
|
+
* Promotes if accessed at least once from cold.
|
|
113
|
+
*/
|
|
114
|
+
private shouldPromoteToWarm;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=tiered-memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tiered-memory.d.ts","sourceRoot":"","sources":["../../../src/memory/tiered-memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAe,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAe,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,GAAG,CAAC,EAAE,eAAe,CAAC;IACtB,IAAI,CAAC,EAAE,iBAAiB,CAAC;IACzB,IAAI,CAAC,EAAE,iBAAiB,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE;QACH,SAAS,EAAE,MAAM,C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AC,IAAI,CAAC;IAUrC;;OAEG;IACH,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAIxB;;OAEG;IACG,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAazC;;OAEG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASxC;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,WAAW,CAAC;IAcnC;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAU5B;;;OAGG;YACW,oBAAoB;IAelC;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAO3B;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IAK1B;;;OAGG;IACH,OAAO,CAAC,mBAAmB;CAI5B"}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { HotMemory } from "./hot-memory.js";
|
|
2
|
+
import { WarmStorage } from "./warm-storage.js";
|
|
3
|
+
import { ColdStorage } from "./cold-storage.js";
|
|
4
|
+
/**
|
|
5
|
+
* Tiered memory manager coordinating hot/warm/cold storage.
|
|
6
|
+
* Automatically promotes frequently accessed data and demotes cold data.
|
|
7
|
+
*/
|
|
8
|
+
export class TieredMemoryManager {
|
|
9
|
+
hot;
|
|
10
|
+
warm;
|
|
11
|
+
cold;
|
|
12
|
+
pinnedKeys = new Set();
|
|
13
|
+
accessPatterns = new Map();
|
|
14
|
+
promotionCount = 0;
|
|
15
|
+
demotionCount = 0;
|
|
16
|
+
evictionQueue = [];
|
|
17
|
+
constructor(config = {}) {
|
|
18
|
+
// Initialize hot memory with eviction callback
|
|
19
|
+
this.hot = new HotMemory({
|
|
20
|
+
...config.hot,
|
|
21
|
+
onEvict: (key, value) => {
|
|
22
|
+
// Queue evictions for async processing
|
|
23
|
+
this.evictionQueue.push({ key, value });
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
this.warm = new WarmStorage(config.warm);
|
|
27
|
+
this.cold = new ColdStorage(config.cold);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Initialize storage layers.
|
|
31
|
+
*/
|
|
32
|
+
async init() {
|
|
33
|
+
await this.warm.init();
|
|
34
|
+
await this.cold.init();
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get a value from tiered memory.
|
|
38
|
+
* Automatically promotes from cold → warm → hot on access.
|
|
39
|
+
*/
|
|
40
|
+
async get(key) {
|
|
41
|
+
// Update access pattern
|
|
42
|
+
this.updateAccessPattern(key);
|
|
43
|
+
// Try hot memory first
|
|
44
|
+
const hotValue = this.hot.get(key);
|
|
45
|
+
if (hotValue !== undefined) {
|
|
46
|
+
return hotValue;
|
|
47
|
+
}
|
|
48
|
+
// Try warm storage
|
|
49
|
+
const warmValue = await this.warm.get(key);
|
|
50
|
+
if (warmValue !== undefined) {
|
|
51
|
+
// Promote to hot if frequently accessed
|
|
52
|
+
if (this.shouldPromoteToHot(key)) {
|
|
53
|
+
this.hot.set(key, warmValue);
|
|
54
|
+
this.promotionCount++;
|
|
55
|
+
}
|
|
56
|
+
return warmValue;
|
|
57
|
+
}
|
|
58
|
+
// Try cold storage
|
|
59
|
+
const coldValue = await this.cold.get(key);
|
|
60
|
+
if (coldValue !== undefined) {
|
|
61
|
+
// Promote to warm if frequently accessed
|
|
62
|
+
if (this.shouldPromoteToWarm(key)) {
|
|
63
|
+
await this.warm.set(key, coldValue);
|
|
64
|
+
this.promotionCount++;
|
|
65
|
+
}
|
|
66
|
+
return coldValue;
|
|
67
|
+
}
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Set a value in tiered memory.
|
|
72
|
+
* Always starts in hot memory.
|
|
73
|
+
*/
|
|
74
|
+
async set(key, value) {
|
|
75
|
+
this.updateAccessPattern(key);
|
|
76
|
+
// Store in hot memory
|
|
77
|
+
this.hot.set(key, value);
|
|
78
|
+
// Process any queued evictions
|
|
79
|
+
await this.processEvictionQueue();
|
|
80
|
+
// If pinned, also save to cold immediately for persistence
|
|
81
|
+
if (this.pinnedKeys.has(key)) {
|
|
82
|
+
await this.cold.set(key, value);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Check if a key exists in any tier.
|
|
87
|
+
*/
|
|
88
|
+
async has(key) {
|
|
89
|
+
return (this.hot.has(key) ||
|
|
90
|
+
(await this.warm.has(key)) ||
|
|
91
|
+
(await this.cold.has(key)));
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Delete a value from all tiers.
|
|
95
|
+
*/
|
|
96
|
+
async delete(key) {
|
|
97
|
+
this.hot.delete(key);
|
|
98
|
+
await this.warm.delete(key);
|
|
99
|
+
await this.cold.delete(key);
|
|
100
|
+
this.accessPatterns.delete(key);
|
|
101
|
+
this.pinnedKeys.delete(key);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Pin a key to prevent eviction and ensure persistence.
|
|
105
|
+
* Pinned keys are always saved to cold storage.
|
|
106
|
+
*/
|
|
107
|
+
async pin(key) {
|
|
108
|
+
this.pinnedKeys.add(key);
|
|
109
|
+
// If key exists in hot, save to cold
|
|
110
|
+
const value = this.hot.get(key);
|
|
111
|
+
if (value !== undefined) {
|
|
112
|
+
await this.cold.set(key, value);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Unpin a key.
|
|
117
|
+
*/
|
|
118
|
+
unpin(key) {
|
|
119
|
+
this.pinnedKeys.delete(key);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Manually promote a key to hot memory.
|
|
123
|
+
*/
|
|
124
|
+
async promote(key) {
|
|
125
|
+
// Try to load from warm or cold
|
|
126
|
+
let value = await this.warm.get(key);
|
|
127
|
+
if (value === undefined) {
|
|
128
|
+
value = await this.cold.get(key);
|
|
129
|
+
}
|
|
130
|
+
if (value !== undefined) {
|
|
131
|
+
this.hot.set(key, value);
|
|
132
|
+
this.promotionCount++;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Manually demote a key to cold storage.
|
|
137
|
+
*/
|
|
138
|
+
async demote(key) {
|
|
139
|
+
const value = this.hot.get(key);
|
|
140
|
+
if (value !== undefined) {
|
|
141
|
+
await this.cold.set(key, value);
|
|
142
|
+
this.hot.delete(key);
|
|
143
|
+
this.demotionCount++;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Get statistics for all tiers.
|
|
148
|
+
*/
|
|
149
|
+
async stats() {
|
|
150
|
+
const hotStats = this.hot.stats();
|
|
151
|
+
const warmStats = await this.warm.stats();
|
|
152
|
+
const coldStats = await this.cold.stats();
|
|
153
|
+
return {
|
|
154
|
+
hot: hotStats,
|
|
155
|
+
warm: warmStats,
|
|
156
|
+
cold: coldStats,
|
|
157
|
+
promotions: this.promotionCount,
|
|
158
|
+
demotions: this.demotionCount,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Clear all tiers.
|
|
163
|
+
*/
|
|
164
|
+
async clear() {
|
|
165
|
+
this.hot.clear();
|
|
166
|
+
await this.warm.clear();
|
|
167
|
+
await this.cold.clear();
|
|
168
|
+
this.accessPatterns.clear();
|
|
169
|
+
this.pinnedKeys.clear();
|
|
170
|
+
this.promotionCount = 0;
|
|
171
|
+
this.demotionCount = 0;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Process queued evictions from hot memory.
|
|
175
|
+
* Move to warm storage unless pinned.
|
|
176
|
+
*/
|
|
177
|
+
async processEvictionQueue() {
|
|
178
|
+
while (this.evictionQueue.length > 0) {
|
|
179
|
+
const { key, value } = this.evictionQueue.shift();
|
|
180
|
+
// Don't demote pinned keys (they're already in cold)
|
|
181
|
+
if (this.pinnedKeys.has(key)) {
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
// Move to warm storage
|
|
185
|
+
await this.warm.set(key, value);
|
|
186
|
+
this.demotionCount++;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Update access pattern for a key.
|
|
191
|
+
*/
|
|
192
|
+
updateAccessPattern(key) {
|
|
193
|
+
const pattern = this.accessPatterns.get(key) ?? { count: 0, lastAccess: 0 };
|
|
194
|
+
pattern.count++;
|
|
195
|
+
pattern.lastAccess = Date.now();
|
|
196
|
+
this.accessPatterns.set(key, pattern);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Determine if a key should be promoted to hot memory.
|
|
200
|
+
* Promotes if accessed more than 2 times.
|
|
201
|
+
*/
|
|
202
|
+
shouldPromoteToHot(key) {
|
|
203
|
+
const pattern = this.accessPatterns.get(key);
|
|
204
|
+
return pattern !== undefined && pattern.count > 2;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Determine if a key should be promoted to warm storage.
|
|
208
|
+
* Promotes if accessed at least once from cold.
|
|
209
|
+
*/
|
|
210
|
+
shouldPromoteToWarm(key) {
|
|
211
|
+
const pattern = this.accessPatterns.get(key);
|
|
212
|
+
return pattern !== undefined && pattern.count > 0;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=tiered-memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tiered-memory.js","sourceRoot":"","sources":["../../../src/memory/tiered-memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAmB,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAqB,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,WAAW,EAAqB,MAAM,mBAAmB,CAAC;AA2CnE;;;GAGG;AACH,MAAM,OAAO,mBAAmB;IACtB,GAAG,CAAY;IACf,IAAI,CAAc;IAClB,IAAI,CAAc;IAClB,UAAU,GAAgB,IAAI,GAAG,EAAE,CAAC;IACpC,cAAc,GAA+B,IAAI,GAAG,EAAE,CAAC;IACvD,cAAc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AAC,KAAK,GAAG,CAAC,CAAC;IACpD,CAAC;CACF"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { type CompressionAlgorithm } from "./compression.js";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for warm storage (compressed disk cache).
|
|
4
|
+
*/
|
|
5
|
+
export interface WarmStorageConfig {
|
|
6
|
+
/** Directory for warm cache files (default: .deity/cache) */
|
|
7
|
+
directory?: string;
|
|
8
|
+
/** Maximum total size in bytes (default: 1GB) */
|
|
9
|
+
maxSize?: number;
|
|
10
|
+
/** Compression algorithm to use (default: gzip) */
|
|
11
|
+
compressionAlgorithm?: CompressionAlgorithm;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Statistics for warm storage usage.
|
|
15
|
+
*/
|
|
16
|
+
export interface WarmStorageStats {
|
|
17
|
+
fileCount: number;
|
|
18
|
+
totalSize: number;
|
|
19
|
+
compressionRatio: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Warm storage layer using compressed JSON files on disk.
|
|
23
|
+
* Automatically cleans up oldest files when size limit is exceeded.
|
|
24
|
+
*/
|
|
25
|
+
export declare class WarmStorage {
|
|
26
|
+
private config;
|
|
27
|
+
private sizeCache;
|
|
28
|
+
private accessTimes;
|
|
29
|
+
private compressor;
|
|
30
|
+
constructor(config?: WarmStorageConfig);
|
|
31
|
+
/**
|
|
32
|
+
* Initialize warm storage directory.
|
|
33
|
+
*/
|
|
34
|
+
init(): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Get a value from warm storage.
|
|
37
|
+
* Returns undefined if not found.
|
|
38
|
+
*/
|
|
39
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
40
|
+
/**
|
|
41
|
+
* Set a value in warm storage.
|
|
42
|
+
* May trigger cleanup if size limit is exceeded.
|
|
43
|
+
*/
|
|
44
|
+
set<T>(key: string, value: T): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Check if a key exists in warm storage.
|
|
47
|
+
*/
|
|
48
|
+
has(key: string): Promise<boolean>;
|
|
49
|
+
/**
|
|
50
|
+
* Delete a value from warm storage.
|
|
51
|
+
*/
|
|
52
|
+
delete(key: string): Promise<boolean>;
|
|
53
|
+
/**
|
|
54
|
+
* Clear all files from warm storage.
|
|
55
|
+
*/
|
|
56
|
+
clear(): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Get statistics about warm storage usage.
|
|
59
|
+
*/
|
|
60
|
+
stats(): Promise<WarmStorageStats>;
|
|
61
|
+
/**
|
|
62
|
+
* Get file path for a key.
|
|
63
|
+
*/
|
|
64
|
+
private getFilePath;
|
|
65
|
+
/**
|
|
66
|
+
* Update size cache by scanning directory.
|
|
67
|
+
*/
|
|
68
|
+
private updateSizeCache;
|
|
69
|
+
/**
|
|
70
|
+
* Cleanup oldest files if over size limit.
|
|
71
|
+
*/
|
|
72
|
+
private cleanup;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=warm-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"warm-storage.d.ts","sourceRoot":"","sources":["../../../src/memory/warm-storage.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,oBAAoB,EAC1B,MAAM,kBAAkB,CAAC;AAE1B;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,6DAA6D;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mDAAmD;IACnD,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;CAC7C;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED;;;GAGG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAA8B;IAC5C,OAAO,CAAC,SAAS,CAAkC;IACnD,OAAO,CAAC,WAAW,CAAkC;IACrD,OAAO,CAAC,UAAU,CAAqB;gBAE3B,MAAM,GAAE,iBAAsB;IAW1C;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAK3B;;;OAGG;IACG,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAmBjD;;;OAGG;IACG,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAwBlD;;OAEG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAUxC;;OAEG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAa3C;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAW5B;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,gBAAgB,CAAC;IA+BxC;;OAEG;IACH,OAAO,CAAC,WAAW;IAuBnB;;OAEG;YACW,eAAe;IAsB7B;;OAEG;YACW,OAAO;CA2BtB"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { promises as fs } from "node:fs";
|
|
2
|
+
import { join, dirname } from "node:path";
|
|
3
|
+
import { createCompressionAdapter, } from "./compression.js";
|
|
4
|
+
/**
|
|
5
|
+
* Warm storage layer using compressed JSON files on disk.
|
|
6
|
+
* Automatically cleans up oldest files when size limit is exceeded.
|
|
7
|
+
*/
|
|
8
|
+
export class WarmStorage {
|
|
9
|
+
config;
|
|
10
|
+
sizeCache = new Map();
|
|
11
|
+
accessTimes = new Map();
|
|
12
|
+
compressor;
|
|
13
|
+
constructor(config = {}) {
|
|
14
|
+
this.config = {
|
|
15
|
+
directory: config.directory ?? join(process.cwd(), ".deity", "cache"),
|
|
16
|
+
maxSize: config.maxSize ?? 1024 * 1024 * 1024, // 1GB
|
|
17
|
+
compressionAlgorithm: config.compressionAlgorithm ?? "gzip",
|
|
18
|
+
};
|
|
19
|
+
// Initialize compression adapter
|
|
20
|
+
this.compressor = createCompressionAdapter(this.config.compressionAlgorithm);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Initialize warm storage directory.
|
|
24
|
+
*/
|
|
25
|
+
async init() {
|
|
26
|
+
await fs.mkdir(this.config.directory, { recursive: true });
|
|
27
|
+
await this.updateSizeCache();
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get a value from warm storage.
|
|
31
|
+
* Returns undefined if not found.
|
|
32
|
+
*/
|
|
33
|
+
async get(key) {
|
|
34
|
+
const filePath = this.getFilePath(key);
|
|
35
|
+
try {
|
|
36
|
+
const compressed = await fs.readFile(filePath);
|
|
37
|
+
const decompressed = await this.compressor.decompress(compressed);
|
|
38
|
+
const json = decompressed.toString("utf-8");
|
|
39
|
+
const value = JSON.parse(json);
|
|
40
|
+
// Update access time for LRU tracking
|
|
41
|
+
this.accessTimes.set(key, Date.now());
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
// File doesn't exist or is corrupted
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Set a value in warm storage.
|
|
51
|
+
* May trigger cleanup if size limit is exceeded.
|
|
52
|
+
*/
|
|
53
|
+
async set(key, value) {
|
|
54
|
+
const filePath = this.getFilePath(key);
|
|
55
|
+
// Ensure directory exists
|
|
56
|
+
await fs.mkdir(dirname(filePath), { recursive: true });
|
|
57
|
+
// Compress and write
|
|
58
|
+
const json = JSON.stringify(value);
|
|
59
|
+
const compressed = await this.compressor.compress(Buffer.from(json, "utf-8"));
|
|
60
|
+
// Write atomically (write to temp file, then rename)
|
|
61
|
+
const tempPath = `${filePath}.tmp`;
|
|
62
|
+
await fs.writeFile(tempPath, compressed);
|
|
63
|
+
await fs.rename(tempPath, filePath);
|
|
64
|
+
// Update tracking
|
|
65
|
+
const size = compressed.length;
|
|
66
|
+
this.sizeCache.set(key, size);
|
|
67
|
+
this.accessTimes.set(key, Date.now());
|
|
68
|
+
// Cleanup if over size limit
|
|
69
|
+
await this.cleanup();
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Check if a key exists in warm storage.
|
|
73
|
+
*/
|
|
74
|
+
async has(key) {
|
|
75
|
+
const filePath = this.getFilePath(key);
|
|
76
|
+
try {
|
|
77
|
+
await fs.access(filePath);
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Delete a value from warm storage.
|
|
86
|
+
*/
|
|
87
|
+
async delete(key) {
|
|
88
|
+
const filePath = this.getFilePath(key);
|
|
89
|
+
try {
|
|
90
|
+
await fs.unlink(filePath);
|
|
91
|
+
this.sizeCache.delete(key);
|
|
92
|
+
this.accessTimes.delete(key);
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Clear all files from warm storage.
|
|
101
|
+
*/
|
|
102
|
+
async clear() {
|
|
103
|
+
try {
|
|
104
|
+
await fs.rm(this.config.directory, { recursive: true, force: true });
|
|
105
|
+
await fs.mkdir(this.config.directory, { recursive: true });
|
|
106
|
+
this.sizeCache.clear();
|
|
107
|
+
this.accessTimes.clear();
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
// Directory might not exist yet
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Get statistics about warm storage usage.
|
|
115
|
+
*/
|
|
116
|
+
async stats() {
|
|
117
|
+
await this.updateSizeCache();
|
|
118
|
+
const totalSize = Array.from(this.sizeCache.values()).reduce((sum, size) => sum + size, 0);
|
|
119
|
+
// Calculate average compression ratio
|
|
120
|
+
let totalOriginal = 0;
|
|
121
|
+
let totalCompressed = 0;
|
|
122
|
+
for (const [key, compressedSize] of this.sizeCache) {
|
|
123
|
+
const value = await this.get(key);
|
|
124
|
+
if (value !== undefined) {
|
|
125
|
+
const originalSize = JSON.stringify(value).length * 2; // UTF-16
|
|
126
|
+
totalOriginal += originalSize;
|
|
127
|
+
totalCompressed += compressedSize;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const compressionRatio = totalCompressed > 0 ? totalOriginal / totalCompressed : 1;
|
|
131
|
+
return {
|
|
132
|
+
fileCount: this.sizeCache.size,
|
|
133
|
+
totalSize,
|
|
134
|
+
compressionRatio,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Get file path for a key.
|
|
139
|
+
*/
|
|
140
|
+
getFilePath(key) {
|
|
141
|
+
// Sanitize key to be filesystem-safe
|
|
142
|
+
const safeKey = key.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
143
|
+
// Choose extension based on compression algorithm
|
|
144
|
+
let extension;
|
|
145
|
+
switch (this.config.compressionAlgorithm) {
|
|
146
|
+
case "gzip":
|
|
147
|
+
extension = ".json.gz";
|
|
148
|
+
break;
|
|
149
|
+
case "lz4":
|
|
150
|
+
extension = ".json.lz4";
|
|
151
|
+
break;
|
|
152
|
+
case "none":
|
|
153
|
+
extension = ".json";
|
|
154
|
+
break;
|
|
155
|
+
default:
|
|
156
|
+
extension = ".json.gz"; // fallback
|
|
157
|
+
}
|
|
158
|
+
return join(this.config.directory, `${safeKey}${extension}`);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Update size cache by scanning directory.
|
|
162
|
+
*/
|
|
163
|
+
async updateSizeCache() {
|
|
164
|
+
try {
|
|
165
|
+
const files = await fs.readdir(this.config.directory);
|
|
166
|
+
// Determine which extensions to scan based on compression
|
|
167
|
+
const extensions = [".json.gz", ".json.lz4", ".json"];
|
|
168
|
+
for (const file of files) {
|
|
169
|
+
// Check if file matches any extension
|
|
170
|
+
const matchingExt = extensions.find((ext) => file.endsWith(ext));
|
|
171
|
+
if (matchingExt) {
|
|
172
|
+
const filePath = join(this.config.directory, file);
|
|
173
|
+
const stat = await fs.stat(filePath);
|
|
174
|
+
const key = file.replace(matchingExt, "");
|
|
175
|
+
this.sizeCache.set(key, stat.size);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
// Directory might not exist yet
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Cleanup oldest files if over size limit.
|
|
185
|
+
*/
|
|
186
|
+
async cleanup() {
|
|
187
|
+
const totalSize = Array.from(this.sizeCache.values()).reduce((sum, size) => sum + size, 0);
|
|
188
|
+
if (totalSize <= this.config.maxSize) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
// Sort keys by access time (oldest first)
|
|
192
|
+
const sortedKeys = Array.from(this.accessTimes.entries())
|
|
193
|
+
.sort((a, b) => a[1] - b[1])
|
|
194
|
+
.map(([key]) => key);
|
|
195
|
+
// Delete oldest files until under limit
|
|
196
|
+
let currentSize = totalSize;
|
|
197
|
+
for (const key of sortedKeys) {
|
|
198
|
+
if (currentSize <= this.config.maxSize) {
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
const size = this.sizeCache.get(key) ?? 0;
|
|
202
|
+
await this.delete(key);
|
|
203
|
+
currentSize -= size;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=warm-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"warm-storage.js","sourceRoot":"","sources":["../../../src/memory/warm-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1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IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAC1D,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,EACzB,CAAC,CACF,CAAC;QAEF,IAAI,SAAS,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACrC,OAAO;QACT,CAAC;QAED,0CAA0C;QAC1C,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;aACtD,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;aAC3B,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;QAEvB,wCAAwC;QACxC,IAAI,WAAW,GAAG,SAAS,CAAC;QAC5B,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;YAC7B,IAAI,WAAW,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACvC,MAAM;YACR,CAAC;YAED,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC1C,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACvB,WAAW,IAAI,IAAI,CAAC;QACtB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Message } from "./component.js";
|
|
2
|
+
import type { LLMAdapter, LLMResponse, GenerationConfig } from "./llm.js";
|
|
3
|
+
import type { Tool } from "./tool.js";
|
|
4
|
+
export interface OpenAIAdapterConfig {
|
|
5
|
+
apiKey: string;
|
|
6
|
+
model?: string;
|
|
7
|
+
baseURL?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* OpenAI-compatible LLM adapter.
|
|
11
|
+
* Works with OpenAI API and compatible endpoints (Azure, local proxies).
|
|
12
|
+
*/
|
|
13
|
+
export declare class OpenAIAdapter implements LLMAdapter {
|
|
14
|
+
private apiKey;
|
|
15
|
+
private model;
|
|
16
|
+
private baseURL;
|
|
17
|
+
constructor(config: OpenAIAdapterConfig);
|
|
18
|
+
generate(messages: Message[], tools?: Tool[], config?: GenerationConfig): Promise<LLMResponse>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=openai-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai-adapter.d.ts","sourceRoot":"","sources":["../../src/openai-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,gBAAgB,EAAY,MAAM,UAAU,CAAC;AACpF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGtC,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,qBAAa,aAAc,YAAW,UAAU;IAC9C,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,EAAE,mBAAmB;IAMjC,QAAQ,CACZ,QAAQ,EAAE,OAAO,EAAE,EACnB,KAAK,CAAC,EAAE,IAAI,EAAE,EACd,MAAM,CAAC,EAAE,gBAAgB,GACxB,OAAO,CAAC,WAAW,CAAC;CAgFxB"}
|