Skip to content

Commit 4762369

Browse files
committed
feat(amazonq): chat context commands for prompts
feat(amazonq): integrate with local context server fix(amazonq): fixes and refactor
1 parent 68e692a commit 4762369

19 files changed

+1213
-65
lines changed

package-lock.json

Lines changed: 126 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/aws-lsp-codewhisperer/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"adm-zip": "^0.5.10",
3939
"archiver": "^7.0.1",
4040
"aws-sdk": "^2.1403.0",
41+
"chokidar": "^4.0.3",
4142
"deepmerge": "^4.3.1",
4243
"diff": "^7.0.0",
4344
"fastest-levenshtein": "^1.0.16",

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Will be deleted or merged.
44
*/
55

6+
import path = require('path')
67
import {
78
ChatResponseStream,
89
CodeWhispererStreaming,
@@ -36,6 +37,8 @@ import { DEFAULT_HELP_FOLLOW_UP_PROMPT, HELP_MESSAGE } from '../chat/constants'
3637
import { TelemetryService } from '../../shared/telemetry/telemetryService'
3738
import { AmazonQTokenServiceManager } from '../../shared/amazonQServiceManager/AmazonQTokenServiceManager'
3839
import { TabBarController } from './tabBarController'
40+
import { getUserPromptsDirectory } from './context/contextUtils'
41+
import { AdditionalContextProvider } from './context/addtionalContextProvider'
3942

4043
describe('AgenticChatController', () => {
4144
const mockTabId = 'tab-1'
@@ -72,6 +75,7 @@ describe('AgenticChatController', () => {
7275
codeReference: undefined,
7376
followUp: undefined,
7477
relatedContent: undefined,
78+
contextList: undefined,
7579
}
7680

7781
const expectedCompleteInlineChatResult: InlineChatResult = {
@@ -82,6 +86,7 @@ describe('AgenticChatController', () => {
8286
followUp: undefined,
8387
relatedContent: undefined,
8488
requestId: mockMessageId,
89+
contextList: undefined,
8590
}
8691

8792
const mockCancellationToken = {
@@ -97,11 +102,13 @@ describe('AgenticChatController', () => {
97102

98103
let sendMessageStub: sinon.SinonStub
99104
let generateAssistantResponseStub: sinon.SinonStub
105+
let additionalContextProviderStub: sinon.SinonStub
100106
let disposeStub: sinon.SinonStub
101107
let activeTabSpy: {
102108
get: sinon.SinonSpy<[], string | undefined>
103109
set: sinon.SinonSpy<[string | undefined], void>
104110
}
111+
let fsWriteFileStub: sinon.SinonStub
105112
let removeConversationSpy: sinon.SinonSpy
106113
let emitConversationMetricStub: sinon.SinonStub
107114

@@ -144,13 +151,14 @@ describe('AgenticChatController', () => {
144151
})
145152

146153
testFeatures = new TestFeatures()
154+
fsWriteFileStub = sinon.stub()
147155

148156
testFeatures.workspace.fs = {
149157
...testFeatures.workspace.fs,
150158
getServerDataDirPath: sinon.stub().returns('/mock/server/data/path'),
151159
mkdir: sinon.stub().resolves(),
152160
readFile: sinon.stub().resolves(),
153-
writeFile: sinon.stub().resolves(),
161+
writeFile: fsWriteFileStub.resolves(),
154162
rm: sinon.stub().resolves(),
155163
}
156164

@@ -161,6 +169,8 @@ describe('AgenticChatController', () => {
161169
addTool: sinon.stub().resolves(),
162170
}
163171

172+
additionalContextProviderStub = sinon.stub(AdditionalContextProvider.prototype, 'getAdditionalContext')
173+
additionalContextProviderStub.resolves([])
164174
// @ts-ignore
165175
const cachedInitializeParams: InitializeParams = {
166176
initializationOptions: {
@@ -173,6 +183,7 @@ describe('AgenticChatController', () => {
173183
},
174184
},
175185
}
186+
testFeatures.lsp.window.showDocument = sinon.stub()
176187
testFeatures.lsp.getClientInitializeParams.returns(cachedInitializeParams)
177188
setCredentials('builderId')
178189

@@ -1001,6 +1012,25 @@ describe('AgenticChatController', () => {
10011012
})
10021013
})
10031014

1015+
describe('onCreatePrompt', () => {
1016+
it('should create prompt file with given name', async () => {
1017+
const promptName = 'testPrompt'
1018+
const expectedPath = path.join(getUserPromptsDirectory(), 'testPrompt.prompt.md')
1019+
1020+
await chatController.onCreatePrompt({ promptName })
1021+
1022+
sinon.assert.calledOnceWithExactly(fsWriteFileStub, expectedPath, '', { mode: 0o600 })
1023+
})
1024+
1025+
it('should create default prompt file when no name provided', async () => {
1026+
const expectedPath = path.join(getUserPromptsDirectory(), 'default.prompt.md')
1027+
1028+
await chatController.onCreatePrompt({ promptName: '' })
1029+
1030+
sinon.assert.calledOnceWithExactly(fsWriteFileStub, expectedPath, '', { mode: 0o600 })
1031+
})
1032+
})
1033+
10041034
describe('onInlineChatPrompt', () => {
10051035
it('read all the response streams and return compiled results', async () => {
10061036
const chatResultPromise = chatController.onInlineChatPrompt(

0 commit comments

Comments
 (0)