@iworkforces/tracelattice 2.0.3
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/LICENSE +24 -0
- package/README.md +260 -0
- package/dist/CliLifecycle.d.ts +31 -0
- package/dist/CliLifecycle.d.ts.map +1 -0
- package/dist/CliLifecycle.js +90 -0
- package/dist/CliLifecycle.js.map +1 -0
- package/dist/ServerConfig.d.ts +290 -0
- package/dist/ServerConfig.d.ts.map +1 -0
- package/dist/ServerConfig.js +175 -0
- package/dist/ServerConfig.js.map +1 -0
- package/dist/cache/DiscoveryCache.d.ts +269 -0
- package/dist/cache/DiscoveryCache.d.ts.map +1 -0
- package/dist/cache/DiscoveryCache.js +104 -0
- package/dist/cache/DiscoveryCache.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +5177 -0
- package/dist/cli.js.map +1 -0
- package/dist/config/ConfigLoader.d.ts +270 -0
- package/dist/config/ConfigLoader.d.ts.map +1 -0
- package/dist/config/ConfigLoader.js +186 -0
- package/dist/config/ConfigLoader.js.map +1 -0
- package/dist/context/RequestContext.d.ts +43 -0
- package/dist/context/RequestContext.d.ts.map +1 -0
- package/dist/context/RequestContext.js +14 -0
- package/dist/context/RequestContext.js.map +1 -0
- package/dist/contracts/PersistenceBackend.d.ts +134 -0
- package/dist/contracts/PersistenceBackend.d.ts.map +1 -0
- package/dist/contracts/PersistenceBackend.js +6 -0
- package/dist/contracts/PersistenceBackend.js.map +1 -0
- package/dist/contracts/calibrator.d.ts +97 -0
- package/dist/contracts/calibrator.d.ts.map +1 -0
- package/dist/contracts/calibrator.js +1 -0
- package/dist/contracts/features.d.ts +35 -0
- package/dist/contracts/features.d.ts.map +1 -0
- package/dist/contracts/features.js +12 -0
- package/dist/contracts/features.js.map +1 -0
- package/dist/contracts/ids.d.ts +68 -0
- package/dist/contracts/ids.d.ts.map +1 -0
- package/dist/contracts/ids.js +40 -0
- package/dist/contracts/ids.js.map +1 -0
- package/dist/contracts/interfaces.d.ts +254 -0
- package/dist/contracts/interfaces.d.ts.map +1 -0
- package/dist/contracts/interfaces.js +1 -0
- package/dist/contracts/persistence-work.d.ts +96 -0
- package/dist/contracts/persistence-work.d.ts.map +1 -0
- package/dist/contracts/persistence-work.js +1 -0
- package/dist/contracts/reasoning-types.d.ts +21 -0
- package/dist/contracts/reasoning-types.d.ts.map +1 -0
- package/dist/contracts/reasoning-types.js +1 -0
- package/dist/contracts/strategy.d.ts +107 -0
- package/dist/contracts/strategy.d.ts.map +1 -0
- package/dist/contracts/strategy.js +1 -0
- package/dist/contracts/summary.d.ts +110 -0
- package/dist/contracts/summary.d.ts.map +1 -0
- package/dist/contracts/summary.js +1 -0
- package/dist/contracts/suspension.d.ts +215 -0
- package/dist/contracts/suspension.d.ts.map +1 -0
- package/dist/contracts/suspension.js +1 -0
- package/dist/contracts/transport.d.ts +26 -0
- package/dist/contracts/transport.d.ts.map +1 -0
- package/dist/contracts/transport.js +1 -0
- package/dist/core/CrossReferenceValidator.d.ts +18 -0
- package/dist/core/CrossReferenceValidator.d.ts.map +1 -0
- package/dist/core/CrossReferenceValidator.js +125 -0
- package/dist/core/CrossReferenceValidator.js.map +1 -0
- package/dist/core/HistoryManager.d.ts +215 -0
- package/dist/core/HistoryManager.d.ts.map +1 -0
- package/dist/core/HistoryManager.js +594 -0
- package/dist/core/HistoryManager.js.map +1 -0
- package/dist/core/IHistoryManager.d.ts +163 -0
- package/dist/core/IHistoryManager.d.ts.map +1 -0
- package/dist/core/IHistoryManager.js +1 -0
- package/dist/core/IThoughtFormatter.d.ts +51 -0
- package/dist/core/IThoughtFormatter.d.ts.map +1 -0
- package/dist/core/IThoughtFormatter.js +1 -0
- package/dist/core/InputNormalizer.d.ts +140 -0
- package/dist/core/InputNormalizer.d.ts.map +1 -0
- package/dist/core/InputNormalizer.js +95 -0
- package/dist/core/InputNormalizer.js.map +1 -0
- package/dist/core/PersistenceBuffer.d.ts +204 -0
- package/dist/core/PersistenceBuffer.d.ts.map +1 -0
- package/dist/core/PersistenceBuffer.js +382 -0
- package/dist/core/PersistenceBuffer.js.map +1 -0
- package/dist/core/PersistenceBufferErrors.d.ts +22 -0
- package/dist/core/PersistenceBufferErrors.d.ts.map +1 -0
- package/dist/core/PersistenceBufferErrors.js +30 -0
- package/dist/core/PersistenceBufferErrors.js.map +1 -0
- package/dist/core/PersistenceRestore.d.ts +21 -0
- package/dist/core/PersistenceRestore.d.ts.map +1 -0
- package/dist/core/PersistenceRestore.js +87 -0
- package/dist/core/PersistenceRestore.js.map +1 -0
- package/dist/core/PersistenceWorkQueue.d.ts +155 -0
- package/dist/core/PersistenceWorkQueue.d.ts.map +1 -0
- package/dist/core/PersistenceWorkQueue.js +298 -0
- package/dist/core/PersistenceWorkQueue.js.map +1 -0
- package/dist/core/PersistenceWriter.d.ts +55 -0
- package/dist/core/PersistenceWriter.d.ts.map +1 -0
- package/dist/core/PersistenceWriter.js +112 -0
- package/dist/core/PersistenceWriter.js.map +1 -0
- package/dist/core/SessionErrors.d.ts +37 -0
- package/dist/core/SessionErrors.d.ts.map +1 -0
- package/dist/core/SessionErrors.js +50 -0
- package/dist/core/SessionErrors.js.map +1 -0
- package/dist/core/SessionLifecycleCoordinator.d.ts +74 -0
- package/dist/core/SessionLifecycleCoordinator.d.ts.map +1 -0
- package/dist/core/SessionLifecycleCoordinator.js +222 -0
- package/dist/core/SessionLifecycleCoordinator.js.map +1 -0
- package/dist/core/SessionLock.d.ts +59 -0
- package/dist/core/SessionLock.d.ts.map +1 -0
- package/dist/core/SessionLock.js +39 -0
- package/dist/core/SessionLock.js.map +1 -0
- package/dist/core/SessionManager.d.ts +62 -0
- package/dist/core/SessionManager.d.ts.map +1 -0
- package/dist/core/SessionManager.js +75 -0
- package/dist/core/SessionManager.js.map +1 -0
- package/dist/core/SessionResetCoordinator.d.ts +37 -0
- package/dist/core/SessionResetCoordinator.d.ts.map +1 -0
- package/dist/core/SessionResetCoordinator.js +80 -0
- package/dist/core/SessionResetCoordinator.js.map +1 -0
- package/dist/core/ThoughtEvaluator.d.ts +48 -0
- package/dist/core/ThoughtEvaluator.d.ts.map +1 -0
- package/dist/core/ThoughtEvaluator.js +85 -0
- package/dist/core/ThoughtEvaluator.js.map +1 -0
- package/dist/core/ThoughtFormatter.d.ts +134 -0
- package/dist/core/ThoughtFormatter.d.ts.map +1 -0
- package/dist/core/ThoughtFormatter.js +118 -0
- package/dist/core/ThoughtFormatter.js.map +1 -0
- package/dist/core/ThoughtProcessor.d.ts +259 -0
- package/dist/core/ThoughtProcessor.d.ts.map +1 -0
- package/dist/core/ThoughtProcessor.js +451 -0
- package/dist/core/ThoughtProcessor.js.map +1 -0
- package/dist/core/ThoughtReferenceIndex.d.ts +23 -0
- package/dist/core/ThoughtReferenceIndex.d.ts.map +1 -0
- package/dist/core/ThoughtReferenceIndex.js +66 -0
- package/dist/core/ThoughtReferenceIndex.js.map +1 -0
- package/dist/core/VerificationOutcomeAdmission.d.ts +15 -0
- package/dist/core/VerificationOutcomeAdmission.d.ts.map +1 -0
- package/dist/core/VerificationOutcomeAdmission.js +28 -0
- package/dist/core/VerificationOutcomeAdmission.js.map +1 -0
- package/dist/core/compression/CompressionService.d.ts +76 -0
- package/dist/core/compression/CompressionService.d.ts.map +1 -0
- package/dist/core/compression/CompressionService.js +160 -0
- package/dist/core/compression/CompressionService.js.map +1 -0
- package/dist/core/compression/DehydrationPolicy.d.ts +75 -0
- package/dist/core/compression/DehydrationPolicy.d.ts.map +1 -0
- package/dist/core/compression/DehydrationPolicy.js +45 -0
- package/dist/core/compression/DehydrationPolicy.js.map +1 -0
- package/dist/core/compression/InMemorySummaryStore.d.ts +132 -0
- package/dist/core/compression/InMemorySummaryStore.d.ts.map +1 -0
- package/dist/core/compression/InMemorySummaryStore.js +69 -0
- package/dist/core/compression/InMemorySummaryStore.js.map +1 -0
- package/dist/core/compression/Summary.d.ts +74 -0
- package/dist/core/compression/Summary.d.ts.map +1 -0
- package/dist/core/compression/Summary.js +16 -0
- package/dist/core/compression/Summary.js.map +1 -0
- package/dist/core/evaluator/Aggregator.d.ts +40 -0
- package/dist/core/evaluator/Aggregator.d.ts.map +1 -0
- package/dist/core/evaluator/Aggregator.js +36 -0
- package/dist/core/evaluator/Aggregator.js.map +1 -0
- package/dist/core/evaluator/Calibrator.d.ts +52 -0
- package/dist/core/evaluator/Calibrator.d.ts.map +1 -0
- package/dist/core/evaluator/Calibrator.js +135 -0
- package/dist/core/evaluator/Calibrator.js.map +1 -0
- package/dist/core/evaluator/PatternDetector.d.ts +69 -0
- package/dist/core/evaluator/PatternDetector.d.ts.map +1 -0
- package/dist/core/evaluator/PatternDetector.js +192 -0
- package/dist/core/evaluator/PatternDetector.js.map +1 -0
- package/dist/core/evaluator/SignalComputer.d.ts +116 -0
- package/dist/core/evaluator/SignalComputer.d.ts.map +1 -0
- package/dist/core/evaluator/SignalComputer.js +110 -0
- package/dist/core/evaluator/SignalComputer.js.map +1 -0
- package/dist/core/evaluator/calibration-math.d.ts +39 -0
- package/dist/core/evaluator/calibration-math.d.ts.map +1 -0
- package/dist/core/evaluator/calibration-math.js +42 -0
- package/dist/core/evaluator/calibration-math.js.map +1 -0
- package/dist/core/evaluator/internals.d.ts +36 -0
- package/dist/core/evaluator/internals.d.ts.map +1 -0
- package/dist/core/evaluator/internals.js +43 -0
- package/dist/core/evaluator/internals.js.map +1 -0
- package/dist/core/graph/Edge.d.ts +58 -0
- package/dist/core/graph/Edge.d.ts.map +1 -0
- package/dist/core/graph/Edge.js +1 -0
- package/dist/core/graph/EdgeEmitter.d.ts +68 -0
- package/dist/core/graph/EdgeEmitter.d.ts.map +1 -0
- package/dist/core/graph/EdgeEmitter.js +118 -0
- package/dist/core/graph/EdgeEmitter.js.map +1 -0
- package/dist/core/graph/EdgeStore.d.ts +116 -0
- package/dist/core/graph/EdgeStore.d.ts.map +1 -0
- package/dist/core/graph/EdgeStore.js +107 -0
- package/dist/core/graph/EdgeStore.js.map +1 -0
- package/dist/core/graph/GraphView.d.ts +157 -0
- package/dist/core/graph/GraphView.d.ts.map +1 -0
- package/dist/core/graph/GraphView.js +149 -0
- package/dist/core/graph/GraphView.js.map +1 -0
- package/dist/core/ids.d.ts +33 -0
- package/dist/core/ids.d.ts.map +1 -0
- package/dist/core/ids.js +11 -0
- package/dist/core/ids.js.map +1 -0
- package/dist/core/reasoning/OutcomeRecorder.d.ts +88 -0
- package/dist/core/reasoning/OutcomeRecorder.d.ts.map +1 -0
- package/dist/core/reasoning/OutcomeRecorder.js +51 -0
- package/dist/core/reasoning/OutcomeRecorder.js.map +1 -0
- package/dist/core/reasoning/strategies/SequentialStrategy.d.ts +54 -0
- package/dist/core/reasoning/strategies/SequentialStrategy.d.ts.map +1 -0
- package/dist/core/reasoning/strategies/SequentialStrategy.js +22 -0
- package/dist/core/reasoning/strategies/SequentialStrategy.js.map +1 -0
- package/dist/core/reasoning/strategies/StrategyFactory.d.ts +25 -0
- package/dist/core/reasoning/strategies/StrategyFactory.d.ts.map +1 -0
- package/dist/core/reasoning/strategies/StrategyFactory.js +16 -0
- package/dist/core/reasoning/strategies/StrategyFactory.js.map +1 -0
- package/dist/core/reasoning/strategies/TreeOfThoughtStrategy.d.ts +58 -0
- package/dist/core/reasoning/strategies/TreeOfThoughtStrategy.d.ts.map +1 -0
- package/dist/core/reasoning/strategies/TreeOfThoughtStrategy.js +103 -0
- package/dist/core/reasoning/strategies/TreeOfThoughtStrategy.js.map +1 -0
- package/dist/core/reasoning/strategies/plateau.d.ts +18 -0
- package/dist/core/reasoning/strategies/plateau.d.ts.map +1 -0
- package/dist/core/reasoning/strategies/plateau.js +12 -0
- package/dist/core/reasoning/strategies/plateau.js.map +1 -0
- package/dist/core/reasoning/strategies/totScoring.d.ts +91 -0
- package/dist/core/reasoning/strategies/totScoring.d.ts.map +1 -0
- package/dist/core/reasoning/strategies/totScoring.js +88 -0
- package/dist/core/reasoning/strategies/totScoring.js.map +1 -0
- package/dist/core/reasoning.d.ts +179 -0
- package/dist/core/reasoning.d.ts.map +1 -0
- package/dist/core/reasoning.js +1 -0
- package/dist/core/step.d.ts +50 -0
- package/dist/core/step.d.ts.map +1 -0
- package/dist/core/step.js +1 -0
- package/dist/core/thought.d.ts +113 -0
- package/dist/core/thought.d.ts.map +1 -0
- package/dist/core/thought.js +1 -0
- package/dist/core/tools/InMemorySuspensionStore.d.ts +66 -0
- package/dist/core/tools/InMemorySuspensionStore.d.ts.map +1 -0
- package/dist/core/tools/InMemorySuspensionStore.js +121 -0
- package/dist/core/tools/InMemorySuspensionStore.js.map +1 -0
- package/dist/di/Container.d.ts +253 -0
- package/dist/di/Container.d.ts.map +1 -0
- package/dist/di/Container.js +111 -0
- package/dist/di/Container.js.map +1 -0
- package/dist/di/ServiceRegistry.d.ts +50 -0
- package/dist/di/ServiceRegistry.d.ts.map +1 -0
- package/dist/di/ServiceRegistry.js +1 -0
- package/dist/errors.d.ts +663 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +282 -0
- package/dist/errors.js.map +1 -0
- package/dist/health/HealthChecker.d.ts +73 -0
- package/dist/health/HealthChecker.d.ts.map +1 -0
- package/dist/health/HealthChecker.js +70 -0
- package/dist/health/HealthChecker.js.map +1 -0
- package/dist/lib.d.ts +273 -0
- package/dist/lib.d.ts.map +1 -0
- package/dist/lib.js +409 -0
- package/dist/lib.js.map +1 -0
- package/dist/logger/NullLogger.d.ts +154 -0
- package/dist/logger/NullLogger.d.ts.map +1 -0
- package/dist/logger/NullLogger.js +24 -0
- package/dist/logger/NullLogger.js.map +1 -0
- package/dist/logger/StructuredLogger.d.ts +327 -0
- package/dist/logger/StructuredLogger.d.ts.map +1 -0
- package/dist/logger/StructuredLogger.js +72 -0
- package/dist/logger/StructuredLogger.js.map +1 -0
- package/dist/metrics/metrics.impl.d.ts +252 -0
- package/dist/metrics/metrics.impl.d.ts.map +1 -0
- package/dist/metrics/metrics.impl.js +197 -0
- package/dist/metrics/metrics.impl.js.map +1 -0
- package/dist/persistence/FileLegacyImport.d.ts +2 -0
- package/dist/persistence/FileLegacyImport.d.ts.map +1 -0
- package/dist/persistence/FileLegacyImport.js +183 -0
- package/dist/persistence/FileLegacyImport.js.map +1 -0
- package/dist/persistence/FilePersistence.d.ts +53 -0
- package/dist/persistence/FilePersistence.d.ts.map +1 -0
- package/dist/persistence/FilePersistence.js +312 -0
- package/dist/persistence/FilePersistence.js.map +1 -0
- package/dist/persistence/FileSnapshotTypes.d.ts +29 -0
- package/dist/persistence/FileSnapshotTypes.d.ts.map +1 -0
- package/dist/persistence/FileSnapshotTypes.js +1 -0
- package/dist/persistence/FileSnapshotV2.d.ts +377 -0
- package/dist/persistence/FileSnapshotV2.d.ts.map +1 -0
- package/dist/persistence/FileSnapshotV2.js +124 -0
- package/dist/persistence/FileSnapshotV2.js.map +1 -0
- package/dist/persistence/FileSnapshotValidation.d.ts +15 -0
- package/dist/persistence/FileSnapshotValidation.d.ts.map +1 -0
- package/dist/persistence/FileSnapshotValidation.js +64 -0
- package/dist/persistence/FileSnapshotValidation.js.map +1 -0
- package/dist/persistence/FileWriter.d.ts +30 -0
- package/dist/persistence/FileWriter.d.ts.map +1 -0
- package/dist/persistence/FileWriter.js +155 -0
- package/dist/persistence/FileWriter.js.map +1 -0
- package/dist/persistence/MemoryPersistence.d.ts +45 -0
- package/dist/persistence/MemoryPersistence.d.ts.map +1 -0
- package/dist/persistence/MemoryPersistence.js +180 -0
- package/dist/persistence/MemoryPersistence.js.map +1 -0
- package/dist/persistence/PersistenceCodec.d.ts +7 -0
- package/dist/persistence/PersistenceCodec.d.ts.map +1 -0
- package/dist/persistence/PersistenceCodec.js +97 -0
- package/dist/persistence/PersistenceCodec.js.map +1 -0
- package/dist/persistence/PersistenceErrors.d.ts +23 -0
- package/dist/persistence/PersistenceErrors.d.ts.map +1 -0
- package/dist/persistence/PersistenceErrors.js +26 -0
- package/dist/persistence/PersistenceErrors.js.map +1 -0
- package/dist/persistence/PersistenceFactory.d.ts +21 -0
- package/dist/persistence/PersistenceFactory.d.ts.map +1 -0
- package/dist/persistence/PersistenceFactory.js +28 -0
- package/dist/persistence/PersistenceFactory.js.map +1 -0
- package/dist/persistence/PersistenceScope.d.ts +42 -0
- package/dist/persistence/PersistenceScope.d.ts.map +1 -0
- package/dist/persistence/PersistenceScope.js +93 -0
- package/dist/persistence/PersistenceScope.js.map +1 -0
- package/dist/persistence/SessionScopedPersistence.d.ts +4 -0
- package/dist/persistence/SessionScopedPersistence.d.ts.map +1 -0
- package/dist/persistence/SessionScopedPersistence.js +9 -0
- package/dist/persistence/SessionScopedPersistence.js.map +1 -0
- package/dist/persistence/SqliteDriver.d.ts +22 -0
- package/dist/persistence/SqliteDriver.d.ts.map +1 -0
- package/dist/persistence/SqliteDriver.js +29 -0
- package/dist/persistence/SqliteDriver.js.map +1 -0
- package/dist/persistence/SqliteLegacyImport.d.ts +14 -0
- package/dist/persistence/SqliteLegacyImport.d.ts.map +1 -0
- package/dist/persistence/SqliteLegacyImport.js +136 -0
- package/dist/persistence/SqliteLegacyImport.js.map +1 -0
- package/dist/persistence/SqliteLegacySchema.d.ts +15 -0
- package/dist/persistence/SqliteLegacySchema.d.ts.map +1 -0
- package/dist/persistence/SqliteLegacySchema.js +72 -0
- package/dist/persistence/SqliteLegacySchema.js.map +1 -0
- package/dist/persistence/SqlitePayload.d.ts +11 -0
- package/dist/persistence/SqlitePayload.d.ts.map +1 -0
- package/dist/persistence/SqlitePayload.js +86 -0
- package/dist/persistence/SqlitePayload.js.map +1 -0
- package/dist/persistence/SqlitePersistence.d.ts +49 -0
- package/dist/persistence/SqlitePersistence.d.ts.map +1 -0
- package/dist/persistence/SqlitePersistence.js +248 -0
- package/dist/persistence/SqlitePersistence.js.map +1 -0
- package/dist/persistence/SqliteSchemaV2.d.ts +14 -0
- package/dist/persistence/SqliteSchemaV2.d.ts.map +1 -0
- package/dist/persistence/SqliteSchemaV2.js +129 -0
- package/dist/persistence/SqliteSchemaV2.js.map +1 -0
- package/dist/persistence/SqliteSnapshotWriter.d.ts +17 -0
- package/dist/persistence/SqliteSnapshotWriter.d.ts.map +1 -0
- package/dist/persistence/SqliteSnapshotWriter.js +30 -0
- package/dist/persistence/SqliteSnapshotWriter.js.map +1 -0
- package/dist/pool/ConnectionPool.d.ts +203 -0
- package/dist/pool/ConnectionPool.d.ts.map +1 -0
- package/dist/pool/ConnectionPool.js +303 -0
- package/dist/pool/ConnectionPool.js.map +1 -0
- package/dist/pool/IConnectionPool.d.ts +143 -0
- package/dist/pool/IConnectionPool.d.ts.map +1 -0
- package/dist/pool/IConnectionPool.js +1 -0
- package/dist/pool/PoolErrors.d.ts +11 -0
- package/dist/pool/PoolErrors.d.ts.map +1 -0
- package/dist/pool/PoolErrors.js +16 -0
- package/dist/pool/PoolErrors.js.map +1 -0
- package/dist/registry/BaseRegistry.d.ts +219 -0
- package/dist/registry/BaseRegistry.d.ts.map +1 -0
- package/dist/registry/BaseRegistry.js +215 -0
- package/dist/registry/BaseRegistry.js.map +1 -0
- package/dist/registry/SkillRegistry.d.ts +67 -0
- package/dist/registry/SkillRegistry.d.ts.map +1 -0
- package/dist/registry/SkillRegistry.js +87 -0
- package/dist/registry/SkillRegistry.js.map +1 -0
- package/dist/registry/ToolRegistry.d.ts +70 -0
- package/dist/registry/ToolRegistry.d.ts.map +1 -0
- package/dist/registry/ToolRegistry.js +96 -0
- package/dist/registry/ToolRegistry.js.map +1 -0
- package/dist/sanitize.d.ts +164 -0
- package/dist/sanitize.d.ts.map +1 -0
- package/dist/sanitize.js +100 -0
- package/dist/sanitize.js.map +1 -0
- package/dist/schema.d.ts +562 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +251 -0
- package/dist/schema.js.map +1 -0
- package/dist/transport/BaseTransport.d.ts +166 -0
- package/dist/transport/BaseTransport.d.ts.map +1 -0
- package/dist/transport/BaseTransport.js +199 -0
- package/dist/transport/BaseTransport.js.map +1 -0
- package/dist/transport/HttpHelpers.d.ts +53 -0
- package/dist/transport/HttpHelpers.d.ts.map +1 -0
- package/dist/transport/HttpHelpers.js +44 -0
- package/dist/transport/HttpHelpers.js.map +1 -0
- package/dist/transport/HttpRequestLifecycle.d.ts +37 -0
- package/dist/transport/HttpRequestLifecycle.d.ts.map +1 -0
- package/dist/transport/HttpRequestLifecycle.js +87 -0
- package/dist/transport/HttpRequestLifecycle.js.map +1 -0
- package/dist/transport/HttpTransport.d.ts +140 -0
- package/dist/transport/HttpTransport.d.ts.map +1 -0
- package/dist/transport/HttpTransport.js +245 -0
- package/dist/transport/HttpTransport.js.map +1 -0
- package/dist/transport/SseTransport.d.ts +149 -0
- package/dist/transport/SseTransport.d.ts.map +1 -0
- package/dist/transport/SseTransport.js +470 -0
- package/dist/transport/SseTransport.js.map +1 -0
- package/dist/transport/StreamableHttpTransport.d.ts +225 -0
- package/dist/transport/StreamableHttpTransport.d.ts.map +1 -0
- package/dist/transport/StreamableHttpTransport.js +449 -0
- package/dist/transport/StreamableHttpTransport.js.map +1 -0
- package/dist/types/disposable.d.ts +22 -0
- package/dist/types/disposable.d.ts.map +1 -0
- package/dist/types/disposable.js +1 -0
- package/dist/types/server-config.d.ts +32 -0
- package/dist/types/server-config.d.ts.map +1 -0
- package/dist/types/server-config.js +1 -0
- package/dist/types/skill.d.ts +74 -0
- package/dist/types/skill.d.ts.map +1 -0
- package/dist/types/skill.js +1 -0
- package/dist/types/tool.d.ts +78 -0
- package/dist/types/tool.d.ts.map +1 -0
- package/dist/types/tool.js +1 -0
- package/dist/utils.d.ts +27 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +6 -0
- package/dist/utils.js.map +1 -0
- package/dist/watchers/SkillWatcher.d.ts +25 -0
- package/dist/watchers/SkillWatcher.d.ts.map +1 -0
- package/dist/watchers/SkillWatcher.js +96 -0
- package/dist/watchers/SkillWatcher.js.map +1 -0
- package/dist/watchers/ToolWatcher.d.ts +24 -0
- package/dist/watchers/ToolWatcher.d.ts.map +1 -0
- package/dist/watchers/ToolWatcher.js +92 -0
- package/dist/watchers/ToolWatcher.js.map +1 -0
- package/package.json +106 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Suspension store contract for tool interleave.
|
|
3
|
+
*
|
|
4
|
+
* Manages pending tool_call thoughts that are awaiting tool execution
|
|
5
|
+
* results. Each suspension is identified by a unique token, has a TTL,
|
|
6
|
+
* and can be resumed (consumed) or peeked (non-destructive lookup).
|
|
7
|
+
*
|
|
8
|
+
* @module contracts/suspension
|
|
9
|
+
*/
|
|
10
|
+
import type { SessionId, SuspensionToken, ThoughtId } from './ids.js';
|
|
11
|
+
/**
|
|
12
|
+
* A single pending tool-call suspension record.
|
|
13
|
+
*
|
|
14
|
+
* Created when a `tool_call` thought is processed and the system is
|
|
15
|
+
* waiting for the corresponding tool result to be supplied via a
|
|
16
|
+
* follow-up `tool_result` thought.
|
|
17
|
+
*/
|
|
18
|
+
export interface SuspensionRecord {
|
|
19
|
+
/** Opaque token used to resume this suspension. */
|
|
20
|
+
readonly token: SuspensionToken;
|
|
21
|
+
/** Session that owns this suspension. */
|
|
22
|
+
readonly sessionId: SessionId;
|
|
23
|
+
/** Thought number of the originating `tool_call` thought. */
|
|
24
|
+
readonly toolCallThoughtNumber: number;
|
|
25
|
+
/** Stable identity of the originating `tool_call` thought. */
|
|
26
|
+
readonly toolCallThoughtId: ThoughtId;
|
|
27
|
+
/** Name of the tool to invoke. */
|
|
28
|
+
readonly toolName: string;
|
|
29
|
+
/** Arguments supplied to the tool. */
|
|
30
|
+
readonly toolArguments: Record<string, unknown>;
|
|
31
|
+
/** Wall-clock millisecond timestamp when the record was created. */
|
|
32
|
+
readonly createdAt: number;
|
|
33
|
+
/** Wall-clock millisecond timestamp after which the record is expired. */
|
|
34
|
+
readonly expiresAt: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Store of pending tool-call suspensions with TTL expiry.
|
|
38
|
+
*
|
|
39
|
+
* Implementations are expected to expire records lazily on access and
|
|
40
|
+
* (optionally) eagerly via a background sweeper started by `start()`.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const store: ISuspensionStore = new InMemorySuspensionStore();
|
|
45
|
+
* store.start();
|
|
46
|
+
* const rec = store.suspend({
|
|
47
|
+
* sessionId: 's1',
|
|
48
|
+
* toolCallThoughtNumber: 3,
|
|
49
|
+
* toolCallThoughtId: 'thought-3',
|
|
50
|
+
* toolName: 'search',
|
|
51
|
+
* toolArguments: { q: 'foo' },
|
|
52
|
+
* expiresAt: Date.now() + 60_000,
|
|
53
|
+
* });
|
|
54
|
+
* const resumed = store.resume(rec.token);
|
|
55
|
+
* store.stop();
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export interface ISuspensionStore {
|
|
59
|
+
/**
|
|
60
|
+
* Create and store a new suspension record.
|
|
61
|
+
*
|
|
62
|
+
* The implementation generates a unique `token` and `createdAt`
|
|
63
|
+
* timestamp. If `ttlMs` is supplied, `expiresAt` is computed as
|
|
64
|
+
* `Date.now() + ttlMs` and overrides any caller-supplied
|
|
65
|
+
* `expiresAt` value.
|
|
66
|
+
*
|
|
67
|
+
* @param record - Record fields excluding `token` and `createdAt`,
|
|
68
|
+
* with optional `ttlMs` to derive `expiresAt`.
|
|
69
|
+
* @returns The fully-populated stored record.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const rec = store.suspend({
|
|
74
|
+
* sessionId: 's1',
|
|
75
|
+
* toolCallThoughtNumber: 2,
|
|
76
|
+
* toolCallThoughtId: 'thought-2',
|
|
77
|
+
* toolName: 'search',
|
|
78
|
+
* toolArguments: {},
|
|
79
|
+
* ttlMs: 30_000,
|
|
80
|
+
* expiresAt: 0,
|
|
81
|
+
* });
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
suspend(record: Omit<SuspensionRecord, 'token' | 'createdAt'> & {
|
|
85
|
+
ttlMs?: number;
|
|
86
|
+
}): SuspensionRecord;
|
|
87
|
+
/**
|
|
88
|
+
* Consume a suspension by token.
|
|
89
|
+
*
|
|
90
|
+
* Returns `null` for both unknown tokens and expired records;
|
|
91
|
+
* expired records are removed as a side-effect. The caller
|
|
92
|
+
* (typically `ThoughtProcessor`) is expected to distinguish the
|
|
93
|
+
* two cases (e.g. via a prior `peek()`) and throw
|
|
94
|
+
* `SuspensionNotFoundError` or `SuspensionExpiredError`
|
|
95
|
+
* accordingly.
|
|
96
|
+
*
|
|
97
|
+
* @param token - Token returned from {@link suspend}.
|
|
98
|
+
* @returns The record on success, `null` if missing or expired.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const rec = store.resume(token);
|
|
103
|
+
* if (!rec) throw new SuspensionNotFoundError(token);
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
resume(token: string): SuspensionRecord | null;
|
|
107
|
+
/**
|
|
108
|
+
* Atomically validate and admit one suspended continuation.
|
|
109
|
+
*
|
|
110
|
+
* Operations sharing a token are serialized. The record must exist, remain
|
|
111
|
+
* unexpired, and belong to `expectedSessionId`. Session mismatches are
|
|
112
|
+
* reported as not found without consuming the record. `admit` runs
|
|
113
|
+
* synchronously inside the token critical section; the record is consumed
|
|
114
|
+
* only after the callback returns successfully.
|
|
115
|
+
*
|
|
116
|
+
* @param token - Opaque continuation token returned from {@link suspend}.
|
|
117
|
+
* @param expectedSessionId - Canonical session presenting the continuation.
|
|
118
|
+
* @param admit - Synchronous history-admission callback.
|
|
119
|
+
* @returns The admitted and consumed suspension record.
|
|
120
|
+
* @throws {SuspensionNotFoundError} If the token is missing or belongs to another session.
|
|
121
|
+
* @throws {SuspensionExpiredError} If the token expires at or before admission.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* const record = await store.compareAndAdmit(token, sessionId, (candidate) => {
|
|
126
|
+
* history.addThought(observation, { toolInvocationSourceThoughtId: candidate.toolCallThoughtId });
|
|
127
|
+
* });
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
compareAndAdmit(token: SuspensionToken, expectedSessionId: SessionId, admit: (record: SuspensionRecord) => void): Promise<SuspensionRecord>;
|
|
131
|
+
/**
|
|
132
|
+
* Non-destructive lookup of a suspension by token.
|
|
133
|
+
*
|
|
134
|
+
* Does not remove expired records. Returns `null` if the token is
|
|
135
|
+
* unknown.
|
|
136
|
+
*
|
|
137
|
+
* @param token - Token to inspect.
|
|
138
|
+
* @returns The record if present (even when expired), else `null`.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* const rec = store.peek(token);
|
|
143
|
+
* if (rec && rec.expiresAt < Date.now()) {
|
|
144
|
+
* throw new SuspensionExpiredError(token);
|
|
145
|
+
* }
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
peek(token: string): SuspensionRecord | null;
|
|
149
|
+
/**
|
|
150
|
+
* Remove all records whose `expiresAt` is at or before `now`.
|
|
151
|
+
*
|
|
152
|
+
* @param now - Wall-clock millisecond timestamp to compare against.
|
|
153
|
+
* @returns Number of records removed.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* const removed = store.expireOlderThan(Date.now());
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
expireOlderThan(now: number): number;
|
|
161
|
+
/**
|
|
162
|
+
* Remove all records belonging to a session.
|
|
163
|
+
*
|
|
164
|
+
* @param sessionId - Session whose records should be cleared.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* store.clearSession('session-a');
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
clearSession(sessionId: SessionId): void;
|
|
172
|
+
/**
|
|
173
|
+
* Discard records from every session namespace.
|
|
174
|
+
* Use only for a trusted process-wide reset; scoped callers must use `clearSession`.
|
|
175
|
+
*/
|
|
176
|
+
clearAll(): void;
|
|
177
|
+
/**
|
|
178
|
+
* Count stored records.
|
|
179
|
+
*
|
|
180
|
+
* @param sessionId - Optional session filter; when omitted, returns
|
|
181
|
+
* the total count across all sessions.
|
|
182
|
+
* @returns Number of currently stored records (expired-but-not-yet-swept
|
|
183
|
+
* records are included).
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* const total = store.size();
|
|
188
|
+
* const perSession = store.size('session-a');
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
size(sessionId?: string): number;
|
|
192
|
+
/**
|
|
193
|
+
* Start the background sweeper, if any.
|
|
194
|
+
*
|
|
195
|
+
* Idempotent — repeated calls have no additional effect.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* store.start();
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
start(): void;
|
|
203
|
+
/**
|
|
204
|
+
* Stop the background sweeper, if any.
|
|
205
|
+
*
|
|
206
|
+
* Idempotent — repeated calls have no additional effect.
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```typescript
|
|
210
|
+
* store.stop();
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
stop(): void;
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=suspension.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suspension.d.ts","sourceRoot":"","sources":["../../src/contracts/suspension.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAEtE;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAChC,mDAAmD;IACnD,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC;IAChC,yCAAyC;IACzC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,6DA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EjB;;;;;;;;;;;;;OAaG;IACH,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAEjC;;;;;;;;;OASG;IACH,KAAK,IAAI,IAAI,CAAC;IAEd;;;;;;;;;OASG;IACH,IAAI,IAAI,IAAI,CAAC;CACb"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transport kind discriminator.
|
|
3
|
+
*/
|
|
4
|
+
import type { McpServer } from 'tmcp';
|
|
5
|
+
export type TransportKind = 'sse' | 'http' | 'streamable-http';
|
|
6
|
+
/**
|
|
7
|
+
* Shared lifecycle interface for MCP transports.
|
|
8
|
+
*
|
|
9
|
+
* All transports (SSE, HTTP, Streamable HTTP) implement this interface.
|
|
10
|
+
* Share lifecycle only — request/response shapes genuinely differ across transports.
|
|
11
|
+
*/
|
|
12
|
+
export interface ITransport {
|
|
13
|
+
/** Discriminator for transport type identification. */
|
|
14
|
+
readonly kind: TransportKind;
|
|
15
|
+
/** Connect the transport to an MCP server. */
|
|
16
|
+
connect(mcpServer: McpServer): Promise<void>;
|
|
17
|
+
/** Stop the transport with graceful shutdown. */
|
|
18
|
+
stop(timeout?: number): Promise<void>;
|
|
19
|
+
/** Number of currently active client connections. */
|
|
20
|
+
readonly clientCount: number;
|
|
21
|
+
/** Whether the transport is in the process of shutting down. */
|
|
22
|
+
readonly isShuttingDown: boolean;
|
|
23
|
+
/** The server URL for client connections. */
|
|
24
|
+
readonly serverUrl: string;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/contracts/transport.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEtC,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,MAAM,GAAG,iBAAiB,CAAC;AAE/D;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IAC1B,uDAAuD;IACvD,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAE7B,8CAA8C;IAC9C,OAAO,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7C,iDAAiD;IACjD,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtC,qDAAqD;IACrD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B,gEAAgE;IAChE,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC;IAEjC,6CAA6C;IAC7C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Logger } from '../logger/StructuredLogger.js';
|
|
2
|
+
import type { HistorySessionSnapshot, ResolvedThoughtReferences } from './IHistoryManager.js';
|
|
3
|
+
import type { ThoughtData } from './thought.js';
|
|
4
|
+
import type { ThoughtReferenceResolution } from './ThoughtReferenceIndex.js';
|
|
5
|
+
export interface CrossReferenceValidationResult {
|
|
6
|
+
readonly result: ThoughtData;
|
|
7
|
+
readonly warnings: string[];
|
|
8
|
+
readonly resolvedReferences: ResolvedThoughtReferences;
|
|
9
|
+
}
|
|
10
|
+
export interface CrossReferenceValidationContext {
|
|
11
|
+
readonly snapshot: HistorySessionSnapshot;
|
|
12
|
+
readonly resolveThoughtReference: (thoughtNumber: number) => ThoughtReferenceResolution;
|
|
13
|
+
readonly strictBranchReferences: boolean;
|
|
14
|
+
readonly logger: Logger;
|
|
15
|
+
}
|
|
16
|
+
export declare function validateThoughtCrossReferences(input: ThoughtData, context: CrossReferenceValidationContext): CrossReferenceValidationResult;
|
|
17
|
+
export declare function resolveThoughtReferencesForAdmission(input: ThoughtData, resolveThoughtReference: (thoughtNumber: number) => ThoughtReferenceResolution): ResolvedThoughtReferences;
|
|
18
|
+
//# sourceMappingURL=CrossReferenceValidator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CrossReferenceValidator.d.ts","sourceRoot":"","sources":["../../src/core/CrossReferenceValidator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,KAAK,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAC9F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAK7E,MAAM,WAAW,8BAA8B;IAC9C,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;IAC5B,QAAQ,CAAC,kBAAkB,EAAE,yBAAyB,CAAC;CACvD;AAED,MAAM,WAAW,+BAA+B;IAC/C,QAAQ,CAAC,QAAQ,EAAE,sBAAsB,CAAC;IAC1C,QAAQ,CAAC,uBAAuB,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,0BAA0B,CAAC;IACxF,QAAQ,CAAC,sBAAsB,EAAE,OAAO,CAAC;IACzC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACxB;AAED,wBAAgB,8BAA8B,CAC7C,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,+BAA+B,GACtC,8BAA8B,CAsBhC;AAED,wBAAgB,oCAAoC,CACnD,KAAK,EAAE,WAAW,EAClB,uBAAuB,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,0BAA0B,GAC5E,yBAAyB,CAkC3B"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { InvalidBacktrackError, ValidationError } from "../errors.js";
|
|
2
|
+
function validateThoughtCrossReferences(input, context) {
|
|
3
|
+
const warnings = [];
|
|
4
|
+
const resolvedReferences = Object.freeze({
|
|
5
|
+
verificationTargetThoughtId: validateScalarReference(input, 'verification_target', context, warnings),
|
|
6
|
+
revisesThoughtId: validateScalarReference(input, 'revises_thought', context, warnings),
|
|
7
|
+
branchFromThoughtId: validateScalarReference(input, 'branch_from_thought', context, warnings),
|
|
8
|
+
synthesisSourceThoughtIds: filterThoughtReferences(input, 'synthesis_sources', context, warnings),
|
|
9
|
+
mergeFromThoughtIds: filterThoughtReferences(input, 'merge_from_thoughts', context, warnings),
|
|
10
|
+
backtrackTargetThoughtId: resolveBacktrackTarget(input, context)
|
|
11
|
+
});
|
|
12
|
+
filterBranchReferences(input, context, warnings);
|
|
13
|
+
return {
|
|
14
|
+
result: input,
|
|
15
|
+
warnings,
|
|
16
|
+
resolvedReferences
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function resolveThoughtReferencesForAdmission(input, resolveThoughtReference) {
|
|
20
|
+
const resolveUnique = (thoughtNumber)=>{
|
|
21
|
+
if (void 0 === thoughtNumber) return;
|
|
22
|
+
const resolution = resolveThoughtReference(thoughtNumber);
|
|
23
|
+
return 'unique' === resolution.kind ? resolution.thoughtId : void 0;
|
|
24
|
+
};
|
|
25
|
+
const resolveArray = (thoughtNumbers)=>{
|
|
26
|
+
if (void 0 === thoughtNumbers) return;
|
|
27
|
+
const resolved = thoughtNumbers.flatMap((thoughtNumber)=>{
|
|
28
|
+
const thoughtId = resolveUnique(thoughtNumber);
|
|
29
|
+
return void 0 === thoughtId ? [] : [
|
|
30
|
+
thoughtId
|
|
31
|
+
];
|
|
32
|
+
});
|
|
33
|
+
return 0 === resolved.length ? void 0 : Object.freeze(resolved);
|
|
34
|
+
};
|
|
35
|
+
const backtrackResolution = 'backtrack' === input.thought_type && void 0 !== input.backtrack_target ? resolveThoughtReference(input.backtrack_target) : void 0;
|
|
36
|
+
if (void 0 !== backtrackResolution && 'unique' !== backtrackResolution.kind) throw new InvalidBacktrackError(`backtrack_target ${input.backtrack_target} is ${backtrackResolution.kind} in session history`);
|
|
37
|
+
return Object.freeze({
|
|
38
|
+
verificationTargetThoughtId: resolveUnique(input.verification_target),
|
|
39
|
+
revisesThoughtId: resolveUnique(input.revises_thought),
|
|
40
|
+
branchFromThoughtId: resolveUnique(input.branch_from_thought),
|
|
41
|
+
synthesisSourceThoughtIds: resolveArray(input.synthesis_sources),
|
|
42
|
+
mergeFromThoughtIds: resolveArray(input.merge_from_thoughts),
|
|
43
|
+
backtrackTargetThoughtId: backtrackResolution?.kind === 'unique' ? backtrackResolution.thoughtId : void 0
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function validateScalarReference(input, field, context, warnings) {
|
|
47
|
+
const target = input[field];
|
|
48
|
+
const strictVerificationTarget = 'verification_target' === field && 'verification' === input.thought_type && void 0 !== input.verification_result;
|
|
49
|
+
if (void 0 === target) {
|
|
50
|
+
if (strictVerificationTarget) throw new ValidationError('verification_result', 'requires verification_target');
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const resolution = context.resolveThoughtReference(target);
|
|
54
|
+
if ('unique' === resolution.kind) return resolution.thoughtId;
|
|
55
|
+
if (strictVerificationTarget) throw new ValidationError('verification_result', `verification_target ${target} is ${resolution.kind} in session history`);
|
|
56
|
+
const descriptor = 'missing' === resolution.kind ? 'dangling' : 'ambiguous';
|
|
57
|
+
warnings.push(`Dropped ${descriptor} ${field}: ${target} (history has ${context.snapshot.history.length} thoughts)`);
|
|
58
|
+
context.logger.warn(`Dropped ${descriptor} ${field}`, {
|
|
59
|
+
[field]: target,
|
|
60
|
+
historyLength: context.snapshot.history.length
|
|
61
|
+
});
|
|
62
|
+
input[field] = void 0;
|
|
63
|
+
}
|
|
64
|
+
function filterThoughtReferences(input, field, context, warnings) {
|
|
65
|
+
const references = input[field];
|
|
66
|
+
if (!references?.length) return;
|
|
67
|
+
const valid = [];
|
|
68
|
+
const validThoughtIds = [];
|
|
69
|
+
const dangling = [];
|
|
70
|
+
const ambiguous = [];
|
|
71
|
+
for (const thoughtNumber of references){
|
|
72
|
+
const resolution = context.resolveThoughtReference(thoughtNumber);
|
|
73
|
+
switch(resolution.kind){
|
|
74
|
+
case 'unique':
|
|
75
|
+
valid.push(thoughtNumber);
|
|
76
|
+
validThoughtIds.push(resolution.thoughtId);
|
|
77
|
+
break;
|
|
78
|
+
case 'missing':
|
|
79
|
+
dangling.push(thoughtNumber);
|
|
80
|
+
break;
|
|
81
|
+
case 'ambiguous':
|
|
82
|
+
ambiguous.push(thoughtNumber);
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
appendFilteredWarning(input, field, 'dangling', dangling, valid, context, warnings);
|
|
87
|
+
appendFilteredWarning(input, field, 'ambiguous', ambiguous, valid, context, warnings);
|
|
88
|
+
input[field] = valid.length > 0 ? valid : void 0;
|
|
89
|
+
return validThoughtIds.length > 0 ? Object.freeze(validThoughtIds) : void 0;
|
|
90
|
+
}
|
|
91
|
+
function resolveBacktrackTarget(input, context) {
|
|
92
|
+
if ('backtrack' !== input.thought_type || void 0 === input.backtrack_target) return;
|
|
93
|
+
const resolution = context.resolveThoughtReference(input.backtrack_target);
|
|
94
|
+
if ('unique' === resolution.kind) return resolution.thoughtId;
|
|
95
|
+
throw new InvalidBacktrackError('backtrack_target ' + input.backtrack_target + ('missing' === resolution.kind ? ' does not exist in session history' : ' is ambiguous in session history'));
|
|
96
|
+
}
|
|
97
|
+
function appendFilteredWarning(input, field, descriptor, dropped, valid, context, warnings) {
|
|
98
|
+
if (0 === dropped.length) return;
|
|
99
|
+
warnings.push(`Filtered ${descriptor} ${field}: [${dropped.join(', ')}] (history has ${context.snapshot.history.length} thoughts)`);
|
|
100
|
+
context.logger.warn(`Filtered ${descriptor} ${field}`, {
|
|
101
|
+
original: input[field],
|
|
102
|
+
filtered: valid,
|
|
103
|
+
historyLength: context.snapshot.history.length
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function filterBranchReferences(input, context, warnings) {
|
|
107
|
+
const references = input.merge_branch_ids;
|
|
108
|
+
if (!references?.length) return;
|
|
109
|
+
const existingBranches = new Set(context.snapshot.branchIds);
|
|
110
|
+
const valid = references.filter((branchId)=>existingBranches.has(branchId));
|
|
111
|
+
const dropped = references.filter((branchId)=>!existingBranches.has(branchId));
|
|
112
|
+
if (dropped.length > 0) {
|
|
113
|
+
if (context.strictBranchReferences) throw new ValidationError('merge_branch_ids', `references missing branches [${dropped.join(', ')}]`);
|
|
114
|
+
warnings.push(`Filtered dangling merge_branch_ids: [${dropped.join(', ')}]`);
|
|
115
|
+
context.logger.warn('Filtered dangling merge_branch_ids', {
|
|
116
|
+
original: references,
|
|
117
|
+
filtered: valid,
|
|
118
|
+
existingBranches: context.snapshot.branchIds
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
input.merge_branch_ids = valid.length > 0 ? valid : void 0;
|
|
122
|
+
}
|
|
123
|
+
export { resolveThoughtReferencesForAdmission, validateThoughtCrossReferences };
|
|
124
|
+
|
|
125
|
+
//# sourceMappingURL=CrossReferenceValidator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core/CrossReferenceValidator.js","sources":["../../src/core/CrossReferenceValidator.ts"],"sourcesContent":["import type { BranchId, ThoughtId } from '../contracts/ids.js';\nimport { InvalidBacktrackError, ValidationError } from '../errors.js';\nimport type { Logger } from '../logger/StructuredLogger.js';\nimport type { HistorySessionSnapshot, ResolvedThoughtReferences } from './IHistoryManager.js';\nimport type { ThoughtData } from './thought.js';\nimport type { ThoughtReferenceResolution } from './ThoughtReferenceIndex.js';\n\ntype ScalarReferenceField = 'verification_target' | 'revises_thought' | 'branch_from_thought';\ntype ThoughtReferenceField = 'synthesis_sources' | 'merge_from_thoughts';\n\nexport interface CrossReferenceValidationResult {\n\treadonly result: ThoughtData;\n\treadonly warnings: string[];\n\treadonly resolvedReferences: ResolvedThoughtReferences;\n}\n\nexport interface CrossReferenceValidationContext {\n\treadonly snapshot: HistorySessionSnapshot;\n\treadonly resolveThoughtReference: (thoughtNumber: number) => ThoughtReferenceResolution;\n\treadonly strictBranchReferences: boolean;\n\treadonly logger: Logger;\n}\n\nexport function validateThoughtCrossReferences(\n\tinput: ThoughtData,\n\tcontext: CrossReferenceValidationContext\n): CrossReferenceValidationResult {\n\tconst warnings: string[] = [];\n\tconst resolvedReferences = Object.freeze({\n\t\tverificationTargetThoughtId: validateScalarReference(\n\t\t\tinput,\n\t\t\t'verification_target',\n\t\t\tcontext,\n\t\t\twarnings\n\t\t),\n\t\trevisesThoughtId: validateScalarReference(input, 'revises_thought', context, warnings),\n\t\tbranchFromThoughtId: validateScalarReference(input, 'branch_from_thought', context, warnings),\n\t\tsynthesisSourceThoughtIds: filterThoughtReferences(\n\t\t\tinput,\n\t\t\t'synthesis_sources',\n\t\t\tcontext,\n\t\t\twarnings\n\t\t),\n\t\tmergeFromThoughtIds: filterThoughtReferences(input, 'merge_from_thoughts', context, warnings),\n\t\tbacktrackTargetThoughtId: resolveBacktrackTarget(input, context),\n\t});\n\tfilterBranchReferences(input, context, warnings);\n\treturn { result: input, warnings, resolvedReferences };\n}\n\nexport function resolveThoughtReferencesForAdmission(\n\tinput: ThoughtData,\n\tresolveThoughtReference: (thoughtNumber: number) => ThoughtReferenceResolution\n): ResolvedThoughtReferences {\n\tconst resolveUnique = (thoughtNumber: number | undefined): ThoughtId | undefined => {\n\t\tif (thoughtNumber === undefined) return undefined;\n\t\tconst resolution = resolveThoughtReference(thoughtNumber);\n\t\treturn resolution.kind === 'unique' ? resolution.thoughtId : undefined;\n\t};\n\tconst resolveArray = (\n\t\tthoughtNumbers: readonly number[] | undefined\n\t): readonly ThoughtId[] | undefined => {\n\t\tif (thoughtNumbers === undefined) return undefined;\n\t\tconst resolved = thoughtNumbers.flatMap((thoughtNumber) => {\n\t\t\tconst thoughtId = resolveUnique(thoughtNumber);\n\t\t\treturn thoughtId === undefined ? [] : [thoughtId];\n\t\t});\n\t\treturn resolved.length === 0 ? undefined : Object.freeze(resolved);\n\t};\n\tconst backtrackResolution =\n\t\tinput.thought_type === 'backtrack' && input.backtrack_target !== undefined\n\t\t\t? resolveThoughtReference(input.backtrack_target)\n\t\t\t: undefined;\n\tif (backtrackResolution !== undefined && backtrackResolution.kind !== 'unique') {\n\t\tthrow new InvalidBacktrackError(\n\t\t\t`backtrack_target ${input.backtrack_target} is ${backtrackResolution.kind} in session history`\n\t\t);\n\t}\n\treturn Object.freeze({\n\t\tverificationTargetThoughtId: resolveUnique(input.verification_target),\n\t\trevisesThoughtId: resolveUnique(input.revises_thought),\n\t\tbranchFromThoughtId: resolveUnique(input.branch_from_thought),\n\t\tsynthesisSourceThoughtIds: resolveArray(input.synthesis_sources),\n\t\tmergeFromThoughtIds: resolveArray(input.merge_from_thoughts),\n\t\tbacktrackTargetThoughtId:\n\t\t\tbacktrackResolution?.kind === 'unique' ? backtrackResolution.thoughtId : undefined,\n\t});\n}\n\nfunction validateScalarReference(\n\tinput: ThoughtData,\n\tfield: ScalarReferenceField,\n\tcontext: CrossReferenceValidationContext,\n\twarnings: string[]\n): ThoughtId | undefined {\n\tconst target = input[field];\n\tconst strictVerificationTarget =\n\t\tfield === 'verification_target' &&\n\t\tinput.thought_type === 'verification' &&\n\t\tinput.verification_result !== undefined;\n\tif (target === undefined) {\n\t\tif (strictVerificationTarget) {\n\t\t\tthrow new ValidationError('verification_result', 'requires verification_target');\n\t\t}\n\t\treturn undefined;\n\t}\n\tconst resolution = context.resolveThoughtReference(target);\n\tif (resolution.kind === 'unique') return resolution.thoughtId;\n\tif (strictVerificationTarget) {\n\t\tthrow new ValidationError(\n\t\t\t'verification_result',\n\t\t\t`verification_target ${target} is ${resolution.kind} in session history`\n\t\t);\n\t}\n\tconst descriptor = resolution.kind === 'missing' ? 'dangling' : 'ambiguous';\n\twarnings.push(\n\t\t`Dropped ${descriptor} ${field}: ${target} (history has ${context.snapshot.history.length} thoughts)`\n\t);\n\tcontext.logger.warn(`Dropped ${descriptor} ${field}`, {\n\t\t[field]: target,\n\t\thistoryLength: context.snapshot.history.length,\n\t});\n\tinput[field] = undefined;\n\treturn undefined;\n}\n\nfunction filterThoughtReferences(\n\tinput: ThoughtData,\n\tfield: ThoughtReferenceField,\n\tcontext: CrossReferenceValidationContext,\n\twarnings: string[]\n): readonly ThoughtId[] | undefined {\n\tconst references = input[field];\n\tif (!references?.length) return undefined;\n\tconst valid: number[] = [];\n\tconst validThoughtIds: ThoughtId[] = [];\n\tconst dangling: number[] = [];\n\tconst ambiguous: number[] = [];\n\tfor (const thoughtNumber of references) {\n\t\tconst resolution = context.resolveThoughtReference(thoughtNumber);\n\t\tswitch (resolution.kind) {\n\t\t\tcase 'unique':\n\t\t\t\tvalid.push(thoughtNumber);\n\t\t\t\tvalidThoughtIds.push(resolution.thoughtId);\n\t\t\t\tbreak;\n\t\t\tcase 'missing':\n\t\t\t\tdangling.push(thoughtNumber);\n\t\t\t\tbreak;\n\t\t\tcase 'ambiguous':\n\t\t\t\tambiguous.push(thoughtNumber);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tappendFilteredWarning(input, field, 'dangling', dangling, valid, context, warnings);\n\tappendFilteredWarning(input, field, 'ambiguous', ambiguous, valid, context, warnings);\n\tinput[field] = valid.length > 0 ? valid : undefined;\n\treturn validThoughtIds.length > 0 ? Object.freeze(validThoughtIds) : undefined;\n}\n\nfunction resolveBacktrackTarget(\n\tinput: ThoughtData,\n\tcontext: CrossReferenceValidationContext\n): ThoughtId | undefined {\n\tif (input.thought_type !== 'backtrack' || input.backtrack_target === undefined) return undefined;\n\tconst resolution = context.resolveThoughtReference(input.backtrack_target);\n\tif (resolution.kind === 'unique') return resolution.thoughtId;\n\tthrow new InvalidBacktrackError(\n\t\t'backtrack_target ' +\n\t\t\tinput.backtrack_target +\n\t\t\t(resolution.kind === 'missing'\n\t\t\t\t? ' does not exist in session history'\n\t\t\t\t: ' is ambiguous in session history')\n\t);\n}\n\nfunction appendFilteredWarning(\n\tinput: ThoughtData,\n\tfield: ThoughtReferenceField,\n\tdescriptor: 'dangling' | 'ambiguous',\n\tdropped: readonly number[],\n\tvalid: readonly number[],\n\tcontext: CrossReferenceValidationContext,\n\twarnings: string[]\n): void {\n\tif (dropped.length === 0) return;\n\twarnings.push(\n\t\t`Filtered ${descriptor} ${field}: [${dropped.join(', ')}] (history has ${context.snapshot.history.length} thoughts)`\n\t);\n\tcontext.logger.warn(`Filtered ${descriptor} ${field}`, {\n\t\toriginal: input[field],\n\t\tfiltered: valid,\n\t\thistoryLength: context.snapshot.history.length,\n\t});\n}\n\nfunction filterBranchReferences(\n\tinput: ThoughtData,\n\tcontext: CrossReferenceValidationContext,\n\twarnings: string[]\n): void {\n\tconst references = input.merge_branch_ids;\n\tif (!references?.length) return;\n\tconst existingBranches = new Set(context.snapshot.branchIds);\n\tconst valid = references.filter((branchId) => existingBranches.has(branchId));\n\tconst dropped = references.filter((branchId) => !existingBranches.has(branchId));\n\tif (dropped.length > 0) {\n\t\tif (context.strictBranchReferences) {\n\t\t\tthrow new ValidationError(\n\t\t\t\t'merge_branch_ids',\n\t\t\t\t`references missing branches [${dropped.join(', ')}]`\n\t\t\t);\n\t\t}\n\t\twarnings.push(`Filtered dangling merge_branch_ids: [${dropped.join(', ')}]`);\n\t\tcontext.logger.warn('Filtered dangling merge_branch_ids', {\n\t\t\toriginal: references,\n\t\t\tfiltered: valid,\n\t\t\texistingBranches: context.snapshot.branchIds,\n\t\t});\n\t}\n\tinput.merge_branch_ids = valid.length > 0 ? (valid as BranchId[]) : undefined;\n}\n"],"names":["validateThoughtCrossReferences","input","context","warnings","resolvedReferences","Object","validateScalarReference","filterThoughtReferences","resolveBacktrackTarget","filterBranchReferences","resolveThoughtReferencesForAdmission","resolveThoughtReference","resolveUnique","thoughtNumber","undefined","resolution","resolveArray","thoughtNumbers","resolved","thoughtId","backtrackResolution","InvalidBacktrackError","field","target","strictVerificationTarget","ValidationError","descriptor","references","valid","validThoughtIds","dangling","ambiguous","appendFilteredWar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,MAAM,CAAC,IAAI,CAAC,sCAAsC;YACzD,UAAUyB;YACV,UAAUC;YACV,kBAAkB1B,QAAQ,QAAQ,CAAC,SAAS;QAC7C;IACD;IACAD,MAAM,gBAAgB,GAAG2B,MAAM,MAAM,GAAG,IAAKA,QAAuBd;AACrE"}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* History and branch management for sequential thinking.
|
|
3
|
+
*
|
|
4
|
+
* This module provides the `HistoryManager` class which manages thought history,
|
|
5
|
+
* branching, and optional persistence with per-session state isolation.
|
|
6
|
+
*
|
|
7
|
+
* Internally delegates to three focused collaborators:
|
|
8
|
+
* - `EdgeEmitter` — DAG edge emission
|
|
9
|
+
* - `PersistenceBuffer` — buffered persistence + retry/backoff
|
|
10
|
+
* - `SessionManager` — session lifecycle (TTL/LRU eviction)
|
|
11
|
+
*
|
|
12
|
+
* @module HistoryManager
|
|
13
|
+
*/
|
|
14
|
+
import type { IEdgeStore, IMetrics, ISessionLock } from '../contracts/interfaces.js';
|
|
15
|
+
import { type BranchId, type SessionId } from '../contracts/ids.js';
|
|
16
|
+
import type { ISummaryStore } from '../contracts/summary.js';
|
|
17
|
+
import type { Logger } from '../logger/StructuredLogger.js';
|
|
18
|
+
import type { PersistenceBackend } from '../contracts/PersistenceBackend.js';
|
|
19
|
+
import { type DehydrationOptions, type HydratedEntry } from './compression/DehydrationPolicy.js';
|
|
20
|
+
import type { Summary } from './compression/Summary.js';
|
|
21
|
+
import type { HistorySessionSnapshot, IHistoryManager, ThoughtAdmissionContext } from './IHistoryManager.js';
|
|
22
|
+
import { type PersistenceEventEmitter } from './PersistenceBuffer.js';
|
|
23
|
+
import type { ThoughtData } from './thought.js';
|
|
24
|
+
import { type ThoughtReferenceResolution } from './ThoughtReferenceIndex.js';
|
|
25
|
+
import { SessionLifecycleCoordinator } from './SessionLifecycleCoordinator.js';
|
|
26
|
+
/** Absolute maximum history size (~20MB at 2KB/thought). Cannot be overridden. */
|
|
27
|
+
export declare const ABSOLUTE_MAX_HISTORY_SIZE = 10000;
|
|
28
|
+
export interface HistoryManagerConfig {
|
|
29
|
+
/** Maximum number of thoughts to keep in main history. @default 1000 */
|
|
30
|
+
maxHistorySize?: number;
|
|
31
|
+
/** Maximum number of branches to maintain. @default 50 */
|
|
32
|
+
maxBranches?: number;
|
|
33
|
+
/** Maximum size of each branch. @default 100 */
|
|
34
|
+
maxBranchSize?: number;
|
|
35
|
+
logger?: Logger;
|
|
36
|
+
persistence?: PersistenceBackend | null;
|
|
37
|
+
metrics?: IMetrics;
|
|
38
|
+
/** Maximum number of thoughts to buffer before flushing. @default 100 */
|
|
39
|
+
persistenceBufferSize?: number;
|
|
40
|
+
/** Periodic flush interval in ms. @default 1000 */
|
|
41
|
+
persistenceFlushInterval?: number;
|
|
42
|
+
/** Max retries for failed persistence flushes. @default 3 */
|
|
43
|
+
persistenceMaxRetries?: number;
|
|
44
|
+
eventEmitter?: PersistenceEventEmitter;
|
|
45
|
+
edgeStore?: IEdgeStore;
|
|
46
|
+
summaryStore?: ISummaryStore;
|
|
47
|
+
/** Whether to emit DAG edges (gated independently of edgeStore). @default false */
|
|
48
|
+
dagEdges?: boolean;
|
|
49
|
+
/** Maximum sessions per owner (per-owner LRU bucket). @default 50 */
|
|
50
|
+
maxSessionsPerOwner?: number;
|
|
51
|
+
/** Shared processor lock used to reject unsafe legacy synchronous clears. */
|
|
52
|
+
sessionLock?: ISessionLock;
|
|
53
|
+
/** Shared admission and exclusive lifecycle coordinator. */
|
|
54
|
+
lifecycleCoordinator?: SessionLifecycleCoordinator;
|
|
55
|
+
/** Clears processor-owned state after a session is actually removed. */
|
|
56
|
+
clearSessionAuxiliaryState?: (sessionId: SessionId) => void;
|
|
57
|
+
/** Clears all processor-owned state after a successful global lifecycle operation. */
|
|
58
|
+
clearAllAuxiliaryState?: () => void;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Manages thought history and branching for sequential thinking.
|
|
62
|
+
*
|
|
63
|
+
* Owns the per-session `Map<string, SessionState>`. Delegates DAG edge emission,
|
|
64
|
+
* buffered persistence, and session TTL/LRU eviction to focused collaborators while
|
|
65
|
+
* preserving test-coupled private member names (`_flushTimer`, `_startFlushTimer`,
|
|
66
|
+
* `_flushBuffer`, `_sessions`).
|
|
67
|
+
*/
|
|
68
|
+
export declare class HistoryManager implements IHistoryManager {
|
|
69
|
+
private static readonly DEFAULT_SESSION;
|
|
70
|
+
private static readonly SESSION_TTL_MS;
|
|
71
|
+
private static readonly MAX_SESSIONS;
|
|
72
|
+
private _sessions;
|
|
73
|
+
private _maxHistorySize;
|
|
74
|
+
private _maxBranches;
|
|
75
|
+
private _maxBranchSize;
|
|
76
|
+
private _logger;
|
|
77
|
+
private _persistence;
|
|
78
|
+
private _persistenceEnabled;
|
|
79
|
+
private _metrics?;
|
|
80
|
+
private _edgeStore?;
|
|
81
|
+
private _summaryStore?;
|
|
82
|
+
private _dagEdges;
|
|
83
|
+
private _eventEmitter;
|
|
84
|
+
private readonly _edgeEmitter;
|
|
85
|
+
private _referenceIndex;
|
|
86
|
+
private _persistenceBuffer;
|
|
87
|
+
private readonly _sessionManager;
|
|
88
|
+
private readonly _resetCoordinator;
|
|
89
|
+
private readonly _sessionLock?;
|
|
90
|
+
private readonly _lifecycle;
|
|
91
|
+
private _shutdownOwner;
|
|
92
|
+
private readonly _clearSessionAuxiliaryState?;
|
|
93
|
+
private readonly _clearAllAuxiliaryState?;
|
|
94
|
+
constructor(config?: HistoryManagerConfig);
|
|
95
|
+
private get _flushTimer();
|
|
96
|
+
private _startFlushTimer;
|
|
97
|
+
private _stopFlushTimer;
|
|
98
|
+
/** @internal Public for backward-compatible test coupling. */
|
|
99
|
+
_flushBuffer(): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Drains accepted persistence work and projects terminal failures to one session.
|
|
102
|
+
*
|
|
103
|
+
* @param sessionId - Authoritative session whose persistence barrier to await.
|
|
104
|
+
* @returns A promise that settles when the session's accepted work settles.
|
|
105
|
+
*/
|
|
106
|
+
drainSession(sessionId: SessionId): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Registers the latest summary snapshot for coordinator-owned persistence.
|
|
109
|
+
*
|
|
110
|
+
* @param sessionId - Authoritative session that owns the summaries.
|
|
111
|
+
* @param summaries - Complete current summary snapshot for the session.
|
|
112
|
+
*/
|
|
113
|
+
bufferSummaries(sessionId: SessionId, summaries: readonly Summary[]): void;
|
|
114
|
+
/** EdgeStore instance, if configured. Used by ThoughtProcessor for StrategyContext. */
|
|
115
|
+
getEdgeStore(): IEdgeStore | undefined;
|
|
116
|
+
private log;
|
|
117
|
+
/** Reads owner from RequestContext (AsyncLocalStorage). Stdio path returns undefined. */
|
|
118
|
+
private _getCurrentOwner;
|
|
119
|
+
/**
|
|
120
|
+
* Gets or creates session state; updates lastAccessedAt.
|
|
121
|
+
*
|
|
122
|
+
* Ownership semantics:
|
|
123
|
+
* - `owner === undefined` (stdio path): never rejects, never sets owner.
|
|
124
|
+
* - `owner !== undefined`: if session has a different owner, throws
|
|
125
|
+
* `SessionAccessDeniedError`. If session was created without an owner
|
|
126
|
+
* (e.g. by stdio), the owner is set on first owner-aware access.
|
|
127
|
+
*/
|
|
128
|
+
private _getSession;
|
|
129
|
+
private _getSessionWithinOperation;
|
|
130
|
+
private _assertSessionOwner;
|
|
131
|
+
private _makeCapacityForSession;
|
|
132
|
+
private _isCapacityEvictionEligible;
|
|
133
|
+
private _isTtlEvictionEligible;
|
|
134
|
+
private _isPersistenceQuiescent;
|
|
135
|
+
private _evictSessions;
|
|
136
|
+
private _evictSession;
|
|
137
|
+
private _removeLiveSession;
|
|
138
|
+
private _createSessionState;
|
|
139
|
+
private _authorizeExistingSession;
|
|
140
|
+
private _assertOwnerlessResetAll;
|
|
141
|
+
/**
|
|
142
|
+
* Adds a thought to the history. Routes per-session, applies retraction for backtrack,
|
|
143
|
+
* caches tools/skills, trims, branches, emits DAG edges, and buffers for persistence.
|
|
144
|
+
*/
|
|
145
|
+
addThought(thought: ThoughtData, context?: ThoughtAdmissionContext): void;
|
|
146
|
+
private _addThoughtWithinOperation;
|
|
147
|
+
private _resolveAdmissionReferences;
|
|
148
|
+
private _enforceRetention;
|
|
149
|
+
private _pruneUnretainedEdges;
|
|
150
|
+
private _bufferRetainedState;
|
|
151
|
+
private _stageAllRestoreBranchReconciliation;
|
|
152
|
+
private _stageRestoreBranchReconciliation;
|
|
153
|
+
private _stageBranchPersistence;
|
|
154
|
+
/** Marks the thought as retracted within the session (append-only). */
|
|
155
|
+
private _applyRetraction;
|
|
156
|
+
private _rebuildReferenceIndex;
|
|
157
|
+
resolveThoughtReference(sessionId: SessionId, thoughtNumber: number): ThoughtReferenceResolution;
|
|
158
|
+
private _addToSessionBranch;
|
|
159
|
+
private _cleanupSessionBranches;
|
|
160
|
+
private _trimSessionBranchSize;
|
|
161
|
+
getHistory(sessionId?: string): ThoughtData[];
|
|
162
|
+
/**
|
|
163
|
+
* Returns history with optional sliding-window dehydration. Non-mutating: when
|
|
164
|
+
* `dagEdges` is off OR no `ISummaryStore` is configured, returns same as getHistory.
|
|
165
|
+
*/
|
|
166
|
+
getHistoryHydrated(sessionId?: string, opts?: DehydrationOptions): HydratedEntry[];
|
|
167
|
+
getHistoryLength(sessionId?: string): number;
|
|
168
|
+
getBranches(sessionId?: string): Record<BranchId, ThoughtData[]>;
|
|
169
|
+
getBranchIds(sessionId?: string): BranchId[];
|
|
170
|
+
/** Returns validation state without creating a session, binding an owner, or updating LRU data. */
|
|
171
|
+
inspectSession(sessionId: string): HistorySessionSnapshot;
|
|
172
|
+
/** @throws {ValidationError} If branchId is empty or already exists. */
|
|
173
|
+
registerBranch(sessionId: string | undefined, branchId: BranchId): void;
|
|
174
|
+
branchExists(sessionId: string | undefined, branchId: BranchId): boolean;
|
|
175
|
+
getAvailableMcpTools(sessionId?: string): string[] | undefined;
|
|
176
|
+
getAvailableSkills(sessionId?: string): string[] | undefined;
|
|
177
|
+
getBranch(branchId: BranchId, sessionId?: string): ThoughtData[] | undefined;
|
|
178
|
+
/** Clears only persistence-disabled state synchronously. */
|
|
179
|
+
clear(sessionId?: string): void;
|
|
180
|
+
/** Awaitably deletes one authorized durable namespace before replacing its live state. */
|
|
181
|
+
resetSession(sessionId: string, clearAuxiliaryState?: () => void): Promise<void>;
|
|
182
|
+
/** Performs scoped reset work while its lifecycle exclusive is already owned. */
|
|
183
|
+
resetSessionWithinExclusive(sessionId: SessionId, clearAuxiliaryState?: () => void): Promise<void>;
|
|
184
|
+
/** Awaitably deletes all durable namespaces from a trusted ownerless context. */
|
|
185
|
+
resetAll(clearAuxiliaryState?: () => void): Promise<void>;
|
|
186
|
+
/** Performs global reset work while its lifecycle exclusive is already owned. */
|
|
187
|
+
resetAllWithinExclusive(clearAuxiliaryState?: () => void): Promise<void>;
|
|
188
|
+
clearSession(sessionId: string): void;
|
|
189
|
+
getSessionIds(): string[];
|
|
190
|
+
getSessionCount(): number;
|
|
191
|
+
private _restoredState;
|
|
192
|
+
/** Loads and atomically commits every authoritative persistence namespace. Call at init. */
|
|
193
|
+
loadFromPersistence(): Promise<void>;
|
|
194
|
+
isPersistenceEnabled(): boolean;
|
|
195
|
+
getPersistenceBackend(): PersistenceBackend | null;
|
|
196
|
+
/** Sets the event emitter for persistence error events (post-construction wiring). */
|
|
197
|
+
setEventEmitter(emitter: PersistenceEventEmitter): void;
|
|
198
|
+
/**
|
|
199
|
+
* Binds shutdown to the resource owner responsible for the complete cleanup sequence.
|
|
200
|
+
*
|
|
201
|
+
* @internal
|
|
202
|
+
* @param owner - Callback returning the owner's memoized shutdown promise.
|
|
203
|
+
* @throws {TypeError} When a shutdown owner has already been bound.
|
|
204
|
+
*/
|
|
205
|
+
bindShutdownOwner(owner: () => Promise<void>): void;
|
|
206
|
+
/** Stops timers, drains writes, and clears live state under one memoized lifecycle settlement. */
|
|
207
|
+
shutdown(): Promise<void>;
|
|
208
|
+
/** Stops timers and drains writes while the caller owns global shutdown. */
|
|
209
|
+
shutdownWithinLifecycle(): Promise<void>;
|
|
210
|
+
/** Clears non-durable state after every shutdown resource has closed successfully. */
|
|
211
|
+
clearLiveStateAfterShutdown(): void;
|
|
212
|
+
/** Number of coordinator-owned thought writes not yet acknowledged successful. */
|
|
213
|
+
getWriteBufferLength(): number;
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=HistoryManager.d.ts.map
|