// Local check of a LAX offer against the registry's published rules
// (https://lax.kognai.ai/aiax/sections/lax_offer.json, saved as lax_offer.schema.json).
export const FIVE_LAWS = ['Solidarity Oath', 'Renewal Mandate', 'Treasury Equilibrium', 'Harm Shield', 'Transparency Covenant'];
export function offerProblems(o: Record<string, any>): string[] {
const p: string[] = [];
const str = (v: unknown, min: number, max: number) => typeof v === 'string' && v.length >= min && v.length <= max;
if (o.lax_version !== undefined && o.lax_version !== '1.0') p.push('lax_version must be 1.0');
if (!str(o.name, 3, 80)) p.push('name must be 3 to 80 characters');
if (!str(o.description, 20, 600)) p.push('description must be 20 to 600 characters');
if (o.category !== undefined && !str(o.category, 2, 40)) p.push('category must be 2 to 40 characters');
const https = (v: unknown) => typeof v === 'string' && /^https:\/\/[^\s/]+/.test(v);
if (!https(o.endpoint) && !https(o.pact_endpoint)) p.push('an https endpoint or pact_endpoint is required');
if (o.agent_did !== undefined && !/^did:[a-z0-9]+:.+/.test(o.agent_did)) p.push('agent_did must be a DID');
if (!Array.isArray(o.capabilities) || o.capabilities.length < 1 || o.capabilities.length > 10) p.push('1 to 10 capabilities');
for (const c of o.capabilities ?? []) {
if (!c.skill_id || !c.description) p.push('capability needs skill_id and description');
const pr = c.pricing ?? {};
if (!['per_call', 'per_minute', 'flat', 'free'].includes(pr.model)) p.push('pricing.model');
if (pr.currency !== 'USDC' || pr.rail !== 'x402') p.push('pricing must be USDC over x402');
if (pr.model !== 'free' && !/^\d+(\.\d+)?$/.test(String(pr.amount))) p.push('pricing.amount');
}
for (const law of FIVE_LAWS) if (!(o.constitutional_constraints ?? []).includes(law)) p.push(`missing law: ${law}`);
for (const r of o.payment_rails ?? []) if (!['x402', 'usdc', 'usdc-base'].includes(r)) p.push(`payment rail ${r}`);
if (/0x[0-9a-fA-F]{40}/.test(`${o.name} ${o.description}`)) p.push('no 0x address in visible text');
if (/[\u2013\u2014]/.test(JSON.stringify(o))) p.push('no long dashes');
return p;
}
agentgate-source: code mirror on Cloudflare Pages. All repos