{"version":3,"file":"utils/common.mjs","sources":["webpack://@multimodal/agent/./src/utils/common.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/*\n * Copyright (c) 2025 Bytedance, Inc. and its affiliates.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { zodToJsonSchema as originalZodToJsonSchema } from 'zod-to-json-schema';\nimport { ZodType, JSONSchema7 as JSONSchema } from '@multimodal/model-provider';\n\n/**\n * Type guard to check if the parameter is a Zod schema\n */\nfunction isZodSchema(schema: any): schema is ZodType {\n  return schema instanceof ZodType;\n}\n\n/**\n * Convert schema to JSON schema, handling both Zod and direct JSON Schema inputs\n */\nexport const zodToJsonSchema = (schema: ZodType | JSONSchema): JSONSchema => {\n  // If it's already a JSON schema, return it directly\n  if (!isZodSchema(schema)) {\n    return schema as JSONSchema;\n  }\n\n  // Otherwise, convert from Zod\n  const originalSchema = originalZodToJsonSchema(schema);\n\n  const removeUnwantedFields = (obj: any): any => {\n    if (typeof obj !== 'object' || obj === null) {\n      return obj;\n    }\n\n    if (Array.isArray(obj)) {\n      return obj.map(removeUnwantedFields);\n    }\n\n    const newObj: any = {};\n    for (const [key, value] of Object.entries(obj)) {\n      if (key === 'additionalProperties' && value === false) {\n        continue;\n      }\n      if (key !== '$schema') {\n        newObj[key] = removeUnwantedFields(value);\n      }\n    }\n\n    return newObj;\n  };\n\n  return removeUnwantedFields(originalSchema);\n};\n\n/**\n * Format tool parameters into a more readable form\n */\nexport function formatToolParameters(schema: JSONSchema): string {\n  if (!schema.properties) {\n    return 'No parameters required';\n  }\n\n  const properties = schema.properties;\n  const requiredProps = schema.required || [];\n\n  return Object.entries(properties)\n    .map(([name, prop]: [string, any]) => {\n      const isRequired = requiredProps.includes(name);\n      return `- ${name}${isRequired ? ' (required)' : ''}: ${prop.description || 'No description'} (type: ${prop.type})`;\n    })\n    .join('\\n');\n}\n"],"names":["isZodSchema","schema","ZodType","zodToJsonSchema","originalSchema","originalZodToJsonSchema","removeUnwantedFields","obj","Array","newObj","key","value","Object","formatToolParameters","properties","requiredProps","name","prop","isRequired"],"mappings":";;;;;;AAWA,SAASA,YAAYC,MAAW;IAC9B,OAAOA,kBAAkBC;AAC3B;AAKO,MAAMC,yBAAkB,CAACF;IAE9B,IAAI,CAACD,YAAYC,SACf,OAAOA;IAIT,MAAMG,iBAAiBC,gBAAwBJ;IAE/C,MAAMK,uBAAuB,CAACC;QAC5B,IAAI,AAAe,YAAf,OAAOA,OAAoBA,AAAQ,SAARA,KAC7B,OAAOA;QAGT,IAAIC,MAAM,OAAO,CAACD,MAChB,OAAOA,IAAI,GAAG,CAACD;QAGjB,MAAMG,SAAc,CAAC;QACrB,KAAK,MAAM,CAACC,KAAKC,MAAM,IAAIC,OAAO,OAAO,CAACL,KACxC,IAAIG,AAAQ,2BAARA,OAAkCC,AAAU,UAAVA,OAGtC;YAAA,IAAID,AAAQ,cAARA,KACFD,MAAM,CAACC,IAAI,GAAGJ,qBAAqBK;QACrC;QAGF,OAAOF;IACT;IAEA,OAAOH,qBAAqBF;AAC9B;AAKO,SAASS,qBAAqBZ,MAAkB;IACrD,IAAI,CAACA,OAAO,UAAU,EACpB,OAAO;IAGT,MAAMa,aAAab,OAAO,UAAU;IACpC,MAAMc,gBAAgBd,OAAO,QAAQ,IAAI,EAAE;IAE3C,OAAOW,OAAO,OAAO,CAACE,YACnB,GAAG,CAAC,CAAC,CAACE,MAAMC,KAAoB;QAC/B,MAAMC,aAAaH,cAAc,QAAQ,CAACC;QAC1C,OAAO,CAAC,EAAE,EAAEA,OAAOE,aAAa,gBAAgB,GAAG,EAAE,EAAED,KAAK,WAAW,IAAI,iBAAiB,QAAQ,EAAEA,KAAK,IAAI,CAAC,CAAC,CAAC;IACpH,GACC,IAAI,CAAC;AACV"}