@fgv/ts-agent-memory 5.1.0-47 → 5.1.0-49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/packlets/ingest/orchestrator.js +11 -1
- package/dist/packlets/ingest/orchestrator.js.map +1 -1
- package/dist/packlets/observe/memoryObservationStore.js +6 -0
- package/dist/packlets/observe/memoryObservationStore.js.map +1 -1
- package/dist/packlets/observe/observer.js.map +1 -1
- package/dist/packlets/retrieve/linkTraversalRetriever.js +1 -1
- package/dist/packlets/retrieve/linkTraversalRetriever.js.map +1 -1
- package/dist/packlets/retrieve/recencyRetriever.js +1 -1
- package/dist/packlets/retrieve/recencyRetriever.js.map +1 -1
- package/dist/packlets/retrieve/retriever.js +11 -5
- package/dist/packlets/retrieve/retriever.js.map +1 -1
- package/dist/packlets/retrieve/structuredFilterRetriever.js +27 -5
- package/dist/packlets/retrieve/structuredFilterRetriever.js.map +1 -1
- package/dist/packlets/retrieve/tagRetriever.js +1 -1
- package/dist/packlets/retrieve/tagRetriever.js.map +1 -1
- package/dist/packlets/retrieve/temporalRetrievers.js +1 -1
- package/dist/packlets/retrieve/temporalRetrievers.js.map +1 -1
- package/dist/packlets/store/fileTreeMemoryStore.js +152 -132
- package/dist/packlets/store/fileTreeMemoryStore.js.map +1 -1
- package/dist/packlets/store/vectorMaintenance.js +251 -0
- package/dist/packlets/store/vectorMaintenance.js.map +1 -0
- package/dist/packlets/types/envelope.js.map +1 -1
- package/dist/packlets/vector/inMemoryCosineIndex.js +81 -18
- package/dist/packlets/vector/inMemoryCosineIndex.js.map +1 -1
- package/dist/packlets/vector/inMemoryFragmentCosineIndex.js +7 -0
- package/dist/packlets/vector/inMemoryFragmentCosineIndex.js.map +1 -1
- package/dist/packlets/vector/vectorIndex.js.map +1 -1
- package/dist/ts-agent-memory.d.ts +431 -79
- package/lib/packlets/ingest/orchestrator.d.ts.map +1 -1
- package/lib/packlets/ingest/orchestrator.js +11 -1
- package/lib/packlets/ingest/orchestrator.js.map +1 -1
- package/lib/packlets/observe/memoryObservationStore.d.ts.map +1 -1
- package/lib/packlets/observe/memoryObservationStore.js +6 -0
- package/lib/packlets/observe/memoryObservationStore.js.map +1 -1
- package/lib/packlets/observe/observer.d.ts +61 -0
- package/lib/packlets/observe/observer.d.ts.map +1 -1
- package/lib/packlets/observe/observer.js.map +1 -1
- package/lib/packlets/retrieve/linkTraversalRetriever.d.ts +1 -1
- package/lib/packlets/retrieve/linkTraversalRetriever.js +1 -1
- package/lib/packlets/retrieve/linkTraversalRetriever.js.map +1 -1
- package/lib/packlets/retrieve/recencyRetriever.d.ts +1 -1
- package/lib/packlets/retrieve/recencyRetriever.js +1 -1
- package/lib/packlets/retrieve/recencyRetriever.js.map +1 -1
- package/lib/packlets/retrieve/retriever.d.ts +26 -7
- package/lib/packlets/retrieve/retriever.d.ts.map +1 -1
- package/lib/packlets/retrieve/retriever.js +11 -5
- package/lib/packlets/retrieve/retriever.js.map +1 -1
- package/lib/packlets/retrieve/structuredFilterRetriever.d.ts +26 -4
- package/lib/packlets/retrieve/structuredFilterRetriever.d.ts.map +1 -1
- package/lib/packlets/retrieve/structuredFilterRetriever.js +27 -5
- package/lib/packlets/retrieve/structuredFilterRetriever.js.map +1 -1
- package/lib/packlets/retrieve/tagRetriever.d.ts +1 -1
- package/lib/packlets/retrieve/tagRetriever.js +1 -1
- package/lib/packlets/retrieve/tagRetriever.js.map +1 -1
- package/lib/packlets/retrieve/temporalRetrievers.js +1 -1
- package/lib/packlets/retrieve/temporalRetrievers.js.map +1 -1
- package/lib/packlets/store/fileTreeMemoryStore.d.ts +135 -59
- package/lib/packlets/store/fileTreeMemoryStore.d.ts.map +1 -1
- package/lib/packlets/store/fileTreeMemoryStore.js +151 -131
- package/lib/packlets/store/fileTreeMemoryStore.js.map +1 -1
- package/lib/packlets/store/vectorMaintenance.d.ts +149 -0
- package/lib/packlets/store/vectorMaintenance.d.ts.map +1 -0
- package/lib/packlets/store/vectorMaintenance.js +255 -0
- package/lib/packlets/store/vectorMaintenance.js.map +1 -0
- package/lib/packlets/types/envelope.d.ts +11 -0
- package/lib/packlets/types/envelope.d.ts.map +1 -1
- package/lib/packlets/types/envelope.js.map +1 -1
- package/lib/packlets/vector/inMemoryCosineIndex.d.ts +30 -7
- package/lib/packlets/vector/inMemoryCosineIndex.d.ts.map +1 -1
- package/lib/packlets/vector/inMemoryCosineIndex.js +80 -17
- package/lib/packlets/vector/inMemoryCosineIndex.js.map +1 -1
- package/lib/packlets/vector/inMemoryFragmentCosineIndex.d.ts +7 -0
- package/lib/packlets/vector/inMemoryFragmentCosineIndex.d.ts.map +1 -1
- package/lib/packlets/vector/inMemoryFragmentCosineIndex.js +7 -0
- package/lib/packlets/vector/inMemoryFragmentCosineIndex.js.map +1 -1
- package/lib/packlets/vector/vectorIndex.d.ts +129 -1
- package/lib/packlets/vector/vectorIndex.d.ts.map +1 -1
- package/lib/packlets/vector/vectorIndex.js.map +1 -1
- package/package.json +17 -7
- package/.rush/temp/5667e36f1c0cc503a5c20a3ebff76e7b9a702d41.tar.log +0 -468
- package/.rush/temp/chunked-rush-logs/ts-agent-memory.build.chunks.jsonl +0 -9
- package/.rush/temp/operation/build/all.log +0 -9
- package/.rush/temp/operation/build/log-chunks.jsonl +0 -9
- package/.rush/temp/operation/build/state.json +0 -3
- package/.rush/temp/shrinkwrap-deps.json +0 -689
- package/config/api-extractor.json +0 -343
- package/config/jest.config.json +0 -14
- package/config/rig.json +0 -4
- package/dist/test/unit/converters/antagonistRoundTrip.test.js +0 -95
- package/dist/test/unit/converters/antagonistRoundTrip.test.js.map +0 -1
- package/dist/test/unit/converters/bodyConverterRegistry.test.js +0 -72
- package/dist/test/unit/converters/bodyConverterRegistry.test.js.map +0 -1
- package/dist/test/unit/converters/envelopeConverter.test.js +0 -313
- package/dist/test/unit/converters/envelopeConverter.test.js.map +0 -1
- package/dist/test/unit/index/memoryIndex.test.js +0 -214
- package/dist/test/unit/index/memoryIndex.test.js.map +0 -1
- package/dist/test/unit/ingest/antagonistCycleAndParity.test.js +0 -277
- package/dist/test/unit/ingest/antagonistCycleAndParity.test.js.map +0 -1
- package/dist/test/unit/ingest/cycleGuard.test.js +0 -81
- package/dist/test/unit/ingest/cycleGuard.test.js.map +0 -1
- package/dist/test/unit/ingest/dedupScope.test.js +0 -434
- package/dist/test/unit/ingest/dedupScope.test.js.map +0 -1
- package/dist/test/unit/ingest/orchestrator.test.js +0 -1058
- package/dist/test/unit/ingest/orchestrator.test.js.map +0 -1
- package/dist/test/unit/observe/memoryObservationStore.test.js +0 -118
- package/dist/test/unit/observe/memoryObservationStore.test.js.map +0 -1
- package/dist/test/unit/retrieve/fragmentSemanticRetriever.test.js +0 -116
- package/dist/test/unit/retrieve/fragmentSemanticRetriever.test.js.map +0 -1
- package/dist/test/unit/retrieve/linkTraversalRetriever.test.js +0 -257
- package/dist/test/unit/retrieve/linkTraversalRetriever.test.js.map +0 -1
- package/dist/test/unit/retrieve/retrievers.test.js +0 -768
- package/dist/test/unit/retrieve/retrievers.test.js.map +0 -1
- package/dist/test/unit/retrieve/temporalRetrievers.test.js +0 -182
- package/dist/test/unit/retrieve/temporalRetrievers.test.js.map +0 -1
- package/dist/test/unit/store/antagonistTemporalBoundary.test.js +0 -120
- package/dist/test/unit/store/antagonistTemporalBoundary.test.js.map +0 -1
- package/dist/test/unit/store/embedOnWrite.test.js +0 -317
- package/dist/test/unit/store/embedOnWrite.test.js.map +0 -1
- package/dist/test/unit/store/fileTreeMemoryStore.test.js +0 -778
- package/dist/test/unit/store/fileTreeMemoryStore.test.js.map +0 -1
- package/dist/test/unit/store/fragmentEmbedOnWrite.test.js +0 -255
- package/dist/test/unit/store/fragmentEmbedOnWrite.test.js.map +0 -1
- package/dist/test/unit/store/indexInjection.test.js +0 -432
- package/dist/test/unit/store/indexInjection.test.js.map +0 -1
- package/dist/test/unit/store/lenientOpen.test.js +0 -248
- package/dist/test/unit/store/lenientOpen.test.js.map +0 -1
- package/dist/test/unit/store/listScoped.test.js +0 -109
- package/dist/test/unit/store/listScoped.test.js.map +0 -1
- package/dist/test/unit/store/observations.test.js +0 -239
- package/dist/test/unit/store/observations.test.js.map +0 -1
- package/dist/test/unit/store/rankAxis.test.js +0 -254
- package/dist/test/unit/store/rankAxis.test.js.map +0 -1
- package/dist/test/unit/store/scopeEncoding.test.js +0 -24
- package/dist/test/unit/store/scopeEncoding.test.js.map +0 -1
- package/dist/test/unit/store/temporalStore.test.js +0 -398
- package/dist/test/unit/store/temporalStore.test.js.map +0 -1
- package/dist/test/unit/tools/memoryTools.test.js +0 -842
- package/dist/test/unit/tools/memoryTools.test.js.map +0 -1
- package/dist/test/unit/types/identityCodec.test.js +0 -187
- package/dist/test/unit/types/identityCodec.test.js.map +0 -1
- package/dist/test/unit/types/ids.test.js +0 -84
- package/dist/test/unit/types/ids.test.js.map +0 -1
- package/dist/test/unit/types/temporalCodec.test.js +0 -203
- package/dist/test/unit/types/temporalCodec.test.js.map +0 -1
- package/dist/test/unit/types/temporalPolicy.test.js +0 -83
- package/dist/test/unit/types/temporalPolicy.test.js.map +0 -1
- package/dist/test/unit/types/writePolicy.test.js +0 -331
- package/dist/test/unit/types/writePolicy.test.js.map +0 -1
- package/dist/test/unit/vector/fragmentConverters.test.js +0 -58
- package/dist/test/unit/vector/fragmentConverters.test.js.map +0 -1
- package/dist/test/unit/vector/inMemoryCosineIndex.test.js +0 -252
- package/dist/test/unit/vector/inMemoryCosineIndex.test.js.map +0 -1
- package/dist/test/unit/vector/inMemoryFragmentCosineIndex.test.js +0 -362
- package/dist/test/unit/vector/inMemoryFragmentCosineIndex.test.js.map +0 -1
- package/dist/test/unit/vector/vectorIndex.test.js +0 -51
- package/dist/test/unit/vector/vectorIndex.test.js.map +0 -1
- package/eslint.config.js +0 -15
- package/etc/ts-agent-memory.api.md +0 -940
- package/lib/test/unit/converters/antagonistRoundTrip.test.d.ts +0 -10
- package/lib/test/unit/converters/antagonistRoundTrip.test.d.ts.map +0 -1
- package/lib/test/unit/converters/antagonistRoundTrip.test.js +0 -97
- package/lib/test/unit/converters/antagonistRoundTrip.test.js.map +0 -1
- package/lib/test/unit/converters/bodyConverterRegistry.test.d.ts +0 -2
- package/lib/test/unit/converters/bodyConverterRegistry.test.d.ts.map +0 -1
- package/lib/test/unit/converters/bodyConverterRegistry.test.js +0 -74
- package/lib/test/unit/converters/bodyConverterRegistry.test.js.map +0 -1
- package/lib/test/unit/converters/envelopeConverter.test.d.ts +0 -2
- package/lib/test/unit/converters/envelopeConverter.test.d.ts.map +0 -1
- package/lib/test/unit/converters/envelopeConverter.test.js +0 -315
- package/lib/test/unit/converters/envelopeConverter.test.js.map +0 -1
- package/lib/test/unit/index/memoryIndex.test.d.ts +0 -2
- package/lib/test/unit/index/memoryIndex.test.d.ts.map +0 -1
- package/lib/test/unit/index/memoryIndex.test.js +0 -216
- package/lib/test/unit/index/memoryIndex.test.js.map +0 -1
- package/lib/test/unit/ingest/antagonistCycleAndParity.test.d.ts +0 -9
- package/lib/test/unit/ingest/antagonistCycleAndParity.test.d.ts.map +0 -1
- package/lib/test/unit/ingest/antagonistCycleAndParity.test.js +0 -279
- package/lib/test/unit/ingest/antagonistCycleAndParity.test.js.map +0 -1
- package/lib/test/unit/ingest/cycleGuard.test.d.ts +0 -2
- package/lib/test/unit/ingest/cycleGuard.test.d.ts.map +0 -1
- package/lib/test/unit/ingest/cycleGuard.test.js +0 -83
- package/lib/test/unit/ingest/cycleGuard.test.js.map +0 -1
- package/lib/test/unit/ingest/dedupScope.test.d.ts +0 -2
- package/lib/test/unit/ingest/dedupScope.test.d.ts.map +0 -1
- package/lib/test/unit/ingest/dedupScope.test.js +0 -436
- package/lib/test/unit/ingest/dedupScope.test.js.map +0 -1
- package/lib/test/unit/ingest/orchestrator.test.d.ts +0 -2
- package/lib/test/unit/ingest/orchestrator.test.d.ts.map +0 -1
- package/lib/test/unit/ingest/orchestrator.test.js +0 -1060
- package/lib/test/unit/ingest/orchestrator.test.js.map +0 -1
- package/lib/test/unit/observe/memoryObservationStore.test.d.ts +0 -2
- package/lib/test/unit/observe/memoryObservationStore.test.d.ts.map +0 -1
- package/lib/test/unit/observe/memoryObservationStore.test.js +0 -120
- package/lib/test/unit/observe/memoryObservationStore.test.js.map +0 -1
- package/lib/test/unit/retrieve/fragmentSemanticRetriever.test.d.ts +0 -2
- package/lib/test/unit/retrieve/fragmentSemanticRetriever.test.d.ts.map +0 -1
- package/lib/test/unit/retrieve/fragmentSemanticRetriever.test.js +0 -118
- package/lib/test/unit/retrieve/fragmentSemanticRetriever.test.js.map +0 -1
- package/lib/test/unit/retrieve/linkTraversalRetriever.test.d.ts +0 -2
- package/lib/test/unit/retrieve/linkTraversalRetriever.test.d.ts.map +0 -1
- package/lib/test/unit/retrieve/linkTraversalRetriever.test.js +0 -259
- package/lib/test/unit/retrieve/linkTraversalRetriever.test.js.map +0 -1
- package/lib/test/unit/retrieve/retrievers.test.d.ts +0 -2
- package/lib/test/unit/retrieve/retrievers.test.d.ts.map +0 -1
- package/lib/test/unit/retrieve/retrievers.test.js +0 -770
- package/lib/test/unit/retrieve/retrievers.test.js.map +0 -1
- package/lib/test/unit/retrieve/temporalRetrievers.test.d.ts +0 -2
- package/lib/test/unit/retrieve/temporalRetrievers.test.d.ts.map +0 -1
- package/lib/test/unit/retrieve/temporalRetrievers.test.js +0 -184
- package/lib/test/unit/retrieve/temporalRetrievers.test.js.map +0 -1
- package/lib/test/unit/store/antagonistTemporalBoundary.test.d.ts +0 -9
- package/lib/test/unit/store/antagonistTemporalBoundary.test.d.ts.map +0 -1
- package/lib/test/unit/store/antagonistTemporalBoundary.test.js +0 -122
- package/lib/test/unit/store/antagonistTemporalBoundary.test.js.map +0 -1
- package/lib/test/unit/store/embedOnWrite.test.d.ts +0 -2
- package/lib/test/unit/store/embedOnWrite.test.d.ts.map +0 -1
- package/lib/test/unit/store/embedOnWrite.test.js +0 -319
- package/lib/test/unit/store/embedOnWrite.test.js.map +0 -1
- package/lib/test/unit/store/fileTreeMemoryStore.test.d.ts +0 -2
- package/lib/test/unit/store/fileTreeMemoryStore.test.d.ts.map +0 -1
- package/lib/test/unit/store/fileTreeMemoryStore.test.js +0 -780
- package/lib/test/unit/store/fileTreeMemoryStore.test.js.map +0 -1
- package/lib/test/unit/store/fragmentEmbedOnWrite.test.d.ts +0 -2
- package/lib/test/unit/store/fragmentEmbedOnWrite.test.d.ts.map +0 -1
- package/lib/test/unit/store/fragmentEmbedOnWrite.test.js +0 -257
- package/lib/test/unit/store/fragmentEmbedOnWrite.test.js.map +0 -1
- package/lib/test/unit/store/indexInjection.test.d.ts +0 -2
- package/lib/test/unit/store/indexInjection.test.d.ts.map +0 -1
- package/lib/test/unit/store/indexInjection.test.js +0 -434
- package/lib/test/unit/store/indexInjection.test.js.map +0 -1
- package/lib/test/unit/store/lenientOpen.test.d.ts +0 -2
- package/lib/test/unit/store/lenientOpen.test.d.ts.map +0 -1
- package/lib/test/unit/store/lenientOpen.test.js +0 -250
- package/lib/test/unit/store/lenientOpen.test.js.map +0 -1
- package/lib/test/unit/store/listScoped.test.d.ts +0 -2
- package/lib/test/unit/store/listScoped.test.d.ts.map +0 -1
- package/lib/test/unit/store/listScoped.test.js +0 -111
- package/lib/test/unit/store/listScoped.test.js.map +0 -1
- package/lib/test/unit/store/observations.test.d.ts +0 -2
- package/lib/test/unit/store/observations.test.d.ts.map +0 -1
- package/lib/test/unit/store/observations.test.js +0 -241
- package/lib/test/unit/store/observations.test.js.map +0 -1
- package/lib/test/unit/store/rankAxis.test.d.ts +0 -2
- package/lib/test/unit/store/rankAxis.test.d.ts.map +0 -1
- package/lib/test/unit/store/rankAxis.test.js +0 -256
- package/lib/test/unit/store/rankAxis.test.js.map +0 -1
- package/lib/test/unit/store/scopeEncoding.test.d.ts +0 -2
- package/lib/test/unit/store/scopeEncoding.test.d.ts.map +0 -1
- package/lib/test/unit/store/scopeEncoding.test.js +0 -26
- package/lib/test/unit/store/scopeEncoding.test.js.map +0 -1
- package/lib/test/unit/store/temporalStore.test.d.ts +0 -2
- package/lib/test/unit/store/temporalStore.test.d.ts.map +0 -1
- package/lib/test/unit/store/temporalStore.test.js +0 -400
- package/lib/test/unit/store/temporalStore.test.js.map +0 -1
- package/lib/test/unit/tools/memoryTools.test.d.ts +0 -2
- package/lib/test/unit/tools/memoryTools.test.d.ts.map +0 -1
- package/lib/test/unit/tools/memoryTools.test.js +0 -844
- package/lib/test/unit/tools/memoryTools.test.js.map +0 -1
- package/lib/test/unit/types/identityCodec.test.d.ts +0 -2
- package/lib/test/unit/types/identityCodec.test.d.ts.map +0 -1
- package/lib/test/unit/types/identityCodec.test.js +0 -189
- package/lib/test/unit/types/identityCodec.test.js.map +0 -1
- package/lib/test/unit/types/ids.test.d.ts +0 -2
- package/lib/test/unit/types/ids.test.d.ts.map +0 -1
- package/lib/test/unit/types/ids.test.js +0 -86
- package/lib/test/unit/types/ids.test.js.map +0 -1
- package/lib/test/unit/types/temporalCodec.test.d.ts +0 -2
- package/lib/test/unit/types/temporalCodec.test.d.ts.map +0 -1
- package/lib/test/unit/types/temporalCodec.test.js +0 -205
- package/lib/test/unit/types/temporalCodec.test.js.map +0 -1
- package/lib/test/unit/types/temporalPolicy.test.d.ts +0 -2
- package/lib/test/unit/types/temporalPolicy.test.d.ts.map +0 -1
- package/lib/test/unit/types/temporalPolicy.test.js +0 -85
- package/lib/test/unit/types/temporalPolicy.test.js.map +0 -1
- package/lib/test/unit/types/writePolicy.test.d.ts +0 -2
- package/lib/test/unit/types/writePolicy.test.d.ts.map +0 -1
- package/lib/test/unit/types/writePolicy.test.js +0 -333
- package/lib/test/unit/types/writePolicy.test.js.map +0 -1
- package/lib/test/unit/vector/fragmentConverters.test.d.ts +0 -2
- package/lib/test/unit/vector/fragmentConverters.test.d.ts.map +0 -1
- package/lib/test/unit/vector/fragmentConverters.test.js +0 -60
- package/lib/test/unit/vector/fragmentConverters.test.js.map +0 -1
- package/lib/test/unit/vector/inMemoryCosineIndex.test.d.ts +0 -2
- package/lib/test/unit/vector/inMemoryCosineIndex.test.d.ts.map +0 -1
- package/lib/test/unit/vector/inMemoryCosineIndex.test.js +0 -254
- package/lib/test/unit/vector/inMemoryCosineIndex.test.js.map +0 -1
- package/lib/test/unit/vector/inMemoryFragmentCosineIndex.test.d.ts +0 -2
- package/lib/test/unit/vector/inMemoryFragmentCosineIndex.test.d.ts.map +0 -1
- package/lib/test/unit/vector/inMemoryFragmentCosineIndex.test.js +0 -364
- package/lib/test/unit/vector/inMemoryFragmentCosineIndex.test.js.map +0 -1
- package/lib/test/unit/vector/vectorIndex.test.d.ts +0 -2
- package/lib/test/unit/vector/vectorIndex.test.d.ts.map +0 -1
- package/lib/test/unit/vector/vectorIndex.test.js +0 -53
- package/lib/test/unit/vector/vectorIndex.test.js.map +0 -1
- package/rush-logs/ts-agent-memory.build.cache.log +0 -3
- package/rush-logs/ts-agent-memory.build.log +0 -9
- package/src/index.ts +0 -14
- package/src/packlets/converters/bodyConverterRegistry.ts +0 -105
- package/src/packlets/converters/envelopeConverter.ts +0 -233
- package/src/packlets/converters/index.ts +0 -7
- package/src/packlets/index/index.ts +0 -6
- package/src/packlets/index/memoryIndex.ts +0 -332
- package/src/packlets/ingest/cycleGuard.ts +0 -153
- package/src/packlets/ingest/hostStages.ts +0 -111
- package/src/packlets/ingest/index.ts +0 -9
- package/src/packlets/ingest/model.ts +0 -195
- package/src/packlets/ingest/orchestrator.ts +0 -968
- package/src/packlets/observe/index.ts +0 -7
- package/src/packlets/observe/memoryObservationStore.ts +0 -153
- package/src/packlets/observe/observer.ts +0 -119
- package/src/packlets/retrieve/fragmentSemanticRetriever.ts +0 -138
- package/src/packlets/retrieve/hybridRetriever.ts +0 -194
- package/src/packlets/retrieve/index.ts +0 -14
- package/src/packlets/retrieve/linkTraversalRetriever.ts +0 -158
- package/src/packlets/retrieve/recencyRetriever.ts +0 -54
- package/src/packlets/retrieve/retriever.ts +0 -291
- package/src/packlets/retrieve/semanticRetriever.ts +0 -152
- package/src/packlets/retrieve/structuredFilterRetriever.ts +0 -58
- package/src/packlets/retrieve/tagRetriever.ts +0 -58
- package/src/packlets/retrieve/temporalRetrievers.ts +0 -210
- package/src/packlets/store/fileTreeMemoryStore.ts +0 -1872
- package/src/packlets/store/index.ts +0 -7
- package/src/packlets/store/scopeEncoding.ts +0 -36
- package/src/packlets/tools/index.ts +0 -6
- package/src/packlets/tools/memoryTools.ts +0 -706
- package/src/packlets/types/envelope.ts +0 -196
- package/src/packlets/types/filenameSafety.ts +0 -57
- package/src/packlets/types/identityCodec.ts +0 -447
- package/src/packlets/types/ids.ts +0 -124
- package/src/packlets/types/index.ts +0 -11
- package/src/packlets/types/temporal.ts +0 -96
- package/src/packlets/types/writePolicy.ts +0 -612
- package/src/packlets/vector/fragmentConverters.ts +0 -55
- package/src/packlets/vector/inMemoryCosineIndex.ts +0 -196
- package/src/packlets/vector/inMemoryFragmentCosineIndex.ts +0 -289
- package/src/packlets/vector/index.ts +0 -9
- package/src/packlets/vector/vectorIndex.ts +0 -273
- package/src/test/unit/converters/antagonistRoundTrip.test.ts +0 -110
- package/src/test/unit/converters/bodyConverterRegistry.test.ts +0 -89
- package/src/test/unit/converters/envelopeConverter.test.ts +0 -418
- package/src/test/unit/index/memoryIndex.test.ts +0 -272
- package/src/test/unit/ingest/antagonistCycleAndParity.test.ts +0 -367
- package/src/test/unit/ingest/cycleGuard.test.ts +0 -110
- package/src/test/unit/ingest/dedupScope.test.ts +0 -542
- package/src/test/unit/ingest/orchestrator.test.ts +0 -1355
- package/src/test/unit/observe/memoryObservationStore.test.ts +0 -158
- package/src/test/unit/retrieve/fragmentSemanticRetriever.test.ts +0 -163
- package/src/test/unit/retrieve/linkTraversalRetriever.test.ts +0 -329
- package/src/test/unit/retrieve/retrievers.test.ts +0 -1018
- package/src/test/unit/retrieve/temporalRetrievers.test.ts +0 -226
- package/src/test/unit/store/antagonistTemporalBoundary.test.ts +0 -158
- package/src/test/unit/store/embedOnWrite.test.ts +0 -418
- package/src/test/unit/store/fileTreeMemoryStore.test.ts +0 -1041
- package/src/test/unit/store/fragmentEmbedOnWrite.test.ts +0 -349
- package/src/test/unit/store/indexInjection.test.ts +0 -550
- package/src/test/unit/store/lenientOpen.test.ts +0 -292
- package/src/test/unit/store/listScoped.test.ts +0 -138
- package/src/test/unit/store/observations.test.ts +0 -290
- package/src/test/unit/store/rankAxis.test.ts +0 -349
- package/src/test/unit/store/scopeEncoding.test.ts +0 -37
- package/src/test/unit/store/temporalStore.test.ts +0 -469
- package/src/test/unit/tools/memoryTools.test.ts +0 -1121
- package/src/test/unit/types/identityCodec.test.ts +0 -266
- package/src/test/unit/types/ids.test.ts +0 -94
- package/src/test/unit/types/temporalCodec.test.ts +0 -259
- package/src/test/unit/types/temporalPolicy.test.ts +0 -124
- package/src/test/unit/types/writePolicy.test.ts +0 -446
- package/src/test/unit/vector/fragmentConverters.test.ts +0 -80
- package/src/test/unit/vector/inMemoryCosineIndex.test.ts +0 -318
- package/src/test/unit/vector/inMemoryFragmentCosineIndex.test.ts +0 -477
- package/src/test/unit/vector/vectorIndex.test.ts +0 -64
- package/temp/build/lint/_eslint-5eVG3S6w.json +0 -306
- package/temp/build/typescript/ts_8nwakTlr.json +0 -1
- package/temp/ts-agent-memory.api.json +0 -21030
- package/temp/ts-agent-memory.api.md +0 -940
- package/tsconfig.json +0 -8
|
@@ -1,706 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2026 Erik Fortune
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { Result, captureResult, fail, succeed } from '@fgv/ts-utils';
|
|
7
|
-
import { JsonSchema } from '@fgv/ts-json-base';
|
|
8
|
-
import { AiAssist } from '@fgv/ts-extras';
|
|
9
|
-
import { Convert, EntityId, IEdgeTarget, IIdentityCodec, IMemoryRecord, Kind, MemoryId, Tag } from '../types';
|
|
10
|
-
import { IBodyConverterRegistry, envelopeConverter } from '../converters';
|
|
11
|
-
import { IMemoryStore } from '../store';
|
|
12
|
-
import { IMemoryQuery, IMemoryRetriever } from '../retrieve';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* The names of the five proof-set memory tools. A caller selects a subset via
|
|
16
|
-
* {@link ICreateMemoryToolsParams.tools | tools}.
|
|
17
|
-
* @public
|
|
18
|
-
*/
|
|
19
|
-
export type MemoryToolName =
|
|
20
|
-
| 'memory_write'
|
|
21
|
-
| 'memory_read'
|
|
22
|
-
| 'memory_search'
|
|
23
|
-
| 'memory_context'
|
|
24
|
-
| 'memory_delete';
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* The default tool subset when {@link ICreateMemoryToolsParams.tools | tools} is
|
|
28
|
-
* omitted: the read-only set. Mutating tools (`memory_write` / `memory_delete`)
|
|
29
|
-
* are **off by default** and must be named explicitly — writes stay
|
|
30
|
-
* curation-mediated unless the host opts in.
|
|
31
|
-
* @public
|
|
32
|
-
*/
|
|
33
|
-
export const DEFAULT_MEMORY_TOOLS: ReadonlyArray<MemoryToolName> = ['memory_search', 'memory_context'];
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Discriminates the outcome of a {@link createMemoryTools | memory_write} call so
|
|
37
|
-
* the agent can reason about what its write actually did.
|
|
38
|
-
*
|
|
39
|
-
* @remarks
|
|
40
|
-
* - `written` — a new record was persisted, or an existing entity was updated.
|
|
41
|
-
* - `deduped` — the content already existed (content-hash dedup no-op); the
|
|
42
|
-
* store returned the existing record unchanged.
|
|
43
|
-
*
|
|
44
|
-
* The store's public `put` return does not surface cap-cull evictions, so a
|
|
45
|
-
* `culled` outcome is not distinguishable at this layer without an L1 change or
|
|
46
|
-
* observer wiring (both out of scope for L2). The writer's own record is always
|
|
47
|
-
* `written` even when the write triggers a cull of older siblings.
|
|
48
|
-
* @public
|
|
49
|
-
*/
|
|
50
|
-
export type MemoryWriteOutcome = 'written' | 'deduped';
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* The success value returned by `memory_write.execute`.
|
|
54
|
-
* @public
|
|
55
|
-
*/
|
|
56
|
-
export interface IMemoryWriteResult {
|
|
57
|
-
/** What the write did — see {@link MemoryWriteOutcome}. */
|
|
58
|
-
readonly outcome: MemoryWriteOutcome;
|
|
59
|
-
/** The stored record's {@link MemoryId}. */
|
|
60
|
-
readonly id: MemoryId;
|
|
61
|
-
/** The domain {@link EntityId} the write targeted. */
|
|
62
|
-
readonly entityId: EntityId;
|
|
63
|
-
/** The record's {@link Kind}. */
|
|
64
|
-
readonly kind: Kind;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* A single agent-visible search / context result item. The agent-facing key is
|
|
69
|
-
* {@link IMemoryToolResultItem.handle | handle}: the host mnemonic when a
|
|
70
|
-
* {@link ICreateMemoryToolsParams.handleFor | handleFor} hook is supplied, else
|
|
71
|
-
* the raw {@link MemoryId}.
|
|
72
|
-
* @public
|
|
73
|
-
*/
|
|
74
|
-
export interface IMemoryToolResultItem {
|
|
75
|
-
/** The agent-visible key (host handle when supplied, raw {@link MemoryId} otherwise). */
|
|
76
|
-
readonly handle: string;
|
|
77
|
-
/** The record's {@link Kind}. */
|
|
78
|
-
readonly kind: Kind;
|
|
79
|
-
/** The record's domain {@link EntityId}. */
|
|
80
|
-
readonly entityId: EntityId;
|
|
81
|
-
/** The record's tags. */
|
|
82
|
-
readonly tags: ReadonlyArray<string>;
|
|
83
|
-
/** The record body (a markdown string in B1). */
|
|
84
|
-
readonly body: unknown;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Parameters for {@link createMemoryTools}.
|
|
89
|
-
*
|
|
90
|
-
* @remarks
|
|
91
|
-
* **Scope isolation is constructor-fixed.** The {@link
|
|
92
|
-
* ICreateMemoryToolsParams.store | store} is the sole scope authority — it is the
|
|
93
|
-
* actor's own, pre-scoped memory root. No tool's `parametersSchema` declares a
|
|
94
|
-
* `scope` (or any scope-widening) property, so an LLM cannot steer a tool at
|
|
95
|
-
* another actor's memory.
|
|
96
|
-
* @public
|
|
97
|
-
*/
|
|
98
|
-
export interface ICreateMemoryToolsParams {
|
|
99
|
-
/**
|
|
100
|
-
* The pre-scoped memory store (the actor's own memory root). Sole scope
|
|
101
|
-
* authority — backs `memory_write` / `memory_read` / `memory_delete`.
|
|
102
|
-
*/
|
|
103
|
-
readonly store: IMemoryStore;
|
|
104
|
-
/** Retriever backing `memory_search` (and `memory_context` via link traversal). */
|
|
105
|
-
readonly retriever: IMemoryRetriever;
|
|
106
|
-
/** Body converter registry — gates the toolable kinds via `has(kind)`. */
|
|
107
|
-
readonly registry: IBodyConverterRegistry;
|
|
108
|
-
/**
|
|
109
|
-
* The per-tool enable subset. Defaults to {@link DEFAULT_MEMORY_TOOLS} (the
|
|
110
|
-
* read-only set). Name `memory_write` / `memory_delete` here to opt into the
|
|
111
|
-
* mutating tools.
|
|
112
|
-
*/
|
|
113
|
-
readonly tools?: ReadonlyArray<MemoryToolName>;
|
|
114
|
-
/**
|
|
115
|
-
* Optional whitelist of toolable kinds. When present, a tool `kind` argument
|
|
116
|
-
* outside this set is rejected. When absent, {@link
|
|
117
|
-
* IBodyConverterRegistry.has | registry.has} is the sole kind gate.
|
|
118
|
-
*/
|
|
119
|
-
readonly kinds?: ReadonlyArray<Kind>;
|
|
120
|
-
/**
|
|
121
|
-
* Per-kind identity codecs, used by `memory_write` to map the domain
|
|
122
|
-
* {@link EntityId} to the record's storage id (the store resolves codecs
|
|
123
|
-
* internally for `get` / `delete`, so read / delete do not need them). Absent
|
|
124
|
-
* → `memory_write` uses {@link ICreateMemoryToolsParams.defaultCodec |
|
|
125
|
-
* defaultCodec}, and fails loudly for a kind with no resolvable codec. The
|
|
126
|
-
* read-only default tool set needs no codecs.
|
|
127
|
-
*/
|
|
128
|
-
readonly codecs?: ReadonlyMap<Kind, IIdentityCodec>;
|
|
129
|
-
/** Default identity codec for kinds without an explicit {@link ICreateMemoryToolsParams.codecs | codecs} entry. */
|
|
130
|
-
readonly defaultCodec?: IIdentityCodec;
|
|
131
|
-
/**
|
|
132
|
-
* Optional host hook mapping a record to its agent-visible handle (an evocative
|
|
133
|
-
* mnemonic tag). When supplied, `memory_search` / `memory_context` results use
|
|
134
|
-
* the returned handle as the agent-visible key; when absent the raw
|
|
135
|
-
* {@link MemoryId} is used.
|
|
136
|
-
*/
|
|
137
|
-
readonly handleFor?: (record: IMemoryRecord<unknown>) => string;
|
|
138
|
-
/**
|
|
139
|
-
* Optional host projector mapping a record (and the requested detail tier) to
|
|
140
|
-
* its agent-visible {@link IMemoryToolResultItem}. When supplied, every
|
|
141
|
-
* `memory_search` / `memory_context` / `memory_read` result item is produced by
|
|
142
|
-
* this callback — the host owns how much of the body a `'gist'` vs `'full'`
|
|
143
|
-
* result carries, so it can bound the default (`'gist'`) path.
|
|
144
|
-
*
|
|
145
|
-
* When absent, the built-in default projection is used (full body plus the
|
|
146
|
-
* {@link ICreateMemoryToolsParams.handleFor | handleFor} handle), which ignores
|
|
147
|
-
* the detail tier — behavior is byte-identical to a build with no projector.
|
|
148
|
-
*
|
|
149
|
-
* The callback is guarded exactly like `handleFor`: a throw degrades to the
|
|
150
|
-
* default full-body projection for that item rather than failing the whole
|
|
151
|
-
* search.
|
|
152
|
-
*/
|
|
153
|
-
readonly projectItem?: (record: IMemoryRecord<unknown>, detail: MemoryDetailTier) => IMemoryToolResultItem;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* The detail tier a `memory_search` / `memory_context` result is projected at.
|
|
158
|
-
* `'gist'` is the default (bounded) path; `'full'` is opt-in. Only meaningful
|
|
159
|
-
* when a host {@link ICreateMemoryToolsParams.projectItem | projectItem} is
|
|
160
|
-
* supplied — the built-in default projection returns the full body regardless.
|
|
161
|
-
* @public
|
|
162
|
-
*/
|
|
163
|
-
export type MemoryDetailTier = 'gist' | 'full';
|
|
164
|
-
|
|
165
|
-
/** The resolved factory context threaded into each tool's `execute`. */
|
|
166
|
-
interface IToolContext {
|
|
167
|
-
readonly store: IMemoryStore;
|
|
168
|
-
readonly retriever: IMemoryRetriever;
|
|
169
|
-
readonly registry: IBodyConverterRegistry;
|
|
170
|
-
readonly kinds?: ReadonlyArray<Kind>;
|
|
171
|
-
readonly codecs?: ReadonlyMap<Kind, IIdentityCodec>;
|
|
172
|
-
readonly defaultCodec?: IIdentityCodec;
|
|
173
|
-
readonly handleFor?: (record: IMemoryRecord<unknown>) => string;
|
|
174
|
-
readonly projectItem?: (record: IMemoryRecord<unknown>, detail: MemoryDetailTier) => IMemoryToolResultItem;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// ---------------------------------------------------------------------------
|
|
178
|
-
// Parameter schemas — authored once via JsonSchema.object(...); the schema IS
|
|
179
|
-
// both the wire schema (.toJson()) and the runtime validator (.convert()).
|
|
180
|
-
// NONE of these declare a `scope` (or scope-widening) property — the adoption
|
|
181
|
-
// gate is enforced structurally and asserted in the tests.
|
|
182
|
-
// ---------------------------------------------------------------------------
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* The scope-qualified target of a link edge authored by the agent on a write.
|
|
186
|
-
* `scope` is optional: when omitted it defaults to the writing record's OWN
|
|
187
|
-
* resolved scope (the common same-conversation case); supply it explicitly to
|
|
188
|
-
* point an edge at a record in a different scope.
|
|
189
|
-
*/
|
|
190
|
-
// eslint-disable-next-line @rushstack/typedef-var
|
|
191
|
-
const linkTargetSchema = JsonSchema.object({
|
|
192
|
-
id: JsonSchema.string({ description: 'The MemoryId of the record this edge points at.' }),
|
|
193
|
-
scope: JsonSchema.optional(
|
|
194
|
-
JsonSchema.string({
|
|
195
|
-
description: "The target record's scope. Defaults to the writing record's own scope when omitted."
|
|
196
|
-
})
|
|
197
|
-
)
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
/** A single attributed link edge as authored by the agent on a write. */
|
|
201
|
-
// eslint-disable-next-line @rushstack/typedef-var
|
|
202
|
-
const linkEdgeSchema = JsonSchema.object({
|
|
203
|
-
type: JsonSchema.string({ description: 'The relation type of the link.' }),
|
|
204
|
-
target: linkTargetSchema,
|
|
205
|
-
confidence: JsonSchema.optional(JsonSchema.number({ description: 'Optional confidence in [0, 1].' }))
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
// eslint-disable-next-line @rushstack/typedef-var
|
|
209
|
-
const writeSchema = JsonSchema.object({
|
|
210
|
-
kind: JsonSchema.string({ description: 'The record kind (must be an enabled, registered kind).' }),
|
|
211
|
-
entityId: JsonSchema.string({
|
|
212
|
-
description:
|
|
213
|
-
'The domain entity id. For composite (e.g. medium-term) kinds this is the full composite key.'
|
|
214
|
-
}),
|
|
215
|
-
body: JsonSchema.string({ description: "The serialized record body; validated by the kind's converter." }),
|
|
216
|
-
tags: JsonSchema.optional(JsonSchema.array(JsonSchema.string({ description: 'A tag label.' }))),
|
|
217
|
-
links: JsonSchema.optional(JsonSchema.array(linkEdgeSchema))
|
|
218
|
-
});
|
|
219
|
-
type WriteArgs = JsonSchema.Static<typeof writeSchema>;
|
|
220
|
-
|
|
221
|
-
// eslint-disable-next-line @rushstack/typedef-var
|
|
222
|
-
const readSchema = JsonSchema.object({
|
|
223
|
-
kind: JsonSchema.string({ description: 'The record kind.' }),
|
|
224
|
-
entityId: JsonSchema.string({ description: 'The domain entity id to read.' }),
|
|
225
|
-
detail: JsonSchema.optional(
|
|
226
|
-
JsonSchema.enumOf(['gist', 'full'] as const, { description: "'gist' | 'full' (default)." })
|
|
227
|
-
)
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
// eslint-disable-next-line @rushstack/typedef-var
|
|
231
|
-
const deleteSchema = JsonSchema.object({
|
|
232
|
-
kind: JsonSchema.string({ description: 'The record kind.' }),
|
|
233
|
-
entityId: JsonSchema.string({ description: 'The domain entity id to delete.' })
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
// eslint-disable-next-line @rushstack/typedef-var
|
|
237
|
-
const searchSchema = JsonSchema.object({
|
|
238
|
-
kind: JsonSchema.optional(JsonSchema.string({ description: 'Restrict to this kind.' })),
|
|
239
|
-
tag: JsonSchema.optional(JsonSchema.string({ description: 'Restrict to records carrying this tag.' })),
|
|
240
|
-
semantic: JsonSchema.optional(
|
|
241
|
-
JsonSchema.string({ description: 'Semantic query text (requires a semantic-capable retriever).' })
|
|
242
|
-
),
|
|
243
|
-
limit: JsonSchema.optional(JsonSchema.integer({ description: 'Maximum number of results to return.' })),
|
|
244
|
-
offset: JsonSchema.optional(
|
|
245
|
-
JsonSchema.integer({ description: 'Number of results to skip after ordering, before limit. Default 0.' })
|
|
246
|
-
),
|
|
247
|
-
detail: JsonSchema.optional(
|
|
248
|
-
JsonSchema.enumOf(['gist', 'full'] as const, { description: "'gist' (default) | 'full'." })
|
|
249
|
-
)
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* The scope-qualified seed a `memory_context` traversal starts from. Nested
|
|
254
|
-
* `{ id, scope }` shape like a link target, but — unlike a write edge — there is
|
|
255
|
-
* no writing record to default the scope from, so `scope` is REQUIRED to
|
|
256
|
-
* disambiguate the seed across scopes (a bare stem like `turn-3` is otherwise
|
|
257
|
-
* ambiguous). It is schema-required (not just runtime-required) so the wire
|
|
258
|
-
* schema an LLM reads never advertises an optionality the tool does not honor.
|
|
259
|
-
*/
|
|
260
|
-
// eslint-disable-next-line @rushstack/typedef-var
|
|
261
|
-
const contextSeedSchema = JsonSchema.object({
|
|
262
|
-
id: JsonSchema.string({ description: 'The MemoryId of the seed record to traverse links from.' }),
|
|
263
|
-
scope: JsonSchema.string({
|
|
264
|
-
description: 'The scope of the seed record (required — a bare seed id is ambiguous across scopes).'
|
|
265
|
-
})
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
// eslint-disable-next-line @rushstack/typedef-var
|
|
269
|
-
const contextSchema = JsonSchema.object({
|
|
270
|
-
from: contextSeedSchema,
|
|
271
|
-
kind: JsonSchema.optional(JsonSchema.string({ description: 'Restrict reached records to this kind.' })),
|
|
272
|
-
tag: JsonSchema.optional(JsonSchema.string({ description: 'Restrict reached records carrying this tag.' })),
|
|
273
|
-
hops: JsonSchema.optional(JsonSchema.integer({ description: 'BFS hop count (default 1).' })),
|
|
274
|
-
limit: JsonSchema.optional(JsonSchema.integer({ description: 'Maximum number of results to return.' })),
|
|
275
|
-
detail: JsonSchema.optional(
|
|
276
|
-
JsonSchema.enumOf(['gist', 'full'] as const, { description: "'gist' (default) | 'full'." })
|
|
277
|
-
)
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
// ---------------------------------------------------------------------------
|
|
281
|
-
// Behavior annotations (Component 4) — host-advisory hints; never serialized to
|
|
282
|
-
// the model. openWorldHint is false throughout (a closed, local store).
|
|
283
|
-
// ---------------------------------------------------------------------------
|
|
284
|
-
|
|
285
|
-
const READ_ONLY_ANNOTATIONS: AiAssist.IAiToolAnnotations = {
|
|
286
|
-
readOnlyHint: true,
|
|
287
|
-
openWorldHint: false
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
const WRITE_ANNOTATIONS: AiAssist.IAiToolAnnotations = {
|
|
291
|
-
destructiveHint: false,
|
|
292
|
-
idempotentHint: false,
|
|
293
|
-
openWorldHint: false
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
const DELETE_ANNOTATIONS: AiAssist.IAiToolAnnotations = {
|
|
297
|
-
destructiveHint: true,
|
|
298
|
-
idempotentHint: true,
|
|
299
|
-
openWorldHint: false
|
|
300
|
-
};
|
|
301
|
-
|
|
302
|
-
// ---------------------------------------------------------------------------
|
|
303
|
-
// Shared validation / projection helpers
|
|
304
|
-
// ---------------------------------------------------------------------------
|
|
305
|
-
|
|
306
|
-
/** Validate a `kind` string and assert it is an enabled, registered toolable kind. */
|
|
307
|
-
function assertKindEnabled(ctx: IToolContext, kindStr: string): Result<Kind> {
|
|
308
|
-
return Convert.kind.convert(kindStr).onSuccess((kind) => {
|
|
309
|
-
if (!ctx.registry.has(kind)) {
|
|
310
|
-
return fail(`memory tools: kind '${kind}' has no registered body converter`);
|
|
311
|
-
}
|
|
312
|
-
if (ctx.kinds !== undefined && !ctx.kinds.includes(kind)) {
|
|
313
|
-
return fail(`memory tools: kind '${kind}' is not enabled for memory tools`);
|
|
314
|
-
}
|
|
315
|
-
return succeed(kind);
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
/** Validate an optional `kind` string (enabled when present; `undefined` passes through). */
|
|
320
|
-
function resolveOptionalKind(ctx: IToolContext, kindStr?: string): Result<Kind | undefined> {
|
|
321
|
-
if (kindStr === undefined) {
|
|
322
|
-
return succeed(undefined);
|
|
323
|
-
}
|
|
324
|
-
return assertKindEnabled(ctx, kindStr);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* Resolve the requested detail tier from the optional tool `detail` string.
|
|
329
|
-
* `'full'` is the only opt-in value; every other input (absent, or an
|
|
330
|
-
* unrecognized string) resolves safely to the bounded default `'gist'`.
|
|
331
|
-
*/
|
|
332
|
-
function resolveDetail(detail?: string): MemoryDetailTier {
|
|
333
|
-
return detail === 'full' ? 'full' : 'gist';
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
/** The built-in default projection: full body plus the guarded host handle. Ignores the detail tier. */
|
|
337
|
-
function defaultProjectItem(ctx: IToolContext, record: IMemoryRecord<unknown>): IMemoryToolResultItem {
|
|
338
|
-
// `handleFor` is a host callback; guard it so a throw degrades to the raw id rather than
|
|
339
|
-
// escaping the Result chain (and crashing the whole search/context call).
|
|
340
|
-
const handle =
|
|
341
|
-
ctx.handleFor !== undefined
|
|
342
|
-
? captureResult(() => ctx.handleFor!(record)).orDefault(record.envelope.id)
|
|
343
|
-
: record.envelope.id;
|
|
344
|
-
return {
|
|
345
|
-
handle,
|
|
346
|
-
kind: record.envelope.kind,
|
|
347
|
-
entityId: record.envelope.entityId,
|
|
348
|
-
tags: record.envelope.tags,
|
|
349
|
-
body: record.body
|
|
350
|
-
};
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
/**
|
|
354
|
-
* Project a record into an agent-visible result item at the requested detail
|
|
355
|
-
* tier. When a host {@link ICreateMemoryToolsParams.projectItem | projectItem}
|
|
356
|
-
* is supplied it owns the projection; otherwise the built-in
|
|
357
|
-
* {@link defaultProjectItem} (full body) is used. The host callback is guarded
|
|
358
|
-
* like `handleFor` — a throw degrades to the default full-body projection for
|
|
359
|
-
* that item rather than failing the whole search/context call.
|
|
360
|
-
*/
|
|
361
|
-
function projectItem(
|
|
362
|
-
ctx: IToolContext,
|
|
363
|
-
record: IMemoryRecord<unknown>,
|
|
364
|
-
detail: MemoryDetailTier
|
|
365
|
-
): IMemoryToolResultItem {
|
|
366
|
-
if (ctx.projectItem === undefined) {
|
|
367
|
-
return defaultProjectItem(ctx, record);
|
|
368
|
-
}
|
|
369
|
-
// Guard the host projector like `handleFor`: a throw degrades to the built-in
|
|
370
|
-
// full-body projection (itself throw-safe) rather than escaping the chain.
|
|
371
|
-
return captureResult(() => ctx.projectItem!(record, detail)).orDefault(defaultProjectItem(ctx, record));
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
/** Resolve the identity codec used by `memory_write` to derive the storage id. */
|
|
375
|
-
function codecForWrite(ctx: IToolContext, kind: Kind): Result<IIdentityCodec> {
|
|
376
|
-
const codec: IIdentityCodec | undefined = ctx.codecs?.get(kind) ?? ctx.defaultCodec;
|
|
377
|
-
if (codec === undefined) {
|
|
378
|
-
return fail(`memory_write: no identity codec available for kind '${kind}'`);
|
|
379
|
-
}
|
|
380
|
-
return succeed(codec);
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
/** Build the record to persist from validated write args (store stamps txn-time metadata). */
|
|
384
|
-
function buildWriteRecord(
|
|
385
|
-
typed: WriteArgs,
|
|
386
|
-
kind: Kind,
|
|
387
|
-
entityId: EntityId,
|
|
388
|
-
idStem: string,
|
|
389
|
-
sourceScope: string
|
|
390
|
-
): Result<IMemoryRecord<unknown>> {
|
|
391
|
-
// Plain shapes handed to `envelopeConverter`, which validates each field
|
|
392
|
-
// (type → LinkType, target → { scope, id }) and produces the branded IEdge[].
|
|
393
|
-
// An edge target with no explicit `scope` defaults to the writing record's own
|
|
394
|
-
// resolved scope — the same-conversation case authors just an id.
|
|
395
|
-
const links: ReadonlyArray<Record<string, unknown>> = (typed.links ?? []).map((link) => ({
|
|
396
|
-
type: link.type,
|
|
397
|
-
target: { scope: link.target.scope ?? sourceScope, id: link.target.id },
|
|
398
|
-
...(link.confidence !== undefined ? { confidence: link.confidence } : {})
|
|
399
|
-
}));
|
|
400
|
-
return envelopeConverter
|
|
401
|
-
.convert({
|
|
402
|
-
id: idStem,
|
|
403
|
-
entityId,
|
|
404
|
-
kind,
|
|
405
|
-
tags: typed.tags ?? [],
|
|
406
|
-
links,
|
|
407
|
-
created: 0,
|
|
408
|
-
updated: 0,
|
|
409
|
-
seq: 0,
|
|
410
|
-
contentHash: '',
|
|
411
|
-
provenance: { source: 'agent' }
|
|
412
|
-
})
|
|
413
|
-
.withErrorFormat((msg) => `memory_write: invalid record: ${msg}`)
|
|
414
|
-
.onSuccess((envelope) => succeed({ envelope, body: typed.body }));
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
/** Resolve the validated write args into the storage id + record (all synchronous). */
|
|
418
|
-
function prepareWrite(
|
|
419
|
-
ctx: IToolContext,
|
|
420
|
-
typed: WriteArgs
|
|
421
|
-
): Result<{ readonly kind: Kind; readonly entityId: EntityId; readonly record: IMemoryRecord<unknown> }> {
|
|
422
|
-
return assertKindEnabled(ctx, typed.kind).onSuccess((kind) =>
|
|
423
|
-
Convert.entityId.convert(typed.entityId).onSuccess((entityId) =>
|
|
424
|
-
codecForWrite(ctx, kind).onSuccess((codec) =>
|
|
425
|
-
codec.encode(entityId).onSuccess((addr) => {
|
|
426
|
-
if (addr.isVersioned) {
|
|
427
|
-
return fail(`memory_write: versioned/temporal kind '${kind}' is not supported`);
|
|
428
|
-
}
|
|
429
|
-
return buildWriteRecord(typed, kind, entityId, addr.idStem, addr.scope).onSuccess((record) =>
|
|
430
|
-
succeed({ kind, entityId, record })
|
|
431
|
-
);
|
|
432
|
-
})
|
|
433
|
-
)
|
|
434
|
-
)
|
|
435
|
-
);
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
/**
|
|
439
|
-
* Discriminate the write outcome from a pre-put snapshot and the returned record.
|
|
440
|
-
* A dedup no-op returns either a different entity (content-scope dedup) or the
|
|
441
|
-
* same-id record with an unchanged `seq` (entity-scope re-put); a fresh write or
|
|
442
|
-
* update advances `seq`.
|
|
443
|
-
*/
|
|
444
|
-
function writeOutcome(
|
|
445
|
-
before: IMemoryRecord<unknown> | undefined,
|
|
446
|
-
written: IMemoryRecord<unknown>,
|
|
447
|
-
entityId: EntityId
|
|
448
|
-
): MemoryWriteOutcome {
|
|
449
|
-
if (written.envelope.entityId !== entityId) {
|
|
450
|
-
return 'deduped';
|
|
451
|
-
}
|
|
452
|
-
if (before !== undefined && written.envelope.seq === before.envelope.seq) {
|
|
453
|
-
return 'deduped';
|
|
454
|
-
}
|
|
455
|
-
return 'written';
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
// ---------------------------------------------------------------------------
|
|
459
|
-
// Tool builders — config with a JsonSchema.object(...) parametersSchema; execute
|
|
460
|
-
// validates/narrows → delegates to store/retriever → returns the Result (never
|
|
461
|
-
// swallowed), following the ts-extras-mcp adapter shape.
|
|
462
|
-
//
|
|
463
|
-
// Each `execute` re-runs its own `parametersSchema.convert(args)` even though the
|
|
464
|
-
// `executeClientToolTurn` harness already validates against the same schema. This
|
|
465
|
-
// is deliberate: the factory returns a heterogeneous `ReadonlyArray<IAiClientTool>`
|
|
466
|
-
// (TParams erased to `unknown`, since the members carry different param shapes), so
|
|
467
|
-
// `execute` receives `unknown` and must narrow it back to the typed args. The
|
|
468
|
-
// re-validation is also the narrowing step exercised by the direct-call tests (which
|
|
469
|
-
// invoke `execute` with raw args, bypassing the harness). Re-validating an
|
|
470
|
-
// already-conforming shape is a cheap, side-effect-free identity.
|
|
471
|
-
// ---------------------------------------------------------------------------
|
|
472
|
-
|
|
473
|
-
function buildWriteTool(ctx: IToolContext): AiAssist.IAiClientTool {
|
|
474
|
-
return {
|
|
475
|
-
config: {
|
|
476
|
-
type: 'client_tool',
|
|
477
|
-
name: 'memory_write',
|
|
478
|
-
description:
|
|
479
|
-
'Store a new memory record or update an existing one by (kind, entityId). ' +
|
|
480
|
-
'Identical content is a no-op that returns the existing record.',
|
|
481
|
-
parametersSchema: writeSchema,
|
|
482
|
-
annotations: WRITE_ANNOTATIONS
|
|
483
|
-
},
|
|
484
|
-
execute: async (args: unknown): Promise<Result<unknown>> =>
|
|
485
|
-
writeSchema
|
|
486
|
-
.convert(args)
|
|
487
|
-
.withErrorFormat((msg) => `memory_write: invalid arguments: ${msg}`)
|
|
488
|
-
.onSuccess((typed) => prepareWrite(ctx, typed))
|
|
489
|
-
.thenOnSuccess(async ({ kind, entityId, record }) =>
|
|
490
|
-
// Read the prior record to discriminate written-vs-deduped. A `Failure`
|
|
491
|
-
// here (corrupt file, I/O error, codec round-trip failure) is a real
|
|
492
|
-
// condition distinct from the "not found" success (`undefined`); propagate
|
|
493
|
-
// it rather than defaulting it away, so a genuine store fault surfaces
|
|
494
|
-
// instead of being masked as a normal write.
|
|
495
|
-
(await ctx.store.get(kind, entityId)).thenOnSuccess(async (before) =>
|
|
496
|
-
(await ctx.store.put(record)).onSuccess((persisted) =>
|
|
497
|
-
succeed<IMemoryWriteResult>({
|
|
498
|
-
outcome: writeOutcome(before, persisted, entityId),
|
|
499
|
-
id: persisted.envelope.id,
|
|
500
|
-
entityId,
|
|
501
|
-
kind
|
|
502
|
-
})
|
|
503
|
-
)
|
|
504
|
-
)
|
|
505
|
-
)
|
|
506
|
-
};
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
function buildReadTool(ctx: IToolContext): AiAssist.IAiClientTool {
|
|
510
|
-
return {
|
|
511
|
-
config: {
|
|
512
|
-
type: 'client_tool',
|
|
513
|
-
name: 'memory_read',
|
|
514
|
-
description: 'Read a specific memory record by (kind, entityId).',
|
|
515
|
-
parametersSchema: readSchema,
|
|
516
|
-
annotations: READ_ONLY_ANNOTATIONS
|
|
517
|
-
},
|
|
518
|
-
execute: async (args: unknown): Promise<Result<unknown>> =>
|
|
519
|
-
readSchema
|
|
520
|
-
.convert(args)
|
|
521
|
-
.withErrorFormat((msg) => `memory_read: invalid arguments: ${msg}`)
|
|
522
|
-
.onSuccess((typed) =>
|
|
523
|
-
assertKindEnabled(ctx, typed.kind).onSuccess((kind) =>
|
|
524
|
-
Convert.entityId.convert(typed.entityId).onSuccess((entityId) => {
|
|
525
|
-
// `memory_read` is the explicit drill-in path, so its detail default is
|
|
526
|
-
// INVERTED vs search/context: `'full'` unless the caller opts down to `'gist'`.
|
|
527
|
-
const detail: MemoryDetailTier = typed.detail === 'gist' ? 'gist' : 'full';
|
|
528
|
-
return succeed({ kind, entityId, detail });
|
|
529
|
-
})
|
|
530
|
-
)
|
|
531
|
-
)
|
|
532
|
-
.thenOnSuccess(async ({ kind, entityId, detail }) =>
|
|
533
|
-
(await ctx.store.get(kind, entityId)).onSuccess((record) =>
|
|
534
|
-
record === undefined
|
|
535
|
-
? succeed({ found: false })
|
|
536
|
-
: succeed({ found: true, item: projectItem(ctx, record, detail) })
|
|
537
|
-
)
|
|
538
|
-
)
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
function buildSearchTool(ctx: IToolContext): AiAssist.IAiClientTool {
|
|
543
|
-
return {
|
|
544
|
-
config: {
|
|
545
|
-
type: 'client_tool',
|
|
546
|
-
name: 'memory_search',
|
|
547
|
-
description: 'Search memories by tag, kind, or semantic text. Returns ranked results.',
|
|
548
|
-
parametersSchema: searchSchema,
|
|
549
|
-
annotations: READ_ONLY_ANNOTATIONS
|
|
550
|
-
},
|
|
551
|
-
execute: async (args: unknown): Promise<Result<unknown>> =>
|
|
552
|
-
searchSchema
|
|
553
|
-
.convert(args)
|
|
554
|
-
.withErrorFormat((msg) => `memory_search: invalid arguments: ${msg}`)
|
|
555
|
-
.onSuccess((typed) =>
|
|
556
|
-
resolveOptionalKind(ctx, typed.kind).onSuccess((kind) =>
|
|
557
|
-
resolveOptionalTag(typed.tag).onSuccess((tag) => succeed({ typed, kind, tag }))
|
|
558
|
-
)
|
|
559
|
-
)
|
|
560
|
-
.thenOnSuccess(async ({ typed, kind, tag }) => {
|
|
561
|
-
const detail: MemoryDetailTier = resolveDetail(typed.detail);
|
|
562
|
-
const query: IMemoryQuery = {
|
|
563
|
-
...(kind !== undefined ? { kind } : {}),
|
|
564
|
-
...(tag !== undefined ? { tag } : {}),
|
|
565
|
-
...(typed.semantic !== undefined ? { semantic: typed.semantic } : {}),
|
|
566
|
-
...(typed.limit !== undefined ? { limit: typed.limit } : {}),
|
|
567
|
-
...(typed.offset !== undefined ? { offset: typed.offset } : {})
|
|
568
|
-
};
|
|
569
|
-
return (await ctx.retriever.retrieve(query)).onSuccess((records) =>
|
|
570
|
-
succeed({ count: records.length, results: records.map((r) => projectItem(ctx, r, detail)) })
|
|
571
|
-
);
|
|
572
|
-
})
|
|
573
|
-
};
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
function buildContextTool(ctx: IToolContext): AiAssist.IAiClientTool {
|
|
577
|
-
return {
|
|
578
|
-
config: {
|
|
579
|
-
type: 'client_tool',
|
|
580
|
-
name: 'memory_context',
|
|
581
|
-
description:
|
|
582
|
-
'Build a context graph from a seed memory: returns the records linked from the seed, up to `hops` hops.',
|
|
583
|
-
parametersSchema: contextSchema,
|
|
584
|
-
annotations: READ_ONLY_ANNOTATIONS
|
|
585
|
-
},
|
|
586
|
-
execute: async (args: unknown): Promise<Result<unknown>> =>
|
|
587
|
-
contextSchema
|
|
588
|
-
.convert(args)
|
|
589
|
-
.withErrorFormat((msg) => `memory_context: invalid arguments: ${msg}`)
|
|
590
|
-
.onSuccess((typed) =>
|
|
591
|
-
resolveContextSeed(typed.from).onSuccess((from) =>
|
|
592
|
-
resolveOptionalKind(ctx, typed.kind).onSuccess((kind) =>
|
|
593
|
-
resolveOptionalTag(typed.tag).onSuccess((tag) => succeed({ typed, from, kind, tag }))
|
|
594
|
-
)
|
|
595
|
-
)
|
|
596
|
-
)
|
|
597
|
-
.thenOnSuccess(async ({ typed, from, kind, tag }) => {
|
|
598
|
-
const detail: MemoryDetailTier = resolveDetail(typed.detail);
|
|
599
|
-
const query: IMemoryQuery = {
|
|
600
|
-
linkedFrom: from,
|
|
601
|
-
...(kind !== undefined ? { kind } : {}),
|
|
602
|
-
...(tag !== undefined ? { tag } : {}),
|
|
603
|
-
...(typed.hops !== undefined ? { hops: typed.hops } : {}),
|
|
604
|
-
...(typed.limit !== undefined ? { limit: typed.limit } : {})
|
|
605
|
-
};
|
|
606
|
-
return (await ctx.retriever.retrieve(query)).onSuccess((records) =>
|
|
607
|
-
succeed({
|
|
608
|
-
seed: from,
|
|
609
|
-
count: records.length,
|
|
610
|
-
results: records.map((r) => projectItem(ctx, r, detail))
|
|
611
|
-
})
|
|
612
|
-
);
|
|
613
|
-
})
|
|
614
|
-
};
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
function buildDeleteTool(ctx: IToolContext): AiAssist.IAiClientTool {
|
|
618
|
-
return {
|
|
619
|
-
config: {
|
|
620
|
-
type: 'client_tool',
|
|
621
|
-
name: 'memory_delete',
|
|
622
|
-
description: 'Delete a memory record by (kind, entityId). Destructive for non-temporal kinds.',
|
|
623
|
-
parametersSchema: deleteSchema,
|
|
624
|
-
annotations: DELETE_ANNOTATIONS
|
|
625
|
-
},
|
|
626
|
-
execute: async (args: unknown): Promise<Result<unknown>> =>
|
|
627
|
-
deleteSchema
|
|
628
|
-
.convert(args)
|
|
629
|
-
.withErrorFormat((msg) => `memory_delete: invalid arguments: ${msg}`)
|
|
630
|
-
.onSuccess((typed) =>
|
|
631
|
-
assertKindEnabled(ctx, typed.kind).onSuccess((kind) =>
|
|
632
|
-
Convert.entityId.convert(typed.entityId).onSuccess((entityId) => succeed({ kind, entityId }))
|
|
633
|
-
)
|
|
634
|
-
)
|
|
635
|
-
.thenOnSuccess(async ({ kind, entityId }) =>
|
|
636
|
-
(await ctx.store.delete(kind, entityId)).onSuccess((id) =>
|
|
637
|
-
succeed({ deleted: true, id, entityId, kind })
|
|
638
|
-
)
|
|
639
|
-
)
|
|
640
|
-
};
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
/**
|
|
644
|
-
* Resolve a `memory_context` seed argument into a scope-qualified
|
|
645
|
-
* {@link IEdgeTarget}. Both `id` and `scope` are present here — the tool's
|
|
646
|
-
* `parametersSchema` ({@link contextSeedSchema}) makes `scope` schema-required —
|
|
647
|
-
* so this only brands the two fields; a malformed value fails via the branded
|
|
648
|
-
* converters (e.g. a path-unsafe seed id).
|
|
649
|
-
*/
|
|
650
|
-
function resolveContextSeed(from: { readonly id: string; readonly scope: string }): Result<IEdgeTarget> {
|
|
651
|
-
return Convert.memoryId
|
|
652
|
-
.convert(from.id)
|
|
653
|
-
.onSuccess((id) => Convert.scopeKey.convert(from.scope).onSuccess((scope) => succeed({ scope, id })));
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
/** Validate an optional `tag` string (`undefined` passes through). */
|
|
657
|
-
function resolveOptionalTag(tagStr?: string): Result<Tag | undefined> {
|
|
658
|
-
if (tagStr === undefined) {
|
|
659
|
-
return succeed(undefined);
|
|
660
|
-
}
|
|
661
|
-
return Convert.tag.convert(tagStr);
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
/** Ordered registry of the five tool builders, keyed by name. */
|
|
665
|
-
const TOOL_BUILDERS: ReadonlyArray<{
|
|
666
|
-
readonly name: MemoryToolName;
|
|
667
|
-
readonly build: (ctx: IToolContext) => AiAssist.IAiClientTool;
|
|
668
|
-
}> = [
|
|
669
|
-
{ name: 'memory_write', build: buildWriteTool },
|
|
670
|
-
{ name: 'memory_read', build: buildReadTool },
|
|
671
|
-
{ name: 'memory_search', build: buildSearchTool },
|
|
672
|
-
{ name: 'memory_context', build: buildContextTool },
|
|
673
|
-
{ name: 'memory_delete', build: buildDeleteTool }
|
|
674
|
-
];
|
|
675
|
-
|
|
676
|
-
/**
|
|
677
|
-
* Build the selected suite of memory `AiAssist.IAiClientTool`s over a
|
|
678
|
-
* pre-scoped store — ready to hand to `AiAssist.executeClientToolTurn` (and, via
|
|
679
|
-
* the shared `JsonSchema.object(...)` schemas, `@fgv/ts-extras-mcp`).
|
|
680
|
-
*
|
|
681
|
-
* @remarks
|
|
682
|
-
* **Scope isolation is make-or-break.** The returned tools close over the
|
|
683
|
-
* pre-scoped {@link ICreateMemoryToolsParams.store | store}; no tool's
|
|
684
|
-
* `parametersSchema` declares a `scope` (or any scope-widening) property, so an
|
|
685
|
-
* LLM cannot steer a tool at another actor's memory. The store instance is the
|
|
686
|
-
* sole scope authority.
|
|
687
|
-
*
|
|
688
|
-
* The default selection is {@link DEFAULT_MEMORY_TOOLS} (the read-only set) —
|
|
689
|
-
* `memory_write` / `memory_delete` are included only when named in
|
|
690
|
-
* {@link ICreateMemoryToolsParams.tools | tools}.
|
|
691
|
-
* @public
|
|
692
|
-
*/
|
|
693
|
-
export function createMemoryTools(params: ICreateMemoryToolsParams): ReadonlyArray<AiAssist.IAiClientTool> {
|
|
694
|
-
const ctx: IToolContext = {
|
|
695
|
-
store: params.store,
|
|
696
|
-
retriever: params.retriever,
|
|
697
|
-
registry: params.registry,
|
|
698
|
-
kinds: params.kinds,
|
|
699
|
-
codecs: params.codecs,
|
|
700
|
-
defaultCodec: params.defaultCodec,
|
|
701
|
-
handleFor: params.handleFor,
|
|
702
|
-
projectItem: params.projectItem
|
|
703
|
-
};
|
|
704
|
-
const selected: ReadonlySet<MemoryToolName> = new Set<MemoryToolName>(params.tools ?? DEFAULT_MEMORY_TOOLS);
|
|
705
|
-
return TOOL_BUILDERS.filter((builder) => selected.has(builder.name)).map((builder) => builder.build(ctx));
|
|
706
|
-
}
|