1- import { CodeWhispererStreaming , ExportIntent } from '@amzn/codewhisperer-streaming'
1+ import { ExportIntent } from '@amzn/codewhisperer-streaming'
22import { Logging , Runtime , Workspace } from '@aws/language-server-runtimes/server-interface'
33import * as fs from 'fs'
44import got from 'got'
99 StopTransformationRequest ,
1010 TransformationJob ,
1111} from '../../client/token/codewhispererbearertokenclient'
12- import { CodeWhispererServiceToken } from '../../shared/codeWhispererService'
1312import { ArtifactManager } from './artifactManager'
1413import { getCWStartTransformRequest , getCWStartTransformResponse } from './converter'
1514import {
@@ -29,21 +28,17 @@ import {
2928import * as validation from './validation'
3029import path = require( 'path' )
3130import AdmZip = require( 'adm-zip' )
32- import { Console } from 'console'
33- import { supportedProjects , unsupportedViewComponents } from './resources/SupportedProjects'
34- import { String } from 'aws-sdk/clients/codebuild'
35- import { ProjectMetadata } from 'aws-sdk/clients/lookoutvision'
36- import { httpstatus } from 'aws-sdk/clients/glacier'
31+ import { AmazonQTokenServiceManager } from '../../shared/amazonQServiceManager/AmazonQTokenServiceManager'
3732
3833const workspaceFolderName = 'artifactWorkspace'
3934
4035export class TransformHandler {
41- private client : CodeWhispererServiceToken
36+ private serviceManager : AmazonQTokenServiceManager
4237 private workspace : Workspace
4338 private logging : Logging
4439 private runtime : Runtime
45- constructor ( client : CodeWhispererServiceToken , workspace : Workspace , logging : Logging , runtime : Runtime ) {
46- this . client = client
40+ constructor ( serviceManager : AmazonQTokenServiceManager , workspace : Workspace , logging : Logging , runtime : Runtime ) {
41+ this . serviceManager = serviceManager
4742 this . workspace = workspace
4843 this . logging = logging
4944 this . runtime = runtime
@@ -82,7 +77,9 @@ export class TransformHandler {
8277 const uploadId = await this . preTransformationUploadCode ( payloadFilePath )
8378 const request = getCWStartTransformRequest ( userInputrequest , uploadId , this . logging )
8479 this . logging . log ( 'Sending request to start transform api: ' + JSON . stringify ( request ) )
85- const response = await this . client . codeModernizerStartCodeTransformation ( request )
80+ const response = await this . serviceManager
81+ . getCodewhispererService ( )
82+ . codeModernizerStartCodeTransformation ( request )
8683 this . logging . log ( 'Received transformation job Id: ' + response ?. transformationJobId )
8784 return getCWStartTransformResponse (
8885 response ,
@@ -122,7 +119,7 @@ export class TransformHandler {
122119 const sha256 = await ArtifactManager . getSha256Async ( payloadFileName )
123120 let response : CreateUploadUrlResponse
124121 try {
125- response = await this . client . codeModernizerCreateUploadUrl ( {
122+ response = await this . serviceManager . getCodewhispererService ( ) . codeModernizerCreateUploadUrl ( {
126123 contentChecksum : sha256 ,
127124 contentChecksumType : 'SHA_256' ,
128125 uploadIntent : 'TRANSFORMATION' ,
@@ -192,7 +189,9 @@ export class TransformHandler {
192189 const getCodeTransformationRequest = {
193190 transformationJobId : request . TransformationJobId ,
194191 } as GetTransformationRequest
195- const response = await this . client . codeModernizerGetCodeTransformation ( getCodeTransformationRequest )
192+ const response = await this . serviceManager
193+ . getCodewhispererService ( )
194+ . codeModernizerGetCodeTransformation ( getCodeTransformationRequest )
196195 this . logging . log ( 'Transformation status: ' + response . transformationJob ?. status )
197196 return {
198197 TransformationJob : response . transformationJob ,
@@ -211,9 +210,9 @@ export class TransformHandler {
211210 const getCodeTransformationPlanRequest = {
212211 transformationJobId : request . TransformationJobId ,
213212 } as GetTransformationRequest
214- const response = await this . client . codeModernizerGetCodeTransformationPlan (
215- getCodeTransformationPlanRequest
216- )
213+ const response = await this . serviceManager
214+ . getCodewhispererService ( )
215+ . codeModernizerGetCodeTransformationPlan ( getCodeTransformationPlanRequest )
217216 return {
218217 TransformationPlan : response . transformationPlan ,
219218 } as GetTransformPlanResponse
@@ -247,7 +246,9 @@ export class TransformHandler {
247246 this . logging . log (
248247 'Sending CancelTransformRequest with job Id: ' + stopCodeTransformationRequest . transformationJobId
249248 )
250- const response = await this . client . codeModernizerStopCodeTransformation ( stopCodeTransformationRequest )
249+ const response = await this . serviceManager
250+ . getCodewhispererService ( )
251+ . codeModernizerStopCodeTransformation ( stopCodeTransformationRequest )
251252 this . logging . log ( 'Transformation status: ' + response . transformationStatus )
252253 let status : CancellationJobStatus
253254 switch ( response . transformationStatus ) {
@@ -293,7 +294,9 @@ export class TransformHandler {
293294 const getCodeTransformationRequest = {
294295 transformationJobId : request . TransformationJobId ,
295296 } as GetTransformationRequest
296- let response = await this . client . codeModernizerGetCodeTransformation ( getCodeTransformationRequest )
297+ let response = await this . serviceManager
298+ . getCodewhispererService ( )
299+ . codeModernizerGetCodeTransformation ( getCodeTransformationRequest )
297300 this . logging . log ( 'Start polling for transformation plan.' )
298301 this . logging . log ( 'The valid status to exit polling are: ' + validExitStatus )
299302 this . logging . log ( 'The failure status are: ' + failureStates )
@@ -308,7 +311,9 @@ export class TransformHandler {
308311 const getCodeTransformationRequest = {
309312 transformationJobId : request . TransformationJobId ,
310313 } as GetTransformationRequest
311- response = await this . client . codeModernizerGetCodeTransformation ( getCodeTransformationRequest )
314+ response = await this . serviceManager
315+ . getCodewhispererService ( )
316+ . codeModernizerGetCodeTransformation ( getCodeTransformationRequest )
312317 this . logging . log ( 'Transformation status: ' + response . transformationJob ?. status )
313318
314319 if ( validExitStatus . includes ( status ) ) {
@@ -350,10 +355,10 @@ export class TransformHandler {
350355 } as GetTransformResponse
351356 }
352357
353- async downloadExportResultArchive ( cwStreamingClient : CodeWhispererStreaming , exportId : string , saveToDir : string ) {
358+ async downloadExportResultArchive ( exportId : string , saveToDir : string ) {
354359 let result
355360 try {
356- result = await cwStreamingClient . exportResultArchive ( {
361+ result = await this . serviceManager . getStreamingClient ( ) . client . exportResultArchive ( {
357362 exportId,
358363 exportIntent : ExportIntent . TRANSFORMATION ,
359364 } )
0 commit comments