Skip to content

Commit 23eae51

Browse files
committed
refactor: convert requestFiles, requestFile, and requestOptionalFile to use object parameters
1 parent ffd9e5e commit 23eae51

File tree

11 files changed

+41
-29
lines changed

11 files changed

+41
-29
lines changed

backend/src/__tests__/cost-aggregation.integration.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@ describe('Cost Aggregation Integration Tests', () => {
237237

238238
// Mock file reading
239239
spyOn(websocketAction, 'requestFiles').mockImplementation(
240-
async (ws, paths) => {
240+
async (params: { ws: any; filePaths: string[] }) => {
241241
const results: Record<string, string | null> = {}
242-
paths.forEach((path) => {
242+
params.filePaths.forEach((path) => {
243243
results[path] = path === 'hello.txt' ? 'Hello, World!' : null
244244
})
245245
return results

backend/src/__tests__/main-prompt.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ describe('mainPrompt', () => {
115115

116116
// Mock websocket actions
117117
spyOn(websocketAction, 'requestFiles').mockImplementation(
118-
async (ws: any, paths: string[]) => {
118+
async (params: { ws: any; filePaths: string[] }) => {
119119
const results: Record<string, string | null> = {}
120-
paths.forEach((p) => {
120+
params.filePaths.forEach((p) => {
121121
if (p === 'test.txt') {
122122
results[p] = 'mock content for test.txt'
123123
} else {
@@ -129,8 +129,8 @@ describe('mainPrompt', () => {
129129
)
130130

131131
spyOn(websocketAction, 'requestFile').mockImplementation(
132-
async (ws: any, path: string) => {
133-
if (path === 'test.txt') {
132+
async (params: { ws: any; filePath: string }) => {
133+
if (params.filePath === 'test.txt') {
134134
return 'mock content for test.txt'
135135
}
136136
return null

backend/src/__tests__/prompt-caching-subagents.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ describe('Prompt Caching for Subagents with inheritParentSystemPrompt', () => {
136136

137137
// Mock file operations
138138
spyOn(websocketAction, 'requestFiles').mockImplementation(
139-
async (ws, paths) => {
139+
async (params: { ws: any; filePaths: string[] }) => {
140140
const results: Record<string, string | null> = {}
141-
paths.forEach((path) => {
141+
params.filePaths.forEach((path) => {
142142
results[path] = null
143143
})
144144
return results

backend/src/__tests__/run-agent-step-tools.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ describe('runAgentStep - set_output tool', () => {
8181
spyOn(liveUserInputs, 'setSessionConnected').mockImplementation(() => {})
8282

8383
spyOn(websocketAction, 'requestFiles').mockImplementation(
84-
async (ws: any, paths: string[]) => {
84+
async (params: { ws: any; filePaths: string[] }) => {
8585
const results: Record<string, string | null> = {}
86-
paths.forEach((p) => {
86+
params.filePaths.forEach((p) => {
8787
if (p === 'src/auth.ts') {
8888
results[p] = 'export function authenticate() { return true; }'
8989
} else if (p === 'src/user.ts') {
@@ -97,10 +97,10 @@ describe('runAgentStep - set_output tool', () => {
9797
)
9898

9999
spyOn(websocketAction, 'requestFile').mockImplementation(
100-
async (ws: any, path: string) => {
101-
if (path === 'src/auth.ts') {
100+
async (params: { ws: any; filePath: string }) => {
101+
if (params.filePath === 'src/auth.ts') {
102102
return 'export function authenticate() { return true; }'
103-
} else if (path === 'src/user.ts') {
103+
} else if (params.filePath === 'src/user.ts') {
104104
return 'export interface User { id: string; name: string; }'
105105
}
106106
return null
@@ -365,9 +365,9 @@ describe('runAgentStep - set_output tool', () => {
365365

366366
// Mock requestFiles to return test file content
367367
spyOn(websocketAction, 'requestFiles').mockImplementation(
368-
async (ws: any, paths: string[]) => {
368+
async (params: { ws: any; filePaths: string[] }) => {
369369
const results: Record<string, string | null> = {}
370-
paths.forEach((p) => {
370+
params.filePaths.forEach((p) => {
371371
if (p === 'src/test.ts') {
372372
results[p] = 'export function testFunction() { return "test"; }'
373373
} else {

backend/src/get-file-reading-updates.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export async function getFileReadingUpdates(
1313
}[]
1414
> {
1515
const allFilePaths = uniq(requestedFiles)
16-
const loadedFiles = await requestFiles(ws, allFilePaths)
16+
const loadedFiles = await requestFiles({ ws, filePaths: allFilePaths })
1717

1818
const addedFiles = allFilePaths
1919
.filter(

backend/src/tools/batch-str-replace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ async function preloadOriginalContent(
194194

195195
try {
196196
// Request all files from the client in one batch
197-
const fileContents = await requestFiles(ws, pathsToLoad)
197+
const fileContents = await requestFiles({ ws, filePaths: pathsToLoad })
198198

199199
// Filter out null values and return only successfully loaded files
200200
const loadedContents: Record<string, string> = {}

backend/src/tools/handlers/tool/find-files.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ async function uploadExpandedFileContextForTraining(
184184
repoId,
185185
)
186186

187-
const loadedFiles = await requestFiles(ws, files)
187+
const loadedFiles = await requestFiles({ ws, filePaths: files })
188188

189189
// Upload a map of:
190190
// {file_path: {content, token_count}}

backend/src/tools/handlers/tool/str-replace.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ export const handleStrReplace = ((params: {
5959
? previousEdit.then((maybeResult) =>
6060
maybeResult && 'content' in maybeResult
6161
? maybeResult.content
62-
: requestOptionalFile(ws, path),
62+
: requestOptionalFile({ ws, filePath: path }),
6363
)
64-
: requestOptionalFile(ws, path)
64+
: requestOptionalFile({ ws, filePath: path })
6565

6666
const newPromise = processStrReplace({
6767
path,

backend/src/tools/handlers/tool/write-file.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ export const handleWriteFile = (({
129129
? previousEdit.then((maybeResult) =>
130130
maybeResult && 'content' in maybeResult
131131
? maybeResult.content
132-
: requestOptionalFile(ws, path),
132+
: requestOptionalFile({ ws, filePath: path }),
133133
)
134-
: requestOptionalFile(ws, path)
134+
: requestOptionalFile({ ws, filePath: path })
135135

136136
const fileContentWithoutStartNewline = content.startsWith('\n')
137137
? content.slice(1)

backend/src/websockets/websocket-action.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,11 @@ subscribeToAction('cancel-user-input', protec.run(onCancelUserInput))
398398
* @param filePaths - Array of file paths to request
399399
* @returns Promise resolving to an object mapping file paths to their contents
400400
*/
401-
export async function requestFiles(ws: WebSocket, filePaths: string[]) {
401+
export async function requestFiles(params: {
402+
ws: WebSocket
403+
filePaths: string[]
404+
}) {
405+
const { ws, filePaths } = params
402406
return new Promise<Record<string, string | null>>((resolve) => {
403407
const requestId = generateCompactId()
404408
const unsubscribe = subscribeToAction('read-files-response', (action) => {
@@ -424,13 +428,21 @@ export async function requestFiles(ws: WebSocket, filePaths: string[]) {
424428
* @param filePath - The path of the file to request
425429
* @returns Promise resolving to the file contents or null if not found
426430
*/
427-
export async function requestFile(ws: WebSocket, filePath: string) {
428-
const files = await requestFiles(ws, [filePath])
431+
export async function requestFile(params: {
432+
ws: WebSocket
433+
filePath: string
434+
}) {
435+
const { ws, filePath } = params
436+
const files = await requestFiles({ ws, filePaths: [filePath] })
429437
return files[filePath] ?? null
430438
}
431439

432-
export async function requestOptionalFile(ws: WebSocket, filePath: string) {
433-
const file = await requestFile(ws, filePath)
440+
export async function requestOptionalFile(params: {
441+
ws: WebSocket
442+
filePath: string
443+
}) {
444+
const { ws, filePath } = params
445+
const file = await requestFile({ ws, filePath })
434446
return toOptionalFile(file)
435447
}
436448

0 commit comments

Comments
 (0)