@lobu/gateway 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +6 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/platform.d.ts +92 -0
- package/dist/api/platform.d.ts.map +1 -0
- package/dist/api/platform.js +236 -0
- package/dist/api/platform.js.map +1 -0
- package/dist/api/response-renderer.d.ts +44 -0
- package/dist/api/response-renderer.d.ts.map +1 -0
- package/dist/api/response-renderer.js +123 -0
- package/dist/api/response-renderer.js.map +1 -0
- package/dist/auth/agent-metadata-store.d.ts +64 -0
- package/dist/auth/agent-metadata-store.d.ts.map +1 -0
- package/dist/auth/agent-metadata-store.js +115 -0
- package/dist/auth/agent-metadata-store.js.map +1 -0
- package/dist/auth/api-auth-middleware.d.ts +19 -0
- package/dist/auth/api-auth-middleware.d.ts.map +1 -0
- package/dist/auth/api-auth-middleware.js +61 -0
- package/dist/auth/api-auth-middleware.js.map +1 -0
- package/dist/auth/api-key-provider-module.d.ts +60 -0
- package/dist/auth/api-key-provider-module.d.ts.map +1 -0
- package/dist/auth/api-key-provider-module.js +148 -0
- package/dist/auth/api-key-provider-module.js.map +1 -0
- package/dist/auth/base-provider-module.d.ts +70 -0
- package/dist/auth/base-provider-module.d.ts.map +1 -0
- package/dist/auth/base-provider-module.js +118 -0
- package/dist/auth/base-provider-module.js.map +1 -0
- package/dist/auth/chatgpt/chatgpt-oauth-module.d.ts +34 -0
- package/dist/auth/chatgpt/chatgpt-oauth-module.d.ts.map +1 -0
- package/dist/auth/chatgpt/chatgpt-oauth-module.js +136 -0
- package/dist/auth/chatgpt/chatgpt-oauth-module.js.map +1 -0
- package/dist/auth/chatgpt/device-code-client.d.ts +40 -0
- package/dist/auth/chatgpt/device-code-client.d.ts.map +1 -0
- package/dist/auth/chatgpt/device-code-client.js +165 -0
- package/dist/auth/chatgpt/device-code-client.js.map +1 -0
- package/dist/auth/chatgpt/index.d.ts +2 -0
- package/dist/auth/chatgpt/index.d.ts.map +1 -0
- package/dist/auth/chatgpt/index.js +6 -0
- package/dist/auth/chatgpt/index.js.map +1 -0
- package/dist/auth/claude/oauth-module.d.ts +29 -0
- package/dist/auth/claude/oauth-module.d.ts.map +1 -0
- package/dist/auth/claude/oauth-module.js +201 -0
- package/dist/auth/claude/oauth-module.js.map +1 -0
- package/dist/auth/cli/token-service.d.ts +35 -0
- package/dist/auth/cli/token-service.d.ts.map +1 -0
- package/dist/auth/cli/token-service.js +171 -0
- package/dist/auth/cli/token-service.js.map +1 -0
- package/dist/auth/external/client.d.ts +65 -0
- package/dist/auth/external/client.d.ts.map +1 -0
- package/dist/auth/external/client.js +348 -0
- package/dist/auth/external/client.js.map +1 -0
- package/dist/auth/external/device-code-client.d.ts +41 -0
- package/dist/auth/external/device-code-client.d.ts.map +1 -0
- package/dist/auth/external/device-code-client.js +128 -0
- package/dist/auth/external/device-code-client.js.map +1 -0
- package/dist/auth/mcp/config-service.d.ts +70 -0
- package/dist/auth/mcp/config-service.d.ts.map +1 -0
- package/dist/auth/mcp/config-service.js +269 -0
- package/dist/auth/mcp/config-service.js.map +1 -0
- package/dist/auth/mcp/proxy.d.ts +68 -0
- package/dist/auth/mcp/proxy.d.ts.map +1 -0
- package/dist/auth/mcp/proxy.js +783 -0
- package/dist/auth/mcp/proxy.js.map +1 -0
- package/dist/auth/mcp/string-substitution.d.ts +11 -0
- package/dist/auth/mcp/string-substitution.d.ts.map +1 -0
- package/dist/auth/mcp/string-substitution.js +21 -0
- package/dist/auth/mcp/string-substitution.js.map +1 -0
- package/dist/auth/mcp/tool-cache.d.ts +26 -0
- package/dist/auth/mcp/tool-cache.d.ts.map +1 -0
- package/dist/auth/mcp/tool-cache.js +58 -0
- package/dist/auth/mcp/tool-cache.js.map +1 -0
- package/dist/auth/oauth/base-client.d.ts +54 -0
- package/dist/auth/oauth/base-client.d.ts.map +1 -0
- package/dist/auth/oauth/base-client.js +191 -0
- package/dist/auth/oauth/base-client.js.map +1 -0
- package/dist/auth/oauth/client.d.ts +35 -0
- package/dist/auth/oauth/client.d.ts.map +1 -0
- package/dist/auth/oauth/client.js +96 -0
- package/dist/auth/oauth/client.js.map +1 -0
- package/dist/auth/oauth/credentials.d.ts +8 -0
- package/dist/auth/oauth/credentials.d.ts.map +1 -0
- package/dist/auth/oauth/credentials.js +3 -0
- package/dist/auth/oauth/credentials.js.map +1 -0
- package/dist/auth/oauth/providers.d.ts +44 -0
- package/dist/auth/oauth/providers.d.ts.map +1 -0
- package/dist/auth/oauth/providers.js +37 -0
- package/dist/auth/oauth/providers.js.map +1 -0
- package/dist/auth/oauth/state-store.d.ts +62 -0
- package/dist/auth/oauth/state-store.d.ts.map +1 -0
- package/dist/auth/oauth/state-store.js +84 -0
- package/dist/auth/oauth/state-store.js.map +1 -0
- package/dist/auth/oauth-templates.d.ts +15 -0
- package/dist/auth/oauth-templates.d.ts.map +1 -0
- package/dist/auth/oauth-templates.js +161 -0
- package/dist/auth/oauth-templates.js.map +1 -0
- package/dist/auth/provider-catalog.d.ts +52 -0
- package/dist/auth/provider-catalog.d.ts.map +1 -0
- package/dist/auth/provider-catalog.js +155 -0
- package/dist/auth/provider-catalog.js.map +1 -0
- package/dist/auth/provider-model-options.d.ts +3 -0
- package/dist/auth/provider-model-options.d.ts.map +1 -0
- package/dist/auth/provider-model-options.js +29 -0
- package/dist/auth/provider-model-options.js.map +1 -0
- package/dist/auth/settings/agent-settings-store.d.ts +112 -0
- package/dist/auth/settings/agent-settings-store.d.ts.map +1 -0
- package/dist/auth/settings/agent-settings-store.js +376 -0
- package/dist/auth/settings/agent-settings-store.js.map +1 -0
- package/dist/auth/settings/auth-profiles-manager.d.ts +26 -0
- package/dist/auth/settings/auth-profiles-manager.d.ts.map +1 -0
- package/dist/auth/settings/auth-profiles-manager.js +146 -0
- package/dist/auth/settings/auth-profiles-manager.js.map +1 -0
- package/dist/auth/settings/index.d.ts +4 -0
- package/dist/auth/settings/index.d.ts.map +1 -0
- package/dist/auth/settings/index.js +9 -0
- package/dist/auth/settings/index.js.map +1 -0
- package/dist/auth/settings/model-preference-store.d.ts +25 -0
- package/dist/auth/settings/model-preference-store.d.ts.map +1 -0
- package/dist/auth/settings/model-preference-store.js +50 -0
- package/dist/auth/settings/model-preference-store.js.map +1 -0
- package/dist/auth/settings/model-selection.d.ts +11 -0
- package/dist/auth/settings/model-selection.d.ts.map +1 -0
- package/dist/auth/settings/model-selection.js +83 -0
- package/dist/auth/settings/model-selection.js.map +1 -0
- package/dist/auth/settings/resolved-settings-view.d.ts +45 -0
- package/dist/auth/settings/resolved-settings-view.d.ts.map +1 -0
- package/dist/auth/settings/resolved-settings-view.js +152 -0
- package/dist/auth/settings/resolved-settings-view.js.map +1 -0
- package/dist/auth/settings/template-utils.d.ts +3 -0
- package/dist/auth/settings/template-utils.d.ts.map +1 -0
- package/dist/auth/settings/template-utils.js +43 -0
- package/dist/auth/settings/template-utils.js.map +1 -0
- package/dist/auth/settings/token-service.d.ts +86 -0
- package/dist/auth/settings/token-service.d.ts.map +1 -0
- package/dist/auth/settings/token-service.js +3 -0
- package/dist/auth/settings/token-service.js.map +1 -0
- package/dist/auth/system-env-store.d.ts +26 -0
- package/dist/auth/system-env-store.d.ts.map +1 -0
- package/dist/auth/system-env-store.js +92 -0
- package/dist/auth/system-env-store.js.map +1 -0
- package/dist/auth/user-agents-store.d.ts +31 -0
- package/dist/auth/user-agents-store.d.ts.map +1 -0
- package/dist/auth/user-agents-store.js +54 -0
- package/dist/auth/user-agents-store.js.map +1 -0
- package/dist/channels/binding-service.d.ts +69 -0
- package/dist/channels/binding-service.d.ts.map +1 -0
- package/dist/channels/binding-service.js +144 -0
- package/dist/channels/binding-service.js.map +1 -0
- package/dist/channels/index.d.ts +2 -0
- package/dist/channels/index.d.ts.map +1 -0
- package/dist/channels/index.js +6 -0
- package/dist/channels/index.js.map +1 -0
- package/dist/cli/gateway.d.ts +31 -0
- package/dist/cli/gateway.d.ts.map +1 -0
- package/dist/cli/gateway.js +1062 -0
- package/dist/cli/gateway.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +56 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/commands/built-in-commands.d.ts +10 -0
- package/dist/commands/built-in-commands.d.ts.map +1 -0
- package/dist/commands/built-in-commands.js +63 -0
- package/dist/commands/built-in-commands.js.map +1 -0
- package/dist/commands/command-dispatcher.d.ts +25 -0
- package/dist/commands/command-dispatcher.d.ts.map +1 -0
- package/dist/commands/command-dispatcher.js +50 -0
- package/dist/commands/command-dispatcher.js.map +1 -0
- package/dist/commands/command-reply-adapters.d.ts +3 -0
- package/dist/commands/command-reply-adapters.d.ts.map +1 -0
- package/dist/commands/command-reply-adapters.js +60 -0
- package/dist/commands/command-reply-adapters.js.map +1 -0
- package/dist/config/file-loader.d.ts +23 -0
- package/dist/config/file-loader.d.ts.map +1 -0
- package/dist/config/file-loader.js +495 -0
- package/dist/config/file-loader.js.map +1 -0
- package/dist/config/index.d.ts +96 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +357 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/network-allowlist.d.ts +18 -0
- package/dist/config/network-allowlist.d.ts.map +1 -0
- package/dist/config/network-allowlist.js +60 -0
- package/dist/config/network-allowlist.js.map +1 -0
- package/dist/connections/chat-instance-manager.d.ts +107 -0
- package/dist/connections/chat-instance-manager.d.ts.map +1 -0
- package/dist/connections/chat-instance-manager.js +886 -0
- package/dist/connections/chat-instance-manager.js.map +1 -0
- package/dist/connections/chat-response-bridge.d.ts +31 -0
- package/dist/connections/chat-response-bridge.d.ts.map +1 -0
- package/dist/connections/chat-response-bridge.js +465 -0
- package/dist/connections/chat-response-bridge.js.map +1 -0
- package/dist/connections/index.d.ts +4 -0
- package/dist/connections/index.d.ts.map +1 -0
- package/dist/connections/index.js +8 -0
- package/dist/connections/index.js.map +1 -0
- package/dist/connections/interaction-bridge.d.ts +7 -0
- package/dist/connections/interaction-bridge.d.ts.map +1 -0
- package/dist/connections/interaction-bridge.js +593 -0
- package/dist/connections/interaction-bridge.js.map +1 -0
- package/dist/connections/message-handler-bridge.d.ts +21 -0
- package/dist/connections/message-handler-bridge.d.ts.map +1 -0
- package/dist/connections/message-handler-bridge.js +314 -0
- package/dist/connections/message-handler-bridge.js.map +1 -0
- package/dist/connections/platform-auth-methods.d.ts +5 -0
- package/dist/connections/platform-auth-methods.d.ts.map +1 -0
- package/dist/connections/platform-auth-methods.js +13 -0
- package/dist/connections/platform-auth-methods.js.map +1 -0
- package/dist/connections/types.d.ts +52 -0
- package/dist/connections/types.d.ts.map +1 -0
- package/dist/connections/types.js +20 -0
- package/dist/connections/types.js.map +1 -0
- package/dist/gateway/connection-manager.d.ts +87 -0
- package/dist/gateway/connection-manager.d.ts.map +1 -0
- package/dist/gateway/connection-manager.js +216 -0
- package/dist/gateway/connection-manager.js.map +1 -0
- package/dist/gateway/index.d.ts +71 -0
- package/dist/gateway/index.d.ts.map +1 -0
- package/dist/gateway/index.js +509 -0
- package/dist/gateway/index.js.map +1 -0
- package/dist/gateway/job-router.d.ts +60 -0
- package/dist/gateway/job-router.d.ts.map +1 -0
- package/dist/gateway/job-router.js +148 -0
- package/dist/gateway/job-router.js.map +1 -0
- package/dist/gateway-main.d.ts +81 -0
- package/dist/gateway-main.d.ts.map +1 -0
- package/dist/gateway-main.js +143 -0
- package/dist/gateway-main.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +64 -0
- package/dist/index.js.map +1 -0
- package/dist/infrastructure/queue/index.d.ts +8 -0
- package/dist/infrastructure/queue/index.d.ts.map +1 -0
- package/dist/infrastructure/queue/index.js +12 -0
- package/dist/infrastructure/queue/index.js.map +1 -0
- package/dist/infrastructure/queue/queue-producer.d.ts +68 -0
- package/dist/infrastructure/queue/queue-producer.d.ts.map +1 -0
- package/dist/infrastructure/queue/queue-producer.js +72 -0
- package/dist/infrastructure/queue/queue-producer.js.map +1 -0
- package/dist/infrastructure/queue/redis-queue.d.ts +45 -0
- package/dist/infrastructure/queue/redis-queue.d.ts.map +1 -0
- package/dist/infrastructure/queue/redis-queue.js +273 -0
- package/dist/infrastructure/queue/redis-queue.js.map +1 -0
- package/dist/infrastructure/queue/types.d.ts +107 -0
- package/dist/infrastructure/queue/types.d.ts.map +1 -0
- package/dist/infrastructure/queue/types.js +7 -0
- package/dist/infrastructure/queue/types.js.map +1 -0
- package/dist/infrastructure/redis/system-message-limiter.d.ts +35 -0
- package/dist/infrastructure/redis/system-message-limiter.d.ts.map +1 -0
- package/dist/infrastructure/redis/system-message-limiter.js +61 -0
- package/dist/infrastructure/redis/system-message-limiter.js.map +1 -0
- package/dist/interactions/config-request-store.d.ts +41 -0
- package/dist/interactions/config-request-store.d.ts.map +1 -0
- package/dist/interactions/config-request-store.js +103 -0
- package/dist/interactions/config-request-store.js.map +1 -0
- package/dist/interactions.d.ts +134 -0
- package/dist/interactions.d.ts.map +1 -0
- package/dist/interactions.js +175 -0
- package/dist/interactions.js.map +1 -0
- package/dist/lobu.d.ts +78 -0
- package/dist/lobu.d.ts.map +1 -0
- package/dist/lobu.js +248 -0
- package/dist/lobu.js.map +1 -0
- package/dist/metrics/prometheus.d.ts +6 -0
- package/dist/metrics/prometheus.d.ts.map +1 -0
- package/dist/metrics/prometheus.js +78 -0
- package/dist/metrics/prometheus.js.map +1 -0
- package/dist/modules/module-system.d.ts +82 -0
- package/dist/modules/module-system.d.ts.map +1 -0
- package/dist/modules/module-system.js +53 -0
- package/dist/modules/module-system.js.map +1 -0
- package/dist/orchestration/base-deployment-manager.d.ts +173 -0
- package/dist/orchestration/base-deployment-manager.d.ts.map +1 -0
- package/dist/orchestration/base-deployment-manager.js +553 -0
- package/dist/orchestration/base-deployment-manager.js.map +1 -0
- package/dist/orchestration/deployment-utils.d.ts +25 -0
- package/dist/orchestration/deployment-utils.d.ts.map +1 -0
- package/dist/orchestration/deployment-utils.js +65 -0
- package/dist/orchestration/deployment-utils.js.map +1 -0
- package/dist/orchestration/impl/docker-deployment.d.ts +43 -0
- package/dist/orchestration/impl/docker-deployment.d.ts.map +1 -0
- package/dist/orchestration/impl/docker-deployment.js +480 -0
- package/dist/orchestration/impl/docker-deployment.js.map +1 -0
- package/dist/orchestration/impl/embedded-deployment.d.ts +16 -0
- package/dist/orchestration/impl/embedded-deployment.d.ts.map +1 -0
- package/dist/orchestration/impl/embedded-deployment.js +195 -0
- package/dist/orchestration/impl/embedded-deployment.js.map +1 -0
- package/dist/orchestration/impl/index.d.ts +8 -0
- package/dist/orchestration/impl/index.d.ts.map +1 -0
- package/dist/orchestration/impl/index.js +14 -0
- package/dist/orchestration/impl/index.js.map +1 -0
- package/dist/orchestration/impl/k8s/deployment.d.ts +204 -0
- package/dist/orchestration/impl/k8s/deployment.d.ts.map +1 -0
- package/dist/orchestration/impl/k8s/deployment.js +620 -0
- package/dist/orchestration/impl/k8s/deployment.js.map +1 -0
- package/dist/orchestration/impl/k8s/helpers.d.ts +34 -0
- package/dist/orchestration/impl/k8s/helpers.d.ts.map +1 -0
- package/dist/orchestration/impl/k8s/helpers.js +377 -0
- package/dist/orchestration/impl/k8s/helpers.js.map +1 -0
- package/dist/orchestration/impl/k8s/index.d.ts +2 -0
- package/dist/orchestration/impl/k8s/index.d.ts.map +1 -0
- package/dist/orchestration/impl/k8s/index.js +6 -0
- package/dist/orchestration/impl/k8s/index.js.map +1 -0
- package/dist/orchestration/index.d.ts +53 -0
- package/dist/orchestration/index.d.ts.map +1 -0
- package/dist/orchestration/index.js +257 -0
- package/dist/orchestration/index.js.map +1 -0
- package/dist/orchestration/message-consumer.d.ts +49 -0
- package/dist/orchestration/message-consumer.d.ts.map +1 -0
- package/dist/orchestration/message-consumer.js +406 -0
- package/dist/orchestration/message-consumer.js.map +1 -0
- package/dist/orchestration/scheduled-wakeup.d.ts +110 -0
- package/dist/orchestration/scheduled-wakeup.d.ts.map +1 -0
- package/dist/orchestration/scheduled-wakeup.js +500 -0
- package/dist/orchestration/scheduled-wakeup.js.map +1 -0
- package/dist/permissions/approval-policy.d.ts +28 -0
- package/dist/permissions/approval-policy.d.ts.map +1 -0
- package/dist/permissions/approval-policy.js +33 -0
- package/dist/permissions/approval-policy.js.map +1 -0
- package/dist/permissions/grant-store.d.ts +52 -0
- package/dist/permissions/grant-store.d.ts.map +1 -0
- package/dist/permissions/grant-store.js +192 -0
- package/dist/permissions/grant-store.js.map +1 -0
- package/dist/platform/file-handler.d.ts +51 -0
- package/dist/platform/file-handler.d.ts.map +1 -0
- package/dist/platform/file-handler.js +6 -0
- package/dist/platform/file-handler.js.map +1 -0
- package/dist/platform/link-buttons.d.ts +21 -0
- package/dist/platform/link-buttons.d.ts.map +1 -0
- package/dist/platform/link-buttons.js +43 -0
- package/dist/platform/link-buttons.js.map +1 -0
- package/dist/platform/renderer-utils.d.ts +10 -0
- package/dist/platform/renderer-utils.d.ts.map +1 -0
- package/dist/platform/renderer-utils.js +42 -0
- package/dist/platform/renderer-utils.js.map +1 -0
- package/dist/platform/response-renderer.d.ts +66 -0
- package/dist/platform/response-renderer.d.ts.map +1 -0
- package/dist/platform/response-renderer.js +8 -0
- package/dist/platform/response-renderer.js.map +1 -0
- package/dist/platform/unified-thread-consumer.d.ts +41 -0
- package/dist/platform/unified-thread-consumer.d.ts.map +1 -0
- package/dist/platform/unified-thread-consumer.js +143 -0
- package/dist/platform/unified-thread-consumer.js.map +1 -0
- package/dist/platform.d.ts +255 -0
- package/dist/platform.d.ts.map +1 -0
- package/dist/platform.js +40 -0
- package/dist/platform.js.map +1 -0
- package/dist/proxy/http-proxy.d.ts +32 -0
- package/dist/proxy/http-proxy.d.ts.map +1 -0
- package/dist/proxy/http-proxy.js +636 -0
- package/dist/proxy/http-proxy.js.map +1 -0
- package/dist/proxy/proxy-manager.d.ts +13 -0
- package/dist/proxy/proxy-manager.d.ts.map +1 -0
- package/dist/proxy/proxy-manager.js +68 -0
- package/dist/proxy/proxy-manager.js.map +1 -0
- package/dist/proxy/secret-proxy.d.ts +78 -0
- package/dist/proxy/secret-proxy.d.ts.map +1 -0
- package/dist/proxy/secret-proxy.js +309 -0
- package/dist/proxy/secret-proxy.js.map +1 -0
- package/dist/proxy/token-refresh-job.d.ts +29 -0
- package/dist/proxy/token-refresh-job.d.ts.map +1 -0
- package/dist/proxy/token-refresh-job.js +104 -0
- package/dist/proxy/token-refresh-job.js.map +1 -0
- package/dist/routes/internal/audio.d.ts +14 -0
- package/dist/routes/internal/audio.d.ts.map +1 -0
- package/dist/routes/internal/audio.js +118 -0
- package/dist/routes/internal/audio.js.map +1 -0
- package/dist/routes/internal/device-auth.d.ts +42 -0
- package/dist/routes/internal/device-auth.d.ts.map +1 -0
- package/dist/routes/internal/device-auth.js +397 -0
- package/dist/routes/internal/device-auth.js.map +1 -0
- package/dist/routes/internal/files.d.ts +9 -0
- package/dist/routes/internal/files.d.ts.map +1 -0
- package/dist/routes/internal/files.js +175 -0
- package/dist/routes/internal/files.js.map +1 -0
- package/dist/routes/internal/history.d.ts +9 -0
- package/dist/routes/internal/history.d.ts.map +1 -0
- package/dist/routes/internal/history.js +55 -0
- package/dist/routes/internal/history.js.map +1 -0
- package/dist/routes/internal/images.d.ts +10 -0
- package/dist/routes/internal/images.d.ts.map +1 -0
- package/dist/routes/internal/images.js +101 -0
- package/dist/routes/internal/images.js.map +1 -0
- package/dist/routes/internal/interactions.d.ts +9 -0
- package/dist/routes/internal/interactions.d.ts.map +1 -0
- package/dist/routes/internal/interactions.js +53 -0
- package/dist/routes/internal/interactions.js.map +1 -0
- package/dist/routes/internal/middleware.d.ts +7 -0
- package/dist/routes/internal/middleware.d.ts.map +1 -0
- package/dist/routes/internal/middleware.js +24 -0
- package/dist/routes/internal/middleware.js.map +1 -0
- package/dist/routes/internal/schedule.d.ts +14 -0
- package/dist/routes/internal/schedule.d.ts.map +1 -0
- package/dist/routes/internal/schedule.js +169 -0
- package/dist/routes/internal/schedule.js.map +1 -0
- package/dist/routes/internal/types.d.ts +22 -0
- package/dist/routes/internal/types.d.ts.map +1 -0
- package/dist/routes/internal/types.js +6 -0
- package/dist/routes/internal/types.js.map +1 -0
- package/dist/routes/openapi-auto.d.ts +8 -0
- package/dist/routes/openapi-auto.d.ts.map +1 -0
- package/dist/routes/openapi-auto.js +196 -0
- package/dist/routes/openapi-auto.js.map +1 -0
- package/dist/routes/public/agent-access.d.ts +11 -0
- package/dist/routes/public/agent-access.d.ts.map +1 -0
- package/dist/routes/public/agent-access.js +11 -0
- package/dist/routes/public/agent-access.js.map +1 -0
- package/dist/routes/public/agent-config.d.ts +42 -0
- package/dist/routes/public/agent-config.d.ts.map +1 -0
- package/dist/routes/public/agent-config.js +415 -0
- package/dist/routes/public/agent-config.js.map +1 -0
- package/dist/routes/public/agent-history.d.ts +17 -0
- package/dist/routes/public/agent-history.d.ts.map +1 -0
- package/dist/routes/public/agent-history.js +335 -0
- package/dist/routes/public/agent-history.js.map +1 -0
- package/dist/routes/public/agent-schedules.d.ts +18 -0
- package/dist/routes/public/agent-schedules.d.ts.map +1 -0
- package/dist/routes/public/agent-schedules.js +242 -0
- package/dist/routes/public/agent-schedules.js.map +1 -0
- package/dist/routes/public/agent.d.ts +23 -0
- package/dist/routes/public/agent.d.ts.map +1 -0
- package/dist/routes/public/agent.js +864 -0
- package/dist/routes/public/agent.js.map +1 -0
- package/dist/routes/public/agents.d.ts +22 -0
- package/dist/routes/public/agents.d.ts.map +1 -0
- package/dist/routes/public/agents.js +257 -0
- package/dist/routes/public/agents.js.map +1 -0
- package/dist/routes/public/channels.d.ts +23 -0
- package/dist/routes/public/channels.d.ts.map +1 -0
- package/dist/routes/public/channels.js +131 -0
- package/dist/routes/public/channels.js.map +1 -0
- package/dist/routes/public/cli-auth.d.ts +12 -0
- package/dist/routes/public/cli-auth.d.ts.map +1 -0
- package/dist/routes/public/cli-auth.js +552 -0
- package/dist/routes/public/cli-auth.js.map +1 -0
- package/dist/routes/public/connections.d.ts +20 -0
- package/dist/routes/public/connections.d.ts.map +1 -0
- package/dist/routes/public/connections.js +464 -0
- package/dist/routes/public/connections.js.map +1 -0
- package/dist/routes/public/landing.d.ts +3 -0
- package/dist/routes/public/landing.d.ts.map +1 -0
- package/dist/routes/public/landing.js +17 -0
- package/dist/routes/public/landing.js.map +1 -0
- package/dist/routes/public/oauth.d.ts +24 -0
- package/dist/routes/public/oauth.d.ts.map +1 -0
- package/dist/routes/public/oauth.js +108 -0
- package/dist/routes/public/oauth.js.map +1 -0
- package/dist/routes/public/settings-auth.d.ts +28 -0
- package/dist/routes/public/settings-auth.d.ts.map +1 -0
- package/dist/routes/public/settings-auth.js +90 -0
- package/dist/routes/public/settings-auth.js.map +1 -0
- package/dist/routes/public/slack.d.ts +4 -0
- package/dist/routes/public/slack.d.ts.map +1 -0
- package/dist/routes/public/slack.js +119 -0
- package/dist/routes/public/slack.js.map +1 -0
- package/dist/routes/shared/agent-ownership.d.ts +15 -0
- package/dist/routes/shared/agent-ownership.d.ts.map +1 -0
- package/dist/routes/shared/agent-ownership.js +61 -0
- package/dist/routes/shared/agent-ownership.js.map +1 -0
- package/dist/routes/shared/token-verifier.d.ts +21 -0
- package/dist/routes/shared/token-verifier.d.ts.map +1 -0
- package/dist/routes/shared/token-verifier.js +25 -0
- package/dist/routes/shared/token-verifier.js.map +1 -0
- package/dist/services/core-services.d.ts +133 -0
- package/dist/services/core-services.d.ts.map +1 -0
- package/dist/services/core-services.js +728 -0
- package/dist/services/core-services.js.map +1 -0
- package/dist/services/image-generation-service.d.ts +38 -0
- package/dist/services/image-generation-service.d.ts.map +1 -0
- package/dist/services/image-generation-service.js +167 -0
- package/dist/services/image-generation-service.js.map +1 -0
- package/dist/services/instruction-service.d.ts +41 -0
- package/dist/services/instruction-service.d.ts.map +1 -0
- package/dist/services/instruction-service.js +252 -0
- package/dist/services/instruction-service.js.map +1 -0
- package/dist/services/mcp-registry.d.ts +31 -0
- package/dist/services/mcp-registry.d.ts.map +1 -0
- package/dist/services/mcp-registry.js +69 -0
- package/dist/services/mcp-registry.js.map +1 -0
- package/dist/services/platform-helpers.d.ts +47 -0
- package/dist/services/platform-helpers.d.ts.map +1 -0
- package/dist/services/platform-helpers.js +200 -0
- package/dist/services/platform-helpers.js.map +1 -0
- package/dist/services/session-manager.d.ts +72 -0
- package/dist/services/session-manager.d.ts.map +1 -0
- package/dist/services/session-manager.js +199 -0
- package/dist/services/session-manager.js.map +1 -0
- package/dist/services/settings-resolver.d.ts +25 -0
- package/dist/services/settings-resolver.d.ts.map +1 -0
- package/dist/services/settings-resolver.js +55 -0
- package/dist/services/settings-resolver.js.map +1 -0
- package/dist/services/system-config-resolver.d.ts +25 -0
- package/dist/services/system-config-resolver.d.ts.map +1 -0
- package/dist/services/system-config-resolver.js +73 -0
- package/dist/services/system-config-resolver.js.map +1 -0
- package/dist/services/system-skills-service.d.ts +38 -0
- package/dist/services/system-skills-service.d.ts.map +1 -0
- package/dist/services/system-skills-service.js +186 -0
- package/dist/services/system-skills-service.js.map +1 -0
- package/dist/services/transcription-service.d.ts +91 -0
- package/dist/services/transcription-service.d.ts.map +1 -0
- package/dist/services/transcription-service.js +465 -0
- package/dist/services/transcription-service.js.map +1 -0
- package/dist/session.d.ts +75 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +19 -0
- package/dist/session.js.map +1 -0
- package/dist/spaces/index.d.ts +2 -0
- package/dist/spaces/index.d.ts.map +1 -0
- package/dist/spaces/index.js +18 -0
- package/dist/spaces/index.js.map +1 -0
- package/dist/spaces/space-resolver.d.ts +10 -0
- package/dist/spaces/space-resolver.d.ts.map +1 -0
- package/dist/spaces/space-resolver.js +17 -0
- package/dist/spaces/space-resolver.js.map +1 -0
- package/dist/stores/in-memory-agent-store.d.ts +57 -0
- package/dist/stores/in-memory-agent-store.d.ts.map +1 -0
- package/dist/stores/in-memory-agent-store.js +304 -0
- package/dist/stores/in-memory-agent-store.js.map +1 -0
- package/dist/stores/redis-agent-store.d.ts +57 -0
- package/dist/stores/redis-agent-store.d.ts.map +1 -0
- package/dist/stores/redis-agent-store.js +163 -0
- package/dist/stores/redis-agent-store.js.map +1 -0
- package/dist/utils/public-url.d.ts +6 -0
- package/dist/utils/public-url.d.ts.map +1 -0
- package/dist/utils/public-url.js +33 -0
- package/dist/utils/public-url.js.map +1 -0
- package/dist/utils/rate-limiter.d.ts +32 -0
- package/dist/utils/rate-limiter.d.ts.map +1 -0
- package/dist/utils/rate-limiter.js +56 -0
- package/dist/utils/rate-limiter.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,886 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ChatInstanceManager — manages Chat SDK instances for API-driven platform connections.
|
|
4
|
+
* Owns Redis persistence, Chat lifecycle, and webhook dispatch.
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.ChatInstanceManager = exports.ADAPTER_FACTORIES = void 0;
|
|
41
|
+
const node_crypto_1 = require("node:crypto");
|
|
42
|
+
const core_1 = require("@lobu/core");
|
|
43
|
+
const types_1 = require("./types");
|
|
44
|
+
const logger = (0, core_1.createLogger)("chat-instance-manager");
|
|
45
|
+
const SLACK_SYSTEM_AGENT_PREFIX = "system:connection:slack";
|
|
46
|
+
exports.ADAPTER_FACTORIES = {
|
|
47
|
+
telegram: async (c) => (await Promise.resolve().then(() => __importStar(require("@chat-adapter/telegram")))).createTelegramAdapter(c),
|
|
48
|
+
slack: async (c) => (await Promise.resolve().then(() => __importStar(require("@chat-adapter/slack")))).createSlackAdapter(c),
|
|
49
|
+
discord: async (c) => (await Promise.resolve().then(() => __importStar(require("@chat-adapter/discord")))).createDiscordAdapter(c),
|
|
50
|
+
whatsapp: async (c) => (await Promise.resolve().then(() => __importStar(require("@chat-adapter/whatsapp")))).createWhatsAppAdapter(c),
|
|
51
|
+
teams: async (c) => (await Promise.resolve().then(() => __importStar(require("@chat-adapter/teams")))).createTeamsAdapter(c),
|
|
52
|
+
gchat: async (c) => (await Promise.resolve().then(() => __importStar(require("@chat-adapter/gchat")))).createGoogleChatAdapter(c),
|
|
53
|
+
};
|
|
54
|
+
class ChatInstanceManager {
|
|
55
|
+
constructor() {
|
|
56
|
+
this.instances = new Map();
|
|
57
|
+
this.publicGatewayUrl = "";
|
|
58
|
+
}
|
|
59
|
+
async initialize(services) {
|
|
60
|
+
var _a, _b;
|
|
61
|
+
this.services = services;
|
|
62
|
+
this.redis = services.getQueue().getRedisClient();
|
|
63
|
+
this.publicGatewayUrl = services.getPublicGatewayUrl();
|
|
64
|
+
// Load all connections from Redis and start active ones
|
|
65
|
+
const connectionIds = await this.redis.smembers("connections:all");
|
|
66
|
+
logger.debug({ count: connectionIds.length }, "Loading connections from Redis");
|
|
67
|
+
for (const id of connectionIds) {
|
|
68
|
+
try {
|
|
69
|
+
const raw = await this.redis.get(`connection:${id}`);
|
|
70
|
+
if (!raw) {
|
|
71
|
+
await this.redis.srem("connections:all", id);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const connection = JSON.parse(raw);
|
|
75
|
+
try {
|
|
76
|
+
connection.config = this.decryptConfig(connection.config);
|
|
77
|
+
}
|
|
78
|
+
catch (decryptError) {
|
|
79
|
+
// ENCRYPTION_KEY changed — remove stale connection so the seeder can recreate it
|
|
80
|
+
logger.warn({ id, platform: connection.platform, error: String(decryptError) }, "Removing connection with undecryptable config (ENCRYPTION_KEY changed?)");
|
|
81
|
+
await this.redis.del(`connection:${id}`);
|
|
82
|
+
await this.redis.srem("connections:all", id);
|
|
83
|
+
if (connection.templateAgentId) {
|
|
84
|
+
await this.redis.srem(`connections:agent:${connection.templateAgentId}`, id);
|
|
85
|
+
}
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
// Migrate legacy agentId → templateAgentId
|
|
89
|
+
const legacy = connection;
|
|
90
|
+
if (legacy.agentId && !connection.templateAgentId) {
|
|
91
|
+
connection.templateAgentId = legacy.agentId;
|
|
92
|
+
delete legacy.agentId;
|
|
93
|
+
await this.persistConnection(connection);
|
|
94
|
+
logger.info({ id, templateAgentId: connection.templateAgentId }, "Migrated agentId → templateAgentId");
|
|
95
|
+
}
|
|
96
|
+
// Migrate legacy scope values: "mcp-servers"/"tools" → "skills"
|
|
97
|
+
if ((_b = (_a = connection.settings) === null || _a === void 0 ? void 0 : _a.userConfigScopes) === null || _b === void 0 ? void 0 : _b.length) {
|
|
98
|
+
const oldScopes = connection.settings.userConfigScopes;
|
|
99
|
+
const hasLegacy = oldScopes.some((s) => s === "mcp-servers" || s === "tools");
|
|
100
|
+
if (hasLegacy) {
|
|
101
|
+
const migrated = new Set();
|
|
102
|
+
for (const s of oldScopes) {
|
|
103
|
+
if (s === "mcp-servers" || s === "tools") {
|
|
104
|
+
migrated.add("skills");
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
migrated.add(s);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
connection.settings.userConfigScopes = [...migrated];
|
|
111
|
+
await this.persistConnection(connection);
|
|
112
|
+
logger.info({ id }, "Migrated legacy scopes → skills");
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (connection.status === "active") {
|
|
116
|
+
await this.startInstance(connection);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
logger.error({ id, error: String(error) }, "Failed to load connection");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async shutdown() {
|
|
125
|
+
logger.info({ count: this.instances.size }, "Shutting down all connections");
|
|
126
|
+
const shutdownPromises = Array.from(this.instances.values()).map(async (instance) => {
|
|
127
|
+
var _a, _b;
|
|
128
|
+
try {
|
|
129
|
+
(_a = instance.interactionCleanup) === null || _a === void 0 ? void 0 : _a.call(instance);
|
|
130
|
+
await ((_b = instance.cleanup) === null || _b === void 0 ? void 0 : _b.call(instance));
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
logger.error({ id: instance.connection.id, error: String(error) }, "Error shutting down connection");
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
await Promise.allSettled(shutdownPromises);
|
|
137
|
+
this.instances.clear();
|
|
138
|
+
}
|
|
139
|
+
async addConnection(platform, templateAgentId, config, settings, metadata = {}) {
|
|
140
|
+
if (!(platform in exports.ADAPTER_FACTORIES)) {
|
|
141
|
+
throw new Error(`Unsupported platform: ${platform}`);
|
|
142
|
+
}
|
|
143
|
+
if (config.platform !== platform) {
|
|
144
|
+
throw new Error(`Config platform mismatch: expected ${platform}, got ${config.platform}`);
|
|
145
|
+
}
|
|
146
|
+
const id = (0, node_crypto_1.randomUUID)().replace(/-/g, "").slice(0, 16);
|
|
147
|
+
const now = Date.now();
|
|
148
|
+
const connection = Object.assign(Object.assign({ id,
|
|
149
|
+
platform }, (templateAgentId ? { templateAgentId } : {})), { config, settings: settings !== null && settings !== void 0 ? settings : { allowGroups: true }, metadata, status: "active", createdAt: now, updatedAt: now });
|
|
150
|
+
// Start the Chat SDK instance
|
|
151
|
+
await this.startInstance(connection);
|
|
152
|
+
// Persist (secrets encrypted)
|
|
153
|
+
await this.persistConnection(connection);
|
|
154
|
+
logger.info({ id, platform, templateAgentId }, "Connection added");
|
|
155
|
+
return connection;
|
|
156
|
+
}
|
|
157
|
+
async removeConnection(id) {
|
|
158
|
+
var _a, _b;
|
|
159
|
+
const instance = this.instances.get(id);
|
|
160
|
+
if (instance) {
|
|
161
|
+
(_a = instance.interactionCleanup) === null || _a === void 0 ? void 0 : _a.call(instance);
|
|
162
|
+
await ((_b = instance.cleanup) === null || _b === void 0 ? void 0 : _b.call(instance));
|
|
163
|
+
this.instances.delete(id);
|
|
164
|
+
}
|
|
165
|
+
// Clean up Redis
|
|
166
|
+
const raw = await this.redis.get(`connection:${id}`);
|
|
167
|
+
if (raw) {
|
|
168
|
+
const conn = JSON.parse(raw);
|
|
169
|
+
if (conn.templateAgentId) {
|
|
170
|
+
await this.redis.srem(`connections:agent:${conn.templateAgentId}`, id);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
await this.redis.del(`connection:${id}`);
|
|
174
|
+
await this.redis.srem("connections:all", id);
|
|
175
|
+
logger.info({ id }, "Connection removed");
|
|
176
|
+
}
|
|
177
|
+
async restartConnection(id) {
|
|
178
|
+
var _a, _b;
|
|
179
|
+
const instance = this.instances.get(id);
|
|
180
|
+
if (instance) {
|
|
181
|
+
(_a = instance.interactionCleanup) === null || _a === void 0 ? void 0 : _a.call(instance);
|
|
182
|
+
await ((_b = instance.cleanup) === null || _b === void 0 ? void 0 : _b.call(instance));
|
|
183
|
+
this.instances.delete(id);
|
|
184
|
+
}
|
|
185
|
+
const raw = await this.redis.get(`connection:${id}`);
|
|
186
|
+
if (!raw)
|
|
187
|
+
throw new Error(`Connection ${id} not found`);
|
|
188
|
+
const connection = JSON.parse(raw);
|
|
189
|
+
connection.config = this.decryptConfig(connection.config);
|
|
190
|
+
connection.status = "active";
|
|
191
|
+
connection.errorMessage = undefined;
|
|
192
|
+
connection.updatedAt = Date.now();
|
|
193
|
+
try {
|
|
194
|
+
await this.startInstance(connection);
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
// startInstance sets connection.status = "error" — persist so UI reflects it
|
|
198
|
+
await this.persistConnection(connection);
|
|
199
|
+
throw error;
|
|
200
|
+
}
|
|
201
|
+
await this.persistConnection(connection);
|
|
202
|
+
logger.info({ id }, "Connection restarted");
|
|
203
|
+
}
|
|
204
|
+
async stopConnection(id) {
|
|
205
|
+
var _a, _b;
|
|
206
|
+
const instance = this.instances.get(id);
|
|
207
|
+
if (instance) {
|
|
208
|
+
(_a = instance.interactionCleanup) === null || _a === void 0 ? void 0 : _a.call(instance);
|
|
209
|
+
await ((_b = instance.cleanup) === null || _b === void 0 ? void 0 : _b.call(instance));
|
|
210
|
+
this.instances.delete(id);
|
|
211
|
+
}
|
|
212
|
+
const raw = await this.redis.get(`connection:${id}`);
|
|
213
|
+
if (!raw)
|
|
214
|
+
throw new Error(`Connection ${id} not found`);
|
|
215
|
+
const connection = JSON.parse(raw);
|
|
216
|
+
connection.config = this.decryptConfig(connection.config);
|
|
217
|
+
connection.status = "stopped";
|
|
218
|
+
connection.updatedAt = Date.now();
|
|
219
|
+
await this.persistConnection(connection);
|
|
220
|
+
logger.info({ id }, "Connection stopped");
|
|
221
|
+
}
|
|
222
|
+
async updateConnection(id, updates) {
|
|
223
|
+
var _a, _b;
|
|
224
|
+
const raw = await this.redis.get(`connection:${id}`);
|
|
225
|
+
if (!raw)
|
|
226
|
+
throw new Error(`Connection ${id} not found`);
|
|
227
|
+
const connection = JSON.parse(raw);
|
|
228
|
+
connection.config = this.decryptConfig(connection.config);
|
|
229
|
+
const needsRestart = updates.config !== undefined &&
|
|
230
|
+
JSON.stringify(updates.config) !== JSON.stringify(connection.config);
|
|
231
|
+
if (updates.templateAgentId !== undefined) {
|
|
232
|
+
// Update agent index — remove old, add new
|
|
233
|
+
if (connection.templateAgentId) {
|
|
234
|
+
await this.redis.srem(`connections:agent:${connection.templateAgentId}`, id);
|
|
235
|
+
}
|
|
236
|
+
if (updates.templateAgentId) {
|
|
237
|
+
connection.templateAgentId = updates.templateAgentId;
|
|
238
|
+
await this.redis.sadd(`connections:agent:${connection.templateAgentId}`, id);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
delete connection.templateAgentId;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (updates.config !== undefined) {
|
|
245
|
+
const merged = Object.assign({}, connection.config);
|
|
246
|
+
for (const [key, value] of Object.entries(updates.config)) {
|
|
247
|
+
if (typeof value === "string" && value.startsWith("***"))
|
|
248
|
+
continue;
|
|
249
|
+
merged[key] = value;
|
|
250
|
+
}
|
|
251
|
+
merged.platform = updates.config.platform;
|
|
252
|
+
connection.config = merged;
|
|
253
|
+
}
|
|
254
|
+
if (updates.settings !== undefined) {
|
|
255
|
+
connection.settings = Object.assign(Object.assign({}, connection.settings), updates.settings);
|
|
256
|
+
}
|
|
257
|
+
if (updates.metadata !== undefined) {
|
|
258
|
+
connection.metadata = Object.assign(Object.assign({}, (connection.metadata || {})), updates.metadata);
|
|
259
|
+
}
|
|
260
|
+
connection.updatedAt = Date.now();
|
|
261
|
+
if (needsRestart && connection.status === "active") {
|
|
262
|
+
const instance = this.instances.get(id);
|
|
263
|
+
if (instance) {
|
|
264
|
+
(_a = instance.interactionCleanup) === null || _a === void 0 ? void 0 : _a.call(instance);
|
|
265
|
+
await ((_b = instance.cleanup) === null || _b === void 0 ? void 0 : _b.call(instance));
|
|
266
|
+
this.instances.delete(id);
|
|
267
|
+
}
|
|
268
|
+
await this.startInstance(connection);
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
const instance = this.instances.get(id);
|
|
272
|
+
if (instance) {
|
|
273
|
+
instance.connection = connection;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
await this.persistConnection(connection);
|
|
277
|
+
return this.sanitizeConnection(connection);
|
|
278
|
+
}
|
|
279
|
+
async listConnections(filter) {
|
|
280
|
+
let ids;
|
|
281
|
+
if (filter === null || filter === void 0 ? void 0 : filter.templateAgentId) {
|
|
282
|
+
ids = await this.redis.smembers(`connections:agent:${filter.templateAgentId}`);
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
ids = await this.redis.smembers("connections:all");
|
|
286
|
+
}
|
|
287
|
+
const connections = [];
|
|
288
|
+
for (const id of ids) {
|
|
289
|
+
const raw = await this.redis.get(`connection:${id}`);
|
|
290
|
+
if (!raw)
|
|
291
|
+
continue;
|
|
292
|
+
const conn = JSON.parse(raw);
|
|
293
|
+
if ((filter === null || filter === void 0 ? void 0 : filter.platform) && conn.platform !== filter.platform)
|
|
294
|
+
continue;
|
|
295
|
+
connections.push(this.sanitizeConnection(conn));
|
|
296
|
+
}
|
|
297
|
+
return connections;
|
|
298
|
+
}
|
|
299
|
+
async getConnection(id) {
|
|
300
|
+
const raw = await this.redis.get(`connection:${id}`);
|
|
301
|
+
if (!raw)
|
|
302
|
+
return null;
|
|
303
|
+
return this.sanitizeConnection(JSON.parse(raw));
|
|
304
|
+
}
|
|
305
|
+
has(id) {
|
|
306
|
+
return this.instances.has(id);
|
|
307
|
+
}
|
|
308
|
+
getInstance(id) {
|
|
309
|
+
return this.instances.get(id);
|
|
310
|
+
}
|
|
311
|
+
/** Get a decrypted secret from a running connection's config. */
|
|
312
|
+
getConnectionConfigSecret(connectionId, field) {
|
|
313
|
+
const instance = this.instances.get(connectionId);
|
|
314
|
+
if (!instance)
|
|
315
|
+
return undefined;
|
|
316
|
+
const config = instance.connection.config;
|
|
317
|
+
const val = config[field];
|
|
318
|
+
return typeof val === "string" ? val : undefined;
|
|
319
|
+
}
|
|
320
|
+
async handleWebhook(connectionId, request) {
|
|
321
|
+
var _a;
|
|
322
|
+
const instance = this.instances.get(connectionId);
|
|
323
|
+
if (!instance) {
|
|
324
|
+
return new Response("Connection not found", { status: 404 });
|
|
325
|
+
}
|
|
326
|
+
const { platform } = instance.connection;
|
|
327
|
+
const webhookHandler = (_a = instance.chat.webhooks) === null || _a === void 0 ? void 0 : _a[platform];
|
|
328
|
+
if (!webhookHandler) {
|
|
329
|
+
logger.warn({ connectionId, platform }, "No webhook handler found for platform");
|
|
330
|
+
return new Response("No webhook handler", { status: 404 });
|
|
331
|
+
}
|
|
332
|
+
try {
|
|
333
|
+
return await webhookHandler(request);
|
|
334
|
+
}
|
|
335
|
+
catch (error) {
|
|
336
|
+
logger.error({ connectionId, platform, error: String(error) }, "Webhook handling failed");
|
|
337
|
+
return new Response("Internal error", { status: 500 });
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
getServices() {
|
|
341
|
+
return this.services;
|
|
342
|
+
}
|
|
343
|
+
async findSlackConnectionByTeamId(teamId) {
|
|
344
|
+
const connections = await this.listConnections({ platform: "slack" });
|
|
345
|
+
return (connections.find((connection) => { var _a; return ((_a = connection.metadata) === null || _a === void 0 ? void 0 : _a.teamId) === teamId; }) || null);
|
|
346
|
+
}
|
|
347
|
+
async getDefaultSlackConnection() {
|
|
348
|
+
const connections = await this.listConnections({ platform: "slack" });
|
|
349
|
+
if (connections.length === 1) {
|
|
350
|
+
return connections[0] || null;
|
|
351
|
+
}
|
|
352
|
+
return (connections.find((connection) => { var _a; return !((_a = connection.metadata) === null || _a === void 0 ? void 0 : _a.teamId); }) || null);
|
|
353
|
+
}
|
|
354
|
+
async ensureSlackWorkspaceConnection(teamId, installation) {
|
|
355
|
+
const baseConfig = this.resolveSlackAdapterConfig({
|
|
356
|
+
requireOAuth: true,
|
|
357
|
+
});
|
|
358
|
+
const config = Object.assign(Object.assign(Object.assign({}, baseConfig), { botToken: installation.botToken }), (installation.botUserId ? { botUserId: installation.botUserId } : {}));
|
|
359
|
+
const agentId = `${SLACK_SYSTEM_AGENT_PREFIX}:${teamId}`;
|
|
360
|
+
const metadata = {
|
|
361
|
+
teamId,
|
|
362
|
+
teamName: installation.teamName,
|
|
363
|
+
botUserId: installation.botUserId,
|
|
364
|
+
};
|
|
365
|
+
const existing = await this.findSlackConnectionByTeamId(teamId);
|
|
366
|
+
if (existing) {
|
|
367
|
+
const updated = await this.updateConnection(existing.id, {
|
|
368
|
+
templateAgentId: agentId,
|
|
369
|
+
config,
|
|
370
|
+
metadata,
|
|
371
|
+
});
|
|
372
|
+
if (!this.has(existing.id)) {
|
|
373
|
+
await this.restartConnection(existing.id);
|
|
374
|
+
}
|
|
375
|
+
return updated;
|
|
376
|
+
}
|
|
377
|
+
return this.addConnection("slack", agentId, config, { allowGroups: true }, metadata);
|
|
378
|
+
}
|
|
379
|
+
async completeSlackOAuthInstall(request, redirectUri) {
|
|
380
|
+
const { chat, adapter } = await this.createSlackOAuthChat({
|
|
381
|
+
requireOAuth: true,
|
|
382
|
+
});
|
|
383
|
+
try {
|
|
384
|
+
const url = new URL(request.url);
|
|
385
|
+
if (redirectUri) {
|
|
386
|
+
url.searchParams.set("redirect_uri", redirectUri);
|
|
387
|
+
}
|
|
388
|
+
const callbackRequest = new Request(url.toString(), {
|
|
389
|
+
method: request.method,
|
|
390
|
+
headers: request.headers,
|
|
391
|
+
});
|
|
392
|
+
const { teamId, installation } = await adapter.handleOAuthCallback(callbackRequest);
|
|
393
|
+
let connection;
|
|
394
|
+
try {
|
|
395
|
+
connection = await this.ensureSlackWorkspaceConnection(teamId, installation);
|
|
396
|
+
}
|
|
397
|
+
catch (error) {
|
|
398
|
+
await adapter.deleteInstallation(teamId).catch((err) => {
|
|
399
|
+
logger.warn({ teamId, error: String(err) }, "Failed to delete Slack installation after connection error");
|
|
400
|
+
});
|
|
401
|
+
throw error;
|
|
402
|
+
}
|
|
403
|
+
return {
|
|
404
|
+
teamId,
|
|
405
|
+
teamName: installation.teamName,
|
|
406
|
+
connectionId: connection.id,
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
finally {
|
|
410
|
+
await chat.shutdown().catch((err) => {
|
|
411
|
+
logger.warn({ error: String(err) }, "Failed to shut down Slack OAuth chat");
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
async handleSlackAppWebhook(request) {
|
|
416
|
+
const body = await request.text();
|
|
417
|
+
const teamId = this.extractSlackTeamId(body, request.headers.get("content-type") || "");
|
|
418
|
+
if (teamId) {
|
|
419
|
+
const connection = await this.findSlackConnectionByTeamId(teamId);
|
|
420
|
+
if (connection) {
|
|
421
|
+
if (!(await this.ensureConnectionRunning(connection.id))) {
|
|
422
|
+
return new Response("Slack connection unavailable", { status: 503 });
|
|
423
|
+
}
|
|
424
|
+
return this.handleWebhook(connection.id, this.cloneRequestWithBody(request, body));
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
const fallbackConnection = await this.getDefaultSlackConnection();
|
|
428
|
+
if (fallbackConnection) {
|
|
429
|
+
if (!(await this.ensureConnectionRunning(fallbackConnection.id))) {
|
|
430
|
+
return new Response("Slack connection unavailable", { status: 503 });
|
|
431
|
+
}
|
|
432
|
+
return this.handleWebhook(fallbackConnection.id, this.cloneRequestWithBody(request, body));
|
|
433
|
+
}
|
|
434
|
+
const { chat, adapter } = await this.createSlackOAuthChat();
|
|
435
|
+
try {
|
|
436
|
+
return await adapter.handleWebhook(this.cloneRequestWithBody(request, body));
|
|
437
|
+
}
|
|
438
|
+
finally {
|
|
439
|
+
await chat.shutdown().catch((err) => {
|
|
440
|
+
logger.warn({ error: String(err) }, "Failed to shut down Slack webhook chat");
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
// --- Private ---
|
|
445
|
+
async startInstance(connection) {
|
|
446
|
+
var _a;
|
|
447
|
+
try {
|
|
448
|
+
const { Chat } = await Promise.resolve().then(() => __importStar(require("chat")));
|
|
449
|
+
const adapter = await this.createAdapter(connection);
|
|
450
|
+
const stateAdapter = await this.createStateAdapter();
|
|
451
|
+
const adapterKey = connection.platform;
|
|
452
|
+
const chat = new Chat({
|
|
453
|
+
userName: connection.metadata.botUsername || `bot-${connection.id}`,
|
|
454
|
+
adapters: { [adapterKey]: adapter },
|
|
455
|
+
state: stateAdapter,
|
|
456
|
+
logger: "warn",
|
|
457
|
+
});
|
|
458
|
+
// Register message handlers (imported lazily to avoid circular deps)
|
|
459
|
+
const { registerMessageHandlers } = await Promise.resolve().then(() => __importStar(require("./message-handler-bridge")));
|
|
460
|
+
const { CommandDispatcher } = await Promise.resolve().then(() => __importStar(require("../commands/command-dispatcher")));
|
|
461
|
+
const commandDispatcher = new CommandDispatcher({
|
|
462
|
+
registry: this.services.getCommandRegistry(),
|
|
463
|
+
channelBindingService: this.services.getChannelBindingService(),
|
|
464
|
+
});
|
|
465
|
+
registerMessageHandlers(chat, connection, this.services, this, commandDispatcher);
|
|
466
|
+
chat.registerSingleton();
|
|
467
|
+
// Initialize adapters (starts long-polling for Telegram, etc.)
|
|
468
|
+
await chat.initialize();
|
|
469
|
+
// Set webhook URL if applicable
|
|
470
|
+
const mode = (_a = connection.config.mode) !== null && _a !== void 0 ? _a : "auto";
|
|
471
|
+
const useWebhook = mode === "webhook" || (mode === "auto" && !!this.publicGatewayUrl);
|
|
472
|
+
if (useWebhook && this.publicGatewayUrl) {
|
|
473
|
+
const webhookUrl = `${this.publicGatewayUrl}/api/v1/webhooks/${connection.id}`;
|
|
474
|
+
logger.info({ id: connection.id, webhookUrl }, "Setting webhook");
|
|
475
|
+
}
|
|
476
|
+
const cleanup = async () => {
|
|
477
|
+
try {
|
|
478
|
+
await chat.shutdown();
|
|
479
|
+
}
|
|
480
|
+
catch (_a) {
|
|
481
|
+
// best effort
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
// Populate metadata (bot username etc.) from adapter properties
|
|
485
|
+
if (!connection.metadata.botUsername) {
|
|
486
|
+
try {
|
|
487
|
+
const userName = adapter.userName || adapter.botUsername;
|
|
488
|
+
if (userName) {
|
|
489
|
+
connection.metadata.botUsername = userName;
|
|
490
|
+
await this.updateConnection(connection.id, {
|
|
491
|
+
metadata: { botUsername: userName },
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
catch (_b) {
|
|
496
|
+
// non-critical
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
this.instances.set(connection.id, { connection, chat, cleanup });
|
|
500
|
+
const { registerInteractionBridge } = await Promise.resolve().then(() => __importStar(require("./interaction-bridge")));
|
|
501
|
+
const interactionCleanup = registerInteractionBridge(this.services.getInteractionService(), this, connection, chat, this.services.getGrantStore(), this.services.getAgentSettingsStore());
|
|
502
|
+
this.instances.get(connection.id).interactionCleanup =
|
|
503
|
+
interactionCleanup;
|
|
504
|
+
// Register slash commands with the platform (e.g. Telegram menu)
|
|
505
|
+
this.registerPlatformCommands(connection).catch((err) => {
|
|
506
|
+
logger.warn({ id: connection.id, error: String(err) }, "Failed to register platform commands");
|
|
507
|
+
});
|
|
508
|
+
logger.info({ id: connection.id, platform: connection.platform }, "Chat instance started");
|
|
509
|
+
}
|
|
510
|
+
catch (error) {
|
|
511
|
+
connection.status = "error";
|
|
512
|
+
connection.errorMessage = String(error);
|
|
513
|
+
logger.error({ id: connection.id, error: String(error) }, "Failed to start Chat instance");
|
|
514
|
+
throw error;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
async createAdapter(connection) {
|
|
518
|
+
const factory = exports.ADAPTER_FACTORIES[connection.platform];
|
|
519
|
+
if (!factory) {
|
|
520
|
+
throw new Error(`No adapter factory for: ${connection.platform}`);
|
|
521
|
+
}
|
|
522
|
+
return factory(connection.config);
|
|
523
|
+
}
|
|
524
|
+
async createStateAdapter() {
|
|
525
|
+
const { createIoRedisState } = await Promise.resolve().then(() => __importStar(require("@chat-adapter/state-ioredis")));
|
|
526
|
+
return createIoRedisState({
|
|
527
|
+
client: this.redis,
|
|
528
|
+
keyPrefix: "chat-conn",
|
|
529
|
+
logger: "warn",
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Register slash commands with the platform's native command menu.
|
|
534
|
+
* Currently supports Telegram (setMyCommands) and Slack (via manifest).
|
|
535
|
+
*/
|
|
536
|
+
async registerPlatformCommands(connection) {
|
|
537
|
+
const commands = this.services
|
|
538
|
+
.getCommandRegistry()
|
|
539
|
+
.getAll()
|
|
540
|
+
.map((cmd) => ({
|
|
541
|
+
command: cmd.name,
|
|
542
|
+
description: cmd.description,
|
|
543
|
+
}));
|
|
544
|
+
if (connection.platform === "telegram") {
|
|
545
|
+
const botToken = connection.config.botToken;
|
|
546
|
+
if (!botToken)
|
|
547
|
+
return;
|
|
548
|
+
const apiBase = connection.config.apiBaseUrl || "https://api.telegram.org";
|
|
549
|
+
const resp = await fetch(`${apiBase}/bot${botToken}/setMyCommands`, {
|
|
550
|
+
method: "POST",
|
|
551
|
+
headers: { "Content-Type": "application/json" },
|
|
552
|
+
body: JSON.stringify({ commands }),
|
|
553
|
+
});
|
|
554
|
+
if (!resp.ok) {
|
|
555
|
+
const text = await resp.text();
|
|
556
|
+
throw new Error(`Telegram setMyCommands failed: ${resp.status} ${text}`);
|
|
557
|
+
}
|
|
558
|
+
logger.info({ id: connection.id, count: commands.length }, "Telegram bot commands menu registered");
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
resolveSlackAdapterConfig(options) {
|
|
562
|
+
var _a;
|
|
563
|
+
const slackInstance = Array.from(this.instances.values()).find((instance) => instance.connection.platform === "slack");
|
|
564
|
+
const currentConfig = ((slackInstance === null || slackInstance === void 0 ? void 0 : slackInstance.connection.config) || {});
|
|
565
|
+
const signingSecret = process.env.SLACK_SIGNING_SECRET || currentConfig.signingSecret;
|
|
566
|
+
const clientId = process.env.SLACK_CLIENT_ID || currentConfig.clientId;
|
|
567
|
+
const clientSecret = process.env.SLACK_CLIENT_SECRET || currentConfig.clientSecret;
|
|
568
|
+
const encryptionKey = process.env.SLACK_ENCRYPTION_KEY || currentConfig.encryptionKey;
|
|
569
|
+
const installationKeyPrefix = process.env.SLACK_INSTALLATION_KEY_PREFIX ||
|
|
570
|
+
currentConfig.installationKeyPrefix;
|
|
571
|
+
const userName = process.env.SLACK_BOT_USERNAME ||
|
|
572
|
+
currentConfig.userName ||
|
|
573
|
+
((_a = slackInstance === null || slackInstance === void 0 ? void 0 : slackInstance.connection.metadata) === null || _a === void 0 ? void 0 : _a.botUsername);
|
|
574
|
+
if (!signingSecret) {
|
|
575
|
+
throw new Error("Slack signing secret is not configured");
|
|
576
|
+
}
|
|
577
|
+
if (options === null || options === void 0 ? void 0 : options.requireOAuth) {
|
|
578
|
+
if (!clientId || !clientSecret) {
|
|
579
|
+
throw new Error("Slack OAuth is not configured. Set SLACK_CLIENT_ID and SLACK_CLIENT_SECRET.");
|
|
580
|
+
}
|
|
581
|
+
return Object.assign(Object.assign(Object.assign({ platform: "slack", signingSecret,
|
|
582
|
+
clientId,
|
|
583
|
+
clientSecret }, (encryptionKey ? { encryptionKey } : {})), (installationKeyPrefix ? { installationKeyPrefix } : {})), (userName ? { userName } : {}));
|
|
584
|
+
}
|
|
585
|
+
const botToken = process.env.SLACK_BOT_TOKEN || currentConfig.botToken;
|
|
586
|
+
if (!botToken && (!clientId || !clientSecret)) {
|
|
587
|
+
throw new Error("Slack adapter is not configured. Provide SLACK_BOT_TOKEN or Slack OAuth credentials.");
|
|
588
|
+
}
|
|
589
|
+
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ platform: "slack", signingSecret }, (botToken ? { botToken } : {})), (clientId ? { clientId } : {})), (clientSecret ? { clientSecret } : {})), (encryptionKey ? { encryptionKey } : {})), (installationKeyPrefix ? { installationKeyPrefix } : {})), (userName ? { userName } : {}));
|
|
590
|
+
}
|
|
591
|
+
async createSlackOAuthChat(options) {
|
|
592
|
+
const { Chat } = await Promise.resolve().then(() => __importStar(require("chat")));
|
|
593
|
+
const { createSlackAdapter } = await Promise.resolve().then(() => __importStar(require("@chat-adapter/slack")));
|
|
594
|
+
const adapter = createSlackAdapter(this.resolveSlackAdapterConfig(options));
|
|
595
|
+
const state = await this.createStateAdapter();
|
|
596
|
+
const chat = new Chat({
|
|
597
|
+
userName: "lobu-slack-oauth",
|
|
598
|
+
adapters: { slack: adapter },
|
|
599
|
+
state,
|
|
600
|
+
logger: "warn",
|
|
601
|
+
});
|
|
602
|
+
await chat.initialize();
|
|
603
|
+
return { chat, adapter };
|
|
604
|
+
}
|
|
605
|
+
cloneRequestWithBody(request, body) {
|
|
606
|
+
return new Request(request.url, {
|
|
607
|
+
method: request.method,
|
|
608
|
+
headers: request.headers,
|
|
609
|
+
body: request.method === "GET" || request.method === "HEAD"
|
|
610
|
+
? undefined
|
|
611
|
+
: body,
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
extractSlackTeamId(body, contentType) {
|
|
615
|
+
var _a, _b, _c;
|
|
616
|
+
if (contentType.includes("application/x-www-form-urlencoded")) {
|
|
617
|
+
const params = new URLSearchParams(body);
|
|
618
|
+
const directTeamId = params.get("team_id");
|
|
619
|
+
if (directTeamId) {
|
|
620
|
+
return directTeamId;
|
|
621
|
+
}
|
|
622
|
+
const payloadStr = params.get("payload");
|
|
623
|
+
if (!payloadStr) {
|
|
624
|
+
return null;
|
|
625
|
+
}
|
|
626
|
+
try {
|
|
627
|
+
const payload = JSON.parse(payloadStr);
|
|
628
|
+
return ((_a = payload.team) === null || _a === void 0 ? void 0 : _a.id) || payload.team_id || null;
|
|
629
|
+
}
|
|
630
|
+
catch (_d) {
|
|
631
|
+
return null;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
try {
|
|
635
|
+
const payload = JSON.parse(body);
|
|
636
|
+
return (payload.team_id ||
|
|
637
|
+
payload.team ||
|
|
638
|
+
((_b = payload.event) === null || _b === void 0 ? void 0 : _b.team_id) ||
|
|
639
|
+
((_c = payload.event) === null || _c === void 0 ? void 0 : _c.team) ||
|
|
640
|
+
null);
|
|
641
|
+
}
|
|
642
|
+
catch (_e) {
|
|
643
|
+
return null;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
async ensureConnectionRunning(id) {
|
|
647
|
+
if (this.has(id)) {
|
|
648
|
+
return true;
|
|
649
|
+
}
|
|
650
|
+
// Don't auto-restart intentionally stopped connections
|
|
651
|
+
const raw = await this.redis.get(`connection:${id}`);
|
|
652
|
+
if (raw) {
|
|
653
|
+
const connection = JSON.parse(raw);
|
|
654
|
+
if (connection.status === "stopped") {
|
|
655
|
+
logger.info({ id }, "Connection is stopped, not auto-restarting");
|
|
656
|
+
return false;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
try {
|
|
660
|
+
await this.restartConnection(id);
|
|
661
|
+
return this.has(id);
|
|
662
|
+
}
|
|
663
|
+
catch (error) {
|
|
664
|
+
logger.error({ id, error: String(error) }, "Failed to restart connection");
|
|
665
|
+
return false;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
async persistConnection(connection) {
|
|
669
|
+
const encrypted = Object.assign(Object.assign({}, connection), { config: this.encryptConfig(connection.config) });
|
|
670
|
+
const json = JSON.stringify(encrypted);
|
|
671
|
+
const pipeline = this.redis
|
|
672
|
+
.pipeline()
|
|
673
|
+
.set(`connection:${connection.id}`, json)
|
|
674
|
+
.sadd("connections:all", connection.id);
|
|
675
|
+
if (connection.templateAgentId) {
|
|
676
|
+
pipeline.sadd(`connections:agent:${connection.templateAgentId}`, connection.id);
|
|
677
|
+
}
|
|
678
|
+
await pipeline.exec();
|
|
679
|
+
}
|
|
680
|
+
encryptConfig(config) {
|
|
681
|
+
const encrypted = Object.assign({}, config);
|
|
682
|
+
for (const field of Object.keys(encrypted)) {
|
|
683
|
+
if ((0, types_1.isSecretField)(field) && typeof encrypted[field] === "string") {
|
|
684
|
+
try {
|
|
685
|
+
encrypted[field] = `enc:v1:${(0, core_1.encrypt)(encrypted[field])}`;
|
|
686
|
+
}
|
|
687
|
+
catch (_a) {
|
|
688
|
+
// encryption not available — store as-is (dev mode)
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
return encrypted;
|
|
693
|
+
}
|
|
694
|
+
decryptConfig(config) {
|
|
695
|
+
const decrypted = Object.assign({}, config);
|
|
696
|
+
for (const field of Object.keys(decrypted)) {
|
|
697
|
+
const val = decrypted[field];
|
|
698
|
+
if ((0, types_1.isSecretField)(field) &&
|
|
699
|
+
typeof val === "string" &&
|
|
700
|
+
val.startsWith("enc:v1:")) {
|
|
701
|
+
try {
|
|
702
|
+
decrypted[field] = (0, core_1.decrypt)(val.slice(7));
|
|
703
|
+
}
|
|
704
|
+
catch (_a) {
|
|
705
|
+
throw new Error(`Failed to decrypt field "${field}" — ENCRYPTION_KEY may have changed`);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
return decrypted;
|
|
710
|
+
}
|
|
711
|
+
/** Return connection with secrets redacted for API responses. */
|
|
712
|
+
sanitizeConnection(connection) {
|
|
713
|
+
const sanitized = Object.assign(Object.assign({}, connection), { config: Object.assign({}, connection.config) });
|
|
714
|
+
for (const field of Object.keys(sanitized.config)) {
|
|
715
|
+
if ((0, types_1.isSecretField)(field) && sanitized.config[field]) {
|
|
716
|
+
const val = String(sanitized.config[field]);
|
|
717
|
+
sanitized.config[field] = `***${val.slice(-4)}`;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
return sanitized;
|
|
721
|
+
}
|
|
722
|
+
// ============================================================================
|
|
723
|
+
// Platform adapter methods (used via PlatformRegistry)
|
|
724
|
+
// ============================================================================
|
|
725
|
+
/**
|
|
726
|
+
* Create PlatformAdapter objects for each chat platform.
|
|
727
|
+
* These are lightweight adapters that delegate to this manager.
|
|
728
|
+
*/
|
|
729
|
+
createPlatformAdapters() {
|
|
730
|
+
return Object.keys(exports.ADAPTER_FACTORIES).map((name) => this.createPlatformAdapter(name));
|
|
731
|
+
}
|
|
732
|
+
createPlatformAdapter(name) {
|
|
733
|
+
return {
|
|
734
|
+
name,
|
|
735
|
+
initialize: async () => {
|
|
736
|
+
/* no-op: lifecycle managed by ChatInstanceManager */
|
|
737
|
+
},
|
|
738
|
+
start: async () => {
|
|
739
|
+
/* no-op: lifecycle managed by ChatInstanceManager */
|
|
740
|
+
},
|
|
741
|
+
stop: async () => {
|
|
742
|
+
/* no-op: lifecycle managed by ChatInstanceManager */
|
|
743
|
+
},
|
|
744
|
+
isHealthy: () => true,
|
|
745
|
+
buildDeploymentMetadata: (conversationId, channelId, platformMetadata) => (Object.assign({ platform: name, channelId,
|
|
746
|
+
conversationId }, (typeof platformMetadata.connectionId === "string"
|
|
747
|
+
? { connectionId: platformMetadata.connectionId }
|
|
748
|
+
: {}))),
|
|
749
|
+
extractRoutingInfo: (body) => this.extractPlatformRoutingInfo(name, body),
|
|
750
|
+
sendMessage: (_token, message, options) => this.sendPlatformMessage(name, message, options),
|
|
751
|
+
getConversationHistory: (channelId, conversationId, limit, before) => this.getPlatformConversationHistory(name, channelId, conversationId, limit, before),
|
|
752
|
+
};
|
|
753
|
+
}
|
|
754
|
+
extractPlatformRoutingInfo(name, body) {
|
|
755
|
+
if (name === "slack") {
|
|
756
|
+
const slack = body.slack;
|
|
757
|
+
if (!(slack === null || slack === void 0 ? void 0 : slack.channel))
|
|
758
|
+
return null;
|
|
759
|
+
return {
|
|
760
|
+
channelId: slack.channel,
|
|
761
|
+
conversationId: slack.thread,
|
|
762
|
+
teamId: slack.team,
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
if (name === "telegram") {
|
|
766
|
+
const telegram = body.telegram;
|
|
767
|
+
if (!(telegram === null || telegram === void 0 ? void 0 : telegram.chatId))
|
|
768
|
+
return null;
|
|
769
|
+
return {
|
|
770
|
+
channelId: String(telegram.chatId),
|
|
771
|
+
conversationId: String(telegram.chatId),
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
const whatsapp = body.whatsapp;
|
|
775
|
+
if (!(whatsapp === null || whatsapp === void 0 ? void 0 : whatsapp.chat))
|
|
776
|
+
return null;
|
|
777
|
+
return {
|
|
778
|
+
channelId: whatsapp.chat,
|
|
779
|
+
conversationId: whatsapp.chat,
|
|
780
|
+
};
|
|
781
|
+
}
|
|
782
|
+
async sendPlatformMessage(name, message, options) {
|
|
783
|
+
var _a, _b, _c, _d, _e;
|
|
784
|
+
if ((_a = options.files) === null || _a === void 0 ? void 0 : _a.length) {
|
|
785
|
+
throw new Error(`Platform "${name}" does not support file uploads via Chat SDK routing yet`);
|
|
786
|
+
}
|
|
787
|
+
const connection = await this.selectConnectionForPlatform(name, options.channelId, options.teamId);
|
|
788
|
+
if (!connection) {
|
|
789
|
+
throw new Error(`No active ${name} connection is available`);
|
|
790
|
+
}
|
|
791
|
+
const instance = this.getInstance(connection.id);
|
|
792
|
+
if (!instance) {
|
|
793
|
+
throw new Error(`Connection ${connection.id} is not running`);
|
|
794
|
+
}
|
|
795
|
+
const content = name === "slack" ? message : message.replace(/@me\s*/g, "").trim();
|
|
796
|
+
if (!content) {
|
|
797
|
+
throw new Error("Cannot send an empty message");
|
|
798
|
+
}
|
|
799
|
+
const useThread = name === "slack" && !!options.conversationId;
|
|
800
|
+
let sent;
|
|
801
|
+
if (useThread) {
|
|
802
|
+
const adapter = (_c = (_b = instance.chat).getAdapter) === null || _c === void 0 ? void 0 : _c.call(_b, connection.platform);
|
|
803
|
+
const createThread = instance.chat.createThread;
|
|
804
|
+
const threadId = `${connection.platform}:${options.channelId}:${options.conversationId}`;
|
|
805
|
+
const thread = adapter && typeof createThread === "function"
|
|
806
|
+
? await createThread.call(instance.chat, adapter, threadId, {}, false)
|
|
807
|
+
: null;
|
|
808
|
+
if (!thread) {
|
|
809
|
+
throw new Error(`Unable to resolve ${name} thread`);
|
|
810
|
+
}
|
|
811
|
+
sent = await thread.post(content);
|
|
812
|
+
}
|
|
813
|
+
else {
|
|
814
|
+
const channel = (_e = (_d = instance.chat).channel) === null || _e === void 0 ? void 0 : _e.call(_d, `${connection.platform}:${options.channelId}`);
|
|
815
|
+
if (!channel) {
|
|
816
|
+
throw new Error(`Unable to resolve ${name} channel`);
|
|
817
|
+
}
|
|
818
|
+
sent = await channel.post(content);
|
|
819
|
+
}
|
|
820
|
+
return {
|
|
821
|
+
messageId: String((sent === null || sent === void 0 ? void 0 : sent.id) || (sent === null || sent === void 0 ? void 0 : sent.messageId) || (sent === null || sent === void 0 ? void 0 : sent.ts) || Date.now()),
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
async getPlatformConversationHistory(name, channelId, _conversationId, limit, before) {
|
|
825
|
+
const connection = await this.selectConnectionForPlatform(name, channelId);
|
|
826
|
+
if (!connection) {
|
|
827
|
+
return { messages: [], nextCursor: null, hasMore: false };
|
|
828
|
+
}
|
|
829
|
+
const redis = this.services.getQueue().getRedisClient();
|
|
830
|
+
const key = `chat:history:${connection.id}:${channelId}`;
|
|
831
|
+
const raw = await redis.lrange(key, 0, -1);
|
|
832
|
+
const parsed = [];
|
|
833
|
+
for (const entry of raw) {
|
|
834
|
+
try {
|
|
835
|
+
parsed.push(JSON.parse(entry));
|
|
836
|
+
}
|
|
837
|
+
catch (err) {
|
|
838
|
+
logger.warn({ key, error: String(err) }, "Skipping corrupt history entry");
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
let entries = parsed;
|
|
842
|
+
if (before) {
|
|
843
|
+
const cutoff = Date.parse(before);
|
|
844
|
+
if (!Number.isNaN(cutoff)) {
|
|
845
|
+
entries = entries.filter((entry) => entry.timestamp < cutoff);
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
const hasMore = entries.length > limit;
|
|
849
|
+
const selected = entries.slice(-limit);
|
|
850
|
+
const nextCursor = hasMore && selected[0]
|
|
851
|
+
? new Date(selected[0].timestamp).toISOString()
|
|
852
|
+
: null;
|
|
853
|
+
return {
|
|
854
|
+
messages: selected.map((entry) => ({
|
|
855
|
+
timestamp: new Date(entry.timestamp).toISOString(),
|
|
856
|
+
user: entry.authorName ||
|
|
857
|
+
(entry.role === "assistant" ? "assistant" : "user"),
|
|
858
|
+
text: entry.content,
|
|
859
|
+
isBot: entry.role === "assistant",
|
|
860
|
+
})),
|
|
861
|
+
nextCursor,
|
|
862
|
+
hasMore,
|
|
863
|
+
};
|
|
864
|
+
}
|
|
865
|
+
async selectConnectionForPlatform(name, channelId, teamId) {
|
|
866
|
+
const connections = await this.listConnections({ platform: name });
|
|
867
|
+
const activeConnections = connections.filter((connection) => this.has(connection.id));
|
|
868
|
+
if (activeConnections.length === 0)
|
|
869
|
+
return null;
|
|
870
|
+
if (activeConnections.length === 1)
|
|
871
|
+
return activeConnections[0] || null;
|
|
872
|
+
const teamMatch = activeConnections.find((connection) => { var _a; return ((_a = connection.metadata) === null || _a === void 0 ? void 0 : _a.teamId) === teamId; });
|
|
873
|
+
if (teamMatch)
|
|
874
|
+
return teamMatch;
|
|
875
|
+
const redis = this.services.getQueue().getRedisClient();
|
|
876
|
+
for (const connection of activeConnections) {
|
|
877
|
+
const exists = await redis.exists(`chat:history:${connection.id}:${channelId}`);
|
|
878
|
+
if (exists === 1) {
|
|
879
|
+
return connection;
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
return activeConnections[0] || null;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
exports.ChatInstanceManager = ChatInstanceManager;
|
|
886
|
+
//# sourceMappingURL=chat-instance-manager.js.map
|