@mastra/core 1.0.0-beta.16 → 1.0.0-beta.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/dist/agent/index.cjs +8 -8
- package/dist/agent/index.js +1 -1
- package/dist/{chunk-UT6MASE5.cjs → chunk-2OOMJRXZ.cjs} +3 -3
- package/dist/{chunk-UT6MASE5.cjs.map → chunk-2OOMJRXZ.cjs.map} +1 -1
- package/dist/{chunk-F7PAZAGE.js → chunk-2XX35XRX.js} +8 -9
- package/dist/chunk-2XX35XRX.js.map +1 -0
- package/dist/{chunk-QD776HMB.js → chunk-5YYAQUEF.js} +3 -3
- package/dist/{chunk-QD776HMB.js.map → chunk-5YYAQUEF.js.map} +1 -1
- package/dist/{chunk-UTMBASR5.js → chunk-6R4744NH.js} +4 -4
- package/dist/{chunk-UTMBASR5.js.map → chunk-6R4744NH.js.map} +1 -1
- package/dist/{chunk-CSCTVLD5.js → chunk-6RFJWX4V.js} +3 -3
- package/dist/{chunk-CSCTVLD5.js.map → chunk-6RFJWX4V.js.map} +1 -1
- package/dist/{chunk-KKYAYRIO.js → chunk-ABMWK6JU.js} +4 -4
- package/dist/{chunk-KKYAYRIO.js.map → chunk-ABMWK6JU.js.map} +1 -1
- package/dist/{chunk-37YWZMBX.js → chunk-AIJLACR2.js} +9 -5
- package/dist/chunk-AIJLACR2.js.map +1 -0
- package/dist/{chunk-WDXYPI3P.js → chunk-AR5CF3IN.js} +3 -3
- package/dist/{chunk-WDXYPI3P.js.map → chunk-AR5CF3IN.js.map} +1 -1
- package/dist/{chunk-4UH5LAF5.cjs → chunk-BWZ6UOBF.cjs} +15 -15
- package/dist/{chunk-4UH5LAF5.cjs.map → chunk-BWZ6UOBF.cjs.map} +1 -1
- package/dist/{chunk-DT5RMENY.js → chunk-CHVWQDMP.js} +39 -5
- package/dist/chunk-CHVWQDMP.js.map +1 -0
- package/dist/{chunk-OXV6QFSV.cjs → chunk-G6YCU7HJ.cjs} +8 -8
- package/dist/{chunk-OXV6QFSV.cjs.map → chunk-G6YCU7HJ.cjs.map} +1 -1
- package/dist/{chunk-5DL6Y7PJ.cjs → chunk-GFALVOBW.cjs} +35 -36
- package/dist/chunk-GFALVOBW.cjs.map +1 -0
- package/dist/{chunk-NNFF3URD.js → chunk-IHPCE24V.js} +8 -8
- package/dist/{chunk-NNFF3URD.js.map → chunk-IHPCE24V.js.map} +1 -1
- package/dist/{chunk-33VDGXRH.cjs → chunk-IY5QWADY.cjs} +16 -16
- package/dist/{chunk-33VDGXRH.cjs.map → chunk-IY5QWADY.cjs.map} +1 -1
- package/dist/{chunk-FB5QMTJJ.js → chunk-JBEKXEX6.js} +4 -4
- package/dist/{chunk-FB5QMTJJ.js.map → chunk-JBEKXEX6.js.map} +1 -1
- package/dist/{chunk-4KVIXN7K.cjs → chunk-NGRUGDFP.cjs} +14 -14
- package/dist/{chunk-4KVIXN7K.cjs.map → chunk-NGRUGDFP.cjs.map} +1 -1
- package/dist/{chunk-6YUHA5UH.cjs → chunk-O4YSWWLB.cjs} +5 -5
- package/dist/{chunk-6YUHA5UH.cjs.map → chunk-O4YSWWLB.cjs.map} +1 -1
- package/dist/{chunk-A6JNGJIU.cjs → chunk-P3XQ3TNY.cjs} +30 -30
- package/dist/{chunk-A6JNGJIU.cjs.map → chunk-P3XQ3TNY.cjs.map} +1 -1
- package/dist/{chunk-4N6WB4EZ.js → chunk-POSO2X6D.js} +6 -6
- package/dist/{chunk-4N6WB4EZ.js.map → chunk-POSO2X6D.js.map} +1 -1
- package/dist/{chunk-GNUITL2N.js → chunk-RC7RN5MY.js} +3 -3
- package/dist/{chunk-GNUITL2N.js.map → chunk-RC7RN5MY.js.map} +1 -1
- package/dist/{chunk-AQ22JIR7.cjs → chunk-SDR22R4D.cjs} +16 -16
- package/dist/{chunk-AQ22JIR7.cjs.map → chunk-SDR22R4D.cjs.map} +1 -1
- package/dist/{chunk-7KL2YFFK.cjs → chunk-SGRMJZMJ.cjs} +15 -15
- package/dist/{chunk-7KL2YFFK.cjs.map → chunk-SGRMJZMJ.cjs.map} +1 -1
- package/dist/{chunk-K4XAKG7L.js → chunk-TI6D7CAN.js} +4 -4
- package/dist/{chunk-K4XAKG7L.js.map → chunk-TI6D7CAN.js.map} +1 -1
- package/dist/{chunk-H2NHG7QL.cjs → chunk-VW7YQWDW.cjs} +9 -5
- package/dist/chunk-VW7YQWDW.cjs.map +1 -0
- package/dist/{chunk-NCAMNQC3.cjs → chunk-XIYLL4DN.cjs} +40 -6
- package/dist/chunk-XIYLL4DN.cjs.map +1 -0
- package/dist/{chunk-NK4UN2LF.cjs → chunk-XR7RX2PS.cjs} +5 -5
- package/dist/{chunk-NK4UN2LF.cjs.map → chunk-XR7RX2PS.cjs.map} +1 -1
- package/dist/{chunk-J4SXS7KN.js → chunk-Y52PV3W4.js} +4 -4
- package/dist/{chunk-J4SXS7KN.js.map → chunk-Y52PV3W4.js.map} +1 -1
- package/dist/{chunk-3ZRMVPQA.cjs → chunk-ZSQ7L6AW.cjs} +7 -7
- package/dist/{chunk-3ZRMVPQA.cjs.map → chunk-ZSQ7L6AW.cjs.map} +1 -1
- package/dist/evals/index.cjs +19 -19
- package/dist/evals/index.js +2 -2
- package/dist/evals/scoreTraces/index.cjs +5 -5
- package/dist/evals/scoreTraces/index.js +2 -2
- package/dist/index.cjs +2 -2
- package/dist/index.js +1 -1
- package/dist/integration/index.cjs +2 -2
- package/dist/integration/index.js +1 -1
- package/dist/llm/index.cjs +11 -11
- package/dist/llm/index.js +3 -3
- package/dist/llm/model/provider-types.generated.d.ts +14 -1
- package/dist/loop/index.cjs +2 -2
- package/dist/loop/index.js +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.js +1 -1
- package/dist/memory/index.cjs +11 -11
- package/dist/memory/index.js +1 -1
- package/dist/netlify-CUYK2MZ2.cjs +12 -0
- package/dist/{netlify-5Y33S7WL.cjs.map → netlify-CUYK2MZ2.cjs.map} +1 -1
- package/dist/netlify-J4QPOROO.js +3 -0
- package/dist/{netlify-3MHHJG2E.js.map → netlify-J4QPOROO.js.map} +1 -1
- package/dist/processors/index.cjs +37 -37
- package/dist/processors/index.js +1 -1
- package/dist/provider-registry-IGILEKIM.js +3 -0
- package/dist/{provider-registry-LXSWMVEC.js.map → provider-registry-IGILEKIM.js.map} +1 -1
- package/dist/provider-registry-XNQEGR56.cjs +40 -0
- package/dist/{provider-registry-YJ2P5YY5.cjs.map → provider-registry-XNQEGR56.cjs.map} +1 -1
- package/dist/provider-registry.json +36 -2
- package/dist/relevance/index.cjs +3 -3
- package/dist/relevance/index.js +1 -1
- package/dist/storage/constants.cjs +14 -14
- package/dist/storage/constants.js +1 -1
- package/dist/storage/index.cjs +92 -92
- package/dist/storage/index.js +2 -2
- package/dist/stream/index.cjs +9 -9
- package/dist/stream/index.js +1 -1
- package/dist/test-utils/llm-mock.cjs +4 -4
- package/dist/test-utils/llm-mock.js +1 -1
- package/dist/tool-loop-agent/index.cjs +4 -4
- package/dist/tool-loop-agent/index.js +1 -1
- package/dist/tools/index.cjs +4 -4
- package/dist/tools/index.js +1 -1
- package/dist/tools/is-vercel-tool.cjs +2 -2
- package/dist/tools/is-vercel-tool.js +1 -1
- package/dist/utils/zod-utils.d.ts +7 -1
- package/dist/utils/zod-utils.d.ts.map +1 -1
- package/dist/utils.cjs +27 -27
- package/dist/utils.js +2 -2
- package/dist/workflows/evented/index.cjs +10 -10
- package/dist/workflows/evented/index.js +1 -1
- package/dist/workflows/index.cjs +23 -23
- package/dist/workflows/index.js +1 -1
- package/package.json +5 -5
- package/src/llm/model/provider-types.generated.d.ts +14 -1
- package/dist/chunk-37YWZMBX.js.map +0 -1
- package/dist/chunk-5DL6Y7PJ.cjs.map +0 -1
- package/dist/chunk-DT5RMENY.js.map +0 -1
- package/dist/chunk-F7PAZAGE.js.map +0 -1
- package/dist/chunk-H2NHG7QL.cjs.map +0 -1
- package/dist/chunk-NCAMNQC3.cjs.map +0 -1
- package/dist/netlify-3MHHJG2E.js +0 -3
- package/dist/netlify-5Y33S7WL.cjs +0 -12
- package/dist/provider-registry-LXSWMVEC.js +0 -3
- package/dist/provider-registry-YJ2P5YY5.cjs +0 -40
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isZodArray, isZodObject } from './chunk-
|
|
1
|
+
import { isZodArray, isZodObject } from './chunk-AIJLACR2.js';
|
|
2
2
|
import { RequestContext } from './chunk-6TBWJV35.js';
|
|
3
3
|
|
|
4
4
|
// src/tools/validation.ts
|
|
@@ -265,5 +265,5 @@ function isVercelTool(tool) {
|
|
|
265
265
|
}
|
|
266
266
|
|
|
267
267
|
export { Tool, createTool, isVercelTool, validateToolInput, validateToolOutput, validateToolSuspendData };
|
|
268
|
-
//# sourceMappingURL=chunk-
|
|
269
|
-
//# sourceMappingURL=chunk-
|
|
268
|
+
//# sourceMappingURL=chunk-5YYAQUEF.js.map
|
|
269
|
+
//# sourceMappingURL=chunk-5YYAQUEF.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/tools/validation.ts","../src/tools/tool.ts","../src/tools/toolchecks.ts"],"names":["resumeData"],"mappings":";;;;AAgBA,SAAS,kBAAA,CAAmB,IAAA,EAAe,SAAA,GAAoB,GAAA,EAAa;AAC1E,EAAA,IAAI;AACF,IAAA,MAAM,WAAA,GAAc,IAAA,CAAK,SAAA,CAAU,IAAA,EAAM,MAAM,CAAC,CAAA;AAChD,IAAA,IAAI,WAAA,CAAY,UAAU,SAAA,EAAW;AACnC,MAAA,OAAO,WAAA;AAAA,IACT;AACA,IAAA,OAAO,WAAA,CAAY,KAAA,CAAM,CAAA,EAAG,SAAS,CAAA,GAAI,iBAAA;AAAA,EAC3C,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,4BAAA;AAAA,EACT;AACF;AAUO,SAAS,uBAAA,CACd,MAAA,EACA,WAAA,EACA,MAAA,EACmD;AAEnD,EAAA,IAAI,CAAC,MAAA,IAAU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;AAElE,QAAA,IAAI,WAAA,EAAa;AACf,UAAA,MAAM,oBAAoB,uBAAA,CAAwB,IAAA,CAAK,aAAA,EAAe,WAAA,EAAa,KAAK,EAAE,CAAA;AAC1F,UAAA,IAAI,kBAAkB,KAAA,EAAO;AAC3B,YAAA,OAAO,iBAAA,CAAkB,KAAA;AAAA,UAC3B;AAAA,QACF;AAEA,QAAA,MAAM,qBAAA,GAAwB,CAAC,EAAE,OAAO,WAAW,WAAA,IAAe,WAAA,CAAA;AAGlE,QAAA,MAAM,mBAAmB,kBAAA,CAAmB,IAAA,CAAK,cAAc,MAAA,EAAQ,IAAA,CAAK,IAAI,qBAAqB,CAAA;AACrG,QAAA,IAAI,iBAAiB,KAAA,EAAO;AAC1B,UAAA,OAAO,gBAAA,CAAiB,KAAA;AAAA,QAC1B;AAEA,QAAA,OAAO,gBAAA,CAAiB,IAAA;AAAA,MAC1B,CAAA;AAAA,IACF;AAAA,EACF;AACF;AA8EO,SAAS,WAWd,IAAA,EAU4E;AAC5E,EAAA,OAAO,IAAI,KAAK,IAAI,CAAA;AACtB;;;AC1XO,SAAS,aAAa,IAAA,EAA0C;AAKrE,EAAA,OAAO,CAAC,EACN,IAAA,IACA,EAAE,gBAAgB,IAAA,CAAA,KACjB,YAAA,IAAgB,IAAA,IAAS,SAAA,IAAa,IAAA,IAAQ,OAAO,IAAA,CAAK,OAAA,KAAY,cAAc,aAAA,IAAiB,IAAA,CAAA,CAAA;AAE1G","file":"chunk-QD776HMB.js","sourcesContent":["import type { z } from 'zod';\nimport type { ZodLikeSchema } from '../types/zod-compat';\nimport { isZodArray, isZodObject } from '../utils/zod-utils';\n\nexport interface ValidationError<T = any> {\n error: true;\n message: string;\n validationErrors: z.ZodFormattedError<T>;\n}\n\n/**\n * Safely truncates data for error messages to avoid exposing sensitive information.\n * @param data The data to truncate\n * @param maxLength Maximum length of the truncated string (default: 200)\n * @returns Truncated string representation\n */\nfunction truncateForLogging(data: unknown, maxLength: number = 200): string {\n try {\n const stringified = JSON.stringify(data, null, 2);\n if (stringified.length <= maxLength) {\n return stringified;\n }\n return stringified.slice(0, maxLength) + '... (truncated)';\n } catch {\n return '[Unable to serialize data]';\n }\n}\n\n/**\n * Validates raw suspend data against a Zod schema.\n *\n * @param schema The Zod schema to validate against\n * @param suspendData The raw suspend data to validate\n * @param toolId Optional tool ID for better error messages\n * @returns The validated data or a validation error\n */\nexport function validateToolSuspendData<T = any>(\n schema: ZodLikeSchema | undefined,\n suspendData: unknown,\n toolId?: string,\n): { data: T | unknown; error?: ValidationError<T> } {\n // If no schema, return suspend data as-is\n if (!schema || !('safeParse' in schema)) {\n return { data: suspendData };\n }\n\n // Validate the input directly - no unwrapping needed in v1.0\n const validation = schema.safeParse(suspendData);\n\n if (validation.success) {\n return { data: validation.data };\n }\n\n // Validation failed, return error\n const errorMessages = validation.error.issues\n .map((e: z.ZodIssue) => `- ${e.path?.join('.') || 'root'}: ${e.message}`)\n .join('\\n');\n\n const error: ValidationError<T> = {\n error: true,\n message: `Tool suspension data validation failed${toolId ? ` for ${toolId}` : ''}. Please fix the following errors and try again:\\n${errorMessages}\\n\\nProvided arguments: ${truncateForLogging(suspendData)}`,\n validationErrors: validation.error.format() as z.ZodFormattedError<T>,\n };\n\n return { data: suspendData, error };\n}\n\n/**\n * Normalizes undefined/null input to an appropriate default value based on schema type.\n * This handles LLMs (Claude Sonnet 4.5, Gemini 2.4, etc.) that send undefined/null\n * instead of {} or [] when all parameters are optional.\n *\n * @param schema The Zod schema to check\n * @param input The input to normalize\n * @returns The normalized input (original value, {}, or [])\n */\nfunction normalizeNullishInput(schema: ZodLikeSchema, input: unknown): unknown {\n if (input !== undefined && input !== null) {\n return input;\n }\n\n // Check if schema is an array type (using typeName to avoid dual-package hazard)\n if (isZodArray(schema as z.ZodTypeAny)) {\n return [];\n }\n\n // Check if schema is an object type (using typeName to avoid dual-package hazard)\n if (isZodObject(schema as z.ZodTypeAny)) {\n return {};\n }\n\n // For other schema types, return the original input and let Zod validate\n return input;\n}\n\n/**\n * Validates raw input data against a Zod schema.\n *\n * @param schema The Zod schema to validate against\n * @param input The raw input data to validate\n * @param toolId Optional tool ID for better error messages\n * @returns The validated data or a validation error\n */\nexport function validateToolInput<T = any>(\n schema: ZodLikeSchema | undefined,\n input: unknown,\n toolId?: string,\n): { data: T | unknown; error?: ValidationError<T> } {\n // If no schema, return input as-is\n if (!schema || !('safeParse' in schema)) {\n return { data: input };\n }\n\n // Normalize undefined/null input to appropriate default for the schema type\n // This handles LLMs that send undefined instead of {} or [] for optional parameters\n const normalizedInput = normalizeNullishInput(schema, input);\n\n // Validate the normalized input\n const validation = schema.safeParse(normalizedInput);\n\n if (validation.success) {\n return { data: validation.data };\n }\n\n // Validation failed, return error\n const errorMessages = validation.error.issues\n .map((e: z.ZodIssue) => `- ${e.path?.join('.') || 'root'}: ${e.message}`)\n .join('\\n');\n\n const error: ValidationError<T> = {\n error: true,\n message: `Tool input validation failed${toolId ? ` for ${toolId}` : ''}. Please fix the following errors and try again:\\n${errorMessages}\\n\\nProvided arguments: ${truncateForLogging(input)}`,\n validationErrors: validation.error.format() as z.ZodFormattedError<T>,\n };\n\n return { data: input, error };\n}\n\n/**\n * Validates tool output data against a Zod schema.\n *\n * @param schema The Zod schema to validate against\n * @param output The output data to validate\n * @param toolId Optional tool ID for better error messages\n * @returns The validated data or a validation error\n */\nexport function validateToolOutput<T = any>(\n schema: ZodLikeSchema | undefined,\n output: unknown,\n toolId?: string,\n suspendCalled?: boolean,\n): { data: T | unknown; error?: ValidationError<T> } {\n // If no schema, return output as-is\n if (!schema || !('safeParse' in schema) || suspendCalled) {\n return { data: output };\n }\n\n // Validate the output\n const validation = schema.safeParse(output);\n\n if (validation.success) {\n return { data: validation.data };\n }\n\n // Validation failed, return error\n const errorMessages = validation.error.issues\n .map((e: z.ZodIssue) => `- ${e.path?.join('.') || 'root'}: ${e.message}`)\n .join('\\n');\n\n const error: ValidationError<T> = {\n error: true,\n message: `Tool output validation failed${toolId ? ` for ${toolId}` : ''}. The tool returned invalid output:\\n${errorMessages}\\n\\nReturned output: ${truncateForLogging(output)}`,\n validationErrors: validation.error.format() as z.ZodFormattedError<T>,\n };\n\n return { data: output, error };\n}\n","import type { Mastra } from '../mastra';\nimport { RequestContext } from '../request-context';\nimport type { ZodLikeSchema, InferZodLikeSchema, InferZodLikeSchemaInput } from '../types/zod-compat';\nimport type { SuspendOptions } from '../workflows';\nimport type { ToolAction, ToolExecutionContext } from './types';\nimport { validateToolInput, validateToolOutput, validateToolSuspendData } from './validation';\n\n/**\n * A type-safe tool that agents and workflows can call to perform specific actions.\n *\n * @template TSchemaIn - Input schema type\n * @template TSchemaOut - Output schema type\n * @template TSuspendSchema - Suspend operation schema type\n * @template TResumeSchema - Resume operation schema type\n * @template TContext - Execution context type\n *\n * @example Basic tool with validation\n * ```typescript\n * const weatherTool = createTool({\n * id: 'get-weather',\n * description: 'Get weather for a location',\n * inputSchema: z.object({\n * location: z.string(),\n * units: z.enum(['celsius', 'fahrenheit']).optional()\n * }),\n * execute: async (inputData) => {\n * return await fetchWeather(inputData.location, inputData.units);\n * }\n * });\n * ```\n *\n * @example Tool requiring approval\n * ```typescript\n * const deleteFileTool = createTool({\n * id: 'delete-file',\n * description: 'Delete a file',\n * requireApproval: true,\n * inputSchema: z.object({ filepath: z.string() }),\n * execute: async (inputData) => {\n * await fs.unlink(inputData.filepath);\n * return { deleted: true };\n * }\n * });\n * ```\n *\n * @example Tool with Mastra integration\n * ```typescript\n * const saveTool = createTool({\n * id: 'save-data',\n * description: 'Save data to storage',\n * inputSchema: z.object({ key: z.string(), value: z.any() }),\n * execute: async (inputData, context) => {\n * const storage = context?.mastra?.getStorage();\n * await storage?.set(inputData.key, inputData.value);\n * return { saved: true };\n * }\n * });\n * ```\n */\nexport class Tool<\n TSchemaIn extends ZodLikeSchema | undefined = undefined,\n TSchemaOut extends ZodLikeSchema | undefined = undefined,\n TSuspendSchema extends ZodLikeSchema = any,\n TResumeSchema extends ZodLikeSchema = any,\n TContext extends ToolExecutionContext<TSuspendSchema, TResumeSchema> = ToolExecutionContext<\n TSuspendSchema,\n TResumeSchema\n >,\n TId extends string = string,\n> implements ToolAction<TSchemaIn, TSchemaOut, TSuspendSchema, TResumeSchema, TContext, TId>\n{\n /** Unique identifier for the tool */\n id: TId;\n\n /** Description of what the tool does */\n description: string;\n\n /** Schema for validating input parameters */\n inputSchema?: TSchemaIn;\n\n /** Schema for validating output structure */\n outputSchema?: TSchemaOut;\n\n /** Schema for suspend operation data */\n suspendSchema?: TSuspendSchema;\n\n /** Schema for resume operation data */\n resumeSchema?: TResumeSchema;\n\n /**\n * Tool execution function\n * @param inputData - The raw, validated input data\n * @param context - Optional execution context with metadata\n * @returns Promise resolving to tool output or a ValidationError if input validation fails\n */\n execute?: ToolAction<TSchemaIn, TSchemaOut, TSuspendSchema, TResumeSchema, TContext>['execute'];\n\n /** Parent Mastra instance for accessing shared resources */\n mastra?: Mastra;\n\n /**\n * Whether the tool requires explicit user approval before execution\n * @example\n * ```typescript\n * // For destructive operations\n * requireApproval: true\n * ```\n */\n requireApproval?: boolean;\n\n /**\n * Provider-specific options passed to the model when this tool is used.\n * Keys are provider names (e.g., 'anthropic', 'openai'), values are provider-specific configs.\n * @example\n * ```typescript\n * providerOptions: {\n * anthropic: {\n * cacheControl: { type: 'ephemeral' }\n * }\n * }\n * ```\n */\n providerOptions?: Record<string, Record<string, unknown>>;\n\n /**\n * Creates a new Tool instance with input validation wrapper.\n *\n * @param opts - Tool configuration and execute function\n * @example\n * ```typescript\n * const tool = new Tool({\n * id: 'my-tool',\n * description: 'Does something useful',\n * inputSchema: z.object({ name: z.string() }),\n * execute: async (inputData) => ({ greeting: `Hello ${inputData.name}` })\n * });\n * ```\n */\n constructor(opts: ToolAction<TSchemaIn, TSchemaOut, TSuspendSchema, TResumeSchema, TContext, TId>) {\n this.id = opts.id;\n this.description = opts.description;\n this.inputSchema = opts.inputSchema;\n this.outputSchema = opts.outputSchema;\n this.suspendSchema = opts.suspendSchema;\n this.resumeSchema = opts.resumeSchema;\n this.mastra = opts.mastra;\n this.requireApproval = opts.requireApproval || false;\n this.providerOptions = opts.providerOptions;\n\n // Tools receive two parameters:\n // 1. input - The raw, validated input data\n // 2. context - Execution metadata (mastra, suspend, etc.)\n if (opts.execute) {\n const originalExecute = opts.execute;\n this.execute = async (inputData: unknown, context?: any) => {\n // Validate input if schema exists\n const { data, error } = validateToolInput(this.inputSchema, inputData, this.id);\n if (error) {\n return error as any;\n }\n\n let suspendData = null;\n\n const baseContext = context\n ? {\n ...context,\n ...(context.suspend\n ? {\n suspend: (args: any, suspendOptions?: SuspendOptions) => {\n suspendData = args;\n return context.suspend?.(args, suspendOptions);\n },\n }\n : {}),\n }\n : {};\n\n // Organize context based on execution source\n let organizedContext = baseContext;\n if (!context) {\n // No context provided - create a minimal context with requestContext\n organizedContext = {\n requestContext: new RequestContext(),\n mastra: undefined,\n };\n } else {\n // Check if this is agent execution (has toolCallId and messages)\n const isAgentExecution = baseContext.toolCallId && baseContext.messages;\n\n // Check if this is workflow execution (has workflow properties)\n // Agent execution takes precedence - don't treat as workflow if it's an agent call\n const isWorkflowExecution = !isAgentExecution && (baseContext.workflow || baseContext.workflowId);\n\n if (isAgentExecution && !baseContext.agent) {\n // Reorganize agent context - nest agent-specific properties under 'agent' key\n const { toolCallId, messages, suspend, resumeData, threadId, resourceId, writableStream, ...rest } =\n baseContext;\n organizedContext = {\n ...rest,\n agent: {\n toolCallId,\n messages,\n suspend,\n resumeData,\n threadId,\n resourceId,\n writableStream,\n },\n // Ensure requestContext is always present\n requestContext: rest.requestContext || new RequestContext(),\n };\n } else if (isWorkflowExecution && !baseContext.workflow) {\n // Reorganize workflow context - nest workflow-specific properties under 'workflow' key\n const { workflowId, runId, state, setState, suspend, resumeData, ...rest } = baseContext;\n organizedContext = {\n ...rest,\n workflow: {\n workflowId,\n runId,\n state,\n setState,\n suspend,\n resumeData,\n },\n // Ensure requestContext is always present\n requestContext: rest.requestContext || new RequestContext(),\n };\n } else {\n // Ensure requestContext is always present even for direct execution\n organizedContext = {\n ...baseContext,\n agent: baseContext.agent\n ? {\n ...baseContext.agent,\n suspend: (args: any, suspendOptions?: SuspendOptions) => {\n suspendData = args;\n return baseContext.agent?.suspend?.(args, suspendOptions);\n },\n }\n : baseContext.agent,\n workflow: baseContext.workflow\n ? {\n ...baseContext.workflow,\n suspend: (args: any, suspendOptions?: SuspendOptions) => {\n suspendData = args;\n return baseContext.workflow?.suspend?.(args, suspendOptions);\n },\n }\n : baseContext.workflow,\n requestContext: baseContext.requestContext || new RequestContext(),\n };\n }\n }\n\n const resumeData =\n organizedContext.agent?.resumeData ?? organizedContext.workflow?.resumeData ?? organizedContext?.resumeData;\n\n if (resumeData) {\n const resumeValidation = validateToolInput(this.resumeSchema, resumeData, this.id);\n if (resumeValidation.error) {\n return resumeValidation.error as any;\n }\n }\n\n // Call the original execute with validated input and organized context\n const output = await originalExecute(data as any, organizedContext);\n\n if (suspendData) {\n const suspendValidation = validateToolSuspendData(this.suspendSchema, suspendData, this.id);\n if (suspendValidation.error) {\n return suspendValidation.error as any;\n }\n }\n\n const skiptOutputValidation = !!(typeof output === 'undefined' && suspendData);\n\n // Validate output if schema exists\n const outputValidation = validateToolOutput(this.outputSchema, output, this.id, skiptOutputValidation);\n if (outputValidation.error) {\n return outputValidation.error as any;\n }\n\n return outputValidation.data;\n };\n }\n }\n}\n\n/**\n * Creates a type-safe tool with automatic input validation.\n *\n * @template TSchemaIn - Input schema type\n * @template TSchemaOut - Output schema type\n * @template TSuspendSchema - Suspend operation schema type\n * @template TResumeSchema - Resume operation schema type\n * @template TContext - Execution context type\n * @template TExecute - Execute function type\n *\n * @param opts - Tool configuration including schemas and execute function\n * @returns Type-safe Tool instance with conditional typing based on schemas\n *\n * @example Simple tool\n * ```typescript\n * const greetTool = createTool({\n * id: 'greet',\n * description: 'Say hello',\n * execute: async () => ({ message: 'Hello!' })\n * });\n * ```\n *\n * @example Tool with input validation\n * ```typescript\n * const calculateTool = createTool({\n * id: 'calculate',\n * description: 'Perform calculations',\n * inputSchema: z.object({\n * operation: z.enum(['add', 'subtract']),\n * a: z.number(),\n * b: z.number()\n * }),\n * execute: async (inputData) => {\n * const result = inputData.operation === 'add'\n * ? inputData.a + inputData.b\n * : inputData.a - inputData.b;\n * return { result };\n * }\n * });\n * ```\n *\n * @example Tool with output schema\n * ```typescript\n * const userTool = createTool({\n * id: 'get-user',\n * description: 'Get user data',\n * inputSchema: z.object({ userId: z.string() }),\n * outputSchema: z.object({\n * id: z.string(),\n * name: z.string(),\n * email: z.string()\n * }),\n * execute: async (inputData) => {\n * return await fetchUser(inputData.userId);\n * }\n * });\n * ```\n *\n * @example Tool with external API\n * ```typescript\n * const weatherTool = createTool({\n * id: 'weather',\n * description: 'Get weather data',\n * inputSchema: z.object({\n * city: z.string(),\n * units: z.enum(['metric', 'imperial']).default('metric')\n * }),\n * execute: async (inputData) => {\n * const response = await fetch(\n * `https://api.weather.com/v1/weather?q=${inputData.city}&units=${inputData.units}`\n * );\n * return response.json();\n * }\n * });\n * ```\n */\nexport function createTool<\n TId extends string = string,\n TSchemaIn extends ZodLikeSchema | undefined = undefined,\n TSchemaOut extends ZodLikeSchema | undefined = undefined,\n TSuspendSchema extends ZodLikeSchema = any,\n TResumeSchema extends ZodLikeSchema = any,\n TContext extends ToolExecutionContext<TSuspendSchema, TResumeSchema> = ToolExecutionContext<\n TSuspendSchema,\n TResumeSchema\n >,\n>(\n opts: ToolAction<TSchemaIn, TSchemaOut, TSuspendSchema, TResumeSchema, TContext, TId>,\n): [TSchemaIn, TSchemaOut] extends [ZodLikeSchema, ZodLikeSchema]\n ? Tool<TSchemaIn, TSchemaOut, TSuspendSchema, TResumeSchema, TContext, TId> & {\n inputSchema: TSchemaIn;\n outputSchema: TSchemaOut;\n execute: (\n inputData: InferZodLikeSchema<TSchemaIn>,\n context?: TContext,\n ) => Promise<InferZodLikeSchemaInput<TSchemaOut> & { error?: never }>;\n }\n : Tool<TSchemaIn, TSchemaOut, TSuspendSchema, TResumeSchema, TContext, TId> {\n return new Tool(opts) as any;\n}\n","import { Tool } from './tool';\nimport type { ToolToConvert } from './tool-builder/builder';\nimport type { VercelTool } from './types';\n\n/**\n * Checks if a tool is a Vercel Tool (AI SDK tool)\n * @param tool - The tool to check\n * @returns True if the tool is a Vercel Tool, false otherwise\n */\nexport function isVercelTool(tool?: ToolToConvert): tool is VercelTool {\n // Checks if this tool is not an instance of Mastra's Tool class\n // AI SDK tools must have an execute function and either:\n // - 'parameters' (v4) or 'inputSchema' (v5/v6)\n // This prevents plain objects with inputSchema (like client tools) from being treated as VercelTools\n return !!(\n tool &&\n !(tool instanceof Tool) &&\n ('parameters' in tool || ('execute' in tool && typeof tool.execute === 'function' && 'inputSchema' in tool))\n );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/tools/validation.ts","../src/tools/tool.ts","../src/tools/toolchecks.ts"],"names":["resumeData"],"mappings":";;;;AAgBA,SAAS,kBAAA,CAAmB,IAAA,EAAe,SAAA,GAAoB,GAAA,EAAa;AAC1E,EAAA,IAAI;AACF,IAAA,MAAM,WAAA,GAAc,IAAA,CAAK,SAAA,CAAU,IAAA,EAAM,MAAM,CAAC,CAAA;AAChD,IAAA,IAAI,WAAA,CAAY,UAAU,SAAA,EAAW;AACnC,MAAA,OAAO,WAAA;AAAA,IACT;AACA,IAAA,OAAO,WAAA,CAAY,KAAA,CAAM,CAAA,EAAG,SAAS,CAAA,GAAI,iBAAA;AAAA,EAC3C,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,4BAAA;AAAA,EACT;AACF;AAUO,SAAS,uBAAA,CACd,MAAA,EACA,WAAA,EACA,MAAA,EACmD;AAEnD,EAAA,IAAI,CAAC,MAAA,IAAU,EAAE,WAAA,IAAe,MAAA,CAAA,EAAS;AACvC,IAAA,OAAO,EAAE,MAAM,WAAA,EAAY;AAAA,EAC7B;AAGA,EAAA,MAAM,UAAA,GAAa,MAAA,CAAO,SAAA,CAAU,W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AkB,KAAA,EAAO;AAC3B,YAAA,OAAO,iBAAA,CAAkB,KAAA;AAAA,UAC3B;AAAA,QACF;AAEA,QAAA,MAAM,qBAAA,GAAwB,CAAC,EAAE,OAAO,WAAW,WAAA,IAAe,WAAA,CAAA;AAGlE,QAAA,MAAM,mBAAmB,kBAAA,CAAmB,IAAA,CAAK,cAAc,MAAA,EAAQ,IAAA,CAAK,IAAI,qBAAqB,CAAA;AACrG,QAAA,IAAI,iBAAiB,KAAA,EAAO;AAC1B,UAAA,OAAO,gBAAA,CAAiB,KAAA;AAAA,QAC1B;AAEA,QAAA,OAAO,gBAAA,CAAiB,IAAA;AAAA,MAC1B,CAAA;AAAA,IACF;AAAA,EACF;AACF;AA8EO,SAAS,WAWd,IAAA,EAU4E;AAC5E,EAAA,OAAO,IAAI,KAAK,IAAI,CAAA;AACtB;;;AC1XO,SAAS,aAAa,IAAA,EAA0C;AAKrE,EAAA,OAAO,CAAC,EACN,IAAA,IACA,EAAE,gBAAgB,IAAA,CAAA,KACjB,YAAA,IAAgB,IAAA,IAAS,SAAA,IAAa,IAAA,IAAQ,OAAO,IAAA,CAAK,OAAA,KAAY,cAAc,aAAA,IAAiB,IAAA,CAAA,CAAA;AAE1G","file":"chunk-5YYAQUEF.js","sourcesContent":["import type { z } from 'zod';\nimport type { ZodLikeSchema } from '../types/zod-compat';\nimport { isZodArray, isZodObject } from '../utils/zod-utils';\n\nexport interface ValidationError<T = any> {\n error: true;\n message: string;\n validationErrors: z.ZodFormattedError<T>;\n}\n\n/**\n * Safely truncates data for error messages to avoid exposing sensitive information.\n * @param data The data to truncate\n * @param maxLength Maximum length of the truncated string (default: 200)\n * @returns Truncated string representation\n */\nfunction truncateForLogging(data: unknown, maxLength: number = 200): string {\n try {\n const stringified = JSON.stringify(data, null, 2);\n if (stringified.length <= maxLength) {\n return stringified;\n }\n return stringified.slice(0, maxLength) + '... (truncated)';\n } catch {\n return '[Unable to serialize data]';\n }\n}\n\n/**\n * Validates raw suspend data against a Zod schema.\n *\n * @param schema The Zod schema to validate against\n * @param suspendData The raw suspend data to validate\n * @param toolId Optional tool ID for better error messages\n * @returns The validated data or a validation error\n */\nexport function validateToolSuspendData<T = any>(\n schema: ZodLikeSchema | undefined,\n suspendData: unknown,\n toolId?: string,\n): { data: T | unknown; error?: ValidationError<T> } {\n // If no schema, return suspend data as-is\n if (!schema || !('safeParse' in schema)) {\n return { data: suspendData };\n }\n\n // Validate the input directly - no unwrapping needed in v1.0\n const validation = schema.safeParse(suspendData);\n\n if (validation.success) {\n return { data: validation.data };\n }\n\n // Validation failed, return error\n const errorMessages = validation.error.issues\n .map((e: z.ZodIssue) => `- ${e.path?.join('.') || 'root'}: ${e.message}`)\n .join('\\n');\n\n const error: ValidationError<T> = {\n error: true,\n message: `Tool suspension data validation failed${toolId ? ` for ${toolId}` : ''}. Please fix the following errors and try again:\\n${errorMessages}\\n\\nProvided arguments: ${truncateForLogging(suspendData)}`,\n validationErrors: validation.error.format() as z.ZodFormattedError<T>,\n };\n\n return { data: suspendData, error };\n}\n\n/**\n * Normalizes undefined/null input to an appropriate default value based on schema type.\n * This handles LLMs (Claude Sonnet 4.5, Gemini 2.4, etc.) that send undefined/null\n * instead of {} or [] when all parameters are optional.\n *\n * @param schema The Zod schema to check\n * @param input The input to normalize\n * @returns The normalized input (original value, {}, or [])\n */\nfunction normalizeNullishInput(schema: ZodLikeSchema, input: unknown): unknown {\n if (input !== undefined && input !== null) {\n return input;\n }\n\n // Check if schema is an array type (using typeName to avoid dual-package hazard)\n if (isZodArray(schema as z.ZodTypeAny)) {\n return [];\n }\n\n // Check if schema is an object type (using typeName to avoid dual-package hazard)\n if (isZodObject(schema as z.ZodTypeAny)) {\n return {};\n }\n\n // For other schema types, return the original input and let Zod validate\n return input;\n}\n\n/**\n * Validates raw input data against a Zod schema.\n *\n * @param schema The Zod schema to validate against\n * @param input The raw input data to validate\n * @param toolId Optional tool ID for better error messages\n * @returns The validated data or a validation error\n */\nexport function validateToolInput<T = any>(\n schema: ZodLikeSchema | undefined,\n input: unknown,\n toolId?: string,\n): { data: T | unknown; error?: ValidationError<T> } {\n // If no schema, return input as-is\n if (!schema || !('safeParse' in schema)) {\n return { data: input };\n }\n\n // Normalize undefined/null input to appropriate default for the schema type\n // This handles LLMs that send undefined instead of {} or [] for optional parameters\n const normalizedInput = normalizeNullishInput(schema, input);\n\n // Validate the normalized input\n const validation = schema.safeParse(normalizedInput);\n\n if (validation.success) {\n return { data: validation.data };\n }\n\n // Validation failed, return error\n const errorMessages = validation.error.issues\n .map((e: z.ZodIssue) => `- ${e.path?.join('.') || 'root'}: ${e.message}`)\n .join('\\n');\n\n const error: ValidationError<T> = {\n error: true,\n message: `Tool input validation failed${toolId ? ` for ${toolId}` : ''}. Please fix the following errors and try again:\\n${errorMessages}\\n\\nProvided arguments: ${truncateForLogging(input)}`,\n validationErrors: validation.error.format() as z.ZodFormattedError<T>,\n };\n\n return { data: input, error };\n}\n\n/**\n * Validates tool output data against a Zod schema.\n *\n * @param schema The Zod schema to validate against\n * @param output The output data to validate\n * @param toolId Optional tool ID for better error messages\n * @returns The validated data or a validation error\n */\nexport function validateToolOutput<T = any>(\n schema: ZodLikeSchema | undefined,\n output: unknown,\n toolId?: string,\n suspendCalled?: boolean,\n): { data: T | unknown; error?: ValidationError<T> } {\n // If no schema, return output as-is\n if (!schema || !('safeParse' in schema) || suspendCalled) {\n return { data: output };\n }\n\n // Validate the output\n const validation = schema.safeParse(output);\n\n if (validation.success) {\n return { data: validation.data };\n }\n\n // Validation failed, return error\n const errorMessages = validation.error.issues\n .map((e: z.ZodIssue) => `- ${e.path?.join('.') || 'root'}: ${e.message}`)\n .join('\\n');\n\n const error: ValidationError<T> = {\n error: true,\n message: `Tool output validation failed${toolId ? ` for ${toolId}` : ''}. The tool returned invalid output:\\n${errorMessages}\\n\\nReturned output: ${truncateForLogging(output)}`,\n validationErrors: validation.error.format() as z.ZodFormattedError<T>,\n };\n\n return { data: output, error };\n}\n","import type { Mastra } from '../mastra';\nimport { RequestContext } from '../request-context';\nimport type { ZodLikeSchema, InferZodLikeSchema, InferZodLikeSchemaInput } from '../types/zod-compat';\nimport type { SuspendOptions } from '../workflows';\nimport type { ToolAction, ToolExecutionContext } from './types';\nimport { validateToolInput, validateToolOutput, validateToolSuspendData } from './validation';\n\n/**\n * A type-safe tool that agents and workflows can call to perform specific actions.\n *\n * @template TSchemaIn - Input schema type\n * @template TSchemaOut - Output schema type\n * @template TSuspendSchema - Suspend operation schema type\n * @template TResumeSchema - Resume operation schema type\n * @template TContext - Execution context type\n *\n * @example Basic tool with validation\n * ```typescript\n * const weatherTool = createTool({\n * id: 'get-weather',\n * description: 'Get weather for a location',\n * inputSchema: z.object({\n * location: z.string(),\n * units: z.enum(['celsius', 'fahrenheit']).optional()\n * }),\n * execute: async (inputData) => {\n * return await fetchWeather(inputData.location, inputData.units);\n * }\n * });\n * ```\n *\n * @example Tool requiring approval\n * ```typescript\n * const deleteFileTool = createTool({\n * id: 'delete-file',\n * description: 'Delete a file',\n * requireApproval: true,\n * inputSchema: z.object({ filepath: z.string() }),\n * execute: async (inputData) => {\n * await fs.unlink(inputData.filepath);\n * return { deleted: true };\n * }\n * });\n * ```\n *\n * @example Tool with Mastra integration\n * ```typescript\n * const saveTool = createTool({\n * id: 'save-data',\n * description: 'Save data to storage',\n * inputSchema: z.object({ key: z.string(), value: z.any() }),\n * execute: async (inputData, context) => {\n * const storage = context?.mastra?.getStorage();\n * await storage?.set(inputData.key, inputData.value);\n * return { saved: true };\n * }\n * });\n * ```\n */\nexport class Tool<\n TSchemaIn extends ZodLikeSchema | undefined = undefined,\n TSchemaOut extends ZodLikeSchema | undefined = undefined,\n TSuspendSchema extends ZodLikeSchema = any,\n TResumeSchema extends ZodLikeSchema = any,\n TContext extends ToolExecutionContext<TSuspendSchema, TResumeSchema> = ToolExecutionContext<\n TSuspendSchema,\n TResumeSchema\n >,\n TId extends string = string,\n> implements ToolAction<TSchemaIn, TSchemaOut, TSuspendSchema, TResumeSchema, TContext, TId>\n{\n /** Unique identifier for the tool */\n id: TId;\n\n /** Description of what the tool does */\n description: string;\n\n /** Schema for validating input parameters */\n inputSchema?: TSchemaIn;\n\n /** Schema for validating output structure */\n outputSchema?: TSchemaOut;\n\n /** Schema for suspend operation data */\n suspendSchema?: TSuspendSchema;\n\n /** Schema for resume operation data */\n resumeSchema?: TResumeSchema;\n\n /**\n * Tool execution function\n * @param inputData - The raw, validated input data\n * @param context - Optional execution context with metadata\n * @returns Promise resolving to tool output or a ValidationError if input validation fails\n */\n execute?: ToolAction<TSchemaIn, TSchemaOut, TSuspendSchema, TResumeSchema, TContext>['execute'];\n\n /** Parent Mastra instance for accessing shared resources */\n mastra?: Mastra;\n\n /**\n * Whether the tool requires explicit user approval before execution\n * @example\n * ```typescript\n * // For destructive operations\n * requireApproval: true\n * ```\n */\n requireApproval?: boolean;\n\n /**\n * Provider-specific options passed to the model when this tool is used.\n * Keys are provider names (e.g., 'anthropic', 'openai'), values are provider-specific configs.\n * @example\n * ```typescript\n * providerOptions: {\n * anthropic: {\n * cacheControl: { type: 'ephemeral' }\n * }\n * }\n * ```\n */\n providerOptions?: Record<string, Record<string, unknown>>;\n\n /**\n * Creates a new Tool instance with input validation wrapper.\n *\n * @param opts - Tool configuration and execute function\n * @example\n * ```typescript\n * const tool = new Tool({\n * id: 'my-tool',\n * description: 'Does something useful',\n * inputSchema: z.object({ name: z.string() }),\n * execute: async (inputData) => ({ greeting: `Hello ${inputData.name}` })\n * });\n * ```\n */\n constructor(opts: ToolAction<TSchemaIn, TSchemaOut, TSuspendSchema, TResumeSchema, TContext, TId>) {\n this.id = opts.id;\n this.description = opts.description;\n this.inputSchema = opts.inputSchema;\n this.outputSchema = opts.outputSchema;\n this.suspendSchema = opts.suspendSchema;\n this.resumeSchema = opts.resumeSchema;\n this.mastra = opts.mastra;\n this.requireApproval = opts.requireApproval || false;\n this.providerOptions = opts.providerOptions;\n\n // Tools receive two parameters:\n // 1. input - The raw, validated input data\n // 2. context - Execution metadata (mastra, suspend, etc.)\n if (opts.execute) {\n const originalExecute = opts.execute;\n this.execute = async (inputData: unknown, context?: any) => {\n // Validate input if schema exists\n const { data, error } = validateToolInput(this.inputSchema, inputData, this.id);\n if (error) {\n return error as any;\n }\n\n let suspendData = null;\n\n const baseContext = context\n ? {\n ...context,\n ...(context.suspend\n ? {\n suspend: (args: any, suspendOptions?: SuspendOptions) => {\n suspendData = args;\n return context.suspend?.(args, suspendOptions);\n },\n }\n : {}),\n }\n : {};\n\n // Organize context based on execution source\n let organizedContext = baseContext;\n if (!context) {\n // No context provided - create a minimal context with requestContext\n organizedContext = {\n requestContext: new RequestContext(),\n mastra: undefined,\n };\n } else {\n // Check if this is agent execution (has toolCallId and messages)\n const isAgentExecution = baseContext.toolCallId && baseContext.messages;\n\n // Check if this is workflow execution (has workflow properties)\n // Agent execution takes precedence - don't treat as workflow if it's an agent call\n const isWorkflowExecution = !isAgentExecution && (baseContext.workflow || baseContext.workflowId);\n\n if (isAgentExecution && !baseContext.agent) {\n // Reorganize agent context - nest agent-specific properties under 'agent' key\n const { toolCallId, messages, suspend, resumeData, threadId, resourceId, writableStream, ...rest } =\n baseContext;\n organizedContext = {\n ...rest,\n agent: {\n toolCallId,\n messages,\n suspend,\n resumeData,\n threadId,\n resourceId,\n writableStream,\n },\n // Ensure requestContext is always present\n requestContext: rest.requestContext || new RequestContext(),\n };\n } else if (isWorkflowExecution && !baseContext.workflow) {\n // Reorganize workflow context - nest workflow-specific properties under 'workflow' key\n const { workflowId, runId, state, setState, suspend, resumeData, ...rest } = baseContext;\n organizedContext = {\n ...rest,\n workflow: {\n workflowId,\n runId,\n state,\n setState,\n suspend,\n resumeData,\n },\n // Ensure requestContext is always present\n requestContext: rest.requestContext || new RequestContext(),\n };\n } else {\n // Ensure requestContext is always present even for direct execution\n organizedContext = {\n ...baseContext,\n agent: baseContext.agent\n ? {\n ...baseContext.agent,\n suspend: (args: any, suspendOptions?: SuspendOptions) => {\n suspendData = args;\n return baseContext.agent?.suspend?.(args, suspendOptions);\n },\n }\n : baseContext.agent,\n workflow: baseContext.workflow\n ? {\n ...baseContext.workflow,\n suspend: (args: any, suspendOptions?: SuspendOptions) => {\n suspendData = args;\n return baseContext.workflow?.suspend?.(args, suspendOptions);\n },\n }\n : baseContext.workflow,\n requestContext: baseContext.requestContext || new RequestContext(),\n };\n }\n }\n\n const resumeData =\n organizedContext.agent?.resumeData ?? organizedContext.workflow?.resumeData ?? organizedContext?.resumeData;\n\n if (resumeData) {\n const resumeValidation = validateToolInput(this.resumeSchema, resumeData, this.id);\n if (resumeValidation.error) {\n return resumeValidation.error as any;\n }\n }\n\n // Call the original execute with validated input and organized context\n const output = await originalExecute(data as any, organizedContext);\n\n if (suspendData) {\n const suspendValidation = validateToolSuspendData(this.suspendSchema, suspendData, this.id);\n if (suspendValidation.error) {\n return suspendValidation.error as any;\n }\n }\n\n const skiptOutputValidation = !!(typeof output === 'undefined' && suspendData);\n\n // Validate output if schema exists\n const outputValidation = validateToolOutput(this.outputSchema, output, this.id, skiptOutputValidation);\n if (outputValidation.error) {\n return outputValidation.error as any;\n }\n\n return outputValidation.data;\n };\n }\n }\n}\n\n/**\n * Creates a type-safe tool with automatic input validation.\n *\n * @template TSchemaIn - Input schema type\n * @template TSchemaOut - Output schema type\n * @template TSuspendSchema - Suspend operation schema type\n * @template TResumeSchema - Resume operation schema type\n * @template TContext - Execution context type\n * @template TExecute - Execute function type\n *\n * @param opts - Tool configuration including schemas and execute function\n * @returns Type-safe Tool instance with conditional typing based on schemas\n *\n * @example Simple tool\n * ```typescript\n * const greetTool = createTool({\n * id: 'greet',\n * description: 'Say hello',\n * execute: async () => ({ message: 'Hello!' })\n * });\n * ```\n *\n * @example Tool with input validation\n * ```typescript\n * const calculateTool = createTool({\n * id: 'calculate',\n * description: 'Perform calculations',\n * inputSchema: z.object({\n * operation: z.enum(['add', 'subtract']),\n * a: z.number(),\n * b: z.number()\n * }),\n * execute: async (inputData) => {\n * const result = inputData.operation === 'add'\n * ? inputData.a + inputData.b\n * : inputData.a - inputData.b;\n * return { result };\n * }\n * });\n * ```\n *\n * @example Tool with output schema\n * ```typescript\n * const userTool = createTool({\n * id: 'get-user',\n * description: 'Get user data',\n * inputSchema: z.object({ userId: z.string() }),\n * outputSchema: z.object({\n * id: z.string(),\n * name: z.string(),\n * email: z.string()\n * }),\n * execute: async (inputData) => {\n * return await fetchUser(inputData.userId);\n * }\n * });\n * ```\n *\n * @example Tool with external API\n * ```typescript\n * const weatherTool = createTool({\n * id: 'weather',\n * description: 'Get weather data',\n * inputSchema: z.object({\n * city: z.string(),\n * units: z.enum(['metric', 'imperial']).default('metric')\n * }),\n * execute: async (inputData) => {\n * const response = await fetch(\n * `https://api.weather.com/v1/weather?q=${inputData.city}&units=${inputData.units}`\n * );\n * return response.json();\n * }\n * });\n * ```\n */\nexport function createTool<\n TId extends string = string,\n TSchemaIn extends ZodLikeSchema | undefined = undefined,\n TSchemaOut extends ZodLikeSchema | undefined = undefined,\n TSuspendSchema extends ZodLikeSchema = any,\n TResumeSchema extends ZodLikeSchema = any,\n TContext extends ToolExecutionContext<TSuspendSchema, TResumeSchema> = ToolExecutionContext<\n TSuspendSchema,\n TResumeSchema\n >,\n>(\n opts: ToolAction<TSchemaIn, TSchemaOut, TSuspendSchema, TResumeSchema, TContext, TId>,\n): [TSchemaIn, TSchemaOut] extends [ZodLikeSchema, ZodLikeSchema]\n ? Tool<TSchemaIn, TSchemaOut, TSuspendSchema, TResumeSchema, TContext, TId> & {\n inputSchema: TSchemaIn;\n outputSchema: TSchemaOut;\n execute: (\n inputData: InferZodLikeSchema<TSchemaIn>,\n context?: TContext,\n ) => Promise<InferZodLikeSchemaInput<TSchemaOut> & { error?: never }>;\n }\n : Tool<TSchemaIn, TSchemaOut, TSuspendSchema, TResumeSchema, TContext, TId> {\n return new Tool(opts) as any;\n}\n","import { Tool } from './tool';\nimport type { ToolToConvert } from './tool-builder/builder';\nimport type { VercelTool } from './types';\n\n/**\n * Checks if a tool is a Vercel Tool (AI SDK tool)\n * @param tool - The tool to check\n * @returns True if the tool is a Vercel Tool, false otherwise\n */\nexport function isVercelTool(tool?: ToolToConvert): tool is VercelTool {\n // Checks if this tool is not an instance of Mastra's Tool class\n // AI SDK tools must have an execute function and either:\n // - 'parameters' (v4) or 'inputSchema' (v5/v6)\n // This prevents plain objects with inputSchema (like client tools) from being treated as VercelTools\n return !!(\n tool &&\n !(tool instanceof Tool) &&\n ('parameters' in tool || ('execute' in tool && typeof tool.execute === 'function' && 'inputSchema' in tool))\n );\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { validateStepInput, createDeprecationProxy, EventEmitterPubSub, getStepResult, validateStepSuspendData, runCountDeprecationMessage, createTimeTravelExecutionParams, validateStepResumeData, Workflow, Run, ExecutionEngine, hydrateSerializedStepErrors } from './chunk-
|
|
1
|
+
import { validateStepInput, createDeprecationProxy, EventEmitterPubSub, getStepResult, validateStepSuspendData, runCountDeprecationMessage, createTimeTravelExecutionParams, validateStepResumeData, Workflow, Run, ExecutionEngine, hydrateSerializedStepErrors } from './chunk-2XX35XRX.js';
|
|
2
2
|
import { STREAM_FORMAT_SYMBOL, PUBSUB_SYMBOL } from './chunk-6PMMP3FR.js';
|
|
3
3
|
import { getErrorFromUnknown, MastraError } from './chunk-FJEVLHJT.js';
|
|
4
|
-
import { Tool } from './chunk-
|
|
4
|
+
import { Tool } from './chunk-5YYAQUEF.js';
|
|
5
5
|
import { RequestContext } from './chunk-6TBWJV35.js';
|
|
6
6
|
import { MastraBase } from './chunk-LSHPJWM5.js';
|
|
7
7
|
import { RegisteredLogger } from './chunk-NRUZYMHE.js';
|
|
@@ -2895,5 +2895,5 @@ var EventedExecutionEngine = class extends ExecutionEngine {
|
|
|
2895
2895
|
};
|
|
2896
2896
|
|
|
2897
2897
|
export { EventedExecutionEngine, EventedRun, EventedWorkflow, StepExecutor, WorkflowEventProcessor, cloneStep, cloneWorkflow, createStep, createWorkflow };
|
|
2898
|
-
//# sourceMappingURL=chunk-
|
|
2899
|
-
//# sourceMappingURL=chunk-
|
|
2898
|
+
//# sourceMappingURL=chunk-6R4744NH.js.map
|
|
2899
|
+
//# sourceMappingURL=chunk-6R4744NH.js.map
|