{"version":3,"file":"get_message.cjs","names":["z","GmailBaseTool","GET_MESSAGE_DESCRIPTION","fields?: GmailBaseToolParams","arg: InferInteropZodOutput<GetMessageSchema>"],"sources":["../../../src/tools/gmail/get_message.ts"],"sourcesContent":["import { z } from \"zod/v3\";\nimport { InferInteropZodOutput } from \"@langchain/core/utils/types\";\nimport { GmailBaseToolParams, GmailBaseTool } from \"./base.js\";\nimport { GET_MESSAGE_DESCRIPTION } from \"./descriptions.js\";\n\nconst getMessageSchema = z.object({\n  messageId: z.string(),\n});\nexport type GetMessageSchema = z.infer<typeof getMessageSchema>;\n\nexport class GmailGetMessage extends GmailBaseTool {\n  name = \"gmail_get_message\";\n\n  schema = getMessageSchema;\n\n  description = GET_MESSAGE_DESCRIPTION;\n\n  constructor(fields?: GmailBaseToolParams) {\n    super(fields);\n  }\n\n  async _call(arg: InferInteropZodOutput<GetMessageSchema>) {\n    const { messageId } = arg;\n\n    const gmail = await this.getGmailClient();\n\n    const { data } = await gmail.users.messages.get({\n      userId: \"me\",\n      format: \"full\",\n\n      id: messageId,\n    });\n\n    if (!data) {\n      throw new Error(\"No data returned from Gmail\");\n    }\n\n    const { payload } = data;\n\n    if (!payload) {\n      throw new Error(\"No payload returned from Gmail\");\n    }\n\n    const { headers } = payload;\n\n    if (!headers) {\n      throw new Error(\"No headers returned from Gmail\");\n    }\n\n    const { subject, sender, body } = this.parseHeaderAndBody(payload);\n\n    if (!subject) {\n      throw new Error(\"No subject returned from Gmail\");\n    }\n\n    if (!body) {\n      throw new Error(\"No body returned from Gmail\");\n    }\n\n    if (!sender) {\n      throw new Error(\"No from returned from Gmail\");\n    }\n\n    const to = headers.find((header) => header.name === \"To\");\n\n    if (!to) {\n      throw new Error(\"No to returned from Gmail\");\n    }\n\n    const date = headers.find((header) => header.name === \"Date\");\n\n    if (!date) {\n      throw new Error(\"No date returned from Gmail\");\n    }\n\n    const messageIdHeader = headers.find(\n      (header) => header.name === \"Message-ID\"\n    );\n\n    if (!messageIdHeader) {\n      throw new Error(\"No message id returned from Gmail\");\n    }\n\n    return `Result for the prompt ${messageId} \\n${JSON.stringify({\n      subject: subject.value,\n      body,\n      from: sender.value,\n      to: to.value,\n      date: date.value,\n      messageId: messageIdHeader.value,\n    })}`;\n  }\n}\n"],"mappings":";;;;;;AAKA,MAAM,mBAAmBA,SAAE,OAAO,EAChC,WAAWA,SAAE,QAAQ,CACtB,EAAC;AAGF,IAAa,kBAAb,cAAqCC,2BAAc;CACjD,OAAO;CAEP,SAAS;CAET,cAAcC;CAEd,YAAYC,QAA8B;EACxC,MAAM,OAAO;CACd;CAED,MAAM,MAAMC,KAA8C;EACxD,MAAM,EAAE,WAAW,GAAG;EAEtB,MAAM,QAAQ,MAAM,KAAK,gBAAgB;EAEzC,MAAM,EAAE,MAAM,GAAG,MAAM,MAAM,MAAM,SAAS,IAAI;GAC9C,QAAQ;GACR,QAAQ;GAER,IAAI;EACL,EAAC;AAEF,MAAI,CAAC,KACH,OAAM,IAAI,MAAM;EAGlB,MAAM,EAAE,SAAS,GAAG;AAEpB,MAAI,CAAC,QACH,OAAM,IAAI,MAAM;EAGlB,MAAM,EAAE,SAAS,GAAG;AAEpB,MAAI,CAAC,QACH,OAAM,IAAI,MAAM;EAGlB,MAAM,EAAE,SAAS,QAAQ,MAAM,GAAG,KAAK,mBAAmB,QAAQ;AAElE,MAAI,CAAC,QACH,OAAM,IAAI,MAAM;AAGlB,MAAI,CAAC,KACH,OAAM,IAAI,MAAM;AAGlB,MAAI,CAAC,OACH,OAAM,IAAI,MAAM;EAGlB,MAAM,KAAK,QAAQ,KAAK,CAAC,WAAW,OAAO,SAAS,KAAK;AAEzD,MAAI,CAAC,GACH,OAAM,IAAI,MAAM;EAGlB,MAAM,OAAO,QAAQ,KAAK,CAAC,WAAW,OAAO,SAAS,OAAO;AAE7D,MAAI,CAAC,KACH,OAAM,IAAI,MAAM;EAGlB,MAAM,kBAAkB,QAAQ,KAC9B,CAAC,WAAW,OAAO,SAAS,aAC7B;AAED,MAAI,CAAC,gBACH,OAAM,IAAI,MAAM;AAGlB,SAAO,CAAC,sBAAsB,EAAE,UAAU,GAAG,EAAE,KAAK,UAAU;GAC5D,SAAS,QAAQ;GACjB;GACA,MAAM,OAAO;GACb,IAAI,GAAG;GACP,MAAM,KAAK;GACX,WAAW,gBAAgB;EAC5B,EAAC,EAAE;CACL;AACF"}