Skip to content

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

Merged
merged 2 commits into from
Aug 15, 2025
Merged

feat: AI SDK 5.0 support #2396

merged 2 commits into from
Aug 15, 2025

Conversation

ericallam
Copy link
Member

No description provided.

Copy link

changeset-bot bot commented Aug 14, 2025

🦋 Changeset detected

Latest 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

Copy link
Contributor

coderabbitai bot commented Aug 14, 2025

Walkthrough

  • Adds a changeset for a patch release mentioning AI SDK 5.0 support and ai.tool accepting schemaTask or a task with jsonSchema.
  • packages/core: Task interface now includes optional jsonSchema: JSONSchema.
  • packages/trigger-sdk/package.json: bumps devDependency ai to ^5.0.0; peerDependency widened to ^4.2.0 || ^5.0.0.
  • packages/trigger-sdk/src/v3/ai.ts: switches tool creation from tool to dynamicTool; updates ToolCallExecutionOptions to derive from ToolCallOptions; expands toolFromTask overloads; adjusts execution to use inputSchema; enhances schema conversion to support ArkType, Zod, or explicit jsonSchema; updated error messages.
  • packages/trigger-sdk/src/v3/shared.ts: createTask now sets jsonSchema from params.

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 Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/ai-sdk-5

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 intersection

Calling task.triggerAndWait(input as inferSchemaIn<TTaskSchema>, ...) against a union type can force an unsafe intersection of call signatures and may fail type-checking when task is a plain Task (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 punctuation

Small 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 message

There’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 optional

Avoid using the in operator on a possibly undefined task.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.

📥 Commits

Reviewing files that changed from the base of the PR and between f767654 and e4fa87b.

⛔ 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 complete

Scanned 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 — LGTM

Adding 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 — LGTM

Surfacing 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 — LGTM

The 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

@c0dezli
Copy link

c0dezli commented Aug 14, 2025

^ need this

@matt-aitken matt-aitken merged commit 3d17ce5 into main Aug 15, 2025
31 checks passed
@matt-aitken matt-aitken deleted the feat/ai-sdk-5 branch August 15, 2025 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants