var o=class{constructor(e){this.schema=e}parse(e){let i=e.match(/```json\s*([\s\S]*?)\s*```/);if(i)return this.validate(JSON.parse(i[1]));let r=e.match(/\{[\s\S]*\}/);return r?this.validate(JSON.parse(r[0])):this.validate({result:e.trim()})}validate(e){let i=[];for(let[r,n]of Object.entries(this.schema)){if(n.required&&!(r in e)&&i.push(`Missing required field: ${r}`),r in e&&n.type){let s=typeof e[r];s!==n.type&&i.push(`Field '${r}' expected ${n.type}, got ${s}`)}if(n.validate&&r in e){let s=n.validate(e[r]);s&&i.push(`Field '${r}': ${s}`)}}if(i.length>0)throw new Error(`Output validation failed:
${i.join(`
`)}`);return e}},a={string:(t=!0)=>({type:"string",required:t}),number:(t=!0)=>({type:"number",required:t}),boolean:(t=!0)=>({type:"boolean",required:t}),array:(t=!0)=>({type:"object",required:t,validate:e=>Array.isArray(e)?null:"must be an array"}),enum:(t,e=!0)=>({type:"string",required:e,validate:i=>t.includes(i)?null:`must be one of: ${t.join(", ")}`})};export{o as OutputParser,a as SchemaTypes};
