Skip to content

fix(wand): nodejs direct fetch#1193

Merged
Sg312 merged 1 commit intostagingfrom
fix/wand
Aug 29, 2025
Merged

fix(wand): nodejs direct fetch#1193
Sg312 merged 1 commit intostagingfrom
fix/wand

Conversation

@Sg312
Copy link
Contributor

@Sg312 Sg312 commented Aug 29, 2025

Summary

Direct fetch on azure/openai endpoints

Type of Change

  • Bug fix

Testing

Manual

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Aug 29, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
sim Ready Ready Preview Comment Aug 29, 2025 11:21pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Aug 29, 2025 11:21pm

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Summary

This PR addresses compatibility issues between the OpenAI SDK and Node.js runtime for streaming API calls in the wand generation feature. The change switches from using the OpenAI SDK to native fetch for making streaming requests to Azure OpenAI and OpenAI endpoints.

The key modifications include:

  1. Runtime Change: Updates the API route from 'edge' to 'nodejs' runtime to support features that don't work in edge environments

  2. Native Fetch Implementation: Replaces the OpenAI SDK with direct HTTP calls using native fetch, providing more control over the streaming response handling

  3. Manual SSE Parsing: Implements custom Server-Sent Events (SSE) parsing logic to handle the streaming response format from OpenAI/Azure endpoints

  4. Enhanced Error Handling: Adds a safeStringify helper function to handle circular references in error objects and improves error logging with more contextual information

  5. Response Headers: Updates response headers to include 'Transfer-Encoding': 'chunked' for proper Node.js streaming compatibility

This change fits into the broader codebase by maintaining the same API interface while resolving underlying streaming issues. The wand generation feature appears to be a core component that generates content using AI models, and this fix ensures it works reliably across different runtime environments. The approach aligns with the existing provider pattern seen in other parts of the codebase, though it bypasses the structured provider system for this specific use case.

Confidence score: 3/5

  • This PR introduces significant complexity with manual SSE parsing that could lead to edge cases around buffer handling and connection management
  • Score reflects the high-risk nature of replacing well-tested SDK functionality with custom HTTP streaming logic
  • Pay close attention to apps/sim/app/api/wand-generate/route.ts for potential streaming and parsing issues

1 file reviewed, no comments

Edit Code Review Bot Settings | Greptile

@Sg312 Sg312 merged commit 7fcbafa into staging Aug 29, 2025
3 of 4 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/wand branch August 30, 2025 18:49
Sg312 added a commit that referenced this pull request Aug 30, 2025
waleedlatif1 pushed a commit that referenced this pull request Sep 1, 2025
arenadeveloper02 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Sep 19, 2025
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.

1 participant