Skip to content
Merged
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
28 changes: 16 additions & 12 deletions packages/core/src/amazonqFeatureDev/client/featureDev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,17 @@ import { createCodeWhispererChatStreamingClient } from '../../shared/clients/cod
import { getClientId, getOptOutPreference, getOperatingSystem } from '../../shared/telemetry/util'
import { extensionVersion } from '../../shared/vscode/env'

// Re-enable once BE is able to handle retries.
const writeAPIRetryOptions = {
maxRetries: 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

this is still at zero, so what effect does this PR have?

Copy link
Contributor Author

@chengoramazon chengoramazon Oct 2, 2024

Choose a reason for hiding this comment

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

It ensure Read APIs using default 3 retries. We don't handle write retries at this moment, but we would support it in the future.

retryDelayOptions: {
// The default number of milliseconds to use in the exponential backoff
base: 500,
},
}

// Create a client for featureDev proxy client based off of aws sdk v2
export async function createFeatureDevProxyClient(): Promise<FeatureDevProxyClient> {
export async function createFeatureDevProxyClient(options?: Partial<ServiceOptions>): Promise<FeatureDevProxyClient> {
const bearerToken = await AuthUtil.instance.getBearerToken()
const cwsprConfig = getCodewhispererConfig()
return (await globals.sdkClientBuilder.createAwsService(
Expand All @@ -37,27 +46,22 @@ export async function createFeatureDevProxyClient(): Promise<FeatureDevProxyClie
region: cwsprConfig.region,
endpoint: cwsprConfig.endpoint,
token: new Token({ token: bearerToken }),
// SETTING TO 0 FOR BETA. RE-ENABLE FOR RE-INVENT
maxRetries: 0,
retryDelayOptions: {
// The default number of milliseconds to use in the exponential backoff
base: 500,
},
...options,
} as ServiceOptions,
undefined
)) as FeatureDevProxyClient
}

export class FeatureDevClient {
public async getClient() {
public async getClient(options?: Partial<ServiceOptions>) {
// Should not be stored for the whole session.
// Client has to be reinitialized for each request so we always have a fresh bearerToken
return await createFeatureDevProxyClient()
return await createFeatureDevProxyClient(options)
}

public async createConversation() {
try {
const client = await this.getClient()
const client = await this.getClient(writeAPIRetryOptions)
getLogger().debug(`Executing createTaskAssistConversation with {}`)
const { conversationId, $response } = await client.createTaskAssistConversation().promise()
getLogger().debug(`${featureName}: Created conversation: %O`, {
Expand All @@ -82,7 +86,7 @@ export class FeatureDevClient {

public async createUploadUrl(conversationId: string, contentChecksumSha256: string, contentLength: number) {
try {
const client = await this.getClient()
const client = await this.getClient(writeAPIRetryOptions)
const params = {
uploadContext: {
taskAssistPlanningUploadContext: {
Expand Down Expand Up @@ -119,7 +123,7 @@ export class FeatureDevClient {

public async startCodeGeneration(conversationId: string, uploadId: string, message: string) {
try {
const client = await this.getClient()
const client = await this.getClient(writeAPIRetryOptions)
const params = {
conversationState: {
conversationId,
Expand Down
Loading