Skip to content

Commit cb29e9d

Browse files
authored
Remove ModelInfo objects from settings (#2939)
1 parent a354c01 commit cb29e9d

Some content is hidden

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

64 files changed

+1089
-1872
lines changed

.eslintrc.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
}
1616
],
1717
"@typescript-eslint/semi": "off",
18+
"no-unused-vars": "off",
19+
"@typescript-eslint/no-unused-vars": ["error", { "varsIgnorePattern": "^_", "argsIgnorePattern": "^_" }],
1820
"eqeqeq": "warn",
1921
"no-throw-literal": "warn",
2022
"semi": "off"

e2e/src/suite/index.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@ export async function run() {
2424
apiProvider: "openrouter" as const,
2525
openRouterApiKey: process.env.OPENROUTER_API_KEY!,
2626
openRouterModelId: "google/gemini-2.0-flash-001",
27-
openRouterModelInfo: {
28-
maxTokens: 8192,
29-
contextWindow: 1000000,
30-
supportsImages: true,
31-
supportsPromptCache: false,
32-
inputPrice: 0.1,
33-
outputPrice: 0.4,
34-
thinking: false,
35-
},
3627
})
3728

3829
await vscode.commands.executeCommand("roo-cline.SidebarProvider.focus")

e2e/src/suite/utils.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import * as vscode from "vscode"
2-
31
import type { RooCodeAPI } from "../../../src/exports/roo-code"
42

53
type WaitForOptions = {

evals/apps/web/src/app/runs/new/new-run.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ export function NewRun() {
9494
}
9595

9696
const openRouterModelId = openRouterModel.id
97-
const openRouterModelInfo = openRouterModel.modelInfo
98-
values.settings = { ...(values.settings || {}), openRouterModelId, openRouterModelInfo }
97+
values.settings = { ...(values.settings || {}), openRouterModelId }
9998
}
10099

101100
const { id } = await createRun(values)

evals/packages/types/src/roo-code.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,10 @@ export const providerSettingsSchema = z.object({
304304
anthropicUseAuthToken: z.boolean().optional(),
305305
// Glama
306306
glamaModelId: z.string().optional(),
307-
glamaModelInfo: modelInfoSchema.optional(),
308307
glamaApiKey: z.string().optional(),
309308
// OpenRouter
310309
openRouterApiKey: z.string().optional(),
311310
openRouterModelId: z.string().optional(),
312-
openRouterModelInfo: modelInfoSchema.optional(),
313311
openRouterBaseUrl: z.string().optional(),
314312
openRouterSpecificProvider: z.string().optional(),
315313
openRouterUseMiddleOutTransform: z.boolean().optional(),
@@ -371,11 +369,9 @@ export const providerSettingsSchema = z.object({
371369
// Unbound
372370
unboundApiKey: z.string().optional(),
373371
unboundModelId: z.string().optional(),
374-
unboundModelInfo: modelInfoSchema.optional(),
375372
// Requesty
376373
requestyApiKey: z.string().optional(),
377374
requestyModelId: z.string().optional(),
378-
requestyModelInfo: modelInfoSchema.optional(),
379375
// Claude 3.7 Sonnet Thinking
380376
modelMaxTokens: z.number().optional(), // Currently only used by Anthropic hybrid thinking models.
381377
modelMaxThinkingTokens: z.number().optional(), // Currently only used by Anthropic hybrid thinking models.
@@ -401,12 +397,10 @@ const providerSettingsRecord: ProviderSettingsRecord = {
401397
anthropicUseAuthToken: undefined,
402398
// Glama
403399
glamaModelId: undefined,
404-
glamaModelInfo: undefined,
405400
glamaApiKey: undefined,
406401
// OpenRouter
407402
openRouterApiKey: undefined,
408403
openRouterModelId: undefined,
409-
openRouterModelInfo: undefined,
410404
openRouterBaseUrl: undefined,
411405
openRouterSpecificProvider: undefined,
412406
openRouterUseMiddleOutTransform: undefined,
@@ -460,11 +454,9 @@ const providerSettingsRecord: ProviderSettingsRecord = {
460454
// Unbound
461455
unboundApiKey: undefined,
462456
unboundModelId: undefined,
463-
unboundModelInfo: undefined,
464457
// Requesty
465458
requestyApiKey: undefined,
466459
requestyModelId: undefined,
467-
requestyModelInfo: undefined,
468460
// Claude 3.7 Sonnet Thinking
469461
modelMaxTokens: undefined,
470462
modelMaxThinkingTokens: undefined,

src/__mocks__/McpHub.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ export class McpHub {
77
this.callTool = jest.fn()
88
}
99

10-
async toggleToolAlwaysAllow(serverName: string, toolName: string, shouldAllow: boolean): Promise<void> {
10+
async toggleToolAlwaysAllow(_serverName: string, _toolName: string, _shouldAllow: boolean): Promise<void> {
1111
return Promise.resolve()
1212
}
1313

14-
async callTool(serverName: string, toolName: string, toolArguments?: Record<string, unknown>): Promise<any> {
14+
async callTool(_serverName: string, _toolName: string, _toolArguments?: Record<string, unknown>): Promise<any> {
1515
return Promise.resolve({ result: "success" })
1616
}
1717
}

src/__tests__/migrateSettings.test.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ jest.mock("vscode")
1010
jest.mock("fs/promises")
1111
jest.mock("fs")
1212
jest.mock("../utils/fs")
13-
// We're testing the real migrateSettings function
1413

1514
describe("Settings Migration", () => {
1615
let mockContext: vscode.ExtensionContext
@@ -52,8 +51,6 @@ describe("Settings Migration", () => {
5251
})
5352

5453
it("should migrate custom modes file if old file exists and new file doesn't", async () => {
55-
const mockCustomModesContent = '{"customModes":[{"slug":"test-mode"}]}' as string
56-
5754
// Mock file existence checks
5855
;(fileExistsAtPath as jest.Mock).mockImplementation(async (path: string) => {
5956
if (path === mockSettingsDir) return true
@@ -69,8 +66,6 @@ describe("Settings Migration", () => {
6966
})
7067

7168
it("should migrate MCP settings file if old file exists and new file doesn't", async () => {
72-
const mockMcpSettingsContent = '{"mcpServers":{"test-server":{}}}' as string
73-
7469
// Mock file existence checks
7570
;(fileExistsAtPath as jest.Mock).mockImplementation(async (path: string) => {
7671
if (path === mockSettingsDir) return true

src/activate/registerCodeActions.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as vscode from "vscode"
33
import { ACTION_NAMES, COMMAND_IDS } from "../core/CodeActionProvider"
44
import { EditorUtils } from "../core/EditorUtils"
55
import { ClineProvider } from "../core/webview/ClineProvider"
6-
import { telemetryService } from "../services/telemetry/TelemetryService"
76

87
export const registerCodeActions = (context: vscode.ExtensionContext) => {
98
registerCodeActionPair(

src/activate/registerCommands.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import * as vscode from "vscode"
22
import delay from "delay"
33

44
import { ClineProvider } from "../core/webview/ClineProvider"
5+
import { ContextProxy } from "../core/config/ContextProxy"
6+
7+
import { registerHumanRelayCallback, unregisterHumanRelayCallback, handleHumanRelayResponse } from "./humanRelay"
8+
import { handleNewTask } from "./handleTask"
59

610
/**
711
* Helper to get the visible ClineProvider instance or log if not found.
@@ -15,9 +19,6 @@ export function getVisibleProviderOrLog(outputChannel: vscode.OutputChannel): Cl
1519
return visibleProvider
1620
}
1721

18-
import { registerHumanRelayCallback, unregisterHumanRelayCallback, handleHumanRelayResponse } from "./humanRelay"
19-
import { handleNewTask } from "./handleTask"
20-
2122
// Store panel references in both modes
2223
let sidebarPanel: vscode.WebviewView | undefined = undefined
2324
let tabPanel: vscode.WebviewPanel | undefined = undefined
@@ -53,7 +54,7 @@ export type RegisterCommandOptions = {
5354
}
5455

5556
export const registerCommands = (options: RegisterCommandOptions) => {
56-
const { context, outputChannel } = options
57+
const { context } = options
5758

5859
for (const [command, callback] of Object.entries(getCommandsMap(options))) {
5960
context.subscriptions.push(vscode.commands.registerCommand(command, callback))
@@ -142,7 +143,8 @@ export const openClineInNewTab = async ({ context, outputChannel }: Omit<Registe
142143
// deserialize cached webview, but since we use retainContextWhenHidden, we
143144
// don't need to use that event).
144145
// https://github.com/microsoft/vscode-extension-samples/blob/main/webview-sample/src/extension.ts
145-
const tabProvider = new ClineProvider(context, outputChannel, "editor")
146+
const contextProxy = await ContextProxy.getInstance(context)
147+
const tabProvider = new ClineProvider(context, outputChannel, "editor", contextProxy)
146148
const lastCol = Math.max(...vscode.window.visibleTextEditors.map((editor) => editor.viewColumn || 0))
147149

148150
// Check if there are any visible text editors, otherwise open a new group

src/api/providers/__tests__/glama.test.ts

Lines changed: 26 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// npx jest src/api/providers/__tests__/glama.test.ts
22

33
import { Anthropic } from "@anthropic-ai/sdk"
4-
import axios from "axios"
54

65
import { GlamaHandler } from "../glama"
76
import { ApiHandlerOptions } from "../../../shared/api"
@@ -20,31 +19,18 @@ jest.mock("openai", () => {
2019
const stream = {
2120
[Symbol.asyncIterator]: async function* () {
2221
yield {
23-
choices: [
24-
{
25-
delta: { content: "Test response" },
26-
index: 0,
27-
},
28-
],
22+
choices: [{ delta: { content: "Test response" }, index: 0 }],
2923
usage: null,
3024
}
3125
yield {
32-
choices: [
33-
{
34-
delta: {},
35-
index: 0,
36-
},
37-
],
38-
usage: {
39-
prompt_tokens: 10,
40-
completion_tokens: 5,
41-
total_tokens: 15,
42-
},
26+
choices: [{ delta: {}, index: 0 }],
27+
usage: { prompt_tokens: 10, completion_tokens: 5, total_tokens: 15 },
4328
}
4429
},
4530
}
4631

4732
const result = mockCreate(...args)
33+
4834
if (args[0].stream) {
4935
mockWithResponse.mockReturnValue(
5036
Promise.resolve({
@@ -59,6 +45,7 @@ jest.mock("openai", () => {
5945
)
6046
result.withResponse = mockWithResponse
6147
}
48+
6249
return result
6350
},
6451
},
@@ -73,10 +60,10 @@ describe("GlamaHandler", () => {
7360

7461
beforeEach(() => {
7562
mockOptions = {
76-
apiModelId: "anthropic/claude-3-7-sonnet",
77-
glamaModelId: "anthropic/claude-3-7-sonnet",
7863
glamaApiKey: "test-api-key",
64+
glamaModelId: "anthropic/claude-3-7-sonnet",
7965
}
66+
8067
handler = new GlamaHandler(mockOptions)
8168
mockCreate.mockClear()
8269
mockWithResponse.mockClear()
@@ -102,7 +89,7 @@ describe("GlamaHandler", () => {
10289
describe("constructor", () => {
10390
it("should initialize with provided options", () => {
10491
expect(handler).toBeInstanceOf(GlamaHandler)
105-
expect(handler.getModel().id).toBe(mockOptions.apiModelId)
92+
expect(handler.getModel().id).toBe(mockOptions.glamaModelId)
10693
})
10794
})
10895

@@ -116,40 +103,15 @@ describe("GlamaHandler", () => {
116103
]
117104

118105
it("should handle streaming responses", async () => {
119-
// Mock axios for token usage request
120-
const mockAxios = jest.spyOn(axios, "get").mockResolvedValueOnce({
121-
data: {
122-
tokenUsage: {
123-
promptTokens: 10,
124-
completionTokens: 5,
125-
cacheCreationInputTokens: 0,
126-
cacheReadInputTokens: 0,
127-
},
128-
totalCostUsd: "0.00",
129-
},
130-
})
131-
132106
const stream = handler.createMessage(systemPrompt, messages)
133107
const chunks: any[] = []
108+
134109
for await (const chunk of stream) {
135110
chunks.push(chunk)
136111
}
137112

138-
expect(chunks.length).toBe(2) // Text chunk and usage chunk
139-
expect(chunks[0]).toEqual({
140-
type: "text",
141-
text: "Test response",
142-
})
143-
expect(chunks[1]).toEqual({
144-
type: "usage",
145-
inputTokens: 10,
146-
outputTokens: 5,
147-
cacheWriteTokens: 0,
148-
cacheReadTokens: 0,
149-
totalCost: 0,
150-
})
151-
152-
mockAxios.mockRestore()
113+
expect(chunks.length).toBe(1)
114+
expect(chunks[0]).toEqual({ type: "text", text: "Test response" })
153115
})
154116

155117
it("should handle API errors", async () => {
@@ -178,7 +140,7 @@ describe("GlamaHandler", () => {
178140
expect(result).toBe("Test response")
179141
expect(mockCreate).toHaveBeenCalledWith(
180142
expect.objectContaining({
181-
model: mockOptions.apiModelId,
143+
model: mockOptions.glamaModelId,
182144
messages: [{ role: "user", content: "Test prompt" }],
183145
temperature: 0,
184146
max_tokens: 8192,
@@ -204,22 +166,16 @@ describe("GlamaHandler", () => {
204166
mockCreate.mockClear()
205167

206168
const nonAnthropicOptions = {
207-
apiModelId: "openai/gpt-4",
208-
glamaModelId: "openai/gpt-4",
209169
glamaApiKey: "test-key",
210-
glamaModelInfo: {
211-
maxTokens: 4096,
212-
contextWindow: 8192,
213-
supportsImages: true,
214-
supportsPromptCache: false,
215-
},
170+
glamaModelId: "openai/gpt-4o",
216171
}
172+
217173
const nonAnthropicHandler = new GlamaHandler(nonAnthropicOptions)
218174

219175
await nonAnthropicHandler.completePrompt("Test prompt")
220176
expect(mockCreate).toHaveBeenCalledWith(
221177
expect.objectContaining({
222-
model: "openai/gpt-4",
178+
model: "openai/gpt-4o",
223179
messages: [{ role: "user", content: "Test prompt" }],
224180
temperature: 0,
225181
}),
@@ -228,13 +184,20 @@ describe("GlamaHandler", () => {
228184
})
229185
})
230186

231-
describe("getModel", () => {
232-
it("should return model info", () => {
233-
const modelInfo = handler.getModel()
234-
expect(modelInfo.id).toBe(mockOptions.apiModelId)
187+
describe("fetchModel", () => {
188+
it("should return model info", async () => {
189+
const modelInfo = await handler.fetchModel()
190+
expect(modelInfo.id).toBe(mockOptions.glamaModelId)
235191
expect(modelInfo.info).toBeDefined()
236192
expect(modelInfo.info.maxTokens).toBe(8192)
237193
expect(modelInfo.info.contextWindow).toBe(200_000)
238194
})
195+
196+
it("should return default model when invalid model provided", async () => {
197+
const handlerWithInvalidModel = new GlamaHandler({ ...mockOptions, glamaModelId: "invalid/model" })
198+
const modelInfo = await handlerWithInvalidModel.fetchModel()
199+
expect(modelInfo.id).toBe("anthropic/claude-3-7-sonnet")
200+
expect(modelInfo.info).toBeDefined()
201+
})
239202
})
240203
})

0 commit comments

Comments
 (0)