File size: 978 Bytes
cd8bd0a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const COPILOT_REASONING_SUMMARY_MARKER = "_omnirouteCopilotReasoningSummary";

export function applyClaudeCodeCompatibleThinkingDisplay(
  thinking: Record<string, unknown>,
  options: {
    normalizedBody?: Record<string, unknown> | null;
    summarizeThinking?: boolean;
  } = {}
) {
  if (thinking.type === "disabled") {
    return thinking;
  }

  const markerRequestsSummary =
    options.normalizedBody?.[COPILOT_REASONING_SUMMARY_MARKER] === "summarized";
  const connectionRequestsSummary = options.summarizeThinking === true;
  if (!markerRequestsSummary && !connectionRequestsSummary) {
    return thinking;
  }

  const hasExplicitDisplay =
    Object.prototype.hasOwnProperty.call(thinking, "display") &&
    thinking.display !== undefined &&
    thinking.display !== null &&
    String(thinking.display).trim().length > 0;
  if (hasExplicitDisplay && !markerRequestsSummary) {
    return thinking;
  }

  return {
    ...thinking,
    display: "summarized",
  };
}