Skip to content

Conversation

AtlantisPleb
Copy link

Summary

This PR implements full support for AI SDK v5 by:

  • Updating dependencies from v4 alpha to v5 beta versions
  • Fixing compatibility issues with the new LanguageModelV2 interface
  • Implementing proper SSE streaming support with consistent text event IDs
  • Removing deprecated features like toolCallType and updating to new interfaces

Changes Made

  • Updated @ai-sdk/provider to 2.0.0-beta.1
  • Updated @ai-sdk/provider-utils to 2.2.8
  • Fixed tool call interface (removed toolCallType, changed args to input)
  • Implemented SSE parser for Cloudflare's streaming format
  • Fixed text event ID consistency (all text events now share the same ID)
  • Removed unsupported response_format field for Cloudflare AI
  • Added comprehensive logging for debugging

Testing

  • Tested with llama-3.1-8b-instruct model
  • Verified streaming works correctly with consistent text event IDs
  • Confirmed all text chunks are received and parsed properly
  • Tested in production Next.js application

Related Issues

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

eli-front and others added 6 commits May 26, 2025 18:30
- Update @ai-sdk/provider to 2.0.0-beta.1
- Update @ai-sdk/provider-utils to 2.2.8
- Fix TypeScript compatibility issues:
  - Remove toolCallType from tool calls (not in v5 spec)
  - Change 'args' to 'input' for tool calls
  - Convert content to proper stream parts in doStream
  - Replace LanguageModelV1FunctionToolCall with custom type
- Bump version to 0.5.3-v5-beta
- Change stream part type from 'text' to proper 'text-delta'
- Add text-start and text-end events to frame text streaming
- Include required id field for stream parts
- Change textDelta to delta property for v5 spec
- Fix system message content extraction in message converter
- Add better error handling in stream processing
- Add support for nested response in result object
- Add debug logging for REST API requests
- Handle both response and result.response formats
- Track textStarted state across transform calls using closure variable
- Only emit text-end event if text was actually started
- Properly map usage data from Cloudflare response format
- Filter out empty response strings to avoid unnecessary events
- Generate single text ID when starting text stream
- Use same ID for all text-delta events
- Use same ID for text-end event
- Fixes 'text part not found' error in AI SDK v5
@eli-front
Copy link

eli-front commented Jul 14, 2025

@AtlantisPleb thanks for continuing this for me -- I didn't have capacity to finish up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants