UNPKG

@plastichub/osr-ai-tools

Version:

CLI and library for LLM tools

99 lines (98 loc) 4.25 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.tools = exports.md2html = void 0; const path_1 = __importDefault(require("path")); const showdown_1 = require("showdown"); const nodemailer_1 = require("@plastichub/osr-mail/lib/nodemailer"); const md2html = (content) => { let converter = new showdown_1.Converter({ tables: true }); converter.setOption('literalMidWordUnderscores', 'true'); return converter.makeHtml(content); }; exports.md2html = md2html; const sendOptions = (recipient = 'cgoflyn@gmail.com', subject, body = 'en') => { const contacts = Array.isArray(recipient) ? recipient : [recipient]; return { from: 'PlasticHub <newsletter@osr-plastic.org>', transport: 'newsletter', subject, contacts, filter: true, query: null, to: null, source: body }; }; const __1 = require("../.."); const tools = (target, options) => { const logger = (0, __1.toolLogger)(path_1.default.parse(__filename).name, options); return [ { type: 'function', function: { name: 'send_email', description: 'Sends an email', parameters: { type: 'object', properties: { recipient: { type: ['string', 'array'], items: { type: 'string' }, description: 'The email address of the recipient(s). Can be a single email or an array of emails. For "me", use the default email address', }, subject: { type: 'string', description: 'the subject', optional: true }, body: { type: 'string', description: 'Markdown formatted body of the email', optional: true } }, required: ['url'] }, function: async (params) => { logger.debug(`Tool::EMail:Send ${params.recipient}`); const sendMail = async (recipients, subject, body, raw) => { const recipientList = Array.isArray(recipients) ? recipients : [recipients]; for (const recipient of recipientList) { if (!recipient) { logger.error(`Invalid contact : ${recipient}`); continue; } const opts = { ...options, from: 'PlasticHub <newsletter@osr-plastic.org>', subject: subject, transport: "newsletter", to: recipient, html: body, attachments: [ { content: raw, filename: 'body.md', contentDisposition: 'attachment', } ], }; return await (0, nodemailer_1.test)(opts); } }; const recipient = params.recipient === 'me' ? options.variables.DEFAULT_EMAIL || 'cgoflyn@gmail.com' : params.recipient; sendMail(recipient, params.subject, (0, exports.md2html)(params.body), params.body); }, parse: JSON.parse } } ]; }; exports.tools = tools;