-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge main into feature/q-inlinechat
- Loading branch information
Showing
163 changed files
with
13,016 additions
and
901 deletions.
There are no files selected for viewing
4 changes: 0 additions & 4 deletions
4
.changes/next-release/.changes/next-release/bugfix-21701bb3-5189-474e-868b-9ec46ecde6ee.json
This file was deleted.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
.changes/next-release/feature-44636712-ede6-4e2a-b4d6-ca2b98da003d.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"type" : "feature", | ||
"description" : "`/review` in Q chat to scan your code for vulnerabilities and quality issues, and generate fixes" | ||
} |
4 changes: 4 additions & 0 deletions
4
.changes/next-release/feature-5c2fae3e-c794-438b-8af5-2c31c00ab000.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"type" : "feature", | ||
"description" : "`/test` in Q chat to generate unit tests for java and python" | ||
} |
4 changes: 4 additions & 0 deletions
4
.changes/next-release/feature-8fc6f4c9-6976-4a4a-88f0-bd4e6081a4b9.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"type" : "feature", | ||
"description" : "`/doc` in Q chat to generate and update documentation for your project" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,4 @@ | |
<RunAsTest>false</RunAsTest> | ||
<method v="2" /> | ||
</configuration> | ||
</component> | ||
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
...community/src/software/aws/toolkits/jetbrains/common/clients/AmazonQCodeGenerateClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
// Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package software.aws.toolkits.jetbrains.common.clients | ||
|
||
import com.intellij.openapi.components.Service | ||
import com.intellij.openapi.components.service | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.util.SystemInfo | ||
import software.amazon.awssdk.services.codewhispererruntime.CodeWhispererRuntimeClient | ||
import software.amazon.awssdk.services.codewhispererruntime.model.ArtifactType | ||
import software.amazon.awssdk.services.codewhispererruntime.model.ContentChecksumType | ||
import software.amazon.awssdk.services.codewhispererruntime.model.CreateTaskAssistConversationRequest | ||
import software.amazon.awssdk.services.codewhispererruntime.model.CreateTaskAssistConversationResponse | ||
import software.amazon.awssdk.services.codewhispererruntime.model.CreateUploadUrlResponse | ||
import software.amazon.awssdk.services.codewhispererruntime.model.DocGenerationEvent | ||
import software.amazon.awssdk.services.codewhispererruntime.model.GetTaskAssistCodeGenerationResponse | ||
import software.amazon.awssdk.services.codewhispererruntime.model.IdeCategory | ||
import software.amazon.awssdk.services.codewhispererruntime.model.OperatingSystem | ||
import software.amazon.awssdk.services.codewhispererruntime.model.OptOutPreference | ||
import software.amazon.awssdk.services.codewhispererruntime.model.SendTelemetryEventResponse | ||
import software.amazon.awssdk.services.codewhispererruntime.model.StartTaskAssistCodeGenerationResponse | ||
import software.amazon.awssdk.services.codewhispererruntime.model.TaskAssistPlanningUploadContext | ||
import software.amazon.awssdk.services.codewhispererruntime.model.UploadContext | ||
import software.amazon.awssdk.services.codewhispererruntime.model.UploadIntent | ||
import software.amazon.awssdk.services.codewhispererruntime.model.UserContext | ||
import software.amazon.awssdk.services.codewhispererstreaming.model.ExportIntent | ||
import software.aws.toolkits.core.utils.error | ||
import software.aws.toolkits.core.utils.getLogger | ||
import software.aws.toolkits.core.utils.info | ||
import software.aws.toolkits.jetbrains.common.session.Intent | ||
import software.aws.toolkits.jetbrains.core.awsClient | ||
import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnectionManager | ||
import software.aws.toolkits.jetbrains.core.credentials.pinning.QConnection | ||
import software.aws.toolkits.jetbrains.services.amazonq.clients.AmazonQStreamingClient | ||
import software.aws.toolkits.jetbrains.services.amazonqDoc.FEATURE_EVALUATION_PRODUCT_NAME | ||
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.calculateTotalLatency | ||
import software.aws.toolkits.jetbrains.services.telemetry.ClientMetadata | ||
import software.aws.toolkits.jetbrains.settings.AwsSettings | ||
import java.time.Instant | ||
import software.amazon.awssdk.services.codewhispererruntime.model.ChatTriggerType as SyncChatTriggerType | ||
|
||
@Service(Service.Level.PROJECT) | ||
class AmazonQCodeGenerateClient(private val project: Project) { | ||
private fun getTelemetryOptOutPreference() = | ||
if (AwsSettings.getInstance().isTelemetryEnabled) { | ||
OptOutPreference.OPTIN | ||
} else { | ||
OptOutPreference.OPTOUT | ||
} | ||
|
||
private val docGenerationUserContext = ClientMetadata.getDefault().let { | ||
val osForFeatureDev: OperatingSystem = | ||
when { | ||
SystemInfo.isWindows -> OperatingSystem.WINDOWS | ||
SystemInfo.isMac -> OperatingSystem.MAC | ||
// For now, categorize everything else as "Linux" (Linux/FreeBSD/Solaris/etc.) | ||
else -> OperatingSystem.LINUX | ||
} | ||
|
||
UserContext.builder() | ||
.ideCategory(IdeCategory.JETBRAINS) | ||
.operatingSystem(osForFeatureDev) | ||
.product(FEATURE_EVALUATION_PRODUCT_NAME) | ||
.clientId(it.clientId) | ||
.ideVersion(it.awsVersion) | ||
.build() | ||
} | ||
|
||
fun connection() = ToolkitConnectionManager.getInstance(project).activeConnectionForFeature(QConnection.getInstance()) | ||
?: error("Attempted to use connection while one does not exist") | ||
|
||
fun bearerClient() = connection().getConnectionSettings().awsClient<CodeWhispererRuntimeClient>() | ||
|
||
private val amazonQStreamingClient | ||
get() = AmazonQStreamingClient.getInstance(project) | ||
|
||
fun sendDocGenerationTelemetryEvent( | ||
docGenerationEvent: DocGenerationEvent, | ||
): SendTelemetryEventResponse = | ||
bearerClient().sendTelemetryEvent { requestBuilder -> | ||
requestBuilder.telemetryEvent { telemetryEventBuilder -> | ||
telemetryEventBuilder.docGenerationEvent(docGenerationEvent) | ||
} | ||
requestBuilder.optOutPreference(getTelemetryOptOutPreference()) | ||
requestBuilder.userContext(docGenerationUserContext) | ||
} | ||
|
||
fun createTaskAssistConversation(): CreateTaskAssistConversationResponse = bearerClient().createTaskAssistConversation( | ||
CreateTaskAssistConversationRequest.builder().build() | ||
) | ||
|
||
fun createTaskAssistUploadUrl(conversationId: String, contentChecksumSha256: String, contentLength: Long): CreateUploadUrlResponse = | ||
bearerClient().createUploadUrl { | ||
it.contentChecksumType(ContentChecksumType.SHA_256) | ||
.contentChecksum(contentChecksumSha256) | ||
.contentLength(contentLength) | ||
.artifactType(ArtifactType.SOURCE_CODE) | ||
.uploadIntent(UploadIntent.TASK_ASSIST_PLANNING) | ||
.uploadContext( | ||
UploadContext.builder() | ||
.taskAssistPlanningUploadContext( | ||
TaskAssistPlanningUploadContext.builder() | ||
.conversationId(conversationId) | ||
.build() | ||
) | ||
.build() | ||
) | ||
} | ||
|
||
fun startTaskAssistCodeGeneration(conversationId: String, uploadId: String, userMessage: String, intent: Intent): StartTaskAssistCodeGenerationResponse = | ||
bearerClient() | ||
.startTaskAssistCodeGeneration { request -> | ||
request | ||
.conversationState { | ||
it | ||
.conversationId(conversationId) | ||
.chatTriggerType(SyncChatTriggerType.MANUAL) | ||
.currentMessage { cm -> cm.userInputMessage { um -> um.content(userMessage) } } | ||
} | ||
.workspaceState { | ||
it | ||
.programmingLanguage { pl -> pl.languageName("javascript") } | ||
.uploadId(uploadId) | ||
} | ||
.intent(intent.name) | ||
} | ||
|
||
fun getTaskAssistCodeGeneration(conversationId: String, codeGenerationId: String): GetTaskAssistCodeGenerationResponse = bearerClient() | ||
.getTaskAssistCodeGeneration { | ||
it | ||
.conversationId(conversationId) | ||
.codeGenerationId(codeGenerationId) | ||
} | ||
|
||
suspend fun exportTaskAssistResultArchive(conversationId: String): MutableList<ByteArray> = amazonQStreamingClient.exportResultArchive( | ||
conversationId, | ||
ExportIntent.TASK_ASSIST, | ||
null, | ||
{ e -> | ||
LOG.error(e) { "TaskAssist - ExportResultArchive stream exportId=$conversationId exportIntent=${ExportIntent.TASK_ASSIST} Failed: ${e.message} " } | ||
}, | ||
{ startTime -> | ||
LOG.info { "TaskAssist - ExportResultArchive latency: ${calculateTotalLatency(startTime, Instant.now())}" } | ||
} | ||
) | ||
|
||
companion object { | ||
private val LOG = getLogger<AmazonQCodeGenerateClient>() | ||
|
||
fun getInstance(project: Project) = project.service<AmazonQCodeGenerateClient>() | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...mmunity/src/software/aws/toolkits/jetbrains/common/session/ConversationNotStartedState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package software.aws.toolkits.jetbrains.common.session | ||
|
||
import software.aws.toolkits.jetbrains.services.amazonqDoc.session.SessionStateInteraction | ||
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.SessionStateAction | ||
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.SessionStatePhase | ||
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.util.CancellationTokenSource | ||
|
||
class ConversationNotStartedState( | ||
override var approach: String, | ||
override val tabID: String, | ||
override var token: CancellationTokenSource?, | ||
) : SessionState { | ||
override val phase = SessionStatePhase.INIT | ||
|
||
override suspend fun interact(action: SessionStateAction): SessionStateInteraction<SessionState> { | ||
error("Illegal transition between states, restart the conversation") | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...at/jetbrains-community/src/software/aws/toolkits/jetbrains/common/session/SessionState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package software.aws.toolkits.jetbrains.common.session | ||
|
||
import software.aws.toolkits.jetbrains.services.amazonqDoc.session.SessionStateInteraction | ||
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.SessionStateAction | ||
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.SessionStatePhase | ||
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.util.CancellationTokenSource | ||
|
||
interface SessionState { | ||
val tabID: String | ||
val phase: SessionStatePhase? | ||
var token: CancellationTokenSource? | ||
var approach: String | ||
suspend fun interact(action: SessionStateAction): SessionStateInteraction<SessionState> | ||
} |
24 changes: 24 additions & 0 deletions
24
...tbrains-community/src/software/aws/toolkits/jetbrains/common/session/SessionStateTypes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package software.aws.toolkits.jetbrains.common.session | ||
|
||
import software.aws.toolkits.jetbrains.common.util.AmazonQCodeGenService | ||
import software.aws.toolkits.jetbrains.services.amazonq.FeatureDevSessionContext | ||
|
||
open class SessionStateConfig( | ||
open val conversationId: String, | ||
open val repoContext: FeatureDevSessionContext, | ||
open val amazonQCodeGenService: AmazonQCodeGenService, | ||
) | ||
|
||
data class SessionStateConfigData( | ||
override val conversationId: String, | ||
override val repoContext: FeatureDevSessionContext, | ||
override val amazonQCodeGenService: AmazonQCodeGenService, | ||
) : SessionStateConfig(conversationId, repoContext, amazonQCodeGenService) | ||
|
||
enum class Intent { | ||
DEV, | ||
DOC, | ||
} |
Oops, something went wrong.