AI SDK v5 migration (#14549)

Co-authored-by: Félix Malfait <felix@twenty.com>
This commit is contained in:
Abdul Rahman
2025-09-23 01:43:43 +05:30
committed by GitHub
parent e8121919bd
commit 216d72b5d7
75 changed files with 1347 additions and 841 deletions
@@ -18,7 +18,7 @@ export class ToolRegistryService {
ToolType.SEND_EMAIL,
() => ({
description: this.sendEmailTool.description,
parameters: this.sendEmailTool.parameters,
inputSchema: this.sendEmailTool.inputSchema,
execute: (params) =>
this.sendEmailTool.execute(params as SendEmailInput),
flag: PermissionFlagType.SEND_EMAIL_TOOL,
@@ -6,7 +6,7 @@ export const HttpRequestInputZodSchema = z.object({
.enum(['GET', 'POST', 'PUT', 'PATCH', 'DELETE'])
.describe('The HTTP method to use'),
headers: z
.record(z.string())
.record(z.string(), z.string())
.optional()
.describe('HTTP headers to include in the request'),
body: z
@@ -13,7 +13,7 @@ import { type Tool } from 'src/engine/core-modules/tool/types/tool.type';
export class HttpTool implements Tool {
description =
'Make an HTTP request to any URL with configurable method, headers, and body.';
parameters = HttpToolParametersZodSchema;
inputSchema = HttpToolParametersZodSchema;
async execute(parameters: ToolInput): Promise<ToolOutput> {
const { url, method, headers, body } = parameters as HttpRequestInput;
@@ -1,11 +1,10 @@
import { z } from 'zod';
export const SendEmailInputZodSchema = z.object({
email: z.string().email().describe('The recipient email address'),
email: z.email().describe('The recipient email address'),
subject: z.string().describe('The email subject line'),
body: z.string().describe('The email body content (HTML or plain text)'),
connectedAccountId: z
.string()
.uuid()
.describe(
'The UUID of the connected account to send the email from. Provide this only if you have it; otherwise, leave blank.',
@@ -26,7 +26,7 @@ export class SendEmailTool implements Tool {
description =
'Send an email using a connected account. Requires SEND_EMAIL_TOOL permission.';
parameters = SendEmailToolParametersZodSchema;
inputSchema = SendEmailToolParametersZodSchema;
constructor(
private readonly scopedWorkspaceContextFactory: ScopedWorkspaceContextFactory,
@@ -91,7 +91,10 @@ export class SendEmailTool implements Tool {
let { connectedAccountId } = parameters;
try {
const emailSchema = z.string().trim().email('Invalid email');
const emailSchema = z
.string()
.trim()
.pipe(z.email({ error: 'Invalid email' }));
const emailValidation = emailSchema.safeParse(email);
if (!emailValidation.success) {
@@ -1,5 +1,4 @@
import { type JSONSchema7 } from 'json-schema';
import { type ZodType } from 'zod';
import { type FlexibleSchema } from '@ai-sdk/provider-utils';
import { type ToolInput } from 'src/engine/core-modules/tool/types/tool-input.type';
import { type ToolOutput } from 'src/engine/core-modules/tool/types/tool-output.type';
@@ -7,7 +6,7 @@ import { type PermissionFlagType } from 'src/engine/metadata-modules/permissions
export type Tool = {
description: string;
parameters: JSONSchema7 | ZodType;
inputSchema: FlexibleSchema<unknown>;
execute(input: ToolInput): Promise<ToolOutput>;
flag?: PermissionFlagType;
};