@revealui/ai 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/LICENSE.commercial +112 -0
- package/README.md +314 -0
- package/dist/a2a/card.d.ts +26 -0
- package/dist/a2a/card.d.ts.map +1 -0
- package/dist/a2a/card.js +173 -0
- package/dist/a2a/handler.d.ts +26 -0
- package/dist/a2a/handler.d.ts.map +1 -0
- package/dist/a2a/handler.js +170 -0
- package/dist/a2a/index.d.ts +10 -0
- package/dist/a2a/index.d.ts.map +1 -0
- package/dist/a2a/index.js +9 -0
- package/dist/a2a/task-store.d.ts +42 -0
- package/dist/a2a/task-store.d.ts.map +1 -0
- package/dist/a2a/task-store.js +99 -0
- package/dist/audit/emitter.d.ts +34 -0
- package/dist/audit/emitter.d.ts.map +1 -0
- package/dist/audit/emitter.js +34 -0
- package/dist/audit/index.d.ts +44 -0
- package/dist/audit/index.d.ts.map +1 -0
- package/dist/audit/index.js +48 -0
- package/dist/audit/observer.d.ts +108 -0
- package/dist/audit/observer.d.ts.map +1 -0
- package/dist/audit/observer.js +271 -0
- package/dist/audit/policy.d.ts +70 -0
- package/dist/audit/policy.d.ts.map +1 -0
- package/dist/audit/policy.js +209 -0
- package/dist/audit/store.d.ts +42 -0
- package/dist/audit/store.d.ts.map +1 -0
- package/dist/audit/store.js +80 -0
- package/dist/audit/types.d.ts +169 -0
- package/dist/audit/types.d.ts.map +1 -0
- package/dist/audit/types.js +80 -0
- package/dist/client/hooks/index.d.ts +22 -0
- package/dist/client/hooks/index.d.ts.map +1 -0
- package/dist/client/hooks/index.js +21 -0
- package/dist/client/hooks/useAgentContext.d.ts +30 -0
- package/dist/client/hooks/useAgentContext.d.ts.map +1 -0
- package/dist/client/hooks/useAgentContext.js +161 -0
- package/dist/client/hooks/useAgentEvents.d.ts +126 -0
- package/dist/client/hooks/useAgentEvents.d.ts.map +1 -0
- package/dist/client/hooks/useAgentEvents.js +232 -0
- package/dist/client/hooks/useAgentStream.d.ts +44 -0
- package/dist/client/hooks/useAgentStream.d.ts.map +1 -0
- package/dist/client/hooks/useAgentStream.js +101 -0
- package/dist/client/hooks/useEpisodicMemory.d.ts +25 -0
- package/dist/client/hooks/useEpisodicMemory.d.ts.map +1 -0
- package/dist/client/hooks/useEpisodicMemory.js +174 -0
- package/dist/client/hooks/useWorkingMemory.d.ts +57 -0
- package/dist/client/hooks/useWorkingMemory.d.ts.map +1 -0
- package/dist/client/hooks/useWorkingMemory.js +276 -0
- package/dist/client/index.d.ts +14 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +13 -0
- package/dist/embeddings/index.d.ts +51 -0
- package/dist/embeddings/index.d.ts.map +1 -0
- package/dist/embeddings/index.js +73 -0
- package/dist/index.d.ts +83 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +103 -0
- package/dist/inference/context-assembly.d.ts +27 -0
- package/dist/inference/context-assembly.d.ts.map +1 -0
- package/dist/inference/context-assembly.js +81 -0
- package/dist/inference/overflow-compressor.d.ts +17 -0
- package/dist/inference/overflow-compressor.d.ts.map +1 -0
- package/dist/inference/overflow-compressor.js +40 -0
- package/dist/inference/runRag.d.ts +35 -0
- package/dist/inference/runRag.d.ts.map +1 -0
- package/dist/inference/runRag.js +53 -0
- package/dist/ingestion/bm25.d.ts +29 -0
- package/dist/ingestion/bm25.d.ts.map +1 -0
- package/dist/ingestion/bm25.js +161 -0
- package/dist/ingestion/cms-indexer.d.ts +39 -0
- package/dist/ingestion/cms-indexer.d.ts.map +1 -0
- package/dist/ingestion/cms-indexer.js +74 -0
- package/dist/ingestion/file-parsers.d.ts +51 -0
- package/dist/ingestion/file-parsers.d.ts.map +1 -0
- package/dist/ingestion/file-parsers.js +247 -0
- package/dist/ingestion/hybrid-search.d.ts +22 -0
- package/dist/ingestion/hybrid-search.d.ts.map +1 -0
- package/dist/ingestion/hybrid-search.js +63 -0
- package/dist/ingestion/index.d.ts +9 -0
- package/dist/ingestion/index.d.ts.map +1 -0
- package/dist/ingestion/index.js +8 -0
- package/dist/ingestion/pipeline.d.ts +35 -0
- package/dist/ingestion/pipeline.d.ts.map +1 -0
- package/dist/ingestion/pipeline.js +114 -0
- package/dist/ingestion/rag-vector-service.d.ts +34 -0
- package/dist/ingestion/rag-vector-service.d.ts.map +1 -0
- package/dist/ingestion/rag-vector-service.js +98 -0
- package/dist/ingestion/reranker.d.ts +10 -0
- package/dist/ingestion/reranker.d.ts.map +1 -0
- package/dist/ingestion/reranker.js +41 -0
- package/dist/ingestion/text-splitter.d.ts +25 -0
- package/dist/ingestion/text-splitter.d.ts.map +1 -0
- package/dist/ingestion/text-splitter.js +119 -0
- package/dist/llm/cache-utils.d.ts +146 -0
- package/dist/llm/cache-utils.d.ts.map +1 -0
- package/dist/llm/cache-utils.js +204 -0
- package/dist/llm/client.d.ts +134 -0
- package/dist/llm/client.d.ts.map +1 -0
- package/dist/llm/client.js +497 -0
- package/dist/llm/key-validator.d.ts +25 -0
- package/dist/llm/key-validator.d.ts.map +1 -0
- package/dist/llm/key-validator.js +101 -0
- package/dist/llm/provider-health.d.ts +40 -0
- package/dist/llm/provider-health.d.ts.map +1 -0
- package/dist/llm/provider-health.js +97 -0
- package/dist/llm/providers/anthropic.d.ts +31 -0
- package/dist/llm/providers/anthropic.d.ts.map +1 -0
- package/dist/llm/providers/anthropic.js +248 -0
- package/dist/llm/providers/base.d.ts +111 -0
- package/dist/llm/providers/base.d.ts.map +1 -0
- package/dist/llm/providers/base.js +6 -0
- package/dist/llm/providers/groq.d.ts +23 -0
- package/dist/llm/providers/groq.d.ts.map +1 -0
- package/dist/llm/providers/groq.js +27 -0
- package/dist/llm/providers/ollama.d.ts +27 -0
- package/dist/llm/providers/ollama.d.ts.map +1 -0
- package/dist/llm/providers/ollama.js +48 -0
- package/dist/llm/providers/openai.d.ts +19 -0
- package/dist/llm/providers/openai.d.ts.map +1 -0
- package/dist/llm/providers/openai.js +245 -0
- package/dist/llm/providers/vultr.d.ts +18 -0
- package/dist/llm/providers/vultr.d.ts.map +1 -0
- package/dist/llm/providers/vultr.js +168 -0
- package/dist/llm/response-cache.d.ts +166 -0
- package/dist/llm/response-cache.d.ts.map +1 -0
- package/dist/llm/response-cache.js +233 -0
- package/dist/llm/semantic-cache.d.ts +179 -0
- package/dist/llm/semantic-cache.d.ts.map +1 -0
- package/dist/llm/semantic-cache.js +306 -0
- package/dist/llm/server.d.ts +14 -0
- package/dist/llm/server.d.ts.map +1 -0
- package/dist/llm/server.js +15 -0
- package/dist/llm/token-counter.d.ts +48 -0
- package/dist/llm/token-counter.d.ts.map +1 -0
- package/dist/llm/token-counter.js +77 -0
- package/dist/llm/workspace-provider-config.d.ts +38 -0
- package/dist/llm/workspace-provider-config.d.ts.map +1 -0
- package/dist/llm/workspace-provider-config.js +47 -0
- package/dist/memory/agent/context-manager.d.ts +148 -0
- package/dist/memory/agent/context-manager.d.ts.map +1 -0
- package/dist/memory/agent/context-manager.js +284 -0
- package/dist/memory/agent/index.d.ts +7 -0
- package/dist/memory/agent/index.d.ts.map +1 -0
- package/dist/memory/agent/index.js +6 -0
- package/dist/memory/crdt/index.d.ts +13 -0
- package/dist/memory/crdt/index.d.ts.map +1 -0
- package/dist/memory/crdt/index.js +12 -0
- package/dist/memory/crdt/lww-register.d.ts +108 -0
- package/dist/memory/crdt/lww-register.d.ts.map +1 -0
- package/dist/memory/crdt/lww-register.js +169 -0
- package/dist/memory/crdt/or-set.d.ts +141 -0
- package/dist/memory/crdt/or-set.d.ts.map +1 -0
- package/dist/memory/crdt/or-set.js +291 -0
- package/dist/memory/crdt/pn-counter.d.ts +116 -0
- package/dist/memory/crdt/pn-counter.d.ts.map +1 -0
- package/dist/memory/crdt/pn-counter.js +174 -0
- package/dist/memory/crdt/vector-clock.d.ts +115 -0
- package/dist/memory/crdt/vector-clock.d.ts.map +1 -0
- package/dist/memory/crdt/vector-clock.js +179 -0
- package/dist/memory/errors/index.d.ts +56 -0
- package/dist/memory/errors/index.d.ts.map +1 -0
- package/dist/memory/errors/index.js +85 -0
- package/dist/memory/index.d.ts +21 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +20 -0
- package/dist/memory/persistence/crdt-persistence.d.ts +85 -0
- package/dist/memory/persistence/crdt-persistence.d.ts.map +1 -0
- package/dist/memory/persistence/crdt-persistence.js +204 -0
- package/dist/memory/persistence/index.d.ts +7 -0
- package/dist/memory/persistence/index.d.ts.map +1 -0
- package/dist/memory/persistence/index.js +6 -0
- package/dist/memory/preferences/index.d.ts +7 -0
- package/dist/memory/preferences/index.d.ts.map +1 -0
- package/dist/memory/preferences/index.js +6 -0
- package/dist/memory/preferences/user-preferences-manager.d.ts +133 -0
- package/dist/memory/preferences/user-preferences-manager.d.ts.map +1 -0
- package/dist/memory/preferences/user-preferences-manager.js +342 -0
- package/dist/memory/services/index.d.ts +8 -0
- package/dist/memory/services/index.d.ts.map +1 -0
- package/dist/memory/services/index.js +6 -0
- package/dist/memory/services/node-id-service.d.ts +75 -0
- package/dist/memory/services/node-id-service.d.ts.map +1 -0
- package/dist/memory/services/node-id-service.js +190 -0
- package/dist/memory/stores/episodic-memory.d.ts +182 -0
- package/dist/memory/stores/episodic-memory.d.ts.map +1 -0
- package/dist/memory/stores/episodic-memory.js +378 -0
- package/dist/memory/stores/index.d.ts +16 -0
- package/dist/memory/stores/index.d.ts.map +1 -0
- package/dist/memory/stores/index.js +15 -0
- package/dist/memory/stores/procedural-memory.d.ts +89 -0
- package/dist/memory/stores/procedural-memory.d.ts.map +1 -0
- package/dist/memory/stores/procedural-memory.js +152 -0
- package/dist/memory/stores/semantic-memory.d.ts +92 -0
- package/dist/memory/stores/semantic-memory.d.ts.map +1 -0
- package/dist/memory/stores/semantic-memory.js +155 -0
- package/dist/memory/stores/working-memory.d.ts +225 -0
- package/dist/memory/stores/working-memory.d.ts.map +1 -0
- package/dist/memory/stores/working-memory.js +336 -0
- package/dist/memory/utils/deep-clone.d.ts +10 -0
- package/dist/memory/utils/deep-clone.d.ts.map +1 -0
- package/dist/memory/utils/deep-clone.js +9 -0
- package/dist/memory/utils/index.d.ts +8 -0
- package/dist/memory/utils/index.d.ts.map +1 -0
- package/dist/memory/utils/index.js +7 -0
- package/dist/memory/utils/logger.d.ts +21 -0
- package/dist/memory/utils/logger.d.ts.map +1 -0
- package/dist/memory/utils/logger.js +62 -0
- package/dist/memory/utils/sql-helpers.d.ts +97 -0
- package/dist/memory/utils/sql-helpers.d.ts.map +1 -0
- package/dist/memory/utils/sql-helpers.js +214 -0
- package/dist/memory/utils/validation.d.ts +62 -0
- package/dist/memory/utils/validation.d.ts.map +1 -0
- package/dist/memory/utils/validation.js +244 -0
- package/dist/memory/vector/index.d.ts +12 -0
- package/dist/memory/vector/index.d.ts.map +1 -0
- package/dist/memory/vector/index.js +14 -0
- package/dist/memory/vector/vector-memory-service.d.ts +88 -0
- package/dist/memory/vector/vector-memory-service.d.ts.map +1 -0
- package/dist/memory/vector/vector-memory-service.js +335 -0
- package/dist/observability/logger.d.ts +79 -0
- package/dist/observability/logger.d.ts.map +1 -0
- package/dist/observability/logger.js +165 -0
- package/dist/observability/metrics.d.ts +43 -0
- package/dist/observability/metrics.d.ts.map +1 -0
- package/dist/observability/metrics.js +197 -0
- package/dist/observability/query.d.ts +150 -0
- package/dist/observability/query.d.ts.map +1 -0
- package/dist/observability/query.js +339 -0
- package/dist/observability/types.d.ts +140 -0
- package/dist/observability/types.d.ts.map +1 -0
- package/dist/observability/types.js +6 -0
- package/dist/orchestration/agent.d.ts +98 -0
- package/dist/orchestration/agent.d.ts.map +1 -0
- package/dist/orchestration/agent.js +6 -0
- package/dist/orchestration/defaults.d.ts +21 -0
- package/dist/orchestration/defaults.d.ts.map +1 -0
- package/dist/orchestration/defaults.js +22 -0
- package/dist/orchestration/memory-integration.d.ts +58 -0
- package/dist/orchestration/memory-integration.d.ts.map +1 -0
- package/dist/orchestration/memory-integration.js +130 -0
- package/dist/orchestration/orchestrator.d.ts +67 -0
- package/dist/orchestration/orchestrator.d.ts.map +1 -0
- package/dist/orchestration/orchestrator.js +174 -0
- package/dist/orchestration/runtime.d.ts +82 -0
- package/dist/orchestration/runtime.d.ts.map +1 -0
- package/dist/orchestration/runtime.js +251 -0
- package/dist/orchestration/streaming-runtime.d.ts +36 -0
- package/dist/orchestration/streaming-runtime.d.ts.map +1 -0
- package/dist/orchestration/streaming-runtime.js +175 -0
- package/dist/orchestration/ticket-agent.d.ts +70 -0
- package/dist/orchestration/ticket-agent.d.ts.map +1 -0
- package/dist/orchestration/ticket-agent.js +146 -0
- package/dist/skills/activation/index.d.ts +7 -0
- package/dist/skills/activation/index.d.ts.map +1 -0
- package/dist/skills/activation/index.js +6 -0
- package/dist/skills/activation/skill-activator.d.ts +68 -0
- package/dist/skills/activation/skill-activator.d.ts.map +1 -0
- package/dist/skills/activation/skill-activator.js +224 -0
- package/dist/skills/catalog/catalog-search.d.ts +55 -0
- package/dist/skills/catalog/catalog-search.d.ts.map +1 -0
- package/dist/skills/catalog/catalog-search.js +111 -0
- package/dist/skills/catalog/catalog-types.d.ts +81 -0
- package/dist/skills/catalog/catalog-types.d.ts.map +1 -0
- package/dist/skills/catalog/catalog-types.js +66 -0
- package/dist/skills/catalog/index.d.ts +9 -0
- package/dist/skills/catalog/index.d.ts.map +1 -0
- package/dist/skills/catalog/index.js +7 -0
- package/dist/skills/catalog/vercel-catalog.d.ts +42 -0
- package/dist/skills/catalog/vercel-catalog.d.ts.map +1 -0
- package/dist/skills/catalog/vercel-catalog.js +189 -0
- package/dist/skills/compat/index.d.ts +9 -0
- package/dist/skills/compat/index.d.ts.map +1 -0
- package/dist/skills/compat/index.js +8 -0
- package/dist/skills/compat/skill-enhancer.d.ts +37 -0
- package/dist/skills/compat/skill-enhancer.d.ts.map +1 -0
- package/dist/skills/compat/skill-enhancer.js +76 -0
- package/dist/skills/compat/tool-mapper.d.ts +61 -0
- package/dist/skills/compat/tool-mapper.d.ts.map +1 -0
- package/dist/skills/compat/tool-mapper.js +168 -0
- package/dist/skills/compat/vercel-compat.d.ts +33 -0
- package/dist/skills/compat/vercel-compat.d.ts.map +1 -0
- package/dist/skills/compat/vercel-compat.js +132 -0
- package/dist/skills/index.d.ts +40 -0
- package/dist/skills/index.d.ts.map +1 -0
- package/dist/skills/index.js +47 -0
- package/dist/skills/integration/agent-skill-provider.d.ts +94 -0
- package/dist/skills/integration/agent-skill-provider.d.ts.map +1 -0
- package/dist/skills/integration/agent-skill-provider.js +161 -0
- package/dist/skills/integration/index.d.ts +7 -0
- package/dist/skills/integration/index.d.ts.map +1 -0
- package/dist/skills/integration/index.js +6 -0
- package/dist/skills/loader/github-loader.d.ts +61 -0
- package/dist/skills/loader/github-loader.d.ts.map +1 -0
- package/dist/skills/loader/github-loader.js +176 -0
- package/dist/skills/loader/index.d.ts +10 -0
- package/dist/skills/loader/index.d.ts.map +1 -0
- package/dist/skills/loader/index.js +9 -0
- package/dist/skills/loader/local-loader.d.ts +56 -0
- package/dist/skills/loader/local-loader.d.ts.map +1 -0
- package/dist/skills/loader/local-loader.js +186 -0
- package/dist/skills/loader/vercel-loader.d.ts +64 -0
- package/dist/skills/loader/vercel-loader.d.ts.map +1 -0
- package/dist/skills/loader/vercel-loader.js +313 -0
- package/dist/skills/loader/vercel-types.d.ts +64 -0
- package/dist/skills/loader/vercel-types.d.ts.map +1 -0
- package/dist/skills/loader/vercel-types.js +55 -0
- package/dist/skills/parser/index.d.ts +7 -0
- package/dist/skills/parser/index.d.ts.map +1 -0
- package/dist/skills/parser/index.js +6 -0
- package/dist/skills/parser/skill-md-parser.d.ts +64 -0
- package/dist/skills/parser/skill-md-parser.d.ts.map +1 -0
- package/dist/skills/parser/skill-md-parser.js +242 -0
- package/dist/skills/registry/index.d.ts +7 -0
- package/dist/skills/registry/index.d.ts.map +1 -0
- package/dist/skills/registry/index.js +6 -0
- package/dist/skills/registry/skill-registry.d.ts +133 -0
- package/dist/skills/registry/skill-registry.d.ts.map +1 -0
- package/dist/skills/registry/skill-registry.js +373 -0
- package/dist/skills/types.d.ts +216 -0
- package/dist/skills/types.d.ts.map +1 -0
- package/dist/skills/types.js +176 -0
- package/dist/templates/agent-spec.d.ts +138 -0
- package/dist/templates/agent-spec.d.ts.map +1 -0
- package/dist/templates/agent-spec.js +138 -0
- package/dist/templates/index.d.ts +56 -0
- package/dist/templates/index.d.ts.map +1 -0
- package/dist/templates/index.js +58 -0
- package/dist/templates/prompt-spec.d.ts +140 -0
- package/dist/templates/prompt-spec.d.ts.map +1 -0
- package/dist/templates/prompt-spec.js +210 -0
- package/dist/templates/skill-spec.d.ts +106 -0
- package/dist/templates/skill-spec.d.ts.map +1 -0
- package/dist/templates/skill-spec.js +119 -0
- package/dist/tools/base.d.ts +74 -0
- package/dist/tools/base.d.ts.map +1 -0
- package/dist/tools/base.js +6 -0
- package/dist/tools/cms/collection-tools.d.ts +36 -0
- package/dist/tools/cms/collection-tools.d.ts.map +1 -0
- package/dist/tools/cms/collection-tools.js +178 -0
- package/dist/tools/cms/factory.d.ts +89 -0
- package/dist/tools/cms/factory.d.ts.map +1 -0
- package/dist/tools/cms/factory.js +462 -0
- package/dist/tools/cms/global-tools.d.ts +21 -0
- package/dist/tools/cms/global-tools.d.ts.map +1 -0
- package/dist/tools/cms/global-tools.js +92 -0
- package/dist/tools/cms/index.d.ts +11 -0
- package/dist/tools/cms/index.d.ts.map +1 -0
- package/dist/tools/cms/index.js +11 -0
- package/dist/tools/cms/media-tools.d.ts +31 -0
- package/dist/tools/cms/media-tools.d.ts.map +1 -0
- package/dist/tools/cms/media-tools.js +140 -0
- package/dist/tools/cms/user-tools.d.ts +31 -0
- package/dist/tools/cms/user-tools.d.ts.map +1 -0
- package/dist/tools/cms/user-tools.js +135 -0
- package/dist/tools/deduplicator.d.ts +19 -0
- package/dist/tools/deduplicator.d.ts.map +1 -0
- package/dist/tools/deduplicator.js +53 -0
- package/dist/tools/document-summarizer.d.ts +11 -0
- package/dist/tools/document-summarizer.d.ts.map +1 -0
- package/dist/tools/document-summarizer.js +82 -0
- package/dist/tools/mcp-adapter.d.ts +66 -0
- package/dist/tools/mcp-adapter.d.ts.map +1 -0
- package/dist/tools/mcp-adapter.js +152 -0
- package/dist/tools/memory/index.d.ts +3 -0
- package/dist/tools/memory/index.d.ts.map +1 -0
- package/dist/tools/memory/index.js +1 -0
- package/dist/tools/memory/store-memory.d.ts +39 -0
- package/dist/tools/memory/store-memory.d.ts.map +1 -0
- package/dist/tools/memory/store-memory.js +94 -0
- package/dist/tools/registry.d.ts +14 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +48 -0
- package/dist/tools/ticket-tools.d.ts +31 -0
- package/dist/tools/ticket-tools.d.ts.map +1 -0
- package/dist/tools/ticket-tools.js +74 -0
- package/dist/tools/web/duck-duck-go.d.ts +52 -0
- package/dist/tools/web/duck-duck-go.d.ts.map +1 -0
- package/dist/tools/web/duck-duck-go.js +202 -0
- package/dist/tools/web/exa.d.ts +34 -0
- package/dist/tools/web/exa.d.ts.map +1 -0
- package/dist/tools/web/exa.js +80 -0
- package/dist/tools/web/index.d.ts +6 -0
- package/dist/tools/web/index.d.ts.map +1 -0
- package/dist/tools/web/index.js +4 -0
- package/dist/tools/web/scraper.d.ts +9 -0
- package/dist/tools/web/scraper.d.ts.map +1 -0
- package/dist/tools/web/scraper.js +118 -0
- package/dist/tools/web/tavily.d.ts +32 -0
- package/dist/tools/web/tavily.d.ts.map +1 -0
- package/dist/tools/web/tavily.js +73 -0
- package/dist/tools/web/types.d.ts +31 -0
- package/dist/tools/web/types.d.ts.map +1 -0
- package/dist/tools/web/types.js +9 -0
- package/package.json +143 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Episodic Memory
|
|
3
|
+
*
|
|
4
|
+
* Long-term memory for conversation history and agent memories.
|
|
5
|
+
* Uses ORSet for collection management and PNCounter for access metrics.
|
|
6
|
+
*
|
|
7
|
+
* Key challenge: Bridge ORSet state (which memories exist) with
|
|
8
|
+
* agent_memories table (which stores individual memory records with vectors).
|
|
9
|
+
*/
|
|
10
|
+
import type { AgentMemory } from '@revealui/contracts/agents';
|
|
11
|
+
import type { Database } from '@revealui/db/client';
|
|
12
|
+
import { type ORSetData } from '../crdt/or-set.js';
|
|
13
|
+
import { type PNCounterData } from '../crdt/pn-counter.js';
|
|
14
|
+
import type { CRDTPersistence } from '../persistence/crdt-persistence.js';
|
|
15
|
+
import { type VectorSearchOptions } from '../vector/vector-memory-service.js';
|
|
16
|
+
export interface EpisodicMemoryData {
|
|
17
|
+
userId: string;
|
|
18
|
+
nodeId: string;
|
|
19
|
+
memories: ORSetData<string>;
|
|
20
|
+
accessCounter: PNCounterData;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Episodic Memory for long-term agent memory storage.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const memory = new EpisodicMemory('user-123', 'node-abc', db, persistence)
|
|
28
|
+
* await memory.load()
|
|
29
|
+
*
|
|
30
|
+
* const memoryId = await memory.add({
|
|
31
|
+
* id: 'mem-1',
|
|
32
|
+
* content: 'User prefers dark theme',
|
|
33
|
+
* type: 'preference',
|
|
34
|
+
* // ... other fields
|
|
35
|
+
* })
|
|
36
|
+
*
|
|
37
|
+
* const all = memory.getAll()
|
|
38
|
+
* await memory.save()
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare class EpisodicMemory {
|
|
42
|
+
private memories;
|
|
43
|
+
private accessCounter;
|
|
44
|
+
private userId;
|
|
45
|
+
private nodeId;
|
|
46
|
+
private db;
|
|
47
|
+
private persistence?;
|
|
48
|
+
private memoryCache;
|
|
49
|
+
private vectorService;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a new EpisodicMemory instance.
|
|
52
|
+
*
|
|
53
|
+
* @param userId - User identifier
|
|
54
|
+
* @param nodeId - Node identifier (for CRDT operations)
|
|
55
|
+
* @param db - Database client (REST DB for CRDT persistence)
|
|
56
|
+
* @param persistence - Optional persistence adapter
|
|
57
|
+
*/
|
|
58
|
+
constructor(userId: string, nodeId: string, db: Database, persistence?: CRDTPersistence);
|
|
59
|
+
/**
|
|
60
|
+
* Adds a memory to the collection.
|
|
61
|
+
* Stores the memory in vector database (Supabase) and adds its ID to ORSet.
|
|
62
|
+
*
|
|
63
|
+
* @param memory - Memory to add
|
|
64
|
+
* @returns Tag for this memory addition (for removal)
|
|
65
|
+
*/
|
|
66
|
+
add(memory: AgentMemory): Promise<string>;
|
|
67
|
+
/**
|
|
68
|
+
* Removes a memory by tag.
|
|
69
|
+
*
|
|
70
|
+
* @param tag - Tag returned from add()
|
|
71
|
+
* @returns true if memory was removed
|
|
72
|
+
*/
|
|
73
|
+
remove(tag: string): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Removes a memory by ID (removes all instances).
|
|
76
|
+
* Also deletes from database.
|
|
77
|
+
*
|
|
78
|
+
* @param memoryId - Memory ID to remove
|
|
79
|
+
* @returns Number of instances removed
|
|
80
|
+
*/
|
|
81
|
+
removeById(memoryId: string): Promise<number>;
|
|
82
|
+
/**
|
|
83
|
+
* Gets all memory IDs in the set.
|
|
84
|
+
*
|
|
85
|
+
* @returns Array of memory IDs
|
|
86
|
+
*/
|
|
87
|
+
getMemoryIds(): string[];
|
|
88
|
+
/**
|
|
89
|
+
* Gets all memories (loads from database if not cached).
|
|
90
|
+
*
|
|
91
|
+
* @returns Array of memory objects
|
|
92
|
+
*/
|
|
93
|
+
getAll(): Promise<AgentMemory[]>;
|
|
94
|
+
/**
|
|
95
|
+
* Gets a specific memory by ID.
|
|
96
|
+
*
|
|
97
|
+
* @param memoryId - Memory ID
|
|
98
|
+
* @returns Memory or null if not found
|
|
99
|
+
*/
|
|
100
|
+
get(memoryId: string): Promise<AgentMemory | null>;
|
|
101
|
+
/**
|
|
102
|
+
* Updates a memory by ID.
|
|
103
|
+
* Merges partial data with the current memory, persists to vector store,
|
|
104
|
+
* and refreshes the cache. Eliminates the need for callers to access
|
|
105
|
+
* private fields or instantiate VectorMemoryService directly.
|
|
106
|
+
*
|
|
107
|
+
* @param memoryId - Memory ID to update
|
|
108
|
+
* @param data - Partial memory data to merge
|
|
109
|
+
* @returns Updated memory
|
|
110
|
+
* @throws Error if memory not found in this user's ORSet
|
|
111
|
+
*/
|
|
112
|
+
update(memoryId: string, data: Partial<AgentMemory>): Promise<AgentMemory>;
|
|
113
|
+
/**
|
|
114
|
+
* Increments access counter and updates memory access tracking.
|
|
115
|
+
*
|
|
116
|
+
* @param memoryId - Optional memory ID to track access for
|
|
117
|
+
*/
|
|
118
|
+
incrementAccess(memoryId?: string): Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* Gets the total access count.
|
|
121
|
+
*
|
|
122
|
+
* @returns Total access count
|
|
123
|
+
*/
|
|
124
|
+
getAccessCount(): number;
|
|
125
|
+
/**
|
|
126
|
+
* Searches memories using vector similarity search.
|
|
127
|
+
*
|
|
128
|
+
* @param query - Search query text
|
|
129
|
+
* @param options - Search options (limit, threshold, filters)
|
|
130
|
+
* @returns Array of matching memories sorted by relevance
|
|
131
|
+
*/
|
|
132
|
+
search(query: string, options?: Omit<VectorSearchOptions, 'userId'>): Promise<AgentMemory[]>;
|
|
133
|
+
/**
|
|
134
|
+
* Merges another EpisodicMemory into this one.
|
|
135
|
+
*
|
|
136
|
+
* @param other - EpisodicMemory to merge
|
|
137
|
+
* @returns New merged EpisodicMemory
|
|
138
|
+
*/
|
|
139
|
+
merge(other: EpisodicMemory): EpisodicMemory;
|
|
140
|
+
/**
|
|
141
|
+
* Loads state from database.
|
|
142
|
+
*
|
|
143
|
+
* @throws Error if persistence is not configured
|
|
144
|
+
*/
|
|
145
|
+
load(): Promise<void>;
|
|
146
|
+
/**
|
|
147
|
+
* Saves state to database.
|
|
148
|
+
*
|
|
149
|
+
* @throws Error if persistence is not configured
|
|
150
|
+
*/
|
|
151
|
+
save(): Promise<void>;
|
|
152
|
+
/**
|
|
153
|
+
* Serializes EpisodicMemory to plain object.
|
|
154
|
+
*
|
|
155
|
+
* @returns Serialized data
|
|
156
|
+
*/
|
|
157
|
+
toData(): EpisodicMemoryData;
|
|
158
|
+
/**
|
|
159
|
+
* Deserializes EpisodicMemory from plain object.
|
|
160
|
+
*
|
|
161
|
+
* @param data - Serialized data
|
|
162
|
+
* @param db - Database client
|
|
163
|
+
* @param persistence - Optional persistence adapter
|
|
164
|
+
* @returns New EpisodicMemory instance
|
|
165
|
+
*/
|
|
166
|
+
static fromData(data: EpisodicMemoryData, db: Database, persistence?: CRDTPersistence): EpisodicMemory;
|
|
167
|
+
/**
|
|
168
|
+
* Creates a copy of this EpisodicMemory.
|
|
169
|
+
*
|
|
170
|
+
* @returns New EpisodicMemory with same state
|
|
171
|
+
*/
|
|
172
|
+
clone(): EpisodicMemory;
|
|
173
|
+
/**
|
|
174
|
+
* Gets the user ID.
|
|
175
|
+
*/
|
|
176
|
+
getUserId(): string;
|
|
177
|
+
/**
|
|
178
|
+
* Gets the node ID.
|
|
179
|
+
*/
|
|
180
|
+
getNodeId(): string;
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=episodic-memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"episodic-memory.d.ts","sourceRoot":"","sources":["../../../src/memory/stores/episodic-memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAE7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAGnD,OAAO,EAAS,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAA;AACzD,OAAO,EAAa,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAA;AACrE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAA;AACzE,OAAO,EAAuB,KAAK,mBAAmB,EAAE,MAAM,oCAAoC,CAAA;AAMlG,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,SAAS,CAAC,MAAM,CAAC,CAAA;IAC3B,aAAa,EAAE,aAAa,CAAA;CAC7B;AAMD;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAe;IAC/B,OAAO,CAAC,aAAa,CAAW;IAChC,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,EAAE,CAAU;IACpB,OAAO,CAAC,WAAW,CAAC,CAAiB;IACrC,OAAO,CAAC,WAAW,CAAsC;IACzD,OAAO,CAAC,aAAa,CAAqB;IAE1C;;;;;;;OAOG;gBACS,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,WAAW,CAAC,EAAE,eAAe;IAYvF;;;;;;OAMG;IACG,GAAG,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IA+B/C;;;;;OAKG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAU5B;;;;;;OAMG;IACG,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAqBnD;;;;OAIG;IACH,YAAY,IAAI,MAAM,EAAE;IAIxB;;;;OAIG;IACG,MAAM,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAwBtC;;;;;OAKG;IACG,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAuBxD;;;;;;;;;;OAUG;IACG,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC;IAgBhF;;;;OAIG;IACG,eAAe,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAwBvD;;;;OAIG;IACH,cAAc,IAAI,MAAM;IAIxB;;;;;;OAMG;IACG,MAAM,CACV,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,IAAI,CAAC,mBAAmB,EAAE,QAAQ,CAAM,GAChD,OAAO,CAAC,WAAW,EAAE,CAAC;IAsBzB;;;;;OAKG;IACH,KAAK,CAAC,KAAK,EAAE,cAAc,GAAG,cAAc;IAO5C;;;;OAIG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IA4B3B;;;;OAIG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAc3B;;;;OAIG;IACH,MAAM,IAAI,kBAAkB;IAS5B;;;;;;;OAOG;IACH,MAAM,CAAC,QAAQ,CACb,IAAI,EAAE,kBAAkB,EACxB,EAAE,EAAE,QAAQ,EACZ,WAAW,CAAC,EAAE,eAAe,GAC5B,cAAc;IAOjB;;;;OAIG;IACH,KAAK,IAAI,cAAc;IAIvB;;OAEG;IACH,SAAS,IAAI,MAAM;IAInB;;OAEG;IACH,SAAS,IAAI,MAAM;CAGpB"}
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Episodic Memory
|
|
3
|
+
*
|
|
4
|
+
* Long-term memory for conversation history and agent memories.
|
|
5
|
+
* Uses ORSet for collection management and PNCounter for access metrics.
|
|
6
|
+
*
|
|
7
|
+
* Key challenge: Bridge ORSet state (which memories exist) with
|
|
8
|
+
* agent_memories table (which stores individual memory records with vectors).
|
|
9
|
+
*/
|
|
10
|
+
import { EmbeddingSchema } from '@revealui/contracts/representation';
|
|
11
|
+
import { generateEmbedding } from '../../embeddings/index.js';
|
|
12
|
+
import { ORSet } from '../crdt/or-set.js';
|
|
13
|
+
import { PNCounter } from '../crdt/pn-counter.js';
|
|
14
|
+
import { VectorMemoryService } from '../vector/vector-memory-service.js';
|
|
15
|
+
// =============================================================================
|
|
16
|
+
// Episodic Memory
|
|
17
|
+
// =============================================================================
|
|
18
|
+
/**
|
|
19
|
+
* Episodic Memory for long-term agent memory storage.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const memory = new EpisodicMemory('user-123', 'node-abc', db, persistence)
|
|
24
|
+
* await memory.load()
|
|
25
|
+
*
|
|
26
|
+
* const memoryId = await memory.add({
|
|
27
|
+
* id: 'mem-1',
|
|
28
|
+
* content: 'User prefers dark theme',
|
|
29
|
+
* type: 'preference',
|
|
30
|
+
* // ... other fields
|
|
31
|
+
* })
|
|
32
|
+
*
|
|
33
|
+
* const all = memory.getAll()
|
|
34
|
+
* await memory.save()
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export class EpisodicMemory {
|
|
38
|
+
memories; // Stores memory IDs
|
|
39
|
+
accessCounter;
|
|
40
|
+
userId;
|
|
41
|
+
nodeId;
|
|
42
|
+
db; // REST DB for CRDT persistence
|
|
43
|
+
persistence;
|
|
44
|
+
memoryCache = new Map();
|
|
45
|
+
vectorService; // Vector DB for memory storage
|
|
46
|
+
/**
|
|
47
|
+
* Creates a new EpisodicMemory instance.
|
|
48
|
+
*
|
|
49
|
+
* @param userId - User identifier
|
|
50
|
+
* @param nodeId - Node identifier (for CRDT operations)
|
|
51
|
+
* @param db - Database client (REST DB for CRDT persistence)
|
|
52
|
+
* @param persistence - Optional persistence adapter
|
|
53
|
+
*/
|
|
54
|
+
constructor(userId, nodeId, db, persistence) {
|
|
55
|
+
this.userId = userId;
|
|
56
|
+
this.nodeId = nodeId;
|
|
57
|
+
this.db = db;
|
|
58
|
+
this.persistence = persistence;
|
|
59
|
+
this.vectorService = new VectorMemoryService();
|
|
60
|
+
// Initialize CRDTs
|
|
61
|
+
this.memories = new ORSet(nodeId);
|
|
62
|
+
this.accessCounter = new PNCounter(nodeId);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Adds a memory to the collection.
|
|
66
|
+
* Stores the memory in vector database (Supabase) and adds its ID to ORSet.
|
|
67
|
+
*
|
|
68
|
+
* @param memory - Memory to add
|
|
69
|
+
* @returns Tag for this memory addition (for removal)
|
|
70
|
+
*/
|
|
71
|
+
async add(memory) {
|
|
72
|
+
// Validate embedding if provided
|
|
73
|
+
if (memory.embedding) {
|
|
74
|
+
const validationResult = EmbeddingSchema.safeParse(memory.embedding);
|
|
75
|
+
if (!validationResult.success) {
|
|
76
|
+
throw new Error(`Invalid embedding structure: ${validationResult.error.message}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// Store in vector database using VectorMemoryService
|
|
80
|
+
await this.vectorService.create({
|
|
81
|
+
id: memory.id,
|
|
82
|
+
version: memory.version || 1,
|
|
83
|
+
content: memory.content,
|
|
84
|
+
type: memory.type,
|
|
85
|
+
source: memory.source,
|
|
86
|
+
embedding: memory.embedding,
|
|
87
|
+
metadata: memory.metadata,
|
|
88
|
+
accessCount: memory.accessCount || 0,
|
|
89
|
+
verified: memory.verified,
|
|
90
|
+
});
|
|
91
|
+
// Add to ORSet
|
|
92
|
+
const tag = this.memories.add(memory.id);
|
|
93
|
+
// Cache the memory
|
|
94
|
+
this.memoryCache.set(memory.id, memory);
|
|
95
|
+
return tag;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Removes a memory by tag.
|
|
99
|
+
*
|
|
100
|
+
* @param tag - Tag returned from add()
|
|
101
|
+
* @returns true if memory was removed
|
|
102
|
+
*/
|
|
103
|
+
remove(tag) {
|
|
104
|
+
const removed = this.memories.remove(tag);
|
|
105
|
+
if (removed) {
|
|
106
|
+
// Note: We don't delete from database here - that's a design decision
|
|
107
|
+
// The memory stays in DB for audit/history, but is removed from active set
|
|
108
|
+
// If you want to actually delete, call removeById() instead
|
|
109
|
+
}
|
|
110
|
+
return removed;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Removes a memory by ID (removes all instances).
|
|
114
|
+
* Also deletes from database.
|
|
115
|
+
*
|
|
116
|
+
* @param memoryId - Memory ID to remove
|
|
117
|
+
* @returns Number of instances removed
|
|
118
|
+
*/
|
|
119
|
+
async removeById(memoryId) {
|
|
120
|
+
// Remove from ORSet
|
|
121
|
+
const entries = this.memories.entries();
|
|
122
|
+
let count = 0;
|
|
123
|
+
for (const [tag, id] of entries) {
|
|
124
|
+
if (id === memoryId) {
|
|
125
|
+
this.memories.remove(tag);
|
|
126
|
+
count++;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// Delete from vector database
|
|
130
|
+
if (count > 0) {
|
|
131
|
+
await this.vectorService.delete(memoryId);
|
|
132
|
+
this.memoryCache.delete(memoryId);
|
|
133
|
+
}
|
|
134
|
+
return count;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Gets all memory IDs in the set.
|
|
138
|
+
*
|
|
139
|
+
* @returns Array of memory IDs
|
|
140
|
+
*/
|
|
141
|
+
getMemoryIds() {
|
|
142
|
+
return this.memories.values();
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Gets all memories (loads from database if not cached).
|
|
146
|
+
*
|
|
147
|
+
* @returns Array of memory objects
|
|
148
|
+
*/
|
|
149
|
+
async getAll() {
|
|
150
|
+
const ids = this.memories.values();
|
|
151
|
+
const memories = [];
|
|
152
|
+
for (const id of ids) {
|
|
153
|
+
// Check cache first
|
|
154
|
+
const cached = this.memoryCache.get(id);
|
|
155
|
+
if (cached) {
|
|
156
|
+
memories.push(cached);
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
// Load from vector database
|
|
160
|
+
const memory = await this.vectorService.getById(id);
|
|
161
|
+
if (memory) {
|
|
162
|
+
this.memoryCache.set(id, memory);
|
|
163
|
+
memories.push(memory);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return memories;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Gets a specific memory by ID.
|
|
170
|
+
*
|
|
171
|
+
* @param memoryId - Memory ID
|
|
172
|
+
* @returns Memory or null if not found
|
|
173
|
+
*/
|
|
174
|
+
async get(memoryId) {
|
|
175
|
+
// Check cache
|
|
176
|
+
const cached = this.memoryCache.get(memoryId);
|
|
177
|
+
if (cached) {
|
|
178
|
+
return cached;
|
|
179
|
+
}
|
|
180
|
+
// Check if in ORSet
|
|
181
|
+
if (!this.memories.values().includes(memoryId)) {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
// Load from vector database
|
|
185
|
+
const memory = await this.vectorService.getById(memoryId);
|
|
186
|
+
if (memory) {
|
|
187
|
+
this.memoryCache.set(memoryId, memory);
|
|
188
|
+
return memory;
|
|
189
|
+
}
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Updates a memory by ID.
|
|
194
|
+
* Merges partial data with the current memory, persists to vector store,
|
|
195
|
+
* and refreshes the cache. Eliminates the need for callers to access
|
|
196
|
+
* private fields or instantiate VectorMemoryService directly.
|
|
197
|
+
*
|
|
198
|
+
* @param memoryId - Memory ID to update
|
|
199
|
+
* @param data - Partial memory data to merge
|
|
200
|
+
* @returns Updated memory
|
|
201
|
+
* @throws Error if memory not found in this user's ORSet
|
|
202
|
+
*/
|
|
203
|
+
async update(memoryId, data) {
|
|
204
|
+
if (!this.memories.values().includes(memoryId)) {
|
|
205
|
+
throw new Error(`Memory not found: ${memoryId}`);
|
|
206
|
+
}
|
|
207
|
+
const current = this.memoryCache.get(memoryId) ?? (await this.vectorService.getById(memoryId));
|
|
208
|
+
if (!current) {
|
|
209
|
+
throw new Error(`Memory not found in store: ${memoryId}`);
|
|
210
|
+
}
|
|
211
|
+
const merged = { ...current, ...data, id: memoryId };
|
|
212
|
+
const updated = await this.vectorService.update(memoryId, merged);
|
|
213
|
+
this.memoryCache.set(memoryId, updated);
|
|
214
|
+
return updated;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Increments access counter and updates memory access tracking.
|
|
218
|
+
*
|
|
219
|
+
* @param memoryId - Optional memory ID to track access for
|
|
220
|
+
*/
|
|
221
|
+
async incrementAccess(memoryId) {
|
|
222
|
+
this.accessCounter.increment();
|
|
223
|
+
if (memoryId) {
|
|
224
|
+
// Get current memory
|
|
225
|
+
const memory = await this.get(memoryId);
|
|
226
|
+
if (memory) {
|
|
227
|
+
// Update access count in vector database
|
|
228
|
+
await this.vectorService.update(memoryId, {
|
|
229
|
+
accessCount: (memory.accessCount || 0) + 1,
|
|
230
|
+
accessedAt: new Date().toISOString(),
|
|
231
|
+
});
|
|
232
|
+
// Update cache
|
|
233
|
+
const cached = this.memoryCache.get(memoryId);
|
|
234
|
+
if (cached) {
|
|
235
|
+
cached.accessCount = (cached.accessCount || 0) + 1;
|
|
236
|
+
cached.accessedAt = new Date().toISOString();
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Gets the total access count.
|
|
243
|
+
*
|
|
244
|
+
* @returns Total access count
|
|
245
|
+
*/
|
|
246
|
+
getAccessCount() {
|
|
247
|
+
return this.accessCounter.value();
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Searches memories using vector similarity search.
|
|
251
|
+
*
|
|
252
|
+
* @param query - Search query text
|
|
253
|
+
* @param options - Search options (limit, threshold, filters)
|
|
254
|
+
* @returns Array of matching memories sorted by relevance
|
|
255
|
+
*/
|
|
256
|
+
async search(query, options = {}) {
|
|
257
|
+
try {
|
|
258
|
+
// Generate embedding for the search query
|
|
259
|
+
const embedding = await generateEmbedding(query);
|
|
260
|
+
// Search for similar memories using vector search
|
|
261
|
+
const results = await this.vectorService.searchSimilar(embedding.vector, {
|
|
262
|
+
...options,
|
|
263
|
+
limit: options.limit ?? 10,
|
|
264
|
+
threshold: options.threshold ?? 0.5,
|
|
265
|
+
});
|
|
266
|
+
// Return memories sorted by similarity
|
|
267
|
+
return results.map((r) => r.memory);
|
|
268
|
+
}
|
|
269
|
+
catch (_error) {
|
|
270
|
+
// Embedding generation failed (e.g. embedding service unavailable).
|
|
271
|
+
// Return empty results — do NOT fall back to getAll(), which would dump the
|
|
272
|
+
// entire memory store into agent context regardless of relevance.
|
|
273
|
+
return [];
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Merges another EpisodicMemory into this one.
|
|
278
|
+
*
|
|
279
|
+
* @param other - EpisodicMemory to merge
|
|
280
|
+
* @returns New merged EpisodicMemory
|
|
281
|
+
*/
|
|
282
|
+
merge(other) {
|
|
283
|
+
const merged = new EpisodicMemory(this.userId, this.nodeId, this.db, this.persistence);
|
|
284
|
+
merged.memories = this.memories.merge(other.memories);
|
|
285
|
+
merged.accessCounter = this.accessCounter.merge(other.accessCounter);
|
|
286
|
+
return merged;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Loads state from database.
|
|
290
|
+
*
|
|
291
|
+
* @throws Error if persistence is not configured
|
|
292
|
+
*/
|
|
293
|
+
async load() {
|
|
294
|
+
if (!this.persistence) {
|
|
295
|
+
throw new Error('Persistence not configured. Pass persistence to constructor.');
|
|
296
|
+
}
|
|
297
|
+
const crdtId = `episodic-memory:${this.userId}`;
|
|
298
|
+
const states = await this.persistence.loadCompositeState(crdtId);
|
|
299
|
+
// Restore memories ORSet
|
|
300
|
+
const memoriesData = states.get('or_set:memories');
|
|
301
|
+
if (memoriesData && 'added' in memoriesData) {
|
|
302
|
+
this.memories = ORSet.fromData(memoriesData);
|
|
303
|
+
}
|
|
304
|
+
// Restore access counter
|
|
305
|
+
const counterData = states.get('pn_counter:access');
|
|
306
|
+
if (counterData && 'increments' in counterData) {
|
|
307
|
+
this.accessCounter = PNCounter.fromData(counterData);
|
|
308
|
+
}
|
|
309
|
+
// Preload memory cache
|
|
310
|
+
const ids = this.memories.values();
|
|
311
|
+
for (const id of ids.slice(0, 100)) {
|
|
312
|
+
// Load first 100 into cache
|
|
313
|
+
await this.get(id);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Saves state to database.
|
|
318
|
+
*
|
|
319
|
+
* @throws Error if persistence is not configured
|
|
320
|
+
*/
|
|
321
|
+
async save() {
|
|
322
|
+
if (!this.persistence) {
|
|
323
|
+
throw new Error('Persistence not configured. Pass persistence to constructor.');
|
|
324
|
+
}
|
|
325
|
+
const crdtId = `episodic-memory:${this.userId}`;
|
|
326
|
+
const states = new Map();
|
|
327
|
+
states.set('or_set:memories', this.memories.toData());
|
|
328
|
+
states.set('pn_counter:access', this.accessCounter.toData());
|
|
329
|
+
await this.persistence.saveCompositeState(crdtId, states);
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Serializes EpisodicMemory to plain object.
|
|
333
|
+
*
|
|
334
|
+
* @returns Serialized data
|
|
335
|
+
*/
|
|
336
|
+
toData() {
|
|
337
|
+
return {
|
|
338
|
+
userId: this.userId,
|
|
339
|
+
nodeId: this.nodeId,
|
|
340
|
+
memories: this.memories.toData(),
|
|
341
|
+
accessCounter: this.accessCounter.toData(),
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Deserializes EpisodicMemory from plain object.
|
|
346
|
+
*
|
|
347
|
+
* @param data - Serialized data
|
|
348
|
+
* @param db - Database client
|
|
349
|
+
* @param persistence - Optional persistence adapter
|
|
350
|
+
* @returns New EpisodicMemory instance
|
|
351
|
+
*/
|
|
352
|
+
static fromData(data, db, persistence) {
|
|
353
|
+
const memory = new EpisodicMemory(data.userId, data.nodeId, db, persistence);
|
|
354
|
+
memory.memories = ORSet.fromData(data.memories);
|
|
355
|
+
memory.accessCounter = PNCounter.fromData(data.accessCounter);
|
|
356
|
+
return memory;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Creates a copy of this EpisodicMemory.
|
|
360
|
+
*
|
|
361
|
+
* @returns New EpisodicMemory with same state
|
|
362
|
+
*/
|
|
363
|
+
clone() {
|
|
364
|
+
return EpisodicMemory.fromData(this.toData(), this.db, this.persistence);
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Gets the user ID.
|
|
368
|
+
*/
|
|
369
|
+
getUserId() {
|
|
370
|
+
return this.userId;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Gets the node ID.
|
|
374
|
+
*/
|
|
375
|
+
getNodeId() {
|
|
376
|
+
return this.nodeId;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory System implementations
|
|
3
|
+
*
|
|
4
|
+
* Hierarchical memory management for AI agents:
|
|
5
|
+
* - Working Memory: Short-term, session-scoped
|
|
6
|
+
* - Episodic Memory: Conversation history
|
|
7
|
+
* - Semantic Memory: Knowledge base with vector search
|
|
8
|
+
* - Procedural Memory: Workflows and behaviors
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
export { EpisodicMemory, type EpisodicMemoryData } from './episodic-memory.js';
|
|
13
|
+
export { ProceduralMemory, type WorkflowContext, type WorkflowDefinition, type WorkflowResult, type WorkflowStep, } from './procedural-memory.js';
|
|
14
|
+
export { type SemanticEntry, SemanticMemory, type SemanticMemoryOptions, type SemanticSearchResult, } from './semantic-memory.js';
|
|
15
|
+
export { type SessionState, WorkingMemory, type WorkingMemoryData, } from './working-memory.js';
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/memory/stores/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,cAAc,EAAE,KAAK,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAC9E,OAAO,EACL,gBAAgB,EAChB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,YAAY,GAClB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,KAAK,aAAa,EAClB,cAAc,EACd,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,GAC1B,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACL,KAAK,YAAY,EACjB,aAAa,EACb,KAAK,iBAAiB,GACvB,MAAM,qBAAqB,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory System implementations
|
|
3
|
+
*
|
|
4
|
+
* Hierarchical memory management for AI agents:
|
|
5
|
+
* - Working Memory: Short-term, session-scoped
|
|
6
|
+
* - Episodic Memory: Conversation history
|
|
7
|
+
* - Semantic Memory: Knowledge base with vector search
|
|
8
|
+
* - Procedural Memory: Workflows and behaviors
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
export { EpisodicMemory } from './episodic-memory.js';
|
|
13
|
+
export { ProceduralMemory, } from './procedural-memory.js';
|
|
14
|
+
export { SemanticMemory, } from './semantic-memory.js';
|
|
15
|
+
export { WorkingMemory, } from './working-memory.js';
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedural Memory
|
|
3
|
+
*
|
|
4
|
+
* Stores and executes named workflows for AI agents.
|
|
5
|
+
* Workflows are sequences of typed steps that can be run
|
|
6
|
+
* sequentially or in parallel.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const mem = new ProceduralMemory()
|
|
11
|
+
*
|
|
12
|
+
* mem.register('onboard-user', [
|
|
13
|
+
* { id: 'welcome', type: 'action', label: 'Send welcome email',
|
|
14
|
+
* execute: async (ctx) => { ... } },
|
|
15
|
+
* { id: 'create-profile', type: 'action', label: 'Init profile',
|
|
16
|
+
* execute: async (ctx) => { ... } },
|
|
17
|
+
* ])
|
|
18
|
+
*
|
|
19
|
+
* const result = await mem.execute('onboard-user', { userId: 'u1' })
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export interface WorkflowContext {
|
|
23
|
+
[key: string]: unknown;
|
|
24
|
+
}
|
|
25
|
+
export interface WorkflowStep {
|
|
26
|
+
id: string;
|
|
27
|
+
label: string;
|
|
28
|
+
type: 'action' | 'condition' | 'parallel';
|
|
29
|
+
/** True when this step and the next should run concurrently */
|
|
30
|
+
parallel?: boolean;
|
|
31
|
+
execute: (context: WorkflowContext) => Promise<unknown>;
|
|
32
|
+
}
|
|
33
|
+
export interface WorkflowDefinition {
|
|
34
|
+
name: string;
|
|
35
|
+
description?: string;
|
|
36
|
+
steps: WorkflowStep[];
|
|
37
|
+
createdAt: number;
|
|
38
|
+
}
|
|
39
|
+
export interface WorkflowResult {
|
|
40
|
+
workflow: string;
|
|
41
|
+
success: boolean;
|
|
42
|
+
steps: Array<{
|
|
43
|
+
id: string;
|
|
44
|
+
status: 'ok' | 'error';
|
|
45
|
+
result?: unknown;
|
|
46
|
+
error?: string;
|
|
47
|
+
}>;
|
|
48
|
+
durationMs: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Procedural Memory stores named workflow definitions and executes them
|
|
52
|
+
* against a shared context object.
|
|
53
|
+
*/
|
|
54
|
+
export declare class ProceduralMemory {
|
|
55
|
+
private workflows;
|
|
56
|
+
/**
|
|
57
|
+
* Register a new workflow.
|
|
58
|
+
* If a workflow with the same name already exists it is overwritten.
|
|
59
|
+
*/
|
|
60
|
+
register(name: string, steps: WorkflowStep[], description?: string): void;
|
|
61
|
+
/**
|
|
62
|
+
* Unregister a workflow by name.
|
|
63
|
+
*/
|
|
64
|
+
unregister(name: string): void;
|
|
65
|
+
/**
|
|
66
|
+
* Check whether a workflow is registered.
|
|
67
|
+
*/
|
|
68
|
+
has(name: string): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* List all registered workflow names.
|
|
71
|
+
*/
|
|
72
|
+
listWorkflows(): string[];
|
|
73
|
+
/**
|
|
74
|
+
* Get the definition for a registered workflow.
|
|
75
|
+
*/
|
|
76
|
+
getDefinition(name: string): WorkflowDefinition | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Execute a workflow by name.
|
|
79
|
+
*
|
|
80
|
+
* Steps marked `parallel: true` are executed concurrently with the
|
|
81
|
+
* immediately following step(s). All other steps run sequentially.
|
|
82
|
+
*
|
|
83
|
+
* @param name - Registered workflow name
|
|
84
|
+
* @param context - Initial context object passed to each step
|
|
85
|
+
* @throws {Error} If the workflow is not registered
|
|
86
|
+
*/
|
|
87
|
+
execute(name: string, context?: WorkflowContext): Promise<WorkflowResult>;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=procedural-memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"procedural-memory.d.ts","sourceRoot":"","sources":["../../../src/memory/stores/procedural-memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAMH,MAAM,WAAW,eAAe;IAC9B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,QAAQ,GAAG,WAAW,GAAG,UAAU,CAAA;IACzC,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,OAAO,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CACxD;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,YAAY,EAAE,CAAA;IACrB,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,IAAI,GAAG,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IACtF,UAAU,EAAE,MAAM,CAAA;CACnB;AAMD;;;GAGG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,SAAS,CAA6C;IAE9D;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI;IAIzE;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAI9B;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI1B;;OAEG;IACH,aAAa,IAAI,MAAM,EAAE;IAIzB;;OAEG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS;IAI3D;;;;;;;;;OASG;IACG,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,cAAc,CAAC;CA4DpF"}
|