// Lordevo tools for LangChain JS (@langchain/core 1.x). // Wraps the lordevo-x402 client's toolDefs(): one LangChain tool per Lordevo tool, JSON-schema input, paid per call // with x402 (USDC on Base), free trial first when the client was made with { trial: true }. import { tool } from '@langchain/core/tools'; // The 5 tools this drop-in exposes by default (all $0.003 per call). Pass your own list to change it. export const DEFAULT_TOOLS = ['page-markdown', 'can-fetch', 'tech-stack', 'dns-lookup', 'email-validate']; // Errors reach the model as JSON it can read (error, message, charged), instead of an exception that ends the run. export const errorJson = e => JSON.stringify({ error: e?.code || (e?.status ? `http_${e.status}` : 'client_error'), message: String(e?.message || e), charged: e?.status ? (e.charged ?? false) : false, ...(e?.trial ? { free_trial: e.trial } : {}) }); /** lordevo: a client from lordevo-x402 (createLordevo / fromPrivateKey). only: tool slugs (default DEFAULT_TOOLS). */ export function lordevoTools(lordevo, only = DEFAULT_TOOLS) { const defs = lordevo.toolDefs(only).sort((a, b) => only.indexOf(a.name.replace(/_/g, '-')) - only.indexOf(b.name.replace(/_/g, '-'))); // keep the caller's order return defs.map(d => tool( async input => { try { return JSON.stringify(await d.execute(input)); } catch (e) { return errorJson(e); } }, { name: d.name, description: d.description, schema: d.parameters }, )); }