Commit 59fcf30
fix(ai): make experimental_context required in ToolLoopAgentOnFinishCallback (#12219)
## Summary
- Fixes type inconsistency where `ToolLoopAgentOnFinishCallback` had
`experimental_context` as optional (`?`) while
`StreamTextOnFinishCallback` and `GenerateTextOnFinishCallback` had it
as required
- Adds type tests to verify callback type compatibility between agent
and streamText/generateText callbacks
- Updates JSDoc comment to use "tool execution" wording for consistency
with other callbacks
## Problem
As reported in #12195, `ToolLoopAgentOnFinishCallback` defines
`experimental_context?: unknown` (optional), but
`StreamTextOnFinishCallback` and `GenerateTextOnFinishCallback` define
`experimental_context: unknown` (required).
Since `ToolLoopAgent` delegates to `streamText`/`generateText`, and both
always pass `experimental_context` when invoking the callback
([stream-text.ts#L1011](https://github.com/vercel/ai/blob/main/packages/ai/src/generate-text/stream-text.ts#L1011),
[generate-text.ts#L940](https://github.com/vercel/ai/blob/main/packages/ai/src/generate-text/generate-text.ts#L940)),
the types should match.
This inconsistency causes type errors when trying to use a
`StreamTextOnFinishCallback` where `ToolLoopAgentOnFinishCallback` is
expected (or vice versa).
## Solution
Changed `experimental_context?: unknown` to `experimental_context:
unknown` in `ToolLoopAgentOnFinishCallback` to match the other callback
types.
## Testing
- All 1812 tests pass including new type tests
- Added 2 new type tests verifying bidirectional type compatibility
between `StreamTextOnFinishCallback` and `ToolLoopAgentOnFinishCallback`
- Full type check passes with no errors
Fixes #12195
---------
Co-authored-by: kaizen403 <kaizen403@users.noreply.github.com>
Co-authored-by: <144584931+dancer@users.noreply.github.com>
Co-authored-by: josh <josh@afterima.ge>1 parent 5bba028 commit 59fcf30
File tree
3 files changed
+36
-3
lines changed- .changeset
- packages/ai/src/agent
3 files changed
+36
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
11 | 37 | | |
12 | 38 | | |
13 | 39 | | |
| |||
0 commit comments