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
14 changes: 11 additions & 3 deletions packages/amazonq/src/lsp/chat/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ import * as vscode from 'vscode'
import { Disposable, LanguageClient, Position, TextDocumentIdentifier } from 'vscode-languageclient'
import * as jose from 'jose'
import { AmazonQChatViewProvider } from './webviewProvider'
import { AuthUtil } from 'aws-core-vscode/codewhisperer'
import { AuthUtil, ReferenceLogViewProvider } from 'aws-core-vscode/codewhisperer'
import { amazonQDiffScheme, AmazonQPromptSettings, messages, openUrl } from 'aws-core-vscode/shared'
import {
DefaultAmazonQAppInitContext,
messageDispatcher,
EditorContentController,
ViewDiffMessage,
referenceLogText,
} from 'aws-core-vscode/amazonq'
import { telemetry, TelemetryBase } from 'aws-core-vscode/telemetry'
import { isValidResponseError } from './error'
Expand Down Expand Up @@ -531,26 +532,33 @@ async function handlePartialResult<T extends ChatResult>(
tabId: tabId,
})
}

for (const ref of decryptedMessage.codeReference ?? []) {
ReferenceLogViewProvider.instance.addReferenceLog(referenceLogText(ref))
}
}

/**
* Decodes the final chat responses from the language server before sending it to mynah UI.
* Once this is called the answer response is finished
*/
async function handleCompleteResult<T>(
async function handleCompleteResult<T extends ChatResult>(
result: string | T,
encryptionKey: Buffer | undefined,
provider: AmazonQChatViewProvider,
tabId: string,
disposable: Disposable
) {
const decryptedMessage =
typeof result === 'string' && encryptionKey ? await decodeRequest(result, encryptionKey) : result
typeof result === 'string' && encryptionKey ? await decodeRequest<T>(result, encryptionKey) : (result as T)
void provider.webview?.postMessage({
command: chatRequestType.method,
params: decryptedMessage,
tabId: tabId,
})
for (const ref of decryptedMessage.codeReference ?? []) {
ReferenceLogViewProvider.instance.addReferenceLog(referenceLogText(ref))
}
disposable.dispose()
}

Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/amazonq/commons/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { LicenseUtil } from '../../codewhisperer/util/licenseUtil'
import { CodeReference } from '../../codewhispererChat/view/connector/connector'

// Currently importing ChatItemType in Mynah UI from the vscode side causes an error
// TODO remove this once the import stops failing
export type ChatItemType =
Expand All @@ -13,3 +16,10 @@ export type ChatItemType =
| 'answer-stream'
| 'answer-part'
| 'code-result'

export const referenceLogText = (reference: CodeReference) =>
`[${new Date().toLocaleString()}] Accepted recommendation from Amazon Q. Code provided with reference under <a href="${LicenseUtil.getLicenseHtml(
reference.licenseName
)}" target="_blank">${reference.licenseName}</a> license from repository <a href="${
reference.url
}" target="_blank">${reference.repository}</a>.<br><br>`
2 changes: 1 addition & 1 deletion packages/core/src/amazonq/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export {
computeDiff,
} from './commons/diff'
export { AuthFollowUpType, AuthMessageDataMap } from './auth/model'
export { ChatItemType } from './commons/model'
export { ChatItemType, referenceLogText } from './commons/model'
export { ExtensionMessage } from '../amazonq/webview/ui/commands'
export { CodeReference } from '../codewhispererChat/view/connector/connector'
export { extractAuthFollowUp } from './util/authUtils'
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/amazonqDoc/session/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { TelemetryHelper } from '../../amazonq/util/telemetryHelper'
import { ConversationNotStartedState } from '../../amazonqFeatureDev/session/sessionState'
import { logWithConversationId } from '../../amazonqFeatureDev/userFacingText'
import { ConversationIdNotFoundError, IllegalStateError } from '../../amazonqFeatureDev/errors'
import { referenceLogText } from '../../amazonqFeatureDev/constants'
import { referenceLogText } from '../../amazonq/commons/model'
import {
DocInteractionType,
DocV2AcceptanceEvent,
Expand Down
8 changes: 0 additions & 8 deletions packages/core/src/amazonqFeatureDev/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ export const clientErrorMessages = [
'The folder you chose did not contain any source files in a supported language. Choose another folder and try again.',
]

// License text that's used in codewhisperer reference log
export const referenceLogText = (reference: CodeReference) =>
`[${new Date().toLocaleString()}] Accepted recommendation from Amazon Q. Code provided with reference under <a href="${LicenseUtil.getLicenseHtml(
reference.licenseName
)}" target="_blank">${reference.licenseName}</a> license from repository <a href="${
reference.url
}" target="_blank">${reference.repository}</a>.<br><br>`

// License text that's used in the file view
export const licenseText = (reference: CodeReference) =>
`<a href="${LicenseUtil.getLicenseHtml(reference.licenseName)}" target="_blank">${
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/amazonqFeatureDev/session/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
UpdateFilesPathsParams,
} from '../../amazonq/commons/types'
import { ContentLengthError, ConversationIdNotFoundError, IllegalStateError } from '../errors'
import { featureDevChat, referenceLogText, featureDevScheme } from '../constants'
import { featureDevChat, featureDevScheme } from '../constants'
import fs from '../../shared/fs/fs'
import { FeatureDevClient } from '../client/featureDev'
import { codeGenRetryLimit } from '../limits'
Expand All @@ -34,6 +34,8 @@ import { FollowUpTypes } from '../../amazonq/commons/types'
import { SessionConfig } from '../../amazonq/commons/session/sessionConfigFactory'
import { Messenger } from '../../amazonq/commons/connector/baseMessenger'
import { ContentLengthError as CommonContentLengthError } from '../../shared/errors'
import { referenceLogText } from '../../amazonq/commons/model'

export class Session {
private _state?: SessionState | Omit<SessionState, 'uploadId'>
private task: string = ''
Expand Down
Loading