{"version":3,"file":"agent/tool.mjs","sources":["webpack://@multimodal/agent/./src/agent/tool.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 { z, JSONSchema7 } from '@multimodal/model-provider';\nimport type { Tool as ITool } from '@multimodal/agent-interface';\n\n/**\n * Type guard to check if the parameter is a Zod schema\n */\nfunction isZodSchema(schema: any): schema is z.ZodObject<any> {\n  return schema instanceof z.ZodObject;\n}\n\n/**\n * Type guard to check if the parameter is a JSON schema\n */\nfunction isJsonSchema(schema: any): schema is JSONSchema7 {\n  return (\n    schema !== null &&\n    typeof schema === 'object' &&\n    !isZodSchema(schema) &&\n    (schema.type === 'object' || schema.properties !== undefined)\n  );\n}\n\n/**\n * Tool class for defining agent tools\n *\n * Supports type inference for parameters defined with both Zod schema and JSON Schema.\n */\nexport class Tool<\n  TSchema extends z.ZodObject<any> | JSONSchema7 = any,\n  TParams = TSchema extends z.ZodObject<any> ? z.infer<TSchema> : any,\n> implements ITool\n{\n  public name: string;\n  public description: string;\n\n  public schema: TSchema;\n  public function: (args: TParams) => Promise<any> | any;\n\n  constructor(options: {\n    id: string;\n    description: string;\n    parameters: TSchema;\n    function: (input: TParams) => Promise<any> | any;\n  }) {\n    this.name = options.id;\n    this.description = options.description;\n    this.schema = options.parameters;\n    this.function = options.function;\n  }\n\n  /**\n   * Check if the tool uses Zod schema\n   */\n  hasZodSchema(): boolean {\n    return isZodSchema(this.schema);\n  }\n\n  /**\n   * Check if the tool uses JSON schema\n   */\n  hasJsonSchema(): boolean {\n    return isJsonSchema(this.schema);\n  }\n}\n"],"names":["isZodSchema","schema","z","isJsonSchema","undefined","Tool","options"],"mappings":";;;;;AAIC;;;;;;;;;;AAOD,SAASA,YAAYC,MAAW;IAC9B,OAAOA,kBAAkBC,EAAE,SAAS;AACtC;AAKA,SAASC,aAAaF,MAAW;IAC/B,OACEA,AAAW,SAAXA,UACA,AAAkB,YAAlB,OAAOA,UACP,CAACD,YAAYC,WACZA,CAAAA,AAAgB,aAAhBA,OAAO,IAAI,IAAiBA,AAAsBG,WAAtBH,OAAO,UAAU,AAAa;AAE/D;AAOO,MAAMI;IA0BX,eAAwB;QACtB,OAAOL,YAAY,IAAI,CAAC,MAAM;IAChC;IAKA,gBAAyB;QACvB,OAAOG,aAAa,IAAI,CAAC,MAAM;IACjC;IAxBA,YAAYG,OAKX,CAAE;QAXH,uBAAO,QAAP;QACA,uBAAO,eAAP;QAEA,uBAAO,UAAP;QACA,uBAAO,YAAP;QAQE,IAAI,CAAC,IAAI,GAAGA,QAAQ,EAAE;QACtB,IAAI,CAAC,WAAW,GAAGA,QAAQ,WAAW;QACtC,IAAI,CAAC,MAAM,GAAGA,QAAQ,UAAU;QAChC,IAAI,CAAC,QAAQ,GAAGA,QAAQ,QAAQ;IAClC;AAeF"}