@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,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Context Manager
|
|
3
|
+
*
|
|
4
|
+
* Wraps WorkingMemory for agent context management.
|
|
5
|
+
* Provides a higher-level API for managing agent contexts with CRDT support.
|
|
6
|
+
*/
|
|
7
|
+
import type { Database } from '@revealui/db/client';
|
|
8
|
+
import type { CRDTPersistence } from '../persistence/crdt-persistence.js';
|
|
9
|
+
import { WorkingMemory } from '../stores/working-memory.js';
|
|
10
|
+
/**
|
|
11
|
+
* Manages agent context with CRDT support.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const manager = new AgentContextManager('session-123', 'agent-456', 'node-abc', db, persistence)
|
|
16
|
+
* await manager.sync()
|
|
17
|
+
*
|
|
18
|
+
* await manager.setContext('theme', 'dark')
|
|
19
|
+
* const theme = manager.getContext('theme')
|
|
20
|
+
*
|
|
21
|
+
* await manager.save()
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare class AgentContextManager {
|
|
25
|
+
private workingMemory;
|
|
26
|
+
private sessionId;
|
|
27
|
+
private agentId;
|
|
28
|
+
private nodeId;
|
|
29
|
+
private db;
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new AgentContextManager.
|
|
32
|
+
*
|
|
33
|
+
* @param sessionId - Session identifier
|
|
34
|
+
* @param agentId - Agent identifier
|
|
35
|
+
* @param nodeId - Node identifier (for CRDT operations)
|
|
36
|
+
* @param db - Database client
|
|
37
|
+
* @param persistence - Optional persistence adapter
|
|
38
|
+
*/
|
|
39
|
+
constructor(sessionId: string, agentId: string, nodeId: string, db: Database, persistence?: CRDTPersistence);
|
|
40
|
+
/**
|
|
41
|
+
* Sets a context value.
|
|
42
|
+
*
|
|
43
|
+
* @param key - Context key
|
|
44
|
+
* @param value - Context value
|
|
45
|
+
*/
|
|
46
|
+
/**
|
|
47
|
+
* Sets a context key-value pair.
|
|
48
|
+
*
|
|
49
|
+
* **Validation**: Validates key and value before setting to prevent security issues.
|
|
50
|
+
*
|
|
51
|
+
* @param key - The context key
|
|
52
|
+
* @param value - The context value
|
|
53
|
+
* @throws ValidationError if key or value is invalid
|
|
54
|
+
*/
|
|
55
|
+
setContext(key: string, value: unknown): void;
|
|
56
|
+
/**
|
|
57
|
+
* Gets a context value.
|
|
58
|
+
*
|
|
59
|
+
* @param key - Context key
|
|
60
|
+
* @returns Context value or undefined
|
|
61
|
+
*/
|
|
62
|
+
getContext(key: string): unknown;
|
|
63
|
+
/**
|
|
64
|
+
* Gets all context.
|
|
65
|
+
*
|
|
66
|
+
* @returns Context object
|
|
67
|
+
*/
|
|
68
|
+
getAllContext(): Record<string, unknown>;
|
|
69
|
+
/**
|
|
70
|
+
* Sets entire context object.
|
|
71
|
+
*
|
|
72
|
+
* @param context - Context object
|
|
73
|
+
*/
|
|
74
|
+
setAllContext(context: Record<string, unknown>): void;
|
|
75
|
+
/**
|
|
76
|
+
* Updates context with partial data.
|
|
77
|
+
*
|
|
78
|
+
* @param updates - Partial context updates
|
|
79
|
+
*/
|
|
80
|
+
/**
|
|
81
|
+
* Updates multiple context keys at once.
|
|
82
|
+
*
|
|
83
|
+
* **Validation**: Validates all keys and values before updating.
|
|
84
|
+
*
|
|
85
|
+
* @param updates - Object with key-value pairs to update
|
|
86
|
+
* @throws ValidationError if any key or value is invalid
|
|
87
|
+
*/
|
|
88
|
+
updateContext(updates: Partial<Record<string, unknown>>): void;
|
|
89
|
+
/**
|
|
90
|
+
* Merges context from another source (for syncing with remote state).
|
|
91
|
+
* Uses CRDT merge for conflict resolution at the key level.
|
|
92
|
+
*
|
|
93
|
+
* Note: Since LWWRegister works at the object level, we merge the context
|
|
94
|
+
* objects manually to preserve non-conflicting keys from both sides.
|
|
95
|
+
* For conflicting keys, we use LWW semantics with proper timestamps.
|
|
96
|
+
*
|
|
97
|
+
* IMPORTANT: Nested objects are merged at the top level only. If both local
|
|
98
|
+
* and remote have the same key with object values, the entire object is
|
|
99
|
+
* replaced (LWW semantics), not deep-merged. For example:
|
|
100
|
+
* - Local: { user: { name: 'Alice', age: 30 } }
|
|
101
|
+
* - Remote: { user: { name: 'Bob', city: 'NYC' } }
|
|
102
|
+
* - Result: { user: { name: 'Bob', city: 'NYC' } } (remote wins, age is lost)
|
|
103
|
+
*
|
|
104
|
+
* @param remoteContext - Context to merge from (must be a plain object)
|
|
105
|
+
* @throws ValidationError if remoteContext is not a valid object
|
|
106
|
+
*/
|
|
107
|
+
mergeContext(remoteContext: Record<string, unknown>): Promise<void>;
|
|
108
|
+
/**
|
|
109
|
+
* Removes a context key.
|
|
110
|
+
*
|
|
111
|
+
* @param key - Context key to remove
|
|
112
|
+
*/
|
|
113
|
+
removeContext(key: string): void;
|
|
114
|
+
/**
|
|
115
|
+
* Syncs with database.
|
|
116
|
+
* Loads existing context, merges with local state, saves back.
|
|
117
|
+
*
|
|
118
|
+
* @throws Error if persistence is not configured
|
|
119
|
+
*/
|
|
120
|
+
sync(): Promise<void>;
|
|
121
|
+
/**
|
|
122
|
+
* Saves context to database.
|
|
123
|
+
*
|
|
124
|
+
* @throws Error if persistence is not configured
|
|
125
|
+
*/
|
|
126
|
+
save(): Promise<void>;
|
|
127
|
+
/**
|
|
128
|
+
* Loads context from database.
|
|
129
|
+
*
|
|
130
|
+
* @throws Error if persistence is not configured
|
|
131
|
+
*/
|
|
132
|
+
load(): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Gets the underlying WorkingMemory instance.
|
|
135
|
+
*
|
|
136
|
+
* @returns WorkingMemory instance
|
|
137
|
+
*/
|
|
138
|
+
getWorkingMemory(): WorkingMemory;
|
|
139
|
+
/**
|
|
140
|
+
* Gets session ID.
|
|
141
|
+
*/
|
|
142
|
+
getSessionId(): string;
|
|
143
|
+
/**
|
|
144
|
+
* Gets agent ID.
|
|
145
|
+
*/
|
|
146
|
+
getAgentId(): string;
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=context-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-manager.d.ts","sourceRoot":"","sources":["../../../src/memory/agent/context-manager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAGnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAA;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAa3D;;;;;;;;;;;;;GAaG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,aAAa,CAAe;IACpC,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,EAAE,CAAU;IAEpB;;;;;;;;OAQG;gBAED,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,QAAQ,EACZ,WAAW,CAAC,EAAE,eAAe;IAS/B;;;;;OAKG;IACH;;;;;;;;OAQG;IACH,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI;IAM7C;;;;;OAKG;IACH,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIhC;;;;OAIG;IACH,aAAa,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAIxC;;;;OAIG;IACH,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAIrD;;;;OAIG;IACH;;;;;;;OAOG;IACH,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,IAAI;IAe9D;;;;;;;;;;;;;;;;;OAiBG;IACG,YAAY,CAAC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IA6FzE;;;;OAIG;IACH,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAOhC;;;;;OAKG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IA+B3B;;;;OAIG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B;;;;OAIG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B;;;;OAIG;IACH,gBAAgB,IAAI,aAAa;IAIjC;;OAEG;IACH,YAAY,IAAI,MAAM;IAItB;;OAEG;IACH,UAAU,IAAI,MAAM;CAGrB"}
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Context Manager
|
|
3
|
+
*
|
|
4
|
+
* Wraps WorkingMemory for agent context management.
|
|
5
|
+
* Provides a higher-level API for managing agent contexts with CRDT support.
|
|
6
|
+
*/
|
|
7
|
+
import { LWWRegister } from '../crdt/lww-register.js';
|
|
8
|
+
import { MemoryError, MigrationError, ValidationError } from '../errors/index.js';
|
|
9
|
+
import { WorkingMemory } from '../stores/working-memory.js';
|
|
10
|
+
import { findAgentContextById } from '../utils/sql-helpers.js';
|
|
11
|
+
import { hasCircularReference, validateContext, validateContextKey, validateContextValue, } from '../utils/validation.js';
|
|
12
|
+
// =============================================================================
|
|
13
|
+
// Agent Context Manager
|
|
14
|
+
// =============================================================================
|
|
15
|
+
/**
|
|
16
|
+
* Manages agent context with CRDT support.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const manager = new AgentContextManager('session-123', 'agent-456', 'node-abc', db, persistence)
|
|
21
|
+
* await manager.sync()
|
|
22
|
+
*
|
|
23
|
+
* await manager.setContext('theme', 'dark')
|
|
24
|
+
* const theme = manager.getContext('theme')
|
|
25
|
+
*
|
|
26
|
+
* await manager.save()
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export class AgentContextManager {
|
|
30
|
+
workingMemory;
|
|
31
|
+
sessionId;
|
|
32
|
+
agentId;
|
|
33
|
+
nodeId;
|
|
34
|
+
db;
|
|
35
|
+
/**
|
|
36
|
+
* Creates a new AgentContextManager.
|
|
37
|
+
*
|
|
38
|
+
* @param sessionId - Session identifier
|
|
39
|
+
* @param agentId - Agent identifier
|
|
40
|
+
* @param nodeId - Node identifier (for CRDT operations)
|
|
41
|
+
* @param db - Database client
|
|
42
|
+
* @param persistence - Optional persistence adapter
|
|
43
|
+
*/
|
|
44
|
+
constructor(sessionId, agentId, nodeId, db, persistence) {
|
|
45
|
+
this.sessionId = sessionId;
|
|
46
|
+
this.agentId = agentId;
|
|
47
|
+
this.nodeId = nodeId;
|
|
48
|
+
this.db = db;
|
|
49
|
+
this.workingMemory = new WorkingMemory(sessionId, nodeId, persistence);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Sets a context value.
|
|
53
|
+
*
|
|
54
|
+
* @param key - Context key
|
|
55
|
+
* @param value - Context value
|
|
56
|
+
*/
|
|
57
|
+
/**
|
|
58
|
+
* Sets a context key-value pair.
|
|
59
|
+
*
|
|
60
|
+
* **Validation**: Validates key and value before setting to prevent security issues.
|
|
61
|
+
*
|
|
62
|
+
* @param key - The context key
|
|
63
|
+
* @param value - The context value
|
|
64
|
+
* @throws ValidationError if key or value is invalid
|
|
65
|
+
*/
|
|
66
|
+
setContext(key, value) {
|
|
67
|
+
validateContextKey(key);
|
|
68
|
+
validateContextValue(value, key);
|
|
69
|
+
this.workingMemory.setContextValue(key, value);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Gets a context value.
|
|
73
|
+
*
|
|
74
|
+
* @param key - Context key
|
|
75
|
+
* @returns Context value or undefined
|
|
76
|
+
*/
|
|
77
|
+
getContext(key) {
|
|
78
|
+
return this.workingMemory.getContextValue(key);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Gets all context.
|
|
82
|
+
*
|
|
83
|
+
* @returns Context object
|
|
84
|
+
*/
|
|
85
|
+
getAllContext() {
|
|
86
|
+
return this.workingMemory.getContext();
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Sets entire context object.
|
|
90
|
+
*
|
|
91
|
+
* @param context - Context object
|
|
92
|
+
*/
|
|
93
|
+
setAllContext(context) {
|
|
94
|
+
this.workingMemory.setContext(context);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Updates context with partial data.
|
|
98
|
+
*
|
|
99
|
+
* @param updates - Partial context updates
|
|
100
|
+
*/
|
|
101
|
+
/**
|
|
102
|
+
* Updates multiple context keys at once.
|
|
103
|
+
*
|
|
104
|
+
* **Validation**: Validates all keys and values before updating.
|
|
105
|
+
*
|
|
106
|
+
* @param updates - Object with key-value pairs to update
|
|
107
|
+
* @throws ValidationError if any key or value is invalid
|
|
108
|
+
*/
|
|
109
|
+
updateContext(updates) {
|
|
110
|
+
// Validate all keys and values before updating
|
|
111
|
+
for (const [key, value] of Object.entries(updates)) {
|
|
112
|
+
validateContextKey(key);
|
|
113
|
+
validateContextValue(value, key);
|
|
114
|
+
}
|
|
115
|
+
// Check for circular references in the updates object
|
|
116
|
+
if (hasCircularReference(updates)) {
|
|
117
|
+
throw new ValidationError('Updates object contains circular references');
|
|
118
|
+
}
|
|
119
|
+
this.workingMemory.updateContext(updates);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Merges context from another source (for syncing with remote state).
|
|
123
|
+
* Uses CRDT merge for conflict resolution at the key level.
|
|
124
|
+
*
|
|
125
|
+
* Note: Since LWWRegister works at the object level, we merge the context
|
|
126
|
+
* objects manually to preserve non-conflicting keys from both sides.
|
|
127
|
+
* For conflicting keys, we use LWW semantics with proper timestamps.
|
|
128
|
+
*
|
|
129
|
+
* IMPORTANT: Nested objects are merged at the top level only. If both local
|
|
130
|
+
* and remote have the same key with object values, the entire object is
|
|
131
|
+
* replaced (LWW semantics), not deep-merged. For example:
|
|
132
|
+
* - Local: { user: { name: 'Alice', age: 30 } }
|
|
133
|
+
* - Remote: { user: { name: 'Bob', city: 'NYC' } }
|
|
134
|
+
* - Result: { user: { name: 'Bob', city: 'NYC' } } (remote wins, age is lost)
|
|
135
|
+
*
|
|
136
|
+
* @param remoteContext - Context to merge from (must be a plain object)
|
|
137
|
+
* @throws ValidationError if remoteContext is not a valid object
|
|
138
|
+
*/
|
|
139
|
+
async mergeContext(remoteContext) {
|
|
140
|
+
try {
|
|
141
|
+
// Validate input
|
|
142
|
+
if (!remoteContext || typeof remoteContext !== 'object' || Array.isArray(remoteContext)) {
|
|
143
|
+
throw new ValidationError(`remoteContext must be a plain object, got: ${typeof remoteContext}`);
|
|
144
|
+
}
|
|
145
|
+
// Early return for empty merge (no-op)
|
|
146
|
+
if (Object.keys(remoteContext).length === 0) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
// Validate remote context (security and performance checks)
|
|
150
|
+
try {
|
|
151
|
+
validateContext(remoteContext);
|
|
152
|
+
}
|
|
153
|
+
catch (validationError) {
|
|
154
|
+
throw new ValidationError(`Invalid remote context: ${validationError instanceof Error ? validationError.message : String(validationError)}`);
|
|
155
|
+
}
|
|
156
|
+
// Check for circular references (deepClone will throw, but we want a better error)
|
|
157
|
+
if (hasCircularReference(remoteContext)) {
|
|
158
|
+
throw new ValidationError('Remote context contains circular references, which are not supported');
|
|
159
|
+
}
|
|
160
|
+
// Load current state
|
|
161
|
+
await this.workingMemory.load();
|
|
162
|
+
// Get current context and actual timestamp from the register
|
|
163
|
+
const currentContext = this.workingMemory.getContext();
|
|
164
|
+
const currentTimestamp = this.workingMemory.getContextTimestamp();
|
|
165
|
+
const now = Date.now();
|
|
166
|
+
// Ensure remote timestamp is always later than current to simulate remote update
|
|
167
|
+
// This ensures remote values win in conflicts (last-writer-wins semantics)
|
|
168
|
+
const remoteTimestamp = Math.max(currentTimestamp + 1, now);
|
|
169
|
+
// Merge objects at key level to preserve all non-conflicting keys
|
|
170
|
+
const mergedContext = { ...currentContext };
|
|
171
|
+
// Process each remote key
|
|
172
|
+
for (const [key, remoteValue] of Object.entries(remoteContext)) {
|
|
173
|
+
if (!(key in currentContext)) {
|
|
174
|
+
// New key from remote - add it
|
|
175
|
+
mergedContext[key] = remoteValue;
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
// Conflicting key - use LWWRegister to determine winner
|
|
179
|
+
// Create temporary registers for this key with proper timestamps
|
|
180
|
+
const currentValue = currentContext[key];
|
|
181
|
+
// Current value uses the actual context register timestamp
|
|
182
|
+
// This ensures proper CRDT semantics based on when the context was last updated
|
|
183
|
+
const currentKeyReg = new LWWRegister(this.nodeId, currentValue, currentTimestamp);
|
|
184
|
+
// Remote value gets a timestamp guaranteed to be later (simulating remote update)
|
|
185
|
+
const remoteKeyReg = new LWWRegister(`${this.nodeId}-remote`, remoteValue, remoteTimestamp);
|
|
186
|
+
// Merge to get winner (remote will always win due to later timestamp)
|
|
187
|
+
const mergedKeyReg = currentKeyReg.merge(remoteKeyReg);
|
|
188
|
+
mergedContext[key] = mergedKeyReg.get();
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// Update context with merged values
|
|
192
|
+
// Note: setContext() will update the register's timestamp to the current time,
|
|
193
|
+
// which is correct for a merge operation (it represents a new local update
|
|
194
|
+
// that incorporates remote changes, so it should have a new timestamp)
|
|
195
|
+
this.workingMemory.setContext(mergedContext);
|
|
196
|
+
// Save merged state
|
|
197
|
+
await this.workingMemory.save();
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
// Wrap errors with context for better debugging
|
|
201
|
+
if (error instanceof ValidationError || error instanceof MemoryError) {
|
|
202
|
+
throw error; // Re-throw known errors as-is
|
|
203
|
+
}
|
|
204
|
+
throw new MemoryError(`Failed to merge context: ${error instanceof Error ? error.message : String(error)}`, 'MERGE_ERROR', 500);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Removes a context key.
|
|
209
|
+
*
|
|
210
|
+
* @param key - Context key to remove
|
|
211
|
+
*/
|
|
212
|
+
removeContext(key) {
|
|
213
|
+
const current = this.workingMemory.getContext();
|
|
214
|
+
const updated = { ...current };
|
|
215
|
+
Reflect.deleteProperty(updated, key);
|
|
216
|
+
this.workingMemory.setContext(updated);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Syncs with database.
|
|
220
|
+
* Loads existing context, merges with local state, saves back.
|
|
221
|
+
*
|
|
222
|
+
* @throws Error if persistence is not configured
|
|
223
|
+
*/
|
|
224
|
+
async sync() {
|
|
225
|
+
const contextId = `${this.sessionId}:${this.agentId}`;
|
|
226
|
+
// Load existing context from database (using raw SQL for Neon HTTP compatibility)
|
|
227
|
+
const existing = await findAgentContextById(this.db, contextId);
|
|
228
|
+
if (existing) {
|
|
229
|
+
// Load WorkingMemory state
|
|
230
|
+
await this.workingMemory.load();
|
|
231
|
+
// Merge with existing context (if any non-CRDT context exists)
|
|
232
|
+
const existingContext = existing.context || {};
|
|
233
|
+
const crdtData = existingContext._crdt;
|
|
234
|
+
// If there's non-CRDT context, throw error (data migration required)
|
|
235
|
+
if (existingContext && !crdtData) {
|
|
236
|
+
throw new MigrationError(`Agent context found but missing CRDT state. ` +
|
|
237
|
+
`Data migration required. All contexts must use CRDT format. ` +
|
|
238
|
+
`Context ID: ${existing.id}`);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
// No existing context, just load (will initialize empty)
|
|
243
|
+
await this.workingMemory.load();
|
|
244
|
+
}
|
|
245
|
+
// Save merged state
|
|
246
|
+
await this.workingMemory.save();
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Saves context to database.
|
|
250
|
+
*
|
|
251
|
+
* @throws Error if persistence is not configured
|
|
252
|
+
*/
|
|
253
|
+
async save() {
|
|
254
|
+
await this.workingMemory.save();
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Loads context from database.
|
|
258
|
+
*
|
|
259
|
+
* @throws Error if persistence is not configured
|
|
260
|
+
*/
|
|
261
|
+
async load() {
|
|
262
|
+
await this.workingMemory.load();
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Gets the underlying WorkingMemory instance.
|
|
266
|
+
*
|
|
267
|
+
* @returns WorkingMemory instance
|
|
268
|
+
*/
|
|
269
|
+
getWorkingMemory() {
|
|
270
|
+
return this.workingMemory;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Gets session ID.
|
|
274
|
+
*/
|
|
275
|
+
getSessionId() {
|
|
276
|
+
return this.sessionId;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Gets agent ID.
|
|
280
|
+
*/
|
|
281
|
+
getAgentId() {
|
|
282
|
+
return this.agentId;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/memory/agent/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CRDT (Conflict-free Replicated Data Types) implementations
|
|
3
|
+
*
|
|
4
|
+
* These data structures enable eventual consistency in distributed systems
|
|
5
|
+
* without requiring coordination between nodes.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
export { LWWRegister, type LWWRegisterData } from './lww-register.js';
|
|
10
|
+
export { ORSet, type ORSetData, type ORSetEntry } from './or-set.js';
|
|
11
|
+
export { PNCounter, type PNCounterData } from './pn-counter.js';
|
|
12
|
+
export { VectorClock, type VectorClockComparison, type VectorClockData, } from './vector-clock.js';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/memory/crdt/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACrE,OAAO,EAAE,KAAK,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAA;AACpE,OAAO,EAAE,SAAS,EAAE,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/D,OAAO,EACL,WAAW,EACX,KAAK,qBAAqB,EAC1B,KAAK,eAAe,GACrB,MAAM,mBAAmB,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CRDT (Conflict-free Replicated Data Types) implementations
|
|
3
|
+
*
|
|
4
|
+
* These data structures enable eventual consistency in distributed systems
|
|
5
|
+
* without requiring coordination between nodes.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
export { LWWRegister } from './lww-register.js';
|
|
10
|
+
export { ORSet } from './or-set.js';
|
|
11
|
+
export { PNCounter } from './pn-counter.js';
|
|
12
|
+
export { VectorClock, } from './vector-clock.js';
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Last-Writer-Wins Register (LWW-Register)
|
|
3
|
+
*
|
|
4
|
+
* A CRDT that stores a single value where the most recent write wins.
|
|
5
|
+
* Uses timestamps and node IDs to determine ordering when timestamps are equal.
|
|
6
|
+
*
|
|
7
|
+
* IMPORTANT: This register deep clones object/array values to prevent external mutations.
|
|
8
|
+
* Primitives (strings, numbers, booleans, null) are stored as-is for performance.
|
|
9
|
+
*
|
|
10
|
+
* Use cases:
|
|
11
|
+
* - User preferences
|
|
12
|
+
* - Agent configurations
|
|
13
|
+
* - Any single-valued state
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const reg1 = new LWWRegister<string>('node-a', 'initial')
|
|
18
|
+
* const reg2 = new LWWRegister<string>('node-b', 'initial')
|
|
19
|
+
*
|
|
20
|
+
* reg1.set('value-from-a')
|
|
21
|
+
* reg2.set('value-from-b')
|
|
22
|
+
*
|
|
23
|
+
* // Merge resolves to most recent write
|
|
24
|
+
* const merged = reg1.merge(reg2)
|
|
25
|
+
* const value = merged.get() // 'value-from-b' (if reg2 was set later)
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export interface LWWRegisterData<T> {
|
|
29
|
+
value: T;
|
|
30
|
+
timestamp: number;
|
|
31
|
+
nodeId: string;
|
|
32
|
+
version: number;
|
|
33
|
+
}
|
|
34
|
+
export declare class LWWRegister<T> {
|
|
35
|
+
private value;
|
|
36
|
+
private timestamp;
|
|
37
|
+
private nodeId;
|
|
38
|
+
private version;
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new LWW-Register.
|
|
41
|
+
* @param nodeId - Unique identifier for this node
|
|
42
|
+
* @param initialValue - The initial value
|
|
43
|
+
* @param timestamp - Optional initial timestamp (defaults to now)
|
|
44
|
+
*/
|
|
45
|
+
constructor(nodeId: string, initialValue: T, timestamp?: number);
|
|
46
|
+
/**
|
|
47
|
+
* Determines if a value should be deep cloned.
|
|
48
|
+
* Only objects and arrays need cloning; primitives are safe to store directly.
|
|
49
|
+
*/
|
|
50
|
+
private shouldClone;
|
|
51
|
+
/**
|
|
52
|
+
* Sets a new value with the current timestamp.
|
|
53
|
+
* Deep clones object/array values to prevent external mutations.
|
|
54
|
+
* @param value - The new value to set
|
|
55
|
+
* @param timestamp - Optional explicit timestamp (defaults to now)
|
|
56
|
+
*/
|
|
57
|
+
set(value: T, timestamp?: number): void;
|
|
58
|
+
/**
|
|
59
|
+
* Gets the current value.
|
|
60
|
+
* Returns a deep clone of object/array values to prevent external mutations.
|
|
61
|
+
* @returns The current value stored in the register (cloned if object/array)
|
|
62
|
+
*/
|
|
63
|
+
get(): T;
|
|
64
|
+
/**
|
|
65
|
+
* Gets the timestamp of the last update.
|
|
66
|
+
* @returns The timestamp when the value was last set
|
|
67
|
+
*/
|
|
68
|
+
getTimestamp(): number;
|
|
69
|
+
/**
|
|
70
|
+
* Gets the current version number.
|
|
71
|
+
* @returns The number of times this register has been updated
|
|
72
|
+
*/
|
|
73
|
+
getVersion(): number;
|
|
74
|
+
/**
|
|
75
|
+
* Merges another LWW-Register into this one.
|
|
76
|
+
* The value with the most recent timestamp wins.
|
|
77
|
+
* @param other - The register to merge
|
|
78
|
+
* @returns A new merged LWWRegister
|
|
79
|
+
*/
|
|
80
|
+
merge(other: LWWRegister<T>): LWWRegister<T>;
|
|
81
|
+
/**
|
|
82
|
+
* Creates a deep copy of this register.
|
|
83
|
+
* @returns A new LWWRegister with the same state
|
|
84
|
+
*/
|
|
85
|
+
clone(): LWWRegister<T>;
|
|
86
|
+
/**
|
|
87
|
+
* Serializes the register to a plain object.
|
|
88
|
+
* @returns A serializable representation
|
|
89
|
+
*/
|
|
90
|
+
toData(): LWWRegisterData<T>;
|
|
91
|
+
/**
|
|
92
|
+
* Deserializes a register from serialized data.
|
|
93
|
+
* @param data - The serialized register data
|
|
94
|
+
* @returns A new LWWRegister instance
|
|
95
|
+
*/
|
|
96
|
+
static fromData<T>(data: LWWRegisterData<T>): LWWRegister<T>;
|
|
97
|
+
/**
|
|
98
|
+
* Creates a new register with a generated node ID.
|
|
99
|
+
* @param initialValue - The initial value
|
|
100
|
+
* @returns A new LWWRegister with a UUID node ID
|
|
101
|
+
*/
|
|
102
|
+
static create<T>(initialValue: T): LWWRegister<T>;
|
|
103
|
+
/**
|
|
104
|
+
* Returns a string representation for debugging.
|
|
105
|
+
*/
|
|
106
|
+
toString(): string;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=lww-register.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lww-register.d.ts","sourceRoot":"","sources":["../../../src/memory/crdt/lww-register.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAKH,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,KAAK,EAAE,CAAC,CAAA;IACR,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,qBAAa,WAAW,CAAC,CAAC;IACxB,OAAO,CAAC,KAAK,CAAG;IAChB,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,OAAO,CAAQ;IAEvB;;;;;OAKG;gBACS,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,EAAE,SAAS,CAAC,EAAE,MAAM;IAQ/D;;;OAGG;IACH,OAAO,CAAC,WAAW;IAInB;;;;;OAKG;IACH,GAAG,CAAC,KAAK,EAAE,CAAC,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI;IAgBvC;;;;OAIG;IACH,GAAG,IAAI,CAAC;IAKR;;;OAGG;IACH,YAAY,IAAI,MAAM;IAItB;;;OAGG;IACH,UAAU,IAAI,MAAM;IAIpB;;;;;OAKG;IACH,KAAK,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC;IAmB5C;;;OAGG;IACH,KAAK,IAAI,WAAW,CAAC,CAAC,CAAC;IAMvB;;;OAGG;IACH,MAAM,IAAI,eAAe,CAAC,CAAC,CAAC;IAW5B;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC;IAO5D;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC;IAIjD;;OAEG;IACH,QAAQ,IAAI,MAAM;CAGnB"}
|