-
Notifications
You must be signed in to change notification settings - Fork 0
[WIP] Update createTool to support AI SDK v5 and v6 features #7
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
Changes from all commits
9376e9b
19692bf
dcdd9ea
d051529
392152f
1e3f63c
7d85495
3ee5263
2987530
1e7c351
219f520
0a1bcb5
ca35f10
34df29b
fcacdb7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # AI SDK v6 Type Error Fix Summary | ||
|
|
||
| ## Problem | ||
| The build fails with TypeScript errors after upgrading to AI SDK v6. The main issues are: | ||
| 1. `ToolCallPart` type now requires `input` field (not optional), but stored data may only have deprecated `args` field | ||
| 2. Tool-result output types missing newer types like `execution-denied` and extended content types | ||
| 3. Generated component types out of sync with updated validators | ||
|
|
||
| ## Changes Made | ||
|
|
||
| ### 1. Fixed `tool-call` Part Handling (src/mapping.ts) | ||
| - Updated `toModelMessageContent()` to ensure `input` is always present by falling back to `args` or `{}` | ||
| - Updated `serializeContent()` and `fromModelMessageContent()` to handle both `input` and legacy `args` fields | ||
| - This fixes the core issue where AI SDK v6's `ToolCallPart` expects non-nullable `input` | ||
|
|
||
| ### 2. Fixed Tool Approval Response Handling (src/client/search.ts) | ||
| - Updated `filterOutOrphanedToolMessages()` to handle tool-approval-response parts that don't have `toolCallId` | ||
| - Tool-approval-response only has `approvalId`, not `toolCallId` | ||
|
|
||
| ### 3. Updated Generated Component Types (src/component/_generated/component.ts) | ||
| Made manual updates to sync with validators (normally done via `convex codegen`): | ||
| - Added `input: any` field to all tool-call type definitions | ||
| - Made `args` optional (`args?: any`) in tool-call types | ||
| - Added `execution-denied` output type to tool-result | ||
| - Added extended content types: `file-data`, `file-url`, `file-id`, `image-data`, `image-url`, `image-file-id`, `custom` | ||
| - Added `providerOptions` to text types in content values | ||
|
|
||
| ## Remaining Issues (5 TypeScript errors) | ||
|
|
||
| The remaining errors are due to a structural mismatch in the generated component types: | ||
| - Generated types have BOTH `experimental_content` (deprecated) and `output` (new) fields on tool-result | ||
| - Our validators only define `output`, not `experimental_content` | ||
| - TypeScript is comparing our new output types against the old experimental_content types | ||
| - This cannot be fixed manually - requires proper component regeneration | ||
|
|
||
| ### To Complete the Fix: | ||
| 1. Run `convex codegen --component-dir ./src/component` with a valid Convex deployment | ||
| 2. This will regenerate `src/component/_generated/component.ts` from the validators | ||
| 3. The regenerated types will: | ||
| - Remove the deprecated `experimental_content` field | ||
| - Use only the `output` field with correct types | ||
| - Properly match the validator definitions | ||
|
|
||
| ### Error Locations: | ||
| - `src/client/index.ts:1052` - addMessages call | ||
| - `src/client/index.ts:1103` - addMessages call | ||
| - `src/client/index.ts:1169` - updateMessage call | ||
| - `src/client/messages.ts:141` - addMessages call | ||
| - `src/client/start.ts:265` - addMessages call | ||
|
|
||
| All errors have the same root cause: content value types in tool-result output don't match experimental_content expectations. | ||
|
|
||
| ## Testing Plan | ||
| Once component types are regenerated: | ||
| 1. Run `npm run build` - should complete without errors | ||
| 2. Run `npm test` - ensure no regressions | ||
| 3. Test with actual AI SDK v6 workflow - verify tool-call handling works with both new `input` and legacy `args` fields | ||
|
|
||
| ## Notes | ||
| - The mapping functions in `src/mapping.ts` correctly handle both old and new formats | ||
| - Data with only `args` will be converted to have `input` (with `args` as fallback) | ||
| - Data with `input` will work directly | ||
| - This provides backward compatibility while supporting AI SDK v6's requirements | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -267,9 +267,14 @@ export function filterOutOrphanedToolMessages(docs: MessageDoc[]) { | |||||||||||||||||||||
| }); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } else if (doc.message?.role === "tool") { | ||||||||||||||||||||||
| const content = doc.message.content.filter((c) => | ||||||||||||||||||||||
| toolCallIds.has(c.toolCallId), | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
| const content = doc.message.content.filter((c) => { | ||||||||||||||||||||||
| // tool-result parts have toolCallId | ||||||||||||||||||||||
| if (c.type === "tool-result") { | ||||||||||||||||||||||
| return toolCallIds.has(c.toolCallId); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| // tool-approval-response parts don't have toolCallId, so include them | ||||||||||||||||||||||
|
Comment on lines
+271
to
+275
|
||||||||||||||||||||||
| // tool-result parts have toolCallId | |
| if (c.type === "tool-result") { | |
| return toolCallIds.has(c.toolCallId); | |
| } | |
| // tool-approval-response parts don't have toolCallId, so include them | |
| // Filter parts that are tied to a specific tool call by toolCallId. | |
| if (c.type === "tool-result" || c.type === "tool-approval-request") { | |
| return toolCallIds.has(c.toolCallId); | |
| } | |
| // tool-approval-response and other non-call-bound parts are always included. |
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.
This documentation file provides excellent context about the migration work and remaining issues. However, it should not be committed to the main codebase as it's implementation-specific documentation. Consider moving this content to the PR description, a GitHub issue, or a separate documentation folder for migration notes.