UNPKG

kestrel.markets

Version:

A typed, token-efficient language + runtime for agentic trading: agents author bounded plans, the runtime fires them at the tick. CLI + typed library + MCP server.

58 lines (56 loc) 2.53 kB
// src/cli/render/offer.ts function renderOffer(p, ctx) { if (ctx.mode === "json") { process.stdout.write(JSON.stringify({ schema: "kestrel.payment-required/v1", ...p }) + ` `); return; } const o = p.offer; const amount = `${o.amount.value} ${o.amount.asset}`; const methods = p.settlement_methods.map((m) => m.method).join(","); const human = p.human_action?.url ?? "(none)"; const proof = p.proof?.url ?? p.proof?.proof_id ?? "(none)"; if (ctx.mode === "text") { process.stdout.write(`payment-required operation=${p.operation_id} offer=${o.offer_id} scope=${o.scope.join("+")}` + ` amount=${amount} ceiling=${o.ceiling} methods=${methods}` + ` human=${human} proof=${proof} `); return; } process.stdout.write(`Payment required to continue operation ${p.operation_id} ` + ` earned proof: ${proof} ` + ` offer ${o.offer_id}: ${amount} for scope ${o.scope.join("+")} (ceiling ${o.ceiling}) ` + ` machine settlement: ${p.settlement_methods.map((m) => m.method).join(", ")} ` + ` human claim-and-fund: ${human} `); } function renderSettlementRequired(s, ctx) { const o = s.offer; const amount = `${o.amount.value} ${o.amount.asset}`; const r = s.resume; const settleUrl = s.settlement?.url ?? "(settle the offer, then resume)"; if (ctx.mode === "json") { process.stdout.write(JSON.stringify({ schema: "kestrel.payment-required/v1", boundary: "settlement", operation_id: s.operationId, offer: o, ...s.settlement !== undefined ? { settlement: s.settlement } : {}, resume: r }) + ` `); return; } if (ctx.mode === "text") { process.stdout.write(`payment-required boundary=settlement operation=${s.operationId} offer=${o.offer_id}` + ` scope=${o.scope.join("+")} amount=${amount} ceiling=${o.ceiling} expiry=${o.expiry}` + ` settle=${settleUrl} resume=${r.method} ${r.path} requires_settlement=${r.requires_settlement}` + ` detail=${r.detail} `); return; } const settleLine = s.settlement !== undefined ? ` settle at: ${s.settlement.method} ${s.settlement.url} (offer ${o.offer_id}) ` : ` settle the offer ${o.offer_id}, then resume `; process.stdout.write(`Payment required to continue operation ${s.operationId} (Spend boundary) ` + ` offer ${o.offer_id}: ${amount} for scope ${o.scope.join("+")} (ceiling ${o.ceiling}, expires ${o.expiry}) ` + settleLine + ` then resume: ${r.method} ${r.path} (operation ${s.operationId}, cursor ${r.cursor}) ` + ` ${r.detail} `); } export { renderOffer, renderSettlementRequired };