@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,139 @@
|
|
|
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
|
+
import { SessionManagerService } from '@ixo/common';
|
|
11
|
+
import { BadRequestException, Injectable, NotFoundException, } from '@nestjs/common';
|
|
12
|
+
import { ConfigService } from '@nestjs/config';
|
|
13
|
+
import * as crypto from 'node:crypto';
|
|
14
|
+
import { UserMatrixSqliteSyncService } from '../../matrix/checkpointer/user-matrix-sqlite-sync-service.service.js';
|
|
15
|
+
import { HomeServerCache } from './homeserver-cache.js';
|
|
16
|
+
/**
|
|
17
|
+
* Resolves everything the agent build needs from the incoming request:
|
|
18
|
+
*
|
|
19
|
+
* - session lookup (parallel with the Matrix → SQLite sync triggered the
|
|
20
|
+
* first time we see this user this process)
|
|
21
|
+
* - room id resolution (uses the cached value when present, otherwise asks
|
|
22
|
+
* Matrix)
|
|
23
|
+
* - per-DID home-server cache
|
|
24
|
+
* - timezone / current-time extraction
|
|
25
|
+
* - the `runnableConfig` LangGraph needs for checkpointing
|
|
26
|
+
*
|
|
27
|
+
* Construction is hot-path code — every chat request runs this once.
|
|
28
|
+
*/
|
|
29
|
+
let RequestPreparer = class RequestPreparer {
|
|
30
|
+
sessions;
|
|
31
|
+
checkpointSync;
|
|
32
|
+
homeServerCache;
|
|
33
|
+
config;
|
|
34
|
+
constructor(sessions, checkpointSync, homeServerCache, config) {
|
|
35
|
+
this.sessions = sessions;
|
|
36
|
+
this.checkpointSync = checkpointSync;
|
|
37
|
+
this.homeServerCache = homeServerCache;
|
|
38
|
+
this.config = config;
|
|
39
|
+
}
|
|
40
|
+
async prepare(payload) {
|
|
41
|
+
const did = payload.did;
|
|
42
|
+
const sessionId = payload.sessionId;
|
|
43
|
+
const requestId = payload.stream && 'requestId' in payload
|
|
44
|
+
? payload.requestId
|
|
45
|
+
: crypto.randomUUID();
|
|
46
|
+
const homeServerName = payload.homeServer ?? (await this.homeServerCache.get(did));
|
|
47
|
+
// Per-process sync-once is owned by `UserMatrixSqliteSyncService` — the
|
|
48
|
+
// first request per user warms the SQLite, subsequent requests reuse it.
|
|
49
|
+
// We still kick the warm-up in parallel with the session lookup so the
|
|
50
|
+
// first-time path stays as fast as possible.
|
|
51
|
+
const [, targetSession] = await Promise.all([
|
|
52
|
+
this.checkpointSync.getUserDatabase(did),
|
|
53
|
+
this.sessions.getSession(sessionId, did, false),
|
|
54
|
+
]);
|
|
55
|
+
if (!targetSession) {
|
|
56
|
+
throw new NotFoundException('Session not found');
|
|
57
|
+
}
|
|
58
|
+
let roomId = targetSession.roomId;
|
|
59
|
+
if (!roomId) {
|
|
60
|
+
const oracleEntityDid = this.config.getOrThrow('ORACLE_ENTITY_DID');
|
|
61
|
+
const roomResult = await this.sessions.matrixManger.getOracleRoomIdWithHomeServer({
|
|
62
|
+
userDid: did,
|
|
63
|
+
oracleEntityDid,
|
|
64
|
+
userHomeServer: homeServerName,
|
|
65
|
+
});
|
|
66
|
+
roomId = roomResult.roomId;
|
|
67
|
+
if (!roomId) {
|
|
68
|
+
throw new NotFoundException('Room not found or Invalid Session Id');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const timezone = this.resolveTimezone(payload, payload.req);
|
|
72
|
+
const currentTime = timezone
|
|
73
|
+
? this.formatTimeInTimezone(timezone)
|
|
74
|
+
: undefined;
|
|
75
|
+
const threadId = payload.overrideLangchainThreadId ?? sessionId;
|
|
76
|
+
const runnableConfig = {
|
|
77
|
+
configurable: {
|
|
78
|
+
thread_id: threadId,
|
|
79
|
+
requestId,
|
|
80
|
+
sessionId: threadId,
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
return {
|
|
84
|
+
sessionId,
|
|
85
|
+
langchainThreadId: threadId,
|
|
86
|
+
roomId,
|
|
87
|
+
homeServerName,
|
|
88
|
+
requestId,
|
|
89
|
+
runnableConfig,
|
|
90
|
+
targetSession,
|
|
91
|
+
timezone,
|
|
92
|
+
currentTime,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
validateSessionId(sessionId, did) {
|
|
96
|
+
if (!sessionId || !did) {
|
|
97
|
+
throw new BadRequestException('Invalid parameters');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
resolveTimezone(payload, req) {
|
|
101
|
+
if (payload?.timezone) {
|
|
102
|
+
return payload.timezone.trim() || undefined;
|
|
103
|
+
}
|
|
104
|
+
const header = req?.headers['x-timezone'];
|
|
105
|
+
if (!header)
|
|
106
|
+
return undefined;
|
|
107
|
+
const tz = typeof header === 'string' ? header : header[0];
|
|
108
|
+
return tz?.trim() || undefined;
|
|
109
|
+
}
|
|
110
|
+
formatTimeInTimezone(timezone) {
|
|
111
|
+
try {
|
|
112
|
+
return new Intl.DateTimeFormat('en-US', {
|
|
113
|
+
timeZone: timezone,
|
|
114
|
+
year: 'numeric',
|
|
115
|
+
month: 'long',
|
|
116
|
+
day: 'numeric',
|
|
117
|
+
hour: 'numeric',
|
|
118
|
+
minute: '2-digit',
|
|
119
|
+
second: '2-digit',
|
|
120
|
+
hour12: true,
|
|
121
|
+
timeZoneName: 'short',
|
|
122
|
+
}).format(new Date());
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
return new Date().toLocaleString('en-US', {
|
|
126
|
+
timeZone: 'UTC',
|
|
127
|
+
timeZoneName: 'short',
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
RequestPreparer = __decorate([
|
|
133
|
+
Injectable(),
|
|
134
|
+
__metadata("design:paramtypes", [SessionManagerService,
|
|
135
|
+
UserMatrixSqliteSyncService,
|
|
136
|
+
HomeServerCache,
|
|
137
|
+
ConfigService])
|
|
138
|
+
], RequestPreparer);
|
|
139
|
+
export { RequestPreparer };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Response } from 'express';
|
|
2
|
+
import { type BaseMessage } from 'langchain';
|
|
3
|
+
import { AgentBuilder } from './agent-builder.js';
|
|
4
|
+
import { type SendMessagePayload } from './dto/send-message.dto.js';
|
|
5
|
+
import { type PreparedRequest } from './request-preparer.js';
|
|
6
|
+
export interface StreamRunInput {
|
|
7
|
+
payload: SendMessagePayload & {
|
|
8
|
+
msgFromMatrixRoom?: boolean;
|
|
9
|
+
clientType?: 'matrix' | 'slack' | 'portal';
|
|
10
|
+
};
|
|
11
|
+
prepared: PreparedRequest;
|
|
12
|
+
inputMessages: BaseMessage[];
|
|
13
|
+
res: Response;
|
|
14
|
+
abortControllers: Map<string, AbortController>;
|
|
15
|
+
/**
|
|
16
|
+
* Called once the agent stream completes with the assembled assistant
|
|
17
|
+
* content, so the orchestrator can fire-and-forget Matrix replay and
|
|
18
|
+
* post-message sync without coupling SseStreamRunner to either.
|
|
19
|
+
*/
|
|
20
|
+
onComplete?: (assistantText: string) => void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Owns the SSE side of the chat request: headers, heartbeat, abort
|
|
24
|
+
* controller registration, and the for-await loop translating
|
|
25
|
+
* `streamEvents` output into the wire format the frontend consumes.
|
|
26
|
+
*
|
|
27
|
+
* Event types preserved verbatim from the legacy implementation:
|
|
28
|
+
*
|
|
29
|
+
* - `ReasoningEvent` (thinking + chunked reasoning + completion marker)
|
|
30
|
+
* - `ToolCallEvent` (server-executed tools — fired on `tool_calls`)
|
|
31
|
+
* - `ActionCallEvent` (AG-UI actions — same `tool_calls` channel but
|
|
32
|
+
* named in `payload.agActions`; the runner branches on the name)
|
|
33
|
+
* - `message` chunk (plain assistant text)
|
|
34
|
+
* - `error` + `done`
|
|
35
|
+
*
|
|
36
|
+
* The SSE headers and the first `Thinking...` event are emitted by
|
|
37
|
+
* `MessagesController` BEFORE the orchestrator hands off — this class
|
|
38
|
+
* picks up after the connection is open, so we don't pay the pre-flight
|
|
39
|
+
* latency before the client knows the request was accepted.
|
|
40
|
+
*/
|
|
41
|
+
export declare class SseStreamRunner {
|
|
42
|
+
private readonly agentBuilder;
|
|
43
|
+
private readonly logger;
|
|
44
|
+
constructor(agentBuilder: AgentBuilder);
|
|
45
|
+
run(input: StreamRunInput): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Fires when an agent invokes a tool. `data.input` carries the fully
|
|
48
|
+
* parsed args — the right place to emit the `isRunning` event with
|
|
49
|
+
* complete args. We key the map by `run_id` from the event envelope so
|
|
50
|
+
* the matching `on_tool_end` (which shares the same `run_id`) can pair
|
|
51
|
+
* with it regardless of how the model formatted the original
|
|
52
|
+
* `tool_call_id`.
|
|
53
|
+
*/
|
|
54
|
+
private handleToolStart;
|
|
55
|
+
private handleToolEnd;
|
|
56
|
+
/**
|
|
57
|
+
* Emit a terminal `error` event for any tool/action call that started but
|
|
58
|
+
* never received a matching `on_tool_end`. Keeps the frontend from
|
|
59
|
+
* showing a perpetually-spinning tool when the agent ends a turn with
|
|
60
|
+
* unresolved tool runs in flight.
|
|
61
|
+
*/
|
|
62
|
+
private flushOrphanedToolCalls;
|
|
63
|
+
/**
|
|
64
|
+
* Emits reasoning + text chunks. Tool-call emission has moved to
|
|
65
|
+
* `handleToolStart` (which fires on `on_tool_start` with full,
|
|
66
|
+
* finalized args) — the chunk's partial `tool_calls` deltas are
|
|
67
|
+
* intentionally ignored here to avoid emitting an `isRunning` event
|
|
68
|
+
* with empty args before the model finishes producing the call.
|
|
69
|
+
*/
|
|
70
|
+
private handleChatStream;
|
|
71
|
+
private writeSse;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=sse-stream-runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse-stream-runner.d.ts","sourceRoot":"","sources":["../../../src/modules/messages/sse-stream-runner.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAkB,KAAK,WAAW,EAAe,MAAM,WAAW,CAAC;AAE1E,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAyG7D,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,kBAAkB,GAAG;QAC5B,iBAAiB,CAAC,EAAE,OAAO,CAAC;QAC5B,UAAU,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC;KAC5C,CAAC;IACF,QAAQ,EAAE,eAAe,CAAC;IAC1B,aAAa,EAAE,WAAW,EAAE,CAAC;IAC7B,GAAG,EAAE,QAAQ,CAAC;IACd,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC/C;;;;OAIG;IACH,UAAU,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9C;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBACa,eAAe;IAGd,OAAO,CAAC,QAAQ,CAAC,YAAY;IAFzC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoC;gBAE9B,YAAY,EAAE,YAAY;IAEjD,GAAG,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAsK/C;;;;;;;OAOG;IACH,OAAO,CAAC,eAAe;IAoDvB,OAAO,CAAC,aAAa;IAgDrB;;;;;OAKG;IACH,OAAO,CAAC,sBAAsB;IA2B9B;;;;;;OAMG;IACH,OAAO,CAAC,gBAAgB;IAmDxB,OAAO,CAAC,QAAQ;CASjB"}
|
|
@@ -0,0 +1,352 @@
|
|
|
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 SseStreamRunner_1;
|
|
11
|
+
import { ActionCallEvent, ReasoningEvent, ToolCallEvent, } from '@ixo/oracles-events';
|
|
12
|
+
import { Injectable, Logger } from '@nestjs/common';
|
|
13
|
+
import { emojify } from '../../utils/emoji.js';
|
|
14
|
+
import { AgentBuilder } from './agent-builder.js';
|
|
15
|
+
import { emitSSEEvent, formatSSE, runWithSSEContext, sendSSEDone, sendSSEError, setSSEHeaders, startSSEHeartbeat, } from './sse.utils.js';
|
|
16
|
+
const THINKING_PHRASES = [
|
|
17
|
+
'Thinking...',
|
|
18
|
+
'Working...',
|
|
19
|
+
'Analyzing...',
|
|
20
|
+
'Processing...',
|
|
21
|
+
'Computing...',
|
|
22
|
+
'Crunching...',
|
|
23
|
+
'Deliberating...',
|
|
24
|
+
'Reasoning...',
|
|
25
|
+
'Calculating...',
|
|
26
|
+
'Evaluating...',
|
|
27
|
+
'Pondering...',
|
|
28
|
+
'Reading...',
|
|
29
|
+
'Synthesizing...',
|
|
30
|
+
'Formulating...',
|
|
31
|
+
'Considering...',
|
|
32
|
+
'Exploring ideas...',
|
|
33
|
+
'Investigating...',
|
|
34
|
+
'Brainstorming...',
|
|
35
|
+
'Solving...',
|
|
36
|
+
'Reviewing...',
|
|
37
|
+
'Reflecting...',
|
|
38
|
+
];
|
|
39
|
+
function pickThinkingPhrase() {
|
|
40
|
+
return THINKING_PHRASES[Math.floor(Math.random() * THINKING_PHRASES.length)];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Parse a `ToolMessage.content` payload into a JSON object when possible.
|
|
44
|
+
* Returns `null` if the content is a non-JSON string, an array of content
|
|
45
|
+
* blocks (LangChain multi-modal output), or anything else we can't reason
|
|
46
|
+
* about. Used by the action-call status decoder to detect failures.
|
|
47
|
+
*/
|
|
48
|
+
function safeParseToolContent(content) {
|
|
49
|
+
if (typeof content === 'string') {
|
|
50
|
+
try {
|
|
51
|
+
const parsed = JSON.parse(content);
|
|
52
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
53
|
+
return parsed;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// Non-JSON text — fall through.
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
if (content && typeof content === 'object' && !Array.isArray(content)) {
|
|
62
|
+
return content;
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Unwrap the args object emitted on `on_tool_start.data.input`. MCP tools
|
|
68
|
+
* surface their args as `{ input: "<json-string>" }` because their schema
|
|
69
|
+
* accepts a single stringified payload — parse the inner JSON so the
|
|
70
|
+
* frontend sees the real fields. For native tools, `input` is already
|
|
71
|
+
* the parsed args object and is returned as-is.
|
|
72
|
+
*/
|
|
73
|
+
function extractToolArgs(input) {
|
|
74
|
+
if (input == null || typeof input !== 'object' || Array.isArray(input)) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
const obj = input;
|
|
78
|
+
const keys = Object.keys(obj);
|
|
79
|
+
if (keys.length === 1 &&
|
|
80
|
+
keys[0] === 'input' &&
|
|
81
|
+
typeof obj.input === 'string') {
|
|
82
|
+
try {
|
|
83
|
+
const parsed = JSON.parse(obj.input);
|
|
84
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
85
|
+
return parsed;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
// Not JSON — fall through and return the wrapper as-is.
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return obj;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Owns the SSE side of the chat request: headers, heartbeat, abort
|
|
96
|
+
* controller registration, and the for-await loop translating
|
|
97
|
+
* `streamEvents` output into the wire format the frontend consumes.
|
|
98
|
+
*
|
|
99
|
+
* Event types preserved verbatim from the legacy implementation:
|
|
100
|
+
*
|
|
101
|
+
* - `ReasoningEvent` (thinking + chunked reasoning + completion marker)
|
|
102
|
+
* - `ToolCallEvent` (server-executed tools — fired on `tool_calls`)
|
|
103
|
+
* - `ActionCallEvent` (AG-UI actions — same `tool_calls` channel but
|
|
104
|
+
* named in `payload.agActions`; the runner branches on the name)
|
|
105
|
+
* - `message` chunk (plain assistant text)
|
|
106
|
+
* - `error` + `done`
|
|
107
|
+
*
|
|
108
|
+
* The SSE headers and the first `Thinking...` event are emitted by
|
|
109
|
+
* `MessagesController` BEFORE the orchestrator hands off — this class
|
|
110
|
+
* picks up after the connection is open, so we don't pay the pre-flight
|
|
111
|
+
* latency before the client knows the request was accepted.
|
|
112
|
+
*/
|
|
113
|
+
let SseStreamRunner = SseStreamRunner_1 = class SseStreamRunner {
|
|
114
|
+
agentBuilder;
|
|
115
|
+
logger = new Logger(SseStreamRunner_1.name);
|
|
116
|
+
constructor(agentBuilder) {
|
|
117
|
+
this.agentBuilder = agentBuilder;
|
|
118
|
+
}
|
|
119
|
+
async run(input) {
|
|
120
|
+
const { payload, prepared, inputMessages, res, abortControllers } = input;
|
|
121
|
+
const { sessionId, requestId } = prepared;
|
|
122
|
+
// SSE headers + heartbeat may already be set by the controller (early
|
|
123
|
+
// flush). Set them defensively here in case run() is called directly.
|
|
124
|
+
if (!res.headersSent) {
|
|
125
|
+
setSSEHeaders(res, requestId);
|
|
126
|
+
res.flushHeaders();
|
|
127
|
+
}
|
|
128
|
+
const heartbeat = startSSEHeartbeat(res);
|
|
129
|
+
const abortController = new AbortController();
|
|
130
|
+
const existingController = abortControllers.get(sessionId);
|
|
131
|
+
if (existingController) {
|
|
132
|
+
existingController.abort();
|
|
133
|
+
}
|
|
134
|
+
abortControllers.set(sessionId, abortController);
|
|
135
|
+
const onClose = () => abortController.abort();
|
|
136
|
+
res.on('close', onClose);
|
|
137
|
+
try {
|
|
138
|
+
await runWithSSEContext(res, async () => {
|
|
139
|
+
const thinkingText = pickThinkingPhrase();
|
|
140
|
+
const thinkingEvent = ReasoningEvent.createChunk(sessionId, requestId, thinkingText, [{ type: 'thinking', text: thinkingText }], false);
|
|
141
|
+
emitSSEEvent(thinkingEvent);
|
|
142
|
+
thinkingEvent.emit();
|
|
143
|
+
const { agent, stateInput, langGraphConfig } = await this.agentBuilder.build({ payload, prepared, inputMessages }, abortController);
|
|
144
|
+
// ReactAgent.streamEvents returns the same `{event, data, tags}`
|
|
145
|
+
// shape as LangChain's `streamEvents v2` — the v2 envelope is the
|
|
146
|
+
// default for ReactAgent in langchain@1.4, no extra option needed.
|
|
147
|
+
const stream = agent.streamEvents(stateInput, langGraphConfig);
|
|
148
|
+
let fullContent = '';
|
|
149
|
+
const toolCallMap = new Map();
|
|
150
|
+
const actionCallMap = new Map();
|
|
151
|
+
const agActionNames = new Set((payload.agActions ?? []).map((a) => a.name));
|
|
152
|
+
for await (const evt of stream) {
|
|
153
|
+
if (abortController.signal.aborted)
|
|
154
|
+
break;
|
|
155
|
+
const { data, event, run_id, name } = evt;
|
|
156
|
+
if (event === 'on_tool_start') {
|
|
157
|
+
this.handleToolStart(run_id, name ?? 'tool', data, sessionId, requestId, agActionNames, toolCallMap, actionCallMap, res, abortController);
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (event === 'on_tool_end') {
|
|
161
|
+
this.handleToolEnd(run_id, data, toolCallMap, actionCallMap, res, abortController);
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (event === 'on_chat_model_stream') {
|
|
165
|
+
const chunkContent = this.handleChatStream(data, sessionId, requestId, res, abortController);
|
|
166
|
+
if (chunkContent)
|
|
167
|
+
fullContent += chunkContent;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (!abortController.signal.aborted) {
|
|
171
|
+
// Flush any tool/action calls that started but never received a
|
|
172
|
+
// matching `on_tool_end`. Without this, the frontend keeps the
|
|
173
|
+
// tool stuck in `isRunning` forever — the run completed cleanly
|
|
174
|
+
// but the UI has no signal to clear it.
|
|
175
|
+
this.flushOrphanedToolCalls(toolCallMap, actionCallMap, res, abortController);
|
|
176
|
+
const completeEvent = ReasoningEvent.createChunk(sessionId, requestId, '', undefined, true);
|
|
177
|
+
if (!res.writableEnded) {
|
|
178
|
+
res.write(formatSSE(completeEvent.eventName, completeEvent.payload));
|
|
179
|
+
}
|
|
180
|
+
sendSSEDone(res);
|
|
181
|
+
input.onComplete?.(fullContent);
|
|
182
|
+
}
|
|
183
|
+
}, abortController);
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
const aborted = error instanceof Error &&
|
|
187
|
+
(error.name === 'AbortError' ||
|
|
188
|
+
error.message.includes('aborted') ||
|
|
189
|
+
error.message.includes('Stream aborted by client'));
|
|
190
|
+
if (aborted) {
|
|
191
|
+
if (!res.writableEnded)
|
|
192
|
+
sendSSEDone(res);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
this.logger.error('Stream failed', error);
|
|
196
|
+
if (!res.writableEnded && !abortController.signal.aborted) {
|
|
197
|
+
sendSSEError(res, error instanceof Error ? error : 'Something went wrong');
|
|
198
|
+
sendSSEDone(res);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
finally {
|
|
202
|
+
clearInterval(heartbeat);
|
|
203
|
+
res.off('close', onClose);
|
|
204
|
+
// Only clear the map entry if it still points at *our* controller. A
|
|
205
|
+
// newer same-session request replaces the entry at the top of `run()`
|
|
206
|
+
// (aborting us first); deleting unconditionally here would drop that
|
|
207
|
+
// newer request's controller and make it un-abortable.
|
|
208
|
+
if (abortControllers.get(sessionId) === abortController) {
|
|
209
|
+
abortControllers.delete(sessionId);
|
|
210
|
+
}
|
|
211
|
+
if (!res.writableEnded)
|
|
212
|
+
res.end();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Fires when an agent invokes a tool. `data.input` carries the fully
|
|
217
|
+
* parsed args — the right place to emit the `isRunning` event with
|
|
218
|
+
* complete args. We key the map by `run_id` from the event envelope so
|
|
219
|
+
* the matching `on_tool_end` (which shares the same `run_id`) can pair
|
|
220
|
+
* with it regardless of how the model formatted the original
|
|
221
|
+
* `tool_call_id`.
|
|
222
|
+
*/
|
|
223
|
+
handleToolStart(runId, toolName, data, sessionId, requestId, agActionNames, toolCallMap, actionCallMap, res, abortController) {
|
|
224
|
+
const args = extractToolArgs(data.input);
|
|
225
|
+
const isAction = agActionNames.has(toolName);
|
|
226
|
+
if (isAction) {
|
|
227
|
+
const actionCallEvent = new ActionCallEvent({
|
|
228
|
+
requestId,
|
|
229
|
+
sessionId,
|
|
230
|
+
toolCallId: runId,
|
|
231
|
+
toolName,
|
|
232
|
+
args,
|
|
233
|
+
status: 'isRunning',
|
|
234
|
+
});
|
|
235
|
+
this.writeSse(res, abortController, actionCallEvent.eventName, actionCallEvent.payload);
|
|
236
|
+
actionCallMap.set(runId, actionCallEvent);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
const toolCallEvent = new ToolCallEvent({
|
|
240
|
+
requestId,
|
|
241
|
+
sessionId,
|
|
242
|
+
toolName,
|
|
243
|
+
args: args ?? {},
|
|
244
|
+
status: 'isRunning',
|
|
245
|
+
});
|
|
246
|
+
toolCallEvent.payload.args.toolName = toolName;
|
|
247
|
+
toolCallEvent.payload.eventId = runId;
|
|
248
|
+
this.writeSse(res, abortController, toolCallEvent.eventName, toolCallEvent.payload);
|
|
249
|
+
toolCallMap.set(runId, toolCallEvent);
|
|
250
|
+
}
|
|
251
|
+
handleToolEnd(runId, data, toolCallMap, actionCallMap, res, abortController) {
|
|
252
|
+
const toolMessage = data.output;
|
|
253
|
+
const actionCallEvent = actionCallMap.get(runId);
|
|
254
|
+
if (actionCallEvent) {
|
|
255
|
+
actionCallEvent.payload.output = emojify(toolMessage.content.toString());
|
|
256
|
+
actionCallEvent.payload.toolCallId = runId;
|
|
257
|
+
const parsed = safeParseToolContent(toolMessage.content);
|
|
258
|
+
if (parsed?.success === false || parsed?.error) {
|
|
259
|
+
actionCallEvent.payload.status = 'error';
|
|
260
|
+
actionCallEvent.payload.error =
|
|
261
|
+
parsed.error || 'Action failed';
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
actionCallEvent.payload.status = 'done';
|
|
265
|
+
}
|
|
266
|
+
this.writeSse(res, abortController, actionCallEvent.eventName, actionCallEvent.payload);
|
|
267
|
+
actionCallMap.delete(runId);
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
const toolCallEvent = toolCallMap.get(runId);
|
|
271
|
+
if (!toolCallEvent)
|
|
272
|
+
return;
|
|
273
|
+
toolCallEvent.payload.output = emojify(toolMessage.content);
|
|
274
|
+
toolCallEvent.payload.status = 'done';
|
|
275
|
+
toolCallEvent.payload.args.toolName =
|
|
276
|
+
toolMessage.name;
|
|
277
|
+
toolCallEvent.payload.eventId = runId;
|
|
278
|
+
this.writeSse(res, abortController, toolCallEvent.eventName, toolCallEvent.payload);
|
|
279
|
+
toolCallMap.delete(runId);
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Emit a terminal `error` event for any tool/action call that started but
|
|
283
|
+
* never received a matching `on_tool_end`. Keeps the frontend from
|
|
284
|
+
* showing a perpetually-spinning tool when the agent ends a turn with
|
|
285
|
+
* unresolved tool runs in flight.
|
|
286
|
+
*/
|
|
287
|
+
flushOrphanedToolCalls(toolCallMap, actionCallMap, res, abortController) {
|
|
288
|
+
for (const [runId, evt] of actionCallMap) {
|
|
289
|
+
evt.payload.status = 'error';
|
|
290
|
+
evt.payload.error = 'Action did not complete';
|
|
291
|
+
evt.payload.toolCallId = runId;
|
|
292
|
+
this.writeSse(res, abortController, evt.eventName, evt.payload);
|
|
293
|
+
}
|
|
294
|
+
actionCallMap.clear();
|
|
295
|
+
for (const [runId, evt] of toolCallMap) {
|
|
296
|
+
// `IToolCallEvent.status` only allows 'isRunning' | 'done' — there's
|
|
297
|
+
// no error variant on tool calls (unlike actions). Mark as 'done'
|
|
298
|
+
// with a sentinel output so the FE clears its spinner but the user
|
|
299
|
+
// sees the call didn't actually produce a result.
|
|
300
|
+
evt.payload.status = 'done';
|
|
301
|
+
evt.payload.output = '⏱️ Tool did not complete';
|
|
302
|
+
evt.payload.eventId = runId;
|
|
303
|
+
this.writeSse(res, abortController, evt.eventName, evt.payload);
|
|
304
|
+
}
|
|
305
|
+
toolCallMap.clear();
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Emits reasoning + text chunks. Tool-call emission has moved to
|
|
309
|
+
* `handleToolStart` (which fires on `on_tool_start` with full,
|
|
310
|
+
* finalized args) — the chunk's partial `tool_calls` deltas are
|
|
311
|
+
* intentionally ignored here to avoid emitting an `isRunning` event
|
|
312
|
+
* with empty args before the model finishes producing the call.
|
|
313
|
+
*/
|
|
314
|
+
handleChatStream(data, sessionId, requestId, res, abortController) {
|
|
315
|
+
const chunk = data.chunk;
|
|
316
|
+
const rawResponse = chunk.additional_kwargs?.__raw_response;
|
|
317
|
+
const delta = rawResponse?.choices?.[0]?.delta;
|
|
318
|
+
const reasoning = delta?.reasoning ?? delta?.reasoning_content;
|
|
319
|
+
if (reasoning && reasoning.trim()) {
|
|
320
|
+
const reasoningDetails = Array.isArray(delta?.reasoning_details)
|
|
321
|
+
? delta.reasoning_details
|
|
322
|
+
.filter((d) => d != null &&
|
|
323
|
+
typeof d === 'object' &&
|
|
324
|
+
typeof d.type === 'string' &&
|
|
325
|
+
typeof d.text === 'string' &&
|
|
326
|
+
d.text.trim().length > 0)
|
|
327
|
+
.map((d) => ({ type: d.type, text: d.text }))
|
|
328
|
+
: undefined;
|
|
329
|
+
const reasoningEvent = ReasoningEvent.createChunk(sessionId, requestId, reasoning, reasoningDetails, false);
|
|
330
|
+
this.writeSse(res, abortController, reasoningEvent.eventName, reasoningEvent.payload);
|
|
331
|
+
}
|
|
332
|
+
const content = chunk.content;
|
|
333
|
+
if (!content)
|
|
334
|
+
return undefined;
|
|
335
|
+
const parsed = emojify(String(content));
|
|
336
|
+
this.writeSse(res, abortController, 'message', {
|
|
337
|
+
content: parsed,
|
|
338
|
+
timestamp: new Date().toISOString(),
|
|
339
|
+
});
|
|
340
|
+
return parsed;
|
|
341
|
+
}
|
|
342
|
+
writeSse(res, abortController, eventName, payload) {
|
|
343
|
+
if (res.writableEnded || abortController.signal.aborted)
|
|
344
|
+
return;
|
|
345
|
+
res.write(formatSSE(eventName, payload));
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
SseStreamRunner = SseStreamRunner_1 = __decorate([
|
|
349
|
+
Injectable(),
|
|
350
|
+
__metadata("design:paramtypes", [AgentBuilder])
|
|
351
|
+
], SseStreamRunner);
|
|
352
|
+
export { SseStreamRunner };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type AllEvents } from '@ixo/oracles-events';
|
|
2
|
+
import { type Response } from 'express';
|
|
3
|
+
/** SSE event format: `event: <name>\ndata: <jsonPayload>\n\n` */
|
|
4
|
+
export declare function formatSSEEvent(event: AllEvents): string;
|
|
5
|
+
/** Format a raw event/data pair without going through the event class system. */
|
|
6
|
+
export declare function formatSSE(eventType: string, data: unknown): string;
|
|
7
|
+
/** SSE heartbeat (comment line) — keeps proxies/load balancers from timing out. */
|
|
8
|
+
export declare function sendSSEHeartbeat(res: Response): void;
|
|
9
|
+
/** Start a 15s heartbeat interval. Caller clears the returned timer. */
|
|
10
|
+
export declare function startSSEHeartbeat(res: Response): NodeJS.Timeout;
|
|
11
|
+
/** Set SSE response headers, optionally including a request id. */
|
|
12
|
+
export declare function setSSEHeaders(res: Response, requestId?: string): void;
|
|
13
|
+
/** Signal stream completion. */
|
|
14
|
+
export declare function sendSSEDone(res: Response): void;
|
|
15
|
+
/** Send an error event. */
|
|
16
|
+
export declare function sendSSEError(res: Response, error: Error | string): void;
|
|
17
|
+
/**
|
|
18
|
+
* Run a callback with an SSE context bound to AsyncLocalStorage so deeply
|
|
19
|
+
* nested code can call `emitSSEEvent()` without threading the Response
|
|
20
|
+
* through every function signature.
|
|
21
|
+
*/
|
|
22
|
+
export declare function runWithSSEContext<T>(res: Response, callback: () => Promise<T>, abortController?: AbortController): Promise<T>;
|
|
23
|
+
/** Emit an SSE event from anywhere within the active SSE context. */
|
|
24
|
+
export declare function emitSSEEvent(event: AllEvents): void;
|
|
25
|
+
export declare function getSSEContext(): Response | undefined;
|
|
26
|
+
export declare function getSSEabortController(): AbortController | undefined;
|
|
27
|
+
export declare function hasSSEContext(): boolean;
|
|
28
|
+
export declare function isSSEAborted(): boolean;
|
|
29
|
+
//# sourceMappingURL=sse.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse.utils.d.ts","sourceRoot":"","sources":["../../../src/modules/messages/sse.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AASxC,iEAAiE;AACjE,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAEvD;AAED,iFAAiF;AACjF,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,CAElE;AAED,mFAAmF;AACnF,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,QAAQ,GAAG,IAAI,CAIpD;AAED,wEAAwE;AACxE,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,QAAQ,GAAG,MAAM,CAAC,OAAO,CAE/D;AAED,mEAAmE;AACnE,wBAAgB,aAAa,CAAC,GAAG,EAAE,QAAQ,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAcrE;AAED,gCAAgC;AAChC,wBAAgB,WAAW,CAAC,GAAG,EAAE,QAAQ,GAAG,IAAI,CAI/C;AAED,2BAA2B;AAC3B,wBAAgB,YAAY,CAAC,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,IAAI,CASvE;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,GAAG,EAAE,QAAQ,EACb,QAAQ,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC1B,eAAe,CAAC,EAAE,eAAe,GAChC,OAAO,CAAC,CAAC,CAAC,CAEZ;AAED,qEAAqE;AACrE,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAKnD;AAED,wBAAgB,aAAa,IAAI,QAAQ,GAAG,SAAS,CAEpD;AAED,wBAAgB,qBAAqB,IAAI,eAAe,GAAG,SAAS,CAEnE;AAED,wBAAgB,aAAa,IAAI,OAAO,CAEvC;AAED,wBAAgB,YAAY,IAAI,OAAO,CAGtC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
const sseContextStorage = new AsyncLocalStorage();
|
|
3
|
+
/** SSE event format: `event: <name>\ndata: <jsonPayload>\n\n` */
|
|
4
|
+
export function formatSSEEvent(event) {
|
|
5
|
+
return `event: ${event.eventName}\ndata: ${JSON.stringify(event.payload)}\n\n`;
|
|
6
|
+
}
|
|
7
|
+
/** Format a raw event/data pair without going through the event class system. */
|
|
8
|
+
export function formatSSE(eventType, data) {
|
|
9
|
+
return `event: ${eventType}\ndata: ${JSON.stringify(data)}\n\n`;
|
|
10
|
+
}
|
|
11
|
+
/** SSE heartbeat (comment line) — keeps proxies/load balancers from timing out. */
|
|
12
|
+
export function sendSSEHeartbeat(res) {
|
|
13
|
+
if (!res.writableEnded) {
|
|
14
|
+
res.write(': heartbeat\n\n');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** Start a 15s heartbeat interval. Caller clears the returned timer. */
|
|
18
|
+
export function startSSEHeartbeat(res) {
|
|
19
|
+
return setInterval(() => sendSSEHeartbeat(res), 15000);
|
|
20
|
+
}
|
|
21
|
+
/** Set SSE response headers, optionally including a request id. */
|
|
22
|
+
export function setSSEHeaders(res, requestId) {
|
|
23
|
+
const headers = {
|
|
24
|
+
'Content-Type': 'text/event-stream',
|
|
25
|
+
'Cache-Control': 'no-cache, no-transform',
|
|
26
|
+
Connection: 'keep-alive',
|
|
27
|
+
'X-Accel-Buffering': 'no',
|
|
28
|
+
};
|
|
29
|
+
if (requestId) {
|
|
30
|
+
headers['X-Request-Id'] = requestId;
|
|
31
|
+
headers['Access-Control-Expose-Headers'] = 'X-Request-Id';
|
|
32
|
+
}
|
|
33
|
+
res.set(headers);
|
|
34
|
+
}
|
|
35
|
+
/** Signal stream completion. */
|
|
36
|
+
export function sendSSEDone(res) {
|
|
37
|
+
if (!res.writableEnded) {
|
|
38
|
+
res.write(formatSSE('done', {}));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** Send an error event. */
|
|
42
|
+
export function sendSSEError(res, error) {
|
|
43
|
+
if (!res.writableEnded) {
|
|
44
|
+
res.write(formatSSE('error', {
|
|
45
|
+
error: error instanceof Error ? error.message : error,
|
|
46
|
+
timestamp: new Date().toISOString(),
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Run a callback with an SSE context bound to AsyncLocalStorage so deeply
|
|
52
|
+
* nested code can call `emitSSEEvent()` without threading the Response
|
|
53
|
+
* through every function signature.
|
|
54
|
+
*/
|
|
55
|
+
export function runWithSSEContext(res, callback, abortController) {
|
|
56
|
+
return sseContextStorage.run({ res, abortController }, callback);
|
|
57
|
+
}
|
|
58
|
+
/** Emit an SSE event from anywhere within the active SSE context. */
|
|
59
|
+
export function emitSSEEvent(event) {
|
|
60
|
+
const context = sseContextStorage.getStore();
|
|
61
|
+
if (context?.res && !context.res.writableEnded) {
|
|
62
|
+
context.res.write(formatSSEEvent(event));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export function getSSEContext() {
|
|
66
|
+
return sseContextStorage.getStore()?.res;
|
|
67
|
+
}
|
|
68
|
+
export function getSSEabortController() {
|
|
69
|
+
return sseContextStorage.getStore()?.abortController;
|
|
70
|
+
}
|
|
71
|
+
export function hasSSEContext() {
|
|
72
|
+
return sseContextStorage.getStore() !== undefined;
|
|
73
|
+
}
|
|
74
|
+
export function isSSEAborted() {
|
|
75
|
+
const context = sseContextStorage.getStore();
|
|
76
|
+
return context?.abortController?.signal.aborted ?? false;
|
|
77
|
+
}
|