Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

Commit 194bdac

Browse files
committed
refactor: extract NATIVE_TOOL_DEFAULTS to shared constant
- Add NATIVE_TOOL_DEFAULTS constant to @roo-code/types/tool.ts - Update RouterProvider.getModel() to merge defaults for all router providers (LiteLLM, Unbound) - Update RequestyHandler to use shared constant - Update useSelectedModel to use shared constant for requesty, unbound, litellm
1 parent 2fe5c51 commit 194bdac

4 files changed

Lines changed: 34 additions & 28 deletions

File tree

packages/types/src/tool.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ export const TOOL_PROTOCOL = {
7171
*/
7272
export type ToolProtocol = (typeof TOOL_PROTOCOL)[keyof typeof TOOL_PROTOCOL]
7373

74+
/**
75+
* Default model info properties for native tool support.
76+
* Used to merge with cached model info that may lack these fields.
77+
* Router providers (Requesty, Unbound, LiteLLM) assume all models support native tools.
78+
*/
79+
export const NATIVE_TOOL_DEFAULTS = {
80+
supportsNativeTools: true,
81+
defaultToolProtocol: TOOL_PROTOCOL.NATIVE,
82+
} as const
83+
7484
/**
7585
* Checks if the protocol is native (non-XML).
7686
*

src/api/providers/requesty.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { Anthropic } from "@anthropic-ai/sdk"
22
import OpenAI from "openai"
33

4-
import { type ModelInfo, requestyDefaultModelId, requestyDefaultModelInfo, TOOL_PROTOCOL } from "@roo-code/types"
4+
import {
5+
type ModelInfo,
6+
requestyDefaultModelId,
7+
requestyDefaultModelInfo,
8+
TOOL_PROTOCOL,
9+
NATIVE_TOOL_DEFAULTS,
10+
} from "@roo-code/types"
511

612
import type { ApiHandlerOptions, ModelRecord } from "../../shared/api"
713
import { resolveToolProtocol } from "../../utils/resolveToolProtocol"
@@ -83,11 +89,7 @@ export class RequestyHandler extends BaseProvider implements SingleCompletionHan
8389

8490
// Merge native tool defaults for cached models that may lack these fields
8591
// The order ensures that cached values (if present) override the defaults
86-
let info: ModelInfo = {
87-
supportsNativeTools: true,
88-
defaultToolProtocol: TOOL_PROTOCOL.NATIVE,
89-
...cachedInfo,
90-
}
92+
let info: ModelInfo = { ...NATIVE_TOOL_DEFAULTS, ...cachedInfo }
9193

9294
// Apply tool preferences for models accessed through routers (OpenAI, Gemini)
9395
info = applyRouterToolPreferences(id, info)

src/api/providers/router-provider.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import OpenAI from "openai"
22

3-
import type { ModelInfo } from "@roo-code/types"
3+
import { type ModelInfo, NATIVE_TOOL_DEFAULTS } from "@roo-code/types"
44

55
import { ApiHandlerOptions, RouterName, ModelRecord } from "../../shared/api"
66

@@ -62,10 +62,15 @@ export abstract class RouterProvider extends BaseProvider {
6262

6363
override getModel(): { id: string; info: ModelInfo } {
6464
const id = this.modelId ?? this.defaultModelId
65+
const cachedInfo = this.models[id]
6566

66-
return this.models[id]
67-
? { id, info: this.models[id] }
68-
: { id: this.defaultModelId, info: this.defaultModelInfo }
67+
if (cachedInfo) {
68+
// Merge native tool defaults for cached models that may lack these fields
69+
// The order ensures that cached values (if present) override the defaults
70+
return { id, info: { ...NATIVE_TOOL_DEFAULTS, ...cachedInfo } }
71+
}
72+
73+
return { id: this.defaultModelId, info: this.defaultModelInfo }
6974
}
7075

7176
protected supportsTemperature(modelId: string): boolean {

webview-ui/src/components/ui/hooks/useSelectedModel.ts

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
BEDROCK_1M_CONTEXT_MODEL_IDS,
3333
isDynamicProvider,
3434
getProviderDefaultModelId,
35+
NATIVE_TOOL_DEFAULTS,
3536
} from "@roo-code/types"
3637

3738
import type { ModelRecord, RouterModels } from "@roo/api"
@@ -157,34 +158,22 @@ function getSelectedModel({
157158
case "requesty": {
158159
const id = getValidatedModelId(apiConfiguration.requestyModelId, routerModels.requesty, defaultModelId)
159160
const routerInfo = routerModels.requesty?.[id]
160-
// Merge native tool call defaults for cached models that may lack these fields
161-
const nativeToolDefaults = {
162-
supportsNativeTools: true,
163-
defaultToolProtocol: "native" as const,
164-
}
165-
const info = routerInfo ? { ...nativeToolDefaults, ...routerInfo } : undefined
161+
// Merge native tool defaults for cached models that may lack these fields
162+
const info = routerInfo ? { ...NATIVE_TOOL_DEFAULTS, ...routerInfo } : undefined
166163
return { id, info }
167164
}
168165
case "unbound": {
169166
const id = getValidatedModelId(apiConfiguration.unboundModelId, routerModels.unbound, defaultModelId)
170167
const routerInfo = routerModels.unbound?.[id]
171-
// Merge native tool call defaults for cached models that may lack these fields
172-
const nativeToolDefaults = {
173-
supportsNativeTools: true,
174-
defaultToolProtocol: "native" as const,
175-
}
176-
const info = routerInfo ? { ...nativeToolDefaults, ...routerInfo } : undefined
168+
// Merge native tool defaults for cached models that may lack these fields
169+
const info = routerInfo ? { ...NATIVE_TOOL_DEFAULTS, ...routerInfo } : undefined
177170
return { id, info }
178171
}
179172
case "litellm": {
180173
const id = getValidatedModelId(apiConfiguration.litellmModelId, routerModels.litellm, defaultModelId)
181174
const routerInfo = routerModels.litellm?.[id]
182-
// Only merge native tool call defaults, not prices or other model-specific info
183-
const nativeToolDefaults = {
184-
supportsNativeTools: litellmDefaultModelInfo.supportsNativeTools,
185-
defaultToolProtocol: litellmDefaultModelInfo.defaultToolProtocol,
186-
}
187-
const info = routerInfo ? { ...nativeToolDefaults, ...routerInfo } : litellmDefaultModelInfo
175+
// Merge native tool defaults for cached models that may lack these fields
176+
const info = routerInfo ? { ...NATIVE_TOOL_DEFAULTS, ...routerInfo } : litellmDefaultModelInfo
188177
return { id, info }
189178
}
190179
case "xai": {

0 commit comments

Comments
 (0)