fix: recognize google-vertex-anthropic as Claude provider (#1700)
This commit is contained in:
@@ -7,7 +7,7 @@ function normalizeModelID(modelID: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isClaudeProvider(providerID: string, modelID: string): boolean {
|
function isClaudeProvider(providerID: string, modelID: string): boolean {
|
||||||
if (["anthropic", "opencode"].includes(providerID)) return true
|
if (["anthropic", "google-vertex-anthropic", "opencode"].includes(providerID)) return true
|
||||||
if (providerID === "github-copilot" && modelID.toLowerCase().includes("claude")) return true
|
if (providerID === "github-copilot" && modelID.toLowerCase().includes("claude")) return true
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,6 +88,21 @@ describe("createAnthropicEffortHook", () => {
|
|||||||
expect(output.options.effort).toBe("max")
|
expect(output.options.effort).toBe("max")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should inject effort max for google-vertex-anthropic provider", async () => {
|
||||||
|
//#given google-vertex-anthropic provider with claude-opus-4-6
|
||||||
|
const hook = createAnthropicEffortHook()
|
||||||
|
const { input, output } = createMockParams({
|
||||||
|
providerID: "google-vertex-anthropic",
|
||||||
|
modelID: "claude-opus-4-6",
|
||||||
|
})
|
||||||
|
|
||||||
|
//#when chat.params hook is called
|
||||||
|
await hook["chat.params"](input, output)
|
||||||
|
|
||||||
|
//#then effort should be injected
|
||||||
|
expect(output.options.effort).toBe("max")
|
||||||
|
})
|
||||||
|
|
||||||
it("should handle normalized model ID with dots (opus-4.6)", async () => {
|
it("should handle normalized model ID with dots (opus-4.6)", async () => {
|
||||||
//#given model ID with dots instead of hyphens
|
//#given model ID with dots instead of hyphens
|
||||||
const hook = createAnthropicEffortHook()
|
const hook = createAnthropicEffortHook()
|
||||||
|
|||||||
@@ -113,6 +113,42 @@ describe("context-window-monitor", () => {
|
|||||||
expect(ctx.client.session.messages).not.toHaveBeenCalled()
|
expect(ctx.client.session.messages).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should append context reminder for google-vertex-anthropic provider", async () => {
|
||||||
|
//#given cached usage for google-vertex-anthropic above threshold
|
||||||
|
const hook = createContextWindowMonitorHook(ctx as never)
|
||||||
|
const sessionID = "ses_vertex_anthropic_high_usage"
|
||||||
|
|
||||||
|
await hook.event({
|
||||||
|
event: {
|
||||||
|
type: "message.updated",
|
||||||
|
properties: {
|
||||||
|
info: {
|
||||||
|
role: "assistant",
|
||||||
|
sessionID,
|
||||||
|
providerID: "google-vertex-anthropic",
|
||||||
|
finish: true,
|
||||||
|
tokens: {
|
||||||
|
input: 150000,
|
||||||
|
output: 1000,
|
||||||
|
reasoning: 0,
|
||||||
|
cache: { read: 10000, write: 0 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
//#when tool.execute.after runs
|
||||||
|
const output = { title: "", output: "original", metadata: null }
|
||||||
|
await hook["tool.execute.after"](
|
||||||
|
{ tool: "bash", sessionID, callID: "call_1" },
|
||||||
|
output
|
||||||
|
)
|
||||||
|
|
||||||
|
//#then context reminder should be appended
|
||||||
|
expect(output.output).toContain("context remaining")
|
||||||
|
})
|
||||||
|
|
||||||
// #given session is deleted
|
// #given session is deleted
|
||||||
// #when session.deleted event fires
|
// #when session.deleted event fires
|
||||||
// #then cached data should be cleaned up
|
// #then cached data should be cleaned up
|
||||||
|
|||||||
@@ -27,6 +27,10 @@ interface CachedTokenState {
|
|||||||
tokens: TokenInfo
|
tokens: TokenInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isAnthropicProvider(providerID: string): boolean {
|
||||||
|
return providerID === "anthropic" || providerID === "google-vertex-anthropic"
|
||||||
|
}
|
||||||
|
|
||||||
export function createContextWindowMonitorHook(_ctx: PluginInput) {
|
export function createContextWindowMonitorHook(_ctx: PluginInput) {
|
||||||
const remindedSessions = new Set<string>()
|
const remindedSessions = new Set<string>()
|
||||||
const tokenCache = new Map<string, CachedTokenState>()
|
const tokenCache = new Map<string, CachedTokenState>()
|
||||||
@@ -42,7 +46,7 @@ export function createContextWindowMonitorHook(_ctx: PluginInput) {
|
|||||||
const cached = tokenCache.get(sessionID)
|
const cached = tokenCache.get(sessionID)
|
||||||
if (!cached) return
|
if (!cached) return
|
||||||
|
|
||||||
if (cached.providerID !== "anthropic") return
|
if (!isAnthropicProvider(cached.providerID)) return
|
||||||
|
|
||||||
const lastTokens = cached.tokens
|
const lastTokens = cached.tokens
|
||||||
const totalInputTokens = (lastTokens?.input ?? 0) + (lastTokens?.cache?.read ?? 0)
|
const totalInputTokens = (lastTokens?.input ?? 0) + (lastTokens?.cache?.read ?? 0)
|
||||||
|
|||||||
@@ -123,6 +123,43 @@ describe("preemptive-compaction", () => {
|
|||||||
expect(ctx.client.session.summarize).toHaveBeenCalled()
|
expect(ctx.client.session.summarize).toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should trigger compaction for google-vertex-anthropic provider", async () => {
|
||||||
|
//#given google-vertex-anthropic usage above threshold
|
||||||
|
const hook = createPreemptiveCompactionHook(ctx as never)
|
||||||
|
const sessionID = "ses_vertex_anthropic_high"
|
||||||
|
|
||||||
|
await hook.event({
|
||||||
|
event: {
|
||||||
|
type: "message.updated",
|
||||||
|
properties: {
|
||||||
|
info: {
|
||||||
|
role: "assistant",
|
||||||
|
sessionID,
|
||||||
|
providerID: "google-vertex-anthropic",
|
||||||
|
modelID: "claude-sonnet-4-5",
|
||||||
|
finish: true,
|
||||||
|
tokens: {
|
||||||
|
input: 170000,
|
||||||
|
output: 1000,
|
||||||
|
reasoning: 0,
|
||||||
|
cache: { read: 10000, write: 0 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
//#when tool.execute.after runs
|
||||||
|
const output = { title: "", output: "test", metadata: null }
|
||||||
|
await hook["tool.execute.after"](
|
||||||
|
{ tool: "bash", sessionID, callID: "call_1" },
|
||||||
|
output
|
||||||
|
)
|
||||||
|
|
||||||
|
//#then summarize should be triggered
|
||||||
|
expect(ctx.client.session.summarize).toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
|
||||||
// #given session deleted
|
// #given session deleted
|
||||||
// #then cache should be cleaned up
|
// #then cache should be cleaned up
|
||||||
it("should clean up cache on session.deleted", async () => {
|
it("should clean up cache on session.deleted", async () => {
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ interface CachedCompactionState {
|
|||||||
tokens: TokenInfo
|
tokens: TokenInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isAnthropicProvider(providerID: string): boolean {
|
||||||
|
return providerID === "anthropic" || providerID === "google-vertex-anthropic"
|
||||||
|
}
|
||||||
|
|
||||||
type PluginInput = {
|
type PluginInput = {
|
||||||
client: {
|
client: {
|
||||||
session: {
|
session: {
|
||||||
@@ -55,7 +59,7 @@ export function createPreemptiveCompactionHook(ctx: PluginInput) {
|
|||||||
if (!cached) return
|
if (!cached) return
|
||||||
|
|
||||||
const actualLimit =
|
const actualLimit =
|
||||||
cached.providerID === "anthropic"
|
isAnthropicProvider(cached.providerID)
|
||||||
? ANTHROPIC_ACTUAL_LIMIT
|
? ANTHROPIC_ACTUAL_LIMIT
|
||||||
: DEFAULT_ACTUAL_LIMIT
|
: DEFAULT_ACTUAL_LIMIT
|
||||||
|
|
||||||
|
|||||||
@@ -214,6 +214,27 @@ describe("createThinkModeHook integration", () => {
|
|||||||
expect(message.thinking).toBeDefined()
|
expect(message.thinking).toBeDefined()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should work for direct google-vertex-anthropic provider", async () => {
|
||||||
|
//#given direct google-vertex-anthropic provider
|
||||||
|
const hook = createThinkModeHook()
|
||||||
|
const input = createMockInput(
|
||||||
|
"google-vertex-anthropic",
|
||||||
|
"claude-opus-4-6",
|
||||||
|
"think deeply"
|
||||||
|
)
|
||||||
|
|
||||||
|
//#when the chat.params hook is called
|
||||||
|
await hook["chat.params"](input, sessionID)
|
||||||
|
|
||||||
|
//#then should upgrade model and inject Claude thinking config
|
||||||
|
const message = input.message as MessageWithInjectedProps
|
||||||
|
expect(input.message.model?.modelID).toBe("claude-opus-4-6-high")
|
||||||
|
expect(message.thinking).toBeDefined()
|
||||||
|
expect((message.thinking as Record<string, unknown>)?.budgetTokens).toBe(
|
||||||
|
64000
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
it("should still work for direct google provider", async () => {
|
it("should still work for direct google provider", async () => {
|
||||||
// given direct google provider
|
// given direct google provider
|
||||||
const hook = createThinkModeHook()
|
const hook = createThinkModeHook()
|
||||||
|
|||||||
@@ -266,6 +266,24 @@ describe("think-mode switcher", () => {
|
|||||||
expect((config?.thinking as Record<string, unknown>)?.type).toBe("enabled")
|
expect((config?.thinking as Record<string, unknown>)?.type).toBe("enabled")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should work for direct google-vertex-anthropic provider", () => {
|
||||||
|
//#given direct google-vertex-anthropic provider
|
||||||
|
const config = getThinkingConfig(
|
||||||
|
"google-vertex-anthropic",
|
||||||
|
"claude-opus-4-6"
|
||||||
|
)
|
||||||
|
|
||||||
|
//#when thinking config is resolved
|
||||||
|
|
||||||
|
//#then it should return anthropic-style thinking config
|
||||||
|
expect(config).not.toBeNull()
|
||||||
|
expect(config?.thinking).toBeDefined()
|
||||||
|
expect((config?.thinking as Record<string, unknown>)?.type).toBe("enabled")
|
||||||
|
expect((config?.thinking as Record<string, unknown>)?.budgetTokens).toBe(
|
||||||
|
64000
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
it("should still work for direct google provider", () => {
|
it("should still work for direct google provider", () => {
|
||||||
// given direct google provider
|
// given direct google provider
|
||||||
const config = getThinkingConfig("google", "gemini-3-pro")
|
const config = getThinkingConfig("google", "gemini-3-pro")
|
||||||
@@ -314,6 +332,17 @@ describe("think-mode switcher", () => {
|
|||||||
expect(config.maxTokens).toBe(128000)
|
expect(config.maxTokens).toBe(128000)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should have correct structure for google-vertex-anthropic", () => {
|
||||||
|
//#given google-vertex-anthropic config entry
|
||||||
|
const config = THINKING_CONFIGS["google-vertex-anthropic"]
|
||||||
|
|
||||||
|
//#when structure is validated
|
||||||
|
|
||||||
|
//#then it should match anthropic style structure
|
||||||
|
expect(config.thinking).toBeDefined()
|
||||||
|
expect(config.maxTokens).toBe(128000)
|
||||||
|
})
|
||||||
|
|
||||||
it("should have correct structure for google", () => {
|
it("should have correct structure for google", () => {
|
||||||
const config = THINKING_CONFIGS.google
|
const config = THINKING_CONFIGS.google
|
||||||
expect(config.providerOptions).toBeDefined()
|
expect(config.providerOptions).toBeDefined()
|
||||||
|
|||||||
@@ -121,6 +121,13 @@ export const THINKING_CONFIGS = {
|
|||||||
},
|
},
|
||||||
maxTokens: 128000,
|
maxTokens: 128000,
|
||||||
},
|
},
|
||||||
|
"google-vertex-anthropic": {
|
||||||
|
thinking: {
|
||||||
|
type: "enabled",
|
||||||
|
budgetTokens: 64000,
|
||||||
|
},
|
||||||
|
maxTokens: 128000,
|
||||||
|
},
|
||||||
"amazon-bedrock": {
|
"amazon-bedrock": {
|
||||||
reasoningConfig: {
|
reasoningConfig: {
|
||||||
type: "enabled",
|
type: "enabled",
|
||||||
@@ -164,6 +171,7 @@ export const THINKING_CONFIGS = {
|
|||||||
|
|
||||||
const THINKING_CAPABLE_MODELS = {
|
const THINKING_CAPABLE_MODELS = {
|
||||||
anthropic: ["claude-sonnet-4", "claude-opus-4", "claude-3"],
|
anthropic: ["claude-sonnet-4", "claude-opus-4", "claude-3"],
|
||||||
|
"google-vertex-anthropic": ["claude-sonnet-4", "claude-opus-4", "claude-3"],
|
||||||
"amazon-bedrock": ["claude", "anthropic"],
|
"amazon-bedrock": ["claude", "anthropic"],
|
||||||
google: ["gemini-2", "gemini-3"],
|
google: ["gemini-2", "gemini-3"],
|
||||||
"google-vertex": ["gemini-2", "gemini-3"],
|
"google-vertex": ["gemini-2", "gemini-3"],
|
||||||
|
|||||||
Reference in New Issue
Block a user