The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { NETWORK_BLOCKING_HINT, UNRESPONSIVE_HOST_HINT } from "./network.ts"; |
| 2 | |
| 3 | const escapeRegExp = (text: string) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); |
| 4 | |
| 5 | const TRANSPORT_ERROR_PATTERNS = [ |
| 6 | /\bSocketCloseError\b/i, |
| 7 | /\bSocketOpenError\b/i, |
| 8 | /\bSocket is not connected\b/i, |
| 9 | /Unable to connect to the T3 server WebSocket\./i, |
| 10 | // The RPC session appends the network hint for relay connections. Any other |
| 11 | // trailing text means a different error that the user should still see. |
| 12 | new RegExp( |
| 13 | `\\b(?:is not connected|disconnected|stopped responding|could not establish a WebSocket connection)\\.(?: ${escapeRegExp(NETWORK_BLOCKING_HINT)})?$`, |
| 14 | "i", |
| 15 | ), |
| 16 | new RegExp(`\\bstopped responding for \\d+s\\. ${escapeRegExp(UNRESPONSIVE_HOST_HINT)}$`, "i"), |
| 17 | /\bClientProtocolError\b/i, |
| 18 | /\bRpcClientError\b/i, |
| 19 | /\bping timeout\b/i, |
| 20 | ] as const; |
| 21 | |
| 22 | export function isTransportConnectionErrorMessage(message: string | null | undefined): boolean { |
| 23 | if (typeof message !== "string") { |
| 24 | return false; |
| 25 | } |
| 26 | |
| 27 | const normalizedMessage = message.trim(); |
| 28 | if (normalizedMessage.length === 0) { |
| 29 | return false; |
| 30 | } |
| 31 | |
| 32 | return TRANSPORT_ERROR_PATTERNS.some((pattern) => pattern.test(normalizedMessage)); |
| 33 | } |
| 34 | |
| 35 | export function sanitizeThreadErrorMessage(message: string | null | undefined): string | null { |
| 36 | return isTransportConnectionErrorMessage(message) ? null : (message ?? null); |
| 37 | } |