()
| 111 | } |
| 112 | |
| 113 | public async initialize(): Promise<void> { |
| 114 | if (this.isInitialized) { |
| 115 | return |
| 116 | } |
| 117 | |
| 118 | try { |
| 119 | // For testing you can create a token with: |
| 120 | // `pnpm --filter @roo-code-cloud/roomote-cli development auth job-token --job-id 1 --user-id user_2xmBhejNeDTwanM8CgIOnMgVxzC --org-id org_2wbhchVXZMQl8OS1yt0mrDazCpW` |
| 121 | // The token will last for 1 hour. |
| 122 | const cloudToken = process.env.ROO_CODE_CLOUD_TOKEN |
| 123 | |
| 124 | if (cloudToken && cloudToken.length > 0) { |
| 125 | this._authService = new StaticTokenAuthService(this.context, cloudToken, this.log) |
| 126 | this._isCloudAgent = true |
| 127 | } else { |
| 128 | this._authService = new WebAuthService(this.context, this.log) |
| 129 | } |
| 130 | |
| 131 | this._authService.on("auth-state-changed", this.authStateListener) |
| 132 | this._authService.on("user-info", this.authUserInfoListener) |
| 133 | await this._authService.initialize() |
| 134 | |
| 135 | // Check for static settings environment variable. |
| 136 | const staticOrgSettings = process.env.ROO_CODE_CLOUD_ORG_SETTINGS |
| 137 | |
| 138 | if (staticOrgSettings && staticOrgSettings.length > 0) { |
| 139 | this._settingsService = new StaticSettingsService(staticOrgSettings, this.log) |
| 140 | } else { |
| 141 | const cloudSettingsService = new CloudSettingsService(this.context, this._authService, this.log) |
| 142 | |
| 143 | cloudSettingsService.on("settings-updated", this.settingsListener) |
| 144 | await cloudSettingsService.initialize() |
| 145 | |
| 146 | this._settingsService = cloudSettingsService |
| 147 | } |
| 148 | |
| 149 | this._cloudAPI = new CloudAPI(this._authService, this.log) |
| 150 | |
| 151 | // Initialize retry queue with auth header provider. |
| 152 | this._retryQueue = new RetryQueue( |
| 153 | this.context, |
| 154 | undefined, // Use default config. |
| 155 | this.log, |
| 156 | () => { |
| 157 | // Provide fresh auth headers for retries. |
| 158 | const sessionToken = this._authService?.getSessionToken() |
| 159 | |
| 160 | if (sessionToken) { |
| 161 | return { Authorization: `Bearer ${sessionToken}` } |
| 162 | } |
| 163 | |
| 164 | return undefined |
| 165 | }, |
| 166 | ) |
| 167 | |
| 168 | this._telemetryClient = new TelemetryClient(this._authService, this._settingsService, this._retryQueue) |
| 169 | |
| 170 | this._shareService = new CloudShareService(this._cloudAPI, this._settingsService, this.log) |
no test coverage detected