What’s new in v4, how to upgrade, and breaking changes.
wait.createToken
function:
idempotencyKeyTTL
allows you to specify how long the idempotency key should be valid for. The default is 30 days.
10
, the run will win over runs with a priority of 0
that were triggered within the last 10 seconds. A more concrete example:
trigger.config.ts
file, but now you can register them anywhere in your codebase:
init.ts
init.ts
file at the root of your trigger directory, it will be automatically loaded when a task is executed. This is useful if you want to register global lifecycle hooks, or initialize a database connection, etc.
onCancel
hook that is called when a run is cancelled. This is useful if you want to clean up any resources that were allocated for the run.
onCancel
hook along with the signal
passed into the run function to interrupt a call to an external service, for example using the streamText function from the AI SDK:
onCancel
hook can optionally wait for the run
function to finish, and access the output of the run:
runPromise
in the onCancel
hook. After that
point the process will be killed.run
function, but now we’ve hoisted it to the top level and it now runs before/after all the other hooks.
We’ve also added a new locals
API that allows you to share data between middleware and hooks.
run
function and all your hooks (global or task specific) you can access the database client using getDb()
:
useWaitToken
react hook that allows you to complete a wait token from a React component, using a Public Access Token.
useWaitToken
hook in your frontend code:
ai.tool
ai.tool
function that allows you to create an AI tool from an existing schemaTask
to use with the Vercel AI SDK:
experimental_toToolResultContent
option to the ai.tool
function to customize the content of the tool result:
ai.currentToolOptions()
function:
ai.tool
is compatible with schemaTask
’s defined with Zod and ArkType schemas, or any schemas
that implement a .toJsonSchema()
function.trigger dev
CLI command and test your tasks locally, fixing any breaking changes.v4-beta
tag.
@trigger.dev/*
packages. v4-beta
version of the trigger.dev
CLI package:
@trigger.dev/sdk/v3
import path and moved to a new path:
handleError
and init
handleError
hook to catchError
to better reflect that it can catch and react to errors. handleError
will be removed in a future version.
init
was previously used to initialize data used in the run function:
locals
API and middleware. See the Improved middleware and locals section for more details.
toolTask
function, which created both a Trigger.dev task and a tool compatible with the Vercel AI SDK:
toolTask
function with the ai.tool
function, which creates an AI tool from an existing schemaTask
. See the ai.tool section for more details.
queue
function:
concurrencyLimit
when a run is paused. You can go back to the previous behavior by setting the releaseConcurrencyOnWaitpoint
option to true
on the queue:
wait.for({ seconds: 10 })
)myTask.triggerAndWait()
, myTask.batchTriggerAndWait([...])
)wait.forToken(tokenId)
)ctx
object:
ctx.attempt.id
and ctx.attempt.status
have been removed. ctx.attempt.number
is still available.ctx.task.exportName
has been removed (since we no longer require tasks to be exported to be triggered).batchTrigger
function no longer returns a runs
list directly. In v3, you could access the runs directly from the batch handle:
runs.list()
method to get the list of runs:
bun
runtime. The only supported runtime is now node
.