Skip to content

Commit db0b5a3

Browse files
committed
feat(amazonq): handle getSerializedChat
1 parent dc43ad2 commit db0b5a3

File tree

3 files changed

+73
-27
lines changed

3 files changed

+73
-27
lines changed

package-lock.json

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

packages/amazonq/src/lsp/chat/messages.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
COPY_TO_CLIPBOARD,
1212
AuthFollowUpType,
1313
DISCLAIMER_ACKNOWLEDGED,
14+
UiMessageResultParams,
1415
} from '@aws/chat-client-ui-types'
1516
import {
1617
ChatResult,
@@ -21,6 +22,10 @@ import {
2122
QuickActionResult,
2223
QuickActionParams,
2324
insertToCursorPositionNotificationType,
25+
ErrorCodes,
26+
ResponseError,
27+
openTabRequestType,
28+
getSerializedChatRequestType,
2429
} from '@aws/language-server-runtimes/protocol'
2530
import { v4 as uuidv4 } from 'uuid'
2631
import * as vscode from 'vscode'
@@ -184,6 +189,59 @@ export function registerMessageListeners(
184189
break
185190
}
186191
}, undefined)
192+
193+
const registerHandlerWithResponseRouter = (command: string) => {
194+
const handler = async (params: any, _: any) => {
195+
const mapErrorType = (type: string | undefined): number => {
196+
switch (type) {
197+
case 'InvalidRequest':
198+
return ErrorCodes.InvalidRequest
199+
case 'InternalError':
200+
return ErrorCodes.InternalError
201+
case 'UnknownError':
202+
default:
203+
return ErrorCodes.UnknownErrorCode
204+
}
205+
}
206+
const requestId = uuidv4()
207+
208+
void provider.webview?.postMessage({
209+
requestId: requestId,
210+
command: command,
211+
params: params,
212+
})
213+
const responsePromise = new Promise<UiMessageResultParams | undefined>((resolve, reject) => {
214+
const timeout = setTimeout(() => {
215+
disposable?.dispose()
216+
reject(new Error('Request timed out'))
217+
}, 30000)
218+
219+
const disposable = provider.webview?.onDidReceiveMessage((message: any) => {
220+
if (message.requestId === requestId) {
221+
clearTimeout(timeout)
222+
disposable?.dispose()
223+
resolve(message.params)
224+
}
225+
})
226+
})
227+
228+
const result = await responsePromise
229+
230+
if (result?.success) {
231+
return result.result
232+
} else {
233+
return new ResponseError(
234+
mapErrorType(result?.error.type),
235+
result?.error.message ?? 'No response from client'
236+
)
237+
}
238+
}
239+
240+
languageClient.onRequest(command, handler)
241+
}
242+
243+
registerHandlerWithResponseRouter(openTabRequestType.method)
244+
registerHandlerWithResponseRouter(getSerializedChatRequestType.method)
187245
}
188246

189247
function isServerEvent(command: string) {

packages/core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,8 @@
441441
"devDependencies": {
442442
"@aws-sdk/types": "^3.13.1",
443443
"@aws/chat-client-ui-types": "^0.1.12",
444-
"@aws/language-server-runtimes": "^0.2.49",
445-
"@aws/language-server-runtimes-types": "^0.1.10",
444+
"@aws/language-server-runtimes": "^0.2.58",
445+
"@aws/language-server-runtimes-types": "^0.1.13",
446446
"@cspotcode/source-map-support": "^0.8.1",
447447
"@sinonjs/fake-timers": "^10.0.2",
448448
"@types/adm-zip": "^0.4.34",

0 commit comments

Comments
 (0)