fade22015f
* Adds new features table to top of v4 upgrade guide * Adds wait idempotency to wait-until, wait-for, and wait-for-token pages * Adds new priority docs page and updates the v4 upgrade guide * Adds new task lifecycle hooks * Removes the message about requiring tasks to be exported * Adds new global lifecycle hooks section * Moves sections from upgrade guide into the table * Adds hidden task page * Improves the global lifecycle hooks section * Updates middleware and locals section * Adds new useWaitToken page to the react hooks section * Adds a new ai.tool section * Moves Docker (legacy) page into self-hosting section * Removes known issues from v4 upgrade guide * Replace “toolTask” with “ai.tool” in the Streams page example * Renames guide to “Migrating from v3” and adds redirect * Remove references to v4 * Removes changelog from migration guide * The installation guide now references `@latest update` * Changes all references from `/sdk/v3` to `/sdk` * Updates @v4-beta to @latest * Fixed broken link * Fixes broken link * Adds an upgrade to v4 using AI section * Fixes 2 broken links * Adds an entry for targetting preview branches * Updates the run statuses * Adds boolean helpers section to the runs and realtime pages * Updates the concurrency page * Updates the test page to include the new options * Adds SDK and curl options for the preview branch targeting * Updates new bulk actions page * Remove the releasing concurrency section * Got rid of some more @v4-beta mentions * Improved rate limit docs * Improved migrating docs * Removed commented sections of the docs * useWaitToken hook * Fixed the description * Fix for missing test image --------- Co-authored-by: Matt Aitken <matt@mattaitken.com> Co-authored-by: Dan <8297864+D-K-P@users.noreply.github.com>
87 lines
5.2 KiB
Plaintext
87 lines
5.2 KiB
Plaintext
---
|
|
title: "Human-in-the-loop workflow with ReactFlow and Trigger.dev waitpoint tokens"
|
|
sidebarTitle: "Human-in-the-loop workflow"
|
|
description: "This example project creates audio summaries of newspaper articles using a human-in-the-loop workflow built with ReactFlow and Trigger.dev waitpoint tokens."
|
|
---
|
|
|
|
## Overview
|
|
|
|
This demo is a full stack example that uses the following:
|
|
|
|
- [Next.js](https://nextjs.org/) for the web application
|
|
- [ReactFlow](https://reactflow.dev/) for the workflow UI
|
|
- [Trigger.dev Realtime](/realtime/overview) to subscribe to task runs and show the real-time status of the workflow steps
|
|
- [Trigger.dev waitpoint tokens](/wait-for-token) to create a human-in-the-loop flow with a review step
|
|
- [OpenAI API](https://openai.com/api/) to generate article summaries
|
|
- [ElevenLabs](https://elevenlabs.io/text-to-speech) to convert text to speech
|
|
|
|
## GitHub repo
|
|
|
|
<Card
|
|
title="View the human-in-the-loop workflow repo"
|
|
icon="GitHub"
|
|
href="https://github.com/triggerdotdev/examples/tree/main/article-summary-workflow"
|
|
>
|
|
Click here to view the full code for this project in our examples repository on GitHub. You can
|
|
fork it and use it as a starting point for your own project.
|
|
</Card>
|
|
|
|
## Video
|
|
|
|
<video
|
|
controls
|
|
className="w-full aspect-video"
|
|
src="https://content.trigger.dev/reactflow-waitpoints-example.mov"
|
|
></video>
|
|
|
|
## Relevant code
|
|
|
|
Each node in the workflow corresponds to a Trigger.dev task. The idea is to enable building flows by composition of different tasks. The output of one task serves as input for another.
|
|
|
|
- **Trigger.dev task splitting**:
|
|
- The [summarizeArticle](https://github.com/triggerdotdev/examples/blob/main/article-summary-workflow/src/trigger/summarizeArticle.ts) task uses the OpenAI API to generate a summary an article.
|
|
- The [convertTextToSpeech](https://github.com/triggerdotdev/examples/blob/main/article-summary-workflow/src/trigger/convertTextToSpeech.ts) task uses the ElevenLabs API to convert the summary into an audio stream and upload it to an S3 bucket.
|
|
- The [reviewSummary](https://github.com/triggerdotdev/examples/blob/main/article-summary-workflow/src/trigger/reviewSummary.ts) task is a human-in-the-loop step that shows the result and waits for approval of the summary before continuing.
|
|
- [articleWorkflow](https://github.com/triggerdotdev/examples/blob/main/article-summary-workflow/src/trigger/articleWorkflow.ts) is the entrypoint that ties the workflow together and orchestrates the tasks. You might choose to approach the orchestration differently, depending on your use case.
|
|
- **ReactFlow Nodes**: there are three types of nodes in this example. All of them are custom ReactFlow nodes.
|
|
- The [InputNode](https://github.com/triggerdotdev/examples/blob/main/article-summary-workflow/src/components/InputNode.tsx) is the starting node of the workflow. It triggers the workflow by submitting an article URL.
|
|
- The [ActionNode](https://github.com/triggerdotdev/examples/blob/main/article-summary-workflow/src/components/ActionNode.tsx) is a node that shows the status of a task run in Trigger.dev, in real-time using the React hooks for Trigger.dev.
|
|
- The [ReviewNode](https://github.com/triggerdotdev/examples/blob/main/article-summary-workflow/src/components/ReviewNode.tsx) is a node that shows the summary result and prompts the user for approval before continuing. It uses the Realtime API to fetch details about the review status. Also, it interacts with the Trigger.dev waitpoint API for completing the waitpoint token using Next.js server actions.
|
|
- **Workflow orchestration**:
|
|
- The workflow is orchestrated by the [Flow](https://github.com/triggerdotdev/examples/blob/main/article-summary-workflow/src/components/Flow.tsx) component. It lays out the nodes, the connections between them, as well as the mapping to the Trigger.dev tasks.
|
|
It also uses the `useRealtimeRunsWithTag` hook to subscribe to task runs associated with the workflow and passes down the run details to the nodes.
|
|
|
|
The waitpoint token is created in [a Next.js server action](https://github.com/triggerdotdev/examples/blob/main/article-summary-workflow/src/app/actions.ts#L26):
|
|
|
|
```ts
|
|
const reviewWaitpointToken = await wait.createToken({
|
|
tags: [workflowTag],
|
|
timeout: "1h",
|
|
idempotencyKey: `review-summary-${workflowTag}`,
|
|
});
|
|
```
|
|
|
|
and later completed in another server action in the same file:
|
|
|
|
```ts
|
|
await wait.completeToken<ReviewPayload>(
|
|
{ id: tokenId },
|
|
{
|
|
approved: true,
|
|
approvedAt: new Date(),
|
|
approvedBy: user,
|
|
}
|
|
);
|
|
```
|
|
|
|
While the workflow in this example is static and does not allow changing the connections between nodes in the UI, it serves as a good baseline for understanding how to build completely custom workflow builders using Trigger.dev and ReactFlow.
|
|
|
|
## Learn more about Trigger.dev Realtime and waitpoint tokens
|
|
|
|
To learn more, take a look at the following resources:
|
|
|
|
- [Trigger.dev Realtime](/realtime) - learn more about how to subscribe to runs and get real-time updates
|
|
- [Realtime streaming](/realtime/react-hooks/streams) - learn more about streaming data from your tasks
|
|
- [React hooks](/realtime/react-hooks) - learn more about using React hooks to interact with the Trigger.dev API
|
|
- [Waitpoint tokens](/wait-for-token) - learn about waitpoint tokens in Trigger.dev and human-in-the-loop flows
|