Skip to content
Merged
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
35 changes: 35 additions & 0 deletions src/core/task/__tests__/apiConversationHistory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"

import { prepareApiConversationMessage } from "../apiConversationHistory.js"
import { providerIdentifiers } from "@roo-code/types/provider-identifiers"
import type { ApiHandler } from "../../../api"

describe("prepareApiConversationMessage", () => {
beforeEach(() => {
Expand Down Expand Up @@ -83,6 +84,40 @@ describe("prepareApiConversationMessage", () => {
])
})

it.each(["reasoning-1", undefined])("preserves encrypted reasoning alongside its visible text (id: %s)", (id) => {
const api = {
createMessage: vi.fn<ApiHandler["createMessage"]>(),
getModel: vi.fn<ApiHandler["getModel"]>(),
countTokens: vi.fn<ApiHandler["countTokens"]>(),
getEncryptedContent: () => ({ encrypted_content: "encrypted", ...(id ? { id } : {}) }),
}
const result = prepareApiConversationMessage({
message: {
role: "assistant",
content: [
{ type: "text", text: "Reading files" },
{ type: "tool_use", id: "call-1", name: "read_file", input: { path: "a.ts" } },
],
},
reasoning: "visible reasoning",
api,
apiConfiguration: { apiProvider: providerIdentifiers.openaiCodex },
apiConversationHistory: [],
})

expect(result.content).toEqual([
{
type: "reasoning",
text: "visible reasoning",
summary: [],
encrypted_content: "encrypted",
...(id ? { id } : {}),
},
{ type: "text", text: "Reading files" },
{ type: "tool_use", id: "call-1", name: "read_file", input: { path: "a.ts" } },
])
})

it("appends thought signatures for non-Anthropic protocols", () => {
const result = prepareApiConversationMessage({
message: { role: "assistant", content: "answer" },
Expand Down
7 changes: 7 additions & 0 deletions src/core/task/apiConversationHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ function prepareAssistantMessage(
type: "reasoning",
text: reasoning,
summary: [] as any[],
// A visible summary must not discard the encrypted state needed for continuation.
...(reasoningData?.encrypted_content
? {
encrypted_content: reasoningData.encrypted_content,
...(reasoningData.id ? { id: reasoningData.id } : {}),
}
: {}),
}

prependContentBlock(messageWithTs, reasoningBlock)
Expand Down
Loading