n8n 2.15.0 → 2.16.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/active-workflow-manager.js +25 -12
- package/dist/active-workflow-manager.js.map +1 -1
- package/dist/auth/auth.service.js +1 -0
- package/dist/auth/auth.service.js.map +1 -1
- package/dist/build.tsbuildinfo +1 -1
- package/dist/commands/base-command.js +7 -1
- package/dist/commands/base-command.js.map +1 -1
- package/dist/controllers/ai.controller.js +2 -2
- package/dist/controllers/ai.controller.js.map +1 -1
- package/dist/controllers/e2e.controller.js +2 -0
- package/dist/controllers/e2e.controller.js.map +1 -1
- package/dist/credentials/credentials.controller.js +1 -1
- package/dist/credentials/credentials.controller.js.map +1 -1
- package/dist/credentials/credentials.service.d.ts +7 -4
- package/dist/credentials/credentials.service.js +77 -16
- package/dist/credentials/credentials.service.js.map +1 -1
- package/dist/credentials-helper.js +7 -1
- package/dist/credentials-helper.js.map +1 -1
- package/dist/errors/http-error-classifier.d.ts +31 -0
- package/dist/errors/http-error-classifier.js +60 -0
- package/dist/errors/http-error-classifier.js.map +1 -0
- package/dist/errors/http-error-serializers.d.ts +18 -0
- package/dist/errors/http-error-serializers.js +64 -0
- package/dist/errors/http-error-serializers.js.map +1 -0
- package/dist/eventbus/event-message-classes/index.d.ts +2 -2
- package/dist/eventbus/event-message-classes/index.js +3 -0
- package/dist/eventbus/event-message-classes/index.js.map +1 -1
- package/dist/events/maps/relay.event-map.d.ts +22 -0
- package/dist/events/relays/log-streaming.event-relay.d.ts +3 -0
- package/dist/events/relays/log-streaming.event-relay.js +21 -0
- package/dist/events/relays/log-streaming.event-relay.js.map +1 -1
- package/dist/execution-lifecycle/execution-lifecycle-hooks.js +2 -0
- package/dist/execution-lifecycle/execution-lifecycle-hooks.js.map +1 -1
- package/dist/executions/execution.service.js +2 -1
- package/dist/executions/execution.service.js.map +1 -1
- package/dist/modules/chat-hub/chat-hub-workflow.service.d.ts +1 -0
- package/dist/modules/chat-hub/chat-hub-workflow.service.js +18 -2
- package/dist/modules/chat-hub/chat-hub-workflow.service.js.map +1 -1
- package/dist/modules/chat-hub/chat-hub.types.d.ts +5 -0
- package/dist/modules/chat-hub/chat-hub.types.js +1 -0
- package/dist/modules/chat-hub/chat-hub.types.js.map +1 -1
- package/dist/modules/chat-hub/context-limits.js +10 -0
- package/dist/modules/chat-hub/context-limits.js.map +1 -1
- package/dist/modules/community-packages/community-node-types-utils.d.ts +2 -2
- package/dist/modules/community-packages/community-node-types-utils.js +4 -4
- package/dist/modules/community-packages/community-node-types-utils.js.map +1 -1
- package/dist/modules/community-packages/strapi-utils.d.ts +1 -1
- package/dist/modules/data-table/data-table-proxy.service.d.ts +44 -2
- package/dist/modules/data-table/data-table-proxy.service.js +86 -2
- package/dist/modules/data-table/data-table-proxy.service.js.map +1 -1
- package/dist/modules/dynamic-credentials.ee/services/resolver-config-expression.service.js +10 -4
- package/dist/modules/dynamic-credentials.ee/services/resolver-config-expression.service.js.map +1 -1
- package/dist/modules/instance-ai/compaction.service.d.ts +19 -0
- package/dist/modules/instance-ai/compaction.service.js +213 -0
- package/dist/modules/instance-ai/compaction.service.js.map +1 -0
- package/dist/modules/instance-ai/entities/index.d.ts +7 -0
- package/dist/modules/instance-ai/entities/index.js +18 -0
- package/dist/modules/instance-ai/entities/index.js.map +1 -0
- package/dist/modules/instance-ai/entities/instance-ai-iteration-log.entity.d.ts +7 -0
- package/dist/modules/instance-ai/entities/instance-ai-iteration-log.entity.js +38 -0
- package/dist/modules/instance-ai/entities/instance-ai-iteration-log.entity.js.map +1 -0
- package/dist/modules/instance-ai/entities/instance-ai-message.entity.d.ts +9 -0
- package/dist/modules/instance-ai/entities/instance-ai-message.entity.js +47 -0
- package/dist/modules/instance-ai/entities/instance-ai-message.entity.js.map +1 -0
- package/dist/modules/instance-ai/entities/instance-ai-observational-memory.entity.d.ts +33 -0
- package/dist/modules/instance-ai/entities/instance-ai-observational-memory.entity.js +145 -0
- package/dist/modules/instance-ai/entities/instance-ai-observational-memory.entity.js.map +1 -0
- package/dist/modules/instance-ai/entities/instance-ai-resource.entity.d.ts +6 -0
- package/dist/modules/instance-ai/entities/instance-ai-resource.entity.js +33 -0
- package/dist/modules/instance-ai/entities/instance-ai-resource.entity.js.map +1 -0
- package/dist/modules/instance-ai/entities/instance-ai-run-snapshot.entity.d.ts +8 -0
- package/dist/modules/instance-ai/entities/instance-ai-run-snapshot.entity.js +43 -0
- package/dist/modules/instance-ai/entities/instance-ai-run-snapshot.entity.js.map +1 -0
- package/dist/modules/instance-ai/entities/instance-ai-thread.entity.d.ts +7 -0
- package/dist/modules/instance-ai/entities/instance-ai-thread.entity.js +38 -0
- package/dist/modules/instance-ai/entities/instance-ai-thread.entity.js.map +1 -0
- package/dist/modules/instance-ai/entities/instance-ai-workflow-snapshot.entity.d.ts +8 -0
- package/dist/modules/instance-ai/entities/instance-ai-workflow-snapshot.entity.js +41 -0
- package/dist/modules/instance-ai/entities/instance-ai-workflow-snapshot.entity.js.map +1 -0
- package/dist/modules/instance-ai/event-bus/in-process-event-bus.d.ts +19 -0
- package/dist/modules/instance-ai/event-bus/in-process-event-bus.js +98 -0
- package/dist/modules/instance-ai/event-bus/in-process-event-bus.js.map +1 -0
- package/dist/modules/instance-ai/filesystem/index.d.ts +4 -0
- package/dist/modules/instance-ai/filesystem/index.js +10 -0
- package/dist/modules/instance-ai/filesystem/index.js.map +1 -0
- package/dist/modules/instance-ai/filesystem/local-fs-provider.d.ts +26 -0
- package/dist/modules/instance-ai/filesystem/local-fs-provider.js +321 -0
- package/dist/modules/instance-ai/filesystem/local-fs-provider.js.map +1 -0
- package/dist/modules/instance-ai/filesystem/local-gateway-registry.d.ts +29 -0
- package/dist/modules/instance-ai/filesystem/local-gateway-registry.js +137 -0
- package/dist/modules/instance-ai/filesystem/local-gateway-registry.js.map +1 -0
- package/dist/modules/instance-ai/filesystem/local-gateway.d.ts +35 -0
- package/dist/modules/instance-ai/filesystem/local-gateway.js +99 -0
- package/dist/modules/instance-ai/filesystem/local-gateway.js.map +1 -0
- package/dist/modules/instance-ai/instance-ai-memory.service.d.ts +36 -0
- package/dist/modules/instance-ai/instance-ai-memory.service.js +265 -0
- package/dist/modules/instance-ai/instance-ai-memory.service.js.map +1 -0
- package/dist/modules/instance-ai/instance-ai-settings.service.d.ts +55 -0
- package/dist/modules/instance-ai/instance-ai-settings.service.js +430 -0
- package/dist/modules/instance-ai/instance-ai-settings.service.js.map +1 -0
- package/dist/modules/instance-ai/instance-ai.adapter.service.d.ts +86 -0
- package/dist/modules/instance-ai/instance-ai.adapter.service.js +1731 -0
- package/dist/modules/instance-ai/instance-ai.adapter.service.js.map +1 -0
- package/dist/modules/instance-ai/instance-ai.controller.d.ts +102 -0
- package/dist/modules/instance-ai/instance-ai.controller.js +613 -0
- package/dist/modules/instance-ai/instance-ai.controller.js.map +1 -0
- package/dist/modules/instance-ai/instance-ai.module.d.ts +13 -0
- package/dist/modules/instance-ai/instance-ai.module.js +119 -0
- package/dist/modules/instance-ai/instance-ai.module.js.map +1 -0
- package/dist/modules/instance-ai/instance-ai.service.d.ts +132 -0
- package/dist/modules/instance-ai/instance-ai.service.js +1674 -0
- package/dist/modules/instance-ai/instance-ai.service.js.map +1 -0
- package/dist/modules/instance-ai/internal-messages.d.ts +2 -0
- package/dist/modules/instance-ai/internal-messages.js +11 -0
- package/dist/modules/instance-ai/internal-messages.js.map +1 -0
- package/dist/modules/instance-ai/message-parser.d.ts +12 -0
- package/dist/modules/instance-ai/message-parser.js +171 -0
- package/dist/modules/instance-ai/message-parser.js.map +1 -0
- package/dist/modules/instance-ai/node-definition-resolver.d.ts +19 -0
- package/dist/modules/instance-ai/node-definition-resolver.js +290 -0
- package/dist/modules/instance-ai/node-definition-resolver.js.map +1 -0
- package/dist/modules/instance-ai/repositories/index.d.ts +7 -0
- package/dist/modules/instance-ai/repositories/index.js +18 -0
- package/dist/modules/instance-ai/repositories/index.js.map +1 -0
- package/dist/modules/instance-ai/repositories/instance-ai-iteration-log.repository.d.ts +5 -0
- package/dist/modules/instance-ai/repositories/instance-ai-iteration-log.repository.js +26 -0
- package/dist/modules/instance-ai/repositories/instance-ai-iteration-log.repository.js.map +1 -0
- package/dist/modules/instance-ai/repositories/instance-ai-message.repository.d.ts +5 -0
- package/dist/modules/instance-ai/repositories/instance-ai-message.repository.js +26 -0
- package/dist/modules/instance-ai/repositories/instance-ai-message.repository.js.map +1 -0
- package/dist/modules/instance-ai/repositories/instance-ai-observational-memory.repository.d.ts +5 -0
- package/dist/modules/instance-ai/repositories/instance-ai-observational-memory.repository.js +26 -0
- package/dist/modules/instance-ai/repositories/instance-ai-observational-memory.repository.js.map +1 -0
- package/dist/modules/instance-ai/repositories/instance-ai-resource.repository.d.ts +5 -0
- package/dist/modules/instance-ai/repositories/instance-ai-resource.repository.js +26 -0
- package/dist/modules/instance-ai/repositories/instance-ai-resource.repository.js.map +1 -0
- package/dist/modules/instance-ai/repositories/instance-ai-run-snapshot.repository.d.ts +5 -0
- package/dist/modules/instance-ai/repositories/instance-ai-run-snapshot.repository.js +26 -0
- package/dist/modules/instance-ai/repositories/instance-ai-run-snapshot.repository.js.map +1 -0
- package/dist/modules/instance-ai/repositories/instance-ai-thread.repository.d.ts +5 -0
- package/dist/modules/instance-ai/repositories/instance-ai-thread.repository.js +26 -0
- package/dist/modules/instance-ai/repositories/instance-ai-thread.repository.js.map +1 -0
- package/dist/modules/instance-ai/repositories/instance-ai-workflow-snapshot.repository.d.ts +5 -0
- package/dist/modules/instance-ai/repositories/instance-ai-workflow-snapshot.repository.js +26 -0
- package/dist/modules/instance-ai/repositories/instance-ai-workflow-snapshot.repository.js.map +1 -0
- package/dist/modules/instance-ai/snapshot-pruning.service.d.ts +14 -0
- package/dist/modules/instance-ai/snapshot-pruning.service.js +77 -0
- package/dist/modules/instance-ai/snapshot-pruning.service.js.map +1 -0
- package/dist/modules/instance-ai/storage/db-iteration-log-storage.d.ts +9 -0
- package/dist/modules/instance-ai/storage/db-iteration-log-storage.js +45 -0
- package/dist/modules/instance-ai/storage/db-iteration-log-storage.js.map +1 -0
- package/dist/modules/instance-ai/storage/db-snapshot-storage.d.ts +10 -0
- package/dist/modules/instance-ai/storage/db-snapshot-storage.js +74 -0
- package/dist/modules/instance-ai/storage/db-snapshot-storage.js.map +1 -0
- package/dist/modules/instance-ai/storage/index.d.ts +5 -0
- package/dist/modules/instance-ai/storage/index.js +14 -0
- package/dist/modules/instance-ai/storage/index.js.map +1 -0
- package/dist/modules/instance-ai/storage/typeorm-composite-store.d.ts +9 -0
- package/dist/modules/instance-ai/storage/typeorm-composite-store.js +33 -0
- package/dist/modules/instance-ai/storage/typeorm-composite-store.js.map +1 -0
- package/dist/modules/instance-ai/storage/typeorm-memory-storage.d.ts +96 -0
- package/dist/modules/instance-ai/storage/typeorm-memory-storage.js +853 -0
- package/dist/modules/instance-ai/storage/typeorm-memory-storage.js.map +1 -0
- package/dist/modules/instance-ai/storage/typeorm-workflows-storage.d.ts +44 -0
- package/dist/modules/instance-ai/storage/typeorm-workflows-storage.js +156 -0
- package/dist/modules/instance-ai/storage/typeorm-workflows-storage.js.map +1 -0
- package/dist/modules/instance-ai/web-research/brave-search.d.ts +10 -0
- package/dist/modules/instance-ai/web-research/brave-search.js +43 -0
- package/dist/modules/instance-ai/web-research/brave-search.js.map +1 -0
- package/dist/modules/instance-ai/web-research/cache.d.ts +13 -0
- package/dist/modules/instance-ai/web-research/cache.js +43 -0
- package/dist/modules/instance-ai/web-research/cache.js.map +1 -0
- package/dist/modules/instance-ai/web-research/fetch-and-extract.d.ts +8 -0
- package/dist/modules/instance-ai/web-research/fetch-and-extract.js +231 -0
- package/dist/modules/instance-ai/web-research/fetch-and-extract.js.map +1 -0
- package/dist/modules/instance-ai/web-research/index.d.ts +7 -0
- package/dist/modules/instance-ai/web-research/index.js +16 -0
- package/dist/modules/instance-ai/web-research/index.js.map +1 -0
- package/dist/modules/instance-ai/web-research/searxng-search.d.ts +6 -0
- package/dist/modules/instance-ai/web-research/searxng-search.js +39 -0
- package/dist/modules/instance-ai/web-research/searxng-search.js.map +1 -0
- package/dist/modules/instance-ai/web-research/ssrf-guard.d.ts +1 -0
- package/dist/modules/instance-ai/web-research/ssrf-guard.js +85 -0
- package/dist/modules/instance-ai/web-research/ssrf-guard.js.map +1 -0
- package/dist/modules/instance-ai/web-research/summarize-content.d.ts +4 -0
- package/dist/modules/instance-ai/web-research/summarize-content.js +34 -0
- package/dist/modules/instance-ai/web-research/summarize-content.js.map +1 -0
- package/dist/modules/instance-registry/instance-registry.types.d.ts +1 -0
- package/dist/modules/instance-registry/instance-registry.types.js +2 -1
- package/dist/modules/instance-registry/instance-registry.types.js.map +1 -1
- package/dist/modules/instance-registry/storage/instance-storage.interface.d.ts +1 -0
- package/dist/modules/instance-registry/storage/lua-scripts.d.ts +4 -0
- package/dist/modules/instance-registry/storage/lua-scripts.js +39 -0
- package/dist/modules/instance-registry/storage/lua-scripts.js.map +1 -0
- package/dist/modules/instance-registry/storage/memory-storage.d.ts +1 -0
- package/dist/modules/instance-registry/storage/memory-storage.js +1 -0
- package/dist/modules/instance-registry/storage/memory-storage.js.map +1 -1
- package/dist/modules/instance-registry/storage/redis-instance-storage.d.ts +25 -0
- package/dist/modules/instance-registry/storage/redis-instance-storage.js +185 -0
- package/dist/modules/instance-registry/storage/redis-instance-storage.js.map +1 -0
- package/dist/modules/log-streaming.ee/log-streaming.controller.js.map +1 -1
- package/dist/modules/mcp/mcp.service.d.ts +3 -1
- package/dist/modules/mcp/mcp.service.js +22 -3
- package/dist/modules/mcp/mcp.service.js.map +1 -1
- package/dist/modules/mcp/mcp.types.d.ts +1 -1
- package/dist/modules/mcp/tools/data-table/add-data-table-column.tool.d.ts +13 -0
- package/dist/modules/mcp/tools/data-table/add-data-table-column.tool.js +69 -0
- package/dist/modules/mcp/tools/data-table/add-data-table-column.tool.js.map +1 -0
- package/dist/modules/mcp/tools/data-table/add-data-table-rows.tool.d.ts +12 -0
- package/dist/modules/mcp/tools/data-table/add-data-table-rows.tool.js +77 -0
- package/dist/modules/mcp/tools/data-table/add-data-table-rows.tool.js.map +1 -0
- package/dist/modules/mcp/tools/data-table/create-data-table.tool.d.ts +21 -0
- package/dist/modules/mcp/tools/data-table/create-data-table.tool.js +92 -0
- package/dist/modules/mcp/tools/data-table/create-data-table.tool.js.map +1 -0
- package/dist/modules/mcp/tools/data-table/delete-data-table-column.tool.d.ts +12 -0
- package/dist/modules/mcp/tools/data-table/delete-data-table-column.tool.js +60 -0
- package/dist/modules/mcp/tools/data-table/delete-data-table-column.tool.js.map +1 -0
- package/dist/modules/mcp/tools/data-table/index.d.ts +7 -0
- package/dist/modules/mcp/tools/data-table/index.js +18 -0
- package/dist/modules/mcp/tools/data-table/index.js.map +1 -0
- package/dist/modules/mcp/tools/data-table/rename-data-table-column.tool.d.ts +13 -0
- package/dist/modules/mcp/tools/data-table/rename-data-table-column.tool.js +70 -0
- package/dist/modules/mcp/tools/data-table/rename-data-table-column.tool.js.map +1 -0
- package/dist/modules/mcp/tools/data-table/rename-data-table.tool.d.ts +12 -0
- package/dist/modules/mcp/tools/data-table/rename-data-table.tool.js +60 -0
- package/dist/modules/mcp/tools/data-table/rename-data-table.tool.js.map +1 -0
- package/dist/modules/mcp/tools/data-table/search-data-tables.tool.d.ts +12 -0
- package/dist/modules/mcp/tools/data-table/search-data-tables.tool.js +93 -0
- package/dist/modules/mcp/tools/data-table/search-data-tables.tool.js.map +1 -0
- package/dist/modules/mcp/tools/execute-workflow.tool.d.ts +3 -4
- package/dist/modules/mcp/tools/execute-workflow.tool.js +10 -25
- package/dist/modules/mcp/tools/execute-workflow.tool.js.map +1 -1
- package/dist/modules/mcp/tools/get-execution.tool.js +4 -8
- package/dist/modules/mcp/tools/get-execution.tool.js.map +1 -1
- package/dist/modules/mcp/tools/schemas.d.ts +73 -2
- package/dist/modules/mcp/tools/schemas.js +41 -1
- package/dist/modules/mcp/tools/schemas.js.map +1 -1
- package/dist/modules/mcp/tools/search-folders.tool.js +2 -7
- package/dist/modules/mcp/tools/search-folders.tool.js.map +1 -1
- package/dist/modules/mcp/tools/search-projects.tool.js +2 -7
- package/dist/modules/mcp/tools/search-projects.tool.js.map +1 -1
- package/dist/modules/mcp/tools/search-workflows.tool.js +2 -7
- package/dist/modules/mcp/tools/search-workflows.tool.js.map +1 -1
- package/dist/modules/mcp/tools/workflow-builder/get-suggested-workflow-nodes.tool.js +1 -37
- package/dist/modules/mcp/tools/workflow-builder/get-suggested-workflow-nodes.tool.js.map +1 -1
- package/dist/modules/mcp/tools/workflow-builder/get-workflow-node-types.tool.js +1 -37
- package/dist/modules/mcp/tools/workflow-builder/get-workflow-node-types.tool.js.map +1 -1
- package/dist/modules/mcp/tools/workflow-builder/search-workflow-nodes.tool.js +1 -37
- package/dist/modules/mcp/tools/workflow-builder/search-workflow-nodes.tool.js.map +1 -1
- package/dist/modules/mcp/tools/workflow-builder/workflow-builder-tools.service.d.ts +17 -0
- package/dist/modules/mcp/tools/workflow-builder/workflow-builder-tools.service.js +48 -0
- package/dist/modules/mcp/tools/workflow-builder/workflow-builder-tools.service.js.map +1 -1
- package/dist/modules/otel/handlers/node-end.handler.d.ts +8 -0
- package/dist/modules/otel/handlers/node-end.handler.js +71 -0
- package/dist/modules/otel/handlers/node-end.handler.js.map +1 -0
- package/dist/modules/otel/handlers/node-start.handler.d.ts +7 -0
- package/dist/modules/otel/handlers/node-start.handler.js +37 -0
- package/dist/modules/otel/handlers/node-start.handler.js.map +1 -0
- package/dist/modules/otel/handlers/workflow-end.handler.d.ts +1 -0
- package/dist/modules/otel/handlers/workflow-end.handler.js +8 -0
- package/dist/modules/otel/handlers/workflow-end.handler.js.map +1 -1
- package/dist/modules/otel/n8n-instrumentation.d.ts +8 -2
- package/dist/modules/otel/n8n-instrumentation.js +32 -1
- package/dist/modules/otel/n8n-instrumentation.js.map +1 -1
- package/dist/modules/otel/otel.config.d.ts +1 -0
- package/dist/modules/otel/otel.config.js +5 -0
- package/dist/modules/otel/otel.config.js.map +1 -1
- package/dist/modules/otel/otel.constants.d.ts +7 -0
- package/dist/modules/otel/otel.constants.js +7 -0
- package/dist/modules/otel/otel.constants.js.map +1 -1
- package/dist/modules/otel/otel.service.d.ts +1 -1
- package/dist/modules/otel/otel.service.js +20 -23
- package/dist/modules/otel/otel.service.js.map +1 -1
- package/dist/modules/otel/span-registry.d.ts +1 -0
- package/dist/modules/otel/span-registry.js +11 -0
- package/dist/modules/otel/span-registry.js.map +1 -1
- package/dist/modules/provisioning.ee/provisioning.service.ee.d.ts +13 -2
- package/dist/modules/provisioning.ee/provisioning.service.ee.js +145 -2
- package/dist/modules/provisioning.ee/provisioning.service.ee.js.map +1 -1
- package/dist/modules/redaction/executions/execution-redaction.service.d.ts +3 -2
- package/dist/modules/redaction/executions/execution-redaction.service.js +5 -1
- package/dist/modules/redaction/executions/execution-redaction.service.js.map +1 -1
- package/dist/modules/redaction/redaction.module.js +0 -6
- package/dist/modules/redaction/redaction.module.js.map +1 -1
- package/dist/modules/sso-oidc/oidc.controller.ee.d.ts +4 -1
- package/dist/modules/sso-oidc/oidc.controller.ee.js +39 -3
- package/dist/modules/sso-oidc/oidc.controller.ee.js.map +1 -1
- package/dist/modules/sso-oidc/oidc.service.ee.d.ts +14 -2
- package/dist/modules/sso-oidc/oidc.service.ee.js +86 -8
- package/dist/modules/sso-oidc/oidc.service.ee.js.map +1 -1
- package/dist/modules/sso-oidc/views/oidc-test-result.d.ts +5 -0
- package/dist/modules/sso-oidc/views/oidc-test-result.js +58 -0
- package/dist/modules/sso-oidc/views/oidc-test-result.js.map +1 -0
- package/dist/modules/sso-saml/saml-helpers.d.ts +1 -0
- package/dist/modules/sso-saml/saml-helpers.js +2 -0
- package/dist/modules/sso-saml/saml-helpers.js.map +1 -1
- package/dist/modules/sso-saml/saml.service.ee.d.ts +4 -1
- package/dist/modules/sso-saml/saml.service.ee.js +13 -7
- package/dist/modules/sso-saml/saml.service.ee.js.map +1 -1
- package/dist/modules/token-exchange/controllers/embed-auth.controller.d.ts +15 -0
- package/dist/modules/token-exchange/controllers/embed-auth.controller.js +67 -0
- package/dist/modules/token-exchange/controllers/embed-auth.controller.js.map +1 -0
- package/dist/modules/token-exchange/database/entities/token-exchange-jti.entity.d.ts +5 -0
- package/dist/modules/token-exchange/database/entities/token-exchange-jti.entity.js +33 -0
- package/dist/modules/token-exchange/database/entities/token-exchange-jti.entity.js.map +1 -0
- package/dist/modules/token-exchange/database/repositories/token-exchange-jti.repository.d.ts +10 -0
- package/dist/modules/token-exchange/database/repositories/token-exchange-jti.repository.js +106 -0
- package/dist/modules/token-exchange/database/repositories/token-exchange-jti.repository.js.map +1 -0
- package/dist/modules/token-exchange/services/identity-resolution.service.d.ts +5 -0
- package/dist/modules/token-exchange/services/identity-resolution.service.js +21 -0
- package/dist/modules/token-exchange/services/identity-resolution.service.js.map +1 -0
- package/dist/modules/token-exchange/services/jti-cleanup.service.d.ts +18 -0
- package/dist/modules/token-exchange/services/jti-cleanup.service.js +90 -0
- package/dist/modules/token-exchange/services/jti-cleanup.service.js.map +1 -0
- package/dist/modules/token-exchange/services/jti-store.service.d.ts +6 -0
- package/dist/modules/token-exchange/services/jti-store.service.js +30 -0
- package/dist/modules/token-exchange/services/jti-store.service.js.map +1 -0
- package/dist/modules/token-exchange/services/token-exchange.service.d.ts +17 -0
- package/dist/modules/token-exchange/services/token-exchange.service.js +93 -0
- package/dist/modules/token-exchange/services/token-exchange.service.js.map +1 -0
- package/dist/modules/token-exchange/services/trusted-key.service.d.ts +13 -0
- package/dist/modules/token-exchange/services/trusted-key.service.js +123 -0
- package/dist/modules/token-exchange/services/trusted-key.service.js.map +1 -0
- package/dist/modules/token-exchange/token-exchange.config.d.ts +7 -0
- package/dist/modules/token-exchange/token-exchange.config.js +47 -0
- package/dist/modules/token-exchange/token-exchange.config.js.map +1 -0
- package/dist/modules/token-exchange/token-exchange.controller.d.ts +9 -0
- package/dist/modules/token-exchange/token-exchange.controller.js +103 -0
- package/dist/modules/token-exchange/token-exchange.controller.js.map +1 -0
- package/dist/modules/token-exchange/token-exchange.module.d.ts +5 -0
- package/dist/modules/token-exchange/token-exchange.module.js +74 -0
- package/dist/modules/token-exchange/token-exchange.module.js.map +1 -0
- package/dist/modules/token-exchange/token-exchange.schemas.d.ts +131 -0
- package/dist/modules/token-exchange/token-exchange.schemas.js +60 -0
- package/dist/modules/token-exchange/token-exchange.schemas.js.map +1 -0
- package/dist/modules/token-exchange/token-exchange.service.d.ts +9 -0
- package/dist/modules/token-exchange/token-exchange.service.js +66 -0
- package/dist/modules/token-exchange/token-exchange.service.js.map +1 -0
- package/dist/modules/token-exchange/token-exchange.types.d.ts +50 -0
- package/dist/modules/token-exchange/token-exchange.types.js +3 -0
- package/dist/modules/token-exchange/token-exchange.types.js.map +1 -0
- package/dist/public-api/index.js +5 -5
- package/dist/public-api/index.js.map +1 -1
- package/dist/public-api/types.d.ts +17 -0
- package/dist/public-api/v1/handlers/community-packages/community-packages.handler.d.ts +18 -0
- package/dist/public-api/v1/handlers/community-packages/community-packages.handler.js +71 -0
- package/dist/public-api/v1/handlers/community-packages/community-packages.handler.js.map +1 -0
- package/dist/public-api/v1/handlers/community-packages/community-packages.mapper.d.ts +27 -0
- package/dist/public-api/v1/handlers/community-packages/community-packages.mapper.js +35 -0
- package/dist/public-api/v1/handlers/community-packages/community-packages.mapper.js.map +1 -0
- package/dist/public-api/v1/handlers/executions/executions.handler.js +48 -4
- package/dist/public-api/v1/handlers/executions/executions.handler.js.map +1 -1
- package/dist/public-api/v1/openapi.yml +208 -2
- package/dist/public-api/v1/public-api-error-response.d.ts +2 -0
- package/dist/public-api/v1/public-api-error-response.js +11 -0
- package/dist/public-api/v1/public-api-error-response.js.map +1 -0
- package/dist/push/abstract.push.d.ts +1 -0
- package/dist/push/abstract.push.js +3 -0
- package/dist/push/abstract.push.js.map +1 -1
- package/dist/push/sse.push.js +5 -1
- package/dist/push/sse.push.js.map +1 -1
- package/dist/push/websocket.push.js +3 -1
- package/dist/push/websocket.push.js.map +1 -1
- package/dist/response-helper.js +6 -29
- package/dist/response-helper.js.map +1 -1
- package/dist/scaling/pubsub/subscriber.service.d.ts +2 -0
- package/dist/scaling/pubsub/subscriber.service.js +17 -8
- package/dist/scaling/pubsub/subscriber.service.js.map +1 -1
- package/dist/scaling/redis/redis.types.d.ts +1 -1
- package/dist/services/ai-workflow-builder.service.d.ts +2 -2
- package/dist/services/ai-workflow-builder.service.js +4 -4
- package/dist/services/ai-workflow-builder.service.js.map +1 -1
- package/dist/services/ai.service.d.ts +4 -0
- package/dist/services/ai.service.js +20 -18
- package/dist/services/ai.service.js.map +1 -1
- package/dist/services/auth-strategy.registry.d.ts +7 -0
- package/dist/services/auth-strategy.registry.js +32 -0
- package/dist/services/auth-strategy.registry.js.map +1 -0
- package/dist/services/auth-strategy.types.d.ts +4 -0
- package/dist/services/auth-strategy.types.js +3 -0
- package/dist/services/auth-strategy.types.js.map +1 -0
- package/dist/services/credentials-tester.service.js +2 -0
- package/dist/services/credentials-tester.service.js.map +1 -1
- package/dist/services/db-clock.service.d.ts +10 -0
- package/dist/services/db-clock.service.js +48 -0
- package/dist/services/db-clock.service.js.map +1 -0
- package/dist/services/frontend.service.js +2 -0
- package/dist/services/frontend.service.js.map +1 -1
- package/dist/wait-tracker.d.ts +6 -2
- package/dist/wait-tracker.js +94 -63
- package/dist/wait-tracker.js.map +1 -1
- package/dist/webhooks/live-webhooks.js +24 -18
- package/dist/webhooks/live-webhooks.js.map +1 -1
- package/dist/webhooks/test-webhooks.js +96 -78
- package/dist/webhooks/test-webhooks.js.map +1 -1
- package/dist/webhooks/waiting-webhooks.js +27 -21
- package/dist/webhooks/waiting-webhooks.js.map +1 -1
- package/dist/webhooks/webhook-helpers.js +21 -6
- package/dist/webhooks/webhook-helpers.js.map +1 -1
- package/dist/webhooks/webhook-last-node-response-extractor.d.ts +5 -2
- package/dist/webhooks/webhook-last-node-response-extractor.js +5 -8
- package/dist/webhooks/webhook-last-node-response-extractor.js.map +1 -1
- package/dist/workflows/workflow-creation.service.js +4 -0
- package/dist/workflows/workflow-creation.service.js.map +1 -1
- package/dist/workflows/workflow-execution.service.js +1 -1
- package/dist/workflows/workflow-execution.service.js.map +1 -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.js +3 -3
- package/dist/workflows/workflow-validation.service.js.map +1 -1
- package/dist/workflows/workflow.service.js +12 -1
- package/dist/workflows/workflow.service.js.map +1 -1
- package/dist/workflows/workflows.controller.d.ts +2 -2
- package/package.json +28 -25
|
@@ -0,0 +1,853 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var TypeORMMemoryStorage_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.TypeORMMemoryStorage = void 0;
|
|
14
|
+
const node_crypto_1 = require("node:crypto");
|
|
15
|
+
const storage_1 = require("@mastra/core/storage");
|
|
16
|
+
const di_1 = require("@n8n/di");
|
|
17
|
+
const instance_ai_1 = require("@n8n/instance-ai");
|
|
18
|
+
const typeorm_1 = require("@n8n/typeorm");
|
|
19
|
+
const utils_1 = require("@n8n/utils");
|
|
20
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
21
|
+
const instance_ai_message_repository_1 = require("../repositories/instance-ai-message.repository");
|
|
22
|
+
const instance_ai_observational_memory_repository_1 = require("../repositories/instance-ai-observational-memory.repository");
|
|
23
|
+
const instance_ai_resource_repository_1 = require("../repositories/instance-ai-resource.repository");
|
|
24
|
+
const instance_ai_thread_repository_1 = require("../repositories/instance-ai-thread.repository");
|
|
25
|
+
const PATCH_ONLY_METADATA_KEYS = ['instanceAiPlannedTasks'];
|
|
26
|
+
function countLines(value) {
|
|
27
|
+
return value === '' ? 0 : value.split(/\r?\n/u).length;
|
|
28
|
+
}
|
|
29
|
+
function buildResourceTraceMetadata(resourceId) {
|
|
30
|
+
const separatorIndex = resourceId.indexOf(':');
|
|
31
|
+
return {
|
|
32
|
+
resource_id: resourceId,
|
|
33
|
+
memory_scope: separatorIndex === -1 ? 'user' : 'user-role',
|
|
34
|
+
...(separatorIndex !== -1 && separatorIndex < resourceId.length - 1
|
|
35
|
+
? { memory_role: resourceId.slice(separatorIndex + 1) }
|
|
36
|
+
: {}),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function summarizeLoadedResource(resource) {
|
|
40
|
+
const workingMemory = resource?.workingMemory;
|
|
41
|
+
return {
|
|
42
|
+
found: resource !== null,
|
|
43
|
+
has_working_memory: typeof workingMemory === 'string' && workingMemory.length > 0,
|
|
44
|
+
working_memory_chars: typeof workingMemory === 'string' ? workingMemory.length : 0,
|
|
45
|
+
working_memory_lines: typeof workingMemory === 'string' ? countLines(workingMemory) : 0,
|
|
46
|
+
metadata_keys: resource?.metadata ? Object.keys(resource.metadata).length : 0,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
let TypeORMMemoryStorage = TypeORMMemoryStorage_1 = class TypeORMMemoryStorage extends storage_1.MemoryStorage {
|
|
50
|
+
constructor(threadRepo, messageRepo, resourceRepo, omRepo) {
|
|
51
|
+
super();
|
|
52
|
+
this.threadRepo = threadRepo;
|
|
53
|
+
this.messageRepo = messageRepo;
|
|
54
|
+
this.resourceRepo = resourceRepo;
|
|
55
|
+
this.omRepo = omRepo;
|
|
56
|
+
this.supportsObservationalMemory = true;
|
|
57
|
+
}
|
|
58
|
+
async dangerouslyClearAll() {
|
|
59
|
+
await this.omRepo.clear();
|
|
60
|
+
await this.messageRepo.clear();
|
|
61
|
+
await this.threadRepo.clear();
|
|
62
|
+
await this.resourceRepo.clear();
|
|
63
|
+
}
|
|
64
|
+
async getThreadById({ threadId }) {
|
|
65
|
+
const entity = await this.threadRepo.findOneBy({ id: threadId });
|
|
66
|
+
if (!entity)
|
|
67
|
+
return null;
|
|
68
|
+
return this.toStorageThread(entity);
|
|
69
|
+
}
|
|
70
|
+
async listThreads(args) {
|
|
71
|
+
const page = args.page ?? 0;
|
|
72
|
+
const perPageInput = args.perPage;
|
|
73
|
+
const perPage = perPageInput === false ? Number.MAX_SAFE_INTEGER : (perPageInput ?? 100);
|
|
74
|
+
const { field, direction } = this.parseOrderBy(args.orderBy);
|
|
75
|
+
const where = {};
|
|
76
|
+
if (args.filter?.resourceId)
|
|
77
|
+
where.resourceId = args.filter.resourceId;
|
|
78
|
+
const metadataFilter = args.filter?.metadata;
|
|
79
|
+
const hasMetadataFilter = metadataFilter && Object.keys(metadataFilter).length > 0;
|
|
80
|
+
if (hasMetadataFilter) {
|
|
81
|
+
this.validateMetadataKeys(metadataFilter);
|
|
82
|
+
const allEntities = await this.threadRepo.find({
|
|
83
|
+
where,
|
|
84
|
+
order: { [field]: direction },
|
|
85
|
+
});
|
|
86
|
+
const allThreads = allEntities
|
|
87
|
+
.map((e) => ({
|
|
88
|
+
id: e.id,
|
|
89
|
+
title: e.title,
|
|
90
|
+
resourceId: e.resourceId,
|
|
91
|
+
metadata: e.metadata ?? undefined,
|
|
92
|
+
createdAt: e.createdAt,
|
|
93
|
+
updatedAt: e.updatedAt,
|
|
94
|
+
}))
|
|
95
|
+
.filter((t) => {
|
|
96
|
+
if (!t.metadata)
|
|
97
|
+
return false;
|
|
98
|
+
return Object.entries(args.filter.metadata).every(([k, v]) => t.metadata[k] === v);
|
|
99
|
+
});
|
|
100
|
+
const total = allThreads.length;
|
|
101
|
+
const offset = page * perPage;
|
|
102
|
+
const paged = allThreads.slice(offset, offset + perPage);
|
|
103
|
+
return {
|
|
104
|
+
threads: paged,
|
|
105
|
+
total,
|
|
106
|
+
page,
|
|
107
|
+
perPage: perPageInput ?? 100,
|
|
108
|
+
hasMore: offset + perPage < total,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const [entities, total] = await this.threadRepo.findAndCount({
|
|
112
|
+
where,
|
|
113
|
+
order: { [field]: direction },
|
|
114
|
+
skip: page * perPage,
|
|
115
|
+
take: perPage,
|
|
116
|
+
});
|
|
117
|
+
const threads = entities.map((e) => ({
|
|
118
|
+
id: e.id,
|
|
119
|
+
title: e.title,
|
|
120
|
+
resourceId: e.resourceId,
|
|
121
|
+
metadata: e.metadata ?? undefined,
|
|
122
|
+
createdAt: e.createdAt,
|
|
123
|
+
updatedAt: e.updatedAt,
|
|
124
|
+
}));
|
|
125
|
+
return {
|
|
126
|
+
threads,
|
|
127
|
+
total,
|
|
128
|
+
page,
|
|
129
|
+
perPage: perPageInput ?? 100,
|
|
130
|
+
hasMore: (page + 1) * perPage < total,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
async saveThread({ thread, }) {
|
|
134
|
+
return await this.serializeThreadMutation(thread.id, async () => {
|
|
135
|
+
const existing = await this.threadRepo.findOneBy({ id: thread.id });
|
|
136
|
+
if (existing) {
|
|
137
|
+
const safeIncoming = { ...(thread.metadata ?? {}) };
|
|
138
|
+
for (const key of PATCH_ONLY_METADATA_KEYS) {
|
|
139
|
+
delete safeIncoming[key];
|
|
140
|
+
}
|
|
141
|
+
existing.title = thread.title ?? existing.title;
|
|
142
|
+
existing.resourceId = thread.resourceId ?? existing.resourceId;
|
|
143
|
+
existing.metadata = {
|
|
144
|
+
...(existing.metadata ?? {}),
|
|
145
|
+
...safeIncoming,
|
|
146
|
+
};
|
|
147
|
+
const saved = await this.threadRepo.save(existing);
|
|
148
|
+
return this.toStorageThread(saved);
|
|
149
|
+
}
|
|
150
|
+
const entity = this.threadRepo.create({
|
|
151
|
+
id: thread.id,
|
|
152
|
+
resourceId: thread.resourceId,
|
|
153
|
+
title: thread.title ?? '',
|
|
154
|
+
metadata: thread.metadata ?? null,
|
|
155
|
+
});
|
|
156
|
+
const saved = await this.threadRepo.save(entity);
|
|
157
|
+
return this.toStorageThread(saved);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
async updateThread({ id, title, metadata, }) {
|
|
161
|
+
return await this.serializeThreadMutation(id, async () => {
|
|
162
|
+
const entity = await this.threadRepo.findOneByOrFail({ id });
|
|
163
|
+
const safeIncoming = { ...metadata };
|
|
164
|
+
for (const key of PATCH_ONLY_METADATA_KEYS) {
|
|
165
|
+
delete safeIncoming[key];
|
|
166
|
+
}
|
|
167
|
+
entity.title = title;
|
|
168
|
+
entity.metadata = {
|
|
169
|
+
...(entity.metadata ?? {}),
|
|
170
|
+
...safeIncoming,
|
|
171
|
+
};
|
|
172
|
+
const updated = await this.threadRepo.save(entity);
|
|
173
|
+
return this.toStorageThread(updated);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
async patchThread({ threadId, update, }) {
|
|
177
|
+
return await this.serializeThreadMutation(threadId, async () => {
|
|
178
|
+
const entity = await this.threadRepo.findOneBy({ id: threadId });
|
|
179
|
+
if (!entity)
|
|
180
|
+
return null;
|
|
181
|
+
const current = this.toStorageThread(entity);
|
|
182
|
+
const patch = update({
|
|
183
|
+
...current,
|
|
184
|
+
metadata: { ...(current.metadata ?? {}) },
|
|
185
|
+
});
|
|
186
|
+
if (!patch)
|
|
187
|
+
return current;
|
|
188
|
+
if (patch.title !== undefined) {
|
|
189
|
+
entity.title = patch.title;
|
|
190
|
+
}
|
|
191
|
+
if (patch.metadata !== undefined) {
|
|
192
|
+
entity.metadata = patch.metadata;
|
|
193
|
+
}
|
|
194
|
+
const updated = await this.threadRepo.save(entity);
|
|
195
|
+
return this.toStorageThread(updated);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
async deleteThread({ threadId }) {
|
|
199
|
+
await this.threadRepo.delete(threadId);
|
|
200
|
+
}
|
|
201
|
+
toStorageThread(entity) {
|
|
202
|
+
return {
|
|
203
|
+
id: entity.id,
|
|
204
|
+
title: entity.title,
|
|
205
|
+
resourceId: entity.resourceId,
|
|
206
|
+
metadata: entity.metadata ?? undefined,
|
|
207
|
+
createdAt: entity.createdAt,
|
|
208
|
+
updatedAt: entity.updatedAt,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
async serializeThreadMutation(threadId, mutation) {
|
|
212
|
+
const queues = TypeORMMemoryStorage_1.threadMutationQueues;
|
|
213
|
+
const previous = queues.get(threadId) ?? Promise.resolve();
|
|
214
|
+
const previousSettled = previous.catch(() => { });
|
|
215
|
+
let releaseCurrent;
|
|
216
|
+
const current = new Promise((resolve) => {
|
|
217
|
+
releaseCurrent = resolve;
|
|
218
|
+
});
|
|
219
|
+
const queued = previousSettled.then(async () => await current);
|
|
220
|
+
queues.set(threadId, queued);
|
|
221
|
+
await previousSettled;
|
|
222
|
+
try {
|
|
223
|
+
return await mutation();
|
|
224
|
+
}
|
|
225
|
+
finally {
|
|
226
|
+
releaseCurrent();
|
|
227
|
+
if (queues.get(threadId) === queued) {
|
|
228
|
+
queues.delete(threadId);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
async listMessages(args) {
|
|
233
|
+
if (args.include?.length) {
|
|
234
|
+
const included = await this.getIncludedMessages(args);
|
|
235
|
+
return {
|
|
236
|
+
messages: included,
|
|
237
|
+
total: included.length,
|
|
238
|
+
page: 0,
|
|
239
|
+
perPage: false,
|
|
240
|
+
hasMore: false,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
const threadIds = Array.isArray(args.threadId) ? args.threadId : [args.threadId];
|
|
244
|
+
const page = args.page ?? 0;
|
|
245
|
+
const perPageInput = args.perPage;
|
|
246
|
+
const perPage = perPageInput === false ? Number.MAX_SAFE_INTEGER : (perPageInput ?? 40);
|
|
247
|
+
const qb = this.messageRepo
|
|
248
|
+
.createQueryBuilder('m')
|
|
249
|
+
.where('m.threadId IN (:...threadIds)', { threadIds });
|
|
250
|
+
if (args.resourceId) {
|
|
251
|
+
qb.andWhere('m.resourceId = :resourceId', {
|
|
252
|
+
resourceId: args.resourceId,
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
if (args.filter?.dateRange?.start) {
|
|
256
|
+
const op = args.filter.dateRange.startExclusive ? '>' : '>=';
|
|
257
|
+
qb.andWhere(`m.createdAt ${op} :start`, {
|
|
258
|
+
start: args.filter.dateRange.start,
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
if (args.filter?.dateRange?.end) {
|
|
262
|
+
const op = args.filter.dateRange.endExclusive ? '<' : '<=';
|
|
263
|
+
qb.andWhere(`m.createdAt ${op} :end`, {
|
|
264
|
+
end: args.filter.dateRange.end,
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
const { field = 'createdAt', direction = 'ASC' } = args.orderBy ?? {};
|
|
268
|
+
qb.orderBy(`m.${field}`, direction);
|
|
269
|
+
const total = await qb.getCount();
|
|
270
|
+
qb.skip(page * perPage).take(perPage);
|
|
271
|
+
const entities = await qb.getMany();
|
|
272
|
+
const messages = entities.map((e) => this.entityToMessage(e));
|
|
273
|
+
return {
|
|
274
|
+
messages,
|
|
275
|
+
total,
|
|
276
|
+
page,
|
|
277
|
+
perPage: perPageInput ?? 40,
|
|
278
|
+
hasMore: (page + 1) * perPage < total,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
async getIncludedMessages(args) {
|
|
282
|
+
const seen = new Set();
|
|
283
|
+
const result = [];
|
|
284
|
+
const threadIds = Array.isArray(args.threadId) ? args.threadId : [args.threadId];
|
|
285
|
+
for (const inc of args.include ?? []) {
|
|
286
|
+
const anchorThreadIds = inc.threadId ? [inc.threadId] : threadIds;
|
|
287
|
+
const anchor = await this.messageRepo.findOneBy({ id: inc.id });
|
|
288
|
+
if (!anchor)
|
|
289
|
+
continue;
|
|
290
|
+
const collected = [];
|
|
291
|
+
if (inc.withPreviousMessages && inc.withPreviousMessages > 0) {
|
|
292
|
+
const before = await this.messageRepo
|
|
293
|
+
.createQueryBuilder('m')
|
|
294
|
+
.where('m.threadId IN (:...threadIds)', { threadIds: anchorThreadIds })
|
|
295
|
+
.andWhere('m.createdAt < :anchorTime', { anchorTime: anchor.createdAt })
|
|
296
|
+
.orderBy('m.createdAt', 'DESC')
|
|
297
|
+
.take(inc.withPreviousMessages)
|
|
298
|
+
.getMany();
|
|
299
|
+
collected.push(...before.reverse().map((e) => this.entityToMessage(e)));
|
|
300
|
+
}
|
|
301
|
+
collected.push(this.entityToMessage(anchor));
|
|
302
|
+
if (inc.withNextMessages && inc.withNextMessages > 0) {
|
|
303
|
+
const after = await this.messageRepo
|
|
304
|
+
.createQueryBuilder('m')
|
|
305
|
+
.where('m.threadId IN (:...threadIds)', { threadIds: anchorThreadIds })
|
|
306
|
+
.andWhere('m.createdAt > :anchorTime', { anchorTime: anchor.createdAt })
|
|
307
|
+
.orderBy('m.createdAt', 'ASC')
|
|
308
|
+
.take(inc.withNextMessages)
|
|
309
|
+
.getMany();
|
|
310
|
+
collected.push(...after.map((e) => this.entityToMessage(e)));
|
|
311
|
+
}
|
|
312
|
+
for (const msg of collected) {
|
|
313
|
+
if (!seen.has(msg.id)) {
|
|
314
|
+
seen.add(msg.id);
|
|
315
|
+
result.push(msg);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
result.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
|
|
320
|
+
return result;
|
|
321
|
+
}
|
|
322
|
+
async listMessagesByResourceId(args) {
|
|
323
|
+
const page = args.page ?? 0;
|
|
324
|
+
const perPageInput = args.perPage;
|
|
325
|
+
const perPage = perPageInput === false ? Number.MAX_SAFE_INTEGER : (perPageInput ?? 40);
|
|
326
|
+
const qb = this.messageRepo
|
|
327
|
+
.createQueryBuilder('m')
|
|
328
|
+
.where('m.resourceId = :resourceId', { resourceId: args.resourceId });
|
|
329
|
+
if (args.filter?.dateRange?.start) {
|
|
330
|
+
const op = args.filter.dateRange.startExclusive ? '>' : '>=';
|
|
331
|
+
qb.andWhere(`m.createdAt ${op} :start`, {
|
|
332
|
+
start: args.filter.dateRange.start,
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
if (args.filter?.dateRange?.end) {
|
|
336
|
+
const op = args.filter.dateRange.endExclusive ? '<' : '<=';
|
|
337
|
+
qb.andWhere(`m.createdAt ${op} :end`, {
|
|
338
|
+
end: args.filter.dateRange.end,
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
const { field = 'createdAt', direction = 'ASC' } = args.orderBy ?? {};
|
|
342
|
+
qb.orderBy(`m.${field}`, direction);
|
|
343
|
+
const total = await qb.getCount();
|
|
344
|
+
qb.skip(page * perPage).take(perPage);
|
|
345
|
+
const entities = await qb.getMany();
|
|
346
|
+
return {
|
|
347
|
+
messages: entities.map((e) => this.entityToMessage(e)),
|
|
348
|
+
total,
|
|
349
|
+
page,
|
|
350
|
+
perPage: perPageInput ?? 40,
|
|
351
|
+
hasMore: (page + 1) * perPage < total,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
async listMessagesById({ messageIds, }) {
|
|
355
|
+
if (messageIds.length === 0)
|
|
356
|
+
return { messages: [] };
|
|
357
|
+
const entities = await this.messageRepo.findBy({ id: (0, typeorm_1.In)(messageIds) });
|
|
358
|
+
return { messages: entities.map((e) => this.entityToMessage(e)) };
|
|
359
|
+
}
|
|
360
|
+
async saveMessages({ messages, }) {
|
|
361
|
+
const entities = messages.map((m) => {
|
|
362
|
+
if (!m.threadId) {
|
|
363
|
+
throw new Error(`Message ${m.id} is missing required threadId`);
|
|
364
|
+
}
|
|
365
|
+
const entity = this.messageRepo.create({
|
|
366
|
+
id: m.id,
|
|
367
|
+
threadId: m.threadId,
|
|
368
|
+
content: JSON.stringify(m.content),
|
|
369
|
+
role: m.role,
|
|
370
|
+
type: m.type ?? null,
|
|
371
|
+
resourceId: m.resourceId ?? null,
|
|
372
|
+
});
|
|
373
|
+
if (m.createdAt) {
|
|
374
|
+
entity.createdAt = m.createdAt;
|
|
375
|
+
}
|
|
376
|
+
return entity;
|
|
377
|
+
});
|
|
378
|
+
const saved = await this.messageRepo.save(entities);
|
|
379
|
+
return { messages: saved.map((e) => this.entityToMessage(e)) };
|
|
380
|
+
}
|
|
381
|
+
async updateMessages({ messages, }) {
|
|
382
|
+
const result = [];
|
|
383
|
+
for (const msg of messages) {
|
|
384
|
+
const existing = await this.messageRepo.findOneBy({ id: msg.id });
|
|
385
|
+
if (!existing)
|
|
386
|
+
continue;
|
|
387
|
+
const updates = {};
|
|
388
|
+
if (msg.role)
|
|
389
|
+
updates.role = msg.role;
|
|
390
|
+
if (msg.type !== undefined)
|
|
391
|
+
updates.type = msg.type;
|
|
392
|
+
if (msg.content) {
|
|
393
|
+
const existingContent = (0, n8n_workflow_1.jsonParse)(existing.content);
|
|
394
|
+
if (msg.content.metadata !== undefined)
|
|
395
|
+
existingContent.metadata = msg.content.metadata;
|
|
396
|
+
if (msg.content.content !== undefined)
|
|
397
|
+
existingContent.content = msg.content.content;
|
|
398
|
+
updates.content = JSON.stringify(existingContent);
|
|
399
|
+
}
|
|
400
|
+
if (Object.keys(updates).length > 0) {
|
|
401
|
+
await this.messageRepo.update(msg.id, updates);
|
|
402
|
+
}
|
|
403
|
+
const updated = await this.messageRepo.findOneByOrFail({ id: msg.id });
|
|
404
|
+
result.push(this.entityToMessage(updated));
|
|
405
|
+
}
|
|
406
|
+
return result;
|
|
407
|
+
}
|
|
408
|
+
async deleteMessages(messageIds) {
|
|
409
|
+
if (messageIds.length === 0)
|
|
410
|
+
return;
|
|
411
|
+
await this.messageRepo.delete(messageIds);
|
|
412
|
+
}
|
|
413
|
+
async getResourceById({ resourceId, }) {
|
|
414
|
+
return await (0, instance_ai_1.withCurrentTraceSpan)({
|
|
415
|
+
name: 'memory_load',
|
|
416
|
+
tags: ['memory', 'internal'],
|
|
417
|
+
metadata: buildResourceTraceMetadata(resourceId),
|
|
418
|
+
inputs: { resource_id: resourceId },
|
|
419
|
+
processOutputs: summarizeLoadedResource,
|
|
420
|
+
}, async () => {
|
|
421
|
+
const entity = await this.resourceRepo.findOneBy({ id: resourceId });
|
|
422
|
+
if (!entity)
|
|
423
|
+
return null;
|
|
424
|
+
return {
|
|
425
|
+
id: entity.id,
|
|
426
|
+
workingMemory: entity.workingMemory ?? undefined,
|
|
427
|
+
metadata: entity.metadata ?? undefined,
|
|
428
|
+
createdAt: entity.createdAt,
|
|
429
|
+
updatedAt: entity.updatedAt,
|
|
430
|
+
};
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
async saveResource({ resource, }) {
|
|
434
|
+
const entity = this.resourceRepo.create({
|
|
435
|
+
id: resource.id,
|
|
436
|
+
workingMemory: resource.workingMemory ?? null,
|
|
437
|
+
metadata: resource.metadata ?? null,
|
|
438
|
+
});
|
|
439
|
+
const saved = await this.resourceRepo.save(entity);
|
|
440
|
+
return {
|
|
441
|
+
id: saved.id,
|
|
442
|
+
workingMemory: saved.workingMemory ?? undefined,
|
|
443
|
+
metadata: saved.metadata ?? undefined,
|
|
444
|
+
createdAt: saved.createdAt,
|
|
445
|
+
updatedAt: saved.updatedAt,
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
async updateResource({ resourceId, workingMemory, metadata, }) {
|
|
449
|
+
let existing = await this.resourceRepo.findOneBy({ id: resourceId });
|
|
450
|
+
if (!existing) {
|
|
451
|
+
existing = await this.resourceRepo.save(this.resourceRepo.create({
|
|
452
|
+
id: resourceId,
|
|
453
|
+
workingMemory: workingMemory ?? null,
|
|
454
|
+
metadata: metadata ?? null,
|
|
455
|
+
}));
|
|
456
|
+
}
|
|
457
|
+
else {
|
|
458
|
+
if (workingMemory !== undefined)
|
|
459
|
+
existing.workingMemory = workingMemory;
|
|
460
|
+
if (metadata !== undefined)
|
|
461
|
+
existing.metadata = metadata;
|
|
462
|
+
existing = await this.resourceRepo.save(existing);
|
|
463
|
+
}
|
|
464
|
+
return {
|
|
465
|
+
id: existing.id,
|
|
466
|
+
workingMemory: existing.workingMemory ?? undefined,
|
|
467
|
+
metadata: existing.metadata ?? undefined,
|
|
468
|
+
createdAt: existing.createdAt,
|
|
469
|
+
updatedAt: existing.updatedAt,
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
async cloneThread(args) {
|
|
473
|
+
const source = await this.getThreadById({
|
|
474
|
+
threadId: args.sourceThreadId,
|
|
475
|
+
});
|
|
476
|
+
if (!source)
|
|
477
|
+
throw new Error(`Source thread ${args.sourceThreadId} not found`);
|
|
478
|
+
const newThreadId = args.newThreadId ?? (0, node_crypto_1.randomUUID)();
|
|
479
|
+
const cloneMetadata = {
|
|
480
|
+
...(source.metadata ?? {}),
|
|
481
|
+
...(args.metadata ?? {}),
|
|
482
|
+
mastra: {
|
|
483
|
+
...(source.metadata?.mastra ?? {}),
|
|
484
|
+
clone: {
|
|
485
|
+
sourceThreadId: args.sourceThreadId,
|
|
486
|
+
clonedAt: new Date(),
|
|
487
|
+
},
|
|
488
|
+
},
|
|
489
|
+
};
|
|
490
|
+
const newThread = await this.saveThread({
|
|
491
|
+
thread: {
|
|
492
|
+
id: newThreadId,
|
|
493
|
+
resourceId: args.resourceId ?? source.resourceId,
|
|
494
|
+
title: args.title ?? source.title,
|
|
495
|
+
metadata: cloneMetadata,
|
|
496
|
+
createdAt: new Date(),
|
|
497
|
+
updatedAt: new Date(),
|
|
498
|
+
},
|
|
499
|
+
});
|
|
500
|
+
const { messages: sourceMessages } = await this.listMessages({
|
|
501
|
+
threadId: args.sourceThreadId,
|
|
502
|
+
perPage: false,
|
|
503
|
+
orderBy: { field: 'createdAt', direction: 'ASC' },
|
|
504
|
+
});
|
|
505
|
+
let messagesToClone = sourceMessages;
|
|
506
|
+
if (args.options?.messageLimit) {
|
|
507
|
+
messagesToClone = messagesToClone.slice(-args.options.messageLimit);
|
|
508
|
+
}
|
|
509
|
+
const messageIdMap = {};
|
|
510
|
+
const clonedMessages = messagesToClone.map((m) => {
|
|
511
|
+
const newId = (0, utils_1.generateNanoId)();
|
|
512
|
+
messageIdMap[m.id] = newId;
|
|
513
|
+
return { ...m, id: newId, threadId: newThreadId };
|
|
514
|
+
});
|
|
515
|
+
if (clonedMessages.length > 0) {
|
|
516
|
+
await this.saveMessages({ messages: clonedMessages });
|
|
517
|
+
}
|
|
518
|
+
return { thread: newThread, clonedMessages, messageIdMap };
|
|
519
|
+
}
|
|
520
|
+
omLookupKey(scope, threadId, resourceId) {
|
|
521
|
+
return `${scope}:${threadId ?? 'null'}:${resourceId}`;
|
|
522
|
+
}
|
|
523
|
+
entityToOMRecord(entity) {
|
|
524
|
+
return {
|
|
525
|
+
id: entity.id,
|
|
526
|
+
scope: entity.scope,
|
|
527
|
+
threadId: entity.threadId,
|
|
528
|
+
resourceId: entity.resourceId,
|
|
529
|
+
createdAt: entity.createdAt,
|
|
530
|
+
updatedAt: entity.updatedAt,
|
|
531
|
+
lastObservedAt: entity.lastObservedAt ?? undefined,
|
|
532
|
+
originType: entity.originType,
|
|
533
|
+
generationCount: entity.generationCount,
|
|
534
|
+
activeObservations: entity.activeObservations,
|
|
535
|
+
bufferedObservationChunks: (entity.bufferedObservationChunks ??
|
|
536
|
+
undefined),
|
|
537
|
+
bufferedObservations: entity.bufferedObservations ?? undefined,
|
|
538
|
+
bufferedObservationTokens: entity.bufferedObservationTokens ?? undefined,
|
|
539
|
+
bufferedMessageIds: entity.bufferedMessageIds ?? undefined,
|
|
540
|
+
bufferedReflection: entity.bufferedReflection ?? undefined,
|
|
541
|
+
bufferedReflectionTokens: entity.bufferedReflectionTokens ?? undefined,
|
|
542
|
+
bufferedReflectionInputTokens: entity.bufferedReflectionInputTokens ?? undefined,
|
|
543
|
+
reflectedObservationLineCount: entity.reflectedObservationLineCount ?? undefined,
|
|
544
|
+
observedMessageIds: entity.observedMessageIds ?? undefined,
|
|
545
|
+
observedTimezone: entity.observedTimezone ?? undefined,
|
|
546
|
+
totalTokensObserved: entity.totalTokensObserved,
|
|
547
|
+
observationTokenCount: entity.observationTokenCount,
|
|
548
|
+
pendingMessageTokens: entity.pendingMessageTokens,
|
|
549
|
+
isReflecting: entity.isReflecting,
|
|
550
|
+
isObserving: entity.isObserving,
|
|
551
|
+
isBufferingObservation: entity.isBufferingObservation,
|
|
552
|
+
isBufferingReflection: entity.isBufferingReflection,
|
|
553
|
+
lastBufferedAtTokens: entity.lastBufferedAtTokens,
|
|
554
|
+
lastBufferedAtTime: entity.lastBufferedAtTime,
|
|
555
|
+
config: typeof entity.config === 'string' ? (0, n8n_workflow_1.jsonParse)(entity.config) : entity.config,
|
|
556
|
+
metadata: entity.metadata ?? undefined,
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
async getObservationalMemory(threadId, resourceId) {
|
|
560
|
+
const lookupKey = this.omLookupKey(threadId ? 'thread' : 'resource', threadId, resourceId);
|
|
561
|
+
const entity = await this.omRepo.findOne({
|
|
562
|
+
where: { lookupKey },
|
|
563
|
+
order: { generationCount: 'DESC' },
|
|
564
|
+
});
|
|
565
|
+
if (!entity)
|
|
566
|
+
return null;
|
|
567
|
+
return this.entityToOMRecord(entity);
|
|
568
|
+
}
|
|
569
|
+
async getObservationalMemoryHistory(threadId, resourceId, limit = 10) {
|
|
570
|
+
const scope = threadId ? 'thread' : 'resource';
|
|
571
|
+
const entities = await this.omRepo.find({
|
|
572
|
+
where: { scope, threadId: threadId ?? undefined, resourceId },
|
|
573
|
+
order: { generationCount: 'DESC' },
|
|
574
|
+
take: limit,
|
|
575
|
+
});
|
|
576
|
+
return entities.map((e) => this.entityToOMRecord(e));
|
|
577
|
+
}
|
|
578
|
+
async initializeObservationalMemory(input) {
|
|
579
|
+
const id = (0, utils_1.generateNanoId)();
|
|
580
|
+
const lookupKey = this.omLookupKey(input.scope, input.threadId, input.resourceId);
|
|
581
|
+
const entity = this.omRepo.create({
|
|
582
|
+
id,
|
|
583
|
+
lookupKey,
|
|
584
|
+
scope: input.scope,
|
|
585
|
+
threadId: input.threadId,
|
|
586
|
+
resourceId: input.resourceId,
|
|
587
|
+
originType: 'initial',
|
|
588
|
+
config: JSON.stringify(input.config),
|
|
589
|
+
observedTimezone: input.observedTimezone ?? null,
|
|
590
|
+
});
|
|
591
|
+
const saved = await this.omRepo.save(entity);
|
|
592
|
+
return this.entityToOMRecord(saved);
|
|
593
|
+
}
|
|
594
|
+
async insertObservationalMemoryRecord(record) {
|
|
595
|
+
const lookupKey = this.omLookupKey(record.scope, record.threadId, record.resourceId);
|
|
596
|
+
const entity = this.omRepo.create({
|
|
597
|
+
id: record.id,
|
|
598
|
+
lookupKey,
|
|
599
|
+
scope: record.scope,
|
|
600
|
+
threadId: record.threadId,
|
|
601
|
+
resourceId: record.resourceId,
|
|
602
|
+
activeObservations: record.activeObservations,
|
|
603
|
+
originType: record.originType,
|
|
604
|
+
config: JSON.stringify(record.config),
|
|
605
|
+
generationCount: record.generationCount,
|
|
606
|
+
lastObservedAt: record.lastObservedAt ?? null,
|
|
607
|
+
pendingMessageTokens: record.pendingMessageTokens,
|
|
608
|
+
totalTokensObserved: record.totalTokensObserved,
|
|
609
|
+
observationTokenCount: record.observationTokenCount,
|
|
610
|
+
isObserving: record.isObserving,
|
|
611
|
+
isReflecting: record.isReflecting,
|
|
612
|
+
observedMessageIds: record.observedMessageIds ?? null,
|
|
613
|
+
observedTimezone: record.observedTimezone ?? null,
|
|
614
|
+
bufferedObservations: record.bufferedObservations ?? null,
|
|
615
|
+
bufferedObservationTokens: record.bufferedObservationTokens ?? null,
|
|
616
|
+
bufferedMessageIds: record.bufferedMessageIds ?? null,
|
|
617
|
+
bufferedReflection: record.bufferedReflection ?? null,
|
|
618
|
+
bufferedReflectionTokens: record.bufferedReflectionTokens ?? null,
|
|
619
|
+
bufferedReflectionInputTokens: record.bufferedReflectionInputTokens ?? null,
|
|
620
|
+
reflectedObservationLineCount: record.reflectedObservationLineCount ?? null,
|
|
621
|
+
bufferedObservationChunks: (record.bufferedObservationChunks ?? null),
|
|
622
|
+
isBufferingObservation: record.isBufferingObservation,
|
|
623
|
+
isBufferingReflection: record.isBufferingReflection,
|
|
624
|
+
lastBufferedAtTokens: record.lastBufferedAtTokens,
|
|
625
|
+
lastBufferedAtTime: record.lastBufferedAtTime ?? null,
|
|
626
|
+
metadata: record.metadata ?? null,
|
|
627
|
+
});
|
|
628
|
+
await this.omRepo.save(entity);
|
|
629
|
+
}
|
|
630
|
+
async updateActiveObservations(input) {
|
|
631
|
+
const entity = await this.omRepo.findOneByOrFail({ id: input.id });
|
|
632
|
+
const existingIds = entity.observedMessageIds ?? [];
|
|
633
|
+
const mergedIds = [...new Set([...existingIds, ...(input.observedMessageIds ?? [])])];
|
|
634
|
+
await this.omRepo.update(input.id, {
|
|
635
|
+
activeObservations: input.observations,
|
|
636
|
+
observationTokenCount: input.tokenCount,
|
|
637
|
+
lastObservedAt: input.lastObservedAt,
|
|
638
|
+
observedMessageIds: mergedIds,
|
|
639
|
+
observedTimezone: input.observedTimezone ?? entity.observedTimezone,
|
|
640
|
+
totalTokensObserved: entity.totalTokensObserved + input.tokenCount,
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
async updateBufferedObservations(input) {
|
|
644
|
+
const entity = await this.omRepo.findOneByOrFail({ id: input.id });
|
|
645
|
+
const chunks = entity.bufferedObservationChunks ?? [];
|
|
646
|
+
chunks.push(input.chunk);
|
|
647
|
+
const updates = {
|
|
648
|
+
bufferedObservationChunks: chunks,
|
|
649
|
+
};
|
|
650
|
+
if (input.lastBufferedAtTime) {
|
|
651
|
+
updates.lastBufferedAtTime = input.lastBufferedAtTime;
|
|
652
|
+
}
|
|
653
|
+
await this.omRepo.update(input.id, updates);
|
|
654
|
+
}
|
|
655
|
+
async swapBufferedToActive(input) {
|
|
656
|
+
const entity = await this.omRepo.findOneByOrFail({ id: input.id });
|
|
657
|
+
const record = this.entityToOMRecord(entity);
|
|
658
|
+
const chunks = record.bufferedObservationChunks ?? [];
|
|
659
|
+
if (chunks.length === 0) {
|
|
660
|
+
return {
|
|
661
|
+
chunksActivated: 0,
|
|
662
|
+
messageTokensActivated: 0,
|
|
663
|
+
observationTokensActivated: 0,
|
|
664
|
+
messagesActivated: 0,
|
|
665
|
+
activatedCycleIds: [],
|
|
666
|
+
activatedMessageIds: [],
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
const retentionFloor = input.messageTokensThreshold * (1 - input.activationRatio);
|
|
670
|
+
const tokensToRemove = input.currentPendingTokens - retentionFloor;
|
|
671
|
+
let removedTokens = 0;
|
|
672
|
+
let activatedCount = 0;
|
|
673
|
+
const activated = [];
|
|
674
|
+
const remaining = [];
|
|
675
|
+
for (const chunk of chunks) {
|
|
676
|
+
if (removedTokens < tokensToRemove || (input.forceMaxActivation && remaining.length === 0)) {
|
|
677
|
+
activated.push(chunk);
|
|
678
|
+
removedTokens += chunk.messageTokens ?? 0;
|
|
679
|
+
activatedCount++;
|
|
680
|
+
}
|
|
681
|
+
else {
|
|
682
|
+
remaining.push(chunk);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
let totalMessageTokens = 0;
|
|
686
|
+
let totalObsTokens = 0;
|
|
687
|
+
let totalMessages = 0;
|
|
688
|
+
const allMsgIds = [];
|
|
689
|
+
const cycleIds = [];
|
|
690
|
+
const observationParts = [];
|
|
691
|
+
for (const chunk of activated) {
|
|
692
|
+
totalMessageTokens += chunk.messageTokens ?? 0;
|
|
693
|
+
totalObsTokens += chunk.tokenCount ?? 0;
|
|
694
|
+
totalMessages += chunk.messageIds?.length ?? 0;
|
|
695
|
+
allMsgIds.push(...(chunk.messageIds ?? []));
|
|
696
|
+
if (chunk.cycleId)
|
|
697
|
+
cycleIds.push(chunk.cycleId);
|
|
698
|
+
if (chunk.observations)
|
|
699
|
+
observationParts.push(chunk.observations);
|
|
700
|
+
}
|
|
701
|
+
const newActive = record.activeObservations
|
|
702
|
+
? record.activeObservations + '\n' + observationParts.join('\n')
|
|
703
|
+
: observationParts.join('\n');
|
|
704
|
+
const lastActivatedChunk = activated[activated.length - 1];
|
|
705
|
+
const newLastObservedAt = input.lastObservedAt ??
|
|
706
|
+
(lastActivatedChunk?.lastObservedAt
|
|
707
|
+
? new Date(lastActivatedChunk.lastObservedAt)
|
|
708
|
+
: record.lastObservedAt);
|
|
709
|
+
const existingMsgIds = record.observedMessageIds ?? [];
|
|
710
|
+
const mergedMsgIds = [...new Set([...existingMsgIds, ...allMsgIds])];
|
|
711
|
+
await this.omRepo.update(input.id, {
|
|
712
|
+
activeObservations: newActive,
|
|
713
|
+
observationTokenCount: record.observationTokenCount + totalObsTokens,
|
|
714
|
+
bufferedObservationChunks: remaining.length > 0 ? remaining : null,
|
|
715
|
+
lastObservedAt: newLastObservedAt ?? null,
|
|
716
|
+
observedMessageIds: mergedMsgIds,
|
|
717
|
+
totalTokensObserved: record.totalTokensObserved + totalObsTokens,
|
|
718
|
+
isBufferingObservation: false,
|
|
719
|
+
});
|
|
720
|
+
return {
|
|
721
|
+
chunksActivated: activatedCount,
|
|
722
|
+
messageTokensActivated: totalMessageTokens,
|
|
723
|
+
observationTokensActivated: totalObsTokens,
|
|
724
|
+
messagesActivated: totalMessages,
|
|
725
|
+
activatedCycleIds: cycleIds,
|
|
726
|
+
activatedMessageIds: allMsgIds,
|
|
727
|
+
observations: observationParts.join('\n'),
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
async createReflectionGeneration(input) {
|
|
731
|
+
const { currentRecord, reflection, tokenCount } = input;
|
|
732
|
+
const newId = (0, utils_1.generateNanoId)();
|
|
733
|
+
const lookupKey = this.omLookupKey(currentRecord.scope, currentRecord.threadId, currentRecord.resourceId);
|
|
734
|
+
const entity = this.omRepo.create({
|
|
735
|
+
id: newId,
|
|
736
|
+
lookupKey,
|
|
737
|
+
scope: currentRecord.scope,
|
|
738
|
+
threadId: currentRecord.threadId,
|
|
739
|
+
resourceId: currentRecord.resourceId,
|
|
740
|
+
activeObservations: reflection,
|
|
741
|
+
originType: 'reflection',
|
|
742
|
+
config: JSON.stringify(currentRecord.config),
|
|
743
|
+
generationCount: currentRecord.generationCount + 1,
|
|
744
|
+
lastObservedAt: currentRecord.lastObservedAt ?? null,
|
|
745
|
+
observationTokenCount: tokenCount,
|
|
746
|
+
totalTokensObserved: currentRecord.totalTokensObserved,
|
|
747
|
+
pendingMessageTokens: currentRecord.pendingMessageTokens,
|
|
748
|
+
isObserving: false,
|
|
749
|
+
isReflecting: false,
|
|
750
|
+
isBufferingObservation: false,
|
|
751
|
+
isBufferingReflection: false,
|
|
752
|
+
lastBufferedAtTokens: 0,
|
|
753
|
+
lastBufferedAtTime: null,
|
|
754
|
+
observedTimezone: currentRecord.observedTimezone ?? null,
|
|
755
|
+
metadata: currentRecord.metadata ?? null,
|
|
756
|
+
});
|
|
757
|
+
const saved = await this.omRepo.save(entity);
|
|
758
|
+
return this.entityToOMRecord(saved);
|
|
759
|
+
}
|
|
760
|
+
async updateBufferedReflection(input) {
|
|
761
|
+
await this.omRepo.update(input.id, {
|
|
762
|
+
bufferedReflection: input.reflection,
|
|
763
|
+
bufferedReflectionTokens: input.tokenCount,
|
|
764
|
+
bufferedReflectionInputTokens: input.inputTokenCount,
|
|
765
|
+
reflectedObservationLineCount: input.reflectedObservationLineCount,
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
async swapBufferedReflectionToActive(input) {
|
|
769
|
+
const { currentRecord, tokenCount } = input;
|
|
770
|
+
const lines = currentRecord.activeObservations.split('\n');
|
|
771
|
+
const reflectedCount = currentRecord.reflectedObservationLineCount ?? lines.length;
|
|
772
|
+
const unreflected = lines.slice(reflectedCount).join('\n');
|
|
773
|
+
const newActive = currentRecord.bufferedReflection
|
|
774
|
+
? unreflected
|
|
775
|
+
? `${currentRecord.bufferedReflection}\n${unreflected}`
|
|
776
|
+
: currentRecord.bufferedReflection
|
|
777
|
+
: unreflected;
|
|
778
|
+
const newId = (0, utils_1.generateNanoId)();
|
|
779
|
+
const lookupKey = this.omLookupKey(currentRecord.scope, currentRecord.threadId, currentRecord.resourceId);
|
|
780
|
+
const entity = this.omRepo.create({
|
|
781
|
+
id: newId,
|
|
782
|
+
lookupKey,
|
|
783
|
+
scope: currentRecord.scope,
|
|
784
|
+
threadId: currentRecord.threadId,
|
|
785
|
+
resourceId: currentRecord.resourceId,
|
|
786
|
+
activeObservations: newActive,
|
|
787
|
+
originType: 'reflection',
|
|
788
|
+
config: JSON.stringify(currentRecord.config),
|
|
789
|
+
generationCount: currentRecord.generationCount + 1,
|
|
790
|
+
lastObservedAt: currentRecord.lastObservedAt ?? null,
|
|
791
|
+
observationTokenCount: tokenCount,
|
|
792
|
+
totalTokensObserved: currentRecord.totalTokensObserved,
|
|
793
|
+
pendingMessageTokens: currentRecord.pendingMessageTokens,
|
|
794
|
+
isObserving: false,
|
|
795
|
+
isReflecting: false,
|
|
796
|
+
isBufferingObservation: false,
|
|
797
|
+
isBufferingReflection: false,
|
|
798
|
+
lastBufferedAtTokens: 0,
|
|
799
|
+
lastBufferedAtTime: null,
|
|
800
|
+
observedTimezone: currentRecord.observedTimezone ?? null,
|
|
801
|
+
metadata: currentRecord.metadata ?? null,
|
|
802
|
+
});
|
|
803
|
+
const saved = await this.omRepo.save(entity);
|
|
804
|
+
return this.entityToOMRecord(saved);
|
|
805
|
+
}
|
|
806
|
+
async setReflectingFlag(id, isReflecting) {
|
|
807
|
+
await this.omRepo.update(id, { isReflecting });
|
|
808
|
+
}
|
|
809
|
+
async setObservingFlag(id, isObserving) {
|
|
810
|
+
await this.omRepo.update(id, { isObserving });
|
|
811
|
+
}
|
|
812
|
+
async setBufferingObservationFlag(id, isBuffering, lastBufferedAtTokens) {
|
|
813
|
+
const updates = {
|
|
814
|
+
isBufferingObservation: isBuffering,
|
|
815
|
+
};
|
|
816
|
+
if (isBuffering && lastBufferedAtTokens !== undefined) {
|
|
817
|
+
updates.lastBufferedAtTokens = lastBufferedAtTokens;
|
|
818
|
+
}
|
|
819
|
+
await this.omRepo.update(id, updates);
|
|
820
|
+
}
|
|
821
|
+
async setBufferingReflectionFlag(id, isBuffering) {
|
|
822
|
+
await this.omRepo.update(id, { isBufferingReflection: isBuffering });
|
|
823
|
+
}
|
|
824
|
+
async clearObservationalMemory(threadId, resourceId) {
|
|
825
|
+
const scope = threadId ? 'thread' : 'resource';
|
|
826
|
+
const lookupKey = this.omLookupKey(scope, threadId, resourceId);
|
|
827
|
+
await this.omRepo.delete({ lookupKey });
|
|
828
|
+
}
|
|
829
|
+
async setPendingMessageTokens(id, tokenCount) {
|
|
830
|
+
await this.omRepo.update(id, { pendingMessageTokens: tokenCount });
|
|
831
|
+
}
|
|
832
|
+
entityToMessage(entity) {
|
|
833
|
+
return {
|
|
834
|
+
id: entity.id,
|
|
835
|
+
role: entity.role,
|
|
836
|
+
createdAt: entity.createdAt,
|
|
837
|
+
threadId: entity.threadId,
|
|
838
|
+
resourceId: entity.resourceId ?? undefined,
|
|
839
|
+
type: entity.type ?? undefined,
|
|
840
|
+
content: (0, n8n_workflow_1.jsonParse)(entity.content),
|
|
841
|
+
};
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
exports.TypeORMMemoryStorage = TypeORMMemoryStorage;
|
|
845
|
+
TypeORMMemoryStorage.threadMutationQueues = new Map();
|
|
846
|
+
exports.TypeORMMemoryStorage = TypeORMMemoryStorage = TypeORMMemoryStorage_1 = __decorate([
|
|
847
|
+
(0, di_1.Service)(),
|
|
848
|
+
__metadata("design:paramtypes", [instance_ai_thread_repository_1.InstanceAiThreadRepository,
|
|
849
|
+
instance_ai_message_repository_1.InstanceAiMessageRepository,
|
|
850
|
+
instance_ai_resource_repository_1.InstanceAiResourceRepository,
|
|
851
|
+
instance_ai_observational_memory_repository_1.InstanceAiObservationalMemoryRepository])
|
|
852
|
+
], TypeORMMemoryStorage);
|
|
853
|
+
//# sourceMappingURL=typeorm-memory-storage.js.map
|