Skip to content

Commit d36b7cb

Browse files
committed
readme wip
1 parent da7dc74 commit d36b7cb

File tree

1 file changed

+240
-14
lines changed

1 file changed

+240
-14
lines changed

packages/trigger-sdk/README.md

Lines changed: 240 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,257 @@
44
<source media="(prefers-color-scheme: light)" srcset="https://imagedelivery.net/3TbraffuDZ4aEf8KWOmI_w/3f5ad4c1-c4c8-4277-b622-290e7f37bd00/public">
55
<img alt="Trigger.dev logo" src="https://imagedelivery.net/3TbraffuDZ4aEf8KWOmI_w/a45d1fa2-0ae8-4a39-4409-f4f934bfae00/public">
66
</picture>
7-
8-
### Open source background jobs with no timeouts
97

10-
[Discord](https://trigger.dev/discord) | [Website](https://trigger.dev) | [Issues](https://github.com/triggerdotdev/trigger.dev/issues) | [Docs](https://trigger.dev/docs)
8+
# Official TypeScript SDK for Trigger.dev
9+
10+
### 🤖 TypeScript SDK for building AI agents & workflows
1111

12-
[![Twitter](https://img.shields.io/twitter/url/https/twitter.com/triggerdotdev.svg?style=social&label=Follow%20%40trigger.dev)](https://twitter.com/triggerdotdev)
12+
[![npm version](https://img.shields.io/npm/v/@trigger.dev/sdk.svg)](https://www.npmjs.com/package/@trigger.dev/sdk)
13+
[![npm downloads](https://img.shields.io/npm/dm/@trigger.dev/sdk.svg)](https://www.npmjs.com/package/@trigger.dev/sdk)
14+
[![GitHub stars](https://img.shields.io/github/stars/triggerdotdev/trigger.dev?style=social)](https://github.com/triggerdotdev/trigger.dev)
15+
[![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](https://www.typescriptlang.org/)
16+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
17+
[![Open Source](https://img.shields.io/badge/Open%20Source-%E2%9D%A4-red)](https://github.com/triggerdotdev/trigger.dev)
18+
19+
[Discord](https://trigger.dev/discord) | [Website](https://trigger.dev) | [Issues](https://github.com/triggerdotdev/trigger.dev/issues) | [Docs](https://trigger.dev/docs) | [Examples](https://trigger.dev/docs/examples)
1320

1421
</div>
1522

16-
# Official TypeScript SDK for Trigger.dev
23+
The **Trigger.dev SDK** enables you to create reliable, long-running AI agents and workflows in your TypeScript applications. Connect to the Trigger.dev platform (cloud or self-hosted) to execute jobs without timeouts, with built-in retries and monitoring.
24+
25+
## ✨ What you get with this SDK
26+
27+
- **Write normal async code** - No special syntax, just regular TypeScript functions
28+
- **No timeouts** - Tasks can run for hours or days without failing
29+
- **Built-in reliability** - Automatic retries, error handling, and durable execution
30+
- **Real-time observability** - Watch your tasks execute with full OpenTelemetry tracing
31+
- **Local development** - Test and debug tasks locally with the same environment
32+
- **Checkpoint-resume system** - Efficient resource usage with automatic state management
33+
- **50+ integrations** - Pre-built connectors for AI, databases, and external services
34+
- **Framework agnostic** - Works with Next.js, Express, Fastify, Remix, and more
35+
36+
## 🚀 Quick Start
37+
38+
### Installation
39+
40+
```bash
41+
npm install @trigger.dev/sdk
42+
# or
43+
yarn add @trigger.dev/sdk
44+
# or
45+
pnpm add @trigger.dev/sdk
46+
```
47+
48+
### Basic Usage
49+
50+
```typescript
51+
import { TriggerClient, eventTrigger } from "@trigger.dev/sdk";
52+
53+
const client = new TriggerClient({
54+
id: "my-app",
55+
apiKey: process.env.TRIGGER_API_KEY!,
56+
});
57+
58+
// Define a background task - just normal async code
59+
export const generateContent = task({
60+
id: "generate-content",
61+
retry: {
62+
maxAttempts: 3,
63+
},
64+
run: async ({ theme, description }: { theme: string; description: string }) => {
65+
// Generate text with OpenAI
66+
const textResult = await openai.chat.completions.create({
67+
model: "gpt-4o",
68+
messages: [{ role: "user", content: `Create content about ${theme}: ${description}` }],
69+
});
70+
71+
if (!textResult.choices[0]) {
72+
throw new Error("No content generated, retrying...");
73+
}
74+
75+
// Generate an image
76+
const imageResult = await openai.images.generate({
77+
model: "dall-e-3",
78+
prompt: `Create an image for: ${theme}`,
79+
});
80+
81+
if (!imageResult.data[0]) {
82+
throw new Error("No image generated, retrying...");
83+
}
84+
85+
return {
86+
text: textResult.choices[0].message.content,
87+
image: imageResult.data[0].url,
88+
};
89+
},
90+
});
91+
92+
// Trigger the task from your app
93+
import { tasks } from "@trigger.dev/sdk/v3";
94+
95+
const handle = await tasks.trigger<typeof generateContent>("generate-content", {
96+
theme: "AI automation",
97+
description: "How AI is transforming business workflows",
98+
});
99+
```
100+
101+
### Scheduled Tasks & Workflows
102+
103+
```typescript
104+
import { schedules } from "@trigger.dev/sdk/v3";
105+
106+
// Scheduled task - runs every Monday at 9 AM
107+
export const weeklyReport = schedules.task({
108+
id: "weekly-report",
109+
cron: "0 9 * * MON",
110+
run: async () => {
111+
// Multi-step workflow with automatic retries
112+
const data = await analyzeMetrics.triggerAndWait({
113+
timeframe: "week",
114+
});
115+
116+
const report = await generateReport.triggerAndWait({
117+
data: data.output,
118+
format: "pdf",
119+
});
120+
121+
// Send to team - runs in parallel
122+
await Promise.all([
123+
sendEmail.trigger({
124+
125+
subject: "Weekly Report",
126+
attachment: report.output.url,
127+
}),
128+
uploadToS3.trigger({
129+
file: report.output,
130+
bucket: "reports",
131+
}),
132+
]);
133+
134+
return { success: true, reportId: report.output.id };
135+
},
136+
});
137+
```
138+
139+
## 📚 Documentation
140+
141+
- **[Getting Started Guide](https://trigger.dev/docs/introduction)** - Complete setup walkthrough
142+
- **[API Reference](https://trigger.dev/docs/sdk/introduction)** - Detailed API documentation
143+
- **[Examples](https://trigger.dev/docs/examples)** - Real-world examples and use cases
144+
- **[Integrations](https://trigger.dev/docs/integrations)** - Pre-built integrations catalog
145+
- **[Best Practices](https://trigger.dev/docs/guides/best-practices)** - Production tips and patterns
17146

18-
The Trigger.dev SDK is a TypeScript/JavaScript library that allows you to define and trigger tasks in your project.
147+
## 🔧 Framework Support
19148

20-
## About
149+
Trigger.dev works seamlessly with popular frameworks:
21150

22-
Trigger.dev is an open source platform and SDK which allows you to create long-running background jobs. Write normal async code, deploy, and never hit a timeout.
151+
- **[Next.js](https://trigger.dev/docs/guides/frameworks/nextjs)** - App Router and Pages Router
152+
- **[Express](https://trigger.dev/docs/guides/frameworks/express)** - Traditional Node.js apps
153+
- **[Fastify](https://trigger.dev/docs/guides/frameworks/fastify)** - High-performance web framework
154+
- **[Remix](https://trigger.dev/docs/guides/frameworks/remix)** - Full-stack web framework
155+
- **[NestJS](https://trigger.dev/docs/guides/frameworks/nestjs)** - Enterprise Node.js framework
23156

24-
## Getting started
157+
## 🧩 Popular Integrations
25158

26-
The quickest way to get started is to create an account in our [web app](https://cloud.trigger.dev), create a new project and follow the instructions in the onboarding. Build and deploy your first task in minutes.
159+
```typescript
160+
// Use any npm package - no special integrations needed
161+
import OpenAI from "openai";
162+
import { PrismaClient } from "@prisma/client";
163+
import { Resend } from "resend";
27164

28-
## SDK usage
165+
export const processWithAI = task({
166+
id: "process-with-ai",
167+
run: async ({ input }: { input: string }) => {
168+
// OpenAI
169+
const openai = new OpenAI();
170+
const completion = await openai.chat.completions.create({
171+
model: "gpt-4o",
172+
messages: [{ role: "user", content: input }],
173+
});
29174

30-
For more information on our SDK, refer to our [docs](https://trigger.dev/docs/introduction).
175+
// Database
176+
const prisma = new PrismaClient();
177+
await prisma.result.create({
178+
data: { content: completion.choices[0].message.content },
179+
});
31180

32-
## Support
181+
// Email
182+
const resend = new Resend();
183+
await resend.emails.send({
184+
185+
186+
subject: "Processing Complete",
187+
text: completion.choices[0].message.content,
188+
});
33189

34-
If you have any questions, please reach out to us on [Discord](https://trigger.dev/discord) and we'll be happy to help.
190+
return { success: true };
191+
},
192+
});
193+
```
194+
195+
## 🏃‍♂️ Getting Started
196+
197+
### 1. Install the SDK
198+
199+
```bash
200+
npm install @trigger.dev/sdk
201+
```
202+
203+
### 2. Set up your project
204+
205+
```bash
206+
npx @trigger.dev/cli@latest init
207+
```
208+
209+
### 3. Connect to Trigger.dev
210+
211+
Choose your deployment option:
212+
213+
- **[Trigger.dev Cloud](https://cloud.trigger.dev)** - Managed service (recommended)
214+
- **[Self-hosted](https://trigger.dev/docs/self-hosting)** - Deploy on your infrastructure
215+
216+
### 4. Deploy your jobs
217+
218+
```bash
219+
npx @trigger.dev/cli@latest deploy
220+
```
221+
222+
Or follow our comprehensive [Getting Started Guide](https://trigger.dev/docs/introduction).
223+
224+
## 💡 Example Tasks
225+
226+
Check out our [examples repository](https://github.com/triggerdotdev/trigger.dev/tree/main/examples) for production-ready workflows:
227+
228+
- [AI agents & workflows](https://trigger.dev/docs/examples) - Build invincible AI agents with tools and memory
229+
- [Video processing with FFmpeg](https://trigger.dev/docs/examples/ffmpeg) - Process videos without timeouts
230+
- [PDF generation & processing](https://trigger.dev/docs/examples) - Convert documents at scale
231+
- [Email campaigns](https://trigger.dev/docs/examples) - Multi-step email automation
232+
- [Data pipelines](https://trigger.dev/docs/examples) - ETL processes and database sync
233+
- [Web scraping](https://trigger.dev/docs/examples) - Scrape websites with Puppeteer
234+
235+
## 🤝 Community & Support
236+
237+
- **[Discord Community](https://trigger.dev/discord)** - Get help and share ideas
238+
- **[GitHub Issues](https://github.com/triggerdotdev/trigger.dev/issues)** - Bug reports and feature requests
239+
- **[Twitter](https://twitter.com/triggerdotdev)** - Latest updates and news
240+
- **[Blog](https://trigger.dev/blog)** - Tutorials and best practices
241+
242+
## 📦 Related Packages
243+
244+
- **[@trigger.dev/cli](https://www.npmjs.com/package/@trigger.dev/cli)** - Command line interface
245+
- **[@trigger.dev/react-hooks](https://www.npmjs.com/package/@trigger.dev/react-hooks)** - React hooks for real-time job monitoring
246+
- **[@trigger.dev/nextjs](https://www.npmjs.com/package/@trigger.dev/nextjs)** - Next.js specific utilities
247+
248+
## 📄 License
249+
250+
MIT License - see the [LICENSE](https://github.com/triggerdotdev/trigger.dev/blob/main/LICENSE) file for details.
251+
252+
## ⭐ Contributing
253+
254+
We love contributions! Please see our [Contributing Guide](https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md) for details on how to get started.
255+
256+
---
257+
258+
<div align="center">
259+
<strong>Built with ❤️ by the Trigger.dev team</strong>
260+
</div>

0 commit comments

Comments
 (0)