{"version":3,"sources":["../../../src/llms/drivers/typescript.ts"],"names":["TypescriptDriver","BaseDriver","template","PromptTemplate","schema","z","object","string","register","parseResponse","textResponse","parseBrokenJson","schemaToString","jsonSchemaToTypescript","compile","guided","json"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBO,MAAMA,yBAEHC,mBAAAA,CAAAA;EA1BV;;;AA2BYC,EAAAA,QAAAA,GAAW,IAAIC,2BAAe,CAAA;AACtCC,IAAAA,MAAAA,EAAQC,MAAEC,MAAO,CAAA;AACfF,MAAAA,MAAAA,EAAQC,MAAEE,MAAM;KAClB,CAAA;IACAL,QAAU,EAAA,CAAA;;;;;;;;GAQZ,CAAA;EAEA;AACE,IAAA,IAAA,CAAKM,QAAQ,EAAA;AACf;AAEUC,EAAAA,aAAAA,CAAcC,YAA+B,EAAA;AACrD,IAAA,OAAOC,2BAAgBD,YAAAA,CAAAA;AACzB;AAEA,EAAA,MAAgBE,eAAeR,MAAuC,EAAA;AACpE,IAAA,OAAO,MAAMS,iCAAAA,CAAuBC,OAAQV,CAAAA,MAAAA,EAAQ,QAAA,CAAA;AACtD;AAEUW,EAAAA,MAAAA,CAAOX,MAAsB,EAAA;AACrC,IAAO,OAAA;MAAEY,IAAMZ,EAAAA;AAAO,KAAA;AACxB;AACF","file":"typescript.cjs","sourcesContent":["/**\n * Copyright 2025 IBM Corp.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { parseBrokenJson } from \"@/internals/helpers/schema.js\";\nimport { GenerateOptions } from \"@/llms/base.js\";\nimport { PromptTemplate } from \"@/template.js\";\nimport { BaseDriver } from \"@/llms/drivers/base.js\";\nimport * as jsonSchemaToTypescript from \"json-schema-to-typescript\";\nimport { SchemaObject } from \"ajv\";\nimport { z } from \"zod\";\n\nexport class TypescriptDriver<\n  TGenerateOptions extends GenerateOptions = GenerateOptions,\n> extends BaseDriver<TGenerateOptions> {\n  protected template = new PromptTemplate({\n    schema: z.object({\n      schema: z.string(),\n    }),\n    template: `You are a helpful assistant that generates only valid JSON adhering to the following TypeScript type.\n\n\\`\\`\\`\n{{schema}}\n\\`\\`\\`\n\nIMPORTANT: Every message must be a parsable JSON string without additional output.\n`,\n  });\n\n  static {\n    this.register();\n  }\n\n  protected parseResponse(textResponse: string): unknown {\n    return parseBrokenJson(textResponse);\n  }\n\n  protected async schemaToString(schema: SchemaObject): Promise<string> {\n    return await jsonSchemaToTypescript.compile(schema, \"Output\");\n  }\n\n  protected guided(schema: SchemaObject) {\n    return { json: schema } as const;\n  }\n}\n"]}