{"version":3,"file":"Calculator.mjs","sources":["../../../src/tools/Calculator.ts"],"sourcesContent":["import { Tool } from '@langchain/core/tools';\nimport * as math from 'mathjs';\n\nexport const CalculatorToolName = 'calculator';\n\nexport const CalculatorToolDescription =\n  'Useful for getting the result of a math expression. The input to this tool should be a valid mathematical expression that could be executed by a simple calculator.';\n\nexport const CalculatorSchema = {\n  type: 'object',\n  properties: {\n    input: {\n      type: 'string',\n      description: 'A valid mathematical expression to evaluate',\n    },\n  },\n  required: ['input'],\n} as const;\n\nexport const CalculatorToolDefinition = {\n  name: CalculatorToolName,\n  description: CalculatorToolDescription,\n  schema: CalculatorSchema,\n} as const;\n\nexport class Calculator extends Tool {\n  static lc_name(): string {\n    return 'Calculator';\n  }\n\n  get lc_namespace(): string[] {\n    return [...super.lc_namespace, 'calculator'];\n  }\n\n  name = CalculatorToolName;\n\n  async _call(input: string): Promise<string> {\n    try {\n      return math.evaluate(input).toString();\n    } catch {\n      return 'I don\\'t know how to do that.';\n    }\n  }\n\n  description = CalculatorToolDescription;\n}\n"],"names":[],"mappings":";;;AAGO,MAAM,kBAAkB,GAAG;AAE3B,MAAM,yBAAyB,GACpC;AAEK,MAAM,gBAAgB,GAAG;AAC9B,IAAA,IAAI,EAAE,QAAQ;AACd,IAAA,UAAU,EAAE;AACV,QAAA,KAAK,EAAE;AACL,YAAA,IAAI,EAAE,QAAQ;AACd,YAAA,WAAW,EAAE,6CAA6C;AAC3D,SAAA;AACF,KAAA;IACD,QAAQ,EAAE,CAAC,OAAO,CAAC;;AAGd,MAAM,wBAAwB,GAAG;AACtC,IAAA,IAAI,EAAE,kBAAkB;AACxB,IAAA,WAAW,EAAE,yBAAyB;AACtC,IAAA,MAAM,EAAE,gBAAgB;;AAGpB,MAAO,UAAW,SAAQ,IAAI,CAAA;AAClC,IAAA,OAAO,OAAO,GAAA;AACZ,QAAA,OAAO,YAAY;IACrB;AAEA,IAAA,IAAI,YAAY,GAAA;QACd,OAAO,CAAC,GAAG,KAAK,CAAC,YAAY,EAAE,YAAY,CAAC;IAC9C;IAEA,IAAI,GAAG,kBAAkB;IAEzB,MAAM,KAAK,CAAC,KAAa,EAAA;AACvB,QAAA,IAAI;YACF,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE;QACxC;AAAE,QAAA,MAAM;AACN,YAAA,OAAO,+BAA+B;QACxC;IACF;IAEA,WAAW,GAAG,yBAAyB;AACxC;;;;"}