Skip to content

Commit f0d8173

Browse files
authored
Merge pull request #62 from aws/dogusata/add-context-selector-to-prompt-input
(feat): Add context selector to prompt input
2 parents de736b5 + 17ff7a9 commit f0d8173

File tree

12 files changed

+343
-94
lines changed

12 files changed

+343
-94
lines changed

docs/DATAMODEL.md

Lines changed: 91 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,30 @@ interface MynahUIDataModel {
2828
* Chat screen loading animation state (mainly use during the stream or getting the initial answer)
2929
*/
3030
loadingChat?: boolean;
31+
/**
32+
* Show chat avatars or not
33+
* */
34+
showChatAvatars?: boolean;
3135
/**
3236
* Show cancel button while loading the chat
33-
* If you want to disable it globally, leave the onStopChatResponse on mynah ui constructor as undefined
3437
* */
3538
cancelButtonWhenLoading?: boolean;
3639
/**
3740
* Quick Action commands to show when user hits / to the input initially
3841
*/
3942
quickActionCommands?: QuickActionCommandGroup[];
4043
/**
44+
* Context commands to show when user hits @ to the input any point
45+
*/
46+
contextCommands?: QuickActionCommandGroup[];
47+
/**
4148
* Placeholder to be shown on prompt input
4249
*/
4350
promptInputPlaceholder?: string;
4451
/**
4552
* Info block to be shown under prompt input
4653
*/
47-
promptInputInfo?: string; // supports MARKDOWN string
54+
promptInputInfo?: string;
4855
/**
4956
* A sticky chat item card on top of the prompt input
5057
*/
@@ -218,7 +225,7 @@ mynahUI.updateStore('tab-1', {
218225
```
219226

220227
<p align="center">
221-
<img src="./img/data-model/tabStore/quickActionCommands.png" alt="mainTitle" style="max-width:500px; width:100%;border: 1px solid #e0e0e0;">
228+
<img src="./img/data-model/tabStore/quickActionCommands.png" alt="quickActionCommands" style="max-width:500px; width:100%;border: 1px solid #e0e0e0;">
222229
</p>
223230

224231
To handle the incoming command (if there is) check it with the prompt object in the `onChatPrompt` event.
@@ -246,6 +253,72 @@ const mynahUI = new MynahUI({
246253

247254
---
248255

256+
### `contextCommands` (default: `[]`)
257+
Context commands are the predefined context items which user can pick between but unlike quick action commands, they can be picked several times at any point in the prompt text. When users hit `@` from their keyboard in the input, if there is an available list of context items provided through store it will show up as an overlay menu.
258+
259+
260+
```typescript
261+
const mynahUI = new MynahUI({
262+
tabs: {
263+
'tab-1': {
264+
...
265+
}
266+
}
267+
});
268+
269+
mynahUI.updateStore('tab-1', {
270+
contextCommands: [
271+
{
272+
groupName: 'Metion code',
273+
commands:[
274+
{
275+
command: '@ws',
276+
description: '(BETA) Reference all code in workspace.'
277+
},
278+
{
279+
command: '@folder',
280+
placeholder: 'mention a specific folder',
281+
description: 'All files within a specific folder'
282+
},
283+
{
284+
command: '@file',
285+
placeholder: 'mention a specific file',
286+
description: 'Reference a specific file'
287+
},
288+
{
289+
command: '@code',
290+
placeholder: 'mention a specific file/folder, or leave blank for full project',
291+
description: 'After that mention a specific file/folder, or leave blank for full project'
292+
},
293+
{
294+
command: '@gitlab',
295+
description: 'Ask about data in gitlab account'
296+
}
297+
]
298+
}
299+
]
300+
})
301+
```
302+
303+
<p align="center">
304+
<img src="./img/data-model/tabStore/contextCommands.png" alt="contextCommands" style="max-width:500px; width:100%;border: 1px solid #e0e0e0;">
305+
</p>
306+
307+
To see which context is used, check the incoming array in the prompt object comes with the `onChatPrompt` event.
308+
309+
```typescript
310+
const mynahUI = new MynahUI({
311+
...
312+
onChatPrompt: (prompt)=>{
313+
if(prompt.context != null && prompt.context.indexOf('@ws') {
314+
// Use whole workspace!
315+
}
316+
}
317+
});
318+
```
319+
320+
---
321+
249322
### `promptInputPlaceholder` (default: `''`)
250323
251324
This is the placeholder text for the prompt input
@@ -1988,3 +2061,18 @@ mynahUI.notify({
19882061
<p align="center">
19892062
<img src="./img/data-model/chatItems/notification-4.png" alt="mainTitle" style="max-width:500px; width:100%;border: 1px solid #e0e0e0;">
19902063
</p>
2064+
2065+
2066+
---
2067+
2068+
## ChatPrompt
2069+
This is the object model which will be send along with the `onChatPrompt` event.
2070+
2071+
```typescript
2072+
export interface ChatPrompt {
2073+
prompt?: string;
2074+
escapedPrompt?: string; // Generally being used to send it back to mynah-ui for end user prompt rendering
2075+
command?: string;
2076+
context?: string[];
2077+
}
2078+
```

docs/PROPERTIES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ onChatPrompt?: (
364364
console.log(`Prompt text (as written): ${prompt.prompt}`);
365365
console.log(`Prompt text (HTML escaped): ${prompt.escapedPrompt}`);
366366
console.log(`Command (if selected from quick actions): ${prompt.command}`);
367+
console.log(`Context (if selected from context selector): ${(prompt.context??[]).join(', ')}`);
367368
console.log(`Attachment (feature not available yet): ${prompt.attachment}`);
368369
};
369370
...
Loading

example/src/config.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export const QuickActionCommands:QuickActionCommandGroup[] = [
101101
},
102102
],
103103
},
104-
];
104+
] as QuickActionCommandGroup[];
105105

106106
export const mynahUIDefaults = {
107107
store: {
@@ -117,6 +117,36 @@ export const mynahUIDefaults = {
117117
defaultFollowUps
118118
],
119119
quickActionCommands: QuickActionCommands,
120-
promptInputPlaceholder: 'Type something or "/" for quick action commands',
120+
contextCommands: [
121+
{
122+
groupName: 'Metion code',
123+
commands:[
124+
{
125+
command: '@ws',
126+
description: '(BETA) Reference all code in workspace.'
127+
},
128+
{
129+
command: '@folder',
130+
placeholder: 'mention a specific folder',
131+
description: 'All files within a specific folder'
132+
},
133+
{
134+
command: '@file',
135+
placeholder: 'mention a specific file',
136+
description: 'Reference a specific file'
137+
},
138+
{
139+
command: '@code',
140+
placeholder: 'mention a specific file/folder, or leave blank for full project',
141+
description: 'After that mention a specific file/folder, or leave blank for full project'
142+
},
143+
{
144+
command: '@gitlab',
145+
description: 'Ask about data in gitlab account'
146+
}
147+
]
148+
}
149+
] as QuickActionCommandGroup[],
150+
promptInputPlaceholder: 'Type something or "/" for quick action commands or @ for choosing context',
121151
}
122152
};

example/src/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ export const createMynahUI = (initialData?: MynahUIDataModel): MynahUI => {
143143
onChatPrompt: (tabId: string, prompt: ChatPrompt) => {
144144
Log(`New prompt on tab: <b>${tabId}</b><br/>
145145
prompt: <b>${prompt.prompt !== undefined && prompt.prompt !== '' ? prompt.prompt : '{command only}'}</b><br/>
146-
command: <b>${prompt.command ?? '{none}'}</b>`);
146+
command: <b>${prompt.command ?? '{none}'}</b><br/>
147+
context: <b>${(prompt.context??[]).join('</b>, <b>')}`);
147148
if (tabId === 'tab-1') {
148149
mynahUI.updateStore(tabId, {
149150
tabCloseConfirmationMessage: `Working on "${prompt.prompt}"`,

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@aws/mynah-ui",
33
"displayName": "AWS Mynah UI",
4-
"version": "4.11.2",
4+
"version": "4.12.0",
55
"description": "AWS Toolkit VSCode and Intellij IDE Extension Mynah UI",
66
"publisher": "Amazon Web Services",
77
"license": "Apache License 2.0",

0 commit comments

Comments
 (0)