{"version":3,"file":"requests.cjs","names":["Tool"],"sources":["../../src/tools/requests.ts"],"sourcesContent":["import { Tool } from \"@langchain/core/tools\";\n\nexport interface Headers {\n  [key: string]: string;\n}\n\n/**\n * Interface for HTTP request tools. Contains properties for headers and\n * maximum output length.\n */\nexport interface RequestTool {\n  headers: Headers;\n  maxOutputLength: number;\n}\n\n/**\n * Class for making GET requests. Extends the Tool class and implements\n * the RequestTool interface. The input should be a URL string, and the\n * output will be the text response of the GET request.\n */\nexport class RequestsGetTool extends Tool implements RequestTool {\n  static lc_name() {\n    return \"RequestsGetTool\";\n  }\n\n  name = \"requests_get\";\n\n  maxOutputLength = 2000;\n\n  constructor(\n    public headers: Headers = {},\n    { maxOutputLength }: { maxOutputLength?: number } = {}\n  ) {\n    super(...arguments);\n\n    this.maxOutputLength = maxOutputLength ?? this.maxOutputLength;\n  }\n\n  /** @ignore */\n  async _call(input: string) {\n    const res = await fetch(input, {\n      headers: this.headers,\n    });\n    const text = await res.text();\n    return text.slice(0, this.maxOutputLength);\n  }\n\n  description = `A portal to the internet. Use this when you need to get specific content from a website.\n  Input should be a url string (i.e. \"https://www.google.com\"). The output will be the text response of the GET request.`;\n}\n\n/**\n * Class for making POST requests. Extends the Tool class and implements\n * the RequestTool interface. The input should be a JSON string with two\n * keys: 'url' and 'data'. The output will be the text response of the\n * POST request.\n */\nexport class RequestsPostTool extends Tool implements RequestTool {\n  static lc_name() {\n    return \"RequestsPostTool\";\n  }\n\n  name = \"requests_post\";\n\n  maxOutputLength = Infinity;\n\n  constructor(\n    public headers: Headers = {},\n    { maxOutputLength }: { maxOutputLength?: number } = {}\n  ) {\n    super(...arguments);\n\n    this.maxOutputLength = maxOutputLength ?? this.maxOutputLength;\n  }\n\n  /** @ignore */\n  async _call(input: string) {\n    try {\n      const { url, data } = JSON.parse(input);\n      const res = await fetch(url, {\n        method: \"POST\",\n        headers: this.headers,\n        body: JSON.stringify(data),\n      });\n      const text = await res.text();\n      return text.slice(0, this.maxOutputLength);\n    } catch (error) {\n      return `${error}`;\n    }\n  }\n\n  description = `Use this when you want to POST to a website.\n  Input should be a json string with two keys: \"url\" and \"data\".\n  The value of \"url\" should be a string, and the value of \"data\" should be a dictionary of\n  key-value pairs you want to POST to the url as a JSON body.\n  Be careful to always use double quotes for strings in the json string\n  The output will be the text response of the POST request.`;\n}\n"],"mappings":";;;;;;;;AAoBA,IAAa,kBAAb,cAAqCA,sBAAAA,KAA4B;CAC/D,OAAO,UAAU;AACf,SAAO;;CAGT,OAAO;CAEP,kBAAkB;CAElB,YACE,UAA0B,EAAE,EAC5B,EAAE,oBAAkD,EAAE,EACtD;AACA,QAAM,GAAG,UAAU;AAHZ,OAAA,UAAA;AAKP,OAAK,kBAAkB,mBAAmB,KAAK;;;CAIjD,MAAM,MAAM,OAAe;AAKzB,UADa,OAHD,MAAM,MAAM,OAAO,EAC7B,SAAS,KAAK,SACf,CAAC,EACqB,MAAM,EACjB,MAAM,GAAG,KAAK,gBAAgB;;CAG5C,cAAc;;;;;;;;;AAUhB,IAAa,mBAAb,cAAsCA,sBAAAA,KAA4B;CAChE,OAAO,UAAU;AACf,SAAO;;CAGT,OAAO;CAEP,kBAAkB;CAElB,YACE,UAA0B,EAAE,EAC5B,EAAE,oBAAkD,EAAE,EACtD;AACA,QAAM,GAAG,UAAU;AAHZ,OAAA,UAAA;AAKP,OAAK,kBAAkB,mBAAmB,KAAK;;;CAIjD,MAAM,MAAM,OAAe;AACzB,MAAI;GACF,MAAM,EAAE,KAAK,SAAS,KAAK,MAAM,MAAM;AAOvC,WADa,OALD,MAAM,MAAM,KAAK;IAC3B,QAAQ;IACR,SAAS,KAAK;IACd,MAAM,KAAK,UAAU,KAAK;IAC3B,CAAC,EACqB,MAAM,EACjB,MAAM,GAAG,KAAK,gBAAgB;WACnC,OAAO;AACd,UAAO,GAAG;;;CAId,cAAc"}