cogmem 3.6.2
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/BENCHMARKS.md +62 -0
- package/CHANGELOG.md +215 -0
- package/CONCURRENT_ACCESS.md +27 -0
- package/CONTRIBUTING.md +32 -0
- package/LICENSE +21 -0
- package/MEMORY_ATLAS.md +101 -0
- package/MEMORY_MODEL.md +179 -0
- package/README.md +751 -0
- package/RECALL_EXPLAINABILITY.md +152 -0
- package/RELEASE_CHECKLIST.md +92 -0
- package/SECURITY.md +21 -0
- package/dist/adapters/MarkdownSourceLoader.d.ts +5 -0
- package/dist/adapters/MarkdownSourceLoader.js +19 -0
- package/dist/adapters/conversation/ConversationMarkdownAdapter.d.ts +9 -0
- package/dist/adapters/conversation/ConversationMarkdownAdapter.js +233 -0
- package/dist/adapters/hermes/HermesStateDbAdapter.d.ts +10 -0
- package/dist/adapters/hermes/HermesStateDbAdapter.js +268 -0
- package/dist/adapters/hermes/HermesWorkspaceProfile.d.ts +15 -0
- package/dist/adapters/hermes/HermesWorkspaceProfile.js +82 -0
- package/dist/adapters/index.d.ts +15 -0
- package/dist/adapters/index.js +12 -0
- package/dist/adapters/openclaw/OpenClawAdapterSupport.d.ts +14 -0
- package/dist/adapters/openclaw/OpenClawAdapterSupport.js +29 -0
- package/dist/adapters/openclaw/OpenClawDailyMemoryAdapter.d.ts +8 -0
- package/dist/adapters/openclaw/OpenClawDailyMemoryAdapter.js +35 -0
- package/dist/adapters/openclaw/OpenClawMemoryIndexAdapter.d.ts +8 -0
- package/dist/adapters/openclaw/OpenClawMemoryIndexAdapter.js +23 -0
- package/dist/adapters/openclaw/OpenClawPersonaAdapter.d.ts +8 -0
- package/dist/adapters/openclaw/OpenClawPersonaAdapter.js +24 -0
- package/dist/adapters/openclaw/OpenClawSessionAdapter.d.ts +8 -0
- package/dist/adapters/openclaw/OpenClawSessionAdapter.js +15 -0
- package/dist/adapters/openclaw/OpenClawUserProfileAdapter.d.ts +8 -0
- package/dist/adapters/openclaw/OpenClawUserProfileAdapter.js +24 -0
- package/dist/adapters/openclaw/OpenClawWorkspaceProfile.d.ts +38 -0
- package/dist/adapters/openclaw/OpenClawWorkspaceProfile.js +199 -0
- package/dist/adapters/soul/SoulMarkdownAdapter.d.ts +14 -0
- package/dist/adapters/soul/SoulMarkdownAdapter.js +255 -0
- package/dist/adapters/types.d.ts +97 -0
- package/dist/adapters/types.js +185 -0
- package/dist/agent/AgentMemoryBackend.d.ts +291 -0
- package/dist/agent/AgentMemoryBackend.js +1272 -0
- package/dist/agent/AgentRecallQueryCompiler.d.ts +20 -0
- package/dist/agent/AgentRecallQueryCompiler.js +289 -0
- package/dist/agent/ContextHygiene.d.ts +9 -0
- package/dist/agent/ContextHygiene.js +20 -0
- package/dist/agent/MemoryUsageReceipt.d.ts +35 -0
- package/dist/agent/MemoryUsageReceipt.js +136 -0
- package/dist/agent/SessionWorkingState.d.ts +20 -0
- package/dist/agent/SessionWorkingState.js +94 -0
- package/dist/agent/index.d.ts +6 -0
- package/dist/agent/index.js +5 -0
- package/dist/algorithm/AlgorithmReviewBackend.d.ts +84 -0
- package/dist/algorithm/AlgorithmReviewBackend.js +261 -0
- package/dist/algorithm/AlgorithmReviewMetrics.d.ts +23 -0
- package/dist/algorithm/AlgorithmReviewMetrics.js +25 -0
- package/dist/algorithm/Phase2ModelAlgorithmReviewBackend.d.ts +38 -0
- package/dist/algorithm/Phase2ModelAlgorithmReviewBackend.js +372 -0
- package/dist/assets/FileAssetIngestionService.d.ts +32 -0
- package/dist/assets/FileAssetIngestionService.js +133 -0
- package/dist/assets/FileAssetStore.d.ts +36 -0
- package/dist/assets/FileAssetStore.js +152 -0
- package/dist/assets/FileBlockStore.d.ts +12 -0
- package/dist/assets/FileBlockStore.js +110 -0
- package/dist/assets/FileChunkStore.d.ts +23 -0
- package/dist/assets/FileChunkStore.js +179 -0
- package/dist/assets/FileChunker.d.ts +10 -0
- package/dist/assets/FileChunker.js +69 -0
- package/dist/assets/FileLoaderRegistry.d.ts +8 -0
- package/dist/assets/FileLoaderRegistry.js +21 -0
- package/dist/assets/FileLoaders.d.ts +37 -0
- package/dist/assets/FileLoaders.js +268 -0
- package/dist/assets/index.d.ts +10 -0
- package/dist/assets/index.js +7 -0
- package/dist/assets/providers/types.d.ts +47 -0
- package/dist/assets/providers/types.js +1 -0
- package/dist/assets/types.d.ts +159 -0
- package/dist/assets/types.js +1 -0
- package/dist/atlas/ActionFrameExtractor.d.ts +15 -0
- package/dist/atlas/ActionFrameExtractor.js +135 -0
- package/dist/atlas/MemoryAtlasIndexer.d.ts +32 -0
- package/dist/atlas/MemoryAtlasIndexer.js +74 -0
- package/dist/atlas/MemoryAtlasQueryCompiler.d.ts +23 -0
- package/dist/atlas/MemoryAtlasQueryCompiler.js +55 -0
- package/dist/atlas/MemoryAtlasService.d.ts +25 -0
- package/dist/atlas/MemoryAtlasService.js +216 -0
- package/dist/atlas/MemoryAtlasTypes.d.ts +107 -0
- package/dist/atlas/MemoryAtlasTypes.js +1 -0
- package/dist/atlas/index.d.ts +6 -0
- package/dist/atlas/index.js +5 -0
- package/dist/backend/SemanticBackend.d.ts +40 -0
- package/dist/backend/SemanticBackend.js +107 -0
- package/dist/batch/IngestionCursorStore.d.ts +52 -0
- package/dist/batch/IngestionCursorStore.js +153 -0
- package/dist/batch/InstalledBatchProcessor.d.ts +88 -0
- package/dist/batch/InstalledBatchProcessor.js +179 -0
- package/dist/batch/SourceOnboarding.d.ts +56 -0
- package/dist/batch/SourceOnboarding.js +366 -0
- package/dist/belief/BeliefGovernanceService.d.ts +59 -0
- package/dist/belief/BeliefGovernanceService.js +183 -0
- package/dist/belief/BeliefStore.d.ts +78 -0
- package/dist/belief/BeliefStore.js +898 -0
- package/dist/benchmark/BenchmarkRegistry.d.ts +16 -0
- package/dist/benchmark/BenchmarkRegistry.js +97 -0
- package/dist/benchmark/BenchmarkReport.d.ts +23 -0
- package/dist/benchmark/BenchmarkReport.js +62 -0
- package/dist/benchmark/BenchmarkRunner.d.ts +27 -0
- package/dist/benchmark/BenchmarkRunner.js +64 -0
- package/dist/benchmark/BrainEval.d.ts +134 -0
- package/dist/benchmark/BrainEval.js +252 -0
- package/dist/benchmark/ExternalBenchmarkRunner.d.ts +8 -0
- package/dist/benchmark/ExternalBenchmarkRunner.js +12 -0
- package/dist/benchmark/LongMemEvalAdapter.d.ts +46 -0
- package/dist/benchmark/LongMemEvalAdapter.js +88 -0
- package/dist/benchmark/LongMemEvalCli.d.ts +6 -0
- package/dist/benchmark/LongMemEvalCli.js +26 -0
- package/dist/bin/CliJson.d.ts +17 -0
- package/dist/bin/CliJson.js +20 -0
- package/dist/bin/brain-eval.d.ts +3 -0
- package/dist/bin/brain-eval.js +46 -0
- package/dist/bin/cogmem.d.ts +3 -0
- package/dist/bin/cogmem.js +95 -0
- package/dist/bin/compact.d.ts +3 -0
- package/dist/bin/compact.js +96 -0
- package/dist/bin/connect.d.ts +3 -0
- package/dist/bin/connect.js +398 -0
- package/dist/bin/doctor.d.ts +3 -0
- package/dist/bin/doctor.js +171 -0
- package/dist/bin/dream.d.ts +3 -0
- package/dist/bin/dream.js +65 -0
- package/dist/bin/episode.d.ts +3 -0
- package/dist/bin/episode.js +268 -0
- package/dist/bin/explain-recall.d.ts +3 -0
- package/dist/bin/explain-recall.js +139 -0
- package/dist/bin/import-hermes.d.ts +3 -0
- package/dist/bin/import-hermes.js +6 -0
- package/dist/bin/import-openclaw.d.ts +3 -0
- package/dist/bin/import-openclaw.js +6 -0
- package/dist/bin/import-support.d.ts +43 -0
- package/dist/bin/import-support.js +528 -0
- package/dist/bin/init.d.ts +30 -0
- package/dist/bin/init.js +761 -0
- package/dist/bin/mcp.d.ts +3 -0
- package/dist/bin/mcp.js +52 -0
- package/dist/bin/memory.d.ts +3 -0
- package/dist/bin/memory.js +803 -0
- package/dist/bin/migrate-vectors.d.ts +3 -0
- package/dist/bin/migrate-vectors.js +74 -0
- package/dist/bin/migrate.d.ts +3 -0
- package/dist/bin/migrate.js +95 -0
- package/dist/bin/normalize-transcript.d.ts +16 -0
- package/dist/bin/normalize-transcript.js +153 -0
- package/dist/bin/openclaw.d.ts +3 -0
- package/dist/bin/openclaw.js +78 -0
- package/dist/bin/prospective.d.ts +3 -0
- package/dist/bin/prospective.js +115 -0
- package/dist/bin/re-embed.d.ts +3 -0
- package/dist/bin/re-embed.js +46 -0
- package/dist/bin/repair.d.ts +3 -0
- package/dist/bin/repair.js +118 -0
- package/dist/bin/snapshot.d.ts +3 -0
- package/dist/bin/snapshot.js +100 -0
- package/dist/bin/strategy.d.ts +3 -0
- package/dist/bin/strategy.js +66 -0
- package/dist/bin/update-release.d.ts +15 -0
- package/dist/bin/update-release.js +62 -0
- package/dist/bin/update.d.ts +3 -0
- package/dist/bin/update.js +215 -0
- package/dist/binding/BindingClassifier.d.ts +19 -0
- package/dist/binding/BindingClassifier.js +270 -0
- package/dist/binding/BindingDecisionEngine.d.ts +11 -0
- package/dist/binding/BindingDecisionEngine.js +13 -0
- package/dist/binding/ClaimKeyGenerator.d.ts +4 -0
- package/dist/binding/ClaimKeyGenerator.js +21 -0
- package/dist/binding/MemoryBindingService.d.ts +28 -0
- package/dist/binding/MemoryBindingService.js +283 -0
- package/dist/binding/MemoryBindingTypes.d.ts +140 -0
- package/dist/binding/MemoryBindingTypes.js +1 -0
- package/dist/binding/TopicPathRegistry.d.ts +5 -0
- package/dist/binding/TopicPathRegistry.js +33 -0
- package/dist/binding/index.d.ts +12 -0
- package/dist/binding/index.js +6 -0
- package/dist/boards/ApprovalBoard.d.ts +14 -0
- package/dist/boards/ApprovalBoard.js +32 -0
- package/dist/boards/Board.d.ts +23 -0
- package/dist/boards/Board.js +1 -0
- package/dist/boards/BoardEventBuffer.d.ts +10 -0
- package/dist/boards/BoardEventBuffer.js +22 -0
- package/dist/boards/BoardEventBus.d.ts +15 -0
- package/dist/boards/BoardEventBus.js +38 -0
- package/dist/boards/BoardEventFilter.d.ts +5 -0
- package/dist/boards/BoardEventFilter.js +1 -0
- package/dist/boards/BoardRegistry.d.ts +11 -0
- package/dist/boards/BoardRegistry.js +15 -0
- package/dist/boards/ContextBoard.d.ts +15 -0
- package/dist/boards/ContextBoard.js +33 -0
- package/dist/boards/MemoryBoard.d.ts +13 -0
- package/dist/boards/MemoryBoard.js +30 -0
- package/dist/boards/ProcessBoard.d.ts +16 -0
- package/dist/boards/ProcessBoard.js +56 -0
- package/dist/boards/ProposalBoard.d.ts +13 -0
- package/dist/boards/ProposalBoard.js +37 -0
- package/dist/boards/ReasoningTraceBoard.d.ts +11 -0
- package/dist/boards/ReasoningTraceBoard.js +34 -0
- package/dist/boards/TaskBoard.d.ts +14 -0
- package/dist/boards/TaskBoard.js +37 -0
- package/dist/boards/index.d.ts +13 -0
- package/dist/boards/index.js +12 -0
- package/dist/config/CogmemConfig.d.ts +43 -0
- package/dist/config/CogmemConfig.js +247 -0
- package/dist/config/VectorDimension.d.ts +13 -0
- package/dist/config/VectorDimension.js +53 -0
- package/dist/context/ContextCortex.d.ts +71 -0
- package/dist/context/ContextCortex.js +156 -0
- package/dist/context/index.d.ts +2 -0
- package/dist/context/index.js +1 -0
- package/dist/core/ImportanceLevels.d.ts +4 -0
- package/dist/core/ImportanceLevels.js +6 -0
- package/dist/core/IntentParser.d.ts +12 -0
- package/dist/core/IntentParser.js +211 -0
- package/dist/core/MemoryGraph.d.ts +100 -0
- package/dist/core/MemoryGraph.js +860 -0
- package/dist/core/Metabolism.d.ts +43 -0
- package/dist/core/Metabolism.js +196 -0
- package/dist/core/Neuron.d.ts +20 -0
- package/dist/core/Neuron.js +51 -0
- package/dist/core/QueryClassifier.d.ts +36 -0
- package/dist/core/QueryClassifier.js +161 -0
- package/dist/core/Reflection.d.ts +42 -0
- package/dist/core/Reflection.js +183 -0
- package/dist/core/ResonanceCore.d.ts +26 -0
- package/dist/core/ResonanceCore.js +115 -0
- package/dist/core/Synapse.d.ts +10 -0
- package/dist/core/Synapse.js +27 -0
- package/dist/core/TwoStagePulseRanker.d.ts +16 -0
- package/dist/core/TwoStagePulseRanker.js +120 -0
- package/dist/dream/DreamScheduler.d.ts +47 -0
- package/dist/dream/DreamScheduler.js +156 -0
- package/dist/dream/index.d.ts +2 -0
- package/dist/dream/index.js +1 -0
- package/dist/embedding/EmbeddingProvider.d.ts +16 -0
- package/dist/embedding/EmbeddingProvider.js +12 -0
- package/dist/embedding/NeuronEmbeddingStore.d.ts +38 -0
- package/dist/embedding/NeuronEmbeddingStore.js +193 -0
- package/dist/embedding/OllamaEmbeddingProvider.d.ts +21 -0
- package/dist/embedding/OllamaEmbeddingProvider.js +65 -0
- package/dist/embedding/QwenAPIEmbeddingProvider.d.ts +26 -0
- package/dist/embedding/QwenAPIEmbeddingProvider.js +53 -0
- package/dist/embedding/ReEmbeddingPipeline.d.ts +30 -0
- package/dist/embedding/ReEmbeddingPipeline.js +119 -0
- package/dist/embedding/ReEmbeddingStatus.d.ts +10 -0
- package/dist/embedding/ReEmbeddingStatus.js +1 -0
- package/dist/embedding/index.d.ts +11 -0
- package/dist/embedding/index.js +5 -0
- package/dist/encryption/AesGcmEncryptionProvider.d.ts +9 -0
- package/dist/encryption/AesGcmEncryptionProvider.js +42 -0
- package/dist/encryption/EncryptionProvider.d.ts +6 -0
- package/dist/encryption/EncryptionProvider.js +3 -0
- package/dist/encryption/index.d.ts +4 -0
- package/dist/encryption/index.js +2 -0
- package/dist/engine/BeliefExtractor.d.ts +48 -0
- package/dist/engine/BeliefExtractor.js +1189 -0
- package/dist/engine/CognitiveGraphCompiler.d.ts +24 -0
- package/dist/engine/CognitiveGraphCompiler.js +243 -0
- package/dist/engine/ConsolidationPipeline.d.ts +66 -0
- package/dist/engine/ConsolidationPipeline.js +376 -0
- package/dist/engine/ConsolidationTrigger.d.ts +18 -0
- package/dist/engine/ConsolidationTrigger.js +41 -0
- package/dist/engine/CrossTopicSynthesizer.d.ts +28 -0
- package/dist/engine/CrossTopicSynthesizer.js +70 -0
- package/dist/engine/CrossTopicTrigger.d.ts +17 -0
- package/dist/engine/CrossTopicTrigger.js +29 -0
- package/dist/engine/DeepWriteConfig.d.ts +14 -0
- package/dist/engine/DeepWriteConfig.js +37 -0
- package/dist/engine/DeepWriteMemoryCompiler.d.ts +43 -0
- package/dist/engine/DeepWriteMemoryCompiler.js +42 -0
- package/dist/engine/DeepWriteMemoryOrchestrator.d.ts +60 -0
- package/dist/engine/DeepWriteMemoryOrchestrator.js +175 -0
- package/dist/engine/DeepWritePromotionPolicy.d.ts +48 -0
- package/dist/engine/DeepWritePromotionPolicy.js +514 -0
- package/dist/engine/DeepWriteRedactor.d.ts +14 -0
- package/dist/engine/DeepWriteRedactor.js +53 -0
- package/dist/engine/DreamCuratorSchedule.d.ts +18 -0
- package/dist/engine/DreamCuratorSchedule.js +95 -0
- package/dist/engine/DreamCuratorWorker.d.ts +67 -0
- package/dist/engine/DreamCuratorWorker.js +908 -0
- package/dist/engine/EntityResolutionEngine.d.ts +45 -0
- package/dist/engine/EntityResolutionEngine.js +105 -0
- package/dist/engine/EpisodicSemanticDistiller.d.ts +25 -0
- package/dist/engine/EpisodicSemanticDistiller.js +68 -0
- package/dist/engine/EvolutionVerifier.d.ts +39 -0
- package/dist/engine/EvolutionVerifier.js +104 -0
- package/dist/engine/FactCompiler.d.ts +41 -0
- package/dist/engine/FactCompiler.js +820 -0
- package/dist/engine/GraphCommunityEngine.d.ts +20 -0
- package/dist/engine/GraphCommunityEngine.js +91 -0
- package/dist/engine/ImportanceSignalDetector.d.ts +11 -0
- package/dist/engine/ImportanceSignalDetector.js +51 -0
- package/dist/engine/IngestionEngine.d.ts +44 -0
- package/dist/engine/IngestionEngine.js +182 -0
- package/dist/engine/InteractionBinder.d.ts +16 -0
- package/dist/engine/InteractionBinder.js +87 -0
- package/dist/engine/LocalSemanticCompiler.d.ts +40 -0
- package/dist/engine/LocalSemanticCompiler.js +111 -0
- package/dist/engine/MemoryConsolidationEngine.d.ts +11 -0
- package/dist/engine/MemoryConsolidationEngine.js +21 -0
- package/dist/engine/MemoryGate.d.ts +10 -0
- package/dist/engine/MemoryGate.js +34 -0
- package/dist/engine/OfflineConsolidationPipeline.d.ts +148 -0
- package/dist/engine/OfflineConsolidationPipeline.js +670 -0
- package/dist/engine/OrphanCleaner.d.ts +15 -0
- package/dist/engine/OrphanCleaner.js +27 -0
- package/dist/engine/PipelineMetrics.d.ts +32 -0
- package/dist/engine/PipelineMetrics.js +126 -0
- package/dist/engine/PrincipleDecayPolicy.d.ts +17 -0
- package/dist/engine/PrincipleDecayPolicy.js +64 -0
- package/dist/engine/TopologyCompiler.d.ts +25 -0
- package/dist/engine/TopologyCompiler.js +276 -0
- package/dist/engine/WorkingMemoryDelta.d.ts +23 -0
- package/dist/engine/WorkingMemoryDelta.js +63 -0
- package/dist/entity/EntityGovernanceService.d.ts +47 -0
- package/dist/entity/EntityGovernanceService.js +215 -0
- package/dist/entity/index.d.ts +3 -0
- package/dist/entity/index.js +1 -0
- package/dist/episode/CogmemBlockStripper.d.ts +11 -0
- package/dist/episode/CogmemBlockStripper.js +58 -0
- package/dist/episode/CorrectionResolver.d.ts +30 -0
- package/dist/episode/CorrectionResolver.js +17 -0
- package/dist/episode/EpisodeAssembler.d.ts +54 -0
- package/dist/episode/EpisodeAssembler.js +203 -0
- package/dist/episode/EpisodeImportIdentity.d.ts +7 -0
- package/dist/episode/EpisodeImportIdentity.js +17 -0
- package/dist/episode/EpisodeSemanticSummarizer.d.ts +4 -0
- package/dist/episode/EpisodeSemanticSummarizer.js +31 -0
- package/dist/episode/EpisodeStore.d.ts +189 -0
- package/dist/episode/EpisodeStore.js +680 -0
- package/dist/episode/EpisodeTypes.d.ts +96 -0
- package/dist/episode/EpisodeTypes.js +1 -0
- package/dist/episode/TurnRelationClassifier.d.ts +40 -0
- package/dist/episode/TurnRelationClassifier.js +205 -0
- package/dist/episode/index.d.ts +9 -0
- package/dist/episode/index.js +8 -0
- package/dist/eval/datasets/contradiction_injection.d.ts +3 -0
- package/dist/eval/datasets/contradiction_injection.js +56 -0
- package/dist/eval/datasets/noisy_tool_output_corpus.d.ts +16 -0
- package/dist/eval/datasets/noisy_tool_output_corpus.js +59 -0
- package/dist/eval/datasets/synthetic_long_conversation.d.ts +40 -0
- package/dist/eval/datasets/synthetic_long_conversation.js +136 -0
- package/dist/eval/runners/EvalRunner.d.ts +12 -0
- package/dist/eval/runners/EvalRunner.js +66 -0
- package/dist/eval/runners/ReportFormatter.d.ts +13 -0
- package/dist/eval/runners/ReportFormatter.js +59 -0
- package/dist/eval/strategy/ContextOutcomeStore.d.ts +12 -0
- package/dist/eval/strategy/ContextOutcomeStore.js +44 -0
- package/dist/eval/strategy/ContextPolicyScorer.d.ts +25 -0
- package/dist/eval/strategy/ContextPolicyScorer.js +58 -0
- package/dist/eval/strategy/MemoryUseJudge.d.ts +49 -0
- package/dist/eval/strategy/MemoryUseJudge.js +75 -0
- package/dist/eval/strategy/StrategyDiversitySelector.d.ts +8 -0
- package/dist/eval/strategy/StrategyDiversitySelector.js +44 -0
- package/dist/eval/strategy/StrategyRolloutEvaluator.d.ts +15 -0
- package/dist/eval/strategy/StrategyRolloutEvaluator.js +30 -0
- package/dist/eval/strategy/index.d.ts +6 -0
- package/dist/eval/strategy/index.js +5 -0
- package/dist/factory.d.ts +726 -0
- package/dist/factory.js +2118 -0
- package/dist/governance/CandidateReviewService.d.ts +33 -0
- package/dist/governance/CandidateReviewService.js +126 -0
- package/dist/governance/ContradictionResolver.d.ts +22 -0
- package/dist/governance/ContradictionResolver.js +54 -0
- package/dist/governance/CredibilityScorer.d.ts +10 -0
- package/dist/governance/CredibilityScorer.js +29 -0
- package/dist/governance/DecayPolicy.d.ts +18 -0
- package/dist/governance/DecayPolicy.js +28 -0
- package/dist/governance/MemoryExplain.d.ts +46 -0
- package/dist/governance/MemoryExplain.js +62 -0
- package/dist/governance/MemoryGovernanceExecutor.d.ts +18 -0
- package/dist/governance/MemoryGovernanceExecutor.js +37 -0
- package/dist/governance/MemoryGovernancePlan.d.ts +36 -0
- package/dist/governance/MemoryGovernancePlan.js +1 -0
- package/dist/governance/MemoryGovernanceValidator.d.ts +13 -0
- package/dist/governance/MemoryGovernanceValidator.js +53 -0
- package/dist/governance/ObservationHygieneRules.d.ts +17 -0
- package/dist/governance/ObservationHygieneRules.js +28 -0
- package/dist/governance/PiiRedactor.d.ts +20 -0
- package/dist/governance/PiiRedactor.js +37 -0
- package/dist/governance/SupersedeChain.d.ts +21 -0
- package/dist/governance/SupersedeChain.js +107 -0
- package/dist/governance/index.d.ts +14 -0
- package/dist/governance/index.js +6 -0
- package/dist/graph/BrainGraphView.d.ts +20 -0
- package/dist/graph/BrainGraphView.js +45 -0
- package/dist/host/openclaw/AutoMemoryPluginInstaller.d.ts +45 -0
- package/dist/host/openclaw/AutoMemoryPluginInstaller.js +1904 -0
- package/dist/internal.d.ts +148 -0
- package/dist/internal.js +144 -0
- package/dist/lexicon/coreMemoryLexicon.d.ts +96 -0
- package/dist/lexicon/coreMemoryLexicon.js +525 -0
- package/dist/lexicon/language-packs/en.d.ts +42 -0
- package/dist/lexicon/language-packs/en.js +41 -0
- package/dist/lexicon/language-packs/zh.d.ts +42 -0
- package/dist/lexicon/language-packs/zh.js +41 -0
- package/dist/lexicon/zh/entities.d.ts +2 -0
- package/dist/lexicon/zh/entities.js +17 -0
- package/dist/lexicon/zh/index.d.ts +5 -0
- package/dist/lexicon/zh/index.js +3 -0
- package/dist/lexicon/zh/stopwords.d.ts +2 -0
- package/dist/lexicon/zh/stopwords.js +22 -0
- package/dist/lexicon/zh/topics.d.ts +6 -0
- package/dist/lexicon/zh/topics.js +52 -0
- package/dist/mcp/CoreMcpTools.d.ts +33 -0
- package/dist/mcp/CoreMcpTools.js +832 -0
- package/dist/mcp/server.d.ts +5 -0
- package/dist/mcp/server.js +29 -0
- package/dist/meta/MetaObservationCollector.d.ts +37 -0
- package/dist/meta/MetaObservationCollector.js +348 -0
- package/dist/meta/PolicyProposalGenerator.d.ts +11 -0
- package/dist/meta/PolicyProposalGenerator.js +159 -0
- package/dist/meta/ProposalApplier.d.ts +18 -0
- package/dist/meta/ProposalApplier.js +91 -0
- package/dist/meta/ProposalConfigOverlay.d.ts +13 -0
- package/dist/meta/ProposalConfigOverlay.js +27 -0
- package/dist/meta/ProposalEvalRunner.d.ts +31 -0
- package/dist/meta/ProposalEvalRunner.js +62 -0
- package/dist/meta/ProposalLedger.d.ts +34 -0
- package/dist/meta/ProposalLedger.js +242 -0
- package/dist/meta/types.d.ts +63 -0
- package/dist/meta/types.js +1 -0
- package/dist/migrations/0001_init.d.ts +4 -0
- package/dist/migrations/0001_init.js +67 -0
- package/dist/migrations/0002_v06_platform.d.ts +10 -0
- package/dist/migrations/0002_v06_platform.js +103 -0
- package/dist/migrations/0003_v07_dialogues.d.ts +9 -0
- package/dist/migrations/0003_v07_dialogues.js +53 -0
- package/dist/migrations/0004_v09_self_improvement.d.ts +9 -0
- package/dist/migrations/0004_v09_self_improvement.js +100 -0
- package/dist/migrations/0005_dialogue_buffer.d.ts +8 -0
- package/dist/migrations/0005_dialogue_buffer.js +44 -0
- package/dist/migrations/0006_deep_write_memory.d.ts +3 -0
- package/dist/migrations/0006_deep_write_memory.js +54 -0
- package/dist/migrations/0007_deep_write_summaries.d.ts +3 -0
- package/dist/migrations/0007_deep_write_summaries.js +24 -0
- package/dist/migrations/0009_memory_importance.d.ts +3 -0
- package/dist/migrations/0009_memory_importance.js +18 -0
- package/dist/migrations/0010_skill_neurons.d.ts +3 -0
- package/dist/migrations/0010_skill_neurons.js +19 -0
- package/dist/migrations/0011_topic_path.d.ts +3 -0
- package/dist/migrations/0011_topic_path.js +19 -0
- package/dist/migrations/0012_governance_security.d.ts +3 -0
- package/dist/migrations/0012_governance_security.js +23 -0
- package/dist/migrations/0015_memory_governance.d.ts +3 -0
- package/dist/migrations/0015_memory_governance.js +74 -0
- package/dist/migrations/0016_entity_governance.d.ts +3 -0
- package/dist/migrations/0016_entity_governance.js +40 -0
- package/dist/migrations/0017_belief_graph.d.ts +3 -0
- package/dist/migrations/0017_belief_graph.js +41 -0
- package/dist/migrations/0018_temporal_memory.d.ts +3 -0
- package/dist/migrations/0018_temporal_memory.js +25 -0
- package/dist/migrations/0019_context_cortex.d.ts +3 -0
- package/dist/migrations/0019_context_cortex.js +19 -0
- package/dist/migrations/0020_prospective_memory.d.ts +3 -0
- package/dist/migrations/0020_prospective_memory.js +42 -0
- package/dist/migrations/0021_strategy_cortex.d.ts +3 -0
- package/dist/migrations/0021_strategy_cortex.js +23 -0
- package/dist/migrations/0022_episode_dream_engine.d.ts +3 -0
- package/dist/migrations/0022_episode_dream_engine.js +74 -0
- package/dist/migrations/0023_episode_dream_hardening.d.ts +3 -0
- package/dist/migrations/0023_episode_dream_hardening.js +65 -0
- package/dist/migrations/0024_episode_ontology_reliability.d.ts +3 -0
- package/dist/migrations/0024_episode_ontology_reliability.js +70 -0
- package/dist/migrations/0025_memory_atlas.d.ts +6 -0
- package/dist/migrations/0025_memory_atlas.js +268 -0
- package/dist/migrations/0026_runtime_governance_atlas_reliability.d.ts +3 -0
- package/dist/migrations/0026_runtime_governance_atlas_reliability.js +72 -0
- package/dist/migrations/0027_openclaw_upgrade_hotfix.d.ts +3 -0
- package/dist/migrations/0027_openclaw_upgrade_hotfix.js +21 -0
- package/dist/migrations/SchemaMigrationRunner.d.ts +21 -0
- package/dist/migrations/SchemaMigrationRunner.js +67 -0
- package/dist/migrations/index.d.ts +36 -0
- package/dist/migrations/index.js +57 -0
- package/dist/models/ModelCapabilityRouter.d.ts +17 -0
- package/dist/models/ModelCapabilityRouter.js +75 -0
- package/dist/models/ModelRegistry.d.ts +15 -0
- package/dist/models/ModelRegistry.js +132 -0
- package/dist/models/ModelRole.d.ts +19 -0
- package/dist/models/ModelRole.js +1 -0
- package/dist/models/UserInsight.d.ts +16 -0
- package/dist/models/UserInsight.js +9 -0
- package/dist/models/UserInsightExtractor.d.ts +19 -0
- package/dist/models/UserInsightExtractor.js +99 -0
- package/dist/models/UserModelManager.d.ts +21 -0
- package/dist/models/UserModelManager.js +41 -0
- package/dist/models/UserModelStore.d.ts +20 -0
- package/dist/models/UserModelStore.js +136 -0
- package/dist/models/WorkingMemoryReporter.d.ts +16 -0
- package/dist/models/WorkingMemoryReporter.js +38 -0
- package/dist/models/adapters/MemoryReviewAdapter.d.ts +12 -0
- package/dist/models/adapters/MemoryReviewAdapter.js +77 -0
- package/dist/models/index.d.ts +8 -0
- package/dist/models/index.js +5 -0
- package/dist/models/providers/AnthropicClient.d.ts +17 -0
- package/dist/models/providers/AnthropicClient.js +40 -0
- package/dist/models/providers/OpenAICompatibleClient.d.ts +24 -0
- package/dist/models/providers/OpenAICompatibleClient.js +76 -0
- package/dist/observability/DecisionExplainer.d.ts +5 -0
- package/dist/observability/DecisionExplainer.js +62 -0
- package/dist/observability/TraceEvent.d.ts +11 -0
- package/dist/observability/TraceEvent.js +1 -0
- package/dist/observability/TraceQuery.d.ts +15 -0
- package/dist/observability/TraceQuery.js +28 -0
- package/dist/observability/TraceStore.d.ts +15 -0
- package/dist/observability/TraceStore.js +110 -0
- package/dist/observability/TraceWriter.d.ts +8 -0
- package/dist/observability/TraceWriter.js +14 -0
- package/dist/ontology/MemoryOntology.d.ts +4 -0
- package/dist/ontology/MemoryOntology.js +7 -0
- package/dist/prospective/ProspectiveMemoryService.d.ts +79 -0
- package/dist/prospective/ProspectiveMemoryService.js +258 -0
- package/dist/prospective/index.d.ts +2 -0
- package/dist/prospective/index.js +1 -0
- package/dist/public.d.ts +160 -0
- package/dist/public.js +115 -0
- package/dist/recall/BrainRecall.d.ts +96 -0
- package/dist/recall/BrainRecall.js +574 -0
- package/dist/recall/HierarchicalRecallRouter.d.ts +24 -0
- package/dist/recall/HierarchicalRecallRouter.js +62 -0
- package/dist/recall/RecallExplanation.d.ts +59 -0
- package/dist/recall/RecallExplanation.js +244 -0
- package/dist/recall/RecallGovernance.d.ts +10 -0
- package/dist/recall/RecallGovernance.js +83 -0
- package/dist/recall/RecallSufficiencyGate.d.ts +40 -0
- package/dist/recall/RecallSufficiencyGate.js +208 -0
- package/dist/recall/SourceContextMetadata.d.ts +49 -0
- package/dist/recall/SourceContextMetadata.js +134 -0
- package/dist/recall/TopicClassifier.d.ts +33 -0
- package/dist/recall/TopicClassifier.js +138 -0
- package/dist/recall/TopicDecayPolicy.d.ts +15 -0
- package/dist/recall/TopicDecayPolicy.js +46 -0
- package/dist/recall/TopicRegistry.d.ts +12 -0
- package/dist/recall/TopicRegistry.js +26 -0
- package/dist/recall/TopicSummaryBoard.d.ts +27 -0
- package/dist/recall/TopicSummaryBoard.js +139 -0
- package/dist/recall/VectorCandidateFilter.d.ts +50 -0
- package/dist/recall/VectorCandidateFilter.js +78 -0
- package/dist/retrieval/ConditionDslEvaluator.d.ts +33 -0
- package/dist/retrieval/ConditionDslEvaluator.js +160 -0
- package/dist/retrieval/EntityActivationIndex.d.ts +14 -0
- package/dist/retrieval/EntityActivationIndex.js +19 -0
- package/dist/retrieval/EvidenceFusionPolicy.d.ts +30 -0
- package/dist/retrieval/EvidenceFusionPolicy.js +112 -0
- package/dist/retrieval/EvidenceFusionRanker.d.ts +13 -0
- package/dist/retrieval/EvidenceFusionRanker.js +17 -0
- package/dist/retrieval/NarrativeRecallAssembler.d.ts +32 -0
- package/dist/retrieval/NarrativeRecallAssembler.js +27 -0
- package/dist/retrieval/NativeQueryParser.d.ts +23 -0
- package/dist/retrieval/NativeQueryParser.js +135 -0
- package/dist/retrieval/PlanDslExecutor.d.ts +67 -0
- package/dist/retrieval/PlanDslExecutor.js +194 -0
- package/dist/retrieval/PolicyRuntimeEvaluator.d.ts +48 -0
- package/dist/retrieval/PolicyRuntimeEvaluator.js +96 -0
- package/dist/retrieval/PolicySideEffectExecutor.d.ts +50 -0
- package/dist/retrieval/PolicySideEffectExecutor.js +202 -0
- package/dist/retrieval/PulseRetrievalEngine.d.ts +37 -0
- package/dist/retrieval/PulseRetrievalEngine.js +51 -0
- package/dist/retrieval/QueryCompiler.d.ts +18 -0
- package/dist/retrieval/QueryCompiler.js +97 -0
- package/dist/retrieval/QueryTimePendingEntityResolver.d.ts +67 -0
- package/dist/retrieval/QueryTimePendingEntityResolver.js +260 -0
- package/dist/retrieval/RetrievalPlanner.d.ts +42 -0
- package/dist/retrieval/RetrievalPlanner.js +209 -0
- package/dist/retrieval/TemporalBranchSearch.d.ts +38 -0
- package/dist/retrieval/TemporalBranchSearch.js +109 -0
- package/dist/retrieval/UniverseNavigator.d.ts +43 -0
- package/dist/retrieval/UniverseNavigator.js +75 -0
- package/dist/retrieval/UniverseTraversalExecutor.d.ts +21 -0
- package/dist/retrieval/UniverseTraversalExecutor.js +77 -0
- package/dist/routing/AnswerEvidenceTrace.d.ts +18 -0
- package/dist/routing/AnswerEvidenceTrace.js +1 -0
- package/dist/routing/BrainToolDispatcher.d.ts +37 -0
- package/dist/routing/BrainToolDispatcher.js +163 -0
- package/dist/routing/ConfidenceGate.d.ts +26 -0
- package/dist/routing/ConfidenceGate.js +40 -0
- package/dist/routing/ConfirmationPhraseMatcher.d.ts +9 -0
- package/dist/routing/ConfirmationPhraseMatcher.js +43 -0
- package/dist/routing/DirectReplyFormatter.d.ts +5 -0
- package/dist/routing/DirectReplyFormatter.js +55 -0
- package/dist/routing/EvidenceBudgetManager.d.ts +30 -0
- package/dist/routing/EvidenceBudgetManager.js +55 -0
- package/dist/routing/ExecutionLoop.d.ts +79 -0
- package/dist/routing/ExecutionLoop.js +234 -0
- package/dist/routing/IntentClassifier.d.ts +15 -0
- package/dist/routing/IntentClassifier.js +97 -0
- package/dist/routing/IntentPatternMatcher.d.ts +12 -0
- package/dist/routing/IntentPatternMatcher.js +206 -0
- package/dist/routing/IterativeLLMClarifier.d.ts +80 -0
- package/dist/routing/IterativeLLMClarifier.js +408 -0
- package/dist/routing/LLMToolSchema.d.ts +60 -0
- package/dist/routing/LLMToolSchema.js +143 -0
- package/dist/routing/MessageRouter.d.ts +20 -0
- package/dist/routing/MessageRouter.js +58 -0
- package/dist/routing/SessionContextSelector.d.ts +12 -0
- package/dist/routing/SessionContextSelector.js +86 -0
- package/dist/routing/SystemIntentClassifier.d.ts +15 -0
- package/dist/routing/SystemIntentClassifier.js +50 -0
- package/dist/routing/TaskPlan.d.ts +31 -0
- package/dist/routing/TaskPlan.js +1 -0
- package/dist/routing/TaskRouter.d.ts +13 -0
- package/dist/routing/TaskRouter.js +111 -0
- package/dist/routing/ToolCallParser.d.ts +16 -0
- package/dist/routing/ToolCallParser.js +123 -0
- package/dist/routing/ToolEvidenceNormalizer.d.ts +13 -0
- package/dist/routing/ToolEvidenceNormalizer.js +96 -0
- package/dist/routing/ToolEvidencePack.d.ts +36 -0
- package/dist/routing/ToolEvidencePack.js +84 -0
- package/dist/routing/ToolResultSanitizer.d.ts +19 -0
- package/dist/routing/ToolResultSanitizer.js +58 -0
- package/dist/routing/ToolUsePolicy.d.ts +78 -0
- package/dist/routing/ToolUsePolicy.js +163 -0
- package/dist/routing/index.d.ts +32 -0
- package/dist/routing/index.js +19 -0
- package/dist/routing/templates/ability_template.d.ts +2 -0
- package/dist/routing/templates/ability_template.js +34 -0
- package/dist/routing/templates/approvals_template.d.ts +2 -0
- package/dist/routing/templates/approvals_template.js +43 -0
- package/dist/routing/templates/context_template.d.ts +2 -0
- package/dist/routing/templates/context_template.js +25 -0
- package/dist/routing/templates/contradictions_template.d.ts +2 -0
- package/dist/routing/templates/contradictions_template.js +36 -0
- package/dist/routing/templates/importance_template.d.ts +2 -0
- package/dist/routing/templates/importance_template.js +23 -0
- package/dist/routing/templates/memory_template.d.ts +2 -0
- package/dist/routing/templates/memory_template.js +37 -0
- package/dist/routing/templates/self_manifest_template.d.ts +5 -0
- package/dist/routing/templates/self_manifest_template.js +64 -0
- package/dist/routing/templates/tasks_template.d.ts +2 -0
- package/dist/routing/templates/tasks_template.js +41 -0
- package/dist/routing/templates/trace_template.d.ts +2 -0
- package/dist/routing/templates/trace_template.js +37 -0
- package/dist/routing/tools/EntityExpandTool.d.ts +25 -0
- package/dist/routing/tools/EntityExpandTool.js +59 -0
- package/dist/routing/tools/NeuronContextTool.d.ts +32 -0
- package/dist/routing/tools/NeuronContextTool.js +66 -0
- package/dist/routing/tools/SecondaryRecallTool.d.ts +27 -0
- package/dist/routing/tools/SecondaryRecallTool.js +30 -0
- package/dist/routing/tools/SkillDiscoveryTool.d.ts +13 -0
- package/dist/routing/tools/SkillDiscoveryTool.js +11 -0
- package/dist/snapshot/SnapshotExporter.d.ts +13 -0
- package/dist/snapshot/SnapshotExporter.js +70 -0
- package/dist/snapshot/SnapshotHeader.d.ts +15 -0
- package/dist/snapshot/SnapshotHeader.js +1 -0
- package/dist/snapshot/SnapshotImporter.d.ts +20 -0
- package/dist/snapshot/SnapshotImporter.js +40 -0
- package/dist/snapshot/errors.d.ts +18 -0
- package/dist/snapshot/errors.js +34 -0
- package/dist/snapshot/index.d.ts +5 -0
- package/dist/snapshot/index.js +3 -0
- package/dist/storage/StorageCompactor.d.ts +30 -0
- package/dist/storage/StorageCompactor.js +95 -0
- package/dist/store/ActivationStore.d.ts +45 -0
- package/dist/store/ActivationStore.js +135 -0
- package/dist/store/BackgroundJobStore.d.ts +49 -0
- package/dist/store/BackgroundJobStore.js +156 -0
- package/dist/store/CandidateReviewStore.d.ts +33 -0
- package/dist/store/CandidateReviewStore.js +67 -0
- package/dist/store/CognitiveGraphStore.d.ts +42 -0
- package/dist/store/CognitiveGraphStore.js +193 -0
- package/dist/store/CompilerConfidenceStore.d.ts +20 -0
- package/dist/store/CompilerConfidenceStore.js +76 -0
- package/dist/store/DeepWriteCandidateStore.d.ts +94 -0
- package/dist/store/DeepWriteCandidateStore.js +290 -0
- package/dist/store/DeterministicEmbedder.d.ts +10 -0
- package/dist/store/DeterministicEmbedder.js +24 -0
- package/dist/store/DreamLedgerStore.d.ts +22 -0
- package/dist/store/DreamLedgerStore.js +84 -0
- package/dist/store/Embedder.d.ts +14 -0
- package/dist/store/Embedder.js +52 -0
- package/dist/store/EmbedderFactory.d.ts +12 -0
- package/dist/store/EmbedderFactory.js +51 -0
- package/dist/store/EntityStore.d.ts +195 -0
- package/dist/store/EntityStore.js +941 -0
- package/dist/store/EventStore.d.ts +118 -0
- package/dist/store/EventStore.js +699 -0
- package/dist/store/FactStore.d.ts +76 -0
- package/dist/store/FactStore.js +356 -0
- package/dist/store/HnswlibVectorStore.d.ts +2 -0
- package/dist/store/HnswlibVectorStore.js +1 -0
- package/dist/store/IVectorStore.d.ts +32 -0
- package/dist/store/IVectorStore.js +1 -0
- package/dist/store/InteractionUnitStore.d.ts +52 -0
- package/dist/store/InteractionUnitStore.js +167 -0
- package/dist/store/MemoryAtlasStore.d.ts +60 -0
- package/dist/store/MemoryAtlasStore.js +500 -0
- package/dist/store/MemoryBindingStore.d.ts +77 -0
- package/dist/store/MemoryBindingStore.js +608 -0
- package/dist/store/MemoryGovernanceStore.d.ts +23 -0
- package/dist/store/MemoryGovernanceStore.js +103 -0
- package/dist/store/MemoryInspectionStore.d.ts +61 -0
- package/dist/store/MemoryInspectionStore.js +215 -0
- package/dist/store/PlanRuntimeStore.d.ts +83 -0
- package/dist/store/PlanRuntimeStore.js +257 -0
- package/dist/store/PolicyExecutionProjector.d.ts +17 -0
- package/dist/store/PolicyExecutionProjector.js +115 -0
- package/dist/store/PolicyExecutionStore.d.ts +62 -0
- package/dist/store/PolicyExecutionStore.js +290 -0
- package/dist/store/PolicyProjectionStore.d.ts +18 -0
- package/dist/store/PolicyProjectionStore.js +61 -0
- package/dist/store/ProjectionObservabilityStore.d.ts +38 -0
- package/dist/store/ProjectionObservabilityStore.js +310 -0
- package/dist/store/ReasoningChainStore.d.ts +13 -0
- package/dist/store/ReasoningChainStore.js +74 -0
- package/dist/store/RuntimeProjectionStore.d.ts +18 -0
- package/dist/store/RuntimeProjectionStore.js +61 -0
- package/dist/store/RuntimeProjector.d.ts +17 -0
- package/dist/store/RuntimeProjector.js +119 -0
- package/dist/store/SqliteVecStore.d.ts +25 -0
- package/dist/store/SqliteVecStore.js +126 -0
- package/dist/store/SummaryStore.d.ts +56 -0
- package/dist/store/SummaryStore.js +225 -0
- package/dist/store/TemporalAdjacencyStore.d.ts +49 -0
- package/dist/store/TemporalAdjacencyStore.js +300 -0
- package/dist/store/TopologyStore.d.ts +89 -0
- package/dist/store/TopologyStore.js +657 -0
- package/dist/store/VectorProjector.d.ts +22 -0
- package/dist/store/VectorProjector.js +125 -0
- package/dist/store/VectorStore.d.ts +35 -0
- package/dist/store/VectorStore.js +201 -0
- package/dist/strategy/StrategyCapsule.d.ts +44 -0
- package/dist/strategy/StrategyCapsule.js +1 -0
- package/dist/strategy/StrategyConditionedCandidateBuilder.d.ts +9 -0
- package/dist/strategy/StrategyConditionedCandidateBuilder.js +11 -0
- package/dist/strategy/StrategyContextFormatter.d.ts +3 -0
- package/dist/strategy/StrategyContextFormatter.js +25 -0
- package/dist/strategy/StrategyCortex.d.ts +28 -0
- package/dist/strategy/StrategyCortex.js +78 -0
- package/dist/strategy/StrategyTemplateRegistry.d.ts +9 -0
- package/dist/strategy/StrategyTemplateRegistry.js +78 -0
- package/dist/strategy/index.d.ts +6 -0
- package/dist/strategy/index.js +5 -0
- package/dist/temporal/TemporalMemoryService.d.ts +62 -0
- package/dist/temporal/TemporalMemoryService.js +128 -0
- package/dist/temporal/index.d.ts +2 -0
- package/dist/temporal/index.js +1 -0
- package/dist/topic/TopicAliasRegistry.d.ts +21 -0
- package/dist/topic/TopicAliasRegistry.js +67 -0
- package/dist/topic/TopicGovernance.d.ts +21 -0
- package/dist/topic/TopicGovernance.js +173 -0
- package/dist/topic/TopicPathRegistry.d.ts +36 -0
- package/dist/topic/TopicPathRegistry.js +105 -0
- package/dist/topic/TopicRelationGraph.d.ts +23 -0
- package/dist/topic/TopicRelationGraph.js +55 -0
- package/dist/topic/TopicTypes.d.ts +73 -0
- package/dist/topic/TopicTypes.js +1 -0
- package/dist/topic/index.d.ts +6 -0
- package/dist/topic/index.js +5 -0
- package/dist/types/AsyncEnrichment.d.ts +62 -0
- package/dist/types/AsyncEnrichment.js +7 -0
- package/dist/types/BrainRecallResult.d.ts +66 -0
- package/dist/types/BrainRecallResult.js +1 -0
- package/dist/types/ExtensionPoints.d.ts +116 -0
- package/dist/types/ExtensionPoints.js +1 -0
- package/dist/types/Migration.d.ts +22 -0
- package/dist/types/Migration.js +1 -0
- package/dist/types/QueryTimePendingEntityResolution.d.ts +11 -0
- package/dist/types/QueryTimePendingEntityResolution.js +23 -0
- package/dist/types/index.d.ts +855 -0
- package/dist/types/index.js +24 -0
- package/dist/types/query-ir.d.ts +71 -0
- package/dist/types/query-ir.js +4 -0
- package/dist/types/reasoning.d.ts +16 -0
- package/dist/types/reasoning.js +4 -0
- package/dist/utils/AAAKGenerator.d.ts +57 -0
- package/dist/utils/AAAKGenerator.js +212 -0
- package/dist/utils/Config.d.ts +78 -0
- package/dist/utils/Config.js +91 -0
- package/dist/utils/ConversationMarkdownNormalization.d.ts +88 -0
- package/dist/utils/ConversationMarkdownNormalization.js +567 -0
- package/dist/utils/Logger.d.ts +22 -0
- package/dist/utils/Logger.js +77 -0
- package/dist/utils/hash.d.ts +33 -0
- package/dist/utils/hash.js +53 -0
- package/dist/utils/text.d.ts +2 -0
- package/dist/utils/text.js +19 -0
- package/dist/utils/vector.d.ts +26 -0
- package/dist/utils/vector.js +38 -0
- package/examples/hermes-backend/AGENTS.md +218 -0
- package/examples/hermes-backend/README.md +153 -0
- package/examples/hermes-backend/SKILL.md +365 -0
- package/examples/hermes-backend/references/operations.md +202 -0
- package/examples/openclaw-backend/AGENTS.md +195 -0
- package/examples/openclaw-backend/README.md +228 -0
- package/examples/openclaw-backend/SKILL.md +464 -0
- package/examples/openclaw-backend/references/operations.md +269 -0
- package/install.sh +84 -0
- package/package.json +90 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export class MessageRouter {
|
|
2
|
+
classifier;
|
|
3
|
+
managers;
|
|
4
|
+
formatter;
|
|
5
|
+
constructor(classifier, managers, formatter) {
|
|
6
|
+
this.classifier = classifier;
|
|
7
|
+
this.managers = managers;
|
|
8
|
+
this.formatter = formatter;
|
|
9
|
+
}
|
|
10
|
+
async route(message) {
|
|
11
|
+
const startedAt = Date.now();
|
|
12
|
+
const classification = this.classifier.classify(message);
|
|
13
|
+
if (classification.intent === 'reasoning_required') {
|
|
14
|
+
return {
|
|
15
|
+
path: 'slow',
|
|
16
|
+
intent: 'reasoning_required',
|
|
17
|
+
reply: '',
|
|
18
|
+
latencyMs: Date.now() - startedAt
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const data = await this.managers.dispatch(classification.intent, this.buildParams(classification.intent, message, classification.matchedPattern));
|
|
22
|
+
return {
|
|
23
|
+
path: 'fast',
|
|
24
|
+
intent: classification.intent,
|
|
25
|
+
reply: data === null ? '(该功能暂不可用)' : this.formatter.format(classification.intent, data),
|
|
26
|
+
latencyMs: Date.now() - startedAt
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
buildParams(intent, message, matchedPattern) {
|
|
30
|
+
switch (intent) {
|
|
31
|
+
case 'system_query.memory_search':
|
|
32
|
+
return { q: message.trim() };
|
|
33
|
+
case 'system_query.memory_recent':
|
|
34
|
+
return { limit: 10 };
|
|
35
|
+
case 'system_query.trace':
|
|
36
|
+
return { limit: 5 };
|
|
37
|
+
case 'system_command.approve':
|
|
38
|
+
case 'system_command.reject':
|
|
39
|
+
case 'system_command.cancel_task': {
|
|
40
|
+
const extractedId = this.extractIdentifier(message, matchedPattern);
|
|
41
|
+
return extractedId ? { id: extractedId } : undefined;
|
|
42
|
+
}
|
|
43
|
+
default:
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
extractIdentifier(message, matchedPattern) {
|
|
48
|
+
const confirmationMatch = matchedPattern?.match(/^confirmation:(?:approve|reject):(.+)$/);
|
|
49
|
+
if (confirmationMatch?.[1]) {
|
|
50
|
+
return confirmationMatch[1];
|
|
51
|
+
}
|
|
52
|
+
const idMatch = message.match(/\b([A-Za-z0-9][A-Za-z0-9_-]{2,})\b/g);
|
|
53
|
+
if (!idMatch || idMatch.length === 0) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
return idMatch[idMatch.length - 1];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ChatSessionLike } from '../types/ExtensionPoints.js';
|
|
2
|
+
export interface SessionContextSelectionInput {
|
|
3
|
+
session?: ChatSessionLike;
|
|
4
|
+
query: string;
|
|
5
|
+
projectId?: string;
|
|
6
|
+
maxChars?: number;
|
|
7
|
+
}
|
|
8
|
+
type SessionTurn = ReturnType<ChatSessionLike['getRecentTurns']>[number];
|
|
9
|
+
export declare function selectCueDrivenSessionTurns(input: SessionContextSelectionInput): SessionTurn[];
|
|
10
|
+
export declare function buildCueDrivenSessionContext(input: SessionContextSelectionInput): string;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=SessionContextSelector.d.ts.map
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
const DEFAULT_MAX_CHARS = 4000;
|
|
2
|
+
export function selectCueDrivenSessionTurns(input) {
|
|
3
|
+
const session = input.session;
|
|
4
|
+
if (!session)
|
|
5
|
+
return [];
|
|
6
|
+
const maxChars = Math.max(1, input.maxChars ?? DEFAULT_MAX_CHARS);
|
|
7
|
+
const hostSelectedTurns = session.getRelevantTurns?.({
|
|
8
|
+
query: input.query,
|
|
9
|
+
projectId: input.projectId,
|
|
10
|
+
maxChars,
|
|
11
|
+
});
|
|
12
|
+
const rawTurns = hostSelectedTurns ?? session.getRecentTurns();
|
|
13
|
+
const scored = rawTurns
|
|
14
|
+
.map((turn, index) => ({
|
|
15
|
+
turn,
|
|
16
|
+
index,
|
|
17
|
+
score: turnRelevanceScore(input.query, turn.content),
|
|
18
|
+
}))
|
|
19
|
+
.filter((item) => item.turn.content.trim().length > 0);
|
|
20
|
+
const candidates = hostSelectedTurns
|
|
21
|
+
? [...scored].sort((a, b) => b.score - a.score || b.turn.timestamp - a.turn.timestamp || b.index - a.index)
|
|
22
|
+
: scored
|
|
23
|
+
.filter((item) => item.score > 0)
|
|
24
|
+
.sort((a, b) => b.score - a.score || b.turn.timestamp - a.turn.timestamp || b.index - a.index);
|
|
25
|
+
const fallback = [...scored].sort((a, b) => b.turn.timestamp - a.turn.timestamp || b.index - a.index);
|
|
26
|
+
const selectedFrom = candidates.length > 0 ? candidates : fallback;
|
|
27
|
+
const selected = [];
|
|
28
|
+
let usedChars = 0;
|
|
29
|
+
for (const item of selectedFrom) {
|
|
30
|
+
const cost = formatSessionTurn(item.turn).length + 1;
|
|
31
|
+
if (selected.length > 0 && usedChars + cost > maxChars)
|
|
32
|
+
continue;
|
|
33
|
+
selected.push(item);
|
|
34
|
+
usedChars += cost;
|
|
35
|
+
if (usedChars >= maxChars)
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
return selected
|
|
39
|
+
.sort((a, b) => a.turn.timestamp - b.turn.timestamp || a.index - b.index)
|
|
40
|
+
.map((item) => item.turn);
|
|
41
|
+
}
|
|
42
|
+
export function buildCueDrivenSessionContext(input) {
|
|
43
|
+
return selectCueDrivenSessionTurns(input)
|
|
44
|
+
.map(formatSessionTurn)
|
|
45
|
+
.join('\n');
|
|
46
|
+
}
|
|
47
|
+
function formatSessionTurn(turn) {
|
|
48
|
+
const role = turn.role === 'user' ? 'User' : 'Agent';
|
|
49
|
+
return `${role}: ${turn.content.trim()}`;
|
|
50
|
+
}
|
|
51
|
+
function turnRelevanceScore(query, content) {
|
|
52
|
+
const queryTokens = tokenize(query);
|
|
53
|
+
if (queryTokens.length === 0)
|
|
54
|
+
return 0;
|
|
55
|
+
const normalizedContent = content.toLowerCase();
|
|
56
|
+
const lexicalHits = queryTokens.filter((token) => normalizedContent.includes(token)).length;
|
|
57
|
+
return lexicalHits / queryTokens.length + trigramJaccard(query, content);
|
|
58
|
+
}
|
|
59
|
+
function tokenize(text) {
|
|
60
|
+
return Array.from(new Set(text
|
|
61
|
+
.toLowerCase()
|
|
62
|
+
.replace(/[^\p{L}\p{N}_\-\u4e00-\u9fa5\s]/gu, ' ')
|
|
63
|
+
.split(/\s+/)
|
|
64
|
+
.map((token) => token.trim())
|
|
65
|
+
.filter((token) => token.length >= 2)));
|
|
66
|
+
}
|
|
67
|
+
function trigrams(text) {
|
|
68
|
+
const normalized = text.toLowerCase().replace(/\s+/g, ' ').trim();
|
|
69
|
+
if (normalized.length < 3)
|
|
70
|
+
return new Set(normalized ? [normalized] : []);
|
|
71
|
+
const grams = new Set();
|
|
72
|
+
for (let i = 0; i <= normalized.length - 3; i++)
|
|
73
|
+
grams.add(normalized.slice(i, i + 3));
|
|
74
|
+
return grams;
|
|
75
|
+
}
|
|
76
|
+
function trigramJaccard(a, b) {
|
|
77
|
+
const left = trigrams(a);
|
|
78
|
+
const right = trigrams(b);
|
|
79
|
+
if (left.size === 0 && right.size === 0)
|
|
80
|
+
return 1;
|
|
81
|
+
let intersection = 0;
|
|
82
|
+
for (const item of left)
|
|
83
|
+
if (right.has(item))
|
|
84
|
+
intersection += 1;
|
|
85
|
+
return intersection / (left.size + right.size - intersection);
|
|
86
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ConfirmationPhraseMatcher } from './ConfirmationPhraseMatcher.js';
|
|
2
|
+
import { IntentPatternMatcher } from './IntentPatternMatcher.js';
|
|
3
|
+
export type SystemIntent = 'system_query.tasks' | 'system_query.approvals' | 'system_query.contradictions' | 'system_query.capabilities' | 'system_query.environment' | 'system_query.self_manifest' | 'system_query.models' | 'system_query.file_assets' | 'system_query.memory_recent' | 'system_query.memory_search' | 'system_query.important_memories' | 'system_query.context' | 'system_query.trace' | 'system_command.approve' | 'system_command.reject' | 'system_command.resume' | 'system_command.cancel_task' | 'system_command.mark_important' | 'system_command.mark_permanent' | 'system_command.unmark_important' | 'system_confirmation.yes_no' | 'reasoning_required';
|
|
4
|
+
export interface IntentClassificationResult {
|
|
5
|
+
intent: SystemIntent;
|
|
6
|
+
confidence: number;
|
|
7
|
+
matchedPattern?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class SystemIntentClassifier {
|
|
10
|
+
private readonly patternMatcher;
|
|
11
|
+
private readonly confirmationPhraseMatcher;
|
|
12
|
+
constructor(patternMatcher?: IntentPatternMatcher, confirmationPhraseMatcher?: ConfirmationPhraseMatcher);
|
|
13
|
+
classify(message: string): IntentClassificationResult;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=SystemIntentClassifier.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ConfirmationPhraseMatcher } from './ConfirmationPhraseMatcher.js';
|
|
2
|
+
import { IntentPatternMatcher } from './IntentPatternMatcher.js';
|
|
3
|
+
export class SystemIntentClassifier {
|
|
4
|
+
patternMatcher;
|
|
5
|
+
confirmationPhraseMatcher;
|
|
6
|
+
constructor(patternMatcher = new IntentPatternMatcher(), confirmationPhraseMatcher = new ConfirmationPhraseMatcher()) {
|
|
7
|
+
this.patternMatcher = patternMatcher;
|
|
8
|
+
this.confirmationPhraseMatcher = confirmationPhraseMatcher;
|
|
9
|
+
}
|
|
10
|
+
classify(message) {
|
|
11
|
+
const normalizedMessage = message.trim();
|
|
12
|
+
if (!normalizedMessage) {
|
|
13
|
+
return { intent: 'reasoning_required', confidence: 1.0 };
|
|
14
|
+
}
|
|
15
|
+
const match = this.patternMatcher.match(normalizedMessage);
|
|
16
|
+
if (match) {
|
|
17
|
+
const confirmation = this.confirmationPhraseMatcher.matchConfirmation(normalizedMessage);
|
|
18
|
+
if (confirmation && (match.intent === 'system_command.approve' || match.intent === 'system_command.reject')) {
|
|
19
|
+
return {
|
|
20
|
+
intent: match.intent,
|
|
21
|
+
confidence: 1.0,
|
|
22
|
+
matchedPattern: confirmation.subject
|
|
23
|
+
? `confirmation:${confirmation.action}:${confirmation.subject}`
|
|
24
|
+
: `confirmation:${confirmation.action}`
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
intent: match.intent,
|
|
29
|
+
confidence: 1.0,
|
|
30
|
+
matchedPattern: match.pattern.source
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const confirmation = this.confirmationPhraseMatcher.matchConfirmation(normalizedMessage);
|
|
34
|
+
if (confirmation?.action === 'approve') {
|
|
35
|
+
return {
|
|
36
|
+
intent: 'system_command.approve',
|
|
37
|
+
confidence: 1.0,
|
|
38
|
+
matchedPattern: confirmation.subject ? `confirmation:approve:${confirmation.subject}` : 'confirmation:approve'
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if (confirmation?.action === 'reject') {
|
|
42
|
+
return {
|
|
43
|
+
intent: 'system_command.reject',
|
|
44
|
+
confidence: 1.0,
|
|
45
|
+
matchedPattern: confirmation.subject ? `confirmation:reject:${confirmation.subject}` : 'confirmation:reject'
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return { intent: 'reasoning_required', confidence: 1.0 };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type IntentType = 'factual_recall' | 'temporal_recall' | 'entity_lookup' | 'cross_domain' | 'correction_check' | 'open_ended';
|
|
2
|
+
export type TaskStepType = 'memory_recall' | 'fact_check' | 'graph_traverse' | 'confidence_check' | 'perception_call' | 'llm_clarify' | 'answer_assemble';
|
|
3
|
+
export interface TaskStep {
|
|
4
|
+
id: string;
|
|
5
|
+
type: TaskStepType;
|
|
6
|
+
label: string;
|
|
7
|
+
inputs: {
|
|
8
|
+
query?: string;
|
|
9
|
+
entityHint?: string;
|
|
10
|
+
projectId?: string;
|
|
11
|
+
subjectHint?: string;
|
|
12
|
+
predicateHint?: string;
|
|
13
|
+
capabilityId?: string;
|
|
14
|
+
capabilityInput?: Record<string, unknown>;
|
|
15
|
+
};
|
|
16
|
+
triggerCondition?: {
|
|
17
|
+
dependsOnStepId: string;
|
|
18
|
+
metric: 'confidence_score';
|
|
19
|
+
operator: 'lt';
|
|
20
|
+
threshold: number;
|
|
21
|
+
};
|
|
22
|
+
mayCallLLM: boolean;
|
|
23
|
+
}
|
|
24
|
+
export interface TaskPlan {
|
|
25
|
+
planId: string;
|
|
26
|
+
intentType: IntentType;
|
|
27
|
+
query: string;
|
|
28
|
+
steps: TaskStep[];
|
|
29
|
+
estimatedLLMCalls: number;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=TaskPlan.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IntentClassifier } from './IntentClassifier.js';
|
|
2
|
+
import type { TaskPlan } from './TaskPlan.js';
|
|
3
|
+
export declare class TaskRouter {
|
|
4
|
+
private classifier;
|
|
5
|
+
constructor(classifier?: IntentClassifier);
|
|
6
|
+
plan(query: string, options?: {
|
|
7
|
+
projectId?: string;
|
|
8
|
+
confidenceThreshold?: number;
|
|
9
|
+
}): TaskPlan;
|
|
10
|
+
private createStep;
|
|
11
|
+
private createClarifyStep;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=TaskRouter.d.ts.map
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { randomUUID } from 'crypto';
|
|
2
|
+
import { IntentClassifier } from './IntentClassifier.js';
|
|
3
|
+
export class TaskRouter {
|
|
4
|
+
classifier;
|
|
5
|
+
constructor(classifier = new IntentClassifier()) {
|
|
6
|
+
this.classifier = classifier;
|
|
7
|
+
}
|
|
8
|
+
plan(query, options = {}) {
|
|
9
|
+
const classification = this.classifier.classify(query, { projectId: options.projectId });
|
|
10
|
+
const threshold = options.confidenceThreshold ?? 0.6;
|
|
11
|
+
const steps = [];
|
|
12
|
+
steps.push(this.createStep('step_1', 'memory_recall', 'Recall memory evidence for the query', {
|
|
13
|
+
query,
|
|
14
|
+
entityHint: classification.entityHint,
|
|
15
|
+
projectId: options.projectId
|
|
16
|
+
}), this.createStep('step_2', 'confidence_check', 'Evaluate confidence of the recall evidence', {
|
|
17
|
+
query,
|
|
18
|
+
entityHint: classification.entityHint,
|
|
19
|
+
projectId: options.projectId
|
|
20
|
+
}));
|
|
21
|
+
switch (classification.intentType) {
|
|
22
|
+
case 'factual_recall':
|
|
23
|
+
case 'entity_lookup':
|
|
24
|
+
steps.push(this.createClarifyStep('step_3', 'Clarify low-confidence recall with LLM', 'step_2', threshold, {
|
|
25
|
+
query,
|
|
26
|
+
entityHint: classification.entityHint,
|
|
27
|
+
projectId: options.projectId
|
|
28
|
+
}));
|
|
29
|
+
break;
|
|
30
|
+
case 'temporal_recall':
|
|
31
|
+
steps.push(this.createStep('step_3', 'fact_check', 'Check temporal facts for the hinted entity', {
|
|
32
|
+
query,
|
|
33
|
+
entityHint: classification.entityHint,
|
|
34
|
+
projectId: options.projectId,
|
|
35
|
+
subjectHint: classification.entityHint,
|
|
36
|
+
predicateHint: 'any'
|
|
37
|
+
}), this.createClarifyStep('step_4', 'Clarify low-confidence temporal evidence with LLM', 'step_3', threshold, {
|
|
38
|
+
query,
|
|
39
|
+
entityHint: classification.entityHint,
|
|
40
|
+
projectId: options.projectId
|
|
41
|
+
}));
|
|
42
|
+
break;
|
|
43
|
+
case 'cross_domain':
|
|
44
|
+
steps.push(this.createStep('step_3', 'graph_traverse', 'Traverse connected memory graph for related domains', {
|
|
45
|
+
query,
|
|
46
|
+
entityHint: classification.entityHint,
|
|
47
|
+
projectId: options.projectId
|
|
48
|
+
}), this.createStep('step_4', 'confidence_check', 'Evaluate confidence of graph traversal evidence', {
|
|
49
|
+
query,
|
|
50
|
+
entityHint: classification.entityHint,
|
|
51
|
+
projectId: options.projectId
|
|
52
|
+
}), this.createClarifyStep('step_5', 'Clarify low-confidence graph evidence with LLM', 'step_4', threshold, {
|
|
53
|
+
query,
|
|
54
|
+
entityHint: classification.entityHint,
|
|
55
|
+
projectId: options.projectId
|
|
56
|
+
}));
|
|
57
|
+
break;
|
|
58
|
+
case 'correction_check':
|
|
59
|
+
steps.push(this.createStep('step_3', 'fact_check', 'Check whether the prior fact was superseded', {
|
|
60
|
+
query,
|
|
61
|
+
entityHint: classification.entityHint,
|
|
62
|
+
projectId: options.projectId,
|
|
63
|
+
subjectHint: classification.entityHint,
|
|
64
|
+
predicateHint: 'superseded'
|
|
65
|
+
}), this.createClarifyStep('step_4', 'Clarify low-confidence correction evidence with LLM', 'step_2', threshold, {
|
|
66
|
+
query,
|
|
67
|
+
entityHint: classification.entityHint,
|
|
68
|
+
projectId: options.projectId
|
|
69
|
+
}));
|
|
70
|
+
break;
|
|
71
|
+
case 'open_ended':
|
|
72
|
+
steps.push(this.createClarifyStep('step_3', 'Clarify open-ended request with LLM', 'step_2', threshold, {
|
|
73
|
+
query,
|
|
74
|
+
entityHint: classification.entityHint,
|
|
75
|
+
projectId: options.projectId
|
|
76
|
+
}));
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
planId: randomUUID(),
|
|
81
|
+
intentType: classification.intentType,
|
|
82
|
+
query,
|
|
83
|
+
steps,
|
|
84
|
+
estimatedLLMCalls: steps.filter((step) => step.type === 'llm_clarify').length
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
createStep(id, type, label, inputs) {
|
|
88
|
+
return {
|
|
89
|
+
id,
|
|
90
|
+
type,
|
|
91
|
+
label,
|
|
92
|
+
inputs,
|
|
93
|
+
mayCallLLM: false
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
createClarifyStep(id, label, dependsOnStepId, threshold, inputs) {
|
|
97
|
+
return {
|
|
98
|
+
id,
|
|
99
|
+
type: 'llm_clarify',
|
|
100
|
+
label,
|
|
101
|
+
inputs,
|
|
102
|
+
triggerCondition: {
|
|
103
|
+
dependsOnStepId,
|
|
104
|
+
metric: 'confidence_score',
|
|
105
|
+
operator: 'lt',
|
|
106
|
+
threshold
|
|
107
|
+
},
|
|
108
|
+
mayCallLLM: true
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ToolCallParser.ts
|
|
3
|
+
* Parses LLM output to extract BrainToolCall JSON objects or detect final answers.
|
|
4
|
+
* Phase 46 — v1.1 ReAct
|
|
5
|
+
*/
|
|
6
|
+
import type { BrainToolCall } from './LLMToolSchema.js';
|
|
7
|
+
/**
|
|
8
|
+
* Parse the LLM output and return a BrainToolCall if the response is a
|
|
9
|
+
* tool invocation, or `null` if it is a final natural-language answer.
|
|
10
|
+
*/
|
|
11
|
+
export declare function parse(llmOutput: string): BrainToolCall | null;
|
|
12
|
+
/**
|
|
13
|
+
* Returns true when the LLM output is a final answer (no tool call detected).
|
|
14
|
+
*/
|
|
15
|
+
export declare function isFinalAnswer(llmOutput: string): boolean;
|
|
16
|
+
//# sourceMappingURL=ToolCallParser.d.ts.map
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ToolCallParser.ts
|
|
3
|
+
* Parses LLM output to extract BrainToolCall JSON objects or detect final answers.
|
|
4
|
+
* Phase 46 — v1.1 ReAct
|
|
5
|
+
*/
|
|
6
|
+
import { getRequiredParams } from './LLMToolSchema.js';
|
|
7
|
+
const ALLOWED_ACTIONS = new Set([
|
|
8
|
+
'brain_recall',
|
|
9
|
+
'get_neuron_context',
|
|
10
|
+
'expand_entity',
|
|
11
|
+
'find_file_assets',
|
|
12
|
+
'get_file_context',
|
|
13
|
+
]);
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
// Helpers
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
/**
|
|
18
|
+
* Attempts to extract the first JSON object from an arbitrary string.
|
|
19
|
+
* The LLM may prefix its call with explanatory text, e.g.:
|
|
20
|
+
* "I need more details.\n{\"action\":\"brain_recall\",...}"
|
|
21
|
+
*
|
|
22
|
+
* Strategy: scan for the first '{' that starts a valid JSON object.
|
|
23
|
+
*/
|
|
24
|
+
function extractFirstJsonObject(text) {
|
|
25
|
+
let depth = 0;
|
|
26
|
+
let start = -1;
|
|
27
|
+
for (let i = 0; i < text.length; i++) {
|
|
28
|
+
const ch = text[i];
|
|
29
|
+
if (ch === '{') {
|
|
30
|
+
if (depth === 0)
|
|
31
|
+
start = i;
|
|
32
|
+
depth++;
|
|
33
|
+
}
|
|
34
|
+
else if (ch === '}') {
|
|
35
|
+
depth--;
|
|
36
|
+
if (depth === 0 && start !== -1) {
|
|
37
|
+
const candidate = text.slice(start, i + 1);
|
|
38
|
+
try {
|
|
39
|
+
const parsed = JSON.parse(candidate);
|
|
40
|
+
if (parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
41
|
+
return parsed;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// not valid JSON, continue scanning
|
|
46
|
+
depth = 0;
|
|
47
|
+
start = -1;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
// ---------------------------------------------------------------------------
|
|
55
|
+
// Public API
|
|
56
|
+
// ---------------------------------------------------------------------------
|
|
57
|
+
/**
|
|
58
|
+
* Parse the LLM output and return a BrainToolCall if the response is a
|
|
59
|
+
* tool invocation, or `null` if it is a final natural-language answer.
|
|
60
|
+
*/
|
|
61
|
+
export function parse(llmOutput) {
|
|
62
|
+
if (!llmOutput || typeof llmOutput !== 'string')
|
|
63
|
+
return null;
|
|
64
|
+
const trimmed = llmOutput.trim();
|
|
65
|
+
if (trimmed.startsWith('[')) {
|
|
66
|
+
try {
|
|
67
|
+
if (Array.isArray(JSON.parse(trimmed)))
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
// Fall through to object extraction for malformed text with later JSON.
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const obj = extractFirstJsonObject(llmOutput);
|
|
75
|
+
if (obj === null)
|
|
76
|
+
return null;
|
|
77
|
+
const action = obj['action'];
|
|
78
|
+
if (typeof action !== 'string')
|
|
79
|
+
return null;
|
|
80
|
+
if (!ALLOWED_ACTIONS.has(action))
|
|
81
|
+
return null;
|
|
82
|
+
const toolName = action;
|
|
83
|
+
// Validate required parameters
|
|
84
|
+
const required = getRequiredParams(toolName);
|
|
85
|
+
for (const param of required) {
|
|
86
|
+
if (obj[param] === undefined || obj[param] === null || obj[param] === '') {
|
|
87
|
+
return null; // missing required field → treat as final answer
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// Build the typed BrainToolCall
|
|
91
|
+
const call = { action: toolName };
|
|
92
|
+
if (typeof obj['query'] === 'string')
|
|
93
|
+
call.query = obj['query'];
|
|
94
|
+
if (typeof obj['entity_hint'] === 'string')
|
|
95
|
+
call.entity_hint = obj['entity_hint'];
|
|
96
|
+
if (typeof obj['limit'] === 'number')
|
|
97
|
+
call.limit = obj['limit'];
|
|
98
|
+
if (typeof obj['neuron_id'] === 'string')
|
|
99
|
+
call.neuron_id = obj['neuron_id'];
|
|
100
|
+
if (typeof obj['entity_name'] === 'string')
|
|
101
|
+
call.entity_name = obj['entity_name'];
|
|
102
|
+
if (typeof obj['entity_type'] === 'string')
|
|
103
|
+
call.entity_type = obj['entity_type'];
|
|
104
|
+
if (typeof obj['extension'] === 'string')
|
|
105
|
+
call.extension = obj['extension'];
|
|
106
|
+
if (typeof obj['mime_type'] === 'string')
|
|
107
|
+
call.mime_type = obj['mime_type'];
|
|
108
|
+
if (typeof obj['asset_id'] === 'string')
|
|
109
|
+
call.asset_id = obj['asset_id'];
|
|
110
|
+
if (typeof obj['chunk_index'] === 'number')
|
|
111
|
+
call.chunk_index = obj['chunk_index'];
|
|
112
|
+
if (typeof obj['radius'] === 'number')
|
|
113
|
+
call.radius = obj['radius'];
|
|
114
|
+
if (typeof obj['reason'] === 'string')
|
|
115
|
+
call.reason = obj['reason'];
|
|
116
|
+
return call;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Returns true when the LLM output is a final answer (no tool call detected).
|
|
120
|
+
*/
|
|
121
|
+
export function isFinalAnswer(llmOutput) {
|
|
122
|
+
return parse(llmOutput) === null;
|
|
123
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { BrainToolCall, BrainToolResult } from './LLMToolSchema.js';
|
|
2
|
+
import { type ToolEvidenceItem } from './ToolEvidencePack.js';
|
|
3
|
+
export interface ToolEvidenceNormalizeInput {
|
|
4
|
+
toolResult: BrainToolResult;
|
|
5
|
+
call: BrainToolCall;
|
|
6
|
+
sanitizedResult: unknown;
|
|
7
|
+
projectId?: string;
|
|
8
|
+
injectionRiskDetected?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare class ToolEvidenceNormalizer {
|
|
11
|
+
normalize(input: ToolEvidenceNormalizeInput): ToolEvidenceItem;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=ToolEvidenceNormalizer.d.ts.map
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { estimateTokens } from './ToolEvidencePack.js';
|
|
2
|
+
export class ToolEvidenceNormalizer {
|
|
3
|
+
normalize(input) {
|
|
4
|
+
const payload = objectPayload(input.sanitizedResult);
|
|
5
|
+
const facts = factArray(payload.facts);
|
|
6
|
+
const events = eventArray(payload.events);
|
|
7
|
+
const neurons = neuronSummaries(payload);
|
|
8
|
+
const entityIds = entityIdsFor(input.call, payload, facts);
|
|
9
|
+
const beliefs = beliefArray(payload.beliefs);
|
|
10
|
+
const query = input.call.query ?? input.call.neuron_id ?? input.call.entity_name ?? '';
|
|
11
|
+
const relevanceScore = computeRelevance(query, facts, events, neurons, beliefs);
|
|
12
|
+
return {
|
|
13
|
+
toolCallId: input.toolResult.callId,
|
|
14
|
+
toolName: input.toolResult.toolName,
|
|
15
|
+
query,
|
|
16
|
+
facts,
|
|
17
|
+
events,
|
|
18
|
+
neurons,
|
|
19
|
+
entityIds,
|
|
20
|
+
beliefs,
|
|
21
|
+
relevanceScore,
|
|
22
|
+
estimatedTokens: estimateTokens(JSON.stringify({ facts, events, neurons, entityIds, beliefs })),
|
|
23
|
+
addedAt: Date.now(),
|
|
24
|
+
projectId: input.projectId,
|
|
25
|
+
sanitized: true,
|
|
26
|
+
injectionRiskDetected: input.injectionRiskDetected ?? false,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function objectPayload(value) {
|
|
31
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
32
|
+
}
|
|
33
|
+
function factArray(value) {
|
|
34
|
+
return Array.isArray(value) ? value : [];
|
|
35
|
+
}
|
|
36
|
+
function eventArray(value) {
|
|
37
|
+
return Array.isArray(value) ? value : [];
|
|
38
|
+
}
|
|
39
|
+
function beliefArray(value) {
|
|
40
|
+
return Array.isArray(value) ? value : [];
|
|
41
|
+
}
|
|
42
|
+
function neuronSummaries(payload) {
|
|
43
|
+
const summaries = [];
|
|
44
|
+
const neuron = objectPayload(payload.neuron);
|
|
45
|
+
if (typeof neuron.neuronId === 'string') {
|
|
46
|
+
summaries.push({
|
|
47
|
+
neuronId: neuron.neuronId,
|
|
48
|
+
contentPreview: String(neuron.content ?? '').slice(0, 500),
|
|
49
|
+
tags: Array.isArray(neuron.tags) ? neuron.tags.filter((tag) => typeof tag === 'string') : [],
|
|
50
|
+
type: typeof neuron.type === 'string' ? neuron.type : 'unknown',
|
|
51
|
+
createdAt: typeof neuron.createdAt === 'number' ? neuron.createdAt : undefined,
|
|
52
|
+
projectId: typeof neuron.projectId === 'string' ? neuron.projectId : undefined,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
const neighbors = Array.isArray(payload.neighbors) ? payload.neighbors : [];
|
|
56
|
+
for (const raw of neighbors) {
|
|
57
|
+
const n = objectPayload(raw);
|
|
58
|
+
if (typeof n.neuronId !== 'string')
|
|
59
|
+
continue;
|
|
60
|
+
summaries.push({
|
|
61
|
+
neuronId: n.neuronId,
|
|
62
|
+
contentPreview: String(n.content ?? '').slice(0, 300),
|
|
63
|
+
tags: Array.isArray(n.tags) ? n.tags.filter((tag) => typeof tag === 'string') : [],
|
|
64
|
+
type: typeof n.type === 'string' ? n.type : 'unknown',
|
|
65
|
+
projectId: typeof n.projectId === 'string' ? n.projectId : undefined,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return summaries;
|
|
69
|
+
}
|
|
70
|
+
function entityIdsFor(call, payload, facts) {
|
|
71
|
+
const ids = new Set();
|
|
72
|
+
if (typeof payload.entityId === 'string')
|
|
73
|
+
ids.add(payload.entityId);
|
|
74
|
+
if (call.entity_name && typeof payload.entityId === 'string')
|
|
75
|
+
ids.add(payload.entityId);
|
|
76
|
+
for (const fact of facts) {
|
|
77
|
+
if (fact.entityId)
|
|
78
|
+
ids.add(fact.entityId);
|
|
79
|
+
}
|
|
80
|
+
return Array.from(ids);
|
|
81
|
+
}
|
|
82
|
+
function computeRelevance(query, facts, events, neurons, beliefs) {
|
|
83
|
+
const q = query.toLowerCase();
|
|
84
|
+
if (!q)
|
|
85
|
+
return 0.5;
|
|
86
|
+
const haystacks = [
|
|
87
|
+
...facts.map((f) => `${f.subject} ${f.predicateFamily} ${f.predicateValue ?? ''} ${f.object ?? ''}`),
|
|
88
|
+
...events.map((e) => `${e.eventType} ${e.actor ?? ''} ${e.target ?? ''}`),
|
|
89
|
+
...neurons.map((n) => n.contentPreview),
|
|
90
|
+
...beliefs.map((b) => `${b.subject} ${b.predicate} ${b.objectValue.raw}`),
|
|
91
|
+
];
|
|
92
|
+
if (haystacks.length === 0)
|
|
93
|
+
return 0.1;
|
|
94
|
+
const hits = haystacks.filter((text) => text.toLowerCase().includes(q)).length;
|
|
95
|
+
return Math.max(0.2, Math.min(1, hits / haystacks.length + 0.4));
|
|
96
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { BeliefRecord } from '../types/index.js';
|
|
2
|
+
import type { EventRecord, FactRecord } from '../store/FactStore.js';
|
|
3
|
+
import type { BrainToolName } from './LLMToolSchema.js';
|
|
4
|
+
export interface NeuronEvidenceSummary {
|
|
5
|
+
neuronId: string;
|
|
6
|
+
contentPreview: string;
|
|
7
|
+
tags: string[];
|
|
8
|
+
type: string;
|
|
9
|
+
createdAt?: number;
|
|
10
|
+
projectId?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ToolEvidenceItem {
|
|
13
|
+
toolCallId: string;
|
|
14
|
+
toolName: BrainToolName;
|
|
15
|
+
query: string;
|
|
16
|
+
facts: FactRecord[];
|
|
17
|
+
events: EventRecord[];
|
|
18
|
+
neurons: NeuronEvidenceSummary[];
|
|
19
|
+
entityIds: string[];
|
|
20
|
+
beliefs: BeliefRecord[];
|
|
21
|
+
relevanceScore: number;
|
|
22
|
+
estimatedTokens: number;
|
|
23
|
+
addedAt: number;
|
|
24
|
+
projectId?: string;
|
|
25
|
+
sanitized: boolean;
|
|
26
|
+
injectionRiskDetected: boolean;
|
|
27
|
+
}
|
|
28
|
+
export declare class ToolEvidencePack {
|
|
29
|
+
readonly items: ToolEvidenceItem[];
|
|
30
|
+
add(item: ToolEvidenceItem): void;
|
|
31
|
+
deduplicate(): void;
|
|
32
|
+
totalTokens(): number;
|
|
33
|
+
toPromptSummary(limit: number): string;
|
|
34
|
+
}
|
|
35
|
+
export declare function estimateTokens(text: string): number;
|
|
36
|
+
//# sourceMappingURL=ToolEvidencePack.d.ts.map
|