This repository was archived by the owner on May 15, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathbuild-tools.ts
More file actions
95 lines (78 loc) · 2.89 KB
/
Copy pathbuild-tools.ts
File metadata and controls
95 lines (78 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import path from "path"
import type OpenAI from "openai"
import type { ProviderSettings, ModeConfig, ModelInfo } from "@roo-code/types"
import { customToolRegistry, formatNative } from "@roo-code/core"
import type { ClineProvider } from "../webview/ClineProvider"
import { getNativeTools, getMcpServerTools } from "../prompts/tools/native-tools"
import { filterNativeToolsForMode, filterMcpToolsForMode } from "../prompts/tools/filter-tools-for-mode"
interface BuildToolsOptions {
provider: ClineProvider
cwd: string
mode: string | undefined
customModes: ModeConfig[] | undefined
experiments: Record<string, boolean> | undefined
apiConfiguration: ProviderSettings | undefined
maxReadFileLine: number
browserToolEnabled: boolean
modelInfo?: ModelInfo
diffEnabled: boolean
}
/**
* Builds the complete tools array for native protocol requests.
* Combines native tools and MCP tools, filtered by mode restrictions.
*
* @param options - Configuration options for building the tools
* @returns Array of filtered native and MCP tools
*/
export async function buildNativeToolsArray(options: BuildToolsOptions): Promise<OpenAI.Chat.ChatCompletionTool[]> {
const {
provider,
cwd,
mode,
customModes,
experiments,
apiConfiguration,
maxReadFileLine,
browserToolEnabled,
modelInfo,
diffEnabled,
} = options
const mcpHub = provider.getMcpHub()
// Get CodeIndexManager for feature checking.
const { CodeIndexManager } = await import("../../services/code-index/manager")
const codeIndexManager = CodeIndexManager.getInstance(provider.context, cwd)
// Build settings object for tool filtering.
const filterSettings = {
todoListEnabled: apiConfiguration?.todoListEnabled ?? true,
browserToolEnabled: browserToolEnabled ?? true,
modelInfo,
diffEnabled,
}
// Determine if partial reads are enabled based on maxReadFileLine setting.
const partialReadsEnabled = maxReadFileLine !== -1
// Build native tools with dynamic read_file tool based on partialReadsEnabled.
const nativeTools = getNativeTools(partialReadsEnabled)
// Filter native tools based on mode restrictions.
const filteredNativeTools = filterNativeToolsForMode(
nativeTools,
mode,
customModes,
experiments,
codeIndexManager,
filterSettings,
mcpHub,
)
// Filter MCP tools based on mode restrictions.
const mcpTools = getMcpServerTools(mcpHub)
const filteredMcpTools = filterMcpToolsForMode(mcpTools, mode, customModes, experiments)
// Add custom tools if they are available and the experiment is enabled.
let nativeCustomTools: OpenAI.Chat.ChatCompletionFunctionTool[] = []
if (experiments?.customTools) {
await customToolRegistry.loadFromDirectoryIfStale(path.join(cwd, ".roo", "tools"))
const customTools = customToolRegistry.getAllSerialized()
if (customTools.length > 0) {
nativeCustomTools = customTools.map(formatNative)
}
}
return [...filteredNativeTools, ...filteredMcpTools, ...nativeCustomTools]
}