@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,406 @@
|
|
|
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 ClaimProcessingService_1;
|
|
14
|
+
import { Claims, Client, Payments } from '@ixo/oracles-chain-client';
|
|
15
|
+
import { Inject, Injectable, InternalServerErrorException, Logger, Optional, } from '@nestjs/common';
|
|
16
|
+
import { ConfigService } from '@nestjs/config';
|
|
17
|
+
import { Cron, CronExpression } from '@nestjs/schedule';
|
|
18
|
+
import { getSubscriptionUrlByNetwork } from '@ixo/common';
|
|
19
|
+
import { SqliteSaver } from '@ixo/sqlite-saver';
|
|
20
|
+
import { entrypoint, task, } from '@langchain/langgraph';
|
|
21
|
+
import { mkdirSync } from 'node:fs';
|
|
22
|
+
import path from 'node:path';
|
|
23
|
+
import { UcanService } from '../../modules/ucan/ucan.service.js';
|
|
24
|
+
import { TokenLimiter } from './token-limiter.js';
|
|
25
|
+
/** Token used to inject the credits-plugin TokenLimiter instance into the service. */
|
|
26
|
+
export const CLAIM_PROCESSING_TOKEN_LIMITER = Symbol.for('ClaimProcessingTokenLimiter');
|
|
27
|
+
/** IBC denom representing uixo on mainnet. */
|
|
28
|
+
const MAINNET_IBC_DENOM = 'ibc/6BBE9BD4246F8E04948D5A4EEE7164B2630263B9EBB5E7DC5F0A46C62A2FF97B';
|
|
29
|
+
/** Minimum held credits before submitting a claim (prevents spam of tiny txns). */
|
|
30
|
+
const MINIMUM_CLAIM_THRESHOLD = 5000;
|
|
31
|
+
/**
|
|
32
|
+
* Submits held-credit claims to the chain on a fixed cron. Pulls users with
|
|
33
|
+
* non-zero held amounts from the credits-plugin `TokenLimiter`, then runs a
|
|
34
|
+
* LangGraph `entrypoint`+`task` workflow per user:
|
|
35
|
+
*
|
|
36
|
+
* 1. submit intent (escrow payment)
|
|
37
|
+
* 2. sign + save the claim to Matrix
|
|
38
|
+
* 3. submit the claim on-chain
|
|
39
|
+
* 4. notify the subscription API
|
|
40
|
+
*
|
|
41
|
+
* Splits oversized batches against the oracle's per-claim max. Internal,
|
|
42
|
+
* agent-invisible — `claimProcessingPlugin` declares `visibility: 'silent'`
|
|
43
|
+
* and ships no tools.
|
|
44
|
+
*/
|
|
45
|
+
let ClaimProcessingService = ClaimProcessingService_1 = class ClaimProcessingService {
|
|
46
|
+
configService;
|
|
47
|
+
ucanService;
|
|
48
|
+
logger = new Logger(ClaimProcessingService_1.name);
|
|
49
|
+
denom;
|
|
50
|
+
claimProcessingCheckpointer;
|
|
51
|
+
claimProcessingDbPath;
|
|
52
|
+
tokenLimiter;
|
|
53
|
+
retryPolicy = {
|
|
54
|
+
maxAttempts: 3,
|
|
55
|
+
backoffFactor: 2,
|
|
56
|
+
initialInterval: 1000,
|
|
57
|
+
};
|
|
58
|
+
constructor(configService, ucanService, tokenLimiter) {
|
|
59
|
+
this.configService = configService;
|
|
60
|
+
this.ucanService = ucanService;
|
|
61
|
+
if (!tokenLimiter) {
|
|
62
|
+
throw new Error('ClaimProcessingService requires a TokenLimiter instance (provide via the CLAIM_PROCESSING_TOKEN_LIMITER token).');
|
|
63
|
+
}
|
|
64
|
+
this.tokenLimiter = tokenLimiter;
|
|
65
|
+
this.denom =
|
|
66
|
+
this.configService.get('NETWORK') === 'mainnet'
|
|
67
|
+
? MAINNET_IBC_DENOM
|
|
68
|
+
: 'uixo';
|
|
69
|
+
const sqlitePath = this.configService.getOrThrow('SQLITE_DATABASE_PATH');
|
|
70
|
+
const claimProcessingFolder = path.join(sqlitePath, 'claim_processing');
|
|
71
|
+
this.claimProcessingDbPath = path.join(claimProcessingFolder, 'claim-processing.db');
|
|
72
|
+
try {
|
|
73
|
+
mkdirSync(claimProcessingFolder, { recursive: true });
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
this.logger.error(`Failed to create claim processing folder: ${err instanceof Error ? err.message : String(err)}`, err instanceof Error ? err.stack : undefined);
|
|
77
|
+
}
|
|
78
|
+
// `@ixo/sqlite-saver` and `@langchain/langgraph` end up referencing two
|
|
79
|
+
// structurally-identical `BaseCheckpointSaver` instances from
|
|
80
|
+
// separately-resolved `@langchain/langgraph-checkpoint` copies (one via
|
|
81
|
+
// core@1.1.42, one via core@1.1.45). Bridge once at construction so the
|
|
82
|
+
// rest of the service sees a single langgraph-native type.
|
|
83
|
+
const sqliteSaver = SqliteSaver.fromConnString(this.claimProcessingDbPath);
|
|
84
|
+
this.claimProcessingCheckpointer =
|
|
85
|
+
sqliteSaver;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Slice `heldAmount` into chunks no larger than `maxAmount`. Used when the
|
|
89
|
+
* total held amount exceeds the oracle's per-claim ceiling.
|
|
90
|
+
*/
|
|
91
|
+
calculateSplits(heldAmount, maxAmount) {
|
|
92
|
+
if (heldAmount <= maxAmount) {
|
|
93
|
+
return [heldAmount];
|
|
94
|
+
}
|
|
95
|
+
const splits = [];
|
|
96
|
+
let remaining = heldAmount;
|
|
97
|
+
while (remaining > 0) {
|
|
98
|
+
const chunk = Math.min(remaining, maxAmount);
|
|
99
|
+
splits.push(chunk);
|
|
100
|
+
remaining -= chunk;
|
|
101
|
+
}
|
|
102
|
+
return splits;
|
|
103
|
+
}
|
|
104
|
+
/** Step 1 of the workflow: pay the user's claim collection escrow. */
|
|
105
|
+
submitIntentTask = task({
|
|
106
|
+
name: 'submitIntent',
|
|
107
|
+
retry: this.retryPolicy,
|
|
108
|
+
}, async (params) => {
|
|
109
|
+
const collectionId = params.subscription.claimCollections.oracleClaimsCollectionId;
|
|
110
|
+
if (!collectionId) {
|
|
111
|
+
throw new Error('Oracle claims collection ID not found');
|
|
112
|
+
}
|
|
113
|
+
const paymentsClient = new Payments();
|
|
114
|
+
const hasActiveIntent = await paymentsClient.checkForActiveIntent({
|
|
115
|
+
userClaimCollection: collectionId,
|
|
116
|
+
granteeAddress: params.configService
|
|
117
|
+
.getOrThrow('ORACLE_DID')
|
|
118
|
+
.replace('did:ixo:', ''),
|
|
119
|
+
});
|
|
120
|
+
if (hasActiveIntent) {
|
|
121
|
+
this.logger.log(`User ${params.userDid} already has an active intent, skipping`);
|
|
122
|
+
return { success: true, transactionHash: null };
|
|
123
|
+
}
|
|
124
|
+
const intent = await paymentsClient.sendPaymentToEscrow({
|
|
125
|
+
amount: {
|
|
126
|
+
amount: params.heldAmount.toString(),
|
|
127
|
+
denom: params.denom,
|
|
128
|
+
},
|
|
129
|
+
userClaimCollection: collectionId,
|
|
130
|
+
});
|
|
131
|
+
if (intent.code !== 0) {
|
|
132
|
+
throw new Error(`Failed to send payment to escrow: ${intent.rawLog || 'Unknown error'}`);
|
|
133
|
+
}
|
|
134
|
+
this.logger.log(`Successfully sent payment to escrow for user: ${params.userDid} with intent tx hash: ${intent.transactionHash}`);
|
|
135
|
+
return { success: true, transactionHash: intent.transactionHash };
|
|
136
|
+
});
|
|
137
|
+
/** Step 2: build a signed claim and stash it in the oracle's Matrix room. */
|
|
138
|
+
saveToMatrixTask = task({
|
|
139
|
+
name: 'saveToMatrix',
|
|
140
|
+
retry: this.retryPolicy,
|
|
141
|
+
}, async (params) => {
|
|
142
|
+
const collectionId = params.subscription.claimCollections.oracleClaimsCollectionId;
|
|
143
|
+
if (!collectionId) {
|
|
144
|
+
throw new Error('Oracle claims collection ID not found');
|
|
145
|
+
}
|
|
146
|
+
const client = Client.getInstance();
|
|
147
|
+
await client.init();
|
|
148
|
+
const claimsClient = new Claims(client);
|
|
149
|
+
// Reuse the signing mnemonic that boot already pulled out of the
|
|
150
|
+
// oracle's Matrix account room. When this is null (cron tick beat the
|
|
151
|
+
// post-Matrix-init boot wiring), fall back to the original lookup so
|
|
152
|
+
// the claim still goes through.
|
|
153
|
+
const cachedSigningMnemonic = this.ucanService.getSigningMnemonic();
|
|
154
|
+
if (!cachedSigningMnemonic) {
|
|
155
|
+
this.logger.warn('Signing mnemonic not yet loaded by UcanService; falling back to per-claim Matrix lookup for this run');
|
|
156
|
+
}
|
|
157
|
+
const cid = await claimsClient.saveSignedClaimToMatrix({
|
|
158
|
+
accessToken: params.configService.getOrThrow('MATRIX_ORACLE_ADMIN_ACCESS_TOKEN'),
|
|
159
|
+
claim: {
|
|
160
|
+
amount: [
|
|
161
|
+
{
|
|
162
|
+
amount: params.heldAmount.toString(),
|
|
163
|
+
denom: params.denom,
|
|
164
|
+
},
|
|
165
|
+
],
|
|
166
|
+
body: {
|
|
167
|
+
amount: params.heldAmount,
|
|
168
|
+
oracleDid: params.configService.getOrThrow('ORACLE_DID'),
|
|
169
|
+
oracleEntityDid: params.configService.getOrThrow('ORACLE_ENTITY_DID'),
|
|
170
|
+
service: `Chatting With AI ${params.configService.getOrThrow('ORACLE_NAME')}`,
|
|
171
|
+
oracleName: params.configService.getOrThrow('ORACLE_NAME'),
|
|
172
|
+
userDid: params.userDid,
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
collectionId,
|
|
176
|
+
matrixRoomId: params.configService.get('MATRIX_ACCOUNT_ROOM_ID') ?? '',
|
|
177
|
+
secpMnemonic: params.configService.getOrThrow('SECP_MNEMONIC'),
|
|
178
|
+
matrixValuePin: params.configService.getOrThrow('MATRIX_VALUE_PIN'),
|
|
179
|
+
oracleDid: params.configService.getOrThrow('ORACLE_DID'),
|
|
180
|
+
network: params.configService.getOrThrow('NETWORK'),
|
|
181
|
+
decryptedSigningMnemonic: cachedSigningMnemonic ?? undefined,
|
|
182
|
+
});
|
|
183
|
+
this.logger.log(`Successfully submitted and saved signed claim ${cid} for user: ${params.userDid}`);
|
|
184
|
+
return { cid };
|
|
185
|
+
});
|
|
186
|
+
/** Step 3: submit the signed claim on-chain against the user's collection. */
|
|
187
|
+
submitToChainTask = task({
|
|
188
|
+
name: 'submitToChain',
|
|
189
|
+
retry: this.retryPolicy,
|
|
190
|
+
}, async (params) => {
|
|
191
|
+
const collectionId = params.subscription.claimCollections.oracleClaimsCollectionId;
|
|
192
|
+
if (!collectionId) {
|
|
193
|
+
throw new Error('Oracle claims collection ID not found');
|
|
194
|
+
}
|
|
195
|
+
const client = Client.getInstance();
|
|
196
|
+
await client.init();
|
|
197
|
+
const claimsClient = new Claims(client);
|
|
198
|
+
const result = await claimsClient.submitClaim({
|
|
199
|
+
claimId: params.cid,
|
|
200
|
+
collectionId,
|
|
201
|
+
useIntent: true,
|
|
202
|
+
amount: [
|
|
203
|
+
{
|
|
204
|
+
amount: params.heldAmount.toString(),
|
|
205
|
+
denom: params.denom,
|
|
206
|
+
},
|
|
207
|
+
],
|
|
208
|
+
});
|
|
209
|
+
if (result.code !== 0) {
|
|
210
|
+
throw new Error(`Failed to submit claim to chain: ${result.rawLog || 'Unknown error'}`);
|
|
211
|
+
}
|
|
212
|
+
this.logger.log(`Successfully submitted claim ${params.cid} to chain for user: ${params.userDid}`);
|
|
213
|
+
return { success: true, transactionHash: result.transactionHash };
|
|
214
|
+
});
|
|
215
|
+
/** Step 4: notify the subscription API so it can update the user's balance. */
|
|
216
|
+
sendToSubsApiTask = task({
|
|
217
|
+
name: 'sendToSubsApi',
|
|
218
|
+
retry: this.retryPolicy,
|
|
219
|
+
}, async (params) => {
|
|
220
|
+
const subscriptionUrl = this.configService.get('SUBSCRIPTION_URL') ??
|
|
221
|
+
getSubscriptionUrlByNetwork(params.configService.getOrThrow('NETWORK'));
|
|
222
|
+
await submitClaimToSubscriptionApi(subscriptionUrl, params.cid);
|
|
223
|
+
this.logger.log(`Successfully sent claim ${params.cid} to subscription API for user: ${params.userDid}`);
|
|
224
|
+
return { success: true };
|
|
225
|
+
});
|
|
226
|
+
/**
|
|
227
|
+
* Per-call factory so the langgraph `entrypoint` always picks up the
|
|
228
|
+
* checkpointer initialized in `constructor`.
|
|
229
|
+
*/
|
|
230
|
+
getProcessClaimWorkflow() {
|
|
231
|
+
return entrypoint({
|
|
232
|
+
checkpointer: this.claimProcessingCheckpointer,
|
|
233
|
+
name: 'processClaim',
|
|
234
|
+
}, async (params) => {
|
|
235
|
+
await this.submitIntentTask(params);
|
|
236
|
+
const { cid } = await this.saveToMatrixTask(params);
|
|
237
|
+
await this.submitToChainTask({ ...params, cid });
|
|
238
|
+
await this.sendToSubsApiTask({ ...params, cid });
|
|
239
|
+
return { success: true, cid };
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Cron-triggered processor — walks users above the minimum held-credits
|
|
244
|
+
* threshold, splits oversized batches against the oracle's per-claim max,
|
|
245
|
+
* and runs the 4-step claim workflow for each. Errors are logged and
|
|
246
|
+
* isolated per-user so one user's failure doesn't stall the batch.
|
|
247
|
+
*/
|
|
248
|
+
async processHeldAmount() {
|
|
249
|
+
const matrixAccountRoomId = this.configService.get('MATRIX_ACCOUNT_ROOM_ID');
|
|
250
|
+
const disableCredits = Boolean(this.configService.get('DISABLE_CREDITS')) ||
|
|
251
|
+
!matrixAccountRoomId;
|
|
252
|
+
if (disableCredits) {
|
|
253
|
+
this.logger.debug('Claims task submission skipped (DISABLE_CREDITS=true)');
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
const users = await this.tokenLimiter.listUsersWithHeldAmount(MINIMUM_CLAIM_THRESHOLD);
|
|
257
|
+
this.logger.log(`Processing held amount for ${users.length} users`);
|
|
258
|
+
for (const [userDid, rawHeldAmount] of users) {
|
|
259
|
+
try {
|
|
260
|
+
const heldAmount = Math.round(rawHeldAmount);
|
|
261
|
+
if (heldAmount < MINIMUM_CLAIM_THRESHOLD) {
|
|
262
|
+
this.logger.debug(`Held amount ${heldAmount} for user ${userDid} below threshold ${MINIMUM_CLAIM_THRESHOLD}, skipping`);
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
const subscription = await this.tokenLimiter.getSubscriptionPayload(userDid);
|
|
266
|
+
if (!subscription) {
|
|
267
|
+
this.logger.warn(`No subscription found for user: ${userDid}`);
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
if (!subscription.claimCollections.oracleClaimsCollectionId) {
|
|
271
|
+
this.logger.warn(`No oracle claims collection ID found for user: ${userDid}`);
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
const availableCredits = subscription.totalCredits;
|
|
275
|
+
if (availableCredits < heldAmount) {
|
|
276
|
+
this.logger.warn(`Insufficient available credits found for user: ${userDid}`);
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
const oraclePricingList = await Payments.getOraclePricingList(this.configService.getOrThrow('ORACLE_ENTITY_DID'));
|
|
280
|
+
const maxAllowedClaimAmount = oraclePricingList.find((item) => item.denom === this.denom)?.amount;
|
|
281
|
+
if (!maxAllowedClaimAmount) {
|
|
282
|
+
throw new InternalServerErrorException(`Max allowed claim amount not found for denom: ${this.denom}`);
|
|
283
|
+
}
|
|
284
|
+
const maxAmount = parseInt(maxAllowedClaimAmount, 10);
|
|
285
|
+
const splits = this.calculateSplits(heldAmount, maxAmount);
|
|
286
|
+
const collectionId = subscription.claimCollections.oracleClaimsCollectionId;
|
|
287
|
+
const subscriptionForProcessing = {
|
|
288
|
+
adminAddress: subscription.adminAddress,
|
|
289
|
+
claimCollections: {
|
|
290
|
+
oracleClaimsCollectionId: collectionId,
|
|
291
|
+
},
|
|
292
|
+
totalCredits: subscription.totalCredits,
|
|
293
|
+
};
|
|
294
|
+
if (splits.length > 1) {
|
|
295
|
+
this.logger.log(`Held amount ${heldAmount} for user ${userDid} exceeds max allowed ${maxAmount}. Splitting into ${splits.length} chunks: ${splits.join(', ')}`);
|
|
296
|
+
for (let i = 0; i < splits.length; i++) {
|
|
297
|
+
const splitAmount = splits[i];
|
|
298
|
+
try {
|
|
299
|
+
await this.processAmount(userDid, splitAmount, subscriptionForProcessing, {
|
|
300
|
+
index: i + 1,
|
|
301
|
+
total: splits.length,
|
|
302
|
+
originalAmount: heldAmount,
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
catch (error) {
|
|
306
|
+
this.logger.error(`Error processing split ${i + 1}/${splits.length} for user ${userDid}:`, error instanceof Error ? error.message : String(error), error instanceof Error ? error.stack : undefined);
|
|
307
|
+
throw new Error(`Failed to process split ${i + 1}/${splits.length}: ${error instanceof Error ? error.message : String(error)}`);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
this.logger.log(`Successfully processed all ${splits.length} splits for user: ${userDid}`);
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
this.logger.log(`Processing held amount ${heldAmount} for user ${userDid} (no splitting needed)`);
|
|
314
|
+
await this.processAmount(userDid, heldAmount, subscriptionForProcessing);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
catch (error) {
|
|
318
|
+
this.logger.error(`Error processing held amount for user ${userDid}:`, error instanceof Error ? error.message : String(error), error instanceof Error ? error.stack : undefined);
|
|
319
|
+
// Don't clear held amount or pending claim - will retry next run.
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Invoke the LangGraph workflow for a single amount (full or split chunk)
|
|
325
|
+
* and reconcile the held-amount / pending-claim records on success.
|
|
326
|
+
*/
|
|
327
|
+
async processAmount(userDid, heldAmount, subscription, splitContext) {
|
|
328
|
+
if (heldAmount <= 0) {
|
|
329
|
+
throw new Error(`Invalid held amount: ${heldAmount}. Must be greater than 0.`);
|
|
330
|
+
}
|
|
331
|
+
if (splitContext) {
|
|
332
|
+
this.logger.log(`Processing split ${splitContext.index}/${splitContext.total} (amount: ${heldAmount}, original: ${splitContext.originalAmount}) for user: ${userDid}`);
|
|
333
|
+
}
|
|
334
|
+
const internalClaimId = await this.tokenLimiter.getOrCreatePendingClaim(userDid, heldAmount);
|
|
335
|
+
const workflowParams = {
|
|
336
|
+
userDid,
|
|
337
|
+
heldAmount,
|
|
338
|
+
subscription,
|
|
339
|
+
internalClaimId,
|
|
340
|
+
denom: this.denom,
|
|
341
|
+
configService: this.configService,
|
|
342
|
+
};
|
|
343
|
+
// Unique thread ID per split so checkpointer state doesn't collide.
|
|
344
|
+
const threadId = splitContext
|
|
345
|
+
? `${userDid}:${internalClaimId}:split${splitContext.index}`
|
|
346
|
+
: `${userDid}:${internalClaimId}`;
|
|
347
|
+
const config = {
|
|
348
|
+
configurable: {
|
|
349
|
+
thread_id: threadId,
|
|
350
|
+
},
|
|
351
|
+
};
|
|
352
|
+
const workflow = this.getProcessClaimWorkflow();
|
|
353
|
+
const result = await workflow.invoke(workflowParams, config);
|
|
354
|
+
if (result.success && result.cid) {
|
|
355
|
+
await this.tokenLimiter.clearPendingClaim(userDid);
|
|
356
|
+
if (splitContext) {
|
|
357
|
+
await this.tokenLimiter.incrementUserHeldAmount(userDid, -heldAmount);
|
|
358
|
+
this.logger.log(`Successfully processed split ${splitContext.index}/${splitContext.total} (claim ${result.cid}) and decremented held amount by ${heldAmount} for user: ${userDid}`);
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
await this.tokenLimiter.deleteUserHeldAmount(userDid);
|
|
362
|
+
this.logger.log(`Successfully processed claim ${result.cid} and cleared held amount and pending claim for user: ${userDid}`);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
this.logger.warn(`Workflow completed but result indicates failure for user: ${userDid}${splitContext
|
|
367
|
+
? ` (split ${splitContext.index}/${splitContext.total})`
|
|
368
|
+
: ''}`);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
__decorate([
|
|
373
|
+
Cron(CronExpression.EVERY_MINUTE),
|
|
374
|
+
__metadata("design:type", Function),
|
|
375
|
+
__metadata("design:paramtypes", []),
|
|
376
|
+
__metadata("design:returntype", Promise)
|
|
377
|
+
], ClaimProcessingService.prototype, "processHeldAmount", null);
|
|
378
|
+
ClaimProcessingService = ClaimProcessingService_1 = __decorate([
|
|
379
|
+
Injectable(),
|
|
380
|
+
__param(2, Optional()),
|
|
381
|
+
__param(2, Inject(CLAIM_PROCESSING_TOKEN_LIMITER)),
|
|
382
|
+
__metadata("design:paramtypes", [ConfigService,
|
|
383
|
+
UcanService,
|
|
384
|
+
TokenLimiter])
|
|
385
|
+
], ClaimProcessingService);
|
|
386
|
+
export { ClaimProcessingService };
|
|
387
|
+
/**
|
|
388
|
+
* Submit a saved claim to the subscription-API webhook so the upstream
|
|
389
|
+
* service can mark it credited. Kept inline (rather than a separate file)
|
|
390
|
+
* since it's only used here and trivial.
|
|
391
|
+
*/
|
|
392
|
+
export async function submitClaimToSubscriptionApi(subscriptionApiUrl, claimId) {
|
|
393
|
+
const webhookUrl = `${subscriptionApiUrl}/api/v1/webhook/claim-submitted`;
|
|
394
|
+
Logger.log('Submitting claim to subscription API', 'SubmitClaimToSubscriptionApi', { webhookUrl, claimId });
|
|
395
|
+
const response = await fetch(webhookUrl, {
|
|
396
|
+
method: 'POST',
|
|
397
|
+
headers: { 'Content-Type': 'application/json' },
|
|
398
|
+
body: JSON.stringify({ claimId }),
|
|
399
|
+
});
|
|
400
|
+
if (!response.ok) {
|
|
401
|
+
const errorBody = await response.text();
|
|
402
|
+
Logger.error(`Subscription API error: ${response.status} ${errorBody}`, 'SubmitClaimToSubscriptionApi', { status: response.status, errorBody, claimId });
|
|
403
|
+
throw new Error(`Subscription API error: ${response.status} ${errorBody}`);
|
|
404
|
+
}
|
|
405
|
+
return (await response.json());
|
|
406
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type AgentMiddleware } from 'langchain';
|
|
2
|
+
import type { Logger } from '../../plugin-api/types.js';
|
|
3
|
+
import { type TokenLimiter } from './token-limiter.js';
|
|
4
|
+
export interface CreditsMiddlewareOptions {
|
|
5
|
+
/** Active limiter. When `null`, the middleware skips silently. */
|
|
6
|
+
limiter: TokenLimiter | null;
|
|
7
|
+
/** Optional logger; defaults to a no-op. */
|
|
8
|
+
logger?: Logger;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Per-user credit-budget guard. Runs on every model call:
|
|
12
|
+
*
|
|
13
|
+
* - `beforeModel` aborts the call with a polite message when the user
|
|
14
|
+
* has no remaining balance.
|
|
15
|
+
* - `afterModel` computes the credit cost of the completion (3-priority
|
|
16
|
+
* fallback: provider USD cost → per-model pricing → flat rate) and
|
|
17
|
+
* deducts it atomically via `TokenLimiter.limit`.
|
|
18
|
+
*
|
|
19
|
+
* Silently passes through when `limiter` is `null` — that's how the credits
|
|
20
|
+
* plugin signals "disabled or no Redis" without breaking the graph.
|
|
21
|
+
*/
|
|
22
|
+
export declare const createCreditsMiddleware: (options: CreditsMiddlewareOptions) => AgentMiddleware;
|
|
23
|
+
//# sourceMappingURL=credits-middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credits-middleware.d.ts","sourceRoot":"","sources":["../../../src/plugins/credits/credits-middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,eAAe,EAAoB,MAAM,WAAW,CAAC;AAEnE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,KAAK,YAAY,EAAqB,MAAM,oBAAoB,CAAC;AAQ1E,MAAM,WAAW,wBAAwB;IACvC,kEAAkE;IAClE,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;IAC7B,4CAA4C;IAC5C,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAiFD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,uBAAuB,GAClC,SAAS,wBAAwB,KAChC,eAwFF,CAAC"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { AIMessageChunk } from '@langchain/core/messages';
|
|
2
|
+
import { createMiddleware } from 'langchain';
|
|
3
|
+
import { mainAgentRequestContextSchema } from '../../graph/main-agent-types.js';
|
|
4
|
+
import { TokenLimiterError } from './token-limiter.js';
|
|
5
|
+
const NOOP_LOGGER = {
|
|
6
|
+
log: () => undefined,
|
|
7
|
+
warn: () => undefined,
|
|
8
|
+
error: () => undefined,
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Extract `user.did` from the LangGraph runtime context without trusting
|
|
12
|
+
* its shape. The runtime channel is typed `unknown` in plain middlewares,
|
|
13
|
+
* so narrowing is the only honest way to read identity off it.
|
|
14
|
+
*/
|
|
15
|
+
function extractUserDid(context) {
|
|
16
|
+
if (!context || typeof context !== 'object' || !('user' in context)) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
const { user } = context;
|
|
20
|
+
if (!user || typeof user !== 'object' || !('did' in user)) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
const { did } = user;
|
|
24
|
+
return typeof did === 'string' && did.length > 0 ? did : undefined;
|
|
25
|
+
}
|
|
26
|
+
function extractUsageMetadata(message) {
|
|
27
|
+
if (!message ||
|
|
28
|
+
typeof message !== 'object' ||
|
|
29
|
+
!('usage_metadata' in message)) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
const meta = message.usage_metadata;
|
|
33
|
+
if (!meta || typeof meta !== 'object')
|
|
34
|
+
return undefined;
|
|
35
|
+
const m = meta;
|
|
36
|
+
if (typeof m.input_tokens === 'number' &&
|
|
37
|
+
typeof m.output_tokens === 'number' &&
|
|
38
|
+
typeof m.total_tokens === 'number') {
|
|
39
|
+
return {
|
|
40
|
+
input_tokens: m.input_tokens,
|
|
41
|
+
output_tokens: m.output_tokens,
|
|
42
|
+
total_tokens: m.total_tokens,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
function extractResponseMeta(message) {
|
|
48
|
+
if (!message ||
|
|
49
|
+
typeof message !== 'object' ||
|
|
50
|
+
!('response_metadata' in message)) {
|
|
51
|
+
return {};
|
|
52
|
+
}
|
|
53
|
+
const meta = message.response_metadata;
|
|
54
|
+
if (!meta || typeof meta !== 'object')
|
|
55
|
+
return {};
|
|
56
|
+
const m = meta;
|
|
57
|
+
const result = {};
|
|
58
|
+
const usage = m.usage;
|
|
59
|
+
if (usage &&
|
|
60
|
+
typeof usage === 'object' &&
|
|
61
|
+
typeof usage.cost === 'number') {
|
|
62
|
+
result.providerCost = usage.cost;
|
|
63
|
+
}
|
|
64
|
+
if (typeof m.model === 'string') {
|
|
65
|
+
result.model = m.model;
|
|
66
|
+
}
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Per-user credit-budget guard. Runs on every model call:
|
|
71
|
+
*
|
|
72
|
+
* - `beforeModel` aborts the call with a polite message when the user
|
|
73
|
+
* has no remaining balance.
|
|
74
|
+
* - `afterModel` computes the credit cost of the completion (3-priority
|
|
75
|
+
* fallback: provider USD cost → per-model pricing → flat rate) and
|
|
76
|
+
* deducts it atomically via `TokenLimiter.limit`.
|
|
77
|
+
*
|
|
78
|
+
* Silently passes through when `limiter` is `null` — that's how the credits
|
|
79
|
+
* plugin signals "disabled or no Redis" without breaking the graph.
|
|
80
|
+
*/
|
|
81
|
+
export const createCreditsMiddleware = (options) => {
|
|
82
|
+
const logger = options.logger ?? NOOP_LOGGER;
|
|
83
|
+
const { limiter } = options;
|
|
84
|
+
return createMiddleware({
|
|
85
|
+
name: 'TokenLimiterMiddleware',
|
|
86
|
+
beforeModel: async (state, runtime) => {
|
|
87
|
+
if (!limiter) {
|
|
88
|
+
logger.debug?.('Credits middleware skipped (limiter unavailable — credits disabled or no Redis)');
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const userDid = extractUserDid(runtime.context);
|
|
92
|
+
if (!userDid) {
|
|
93
|
+
throw new Error('User DID is required for credit limiting');
|
|
94
|
+
}
|
|
95
|
+
const remaining = await limiter.getRemaining(userDid);
|
|
96
|
+
logger.debug?.(`Remaining credits: ${remaining} for user ${userDid}`);
|
|
97
|
+
if (remaining <= 0) {
|
|
98
|
+
return {
|
|
99
|
+
messages: [
|
|
100
|
+
...state.messages,
|
|
101
|
+
new AIMessageChunk({
|
|
102
|
+
content: `Looks like you have run out of tokens. Please upgrade your plan or topup your balance. You have ${remaining} tokens remaining.`,
|
|
103
|
+
}),
|
|
104
|
+
],
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
afterModel: async (state, runtime) => {
|
|
109
|
+
if (!limiter)
|
|
110
|
+
return;
|
|
111
|
+
try {
|
|
112
|
+
const userDid = extractUserDid(runtime.context);
|
|
113
|
+
if (!userDid) {
|
|
114
|
+
throw new Error('User DID is required for credit limiting');
|
|
115
|
+
}
|
|
116
|
+
const lastMessage = state.messages.at(-1);
|
|
117
|
+
const usage = extractUsageMetadata(lastMessage);
|
|
118
|
+
if (!usage) {
|
|
119
|
+
// No AI response with usage metadata to deduct against — happens
|
|
120
|
+
// when `beforeModel` short-circuited the call, or when the graph
|
|
121
|
+
// resumed on a non-AI message. Nothing to bill, skip silently.
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const { providerCost, model } = extractResponseMeta(lastMessage);
|
|
125
|
+
const credits = limiter.creditsForUsage({
|
|
126
|
+
providerCost,
|
|
127
|
+
inputTokens: usage.input_tokens,
|
|
128
|
+
outputTokens: usage.output_tokens,
|
|
129
|
+
totalTokens: usage.total_tokens,
|
|
130
|
+
model,
|
|
131
|
+
});
|
|
132
|
+
logger.log(`[Credits] input=${usage.input_tokens} output=${usage.output_tokens} total=${usage.total_tokens} | credits=${credits}`);
|
|
133
|
+
const result = await limiter.limit(userDid, credits);
|
|
134
|
+
logger.debug?.(`Credit limit result: ${JSON.stringify(result)}`);
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
if (error instanceof TokenLimiterError) {
|
|
138
|
+
logger.error(`Credit limit error: ${error.message}`);
|
|
139
|
+
return {
|
|
140
|
+
messages: [
|
|
141
|
+
...state.messages,
|
|
142
|
+
new AIMessageChunk({
|
|
143
|
+
content: `Looks like you have run out of tokens. Please upgrade your plan or topup your balance. You have ${error.currentBalance?.toFixed(2) ?? '0'} tokens remaining.`,
|
|
144
|
+
}),
|
|
145
|
+
],
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
logger.error(`Error in CreditsMiddleware: ${error instanceof Error ? error.message : String(error)}`);
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
contextSchema: mainAgentRequestContextSchema,
|
|
153
|
+
});
|
|
154
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { DynamicModule, Type } from '@nestjs/common';
|
|
2
|
+
import type { Redis } from 'ioredis';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { OraclePlugin } from '../../plugin-api/oracle-plugin.js';
|
|
5
|
+
import type { AgentMiddleware, PluginContext, PluginManifest } from '../../plugin-api/types.js';
|
|
6
|
+
import { type CreditsNetwork, type ModelPricingLookup } from './token-limiter.js';
|
|
7
|
+
/** Constructor options for the credits plugin. */
|
|
8
|
+
export interface CreditsPluginOptions {
|
|
9
|
+
/**
|
|
10
|
+
* The ioredis client used for credit balance + atomic limit. `null`
|
|
11
|
+
* disables the middleware (e.g. Redis not configured). Forks pass the
|
|
12
|
+
* same client they already use elsewhere in the app.
|
|
13
|
+
*/
|
|
14
|
+
redis?: Redis | null;
|
|
15
|
+
/**
|
|
16
|
+
* Network tier — required when `redis` is set, so the claim-processing
|
|
17
|
+
* Nest module can construct its `TokenLimiter` at boot. Omitted in tests
|
|
18
|
+
* that don't exercise the cron path.
|
|
19
|
+
*/
|
|
20
|
+
network?: CreditsNetwork;
|
|
21
|
+
/** Optional per-model pricing lookup; defaults to flat-rate fallback. */
|
|
22
|
+
modelPricingLookup?: ModelPricingLookup;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Owns the full credit lifecycle:
|
|
26
|
+
* - **Enforcement**: per-request middleware that aborts model calls when
|
|
27
|
+
* the user is out of credits (`createCreditsMiddleware` + `TokenLimiter`).
|
|
28
|
+
* - **Settlement**: background cron that converts held credits into
|
|
29
|
+
* on-chain claims, shipped via `ClaimProcessingModule` (returned from
|
|
30
|
+
* `getNestModules()` when Redis is configured).
|
|
31
|
+
*
|
|
32
|
+
* Silent (no agent-visible tools). Stays loaded by default and only opts
|
|
33
|
+
* out when `DISABLE_CREDITS=true`. When loaded, this plugin also activates
|
|
34
|
+
* the runtime's Tier-0 `SubscriptionMiddleware`, which gates the HTTP
|
|
35
|
+
* request before the graph even runs.
|
|
36
|
+
*/
|
|
37
|
+
export declare class CreditsPlugin extends OraclePlugin {
|
|
38
|
+
static readonly NAME = "credits";
|
|
39
|
+
readonly name = "credits";
|
|
40
|
+
readonly version = "1.0.0";
|
|
41
|
+
readonly manifest: PluginManifest;
|
|
42
|
+
readonly configSchema: z.ZodObject<{
|
|
43
|
+
SUBSCRIPTION_URL: z.ZodOptional<z.ZodURL>;
|
|
44
|
+
SUBSCRIPTION_ORACLE_MCP_URL: z.ZodOptional<z.ZodURL>;
|
|
45
|
+
}, z.core.$strip>;
|
|
46
|
+
readonly autoDetectHint = "DISABLE_CREDITS!=true";
|
|
47
|
+
private readonly redis;
|
|
48
|
+
private readonly network?;
|
|
49
|
+
private readonly modelPricingLookup?;
|
|
50
|
+
constructor(options?: CreditsPluginOptions);
|
|
51
|
+
autoDetect(env: NodeJS.ProcessEnv): boolean;
|
|
52
|
+
getMiddlewares(ctx: PluginContext): AgentMiddleware[];
|
|
53
|
+
getNestModules(): Array<Type | DynamicModule>;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=credits.plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credits.plugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/credits/credits.plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACb,cAAc,EACf,MAAM,2BAA2B,CAAC;AAKnC,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACxB,MAAM,oBAAoB,CAAC;AAE5B,kDAAkD;AAClD,MAAM,WAAW,oBAAoB;IACnC;;;;OAIG;IACH,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;IACrB;;;;OAIG;IACH,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,yEAAyE;IACzE,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CACzC;AAcD;;;;;;;;;;;;GAYG;AACH,qBAAa,aAAc,SAAQ,YAAY;IAC7C,MAAM,CAAC,QAAQ,CAAC,IAAI,aAAa;IAEjC,QAAQ,CAAC,IAAI,aAAsB;IAEnC,QAAQ,CAAC,OAAO,WAAW;IAE3B,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAQ/B;IAEF,SAAkB,YAAY;;;sBAAuB;IAErD,SAAkB,cAAc,2BAA2B;IAE3D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;IAErC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAiB;IAE1C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAqB;gBAE7C,OAAO,GAAE,oBAAyB;IAOrC,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG,OAAO;IAI3C,cAAc,CAAC,GAAG,EAAE,aAAa,GAAG,eAAe,EAAE;IAsBrD,cAAc,IAAI,KAAK,CAAC,IAAI,GAAG,aAAa,CAAC;CA2BvD"}
|