// Lordevo tools for the Vercel AI SDK (ai 7.x). // Wraps the lordevo-x402 client's toolDefs(): returns the { name: tool } record that generateText / streamText take. // Paid per call with x402 (USDC on Base), free trial first when the client was made with { trial: true }. import { jsonSchema, tool } from 'ai'; // 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 an object it can read (error, message, charged), instead of an exception that ends the run. export const errorObject = e => ({ 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); return Object.fromEntries(only.map(slug => defs.find(d => d.name === slug.replace(/-/g, '_'))).filter(Boolean).map(d => [d.name, tool({ description: d.description, inputSchema: jsonSchema(d.parameters), execute: async input => { try { return await d.execute(input); } catch (e) { return errorObject(e); } }, })])); }