Skip to content

Commit 5ffb846

Browse files
committed
Trying another approach for read and list tool execution
1 parent 6a9ccfa commit 5ffb846

File tree

5 files changed

+18
-20
lines changed

5 files changed

+18
-20
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,11 @@ export class Messenger {
353353
isReadOrList,
354354
changeList
355355
)
356-
await ToolUtils.queueDescription(tool, chatStream)
356+
await ToolUtils.queueDescription(
357+
tool,
358+
chatStream,
359+
chatStream.validation.requiresAcceptance
360+
)
357361
if (session.messageIdToUpdate === undefined && tool.type === ToolType.FsRead) {
358362
// Store the first messageId in a chain of tool uses
359363
session.setMessageIdToUpdate(toolUse.toolUseId)

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { Writable } from 'stream'
99
import { InvokeOutput, OutputKind, sanitizePath, CommandValidation } from './toolShared'
1010
import { isInDirectory } from '../../shared/filesystemUtilities'
1111
import path from 'path'
12-
import { ChatStream } from './chatStream'
1312

1413
export interface FsReadParams {
1514
path: string
@@ -49,8 +48,8 @@ export class FsRead {
4948
this.logger.debug(`Validation succeeded for path: ${this.fsPath}`)
5049
}
5150

52-
public queueDescription(updates: ChatStream): void {
53-
if (updates.validation.requiresAcceptance) {
51+
public queueDescription(updates: Writable, requiresAcceptance: boolean): void {
52+
if (requiresAcceptance) {
5453
const fileName = path.basename(this.fsPath)
5554
const fileUri = vscode.Uri.file(this.fsPath)
5655
updates.write(`Reading file: [${fileName}](${fileUri}), `)

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { Writable } from 'stream'
1010
import path from 'path'
1111
import { InvokeOutput, OutputKind, sanitizePath, CommandValidation } from './toolShared'
1212
import { isInDirectory } from '../../shared/filesystemUtilities'
13-
import { ChatStream } from './chatStream'
1413

1514
export interface ListDirectoryParams {
1615
path: string
@@ -50,8 +49,8 @@ export class ListDirectory {
5049
}
5150
}
5251

53-
public queueDescription(updates: ChatStream): void {
54-
if (updates.validation.requiresAcceptance) {
52+
public queueDescription(updates: Writable, requiresAcceptance: boolean): void {
53+
if (requiresAcceptance) {
5554
const fileName = path.basename(this.fsPath)
5655
if (this.maxDepth === undefined) {
5756
updates.write(`Analyzing directories recursively: ${fileName}`)

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { CommandValidation, ExecuteBash, ExecuteBashParams } from './executeBash
1010
import { ToolResult, ToolResultContentBlock, ToolResultStatus, ToolUse } from '@amzn/codewhisperer-streaming'
1111
import { InvokeOutput, maxToolResponseSize } from './toolShared'
1212
import { ListDirectory, ListDirectoryParams } from './listDirectory'
13-
import { ChatStream } from './chatStream'
1413

1514
export enum ToolType {
1615
FsRead = 'fsRead',
@@ -80,10 +79,10 @@ export class ToolUtils {
8079
}
8180
}
8281

83-
static async queueDescription(tool: Tool, updates: ChatStream): Promise<void> {
82+
static async queueDescription(tool: Tool, updates: Writable, requiresAcceptance: boolean): Promise<void> {
8483
switch (tool.type) {
8584
case ToolType.FsRead:
86-
tool.tool.queueDescription(updates)
85+
tool.tool.queueDescription(updates, requiresAcceptance)
8786
break
8887
case ToolType.FsWrite:
8988
await tool.tool.queueDescription(updates)
@@ -92,7 +91,7 @@ export class ToolUtils {
9291
tool.tool.queueDescription(updates)
9392
break
9493
case ToolType.ListDirectory:
95-
tool.tool.queueDescription(updates)
94+
tool.tool.queueDescription(updates, requiresAcceptance)
9695
break
9796
}
9897
}

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { ToolUse } from '@amzn/codewhisperer-streaming'
1515
import path from 'path'
1616
import fs from '../../../shared/fs/fs'
1717
import { ListDirectory } from '../../../codewhispererChat/tools/listDirectory'
18-
import { ChatStream } from '../../../codewhispererChat/tools/chatStream'
1918

2019
describe('ToolUtils', function () {
2120
let sandbox: sinon.SinonSandbox
@@ -24,7 +23,6 @@ describe('ToolUtils', function () {
2423
let mockExecuteBash: sinon.SinonStubbedInstance<ExecuteBash>
2524
let mockListDirectory: sinon.SinonStubbedInstance<ListDirectory>
2625
let mockWritable: sinon.SinonStubbedInstance<Writable>
27-
let mockChatStream: sinon.SinonStubbedInstance<ChatStream>
2826

2927
beforeEach(function () {
3028
sandbox = sinon.createSandbox()
@@ -35,7 +33,6 @@ describe('ToolUtils', function () {
3533
mockWritable = {
3634
write: sandbox.stub(),
3735
} as unknown as sinon.SinonStubbedInstance<Writable>
38-
mockChatStream = sandbox.createStubInstance(ChatStream)
3936
;(mockFsRead.requiresAcceptance as sinon.SinonStub).returns({ requiresAcceptance: false })
4037
;(mockListDirectory.requiresAcceptance as sinon.SinonStub).returns({ requiresAcceptance: false })
4138
})
@@ -188,30 +185,30 @@ describe('ToolUtils', function () {
188185
// TODO: Adding "void" to the following tests for the current implementation but in the next followup PR I will fix this issue.
189186
it('delegates to FsRead tool queueDescription method', function () {
190187
const tool: Tool = { type: ToolType.FsRead, tool: mockFsRead as unknown as FsRead }
191-
void ToolUtils.queueDescription(tool, mockWritable as unknown as ChatStream)
188+
void ToolUtils.queueDescription(tool, mockWritable as unknown as Writable, false)
192189

193-
assert(mockFsRead.queueDescription.calledOnceWith(mockChatStream))
190+
assert(mockFsRead.queueDescription.calledOnceWith(mockWritable, false))
194191
})
195192

196193
it('delegates to FsWrite tool queueDescription method', function () {
197194
const tool: Tool = { type: ToolType.FsWrite, tool: mockFsWrite as unknown as FsWrite }
198-
void ToolUtils.queueDescription(tool, mockWritable as unknown as ChatStream)
195+
void ToolUtils.queueDescription(tool, mockWritable as unknown as Writable, false)
199196

200197
assert(mockFsWrite.queueDescription.calledOnceWith(mockWritable))
201198
})
202199

203200
it('delegates to ExecuteBash tool queueDescription method', function () {
204201
const tool: Tool = { type: ToolType.ExecuteBash, tool: mockExecuteBash as unknown as ExecuteBash }
205-
void ToolUtils.queueDescription(tool, mockWritable as unknown as ChatStream)
202+
void ToolUtils.queueDescription(tool, mockWritable as unknown as Writable, false)
206203

207204
assert(mockExecuteBash.queueDescription.calledOnceWith(mockWritable))
208205
})
209206

210207
it('delegates to ListDirectory tool queueDescription method', function () {
211208
const tool: Tool = { type: ToolType.ListDirectory, tool: mockListDirectory as unknown as ListDirectory }
212-
void ToolUtils.queueDescription(tool, mockWritable as unknown as ChatStream)
209+
void ToolUtils.queueDescription(tool, mockWritable as unknown as Writable, false)
213210

214-
assert(mockListDirectory.queueDescription.calledOnceWith(mockChatStream))
211+
assert(mockListDirectory.queueDescription.calledOnceWith(mockWritable, false))
215212
})
216213
})
217214

0 commit comments

Comments
 (0)