(configYaml: string)
| 30 | import { BlockType, getBlockType } from "./getBlockType.js"; |
| 31 | |
| 32 | export function parseConfigYaml(configYaml: string): ConfigYaml { |
| 33 | try { |
| 34 | const parsed = YAML.parse(configYaml); |
| 35 | const result = configYamlSchema.safeParse(parsed); |
| 36 | if (result.success) { |
| 37 | return result.data; |
| 38 | } |
| 39 | |
| 40 | throw new Error(formatZodError(result.error), { |
| 41 | cause: "result.success was false", |
| 42 | }); |
| 43 | } catch (e) { |
| 44 | if ( |
| 45 | e instanceof Error && |
| 46 | "cause" in e && |
| 47 | e.cause === "result.success was false" |
| 48 | ) { |
| 49 | throw new Error(`Failed to parse config: ${e.message}`); |
| 50 | } else if (e instanceof ZodError) { |
| 51 | throw new Error(`Failed to parse config: ${formatZodError(e)}`); |
| 52 | } else { |
| 53 | throw new Error( |
| 54 | `Failed to parse config: ${e instanceof Error ? e.message : e}`, |
| 55 | ); |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | export function parseAssistantUnrolled(configYaml: string): AssistantUnrolled { |
| 61 | try { |
no test coverage detected