n8n 2.20.6 → 2.21.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/abstract-server.d.ts +1 -0
- package/dist/abstract-server.js +10 -3
- package/dist/abstract-server.js.map +1 -1
- package/dist/agent-library-bundle.js +5989 -0
- package/dist/auth/auth.service.js +3 -3
- package/dist/auth/auth.service.js.map +1 -1
- package/dist/build.tsbuildinfo +1 -1
- package/dist/commands/execute-batch.d.ts +2 -2
- package/dist/commands/export/workflow.d.ts +2 -2
- package/dist/commands/import/workflow.d.ts +3 -0
- package/dist/commands/import/workflow.js +15 -1
- package/dist/commands/import/workflow.js.map +1 -1
- package/dist/commands/start.js +2 -0
- package/dist/commands/start.js.map +1 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +6 -1
- package/dist/constants.js.map +1 -1
- package/dist/controller.registry.js +6 -0
- package/dist/controller.registry.js.map +1 -1
- package/dist/controllers/auth.controller.js +7 -2
- package/dist/controllers/auth.controller.js.map +1 -1
- package/dist/controllers/me.controller.d.ts +1 -0
- package/dist/controllers/me.controller.js +4 -1
- package/dist/controllers/me.controller.js.map +1 -1
- package/dist/controllers/users.controller.d.ts +2 -2
- package/dist/credentials/credentials.service.d.ts +1 -0
- package/dist/credentials/credentials.service.js +11 -4
- package/dist/credentials/credentials.service.js.map +1 -1
- package/dist/evaluation.ee/evaluation-api-error.d.ts +7 -0
- package/dist/evaluation.ee/evaluation-api-error.js +16 -0
- package/dist/evaluation.ee/evaluation-api-error.js.map +1 -0
- package/dist/evaluation.ee/evaluation-config-validator.d.ts +30 -0
- package/dist/evaluation.ee/evaluation-config-validator.js +236 -0
- package/dist/evaluation.ee/evaluation-config-validator.js.map +1 -0
- package/dist/evaluation.ee/evaluation-config.controller.d.ts +24 -0
- package/dist/evaluation.ee/evaluation-config.controller.js +94 -0
- package/dist/evaluation.ee/evaluation-config.controller.js.map +1 -0
- package/dist/evaluation.ee/evaluation-config.service.d.ts +18 -0
- package/dist/evaluation.ee/evaluation-config.service.js +74 -0
- package/dist/evaluation.ee/evaluation-config.service.js.map +1 -0
- package/dist/evaluation.ee/llm-judge-provider-registry.d.ts +13 -0
- package/dist/evaluation.ee/llm-judge-provider-registry.js +122 -0
- package/dist/evaluation.ee/llm-judge-provider-registry.js.map +1 -0
- package/dist/evaluation.ee/test-runner/test-runner.service.ee.d.ts +5 -0
- package/dist/evaluation.ee/test-runner/test-runner.service.ee.js +32 -10
- package/dist/evaluation.ee/test-runner/test-runner.service.ee.js.map +1 -1
- package/dist/evaluation.ee/test-runner/workflow-compiler.service.d.ts +22 -0
- package/dist/evaluation.ee/test-runner/workflow-compiler.service.js +285 -0
- package/dist/evaluation.ee/test-runner/workflow-compiler.service.js.map +1 -0
- package/dist/evaluation.ee/test-runs.controller.ee.d.ts +3 -0
- package/dist/evaluation.ee/test-runs.controller.ee.js +26 -9
- package/dist/evaluation.ee/test-runs.controller.ee.js.map +1 -1
- package/dist/evaluation.ee/test-runs.types.ee.d.ts +3 -0
- package/dist/eventbus/message-event-bus/message-event-bus.d.ts +2 -0
- package/dist/eventbus/message-event-bus/message-event-bus.js +54 -46
- package/dist/eventbus/message-event-bus/message-event-bus.js.map +1 -1
- package/dist/events/maps/relay.event-map.d.ts +3 -0
- package/dist/instance-settings-loader/instance-settings-loader.service.d.ts +4 -2
- package/dist/instance-settings-loader/instance-settings-loader.service.js +7 -3
- package/dist/instance-settings-loader/instance-settings-loader.service.js.map +1 -1
- package/dist/instance-settings-loader/loaders/community-packages.instance-settings-loader.d.ts +20 -0
- package/dist/instance-settings-loader/loaders/community-packages.instance-settings-loader.js +235 -0
- package/dist/instance-settings-loader/loaders/community-packages.instance-settings-loader.js.map +1 -0
- package/dist/instance-settings-loader/loaders/{sso.instance-settings-loader.d.ts → sso/oidc.instance-settings-loader.d.ts} +4 -10
- package/dist/instance-settings-loader/loaders/sso/oidc.instance-settings-loader.js +98 -0
- package/dist/instance-settings-loader/loaders/sso/oidc.instance-settings-loader.js.map +1 -0
- package/dist/instance-settings-loader/loaders/sso/provisioning.instance-settings-loader.d.ts +10 -0
- package/dist/instance-settings-loader/loaders/sso/provisioning.instance-settings-loader.js +65 -0
- package/dist/instance-settings-loader/loaders/sso/provisioning.instance-settings-loader.js.map +1 -0
- package/dist/instance-settings-loader/loaders/sso/saml.instance-settings-loader.d.ts +12 -0
- package/dist/instance-settings-loader/loaders/sso/saml.instance-settings-loader.js +75 -0
- package/dist/instance-settings-loader/loaders/sso/saml.instance-settings-loader.js.map +1 -0
- package/dist/instance-settings-loader/loaders/sso/sso.instance-settings-loader.d.ts +15 -0
- package/dist/instance-settings-loader/loaders/sso/sso.instance-settings-loader.js +75 -0
- package/dist/instance-settings-loader/loaders/sso/sso.instance-settings-loader.js.map +1 -0
- package/dist/load-nodes-and-credentials.d.ts +3 -3
- package/dist/load-nodes-and-credentials.js +25 -17
- package/dist/load-nodes-and-credentials.js.map +1 -1
- package/dist/modules/agents/adapters/agents-credential-provider.d.ts +12 -0
- package/dist/modules/agents/adapters/agents-credential-provider.js +63 -0
- package/dist/modules/agents/adapters/agents-credential-provider.js.map +1 -0
- package/dist/modules/agents/agent-execution.service.d.ts +42 -0
- package/dist/modules/agents/agent-execution.service.js +153 -0
- package/dist/modules/agents/agent-execution.service.js.map +1 -0
- package/dist/modules/agents/agent-message-mapper.d.ts +5 -0
- package/dist/modules/agents/agent-message-mapper.js +43 -0
- package/dist/modules/agents/agent-message-mapper.js.map +1 -0
- package/dist/modules/agents/agent-skills.service.d.ts +24 -0
- package/dist/modules/agents/agent-skills.service.js +166 -0
- package/dist/modules/agents/agent-skills.service.js.map +1 -0
- package/dist/modules/agents/agent-sse-stream.d.ts +15 -0
- package/dist/modules/agents/agent-sse-stream.js +194 -0
- package/dist/modules/agents/agent-sse-stream.js.map +1 -0
- package/dist/modules/agents/agents-tools.service.d.ts +18 -0
- package/dist/modules/agents/agents-tools.service.js +193 -0
- package/dist/modules/agents/agents-tools.service.js.map +1 -0
- package/dist/modules/agents/agents.controller.d.ts +260 -0
- package/dist/modules/agents/agents.controller.js +818 -0
- package/dist/modules/agents/agents.controller.js.map +1 -0
- package/dist/modules/agents/agents.module.d.ts +12 -0
- package/dist/modules/agents/agents.module.js +136 -0
- package/dist/modules/agents/agents.module.js.map +1 -0
- package/dist/modules/agents/agents.service.d.ts +151 -0
- package/dist/modules/agents/agents.service.js +1134 -0
- package/dist/modules/agents/agents.service.js.map +1 -0
- package/dist/modules/agents/builder/agents-builder-prompts.d.ts +27 -0
- package/dist/modules/agents/builder/agents-builder-prompts.js +584 -0
- package/dist/modules/agents/builder/agents-builder-prompts.js.map +1 -0
- package/dist/modules/agents/builder/agents-builder-settings.controller.d.ts +11 -0
- package/dist/modules/agents/builder/agents-builder-settings.controller.js +61 -0
- package/dist/modules/agents/builder/agents-builder-settings.controller.js.map +1 -0
- package/dist/modules/agents/builder/agents-builder-settings.service.d.ts +31 -0
- package/dist/modules/agents/builder/agents-builder-settings.service.js +199 -0
- package/dist/modules/agents/builder/agents-builder-settings.service.js.map +1 -0
- package/dist/modules/agents/builder/agents-builder-tools.service.d.ts +31 -0
- package/dist/modules/agents/builder/agents-builder-tools.service.js +420 -0
- package/dist/modules/agents/builder/agents-builder-tools.service.js.map +1 -0
- package/dist/modules/agents/builder/agents-builder.service.d.ts +26 -0
- package/dist/modules/agents/builder/agents-builder.service.js +164 -0
- package/dist/modules/agents/builder/agents-builder.service.js.map +1 -0
- package/dist/modules/agents/builder/builder-model-lookup.service.d.ts +17 -0
- package/dist/modules/agents/builder/builder-model-lookup.service.js +67 -0
- package/dist/modules/agents/builder/builder-model-lookup.service.js.map +1 -0
- package/dist/modules/agents/builder/builder-tool-names.d.ts +14 -0
- package/dist/modules/agents/builder/builder-tool-names.js +17 -0
- package/dist/modules/agents/builder/builder-tool-names.js.map +1 -0
- package/dist/modules/agents/builder/errors.d.ts +6 -0
- package/dist/modules/agents/builder/errors.js +13 -0
- package/dist/modules/agents/builder/errors.js.map +1 -0
- package/dist/modules/agents/builder/interactive/ask-credential.tool.d.ts +5 -0
- package/dist/modules/agents/builder/interactive/ask-credential.tool.js +29 -0
- package/dist/modules/agents/builder/interactive/ask-credential.tool.js.map +1 -0
- package/dist/modules/agents/builder/interactive/ask-llm.tool.d.ts +2 -0
- package/dist/modules/agents/builder/interactive/ask-llm.tool.js +27 -0
- package/dist/modules/agents/builder/interactive/ask-llm.tool.js.map +1 -0
- package/dist/modules/agents/builder/interactive/ask-question.tool.d.ts +2 -0
- package/dist/modules/agents/builder/interactive/ask-question.tool.js +26 -0
- package/dist/modules/agents/builder/interactive/ask-question.tool.js.map +1 -0
- package/dist/modules/agents/builder/interactive/index.d.ts +4 -0
- package/dist/modules/agents/builder/interactive/index.js +12 -0
- package/dist/modules/agents/builder/interactive/index.js.map +1 -0
- package/dist/modules/agents/builder/interactive/llm-provider-defaults.d.ts +17 -0
- package/dist/modules/agents/builder/interactive/llm-provider-defaults.js +60 -0
- package/dist/modules/agents/builder/interactive/llm-provider-defaults.js.map +1 -0
- package/dist/modules/agents/builder/interactive/resolve-llm.tool.d.ts +13 -0
- package/dist/modules/agents/builder/interactive/resolve-llm.tool.js +136 -0
- package/dist/modules/agents/builder/interactive/resolve-llm.tool.js.map +1 -0
- package/dist/modules/agents/entities/agent-checkpoint.entity.d.ts +9 -0
- package/dist/modules/agents/entities/agent-checkpoint.entity.js +43 -0
- package/dist/modules/agents/entities/agent-checkpoint.entity.js.map +1 -0
- package/dist/modules/agents/entities/agent-execution-thread.entity.d.ts +16 -0
- package/dist/modules/agents/entities/agent-execution-thread.entity.js +74 -0
- package/dist/modules/agents/entities/agent-execution-thread.entity.js.map +1 -0
- package/dist/modules/agents/entities/agent-execution.entity.d.ts +26 -0
- package/dist/modules/agents/entities/agent-execution.entity.js +100 -0
- package/dist/modules/agents/entities/agent-execution.entity.js.map +1 -0
- package/dist/modules/agents/entities/agent-message.entity.d.ts +10 -0
- package/dist/modules/agents/entities/agent-message.entity.js +47 -0
- package/dist/modules/agents/entities/agent-message.entity.js.map +1 -0
- package/dist/modules/agents/entities/agent-observation-cursor.entity.d.ts +8 -0
- package/dist/modules/agents/entities/agent-observation-cursor.entity.js +37 -0
- package/dist/modules/agents/entities/agent-observation-cursor.entity.js.map +1 -0
- package/dist/modules/agents/entities/agent-observation-lock.entity.d.ts +8 -0
- package/dist/modules/agents/entities/agent-observation-lock.entity.js +37 -0
- package/dist/modules/agents/entities/agent-observation-lock.entity.js.map +1 -0
- package/dist/modules/agents/entities/agent-observation.entity.d.ts +10 -0
- package/dist/modules/agents/entities/agent-observation.entity.js +47 -0
- package/dist/modules/agents/entities/agent-observation.entity.js.map +1 -0
- package/dist/modules/agents/entities/agent-published-version.entity.d.ts +22 -0
- package/dist/modules/agents/entities/agent-published-version.entity.js +67 -0
- package/dist/modules/agents/entities/agent-published-version.entity.js.map +1 -0
- package/dist/modules/agents/entities/agent-resource.entity.d.ts +5 -0
- package/dist/modules/agents/entities/agent-resource.entity.js +29 -0
- package/dist/modules/agents/entities/agent-resource.entity.js.map +1 -0
- package/dist/modules/agents/entities/agent-thread.entity.d.ts +6 -0
- package/dist/modules/agents/entities/agent-thread.entity.js +33 -0
- package/dist/modules/agents/entities/agent-thread.entity.js.map +1 -0
- package/dist/modules/agents/entities/agent.entity.d.ts +24 -0
- package/dist/modules/agents/entities/agent.entity.js +74 -0
- package/dist/modules/agents/entities/agent.entity.js.map +1 -0
- package/dist/modules/agents/execution-recorder.d.ts +82 -0
- package/dist/modules/agents/execution-recorder.js +272 -0
- package/dist/modules/agents/execution-recorder.js.map +1 -0
- package/dist/modules/agents/integrations/agent-chat-bridge.d.ts +62 -0
- package/dist/modules/agents/integrations/agent-chat-bridge.js +540 -0
- package/dist/modules/agents/integrations/agent-chat-bridge.js.map +1 -0
- package/dist/modules/agents/integrations/agent-chat-integration.d.ts +39 -0
- package/dist/modules/agents/integrations/agent-chat-integration.js +45 -0
- package/dist/modules/agents/integrations/agent-chat-integration.js.map +1 -0
- package/dist/modules/agents/integrations/agent-schedule.service.d.ts +30 -0
- package/dist/modules/agents/integrations/agent-schedule.service.js +327 -0
- package/dist/modules/agents/integrations/agent-schedule.service.js.map +1 -0
- package/dist/modules/agents/integrations/callback-store.d.ts +11 -0
- package/dist/modules/agents/integrations/callback-store.js +30 -0
- package/dist/modules/agents/integrations/callback-store.js.map +1 -0
- package/dist/modules/agents/integrations/chat-integration.service.d.ts +58 -0
- package/dist/modules/agents/integrations/chat-integration.service.js +397 -0
- package/dist/modules/agents/integrations/chat-integration.service.js.map +1 -0
- package/dist/modules/agents/integrations/component-mapper.d.ts +57 -0
- package/dist/modules/agents/integrations/component-mapper.js +223 -0
- package/dist/modules/agents/integrations/component-mapper.js.map +1 -0
- package/dist/modules/agents/integrations/cron-validation.d.ts +1 -0
- package/dist/modules/agents/integrations/cron-validation.js +8 -0
- package/dist/modules/agents/integrations/cron-validation.js.map +1 -0
- package/dist/modules/agents/integrations/esm-loader.d.ts +5 -0
- package/dist/modules/agents/integrations/esm-loader.js +24 -0
- package/dist/modules/agents/integrations/esm-loader.js.map +1 -0
- package/dist/modules/agents/integrations/integrations-sync.d.ts +4 -0
- package/dist/modules/agents/integrations/integrations-sync.js +78 -0
- package/dist/modules/agents/integrations/integrations-sync.js.map +1 -0
- package/dist/modules/agents/integrations/n8n-checkpoint-storage.d.ts +36 -0
- package/dist/modules/agents/integrations/n8n-checkpoint-storage.js +148 -0
- package/dist/modules/agents/integrations/n8n-checkpoint-storage.js.map +1 -0
- package/dist/modules/agents/integrations/n8n-memory.d.ts +76 -0
- package/dist/modules/agents/integrations/n8n-memory.js +383 -0
- package/dist/modules/agents/integrations/n8n-memory.js.map +1 -0
- package/dist/modules/agents/integrations/platforms/linear-integration.d.ts +14 -0
- package/dist/modules/agents/integrations/platforms/linear-integration.js +83 -0
- package/dist/modules/agents/integrations/platforms/linear-integration.js.map +1 -0
- package/dist/modules/agents/integrations/platforms/slack-integration.d.ts +12 -0
- package/dist/modules/agents/integrations/platforms/slack-integration.js +81 -0
- package/dist/modules/agents/integrations/platforms/slack-integration.js.map +1 -0
- package/dist/modules/agents/integrations/platforms/telegram-integration.d.ts +30 -0
- package/dist/modules/agents/integrations/platforms/telegram-integration.js +122 -0
- package/dist/modules/agents/integrations/platforms/telegram-integration.js.map +1 -0
- package/dist/modules/agents/integrations/rich-interaction-tool.d.ts +47 -0
- package/dist/modules/agents/integrations/rich-interaction-tool.js +109 -0
- package/dist/modules/agents/integrations/rich-interaction-tool.js.map +1 -0
- package/dist/modules/agents/integrations/types.d.ts +8 -0
- package/dist/modules/agents/integrations/types.js +12 -0
- package/dist/modules/agents/integrations/types.js.map +1 -0
- package/dist/modules/agents/json-config/agent-config-composition.d.ts +9 -0
- package/dist/modules/agents/json-config/agent-config-composition.js +27 -0
- package/dist/modules/agents/json-config/agent-config-composition.js.map +1 -0
- package/dist/modules/agents/json-config/agent-json-config.d.ts +1022 -0
- package/dist/modules/agents/json-config/agent-json-config.js +128 -0
- package/dist/modules/agents/json-config/agent-json-config.js.map +1 -0
- package/dist/modules/agents/json-config/credential-field-mapping.d.ts +4 -0
- package/dist/modules/agents/json-config/credential-field-mapping.js +41 -0
- package/dist/modules/agents/json-config/credential-field-mapping.js.map +1 -0
- package/dist/modules/agents/json-config/from-json-config.d.ts +18 -0
- package/dist/modules/agents/json-config/from-json-config.js +209 -0
- package/dist/modules/agents/json-config/from-json-config.js.map +1 -0
- package/dist/modules/agents/json-config/integration-config.d.ts +61 -0
- package/dist/modules/agents/json-config/integration-config.js +33 -0
- package/dist/modules/agents/json-config/integration-config.js.map +1 -0
- package/dist/modules/agents/json-config/provider-tool-aliases.d.ts +1 -0
- package/dist/modules/agents/json-config/provider-tool-aliases.js +15 -0
- package/dist/modules/agents/json-config/provider-tool-aliases.js.map +1 -0
- package/dist/modules/agents/json-config/schema-text-serializer.d.ts +2 -0
- package/dist/modules/agents/json-config/schema-text-serializer.js +205 -0
- package/dist/modules/agents/json-config/schema-text-serializer.js.map +1 -0
- package/dist/modules/agents/repositories/agent-checkpoint.repository.d.ts +6 -0
- package/dist/modules/agents/repositories/agent-checkpoint.repository.js +35 -0
- package/dist/modules/agents/repositories/agent-checkpoint.repository.js.map +1 -0
- package/dist/modules/agents/repositories/agent-execution-thread.repository.d.ts +18 -0
- package/dist/modules/agents/repositories/agent-execution-thread.repository.js +120 -0
- package/dist/modules/agents/repositories/agent-execution-thread.repository.js.map +1 -0
- package/dist/modules/agents/repositories/agent-execution.repository.d.ts +10 -0
- package/dist/modules/agents/repositories/agent-execution.repository.js +59 -0
- package/dist/modules/agents/repositories/agent-execution.repository.js.map +1 -0
- package/dist/modules/agents/repositories/agent-message.repository.d.ts +5 -0
- package/dist/modules/agents/repositories/agent-message.repository.js +26 -0
- package/dist/modules/agents/repositories/agent-message.repository.js.map +1 -0
- package/dist/modules/agents/repositories/agent-observation-cursor.repository.d.ts +5 -0
- package/dist/modules/agents/repositories/agent-observation-cursor.repository.js +26 -0
- package/dist/modules/agents/repositories/agent-observation-cursor.repository.js.map +1 -0
- package/dist/modules/agents/repositories/agent-observation-lock.repository.d.ts +5 -0
- package/dist/modules/agents/repositories/agent-observation-lock.repository.js +26 -0
- package/dist/modules/agents/repositories/agent-observation-lock.repository.js.map +1 -0
- package/dist/modules/agents/repositories/agent-observation.repository.d.ts +5 -0
- package/dist/modules/agents/repositories/agent-observation.repository.js +26 -0
- package/dist/modules/agents/repositories/agent-observation.repository.js.map +1 -0
- package/dist/modules/agents/repositories/agent-published-version.repository.d.ts +20 -0
- package/dist/modules/agents/repositories/agent-published-version.repository.js +35 -0
- package/dist/modules/agents/repositories/agent-published-version.repository.js.map +1 -0
- package/dist/modules/agents/repositories/agent-resource.repository.d.ts +5 -0
- package/dist/modules/agents/repositories/agent-resource.repository.js +26 -0
- package/dist/modules/agents/repositories/agent-resource.repository.js.map +1 -0
- package/dist/modules/agents/repositories/agent-thread.repository.d.ts +5 -0
- package/dist/modules/agents/repositories/agent-thread.repository.js +26 -0
- package/dist/modules/agents/repositories/agent-thread.repository.js.map +1 -0
- package/dist/modules/agents/repositories/agent.repository.d.ts +9 -0
- package/dist/modules/agents/repositories/agent.repository.js +50 -0
- package/dist/modules/agents/repositories/agent.repository.js.map +1 -0
- package/dist/modules/agents/runtime/agent-isolate-pool.d.ts +48 -0
- package/dist/modules/agents/runtime/agent-isolate-pool.js +246 -0
- package/dist/modules/agents/runtime/agent-isolate-pool.js.map +1 -0
- package/dist/modules/agents/runtime/agent-secure-runtime.d.ts +21 -0
- package/dist/modules/agents/runtime/agent-secure-runtime.js +281 -0
- package/dist/modules/agents/runtime/agent-secure-runtime.js.map +1 -0
- package/dist/modules/agents/runtime/sandbox-polyfills.d.ts +1 -0
- package/dist/modules/agents/runtime/sandbox-polyfills.js +74 -0
- package/dist/modules/agents/runtime/sandbox-polyfills.js.map +1 -0
- package/dist/modules/agents/tool-registry.d.ts +13 -0
- package/dist/modules/agents/tool-registry.js +42 -0
- package/dist/modules/agents/tool-registry.js.map +1 -0
- package/dist/modules/agents/tools/environment-tool.d.ts +3 -0
- package/dist/modules/agents/tools/environment-tool.js +26 -0
- package/dist/modules/agents/tools/environment-tool.js.map +1 -0
- package/dist/modules/agents/tools/node-tool-factory.d.ts +10 -0
- package/dist/modules/agents/tools/node-tool-factory.js +100 -0
- package/dist/modules/agents/tools/node-tool-factory.js.map +1 -0
- package/dist/modules/agents/tools/workflow-tool-factory.d.ts +43 -0
- package/dist/modules/agents/tools/workflow-tool-factory.js +404 -0
- package/dist/modules/agents/tools/workflow-tool-factory.js.map +1 -0
- package/dist/modules/agents/tracing/builder-telemetry.d.ts +12 -0
- package/dist/modules/agents/tracing/builder-telemetry.js +48 -0
- package/dist/modules/agents/tracing/builder-telemetry.js.map +1 -0
- package/dist/modules/agents/types/components.d.ts +71 -0
- package/dist/modules/agents/types/components.js +3 -0
- package/dist/modules/agents/types/components.js.map +1 -0
- package/dist/modules/agents/types/index.d.ts +1 -0
- package/dist/modules/agents/types/index.js +3 -0
- package/dist/modules/agents/types/index.js.map +1 -0
- package/dist/modules/agents/utils/agent-draft.utils.d.ts +2 -0
- package/dist/modules/agents/utils/agent-draft.utils.js +11 -0
- package/dist/modules/agents/utils/agent-draft.utils.js.map +1 -0
- package/dist/modules/agents/utils/agent-resource-id.d.ts +3 -0
- package/dist/modules/agents/utils/agent-resource-id.js +14 -0
- package/dist/modules/agents/utils/agent-resource-id.js.map +1 -0
- package/dist/modules/chat-hub/chat-hub.module.d.ts +2 -2
- package/dist/modules/chat-hub/chat-hub.settings.controller.d.ts +4 -4
- package/dist/modules/chat-hub/chat-hub.types.d.ts +2 -2
- package/dist/modules/chat-hub/dto/chat-models-request.dto.d.ts +1 -1
- package/dist/modules/community-packages/community-packages.config.js +2 -2
- package/dist/modules/community-packages/community-packages.config.js.map +1 -1
- package/dist/modules/community-packages/community-packages.lifecycle.service.d.ts +4 -1
- package/dist/modules/community-packages/community-packages.lifecycle.service.js +14 -2
- package/dist/modules/community-packages/community-packages.lifecycle.service.js.map +1 -1
- package/dist/modules/community-packages/community-packages.module.d.ts +1 -1
- package/dist/modules/community-packages/community-packages.module.js +10 -5
- package/dist/modules/community-packages/community-packages.module.js.map +1 -1
- package/dist/modules/data-table/data-table.service.js +6 -0
- package/dist/modules/data-table/data-table.service.js.map +1 -1
- package/dist/modules/dynamic-credentials.ee/credential-resolvers/identifiers/slack-signature-identifier.d.ts +1 -1
- package/dist/modules/dynamic-credentials.ee/dynamic-credentials.config.d.ts +2 -0
- package/dist/modules/dynamic-credentials.ee/dynamic-credentials.config.js +10 -0
- package/dist/modules/dynamic-credentials.ee/dynamic-credentials.config.js.map +1 -1
- package/dist/modules/dynamic-credentials.ee/dynamic-credentials.controller.d.ts +1 -1
- package/dist/modules/dynamic-credentials.ee/dynamic-credentials.controller.js +16 -4
- package/dist/modules/dynamic-credentials.ee/dynamic-credentials.controller.js.map +1 -1
- package/dist/modules/dynamic-credentials.ee/workflow-status.controller.d.ts +3 -3
- package/dist/modules/dynamic-credentials.ee/workflow-status.controller.js +11 -3
- package/dist/modules/dynamic-credentials.ee/workflow-status.controller.js.map +1 -1
- package/dist/modules/encryption-key-manager/encryption-bootstrap.service.js +4 -2
- package/dist/modules/encryption-key-manager/encryption-bootstrap.service.js.map +1 -1
- package/dist/modules/encryption-key-manager/encryption-key-manager.module.js +5 -2
- package/dist/modules/encryption-key-manager/encryption-key-manager.module.js.map +1 -1
- package/dist/modules/encryption-key-manager/encryption-key.controller.d.ts +3 -3
- package/dist/modules/encryption-key-manager/encryption-key.controller.js +8 -2
- package/dist/modules/encryption-key-manager/encryption-key.controller.js.map +1 -1
- package/dist/modules/encryption-key-manager/key-manager.service.d.ts +5 -1
- package/dist/modules/encryption-key-manager/key-manager.service.js +11 -4
- package/dist/modules/encryption-key-manager/key-manager.service.js.map +1 -1
- package/dist/modules/insights/insights-collection.service.js +1 -0
- package/dist/modules/insights/insights-collection.service.js.map +1 -1
- package/dist/modules/instance-ai/eval/mock-handler.js +17 -49
- package/dist/modules/instance-ai/eval/mock-handler.js.map +1 -1
- package/dist/modules/instance-ai/filesystem/local-gateway-registry.d.ts +1 -0
- package/dist/modules/instance-ai/filesystem/local-gateway-registry.js +21 -3
- package/dist/modules/instance-ai/filesystem/local-gateway-registry.js.map +1 -1
- package/dist/modules/instance-ai/instance-ai-settings.service.d.ts +3 -2
- package/dist/modules/instance-ai/instance-ai-settings.service.js +10 -9
- package/dist/modules/instance-ai/instance-ai-settings.service.js.map +1 -1
- package/dist/modules/instance-ai/instance-ai-test.controller.d.ts +21 -2
- package/dist/modules/instance-ai/instance-ai-test.controller.js +35 -3
- package/dist/modules/instance-ai/instance-ai-test.controller.js.map +1 -1
- package/dist/modules/instance-ai/instance-ai.adapter.service.js +72 -42
- package/dist/modules/instance-ai/instance-ai.adapter.service.js.map +1 -1
- package/dist/modules/instance-ai/instance-ai.controller.d.ts +2 -0
- package/dist/modules/instance-ai/instance-ai.controller.js +25 -1
- package/dist/modules/instance-ai/instance-ai.controller.js.map +1 -1
- package/dist/modules/instance-ai/instance-ai.module.d.ts +0 -1
- package/dist/modules/instance-ai/instance-ai.module.js +0 -2
- package/dist/modules/instance-ai/instance-ai.module.js.map +1 -1
- package/dist/modules/instance-ai/instance-ai.service.d.ts +34 -5
- package/dist/modules/instance-ai/instance-ai.service.js +723 -76
- package/dist/modules/instance-ai/instance-ai.service.js.map +1 -1
- package/dist/modules/instance-ai/liveness/index.d.ts +1 -0
- package/dist/modules/instance-ai/liveness/index.js +7 -0
- package/dist/modules/instance-ai/liveness/index.js.map +1 -0
- package/dist/modules/instance-ai/liveness/instance-ai-liveness.service.d.ts +72 -0
- package/dist/modules/instance-ai/liveness/instance-ai-liveness.service.js +123 -0
- package/dist/modules/instance-ai/liveness/instance-ai-liveness.service.js.map +1 -0
- package/dist/modules/instance-ai/message-parser.js +85 -6
- package/dist/modules/instance-ai/message-parser.js.map +1 -1
- package/dist/modules/instance-ai/storage/db-snapshot-storage.js +4 -0
- package/dist/modules/instance-ai/storage/db-snapshot-storage.js.map +1 -1
- package/dist/modules/instance-ai/storage/typeorm-memory-storage.js +1 -0
- package/dist/modules/instance-ai/storage/typeorm-memory-storage.js.map +1 -1
- package/dist/modules/instance-ai/web-research/fetch-and-extract.js +23 -7
- package/dist/modules/instance-ai/web-research/fetch-and-extract.js.map +1 -1
- package/dist/modules/mcp/mcp.service.d.ts +3 -3
- package/dist/modules/mcp/mcp.service.js +12 -9
- package/dist/modules/mcp/mcp.service.js.map +1 -1
- package/dist/modules/mcp/tools/get-execution.tool.js +6 -4
- package/dist/modules/mcp/tools/get-execution.tool.js.map +1 -1
- package/dist/modules/mcp/tools/list-credentials.tool.d.ts +40 -0
- package/dist/modules/mcp/tools/list-credentials.tool.js +148 -0
- package/dist/modules/mcp/tools/list-credentials.tool.js.map +1 -0
- package/dist/modules/mcp/tools/workflow-builder/create-workflow-from-code.tool.js +5 -4
- package/dist/modules/mcp/tools/workflow-builder/create-workflow-from-code.tool.js.map +1 -1
- package/dist/modules/mcp/tools/workflow-builder/get-suggested-workflow-nodes.tool.d.ts +2 -2
- package/dist/modules/mcp/tools/workflow-builder/get-suggested-workflow-nodes.tool.js +3 -3
- package/dist/modules/mcp/tools/workflow-builder/get-suggested-workflow-nodes.tool.js.map +1 -1
- package/dist/modules/mcp/tools/workflow-builder/get-workflow-node-types.tool.d.ts +2 -2
- package/dist/modules/mcp/tools/workflow-builder/get-workflow-node-types.tool.js +2 -2
- package/dist/modules/mcp/tools/workflow-builder/get-workflow-node-types.tool.js.map +1 -1
- package/dist/modules/mcp/tools/workflow-builder/get-workflow-sdk-reference.tool.js +3 -2
- package/dist/modules/mcp/tools/workflow-builder/get-workflow-sdk-reference.tool.js.map +1 -1
- package/dist/modules/mcp/tools/workflow-builder/mcp-instructions.js +3 -3
- package/dist/modules/mcp/tools/workflow-builder/mcp-instructions.js.map +1 -1
- package/dist/modules/mcp/tools/workflow-builder/sdk-reference-content.d.ts +1 -1
- package/dist/modules/mcp/tools/workflow-builder/sdk-reference-content.js +12 -4
- package/dist/modules/mcp/tools/workflow-builder/sdk-reference-content.js.map +1 -1
- package/dist/modules/mcp/tools/workflow-builder/search-workflow-nodes.tool.d.ts +2 -2
- package/dist/modules/mcp/tools/workflow-builder/search-workflow-nodes.tool.js +12 -5
- package/dist/modules/mcp/tools/workflow-builder/search-workflow-nodes.tool.js.map +1 -1
- package/dist/modules/mcp/tools/workflow-builder/update-workflow.tool.js +1 -2
- package/dist/modules/mcp/tools/workflow-builder/update-workflow.tool.js.map +1 -1
- package/dist/modules/mcp/tools/workflow-builder/validate-workflow-code.tool.js +1 -1
- package/dist/modules/mcp/tools/workflow-builder/validate-workflow-code.tool.js.map +1 -1
- package/dist/modules/mcp/tools/workflow-validation.utils.d.ts +5 -1
- package/dist/modules/mcp/tools/workflow-validation.utils.js +4 -2
- package/dist/modules/mcp/tools/workflow-validation.utils.js.map +1 -1
- package/dist/modules/mcp-registry/mcp-registry-node-loader.d.ts +27 -0
- package/dist/modules/mcp-registry/mcp-registry-node-loader.js +105 -0
- package/dist/modules/mcp-registry/mcp-registry-node-loader.js.map +1 -0
- package/dist/modules/mcp-registry/mcp-registry-node-loader.test.d.ts +1 -0
- package/dist/modules/mcp-registry/mcp-registry-node-loader.test.js +244 -0
- package/dist/modules/mcp-registry/mcp-registry-node-loader.test.js.map +1 -0
- package/dist/modules/mcp-registry/mcp-registry.module.d.ts +4 -0
- package/dist/modules/mcp-registry/mcp-registry.module.js +60 -0
- package/dist/modules/mcp-registry/mcp-registry.module.js.map +1 -0
- package/dist/modules/mcp-registry/node-description-transform.d.ts +8 -0
- package/dist/modules/mcp-registry/node-description-transform.js +133 -0
- package/dist/modules/mcp-registry/node-description-transform.js.map +1 -0
- package/dist/modules/mcp-registry/node-description-transform.test.d.ts +1 -0
- package/dist/modules/mcp-registry/node-description-transform.test.js +286 -0
- package/dist/modules/mcp-registry/node-description-transform.test.js.map +1 -0
- package/dist/modules/mcp-registry/registry/mcp-registry.service.d.ts +8 -0
- package/dist/modules/mcp-registry/registry/mcp-registry.service.js +31 -0
- package/dist/modules/mcp-registry/registry/mcp-registry.service.js.map +1 -0
- package/dist/modules/mcp-registry/registry/mcp-registry.service.test.d.ts +1 -0
- package/dist/modules/mcp-registry/registry/mcp-registry.service.test.js +41 -0
- package/dist/modules/mcp-registry/registry/mcp-registry.service.test.js.map +1 -0
- package/dist/modules/mcp-registry/registry/mcp-registry.types.d.ts +36 -0
- package/dist/modules/mcp-registry/registry/mcp-registry.types.js +3 -0
- package/dist/modules/mcp-registry/registry/mcp-registry.types.js.map +1 -0
- package/dist/modules/mcp-registry/registry/mock-servers.d.ts +3 -0
- package/dist/modules/mcp-registry/registry/mock-servers.js +80 -0
- package/dist/modules/mcp-registry/registry/mock-servers.js.map +1 -0
- package/dist/modules/otel/execution-level-tracer.d.ts +1 -1
- package/dist/modules/otel/execution-level-tracer.js +24 -9
- package/dist/modules/otel/execution-level-tracer.js.map +1 -1
- package/dist/modules/otel/execution-level-tracer.types.d.ts +9 -7
- package/dist/modules/otel/execution-level-tracer.types.js +14 -0
- package/dist/modules/otel/execution-level-tracer.types.js.map +1 -1
- package/dist/modules/quick-connect/quick-connect.config.d.ts +176 -0
- package/dist/modules/quick-connect/quick-connect.config.js +8 -0
- package/dist/modules/quick-connect/quick-connect.config.js.map +1 -1
- package/dist/modules/quick-connect/quick-connect.module.d.ts +15 -0
- package/dist/modules/redaction/executions/execution-redaction.service.d.ts +1 -3
- package/dist/modules/redaction/executions/execution-redaction.service.js +2 -6
- package/dist/modules/redaction/executions/execution-redaction.service.js.map +1 -1
- package/dist/modules/source-control.ee/source-control.controller.ee.d.ts +2 -2
- package/dist/modules/source-control.ee/source-control.service.ee.d.ts +1 -1
- package/dist/modules/sso-oidc/oidc.controller.ee.d.ts +3 -1
- package/dist/modules/sso-oidc/oidc.controller.ee.js +8 -1
- package/dist/modules/sso-oidc/oidc.controller.ee.js.map +1 -1
- package/dist/node-catalog/index.d.ts +1 -0
- package/dist/node-catalog/index.js +6 -0
- package/dist/node-catalog/index.js.map +1 -0
- package/dist/{modules/mcp/tools/workflow-builder/workflow-builder-tools.service.d.ts → node-catalog/node-catalog.service.d.ts} +9 -15
- package/dist/{modules/mcp/tools/workflow-builder/workflow-builder-tools.service.js → node-catalog/node-catalog.service.js} +38 -28
- package/dist/node-catalog/node-catalog.service.js.map +1 -0
- package/dist/node-execution/ephemeral-node-executor.d.ts +47 -0
- package/dist/node-execution/ephemeral-node-executor.js +289 -0
- package/dist/node-execution/ephemeral-node-executor.js.map +1 -0
- package/dist/node-execution/index.d.ts +2 -0
- package/dist/node-execution/index.js +8 -0
- package/dist/node-execution/index.js.map +1 -0
- package/dist/public-api/v1/handlers/audit/audit.handler.d.ts +5 -4
- package/dist/public-api/v1/handlers/audit/audit.handler.js +5 -9
- package/dist/public-api/v1/handlers/audit/audit.handler.js.map +1 -1
- package/dist/public-api/v1/handlers/community-packages/community-packages.handler.d.ts +20 -17
- package/dist/public-api/v1/handlers/community-packages/community-packages.handler.js +12 -39
- package/dist/public-api/v1/handlers/community-packages/community-packages.handler.js.map +1 -1
- package/dist/public-api/v1/handlers/credentials/credentials.handler.d.ts +12 -49
- package/dist/public-api/v1/handlers/credentials/credentials.handler.js +6 -5
- package/dist/public-api/v1/handlers/credentials/credentials.handler.js.map +1 -1
- package/dist/public-api/v1/handlers/data-tables/data-tables.columns.handler.d.ts +8 -19
- package/dist/public-api/v1/handlers/data-tables/data-tables.columns.handler.js +11 -11
- package/dist/public-api/v1/handlers/data-tables/data-tables.columns.handler.js.map +1 -1
- package/dist/public-api/v1/handlers/data-tables/data-tables.handler.d.ts +9 -17
- package/dist/public-api/v1/handlers/data-tables/data-tables.handler.js +19 -23
- package/dist/public-api/v1/handlers/data-tables/data-tables.handler.js.map +1 -1
- package/dist/public-api/v1/handlers/data-tables/data-tables.rows.handler.d.ts +9 -23
- package/dist/public-api/v1/handlers/data-tables/data-tables.rows.handler.js +17 -27
- package/dist/public-api/v1/handlers/data-tables/data-tables.rows.handler.js.map +1 -1
- package/dist/public-api/v1/handlers/discover/discover.handler.d.ts +11 -9
- package/dist/public-api/v1/handlers/discover/discover.handler.js +5 -3
- package/dist/public-api/v1/handlers/discover/discover.handler.js.map +1 -1
- package/dist/public-api/v1/handlers/executions/executions.handler.d.ts +12 -11
- package/dist/public-api/v1/handlers/executions/executions.handler.js +46 -80
- package/dist/public-api/v1/handlers/executions/executions.handler.js.map +1 -1
- package/dist/public-api/v1/handlers/folders/folders.handler.d.ts +12 -17
- package/dist/public-api/v1/handlers/folders/folders.handler.js +17 -20
- package/dist/public-api/v1/handlers/folders/folders.handler.js.map +1 -1
- package/dist/public-api/v1/handlers/insights/insights.handler.d.ts +5 -4
- package/dist/public-api/v1/handlers/insights/insights.handler.js +9 -5
- package/dist/public-api/v1/handlers/insights/insights.handler.js.map +1 -1
- package/dist/public-api/v1/handlers/projects/projects.handler.d.ts +28 -11
- package/dist/public-api/v1/handlers/projects/projects.handler.js +44 -75
- package/dist/public-api/v1/handlers/projects/projects.handler.js.map +1 -1
- package/dist/public-api/v1/handlers/source-control/source-control.handler.d.ts +5 -6
- package/dist/public-api/v1/handlers/source-control/source-control.handler.js +3 -2
- package/dist/public-api/v1/handlers/source-control/source-control.handler.js.map +1 -1
- package/dist/public-api/v1/handlers/tags/tags.handler.d.ts +9 -8
- package/dist/public-api/v1/handlers/tags/tags.handler.js +11 -8
- package/dist/public-api/v1/handlers/tags/tags.handler.js.map +1 -1
- package/dist/public-api/v1/handlers/users/users.handler.ee.d.ts +14 -11
- package/dist/public-api/v1/handlers/users/users.handler.ee.js +7 -8
- package/dist/public-api/v1/handlers/users/users.handler.ee.js.map +1 -1
- package/dist/public-api/v1/handlers/variables/variables.handler.d.ts +13 -7
- package/dist/public-api/v1/handlers/variables/variables.handler.js +5 -3
- package/dist/public-api/v1/handlers/variables/variables.handler.js.map +1 -1
- package/dist/public-api/v1/handlers/workflows/workflows.handler.d.ts +17 -49
- package/dist/public-api/v1/handlers/workflows/workflows.handler.js +27 -46
- package/dist/public-api/v1/handlers/workflows/workflows.handler.js.map +1 -1
- package/dist/public-api/v1/shared/handler.types.d.ts +7 -1
- package/dist/public-api/v1/shared/middlewares/global.middleware.d.ts +1 -2
- package/dist/public-api/v1/shared/middlewares/global.middleware.js +7 -6
- package/dist/public-api/v1/shared/middlewares/global.middleware.js.map +1 -1
- package/dist/scaling/constants.d.ts +2 -2
- package/dist/scaling/job-processor.js +2 -0
- package/dist/scaling/job-processor.js.map +1 -1
- package/dist/scaling/pubsub/pubsub.event-map.d.ts +9 -0
- package/dist/scaling/pubsub/pubsub.types.d.ts +3 -1
- package/dist/scaling/scaling.types.d.ts +1 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.js +2 -0
- package/dist/server.js.map +1 -1
- package/dist/services/frontend.service.js +7 -14
- package/dist/services/frontend.service.js.map +1 -1
- package/dist/services/import.service.d.ts +9 -3
- package/dist/services/import.service.js +72 -5
- package/dist/services/import.service.js.map +1 -1
- package/dist/services/proxy-token-manager.js.map +1 -0
- package/dist/services/workflow-statistics.service.js +1 -0
- package/dist/services/workflow-statistics.service.js.map +1 -1
- package/dist/task-runners/task-broker/task-broker.service.d.ts +2 -0
- package/dist/task-runners/task-broker/task-broker.service.js +13 -1
- package/dist/task-runners/task-broker/task-broker.service.js.map +1 -1
- package/dist/utils/ttl-map.d.ts +17 -0
- package/dist/utils/ttl-map.js +80 -0
- package/dist/utils/ttl-map.js.map +1 -0
- package/dist/webhooks/test-webhooks.d.ts +3 -1
- package/dist/webhooks/test-webhooks.js +11 -3
- package/dist/webhooks/test-webhooks.js.map +1 -1
- package/dist/workflow-execute-additional-data.d.ts +2 -1
- package/dist/workflow-execute-additional-data.js +34 -0
- package/dist/workflow-execute-additional-data.js.map +1 -1
- package/dist/workflow-helpers.d.ts +1 -0
- package/dist/workflow-helpers.js +15 -0
- package/dist/workflow-helpers.js.map +1 -1
- package/dist/workflow-runner.js +2 -0
- package/dist/workflow-runner.js.map +1 -1
- package/dist/workflows/workflow-creation.service.js +1 -0
- package/dist/workflows/workflow-creation.service.js.map +1 -1
- package/dist/workflows/workflow.service.js +4 -0
- package/dist/workflows/workflow.service.js.map +1 -1
- package/package.json +40 -25
- package/dist/instance-settings-loader/loaders/sso.instance-settings-loader.js +0 -203
- package/dist/instance-settings-loader/loaders/sso.instance-settings-loader.js.map +0 -1
- package/dist/modules/instance-ai/proxy-token-manager.js.map +0 -1
- package/dist/modules/mcp/tools/workflow-builder/workflow-builder-tools.service.js.map +0 -1
- /package/dist/{modules/instance-ai → services}/proxy-token-manager.d.ts +0 -0
- /package/dist/{modules/instance-ai → services}/proxy-token-manager.js +0 -0
|
@@ -47,15 +47,18 @@ const api_types_1 = require("@n8n/api-types");
|
|
|
47
47
|
const backend_common_1 = require("@n8n/backend-common");
|
|
48
48
|
const config_1 = require("@n8n/config");
|
|
49
49
|
const n8n_core_1 = require("n8n-core");
|
|
50
|
-
const
|
|
50
|
+
const ssrf_protection_service_1 = require("../../services/ssrf/ssrf-protection.service");
|
|
51
51
|
const db_1 = require("@n8n/db");
|
|
52
52
|
const di_1 = require("@n8n/di");
|
|
53
|
+
const permissions_1 = require("@n8n/permissions");
|
|
53
54
|
const url_service_1 = require("../../services/url.service");
|
|
54
55
|
const instance_ai_1 = require("@n8n/instance-ai");
|
|
55
56
|
const workflow_sdk_1 = require("@n8n/workflow-sdk");
|
|
56
57
|
const nanoid_1 = require("nanoid");
|
|
58
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
57
59
|
const uuid_1 = require("uuid");
|
|
58
|
-
const
|
|
60
|
+
const constants_1 = require("../../constants");
|
|
61
|
+
const event_service_1 = require("../../events/event.service");
|
|
59
62
|
const source_control_preferences_service_ee_1 = require("../../modules/source-control.ee/source-control-preferences.service.ee");
|
|
60
63
|
const ai_service_1 = require("../../services/ai.service");
|
|
61
64
|
const push_1 = require("../../push");
|
|
@@ -69,16 +72,80 @@ const typeorm_composite_store_1 = require("./storage/typeorm-composite-store");
|
|
|
69
72
|
const db_snapshot_storage_1 = require("./storage/db-snapshot-storage");
|
|
70
73
|
const db_iteration_log_storage_1 = require("./storage/db-iteration-log-storage");
|
|
71
74
|
const compaction_service_1 = require("./compaction.service");
|
|
72
|
-
const proxy_token_manager_1 = require("
|
|
75
|
+
const proxy_token_manager_1 = require("../../services/proxy-token-manager");
|
|
73
76
|
const instance_ai_thread_repository_1 = require("./repositories/instance-ai-thread.repository");
|
|
74
77
|
const trace_replay_state_1 = require("./trace-replay-state");
|
|
78
|
+
const liveness_1 = require("./liveness");
|
|
75
79
|
function getErrorMessage(error) {
|
|
76
80
|
return error instanceof Error ? error.message : String(error);
|
|
77
81
|
}
|
|
82
|
+
const ORCHESTRATOR_AGENT_ID = 'agent-001';
|
|
83
|
+
function getUserFacingErrorMessage(error) {
|
|
84
|
+
if (error instanceof n8n_workflow_1.UserError) {
|
|
85
|
+
return error.message;
|
|
86
|
+
}
|
|
87
|
+
if (error instanceof n8n_workflow_1.OperationalError) {
|
|
88
|
+
return 'I hit an operational error before I could finish that response. Please try again.';
|
|
89
|
+
}
|
|
90
|
+
if (error instanceof n8n_workflow_1.UnexpectedError) {
|
|
91
|
+
return 'Something went wrong before I could finish that response. Please try again.';
|
|
92
|
+
}
|
|
93
|
+
return 'Something went wrong before I could finish that response. Please try again.';
|
|
94
|
+
}
|
|
95
|
+
function getBackgroundOutcomeResponseId(outcome) {
|
|
96
|
+
return `background-outcome:${outcome.id}`;
|
|
97
|
+
}
|
|
98
|
+
function createTerminalOutcomeAgentTree(outcome, responseId) {
|
|
99
|
+
return {
|
|
100
|
+
agentId: ORCHESTRATOR_AGENT_ID,
|
|
101
|
+
role: 'orchestrator',
|
|
102
|
+
status: outcome.status === 'cancelled'
|
|
103
|
+
? 'cancelled'
|
|
104
|
+
: outcome.status === 'failed'
|
|
105
|
+
? 'error'
|
|
106
|
+
: 'completed',
|
|
107
|
+
textContent: outcome.userFacingMessage,
|
|
108
|
+
reasoning: '',
|
|
109
|
+
toolCalls: [],
|
|
110
|
+
children: [],
|
|
111
|
+
timeline: [{ type: 'text', content: outcome.userFacingMessage, responseId }],
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function appendTerminalOutcomeToAgentTree(tree, outcome, responseId) {
|
|
115
|
+
const text = outcome.userFacingMessage.trim();
|
|
116
|
+
if (!text)
|
|
117
|
+
return { tree, appended: false };
|
|
118
|
+
const alreadyInTimeline = tree.timeline.some((entry) => entry.type === 'text' && entry.responseId === responseId);
|
|
119
|
+
if (alreadyInTimeline) {
|
|
120
|
+
return { tree, appended: false };
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
appended: true,
|
|
124
|
+
tree: {
|
|
125
|
+
...tree,
|
|
126
|
+
textContent: tree.textContent ? `${tree.textContent}\n\n${outcome.userFacingMessage}` : text,
|
|
127
|
+
timeline: [
|
|
128
|
+
...tree.timeline,
|
|
129
|
+
{ type: 'text', content: outcome.userFacingMessage, responseId },
|
|
130
|
+
],
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
78
134
|
function createInertAbortSignal() {
|
|
79
135
|
return new AbortController().signal;
|
|
80
136
|
}
|
|
81
|
-
|
|
137
|
+
function getAbortReason(signal) {
|
|
138
|
+
const reason = signal.reason;
|
|
139
|
+
if (typeof reason === 'object' &&
|
|
140
|
+
reason !== null &&
|
|
141
|
+
'name' in reason &&
|
|
142
|
+
reason.name === 'AbortError') {
|
|
143
|
+
return 'user_cancelled';
|
|
144
|
+
}
|
|
145
|
+
if (reason instanceof Error)
|
|
146
|
+
return reason.message;
|
|
147
|
+
return typeof reason === 'string' ? reason : 'user_cancelled';
|
|
148
|
+
}
|
|
82
149
|
const INSTANCE_AI_FEEDBACK_NAMESPACE = 'c5be4c87-5b6e-49ed-afe1-9c5c1f99a5c0';
|
|
83
150
|
const MAX_CONCURRENT_BACKGROUND_TASKS_PER_THREAD = 5;
|
|
84
151
|
function estimateTokens(text) {
|
|
@@ -176,7 +243,7 @@ function toConfirmationData(request) {
|
|
|
176
243
|
}
|
|
177
244
|
}
|
|
178
245
|
let InstanceAiService = class InstanceAiService {
|
|
179
|
-
constructor(logger, globalConfig, adapterService, eventBus, settingsService, compositeStore, compactionService, aiService, push, threadRepo, urlService, dbSnapshotStorage, dbIterationLogStorage, sourceControlPreferencesService, telemetry, userRepository, aiBuilderTemporaryWorkflowRepository, errorReporter) {
|
|
246
|
+
constructor(logger, globalConfig, adapterService, eventBus, settingsService, compositeStore, compactionService, aiService, push, threadRepo, urlService, dbSnapshotStorage, dbIterationLogStorage, sourceControlPreferencesService, telemetry, userRepository, aiBuilderTemporaryWorkflowRepository, errorReporter, ssrfProtectionConfig, ssrfProtectionService, eventService) {
|
|
180
247
|
this.adapterService = adapterService;
|
|
181
248
|
this.eventBus = eventBus;
|
|
182
249
|
this.settingsService = settingsService;
|
|
@@ -193,7 +260,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
193
260
|
this.userRepository = userRepository;
|
|
194
261
|
this.aiBuilderTemporaryWorkflowRepository = aiBuilderTemporaryWorkflowRepository;
|
|
195
262
|
this.errorReporter = errorReporter;
|
|
196
|
-
this.
|
|
263
|
+
this.eventService = eventService;
|
|
197
264
|
this.runState = new instance_ai_1.RunStateRegistry();
|
|
198
265
|
this.backgroundTasks = new instance_ai_1.BackgroundTaskManager(MAX_CONCURRENT_BACKGROUND_TASKS_PER_THREAD);
|
|
199
266
|
this.traceContextsByRunId = new Map();
|
|
@@ -203,35 +270,42 @@ let InstanceAiService = class InstanceAiService {
|
|
|
203
270
|
this.threadPushRef = new Map();
|
|
204
271
|
this.schedulerLocks = new Map();
|
|
205
272
|
this.pendingCheckpointReentries = new Map();
|
|
273
|
+
this.pendingTerminalOutcomes = new Map();
|
|
206
274
|
this.creditedThreads = new Set();
|
|
207
275
|
this.traceReplay = new trace_replay_state_1.TraceReplayState();
|
|
208
276
|
this.logger = logger.scoped('instance-ai');
|
|
209
277
|
this.instanceAiConfig = globalConfig.instanceAi;
|
|
278
|
+
const livenessPolicyConfig = (0, instance_ai_1.createInstanceAiLivenessPolicyConfig)({
|
|
279
|
+
confirmationTimeoutMs: this.instanceAiConfig.confirmationTimeout,
|
|
280
|
+
});
|
|
281
|
+
this.liveness = new liveness_1.InstanceAiLivenessService({
|
|
282
|
+
policy: new instance_ai_1.InstanceAiLivenessPolicy(livenessPolicyConfig),
|
|
283
|
+
backgroundTaskIdleTimeoutMs: livenessPolicyConfig.backgroundTaskIdleTimeoutMs,
|
|
284
|
+
runState: this.runState,
|
|
285
|
+
backgroundTasks: this.backgroundTasks,
|
|
286
|
+
eventBus: this.eventBus,
|
|
287
|
+
logger: this.logger,
|
|
288
|
+
finalizeCancelledSuspendedRun: (suspended, reason) => {
|
|
289
|
+
void this.finalizeCancelledSuspendedRun(suspended, reason);
|
|
290
|
+
},
|
|
291
|
+
});
|
|
210
292
|
this.builderSandboxSessions = new instance_ai_1.BuilderSandboxSessionRegistry(this.instanceAiConfig.builderSandboxTtlMs);
|
|
211
293
|
this.defaultTimeZone = globalConfig.generic.timezone;
|
|
212
|
-
const editorBaseUrl = globalConfig.editorBaseUrl || `http://localhost:${globalConfig.port}`;
|
|
213
294
|
const restEndpoint = globalConfig.endpoints.rest;
|
|
214
|
-
this.oauth2CallbackUrl = `${
|
|
295
|
+
this.oauth2CallbackUrl = `${this.urlService.getInstanceBaseUrl()}/${restEndpoint}/oauth2-credential/callback`;
|
|
215
296
|
this.webhookBaseUrl = `${this.urlService.getWebhookBaseUrl()}${globalConfig.endpoints.webhook}`;
|
|
216
|
-
this.
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
for (const threadId of suspendedThreadIds) {
|
|
225
|
-
this.logger.debug('Auto-rejecting timed-out suspended run', { threadId });
|
|
226
|
-
this.cancelRun(threadId);
|
|
227
|
-
}
|
|
228
|
-
for (const reqId of confirmationRequestIds) {
|
|
229
|
-
this.logger.debug('Auto-rejecting timed-out sub-agent confirmation', {
|
|
230
|
-
requestId: reqId,
|
|
297
|
+
this.formBaseUrl = `${this.urlService.getWebhookBaseUrl()}${globalConfig.endpoints.form}`;
|
|
298
|
+
this.mcpClientManager = new instance_ai_1.McpClientManager(ssrfProtectionConfig.enabled ? ssrfProtectionService : undefined);
|
|
299
|
+
this.eventService.on('instance-ai-settings-updated', ({ mcpSettingsChanged }) => {
|
|
300
|
+
if (!mcpSettingsChanged)
|
|
301
|
+
return;
|
|
302
|
+
this.mcpClientManager.disconnect().catch((error) => {
|
|
303
|
+
this.logger.warn('Failed to disconnect MCP clients after settings change', {
|
|
304
|
+
error: getErrorMessage(error),
|
|
231
305
|
});
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
this.liveness.start();
|
|
235
309
|
}
|
|
236
310
|
getSandboxConfigFromEnv() {
|
|
237
311
|
const { sandboxEnabled, sandboxProvider, daytonaApiUrl, daytonaApiKey, n8nSandboxServiceUrl, n8nSandboxServiceApiKey, sandboxImage, sandboxTimeout, } = this.instanceAiConfig;
|
|
@@ -253,7 +327,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
253
327
|
daytonaApiUrl: daytonaApiUrl || undefined,
|
|
254
328
|
daytonaApiKey: daytonaApiKey || undefined,
|
|
255
329
|
image: sandboxImage || undefined,
|
|
256
|
-
n8nVersion:
|
|
330
|
+
n8nVersion: constants_1.N8N_VERSION || undefined,
|
|
257
331
|
timeout: sandboxTimeout,
|
|
258
332
|
};
|
|
259
333
|
}
|
|
@@ -382,7 +456,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
382
456
|
for (const [k, v] of Object.entries(auth)) {
|
|
383
457
|
headers.set(k, v);
|
|
384
458
|
}
|
|
385
|
-
for (const [k, v] of Object.entries((0, api_types_1.buildProxyHeaders)({ feature: 'instance-ai', n8nVersion:
|
|
459
|
+
for (const [k, v] of Object.entries((0, api_types_1.buildProxyHeaders)({ feature: 'instance-ai', n8nVersion: constants_1.N8N_VERSION }))) {
|
|
386
460
|
headers.set(k, v);
|
|
387
461
|
}
|
|
388
462
|
return await globalThis.fetch(input, { ...init, headers });
|
|
@@ -682,6 +756,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
682
756
|
}
|
|
683
757
|
}
|
|
684
758
|
startRun(user, threadId, message, researchMode, attachments, timeZone, pushRef) {
|
|
759
|
+
this.liveness.clearThreadState(threadId);
|
|
685
760
|
const { runId, abortController, messageGroupId } = this.runState.startRun({
|
|
686
761
|
threadId,
|
|
687
762
|
user,
|
|
@@ -708,7 +783,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
708
783
|
getActiveRunId(threadId) {
|
|
709
784
|
return this.runState.getActiveRunId(threadId);
|
|
710
785
|
}
|
|
711
|
-
cancelRun(threadId) {
|
|
786
|
+
cancelRun(threadId, reason = 'user_cancelled') {
|
|
712
787
|
const cancelledTasks = this.backgroundTasks.cancelThread(threadId);
|
|
713
788
|
const user = this.runState.getThreadUser(threadId);
|
|
714
789
|
for (const task of cancelledTasks) {
|
|
@@ -717,9 +792,15 @@ let InstanceAiService = class InstanceAiService {
|
|
|
717
792
|
type: 'agent-completed',
|
|
718
793
|
runId: task.runId,
|
|
719
794
|
agentId: task.agentId,
|
|
720
|
-
payload: {
|
|
795
|
+
payload: {
|
|
796
|
+
role: task.role,
|
|
797
|
+
result: '',
|
|
798
|
+
error: reason === liveness_1.INSTANCE_AI_RUN_TIMEOUT_REASON ? 'Timed out' : 'Cancelled by user',
|
|
799
|
+
},
|
|
800
|
+
});
|
|
801
|
+
void this.recordBackgroundTerminalOutcome(task).finally(() => {
|
|
802
|
+
void this.saveAgentTreeSnapshot(threadId, task.runId, this.dbSnapshotStorage, true, task.messageGroupId);
|
|
721
803
|
});
|
|
722
|
-
void this.saveAgentTreeSnapshot(threadId, task.runId, this.dbSnapshotStorage, true, task.messageGroupId);
|
|
723
804
|
if (user) {
|
|
724
805
|
void this.handlePlannedTaskSettlement(user, task, 'cancelled');
|
|
725
806
|
}
|
|
@@ -727,12 +808,16 @@ let InstanceAiService = class InstanceAiService {
|
|
|
727
808
|
void this.cancelAwaitingApprovalPlan(threadId);
|
|
728
809
|
const { active, suspended } = this.runState.cancelThread(threadId);
|
|
729
810
|
if (active) {
|
|
811
|
+
if (reason === liveness_1.INSTANCE_AI_RUN_TIMEOUT_REASON)
|
|
812
|
+
this.liveness.markRunTimedOut(active.runId);
|
|
730
813
|
active.abortController.abort();
|
|
731
814
|
return;
|
|
732
815
|
}
|
|
733
816
|
if (suspended) {
|
|
817
|
+
if (reason === liveness_1.INSTANCE_AI_RUN_TIMEOUT_REASON)
|
|
818
|
+
this.liveness.markRunTimedOut(suspended.runId);
|
|
734
819
|
suspended.abortController.abort();
|
|
735
|
-
void this.finalizeCancelledSuspendedRun(suspended);
|
|
820
|
+
void this.finalizeCancelledSuspendedRun(suspended, reason);
|
|
736
821
|
}
|
|
737
822
|
}
|
|
738
823
|
sendCorrectionToTask(threadId, taskId, correction) {
|
|
@@ -749,12 +834,34 @@ let InstanceAiService = class InstanceAiService {
|
|
|
749
834
|
agentId: task.agentId,
|
|
750
835
|
payload: { role: task.role, result: '', error: 'Cancelled by user' },
|
|
751
836
|
});
|
|
752
|
-
void this.
|
|
837
|
+
void this.recordBackgroundTerminalOutcome(task).finally(() => {
|
|
838
|
+
void this.saveAgentTreeSnapshot(threadId, task.runId, this.dbSnapshotStorage, true, task.messageGroupId);
|
|
839
|
+
});
|
|
753
840
|
const user = this.runState.getThreadUser(threadId);
|
|
754
841
|
if (user) {
|
|
755
842
|
void this.handlePlannedTaskSettlement(user, task, 'cancelled');
|
|
756
843
|
}
|
|
757
844
|
}
|
|
845
|
+
async revalidateActiveUser(userId) {
|
|
846
|
+
try {
|
|
847
|
+
const user = await this.userRepository.findOne({
|
|
848
|
+
where: { id: userId },
|
|
849
|
+
relations: ['role'],
|
|
850
|
+
});
|
|
851
|
+
if (!user || user.disabled)
|
|
852
|
+
return null;
|
|
853
|
+
if (!(0, permissions_1.hasGlobalScope)(user, 'instanceAi:message'))
|
|
854
|
+
return null;
|
|
855
|
+
return user;
|
|
856
|
+
}
|
|
857
|
+
catch (error) {
|
|
858
|
+
this.logger.warn('Failed to revalidate user', {
|
|
859
|
+
userId,
|
|
860
|
+
error: getErrorMessage(error),
|
|
861
|
+
});
|
|
862
|
+
return null;
|
|
863
|
+
}
|
|
864
|
+
}
|
|
758
865
|
cancelAllBackgroundTasks() {
|
|
759
866
|
const cancelled = this.backgroundTasks.cancelAll();
|
|
760
867
|
for (const task of cancelled) {
|
|
@@ -762,6 +869,111 @@ let InstanceAiService = class InstanceAiService {
|
|
|
762
869
|
}
|
|
763
870
|
return cancelled.length;
|
|
764
871
|
}
|
|
872
|
+
async startStuckBackgroundTaskForTest(user, threadId) {
|
|
873
|
+
const messageId = `msg_${(0, nanoid_1.nanoid)()}`;
|
|
874
|
+
const messageText = 'I started a background workflow-builder task.';
|
|
875
|
+
const { runId, messageGroupId } = this.runState.startRun({ threadId, user });
|
|
876
|
+
if (!messageGroupId) {
|
|
877
|
+
throw new n8n_workflow_1.UnexpectedError('Failed to create message group for timeout simulation');
|
|
878
|
+
}
|
|
879
|
+
const taskId = `task_${(0, nanoid_1.nanoid)()}`;
|
|
880
|
+
const agentId = `agent_${(0, nanoid_1.nanoid)()}`;
|
|
881
|
+
this.eventBus.publish(threadId, {
|
|
882
|
+
type: 'run-start',
|
|
883
|
+
runId,
|
|
884
|
+
agentId: ORCHESTRATOR_AGENT_ID,
|
|
885
|
+
userId: user.id,
|
|
886
|
+
payload: { messageId, messageGroupId },
|
|
887
|
+
});
|
|
888
|
+
this.eventBus.publish(threadId, {
|
|
889
|
+
type: 'text-delta',
|
|
890
|
+
runId,
|
|
891
|
+
agentId: ORCHESTRATOR_AGENT_ID,
|
|
892
|
+
responseId: `test-background-start:${runId}`,
|
|
893
|
+
payload: { text: messageText },
|
|
894
|
+
});
|
|
895
|
+
this.eventBus.publish(threadId, {
|
|
896
|
+
type: 'agent-spawned',
|
|
897
|
+
runId,
|
|
898
|
+
agentId,
|
|
899
|
+
payload: {
|
|
900
|
+
parentId: ORCHESTRATOR_AGENT_ID,
|
|
901
|
+
role: 'workflow-builder',
|
|
902
|
+
tools: [],
|
|
903
|
+
taskId,
|
|
904
|
+
kind: 'builder',
|
|
905
|
+
title: 'Building workflow',
|
|
906
|
+
subtitle: 'Timeout simulation',
|
|
907
|
+
goal: 'Simulate a stuck background task timeout',
|
|
908
|
+
},
|
|
909
|
+
});
|
|
910
|
+
const memoryStorage = this.compositeStore.stores.memory;
|
|
911
|
+
await memoryStorage.saveMessages({
|
|
912
|
+
messages: [
|
|
913
|
+
{
|
|
914
|
+
id: messageId,
|
|
915
|
+
threadId,
|
|
916
|
+
resourceId: user.id,
|
|
917
|
+
role: 'assistant',
|
|
918
|
+
content: {
|
|
919
|
+
format: 2,
|
|
920
|
+
parts: [{ type: 'text', text: messageText }],
|
|
921
|
+
content: messageText,
|
|
922
|
+
},
|
|
923
|
+
createdAt: new Date(),
|
|
924
|
+
},
|
|
925
|
+
],
|
|
926
|
+
});
|
|
927
|
+
const outcome = this.backgroundTasks.spawn({
|
|
928
|
+
taskId,
|
|
929
|
+
threadId,
|
|
930
|
+
runId,
|
|
931
|
+
role: 'workflow-builder',
|
|
932
|
+
agentId,
|
|
933
|
+
messageGroupId,
|
|
934
|
+
run: async (signal) => await new Promise((resolve) => {
|
|
935
|
+
signal.addEventListener('abort', () => resolve('aborted'), { once: true });
|
|
936
|
+
}),
|
|
937
|
+
onFailed: (task) => {
|
|
938
|
+
this.eventBus.publish(threadId, {
|
|
939
|
+
type: 'agent-completed',
|
|
940
|
+
runId,
|
|
941
|
+
agentId,
|
|
942
|
+
payload: {
|
|
943
|
+
role: task.role,
|
|
944
|
+
result: '',
|
|
945
|
+
error: task.error ?? 'Unknown error',
|
|
946
|
+
},
|
|
947
|
+
});
|
|
948
|
+
},
|
|
949
|
+
onSettled: async (task) => {
|
|
950
|
+
await this.recordBackgroundTerminalOutcome(task);
|
|
951
|
+
await this.saveAgentTreeSnapshot(threadId, runId, this.dbSnapshotStorage, true, messageGroupId);
|
|
952
|
+
},
|
|
953
|
+
});
|
|
954
|
+
if (outcome.status !== 'started') {
|
|
955
|
+
throw new n8n_workflow_1.UnexpectedError('Failed to start stuck background task simulation');
|
|
956
|
+
}
|
|
957
|
+
this.runState.clearActiveRun(threadId);
|
|
958
|
+
this.eventBus.publish(threadId, {
|
|
959
|
+
type: 'run-finish',
|
|
960
|
+
runId,
|
|
961
|
+
agentId: ORCHESTRATOR_AGENT_ID,
|
|
962
|
+
userId: user.id,
|
|
963
|
+
payload: { status: 'completed' },
|
|
964
|
+
});
|
|
965
|
+
return {
|
|
966
|
+
threadId,
|
|
967
|
+
runId,
|
|
968
|
+
messageGroupId,
|
|
969
|
+
taskId,
|
|
970
|
+
agentId,
|
|
971
|
+
timeoutAt: outcome.task.lastActivityAt + this.liveness.backgroundTaskIdleTimeoutMs + 1,
|
|
972
|
+
};
|
|
973
|
+
}
|
|
974
|
+
async runLivenessSweepForTest(now) {
|
|
975
|
+
await this.liveness.sweepTimedOutWork(now);
|
|
976
|
+
}
|
|
765
977
|
loadTraceEvents(slug, events) {
|
|
766
978
|
this.traceReplay.loadEvents(slug, events);
|
|
767
979
|
}
|
|
@@ -780,6 +992,9 @@ let InstanceAiService = class InstanceAiService {
|
|
|
780
992
|
generatePairingToken(userId) {
|
|
781
993
|
return this.gatewayRegistry.generatePairingToken(userId);
|
|
782
994
|
}
|
|
995
|
+
getGatewayApiKeyExpiresAt(userId, key) {
|
|
996
|
+
return this.gatewayRegistry.getApiKeyExpiresAt(userId, key);
|
|
997
|
+
}
|
|
783
998
|
getPairingToken(userId) {
|
|
784
999
|
return this.gatewayRegistry.getPairingToken(userId);
|
|
785
1000
|
}
|
|
@@ -852,6 +1067,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
852
1067
|
});
|
|
853
1068
|
this.creditedThreads.delete(threadId);
|
|
854
1069
|
this.schedulerLocks.delete(threadId);
|
|
1070
|
+
this.liveness.clearThreadState(threadId);
|
|
855
1071
|
this.domainAccessTrackersByThread.delete(threadId);
|
|
856
1072
|
this.threadPushRef.delete(threadId);
|
|
857
1073
|
this.deleteTraceContextsForThread(threadId);
|
|
@@ -861,10 +1077,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
861
1077
|
this.eventBus.clearThread(threadId);
|
|
862
1078
|
}
|
|
863
1079
|
async shutdown() {
|
|
864
|
-
|
|
865
|
-
clearInterval(this.confirmationTimeoutInterval);
|
|
866
|
-
this.confirmationTimeoutInterval = undefined;
|
|
867
|
-
}
|
|
1080
|
+
this.liveness.shutdown();
|
|
868
1081
|
const { activeRuns, suspendedRuns } = this.runState.shutdown();
|
|
869
1082
|
for (const run of activeRuns) {
|
|
870
1083
|
run.abortController.abort();
|
|
@@ -990,6 +1203,290 @@ let InstanceAiService = class InstanceAiService {
|
|
|
990
1203
|
const plannedTaskService = new instance_ai_1.PlannedTaskCoordinator(plannedTaskStorage);
|
|
991
1204
|
return { memory, taskStorage, plannedTaskService };
|
|
992
1205
|
}
|
|
1206
|
+
evaluateTerminalResponse(threadId, runId, status, options = {}) {
|
|
1207
|
+
const guard = new instance_ai_1.InstanceAiTerminalResponseGuard({
|
|
1208
|
+
runId,
|
|
1209
|
+
rootAgentId: ORCHESTRATOR_AGENT_ID,
|
|
1210
|
+
messageGroupId: options.messageGroupId,
|
|
1211
|
+
correlationId: options.correlationId,
|
|
1212
|
+
});
|
|
1213
|
+
const decision = guard.evaluateTerminal(this.getTerminalGuardEvents(threadId, runId, options.messageGroupId), status, {
|
|
1214
|
+
workSummary: options.workSummary,
|
|
1215
|
+
errorMessage: options.errorMessage,
|
|
1216
|
+
});
|
|
1217
|
+
this.handleTerminalResponseDecision(threadId, runId, decision, options.messageGroupId);
|
|
1218
|
+
return decision;
|
|
1219
|
+
}
|
|
1220
|
+
evaluateWaitingResponse(threadId, runId, confirmationEvent, options = {}) {
|
|
1221
|
+
const guard = new instance_ai_1.InstanceAiTerminalResponseGuard({
|
|
1222
|
+
runId,
|
|
1223
|
+
rootAgentId: ORCHESTRATOR_AGENT_ID,
|
|
1224
|
+
messageGroupId: options.messageGroupId,
|
|
1225
|
+
correlationId: options.correlationId,
|
|
1226
|
+
});
|
|
1227
|
+
const decision = guard.evaluateWaiting(this.getTerminalGuardEvents(threadId, runId, options.messageGroupId), confirmationEvent);
|
|
1228
|
+
this.handleTerminalResponseDecision(threadId, runId, decision, options.messageGroupId);
|
|
1229
|
+
return decision;
|
|
1230
|
+
}
|
|
1231
|
+
getTerminalGuardEvents(threadId, runId, messageGroupId) {
|
|
1232
|
+
if (!messageGroupId)
|
|
1233
|
+
return this.eventBus.getEventsForRun(threadId, runId);
|
|
1234
|
+
const groupRunIds = this.getRunIdsForMessageGroup(messageGroupId);
|
|
1235
|
+
return groupRunIds.length > 0
|
|
1236
|
+
? this.eventBus.getEventsForRuns(threadId, groupRunIds)
|
|
1237
|
+
: this.eventBus.getEventsForRun(threadId, runId);
|
|
1238
|
+
}
|
|
1239
|
+
handleTerminalResponseDecision(threadId, runId, decision, messageGroupId) {
|
|
1240
|
+
this.telemetry.track('instance_ai_terminal_response_decision', {
|
|
1241
|
+
thread_id: threadId,
|
|
1242
|
+
run_id: runId,
|
|
1243
|
+
message_group_id: messageGroupId,
|
|
1244
|
+
source: 'terminal_guard',
|
|
1245
|
+
status: decision.status,
|
|
1246
|
+
action: decision.action,
|
|
1247
|
+
reason: decision.reason,
|
|
1248
|
+
visibility_source: decision.visibilitySource,
|
|
1249
|
+
});
|
|
1250
|
+
if (decision.reason === 'completed-after-error') {
|
|
1251
|
+
this.logger.warn('completed_after_error_event', {
|
|
1252
|
+
threadId,
|
|
1253
|
+
runId,
|
|
1254
|
+
messageGroupId,
|
|
1255
|
+
});
|
|
1256
|
+
}
|
|
1257
|
+
if (decision.reason === 'confirmation-invalid') {
|
|
1258
|
+
this.logger.warn('invalid_confirmation_payload', {
|
|
1259
|
+
threadId,
|
|
1260
|
+
runId,
|
|
1261
|
+
messageGroupId,
|
|
1262
|
+
});
|
|
1263
|
+
}
|
|
1264
|
+
if (decision.action === 'emit' && decision.event) {
|
|
1265
|
+
this.eventBus.publish(threadId, decision.event);
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
createTerminalOutcomeStorage() {
|
|
1269
|
+
this.terminalOutcomeStorage ??= new instance_ai_1.TerminalOutcomeStorage((0, instance_ai_1.createMemory)(this.createMemoryConfig()));
|
|
1270
|
+
return this.terminalOutcomeStorage;
|
|
1271
|
+
}
|
|
1272
|
+
async finishInvalidConfirmationRun(args) {
|
|
1273
|
+
this.runState.cancelThread(args.threadId);
|
|
1274
|
+
args.abortController.abort();
|
|
1275
|
+
await this.finalizeRunTracing(args.runId, args.tracing, {
|
|
1276
|
+
status: 'error',
|
|
1277
|
+
reason: 'invalid_confirmation_payload',
|
|
1278
|
+
});
|
|
1279
|
+
this.publishRunFinish(args.threadId, args.runId, 'errored', 'I need your input to continue, but I could not display the prompt. Please try again.');
|
|
1280
|
+
await this.saveAgentTreeSnapshot(args.threadId, args.runId, args.snapshotStorage);
|
|
1281
|
+
return {
|
|
1282
|
+
status: 'error',
|
|
1283
|
+
reason: 'invalid_confirmation_payload',
|
|
1284
|
+
metadata: { completion_source: 'orchestrator' },
|
|
1285
|
+
};
|
|
1286
|
+
}
|
|
1287
|
+
buildBackgroundTerminalOutcome(task) {
|
|
1288
|
+
const status = task.status === 'failed' ? 'failed' : task.status === 'cancelled' ? 'cancelled' : 'completed';
|
|
1289
|
+
const userFacingMessage = status === 'completed'
|
|
1290
|
+
? `The background ${task.role} task finished.`
|
|
1291
|
+
: status === 'cancelled'
|
|
1292
|
+
? `The background ${task.role} task was cancelled.`
|
|
1293
|
+
: `The background ${task.role} task failed before I could complete that part.`;
|
|
1294
|
+
return {
|
|
1295
|
+
id: `${task.messageGroupId ?? task.runId}:${task.taskId}:${status}`,
|
|
1296
|
+
threadId: task.threadId,
|
|
1297
|
+
runId: task.runId,
|
|
1298
|
+
messageGroupId: task.messageGroupId,
|
|
1299
|
+
correlationId: task.messageGroupId,
|
|
1300
|
+
taskId: task.taskId,
|
|
1301
|
+
agentId: task.agentId,
|
|
1302
|
+
status,
|
|
1303
|
+
userFacingMessage,
|
|
1304
|
+
createdAt: new Date().toISOString(),
|
|
1305
|
+
};
|
|
1306
|
+
}
|
|
1307
|
+
async replayUndeliveredTerminalOutcomes(threadId, options = {}) {
|
|
1308
|
+
const storage = this.createTerminalOutcomeStorage();
|
|
1309
|
+
const persistedOutcomes = await storage.getUndelivered(threadId).catch((error) => {
|
|
1310
|
+
this.logger.warn('Failed to load undelivered Instance AI terminal outcomes', {
|
|
1311
|
+
threadId,
|
|
1312
|
+
error: getErrorMessage(error),
|
|
1313
|
+
});
|
|
1314
|
+
return [];
|
|
1315
|
+
});
|
|
1316
|
+
const inMemoryOutcomes = [...this.pendingTerminalOutcomes.values()].filter((outcome) => outcome.threadId === threadId);
|
|
1317
|
+
const outcomes = new Map();
|
|
1318
|
+
for (const outcome of [...persistedOutcomes, ...inMemoryOutcomes]) {
|
|
1319
|
+
outcomes.set(outcome.id, outcome);
|
|
1320
|
+
}
|
|
1321
|
+
const persistedOutcomeIds = new Set(persistedOutcomes.map((outcome) => outcome.id));
|
|
1322
|
+
const delivery = options.delivery ?? 'snapshot';
|
|
1323
|
+
for (const outcome of outcomes.values()) {
|
|
1324
|
+
const responseId = getBackgroundOutcomeResponseId(outcome);
|
|
1325
|
+
let snapshotDelivered = false;
|
|
1326
|
+
try {
|
|
1327
|
+
snapshotDelivered = await this.persistTerminalOutcomeLineToSnapshot(outcome, responseId);
|
|
1328
|
+
}
|
|
1329
|
+
catch (error) {
|
|
1330
|
+
this.logger.warn('Failed to replay Instance AI terminal outcome', {
|
|
1331
|
+
threadId,
|
|
1332
|
+
runId: outcome.runId,
|
|
1333
|
+
taskId: outcome.taskId,
|
|
1334
|
+
error: getErrorMessage(error),
|
|
1335
|
+
});
|
|
1336
|
+
if (delivery === 'event') {
|
|
1337
|
+
const published = this.publishTerminalOutcomeLine(outcome, responseId);
|
|
1338
|
+
this.telemetry.track('instance_ai_terminal_response_decision', {
|
|
1339
|
+
thread_id: threadId,
|
|
1340
|
+
run_id: outcome.runId,
|
|
1341
|
+
message_group_id: outcome.messageGroupId,
|
|
1342
|
+
task_id: outcome.taskId,
|
|
1343
|
+
source: 'terminal_outcome_replay',
|
|
1344
|
+
status: outcome.status,
|
|
1345
|
+
action: published ? 'replay_event' : 'already-emitted',
|
|
1346
|
+
visibility_source: 'background-outcome',
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1349
|
+
continue;
|
|
1350
|
+
}
|
|
1351
|
+
if (!snapshotDelivered)
|
|
1352
|
+
continue;
|
|
1353
|
+
let action = 'replay_snapshot';
|
|
1354
|
+
if (delivery === 'event') {
|
|
1355
|
+
const published = this.publishTerminalOutcomeLine(outcome, responseId);
|
|
1356
|
+
action = published ? 'replay_event' : 'already-emitted';
|
|
1357
|
+
}
|
|
1358
|
+
if (persistedOutcomeIds.has(outcome.id)) {
|
|
1359
|
+
await storage
|
|
1360
|
+
.markDelivered(threadId, outcome.id, new Date().toISOString())
|
|
1361
|
+
.catch((error) => {
|
|
1362
|
+
this.logger.warn('Failed to mark Instance AI terminal outcome as delivered', {
|
|
1363
|
+
threadId,
|
|
1364
|
+
runId: outcome.runId,
|
|
1365
|
+
taskId: outcome.taskId,
|
|
1366
|
+
error: getErrorMessage(error),
|
|
1367
|
+
});
|
|
1368
|
+
});
|
|
1369
|
+
}
|
|
1370
|
+
this.pendingTerminalOutcomes.delete(outcome.id);
|
|
1371
|
+
this.telemetry.track('instance_ai_terminal_response_decision', {
|
|
1372
|
+
thread_id: threadId,
|
|
1373
|
+
run_id: outcome.runId,
|
|
1374
|
+
message_group_id: outcome.messageGroupId,
|
|
1375
|
+
task_id: outcome.taskId,
|
|
1376
|
+
source: 'terminal_outcome_replay',
|
|
1377
|
+
status: outcome.status,
|
|
1378
|
+
action,
|
|
1379
|
+
visibility_source: 'background-outcome',
|
|
1380
|
+
});
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
async persistTerminalOutcomeLineToSnapshot(outcome, responseId) {
|
|
1384
|
+
const snapshot = await this.dbSnapshotStorage.getLatest(outcome.threadId, {
|
|
1385
|
+
messageGroupId: outcome.messageGroupId,
|
|
1386
|
+
runId: outcome.runId,
|
|
1387
|
+
});
|
|
1388
|
+
if (!snapshot) {
|
|
1389
|
+
await this.dbSnapshotStorage.save(outcome.threadId, createTerminalOutcomeAgentTree(outcome, responseId), outcome.runId, {
|
|
1390
|
+
messageGroupId: outcome.messageGroupId,
|
|
1391
|
+
runIds: [outcome.runId],
|
|
1392
|
+
});
|
|
1393
|
+
return true;
|
|
1394
|
+
}
|
|
1395
|
+
const { tree } = appendTerminalOutcomeToAgentTree(snapshot.tree, outcome, responseId);
|
|
1396
|
+
const runIds = new Set(snapshot.runIds ?? [snapshot.runId]);
|
|
1397
|
+
runIds.add(outcome.runId);
|
|
1398
|
+
await this.dbSnapshotStorage.updateLast(outcome.threadId, tree, snapshot.runId, {
|
|
1399
|
+
messageGroupId: snapshot.messageGroupId ?? outcome.messageGroupId,
|
|
1400
|
+
runIds: [...runIds],
|
|
1401
|
+
langsmithRunId: snapshot.langsmithRunId,
|
|
1402
|
+
langsmithTraceId: snapshot.langsmithTraceId,
|
|
1403
|
+
});
|
|
1404
|
+
return true;
|
|
1405
|
+
}
|
|
1406
|
+
publishTerminalOutcomeLine(outcome, responseId) {
|
|
1407
|
+
const alreadyPublished = this.eventBus
|
|
1408
|
+
.getEventsForRun(outcome.threadId, outcome.runId)
|
|
1409
|
+
.some((event) => event.responseId === responseId);
|
|
1410
|
+
if (alreadyPublished)
|
|
1411
|
+
return false;
|
|
1412
|
+
this.eventBus.publish(outcome.threadId, {
|
|
1413
|
+
type: 'text-delta',
|
|
1414
|
+
runId: outcome.runId,
|
|
1415
|
+
agentId: ORCHESTRATOR_AGENT_ID,
|
|
1416
|
+
responseId,
|
|
1417
|
+
payload: { text: outcome.userFacingMessage },
|
|
1418
|
+
});
|
|
1419
|
+
return true;
|
|
1420
|
+
}
|
|
1421
|
+
async recordBackgroundTerminalOutcome(task) {
|
|
1422
|
+
const outcome = this.buildBackgroundTerminalOutcome(task);
|
|
1423
|
+
let persisted = false;
|
|
1424
|
+
try {
|
|
1425
|
+
await this.createTerminalOutcomeStorage().upsert(task.threadId, outcome);
|
|
1426
|
+
persisted = true;
|
|
1427
|
+
}
|
|
1428
|
+
catch (error) {
|
|
1429
|
+
this.pendingTerminalOutcomes.set(outcome.id, outcome);
|
|
1430
|
+
this.logger.warn('Failed to persist Instance AI terminal outcome', {
|
|
1431
|
+
threadId: task.threadId,
|
|
1432
|
+
runId: task.runId,
|
|
1433
|
+
taskId: task.taskId,
|
|
1434
|
+
error: getErrorMessage(error),
|
|
1435
|
+
});
|
|
1436
|
+
this.telemetry.track('instance_ai_terminal_outcome_persistence_failure', {
|
|
1437
|
+
thread_id: task.threadId,
|
|
1438
|
+
run_id: task.runId,
|
|
1439
|
+
task_id: task.taskId,
|
|
1440
|
+
status: outcome.status,
|
|
1441
|
+
phase: 'metadata',
|
|
1442
|
+
});
|
|
1443
|
+
}
|
|
1444
|
+
const responseId = getBackgroundOutcomeResponseId(outcome);
|
|
1445
|
+
const published = this.publishTerminalOutcomeLine(outcome, responseId);
|
|
1446
|
+
this.telemetry.track('instance_ai_terminal_response_decision', {
|
|
1447
|
+
thread_id: task.threadId,
|
|
1448
|
+
run_id: task.runId,
|
|
1449
|
+
message_group_id: task.messageGroupId,
|
|
1450
|
+
task_id: task.taskId,
|
|
1451
|
+
source: 'background_outcome',
|
|
1452
|
+
status: outcome.status,
|
|
1453
|
+
action: published ? 'emit' : 'already-emitted',
|
|
1454
|
+
visibility_source: 'background-outcome',
|
|
1455
|
+
});
|
|
1456
|
+
let snapshotDelivered = false;
|
|
1457
|
+
try {
|
|
1458
|
+
snapshotDelivered = await this.persistTerminalOutcomeLineToSnapshot(outcome, responseId);
|
|
1459
|
+
}
|
|
1460
|
+
catch (error) {
|
|
1461
|
+
this.logger.warn('Failed to persist Instance AI terminal outcome line to snapshot', {
|
|
1462
|
+
threadId: task.threadId,
|
|
1463
|
+
runId: task.runId,
|
|
1464
|
+
taskId: task.taskId,
|
|
1465
|
+
error: getErrorMessage(error),
|
|
1466
|
+
});
|
|
1467
|
+
this.telemetry.track('instance_ai_terminal_outcome_persistence_failure', {
|
|
1468
|
+
thread_id: task.threadId,
|
|
1469
|
+
run_id: task.runId,
|
|
1470
|
+
task_id: task.taskId,
|
|
1471
|
+
status: outcome.status,
|
|
1472
|
+
phase: 'snapshot',
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
if (!persisted || !snapshotDelivered)
|
|
1476
|
+
return;
|
|
1477
|
+
try {
|
|
1478
|
+
await this.createTerminalOutcomeStorage().markDelivered(task.threadId, outcome.id, new Date().toISOString());
|
|
1479
|
+
this.pendingTerminalOutcomes.delete(outcome.id);
|
|
1480
|
+
}
|
|
1481
|
+
catch (error) {
|
|
1482
|
+
this.logger.warn('Failed to mark Instance AI terminal outcome as delivered', {
|
|
1483
|
+
threadId: task.threadId,
|
|
1484
|
+
runId: task.runId,
|
|
1485
|
+
taskId: task.taskId,
|
|
1486
|
+
error: getErrorMessage(error),
|
|
1487
|
+
});
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
993
1490
|
async syncPlannedTasksToUi(threadId, graph) {
|
|
994
1491
|
const { taskStorage } = await this.createPlannedTaskState();
|
|
995
1492
|
const tasks = this.projectPlannedTaskList(graph);
|
|
@@ -1024,7 +1521,8 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1024
1521
|
}
|
|
1025
1522
|
}
|
|
1026
1523
|
async createExecutionEnvironment(user, threadId, runId, abortSignal, researchMode, messageGroupId, pushRef) {
|
|
1027
|
-
const
|
|
1524
|
+
const localGatewayDisabledGlobally = this.settingsService.getAdminSettings().localGatewayDisabled;
|
|
1525
|
+
const localGatewayDisabledForUser = await this.settingsService.isLocalGatewayDisabledForUser(user.id);
|
|
1028
1526
|
const userGateway = this.gatewayRegistry.findGateway(user.id);
|
|
1029
1527
|
let searchProxyConfig;
|
|
1030
1528
|
let tracingProxyConfig;
|
|
@@ -1039,7 +1537,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1039
1537
|
tokenManager = manager;
|
|
1040
1538
|
const featureHeaders = (0, api_types_1.buildProxyHeaders)({
|
|
1041
1539
|
feature: 'instance-ai',
|
|
1042
|
-
n8nVersion:
|
|
1540
|
+
n8nVersion: constants_1.N8N_VERSION,
|
|
1043
1541
|
});
|
|
1044
1542
|
searchProxyConfig = {
|
|
1045
1543
|
apiUrl: proxyBaseUrl + '/brave-search',
|
|
@@ -1061,7 +1559,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1061
1559
|
pushRef,
|
|
1062
1560
|
threadId,
|
|
1063
1561
|
});
|
|
1064
|
-
if (!
|
|
1562
|
+
if (!localGatewayDisabledForUser && userGateway?.isConnected) {
|
|
1065
1563
|
context.localMcpServer = userGateway;
|
|
1066
1564
|
}
|
|
1067
1565
|
context.permissions = this.settingsService.getPermissions();
|
|
@@ -1076,16 +1574,21 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1076
1574
|
}
|
|
1077
1575
|
context.domainAccessTracker = domainTracker;
|
|
1078
1576
|
context.runId = runId;
|
|
1079
|
-
if (
|
|
1080
|
-
context.localGatewayStatus = { status: '
|
|
1577
|
+
if (localGatewayDisabledGlobally) {
|
|
1578
|
+
context.localGatewayStatus = { status: 'disabledGlobally' };
|
|
1081
1579
|
}
|
|
1082
|
-
else if (userGateway?.isConnected) {
|
|
1083
|
-
context.localGatewayStatus = {
|
|
1580
|
+
else if (!localGatewayDisabledForUser && userGateway?.isConnected) {
|
|
1581
|
+
context.localGatewayStatus = {
|
|
1582
|
+
status: 'connected',
|
|
1583
|
+
capabilities: userGateway
|
|
1584
|
+
.getStatus()
|
|
1585
|
+
.toolCategories.filter(({ enabled }) => enabled)
|
|
1586
|
+
.map(({ name }) => name),
|
|
1587
|
+
};
|
|
1084
1588
|
}
|
|
1085
1589
|
else {
|
|
1086
1590
|
context.localGatewayStatus = {
|
|
1087
|
-
status: 'disconnected',
|
|
1088
|
-
capabilities: ['filesystem', 'browser'],
|
|
1591
|
+
status: localGatewayDisabledForUser ? 'disabled' : 'disconnected',
|
|
1089
1592
|
};
|
|
1090
1593
|
}
|
|
1091
1594
|
const modelId = proxyBaseUrl && tokenManager
|
|
@@ -1131,7 +1634,9 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1131
1634
|
localMcpServer: context.localMcpServer,
|
|
1132
1635
|
oauth2CallbackUrl: this.oauth2CallbackUrl,
|
|
1133
1636
|
webhookBaseUrl: this.webhookBaseUrl,
|
|
1637
|
+
formBaseUrl: this.formBaseUrl,
|
|
1134
1638
|
waitForConfirmation: async (requestId) => {
|
|
1639
|
+
this.runState.touchActiveRun(threadId);
|
|
1135
1640
|
return await new Promise((resolve) => {
|
|
1136
1641
|
this.runState.registerPendingConfirmation(requestId, {
|
|
1137
1642
|
resolve,
|
|
@@ -1146,6 +1651,8 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1146
1651
|
},
|
|
1147
1652
|
cancelBackgroundTask: async (taskId) => this.cancelBackgroundTask(threadId, taskId),
|
|
1148
1653
|
spawnBackgroundTask: (opts) => this.spawnBackgroundTask(runId, opts, snapshotStorage, messageGroupId),
|
|
1654
|
+
touchRun: () => this.runState.touchActiveRun(threadId),
|
|
1655
|
+
touchBackgroundTask: (taskId) => this.backgroundTasks.touchTask(threadId, taskId),
|
|
1149
1656
|
plannedTaskService,
|
|
1150
1657
|
schedulePlannedTasks: async () => await this.schedulePlannedTasks(user, threadId),
|
|
1151
1658
|
iterationLog,
|
|
@@ -1313,6 +1820,16 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1313
1820
|
await current;
|
|
1314
1821
|
}
|
|
1315
1822
|
async doSchedulePlannedTasks(user, threadId) {
|
|
1823
|
+
const revalidated = await this.revalidateActiveUser(user.id);
|
|
1824
|
+
if (!revalidated) {
|
|
1825
|
+
this.logger.warn('Cancelling run: user no longer authorized for AI Assistant', {
|
|
1826
|
+
userId: user.id,
|
|
1827
|
+
threadId,
|
|
1828
|
+
});
|
|
1829
|
+
this.cancelRun(threadId);
|
|
1830
|
+
return;
|
|
1831
|
+
}
|
|
1832
|
+
const activeUser = revalidated;
|
|
1316
1833
|
const { plannedTaskService } = await this.createPlannedTaskState();
|
|
1317
1834
|
const graph = await plannedTaskService.getGraph(threadId);
|
|
1318
1835
|
if (!graph)
|
|
@@ -1325,7 +1842,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1325
1842
|
return;
|
|
1326
1843
|
if (action.type === 'replan') {
|
|
1327
1844
|
await this.syncPlannedTasksToUi(threadId, action.graph);
|
|
1328
|
-
const startedRunId = await this.startInternalFollowUpRun(
|
|
1845
|
+
const startedRunId = await this.startInternalFollowUpRun(activeUser, threadId, this.buildPlannedTaskFollowUpMessage('replan', action.graph, {
|
|
1329
1846
|
failedTask: action.failedTask,
|
|
1330
1847
|
}), this.runState.getThreadResearchMode(threadId), action.graph.messageGroupId, true);
|
|
1331
1848
|
if (!startedRunId) {
|
|
@@ -1335,7 +1852,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1335
1852
|
}
|
|
1336
1853
|
if (action.type === 'synthesize') {
|
|
1337
1854
|
await this.syncPlannedTasksToUi(threadId, action.graph);
|
|
1338
|
-
const startedRunId = await this.startInternalFollowUpRun(
|
|
1855
|
+
const startedRunId = await this.startInternalFollowUpRun(activeUser, threadId, this.buildPlannedTaskFollowUpMessage('synthesize', action.graph), this.runState.getThreadResearchMode(threadId), action.graph.messageGroupId);
|
|
1339
1856
|
if (!startedRunId) {
|
|
1340
1857
|
await plannedTaskService.revertToActive(threadId);
|
|
1341
1858
|
}
|
|
@@ -1352,7 +1869,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1352
1869
|
const graphAfterMark = (await plannedTaskService.getGraph(threadId)) ?? action.graph;
|
|
1353
1870
|
await this.syncPlannedTasksToUi(threadId, graphAfterMark);
|
|
1354
1871
|
const checkpointRecord = graphAfterMark.tasks.find((t) => t.id === checkpoint.id) ?? checkpoint;
|
|
1355
|
-
const startedRunId = await this.startInternalFollowUpRun(
|
|
1872
|
+
const startedRunId = await this.startInternalFollowUpRun(activeUser, threadId, this.buildPlannedTaskFollowUpMessage('checkpoint', graphAfterMark, {
|
|
1356
1873
|
checkpoint: checkpointRecord,
|
|
1357
1874
|
}), this.runState.getThreadResearchMode(threadId), action.graph.messageGroupId, false, { isCheckpointFollowUp: true, checkpointTaskId: checkpoint.id });
|
|
1358
1875
|
if (!startedRunId) {
|
|
@@ -1361,12 +1878,12 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1361
1878
|
}
|
|
1362
1879
|
return;
|
|
1363
1880
|
}
|
|
1364
|
-
const environment = await this.createExecutionEnvironment(
|
|
1881
|
+
const environment = await this.createExecutionEnvironment(activeUser, threadId, action.graph.planRunId, createInertAbortSignal(), this.runState.getThreadResearchMode(threadId), action.graph.messageGroupId, this.threadPushRef.get(threadId));
|
|
1365
1882
|
environment.orchestrationContext.tracing = this.getTraceContext(action.graph.planRunId);
|
|
1366
1883
|
for (const task of action.tasks) {
|
|
1367
1884
|
await this.dispatchPlannedTask(task, environment.orchestrationContext, action.graph);
|
|
1368
1885
|
}
|
|
1369
|
-
await this.doSchedulePlannedTasks(
|
|
1886
|
+
await this.doSchedulePlannedTasks(activeUser, threadId);
|
|
1370
1887
|
}
|
|
1371
1888
|
async executeRun(user, threadId, runId, message, abortController, researchMode, attachments, messageGroupId, timeZone, isReplanFollowUp = false, checkpoint) {
|
|
1372
1889
|
const signal = abortController.signal;
|
|
@@ -1374,8 +1891,10 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1374
1891
|
let tracing;
|
|
1375
1892
|
let messageTraceFinalization;
|
|
1376
1893
|
let aiCreatedWorkflowIds;
|
|
1894
|
+
let activeSnapshotStorage;
|
|
1895
|
+
let messageId = '';
|
|
1377
1896
|
try {
|
|
1378
|
-
|
|
1897
|
+
messageId = (0, nanoid_1.nanoid)();
|
|
1379
1898
|
this.eventBus.publish(threadId, {
|
|
1380
1899
|
type: 'run-start',
|
|
1381
1900
|
runId,
|
|
@@ -1384,6 +1903,10 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1384
1903
|
payload: { messageId, messageGroupId },
|
|
1385
1904
|
});
|
|
1386
1905
|
if (signal.aborted) {
|
|
1906
|
+
this.evaluateTerminalResponse(threadId, runId, 'cancelled', {
|
|
1907
|
+
messageGroupId,
|
|
1908
|
+
correlationId: messageId,
|
|
1909
|
+
});
|
|
1387
1910
|
this.eventBus.publish(threadId, {
|
|
1388
1911
|
type: 'run-finish',
|
|
1389
1912
|
runId,
|
|
@@ -1394,7 +1917,9 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1394
1917
|
}
|
|
1395
1918
|
const mcpServers = this.parseMcpServers(this.instanceAiConfig.mcpServers);
|
|
1396
1919
|
const executionPushRef = this.threadPushRef.get(threadId);
|
|
1397
|
-
const
|
|
1920
|
+
const environment = await this.createExecutionEnvironment(user, threadId, runId, signal, researchMode, messageGroupId, executionPushRef);
|
|
1921
|
+
activeSnapshotStorage = environment.snapshotStorage;
|
|
1922
|
+
const { context, memory, taskStorage, snapshotStorage, modelId, orchestrationContext } = environment;
|
|
1398
1923
|
aiCreatedWorkflowIds = context.aiCreatedWorkflowIds ??= new Set();
|
|
1399
1924
|
orchestrationContext.currentUserMessage = message;
|
|
1400
1925
|
orchestrationContext.isReplanFollowUp = isReplanFollowUp;
|
|
@@ -1433,6 +1958,8 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1433
1958
|
userId: user.id,
|
|
1434
1959
|
modelId,
|
|
1435
1960
|
input: traceInput,
|
|
1961
|
+
n8nVersion: constants_1.N8N_VERSION,
|
|
1962
|
+
workflowSdkVersion: constants_1.WORKFLOW_SDK_VERSION,
|
|
1436
1963
|
proxyConfig: orchestrationContext.tracingProxyConfig,
|
|
1437
1964
|
});
|
|
1438
1965
|
if (!tracing && process.env.E2E_TESTS === 'true') {
|
|
@@ -1466,18 +1993,19 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1466
1993
|
context,
|
|
1467
1994
|
orchestrationContext,
|
|
1468
1995
|
mcpServers,
|
|
1996
|
+
mcpManager: this.mcpClientManager,
|
|
1469
1997
|
memoryConfig,
|
|
1470
1998
|
memory,
|
|
1471
1999
|
disableDeferredTools: true,
|
|
1472
2000
|
timeZone: timeZone ?? this.defaultTimeZone,
|
|
1473
2001
|
});
|
|
1474
2002
|
const enrichedMessage = await this.buildMessageWithRunningTasks(threadId, message);
|
|
1475
|
-
let
|
|
2003
|
+
let multimodalAttachments = [];
|
|
1476
2004
|
let attachmentManifest = '';
|
|
1477
2005
|
let hasParseableAttachment = false;
|
|
1478
2006
|
if (attachments && attachments.length > 0) {
|
|
1479
2007
|
const classifiedAttachments = (0, instance_ai_1.classifyAttachments)(attachments);
|
|
1480
|
-
|
|
2008
|
+
multimodalAttachments = attachments.filter((attachment) => !(0, instance_ai_1.isParseableAttachment)(attachment) && attachment.mimeType.startsWith('image/'));
|
|
1481
2009
|
hasParseableAttachment = classifiedAttachments.some((attachment) => attachment.parseable);
|
|
1482
2010
|
attachmentManifest = (0, instance_ai_1.buildAttachmentManifest)(classifiedAttachments);
|
|
1483
2011
|
}
|
|
@@ -1553,13 +2081,13 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1553
2081
|
const fullMessage = conversationSummary
|
|
1554
2082
|
? `${conversationSummary}\n\n${messageWithoutSummary}`
|
|
1555
2083
|
: messageWithoutSummary;
|
|
1556
|
-
if (
|
|
2084
|
+
if (multimodalAttachments.length > 0) {
|
|
1557
2085
|
streamInput = [
|
|
1558
2086
|
{
|
|
1559
2087
|
role: 'user',
|
|
1560
2088
|
content: [
|
|
1561
2089
|
{ type: 'text', text: fullMessage },
|
|
1562
|
-
...
|
|
2090
|
+
...multimodalAttachments.map((attachment) => ({
|
|
1563
2091
|
type: 'file',
|
|
1564
2092
|
data: attachment.data,
|
|
1565
2093
|
mimeType: attachment.mimeType,
|
|
@@ -1577,7 +2105,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1577
2105
|
: {
|
|
1578
2106
|
fullMessage,
|
|
1579
2107
|
attachmentCount: attachments?.length ?? 0,
|
|
1580
|
-
|
|
2108
|
+
multimodalAttachmentCount: multimodalAttachments.length,
|
|
1581
2109
|
};
|
|
1582
2110
|
await tracing.finishRun(promptBuildRun, {
|
|
1583
2111
|
outputs: traceOutput,
|
|
@@ -1612,6 +2140,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1612
2140
|
signal,
|
|
1613
2141
|
eventBus: this.eventBus,
|
|
1614
2142
|
logger: this.logger,
|
|
2143
|
+
onActivity: () => this.runState.touchActiveRun(threadId),
|
|
1615
2144
|
});
|
|
1616
2145
|
})
|
|
1617
2146
|
: await (0, instance_ai_1.streamAgentRun)(agent, streamInput, {
|
|
@@ -1631,6 +2160,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1631
2160
|
signal,
|
|
1632
2161
|
eventBus: this.eventBus,
|
|
1633
2162
|
logger: this.logger,
|
|
2163
|
+
onActivity: () => this.runState.touchActiveRun(threadId),
|
|
1634
2164
|
});
|
|
1635
2165
|
mastraRunId = result.mastraRunId;
|
|
1636
2166
|
if (result.status === 'suspended') {
|
|
@@ -1658,6 +2188,20 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1658
2188
|
is_intermediate: true,
|
|
1659
2189
|
});
|
|
1660
2190
|
}
|
|
2191
|
+
const waitingDecision = this.evaluateWaitingResponse(threadId, runId, result.confirmationEvent, {
|
|
2192
|
+
messageGroupId,
|
|
2193
|
+
correlationId: messageId,
|
|
2194
|
+
});
|
|
2195
|
+
if (waitingDecision?.reason === 'confirmation-invalid') {
|
|
2196
|
+
messageTraceFinalization = await this.finishInvalidConfirmationRun({
|
|
2197
|
+
threadId,
|
|
2198
|
+
runId,
|
|
2199
|
+
abortController,
|
|
2200
|
+
snapshotStorage,
|
|
2201
|
+
tracing,
|
|
2202
|
+
});
|
|
2203
|
+
return;
|
|
2204
|
+
}
|
|
1661
2205
|
if (result.confirmationEvent) {
|
|
1662
2206
|
this.trackConfirmationRequest(threadId, result.confirmationEvent);
|
|
1663
2207
|
this.eventBus.publish(threadId, result.confirmationEvent);
|
|
@@ -1666,6 +2210,11 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1666
2210
|
return;
|
|
1667
2211
|
}
|
|
1668
2212
|
const outputText = await (result.text ?? Promise.resolve(''));
|
|
2213
|
+
this.evaluateTerminalResponse(threadId, runId, result.status, {
|
|
2214
|
+
messageGroupId,
|
|
2215
|
+
correlationId: messageId,
|
|
2216
|
+
workSummary: result.workSummary,
|
|
2217
|
+
});
|
|
1669
2218
|
const finalStatus = result.status === 'errored' ? 'error' : result.status;
|
|
1670
2219
|
await this.finalizeRunTracing(runId, tracing, {
|
|
1671
2220
|
status: finalStatus,
|
|
@@ -1697,25 +2246,44 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1697
2246
|
}
|
|
1698
2247
|
catch (error) {
|
|
1699
2248
|
if (signal.aborted) {
|
|
2249
|
+
const cancellationReason = this.liveness.consumeRunTimedOut(runId)
|
|
2250
|
+
? liveness_1.INSTANCE_AI_RUN_TIMEOUT_REASON
|
|
2251
|
+
: getAbortReason(signal);
|
|
2252
|
+
if (cancellationReason === liveness_1.INSTANCE_AI_RUN_TIMEOUT_REASON) {
|
|
2253
|
+
this.liveness.publishRunTimeoutNotice(threadId, runId);
|
|
2254
|
+
}
|
|
2255
|
+
this.evaluateTerminalResponse(threadId, runId, 'cancelled', {
|
|
2256
|
+
messageGroupId,
|
|
2257
|
+
correlationId: messageId,
|
|
2258
|
+
});
|
|
1700
2259
|
await this.finalizeRunTracing(runId, tracing, {
|
|
1701
2260
|
status: 'cancelled',
|
|
1702
|
-
reason:
|
|
2261
|
+
reason: cancellationReason,
|
|
1703
2262
|
});
|
|
1704
2263
|
messageTraceFinalization = {
|
|
1705
2264
|
status: 'cancelled',
|
|
1706
|
-
reason:
|
|
2265
|
+
reason: cancellationReason,
|
|
1707
2266
|
metadata: { completion_source: 'orchestrator' },
|
|
1708
2267
|
};
|
|
1709
2268
|
const archivedWorkflowIds = await this.reapAiTemporaryFromRun(threadId, user, aiCreatedWorkflowIds);
|
|
1710
|
-
this.publishRunFinish(threadId, runId, 'cancelled',
|
|
2269
|
+
this.publishRunFinish(threadId, runId, 'cancelled', cancellationReason, archivedWorkflowIds);
|
|
2270
|
+
if (activeSnapshotStorage) {
|
|
2271
|
+
await this.saveAgentTreeSnapshot(threadId, runId, activeSnapshotStorage);
|
|
2272
|
+
}
|
|
1711
2273
|
return;
|
|
1712
2274
|
}
|
|
1713
2275
|
const errorMessage = getErrorMessage(error);
|
|
2276
|
+
const userFacingErrorMessage = getUserFacingErrorMessage(error);
|
|
1714
2277
|
this.logger.error('Instance AI run error', {
|
|
1715
2278
|
error: errorMessage,
|
|
1716
2279
|
threadId,
|
|
1717
2280
|
runId,
|
|
1718
2281
|
});
|
|
2282
|
+
this.evaluateTerminalResponse(threadId, runId, 'errored', {
|
|
2283
|
+
messageGroupId,
|
|
2284
|
+
correlationId: messageId,
|
|
2285
|
+
errorMessage: userFacingErrorMessage,
|
|
2286
|
+
});
|
|
1719
2287
|
await this.finalizeRunTracing(runId, tracing, {
|
|
1720
2288
|
status: 'error',
|
|
1721
2289
|
reason: errorMessage,
|
|
@@ -1732,14 +2300,16 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1732
2300
|
agentId: ORCHESTRATOR_AGENT_ID,
|
|
1733
2301
|
payload: {
|
|
1734
2302
|
status: 'error',
|
|
1735
|
-
reason:
|
|
2303
|
+
reason: userFacingErrorMessage,
|
|
1736
2304
|
...(archivedWorkflowIds.length > 0 ? { archivedWorkflowIds } : {}),
|
|
1737
2305
|
},
|
|
1738
2306
|
});
|
|
2307
|
+
if (activeSnapshotStorage) {
|
|
2308
|
+
await this.saveAgentTreeSnapshot(threadId, runId, activeSnapshotStorage);
|
|
2309
|
+
}
|
|
1739
2310
|
}
|
|
1740
2311
|
finally {
|
|
1741
2312
|
this.runState.clearActiveRun(threadId);
|
|
1742
|
-
this.threadPushRef.delete(threadId);
|
|
1743
2313
|
this.domainAccessTrackersByThread.get(threadId)?.clearRun(runId);
|
|
1744
2314
|
if (messageTraceFinalization) {
|
|
1745
2315
|
await this.maybeFinalizeRunTraceRoot(runId, messageTraceFinalization);
|
|
@@ -1866,6 +2436,19 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1866
2436
|
}
|
|
1867
2437
|
async resolveConfirmation(requestingUserId, requestId, request) {
|
|
1868
2438
|
const data = toConfirmationData(request);
|
|
2439
|
+
const revalidated = await this.revalidateActiveUser(requestingUserId);
|
|
2440
|
+
if (!revalidated) {
|
|
2441
|
+
this.logger.warn('Rejecting confirmation: user no longer authorized for AI Assistant', {
|
|
2442
|
+
userId: requestingUserId,
|
|
2443
|
+
requestId,
|
|
2444
|
+
});
|
|
2445
|
+
this.runState.rejectPendingConfirmation(requestId);
|
|
2446
|
+
const suspended = this.runState.findSuspendedByRequestId(requestId);
|
|
2447
|
+
if (suspended && suspended.user.id === requestingUserId) {
|
|
2448
|
+
this.cancelRun(suspended.threadId);
|
|
2449
|
+
}
|
|
2450
|
+
return false;
|
|
2451
|
+
}
|
|
1869
2452
|
if (this.runState.resolvePendingConfirmation(requestingUserId, requestId, data)) {
|
|
1870
2453
|
this.logger.debug('Resolved pending confirmation (sub-agent HITL)', {
|
|
1871
2454
|
requestId,
|
|
@@ -1891,6 +2474,16 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1891
2474
|
const { agent, runId, mastraRunId, threadId, user, toolCallId, abortController, tracing, checkpoint, } = suspended;
|
|
1892
2475
|
if (user.id !== requestingUserId)
|
|
1893
2476
|
return false;
|
|
2477
|
+
const revalidated = await this.revalidateActiveUser(user.id);
|
|
2478
|
+
if (!revalidated) {
|
|
2479
|
+
this.logger.warn('Cancelling suspended run: user no longer authorized for AI Assistant', {
|
|
2480
|
+
userId: user.id,
|
|
2481
|
+
threadId,
|
|
2482
|
+
requestId,
|
|
2483
|
+
});
|
|
2484
|
+
this.cancelRun(threadId);
|
|
2485
|
+
return false;
|
|
2486
|
+
}
|
|
1894
2487
|
this.runState.activateSuspendedRun(threadId);
|
|
1895
2488
|
const credentialsPayload = data.nodeCredentials ?? data.credentials;
|
|
1896
2489
|
const resumeData = {
|
|
@@ -1908,7 +2501,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1908
2501
|
runId,
|
|
1909
2502
|
mastraRunId,
|
|
1910
2503
|
threadId,
|
|
1911
|
-
user,
|
|
2504
|
+
user: revalidated,
|
|
1912
2505
|
toolCallId,
|
|
1913
2506
|
signal: abortController.signal,
|
|
1914
2507
|
abortController,
|
|
@@ -1935,6 +2528,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1935
2528
|
eventBus: this.eventBus,
|
|
1936
2529
|
logger: this.logger,
|
|
1937
2530
|
mastraRunId: opts.mastraRunId,
|
|
2531
|
+
onActivity: () => this.runState.touchActiveRun(opts.threadId),
|
|
1938
2532
|
});
|
|
1939
2533
|
})
|
|
1940
2534
|
: await (0, instance_ai_1.resumeAgentRun)(agent, resumeData, {
|
|
@@ -1949,6 +2543,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1949
2543
|
eventBus: this.eventBus,
|
|
1950
2544
|
logger: this.logger,
|
|
1951
2545
|
mastraRunId: opts.mastraRunId,
|
|
2546
|
+
onActivity: () => this.runState.touchActiveRun(opts.threadId),
|
|
1952
2547
|
});
|
|
1953
2548
|
if (result.status === 'suspended') {
|
|
1954
2549
|
if (result.suspension) {
|
|
@@ -1975,6 +2570,18 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1975
2570
|
is_intermediate: true,
|
|
1976
2571
|
});
|
|
1977
2572
|
}
|
|
2573
|
+
const messageGroupId = this.traceContextsByRunId.get(opts.runId)?.messageGroupId;
|
|
2574
|
+
const waitingDecision = this.evaluateWaitingResponse(opts.threadId, opts.runId, result.confirmationEvent, { messageGroupId });
|
|
2575
|
+
if (waitingDecision?.reason === 'confirmation-invalid') {
|
|
2576
|
+
messageTraceFinalization = await this.finishInvalidConfirmationRun({
|
|
2577
|
+
threadId: opts.threadId,
|
|
2578
|
+
runId: opts.runId,
|
|
2579
|
+
abortController: opts.abortController,
|
|
2580
|
+
snapshotStorage: opts.snapshotStorage,
|
|
2581
|
+
tracing: opts.tracing,
|
|
2582
|
+
});
|
|
2583
|
+
return;
|
|
2584
|
+
}
|
|
1978
2585
|
if (result.confirmationEvent) {
|
|
1979
2586
|
this.trackConfirmationRequest(opts.threadId, result.confirmationEvent);
|
|
1980
2587
|
this.eventBus.publish(opts.threadId, result.confirmationEvent);
|
|
@@ -1983,6 +2590,11 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1983
2590
|
return;
|
|
1984
2591
|
}
|
|
1985
2592
|
const outputText = await (result.text ?? Promise.resolve(''));
|
|
2593
|
+
const messageGroupId = this.traceContextsByRunId.get(opts.runId)?.messageGroupId;
|
|
2594
|
+
this.evaluateTerminalResponse(opts.threadId, opts.runId, result.status, {
|
|
2595
|
+
messageGroupId,
|
|
2596
|
+
workSummary: result.workSummary,
|
|
2597
|
+
});
|
|
1986
2598
|
const finalStatus = result.status === 'errored' ? 'error' : result.status;
|
|
1987
2599
|
await this.finalizeRunTracing(opts.runId, opts.tracing, {
|
|
1988
2600
|
status: finalStatus,
|
|
@@ -2009,6 +2621,10 @@ let InstanceAiService = class InstanceAiService {
|
|
|
2009
2621
|
}
|
|
2010
2622
|
catch (error) {
|
|
2011
2623
|
if (opts.signal.aborted) {
|
|
2624
|
+
const messageGroupId = this.traceContextsByRunId.get(opts.runId)?.messageGroupId;
|
|
2625
|
+
this.evaluateTerminalResponse(opts.threadId, opts.runId, 'cancelled', {
|
|
2626
|
+
messageGroupId,
|
|
2627
|
+
});
|
|
2012
2628
|
await this.finalizeRunTracing(opts.runId, opts.tracing, {
|
|
2013
2629
|
status: 'cancelled',
|
|
2014
2630
|
reason: 'user_cancelled',
|
|
@@ -2020,14 +2636,21 @@ let InstanceAiService = class InstanceAiService {
|
|
|
2020
2636
|
};
|
|
2021
2637
|
const archivedWorkflowIds = await this.reapAiTemporaryFromRun(opts.threadId, opts.user, undefined);
|
|
2022
2638
|
this.publishRunFinish(opts.threadId, opts.runId, 'cancelled', 'user_cancelled', archivedWorkflowIds);
|
|
2639
|
+
await this.saveAgentTreeSnapshot(opts.threadId, opts.runId, opts.snapshotStorage);
|
|
2023
2640
|
return;
|
|
2024
2641
|
}
|
|
2025
2642
|
const errorMessage = getErrorMessage(error);
|
|
2643
|
+
const userFacingErrorMessage = getUserFacingErrorMessage(error);
|
|
2026
2644
|
this.logger.error('Instance AI resumed run error', {
|
|
2027
2645
|
error: errorMessage,
|
|
2028
2646
|
threadId: opts.threadId,
|
|
2029
2647
|
runId: opts.runId,
|
|
2030
2648
|
});
|
|
2649
|
+
const messageGroupId = this.traceContextsByRunId.get(opts.runId)?.messageGroupId;
|
|
2650
|
+
this.evaluateTerminalResponse(opts.threadId, opts.runId, 'errored', {
|
|
2651
|
+
messageGroupId,
|
|
2652
|
+
errorMessage: userFacingErrorMessage,
|
|
2653
|
+
});
|
|
2031
2654
|
await this.finalizeRunTracing(opts.runId, opts.tracing, {
|
|
2032
2655
|
status: 'error',
|
|
2033
2656
|
reason: errorMessage,
|
|
@@ -2044,14 +2667,14 @@ let InstanceAiService = class InstanceAiService {
|
|
|
2044
2667
|
agentId: ORCHESTRATOR_AGENT_ID,
|
|
2045
2668
|
payload: {
|
|
2046
2669
|
status: 'error',
|
|
2047
|
-
reason:
|
|
2670
|
+
reason: userFacingErrorMessage,
|
|
2048
2671
|
...(archivedWorkflowIds.length > 0 ? { archivedWorkflowIds } : {}),
|
|
2049
2672
|
},
|
|
2050
2673
|
});
|
|
2674
|
+
await this.saveAgentTreeSnapshot(opts.threadId, opts.runId, opts.snapshotStorage);
|
|
2051
2675
|
}
|
|
2052
2676
|
finally {
|
|
2053
2677
|
this.runState.clearActiveRun(opts.threadId);
|
|
2054
|
-
this.threadPushRef.delete(opts.threadId);
|
|
2055
2678
|
if (messageTraceFinalization) {
|
|
2056
2679
|
await this.maybeFinalizeRunTraceRoot(opts.runId, messageTraceFinalization);
|
|
2057
2680
|
}
|
|
@@ -2132,6 +2755,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
2132
2755
|
}
|
|
2133
2756
|
},
|
|
2134
2757
|
onSettled: async (task) => {
|
|
2758
|
+
await this.recordBackgroundTerminalOutcome(task);
|
|
2135
2759
|
await this.saveAgentTreeSnapshot(opts.threadId, runId, snapshotStorage, true, task.messageGroupId);
|
|
2136
2760
|
if (task.plannedTaskId)
|
|
2137
2761
|
return;
|
|
@@ -2152,6 +2776,13 @@ let InstanceAiService = class InstanceAiService {
|
|
|
2152
2776
|
const hasActiveRun = !!this.runState.getActiveRunId(opts.threadId);
|
|
2153
2777
|
const hasSuspendedRun = this.runState.hasSuspendedRun(opts.threadId);
|
|
2154
2778
|
if (remaining.length === 0 && !hasActiveRun && !hasSuspendedRun) {
|
|
2779
|
+
if (this.liveness.hasTimedOutActiveRunThread(opts.threadId)) {
|
|
2780
|
+
this.logger.debug('Skipping background auto-follow-up after active run timeout', {
|
|
2781
|
+
threadId: opts.threadId,
|
|
2782
|
+
taskId: task.taskId,
|
|
2783
|
+
});
|
|
2784
|
+
return;
|
|
2785
|
+
}
|
|
2155
2786
|
const user = this.runState.getThreadUser(opts.threadId);
|
|
2156
2787
|
if (user) {
|
|
2157
2788
|
const payload = JSON.stringify({
|
|
@@ -2302,20 +2933,23 @@ let InstanceAiService = class InstanceAiService {
|
|
|
2302
2933
|
}
|
|
2303
2934
|
return archived;
|
|
2304
2935
|
}
|
|
2305
|
-
async finalizeCancelledSuspendedRun(suspended) {
|
|
2936
|
+
async finalizeCancelledSuspendedRun(suspended, reason = 'user_cancelled') {
|
|
2937
|
+
if (reason === liveness_1.INSTANCE_AI_RUN_TIMEOUT_REASON) {
|
|
2938
|
+
this.liveness.publishRunTimeoutNotice(suspended.threadId, suspended.runId);
|
|
2939
|
+
}
|
|
2306
2940
|
await this.finalizeRunTracing(suspended.runId, suspended.tracing, {
|
|
2307
2941
|
status: 'cancelled',
|
|
2308
|
-
reason
|
|
2942
|
+
reason,
|
|
2309
2943
|
});
|
|
2310
2944
|
const archivedWorkflowIds = await this.reapAiTemporaryFromRun(suspended.threadId, suspended.user, undefined);
|
|
2311
|
-
this.publishRunFinish(suspended.threadId, suspended.runId, 'cancelled',
|
|
2945
|
+
this.publishRunFinish(suspended.threadId, suspended.runId, 'cancelled', reason, archivedWorkflowIds);
|
|
2312
2946
|
await this.saveAgentTreeSnapshot(suspended.threadId, suspended.runId, this.dbSnapshotStorage, true);
|
|
2313
2947
|
if (suspended.mastraRunId) {
|
|
2314
2948
|
void this.cleanupMastraSnapshots(suspended.mastraRunId);
|
|
2315
2949
|
}
|
|
2316
2950
|
await this.maybeFinalizeRunTraceRoot(suspended.runId, {
|
|
2317
2951
|
status: 'cancelled',
|
|
2318
|
-
reason
|
|
2952
|
+
reason,
|
|
2319
2953
|
metadata: { completion_source: 'orchestrator' },
|
|
2320
2954
|
});
|
|
2321
2955
|
}
|
|
@@ -2391,11 +3025,9 @@ let InstanceAiService = class InstanceAiService {
|
|
|
2391
3025
|
}
|
|
2392
3026
|
async finalizeRun(threadId, runId, status, snapshotStorage, options) {
|
|
2393
3027
|
this.publishRunFinish(threadId, runId, status, undefined, options?.archivedWorkflowIds);
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
void this.refineTitleIfNeeded(threadId, options.userId, options.modelId);
|
|
2398
|
-
}
|
|
3028
|
+
await this.saveAgentTreeSnapshot(threadId, runId, snapshotStorage);
|
|
3029
|
+
if (status === 'completed' && options?.userId && options?.modelId) {
|
|
3030
|
+
void this.refineTitleIfNeeded(threadId, options.userId, options.modelId);
|
|
2399
3031
|
}
|
|
2400
3032
|
}
|
|
2401
3033
|
async refineTitleIfNeeded(threadId, userId, modelId) {
|
|
@@ -2456,11 +3088,23 @@ let InstanceAiService = class InstanceAiService {
|
|
|
2456
3088
|
let groupRunIds;
|
|
2457
3089
|
if (messageGroupId) {
|
|
2458
3090
|
groupRunIds = this.getRunIdsForMessageGroup(messageGroupId);
|
|
3091
|
+
if (groupRunIds.length === 0) {
|
|
3092
|
+
const snapshot = await snapshotStorage.getLatest(threadId, { messageGroupId, runId });
|
|
3093
|
+
groupRunIds = snapshot?.runIds?.length ? snapshot.runIds : [runId];
|
|
3094
|
+
}
|
|
2459
3095
|
events = this.eventBus.getEventsForRuns(threadId, groupRunIds);
|
|
2460
3096
|
}
|
|
2461
3097
|
else {
|
|
2462
3098
|
events = this.eventBus.getEventsForRun(threadId, runId);
|
|
2463
3099
|
}
|
|
3100
|
+
if (isUpdate && events.length === 0) {
|
|
3101
|
+
this.logger.warn('Skipped updating empty Instance AI agent tree snapshot', {
|
|
3102
|
+
threadId,
|
|
3103
|
+
runId,
|
|
3104
|
+
messageGroupId,
|
|
3105
|
+
});
|
|
3106
|
+
return;
|
|
3107
|
+
}
|
|
2464
3108
|
const agentTree = (0, instance_ai_1.buildAgentTreeFromEvents)(events);
|
|
2465
3109
|
const tracing = this.traceContextsByRunId.get(runId)?.tracing;
|
|
2466
3110
|
const saveOptions = {
|
|
@@ -2513,6 +3157,9 @@ exports.InstanceAiService = InstanceAiService = __decorate([
|
|
|
2513
3157
|
telemetry_1.Telemetry,
|
|
2514
3158
|
db_1.UserRepository,
|
|
2515
3159
|
db_1.AiBuilderTemporaryWorkflowRepository,
|
|
2516
|
-
n8n_core_1.ErrorReporter
|
|
3160
|
+
n8n_core_1.ErrorReporter,
|
|
3161
|
+
config_1.SsrfProtectionConfig,
|
|
3162
|
+
ssrf_protection_service_1.SsrfProtectionService,
|
|
3163
|
+
event_service_1.EventService])
|
|
2517
3164
|
], InstanceAiService);
|
|
2518
3165
|
//# sourceMappingURL=instance-ai.service.js.map
|