Skip to content

Commit 771ad96

Browse files
authored
fix createTool type with exactOptionalPropertyTypes (#12325)
## Description Fixed type error when using `createTool` with Agent when `exactOptionalPropertyTypes: true` is enabled in TypeScript config. The `ProviderDefinedTool` structural type in `@internal/external-types` had two incompatibilities with `ToolAction`: 1. `inputSchema` was required but `ToolAction.inputSchema` is optional 2. `execute?` didn't allow explicit `undefined` values, which `exactOptionalPropertyTypes` distinguishes from absent properties Changes: - `inputSchema: unknown` → `inputSchema?: unknown` - `execute?: (...args: any[]) => any` → `execute?: ((...args: any[]) => any) | undefined` These changes make the types more permissive for users with stricter TypeScript configs while having no effect for users without `exactOptionalPropertyTypes`. ## Related Issue(s) Fixes #12281 ## Type of Change - [x] Bug fix (non-breaking change that fixes an issue) - [ ] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [ ] Code refactoring - [ ] Performance improvement - [ ] Test update ## Checklist - [x] I have made corresponding changes to the documentation (if applicable) - [ ] I have added tests that prove my fix is effective or that my feature works <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Fixed type compatibility for `createTool` with Agent configurations, correcting optional property handling to support strict TypeScript type checking. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent c5f4c00 commit 771ad96

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

.changeset/good-falcons-win.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@mastra/core': patch
3+
---
4+
5+
Fixed type error when using createTool with Agent when exactOptionalPropertyTypes is enabled in TypeScript config. The ProviderDefinedTool structural type now correctly marks inputSchema as optional and allows execute to be undefined, matching the ToolAction interface. Fixes #12281

packages/_external-types/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ export type ProviderDefinedTool =
2525
type?: string;
2626
id?: string;
2727
args?: Record<string, unknown>;
28-
execute?: (...args: any[]) => any;
28+
execute?: ((...args: any[]) => any) | undefined;
2929
[key: string]: any; // Allows experimental_* and other future properties
3030
}
3131
| {
3232
// ToolV5 structure
33-
inputSchema: unknown;
33+
inputSchema?: unknown;
3434
description?: string;
3535
type?: string;
3636
id?: string;
3737
name?: string;
3838
providerOptions?: any;
39-
execute?: (...args: any[]) => any;
39+
execute?: ((...args: any[]) => any) | undefined;
4040
outputSchema?: any;
4141
[key: string]: any; // Allows onInput* callbacks and other future properties
4242
};

0 commit comments

Comments
 (0)