{"version":3,"file":"zod_to_genai_parameters.cjs","names":["isInteropZodSchema","isSerializableSchema","toJsonSchema"],"sources":["../../src/utils/zod_to_genai_parameters.ts"],"sourcesContent":["import {\n  type FunctionDeclarationSchema as GenerativeAIFunctionDeclarationSchema,\n  type SchemaType as FunctionDeclarationSchemaType,\n} from \"@google/generative-ai\";\nimport {\n  InteropZodType,\n  isInteropZodSchema,\n} from \"@langchain/core/utils/types\";\nimport {\n  type JsonSchema7Type,\n  toJsonSchema,\n} from \"@langchain/core/utils/json_schema\";\nimport {\n  isSerializableSchema,\n  SerializableSchema,\n} from \"@langchain/core/utils/standard_schema\";\n\nexport interface GenerativeAIJsonSchema extends Record<string, unknown> {\n  properties?: Record<string, GenerativeAIJsonSchema>;\n  type: FunctionDeclarationSchemaType;\n}\n\nexport interface GenerativeAIJsonSchemaDirty extends GenerativeAIJsonSchema {\n  properties?: Record<string, GenerativeAIJsonSchemaDirty>;\n  additionalProperties?: boolean;\n}\n\nexport function removeAdditionalProperties(\n  // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n  obj: Record<string, any>\n): GenerativeAIJsonSchema {\n  if (typeof obj === \"object\" && obj !== null) {\n    const newObj = { ...obj };\n\n    if (\"additionalProperties\" in newObj) {\n      delete newObj.additionalProperties;\n    }\n    if (\"$schema\" in newObj) {\n      delete newObj.$schema;\n    }\n    if (\"strict\" in newObj) {\n      delete newObj.strict;\n    }\n\n    for (const key in newObj) {\n      if (key in newObj) {\n        if (Array.isArray(newObj[key])) {\n          newObj[key] = newObj[key].map(removeAdditionalProperties);\n        } else if (typeof newObj[key] === \"object\" && newObj[key] !== null) {\n          newObj[key] = removeAdditionalProperties(newObj[key]);\n        }\n      }\n    }\n\n    return newObj as GenerativeAIJsonSchema;\n  }\n\n  return obj as GenerativeAIJsonSchema;\n}\n\nexport function schemaToGenerativeAIParameters<\n  // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n  RunOutput extends Record<string, any> = Record<string, any>,\n>(\n  schema:\n    | SerializableSchema<RunOutput>\n    | InteropZodType<RunOutput>\n    | JsonSchema7Type\n): GenerativeAIFunctionDeclarationSchema {\n  // GenerativeAI doesn't accept either the $schema or additionalProperties\n  // attributes, so we need to explicitly remove them.\n  const jsonSchema = removeAdditionalProperties(\n    isInteropZodSchema(schema) || isSerializableSchema(schema)\n      ? toJsonSchema(schema)\n      : schema\n  );\n  const { $schema, ...rest } = jsonSchema;\n  return rest as GenerativeAIFunctionDeclarationSchema;\n}\n\nexport function jsonSchemaToGeminiParameters(\n  // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n  schema: Record<string, any>\n): GenerativeAIFunctionDeclarationSchema {\n  // Gemini doesn't accept either the $schema or additionalProperties\n  // attributes, so we need to explicitly remove them.\n  const jsonSchema = removeAdditionalProperties(\n    schema as GenerativeAIJsonSchemaDirty\n  );\n  const { $schema, ...rest } = jsonSchema;\n\n  return rest as GenerativeAIFunctionDeclarationSchema;\n}\n"],"mappings":";;;;AA2BA,SAAgB,2BAEd,KACwB;CACxB,IAAI,OAAO,QAAQ,YAAY,QAAQ,MAAM;EAC3C,MAAM,SAAS,EAAE,GAAG,IAAI;EAExB,IAAI,0BAA0B,QAC5B,OAAO,OAAO;EAEhB,IAAI,aAAa,QACf,OAAO,OAAO;EAEhB,IAAI,YAAY,QACd,OAAO,OAAO;EAGhB,KAAK,MAAM,OAAO,QAChB,IAAI,OAAO,QAAQ;GACjB,IAAI,MAAM,QAAQ,OAAO,IAAI,GAC3B,OAAO,OAAO,OAAO,IAAI,CAAC,IAAI,0BAA0B;QACnD,IAAI,OAAO,OAAO,SAAS,YAAY,OAAO,SAAS,MAC5D,OAAO,OAAO,2BAA2B,OAAO,IAAI;EAExD;EAGF,OAAO;CACT;CAEA,OAAO;AACT;AAEA,SAAgB,+BAId,QAIuC;CAQvC,MAAM,EAAE,SAAS,GAAG,SALD,4BAAA,GACjBA,4BAAAA,mBAAAA,CAAmB,MAAM,MAAA,GAAKC,sCAAAA,qBAAAA,CAAqB,MAAM,KAAA,GACrDC,kCAAAA,aAAAA,CAAa,MAAM,IACnB,MAEgC;CACtC,OAAO;AACT;AAEA,SAAgB,6BAEd,QACuC;CAMvC,MAAM,EAAE,SAAS,GAAG,SAHD,2BACjB,MAEoC;CAEtC,OAAO;AACT"}