@db3.ai/app 0.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +31 -0
- package/README.md +241 -0
- package/agent-instructions.md +69 -0
- package/bin/db3-agents.mjs +140 -0
- package/bin/db3.mjs +11 -0
- package/dist/ai/AIErrors.d.ts +33 -0
- package/dist/ai/AIErrors.js +43 -0
- package/dist/ai/AIFailover.d.ts +25 -0
- package/dist/ai/AIFailover.js +96 -0
- package/dist/ai/AIProviders.d.ts +35 -0
- package/dist/ai/AIProviders.js +197 -0
- package/dist/ai/AIQuotaDeferredError.d.ts +19 -0
- package/dist/ai/AIQuotaDeferredError.js +25 -0
- package/dist/ai/AIRateLimiter.d.ts +103 -0
- package/dist/ai/AIRateLimiter.js +690 -0
- package/dist/ai/Agent.d.ts +633 -0
- package/dist/ai/Agent.js +2976 -0
- package/dist/ai/AgentHistory.d.ts +11 -0
- package/dist/ai/AgentHistory.js +495 -0
- package/dist/ai/AgentRunJob.d.ts +21 -0
- package/dist/ai/AgentRunJob.js +53 -0
- package/dist/ai/Ai.d.ts +375 -0
- package/dist/ai/Ai.js +1771 -0
- package/dist/ai/AiConversation.d.ts +17 -0
- package/dist/ai/AiConversation.js +38 -0
- package/dist/ai/AiExecutionContext.d.ts +7 -0
- package/dist/ai/AiExecutionContext.js +16 -0
- package/dist/ai/AiMessage.d.ts +43 -0
- package/dist/ai/AiMessage.js +105 -0
- package/dist/ai/AiRateLimitBucket.d.ts +69 -0
- package/dist/ai/AiRateLimitBucket.js +138 -0
- package/dist/ai/AiRateLimitReservation.d.ts +56 -0
- package/dist/ai/AiRateLimitReservation.js +101 -0
- package/dist/ai/AiRequest.d.ts +78 -0
- package/dist/ai/AiRequest.js +384 -0
- package/dist/ai/Estimates.d.ts +26 -0
- package/dist/ai/Estimates.js +34 -0
- package/dist/ai/Models.d.ts +88 -0
- package/dist/ai/Models.js +328 -0
- package/dist/ai/OpenAIProviderError.d.ts +30 -0
- package/dist/ai/OpenAIProviderError.js +77 -0
- package/dist/ai/OpenAIQuotaRetry.d.ts +27 -0
- package/dist/ai/OpenAIQuotaRetry.js +144 -0
- package/dist/ai/ProviderCosts.d.ts +55 -0
- package/dist/ai/ProviderCosts.js +108 -0
- package/dist/ai/ResponsesProviderCall.d.ts +13 -0
- package/dist/ai/ResponsesProviderCall.js +29 -0
- package/dist/ai/agentCitations.d.ts +27 -0
- package/dist/ai/agentCitations.js +153 -0
- package/dist/ai/contracts/AI.d.ts +347 -0
- package/dist/ai/contracts/AI.js +13 -0
- package/dist/ai/contracts/Agent.d.ts +476 -0
- package/dist/ai/contracts/Agent.js +1 -0
- package/dist/ai/contracts/AiRequestRunCostSummary.d.ts +31 -0
- package/dist/ai/contracts/AiRequestRunCostSummary.js +1 -0
- package/dist/ai/contracts/Pricing.d.ts +88 -0
- package/dist/ai/contracts/Pricing.js +1 -0
- package/dist/ai/contracts/Providers.d.ts +68 -0
- package/dist/ai/contracts/Providers.js +1 -0
- package/dist/ai/contracts/QuotaRetry.d.ts +38 -0
- package/dist/ai/contracts/QuotaRetry.js +1 -0
- package/dist/ai/contracts/RateLimits.d.ts +45 -0
- package/dist/ai/contracts/RateLimits.js +1 -0
- package/dist/ai/contracts/ResponsesProviderCall.d.ts +28 -0
- package/dist/ai/contracts/ResponsesProviderCall.js +1 -0
- package/dist/ai/contracts/index.d.ts +8 -0
- package/dist/ai/contracts/index.js +8 -0
- package/dist/ai/index.d.ts +27 -0
- package/dist/ai/index.js +27 -0
- package/dist/ai/registry.d.ts +28 -0
- package/dist/ai/registry.js +49 -0
- package/dist/ai/sdkNodeCompatibility.d.ts +76 -0
- package/dist/ai/toolCallRecovery.d.ts +16 -0
- package/dist/ai/toolCallRecovery.js +71 -0
- package/dist/ai/toolHelpers.d.ts +65 -0
- package/dist/ai/toolHelpers.js +106 -0
- package/dist/auth/Auth.d.ts +641 -0
- package/dist/auth/Auth.js +927 -0
- package/dist/auth/AuthProvider.d.ts +104 -0
- package/dist/auth/AuthProvider.js +185 -0
- package/dist/auth/AuthToken.d.ts +123 -0
- package/dist/auth/AuthToken.js +156 -0
- package/dist/auth/PasswordResetToken.d.ts +33 -0
- package/dist/auth/PasswordResetToken.js +64 -0
- package/dist/auth/UserIdentity.d.ts +46 -0
- package/dist/auth/UserIdentity.js +72 -0
- package/dist/auth/contracts/AuthProviderDriver.d.ts +94 -0
- package/dist/auth/contracts/AuthProviderDriver.js +1 -0
- package/dist/auth/contracts/index.d.ts +1 -0
- package/dist/auth/contracts/index.js +1 -0
- package/dist/auth/index.d.ts +8 -0
- package/dist/auth/index.js +8 -0
- package/dist/auth/passwordHash.d.ts +26 -0
- package/dist/auth/passwordHash.js +96 -0
- package/dist/auth/providers/GoogleAuthProvider.d.ts +135 -0
- package/dist/auth/providers/GoogleAuthProvider.js +305 -0
- package/dist/auth/providers/PasswordAuthProvider.d.ts +115 -0
- package/dist/auth/providers/PasswordAuthProvider.js +195 -0
- package/dist/auth/providers/index.d.ts +3 -0
- package/dist/auth/providers/index.js +3 -0
- package/dist/auth/providers/resolveAuthProviders.d.ts +29 -0
- package/dist/auth/providers/resolveAuthProviders.js +111 -0
- package/dist/cache/Cache.d.ts +67 -0
- package/dist/cache/Cache.js +115 -0
- package/dist/cache/contracts/CacheDriver.d.ts +10 -0
- package/dist/cache/contracts/CacheDriver.js +1 -0
- package/dist/cache/contracts/CacheOperations.d.ts +26 -0
- package/dist/cache/contracts/CacheOperations.js +1 -0
- package/dist/cache/contracts/CacheOptions.d.ts +51 -0
- package/dist/cache/contracts/CacheOptions.js +1 -0
- package/dist/cache/contracts/CacheRepository.d.ts +45 -0
- package/dist/cache/contracts/CacheRepository.js +1 -0
- package/dist/cache/contracts/index.d.ts +4 -0
- package/dist/cache/contracts/index.js +4 -0
- package/dist/cache/drivers/CacheManagerDriver.d.ts +55 -0
- package/dist/cache/drivers/CacheManagerDriver.js +68 -0
- package/dist/cache/drivers/createCacheDriver.d.ts +8 -0
- package/dist/cache/drivers/createCacheDriver.js +147 -0
- package/dist/cache/index.d.ts +2 -0
- package/dist/cache/index.js +2 -0
- package/dist/cli/Cli.d.ts +17 -0
- package/dist/cli/Cli.js +120 -0
- package/dist/cli/commands/repl.d.ts +9 -0
- package/dist/cli/commands/repl.js +27 -0
- package/dist/cli/contracts/CliCommand.d.ts +30 -0
- package/dist/cli/contracts/CliCommand.js +1 -0
- package/dist/cli/contracts/CliConfig.d.ts +9 -0
- package/dist/cli/contracts/CliConfig.js +1 -0
- package/dist/cli/contracts/CliOptions.d.ts +13 -0
- package/dist/cli/contracts/CliOptions.js +1 -0
- package/dist/cli/contracts/CommandDefinition.d.ts +18 -0
- package/dist/cli/contracts/CommandDefinition.js +1 -0
- package/dist/cli/contracts/ReplOptions.d.ts +11 -0
- package/dist/cli/contracts/ReplOptions.js +1 -0
- package/dist/cli/contracts/index.d.ts +5 -0
- package/dist/cli/contracts/index.js +1 -0
- package/dist/cli/defineCommand.d.ts +10 -0
- package/dist/cli/defineCommand.js +25 -0
- package/dist/cli/index.d.ts +5 -0
- package/dist/cli/index.js +5 -0
- package/dist/cli/runDb3.d.ts +11 -0
- package/dist/cli/runDb3.js +70 -0
- package/dist/cli/runRepl.d.ts +12 -0
- package/dist/cli/runRepl.js +54 -0
- package/dist/config/Config.d.ts +48 -0
- package/dist/config/Config.js +80 -0
- package/dist/config/env.d.ts +26 -0
- package/dist/config/env.js +117 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +2 -0
- package/dist/db/ActiveProjection.d.ts +90 -0
- package/dist/db/ActiveProjection.js +134 -0
- package/dist/db/ActiveQueryBuilder.d.ts +268 -0
- package/dist/db/ActiveQueryBuilder.js +621 -0
- package/dist/db/ActiveRecord.d.ts +483 -0
- package/dist/db/ActiveRecord.js +765 -0
- package/dist/db/Database.d.ts +277 -0
- package/dist/db/Database.js +827 -0
- package/dist/db/FieldType.d.ts +540 -0
- package/dist/db/FieldType.js +706 -0
- package/dist/db/SoftDeletes.d.ts +30 -0
- package/dist/db/SoftDeletes.js +93 -0
- package/dist/db/commands/check.d.ts +6 -0
- package/dist/db/commands/check.js +8 -0
- package/dist/db/commands/index.d.ts +6 -0
- package/dist/db/commands/index.js +17 -0
- package/dist/db/commands/makeMigration.d.ts +7 -0
- package/dist/db/commands/makeMigration.js +9 -0
- package/dist/db/commands/migrate.d.ts +6 -0
- package/dist/db/commands/migrate.js +8 -0
- package/dist/db/connection.d.ts +10 -0
- package/dist/db/connection.js +55 -0
- package/dist/db/contracts/ActiveRecordDefinition.d.ts +64 -0
- package/dist/db/contracts/ActiveRecordDefinition.js +1 -0
- package/dist/db/contracts/DatabaseBackup.d.ts +7 -0
- package/dist/db/contracts/DatabaseBackup.js +1 -0
- package/dist/db/contracts/DatabaseMigrationsConfig.d.ts +9 -0
- package/dist/db/contracts/DatabaseMigrationsConfig.js +1 -0
- package/dist/db/contracts/index.d.ts +3 -0
- package/dist/db/contracts/index.js +3 -0
- package/dist/db/dialects/columnTypes.d.ts +20 -0
- package/dist/db/dialects/columnTypes.js +67 -0
- package/dist/db/dialects/index.d.ts +6 -0
- package/dist/db/dialects/index.js +6 -0
- package/dist/db/dialects/mariadb.d.ts +7 -0
- package/dist/db/dialects/mariadb.js +35 -0
- package/dist/db/dialects/mysql.d.ts +14 -0
- package/dist/db/dialects/mysql.js +203 -0
- package/dist/db/dialects/postgres.d.ts +5 -0
- package/dist/db/dialects/postgres.js +106 -0
- package/dist/db/dialects/resolveDialect.d.ts +14 -0
- package/dist/db/dialects/resolveDialect.js +57 -0
- package/dist/db/dialects/types.d.ts +44 -0
- package/dist/db/dialects/types.js +1 -0
- package/dist/db/errors.d.ts +15 -0
- package/dist/db/errors.js +20 -0
- package/dist/db/fields/BooleanField.d.ts +29 -0
- package/dist/db/fields/BooleanField.js +89 -0
- package/dist/db/fields/CharUuidField.d.ts +29 -0
- package/dist/db/fields/CharUuidField.js +63 -0
- package/dist/db/fields/ChoiceStringField.d.ts +25 -0
- package/dist/db/fields/ChoiceStringField.js +58 -0
- package/dist/db/fields/DecimalField.d.ts +20 -0
- package/dist/db/fields/DecimalField.js +105 -0
- package/dist/db/fields/EmailField.d.ts +31 -0
- package/dist/db/fields/EmailField.js +52 -0
- package/dist/db/fields/EncryptedJsonField.d.ts +82 -0
- package/dist/db/fields/EncryptedJsonField.js +169 -0
- package/dist/db/fields/IntegerField.d.ts +35 -0
- package/dist/db/fields/IntegerField.js +139 -0
- package/dist/db/fields/JsonField.d.ts +40 -0
- package/dist/db/fields/JsonField.js +79 -0
- package/dist/db/fields/JsonStringField.d.ts +21 -0
- package/dist/db/fields/JsonStringField.js +41 -0
- package/dist/db/fields/LinkField.d.ts +180 -0
- package/dist/db/fields/LinkField.js +359 -0
- package/dist/db/fields/PasswordField.d.ts +93 -0
- package/dist/db/fields/PasswordField.js +180 -0
- package/dist/db/fields/StringField.d.ts +43 -0
- package/dist/db/fields/StringField.js +102 -0
- package/dist/db/fields/StringListField.d.ts +54 -0
- package/dist/db/fields/StringListField.js +124 -0
- package/dist/db/fields/TextField.d.ts +25 -0
- package/dist/db/fields/TextField.js +44 -0
- package/dist/db/fields/TimestampField.d.ts +47 -0
- package/dist/db/fields/TimestampField.js +97 -0
- package/dist/db/fields/UlidField.d.ts +69 -0
- package/dist/db/fields/UlidField.js +114 -0
- package/dist/db/fields/UrlField.d.ts +30 -0
- package/dist/db/fields/UrlField.js +61 -0
- package/dist/db/fields/VectorField.d.ts +64 -0
- package/dist/db/fields/VectorField.js +180 -0
- package/dist/db/fields/createField.d.ts +2 -0
- package/dist/db/fields/createField.js +13 -0
- package/dist/db/fields/field.d.ts +36 -0
- package/dist/db/fields/field.js +101 -0
- package/dist/db/fields/index.d.ts +18 -0
- package/dist/db/fields/index.js +18 -0
- package/dist/db/fields/resolveFields.d.ts +17 -0
- package/dist/db/fields/resolveFields.js +38 -0
- package/dist/db/index.d.ts +13 -0
- package/dist/db/index.js +13 -0
- package/dist/db/migrations/DatabaseMigrationManager.d.ts +57 -0
- package/dist/db/migrations/DatabaseMigrationManager.js +589 -0
- package/dist/db/migrations/DatabaseSchemaInspector.d.ts +19 -0
- package/dist/db/migrations/DatabaseSchemaInspector.js +384 -0
- package/dist/db/migrations/KnexMigrationRenderer.d.ts +11 -0
- package/dist/db/migrations/KnexMigrationRenderer.js +390 -0
- package/dist/db/migrations/ModelSchemaCollector.d.ts +29 -0
- package/dist/db/migrations/ModelSchemaCollector.js +183 -0
- package/dist/db/migrations/SchemaDiffer.d.ts +13 -0
- package/dist/db/migrations/SchemaDiffer.js +427 -0
- package/dist/db/migrations/SchemaNames.d.ts +27 -0
- package/dist/db/migrations/SchemaNames.js +46 -0
- package/dist/db/migrations/SchemaSnapshotSerializer.d.ts +30 -0
- package/dist/db/migrations/SchemaSnapshotSerializer.js +49 -0
- package/dist/db/migrations/contracts/DatabaseMigration.d.ts +118 -0
- package/dist/db/migrations/contracts/DatabaseMigration.js +1 -0
- package/dist/db/migrations/contracts/SchemaChange.d.ts +83 -0
- package/dist/db/migrations/contracts/SchemaChange.js +1 -0
- package/dist/db/migrations/contracts/SchemaSnapshot.d.ts +94 -0
- package/dist/db/migrations/contracts/SchemaSnapshot.js +1 -0
- package/dist/db/migrations/contracts/index.d.ts +3 -0
- package/dist/db/migrations/contracts/index.js +3 -0
- package/dist/db/migrations/errors.d.ts +35 -0
- package/dist/db/migrations/errors.js +45 -0
- package/dist/db/migrations/index.d.ts +10 -0
- package/dist/db/migrations/index.js +10 -0
- package/dist/db/migrations/promoteDestructiveSchemaChanges.d.ts +19 -0
- package/dist/db/migrations/promoteDestructiveSchemaChanges.js +102 -0
- package/dist/db/queryMonitor.d.ts +142 -0
- package/dist/db/queryMonitor.js +357 -0
- package/dist/db/sqlErrors.d.ts +11 -0
- package/dist/db/sqlErrors.js +17 -0
- package/dist/db/test/db.d.ts +11 -0
- package/dist/db/test/db.js +109 -0
- package/dist/devtools/HttpEventDispatcher.d.ts +19 -0
- package/dist/devtools/HttpEventDispatcher.js +180 -0
- package/dist/devtools/contracts/DevtoolsEventDispatcher.d.ts +53 -0
- package/dist/devtools/contracts/DevtoolsEventDispatcher.js +1 -0
- package/dist/devtools/contracts/index.d.ts +1 -0
- package/dist/devtools/contracts/index.js +1 -0
- package/dist/devtools/environment.d.ts +10 -0
- package/dist/devtools/environment.js +14 -0
- package/dist/devtools/index.d.ts +3 -0
- package/dist/devtools/index.js +3 -0
- package/dist/events/Events.d.ts +70 -0
- package/dist/events/Events.js +126 -0
- package/dist/events/contracts/EventConstructor.d.ts +12 -0
- package/dist/events/contracts/EventConstructor.js +1 -0
- package/dist/events/contracts/EventListener.d.ts +6 -0
- package/dist/events/contracts/EventListener.js +1 -0
- package/dist/events/contracts/EventUnsubscribe.d.ts +4 -0
- package/dist/events/contracts/EventUnsubscribe.js +1 -0
- package/dist/events/contracts/index.d.ts +3 -0
- package/dist/events/contracts/index.js +3 -0
- package/dist/events/index.d.ts +2 -0
- package/dist/events/index.js +2 -0
- package/dist/flows/FlowBlockRegistry.d.ts +39 -0
- package/dist/flows/FlowBlockRegistry.js +66 -0
- package/dist/flows/FlowCompiler.d.ts +26 -0
- package/dist/flows/FlowCompiler.js +488 -0
- package/dist/flows/FlowDefinitionError.d.ts +21 -0
- package/dist/flows/FlowDefinitionError.js +16 -0
- package/dist/flows/FlowStepJob.d.ts +28 -0
- package/dist/flows/FlowStepJob.js +31 -0
- package/dist/flows/FlowValueValidator.d.ts +32 -0
- package/dist/flows/FlowValueValidator.js +105 -0
- package/dist/flows/Flows.d.ts +102 -0
- package/dist/flows/Flows.js +871 -0
- package/dist/flows/blocks/FlowInput.d.ts +10 -0
- package/dist/flows/blocks/FlowInput.js +29 -0
- package/dist/flows/blocks/FlowOutput.d.ts +10 -0
- package/dist/flows/blocks/FlowOutput.js +29 -0
- package/dist/flows/blocks/Subflow.d.ts +10 -0
- package/dist/flows/blocks/Subflow.js +21 -0
- package/dist/flows/blocks/index.d.ts +6 -0
- package/dist/flows/blocks/index.js +8 -0
- package/dist/flows/constants.d.ts +55 -0
- package/dist/flows/constants.js +47 -0
- package/dist/flows/contracts/FlowBlock.d.ts +64 -0
- package/dist/flows/contracts/FlowBlock.js +1 -0
- package/dist/flows/contracts/FlowCompiler.d.ts +30 -0
- package/dist/flows/contracts/FlowCompiler.js +1 -0
- package/dist/flows/contracts/FlowDefinition.d.ts +118 -0
- package/dist/flows/contracts/FlowDefinition.js +1 -0
- package/dist/flows/contracts/FlowDefinitionStore.d.ts +47 -0
- package/dist/flows/contracts/FlowDefinitionStore.js +1 -0
- package/dist/flows/contracts/FlowRun.d.ts +40 -0
- package/dist/flows/contracts/FlowRun.js +1 -0
- package/dist/flows/contracts/FlowValue.d.ts +49 -0
- package/dist/flows/contracts/FlowValue.js +1 -0
- package/dist/flows/contracts/FlowsService.d.ts +37 -0
- package/dist/flows/contracts/FlowsService.js +1 -0
- package/dist/flows/contracts/index.d.ts +7 -0
- package/dist/flows/contracts/index.js +7 -0
- package/dist/flows/defineBlock.d.ts +18 -0
- package/dist/flows/defineBlock.js +19 -0
- package/dist/flows/drivers/FileFlowDefinitionStore.d.ts +53 -0
- package/dist/flows/drivers/FileFlowDefinitionStore.js +313 -0
- package/dist/flows/drivers/index.d.ts +1 -0
- package/dist/flows/drivers/index.js +1 -0
- package/dist/flows/errors.d.ts +8 -0
- package/dist/flows/errors.js +19 -0
- package/dist/flows/index.d.ts +13 -0
- package/dist/flows/index.js +13 -0
- package/dist/flows/models/FlowRun.d.ts +55 -0
- package/dist/flows/models/FlowRun.js +126 -0
- package/dist/flows/models/FlowRunEvent.d.ts +41 -0
- package/dist/flows/models/FlowRunEvent.js +85 -0
- package/dist/flows/models/FlowStepRun.d.ts +56 -0
- package/dist/flows/models/FlowStepRun.js +137 -0
- package/dist/flows/models/index.d.ts +10 -0
- package/dist/flows/models/index.js +14 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +16 -0
- package/dist/logging/Log.d.ts +66 -0
- package/dist/logging/Log.js +79 -0
- package/dist/logging/contracts/HttpExchange.d.ts +50 -0
- package/dist/logging/contracts/HttpExchange.js +1 -0
- package/dist/logging/contracts/Logger.d.ts +41 -0
- package/dist/logging/contracts/Logger.js +1 -0
- package/dist/logging/contracts/LoggerDriver.d.ts +16 -0
- package/dist/logging/contracts/LoggerDriver.js +1 -0
- package/dist/logging/contracts/LoggingOptions.d.ts +49 -0
- package/dist/logging/contracts/LoggingOptions.js +1 -0
- package/dist/logging/contracts/index.d.ts +4 -0
- package/dist/logging/contracts/index.js +4 -0
- package/dist/logging/drivers/PinoLoggerDriver.d.ts +24 -0
- package/dist/logging/drivers/PinoLoggerDriver.js +291 -0
- package/dist/logging/drivers/index.d.ts +1 -0
- package/dist/logging/drivers/index.js +1 -0
- package/dist/logging/index.d.ts +3 -0
- package/dist/logging/index.js +3 -0
- package/dist/logging/transports/DevtoolsLogTransport.d.ts +35 -0
- package/dist/logging/transports/DevtoolsLogTransport.js +96 -0
- package/dist/mail/Mail.d.ts +62 -0
- package/dist/mail/Mail.js +98 -0
- package/dist/mail/index.d.ts +4 -0
- package/dist/mail/index.js +4 -0
- package/dist/mail/transports/FileMailTransport.d.ts +12 -0
- package/dist/mail/transports/FileMailTransport.js +41 -0
- package/dist/mail/transports/MailgunTransport.d.ts +22 -0
- package/dist/mail/transports/MailgunTransport.js +57 -0
- package/dist/mail/transports/ResendTransport.d.ts +14 -0
- package/dist/mail/transports/ResendTransport.js +55 -0
- package/dist/media/MediaFile.d.ts +48 -0
- package/dist/media/MediaFile.js +104 -0
- package/dist/media/MediaItem.d.ts +47 -0
- package/dist/media/MediaItem.js +106 -0
- package/dist/media/MediaLibrary.d.ts +42 -0
- package/dist/media/MediaLibrary.js +94 -0
- package/dist/media/MediaManager.d.ts +159 -0
- package/dist/media/MediaManager.js +754 -0
- package/dist/media/constants.d.ts +27 -0
- package/dist/media/constants.js +19 -0
- package/dist/media/contracts/MediaOptions.d.ts +8 -0
- package/dist/media/contracts/MediaOptions.js +1 -0
- package/dist/media/contracts/index.d.ts +1 -0
- package/dist/media/contracts/index.js +1 -0
- package/dist/media/image/ImageReconstructionError.d.ts +15 -0
- package/dist/media/image/ImageReconstructionError.js +18 -0
- package/dist/media/image/ImageVariantRenderer.d.ts +44 -0
- package/dist/media/image/ImageVariantRenderer.js +337 -0
- package/dist/media/image/ImageVariantRequest.d.ts +28 -0
- package/dist/media/image/ImageVariantRequest.js +55 -0
- package/dist/media/image/contracts/ImageProcessor.d.ts +46 -0
- package/dist/media/image/contracts/ImageProcessor.js +1 -0
- package/dist/media/image/contracts/ImageVariant.d.ts +31 -0
- package/dist/media/image/contracts/ImageVariant.js +7 -0
- package/dist/media/image/contracts/ImageVariantCacheOptions.d.ts +20 -0
- package/dist/media/image/contracts/ImageVariantCacheOptions.js +1 -0
- package/dist/media/image/contracts/index.d.ts +3 -0
- package/dist/media/image/contracts/index.js +3 -0
- package/dist/media/image/index.d.ts +5 -0
- package/dist/media/image/index.js +5 -0
- package/dist/media/image/processors/SharpImageProcessor.d.ts +25 -0
- package/dist/media/image/processors/SharpImageProcessor.js +112 -0
- package/dist/media/image/processors/index.d.ts +1 -0
- package/dist/media/image/processors/index.js +1 -0
- package/dist/media/index.d.ts +8 -0
- package/dist/media/index.js +8 -0
- package/dist/media/types.d.ts +129 -0
- package/dist/media/types.js +1 -0
- package/dist/queue/FailedJob.d.ts +31 -0
- package/dist/queue/FailedJob.js +41 -0
- package/dist/queue/Queue.d.ts +208 -0
- package/dist/queue/Queue.js +685 -0
- package/dist/queue/QueueEvents.d.ts +31 -0
- package/dist/queue/QueueEvents.js +49 -0
- package/dist/queue/QueueRetryLaterError.d.ts +23 -0
- package/dist/queue/QueueRetryLaterError.js +34 -0
- package/dist/queue/QueueWorker.d.ts +72 -0
- package/dist/queue/QueueWorker.js +236 -0
- package/dist/queue/QueueableJob.d.ts +109 -0
- package/dist/queue/QueueableJob.js +137 -0
- package/dist/queue/QueuedJob.d.ts +31 -0
- package/dist/queue/QueuedJob.js +52 -0
- package/dist/queue/RetryPolicy.d.ts +51 -0
- package/dist/queue/RetryPolicy.js +84 -0
- package/dist/queue/commands/index.d.ts +4 -0
- package/dist/queue/commands/index.js +11 -0
- package/dist/queue/commands/makeJob.d.ts +7 -0
- package/dist/queue/commands/makeJob.js +9 -0
- package/dist/queue/console.d.ts +60 -0
- package/dist/queue/console.js +348 -0
- package/dist/queue/contracts/CreateJob.d.ts +12 -0
- package/dist/queue/contracts/CreateJob.js +1 -0
- package/dist/queue/contracts/QueueDriver.d.ts +122 -0
- package/dist/queue/contracts/QueueDriver.js +1 -0
- package/dist/queue/contracts/QueueEvents.d.ts +61 -0
- package/dist/queue/contracts/QueueEvents.js +1 -0
- package/dist/queue/contracts/QueuePayload.d.ts +136 -0
- package/dist/queue/contracts/QueuePayload.js +1 -0
- package/dist/queue/contracts/QueueRetry.d.ts +43 -0
- package/dist/queue/contracts/QueueRetry.js +1 -0
- package/dist/queue/contracts/QueueService.d.ts +199 -0
- package/dist/queue/contracts/QueueService.js +1 -0
- package/dist/queue/contracts/QueueWorkerLifecycle.d.ts +65 -0
- package/dist/queue/contracts/QueueWorkerLifecycle.js +1 -0
- package/dist/queue/contracts/QueueableJob.d.ts +50 -0
- package/dist/queue/contracts/QueueableJob.js +1 -0
- package/dist/queue/contracts/RedisQueueDriver.d.ts +37 -0
- package/dist/queue/contracts/RedisQueueDriver.js +1 -0
- package/dist/queue/contracts/index.d.ts +9 -0
- package/dist/queue/contracts/index.js +9 -0
- package/dist/queue/createJob.d.ts +18 -0
- package/dist/queue/createJob.js +52 -0
- package/dist/queue/drivers/DatabaseQueueDriver.d.ts +83 -0
- package/dist/queue/drivers/DatabaseQueueDriver.js +393 -0
- package/dist/queue/drivers/RedisQueueDriver.d.ts +102 -0
- package/dist/queue/drivers/RedisQueueDriver.js +641 -0
- package/dist/queue/index.d.ts +13 -0
- package/dist/queue/index.js +13 -0
- package/dist/queue/queueMonitor.d.ts +133 -0
- package/dist/queue/queueMonitor.js +238 -0
- package/dist/scheduler/ScheduledCall.d.ts +25 -0
- package/dist/scheduler/ScheduledCall.js +31 -0
- package/dist/scheduler/ScheduledEvent.d.ts +74 -0
- package/dist/scheduler/ScheduledEvent.js +115 -0
- package/dist/scheduler/ScheduledJob.d.ts +34 -0
- package/dist/scheduler/ScheduledJob.js +50 -0
- package/dist/scheduler/ScheduledOccurrence.d.ts +74 -0
- package/dist/scheduler/ScheduledOccurrence.js +194 -0
- package/dist/scheduler/ScheduledOccurrenceRecorder.d.ts +34 -0
- package/dist/scheduler/ScheduledOccurrenceRecorder.js +106 -0
- package/dist/scheduler/Scheduler.d.ts +76 -0
- package/dist/scheduler/Scheduler.js +186 -0
- package/dist/scheduler/SchedulerWorker.d.ts +37 -0
- package/dist/scheduler/SchedulerWorker.js +119 -0
- package/dist/scheduler/console.d.ts +18 -0
- package/dist/scheduler/console.js +288 -0
- package/dist/scheduler/constants.d.ts +13 -0
- package/dist/scheduler/constants.js +23 -0
- package/dist/scheduler/contracts/Scheduler.d.ts +104 -0
- package/dist/scheduler/contracts/Scheduler.js +1 -0
- package/dist/scheduler/contracts/SchedulerConsole.d.ts +37 -0
- package/dist/scheduler/contracts/SchedulerConsole.js +1 -0
- package/dist/scheduler/contracts/SchedulerWorker.d.ts +18 -0
- package/dist/scheduler/contracts/SchedulerWorker.js +1 -0
- package/dist/scheduler/contracts/index.d.ts +3 -0
- package/dist/scheduler/contracts/index.js +3 -0
- package/dist/scheduler/index.d.ts +9 -0
- package/dist/scheduler/index.js +9 -0
- package/dist/scheduler/scheduleTime.d.ts +30 -0
- package/dist/scheduler/scheduleTime.js +64 -0
- package/dist/security/Security.d.ts +60 -0
- package/dist/security/Security.js +252 -0
- package/dist/security/SecurityError.d.ts +13 -0
- package/dist/security/SecurityError.js +16 -0
- package/dist/security/contracts/SecurityOptions.d.ts +17 -0
- package/dist/security/contracts/SecurityOptions.js +1 -0
- package/dist/security/contracts/SecurityPayload.d.ts +13 -0
- package/dist/security/contracts/SecurityPayload.js +1 -0
- package/dist/security/contracts/index.d.ts +2 -0
- package/dist/security/contracts/index.js +2 -0
- package/dist/security/ensureAppKey.d.ts +16 -0
- package/dist/security/ensureAppKey.js +69 -0
- package/dist/security/index.d.ts +4 -0
- package/dist/security/index.js +4 -0
- package/dist/serialization/Serializable.d.ts +17 -0
- package/dist/serialization/Serializable.js +1 -0
- package/dist/serialization/SerializationError.d.ts +40 -0
- package/dist/serialization/SerializationError.js +42 -0
- package/dist/serialization/SerializationRegistry.d.ts +76 -0
- package/dist/serialization/SerializationRegistry.js +153 -0
- package/dist/serialization/SerializationRegistryError.d.ts +18 -0
- package/dist/serialization/SerializationRegistryError.js +18 -0
- package/dist/serialization/Serializer.d.ts +37 -0
- package/dist/serialization/Serializer.js +477 -0
- package/dist/serialization/contracts/SerializableClass.d.ts +20 -0
- package/dist/serialization/contracts/SerializableClass.js +1 -0
- package/dist/serialization/contracts/SerializedValue.d.ts +59 -0
- package/dist/serialization/contracts/SerializedValue.js +19 -0
- package/dist/serialization/contracts/SerializerOptions.d.ts +17 -0
- package/dist/serialization/contracts/SerializerOptions.js +1 -0
- package/dist/serialization/contracts/SerializerService.d.ts +26 -0
- package/dist/serialization/contracts/SerializerService.js +1 -0
- package/dist/serialization/contracts/index.d.ts +4 -0
- package/dist/serialization/contracts/index.js +4 -0
- package/dist/serialization/index.d.ts +6 -0
- package/dist/serialization/index.js +6 -0
- package/dist/server/App.d.ts +141 -0
- package/dist/server/App.js +225 -0
- package/dist/server/RequestContext.d.ts +42 -0
- package/dist/server/RequestContext.js +95 -0
- package/dist/server/appContext.d.ts +34 -0
- package/dist/server/appContext.js +42 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.js +3 -0
- package/dist/ssr/constants.d.ts +6 -0
- package/dist/ssr/constants.js +6 -0
- package/dist/ssr/contracts/DocumentHead.d.ts +32 -0
- package/dist/ssr/contracts/DocumentHead.js +1 -0
- package/dist/ssr/contracts/SsrRenderContext.d.ts +23 -0
- package/dist/ssr/contracts/SsrRenderContext.js +1 -0
- package/dist/ssr/contracts/SsrRenderResult.d.ts +21 -0
- package/dist/ssr/contracts/SsrRenderResult.js +1 -0
- package/dist/ssr/contracts/SsrRenderer.d.ts +9 -0
- package/dist/ssr/contracts/SsrRenderer.js +1 -0
- package/dist/ssr/contracts/SsrRequest.d.ts +16 -0
- package/dist/ssr/contracts/SsrRequest.js +1 -0
- package/dist/ssr/contracts/index.d.ts +5 -0
- package/dist/ssr/contracts/index.js +1 -0
- package/dist/ssr/createSsrRenderContext.d.ts +9 -0
- package/dist/ssr/createSsrRenderContext.js +20 -0
- package/dist/ssr/fastify/contracts/FastifySsrOptions.d.ts +21 -0
- package/dist/ssr/fastify/contracts/FastifySsrOptions.js +1 -0
- package/dist/ssr/fastify/contracts/index.d.ts +1 -0
- package/dist/ssr/fastify/contracts/index.js +1 -0
- package/dist/ssr/fastify/fastifySsr.d.ts +25 -0
- package/dist/ssr/fastify/fastifySsr.js +89 -0
- package/dist/ssr/fastify/index.d.ts +2 -0
- package/dist/ssr/fastify/index.js +1 -0
- package/dist/ssr/index.d.ts +6 -0
- package/dist/ssr/index.js +5 -0
- package/dist/ssr/renderDocumentHead.d.ts +8 -0
- package/dist/ssr/renderDocumentHead.js +62 -0
- package/dist/ssr/renderSsrDocument.d.ts +14 -0
- package/dist/ssr/renderSsrDocument.js +28 -0
- package/dist/ssr/serializeSsrState.d.ts +10 -0
- package/dist/ssr/serializeSsrState.js +18 -0
- package/dist/ssr/vite/contracts/ViteSsrOptions.d.ts +45 -0
- package/dist/ssr/vite/contracts/ViteSsrOptions.js +1 -0
- package/dist/ssr/vite/contracts/index.d.ts +1 -0
- package/dist/ssr/vite/contracts/index.js +1 -0
- package/dist/ssr/vite/fastifyViteSsr.d.ts +24 -0
- package/dist/ssr/vite/fastifyViteSsr.js +213 -0
- package/dist/ssr/vite/index.d.ts +4 -0
- package/dist/ssr/vite/index.js +2 -0
- package/dist/ssr/vite/viteSsrManifest.d.ts +16 -0
- package/dist/ssr/vite/viteSsrManifest.js +63 -0
- package/dist/storage/Storage.d.ts +244 -0
- package/dist/storage/Storage.js +348 -0
- package/dist/storage/contents.d.ts +8 -0
- package/dist/storage/contents.js +18 -0
- package/dist/storage/contracts/StorageListing.d.ts +50 -0
- package/dist/storage/contracts/StorageListing.js +1 -0
- package/dist/storage/contracts/index.d.ts +1 -0
- package/dist/storage/contracts/index.js +1 -0
- package/dist/storage/drivers/FlystorageDisk.d.ts +185 -0
- package/dist/storage/drivers/FlystorageDisk.js +250 -0
- package/dist/storage/drivers/FlystorageListing.d.ts +27 -0
- package/dist/storage/drivers/FlystorageListing.js +69 -0
- package/dist/storage/drivers/LocalStorageDisk.d.ts +25 -0
- package/dist/storage/drivers/LocalStorageDisk.js +38 -0
- package/dist/storage/drivers/S3StorageDisk.d.ts +17 -0
- package/dist/storage/drivers/S3StorageDisk.js +102 -0
- package/dist/storage/drivers/index.d.ts +3 -0
- package/dist/storage/drivers/index.js +3 -0
- package/dist/storage/index.d.ts +7 -0
- package/dist/storage/index.js +7 -0
- package/dist/storage/mime.d.ts +7 -0
- package/dist/storage/mime.js +28 -0
- package/dist/storage/path.d.ts +22 -0
- package/dist/storage/path.js +61 -0
- package/dist/storage/types.d.ts +218 -0
- package/dist/storage/types.js +1 -0
- package/dist/url/UrlGenerator.d.ts +32 -0
- package/dist/url/UrlGenerator.js +61 -0
- package/dist/url/contracts/UrlGeneratorOptions.d.ts +13 -0
- package/dist/url/contracts/UrlGeneratorOptions.js +1 -0
- package/dist/url/contracts/index.d.ts +1 -0
- package/dist/url/contracts/index.js +1 -0
- package/dist/url/index.d.ts +2 -0
- package/dist/url/index.js +2 -0
- package/dist/validation/index.d.ts +28 -0
- package/dist/validation/index.js +260 -0
- package/package.json +290 -0
- package/src/ai/AIErrors.ts +46 -0
- package/src/ai/AIFailover.ts +101 -0
- package/src/ai/AIProviders.ts +228 -0
- package/src/ai/AIQuotaDeferredError.ts +26 -0
- package/src/ai/AIRateLimiter.ts +880 -0
- package/src/ai/Agent.ts +3630 -0
- package/src/ai/AgentHistory.ts +576 -0
- package/src/ai/AgentRunJob.ts +65 -0
- package/src/ai/Ai.ts +2176 -0
- package/src/ai/AiConversation.ts +49 -0
- package/src/ai/AiExecutionContext.ts +19 -0
- package/src/ai/AiMessage.ts +131 -0
- package/src/ai/AiRateLimitBucket.ts +163 -0
- package/src/ai/AiRateLimitReservation.ts +117 -0
- package/src/ai/AiRequest.ts +466 -0
- package/src/ai/Estimates.ts +36 -0
- package/src/ai/Models.ts +373 -0
- package/src/ai/OpenAIProviderError.ts +98 -0
- package/src/ai/OpenAIQuotaRetry.ts +183 -0
- package/src/ai/ProviderCosts.ts +156 -0
- package/src/ai/README.md +187 -0
- package/src/ai/ResponsesProviderCall.ts +34 -0
- package/src/ai/agentCitations.ts +186 -0
- package/src/ai/contracts/AI.ts +380 -0
- package/src/ai/contracts/Agent.ts +539 -0
- package/src/ai/contracts/AiRequestRunCostSummary.ts +31 -0
- package/src/ai/contracts/Pricing.ts +95 -0
- package/src/ai/contracts/Providers.ts +73 -0
- package/src/ai/contracts/QuotaRetry.ts +39 -0
- package/src/ai/contracts/RateLimits.ts +49 -0
- package/src/ai/contracts/ResponsesProviderCall.ts +30 -0
- package/src/ai/contracts/index.ts +8 -0
- package/src/ai/examples/Conversation.ts +12 -0
- package/src/ai/examples/HelpAgent.ts +27 -0
- package/src/ai/examples/createHelpImage.ts +13 -0
- package/src/ai/index.ts +27 -0
- package/src/ai/registry.ts +70 -0
- package/src/ai/sdkNodeCompatibility.d.ts +76 -0
- package/src/ai/toolCallRecovery.ts +82 -0
- package/src/ai/toolHelpers.ts +145 -0
- package/src/auth/Auth.ts +1422 -0
- package/src/auth/AuthProvider.ts +251 -0
- package/src/auth/AuthToken.ts +239 -0
- package/src/auth/PasswordResetToken.ts +93 -0
- package/src/auth/README.md +396 -0
- package/src/auth/UserIdentity.ts +112 -0
- package/src/auth/contracts/AuthProviderDriver.ts +114 -0
- package/src/auth/contracts/index.ts +1 -0
- package/src/auth/examples/runPasswordAuth.ts +45 -0
- package/src/auth/index.ts +8 -0
- package/src/auth/passwordHash.ts +160 -0
- package/src/auth/providers/GoogleAuthProvider.ts +470 -0
- package/src/auth/providers/PasswordAuthProvider.ts +256 -0
- package/src/auth/providers/index.ts +3 -0
- package/src/auth/providers/resolveAuthProviders.ts +166 -0
- package/src/cache/Cache.ts +151 -0
- package/src/cache/README.md +137 -0
- package/src/cache/contracts/CacheDriver.ts +11 -0
- package/src/cache/contracts/CacheOperations.ts +28 -0
- package/src/cache/contracts/CacheOptions.ts +56 -0
- package/src/cache/contracts/CacheRepository.ts +62 -0
- package/src/cache/contracts/index.ts +4 -0
- package/src/cache/drivers/CacheManagerDriver.ts +84 -0
- package/src/cache/drivers/createCacheDriver.ts +191 -0
- package/src/cache/examples/runNoteCache.ts +37 -0
- package/src/cache/index.ts +2 -0
- package/src/cli/Cli.ts +110 -0
- package/src/cli/README.md +164 -0
- package/src/cli/commands/repl.ts +29 -0
- package/src/cli/contracts/CliCommand.ts +33 -0
- package/src/cli/contracts/CliConfig.ts +10 -0
- package/src/cli/contracts/CliOptions.ts +13 -0
- package/src/cli/contracts/CommandDefinition.ts +19 -0
- package/src/cli/contracts/ReplOptions.ts +11 -0
- package/src/cli/contracts/index.ts +5 -0
- package/src/cli/defineCommand.ts +25 -0
- package/src/cli/index.ts +5 -0
- package/src/cli/runDb3.ts +63 -0
- package/src/cli/runRepl.ts +55 -0
- package/src/config/Config.ts +110 -0
- package/src/config/README.md +142 -0
- package/src/config/env.ts +164 -0
- package/src/config/examples/loadNotesConfig.ts +29 -0
- package/src/config/examples/runConfig.ts +40 -0
- package/src/config/index.ts +2 -0
- package/src/db/ActiveProjection.ts +311 -0
- package/src/db/ActiveQueryBuilder.ts +831 -0
- package/src/db/ActiveRecord.ts +1317 -0
- package/src/db/Database.ts +1283 -0
- package/src/db/FieldType.ts +1243 -0
- package/src/db/README.md +508 -0
- package/src/db/SoftDeletes.ts +158 -0
- package/src/db/commands/check.ts +10 -0
- package/src/db/commands/index.ts +19 -0
- package/src/db/commands/makeMigration.ts +11 -0
- package/src/db/commands/migrate.ts +10 -0
- package/src/db/connection.ts +68 -0
- package/src/db/contracts/ActiveRecordDefinition.ts +69 -0
- package/src/db/contracts/DatabaseBackup.ts +7 -0
- package/src/db/contracts/DatabaseMigrationsConfig.ts +10 -0
- package/src/db/contracts/index.ts +3 -0
- package/src/db/dialects/columnTypes.ts +103 -0
- package/src/db/dialects/index.ts +6 -0
- package/src/db/dialects/mariadb.ts +51 -0
- package/src/db/dialects/mysql.ts +277 -0
- package/src/db/dialects/postgres.ts +143 -0
- package/src/db/dialects/resolveDialect.ts +88 -0
- package/src/db/dialects/types.ts +59 -0
- package/src/db/errors.ts +22 -0
- package/src/db/examples/DefinedUser.ts +20 -0
- package/src/db/examples/FieldNote.ts +27 -0
- package/src/db/examples/KnowledgeNote.ts +29 -0
- package/src/db/examples/NoteCodeField.ts +9 -0
- package/src/db/examples/createNotesTogether.ts +24 -0
- package/src/db/examples/outputs/workspace-notes.json +9 -0
- package/src/db/examples/runFieldNotes.ts +51 -0
- package/src/db/examples/runNoteMigrations.ts +64 -0
- package/src/db/examples/runWorkspaceNotes.ts +86 -0
- package/src/db/examples/workspaceNotes.ts +57 -0
- package/src/db/fields/BooleanField.ts +128 -0
- package/src/db/fields/CharUuidField.ts +91 -0
- package/src/db/fields/ChoiceStringField.ts +97 -0
- package/src/db/fields/DecimalField.ts +157 -0
- package/src/db/fields/EmailField.ts +79 -0
- package/src/db/fields/EncryptedJsonField.ts +211 -0
- package/src/db/fields/IntegerField.ts +200 -0
- package/src/db/fields/JsonField.ts +108 -0
- package/src/db/fields/JsonStringField.ts +63 -0
- package/src/db/fields/LinkField.ts +502 -0
- package/src/db/fields/PasswordField.ts +294 -0
- package/src/db/fields/StringField.ts +154 -0
- package/src/db/fields/StringListField.ts +179 -0
- package/src/db/fields/TextField.ts +71 -0
- package/src/db/fields/TimestampField.ts +164 -0
- package/src/db/fields/UlidField.ts +189 -0
- package/src/db/fields/UrlField.ts +97 -0
- package/src/db/fields/VectorField.ts +266 -0
- package/src/db/fields/createField.ts +22 -0
- package/src/db/fields/field.ts +209 -0
- package/src/db/fields/index.ts +76 -0
- package/src/db/fields/resolveFields.ts +69 -0
- package/src/db/index.ts +13 -0
- package/src/db/migrations/DatabaseMigrationManager.ts +756 -0
- package/src/db/migrations/DatabaseSchemaInspector.ts +541 -0
- package/src/db/migrations/KnexMigrationRenderer.ts +490 -0
- package/src/db/migrations/ModelSchemaCollector.ts +240 -0
- package/src/db/migrations/SchemaDiffer.ts +541 -0
- package/src/db/migrations/SchemaNames.ts +62 -0
- package/src/db/migrations/SchemaSnapshotSerializer.ts +59 -0
- package/src/db/migrations/contracts/DatabaseMigration.ts +143 -0
- package/src/db/migrations/contracts/SchemaChange.ts +113 -0
- package/src/db/migrations/contracts/SchemaSnapshot.ts +122 -0
- package/src/db/migrations/contracts/index.ts +3 -0
- package/src/db/migrations/errors.ts +45 -0
- package/src/db/migrations/index.ts +10 -0
- package/src/db/migrations/promoteDestructiveSchemaChanges.ts +120 -0
- package/src/db/queryMonitor.ts +549 -0
- package/src/db/sqlErrors.ts +36 -0
- package/src/db/test/db.ts +159 -0
- package/src/devtools/HttpEventDispatcher.ts +214 -0
- package/src/devtools/contracts/DevtoolsEventDispatcher.ts +57 -0
- package/src/devtools/contracts/index.ts +1 -0
- package/src/devtools/environment.ts +18 -0
- package/src/devtools/index.ts +3 -0
- package/src/events/Events.ts +165 -0
- package/src/events/README.md +106 -0
- package/src/events/contracts/EventConstructor.ts +12 -0
- package/src/events/contracts/EventListener.ts +8 -0
- package/src/events/contracts/EventUnsubscribe.ts +4 -0
- package/src/events/contracts/index.ts +3 -0
- package/src/events/examples/NoteSaved.ts +9 -0
- package/src/events/examples/runNoteEvents.ts +31 -0
- package/src/events/index.ts +2 -0
- package/src/flows/FlowBlockRegistry.ts +79 -0
- package/src/flows/FlowCompiler.ts +624 -0
- package/src/flows/FlowDefinitionError.ts +24 -0
- package/src/flows/FlowStepJob.ts +54 -0
- package/src/flows/FlowValueValidator.ts +120 -0
- package/src/flows/Flows.ts +1118 -0
- package/src/flows/README.md +144 -0
- package/src/flows/blocks/FlowInput.ts +32 -0
- package/src/flows/blocks/FlowOutput.ts +32 -0
- package/src/flows/blocks/Subflow.ts +24 -0
- package/src/flows/blocks/index.ts +11 -0
- package/src/flows/constants.ts +62 -0
- package/src/flows/contracts/FlowBlock.ts +73 -0
- package/src/flows/contracts/FlowCompiler.ts +32 -0
- package/src/flows/contracts/FlowDefinition.ts +126 -0
- package/src/flows/contracts/FlowDefinitionStore.ts +52 -0
- package/src/flows/contracts/FlowRun.ts +44 -0
- package/src/flows/contracts/FlowValue.ts +54 -0
- package/src/flows/contracts/FlowsService.ts +39 -0
- package/src/flows/contracts/index.ts +7 -0
- package/src/flows/defineBlock.ts +25 -0
- package/src/flows/drivers/FileFlowDefinitionStore.ts +372 -0
- package/src/flows/drivers/index.ts +1 -0
- package/src/flows/errors.ts +22 -0
- package/src/flows/examples/FlowExampleApp.ts +15 -0
- package/src/flows/examples/createTextFlow.ts +14 -0
- package/src/flows/examples/normalizeTextBlock.ts +15 -0
- package/src/flows/examples/runTextFlow.ts +46 -0
- package/src/flows/examples/uppercaseTextBlock.ts +11 -0
- package/src/flows/index.ts +13 -0
- package/src/flows/models/FlowRun.ts +164 -0
- package/src/flows/models/FlowRunEvent.ts +108 -0
- package/src/flows/models/FlowStepRun.ts +176 -0
- package/src/flows/models/index.ts +16 -0
- package/src/index.ts +40 -0
- package/src/logging/Log.ts +100 -0
- package/src/logging/README.md +139 -0
- package/src/logging/contracts/HttpExchange.ts +53 -0
- package/src/logging/contracts/Logger.ts +45 -0
- package/src/logging/contracts/LoggerDriver.ts +19 -0
- package/src/logging/contracts/LoggingOptions.ts +51 -0
- package/src/logging/contracts/index.ts +4 -0
- package/src/logging/drivers/PinoLoggerDriver.ts +376 -0
- package/src/logging/drivers/index.ts +1 -0
- package/src/logging/examples/runNoteLogs.ts +38 -0
- package/src/logging/index.ts +3 -0
- package/src/logging/transports/DevtoolsLogTransport.ts +142 -0
- package/src/mail/Mail.ts +188 -0
- package/src/mail/README.md +206 -0
- package/src/mail/examples/runMailPreview.ts +44 -0
- package/src/mail/examples/welcomeMessage.ts +26 -0
- package/src/mail/index.ts +4 -0
- package/src/mail/transports/FileMailTransport.ts +58 -0
- package/src/mail/transports/MailgunTransport.ts +85 -0
- package/src/mail/transports/ResendTransport.ts +80 -0
- package/src/media/MediaFile.ts +132 -0
- package/src/media/MediaItem.ts +132 -0
- package/src/media/MediaLibrary.ts +117 -0
- package/src/media/MediaManager.ts +874 -0
- package/src/media/README.md +358 -0
- package/src/media/constants.ts +31 -0
- package/src/media/contracts/MediaOptions.ts +9 -0
- package/src/media/contracts/index.ts +1 -0
- package/src/media/examples/createPrivateFileServer.ts +55 -0
- package/src/media/examples/runPrivateFiles.ts +45 -0
- package/src/media/examples/runProjectMedia.ts +46 -0
- package/src/media/image/ImageReconstructionError.ts +18 -0
- package/src/media/image/ImageVariantRenderer.ts +386 -0
- package/src/media/image/ImageVariantRequest.ts +65 -0
- package/src/media/image/contracts/ImageProcessor.ts +53 -0
- package/src/media/image/contracts/ImageVariant.ts +37 -0
- package/src/media/image/contracts/ImageVariantCacheOptions.ts +21 -0
- package/src/media/image/contracts/index.ts +3 -0
- package/src/media/image/index.ts +5 -0
- package/src/media/image/processors/SharpImageProcessor.ts +121 -0
- package/src/media/image/processors/index.ts +1 -0
- package/src/media/index.ts +8 -0
- package/src/media/types.ts +168 -0
- package/src/queue/FailedJob.ts +58 -0
- package/src/queue/Queue.ts +938 -0
- package/src/queue/QueueEvents.ts +57 -0
- package/src/queue/QueueRetryLaterError.ts +40 -0
- package/src/queue/QueueWorker.ts +296 -0
- package/src/queue/QueueableJob.ts +167 -0
- package/src/queue/QueuedJob.ts +69 -0
- package/src/queue/README.md +368 -0
- package/src/queue/RetryPolicy.ts +129 -0
- package/src/queue/commands/index.ts +13 -0
- package/src/queue/commands/makeJob.ts +11 -0
- package/src/queue/console.ts +518 -0
- package/src/queue/contracts/CreateJob.ts +13 -0
- package/src/queue/contracts/QueueDriver.ts +135 -0
- package/src/queue/contracts/QueueEvents.ts +77 -0
- package/src/queue/contracts/QueuePayload.ts +150 -0
- package/src/queue/contracts/QueueRetry.ts +47 -0
- package/src/queue/contracts/QueueService.ts +219 -0
- package/src/queue/contracts/QueueWorkerLifecycle.ts +71 -0
- package/src/queue/contracts/QueueableJob.ts +56 -0
- package/src/queue/contracts/RedisQueueDriver.ts +37 -0
- package/src/queue/contracts/index.ts +9 -0
- package/src/queue/createJob.ts +54 -0
- package/src/queue/drivers/DatabaseQueueDriver.ts +449 -0
- package/src/queue/drivers/RedisQueueDriver.ts +733 -0
- package/src/queue/examples/DeferredReportJob.ts +25 -0
- package/src/queue/examples/GenerateReportJob.ts +37 -0
- package/src/queue/examples/WriteReportJob.ts +37 -0
- package/src/queue/examples/createAndProcessReportJob.ts +29 -0
- package/src/queue/examples/dispatchReportWorkflows.ts +40 -0
- package/src/queue/examples/manageReportRetries.ts +47 -0
- package/src/queue/examples/outputs/create-and-process-report-job.json +6 -0
- package/src/queue/examples/outputs/dispatch-report-workflows.json +14 -0
- package/src/queue/examples/outputs/manage-report-retries.json +24 -0
- package/src/queue/examples/outputs/queue-reports.json +11 -0
- package/src/queue/examples/reportConsole.ts +47 -0
- package/src/queue/examples/runBackpressure.ts +27 -0
- package/src/queue/examples/runQueueReports.ts +80 -0
- package/src/queue/examples/runQueueWorkflows.ts +43 -0
- package/src/queue/index.ts +13 -0
- package/src/queue/queueMonitor.ts +368 -0
- package/src/scheduler/README.md +139 -0
- package/src/scheduler/ScheduledCall.ts +36 -0
- package/src/scheduler/ScheduledEvent.ts +149 -0
- package/src/scheduler/ScheduledJob.ts +58 -0
- package/src/scheduler/ScheduledOccurrence.ts +250 -0
- package/src/scheduler/ScheduledOccurrenceRecorder.ts +125 -0
- package/src/scheduler/Scheduler.ts +225 -0
- package/src/scheduler/SchedulerWorker.ts +151 -0
- package/src/scheduler/console.ts +368 -0
- package/src/scheduler/constants.ts +27 -0
- package/src/scheduler/contracts/Scheduler.ts +123 -0
- package/src/scheduler/contracts/SchedulerConsole.ts +40 -0
- package/src/scheduler/contracts/SchedulerWorker.ts +23 -0
- package/src/scheduler/contracts/index.ts +3 -0
- package/src/scheduler/examples/RecoverableSummaryJob.ts +18 -0
- package/src/scheduler/examples/WriteDailySummaryJob.ts +17 -0
- package/src/scheduler/examples/registerDailySummary.ts +13 -0
- package/src/scheduler/examples/runDailySummary.ts +46 -0
- package/src/scheduler/examples/runScheduledReplay.ts +60 -0
- package/src/scheduler/index.ts +9 -0
- package/src/scheduler/scheduleTime.ts +78 -0
- package/src/security/README.md +130 -0
- package/src/security/Security.ts +346 -0
- package/src/security/SecurityError.ts +16 -0
- package/src/security/contracts/SecurityOptions.ts +20 -0
- package/src/security/contracts/SecurityPayload.ts +14 -0
- package/src/security/contracts/index.ts +2 -0
- package/src/security/ensureAppKey.ts +82 -0
- package/src/security/examples/runSecretRoundTrip.ts +42 -0
- package/src/security/index.ts +4 -0
- package/src/serialization/README.md +169 -0
- package/src/serialization/Serializable.ts +17 -0
- package/src/serialization/SerializationError.ts +91 -0
- package/src/serialization/SerializationRegistry.ts +208 -0
- package/src/serialization/SerializationRegistryError.ts +24 -0
- package/src/serialization/Serializer.ts +793 -0
- package/src/serialization/contracts/SerializableClass.ts +26 -0
- package/src/serialization/contracts/SerializedValue.ts +71 -0
- package/src/serialization/contracts/SerializerOptions.ts +19 -0
- package/src/serialization/contracts/SerializerService.ts +29 -0
- package/src/serialization/contracts/index.ts +4 -0
- package/src/serialization/examples/ExportRequest.ts +25 -0
- package/src/serialization/examples/runExportSerialization.ts +24 -0
- package/src/serialization/index.ts +6 -0
- package/src/server/App.ts +326 -0
- package/src/server/README.md +219 -0
- package/src/server/RequestContext.ts +122 -0
- package/src/server/appContext.ts +59 -0
- package/src/server/examples/createFirstServer.ts +25 -0
- package/src/server/examples/startFirstServer.ts +19 -0
- package/src/server/index.ts +16 -0
- package/src/ssr/README.md +158 -0
- package/src/ssr/constants.ts +8 -0
- package/src/ssr/contracts/DocumentHead.ts +35 -0
- package/src/ssr/contracts/SsrRenderContext.ts +25 -0
- package/src/ssr/contracts/SsrRenderResult.ts +23 -0
- package/src/ssr/contracts/SsrRenderer.ts +12 -0
- package/src/ssr/contracts/SsrRequest.ts +17 -0
- package/src/ssr/contracts/index.ts +19 -0
- package/src/ssr/createSsrRenderContext.ts +25 -0
- package/src/ssr/examples/createPublicPageServer.ts +32 -0
- package/src/ssr/examples/runPublicPages.ts +25 -0
- package/src/ssr/fastify/contracts/FastifySsrOptions.ts +24 -0
- package/src/ssr/fastify/contracts/index.ts +5 -0
- package/src/ssr/fastify/fastifySsr.ts +110 -0
- package/src/ssr/fastify/index.ts +2 -0
- package/src/ssr/index.ts +10 -0
- package/src/ssr/renderDocumentHead.ts +72 -0
- package/src/ssr/renderSsrDocument.ts +35 -0
- package/src/ssr/serializeSsrState.ts +19 -0
- package/src/ssr/vite/contracts/ViteSsrOptions.ts +52 -0
- package/src/ssr/vite/contracts/index.ts +6 -0
- package/src/ssr/vite/fastifyViteSsr.ts +279 -0
- package/src/ssr/vite/index.ts +4 -0
- package/src/ssr/vite/viteSsrManifest.ts +92 -0
- package/src/storage/README.md +310 -0
- package/src/storage/Storage.ts +392 -0
- package/src/storage/contents.ts +23 -0
- package/src/storage/contracts/StorageListing.ts +55 -0
- package/src/storage/contracts/index.ts +1 -0
- package/src/storage/drivers/FlystorageDisk.ts +295 -0
- package/src/storage/drivers/FlystorageListing.ts +78 -0
- package/src/storage/drivers/LocalStorageDisk.ts +45 -0
- package/src/storage/drivers/S3StorageDisk.ts +114 -0
- package/src/storage/drivers/index.ts +3 -0
- package/src/storage/examples/runStorage.ts +37 -0
- package/src/storage/examples/runStreamExport.ts +41 -0
- package/src/storage/examples/writeCsvExport.ts +45 -0
- package/src/storage/index.ts +7 -0
- package/src/storage/mime.ts +30 -0
- package/src/storage/path.ts +76 -0
- package/src/storage/types.ts +251 -0
- package/src/url/README.md +41 -0
- package/src/url/UrlGenerator.ts +72 -0
- package/src/url/contracts/UrlGeneratorOptions.ts +14 -0
- package/src/url/contracts/index.ts +1 -0
- package/src/url/examples/runApplicationLinks.ts +33 -0
- package/src/url/index.ts +2 -0
- package/src/validation/README.md +433 -0
- package/src/validation/examples/runNoteValidation.ts +18 -0
- package/src/validation/examples/validateNoteInput.ts +31 -0
- package/src/validation/index.ts +398 -0
- package/templates/AGENTS.md +15 -0
|
@@ -0,0 +1,1118 @@
|
|
|
1
|
+
import { ActiveRecord } from '../db';
|
|
2
|
+
import type { QueueJob } from '../queue';
|
|
3
|
+
import { FLOW_INPUT_BLOCK_TYPE, FLOW_OUTPUT_BLOCK_TYPE, FLOW_SYSTEM_BLOCKS, SUBFLOW_BLOCK_TYPE } from './blocks';
|
|
4
|
+
import { FLOW_REPLAY_DEFINITION, FLOW_RUN_EVENT_TYPE, FLOW_RUN_STATUS, FLOW_STEP_STATUS } from './constants';
|
|
5
|
+
import type { CompiledFlowBlock, FlowBlockLogInput, FlowBlockMetadata, FlowDefinition, FlowDefinitionSummary, FlowDefinitionWriteOptions, FlowExecutionDefinition, FlowReplayOptions, FlowResolvedBlockContract, FlowRunOptions, FlowValue, FlowValueDefinitions, FlowValues, FlowsOptions, StoredFlowDefinition } from './contracts';
|
|
6
|
+
import { FlowBlockRegistry } from './FlowBlockRegistry';
|
|
7
|
+
import { FlowCompiler } from './FlowCompiler';
|
|
8
|
+
import { FlowDefinitionError } from './FlowDefinitionError';
|
|
9
|
+
import { flowErrorSnapshot } from './errors';
|
|
10
|
+
import { FlowStepJob } from './FlowStepJob';
|
|
11
|
+
import { validateFlowValues } from './FlowValueValidator';
|
|
12
|
+
import { FlowRun, FlowRunEvent, FlowStepRun } from './models';
|
|
13
|
+
|
|
14
|
+
const DEFAULT_MAX_PAYLOAD_BYTES = 1024 * 1024;
|
|
15
|
+
|
|
16
|
+
interface NestedRunParent {
|
|
17
|
+
run: FlowRun;
|
|
18
|
+
blockId: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface NestedDefinitionSelection {
|
|
22
|
+
stored: StoredFlowDefinition;
|
|
23
|
+
replayOf: FlowRun | null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface StoredExecutionDefinition extends Omit<StoredFlowDefinition, 'definition'> {
|
|
27
|
+
definition: FlowExecutionDefinition;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Durable run details returned to APIs and development inspectors.
|
|
32
|
+
*/
|
|
33
|
+
export interface FlowRunDetails {
|
|
34
|
+
/** Flow run summary and immutable definition snapshot. */
|
|
35
|
+
run: FlowRun;
|
|
36
|
+
/** Block step states in execution order. */
|
|
37
|
+
steps: FlowStepRun[];
|
|
38
|
+
/** Ordered lifecycle and log events. */
|
|
39
|
+
events: FlowRunEvent[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Application-scoped flow definition, execution, observability, and replay service.
|
|
44
|
+
*/
|
|
45
|
+
export class Flows {
|
|
46
|
+
/** Source-of-truth definition provider exposed for advanced app integrations. */
|
|
47
|
+
readonly definitions;
|
|
48
|
+
/** Registered executable block types. */
|
|
49
|
+
readonly blocks: FlowBlockRegistry;
|
|
50
|
+
readonly #compiler: FlowCompiler;
|
|
51
|
+
readonly #queueName: string;
|
|
52
|
+
readonly #maxTries: number;
|
|
53
|
+
readonly #maxPayloadBytes: number;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Creates an application flow service over the existing queue and models.
|
|
57
|
+
*
|
|
58
|
+
* @param options - Queue, definition store, block types, and runtime limits.
|
|
59
|
+
*/
|
|
60
|
+
constructor(private readonly options: FlowsOptions) {
|
|
61
|
+
this.definitions = options.definitions;
|
|
62
|
+
this.blocks = new FlowBlockRegistry([...FLOW_SYSTEM_BLOCKS, ...options.blocks]);
|
|
63
|
+
this.#compiler = new FlowCompiler(this.blocks);
|
|
64
|
+
this.#queueName = options.queueName ?? 'flows';
|
|
65
|
+
this.#maxTries = options.maxTries ?? 3;
|
|
66
|
+
this.#maxPayloadBytes = options.maxPayloadBytes ?? DEFAULT_MAX_PAYLOAD_BYTES;
|
|
67
|
+
this.options.queue.registerJob(FlowStepJob);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Lists current source definitions from the configured provider.
|
|
72
|
+
*
|
|
73
|
+
* @returns Available flow definition summaries.
|
|
74
|
+
*/
|
|
75
|
+
listDefinitions(): Promise<FlowDefinitionSummary[]> {
|
|
76
|
+
return this.definitions.list();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Loads and validates one source definition.
|
|
81
|
+
*
|
|
82
|
+
* @param id - Stable flow ULID.
|
|
83
|
+
* @returns Stored definition and provider metadata.
|
|
84
|
+
*/
|
|
85
|
+
async definition(id: string): Promise<StoredFlowDefinition> {
|
|
86
|
+
const stored = await this.definitions.read(id);
|
|
87
|
+
|
|
88
|
+
if (!stored) {
|
|
89
|
+
throw new Error(`Flow definition "${id}" was not found.`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
await this.#resolveStoredDefinition(stored);
|
|
93
|
+
|
|
94
|
+
return stored;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Validates and persists one definition through the configured provider.
|
|
99
|
+
*
|
|
100
|
+
* @param definition - Source-of-truth graph to save.
|
|
101
|
+
* @param options - Optional revision and creation path.
|
|
102
|
+
* @returns Stored definition and new revision.
|
|
103
|
+
*/
|
|
104
|
+
async saveDefinition(
|
|
105
|
+
definition: FlowDefinition,
|
|
106
|
+
options: FlowDefinitionWriteOptions = {},
|
|
107
|
+
): Promise<StoredFlowDefinition> {
|
|
108
|
+
await this.#resolveStoredDefinition({
|
|
109
|
+
definition,
|
|
110
|
+
revision: options.expectedRevision ?? 'pending',
|
|
111
|
+
path: options.path,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
return await this.definitions.write(definition, options);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Returns registered block metadata for palettes and inspectors.
|
|
119
|
+
*
|
|
120
|
+
* @returns Designer-safe block metadata.
|
|
121
|
+
*/
|
|
122
|
+
blockMetadata(): FlowBlockMetadata[] {
|
|
123
|
+
return this.blocks.metadata();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Resolves structural and nested block contracts into an immutable run snapshot.
|
|
128
|
+
*
|
|
129
|
+
* Child definitions are recursively captured here so a queued parent continues
|
|
130
|
+
* to execute the same nested graph even when source files change mid-run.
|
|
131
|
+
*
|
|
132
|
+
* @param stored - Source definition and provider metadata.
|
|
133
|
+
* @param ancestry - Parent flow ids used to detect recursive nesting.
|
|
134
|
+
* @returns Stored definition with resolved contracts and child snapshots.
|
|
135
|
+
*/
|
|
136
|
+
async #resolveStoredDefinition(
|
|
137
|
+
stored: StoredFlowDefinition,
|
|
138
|
+
ancestry: string[] = [],
|
|
139
|
+
): Promise<StoredExecutionDefinition> {
|
|
140
|
+
if (isExecutionDefinition(stored.definition)) {
|
|
141
|
+
this.#compiler.compile(stored.definition);
|
|
142
|
+
return stored as StoredExecutionDefinition;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (ancestry.includes(stored.definition.id)) {
|
|
146
|
+
throw new FlowDefinitionError([{
|
|
147
|
+
path: 'blocks',
|
|
148
|
+
message: `Nested flow cycle detected: ${[...ancestry, stored.definition.id].join(' -> ')}.`,
|
|
149
|
+
}]);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const nextAncestry = [...ancestry, stored.definition.id];
|
|
153
|
+
const resolvedBlocks: Record<string, FlowResolvedBlockContract> = {};
|
|
154
|
+
const nestedDefinitions: FlowExecutionDefinition['nestedDefinitions'] = {};
|
|
155
|
+
|
|
156
|
+
for (const instance of stored.definition.blocks) {
|
|
157
|
+
if (instance.type === FLOW_INPUT_BLOCK_TYPE) {
|
|
158
|
+
resolvedBlocks[instance.id] = boundaryContract(stored.definition.inputs);
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (instance.type === FLOW_OUTPUT_BLOCK_TYPE) {
|
|
163
|
+
resolvedBlocks[instance.id] = boundaryContract(stored.definition.outputs);
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const registered = this.blocks.get(instance.type);
|
|
168
|
+
|
|
169
|
+
if (!registered || (registered.kind ?? 'function') !== 'flow' || !instance.flowId) continue;
|
|
170
|
+
|
|
171
|
+
const child = await this.definitions.read(instance.flowId);
|
|
172
|
+
|
|
173
|
+
if (!child) {
|
|
174
|
+
throw new FlowDefinitionError([{
|
|
175
|
+
path: `blocks.${instance.id}.flowId`,
|
|
176
|
+
message: `Nested flow definition "${instance.flowId}" was not found.`,
|
|
177
|
+
}]);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const resolvedChild = await this.#resolveStoredDefinition(child, nextAncestry);
|
|
181
|
+
|
|
182
|
+
nestedDefinitions[instance.id] = resolvedChild;
|
|
183
|
+
|
|
184
|
+
if (instance.type === SUBFLOW_BLOCK_TYPE) {
|
|
185
|
+
resolvedBlocks[instance.id] = {
|
|
186
|
+
inputs: structuredClone(resolvedChild.definition.inputs),
|
|
187
|
+
outputs: structuredClone(resolvedChild.definition.outputs),
|
|
188
|
+
};
|
|
189
|
+
} else {
|
|
190
|
+
assertMatchingContracts(registered.inputs, resolvedChild.definition.inputs, `Nested flow "${instance.flowId}" inputs`);
|
|
191
|
+
assertMatchingContracts(registered.outputs, resolvedChild.definition.outputs, `Nested flow "${instance.flowId}" outputs`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const definition: FlowExecutionDefinition = {
|
|
196
|
+
...structuredClone(stored.definition),
|
|
197
|
+
resolvedBlocks,
|
|
198
|
+
nestedDefinitions,
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
this.#compiler.compile(definition);
|
|
202
|
+
|
|
203
|
+
return {
|
|
204
|
+
...stored,
|
|
205
|
+
definition,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Creates and queues a new run of the latest stored definition.
|
|
211
|
+
*
|
|
212
|
+
* @param flowId - Stable flow ULID.
|
|
213
|
+
* @param input - Public flow input values.
|
|
214
|
+
* @param options - Optional replay relationship metadata.
|
|
215
|
+
* @returns Newly-created durable flow run.
|
|
216
|
+
*/
|
|
217
|
+
async run(
|
|
218
|
+
flowId: string,
|
|
219
|
+
input: FlowValues,
|
|
220
|
+
options: FlowRunOptions = {},
|
|
221
|
+
): Promise<FlowRun> {
|
|
222
|
+
const stored = await this.definition(flowId);
|
|
223
|
+
const replayOf = options.replayOfRunId
|
|
224
|
+
? await FlowRun.findOrFail(options.replayOfRunId)
|
|
225
|
+
: null;
|
|
226
|
+
|
|
227
|
+
return await this.#createAndDispatch(stored, input, replayOf, null, null, null);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Replays a historical run using its original snapshot or the latest source.
|
|
232
|
+
*
|
|
233
|
+
* @param runId - Historical flow run ULID.
|
|
234
|
+
* @param options - Definition source and optional replacement input.
|
|
235
|
+
* @returns Newly-created linked replay run.
|
|
236
|
+
*/
|
|
237
|
+
async replay(runId: string, options: FlowReplayOptions = {}): Promise<FlowRun> {
|
|
238
|
+
const previous = await FlowRun.findOrFail(runId);
|
|
239
|
+
const definitionSource = options.definition ?? FLOW_REPLAY_DEFINITION.original;
|
|
240
|
+
const input = options.input ?? previous.input;
|
|
241
|
+
|
|
242
|
+
if (!input) {
|
|
243
|
+
throw new Error(`Flow run "${runId}" does not contain replayable input.`);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const stored = definitionSource === FLOW_REPLAY_DEFINITION.latest
|
|
247
|
+
? await this.definition(requiredString(previous.flowId, 'Historical flow id is required.'))
|
|
248
|
+
: {
|
|
249
|
+
definition: requiredDefinition(previous.definitionSnapshot),
|
|
250
|
+
revision: requiredString(previous.definitionRevision, 'Historical definition revision is required.'),
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
return await this.#createAndDispatch(stored, input, previous, null, definitionSource, null);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Lists recent runs, optionally restricted to one source flow.
|
|
258
|
+
*
|
|
259
|
+
* @param flowId - Optional source flow ULID.
|
|
260
|
+
* @param limit - Maximum rows to return.
|
|
261
|
+
* @returns Recent runs ordered newest first.
|
|
262
|
+
*/
|
|
263
|
+
async listRuns(flowId?: string, limit = 50): Promise<FlowRun[]> {
|
|
264
|
+
const query = FlowRun.query().orderBy('createdAt', 'desc').limit(Math.max(1, Math.min(limit, 200)));
|
|
265
|
+
|
|
266
|
+
if (flowId) {
|
|
267
|
+
query.where('flowId', flowId);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return await query.all();
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Loads one run with ordered block steps and timeline events.
|
|
275
|
+
*
|
|
276
|
+
* @param runId - Flow run ULID.
|
|
277
|
+
* @returns Complete durable run details.
|
|
278
|
+
*/
|
|
279
|
+
async runDetails(runId: string): Promise<FlowRunDetails> {
|
|
280
|
+
const run = await FlowRun.findOrFail(runId);
|
|
281
|
+
const [steps, events] = await Promise.all([
|
|
282
|
+
FlowStepRun.where('run', run).orderBy('sequence').all(),
|
|
283
|
+
FlowRunEvent.where('run', run).orderBy('sequence').all(),
|
|
284
|
+
]);
|
|
285
|
+
|
|
286
|
+
return {
|
|
287
|
+
run,
|
|
288
|
+
steps,
|
|
289
|
+
events,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Executes one queued block step and advances the durable run.
|
|
295
|
+
*
|
|
296
|
+
* This method is public for FlowStepJob and should not be called directly by
|
|
297
|
+
* application routes.
|
|
298
|
+
*
|
|
299
|
+
* @param runId - Flow run ULID.
|
|
300
|
+
* @param blockId - Block occurrence ULID.
|
|
301
|
+
* @param queueJob - Claimed queue job metadata.
|
|
302
|
+
*/
|
|
303
|
+
async processStep(runId: string, blockId: string, queueJob: QueueJob): Promise<void> {
|
|
304
|
+
const run = await FlowRun.findOrFail(runId);
|
|
305
|
+
|
|
306
|
+
if (run.status === FLOW_RUN_STATUS.failed) return;
|
|
307
|
+
|
|
308
|
+
const compiled = this.#compiler.compile(requiredDefinition(run.definitionSnapshot));
|
|
309
|
+
const compiledBlock = compiled.blocks.find(candidate => candidate.instance.id === blockId);
|
|
310
|
+
|
|
311
|
+
if (!compiledBlock) {
|
|
312
|
+
throw new Error(`Block "${blockId}" does not exist in flow run "${runId}".`);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const step = await FlowStepRun
|
|
316
|
+
.where({
|
|
317
|
+
run,
|
|
318
|
+
blockId,
|
|
319
|
+
})
|
|
320
|
+
.firstOrFail();
|
|
321
|
+
|
|
322
|
+
if (step.status === FLOW_STEP_STATUS.completed) {
|
|
323
|
+
await this.#advanceCompletedStep(run, step, compiled.blocks);
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (run.status === FLOW_RUN_STATUS.completed) return;
|
|
328
|
+
|
|
329
|
+
let completed: boolean;
|
|
330
|
+
|
|
331
|
+
try {
|
|
332
|
+
completed = await this.#executeBlock(run, step, compiledBlock, queueJob);
|
|
333
|
+
} catch (error) {
|
|
334
|
+
await this.#recordStepFailure(run, step, queueJob, error);
|
|
335
|
+
throw error;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (completed) {
|
|
339
|
+
await this.#advanceCompletedStep(run, step, compiled.blocks);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Creates all run/step records atomically, then dispatches the root step.
|
|
345
|
+
*
|
|
346
|
+
* @param stored - Definition and immutable content revision to execute.
|
|
347
|
+
* @param input - Public input values supplied to the root block.
|
|
348
|
+
* @param replayOf - Historical run linked to this invocation.
|
|
349
|
+
* @param parent - Parent run and block for nested execution.
|
|
350
|
+
* @param replayDefinition - Definition source selected for replay lineage.
|
|
351
|
+
* @param beforeDispatch - Optional hook that links nested state before queue visibility.
|
|
352
|
+
* @returns Created durable run after its root step is queued.
|
|
353
|
+
*/
|
|
354
|
+
async #createAndDispatch(
|
|
355
|
+
stored: StoredFlowDefinition,
|
|
356
|
+
input: FlowValues,
|
|
357
|
+
replayOf: FlowRun | null,
|
|
358
|
+
parent: NestedRunParent | null,
|
|
359
|
+
replayDefinition: typeof FLOW_REPLAY_DEFINITION[keyof typeof FLOW_REPLAY_DEFINITION] | null,
|
|
360
|
+
beforeDispatch: ((run: FlowRun, rootStep: FlowStepRun) => Promise<void>) | null,
|
|
361
|
+
): Promise<FlowRun> {
|
|
362
|
+
const execution = await this.#resolveStoredDefinition(stored);
|
|
363
|
+
const compiled = this.#compiler.compile(execution.definition);
|
|
364
|
+
const normalizedInput = validateFlowValues(input, execution.definition.inputs, 'flow.input');
|
|
365
|
+
|
|
366
|
+
this.#assertPayloadSize(normalizedInput, 'Flow input');
|
|
367
|
+
|
|
368
|
+
const db = FlowRun.getDb();
|
|
369
|
+
const createdIds = await db.transaction(async transaction => ActiveRecord.withDb(transaction, async () => {
|
|
370
|
+
const run = FlowRun.create({
|
|
371
|
+
flowId: execution.definition.id,
|
|
372
|
+
flowName: execution.definition.name,
|
|
373
|
+
status: FLOW_RUN_STATUS.queued,
|
|
374
|
+
replayDefinition,
|
|
375
|
+
definitionRevision: execution.revision,
|
|
376
|
+
definitionSnapshot: structuredClone(execution.definition),
|
|
377
|
+
input: normalizedInput,
|
|
378
|
+
output: null,
|
|
379
|
+
error: null,
|
|
380
|
+
replayOf,
|
|
381
|
+
parentRun: parent?.run ?? null,
|
|
382
|
+
parentBlockId: parent?.blockId ?? null,
|
|
383
|
+
startedAt: null,
|
|
384
|
+
completedAt: null,
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
await run.save();
|
|
388
|
+
|
|
389
|
+
const steps: FlowStepRun[] = [];
|
|
390
|
+
|
|
391
|
+
for (const compiledBlock of compiled.blocks) {
|
|
392
|
+
const step = FlowStepRun.create({
|
|
393
|
+
run,
|
|
394
|
+
blockId: compiledBlock.instance.id,
|
|
395
|
+
blockType: compiledBlock.instance.type,
|
|
396
|
+
blockName: compiledBlock.instance.name || compiledBlock.block.name,
|
|
397
|
+
sequence: compiledBlock.sequence,
|
|
398
|
+
status: FLOW_STEP_STATUS.pending,
|
|
399
|
+
attempt: 0,
|
|
400
|
+
queueJobId: null,
|
|
401
|
+
nestedRun: null,
|
|
402
|
+
input: null,
|
|
403
|
+
output: null,
|
|
404
|
+
error: null,
|
|
405
|
+
startedAt: null,
|
|
406
|
+
completedAt: null,
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
await step.save();
|
|
410
|
+
steps.push(step);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
await this.#recordEvent(run, null, FLOW_RUN_EVENT_TYPE.runCreated, `Run created for ${execution.definition.name}.`, {
|
|
414
|
+
flowId: execution.definition.id,
|
|
415
|
+
definitionRevision: execution.revision,
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
if (replayOf?.id) {
|
|
419
|
+
await this.#recordEvent(run, null, FLOW_RUN_EVENT_TYPE.runReplayed, `Replaying run ${replayOf.id}.`, {
|
|
420
|
+
replayOfRunId: replayOf.id,
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
return {
|
|
425
|
+
runId: requiredString(run.id, 'Created flow run id is required.'),
|
|
426
|
+
rootStepId: requiredString(steps[0]?.id, 'Created root flow step id is required.'),
|
|
427
|
+
};
|
|
428
|
+
}));
|
|
429
|
+
const run = await FlowRun.findOrFail(createdIds.runId);
|
|
430
|
+
const rootStep = await FlowStepRun.findOrFail(createdIds.rootStepId);
|
|
431
|
+
|
|
432
|
+
try {
|
|
433
|
+
await beforeDispatch?.(run, rootStep);
|
|
434
|
+
await this.#dispatchStep(run, rootStep);
|
|
435
|
+
} catch (error) {
|
|
436
|
+
await this.#failUndispatchedRun(run, rootStep, error);
|
|
437
|
+
throw error;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
return run;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Executes and records one block function without scheduling its successor.
|
|
445
|
+
*
|
|
446
|
+
* @param run - Durable flow run being advanced.
|
|
447
|
+
* @param step - Durable block step being executed.
|
|
448
|
+
* @param compiledBlock - Validated block occurrence and port connections.
|
|
449
|
+
* @param queueJob - Claimed queue attempt metadata.
|
|
450
|
+
* @returns True when the step completed synchronously; false while nested work waits.
|
|
451
|
+
*/
|
|
452
|
+
async #executeBlock(
|
|
453
|
+
run: FlowRun,
|
|
454
|
+
step: FlowStepRun,
|
|
455
|
+
compiledBlock: CompiledFlowBlock,
|
|
456
|
+
queueJob: QueueJob,
|
|
457
|
+
): Promise<boolean> {
|
|
458
|
+
const input = await this.#inputFor(run, compiledBlock);
|
|
459
|
+
const config = validateFlowValues(
|
|
460
|
+
compiledBlock.instance.config ?? {},
|
|
461
|
+
compiledBlock.block.config ?? {},
|
|
462
|
+
`block.${compiledBlock.instance.id}.config`,
|
|
463
|
+
);
|
|
464
|
+
|
|
465
|
+
this.#assertPayloadSize(input, `Block ${compiledBlock.instance.id} input`);
|
|
466
|
+
|
|
467
|
+
const now = new Date();
|
|
468
|
+
|
|
469
|
+
if (run.status === FLOW_RUN_STATUS.queued) {
|
|
470
|
+
run.status = FLOW_RUN_STATUS.running;
|
|
471
|
+
run.startedAt = now;
|
|
472
|
+
await run.save();
|
|
473
|
+
await this.#recordEvent(run, null, FLOW_RUN_EVENT_TYPE.runStarted, `Run started with ${compiledBlock.instance.name || compiledBlock.block.name}.`);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
step.status = FLOW_STEP_STATUS.running;
|
|
477
|
+
step.attempt = queueJob.attempts;
|
|
478
|
+
step.queueJobId = String(queueJob.id);
|
|
479
|
+
step.input = input;
|
|
480
|
+
step.error = null;
|
|
481
|
+
step.startedAt = now;
|
|
482
|
+
step.completedAt = null;
|
|
483
|
+
await step.save();
|
|
484
|
+
await this.#recordEvent(run, step, FLOW_RUN_EVENT_TYPE.stepStarted, `${step.blockName} started.`, {
|
|
485
|
+
attempt: queueJob.attempts,
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
if ((compiledBlock.block.kind ?? 'function') === 'flow') {
|
|
489
|
+
await this.#startNestedFlow(run, step, compiledBlock, input);
|
|
490
|
+
return false;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
if (!compiledBlock.block.run) {
|
|
494
|
+
throw new Error(`Function flow block "${compiledBlock.block.type}" does not define run().`);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
const rawOutput = await compiledBlock.block.run(input, {
|
|
498
|
+
flowId: requiredString(run.flowId, 'Flow run flowId is required.'),
|
|
499
|
+
runId: requiredString(run.id, 'Flow run id is required.'),
|
|
500
|
+
stepRunId: requiredString(step.id, 'Flow step-run id is required.'),
|
|
501
|
+
block: compiledBlock.instance,
|
|
502
|
+
config,
|
|
503
|
+
log: async (level, message, data) => {
|
|
504
|
+
await this.#recordBlockLog(run, step, {
|
|
505
|
+
level,
|
|
506
|
+
message,
|
|
507
|
+
data,
|
|
508
|
+
});
|
|
509
|
+
},
|
|
510
|
+
});
|
|
511
|
+
const output = validateFlowValues(rawOutput, compiledBlock.block.outputs, `block.${compiledBlock.instance.id}.output`);
|
|
512
|
+
|
|
513
|
+
this.#assertPayloadSize(output, `Block ${compiledBlock.instance.id} output`);
|
|
514
|
+
|
|
515
|
+
step.status = FLOW_STEP_STATUS.completed;
|
|
516
|
+
step.output = output;
|
|
517
|
+
step.error = null;
|
|
518
|
+
step.completedAt = new Date();
|
|
519
|
+
await step.save();
|
|
520
|
+
await this.#recordEvent(run, step, FLOW_RUN_EVENT_TYPE.stepCompleted, `${step.blockName} completed.`);
|
|
521
|
+
|
|
522
|
+
return true;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Delegates one flow-backed block to a durable child run.
|
|
527
|
+
*
|
|
528
|
+
* @param run - Parent flow run.
|
|
529
|
+
* @param step - Parent block step entering its waiting state.
|
|
530
|
+
* @param compiledBlock - Flow-backed block occurrence and contract.
|
|
531
|
+
* @param input - Validated values passed to the nested flow.
|
|
532
|
+
*/
|
|
533
|
+
async #startNestedFlow(
|
|
534
|
+
run: FlowRun,
|
|
535
|
+
step: FlowStepRun,
|
|
536
|
+
compiledBlock: CompiledFlowBlock,
|
|
537
|
+
input: FlowValues,
|
|
538
|
+
): Promise<void> {
|
|
539
|
+
const blockId = requiredString(step.blockId, 'Nested parent block id is required.');
|
|
540
|
+
const existing = await FlowRun
|
|
541
|
+
.where({
|
|
542
|
+
parentRun: run,
|
|
543
|
+
parentBlockId: blockId,
|
|
544
|
+
})
|
|
545
|
+
.orderBy('createdAt', 'desc')
|
|
546
|
+
.first();
|
|
547
|
+
|
|
548
|
+
if (existing) {
|
|
549
|
+
await this.#attachNestedRun(step, existing);
|
|
550
|
+
|
|
551
|
+
if (existing.status === FLOW_RUN_STATUS.completed) {
|
|
552
|
+
await this.#completeNestedParent(existing);
|
|
553
|
+
} else if (existing.status === FLOW_RUN_STATUS.failed) {
|
|
554
|
+
await this.#failNestedParent(existing);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
const nestedFlowId = requiredString(compiledBlock.instance.flowId, `Flow-backed block "${blockId}" requires flowId.`);
|
|
561
|
+
const selection = await this.#nestedDefinitionSelection(run, blockId, nestedFlowId);
|
|
562
|
+
|
|
563
|
+
assertMatchingContracts(
|
|
564
|
+
compiledBlock.block.inputs,
|
|
565
|
+
selection.stored.definition.inputs,
|
|
566
|
+
`Nested flow "${nestedFlowId}" inputs`,
|
|
567
|
+
);
|
|
568
|
+
assertMatchingContracts(
|
|
569
|
+
compiledBlock.block.outputs,
|
|
570
|
+
selection.stored.definition.outputs,
|
|
571
|
+
`Nested flow "${nestedFlowId}" outputs`,
|
|
572
|
+
);
|
|
573
|
+
|
|
574
|
+
step.status = FLOW_STEP_STATUS.waiting;
|
|
575
|
+
await step.save();
|
|
576
|
+
await this.#recordEvent(run, step, FLOW_RUN_EVENT_TYPE.stepWaiting, `${step.blockName} is waiting for a nested flow.`);
|
|
577
|
+
|
|
578
|
+
try {
|
|
579
|
+
await this.#createAndDispatch(
|
|
580
|
+
selection.stored,
|
|
581
|
+
input,
|
|
582
|
+
selection.replayOf,
|
|
583
|
+
{
|
|
584
|
+
run,
|
|
585
|
+
blockId,
|
|
586
|
+
},
|
|
587
|
+
run.replayDefinition,
|
|
588
|
+
async nestedRun => {
|
|
589
|
+
await this.#attachNestedRun(step, nestedRun);
|
|
590
|
+
await this.#recordEvent(run, step, FLOW_RUN_EVENT_TYPE.nestedStarted, `${step.blockName} started ${nestedRun.flowName}.`, {
|
|
591
|
+
childRunId: requiredString(nestedRun.id, 'Nested flow run id is required.'),
|
|
592
|
+
flowId: requiredString(nestedRun.flowId, 'Nested flow id is required.'),
|
|
593
|
+
});
|
|
594
|
+
},
|
|
595
|
+
);
|
|
596
|
+
} catch (error) {
|
|
597
|
+
const latestParent = await FlowRun.findOrFail(requiredString(run.id, 'Parent flow run id is required.'));
|
|
598
|
+
|
|
599
|
+
if (latestParent.status === FLOW_RUN_STATUS.failed) return;
|
|
600
|
+
throw error;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* Chooses the latest nested definition or the child snapshot linked to an
|
|
607
|
+
* original-definition replay.
|
|
608
|
+
*
|
|
609
|
+
* @param parent - Parent run executing the flow-backed block.
|
|
610
|
+
* @param blockId - Parent block occurrence ULID.
|
|
611
|
+
* @param nestedFlowId - Referenced child flow ULID.
|
|
612
|
+
* @returns Definition and historical child lineage for the new child run.
|
|
613
|
+
*/
|
|
614
|
+
async #nestedDefinitionSelection(
|
|
615
|
+
parent: FlowRun,
|
|
616
|
+
blockId: string,
|
|
617
|
+
nestedFlowId: string,
|
|
618
|
+
): Promise<NestedDefinitionSelection> {
|
|
619
|
+
const previousParent = await parent.replayOf?.load() ?? null;
|
|
620
|
+
let previousChild: FlowRun | null = null;
|
|
621
|
+
|
|
622
|
+
if (previousParent) {
|
|
623
|
+
const previousStep = await FlowStepRun
|
|
624
|
+
.where({
|
|
625
|
+
run: previousParent,
|
|
626
|
+
blockId,
|
|
627
|
+
})
|
|
628
|
+
.first();
|
|
629
|
+
|
|
630
|
+
previousChild = await previousStep?.nestedRun?.load() ?? null;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
if (parent.replayDefinition === FLOW_REPLAY_DEFINITION.original && previousChild) {
|
|
634
|
+
return {
|
|
635
|
+
stored: {
|
|
636
|
+
definition: requiredDefinition(previousChild.definitionSnapshot),
|
|
637
|
+
revision: requiredString(previousChild.definitionRevision, 'Nested replay definition revision is required.'),
|
|
638
|
+
},
|
|
639
|
+
replayOf: previousChild,
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
const captured = requiredDefinition(parent.definitionSnapshot).nestedDefinitions[blockId];
|
|
644
|
+
|
|
645
|
+
if (captured) {
|
|
646
|
+
return {
|
|
647
|
+
stored: captured,
|
|
648
|
+
replayOf: previousChild,
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
return {
|
|
653
|
+
stored: await this.definition(nestedFlowId),
|
|
654
|
+
replayOf: previousChild,
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* Links a parent step to its child run while preserving newer step state.
|
|
660
|
+
*
|
|
661
|
+
* @param step - Parent flow-backed step.
|
|
662
|
+
* @param child - Nested child run.
|
|
663
|
+
*/
|
|
664
|
+
async #attachNestedRun(step: FlowStepRun, child: FlowRun): Promise<void> {
|
|
665
|
+
const current = await FlowStepRun.findOrFail(requiredString(step.id, 'Parent flow step id is required.'));
|
|
666
|
+
|
|
667
|
+
current.set('nestedRun', child);
|
|
668
|
+
|
|
669
|
+
if (current.status === FLOW_STEP_STATUS.running) {
|
|
670
|
+
current.status = FLOW_STEP_STATUS.waiting;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
await current.save();
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
/**
|
|
677
|
+
* Completes a waiting parent block from a successful nested run and advances it.
|
|
678
|
+
*
|
|
679
|
+
* @param child - Completed nested child run.
|
|
680
|
+
*/
|
|
681
|
+
async #completeNestedParent(child: FlowRun): Promise<void> {
|
|
682
|
+
const parent = await child.parentRun?.load() ?? null;
|
|
683
|
+
|
|
684
|
+
if (!parent || !child.parentBlockId || parent.status === FLOW_RUN_STATUS.completed || parent.status === FLOW_RUN_STATUS.failed) {
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
const step = await FlowStepRun
|
|
689
|
+
.where({
|
|
690
|
+
run: parent,
|
|
691
|
+
blockId: child.parentBlockId,
|
|
692
|
+
})
|
|
693
|
+
.firstOrFail();
|
|
694
|
+
|
|
695
|
+
if (step.status === FLOW_STEP_STATUS.completed) return;
|
|
696
|
+
|
|
697
|
+
const compiled = this.#compiler.compile(requiredDefinition(parent.definitionSnapshot));
|
|
698
|
+
const parentBlock = compiled.blocks.find(candidate => candidate.instance.id === child.parentBlockId);
|
|
699
|
+
|
|
700
|
+
if (!parentBlock) {
|
|
701
|
+
throw new Error(`Nested parent block "${child.parentBlockId}" does not exist in run "${parent.id}".`);
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
const output = validateFlowValues(
|
|
705
|
+
requiredValues(child.output, 'Completed nested run output is required.'),
|
|
706
|
+
parentBlock.block.outputs,
|
|
707
|
+
`block.${child.parentBlockId}.output`,
|
|
708
|
+
);
|
|
709
|
+
|
|
710
|
+
this.#assertPayloadSize(output, `Nested block ${child.parentBlockId} output`);
|
|
711
|
+
step.set('nestedRun', child);
|
|
712
|
+
step.status = FLOW_STEP_STATUS.completed;
|
|
713
|
+
step.output = output;
|
|
714
|
+
step.error = null;
|
|
715
|
+
step.completedAt = child.completedAt ?? new Date();
|
|
716
|
+
await step.save();
|
|
717
|
+
await this.#recordEvent(parent, step, FLOW_RUN_EVENT_TYPE.nestedCompleted, `${step.blockName} completed from ${child.flowName}.`, {
|
|
718
|
+
childRunId: requiredString(child.id, 'Nested flow run id is required.'),
|
|
719
|
+
});
|
|
720
|
+
await this.#recordEvent(parent, step, FLOW_RUN_EVENT_TYPE.stepCompleted, `${step.blockName} completed.`);
|
|
721
|
+
await this.#advanceCompletedStep(parent, step, compiled.blocks);
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
/**
|
|
725
|
+
* Propagates a terminal nested failure to its waiting parent run.
|
|
726
|
+
*
|
|
727
|
+
* @param child - Failed nested child run.
|
|
728
|
+
*/
|
|
729
|
+
async #failNestedParent(child: FlowRun): Promise<void> {
|
|
730
|
+
const parent = await child.parentRun?.load() ?? null;
|
|
731
|
+
|
|
732
|
+
if (!parent || !child.parentBlockId || parent.status === FLOW_RUN_STATUS.completed || parent.status === FLOW_RUN_STATUS.failed) {
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
const step = await FlowStepRun
|
|
737
|
+
.where({
|
|
738
|
+
run: parent,
|
|
739
|
+
blockId: child.parentBlockId,
|
|
740
|
+
})
|
|
741
|
+
.firstOrFail();
|
|
742
|
+
const error = child.error ?? flowErrorSnapshot(new Error(`Nested flow "${child.flowName}" failed.`));
|
|
743
|
+
const completedAt = child.completedAt ?? new Date();
|
|
744
|
+
|
|
745
|
+
step.set('nestedRun', child);
|
|
746
|
+
step.status = FLOW_STEP_STATUS.failed;
|
|
747
|
+
step.error = error;
|
|
748
|
+
step.completedAt = completedAt;
|
|
749
|
+
await step.save();
|
|
750
|
+
await this.#recordEvent(parent, step, FLOW_RUN_EVENT_TYPE.nestedFailed, `${step.blockName} failed with ${child.flowName}.`, {
|
|
751
|
+
childRunId: requiredString(child.id, 'Nested flow run id is required.'),
|
|
752
|
+
error: errorEventData(error),
|
|
753
|
+
});
|
|
754
|
+
await this.#recordEvent(parent, step, FLOW_RUN_EVENT_TYPE.stepFailed, `${step.blockName} failed.`, errorEventData(error));
|
|
755
|
+
parent.status = FLOW_RUN_STATUS.failed;
|
|
756
|
+
parent.error = error;
|
|
757
|
+
parent.completedAt = completedAt;
|
|
758
|
+
await parent.save();
|
|
759
|
+
await this.#recordEvent(parent, null, FLOW_RUN_EVENT_TYPE.runFailed, 'Run failed because a nested flow failed.', errorEventData(error));
|
|
760
|
+
await this.#failNestedParent(parent);
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
/**
|
|
764
|
+
* Assembles validated block input from run input or the predecessor output.
|
|
765
|
+
*
|
|
766
|
+
* @param run - Durable flow run containing public input and prior steps.
|
|
767
|
+
* @param compiledBlock - Block occurrence whose input should be assembled.
|
|
768
|
+
* @returns Validated named block input values.
|
|
769
|
+
*/
|
|
770
|
+
async #inputFor(run: FlowRun, compiledBlock: CompiledFlowBlock): Promise<FlowValues> {
|
|
771
|
+
if (compiledBlock.sequence === 0) {
|
|
772
|
+
return validateFlowValues(
|
|
773
|
+
requiredValues(run.input, 'Flow run input is required.'),
|
|
774
|
+
compiledBlock.block.inputs,
|
|
775
|
+
`block.${compiledBlock.instance.id}.input`,
|
|
776
|
+
);
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
const predecessor = await FlowStepRun
|
|
780
|
+
.where({
|
|
781
|
+
run,
|
|
782
|
+
sequence: compiledBlock.sequence - 1,
|
|
783
|
+
})
|
|
784
|
+
.firstOrFail();
|
|
785
|
+
const predecessorOutput = requiredValues(predecessor.output, `Predecessor step ${predecessor.id} has no output.`);
|
|
786
|
+
const values: FlowValues = {};
|
|
787
|
+
|
|
788
|
+
for (const connection of compiledBlock.incoming) {
|
|
789
|
+
const value = predecessorOutput[connection.sourcePort];
|
|
790
|
+
|
|
791
|
+
if (value !== undefined) {
|
|
792
|
+
values[connection.targetPort] = structuredClone(value);
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
return validateFlowValues(values, compiledBlock.block.inputs, `block.${compiledBlock.instance.id}.input`);
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
/**
|
|
800
|
+
* Completes a terminal run or dispatches the next pending step.
|
|
801
|
+
*
|
|
802
|
+
* @param run - Durable flow run being advanced.
|
|
803
|
+
* @param step - Completed block step.
|
|
804
|
+
* @param compiledBlocks - Complete sequential execution plan.
|
|
805
|
+
*/
|
|
806
|
+
async #advanceCompletedStep(
|
|
807
|
+
run: FlowRun,
|
|
808
|
+
step: FlowStepRun,
|
|
809
|
+
compiledBlocks: CompiledFlowBlock[],
|
|
810
|
+
): Promise<void> {
|
|
811
|
+
const nextBlock = compiledBlocks[Number(step.sequence) + 1];
|
|
812
|
+
|
|
813
|
+
if (nextBlock) {
|
|
814
|
+
const nextStep = await FlowStepRun
|
|
815
|
+
.where({
|
|
816
|
+
run,
|
|
817
|
+
blockId: nextBlock.instance.id,
|
|
818
|
+
})
|
|
819
|
+
.firstOrFail();
|
|
820
|
+
|
|
821
|
+
if (nextStep.status === FLOW_STEP_STATUS.pending) {
|
|
822
|
+
await this.#dispatchStep(run, nextStep);
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
if (run.status === FLOW_RUN_STATUS.completed) return;
|
|
829
|
+
|
|
830
|
+
const definition = requiredDefinition(run.definitionSnapshot);
|
|
831
|
+
const publicOutput = validateFlowValues(
|
|
832
|
+
requiredValues(step.output, 'Terminal step output is required.'),
|
|
833
|
+
definition.outputs,
|
|
834
|
+
'flow.output',
|
|
835
|
+
);
|
|
836
|
+
|
|
837
|
+
this.#assertPayloadSize(publicOutput, 'Flow output');
|
|
838
|
+
run.status = FLOW_RUN_STATUS.completed;
|
|
839
|
+
run.output = publicOutput;
|
|
840
|
+
run.error = null;
|
|
841
|
+
run.completedAt = new Date();
|
|
842
|
+
await run.save();
|
|
843
|
+
await this.#recordEvent(run, null, FLOW_RUN_EVENT_TYPE.runCompleted, 'Run completed.');
|
|
844
|
+
await this.#completeNestedParent(run);
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
/**
|
|
848
|
+
* Dispatches one pending step and records its queue identity.
|
|
849
|
+
*
|
|
850
|
+
* @param run - Flow run owning the pending step.
|
|
851
|
+
* @param step - Pending step to queue.
|
|
852
|
+
*/
|
|
853
|
+
async #dispatchStep(run: FlowRun, step: FlowStepRun): Promise<void> {
|
|
854
|
+
const jobId = await this.options.queue.dispatch(
|
|
855
|
+
new FlowStepJob({
|
|
856
|
+
runId: requiredString(run.id, 'Flow run id is required.'),
|
|
857
|
+
blockId: requiredString(step.blockId, 'Flow step blockId is required.'),
|
|
858
|
+
}),
|
|
859
|
+
{
|
|
860
|
+
queue: this.#queueName,
|
|
861
|
+
maxTries: this.#maxTries,
|
|
862
|
+
},
|
|
863
|
+
);
|
|
864
|
+
|
|
865
|
+
step.status = FLOW_STEP_STATUS.queued;
|
|
866
|
+
step.queueJobId = String(jobId);
|
|
867
|
+
await step.save();
|
|
868
|
+
await this.#recordEvent(run, step, FLOW_RUN_EVENT_TYPE.stepQueued, `${step.blockName} queued.`, {
|
|
869
|
+
queue: this.#queueName,
|
|
870
|
+
queueJobId: String(jobId),
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
/**
|
|
875
|
+
* Records retryable or terminal block failure state before rethrowing to Queue.
|
|
876
|
+
*
|
|
877
|
+
* @param run - Flow run owning the failed attempt.
|
|
878
|
+
* @param step - Step whose block function failed.
|
|
879
|
+
* @param queueJob - Claimed queue attempt metadata.
|
|
880
|
+
* @param error - Unknown block failure.
|
|
881
|
+
*/
|
|
882
|
+
async #recordStepFailure(
|
|
883
|
+
run: FlowRun,
|
|
884
|
+
step: FlowStepRun,
|
|
885
|
+
queueJob: QueueJob,
|
|
886
|
+
error: unknown,
|
|
887
|
+
): Promise<void> {
|
|
888
|
+
const snapshot = flowErrorSnapshot(error);
|
|
889
|
+
const terminal = queueJob.attempts >= queueJob.payload.maxTries;
|
|
890
|
+
|
|
891
|
+
step.attempt = queueJob.attempts;
|
|
892
|
+
step.error = snapshot;
|
|
893
|
+
step.status = terminal ? FLOW_STEP_STATUS.failed : FLOW_STEP_STATUS.queued;
|
|
894
|
+
step.completedAt = terminal ? new Date() : null;
|
|
895
|
+
await step.save();
|
|
896
|
+
|
|
897
|
+
if (!terminal) {
|
|
898
|
+
await this.#recordEvent(run, step, FLOW_RUN_EVENT_TYPE.stepRetrying, `${step.blockName} will retry.`, {
|
|
899
|
+
attempt: queueJob.attempts,
|
|
900
|
+
error: errorEventData(snapshot),
|
|
901
|
+
});
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
await this.#recordEvent(run, step, FLOW_RUN_EVENT_TYPE.stepFailed, `${step.blockName} failed.`, errorEventData(snapshot));
|
|
906
|
+
run.status = FLOW_RUN_STATUS.failed;
|
|
907
|
+
run.error = snapshot;
|
|
908
|
+
run.completedAt = new Date();
|
|
909
|
+
await run.save();
|
|
910
|
+
await this.#recordEvent(run, null, FLOW_RUN_EVENT_TYPE.runFailed, 'Run failed.', errorEventData(snapshot));
|
|
911
|
+
await this.#failNestedParent(run);
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
/**
|
|
915
|
+
* Marks a run failed when its first queue dispatch could not be persisted.
|
|
916
|
+
*
|
|
917
|
+
* @param run - Newly created flow run.
|
|
918
|
+
* @param step - Root step that could not be queued.
|
|
919
|
+
* @param error - Queue dispatch failure.
|
|
920
|
+
*/
|
|
921
|
+
async #failUndispatchedRun(run: FlowRun, step: FlowStepRun, error: unknown): Promise<void> {
|
|
922
|
+
const snapshot = flowErrorSnapshot(error);
|
|
923
|
+
const completedAt = new Date();
|
|
924
|
+
|
|
925
|
+
step.status = FLOW_STEP_STATUS.failed;
|
|
926
|
+
step.error = snapshot;
|
|
927
|
+
step.completedAt = completedAt;
|
|
928
|
+
await step.save();
|
|
929
|
+
run.status = FLOW_RUN_STATUS.failed;
|
|
930
|
+
run.error = snapshot;
|
|
931
|
+
run.completedAt = completedAt;
|
|
932
|
+
await run.save();
|
|
933
|
+
await this.#recordEvent(run, step, FLOW_RUN_EVENT_TYPE.stepFailed, `${step.blockName} could not be queued.`, errorEventData(snapshot));
|
|
934
|
+
await this.#recordEvent(run, null, FLOW_RUN_EVENT_TYPE.runFailed, 'Run could not be queued.', errorEventData(snapshot));
|
|
935
|
+
await this.#failNestedParent(run);
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
/**
|
|
939
|
+
* Writes one durable block-requested log event.
|
|
940
|
+
*
|
|
941
|
+
* @param run - Flow run receiving the log.
|
|
942
|
+
* @param step - Block step that requested the log.
|
|
943
|
+
* @param input - Structured log severity, message, and data.
|
|
944
|
+
*/
|
|
945
|
+
async #recordBlockLog(run: FlowRun, step: FlowStepRun, input: FlowBlockLogInput): Promise<void> {
|
|
946
|
+
if (input.data !== undefined) {
|
|
947
|
+
this.#assertPayloadSize(input.data, 'Flow log data');
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
await this.#recordEvent(
|
|
951
|
+
run,
|
|
952
|
+
step,
|
|
953
|
+
FLOW_RUN_EVENT_TYPE.stepLog,
|
|
954
|
+
input.message,
|
|
955
|
+
input.data,
|
|
956
|
+
input.level,
|
|
957
|
+
);
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
/**
|
|
961
|
+
* Appends one run-local ordered lifecycle or log event.
|
|
962
|
+
*
|
|
963
|
+
* @param run - Flow run receiving the event.
|
|
964
|
+
* @param step - Related block step, when applicable.
|
|
965
|
+
* @param type - Durable event type.
|
|
966
|
+
* @param message - Human-readable event message.
|
|
967
|
+
* @param data - Optional structured event data.
|
|
968
|
+
* @param level - Optional block log severity.
|
|
969
|
+
* @returns Persisted ordered event record.
|
|
970
|
+
*/
|
|
971
|
+
async #recordEvent(
|
|
972
|
+
run: FlowRun,
|
|
973
|
+
step: FlowStepRun | null,
|
|
974
|
+
type: FlowRunEvent['type'],
|
|
975
|
+
message: string,
|
|
976
|
+
data?: FlowValue,
|
|
977
|
+
level?: FlowRunEvent['level'],
|
|
978
|
+
): Promise<FlowRunEvent> {
|
|
979
|
+
const latest = await FlowRunEvent
|
|
980
|
+
.where('run', run)
|
|
981
|
+
.orderBy('sequence', 'desc')
|
|
982
|
+
.first();
|
|
983
|
+
const event = FlowRunEvent.create({
|
|
984
|
+
run,
|
|
985
|
+
stepRun: step,
|
|
986
|
+
sequence: (latest?.sequence ?? -1) + 1,
|
|
987
|
+
type,
|
|
988
|
+
level: level ?? null,
|
|
989
|
+
message: message.slice(0, 1024),
|
|
990
|
+
data: data ?? null,
|
|
991
|
+
});
|
|
992
|
+
|
|
993
|
+
await event.save();
|
|
994
|
+
|
|
995
|
+
return event;
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
/**
|
|
999
|
+
* Prevents oversized values from being copied into run history tables.
|
|
1000
|
+
*
|
|
1001
|
+
* @param value - JSON-safe value being persisted.
|
|
1002
|
+
* @param label - Boundary label included in limit errors.
|
|
1003
|
+
*/
|
|
1004
|
+
#assertPayloadSize(value: FlowValue | FlowValues, label: string): void {
|
|
1005
|
+
const size = Buffer.byteLength(JSON.stringify(value), 'utf8');
|
|
1006
|
+
|
|
1007
|
+
if (size > this.#maxPayloadBytes) {
|
|
1008
|
+
throw new Error(`${label} exceeds the ${this.#maxPayloadBytes} byte flow capture limit.`);
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
/**
|
|
1014
|
+
* Returns a required non-empty string or throws a developer-facing error.
|
|
1015
|
+
*
|
|
1016
|
+
* @param value - Nullable candidate string.
|
|
1017
|
+
* @param message - Error message used when the value is absent.
|
|
1018
|
+
* @returns Required non-empty string.
|
|
1019
|
+
*/
|
|
1020
|
+
function requiredString(value: string | null | undefined, message: string): string {
|
|
1021
|
+
if (!value) throw new Error(message);
|
|
1022
|
+
|
|
1023
|
+
return value;
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
/**
|
|
1027
|
+
* Returns a required definition snapshot or throws a developer-facing error.
|
|
1028
|
+
*
|
|
1029
|
+
* @param value - Nullable definition snapshot.
|
|
1030
|
+
* @returns Required flow definition.
|
|
1031
|
+
*/
|
|
1032
|
+
function requiredDefinition(value: FlowExecutionDefinition | null | undefined): FlowExecutionDefinition {
|
|
1033
|
+
if (!value) throw new Error('Flow run definition snapshot is required.');
|
|
1034
|
+
|
|
1035
|
+
return value;
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
/**
|
|
1039
|
+
* Creates the pass-through contract used by a visible flow boundary block.
|
|
1040
|
+
*
|
|
1041
|
+
* @param definitions - Public input or output contract owned by the flow.
|
|
1042
|
+
* @returns Independent input and output copies for the resolved block.
|
|
1043
|
+
*/
|
|
1044
|
+
function boundaryContract(definitions: FlowValueDefinitions): FlowResolvedBlockContract {
|
|
1045
|
+
return {
|
|
1046
|
+
inputs: structuredClone(definitions),
|
|
1047
|
+
outputs: structuredClone(definitions),
|
|
1048
|
+
};
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
/**
|
|
1052
|
+
* Detects a durable execution snapshot without trusting partial source objects.
|
|
1053
|
+
*
|
|
1054
|
+
* @param definition - Source or execution definition candidate.
|
|
1055
|
+
* @returns True when runtime resolution maps are present.
|
|
1056
|
+
*/
|
|
1057
|
+
function isExecutionDefinition(definition: FlowDefinition): definition is FlowExecutionDefinition {
|
|
1058
|
+
return 'resolvedBlocks' in definition
|
|
1059
|
+
&& typeof definition.resolvedBlocks === 'object'
|
|
1060
|
+
&& 'nestedDefinitions' in definition
|
|
1061
|
+
&& typeof definition.nestedDefinitions === 'object';
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
/**
|
|
1065
|
+
* Returns required named flow values or throws a developer-facing error.
|
|
1066
|
+
*
|
|
1067
|
+
* @param value - Nullable named values.
|
|
1068
|
+
* @param message - Error message used when values are absent.
|
|
1069
|
+
* @returns Required named flow values.
|
|
1070
|
+
*/
|
|
1071
|
+
function requiredValues(value: FlowValues | null | undefined, message: string): FlowValues {
|
|
1072
|
+
if (!value) throw new Error(message);
|
|
1073
|
+
|
|
1074
|
+
return value;
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
/**
|
|
1078
|
+
* Ensures a flow-backed block exposes the same named boundary as its child flow.
|
|
1079
|
+
*
|
|
1080
|
+
* @param blockContract - Contract declared by the registered flow-backed block.
|
|
1081
|
+
* @param flowContract - Public contract declared by the nested flow definition.
|
|
1082
|
+
* @param label - Boundary label included in mismatch errors.
|
|
1083
|
+
*/
|
|
1084
|
+
function assertMatchingContracts(
|
|
1085
|
+
blockContract: FlowValueDefinitions,
|
|
1086
|
+
flowContract: FlowValueDefinitions,
|
|
1087
|
+
label: string,
|
|
1088
|
+
): void {
|
|
1089
|
+
const blockNames = Object.keys(blockContract).sort();
|
|
1090
|
+
const flowNames = Object.keys(flowContract).sort();
|
|
1091
|
+
|
|
1092
|
+
if (JSON.stringify(blockNames) !== JSON.stringify(flowNames)) {
|
|
1093
|
+
throw new Error(`${label} must match the flow-backed block ports.`);
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
for (const name of blockNames) {
|
|
1097
|
+
const blockValue = blockContract[name];
|
|
1098
|
+
const flowValue = flowContract[name];
|
|
1099
|
+
|
|
1100
|
+
if (!blockValue || !flowValue || blockValue.type !== flowValue.type || Boolean(blockValue.required) !== Boolean(flowValue.required)) {
|
|
1101
|
+
throw new Error(`${label} port "${name}" must use the same type and required setting as the flow-backed block.`);
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
/**
|
|
1107
|
+
* Converts a typed error snapshot into a recursive flow JSON object.
|
|
1108
|
+
*
|
|
1109
|
+
* @param snapshot - Structured error captured by the flow runtime.
|
|
1110
|
+
* @returns JSON-safe error event data.
|
|
1111
|
+
*/
|
|
1112
|
+
function errorEventData(snapshot: ReturnType<typeof flowErrorSnapshot>): FlowValues {
|
|
1113
|
+
return {
|
|
1114
|
+
name: snapshot.name,
|
|
1115
|
+
message: snapshot.message,
|
|
1116
|
+
stack: snapshot.stack ?? null,
|
|
1117
|
+
};
|
|
1118
|
+
}
|