(req)
| 368 | port: 0, |
| 369 | idleTimeout: 255, // max — Cursor responses can take 30s+ |
| 370 | async fetch(req) { |
| 371 | const url = new URL(req.url); |
| 372 | |
| 373 | if (req.method === "GET" && url.pathname === "/v1/models") { |
| 374 | return new Response( |
| 375 | JSON.stringify({ |
| 376 | object: "list", |
| 377 | data: buildOpenAIModelList(proxyModels), |
| 378 | }), |
| 379 | { headers: { "Content-Type": "application/json" } }, |
| 380 | ); |
| 381 | } |
| 382 | |
| 383 | if (req.method === "POST" && url.pathname === "/v1/chat/completions") { |
| 384 | try { |
| 385 | const body = (await req.json()) as ChatCompletionRequest; |
| 386 | if (!proxyAccessTokenProvider) { |
| 387 | throw new Error("Cursor proxy access token provider not configured"); |
| 388 | } |
| 389 | const accessToken = await proxyAccessTokenProvider(); |
| 390 | return handleChatCompletion(body, accessToken); |
| 391 | } catch (err) { |
| 392 | const message = err instanceof Error ? err.message : String(err); |
| 393 | return new Response( |
| 394 | JSON.stringify({ |
| 395 | error: { message, type: "server_error", code: "internal_error" }, |
| 396 | }), |
| 397 | { status: 500, headers: { "Content-Type": "application/json" } }, |
| 398 | ); |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | return new Response("Not Found", { status: 404 }); |
| 403 | }, |
| 404 | }); |
| 405 | |
| 406 | proxyPort = proxyServer.port; |
nothing calls this directly
no test coverage detected