Skip to content

Commit e5dc9f3

Browse files
committed
feat: added protocol for context commands
1 parent 55a5d76 commit e5dc9f3

File tree

9 files changed

+44
-9
lines changed

9 files changed

+44
-9
lines changed

runtimes/protocol/chat.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ import {
4141
FileClickParams,
4242
INLINE_CHAT_REQUEST_METHOD,
4343
InlineChatParams,
44+
CONTEXT_COMMAND_NOTIFICATION_METHOD,
45+
ContextCommandParams,
4446
} from './lsp'
4547

4648
export const chatRequestType = new AutoParameterStructuresProtocolRequestType<
@@ -100,3 +102,6 @@ export const chatUpdateNotificationType = new ProtocolNotificationType<ChatUpdat
100102
export const fileClickNotificationType = new ProtocolNotificationType<FileClickParams, void>(
101103
FILE_CLICK_NOTIFICATION_METHOD
102104
)
105+
export const contextCommandsNotificationType = new ProtocolNotificationType<ContextCommandParams, void>(
106+
CONTEXT_COMMAND_NOTIFICATION_METHOD
107+
)

runtimes/runtimes/auth/auth.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function clearHandlers() {
4848
authHandlers.bearerDeleteHandler = () => {}
4949
}
5050

51-
const serverLspConnectionMock = <Connection>{
51+
const serverLspConnectionMock = {
5252
onRequest: (requestType: any, handler: any) => {
5353
if (requestType.method === credentialsProtocolMethodNames.iamCredentialsUpdate) {
5454
authHandlers.iamUpdateHandler = handler
@@ -83,7 +83,7 @@ const serverLspConnectionMock = <Connection>{
8383
onExecuteCommand: (handler: ServerRequestHandler<ExecuteCommandParams, any, never, void>) => {},
8484
onInitialize: (handler: ServerRequestHandler<InitializeParams, InitializeResult, never, InitializeError>) => {},
8585
onInitialized: (handler: NotificationHandler<InitializedParams>) => {},
86-
}
86+
} as Connection
8787

8888
const lspRouter = new LspRouter(serverLspConnectionMock, 'name')
8989

runtimes/runtimes/base-runtime.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
chatUpdateNotificationType,
4040
fileClickNotificationType,
4141
inlineChatRequestType,
42+
contextCommandsNotificationType,
4243
} from '../protocol'
4344
import { createConnection } from 'vscode-languageserver/browser'
4445
import {
@@ -144,6 +145,7 @@ export const baseRuntime = (connections: { reader: MessageReader; writer: Messag
144145
openTab: params => lspConnection.sendRequest(openTabRequestType.method, params),
145146
sendChatUpdate: params => lspConnection.sendNotification(chatUpdateNotificationType.method, params),
146147
onFileClicked: handler => lspConnection.onNotification(fileClickNotificationType.method, handler),
148+
sendContextCommands: params => lspConnection.sendNotification(contextCommandsNotificationType.method),
147149
}
148150

149151
const identityManagement: IdentityManagement = {

runtimes/runtimes/chat/baseChat.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import {
3838
fileClickNotificationType,
3939
inlineChatRequestType,
4040
InlineChatParams,
41+
ContextCommandParams,
42+
contextCommandsNotificationType,
4143
} from '../../protocol'
4244
import { Chat } from '../../server-interface'
4345

@@ -111,4 +113,8 @@ export class BaseChat implements Chat {
111113
public onFileClicked(handler: NotificationHandler<FileClickParams>) {
112114
this.connection.onNotification(fileClickNotificationType.method, handler)
113115
}
116+
117+
public sendContextCommands(params: ContextCommandParams) {
118+
this.connection.sendNotification(contextCommandsNotificationType.method, params)
119+
}
114120
}

runtimes/runtimes/encoding.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { WebBase64Encoding } from './encoding'
33
import sinon, { StubbedInstance, stubInterface } from 'ts-sinon'
44

55
describe('WebBase64Encoding', () => {
6-
const wdw = <WindowOrWorkerGlobalScope>{}
6+
const wdw = {} as WindowOrWorkerGlobalScope
77
const encoding = new WebBase64Encoding(wdw)
88

99
it('encodes and decodes string', () => {

runtimes/runtimes/lsp/router/lspRouter.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ describe('LspRouter', () => {
2828
encode: (value: string) => value,
2929
decode: (value: string) => value,
3030
}
31-
const logging = <Logging>{
31+
const logging = {
3232
log: sandbox.stub(),
3333
debug: sandbox.stub(),
3434
error: sandbox.stub(),
3535
warn: sandbox.stub(),
3636
info: sandbox.stub(),
37-
}
37+
} as Logging
3838
const lspConnection = stubLspConnection()
3939

4040
let executeCommandHandler: RequestHandler<ExecuteCommandParams, any | undefined | null, void>
@@ -613,7 +613,7 @@ describe('LspRouter', () => {
613613
})
614614

615615
function stubLspConnection(overrides = {}): Connection {
616-
return <Connection>{
616+
return {
617617
console: {
618618
info: (message: any) => {},
619619
},
@@ -627,7 +627,7 @@ describe('LspRouter', () => {
627627
onNotification: (handler: any) => {},
628628
onDidChangeConfiguration: (handler: any) => {},
629629
...overrides,
630-
}
630+
} as Connection
631631
}
632632

633633
function newServer({

runtimes/runtimes/lsp/router/routerByServerName.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { EventIdentifier, FollowupIdentifier } from '../../../protocol'
44
import { RouterByServerName } from './routerByServerName'
55

66
describe('RouterByServerName', () => {
7-
const encoding = <Encoding>{
7+
const encoding = {
88
encode: value => Buffer.from(value).toString('base64'),
99
decode: value => Buffer.from(value, 'base64').toString('utf-8'),
10-
}
10+
} as Encoding
1111
const serverName = 'Server_XXX'
1212

1313
let router: RouterByServerName<Partial<EventIdentifier>, FollowupIdentifier>

runtimes/server-interface/chat.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
ChatUpdateParams,
2222
FileClickParams,
2323
InlineChatParams,
24+
ContextCommandParams,
2425
} from '../protocol'
2526

2627
/**
@@ -46,4 +47,5 @@ export type Chat = {
4647
onFollowUpClicked: (handler: NotificationHandler<FollowUpClickParams>) => void
4748
sendChatUpdate: (params: ChatUpdateParams) => void
4849
onFileClicked: (handler: NotificationHandler<FileClickParams>) => void
50+
sendContextCommands: (params: ContextCommandParams) => void
4951
}

types/chat.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const OPEN_TAB_REQUEST_METHOD = 'aws/chat/openTab'
1818
export const CHAT_UPDATE_NOTIFICATION_METHOD = 'aws/chat/sendChatUpdate'
1919
export const FILE_CLICK_NOTIFICATION_METHOD = 'aws/chat/fileClick'
2020
export const INLINE_CHAT_REQUEST_METHOD = 'aws/chat/sendInlineChatPrompt'
21+
export const CONTEXT_COMMAND_NOTIFICATION_METHOD = 'aws/chat/sendContextCommands'
2122

2223
export interface ChatItemAction {
2324
pillText: string
@@ -126,6 +127,7 @@ export interface QuickActionCommand {
126127
command: string
127128
description?: string
128129
placeholder?: string
130+
icon?: IconType
129131
}
130132

131133
/**
@@ -256,3 +258,21 @@ export interface FileClickParams {
256258
filePath: string
257259
action?: FileAction
258260
}
261+
262+
export interface ContextCommandGroup {
263+
groupName?: string
264+
commands: ContextCommand[]
265+
}
266+
267+
export type IconType = 'file' | 'folder' | 'code-block' | 'list-add' | 'magic' | 'help' | 'trash'
268+
269+
export interface ContextCommand extends QuickActionCommand {
270+
id?: string
271+
route?: string[]
272+
label?: 'file' | 'folder' | 'code'
273+
children?: ContextCommandGroup[]
274+
}
275+
276+
export interface ContextCommandParams {
277+
contextCommandGroups: ContextCommandGroup[]
278+
}

0 commit comments

Comments
 (0)