* Builds a tool-specific graceful offline response (HTTP 200). * * CRITICAL: ChatGPT converts ANY non-2xx status into a ClientResponseError. * We must ALWAYS return 200 — even when the browser tunnel is unreachable. * The offline payload gives ChatGPT enough context to tell the user what to do.
(query_type: string)
| 34 | * The offline payload gives ChatGPT enough context to tell the user what to do. |
| 35 | */ |
| 36 | function offlineResponse(query_type: string) { |
| 37 | const openUrl = "https://cgc.codes/explore"; |
| 38 | |
| 39 | const base = { |
| 40 | status: "offline", |
| 41 | message: `Browser tunnel is offline. Open ${openUrl} in a browser tab, keep that tab active (not in the background), wait a few seconds for the tunnel to connect, then retry in ChatGPT.`, |
| 42 | }; |
| 43 | |
| 44 | switch (query_type) { |
| 45 | case "list_indexed_repositories": |
| 46 | return { ...base, indexed_repositories: [] }; |
| 47 | case "get_repository_stats": |
| 48 | return { ...base, total_nodes: 0, total_links: 0, files_count: 0, classes_count: 0, functions_count: 0 }; |
| 49 | case "find_dead_code": |
| 50 | return { ...base, dead_symbols: [], total_dead_symbols: 0 }; |
| 51 | case "calculate_cyclomatic_complexity": |
| 52 | case "find_most_complex_functions": |
| 53 | return { ...base, most_complex_functions: [] }; |
| 54 | case "analyze_code_relationships": |
| 55 | return { ...base, relationships_count: 0, connected_nodes: [], connected_links: [] }; |
| 56 | case "search_registry_bundles": |
| 57 | return { ...base, results: [] }; |
| 58 | case "definitions": |
| 59 | case "callers": |
| 60 | case "callees": |
| 61 | case "file_structure": |
| 62 | case "search": |
| 63 | return { ...base, nodes: [], links: [] }; |
| 64 | case "cypher": |
| 65 | return { ...base, nodes: [], links: [] }; |
| 66 | default: |
| 67 | return { ...base, result: null }; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | export default async function handler(req: any, res: any) { |
| 72 | res.setHeader("Access-Control-Allow-Origin", "*"); |