Skip to content

Commit 1e5350a

Browse files
committed
Some tweaks and added a Replicate example
1 parent f5d73f4 commit 1e5350a

File tree

5 files changed

+126
-7
lines changed

5 files changed

+126
-7
lines changed
Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
1-
import { PhoneArrowDownLeftIcon } from "@heroicons/react/20/solid";
2-
31
export function HttpCallbackIcon({ className }: { className?: string }) {
4-
return <PhoneArrowDownLeftIcon className={className} />;
2+
return (
3+
<svg
4+
className={className}
5+
xmlns="http://www.w3.org/2000/svg"
6+
viewBox="0 0 24 24"
7+
fill="none"
8+
stroke="currentColor"
9+
strokeWidth="2"
10+
strokeLinecap="round"
11+
strokeLinejoin="round"
12+
>
13+
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
14+
<path d="M21 12a9 9 0 1 0 -9 9" />
15+
<path d="M3.6 9h16.8" />
16+
<path d="M3.6 15h8.4" />
17+
<path d="M11.578 3a17 17 0 0 0 0 18" />
18+
<path d="M12.5 3c1.719 2.755 2.5 5.876 2.5 9" />
19+
<path d="M18 21v-7m3 3l-3 -3l-3 3" />
20+
</svg>
21+
);
522
}

apps/webapp/app/components/runs/v3/WaitpointDetails.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ import { WaitpointStatusCombo } from "./WaitpointStatus";
1717
import { RunTag } from "./RunTag";
1818
import { CopyableText } from "~/components/primitives/CopyableText";
1919
import { ClipboardField } from "~/components/primitives/ClipboardField";
20+
import { WaitpointResolver } from "@trigger.dev/database";
21+
import { WaitpointTokenIcon } from "~/assets/icons/WaitpointTokenIcon";
22+
import { HttpCallbackIcon } from "~/assets/icons/HttpCallbackIcon";
2023

2124
export function WaitpointDetailTable({
2225
waitpoint,
@@ -62,6 +65,12 @@ export function WaitpointDetailTable({
6265
)}
6366
</Property.Value>
6467
</Property.Item>
68+
<Property.Item>
69+
<Property.Label>Type</Property.Label>
70+
<Property.Value>
71+
<WaitpointResolverCombo resolver={waitpoint.resolver} />
72+
</Property.Value>
73+
</Property.Item>
6574
{waitpoint.callbackUrl && (
6675
<Property.Item>
6776
<Property.Label>Callback URL</Property.Label>
@@ -148,3 +157,22 @@ export function WaitpointDetailTable({
148157
</Property.Table>
149158
);
150159
}
160+
161+
export function WaitpointResolverCombo({ resolver }: { resolver: WaitpointResolver }) {
162+
switch (resolver) {
163+
case "TOKEN":
164+
return (
165+
<div className="flex items-center gap-1">
166+
<WaitpointTokenIcon className="size-4" />
167+
<span>Token</span>
168+
</div>
169+
);
170+
case "HTTP_CALLBACK":
171+
return (
172+
<div className="flex items-center gap-1">
173+
<HttpCallbackIcon className="size-4" />
174+
<span>HTTP Callback</span>
175+
</div>
176+
);
177+
}
178+
}

pnpm-lock.yaml

Lines changed: 38 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

references/hello-world/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
},
88
"dependencies": {
99
"@trigger.dev/sdk": "workspace:*",
10+
"openai": "^4.97.0",
11+
"replicate": "^1.0.1",
1012
"zod": "3.23.8"
1113
},
1214
"scripts": {

references/hello-world/src/trigger/waits.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { logger, wait, task, retry, idempotencyKeys, auth } from "@trigger.dev/sdk/v3";
2-
import { z } from "zod";
1+
import { auth, idempotencyKeys, logger, retry, task, wait } from "@trigger.dev/sdk/v3";
2+
import Replicate, { Prediction } from "replicate";
33
type Token = {
44
status: "approved" | "pending" | "rejected";
55
};
@@ -143,7 +143,43 @@ export const waitForDuration = task({
143143

144144
export const waitHttpCallback = task({
145145
id: "wait-http-callback",
146+
retry: {
147+
maxAttempts: 1,
148+
},
146149
run: async () => {
150+
if (process.env.REPLICATE_API_KEY) {
151+
const replicate = new Replicate({
152+
auth: process.env.REPLICATE_API_KEY,
153+
});
154+
155+
const prediction = await wait.forHttpCallback<Prediction>(
156+
async (url) => {
157+
//pass the provided URL to Replicate's webhook
158+
await replicate.predictions.create({
159+
version: "27b93a2413e7f36cd83da926f3656280b2931564ff050bf9575f1fdf9bcd7478",
160+
input: {
161+
prompt: "A painting of a cat by Any Warhol",
162+
},
163+
// pass the provided URL to Replicate's webhook, so they can "callback"
164+
webhook: url,
165+
webhook_events_filter: ["completed"],
166+
});
167+
},
168+
{
169+
timeout: "10m",
170+
}
171+
);
172+
173+
if (!prediction.ok) {
174+
throw new Error("Failed to create prediction");
175+
}
176+
177+
logger.log("Prediction", prediction);
178+
179+
const imageUrl = prediction.output.output;
180+
logger.log("Image URL", imageUrl);
181+
}
182+
147183
const result = await wait.forHttpCallback<{ foo: string }>(
148184
async (url) => {
149185
logger.log(`Wait for HTTP callback ${url}`);

0 commit comments

Comments
 (0)