Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ZodError: "Message must contain at least one part" when stopping stream before AI response #11444

@boh001

Description

@boh001

Description

I'm using createAgentUIStreamResponse. When the user clicks the stop button using stop function from useChat before the AI generates any response, a ZodError is thrown due to an empty message parts array.

plz let me know how to handle stop function

Steps to Reproduce

  1. Click the chat button to send a message
  2. Immediately click the stop button before the AI starts responding
  3. Observe the error
[cause]: Error [ZodError]: [
  {
    "origin": "array",
    "code": "too_small",
    "minimum": 1,
    "inclusive": true,
    "path": [7, "parts"],
    "message": "Message must contain at least one part"
  }
]

AI SDK Version

  • ai: 6.0.3
  • @ai-sdk/react: 3.0.3

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions