Skip to content

Commit 131c1e1

Browse files
committed
fix: address provider identifier review feedback
1 parent 4347068 commit 131c1e1

3 files changed

Lines changed: 23 additions & 82 deletions

File tree

packages/types/src/__tests__/provider-settings.test.ts

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getApiProtocol, providerIdentifiers, type ProviderName } from "../index.js"
1+
import { getApiProtocol, providerIdentifiers } from "../index.js"
22

33
describe("getApiProtocol", () => {
44
describe("Anthropic-style providers", () => {
@@ -15,21 +15,8 @@ describe("getApiProtocol", () => {
1515
})
1616

1717
describe("Vertex provider with Claude models", () => {
18-
it("uses the canonical Vertex identifier for Claude protocol selection", () => {
19-
const identifiers = providerIdentifiers as Record<string, string>
20-
const originalIdentifier = identifiers.vertex!
21-
22-
try {
23-
identifiers.vertex = "canonical-vertex"
24-
25-
expect(getApiProtocol(identifiers.vertex as ProviderName, "claude-3-opus")).toBe("anthropic")
26-
} finally {
27-
identifiers.vertex = originalIdentifier
28-
}
29-
})
30-
3118
it("should return 'anthropic' for vertex provider with claude models", () => {
32-
expect(getApiProtocol("vertex", "claude-3-opus")).toBe("anthropic")
19+
expect(getApiProtocol(providerIdentifiers.vertex, "claude-3-opus")).toBe("anthropic")
3320
expect(getApiProtocol("vertex", "Claude-3-Sonnet")).toBe("anthropic")
3421
expect(getApiProtocol("vertex", "CLAUDE-instant")).toBe("anthropic")
3522
expect(getApiProtocol("vertex", "anthropic/claude-3-haiku")).toBe("anthropic")
@@ -48,24 +35,8 @@ describe("getApiProtocol", () => {
4835

4936
describe("Vercel AI Gateway provider", () => {
5037
it("uses canonical gateway identifiers for Anthropic model protocol selection", () => {
51-
const identifiers = providerIdentifiers as Record<string, string>
52-
const originalVercelIdentifier = identifiers.vercelAiGateway!
53-
const originalZooIdentifier = identifiers.zooGateway!
54-
55-
try {
56-
identifiers.vercelAiGateway = "canonical-vercel-ai-gateway"
57-
identifiers.zooGateway = "canonical-zoo-gateway"
58-
59-
expect(getApiProtocol(identifiers.vercelAiGateway as ProviderName, "anthropic/claude-3-opus")).toBe(
60-
"anthropic",
61-
)
62-
expect(getApiProtocol(identifiers.zooGateway as ProviderName, "anthropic/claude-3-opus")).toBe(
63-
"anthropic",
64-
)
65-
} finally {
66-
identifiers.vercelAiGateway = originalVercelIdentifier
67-
identifiers.zooGateway = originalZooIdentifier
68-
}
38+
expect(getApiProtocol(providerIdentifiers.vercelAiGateway, "anthropic/claude-3-opus")).toBe("anthropic")
39+
expect(getApiProtocol(providerIdentifiers.zooGateway, "anthropic/claude-3-opus")).toBe("anthropic")
6940
})
7041

7142
it("should return 'anthropic' for vercel-ai-gateway provider with anthropic models", () => {
@@ -88,21 +59,8 @@ describe("getApiProtocol", () => {
8859
})
8960

9061
describe("Opencode Go provider", () => {
91-
it("uses the canonical OpenCode Go identifier for model-specific protocol selection", () => {
92-
const identifiers = providerIdentifiers as Record<string, string>
93-
const originalIdentifier = identifiers.opencodeGo!
94-
95-
try {
96-
identifiers.opencodeGo = "canonical-opencode-go"
97-
98-
expect(getApiProtocol(identifiers.opencodeGo as ProviderName, "qwen3.7-max")).toBe("anthropic")
99-
} finally {
100-
identifiers.opencodeGo = originalIdentifier
101-
}
102-
})
103-
10462
it("should return 'anthropic' for opencode-go Anthropic-format models (Qwen/MiniMax)", () => {
105-
expect(getApiProtocol("opencode-go", "qwen3.7-max")).toBe("anthropic")
63+
expect(getApiProtocol(providerIdentifiers.opencodeGo, "qwen3.7-max")).toBe("anthropic")
10664
expect(getApiProtocol("opencode-go", "qwen3.7-plus")).toBe("anthropic")
10765
expect(getApiProtocol("opencode-go", "qwen3.6-plus")).toBe("anthropic")
10866
expect(getApiProtocol("opencode-go", "minimax-m3")).toBe("anthropic")

packages/types/src/provider-settings.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -587,21 +587,33 @@ export const ANTHROPIC_STYLE_PROVIDERS: ProviderName[] = [
587587
providerIdentifiers.minimax,
588588
]
589589

590+
const CLAUDE_MODEL_ID_FRAGMENT = "claude"
591+
const ANTHROPIC_MODEL_ID_PREFIX = "anthropic/"
592+
const ANTHROPIC_MODEL_GATEWAY_PROVIDERS: ProviderName[] = [
593+
providerIdentifiers.vercelAiGateway,
594+
providerIdentifiers.zooGateway,
595+
]
596+
590597
export const getApiProtocol = (provider: ProviderName | undefined, modelId?: string): "anthropic" | "openai" => {
591598
if (provider && ANTHROPIC_STYLE_PROVIDERS.includes(provider)) {
592599
return "anthropic"
593600
}
594601

595-
if (provider && provider === providerIdentifiers.vertex && modelId && modelId.toLowerCase().includes("claude")) {
602+
if (
603+
provider &&
604+
provider === providerIdentifiers.vertex &&
605+
modelId &&
606+
modelId.toLowerCase().includes(CLAUDE_MODEL_ID_FRAGMENT)
607+
) {
596608
return "anthropic"
597609
}
598610

599611
// Vercel AI Gateway and Zoo Gateway use the anthropic protocol for anthropic models.
600612
if (
601613
provider &&
602-
(provider === providerIdentifiers.vercelAiGateway || provider === providerIdentifiers.zooGateway) &&
614+
ANTHROPIC_MODEL_GATEWAY_PROVIDERS.includes(provider) &&
603615
modelId &&
604-
modelId.toLowerCase().startsWith("anthropic/")
616+
modelId.toLowerCase().startsWith(ANTHROPIC_MODEL_ID_PREFIX)
605617
) {
606618
return "anthropic"
607619
}

src/shared/__tests__/checkExistApiConfig.spec.ts

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,7 @@ describe("checkExistKey", () => {
6767
})
6868

6969
it("recognizes keyless providers through their canonical identifiers", () => {
70-
const identifiers = providerIdentifiers as Record<string, string>
71-
const originalIdentifier = identifiers.fakeAi!
72-
73-
try {
74-
identifiers.fakeAi = "canonical-fake-ai"
75-
76-
expect(checkExistKey({ apiProvider: identifiers.fakeAi } as ProviderSettings)).toBe(true)
77-
} finally {
78-
identifiers.fakeAi = originalIdentifier
79-
}
70+
expect(checkExistKey({ apiProvider: providerIdentifiers.fakeAi })).toBe(true)
8071
})
8172

8273
it("should return true for openai-codex provider without API key", () => {
@@ -109,18 +100,7 @@ describe("checkExistKey", () => {
109100
})
110101

111102
it("recognizes OAuth authentication through the canonical Kimi Code identifier", () => {
112-
const identifiers = providerIdentifiers as Record<string, string>
113-
const originalIdentifier = identifiers.kimiCode!
114-
115-
try {
116-
identifiers.kimiCode = "canonical-kimi-code"
117-
118-
expect(
119-
checkExistKey({ apiProvider: identifiers.kimiCode, kimiCodeAuthMethod: "oauth" } as ProviderSettings),
120-
).toBe(true)
121-
} finally {
122-
identifiers.kimiCode = originalIdentifier
123-
}
103+
expect(checkExistKey({ apiProvider: providerIdentifiers.kimiCode, kimiCodeAuthMethod: "oauth" })).toBe(true)
124104
})
125105

126106
it("should return true for kimi-code provider without auth method (defaults to OAuth)", () => {
@@ -157,16 +137,7 @@ describe("checkExistKey", () => {
157137
})
158138

159139
it("recognizes session authentication through the canonical Zoo Gateway identifier", () => {
160-
const identifiers = providerIdentifiers as Record<string, string>
161-
const originalIdentifier = identifiers.zooGateway!
162-
163-
try {
164-
identifiers.zooGateway = "canonical-zoo-gateway"
165-
166-
expect(checkExistKey({ apiProvider: identifiers.zooGateway } as ProviderSettings, true)).toBe(true)
167-
} finally {
168-
identifiers.zooGateway = originalIdentifier
169-
}
140+
expect(checkExistKey({ apiProvider: providerIdentifiers.zooGateway }, true)).toBe(true)
170141
})
171142

172143
it("should return true for zoo-gateway when profile has zooSessionToken", () => {

0 commit comments

Comments
 (0)