@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,108 @@
|
|
|
1
|
+
import { AI_PROVIDER } from './contracts/AI.js';
|
|
2
|
+
const USD_COST_PRECISION = 100_000_000;
|
|
3
|
+
const XAI_USD_TICKS_PER_DOLLAR = 10_000_000_000;
|
|
4
|
+
/**
|
|
5
|
+
* Extracts the authoritative billed USD cost from one provider payload.
|
|
6
|
+
*
|
|
7
|
+
* OpenRouter returns dollars in `usage.cost`. xAI returns integer USD ticks in
|
|
8
|
+
* `usage.cost_in_usd_ticks`, where ten billion ticks equal one US dollar.
|
|
9
|
+
* Other providers intentionally return null so locally estimated prices cannot
|
|
10
|
+
* be mistaken for the amount actually charged by an intermediary.
|
|
11
|
+
*
|
|
12
|
+
* @param provider - Provider that returned the payload.
|
|
13
|
+
* @param payload - Response object containing the provider usage block.
|
|
14
|
+
* @returns Provider-reported billed cost in USD, or null when unavailable.
|
|
15
|
+
*/
|
|
16
|
+
export function providerReportedCostUSD(provider, payload) {
|
|
17
|
+
const usage = recordValue(recordValue(payload)?.usage);
|
|
18
|
+
if (!usage)
|
|
19
|
+
return null;
|
|
20
|
+
if (provider === AI_PROVIDER.openrouter) {
|
|
21
|
+
return validNonNegativeNumber(usage.cost);
|
|
22
|
+
}
|
|
23
|
+
if (provider === AI_PROVIDER.xai) {
|
|
24
|
+
const ticks = validNonNegativeNumber(usage.cost_in_usd_ticks);
|
|
25
|
+
return ticks === null ? null : roundCostUSD(ticks / XAI_USD_TICKS_PER_DOLLAR);
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Builds a deduplicatable cost entry for one terminal provider response.
|
|
31
|
+
*
|
|
32
|
+
* @param provider - Provider that returned the response.
|
|
33
|
+
* @param payload - Response object containing provider usage.
|
|
34
|
+
* @param responseId - Stable provider response identifier.
|
|
35
|
+
* @returns Captured provider cost, or null when the id or billed cost is absent.
|
|
36
|
+
*/
|
|
37
|
+
export function providerReportedCost(provider, payload, responseId) {
|
|
38
|
+
if (typeof responseId !== 'string' || !responseId.trim())
|
|
39
|
+
return null;
|
|
40
|
+
const costUSD = providerReportedCostUSD(provider, payload);
|
|
41
|
+
if (costUSD === null)
|
|
42
|
+
return null;
|
|
43
|
+
return {
|
|
44
|
+
responseId,
|
|
45
|
+
costUSD,
|
|
46
|
+
source: provider === AI_PROVIDER.xai
|
|
47
|
+
? 'xai_usage_cost_in_usd_ticks'
|
|
48
|
+
: 'openrouter_usage_cost',
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Summarizes unique provider costs and fails closed when coverage is incomplete.
|
|
53
|
+
*
|
|
54
|
+
* @param costs - Cost entries keyed by provider response id.
|
|
55
|
+
* @param expectedRequestCount - Provider request count reported by the SDK.
|
|
56
|
+
* @returns Known subtotal plus an exact total only when every request is covered.
|
|
57
|
+
*/
|
|
58
|
+
export function summarizeProviderReportedCosts(costs, expectedRequestCount) {
|
|
59
|
+
const entries = [...costs.values()];
|
|
60
|
+
const knownCostUSD = roundCostUSD(entries.reduce((total, entry) => total + entry.costUSD, 0));
|
|
61
|
+
const normalizedExpectedCount = Number.isFinite(expectedRequestCount) && expectedRequestCount >= 0
|
|
62
|
+
? Math.trunc(expectedRequestCount)
|
|
63
|
+
: 0;
|
|
64
|
+
const complete = normalizedExpectedCount > 0 && entries.length === normalizedExpectedCount;
|
|
65
|
+
return {
|
|
66
|
+
knownCostUSD,
|
|
67
|
+
costUSD: complete ? knownCostUSD : null,
|
|
68
|
+
reportedRequestCount: entries.length,
|
|
69
|
+
expectedRequestCount: normalizedExpectedCount,
|
|
70
|
+
sources: [...new Set(entries.map(entry => entry.source))],
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Converts a provider numeric field into a safe non-negative number.
|
|
75
|
+
*
|
|
76
|
+
* @param value - Unknown numeric value from a provider response.
|
|
77
|
+
* @returns Rounded numeric value, or null when missing, negative, or invalid.
|
|
78
|
+
*/
|
|
79
|
+
function validNonNegativeNumber(value) {
|
|
80
|
+
const parsed = typeof value === 'number'
|
|
81
|
+
? value
|
|
82
|
+
: typeof value === 'string' && value.trim()
|
|
83
|
+
? Number(value)
|
|
84
|
+
: null;
|
|
85
|
+
if (parsed === null || !Number.isFinite(parsed) || parsed < 0)
|
|
86
|
+
return null;
|
|
87
|
+
return roundCostUSD(parsed);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Narrows an unknown value to a plain record.
|
|
91
|
+
*
|
|
92
|
+
* @param value - Unknown provider payload value.
|
|
93
|
+
* @returns Record value, or null for scalars and arrays.
|
|
94
|
+
*/
|
|
95
|
+
function recordValue(value) {
|
|
96
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
97
|
+
return null;
|
|
98
|
+
return value;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Rounds provider billed cost to the precision stored on AiRequest.
|
|
102
|
+
*
|
|
103
|
+
* @param value - USD cost before persistence rounding.
|
|
104
|
+
* @returns Cost rounded to eight decimal places.
|
|
105
|
+
*/
|
|
106
|
+
function roundCostUSD(value) {
|
|
107
|
+
return Math.round(value * USD_COST_PRECISION) / USD_COST_PRECISION;
|
|
108
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ResponsesProviderCallInput, ResponsesProviderCallResult } from './contracts/ResponsesProviderCall.js';
|
|
2
|
+
export type { ResponsesProviderCallInput, ResponsesProviderCallResult } from './contracts/ResponsesProviderCall.js';
|
|
3
|
+
/**
|
|
4
|
+
* Sends one Responses API request to an OpenAI-compatible provider.
|
|
5
|
+
*
|
|
6
|
+
* This is pure transport: it performs the HTTP call and parses the payload and
|
|
7
|
+
* headers. Tracking, rate limiting, failover policy, and error shaping stay in
|
|
8
|
+
* the AI service so every attempt in a failover chain shares one lifecycle.
|
|
9
|
+
*
|
|
10
|
+
* @param input - Provider connection, request payload, and fetch implementation.
|
|
11
|
+
* @returns Raw provider response for the caller to classify.
|
|
12
|
+
*/
|
|
13
|
+
export declare function sendResponsesRequest(input: ResponsesProviderCallInput): Promise<ResponsesProviderCallResult>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { providerResponseMetadata } from './AIRateLimiter.js';
|
|
2
|
+
/**
|
|
3
|
+
* Sends one Responses API request to an OpenAI-compatible provider.
|
|
4
|
+
*
|
|
5
|
+
* This is pure transport: it performs the HTTP call and parses the payload and
|
|
6
|
+
* headers. Tracking, rate limiting, failover policy, and error shaping stay in
|
|
7
|
+
* the AI service so every attempt in a failover chain shares one lifecycle.
|
|
8
|
+
*
|
|
9
|
+
* @param input - Provider connection, request payload, and fetch implementation.
|
|
10
|
+
* @returns Raw provider response for the caller to classify.
|
|
11
|
+
*/
|
|
12
|
+
export async function sendResponsesRequest(input) {
|
|
13
|
+
const response = await input.fetcher(`${input.baseUrl}/responses`, {
|
|
14
|
+
method: 'POST',
|
|
15
|
+
headers: {
|
|
16
|
+
authorization: `Bearer ${input.apiKey}`,
|
|
17
|
+
'content-type': 'application/json',
|
|
18
|
+
},
|
|
19
|
+
body: JSON.stringify(input.request),
|
|
20
|
+
});
|
|
21
|
+
const metadata = providerResponseMetadata(response.headers);
|
|
22
|
+
const payload = await response.json().catch(() => null);
|
|
23
|
+
return {
|
|
24
|
+
ok: response.ok,
|
|
25
|
+
status: response.status,
|
|
26
|
+
payload,
|
|
27
|
+
metadata,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type AgentCitation } from '@db3.ai/pure';
|
|
2
|
+
/**
|
|
3
|
+
* Extracts a normalized URL citation from a Responses streaming annotation.
|
|
4
|
+
*
|
|
5
|
+
* @param record - Raw `response.output_text.annotation.added` event.
|
|
6
|
+
* @returns Valid URL citation, or null for unsupported annotations.
|
|
7
|
+
*/
|
|
8
|
+
export declare function agentCitationFromStreamRecord(record: Record<string, unknown>): AgentCitation | null;
|
|
9
|
+
/**
|
|
10
|
+
* Extracts URL citations from the final Agents SDK model response.
|
|
11
|
+
*
|
|
12
|
+
* A null result means the provider did not expose an authoritative annotation
|
|
13
|
+
* collection, so callers may fall back to citations observed in stream events.
|
|
14
|
+
* An empty array is authoritative and means the final response had no citations.
|
|
15
|
+
*
|
|
16
|
+
* @param rawResponses - Agents SDK model responses generated by the run.
|
|
17
|
+
* @returns Final normalized citations, or null when annotations are unavailable.
|
|
18
|
+
*/
|
|
19
|
+
export declare function agentCitationsFromFinalModelResponse(rawResponses: unknown): AgentCitation[] | null;
|
|
20
|
+
/**
|
|
21
|
+
* Adds a citation to an in-memory collection when its occurrence is new.
|
|
22
|
+
*
|
|
23
|
+
* @param citations - Mutable citations collected for the current attempt.
|
|
24
|
+
* @param citation - Citation occurrence to remember.
|
|
25
|
+
* @returns True when the citation was added.
|
|
26
|
+
*/
|
|
27
|
+
export declare function rememberAgentCitation(citations: AgentCitation[], citation: AgentCitation): boolean;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { agentCitationOccurrenceKey, normalizedAgentCitations } from '@db3.ai/pure';
|
|
2
|
+
/**
|
|
3
|
+
* Extracts a normalized URL citation from a Responses streaming annotation.
|
|
4
|
+
*
|
|
5
|
+
* @param record - Raw `response.output_text.annotation.added` event.
|
|
6
|
+
* @returns Valid URL citation, or null for unsupported annotations.
|
|
7
|
+
*/
|
|
8
|
+
export function agentCitationFromStreamRecord(record) {
|
|
9
|
+
if (record.type !== 'response.output_text.annotation.added')
|
|
10
|
+
return null;
|
|
11
|
+
const annotation = recordValue(record.annotation);
|
|
12
|
+
const itemId = stringValue(record.item_id) || stringValue(record.itemId);
|
|
13
|
+
const annotationIndex = integerValue(record.annotation_index) ?? integerValue(record.annotationIndex);
|
|
14
|
+
const contentIndex = integerValue(record.content_index) ?? integerValue(record.contentIndex) ?? 0;
|
|
15
|
+
return providerUrlCitation(annotation, {
|
|
16
|
+
id: citationId(itemId, contentIndex, annotationIndex),
|
|
17
|
+
offset: contentIndex === 0 ? 0 : null,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Extracts URL citations from the final Agents SDK model response.
|
|
22
|
+
*
|
|
23
|
+
* A null result means the provider did not expose an authoritative annotation
|
|
24
|
+
* collection, so callers may fall back to citations observed in stream events.
|
|
25
|
+
* An empty array is authoritative and means the final response had no citations.
|
|
26
|
+
*
|
|
27
|
+
* @param rawResponses - Agents SDK model responses generated by the run.
|
|
28
|
+
* @returns Final normalized citations, or null when annotations are unavailable.
|
|
29
|
+
*/
|
|
30
|
+
export function agentCitationsFromFinalModelResponse(rawResponses) {
|
|
31
|
+
if (!Array.isArray(rawResponses) || rawResponses.length === 0)
|
|
32
|
+
return null;
|
|
33
|
+
const response = recordValue(rawResponses.at(-1));
|
|
34
|
+
const output = Array.isArray(response?.output) ? response.output : null;
|
|
35
|
+
if (!output || output.length === 0)
|
|
36
|
+
return null;
|
|
37
|
+
const message = recordValue(output.at(-1));
|
|
38
|
+
if (!message)
|
|
39
|
+
return null;
|
|
40
|
+
const content = message.type === 'message' && Array.isArray(message.content)
|
|
41
|
+
? message.content
|
|
42
|
+
: null;
|
|
43
|
+
if (!content)
|
|
44
|
+
return null;
|
|
45
|
+
const messageId = stringValue(message.id);
|
|
46
|
+
const citations = [];
|
|
47
|
+
let textOffset = 0;
|
|
48
|
+
let hasAnnotationCollection = false;
|
|
49
|
+
for (let contentIndex = 0; contentIndex < content.length; contentIndex += 1) {
|
|
50
|
+
const part = recordValue(content[contentIndex]);
|
|
51
|
+
if (part?.type !== 'output_text')
|
|
52
|
+
continue;
|
|
53
|
+
const providerData = recordValue(part.providerData);
|
|
54
|
+
const annotations = Array.isArray(providerData?.annotations)
|
|
55
|
+
? providerData.annotations
|
|
56
|
+
: Array.isArray(part.annotations)
|
|
57
|
+
? part.annotations
|
|
58
|
+
: null;
|
|
59
|
+
if (annotations) {
|
|
60
|
+
hasAnnotationCollection = true;
|
|
61
|
+
for (let annotationIndex = 0; annotationIndex < annotations.length; annotationIndex += 1) {
|
|
62
|
+
const citation = providerUrlCitation(recordValue(annotations[annotationIndex]), {
|
|
63
|
+
id: citationId(messageId, contentIndex, annotationIndex),
|
|
64
|
+
offset: textOffset,
|
|
65
|
+
});
|
|
66
|
+
if (citation)
|
|
67
|
+
citations.push(citation);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
textOffset += stringValue(part.text)?.length ?? 0;
|
|
71
|
+
}
|
|
72
|
+
return hasAnnotationCollection ? normalizedAgentCitations(citations) : null;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Adds a citation to an in-memory collection when its occurrence is new.
|
|
76
|
+
*
|
|
77
|
+
* @param citations - Mutable citations collected for the current attempt.
|
|
78
|
+
* @param citation - Citation occurrence to remember.
|
|
79
|
+
* @returns True when the citation was added.
|
|
80
|
+
*/
|
|
81
|
+
export function rememberAgentCitation(citations, citation) {
|
|
82
|
+
const key = agentCitationOccurrenceKey(citation);
|
|
83
|
+
if (citations.some(existing => agentCitationOccurrenceKey(existing) === key))
|
|
84
|
+
return false;
|
|
85
|
+
citations.push(citation);
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Converts a provider URL annotation into application's public citation contract.
|
|
90
|
+
*
|
|
91
|
+
* @param annotation - Raw provider annotation object.
|
|
92
|
+
* @param context - Stable id and complete-message character offset.
|
|
93
|
+
* @returns Valid normalized citation, or null when required data is absent.
|
|
94
|
+
*/
|
|
95
|
+
function providerUrlCitation(annotation, context) {
|
|
96
|
+
if (!annotation || annotation.type !== 'url_citation' || context.offset === null)
|
|
97
|
+
return null;
|
|
98
|
+
const startIndex = integerValue(annotation.start_index) ?? integerValue(annotation.startIndex);
|
|
99
|
+
const endIndex = integerValue(annotation.end_index) ?? integerValue(annotation.endIndex);
|
|
100
|
+
const title = stringValue(annotation.title)?.trim();
|
|
101
|
+
const url = stringValue(annotation.url)?.trim();
|
|
102
|
+
if (startIndex === null || endIndex === null || !title || !url)
|
|
103
|
+
return null;
|
|
104
|
+
const citations = normalizedAgentCitations([{
|
|
105
|
+
id: context.id,
|
|
106
|
+
type: 'url',
|
|
107
|
+
title,
|
|
108
|
+
url,
|
|
109
|
+
startIndex: context.offset + startIndex,
|
|
110
|
+
endIndex: context.offset + endIndex,
|
|
111
|
+
}]);
|
|
112
|
+
return citations[0] ?? null;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Builds a stable id for one provider citation occurrence.
|
|
116
|
+
*
|
|
117
|
+
* @param itemId - Provider output message id when available.
|
|
118
|
+
* @param contentIndex - Output-text part index within the message.
|
|
119
|
+
* @param annotationIndex - Annotation index within the output-text part.
|
|
120
|
+
* @returns Stable citation id for streaming and restored UI state.
|
|
121
|
+
*/
|
|
122
|
+
function citationId(itemId, contentIndex, annotationIndex) {
|
|
123
|
+
return `${itemId || 'output'}:${contentIndex}:${annotationIndex ?? 0}`;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Narrows an unknown JSON value to a non-array record.
|
|
127
|
+
*
|
|
128
|
+
* @param value - Unknown provider value.
|
|
129
|
+
* @returns Object record, or null for primitives and arrays.
|
|
130
|
+
*/
|
|
131
|
+
function recordValue(value) {
|
|
132
|
+
return value && typeof value === 'object' && !Array.isArray(value)
|
|
133
|
+
? value
|
|
134
|
+
: null;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Reads a non-empty string from an unknown provider value.
|
|
138
|
+
*
|
|
139
|
+
* @param value - Unknown provider value.
|
|
140
|
+
* @returns String value, or null when absent.
|
|
141
|
+
*/
|
|
142
|
+
function stringValue(value) {
|
|
143
|
+
return typeof value === 'string' && value ? value : null;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Reads a non-negative integer from an unknown provider value.
|
|
147
|
+
*
|
|
148
|
+
* @param value - Unknown provider index value.
|
|
149
|
+
* @returns Non-negative integer, or null when invalid.
|
|
150
|
+
*/
|
|
151
|
+
function integerValue(value) {
|
|
152
|
+
return typeof value === 'number' && Number.isInteger(value) && value >= 0 ? value : null;
|
|
153
|
+
}
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
import type { TextResponsePayload } from '@db3.ai/pure';
|
|
2
|
+
import type { ZodType } from 'zod';
|
|
3
|
+
import type { AiConversation } from '../AiConversation.js';
|
|
4
|
+
import type { AiRequest } from '../AiRequest.js';
|
|
5
|
+
import type { AiRateLimitEndpoint } from '../AiRateLimitBucket.js';
|
|
6
|
+
import type { AIRateLimiter } from '../AIRateLimiter.js';
|
|
7
|
+
/**
|
|
8
|
+
* Provider identifiers stored with AI requests and conversation messages.
|
|
9
|
+
*
|
|
10
|
+
* Every provider must expose an OpenAI-compatible API. Keep these values stable
|
|
11
|
+
* because they are persisted in tracking tables and rate-limit bucket keys.
|
|
12
|
+
*/
|
|
13
|
+
export declare const AI_PROVIDER: {
|
|
14
|
+
readonly openai: "openai";
|
|
15
|
+
readonly openrouter: "openrouter";
|
|
16
|
+
readonly groq: "groq";
|
|
17
|
+
readonly xai: "xai";
|
|
18
|
+
readonly deepseek: "deepseek";
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Supported AI provider id.
|
|
22
|
+
*/
|
|
23
|
+
export type AIProvider = typeof AI_PROVIDER[keyof typeof AI_PROVIDER];
|
|
24
|
+
/**
|
|
25
|
+
* Application-owned AI model configuration.
|
|
26
|
+
*
|
|
27
|
+
* `model` is the global fallback. Additional keys are stable runtime names,
|
|
28
|
+
* such as concrete agent class names, resolved through `AI.config(...)`.
|
|
29
|
+
*/
|
|
30
|
+
export interface AIConfig {
|
|
31
|
+
/** Global model used when a call or agent does not select its own model. */
|
|
32
|
+
model: string;
|
|
33
|
+
/** Named model override or the required global model. */
|
|
34
|
+
[name: string]: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Ordered provider selection for a call, an agent, or the app default.
|
|
38
|
+
*
|
|
39
|
+
* A single provider keeps normal single-provider behavior. An ordered list
|
|
40
|
+
* fails over to the next provider using each provider's default model. An
|
|
41
|
+
* ordered record pins a model per provider and preserves insertion order:
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* provider: [AI_PROVIDER.openai, AI_PROVIDER.openrouter]
|
|
45
|
+
* provider: {
|
|
46
|
+
* [AI_PROVIDER.openai]: 'gpt-5.4-mini',
|
|
47
|
+
* [AI_PROVIDER.openrouter]: 'comparable-mini-model',
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export type AIProviderSelection = AIProvider | AIProvider[] | Partial<Record<AIProvider, string>>;
|
|
52
|
+
/** Explicit application credit charge attached to one AI provider operation. */
|
|
53
|
+
export interface AIUsageCharge {
|
|
54
|
+
/** Independent credit bucket selected by the feature starting the operation. */
|
|
55
|
+
bucket: string;
|
|
56
|
+
/** Positive whole-credit amount consumed before provider work begins. */
|
|
57
|
+
credits: number;
|
|
58
|
+
/**
|
|
59
|
+
* Optional caller-owned key for one logical usage charge.
|
|
60
|
+
*
|
|
61
|
+
* Supply this when queue retries or other re-executions can create more than
|
|
62
|
+
* one tracked AI request for the same billable operation. When omitted, the
|
|
63
|
+
* allowance adapter derives its key from the tracked AI request.
|
|
64
|
+
*/
|
|
65
|
+
idempotencyKey?: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Context passed to an application-owned customer allowance hook.
|
|
69
|
+
*
|
|
70
|
+
* This hook is separate from provider rate limits. Provider limits answer "can
|
|
71
|
+
* this API key call OpenAI right now"; allowance checks answer "is this user,
|
|
72
|
+
* scope, team, or customer allowed to spend more application AI budget".
|
|
73
|
+
*/
|
|
74
|
+
export interface AIAllowanceCheckInput {
|
|
75
|
+
/** Provider that will receive the request. */
|
|
76
|
+
provider: AIProvider;
|
|
77
|
+
/** Provider endpoint family, such as responses or embeddings. */
|
|
78
|
+
endpoint: AiRateLimitEndpoint;
|
|
79
|
+
/** Provider model or shared limit key used by the request. */
|
|
80
|
+
model: string;
|
|
81
|
+
/** Logical app operation, such as responses.create or agents.run.stream. */
|
|
82
|
+
operation: string;
|
|
83
|
+
/** User record or id associated with this request. */
|
|
84
|
+
user?: AIRecordIdentity | string | null;
|
|
85
|
+
/** Scope record or id associated with this request. */
|
|
86
|
+
scope?: AIRecordIdentity | string | null;
|
|
87
|
+
/** Pending tracked request row, when one has already been created. */
|
|
88
|
+
aiRequest?: AiRequest | null;
|
|
89
|
+
/** Estimated token cost used for pre-flight decisions. */
|
|
90
|
+
estimatedTokens?: number | null;
|
|
91
|
+
/** Explicit app credit charge, or null for unmetered and separately funded work. */
|
|
92
|
+
usage?: AIUsageCharge | null;
|
|
93
|
+
/** Extra operation metadata for policy decisions and audit messages. */
|
|
94
|
+
metadata?: Record<string, unknown> | null;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Application-defined allowance checker.
|
|
98
|
+
*
|
|
99
|
+
* Throw an app-level error from this hook to stop a request before provider
|
|
100
|
+
* capacity is reserved or external work starts.
|
|
101
|
+
*/
|
|
102
|
+
export type AIAllowanceChecker = (input: AIAllowanceCheckInput) => void | Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Runtime configuration for the AI service.
|
|
105
|
+
*
|
|
106
|
+
* Values supplied here override environment variables, which makes the service
|
|
107
|
+
* easy to test with a fake fetch implementation or alternate API endpoint.
|
|
108
|
+
*/
|
|
109
|
+
export interface AIOptions {
|
|
110
|
+
/** Maximum duration of each provider HTTP request, including SDK model turns. */
|
|
111
|
+
timeoutMs?: number;
|
|
112
|
+
/** Persisted logical scope field. Apps may map this to an existing domain field. */
|
|
113
|
+
scopeField?: string;
|
|
114
|
+
/** Model subclasses registered by the application migration workflow. */
|
|
115
|
+
models?: Partial<AIModels>;
|
|
116
|
+
/** OpenAI API key. Falls back to OPENAI_API_KEY when omitted. */
|
|
117
|
+
apiKey?: string;
|
|
118
|
+
/** Base API URL without the /responses suffix. Falls back to OPENAI_BASE_URL. */
|
|
119
|
+
baseUrl?: string;
|
|
120
|
+
/** Model name to use instead of the application config default. */
|
|
121
|
+
model?: string;
|
|
122
|
+
/** Default provider failover chain. Falls back to AI_PROVIDER_CHAIN, then OpenAI only. */
|
|
123
|
+
provider?: AIProviderSelection;
|
|
124
|
+
/** Fetch implementation used to send requests. Defaults to global fetch. */
|
|
125
|
+
fetch?: typeof fetch;
|
|
126
|
+
/** Rate limiter used before provider requests. Pass false only in isolated tests. */
|
|
127
|
+
rateLimiter?: AIRateLimiter | false;
|
|
128
|
+
/** Optional customer allowance hook. Defaults to no-op until billing limits exist. */
|
|
129
|
+
allowance?: AIAllowanceChecker | false;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Plain text request sent to the Responses API.
|
|
133
|
+
*/
|
|
134
|
+
export interface GenerateTextInput {
|
|
135
|
+
/** Optional per-call model override for the OpenAI provider entry. */
|
|
136
|
+
model?: string;
|
|
137
|
+
/** Optional provider failover chain overriding the app default for this call. */
|
|
138
|
+
provider?: AIProviderSelection;
|
|
139
|
+
/** System-level instructions that define the assistant's task and constraints. */
|
|
140
|
+
instructions: string;
|
|
141
|
+
/** User-level prompt or context for the request. */
|
|
142
|
+
input: string;
|
|
143
|
+
/** Optional maximum response tokens sent as max_output_tokens. */
|
|
144
|
+
maxOutputTokens?: number;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Text generation result with optional database tracking identifiers.
|
|
148
|
+
*/
|
|
149
|
+
export interface GenerateTextResult {
|
|
150
|
+
/** Extracted assistant text from the Responses API payload. */
|
|
151
|
+
text: string;
|
|
152
|
+
/** Saved AiRequest id when response logging is enabled; otherwise null. */
|
|
153
|
+
aiRequestId: string | null;
|
|
154
|
+
/** Saved response id. Currently mirrors aiRequestId because responses live on AiRequest. */
|
|
155
|
+
aiResponseId: string | null;
|
|
156
|
+
/** Conversation id used for tracked request and message rows; otherwise null. */
|
|
157
|
+
conversationId: string | null;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Embedding generation result with optional database tracking identifier.
|
|
161
|
+
*/
|
|
162
|
+
export interface GenerateEmbeddingResult {
|
|
163
|
+
/** Embedding vector returned by the provider. */
|
|
164
|
+
vector: number[];
|
|
165
|
+
/** Embedding model used for the request. */
|
|
166
|
+
model: string;
|
|
167
|
+
/** Saved AiRequest id when response logging is enabled; otherwise null. */
|
|
168
|
+
aiRequestId: string | null;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Structured generation request that asks the provider to return JSON matching
|
|
172
|
+
* a Zod schema and validates the parsed result before returning it.
|
|
173
|
+
*/
|
|
174
|
+
export interface GenerateStructuredInput<TValue> extends GenerateTextInput {
|
|
175
|
+
/** Schema used both for provider response formatting and local validation. */
|
|
176
|
+
schema: ZodType<TValue>;
|
|
177
|
+
/** Stable schema name sent to OpenAI and stored in request metadata. */
|
|
178
|
+
schemaName: string;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Optional metadata that controls how AI requests are attached to application
|
|
182
|
+
* records when response logging is enabled.
|
|
183
|
+
*/
|
|
184
|
+
export interface AIResponseLogOptions extends Record<string, unknown> {
|
|
185
|
+
/** User record or id to associate with the request. Defaults to the active user. */
|
|
186
|
+
user?: AIRecordIdentity | string | null;
|
|
187
|
+
/** Scope record or id to associate with the request. */
|
|
188
|
+
scope?: AIRecordIdentity | string | null;
|
|
189
|
+
/** Existing conversation record or id to append to. Creates a new conversation when omitted. */
|
|
190
|
+
conversation?: AiConversation | string | null;
|
|
191
|
+
/** Immediate parent AI request that caused this nested provider request. */
|
|
192
|
+
parentAiRequest?: AiRequest | string | null;
|
|
193
|
+
/** Logical feature or agent name shown on the conversation/request. */
|
|
194
|
+
agent?: string | null;
|
|
195
|
+
/** Human-readable conversation title when a new conversation is created. */
|
|
196
|
+
title?: string | null;
|
|
197
|
+
/** Extra JSON metadata copied to the conversation, request, and message rows. */
|
|
198
|
+
metadata?: Record<string, unknown> | null;
|
|
199
|
+
/** Explicit app credit charge checked before provider work begins. */
|
|
200
|
+
usage?: AIUsageCharge | null;
|
|
201
|
+
/** Set to false to opt out of saving request, response, and message rows. */
|
|
202
|
+
saveAiResponse?: boolean;
|
|
203
|
+
}
|
|
204
|
+
/** Untrusted provider text response, including optional token usage. */
|
|
205
|
+
export interface TextResponsePayloadWithUsage extends TextResponsePayload {
|
|
206
|
+
/** Provider completion status; omitted by some compatible endpoints. */
|
|
207
|
+
status?: unknown;
|
|
208
|
+
usage?: unknown;
|
|
209
|
+
}
|
|
210
|
+
/** Untrusted embedding response validated by the AI service before it is returned. */
|
|
211
|
+
export interface EmbeddingResponsePayloadWithUsage {
|
|
212
|
+
data?: Array<{
|
|
213
|
+
embedding?: unknown;
|
|
214
|
+
index?: unknown;
|
|
215
|
+
object?: unknown;
|
|
216
|
+
}>;
|
|
217
|
+
model?: unknown;
|
|
218
|
+
object?: unknown;
|
|
219
|
+
usage?: unknown;
|
|
220
|
+
error?: unknown;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Image generation request sent to the provider Images API.
|
|
224
|
+
*/
|
|
225
|
+
export interface GenerateImageInput {
|
|
226
|
+
/** Optional per-call model override. Defaults to the `ImageGeneration` AI config entry. */
|
|
227
|
+
model?: string;
|
|
228
|
+
/** Detailed image prompt. */
|
|
229
|
+
prompt: string;
|
|
230
|
+
/** Provider image size, such as 1024x1024 or 1536x1024. */
|
|
231
|
+
size?: string;
|
|
232
|
+
/** Provider image quality, such as low, medium, high, or auto. */
|
|
233
|
+
quality?: string;
|
|
234
|
+
/** Provider image output format. Defaults to png. */
|
|
235
|
+
outputFormat?: 'png' | 'jpeg' | 'webp';
|
|
236
|
+
/** Provider end-user id forwarded to OpenAI, when available. */
|
|
237
|
+
user?: string | null;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Provider Images API response shape used by the AI service.
|
|
241
|
+
*/
|
|
242
|
+
export interface ImageResponsePayloadWithUsage {
|
|
243
|
+
created?: unknown;
|
|
244
|
+
data?: Array<{
|
|
245
|
+
b64_json?: unknown;
|
|
246
|
+
revised_prompt?: unknown;
|
|
247
|
+
url?: unknown;
|
|
248
|
+
}>;
|
|
249
|
+
error?: unknown;
|
|
250
|
+
usage?: unknown;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Image bytes and tracking context passed to a storage callback.
|
|
254
|
+
*/
|
|
255
|
+
export interface GenerateImageStoreInput {
|
|
256
|
+
/** Base64-encoded image bytes returned by the provider. */
|
|
257
|
+
b64Json: string;
|
|
258
|
+
/** Tracked request row, when request logging is enabled. */
|
|
259
|
+
aiRequest: AiRequest | null;
|
|
260
|
+
/** Tracked request id, when request logging is enabled. */
|
|
261
|
+
aiRequestId: string | null;
|
|
262
|
+
/** Provider model used for this image. */
|
|
263
|
+
model: string;
|
|
264
|
+
/** Prompt sent to the provider. */
|
|
265
|
+
prompt: string;
|
|
266
|
+
/** Image size sent to the provider. */
|
|
267
|
+
size: string | null;
|
|
268
|
+
/** Image quality sent to the provider. */
|
|
269
|
+
quality: string | null;
|
|
270
|
+
/** Image output format sent to the provider. */
|
|
271
|
+
outputFormat: string;
|
|
272
|
+
/** Compact provider response without raw image bytes. */
|
|
273
|
+
providerResponse: Record<string, unknown> | null;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Stores generated image bytes and returns the app-owned storage reference.
|
|
277
|
+
*/
|
|
278
|
+
export type GenerateImageStoreCallback<TStored> = (input: GenerateImageStoreInput) => TStored | Promise<TStored>;
|
|
279
|
+
/**
|
|
280
|
+
* Optional metadata and storage callback for image generation.
|
|
281
|
+
*/
|
|
282
|
+
export interface GenerateImageOptions<TStored = unknown> extends RequestLogOptions {
|
|
283
|
+
/** Saves generated image bytes and returns the value stored on AiRequest.response. */
|
|
284
|
+
store?: GenerateImageStoreCallback<TStored>;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Image generation result with optional storage and tracking identifiers.
|
|
288
|
+
*/
|
|
289
|
+
export interface GenerateImageResult<TStored = unknown> {
|
|
290
|
+
/** Base64-encoded image bytes returned by the provider. */
|
|
291
|
+
b64Json: string;
|
|
292
|
+
/** Image model used for the request. */
|
|
293
|
+
model: string;
|
|
294
|
+
/** Saved AiRequest id when response logging is enabled; otherwise null. */
|
|
295
|
+
aiRequestId: string | null;
|
|
296
|
+
/** App-owned storage reference returned by the storage callback. */
|
|
297
|
+
stored: TStored | null;
|
|
298
|
+
}
|
|
299
|
+
/** Tracking metadata and an optional application-specific operation name. */
|
|
300
|
+
export interface RequestLogOptions extends AIResponseLogOptions {
|
|
301
|
+
operation?: string;
|
|
302
|
+
}
|
|
303
|
+
/** Internal lifecycle state for a persisted text request and its current attempt. */
|
|
304
|
+
export interface TrackedRequest {
|
|
305
|
+
aiRequest: AiRequest;
|
|
306
|
+
conversation: AiConversation;
|
|
307
|
+
nextSequence: number;
|
|
308
|
+
startTimeMs: number;
|
|
309
|
+
userId: string | null;
|
|
310
|
+
scopeId: string | null;
|
|
311
|
+
/** Model for the current provider attempt; updated when failover switches providers. */
|
|
312
|
+
model: string;
|
|
313
|
+
/** Provider for the current attempt; updated when failover switches providers. */
|
|
314
|
+
provider: AIProvider;
|
|
315
|
+
}
|
|
316
|
+
/** Internal lifecycle state for a persisted embedding operation. */
|
|
317
|
+
export interface TrackedEmbeddingRequest {
|
|
318
|
+
aiRequest: AiRequest;
|
|
319
|
+
startTimeMs: number;
|
|
320
|
+
model: string;
|
|
321
|
+
}
|
|
322
|
+
/** Internal lifecycle state for a persisted image operation. */
|
|
323
|
+
export interface TrackedImageRequest {
|
|
324
|
+
aiRequest: AiRequest;
|
|
325
|
+
startTimeMs: number;
|
|
326
|
+
model: string;
|
|
327
|
+
}
|
|
328
|
+
/** Normalized provider token counts; null means the provider did not report a value. */
|
|
329
|
+
export interface TokenUsage {
|
|
330
|
+
inputTokens: number | null;
|
|
331
|
+
outputTokens: number | null;
|
|
332
|
+
totalTokens: number | null;
|
|
333
|
+
reasoningTokens: number | null;
|
|
334
|
+
cachedTokens: number | null;
|
|
335
|
+
/** Input tokens written into a billable provider prompt cache. */
|
|
336
|
+
cacheWriteTokens: number | null;
|
|
337
|
+
}
|
|
338
|
+
/** Minimal identity accepted at a framework ownership boundary. */
|
|
339
|
+
export interface AIRecordIdentity {
|
|
340
|
+
id: unknown;
|
|
341
|
+
}
|
|
342
|
+
/** Model constructors used for every AI persistence operation. */
|
|
343
|
+
export interface AIModels {
|
|
344
|
+
conversation: typeof AiConversation;
|
|
345
|
+
request: typeof AiRequest;
|
|
346
|
+
message: typeof import('../AiMessage.js').AiMessage;
|
|
347
|
+
}
|