Skip to content

Commit a4fcef6

Browse files
authored
feat: added chat history protocol (#410)
* feat: added chat history protocol * chore: extended readme with new protocol methods * chore: fixed typo * chore: changed protocol type used for request * chore: fixed typo * feat: removed sendConversationsUpda * chore: updated README * feat: updated ConversationClickResult with id and action
1 parent 2b0508b commit a4fcef6

File tree

6 files changed

+109
-3
lines changed

6 files changed

+109
-3
lines changed

runtimes/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ The runtime supports chat by default
186186
| 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 |
187187
| 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 |
188188
| 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 |
189+
| Send request to list the conversations available in history: all or based on filter if provided. As there can be several filter options used, the filter in the request is a map of filter option ids to corresponding values. Possible filter options are expected to be provided in the previous `listConversations` result before filter can be used. | `aws/chat/listConversations` | `ListConversationsParams` | [Request](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) Client to Server | `ListConversationsResult` |
190+
| Send conversation or conversation action click event. If no action is provided, the default action is "open". | `aws/chat/conversationClick` | `ConversationClickParams` | [Request](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) Client to Server | `ConversationClickResult` |
189191
190192
```ts
191193
export interface ChatPrompt {

runtimes/protocol/chat.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ import {
4646
ContextCommandParams,
4747
CREATE_PROMPT_NOTIFICATION_METHOD,
4848
CreatePromptParams,
49+
ListConversationsParams,
50+
ListConversationsResult,
51+
LIST_CONVERSATIONS_REQUEST_METHOD,
52+
ConversationClickParams,
53+
ConversationClickResult,
54+
CONVERSATION_CLICK_REQUEST_METHOD,
4955
} from './lsp'
5056

5157
export const chatRequestType = new AutoParameterStructuresProtocolRequestType<
@@ -105,9 +111,27 @@ export const chatUpdateNotificationType = new ProtocolNotificationType<ChatUpdat
105111
export const fileClickNotificationType = new ProtocolNotificationType<FileClickParams, void>(
106112
FILE_CLICK_NOTIFICATION_METHOD
107113
)
114+
115+
// context
108116
export const contextCommandsNotificationType = new ProtocolNotificationType<ContextCommandParams, void>(
109117
CONTEXT_COMMAND_NOTIFICATION_METHOD
110118
)
111119
export const createPromptNotificationType = new ProtocolNotificationType<CreatePromptParams, void>(
112120
CREATE_PROMPT_NOTIFICATION_METHOD
113121
)
122+
123+
// history
124+
export const listConversationsRequestType = new AutoParameterStructuresProtocolRequestType<
125+
ListConversationsParams,
126+
ListConversationsResult,
127+
never,
128+
void,
129+
void
130+
>(LIST_CONVERSATIONS_REQUEST_METHOD)
131+
export const conversationClickRequestType = new AutoParameterStructuresProtocolRequestType<
132+
ConversationClickParams,
133+
ConversationClickResult,
134+
never,
135+
void,
136+
void
137+
>(CONVERSATION_CLICK_REQUEST_METHOD)

runtimes/runtimes/base-runtime.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ import {
4141
inlineChatRequestType,
4242
contextCommandsNotificationType,
4343
createPromptNotificationType,
44+
listConversationsRequestType,
45+
conversationClickRequestType,
4446
} from '../protocol'
4547
import { createConnection } from 'vscode-languageserver/browser'
4648
import {
@@ -148,6 +150,8 @@ export const baseRuntime = (connections: { reader: MessageReader; writer: Messag
148150
onFileClicked: handler => lspConnection.onNotification(fileClickNotificationType.method, handler),
149151
sendContextCommands: params => lspConnection.sendNotification(contextCommandsNotificationType.method, params),
150152
onCreatePrompt: handler => lspConnection.onNotification(createPromptNotificationType.method, handler),
153+
onListConversations: handler => lspConnection.onRequest(listConversationsRequestType.method, handler),
154+
onConversationClick: handler => lspConnection.onRequest(conversationClickRequestType.method, handler),
151155
}
152156

153157
const identityManagement: IdentityManagement = {

runtimes/runtimes/chat/baseChat.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ import {
4343
contextCommandsNotificationType,
4444
CreatePromptParams,
4545
createPromptNotificationType,
46+
listConversationsRequestType,
47+
ListConversationsParams,
48+
ListConversationsResult,
49+
ConversationClickParams,
50+
conversationClickRequestType,
51+
ConversationClickResult,
4652
} from '../../protocol'
4753
import { Chat } from '../../server-interface'
4854

@@ -126,4 +132,12 @@ export class BaseChat implements Chat {
126132
public onCreatePrompt(handler: NotificationHandler<CreatePromptParams>) {
127133
this.connection.onNotification(createPromptNotificationType.method, handler)
128134
}
135+
136+
public onListConversations(handler: RequestHandler<ListConversationsParams, ListConversationsResult, void>) {
137+
this.connection.onRequest(listConversationsRequestType.method, handler)
138+
}
139+
140+
public onConversationClick(handler: RequestHandler<ConversationClickParams, ConversationClickResult, void>) {
141+
this.connection.onRequest(conversationClickRequestType.method, handler)
142+
}
129143
}

runtimes/server-interface/chat.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ import {
2424
InlineChatResult,
2525
ContextCommandParams,
2626
CreatePromptParams,
27+
ListConversationsParams,
28+
ListConversationsResult,
29+
ConversationClickParams,
30+
ConversationClickResult,
2731
} from '../protocol'
2832

2933
/**
@@ -38,6 +42,8 @@ export type Chat = {
3842
onEndChat: (handler: RequestHandler<EndChatParams, EndChatResult, void>) => void
3943
onQuickAction: (handler: RequestHandler<QuickActionParams, QuickActionResult, void>) => void
4044
openTab: (params: OpenTabParams) => Promise<OpenTabResult>
45+
onListConversations: (handler: RequestHandler<ListConversationsParams, ListConversationsResult, void>) => void
46+
onConversationClick: (handler: RequestHandler<ConversationClickParams, ConversationClickResult, void>) => void
4147
// Notifications
4248
onSendFeedback: (handler: NotificationHandler<FeedbackParams>) => void
4349
onReady: (handler: NotificationHandler<void>) => void

types/chat.ts

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Chat Data Model
21
import { Position, Range, TextDocumentIdentifier } from './lsp'
32

43
export const CHAT_REQUEST_METHOD = 'aws/chat/sendChatPrompt'
@@ -18,8 +17,12 @@ export const OPEN_TAB_REQUEST_METHOD = 'aws/chat/openTab'
1817
export const CHAT_UPDATE_NOTIFICATION_METHOD = 'aws/chat/sendChatUpdate'
1918
export const FILE_CLICK_NOTIFICATION_METHOD = 'aws/chat/fileClick'
2019
export const INLINE_CHAT_REQUEST_METHOD = 'aws/chat/sendInlineChatPrompt'
20+
// context
2121
export const CONTEXT_COMMAND_NOTIFICATION_METHOD = 'aws/chat/sendContextCommands'
2222
export const CREATE_PROMPT_NOTIFICATION_METHOD = 'aws/chat/createPrompt'
23+
// history
24+
export const LIST_CONVERSATIONS_REQUEST_METHOD = 'aws/chat/listConversations'
25+
export const CONVERSATION_CLICK_REQUEST_METHOD = 'aws/chat/conversationClick'
2326

2427
export interface ChatItemAction {
2528
pillText: string
@@ -63,7 +66,6 @@ export type CodeSelectionType = 'selection' | 'block'
6366

6467
export type CursorState = { position: Position } | { range: Range }
6568

66-
// LSP Types
6769
interface PartialResultParams {
6870
partialResultToken?: number | string
6971
}
@@ -134,7 +136,8 @@ export interface QuickActionCommand {
134136
icon?: IconType
135137
}
136138

137-
export type IconType = 'file' | 'folder' | 'code-block' | 'list-add' | 'magic' | 'help' | 'trash'
139+
export type ContextCommandIconType = 'file' | 'folder' | 'code-block' | 'list-add' | 'magic'
140+
export type IconType = ContextCommandIconType | 'help' | 'trash' | 'search' | 'calendar' | string
138141

139142
/**
140143
* Configuration object for registering chat quick actions groups.
@@ -265,6 +268,8 @@ export interface FileClickParams {
265268
action?: FileAction
266269
}
267270

271+
// context
272+
268273
export interface ContextCommandGroup {
269274
groupName?: string
270275
commands: ContextCommand[]
@@ -284,3 +289,54 @@ export interface ContextCommandParams {
284289
export interface CreatePromptParams {
285290
promptName: string
286291
}
292+
293+
// history
294+
295+
export type TextBasedFilterOption = {
296+
type: 'textarea' | 'textinput'
297+
placeholder?: string
298+
icon?: IconType
299+
}
300+
export type FilterValue = string
301+
export type FilterOption = { id: string } & TextBasedFilterOption
302+
export interface Action {
303+
id: string
304+
icon?: IconType
305+
text: string
306+
}
307+
export interface ConversationItem {
308+
id: string
309+
icon?: IconType
310+
description?: string
311+
actions?: Action[]
312+
}
313+
314+
export interface ConversationItemGroup {
315+
groupName?: string
316+
icon?: IconType
317+
items?: ConversationItem[]
318+
}
319+
320+
export interface ListConversationsParams {
321+
// key maps to id in FilterOption and value to corresponding filter value
322+
filter?: Record<string, FilterValue>
323+
}
324+
325+
export interface ConversationsList {
326+
header?: { title: string }
327+
filterOptions?: FilterOption[]
328+
list: ConversationItemGroup[]
329+
}
330+
331+
export interface ListConversationsResult extends ConversationsList {}
332+
333+
export type ConversationAction = 'delete' | 'export'
334+
335+
export interface ConversationClickParams {
336+
id: string
337+
action?: ConversationAction
338+
}
339+
340+
export interface ConversationClickResult extends ConversationClickParams {
341+
success: boolean
342+
}

0 commit comments

Comments
 (0)