Commit a0f4f12
fix(auto-instrumentation): Use sync channel for AI SDK CJS streamText/streamObject in v4+ (#1768)
## Summary
- The CJS bundle entries for `streamText` and `streamObject` used `kind:
"Async"` for all versions (`>=3.0.0`), but
`DefaultStreamTextResult`/`DefaultStreamObjectResult` have no `.then()`,
so `asyncEnd` never fires when the transformer wraps via
`promise.then()`
- Splits the CJS entries to mirror the existing ESM split (which was
already correct in main):
- `>=3.0.0 <4.0.0`: `kind: "Async"` — v3, where the function was
genuinely async
- `>=4.0.0`: `kind: "Sync"` + sync channel — v4+, after the sync
refactor
- The `traceSyncStreamChannel` handlers for
`streamTextSync`/`streamObjectSync` already exist in `ai-sdk-plugin.ts`
(they were added when the ESM path was fixed), so no plugin change is
needed
## Test plan
- [x] `ai-sdk-plugin.test.ts` — 96 tests pass
- [x] Pre-existing test failures in `transformation.test.ts` /
`loader-hook.test.ts` confirmed unrelated (same failures on `main`)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent 6214e89 commit a0f4f12
1 file changed
Lines changed: 26 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
| 73 | + | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
81 | 93 | | |
82 | 94 | | |
83 | 95 | | |
| |||
188 | 200 | | |
189 | 201 | | |
190 | 202 | | |
191 | | - | |
| 203 | + | |
192 | 204 | | |
193 | 205 | | |
194 | 206 | | |
195 | 207 | | |
196 | 208 | | |
197 | 209 | | |
198 | 210 | | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
199 | 223 | | |
200 | 224 | | |
201 | 225 | | |
| |||
0 commit comments