Skip to content

fix: support Responses input string shortcut#708

Open
FutureUnreal wants to merge 2 commits intoding113:devfrom
FutureUnreal:dev
Open

fix: support Responses input string shortcut#708
FutureUnreal wants to merge 2 commits intoding113:devfrom
FutureUnreal:dev

Conversation

@FutureUnreal
Copy link

@FutureUnreal FutureUnreal commented Feb 2, 2026

Summary

Fix /v1/responses OpenAI-compatible parsing to accept input as a string shortcut and normalize it to standard input[] 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:

  1. Converts string input to standard array format:
    "input": "hello" → [{ "role": "user", "content": [{ "type": "input_text", "text": "hello" }] }]
  2. Wraps single object input into an array for compatibility
  3. Handles empty strings by converting to empty array

Changes

Core Changes

  • src/app/v1/_lib/codex/chat-completions-handler.ts (+35/-1)
    • Added normalizeResponseInput() function for input format normalization
    • Updated format detection to recognize string and object inputs as valid Response API format
    • Call normalization before downstream guards/filters

Tests

  • tests/unit/proxy/chat-completions-handler-guard-pipeline.test.ts (+39/-0)
    • Added test case for string input shortcut support

Testing

Automated Tests

  • Unit tests added

Manual Testing

bun run typecheck
bun run test -- tests/unit/proxy/chat-completions-handler-guard-pipeline.test.ts

Checklist

  • Code follows project conventions
  • Self-review completed
  • Tests pass locally
  • No behavior change for existing input: [...] requests

Description enhanced by Claude AI

@coderabbitai
Copy link

coderabbitai bot commented Feb 2, 2026

📝 Walkthrough

概览

添加了 normalizeResponseInput 辅助函数,用于将各种输入格式(字符串、对象、数组)规范化为一致的数组形式,并在 Response API 格式处理中集成该规范化逻辑。同时新增相应的测试用例验证字符串输入的处理。

变更

Cohort / File(s) 摘要
输入规范化处理
src/app/v1/_lib/codex/chat-completions-handler.ts
新增 normalizeResponseInput 函数,支持将字符串和对象输入转换为统一的数组格式;扩展 Response API 格式检测以接受数组、字符串或对象作为输入;在请求处理流程中应用规范化逻辑。
测试覆盖
tests/unit/proxy/chat-completions-handler-guard-pipeline.test.ts
新增测试用例验证字符串输入作为 OpenAI 快捷方式的支持,确保在处理字符串 input 时正确设置 originalFormat 并转换为单个用户 input_text 消息,同时验证完整的guard pipeline调用序列。

代码审查工作量评估

🎯 2 (Simple) | ⏱️ ~12 分钟

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed PR标题明确概括了主要改动:支持Responses API中input作为字符串快捷方式,与代码改动相符。
Description check ✅ Passed The pull request description clearly relates to the changeset, describing a feature to support string shortcuts for the Response API input parameter and normalize them to array format.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 /v1/responses endpoint by allowing the input field to be provided as a string or a single object, in addition to the existing array format. A new normalization function ensures these varied inputs are consistently transformed into the expected array structure before processing, preventing rejections from certain OpenAI-compatible clients and enhancing overall API compatibility.

Highlights

  • Input Normalization: Introduced a new normalizeResponseInput function to standardize the input field in API requests.
  • String Shortcut Support: The API now accepts input as a string (e.g., {"input": "hello"}) and converts it into the standard array format required by the Responses API.
  • Single Object Input Handling: Requests with input as a single object (instead of an array) are now automatically wrapped into an array for compatibility.
  • Enhanced Format Detection: The isResponseAPIFormat check has been updated to correctly identify requests where input is a string, object, or array.
  • New Unit Test: A dedicated unit test was added to confirm the proper functionality of the string shortcut for input in the Responses API.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions github-actions bot added bug Something isn't working area:OpenAI area:provider labels Feb 2, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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 }],
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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.

Suggested change
content: [{ type: "input_text", text }],
content: [{ type: "text", text }],

Copy link

@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.

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +31 to +39
const text = input.trim();
request.input = text.length
? [
{
role: "user",
content: [{ type: "input_text", text }],
},
]
: [];
Copy link

Choose a reason for hiding this comment

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

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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".

@github-actions github-actions bot added the size/XS Extra Small PR (< 50 lines) label Feb 2, 2026
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

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

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

Labels

area:OpenAI area:provider bug Something isn't working size/XS Extra Small PR (< 50 lines)

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant