Skip to content
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

Code block user intent #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 8 additions & 2 deletions packages/core/src/amazonq/webview/ui/apps/cwChatConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ export class Connector {
codeReference?: CodeReference[],
eventId?: string,
codeBlockIndex?: number,
totalCodeBlocks?: number
totalCodeBlocks?: number,
userIntent?: string
): void => {
this.sendMessageToExtension({
tabID: tabID,
Expand All @@ -113,6 +114,7 @@ export class Connector {
eventId,
codeBlockIndex,
totalCodeBlocks,
userIntent,
})
}

Expand All @@ -124,7 +126,8 @@ export class Connector {
codeReference?: CodeReference[],
eventId?: string,
codeBlockIndex?: number,
totalCodeBlocks?: number
totalCodeBlocks?: number,
userIntent?: string
): void => {
this.sendMessageToExtension({
tabID: tabID,
Expand All @@ -137,6 +140,7 @@ export class Connector {
eventId,
codeBlockIndex,
totalCodeBlocks,
userIntent,
})
}

Expand Down Expand Up @@ -269,6 +273,7 @@ export class Connector {
canBeVoted: true,
codeReference: messageData.codeReference,
traceId: messageData.traceId,
userIntent: messageData.userIntent,
}

// If it is not there we will not set it
Expand Down Expand Up @@ -309,6 +314,7 @@ export class Connector {
}
: undefined,
traceId: messageData.traceId,
userIntent: messageData.userIntent,
}
this.onChatAnswerReceived(messageData.tabID, answer)

Expand Down
14 changes: 10 additions & 4 deletions packages/core/src/amazonq/webview/ui/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { TabType, TabsStorage } from './storages/tabsStorage'
import { WelcomeFollowupType } from './apps/amazonqCommonsConnector'
import { AuthFollowUpType } from './followUps/generator'
import { DiffTreeFileInfo } from './diffTree/types'
import { UserIntent } from '@amzn/codewhisperer-streaming'

export interface CodeReference {
licenseName?: string
Expand All @@ -32,6 +33,7 @@ export interface ChatPayload {

export interface TracedChatItem extends ChatItem {
traceId?: string
userIntent?: UserIntent
}

export interface ConnectorProps {
Expand Down Expand Up @@ -219,7 +221,8 @@ export class Connector {
codeReference?: CodeReference[],
eventId?: string,
codeBlockIndex?: number,
totalCodeBlocks?: number
totalCodeBlocks?: number,
userIntent?: string
): void => {
switch (this.tabsStorage.getTab(tabID)?.type) {
case 'cwc':
Expand All @@ -231,7 +234,8 @@ export class Connector {
codeReference,
eventId,
codeBlockIndex,
totalCodeBlocks
totalCodeBlocks,
userIntent
)
break
case 'featuredev':
Expand All @@ -248,7 +252,8 @@ export class Connector {
codeReference?: CodeReference[],
eventId?: string,
codeBlockIndex?: number,
totalCodeBlocks?: number
totalCodeBlocks?: number,
userIntent?: string
): void => {
switch (this.tabsStorage.getTab(tabID)?.type) {
case 'cwc':
Expand All @@ -260,7 +265,8 @@ export class Connector {
codeReference,
eventId,
codeBlockIndex,
totalCodeBlocks
totalCodeBlocks,
userIntent
)
break
case 'featuredev':
Expand Down
31 changes: 29 additions & 2 deletions packages/core/src/amazonq/webview/ui/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export const createMynahUI = (ideApi: any, amazonQEnabled: boolean) => {
// eslint-disable-next-line prefer-const
let connector: Connector

const messageUserIntentMap = new Map<string, string>()

window.addEventListener('error', (e) => {
const { error, message } = e
ideApi.postMessage({
Expand Down Expand Up @@ -201,6 +203,9 @@ export const createMynahUI = (ideApi: any, amazonQEnabled: boolean) => {
? { type: ChatItemType.CODE_RESULT, fileList: item.fileList }
: {}),
})
if (item.messageId !== undefined && item.userIntent !== undefined) {
messageUserIntentMap.set(item.messageId, item.userIntent)
}
return
}

Expand Down Expand Up @@ -429,7 +434,28 @@ export const createMynahUI = (ideApi: any, amazonQEnabled: boolean) => {
content: 'Thanks for your feedback.',
})
},
onCodeInsertToCursorPosition: connector.onCodeInsertToCursorPosition,
onCodeInsertToCursorPosition: (
tabId,
messageId,
code,
type,
referenceTrackerInfo,
eventId,
codeBlockIndex,
totalCodeBlocks
) => {
connector.onCodeInsertToCursorPosition(
tabId,
messageId,
code,
type,
referenceTrackerInfo,
eventId,
codeBlockIndex,
totalCodeBlocks,
messageUserIntentMap.get(messageId) ?? undefined
)
},
onCopyCodeToClipboard: (
tabId,
messageId,
Expand All @@ -448,7 +474,8 @@ export const createMynahUI = (ideApi: any, amazonQEnabled: boolean) => {
referenceTrackerInfo,
eventId,
codeBlockIndex,
totalCodeBlocks
totalCodeBlocks,
messageUserIntentMap.get(messageId) ?? undefined
)
mynahUI.notify({
type: NotificationType.SUCCESS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class Messenger {
relatedSuggestions: undefined,
triggerID,
messageID: '',
userIntent: undefined,
},
tabID
)
Expand Down Expand Up @@ -184,6 +185,7 @@ export class Messenger {
codeReference,
triggerID,
messageID,
userIntent: triggerPayload.userIntent,
},
tabID
)
Expand Down Expand Up @@ -260,6 +262,7 @@ export class Messenger {
relatedSuggestions: undefined,
triggerID,
messageID,
userIntent: triggerPayload.userIntent,
},
tabID
)
Expand All @@ -277,6 +280,7 @@ export class Messenger {
relatedSuggestions,
triggerID,
messageID,
userIntent: triggerPayload.userIntent,
},
tabID
)
Expand All @@ -294,6 +298,7 @@ export class Messenger {
triggerID,
messageID,
traceId: triggerPayload.traceId,
userIntent: triggerPayload.userIntent,
},
tabID
)
Expand Down Expand Up @@ -417,6 +422,7 @@ export class Messenger {
relatedSuggestions: undefined,
triggerID,
messageID: 'static_message_' + triggerID,
userIntent: undefined,
},
tabID
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export interface ChatMessageProps {
readonly codeReference?: CodeReference[]
readonly triggerID: string
readonly messageID: string
readonly userIntent: string | undefined
readonly traceId?: string
}

Expand All @@ -155,6 +156,7 @@ export class ChatMessage extends UiMessage {
readonly triggerID: string
readonly messageID: string | undefined
readonly traceId?: string
readonly userIntent: string | undefined
override type = 'chatMessage'

constructor(props: ChatMessageProps, tabID: string) {
Expand All @@ -168,6 +170,7 @@ export class ChatMessage extends UiMessage {
this.triggerID = props.triggerID
this.messageID = props.messageID
this.traceId = props.traceId
this.userIntent = props.userIntent
}
}

Expand Down