Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lua/codecompanion/adapters/http/openai_responses.lua
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ return {
if not self.opts.stream then
-- Reasoning
local reasoning = {}
local content = nil
if json.output then
for _, item in ipairs(json.output) do
if item.type == "reasoning" then
Expand All @@ -342,6 +343,12 @@ return {
reasoning.content = reasoning.content and (reasoning.content .. "\n\n" .. block.text) or block.text
end
end
elseif item.type == "message" then
for _, block in ipairs(item.content) do
if block.type == "output_text" then
content = content and (content .. "\n\n" .. block.text) or block.text
end
end
end
end
end
Expand Down Expand Up @@ -369,13 +376,6 @@ return {
end)
end

local content = json.output
and json.output[1]
and json.output[1].content
and json.output[1].content[1]
and json.output[1].content[1].text
or nil

return {
status = "success",
output = {
Expand Down
14 changes: 5 additions & 9 deletions tests/adapters/http/test_openai_responses.lua
Original file line number Diff line number Diff line change
Expand Up @@ -536,16 +536,12 @@ T["Responses"]["No Streaming"]["can process reasoning output"] = function()
-- Match the format of the actual request
local json = { body = data }

h.expect_contains(
"**Choosing descriptive terms**",
adapter.handlers.response.parse_chat(adapter, json).output.reasoning.content
)
local output = adapter.handlers.response.parse_chat(adapter, json).output

h.eq(
"rs_0a10a8c968d594670168e91d0204ac8195b26b3e4de997f65c",
adapter.handlers.response.parse_chat(adapter, json).output.reasoning.id
)
h.eq("gAAAAABo6", adapter.handlers.response.parse_chat(adapter, json).output.reasoning.encrypted_content)
h.expect_contains("**Choosing descriptive terms**", output.reasoning.content)
h.eq("rs_0a10a8c968d594670168e91d0204ac8195b26b3e4de997f65c", output.reasoning.id)
h.eq("gAAAAABo6", output.reasoning.encrypted_content)
h.eq("Dynamic expressive", output.content)
Copy link
Copy Markdown
Contributor Author

@xhebox xhebox Mar 13, 2026

Choose a reason for hiding this comment

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

FYI, sample data is not fully tested. Before the change, output.content is nil, while it is "Dynamic expressive" actually. The first block can be item.type == reasoning.

@olimorris

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I have no idea what you mean by "not fully tested".

I haven't tried this PR out yet but will run it through OpenAI's models at some point this weekend.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have no idea what you mean by "not fully tested".

mock data tests/adapters/http/stubs/openai_responses_inline.txt") has two items, type = reasoning for the first, type = message for the second.
We tested the reasoning content but not the message content in this test. It would not pass if we do check the message content.

end

T["Responses"]["Streaming"] = new_set()
Expand Down
Loading