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
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Feature",
"description": "Amazon Q chat: View and search chat history"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Feature",
"description": "Amazon Q chat: Automatically persist chats between IDE sessions"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Feature",
"description": "Amazon Q chat: Click share icon to export chat to Markdown or HTML"
}
2 changes: 2 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@
"@types/js-yaml": "^4.0.5",
"@types/jsdom": "^21.1.6",
"@types/lodash": "^4.14.180",
"@types/lokijs": "^1.5.14",
"@types/markdown-it": "^13.0.2",
"@types/mime-types": "^2.1.4",
"@types/mocha": "^10.0.6",
Expand Down Expand Up @@ -554,6 +555,7 @@
"js-yaml": "^4.1.0",
"jsonc-parser": "^3.2.0",
"lodash": "^4.17.21",
"lokijs": "^1.5.12",
Copy link
Contributor

@justinmk3 justinmk3 Mar 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this required? what alternatives were considered? are you confidence this package will be actively maintained?

is https://github.com/techfort/LokiJS/pulse the correct repo for it? no activity for 3 years.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes thats the correct repo, and based on my research its stable and widely used. its a pretty lightweight library with 500k+ weekly downloads https://www.npmjs.com/package/lokijs

LokiJS includes helpful functionality out of the box like autoload, autosave, finding elements, and updating elements, and was easy to use. Alternatives considered were better-sqlite3 and sqlite3 but those are not web-compatible

"markdown-it": "^13.0.2",
"mime-types": "^2.1.32",
"node-fetch": "^2.7.0",
Expand Down
82 changes: 81 additions & 1 deletion packages/core/src/amazonq/webview/ui/apps/baseConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { ChatItem, ChatItemAction, ChatItemType, FeedbackPayload, QuickActionCommand } from '@aws/mynah-ui'
import {
ChatItem,
ChatItemAction,
ChatItemType,
DetailedList,
FeedbackPayload,
QuickActionCommand,
} from '@aws/mynah-ui'
import { ExtensionMessage } from '../commands'
import { CodeReference } from './amazonqCommonsConnector'
import { TabOpenType, TabsStorage, TabType } from '../storages/tabsStorage'
import { FollowUpGenerator } from '../followUps/generator'
import { CWCChatItem } from '../connector'
import { DetailedListSheetProps } from '@aws/mynah-ui/dist/components/detailed-list/detailed-list-sheet'
import { DetailedListConnector, DetailedListType } from '../detailedList/detailedListConnector'

interface ChatPayload {
chatMessage: string
Expand All @@ -23,6 +32,15 @@ export interface BaseConnectorProps {
onError: (tabID: string, message: string, title: string) => void
onWarning: (tabID: string, message: string, title: string) => void
onOpenSettingsMessage: (tabID: string) => void
onNewTab: (tabType: TabType, chats?: ChatItem[]) => string | undefined
onOpenDetailedList: (data: DetailedListSheetProps) => {
update: (data: DetailedList) => void
close: () => void
changeTarget: (direction: 'up' | 'down', snapOnLastAndFirst?: boolean) => void
getTargetElementId: () => string | undefined
}
onSelectTab: (tabID: string, eventID: string) => void
onExportChat: (tabId: string, format: 'html' | 'markdown') => string
tabsStorage: TabsStorage
}

Expand All @@ -32,8 +50,13 @@ export abstract class BaseConnector {
protected readonly onWarning
protected readonly onChatAnswerReceived
protected readonly onOpenSettingsMessage
protected readonly onNewTab
protected readonly onOpenDetailedList
protected readonly onExportChat
protected readonly onSelectTab
protected readonly followUpGenerator: FollowUpGenerator
protected readonly tabsStorage
protected historyConnector

abstract getTabType(): TabType

Expand All @@ -43,8 +66,17 @@ export abstract class BaseConnector {
this.onWarning = props.onWarning
this.onError = props.onError
this.onOpenSettingsMessage = props.onOpenSettingsMessage
this.onNewTab = props.onNewTab
this.tabsStorage = props.tabsStorage
this.onOpenDetailedList = props.onOpenDetailedList
this.onExportChat = props.onExportChat
this.onSelectTab = props.onSelectTab
this.followUpGenerator = new FollowUpGenerator()
this.historyConnector = new DetailedListConnector(
DetailedListType.history,
this.sendMessageToExtension,
this.onOpenDetailedList
)
}

onResponseBodyLinkClick = (tabID: string, messageId: string, link: string): void => {
Expand Down Expand Up @@ -296,5 +328,53 @@ export abstract class BaseConnector {
await this.processOpenSettingsMessage(messageData)
return
}

if (messageData.type === 'restoreTabMessage') {
const newTabId = this.onNewTab(messageData.tabType, messageData.chats)
this.sendMessageToExtension({
command: 'tab-restored',
historyId: messageData.historyId,
newTabId,
tabType: this.getTabType(),
exportTab: messageData.exportTab,
})
return
}

if (messageData.type === 'updateDetailedListMessage') {
if (messageData.listType === DetailedListType.history) {
this.historyConnector.updateList(messageData.detailedList)
}
return
}

if (messageData.type === 'closeDetailedListMessage') {
if (messageData.listType === DetailedListType.history) {
this.historyConnector.closeList()
}
return
}

if (messageData.type === 'openDetailedListMessage') {
if (messageData.listType === DetailedListType.history) {
this.historyConnector.openList(messageData)
}
return
}

if (messageData.type === 'exportChatMessage') {
const serializedChat = this.onExportChat(messageData.tabID, messageData.format)
this.sendMessageToExtension({
command: 'save-chat',
uri: messageData.uri,
serializedChat,
tabType: 'cwc',
})
return
}

if (messageData.type === 'selectTabMessage') {
this.onSelectTab(messageData.tabID, messageData.eventID)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export interface ConnectorProps extends BaseConnectorProps {
onUpdatePromptProgress: (tabID: string, progressField: ProgressField) => void
onChatInputEnabled: (tabID: string, enabled: boolean) => void
onUpdateAuthentication: (featureDevEnabled: boolean, authenticatingTabIDs: string[]) => void
onNewTab: (tabType: TabType) => void
}

export class Connector extends BaseConnector {
Expand All @@ -32,7 +31,6 @@ export class Connector extends BaseConnector {
private readonly updatePlaceholder
private readonly chatInputEnabled
private readonly onUpdateAuthentication
private readonly onNewTab
private readonly updatePromptProgress

override getTabType(): TabType {
Expand All @@ -46,7 +44,6 @@ export class Connector extends BaseConnector {
this.updatePlaceholder = props.onUpdatePlaceholder
this.chatInputEnabled = props.onChatInputEnabled
this.onUpdateAuthentication = props.onUpdateAuthentication
this.onNewTab = props.onNewTab
this.updatePromptProgress = props.onUpdatePromptProgress
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export interface ConnectorProps extends BaseConnectorProps {
onUpdatePlaceholder: (tabID: string, newPlaceholder: string) => void
onChatInputEnabled: (tabID: string, enabled: boolean) => void
onUpdateAuthentication: (featureDevEnabled: boolean, authenticatingTabIDs: string[]) => void
onNewTab: (tabType: TabType) => void
}

export class Connector extends BaseConnector {
Expand All @@ -40,7 +39,6 @@ export class Connector extends BaseConnector {
private readonly updatePlaceholder
private readonly chatInputEnabled
private readonly onUpdateAuthentication
private readonly onNewTab

override getTabType(): TabType {
return 'featuredev'
Expand All @@ -53,7 +51,6 @@ export class Connector extends BaseConnector {
this.updatePlaceholder = props.onUpdatePlaceholder
this.chatInputEnabled = props.onChatInputEnabled
this.onUpdateAuthentication = props.onUpdateAuthentication
this.onNewTab = props.onNewTab
this.onChatAnswerUpdated = props.onChatAnswerUpdated
}

Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/amazonq/webview/ui/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,12 @@ type MessageCommand =
| 'update-welcome-count'
| 'quick-command-group-action-click'
| 'context-selected'
| 'tab-restored'
| 'tab-bar-button-clicked'
| 'export-chat'
| 'save-chat'
| 'detailed-list-filter-change'
| 'detailed-list-item-select'
| 'detailed-list-action-click'

export type ExtensionMessage = Record<string, any> & { command: MessageCommand }
23 changes: 22 additions & 1 deletion packages/core/src/amazonq/webview/ui/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
QuickActionCommand,
ChatItemFormItem,
ChatItemButton,
DetailedList,
} from '@aws/mynah-ui'
import { Connector as CWChatConnector } from './apps/cwChatConnector'
import { Connector as FeatureDevChatConnector } from './apps/featureDevChatConnector'
Expand All @@ -30,6 +31,7 @@ import { WelcomeFollowupType } from './apps/amazonqCommonsConnector'
import { AuthFollowUpType } from './followUps/generator'
import { DiffTreeFileInfo } from './diffTree/types'
import { UserIntent } from '@amzn/codewhisperer-streaming'
import { DetailedListSheetProps } from '@aws/mynah-ui/dist/components/detailed-list/detailed-list-sheet'

export interface CodeReference {
licenseName?: string
Expand Down Expand Up @@ -94,7 +96,7 @@ export interface ConnectorProps {
onUpdatePromptProgress: (tabID: string, progressField: ProgressField) => void
onChatInputEnabled: (tabID: string, enabled: boolean) => void
onUpdateAuthentication: (featureDevEnabled: boolean, authenticatingTabIDs: string[]) => void
onNewTab: (tabType: TabType) => void
onNewTab: (tabType: TabType, chats?: ChatItem[]) => string | undefined
onFileActionClick: (tabID: string, messageId: string, filePath: string, actionName: string) => void
handleCommand: (chatPrompt: ChatPrompt, tabId: string) => void
sendStaticMessages: (tabID: string, messages: ChatItem[]) => void
Expand All @@ -106,6 +108,14 @@ export interface ConnectorProps {
title?: string,
description?: string
) => void
onOpenDetailedList: (data: DetailedListSheetProps) => {
update: (data: DetailedList) => void
close: () => void
changeTarget: (direction: 'up' | 'down', snapOnLastAndFirst?: boolean) => void
getTargetElementId: () => string | undefined
}
onSelectTab: (tabID: string, eventID: string) => void
onExportChat: (tabID: string, format: 'markdown' | 'html') => string
tabsStorage: TabsStorage
}

Expand Down Expand Up @@ -291,6 +301,7 @@ export class Connector {
this.tabsStorage.updateTabLastCommand(messageData.tabID, '')
}

// Run when user opens new tab in UI
onTabAdd = (tabID: string): void => {
this.tabsStorage.addTab({
id: tabID,
Expand Down Expand Up @@ -684,6 +695,16 @@ export class Connector {
return false
}

onTabBarButtonClick = async (tabId: string, buttonId: string, eventId?: string) => {
this.sendMessageToExtension({
command: 'tab-bar-button-clicked',
buttonId,
type: '',
tabID: tabId,
tabType: 'cwc',
})
}

onCustomFormAction = (
tabId: string,
messageId: string | undefined,
Expand Down
Loading
Loading