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
63 changes: 55 additions & 8 deletions chat-client/src/client/chat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
import { MynahUI } from '@aws/mynah-ui'
import { TabFactory } from './tabs/tabFactory'
import { ChatClientAdapter } from '../contracts/chatClientAdapter'
import { deprecationCard } from './texts/deprecation'

describe('Chat', () => {
const sandbox = sinon.createSandbox()
Expand Down Expand Up @@ -74,11 +75,8 @@ describe('Chat', () => {
window.removeEventListener('message', messageHandler as EventListener)
messageHandler = undefined
}
mynahUi.destroy()
sandbox.restore()

Object.keys(mynahUi.getAllTabs()).forEach(tabId => {
mynahUi.removeTab(tabId, (mynahUi as any).lastEventId)
})
})

after(() => {
Expand Down Expand Up @@ -117,6 +115,19 @@ describe('Chat', () => {
})
})

it('hides the deprecation notice when it was previously acknowledged', () => {
mynahUi.destroy()
mynahUi = createChat(clientApi, {
agenticMode: true,
deprecationNoticeAcknowledged: true,
})

const tabId = mynahUi.getSelectedTabId()
const chatItems = tabId ? mynahUi.getTabData(tabId).getStore()?.chatItems : undefined

assert.match(chatItems?.some(item => item.messageId === deprecationCard.messageId) ?? false, false)
})

it('publishes telemetry event, when send to prompt is triggered', () => {
const eventParams = { command: SEND_TO_PROMPT, params: { prompt: 'hey' } }
const sendToPromptEvent = createInboundEvent(eventParams)
Expand Down Expand Up @@ -397,6 +408,33 @@ describe('Chat', () => {
})

describe('chatOptions', () => {
it('preserves the deprecation notice presentation when chat notifications are added', () => {
const chatOptionsRequest = createInboundEvent({
command: CHAT_OPTIONS,
params: {
chatNotifications: [
{
messageId: 'server-notification',
type: 'answer',
body: 'Server notification',
},
],
},
})

window.dispatchEvent(chatOptionsRequest)

const chatItems = mynahUi.getTabData(initialTabId).getStore()?.chatItems
const notice = chatItems?.find(item => item.messageId === deprecationCard.messageId)

assert.match(chatItems?.[0].messageId, 'server-notification')
assert.match(notice?.title, deprecationCard.title)
assert.match(notice?.status, deprecationCard.status)
assert.match(notice?.border, deprecationCard.border)
assert.match(notice?.fullWidth, deprecationCard.fullWidth)
assert.match(notice?.canBeDismissed, deprecationCard.canBeDismissed)
})

it('enables history and export features support', () => {
const chatOptionsRequest = createInboundEvent({
command: CHAT_OPTIONS,
Expand Down Expand Up @@ -432,6 +470,7 @@ describe('Chat', () => {
it('enables MCP when params.mcpServers is true and config.agenticMode is true', function () {
// Create a separate sandbox for this test
const testSandbox = sinon.createSandbox()
let localMynahUi: MynahUI | undefined

// Save original window functions
const originalAddEventListener = window.addEventListener
Expand All @@ -452,7 +491,7 @@ describe('Chat', () => {
}

// Create a new chat instance specifically for this test
const localMynahUi = createChat(localClientApi, { agenticMode: true })
localMynahUi = createChat(localClientApi, { agenticMode: true })

// Create a new event
const chatOptionsRequest = createInboundEvent({
Expand All @@ -474,13 +513,15 @@ describe('Chat', () => {
// Restore window functions
window.addEventListener = originalAddEventListener
window.dispatchEvent = originalDispatchEvent
localMynahUi?.destroy()
testSandbox.restore()
}
})

it('does not enable MCP when params.mcpServers is true but config.agenticMode is false', function () {
// Create a separate sandbox for this test
const testSandbox = sinon.createSandbox()
let localMynahUi: MynahUI | undefined

// Save original window functions
const originalAddEventListener = window.addEventListener
Expand All @@ -501,7 +542,7 @@ describe('Chat', () => {
}

// Create a new chat instance specifically for this test
const localMynahUi = createChat(localClientApi, { agenticMode: false })
localMynahUi = createChat(localClientApi, { agenticMode: false })

// Create a new event
const chatOptionsRequest = createInboundEvent({
Expand All @@ -523,13 +564,15 @@ describe('Chat', () => {
// Restore window functions
window.addEventListener = originalAddEventListener
window.dispatchEvent = originalDispatchEvent
localMynahUi?.destroy()
testSandbox.restore()
}
})

it('does not enable MCP when params.mcpServers is false and config.agenticMode is true', function () {
// Create a separate sandbox for this test
const testSandbox = sinon.createSandbox()
let localMynahUi: MynahUI | undefined

// Save original window functions
const originalAddEventListener = window.addEventListener
Expand All @@ -550,7 +593,7 @@ describe('Chat', () => {
}

// Create a new chat instance specifically for this test
const localMynahUi = createChat(localClientApi, { agenticMode: true })
localMynahUi = createChat(localClientApi, { agenticMode: true })

// Create a new event
const chatOptionsRequest = createInboundEvent({
Expand All @@ -572,13 +615,15 @@ describe('Chat', () => {
// Restore window functions
window.addEventListener = originalAddEventListener
window.dispatchEvent = originalDispatchEvent
localMynahUi?.destroy()
testSandbox.restore()
}
})

it('does not enable MCP when params.mcpServers is undefined and config.agenticMode is true', function () {
// Create a separate sandbox for this test
const testSandbox = sinon.createSandbox()
let localMynahUi: MynahUI | undefined

// Save original window functions
const originalAddEventListener = window.addEventListener
Expand All @@ -599,7 +644,7 @@ describe('Chat', () => {
}

// Create a new chat instance specifically for this test
const localMynahUi = createChat(localClientApi, { agenticMode: true })
localMynahUi = createChat(localClientApi, { agenticMode: true })

// Create a new event
const chatOptionsRequest = createInboundEvent({
Expand All @@ -620,6 +665,7 @@ describe('Chat', () => {
// Restore window functions
window.addEventListener = originalAddEventListener
window.dispatchEvent = originalDispatchEvent
localMynahUi?.destroy()
testSandbox.restore()
}
})
Expand Down Expand Up @@ -675,6 +721,7 @@ describe('Chat', () => {
handleMessageReceive: handleMessageReceiveStub,
isSupportedTab: () => false,
}
mynahUi.destroy()
mynahUi = createChat(
clientApi,
{
Expand Down
7 changes: 4 additions & 3 deletions chat-client/src/client/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import {
CONTEXT_COMMAND_NOTIFICATION_METHOD,
CONVERSATION_CLICK_REQUEST_METHOD,
CREATE_PROMPT_NOTIFICATION_METHOD,
ChatMessage,
ChatOptionsUpdateParams,
ChatParams,
ChatUpdateParams,
Expand Down Expand Up @@ -129,7 +128,9 @@ const getDefaultTabConfig = (agenticMode?: boolean) => {

type ChatClientConfig = Pick<MynahUIDataModel, 'quickActionCommands'> & {
disclaimerAcknowledged?: boolean
// Retained for compatibility with clients that still send the former feature-card state.
pairProgrammingAcknowledged?: boolean
deprecationNoticeAcknowledged?: boolean
agenticMode?: boolean
modelSelectionEnabled?: boolean
stringOverrides?: Partial<ConfigTexts>
Expand Down Expand Up @@ -368,7 +369,7 @@ export const createChat = (
// that tab does not have banner message, which arrives in ChatOptions above.
const store = mynahUi.getTabData(tabFactory.initialTabId)?.getStore() || {}
const chatItems = store.chatItems || []
const updatedInitialItems = tabFactory.getChatItems(false, false, chatItems as ChatMessage[])
const updatedInitialItems = [...tabFactory.getChatItems(false, false), ...chatItems]

// First clear the tab, so that messages are not appended https://github.com/aws/mynah-ui/blob/38608dff905b3790d85c73e2911ec7071c8a8cdf/docs/USAGE.md#using-updatestore-function
mynahUi.updateStore(tabFactory.initialTabId, {
Expand Down Expand Up @@ -585,7 +586,7 @@ export const createChat = (
messager,
tabFactory,
config?.disclaimerAcknowledged ?? false,
config?.pairProgrammingAcknowledged ?? false,
config?.deprecationNoticeAcknowledged ?? false,
chatClientAdapter,
featureConfig,
!!config?.agenticMode,
Expand Down
Loading
Loading