(req, server)
| 305 | idleTimeout: 0, |
| 306 | |
| 307 | async fetch(req, server) { |
| 308 | const url = new URL(req.url); |
| 309 | |
| 310 | if (agentTerminal.matches(url.pathname)) { |
| 311 | if (agentTerminal.capability.enabled && agentTerminal.upgrade(req, server)) { |
| 312 | return; |
| 313 | } |
| 314 | return new Response("Agent terminal is unavailable", { status: 404 }); |
| 315 | } |
| 316 | if (isAgentTerminalWsRoute(url.pathname)) { |
| 317 | return new Response("Agent terminal is unavailable", { status: 404 }); |
| 318 | } |
| 319 | |
| 320 | // API: Get plan content (reuse /api/plan so the plan editor UI works) |
| 321 | if (url.pathname === "/api/plan" && req.method === "GET") { |
| 322 | const displayRawHtml = renderHtml && rawHtml ? htmlAssets.rewriteHtml(rawHtml, filePath) : undefined; |
| 323 | const primarySource = getPrimarySource(); |
| 324 | return Response.json({ |
| 325 | plan: primarySource.plan, |
| 326 | origin, |
| 327 | mode, |
| 328 | filePath, |
| 329 | sourceInfo, |
| 330 | sourceConverted: sourceConverted ?? false, |
| 331 | sourceSave: primarySource.sourceSave, |
| 332 | gate, |
| 333 | renderAs: displayRawHtml ? 'html' as const : 'markdown' as const, |
| 334 | ...(displayRawHtml ? { rawHtml: displayRawHtml } : {}), |
| 335 | convertHtml, |
| 336 | sharingEnabled, |
| 337 | shareBaseUrl, |
| 338 | pasteApiUrl, |
| 339 | repoInfo, |
| 340 | projectRoot: folderPath || process.cwd(), |
| 341 | isWSL: wslFlag, |
| 342 | serverConfig: getServerConfig(gitUser), |
| 343 | agentTerminal: agentTerminal.capability, |
| 344 | ...(recentMessages ? { recentMessages } : {}), |
| 345 | }); |
| 346 | } |
| 347 | |
| 348 | if (url.pathname === "/api/share-html" && req.method === "GET") { |
| 349 | return loadShareHtml(url.searchParams.get("path")); |
| 350 | } |
| 351 | |
| 352 | // API: List apps the host can open a file in (Open in App control). |
| 353 | if (url.pathname === "/api/open-in/apps" && req.method === "GET") { |
| 354 | // A URL annotation source has no local file to open — mirror Pi and |
| 355 | // report unavailable so the UI hides the control entirely. |
| 356 | if (/^https?:\/\//i.test(filePath)) { |
| 357 | return Response.json({ available: false, apps: [] }); |
| 358 | } |
| 359 | return handleOpenInApps(); |
| 360 | } |
| 361 | |
| 362 | // API: Open the annotated file in an app. A URL source has no local |
| 363 | // file; any other open is confined to the same reference roots |
| 364 | // /api/doc serves from, so any linked doc the user can view can also |
nothing calls this directly
no test coverage detected