Commit b094c07
fix(anthropic): allow null content in compaction_delta streaming schema (#12471)
## Background
PR #12384 introduced support for Anthropic's compaction feature, but the
streaming Zod schema for compaction_delta events requires content to be
a non-nullable string. Anthropic's API sends compaction_delta events
with content: null (e.g. the initial frame before the compaction summary
text), which causes Zod validation to fail at runtime.
## Summary
Changed content: z.string() to content: z.string().nullish() in the
compaction_delta streaming schema in
packages/anthropic/src/anthropic-messages-api.ts. This matches the
existing content_block_start schema for compaction, which already uses
.nullish().
## Manual Verification
Reproduction requires streaming a conversation that exceeds the
compaction trigger threshold (50k+ tokens) with @ai-sdk/anthropic, which
triggers a compaction_delta event with content: null. This is not
practical to verify without an API key and a large conversation, but the
added regression test simulates this exact scenario by streaming a
compaction_delta chunk with content: null.
## Checklist
- Tests have been added / updated (for bug fixes / features)
- Documentation has been added / updated (for bug fixes / features)
- A patch changeset for relevant packages has been added (for bug fixes
/ features - run pnpm changeset in the project root)
- I have reviewed this pull request (self-review)
## Related Issues
Fixes #12470
---------
Co-authored-by: Embedder <215220128+embedder-dev@users.noreply.github.com>
Co-authored-by: Aayush Kapoor <83492835+aayush-kapoor@users.noreply.github.com>1 parent 0c531f9 commit b094c07
File tree
4 files changed
+47
-6
lines changed- .changeset
- packages/anthropic/src
4 files changed
+47
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1128 | 1128 | | |
1129 | 1129 | | |
1130 | 1130 | | |
1131 | | - | |
| 1131 | + | |
1132 | 1132 | | |
1133 | 1133 | | |
1134 | 1134 | | |
| |||
Lines changed: 34 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5679 | 5679 | | |
5680 | 5680 | | |
5681 | 5681 | | |
| 5682 | + | |
| 5683 | + | |
| 5684 | + | |
| 5685 | + | |
| 5686 | + | |
| 5687 | + | |
| 5688 | + | |
| 5689 | + | |
| 5690 | + | |
| 5691 | + | |
| 5692 | + | |
| 5693 | + | |
| 5694 | + | |
| 5695 | + | |
| 5696 | + | |
| 5697 | + | |
| 5698 | + | |
| 5699 | + | |
| 5700 | + | |
| 5701 | + | |
| 5702 | + | |
| 5703 | + | |
| 5704 | + | |
| 5705 | + | |
| 5706 | + | |
| 5707 | + | |
| 5708 | + | |
| 5709 | + | |
| 5710 | + | |
| 5711 | + | |
| 5712 | + | |
| 5713 | + | |
| 5714 | + | |
| 5715 | + | |
5682 | 5716 | | |
5683 | 5717 | | |
5684 | 5718 | | |
| |||
Lines changed: 7 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1840 | 1840 | | |
1841 | 1841 | | |
1842 | 1842 | | |
1843 | | - | |
1844 | | - | |
1845 | | - | |
1846 | | - | |
1847 | | - | |
| 1843 | + | |
| 1844 | + | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
| 1849 | + | |
1848 | 1850 | | |
1849 | 1851 | | |
1850 | 1852 | | |
| |||
0 commit comments