(options: PerformRequestOptions)
| 171 | } |
| 172 | |
| 173 | override performRequest(options: PerformRequestOptions): void { |
| 174 | void iife(async () => { |
| 175 | const commonResponseHeaders = { |
| 176 | "x-github-request-id": "some-request-id", |
| 177 | }; |
| 178 | |
| 179 | try { |
| 180 | // Handle /copilot-user-config endpoint for configuring per-token user responses |
| 181 | if ( |
| 182 | options.requestOptions.path === "/copilot-user-config" && |
| 183 | options.requestOptions.method === "POST" |
| 184 | ) { |
| 185 | const config = JSON.parse(options.body!) as { |
| 186 | token: string; |
| 187 | response: CopilotUserResponse; |
| 188 | }; |
| 189 | this.copilotUserByToken.set(config.token, config.response); |
| 190 | options.onResponseStart(200, {}); |
| 191 | options.onResponseEnd(); |
| 192 | return; |
| 193 | } |
| 194 | |
| 195 | // Handle /config endpoint for updating proxy configuration |
| 196 | if ( |
| 197 | options.requestOptions.path === "/config" && |
| 198 | options.requestOptions.method === "POST" |
| 199 | ) { |
| 200 | await this.updateConfig(JSON.parse(options.body!)); |
| 201 | options.onResponseStart(200, {}); |
| 202 | options.onResponseEnd(); |
| 203 | return; |
| 204 | } |
| 205 | |
| 206 | // Handle /stop endpoint for stopping the proxy |
| 207 | if ( |
| 208 | options.requestOptions.path?.startsWith("/stop") && |
| 209 | options.requestOptions.method === "POST" |
| 210 | ) { |
| 211 | const skipWritingCache = options.requestOptions.path.includes( |
| 212 | "skipWritingCache=true", |
| 213 | ); |
| 214 | options.onResponseStart(200, {}); |
| 215 | options.onResponseEnd(); |
| 216 | await this.onStopRequested?.(skipWritingCache); |
| 217 | await this.stop(skipWritingCache); |
| 218 | process.exit(0); |
| 219 | } |
| 220 | |
| 221 | // Handle /exchanges endpoint for retrieving captured exchanges |
| 222 | if ( |
| 223 | options.requestOptions.path === "/exchanges" && |
| 224 | options.requestOptions.method === "GET" |
| 225 | ) { |
| 226 | const chatCompletionExchanges = this.exchanges.filter( |
| 227 | (e) => e.request.url === chatCompletionEndpoint, |
| 228 | ); |
| 229 | const parsedExchanges = await Promise.all( |
| 230 | chatCompletionExchanges.map((e) => |
nothing calls this directly
no test coverage detected