( resumeIdentifier: string, )
| 20 | * @returns Parsed session information or null if invalid |
| 21 | */ |
| 22 | export function parseSessionIdentifier( |
| 23 | resumeIdentifier: string, |
| 24 | ): ParsedSessionUrl | null { |
| 25 | // Check for JSONL file path before URL parsing, since Windows absolute |
| 26 | // paths (e.g., C:\path\file.jsonl) are parsed as valid URLs with C: as protocol |
| 27 | if (resumeIdentifier.toLowerCase().endsWith('.jsonl')) { |
| 28 | return { |
| 29 | sessionId: randomUUID() as UUID, |
| 30 | ingressUrl: null, |
| 31 | isUrl: false, |
| 32 | jsonlFile: resumeIdentifier, |
| 33 | isJsonlFile: true, |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | // Check if it's a plain UUID |
| 38 | if (validateUuid(resumeIdentifier)) { |
| 39 | return { |
| 40 | sessionId: resumeIdentifier as UUID, |
| 41 | ingressUrl: null, |
| 42 | isUrl: false, |
| 43 | jsonlFile: null, |
| 44 | isJsonlFile: false, |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | // Check if it's a URL |
| 49 | try { |
| 50 | const url = new URL(resumeIdentifier) |
| 51 | |
| 52 | // Use the entire URL as the ingress URL |
| 53 | // Always generate a random session ID |
| 54 | return { |
| 55 | sessionId: randomUUID() as UUID, |
| 56 | ingressUrl: url.href, |
| 57 | isUrl: true, |
| 58 | jsonlFile: null, |
| 59 | isJsonlFile: false, |
| 60 | } |
| 61 | } catch { |
| 62 | // Not a valid URL |
| 63 | } |
| 64 | |
| 65 | return null |
| 66 | } |
no test coverage detected