agentfootprint 6.44.0 → 7.0.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/AGENTS.md +4 -0
- package/CLAUDE.md +4 -0
- package/README.md +141 -167
- package/ai-instructions/claude-code/SKILL.md +11 -0
- package/ai-instructions/setup.sh +0 -0
- package/dist/adapters/llm/BrowserOpenAIProvider.js +1 -1
- package/dist/adapters/llm/MockProvider.js +2 -1
- package/dist/adapters/llm/MockProvider.js.map +1 -1
- package/dist/core/agent/buildAgentChart.js +2 -1
- package/dist/core/agent/buildAgentChart.js.map +1 -1
- package/dist/core/agent/buildDynamicAgentChart.js +3 -1
- package/dist/core/agent/buildDynamicAgentChart.js.map +1 -1
- package/dist/core/agent/stages/pickEntry.js +3 -1
- package/dist/core/agent/stages/pickEntry.js.map +1 -1
- package/dist/debug/finders.js +29 -0
- package/dist/debug/finders.js.map +1 -0
- package/dist/debug.js +134 -0
- package/dist/debug.js.map +1 -0
- package/dist/esm/adapters/identity/agentcore.d.ts +100 -0
- package/dist/esm/adapters/llm/AnthropicProvider.d.ts +130 -0
- package/dist/esm/adapters/llm/BedrockProvider.d.ts +100 -0
- package/dist/esm/adapters/llm/BrowserAnthropicProvider.d.ts +41 -0
- package/dist/esm/adapters/llm/BrowserOpenAIProvider.d.ts +95 -0
- package/dist/esm/adapters/llm/BrowserOpenAIProvider.js +1 -1
- package/dist/esm/adapters/llm/MockProvider.d.ts +154 -0
- package/dist/esm/adapters/llm/MockProvider.js +2 -1
- package/dist/esm/adapters/llm/MockProvider.js.map +1 -1
- package/dist/esm/adapters/llm/OpenAIProvider.d.ts +220 -0
- package/dist/esm/adapters/llm/createProvider.d.ts +85 -0
- package/dist/esm/adapters/memory/agentcore.d.ts +146 -0
- package/dist/esm/adapters/memory/bedrockAgentMemory.d.ts +95 -0
- package/dist/esm/adapters/memory/redis.d.ts +127 -0
- package/dist/esm/adapters/observability/agentcore.d.ts +67 -0
- package/dist/esm/adapters/observability/audit.d.ts +254 -0
- package/dist/esm/adapters/observability/cloudwatch.d.ts +96 -0
- package/dist/esm/adapters/observability/otel.d.ts +237 -0
- package/dist/esm/adapters/observability/xray.d.ts +88 -0
- package/dist/esm/adapters/types.d.ts +378 -0
- package/dist/esm/bridge/eventMeta.d.ts +59 -0
- package/dist/esm/cache/CacheDecisionSubflow.d.ts +85 -0
- package/dist/esm/cache/CacheGateDecider.d.ts +127 -0
- package/dist/esm/cache/applyCachePolicy.d.ts +37 -0
- package/dist/esm/cache/cacheRecorder.d.ts +85 -0
- package/dist/esm/cache/index.d.ts +33 -0
- package/dist/esm/cache/strategies/AnthropicCacheStrategy.d.ts +38 -0
- package/dist/esm/cache/strategies/BedrockCacheStrategy.d.ts +33 -0
- package/dist/esm/cache/strategies/NoOpCacheStrategy.d.ts +29 -0
- package/dist/esm/cache/strategies/OpenAICacheStrategy.d.ts +36 -0
- package/dist/esm/cache/strategyRegistry.d.ts +45 -0
- package/dist/esm/cache/types.d.ts +243 -0
- package/dist/esm/conventions.d.ts +203 -0
- package/dist/esm/core/Agent.d.ts +355 -0
- package/dist/esm/core/LLMCall.d.ts +139 -0
- package/dist/esm/core/RunnerBase.d.ts +267 -0
- package/dist/esm/core/agent/AgentBuilder.d.ts +565 -0
- package/dist/esm/core/agent/buildAgentChart.d.ts +109 -0
- package/dist/esm/core/agent/buildAgentChart.js +2 -1
- package/dist/esm/core/agent/buildAgentChart.js.map +1 -1
- package/dist/esm/core/agent/buildAgentMessageApiChart.d.ts +40 -0
- package/dist/esm/core/agent/buildCacheSubflow.d.ts +35 -0
- package/dist/esm/core/agent/buildDynamicAgentChart.d.ts +56 -0
- package/dist/esm/core/agent/buildDynamicAgentChart.js +3 -1
- package/dist/esm/core/agent/buildDynamicAgentChart.js.map +1 -1
- package/dist/esm/core/agent/buildMessageApiChart.d.ts +47 -0
- package/dist/esm/core/agent/buildToolRegistry.d.ts +61 -0
- package/dist/esm/core/agent/memoryRecallInjections.d.ts +8 -0
- package/dist/esm/core/agent/stages/breakFinal.d.ts +22 -0
- package/dist/esm/core/agent/stages/callLLM.d.ts +74 -0
- package/dist/esm/core/agent/stages/pickEntry.d.ts +19 -0
- package/dist/esm/core/agent/stages/pickEntry.js +3 -1
- package/dist/esm/core/agent/stages/pickEntry.js.map +1 -1
- package/dist/esm/core/agent/stages/prepareFinal.d.ts +19 -0
- package/dist/esm/core/agent/stages/reliabilityExecution.d.ts +135 -0
- package/dist/esm/core/agent/stages/route.d.ts +18 -0
- package/dist/esm/core/agent/stages/seed.d.ts +53 -0
- package/dist/esm/core/agent/stages/toolCalls.d.ts +76 -0
- package/dist/esm/core/agent/toolArgsValidation.d.ts +62 -0
- package/dist/esm/core/agent/types.d.ts +382 -0
- package/dist/esm/core/agent/validators.d.ts +52 -0
- package/dist/esm/core/cost.d.ts +38 -0
- package/dist/esm/core/flowchartAsTool.d.ts +200 -0
- package/dist/esm/core/humanizeLLMError.d.ts +23 -0
- package/dist/esm/core/outputFallback.d.ts +139 -0
- package/dist/esm/core/outputSchema.d.ts +127 -0
- package/dist/esm/core/pause.d.ts +74 -0
- package/dist/esm/core/runCheckpoint.d.ts +179 -0
- package/dist/esm/core/runner.d.ts +203 -0
- package/dist/esm/core/slots/buildMessagesSlot.d.ts +40 -0
- package/dist/esm/core/slots/buildSystemPromptSlot.d.ts +41 -0
- package/dist/esm/core/slots/buildThinkingSubflow.d.ts +40 -0
- package/dist/esm/core/slots/buildToolsSlot.d.ts +60 -0
- package/dist/esm/core/slots/helpers.d.ts +27 -0
- package/dist/esm/core/toolContract.d.ts +43 -0
- package/dist/esm/core/tools.d.ts +90 -0
- package/dist/esm/core/translator.d.ts +94 -0
- package/dist/esm/core-flow/Conditional.d.ts +119 -0
- package/dist/esm/core-flow/Loop.d.ts +160 -0
- package/dist/esm/core-flow/Parallel.d.ts +360 -0
- package/dist/esm/core-flow/Sequence.d.ts +133 -0
- package/dist/esm/debug/finders.d.ts +12 -0
- package/dist/esm/debug/finders.js +13 -0
- package/dist/esm/debug/finders.js.map +1 -0
- package/dist/esm/debug.d.ts +25 -0
- package/dist/esm/debug.js +54 -0
- package/dist/esm/debug.js.map +1 -0
- package/dist/esm/events/dispatcher.d.ts +134 -0
- package/dist/esm/events/payloads.d.ts +761 -0
- package/dist/esm/events/registry.d.ts +198 -0
- package/dist/esm/events/types.d.ts +70 -0
- package/dist/esm/events.d.ts +18 -0
- package/dist/esm/events.js +22 -0
- package/dist/esm/events.js.map +1 -0
- package/dist/esm/identity/kinds.d.ts +36 -0
- package/dist/esm/identity/staticTokens.d.ts +28 -0
- package/dist/esm/identity/types.d.ts +113 -0
- package/dist/esm/identity/withCredentialRetry.d.ts +64 -0
- package/dist/esm/identity.d.ts +31 -0
- package/dist/esm/index.d.ts +44 -0
- package/dist/esm/index.js +7 -52
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/injection-engine.d.ts +4 -0
- package/dist/esm/lib/canonicalJson.d.ts +56 -0
- package/dist/esm/lib/context-bisect/ablation.d.ts +109 -0
- package/dist/esm/lib/context-bisect/bisect.d.ts +75 -0
- package/dist/esm/lib/context-bisect/cost.d.ts +37 -0
- package/dist/esm/lib/context-bisect/index.d.ts +31 -0
- package/dist/esm/lib/context-bisect/index.js +3 -0
- package/dist/esm/lib/context-bisect/index.js.map +1 -1
- package/dist/esm/lib/context-bisect/llmEdgeWeigher.d.ts +124 -0
- package/dist/esm/lib/context-bisect/localize.d.ts +152 -0
- package/dist/esm/lib/context-bisect/localize.js +2 -0
- package/dist/esm/lib/context-bisect/localize.js.map +1 -1
- package/dist/esm/lib/context-bisect/loop-recall.d.ts +97 -0
- package/dist/esm/lib/context-bisect/missingContext.d.ts +71 -0
- package/dist/esm/lib/context-bisect/restoration.d.ts +39 -0
- package/dist/esm/lib/context-bisect/toBacktrackTrace.d.ts +138 -0
- package/dist/esm/lib/context-bisect/trajectory.d.ts +168 -0
- package/dist/esm/lib/context-bisect/types.d.ts +448 -0
- package/dist/esm/lib/context-bisect/walk-to-root.d.ts +103 -0
- package/dist/esm/lib/influence-core/attributability.d.ts +72 -0
- package/dist/esm/lib/influence-core/cache.d.ts +94 -0
- package/dist/esm/lib/influence-core/contrastive.d.ts +26 -0
- package/dist/esm/lib/influence-core/index.d.ts +34 -0
- package/dist/esm/lib/influence-core/margin.d.ts +33 -0
- package/dist/esm/lib/influence-core/signals.d.ts +128 -0
- package/dist/esm/lib/influence-core/similarity.d.ts +25 -0
- package/dist/esm/lib/influence-core/types.d.ts +252 -0
- package/dist/esm/lib/injection-engine/SkillRegistry.d.ts +147 -0
- package/dist/esm/lib/injection-engine/buildInjectionEngineSubflow.d.ts +110 -0
- package/dist/esm/lib/injection-engine/buildInjectionEngineSubflow.js +1 -0
- package/dist/esm/lib/injection-engine/buildInjectionEngineSubflow.js.map +1 -1
- package/dist/esm/lib/injection-engine/entryScorer.d.ts +93 -0
- package/dist/esm/lib/injection-engine/entryScorer.js +172 -0
- package/dist/esm/lib/injection-engine/entryScorer.js.map +1 -0
- package/dist/esm/lib/injection-engine/evaluator.d.ts +24 -0
- package/dist/esm/lib/injection-engine/factories/defineFact.d.ts +60 -0
- package/dist/esm/lib/injection-engine/factories/defineInjection.d.ts +41 -0
- package/dist/esm/lib/injection-engine/factories/defineInstruction.d.ts +78 -0
- package/dist/esm/lib/injection-engine/factories/defineRelevanceHint.d.ts +26 -0
- package/dist/esm/lib/injection-engine/factories/defineSkill.d.ts +160 -0
- package/dist/esm/lib/injection-engine/factories/defineSteering.d.ts +39 -0
- package/dist/esm/lib/injection-engine/index.d.ts +22 -0
- package/dist/esm/lib/injection-engine/index.js +2 -1
- package/dist/esm/lib/injection-engine/index.js.map +1 -1
- package/dist/esm/lib/injection-engine/skillContract.d.ts +29 -0
- package/dist/esm/lib/injection-engine/skillGraph.d.ts +290 -0
- package/dist/esm/lib/injection-engine/skillGraph.js +38 -43
- package/dist/esm/lib/injection-engine/skillGraph.js.map +1 -1
- package/dist/esm/lib/injection-engine/skillGraphCheckup.d.ts +49 -0
- package/dist/esm/lib/injection-engine/skillTools.d.ts +72 -0
- package/dist/esm/lib/injection-engine/softmax.d.ts +11 -0
- package/dist/esm/lib/injection-engine/types.d.ts +229 -0
- package/dist/esm/lib/injection-engine/types.js.map +1 -1
- package/dist/esm/lib/lazyRequire.d.ts +29 -0
- package/dist/esm/lib/mcp/index.d.ts +9 -0
- package/dist/esm/lib/mcp/mcpClient.d.ts +46 -0
- package/dist/esm/lib/mcp/mockMcpClient.d.ts +65 -0
- package/dist/esm/lib/mcp/types.d.ts +133 -0
- package/dist/esm/lib/rag/defineRAG.d.ts +139 -0
- package/dist/esm/lib/rag/defineRAG.js +3 -3
- package/dist/esm/lib/rag/index.d.ts +7 -0
- package/dist/esm/lib/rag/indexDocuments.d.ts +106 -0
- package/dist/esm/lib/rag/indexDocuments.js +2 -1
- package/dist/esm/lib/rag/indexDocuments.js.map +1 -1
- package/dist/esm/lib/tool-lint/analyze.d.ts +83 -0
- package/dist/esm/lib/tool-lint/cli.d.ts +43 -0
- package/dist/esm/lib/tool-lint/format.d.ts +18 -0
- package/dist/esm/lib/tool-lint/index.d.ts +23 -0
- package/dist/esm/lib/tool-lint/rules.d.ts +85 -0
- package/dist/esm/lib/tool-lint/types.d.ts +155 -0
- package/dist/esm/lib/trace-toolpack/bounded.d.ts +47 -0
- package/dist/esm/lib/trace-toolpack/debugPrompt.d.ts +19 -0
- package/dist/esm/lib/trace-toolpack/index.d.ts +20 -0
- package/dist/esm/lib/trace-toolpack/lazyToolpack.d.ts +35 -0
- package/dist/esm/lib/trace-toolpack/selfExplain.d.ts +100 -0
- package/dist/esm/lib/trace-toolpack/traceDebugAgent.d.ts +42 -0
- package/dist/esm/lib/trace-toolpack/traceToolpack.d.ts +69 -0
- package/dist/esm/lib/trace-toolpack/types.d.ts +59 -0
- package/dist/esm/llm-providers.d.ts +26 -0
- package/dist/esm/locales/index.d.ts +141 -0
- package/dist/esm/locales/index.js +7 -0
- package/dist/esm/locales/index.js.map +1 -1
- package/dist/esm/memory/beats/extractBeats.d.ts +61 -0
- package/dist/esm/memory/beats/extractor.d.ts +47 -0
- package/dist/esm/memory/beats/formatAsNarrative.d.ts +62 -0
- package/dist/esm/memory/beats/heuristicExtractor.d.ts +37 -0
- package/dist/esm/memory/beats/index.d.ts +12 -0
- package/dist/esm/memory/beats/llmExtractor.d.ts +56 -0
- package/dist/esm/memory/beats/types.d.ts +60 -0
- package/dist/esm/memory/beats/writeBeats.d.ts +22 -0
- package/dist/esm/memory/causal/evidenceRecorder.d.ts +66 -0
- package/dist/esm/memory/causal/index.d.ts +6 -0
- package/dist/esm/memory/causal/loadSnapshot.d.ts +51 -0
- package/dist/esm/memory/causal/snapshotPipeline.d.ts +35 -0
- package/dist/esm/memory/causal/types.d.ts +134 -0
- package/dist/esm/memory/causal/types.js.map +1 -1
- package/dist/esm/memory/causal/writeSnapshot.d.ts +73 -0
- package/dist/esm/memory/define.d.ts +63 -0
- package/dist/esm/memory/define.types.d.ts +278 -0
- package/dist/esm/memory/define.types.js +6 -4
- package/dist/esm/memory/define.types.js.map +1 -1
- package/dist/esm/memory/embedding/cosine.d.ts +18 -0
- package/dist/esm/memory/embedding/embedMessages.d.ts +58 -0
- package/dist/esm/memory/embedding/index.d.ts +8 -0
- package/dist/esm/memory/embedding/loadRelevant.d.ts +51 -0
- package/dist/esm/memory/embedding/mockEmbedder.d.ts +22 -0
- package/dist/esm/memory/embedding/types.d.ts +46 -0
- package/dist/esm/memory/entry/decay.d.ts +36 -0
- package/dist/esm/memory/entry/index.d.ts +2 -0
- package/dist/esm/memory/entry/types.d.ts +140 -0
- package/dist/esm/memory/facts/extractFacts.d.ts +50 -0
- package/dist/esm/memory/facts/extractor.d.ts +33 -0
- package/dist/esm/memory/facts/formatFacts.d.ts +60 -0
- package/dist/esm/memory/facts/index.d.ts +14 -0
- package/dist/esm/memory/facts/llmFactExtractor.d.ts +64 -0
- package/dist/esm/memory/facts/loadFacts.d.ts +43 -0
- package/dist/esm/memory/facts/patternFactExtractor.d.ts +2 -0
- package/dist/esm/memory/facts/types.d.ts +68 -0
- package/dist/esm/memory/facts/writeFacts.d.ts +19 -0
- package/dist/esm/memory/identity/index.d.ts +2 -0
- package/dist/esm/memory/identity/types.d.ts +49 -0
- package/dist/esm/memory/index.d.ts +19 -0
- package/dist/esm/memory/pipeline/auto.d.ts +59 -0
- package/dist/esm/memory/pipeline/default.d.ts +49 -0
- package/dist/esm/memory/pipeline/ephemeral.d.ts +28 -0
- package/dist/esm/memory/pipeline/fact.d.ts +26 -0
- package/dist/esm/memory/pipeline/index.d.ts +13 -0
- package/dist/esm/memory/pipeline/narrative.d.ts +35 -0
- package/dist/esm/memory/pipeline/semantic.d.ts +37 -0
- package/dist/esm/memory/pipeline/types.d.ts +31 -0
- package/dist/esm/memory/stages/formatDefault.d.ts +64 -0
- package/dist/esm/memory/stages/index.d.ts +13 -0
- package/dist/esm/memory/stages/loadRecent.d.ts +49 -0
- package/dist/esm/memory/stages/pickByBudget.d.ts +63 -0
- package/dist/esm/memory/stages/summarize.d.ts +87 -0
- package/dist/esm/memory/stages/tokenize.d.ts +43 -0
- package/dist/esm/memory/stages/types.d.ts +75 -0
- package/dist/esm/memory/stages/writeMessages.d.ts +71 -0
- package/dist/esm/memory/store/InMemoryStore.d.ts +62 -0
- package/dist/esm/memory/store/index.d.ts +2 -0
- package/dist/esm/memory/store/types.d.ts +223 -0
- package/dist/esm/memory/wire/index.d.ts +2 -0
- package/dist/esm/memory/wire/mountMemoryPipeline.d.ts +108 -0
- package/dist/esm/memory-providers.d.ts +37 -0
- package/dist/esm/observability/contextError/finders/compareFinders.d.ts +19 -0
- package/dist/esm/observability/contextError/finders/index.d.ts +22 -0
- package/dist/esm/observability/contextError/finders/rankSuspects.d.ts +2 -0
- package/dist/esm/observability/contextError/finders/removeAndRetry.d.ts +11 -0
- package/dist/esm/observability/contextError/finders/shrinkToCause.d.ts +11 -0
- package/dist/esm/observability/contextError/finders/testManyCombos.d.ts +11 -0
- package/dist/esm/observability/contextError/finders/traceSteps.d.ts +2 -0
- package/dist/esm/observability/contextError/finders/types.d.ts +88 -0
- package/dist/esm/observability-providers.d.ts +46 -0
- package/dist/esm/observe.d.ts +57 -0
- package/dist/esm/observe.js +7 -36
- package/dist/esm/observe.js.map +1 -1
- package/dist/esm/patterns/Debate.d.ts +39 -0
- package/dist/esm/patterns/MapReduce.d.ts +66 -0
- package/dist/esm/patterns/Reflection.d.ts +51 -0
- package/dist/esm/patterns/SelfConsistency.d.ts +43 -0
- package/dist/esm/patterns/Swarm.d.ts +60 -0
- package/dist/esm/patterns/ToT.d.ts +53 -0
- package/dist/esm/patterns/index.d.ts +22 -0
- package/dist/esm/providers.d.ts +33 -0
- package/dist/esm/providers.js +1 -1
- package/dist/esm/providers.js.map +1 -1
- package/dist/esm/recorders/core/AgentRecorder.d.ts +15 -0
- package/dist/esm/recorders/core/CompositionRecorder.d.ts +17 -0
- package/dist/esm/recorders/core/ContextEvaluatedRecorder.d.ts +23 -0
- package/dist/esm/recorders/core/ContextRecorder.d.ts +47 -0
- package/dist/esm/recorders/core/CostRecorder.d.ts +14 -0
- package/dist/esm/recorders/core/EmitBridge.d.ts +30 -0
- package/dist/esm/recorders/core/ErrorBridge.d.ts +38 -0
- package/dist/esm/recorders/core/EvalRecorder.d.ts +16 -0
- package/dist/esm/recorders/core/MemoryRecorder.d.ts +17 -0
- package/dist/esm/recorders/core/PermissionRecorder.d.ts +16 -0
- package/dist/esm/recorders/core/ReliabilityRecorder.d.ts +24 -0
- package/dist/esm/recorders/core/SkillRecorder.d.ts +14 -0
- package/dist/esm/recorders/core/StreamRecorder.d.ts +15 -0
- package/dist/esm/recorders/core/ToolsRecorder.d.ts +18 -0
- package/dist/esm/recorders/core/ValidationRecorder.d.ts +16 -0
- package/dist/esm/recorders/core/contextEngineering.d.ts +136 -0
- package/dist/esm/recorders/core/typedEmit.d.ts +34 -0
- package/dist/esm/recorders/core/types.d.ts +97 -0
- package/dist/esm/recorders/observability/AgentThinkingTraceRecorder.d.ts +117 -0
- package/dist/esm/recorders/observability/BoundaryRecorder.d.ts +546 -0
- package/dist/esm/recorders/observability/FlowchartRecorder.d.ts +220 -0
- package/dist/esm/recorders/observability/LiveStateRecorder.d.ts +250 -0
- package/dist/esm/recorders/observability/LoggingRecorder.d.ts +91 -0
- package/dist/esm/recorders/observability/RouteRecorder.d.ts +83 -0
- package/dist/esm/recorders/observability/RunStepRecorder.d.ts +231 -0
- package/dist/esm/recorders/observability/StatusRecorder.d.ts +36 -0
- package/dist/esm/recorders/observability/ToolChoiceRecorder.d.ts +164 -0
- package/dist/esm/recorders/observability/ToolLineageRecorder.d.ts +71 -0
- package/dist/esm/recorders/observability/commentary/commentaryTemplates.d.ts +105 -0
- package/dist/esm/recorders/observability/internal/ActorArrowClassifier.d.ts +25 -0
- package/dist/esm/recorders/observability/internal/CandidateAnswerBuffer.d.ts +28 -0
- package/dist/esm/recorders/observability/internal/ForkTracker.d.ts +60 -0
- package/dist/esm/recorders/observability/internal/RootInferrer.d.ts +51 -0
- package/dist/esm/recorders/observability/internal/SequenceSiblingTracker.d.ts +24 -0
- package/dist/esm/recorders/observability/localObservability.d.ts +48 -0
- package/dist/esm/recorders/observability/observeRunId.d.ts +36 -0
- package/dist/esm/recorders/observability/status/statusTemplates.d.ts +106 -0
- package/dist/esm/recorders/observability/trace.d.ts +119 -0
- package/dist/esm/reliability/CircuitBreaker.d.ts +75 -0
- package/dist/esm/reliability/buildReliabilityGateChart.d.ts +53 -0
- package/dist/esm/reliability/classifyError.d.ts +28 -0
- package/dist/esm/reliability/index.d.ts +35 -0
- package/dist/esm/reliability/types.d.ts +327 -0
- package/dist/esm/resilience/fallbackProvider.d.ts +33 -0
- package/dist/esm/resilience/index.d.ts +21 -0
- package/dist/esm/resilience/withCircuitBreaker.d.ts +129 -0
- package/dist/esm/resilience/withFallback.d.ts +45 -0
- package/dist/esm/resilience/withRetry.d.ts +71 -0
- package/dist/esm/security/PermissionPolicy.d.ts +124 -0
- package/dist/esm/security/PolicyHaltError.d.ts +72 -0
- package/dist/esm/security/extractSequence.d.ts +46 -0
- package/dist/esm/security/index.d.ts +44 -0
- package/dist/esm/security/thinkingRedaction.d.ts +50 -0
- package/dist/esm/status.d.ts +54 -0
- package/dist/esm/status.js +13 -4
- package/dist/esm/status.js.map +1 -1
- package/dist/esm/strategies/attach.d.ts +47 -0
- package/dist/esm/strategies/compose.d.ts +48 -0
- package/dist/esm/strategies/defaults/chatBubbleLiveStatus.d.ts +36 -0
- package/dist/esm/strategies/defaults/consoleObservability.d.ts +42 -0
- package/dist/esm/strategies/defaults/inMemorySinkCost.d.ts +50 -0
- package/dist/esm/strategies/defaults/index.d.ts +30 -0
- package/dist/esm/strategies/defaults/noopLens.d.ts +28 -0
- package/dist/esm/strategies/index.d.ts +36 -0
- package/dist/esm/strategies/registry.d.ts +70 -0
- package/dist/esm/strategies/types.d.ts +303 -0
- package/dist/esm/stream.d.ts +82 -0
- package/dist/esm/thinking/AnthropicThinkingHandler.d.ts +42 -0
- package/dist/esm/thinking/MockThinkingHandler.d.ts +50 -0
- package/dist/esm/thinking/OpenAIThinkingHandler.d.ts +37 -0
- package/dist/esm/thinking/index.d.ts +51 -0
- package/dist/esm/thinking/registry.d.ts +33 -0
- package/dist/esm/thinking/types.d.ts +162 -0
- package/dist/esm/tool-providers/gatedTools.d.ts +36 -0
- package/dist/esm/tool-providers/index.d.ts +41 -0
- package/dist/esm/tool-providers/skillScopedTools.d.ts +45 -0
- package/dist/esm/tool-providers/staticTools.d.ts +21 -0
- package/dist/esm/tool-providers/types.d.ts +138 -0
- package/dist/events.js +42 -0
- package/dist/events.js.map +1 -0
- package/dist/index.js +7 -117
- package/dist/index.js.map +1 -1
- package/dist/lib/context-bisect/index.js +3 -0
- package/dist/lib/context-bisect/index.js.map +1 -1
- package/dist/lib/context-bisect/localize.js +2 -0
- package/dist/lib/context-bisect/localize.js.map +1 -1
- package/dist/lib/injection-engine/buildInjectionEngineSubflow.js +1 -0
- package/dist/lib/injection-engine/buildInjectionEngineSubflow.js.map +1 -1
- package/dist/lib/injection-engine/entryScorer.js +178 -0
- package/dist/lib/injection-engine/entryScorer.js.map +1 -0
- package/dist/lib/injection-engine/index.js +6 -2
- package/dist/lib/injection-engine/index.js.map +1 -1
- package/dist/lib/injection-engine/skillGraph.js +40 -45
- package/dist/lib/injection-engine/skillGraph.js.map +1 -1
- package/dist/lib/injection-engine/types.js.map +1 -1
- package/dist/lib/rag/defineRAG.js +3 -3
- package/dist/lib/rag/indexDocuments.js +2 -1
- package/dist/lib/rag/indexDocuments.js.map +1 -1
- package/dist/locales/index.js +2 -1
- package/dist/locales/index.js.map +1 -1
- package/dist/memory/causal/types.js.map +1 -1
- package/dist/memory/define.types.js +6 -4
- package/dist/memory/define.types.js.map +1 -1
- package/dist/observe.js +22 -115
- package/dist/observe.js.map +1 -1
- package/dist/providers.js +3 -1
- package/dist/providers.js.map +1 -1
- package/dist/status.js +13 -5
- package/dist/status.js.map +1 -1
- package/dist/types/adapters/llm/BrowserOpenAIProvider.d.ts +1 -1
- package/dist/types/adapters/llm/MockProvider.d.ts +2 -1
- package/dist/types/adapters/llm/MockProvider.d.ts.map +1 -1
- package/dist/types/core/agent/buildAgentChart.d.ts.map +1 -1
- package/dist/types/core/agent/buildDynamicAgentChart.d.ts.map +1 -1
- package/dist/types/core/agent/stages/pickEntry.d.ts.map +1 -1
- package/dist/types/core/agent/types.d.ts +8 -4
- package/dist/types/core/agent/types.d.ts.map +1 -1
- package/dist/types/debug/finders.d.ts +13 -0
- package/dist/types/debug/finders.d.ts.map +1 -0
- package/dist/types/debug.d.ts +26 -0
- package/dist/types/debug.d.ts.map +1 -0
- package/dist/types/events.d.ts +19 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/index.d.ts +4 -24
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/context-bisect/index.d.ts +3 -0
- package/dist/types/lib/context-bisect/index.d.ts.map +1 -1
- package/dist/types/lib/context-bisect/localize.d.ts +2 -0
- package/dist/types/lib/context-bisect/localize.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/buildInjectionEngineSubflow.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/entryScorer.d.ts +94 -0
- package/dist/types/lib/injection-engine/entryScorer.d.ts.map +1 -0
- package/dist/types/lib/injection-engine/index.d.ts +2 -1
- package/dist/types/lib/injection-engine/index.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/skillGraph.d.ts +24 -26
- package/dist/types/lib/injection-engine/skillGraph.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/types.d.ts +9 -4
- package/dist/types/lib/injection-engine/types.d.ts.map +1 -1
- package/dist/types/lib/rag/defineRAG.d.ts +3 -3
- package/dist/types/lib/rag/indexDocuments.d.ts +2 -1
- package/dist/types/lib/rag/indexDocuments.d.ts.map +1 -1
- package/dist/types/locales/index.d.ts +9 -0
- package/dist/types/locales/index.d.ts.map +1 -1
- package/dist/types/memory/causal/types.d.ts +13 -9
- package/dist/types/memory/causal/types.d.ts.map +1 -1
- package/dist/types/memory/define.types.d.ts +6 -4
- package/dist/types/memory/define.types.d.ts.map +1 -1
- package/dist/types/observe.d.ts +1 -6
- package/dist/types/observe.d.ts.map +1 -1
- package/dist/types/providers.d.ts +2 -2
- package/dist/types/providers.d.ts.map +1 -1
- package/dist/types/status.d.ts +10 -4
- package/dist/types/status.d.ts.map +1 -1
- package/dist/types/tool-providers/index.d.ts +1 -1
- package/dist/types/tool-providers/index.d.ts.map +1 -1
- package/package.json +261 -57
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* summarize — stage that compresses old loaded entries into a single
|
|
3
|
+
* summary entry, preserving the most-recent N verbatim.
|
|
4
|
+
*
|
|
5
|
+
* Reads from scope: `loaded`
|
|
6
|
+
* Writes to scope: `loaded` (mutated: oldest entries replaced by one
|
|
7
|
+
* synthetic summary entry)
|
|
8
|
+
*
|
|
9
|
+
* Where this fits in the pipeline:
|
|
10
|
+
*
|
|
11
|
+
* loadRecent → summarize → pickByBudget → formatDefault
|
|
12
|
+
*
|
|
13
|
+
* After `summarize` runs, `loaded` is smaller (fewer entries, one of
|
|
14
|
+
* which is a synthetic summary). The picker then selects from this
|
|
15
|
+
* reduced set using the standard budget logic.
|
|
16
|
+
*
|
|
17
|
+
* ## Determinism contract (Anthropic-reviewer ask)
|
|
18
|
+
*
|
|
19
|
+
* For prompt caching to stay stable across runs, the summary content
|
|
20
|
+
* MUST be the same each time for the same input. This requires:
|
|
21
|
+
*
|
|
22
|
+
* 1. Temperature = 0 on the provided LLM.
|
|
23
|
+
* 2. A stable seed if the provider supports it (Anthropic: omit;
|
|
24
|
+
* OpenAI: pass a fixed `seed` in the request).
|
|
25
|
+
* 3. Same system prompt + message set produces same output.
|
|
26
|
+
*
|
|
27
|
+
* The stage CANNOT enforce this — it just calls the caller-supplied
|
|
28
|
+
* `llm` function. Callers are responsible for configuring determinism.
|
|
29
|
+
* Non-deterministic summarizers still work but invalidate prompt caches
|
|
30
|
+
* on every turn (~5× token-cost increase on cache-enabled providers).
|
|
31
|
+
*
|
|
32
|
+
* ## When summarize does NOT fire
|
|
33
|
+
*
|
|
34
|
+
* - `loaded.length < triggerMinEntries` → no-op (not enough history).
|
|
35
|
+
* - `loaded.length <= preserveRecent` → no-op (nothing to summarize; all
|
|
36
|
+
* entries would be preserved verbatim anyway).
|
|
37
|
+
* - LLM call throws → error propagates to the pipeline's executor
|
|
38
|
+
* (fail-loud, per loadRecent / writeMessages convention).
|
|
39
|
+
*
|
|
40
|
+
* ## Config guidance
|
|
41
|
+
*
|
|
42
|
+
* Choose `triggerMinEntries - preserveRecent >= 2`. Below that, a firing
|
|
43
|
+
* summarizer would compress just one entry — wasted LLM call with no
|
|
44
|
+
* real compression. Defaults (trigger 20, preserve 5) summarize 15
|
|
45
|
+
* entries when firing, which is a meaningful compression ratio.
|
|
46
|
+
*
|
|
47
|
+
* ## Summary entry shape
|
|
48
|
+
*
|
|
49
|
+
* The synthetic entry replaces the summarized range. It has:
|
|
50
|
+
* - `id`: `summary-{earliest_turn}-to-{latest_turn}`
|
|
51
|
+
* - `value`: a `{role: 'system', content: summaryText}` message
|
|
52
|
+
* - `source.turn`: the LATEST turn that was summarized (for sorting)
|
|
53
|
+
* - `tier`: 'cold' (marks it as "condensed, may not be recent")
|
|
54
|
+
* - `source.identity`: carried over from the summarized range's first entry
|
|
55
|
+
*/
|
|
56
|
+
import type { TypedScope } from 'footprintjs';
|
|
57
|
+
import type { LLMMessage as Message } from '../../adapters/types.js';
|
|
58
|
+
import type { MemoryState } from './types.js';
|
|
59
|
+
export interface SummarizeConfig {
|
|
60
|
+
/**
|
|
61
|
+
* LLM callback. Receives the chronological messages to summarize;
|
|
62
|
+
* must return the summary text. Caller is responsible for configuring
|
|
63
|
+
* the underlying model (temperature=0, seed, system prompt, etc.) to
|
|
64
|
+
* keep the output deterministic — see "Determinism contract" above.
|
|
65
|
+
*/
|
|
66
|
+
readonly llm: (messages: readonly Message[]) => Promise<string>;
|
|
67
|
+
/**
|
|
68
|
+
* Minimum `loaded.length` before summarization triggers. Below this,
|
|
69
|
+
* no-op — the conversation is short enough to keep verbatim. Default 20.
|
|
70
|
+
*/
|
|
71
|
+
readonly triggerMinEntries?: number;
|
|
72
|
+
/**
|
|
73
|
+
* Number of most-recent entries to preserve verbatim (NOT summarized).
|
|
74
|
+
* The oldest `loaded.length - preserveRecent` entries become a single
|
|
75
|
+
* summary entry. Default 5 — keeps recent turns intact so the agent
|
|
76
|
+
* can reference specific phrasing.
|
|
77
|
+
*/
|
|
78
|
+
readonly preserveRecent?: number;
|
|
79
|
+
/**
|
|
80
|
+
* Optional custom system prompt for the summarizer. Default is a
|
|
81
|
+
* neutral "summarize the following conversation..." instruction.
|
|
82
|
+
* Override for domain-specific summaries (e.g., "preserve all
|
|
83
|
+
* refund-related details").
|
|
84
|
+
*/
|
|
85
|
+
readonly systemPrompt?: string;
|
|
86
|
+
}
|
|
87
|
+
export declare function summarize(config: SummarizeConfig): (scope: TypedScope<MemoryState>) => Promise<void>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tokenize — approximate token counter for budget-aware memory stages.
|
|
3
|
+
*
|
|
4
|
+
* Memory stages need to answer "how many tokens does this content cost?"
|
|
5
|
+
* to decide what fits in a budget. A real tokenizer (tiktoken, Anthropic's
|
|
6
|
+
* tokenizer, etc.) is accurate but:
|
|
7
|
+
*
|
|
8
|
+
* - Adds a dependency (tiktoken is ~2MB, has WASM loading quirks).
|
|
9
|
+
* - Differs per model family (Claude counts differently from GPT).
|
|
10
|
+
* - Pulls frontend bundles from small to huge.
|
|
11
|
+
*
|
|
12
|
+
* Phase 1 uses a deterministic approximation: 1 token ≈ 4 characters of
|
|
13
|
+
* English text. The constant comes from OpenAI's own documentation and
|
|
14
|
+
* is within ~15% for typical chat content. For "how much memory can I
|
|
15
|
+
* inject into an 8K context", 15% is fine.
|
|
16
|
+
*
|
|
17
|
+
* Consumers who need exact counts pass their own `TokenCounter` through
|
|
18
|
+
* the pipeline config. When that lands (Phase 2), this default stays as
|
|
19
|
+
* the dependency-free baseline.
|
|
20
|
+
*/
|
|
21
|
+
import type { LLMMessage as Message } from '../../adapters/types.js';
|
|
22
|
+
/** A function that returns the token count of a string. */
|
|
23
|
+
export type TokenCounter = (text: string) => number;
|
|
24
|
+
/**
|
|
25
|
+
* Default approximation — 1 token per ~4 characters. Low-accuracy,
|
|
26
|
+
* zero-dependency, deterministic (same input → same count). Good enough
|
|
27
|
+
* for budget-based decisions; replace via pipeline config for accuracy.
|
|
28
|
+
*
|
|
29
|
+
* Accuracy notes:
|
|
30
|
+
* - ASCII English: within ~15% of tiktoken.
|
|
31
|
+
* - CJK / emoji / heavy unicode: can undercount by ~2× because
|
|
32
|
+
* `String.length` counts UTF-16 code units, and CJK chars often
|
|
33
|
+
* take multiple tokens each. Use a real tokenizer for these workloads.
|
|
34
|
+
* - Code / JSON: reasonably accurate (punctuation-heavy is ~4 chars/tok).
|
|
35
|
+
*/
|
|
36
|
+
export declare const approximateTokenCounter: TokenCounter;
|
|
37
|
+
/**
|
|
38
|
+
* Count tokens in a single message. Handles string content and the
|
|
39
|
+
* content-block array variant (where each block has its own text field).
|
|
40
|
+
* Non-text blocks (tool calls, images) contribute a small constant to
|
|
41
|
+
* reflect their structural cost.
|
|
42
|
+
*/
|
|
43
|
+
export declare function countMessageTokens(message: Message, counter?: TokenCounter): number;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MemoryState — shared scope for every stage in a memory pipeline.
|
|
3
|
+
*
|
|
4
|
+
* Each stage reads some fields and writes others; the pipeline's narrative
|
|
5
|
+
* shows who wrote what. Fields are added as layers need them — this is the
|
|
6
|
+
* minimal shape for Layer 2 (load + write stages). Layer 3 will add
|
|
7
|
+
* `candidates`, `selected`, `formatted`; Layer 8 will add summarization
|
|
8
|
+
* fields. Every field is optional so pipelines can mix stages freely.
|
|
9
|
+
*
|
|
10
|
+
* Shape design: fields cluster by pipeline direction.
|
|
11
|
+
* - `identity` / `turnNumber` / `contextTokensRemaining` are INPUTS
|
|
12
|
+
* set by the wire layer before the pipeline runs.
|
|
13
|
+
* - `loaded` is the READ-SIDE output.
|
|
14
|
+
* - `newMessages` is the WRITE-SIDE input.
|
|
15
|
+
* - (later layers: `candidates`, `selected`, `formatted`, `saveBatch`)
|
|
16
|
+
*/
|
|
17
|
+
import type { MemoryIdentity } from '../identity/index.js';
|
|
18
|
+
import type { MemoryEntry } from '../entry/index.js';
|
|
19
|
+
import type { LLMMessage as Message } from '../../adapters/types.js';
|
|
20
|
+
export interface MemoryState {
|
|
21
|
+
/**
|
|
22
|
+
* Scoping for every storage call this pipeline makes. Wire layer
|
|
23
|
+
* populates this before the pipeline runs; stages MUST NOT mutate it.
|
|
24
|
+
*/
|
|
25
|
+
readonly identity: MemoryIdentity;
|
|
26
|
+
/**
|
|
27
|
+
* Run-local turn counter — 1 for the first `agent.run`, 2 for the second,
|
|
28
|
+
* and so on within the same conversationId. Written into `MemoryEntry.source`
|
|
29
|
+
* by write-side stages for provenance.
|
|
30
|
+
*/
|
|
31
|
+
readonly turnNumber: number;
|
|
32
|
+
/**
|
|
33
|
+
* Context-window pressure signal (MemGPT-reviewer ask). Populated by the
|
|
34
|
+
* wire layer with `model.contextWindow - tokensUsedSoFar`. Picker stages
|
|
35
|
+
* (Layer 3) use this to decide how much memory to inject.
|
|
36
|
+
*
|
|
37
|
+
* 0 or negative values should be treated by consumers as "no headroom" —
|
|
38
|
+
* stages typically skip or truncate memory injection in that case.
|
|
39
|
+
*/
|
|
40
|
+
readonly contextTokensRemaining: number;
|
|
41
|
+
/**
|
|
42
|
+
* Read-side output: entries loaded from the store this turn. Stages
|
|
43
|
+
* typically APPEND rather than replace so multiple load stages can
|
|
44
|
+
* contribute (e.g. recent-messages + semantic-retrieval + facts).
|
|
45
|
+
*/
|
|
46
|
+
loaded: MemoryEntry<Message>[];
|
|
47
|
+
/**
|
|
48
|
+
* Picker output — the subset of `loaded` that fits the context budget,
|
|
49
|
+
* in chronological order (oldest first). Format stages consume this.
|
|
50
|
+
* Empty array when the picker decided NOT to inject memory (budget
|
|
51
|
+
* below minimum, or no entries loaded).
|
|
52
|
+
*/
|
|
53
|
+
selected: MemoryEntry<Message>[];
|
|
54
|
+
/**
|
|
55
|
+
* Formatter output — the `Message[]` that will be injected into the
|
|
56
|
+
* LLM's prompt this turn. The wire layer merges this into the agent's
|
|
57
|
+
* messages array (typically as `system` messages before the user turn).
|
|
58
|
+
*/
|
|
59
|
+
formatted: Message[];
|
|
60
|
+
/**
|
|
61
|
+
* Write-side input: messages to persist at the end of this turn. The
|
|
62
|
+
* wire layer populates from the agent's final message state;
|
|
63
|
+
* `writeMessages` wraps each as a `MemoryEntry` and calls `store.put`.
|
|
64
|
+
*/
|
|
65
|
+
newMessages: Message[];
|
|
66
|
+
/**
|
|
67
|
+
* Write-side input (CAUSAL pipelines): evidence harvested during the run by
|
|
68
|
+
* `causalEvidenceRecorder` — decisions, tool calls, iterations, duration,
|
|
69
|
+
* token usage. Populated by the wire layer via the mount's `evidenceSource`;
|
|
70
|
+
* undefined for non-causal pipelines (writeSnapshot falls back to zeros).
|
|
71
|
+
*/
|
|
72
|
+
runEvidence?: import('../causal/evidenceRecorder.js').RunEvidence;
|
|
73
|
+
/** Escape hatch for pipeline-specific fields. Typed per-pipeline as needed. */
|
|
74
|
+
[key: string]: unknown;
|
|
75
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* writeMessages — write-side stage that persists new turn messages as
|
|
3
|
+
* `MemoryEntry`s.
|
|
4
|
+
*
|
|
5
|
+
* Reads from scope: `identity`, `turnNumber`, `newMessages`
|
|
6
|
+
* Writes to store: one entry per message, id = `msg-{turnNumber}-{index}`
|
|
7
|
+
*
|
|
8
|
+
* Every written entry carries `source.turn` + `source.identity` so
|
|
9
|
+
* retrieval stages can later show "recalled from turn 5" with correct
|
|
10
|
+
* cross-session provenance. A content-hash signature is also registered
|
|
11
|
+
* via `store.recordSignature` so subsequent `seen()` calls recognize
|
|
12
|
+
* near-duplicate content without loading the full entries.
|
|
13
|
+
*
|
|
14
|
+
* Why a deterministic `id` format?
|
|
15
|
+
* `msg-{turn}-{index}` lets write-then-re-write be idempotent: a stage
|
|
16
|
+
* that re-runs in the same turn (retries, resumable turns) overwrites
|
|
17
|
+
* the same id instead of growing history. For non-turn-scoped writes,
|
|
18
|
+
* pass a custom `idFrom` that produces whatever shape your app needs.
|
|
19
|
+
*
|
|
20
|
+
* PII / redaction:
|
|
21
|
+
* Message content is stored VERBATIM. If your messages contain PII
|
|
22
|
+
* (names, addresses, secrets), redact BEFORE writing — either by
|
|
23
|
+
* mutating `scope.newMessages` upstream or by wrapping the call site
|
|
24
|
+
* with a redaction helper. The storage layer does NOT scrub for you.
|
|
25
|
+
* Pair with footprintjs's `RedactionPolicy` for end-to-end coverage.
|
|
26
|
+
*
|
|
27
|
+
* Extended thinking blocks (Anthropic) / reasoning tokens (OpenAI):
|
|
28
|
+
* Persisting reasoning blocks is expensive — they can be 10-100× the
|
|
29
|
+
* size of the final message. Strip them from `scope.newMessages` before
|
|
30
|
+
* calling this stage UNLESS you plan to recall them (e.g. for debugging
|
|
31
|
+
* replay). A common pattern: write reasoning to `tier: 'cold'` with a
|
|
32
|
+
* short `ttlMs` so they age out quickly.
|
|
33
|
+
*/
|
|
34
|
+
import type { TypedScope } from 'footprintjs';
|
|
35
|
+
import type { MemoryStore } from '../store/index.js';
|
|
36
|
+
import type { LLMMessage as Message } from '../../adapters/types.js';
|
|
37
|
+
import type { MemoryState } from './types.js';
|
|
38
|
+
export interface WriteMessagesConfig {
|
|
39
|
+
/** The store to persist to. */
|
|
40
|
+
readonly store: MemoryStore;
|
|
41
|
+
/**
|
|
42
|
+
* Optional id producer — receives (turn, index, message) and returns
|
|
43
|
+
* the `MemoryEntry.id`. Defaults to `msg-{turn}-{index}` which makes
|
|
44
|
+
* re-runs of the same turn idempotent. Override for app-level ids
|
|
45
|
+
* (e.g. use a message's server-side id).
|
|
46
|
+
*/
|
|
47
|
+
readonly idFrom?: (turn: number, index: number, message: Message) => string;
|
|
48
|
+
/**
|
|
49
|
+
* Optional signature producer for the recognition set. When present,
|
|
50
|
+
* each message produces a signature that is registered via
|
|
51
|
+
* `store.recordSignature`; `seen()` later returns `true` for the same
|
|
52
|
+
* content. Default: skip (many apps don't need recognition).
|
|
53
|
+
*/
|
|
54
|
+
readonly signatureFrom?: (message: Message) => string;
|
|
55
|
+
/**
|
|
56
|
+
* Optional TTL in milliseconds from `Date.now()`. When set, written
|
|
57
|
+
* entries expire this long after they were stored. Useful for
|
|
58
|
+
* compliance retention windows ("delete chat history after 30 days").
|
|
59
|
+
*/
|
|
60
|
+
readonly ttlMs?: number;
|
|
61
|
+
/**
|
|
62
|
+
* Optional tier for the entries. Typical pattern:
|
|
63
|
+
* - `'hot'` for the last few turns
|
|
64
|
+
* - `'warm'` for older turns
|
|
65
|
+
* - `'cold'` for archived
|
|
66
|
+
* Stages in Layer 3+ can filter on tier. Omitting leaves entries
|
|
67
|
+
* untiered (read stages still see them; tier-filtered reads skip them).
|
|
68
|
+
*/
|
|
69
|
+
readonly tier?: 'hot' | 'warm' | 'cold';
|
|
70
|
+
}
|
|
71
|
+
export declare function writeMessages(config: WriteMessagesConfig): (scope: TypedScope<MemoryState>) => Promise<void>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* InMemoryStore — reference `MemoryStore` implementation, zero dependencies.
|
|
3
|
+
*
|
|
4
|
+
* Kept deliberately small — ~200 lines. Its job is to validate the
|
|
5
|
+
* interface contract: every stage and pipeline is tested against this
|
|
6
|
+
* adapter, so any bug in the store shape surfaces here first.
|
|
7
|
+
*
|
|
8
|
+
* Internal structure:
|
|
9
|
+
* namespace (string) → Map<entryId, MemoryEntry>
|
|
10
|
+
* + Set<signature> (for seen)
|
|
11
|
+
* + Map<id, usefulnessSum, usefulnessCount> (for feedback)
|
|
12
|
+
*
|
|
13
|
+
* TTL is enforced lazily on read (cheapest; no background sweeper needed).
|
|
14
|
+
* Pagination cursor is a monotonic integer — entries sorted by updatedAt desc.
|
|
15
|
+
*/
|
|
16
|
+
import type { MemoryIdentity } from '../identity/index.js';
|
|
17
|
+
import type { MemoryEntry } from '../entry/index.js';
|
|
18
|
+
import type { ListOptions, ListResult, MemoryStore, PutIfVersionResult, ScoredEntry, SearchOptions } from './types.js';
|
|
19
|
+
export declare class InMemoryStore implements MemoryStore {
|
|
20
|
+
/**
|
|
21
|
+
* Top-level namespace → slot. Using `Map` rather than a plain object
|
|
22
|
+
* avoids prototype-pollution surface AND preserves insertion order
|
|
23
|
+
* (needed for deterministic list pagination).
|
|
24
|
+
*/
|
|
25
|
+
private readonly namespaces;
|
|
26
|
+
private slot;
|
|
27
|
+
/** True if the entry's TTL has elapsed. Centralized so both `get` and `list` agree. */
|
|
28
|
+
private isExpired;
|
|
29
|
+
get<T = unknown>(identity: MemoryIdentity, id: string): Promise<MemoryEntry<T> | null>;
|
|
30
|
+
put<T = unknown>(identity: MemoryIdentity, entry: MemoryEntry<T>): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Batched write — resolves the slot once and writes each entry into the
|
|
33
|
+
* same Map. Saves N-1 slot lookups vs. calling `put()` in a loop, and
|
|
34
|
+
* gives network-backed adapters a place to pipeline round-trips.
|
|
35
|
+
*/
|
|
36
|
+
putMany<T = unknown>(identity: MemoryIdentity, entries: readonly MemoryEntry<T>[]): Promise<void>;
|
|
37
|
+
putIfVersion<T = unknown>(identity: MemoryIdentity, entry: MemoryEntry<T>, expectedVersion: number): Promise<PutIfVersionResult>;
|
|
38
|
+
list<T = unknown>(identity: MemoryIdentity, options?: ListOptions): Promise<ListResult<T>>;
|
|
39
|
+
delete(identity: MemoryIdentity, id: string): Promise<void>;
|
|
40
|
+
seen(identity: MemoryIdentity, signature: string): Promise<boolean>;
|
|
41
|
+
recordSignature(identity: MemoryIdentity, signature: string): Promise<void>;
|
|
42
|
+
feedback(identity: MemoryIdentity, id: string, usefulness: number): Promise<void>;
|
|
43
|
+
getFeedback(identity: MemoryIdentity, id: string): Promise<{
|
|
44
|
+
average: number;
|
|
45
|
+
count: number;
|
|
46
|
+
} | null>;
|
|
47
|
+
forget(identity: MemoryIdentity): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* O(n) linear scan over identity-scoped entries. Fine for dev / tests
|
|
50
|
+
* — for production, plug in a real vector backend (pgvector, Pinecone,
|
|
51
|
+
* Qdrant) that implements the same interface.
|
|
52
|
+
*
|
|
53
|
+
* Semantics per the `MemoryStore.search?` contract:
|
|
54
|
+
* - Entries without `embedding` are skipped (ignored, not errored).
|
|
55
|
+
* - Entries with `embedding.length` mismatching the query are
|
|
56
|
+
* skipped (cosine would throw — silent-skip avoids poisoning top-k).
|
|
57
|
+
* - TTL-expired entries are omitted.
|
|
58
|
+
* - Optional `tiers` / `minScore` / `embedderId` filters applied.
|
|
59
|
+
* - Returns descending by score; ties broken by id for determinism.
|
|
60
|
+
*/
|
|
61
|
+
search<T = unknown>(identity: MemoryIdentity, query: readonly number[], options?: SearchOptions): Promise<readonly ScoredEntry<T>[]>;
|
|
62
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MemoryStore — the I/O boundary.
|
|
3
|
+
*
|
|
4
|
+
* Every storage backend (InMemory, Redis, DynamoDB, Postgres, Bedrock
|
|
5
|
+
* AgentCore) implements this interface. Stages above the store layer never
|
|
6
|
+
* talk to a concrete backend — they invoke these methods and trust the
|
|
7
|
+
* adapter to handle durability, consistency, encryption, pagination, etc.
|
|
8
|
+
*
|
|
9
|
+
* Design principles:
|
|
10
|
+
*
|
|
11
|
+
* 1. **Identity is always the first argument.** Every call takes
|
|
12
|
+
* `MemoryIdentity` so stores enforce tenant / principal isolation at
|
|
13
|
+
* the boundary. A bug passing the wrong identity surfaces as "no data"
|
|
14
|
+
* rather than a cross-tenant leak.
|
|
15
|
+
*
|
|
16
|
+
* 2. **Methods return Promises uniformly.** Even InMemoryStore's sync ops
|
|
17
|
+
* are wrapped — stages can await every call and adapters are free to
|
|
18
|
+
* swap sync ↔ async without breaking callers.
|
|
19
|
+
*
|
|
20
|
+
* 3. **Writes are optimistic-concurrency-aware.** `putIfVersion` is the
|
|
21
|
+
* default for multi-writer correctness; `put` is convenience for "I
|
|
22
|
+
* know I'm the only writer" callers (single-server, tests).
|
|
23
|
+
*
|
|
24
|
+
* 4. **Reads return cursors, not unbounded arrays.** `list` takes
|
|
25
|
+
* `{ cursor?, limit? }` so large namespaces never OOM. Stages iterate
|
|
26
|
+
* as long as they need.
|
|
27
|
+
*
|
|
28
|
+
* 5. **Recognition is separate from recall.** `seen(signature)` is a
|
|
29
|
+
* boolean check — cheaper than `get` when the caller only needs
|
|
30
|
+
* "have we processed this before?" (cognitive-arch reviewer ask).
|
|
31
|
+
*
|
|
32
|
+
* 6. **Feedback flows back.** `feedback(id, usefulness)` lets retrieval
|
|
33
|
+
* stages signal "this entry was actually used / wasn't used" so
|
|
34
|
+
* adapters can drive their own learning / eviction (RAG-theory ask).
|
|
35
|
+
*/
|
|
36
|
+
import type { MemoryIdentity } from '../identity/index.js';
|
|
37
|
+
import type { MemoryEntry } from '../entry/index.js';
|
|
38
|
+
/** Pagination cursor — opaque string, adapter-specific encoding. */
|
|
39
|
+
export type MemoryCursor = string;
|
|
40
|
+
/** Options for listing entries in a namespace. */
|
|
41
|
+
export interface ListOptions {
|
|
42
|
+
/** Continuation token from a previous `list` call. Omit for the first page. */
|
|
43
|
+
readonly cursor?: MemoryCursor;
|
|
44
|
+
/** Maximum entries to return in this page. Adapters may cap this lower. */
|
|
45
|
+
readonly limit?: number;
|
|
46
|
+
/** Optional filter — only return entries matching these tiers. */
|
|
47
|
+
readonly tiers?: ReadonlyArray<'hot' | 'warm' | 'cold'>;
|
|
48
|
+
}
|
|
49
|
+
/** Result of a paginated `list` call. */
|
|
50
|
+
export interface ListResult<T = unknown> {
|
|
51
|
+
readonly entries: readonly MemoryEntry<T>[];
|
|
52
|
+
/** Present iff more pages exist. Pass back into `list.cursor` to continue. */
|
|
53
|
+
readonly cursor?: MemoryCursor;
|
|
54
|
+
}
|
|
55
|
+
/** Outcome of a `putIfVersion` attempt. */
|
|
56
|
+
export interface PutIfVersionResult {
|
|
57
|
+
/** True iff the write succeeded. */
|
|
58
|
+
readonly applied: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* When `applied === false`, the current version stored — caller can
|
|
61
|
+
* decide whether to retry, merge, or abort. Absent if the entry did
|
|
62
|
+
* not exist at all.
|
|
63
|
+
*/
|
|
64
|
+
readonly currentVersion?: number;
|
|
65
|
+
}
|
|
66
|
+
/** Options for a vector similarity search. */
|
|
67
|
+
export interface SearchOptions {
|
|
68
|
+
/**
|
|
69
|
+
* How many top-scoring entries to return. Default 10. Adapters may
|
|
70
|
+
* cap this lower (Pinecone: 10000, pgvector: user-defined, etc.).
|
|
71
|
+
*/
|
|
72
|
+
readonly k?: number;
|
|
73
|
+
/** Filter results by tier (e.g. `['hot']`) before ranking. */
|
|
74
|
+
readonly tiers?: ReadonlyArray<'hot' | 'warm' | 'cold'>;
|
|
75
|
+
/**
|
|
76
|
+
* Drop entries whose similarity score is below this threshold. Useful
|
|
77
|
+
* when "no match" is a valid outcome (vs. always returning the k
|
|
78
|
+
* nearest no matter how far away). Range [-1, 1] for cosine.
|
|
79
|
+
*/
|
|
80
|
+
readonly minScore?: number;
|
|
81
|
+
/**
|
|
82
|
+
* Embedder id the query was produced with. When present, adapters MAY
|
|
83
|
+
* skip entries whose `embeddingModel` doesn't match — prevents silent
|
|
84
|
+
* cross-model similarity pollution. Absent = trust caller knows what
|
|
85
|
+
* they're doing.
|
|
86
|
+
*/
|
|
87
|
+
readonly embedderId?: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* A `MemoryEntry` annotated with its similarity score. Returned by
|
|
91
|
+
* `store.search()`. Score semantics are adapter-defined but SHOULD
|
|
92
|
+
* use cosine similarity by default ([-1, 1], higher = closer).
|
|
93
|
+
*/
|
|
94
|
+
export interface ScoredEntry<T = unknown> {
|
|
95
|
+
readonly entry: MemoryEntry<T>;
|
|
96
|
+
readonly score: number;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Common surface for all backends. Every method takes `MemoryIdentity`
|
|
100
|
+
* as the scoping argument; stores MUST prefix their internal keys with
|
|
101
|
+
* `identityNamespace(identity)` to prevent cross-tenant access.
|
|
102
|
+
*/
|
|
103
|
+
export interface MemoryStore {
|
|
104
|
+
/**
|
|
105
|
+
* Fetch one entry by id within the given identity's namespace.
|
|
106
|
+
* Returns `null` when the entry doesn't exist OR has expired (TTL).
|
|
107
|
+
* Callers should not distinguish — both mean "no data."
|
|
108
|
+
*
|
|
109
|
+
* Side effect: adapters MAY increment `accessCount` and update
|
|
110
|
+
* `lastAccessedAt` when returning the entry (decay signals).
|
|
111
|
+
*/
|
|
112
|
+
get<T = unknown>(identity: MemoryIdentity, id: string): Promise<MemoryEntry<T> | null>;
|
|
113
|
+
/**
|
|
114
|
+
* Unconditional write — overwrites any existing entry with the same id.
|
|
115
|
+
* Prefer `putIfVersion` in multi-writer scenarios.
|
|
116
|
+
*/
|
|
117
|
+
put<T = unknown>(identity: MemoryIdentity, entry: MemoryEntry<T>): Promise<void>;
|
|
118
|
+
/**
|
|
119
|
+
* Batched unconditional write. Semantically equivalent to N sequential
|
|
120
|
+
* `put()` calls but gives adapters a chance to batch the round-trip.
|
|
121
|
+
*
|
|
122
|
+
* - **InMemoryStore**: no-op optimization — loops internally.
|
|
123
|
+
* - **Redis**: pipelined MSET / MULTI-EXEC.
|
|
124
|
+
* - **DynamoDB**: `BatchWriteItem` (25-entry limit enforced by caller
|
|
125
|
+
* or adapter — adapters MAY chunk).
|
|
126
|
+
* - **Postgres**: multi-row INSERT … ON CONFLICT DO UPDATE.
|
|
127
|
+
*
|
|
128
|
+
* Atomicity is NOT guaranteed across the batch — a partial failure
|
|
129
|
+
* may leave some entries written, some not. Stages that need
|
|
130
|
+
* transactional semantics should use `putIfVersion` per entry with
|
|
131
|
+
* application-level rollback. Most memory flows are append-idempotent
|
|
132
|
+
* (ids are deterministic like `msg-{turn}-{idx}`), so the batch model
|
|
133
|
+
* matches the common case.
|
|
134
|
+
*
|
|
135
|
+
* **Empty batch (`entries.length === 0`): MUST be a no-op.** Callers
|
|
136
|
+
* rely on this to skip a round-trip when there's nothing to persist
|
|
137
|
+
* (e.g., a turn that produced no new messages). Adapters must not
|
|
138
|
+
* reject empty batches — return a resolved Promise immediately.
|
|
139
|
+
*
|
|
140
|
+
* Default implementation for adapters that don't override: sequentially
|
|
141
|
+
* calls `put()` for each entry. Adapters SHOULD override for
|
|
142
|
+
* performance-critical paths.
|
|
143
|
+
*/
|
|
144
|
+
putMany<T = unknown>(identity: MemoryIdentity, entries: readonly MemoryEntry<T>[]): Promise<void>;
|
|
145
|
+
/**
|
|
146
|
+
* Optimistic-concurrency write. Writes only if the stored version equals
|
|
147
|
+
* `expectedVersion`, OR if no entry exists at all AND `expectedVersion`
|
|
148
|
+
* is `0` (first-write sentinel).
|
|
149
|
+
*
|
|
150
|
+
* Returns `{ applied: true }` on success, `{ applied: false, currentVersion }`
|
|
151
|
+
* when the caller's assumed version is stale.
|
|
152
|
+
*/
|
|
153
|
+
putIfVersion<T = unknown>(identity: MemoryIdentity, entry: MemoryEntry<T>, expectedVersion: number): Promise<PutIfVersionResult>;
|
|
154
|
+
/**
|
|
155
|
+
* Page through entries in the identity's namespace. Ordered by adapter's
|
|
156
|
+
* choice (usually most-recently-updated first) — consumers that care
|
|
157
|
+
* about order should filter client-side.
|
|
158
|
+
*/
|
|
159
|
+
list<T = unknown>(identity: MemoryIdentity, options?: ListOptions): Promise<ListResult<T>>;
|
|
160
|
+
/** Remove one entry. No-op if the entry doesn't exist. */
|
|
161
|
+
delete(identity: MemoryIdentity, id: string): Promise<void>;
|
|
162
|
+
/**
|
|
163
|
+
* Cheap "have we processed this signature before?" check. Useful for
|
|
164
|
+
* deduplication, idempotent writes, and cognitive-arch-style recognition
|
|
165
|
+
* vs. recall. Signature is an opaque string the caller controls
|
|
166
|
+
* (content hash, canonicalized fact, etc.).
|
|
167
|
+
*/
|
|
168
|
+
seen(identity: MemoryIdentity, signature: string): Promise<boolean>;
|
|
169
|
+
/**
|
|
170
|
+
* Write-side of the recognition set — adds a signature so subsequent
|
|
171
|
+
* `seen()` calls return `true`. Stages register signatures as entries
|
|
172
|
+
* are written (content hashes, canonicalized facts). Separate from the
|
|
173
|
+
* entry store: a signature outlives the entry that produced it, so
|
|
174
|
+
* dedup survives garbage collection.
|
|
175
|
+
*/
|
|
176
|
+
recordSignature(identity: MemoryIdentity, signature: string): Promise<void>;
|
|
177
|
+
/**
|
|
178
|
+
* Record usefulness feedback for an entry. `usefulness` in `[-1, 1]`:
|
|
179
|
+
* -1 = retrieved but harmful / misleading
|
|
180
|
+
* 0 = retrieved but not used (neutral)
|
|
181
|
+
* 1 = retrieved AND used in the final answer
|
|
182
|
+
*
|
|
183
|
+
* Non-finite values (NaN / ±Infinity) MUST be rejected by adapters —
|
|
184
|
+
* they poison the aggregate. Caller should pass a finite number in
|
|
185
|
+
* `[-1, 1]`; adapters clamp to the valid range for hardening.
|
|
186
|
+
*/
|
|
187
|
+
feedback(identity: MemoryIdentity, id: string, usefulness: number): Promise<void>;
|
|
188
|
+
/**
|
|
189
|
+
* Read-side of feedback — aggregated usefulness for an entry. Returns
|
|
190
|
+
* `null` when no feedback has been recorded (distinct from "neutral
|
|
191
|
+
* average of 0" — callers often want to treat the two differently).
|
|
192
|
+
* Retrieval stages consume this to feedback-weight rankings.
|
|
193
|
+
*/
|
|
194
|
+
getFeedback(identity: MemoryIdentity, id: string): Promise<{
|
|
195
|
+
average: number;
|
|
196
|
+
count: number;
|
|
197
|
+
} | null>;
|
|
198
|
+
/**
|
|
199
|
+
* GDPR — remove ALL entries for the given identity.
|
|
200
|
+
* Must be implementable in one operation per backend (DELETE WHERE prefix).
|
|
201
|
+
*/
|
|
202
|
+
forget(identity: MemoryIdentity): Promise<void>;
|
|
203
|
+
/**
|
|
204
|
+
* Optional — similarity search over entries that carry an
|
|
205
|
+
* `embedding` field. Returns the top-k entries by cosine similarity
|
|
206
|
+
* (descending). Adapters that don't support vector search should
|
|
207
|
+
* OMIT this method; callers feature-detect via `if (store.search)`.
|
|
208
|
+
*
|
|
209
|
+
* Semantics:
|
|
210
|
+
* - Entries with no `embedding` field are ignored (not errored).
|
|
211
|
+
* - Entries with `embedding` of mismatched length are skipped
|
|
212
|
+
* (cosine would throw — silent-skip avoids poisoning the top-k).
|
|
213
|
+
* - TTL-expired entries are omitted (same as `get`/`list`).
|
|
214
|
+
* - Ordering: descending by score. Ties broken by adapter choice.
|
|
215
|
+
*
|
|
216
|
+
* Reference backends:
|
|
217
|
+
* - **InMemoryStore**: O(n) linear scan over identity-scoped entries.
|
|
218
|
+
* Fine for dev / tests. Production needs a real vector DB.
|
|
219
|
+
* - **pgvector**: `ORDER BY embedding <=> query LIMIT k`.
|
|
220
|
+
* - **Pinecone / Qdrant / Weaviate**: native vector query API.
|
|
221
|
+
*/
|
|
222
|
+
search?<T = unknown>(identity: MemoryIdentity, query: readonly number[], options?: SearchOptions): Promise<readonly ScoredEntry<T>[]>;
|
|
223
|
+
}
|