Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/types/src/providers/anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const anthropicModels = {
supportsImages: true,
supportsPromptCache: true,
supportsNativeTools: true,
defaultToolProtocol: "native",
inputPrice: 3.0, // $3 per million input tokens (≤200K context)
outputPrice: 15.0, // $15 per million output tokens (≤200K context)
cacheWritesPrice: 3.75, // $3.75 per million tokens
Expand All @@ -34,6 +35,7 @@ export const anthropicModels = {
supportsImages: true,
supportsPromptCache: true,
supportsNativeTools: true,
defaultToolProtocol: "native",
inputPrice: 3.0, // $3 per million input tokens (≤200K context)
outputPrice: 15.0, // $15 per million output tokens (≤200K context)
cacheWritesPrice: 3.75, // $3.75 per million tokens
Expand All @@ -56,6 +58,7 @@ export const anthropicModels = {
supportsImages: true,
supportsPromptCache: true,
supportsNativeTools: true,
defaultToolProtocol: "native",
inputPrice: 5.0, // $5 per million input tokens
outputPrice: 25.0, // $25 per million output tokens
cacheWritesPrice: 6.25, // $6.25 per million tokens
Expand All @@ -68,6 +71,7 @@ export const anthropicModels = {
supportsImages: true,
supportsPromptCache: true,
supportsNativeTools: true,
defaultToolProtocol: "native",
inputPrice: 15.0, // $15 per million input tokens
outputPrice: 75.0, // $75 per million output tokens
cacheWritesPrice: 18.75, // $18.75 per million tokens
Expand All @@ -80,6 +84,7 @@ export const anthropicModels = {
supportsImages: true,
supportsPromptCache: true,
supportsNativeTools: true,
defaultToolProtocol: "native",
inputPrice: 15.0, // $15 per million input tokens
outputPrice: 75.0, // $75 per million output tokens
cacheWritesPrice: 18.75, // $18.75 per million tokens
Expand All @@ -92,6 +97,7 @@ export const anthropicModels = {
supportsImages: true,
supportsPromptCache: true,
supportsNativeTools: true,
defaultToolProtocol: "native",
inputPrice: 3.0, // $3 per million input tokens
outputPrice: 15.0, // $15 per million output tokens
cacheWritesPrice: 3.75, // $3.75 per million tokens
Expand All @@ -105,6 +111,7 @@ export const anthropicModels = {
supportsImages: true,
supportsPromptCache: true,
supportsNativeTools: true,
defaultToolProtocol: "native",
inputPrice: 3.0, // $3 per million input tokens
outputPrice: 15.0, // $15 per million output tokens
cacheWritesPrice: 3.75, // $3.75 per million tokens
Expand All @@ -116,6 +123,7 @@ export const anthropicModels = {
supportsImages: true,
supportsPromptCache: true,
supportsNativeTools: true,
defaultToolProtocol: "native",
inputPrice: 3.0, // $3 per million input tokens
outputPrice: 15.0, // $15 per million output tokens
cacheWritesPrice: 3.75, // $3.75 per million tokens
Expand All @@ -127,6 +135,7 @@ export const anthropicModels = {
supportsImages: false,
supportsPromptCache: true,
supportsNativeTools: true,
defaultToolProtocol: "native",
inputPrice: 1.0,
outputPrice: 5.0,
cacheWritesPrice: 1.25,
Expand All @@ -138,6 +147,7 @@ export const anthropicModels = {
supportsImages: true,
supportsPromptCache: true,
supportsNativeTools: true,
defaultToolProtocol: "native",
inputPrice: 15.0,
outputPrice: 75.0,
cacheWritesPrice: 18.75,
Expand All @@ -149,6 +159,7 @@ export const anthropicModels = {
supportsImages: true,
supportsPromptCache: true,
supportsNativeTools: true,
defaultToolProtocol: "native",
inputPrice: 0.25,
outputPrice: 1.25,
cacheWritesPrice: 0.3,
Expand All @@ -160,6 +171,7 @@ export const anthropicModels = {
supportsImages: true,
supportsPromptCache: true,
supportsNativeTools: true,
defaultToolProtocol: "native",
inputPrice: 1.0,
outputPrice: 5.0,
cacheWritesPrice: 1.25,
Expand Down
38 changes: 26 additions & 12 deletions src/api/providers/__tests__/anthropic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
import { AnthropicHandler } from "../anthropic"
import { ApiHandlerOptions } from "../../../shared/api"

// Mock TelemetryService
vitest.mock("@roo-code/telemetry", () => ({
TelemetryService: {
instance: {
captureException: vitest.fn(),
},
},
}))

const mockCreate = vitest.fn()

vitest.mock("@anthropic-ai/sdk", () => {
Expand Down Expand Up @@ -411,11 +420,11 @@ describe("AnthropicHandler", () => {
},
]

it("should include tools in request when toolProtocol is native", async () => {
it("should include tools in request by default (native is default)", async () => {
// Handler uses native protocol by default via model's defaultToolProtocol
const stream = handler.createMessage(systemPrompt, messages, {
taskId: "test-task",
tools: mockTools,
toolProtocol: "native",
})

// Consume the stream to trigger the API call
Expand Down Expand Up @@ -443,10 +452,15 @@ describe("AnthropicHandler", () => {
})

it("should not include tools when toolProtocol is xml", async () => {
const stream = handler.createMessage(systemPrompt, messages, {
// Create handler with xml tool protocol in options
const xmlHandler = new AnthropicHandler({
...mockOptions,
toolProtocol: "xml",
})

const stream = xmlHandler.createMessage(systemPrompt, messages, {
taskId: "test-task",
tools: mockTools,
toolProtocol: "xml",
})

// Consume the stream to trigger the API call
Expand All @@ -463,9 +477,9 @@ describe("AnthropicHandler", () => {
})

it("should not include tools when no tools are provided", async () => {
// Handler uses native protocol by default
const stream = handler.createMessage(systemPrompt, messages, {
taskId: "test-task",
toolProtocol: "native",
})

// Consume the stream to trigger the API call
Expand All @@ -482,10 +496,10 @@ describe("AnthropicHandler", () => {
})

it("should convert tool_choice 'auto' to Anthropic format", async () => {
// Handler uses native protocol by default
const stream = handler.createMessage(systemPrompt, messages, {
taskId: "test-task",
tools: mockTools,
toolProtocol: "native",
tool_choice: "auto",
})

Expand All @@ -503,10 +517,10 @@ describe("AnthropicHandler", () => {
})

it("should convert tool_choice 'required' to Anthropic 'any' format", async () => {
// Handler uses native protocol by default
const stream = handler.createMessage(systemPrompt, messages, {
taskId: "test-task",
tools: mockTools,
toolProtocol: "native",
tool_choice: "required",
})

Expand All @@ -524,10 +538,10 @@ describe("AnthropicHandler", () => {
})

it("should omit both tools and tool_choice when tool_choice is 'none'", async () => {
// Handler uses native protocol by default
const stream = handler.createMessage(systemPrompt, messages, {
taskId: "test-task",
tools: mockTools,
toolProtocol: "native",
tool_choice: "none",
})

Expand All @@ -552,10 +566,10 @@ describe("AnthropicHandler", () => {
})

it("should convert specific tool_choice to Anthropic 'tool' format", async () => {
// Handler uses native protocol by default
const stream = handler.createMessage(systemPrompt, messages, {
taskId: "test-task",
tools: mockTools,
toolProtocol: "native",
tool_choice: { type: "function" as const, function: { name: "get_weather" } },
})

Expand All @@ -573,10 +587,10 @@ describe("AnthropicHandler", () => {
})

it("should enable parallel tool calls when parallelToolCalls is true", async () => {
// Handler uses native protocol by default
const stream = handler.createMessage(systemPrompt, messages, {
taskId: "test-task",
tools: mockTools,
toolProtocol: "native",
tool_choice: "auto",
parallelToolCalls: true,
})
Expand Down Expand Up @@ -618,10 +632,10 @@ describe("AnthropicHandler", () => {
},
}))

// Handler uses native protocol by default
const stream = handler.createMessage(systemPrompt, messages, {
taskId: "test-task",
tools: mockTools,
toolProtocol: "native",
})

const chunks: any[] = []
Expand Down Expand Up @@ -685,10 +699,10 @@ describe("AnthropicHandler", () => {
},
}))

// Handler uses native protocol by default
const stream = handler.createMessage(systemPrompt, messages, {
taskId: "test-task",
tools: mockTools,
toolProtocol: "native",
})

const chunks: any[] = []
Expand Down
Loading
Loading