|
5 | 5 | <img alt="Trigger.dev logo" src="https://imagedelivery.net/3TbraffuDZ4aEf8KWOmI_w/a45d1fa2-0ae8-4a39-4409-f4f934bfae00/public"> |
6 | 6 | </picture> |
7 | 7 |
|
8 | | -# Official TypeScript SDK for Trigger.dev |
9 | | - |
10 | | -### 🤖 TypeScript SDK for building AI agents & workflows |
11 | | - |
12 | 8 | [](https://www.npmjs.com/package/@trigger.dev/sdk) |
13 | 9 | [](https://www.npmjs.com/package/@trigger.dev/sdk) |
14 | 10 | [](https://github.com/triggerdotdev/trigger.dev) |
|
20 | 16 |
|
21 | 17 | </div> |
22 | 18 |
|
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 |
146 | | - |
147 | | -## 🔧 Framework Support |
148 | | - |
149 | | -Trigger.dev works seamlessly with popular frameworks: |
150 | | - |
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 |
156 | | - |
157 | | -## 🧩 Popular Integrations |
158 | | - |
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"; |
164 | | - |
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 | | - }); |
174 | | - |
175 | | - // Database |
176 | | - const prisma = new PrismaClient(); |
177 | | - await prisma.result.create({ |
178 | | - data: { content: completion.choices[0].message.content }, |
179 | | - }); |
180 | | - |
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 | | - }); |
189 | | - |
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 |
| 19 | +# Official TypeScript SDK for Trigger.dev |
236 | 20 |
|
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 |
| 21 | +The Trigger.dev SDK is a TypeScript/JavaScript library that allows you to define and trigger tasks in your project. |
241 | 22 |
|
242 | | -## 📦 Related Packages |
| 23 | +## About Trigger.dev |
243 | 24 |
|
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 |
| 25 | +Trigger.dev is a platform for building and deploying fully-managed AI agents and workflows. Write workflows in normal async TypeScript for everything from simple tasks to long-running AI agents, heavy media processing, complex real-time systems and more. Complete with trace visibility, managed queues, and elastic infrastructure which handles the horizontal scaling. |
247 | 26 |
|
248 | | -## 📄 License |
| 27 | +## Getting started |
249 | 28 |
|
250 | | -MIT License - see the [LICENSE](https://github.com/triggerdotdev/trigger.dev/blob/main/LICENSE) file for details. |
| 29 | +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. |
251 | 30 |
|
252 | | -## ⭐ Contributing |
| 31 | +## SDK usage |
253 | 32 |
|
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. |
| 33 | +For more information on our SDK, refer to our [docs](https://trigger.dev/docs/introduction). |
255 | 34 |
|
256 | | ---- |
| 35 | +## Support |
257 | 36 |
|
258 | | -<div align="center"> |
259 | | - <strong>Built with ❤️ by the Trigger.dev team</strong> |
260 | | -</div> |
| 37 | +If you have any questions, please reach out to us on [Discord](https://trigger.dev/discord) and we'll be happy to help. |
0 commit comments