(filePath: string, label: string)
| 55 | } |
| 56 | |
| 57 | function readJsonObject(filePath: string, label: string): JsonObject { |
| 58 | let raw: string; |
| 59 | try { |
| 60 | raw = fs.readFileSync(filePath, 'utf8'); |
| 61 | } catch (error) { |
| 62 | const message = error instanceof Error ? error.message : String(error); |
| 63 | throw new Error(`Failed to read ${label} at ${filePath}: ${message}`); |
| 64 | } |
| 65 | |
| 66 | let parsed: unknown; |
| 67 | try { |
| 68 | parsed = JSON.parse(raw) as unknown; |
| 69 | } catch (error) { |
| 70 | const message = error instanceof Error ? error.message : String(error); |
| 71 | throw new Error(`Failed to parse ${label} at ${filePath}: ${message}`); |
| 72 | } |
| 73 | |
| 74 | if (!isRecord(parsed)) { |
| 75 | throw new Error(`${label} at ${filePath} must be a JSON object.`); |
| 76 | } |
| 77 | return parsed; |
| 78 | } |
| 79 | |
| 80 | function schemaPathFor(ref: StructuredOutputSchemaRef): string { |
| 81 | const schemasDir = getStructuredOutputSchemasDir(); |
no test coverage detected