Skip to content

Commit b71c5b0

Browse files
committed
feat: allign with vscode-copilot-chat extractThinkingData, otherwise it will cause miss cache occasionally
1 parent 10595c9 commit b71c5b0

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

src/routes/messages/responses-stream-translation.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ const handleOutputItemDone = (
163163

164164
const outputIndex = rawEvent.output_index
165165
const blockIndex = openThinkingBlockIfNeeded(state, outputIndex, events)
166-
const signature = item.encrypted_content
166+
const signature = (item.encrypted_content ?? "") + "@" + item.id
167167
if (signature) {
168168
events.push({
169169
type: "content_block_delta",
@@ -468,8 +468,9 @@ const openThinkingBlockIfNeeded = (
468468
outputIndex: number,
469469
events: Array<AnthropicStreamEventData>,
470470
): number => {
471-
const contentIndex = 0
472-
const key = getBlockKey(outputIndex, contentIndex)
471+
//thinking blocks has multiple summary_index, should combine into one block
472+
const summaryIndex = 0
473+
const key = getBlockKey(outputIndex, summaryIndex)
473474
let blockIndex = state.blockIndexByKey.get(key)
474475

475476
if (blockIndex === undefined) {

src/routes/messages/responses-translation.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const translateAnthropicMessagesToResponsesPayload = (
7272
stream: payload.stream ?? null,
7373
store: false,
7474
parallel_tool_calls: true,
75-
reasoning: { effort: "high", summary: "auto" },
75+
reasoning: { effort: "high", summary: "detailed" },
7676
include: ["reasoning.encrypted_content"],
7777
}
7878

@@ -232,16 +232,20 @@ const createImageContent = (
232232

233233
const createReasoningContent = (
234234
block: AnthropicThinkingBlock,
235-
): ResponseInputReasoning => ({
236-
type: "reasoning",
237-
summary: [
238-
{
239-
type: "summary_text",
240-
text: block.thinking,
241-
},
242-
],
243-
encrypted_content: block.signature,
244-
})
235+
): ResponseInputReasoning => {
236+
// allign with vscode-copilot-chat extractThinkingData, otherwise it will cause miss cache occasionally —— the usage input cached tokens to be 0
237+
// https://github.com/microsoft/vscode-copilot-chat/blob/main/src/platform/endpoint/node/responsesApi.ts#L162
238+
// when use in codex cli, reasoning id is empty, so it will cause miss cache occasionally
239+
const array = block.signature.split("@")
240+
const signature = array[0]
241+
const id = array[1]
242+
return {
243+
id,
244+
type: "reasoning",
245+
summary: [],
246+
encrypted_content: signature,
247+
}
248+
}
245249

246250
const createFunctionToolCall = (
247251
block: AnthropicToolUseBlock,

src/services/copilot/create-responses.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export interface ResponseFunctionCallOutputItem {
7777
}
7878

7979
export interface ResponseInputReasoning {
80+
id?: string
8081
type: "reasoning"
8182
summary: Array<{
8283
type: "summary_text"

0 commit comments

Comments
 (0)