Skip to content

Commit a0ca8e0

Browse files
rahmaniaamRahmania Astrid Mochtar
andauthored
feat: add explanation text as directive (#1054)
Co-authored-by: Rahmania Astrid Mochtar <[email protected]>
1 parent 82138b3 commit a0ca8e0

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

chat-client/src/client/mynahUi.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,12 @@ export const createMynahUi = (
514514
chatResult.additionalMessages.forEach(am => {
515515
const chatItem: ChatItem = {
516516
messageId: am.messageId,
517-
type: am.type === 'tool' ? ChatItemType.ANSWER : ChatItemType.ANSWER_STREAM,
517+
type:
518+
am.type === 'tool'
519+
? ChatItemType.ANSWER
520+
: am.type === 'directive'
521+
? ChatItemType.DIRECTIVE
522+
: ChatItemType.ANSWER_STREAM,
518523
...prepareChatItemFromMessage(am),
519524
}
520525

server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ import { FsReadParams } from './tools/fsRead'
100100
import { ListDirectoryParams } from './tools/listDirectory'
101101
import { FsWrite, FsWriteParams, getDiffChanges } from './tools/fsWrite'
102102
import { ExecuteBash, ExecuteBashOutput, ExecuteBashParams } from './tools/executeBash'
103-
import { InvokeOutput } from './tools/toolShared'
103+
import { ExplanatoryParams, InvokeOutput } from './tools/toolShared'
104104

105105
type ChatHandlers = Omit<
106106
LspHandlers<Chat>,
@@ -469,6 +469,14 @@ export class AgenticChatController implements ChatHandlers {
469469
let needsConfirmation
470470

471471
try {
472+
const { explanation } = toolUse.input as unknown as ExplanatoryParams
473+
if (explanation) {
474+
await chatResultStream.writeResultBlock({
475+
type: 'directive',
476+
messageId: toolUse.toolUseId + '_explanation',
477+
body: explanation,
478+
})
479+
}
472480
switch (toolUse.name) {
473481
case 'fsRead':
474482
case 'listDirectory':

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Port from VSC https://github.com/aws/aws-toolkit-vscode/blob/741c2c481bcf0dca2d9554e32dc91d8514b1b1d1/packages/core/src/codewhispererChat/tools/executeBash.ts#L134
22

3-
import { CommandValidation, InvokeOutput } from './toolShared'
3+
import { CommandValidation, ExplanatoryParams, InvokeOutput } from './toolShared'
44
import { split } from 'shlex'
55
import { Logging } from '@aws/language-server-runtimes/server-interface'
66
import { processUtils, workspaceUtils } from '@aws/lsp-core'
@@ -108,10 +108,9 @@ export const lineCount: number = 1024
108108
export const destructiveCommandWarningMessage = '⚠️ WARNING: Destructive command detected:\n\n'
109109
export const mutateCommandWarningMessage = 'Mutation command:\n\n'
110110

111-
export interface ExecuteBashParams {
111+
export interface ExecuteBashParams extends ExplanatoryParams {
112112
command: string
113113
cwd?: string
114-
explanation?: string
115114
}
116115

117116
interface TimestampedChunk {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import { InvokeOutput } from './toolShared'
1+
import { ExplanatoryParams, InvokeOutput } from './toolShared'
22
import { Features } from '@aws/language-server-runtimes/server-interface/server'
33
import { sanitize } from '@aws/lsp-core/out/util/path'
44
import { Change, diffLines } from 'diff'
55

66
// Port of https://github.com/aws/aws-toolkit-vscode/blob/16aa8768834f41ae512522473a6a962bb96abe51/packages/core/src/codewhispererChat/tools/fsWrite.ts#L42
77

8-
interface BaseParams {
8+
interface BaseParams extends ExplanatoryParams {
99
path: string
10-
explanation?: string
1110
}
1211

1312
export interface CreateParams extends BaseParams {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ export interface CommandValidation {
2727
requiresAcceptance: boolean
2828
warning?: string
2929
}
30+
31+
export interface ExplanatoryParams {
32+
explanation?: string
33+
}

0 commit comments

Comments
 (0)