n8n 2.22.4 → 2.23.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/auth/auth.service.d.ts +2 -0
- package/dist/auth/auth.service.js +15 -4
- package/dist/auth/auth.service.js.map +1 -1
- package/dist/build.tsbuildinfo +1 -1
- package/dist/chat/chat-service.types.d.ts +4 -4
- package/dist/commands/execute.d.ts +2 -2
- package/dist/commands/export/workflow.js +1 -0
- package/dist/commands/export/workflow.js.map +1 -1
- package/dist/commands/license/info.js +4 -4
- package/dist/commands/license/info.js.map +1 -1
- package/dist/commands/start.js +21 -1
- package/dist/commands/start.js.map +1 -1
- package/dist/constants.js +1 -0
- package/dist/constants.js.map +1 -1
- package/dist/controllers/annotation-tags.controller.ee.d.ts +1 -1
- package/dist/controllers/e2e.controller.js +1 -0
- package/dist/controllers/e2e.controller.js.map +1 -1
- package/dist/controllers/oauth/oauth1-credential.controller.d.ts +1 -1
- package/dist/controllers/oauth/oauth1-credential.controller.js +4 -7
- package/dist/controllers/oauth/oauth1-credential.controller.js.map +1 -1
- package/dist/controllers/oauth/oauth2-credential.controller.js +3 -6
- package/dist/controllers/oauth/oauth2-credential.controller.js.map +1 -1
- package/dist/controllers/redaction-enforcement-mapper.d.ts +3 -0
- package/dist/controllers/redaction-enforcement-mapper.js +27 -0
- package/dist/controllers/redaction-enforcement-mapper.js.map +1 -0
- package/dist/controllers/security-settings.controller.d.ts +8 -2
- package/dist/controllers/security-settings.controller.js +35 -25
- package/dist/controllers/security-settings.controller.js.map +1 -1
- package/dist/credentials/credential-connection-status-provider.interface.d.ts +3 -0
- package/dist/credentials/credential-connection-status-provider.interface.js +3 -0
- package/dist/credentials/credential-connection-status-provider.interface.js.map +1 -0
- package/dist/credentials/credential-connection-status-proxy.d.ts +6 -0
- package/dist/credentials/credential-connection-status-proxy.js +25 -0
- package/dist/credentials/credential-connection-status-proxy.js.map +1 -0
- package/dist/credentials/credential-resolution-provider.interface.d.ts +1 -0
- package/dist/credentials/credentials.controller.d.ts +2 -0
- package/dist/credentials/credentials.service.d.ts +10 -1
- package/dist/credentials/credentials.service.ee.d.ts +2 -0
- package/dist/credentials/credentials.service.ee.js +13 -3
- package/dist/credentials/credentials.service.ee.js.map +1 -1
- package/dist/credentials/credentials.service.js +34 -7
- package/dist/credentials/credentials.service.js.map +1 -1
- package/dist/credentials/dynamic-credentials-proxy.d.ts +2 -0
- package/dist/credentials/dynamic-credentials-proxy.js +9 -0
- package/dist/credentials/dynamic-credentials-proxy.js.map +1 -1
- package/dist/credentials-helper.js +2 -1
- package/dist/credentials-helper.js.map +1 -1
- package/dist/errors/feature-not-licensed.error.d.ts +3 -1
- package/dist/errors/feature-not-licensed.error.js +2 -2
- package/dist/errors/feature-not-licensed.error.js.map +1 -1
- package/dist/evaluation.ee/evaluation-collection.service.js +2 -0
- package/dist/evaluation.ee/evaluation-collection.service.js.map +1 -1
- package/dist/evaluation.ee/insights/eval-insights.controller.ee.d.ts +41 -0
- package/dist/evaluation.ee/insights/eval-insights.controller.ee.js +62 -0
- package/dist/evaluation.ee/insights/eval-insights.controller.ee.js.map +1 -0
- package/dist/evaluation.ee/insights/eval-insights.service.d.ts +25 -0
- package/dist/evaluation.ee/insights/eval-insights.service.js +206 -0
- package/dist/evaluation.ee/insights/eval-insights.service.js.map +1 -0
- package/dist/evaluation.ee/test-runner/test-runner.service.ee.d.ts +3 -2
- package/dist/evaluation.ee/test-runner/test-runner.service.ee.js +16 -2
- package/dist/evaluation.ee/test-runner/test-runner.service.ee.js.map +1 -1
- package/dist/events/relays/telemetry.event-relay.d.ts +3 -1
- package/dist/events/relays/telemetry.event-relay.js +9 -3
- package/dist/events/relays/telemetry.event-relay.js.map +1 -1
- package/dist/execution-lifecycle/execution-lifecycle-hooks.d.ts +1 -1
- package/dist/execution-lifecycle/execution-lifecycle-hooks.js +4 -2
- package/dist/execution-lifecycle/execution-lifecycle-hooks.js.map +1 -1
- package/dist/executions/execution-data/db-store.d.ts +4 -2
- package/dist/executions/execution-data/db-store.js +9 -4
- package/dist/executions/execution-data/db-store.js.map +1 -1
- package/dist/executions/execution-data/missing-execution-data.error.d.ts +5 -0
- package/dist/executions/execution-data/missing-execution-data.error.js +11 -0
- package/dist/executions/execution-data/missing-execution-data.error.js.map +1 -0
- package/dist/executions/execution-data/types.d.ts +3 -2
- package/dist/executions/execution-data/types.js.map +1 -1
- package/dist/executions/execution-persistence.d.ts +12 -3
- package/dist/executions/execution-persistence.js +102 -26
- package/dist/executions/execution-persistence.js.map +1 -1
- package/dist/external-hooks.d.ts +6 -1
- package/dist/external-hooks.js.map +1 -1
- package/dist/instance-settings-loader/loaders/sso/provisioning.instance-settings-loader.d.ts +3 -2
- package/dist/instance-settings-loader/loaders/sso/provisioning.instance-settings-loader.js +17 -12
- package/dist/instance-settings-loader/loaders/sso/provisioning.instance-settings-loader.js.map +1 -1
- package/dist/interfaces.d.ts +1 -0
- package/dist/license.d.ts +2 -0
- package/dist/license.js +6 -0
- package/dist/license.js.map +1 -1
- package/dist/load-nodes-and-credentials.d.ts +32 -4
- package/dist/manual-execution.service.js +3 -0
- package/dist/manual-execution.service.js.map +1 -1
- package/dist/modules/agents/agent-execution.service.js +5 -5
- package/dist/modules/agents/agent-execution.service.js.map +1 -1
- package/dist/modules/agents/agent-sse-stream.js +17 -1
- package/dist/modules/agents/agent-sse-stream.js.map +1 -1
- package/dist/modules/agents/agents-tools.service.js +7 -5
- package/dist/modules/agents/agents-tools.service.js.map +1 -1
- package/dist/modules/agents/agents.controller.d.ts +29 -3
- package/dist/modules/agents/agents.controller.js +88 -7
- package/dist/modules/agents/agents.controller.js.map +1 -1
- package/dist/modules/agents/agents.module.d.ts +1 -1
- package/dist/modules/agents/agents.module.js +12 -6
- package/dist/modules/agents/agents.module.js.map +1 -1
- package/dist/modules/agents/agents.service.d.ts +7 -8
- package/dist/modules/agents/agents.service.js +120 -65
- package/dist/modules/agents/agents.service.js.map +1 -1
- package/dist/modules/agents/builder/agents-builder-model-recommendations.d.ts +1 -1
- package/dist/modules/agents/builder/agents-builder-model-recommendations.js +3 -3
- package/dist/modules/agents/builder/agents-builder-model-recommendations.js.map +1 -1
- package/dist/modules/agents/builder/agents-builder-prompts.d.ts +9 -17
- package/dist/modules/agents/builder/agents-builder-prompts.js +145 -549
- package/dist/modules/agents/builder/agents-builder-prompts.js.map +1 -1
- package/dist/modules/agents/builder/agents-builder-settings.service.js +2 -2
- package/dist/modules/agents/builder/agents-builder-settings.service.js.map +1 -1
- package/dist/modules/agents/builder/agents-builder-tools.service.js +10 -10
- package/dist/modules/agents/builder/agents-builder-tools.service.js.map +1 -1
- package/dist/modules/agents/builder/agents-builder.service.d.ts +3 -1
- package/dist/modules/agents/builder/agents-builder.service.js +58 -9
- package/dist/modules/agents/builder/agents-builder.service.js.map +1 -1
- package/dist/modules/agents/builder/interactive/ask-credential.tool.js +2 -2
- package/dist/modules/agents/builder/interactive/ask-credential.tool.js.map +1 -1
- package/dist/modules/agents/builder/interactive/ask-llm.tool.js +2 -2
- package/dist/modules/agents/builder/interactive/ask-llm.tool.js.map +1 -1
- package/dist/modules/agents/builder/interactive/ask-question.tool.js +2 -2
- package/dist/modules/agents/builder/interactive/ask-question.tool.js.map +1 -1
- package/dist/modules/agents/builder/interactive/resolve-llm.tool.js +2 -2
- package/dist/modules/agents/builder/interactive/resolve-llm.tool.js.map +1 -1
- package/dist/modules/agents/builder/prompts/config-mutation.prompt.d.ts +1 -0
- package/dist/modules/agents/builder/prompts/config-mutation.prompt.js +132 -0
- package/dist/modules/agents/builder/prompts/config-mutation.prompt.js.map +1 -0
- package/dist/modules/agents/builder/prompts/config-rules.prompt.d.ts +2 -0
- package/dist/modules/agents/builder/prompts/config-rules.prompt.js +63 -0
- package/dist/modules/agents/builder/prompts/config-rules.prompt.js.map +1 -0
- package/dist/modules/agents/builder/prompts/llm-selection.prompt.d.ts +1 -0
- package/dist/modules/agents/builder/prompts/llm-selection.prompt.js +47 -0
- package/dist/modules/agents/builder/prompts/llm-selection.prompt.js.map +1 -0
- package/dist/modules/agents/builder/prompts/memory.prompt.d.ts +1 -0
- package/dist/modules/agents/builder/prompts/memory.prompt.js +60 -0
- package/dist/modules/agents/builder/prompts/memory.prompt.js.map +1 -0
- package/dist/modules/agents/builder/prompts/tools.prompt.d.ts +1 -0
- package/dist/modules/agents/builder/prompts/tools.prompt.js +81 -0
- package/dist/modules/agents/builder/prompts/tools.prompt.js.map +1 -0
- package/dist/modules/agents/builder/skills/index.d.ts +2 -0
- package/dist/modules/agents/builder/skills/index.js +12 -0
- package/dist/modules/agents/builder/skills/index.js.map +1 -0
- package/dist/modules/agents/builder/skills/integrations.skill.d.ts +2 -0
- package/dist/modules/agents/builder/skills/integrations.skill.js +53 -0
- package/dist/modules/agents/builder/skills/integrations.skill.js.map +1 -0
- package/dist/modules/agents/builder/skills/research.skill.d.ts +2 -0
- package/dist/modules/agents/builder/skills/research.skill.js +42 -0
- package/dist/modules/agents/builder/skills/research.skill.js.map +1 -0
- package/dist/modules/agents/builder/skills/target-skills.skill.d.ts +2 -0
- package/dist/modules/agents/builder/skills/target-skills.skill.js +59 -0
- package/dist/modules/agents/builder/skills/target-skills.skill.js.map +1 -0
- package/dist/modules/agents/entities/{agent-published-version.entity.d.ts → agent-history.entity.d.ts} +4 -7
- package/dist/modules/agents/entities/{agent-published-version.entity.js → agent-history.entity.js} +22 -34
- package/dist/modules/agents/entities/agent-history.entity.js.map +1 -0
- package/dist/modules/agents/entities/agent-memory-entry-cursor.entity.d.ts +7 -0
- package/dist/modules/agents/entities/agent-memory-entry-cursor.entity.js +38 -0
- package/dist/modules/agents/entities/agent-memory-entry-cursor.entity.js.map +1 -0
- package/dist/modules/agents/entities/agent-memory-entry-lock.entity.d.ts +7 -0
- package/dist/modules/{instance-ai/entities/instance-ai-workflow-snapshot.entity.js → agents/entities/agent-memory-entry-lock.entity.js} +16 -19
- package/dist/modules/agents/entities/agent-memory-entry-lock.entity.js.map +1 -0
- package/dist/modules/agents/entities/agent-memory-entry-source.entity.d.ts +9 -0
- package/dist/modules/agents/entities/agent-memory-entry-source.entity.js +49 -0
- package/dist/modules/agents/entities/agent-memory-entry-source.entity.js.map +1 -0
- package/dist/modules/agents/entities/agent-memory-entry.entity.d.ts +15 -0
- package/dist/modules/agents/entities/agent-memory-entry.entity.js +65 -0
- package/dist/modules/agents/entities/agent-memory-entry.entity.js.map +1 -0
- package/dist/modules/agents/entities/agent-observation-cursor.entity.d.ts +2 -3
- package/dist/modules/agents/entities/agent-observation-cursor.entity.js +5 -4
- package/dist/modules/agents/entities/agent-observation-cursor.entity.js.map +1 -1
- package/dist/modules/agents/entities/agent-observation-lock.entity.d.ts +2 -3
- package/dist/modules/agents/entities/agent-observation-lock.entity.js +5 -4
- package/dist/modules/agents/entities/agent-observation-lock.entity.js.map +1 -1
- package/dist/modules/agents/entities/agent-observation.entity.d.ts +2 -3
- package/dist/modules/agents/entities/agent-observation.entity.js +6 -5
- package/dist/modules/agents/entities/agent-observation.entity.js.map +1 -1
- package/dist/modules/agents/entities/agent.entity.d.ts +3 -5
- package/dist/modules/agents/entities/agent.entity.js +7 -14
- package/dist/modules/agents/entities/agent.entity.js.map +1 -1
- package/dist/modules/agents/episodic-memory.d.ts +2 -0
- package/dist/modules/agents/episodic-memory.js +12 -0
- package/dist/modules/agents/episodic-memory.js.map +1 -0
- package/dist/modules/agents/integrations/agent-chat-bridge.d.ts +2 -1
- package/dist/modules/agents/integrations/agent-chat-bridge.js +19 -5
- package/dist/modules/agents/integrations/agent-chat-bridge.js.map +1 -1
- package/dist/modules/agents/integrations/agent-schedule.service.js +10 -6
- package/dist/modules/agents/integrations/agent-schedule.service.js.map +1 -1
- package/dist/modules/agents/integrations/chat-integration.service.js +1 -1
- package/dist/modules/agents/integrations/chat-integration.service.js.map +1 -1
- package/dist/modules/agents/integrations/n8n-memory.d.ts +41 -18
- package/dist/modules/agents/integrations/n8n-memory.js +519 -77
- package/dist/modules/agents/integrations/n8n-memory.js.map +1 -1
- package/dist/modules/agents/integrations/platforms/slack-integration.js +2 -12
- package/dist/modules/agents/integrations/platforms/slack-integration.js.map +1 -1
- package/dist/modules/agents/integrations/rich-interaction-tool.d.ts +1 -1
- package/dist/modules/agents/integrations/rich-interaction-tool.js +2 -2
- package/dist/modules/agents/integrations/rich-interaction-tool.js.map +1 -1
- package/dist/modules/agents/integrations/slack-app-setup.service.d.ts +52 -0
- package/dist/modules/agents/integrations/slack-app-setup.service.js +316 -0
- package/dist/modules/agents/integrations/slack-app-setup.service.js.map +1 -0
- package/dist/modules/agents/json-config/from-json-config.d.ts +2 -3
- package/dist/modules/agents/json-config/from-json-config.js +76 -61
- package/dist/modules/agents/json-config/from-json-config.js.map +1 -1
- package/dist/modules/agents/json-config/schema-text-serializer.js +2 -1
- package/dist/modules/agents/json-config/schema-text-serializer.js.map +1 -1
- package/dist/modules/agents/repositories/agent-history.repository.d.ts +19 -0
- package/dist/modules/agents/repositories/agent-history.repository.js +51 -0
- package/dist/modules/agents/repositories/agent-history.repository.js.map +1 -0
- package/dist/modules/agents/repositories/agent-memory-entry-cursor.repository.d.ts +5 -0
- package/dist/modules/{instance-ai/repositories/instance-ai-workflow-snapshot.repository.js → agents/repositories/agent-memory-entry-cursor.repository.js} +8 -8
- package/dist/modules/agents/repositories/agent-memory-entry-cursor.repository.js.map +1 -0
- package/dist/modules/agents/repositories/agent-memory-entry-lock.repository.d.ts +5 -0
- package/dist/modules/{instance-ai/repositories/instance-ai-observational-memory.repository.js → agents/repositories/agent-memory-entry-lock.repository.js} +8 -8
- package/dist/modules/agents/repositories/agent-memory-entry-lock.repository.js.map +1 -0
- package/dist/modules/agents/repositories/agent-memory-entry-source.repository.d.ts +5 -0
- package/dist/modules/agents/repositories/agent-memory-entry-source.repository.js +26 -0
- package/dist/modules/agents/repositories/agent-memory-entry-source.repository.js.map +1 -0
- package/dist/modules/agents/repositories/agent-memory-entry.repository.d.ts +5 -0
- package/dist/modules/agents/repositories/agent-memory-entry.repository.js +26 -0
- package/dist/modules/agents/repositories/agent-memory-entry.repository.js.map +1 -0
- package/dist/modules/agents/repositories/agent.repository.js +3 -3
- package/dist/modules/agents/repositories/agent.repository.js.map +1 -1
- package/dist/modules/agents/runtime/agent-secure-runtime.js +5 -5
- package/dist/modules/agents/runtime/agent-secure-runtime.js.map +1 -1
- package/dist/modules/agents/tools/environment-tool.d.ts +1 -1
- package/dist/modules/agents/tools/environment-tool.js +3 -3
- package/dist/modules/agents/tools/environment-tool.js.map +1 -1
- package/dist/modules/agents/tools/node-tool-factory.js +5 -5
- package/dist/modules/agents/tools/node-tool-factory.js.map +1 -1
- package/dist/modules/agents/tools/workflow-tool-factory.js +3 -3
- package/dist/modules/agents/tools/workflow-tool-factory.js.map +1 -1
- package/dist/modules/agents/tracing/builder-telemetry.d.ts +2 -3
- package/dist/modules/agents/tracing/builder-telemetry.js +36 -3
- package/dist/modules/agents/tracing/builder-telemetry.js.map +1 -1
- package/dist/modules/agents/utils/agent-draft.utils.js +1 -2
- package/dist/modules/agents/utils/agent-draft.utils.js.map +1 -1
- package/dist/modules/agents/utils/agent-memory-scope.d.ts +3 -0
- package/dist/modules/agents/utils/agent-memory-scope.js +15 -0
- package/dist/modules/agents/utils/agent-memory-scope.js.map +1 -0
- package/dist/modules/chat-hub/chat-hub.constants.js +4 -0
- package/dist/modules/chat-hub/chat-hub.constants.js.map +1 -1
- package/dist/modules/chat-hub/context-limits.js +1 -0
- package/dist/modules/chat-hub/context-limits.js.map +1 -1
- package/dist/modules/dynamic-credentials.ee/constants.d.ts +3 -0
- package/dist/modules/dynamic-credentials.ee/constants.js +7 -0
- package/dist/modules/dynamic-credentials.ee/constants.js.map +1 -0
- package/dist/modules/dynamic-credentials.ee/credential-resolvers/identifiers/n8n-identifier.js +14 -2
- package/dist/modules/dynamic-credentials.ee/credential-resolvers/identifiers/n8n-identifier.js.map +1 -1
- package/dist/modules/dynamic-credentials.ee/credential-resolvers.controller.d.ts +2 -2
- package/dist/modules/dynamic-credentials.ee/credential-resolvers.controller.js +18 -4
- package/dist/modules/dynamic-credentials.ee/credential-resolvers.controller.js.map +1 -1
- package/dist/modules/dynamic-credentials.ee/dynamic-credentials.module.d.ts +1 -1
- package/dist/modules/dynamic-credentials.ee/dynamic-credentials.module.js +4 -1
- package/dist/modules/dynamic-credentials.ee/dynamic-credentials.module.js.map +1 -1
- package/dist/modules/dynamic-credentials.ee/errors/system-resolver-modification.error.d.ts +4 -0
- package/dist/modules/dynamic-credentials.ee/errors/system-resolver-modification.error.js +11 -0
- package/dist/modules/dynamic-credentials.ee/errors/system-resolver-modification.error.js.map +1 -0
- package/dist/modules/dynamic-credentials.ee/services/credential-connection-status.service.d.ts +7 -0
- package/dist/modules/dynamic-credentials.ee/services/credential-connection-status.service.js +40 -0
- package/dist/modules/dynamic-credentials.ee/services/credential-connection-status.service.js.map +1 -0
- package/dist/modules/dynamic-credentials.ee/services/credential-resolver-workflow.service.d.ts +3 -1
- package/dist/modules/dynamic-credentials.ee/services/credential-resolver-workflow.service.js +6 -3
- package/dist/modules/dynamic-credentials.ee/services/credential-resolver-workflow.service.js.map +1 -1
- package/dist/modules/dynamic-credentials.ee/services/credential-resolver.service.d.ts +2 -0
- package/dist/modules/dynamic-credentials.ee/services/credential-resolver.service.js +22 -0
- package/dist/modules/dynamic-credentials.ee/services/credential-resolver.service.js.map +1 -1
- package/dist/modules/dynamic-credentials.ee/services/dynamic-credential-storage.service.d.ts +3 -1
- package/dist/modules/dynamic-credentials.ee/services/dynamic-credential-storage.service.js +7 -3
- package/dist/modules/dynamic-credentials.ee/services/dynamic-credential-storage.service.js.map +1 -1
- package/dist/modules/dynamic-credentials.ee/services/dynamic-credential.service.d.ts +4 -1
- package/dist/modules/dynamic-credentials.ee/services/dynamic-credential.service.js +11 -3
- package/dist/modules/dynamic-credentials.ee/services/dynamic-credential.service.js.map +1 -1
- package/dist/modules/dynamic-credentials.ee/services/index.d.ts +2 -0
- package/dist/modules/dynamic-credentials.ee/services/index.js +2 -0
- package/dist/modules/dynamic-credentials.ee/services/index.js.map +1 -1
- package/dist/modules/dynamic-credentials.ee/services/n8n-resolver-seeder.service.d.ts +14 -0
- package/dist/modules/dynamic-credentials.ee/services/n8n-resolver-seeder.service.js +70 -0
- package/dist/modules/dynamic-credentials.ee/services/n8n-resolver-seeder.service.js.map +1 -0
- package/dist/modules/insights/insights-collection.service.js +1 -1
- package/dist/modules/insights/insights-collection.service.js.map +1 -1
- package/dist/modules/instance-ai/entities/index.d.ts +6 -2
- package/dist/modules/instance-ai/entities/index.js +9 -5
- package/dist/modules/instance-ai/entities/index.js.map +1 -1
- package/dist/modules/instance-ai/entities/instance-ai-checkpoint.entity.d.ts +12 -0
- package/dist/modules/instance-ai/entities/instance-ai-checkpoint.entity.js +54 -0
- package/dist/modules/instance-ai/entities/instance-ai-checkpoint.entity.js.map +1 -0
- package/dist/modules/instance-ai/entities/instance-ai-observation-cursor.entity.d.ts +6 -0
- package/dist/modules/instance-ai/entities/instance-ai-observation-cursor.entity.js +33 -0
- package/dist/modules/instance-ai/entities/instance-ai-observation-cursor.entity.js.map +1 -0
- package/dist/modules/instance-ai/entities/instance-ai-observation-lock.entity.d.ts +8 -0
- package/dist/modules/instance-ai/entities/instance-ai-observation-lock.entity.js +37 -0
- package/dist/modules/instance-ai/entities/instance-ai-observation-lock.entity.js.map +1 -0
- package/dist/modules/instance-ai/entities/instance-ai-observation.entity.d.ts +12 -0
- package/dist/modules/instance-ai/entities/instance-ai-observation.entity.js +52 -0
- package/dist/modules/instance-ai/entities/instance-ai-observation.entity.js.map +1 -0
- package/dist/modules/instance-ai/entities/instance-ai-pending-confirmation.entity.d.ts +19 -0
- package/dist/modules/instance-ai/entities/instance-ai-pending-confirmation.entity.js +82 -0
- package/dist/modules/instance-ai/entities/instance-ai-pending-confirmation.entity.js.map +1 -0
- package/dist/modules/instance-ai/entities/instance-ai-run-snapshot.entity.d.ts +2 -0
- package/dist/modules/instance-ai/entities/instance-ai-run-snapshot.entity.js +8 -0
- package/dist/modules/instance-ai/entities/instance-ai-run-snapshot.entity.js.map +1 -1
- package/dist/modules/instance-ai/eval/eval-mocked-credentials-helper.d.ts +12 -2
- package/dist/modules/instance-ai/eval/eval-mocked-credentials-helper.js +40 -4
- package/dist/modules/instance-ai/eval/eval-mocked-credentials-helper.js.map +1 -1
- package/dist/modules/instance-ai/eval/execution.service.d.ts +8 -2
- package/dist/modules/instance-ai/eval/execution.service.js +137 -47
- package/dist/modules/instance-ai/eval/execution.service.js.map +1 -1
- package/dist/modules/instance-ai/eval/llm-wire-server.d.ts +31 -0
- package/dist/modules/instance-ai/eval/llm-wire-server.js +127 -0
- package/dist/modules/instance-ai/eval/llm-wire-server.js.map +1 -0
- package/dist/modules/instance-ai/eval/openai-envelope.d.ts +6 -0
- package/dist/modules/instance-ai/eval/openai-envelope.js +96 -0
- package/dist/modules/instance-ai/eval/openai-envelope.js.map +1 -0
- package/dist/modules/instance-ai/eval/proxy-loopback.d.ts +1 -0
- package/dist/modules/instance-ai/eval/proxy-loopback.js +44 -0
- package/dist/modules/instance-ai/eval/proxy-loopback.js.map +1 -0
- package/dist/modules/instance-ai/eval/sub-agent-eval.service.js +29 -7
- package/dist/modules/instance-ai/eval/sub-agent-eval.service.js.map +1 -1
- package/dist/modules/instance-ai/eval/workflow-analysis.d.ts +7 -1
- package/dist/modules/instance-ai/eval/workflow-analysis.js +178 -3
- package/dist/modules/instance-ai/eval/workflow-analysis.js.map +1 -1
- package/dist/modules/instance-ai/instance-ai-memory.service.d.ts +6 -6
- package/dist/modules/instance-ai/instance-ai-memory.service.js +44 -85
- package/dist/modules/instance-ai/instance-ai-memory.service.js.map +1 -1
- package/dist/modules/instance-ai/instance-ai-settings.service.d.ts +2 -1
- package/dist/modules/instance-ai/instance-ai-settings.service.js +11 -22
- package/dist/modules/instance-ai/instance-ai-settings.service.js.map +1 -1
- package/dist/modules/instance-ai/instance-ai.adapter.service.d.ts +2 -0
- package/dist/modules/instance-ai/instance-ai.adapter.service.js +105 -13
- package/dist/modules/instance-ai/instance-ai.adapter.service.js.map +1 -1
- package/dist/modules/instance-ai/instance-ai.module.d.ts +1 -1
- package/dist/modules/instance-ai/instance-ai.module.js +10 -6
- package/dist/modules/instance-ai/instance-ai.module.js.map +1 -1
- package/dist/modules/instance-ai/instance-ai.service.d.ts +34 -12
- package/dist/modules/instance-ai/instance-ai.service.js +724 -264
- package/dist/modules/instance-ai/instance-ai.service.js.map +1 -1
- package/dist/modules/instance-ai/liveness/instance-ai-liveness.service.d.ts +4 -1
- package/dist/modules/instance-ai/liveness/instance-ai-liveness.service.js +3 -1
- package/dist/modules/instance-ai/liveness/instance-ai-liveness.service.js.map +1 -1
- package/dist/modules/instance-ai/message-parser.d.ts +3 -3
- package/dist/modules/instance-ai/message-parser.js +65 -61
- package/dist/modules/instance-ai/message-parser.js.map +1 -1
- package/dist/modules/instance-ai/node-definition-resolver.js +12 -48
- package/dist/modules/instance-ai/node-definition-resolver.js.map +1 -1
- package/dist/modules/instance-ai/repositories/index.d.ts +4 -2
- package/dist/modules/instance-ai/repositories/index.js +9 -5
- package/dist/modules/instance-ai/repositories/index.js.map +1 -1
- package/dist/modules/instance-ai/repositories/instance-ai-checkpoint.repository.d.ts +5 -0
- package/dist/modules/instance-ai/repositories/instance-ai-checkpoint.repository.js +26 -0
- package/dist/modules/instance-ai/repositories/instance-ai-checkpoint.repository.js.map +1 -0
- package/dist/modules/instance-ai/repositories/instance-ai-observation-cursor.repository.d.ts +5 -0
- package/dist/modules/instance-ai/repositories/instance-ai-observation-cursor.repository.js +26 -0
- package/dist/modules/instance-ai/repositories/instance-ai-observation-cursor.repository.js.map +1 -0
- package/dist/modules/instance-ai/repositories/instance-ai-observation-lock.repository.d.ts +5 -0
- package/dist/modules/instance-ai/repositories/instance-ai-observation-lock.repository.js +26 -0
- package/dist/modules/instance-ai/repositories/instance-ai-observation-lock.repository.js.map +1 -0
- package/dist/modules/instance-ai/repositories/instance-ai-observation.repository.d.ts +5 -0
- package/dist/modules/{agents/repositories/agent-published-version.repository.js → instance-ai/repositories/instance-ai-observation.repository.js} +8 -17
- package/dist/modules/instance-ai/repositories/instance-ai-observation.repository.js.map +1 -0
- package/dist/modules/instance-ai/storage/db-snapshot-storage.d.ts +2 -0
- package/dist/modules/instance-ai/storage/db-snapshot-storage.js +12 -2
- package/dist/modules/instance-ai/storage/db-snapshot-storage.js.map +1 -1
- package/dist/modules/instance-ai/storage/index.d.ts +2 -3
- package/dist/modules/instance-ai/storage/index.js +5 -7
- package/dist/modules/instance-ai/storage/index.js.map +1 -1
- package/dist/modules/instance-ai/storage/typeorm-agent-checkpoint-store.d.ts +15 -0
- package/dist/modules/instance-ai/storage/typeorm-agent-checkpoint-store.js +94 -0
- package/dist/modules/instance-ai/storage/typeorm-agent-checkpoint-store.js.map +1 -0
- package/dist/modules/instance-ai/storage/typeorm-agent-memory.d.ts +94 -0
- package/dist/modules/instance-ai/storage/typeorm-agent-memory.js +324 -0
- package/dist/modules/instance-ai/storage/typeorm-agent-memory.js.map +1 -0
- package/dist/modules/instance-ai/storage/typeorm-observation-log-store.d.ts +37 -0
- package/dist/modules/instance-ai/storage/typeorm-observation-log-store.js +212 -0
- package/dist/modules/instance-ai/storage/typeorm-observation-log-store.js.map +1 -0
- package/dist/modules/instance-ai/web-research/fetch-and-extract.js +34 -11
- package/dist/modules/instance-ai/web-research/fetch-and-extract.js.map +1 -1
- package/dist/modules/mcp/mcp.service.js +5 -5
- package/dist/modules/mcp/mcp.service.js.map +1 -1
- package/dist/modules/mcp/tools/schemas.d.ts +24 -24
- package/dist/modules/mcp/tools/search-projects.tool.js +59 -13
- package/dist/modules/mcp/tools/search-projects.tool.js.map +1 -1
- package/dist/modules/mcp/tools/test-workflow.tool.d.ts +2 -2
- package/dist/modules/mcp/tools/workflow-builder/connection-structure-check.d.ts +35 -0
- package/dist/modules/mcp/tools/workflow-builder/connection-structure-check.js +88 -0
- package/dist/modules/mcp/tools/workflow-builder/connection-structure-check.js.map +1 -0
- package/dist/modules/mcp/tools/workflow-builder/create-workflow-from-code.tool.d.ts +3 -2
- package/dist/modules/mcp/tools/workflow-builder/create-workflow-from-code.tool.js +41 -9
- package/dist/modules/mcp/tools/workflow-builder/create-workflow-from-code.tool.js.map +1 -1
- package/dist/modules/mcp/tools/workflow-builder/data-table-validation.d.ts +13 -0
- package/dist/modules/mcp/tools/workflow-builder/data-table-validation.js +87 -0
- package/dist/modules/mcp/tools/workflow-builder/data-table-validation.js.map +1 -0
- package/dist/modules/mcp/tools/workflow-builder/update-workflow.tool.d.ts +2 -1
- package/dist/modules/mcp/tools/workflow-builder/update-workflow.tool.js +42 -6
- 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.d.ts +2 -1
- package/dist/modules/mcp/tools/workflow-builder/validate-workflow-code.tool.js +5 -1
- package/dist/modules/mcp/tools/workflow-builder/validate-workflow-code.tool.js.map +1 -1
- package/dist/modules/mcp/tools/workflow-validation.utils.js +1 -1
- package/dist/modules/mcp/tools/workflow-validation.utils.js.map +1 -1
- package/dist/modules/mcp-registry/mcp-registry-test.controller.js +5 -1
- package/dist/modules/mcp-registry/mcp-registry-test.controller.js.map +1 -1
- package/dist/modules/n8n-packages/entities/workflow/workflow.exporter.d.ts +18 -0
- package/dist/modules/n8n-packages/entities/workflow/workflow.exporter.js +73 -0
- package/dist/modules/n8n-packages/entities/workflow/workflow.exporter.js.map +1 -0
- package/dist/modules/n8n-packages/entities/workflow/workflow.serializer.d.ts +5 -0
- package/dist/modules/n8n-packages/entities/workflow/workflow.serializer.js +31 -0
- package/dist/modules/n8n-packages/entities/workflow/workflow.serializer.js.map +1 -0
- package/dist/modules/n8n-packages/io/package-writer.d.ts +6 -0
- package/dist/{scaling/multi-main-setup.types.js → modules/n8n-packages/io/package-writer.js} +1 -1
- package/dist/modules/n8n-packages/io/package-writer.js.map +1 -0
- package/dist/modules/n8n-packages/io/slug.utils.d.ts +1 -0
- package/dist/modules/n8n-packages/io/slug.utils.js +16 -0
- package/dist/modules/n8n-packages/io/slug.utils.js.map +1 -0
- package/dist/modules/n8n-packages/io/tar/tar-package-writer.d.ts +9 -0
- package/dist/modules/n8n-packages/io/tar/tar-package-writer.js +71 -0
- package/dist/modules/n8n-packages/io/tar/tar-package-writer.js.map +1 -0
- package/dist/modules/n8n-packages/n8n-packages.controller.d.ts +10 -0
- package/dist/modules/n8n-packages/n8n-packages.controller.js +45 -0
- package/dist/modules/n8n-packages/n8n-packages.controller.js.map +1 -0
- package/dist/modules/{inbound-secrets/inbound-secrets.module.d.ts → n8n-packages/n8n-packages.module.d.ts} +1 -1
- package/dist/modules/{inbound-secrets/inbound-secrets.module.js → n8n-packages/n8n-packages.module.js} +12 -16
- package/dist/modules/n8n-packages/n8n-packages.module.js.map +1 -0
- package/dist/modules/n8n-packages/n8n-packages.service.d.ts +10 -0
- package/dist/modules/n8n-packages/n8n-packages.service.js +49 -0
- package/dist/modules/n8n-packages/n8n-packages.service.js.map +1 -0
- package/dist/modules/n8n-packages/n8n-packages.types.d.ts +5 -0
- package/dist/modules/n8n-packages/n8n-packages.types.js +3 -0
- package/dist/modules/n8n-packages/n8n-packages.types.js.map +1 -0
- package/dist/modules/n8n-packages/spec/constants.d.ts +1 -0
- package/dist/modules/n8n-packages/spec/constants.js +5 -0
- package/dist/modules/n8n-packages/spec/constants.js.map +1 -0
- package/dist/modules/n8n-packages/spec/manifest.schema.d.ts +55 -0
- package/dist/modules/n8n-packages/spec/manifest.schema.js +17 -0
- package/dist/modules/n8n-packages/spec/manifest.schema.js.map +1 -0
- package/dist/modules/n8n-packages/spec/serialized/workflow.schema.d.ts +169 -0
- package/dist/modules/n8n-packages/spec/serialized/workflow.schema.js +46 -0
- package/dist/modules/n8n-packages/spec/serialized/workflow.schema.js.map +1 -0
- package/dist/modules/oauth-jwe/oauth-jwe-decrypt.service.d.ts +5 -1
- package/dist/modules/oauth-jwe/oauth-jwe-decrypt.service.js +18 -2
- package/dist/modules/oauth-jwe/oauth-jwe-decrypt.service.js.map +1 -1
- package/dist/modules/oauth-jwe/oauth-jwe.utils.js +27 -2
- package/dist/modules/oauth-jwe/oauth-jwe.utils.js.map +1 -1
- package/dist/modules/otel/execution-level-tracer.js +1 -0
- package/dist/modules/otel/execution-level-tracer.js.map +1 -1
- package/dist/modules/otel/execution-level-tracer.types.d.ts +11 -6
- package/dist/modules/otel/execution-level-tracer.types.js.map +1 -1
- package/dist/modules/otel/otel-lifecycle-handler.d.ts +5 -1
- package/dist/modules/otel/otel-lifecycle-handler.js +30 -2
- package/dist/modules/otel/otel-lifecycle-handler.js.map +1 -1
- package/dist/modules/otel/otel.constants.d.ts +1 -0
- package/dist/modules/otel/otel.constants.js +1 -0
- package/dist/modules/otel/otel.constants.js.map +1 -1
- package/dist/modules/runtime-credentials/path-traversal.js.map +1 -0
- package/dist/modules/runtime-credentials/runtime-credentials-access.service.d.ts +8 -0
- package/dist/modules/runtime-credentials/runtime-credentials-access.service.js +35 -0
- package/dist/modules/runtime-credentials/runtime-credentials-access.service.js.map +1 -0
- package/dist/modules/{inbound-secrets/inbound-secrets-context-hook.d.ts → runtime-credentials/runtime-credentials-context-hook.d.ts} +4 -5
- package/dist/modules/{inbound-secrets/inbound-secrets-context-hook.js → runtime-credentials/runtime-credentials-context-hook.js} +14 -22
- package/dist/modules/runtime-credentials/runtime-credentials-context-hook.js.map +1 -0
- package/dist/modules/runtime-credentials/runtime-credentials.config.d.ts +3 -0
- package/dist/modules/{inbound-secrets/inbound-secrets.config.js → runtime-credentials/runtime-credentials.config.js} +7 -7
- package/dist/modules/runtime-credentials/runtime-credentials.config.js.map +1 -0
- package/dist/modules/runtime-credentials/runtime-credentials.module.d.ts +4 -0
- package/dist/modules/runtime-credentials/runtime-credentials.module.js +65 -0
- package/dist/modules/runtime-credentials/runtime-credentials.module.js.map +1 -0
- package/dist/modules/runtime-credentials/runtime-credentials.schemas.d.ts +23 -0
- package/dist/modules/runtime-credentials/runtime-credentials.schemas.js +10 -0
- package/dist/modules/runtime-credentials/runtime-credentials.schemas.js.map +1 -0
- package/dist/modules/runtime-credentials/runtime-credentials.service.d.ts +18 -0
- package/dist/modules/{inbound-secrets/inbound-secrets.service.js → runtime-credentials/runtime-credentials.service.js} +31 -28
- package/dist/modules/runtime-credentials/runtime-credentials.service.js.map +1 -0
- package/dist/modules/source-control.ee/source-control-export.service.ee.d.ts +1 -1
- package/dist/modules/source-control.ee/source-control-export.service.ee.js +3 -1
- package/dist/modules/source-control.ee/source-control-export.service.ee.js.map +1 -1
- package/dist/modules/source-control.ee/source-control-import.service.ee.d.ts +2 -2
- package/dist/modules/source-control.ee/source-control-import.service.ee.js +29 -8
- package/dist/modules/source-control.ee/source-control-import.service.ee.js.map +1 -1
- package/dist/modules/source-control.ee/source-control-status.service.ee.js +4 -4
- package/dist/modules/source-control.ee/source-control-status.service.ee.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/source-control.ee/types/exportable-workflow.d.ts +2 -1
- package/dist/modules/sso-saml/saml.service.ee.js +5 -1
- package/dist/modules/sso-saml/saml.service.ee.js.map +1 -1
- package/dist/modules/workflow-index/workflow-dependency.controller.d.ts +1 -4
- package/dist/modules/workflow-index/workflow-dependency.controller.js +2 -13
- package/dist/modules/workflow-index/workflow-dependency.controller.js.map +1 -1
- package/dist/node-catalog/node-catalog.service.d.ts +1 -2
- package/dist/node-catalog/node-catalog.service.js +6 -10
- package/dist/node-catalog/node-catalog.service.js.map +1 -1
- package/dist/node-execution/ephemeral-node-executor.js +19 -11
- package/dist/node-execution/ephemeral-node-executor.js.map +1 -1
- package/dist/oauth/oauth-jwe-service.proxy.d.ts +12 -2
- package/dist/oauth/oauth-jwe-service.proxy.js +5 -0
- package/dist/oauth/oauth-jwe-service.proxy.js.map +1 -1
- package/dist/oauth/oauth.service.d.ts +6 -1
- package/dist/oauth/oauth.service.js +42 -4
- package/dist/oauth/oauth.service.js.map +1 -1
- package/dist/permissions.ee/check-access.d.ts +2 -2
- package/dist/permissions.ee/check-access.js +15 -11
- package/dist/permissions.ee/check-access.js.map +1 -1
- package/dist/posthog/index.d.ts +2 -0
- package/dist/posthog/index.js +28 -6
- package/dist/posthog/index.js.map +1 -1
- package/dist/public-api/v1/handlers/n8n-packages/n8n-packages.handler.d.ts +10 -0
- package/dist/public-api/v1/handlers/n8n-packages/n8n-packages.handler.js +42 -0
- package/dist/public-api/v1/handlers/n8n-packages/n8n-packages.handler.js.map +1 -0
- package/dist/public-api/v1/openapi.yml +55 -0
- package/dist/requests.d.ts +1 -1
- package/dist/scaling/constants.js +3 -0
- package/dist/scaling/constants.js.map +1 -1
- package/dist/scaling/multi-main-setup.ee.d.ts +12 -7
- package/dist/scaling/multi-main-setup.ee.js +125 -22
- package/dist/scaling/multi-main-setup.ee.js.map +1 -1
- package/dist/server.d.ts +1 -0
- package/dist/server.js +3 -4
- package/dist/server.js.map +1 -1
- package/dist/services/dynamic-node-parameters.service.d.ts +0 -1
- package/dist/services/dynamic-node-parameters.service.js +6 -14
- package/dist/services/dynamic-node-parameters.service.js.map +1 -1
- package/dist/services/frontend.service.js +1 -1
- package/dist/services/frontend.service.js.map +1 -1
- package/dist/services/import.service.js +3 -1
- package/dist/services/import.service.js.map +1 -1
- package/dist/services/proxy-token-manager.js +2 -13
- package/dist/services/proxy-token-manager.js.map +1 -1
- package/dist/services/runtime-credential-proxy.service.d.ts +9 -0
- package/dist/services/runtime-credential-proxy.service.js +29 -0
- package/dist/services/runtime-credential-proxy.service.js.map +1 -0
- package/dist/services/url.service.d.ts +1 -0
- package/dist/services/url.service.js +3 -0
- package/dist/services/url.service.js.map +1 -1
- package/dist/telemetry/index.d.ts +4 -1
- package/dist/telemetry/index.js +16 -8
- package/dist/telemetry/index.js.map +1 -1
- package/dist/utils.d.ts +2 -1
- package/dist/utils.js +10 -0
- package/dist/utils.js.map +1 -1
- package/dist/webhooks/live-webhooks.js +2 -2
- package/dist/webhooks/live-webhooks.js.map +1 -1
- package/dist/webhooks/webhook-helpers.js +1 -1
- package/dist/webhooks/webhook-helpers.js.map +1 -1
- package/dist/workflow-execute-additional-data.d.ts +3 -1
- package/dist/workflow-execute-additional-data.js +26 -3
- package/dist/workflow-execute-additional-data.js.map +1 -1
- package/dist/workflow-helpers.d.ts +3 -1
- package/dist/workflow-helpers.js +39 -5
- package/dist/workflow-helpers.js.map +1 -1
- package/dist/workflow-hook-context.service.d.ts +6 -0
- package/dist/workflow-hook-context.service.js +32 -0
- package/dist/workflow-hook-context.service.js.map +1 -0
- package/dist/workflow-runner.js +2 -1
- package/dist/workflow-runner.js.map +1 -1
- package/dist/workflows/utils.d.ts +3 -0
- package/dist/workflows/utils.js +19 -0
- package/dist/workflows/utils.js.map +1 -1
- package/dist/workflows/workflow-creation.service.js +4 -2
- package/dist/workflows/workflow-creation.service.js.map +1 -1
- package/dist/workflows/workflow-execution.service.d.ts +4 -3
- package/dist/workflows/workflow-execution.service.js +8 -3
- package/dist/workflows/workflow-execution.service.js.map +1 -1
- package/dist/workflows/workflow-finder.service.d.ts +6 -2
- package/dist/workflows/workflow-finder.service.js +18 -0
- package/dist/workflows/workflow-finder.service.js.map +1 -1
- package/dist/workflows/workflow-history/workflow-history.controller.d.ts +1 -1
- package/dist/workflows/workflow-history/workflow-history.service.d.ts +2 -1
- package/dist/workflows/workflow-history/workflow-history.service.js +1 -0
- package/dist/workflows/workflow-history/workflow-history.service.js.map +1 -1
- package/dist/workflows/workflow-validation.service.d.ts +3 -1
- package/dist/workflows/workflow-validation.service.js +6 -3
- package/dist/workflows/workflow-validation.service.js.map +1 -1
- package/dist/workflows/workflow.service.d.ts +3 -3
- package/dist/workflows/workflow.service.js +26 -4
- package/dist/workflows/workflow.service.js.map +1 -1
- package/dist/workflows/workflows.controller.d.ts +31 -21
- package/dist/workflows/workflows.controller.js +6 -2
- package/dist/workflows/workflows.controller.js.map +1 -1
- package/package.json +36 -34
- package/dist/modules/agents/entities/agent-published-version.entity.js.map +0 -1
- package/dist/modules/agents/repositories/agent-published-version.repository.d.ts +0 -20
- package/dist/modules/agents/repositories/agent-published-version.repository.js.map +0 -1
- package/dist/modules/inbound-secrets/inbound-secrets-context-hook.js.map +0 -1
- package/dist/modules/inbound-secrets/inbound-secrets.config.d.ts +0 -3
- package/dist/modules/inbound-secrets/inbound-secrets.config.js.map +0 -1
- package/dist/modules/inbound-secrets/inbound-secrets.module.js.map +0 -1
- package/dist/modules/inbound-secrets/inbound-secrets.schemas.d.ts +0 -3
- package/dist/modules/inbound-secrets/inbound-secrets.schemas.js +0 -6
- package/dist/modules/inbound-secrets/inbound-secrets.schemas.js.map +0 -1
- package/dist/modules/inbound-secrets/inbound-secrets.service.d.ts +0 -17
- package/dist/modules/inbound-secrets/inbound-secrets.service.js.map +0 -1
- package/dist/modules/inbound-secrets/path-traversal.js.map +0 -1
- package/dist/modules/instance-ai/compaction.service.d.ts +0 -24
- package/dist/modules/instance-ai/compaction.service.js +0 -213
- package/dist/modules/instance-ai/compaction.service.js.map +0 -1
- package/dist/modules/instance-ai/entities/instance-ai-observational-memory.entity.d.ts +0 -33
- package/dist/modules/instance-ai/entities/instance-ai-observational-memory.entity.js +0 -145
- package/dist/modules/instance-ai/entities/instance-ai-observational-memory.entity.js.map +0 -1
- package/dist/modules/instance-ai/entities/instance-ai-workflow-snapshot.entity.d.ts +0 -8
- package/dist/modules/instance-ai/entities/instance-ai-workflow-snapshot.entity.js.map +0 -1
- package/dist/modules/instance-ai/repositories/instance-ai-observational-memory.repository.d.ts +0 -5
- package/dist/modules/instance-ai/repositories/instance-ai-observational-memory.repository.js.map +0 -1
- package/dist/modules/instance-ai/repositories/instance-ai-workflow-snapshot.repository.d.ts +0 -5
- package/dist/modules/instance-ai/repositories/instance-ai-workflow-snapshot.repository.js.map +0 -1
- package/dist/modules/instance-ai/snapshot-pruning.service.d.ts +0 -17
- package/dist/modules/instance-ai/snapshot-pruning.service.js +0 -89
- package/dist/modules/instance-ai/snapshot-pruning.service.js.map +0 -1
- package/dist/modules/instance-ai/storage/typeorm-composite-store.d.ts +0 -9
- package/dist/modules/instance-ai/storage/typeorm-composite-store.js +0 -33
- package/dist/modules/instance-ai/storage/typeorm-composite-store.js.map +0 -1
- package/dist/modules/instance-ai/storage/typeorm-memory-storage.d.ts +0 -96
- package/dist/modules/instance-ai/storage/typeorm-memory-storage.js +0 -864
- package/dist/modules/instance-ai/storage/typeorm-memory-storage.js.map +0 -1
- package/dist/modules/instance-ai/storage/typeorm-workflows-storage.d.ts +0 -44
- package/dist/modules/instance-ai/storage/typeorm-workflows-storage.js +0 -156
- package/dist/modules/instance-ai/storage/typeorm-workflows-storage.js.map +0 -1
- package/dist/scaling/multi-main-setup-legacy.d.ts +0 -25
- package/dist/scaling/multi-main-setup-legacy.js +0 -75
- package/dist/scaling/multi-main-setup-legacy.js.map +0 -1
- package/dist/scaling/multi-main-setup-v2.d.ts +0 -25
- package/dist/scaling/multi-main-setup-v2.js +0 -143
- package/dist/scaling/multi-main-setup-v2.js.map +0 -1
- package/dist/scaling/multi-main-setup.types.d.ts +0 -6
- package/dist/scaling/multi-main-setup.types.js.map +0 -1
- /package/dist/modules/{inbound-secrets → runtime-credentials}/path-traversal.d.ts +0 -0
- /package/dist/modules/{inbound-secrets → runtime-credentials}/path-traversal.js +0 -0
|
@@ -46,11 +46,11 @@ exports.InstanceAiService = void 0;
|
|
|
46
46
|
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
|
+
const decorators_1 = require("@n8n/decorators");
|
|
49
50
|
const n8n_core_1 = require("n8n-core");
|
|
50
51
|
const ssrf_protection_service_1 = require("../../services/ssrf/ssrf-protection.service");
|
|
51
52
|
const db_1 = require("@n8n/db");
|
|
52
53
|
const di_1 = require("@n8n/di");
|
|
53
|
-
const permissions_1 = require("@n8n/permissions");
|
|
54
54
|
const url_service_1 = require("../../services/url.service");
|
|
55
55
|
const instance_ai_1 = require("@n8n/instance-ai");
|
|
56
56
|
const workflow_sdk_1 = require("@n8n/workflow-sdk");
|
|
@@ -68,10 +68,10 @@ const filesystem_1 = require("./filesystem");
|
|
|
68
68
|
const instance_ai_settings_service_1 = require("./instance-ai-settings.service");
|
|
69
69
|
const instance_ai_adapter_service_1 = require("./instance-ai.adapter.service");
|
|
70
70
|
const internal_messages_1 = require("./internal-messages");
|
|
71
|
-
const typeorm_composite_store_1 = require("./storage/typeorm-composite-store");
|
|
72
71
|
const db_snapshot_storage_1 = require("./storage/db-snapshot-storage");
|
|
73
72
|
const db_iteration_log_storage_1 = require("./storage/db-iteration-log-storage");
|
|
74
|
-
const
|
|
73
|
+
const typeorm_agent_checkpoint_store_1 = require("./storage/typeorm-agent-checkpoint-store");
|
|
74
|
+
const typeorm_agent_memory_1 = require("./storage/typeorm-agent-memory");
|
|
75
75
|
const proxy_token_manager_1 = require("../../services/proxy-token-manager");
|
|
76
76
|
const instance_ai_thread_repository_1 = require("./repositories/instance-ai-thread.repository");
|
|
77
77
|
const trace_replay_state_1 = require("./trace-replay-state");
|
|
@@ -80,7 +80,89 @@ const run_trace_metadata_1 = require("./run-trace-metadata");
|
|
|
80
80
|
function getErrorMessage(error) {
|
|
81
81
|
return error instanceof Error ? error.message : String(error);
|
|
82
82
|
}
|
|
83
|
+
function isTelemetryConfigurableAgent(agent) {
|
|
84
|
+
return (typeof agent === 'object' &&
|
|
85
|
+
agent !== null &&
|
|
86
|
+
typeof Reflect.get(agent, 'telemetry') === 'function');
|
|
87
|
+
}
|
|
88
|
+
const INSTANCE_AI_CHECKPOINT_PRUNE_RETRY_MS = 30 * 1000;
|
|
89
|
+
function isTextMessagePart(part) {
|
|
90
|
+
return (typeof part === 'object' &&
|
|
91
|
+
part !== null &&
|
|
92
|
+
'type' in part &&
|
|
93
|
+
part.type === 'text' &&
|
|
94
|
+
'text' in part &&
|
|
95
|
+
typeof part.text === 'string');
|
|
96
|
+
}
|
|
83
97
|
const ORCHESTRATOR_AGENT_ID = 'agent-001';
|
|
98
|
+
const SANDBOX_NAME_MAX_LEN = 63;
|
|
99
|
+
const SANDBOX_LABEL_MAX_LEN = 63;
|
|
100
|
+
const NAME_PREFIX_SLUG_MAX_LEN = 24;
|
|
101
|
+
const SHORT_RUN_ID_LEN = 8;
|
|
102
|
+
const DEFAULT_SANDBOX_TTL_MS = 15 * 60 * 1000;
|
|
103
|
+
function slugifySandboxName(value, maxLen) {
|
|
104
|
+
const slug = value
|
|
105
|
+
.toLowerCase()
|
|
106
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
107
|
+
.replace(/^-+|-+$/g, '');
|
|
108
|
+
return slug.slice(0, maxLen).replace(/-+$/, '');
|
|
109
|
+
}
|
|
110
|
+
function slugifySandboxLabel(value, maxLen) {
|
|
111
|
+
return value
|
|
112
|
+
.replace(/[^A-Za-z0-9_.-]+/g, '-')
|
|
113
|
+
.replace(/^[-.]+|[-.]+$/g, '')
|
|
114
|
+
.slice(0, maxLen)
|
|
115
|
+
.replace(/[-.]+$/, '');
|
|
116
|
+
}
|
|
117
|
+
function getThreadScopedSandboxName(threadId) {
|
|
118
|
+
return `instance-ai-thread-${threadId}`;
|
|
119
|
+
}
|
|
120
|
+
function buildThreadScopedSandboxName(threadId, namePrefix, runId) {
|
|
121
|
+
const parts = [];
|
|
122
|
+
if (namePrefix) {
|
|
123
|
+
const prefixSlug = slugifySandboxName(namePrefix, NAME_PREFIX_SLUG_MAX_LEN);
|
|
124
|
+
if (prefixSlug)
|
|
125
|
+
parts.push(prefixSlug);
|
|
126
|
+
}
|
|
127
|
+
if (runId) {
|
|
128
|
+
const runSlug = slugifySandboxName(runId, SHORT_RUN_ID_LEN);
|
|
129
|
+
if (runSlug)
|
|
130
|
+
parts.push(runSlug);
|
|
131
|
+
}
|
|
132
|
+
const threadSlug = slugifySandboxName(getThreadScopedSandboxName(threadId), SANDBOX_NAME_MAX_LEN);
|
|
133
|
+
if (threadSlug)
|
|
134
|
+
parts.push(threadSlug);
|
|
135
|
+
const name = slugifySandboxName(parts.join('-'), SANDBOX_NAME_MAX_LEN);
|
|
136
|
+
if (!name)
|
|
137
|
+
throw new n8n_workflow_1.UnexpectedError('Failed to build thread-scoped sandbox name');
|
|
138
|
+
return name;
|
|
139
|
+
}
|
|
140
|
+
function buildThreadScopedSandboxLabels(threadId, namePrefix, runId) {
|
|
141
|
+
const baseName = getThreadScopedSandboxName(threadId);
|
|
142
|
+
const labels = {
|
|
143
|
+
'n8n-builder': slugifySandboxLabel(baseName, SANDBOX_LABEL_MAX_LEN),
|
|
144
|
+
thread_id: slugifySandboxLabel(threadId, SANDBOX_LABEL_MAX_LEN),
|
|
145
|
+
};
|
|
146
|
+
if (namePrefix)
|
|
147
|
+
labels.name_prefix = slugifySandboxLabel(namePrefix, SANDBOX_LABEL_MAX_LEN);
|
|
148
|
+
if (runId)
|
|
149
|
+
labels.run_id = slugifySandboxLabel(runId, SANDBOX_LABEL_MAX_LEN);
|
|
150
|
+
return labels;
|
|
151
|
+
}
|
|
152
|
+
function withThreadScopedSandboxIdentity(config, threadId, runId) {
|
|
153
|
+
if (!config.enabled || config.provider !== 'daytona')
|
|
154
|
+
return config;
|
|
155
|
+
const name = buildThreadScopedSandboxName(threadId, config.namePrefix, runId);
|
|
156
|
+
return {
|
|
157
|
+
...config,
|
|
158
|
+
id: name,
|
|
159
|
+
name,
|
|
160
|
+
labels: {
|
|
161
|
+
...buildThreadScopedSandboxLabels(threadId, config.namePrefix, runId),
|
|
162
|
+
...config.labels,
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
84
166
|
function getUserFacingErrorMessage(error) {
|
|
85
167
|
if (error instanceof n8n_workflow_1.UserError) {
|
|
86
168
|
return error.message;
|
|
@@ -149,9 +231,6 @@ function getAbortReason(signal) {
|
|
|
149
231
|
}
|
|
150
232
|
const INSTANCE_AI_FEEDBACK_NAMESPACE = 'c5be4c87-5b6e-49ed-afe1-9c5c1f99a5c0';
|
|
151
233
|
const MAX_CONCURRENT_BACKGROUND_TASKS_PER_THREAD = 5;
|
|
152
|
-
function estimateTokens(text) {
|
|
153
|
-
return Math.ceil(text.length / 4);
|
|
154
|
-
}
|
|
155
234
|
function stringifyForContextValue(value) {
|
|
156
235
|
if (typeof value === 'string')
|
|
157
236
|
return value;
|
|
@@ -220,6 +299,8 @@ function toConfirmationData(request) {
|
|
|
220
299
|
return { approved: true, domainAccessAction: request.domainAccessAction };
|
|
221
300
|
case 'domainAccessDeny':
|
|
222
301
|
return { approved: false };
|
|
302
|
+
case 'planDeny':
|
|
303
|
+
return { approved: false, denied: true };
|
|
223
304
|
case 'questions':
|
|
224
305
|
return { approved: true, answers: request.answers };
|
|
225
306
|
case 'credentialSelection':
|
|
@@ -244,12 +325,19 @@ function toConfirmationData(request) {
|
|
|
244
325
|
}
|
|
245
326
|
}
|
|
246
327
|
let InstanceAiService = class InstanceAiService {
|
|
247
|
-
|
|
328
|
+
get mcpClientManager() {
|
|
329
|
+
if (!this._mcpClientManager) {
|
|
330
|
+
this._mcpClientManager = new instance_ai_1.McpClientManager(this._ssrfProtectionConfig.enabled ? this._ssrfProtectionService : undefined);
|
|
331
|
+
}
|
|
332
|
+
return this._mcpClientManager;
|
|
333
|
+
}
|
|
334
|
+
constructor(logger, globalConfig, instanceSettings, adapterService, eventBus, settingsService, agentMemory, checkpointStore, aiService, push, threadRepo, urlService, dbSnapshotStorage, dbIterationLogStorage, sourceControlPreferencesService, telemetry, userRepository, aiBuilderTemporaryWorkflowRepository, errorReporter, ssrfProtectionConfig, ssrfProtectionService, eventService) {
|
|
335
|
+
this.instanceSettings = instanceSettings;
|
|
248
336
|
this.adapterService = adapterService;
|
|
249
337
|
this.eventBus = eventBus;
|
|
250
338
|
this.settingsService = settingsService;
|
|
251
|
-
this.
|
|
252
|
-
this.
|
|
339
|
+
this.agentMemory = agentMemory;
|
|
340
|
+
this.checkpointStore = checkpointStore;
|
|
253
341
|
this.aiService = aiService;
|
|
254
342
|
this.push = push;
|
|
255
343
|
this.threadRepo = threadRepo;
|
|
@@ -266,6 +354,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
266
354
|
this.backgroundTasks = new instance_ai_1.BackgroundTaskManager(MAX_CONCURRENT_BACKGROUND_TASKS_PER_THREAD);
|
|
267
355
|
this.traceContextsByRunId = new Map();
|
|
268
356
|
this.sandboxes = new Map();
|
|
357
|
+
this.sandboxCreations = new Map();
|
|
269
358
|
this.gatewayRegistry = new filesystem_1.LocalGatewayRegistry();
|
|
270
359
|
this.domainAccessTrackersByThread = new Map();
|
|
271
360
|
this.threadPushRef = new Map();
|
|
@@ -274,6 +363,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
274
363
|
this.pendingTerminalOutcomes = new Map();
|
|
275
364
|
this.creditedThreads = new Set();
|
|
276
365
|
this.traceReplay = new trace_replay_state_1.TraceReplayState();
|
|
366
|
+
this.checkpointPruningStopped = true;
|
|
277
367
|
this.logger = logger.scoped('instance-ai');
|
|
278
368
|
this.instanceAiConfig = globalConfig.instanceAi;
|
|
279
369
|
const livenessPolicyConfig = (0, instance_ai_1.createInstanceAiLivenessPolicyConfig)({
|
|
@@ -290,26 +380,30 @@ let InstanceAiService = class InstanceAiService {
|
|
|
290
380
|
void this.finalizeCancelledSuspendedRun(suspended, reason);
|
|
291
381
|
},
|
|
292
382
|
});
|
|
293
|
-
this.builderSandboxSessions = new instance_ai_1.BuilderSandboxSessionRegistry(this.instanceAiConfig.builderSandboxTtlMs);
|
|
294
383
|
this.defaultTimeZone = globalConfig.generic.timezone;
|
|
295
384
|
const restEndpoint = globalConfig.endpoints.rest;
|
|
296
385
|
this.oauth2CallbackUrl = `${this.urlService.getInstanceBaseUrl()}/${restEndpoint}/oauth2-credential/callback`;
|
|
297
386
|
this.webhookBaseUrl = `${this.urlService.getWebhookBaseUrl()}${globalConfig.endpoints.webhook}`;
|
|
298
387
|
this.formBaseUrl = `${this.urlService.getWebhookBaseUrl()}${globalConfig.endpoints.form}`;
|
|
299
|
-
this.
|
|
388
|
+
this._ssrfProtectionConfig = ssrfProtectionConfig;
|
|
389
|
+
this._ssrfProtectionService = ssrfProtectionService;
|
|
300
390
|
this.eventService.on('instance-ai-settings-updated', ({ mcpSettingsChanged }) => {
|
|
301
391
|
if (!mcpSettingsChanged)
|
|
302
392
|
return;
|
|
303
|
-
this.
|
|
393
|
+
if (!this._mcpClientManager)
|
|
394
|
+
return;
|
|
395
|
+
this._mcpClientManager.disconnect().catch((error) => {
|
|
304
396
|
this.logger.warn('Failed to disconnect MCP clients after settings change', {
|
|
305
397
|
error: getErrorMessage(error),
|
|
306
398
|
});
|
|
307
399
|
});
|
|
308
400
|
});
|
|
309
401
|
this.liveness.start();
|
|
402
|
+
if (this.instanceSettings.isLeader)
|
|
403
|
+
this.startCheckpointPruning();
|
|
310
404
|
}
|
|
311
405
|
getSandboxConfigFromEnv() {
|
|
312
|
-
const { sandboxEnabled, sandboxProvider, daytonaApiUrl, daytonaApiKey, n8nSandboxServiceUrl, n8nSandboxServiceApiKey, sandboxImage, sandboxTimeout, } = this.instanceAiConfig;
|
|
406
|
+
const { sandboxEnabled, sandboxProvider, daytonaApiUrl, daytonaApiKey, n8nSandboxServiceUrl, n8nSandboxServiceApiKey, sandboxImage, sandboxTimeout, sandboxNamePrefix, daytonaTokenRefreshSkewMs, } = this.instanceAiConfig;
|
|
313
407
|
if (!sandboxEnabled) {
|
|
314
408
|
return {
|
|
315
409
|
enabled: false,
|
|
@@ -330,6 +424,8 @@ let InstanceAiService = class InstanceAiService {
|
|
|
330
424
|
image: sandboxImage || undefined,
|
|
331
425
|
n8nVersion: constants_1.N8N_VERSION || undefined,
|
|
332
426
|
timeout: sandboxTimeout,
|
|
427
|
+
namePrefix: sandboxNamePrefix || undefined,
|
|
428
|
+
refreshSkewMs: daytonaTokenRefreshSkewMs,
|
|
333
429
|
};
|
|
334
430
|
}
|
|
335
431
|
if (sandboxProvider === 'n8n-sandbox') {
|
|
@@ -359,6 +455,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
359
455
|
...base,
|
|
360
456
|
daytonaApiUrl: client.getSandboxProxyBaseUrl(),
|
|
361
457
|
image: proxyConfig.image,
|
|
458
|
+
logger: this.logger,
|
|
362
459
|
getAuthToken: async () => {
|
|
363
460
|
const token = await client.getBuilderApiProxyToken({ id: user.id }, { userMessageId: (0, nanoid_1.nanoid)() });
|
|
364
461
|
return token.accessToken;
|
|
@@ -382,47 +479,152 @@ let InstanceAiService = class InstanceAiService {
|
|
|
382
479
|
}
|
|
383
480
|
return base;
|
|
384
481
|
}
|
|
385
|
-
async
|
|
386
|
-
const
|
|
387
|
-
if (
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
482
|
+
async getOrCreateWorkspaceEntry(threadId, user, runId) {
|
|
483
|
+
const existing = this.sandboxes.get(threadId);
|
|
484
|
+
if (existing) {
|
|
485
|
+
if (this.isSandboxEntryExpired(existing) && !this.isSandboxInUse(threadId)) {
|
|
486
|
+
this.evictSandboxEntry(threadId, existing);
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
this.touchSandboxEntry(threadId, existing);
|
|
490
|
+
return existing;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
const pending = this.sandboxCreations.get(threadId);
|
|
494
|
+
if (pending)
|
|
495
|
+
return await pending;
|
|
496
|
+
const creation = this.createWorkspaceEntry(threadId, user, runId);
|
|
497
|
+
this.sandboxCreations.set(threadId, creation);
|
|
498
|
+
try {
|
|
499
|
+
return await creation;
|
|
500
|
+
}
|
|
501
|
+
finally {
|
|
502
|
+
this.sandboxCreations.delete(threadId);
|
|
391
503
|
}
|
|
392
|
-
return new instance_ai_1.BuilderSandboxFactory(config, undefined, this.logger);
|
|
393
504
|
}
|
|
394
|
-
async getOrCreateWorkspace(threadId, user) {
|
|
395
|
-
const
|
|
396
|
-
if (
|
|
397
|
-
|
|
398
|
-
|
|
505
|
+
async getOrCreateWorkspace(threadId, user, context, runId) {
|
|
506
|
+
const entry = await this.getOrCreateWorkspaceEntry(threadId, user, runId);
|
|
507
|
+
if (entry)
|
|
508
|
+
await this.ensureWorkspaceSetup(entry, context);
|
|
509
|
+
return entry;
|
|
510
|
+
}
|
|
511
|
+
async ensureWorkspaceSetup(entry, context) {
|
|
512
|
+
if (entry.setupComplete)
|
|
513
|
+
return;
|
|
514
|
+
entry.setupPromise ??= (0, instance_ai_1.setupSandboxWorkspace)(entry.workspace, context)
|
|
515
|
+
.then(() => {
|
|
516
|
+
entry.setupComplete = true;
|
|
517
|
+
})
|
|
518
|
+
.finally(() => {
|
|
519
|
+
entry.setupPromise = undefined;
|
|
520
|
+
});
|
|
521
|
+
await entry.setupPromise;
|
|
522
|
+
}
|
|
523
|
+
async createWorkspaceEntry(threadId, user, runId) {
|
|
524
|
+
const config = withThreadScopedSandboxIdentity(await this.resolveSandboxConfig(user), threadId, runId);
|
|
399
525
|
if (!config.enabled)
|
|
400
526
|
return undefined;
|
|
401
|
-
const sandbox = await (0, instance_ai_1.createSandbox)(config
|
|
527
|
+
const sandbox = await (0, instance_ai_1.createSandbox)(config, {
|
|
528
|
+
logger: this.logger,
|
|
529
|
+
errorReporter: this.errorReporter,
|
|
530
|
+
useSnapshotFallback: true,
|
|
531
|
+
});
|
|
402
532
|
const workspace = (0, instance_ai_1.createWorkspace)(sandbox);
|
|
403
533
|
if (!sandbox || !workspace)
|
|
404
534
|
return undefined;
|
|
405
|
-
|
|
535
|
+
try {
|
|
536
|
+
await workspace.init();
|
|
537
|
+
}
|
|
538
|
+
catch (error) {
|
|
539
|
+
try {
|
|
540
|
+
await workspace.destroy();
|
|
541
|
+
}
|
|
542
|
+
catch {
|
|
543
|
+
}
|
|
544
|
+
throw error;
|
|
545
|
+
}
|
|
546
|
+
const entry = {
|
|
547
|
+
sandbox,
|
|
548
|
+
workspace,
|
|
549
|
+
setupComplete: false,
|
|
550
|
+
setupPromise: undefined,
|
|
551
|
+
expiresAt: this.nextSandboxExpiry(),
|
|
552
|
+
};
|
|
406
553
|
this.sandboxes.set(threadId, entry);
|
|
554
|
+
this.scheduleSandboxExpiry(threadId, entry);
|
|
407
555
|
return entry;
|
|
408
556
|
}
|
|
409
|
-
|
|
557
|
+
evictSandboxEntry(threadId, entry) {
|
|
558
|
+
if (this.sandboxes.get(threadId) !== entry)
|
|
559
|
+
return;
|
|
560
|
+
this.sandboxes.delete(threadId);
|
|
561
|
+
if (entry.cleanupTimer) {
|
|
562
|
+
clearTimeout(entry.cleanupTimer);
|
|
563
|
+
entry.cleanupTimer = undefined;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
async destroySandbox(threadId, reason = 'thread_cleanup') {
|
|
410
567
|
const entry = this.sandboxes.get(threadId);
|
|
411
568
|
if (!entry?.sandbox)
|
|
412
569
|
return;
|
|
413
|
-
this.
|
|
570
|
+
this.evictSandboxEntry(threadId, entry);
|
|
414
571
|
try {
|
|
415
|
-
|
|
416
|
-
await entry.sandbox.destroy();
|
|
417
|
-
}
|
|
572
|
+
await entry.workspace?.destroy();
|
|
418
573
|
}
|
|
419
574
|
catch (error) {
|
|
420
575
|
this.logger.warn('Failed to destroy sandbox', {
|
|
421
576
|
threadId,
|
|
577
|
+
reason,
|
|
422
578
|
error: error instanceof Error ? error.message : String(error),
|
|
423
579
|
});
|
|
424
580
|
}
|
|
425
581
|
}
|
|
582
|
+
get sandboxTtlMs() {
|
|
583
|
+
return this.instanceAiConfig?.builderSandboxTtlMs ?? DEFAULT_SANDBOX_TTL_MS;
|
|
584
|
+
}
|
|
585
|
+
nextSandboxExpiry() {
|
|
586
|
+
return Date.now() + this.sandboxTtlMs;
|
|
587
|
+
}
|
|
588
|
+
isSandboxEntryExpired(entry) {
|
|
589
|
+
return this.sandboxTtlMs > 0 && entry.expiresAt <= Date.now();
|
|
590
|
+
}
|
|
591
|
+
touchSandboxEntry(threadId, entry) {
|
|
592
|
+
if (this.sandboxTtlMs <= 0)
|
|
593
|
+
return;
|
|
594
|
+
entry.expiresAt = this.nextSandboxExpiry();
|
|
595
|
+
this.scheduleSandboxExpiry(threadId, entry);
|
|
596
|
+
}
|
|
597
|
+
isSandboxInUse(threadId) {
|
|
598
|
+
return Boolean(this.runState.getActiveRunId(threadId) ||
|
|
599
|
+
this.runState.hasSuspendedRun(threadId) ||
|
|
600
|
+
this.backgroundTasks.getRunningTasks(threadId).length > 0);
|
|
601
|
+
}
|
|
602
|
+
scheduleSandboxExpiry(threadId, entry) {
|
|
603
|
+
if (this.sandboxTtlMs <= 0)
|
|
604
|
+
return;
|
|
605
|
+
if (entry.cleanupTimer)
|
|
606
|
+
clearTimeout(entry.cleanupTimer);
|
|
607
|
+
const delay = Math.max(0, entry.expiresAt - Date.now());
|
|
608
|
+
entry.cleanupTimer = setTimeout(() => {
|
|
609
|
+
const current = this.sandboxes.get(threadId);
|
|
610
|
+
if (current !== entry)
|
|
611
|
+
return;
|
|
612
|
+
if (this.isSandboxInUse(threadId)) {
|
|
613
|
+
this.touchSandboxEntry(threadId, entry);
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
this.evictSandboxEntry(threadId, entry);
|
|
617
|
+
}, delay);
|
|
618
|
+
entry.cleanupTimer.unref();
|
|
619
|
+
}
|
|
620
|
+
stopSandboxExpiryTimers() {
|
|
621
|
+
for (const entry of this.sandboxes.values()) {
|
|
622
|
+
if (!entry.cleanupTimer)
|
|
623
|
+
continue;
|
|
624
|
+
clearTimeout(entry.cleanupTimer);
|
|
625
|
+
entry.cleanupTimer = undefined;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
426
628
|
async getProxyAuth(user) {
|
|
427
629
|
const client = await this.aiService.getClient();
|
|
428
630
|
const token = await client.getBuilderApiProxyToken({ id: user.id }, { userMessageId: (0, nanoid_1.nanoid)() });
|
|
@@ -446,7 +648,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
446
648
|
return await this.settingsService.resolveModelConfig(user);
|
|
447
649
|
}
|
|
448
650
|
async resolveProxyModel(user, proxyBaseUrl, tokenManager) {
|
|
449
|
-
const modelName =
|
|
651
|
+
const modelName = this.settingsService.resolveModelName(user);
|
|
450
652
|
const { createAnthropic } = await Promise.resolve().then(() => __importStar(require('@ai-sdk/anthropic')));
|
|
451
653
|
const provider = createAnthropic({
|
|
452
654
|
baseURL: proxyBaseUrl + '/anthropic/v1',
|
|
@@ -561,6 +763,42 @@ let InstanceAiService = class InstanceAiService {
|
|
|
561
763
|
getTraceContext(runId) {
|
|
562
764
|
return this.traceContextsByRunId.get(runId)?.tracing;
|
|
563
765
|
}
|
|
766
|
+
getTraceContextForContinuation(threadId, messageGroupId) {
|
|
767
|
+
const entries = [...this.traceContextsByRunId.values()].reverse();
|
|
768
|
+
const sameGroup = messageGroupId === undefined
|
|
769
|
+
? undefined
|
|
770
|
+
: entries.find((entry) => entry.threadId === threadId && entry.messageGroupId === messageGroupId)?.tracing;
|
|
771
|
+
return sameGroup ?? entries.find((entry) => entry.threadId === threadId)?.tracing;
|
|
772
|
+
}
|
|
773
|
+
async createOrchestratorResumeTraceContext(options) {
|
|
774
|
+
const baseTracing = options.baseTracing ??
|
|
775
|
+
this.getTraceContextForContinuation(options.threadId, options.messageGroupId);
|
|
776
|
+
if (!baseTracing)
|
|
777
|
+
return undefined;
|
|
778
|
+
const tracing = await (0, instance_ai_1.continueInstanceAiTraceContext)(baseTracing, {
|
|
779
|
+
threadId: options.threadId,
|
|
780
|
+
messageId: options.messageId,
|
|
781
|
+
messageGroupId: options.messageGroupId,
|
|
782
|
+
runId: options.runId,
|
|
783
|
+
userId: options.userId,
|
|
784
|
+
modelId: options.modelId,
|
|
785
|
+
input: options.input,
|
|
786
|
+
proxyConfig: options.proxyConfig ?? baseTracing?.proxyConfig,
|
|
787
|
+
metadata: {
|
|
788
|
+
resume_reason: options.resumeReason,
|
|
789
|
+
agent_id: ORCHESTRATOR_AGENT_ID,
|
|
790
|
+
...options.metadata,
|
|
791
|
+
},
|
|
792
|
+
n8nVersion: constants_1.N8N_VERSION,
|
|
793
|
+
workflowSdkVersion: constants_1.WORKFLOW_SDK_VERSION,
|
|
794
|
+
});
|
|
795
|
+
if (tracing) {
|
|
796
|
+
await this.configureTraceReplayMode(tracing);
|
|
797
|
+
this.storeTraceContext(options.runId, options.threadId, tracing, options.messageGroupId);
|
|
798
|
+
this.runState.attachTracing(options.threadId, tracing);
|
|
799
|
+
}
|
|
800
|
+
return tracing;
|
|
801
|
+
}
|
|
564
802
|
async configureTraceReplayMode(tracing) {
|
|
565
803
|
await this.traceReplay.configureReplayMode(tracing);
|
|
566
804
|
}
|
|
@@ -645,6 +883,20 @@ let InstanceAiService = class InstanceAiService {
|
|
|
645
883
|
if (!traceContext)
|
|
646
884
|
return;
|
|
647
885
|
try {
|
|
886
|
+
if (traceContext.actorRun.id !== traceContext.rootRun.id &&
|
|
887
|
+
traceContext.actorRun.endTime === undefined) {
|
|
888
|
+
await traceContext.finishRun(traceContext.actorRun, {
|
|
889
|
+
outputs: {
|
|
890
|
+
status: options.status,
|
|
891
|
+
...options.outputs,
|
|
892
|
+
},
|
|
893
|
+
metadata: {
|
|
894
|
+
final_status: options.status,
|
|
895
|
+
...options.metadata,
|
|
896
|
+
},
|
|
897
|
+
...(options.error ? { error: options.error } : {}),
|
|
898
|
+
});
|
|
899
|
+
}
|
|
648
900
|
await traceContext.finishRun(traceContext.rootRun, {
|
|
649
901
|
outputs: {
|
|
650
902
|
status: options.status,
|
|
@@ -671,7 +923,9 @@ let InstanceAiService = class InstanceAiService {
|
|
|
671
923
|
async finalizeRunTracing(runId, tracing, options) {
|
|
672
924
|
if (!tracing)
|
|
673
925
|
return;
|
|
674
|
-
|
|
926
|
+
if (tracing.actorRun.endTime)
|
|
927
|
+
return;
|
|
928
|
+
const outputs = options.outputs ?? {
|
|
675
929
|
status: options.status,
|
|
676
930
|
runId,
|
|
677
931
|
...(options.outputText ? { response: options.outputText } : {}),
|
|
@@ -680,6 +934,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
680
934
|
const metadata = {
|
|
681
935
|
final_status: options.status,
|
|
682
936
|
...(options.modelId !== undefined ? { model_id: options.modelId } : {}),
|
|
937
|
+
...options.metadata,
|
|
683
938
|
};
|
|
684
939
|
try {
|
|
685
940
|
await tracing.finishRun(tracing.actorRun, {
|
|
@@ -855,26 +1110,6 @@ let InstanceAiService = class InstanceAiService {
|
|
|
855
1110
|
void this.handlePlannedTaskSettlement(user, task, 'cancelled');
|
|
856
1111
|
}
|
|
857
1112
|
}
|
|
858
|
-
async revalidateActiveUser(userId) {
|
|
859
|
-
try {
|
|
860
|
-
const user = await this.userRepository.findOne({
|
|
861
|
-
where: { id: userId },
|
|
862
|
-
relations: ['role'],
|
|
863
|
-
});
|
|
864
|
-
if (!user || user.disabled)
|
|
865
|
-
return null;
|
|
866
|
-
if (!(0, permissions_1.hasGlobalScope)(user, 'instanceAi:message'))
|
|
867
|
-
return null;
|
|
868
|
-
return user;
|
|
869
|
-
}
|
|
870
|
-
catch (error) {
|
|
871
|
-
this.logger.warn('Failed to revalidate user', {
|
|
872
|
-
userId,
|
|
873
|
-
error: getErrorMessage(error),
|
|
874
|
-
});
|
|
875
|
-
return null;
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
1113
|
cancelAllBackgroundTasks() {
|
|
879
1114
|
const cancelled = this.backgroundTasks.cancelAll();
|
|
880
1115
|
for (const task of cancelled) {
|
|
@@ -920,20 +1155,16 @@ let InstanceAiService = class InstanceAiService {
|
|
|
920
1155
|
goal: 'Simulate a stuck background task timeout',
|
|
921
1156
|
},
|
|
922
1157
|
});
|
|
923
|
-
|
|
924
|
-
|
|
1158
|
+
await this.agentMemory.saveMessages({
|
|
1159
|
+
threadId,
|
|
1160
|
+
resourceId: user.id,
|
|
925
1161
|
messages: [
|
|
926
1162
|
{
|
|
927
1163
|
id: messageId,
|
|
928
|
-
threadId,
|
|
929
|
-
resourceId: user.id,
|
|
930
|
-
role: 'assistant',
|
|
931
|
-
content: {
|
|
932
|
-
format: 2,
|
|
933
|
-
parts: [{ type: 'text', text: messageText }],
|
|
934
|
-
content: messageText,
|
|
935
|
-
},
|
|
936
1164
|
createdAt: new Date(),
|
|
1165
|
+
type: 'llm',
|
|
1166
|
+
role: 'assistant',
|
|
1167
|
+
content: [{ type: 'text', text: messageText }],
|
|
937
1168
|
},
|
|
938
1169
|
],
|
|
939
1170
|
});
|
|
@@ -1054,6 +1285,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1054
1285
|
this.gatewayRegistry.clearDisconnectTimer(userId);
|
|
1055
1286
|
}
|
|
1056
1287
|
async clearThreadState(threadId) {
|
|
1288
|
+
this.liveness.clearThreadState(threadId);
|
|
1057
1289
|
const { active, suspended } = this.runState.clearThread(threadId);
|
|
1058
1290
|
if (active) {
|
|
1059
1291
|
active.abortController.abort();
|
|
@@ -1080,16 +1312,15 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1080
1312
|
});
|
|
1081
1313
|
this.creditedThreads.delete(threadId);
|
|
1082
1314
|
this.schedulerLocks.delete(threadId);
|
|
1083
|
-
this.liveness.clearThreadState(threadId);
|
|
1084
1315
|
this.domainAccessTrackersByThread.delete(threadId);
|
|
1085
1316
|
this.threadPushRef.delete(threadId);
|
|
1086
1317
|
this.deleteTraceContextsForThread(threadId);
|
|
1087
|
-
await this.builderSandboxSessions.cleanupThread(threadId, 'thread_cleared');
|
|
1088
1318
|
await this.destroySandbox(threadId);
|
|
1089
1319
|
await this.reapAiTemporaryForThreadCleanup(threadId);
|
|
1090
1320
|
this.eventBus.clearThread(threadId);
|
|
1091
1321
|
}
|
|
1092
1322
|
async shutdown() {
|
|
1323
|
+
this.stopCheckpointPruning();
|
|
1093
1324
|
this.liveness.shutdown();
|
|
1094
1325
|
const { activeRuns, suspendedRuns } = this.runState.shutdown();
|
|
1095
1326
|
for (const run of activeRuns) {
|
|
@@ -1119,38 +1350,68 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1119
1350
|
});
|
|
1120
1351
|
}
|
|
1121
1352
|
this.gatewayRegistry.disconnectAll();
|
|
1122
|
-
|
|
1123
|
-
await Promise.allSettled([
|
|
1124
|
-
...sandboxCleanups,
|
|
1125
|
-
this.builderSandboxSessions.cleanupAll('service_shutdown'),
|
|
1126
|
-
]);
|
|
1353
|
+
this.stopSandboxExpiryTimers();
|
|
1127
1354
|
this.domainAccessTrackersByThread.clear();
|
|
1128
1355
|
this.traceContextsByRunId.clear();
|
|
1129
1356
|
this.eventBus.clear();
|
|
1130
|
-
await this.
|
|
1357
|
+
await this._mcpClientManager?.disconnect();
|
|
1131
1358
|
this.logger.debug('Instance AI service shut down');
|
|
1132
1359
|
}
|
|
1133
|
-
|
|
1360
|
+
startCheckpointPruning() {
|
|
1361
|
+
if (this.checkpointPruneTimer || this.instanceAiConfig.snapshotPruneInterval <= 0)
|
|
1362
|
+
return;
|
|
1363
|
+
this.checkpointPruningStopped = false;
|
|
1364
|
+
this.scheduleCheckpointPrune(0);
|
|
1365
|
+
}
|
|
1366
|
+
stopCheckpointPruning() {
|
|
1367
|
+
this.checkpointPruningStopped = true;
|
|
1368
|
+
clearTimeout(this.checkpointPruneTimer);
|
|
1369
|
+
this.checkpointPruneTimer = undefined;
|
|
1370
|
+
}
|
|
1371
|
+
scheduleCheckpointPrune(delayMs = this.instanceAiConfig.snapshotPruneInterval) {
|
|
1372
|
+
if (this.checkpointPruningStopped)
|
|
1373
|
+
return;
|
|
1374
|
+
this.checkpointPruneTimer = setTimeout(() => {
|
|
1375
|
+
void this.pruneStaleCheckpoints();
|
|
1376
|
+
}, delayMs);
|
|
1377
|
+
this.checkpointPruneTimer.unref();
|
|
1378
|
+
}
|
|
1379
|
+
async pruneStaleCheckpoints(now = Date.now()) {
|
|
1380
|
+
const olderThan = new Date(now - this.instanceAiConfig.snapshotRetention);
|
|
1381
|
+
try {
|
|
1382
|
+
const count = await this.checkpointStore.deleteOlderThan(olderThan);
|
|
1383
|
+
if (count > 0) {
|
|
1384
|
+
this.logger.info('Deleted stale Instance AI checkpoints', { count });
|
|
1385
|
+
}
|
|
1386
|
+
else {
|
|
1387
|
+
this.logger.debug('No stale Instance AI checkpoints to delete');
|
|
1388
|
+
}
|
|
1389
|
+
this.scheduleCheckpointPrune();
|
|
1390
|
+
}
|
|
1391
|
+
catch (error) {
|
|
1392
|
+
this.logger.warn('Failed to delete stale Instance AI checkpoints', {
|
|
1393
|
+
error: getErrorMessage(error),
|
|
1394
|
+
});
|
|
1395
|
+
this.scheduleCheckpointPrune(INSTANCE_AI_CHECKPOINT_PRUNE_RETRY_MS);
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
createAgentMemoryOptions() {
|
|
1134
1399
|
return {
|
|
1135
|
-
storage: this.compositeStore,
|
|
1136
|
-
embedderModel: this.instanceAiConfig.embedderModel || undefined,
|
|
1137
1400
|
lastMessages: this.instanceAiConfig.lastMessages,
|
|
1138
|
-
|
|
1401
|
+
observationalMemory: {
|
|
1402
|
+
observerThresholdTokens: this.instanceAiConfig.observerMessageTokens,
|
|
1403
|
+
reflectorThresholdTokens: this.instanceAiConfig.reflectorObservationTokens,
|
|
1404
|
+
},
|
|
1139
1405
|
};
|
|
1140
1406
|
}
|
|
1141
1407
|
async ensureThreadExists(memory, threadId, resourceId) {
|
|
1142
|
-
const existingThread = await memory.
|
|
1408
|
+
const existingThread = await memory.getThread(threadId);
|
|
1143
1409
|
if (existingThread)
|
|
1144
1410
|
return;
|
|
1145
|
-
const now = new Date();
|
|
1146
1411
|
await memory.saveThread({
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
title: '',
|
|
1151
|
-
createdAt: now,
|
|
1152
|
-
updatedAt: now,
|
|
1153
|
-
},
|
|
1412
|
+
id: threadId,
|
|
1413
|
+
resourceId,
|
|
1414
|
+
title: '',
|
|
1154
1415
|
});
|
|
1155
1416
|
}
|
|
1156
1417
|
projectPlannedTaskList(graph) {
|
|
@@ -1210,8 +1471,8 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1210
1471
|
return `<planned-task-follow-up type="${type}">\n${JSON.stringify(payload, null, 2)}\n</planned-task-follow-up>\n\n${internal_messages_1.AUTO_FOLLOW_UP_MESSAGE}`;
|
|
1211
1472
|
}
|
|
1212
1473
|
async createPlannedTaskState() {
|
|
1213
|
-
const memory =
|
|
1214
|
-
const taskStorage = new instance_ai_1.
|
|
1474
|
+
const memory = this.agentMemory;
|
|
1475
|
+
const taskStorage = new instance_ai_1.ThreadTaskStorage(memory);
|
|
1215
1476
|
const plannedTaskStorage = new instance_ai_1.PlannedTaskStorage(memory);
|
|
1216
1477
|
const plannedTaskService = new instance_ai_1.PlannedTaskCoordinator(plannedTaskStorage);
|
|
1217
1478
|
return { memory, taskStorage, plannedTaskService };
|
|
@@ -1279,7 +1540,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1279
1540
|
}
|
|
1280
1541
|
}
|
|
1281
1542
|
createTerminalOutcomeStorage() {
|
|
1282
|
-
this.terminalOutcomeStorage ??= new instance_ai_1.TerminalOutcomeStorage(
|
|
1543
|
+
this.terminalOutcomeStorage ??= new instance_ai_1.TerminalOutcomeStorage(this.agentMemory);
|
|
1283
1544
|
return this.terminalOutcomeStorage;
|
|
1284
1545
|
}
|
|
1285
1546
|
async finishInvalidConfirmationRun(args) {
|
|
@@ -1536,7 +1797,8 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1536
1797
|
}
|
|
1537
1798
|
}
|
|
1538
1799
|
async createExecutionEnvironment(user, threadId, runId, abortSignal, messageGroupId, pushRef) {
|
|
1539
|
-
const
|
|
1800
|
+
const adminSettings = this.settingsService.getAdminSettings();
|
|
1801
|
+
const localGatewayDisabledGlobally = adminSettings.localGatewayDisabled;
|
|
1540
1802
|
const localGatewayDisabledForUser = await this.settingsService.isLocalGatewayDisabledForUser(user.id);
|
|
1541
1803
|
const userGateway = this.gatewayRegistry.findGateway(user.id);
|
|
1542
1804
|
let searchProxyConfig;
|
|
@@ -1609,9 +1871,9 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1609
1871
|
const modelId = proxyBaseUrl && tokenManager
|
|
1610
1872
|
? await this.resolveProxyModel(user, proxyBaseUrl, tokenManager)
|
|
1611
1873
|
: await this.resolveAgentModelConfig(user);
|
|
1612
|
-
const memory =
|
|
1874
|
+
const memory = this.agentMemory;
|
|
1613
1875
|
await this.ensureThreadExists(memory, threadId, user.id);
|
|
1614
|
-
const taskStorage = new instance_ai_1.
|
|
1876
|
+
const taskStorage = new instance_ai_1.ThreadTaskStorage(memory);
|
|
1615
1877
|
const iterationLog = this.dbIterationLogStorage;
|
|
1616
1878
|
const snapshotStorage = this.dbSnapshotStorage;
|
|
1617
1879
|
const workflowLoopStorage = new instance_ai_1.WorkflowLoopStorage(memory);
|
|
@@ -1623,7 +1885,35 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1623
1885
|
(0, workflow_sdk_1.setSchemaBaseDirs)(nodeDefDirs);
|
|
1624
1886
|
}
|
|
1625
1887
|
const domainTools = (0, instance_ai_1.createAllTools)(context);
|
|
1626
|
-
const
|
|
1888
|
+
const baseRuntimeSkills = (0, instance_ai_1.loadInstanceAiRuntimeSkillSource)();
|
|
1889
|
+
let runtimeSkills = baseRuntimeSkills;
|
|
1890
|
+
let runtimeWorkspace;
|
|
1891
|
+
if (adminSettings.sandboxEnabled) {
|
|
1892
|
+
let sandboxEntryPromise;
|
|
1893
|
+
const getSandboxEntry = async () => {
|
|
1894
|
+
sandboxEntryPromise ??= this.getOrCreateWorkspaceEntry(threadId, user, runId).catch((error) => {
|
|
1895
|
+
sandboxEntryPromise = undefined;
|
|
1896
|
+
throw error;
|
|
1897
|
+
});
|
|
1898
|
+
return await sandboxEntryPromise;
|
|
1899
|
+
};
|
|
1900
|
+
const getSetupSandboxEntry = async () => {
|
|
1901
|
+
return await this.getOrCreateWorkspace(threadId, user, context, runId);
|
|
1902
|
+
};
|
|
1903
|
+
runtimeWorkspace = (0, instance_ai_1.createLazyRuntimeWorkspace)({
|
|
1904
|
+
ensureWorkspace: async () => (await getSetupSandboxEntry())?.workspace,
|
|
1905
|
+
});
|
|
1906
|
+
const runtimeSkillWorkspace = (0, instance_ai_1.createLazyRuntimeWorkspace)({
|
|
1907
|
+
id: 'instance-ai-runtime-skill-workspace',
|
|
1908
|
+
name: 'Instance AI runtime skill workspace',
|
|
1909
|
+
ensureWorkspace: async () => (await getSandboxEntry())?.workspace,
|
|
1910
|
+
});
|
|
1911
|
+
runtimeSkills = (0, instance_ai_1.createLazyWorkspaceRuntimeSkillSource)({
|
|
1912
|
+
source: baseRuntimeSkills,
|
|
1913
|
+
workspace: runtimeSkillWorkspace,
|
|
1914
|
+
logger: this.logger,
|
|
1915
|
+
});
|
|
1916
|
+
}
|
|
1627
1917
|
const orchestrationContext = {
|
|
1628
1918
|
threadId,
|
|
1629
1919
|
runId,
|
|
@@ -1631,7 +1921,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1631
1921
|
userId: user.id,
|
|
1632
1922
|
orchestratorAgentId: ORCHESTRATOR_AGENT_ID,
|
|
1633
1923
|
modelId,
|
|
1634
|
-
|
|
1924
|
+
checkpointStore: this.checkpointStore,
|
|
1635
1925
|
subAgentMaxSteps: this.instanceAiConfig.subAgentMaxSteps,
|
|
1636
1926
|
eventBus: this.eventBus,
|
|
1637
1927
|
logger: this.logger,
|
|
@@ -1646,6 +1936,8 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1646
1936
|
? { name: 'chrome-devtools', command: 'npx', args: ['-y', 'chrome-devtools-mcp@latest'] }
|
|
1647
1937
|
: undefined,
|
|
1648
1938
|
localMcpServer: context.localMcpServer,
|
|
1939
|
+
runtimeSkills,
|
|
1940
|
+
runtimeSkillCatalog: baseRuntimeSkills,
|
|
1649
1941
|
oauth2CallbackUrl: this.oauth2CallbackUrl,
|
|
1650
1942
|
webhookBaseUrl: this.webhookBaseUrl,
|
|
1651
1943
|
formBaseUrl: this.formBaseUrl,
|
|
@@ -1672,9 +1964,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1672
1964
|
iterationLog,
|
|
1673
1965
|
sendCorrectionToTask: (taskId, correction) => this.sendCorrectionToTask(threadId, taskId, correction),
|
|
1674
1966
|
workflowTaskService: workflowTasks,
|
|
1675
|
-
workspace:
|
|
1676
|
-
builderSandboxFactory: await this.createBuilderFactory(user),
|
|
1677
|
-
builderSandboxSessionRegistry: this.builderSandboxSessions,
|
|
1967
|
+
workspace: runtimeWorkspace,
|
|
1678
1968
|
nodeDefinitionDirs: nodeDefDirs.length > 0 ? nodeDefDirs : undefined,
|
|
1679
1969
|
domainContext: context,
|
|
1680
1970
|
tracingProxyConfig,
|
|
@@ -1690,7 +1980,6 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1690
1980
|
plannedTaskService,
|
|
1691
1981
|
modelId,
|
|
1692
1982
|
orchestrationContext,
|
|
1693
|
-
sandboxEntry,
|
|
1694
1983
|
};
|
|
1695
1984
|
}
|
|
1696
1985
|
async dispatchPlannedTask(task, context, graph) {
|
|
@@ -1706,21 +1995,6 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1706
1995
|
conversationContext,
|
|
1707
1996
|
});
|
|
1708
1997
|
break;
|
|
1709
|
-
case 'manage-data-tables':
|
|
1710
|
-
started = await (0, instance_ai_1.startDataTableAgentTask)(taskContext, {
|
|
1711
|
-
task: task.spec,
|
|
1712
|
-
plannedTaskId: task.id,
|
|
1713
|
-
conversationContext,
|
|
1714
|
-
});
|
|
1715
|
-
break;
|
|
1716
|
-
case 'research':
|
|
1717
|
-
started = await (0, instance_ai_1.startResearchAgentTask)(taskContext, {
|
|
1718
|
-
goal: task.title,
|
|
1719
|
-
constraints: task.spec,
|
|
1720
|
-
plannedTaskId: task.id,
|
|
1721
|
-
conversationContext,
|
|
1722
|
-
});
|
|
1723
|
-
break;
|
|
1724
1998
|
case 'delegate':
|
|
1725
1999
|
started = await (0, instance_ai_1.startDetachedDelegateTask)(taskContext, {
|
|
1726
2000
|
title: task.title,
|
|
@@ -1823,7 +2097,12 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1823
2097
|
messageGroupId,
|
|
1824
2098
|
});
|
|
1825
2099
|
const timeZone = this.runState.getTimeZone(threadId) ?? this.defaultTimeZone;
|
|
1826
|
-
|
|
2100
|
+
const resumeReason = checkpoint
|
|
2101
|
+
? 'planned_checkpoint'
|
|
2102
|
+
: isReplanFollowUp
|
|
2103
|
+
? 'replan'
|
|
2104
|
+
: 'background_task_completed';
|
|
2105
|
+
void this.executeRun(user, threadId, runId, message, abortController, undefined, messageGroupId, timeZone, isReplanFollowUp, checkpoint, resumeReason);
|
|
1827
2106
|
return runId;
|
|
1828
2107
|
}
|
|
1829
2108
|
async schedulePlannedTasks(user, threadId) {
|
|
@@ -1898,9 +2177,8 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1898
2177
|
}
|
|
1899
2178
|
await this.doSchedulePlannedTasks(activeUser, threadId);
|
|
1900
2179
|
}
|
|
1901
|
-
async executeRun(user, threadId, runId, message, abortController, attachments, messageGroupId, timeZone, isReplanFollowUp = false, checkpoint) {
|
|
2180
|
+
async executeRun(user, threadId, runId, message, abortController, attachments, messageGroupId, timeZone, isReplanFollowUp = false, checkpoint, resumeReason) {
|
|
1902
2181
|
const signal = abortController.signal;
|
|
1903
|
-
let mastraRunId = '';
|
|
1904
2182
|
let tracing;
|
|
1905
2183
|
let messageTraceFinalization;
|
|
1906
2184
|
let aiCreatedWorkflowIds;
|
|
@@ -1949,7 +2227,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1949
2227
|
if (attachments && attachments.length > 0) {
|
|
1950
2228
|
context.currentUserAttachments = attachments;
|
|
1951
2229
|
}
|
|
1952
|
-
const memoryConfig = this.
|
|
2230
|
+
const memoryConfig = this.createAgentMemoryOptions();
|
|
1953
2231
|
const traceInput = {
|
|
1954
2232
|
message,
|
|
1955
2233
|
...(attachments?.length
|
|
@@ -1962,29 +2240,48 @@ let InstanceAiService = class InstanceAiService {
|
|
|
1962
2240
|
: {}),
|
|
1963
2241
|
...(messageGroupId ? { messageGroupId } : {}),
|
|
1964
2242
|
};
|
|
1965
|
-
tracing =
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
2243
|
+
tracing = resumeReason
|
|
2244
|
+
? await this.createOrchestratorResumeTraceContext({
|
|
2245
|
+
threadId,
|
|
2246
|
+
messageId,
|
|
2247
|
+
messageGroupId,
|
|
2248
|
+
runId,
|
|
2249
|
+
userId: user.id,
|
|
2250
|
+
modelId,
|
|
2251
|
+
input: traceInput,
|
|
2252
|
+
proxyConfig: orchestrationContext.tracingProxyConfig,
|
|
2253
|
+
resumeReason,
|
|
2254
|
+
metadata: {
|
|
2255
|
+
...(checkpoint?.isCheckpointFollowUp
|
|
2256
|
+
? { checkpoint_task_id: checkpoint.checkpointTaskId }
|
|
2257
|
+
: {}),
|
|
2258
|
+
},
|
|
2259
|
+
})
|
|
2260
|
+
: await (0, instance_ai_1.createInstanceAiTraceContext)({
|
|
2261
|
+
threadId,
|
|
2262
|
+
messageId,
|
|
2263
|
+
messageGroupId,
|
|
2264
|
+
runId,
|
|
2265
|
+
userId: user.id,
|
|
2266
|
+
modelId,
|
|
2267
|
+
input: traceInput,
|
|
2268
|
+
proxyConfig: orchestrationContext.tracingProxyConfig,
|
|
2269
|
+
n8nVersion: constants_1.N8N_VERSION,
|
|
2270
|
+
workflowSdkVersion: constants_1.WORKFLOW_SDK_VERSION,
|
|
2271
|
+
});
|
|
1977
2272
|
if (!tracing && process.env.E2E_TESTS === 'true') {
|
|
1978
2273
|
const { createTraceReplayOnlyContext } = await Promise.resolve().then(() => __importStar(require('@n8n/instance-ai')));
|
|
1979
2274
|
tracing = createTraceReplayOnlyContext();
|
|
1980
2275
|
}
|
|
1981
2276
|
if (tracing) {
|
|
1982
|
-
await this.configureTraceReplayMode(tracing);
|
|
1983
2277
|
orchestrationContext.tracing = tracing;
|
|
1984
|
-
this.
|
|
1985
|
-
|
|
2278
|
+
if (this.getTraceContext(runId) !== tracing) {
|
|
2279
|
+
await this.configureTraceReplayMode(tracing);
|
|
2280
|
+
this.runState.attachTracing(threadId, tracing);
|
|
2281
|
+
this.storeTraceContext(runId, threadId, tracing, messageGroupId);
|
|
2282
|
+
}
|
|
1986
2283
|
}
|
|
1987
|
-
const thread = await memory.
|
|
2284
|
+
const thread = await memory.getThread(threadId);
|
|
1988
2285
|
if (thread && !thread.title) {
|
|
1989
2286
|
await (0, instance_ai_1.patchThread)(memory, {
|
|
1990
2287
|
threadId,
|
|
@@ -2000,109 +2297,45 @@ let InstanceAiService = class InstanceAiService {
|
|
|
2000
2297
|
payload: { tasks: existingTasks },
|
|
2001
2298
|
});
|
|
2002
2299
|
}
|
|
2003
|
-
const agent = await (0, instance_ai_1.createInstanceAgent)({
|
|
2004
|
-
modelId,
|
|
2005
|
-
context,
|
|
2006
|
-
orchestrationContext,
|
|
2007
|
-
mcpServers,
|
|
2008
|
-
mcpManager: this.mcpClientManager,
|
|
2009
|
-
memoryConfig,
|
|
2010
|
-
memory,
|
|
2011
|
-
disableDeferredTools: true,
|
|
2012
|
-
timeZone: timeZone ?? this.defaultTimeZone,
|
|
2013
|
-
});
|
|
2014
2300
|
const enrichedMessage = await this.buildMessageWithRunningTasks(threadId, message);
|
|
2015
|
-
let
|
|
2301
|
+
let nonStructuredAttachments = [];
|
|
2016
2302
|
let attachmentManifest = '';
|
|
2017
2303
|
let hasParseableAttachment = false;
|
|
2018
2304
|
if (attachments && attachments.length > 0) {
|
|
2019
2305
|
const classifiedAttachments = (0, instance_ai_1.classifyAttachments)(attachments);
|
|
2020
|
-
|
|
2306
|
+
nonStructuredAttachments = attachments.filter((attachment) => !(0, instance_ai_1.isParseableAttachment)(attachment));
|
|
2021
2307
|
hasParseableAttachment = classifiedAttachments.some((attachment) => attachment.parseable);
|
|
2022
2308
|
attachmentManifest = (0, instance_ai_1.buildAttachmentManifest)(classifiedAttachments);
|
|
2023
2309
|
}
|
|
2024
|
-
const
|
|
2310
|
+
const fullMessage = !message && hasParseableAttachment
|
|
2025
2311
|
? `The user attached file(s) without a message. Inspect the first parseable attachment with parse-file and provide a concise summary.\n\n${attachmentManifest}`
|
|
2026
2312
|
: attachmentManifest
|
|
2027
2313
|
? `${enrichedMessage}\n\n${attachmentManifest}`
|
|
2028
2314
|
: enrichedMessage;
|
|
2029
|
-
const messageWithoutSummaryTokens = estimateTokens(messageWithoutSummary);
|
|
2030
|
-
this.eventBus.publish(threadId, {
|
|
2031
|
-
type: 'status',
|
|
2032
|
-
runId,
|
|
2033
|
-
agentId: ORCHESTRATOR_AGENT_ID,
|
|
2034
|
-
payload: { message: 'Recalling conversation...' },
|
|
2035
|
-
});
|
|
2036
|
-
const contextCompactionRun = tracing
|
|
2037
|
-
? await tracing.startChildRun(tracing.actorRun, {
|
|
2038
|
-
name: 'context_compaction',
|
|
2039
|
-
tags: ['context'],
|
|
2040
|
-
metadata: { agent_role: 'context_compaction' },
|
|
2041
|
-
inputs: {
|
|
2042
|
-
threadId,
|
|
2043
|
-
lastMessages: this.instanceAiConfig.lastMessages ?? 20,
|
|
2044
|
-
currentInputTokens: messageWithoutSummaryTokens,
|
|
2045
|
-
},
|
|
2046
|
-
})
|
|
2047
|
-
: undefined;
|
|
2048
|
-
let conversationSummary;
|
|
2049
|
-
try {
|
|
2050
|
-
conversationSummary = await this.compactionService.prepareCompactedContext(threadId, memory, modelId, this.instanceAiConfig.lastMessages ?? 20, 0.8, {
|
|
2051
|
-
label: 'orchestrator-current-input',
|
|
2052
|
-
text: messageWithoutSummary,
|
|
2053
|
-
});
|
|
2054
|
-
if (contextCompactionRun && tracing) {
|
|
2055
|
-
await tracing.finishRun(contextCompactionRun, {
|
|
2056
|
-
outputs: {
|
|
2057
|
-
summarized: Boolean(conversationSummary),
|
|
2058
|
-
summary: conversationSummary ?? '',
|
|
2059
|
-
currentInputTokens: messageWithoutSummaryTokens,
|
|
2060
|
-
},
|
|
2061
|
-
metadata: { final_status: 'completed' },
|
|
2062
|
-
});
|
|
2063
|
-
}
|
|
2064
|
-
}
|
|
2065
|
-
catch (error) {
|
|
2066
|
-
if (contextCompactionRun && tracing) {
|
|
2067
|
-
await tracing.failRun(contextCompactionRun, error, {
|
|
2068
|
-
final_status: 'error',
|
|
2069
|
-
});
|
|
2070
|
-
}
|
|
2071
|
-
throw error;
|
|
2072
|
-
}
|
|
2073
|
-
this.eventBus.publish(threadId, {
|
|
2074
|
-
type: 'status',
|
|
2075
|
-
runId,
|
|
2076
|
-
agentId: ORCHESTRATOR_AGENT_ID,
|
|
2077
|
-
payload: { message: '' },
|
|
2078
|
-
});
|
|
2079
2315
|
const promptBuildRun = tracing
|
|
2080
|
-
? await tracing.startChildRun(tracing.
|
|
2081
|
-
name: '
|
|
2316
|
+
? await tracing.startChildRun(tracing.messageRun, {
|
|
2317
|
+
name: 'prepare: prompt',
|
|
2318
|
+
canonicalName: 'instance-ai.prompt_build',
|
|
2082
2319
|
tags: ['prompt'],
|
|
2083
2320
|
metadata: { agent_role: 'prompt_build' },
|
|
2084
2321
|
inputs: {
|
|
2085
2322
|
message,
|
|
2086
|
-
hasConversationSummary: Boolean(conversationSummary),
|
|
2087
2323
|
attachmentCount: attachments?.length ?? 0,
|
|
2088
2324
|
},
|
|
2089
2325
|
})
|
|
2090
2326
|
: undefined;
|
|
2091
2327
|
let streamInput;
|
|
2092
2328
|
try {
|
|
2093
|
-
|
|
2094
|
-
? `${conversationSummary}\n\n${messageWithoutSummary}`
|
|
2095
|
-
: messageWithoutSummary;
|
|
2096
|
-
if (multimodalAttachments.length > 0) {
|
|
2329
|
+
if (nonStructuredAttachments.length > 0) {
|
|
2097
2330
|
streamInput = [
|
|
2098
2331
|
{
|
|
2099
2332
|
role: 'user',
|
|
2100
2333
|
content: [
|
|
2101
2334
|
{ type: 'text', text: fullMessage },
|
|
2102
|
-
...
|
|
2335
|
+
...nonStructuredAttachments.map((attachment) => ({
|
|
2103
2336
|
type: 'file',
|
|
2104
2337
|
data: attachment.data,
|
|
2105
|
-
|
|
2338
|
+
mediaType: attachment.mimeType,
|
|
2106
2339
|
})),
|
|
2107
2340
|
],
|
|
2108
2341
|
},
|
|
@@ -2117,7 +2350,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
2117
2350
|
: {
|
|
2118
2351
|
fullMessage,
|
|
2119
2352
|
attachmentCount: attachments?.length ?? 0,
|
|
2120
|
-
|
|
2353
|
+
nonStructuredAttachmentCount: nonStructuredAttachments.length,
|
|
2121
2354
|
};
|
|
2122
2355
|
await tracing.finishRun(promptBuildRun, {
|
|
2123
2356
|
outputs: traceOutput,
|
|
@@ -2133,14 +2366,41 @@ let InstanceAiService = class InstanceAiService {
|
|
|
2133
2366
|
}
|
|
2134
2367
|
throw error;
|
|
2135
2368
|
}
|
|
2369
|
+
if (tracing && tracing.actorRun.id === tracing.rootRun.id) {
|
|
2370
|
+
const actorRun = await tracing.startChildRun(tracing.rootRun, {
|
|
2371
|
+
name: 'agent: orchestrator',
|
|
2372
|
+
canonicalName: 'instance-ai.agent.orchestrator',
|
|
2373
|
+
tags: ['orchestrator'],
|
|
2374
|
+
metadata: {
|
|
2375
|
+
agent_role: 'orchestrator',
|
|
2376
|
+
agent_id: ORCHESTRATOR_AGENT_ID,
|
|
2377
|
+
execution_mode: 'foreground',
|
|
2378
|
+
trace_kind: tracing.traceKind,
|
|
2379
|
+
},
|
|
2380
|
+
inputs: traceInput,
|
|
2381
|
+
});
|
|
2382
|
+
tracing.actorRun = actorRun;
|
|
2383
|
+
tracing.orchestratorRun = actorRun;
|
|
2384
|
+
}
|
|
2385
|
+
const agent = await (0, instance_ai_1.createInstanceAgent)({
|
|
2386
|
+
modelId,
|
|
2387
|
+
context,
|
|
2388
|
+
orchestrationContext,
|
|
2389
|
+
mcpServers,
|
|
2390
|
+
mcpManager: this.mcpClientManager,
|
|
2391
|
+
memoryConfig,
|
|
2392
|
+
memory,
|
|
2393
|
+
checkpointStore: this.checkpointStore,
|
|
2394
|
+
timeZone: timeZone ?? this.defaultTimeZone,
|
|
2395
|
+
});
|
|
2136
2396
|
const result = tracing
|
|
2137
|
-
? await tracing.
|
|
2397
|
+
? await tracing.withActiveSpan(tracing.actorRun, async () => {
|
|
2138
2398
|
return await (0, instance_ai_1.streamAgentRun)(agent, streamInput, {
|
|
2139
|
-
|
|
2399
|
+
maxIterations: instance_ai_1.MAX_STEPS.ORCHESTRATOR,
|
|
2140
2400
|
abortSignal: signal,
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2401
|
+
persistence: {
|
|
2402
|
+
resourceId: user.id,
|
|
2403
|
+
threadId,
|
|
2144
2404
|
},
|
|
2145
2405
|
providerOptions: {
|
|
2146
2406
|
anthropic: { cacheControl: { type: 'ephemeral' } },
|
|
@@ -2156,11 +2416,11 @@ let InstanceAiService = class InstanceAiService {
|
|
|
2156
2416
|
});
|
|
2157
2417
|
})
|
|
2158
2418
|
: await (0, instance_ai_1.streamAgentRun)(agent, streamInput, {
|
|
2159
|
-
|
|
2419
|
+
maxIterations: instance_ai_1.MAX_STEPS.ORCHESTRATOR,
|
|
2160
2420
|
abortSignal: signal,
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2421
|
+
persistence: {
|
|
2422
|
+
resourceId: user.id,
|
|
2423
|
+
threadId,
|
|
2164
2424
|
},
|
|
2165
2425
|
providerOptions: {
|
|
2166
2426
|
anthropic: { cacheControl: { type: 'ephemeral' } },
|
|
@@ -2174,12 +2434,11 @@ let InstanceAiService = class InstanceAiService {
|
|
|
2174
2434
|
logger: this.logger,
|
|
2175
2435
|
onActivity: () => this.runState.touchActiveRun(threadId),
|
|
2176
2436
|
});
|
|
2177
|
-
mastraRunId = result.mastraRunId;
|
|
2178
2437
|
if (result.status === 'suspended') {
|
|
2179
2438
|
if (result.suspension) {
|
|
2180
2439
|
this.runState.suspendRun(threadId, {
|
|
2181
2440
|
runId,
|
|
2182
|
-
|
|
2441
|
+
agentRunId: result.agentRunId,
|
|
2183
2442
|
agent,
|
|
2184
2443
|
threadId,
|
|
2185
2444
|
user,
|
|
@@ -2189,6 +2448,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
2189
2448
|
messageGroupId,
|
|
2190
2449
|
createdAt: Date.now(),
|
|
2191
2450
|
tracing,
|
|
2451
|
+
modelId,
|
|
2192
2452
|
checkpoint,
|
|
2193
2453
|
});
|
|
2194
2454
|
}
|
|
@@ -2219,6 +2479,43 @@ let InstanceAiService = class InstanceAiService {
|
|
|
2219
2479
|
this.eventBus.publish(threadId, result.confirmationEvent);
|
|
2220
2480
|
}
|
|
2221
2481
|
await this.saveAgentTreeSnapshot(threadId, runId, snapshotStorage);
|
|
2482
|
+
const suspensionOutputs = {
|
|
2483
|
+
status: 'suspended',
|
|
2484
|
+
runId,
|
|
2485
|
+
...(result.suspension?.requestId ? { requestId: result.suspension.requestId } : {}),
|
|
2486
|
+
...(result.suspension?.toolCallId
|
|
2487
|
+
? { pendingToolCallId: result.suspension.toolCallId }
|
|
2488
|
+
: {}),
|
|
2489
|
+
...(result.suspension?.toolName ? { toolName: result.suspension.toolName } : {}),
|
|
2490
|
+
};
|
|
2491
|
+
await this.finalizeRunTracing(runId, tracing, {
|
|
2492
|
+
status: 'suspended',
|
|
2493
|
+
outputs: suspensionOutputs,
|
|
2494
|
+
metadata: {
|
|
2495
|
+
completion_source: 'orchestrator',
|
|
2496
|
+
...(result.suspension?.requestId ? { request_id: result.suspension.requestId } : {}),
|
|
2497
|
+
...(result.suspension?.toolCallId
|
|
2498
|
+
? { pending_tool_call_id: result.suspension.toolCallId }
|
|
2499
|
+
: {}),
|
|
2500
|
+
...(result.suspension?.toolName
|
|
2501
|
+
? { pending_tool_name: result.suspension.toolName }
|
|
2502
|
+
: {}),
|
|
2503
|
+
},
|
|
2504
|
+
});
|
|
2505
|
+
messageTraceFinalization = {
|
|
2506
|
+
status: 'suspended',
|
|
2507
|
+
outputs: suspensionOutputs,
|
|
2508
|
+
metadata: {
|
|
2509
|
+
completion_source: 'orchestrator',
|
|
2510
|
+
...(result.suspension?.requestId ? { request_id: result.suspension.requestId } : {}),
|
|
2511
|
+
...(result.suspension?.toolCallId
|
|
2512
|
+
? { pending_tool_call_id: result.suspension.toolCallId }
|
|
2513
|
+
: {}),
|
|
2514
|
+
...(result.suspension?.toolName
|
|
2515
|
+
? { pending_tool_name: result.suspension.toolName }
|
|
2516
|
+
: {}),
|
|
2517
|
+
},
|
|
2518
|
+
};
|
|
2222
2519
|
return;
|
|
2223
2520
|
}
|
|
2224
2521
|
const outputText = await (result.text ?? Promise.resolve(''));
|
|
@@ -2334,9 +2631,6 @@ let InstanceAiService = class InstanceAiService {
|
|
|
2334
2631
|
this.liveness.consumeRunTimeout(runId);
|
|
2335
2632
|
}
|
|
2336
2633
|
}
|
|
2337
|
-
if (!this.runState.hasSuspendedRun(threadId) && mastraRunId) {
|
|
2338
|
-
void this.cleanupMastraSnapshots(mastraRunId);
|
|
2339
|
-
}
|
|
2340
2634
|
if (!this.runState.hasSuspendedRun(threadId)) {
|
|
2341
2635
|
if (checkpoint?.isCheckpointFollowUp) {
|
|
2342
2636
|
await this.finalizeCheckpointFollowUp(user, threadId, checkpoint.checkpointTaskId);
|
|
@@ -2456,20 +2750,20 @@ let InstanceAiService = class InstanceAiService {
|
|
|
2456
2750
|
}
|
|
2457
2751
|
async resolveConfirmation(requestingUserId, requestId, request) {
|
|
2458
2752
|
const data = toConfirmationData(request);
|
|
2459
|
-
const
|
|
2460
|
-
if (!
|
|
2461
|
-
this.logger.warn('Rejecting confirmation: user no longer authorized for AI Assistant', {
|
|
2462
|
-
userId: requestingUserId,
|
|
2463
|
-
requestId,
|
|
2464
|
-
});
|
|
2753
|
+
const freshUser = await this.revalidateActiveUser(requestingUserId);
|
|
2754
|
+
if (!freshUser) {
|
|
2465
2755
|
this.runState.rejectPendingConfirmation(requestId);
|
|
2466
2756
|
const suspended = this.runState.findSuspendedByRequestId(requestId);
|
|
2467
|
-
if (suspended
|
|
2757
|
+
if (suspended?.user.id === requestingUserId) {
|
|
2468
2758
|
this.cancelRun(suspended.threadId);
|
|
2469
2759
|
}
|
|
2760
|
+
this.logger.warn('Rejecting confirmation: user no longer authorized for AI Assistant', {
|
|
2761
|
+
userId: requestingUserId,
|
|
2762
|
+
requestId,
|
|
2763
|
+
});
|
|
2470
2764
|
return false;
|
|
2471
2765
|
}
|
|
2472
|
-
if (this.runState.resolvePendingConfirmation(
|
|
2766
|
+
if (this.runState.resolvePendingConfirmation(freshUser.id, requestId, data)) {
|
|
2473
2767
|
this.logger.debug('Resolved pending confirmation (sub-agent HITL)', {
|
|
2474
2768
|
requestId,
|
|
2475
2769
|
approved: data.approved,
|
|
@@ -2482,6 +2776,25 @@ let InstanceAiService = class InstanceAiService {
|
|
|
2482
2776
|
});
|
|
2483
2777
|
return await this.resumeSuspendedRun(requestingUserId, requestId, data);
|
|
2484
2778
|
}
|
|
2779
|
+
async revalidateActiveUser(userId) {
|
|
2780
|
+
try {
|
|
2781
|
+
const user = await this.userRepository.findOne({
|
|
2782
|
+
where: { id: userId },
|
|
2783
|
+
relations: ['role'],
|
|
2784
|
+
});
|
|
2785
|
+
if (!user || user.disabled)
|
|
2786
|
+
return null;
|
|
2787
|
+
const hasInstanceAiMessageScope = user.role?.scopes?.some((scope) => scope.slug === 'instanceAi:message') ?? false;
|
|
2788
|
+
return hasInstanceAiMessageScope ? user : null;
|
|
2789
|
+
}
|
|
2790
|
+
catch (error) {
|
|
2791
|
+
this.logger.warn('Failed to revalidate user', {
|
|
2792
|
+
userId,
|
|
2793
|
+
error: getErrorMessage(error),
|
|
2794
|
+
});
|
|
2795
|
+
return null;
|
|
2796
|
+
}
|
|
2797
|
+
}
|
|
2485
2798
|
async resumeSuspendedRun(requestingUserId, requestId, data) {
|
|
2486
2799
|
const suspended = this.runState.findSuspendedByRequestId(requestId);
|
|
2487
2800
|
if (!suspended) {
|
|
@@ -2491,11 +2804,11 @@ let InstanceAiService = class InstanceAiService {
|
|
|
2491
2804
|
});
|
|
2492
2805
|
return false;
|
|
2493
2806
|
}
|
|
2494
|
-
const { agent, runId,
|
|
2807
|
+
const { agent, runId, agentRunId, threadId, user, toolCallId, abortController, tracing, modelId, messageGroupId, checkpoint, } = suspended;
|
|
2495
2808
|
if (user.id !== requestingUserId)
|
|
2496
2809
|
return false;
|
|
2497
|
-
const
|
|
2498
|
-
if (!
|
|
2810
|
+
const activeUser = await this.revalidateActiveUser(user.id);
|
|
2811
|
+
if (!activeUser) {
|
|
2499
2812
|
this.logger.warn('Cancelling suspended run: user no longer authorized for AI Assistant', {
|
|
2500
2813
|
userId: user.id,
|
|
2501
2814
|
threadId,
|
|
@@ -2517,16 +2830,41 @@ let InstanceAiService = class InstanceAiService {
|
|
|
2517
2830
|
...(data.answers ? { answers: data.answers } : {}),
|
|
2518
2831
|
...(data.resourceDecision ? { resourceDecision: data.resourceDecision } : {}),
|
|
2519
2832
|
};
|
|
2833
|
+
const resumeTracing = await this.createOrchestratorResumeTraceContext({
|
|
2834
|
+
baseTracing: tracing,
|
|
2835
|
+
threadId,
|
|
2836
|
+
messageId: (0, nanoid_1.nanoid)(),
|
|
2837
|
+
messageGroupId,
|
|
2838
|
+
runId,
|
|
2839
|
+
userId: activeUser.id,
|
|
2840
|
+
modelId,
|
|
2841
|
+
input: {
|
|
2842
|
+
requestId,
|
|
2843
|
+
toolCallId,
|
|
2844
|
+
approved: data.approved,
|
|
2845
|
+
resumeFields: Object.keys(resumeData),
|
|
2846
|
+
},
|
|
2847
|
+
resumeReason: 'approval',
|
|
2848
|
+
metadata: {
|
|
2849
|
+
request_id: requestId,
|
|
2850
|
+
pending_tool_call_id: toolCallId,
|
|
2851
|
+
approved: data.approved,
|
|
2852
|
+
...(checkpoint?.isCheckpointFollowUp
|
|
2853
|
+
? { checkpoint_task_id: checkpoint.checkpointTaskId }
|
|
2854
|
+
: {}),
|
|
2855
|
+
},
|
|
2856
|
+
});
|
|
2520
2857
|
void this.processResumedStream(agent, resumeData, {
|
|
2521
2858
|
runId,
|
|
2522
|
-
|
|
2859
|
+
agentRunId,
|
|
2523
2860
|
threadId,
|
|
2524
|
-
user:
|
|
2861
|
+
user: activeUser,
|
|
2525
2862
|
toolCallId,
|
|
2526
2863
|
signal: abortController.signal,
|
|
2527
2864
|
abortController,
|
|
2528
2865
|
snapshotStorage: this.dbSnapshotStorage,
|
|
2529
|
-
tracing,
|
|
2866
|
+
tracing: resumeTracing ?? tracing,
|
|
2867
|
+
modelId,
|
|
2530
2868
|
checkpoint,
|
|
2531
2869
|
});
|
|
2532
2870
|
return true;
|
|
@@ -2534,12 +2872,28 @@ let InstanceAiService = class InstanceAiService {
|
|
|
2534
2872
|
async processResumedStream(agent, resumeData, opts) {
|
|
2535
2873
|
let messageTraceFinalization;
|
|
2536
2874
|
try {
|
|
2875
|
+
if (opts.tracing?.getTelemetry && isTelemetryConfigurableAgent(agent)) {
|
|
2876
|
+
try {
|
|
2877
|
+
agent.telemetry(opts.tracing.getTelemetry({
|
|
2878
|
+
agentRole: 'orchestrator',
|
|
2879
|
+
functionId: 'instance-ai.orchestrator',
|
|
2880
|
+
executionMode: opts.tracing.traceKind === 'orchestrator_resume' ? 'resume' : 'foreground',
|
|
2881
|
+
}));
|
|
2882
|
+
}
|
|
2883
|
+
catch (error) {
|
|
2884
|
+
this.logger.warn('Failed to configure Instance AI resume tracing', {
|
|
2885
|
+
error: getErrorMessage(error),
|
|
2886
|
+
threadId: opts.threadId,
|
|
2887
|
+
runId: opts.runId,
|
|
2888
|
+
});
|
|
2889
|
+
}
|
|
2890
|
+
}
|
|
2537
2891
|
const result = opts.tracing
|
|
2538
|
-
? await opts.tracing.
|
|
2892
|
+
? await opts.tracing.withActiveSpan(opts.tracing.actorRun, async () => {
|
|
2539
2893
|
return await (0, instance_ai_1.resumeAgentRun)(agent, resumeData, {
|
|
2540
|
-
runId: opts.
|
|
2894
|
+
runId: opts.agentRunId,
|
|
2541
2895
|
toolCallId: opts.toolCallId,
|
|
2542
|
-
|
|
2896
|
+
persistence: { resourceId: opts.user.id, threadId: opts.threadId },
|
|
2543
2897
|
}, {
|
|
2544
2898
|
threadId: opts.threadId,
|
|
2545
2899
|
runId: opts.runId,
|
|
@@ -2547,14 +2901,14 @@ let InstanceAiService = class InstanceAiService {
|
|
|
2547
2901
|
signal: opts.signal,
|
|
2548
2902
|
eventBus: this.eventBus,
|
|
2549
2903
|
logger: this.logger,
|
|
2550
|
-
|
|
2904
|
+
agentRunId: opts.agentRunId,
|
|
2551
2905
|
onActivity: () => this.runState.touchActiveRun(opts.threadId),
|
|
2552
2906
|
});
|
|
2553
2907
|
})
|
|
2554
2908
|
: await (0, instance_ai_1.resumeAgentRun)(agent, resumeData, {
|
|
2555
|
-
runId: opts.
|
|
2909
|
+
runId: opts.agentRunId,
|
|
2556
2910
|
toolCallId: opts.toolCallId,
|
|
2557
|
-
|
|
2911
|
+
persistence: { resourceId: opts.user.id, threadId: opts.threadId },
|
|
2558
2912
|
}, {
|
|
2559
2913
|
threadId: opts.threadId,
|
|
2560
2914
|
runId: opts.runId,
|
|
@@ -2562,14 +2916,14 @@ let InstanceAiService = class InstanceAiService {
|
|
|
2562
2916
|
signal: opts.signal,
|
|
2563
2917
|
eventBus: this.eventBus,
|
|
2564
2918
|
logger: this.logger,
|
|
2565
|
-
|
|
2919
|
+
agentRunId: opts.agentRunId,
|
|
2566
2920
|
onActivity: () => this.runState.touchActiveRun(opts.threadId),
|
|
2567
2921
|
});
|
|
2568
2922
|
if (result.status === 'suspended') {
|
|
2569
2923
|
if (result.suspension) {
|
|
2570
2924
|
this.runState.suspendRun(opts.threadId, {
|
|
2571
2925
|
runId: opts.runId,
|
|
2572
|
-
|
|
2926
|
+
agentRunId: result.agentRunId,
|
|
2573
2927
|
agent,
|
|
2574
2928
|
threadId: opts.threadId,
|
|
2575
2929
|
user: opts.user,
|
|
@@ -2579,6 +2933,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
2579
2933
|
messageGroupId: this.traceContextsByRunId.get(opts.runId)?.messageGroupId,
|
|
2580
2934
|
createdAt: Date.now(),
|
|
2581
2935
|
tracing: opts.tracing,
|
|
2936
|
+
...(opts.modelId !== undefined ? { modelId: opts.modelId } : {}),
|
|
2582
2937
|
checkpoint: opts.checkpoint,
|
|
2583
2938
|
});
|
|
2584
2939
|
}
|
|
@@ -2607,6 +2962,43 @@ let InstanceAiService = class InstanceAiService {
|
|
|
2607
2962
|
this.eventBus.publish(opts.threadId, result.confirmationEvent);
|
|
2608
2963
|
}
|
|
2609
2964
|
await this.saveAgentTreeSnapshot(opts.threadId, opts.runId, opts.snapshotStorage);
|
|
2965
|
+
const suspensionOutputs = {
|
|
2966
|
+
status: 'suspended',
|
|
2967
|
+
runId: opts.runId,
|
|
2968
|
+
...(result.suspension?.requestId ? { requestId: result.suspension.requestId } : {}),
|
|
2969
|
+
...(result.suspension?.toolCallId
|
|
2970
|
+
? { pendingToolCallId: result.suspension.toolCallId }
|
|
2971
|
+
: {}),
|
|
2972
|
+
...(result.suspension?.toolName ? { toolName: result.suspension.toolName } : {}),
|
|
2973
|
+
};
|
|
2974
|
+
await this.finalizeRunTracing(opts.runId, opts.tracing, {
|
|
2975
|
+
status: 'suspended',
|
|
2976
|
+
outputs: suspensionOutputs,
|
|
2977
|
+
metadata: {
|
|
2978
|
+
completion_source: 'orchestrator',
|
|
2979
|
+
...(result.suspension?.requestId ? { request_id: result.suspension.requestId } : {}),
|
|
2980
|
+
...(result.suspension?.toolCallId
|
|
2981
|
+
? { pending_tool_call_id: result.suspension.toolCallId }
|
|
2982
|
+
: {}),
|
|
2983
|
+
...(result.suspension?.toolName
|
|
2984
|
+
? { pending_tool_name: result.suspension.toolName }
|
|
2985
|
+
: {}),
|
|
2986
|
+
},
|
|
2987
|
+
});
|
|
2988
|
+
messageTraceFinalization = {
|
|
2989
|
+
status: 'suspended',
|
|
2990
|
+
outputs: suspensionOutputs,
|
|
2991
|
+
metadata: {
|
|
2992
|
+
completion_source: 'orchestrator',
|
|
2993
|
+
...(result.suspension?.requestId ? { request_id: result.suspension.requestId } : {}),
|
|
2994
|
+
...(result.suspension?.toolCallId
|
|
2995
|
+
? { pending_tool_call_id: result.suspension.toolCallId }
|
|
2996
|
+
: {}),
|
|
2997
|
+
...(result.suspension?.toolName
|
|
2998
|
+
? { pending_tool_name: result.suspension.toolName }
|
|
2999
|
+
: {}),
|
|
3000
|
+
},
|
|
3001
|
+
};
|
|
2610
3002
|
return;
|
|
2611
3003
|
}
|
|
2612
3004
|
const outputText = await (result.text ?? Promise.resolve(''));
|
|
@@ -2739,6 +3131,7 @@ let InstanceAiService = class InstanceAiService {
|
|
|
2739
3131
|
plannedTaskId: opts.plannedTaskId,
|
|
2740
3132
|
workItemId: opts.workItemId,
|
|
2741
3133
|
traceContext: opts.traceContext,
|
|
3134
|
+
createTraceContext: opts.createTraceContext,
|
|
2742
3135
|
dedupeKey: opts.dedupeKey,
|
|
2743
3136
|
parentCheckpointId: opts.parentCheckpointId,
|
|
2744
3137
|
run: opts.run,
|
|
@@ -2986,9 +3379,6 @@ let InstanceAiService = class InstanceAiService {
|
|
|
2986
3379
|
const archivedWorkflowIds = await this.reapAiTemporaryFromRun(suspended.threadId, suspended.user, undefined);
|
|
2987
3380
|
this.publishRunFinish(suspended.threadId, suspended.runId, 'cancelled', reason, archivedWorkflowIds);
|
|
2988
3381
|
await this.saveAgentTreeSnapshot(suspended.threadId, suspended.runId, this.dbSnapshotStorage, true);
|
|
2989
|
-
if (suspended.mastraRunId) {
|
|
2990
|
-
void this.cleanupMastraSnapshots(suspended.mastraRunId);
|
|
2991
|
-
}
|
|
2992
3382
|
await this.maybeFinalizeRunTraceRoot(suspended.runId, {
|
|
2993
3383
|
status: 'cancelled',
|
|
2994
3384
|
reason,
|
|
@@ -3078,20 +3468,79 @@ let InstanceAiService = class InstanceAiService {
|
|
|
3078
3468
|
}
|
|
3079
3469
|
async refineTitleIfNeeded(threadId, userId, modelId) {
|
|
3080
3470
|
try {
|
|
3081
|
-
const memory =
|
|
3082
|
-
const thread = await memory.
|
|
3471
|
+
const memory = this.agentMemory;
|
|
3472
|
+
const thread = await memory.getThread(threadId);
|
|
3083
3473
|
if (!thread?.title)
|
|
3084
3474
|
return;
|
|
3085
3475
|
if (thread.metadata?.titleRefined)
|
|
3086
3476
|
return;
|
|
3087
|
-
const
|
|
3088
|
-
const userTexts =
|
|
3089
|
-
|
|
3090
|
-
|
|
3477
|
+
const history = await memory.getMessages(threadId, { limit: 5 });
|
|
3478
|
+
const userTexts = history.flatMap((m) => {
|
|
3479
|
+
if (!('role' in m) || m.role !== 'user')
|
|
3480
|
+
return [];
|
|
3481
|
+
const text = this.extractStoredMessageText(m.content);
|
|
3482
|
+
return text.length > 0 ? [text] : [];
|
|
3483
|
+
});
|
|
3091
3484
|
if (userTexts.length === 0)
|
|
3092
3485
|
return;
|
|
3093
3486
|
const userText = userTexts.join('\n');
|
|
3094
|
-
const
|
|
3487
|
+
const baseTracing = this.getTraceContextForContinuation(threadId);
|
|
3488
|
+
const titleTracing = await (0, instance_ai_1.createInternalOperationTraceContext)({
|
|
3489
|
+
threadId,
|
|
3490
|
+
conversationId: threadId,
|
|
3491
|
+
messageId: `internal:title:${threadId}`,
|
|
3492
|
+
runId: `title-${(0, nanoid_1.nanoid)()}`,
|
|
3493
|
+
userId,
|
|
3494
|
+
modelId,
|
|
3495
|
+
operationName: 'thread_title',
|
|
3496
|
+
input: {
|
|
3497
|
+
message_count: userTexts.length,
|
|
3498
|
+
source: 'thread_title_refinement',
|
|
3499
|
+
},
|
|
3500
|
+
proxyConfig: baseTracing?.proxyConfig,
|
|
3501
|
+
metadata: {
|
|
3502
|
+
n8n_version: constants_1.N8N_VERSION || undefined,
|
|
3503
|
+
operation_name: 'thread_title',
|
|
3504
|
+
trigger: 'run_completed',
|
|
3505
|
+
},
|
|
3506
|
+
});
|
|
3507
|
+
const titleTelemetry = titleTracing?.getTelemetry?.({
|
|
3508
|
+
agentRole: 'thread_title',
|
|
3509
|
+
functionId: 'instance-ai.thread_title',
|
|
3510
|
+
executionMode: 'internal',
|
|
3511
|
+
metadata: {
|
|
3512
|
+
operation_name: 'thread_title',
|
|
3513
|
+
},
|
|
3514
|
+
});
|
|
3515
|
+
let llmTitle;
|
|
3516
|
+
if (titleTracing) {
|
|
3517
|
+
try {
|
|
3518
|
+
llmTitle = await titleTracing.withActiveSpan(titleTracing.rootRun, async () => {
|
|
3519
|
+
const title = await (0, instance_ai_1.generateTitleForRun)(modelId, userText, {
|
|
3520
|
+
...(titleTelemetry ? { telemetry: titleTelemetry } : {}),
|
|
3521
|
+
});
|
|
3522
|
+
if (title) {
|
|
3523
|
+
await titleTracing.finishRun(titleTracing.rootRun, {
|
|
3524
|
+
outputs: { title },
|
|
3525
|
+
metadata: { final_status: 'completed' },
|
|
3526
|
+
});
|
|
3527
|
+
}
|
|
3528
|
+
else {
|
|
3529
|
+
await titleTracing.finishRun(titleTracing.rootRun, {
|
|
3530
|
+
outputs: { title: null },
|
|
3531
|
+
metadata: { final_status: 'skipped' },
|
|
3532
|
+
});
|
|
3533
|
+
}
|
|
3534
|
+
return title;
|
|
3535
|
+
});
|
|
3536
|
+
}
|
|
3537
|
+
finally {
|
|
3538
|
+
(0, instance_ai_1.releaseTraceClient)(titleTracing.rootRun.traceId);
|
|
3539
|
+
}
|
|
3540
|
+
}
|
|
3541
|
+
else {
|
|
3542
|
+
llmTitle = await (0, instance_ai_1.generateTitleForRun)(modelId, userText);
|
|
3543
|
+
}
|
|
3095
3544
|
if (!llmTitle)
|
|
3096
3545
|
return;
|
|
3097
3546
|
await (0, instance_ai_1.patchThread)(memory, {
|
|
@@ -3115,17 +3564,13 @@ let InstanceAiService = class InstanceAiService {
|
|
|
3115
3564
|
});
|
|
3116
3565
|
}
|
|
3117
3566
|
}
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
catch (error) {
|
|
3124
|
-
this.logger.warn('Failed to clean up Mastra workflow snapshots', {
|
|
3125
|
-
mastraRunId,
|
|
3126
|
-
error: getErrorMessage(error),
|
|
3127
|
-
});
|
|
3567
|
+
extractStoredMessageText(content) {
|
|
3568
|
+
if (typeof content === 'string')
|
|
3569
|
+
return content;
|
|
3570
|
+
if (Array.isArray(content)) {
|
|
3571
|
+
return content.flatMap((part) => (isTextMessagePart(part) ? [part.text] : [])).join('\n');
|
|
3128
3572
|
}
|
|
3573
|
+
return '';
|
|
3129
3574
|
}
|
|
3130
3575
|
async saveAgentTreeSnapshot(threadId, runId, snapshotStorage, isUpdate = false, overrideMessageGroupId) {
|
|
3131
3576
|
try {
|
|
@@ -3156,6 +3601,8 @@ let InstanceAiService = class InstanceAiService {
|
|
|
3156
3601
|
const saveOptions = {
|
|
3157
3602
|
messageGroupId,
|
|
3158
3603
|
runIds: groupRunIds,
|
|
3604
|
+
traceId: tracing?.rootRun.otelTraceId,
|
|
3605
|
+
spanId: tracing?.rootRun.otelSpanId,
|
|
3159
3606
|
langsmithRunId: tracing?.rootRun.id,
|
|
3160
3607
|
langsmithTraceId: tracing?.rootRun.traceId,
|
|
3161
3608
|
};
|
|
@@ -3184,15 +3631,28 @@ let InstanceAiService = class InstanceAiService {
|
|
|
3184
3631
|
}
|
|
3185
3632
|
};
|
|
3186
3633
|
exports.InstanceAiService = InstanceAiService;
|
|
3634
|
+
__decorate([
|
|
3635
|
+
(0, decorators_1.OnLeaderTakeover)(),
|
|
3636
|
+
__metadata("design:type", Function),
|
|
3637
|
+
__metadata("design:paramtypes", []),
|
|
3638
|
+
__metadata("design:returntype", void 0)
|
|
3639
|
+
], InstanceAiService.prototype, "startCheckpointPruning", null);
|
|
3640
|
+
__decorate([
|
|
3641
|
+
(0, decorators_1.OnLeaderStepdown)(),
|
|
3642
|
+
__metadata("design:type", Function),
|
|
3643
|
+
__metadata("design:paramtypes", []),
|
|
3644
|
+
__metadata("design:returntype", void 0)
|
|
3645
|
+
], InstanceAiService.prototype, "stopCheckpointPruning", null);
|
|
3187
3646
|
exports.InstanceAiService = InstanceAiService = __decorate([
|
|
3188
3647
|
(0, di_1.Service)(),
|
|
3189
3648
|
__metadata("design:paramtypes", [backend_common_1.Logger,
|
|
3190
3649
|
config_1.GlobalConfig,
|
|
3650
|
+
n8n_core_1.InstanceSettings,
|
|
3191
3651
|
instance_ai_adapter_service_1.InstanceAiAdapterService,
|
|
3192
3652
|
in_process_event_bus_1.InProcessEventBus,
|
|
3193
3653
|
instance_ai_settings_service_1.InstanceAiSettingsService,
|
|
3194
|
-
|
|
3195
|
-
|
|
3654
|
+
typeorm_agent_memory_1.TypeORMAgentMemory,
|
|
3655
|
+
typeorm_agent_checkpoint_store_1.TypeORMAgentCheckpointStore,
|
|
3196
3656
|
ai_service_1.AiService,
|
|
3197
3657
|
push_1.Push,
|
|
3198
3658
|
instance_ai_thread_repository_1.InstanceAiThreadRepository,
|