Description
The issue is in smooth-stream.ts line 82. The template variables ${match} and ${buffer} are in each other's slot (i.e. interchanged), making the thrown error read completely backwards:
# ACTUAL (wrong)
Received: "world" expected to start with "Hello, world!"
The logic buffer.startsWith(match) means the buffer starts with match - so the error should say the match is not a prefix of the buffer. The current message says the opposite.
Fix - swap the two variable positions:
Old : `...Received: "${match}" expected to start with "${buffer}"`
New : `...Received: "${match}" which is not a prefix of buffer "${buffer}"`
Reproduction
The existing test at smooth-stream.test.ts:816 already enshrines the confusing message as the expected snapshot. A minimal reproduction:
import { smoothStream } from 'ai';
const transform = smoothStream({
chunking: (_buffer) => 'world', // returns non-prefix
})({ tools: {} });
// Received: "world" expected to start with "Hello, world!"
AI SDK Version
- ai: 7.0.157
Code of Conduct
- I agree to follow this project's Code of Conduct