@ixo/oracle-runtime 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bootstrap/ambient-factory.d.ts +32 -0
- package/dist/bootstrap/ambient-factory.d.ts.map +1 -0
- package/dist/bootstrap/ambient-factory.js +128 -0
- package/dist/bootstrap/create-oracle-app.d.ts +112 -0
- package/dist/bootstrap/create-oracle-app.d.ts.map +1 -0
- package/dist/bootstrap/create-oracle-app.js +530 -0
- package/dist/bootstrap/graceful-shutdown.d.ts +20 -0
- package/dist/bootstrap/graceful-shutdown.d.ts.map +1 -0
- package/dist/bootstrap/graceful-shutdown.js +61 -0
- package/dist/bootstrap/index.d.ts +13 -0
- package/dist/bootstrap/index.d.ts.map +1 -0
- package/dist/bootstrap/index.js +6 -0
- package/dist/bootstrap/inspect.d.ts +74 -0
- package/dist/bootstrap/inspect.d.ts.map +1 -0
- package/dist/bootstrap/inspect.js +111 -0
- package/dist/bootstrap/plugin-loader.d.ts +50 -0
- package/dist/bootstrap/plugin-loader.d.ts.map +1 -0
- package/dist/bootstrap/plugin-loader.js +119 -0
- package/dist/bootstrap/runtime-app-module.d.ts +38 -0
- package/dist/bootstrap/runtime-app-module.d.ts.map +1 -0
- package/dist/bootstrap/runtime-app-module.js +114 -0
- package/dist/bootstrap/schema-composer.d.ts +46 -0
- package/dist/bootstrap/schema-composer.d.ts.map +1 -0
- package/dist/bootstrap/schema-composer.js +65 -0
- package/dist/config/base-env-config.d.ts +31 -0
- package/dist/config/base-env-config.d.ts.map +1 -0
- package/dist/config/base-env-config.js +70 -0
- package/dist/config/base-env-schema.d.ts +77 -0
- package/dist/config/base-env-schema.d.ts.map +1 -0
- package/dist/config/base-env-schema.js +102 -0
- package/dist/events/scoped-emitter.d.ts +33 -0
- package/dist/events/scoped-emitter.d.ts.map +1 -0
- package/dist/events/scoped-emitter.js +32 -0
- package/dist/graph/index.d.ts +8 -0
- package/dist/graph/index.d.ts.map +1 -0
- package/dist/graph/index.js +6 -0
- package/dist/graph/main-agent-types.d.ts +88 -0
- package/dist/graph/main-agent-types.d.ts.map +1 -0
- package/dist/graph/main-agent-types.js +20 -0
- package/dist/graph/main-agent.d.ts +16 -0
- package/dist/graph/main-agent.d.ts.map +1 -0
- package/dist/graph/main-agent.js +251 -0
- package/dist/graph/middlewares/capability-gate-middleware.d.ts +35 -0
- package/dist/graph/middlewares/capability-gate-middleware.d.ts.map +1 -0
- package/dist/graph/middlewares/capability-gate-middleware.js +54 -0
- package/dist/graph/middlewares/index.d.ts +7 -0
- package/dist/graph/middlewares/index.d.ts.map +1 -0
- package/dist/graph/middlewares/index.js +6 -0
- package/dist/graph/middlewares/page-context-middleware.d.ts +23 -0
- package/dist/graph/middlewares/page-context-middleware.d.ts.map +1 -0
- package/dist/graph/middlewares/page-context-middleware.js +68 -0
- package/dist/graph/middlewares/safety-guardrail-middleware.d.ts +26 -0
- package/dist/graph/middlewares/safety-guardrail-middleware.d.ts.map +1 -0
- package/dist/graph/middlewares/safety-guardrail-middleware.js +88 -0
- package/dist/graph/middlewares/summarization-middleware.d.ts +17 -0
- package/dist/graph/middlewares/summarization-middleware.d.ts.map +1 -0
- package/dist/graph/middlewares/summarization-middleware.js +62 -0
- package/dist/graph/middlewares/tool-repetition-guard-middleware.d.ts +24 -0
- package/dist/graph/middlewares/tool-repetition-guard-middleware.d.ts.map +1 -0
- package/dist/graph/middlewares/tool-repetition-guard-middleware.js +112 -0
- package/dist/graph/middlewares/tool-validation-middleware.d.ts +24 -0
- package/dist/graph/middlewares/tool-validation-middleware.d.ts.map +1 -0
- package/dist/graph/middlewares/tool-validation-middleware.js +61 -0
- package/dist/graph/prompt-composer.d.ts +69 -0
- package/dist/graph/prompt-composer.d.ts.map +1 -0
- package/dist/graph/prompt-composer.js +315 -0
- package/dist/graph/state.d.ts +65 -0
- package/dist/graph/state.d.ts.map +1 -0
- package/dist/graph/state.js +60 -0
- package/dist/graph/sub-agent-fallback.d.ts +56 -0
- package/dist/graph/sub-agent-fallback.d.ts.map +1 -0
- package/dist/graph/sub-agent-fallback.js +79 -0
- package/dist/graph/subagent-as-tool.d.ts +77 -0
- package/dist/graph/subagent-as-tool.d.ts.map +1 -0
- package/dist/graph/subagent-as-tool.js +197 -0
- package/dist/graph/wrap-plugin-tool.d.ts +28 -0
- package/dist/graph/wrap-plugin-tool.d.ts.map +1 -0
- package/dist/graph/wrap-plugin-tool.js +30 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/llm/index.d.ts +2 -0
- package/dist/llm/index.d.ts.map +1 -0
- package/dist/llm/index.js +1 -0
- package/dist/llm/llm-provider.d.ts +41 -0
- package/dist/llm/llm-provider.d.ts.map +1 -0
- package/dist/llm/llm-provider.js +130 -0
- package/dist/manifest/index.d.ts +6 -0
- package/dist/manifest/index.d.ts.map +1 -0
- package/dist/manifest/index.js +3 -0
- package/dist/manifest/schema.d.ts +31 -0
- package/dist/manifest/schema.d.ts.map +1 -0
- package/dist/manifest/schema.js +44 -0
- package/dist/manifest/tier1-renderer.d.ts +31 -0
- package/dist/manifest/tier1-renderer.d.ts.map +1 -0
- package/dist/manifest/tier1-renderer.js +68 -0
- package/dist/manifest/validator.d.ts +34 -0
- package/dist/manifest/validator.d.ts.map +1 -0
- package/dist/manifest/validator.js +111 -0
- package/dist/matrix/checkpointer/matrix-upload-utils.d.ts +66 -0
- package/dist/matrix/checkpointer/matrix-upload-utils.d.ts.map +1 -0
- package/dist/matrix/checkpointer/matrix-upload-utils.js +228 -0
- package/dist/matrix/checkpointer/type.d.ts +4 -0
- package/dist/matrix/checkpointer/type.d.ts.map +1 -0
- package/dist/matrix/checkpointer/type.js +1 -0
- package/dist/matrix/checkpointer/user-matrix-sqlite-sync-service.module.d.ts +3 -0
- package/dist/matrix/checkpointer/user-matrix-sqlite-sync-service.module.d.ts.map +1 -0
- package/dist/matrix/checkpointer/user-matrix-sqlite-sync-service.module.js +22 -0
- package/dist/matrix/checkpointer/user-matrix-sqlite-sync-service.service.d.ts +93 -0
- package/dist/matrix/checkpointer/user-matrix-sqlite-sync-service.service.d.ts.map +1 -0
- package/dist/matrix/checkpointer/user-matrix-sqlite-sync-service.service.js +856 -0
- package/dist/matrix/room-membership.d.ts +11 -0
- package/dist/matrix/room-membership.d.ts.map +1 -0
- package/dist/matrix/room-membership.js +33 -0
- package/dist/meta-tools/index.d.ts +28 -0
- package/dist/meta-tools/index.d.ts.map +1 -0
- package/dist/meta-tools/index.js +24 -0
- package/dist/meta-tools/list-capabilities.d.ts +12 -0
- package/dist/meta-tools/list-capabilities.d.ts.map +1 -0
- package/dist/meta-tools/list-capabilities.js +55 -0
- package/dist/meta-tools/load-capability.d.ts +24 -0
- package/dist/meta-tools/load-capability.d.ts.map +1 -0
- package/dist/meta-tools/load-capability.js +82 -0
- package/dist/modules/auth/auth-header.middleware.d.ts +37 -0
- package/dist/modules/auth/auth-header.middleware.d.ts.map +1 -0
- package/dist/modules/auth/auth-header.middleware.js +115 -0
- package/dist/modules/auth/auth.module.d.ts +9 -0
- package/dist/modules/auth/auth.module.d.ts.map +1 -0
- package/dist/modules/auth/auth.module.js +27 -0
- package/dist/modules/auth/index.d.ts +3 -0
- package/dist/modules/auth/index.d.ts.map +1 -0
- package/dist/modules/auth/index.js +2 -0
- package/dist/modules/auth/validate-ucan-delegation.d.ts +31 -0
- package/dist/modules/auth/validate-ucan-delegation.d.ts.map +1 -0
- package/dist/modules/auth/validate-ucan-delegation.js +36 -0
- package/dist/modules/blob-store/blob-store.module.d.ts +10 -0
- package/dist/modules/blob-store/blob-store.module.d.ts.map +1 -0
- package/dist/modules/blob-store/blob-store.module.js +25 -0
- package/dist/modules/blob-store/blob-store.service.d.ts +66 -0
- package/dist/modules/blob-store/blob-store.service.d.ts.map +1 -0
- package/dist/modules/blob-store/blob-store.service.js +108 -0
- package/dist/modules/blob-store/index.d.ts +3 -0
- package/dist/modules/blob-store/index.d.ts.map +1 -0
- package/dist/modules/blob-store/index.js +2 -0
- package/dist/modules/health/health.controller.d.ts +18 -0
- package/dist/modules/health/health.controller.d.ts.map +1 -0
- package/dist/modules/health/health.controller.js +48 -0
- package/dist/modules/health/health.module.d.ts +8 -0
- package/dist/modules/health/health.module.d.ts.map +1 -0
- package/dist/modules/health/health.module.js +21 -0
- package/dist/modules/index.d.ts +8 -0
- package/dist/modules/index.d.ts.map +1 -0
- package/dist/modules/index.js +6 -0
- package/dist/modules/messages/__test-fixtures__/deps.d.ts +41 -0
- package/dist/modules/messages/__test-fixtures__/deps.d.ts.map +1 -0
- package/dist/modules/messages/__test-fixtures__/deps.js +73 -0
- package/dist/modules/messages/__test-fixtures__/fake-agent.d.ts +27 -0
- package/dist/modules/messages/__test-fixtures__/fake-agent.d.ts.map +1 -0
- package/dist/modules/messages/__test-fixtures__/fake-agent.js +41 -0
- package/dist/modules/messages/__test-fixtures__/fake-response.d.ts +29 -0
- package/dist/modules/messages/__test-fixtures__/fake-response.d.ts.map +1 -0
- package/dist/modules/messages/__test-fixtures__/fake-response.js +55 -0
- package/dist/modules/messages/agent-builder.d.ts +64 -0
- package/dist/modules/messages/agent-builder.d.ts.map +1 -0
- package/dist/modules/messages/agent-builder.js +219 -0
- package/dist/modules/messages/batch-invoker.d.ts +36 -0
- package/dist/modules/messages/batch-invoker.d.ts.map +1 -0
- package/dist/modules/messages/batch-invoker.js +58 -0
- package/dist/modules/messages/dto/list-messages.dto.d.ts +4 -0
- package/dist/modules/messages/dto/list-messages.dto.d.ts.map +1 -0
- package/dist/modules/messages/dto/list-messages.dto.js +17 -0
- package/dist/modules/messages/dto/send-message.dto.d.ts +73 -0
- package/dist/modules/messages/dto/send-message.dto.d.ts.map +1 -0
- package/dist/modules/messages/dto/send-message.dto.js +318 -0
- package/dist/modules/messages/file-processing-credit-sink.port.d.ts +20 -0
- package/dist/modules/messages/file-processing-credit-sink.port.d.ts.map +1 -0
- package/dist/modules/messages/file-processing-credit-sink.port.js +1 -0
- package/dist/modules/messages/file-processing.service.d.ts +195 -0
- package/dist/modules/messages/file-processing.service.d.ts.map +1 -0
- package/dist/modules/messages/file-processing.service.js +1278 -0
- package/dist/modules/messages/homeserver-cache.d.ts +11 -0
- package/dist/modules/messages/homeserver-cache.d.ts.map +1 -0
- package/dist/modules/messages/homeserver-cache.js +31 -0
- package/dist/modules/messages/matrix-listener-bridge.d.ts +63 -0
- package/dist/modules/messages/matrix-listener-bridge.d.ts.map +1 -0
- package/dist/modules/messages/matrix-listener-bridge.js +280 -0
- package/dist/modules/messages/messages.controller.d.ts +13 -0
- package/dist/modules/messages/messages.controller.d.ts.map +1 -0
- package/dist/modules/messages/messages.controller.js +95 -0
- package/dist/modules/messages/messages.module.d.ts +3 -0
- package/dist/modules/messages/messages.module.d.ts.map +1 -0
- package/dist/modules/messages/messages.module.js +75 -0
- package/dist/modules/messages/messages.service.d.ts +112 -0
- package/dist/modules/messages/messages.service.d.ts.map +1 -0
- package/dist/modules/messages/messages.service.js +279 -0
- package/dist/modules/messages/oracle-runtime-bundle.d.ts +38 -0
- package/dist/modules/messages/oracle-runtime-bundle.d.ts.map +1 -0
- package/dist/modules/messages/oracle-runtime-bundle.js +40 -0
- package/dist/modules/messages/post-message-syncer.d.ts +30 -0
- package/dist/modules/messages/post-message-syncer.d.ts.map +1 -0
- package/dist/modules/messages/post-message-syncer.js +73 -0
- package/dist/modules/messages/request-preparer.d.ts +53 -0
- package/dist/modules/messages/request-preparer.d.ts.map +1 -0
- package/dist/modules/messages/request-preparer.js +139 -0
- package/dist/modules/messages/sse-stream-runner.d.ts +73 -0
- package/dist/modules/messages/sse-stream-runner.d.ts.map +1 -0
- package/dist/modules/messages/sse-stream-runner.js +352 -0
- package/dist/modules/messages/sse.utils.d.ts +29 -0
- package/dist/modules/messages/sse.utils.d.ts.map +1 -0
- package/dist/modules/messages/sse.utils.js +77 -0
- package/dist/modules/messages/user-context-fetcher.d.ts +41 -0
- package/dist/modules/messages/user-context-fetcher.d.ts.map +1 -0
- package/dist/modules/messages/user-context-fetcher.js +117 -0
- package/dist/modules/secrets/index.d.ts +2 -0
- package/dist/modules/secrets/index.d.ts.map +1 -0
- package/dist/modules/secrets/index.js +1 -0
- package/dist/modules/secrets/secrets.service.d.ts +29 -0
- package/dist/modules/secrets/secrets.service.d.ts.map +1 -0
- package/dist/modules/secrets/secrets.service.js +107 -0
- package/dist/modules/sessions/dto/create-session.dto.d.ts +6 -0
- package/dist/modules/sessions/dto/create-session.dto.d.ts.map +1 -0
- package/dist/modules/sessions/dto/create-session.dto.js +5 -0
- package/dist/modules/sessions/dto/delete-session.dto.d.ts +6 -0
- package/dist/modules/sessions/dto/delete-session.dto.d.ts.map +1 -0
- package/dist/modules/sessions/dto/delete-session.dto.js +5 -0
- package/dist/modules/sessions/dto/list-sessions.dto.d.ts +7 -0
- package/dist/modules/sessions/dto/list-sessions.dto.d.ts.map +1 -0
- package/dist/modules/sessions/dto/list-sessions.dto.js +6 -0
- package/dist/modules/sessions/session-history-processor.service.d.ts +48 -0
- package/dist/modules/sessions/session-history-processor.service.d.ts.map +1 -0
- package/dist/modules/sessions/session-history-processor.service.js +254 -0
- package/dist/modules/sessions/sessions.controller.d.ts +13 -0
- package/dist/modules/sessions/sessions.controller.d.ts.map +1 -0
- package/dist/modules/sessions/sessions.controller.js +113 -0
- package/dist/modules/sessions/sessions.module.d.ts +3 -0
- package/dist/modules/sessions/sessions.module.d.ts.map +1 -0
- package/dist/modules/sessions/sessions.module.js +49 -0
- package/dist/modules/sessions/sessions.service.d.ts +23 -0
- package/dist/modules/sessions/sessions.service.d.ts.map +1 -0
- package/dist/modules/sessions/sessions.service.js +168 -0
- package/dist/modules/subscription/subscription.middleware.d.ts +37 -0
- package/dist/modules/subscription/subscription.middleware.d.ts.map +1 -0
- package/dist/modules/subscription/subscription.middleware.js +141 -0
- package/dist/modules/subscription/subscription.module.d.ts +12 -0
- package/dist/modules/subscription/subscription.module.d.ts.map +1 -0
- package/dist/modules/subscription/subscription.module.js +26 -0
- package/dist/modules/throttler/throttler.module.d.ts +11 -0
- package/dist/modules/throttler/throttler.module.d.ts.map +1 -0
- package/dist/modules/throttler/throttler.module.js +32 -0
- package/dist/modules/ucan/index.d.ts +7 -0
- package/dist/modules/ucan/index.d.ts.map +1 -0
- package/dist/modules/ucan/index.js +6 -0
- package/dist/modules/ucan/ucan.config.d.ts +87 -0
- package/dist/modules/ucan/ucan.config.d.ts.map +1 -0
- package/dist/modules/ucan/ucan.config.js +114 -0
- package/dist/modules/ucan/ucan.module.d.ts +29 -0
- package/dist/modules/ucan/ucan.module.d.ts.map +1 -0
- package/dist/modules/ucan/ucan.module.js +46 -0
- package/dist/modules/ucan/ucan.service.d.ts +129 -0
- package/dist/modules/ucan/ucan.service.d.ts.map +1 -0
- package/dist/modules/ucan/ucan.service.js +582 -0
- package/dist/modules/ws/emitter.d.ts +12 -0
- package/dist/modules/ws/emitter.d.ts.map +1 -0
- package/dist/modules/ws/emitter.js +12 -0
- package/dist/modules/ws/ws.gateway.d.ts +34 -0
- package/dist/modules/ws/ws.gateway.d.ts.map +1 -0
- package/dist/modules/ws/ws.gateway.js +241 -0
- package/dist/modules/ws/ws.module.d.ts +3 -0
- package/dist/modules/ws/ws.module.d.ts.map +1 -0
- package/dist/modules/ws/ws.module.js +21 -0
- package/dist/modules/ws/ws.service.d.ts +25 -0
- package/dist/modules/ws/ws.service.d.ts.map +1 -0
- package/dist/modules/ws/ws.service.js +113 -0
- package/dist/plugin-api/define-plugin.d.ts +19 -0
- package/dist/plugin-api/define-plugin.d.ts.map +1 -0
- package/dist/plugin-api/define-plugin.js +25 -0
- package/dist/plugin-api/oracle-plugin.d.ts +92 -0
- package/dist/plugin-api/oracle-plugin.d.ts.map +1 -0
- package/dist/plugin-api/oracle-plugin.js +15 -0
- package/dist/plugin-api/tool-helper.d.ts +33 -0
- package/dist/plugin-api/tool-helper.d.ts.map +1 -0
- package/dist/plugin-api/tool-helper.js +40 -0
- package/dist/plugin-api/types.d.ts +378 -0
- package/dist/plugin-api/types.d.ts.map +1 -0
- package/dist/plugin-api/types.js +1 -0
- package/dist/plugins/agui/agui-agent.d.ts +10 -0
- package/dist/plugins/agui/agui-agent.d.ts.map +1 -0
- package/dist/plugins/agui/agui-agent.js +110 -0
- package/dist/plugins/agui/agui.plugin.d.ts +16 -0
- package/dist/plugins/agui/agui.plugin.d.ts.map +1 -0
- package/dist/plugins/agui/agui.plugin.js +117 -0
- package/dist/plugins/agui/index.d.ts +3 -0
- package/dist/plugins/agui/index.d.ts.map +1 -0
- package/dist/plugins/agui/index.js +2 -0
- package/dist/plugins/composio/composio-tools.d.ts +59 -0
- package/dist/plugins/composio/composio-tools.d.ts.map +1 -0
- package/dist/plugins/composio/composio-tools.js +88 -0
- package/dist/plugins/composio/composio-ucan.d.ts +14 -0
- package/dist/plugins/composio/composio-ucan.d.ts.map +1 -0
- package/dist/plugins/composio/composio-ucan.js +32 -0
- package/dist/plugins/composio/composio.plugin.d.ts +45 -0
- package/dist/plugins/composio/composio.plugin.d.ts.map +1 -0
- package/dist/plugins/composio/composio.plugin.js +116 -0
- package/dist/plugins/composio/index.d.ts +4 -0
- package/dist/plugins/composio/index.d.ts.map +1 -0
- package/dist/plugins/composio/index.js +3 -0
- package/dist/plugins/credits/claim-processing.module.d.ts +28 -0
- package/dist/plugins/credits/claim-processing.module.d.ts.map +1 -0
- package/dist/plugins/credits/claim-processing.module.js +37 -0
- package/dist/plugins/credits/claim-processing.service.d.ts +92 -0
- package/dist/plugins/credits/claim-processing.service.d.ts.map +1 -0
- package/dist/plugins/credits/claim-processing.service.js +406 -0
- package/dist/plugins/credits/credits-middleware.d.ts +23 -0
- package/dist/plugins/credits/credits-middleware.d.ts.map +1 -0
- package/dist/plugins/credits/credits-middleware.js +154 -0
- package/dist/plugins/credits/credits.plugin.d.ts +55 -0
- package/dist/plugins/credits/credits.plugin.d.ts.map +1 -0
- package/dist/plugins/credits/credits.plugin.js +95 -0
- package/dist/plugins/credits/file-processing-sink.module.d.ts +18 -0
- package/dist/plugins/credits/file-processing-sink.module.d.ts.map +1 -0
- package/dist/plugins/credits/file-processing-sink.module.js +56 -0
- package/dist/plugins/credits/index.d.ts +8 -0
- package/dist/plugins/credits/index.d.ts.map +1 -0
- package/dist/plugins/credits/index.js +7 -0
- package/dist/plugins/credits/subscription-sink.module.d.ts +23 -0
- package/dist/plugins/credits/subscription-sink.module.d.ts.map +1 -0
- package/dist/plugins/credits/subscription-sink.module.js +54 -0
- package/dist/plugins/credits/token-limiter.d.ts +139 -0
- package/dist/plugins/credits/token-limiter.d.ts.map +1 -0
- package/dist/plugins/credits/token-limiter.js +302 -0
- package/dist/plugins/domain-indexer/domain-indexer-agent.d.ts +7 -0
- package/dist/plugins/domain-indexer/domain-indexer-agent.d.ts.map +1 -0
- package/dist/plugins/domain-indexer/domain-indexer-agent.js +48 -0
- package/dist/plugins/domain-indexer/domain-indexer-tools.d.ts +8 -0
- package/dist/plugins/domain-indexer/domain-indexer-tools.d.ts.map +1 -0
- package/dist/plugins/domain-indexer/domain-indexer-tools.js +194 -0
- package/dist/plugins/domain-indexer/domain-indexer.plugin.d.ts +20 -0
- package/dist/plugins/domain-indexer/domain-indexer.plugin.d.ts.map +1 -0
- package/dist/plugins/domain-indexer/domain-indexer.plugin.js +78 -0
- package/dist/plugins/domain-indexer/index.d.ts +2 -0
- package/dist/plugins/domain-indexer/index.d.ts.map +1 -0
- package/dist/plugins/domain-indexer/index.js +1 -0
- package/dist/plugins/editor/apply-sandbox-output.d.ts +33 -0
- package/dist/plugins/editor/apply-sandbox-output.d.ts.map +1 -0
- package/dist/plugins/editor/apply-sandbox-output.js +302 -0
- package/dist/plugins/editor/block-actions.d.ts +84 -0
- package/dist/plugins/editor/block-actions.d.ts.map +1 -0
- package/dist/plugins/editor/block-actions.js +471 -0
- package/dist/plugins/editor/blocknote-helper.d.ts +147 -0
- package/dist/plugins/editor/blocknote-helper.d.ts.map +1 -0
- package/dist/plugins/editor/blocknote-helper.js +542 -0
- package/dist/plugins/editor/blocknote-tools.d.ts +364 -0
- package/dist/plugins/editor/blocknote-tools.d.ts.map +1 -0
- package/dist/plugins/editor/blocknote-tools.js +2123 -0
- package/dist/plugins/editor/editor-agent.d.ts +47 -0
- package/dist/plugins/editor/editor-agent.d.ts.map +1 -0
- package/dist/plugins/editor/editor-agent.js +158 -0
- package/dist/plugins/editor/editor-mx.d.ts +56 -0
- package/dist/plugins/editor/editor-mx.d.ts.map +1 -0
- package/dist/plugins/editor/editor-mx.js +100 -0
- package/dist/plugins/editor/editor.plugin.d.ts +32 -0
- package/dist/plugins/editor/editor.plugin.d.ts.map +1 -0
- package/dist/plugins/editor/editor.plugin.js +189 -0
- package/dist/plugins/editor/index.d.ts +6 -0
- package/dist/plugins/editor/index.d.ts.map +1 -0
- package/dist/plugins/editor/index.js +5 -0
- package/dist/plugins/editor/mint-invocation-tool.d.ts +72 -0
- package/dist/plugins/editor/mint-invocation-tool.d.ts.map +1 -0
- package/dist/plugins/editor/mint-invocation-tool.js +173 -0
- package/dist/plugins/editor/page-functions.d.ts +100 -0
- package/dist/plugins/editor/page-functions.d.ts.map +1 -0
- package/dist/plugins/editor/page-functions.js +317 -0
- package/dist/plugins/editor/page-tools.d.ts +75 -0
- package/dist/plugins/editor/page-tools.d.ts.map +1 -0
- package/dist/plugins/editor/page-tools.js +238 -0
- package/dist/plugins/editor/prompts.d.ts +22 -0
- package/dist/plugins/editor/prompts.d.ts.map +1 -0
- package/dist/plugins/editor/prompts.js +451 -0
- package/dist/plugins/editor/provider.d.ts +101 -0
- package/dist/plugins/editor/provider.d.ts.map +1 -0
- package/dist/plugins/editor/provider.js +249 -0
- package/dist/plugins/editor/standalone-editor-tool.d.ts +17 -0
- package/dist/plugins/editor/standalone-editor-tool.d.ts.map +1 -0
- package/dist/plugins/editor/standalone-editor-tool.js +136 -0
- package/dist/plugins/editor/survey-helpers.d.ts +112 -0
- package/dist/plugins/editor/survey-helpers.d.ts.map +1 -0
- package/dist/plugins/editor/survey-helpers.js +358 -0
- package/dist/plugins/firecrawl/firecrawl-agent.d.ts +7 -0
- package/dist/plugins/firecrawl/firecrawl-agent.d.ts.map +1 -0
- package/dist/plugins/firecrawl/firecrawl-agent.js +84 -0
- package/dist/plugins/firecrawl/firecrawl-tools.d.ts +37 -0
- package/dist/plugins/firecrawl/firecrawl-tools.d.ts.map +1 -0
- package/dist/plugins/firecrawl/firecrawl-tools.js +129 -0
- package/dist/plugins/firecrawl/firecrawl.plugin.d.ts +32 -0
- package/dist/plugins/firecrawl/firecrawl.plugin.d.ts.map +1 -0
- package/dist/plugins/firecrawl/firecrawl.plugin.js +69 -0
- package/dist/plugins/firecrawl/index.d.ts +3 -0
- package/dist/plugins/firecrawl/index.d.ts.map +1 -0
- package/dist/plugins/firecrawl/index.js +2 -0
- package/dist/plugins/index.d.ts +47 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +69 -0
- package/dist/plugins/matrix-group-chats/channel-memory.module.d.ts +7 -0
- package/dist/plugins/matrix-group-chats/channel-memory.module.d.ts.map +1 -0
- package/dist/plugins/matrix-group-chats/channel-memory.module.js +22 -0
- package/dist/plugins/matrix-group-chats/channel-memory.repo.d.ts +62 -0
- package/dist/plugins/matrix-group-chats/channel-memory.repo.d.ts.map +1 -0
- package/dist/plugins/matrix-group-chats/channel-memory.repo.js +311 -0
- package/dist/plugins/matrix-group-chats/channel-memory.service.d.ts +89 -0
- package/dist/plugins/matrix-group-chats/channel-memory.service.d.ts.map +1 -0
- package/dist/plugins/matrix-group-chats/channel-memory.service.js +565 -0
- package/dist/plugins/matrix-group-chats/channel-memory.summarizer.d.ts +18 -0
- package/dist/plugins/matrix-group-chats/channel-memory.summarizer.d.ts.map +1 -0
- package/dist/plugins/matrix-group-chats/channel-memory.summarizer.js +128 -0
- package/dist/plugins/matrix-group-chats/channel-memory.types.d.ts +50 -0
- package/dist/plugins/matrix-group-chats/channel-memory.types.d.ts.map +1 -0
- package/dist/plugins/matrix-group-chats/channel-memory.types.js +2 -0
- package/dist/plugins/matrix-group-chats/guard.d.ts +83 -0
- package/dist/plugins/matrix-group-chats/guard.d.ts.map +1 -0
- package/dist/plugins/matrix-group-chats/guard.js +138 -0
- package/dist/plugins/matrix-group-chats/index.d.ts +59 -0
- package/dist/plugins/matrix-group-chats/index.d.ts.map +1 -0
- package/dist/plugins/matrix-group-chats/index.js +140 -0
- package/dist/plugins/matrix-group-chats/middleware.d.ts +31 -0
- package/dist/plugins/matrix-group-chats/middleware.d.ts.map +1 -0
- package/dist/plugins/matrix-group-chats/middleware.js +186 -0
- package/dist/plugins/matrix-group-chats/power-levels.d.ts +15 -0
- package/dist/plugins/matrix-group-chats/power-levels.d.ts.map +1 -0
- package/dist/plugins/matrix-group-chats/power-levels.js +36 -0
- package/dist/plugins/matrix-group-chats/room-info.d.ts +23 -0
- package/dist/plugins/matrix-group-chats/room-info.d.ts.map +1 -0
- package/dist/plugins/matrix-group-chats/room-info.js +34 -0
- package/dist/plugins/matrix-group-chats/tools.d.ts +8 -0
- package/dist/plugins/matrix-group-chats/tools.d.ts.map +1 -0
- package/dist/plugins/matrix-group-chats/tools.js +154 -0
- package/dist/plugins/memory/index.d.ts +5 -0
- package/dist/plugins/memory/index.d.ts.map +1 -0
- package/dist/plugins/memory/index.js +3 -0
- package/dist/plugins/memory/memory-tools.d.ts +52 -0
- package/dist/plugins/memory/memory-tools.d.ts.map +1 -0
- package/dist/plugins/memory/memory-tools.js +88 -0
- package/dist/plugins/memory/memory-ucan.d.ts +17 -0
- package/dist/plugins/memory/memory-ucan.d.ts.map +1 -0
- package/dist/plugins/memory/memory-ucan.js +43 -0
- package/dist/plugins/memory/memory.plugin.d.ts +51 -0
- package/dist/plugins/memory/memory.plugin.d.ts.map +1 -0
- package/dist/plugins/memory/memory.plugin.js +76 -0
- package/dist/plugins/memory/types.d.ts +75 -0
- package/dist/plugins/memory/types.d.ts.map +1 -0
- package/dist/plugins/memory/types.js +2 -0
- package/dist/plugins/portal/index.d.ts +3 -0
- package/dist/plugins/portal/index.d.ts.map +1 -0
- package/dist/plugins/portal/index.js +2 -0
- package/dist/plugins/portal/portal-agent.d.ts +9 -0
- package/dist/plugins/portal/portal-agent.d.ts.map +1 -0
- package/dist/plugins/portal/portal-agent.js +70 -0
- package/dist/plugins/portal/portal.plugin.d.ts +16 -0
- package/dist/plugins/portal/portal.plugin.d.ts.map +1 -0
- package/dist/plugins/portal/portal.plugin.js +115 -0
- package/dist/plugins/sandbox/index.d.ts +3 -0
- package/dist/plugins/sandbox/index.d.ts.map +1 -0
- package/dist/plugins/sandbox/index.js +2 -0
- package/dist/plugins/sandbox/sandbox-mcp.d.ts +46 -0
- package/dist/plugins/sandbox/sandbox-mcp.d.ts.map +1 -0
- package/dist/plugins/sandbox/sandbox-mcp.js +80 -0
- package/dist/plugins/sandbox/sandbox-write-blob.d.ts +22 -0
- package/dist/plugins/sandbox/sandbox-write-blob.d.ts.map +1 -0
- package/dist/plugins/sandbox/sandbox-write-blob.js +80 -0
- package/dist/plugins/sandbox/sandbox.plugin.d.ts +80 -0
- package/dist/plugins/sandbox/sandbox.plugin.d.ts.map +1 -0
- package/dist/plugins/sandbox/sandbox.plugin.js +204 -0
- package/dist/plugins/skills/index.d.ts +3 -0
- package/dist/plugins/skills/index.d.ts.map +1 -0
- package/dist/plugins/skills/index.js +2 -0
- package/dist/plugins/skills/skills-tools.d.ts +20 -0
- package/dist/plugins/skills/skills-tools.d.ts.map +1 -0
- package/dist/plugins/skills/skills-tools.js +204 -0
- package/dist/plugins/skills/skills-ucan.d.ts +24 -0
- package/dist/plugins/skills/skills-ucan.d.ts.map +1 -0
- package/dist/plugins/skills/skills-ucan.js +28 -0
- package/dist/plugins/skills/skills.plugin.d.ts +37 -0
- package/dist/plugins/skills/skills.plugin.d.ts.map +1 -0
- package/dist/plugins/skills/skills.plugin.js +82 -0
- package/dist/plugins/slack/index.d.ts +4 -0
- package/dist/plugins/slack/index.d.ts.map +1 -0
- package/dist/plugins/slack/index.js +3 -0
- package/dist/plugins/slack/slack.module.d.ts +9 -0
- package/dist/plugins/slack/slack.module.d.ts.map +1 -0
- package/dist/plugins/slack/slack.module.js +27 -0
- package/dist/plugins/slack/slack.plugin.d.ts +30 -0
- package/dist/plugins/slack/slack.plugin.d.ts.map +1 -0
- package/dist/plugins/slack/slack.plugin.js +40 -0
- package/dist/plugins/slack/slack.service.d.ts +32 -0
- package/dist/plugins/slack/slack.service.d.ts.map +1 -0
- package/dist/plugins/slack/slack.service.js +157 -0
- package/dist/plugins/user-preferences/index.d.ts +4 -0
- package/dist/plugins/user-preferences/index.d.ts.map +1 -0
- package/dist/plugins/user-preferences/index.js +3 -0
- package/dist/plugins/user-preferences/service/user-preferences.service.d.ts +61 -0
- package/dist/plugins/user-preferences/service/user-preferences.service.d.ts.map +1 -0
- package/dist/plugins/user-preferences/service/user-preferences.service.js +105 -0
- package/dist/plugins/user-preferences/user-preferences-http.module.d.ts +10 -0
- package/dist/plugins/user-preferences/user-preferences-http.module.d.ts.map +1 -0
- package/dist/plugins/user-preferences/user-preferences-http.module.js +23 -0
- package/dist/plugins/user-preferences/user-preferences-tool.d.ts +22 -0
- package/dist/plugins/user-preferences/user-preferences-tool.d.ts.map +1 -0
- package/dist/plugins/user-preferences/user-preferences-tool.js +103 -0
- package/dist/plugins/user-preferences/user-preferences.controller.d.ts +18 -0
- package/dist/plugins/user-preferences/user-preferences.controller.d.ts.map +1 -0
- package/dist/plugins/user-preferences/user-preferences.controller.js +72 -0
- package/dist/plugins/user-preferences/user-preferences.plugin.d.ts +27 -0
- package/dist/plugins/user-preferences/user-preferences.plugin.d.ts.map +1 -0
- package/dist/plugins/user-preferences/user-preferences.plugin.js +66 -0
- package/dist/registries/config-schema-registry.d.ts +24 -0
- package/dist/registries/config-schema-registry.d.ts.map +1 -0
- package/dist/registries/config-schema-registry.js +27 -0
- package/dist/registries/index.d.ts +13 -0
- package/dist/registries/index.d.ts.map +1 -0
- package/dist/registries/index.js +6 -0
- package/dist/registries/manifest-registry.d.ts +49 -0
- package/dist/registries/manifest-registry.d.ts.map +1 -0
- package/dist/registries/manifest-registry.js +53 -0
- package/dist/registries/middleware-registry.d.ts +41 -0
- package/dist/registries/middleware-registry.d.ts.map +1 -0
- package/dist/registries/middleware-registry.js +52 -0
- package/dist/registries/shared-state-registry.d.ts +41 -0
- package/dist/registries/shared-state-registry.d.ts.map +1 -0
- package/dist/registries/shared-state-registry.js +65 -0
- package/dist/registries/subagent-registry.d.ts +55 -0
- package/dist/registries/subagent-registry.d.ts.map +1 -0
- package/dist/registries/subagent-registry.js +106 -0
- package/dist/registries/test-fixtures.d.ts +47 -0
- package/dist/registries/test-fixtures.d.ts.map +1 -0
- package/dist/registries/test-fixtures.js +168 -0
- package/dist/registries/tool-registry.d.ts +74 -0
- package/dist/registries/tool-registry.d.ts.map +1 -0
- package/dist/registries/tool-registry.js +130 -0
- package/dist/runtime-context/ambient.d.ts +118 -0
- package/dist/runtime-context/ambient.d.ts.map +1 -0
- package/dist/runtime-context/ambient.js +1 -0
- package/dist/runtime-context/build-plugin.d.ts +20 -0
- package/dist/runtime-context/build-plugin.d.ts.map +1 -0
- package/dist/runtime-context/build-plugin.js +16 -0
- package/dist/runtime-context/build-runtime.d.ts +60 -0
- package/dist/runtime-context/build-runtime.d.ts.map +1 -0
- package/dist/runtime-context/build-runtime.js +81 -0
- package/dist/testing/create-test-runtime.d.ts +95 -0
- package/dist/testing/create-test-runtime.d.ts.map +1 -0
- package/dist/testing/create-test-runtime.js +302 -0
- package/dist/testing/index.d.ts +5 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +5 -0
- package/dist/testing/integration/chat-client.d.ts +143 -0
- package/dist/testing/integration/chat-client.d.ts.map +1 -0
- package/dist/testing/integration/chat-client.js +238 -0
- package/dist/testing/integration/harness.d.ts +189 -0
- package/dist/testing/integration/harness.d.ts.map +1 -0
- package/dist/testing/integration/harness.js +461 -0
- package/dist/testing/integration/index.d.ts +14 -0
- package/dist/testing/integration/index.d.ts.map +1 -0
- package/dist/testing/integration/index.js +18 -0
- package/dist/testing/integration/setup.d.ts +2 -0
- package/dist/testing/integration/setup.d.ts.map +1 -0
- package/dist/testing/integration/setup.js +41 -0
- package/dist/testing/integration/sse-parser.d.ts +99 -0
- package/dist/testing/integration/sse-parser.d.ts.map +1 -0
- package/dist/testing/integration/sse-parser.js +125 -0
- package/dist/testing/integration/ucan.d.ts +74 -0
- package/dist/testing/integration/ucan.d.ts.map +1 -0
- package/dist/testing/integration/ucan.js +95 -0
- package/dist/testing/integration/wait-for-matrix-loaded.d.ts +19 -0
- package/dist/testing/integration/wait-for-matrix-loaded.d.ts.map +1 -0
- package/dist/testing/integration/wait-for-matrix-loaded.js +31 -0
- package/dist/testing/mocks.d.ts +64 -0
- package/dist/testing/mocks.d.ts.map +1 -0
- package/dist/testing/mocks.js +141 -0
- package/dist/testing/nest-doubles.d.ts +10 -0
- package/dist/testing/nest-doubles.d.ts.map +1 -0
- package/dist/testing/nest-doubles.js +19 -0
- package/dist/utils/emoji.d.ts +3 -0
- package/dist/utils/emoji.d.ts.map +1 -0
- package/dist/utils/emoji.js +36 -0
- package/package.json +102 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { MatrixManager } from '@ixo/matrix';
|
|
2
|
+
import { type OnModuleDestroy, type OnModuleInit } from '@nestjs/common';
|
|
3
|
+
import { ConfigService } from '@nestjs/config';
|
|
4
|
+
import { type Summarizer } from './channel-memory.summarizer.js';
|
|
5
|
+
import { type ChannelMember, type ChannelMemoryChunk, type ObservedMessage, type PinnedFact } from './channel-memory.types.js';
|
|
6
|
+
export interface ChannelMemoryServiceConfig {
|
|
7
|
+
dbPath?: string;
|
|
8
|
+
syncDebounceMs?: number;
|
|
9
|
+
oracleDid?: string;
|
|
10
|
+
/** Disable Matrix sync entirely (e.g. unit tests). */
|
|
11
|
+
matrixSyncDisabled?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare const CHANNEL_MEMORY_SERVICE_CONFIG: unique symbol;
|
|
14
|
+
export declare const CHANNEL_MEMORY_SUMMARIZER: unique symbol;
|
|
15
|
+
/**
|
|
16
|
+
* Channel memory pipeline. One SQLite DB per Matrix room (under
|
|
17
|
+
* `dbPath/channel_memory/`), each synced as encrypted media to its own
|
|
18
|
+
* Matrix room. On first access the service tries to download the latest
|
|
19
|
+
* snapshot from the room before opening locally; on writes it schedules a
|
|
20
|
+
* debounced upload back to the room.
|
|
21
|
+
*
|
|
22
|
+
* Compaction triggers when the buffer hits a threshold, an idle timeout
|
|
23
|
+
* elapses, or the agent is about to be engaged (`compactJustInTime`).
|
|
24
|
+
*/
|
|
25
|
+
export declare class ChannelMemoryService implements OnModuleInit, OnModuleDestroy {
|
|
26
|
+
private readonly config;
|
|
27
|
+
private readonly overrides;
|
|
28
|
+
private readonly summarizer;
|
|
29
|
+
private static singleton;
|
|
30
|
+
private readonly buffer;
|
|
31
|
+
private readonly compactionInFlight;
|
|
32
|
+
private readonly rooms;
|
|
33
|
+
private readonly opening;
|
|
34
|
+
private rootDir;
|
|
35
|
+
private oracleDid;
|
|
36
|
+
private syncDebounceMs;
|
|
37
|
+
private matrixSyncDisabled;
|
|
38
|
+
constructor(config: ConfigService | null, overrides: ChannelMemoryServiceConfig | null, summarizer?: Summarizer);
|
|
39
|
+
static getInstance(): ChannelMemoryService | undefined;
|
|
40
|
+
/** Test-only — wipe the singleton so a fresh instance can register. */
|
|
41
|
+
static resetSingleton(): void;
|
|
42
|
+
onModuleInit(): void;
|
|
43
|
+
onModuleDestroy(): Promise<void>;
|
|
44
|
+
private dbPathFor;
|
|
45
|
+
private getRoom;
|
|
46
|
+
/**
|
|
47
|
+
* Restore from Matrix when the local file is missing. The snapshot is
|
|
48
|
+
* gzipped on upload (mirrors the user-DB pattern), so we gunzip on
|
|
49
|
+
* download and fall back to using the raw buffer when it's already a
|
|
50
|
+
* valid SQLite header (legacy snapshots).
|
|
51
|
+
*/
|
|
52
|
+
private maybeRestoreFromMatrix;
|
|
53
|
+
private markDirty;
|
|
54
|
+
private syncToMatrix;
|
|
55
|
+
/** Public for the tier scheduler — force-flush all known rooms to Matrix. */
|
|
56
|
+
flushAll(): Promise<void>;
|
|
57
|
+
observeMessage(roomId: string, message: ObservedMessage): void;
|
|
58
|
+
compactJustInTime(roomId: string): Promise<void>;
|
|
59
|
+
private compact;
|
|
60
|
+
private compactInner;
|
|
61
|
+
/** Used by the tier scheduler — drives a rollup transaction for one room. */
|
|
62
|
+
rollupTier(roomId: string, sourceTier: number, olderThanTs: number, bucketMs: number, minChunksPerBucket: number): Promise<number>;
|
|
63
|
+
listOpenRoomIds(): string[];
|
|
64
|
+
recentChunks(roomId: string, limit?: number): Promise<ChannelMemoryChunk[]>;
|
|
65
|
+
oldestChunks(roomId: string, limit?: number): Promise<ChannelMemoryChunk[]>;
|
|
66
|
+
search(roomId: string, query: string, limit?: number): Promise<ChannelMemoryChunk[]>;
|
|
67
|
+
listPinnedFacts(roomId: string): Promise<PinnedFact[]>;
|
|
68
|
+
pinFact(args: {
|
|
69
|
+
roomId: string;
|
|
70
|
+
fact: string;
|
|
71
|
+
pinnedByDid: string;
|
|
72
|
+
sourceEventId?: string;
|
|
73
|
+
}): Promise<PinnedFact>;
|
|
74
|
+
unpinFact(roomId: string, factId: string): Promise<boolean>;
|
|
75
|
+
getMembers(roomId: string): Promise<ChannelMember[]>;
|
|
76
|
+
/**
|
|
77
|
+
* Pull the room member roster from Matrix (display names + matrix user IDs),
|
|
78
|
+
* upsert into the local DB. Returns the freshly fetched list — falls back
|
|
79
|
+
* to the cached roster if Matrix fetch fails.
|
|
80
|
+
*/
|
|
81
|
+
refreshMembers(roomId: string, matrixManager?: MatrixManager): Promise<ChannelMember[]>;
|
|
82
|
+
/**
|
|
83
|
+
* Build the system-prompt-ready context block injected at the start of a
|
|
84
|
+
* group-room session. Combines member roster, pinned facts, recent +
|
|
85
|
+
* oldest summary chunks, and the last K verbatim messages.
|
|
86
|
+
*/
|
|
87
|
+
buildSessionContext(roomId: string, matrixManager?: MatrixManager): Promise<string>;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=channel-memory.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel-memory.service.d.ts","sourceRoot":"","sources":["../../../src/plugins/matrix-group-chats/channel-memory.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAKL,KAAK,eAAe,EACpB,KAAK,YAAY,EAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAa/C,OAAO,EAEL,KAAK,UAAU,EAChB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,UAAU,EAChB,MAAM,2BAA2B,CAAC;AAqBnC,MAAM,WAAW,0BAA0B;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sDAAsD;IACtD,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,eAAO,MAAM,6BAA6B,eAEzC,CAAC;AAEF,eAAO,MAAM,yBAAyB,eAErC,CAAC;AAiBF;;;;;;;;;GASG;AACH,qBACa,oBAAqB,YAAW,YAAY,EAAE,eAAe;IAc1D,OAAO,CAAC,QAAQ,CAAC,MAAM;IAGnC,OAAO,CAAC,QAAQ,CAAC,SAAS;IAG1B,OAAO,CAAC,QAAQ,CAAC,UAAU;IAnB7B,OAAO,CAAC,MAAM,CAAC,SAAS,CAAmC;IAE3D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkC;IACzD,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAoC;IACvE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgC;IACtD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyC;IAEjE,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,SAAS,CAAU;IAC3B,OAAO,CAAC,cAAc,CAAU;IAChC,OAAO,CAAC,kBAAkB,CAAS;gBAGJ,MAAM,EAAE,aAAa,GAAG,IAAI,EAGxC,SAAS,EAAE,0BAA0B,GAAG,IAAI,EAG5C,UAAU,GAAE,UAA0C;IAGzE,MAAM,CAAC,WAAW,IAAI,oBAAoB,GAAG,SAAS;IAItD,uEAAuE;IACvE,MAAM,CAAC,cAAc,IAAI,IAAI;IAI7B,YAAY,IAAI,IAAI;IA4Bd,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAkCtC,OAAO,CAAC,SAAS;YASH,OAAO;IA4BrB;;;;;OAKG;YACW,sBAAsB;IA2DpC,OAAO,CAAC,SAAS;YAeH,YAAY;IA8C1B,6EAA6E;IACvE,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAO/B,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,IAAI;IA4BxD,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAcxC,OAAO;YAWP,YAAY;IAqD1B,6EAA6E;IACvE,UAAU,CACd,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,kBAAkB,EAAE,MAAM,GACzB,OAAO,CAAC,MAAM,CAAC;IAwDlB,eAAe,IAAI,MAAM,EAAE;IAMrB,YAAY,CAChB,MAAM,EAAE,MAAM,EACd,KAAK,SAA+B,GACnC,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAK1B,YAAY,CAChB,MAAM,EAAE,MAAM,EACd,KAAK,SAA+B,GACnC,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAK1B,MAAM,CACV,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,KAAK,SAAK,GACT,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAK1B,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAKtD,OAAO,CAAC,IAAI,EAAE;QAClB,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,GAAG,OAAO,CAAC,UAAU,CAAC;IAejB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAO3D,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAK1D;;;;OAIG;IACG,cAAc,CAClB,MAAM,EAAE,MAAM,EACd,aAAa,GAAE,aAA2C,GACzD,OAAO,CAAC,aAAa,EAAE,CAAC;IA8B3B;;;;OAIG;IACG,mBAAmB,CACvB,MAAM,EAAE,MAAM,EACd,aAAa,GAAE,aAA2C,GACzD,OAAO,CAAC,MAAM,CAAC;CAwFnB"}
|
|
@@ -0,0 +1,565 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
var ChannelMemoryService_1;
|
|
14
|
+
import { MatrixManager } from '@ixo/matrix';
|
|
15
|
+
import { Inject, Injectable, Logger, Optional, } from '@nestjs/common';
|
|
16
|
+
import { File } from 'node:buffer';
|
|
17
|
+
import * as crypto from 'node:crypto';
|
|
18
|
+
import * as fs from 'node:fs';
|
|
19
|
+
import * as fsp from 'node:fs/promises';
|
|
20
|
+
import * as path from 'node:path';
|
|
21
|
+
import { promisify } from 'node:util';
|
|
22
|
+
import { gunzip, gzip } from 'node:zlib';
|
|
23
|
+
import { getMediaFromRoomByStorageKey, uploadMediaToRoom, } from '../../matrix/checkpointer/matrix-upload-utils.js';
|
|
24
|
+
import { ChannelMemoryRepo } from './channel-memory.repo.js';
|
|
25
|
+
import { ChannelMemorySummarizer, } from './channel-memory.summarizer.js';
|
|
26
|
+
const gzipAsync = promisify(gzip);
|
|
27
|
+
const gunzipAsync = promisify(gunzip);
|
|
28
|
+
const SQLITE_MAGIC = Buffer.from('SQLite format 3\0');
|
|
29
|
+
const logger = new Logger('ChannelMemoryService');
|
|
30
|
+
const COMPACT_BUFFER_THRESHOLD = 20;
|
|
31
|
+
const COMPACT_IDLE_MS = 5 * 60 * 1000;
|
|
32
|
+
const COMPACT_JIT_MIN = 5;
|
|
33
|
+
const COMPACT_JIT_TIMEOUT_MS = 3000;
|
|
34
|
+
const BUFFER_HARD_CAP = 40;
|
|
35
|
+
const SESSION_INJECT_RECENT_CHUNKS = 8;
|
|
36
|
+
const SESSION_INJECT_OLDEST_CHUNKS = 2;
|
|
37
|
+
const SESSION_INJECT_LAST_MESSAGES = 15;
|
|
38
|
+
const MATRIX_STORAGE_KEY = 'qiforge.channel_memory.v1';
|
|
39
|
+
const DEFAULT_SYNC_DEBOUNCE_MS = 60 * 1000;
|
|
40
|
+
const DEFAULT_DB_PATH = './data/channel_memory';
|
|
41
|
+
export const CHANNEL_MEMORY_SERVICE_CONFIG = Symbol.for('CHANNEL_MEMORY_SERVICE_CONFIG');
|
|
42
|
+
export const CHANNEL_MEMORY_SUMMARIZER = Symbol.for('CHANNEL_MEMORY_SUMMARIZER');
|
|
43
|
+
/**
|
|
44
|
+
* Channel memory pipeline. One SQLite DB per Matrix room (under
|
|
45
|
+
* `dbPath/channel_memory/`), each synced as encrypted media to its own
|
|
46
|
+
* Matrix room. On first access the service tries to download the latest
|
|
47
|
+
* snapshot from the room before opening locally; on writes it schedules a
|
|
48
|
+
* debounced upload back to the room.
|
|
49
|
+
*
|
|
50
|
+
* Compaction triggers when the buffer hits a threshold, an idle timeout
|
|
51
|
+
* elapses, or the agent is about to be engaged (`compactJustInTime`).
|
|
52
|
+
*/
|
|
53
|
+
let ChannelMemoryService = class ChannelMemoryService {
|
|
54
|
+
static { ChannelMemoryService_1 = this; }
|
|
55
|
+
config;
|
|
56
|
+
overrides;
|
|
57
|
+
summarizer;
|
|
58
|
+
static singleton;
|
|
59
|
+
buffer = new Map();
|
|
60
|
+
compactionInFlight = new Map();
|
|
61
|
+
rooms = new Map();
|
|
62
|
+
opening = new Map();
|
|
63
|
+
rootDir;
|
|
64
|
+
oracleDid;
|
|
65
|
+
syncDebounceMs;
|
|
66
|
+
matrixSyncDisabled = false;
|
|
67
|
+
constructor(config, overrides, summarizer = new ChannelMemorySummarizer()) {
|
|
68
|
+
this.config = config;
|
|
69
|
+
this.overrides = overrides;
|
|
70
|
+
this.summarizer = summarizer;
|
|
71
|
+
}
|
|
72
|
+
static getInstance() {
|
|
73
|
+
return ChannelMemoryService_1.singleton;
|
|
74
|
+
}
|
|
75
|
+
/** Test-only — wipe the singleton so a fresh instance can register. */
|
|
76
|
+
static resetSingleton() {
|
|
77
|
+
ChannelMemoryService_1.singleton = undefined;
|
|
78
|
+
}
|
|
79
|
+
onModuleInit() {
|
|
80
|
+
const cfg = this.overrides ?? {};
|
|
81
|
+
const baseDir = cfg.dbPath ??
|
|
82
|
+
this.config?.get('SQLITE_DATABASE_PATH') ??
|
|
83
|
+
DEFAULT_DB_PATH;
|
|
84
|
+
this.rootDir = path.resolve(baseDir);
|
|
85
|
+
fs.mkdirSync(this.rootDir, { recursive: true });
|
|
86
|
+
this.oracleDid =
|
|
87
|
+
cfg.oracleDid ??
|
|
88
|
+
this.config?.get('ORACLE_ENTITY_DID') ??
|
|
89
|
+
this.config?.get('ORACLE_DID') ??
|
|
90
|
+
'unknown-oracle';
|
|
91
|
+
this.syncDebounceMs =
|
|
92
|
+
cfg.syncDebounceMs ??
|
|
93
|
+
Number(this.config?.get('CHANNEL_MEMORY_SYNC_INTERVAL_MS') ??
|
|
94
|
+
DEFAULT_SYNC_DEBOUNCE_MS);
|
|
95
|
+
this.matrixSyncDisabled = cfg.matrixSyncDisabled ?? false;
|
|
96
|
+
ChannelMemoryService_1.singleton = this;
|
|
97
|
+
logger.log(`DB root ready at ${this.rootDir}`);
|
|
98
|
+
}
|
|
99
|
+
async onModuleDestroy() {
|
|
100
|
+
for (const entry of this.buffer.values()) {
|
|
101
|
+
if (entry.idleTimer)
|
|
102
|
+
clearTimeout(entry.idleTimer);
|
|
103
|
+
}
|
|
104
|
+
this.buffer.clear();
|
|
105
|
+
const flushes = [];
|
|
106
|
+
for (const [roomId, room] of this.rooms) {
|
|
107
|
+
if (room.syncTimer) {
|
|
108
|
+
clearTimeout(room.syncTimer);
|
|
109
|
+
room.syncTimer = null;
|
|
110
|
+
}
|
|
111
|
+
if (room.dirty || room.uploadInFlight) {
|
|
112
|
+
flushes.push(this.syncToMatrix(roomId).catch(() => undefined));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
await Promise.allSettled(flushes);
|
|
116
|
+
for (const room of this.rooms.values()) {
|
|
117
|
+
try {
|
|
118
|
+
room.repo.close();
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
// ignore — best-effort shutdown
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
this.rooms.clear();
|
|
125
|
+
if (ChannelMemoryService_1.singleton === this) {
|
|
126
|
+
ChannelMemoryService_1.singleton = undefined;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// ── Per-room DB lifecycle ───────────────────────────────────────────────
|
|
130
|
+
dbPathFor(roomId) {
|
|
131
|
+
const hash = crypto
|
|
132
|
+
.createHash('sha256')
|
|
133
|
+
.update(`${roomId}|${this.oracleDid}`)
|
|
134
|
+
.digest('hex')
|
|
135
|
+
.slice(0, 24);
|
|
136
|
+
return path.join(this.rootDir, `${hash}.db`);
|
|
137
|
+
}
|
|
138
|
+
async getRoom(roomId) {
|
|
139
|
+
const existing = this.rooms.get(roomId);
|
|
140
|
+
if (existing)
|
|
141
|
+
return existing;
|
|
142
|
+
const opening = this.opening.get(roomId);
|
|
143
|
+
if (opening)
|
|
144
|
+
return opening;
|
|
145
|
+
const promise = (async () => {
|
|
146
|
+
const dbPath = this.dbPathFor(roomId);
|
|
147
|
+
await this.maybeRestoreFromMatrix(roomId, dbPath);
|
|
148
|
+
const repo = new ChannelMemoryRepo(dbPath);
|
|
149
|
+
const entry = {
|
|
150
|
+
repo,
|
|
151
|
+
dbPath,
|
|
152
|
+
dirty: false,
|
|
153
|
+
syncTimer: null,
|
|
154
|
+
uploadInFlight: null,
|
|
155
|
+
lastUploadedChecksum: undefined,
|
|
156
|
+
};
|
|
157
|
+
this.rooms.set(roomId, entry);
|
|
158
|
+
return entry;
|
|
159
|
+
})().finally(() => {
|
|
160
|
+
this.opening.delete(roomId);
|
|
161
|
+
});
|
|
162
|
+
this.opening.set(roomId, promise);
|
|
163
|
+
return promise;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Restore from Matrix when the local file is missing. The snapshot is
|
|
167
|
+
* gzipped on upload (mirrors the user-DB pattern), so we gunzip on
|
|
168
|
+
* download and fall back to using the raw buffer when it's already a
|
|
169
|
+
* valid SQLite header (legacy snapshots).
|
|
170
|
+
*/
|
|
171
|
+
async maybeRestoreFromMatrix(roomId, dbPath) {
|
|
172
|
+
if (this.matrixSyncDisabled)
|
|
173
|
+
return;
|
|
174
|
+
if (fs.existsSync(dbPath))
|
|
175
|
+
return;
|
|
176
|
+
let remote;
|
|
177
|
+
try {
|
|
178
|
+
remote = await getMediaFromRoomByStorageKey(roomId, MATRIX_STORAGE_KEY);
|
|
179
|
+
}
|
|
180
|
+
catch (err) {
|
|
181
|
+
logger.warn(`Restore from Matrix failed for room=${roomId}; starting fresh. ${err instanceof Error ? err.message : String(err)}`);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (!remote) {
|
|
185
|
+
logger.log(`No prior DB in Matrix for room=${roomId}; starting fresh`);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
let buffer;
|
|
189
|
+
try {
|
|
190
|
+
buffer = await gunzipAsync(remote.mediaBuffer);
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
if (remote.mediaBuffer.length >= 16 &&
|
|
194
|
+
remote.mediaBuffer.subarray(0, 16).equals(SQLITE_MAGIC)) {
|
|
195
|
+
buffer = remote.mediaBuffer;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
logger.warn(`Restored payload for room=${roomId} is neither valid gzip nor SQLite — starting fresh`);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (buffer.length < 16 || !buffer.subarray(0, 16).equals(SQLITE_MAGIC)) {
|
|
203
|
+
logger.warn(`Restored DB for room=${roomId} has invalid SQLite header — starting fresh`);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const tmp = `${dbPath}.tmp`;
|
|
207
|
+
try {
|
|
208
|
+
await fsp.writeFile(tmp, buffer);
|
|
209
|
+
await fsp.rename(tmp, dbPath);
|
|
210
|
+
logger.log(`Restored channel-memory DB for room=${roomId} (${buffer.length} bytes)`);
|
|
211
|
+
}
|
|
212
|
+
catch (err) {
|
|
213
|
+
await fsp.unlink(tmp).catch(() => undefined);
|
|
214
|
+
throw err;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
markDirty(roomId) {
|
|
218
|
+
const room = this.rooms.get(roomId);
|
|
219
|
+
if (!room)
|
|
220
|
+
return;
|
|
221
|
+
room.dirty = true;
|
|
222
|
+
if (this.matrixSyncDisabled)
|
|
223
|
+
return;
|
|
224
|
+
if (room.syncTimer)
|
|
225
|
+
clearTimeout(room.syncTimer);
|
|
226
|
+
room.syncTimer = setTimeout(() => {
|
|
227
|
+
this.syncToMatrix(roomId).catch((err) => {
|
|
228
|
+
logger.warn(`debounced sync failed for ${roomId}: ${err instanceof Error ? err.message : String(err)}`);
|
|
229
|
+
});
|
|
230
|
+
}, this.syncDebounceMs);
|
|
231
|
+
}
|
|
232
|
+
async syncToMatrix(roomId) {
|
|
233
|
+
if (this.matrixSyncDisabled)
|
|
234
|
+
return;
|
|
235
|
+
const room = this.rooms.get(roomId);
|
|
236
|
+
if (!room)
|
|
237
|
+
return;
|
|
238
|
+
if (room.uploadInFlight) {
|
|
239
|
+
await room.uploadInFlight;
|
|
240
|
+
if (!room.dirty)
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
if (!room.dirty)
|
|
244
|
+
return;
|
|
245
|
+
const upload = (async () => {
|
|
246
|
+
room.repo.checkpoint();
|
|
247
|
+
const snapshotPath = `${room.dbPath}.snap-${Date.now()}`;
|
|
248
|
+
try {
|
|
249
|
+
await fsp.copyFile(room.dbPath, snapshotPath);
|
|
250
|
+
const raw = await fsp.readFile(snapshotPath);
|
|
251
|
+
const checksum = crypto.createHash('sha256').update(raw).digest('hex');
|
|
252
|
+
if (checksum === room.lastUploadedChecksum) {
|
|
253
|
+
room.dirty = false;
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
const compressed = await gzipAsync(raw);
|
|
257
|
+
const file = new File([compressed], `${MATRIX_STORAGE_KEY}.db.gz`, {
|
|
258
|
+
type: 'application/gzip',
|
|
259
|
+
lastModified: Date.now(),
|
|
260
|
+
});
|
|
261
|
+
await uploadMediaToRoom(roomId, file, MATRIX_STORAGE_KEY);
|
|
262
|
+
room.dirty = false;
|
|
263
|
+
room.lastUploadedChecksum = checksum;
|
|
264
|
+
logger.log(`Uploaded DB to room=${roomId} (${raw.length}B raw, ${compressed.length}B gz)`);
|
|
265
|
+
}
|
|
266
|
+
finally {
|
|
267
|
+
await fsp.unlink(snapshotPath).catch(() => undefined);
|
|
268
|
+
}
|
|
269
|
+
})();
|
|
270
|
+
room.uploadInFlight = upload;
|
|
271
|
+
try {
|
|
272
|
+
await upload;
|
|
273
|
+
}
|
|
274
|
+
finally {
|
|
275
|
+
room.uploadInFlight = null;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
/** Public for the tier scheduler — force-flush all known rooms to Matrix. */
|
|
279
|
+
async flushAll() {
|
|
280
|
+
const ids = Array.from(this.rooms.keys());
|
|
281
|
+
await Promise.allSettled(ids.map((id) => this.syncToMatrix(id)));
|
|
282
|
+
}
|
|
283
|
+
// ── Capture + compaction ────────────────────────────────────────────────
|
|
284
|
+
observeMessage(roomId, message) {
|
|
285
|
+
let entry = this.buffer.get(roomId);
|
|
286
|
+
if (!entry) {
|
|
287
|
+
entry = { messages: [], idleTimer: null };
|
|
288
|
+
this.buffer.set(roomId, entry);
|
|
289
|
+
}
|
|
290
|
+
entry.messages.push(message);
|
|
291
|
+
if (entry.idleTimer)
|
|
292
|
+
clearTimeout(entry.idleTimer);
|
|
293
|
+
entry.idleTimer = setTimeout(() => {
|
|
294
|
+
this.compact(roomId).catch((err) => logger.warn(`idle compaction failed for ${roomId}: ${err instanceof Error ? err.message : String(err)}`));
|
|
295
|
+
}, COMPACT_IDLE_MS);
|
|
296
|
+
if (entry.messages.length >= COMPACT_BUFFER_THRESHOLD) {
|
|
297
|
+
void this.compact(roomId).catch((err) => logger.warn(`threshold compaction failed for ${roomId}: ${err instanceof Error ? err.message : String(err)}`));
|
|
298
|
+
}
|
|
299
|
+
else if (entry.messages.length >= BUFFER_HARD_CAP) {
|
|
300
|
+
void this.compact(roomId);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
async compactJustInTime(roomId) {
|
|
304
|
+
const entry = this.buffer.get(roomId);
|
|
305
|
+
if (!entry || entry.messages.length < COMPACT_JIT_MIN)
|
|
306
|
+
return;
|
|
307
|
+
const timeout = new Promise((resolve) => setTimeout(resolve, COMPACT_JIT_TIMEOUT_MS));
|
|
308
|
+
await Promise.race([this.compact(roomId), timeout]).catch((err) => logger.warn(`JIT compaction error for ${roomId}: ${err instanceof Error ? err.message : String(err)}`));
|
|
309
|
+
}
|
|
310
|
+
async compact(roomId) {
|
|
311
|
+
const inFlight = this.compactionInFlight.get(roomId);
|
|
312
|
+
if (inFlight)
|
|
313
|
+
return inFlight;
|
|
314
|
+
const promise = this.compactInner(roomId).finally(() => {
|
|
315
|
+
this.compactionInFlight.delete(roomId);
|
|
316
|
+
});
|
|
317
|
+
this.compactionInFlight.set(roomId, promise);
|
|
318
|
+
return promise;
|
|
319
|
+
}
|
|
320
|
+
async compactInner(roomId) {
|
|
321
|
+
const entry = this.buffer.get(roomId);
|
|
322
|
+
if (!entry || entry.messages.length === 0)
|
|
323
|
+
return;
|
|
324
|
+
const drained = entry.messages.slice();
|
|
325
|
+
entry.messages.length = 0;
|
|
326
|
+
if (entry.idleTimer) {
|
|
327
|
+
clearTimeout(entry.idleTimer);
|
|
328
|
+
entry.idleTimer = null;
|
|
329
|
+
}
|
|
330
|
+
const first = drained[0];
|
|
331
|
+
const last = drained[drained.length - 1];
|
|
332
|
+
if (!first || !last)
|
|
333
|
+
return;
|
|
334
|
+
const summary = await this.summarizer.summarize(drained);
|
|
335
|
+
if (!summary) {
|
|
336
|
+
entry.messages.unshift(...drained);
|
|
337
|
+
logger.warn(`summary unavailable; ${drained.length} msgs requeued for ${roomId}`);
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
const chunk = {
|
|
341
|
+
id: crypto.randomUUID(),
|
|
342
|
+
roomId,
|
|
343
|
+
summary,
|
|
344
|
+
fromEventId: first.eventId,
|
|
345
|
+
toEventId: last.eventId,
|
|
346
|
+
fromTimestamp: first.timestamp,
|
|
347
|
+
toTimestamp: last.timestamp,
|
|
348
|
+
messageCount: drained.length,
|
|
349
|
+
participants: Array.from(new Set(drained.map((m) => m.senderDid))),
|
|
350
|
+
threadIds: Array.from(new Set(drained.map((m) => m.threadId))),
|
|
351
|
+
tier: 1,
|
|
352
|
+
createdAt: Date.now(),
|
|
353
|
+
};
|
|
354
|
+
try {
|
|
355
|
+
const room = await this.getRoom(roomId);
|
|
356
|
+
room.repo.insertChunk(chunk);
|
|
357
|
+
this.markDirty(roomId);
|
|
358
|
+
logger.log(`room=${roomId} chunk=${chunk.id} msgs=${chunk.messageCount} totalChunks=${room.repo.countChunks(roomId)}`);
|
|
359
|
+
}
|
|
360
|
+
catch (err) {
|
|
361
|
+
logger.error(`insertChunk failed for ${roomId}: ${err instanceof Error ? err.message : String(err)}`);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
/** Used by the tier scheduler — drives a rollup transaction for one room. */
|
|
365
|
+
async rollupTier(roomId, sourceTier, olderThanTs, bucketMs, minChunksPerBucket) {
|
|
366
|
+
const room = await this.getRoom(roomId);
|
|
367
|
+
const candidates = room.repo.findRollupCandidates(roomId, {
|
|
368
|
+
sourceTier,
|
|
369
|
+
olderThanTs,
|
|
370
|
+
bucketMs,
|
|
371
|
+
minChunksPerBucket,
|
|
372
|
+
});
|
|
373
|
+
if (candidates.length === 0)
|
|
374
|
+
return 0;
|
|
375
|
+
let rolledUp = 0;
|
|
376
|
+
for (const candidate of candidates) {
|
|
377
|
+
const rollup = await this.summarizer.rollup(candidate.chunks.map((c) => c.summary));
|
|
378
|
+
if (!rollup)
|
|
379
|
+
continue;
|
|
380
|
+
const first = candidate.chunks[0];
|
|
381
|
+
const last = candidate.chunks[candidate.chunks.length - 1];
|
|
382
|
+
if (!first || !last)
|
|
383
|
+
continue;
|
|
384
|
+
const participants = Array.from(new Set(candidate.chunks.flatMap((c) => c.participants)));
|
|
385
|
+
const threadIds = Array.from(new Set(candidate.chunks.flatMap((c) => c.threadIds)));
|
|
386
|
+
const messageCount = candidate.chunks.reduce((n, c) => n + c.messageCount, 0);
|
|
387
|
+
const consolidated = {
|
|
388
|
+
id: crypto.randomUUID(),
|
|
389
|
+
roomId,
|
|
390
|
+
summary: rollup,
|
|
391
|
+
fromEventId: first.fromEventId,
|
|
392
|
+
toEventId: last.toEventId,
|
|
393
|
+
fromTimestamp: first.fromTimestamp,
|
|
394
|
+
toTimestamp: last.toTimestamp,
|
|
395
|
+
messageCount,
|
|
396
|
+
participants,
|
|
397
|
+
threadIds,
|
|
398
|
+
tier: candidate.toTier,
|
|
399
|
+
createdAt: Date.now(),
|
|
400
|
+
};
|
|
401
|
+
room.repo.replaceWithRollup(candidate.chunks.map((c) => c.id), consolidated);
|
|
402
|
+
rolledUp += candidate.chunks.length;
|
|
403
|
+
}
|
|
404
|
+
if (rolledUp > 0)
|
|
405
|
+
this.markDirty(roomId);
|
|
406
|
+
return rolledUp;
|
|
407
|
+
}
|
|
408
|
+
listOpenRoomIds() {
|
|
409
|
+
return Array.from(this.rooms.keys());
|
|
410
|
+
}
|
|
411
|
+
// ── Read APIs ───────────────────────────────────────────────────────────
|
|
412
|
+
async recentChunks(roomId, limit = SESSION_INJECT_RECENT_CHUNKS) {
|
|
413
|
+
const room = await this.getRoom(roomId);
|
|
414
|
+
return room.repo.recentChunks(roomId, limit);
|
|
415
|
+
}
|
|
416
|
+
async oldestChunks(roomId, limit = SESSION_INJECT_OLDEST_CHUNKS) {
|
|
417
|
+
const room = await this.getRoom(roomId);
|
|
418
|
+
return room.repo.oldestChunks(roomId, limit);
|
|
419
|
+
}
|
|
420
|
+
async search(roomId, query, limit = 10) {
|
|
421
|
+
const room = await this.getRoom(roomId);
|
|
422
|
+
return room.repo.searchChunks(roomId, query, limit);
|
|
423
|
+
}
|
|
424
|
+
async listPinnedFacts(roomId) {
|
|
425
|
+
const room = await this.getRoom(roomId);
|
|
426
|
+
return room.repo.listPinnedFacts(roomId);
|
|
427
|
+
}
|
|
428
|
+
async pinFact(args) {
|
|
429
|
+
const fact = {
|
|
430
|
+
id: crypto.randomUUID(),
|
|
431
|
+
roomId: args.roomId,
|
|
432
|
+
fact: args.fact,
|
|
433
|
+
pinnedByDid: args.pinnedByDid,
|
|
434
|
+
sourceEventId: args.sourceEventId,
|
|
435
|
+
createdAt: Date.now(),
|
|
436
|
+
};
|
|
437
|
+
const room = await this.getRoom(args.roomId);
|
|
438
|
+
room.repo.insertPinnedFact(fact);
|
|
439
|
+
this.markDirty(args.roomId);
|
|
440
|
+
return fact;
|
|
441
|
+
}
|
|
442
|
+
async unpinFact(roomId, factId) {
|
|
443
|
+
const room = await this.getRoom(roomId);
|
|
444
|
+
const ok = room.repo.deletePinnedFact(roomId, factId);
|
|
445
|
+
if (ok)
|
|
446
|
+
this.markDirty(roomId);
|
|
447
|
+
return ok;
|
|
448
|
+
}
|
|
449
|
+
async getMembers(roomId) {
|
|
450
|
+
const room = await this.getRoom(roomId);
|
|
451
|
+
return room.repo.getMembers(roomId);
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Pull the room member roster from Matrix (display names + matrix user IDs),
|
|
455
|
+
* upsert into the local DB. Returns the freshly fetched list — falls back
|
|
456
|
+
* to the cached roster if Matrix fetch fails.
|
|
457
|
+
*/
|
|
458
|
+
async refreshMembers(roomId, matrixManager = MatrixManager.getInstance()) {
|
|
459
|
+
try {
|
|
460
|
+
const info = await matrixManager.getRoomInfo(roomId);
|
|
461
|
+
const botUserId = matrixManager.getBotMatrixUserId();
|
|
462
|
+
const members = [];
|
|
463
|
+
for (const userId of info.joinedMemberIds) {
|
|
464
|
+
if (userId === botUserId)
|
|
465
|
+
continue;
|
|
466
|
+
const displayName = await matrixManager.getCachedDisplayName(userId, roomId);
|
|
467
|
+
members.push({ matrixUserId: userId, displayName });
|
|
468
|
+
}
|
|
469
|
+
const room = await this.getRoom(roomId);
|
|
470
|
+
room.repo.upsertMembers(roomId, members);
|
|
471
|
+
this.markDirty(roomId);
|
|
472
|
+
return members;
|
|
473
|
+
}
|
|
474
|
+
catch (err) {
|
|
475
|
+
logger.warn(`refreshMembers failed for ${roomId}: ${err instanceof Error ? err.message : String(err)}`);
|
|
476
|
+
try {
|
|
477
|
+
const room = await this.getRoom(roomId);
|
|
478
|
+
return room.repo.getMembers(roomId);
|
|
479
|
+
}
|
|
480
|
+
catch {
|
|
481
|
+
return [];
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Build the system-prompt-ready context block injected at the start of a
|
|
487
|
+
* group-room session. Combines member roster, pinned facts, recent +
|
|
488
|
+
* oldest summary chunks, and the last K verbatim messages.
|
|
489
|
+
*/
|
|
490
|
+
async buildSessionContext(roomId, matrixManager = MatrixManager.getInstance()) {
|
|
491
|
+
const [members, recent, oldest, facts, recentMsgs] = await Promise.all([
|
|
492
|
+
this.refreshMembers(roomId, matrixManager),
|
|
493
|
+
this.recentChunks(roomId),
|
|
494
|
+
this.oldestChunks(roomId),
|
|
495
|
+
this.listPinnedFacts(roomId),
|
|
496
|
+
matrixManager
|
|
497
|
+
.getRecentRoomMessages(roomId, { limit: SESSION_INJECT_LAST_MESSAGES })
|
|
498
|
+
.catch((err) => {
|
|
499
|
+
logger.warn(`live recent fetch failed for ${roomId}: ${err instanceof Error ? err.message : String(err)}`);
|
|
500
|
+
return {
|
|
501
|
+
messages: [],
|
|
502
|
+
};
|
|
503
|
+
}),
|
|
504
|
+
]);
|
|
505
|
+
const sections = [];
|
|
506
|
+
sections.push(`You are participating in a Matrix group chat. User messages are prefixed with "[DisplayName]:" so you know who is speaking. Address users by their display name when relevant. Stay quiet unless explicitly mentioned, replied to, or already in an active thread with you.`);
|
|
507
|
+
if (members.length > 0) {
|
|
508
|
+
const lines = members
|
|
509
|
+
.map((m) => `- ${m.displayName} (${m.matrixUserId})`)
|
|
510
|
+
.join('\n');
|
|
511
|
+
sections.push(`## Members in this room\n${lines}`);
|
|
512
|
+
}
|
|
513
|
+
if (facts.length > 0) {
|
|
514
|
+
const lines = facts.map((f) => `- ${f.fact}`).join('\n');
|
|
515
|
+
sections.push(`## Pinned facts\n${lines}`);
|
|
516
|
+
}
|
|
517
|
+
const seen = new Set();
|
|
518
|
+
const ordered = [];
|
|
519
|
+
for (const c of oldest) {
|
|
520
|
+
if (!seen.has(c.id)) {
|
|
521
|
+
ordered.push(c);
|
|
522
|
+
seen.add(c.id);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
for (const c of recent) {
|
|
526
|
+
if (!seen.has(c.id)) {
|
|
527
|
+
ordered.push(c);
|
|
528
|
+
seen.add(c.id);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
if (ordered.length > 0) {
|
|
532
|
+
const lines = ordered
|
|
533
|
+
.map((c) => {
|
|
534
|
+
const when = new Date(c.toTimestamp).toISOString();
|
|
535
|
+
const tierTag = c.tier > 1 ? ` tier=${c.tier}` : '';
|
|
536
|
+
return `### [${when}${tierTag}] ${c.messageCount} msgs\n${c.summary}`;
|
|
537
|
+
})
|
|
538
|
+
.join('\n\n');
|
|
539
|
+
sections.push(`## Channel memory\n${lines}`);
|
|
540
|
+
}
|
|
541
|
+
if (recentMsgs.messages.length > 0) {
|
|
542
|
+
const lines = await Promise.all(recentMsgs.messages.map(async (m) => {
|
|
543
|
+
const dn = await matrixManager
|
|
544
|
+
.getCachedDisplayName(m.sender, roomId)
|
|
545
|
+
.catch(() => m.sender);
|
|
546
|
+
const when = new Date(m.timestamp).toISOString();
|
|
547
|
+
const thread = m.threadId ? ` thread=${m.threadId.slice(0, 10)}` : '';
|
|
548
|
+
return `[${dn} @ ${when}${thread}]: ${m.body}`;
|
|
549
|
+
}));
|
|
550
|
+
sections.push(`## Recent messages (verbatim)\n${lines.join('\n')}`);
|
|
551
|
+
}
|
|
552
|
+
sections.push(`Tools available for this room: search_channel_memory, recall_channel_memory, pin_room_fact, unpin_room_fact.`);
|
|
553
|
+
return sections.join('\n\n');
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
ChannelMemoryService = ChannelMemoryService_1 = __decorate([
|
|
557
|
+
Injectable(),
|
|
558
|
+
__param(0, Optional()),
|
|
559
|
+
__param(1, Optional()),
|
|
560
|
+
__param(1, Inject(CHANNEL_MEMORY_SERVICE_CONFIG)),
|
|
561
|
+
__param(2, Optional()),
|
|
562
|
+
__param(2, Inject(CHANNEL_MEMORY_SUMMARIZER)),
|
|
563
|
+
__metadata("design:paramtypes", [Object, Object, Object])
|
|
564
|
+
], ChannelMemoryService);
|
|
565
|
+
export { ChannelMemoryService };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ObservedMessage } from './channel-memory.types.js';
|
|
2
|
+
export interface Summarizer {
|
|
3
|
+
summarize(messages: ObservedMessage[]): Promise<string | null>;
|
|
4
|
+
rollup(summaries: string[]): Promise<string | null>;
|
|
5
|
+
}
|
|
6
|
+
export declare class ChannelMemorySummarizer implements Summarizer {
|
|
7
|
+
/**
|
|
8
|
+
* Compact a batch of observed messages into a summary string.
|
|
9
|
+
* Returns null if the LLM call fails — caller should keep the buffer.
|
|
10
|
+
*/
|
|
11
|
+
summarize(messages: ObservedMessage[]): Promise<string | null>;
|
|
12
|
+
/**
|
|
13
|
+
* Consolidate multiple tier-N summaries into a single tier-(N+1) summary.
|
|
14
|
+
* Used by the tier scheduler for week/month rollups.
|
|
15
|
+
*/
|
|
16
|
+
rollup(summaries: string[]): Promise<string | null>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=channel-memory.summarizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel-memory.summarizer.d.ts","sourceRoot":"","sources":["../../../src/plugins/matrix-group-chats/channel-memory.summarizer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAkDjE,MAAM,WAAW,UAAU;IACzB,SAAS,CAAC,QAAQ,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC/D,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CACrD;AAED,qBAAa,uBAAwB,YAAW,UAAU;IACxD;;;OAGG;IACG,SAAS,CAAC,QAAQ,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IA+BpE;;;OAGG;IACG,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAiC1D"}
|