1- import { ToolName } from "@roo-code/types"
1+ import { ModelInfo , shouldUseSingleFileRead , ToolName } from "@roo-code/types"
22import { CodeIndexManager } from "../../../../services/code-index/manager"
33import { Mode , getModeConfig , isToolAllowedForMode , getGroupName } from "../../../../shared/modes"
44import { ClineProviderState } from "../../../webview/ClineProvider"
@@ -7,13 +7,14 @@ import { ALWAYS_AVAILABLE_TOOLS, TOOL_GROUPS } from "../../../../shared/tools"
77import { isFastApplyAvailable } from "../../../tools/editFileTool"
88import { nativeTools } from "."
99import { apply_diff_multi_file , apply_diff_single_file } from "./apply_diff"
10+ import { read_file_multi , read_file_single } from "./read_file"
1011
1112export function getAllowedJSONToolsForMode (
1213 mode : Mode ,
1314 codeIndexManager : CodeIndexManager | undefined ,
1415 clineProviderState : ClineProviderState | undefined ,
1516 diffEnabled : boolean ,
16- supportsImages : boolean ,
17+ model : { id : string ; info : ModelInfo } | undefined ,
1718) : OpenAI . Chat . ChatCompletionTool [ ] {
1819 const config = getModeConfig ( mode , clineProviderState ?. customModes )
1920
@@ -75,28 +76,39 @@ export function getAllowedJSONToolsForMode(
7576 tools . delete ( "run_slash_command" )
7677 }
7778
78- if ( ! clineProviderState ?. browserToolEnabled || ! supportsImages ) {
79+ if ( ! clineProviderState ?. browserToolEnabled || ! model ?. info . supportsImages ) {
7980 tools . delete ( "browser_action" )
8081 }
8182
8283 // Create a map of tool names to native tool definitions for quick lookup
8384 // Exclude apply_diff tools as they are handled specially below
8485 const allowedTools : OpenAI . Chat . ChatCompletionTool [ ] = [ ]
8586
87+ let isReadFileToolAllowedForMode = false
8688 let isApplyDiffToolAllowedForMode = false
8789 for ( const nativeTool of nativeTools ) {
8890 const toolName = nativeTool . function . name
8991
9092 // If the tool is in the allowed set, add it.
9193 if ( tools . has ( toolName ) ) {
92- if ( toolName === "apply_diff" ) {
94+ if ( toolName === "read_file" ) {
95+ isReadFileToolAllowedForMode = true
96+ } else if ( toolName === "apply_diff" ) {
9397 isApplyDiffToolAllowedForMode = true
9498 } else {
9599 allowedTools . push ( nativeTool )
96100 }
97101 }
98102 }
99103
104+ if ( isReadFileToolAllowedForMode ) {
105+ if ( model ?. id && shouldUseSingleFileRead ( model ?. id ) ) {
106+ allowedTools . push ( read_file_single )
107+ } else {
108+ allowedTools . push ( read_file_multi )
109+ }
110+ }
111+
100112 // Handle the "apply_diff" logic separately because the same tool has different
101113 // implementations depending on whether multi-file diffs are enabled, but the same name is used.
102114 if ( isApplyDiffToolAllowedForMode && diffEnabled ) {
0 commit comments