-
-
Notifications
You must be signed in to change notification settings - Fork 784
feat: AI SDK 5.0 support #2396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: AI SDK 5.0 support #2396
Conversation
🦋 Changeset detectedLatest commit: e4fa87b The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Walkthrough
Estimated code review effort🎯 4 (Complex) | ⏱️ ~40 minutes Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🔭 Outside diff range comments (1)
packages/trigger-sdk/src/v3/ai.ts (1)
64-74
: Narrow the union before calling triggerAndWait to avoid unsafe call-signature intersectionCalling
task.triggerAndWait(input as inferSchemaIn<TTaskSchema>, ...)
against a union type can force an unsafe intersection of call signatures and may fail type-checking whentask
is a plainTask
(no schema). Narrow first so each branch uses the correct payload type.- execute: async (input, options) => { - const serializedOptions = options ? JSON.parse(JSON.stringify(options)) : undefined; - - return await task - .triggerAndWait(input as inferSchemaIn<TTaskSchema>, { - metadata: { - [METADATA_KEY]: serializedOptions, - }, - }) - .unwrap(); - }, + execute: async (input, options) => { + const serializedOptions = options ? JSON.parse(JSON.stringify(options)) : undefined; + + if ("schema" in task && task.schema) { + return await task + .triggerAndWait(input as inferSchemaIn<TTaskSchema>, { + metadata: { [METADATA_KEY]: serializedOptions }, + }) + .unwrap(); + } + + // Plain Task with jsonSchema + return await (task as Task<TIdentifier, TInput, TOutput>) + .triggerAndWait(input as TInput, { + metadata: { [METADATA_KEY]: serializedOptions }, + }) + .unwrap(); + },
🧹 Nitpick comments (3)
.changeset/famous-clocks-thank.md (1)
1-6
: Nit: tighten wording and punctuationSmall phrasing/punctuation tweak for clarity.
-feat: Support AI SDK 5.0. `ai.tool` now accepts either a schemaTask or a task with a provided jsonSchema +feat: Support AI SDK 5.0. `ai.tool()` now accepts either a `schemaTask` or a task with a provided `jsonSchema`.packages/trigger-sdk/src/v3/ai.ts (2)
55-58
: Fix typo in error messageThere’s a duplicated word (“to to”) and a minor phrasing nit.
- "Cannot convert this task to to a tool because the task has no schema. Make sure to either use schemaTask or a task with an input jsonSchema." + "Cannot convert this task to a tool because the task has no schema. Make sure to either use a schemaTask or a task with an input jsonSchema."
91-104
: Make schema conversion more robust when schema is optionalAvoid using the
in
operator on a possibly undefinedtask.schema
and guard explicitly. This prevents future regressions if the converter gets reused outside the guarded path.-function convertTaskSchemaToToolParameters( - task: AnyTask | TaskWithSchema<any, any, any> -): Schema<unknown> { - if ("schema" in task) { - // If TaskSchema is ArkTypeEsque, use ai.jsonSchema to convert it to a Schema - if ("toJsonSchema" in task.schema && typeof task.schema.toJsonSchema === "function") { - return jsonSchema((task.schema as any).toJsonSchema()); - } - - // If TaskSchema is ZodEsque, use ai.zodSchema to convert it to a Schema - if (isSchemaZodEsque(task.schema)) { - return zodSchema(task.schema as any); - } - } - - if ("jsonSchema" in task) { - return jsonSchema(task.jsonSchema as JSONSchema7); - } +function convertTaskSchemaToToolParameters( + task: AnyTask | TaskWithSchema<any, any, any> +): Schema<unknown> { + if ("schema" in task && task.schema) { + const s = task.schema as any; + // If TaskSchema is ArkTypeEsque, use ai.jsonSchema to convert it to a Schema + if (typeof s?.toJsonSchema === "function") { + return jsonSchema(s.toJsonSchema()); + } + + // If TaskSchema is ZodEsque, use ai.zodSchema to convert it to a Schema + if (isSchemaZodEsque(s)) { + return zodSchema(s); + } + } + + if ("jsonSchema" in task && task.jsonSchema) { + return jsonSchema(task.jsonSchema as JSONSchema7); + }Also applies to: 106-108, 111-111
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these settings in your CodeRabbit configuration.
⛔ Files ignored due to path filters (4)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
references/d3-chat/package.json
is excluded by!references/**
references/d3-chat/src/components/chat-container.tsx
is excluded by!references/**
references/d3-chat/src/trigger/chat.ts
is excluded by!references/**
📒 Files selected for processing (5)
.changeset/famous-clocks-thank.md
(1 hunks)packages/core/src/v3/types/tasks.ts
(1 hunks)packages/trigger-sdk/package.json
(2 hunks)packages/trigger-sdk/src/v3/ai.ts
(4 hunks)packages/trigger-sdk/src/v3/shared.ts
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)
**/*.{ts,tsx}
: Always prefer using isomorphic code like fetch, ReadableStream, etc. instead of Node.js specific code
For TypeScript, we usually use types over interfaces
Avoid enums
No default exports, use function declarations
Files:
packages/core/src/v3/types/tasks.ts
packages/trigger-sdk/src/v3/shared.ts
packages/trigger-sdk/src/v3/ai.ts
{packages/core,apps/webapp}/**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)
We use zod a lot in packages/core and in the webapp
Files:
packages/core/src/v3/types/tasks.ts
🧠 Learnings (13)
📓 Common learnings
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : When implementing schema tasks, use `schemaTask` from `trigger.dev/sdk/v3` and validate payloads as shown.
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : You MUST use `trigger.dev/sdk/v3` when writing Trigger.dev tasks.
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : ALWAYS generate Trigger.dev tasks using the `task` function from `trigger.dev/sdk/v3` and export them as shown in the correct pattern.
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : When implementing scheduled (cron) tasks, use `schedules.task` from `trigger.dev/sdk/v3` and follow the shown patterns.
📚 Learning: 2025-07-18T17:50:25.014Z
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : You MUST use `trigger.dev/sdk/v3` when writing Trigger.dev tasks.
Applied to files:
packages/trigger-sdk/package.json
.changeset/famous-clocks-thank.md
packages/trigger-sdk/src/v3/shared.ts
packages/trigger-sdk/src/v3/ai.ts
📚 Learning: 2025-07-18T17:50:25.014Z
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : ALWAYS generate Trigger.dev tasks using the `task` function from `trigger.dev/sdk/v3` and export them as shown in the correct pattern.
Applied to files:
packages/trigger-sdk/package.json
packages/trigger-sdk/src/v3/shared.ts
packages/trigger-sdk/src/v3/ai.ts
📚 Learning: 2025-07-18T17:50:25.014Z
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : When implementing schema tasks, use `schemaTask` from `trigger.dev/sdk/v3` and validate payloads as shown.
Applied to files:
packages/core/src/v3/types/tasks.ts
.changeset/famous-clocks-thank.md
packages/trigger-sdk/src/v3/shared.ts
packages/trigger-sdk/src/v3/ai.ts
📚 Learning: 2025-07-18T17:50:25.014Z
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : If you are able to generate an example payload for a task, do so.
Applied to files:
packages/trigger-sdk/src/v3/shared.ts
📚 Learning: 2025-07-18T17:50:25.014Z
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : When triggering a task from backend code, use `tasks.trigger`, `tasks.batchTrigger`, or `tasks.triggerAndPoll` as shown in the examples.
Applied to files:
packages/trigger-sdk/src/v3/shared.ts
packages/trigger-sdk/src/v3/ai.ts
📚 Learning: 2025-07-18T17:50:25.014Z
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : The `run` function contains your task logic in Trigger.dev tasks.
Applied to files:
packages/trigger-sdk/src/v3/shared.ts
📚 Learning: 2025-07-18T17:50:25.014Z
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Each task needs a unique ID within your project.
Applied to files:
packages/trigger-sdk/src/v3/shared.ts
📚 Learning: 2025-07-18T17:50:25.014Z
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : When implementing scheduled (cron) tasks, use `schedules.task` from `trigger.dev/sdk/v3` and follow the shown patterns.
Applied to files:
packages/trigger-sdk/src/v3/shared.ts
packages/trigger-sdk/src/v3/ai.ts
📚 Learning: 2025-07-18T17:50:25.014Z
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : When using metadata in tasks, use the `metadata` API as shown, and only inside run functions or task lifecycle hooks.
Applied to files:
packages/trigger-sdk/src/v3/ai.ts
📚 Learning: 2025-07-18T17:50:25.014Z
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Tasks must be exported, even subtasks in the same file.
Applied to files:
packages/trigger-sdk/src/v3/ai.ts
📚 Learning: 2025-07-18T17:50:25.014Z
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : You MUST `export` every task, including subtasks, in Trigger.dev task files.
Applied to files:
packages/trigger-sdk/src/v3/ai.ts
📚 Learning: 2025-07-18T17:50:25.014Z
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Before generating any code for Trigger.dev tasks, verify: (1) Are you importing from `trigger.dev/sdk/v3`? (2) Have you exported every task? (3) Have you generated any deprecated code patterns?
Applied to files:
packages/trigger-sdk/src/v3/ai.ts
🧬 Code Graph Analysis (2)
packages/core/src/v3/types/tasks.ts (3)
packages/core/src/v3/types/jsonSchema.ts (1)
JSONSchema
(5-67)packages/schema-to-json/src/index.ts (1)
JSONSchema
(5-5)packages/trigger-sdk/src/v3/schemas.ts (1)
JSONSchema
(2-2)
packages/trigger-sdk/src/v3/ai.ts (3)
packages/core/src/v3/types/tasks.ts (5)
Task
(542-623)TaskSchema
(34-34)TaskWithSchema
(625-631)inferSchemaIn
(35-35)AnyTask
(645-645)packages/core/src/v3/types/schemas.ts (3)
inferSchemaIn
(91-94)Schema
(74-74)isSchemaZodEsque
(6-16)packages/core/src/v3/index.ts (1)
isSchemaZodEsque
(78-78)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (23)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (8, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (6, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (7, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (5, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (2, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (4, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (1, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (3, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (2, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (5, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (7, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (8, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (3, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (1, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (4, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (6, 8)
- GitHub Check: units / packages / 🧪 Unit Tests: Packages (1, 1)
- GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - npm)
- GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - pnpm)
- GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
- GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
- GitHub Check: typecheck / typecheck
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (4)
packages/trigger-sdk/package.json (1)
71-71
: Peer range widened to include AI SDK 5.x — verification completeScanned all package.json files; findings:
- apps/webapp/package.json: dependencies.ai = ^4.3.19
- packages/core/package.json: devDependencies.ai = ^3.4.33
- packages/trigger-sdk/package.json: devDependencies.ai = ^5.0.0, peerDependencies.ai = ^4.2.0 || ^5.0.0
Conclusion: trigger-sdk's peer range ( ^4.2.0 || ^5.0.0 ) is compatible with apps/webapp's ^4.3.19, so no install-time conflict detected. packages/core's 3.x entry is a devDependency only and not blocking. No change required for this PR.
packages/core/src/v3/types/tasks.ts (1)
550-551
: Expose jsonSchema on Task — LGTMAdding
jsonSchema?: JSONSchema
to the Task interface aligns the public type with the new AI tooling path and is consistent with the changes in the SDK.packages/trigger-sdk/src/v3/shared.ts (1)
165-165
: Propagate jsonSchema into returned Task — LGTMSurfacing
jsonSchema: params.jsonSchema
on the Task instance keeps runtime shape in sync with the updated type and enables downstream tool conversion.packages/trigger-sdk/src/v3/ai.ts (1)
32-36
: Migration to dynamicTool and overloads — LGTMThe switch to
dynamicTool
, expanded overloads, and conditional return typing match AI SDK 5.0 expectations and keep strong typing for both schema and jsonSchema scenarios.Also applies to: 41-44, 78-80
^ need this |
No description provided.