noormme 1.0.6 → 1.2.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 +92 -63
- package/dist/cjs/agentic/ActionJournal.js +13 -9
- package/dist/cjs/agentic/CapabilityManager.d.ts +9 -4
- package/dist/cjs/agentic/CapabilityManager.js +113 -17
- package/dist/cjs/agentic/CognitiveRepository.js +19 -9
- package/dist/cjs/agentic/ContextBuffer.js +24 -12
- package/dist/cjs/agentic/Cortex.d.ts +8 -1
- package/dist/cjs/agentic/Cortex.js +30 -7
- package/dist/cjs/agentic/EpisodicMemory.js +7 -5
- package/dist/cjs/agentic/PersonaManager.js +16 -8
- package/dist/cjs/agentic/PolicyEnforcer.js +31 -12
- package/dist/cjs/agentic/ResourceMonitor.js +4 -4
- package/dist/cjs/agentic/SessionCompressor.js +22 -14
- package/dist/cjs/agentic/SessionManager.js +36 -18
- package/dist/cjs/agentic/VectorIndexer.js +22 -18
- package/dist/cjs/agentic/improvement/AblationEngine.js +22 -15
- package/dist/cjs/agentic/improvement/ActionRefiner.js +12 -10
- package/dist/cjs/agentic/improvement/ConflictResolver.js +5 -5
- package/dist/cjs/agentic/improvement/CortexJanitor.d.ts +1 -1
- package/dist/cjs/agentic/improvement/CortexJanitor.js +64 -27
- package/dist/cjs/agentic/improvement/CuriosityEngine.d.ts +2 -2
- package/dist/cjs/agentic/improvement/CuriosityEngine.js +68 -59
- package/dist/cjs/agentic/improvement/EvolutionRitual.d.ts +24 -0
- package/dist/cjs/agentic/improvement/EvolutionRitual.js +91 -0
- package/dist/cjs/agentic/improvement/EvolutionaryPilot.d.ts +5 -0
- package/dist/cjs/agentic/improvement/EvolutionaryPilot.js +80 -7
- package/dist/cjs/agentic/improvement/GoalArchitect.d.ts +2 -2
- package/dist/cjs/agentic/improvement/GoalArchitect.js +20 -18
- package/dist/cjs/agentic/improvement/GovernanceManager.d.ts +1 -1
- package/dist/cjs/agentic/improvement/GovernanceManager.js +85 -49
- package/dist/cjs/agentic/improvement/HiveLink.d.ts +9 -0
- package/dist/cjs/agentic/improvement/HiveLink.js +120 -26
- package/dist/cjs/agentic/improvement/KnowledgeDistiller.d.ts +2 -0
- package/dist/cjs/agentic/improvement/KnowledgeDistiller.js +101 -47
- package/dist/cjs/agentic/improvement/RecursiveReasoner.d.ts +7 -1
- package/dist/cjs/agentic/improvement/RecursiveReasoner.js +106 -22
- package/dist/cjs/agentic/improvement/ReflectionEngine.js +10 -8
- package/dist/cjs/agentic/improvement/RitualOrchestrator.js +34 -22
- package/dist/cjs/agentic/improvement/RuleEngine.js +22 -17
- package/dist/cjs/agentic/improvement/SelfEvolution.js +24 -18
- package/dist/cjs/agentic/improvement/SelfTestRegistry.js +18 -15
- package/dist/cjs/agentic/improvement/SkillSynthesizer.d.ts +48 -0
- package/dist/cjs/agentic/improvement/SkillSynthesizer.js +288 -0
- package/dist/cjs/agentic/improvement/SovereignMetrics.js +19 -17
- package/dist/cjs/agentic/improvement/StrategicPlanner.d.ts +1 -1
- package/dist/cjs/agentic/improvement/StrategicPlanner.js +129 -55
- package/dist/cjs/agentic/telemetry/CognitiveSynthesizer.js +26 -12
- package/dist/cjs/agentic/telemetry/EventHarvester.js +3 -2
- package/dist/cjs/agentic/telemetry/ResearchAlchemist.js +13 -4
- package/dist/cjs/cache/cache-manager.js +7 -4
- package/dist/cjs/cli/commands/analyze.js +5 -4
- package/dist/cjs/cli/commands/generate.js +81 -44
- package/dist/cjs/cli/commands/init.js +7 -3
- package/dist/cjs/cli/commands/inspect.js +139 -36
- package/dist/cjs/cli/commands/migrate.js +5 -4
- package/dist/cjs/cli/commands/optimize.js +4 -4
- package/dist/cjs/cli/commands/status.js +9 -7
- package/dist/cjs/cli/commands/watch.js +7 -6
- package/dist/cjs/cli/index.js +2 -2
- package/dist/cjs/cli/ui/spinner.d.ts +15 -0
- package/dist/cjs/cli/ui/spinner.js +76 -0
- package/dist/cjs/dialect/database-introspector.js +3 -1
- package/dist/cjs/dialect/postgresql/postgresql-driver.js +3 -1
- package/dist/cjs/dialect/postgresql/postgresql-features.js +18 -8
- package/dist/cjs/dialect/postgresql/postgresql-introspector.js +2 -2
- package/dist/cjs/dialect/sqlite/sqlite-auto-indexer.js +47 -33
- package/dist/cjs/dialect/sqlite/sqlite-auto-optimizer.js +8 -7
- package/dist/cjs/dialect/sqlite/sqlite-driver.js +2 -2
- package/dist/cjs/dialect/sqlite/sqlite-introspector.js +15 -12
- package/dist/cjs/edge-runtime/edge-config.js +21 -19
- package/dist/cjs/errors/NoormError.js +22 -20
- package/dist/cjs/helpers/agent-schema.js +3 -0
- package/dist/cjs/helpers/postgresql.js +7 -4
- package/dist/cjs/helpers/schema-evolution.js +31 -6
- package/dist/cjs/index.d.ts +18 -16
- package/dist/cjs/logging/logger.js +8 -4
- package/dist/cjs/migration/data_migrator.js +12 -11
- package/dist/cjs/migration/database_migration_manager.js +17 -13
- package/dist/cjs/migration/schema_differ.js +22 -14
- package/dist/cjs/migration/schema_introspector.js +8 -8
- package/dist/cjs/migration/type_mapper.js +68 -67
- package/dist/cjs/noormme.js +54 -37
- package/dist/cjs/performance/index.js +5 -5
- package/dist/cjs/performance/query-optimizer.js +26 -21
- package/dist/cjs/performance/services/cache-service.js +26 -16
- package/dist/cjs/performance/services/connection-factory.js +28 -23
- package/dist/cjs/performance/services/metrics-collector.js +41 -36
- package/dist/cjs/performance/utils/query-parser.js +15 -16
- package/dist/cjs/relationships/relationship-engine.js +10 -8
- package/dist/cjs/repository/repository-factory.js +97 -38
- package/dist/cjs/schema/core/coordinators/schema-discovery.coordinator.js +1 -3
- package/dist/cjs/schema/core/discovery/relationship-discovery.js +16 -16
- package/dist/cjs/schema/core/discovery/table-metadata-discovery.js +9 -9
- package/dist/cjs/schema/core/discovery/view-discovery.js +5 -4
- package/dist/cjs/schema/core/factories/discovery-factory.js +4 -4
- package/dist/cjs/schema/core/utils/name-generator.js +14 -5
- package/dist/cjs/schema/core/utils/type-mapper.js +24 -24
- package/dist/cjs/schema/dialects/postgresql/postgresql-discovery.coordinator.js +8 -7
- package/dist/cjs/schema/dialects/sqlite/discovery/sqlite-constraint-discovery.js +17 -15
- package/dist/cjs/schema/dialects/sqlite/discovery/sqlite-index-discovery.js +8 -8
- package/dist/cjs/schema/dialects/sqlite/introspection/sqlite-schema-introspector.js +6 -11
- package/dist/cjs/schema/dialects/sqlite/sqlite-discovery.coordinator.js +14 -13
- package/dist/cjs/schema/test/basic-schema-test.js +11 -9
- package/dist/cjs/schema/test/dialect-capabilities.test.js +6 -6
- package/dist/cjs/schema/test/discovery-factory.test.js +2 -2
- package/dist/cjs/schema/test/error-handling.test.js +8 -6
- package/dist/cjs/schema/test/integration.test.js +24 -18
- package/dist/cjs/schema/test/schema-discovery-coordinator.test.js +9 -9
- package/dist/cjs/schema/test/simple-schema-test.js +9 -9
- package/dist/cjs/schema/test/sqlite-discovery-coordinator.test.js +64 -48
- package/dist/cjs/schema/test/test-runner.js +3 -3
- package/dist/cjs/sqlite-migration/index.d.ts +2 -2
- package/dist/cjs/sqlite-migration/sqlite-migration-manager.js +21 -17
- package/dist/cjs/sqlite-migration/sqlite-migration-provider.js +38 -34
- package/dist/cjs/testing/test-utils.js +36 -34
- package/dist/cjs/types/index.d.ts +61 -4
- package/dist/cjs/types/index.js +6 -3
- package/dist/cjs/types/type-generator.js +46 -42
- package/dist/cjs/util/safe-sql-helpers.js +1 -1
- package/dist/cjs/util/security-validator.js +20 -9
- package/dist/cjs/utils/errorHelpers.js +20 -10
- package/dist/cjs/watch/schema-watcher.js +22 -23
- package/dist/esm/agentic/ActionJournal.js +13 -9
- package/dist/esm/agentic/CapabilityManager.d.ts +9 -4
- package/dist/esm/agentic/CapabilityManager.js +113 -17
- package/dist/esm/agentic/CognitiveRepository.js +19 -9
- package/dist/esm/agentic/ContextBuffer.js +24 -12
- package/dist/esm/agentic/Cortex.d.ts +8 -1
- package/dist/esm/agentic/Cortex.js +30 -7
- package/dist/esm/agentic/EpisodicMemory.js +7 -5
- package/dist/esm/agentic/PersonaManager.js +16 -8
- package/dist/esm/agentic/PolicyEnforcer.js +31 -12
- package/dist/esm/agentic/ResourceMonitor.js +4 -4
- package/dist/esm/agentic/SessionCompressor.js +22 -14
- package/dist/esm/agentic/SessionManager.js +36 -18
- package/dist/esm/agentic/VectorIndexer.js +22 -18
- package/dist/esm/agentic/improvement/AblationEngine.js +22 -15
- package/dist/esm/agentic/improvement/ActionRefiner.js +12 -10
- package/dist/esm/agentic/improvement/ConflictResolver.js +5 -5
- package/dist/esm/agentic/improvement/CortexJanitor.d.ts +1 -1
- package/dist/esm/agentic/improvement/CortexJanitor.js +64 -27
- package/dist/esm/agentic/improvement/CuriosityEngine.d.ts +2 -2
- package/dist/esm/agentic/improvement/CuriosityEngine.js +68 -59
- package/dist/esm/agentic/improvement/EvolutionRitual.d.ts +24 -0
- package/dist/esm/agentic/improvement/EvolutionRitual.js +88 -0
- package/dist/esm/agentic/improvement/EvolutionaryPilot.d.ts +5 -0
- package/dist/esm/agentic/improvement/EvolutionaryPilot.js +80 -7
- package/dist/esm/agentic/improvement/GoalArchitect.d.ts +2 -2
- package/dist/esm/agentic/improvement/GoalArchitect.js +20 -18
- package/dist/esm/agentic/improvement/GovernanceManager.d.ts +1 -1
- package/dist/esm/agentic/improvement/GovernanceManager.js +85 -49
- package/dist/esm/agentic/improvement/HiveLink.d.ts +9 -0
- package/dist/esm/agentic/improvement/HiveLink.js +120 -26
- package/dist/esm/agentic/improvement/KnowledgeDistiller.d.ts +2 -0
- package/dist/esm/agentic/improvement/KnowledgeDistiller.js +101 -47
- package/dist/esm/agentic/improvement/RecursiveReasoner.d.ts +7 -1
- package/dist/esm/agentic/improvement/RecursiveReasoner.js +106 -22
- package/dist/esm/agentic/improvement/ReflectionEngine.js +10 -8
- package/dist/esm/agentic/improvement/RitualOrchestrator.js +34 -22
- package/dist/esm/agentic/improvement/RuleEngine.js +22 -17
- package/dist/esm/agentic/improvement/SelfEvolution.js +24 -18
- package/dist/esm/agentic/improvement/SelfTestRegistry.js +18 -15
- package/dist/esm/agentic/improvement/SkillSynthesizer.d.ts +48 -0
- package/dist/esm/agentic/improvement/SkillSynthesizer.js +285 -0
- package/dist/esm/agentic/improvement/SovereignMetrics.js +19 -17
- package/dist/esm/agentic/improvement/StrategicPlanner.d.ts +1 -1
- package/dist/esm/agentic/improvement/StrategicPlanner.js +129 -55
- package/dist/esm/agentic/telemetry/CognitiveSynthesizer.js +26 -12
- package/dist/esm/agentic/telemetry/EventHarvester.js +3 -2
- package/dist/esm/agentic/telemetry/ResearchAlchemist.js +13 -4
- package/dist/esm/cache/cache-manager.js +7 -4
- package/dist/esm/cli/commands/analyze.js +5 -4
- package/dist/esm/cli/commands/generate.js +82 -45
- package/dist/esm/cli/commands/init.js +8 -4
- package/dist/esm/cli/commands/inspect.js +140 -37
- package/dist/esm/cli/commands/migrate.js +5 -4
- package/dist/esm/cli/commands/optimize.js +4 -4
- package/dist/esm/cli/commands/status.js +9 -7
- package/dist/esm/cli/commands/watch.js +7 -6
- package/dist/esm/cli/index.js +2 -2
- package/dist/esm/cli/ui/spinner.d.ts +15 -0
- package/dist/esm/cli/ui/spinner.js +70 -0
- package/dist/esm/dialect/database-introspector.js +3 -1
- package/dist/esm/dialect/postgresql/postgresql-driver.js +3 -1
- package/dist/esm/dialect/postgresql/postgresql-features.js +18 -8
- package/dist/esm/dialect/postgresql/postgresql-introspector.js +2 -2
- package/dist/esm/dialect/sqlite/sqlite-auto-indexer.js +47 -33
- package/dist/esm/dialect/sqlite/sqlite-auto-optimizer.js +8 -7
- package/dist/esm/dialect/sqlite/sqlite-driver.js +2 -2
- package/dist/esm/dialect/sqlite/sqlite-introspector.js +15 -12
- package/dist/esm/dynamic/dynamic.js +1 -1
- package/dist/esm/edge-runtime/edge-config.js +21 -19
- package/dist/esm/errors/NoormError.js +22 -20
- package/dist/esm/helpers/agent-schema.js +3 -0
- package/dist/esm/helpers/postgresql.js +7 -4
- package/dist/esm/helpers/schema-evolution.js +31 -6
- package/dist/esm/index.d.ts +18 -16
- package/dist/esm/index.js +2 -2
- package/dist/esm/logging/logger.js +8 -4
- package/dist/esm/migration/data_migrator.js +12 -11
- package/dist/esm/migration/database_migration_manager.js +18 -14
- package/dist/esm/migration/schema_differ.js +22 -14
- package/dist/esm/migration/schema_introspector.js +8 -8
- package/dist/esm/migration/type_mapper.js +68 -67
- package/dist/esm/noormme.js +54 -37
- package/dist/esm/performance/index.js +5 -5
- package/dist/esm/performance/query-optimizer.js +26 -21
- package/dist/esm/performance/services/cache-service.js +26 -16
- package/dist/esm/performance/services/connection-factory.js +28 -23
- package/dist/esm/performance/services/metrics-collector.js +41 -36
- package/dist/esm/performance/utils/query-parser.js +15 -16
- package/dist/esm/raw-builder/sql.js +1 -1
- package/dist/esm/relationships/relationship-engine.js +10 -8
- package/dist/esm/repository/repository-factory.js +98 -39
- package/dist/esm/schema/builders/alter-table-add-index-builder.js +1 -1
- package/dist/esm/schema/builders/create-index-builder.js +2 -2
- package/dist/esm/schema/core/coordinators/schema-discovery.coordinator.js +1 -3
- package/dist/esm/schema/core/discovery/relationship-discovery.js +16 -16
- package/dist/esm/schema/core/discovery/table-metadata-discovery.js +9 -9
- package/dist/esm/schema/core/discovery/view-discovery.js +5 -4
- package/dist/esm/schema/core/factories/discovery-factory.js +4 -4
- package/dist/esm/schema/core/utils/name-generator.js +14 -5
- package/dist/esm/schema/core/utils/type-mapper.js +24 -24
- package/dist/esm/schema/dialects/postgresql/postgresql-discovery.coordinator.js +8 -7
- package/dist/esm/schema/dialects/sqlite/discovery/sqlite-constraint-discovery.js +17 -15
- package/dist/esm/schema/dialects/sqlite/discovery/sqlite-index-discovery.js +8 -8
- package/dist/esm/schema/dialects/sqlite/introspection/sqlite-schema-introspector.js +6 -11
- package/dist/esm/schema/dialects/sqlite/sqlite-discovery.coordinator.js +14 -13
- package/dist/esm/schema/test/basic-schema-test.js +11 -9
- package/dist/esm/schema/test/dialect-capabilities.test.js +6 -6
- package/dist/esm/schema/test/discovery-factory.test.js +2 -2
- package/dist/esm/schema/test/error-handling.test.js +8 -6
- package/dist/esm/schema/test/integration.test.js +24 -18
- package/dist/esm/schema/test/schema-discovery-coordinator.test.js +9 -9
- package/dist/esm/schema/test/simple-schema-test.js +9 -9
- package/dist/esm/schema/test/sqlite-discovery-coordinator.test.js +64 -48
- package/dist/esm/schema/test/test-runner.js +3 -3
- package/dist/esm/sqlite-migration/index.d.ts +2 -2
- package/dist/esm/sqlite-migration/sqlite-migration-manager.js +21 -17
- package/dist/esm/sqlite-migration/sqlite-migration-provider.js +38 -34
- package/dist/esm/testing/test-utils.js +36 -34
- package/dist/esm/types/index.d.ts +61 -4
- package/dist/esm/types/index.js +6 -3
- package/dist/esm/types/type-generator.js +46 -42
- package/dist/esm/util/safe-sql-helpers.js +1 -1
- package/dist/esm/util/security-validator.js +20 -9
- package/dist/esm/utils/errorHelpers.js +21 -11
- package/dist/esm/watch/schema-watcher.js +22 -23
- package/package.json +40 -44
|
@@ -52,7 +52,7 @@ class ContextBuffer {
|
|
|
52
52
|
msg: m,
|
|
53
53
|
index,
|
|
54
54
|
isAnchor: !!m.metadata?.anchor,
|
|
55
|
-
tokens: this.estimateTokens(m.content)
|
|
55
|
+
tokens: this.estimateTokens(m.content),
|
|
56
56
|
}));
|
|
57
57
|
const sortedForSelection = [...scored].sort((a, b) => {
|
|
58
58
|
if (a.isAnchor !== b.isAnchor)
|
|
@@ -60,15 +60,18 @@ class ContextBuffer {
|
|
|
60
60
|
return b.index - a.index; // Recency tie-breaker
|
|
61
61
|
});
|
|
62
62
|
const selected = new Set();
|
|
63
|
-
let currentTokens = systemMessage
|
|
63
|
+
let currentTokens = systemMessage
|
|
64
|
+
? this.estimateTokens(systemMessage.content)
|
|
65
|
+
: 0;
|
|
64
66
|
for (const item of sortedForSelection) {
|
|
65
|
-
if (selected.size < effectiveLimit &&
|
|
67
|
+
if (selected.size < effectiveLimit &&
|
|
68
|
+
currentTokens + item.tokens <= tokenLimit) {
|
|
66
69
|
selected.add(item.msg);
|
|
67
70
|
currentTokens += item.tokens;
|
|
68
71
|
}
|
|
69
72
|
}
|
|
70
73
|
// Maintain temporal order
|
|
71
|
-
const result = this.messages.filter(m => m === systemMessage || selected.has(m));
|
|
74
|
+
const result = this.messages.filter((m) => m === systemMessage || selected.has(m));
|
|
72
75
|
return result;
|
|
73
76
|
}
|
|
74
77
|
/**
|
|
@@ -76,14 +79,14 @@ class ContextBuffer {
|
|
|
76
79
|
*/
|
|
77
80
|
toPromptString(limit) {
|
|
78
81
|
return this.getWindow({ maxMessages: limit })
|
|
79
|
-
.map(m => `[${m.role.toUpperCase()}]: ${m.content}`)
|
|
82
|
+
.map((m) => `[${m.role.toUpperCase()}]: ${m.content}`)
|
|
80
83
|
.join('\n\n');
|
|
81
84
|
}
|
|
82
85
|
/**
|
|
83
86
|
* Helper to identify if the buffer is becoming too large.
|
|
84
87
|
*/
|
|
85
88
|
shouldSummarize(tokenThreshold) {
|
|
86
|
-
const threshold = tokenThreshold ||
|
|
89
|
+
const threshold = tokenThreshold || this.maxTokens * 0.8;
|
|
87
90
|
return this.getTotalTokens() > threshold;
|
|
88
91
|
}
|
|
89
92
|
/**
|
|
@@ -94,7 +97,7 @@ class ContextBuffer {
|
|
|
94
97
|
messageCount: this.messages.length,
|
|
95
98
|
totalTokens: this.getTotalTokens(),
|
|
96
99
|
maxTokens: this.maxTokens,
|
|
97
|
-
maxMessages: this.maxMessages
|
|
100
|
+
maxMessages: this.maxMessages,
|
|
98
101
|
};
|
|
99
102
|
}
|
|
100
103
|
getTotalTokens() {
|
|
@@ -107,28 +110,37 @@ class ContextBuffer {
|
|
|
107
110
|
const initialCount = this.messages.length;
|
|
108
111
|
// Importance Trimming: Prefer keeping 'anchor' messages or high-priority messages
|
|
109
112
|
// We sort a copy to determine which ones to keep, then reconstruct in temporal order
|
|
110
|
-
const otherMessages = systemMessage
|
|
113
|
+
const otherMessages = systemMessage
|
|
114
|
+
? this.messages.slice(1)
|
|
115
|
+
: this.messages;
|
|
111
116
|
// Heuristic for importance: anchors > assistant > user (user input is often redundant if reflected/anchored)
|
|
112
117
|
const sortedByImportance = [...otherMessages].sort((a, b) => {
|
|
113
118
|
const aIsAnchor = a.metadata?.anchor ? 1 : 0;
|
|
114
119
|
const bIsAnchor = b.metadata?.anchor ? 1 : 0;
|
|
115
120
|
if (aIsAnchor !== bIsAnchor)
|
|
116
121
|
return bIsAnchor - aIsAnchor;
|
|
117
|
-
const rolePriority = {
|
|
122
|
+
const rolePriority = {
|
|
123
|
+
system: 3,
|
|
124
|
+
assistant: 2,
|
|
125
|
+
user: 1,
|
|
126
|
+
action: 2,
|
|
127
|
+
};
|
|
118
128
|
return (rolePriority[b.role] || 0) - (rolePriority[a.role] || 0);
|
|
119
129
|
});
|
|
120
130
|
const toKeep = new Set(sortedByImportance.slice(0, this.maxMessages));
|
|
121
|
-
this.messages = this.messages.filter(m => m === systemMessage || toKeep.has(m));
|
|
131
|
+
this.messages = this.messages.filter((m) => m === systemMessage || toKeep.has(m));
|
|
122
132
|
console.log(`[ContextBuffer] Importance Trimming: ${initialCount} -> ${this.messages.length} messages. preserved anchors and assistant reasoning.`);
|
|
123
133
|
}
|
|
124
134
|
}
|
|
125
135
|
estimateTokens(content) {
|
|
126
136
|
if (!content)
|
|
127
137
|
return 0;
|
|
128
|
-
// More sophisticated heuristic:
|
|
138
|
+
// More sophisticated heuristic:
|
|
129
139
|
// - JSON/Code tends to have more tokens per character due to symbols.
|
|
130
140
|
// - Natural language is ~4 chars per token.
|
|
131
|
-
const isStructured = content.startsWith('{') ||
|
|
141
|
+
const isStructured = content.startsWith('{') ||
|
|
142
|
+
content.startsWith('[') ||
|
|
143
|
+
content.includes('```');
|
|
132
144
|
const ratio = isStructured ? 3 : 4;
|
|
133
145
|
return Math.ceil(content.length / ratio);
|
|
134
146
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Kysely } from '../kysely.js';
|
|
2
|
-
import type { AgenticConfig, AgentMessage, NOORMConfig } from '../types/index.js';
|
|
2
|
+
import type { AgenticConfig, AgentMessage, NOORMConfig, LLMProvider } from '../types/index.js';
|
|
3
3
|
import { SessionManager } from './SessionManager.js';
|
|
4
4
|
import { ContextBuffer } from './ContextBuffer.js';
|
|
5
5
|
import { VectorIndexer } from './VectorIndexer.js';
|
|
@@ -29,6 +29,8 @@ import { StrategicPlanner } from './improvement/StrategicPlanner.js';
|
|
|
29
29
|
import { AblationEngine } from './improvement/AblationEngine.js';
|
|
30
30
|
import { SelfTestRegistry } from './improvement/SelfTestRegistry.js';
|
|
31
31
|
import { TelemetryOrchestrator } from './telemetry/TelemetryOrchestrator.js';
|
|
32
|
+
import { SkillSynthesizer } from './improvement/SkillSynthesizer.js';
|
|
33
|
+
import { EvolutionRitual } from './improvement/EvolutionRitual.js';
|
|
32
34
|
/**
|
|
33
35
|
* Cortex is the unified facade for agentic operations.
|
|
34
36
|
* It coordinates sessions, memory, reflection, and knowledge.
|
|
@@ -65,6 +67,11 @@ export declare class Cortex {
|
|
|
65
67
|
ablation: AblationEngine;
|
|
66
68
|
tests: SelfTestRegistry;
|
|
67
69
|
telemetry: TelemetryOrchestrator;
|
|
70
|
+
skillSynthesizer: SkillSynthesizer;
|
|
71
|
+
evolutionRitual: EvolutionRitual;
|
|
72
|
+
llm: LLMProvider | null;
|
|
73
|
+
llmFast: LLMProvider | null;
|
|
74
|
+
llmPremium: LLMProvider | null;
|
|
68
75
|
agenticConfig: AgenticConfig;
|
|
69
76
|
constructor(db: Kysely<any>, config: NOORMConfig);
|
|
70
77
|
/**
|
|
@@ -30,6 +30,8 @@ const StrategicPlanner_js_1 = require("./improvement/StrategicPlanner.js");
|
|
|
30
30
|
const AblationEngine_js_1 = require("./improvement/AblationEngine.js");
|
|
31
31
|
const SelfTestRegistry_js_1 = require("./improvement/SelfTestRegistry.js");
|
|
32
32
|
const TelemetryOrchestrator_js_1 = require("./telemetry/TelemetryOrchestrator.js");
|
|
33
|
+
const SkillSynthesizer_js_1 = require("./improvement/SkillSynthesizer.js");
|
|
34
|
+
const EvolutionRitual_js_1 = require("./improvement/EvolutionRitual.js");
|
|
33
35
|
/**
|
|
34
36
|
* Cortex is the unified facade for agentic operations.
|
|
35
37
|
* It coordinates sessions, memory, reflection, and knowledge.
|
|
@@ -66,15 +68,25 @@ class Cortex {
|
|
|
66
68
|
ablation;
|
|
67
69
|
tests;
|
|
68
70
|
telemetry;
|
|
71
|
+
skillSynthesizer;
|
|
72
|
+
evolutionRitual;
|
|
73
|
+
llm;
|
|
74
|
+
llmFast;
|
|
75
|
+
llmPremium;
|
|
69
76
|
agenticConfig;
|
|
70
77
|
constructor(db, config) {
|
|
71
78
|
this.db = db;
|
|
72
79
|
this.config = config;
|
|
73
80
|
const agenticConfig = config.agentic || {};
|
|
74
81
|
this.agenticConfig = agenticConfig;
|
|
82
|
+
this.llm = agenticConfig.llm || null;
|
|
83
|
+
this.llmFast = agenticConfig.llmFast || this.llm;
|
|
84
|
+
this.llmPremium = agenticConfig.llmPremium || this.llm;
|
|
75
85
|
this.telemetry = new TelemetryOrchestrator_js_1.TelemetryOrchestrator(db, agenticConfig);
|
|
76
86
|
this.sessions = new SessionManager_js_1.SessionManager(db, agenticConfig, this.telemetry);
|
|
77
|
-
this.buffer = new ContextBuffer_js_1.ContextBuffer({
|
|
87
|
+
this.buffer = new ContextBuffer_js_1.ContextBuffer({
|
|
88
|
+
maxMessages: agenticConfig.contextWindowSize,
|
|
89
|
+
});
|
|
78
90
|
this.vectors = agenticConfig.vectorConfig
|
|
79
91
|
? new VectorIndexer_js_1.VectorIndexer(db, agenticConfig.vectorConfig, agenticConfig.memoriesTable)
|
|
80
92
|
: null;
|
|
@@ -83,7 +95,7 @@ class Cortex {
|
|
|
83
95
|
this.actions = new ActionJournal_js_1.ActionJournal(db, agenticConfig, this.telemetry);
|
|
84
96
|
this.resources = new ResourceMonitor_js_1.ResourceMonitor(db, agenticConfig);
|
|
85
97
|
this.episodes = new EpisodicMemory_js_1.EpisodicMemory(db, agenticConfig);
|
|
86
|
-
this.capabilities = new CapabilityManager_js_1.CapabilityManager(db, agenticConfig);
|
|
98
|
+
this.capabilities = new CapabilityManager_js_1.CapabilityManager(db, this, agenticConfig);
|
|
87
99
|
this.policies = new PolicyEnforcer_js_1.PolicyEnforcer(db, agenticConfig);
|
|
88
100
|
this.metrics = new SovereignMetrics_js_1.SovereignMetrics(db, agenticConfig);
|
|
89
101
|
this.evolution = new SelfEvolution_js_1.SelfEvolution(db, config);
|
|
@@ -103,6 +115,8 @@ class Cortex {
|
|
|
103
115
|
this.strategy = new StrategicPlanner_js_1.StrategicPlanner(db, this, agenticConfig);
|
|
104
116
|
this.ablation = new AblationEngine_js_1.AblationEngine(db, this, agenticConfig);
|
|
105
117
|
this.tests = new SelfTestRegistry_js_1.SelfTestRegistry(db, this, agenticConfig);
|
|
118
|
+
this.skillSynthesizer = new SkillSynthesizer_js_1.SkillSynthesizer(db, this, agenticConfig);
|
|
119
|
+
this.evolutionRitual = new EvolutionRitual_js_1.EvolutionRitual(db, this, agenticConfig);
|
|
106
120
|
}
|
|
107
121
|
/**
|
|
108
122
|
* The "Soul-Searching" Loop: A top-level orchestration of all self-improvement rituals.
|
|
@@ -125,16 +139,22 @@ class Cortex {
|
|
|
125
139
|
await this.ablation.monitorAblationPerformance();
|
|
126
140
|
// 4. Mutation & Strategy
|
|
127
141
|
await this.strategy.mutateStrategy();
|
|
128
|
-
// 5.
|
|
142
|
+
// 5. High-Throughput Evolution Pulse
|
|
143
|
+
await this.evolutionRitual.execute();
|
|
144
|
+
// 6. Broadcast knowledge & skills
|
|
129
145
|
await this.hive.broadcastKnowledge();
|
|
130
|
-
//
|
|
146
|
+
// 6b. Emergent Skill Synthesis
|
|
147
|
+
await this.skillSynthesizer.discoverAndSynthesize();
|
|
148
|
+
// 7. Evolutionary pulse
|
|
131
149
|
await this.pilot.runSelfImprovementCycle();
|
|
132
150
|
console.log('[Cortex] Soul-Searching loop completed.');
|
|
133
151
|
}
|
|
134
152
|
catch (err) {
|
|
135
153
|
console.error('[Cortex] Soul-Searching loop failed:', err);
|
|
136
154
|
// Telemetry: track failure
|
|
137
|
-
await this.telemetry.track('system', 'error', 'Self-iteration failed', {
|
|
155
|
+
await this.telemetry.track('system', 'error', 'Self-iteration failed', {
|
|
156
|
+
error: String(err),
|
|
157
|
+
});
|
|
138
158
|
}
|
|
139
159
|
}
|
|
140
160
|
/**
|
|
@@ -151,8 +171,11 @@ class Cortex {
|
|
|
151
171
|
async recordInteraction(sessionId, role, content, options = {}) {
|
|
152
172
|
const message = await this.sessions.addMessage(sessionId, role, content);
|
|
153
173
|
// Telemetry: Track prompt and output
|
|
154
|
-
const type = role === 'user' ? 'prompt' :
|
|
155
|
-
await this.telemetry.track(sessionId, type, content, {
|
|
174
|
+
const type = role === 'user' ? 'prompt' : role === 'assistant' ? 'output' : 'action';
|
|
175
|
+
await this.telemetry.track(sessionId, type, content, {
|
|
176
|
+
role,
|
|
177
|
+
messageId: message.id,
|
|
178
|
+
});
|
|
156
179
|
if (options.index && options.embedding && this.vectors) {
|
|
157
180
|
await this.vectors.addMemory(content, options.embedding, sessionId);
|
|
158
181
|
}
|
|
@@ -28,7 +28,7 @@ class EpisodicMemory {
|
|
|
28
28
|
name,
|
|
29
29
|
status: 'active',
|
|
30
30
|
start_time: new Date(),
|
|
31
|
-
metadata: metadata ? JSON.stringify(metadata) : null
|
|
31
|
+
metadata: metadata ? JSON.stringify(metadata) : null,
|
|
32
32
|
})
|
|
33
33
|
.returningAll()
|
|
34
34
|
.executeTakeFirstOrThrow();
|
|
@@ -54,7 +54,7 @@ class EpisodicMemory {
|
|
|
54
54
|
status: 'completed',
|
|
55
55
|
summary,
|
|
56
56
|
end_time: new Date(),
|
|
57
|
-
metadata: JSON.stringify(newMeta)
|
|
57
|
+
metadata: JSON.stringify(newMeta),
|
|
58
58
|
})
|
|
59
59
|
.where('id', '=', episodeId)
|
|
60
60
|
.returningAll()
|
|
@@ -72,7 +72,7 @@ class EpisodicMemory {
|
|
|
72
72
|
.where('session_id', '=', sessionId)
|
|
73
73
|
.orderBy('start_time', 'desc')
|
|
74
74
|
.execute();
|
|
75
|
-
return list.map(e => this.parseEpisode(e));
|
|
75
|
+
return list.map((e) => this.parseEpisode(e));
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
78
|
* Get recently completed episodes across all sessions.
|
|
@@ -85,7 +85,7 @@ class EpisodicMemory {
|
|
|
85
85
|
.orderBy('end_time', 'desc')
|
|
86
86
|
.limit(limit)
|
|
87
87
|
.execute();
|
|
88
|
-
return list.map(e => this.parseEpisode(e));
|
|
88
|
+
return list.map((e) => this.parseEpisode(e));
|
|
89
89
|
}
|
|
90
90
|
parseEpisode(episode) {
|
|
91
91
|
return {
|
|
@@ -96,7 +96,9 @@ class EpisodicMemory {
|
|
|
96
96
|
status: episode.status,
|
|
97
97
|
startTime: new Date(episode.start_time),
|
|
98
98
|
endTime: episode.end_time ? new Date(episode.end_time) : undefined,
|
|
99
|
-
metadata: typeof episode.metadata === 'string'
|
|
99
|
+
metadata: typeof episode.metadata === 'string'
|
|
100
|
+
? JSON.parse(episode.metadata)
|
|
101
|
+
: episode.metadata || {},
|
|
100
102
|
};
|
|
101
103
|
}
|
|
102
104
|
}
|
|
@@ -28,10 +28,12 @@ class PersonaManager {
|
|
|
28
28
|
const values = {
|
|
29
29
|
name,
|
|
30
30
|
role: options.role || null,
|
|
31
|
-
capabilities: options.capabilities
|
|
31
|
+
capabilities: options.capabilities
|
|
32
|
+
? JSON.stringify(options.capabilities)
|
|
33
|
+
: null,
|
|
32
34
|
policies: options.policies ? JSON.stringify(options.policies) : null,
|
|
33
35
|
metadata: options.metadata ? JSON.stringify(options.metadata) : null,
|
|
34
|
-
updated_at: new Date()
|
|
36
|
+
updated_at: new Date(),
|
|
35
37
|
};
|
|
36
38
|
if (existing) {
|
|
37
39
|
const updated = await this.typedDb
|
|
@@ -46,7 +48,7 @@ class PersonaManager {
|
|
|
46
48
|
.insertInto(this.personasTable)
|
|
47
49
|
.values({
|
|
48
50
|
...values,
|
|
49
|
-
created_at: new Date()
|
|
51
|
+
created_at: new Date(),
|
|
50
52
|
})
|
|
51
53
|
.returningAll()
|
|
52
54
|
.executeTakeFirstOrThrow();
|
|
@@ -82,18 +84,24 @@ class PersonaManager {
|
|
|
82
84
|
.selectAll()
|
|
83
85
|
.orderBy('name', 'asc')
|
|
84
86
|
.execute();
|
|
85
|
-
return list.map(p => this.parsePersona(p));
|
|
87
|
+
return list.map((p) => this.parsePersona(p));
|
|
86
88
|
}
|
|
87
89
|
parsePersona(p) {
|
|
88
90
|
return {
|
|
89
91
|
id: p.id,
|
|
90
92
|
name: p.name,
|
|
91
93
|
role: p.role || undefined,
|
|
92
|
-
capabilities: typeof p.capabilities === 'string'
|
|
93
|
-
|
|
94
|
-
|
|
94
|
+
capabilities: typeof p.capabilities === 'string'
|
|
95
|
+
? JSON.parse(p.capabilities)
|
|
96
|
+
: p.capabilities || [],
|
|
97
|
+
policies: typeof p.policies === 'string'
|
|
98
|
+
? JSON.parse(p.policies)
|
|
99
|
+
: p.policies || [],
|
|
100
|
+
metadata: typeof p.metadata === 'string'
|
|
101
|
+
? JSON.parse(p.metadata)
|
|
102
|
+
: p.metadata || {},
|
|
95
103
|
createdAt: new Date(p.created_at),
|
|
96
|
-
updatedAt: new Date(p.updated_at)
|
|
104
|
+
updatedAt: new Date(p.updated_at),
|
|
97
105
|
};
|
|
98
106
|
}
|
|
99
107
|
}
|
|
@@ -36,7 +36,7 @@ class PolicyEnforcer {
|
|
|
36
36
|
type,
|
|
37
37
|
definition: JSON.stringify(definition),
|
|
38
38
|
is_enabled: isEnabled,
|
|
39
|
-
updated_at: new Date()
|
|
39
|
+
updated_at: new Date(),
|
|
40
40
|
})
|
|
41
41
|
.where('id', '=', existing.id)
|
|
42
42
|
.returningAll()
|
|
@@ -51,7 +51,7 @@ class PolicyEnforcer {
|
|
|
51
51
|
definition: JSON.stringify(definition),
|
|
52
52
|
is_enabled: isEnabled,
|
|
53
53
|
created_at: new Date(),
|
|
54
|
-
updated_at: new Date()
|
|
54
|
+
updated_at: new Date(),
|
|
55
55
|
})
|
|
56
56
|
.returningAll()
|
|
57
57
|
.executeTakeFirstOrThrow();
|
|
@@ -75,20 +75,32 @@ class PolicyEnforcer {
|
|
|
75
75
|
// 1. Threshold Check (Numeric)
|
|
76
76
|
if (typeof value === 'number') {
|
|
77
77
|
if (def.max !== undefined && value > def.max) {
|
|
78
|
-
return {
|
|
78
|
+
return {
|
|
79
|
+
allowed: false,
|
|
80
|
+
reason: `Value ${value} exceeds max ${def.max} for policy '${name}'`,
|
|
81
|
+
};
|
|
79
82
|
}
|
|
80
83
|
if (def.min !== undefined && value < def.min) {
|
|
81
|
-
return {
|
|
84
|
+
return {
|
|
85
|
+
allowed: false,
|
|
86
|
+
reason: `Value ${value} below min ${def.min} for policy '${name}'`,
|
|
87
|
+
};
|
|
82
88
|
}
|
|
83
89
|
}
|
|
84
90
|
// 2. Pattern Check (String/Regex)
|
|
85
91
|
if (typeof value === 'string' && def.pattern) {
|
|
86
92
|
const regex = new RegExp(def.pattern, 'i');
|
|
87
93
|
if (def.mustMatch && !regex.test(value)) {
|
|
88
|
-
return {
|
|
94
|
+
return {
|
|
95
|
+
allowed: false,
|
|
96
|
+
reason: `Value does not match required pattern for policy '${name}'`,
|
|
97
|
+
};
|
|
89
98
|
}
|
|
90
99
|
if (!def.mustMatch && regex.test(value)) {
|
|
91
|
-
return {
|
|
100
|
+
return {
|
|
101
|
+
allowed: false,
|
|
102
|
+
reason: `Value contains forbidden pattern for policy '${name}'`,
|
|
103
|
+
};
|
|
92
104
|
}
|
|
93
105
|
}
|
|
94
106
|
// 3. Budget Check (Cumulative)
|
|
@@ -97,7 +109,10 @@ class PolicyEnforcer {
|
|
|
97
109
|
const limit = def.limit || 0;
|
|
98
110
|
const total = await this.getCumulativeMetric(def.metricName, period);
|
|
99
111
|
if (total + (typeof value === 'number' ? value : 0) > limit) {
|
|
100
|
-
return {
|
|
112
|
+
return {
|
|
113
|
+
allowed: false,
|
|
114
|
+
reason: `Cumulative budget for '${def.metricName}' exceeded (${total.toFixed(4)} / ${limit})`,
|
|
115
|
+
};
|
|
101
116
|
}
|
|
102
117
|
}
|
|
103
118
|
return { allowed: true };
|
|
@@ -124,7 +139,7 @@ class PolicyEnforcer {
|
|
|
124
139
|
}
|
|
125
140
|
return {
|
|
126
141
|
allowed: violations.length === 0,
|
|
127
|
-
violations
|
|
142
|
+
violations,
|
|
128
143
|
};
|
|
129
144
|
}
|
|
130
145
|
/**
|
|
@@ -136,7 +151,7 @@ class PolicyEnforcer {
|
|
|
136
151
|
.selectAll()
|
|
137
152
|
.where('is_enabled', '=', true)
|
|
138
153
|
.execute();
|
|
139
|
-
return list.map(p => this.parsePolicy(p));
|
|
154
|
+
return list.map((p) => this.parsePolicy(p));
|
|
140
155
|
}
|
|
141
156
|
async getCumulativeMetric(metricName, period) {
|
|
142
157
|
let cutoff = new Date(0); // beginning of time
|
|
@@ -160,11 +175,15 @@ class PolicyEnforcer {
|
|
|
160
175
|
id: p.id,
|
|
161
176
|
name: p.name,
|
|
162
177
|
type: p.type,
|
|
163
|
-
definition: typeof p.definition === 'string'
|
|
178
|
+
definition: typeof p.definition === 'string'
|
|
179
|
+
? JSON.parse(p.definition)
|
|
180
|
+
: p.definition,
|
|
164
181
|
isEnabled: !!p.is_enabled,
|
|
165
|
-
metadata: typeof p.metadata === 'string'
|
|
182
|
+
metadata: typeof p.metadata === 'string'
|
|
183
|
+
? JSON.parse(p.metadata)
|
|
184
|
+
: p.metadata || {},
|
|
166
185
|
createdAt: new Date(p.created_at),
|
|
167
|
-
updatedAt: new Date(p.updated_at)
|
|
186
|
+
updatedAt: new Date(p.updated_at),
|
|
168
187
|
};
|
|
169
188
|
}
|
|
170
189
|
}
|
|
@@ -32,7 +32,7 @@ class ResourceMonitor {
|
|
|
32
32
|
cost: cost || 0,
|
|
33
33
|
currency: 'USD',
|
|
34
34
|
metadata: metadata ? JSON.stringify(metadata) : null,
|
|
35
|
-
created_at: new Date()
|
|
35
|
+
created_at: new Date(),
|
|
36
36
|
})
|
|
37
37
|
.returningAll()
|
|
38
38
|
.executeTakeFirstOrThrow();
|
|
@@ -68,14 +68,14 @@ class ResourceMonitor {
|
|
|
68
68
|
.select([
|
|
69
69
|
'model_name',
|
|
70
70
|
(eb) => eb.fn.sum((0, sql_js_1.sql) `input_tokens + output_tokens`).as('totalTokens'),
|
|
71
|
-
(eb) => eb.fn.sum('cost').as('totalCost')
|
|
71
|
+
(eb) => eb.fn.sum('cost').as('totalCost'),
|
|
72
72
|
])
|
|
73
73
|
.groupBy('model_name')
|
|
74
74
|
.execute();
|
|
75
75
|
return results.map((r) => ({
|
|
76
76
|
modelName: r.model_name,
|
|
77
77
|
totalTokens: Number(r.totalTokens),
|
|
78
|
-
totalCost: Number(r.totalCost)
|
|
78
|
+
totalCost: Number(r.totalCost),
|
|
79
79
|
}));
|
|
80
80
|
}
|
|
81
81
|
parseUsage(usage) {
|
|
@@ -88,7 +88,7 @@ class ResourceMonitor {
|
|
|
88
88
|
outputTokens: usage.output_tokens,
|
|
89
89
|
cost: usage.cost,
|
|
90
90
|
currency: usage.currency,
|
|
91
|
-
createdAt: new Date(usage.created_at)
|
|
91
|
+
createdAt: new Date(usage.created_at),
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
94
|
}
|
|
@@ -19,7 +19,7 @@ class SessionCompressor {
|
|
|
19
19
|
*/
|
|
20
20
|
async compress(sessionId, summary, startMessageId, endMessageId, anchors = [], metadata) {
|
|
21
21
|
console.log(`[SessionCompressor] Compressing session ${sessionId} with ${anchors.length} semantic anchors.`);
|
|
22
|
-
const epoch = await this.db
|
|
22
|
+
const epoch = (await this.db
|
|
23
23
|
.insertInto(this.epochsTable)
|
|
24
24
|
.values({
|
|
25
25
|
session_id: sessionId,
|
|
@@ -29,10 +29,10 @@ class SessionCompressor {
|
|
|
29
29
|
metadata: metadata || anchors.length > 0
|
|
30
30
|
? JSON.stringify({ ...metadata, anchors })
|
|
31
31
|
: null,
|
|
32
|
-
created_at: new Date()
|
|
32
|
+
created_at: new Date(),
|
|
33
33
|
})
|
|
34
34
|
.returningAll()
|
|
35
|
-
.executeTakeFirstOrThrow();
|
|
35
|
+
.executeTakeFirstOrThrow());
|
|
36
36
|
return this.parseEpoch(epoch);
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
@@ -51,8 +51,8 @@ class SessionCompressor {
|
|
|
51
51
|
eb('metadata', 'is', null),
|
|
52
52
|
eb.and([
|
|
53
53
|
eb('metadata', 'not like', '%"anchor":true%'),
|
|
54
|
-
eb('metadata', 'not like', '%"anchor": true%')
|
|
55
|
-
])
|
|
54
|
+
eb('metadata', 'not like', '%"anchor": true%'),
|
|
55
|
+
]),
|
|
56
56
|
]));
|
|
57
57
|
}
|
|
58
58
|
const result = await query.execute();
|
|
@@ -70,11 +70,15 @@ class SessionCompressor {
|
|
|
70
70
|
if (epochs.length > 10) {
|
|
71
71
|
console.log(`[SessionCompressor] Consolidating ${epochs.length} epochs into a new Era for session ${sessionId}`);
|
|
72
72
|
const summary = `Consolidated era summary of ${epochs.length} epochs: ` +
|
|
73
|
-
epochs
|
|
73
|
+
epochs
|
|
74
|
+
.slice(0, 5)
|
|
75
|
+
.map((e) => e.summary)
|
|
76
|
+
.join('; ') +
|
|
77
|
+
'...';
|
|
74
78
|
const eraMetadata = {
|
|
75
79
|
type: 'era',
|
|
76
80
|
original_epochs: epochs.length,
|
|
77
|
-
consolidated_at: new Date().toISOString()
|
|
81
|
+
consolidated_at: new Date().toISOString(),
|
|
78
82
|
};
|
|
79
83
|
// In this version, we mark the new epoch as an "Era" in metadata
|
|
80
84
|
const consolidatedEpoch = await this.compress(sessionId, summary, epochs[0].startMessageId, epochs[epochs.length - 1].endMessageId, [], eraMetadata);
|
|
@@ -87,12 +91,16 @@ class SessionCompressor {
|
|
|
87
91
|
session_id: sessionId,
|
|
88
92
|
role: 'system',
|
|
89
93
|
content: `[ERA SUMMARY] This era covers the initial phases of the session. Key takeaways: ${summary}`,
|
|
90
|
-
metadata: JSON.stringify({
|
|
91
|
-
|
|
94
|
+
metadata: JSON.stringify({
|
|
95
|
+
anchor: true,
|
|
96
|
+
type: 'era_reification',
|
|
97
|
+
epoch_id: consolidatedEpoch.id,
|
|
98
|
+
}),
|
|
99
|
+
created_at: new Date(),
|
|
92
100
|
})
|
|
93
101
|
.execute();
|
|
94
102
|
// Prune old epochs that were consolidated
|
|
95
|
-
const epochIds = epochs.map(e => e.id);
|
|
103
|
+
const epochIds = epochs.map((e) => e.id);
|
|
96
104
|
await this.db
|
|
97
105
|
.deleteFrom(this.epochsTable)
|
|
98
106
|
.where('id', 'in', epochIds)
|
|
@@ -103,13 +111,13 @@ class SessionCompressor {
|
|
|
103
111
|
* Get epochs for a session
|
|
104
112
|
*/
|
|
105
113
|
async getEpochs(sessionId) {
|
|
106
|
-
const list = await this.db
|
|
114
|
+
const list = (await this.db
|
|
107
115
|
.selectFrom(this.epochsTable)
|
|
108
116
|
.selectAll()
|
|
109
117
|
.where('session_id', '=', sessionId)
|
|
110
118
|
.orderBy('created_at', 'asc')
|
|
111
|
-
.execute();
|
|
112
|
-
return list.map(e => this.parseEpoch(e));
|
|
119
|
+
.execute());
|
|
120
|
+
return list.map((e) => this.parseEpoch(e));
|
|
113
121
|
}
|
|
114
122
|
parseEpoch(e) {
|
|
115
123
|
return {
|
|
@@ -118,7 +126,7 @@ class SessionCompressor {
|
|
|
118
126
|
startMessageId: e.start_message_id,
|
|
119
127
|
endMessageId: e.end_message_id,
|
|
120
128
|
metadata: typeof e.metadata === 'string' ? JSON.parse(e.metadata) : e.metadata,
|
|
121
|
-
createdAt: new Date(e.created_at)
|
|
129
|
+
createdAt: new Date(e.created_at),
|
|
122
130
|
};
|
|
123
131
|
}
|
|
124
132
|
}
|