|
1 | 1 | import path from "path" |
2 | 2 | import { isBinaryFile } from "isbinaryfile" |
3 | 3 | import type { FileEntry, LineRange } from "@roo-code/types" |
4 | | -import { isNativeProtocol } from "@roo-code/types" |
| 4 | +import { isNativeProtocol, ANTHROPIC_DEFAULT_MAX_TOKENS } from "@roo-code/types" |
5 | 5 |
|
6 | 6 | import { Task } from "../task/Task" |
7 | 7 | import { ClineSayTool } from "../../shared/ExtensionMessage" |
8 | 8 | import { formatResponse } from "../prompts/responses" |
| 9 | +import { getModelMaxOutputTokens } from "../../shared/api" |
9 | 10 | import { t } from "../../i18n" |
10 | 11 | import { RecordSource } from "../context-tracking/FileContextTrackerTypes" |
11 | 12 | import { isPathOutsideWorkspace } from "../../utils/pathUtils" |
@@ -480,11 +481,22 @@ export class ReadFileTool extends BaseTool<"read_file"> { |
480 | 481 | continue |
481 | 482 | } |
482 | 483 |
|
483 | | - const modelInfo = task.api.getModel().info |
| 484 | + const { id: modelId, info: modelInfo } = task.api.getModel() |
484 | 485 | const { contextTokens } = task.getTokenUsage() |
485 | 486 | const contextWindow = modelInfo.contextWindow |
486 | 487 |
|
487 | | - const budgetResult = await validateFileTokenBudget(fullPath, contextWindow, contextTokens || 0) |
| 488 | + const maxOutputTokens = |
| 489 | + getModelMaxOutputTokens({ |
| 490 | + modelId, |
| 491 | + model: modelInfo, |
| 492 | + settings: task.apiConfiguration, |
| 493 | + }) ?? ANTHROPIC_DEFAULT_MAX_TOKENS |
| 494 | + |
| 495 | + const budgetResult = await validateFileTokenBudget( |
| 496 | + fullPath, |
| 497 | + contextWindow - maxOutputTokens, |
| 498 | + contextTokens || 0, |
| 499 | + ) |
488 | 500 |
|
489 | 501 | let content = await extractTextFromFile(fullPath) |
490 | 502 | let xmlInfo = "" |
|
0 commit comments