fix: support Responses input string shortcut#708
fix: support Responses input string shortcut#708FutureUnreal wants to merge 2 commits intoding113:devfrom
Conversation
…ring fix: support Responses input string shortcut
📝 Walkthrough概览添加了 变更
代码审查工作量评估🎯 2 (Simple) | ⏱️ ~12 分钟 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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 |
Summary of ChangesHello @FutureUnreal, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request improves the flexibility of the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds support for string and single-object shortcuts for the input field in OpenAI-compatible /v1/responses requests, enhancing compatibility with various clients. The implementation introduces a normalizeResponseInput function to convert these shortcuts into the standard array format before they enter the guard pipeline. The associated format detection logic has been correctly updated, and a new unit test effectively validates the new string shortcut functionality. The changes are well-structured and address the stated goal. I have one suggestion to improve consistency within the codebase.
| ? [ | ||
| { | ||
| role: "user", | ||
| content: [{ type: "input_text", text }], |
There was a problem hiding this comment.
In the normalized input, you're using type: "input_text". However, other parts of the codebase, like the existing test case Response(input) 请求成功路径必须执行全链路 guards/filters 再 forward/dispatch in tests/unit/proxy/chat-completions-handler-guard-pipeline.test.ts, use type: "text". To maintain consistency and avoid potential issues in downstream processing, it would be better to use "text" here as well.
| content: [{ type: "input_text", text }], | |
| content: [{ type: "text", text }], |
| const text = input.trim(); | ||
| request.input = text.length | ||
| ? [ | ||
| { | ||
| role: "user", | ||
| content: [{ type: "input_text", text }], | ||
| }, | ||
| ] | ||
| : []; |
There was a problem hiding this comment.
Consider whether whitespace-only input (e.g., " ") should be rejected with a validation error instead of silently converting to empty array []
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/app/v1/_lib/codex/chat-completions-handler.ts
Line: 31:39
Comment:
Consider whether whitespace-only input (e.g., `" "`) should be rejected with a validation error instead of silently converting to empty array `[]`
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/app/v1/_lib/codex/chat-completions-handler.ts`:
- Around line 28-40: In chat-completions-handler.ts, stop trimming the incoming
string and stop converting empty strings to an empty array: use the raw input
string (do not call trim()) when building request.input so the role "user"
content entry (content [{ type: "input_text", text }]) always preserves original
whitespace and is always created; leave empty/blank handling to upstream
validation logic rather than turning the input into [] in the branch that
currently checks typeof input === "string".
There was a problem hiding this comment.
Code Review Summary
This PR adds OpenAI-compatible string shortcut support for the Responses API input parameter. The implementation is clean and follows the project's coding standards.
PR Size: XS
- Lines changed: 75 (74 additions, 1 deletion)
- Files changed: 2
Issues Found
| Category | Critical | High | Medium | Low |
|---|---|---|---|---|
| Logic/Bugs | 0 | 0 | 0 | 0 |
| Security | 0 | 0 | 0 | 0 |
| Error Handling | 0 | 0 | 0 | 0 |
| Types | 0 | 0 | 0 | 0 |
| Comments/Docs | 0 | 0 | 0 | 0 |
| Tests | 0 | 0 | 0 | 0 |
| Simplification | 0 | 0 | 0 | 0 |
Review Coverage
- Logic and correctness - Clean
- Security (OWASP Top 10) - Clean
- Error handling - Clean
- Type safety - Clean
- Documentation accuracy - Clean
- Test coverage - Adequate
- Code clarity - Good
Analysis Summary
The new normalizeResponseInput function properly handles:
- String input shortcut conversion (main use case)
- Empty/whitespace-only strings (returns empty array)
- Single object to array wrapping (compatibility enhancement)
- Type checking before operations (no runtime errors)
The test coverage includes the critical success path for string input normalization and validates the full guard pipeline execution. The implementation is defensive with proper type checks before calling methods like .trim().
Automated review by Claude AI
Summary
Fix
/v1/responsesOpenAI-compatible parsing to acceptinputas a string shortcut and normalize it to standardinput[]before the guard pipeline.Problem
Some OpenAI-compatible clients send requests with a string shortcut format:
{"model": "...", "input": "hi"}Previously, this was rejected and treated as missing required fields, while other gateways accept this format.
Solution
Added
normalizeResponseInput()function that:Changes
Core Changes
src/app/v1/_lib/codex/chat-completions-handler.ts(+35/-1)normalizeResponseInput()function for input format normalizationTests
tests/unit/proxy/chat-completions-handler-guard-pipeline.test.ts(+39/-0)Testing
Automated Tests
Manual Testing
bun run typecheck bun run test -- tests/unit/proxy/chat-completions-handler-guard-pipeline.test.tsChecklist
input: [...]requestsDescription enhanced by Claude AI