Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 93 additions & 1 deletion packages/ai/src/generate-text/to-response-messages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ describe('toResponseMessages', () => {
`);
});

it('should not append text parts if text is empty string', async () => {
it('should preserve empty text parts', async () => {
const result = await toResponseMessages({
content: [
{
Expand All @@ -729,6 +729,98 @@ describe('toResponseMessages', () => {
[
{
"content": [
{
"providerOptions": undefined,
"text": "",
"type": "text",
},
{
"input": {},
"providerExecuted": undefined,
"providerOptions": undefined,
"toolCallId": "123",
"toolName": "testTool",
"type": "tool-call",
},
],
"role": "assistant",
},
]
`);
});

it('should preserve empty text between reasoning blocks for structural integrity', async () => {
const result = await toResponseMessages({
content: [
{
type: 'reasoning',
text: 'First reasoning block',
providerMetadata: {
bedrock: { signature: 'sig-1' },
},
},
{
type: 'text',
text: '',
},
{
type: 'reasoning',
text: 'Second reasoning block',
providerMetadata: {
bedrock: { signature: 'sig-2' },
},
},
{
type: 'text',
text: 'Final response',
},
{
type: 'tool-call',
toolCallId: '123',
toolName: 'testTool',
input: {},
},
],
tools: {
testTool: tool({
description: 'A test tool',
inputSchema: z.object({}),
}),
},
});

expect(result).toMatchInlineSnapshot(`
[
{
"content": [
{
"providerOptions": {
"bedrock": {
"signature": "sig-1",
},
},
"text": "First reasoning block",
"type": "reasoning",
},
{
"providerOptions": undefined,
"text": "",
"type": "text",
},
{
"providerOptions": {
"bedrock": {
"signature": "sig-2",
},
},
"text": "Second reasoning block",
"type": "reasoning",
},
{
"providerOptions": undefined,
"text": "Final response",
"type": "text",
},
{
"input": {},
"providerExecuted": undefined,
Expand Down
5 changes: 0 additions & 5 deletions packages/ai/src/generate-text/to-response-messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ export async function toResponseMessages<TOOLS extends ToolSet>({
continue;
}

// Skip empty text
if (part.type === 'text' && part.text.length === 0) {
continue;
}

switch (part.type) {
case 'text':
content.push({
Expand Down