feat(openai): add OpenAI protocol adapter with configurable API mode#74
feat(openai): add OpenAI protocol adapter with configurable API mode#74CJackHwang wants to merge 2 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 95e8ceacd4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const data = await response.json(); | ||
| const outputText = data?.output_text; | ||
| if (outputText) onChunk(outputText); | ||
| return; |
There was a problem hiding this comment.
Parse Responses text from
output instead of output_text
In apiMode: 'auto' (the new default), a successful /responses call returns early after reading only data?.output_text. The REST response body typically carries assistant text under output[].content[] (e.g. type: "output_text"), so output_text can be absent and this path emits no chunk, yielding an empty assistant reply while skipping fallback because the status is 200. This makes normal OpenAI responses appear blank for users on the new mode.
Useful? React with 👍 / 👎.
| @@ -216,7 +288,7 @@ export class OpenAIChatService implements IChatService<OpenAIServiceConfig> { | |||
| }; | |||
There was a problem hiding this comment.
Keep normalized tool calls in assistant history message
The new compatibility path detects tool calls from message.content via normalizeToolCalls(message), but the assistant turn pushed into messages still stores only message.tool_calls. When a provider returns tool calls only in content, the code executes tools and then sends role: "tool" messages without a matching assistant tool_calls record in history, which commonly breaks the next chat-completions request validation and stops the tool loop.
Useful? React with 👍 / 👎.
Motivation
/v1/responses与/v1/chat/completions)并支持特殊网关/厂商差异,新增可配置的“协议模式”以提高互操作性与容错性。message.tool_calls结构导致在不同 API 形态下失效。Description
OpenAIServiceConfig中新增apiMode?: 'auto' | 'chat_completions' | 'responses'并在调用链中透传(useSettings→useChatStream→StreamController→apiService→OpenAIChatService)。OpenAIChatService中实现协议适配层:新增buildChatCompletionsPayload(...)与buildResponsesPayload(...),以及normalizeBaseUrl(...)、shouldFallbackToChatCompletions(...)等辅助方法用于构建请求与判断回退条件。apiMode: 'auto'下优先尝试/v1/responses,当返回404/501或明显的“不支持/unsupported/unknown endpoint/responses” 字样时自动回退到/v1/chat/completions;非流式的responses路径会读取output_text并通过现有的 chunk 回调发出以保持兼容。normalizeToolCalls(...)以兼容不同位置的工具调用信息(除了message.tool_calls也会从message.content中查找tool_call部分),并将构造器结果用于streamWithTools的工具执行流程中。Auto/Responses/Chat Completions)并补充对应 i18n 文案(EN / ZH-CN / JA)。Testing
npm run build构建通过,生产包成功生成(构建过程中输出了原有的若干警告,但不影响本次改动的编译通过)。Codex Task