Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions runtimes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ The runtime supports chat by default
| Send request to open existing tab, if `tabId` is passed or create and open new tab, if `tabId` is not passed. For the new tab, it's also possible to set tab state and content. | `aws/chat/openTab` | `OpenTabParams` | [Request](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) Server to Client | `OpenTabResult` |
| Send chat messages and tab state update to specific tab. Depending on new vs existing`messageId` within `ChatMessage` message, the massgage will be added or updated. | `aws/chat/sendChatUpdate` | `ChatUpdateParams` | [Notification](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) Server to Client | n/a |
| Send file or file action click event. | `aws/chat/fileClick` | `FileClickParams` | [Notification](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) Client to Server | n/a |
| Send or update context commands that customer can attach to their prompt request (available via `@` in chat UI). | `aws/chat/sendContextCommands` | `ContextCommandParams` | [Notification](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) Server to Client | n/a |
| Send create prompt event that triggers new prompt creation flow on server. | `aws/chat/createPrompt` | `CreatePromptParams` | [Notification](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) Client to Server | n/a |

```ts
export interface ChatPrompt {
Expand Down
10 changes: 10 additions & 0 deletions runtimes/protocol/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ import {
INLINE_CHAT_REQUEST_METHOD,
InlineChatParams,
InlineChatResult,
CONTEXT_COMMAND_NOTIFICATION_METHOD,
ContextCommandParams,
CREATE_PROMPT_NOTIFICATION_METHOD,
CreatePromptParams,
} from './lsp'

export const chatRequestType = new AutoParameterStructuresProtocolRequestType<
Expand Down Expand Up @@ -101,3 +105,9 @@ export const chatUpdateNotificationType = new ProtocolNotificationType<ChatUpdat
export const fileClickNotificationType = new ProtocolNotificationType<FileClickParams, void>(
FILE_CLICK_NOTIFICATION_METHOD
)
export const contextCommandsNotificationType = new ProtocolNotificationType<ContextCommandParams, void>(
CONTEXT_COMMAND_NOTIFICATION_METHOD
)
export const createPromptNotificationType = new ProtocolNotificationType<CreatePromptParams, void>(
CREATE_PROMPT_NOTIFICATION_METHOD
)
4 changes: 2 additions & 2 deletions runtimes/runtimes/auth/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function clearHandlers() {
authHandlers.bearerDeleteHandler = () => {}
}

const serverLspConnectionMock = <Connection>{
const serverLspConnectionMock = {
onRequest: (requestType: any, handler: any) => {
if (requestType.method === credentialsProtocolMethodNames.iamCredentialsUpdate) {
authHandlers.iamUpdateHandler = handler
Expand Down Expand Up @@ -83,7 +83,7 @@ const serverLspConnectionMock = <Connection>{
onExecuteCommand: (handler: ServerRequestHandler<ExecuteCommandParams, any, never, void>) => {},
onInitialize: (handler: ServerRequestHandler<InitializeParams, InitializeResult, never, InitializeError>) => {},
onInitialized: (handler: NotificationHandler<InitializedParams>) => {},
}
} as Connection

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

Expand Down
4 changes: 4 additions & 0 deletions runtimes/runtimes/base-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import {
chatUpdateNotificationType,
fileClickNotificationType,
inlineChatRequestType,
contextCommandsNotificationType,
createPromptNotificationType,
} from '../protocol'
import { createConnection } from 'vscode-languageserver/browser'
import {
Expand Down Expand Up @@ -144,6 +146,8 @@ export const baseRuntime = (connections: { reader: MessageReader; writer: Messag
openTab: params => lspConnection.sendRequest(openTabRequestType.method, params),
sendChatUpdate: params => lspConnection.sendNotification(chatUpdateNotificationType.method, params),
onFileClicked: handler => lspConnection.onNotification(fileClickNotificationType.method, handler),
sendContextCommands: params => lspConnection.sendNotification(contextCommandsNotificationType.method, params),
onCreatePrompt: handler => lspConnection.onNotification(createPromptNotificationType.method, handler),
}

const identityManagement: IdentityManagement = {
Expand Down
12 changes: 12 additions & 0 deletions runtimes/runtimes/chat/baseChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ import {
inlineChatRequestType,
InlineChatParams,
InlineChatResult,
ContextCommandParams,
contextCommandsNotificationType,
CreatePromptParams,
createPromptNotificationType,
} from '../../protocol'
import { Chat } from '../../server-interface'

Expand Down Expand Up @@ -114,4 +118,12 @@ export class BaseChat implements Chat {
public onFileClicked(handler: NotificationHandler<FileClickParams>) {
this.connection.onNotification(fileClickNotificationType.method, handler)
}

public sendContextCommands(params: ContextCommandParams) {
this.connection.sendNotification(contextCommandsNotificationType.method, params)
}

public onCreatePrompt(handler: NotificationHandler<CreatePromptParams>) {
this.connection.onNotification(createPromptNotificationType.method, handler)
}
}
2 changes: 1 addition & 1 deletion runtimes/runtimes/encoding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { WebBase64Encoding } from './encoding'
import sinon, { StubbedInstance, stubInterface } from 'ts-sinon'

describe('WebBase64Encoding', () => {
const wdw = <WindowOrWorkerGlobalScope>{}
const wdw = {} as WindowOrWorkerGlobalScope
const encoding = new WebBase64Encoding(wdw)

it('encodes and decodes string', () => {
Expand Down
8 changes: 4 additions & 4 deletions runtimes/runtimes/lsp/router/lspRouter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ describe('LspRouter', () => {
encode: (value: string) => value,
decode: (value: string) => value,
}
const logging = <Logging>{
const logging = {
log: sandbox.stub(),
debug: sandbox.stub(),
error: sandbox.stub(),
warn: sandbox.stub(),
info: sandbox.stub(),
}
} as Logging
const lspConnection = stubLspConnection()

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

function stubLspConnection(overrides = {}): Connection {
return <Connection>{
return {
console: {
info: (message: any) => {},
},
Expand All @@ -627,7 +627,7 @@ describe('LspRouter', () => {
onNotification: (handler: any) => {},
onDidChangeConfiguration: (handler: any) => {},
...overrides,
}
} as Connection
}

function newServer({
Expand Down
4 changes: 2 additions & 2 deletions runtimes/runtimes/lsp/router/routerByServerName.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { EventIdentifier, FollowupIdentifier } from '../../../protocol'
import { RouterByServerName } from './routerByServerName'

describe('RouterByServerName', () => {
const encoding = <Encoding>{
const encoding = {
encode: value => Buffer.from(value).toString('base64'),
decode: value => Buffer.from(value, 'base64').toString('utf-8'),
}
} as Encoding
const serverName = 'Server_XXX'

let router: RouterByServerName<Partial<EventIdentifier>, FollowupIdentifier>
Expand Down
4 changes: 4 additions & 0 deletions runtimes/server-interface/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {
FileClickParams,
InlineChatParams,
InlineChatResult,
ContextCommandParams,
CreatePromptParams,
} from '../protocol'

/**
Expand Down Expand Up @@ -49,4 +51,6 @@ export type Chat = {
onFollowUpClicked: (handler: NotificationHandler<FollowUpClickParams>) => void
sendChatUpdate: (params: ChatUpdateParams) => void
onFileClicked: (handler: NotificationHandler<FileClickParams>) => void
sendContextCommands: (params: ContextCommandParams) => void
onCreatePrompt: (handler: NotificationHandler<CreatePromptParams>) => void
}
25 changes: 25 additions & 0 deletions types/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export const OPEN_TAB_REQUEST_METHOD = 'aws/chat/openTab'
export const CHAT_UPDATE_NOTIFICATION_METHOD = 'aws/chat/sendChatUpdate'
export const FILE_CLICK_NOTIFICATION_METHOD = 'aws/chat/fileClick'
export const INLINE_CHAT_REQUEST_METHOD = 'aws/chat/sendInlineChatPrompt'
export const CONTEXT_COMMAND_NOTIFICATION_METHOD = 'aws/chat/sendContextCommands'
export const CREATE_PROMPT_NOTIFICATION_METHOD = 'aws/chat/createPrompt'

export interface ChatItemAction {
pillText: string
Expand Down Expand Up @@ -129,8 +131,11 @@ export interface QuickActionCommand {
command: string
description?: string
placeholder?: string
icon?: IconType
}

export type IconType = 'file' | 'folder' | 'code-block' | 'list-add' | 'magic' | 'help' | 'trash'

/**
* Configuration object for registering chat quick actions groups.
*/
Expand Down Expand Up @@ -259,3 +264,23 @@ export interface FileClickParams {
filePath: string
action?: FileAction
}

export interface ContextCommandGroup {
groupName?: string
commands: ContextCommand[]
}

export interface ContextCommand extends QuickActionCommand {
id?: string
route?: string[]
label?: 'file' | 'folder' | 'code'
children?: ContextCommandGroup[]
}

export interface ContextCommandParams {
contextCommandGroups: ContextCommandGroup[]
}

export interface CreatePromptParams {
promptName: string
}