Repository navigation
Conversation
📝 WalkthroughWalkthroughThis PR introduces a shared content extraction utility and applies it across three LLM provider clients to normalize message content handling. A new ChangesContent extraction normalization
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/llm/openai.ts (1)
214-216:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winUse
isStreamingto select SSE parsing pathLine 214 checks
onTokendirectly. IfonTokenis provided butshouldStream(model)is false, the request is JSON (stream: false) yet this branch still callsreadStream, causing incorrect parsing.Proposed fix
- if (onToken && response.body) { + if (isStreaming && response.body) { return this.readStream(response.body, model, startTime, onToken); }As per coding guidelines, "Fix LLM stream response parsing: check
isStreamingflag instead ofonTokencallback to correctly distinguish JSON responses from SSE-formatted streams (critical bugs at openai.ts:189, openrouter.ts:179)."🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/llm/openai.ts` around lines 214 - 216, The branch currently checks the presence of the onToken callback and calls readStream(response.body, model, startTime, onToken) which attempts SSE parsing even for non-stream JSON responses; change the condition to use the isStreaming/shouldStream predicate (e.g., shouldStream(model) or a computed isStreaming boolean used earlier) instead of onToken so that readStream is only invoked when the request was made as a stream; update the conditional that references response.body to guard with isStreaming (and preserve the existing parameters to readStream) and ensure non-stream paths handle JSON parsing as before.src/llm/openrouter.ts (1)
231-234:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winGate streaming reader with
isStreamingLine 232 uses
onTokendirectly. When streaming is disabled for a model (shouldStream(model) === false), this can still route a JSON response intoreadStream.Proposed fix
- if (onToken && response.body) { + if (isStreaming && response.body) { return this.readStream(response.body, model, startTime, onToken); }As per coding guidelines, "Fix LLM stream response parsing: check
isStreamingflag instead ofonTokencallback to correctly distinguish JSON responses from SSE-formatted streams (critical bugs at openai.ts:189, openrouter.ts:179)."🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/llm/openrouter.ts` around lines 231 - 234, The streaming branch currently checks only for onToken and can call readStream on non-SSE JSON responses; change the condition to guard with the model streaming flag instead: compute or use the existing isStreaming/shouldStream(model) boolean and replace the `if (onToken && response.body)` with something like `if (isStreaming && onToken && response.body)` (or `if (shouldStream(model) && onToken && response.body)`), so readStream(model, startTime, onToken) is only invoked for true streaming models and JSON responses take the non-stream parsing path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/llm/openai.ts`:
- Around line 214-216: The branch currently checks the presence of the onToken
callback and calls readStream(response.body, model, startTime, onToken) which
attempts SSE parsing even for non-stream JSON responses; change the condition to
use the isStreaming/shouldStream predicate (e.g., shouldStream(model) or a
computed isStreaming boolean used earlier) instead of onToken so that readStream
is only invoked when the request was made as a stream; update the conditional
that references response.body to guard with isStreaming (and preserve the
existing parameters to readStream) and ensure non-stream paths handle JSON
parsing as before.
In `@src/llm/openrouter.ts`:
- Around line 231-234: The streaming branch currently checks only for onToken
and can call readStream on non-SSE JSON responses; change the condition to guard
with the model streaming flag instead: compute or use the existing
isStreaming/shouldStream(model) boolean and replace the `if (onToken &&
response.body)` with something like `if (isStreaming && onToken &&
response.body)` (or `if (shouldStream(model) && onToken && response.body)`), so
readStream(model, startTime, onToken) is only invoked for true streaming models
and JSON responses take the non-stream parsing path.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a37310ef-fed6-43ab-819b-b14c3883475e
📒 Files selected for processing (4)
src/llm/content.tssrc/llm/ollama.tssrc/llm/openai.tssrc/llm/openrouter.ts
Summary
Fixes #13.
Verification
npm run buildnpx eslint src/llm/content.ts src/llm/openai.ts src/llm/openrouter.ts src/llm/ollama.tsgit diff --checkNote: full
npm run lintstill fails on existing unrelated React/hooks and unused-variable violations outside the LLM provider files.Summary by CodeRabbit