Skip to content

feat: configure history button based on history enabled/disabled #957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 14, 2025
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
22 changes: 11 additions & 11 deletions chat-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ interface SomeEvent {

### Inbound events

| Name | Description | command | params |
| ----------------------- | -------------------------------------------------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| sendChatPrompt response | Provides response to sendChatPrompt request | `aws/chat/sendChatPrompt` | [ChatResult](https://github.com/aws/language-server-runtimes/blob/10e67de47600f20bf090ce8ec0ea318038a387f2/types/chat.ts#L77C18-L77C28) |
| openTab request | Request to open tab (creates tab if no `tabId` provided) | `aws/chat/openTab` | requestID - ID shared between the webview and vscode client, [OpenTabParams](https://github.com/aws/language-server-runtimes/blob/10e67de47600f20bf090ce8ec0ea318038a387f2/types/chat.ts#L200) |
| sendToPrompt | Request to send selection to prompt | `sendToPrompt` | [SendToPromptParams](https://github.com/aws/language-server-runtimes/blob/fe2669c34479d4925f2bdbe5527417ea8aed6c39/chat-client-ui-types/src/uiContracts.ts#L50C18-L50C36) |
| genericCommand | Request to execute generic command | `genericCommand` | [GenericCommandParams](https://github.com/aws/language-server-runtimes/blob/fe2669c34479d4925f2bdbe5527417ea8aed6c39/chat-client-ui-types/src/uiContracts.ts#L76) |
| errorMessage | Request to show error in chat UI | `errorMessage` | [ErrorParams](https://github.com/aws/language-server-runtimes/blob/fe2669c34479d4925f2bdbe5527417ea8aed6c39/chat-client-ui-types/src/uiContracts.ts#L88C18-L88C29) |
| chatOptions | Configures chat startup options | `chatOptions` | [ChatOptions](https://github.com/aws/language-server-runtimes/blob/main/types/chat.ts#L127) |
| Name | Description | command | params |
| ----------------------- | -------------------------------------------------------- | ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| sendChatPrompt response | Provides response to sendChatPrompt request | `aws/chat/sendChatPrompt` | [ChatResult](https://github.com/aws/language-server-runtimes/blob/10e67de47600f20bf090ce8ec0ea318038a387f2/types/chat.ts#L77C18-L77C28) |
| openTab request | Request to open tab (creates tab if no `tabId` provided) | `aws/chat/openTab` | requestID - ID shared between the webview and vscode client, [OpenTabParams](https://github.com/aws/language-server-runtimes/blob/10e67de47600f20bf090ce8ec0ea318038a387f2/types/chat.ts#L200) |
| sendToPrompt | Request to send selection to prompt | `sendToPrompt` | [SendToPromptParams](https://github.com/aws/language-server-runtimes/blob/fe2669c34479d4925f2bdbe5527417ea8aed6c39/chat-client-ui-types/src/uiContracts.ts#L50C18-L50C36) |
| genericCommand | Request to execute generic command | `genericCommand` | [GenericCommandParams](https://github.com/aws/language-server-runtimes/blob/fe2669c34479d4925f2bdbe5527417ea8aed6c39/chat-client-ui-types/src/uiContracts.ts#L76) |
| errorMessage | Request to show error in chat UI | `errorMessage` | [ErrorParams](https://github.com/aws/language-server-runtimes/blob/fe2669c34479d4925f2bdbe5527417ea8aed6c39/chat-client-ui-types/src/uiContracts.ts#L88C18-L88C29) |
| chatOptions | Configures chat startup options | `chatOptions` | [ChatOptions](https://github.com/aws/language-server-runtimes/blob/main/types/chat.ts#L127) |

### Outbound events

| Name | Description | command | params |
| ---------------------- | --------------------------------------------------------------------- | ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Name | Description | command | params |
| ---------------------- | --------------------------------------------------------------------- | ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| openTab response | Provides response to openTab request | `aws/chat/openTab` | requestID - ID shared between the webview and vscode client, [UiMessageResultParams](https://github.com/aws/language-server-runtimes/blob/10e67de47600f20bf090ce8ec0ea318038a387f2/chat-client-ui-types/src/uiContracts.ts#L129) with `result` of type [OpenTabResult](https://github.com/aws/language-server-runtimes/blob/main/types/chat.ts#L201) |
| disclaimerAcknowledged | Notifies destination that legal disclaimer was acknowlegded by a user | `disclaimerAcknowledged` | N/A |
| disclaimerAcknowledged | Notifies destination that legal disclaimer was acknowlegded by a user | `disclaimerAcknowledged` | N/A |

TODO: Provide full list of events

Expand Down
3 changes: 3 additions & 0 deletions chat-client/src/client/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ export const createChat = (
}))
tabFactory.updateQuickActionCommands(quickActionCommandGroups)
}
if (params?.history) {
tabFactory.enableHistory()
}

const allExistingTabs: MynahUITabStoreModel = mynahUi.getAllTabs()
for (const tabId in allExistingTabs) {
Expand Down
16 changes: 5 additions & 11 deletions chat-client/src/client/mynahUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import {
NotificationType,
MynahUIProps,
QuickActionCommand,
MynahIcons,
} from '@aws/mynah-ui'
import { VoteParams } from '../contracts/telemetry'
import { Messager } from './messager'
Expand Down Expand Up @@ -357,14 +356,6 @@ export const createMynahUi = (
config: {
maxTabs: 10,
texts: uiComponentsTexts,
// TODO: load dynamically from ChatOptions
tabBarButtons: [
{
id: ChatHistory.TabBarButtonId,
icon: MynahIcons.HISTORY,
description: 'View chat history',
},
],
},
}

Expand Down Expand Up @@ -588,14 +579,17 @@ ${params.message}`,
})
}

let chatHistoryList = new ChatHistoryList(mynahUi, messager)
const chatHistoryList = new ChatHistoryList(mynahUi, messager)
const listConversations = (params: ListConversationsResult) => {
chatHistoryList.show(params)
}

const conversationClicked = (params: ConversationClickResult) => {
if (!params.success) {
// TODO: any logging, error for this?
mynahUi.notify({
content: `Failed to ${params.action ?? 'open'} the history`,
type: NotificationType.ERROR,
})
return
}

Expand Down
63 changes: 63 additions & 0 deletions chat-client/src/client/tabs/tabFactory.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { ChatHistory } from '../features/history'
import { TabFactory } from './tabFactory'
import * as assert from 'assert'

describe('tabFactory', () => {
describe('getDefaultTabData', () => {
const defaultData = {
tabTitle: 'Chat',
promptInputInfo: 'Amazon Q Developer uses generative AI.',
tabBarButtons: [
{
id: '1',
},
],
}
it('returns default tab data if no updates', () => {
const tabFactory = new TabFactory(defaultData)
const result = tabFactory.getDefaultTabData()

assert.deepEqual(result, defaultData)
})

it('enabling history adds history tab bar button to default tab bar buttons', () => {
const tabFactory = new TabFactory(defaultData)
tabFactory.enableHistory()
const result = tabFactory.getDefaultTabData()

const expected = {
...defaultData,
tabBarButtons: [
...defaultData.tabBarButtons,
{
description: 'View chat history',
icon: 'history',
id: ChatHistory.TabBarButtonId,
},
],
}
assert.deepEqual(result, expected)
})

it('enabling history sets history tab bar button', () => {
const data = {
tabTitle: 'Chat',
}
const tabFactory = new TabFactory(data)
tabFactory.enableHistory()
const result = tabFactory.getDefaultTabData()

const expected = {
...data,
tabBarButtons: [
{
description: 'View chat history',
icon: 'history',
id: ChatHistory.TabBarButtonId,
},
],
}
assert.deepEqual(result, expected)
})
})
})
34 changes: 32 additions & 2 deletions chat-client/src/client/tabs/tabFactory.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import { ChatItem, ChatItemType, MynahUIDataModel, QuickActionCommandGroup } from '@aws/mynah-ui'
import {
ChatItem,
ChatItemType,
MynahIcons,
MynahUIDataModel,
QuickActionCommandGroup,
TabBarMainAction,
} from '@aws/mynah-ui'
import { disclaimerCard } from '../texts/disclaimer'
import { ChatMessage } from '@aws/language-server-runtimes-types'
import { ChatHistory } from '../features/history'

export type DefaultTabData = MynahUIDataModel

export class TabFactory {
private history: boolean = false

public static generateUniqueId() {
// from https://github.com/aws/mynah-ui/blob/a3799f47ca4b7c02850264e328539a40709a6858/src/helper/guid.ts#L6
const firstPart: number = (Math.random() * 46656) | 0
Expand Down Expand Up @@ -49,11 +59,18 @@ export class TabFactory {
this.quickActionCommands = [...(this.quickActionCommands ?? []), ...quickActionCommands]
}

public enableHistory() {
this.history = true
}

public getDefaultTabData(): DefaultTabData {
return {
const tabData = {
...this.defaultTabData,
...(this.quickActionCommands ? { quickActionCommands: this.quickActionCommands } : {}),
}

tabData.tabBarButtons = this.getTabBarButtons()
return tabData
}

private getWelcomeBlock() {
Expand All @@ -72,4 +89,17 @@ export class TabFactory {
],
}
}

private getTabBarButtons(): TabBarMainAction[] | undefined {
const historyButton = this.history
? {
id: ChatHistory.TabBarButtonId,
icon: MynahIcons.HISTORY,
description: 'View chat history',
}
: null

const tabBarButtons = [...(this.defaultTabData.tabBarButtons ?? []), ...(historyButton ? [historyButton] : [])]
return tabBarButtons.length ? tabBarButtons : undefined
}
}
Loading