@trigger.dev/sdk 0.0.0-python-preview-20250226140121 → 0.0.0-rc-4-8-0-20261021151928
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/README.md +29 -9
- package/dist/commonjs/imports/ai-runtime-cjs.cjs.map +1 -0
- package/dist/commonjs/imports/ai-runtime.d.ts +1 -0
- package/dist/commonjs/imports/ai-runtime.js +31 -0
- package/dist/commonjs/imports/uncrypto.js +4 -4
- package/dist/commonjs/package.json +2 -1
- package/dist/commonjs/v3/agentSkillsRuntime.d.ts +28 -0
- package/dist/commonjs/v3/agentSkillsRuntime.js +173 -0
- package/dist/commonjs/v3/agentSkillsRuntime.js.map +1 -0
- package/dist/commonjs/v3/ai-shared.d.ts +156 -0
- package/dist/commonjs/v3/ai-shared.js +215 -0
- package/dist/commonjs/v3/ai-shared.js.map +1 -0
- package/dist/commonjs/v3/ai.d.ts +4225 -0
- package/dist/commonjs/v3/ai.js +11569 -0
- package/dist/commonjs/v3/ai.js.map +1 -0
- package/dist/commonjs/v3/aiAutoTelemetry.d.ts +2 -0
- package/dist/commonjs/v3/aiAutoTelemetry.js +81 -0
- package/dist/commonjs/v3/aiAutoTelemetry.js.map +1 -0
- package/dist/commonjs/v3/auth.d.ts +71 -10
- package/dist/commonjs/v3/auth.js +85 -19
- package/dist/commonjs/v3/auth.js.map +1 -1
- package/dist/commonjs/v3/batch.d.ts +3 -3
- package/dist/commonjs/v3/batch.js.map +1 -1
- package/dist/commonjs/v3/cache.js.map +1 -1
- package/dist/commonjs/v3/chat-client.d.ts +324 -0
- package/dist/commonjs/v3/chat-client.js +774 -0
- package/dist/commonjs/v3/chat-client.js.map +1 -0
- package/dist/commonjs/v3/chat-react.d.ts +244 -0
- package/dist/commonjs/v3/chat-react.js +463 -0
- package/dist/commonjs/v3/chat-react.js.map +1 -0
- package/dist/commonjs/v3/chat-server.d.ts +350 -0
- package/dist/commonjs/v3/chat-server.js +965 -0
- package/dist/commonjs/v3/chat-server.js.map +1 -0
- package/dist/commonjs/v3/chat-tab-coordinator.d.ts +65 -0
- package/dist/commonjs/v3/chat-tab-coordinator.js +235 -0
- package/dist/commonjs/v3/chat-tab-coordinator.js.map +1 -0
- package/dist/commonjs/v3/chat.d.ts +792 -0
- package/dist/commonjs/v3/chat.js +1662 -0
- package/dist/commonjs/v3/chat.js.map +1 -0
- package/dist/commonjs/v3/chatRouteWait.d.ts +21 -0
- package/dist/commonjs/v3/chatRouteWait.js +43 -0
- package/dist/commonjs/v3/chatRouteWait.js.map +1 -0
- package/dist/commonjs/v3/chatSnapshotIo.d.ts +2 -0
- package/dist/commonjs/v3/chatSnapshotIo.js +173 -0
- package/dist/commonjs/v3/chatSnapshotIo.js.map +1 -0
- package/dist/commonjs/v3/chatVersionSkew.d.ts +12 -0
- package/dist/commonjs/v3/chatVersionSkew.js +30 -0
- package/dist/commonjs/v3/chatVersionSkew.js.map +1 -0
- package/dist/commonjs/v3/compactionResponse.d.ts +9 -0
- package/dist/commonjs/v3/compactionResponse.js +37 -0
- package/dist/commonjs/v3/compactionResponse.js.map +1 -0
- package/dist/commonjs/v3/concurrency-shared.d.ts +13 -0
- package/dist/commonjs/v3/concurrency-shared.js +35 -0
- package/dist/commonjs/v3/concurrency-shared.js.map +1 -0
- package/dist/commonjs/v3/concurrencyLimits.d.ts +103 -0
- package/dist/commonjs/v3/concurrencyLimits.js +134 -0
- package/dist/commonjs/v3/concurrencyLimits.js.map +1 -0
- package/dist/commonjs/v3/config.js.map +1 -1
- package/dist/commonjs/v3/deployments.d.ts +25 -0
- package/dist/commonjs/v3/deployments.js +37 -0
- package/dist/commonjs/v3/deployments.js.map +1 -0
- package/dist/commonjs/v3/envvars.d.ts +5 -5
- package/dist/commonjs/v3/envvars.js.map +1 -1
- package/dist/commonjs/v3/externalDeploymentId.d.ts +23 -0
- package/dist/commonjs/v3/externalDeploymentId.js +43 -0
- package/dist/commonjs/v3/externalDeploymentId.js.map +1 -0
- package/dist/commonjs/v3/heartbeats.d.ts +37 -0
- package/dist/commonjs/v3/heartbeats.js +45 -0
- package/dist/commonjs/v3/heartbeats.js.map +1 -0
- package/dist/commonjs/v3/hooks.d.ts +26 -0
- package/dist/commonjs/v3/hooks.js +79 -0
- package/dist/commonjs/v3/hooks.js.map +1 -0
- package/dist/commonjs/v3/idempotencyKeys.d.ts +2 -1
- package/dist/commonjs/v3/idempotencyKeys.js +1 -0
- package/dist/commonjs/v3/idempotencyKeys.js.map +1 -1
- package/dist/commonjs/v3/index.d.ts +20 -5
- package/dist/commonjs/v3/index.js +56 -20
- package/dist/commonjs/v3/index.js.map +1 -1
- package/dist/commonjs/v3/locals.d.ts +3 -0
- package/dist/commonjs/v3/locals.js +6 -0
- package/dist/commonjs/v3/locals.js.map +1 -0
- package/dist/commonjs/v3/managedChatResponse.d.ts +44 -0
- package/dist/commonjs/v3/managedChatResponse.js +221 -0
- package/dist/commonjs/v3/managedChatResponse.js.map +1 -0
- package/dist/commonjs/v3/metadata.d.ts +5 -2
- package/dist/commonjs/v3/metadata.js +8 -1
- package/dist/commonjs/v3/metadata.js.map +1 -1
- package/dist/commonjs/v3/modelFileDownload.d.ts +10 -0
- package/dist/commonjs/v3/modelFileDownload.js +164 -0
- package/dist/commonjs/v3/modelFileDownload.js.map +1 -0
- package/dist/commonjs/v3/otel.d.ts +4 -0
- package/dist/commonjs/v3/otel.js +12 -0
- package/dist/commonjs/v3/otel.js.map +1 -0
- package/dist/commonjs/v3/prompt.d.ts +38 -0
- package/dist/commonjs/v3/prompt.js +146 -0
- package/dist/commonjs/v3/prompt.js.map +1 -0
- package/dist/commonjs/v3/promptManagement.d.ts +26 -0
- package/dist/commonjs/v3/promptManagement.js +180 -0
- package/dist/commonjs/v3/promptManagement.js.map +1 -0
- package/dist/commonjs/v3/prompts.d.ts +3 -0
- package/dist/commonjs/v3/prompts.js +15 -0
- package/dist/commonjs/v3/prompts.js.map +1 -0
- package/dist/commonjs/v3/query.d.ts +545 -0
- package/dist/commonjs/v3/query.js +163 -0
- package/dist/commonjs/v3/query.js.map +1 -0
- package/dist/commonjs/v3/queues.d.ts +107 -0
- package/dist/commonjs/v3/queues.js +225 -0
- package/dist/commonjs/v3/queues.js.map +1 -0
- package/dist/commonjs/v3/retry.d.ts +6 -2
- package/dist/commonjs/v3/retry.js +34 -23
- package/dist/commonjs/v3/retry.js.map +1 -1
- package/dist/commonjs/v3/runs.d.ts +182 -101
- package/dist/commonjs/v3/runs.js +99 -5
- package/dist/commonjs/v3/runs.js.map +1 -1
- package/dist/commonjs/v3/schedules/api.d.ts +8 -1
- package/dist/commonjs/v3/schedules/index.d.ts +29 -9
- package/dist/commonjs/v3/schedules/index.js +5 -1
- package/dist/commonjs/v3/schedules/index.js.map +1 -1
- package/dist/commonjs/v3/schemas.d.ts +1 -0
- package/dist/commonjs/{integrations.js → v3/schemas.js} +1 -1
- package/dist/commonjs/v3/schemas.js.map +1 -0
- package/dist/commonjs/v3/sessionTracing.d.ts +7 -0
- package/dist/commonjs/v3/sessionTracing.js +44 -0
- package/dist/commonjs/v3/sessionTracing.js.map +1 -0
- package/dist/commonjs/v3/sessions.d.ts +268 -0
- package/dist/commonjs/v3/sessions.js +776 -0
- package/dist/commonjs/v3/sessions.js.map +1 -0
- package/dist/commonjs/v3/shared.d.ts +129 -24
- package/dist/commonjs/v3/shared.js +1527 -689
- package/dist/commonjs/v3/shared.js.map +1 -1
- package/dist/commonjs/v3/skill.d.ts +99 -0
- package/dist/commonjs/v3/skill.js +165 -0
- package/dist/commonjs/v3/skill.js.map +1 -0
- package/dist/commonjs/v3/skills.d.ts +2 -0
- package/dist/commonjs/v3/skills.js +6 -0
- package/dist/commonjs/v3/skills.js.map +1 -0
- package/dist/commonjs/v3/steeringContext.d.ts +41 -0
- package/dist/commonjs/v3/steeringContext.js +118 -0
- package/dist/commonjs/v3/steeringContext.js.map +1 -0
- package/dist/commonjs/v3/streams.d.ts +298 -0
- package/dist/commonjs/v3/streams.js +584 -0
- package/dist/commonjs/v3/streams.js.map +1 -0
- package/dist/commonjs/v3/tasks.d.ts +19 -4
- package/dist/commonjs/v3/tasks.js +15 -1
- package/dist/commonjs/v3/tasks.js.map +1 -1
- package/dist/commonjs/v3/test/index.d.ts +5 -0
- package/dist/commonjs/v3/test/index.js +23 -0
- package/dist/commonjs/v3/test/index.js.map +1 -0
- package/dist/commonjs/v3/test/mock-channel-connector.d.ts +172 -0
- package/dist/commonjs/v3/test/mock-channel-connector.js +173 -0
- package/dist/commonjs/v3/test/mock-channel-connector.js.map +1 -0
- package/dist/commonjs/v3/test/mock-chat-agent.d.ts +388 -0
- package/dist/commonjs/v3/test/mock-chat-agent.js +689 -0
- package/dist/commonjs/v3/test/mock-chat-agent.js.map +1 -0
- package/dist/commonjs/v3/test/setup-catalog.d.ts +1 -0
- package/dist/commonjs/v3/test/setup-catalog.js +18 -0
- package/dist/commonjs/v3/test/setup-catalog.js.map +1 -0
- package/dist/commonjs/v3/test/test-session-handle.d.ts +24 -0
- package/dist/commonjs/v3/test/test-session-handle.js +271 -0
- package/dist/commonjs/v3/test/test-session-handle.js.map +1 -0
- package/dist/commonjs/v3/test/transcript-storage-tests.d.ts +40 -0
- package/dist/commonjs/v3/test/transcript-storage-tests.js +258 -0
- package/dist/commonjs/v3/test/transcript-storage-tests.js.map +1 -0
- package/dist/commonjs/v3/toolResultOrder.d.ts +15 -0
- package/dist/commonjs/v3/toolResultOrder.js +58 -0
- package/dist/commonjs/v3/toolResultOrder.js.map +1 -0
- package/dist/commonjs/v3/transcriptStorage.d.ts +307 -0
- package/dist/commonjs/v3/transcriptStorage.js +445 -0
- package/dist/commonjs/v3/transcriptStorage.js.map +1 -0
- package/dist/commonjs/v3/triggerClient.d.ts +45 -0
- package/dist/commonjs/v3/triggerClient.js +114 -0
- package/dist/commonjs/v3/triggerClient.js.map +1 -0
- package/dist/commonjs/v3/uiMessageChunks.d.ts +1 -0
- package/dist/commonjs/v3/uiMessageChunks.js +119 -0
- package/dist/commonjs/v3/uiMessageChunks.js.map +1 -0
- package/dist/commonjs/v3/usage.js +7 -6
- package/dist/commonjs/v3/usage.js.map +1 -1
- package/dist/commonjs/v3/wait.d.ts +218 -3
- package/dist/commonjs/v3/wait.js +433 -7
- package/dist/commonjs/v3/wait.js.map +1 -1
- package/dist/commonjs/v3/waitUntil.js.map +1 -1
- package/dist/commonjs/v3/webhookWaiters.d.ts +80 -0
- package/dist/commonjs/v3/webhookWaiters.js +156 -0
- package/dist/commonjs/v3/webhookWaiters.js.map +1 -0
- package/dist/commonjs/v3/webhooks.d.ts +192 -2
- package/dist/commonjs/v3/webhooks.js +340 -2
- package/dist/commonjs/v3/webhooks.js.map +1 -1
- package/dist/commonjs/version.js +1 -1
- package/dist/esm/imports/ai-runtime.d.ts +2 -0
- package/dist/esm/imports/ai-runtime.js +16 -0
- package/dist/esm/imports/ai-runtime.js.map +1 -0
- package/dist/esm/package.json +2 -1
- package/dist/esm/v3/agentSkillsRuntime.d.ts +28 -0
- package/dist/esm/v3/agentSkillsRuntime.js +136 -0
- package/dist/esm/v3/agentSkillsRuntime.js.map +1 -0
- package/dist/esm/v3/ai-shared.d.ts +156 -0
- package/dist/esm/v3/ai-shared.js +208 -0
- package/dist/esm/v3/ai-shared.js.map +1 -0
- package/dist/esm/v3/ai.d.ts +4225 -0
- package/dist/esm/v3/ai.js +11550 -0
- package/dist/esm/v3/ai.js.map +1 -0
- package/dist/esm/v3/aiAutoTelemetry.d.ts +2 -0
- package/dist/esm/v3/aiAutoTelemetry.js +78 -0
- package/dist/esm/v3/aiAutoTelemetry.js.map +1 -0
- package/dist/esm/v3/auth.d.ts +71 -10
- package/dist/esm/v3/auth.js +83 -17
- package/dist/esm/v3/auth.js.map +1 -1
- package/dist/esm/v3/batch.d.ts +3 -3
- package/dist/esm/v3/batch.js +2 -2
- package/dist/esm/v3/batch.js.map +1 -1
- package/dist/esm/v3/chat-client.d.ts +324 -0
- package/dist/esm/v3/chat-client.js +769 -0
- package/dist/esm/v3/chat-client.js.map +1 -0
- package/dist/esm/v3/chat-react.d.ts +244 -0
- package/dist/esm/v3/chat-react.js +455 -0
- package/dist/esm/v3/chat-react.js.map +1 -0
- package/dist/esm/v3/chat-server.d.ts +350 -0
- package/dist/esm/v3/chat-server.js +962 -0
- package/dist/esm/v3/chat-server.js.map +1 -0
- package/dist/esm/v3/chat-tab-coordinator.d.ts +65 -0
- package/dist/esm/v3/chat-tab-coordinator.js +231 -0
- package/dist/esm/v3/chat-tab-coordinator.js.map +1 -0
- package/dist/esm/v3/chat.d.ts +792 -0
- package/dist/esm/v3/chat.js +1655 -0
- package/dist/esm/v3/chat.js.map +1 -0
- package/dist/esm/v3/chatRouteWait.d.ts +21 -0
- package/dist/esm/v3/chatRouteWait.js +40 -0
- package/dist/esm/v3/chatRouteWait.js.map +1 -0
- package/dist/esm/v3/chatSnapshotIo.d.ts +2 -0
- package/dist/esm/v3/chatSnapshotIo.js +165 -0
- package/dist/esm/v3/chatSnapshotIo.js.map +1 -0
- package/dist/esm/v3/chatVersionSkew.d.ts +12 -0
- package/dist/esm/v3/chatVersionSkew.js +27 -0
- package/dist/esm/v3/chatVersionSkew.js.map +1 -0
- package/dist/esm/v3/compactionResponse.d.ts +9 -0
- package/dist/esm/v3/compactionResponse.js +34 -0
- package/dist/esm/v3/compactionResponse.js.map +1 -0
- package/dist/esm/v3/concurrency-shared.d.ts +13 -0
- package/dist/esm/v3/concurrency-shared.js +31 -0
- package/dist/esm/v3/concurrency-shared.js.map +1 -0
- package/dist/esm/v3/concurrencyLimits.d.ts +103 -0
- package/dist/esm/v3/concurrencyLimits.js +126 -0
- package/dist/esm/v3/concurrencyLimits.js.map +1 -0
- package/dist/esm/v3/deployments.d.ts +25 -0
- package/dist/esm/v3/deployments.js +34 -0
- package/dist/esm/v3/deployments.js.map +1 -0
- package/dist/esm/v3/envvars.d.ts +5 -5
- package/dist/esm/v3/envvars.js.map +1 -1
- package/dist/esm/v3/externalDeploymentId.d.ts +23 -0
- package/dist/esm/v3/externalDeploymentId.js +38 -0
- package/dist/esm/v3/externalDeploymentId.js.map +1 -0
- package/dist/esm/v3/heartbeats.d.ts +37 -0
- package/dist/esm/v3/heartbeats.js +42 -0
- package/dist/esm/v3/heartbeats.js.map +1 -0
- package/dist/esm/v3/hooks.d.ts +26 -0
- package/dist/esm/v3/hooks.js +66 -0
- package/dist/esm/v3/hooks.js.map +1 -0
- package/dist/esm/v3/idempotencyKeys.d.ts +2 -1
- package/dist/esm/v3/idempotencyKeys.js +2 -1
- package/dist/esm/v3/idempotencyKeys.js.map +1 -1
- package/dist/esm/v3/index.d.ts +20 -5
- package/dist/esm/v3/index.js +16 -2
- package/dist/esm/v3/index.js.map +1 -1
- package/dist/esm/v3/locals.d.ts +3 -0
- package/dist/esm/v3/locals.js +3 -0
- package/dist/esm/v3/locals.js.map +1 -0
- package/dist/esm/v3/managedChatResponse.d.ts +44 -0
- package/dist/esm/v3/managedChatResponse.js +216 -0
- package/dist/esm/v3/managedChatResponse.js.map +1 -0
- package/dist/esm/v3/metadata.d.ts +5 -2
- package/dist/esm/v3/metadata.js +8 -1
- package/dist/esm/v3/metadata.js.map +1 -1
- package/dist/esm/v3/modelFileDownload.d.ts +10 -0
- package/dist/esm/v3/modelFileDownload.js +161 -0
- package/dist/esm/v3/modelFileDownload.js.map +1 -0
- package/dist/esm/v3/otel.d.ts +4 -0
- package/dist/esm/v3/otel.js +9 -0
- package/dist/esm/v3/otel.js.map +1 -0
- package/dist/esm/v3/prompt.d.ts +38 -0
- package/dist/esm/v3/prompt.js +143 -0
- package/dist/esm/v3/prompt.js.map +1 -0
- package/dist/esm/v3/promptManagement.d.ts +26 -0
- package/dist/esm/v3/promptManagement.js +170 -0
- package/dist/esm/v3/promptManagement.js.map +1 -0
- package/dist/esm/v3/prompts.d.ts +3 -0
- package/dist/esm/v3/prompts.js +3 -0
- package/dist/esm/v3/prompts.js.map +1 -0
- package/dist/esm/v3/query.d.ts +545 -0
- package/dist/esm/v3/query.js +160 -0
- package/dist/esm/v3/query.js.map +1 -0
- package/dist/esm/v3/queues.d.ts +107 -0
- package/dist/esm/v3/queues.js +217 -0
- package/dist/esm/v3/queues.js.map +1 -0
- package/dist/esm/v3/retry.d.ts +6 -2
- package/dist/esm/v3/retry.js +27 -19
- package/dist/esm/v3/retry.js.map +1 -1
- package/dist/esm/v3/runs.d.ts +179 -98
- package/dist/esm/v3/runs.js +99 -5
- package/dist/esm/v3/runs.js.map +1 -1
- package/dist/esm/v3/schedules/api.d.ts +8 -1
- package/dist/esm/v3/schedules/index.d.ts +29 -9
- package/dist/esm/v3/schedules/index.js +6 -2
- package/dist/esm/v3/schedules/index.js.map +1 -1
- package/dist/esm/v3/schemas.d.ts +1 -0
- package/dist/esm/v3/schemas.js +2 -0
- package/dist/esm/v3/schemas.js.map +1 -0
- package/dist/esm/v3/sessionTracing.d.ts +7 -0
- package/dist/esm/v3/sessionTracing.js +40 -0
- package/dist/esm/v3/sessionTracing.js.map +1 -0
- package/dist/esm/v3/sessions.d.ts +268 -0
- package/dist/esm/v3/sessions.js +767 -0
- package/dist/esm/v3/sessions.js.map +1 -0
- package/dist/esm/v3/shared.d.ts +129 -24
- package/dist/esm/v3/shared.js +1521 -688
- package/dist/esm/v3/shared.js.map +1 -1
- package/dist/esm/v3/skill.d.ts +99 -0
- package/dist/esm/v3/skill.js +128 -0
- package/dist/esm/v3/skill.js.map +1 -0
- package/dist/esm/v3/skills.d.ts +2 -0
- package/dist/esm/v3/skills.js +2 -0
- package/dist/esm/v3/skills.js.map +1 -0
- package/dist/esm/v3/steeringContext.d.ts +41 -0
- package/dist/esm/v3/steeringContext.js +113 -0
- package/dist/esm/v3/steeringContext.js.map +1 -0
- package/dist/esm/v3/streams.d.ts +298 -0
- package/dist/esm/v3/streams.js +580 -0
- package/dist/esm/v3/streams.js.map +1 -0
- package/dist/esm/v3/tasks.d.ts +19 -4
- package/dist/esm/v3/tasks.js +16 -2
- package/dist/esm/v3/tasks.js.map +1 -1
- package/dist/esm/v3/test/index.d.ts +5 -0
- package/dist/esm/v3/test/index.js +15 -0
- package/dist/esm/v3/test/index.js.map +1 -0
- package/dist/esm/v3/test/mock-channel-connector.d.ts +172 -0
- package/dist/esm/v3/test/mock-channel-connector.js +170 -0
- package/dist/esm/v3/test/mock-channel-connector.js.map +1 -0
- package/dist/esm/v3/test/mock-chat-agent.d.ts +388 -0
- package/dist/esm/v3/test/mock-chat-agent.js +685 -0
- package/dist/esm/v3/test/mock-chat-agent.js.map +1 -0
- package/dist/esm/v3/test/setup-catalog.d.ts +1 -0
- package/dist/esm/v3/test/setup-catalog.js +16 -0
- package/dist/esm/v3/test/setup-catalog.js.map +1 -0
- package/dist/esm/v3/test/test-session-handle.d.ts +24 -0
- package/dist/esm/v3/test/test-session-handle.js +268 -0
- package/dist/esm/v3/test/test-session-handle.js.map +1 -0
- package/dist/esm/v3/test/transcript-storage-tests.d.ts +40 -0
- package/dist/esm/v3/test/transcript-storage-tests.js +255 -0
- package/dist/esm/v3/test/transcript-storage-tests.js.map +1 -0
- package/dist/esm/v3/toolResultOrder.d.ts +15 -0
- package/dist/esm/v3/toolResultOrder.js +55 -0
- package/dist/esm/v3/toolResultOrder.js.map +1 -0
- package/dist/esm/v3/transcriptStorage.d.ts +307 -0
- package/dist/esm/v3/transcriptStorage.js +431 -0
- package/dist/esm/v3/transcriptStorage.js.map +1 -0
- package/dist/esm/v3/triggerClient.d.ts +45 -0
- package/dist/esm/v3/triggerClient.js +77 -0
- package/dist/esm/v3/triggerClient.js.map +1 -0
- package/dist/esm/v3/uiMessageChunks.d.ts +1 -0
- package/dist/esm/v3/uiMessageChunks.js +116 -0
- package/dist/esm/v3/uiMessageChunks.js.map +1 -0
- package/dist/esm/v3/usage.js +7 -6
- package/dist/esm/v3/usage.js.map +1 -1
- package/dist/esm/v3/wait.d.ts +218 -3
- package/dist/esm/v3/wait.js +431 -7
- package/dist/esm/v3/wait.js.map +1 -1
- package/dist/esm/v3/webhookWaiters.d.ts +80 -0
- package/dist/esm/v3/webhookWaiters.js +149 -0
- package/dist/esm/v3/webhookWaiters.js.map +1 -0
- package/dist/esm/v3/webhooks.d.ts +192 -2
- package/dist/esm/v3/webhooks.js +336 -2
- package/dist/esm/v3/webhooks.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/docs/ai/observability.mdx +174 -0
- package/docs/ai/prompts.mdx +426 -0
- package/docs/ai-chat/actions.mdx +148 -0
- package/docs/ai-chat/anatomy.mdx +87 -0
- package/docs/ai-chat/backend.mdx +933 -0
- package/docs/ai-chat/background-injection.mdx +320 -0
- package/docs/ai-chat/changelog.mdx +958 -0
- package/docs/ai-chat/chat-local.mdx +170 -0
- package/docs/ai-chat/client-protocol.mdx +1091 -0
- package/docs/ai-chat/compaction.mdx +413 -0
- package/docs/ai-chat/custom-agents.mdx +545 -0
- package/docs/ai-chat/error-handling.mdx +379 -0
- package/docs/ai-chat/fast-starts.mdx +764 -0
- package/docs/ai-chat/frontend.mdx +634 -0
- package/docs/ai-chat/how-it-works.mdx +226 -0
- package/docs/ai-chat/lifecycle-hooks.mdx +532 -0
- package/docs/ai-chat/mcp.mdx +97 -0
- package/docs/ai-chat/migrating-from-a-route-handler.mdx +594 -0
- package/docs/ai-chat/migrating-from-hydrate-messages.mdx +299 -0
- package/docs/ai-chat/overview.mdx +86 -0
- package/docs/ai-chat/patterns/branching-conversations.mdx +145 -0
- package/docs/ai-chat/patterns/code-sandbox.mdx +122 -0
- package/docs/ai-chat/patterns/database-persistence.mdx +425 -0
- package/docs/ai-chat/patterns/human-in-the-loop.mdx +281 -0
- package/docs/ai-chat/patterns/large-payloads.mdx +165 -0
- package/docs/ai-chat/patterns/native-compaction.mdx +310 -0
- package/docs/ai-chat/patterns/oom-resilience.mdx +116 -0
- package/docs/ai-chat/patterns/persistence-and-replay.mdx +218 -0
- package/docs/ai-chat/patterns/recovery-boot.mdx +233 -0
- package/docs/ai-chat/patterns/redacting-telemetry.mdx +117 -0
- package/docs/ai-chat/patterns/skills.mdx +214 -0
- package/docs/ai-chat/patterns/sub-agents.mdx +412 -0
- package/docs/ai-chat/patterns/tool-result-auditing.mdx +145 -0
- package/docs/ai-chat/patterns/trusted-edge-signals.mdx +333 -0
- package/docs/ai-chat/patterns/version-upgrades.mdx +261 -0
- package/docs/ai-chat/pending-messages.mdx +363 -0
- package/docs/ai-chat/prompt-caching.mdx +204 -0
- package/docs/ai-chat/quick-start.mdx +163 -0
- package/docs/ai-chat/reference.mdx +1071 -0
- package/docs/ai-chat/server-chat.mdx +259 -0
- package/docs/ai-chat/sessions.mdx +334 -0
- package/docs/ai-chat/side-channels.mdx +172 -0
- package/docs/ai-chat/testing.mdx +691 -0
- package/docs/ai-chat/tools.mdx +192 -0
- package/docs/ai-chat/transcript-storage.mdx +247 -0
- package/docs/ai-chat/types.mdx +242 -0
- package/docs/ai-chat/upgrade-guide.mdx +511 -0
- package/docs/apikeys.mdx +170 -0
- package/docs/billing-limits.mdx +73 -0
- package/docs/building-with-ai.mdx +261 -0
- package/docs/bulk-actions.mdx +77 -0
- package/docs/changelog.mdx +6 -0
- package/docs/cli-deploy-commands.mdx +9 -0
- package/docs/cli-dev-commands.mdx +9 -0
- package/docs/cli-env-commands.mdx +115 -0
- package/docs/cli-init-commands.mdx +84 -0
- package/docs/cli-introduction.mdx +25 -0
- package/docs/cli-list-profiles-commands.mdx +42 -0
- package/docs/cli-login-commands.mdx +53 -0
- package/docs/cli-logout-commands.mdx +33 -0
- package/docs/cli-preview-archive.mdx +59 -0
- package/docs/cli-projects-commands.mdx +74 -0
- package/docs/cli-promote-commands.mdx +9 -0
- package/docs/cli-runs-commands.mdx +95 -0
- package/docs/cli-switch.mdx +43 -0
- package/docs/cli-tasks-commands.mdx +95 -0
- package/docs/cli-update-commands.mdx +48 -0
- package/docs/cli-whoami-commands.mdx +45 -0
- package/docs/community.mdx +6 -0
- package/docs/concurrency.mdx +416 -0
- package/docs/config/config-file.mdx +662 -0
- package/docs/config/extensions/additionalFiles.mdx +38 -0
- package/docs/config/extensions/additionalPackages.mdx +40 -0
- package/docs/config/extensions/aptGet.mdx +34 -0
- package/docs/config/extensions/audioWaveform.mdx +23 -0
- package/docs/config/extensions/custom.mdx +393 -0
- package/docs/config/extensions/emitDecoratorMetadata.mdx +52 -0
- package/docs/config/extensions/esbuildPlugin.mdx +31 -0
- package/docs/config/extensions/ffmpeg.mdx +45 -0
- package/docs/config/extensions/lightpanda.mdx +56 -0
- package/docs/config/extensions/overview.mdx +69 -0
- package/docs/config/extensions/playwright.mdx +195 -0
- package/docs/config/extensions/prismaExtension.mdx +1013 -0
- package/docs/config/extensions/puppeteer.mdx +28 -0
- package/docs/config/extensions/pythonExtension.mdx +190 -0
- package/docs/config/extensions/syncEnvVars.mdx +330 -0
- package/docs/context.mdx +235 -0
- package/docs/database-connections.mdx +213 -0
- package/docs/deploy-environment-variables.mdx +466 -0
- package/docs/deployment/atomic-deployment.mdx +470 -0
- package/docs/deployment/dev-branches.mdx +92 -0
- package/docs/deployment/overview.mdx +260 -0
- package/docs/deployment/preview-branches.mdx +227 -0
- package/docs/errors-retrying.mdx +383 -0
- package/docs/github-actions.mdx +260 -0
- package/docs/github-integration.mdx +148 -0
- package/docs/github-repo.mdx +8 -0
- package/docs/help-email.mdx +6 -0
- package/docs/help-slack.mdx +12 -0
- package/docs/hidden-tasks.mdx +56 -0
- package/docs/how-it-works.mdx +454 -0
- package/docs/how-to-reduce-your-spend.mdx +211 -0
- package/docs/idempotency.mdx +542 -0
- package/docs/introduction.mdx +135 -0
- package/docs/limits.mdx +284 -0
- package/docs/logging.mdx +195 -0
- package/docs/machines.mdx +952 -0
- package/docs/manual-setup.mdx +632 -0
- package/docs/mcp-agent-rules.mdx +41 -0
- package/docs/mcp-introduction.mdx +386 -0
- package/docs/mcp-tools.mdx +425 -0
- package/docs/migrating-from-v3.mdx +332 -0
- package/docs/observability/dashboards.mdx +166 -0
- package/docs/observability/query.mdx +614 -0
- package/docs/open-source-contributing.mdx +16 -0
- package/docs/private-networking/aws-console-setup.mdx +304 -0
- package/docs/private-networking/overview.mdx +144 -0
- package/docs/private-networking/troubleshooting.mdx +78 -0
- package/docs/queues.mdx +271 -0
- package/docs/quick-start.mdx +60 -0
- package/docs/realtime/auth.mdx +228 -0
- package/docs/realtime/backend/input-streams.mdx +159 -0
- package/docs/realtime/backend/overview.mdx +45 -0
- package/docs/realtime/backend/streams.mdx +433 -0
- package/docs/realtime/backend/subscribe.mdx +225 -0
- package/docs/realtime/how-it-works.mdx +94 -0
- package/docs/realtime/overview.mdx +63 -0
- package/docs/realtime/react-hooks/overview.mdx +73 -0
- package/docs/realtime/react-hooks/session-stream.mdx +126 -0
- package/docs/realtime/react-hooks/streams.mdx +517 -0
- package/docs/realtime/react-hooks/subscribe.mdx +690 -0
- package/docs/realtime/react-hooks/swr.mdx +87 -0
- package/docs/realtime/react-hooks/triggering.mdx +194 -0
- package/docs/realtime/react-hooks/use-wait-token.mdx +34 -0
- package/docs/realtime/run-object.mdx +197 -0
- package/docs/replaying.mdx +97 -0
- package/docs/reports.mdx +159 -0
- package/docs/request-feature.mdx +6 -0
- package/docs/roadmap.mdx +6 -0
- package/docs/run-tests.mdx +21 -0
- package/docs/run-usage.mdx +113 -0
- package/docs/runs/bulk-actions.mdx +183 -0
- package/docs/runs/heartbeats.mdx +38 -0
- package/docs/runs/list-best-practices.mdx +234 -0
- package/docs/runs/max-duration.mdx +143 -0
- package/docs/runs/metadata.mdx +731 -0
- package/docs/runs/priority.mdx +8 -0
- package/docs/runs.mdx +406 -0
- package/docs/self-hosting/docker.mdx +512 -0
- package/docs/self-hosting/env/supervisor.mdx +78 -0
- package/docs/self-hosting/env/webapp.mdx +305 -0
- package/docs/self-hosting/kubernetes.mdx +725 -0
- package/docs/self-hosting/overview.mdx +145 -0
- package/docs/self-hosting/security.mdx +67 -0
- package/docs/skills.mdx +85 -0
- package/docs/tags.mdx +126 -0
- package/docs/tasks/overview.mdx +695 -0
- package/docs/tasks/scheduled.mdx +479 -0
- package/docs/tasks/schemaTask.mdx +413 -0
- package/docs/tasks/streams.mdx +887 -0
- package/docs/triggering.mdx +1340 -0
- package/docs/troubleshooting-alerts.mdx +607 -0
- package/docs/troubleshooting-debugging-in-vscode.mdx +9 -0
- package/docs/troubleshooting-github-issues.mdx +6 -0
- package/docs/troubleshooting-uptime-status.mdx +7 -0
- package/docs/troubleshooting-zod.mdx +158 -0
- package/docs/troubleshooting.mdx +414 -0
- package/docs/upgrading-packages.mdx +80 -0
- package/docs/vercel-integration.mdx +250 -0
- package/docs/versioning.mdx +58 -0
- package/docs/video-walkthrough.mdx +23 -0
- package/docs/wait-for-token.mdx +540 -0
- package/docs/wait-for.mdx +42 -0
- package/docs/wait-until.mdx +53 -0
- package/docs/wait.mdx +18 -0
- package/docs/webhooks/channels.mdx +154 -0
- package/docs/webhooks/connect.mdx +91 -0
- package/docs/webhooks/deliveries.mdx +99 -0
- package/docs/webhooks/filters.mdx +146 -0
- package/docs/webhooks/human-in-the-loop.mdx +158 -0
- package/docs/webhooks/linear.mdx +186 -0
- package/docs/webhooks/overview.mdx +115 -0
- package/docs/webhooks/session-routing.mdx +141 -0
- package/docs/webhooks/slack.mdx +393 -0
- package/docs/webhooks/sources.mdx +250 -0
- package/docs/webhooks/waiters.mdx +190 -0
- package/docs/writing-tasks-introduction.mdx +34 -0
- package/package.json +143 -42
- package/skills/trigger-authoring-chat-agent/SKILL.md +308 -0
- package/skills/trigger-authoring-tasks/SKILL.md +254 -0
- package/skills/trigger-chat-agent-advanced/SKILL.md +403 -0
- package/skills/trigger-cost-savings/SKILL.md +116 -0
- package/skills/trigger-realtime-and-frontend/SKILL.md +276 -0
- package/dist/commonjs/apiClient.d.ts +0 -727
- package/dist/commonjs/apiClient.js +0 -692
- package/dist/commonjs/apiClient.js.map +0 -1
- package/dist/commonjs/concurrencyLimit.d.ts +0 -10
- package/dist/commonjs/concurrencyLimit.js +0 -17
- package/dist/commonjs/concurrencyLimit.js.map +0 -1
- package/dist/commonjs/errors.d.ts +0 -66
- package/dist/commonjs/errors.js +0 -109
- package/dist/commonjs/errors.js.map +0 -1
- package/dist/commonjs/httpEndpoint.d.ts +0 -87
- package/dist/commonjs/httpEndpoint.js +0 -130
- package/dist/commonjs/httpEndpoint.js.map +0 -1
- package/dist/commonjs/index.d.ts +0 -23
- package/dist/commonjs/index.js +0 -55
- package/dist/commonjs/index.js.map +0 -1
- package/dist/commonjs/integrations.d.ts +0 -11
- package/dist/commonjs/integrations.js.map +0 -1
- package/dist/commonjs/io.d.ts +0 -441
- package/dist/commonjs/io.js +0 -1165
- package/dist/commonjs/io.js.map +0 -1
- package/dist/commonjs/ioWithIntegrations.d.ts +0 -4
- package/dist/commonjs/ioWithIntegrations.js +0 -32
- package/dist/commonjs/ioWithIntegrations.js.map +0 -1
- package/dist/commonjs/job.d.ts +0 -96
- package/dist/commonjs/job.js +0 -210
- package/dist/commonjs/job.js.map +0 -1
- package/dist/commonjs/retry.d.ts +0 -20
- package/dist/commonjs/retry.js +0 -22
- package/dist/commonjs/retry.js.map +0 -1
- package/dist/commonjs/runLocalStorage.d.ts +0 -8
- package/dist/commonjs/runLocalStorage.js +0 -6
- package/dist/commonjs/runLocalStorage.js.map +0 -1
- package/dist/commonjs/security.d.ts +0 -18
- package/dist/commonjs/security.js +0 -41
- package/dist/commonjs/security.js.map +0 -1
- package/dist/commonjs/status.d.ts +0 -19
- package/dist/commonjs/status.js +0 -38
- package/dist/commonjs/status.js.map +0 -1
- package/dist/commonjs/store/keyValueStore.d.ts +0 -17
- package/dist/commonjs/store/keyValueStore.js +0 -138
- package/dist/commonjs/store/keyValueStore.js.map +0 -1
- package/dist/commonjs/store/keyValueStoreClient.d.ts +0 -19
- package/dist/commonjs/store/keyValueStoreClient.js +0 -65
- package/dist/commonjs/store/keyValueStoreClient.js.map +0 -1
- package/dist/commonjs/triggerClient.d.ts +0 -290
- package/dist/commonjs/triggerClient.js +0 -1366
- package/dist/commonjs/triggerClient.js.map +0 -1
- package/dist/commonjs/triggers/dynamic.d.ts +0 -56
- package/dist/commonjs/triggers/dynamic.js +0 -97
- package/dist/commonjs/triggers/dynamic.js.map +0 -1
- package/dist/commonjs/triggers/eventTrigger.d.ts +0 -58
- package/dist/commonjs/triggers/eventTrigger.js +0 -69
- package/dist/commonjs/triggers/eventTrigger.js.map +0 -1
- package/dist/commonjs/triggers/externalSource.d.ts +0 -148
- package/dist/commonjs/triggers/externalSource.js +0 -106
- package/dist/commonjs/triggers/externalSource.js.map +0 -1
- package/dist/commonjs/triggers/invokeTrigger.d.ts +0 -39
- package/dist/commonjs/triggers/invokeTrigger.js +0 -58
- package/dist/commonjs/triggers/invokeTrigger.js.map +0 -1
- package/dist/commonjs/triggers/notifications.d.ts +0 -111
- package/dist/commonjs/triggers/notifications.js +0 -101
- package/dist/commonjs/triggers/notifications.js.map +0 -1
- package/dist/commonjs/triggers/scheduled.d.ts +0 -145
- package/dist/commonjs/triggers/scheduled.js +0 -208
- package/dist/commonjs/triggers/scheduled.js.map +0 -1
- package/dist/commonjs/triggers/webhook.d.ts +0 -143
- package/dist/commonjs/triggers/webhook.js +0 -133
- package/dist/commonjs/triggers/webhook.js.map +0 -1
- package/dist/commonjs/typed-emitter.d.ts +0 -37
- package/dist/commonjs/typed-emitter.js +0 -3
- package/dist/commonjs/typed-emitter.js.map +0 -1
- package/dist/commonjs/types.d.ts +0 -204
- package/dist/commonjs/types.js +0 -23
- package/dist/commonjs/types.js.map +0 -1
- package/dist/commonjs/utils/formatSchemaErrors.d.ts +0 -3
- package/dist/commonjs/utils/formatSchemaErrors.js +0 -10
- package/dist/commonjs/utils/formatSchemaErrors.js.map +0 -1
- package/dist/commonjs/utils/typedAsyncLocalStorage.d.ts +0 -6
- package/dist/commonjs/utils/typedAsyncLocalStorage.js +0 -18
- package/dist/commonjs/utils/typedAsyncLocalStorage.js.map +0 -1
- package/dist/commonjs/utils.d.ts +0 -1
- package/dist/commonjs/utils.js +0 -11
- package/dist/commonjs/utils.js.map +0 -1
- package/dist/esm/apiClient.d.ts +0 -727
- package/dist/esm/apiClient.js +0 -687
- package/dist/esm/apiClient.js.map +0 -1
- package/dist/esm/concurrencyLimit.d.ts +0 -10
- package/dist/esm/concurrencyLimit.js +0 -13
- package/dist/esm/concurrencyLimit.js.map +0 -1
- package/dist/esm/errors.d.ts +0 -66
- package/dist/esm/errors.js +0 -95
- package/dist/esm/errors.js.map +0 -1
- package/dist/esm/httpEndpoint.d.ts +0 -87
- package/dist/esm/httpEndpoint.js +0 -125
- package/dist/esm/httpEndpoint.js.map +0 -1
- package/dist/esm/index.d.ts +0 -23
- package/dist/esm/index.js +0 -35
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/integrations.d.ts +0 -11
- package/dist/esm/integrations.js +0 -2
- package/dist/esm/integrations.js.map +0 -1
- package/dist/esm/io.d.ts +0 -441
- package/dist/esm/io.js +0 -1159
- package/dist/esm/io.js.map +0 -1
- package/dist/esm/ioWithIntegrations.d.ts +0 -4
- package/dist/esm/ioWithIntegrations.js +0 -29
- package/dist/esm/ioWithIntegrations.js.map +0 -1
- package/dist/esm/job.d.ts +0 -96
- package/dist/esm/job.js +0 -206
- package/dist/esm/job.js.map +0 -1
- package/dist/esm/retry.d.ts +0 -20
- package/dist/esm/retry.js +0 -19
- package/dist/esm/retry.js.map +0 -1
- package/dist/esm/runLocalStorage.d.ts +0 -8
- package/dist/esm/runLocalStorage.js +0 -3
- package/dist/esm/runLocalStorage.js.map +0 -1
- package/dist/esm/security.d.ts +0 -18
- package/dist/esm/security.js +0 -34
- package/dist/esm/security.js.map +0 -1
- package/dist/esm/status.d.ts +0 -19
- package/dist/esm/status.js +0 -34
- package/dist/esm/status.js.map +0 -1
- package/dist/esm/store/keyValueStore.d.ts +0 -17
- package/dist/esm/store/keyValueStore.js +0 -134
- package/dist/esm/store/keyValueStore.js.map +0 -1
- package/dist/esm/store/keyValueStoreClient.d.ts +0 -19
- package/dist/esm/store/keyValueStoreClient.js +0 -61
- package/dist/esm/store/keyValueStoreClient.js.map +0 -1
- package/dist/esm/triggerClient.d.ts +0 -288
- package/dist/esm/triggerClient.js +0 -1359
- package/dist/esm/triggerClient.js.map +0 -1
- package/dist/esm/triggers/dynamic.d.ts +0 -56
- package/dist/esm/triggers/dynamic.js +0 -93
- package/dist/esm/triggers/dynamic.js.map +0 -1
- package/dist/esm/triggers/eventTrigger.d.ts +0 -58
- package/dist/esm/triggers/eventTrigger.js +0 -64
- package/dist/esm/triggers/eventTrigger.js.map +0 -1
- package/dist/esm/triggers/externalSource.d.ts +0 -148
- package/dist/esm/triggers/externalSource.js +0 -100
- package/dist/esm/triggers/externalSource.js.map +0 -1
- package/dist/esm/triggers/invokeTrigger.d.ts +0 -39
- package/dist/esm/triggers/invokeTrigger.js +0 -53
- package/dist/esm/triggers/invokeTrigger.js.map +0 -1
- package/dist/esm/triggers/notifications.d.ts +0 -111
- package/dist/esm/triggers/notifications.js +0 -94
- package/dist/esm/triggers/notifications.js.map +0 -1
- package/dist/esm/triggers/scheduled.d.ts +0 -145
- package/dist/esm/triggers/scheduled.js +0 -197
- package/dist/esm/triggers/scheduled.js.map +0 -1
- package/dist/esm/triggers/webhook.d.ts +0 -143
- package/dist/esm/triggers/webhook.js +0 -128
- package/dist/esm/triggers/webhook.js.map +0 -1
- package/dist/esm/typed-emitter.d.ts +0 -37
- package/dist/esm/typed-emitter.js +0 -2
- package/dist/esm/typed-emitter.js.map +0 -1
- package/dist/esm/types.d.ts +0 -204
- package/dist/esm/types.js +0 -19
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/utils/formatSchemaErrors.d.ts +0 -3
- package/dist/esm/utils/formatSchemaErrors.js +0 -7
- package/dist/esm/utils/formatSchemaErrors.js.map +0 -1
- package/dist/esm/utils/typedAsyncLocalStorage.d.ts +0 -6
- package/dist/esm/utils/typedAsyncLocalStorage.js +0 -14
- package/dist/esm/utils/typedAsyncLocalStorage.js.map +0 -1
- package/dist/esm/utils.d.ts +0 -1
- package/dist/esm/utils.js +0 -8
- package/dist/esm/utils.js.map +0 -1
|
@@ -1,60 +1,142 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TaskRunPromise = exports.SubtaskUnwrapError = void 0;
|
|
3
|
+
exports.BatchTriggerError = exports.TaskRunPromise = exports.SubtaskUnwrapError = void 0;
|
|
4
4
|
exports.queue = queue;
|
|
5
|
+
exports.concurrencyLimit = concurrencyLimit;
|
|
5
6
|
exports.createTask = createTask;
|
|
6
7
|
exports.createToolTask = createToolTask;
|
|
7
8
|
exports.createSchemaTask = createSchemaTask;
|
|
8
9
|
exports.trigger = trigger;
|
|
9
10
|
exports.triggerAndWait = triggerAndWait;
|
|
11
|
+
exports.triggerAndSubscribe = triggerAndSubscribe;
|
|
10
12
|
exports.batchTriggerAndWait = batchTriggerAndWait;
|
|
11
|
-
exports.triggerAndPoll = triggerAndPoll;
|
|
12
13
|
exports.batchTrigger = batchTrigger;
|
|
13
14
|
exports.batchTriggerById = batchTriggerById;
|
|
14
15
|
exports.batchTriggerByIdAndWait = batchTriggerByIdAndWait;
|
|
15
16
|
exports.batchTriggerTasks = batchTriggerTasks;
|
|
16
17
|
exports.batchTriggerAndWaitTasks = batchTriggerAndWaitTasks;
|
|
18
|
+
exports.uniqueBatchTaskIdentifiers = uniqueBatchTaskIdentifiers;
|
|
19
|
+
exports.offloadBatchItemPayloads = offloadBatchItemPayloads;
|
|
20
|
+
exports.readableStreamToAsyncIterable = readableStreamToAsyncIterable;
|
|
17
21
|
const api_1 = require("@opentelemetry/api");
|
|
18
22
|
const v3_1 = require("@trigger.dev/core/v3");
|
|
19
23
|
Object.defineProperty(exports, "SubtaskUnwrapError", { enumerable: true, get: function () { return v3_1.SubtaskUnwrapError; } });
|
|
20
24
|
Object.defineProperty(exports, "TaskRunPromise", { enumerable: true, get: function () { return v3_1.TaskRunPromise; } });
|
|
21
|
-
const
|
|
25
|
+
const externalDeploymentId_js_1 = require("./externalDeploymentId.js");
|
|
22
26
|
const tracer_js_1 = require("./tracer.js");
|
|
27
|
+
const concurrency_shared_js_1 = require("./concurrency-shared.js");
|
|
28
|
+
/** A task's `queue` is a queue object or a string reference to a queue defined elsewhere. */
|
|
29
|
+
function normalizeTaskQueue(queue) {
|
|
30
|
+
if (!queue) {
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
return { queue: typeof queue === "string" ? { name: queue } : queue };
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Validates and normalizes the task `concurrency` option into its manifest shape:
|
|
37
|
+
* at most one inline limit (caps this task) plus up to two named limits (shared).
|
|
38
|
+
*/
|
|
39
|
+
function normalizeTaskConcurrency(taskId, concurrency) {
|
|
40
|
+
if (!concurrency) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
const items = Array.isArray(concurrency) ? concurrency : [concurrency];
|
|
44
|
+
const inline = [];
|
|
45
|
+
const limits = [];
|
|
46
|
+
for (const item of items) {
|
|
47
|
+
if (typeof item === "string") {
|
|
48
|
+
limits.push(item);
|
|
49
|
+
}
|
|
50
|
+
else if (item &&
|
|
51
|
+
typeof item === "object" &&
|
|
52
|
+
"name" in item &&
|
|
53
|
+
typeof item.name === "string") {
|
|
54
|
+
(0, concurrency_shared_js_1.validateConcurrencyLimitName)(item.name);
|
|
55
|
+
v3_1.resourceCatalog.registerConcurrencyLimitMetadata(item);
|
|
56
|
+
limits.push(item.name);
|
|
57
|
+
}
|
|
58
|
+
else if (item && typeof item === "object") {
|
|
59
|
+
inline.push({ perKey: item.perKey, total: item.total });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (inline.length > 1) {
|
|
63
|
+
throw new Error(`Task "${taskId}": concurrency accepts at most one inline limit. Give shared limits a name with concurrencyLimit().`);
|
|
64
|
+
}
|
|
65
|
+
if (limits.length > 2) {
|
|
66
|
+
throw new Error(`Task "${taskId}": concurrency accepts at most two named limits.`);
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
inline: inline[0],
|
|
70
|
+
limits: limits.length > 0 ? limits : undefined,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** Builds the queue field of a trigger request body. */
|
|
74
|
+
function triggerQueueBody(queue, fallbackQueueName) {
|
|
75
|
+
const name = queue ?? fallbackQueueName;
|
|
76
|
+
return { queue: name ? { name } : undefined };
|
|
77
|
+
}
|
|
23
78
|
function queue(options) {
|
|
79
|
+
v3_1.resourceCatalog.registerQueueMetadata(options);
|
|
80
|
+
// @ts-expect-error
|
|
81
|
+
options[Symbol.for("trigger.dev/queue")] = true;
|
|
82
|
+
return options;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Declares a named, shareable concurrency limit. Tasks hold it via their `concurrency`
|
|
86
|
+
* option; every task holding the same limit draws from the same pools.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
*
|
|
90
|
+
* ```ts
|
|
91
|
+
* export const openaiLimit = concurrencyLimit({ name: "openai", total: 25 });
|
|
92
|
+
*
|
|
93
|
+
* export const generateSummary = task({
|
|
94
|
+
* id: "generate-summary",
|
|
95
|
+
* concurrency: [{ total: 5 }, openaiLimit],
|
|
96
|
+
* run: async (payload) => {},
|
|
97
|
+
* });
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
function concurrencyLimit(options) {
|
|
101
|
+
(0, concurrency_shared_js_1.validateConcurrencyLimitName)(options.name);
|
|
102
|
+
v3_1.resourceCatalog.registerConcurrencyLimitMetadata(options);
|
|
103
|
+
// @ts-expect-error
|
|
104
|
+
options[Symbol.for("trigger.dev/concurrencyLimit")] = true;
|
|
24
105
|
return options;
|
|
25
106
|
}
|
|
26
107
|
function createTask(params) {
|
|
27
|
-
const
|
|
28
|
-
? queue({
|
|
29
|
-
name: params.queue?.name ?? `task/${params.id}`,
|
|
30
|
-
...params.queue,
|
|
31
|
-
})
|
|
32
|
-
: undefined;
|
|
108
|
+
const normalizedQueue = normalizeTaskQueue(params.queue);
|
|
33
109
|
const task = {
|
|
34
110
|
id: params.id,
|
|
35
111
|
description: params.description,
|
|
112
|
+
jsonSchema: params.jsonSchema,
|
|
36
113
|
trigger: async (payload, options) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
? `${taskMetadata.exportName}.trigger()`
|
|
40
|
-
: `trigger()`, params.id, payload, undefined, {
|
|
41
|
-
queue: customQueue,
|
|
114
|
+
return await trigger_internal("trigger()", params.id, payload, undefined, {
|
|
115
|
+
queue: normalizedQueue.queue?.name,
|
|
42
116
|
...options,
|
|
43
117
|
});
|
|
44
118
|
},
|
|
45
119
|
batchTrigger: async (items, options) => {
|
|
46
|
-
|
|
47
|
-
return await batchTrigger_internal(taskMetadata && taskMetadata.exportName
|
|
48
|
-
? `${taskMetadata.exportName}.batchTrigger()`
|
|
49
|
-
: `batchTrigger()`, params.id, items, options, undefined, undefined, customQueue);
|
|
120
|
+
return await batchTrigger_internal("batchTrigger()", params.id, items, options, undefined, undefined, normalizedQueue.queue?.name);
|
|
50
121
|
},
|
|
51
|
-
triggerAndWait: (payload, options) => {
|
|
52
|
-
|
|
122
|
+
triggerAndWait: (payload, options, requestOptions) => {
|
|
123
|
+
return new v3_1.TaskRunPromise((resolve, reject) => {
|
|
124
|
+
triggerAndWait_internal("triggerAndWait()", params.id, payload, undefined, {
|
|
125
|
+
queue: normalizedQueue.queue?.name,
|
|
126
|
+
...options,
|
|
127
|
+
}, requestOptions)
|
|
128
|
+
.then((result) => {
|
|
129
|
+
resolve(result);
|
|
130
|
+
})
|
|
131
|
+
.catch((error) => {
|
|
132
|
+
reject(error);
|
|
133
|
+
});
|
|
134
|
+
}, params.id);
|
|
135
|
+
},
|
|
136
|
+
triggerAndSubscribe: (payload, options) => {
|
|
53
137
|
return new v3_1.TaskRunPromise((resolve, reject) => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
: `triggerAndWait()`, params.id, payload, undefined, {
|
|
57
|
-
queue: customQueue,
|
|
138
|
+
triggerAndSubscribe_internal("triggerAndSubscribe()", params.id, payload, undefined, {
|
|
139
|
+
queue: normalizedQueue.queue?.name,
|
|
58
140
|
...options,
|
|
59
141
|
})
|
|
60
142
|
.then((result) => {
|
|
@@ -66,34 +148,46 @@ function createTask(params) {
|
|
|
66
148
|
}, params.id);
|
|
67
149
|
},
|
|
68
150
|
batchTriggerAndWait: async (items, options) => {
|
|
69
|
-
|
|
70
|
-
return await batchTriggerAndWait_internal(taskMetadata && taskMetadata.exportName
|
|
71
|
-
? `${taskMetadata.exportName}.batchTriggerAndWait()`
|
|
72
|
-
: `batchTriggerAndWait()`, params.id, items, undefined, options, undefined, customQueue);
|
|
151
|
+
return await batchTriggerAndWait_internal("batchTriggerAndWait()", params.id, items, undefined, options, undefined, normalizedQueue.queue?.name);
|
|
73
152
|
},
|
|
74
153
|
};
|
|
75
|
-
|
|
154
|
+
registerTaskLifecycleHooks(params.id, params);
|
|
155
|
+
v3_1.resourceCatalog.registerTaskMetadata({
|
|
76
156
|
id: params.id,
|
|
77
157
|
description: params.description,
|
|
78
|
-
queue:
|
|
158
|
+
queue: normalizedQueue.queue,
|
|
159
|
+
concurrency: normalizeTaskConcurrency(params.id, params.concurrency),
|
|
79
160
|
retry: params.retry ? { ...v3_1.defaultRetryOptions, ...params.retry } : undefined,
|
|
80
161
|
machine: typeof params.machine === "string" ? { preset: params.machine } : params.machine,
|
|
162
|
+
triggerSource: params.triggerSource,
|
|
163
|
+
agentConfig: params.agentConfig,
|
|
81
164
|
maxDuration: params.maxDuration,
|
|
165
|
+
ttl: params.ttl,
|
|
166
|
+
payloadSchema: params.jsonSchema,
|
|
82
167
|
fns: {
|
|
83
168
|
run: params.run,
|
|
84
|
-
init: params.init,
|
|
85
|
-
cleanup: params.cleanup,
|
|
86
|
-
middleware: params.middleware,
|
|
87
|
-
handleError: params.handleError,
|
|
88
|
-
onSuccess: params.onSuccess,
|
|
89
|
-
onFailure: params.onFailure,
|
|
90
|
-
onStart: params.onStart,
|
|
91
169
|
},
|
|
92
170
|
});
|
|
171
|
+
const queue = normalizedQueue.queue;
|
|
172
|
+
/**
|
|
173
|
+
* A string queue name (bare or as a tuple's first element) is a REFERENCE to a
|
|
174
|
+
* queue defined elsewhere; registering it would create an empty definition that
|
|
175
|
+
* can shadow the real one depending on module evaluation order.
|
|
176
|
+
*/
|
|
177
|
+
const homeIsReference = typeof params.queue === "string";
|
|
178
|
+
if (queue && typeof queue.name === "string" && !homeIsReference) {
|
|
179
|
+
v3_1.resourceCatalog.registerQueueMetadata({
|
|
180
|
+
name: queue.name,
|
|
181
|
+
concurrencyLimit: queue.concurrencyLimit,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
93
184
|
// @ts-expect-error
|
|
94
185
|
task[Symbol.for("trigger.dev/task")] = true;
|
|
95
186
|
return task;
|
|
96
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* @deprecated Use `schemaTask` plus AI SDK `tool()` with `execute: ai.toolExecute(task)` instead.
|
|
190
|
+
*/
|
|
97
191
|
function createToolTask(params) {
|
|
98
192
|
const task = createSchemaTask({
|
|
99
193
|
...params,
|
|
@@ -111,41 +205,41 @@ function createToolTask(params) {
|
|
|
111
205
|
};
|
|
112
206
|
}
|
|
113
207
|
function createSchemaTask(params) {
|
|
114
|
-
const customQueue = params.queue
|
|
115
|
-
? queue({
|
|
116
|
-
name: params.queue?.name ?? `task/${params.id}`,
|
|
117
|
-
...params.queue,
|
|
118
|
-
})
|
|
119
|
-
: undefined;
|
|
120
208
|
const parsePayload = params.schema
|
|
121
209
|
? (0, v3_1.getSchemaParseFn)(params.schema)
|
|
122
210
|
: undefined;
|
|
211
|
+
const normalizedQueue = normalizeTaskQueue(params.queue);
|
|
123
212
|
const task = {
|
|
124
213
|
id: params.id,
|
|
125
214
|
description: params.description,
|
|
126
215
|
schema: params.schema,
|
|
127
216
|
trigger: async (payload, options, requestOptions) => {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
? `${taskMetadata.exportName}.trigger()`
|
|
131
|
-
: `trigger()`, params.id, payload, parsePayload, {
|
|
132
|
-
queue: customQueue,
|
|
217
|
+
return await trigger_internal("trigger()", params.id, payload, parsePayload, {
|
|
218
|
+
queue: normalizedQueue.queue?.name,
|
|
133
219
|
...options,
|
|
134
220
|
}, requestOptions);
|
|
135
221
|
},
|
|
136
222
|
batchTrigger: async (items, options, requestOptions) => {
|
|
137
|
-
|
|
138
|
-
return await batchTrigger_internal(taskMetadata && taskMetadata.exportName
|
|
139
|
-
? `${taskMetadata.exportName}.batchTrigger()`
|
|
140
|
-
: `batchTrigger()`, params.id, items, options, parsePayload, requestOptions, customQueue);
|
|
223
|
+
return await batchTrigger_internal("batchTrigger()", params.id, items, options, parsePayload, requestOptions, normalizedQueue.queue?.name);
|
|
141
224
|
},
|
|
142
225
|
triggerAndWait: (payload, options) => {
|
|
143
|
-
const taskMetadata = v3_1.taskCatalog.getTaskManifest(params.id);
|
|
144
226
|
return new v3_1.TaskRunPromise((resolve, reject) => {
|
|
145
|
-
triggerAndWait_internal(
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
227
|
+
triggerAndWait_internal("triggerAndWait()", params.id, payload, parsePayload, {
|
|
228
|
+
queue: normalizedQueue.queue?.name,
|
|
229
|
+
...options,
|
|
230
|
+
})
|
|
231
|
+
.then((result) => {
|
|
232
|
+
resolve(result);
|
|
233
|
+
})
|
|
234
|
+
.catch((error) => {
|
|
235
|
+
reject(error);
|
|
236
|
+
});
|
|
237
|
+
}, params.id);
|
|
238
|
+
},
|
|
239
|
+
triggerAndSubscribe: (payload, options) => {
|
|
240
|
+
return new v3_1.TaskRunPromise((resolve, reject) => {
|
|
241
|
+
triggerAndSubscribe_internal("triggerAndSubscribe()", params.id, payload, parsePayload, {
|
|
242
|
+
queue: normalizedQueue.queue?.name,
|
|
149
243
|
...options,
|
|
150
244
|
})
|
|
151
245
|
.then((result) => {
|
|
@@ -157,31 +251,40 @@ function createSchemaTask(params) {
|
|
|
157
251
|
}, params.id);
|
|
158
252
|
},
|
|
159
253
|
batchTriggerAndWait: async (items, options) => {
|
|
160
|
-
|
|
161
|
-
return await batchTriggerAndWait_internal(taskMetadata && taskMetadata.exportName
|
|
162
|
-
? `${taskMetadata.exportName}.batchTriggerAndWait()`
|
|
163
|
-
: `batchTriggerAndWait()`, params.id, items, parsePayload, options, undefined, customQueue);
|
|
254
|
+
return await batchTriggerAndWait_internal("batchTriggerAndWait()", params.id, items, parsePayload, options, undefined, normalizedQueue.queue?.name);
|
|
164
255
|
},
|
|
165
256
|
};
|
|
166
|
-
|
|
257
|
+
registerTaskLifecycleHooks(params.id, params);
|
|
258
|
+
v3_1.resourceCatalog.registerTaskMetadata({
|
|
167
259
|
id: params.id,
|
|
168
260
|
description: params.description,
|
|
169
|
-
queue:
|
|
261
|
+
queue: normalizedQueue.queue,
|
|
262
|
+
concurrency: normalizeTaskConcurrency(params.id, params.concurrency),
|
|
170
263
|
retry: params.retry ? { ...v3_1.defaultRetryOptions, ...params.retry } : undefined,
|
|
171
264
|
machine: typeof params.machine === "string" ? { preset: params.machine } : params.machine,
|
|
265
|
+
triggerSource: params.triggerSource,
|
|
266
|
+
agentConfig: params.agentConfig,
|
|
172
267
|
maxDuration: params.maxDuration,
|
|
268
|
+
ttl: params.ttl,
|
|
173
269
|
fns: {
|
|
174
270
|
run: params.run,
|
|
175
|
-
init: params.init,
|
|
176
|
-
cleanup: params.cleanup,
|
|
177
|
-
middleware: params.middleware,
|
|
178
|
-
handleError: params.handleError,
|
|
179
|
-
onSuccess: params.onSuccess,
|
|
180
|
-
onFailure: params.onFailure,
|
|
181
|
-
onStart: params.onStart,
|
|
182
271
|
parsePayload,
|
|
183
272
|
},
|
|
273
|
+
schema: params.schema,
|
|
184
274
|
});
|
|
275
|
+
const queue = normalizedQueue.queue;
|
|
276
|
+
/**
|
|
277
|
+
* A string queue name (bare or as a tuple's first element) is a REFERENCE to a
|
|
278
|
+
* queue defined elsewhere; registering it would create an empty definition that
|
|
279
|
+
* can shadow the real one depending on module evaluation order.
|
|
280
|
+
*/
|
|
281
|
+
const homeIsReference = typeof params.queue === "string";
|
|
282
|
+
if (queue && typeof queue.name === "string" && !homeIsReference) {
|
|
283
|
+
v3_1.resourceCatalog.registerQueueMetadata({
|
|
284
|
+
name: queue.name,
|
|
285
|
+
concurrencyLimit: queue.concurrencyLimit,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
185
288
|
// @ts-expect-error
|
|
186
289
|
task[Symbol.for("trigger.dev/task")] = true;
|
|
187
290
|
return task;
|
|
@@ -234,6 +337,38 @@ function triggerAndWait(id, payload, options, requestOptions) {
|
|
|
234
337
|
});
|
|
235
338
|
}, id);
|
|
236
339
|
}
|
|
340
|
+
/**
|
|
341
|
+
* Trigger a task and subscribe to its updates via realtime. Unlike `triggerAndWait`,
|
|
342
|
+
* this does NOT suspend the parent run — the parent stays alive and subscribes to updates.
|
|
343
|
+
* This enables parallel execution and proper abort signal handling.
|
|
344
|
+
*
|
|
345
|
+
* @param id - The id of the task to trigger
|
|
346
|
+
* @param payload
|
|
347
|
+
* @param options - Options for the task run, including an optional `signal` to cancel the subscription and child run
|
|
348
|
+
* @returns TaskRunPromise
|
|
349
|
+
* @example
|
|
350
|
+
* ```ts
|
|
351
|
+
* import { tasks } from "@trigger.dev/sdk/v3";
|
|
352
|
+
* const result = await tasks.triggerAndSubscribe("my-task", { foo: "bar" });
|
|
353
|
+
*
|
|
354
|
+
* if (result.ok) {
|
|
355
|
+
* console.log(result.output);
|
|
356
|
+
* } else {
|
|
357
|
+
* console.error(result.error);
|
|
358
|
+
* }
|
|
359
|
+
* ```
|
|
360
|
+
*/
|
|
361
|
+
function triggerAndSubscribe(id, payload, options, requestOptions) {
|
|
362
|
+
return new v3_1.TaskRunPromise((resolve, reject) => {
|
|
363
|
+
triggerAndSubscribe_internal("tasks.triggerAndSubscribe()", id, payload, undefined, options, requestOptions)
|
|
364
|
+
.then((result) => {
|
|
365
|
+
resolve(result);
|
|
366
|
+
})
|
|
367
|
+
.catch((error) => {
|
|
368
|
+
reject(error);
|
|
369
|
+
});
|
|
370
|
+
}, id);
|
|
371
|
+
}
|
|
237
372
|
/**
|
|
238
373
|
* Batch trigger multiple task runs with the given payloads, and wait for the results. Returns the results of the task runs.
|
|
239
374
|
* @param id - The id of the task to trigger
|
|
@@ -261,597 +396,947 @@ function triggerAndWait(id, payload, options, requestOptions) {
|
|
|
261
396
|
async function batchTriggerAndWait(id, items, options, requestOptions) {
|
|
262
397
|
return await batchTriggerAndWait_internal("tasks.batchTriggerAndWait()", id, items, undefined, options, requestOptions);
|
|
263
398
|
}
|
|
264
|
-
/**
|
|
265
|
-
* Trigger a task by its identifier with the given payload and poll until the run is completed.
|
|
266
|
-
*
|
|
267
|
-
* @example
|
|
268
|
-
*
|
|
269
|
-
* ```ts
|
|
270
|
-
* import { tasks, runs } from "@trigger.dev/sdk/v3";
|
|
271
|
-
* import type { myTask } from "./myTasks"; // Import just the type of the task
|
|
272
|
-
*
|
|
273
|
-
* const run = await tasks.triggerAndPoll<typeof myTask>("my-task", { foo: "bar" }); // The id and payload are fully typesafe
|
|
274
|
-
* console.log(run.output) // The output is also fully typed
|
|
275
|
-
* ```
|
|
276
|
-
*
|
|
277
|
-
* @returns {Run} The completed run, either successful or failed.
|
|
278
|
-
*/
|
|
279
|
-
async function triggerAndPoll(id, payload, options, requestOptions) {
|
|
280
|
-
const handle = await trigger(id, payload, options, requestOptions);
|
|
281
|
-
return runs_js_1.runs.poll(handle, options, requestOptions);
|
|
282
|
-
}
|
|
283
399
|
async function batchTrigger(id, items, options, requestOptions) {
|
|
284
400
|
return await batchTrigger_internal("tasks.batchTrigger()", id, items, options, undefined, requestOptions);
|
|
285
401
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
* @returns {Promise<BatchRunHandleFromTypes<InferRunTypes<TTask>>>} A promise that resolves with the batch run handle
|
|
296
|
-
* containing batch ID, cached status, idempotency info, runs, and public access token
|
|
297
|
-
*
|
|
298
|
-
* @example
|
|
299
|
-
* ```ts
|
|
300
|
-
* import { batch } from "@trigger.dev/sdk/v3";
|
|
301
|
-
* import type { myTask1, myTask2 } from "~/trigger/myTasks";
|
|
302
|
-
*
|
|
303
|
-
* // Trigger multiple tasks with different payloads
|
|
304
|
-
* const result = await batch.trigger<typeof myTask1 | typeof myTask2>([
|
|
305
|
-
* {
|
|
306
|
-
* id: "my-task-1",
|
|
307
|
-
* payload: { some: "data" },
|
|
308
|
-
* options: {
|
|
309
|
-
* queue: "default",
|
|
310
|
-
* concurrencyKey: "key",
|
|
311
|
-
* idempotencyKey: "unique-key",
|
|
312
|
-
* delay: "5m",
|
|
313
|
-
* tags: ["tag1", "tag2"]
|
|
314
|
-
* }
|
|
315
|
-
* },
|
|
316
|
-
* {
|
|
317
|
-
* id: "my-task-2",
|
|
318
|
-
* payload: { other: "data" }
|
|
319
|
-
* }
|
|
320
|
-
* ]);
|
|
321
|
-
* ```
|
|
322
|
-
*
|
|
323
|
-
* @description
|
|
324
|
-
* Each task item in the array can include:
|
|
325
|
-
* - `id`: The unique identifier of the task
|
|
326
|
-
* - `payload`: The data to pass to the task
|
|
327
|
-
* - `options`: Optional task-specific settings including:
|
|
328
|
-
* - `queue`: Specify a queue for the task
|
|
329
|
-
* - `concurrencyKey`: Control concurrent execution
|
|
330
|
-
* - `idempotencyKey`: Prevent duplicate runs
|
|
331
|
-
* - `idempotencyKeyTTL`: Time-to-live for idempotency key
|
|
332
|
-
* - `delay`: Delay before task execution
|
|
333
|
-
* - `ttl`: Time-to-live for the task
|
|
334
|
-
* - `tags`: Array of tags for the task
|
|
335
|
-
* - `maxAttempts`: Maximum retry attempts
|
|
336
|
-
* - `metadata`: Additional metadata
|
|
337
|
-
* - `maxDuration`: Maximum execution duration
|
|
338
|
-
*/
|
|
339
|
-
async function batchTriggerById(items, options, requestOptions) {
|
|
340
|
-
const apiClient = v3_1.apiClientManager.clientOrThrow();
|
|
341
|
-
const response = await apiClient.batchTriggerV2({
|
|
342
|
-
items: await Promise.all(items.map(async (item) => {
|
|
343
|
-
const taskMetadata = v3_1.taskCatalog.getTask(item.id);
|
|
402
|
+
// Implementation
|
|
403
|
+
async function batchTriggerById(...args) {
|
|
404
|
+
const [items, options, requestOptions] = args;
|
|
405
|
+
const apiClient = v3_1.apiClientManager.clientOrThrow(requestOptions?.clientConfig);
|
|
406
|
+
// Check if items is an array or a stream
|
|
407
|
+
if (Array.isArray(items)) {
|
|
408
|
+
// Array path: existing logic
|
|
409
|
+
const ndJsonItems = await Promise.all(items.map(async (item, index) => {
|
|
410
|
+
const taskMetadata = v3_1.resourceCatalog.getTask(item.id);
|
|
344
411
|
const parsedPayload = taskMetadata?.fns.parsePayload
|
|
345
412
|
? await taskMetadata?.fns.parsePayload(item.payload)
|
|
346
413
|
: item.payload;
|
|
347
414
|
const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
|
|
415
|
+
const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
|
|
348
416
|
return {
|
|
417
|
+
index,
|
|
349
418
|
task: item.id,
|
|
350
419
|
payload: payloadPacket.data,
|
|
351
420
|
options: {
|
|
352
|
-
|
|
421
|
+
...triggerQueueBody(item.options?.queue),
|
|
422
|
+
...(0, concurrency_shared_js_1.triggerConcurrencyBody)(item.options?.concurrency),
|
|
353
423
|
concurrencyKey: item.options?.concurrencyKey,
|
|
354
424
|
test: v3_1.taskContext.ctx?.run.isTest,
|
|
355
425
|
payloadType: payloadPacket.dataType,
|
|
356
|
-
idempotencyKey: await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey),
|
|
357
|
-
idempotencyKeyTTL: item.options?.idempotencyKeyTTL,
|
|
358
426
|
delay: item.options?.delay,
|
|
359
427
|
ttl: item.options?.ttl,
|
|
360
428
|
tags: item.options?.tags,
|
|
361
429
|
maxAttempts: item.options?.maxAttempts,
|
|
362
|
-
parentAttempt: v3_1.taskContext.ctx?.attempt.id,
|
|
363
430
|
metadata: item.options?.metadata,
|
|
364
431
|
maxDuration: item.options?.maxDuration,
|
|
432
|
+
idempotencyKey: (await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey)) ?? batchItemIdempotencyKey,
|
|
433
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
365
434
|
machine: item.options?.machine,
|
|
435
|
+
priority: item.options?.priority,
|
|
436
|
+
region: item.options?.region,
|
|
437
|
+
lockToVersion: item.options?.version ?? (0, externalDeploymentId_js_1.scopedEnvVar)("TRIGGER_VERSION"),
|
|
438
|
+
externalDeploymentId: (0, externalDeploymentId_js_1.resolveTriggerExternalDeploymentId)(item.options?.externalDeploymentId),
|
|
439
|
+
debounce: item.options?.debounce,
|
|
366
440
|
},
|
|
367
441
|
};
|
|
368
|
-
}))
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
442
|
+
}));
|
|
443
|
+
// Execute 2-phase batch
|
|
444
|
+
const response = await tracer_js_1.tracer.startActiveSpan("batch.trigger()", async (span) => {
|
|
445
|
+
const result = await executeBatchTwoPhase(apiClient, ndJsonItems, {
|
|
446
|
+
parentRunId: v3_1.taskContext.ctx?.run.id,
|
|
447
|
+
idempotencyKey: await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey),
|
|
448
|
+
spanParentAsLink: true, // Fire-and-forget: child runs get separate trace IDs
|
|
449
|
+
}, requestOptions);
|
|
450
|
+
span.setAttribute("batchId", result.id);
|
|
451
|
+
span.setAttribute("runCount", result.runCount);
|
|
452
|
+
return result;
|
|
453
|
+
}, {
|
|
454
|
+
kind: api_1.SpanKind.PRODUCER,
|
|
455
|
+
attributes: {
|
|
456
|
+
[v3_1.SemanticInternalAttributes.STYLE_ICON]: "trigger",
|
|
457
|
+
},
|
|
458
|
+
});
|
|
459
|
+
const handle = {
|
|
460
|
+
batchId: response.id,
|
|
461
|
+
runCount: response.runCount,
|
|
462
|
+
publicAccessToken: response.publicAccessToken,
|
|
463
|
+
};
|
|
464
|
+
return handle;
|
|
465
|
+
}
|
|
466
|
+
else {
|
|
467
|
+
// Stream path: convert to AsyncIterable and transform
|
|
468
|
+
const asyncItems = normalizeToAsyncIterable(items);
|
|
469
|
+
const transformedItems = transformBatchItemsStream(asyncItems, options);
|
|
470
|
+
// Execute streaming 2-phase batch
|
|
471
|
+
const response = await tracer_js_1.tracer.startActiveSpan("batch.trigger()", async (span) => {
|
|
472
|
+
const result = await executeBatchTwoPhaseStreaming(apiClient, transformedItems, {
|
|
473
|
+
parentRunId: v3_1.taskContext.ctx?.run.id,
|
|
474
|
+
idempotencyKey: await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey),
|
|
475
|
+
spanParentAsLink: true, // Fire-and-forget: child runs get separate trace IDs
|
|
476
|
+
}, requestOptions);
|
|
477
|
+
span.setAttribute("batchId", result.id);
|
|
478
|
+
span.setAttribute("runCount", result.runCount);
|
|
479
|
+
return result;
|
|
480
|
+
}, {
|
|
481
|
+
kind: api_1.SpanKind.PRODUCER,
|
|
482
|
+
attributes: {
|
|
483
|
+
[v3_1.SemanticInternalAttributes.STYLE_ICON]: "trigger",
|
|
484
|
+
},
|
|
485
|
+
});
|
|
486
|
+
const handle = {
|
|
487
|
+
batchId: response.id,
|
|
488
|
+
runCount: response.runCount,
|
|
489
|
+
publicAccessToken: response.publicAccessToken,
|
|
490
|
+
};
|
|
491
|
+
return handle;
|
|
492
|
+
}
|
|
407
493
|
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
*
|
|
412
|
-
* @template TTask - Union type of tasks to be triggered, extends AnyTask
|
|
413
|
-
*
|
|
414
|
-
* @param {Array<BatchByIdAndWaitItem<InferRunTypes<TTask>>>} items - Array of task items to trigger
|
|
415
|
-
* @param {TriggerApiRequestOptions} [requestOptions] - Optional API request configuration
|
|
416
|
-
*
|
|
417
|
-
* @returns {Promise<BatchByIdResult<TTask>>} A promise that resolves with the batch results, including
|
|
418
|
-
* success/failure status and strongly-typed outputs for each task
|
|
419
|
-
*
|
|
420
|
-
* @throws {Error} If called outside of a task.run() context
|
|
421
|
-
* @throws {Error} If no API client is configured
|
|
422
|
-
*
|
|
423
|
-
* @example
|
|
424
|
-
* ```ts
|
|
425
|
-
* import { batch, task } from "@trigger.dev/sdk/v3";
|
|
426
|
-
*
|
|
427
|
-
* export const parentTask = task({
|
|
428
|
-
* id: "parent-task",
|
|
429
|
-
* run: async (payload: string) => {
|
|
430
|
-
* const results = await batch.triggerAndWait<typeof childTask1 | typeof childTask2>([
|
|
431
|
-
* {
|
|
432
|
-
* id: "child-task-1",
|
|
433
|
-
* payload: { foo: "World" },
|
|
434
|
-
* options: {
|
|
435
|
-
* queue: "default",
|
|
436
|
-
* delay: "5m",
|
|
437
|
-
* tags: ["batch", "child1"]
|
|
438
|
-
* }
|
|
439
|
-
* },
|
|
440
|
-
* {
|
|
441
|
-
* id: "child-task-2",
|
|
442
|
-
* payload: { bar: 42 }
|
|
443
|
-
* }
|
|
444
|
-
* ]);
|
|
445
|
-
*
|
|
446
|
-
* // Type-safe result handling
|
|
447
|
-
* for (const result of results) {
|
|
448
|
-
* if (result.ok) {
|
|
449
|
-
* switch (result.taskIdentifier) {
|
|
450
|
-
* case "child-task-1":
|
|
451
|
-
* console.log("Child task 1 output:", result.output); // string type
|
|
452
|
-
* break;
|
|
453
|
-
* case "child-task-2":
|
|
454
|
-
* console.log("Child task 2 output:", result.output); // number type
|
|
455
|
-
* break;
|
|
456
|
-
* }
|
|
457
|
-
* } else {
|
|
458
|
-
* console.error("Task failed:", result.error);
|
|
459
|
-
* }
|
|
460
|
-
* }
|
|
461
|
-
* }
|
|
462
|
-
* });
|
|
463
|
-
* ```
|
|
464
|
-
*
|
|
465
|
-
* @description
|
|
466
|
-
* Each task item in the array can include:
|
|
467
|
-
* - `id`: The task identifier (must match one of the tasks in the union type)
|
|
468
|
-
* - `payload`: Strongly-typed payload matching the task's input type
|
|
469
|
-
* - `options`: Optional task-specific settings including:
|
|
470
|
-
* - `queue`: Specify a queue for the task
|
|
471
|
-
* - `concurrencyKey`: Control concurrent execution
|
|
472
|
-
* - `delay`: Delay before task execution
|
|
473
|
-
* - `ttl`: Time-to-live for the task
|
|
474
|
-
* - `tags`: Array of tags for the task
|
|
475
|
-
* - `maxAttempts`: Maximum retry attempts
|
|
476
|
-
* - `metadata`: Additional metadata
|
|
477
|
-
* - `maxDuration`: Maximum execution duration
|
|
478
|
-
*
|
|
479
|
-
* The function provides full type safety for:
|
|
480
|
-
* - Task IDs
|
|
481
|
-
* - Payload types
|
|
482
|
-
* - Return value types
|
|
483
|
-
* - Error handling
|
|
484
|
-
*/
|
|
485
|
-
async function batchTriggerByIdAndWait(items, options, requestOptions) {
|
|
494
|
+
// Implementation
|
|
495
|
+
async function batchTriggerByIdAndWait(...args) {
|
|
496
|
+
const [items, options, requestOptions] = args;
|
|
486
497
|
const ctx = v3_1.taskContext.ctx;
|
|
487
498
|
if (!ctx) {
|
|
488
499
|
throw new Error("batchTriggerAndWait can only be used from inside a task.run()");
|
|
489
500
|
}
|
|
490
|
-
const apiClient = v3_1.apiClientManager.clientOrThrow();
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
501
|
+
const apiClient = v3_1.apiClientManager.clientOrThrow(requestOptions?.clientConfig);
|
|
502
|
+
// Check if items is an array or a stream
|
|
503
|
+
if (Array.isArray(items)) {
|
|
504
|
+
// Array path: existing logic
|
|
505
|
+
const ndJsonItems = await Promise.all(items.map(async (item, index) => {
|
|
506
|
+
const taskMetadata = v3_1.resourceCatalog.getTask(item.id);
|
|
507
|
+
const parsedPayload = taskMetadata?.fns.parsePayload
|
|
508
|
+
? await taskMetadata?.fns.parsePayload(item.payload)
|
|
509
|
+
: item.payload;
|
|
510
|
+
const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
|
|
511
|
+
const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
|
|
512
|
+
return {
|
|
513
|
+
index,
|
|
514
|
+
task: item.id,
|
|
515
|
+
payload: payloadPacket.data,
|
|
516
|
+
options: {
|
|
517
|
+
lockToVersion: v3_1.taskContext.worker?.version,
|
|
518
|
+
...triggerQueueBody(item.options?.queue),
|
|
519
|
+
...(0, concurrency_shared_js_1.triggerConcurrencyBody)(item.options?.concurrency),
|
|
520
|
+
concurrencyKey: item.options?.concurrencyKey,
|
|
521
|
+
test: v3_1.taskContext.ctx?.run.isTest,
|
|
522
|
+
payloadType: payloadPacket.dataType,
|
|
523
|
+
delay: item.options?.delay,
|
|
524
|
+
ttl: item.options?.ttl,
|
|
525
|
+
tags: item.options?.tags,
|
|
526
|
+
maxAttempts: item.options?.maxAttempts,
|
|
527
|
+
metadata: item.options?.metadata,
|
|
528
|
+
maxDuration: item.options?.maxDuration,
|
|
529
|
+
idempotencyKey: (await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey)) ?? batchItemIdempotencyKey,
|
|
530
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
531
|
+
machine: item.options?.machine,
|
|
532
|
+
priority: item.options?.priority,
|
|
533
|
+
region: item.options?.region,
|
|
534
|
+
debounce: item.options?.debounce,
|
|
535
|
+
},
|
|
536
|
+
};
|
|
537
|
+
}));
|
|
538
|
+
return await tracer_js_1.tracer.startActiveSpan("batch.triggerAndWait()", async (span) => {
|
|
539
|
+
// Execute 2-phase batch
|
|
540
|
+
const response = await executeBatchTwoPhase(apiClient, ndJsonItems, {
|
|
541
|
+
parentRunId: ctx.run.id,
|
|
542
|
+
resumeParentOnCompletion: true,
|
|
543
|
+
idempotencyKey: await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey),
|
|
544
|
+
spanParentAsLink: false, // Waiting: child runs share parent's trace ID
|
|
545
|
+
}, requestOptions);
|
|
546
|
+
span.setAttribute("batchId", response.id);
|
|
547
|
+
span.setAttribute("runCount", response.runCount);
|
|
548
|
+
const result = await v3_1.runtime.waitForBatch({
|
|
549
|
+
id: response.id,
|
|
550
|
+
runCount: response.runCount,
|
|
551
|
+
ctx,
|
|
552
|
+
});
|
|
553
|
+
const runs = await handleBatchTaskRunExecutionResultV2(result.items, response.taskIdentifiers);
|
|
554
|
+
return {
|
|
555
|
+
id: result.id,
|
|
556
|
+
runs,
|
|
557
|
+
};
|
|
519
558
|
}, {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
span.setAttribute("isCached", response.isCached);
|
|
525
|
-
if (response.isCached) {
|
|
526
|
-
console.warn(`Result is a cached response because the request was idempotent.`);
|
|
527
|
-
}
|
|
528
|
-
if (response.idempotencyKey) {
|
|
529
|
-
span.setAttribute("idempotencyKey", response.idempotencyKey);
|
|
530
|
-
}
|
|
531
|
-
const result = await v3_1.runtime.waitForBatch({
|
|
532
|
-
id: response.id,
|
|
533
|
-
runs: response.runs.map((run) => run.id),
|
|
534
|
-
ctx,
|
|
559
|
+
kind: api_1.SpanKind.PRODUCER,
|
|
560
|
+
attributes: {
|
|
561
|
+
[v3_1.SemanticInternalAttributes.STYLE_ICON]: "trigger",
|
|
562
|
+
},
|
|
535
563
|
});
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
564
|
+
}
|
|
565
|
+
else {
|
|
566
|
+
// Stream path: convert to AsyncIterable and transform
|
|
567
|
+
const asyncItems = normalizeToAsyncIterable(items);
|
|
568
|
+
const transformedItems = transformBatchItemsStreamForWait(asyncItems, options);
|
|
569
|
+
return await tracer_js_1.tracer.startActiveSpan("batch.triggerAndWait()", async (span) => {
|
|
570
|
+
// Execute streaming 2-phase batch
|
|
571
|
+
const response = await executeBatchTwoPhaseStreaming(apiClient, transformedItems, {
|
|
572
|
+
parentRunId: ctx.run.id,
|
|
573
|
+
resumeParentOnCompletion: true,
|
|
574
|
+
idempotencyKey: await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey),
|
|
575
|
+
spanParentAsLink: false, // Waiting: child runs share parent's trace ID
|
|
576
|
+
}, requestOptions);
|
|
577
|
+
span.setAttribute("batchId", response.id);
|
|
578
|
+
span.setAttribute("runCount", response.runCount);
|
|
579
|
+
const result = await v3_1.runtime.waitForBatch({
|
|
580
|
+
id: response.id,
|
|
581
|
+
runCount: response.runCount,
|
|
582
|
+
ctx,
|
|
583
|
+
});
|
|
584
|
+
const runs = await handleBatchTaskRunExecutionResultV2(result.items, response.taskIdentifiers);
|
|
585
|
+
return {
|
|
586
|
+
id: result.id,
|
|
587
|
+
runs,
|
|
588
|
+
};
|
|
589
|
+
}, {
|
|
590
|
+
kind: api_1.SpanKind.PRODUCER,
|
|
591
|
+
attributes: {
|
|
592
|
+
[v3_1.SemanticInternalAttributes.STYLE_ICON]: "trigger",
|
|
593
|
+
},
|
|
594
|
+
});
|
|
595
|
+
}
|
|
547
596
|
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
* @returns {Promise<BatchByIdResult<TTask>>} A promise that resolves with the batch results, including
|
|
558
|
-
* success/failure status and strongly-typed outputs for each task
|
|
559
|
-
*
|
|
560
|
-
* @throws {Error} If called outside of a task.run() context
|
|
561
|
-
* @throws {Error} If no API client is configured
|
|
562
|
-
*
|
|
563
|
-
* @example
|
|
564
|
-
* ```ts
|
|
565
|
-
* import { batch, task } from "@trigger.dev/sdk/v3";
|
|
566
|
-
*
|
|
567
|
-
* export const parentTask = task({
|
|
568
|
-
* id: "parent-task",
|
|
569
|
-
* run: async (payload: string) => {
|
|
570
|
-
* const results = await batch.triggerAndWait<typeof childTask1 | typeof childTask2>([
|
|
571
|
-
* {
|
|
572
|
-
* id: "child-task-1",
|
|
573
|
-
* payload: { foo: "World" },
|
|
574
|
-
* options: {
|
|
575
|
-
* queue: "default",
|
|
576
|
-
* delay: "5m",
|
|
577
|
-
* tags: ["batch", "child1"]
|
|
578
|
-
* }
|
|
579
|
-
* },
|
|
580
|
-
* {
|
|
581
|
-
* id: "child-task-2",
|
|
582
|
-
* payload: { bar: 42 }
|
|
583
|
-
* }
|
|
584
|
-
* ]);
|
|
585
|
-
*
|
|
586
|
-
* // Type-safe result handling
|
|
587
|
-
* for (const result of results) {
|
|
588
|
-
* if (result.ok) {
|
|
589
|
-
* switch (result.taskIdentifier) {
|
|
590
|
-
* case "child-task-1":
|
|
591
|
-
* console.log("Child task 1 output:", result.output); // string type
|
|
592
|
-
* break;
|
|
593
|
-
* case "child-task-2":
|
|
594
|
-
* console.log("Child task 2 output:", result.output); // number type
|
|
595
|
-
* break;
|
|
596
|
-
* }
|
|
597
|
-
* } else {
|
|
598
|
-
* console.error("Task failed:", result.error);
|
|
599
|
-
* }
|
|
600
|
-
* }
|
|
601
|
-
* }
|
|
602
|
-
* });
|
|
603
|
-
* ```
|
|
604
|
-
*
|
|
605
|
-
* @description
|
|
606
|
-
* Each task item in the array can include:
|
|
607
|
-
* - `id`: The task identifier (must match one of the tasks in the union type)
|
|
608
|
-
* - `payload`: Strongly-typed payload matching the task's input type
|
|
609
|
-
* - `options`: Optional task-specific settings including:
|
|
610
|
-
* - `queue`: Specify a queue for the task
|
|
611
|
-
* - `concurrencyKey`: Control concurrent execution
|
|
612
|
-
* - `delay`: Delay before task execution
|
|
613
|
-
* - `ttl`: Time-to-live for the task
|
|
614
|
-
* - `tags`: Array of tags for the task
|
|
615
|
-
* - `maxAttempts`: Maximum retry attempts
|
|
616
|
-
* - `metadata`: Additional metadata
|
|
617
|
-
* - `maxDuration`: Maximum execution duration
|
|
618
|
-
*
|
|
619
|
-
* The function provides full type safety for:
|
|
620
|
-
* - Task IDs
|
|
621
|
-
* - Payload types
|
|
622
|
-
* - Return value types
|
|
623
|
-
* - Error handling
|
|
624
|
-
*/
|
|
625
|
-
async function batchTriggerTasks(items, options, requestOptions) {
|
|
626
|
-
const apiClient = v3_1.apiClientManager.clientOrThrow();
|
|
627
|
-
const response = await apiClient.batchTriggerV2({
|
|
628
|
-
items: await Promise.all(items.map(async (item) => {
|
|
629
|
-
const taskMetadata = v3_1.taskCatalog.getTask(item.task.id);
|
|
597
|
+
// Implementation
|
|
598
|
+
async function batchTriggerTasks(...args) {
|
|
599
|
+
const [items, options, requestOptions] = args;
|
|
600
|
+
const apiClient = v3_1.apiClientManager.clientOrThrow(requestOptions?.clientConfig);
|
|
601
|
+
// Check if items is an array or a stream
|
|
602
|
+
if (Array.isArray(items)) {
|
|
603
|
+
// Array path: existing logic
|
|
604
|
+
const ndJsonItems = await Promise.all(items.map(async (item, index) => {
|
|
605
|
+
const taskMetadata = v3_1.resourceCatalog.getTask(item.task.id);
|
|
630
606
|
const parsedPayload = taskMetadata?.fns.parsePayload
|
|
631
607
|
? await taskMetadata?.fns.parsePayload(item.payload)
|
|
632
608
|
: item.payload;
|
|
633
609
|
const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
|
|
610
|
+
const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
|
|
634
611
|
return {
|
|
612
|
+
index,
|
|
635
613
|
task: item.task.id,
|
|
636
614
|
payload: payloadPacket.data,
|
|
637
615
|
options: {
|
|
638
|
-
|
|
616
|
+
...triggerQueueBody(item.options?.queue),
|
|
617
|
+
...(0, concurrency_shared_js_1.triggerConcurrencyBody)(item.options?.concurrency),
|
|
639
618
|
concurrencyKey: item.options?.concurrencyKey,
|
|
640
619
|
test: v3_1.taskContext.ctx?.run.isTest,
|
|
641
620
|
payloadType: payloadPacket.dataType,
|
|
642
|
-
idempotencyKey: await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey),
|
|
643
|
-
idempotencyKeyTTL: item.options?.idempotencyKeyTTL,
|
|
644
621
|
delay: item.options?.delay,
|
|
645
622
|
ttl: item.options?.ttl,
|
|
646
623
|
tags: item.options?.tags,
|
|
647
624
|
maxAttempts: item.options?.maxAttempts,
|
|
648
|
-
parentAttempt: v3_1.taskContext.ctx?.attempt.id,
|
|
649
625
|
metadata: item.options?.metadata,
|
|
650
626
|
maxDuration: item.options?.maxDuration,
|
|
627
|
+
idempotencyKey: (await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey)) ?? batchItemIdempotencyKey,
|
|
628
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
651
629
|
machine: item.options?.machine,
|
|
630
|
+
priority: item.options?.priority,
|
|
631
|
+
region: item.options?.region,
|
|
632
|
+
lockToVersion: item.options?.version ?? (0, externalDeploymentId_js_1.scopedEnvVar)("TRIGGER_VERSION"),
|
|
633
|
+
externalDeploymentId: (0, externalDeploymentId_js_1.resolveTriggerExternalDeploymentId)(item.options?.externalDeploymentId),
|
|
634
|
+
debounce: item.options?.debounce,
|
|
652
635
|
},
|
|
653
636
|
};
|
|
654
|
-
}))
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
637
|
+
}));
|
|
638
|
+
// Execute 2-phase batch
|
|
639
|
+
const response = await tracer_js_1.tracer.startActiveSpan("batch.triggerByTask()", async (span) => {
|
|
640
|
+
const result = await executeBatchTwoPhase(apiClient, ndJsonItems, {
|
|
641
|
+
parentRunId: v3_1.taskContext.ctx?.run.id,
|
|
642
|
+
idempotencyKey: await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey),
|
|
643
|
+
spanParentAsLink: true, // Fire-and-forget: child runs get separate trace IDs
|
|
644
|
+
}, requestOptions);
|
|
645
|
+
span.setAttribute("batchId", result.id);
|
|
646
|
+
span.setAttribute("runCount", result.runCount);
|
|
647
|
+
return result;
|
|
648
|
+
}, {
|
|
649
|
+
kind: api_1.SpanKind.PRODUCER,
|
|
650
|
+
attributes: {
|
|
651
|
+
[v3_1.SemanticInternalAttributes.STYLE_ICON]: "trigger",
|
|
652
|
+
},
|
|
653
|
+
});
|
|
654
|
+
const handle = {
|
|
655
|
+
batchId: response.id,
|
|
656
|
+
runCount: response.runCount,
|
|
657
|
+
publicAccessToken: response.publicAccessToken,
|
|
658
|
+
};
|
|
659
|
+
return handle;
|
|
660
|
+
}
|
|
661
|
+
else {
|
|
662
|
+
// Stream path: convert to AsyncIterable and transform
|
|
663
|
+
const streamItems = items;
|
|
664
|
+
const asyncItems = normalizeToAsyncIterable(streamItems);
|
|
665
|
+
const transformedItems = transformBatchByTaskItemsStream(asyncItems, options);
|
|
666
|
+
// Execute streaming 2-phase batch
|
|
667
|
+
const response = await tracer_js_1.tracer.startActiveSpan("batch.triggerByTask()", async (span) => {
|
|
668
|
+
const result = await executeBatchTwoPhaseStreaming(apiClient, transformedItems, {
|
|
669
|
+
parentRunId: v3_1.taskContext.ctx?.run.id,
|
|
670
|
+
idempotencyKey: await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey),
|
|
671
|
+
spanParentAsLink: true, // Fire-and-forget: child runs get separate trace IDs
|
|
672
|
+
}, requestOptions);
|
|
673
|
+
span.setAttribute("batchId", result.id);
|
|
674
|
+
span.setAttribute("runCount", result.runCount);
|
|
675
|
+
return result;
|
|
676
|
+
}, {
|
|
677
|
+
kind: api_1.SpanKind.PRODUCER,
|
|
678
|
+
attributes: {
|
|
679
|
+
[v3_1.SemanticInternalAttributes.STYLE_ICON]: "trigger",
|
|
680
|
+
},
|
|
681
|
+
});
|
|
682
|
+
const handle = {
|
|
683
|
+
batchId: response.id,
|
|
684
|
+
runCount: response.runCount,
|
|
685
|
+
publicAccessToken: response.publicAccessToken,
|
|
686
|
+
};
|
|
687
|
+
return handle;
|
|
688
|
+
}
|
|
693
689
|
}
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
690
|
+
// Implementation
|
|
691
|
+
async function batchTriggerAndWaitTasks(...args) {
|
|
692
|
+
const [items, options, requestOptions] = args;
|
|
693
|
+
const ctx = v3_1.taskContext.ctx;
|
|
694
|
+
if (!ctx) {
|
|
695
|
+
throw new Error("batchTriggerAndWait can only be used from inside a task.run()");
|
|
696
|
+
}
|
|
697
|
+
const apiClient = v3_1.apiClientManager.clientOrThrow(requestOptions?.clientConfig);
|
|
698
|
+
// Check if items is an array or a stream
|
|
699
|
+
if (Array.isArray(items)) {
|
|
700
|
+
// Array path: existing logic
|
|
701
|
+
const ndJsonItems = await Promise.all(items.map(async (item, index) => {
|
|
702
|
+
const taskMetadata = v3_1.resourceCatalog.getTask(item.task.id);
|
|
703
|
+
const parsedPayload = taskMetadata?.fns.parsePayload
|
|
704
|
+
? await taskMetadata?.fns.parsePayload(item.payload)
|
|
705
|
+
: item.payload;
|
|
706
|
+
const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
|
|
707
|
+
const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
|
|
708
|
+
return {
|
|
709
|
+
index,
|
|
710
|
+
task: item.task.id,
|
|
711
|
+
payload: payloadPacket.data,
|
|
712
|
+
options: {
|
|
713
|
+
lockToVersion: v3_1.taskContext.worker?.version,
|
|
714
|
+
...triggerQueueBody(item.options?.queue),
|
|
715
|
+
...(0, concurrency_shared_js_1.triggerConcurrencyBody)(item.options?.concurrency),
|
|
716
|
+
concurrencyKey: item.options?.concurrencyKey,
|
|
717
|
+
test: v3_1.taskContext.ctx?.run.isTest,
|
|
718
|
+
payloadType: payloadPacket.dataType,
|
|
719
|
+
delay: item.options?.delay,
|
|
720
|
+
ttl: item.options?.ttl,
|
|
721
|
+
tags: item.options?.tags,
|
|
722
|
+
maxAttempts: item.options?.maxAttempts,
|
|
723
|
+
metadata: item.options?.metadata,
|
|
724
|
+
maxDuration: item.options?.maxDuration,
|
|
725
|
+
idempotencyKey: (await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey)) ?? batchItemIdempotencyKey,
|
|
726
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
727
|
+
machine: item.options?.machine,
|
|
728
|
+
priority: item.options?.priority,
|
|
729
|
+
region: item.options?.region,
|
|
730
|
+
debounce: item.options?.debounce,
|
|
731
|
+
},
|
|
732
|
+
};
|
|
733
|
+
}));
|
|
734
|
+
return await tracer_js_1.tracer.startActiveSpan("batch.triggerByTaskAndWait()", async (span) => {
|
|
735
|
+
// Execute 2-phase batch
|
|
736
|
+
const response = await executeBatchTwoPhase(apiClient, ndJsonItems, {
|
|
737
|
+
parentRunId: ctx.run.id,
|
|
738
|
+
resumeParentOnCompletion: true,
|
|
739
|
+
idempotencyKey: await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey),
|
|
740
|
+
spanParentAsLink: false, // Waiting: child runs share parent's trace ID
|
|
741
|
+
}, requestOptions);
|
|
742
|
+
span.setAttribute("batchId", response.id);
|
|
743
|
+
span.setAttribute("runCount", response.runCount);
|
|
744
|
+
const result = await v3_1.runtime.waitForBatch({
|
|
745
|
+
id: response.id,
|
|
746
|
+
runCount: response.runCount,
|
|
747
|
+
ctx,
|
|
748
|
+
});
|
|
749
|
+
const runs = await handleBatchTaskRunExecutionResultV2(result.items, response.taskIdentifiers);
|
|
750
|
+
return {
|
|
751
|
+
id: result.id,
|
|
752
|
+
runs,
|
|
753
|
+
};
|
|
754
|
+
}, {
|
|
755
|
+
kind: api_1.SpanKind.PRODUCER,
|
|
756
|
+
attributes: {
|
|
757
|
+
[v3_1.SemanticInternalAttributes.STYLE_ICON]: "trigger",
|
|
758
|
+
},
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
else {
|
|
762
|
+
// Stream path: convert to AsyncIterable and transform
|
|
763
|
+
const streamItems = items;
|
|
764
|
+
const asyncItems = normalizeToAsyncIterable(streamItems);
|
|
765
|
+
const transformedItems = transformBatchByTaskItemsStreamForWait(asyncItems, options);
|
|
766
|
+
return await tracer_js_1.tracer.startActiveSpan("batch.triggerByTaskAndWait()", async (span) => {
|
|
767
|
+
// Execute streaming 2-phase batch
|
|
768
|
+
const response = await executeBatchTwoPhaseStreaming(apiClient, transformedItems, {
|
|
769
|
+
parentRunId: ctx.run.id,
|
|
770
|
+
resumeParentOnCompletion: true,
|
|
771
|
+
idempotencyKey: await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey),
|
|
772
|
+
spanParentAsLink: false, // Waiting: child runs share parent's trace ID
|
|
773
|
+
}, requestOptions);
|
|
774
|
+
span.setAttribute("batchId", response.id);
|
|
775
|
+
span.setAttribute("runCount", response.runCount);
|
|
776
|
+
const result = await v3_1.runtime.waitForBatch({
|
|
777
|
+
id: response.id,
|
|
778
|
+
runCount: response.runCount,
|
|
779
|
+
ctx,
|
|
780
|
+
});
|
|
781
|
+
const runs = await handleBatchTaskRunExecutionResultV2(result.items, response.taskIdentifiers);
|
|
782
|
+
return {
|
|
783
|
+
id: result.id,
|
|
784
|
+
runs,
|
|
785
|
+
};
|
|
786
|
+
}, {
|
|
787
|
+
kind: api_1.SpanKind.PRODUCER,
|
|
788
|
+
attributes: {
|
|
789
|
+
[v3_1.SemanticInternalAttributes.STYLE_ICON]: "trigger",
|
|
790
|
+
},
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
function uniqueBatchTaskIdentifiers(items) {
|
|
795
|
+
return Array.from(new Set(items.map((item) => item.task))).sort();
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* Helper function that executes a 2-phase batch trigger:
|
|
799
|
+
* 1. Creates the batch record with expected run count
|
|
800
|
+
* 2. Streams items as NDJSON to the server
|
|
712
801
|
*
|
|
713
|
-
*
|
|
714
|
-
*
|
|
715
|
-
*
|
|
716
|
-
*
|
|
717
|
-
*
|
|
718
|
-
*
|
|
719
|
-
*
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
802
|
+
* @param apiClient - The API client instance
|
|
803
|
+
* @param items - Array of batch items
|
|
804
|
+
* @param options - Batch options including trace context settings
|
|
805
|
+
* @param options.spanParentAsLink - If true, child runs will have separate trace IDs with a link to parent.
|
|
806
|
+
* Use true for batchTrigger (fire-and-forget), false for batchTriggerAndWait.
|
|
807
|
+
* @param requestOptions - Optional request options
|
|
808
|
+
* @internal
|
|
809
|
+
*/
|
|
810
|
+
async function executeBatchTwoPhase(apiClient, items, options, requestOptions) {
|
|
811
|
+
// Offload any oversized per-item payloads to object storage before streaming, so a batch
|
|
812
|
+
// of large items keeps the request body small — the same treatment single triggers get.
|
|
813
|
+
// Both the array and streaming batch paths funnel through here, so this is the one place
|
|
814
|
+
// batch offloading needs to happen. Wrap failures so a presign/upload error carries the
|
|
815
|
+
// same batch context (phase, itemCount, rate-limit info) as the create/stream phases.
|
|
816
|
+
try {
|
|
817
|
+
items = await offloadBatchItemPayloads(items, apiClient);
|
|
818
|
+
}
|
|
819
|
+
catch (error) {
|
|
820
|
+
throw new BatchTriggerError(`Failed to offload payloads for batch with ${items.length} items`, {
|
|
821
|
+
cause: error,
|
|
822
|
+
phase: "offload",
|
|
823
|
+
itemCount: items.length,
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
let batch;
|
|
827
|
+
try {
|
|
828
|
+
// Phase 1: Create batch
|
|
829
|
+
batch = await apiClient.createBatch({
|
|
830
|
+
runCount: items.length,
|
|
831
|
+
taskIdentifiers: uniqueBatchTaskIdentifiers(items),
|
|
832
|
+
parentRunId: options.parentRunId,
|
|
833
|
+
resumeParentOnCompletion: options.resumeParentOnCompletion,
|
|
834
|
+
idempotencyKey: options.idempotencyKey,
|
|
835
|
+
idempotencyKeyOptions: options.idempotencyKeyOptions,
|
|
836
|
+
}, { spanParentAsLink: options.spanParentAsLink }, requestOptions);
|
|
837
|
+
}
|
|
838
|
+
catch (error) {
|
|
839
|
+
// Wrap with context about which phase failed
|
|
840
|
+
throw new BatchTriggerError(`Failed to create batch with ${items.length} items`, {
|
|
841
|
+
cause: error,
|
|
842
|
+
phase: "create",
|
|
843
|
+
itemCount: items.length,
|
|
844
|
+
});
|
|
845
|
+
}
|
|
846
|
+
// If the batch was cached (idempotent replay), skip streaming items
|
|
847
|
+
if (!batch.isCached) {
|
|
848
|
+
try {
|
|
849
|
+
// Phase 2: Stream items
|
|
850
|
+
await apiClient.streamBatchItems(batch.id, items, requestOptions);
|
|
851
|
+
}
|
|
852
|
+
catch (error) {
|
|
853
|
+
// Wrap with context about which phase failed and include batch ID
|
|
854
|
+
throw new BatchTriggerError(`Failed to stream items for batch ${batch.id} (${items.length} items)`, { cause: error, phase: "stream", batchId: batch.id, itemCount: items.length });
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
return {
|
|
858
|
+
id: batch.id,
|
|
859
|
+
runCount: batch.runCount,
|
|
860
|
+
publicAccessToken: batch.publicAccessToken,
|
|
861
|
+
taskIdentifiers: items.map((item) => item.task),
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
/**
|
|
865
|
+
* Offload any oversized per-item payloads in a batch to object storage, mirroring the
|
|
866
|
+
* single-trigger offload path. Small payloads pass through untouched. Every returned item
|
|
867
|
+
* carries `options.payloadSize` (the pre-offload serialized byte size) so the pipeline can
|
|
868
|
+
* reason about payload size without downloading an "application/store" reference.
|
|
731
869
|
*
|
|
732
|
-
*
|
|
733
|
-
*
|
|
734
|
-
* if (result.ok) {
|
|
735
|
-
* switch (result.taskIdentifier) {
|
|
736
|
-
* case "child-task-1":
|
|
737
|
-
* console.log("Child task 1 output:", result.output); // string type
|
|
738
|
-
* break;
|
|
739
|
-
* case "child-task-2":
|
|
740
|
-
* console.log("Child task 2 output:", result.output); // number type
|
|
741
|
-
* break;
|
|
742
|
-
* }
|
|
743
|
-
* } else {
|
|
744
|
-
* console.error("Task failed:", result.error);
|
|
745
|
-
* }
|
|
746
|
-
* }
|
|
747
|
-
* }
|
|
748
|
-
* });
|
|
749
|
-
* ```
|
|
870
|
+
* Uploads run with bounded concurrency so a batch of large items doesn't fire an unbounded
|
|
871
|
+
* number of simultaneous presigned PUTs.
|
|
750
872
|
*
|
|
751
|
-
* @
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
873
|
+
* @internal Exported for testing.
|
|
874
|
+
*/
|
|
875
|
+
async function offloadBatchItemPayloads(items, apiClient, concurrency = 10) {
|
|
876
|
+
if (items.length === 0) {
|
|
877
|
+
return items;
|
|
878
|
+
}
|
|
879
|
+
const results = new Array(items.length);
|
|
880
|
+
let cursor = 0;
|
|
881
|
+
async function worker() {
|
|
882
|
+
while (cursor < items.length) {
|
|
883
|
+
const index = cursor++;
|
|
884
|
+
results[index] = await offloadBatchItemPayload(items[index], apiClient);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, items.length) }, () => worker()));
|
|
888
|
+
return results;
|
|
889
|
+
}
|
|
890
|
+
async function offloadBatchItemPayload(item, apiClient) {
|
|
891
|
+
// The batch builders serialize each payload to a string via stringifyIO before we get
|
|
892
|
+
// here; anything else has no inline body to offload or measure.
|
|
893
|
+
if (typeof item.payload !== "string" || item.payload.length === 0) {
|
|
894
|
+
return item;
|
|
895
|
+
}
|
|
896
|
+
const dataType = item.options?.payloadType ?? "application/json";
|
|
897
|
+
// Already an object-store reference — the caller pre-offloaded it, nothing to do.
|
|
898
|
+
if (dataType === "application/store") {
|
|
899
|
+
return item;
|
|
900
|
+
}
|
|
901
|
+
const packet = { data: item.payload, dataType };
|
|
902
|
+
// Measure before offload so the size reflects the real payload, not the small reference
|
|
903
|
+
// we may replace it with.
|
|
904
|
+
const { size: payloadSize } = (0, v3_1.packetRequiresOffloading)(packet);
|
|
905
|
+
const exported = await (0, v3_1.conditionallyExportPacket)(packet, createTriggerPayloadPathPrefix(), undefined, apiClient);
|
|
906
|
+
return {
|
|
907
|
+
...item,
|
|
908
|
+
payload: exported.data,
|
|
909
|
+
options: {
|
|
910
|
+
...item.options,
|
|
911
|
+
payloadType: exported.dataType,
|
|
912
|
+
payloadSize,
|
|
913
|
+
},
|
|
914
|
+
};
|
|
915
|
+
}
|
|
916
|
+
/**
|
|
917
|
+
* Error thrown when batch trigger operations fail.
|
|
918
|
+
* Includes context about which phase failed and the batch details.
|
|
764
919
|
*
|
|
765
|
-
*
|
|
766
|
-
* -
|
|
767
|
-
* -
|
|
768
|
-
* - Return value types
|
|
769
|
-
* - Error handling
|
|
920
|
+
* When the underlying error is a rate limit (429), additional properties are exposed:
|
|
921
|
+
* - `isRateLimited`: true
|
|
922
|
+
* - `retryAfterMs`: milliseconds until the rate limit resets
|
|
770
923
|
*/
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
924
|
+
class BatchTriggerError extends Error {
|
|
925
|
+
phase;
|
|
926
|
+
batchId;
|
|
927
|
+
itemCount;
|
|
928
|
+
/** True if the error was caused by rate limiting (HTTP 429) */
|
|
929
|
+
isRateLimited;
|
|
930
|
+
/** Milliseconds until the rate limit resets. Only set when `isRateLimited` is true. */
|
|
931
|
+
retryAfterMs;
|
|
932
|
+
/** The underlying API error, if the cause was an ApiError */
|
|
933
|
+
apiError;
|
|
934
|
+
/** The underlying cause of the error */
|
|
935
|
+
cause;
|
|
936
|
+
constructor(message, options) {
|
|
937
|
+
// Build enhanced message that includes the cause's message
|
|
938
|
+
const fullMessage = buildBatchErrorMessage(message, options.cause);
|
|
939
|
+
super(fullMessage, { cause: options.cause });
|
|
940
|
+
this.name = "BatchTriggerError";
|
|
941
|
+
this.cause = options.cause;
|
|
942
|
+
this.phase = options.phase;
|
|
943
|
+
this.batchId = options.batchId;
|
|
944
|
+
this.itemCount = options.itemCount;
|
|
945
|
+
// Extract rate limit info from cause
|
|
946
|
+
if (options.cause instanceof v3_1.RateLimitError) {
|
|
947
|
+
this.isRateLimited = true;
|
|
948
|
+
this.retryAfterMs = options.cause.millisecondsUntilReset;
|
|
949
|
+
this.apiError = options.cause;
|
|
950
|
+
}
|
|
951
|
+
else if (options.cause instanceof v3_1.ApiError) {
|
|
952
|
+
this.isRateLimited = options.cause.status === 429;
|
|
953
|
+
this.apiError = options.cause;
|
|
954
|
+
}
|
|
955
|
+
else {
|
|
956
|
+
this.isRateLimited = false;
|
|
957
|
+
}
|
|
775
958
|
}
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
concurrencyKey: item.options?.concurrencyKey,
|
|
792
|
-
test: v3_1.taskContext.ctx?.run.isTest,
|
|
793
|
-
payloadType: payloadPacket.dataType,
|
|
794
|
-
delay: item.options?.delay,
|
|
795
|
-
ttl: item.options?.ttl,
|
|
796
|
-
tags: item.options?.tags,
|
|
797
|
-
maxAttempts: item.options?.maxAttempts,
|
|
798
|
-
metadata: item.options?.metadata,
|
|
799
|
-
maxDuration: item.options?.maxDuration,
|
|
800
|
-
machine: item.options?.machine,
|
|
801
|
-
},
|
|
802
|
-
};
|
|
803
|
-
})),
|
|
804
|
-
dependentAttempt: ctx.attempt.id,
|
|
805
|
-
}, {
|
|
806
|
-
processingStrategy: options?.triggerSequentially ? "sequential" : undefined,
|
|
807
|
-
}, requestOptions);
|
|
808
|
-
span.setAttribute("batchId", response.id);
|
|
809
|
-
span.setAttribute("runCount", response.runs.length);
|
|
810
|
-
span.setAttribute("isCached", response.isCached);
|
|
811
|
-
if (response.isCached) {
|
|
812
|
-
console.warn(`Result is a cached response because the request was idempotent.`);
|
|
959
|
+
}
|
|
960
|
+
exports.BatchTriggerError = BatchTriggerError;
|
|
961
|
+
/**
|
|
962
|
+
* Build an enhanced error message that includes context from the cause.
|
|
963
|
+
*/
|
|
964
|
+
function buildBatchErrorMessage(baseMessage, cause) {
|
|
965
|
+
if (!cause) {
|
|
966
|
+
return baseMessage;
|
|
967
|
+
}
|
|
968
|
+
// Handle RateLimitError specifically for better messaging
|
|
969
|
+
if (cause instanceof v3_1.RateLimitError) {
|
|
970
|
+
const retryMs = cause.millisecondsUntilReset;
|
|
971
|
+
if (retryMs !== undefined) {
|
|
972
|
+
const retrySeconds = Math.ceil(retryMs / 1000);
|
|
973
|
+
return `${baseMessage}: Rate limit exceeded - retry after ${retrySeconds}s`;
|
|
813
974
|
}
|
|
814
|
-
|
|
815
|
-
|
|
975
|
+
return `${baseMessage}: Rate limit exceeded`;
|
|
976
|
+
}
|
|
977
|
+
// Handle other ApiErrors
|
|
978
|
+
if (cause instanceof v3_1.ApiError) {
|
|
979
|
+
return `${baseMessage}: ${cause.message}`;
|
|
980
|
+
}
|
|
981
|
+
// Handle generic errors
|
|
982
|
+
if (cause instanceof Error) {
|
|
983
|
+
return `${baseMessage}: ${cause.message}`;
|
|
984
|
+
}
|
|
985
|
+
return baseMessage;
|
|
986
|
+
}
|
|
987
|
+
/**
|
|
988
|
+
* Execute a streaming 2-phase batch trigger where items are streamed from an AsyncIterable.
|
|
989
|
+
* Unlike executeBatchTwoPhase, this doesn't know the count upfront.
|
|
990
|
+
*
|
|
991
|
+
* @param apiClient - The API client instance
|
|
992
|
+
* @param items - AsyncIterable of batch items
|
|
993
|
+
* @param options - Batch options including trace context settings
|
|
994
|
+
* @param options.spanParentAsLink - If true, child runs will have separate trace IDs with a link to parent.
|
|
995
|
+
* Use true for batchTrigger (fire-and-forget), false for batchTriggerAndWait.
|
|
996
|
+
* @param requestOptions - Optional request options
|
|
997
|
+
* @internal
|
|
998
|
+
*/
|
|
999
|
+
async function executeBatchTwoPhaseStreaming(apiClient, items, options, requestOptions) {
|
|
1000
|
+
// For streaming, we need to buffer items to get the count first
|
|
1001
|
+
// This is because createBatch requires runCount upfront
|
|
1002
|
+
// In the future, we could add a streaming-first endpoint that doesn't require this
|
|
1003
|
+
const itemsArray = [];
|
|
1004
|
+
for await (const item of items) {
|
|
1005
|
+
itemsArray.push(item);
|
|
1006
|
+
}
|
|
1007
|
+
// Now we can use the regular 2-phase approach
|
|
1008
|
+
return executeBatchTwoPhase(apiClient, itemsArray, options, requestOptions);
|
|
1009
|
+
}
|
|
1010
|
+
/**
|
|
1011
|
+
* Type guard to check if a value is a ReadableStream
|
|
1012
|
+
*/
|
|
1013
|
+
function isReadableStream(value) {
|
|
1014
|
+
return (value != null &&
|
|
1015
|
+
typeof value === "object" &&
|
|
1016
|
+
"getReader" in value &&
|
|
1017
|
+
typeof value.getReader === "function");
|
|
1018
|
+
}
|
|
1019
|
+
/**
|
|
1020
|
+
* Convert a ReadableStream to an AsyncIterable.
|
|
1021
|
+
* Properly cancels the stream when the consumer terminates early.
|
|
1022
|
+
*
|
|
1023
|
+
* @internal Exported for testing purposes
|
|
1024
|
+
*/
|
|
1025
|
+
async function* readableStreamToAsyncIterable(stream) {
|
|
1026
|
+
const reader = stream.getReader();
|
|
1027
|
+
try {
|
|
1028
|
+
while (true) {
|
|
1029
|
+
const { done, value } = await reader.read();
|
|
1030
|
+
if (done)
|
|
1031
|
+
break;
|
|
1032
|
+
yield value;
|
|
816
1033
|
}
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
1034
|
+
}
|
|
1035
|
+
finally {
|
|
1036
|
+
try {
|
|
1037
|
+
await reader.cancel();
|
|
1038
|
+
}
|
|
1039
|
+
catch {
|
|
1040
|
+
// Ignore errors - stream might already be errored or closed
|
|
1041
|
+
}
|
|
1042
|
+
reader.releaseLock();
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
/**
|
|
1046
|
+
* Normalize stream input to AsyncIterable
|
|
1047
|
+
*/
|
|
1048
|
+
function normalizeToAsyncIterable(input) {
|
|
1049
|
+
if (isReadableStream(input)) {
|
|
1050
|
+
return readableStreamToAsyncIterable(input);
|
|
1051
|
+
}
|
|
1052
|
+
return input;
|
|
1053
|
+
}
|
|
1054
|
+
/**
|
|
1055
|
+
* Transform a stream of BatchByIdItem to BatchItemNDJSON format.
|
|
1056
|
+
* Handles payload serialization and idempotency key generation.
|
|
1057
|
+
*
|
|
1058
|
+
* @internal
|
|
1059
|
+
*/
|
|
1060
|
+
async function* transformBatchItemsStream(items, options) {
|
|
1061
|
+
let index = 0;
|
|
1062
|
+
for await (const item of items) {
|
|
1063
|
+
const taskMetadata = v3_1.resourceCatalog.getTask(item.id);
|
|
1064
|
+
const parsedPayload = taskMetadata?.fns.parsePayload
|
|
1065
|
+
? await taskMetadata?.fns.parsePayload(item.payload)
|
|
1066
|
+
: item.payload;
|
|
1067
|
+
const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
|
|
1068
|
+
const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
|
|
1069
|
+
yield {
|
|
1070
|
+
index: index++,
|
|
1071
|
+
task: item.id,
|
|
1072
|
+
payload: payloadPacket.data,
|
|
1073
|
+
options: {
|
|
1074
|
+
...triggerQueueBody(item.options?.queue),
|
|
1075
|
+
...(0, concurrency_shared_js_1.triggerConcurrencyBody)(item.options?.concurrency),
|
|
1076
|
+
concurrencyKey: item.options?.concurrencyKey,
|
|
1077
|
+
test: v3_1.taskContext.ctx?.run.isTest,
|
|
1078
|
+
payloadType: payloadPacket.dataType,
|
|
1079
|
+
delay: item.options?.delay,
|
|
1080
|
+
ttl: item.options?.ttl,
|
|
1081
|
+
tags: item.options?.tags,
|
|
1082
|
+
maxAttempts: item.options?.maxAttempts,
|
|
1083
|
+
metadata: item.options?.metadata,
|
|
1084
|
+
maxDuration: item.options?.maxDuration,
|
|
1085
|
+
idempotencyKey: (await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey)) ?? batchItemIdempotencyKey,
|
|
1086
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
1087
|
+
machine: item.options?.machine,
|
|
1088
|
+
priority: item.options?.priority,
|
|
1089
|
+
region: item.options?.region,
|
|
1090
|
+
lockToVersion: item.options?.version ?? (0, externalDeploymentId_js_1.scopedEnvVar)("TRIGGER_VERSION"),
|
|
1091
|
+
externalDeploymentId: (0, externalDeploymentId_js_1.resolveTriggerExternalDeploymentId)(item.options?.externalDeploymentId),
|
|
1092
|
+
debounce: item.options?.debounce,
|
|
1093
|
+
},
|
|
826
1094
|
};
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
/**
|
|
1098
|
+
* Transform a stream of BatchByIdAndWaitItem to BatchItemNDJSON format for triggerAndWait.
|
|
1099
|
+
* Uses the current worker version for lockToVersion.
|
|
1100
|
+
*
|
|
1101
|
+
* @internal
|
|
1102
|
+
*/
|
|
1103
|
+
async function* transformBatchItemsStreamForWait(items, options) {
|
|
1104
|
+
let index = 0;
|
|
1105
|
+
for await (const item of items) {
|
|
1106
|
+
const taskMetadata = v3_1.resourceCatalog.getTask(item.id);
|
|
1107
|
+
const parsedPayload = taskMetadata?.fns.parsePayload
|
|
1108
|
+
? await taskMetadata?.fns.parsePayload(item.payload)
|
|
1109
|
+
: item.payload;
|
|
1110
|
+
const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
|
|
1111
|
+
const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
|
|
1112
|
+
yield {
|
|
1113
|
+
index: index++,
|
|
1114
|
+
task: item.id,
|
|
1115
|
+
payload: payloadPacket.data,
|
|
1116
|
+
options: {
|
|
1117
|
+
lockToVersion: v3_1.taskContext.worker?.version,
|
|
1118
|
+
...triggerQueueBody(item.options?.queue),
|
|
1119
|
+
...(0, concurrency_shared_js_1.triggerConcurrencyBody)(item.options?.concurrency),
|
|
1120
|
+
concurrencyKey: item.options?.concurrencyKey,
|
|
1121
|
+
test: v3_1.taskContext.ctx?.run.isTest,
|
|
1122
|
+
payloadType: payloadPacket.dataType,
|
|
1123
|
+
delay: item.options?.delay,
|
|
1124
|
+
ttl: item.options?.ttl,
|
|
1125
|
+
tags: item.options?.tags,
|
|
1126
|
+
maxAttempts: item.options?.maxAttempts,
|
|
1127
|
+
metadata: item.options?.metadata,
|
|
1128
|
+
maxDuration: item.options?.maxDuration,
|
|
1129
|
+
idempotencyKey: (await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey)) ?? batchItemIdempotencyKey,
|
|
1130
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
1131
|
+
machine: item.options?.machine,
|
|
1132
|
+
priority: item.options?.priority,
|
|
1133
|
+
region: item.options?.region,
|
|
1134
|
+
debounce: item.options?.debounce,
|
|
1135
|
+
},
|
|
1136
|
+
};
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
/**
|
|
1140
|
+
* Transform a stream of BatchByTaskItem to BatchItemNDJSON format.
|
|
1141
|
+
*
|
|
1142
|
+
* @internal
|
|
1143
|
+
*/
|
|
1144
|
+
async function* transformBatchByTaskItemsStream(items, options) {
|
|
1145
|
+
let index = 0;
|
|
1146
|
+
for await (const item of items) {
|
|
1147
|
+
const taskMetadata = v3_1.resourceCatalog.getTask(item.task.id);
|
|
1148
|
+
const parsedPayload = taskMetadata?.fns.parsePayload
|
|
1149
|
+
? await taskMetadata?.fns.parsePayload(item.payload)
|
|
1150
|
+
: item.payload;
|
|
1151
|
+
const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
|
|
1152
|
+
const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
|
|
1153
|
+
yield {
|
|
1154
|
+
index: index++,
|
|
1155
|
+
task: item.task.id,
|
|
1156
|
+
payload: payloadPacket.data,
|
|
1157
|
+
options: {
|
|
1158
|
+
...triggerQueueBody(item.options?.queue),
|
|
1159
|
+
...(0, concurrency_shared_js_1.triggerConcurrencyBody)(item.options?.concurrency),
|
|
1160
|
+
concurrencyKey: item.options?.concurrencyKey,
|
|
1161
|
+
test: v3_1.taskContext.ctx?.run.isTest,
|
|
1162
|
+
payloadType: payloadPacket.dataType,
|
|
1163
|
+
delay: item.options?.delay,
|
|
1164
|
+
ttl: item.options?.ttl,
|
|
1165
|
+
tags: item.options?.tags,
|
|
1166
|
+
maxAttempts: item.options?.maxAttempts,
|
|
1167
|
+
metadata: item.options?.metadata,
|
|
1168
|
+
maxDuration: item.options?.maxDuration,
|
|
1169
|
+
idempotencyKey: (await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey)) ?? batchItemIdempotencyKey,
|
|
1170
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
1171
|
+
machine: item.options?.machine,
|
|
1172
|
+
priority: item.options?.priority,
|
|
1173
|
+
region: item.options?.region,
|
|
1174
|
+
lockToVersion: item.options?.version ?? (0, externalDeploymentId_js_1.scopedEnvVar)("TRIGGER_VERSION"),
|
|
1175
|
+
externalDeploymentId: (0, externalDeploymentId_js_1.resolveTriggerExternalDeploymentId)(item.options?.externalDeploymentId),
|
|
1176
|
+
debounce: item.options?.debounce,
|
|
1177
|
+
},
|
|
1178
|
+
};
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
/**
|
|
1182
|
+
* Transform a stream of BatchByTaskAndWaitItem to BatchItemNDJSON format for triggerAndWait.
|
|
1183
|
+
*
|
|
1184
|
+
* @internal
|
|
1185
|
+
*/
|
|
1186
|
+
async function* transformBatchByTaskItemsStreamForWait(items, options) {
|
|
1187
|
+
let index = 0;
|
|
1188
|
+
for await (const item of items) {
|
|
1189
|
+
const taskMetadata = v3_1.resourceCatalog.getTask(item.task.id);
|
|
1190
|
+
const parsedPayload = taskMetadata?.fns.parsePayload
|
|
1191
|
+
? await taskMetadata?.fns.parsePayload(item.payload)
|
|
1192
|
+
: item.payload;
|
|
1193
|
+
const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
|
|
1194
|
+
const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
|
|
1195
|
+
yield {
|
|
1196
|
+
index: index++,
|
|
1197
|
+
task: item.task.id,
|
|
1198
|
+
payload: payloadPacket.data,
|
|
1199
|
+
options: {
|
|
1200
|
+
lockToVersion: v3_1.taskContext.worker?.version,
|
|
1201
|
+
...triggerQueueBody(item.options?.queue),
|
|
1202
|
+
...(0, concurrency_shared_js_1.triggerConcurrencyBody)(item.options?.concurrency),
|
|
1203
|
+
concurrencyKey: item.options?.concurrencyKey,
|
|
1204
|
+
test: v3_1.taskContext.ctx?.run.isTest,
|
|
1205
|
+
payloadType: payloadPacket.dataType,
|
|
1206
|
+
delay: item.options?.delay,
|
|
1207
|
+
ttl: item.options?.ttl,
|
|
1208
|
+
tags: item.options?.tags,
|
|
1209
|
+
maxAttempts: item.options?.maxAttempts,
|
|
1210
|
+
metadata: item.options?.metadata,
|
|
1211
|
+
maxDuration: item.options?.maxDuration,
|
|
1212
|
+
idempotencyKey: (await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey)) ?? batchItemIdempotencyKey,
|
|
1213
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
1214
|
+
machine: item.options?.machine,
|
|
1215
|
+
priority: item.options?.priority,
|
|
1216
|
+
region: item.options?.region,
|
|
1217
|
+
debounce: item.options?.debounce,
|
|
1218
|
+
},
|
|
1219
|
+
};
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
/**
|
|
1223
|
+
* Transform a stream of BatchItem (single task type) to BatchItemNDJSON format.
|
|
1224
|
+
*
|
|
1225
|
+
* @internal
|
|
1226
|
+
*/
|
|
1227
|
+
async function* transformSingleTaskBatchItemsStream(taskIdentifier, items, parsePayload, options, queue) {
|
|
1228
|
+
let index = 0;
|
|
1229
|
+
for await (const item of items) {
|
|
1230
|
+
const parsedPayload = parsePayload ? await parsePayload(item.payload) : item.payload;
|
|
1231
|
+
const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
|
|
1232
|
+
const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
|
|
1233
|
+
yield {
|
|
1234
|
+
index: index++,
|
|
1235
|
+
task: taskIdentifier,
|
|
1236
|
+
payload: payloadPacket.data,
|
|
1237
|
+
options: {
|
|
1238
|
+
...triggerQueueBody(item.options?.queue, queue),
|
|
1239
|
+
...(0, concurrency_shared_js_1.triggerConcurrencyBody)(item.options?.concurrency),
|
|
1240
|
+
concurrencyKey: item.options?.concurrencyKey,
|
|
1241
|
+
test: v3_1.taskContext.ctx?.run.isTest,
|
|
1242
|
+
payloadType: payloadPacket.dataType,
|
|
1243
|
+
delay: item.options?.delay,
|
|
1244
|
+
ttl: item.options?.ttl,
|
|
1245
|
+
tags: item.options?.tags,
|
|
1246
|
+
maxAttempts: item.options?.maxAttempts,
|
|
1247
|
+
metadata: item.options?.metadata,
|
|
1248
|
+
maxDuration: item.options?.maxDuration,
|
|
1249
|
+
idempotencyKey: (await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey)) ?? batchItemIdempotencyKey,
|
|
1250
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
1251
|
+
machine: item.options?.machine,
|
|
1252
|
+
priority: item.options?.priority,
|
|
1253
|
+
region: item.options?.region,
|
|
1254
|
+
lockToVersion: item.options?.version ?? (0, externalDeploymentId_js_1.scopedEnvVar)("TRIGGER_VERSION"),
|
|
1255
|
+
externalDeploymentId: (0, externalDeploymentId_js_1.resolveTriggerExternalDeploymentId)(item.options?.externalDeploymentId),
|
|
1256
|
+
debounce: item.options?.debounce,
|
|
1257
|
+
},
|
|
1258
|
+
};
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
/**
|
|
1262
|
+
* Transform a stream of BatchTriggerAndWaitItem (single task type) to BatchItemNDJSON format.
|
|
1263
|
+
*
|
|
1264
|
+
* @internal
|
|
1265
|
+
*/
|
|
1266
|
+
async function* transformSingleTaskBatchItemsStreamForWait(taskIdentifier, items, parsePayload, options, queue) {
|
|
1267
|
+
let index = 0;
|
|
1268
|
+
for await (const item of items) {
|
|
1269
|
+
const parsedPayload = parsePayload ? await parsePayload(item.payload) : item.payload;
|
|
1270
|
+
const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
|
|
1271
|
+
const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
|
|
1272
|
+
// Process item-specific idempotency key and extract options
|
|
1273
|
+
const itemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey);
|
|
1274
|
+
const finalIdempotencyKey = itemIdempotencyKey ?? batchItemIdempotencyKey;
|
|
1275
|
+
const idempotencyKeyOptions = itemIdempotencyKey
|
|
1276
|
+
? (0, v3_1.getIdempotencyKeyOptions)(itemIdempotencyKey)
|
|
1277
|
+
: undefined;
|
|
1278
|
+
yield {
|
|
1279
|
+
index: index++,
|
|
1280
|
+
task: taskIdentifier,
|
|
1281
|
+
payload: payloadPacket.data,
|
|
1282
|
+
options: {
|
|
1283
|
+
lockToVersion: v3_1.taskContext.worker?.version,
|
|
1284
|
+
...triggerQueueBody(item.options?.queue, queue),
|
|
1285
|
+
...(0, concurrency_shared_js_1.triggerConcurrencyBody)(item.options?.concurrency),
|
|
1286
|
+
concurrencyKey: item.options?.concurrencyKey,
|
|
1287
|
+
test: v3_1.taskContext.ctx?.run.isTest,
|
|
1288
|
+
payloadType: payloadPacket.dataType,
|
|
1289
|
+
delay: item.options?.delay,
|
|
1290
|
+
ttl: item.options?.ttl,
|
|
1291
|
+
tags: item.options?.tags,
|
|
1292
|
+
maxAttempts: item.options?.maxAttempts,
|
|
1293
|
+
metadata: item.options?.metadata,
|
|
1294
|
+
maxDuration: item.options?.maxDuration,
|
|
1295
|
+
idempotencyKey: finalIdempotencyKey?.toString(),
|
|
1296
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
1297
|
+
idempotencyKeyOptions,
|
|
1298
|
+
machine: item.options?.machine,
|
|
1299
|
+
priority: item.options?.priority,
|
|
1300
|
+
region: item.options?.region,
|
|
1301
|
+
debounce: item.options?.debounce,
|
|
1302
|
+
},
|
|
1303
|
+
};
|
|
1304
|
+
}
|
|
833
1305
|
}
|
|
834
1306
|
async function trigger_internal(name, id, payload, parsePayload, options, requestOptions) {
|
|
835
|
-
const apiClient = v3_1.apiClientManager.clientOrThrow();
|
|
1307
|
+
const apiClient = v3_1.apiClientManager.clientOrThrow(requestOptions?.clientConfig);
|
|
836
1308
|
const parsedPayload = parsePayload ? await parsePayload(payload) : payload;
|
|
837
|
-
const
|
|
1309
|
+
const { packet: triggerPayloadPacket, payloadSize } = await prepareTriggerPayload(parsedPayload, apiClient);
|
|
1310
|
+
// Process idempotency key and extract options for storage
|
|
1311
|
+
const processedIdempotencyKey = await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey);
|
|
1312
|
+
const idempotencyKeyOptions = processedIdempotencyKey
|
|
1313
|
+
? (0, v3_1.getIdempotencyKeyOptions)(processedIdempotencyKey)
|
|
1314
|
+
: undefined;
|
|
838
1315
|
const handle = await apiClient.triggerTask(id, {
|
|
839
|
-
payload:
|
|
1316
|
+
payload: triggerPayloadPacket.data,
|
|
840
1317
|
options: {
|
|
841
|
-
|
|
1318
|
+
...triggerQueueBody(options?.queue),
|
|
1319
|
+
...(0, concurrency_shared_js_1.triggerConcurrencyBody)(options?.concurrency),
|
|
842
1320
|
concurrencyKey: options?.concurrencyKey,
|
|
843
1321
|
test: v3_1.taskContext.ctx?.run.isTest,
|
|
844
|
-
payloadType:
|
|
845
|
-
|
|
1322
|
+
payloadType: triggerPayloadPacket.dataType,
|
|
1323
|
+
payloadSize,
|
|
1324
|
+
idempotencyKey: processedIdempotencyKey?.toString(),
|
|
846
1325
|
idempotencyKeyTTL: options?.idempotencyKeyTTL,
|
|
1326
|
+
idempotencyKeyOptions,
|
|
847
1327
|
delay: options?.delay,
|
|
848
1328
|
ttl: options?.ttl,
|
|
849
1329
|
tags: options?.tags,
|
|
850
1330
|
maxAttempts: options?.maxAttempts,
|
|
851
|
-
parentAttempt: v3_1.taskContext.ctx?.attempt.id,
|
|
852
1331
|
metadata: options?.metadata,
|
|
853
1332
|
maxDuration: options?.maxDuration,
|
|
1333
|
+
parentRunId: v3_1.taskContext.ctx?.run.id,
|
|
854
1334
|
machine: options?.machine,
|
|
1335
|
+
priority: options?.priority,
|
|
1336
|
+
region: options?.region,
|
|
1337
|
+
lockToVersion: options?.version ?? (0, externalDeploymentId_js_1.scopedEnvVar)("TRIGGER_VERSION"),
|
|
1338
|
+
externalDeploymentId: (0, externalDeploymentId_js_1.resolveTriggerExternalDeploymentId)(options?.externalDeploymentId),
|
|
1339
|
+
debounce: options?.debounce,
|
|
855
1340
|
},
|
|
856
1341
|
}, {
|
|
857
1342
|
spanParentAsLink: true,
|
|
@@ -871,96 +1356,169 @@ async function trigger_internal(name, id, payload, parsePayload, options, reques
|
|
|
871
1356
|
return handle;
|
|
872
1357
|
}
|
|
873
1358
|
async function batchTrigger_internal(name, taskIdentifier, items, options, parsePayload, requestOptions, queue) {
|
|
874
|
-
const apiClient = v3_1.apiClientManager.clientOrThrow();
|
|
875
|
-
const
|
|
876
|
-
|
|
1359
|
+
const apiClient = v3_1.apiClientManager.clientOrThrow(requestOptions?.clientConfig);
|
|
1360
|
+
const ctx = v3_1.taskContext.ctx;
|
|
1361
|
+
// Check if items is an array or a stream
|
|
1362
|
+
if (Array.isArray(items)) {
|
|
1363
|
+
// Prepare items as BatchItemNDJSON
|
|
1364
|
+
const ndJsonItems = await Promise.all(items.map(async (item, index) => {
|
|
877
1365
|
const parsedPayload = parsePayload ? await parsePayload(item.payload) : item.payload;
|
|
878
1366
|
const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
|
|
1367
|
+
const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
|
|
1368
|
+
// Process item-specific idempotency key and extract options
|
|
1369
|
+
const itemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey);
|
|
1370
|
+
const finalIdempotencyKey = itemIdempotencyKey ?? batchItemIdempotencyKey;
|
|
1371
|
+
const idempotencyKeyOptions = itemIdempotencyKey
|
|
1372
|
+
? (0, v3_1.getIdempotencyKeyOptions)(itemIdempotencyKey)
|
|
1373
|
+
: undefined;
|
|
879
1374
|
return {
|
|
1375
|
+
index,
|
|
880
1376
|
task: taskIdentifier,
|
|
881
1377
|
payload: payloadPacket.data,
|
|
882
1378
|
options: {
|
|
883
|
-
|
|
1379
|
+
...triggerQueueBody(item.options?.queue, queue),
|
|
1380
|
+
...(0, concurrency_shared_js_1.triggerConcurrencyBody)(item.options?.concurrency),
|
|
884
1381
|
concurrencyKey: item.options?.concurrencyKey,
|
|
885
1382
|
test: v3_1.taskContext.ctx?.run.isTest,
|
|
886
1383
|
payloadType: payloadPacket.dataType,
|
|
887
|
-
idempotencyKey: await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey),
|
|
888
|
-
idempotencyKeyTTL: item.options?.idempotencyKeyTTL,
|
|
889
1384
|
delay: item.options?.delay,
|
|
890
1385
|
ttl: item.options?.ttl,
|
|
891
1386
|
tags: item.options?.tags,
|
|
892
1387
|
maxAttempts: item.options?.maxAttempts,
|
|
893
|
-
parentAttempt: v3_1.taskContext.ctx?.attempt.id,
|
|
894
1388
|
metadata: item.options?.metadata,
|
|
895
1389
|
maxDuration: item.options?.maxDuration,
|
|
1390
|
+
idempotencyKey: finalIdempotencyKey?.toString(),
|
|
1391
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
1392
|
+
idempotencyKeyOptions,
|
|
896
1393
|
machine: item.options?.machine,
|
|
1394
|
+
priority: item.options?.priority,
|
|
1395
|
+
region: item.options?.region,
|
|
1396
|
+
lockToVersion: item.options?.version ?? (0, externalDeploymentId_js_1.scopedEnvVar)("TRIGGER_VERSION"),
|
|
1397
|
+
externalDeploymentId: (0, externalDeploymentId_js_1.resolveTriggerExternalDeploymentId)(item.options?.externalDeploymentId),
|
|
1398
|
+
debounce: item.options?.debounce,
|
|
897
1399
|
},
|
|
898
1400
|
};
|
|
899
|
-
}))
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
name,
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
1401
|
+
}));
|
|
1402
|
+
// Execute 2-phase batch
|
|
1403
|
+
// Process batch-level idempotency key
|
|
1404
|
+
const batchIdempotencyKey = await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey);
|
|
1405
|
+
const batchIdempotencyKeyOptions = batchIdempotencyKey
|
|
1406
|
+
? (0, v3_1.getIdempotencyKeyOptions)(batchIdempotencyKey)
|
|
1407
|
+
: undefined;
|
|
1408
|
+
const response = await tracer_js_1.tracer.startActiveSpan(name, async (span) => {
|
|
1409
|
+
const result = await executeBatchTwoPhase(apiClient, ndJsonItems, {
|
|
1410
|
+
parentRunId: ctx?.run.id,
|
|
1411
|
+
idempotencyKey: batchIdempotencyKey?.toString(),
|
|
1412
|
+
idempotencyKeyOptions: batchIdempotencyKeyOptions,
|
|
1413
|
+
spanParentAsLink: true, // Fire-and-forget: child runs get separate trace IDs
|
|
1414
|
+
}, requestOptions);
|
|
1415
|
+
span.setAttribute("batchId", result.id);
|
|
1416
|
+
span.setAttribute("runCount", result.runCount);
|
|
1417
|
+
return result;
|
|
1418
|
+
}, {
|
|
1419
|
+
kind: api_1.SpanKind.PRODUCER,
|
|
1420
|
+
attributes: {
|
|
1421
|
+
[v3_1.SemanticInternalAttributes.STYLE_ICON]: "trigger",
|
|
1422
|
+
...(0, v3_1.accessoryAttributes)({
|
|
1423
|
+
items: [
|
|
1424
|
+
{
|
|
1425
|
+
text: taskIdentifier,
|
|
1426
|
+
variant: "normal",
|
|
1427
|
+
},
|
|
1428
|
+
],
|
|
1429
|
+
style: "codepath",
|
|
1430
|
+
}),
|
|
1431
|
+
},
|
|
1432
|
+
});
|
|
1433
|
+
const handle = {
|
|
1434
|
+
batchId: response.id,
|
|
1435
|
+
runCount: response.runCount,
|
|
1436
|
+
publicAccessToken: response.publicAccessToken,
|
|
1437
|
+
};
|
|
1438
|
+
return handle;
|
|
1439
|
+
}
|
|
1440
|
+
else {
|
|
1441
|
+
// Stream path: convert to AsyncIterable and transform
|
|
1442
|
+
const asyncItems = normalizeToAsyncIterable(items);
|
|
1443
|
+
const transformedItems = transformSingleTaskBatchItemsStream(taskIdentifier, asyncItems, parsePayload, options, queue);
|
|
1444
|
+
// Execute streaming 2-phase batch
|
|
1445
|
+
// Process batch-level idempotency key
|
|
1446
|
+
const streamBatchIdempotencyKey = await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey);
|
|
1447
|
+
const streamBatchIdempotencyKeyOptions = streamBatchIdempotencyKey
|
|
1448
|
+
? (0, v3_1.getIdempotencyKeyOptions)(streamBatchIdempotencyKey)
|
|
1449
|
+
: undefined;
|
|
1450
|
+
const response = await tracer_js_1.tracer.startActiveSpan(name, async (span) => {
|
|
1451
|
+
const result = await executeBatchTwoPhaseStreaming(apiClient, transformedItems, {
|
|
1452
|
+
parentRunId: ctx?.run.id,
|
|
1453
|
+
idempotencyKey: streamBatchIdempotencyKey?.toString(),
|
|
1454
|
+
idempotencyKeyOptions: streamBatchIdempotencyKeyOptions,
|
|
1455
|
+
spanParentAsLink: true, // Fire-and-forget: child runs get separate trace IDs
|
|
1456
|
+
}, requestOptions);
|
|
1457
|
+
span.setAttribute("batchId", result.id);
|
|
1458
|
+
span.setAttribute("runCount", result.runCount);
|
|
1459
|
+
return result;
|
|
1460
|
+
}, {
|
|
1461
|
+
kind: api_1.SpanKind.PRODUCER,
|
|
1462
|
+
attributes: {
|
|
1463
|
+
[v3_1.SemanticInternalAttributes.STYLE_ICON]: "trigger",
|
|
1464
|
+
...(0, v3_1.accessoryAttributes)({
|
|
1465
|
+
items: [
|
|
1466
|
+
{
|
|
1467
|
+
text: taskIdentifier,
|
|
1468
|
+
variant: "normal",
|
|
1469
|
+
},
|
|
1470
|
+
],
|
|
1471
|
+
style: "codepath",
|
|
1472
|
+
}),
|
|
1473
|
+
},
|
|
1474
|
+
});
|
|
1475
|
+
const handle = {
|
|
1476
|
+
batchId: response.id,
|
|
1477
|
+
runCount: response.runCount,
|
|
1478
|
+
publicAccessToken: response.publicAccessToken,
|
|
1479
|
+
};
|
|
1480
|
+
return handle;
|
|
1481
|
+
}
|
|
938
1482
|
}
|
|
939
1483
|
async function triggerAndWait_internal(name, id, payload, parsePayload, options, requestOptions) {
|
|
940
1484
|
const ctx = v3_1.taskContext.ctx;
|
|
941
1485
|
if (!ctx) {
|
|
942
1486
|
throw new Error("triggerAndWait can only be used from inside a task.run()");
|
|
943
1487
|
}
|
|
944
|
-
const apiClient = v3_1.apiClientManager.clientOrThrow();
|
|
1488
|
+
const apiClient = v3_1.apiClientManager.clientOrThrow(requestOptions?.clientConfig);
|
|
945
1489
|
const parsedPayload = parsePayload ? await parsePayload(payload) : payload;
|
|
946
|
-
const
|
|
1490
|
+
const { packet: triggerPayloadPacket, payloadSize } = await prepareTriggerPayload(parsedPayload, apiClient);
|
|
1491
|
+
// Process idempotency key and extract options for storage
|
|
1492
|
+
const processedIdempotencyKey = await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey);
|
|
1493
|
+
const idempotencyKeyOptions = processedIdempotencyKey
|
|
1494
|
+
? (0, v3_1.getIdempotencyKeyOptions)(processedIdempotencyKey)
|
|
1495
|
+
: undefined;
|
|
947
1496
|
return await tracer_js_1.tracer.startActiveSpan(name, async (span) => {
|
|
948
1497
|
const response = await apiClient.triggerTask(id, {
|
|
949
|
-
payload:
|
|
1498
|
+
payload: triggerPayloadPacket.data,
|
|
950
1499
|
options: {
|
|
951
|
-
dependentAttempt: ctx.attempt.id,
|
|
952
1500
|
lockToVersion: v3_1.taskContext.worker?.version, // Lock to current version because we're waiting for it to finish
|
|
953
|
-
|
|
1501
|
+
...triggerQueueBody(options?.queue),
|
|
1502
|
+
...(0, concurrency_shared_js_1.triggerConcurrencyBody)(options?.concurrency),
|
|
954
1503
|
concurrencyKey: options?.concurrencyKey,
|
|
955
1504
|
test: v3_1.taskContext.ctx?.run.isTest,
|
|
956
|
-
payloadType:
|
|
1505
|
+
payloadType: triggerPayloadPacket.dataType,
|
|
1506
|
+
payloadSize,
|
|
957
1507
|
delay: options?.delay,
|
|
958
1508
|
ttl: options?.ttl,
|
|
959
1509
|
tags: options?.tags,
|
|
960
1510
|
maxAttempts: options?.maxAttempts,
|
|
961
1511
|
metadata: options?.metadata,
|
|
962
1512
|
maxDuration: options?.maxDuration,
|
|
1513
|
+
resumeParentOnCompletion: true,
|
|
1514
|
+
parentRunId: ctx.run.id,
|
|
1515
|
+
idempotencyKey: processedIdempotencyKey?.toString(),
|
|
1516
|
+
idempotencyKeyTTL: options?.idempotencyKeyTTL,
|
|
1517
|
+
idempotencyKeyOptions,
|
|
963
1518
|
machine: options?.machine,
|
|
1519
|
+
priority: options?.priority,
|
|
1520
|
+
region: options?.region,
|
|
1521
|
+
debounce: options?.debounce,
|
|
964
1522
|
},
|
|
965
1523
|
}, {}, requestOptions);
|
|
966
1524
|
span.setAttribute("runId", response.id);
|
|
@@ -985,59 +1543,118 @@ async function triggerAndWait_internal(name, id, payload, parsePayload, options,
|
|
|
985
1543
|
},
|
|
986
1544
|
});
|
|
987
1545
|
}
|
|
988
|
-
async function
|
|
1546
|
+
async function triggerAndSubscribe_internal(name, id, payload, parsePayload, options, requestOptions) {
|
|
989
1547
|
const ctx = v3_1.taskContext.ctx;
|
|
990
1548
|
if (!ctx) {
|
|
991
|
-
throw new Error("
|
|
1549
|
+
throw new Error("triggerAndSubscribe can only be used from inside a task.run()");
|
|
992
1550
|
}
|
|
993
|
-
const apiClient = v3_1.apiClientManager.clientOrThrow();
|
|
1551
|
+
const apiClient = v3_1.apiClientManager.clientOrThrow(requestOptions?.clientConfig);
|
|
1552
|
+
const parsedPayload = parsePayload ? await parsePayload(payload) : payload;
|
|
1553
|
+
const { packet: triggerPayloadPacket, payloadSize } = await prepareTriggerPayload(parsedPayload, apiClient);
|
|
1554
|
+
const processedIdempotencyKey = await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey);
|
|
1555
|
+
const idempotencyKeyOptions = processedIdempotencyKey
|
|
1556
|
+
? (0, v3_1.getIdempotencyKeyOptions)(processedIdempotencyKey)
|
|
1557
|
+
: undefined;
|
|
994
1558
|
return await tracer_js_1.tracer.startActiveSpan(name, async (span) => {
|
|
995
|
-
const response = await apiClient.
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
}, requestOptions);
|
|
1022
|
-
|
|
1023
|
-
span.setAttribute("
|
|
1024
|
-
span.setAttribute("
|
|
1025
|
-
|
|
1026
|
-
|
|
1559
|
+
const response = await apiClient.triggerTask(id, {
|
|
1560
|
+
payload: triggerPayloadPacket.data,
|
|
1561
|
+
options: {
|
|
1562
|
+
lockToVersion: v3_1.taskContext.worker?.version,
|
|
1563
|
+
...triggerQueueBody(options?.queue),
|
|
1564
|
+
...(0, concurrency_shared_js_1.triggerConcurrencyBody)(options?.concurrency),
|
|
1565
|
+
concurrencyKey: options?.concurrencyKey,
|
|
1566
|
+
test: v3_1.taskContext.ctx?.run.isTest,
|
|
1567
|
+
payloadType: triggerPayloadPacket.dataType,
|
|
1568
|
+
payloadSize,
|
|
1569
|
+
delay: options?.delay,
|
|
1570
|
+
ttl: options?.ttl,
|
|
1571
|
+
tags: options?.tags,
|
|
1572
|
+
maxAttempts: options?.maxAttempts,
|
|
1573
|
+
metadata: options?.metadata,
|
|
1574
|
+
maxDuration: options?.maxDuration,
|
|
1575
|
+
parentRunId: ctx.run.id,
|
|
1576
|
+
// NOTE: no resumeParentOnCompletion — parent stays alive and subscribes
|
|
1577
|
+
idempotencyKey: processedIdempotencyKey?.toString(),
|
|
1578
|
+
idempotencyKeyTTL: options?.idempotencyKeyTTL,
|
|
1579
|
+
idempotencyKeyOptions,
|
|
1580
|
+
machine: options?.machine,
|
|
1581
|
+
priority: options?.priority,
|
|
1582
|
+
region: options?.region,
|
|
1583
|
+
debounce: options?.debounce,
|
|
1584
|
+
},
|
|
1585
|
+
}, {}, requestOptions);
|
|
1586
|
+
// Set attributes after trigger so the dashboard can link to the child run
|
|
1587
|
+
span.setAttribute("messaging.message.id", response.id);
|
|
1588
|
+
span.setAttribute("runId", response.id);
|
|
1589
|
+
span.setAttribute(v3_1.SemanticInternalAttributes.ENTITY_TYPE, "run");
|
|
1590
|
+
span.setAttribute(v3_1.SemanticInternalAttributes.ENTITY_ID, response.id);
|
|
1591
|
+
// Optionally cancel the child run when the abort signal fires (default: true)
|
|
1592
|
+
const cancelOnAbort = options?.cancelOnAbort !== false;
|
|
1593
|
+
let onAbort;
|
|
1594
|
+
if (options?.signal && cancelOnAbort) {
|
|
1595
|
+
if (options.signal.aborted) {
|
|
1596
|
+
await apiClient.cancelRun(response.id).catch(() => { });
|
|
1597
|
+
throw new DOMException("Aborted", "AbortError");
|
|
1598
|
+
}
|
|
1599
|
+
onAbort = () => {
|
|
1600
|
+
apiClient.cancelRun(response.id).catch(() => { });
|
|
1601
|
+
};
|
|
1602
|
+
// `{ once: true }` auto-removes the listener on abort, but if the
|
|
1603
|
+
// run completes normally the listener stays attached and pins
|
|
1604
|
+
// `apiClient` + `response.id` until the signal is GC'd. Long-lived
|
|
1605
|
+
// signals shared across many calls accumulate dead listeners; the
|
|
1606
|
+
// `finally` below removes the listener on every exit path.
|
|
1607
|
+
options.signal.addEventListener("abort", onAbort, { once: true });
|
|
1608
|
+
}
|
|
1609
|
+
try {
|
|
1610
|
+
for await (const run of apiClient.subscribeToRun(response.id, {
|
|
1611
|
+
closeOnComplete: true,
|
|
1612
|
+
signal: options?.signal,
|
|
1613
|
+
skipColumns: ["payload"],
|
|
1614
|
+
})) {
|
|
1615
|
+
if (run.isSuccess) {
|
|
1616
|
+
// run.output from subscribeToRun is already deserialized
|
|
1617
|
+
return {
|
|
1618
|
+
ok: true,
|
|
1619
|
+
id: response.id,
|
|
1620
|
+
taskIdentifier: id,
|
|
1621
|
+
output: run.output,
|
|
1622
|
+
};
|
|
1623
|
+
}
|
|
1624
|
+
if (run.isFailed || run.isCancelled) {
|
|
1625
|
+
// Note: this intentionally diverges from `triggerAndWait`'s
|
|
1626
|
+
// error shape. `triggerAndWait` receives a full `TaskRunError`
|
|
1627
|
+
// (with `type` discriminator: BUILT_IN_ERROR, CUSTOM_ERROR,
|
|
1628
|
+
// INTERNAL_ERROR, STRING_ERROR) via the completion message and
|
|
1629
|
+
// passes it through `createErrorTaskError` to preserve the
|
|
1630
|
+
// discriminator. `subscribeToRun` only surfaces a
|
|
1631
|
+
// `SerializedError` (`{ name, message, stackTrace, causes }`)
|
|
1632
|
+
// because `createJsonErrorObject` strips the discriminator before
|
|
1633
|
+
// the record hits the realtime stream. We can't reconstruct the
|
|
1634
|
+
// discriminator here without lossy guessing — callers that
|
|
1635
|
+
// need exact error-type matching should use `triggerAndWait`
|
|
1636
|
+
// instead; subscribers get message, name and the cause chain.
|
|
1637
|
+
const cause = run.error?.causes?.length
|
|
1638
|
+
? (0, v3_1.createErrorFromCauses)(run.error.causes)
|
|
1639
|
+
: undefined;
|
|
1640
|
+
const error = new Error(run.error?.message ?? `Task ${id} failed (${run.status})`, cause ? { cause } : undefined);
|
|
1641
|
+
if (run.error?.name)
|
|
1642
|
+
error.name = run.error.name;
|
|
1643
|
+
return {
|
|
1644
|
+
ok: false,
|
|
1645
|
+
id: response.id,
|
|
1646
|
+
taskIdentifier: id,
|
|
1647
|
+
error,
|
|
1648
|
+
};
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
throw new Error(`Task ${id}: subscription ended without completion`);
|
|
1027
1652
|
}
|
|
1028
|
-
|
|
1029
|
-
|
|
1653
|
+
finally {
|
|
1654
|
+
if (onAbort && options?.signal) {
|
|
1655
|
+
options.signal.removeEventListener("abort", onAbort);
|
|
1656
|
+
}
|
|
1030
1657
|
}
|
|
1031
|
-
const result = await v3_1.runtime.waitForBatch({
|
|
1032
|
-
id: response.id,
|
|
1033
|
-
runs: response.runs.map((run) => run.id),
|
|
1034
|
-
ctx,
|
|
1035
|
-
});
|
|
1036
|
-
const runs = await handleBatchTaskRunExecutionResult(result.items, id);
|
|
1037
|
-
return {
|
|
1038
|
-
id: result.id,
|
|
1039
|
-
runs,
|
|
1040
|
-
};
|
|
1041
1658
|
}, {
|
|
1042
1659
|
kind: api_1.SpanKind.PRODUCER,
|
|
1043
1660
|
attributes: {
|
|
@@ -1054,6 +1671,141 @@ async function batchTriggerAndWait_internal(name, id, items, parsePayload, optio
|
|
|
1054
1671
|
},
|
|
1055
1672
|
});
|
|
1056
1673
|
}
|
|
1674
|
+
async function batchTriggerAndWait_internal(name, id, items, parsePayload, options, requestOptions, queue) {
|
|
1675
|
+
const ctx = v3_1.taskContext.ctx;
|
|
1676
|
+
if (!ctx) {
|
|
1677
|
+
throw new Error("batchTriggerAndWait can only be used from inside a task.run()");
|
|
1678
|
+
}
|
|
1679
|
+
const apiClient = v3_1.apiClientManager.clientOrThrow(requestOptions?.clientConfig);
|
|
1680
|
+
// Check if items is an array or a stream
|
|
1681
|
+
if (Array.isArray(items)) {
|
|
1682
|
+
// Prepare items as BatchItemNDJSON
|
|
1683
|
+
const ndJsonItems = await Promise.all(items.map(async (item, index) => {
|
|
1684
|
+
const parsedPayload = parsePayload ? await parsePayload(item.payload) : item.payload;
|
|
1685
|
+
const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
|
|
1686
|
+
const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
|
|
1687
|
+
// Process item-specific idempotency key and extract options
|
|
1688
|
+
const itemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey);
|
|
1689
|
+
const finalIdempotencyKey = itemIdempotencyKey ?? batchItemIdempotencyKey;
|
|
1690
|
+
const idempotencyKeyOptions = itemIdempotencyKey
|
|
1691
|
+
? (0, v3_1.getIdempotencyKeyOptions)(itemIdempotencyKey)
|
|
1692
|
+
: undefined;
|
|
1693
|
+
return {
|
|
1694
|
+
index,
|
|
1695
|
+
task: id,
|
|
1696
|
+
payload: payloadPacket.data,
|
|
1697
|
+
options: {
|
|
1698
|
+
lockToVersion: v3_1.taskContext.worker?.version,
|
|
1699
|
+
...triggerQueueBody(item.options?.queue, queue),
|
|
1700
|
+
...(0, concurrency_shared_js_1.triggerConcurrencyBody)(item.options?.concurrency),
|
|
1701
|
+
concurrencyKey: item.options?.concurrencyKey,
|
|
1702
|
+
test: v3_1.taskContext.ctx?.run.isTest,
|
|
1703
|
+
payloadType: payloadPacket.dataType,
|
|
1704
|
+
delay: item.options?.delay,
|
|
1705
|
+
ttl: item.options?.ttl,
|
|
1706
|
+
tags: item.options?.tags,
|
|
1707
|
+
maxAttempts: item.options?.maxAttempts,
|
|
1708
|
+
metadata: item.options?.metadata,
|
|
1709
|
+
maxDuration: item.options?.maxDuration,
|
|
1710
|
+
idempotencyKey: finalIdempotencyKey?.toString(),
|
|
1711
|
+
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
1712
|
+
idempotencyKeyOptions,
|
|
1713
|
+
machine: item.options?.machine,
|
|
1714
|
+
priority: item.options?.priority,
|
|
1715
|
+
region: item.options?.region,
|
|
1716
|
+
debounce: item.options?.debounce,
|
|
1717
|
+
},
|
|
1718
|
+
};
|
|
1719
|
+
}));
|
|
1720
|
+
// Process batch-level idempotency key
|
|
1721
|
+
const batchIdempotencyKey = await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey);
|
|
1722
|
+
const batchIdempotencyKeyOptions = batchIdempotencyKey
|
|
1723
|
+
? (0, v3_1.getIdempotencyKeyOptions)(batchIdempotencyKey)
|
|
1724
|
+
: undefined;
|
|
1725
|
+
return await tracer_js_1.tracer.startActiveSpan(name, async (span) => {
|
|
1726
|
+
// Execute 2-phase batch
|
|
1727
|
+
const response = await executeBatchTwoPhase(apiClient, ndJsonItems, {
|
|
1728
|
+
parentRunId: ctx.run.id,
|
|
1729
|
+
resumeParentOnCompletion: true,
|
|
1730
|
+
idempotencyKey: batchIdempotencyKey?.toString(),
|
|
1731
|
+
idempotencyKeyOptions: batchIdempotencyKeyOptions,
|
|
1732
|
+
spanParentAsLink: false, // Waiting: child runs share parent's trace ID
|
|
1733
|
+
}, requestOptions);
|
|
1734
|
+
span.setAttribute("batchId", response.id);
|
|
1735
|
+
span.setAttribute("runCount", response.runCount);
|
|
1736
|
+
const result = await v3_1.runtime.waitForBatch({
|
|
1737
|
+
id: response.id,
|
|
1738
|
+
runCount: response.runCount,
|
|
1739
|
+
ctx,
|
|
1740
|
+
});
|
|
1741
|
+
const runs = await handleBatchTaskRunExecutionResult(result.items, id);
|
|
1742
|
+
return {
|
|
1743
|
+
id: result.id,
|
|
1744
|
+
runs,
|
|
1745
|
+
};
|
|
1746
|
+
}, {
|
|
1747
|
+
kind: api_1.SpanKind.PRODUCER,
|
|
1748
|
+
attributes: {
|
|
1749
|
+
[v3_1.SemanticInternalAttributes.STYLE_ICON]: "trigger",
|
|
1750
|
+
...(0, v3_1.accessoryAttributes)({
|
|
1751
|
+
items: [
|
|
1752
|
+
{
|
|
1753
|
+
text: id,
|
|
1754
|
+
variant: "normal",
|
|
1755
|
+
},
|
|
1756
|
+
],
|
|
1757
|
+
style: "codepath",
|
|
1758
|
+
}),
|
|
1759
|
+
},
|
|
1760
|
+
});
|
|
1761
|
+
}
|
|
1762
|
+
else {
|
|
1763
|
+
// Stream path: convert to AsyncIterable and transform
|
|
1764
|
+
const asyncItems = normalizeToAsyncIterable(items);
|
|
1765
|
+
const transformedItems = transformSingleTaskBatchItemsStreamForWait(id, asyncItems, parsePayload, options, queue);
|
|
1766
|
+
// Process batch-level idempotency key for streaming path
|
|
1767
|
+
const streamBatchIdempotencyKey = await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey);
|
|
1768
|
+
const streamBatchIdempotencyKeyOptions = streamBatchIdempotencyKey
|
|
1769
|
+
? (0, v3_1.getIdempotencyKeyOptions)(streamBatchIdempotencyKey)
|
|
1770
|
+
: undefined;
|
|
1771
|
+
return await tracer_js_1.tracer.startActiveSpan(name, async (span) => {
|
|
1772
|
+
// Execute streaming 2-phase batch
|
|
1773
|
+
const response = await executeBatchTwoPhaseStreaming(apiClient, transformedItems, {
|
|
1774
|
+
parentRunId: ctx.run.id,
|
|
1775
|
+
resumeParentOnCompletion: true,
|
|
1776
|
+
idempotencyKey: streamBatchIdempotencyKey?.toString(),
|
|
1777
|
+
idempotencyKeyOptions: streamBatchIdempotencyKeyOptions,
|
|
1778
|
+
spanParentAsLink: false, // Waiting: child runs share parent's trace ID
|
|
1779
|
+
}, requestOptions);
|
|
1780
|
+
span.setAttribute("batchId", response.id);
|
|
1781
|
+
span.setAttribute("runCount", response.runCount);
|
|
1782
|
+
const result = await v3_1.runtime.waitForBatch({
|
|
1783
|
+
id: response.id,
|
|
1784
|
+
runCount: response.runCount,
|
|
1785
|
+
ctx,
|
|
1786
|
+
});
|
|
1787
|
+
const runs = await handleBatchTaskRunExecutionResult(result.items, id);
|
|
1788
|
+
return {
|
|
1789
|
+
id: result.id,
|
|
1790
|
+
runs,
|
|
1791
|
+
};
|
|
1792
|
+
}, {
|
|
1793
|
+
kind: api_1.SpanKind.PRODUCER,
|
|
1794
|
+
attributes: {
|
|
1795
|
+
[v3_1.SemanticInternalAttributes.STYLE_ICON]: "trigger",
|
|
1796
|
+
...(0, v3_1.accessoryAttributes)({
|
|
1797
|
+
items: [
|
|
1798
|
+
{
|
|
1799
|
+
text: id,
|
|
1800
|
+
variant: "normal",
|
|
1801
|
+
},
|
|
1802
|
+
],
|
|
1803
|
+
style: "codepath",
|
|
1804
|
+
}),
|
|
1805
|
+
},
|
|
1806
|
+
});
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1057
1809
|
async function handleBatchTaskRunExecutionResult(items, taskIdentifier) {
|
|
1058
1810
|
const someObjectStoreOutputs = items.some((item) => item.ok && item.outputType === "application/store");
|
|
1059
1811
|
if (!someObjectStoreOutputs) {
|
|
@@ -1072,17 +1824,17 @@ async function handleBatchTaskRunExecutionResult(items, taskIdentifier) {
|
|
|
1072
1824
|
[v3_1.SemanticInternalAttributes.STYLE_ICON]: "cloud-download",
|
|
1073
1825
|
});
|
|
1074
1826
|
}
|
|
1075
|
-
async function handleBatchTaskRunExecutionResultV2(items) {
|
|
1827
|
+
async function handleBatchTaskRunExecutionResultV2(items, taskIdentifiers) {
|
|
1076
1828
|
const someObjectStoreOutputs = items.some((item) => item.ok && item.outputType === "application/store");
|
|
1077
1829
|
if (!someObjectStoreOutputs) {
|
|
1078
|
-
const results = await Promise.all(items.map(async (item) => {
|
|
1079
|
-
return await handleTaskRunExecutionResult(item, item.taskIdentifier ?? "unknown");
|
|
1830
|
+
const results = await Promise.all(items.map(async (item, index) => {
|
|
1831
|
+
return await handleTaskRunExecutionResult(item, item.taskIdentifier ?? taskIdentifiers?.[index] ?? "unknown");
|
|
1080
1832
|
}));
|
|
1081
1833
|
return results;
|
|
1082
1834
|
}
|
|
1083
1835
|
return await tracer_js_1.tracer.startActiveSpan("store.downloadPayloads", async (span) => {
|
|
1084
|
-
const results = await Promise.all(items.map(async (item) => {
|
|
1085
|
-
return await handleTaskRunExecutionResult(item, item.taskIdentifier ?? "unknown");
|
|
1836
|
+
const results = await Promise.all(items.map(async (item, index) => {
|
|
1837
|
+
return await handleTaskRunExecutionResult(item, item.taskIdentifier ?? taskIdentifiers?.[index] ?? "unknown");
|
|
1086
1838
|
}));
|
|
1087
1839
|
return results;
|
|
1088
1840
|
}, {
|
|
@@ -1110,4 +1862,90 @@ async function handleTaskRunExecutionResult(execution, taskIdentifier) {
|
|
|
1110
1862
|
};
|
|
1111
1863
|
}
|
|
1112
1864
|
}
|
|
1865
|
+
function registerTaskLifecycleHooks(taskId, params) {
|
|
1866
|
+
if (params.init) {
|
|
1867
|
+
v3_1.lifecycleHooks.registerTaskInitHook(taskId, {
|
|
1868
|
+
fn: params.init,
|
|
1869
|
+
});
|
|
1870
|
+
}
|
|
1871
|
+
if (params.onStart) {
|
|
1872
|
+
v3_1.lifecycleHooks.registerTaskStartHook(taskId, {
|
|
1873
|
+
fn: params.onStart,
|
|
1874
|
+
});
|
|
1875
|
+
}
|
|
1876
|
+
if (params.onStartAttempt) {
|
|
1877
|
+
v3_1.lifecycleHooks.registerTaskStartAttemptHook(taskId, {
|
|
1878
|
+
fn: params.onStartAttempt,
|
|
1879
|
+
});
|
|
1880
|
+
}
|
|
1881
|
+
if (params.onFailure) {
|
|
1882
|
+
v3_1.lifecycleHooks.registerTaskFailureHook(taskId, {
|
|
1883
|
+
fn: params.onFailure,
|
|
1884
|
+
});
|
|
1885
|
+
}
|
|
1886
|
+
if (params.onSuccess) {
|
|
1887
|
+
v3_1.lifecycleHooks.registerTaskSuccessHook(taskId, {
|
|
1888
|
+
fn: params.onSuccess,
|
|
1889
|
+
});
|
|
1890
|
+
}
|
|
1891
|
+
if (params.onComplete) {
|
|
1892
|
+
v3_1.lifecycleHooks.registerTaskCompleteHook(taskId, {
|
|
1893
|
+
fn: params.onComplete,
|
|
1894
|
+
});
|
|
1895
|
+
}
|
|
1896
|
+
if (params.onWait) {
|
|
1897
|
+
v3_1.lifecycleHooks.registerTaskWaitHook(taskId, {
|
|
1898
|
+
fn: params.onWait,
|
|
1899
|
+
});
|
|
1900
|
+
}
|
|
1901
|
+
if (params.onResume) {
|
|
1902
|
+
v3_1.lifecycleHooks.registerTaskResumeHook(taskId, {
|
|
1903
|
+
fn: params.onResume,
|
|
1904
|
+
});
|
|
1905
|
+
}
|
|
1906
|
+
if (params.catchError) {
|
|
1907
|
+
// We don't need to use an adapter here because catchError is the new version of handleError
|
|
1908
|
+
v3_1.lifecycleHooks.registerTaskCatchErrorHook(taskId, {
|
|
1909
|
+
fn: params.catchError,
|
|
1910
|
+
});
|
|
1911
|
+
}
|
|
1912
|
+
if (params.handleError) {
|
|
1913
|
+
v3_1.lifecycleHooks.registerTaskCatchErrorHook(taskId, {
|
|
1914
|
+
fn: params.handleError,
|
|
1915
|
+
});
|
|
1916
|
+
}
|
|
1917
|
+
if (params.middleware) {
|
|
1918
|
+
v3_1.lifecycleHooks.registerTaskMiddlewareHook(taskId, {
|
|
1919
|
+
fn: params.middleware,
|
|
1920
|
+
});
|
|
1921
|
+
}
|
|
1922
|
+
if (params.cleanup) {
|
|
1923
|
+
v3_1.lifecycleHooks.registerTaskCleanupHook(taskId, {
|
|
1924
|
+
fn: params.cleanup,
|
|
1925
|
+
});
|
|
1926
|
+
}
|
|
1927
|
+
if (params.onCancel) {
|
|
1928
|
+
v3_1.lifecycleHooks.registerTaskCancelHook(taskId, {
|
|
1929
|
+
fn: params.onCancel,
|
|
1930
|
+
});
|
|
1931
|
+
}
|
|
1932
|
+
}
|
|
1933
|
+
async function prepareTriggerPayload(payload, apiClient) {
|
|
1934
|
+
const payloadPacket = await (0, v3_1.stringifyIO)(payload);
|
|
1935
|
+
// Measure the serialized size before any offload, so it reflects the real payload
|
|
1936
|
+
// size rather than the small "application/store" reference we may send instead.
|
|
1937
|
+
const { size: payloadSize } = (0, v3_1.packetRequiresOffloading)(payloadPacket);
|
|
1938
|
+
const packet = await (0, v3_1.conditionallyExportPacket)(payloadPacket, createTriggerPayloadPathPrefix(), undefined, apiClient);
|
|
1939
|
+
return { packet, payloadSize };
|
|
1940
|
+
}
|
|
1941
|
+
/**
|
|
1942
|
+
* Build the object-storage path prefix for an offloaded trigger payload.
|
|
1943
|
+
*
|
|
1944
|
+
* Every segment is generated here, so nothing caller-controlled reaches the key.
|
|
1945
|
+
* The id's alphabet is lowercase alphanumeric, which no layer between here and the
|
|
1946
|
+
* object store rewrites, so the path the SDK asks for is the path that gets stored.
|
|
1947
|
+
*/
|
|
1948
|
+
function createTriggerPayloadPathPrefix() {
|
|
1949
|
+
return `trigger/${(0, v3_1.generateFriendlyId)("packet")}/payload`;
|
|
1950
|
+
}
|
|
1113
1951
|
//# sourceMappingURL=shared.js.map
|