Skip to content

Commit 4c02f9f

Browse files
committed
refactor: validate before invoking
1 parent 1949a56 commit 4c02f9f

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/fsRead.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export class FsRead {
4545
}
4646

4747
public async invoke(params: FsReadParams): Promise<InvokeOutput> {
48+
await this.validate(params)
4849
try {
4950
const fileContents = await this.readFile(params.path)
5051
this.logging.info(`Read file: ${params.path}, size: ${fileContents.length}`)
@@ -115,7 +116,7 @@ export class FsRead {
115116
}
116117
}
117118

118-
public static getSpec() {
119+
public getSpec() {
119120
return {
120121
name: 'fsRead',
121122
description:

server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/fsWrite.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export class FsWrite {
4343
}
4444

4545
public async invoke(params: FsWriteParams): Promise<InvokeOutput> {
46+
await this.validate(params)
4647
const sanitizedPath = sanitize(params.path)
4748

4849
switch (params.command) {
@@ -162,7 +163,7 @@ export class FsWrite {
162163
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
163164
}
164165

165-
public static getSpec() {
166+
public getSpec() {
166167
return {
167168
name: 'fsWrite',
168169
description:

server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/toolServer.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,12 @@ import { FsRead, FsReadParams } from './fsRead'
33
import { FsWrite, FsWriteParams } from './fsWrite'
44

55
export const FsToolsServer: Server = ({ workspace, logging, agent }) => {
6-
const fsRead = new FsRead({ workspace, logging })
7-
const fsWrite = new FsWrite({ workspace, logging })
6+
const fsReadTool = new FsRead({ workspace, logging })
7+
const fsWriteTool = new FsWrite({ workspace, logging })
88

9-
agent.addTool(FsRead.getSpec(), (input: FsReadParams) => {
10-
return fsRead.invoke(input)
11-
})
9+
agent.addTool(fsReadTool.getSpec(), (input: FsReadParams) => fsReadTool.invoke(input))
1210

13-
agent.addTool(FsWrite.getSpec(), (input: FsWriteParams) => {
14-
return fsWrite.invoke(input)
15-
})
11+
agent.addTool(fsWriteTool.getSpec(), (input: FsWriteParams) => fsWriteTool.invoke(input))
1612

17-
// nothing to dispose of.
1813
return () => {}
1914
}

0 commit comments

Comments
 (0)