// Lordevo tools for the OpenAI Agents SDK, JavaScript (@openai/agents). // Wraps the lordevo-x402 client's toolDefs(): one function tool per Lordevo tool, paid per call with x402 (USDC on // Base), free trial first when the client was made with { trial: true }. Strict schemas: optional inputs are nullable. import { tool } from '@openai/agents'; // 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 } : {}) }); // The SDK's strict mode wants every property required: optional inputs become nullable (null = not given). export function strictSchema(s) { const properties = Object.fromEntries(Object.entries(s.properties).map(([k, p]) => [k, s.required.includes(k) ? p : { ...p, type: ['string', 'null'], ...(p.enum ? { enum: [...p.enum, null] } : {}) }])); return { type: 'object', properties, required: Object.keys(properties), additionalProperties: false }; } /** 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 only.map(slug => defs.find(d => d.name === slug.replace(/-/g, '_'))).filter(Boolean).map(d => tool({ name: d.name, description: d.description, parameters: strictSchema(d.parameters), strict: true, execute: async input => { try { return JSON.stringify(await d.execute(input)); } catch (e) { return errorJson(e); } }, })); }