Skip to content

Commit 504c4b9

Browse files
committed
refactor: reuse anthropicSupportsNativeXhigh in Anthropic fetch wrapper
Replace the duplicated Opus 4.7+ regex inside wrapFetchWithAnthropicCacheControl with a call to the existing anthropicSupportsNativeXhigh helper from src/common/types/thinking.ts. The helper already performs the same regex check plus provider-prefix normalization (e.g., anthropic/claude-opus-4-7 via the ai-model-id gateway header), keeping the wire-level detection and the policy-level detection in one place.
1 parent 02764cf commit 504c4b9

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/node/services/providerModelFactory.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import assert from "node:assert";
22
import type { XaiProviderOptions } from "@ai-sdk/xai";
33
import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
44
import { wrapLanguageModel, type LanguageModel } from "ai";
5-
import type { ThinkingLevel } from "@/common/types/thinking";
5+
import { anthropicSupportsNativeXhigh, type ThinkingLevel } from "@/common/types/thinking";
66
import { Ok, Err } from "@/common/types/result";
77
import type { Result } from "@/common/types/result";
88
import type { SendMessageError } from "@/common/types/errors";
@@ -324,9 +324,10 @@ export function wrapFetchWithAnthropicCacheControl(
324324
// with the model exposed via the ai-model-id header.
325325
const directModel = typeof json.model === "string" ? json.model : "";
326326
const headerModelId = incomingHeaders.get("ai-model-id") ?? "";
327-
const targetsOpus47OrNewer = [directModel, headerModelId].some((candidate) =>
328-
/claude-opus-(?:4-(?:[7-9]|\d{2,})|[5-9]|\d{2,})/i.test(candidate)
329-
);
327+
// Reuse the shared Opus 4.7+ detector so the wire-level regex stays in
328+
// one place (src/common/types/thinking.ts) — it also normalizes provider
329+
// prefixes (e.g., `anthropic/claude-opus-4-7`).
330+
const targetsOpus47OrNewer = [directModel, headerModelId].some(anthropicSupportsNativeXhigh);
330331

331332
const directThinking = isRecord(json.thinking) ? json.thinking : undefined;
332333
const providerOpts = isRecord(json.providerOptions) ? json.providerOptions : undefined;

0 commit comments

Comments
 (0)