Skip to content

Commit ed3a077

Browse files
authored
Merge branch 'RooCodeInc:main' into main
2 parents be90907 + e78d954 commit ed3a077

File tree

59 files changed

+1135
-62
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1135
-62
lines changed

packages/cloud/src/auth/WebAuthService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ export class WebAuthService extends EventEmitter<AuthServiceEvents> implements A
494494
signal: AbortSignal.timeout(10000),
495495
})
496496

497-
if (response.status >= 400 && response.status < 500) {
497+
if (response.status === 401 || response.status === 404) {
498498
throw new InvalidClientTokenError()
499499
} else if (!response.ok) {
500500
throw new Error(`HTTP ${response.status}: ${response.statusText}`)

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

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ describe("getApiProtocol", () => {
1212
expect(getApiProtocol("claude-code")).toBe("anthropic")
1313
expect(getApiProtocol("claude-code", "some-model")).toBe("anthropic")
1414
})
15+
16+
it("should return 'anthropic' for bedrock provider", () => {
17+
expect(getApiProtocol("bedrock")).toBe("anthropic")
18+
expect(getApiProtocol("bedrock", "gpt-4")).toBe("anthropic")
19+
expect(getApiProtocol("bedrock", "claude-3-opus")).toBe("anthropic")
20+
})
1521
})
1622

1723
describe("Vertex provider with Claude models", () => {
@@ -27,25 +33,14 @@ describe("getApiProtocol", () => {
2733
expect(getApiProtocol("vertex", "gemini-pro")).toBe("openai")
2834
expect(getApiProtocol("vertex", "llama-2")).toBe("openai")
2935
})
30-
})
31-
32-
describe("Bedrock provider with Claude models", () => {
33-
it("should return 'anthropic' for bedrock provider with claude models", () => {
34-
expect(getApiProtocol("bedrock", "claude-3-opus")).toBe("anthropic")
35-
expect(getApiProtocol("bedrock", "Claude-3-Sonnet")).toBe("anthropic")
36-
expect(getApiProtocol("bedrock", "CLAUDE-instant")).toBe("anthropic")
37-
expect(getApiProtocol("bedrock", "anthropic.claude-v2")).toBe("anthropic")
38-
})
3936

40-
it("should return 'openai' for bedrock provider with non-claude models", () => {
41-
expect(getApiProtocol("bedrock", "gpt-4")).toBe("openai")
42-
expect(getApiProtocol("bedrock", "titan-text")).toBe("openai")
43-
expect(getApiProtocol("bedrock", "llama-2")).toBe("openai")
37+
it("should return 'openai' for vertex provider without model", () => {
38+
expect(getApiProtocol("vertex")).toBe("openai")
4439
})
4540
})
4641

47-
describe("Other providers with Claude models", () => {
48-
it("should return 'openai' for non-vertex/bedrock providers with claude models", () => {
42+
describe("Other providers", () => {
43+
it("should return 'openai' for non-anthropic providers regardless of model", () => {
4944
expect(getApiProtocol("openrouter", "claude-3-opus")).toBe("openai")
5045
expect(getApiProtocol("openai", "claude-3-sonnet")).toBe("openai")
5146
expect(getApiProtocol("litellm", "claude-instant")).toBe("openai")
@@ -59,20 +54,13 @@ describe("getApiProtocol", () => {
5954
expect(getApiProtocol(undefined, "claude-3-opus")).toBe("openai")
6055
})
6156

62-
it("should return 'openai' when model is undefined", () => {
63-
expect(getApiProtocol("openai")).toBe("openai")
64-
expect(getApiProtocol("vertex")).toBe("openai")
65-
expect(getApiProtocol("bedrock")).toBe("openai")
66-
})
67-
6857
it("should handle empty strings", () => {
6958
expect(getApiProtocol("vertex", "")).toBe("openai")
70-
expect(getApiProtocol("bedrock", "")).toBe("openai")
7159
})
7260

7361
it("should be case-insensitive for claude detection", () => {
7462
expect(getApiProtocol("vertex", "CLAUDE-3-OPUS")).toBe("anthropic")
75-
expect(getApiProtocol("bedrock", "claude-3-opus")).toBe("anthropic")
63+
expect(getApiProtocol("vertex", "claude-3-opus")).toBe("anthropic")
7664
expect(getApiProtocol("vertex", "ClAuDe-InStAnT")).toBe("anthropic")
7765
})
7866
})

packages/types/src/global-settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ export const SECRET_STATE_KEYS = [
159159
"geminiApiKey",
160160
"openAiNativeApiKey",
161161
"deepSeekApiKey",
162+
"moonshotApiKey",
162163
"mistralApiKey",
163164
"unboundApiKey",
164165
"requestyApiKey",

packages/types/src/provider-settings.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const providerNames = [
2222
"gemini-cli",
2323
"openai-native",
2424
"mistral",
25+
"moonshot",
2526
"deepseek",
2627
"unbound",
2728
"requesty",
@@ -61,6 +62,7 @@ export const DEFAULT_CONSECUTIVE_MISTAKE_LIMIT = 3
6162
const baseProviderSettingsSchema = z.object({
6263
includeMaxTokens: z.boolean().optional(),
6364
diffEnabled: z.boolean().optional(),
65+
todoListEnabled: z.boolean().optional(),
6466
fuzzyMatchThreshold: z.number().optional(),
6567
modelTemperature: z.number().nullish(),
6668
rateLimitSeconds: z.number().optional(),
@@ -186,6 +188,13 @@ const deepSeekSchema = apiModelIdProviderModelSchema.extend({
186188
deepSeekApiKey: z.string().optional(),
187189
})
188190

191+
const moonshotSchema = apiModelIdProviderModelSchema.extend({
192+
moonshotBaseUrl: z
193+
.union([z.literal("https://api.moonshot.ai/v1"), z.literal("https://api.moonshot.cn/v1")])
194+
.optional(),
195+
moonshotApiKey: z.string().optional(),
196+
})
197+
189198
const unboundSchema = baseProviderSettingsSchema.extend({
190199
unboundApiKey: z.string().optional(),
191200
unboundModelId: z.string().optional(),
@@ -240,6 +249,7 @@ export const providerSettingsSchemaDiscriminated = z.discriminatedUnion("apiProv
240249
openAiNativeSchema.merge(z.object({ apiProvider: z.literal("openai-native") })),
241250
mistralSchema.merge(z.object({ apiProvider: z.literal("mistral") })),
242251
deepSeekSchema.merge(z.object({ apiProvider: z.literal("deepseek") })),
252+
moonshotSchema.merge(z.object({ apiProvider: z.literal("moonshot") })),
243253
unboundSchema.merge(z.object({ apiProvider: z.literal("unbound") })),
244254
requestySchema.merge(z.object({ apiProvider: z.literal("requesty") })),
245255
humanRelaySchema.merge(z.object({ apiProvider: z.literal("human-relay") })),
@@ -268,6 +278,7 @@ export const providerSettingsSchema = z.object({
268278
...openAiNativeSchema.shape,
269279
...mistralSchema.shape,
270280
...deepSeekSchema.shape,
281+
...moonshotSchema.shape,
271282
...unboundSchema.shape,
272283
...requestySchema.shape,
273284
...humanRelaySchema.shape,
@@ -301,7 +312,7 @@ export const getModelId = (settings: ProviderSettings): string | undefined => {
301312
}
302313

303314
// Providers that use Anthropic-style API protocol
304-
export const ANTHROPIC_STYLE_PROVIDERS: ProviderName[] = ["anthropic", "claude-code"]
315+
export const ANTHROPIC_STYLE_PROVIDERS: ProviderName[] = ["anthropic", "claude-code", "bedrock"]
305316

306317
// Helper function to determine API protocol for a provider and model
307318
export const getApiProtocol = (provider: ProviderName | undefined, modelId?: string): "anthropic" | "openai" => {
@@ -310,13 +321,8 @@ export const getApiProtocol = (provider: ProviderName | undefined, modelId?: str
310321
return "anthropic"
311322
}
312323

313-
// For vertex and bedrock providers, check if the model ID contains "claude" (case-insensitive)
314-
if (
315-
provider &&
316-
(provider === "vertex" || provider === "bedrock") &&
317-
modelId &&
318-
modelId.toLowerCase().includes("claude")
319-
) {
324+
// For vertex provider, check if the model ID contains "claude" (case-insensitive)
325+
if (provider && provider === "vertex" && modelId && modelId.toLowerCase().includes("claude")) {
320326
return "anthropic"
321327
}
322328

packages/types/src/providers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export * from "./groq.js"
99
export * from "./lite-llm.js"
1010
export * from "./lm-studio.js"
1111
export * from "./mistral.js"
12+
export * from "./moonshot.js"
1213
export * from "./ollama.js"
1314
export * from "./openai.js"
1415
export * from "./openrouter.js"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { ModelInfo } from "../model.js"
2+
3+
// https://platform.moonshot.ai/
4+
export type MoonshotModelId = keyof typeof moonshotModels
5+
6+
export const moonshotDefaultModelId: MoonshotModelId = "kimi-k2-0711-preview"
7+
8+
export const moonshotModels = {
9+
"kimi-k2-0711-preview": {
10+
maxTokens: 32_000,
11+
contextWindow: 131_072,
12+
supportsImages: false,
13+
supportsPromptCache: true,
14+
inputPrice: 0.6, // $0.60 per million tokens (cache miss)
15+
outputPrice: 2.5, // $2.50 per million tokens
16+
cacheWritesPrice: 0, // $0 per million tokens (cache miss)
17+
cacheReadsPrice: 0.15, // $0.15 per million tokens (cache hit)
18+
description: `Kimi K2 is a state-of-the-art mixture-of-experts (MoE) language model with 32 billion activated parameters and 1 trillion total parameters.`,
19+
},
20+
} as const satisfies Record<string, ModelInfo>
21+
22+
export const MOONSHOT_DEFAULT_TEMPERATURE = 0.6

src/api/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
GeminiHandler,
1818
OpenAiNativeHandler,
1919
DeepSeekHandler,
20+
MoonshotHandler,
2021
MistralHandler,
2122
VsCodeLmHandler,
2223
UnboundHandler,
@@ -89,6 +90,8 @@ export function buildApiHandler(configuration: ProviderSettings): ApiHandler {
8990
return new OpenAiNativeHandler(options)
9091
case "deepseek":
9192
return new DeepSeekHandler(options)
93+
case "moonshot":
94+
return new MoonshotHandler(options)
9295
case "vscode-lm":
9396
return new VsCodeLmHandler(options)
9497
case "mistral":
@@ -110,6 +113,7 @@ export function buildApiHandler(configuration: ProviderSettings): ApiHandler {
110113
case "litellm":
111114
return new LiteLLMHandler(options)
112115
default:
116+
apiProvider satisfies "gemini-cli" | undefined
113117
return new AnthropicHandler(options)
114118
}
115119
}

0 commit comments

Comments
 (0)