Skip to content

Commit 4b0f65a

Browse files
committed
fix(chat): Remove enforceMaxSize from fsRead
1 parent 8a20b10 commit 4b0f65a

File tree

4 files changed

+9
-23
lines changed

4 files changed

+9
-23
lines changed

packages/core/src/codewhispererChat/controllers/chat/controller.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ import {
9393
} from '../../constants'
9494
import { ChatSession } from '../../clients/chat/v0/chat'
9595
import { amazonQTabSuffix } from '../../../shared/constants'
96-
import { maxToolOutputCharacterLength, OutputKind } from '../../tools/toolShared'
96+
import { maxToolResponseSize, OutputKind } from '../../tools/toolShared'
9797
import { ToolUtils, Tool, ToolType } from '../../tools/toolUtils'
9898
import { ChatStream } from '../../tools/chatStream'
9999
import { ChatHistoryStorage } from '../../storages/chatHistoryStorage'
@@ -723,10 +723,8 @@ export class ChatController {
723723
requiresAcceptance: false,
724724
})
725725
const output = await ToolUtils.invoke(tool, chatStream)
726-
if (output.output.content.length > maxToolOutputCharacterLength) {
727-
throw Error(
728-
`Tool output exceeds maximum character limit of ${maxToolOutputCharacterLength}`
729-
)
726+
if (output.output.content.length > maxToolResponseSize) {
727+
throw Error(`Tool output exceeds maximum character limit of ${maxToolResponseSize}`)
730728
}
731729

732730
toolResults.push({

packages/core/src/codewhispererChat/tools/fsRead.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import * as vscode from 'vscode'
66
import { getLogger } from '../../shared/logger/logger'
77
import fs from '../../shared/fs/fs'
8-
import { InvokeOutput, maxToolResponseSize, OutputKind, sanitizePath } from './toolShared'
8+
import { InvokeOutput, OutputKind, sanitizePath } from './toolShared'
99
import { Writable } from 'stream'
1010
import path from 'path'
1111

@@ -89,7 +89,7 @@ export class FsRead {
8989
private handleFileRange(fullText: string): InvokeOutput {
9090
if (!this.readRange || this.readRange.length === 0) {
9191
this.logger.info('No range provided. returning entire file.')
92-
return this.createOutput(this.enforceMaxSize(fullText))
92+
return this.createOutput(fullText)
9393
}
9494

9595
const lines = fullText.split('\n')
@@ -101,7 +101,7 @@ export class FsRead {
101101

102102
this.logger.info(`Reading file: ${this.fsPath}, lines ${start + 1}-${end + 1}`)
103103
const slice = lines.slice(start, end + 1).join('\n')
104-
return this.createOutput(this.enforceMaxSize(slice))
104+
return this.createOutput(slice)
105105
}
106106

107107
private parseLineRange(lineCount: number, range: number[]): [number, number] {
@@ -121,17 +121,6 @@ export class FsRead {
121121
return [finalStart, finalEnd]
122122
}
123123

124-
private enforceMaxSize(content: string): string {
125-
const byteCount = Buffer.byteLength(content, 'utf8')
126-
if (byteCount > maxToolResponseSize) {
127-
throw new Error(
128-
`This tool only supports reading ${maxToolResponseSize} bytes at a time.
129-
You tried to read ${byteCount} bytes. Try executing with fewer lines specified.`
130-
)
131-
}
132-
return content
133-
}
134-
135124
private createOutput(content: string): InvokeOutput {
136125
return {
137126
output: {

packages/core/src/codewhispererChat/tools/toolShared.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
import path from 'path'
77
import fs from '../../shared/fs/fs'
88

9-
export const maxToolResponseSize = 30720 // 30KB
10-
export const maxToolOutputCharacterLength = 800_000
9+
export const maxToolResponseSize = 800_000
1110

1211
export enum OutputKind {
1312
Text = 'text',

packages/core/src/test/codewhispererChat/tools/fsRead.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ describe('FsRead Tool', () => {
5454
)
5555
})
5656

57-
it('throws error if content exceeds 30KB', async function () {
58-
const bigContent = 'x'.repeat(35_000)
57+
it('throws error if content exceeds 800KB', async function () {
58+
const bigContent = 'x'.repeat(800_001)
5959
const bigFilePath = await testFolder.write('bigFile.txt', bigContent)
6060

6161
const fsRead = new FsRead({ path: bigFilePath })

0 commit comments

Comments
 (0)