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

Commit 660365e

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 3970acf commit 660365e

4 files changed

Lines changed: 29 additions & 27 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: 4 additions & 3 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

@@ -64,8 +64,9 @@ export abstract class RouterProvider extends BaseProvider {
6464
const id = this.modelId ?? this.defaultModelId
6565

6666
// First check instance models (populated by fetchModel)
67+
// Merge native tool defaults for cached models that may lack these fields
6768
if (this.models[id]) {
68-
return { id, info: this.models[id] }
69+
return { id, info: { ...NATIVE_TOOL_DEFAULTS, ...this.models[id] } }
6970
}
7071

7172
// Fall back to global cache (synchronous disk/memory cache)
@@ -74,7 +75,7 @@ export abstract class RouterProvider extends BaseProvider {
7475
if (cachedModels?.[id]) {
7576
// Also populate instance models for future calls
7677
this.models = cachedModels
77-
return { id, info: cachedModels[id] }
78+
return { id, info: { ...NATIVE_TOOL_DEFAULTS, ...cachedModels[id] } }
7879
}
7980

8081
// Last resort: return default model

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

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

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

0 commit comments

Comments
 (0)