@illuma-ai/agents 1.1.25 → 1.3.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/dist/cjs/agents/AgentContext.cjs +20 -3
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/common/spawnPath.cjs +104 -0
- package/dist/cjs/common/spawnPath.cjs.map +1 -0
- package/dist/cjs/graphs/Graph.cjs +87 -31
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/HandoffRegistry.cjs +143 -0
- package/dist/cjs/graphs/HandoffRegistry.cjs.map +1 -0
- package/dist/cjs/graphs/MultiAgentGraph.cjs +587 -184
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/graphs/phases/flushLoop.cjs +214 -0
- package/dist/cjs/graphs/phases/flushLoop.cjs.map +1 -0
- package/dist/cjs/graphs/phases/memoryFlushPhase.cjs +102 -0
- package/dist/cjs/graphs/phases/memoryFlushPhase.cjs.map +1 -0
- package/dist/cjs/llm/bedrock/index.cjs +4 -3
- package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
- package/dist/cjs/main.cjs +115 -0
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/memory/citations.cjs +69 -0
- package/dist/cjs/memory/citations.cjs.map +1 -0
- package/dist/cjs/memory/compositeBackend.cjs +60 -0
- package/dist/cjs/memory/compositeBackend.cjs.map +1 -0
- package/dist/cjs/memory/constants.cjs +232 -0
- package/dist/cjs/memory/constants.cjs.map +1 -0
- package/dist/cjs/memory/embeddings.cjs +151 -0
- package/dist/cjs/memory/embeddings.cjs.map +1 -0
- package/dist/cjs/memory/factory.cjs +95 -0
- package/dist/cjs/memory/factory.cjs.map +1 -0
- package/dist/cjs/memory/migrate.cjs +81 -0
- package/dist/cjs/memory/migrate.cjs.map +1 -0
- package/dist/cjs/memory/mmr.cjs +138 -0
- package/dist/cjs/memory/mmr.cjs.map +1 -0
- package/dist/cjs/memory/paths.cjs +217 -0
- package/dist/cjs/memory/paths.cjs.map +1 -0
- package/dist/cjs/memory/pgvectorStore.cjs +225 -0
- package/dist/cjs/memory/pgvectorStore.cjs.map +1 -0
- package/dist/cjs/memory/recallTracking.cjs +98 -0
- package/dist/cjs/memory/recallTracking.cjs.map +1 -0
- package/dist/cjs/memory/schema.sql +51 -0
- package/dist/cjs/memory/temporalDecay.cjs +118 -0
- package/dist/cjs/memory/temporalDecay.cjs.map +1 -0
- package/dist/cjs/nodes/ApprovalGateNode.cjs +1 -1
- package/dist/cjs/nodes/ApprovalGateNode.cjs.map +1 -1
- package/dist/cjs/prompts/memoryFlushPrompt.cjs +49 -0
- package/dist/cjs/prompts/memoryFlushPrompt.cjs.map +1 -0
- package/dist/cjs/run.cjs +16 -3
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/stream.cjs +4 -4
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/tools/AskUser.cjs +6 -1
- package/dist/cjs/tools/AskUser.cjs.map +1 -1
- package/dist/cjs/tools/BrowserTools.cjs +1 -1
- package/dist/cjs/tools/BrowserTools.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +127 -10
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/approval/constants.cjs +2 -2
- package/dist/cjs/tools/approval/constants.cjs.map +1 -1
- package/dist/cjs/tools/memory/index.cjs +58 -0
- package/dist/cjs/tools/memory/index.cjs.map +1 -0
- package/dist/cjs/tools/memory/memoryAppendTool.cjs +69 -0
- package/dist/cjs/tools/memory/memoryAppendTool.cjs.map +1 -0
- package/dist/cjs/tools/memory/memoryGetTool.cjs +49 -0
- package/dist/cjs/tools/memory/memoryGetTool.cjs.map +1 -0
- package/dist/cjs/tools/memory/memorySearchTool.cjs +65 -0
- package/dist/cjs/tools/memory/memorySearchTool.cjs.map +1 -0
- package/dist/cjs/tools/memory/shared.cjs +106 -0
- package/dist/cjs/tools/memory/shared.cjs.map +1 -0
- package/dist/cjs/types/graph.cjs.map +1 -1
- package/dist/cjs/utils/childAgentContext.cjs +242 -0
- package/dist/cjs/utils/childAgentContext.cjs.map +1 -0
- package/dist/cjs/utils/events.cjs +36 -4
- package/dist/cjs/utils/events.cjs.map +1 -1
- package/dist/cjs/utils/finishReasons.cjs +44 -0
- package/dist/cjs/utils/finishReasons.cjs.map +1 -0
- package/dist/cjs/utils/llm.cjs.map +1 -1
- package/dist/cjs/utils/logging.cjs +34 -0
- package/dist/cjs/utils/logging.cjs.map +1 -0
- package/dist/cjs/utils/toolCallNormalization.cjs +250 -0
- package/dist/cjs/utils/toolCallNormalization.cjs.map +1 -0
- package/dist/esm/agents/AgentContext.mjs +20 -3
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/common/spawnPath.mjs +95 -0
- package/dist/esm/common/spawnPath.mjs.map +1 -0
- package/dist/esm/graphs/Graph.mjs +87 -31
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/HandoffRegistry.mjs +141 -0
- package/dist/esm/graphs/HandoffRegistry.mjs.map +1 -0
- package/dist/esm/graphs/MultiAgentGraph.mjs +587 -184
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/graphs/phases/flushLoop.mjs +209 -0
- package/dist/esm/graphs/phases/flushLoop.mjs.map +1 -0
- package/dist/esm/graphs/phases/memoryFlushPhase.mjs +99 -0
- package/dist/esm/graphs/phases/memoryFlushPhase.mjs.map +1 -0
- package/dist/esm/llm/bedrock/index.mjs +4 -3
- package/dist/esm/llm/bedrock/index.mjs.map +1 -1
- package/dist/esm/main.mjs +21 -0
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/memory/citations.mjs +64 -0
- package/dist/esm/memory/citations.mjs.map +1 -0
- package/dist/esm/memory/compositeBackend.mjs +58 -0
- package/dist/esm/memory/compositeBackend.mjs.map +1 -0
- package/dist/esm/memory/constants.mjs +198 -0
- package/dist/esm/memory/constants.mjs.map +1 -0
- package/dist/esm/memory/embeddings.mjs +148 -0
- package/dist/esm/memory/embeddings.mjs.map +1 -0
- package/dist/esm/memory/factory.mjs +93 -0
- package/dist/esm/memory/factory.mjs.map +1 -0
- package/dist/esm/memory/migrate.mjs +78 -0
- package/dist/esm/memory/migrate.mjs.map +1 -0
- package/dist/esm/memory/mmr.mjs +130 -0
- package/dist/esm/memory/mmr.mjs.map +1 -0
- package/dist/esm/memory/paths.mjs +207 -0
- package/dist/esm/memory/paths.mjs.map +1 -0
- package/dist/esm/memory/pgvectorStore.mjs +223 -0
- package/dist/esm/memory/pgvectorStore.mjs.map +1 -0
- package/dist/esm/memory/recallTracking.mjs +94 -0
- package/dist/esm/memory/recallTracking.mjs.map +1 -0
- package/dist/esm/memory/schema.sql +51 -0
- package/dist/esm/memory/temporalDecay.mjs +110 -0
- package/dist/esm/memory/temporalDecay.mjs.map +1 -0
- package/dist/esm/nodes/ApprovalGateNode.mjs +1 -1
- package/dist/esm/nodes/ApprovalGateNode.mjs.map +1 -1
- package/dist/esm/prompts/memoryFlushPrompt.mjs +44 -0
- package/dist/esm/prompts/memoryFlushPrompt.mjs.map +1 -0
- package/dist/esm/run.mjs +16 -3
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/stream.mjs +4 -4
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/tools/AskUser.mjs +6 -1
- package/dist/esm/tools/AskUser.mjs.map +1 -1
- package/dist/esm/tools/BrowserTools.mjs +1 -1
- package/dist/esm/tools/BrowserTools.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +128 -11
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/approval/constants.mjs +2 -2
- package/dist/esm/tools/approval/constants.mjs.map +1 -1
- package/dist/esm/tools/memory/index.mjs +46 -0
- package/dist/esm/tools/memory/index.mjs.map +1 -0
- package/dist/esm/tools/memory/memoryAppendTool.mjs +67 -0
- package/dist/esm/tools/memory/memoryAppendTool.mjs.map +1 -0
- package/dist/esm/tools/memory/memoryGetTool.mjs +47 -0
- package/dist/esm/tools/memory/memoryGetTool.mjs.map +1 -0
- package/dist/esm/tools/memory/memorySearchTool.mjs +63 -0
- package/dist/esm/tools/memory/memorySearchTool.mjs.map +1 -0
- package/dist/esm/tools/memory/shared.mjs +98 -0
- package/dist/esm/tools/memory/shared.mjs.map +1 -0
- package/dist/esm/types/graph.mjs.map +1 -1
- package/dist/esm/utils/childAgentContext.mjs +237 -0
- package/dist/esm/utils/childAgentContext.mjs.map +1 -0
- package/dist/esm/utils/events.mjs +36 -5
- package/dist/esm/utils/events.mjs.map +1 -1
- package/dist/esm/utils/finishReasons.mjs +41 -0
- package/dist/esm/utils/finishReasons.mjs.map +1 -0
- package/dist/esm/utils/llm.mjs.map +1 -1
- package/dist/esm/utils/logging.mjs +31 -0
- package/dist/esm/utils/logging.mjs.map +1 -0
- package/dist/esm/utils/toolCallNormalization.mjs +247 -0
- package/dist/esm/utils/toolCallNormalization.mjs.map +1 -0
- package/dist/types/common/index.d.ts +1 -0
- package/dist/types/common/spawnPath.d.ts +59 -0
- package/dist/types/graphs/HandoffRegistry.d.ts +97 -0
- package/dist/types/graphs/MultiAgentGraph.d.ts +58 -18
- package/dist/types/graphs/index.d.ts +1 -0
- package/dist/types/graphs/phases/flushLoop.d.ts +106 -0
- package/dist/types/graphs/phases/memoryFlushPhase.d.ts +100 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/memory/__tests__/mockBackend.d.ts +40 -0
- package/dist/types/memory/citations.d.ts +39 -0
- package/dist/types/memory/compositeBackend.d.ts +30 -0
- package/dist/types/memory/constants.d.ts +121 -0
- package/dist/types/memory/embeddings.d.ts +15 -0
- package/dist/types/memory/factory.d.ts +23 -0
- package/dist/types/memory/index.d.ts +21 -0
- package/dist/types/memory/migrate.d.ts +14 -0
- package/dist/types/memory/mmr.d.ts +50 -0
- package/dist/types/memory/paths.d.ts +107 -0
- package/dist/types/memory/pgvectorStore.d.ts +56 -0
- package/dist/types/memory/recallTracking.d.ts +30 -0
- package/dist/types/memory/temporalDecay.d.ts +53 -0
- package/dist/types/memory/types.d.ts +182 -0
- package/dist/types/prompts/memoryFlushPrompt.d.ts +54 -0
- package/dist/types/run.d.ts +1 -0
- package/dist/types/tools/AskUser.d.ts +1 -1
- package/dist/types/tools/BrowserTools.d.ts +2 -2
- package/dist/types/tools/approval/constants.d.ts +2 -2
- package/dist/types/tools/memory/index.d.ts +39 -0
- package/dist/types/tools/memory/memoryAppendTool.d.ts +27 -0
- package/dist/types/tools/memory/memoryGetTool.d.ts +22 -0
- package/dist/types/tools/memory/memorySearchTool.d.ts +22 -0
- package/dist/types/tools/memory/shared.d.ts +106 -0
- package/dist/types/types/graph.d.ts +16 -3
- package/dist/types/utils/childAgentContext.d.ts +99 -0
- package/dist/types/utils/events.d.ts +21 -0
- package/dist/types/utils/finishReasons.d.ts +32 -0
- package/dist/types/utils/logging.d.ts +2 -0
- package/dist/types/utils/toolCallNormalization.d.ts +44 -0
- package/package.json +6 -4
- package/src/agents/AgentContext.ts +26 -3
- package/src/common/__tests__/enum.test.ts +4 -2
- package/src/common/__tests__/spawnPath.test.ts +110 -0
- package/src/common/index.ts +1 -0
- package/src/common/spawnPath.ts +101 -0
- package/src/graphs/Graph.ts +94 -43
- package/src/graphs/HandoffRegistry.ts +199 -0
- package/src/graphs/MultiAgentGraph.ts +694 -226
- package/src/graphs/__tests__/HandoffRegistry.test.ts +410 -0
- package/src/graphs/__tests__/multi-agent-delegate.test.ts +61 -16
- package/src/graphs/__tests__/multi-agent-edges.test.ts +4 -2
- package/src/graphs/__tests__/multi-agent-nested-subgraph.test.ts +221 -0
- package/src/graphs/__tests__/structured-output.integration.test.ts +212 -118
- package/src/graphs/contextManagement.e2e.test.ts +1 -1
- package/src/graphs/index.ts +1 -0
- package/src/graphs/phases/__tests__/flushLoop.test.ts +264 -0
- package/src/graphs/phases/__tests__/memoryFlushPhase.test.ts +37 -0
- package/src/graphs/phases/__tests__/runMemoryFlush.test.ts +150 -0
- package/src/graphs/phases/flushLoop.ts +303 -0
- package/src/graphs/phases/memoryFlushPhase.ts +209 -0
- package/src/index.ts +30 -1
- package/src/llm/bedrock/index.ts +4 -5
- package/src/memory/__tests__/citations.test.ts +61 -0
- package/src/memory/__tests__/compositeBackend.test.ts +79 -0
- package/src/memory/__tests__/isolation.test.ts +206 -0
- package/src/memory/__tests__/mmr.test.ts +148 -0
- package/src/memory/__tests__/mockBackend.ts +161 -0
- package/src/memory/__tests__/paths.test.ts +168 -0
- package/src/memory/__tests__/recallTracking.test.ts +96 -0
- package/src/memory/__tests__/temporalDecay.test.ts +151 -0
- package/src/memory/citations.ts +80 -0
- package/src/memory/compositeBackend.ts +99 -0
- package/src/memory/constants.ts +229 -0
- package/src/memory/embeddings.ts +188 -0
- package/src/memory/factory.ts +111 -0
- package/src/memory/index.ts +46 -0
- package/src/memory/migrate.ts +116 -0
- package/src/memory/mmr.ts +161 -0
- package/src/memory/paths.ts +258 -0
- package/src/memory/pgvectorStore.ts +324 -0
- package/src/memory/recallTracking.ts +127 -0
- package/src/memory/schema.sql +51 -0
- package/src/memory/temporalDecay.ts +134 -0
- package/src/memory/types.ts +185 -0
- package/src/nodes/ApprovalGateNode.ts +4 -10
- package/src/nodes/__tests__/ApprovalGateNode.test.ts +11 -20
- package/src/prompts/memoryFlushPrompt.ts +78 -0
- package/src/run.ts +17 -6
- package/src/scripts/test-bedrock-handoff-autonomous.ts +56 -20
- package/src/specs/agent-handoffs-bedrock.integration.test.ts +8 -5
- package/src/specs/agent-handoffs.test.ts +8 -2
- package/src/stream.ts +4 -6
- package/src/tools/AskUser.ts +7 -2
- package/src/tools/BrowserTools.ts +3 -5
- package/src/tools/ToolNode.ts +150 -13
- package/src/tools/__tests__/ToolApproval.test.ts +22 -9
- package/src/tools/approval/__tests__/constants.test.ts +4 -4
- package/src/tools/approval/constants.ts +2 -2
- package/src/tools/memory/__tests__/memoryTools.test.ts +205 -0
- package/src/tools/memory/index.ts +96 -0
- package/src/tools/memory/memoryAppendTool.ts +101 -0
- package/src/tools/memory/memoryGetTool.ts +53 -0
- package/src/tools/memory/memorySearchTool.ts +80 -0
- package/src/tools/memory/shared.ts +169 -0
- package/src/tools/search/search.test.ts +6 -1
- package/src/types/graph.ts +16 -3
- package/src/utils/__tests__/childAgentContext.test.ts +217 -0
- package/src/utils/__tests__/finishReasons.test.ts +55 -0
- package/src/utils/__tests__/toolCallNormalization.test.ts +181 -0
- package/src/utils/childAgentContext.ts +259 -0
- package/src/utils/events.ts +37 -4
- package/src/utils/finishReasons.ts +40 -0
- package/src/utils/llm.ts +0 -1
- package/src/utils/logging.ts +45 -8
- package/src/utils/toolCallNormalization.ts +271 -0
package/dist/cjs/main.cjs
CHANGED
|
@@ -15,6 +15,7 @@ var summarize = require('./messages/summarize.cjs');
|
|
|
15
15
|
var dedup = require('./messages/dedup.cjs');
|
|
16
16
|
var Graph = require('./graphs/Graph.cjs');
|
|
17
17
|
var MultiAgentGraph = require('./graphs/MultiAgentGraph.cjs');
|
|
18
|
+
var HandoffRegistry = require('./graphs/HandoffRegistry.cjs');
|
|
18
19
|
var Calculator = require('./tools/Calculator.cjs');
|
|
19
20
|
var CodeExecutor = require('./tools/CodeExecutor.cjs');
|
|
20
21
|
var BrowserTools = require('./tools/BrowserTools.cjs');
|
|
@@ -26,10 +27,26 @@ var schema$1 = require('./tools/schema.cjs');
|
|
|
26
27
|
var handlers$1 = require('./tools/handlers.cjs');
|
|
27
28
|
var tool = require('./tools/search/tool.cjs');
|
|
28
29
|
var schema = require('./tools/search/schema.cjs');
|
|
30
|
+
var index$2 = require('./tools/memory/index.cjs');
|
|
31
|
+
var constants$2 = require('./memory/constants.cjs');
|
|
32
|
+
var paths = require('./memory/paths.cjs');
|
|
33
|
+
var pgvectorStore = require('./memory/pgvectorStore.cjs');
|
|
34
|
+
var compositeBackend = require('./memory/compositeBackend.cjs');
|
|
35
|
+
var embeddings = require('./memory/embeddings.cjs');
|
|
36
|
+
var migrate = require('./memory/migrate.cjs');
|
|
37
|
+
var factory = require('./memory/factory.cjs');
|
|
38
|
+
var mmr = require('./memory/mmr.cjs');
|
|
39
|
+
var temporalDecay = require('./memory/temporalDecay.cjs');
|
|
40
|
+
var citations = require('./memory/citations.cjs');
|
|
41
|
+
var recallTracking = require('./memory/recallTracking.cjs');
|
|
42
|
+
var memoryFlushPrompt = require('./prompts/memoryFlushPrompt.cjs');
|
|
43
|
+
var memoryFlushPhase = require('./graphs/phases/memoryFlushPhase.cjs');
|
|
44
|
+
var flushLoop = require('./graphs/phases/flushLoop.cjs');
|
|
29
45
|
var validate = require('./schemas/validate.cjs');
|
|
30
46
|
var ApprovalGateNode = require('./nodes/ApprovalGateNode.cjs');
|
|
31
47
|
var _enum = require('./common/enum.cjs');
|
|
32
48
|
var constants$1 = require('./common/constants.cjs');
|
|
49
|
+
var spawnPath = require('./common/spawnPath.cjs');
|
|
33
50
|
var constants = require('./tools/approval/constants.cjs');
|
|
34
51
|
var graph = require('./utils/graph.cjs');
|
|
35
52
|
var llm = require('./utils/llm.cjs');
|
|
@@ -48,6 +65,10 @@ var fileManifest = require('./utils/fileManifest.cjs');
|
|
|
48
65
|
var index$1 = require('./llm/openai/index.cjs');
|
|
49
66
|
var index = require('./llm/openrouter/index.cjs');
|
|
50
67
|
var providers = require('./llm/providers.cjs');
|
|
68
|
+
var shared = require('./tools/memory/shared.cjs');
|
|
69
|
+
var memoryAppendTool = require('./tools/memory/memoryAppendTool.cjs');
|
|
70
|
+
var memoryGetTool = require('./tools/memory/memoryGetTool.cjs');
|
|
71
|
+
var memorySearchTool = require('./tools/memory/memorySearchTool.cjs');
|
|
51
72
|
|
|
52
73
|
|
|
53
74
|
|
|
@@ -105,6 +126,7 @@ exports.deduplicateSystemMessages = dedup.deduplicateSystemMessages;
|
|
|
105
126
|
exports.Graph = Graph.Graph;
|
|
106
127
|
exports.StandardGraph = Graph.StandardGraph;
|
|
107
128
|
exports.MultiAgentGraph = MultiAgentGraph.MultiAgentGraph;
|
|
129
|
+
exports.HandoffRegistry = HandoffRegistry.HandoffRegistry;
|
|
108
130
|
exports.Calculator = Calculator.Calculator;
|
|
109
131
|
exports.CalculatorSchema = Calculator.CalculatorSchema;
|
|
110
132
|
exports.CalculatorToolDefinition = Calculator.CalculatorToolDefinition;
|
|
@@ -182,6 +204,81 @@ exports.imagesSchema = schema.imagesSchema;
|
|
|
182
204
|
exports.newsSchema = schema.newsSchema;
|
|
183
205
|
exports.querySchema = schema.querySchema;
|
|
184
206
|
exports.videosSchema = schema.videosSchema;
|
|
207
|
+
exports.buildMemoryTools = index$2.buildMemoryTools;
|
|
208
|
+
exports.DEFAULT_CITATIONS_MODE = constants$2.DEFAULT_CITATIONS_MODE;
|
|
209
|
+
exports.DEFAULT_FLUSH_RESERVE_FLOOR_TOKENS = constants$2.DEFAULT_FLUSH_RESERVE_FLOOR_TOKENS;
|
|
210
|
+
exports.DEFAULT_FLUSH_SOFT_THRESHOLD_TOKENS = constants$2.DEFAULT_FLUSH_SOFT_THRESHOLD_TOKENS;
|
|
211
|
+
exports.DEFAULT_MAX_APPENDS_PER_FLUSH = constants$2.DEFAULT_MAX_APPENDS_PER_FLUSH;
|
|
212
|
+
exports.DEFAULT_MAX_FLUSH_ITERATIONS = constants$2.DEFAULT_MAX_FLUSH_ITERATIONS;
|
|
213
|
+
exports.DEFAULT_MAX_INJECTED_CHARS = constants$2.DEFAULT_MAX_INJECTED_CHARS;
|
|
214
|
+
exports.DEFAULT_MAX_SEARCH_RESULTS = constants$2.DEFAULT_MAX_SEARCH_RESULTS;
|
|
215
|
+
exports.DEFAULT_MEMORY_DIMENSIONS = constants$2.DEFAULT_MEMORY_DIMENSIONS;
|
|
216
|
+
exports.DEFAULT_MEMORY_FLUSH_PROMPT = constants$2.DEFAULT_MEMORY_FLUSH_PROMPT;
|
|
217
|
+
exports.DEFAULT_MEMORY_FLUSH_SYSTEM_PROMPT = constants$2.DEFAULT_MEMORY_FLUSH_SYSTEM_PROMPT;
|
|
218
|
+
exports.DEFAULT_MEMORY_MODEL = constants$2.DEFAULT_MEMORY_MODEL;
|
|
219
|
+
exports.DEFAULT_MEMORY_PROVIDER = constants$2.DEFAULT_MEMORY_PROVIDER;
|
|
220
|
+
exports.DEFAULT_MEMORY_SCHEMA = constants$2.DEFAULT_MEMORY_SCHEMA;
|
|
221
|
+
exports.DEFAULT_MEMORY_TABLE = constants$2.DEFAULT_MEMORY_TABLE;
|
|
222
|
+
exports.DEFAULT_MIN_SCORE = constants$2.DEFAULT_MIN_SCORE;
|
|
223
|
+
exports.DEFAULT_MMR_ENABLED = constants$2.DEFAULT_MMR_ENABLED;
|
|
224
|
+
exports.DEFAULT_MMR_LAMBDA = constants$2.DEFAULT_MMR_LAMBDA;
|
|
225
|
+
exports.DEFAULT_RECALL_TRACKING_ENABLED = constants$2.DEFAULT_RECALL_TRACKING_ENABLED;
|
|
226
|
+
exports.DEFAULT_TEMPORAL_DECAY_ENABLED = constants$2.DEFAULT_TEMPORAL_DECAY_ENABLED;
|
|
227
|
+
exports.DEFAULT_TEMPORAL_DECAY_HALF_LIFE_DAYS = constants$2.DEFAULT_TEMPORAL_DECAY_HALF_LIFE_DAYS;
|
|
228
|
+
exports.FLUSH_PROMPT_RUBRIC_PLACEHOLDER = constants$2.FLUSH_PROMPT_RUBRIC_PLACEHOLDER;
|
|
229
|
+
exports.HYBRID_TEXT_WEIGHT = constants$2.HYBRID_TEXT_WEIGHT;
|
|
230
|
+
exports.HYBRID_VECTOR_WEIGHT = constants$2.HYBRID_VECTOR_WEIGHT;
|
|
231
|
+
exports.MEMORY_APPEND_DESCRIPTION = constants$2.MEMORY_APPEND_DESCRIPTION;
|
|
232
|
+
exports.MEMORY_APPEND_TOOL_NAME = constants$2.MEMORY_APPEND_TOOL_NAME;
|
|
233
|
+
exports.MEMORY_GET_DESCRIPTION = constants$2.MEMORY_GET_DESCRIPTION;
|
|
234
|
+
exports.MEMORY_GET_TOOL_NAME = constants$2.MEMORY_GET_TOOL_NAME;
|
|
235
|
+
exports.MEMORY_PATH_PREFIX = constants$2.MEMORY_PATH_PREFIX;
|
|
236
|
+
exports.MEMORY_PHASE_FLUSHING = constants$2.MEMORY_PHASE_FLUSHING;
|
|
237
|
+
exports.MEMORY_PHASE_NORMAL = constants$2.MEMORY_PHASE_NORMAL;
|
|
238
|
+
exports.MEMORY_SEARCH_DESCRIPTION = constants$2.MEMORY_SEARCH_DESCRIPTION;
|
|
239
|
+
exports.MEMORY_SEARCH_TOOL_NAME = constants$2.MEMORY_SEARCH_TOOL_NAME;
|
|
240
|
+
exports.SILENT_REPLY_TOKEN = constants$2.SILENT_REPLY_TOKEN;
|
|
241
|
+
exports.MEMORY_AGENT_PATHS = paths.MEMORY_AGENT_PATHS;
|
|
242
|
+
exports.MEMORY_ALL_PATHS = paths.MEMORY_ALL_PATHS;
|
|
243
|
+
exports.MEMORY_USER_PATHS = paths.MEMORY_USER_PATHS;
|
|
244
|
+
exports.MEMORY_WRITABLE_PATHS = paths.MEMORY_WRITABLE_PATHS;
|
|
245
|
+
exports.assertWritablePath = paths.assertWritablePath;
|
|
246
|
+
exports.getPathDescriptor = paths.getPathDescriptor;
|
|
247
|
+
exports.getTierForPath = paths.getTierForPath;
|
|
248
|
+
exports.getWritablePathsForScope = paths.getWritablePathsForScope;
|
|
249
|
+
exports.renderPathsRubric = paths.renderPathsRubric;
|
|
250
|
+
exports.PgvectorMemoryStore = pgvectorStore.PgvectorMemoryStore;
|
|
251
|
+
exports.CompositeMemoryBackend = compositeBackend.CompositeMemoryBackend;
|
|
252
|
+
exports.getMemoryEmbedder = embeddings.getMemoryEmbedder;
|
|
253
|
+
exports.resetMemoryEmbedder = embeddings.resetMemoryEmbedder;
|
|
254
|
+
exports.runMemoryMigration = migrate.runMemoryMigration;
|
|
255
|
+
exports.buildMemoryBackendFromEnv = factory.buildMemoryBackendFromEnv;
|
|
256
|
+
exports.DEFAULT_MMR_CONFIG = mmr.DEFAULT_MMR_CONFIG;
|
|
257
|
+
exports.applyMMRToMemoryHits = mmr.applyMMRToMemoryHits;
|
|
258
|
+
exports.computeMMRScore = mmr.computeMMRScore;
|
|
259
|
+
exports.jaccardSimilarity = mmr.jaccardSimilarity;
|
|
260
|
+
exports.mmrRerank = mmr.mmrRerank;
|
|
261
|
+
exports.textSimilarity = mmr.textSimilarity;
|
|
262
|
+
exports.tokenize = mmr.tokenize;
|
|
263
|
+
exports.DEFAULT_TEMPORAL_DECAY_CONFIG = temporalDecay.DEFAULT_TEMPORAL_DECAY_CONFIG;
|
|
264
|
+
exports.applyTemporalDecayToHits = temporalDecay.applyTemporalDecayToHits;
|
|
265
|
+
exports.applyTemporalDecayToScore = temporalDecay.applyTemporalDecayToScore;
|
|
266
|
+
exports.calculateTemporalDecayMultiplier = temporalDecay.calculateTemporalDecayMultiplier;
|
|
267
|
+
exports.isEvergreenMemoryPath = temporalDecay.isEvergreenMemoryPath;
|
|
268
|
+
exports.parseMemoryDateFromPath = temporalDecay.parseMemoryDateFromPath;
|
|
269
|
+
exports.decorateCitations = citations.decorateCitations;
|
|
270
|
+
exports.resolveMemoryCitationsMode = citations.resolveMemoryCitationsMode;
|
|
271
|
+
exports.shouldIncludeCitations = citations.shouldIncludeCitations;
|
|
272
|
+
exports.NullRecallTracker = recallTracking.NullRecallTracker;
|
|
273
|
+
exports.PgvectorRecallTracker = recallTracking.PgvectorRecallTracker;
|
|
274
|
+
exports.RECALL_TABLE = recallTracking.RECALL_TABLE;
|
|
275
|
+
exports.MEMORY_FLUSH_SYSTEM_PROMPT = memoryFlushPrompt.MEMORY_FLUSH_SYSTEM_PROMPT;
|
|
276
|
+
exports.runMemoryFlush = memoryFlushPhase.runMemoryFlush;
|
|
277
|
+
exports.shouldFlushMemory = memoryFlushPhase.shouldFlushMemory;
|
|
278
|
+
exports.bindToolsIfSupported = flushLoop.bindToolsIfSupported;
|
|
279
|
+
exports.extractFlushText = flushLoop.extractText;
|
|
280
|
+
exports.parseFlushToolResult = flushLoop.parseToolResult;
|
|
281
|
+
exports.runFlushLoop = flushLoop.runFlushLoop;
|
|
185
282
|
exports.createValidationErrorMessage = validate.createValidationErrorMessage;
|
|
186
283
|
exports.isValidJsonSchema = validate.isValidJsonSchema;
|
|
187
284
|
exports.normalizeJsonSchema = validate.normalizeJsonSchema;
|
|
@@ -264,6 +361,14 @@ exports.SUMMARIZATION_CONTEXT_THRESHOLD = constants$1.SUMMARIZATION_CONTEXT_THRE
|
|
|
264
361
|
exports.SUMMARIZATION_RESERVE_RATIO = constants$1.SUMMARIZATION_RESERVE_RATIO;
|
|
265
362
|
exports.TOOL_DISCOVERY_CACHE_MAX_SIZE = constants$1.TOOL_DISCOVERY_CACHE_MAX_SIZE;
|
|
266
363
|
exports.TOOL_TURN_THINKING_BUDGET = constants$1.TOOL_TURN_THINKING_BUDGET;
|
|
364
|
+
exports.MAX_NESTING_DEPTH = spawnPath.MAX_NESTING_DEPTH;
|
|
365
|
+
exports.SPAWN_PATH_SEP = spawnPath.SPAWN_PATH_SEP;
|
|
366
|
+
exports.buildSpawnPath = spawnPath.buildSpawnPath;
|
|
367
|
+
exports.isAncestorSpawnPath = spawnPath.isAncestorSpawnPath;
|
|
368
|
+
exports.leafSpawnKey = spawnPath.leafSpawnKey;
|
|
369
|
+
exports.parentSpawnPath = spawnPath.parentSpawnPath;
|
|
370
|
+
exports.spawnPathDepth = spawnPath.spawnPathDepth;
|
|
371
|
+
exports.spawnPathParts = spawnPath.spawnPathParts;
|
|
267
372
|
Object.defineProperty(exports, "ActionCategory", {
|
|
268
373
|
enumerable: true,
|
|
269
374
|
get: function () { return constants.ActionCategory; }
|
|
@@ -324,4 +429,14 @@ exports.CustomOpenAIClient = index$1.CustomOpenAIClient;
|
|
|
324
429
|
exports.ChatOpenRouter = index.ChatOpenRouter;
|
|
325
430
|
exports.getChatModelClass = providers.getChatModelClass;
|
|
326
431
|
exports.llmProviders = providers.llmProviders;
|
|
432
|
+
exports.MemoryAppendSchema = shared.MemoryAppendSchema;
|
|
433
|
+
exports.MemoryGetSchema = shared.MemoryGetSchema;
|
|
434
|
+
exports.MemorySearchSchema = shared.MemorySearchSchema;
|
|
435
|
+
exports.assertAppendAllowed = shared.assertAppendAllowed;
|
|
436
|
+
exports.buildMemorySearchUnavailableResult = shared.buildMemorySearchUnavailableResult;
|
|
437
|
+
exports.clampResultsByInjectedChars = shared.clampResultsByInjectedChars;
|
|
438
|
+
exports.toAppendInput = shared.toAppendInput;
|
|
439
|
+
exports.createMemoryAppendTool = memoryAppendTool.createMemoryAppendTool;
|
|
440
|
+
exports.createMemoryGetTool = memoryGetTool.createMemoryGetTool;
|
|
441
|
+
exports.createMemorySearchTool = memorySearchTool.createMemorySearchTool;
|
|
327
442
|
//# sourceMappingURL=main.cjs.map
|
package/dist/cjs/main.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"main.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Citation decoration — Phase 2.
|
|
5
|
+
*
|
|
6
|
+
* Ported from upstream `extensions/memory-core/src/tools.citations.ts`.
|
|
7
|
+
* Decorates memory_search hits with `[path#L{start}-L{end}]` markers so
|
|
8
|
+
* the model can attribute claims back to specific memory files when it
|
|
9
|
+
* uses them in its answer.
|
|
10
|
+
*
|
|
11
|
+
* Since our backend stores files as single rows (not line-chunked), we
|
|
12
|
+
* compute line ranges from the returned content block on the fly:
|
|
13
|
+
* - `startLine` = 1 (line 1 of the file)
|
|
14
|
+
* - `endLine` = total number of lines in the block
|
|
15
|
+
* This matches upstream's output format exactly while keeping the pg
|
|
16
|
+
* schema chunk-free.
|
|
17
|
+
*/
|
|
18
|
+
const DEFAULT_CITATIONS_MODE = 'auto';
|
|
19
|
+
function resolveMemoryCitationsMode(raw) {
|
|
20
|
+
if (raw === 'on' || raw === 'off' || raw === 'auto')
|
|
21
|
+
return raw;
|
|
22
|
+
return DEFAULT_CITATIONS_MODE;
|
|
23
|
+
}
|
|
24
|
+
function countLines(text) {
|
|
25
|
+
if (!text)
|
|
26
|
+
return 1;
|
|
27
|
+
return Math.max(1, text.split('\n').length);
|
|
28
|
+
}
|
|
29
|
+
function formatCitation(path, startLine, endLine) {
|
|
30
|
+
if (startLine === endLine)
|
|
31
|
+
return `${path}#L${startLine}`;
|
|
32
|
+
return `${path}#L${startLine}-L${endLine}`;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Decorate each hit with a citation marker. Mirrors upstream's behavior:
|
|
36
|
+
* appends `\n\nSource: <citation>` to the content and sets `citation`.
|
|
37
|
+
* When `include=false`, clears any existing citation field.
|
|
38
|
+
*/
|
|
39
|
+
function decorateCitations(hits, include) {
|
|
40
|
+
if (!include)
|
|
41
|
+
return hits.map((h) => ({ ...h, citation: undefined }));
|
|
42
|
+
return hits.map((h) => {
|
|
43
|
+
const start = Math.max(1, Math.floor(h.startLine ?? 1));
|
|
44
|
+
const end = Math.max(start, Math.floor(h.endLine ?? countLines(h.content)));
|
|
45
|
+
const citation = formatCitation(h.path, start, end);
|
|
46
|
+
const content = `${(h.content ?? '').trimEnd()}\n\nSource: ${citation}`;
|
|
47
|
+
return { ...h, citation, content, startLine: start, endLine: end };
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Whether citations should be emitted for this call.
|
|
52
|
+
*
|
|
53
|
+
* Upstream keys `auto` off the session type (direct/group/channel). In
|
|
54
|
+
* Phase 1 we only have direct chat, so `auto` => `on`. Callers that
|
|
55
|
+
* later distinguish session types can pass `mode` explicitly.
|
|
56
|
+
*/
|
|
57
|
+
function shouldIncludeCitations(mode) {
|
|
58
|
+
if (mode === 'on')
|
|
59
|
+
return true;
|
|
60
|
+
if (mode === 'off')
|
|
61
|
+
return false;
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
exports.DEFAULT_CITATIONS_MODE = DEFAULT_CITATIONS_MODE;
|
|
66
|
+
exports.decorateCitations = decorateCitations;
|
|
67
|
+
exports.resolveMemoryCitationsMode = resolveMemoryCitationsMode;
|
|
68
|
+
exports.shouldIncludeCitations = shouldIncludeCitations;
|
|
69
|
+
//# sourceMappingURL=citations.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"citations.cjs","sources":["../../../src/memory/citations.ts"],"sourcesContent":["/**\n * Citation decoration — Phase 2.\n *\n * Ported from upstream `extensions/memory-core/src/tools.citations.ts`.\n * Decorates memory_search hits with `[path#L{start}-L{end}]` markers so\n * the model can attribute claims back to specific memory files when it\n * uses them in its answer.\n *\n * Since our backend stores files as single rows (not line-chunked), we\n * compute line ranges from the returned content block on the fly:\n * - `startLine` = 1 (line 1 of the file)\n * - `endLine` = total number of lines in the block\n * This matches upstream's output format exactly while keeping the pg\n * schema chunk-free.\n */\n\nexport type MemoryCitationsMode = 'on' | 'off' | 'auto';\n\nexport const DEFAULT_CITATIONS_MODE: MemoryCitationsMode = 'auto';\n\nexport function resolveMemoryCitationsMode(\n raw: string | undefined | null\n): MemoryCitationsMode {\n if (raw === 'on' || raw === 'off' || raw === 'auto') return raw;\n return DEFAULT_CITATIONS_MODE;\n}\n\nexport interface CitationCandidate {\n path: string;\n content: string;\n startLine?: number;\n endLine?: number;\n citation?: string;\n}\n\nfunction countLines(text: string): number {\n if (!text) return 1;\n return Math.max(1, text.split('\\n').length);\n}\n\nfunction formatCitation(\n path: string,\n startLine: number,\n endLine: number\n): string {\n if (startLine === endLine) return `${path}#L${startLine}`;\n return `${path}#L${startLine}-L${endLine}`;\n}\n\n/**\n * Decorate each hit with a citation marker. Mirrors upstream's behavior:\n * appends `\\n\\nSource: <citation>` to the content and sets `citation`.\n * When `include=false`, clears any existing citation field.\n */\nexport function decorateCitations<T extends CitationCandidate>(\n hits: T[],\n include: boolean\n): T[] {\n if (!include) return hits.map((h) => ({ ...h, citation: undefined }));\n return hits.map((h) => {\n const start = Math.max(1, Math.floor(h.startLine ?? 1));\n const end = Math.max(start, Math.floor(h.endLine ?? countLines(h.content)));\n const citation = formatCitation(h.path, start, end);\n const content = `${(h.content ?? '').trimEnd()}\\n\\nSource: ${citation}`;\n return { ...h, citation, content, startLine: start, endLine: end };\n });\n}\n\n/**\n * Whether citations should be emitted for this call.\n *\n * Upstream keys `auto` off the session type (direct/group/channel). In\n * Phase 1 we only have direct chat, so `auto` => `on`. Callers that\n * later distinguish session types can pass `mode` explicitly.\n */\nexport function shouldIncludeCitations(mode: MemoryCitationsMode): boolean {\n if (mode === 'on') return true;\n if (mode === 'off') return false;\n return true;\n}\n"],"names":[],"mappings":";;AAAA;;;;;;;;;;;;;;AAcG;AAII,MAAM,sBAAsB,GAAwB;AAErD,SAAU,0BAA0B,CACxC,GAA8B,EAAA;IAE9B,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,KAAK,IAAI,GAAG,KAAK,MAAM;AAAE,QAAA,OAAO,GAAG;AAC/D,IAAA,OAAO,sBAAs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e,QAAQ,EAAE;AACvE,QAAA,OAAO,EAAE,GAAG,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE;AACpE,IAAA,CAAC,CAAC;AACJ;AAEA;;;;;;AAMG;AACG,SAAU,sBAAsB,CAAC,IAAyB,EAAA;IAC9D,IAAI,IAAI,KAAK,IAAI;AAAE,QAAA,OAAO,IAAI;IAC9B,IAAI,IAAI,KAAK,KAAK;AAAE,QAAA,OAAO,KAAK;AAChC,IAAA,OAAO,IAAI;AACb;;;;;;;"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
class CompositeMemoryBackend {
|
|
4
|
+
kind = 'composite';
|
|
5
|
+
backends;
|
|
6
|
+
constructor(backends) {
|
|
7
|
+
if (backends.length === 0) {
|
|
8
|
+
throw new Error('CompositeMemoryBackend requires at least one backend');
|
|
9
|
+
}
|
|
10
|
+
this.backends = backends;
|
|
11
|
+
}
|
|
12
|
+
async search(scope, query, opts) {
|
|
13
|
+
const perBackend = await Promise.all(this.backends.map((backend) => backend.search(scope, query, opts)));
|
|
14
|
+
const merged = new Map();
|
|
15
|
+
for (const entries of perBackend) {
|
|
16
|
+
for (const entry of entries) {
|
|
17
|
+
const key = `${entry.source ?? 'unknown'}:${entry.id}`;
|
|
18
|
+
const existing = merged.get(key);
|
|
19
|
+
if (!existing || entry.score > existing.score) {
|
|
20
|
+
merged.set(key, entry);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const limit = Math.max(1, opts?.maxResults ?? 10);
|
|
25
|
+
return Array.from(merged.values())
|
|
26
|
+
.sort((a, b) => b.score - a.score)
|
|
27
|
+
.slice(0, limit);
|
|
28
|
+
}
|
|
29
|
+
async get(scope, opts) {
|
|
30
|
+
for (const backend of this.backends) {
|
|
31
|
+
const result = await backend.get(scope, opts);
|
|
32
|
+
if (result)
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
async append(scope, input) {
|
|
38
|
+
// Serial fan-out — a failure in an earlier backend means we stop and
|
|
39
|
+
// bubble. We do NOT want a partial write where the vector row landed but
|
|
40
|
+
// the graph backend quietly dropped the note.
|
|
41
|
+
for (const backend of this.backends) {
|
|
42
|
+
await backend.append(scope, input);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async health() {
|
|
46
|
+
const healths = await Promise.all(this.backends.map((b) => b.health()));
|
|
47
|
+
const failed = healths.find((h) => !h.ok);
|
|
48
|
+
if (failed) {
|
|
49
|
+
return {
|
|
50
|
+
ok: false,
|
|
51
|
+
backend: 'composite',
|
|
52
|
+
error: `${failed.backend}: ${failed.error ?? 'unhealthy'}`,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return { ok: true, backend: 'composite' };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
exports.CompositeMemoryBackend = CompositeMemoryBackend;
|
|
60
|
+
//# sourceMappingURL=compositeBackend.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compositeBackend.cjs","sources":["../../../src/memory/compositeBackend.ts"],"sourcesContent":["/**\n * Composite memory backend — the architectural seam for a future graph layer.\n *\n * Today, memory is pgvector only. Tomorrow, a Graphiti or Neo4j-agent-memory\n * adapter can implement the same {@link MemoryBackend} interface and be\n * composed with the vector store here — without touching the tool\n * definitions, prompts, or host wiring.\n *\n * Fan-out strategy (simple on purpose for Phase 1):\n * - `search`: query every backend in parallel, merge, dedupe by id, sort by\n * score, cap at maxResults. Graph hits and vector hits are interleaved by\n * score — the LLM sees one ranked list.\n * - `get`: the vector store owns file paths; graph stores don't. First\n * backend that returns a non-null result wins. In practice this will almost\n * always be the vector store, since append paths live there.\n * - `append`: fan out to every backend. Vector store persists the note,\n * graph backend runs its own extraction pipeline. An append failure in any\n * single backend is surfaced — we fail loud rather than silently dropping\n * writes.\n */\nimport type {\n MemoryAppendInput,\n MemoryBackend,\n MemoryEntry,\n MemoryGetOptions,\n MemoryHealth,\n MemoryReadResult,\n MemoryScope,\n MemorySearchOptions,\n} from './types';\n\nexport class CompositeMemoryBackend implements MemoryBackend {\n readonly kind = 'composite' as const;\n private readonly backends: MemoryBackend[];\n\n constructor(backends: MemoryBackend[]) {\n if (backends.length === 0) {\n throw new Error('CompositeMemoryBackend requires at least one backend');\n }\n this.backends = backends;\n }\n\n async search(\n scope: MemoryScope,\n query: string,\n opts?: MemorySearchOptions\n ): Promise<MemoryEntry[]> {\n const perBackend = await Promise.all(\n this.backends.map((backend) => backend.search(scope, query, opts))\n );\n const merged = new Map<string, MemoryEntry>();\n for (const entries of perBackend) {\n for (const entry of entries) {\n const key = `${entry.source ?? 'unknown'}:${entry.id}`;\n const existing = merged.get(key);\n if (!existing || entry.score > existing.score) {\n merged.set(key, entry);\n }\n }\n }\n const limit = Math.max(1, opts?.maxResults ?? 10);\n return Array.from(merged.values())\n .sort((a, b) => b.score - a.score)\n .slice(0, limit);\n }\n\n async get(\n scope: MemoryScope,\n opts: MemoryGetOptions\n ): Promise<MemoryReadResult | null> {\n for (const backend of this.backends) {\n const result = await backend.get(scope, opts);\n if (result) return result;\n }\n return null;\n }\n\n async append(scope: MemoryScope, input: MemoryAppendInput): Promise<void> {\n // Serial fan-out — a failure in an earlier backend means we stop and\n // bubble. We do NOT want a partial write where the vector row landed but\n // the graph backend quietly dropped the note.\n for (const backend of this.backends) {\n await backend.append(scope, input);\n }\n }\n\n async health(): Promise<MemoryHealth> {\n const healths = await Promise.all(this.backends.map((b) => b.health()));\n const failed = healths.find((h) => !h.ok);\n if (failed) {\n return {\n ok: false,\n backend: 'composite',\n error: `${failed.backend}: ${failed.error ?? 'unhealthy'}`,\n };\n }\n return { ok: true, backend: 'composite' };\n }\n}\n"],"names":[],"mappings":";;MA+Ba,sBAAsB,CAAA;IACxB,IAAI,GAAG,WAAoB;AACnB,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, limits, and magic strings used across
|
|
7
|
+
* the memory store, tools, flush phase, and tests. Changing a value here
|
|
8
|
+
* changes it everywhere — no hunting through files.
|
|
9
|
+
*/
|
|
10
|
+
/** Default embedding provider when {@link process.env.MEMORY_EMBEDDINGS_PROVIDER} is unset. */
|
|
11
|
+
const DEFAULT_MEMORY_PROVIDER = 'bedrock';
|
|
12
|
+
/** Default embedding model (Titan v2 — AWS-native, 6× cheaper than Cohere v4). */
|
|
13
|
+
const DEFAULT_MEMORY_MODEL = 'amazon.titan-embed-text-v2:0';
|
|
14
|
+
/** Default vector width (Titan v2 supports 256 / 512 / 1024). */
|
|
15
|
+
const DEFAULT_MEMORY_DIMENSIONS = 1024;
|
|
16
|
+
/** Default Postgres table name; can be overridden via env for dev/prod sharing. */
|
|
17
|
+
const DEFAULT_MEMORY_TABLE = 'agent_memories';
|
|
18
|
+
/** Default Postgres schema. */
|
|
19
|
+
const DEFAULT_MEMORY_SCHEMA = 'public';
|
|
20
|
+
/** Phase values used by the flush-phase gate. */
|
|
21
|
+
const MEMORY_PHASE_NORMAL = 'normal';
|
|
22
|
+
const MEMORY_PHASE_FLUSHING = 'memory_flushing';
|
|
23
|
+
/**
|
|
24
|
+
* Search defaults — aligned with upstream's upstream defaults.
|
|
25
|
+
*
|
|
26
|
+
* Sources:
|
|
27
|
+
* - `upstream reference` → maxResults=6
|
|
28
|
+
* - `upstream reference` → maxInjectedChars=4000
|
|
29
|
+
*
|
|
30
|
+
* Keeping these in lockstep with upstream means the mandatory-recall tool
|
|
31
|
+
* description, budget clamps, and eval corpora line up with upstream's
|
|
32
|
+
* tuning — we inherit their calibration instead of re-tuning from scratch.
|
|
33
|
+
*/
|
|
34
|
+
const DEFAULT_MAX_SEARCH_RESULTS = 6;
|
|
35
|
+
const DEFAULT_MIN_SCORE = 0.1;
|
|
36
|
+
const DEFAULT_MAX_INJECTED_CHARS = 4000;
|
|
37
|
+
/** Hybrid retrieval weights — 70% vector cosine, 30% BM25 / ts_rank text score. */
|
|
38
|
+
const HYBRID_VECTOR_WEIGHT = 0.7;
|
|
39
|
+
const HYBRID_TEXT_WEIGHT = 0.3;
|
|
40
|
+
/**
|
|
41
|
+
* Phase 2 rerank defaults — ported from upstream.
|
|
42
|
+
*
|
|
43
|
+
* Sources:
|
|
44
|
+
* - `upstream reference` → lambda=0.7
|
|
45
|
+
* - `upstream reference` → halfLifeDays=30
|
|
46
|
+
*
|
|
47
|
+
* Both features are opt-in (enabled=false by default) — the Phase 2
|
|
48
|
+
* features are layered on top of hybrid search and don't change default
|
|
49
|
+
* behavior for callers that upgrade in place.
|
|
50
|
+
*/
|
|
51
|
+
const DEFAULT_MMR_ENABLED = false;
|
|
52
|
+
const DEFAULT_MMR_LAMBDA = 0.7;
|
|
53
|
+
const DEFAULT_TEMPORAL_DECAY_ENABLED = false;
|
|
54
|
+
const DEFAULT_TEMPORAL_DECAY_HALF_LIFE_DAYS = 30;
|
|
55
|
+
const DEFAULT_RECALL_TRACKING_ENABLED = false;
|
|
56
|
+
const DEFAULT_CITATIONS_MODE = 'auto';
|
|
57
|
+
/**
|
|
58
|
+
* Flush trigger margins (token counts) — aligned with upstream upstream.
|
|
59
|
+
*
|
|
60
|
+
* Sources:
|
|
61
|
+
* - `upstream reference` → softThreshold=4000
|
|
62
|
+
* - `upstream reference` → reserveFloor=20000
|
|
63
|
+
*/
|
|
64
|
+
const DEFAULT_FLUSH_SOFT_THRESHOLD_TOKENS = 4000;
|
|
65
|
+
const DEFAULT_FLUSH_RESERVE_FLOOR_TOKENS = 20000;
|
|
66
|
+
/** Hard cap on append calls per flush phase — prevents runaway writes. */
|
|
67
|
+
const DEFAULT_MAX_APPENDS_PER_FLUSH = 20;
|
|
68
|
+
/**
|
|
69
|
+
* Hard cap on agentic loop iterations inside {@link runMemoryFlush}.
|
|
70
|
+
*
|
|
71
|
+
* Each iteration = one model.invoke() followed by execution of any
|
|
72
|
+
* `memory_append` tool_calls it emits. Mirrors upstream's flush-plan
|
|
73
|
+
* loop cap; 8 is enough for ~2–3 reflections of batched notes while
|
|
74
|
+
* protecting against runaway cycles if the model refuses to stop.
|
|
75
|
+
*/
|
|
76
|
+
const DEFAULT_MAX_FLUSH_ITERATIONS = 8;
|
|
77
|
+
/** Path prefix enforced on every append. Paths outside this are rejected. */
|
|
78
|
+
const MEMORY_PATH_PREFIX = 'memory/';
|
|
79
|
+
/** Tool names — kept as constants so server code + tests never drift. */
|
|
80
|
+
const MEMORY_SEARCH_TOOL_NAME = 'memory_search';
|
|
81
|
+
const MEMORY_GET_TOOL_NAME = 'memory_get';
|
|
82
|
+
const MEMORY_APPEND_TOOL_NAME = 'memory_append';
|
|
83
|
+
/**
|
|
84
|
+
* Mandatory-recall description — the single most load-bearing line in the
|
|
85
|
+
* whole memory system. Do not soften, shorten, or reword without an eval run.
|
|
86
|
+
*
|
|
87
|
+
* Ported VERBATIM from upstream `extensions/memory-core/src/tools.ts:186`.
|
|
88
|
+
* The wiki/corpus clause is retained even though Phase 1 doesn't ship
|
|
89
|
+
* compiled-wiki supplements — keeping the string identical means upstream's
|
|
90
|
+
* eval corpora remain drop-in valid.
|
|
91
|
+
*/
|
|
92
|
+
const MEMORY_SEARCH_DESCRIPTION = 'Mandatory recall step: semantically search MEMORY.md + memory/*.md ' +
|
|
93
|
+
'(and optional session transcripts) before answering questions about ' +
|
|
94
|
+
'prior work, decisions, dates, people, preferences, or todos. Optional ' +
|
|
95
|
+
'`corpus=wiki` or `corpus=all` also searches registered compiled-wiki ' +
|
|
96
|
+
'supplements. If response has disabled=true, memory retrieval is ' +
|
|
97
|
+
'unavailable and should be surfaced to the user.';
|
|
98
|
+
/**
|
|
99
|
+
* Ported VERBATIM from upstream `extensions/memory-core/src/tools.ts:322`.
|
|
100
|
+
*/
|
|
101
|
+
const MEMORY_GET_DESCRIPTION = 'Safe snippet read from MEMORY.md or memory/*.md with optional from/lines; ' +
|
|
102
|
+
'`corpus=wiki` reads from registered compiled-wiki supplements. Use after ' +
|
|
103
|
+
'search to pull only the needed lines and keep context small.';
|
|
104
|
+
/**
|
|
105
|
+
* `memory_append` tool description.
|
|
106
|
+
*
|
|
107
|
+
* Phase 1 historically wrote to a single date-keyed file
|
|
108
|
+
* (`memory/YYYY-MM-DD.md`), ported verbatim from upstream. That scheme
|
|
109
|
+
* is now replaced by an 8-path canonical whitelist — see
|
|
110
|
+
* {@link ./paths.MEMORY_ALL_PATHS}. The tool description no longer
|
|
111
|
+
* names a specific file; the flush-turn prompt renders the full rubric
|
|
112
|
+
* inline so the model sees every writable path at inference time.
|
|
113
|
+
*/
|
|
114
|
+
const MEMORY_APPEND_DESCRIPTION = "Append a durable note to one of the agent's canonical memory documents. " +
|
|
115
|
+
'The `path` argument MUST be one of the whitelisted paths listed in the ' +
|
|
116
|
+
'flush prompt rubric — unknown paths are rejected. Content is merged into ' +
|
|
117
|
+
'the existing row for that document via UPSERT, so the same document ' +
|
|
118
|
+
'accumulates across sessions.';
|
|
119
|
+
/**
|
|
120
|
+
* Reply token that signals the flush turn produced no user-visible output.
|
|
121
|
+
* Ported VERBATIM from upstream `src/auto-reply/tokens.ts:4`.
|
|
122
|
+
*/
|
|
123
|
+
const SILENT_REPLY_TOKEN = 'NO_REPLY';
|
|
124
|
+
/**
|
|
125
|
+
* Placeholder replaced at flush time with the rendered path-rubric for
|
|
126
|
+
* the caller's scope. See `renderPathsRubric()` in `./paths.ts` and
|
|
127
|
+
* `resolveFlushPrompts()` in `../prompts/memoryFlushPrompt.ts`.
|
|
128
|
+
*
|
|
129
|
+
* Kept as a unique sentinel so `replaceAll` is safe even if the rubric
|
|
130
|
+
* content happens to contain regex metacharacters.
|
|
131
|
+
*/
|
|
132
|
+
const FLUSH_PROMPT_RUBRIC_PLACEHOLDER = '{{MEMORY_PATHS_RUBRIC}}';
|
|
133
|
+
/**
|
|
134
|
+
* Memory-flush prompts — canonical-document model.
|
|
135
|
+
*
|
|
136
|
+
* Every durable memory routes into one of 8 stable canonical documents
|
|
137
|
+
* (4 agent-tier + 4 user-tier). The rubric is injected at flush time so
|
|
138
|
+
* the model reads the authoritative path list with descriptions, and for
|
|
139
|
+
* isolated/autonomous agents the user-tier rows are transparently omitted
|
|
140
|
+
* from the rubric — making "user-tier writes require a scoped caller" a
|
|
141
|
+
* compile-time guarantee rather than a runtime check alone.
|
|
142
|
+
*
|
|
143
|
+
* Two-tier semantics the prompt enforces:
|
|
144
|
+
* - **agent/** — shared operational knowledge; every user of this agent
|
|
145
|
+
* benefits from rows written here. Do NOT put personal facts here.
|
|
146
|
+
* - **user/** — personalization for the specific caller only. Row is
|
|
147
|
+
* private to that user; other users never see it.
|
|
148
|
+
*/
|
|
149
|
+
const MEMORY_FLUSH_ROUTING_HINT = 'Route every note into exactly one of the canonical documents below by ' +
|
|
150
|
+
'picking the best match. Do NOT invent new paths; do NOT create date-keyed ' +
|
|
151
|
+
'files; unknown paths are rejected by the store.';
|
|
152
|
+
const MEMORY_FLUSH_TIER_HINT = 'Two tiers: `memory/agent/*` is SHARED operational knowledge visible to ' +
|
|
153
|
+
'every user of this agent — put successful patterns, pitfalls, domain ' +
|
|
154
|
+
'facts, and house-style there. `memory/user/*` is PRIVATE to the specific ' +
|
|
155
|
+
'caller — put their identity, preferences, projects, and references there. ' +
|
|
156
|
+
'Never put user-specific facts in an agent/* document.';
|
|
157
|
+
const MEMORY_FLUSH_READ_ONLY_HINT = 'Treat workspace bootstrap/reference files such as MEMORY.md, DREAMS.md, SOUL.md, TOOLS.md, and AGENTS.md as read-only during this flush; never overwrite, replace, or edit them.';
|
|
158
|
+
/**
|
|
159
|
+
* Learning hint — steers the flush turn to capture the things that
|
|
160
|
+
* matter most for future turns: reusable patterns, tool failures
|
|
161
|
+
* (so the same mistake is not repeated), explicit corrections, and
|
|
162
|
+
* durable user-specific facts. Append-only via `memory_append`; one
|
|
163
|
+
* note per lesson.
|
|
164
|
+
*/
|
|
165
|
+
const MEMORY_FLUSH_LEARNING_HINT = 'Capture durable lessons the agent (and future turns) should retain: ' +
|
|
166
|
+
'(a) successful task patterns and workflows → memory/agent/playbook.md; ' +
|
|
167
|
+
'(b) tool failures and schema mistakes → memory/agent/pitfalls.md; ' +
|
|
168
|
+
'(c) stable domain facts about the systems/APIs → memory/agent/domain.md; ' +
|
|
169
|
+
"(d) this user's preferences, tone, and corrections → memory/user/preferences.md; " +
|
|
170
|
+
"(e) this user's identity and role → memory/user/profile.md. " +
|
|
171
|
+
'Write one note per distinct lesson. Do not log conversation summaries ' +
|
|
172
|
+
'or anything derivable from the code or recent history.';
|
|
173
|
+
const MEMORY_FLUSH_RUBRIC_BLOCK = 'Canonical documents available for this turn (path — tag — description):\n' +
|
|
174
|
+
FLUSH_PROMPT_RUBRIC_PLACEHOLDER;
|
|
175
|
+
const DEFAULT_MEMORY_FLUSH_PROMPT = [
|
|
176
|
+
'Pre-compaction memory flush.',
|
|
177
|
+
MEMORY_FLUSH_ROUTING_HINT,
|
|
178
|
+
MEMORY_FLUSH_TIER_HINT,
|
|
179
|
+
MEMORY_FLUSH_READ_ONLY_HINT,
|
|
180
|
+
MEMORY_FLUSH_LEARNING_HINT,
|
|
181
|
+
'Call the `memory_append` tool for every note you want to persist, passing one of the whitelisted paths as the `path` argument. Do NOT describe what you are about to write; just call the tool.',
|
|
182
|
+
`If nothing worth storing, reply with exactly ${SILENT_REPLY_TOKEN}.`,
|
|
183
|
+
'',
|
|
184
|
+
MEMORY_FLUSH_RUBRIC_BLOCK,
|
|
185
|
+
].join('\n');
|
|
186
|
+
const DEFAULT_MEMORY_FLUSH_SYSTEM_PROMPT = [
|
|
187
|
+
'Pre-compaction memory flush turn.',
|
|
188
|
+
'The session is near auto-compaction; capture durable memories to disk.',
|
|
189
|
+
MEMORY_FLUSH_ROUTING_HINT,
|
|
190
|
+
MEMORY_FLUSH_TIER_HINT,
|
|
191
|
+
MEMORY_FLUSH_READ_ONLY_HINT,
|
|
192
|
+
MEMORY_FLUSH_LEARNING_HINT,
|
|
193
|
+
'Use the `memory_append` tool for every durable note, with `path` set to one of the whitelisted canonical documents. Never claim you wrote a note without actually calling the tool.',
|
|
194
|
+
`If there is nothing worth storing, reply with exactly ${SILENT_REPLY_TOKEN}.`,
|
|
195
|
+
'',
|
|
196
|
+
MEMORY_FLUSH_RUBRIC_BLOCK,
|
|
197
|
+
].join('\n');
|
|
198
|
+
|
|
199
|
+
exports.DEFAULT_CITATIONS_MODE = DEFAULT_CITATIONS_MODE;
|
|
200
|
+
exports.DEFAULT_FLUSH_RESERVE_FLOOR_TOKENS = DEFAULT_FLUSH_RESERVE_FLOOR_TOKENS;
|
|
201
|
+
exports.DEFAULT_FLUSH_SOFT_THRESHOLD_TOKENS = DEFAULT_FLUSH_SOFT_THRESHOLD_TOKENS;
|
|
202
|
+
exports.DEFAULT_MAX_APPENDS_PER_FLUSH = DEFAULT_MAX_APPENDS_PER_FLUSH;
|
|
203
|
+
exports.DEFAULT_MAX_FLUSH_ITERATIONS = DEFAULT_MAX_FLUSH_ITERATIONS;
|
|
204
|
+
exports.DEFAULT_MAX_INJECTED_CHARS = DEFAULT_MAX_INJECTED_CHARS;
|
|
205
|
+
exports.DEFAULT_MAX_SEARCH_RESULTS = DEFAULT_MAX_SEARCH_RESULTS;
|
|
206
|
+
exports.DEFAULT_MEMORY_DIMENSIONS = DEFAULT_MEMORY_DIMENSIONS;
|
|
207
|
+
exports.DEFAULT_MEMORY_FLUSH_PROMPT = DEFAULT_MEMORY_FLUSH_PROMPT;
|
|
208
|
+
exports.DEFAULT_MEMORY_FLUSH_SYSTEM_PROMPT = DEFAULT_MEMORY_FLUSH_SYSTEM_PROMPT;
|
|
209
|
+
exports.DEFAULT_MEMORY_MODEL = DEFAULT_MEMORY_MODEL;
|
|
210
|
+
exports.DEFAULT_MEMORY_PROVIDER = DEFAULT_MEMORY_PROVIDER;
|
|
211
|
+
exports.DEFAULT_MEMORY_SCHEMA = DEFAULT_MEMORY_SCHEMA;
|
|
212
|
+
exports.DEFAULT_MEMORY_TABLE = DEFAULT_MEMORY_TABLE;
|
|
213
|
+
exports.DEFAULT_MIN_SCORE = DEFAULT_MIN_SCORE;
|
|
214
|
+
exports.DEFAULT_MMR_ENABLED = DEFAULT_MMR_ENABLED;
|
|
215
|
+
exports.DEFAULT_MMR_LAMBDA = DEFAULT_MMR_LAMBDA;
|
|
216
|
+
exports.DEFAULT_RECALL_TRACKING_ENABLED = DEFAULT_RECALL_TRACKING_ENABLED;
|
|
217
|
+
exports.DEFAULT_TEMPORAL_DECAY_ENABLED = DEFAULT_TEMPORAL_DECAY_ENABLED;
|
|
218
|
+
exports.DEFAULT_TEMPORAL_DECAY_HALF_LIFE_DAYS = DEFAULT_TEMPORAL_DECAY_HALF_LIFE_DAYS;
|
|
219
|
+
exports.FLUSH_PROMPT_RUBRIC_PLACEHOLDER = FLUSH_PROMPT_RUBRIC_PLACEHOLDER;
|
|
220
|
+
exports.HYBRID_TEXT_WEIGHT = HYBRID_TEXT_WEIGHT;
|
|
221
|
+
exports.HYBRID_VECTOR_WEIGHT = HYBRID_VECTOR_WEIGHT;
|
|
222
|
+
exports.MEMORY_APPEND_DESCRIPTION = MEMORY_APPEND_DESCRIPTION;
|
|
223
|
+
exports.MEMORY_APPEND_TOOL_NAME = MEMORY_APPEND_TOOL_NAME;
|
|
224
|
+
exports.MEMORY_GET_DESCRIPTION = MEMORY_GET_DESCRIPTION;
|
|
225
|
+
exports.MEMORY_GET_TOOL_NAME = MEMORY_GET_TOOL_NAME;
|
|
226
|
+
exports.MEMORY_PATH_PREFIX = MEMORY_PATH_PREFIX;
|
|
227
|
+
exports.MEMORY_PHASE_FLUSHING = MEMORY_PHASE_FLUSHING;
|
|
228
|
+
exports.MEMORY_PHASE_NORMAL = MEMORY_PHASE_NORMAL;
|
|
229
|
+
exports.MEMORY_SEARCH_DESCRIPTION = MEMORY_SEARCH_DESCRIPTION;
|
|
230
|
+
exports.MEMORY_SEARCH_TOOL_NAME = MEMORY_SEARCH_TOOL_NAME;
|
|
231
|
+
exports.SILENT_REPLY_TOKEN = SILENT_REPLY_TOKEN;
|
|
232
|
+
//# sourceMappingURL=constants.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.cjs","sources":["../../../src/memory/constants.ts"],"sourcesContent":["/**\n * Autonomous memory — shared constants.\n *\n * Single source of truth for defaults, limits, and magic strings used across\n * the memory store, tools, flush phase, and tests. Changing a value here\n * changes it everywhere — no hunting through files.\n */\n\n/** Default embedding provider when {@link process.env.MEMORY_EMBEDDINGS_PROVIDER} is unset. */\nexport const DEFAULT_MEMORY_PROVIDER = 'bedrock' as const;\n\n/** Default embedding model (Titan v2 — AWS-native, 6× cheaper than Cohere v4). */\nexport const DEFAULT_MEMORY_MODEL = 'amazon.titan-embed-text-v2:0';\n\n/** Default vector width (Titan v2 supports 256 / 512 / 1024). */\nexport const DEFAULT_MEMORY_DIMENSIONS = 1024;\n\n/** Default Postgres table name; can be overridden via env for dev/prod sharing. */\nexport const DEFAULT_MEMORY_TABLE = 'agent_memories';\n\n/** Default Postgres schema. */\nexport const DEFAULT_MEMORY_SCHEMA = 'public';\n\n/** Phase values used by the flush-phase gate. */\nexport const MEMORY_PHASE_NORMAL = 'normal';\nexport const MEMORY_PHASE_FLUSHING = 'memory_flushing';\n\n/**\n * Search defaults — aligned with upstream's upstream defaults.\n *\n * Sources:\n * - `upstream reference` → maxResults=6\n * - `upstream reference` → maxInjectedChars=4000\n *\n * Keeping these in lockstep with upstream means the mandatory-recall tool\n * description, budget clamps, and eval corpora line up with upstream's\n * tuning — we inherit their calibration instead of re-tuning from scratch.\n */\nexport const DEFAULT_MAX_SEARCH_RESULTS = 6;\nexport const DEFAULT_MIN_SCORE = 0.1;\nexport const DEFAULT_MAX_INJECTED_CHARS = 4000;\n\n/** Hybrid retrieval weights — 70% vector cosine, 30% BM25 / ts_rank text score. */\nexport const HYBRID_VECTOR_WEIGHT = 0.7;\nexport const HYBRID_TEXT_WEIGHT = 0.3;\n\n/**\n * Phase 2 rerank defaults — ported from upstream.\n *\n * Sources:\n * - `upstream reference` → lambda=0.7\n * - `upstream reference` → halfLifeDays=30\n *\n * Both features are opt-in (enabled=false by default) — the Phase 2\n * features are layered on top of hybrid search and don't change default\n * behavior for callers that upgrade in place.\n */\nexport const DEFAULT_MMR_ENABLED = false;\nexport const DEFAULT_MMR_LAMBDA = 0.7;\nexport const DEFAULT_TEMPORAL_DECAY_ENABLED = false;\nexport const DEFAULT_TEMPORAL_DECAY_HALF_LIFE_DAYS = 30;\nexport const DEFAULT_RECALL_TRACKING_ENABLED = false;\nexport const DEFAULT_CITATIONS_MODE = 'auto' as const;\n\n/**\n * Flush trigger margins (token counts) — aligned with upstream upstream.\n *\n * Sources:\n * - `upstream reference` → softThreshold=4000\n * - `upstream reference` → reserveFloor=20000\n */\nexport const DEFAULT_FLUSH_SOFT_THRESHOLD_TOKENS = 4000;\nexport const DEFAULT_FLUSH_RESERVE_FLOOR_TOKENS = 20000;\n\n/** Hard cap on append calls per flush phase — prevents runaway writes. */\nexport const DEFAULT_MAX_APPENDS_PER_FLUSH = 20;\n\n/**\n * Hard cap on agentic loop iterations inside {@link runMemoryFlush}.\n *\n * Each iteration = one model.invoke() followed by execution of any\n * `memory_append` tool_calls it emits. Mirrors upstream's flush-plan\n * loop cap; 8 is enough for ~2–3 reflections of batched notes while\n * protecting against runaway cycles if the model refuses to stop.\n */\nexport const DEFAULT_MAX_FLUSH_ITERATIONS = 8;\n\n/** Path prefix enforced on every append. Paths outside this are rejected. */\nexport const MEMORY_PATH_PREFIX = 'memory/';\n\n/** Tool names — kept as constants so server code + tests never drift. */\nexport const MEMORY_SEARCH_TOOL_NAME = 'memory_search';\nexport const MEMORY_GET_TOOL_NAME = 'memory_get';\nexport const MEMORY_APPEND_TOOL_NAME = 'memory_append';\n\n/**\n * Mandatory-recall description — the single most load-bearing line in the\n * whole memory system. Do not soften, shorten, or reword without an eval run.\n *\n * Ported VERBATIM from upstream `extensions/memory-core/src/tools.ts:186`.\n * The wiki/corpus clause is retained even though Phase 1 doesn't ship\n * compiled-wiki supplements — keeping the string identical means upstream's\n * eval corpora remain drop-in valid.\n */\nexport const MEMORY_SEARCH_DESCRIPTION =\n 'Mandatory recall step: semantically search MEMORY.md + memory/*.md ' +\n '(and optional session transcripts) before answering questions about ' +\n 'prior work, decisions, dates, people, preferences, or todos. Optional ' +\n '`corpus=wiki` or `corpus=all` also searches registered compiled-wiki ' +\n 'supplements. If response has disabled=true, memory retrieval is ' +\n 'unavailable and should be surfaced to the user.';\n\n/**\n * Ported VERBATIM from upstream `extensions/memory-core/src/tools.ts:322`.\n */\nexport const MEMORY_GET_DESCRIPTION =\n 'Safe snippet read from MEMORY.md or memory/*.md with optional from/lines; ' +\n '`corpus=wiki` reads from registered compiled-wiki supplements. Use after ' +\n 'search to pull only the needed lines and keep context small.';\n\n/**\n * `memory_append` tool description.\n *\n * Phase 1 historically wrote to a single date-keyed file\n * (`memory/YYYY-MM-DD.md`), ported verbatim from upstream. That scheme\n * is now replaced by an 8-path canonical whitelist — see\n * {@link ./paths.MEMORY_ALL_PATHS}. The tool description no longer\n * names a specific file; the flush-turn prompt renders the full rubric\n * inline so the model sees every writable path at inference time.\n */\nexport const MEMORY_APPEND_DESCRIPTION =\n \"Append a durable note to one of the agent's canonical memory documents. \" +\n 'The `path` argument MUST be one of the whitelisted paths listed in the ' +\n 'flush prompt rubric — unknown paths are rejected. Content is merged into ' +\n 'the existing row for that document via UPSERT, so the same document ' +\n 'accumulates across sessions.';\n\n/**\n * Reply token that signals the flush turn produced no user-visible output.\n * Ported VERBATIM from upstream `src/auto-reply/tokens.ts:4`.\n */\nexport const SILENT_REPLY_TOKEN = 'NO_REPLY';\n\n/**\n * Placeholder replaced at flush time with the rendered path-rubric for\n * the caller's scope. See `renderPathsRubric()` in `./paths.ts` and\n * `resolveFlushPrompts()` in `../prompts/memoryFlushPrompt.ts`.\n *\n * Kept as a unique sentinel so `replaceAll` is safe even if the rubric\n * content happens to contain regex metacharacters.\n */\nexport const FLUSH_PROMPT_RUBRIC_PLACEHOLDER = '{{MEMORY_PATHS_RUBRIC}}';\n\n/**\n * Memory-flush prompts — canonical-document model.\n *\n * Every durable memory routes into one of 8 stable canonical documents\n * (4 agent-tier + 4 user-tier). The rubric is injected at flush time so\n * the model reads the authoritative path list with descriptions, and for\n * isolated/autonomous agents the user-tier rows are transparently omitted\n * from the rubric — making \"user-tier writes require a scoped caller\" a\n * compile-time guarantee rather than a runtime check alone.\n *\n * Two-tier semantics the prompt enforces:\n * - **agent/** — shared operational knowledge; every user of this agent\n * benefits from rows written here. Do NOT put personal facts here.\n * - **user/** — personalization for the specific caller only. Row is\n * private to that user; other users never see it.\n */\nconst MEMORY_FLUSH_ROUTING_HINT =\n 'Route every note into exactly one of the canonical documents below by ' +\n 'picking the best match. Do NOT invent new paths; do NOT create date-keyed ' +\n 'files; unknown paths are rejected by the store.';\n\nconst MEMORY_FLUSH_TIER_HINT =\n 'Two tiers: `memory/agent/*` is SHARED operational knowledge visible to ' +\n 'every user of this agent — put successful patterns, pitfalls, domain ' +\n 'facts, and house-style there. `memory/user/*` is PRIVATE to the specific ' +\n 'caller — put their identity, preferences, projects, and references there. ' +\n 'Never put user-specific facts in an agent/* document.';\n\nconst MEMORY_FLUSH_READ_ONLY_HINT =\n 'Treat workspace bootstrap/reference files such as MEMORY.md, DREAMS.md, SOUL.md, TOOLS.md, and AGENTS.md as read-only during this flush; never overwrite, replace, or edit them.';\n\n/**\n * Learning hint — steers the flush turn to capture the things that\n * matter most for future turns: reusable patterns, tool failures\n * (so the same mistake is not repeated), explicit corrections, and\n * durable user-specific facts. Append-only via `memory_append`; one\n * note per lesson.\n */\nconst MEMORY_FLUSH_LEARNING_HINT =\n 'Capture durable lessons the agent (and future turns) should retain: ' +\n '(a) successful task patterns and workflows → memory/agent/playbook.md; ' +\n '(b) tool failures and schema mistakes → memory/agent/pitfalls.md; ' +\n '(c) stable domain facts about the systems/APIs → memory/agent/domain.md; ' +\n \"(d) this user's preferences, tone, and corrections → memory/user/preferences.md; \" +\n \"(e) this user's identity and role → memory/user/profile.md. \" +\n 'Write one note per distinct lesson. Do not log conversation summaries ' +\n 'or anything derivable from the code or recent history.';\n\nconst MEMORY_FLUSH_RUBRIC_BLOCK =\n 'Canonical documents available for this turn (path — tag — description):\\n' +\n FLUSH_PROMPT_RUBRIC_PLACEHOLDER;\n\nexport const DEFAULT_MEMORY_FLUSH_PROMPT = [\n 'Pre-compaction memory flush.',\n MEMORY_FLUSH_ROUTING_HINT,\n MEMORY_FLUSH_TIER_HINT,\n MEMORY_FLUSH_READ_ONLY_HINT,\n MEMORY_FLUSH_LEARNING_HINT,\n 'Call the `memory_append` tool for every note you want to persist, passing one of the whitelisted paths as the `path` argument. Do NOT describe what you are about to write; just call the tool.',\n `If nothing worth storing, reply with exactly ${SILENT_REPLY_TOKEN}.`,\n '',\n MEMORY_FLUSH_RUBRIC_BLOCK,\n].join('\\n');\n\nexport const DEFAULT_MEMORY_FLUSH_SYSTEM_PROMPT = [\n 'Pre-compaction memory flush turn.',\n 'The session is near auto-compaction; capture durable memories to disk.',\n MEMORY_FLUSH_ROUTING_HINT,\n MEMORY_FLUSH_TIER_HINT,\n MEMORY_FLUSH_READ_ONLY_HINT,\n MEMORY_FLUSH_LEARNING_HINT,\n 'Use the `memory_append` tool for every durable note, with `path` set to one of the whitelisted canonical documents. Never claim you wrote a note without actually calling the tool.',\n `If there is nothing worth storing, reply with exactly ${SILENT_REPLY_TOKEN}.`,\n '',\n MEMORY_FLUSH_RUBRIC_BLOCK,\n].join('\\n');\n"],"names":[],"mappings":";;AAAA;;;;;;AAMG;AAEH;AACO,MAAM,uBAAuB,GAAG;AAEvC;AACO,MAAM,oBAAoB,GAAG;AAEpC;AACO,MAAM,yBAAyB,GAAG;AAEzC;AACO,MAAM,oBAAoB,GAAG;AAEpC;AACO,MAAM,qBAAqB,GAAG;AAErC;AACO,MAAM,mBAAmB,GAAG;AAC5B,MAAM,qBAAqB,GAAG;AAErC;;;;;;;;;;AAUG;AACI,MAAM,0BAA0B,GAAG;AACnC,M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