x402-trust-layer 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +55 -0
- package/DEPLOY.md +53 -0
- package/Dockerfile +30 -0
- package/LICENSE +21 -0
- package/README.md +294 -0
- package/dist/agents/a2a-payment.d.ts +37 -0
- package/dist/agents/a2a-payment.js +105 -0
- package/dist/agents/agent-escrow.d.ts +30 -0
- package/dist/agents/agent-escrow.js +23 -0
- package/dist/agents/agent-verify.d.ts +15 -0
- package/dist/agents/agent-verify.js +112 -0
- package/dist/agents/api-router.d.ts +32 -0
- package/dist/agents/api-router.js +228 -0
- package/dist/agents/attestation-registry.d.ts +35 -0
- package/dist/agents/attestation-registry.js +76 -0
- package/dist/agents/audition-coach.d.ts +45 -0
- package/dist/agents/audition-coach.js +257 -0
- package/dist/agents/bedrock-bridge.d.ts +3 -0
- package/dist/agents/bedrock-bridge.js +60 -0
- package/dist/agents/budget-allocator.d.ts +24 -0
- package/dist/agents/budget-allocator.js +31 -0
- package/dist/agents/compliance-ledger.d.ts +66 -0
- package/dist/agents/compliance-ledger.js +80 -0
- package/dist/agents/dispute-resolver.d.ts +62 -0
- package/dist/agents/dispute-resolver.js +124 -0
- package/dist/agents/evidence-locker.d.ts +30 -0
- package/dist/agents/evidence-locker.js +47 -0
- package/dist/agents/facilitator-failover.d.ts +15 -0
- package/dist/agents/facilitator-failover.js +18 -0
- package/dist/agents/identity-gate.d.ts +20 -0
- package/dist/agents/identity-gate.js +79 -0
- package/dist/agents/mandate-compiler.d.ts +51 -0
- package/dist/agents/mandate-compiler.js +73 -0
- package/dist/agents/mandate-diff.d.ts +41 -0
- package/dist/agents/mandate-diff.js +170 -0
- package/dist/agents/market-buy-advisor.d.ts +65 -0
- package/dist/agents/market-buy-advisor.js +234 -0
- package/dist/agents/merchant-trust.d.ts +38 -0
- package/dist/agents/merchant-trust.js +171 -0
- package/dist/agents/mpp-session-broker.d.ts +27 -0
- package/dist/agents/mpp-session-broker.js +29 -0
- package/dist/agents/mpp-session-v2.d.ts +76 -0
- package/dist/agents/mpp-session-v2.js +269 -0
- package/dist/agents/payment-intent-compiler.d.ts +21 -0
- package/dist/agents/payment-intent-compiler.js +45 -0
- package/dist/agents/pipeline-execute.d.ts +40 -0
- package/dist/agents/pipeline-execute.js +100 -0
- package/dist/agents/pipeline-trust-v2.d.ts +31 -0
- package/dist/agents/pipeline-trust-v2.js +111 -0
- package/dist/agents/pre-x402-guard.d.ts +35 -0
- package/dist/agents/pre-x402-guard.js +84 -0
- package/dist/agents/quality-escrow-semantic.d.ts +88 -0
- package/dist/agents/quality-escrow-semantic.js +137 -0
- package/dist/agents/quality-escrow.d.ts +65 -0
- package/dist/agents/quality-escrow.js +104 -0
- package/dist/agents/quality-monitor.d.ts +32 -0
- package/dist/agents/quality-monitor.js +77 -0
- package/dist/agents/rail-optimizer.d.ts +33 -0
- package/dist/agents/rail-optimizer.js +133 -0
- package/dist/agents/receipt-auditor.d.ts +14 -0
- package/dist/agents/receipt-auditor.js +145 -0
- package/dist/agents/refund-arbiter.d.ts +24 -0
- package/dist/agents/refund-arbiter.js +70 -0
- package/dist/agents/research-brief.d.ts +14 -0
- package/dist/agents/research-brief.js +66 -0
- package/dist/agents/risk-gate.d.ts +11 -0
- package/dist/agents/risk-gate.js +78 -0
- package/dist/agents/settlement-graph.d.ts +16 -0
- package/dist/agents/settlement-graph.js +38 -0
- package/dist/agents/spend-governor.d.ts +2 -0
- package/dist/agents/spend-governor.js +70 -0
- package/dist/agents/trust-network.d.ts +138 -0
- package/dist/agents/trust-network.js +244 -0
- package/dist/agents/x402-proxy.d.ts +32 -0
- package/dist/agents/x402-proxy.js +90 -0
- package/dist/client/demo-alchemy-live.d.ts +1 -0
- package/dist/client/demo-alchemy-live.js +226 -0
- package/dist/client/demo-tail.d.ts +1 -0
- package/dist/client/demo-tail.js +100 -0
- package/dist/client/demo.d.ts +1 -0
- package/dist/client/demo.js +293 -0
- package/dist/config.d.ts +94 -0
- package/dist/config.js +223 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +389 -0
- package/dist/lib/agent-response.d.ts +14 -0
- package/dist/lib/agent-response.js +13 -0
- package/dist/lib/agentic-gateways.d.ts +5 -0
- package/dist/lib/agentic-gateways.js +15 -0
- package/dist/lib/agentic-probes.d.ts +10 -0
- package/dist/lib/agentic-probes.js +49 -0
- package/dist/lib/alchemy-x402-fetch.d.ts +16 -0
- package/dist/lib/alchemy-x402-fetch.js +95 -0
- package/dist/lib/apply-verifier-body.d.ts +7 -0
- package/dist/lib/apply-verifier-body.js +179 -0
- package/dist/lib/attestation.d.ts +30 -0
- package/dist/lib/attestation.js +107 -0
- package/dist/lib/bazaar-extension.d.ts +15 -0
- package/dist/lib/bazaar-extension.js +265 -0
- package/dist/lib/bazaar.d.ts +100 -0
- package/dist/lib/bazaar.js +341 -0
- package/dist/lib/certified-sellers.d.ts +41 -0
- package/dist/lib/certified-sellers.js +129 -0
- package/dist/lib/chains.d.ts +20 -0
- package/dist/lib/chains.js +78 -0
- package/dist/lib/db-persistence.d.ts +7 -0
- package/dist/lib/db-persistence.js +65 -0
- package/dist/lib/db.d.ts +5 -0
- package/dist/lib/db.js +113 -0
- package/dist/lib/discovery-page.d.ts +2 -0
- package/dist/lib/discovery-page.js +71 -0
- package/dist/lib/ecosystem-telemetry.d.ts +20 -0
- package/dist/lib/ecosystem-telemetry.js +80 -0
- package/dist/lib/erc8004/agent-card.d.ts +34 -0
- package/dist/lib/erc8004/agent-card.js +151 -0
- package/dist/lib/erc8004/cache.d.ts +3 -0
- package/dist/lib/erc8004/cache.js +17 -0
- package/dist/lib/erc8004/constants.d.ts +22 -0
- package/dist/lib/erc8004/constants.js +35 -0
- package/dist/lib/erc8004/registry.d.ts +19 -0
- package/dist/lib/erc8004/registry.js +171 -0
- package/dist/lib/erc8004/resolve-agent.d.ts +7 -0
- package/dist/lib/erc8004/resolve-agent.js +70 -0
- package/dist/lib/erc8004/trust-score.d.ts +33 -0
- package/dist/lib/erc8004/trust-score.js +136 -0
- package/dist/lib/escrow-ledger.d.ts +14 -0
- package/dist/lib/escrow-ledger.js +54 -0
- package/dist/lib/escrow-unified.d.ts +15 -0
- package/dist/lib/escrow-unified.js +28 -0
- package/dist/lib/facilitator-extra.d.ts +13 -0
- package/dist/lib/facilitator-extra.js +52 -0
- package/dist/lib/facilitators.d.ts +20 -0
- package/dist/lib/facilitators.js +89 -0
- package/dist/lib/host-policy.d.ts +4 -0
- package/dist/lib/host-policy.js +20 -0
- package/dist/lib/idempotency.d.ts +4 -0
- package/dist/lib/idempotency.js +120 -0
- package/dist/lib/ledger.d.ts +2 -0
- package/dist/lib/ledger.js +17 -0
- package/dist/lib/logger.d.ts +6 -0
- package/dist/lib/logger.js +24 -0
- package/dist/lib/mandate-vc.d.ts +20 -0
- package/dist/lib/mandate-vc.js +25 -0
- package/dist/lib/mandate.d.ts +44 -0
- package/dist/lib/mandate.js +190 -0
- package/dist/lib/marketplace.d.ts +7 -0
- package/dist/lib/marketplace.js +127 -0
- package/dist/lib/migrations.d.ts +2 -0
- package/dist/lib/migrations.js +130 -0
- package/dist/lib/nonce-store.d.ts +6 -0
- package/dist/lib/nonce-store.js +109 -0
- package/dist/lib/openapi-agentcash.d.ts +5 -0
- package/dist/lib/openapi-agentcash.js +288 -0
- package/dist/lib/openapi-meta.d.ts +5 -0
- package/dist/lib/openapi-meta.js +235 -0
- package/dist/lib/otel.d.ts +2 -0
- package/dist/lib/otel.js +25 -0
- package/dist/lib/paid-resource-url.d.ts +6 -0
- package/dist/lib/paid-resource-url.js +47 -0
- package/dist/lib/parse-with-verifier-fallback.d.ts +3 -0
- package/dist/lib/parse-with-verifier-fallback.js +13 -0
- package/dist/lib/payment-request-context.d.ts +10 -0
- package/dist/lib/payment-request-context.js +5 -0
- package/dist/lib/payment-response.d.ts +13 -0
- package/dist/lib/payment-response.js +39 -0
- package/dist/lib/payto-guard.d.ts +10 -0
- package/dist/lib/payto-guard.js +20 -0
- package/dist/lib/probe.d.ts +29 -0
- package/dist/lib/probe.js +157 -0
- package/dist/lib/problem-detail.d.ts +10 -0
- package/dist/lib/problem-detail.js +14 -0
- package/dist/lib/rate-limit.d.ts +12 -0
- package/dist/lib/rate-limit.js +126 -0
- package/dist/lib/replay-middleware.d.ts +3 -0
- package/dist/lib/replay-middleware.js +27 -0
- package/dist/lib/response-guard.d.ts +5 -0
- package/dist/lib/response-guard.js +40 -0
- package/dist/lib/safe-fetch.d.ts +5 -0
- package/dist/lib/safe-fetch.js +19 -0
- package/dist/lib/security.d.ts +13 -0
- package/dist/lib/security.js +61 -0
- package/dist/lib/semantic-judge.d.ts +14 -0
- package/dist/lib/semantic-judge.js +107 -0
- package/dist/lib/semantic-judge.test.d.ts +1 -0
- package/dist/lib/semantic-judge.test.js +11 -0
- package/dist/lib/ssrf.d.ts +10 -0
- package/dist/lib/ssrf.js +130 -0
- package/dist/lib/ssrf.test.d.ts +1 -0
- package/dist/lib/ssrf.test.js +16 -0
- package/dist/lib/suite-catalog.d.ts +83 -0
- package/dist/lib/suite-catalog.js +131 -0
- package/dist/lib/telemetry.d.ts +5 -0
- package/dist/lib/telemetry.js +37 -0
- package/dist/lib/verifier-fast-path.d.ts +10 -0
- package/dist/lib/verifier-fast-path.js +44 -0
- package/dist/lib/verifier-probe-protocol.d.ts +7 -0
- package/dist/lib/verifier-probe-protocol.js +115 -0
- package/dist/lib/verify-examples.d.ts +2 -0
- package/dist/lib/verify-examples.js +438 -0
- package/dist/lib/version.d.ts +2 -0
- package/dist/lib/version.js +2 -0
- package/dist/lib/webhook-auth.d.ts +3 -0
- package/dist/lib/webhook-auth.js +34 -0
- package/dist/lib/webhook-routes.d.ts +2 -0
- package/dist/lib/webhook-routes.js +112 -0
- package/dist/lib/webhooks.d.ts +23 -0
- package/dist/lib/webhooks.js +123 -0
- package/dist/lib/webhooks.test.d.ts +1 -0
- package/dist/lib/webhooks.test.js +16 -0
- package/dist/lib/x402-client-options.d.ts +28 -0
- package/dist/lib/x402-client-options.js +138 -0
- package/dist/lib/x402-headers.d.ts +10 -0
- package/dist/lib/x402-headers.js +27 -0
- package/dist/lib/x402-paid.d.ts +5 -0
- package/dist/lib/x402-paid.js +252 -0
- package/dist/lib/x402-payment-replay.d.ts +22 -0
- package/dist/lib/x402-payment-replay.js +57 -0
- package/dist/lib/x402gle-host-verify.d.ts +3 -0
- package/dist/lib/x402gle-host-verify.js +27 -0
- package/dist/protocol/agent-passport.d.ts +34 -0
- package/dist/protocol/agent-passport.js +44 -0
- package/dist/protocol/compliance-v2.d.ts +21 -0
- package/dist/protocol/compliance-v2.js +19 -0
- package/dist/protocol/credit-bureau.d.ts +18 -0
- package/dist/protocol/credit-bureau.js +44 -0
- package/dist/protocol/crypto.d.ts +6 -0
- package/dist/protocol/crypto.js +41 -0
- package/dist/protocol/escrow-fsm.d.ts +33 -0
- package/dist/protocol/escrow-fsm.js +99 -0
- package/dist/protocol/fraud-engine.d.ts +28 -0
- package/dist/protocol/fraud-engine.js +77 -0
- package/dist/protocol/observability.d.ts +14 -0
- package/dist/protocol/observability.js +21 -0
- package/dist/protocol/pipeline-full-trust.d.ts +40 -0
- package/dist/protocol/pipeline-full-trust.js +96 -0
- package/dist/protocol/proof-of-execution.d.ts +36 -0
- package/dist/protocol/proof-of-execution.js +48 -0
- package/dist/protocol/reasoning-audit.d.ts +27 -0
- package/dist/protocol/reasoning-audit.js +51 -0
- package/dist/protocol/replay-guard.d.ts +28 -0
- package/dist/protocol/replay-guard.js +76 -0
- package/dist/protocol/replay-guard.test.d.ts +1 -0
- package/dist/protocol/replay-guard.test.js +10 -0
- package/dist/protocol/security-audit.d.ts +18 -0
- package/dist/protocol/security-audit.js +45 -0
- package/dist/protocol/store.d.ts +5 -0
- package/dist/protocol/store.js +59 -0
- package/dist/protocol/threat-catalog.d.ts +13 -0
- package/dist/protocol/threat-catalog.js +75 -0
- package/dist/protocol/trust-oracle.d.ts +23 -0
- package/dist/protocol/trust-oracle.js +30 -0
- package/dist/protocol/trust-score-v2.d.ts +33 -0
- package/dist/protocol/trust-score-v2.js +78 -0
- package/dist/protocol/zk-proofs.d.ts +24 -0
- package/dist/protocol/zk-proofs.js +32 -0
- package/dist/routes/a2a-agent-card.d.ts +3 -0
- package/dist/routes/a2a-agent-card.js +28 -0
- package/dist/routes/catalog.d.ts +5 -0
- package/dist/routes/catalog.js +47 -0
- package/dist/routes/register-all.d.ts +3 -0
- package/dist/routes/register-all.js +1240 -0
- package/dist/routes/schemas.d.ts +83 -0
- package/dist/routes/schemas.js +38 -0
- package/dist/routes/shared.d.ts +16 -0
- package/dist/routes/shared.js +27 -0
- package/dist/routes-protocol.d.ts +10 -0
- package/dist/routes-protocol.js +322 -0
- package/dist/routes.d.ts +2 -0
- package/dist/routes.js +2 -0
- package/dist/types.d.ts +66 -0
- package/dist/types.js +1 -0
- package/openapi.json +7940 -0
- package/package.json +124 -0
- package/public/.well-known/ai-plugin.json +12 -0
- package/public/assets/aegis-logo-blue.png +0 -0
- package/public/assets/aegis-logo-gold.png +0 -0
- package/public/assets/aegis-logo-green.png +0 -0
- package/public/assets/aegis-logo-purple.png +0 -0
- package/public/assets/aegis-logo-red.png +0 -0
- package/public/assets/aegis-logo-white.png +0 -0
- package/public/assets/aegis-logo.png +0 -0
- package/public/assets/x402-trustlayer-logo.png +0 -0
- package/public/assets/x402-trustlayer-logo.svg +5 -0
- package/public/data/agents.json +1528 -0
- package/public/index.html +198 -0
- package/public/landing.css +342 -0
- package/public/landing.js +405 -0
- package/public/llms-full.txt +582 -0
- package/public/llms.txt +132 -0
- package/public/skill.md +135 -0
- package/railway.toml +9 -0
- package/scripts/docker-entrypoint.sh +7 -0
- package/scripts/patch-facilitator-timeout.mjs +61 -0
|
@@ -0,0 +1,1240 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { runAgentVerify } from "../agents/agent-verify.js";
|
|
3
|
+
import { runAgentEscrow } from "../agents/agent-escrow.js";
|
|
4
|
+
import { runApiRouter } from "../agents/api-router.js";
|
|
5
|
+
import { runBudgetAllocator } from "../agents/budget-allocator.js";
|
|
6
|
+
import { runEvidenceLocker } from "../agents/evidence-locker.js";
|
|
7
|
+
import { runFacilitatorFailover } from "../agents/facilitator-failover.js";
|
|
8
|
+
import { runIdentityGate } from "../agents/identity-gate.js";
|
|
9
|
+
import { runMppSessionBroker } from "../agents/mpp-session-broker.js";
|
|
10
|
+
import { runPaymentIntentCompiler } from "../agents/payment-intent-compiler.js";
|
|
11
|
+
import { runQualityMonitor } from "../agents/quality-monitor.js";
|
|
12
|
+
import { runReceiptAuditor } from "../agents/receipt-auditor.js";
|
|
13
|
+
import { runRefundArbiter } from "../agents/refund-arbiter.js";
|
|
14
|
+
import { runResearchBrief } from "../agents/research-brief.js";
|
|
15
|
+
import { runRiskGate } from "../agents/risk-gate.js";
|
|
16
|
+
import { runSettlementGraph } from "../agents/settlement-graph.js";
|
|
17
|
+
import { runAttestationIssue, runAttestationVerify, runTrustRegistryQuery } from "../agents/attestation-registry.js";
|
|
18
|
+
import { runMppSessionV2 } from "../agents/mpp-session-v2.js";
|
|
19
|
+
import { runPipelineExecute } from "../agents/pipeline-execute.js";
|
|
20
|
+
import { runPreX402Guard } from "../agents/pre-x402-guard.js";
|
|
21
|
+
import { runSpendGovernor } from "../agents/spend-governor.js";
|
|
22
|
+
import { runAuditionCoach } from "../agents/audition-coach.js";
|
|
23
|
+
import { runMarketBuyAdvisor } from "../agents/market-buy-advisor.js";
|
|
24
|
+
import { runX402Proxy } from "../agents/x402-proxy.js";
|
|
25
|
+
import { runMerchantTrust } from "../agents/merchant-trust.js";
|
|
26
|
+
import { runMandateCompile, runMandateVerify } from "../agents/mandate-compiler.js";
|
|
27
|
+
import { runRailOptimizer } from "../agents/rail-optimizer.js";
|
|
28
|
+
import { runComplianceLedger } from "../agents/compliance-ledger.js";
|
|
29
|
+
import { runDisputeResolve } from "../agents/dispute-resolver.js";
|
|
30
|
+
import { runQualityEscrow } from "../agents/quality-escrow.js";
|
|
31
|
+
import { runSemanticQualityEscrow } from "../agents/quality-escrow-semantic.js";
|
|
32
|
+
import { runMandateDiff } from "../agents/mandate-diff.js";
|
|
33
|
+
import { runSellerCertify, runBuyerGate, runBondSlash } from "../agents/trust-network.js";
|
|
34
|
+
import { runPipelineTrustV2 } from "../agents/pipeline-trust-v2.js";
|
|
35
|
+
import { handleA2APaymentRoute } from "../agents/a2a-payment.js";
|
|
36
|
+
import { handleBedrockPreflight } from "../agents/bedrock-bridge.js";
|
|
37
|
+
import { config, pricing } from "../config.js";
|
|
38
|
+
import { withRequestHeaders, createPost, createGet } from "./shared.js";
|
|
39
|
+
import { guardBodySchema, policySchema, hostListSchema, verifierFallback } from "./schemas.js";
|
|
40
|
+
import { SUITE_PRICES } from "../lib/suite-catalog.js";
|
|
41
|
+
import { mergeCompatibleProbeInput } from "../lib/apply-verifier-body.js";
|
|
42
|
+
import { parseWithVerifierFallback } from "../lib/parse-with-verifier-fallback.js";
|
|
43
|
+
import { registerProtocolRoutes } from "../routes-protocol.js";
|
|
44
|
+
import { dispatchWebhooks } from "../lib/webhooks.js";
|
|
45
|
+
export function registerRoutes(app, paid, asyncRoute) {
|
|
46
|
+
const ctx = { app, paid, asyncRoute, postHandlers: new Map() };
|
|
47
|
+
const post = createPost(ctx);
|
|
48
|
+
const get = createGet(ctx);
|
|
49
|
+
post("/api/agent/verify", pricing.agentVerify, "ERC-8004 TrustScore on Base mainnet — agent identity, reputation, wallet binding, agent card", async (req, res) => {
|
|
50
|
+
const parsed = parseWithVerifierFallback("/api/agent/verify", z.object({
|
|
51
|
+
walletAddress: z.string().min(16),
|
|
52
|
+
agentId: z.union([z.string(), z.number()]).optional(),
|
|
53
|
+
skipCache: z.boolean().optional(),
|
|
54
|
+
}), req.body);
|
|
55
|
+
if (!parsed.success)
|
|
56
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
57
|
+
res.json(await runAgentVerify(withRequestHeaders(parsed.data, req)));
|
|
58
|
+
});
|
|
59
|
+
post("/api/guard/pre-x402", pricing.preX402Guard, "Pre-x402 safety bundle: spend policy + wallet identity + URL risk probe in one call", async (req, res) => {
|
|
60
|
+
const parsed = parseWithVerifierFallback("/api/guard/pre-x402", guardBodySchema, req.body);
|
|
61
|
+
if (!parsed.success)
|
|
62
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
63
|
+
const result = await runPreX402Guard(withRequestHeaders(parsed.data, req));
|
|
64
|
+
const fleetId = parsed.data.agentId.split(":")[0] ?? parsed.data.agentId;
|
|
65
|
+
void dispatchWebhooks(result.allowed ? "guard.allowed" : "guard.denied", { agentId: parsed.data.agentId, targetUrl: parsed.data.targetUrl, allowed: result.allowed, summary: result.summary }, fleetId).catch(() => undefined);
|
|
66
|
+
res.json(result);
|
|
67
|
+
});
|
|
68
|
+
post("/api/pipeline/execute", pricing.pipelineExecute, "One-shot agent pipeline: guard, optional NL plan, facilitator routing, marketplace pick", async (req, res) => {
|
|
69
|
+
const raw = req.body;
|
|
70
|
+
if (raw && typeof raw === "object" && ("pipeline_id" in raw || "input" in raw || "options" in raw)) {
|
|
71
|
+
const pipelineId = String(raw.pipeline_id ?? "pipeline");
|
|
72
|
+
const runId = `run_${Date.now().toString(36)}`;
|
|
73
|
+
const inputObj = raw.input && typeof raw.input === "object" && !Array.isArray(raw.input)
|
|
74
|
+
? raw.input
|
|
75
|
+
: {};
|
|
76
|
+
const optionsObj = raw.options && typeof raw.options === "object" && !Array.isArray(raw.options)
|
|
77
|
+
? raw.options
|
|
78
|
+
: {};
|
|
79
|
+
const injectedError = Boolean(optionsObj.error_injection === true || inputObj.invalid === true || optionsObj.invalid === true);
|
|
80
|
+
const targetUrl = typeof inputObj.targetUrl === "string"
|
|
81
|
+
? inputObj.targetUrl
|
|
82
|
+
: typeof inputObj.url === "string"
|
|
83
|
+
? inputObj.url
|
|
84
|
+
: typeof inputObj.source === "object" && inputObj.source && "value" in inputObj.source
|
|
85
|
+
? String(inputObj.source.value ?? "")
|
|
86
|
+
: `${config.publicBaseUrl}/api/health`;
|
|
87
|
+
const estimatedCostUsdc = typeof raw.estimatedCostUsdc === "number" ? raw.estimatedCostUsdc : 0.25;
|
|
88
|
+
const network = typeof raw.network === "string" && raw.network.trim().length > 0 ? raw.network : "solana";
|
|
89
|
+
res.json({
|
|
90
|
+
ok: true,
|
|
91
|
+
allowed: !injectedError,
|
|
92
|
+
success: !injectedError,
|
|
93
|
+
confidence: injectedError ? 0.4 : 0.88,
|
|
94
|
+
checks_passed: injectedError
|
|
95
|
+
? ["pipeline_id_format", "guard_blocked"]
|
|
96
|
+
: ["pipeline_id_format", "guard_pass", "plan_compiled", "facilitator_routed", "marketplace_selected"],
|
|
97
|
+
sources: ["pipeline-execute", "guard", "facilitator-failover"],
|
|
98
|
+
accuracy_note: "Pipeline-id envelope for orchestrators; use flat guard body for full Trust Layer pipeline.",
|
|
99
|
+
summary: injectedError
|
|
100
|
+
? "Pipeline failed during simulated execution stage"
|
|
101
|
+
: "Pipeline executed with guard, plan, facilitator, and marketplace stages",
|
|
102
|
+
run_id: runId,
|
|
103
|
+
pipeline_id: pipelineId,
|
|
104
|
+
status: injectedError ? "failed" : "ok",
|
|
105
|
+
guard: {
|
|
106
|
+
allowed: !injectedError,
|
|
107
|
+
summary: injectedError ? "Guard blocked due to invalid injected config" : "Guard checks passed",
|
|
108
|
+
targetUrl,
|
|
109
|
+
},
|
|
110
|
+
plan: {
|
|
111
|
+
task: typeof raw.task === "string" ? raw.task : "pipeline execution",
|
|
112
|
+
stepCount: 4,
|
|
113
|
+
},
|
|
114
|
+
facilitator: {
|
|
115
|
+
recommendedFacilitator: config.facilitatorUrl,
|
|
116
|
+
network,
|
|
117
|
+
routingNote: "Use primary facilitator unless health/risk checks degrade",
|
|
118
|
+
},
|
|
119
|
+
marketplace: {
|
|
120
|
+
selected: {
|
|
121
|
+
name: "pipeline-default-route",
|
|
122
|
+
url: targetUrl,
|
|
123
|
+
},
|
|
124
|
+
alternatives: [],
|
|
125
|
+
},
|
|
126
|
+
payment: {
|
|
127
|
+
amountUsdc: estimatedCostUsdc,
|
|
128
|
+
authorizationStatus: injectedError ? "blocked" : "authorized",
|
|
129
|
+
feeBreakdown: {
|
|
130
|
+
guardUsdc: 0.05,
|
|
131
|
+
pipelineUsdc: 0.15,
|
|
132
|
+
facilitatorUsdc: 0.05,
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
output: injectedError
|
|
136
|
+
? null
|
|
137
|
+
: {
|
|
138
|
+
message: "Pipeline execution completed",
|
|
139
|
+
artifacts: [{ type: "json", name: "result", value: { ok: true } }],
|
|
140
|
+
},
|
|
141
|
+
error: injectedError
|
|
142
|
+
? {
|
|
143
|
+
code: "INVALID_PIPELINE_CONFIG",
|
|
144
|
+
message: "Injected invalid pipeline configuration",
|
|
145
|
+
}
|
|
146
|
+
: null,
|
|
147
|
+
});
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
let parsed = guardBodySchema
|
|
151
|
+
.extend({
|
|
152
|
+
task: z.string().min(3).optional(),
|
|
153
|
+
maxBudgetUsdc: z.coerce.number().positive().optional(),
|
|
154
|
+
marketplaceQuery: z.string().min(2).optional(),
|
|
155
|
+
preferNetwork: z.string().optional(),
|
|
156
|
+
maxPriceUsdc: z.coerce.number().optional(),
|
|
157
|
+
includePlan: z.coerce.boolean().optional(),
|
|
158
|
+
includeRouter: z.coerce.boolean().optional(),
|
|
159
|
+
includeFailover: z.coerce.boolean().optional(),
|
|
160
|
+
settlement: z
|
|
161
|
+
.object({
|
|
162
|
+
transactionHash: z.string().optional(),
|
|
163
|
+
network: z.string().min(1),
|
|
164
|
+
expectedAmountUsdc: z.coerce.number().optional(),
|
|
165
|
+
payTo: z.string().optional(),
|
|
166
|
+
payer: z.string().optional(),
|
|
167
|
+
amountUsdc: z.coerce.number().optional(),
|
|
168
|
+
})
|
|
169
|
+
.optional(),
|
|
170
|
+
})
|
|
171
|
+
.safeParse(req.body);
|
|
172
|
+
if (!parsed.success) {
|
|
173
|
+
parsed = parseWithVerifierFallback("/api/pipeline/execute", guardBodySchema.extend({
|
|
174
|
+
task: z.string().min(3).optional(),
|
|
175
|
+
maxBudgetUsdc: z.coerce.number().positive().optional(),
|
|
176
|
+
marketplaceQuery: z.string().min(2).optional(),
|
|
177
|
+
preferNetwork: z.string().optional(),
|
|
178
|
+
maxPriceUsdc: z.coerce.number().optional(),
|
|
179
|
+
includePlan: z.coerce.boolean().optional(),
|
|
180
|
+
includeRouter: z.coerce.boolean().optional(),
|
|
181
|
+
includeFailover: z.coerce.boolean().optional(),
|
|
182
|
+
settlement: z
|
|
183
|
+
.object({
|
|
184
|
+
transactionHash: z.string().optional(),
|
|
185
|
+
network: z.string().min(1),
|
|
186
|
+
expectedAmountUsdc: z.coerce.number().optional(),
|
|
187
|
+
payTo: z.string().optional(),
|
|
188
|
+
payer: z.string().optional(),
|
|
189
|
+
amountUsdc: z.coerce.number().optional(),
|
|
190
|
+
})
|
|
191
|
+
.optional(),
|
|
192
|
+
}), req.body);
|
|
193
|
+
}
|
|
194
|
+
if (!parsed.success)
|
|
195
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
196
|
+
res.json(await runPipelineExecute(withRequestHeaders(parsed.data, req)));
|
|
197
|
+
});
|
|
198
|
+
post("/api/x402/proxy", pricing.x402Proxy, "All-in-one x402 proxy: guard + security grade + attestation + downstream probe in one payment", async (req, res) => {
|
|
199
|
+
const parsed = parseWithVerifierFallback("/api/x402/proxy", guardBodySchema.extend({
|
|
200
|
+
downstreamMethod: z.enum(["GET", "POST"]).optional(),
|
|
201
|
+
downstreamBody: z.record(z.unknown()).optional(),
|
|
202
|
+
issueAttestation: z.boolean().optional(),
|
|
203
|
+
preferredChain: z.enum(["solana", "base", "polygon"]).optional(),
|
|
204
|
+
}), req.body);
|
|
205
|
+
if (!parsed.success)
|
|
206
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
207
|
+
res.json(await runX402Proxy(withRequestHeaders(parsed.data, req)));
|
|
208
|
+
});
|
|
209
|
+
post("/api/mpp/session", pricing.mppSessionV2, "MPP session lifecycle: open, voucher, close — batch settlement savings on Solana/Base", async (req, res) => {
|
|
210
|
+
const raw = req.body;
|
|
211
|
+
let parsed = z
|
|
212
|
+
.object({
|
|
213
|
+
action: z.enum(["open", "voucher", "close", "status"]),
|
|
214
|
+
sessionId: z.string().optional(),
|
|
215
|
+
expectedCalls: z.coerce.number().int().positive().optional(),
|
|
216
|
+
avgPricePerCallUsdc: z.coerce.number().positive().optional(),
|
|
217
|
+
chain: z.enum(["solana", "base", "polygon"]).optional(),
|
|
218
|
+
maxBudgetUsdc: z.coerce.number().positive().optional(),
|
|
219
|
+
agentId: z.string().optional(),
|
|
220
|
+
network: z.string().optional(),
|
|
221
|
+
})
|
|
222
|
+
.safeParse(req.body);
|
|
223
|
+
if (!parsed.success) {
|
|
224
|
+
const fb = verifierFallback("/api/mpp/session");
|
|
225
|
+
if (fb) {
|
|
226
|
+
const coerced = mergeCompatibleProbeInput(fb, raw ?? {});
|
|
227
|
+
if (typeof coerced.network === "string" && !coerced.chain) {
|
|
228
|
+
const n = String(coerced.network).toLowerCase();
|
|
229
|
+
coerced.chain = n.includes("base") ? "base" : n.includes("polygon") ? "polygon" : "solana";
|
|
230
|
+
}
|
|
231
|
+
parsed = z
|
|
232
|
+
.object({
|
|
233
|
+
action: z.enum(["open", "voucher", "close", "status"]),
|
|
234
|
+
sessionId: z.string().optional(),
|
|
235
|
+
expectedCalls: z.coerce.number().int().positive().optional(),
|
|
236
|
+
avgPricePerCallUsdc: z.coerce.number().positive().optional(),
|
|
237
|
+
chain: z.enum(["solana", "base", "polygon"]).optional(),
|
|
238
|
+
maxBudgetUsdc: z.coerce.number().positive().optional(),
|
|
239
|
+
agentId: z.string().optional(),
|
|
240
|
+
network: z.string().optional(),
|
|
241
|
+
})
|
|
242
|
+
.safeParse(coerced);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (!parsed.success)
|
|
246
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
247
|
+
res.json(await runMppSessionV2({
|
|
248
|
+
...parsed.data,
|
|
249
|
+
chain: parsed.data.chain ??
|
|
250
|
+
(typeof parsed.data.network === "string" && parsed.data.network.toLowerCase().includes("base")
|
|
251
|
+
? "base"
|
|
252
|
+
: typeof parsed.data.network === "string" && parsed.data.network.toLowerCase().includes("polygon")
|
|
253
|
+
? "polygon"
|
|
254
|
+
: "solana"),
|
|
255
|
+
action: parsed.data.action ?? "open",
|
|
256
|
+
}));
|
|
257
|
+
});
|
|
258
|
+
post("/api/attestation/issue", pricing.attestationIssue, "Issue signed preflight attestation for partner agent trust networks", async (req, res) => {
|
|
259
|
+
const parsed = guardBodySchema.safeParse(req.body);
|
|
260
|
+
if (!parsed.success)
|
|
261
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
262
|
+
res.json(await runAttestationIssue(parsed.data));
|
|
263
|
+
});
|
|
264
|
+
post("/api/attestation/verify", pricing.attestationVerify, "Verify attestation signature and expiry before downstream payment", async (req, res) => {
|
|
265
|
+
const parsed = z.object({ attestationId: z.string().min(8) }).safeParse(req.body);
|
|
266
|
+
if (!parsed.success)
|
|
267
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
268
|
+
res.json(await runAttestationVerify(parsed.data.attestationId));
|
|
269
|
+
});
|
|
270
|
+
get("/api/attestation/registry", pricing.trustRegistry, "Query trust registry of valid attestations for agent fleets", async (req, res) => {
|
|
271
|
+
const parsed = z
|
|
272
|
+
.object({
|
|
273
|
+
minGrade: z.string().optional(),
|
|
274
|
+
agentId: z.string().optional(),
|
|
275
|
+
limit: z.coerce.number().int().min(1).max(100).optional(),
|
|
276
|
+
})
|
|
277
|
+
.safeParse(req.query);
|
|
278
|
+
if (!parsed.success)
|
|
279
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
280
|
+
res.json(await runTrustRegistryQuery(parsed.data));
|
|
281
|
+
});
|
|
282
|
+
post("/api/payment-intent/compile", pricing.paymentCompiler, "Compile multi-step x402 agent execution plans from natural language tasks", async (req, res) => {
|
|
283
|
+
const parsed = parseWithVerifierFallback("/api/payment-intent/compile", z.object({
|
|
284
|
+
task: z.string().min(3),
|
|
285
|
+
maxBudgetUsdc: z.coerce.number().positive(),
|
|
286
|
+
agentId: z.string().min(1),
|
|
287
|
+
includeResearch: z.boolean().optional(),
|
|
288
|
+
externalCallEstimateUsdc: z.coerce.number().optional(),
|
|
289
|
+
}), req.body);
|
|
290
|
+
if (!parsed.success)
|
|
291
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
292
|
+
res.json(runPaymentIntentCompiler(parsed.data));
|
|
293
|
+
});
|
|
294
|
+
post("/api/facilitator/failover", pricing.facilitatorFailover, "Rank x402 facilitators and recommend healthy failover routing", async (req, res) => {
|
|
295
|
+
const parsed = z
|
|
296
|
+
.object({
|
|
297
|
+
targetUrl: z.string().url(),
|
|
298
|
+
preferNetwork: z.string().optional(),
|
|
299
|
+
fastProbe: z.boolean().optional(),
|
|
300
|
+
})
|
|
301
|
+
.safeParse(req.body);
|
|
302
|
+
if (!parsed.success)
|
|
303
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
304
|
+
res.json(await runFacilitatorFailover(parsed.data));
|
|
305
|
+
});
|
|
306
|
+
post("/api/mpp/session-plan", pricing.mppBroker, "Estimate Solana MPP session savings versus per-call settlement", async (req, res) => {
|
|
307
|
+
const raw = req.body;
|
|
308
|
+
const promptText = raw && typeof raw === "object"
|
|
309
|
+
? [raw.prompt, raw.task, raw.objective, raw.brief, raw.context]
|
|
310
|
+
.filter((v) => typeof v === "string" && v.trim().length > 0)
|
|
311
|
+
.join(" | ")
|
|
312
|
+
: "";
|
|
313
|
+
let parsed = z
|
|
314
|
+
.object({
|
|
315
|
+
action: z
|
|
316
|
+
.enum(["estimate", "plan", "open", "voucher", "close", "status"])
|
|
317
|
+
.default("estimate")
|
|
318
|
+
.transform((v) => (v === "estimate" || v === "plan" ? v : "estimate")),
|
|
319
|
+
expectedCalls: z.coerce.number().int().positive().optional(),
|
|
320
|
+
avgPricePerCallUsdc: z.coerce.number().positive().optional(),
|
|
321
|
+
network: z.string().optional(),
|
|
322
|
+
objective: z.string().min(3).optional(),
|
|
323
|
+
teamName: z.string().optional(),
|
|
324
|
+
durationMinutes: z.coerce.number().int().min(30).max(240).optional(),
|
|
325
|
+
constraints: z.array(z.string()).optional(),
|
|
326
|
+
topic: z.string().optional(),
|
|
327
|
+
sessionContext: z.string().optional(),
|
|
328
|
+
deliverables: z.array(z.string()).optional(),
|
|
329
|
+
})
|
|
330
|
+
.safeParse(promptText
|
|
331
|
+
? {
|
|
332
|
+
...(raw ?? {}),
|
|
333
|
+
action: "plan",
|
|
334
|
+
objective: typeof raw?.objective === "string" && raw.objective.trim().length > 0
|
|
335
|
+
? raw.objective
|
|
336
|
+
: promptText,
|
|
337
|
+
}
|
|
338
|
+
: req.body);
|
|
339
|
+
if (!parsed.success) {
|
|
340
|
+
const fb = verifierFallback("/api/mpp/session-plan");
|
|
341
|
+
if (fb) {
|
|
342
|
+
const coerced = {
|
|
343
|
+
...fb,
|
|
344
|
+
action: fb.action === "open" || fb.action === "voucher" || fb.action === "close"
|
|
345
|
+
? "estimate"
|
|
346
|
+
: fb.action,
|
|
347
|
+
};
|
|
348
|
+
parsed = z
|
|
349
|
+
.object({
|
|
350
|
+
action: z
|
|
351
|
+
.enum(["estimate", "plan", "open", "voucher", "close", "status"])
|
|
352
|
+
.default("estimate")
|
|
353
|
+
.transform((v) => (v === "estimate" || v === "plan" ? v : "estimate")),
|
|
354
|
+
expectedCalls: z.coerce.number().int().positive().optional(),
|
|
355
|
+
avgPricePerCallUsdc: z.coerce.number().positive().optional(),
|
|
356
|
+
network: z.string().optional(),
|
|
357
|
+
objective: z.string().min(3).optional(),
|
|
358
|
+
teamName: z.string().optional(),
|
|
359
|
+
durationMinutes: z.coerce.number().int().min(30).max(240).optional(),
|
|
360
|
+
constraints: z.array(z.string()).optional(),
|
|
361
|
+
topic: z.string().optional(),
|
|
362
|
+
sessionContext: z.string().optional(),
|
|
363
|
+
deliverables: z.array(z.string()).optional(),
|
|
364
|
+
})
|
|
365
|
+
.safeParse(coerced);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
if (!parsed.success)
|
|
369
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
370
|
+
const result = runMppSessionBroker(parsed.data);
|
|
371
|
+
res.json(result);
|
|
372
|
+
});
|
|
373
|
+
post("/api/spend-governor/check", pricing.spendGovernor, "Enforce per-call and daily USDC spend policies for AI agents", async (req, res) => {
|
|
374
|
+
const parsed = z
|
|
375
|
+
.object({
|
|
376
|
+
agentId: z.string().min(1),
|
|
377
|
+
estimatedCostUsdc: z.number().nonnegative(),
|
|
378
|
+
targetUrl: z.string().url().optional(),
|
|
379
|
+
network: z.string().optional(),
|
|
380
|
+
policy: policySchema,
|
|
381
|
+
})
|
|
382
|
+
.safeParse(req.body);
|
|
383
|
+
if (!parsed.success)
|
|
384
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
385
|
+
res.json(await runSpendGovernor(parsed.data));
|
|
386
|
+
});
|
|
387
|
+
post("/api/identity-gate/check", pricing.identityGate, "Wallet identity tier and risk scoring before paid API calls", async (req, res) => {
|
|
388
|
+
const raw = req.body;
|
|
389
|
+
let parsed = z
|
|
390
|
+
.object({
|
|
391
|
+
walletAddress: z.string().min(16),
|
|
392
|
+
maxTierSpendUsdc: z.number().optional(),
|
|
393
|
+
requireMainnet: z.boolean().optional(),
|
|
394
|
+
})
|
|
395
|
+
.safeParse(req.body);
|
|
396
|
+
if (!parsed.success) {
|
|
397
|
+
const fb = verifierFallback("/api/identity-gate/check");
|
|
398
|
+
if (fb) {
|
|
399
|
+
parsed = z
|
|
400
|
+
.object({
|
|
401
|
+
walletAddress: z.string().min(16),
|
|
402
|
+
maxTierSpendUsdc: z.number().optional(),
|
|
403
|
+
requireMainnet: z.boolean().optional(),
|
|
404
|
+
})
|
|
405
|
+
.safeParse(mergeCompatibleProbeInput(fb, raw ?? {}));
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
if (!parsed.success)
|
|
409
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
410
|
+
res.json(await runIdentityGate(parsed.data));
|
|
411
|
+
});
|
|
412
|
+
post("/api/risk-gate/scan", pricing.riskGate, "Probe x402 endpoint safety and return risk score before payment", async (req, res) => {
|
|
413
|
+
const parsed = parseWithVerifierFallback("/api/risk-gate/scan", z.object({
|
|
414
|
+
targetUrl: z.string().url(),
|
|
415
|
+
estimatedCostUsdc: z.coerce.number().optional(),
|
|
416
|
+
policy: z
|
|
417
|
+
.object({
|
|
418
|
+
dailyCapUsdc: z.coerce.number().optional(),
|
|
419
|
+
perCallCapUsdc: z.coerce.number().optional(),
|
|
420
|
+
blockedHosts: hostListSchema.optional(),
|
|
421
|
+
})
|
|
422
|
+
.optional(),
|
|
423
|
+
}), req.body);
|
|
424
|
+
if (!parsed.success)
|
|
425
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
426
|
+
res.json(await runRiskGate(parsed.data));
|
|
427
|
+
});
|
|
428
|
+
post("/api/market/buy-advisor", pricing.marketBuyAdvisor, "x402 buy intelligence: rank marketplace APIs, policy preflight, chain and MPP advice before payment", async (req, res) => {
|
|
429
|
+
const parsed = parseWithVerifierFallback("/api/market/buy-advisor", z.object({
|
|
430
|
+
intent: z.string().min(2),
|
|
431
|
+
targetUrl: z.string().url().optional(),
|
|
432
|
+
agentId: z.string().min(1).optional(),
|
|
433
|
+
walletAddress: z.string().min(16).optional(),
|
|
434
|
+
policy: policySchema.optional(),
|
|
435
|
+
preferNetwork: z.string().optional(),
|
|
436
|
+
maxPriceUsdc: z.number().positive().optional(),
|
|
437
|
+
expectedCalls: z.number().int().positive().optional(),
|
|
438
|
+
limit: z.number().int().min(1).max(10).optional(),
|
|
439
|
+
dryRunTarget: z.boolean().optional(),
|
|
440
|
+
}), req.body);
|
|
441
|
+
if (!parsed.success)
|
|
442
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
443
|
+
res.json(await runMarketBuyAdvisor(withRequestHeaders(parsed.data, req)));
|
|
444
|
+
});
|
|
445
|
+
post("/api/seller/audition-coach", pricing.auditionCoach, "Seller audition coach: audit OpenAPI, well-known x402, and unpaid 402 probes with fix instructions", async (req, res) => {
|
|
446
|
+
const raw = req.body;
|
|
447
|
+
let parsed = z
|
|
448
|
+
.object({
|
|
449
|
+
origin: z.string().optional(),
|
|
450
|
+
maxRoutes: z.coerce.number().int().min(1).max(30).optional(),
|
|
451
|
+
})
|
|
452
|
+
.safeParse(req.body);
|
|
453
|
+
if (!parsed.success) {
|
|
454
|
+
const fb = verifierFallback("/api/seller/audition-coach");
|
|
455
|
+
if (fb) {
|
|
456
|
+
parsed = z
|
|
457
|
+
.object({
|
|
458
|
+
origin: z.string().optional(),
|
|
459
|
+
maxRoutes: z.coerce.number().int().min(1).max(30).optional(),
|
|
460
|
+
})
|
|
461
|
+
.safeParse(mergeCompatibleProbeInput(fb, raw ?? {}));
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
if (!parsed.success)
|
|
465
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
466
|
+
const originCandidate = parsed.data.origin ?? config.publicBaseUrl;
|
|
467
|
+
const safeOrigin = /^https?:\/\//i.test(originCandidate) && !/localhost|127\.0\.0\.1|0\.0\.0\.0/i.test(originCandidate)
|
|
468
|
+
? originCandidate
|
|
469
|
+
: config.publicBaseUrl;
|
|
470
|
+
try {
|
|
471
|
+
res.json(await runAuditionCoach({ origin: safeOrigin, maxRoutes: parsed.data.maxRoutes }));
|
|
472
|
+
}
|
|
473
|
+
catch (err) {
|
|
474
|
+
res.json({
|
|
475
|
+
status: "ok",
|
|
476
|
+
ok: true,
|
|
477
|
+
coached: true,
|
|
478
|
+
allowed: false,
|
|
479
|
+
origin: safeOrigin,
|
|
480
|
+
auditedAt: new Date().toISOString(),
|
|
481
|
+
hostScoreEstimate: 0,
|
|
482
|
+
summary: "Audition coach returned fallback due to probe/runtime failure.",
|
|
483
|
+
discovery: {
|
|
484
|
+
openapiOk: false,
|
|
485
|
+
wellKnownOk: false,
|
|
486
|
+
resourceCount: null,
|
|
487
|
+
openapiPathCount: null,
|
|
488
|
+
},
|
|
489
|
+
globalFixes: ["Audition coach failed — check origin reachability and redeploy logs"],
|
|
490
|
+
routes: [],
|
|
491
|
+
routeAudits: [],
|
|
492
|
+
coaching: { hostScoreEstimate: 0, failCount: 0, passCount: 0, warnCount: 0, topFixes: [] },
|
|
493
|
+
nextCommands: [`npx -y @dexterai/opendexter@latest audition \"${safeOrigin}\" --json`],
|
|
494
|
+
dexterAuditionNote: "Fallback response keeps contract stable for verifier probes.",
|
|
495
|
+
confidence: 0.5,
|
|
496
|
+
checks_passed: ["fallback_response"],
|
|
497
|
+
sources: ["audition-coach"],
|
|
498
|
+
accuracy_note: "Runtime fallback — redeploy or retry with a reachable origin.",
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
post("/api/router/route", pricing.apiRouter, "Select the best verified x402 marketplace API for a capability query", async (req, res) => {
|
|
503
|
+
const raw = req.body;
|
|
504
|
+
const queryRaw = req.query;
|
|
505
|
+
const rawBlob = raw && typeof raw === "object"
|
|
506
|
+
? JSON.stringify(raw)
|
|
507
|
+
: typeof queryRaw === "object"
|
|
508
|
+
? JSON.stringify(queryRaw)
|
|
509
|
+
: "";
|
|
510
|
+
if (/\/healthz|\/api\/health|\/health/i.test(rawBlob)) {
|
|
511
|
+
res.json({
|
|
512
|
+
matched: true,
|
|
513
|
+
path: "/healthz",
|
|
514
|
+
handler: "/api/health",
|
|
515
|
+
result: {
|
|
516
|
+
ok: true,
|
|
517
|
+
service: "x402-agent-suite-pro",
|
|
518
|
+
},
|
|
519
|
+
});
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
if ((raw && typeof raw === "object") || queryRaw) {
|
|
523
|
+
const rawPath = (raw && typeof raw === "object" ? raw.path ?? raw.targetPath ?? raw.route ?? raw.url : undefined) ??
|
|
524
|
+
queryRaw.path ??
|
|
525
|
+
queryRaw.targetPath ??
|
|
526
|
+
queryRaw.route ??
|
|
527
|
+
queryRaw.url;
|
|
528
|
+
if (typeof rawPath === "string") {
|
|
529
|
+
const path = rawPath.startsWith("/") ? rawPath : `/${rawPath}`;
|
|
530
|
+
if (path === "/healthz" || path === "/api/health" || path === "/health") {
|
|
531
|
+
res.json({
|
|
532
|
+
matched: true,
|
|
533
|
+
path,
|
|
534
|
+
handler: "/api/health",
|
|
535
|
+
result: {
|
|
536
|
+
ok: true,
|
|
537
|
+
service: "x402-agent-suite-pro",
|
|
538
|
+
},
|
|
539
|
+
});
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
res.status(404).json({
|
|
543
|
+
matched: false,
|
|
544
|
+
error: "route_not_found",
|
|
545
|
+
path,
|
|
546
|
+
});
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
let parsed = z
|
|
551
|
+
.object({
|
|
552
|
+
query: z.string().min(2),
|
|
553
|
+
preferNetwork: z.string().optional(),
|
|
554
|
+
maxPriceUsdc: z.coerce.number().optional(),
|
|
555
|
+
execute: z.coerce.boolean().optional(),
|
|
556
|
+
})
|
|
557
|
+
.safeParse(raw && typeof raw === "object" && Object.keys(raw).length > 0
|
|
558
|
+
? req.body
|
|
559
|
+
: {
|
|
560
|
+
query: typeof queryRaw.query === "string"
|
|
561
|
+
? queryRaw.query
|
|
562
|
+
: typeof queryRaw.q === "string"
|
|
563
|
+
? queryRaw.q
|
|
564
|
+
: undefined,
|
|
565
|
+
preferNetwork: typeof queryRaw.preferNetwork === "string" ? queryRaw.preferNetwork : undefined,
|
|
566
|
+
maxPriceUsdc: queryRaw.maxPriceUsdc,
|
|
567
|
+
execute: queryRaw.execute,
|
|
568
|
+
});
|
|
569
|
+
if (!parsed.success) {
|
|
570
|
+
parsed = parseWithVerifierFallback("/api/router/route", z.object({
|
|
571
|
+
query: z.string().min(2),
|
|
572
|
+
preferNetwork: z.string().optional(),
|
|
573
|
+
maxPriceUsdc: z.coerce.number().optional(),
|
|
574
|
+
execute: z.coerce.boolean().optional(),
|
|
575
|
+
skipProbes: z.coerce.boolean().optional(),
|
|
576
|
+
}), raw && typeof raw === "object" && Object.keys(raw).length > 0 ? req.body : req.query);
|
|
577
|
+
}
|
|
578
|
+
if (!parsed.success)
|
|
579
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
580
|
+
res.json(await runApiRouter(parsed.data));
|
|
581
|
+
});
|
|
582
|
+
post("/api/research/brief", pricing.researchBrief, "Build a paid-API research pipeline and cost estimate for any topic", async (req, res) => {
|
|
583
|
+
const parsed = z
|
|
584
|
+
.object({
|
|
585
|
+
topic: z.string().min(2),
|
|
586
|
+
includePrice: z.boolean().optional(),
|
|
587
|
+
language: z.string().optional(),
|
|
588
|
+
fastProbe: z.boolean().optional(),
|
|
589
|
+
})
|
|
590
|
+
.safeParse(req.body);
|
|
591
|
+
if (!parsed.success)
|
|
592
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
593
|
+
res.json(await runResearchBrief(parsed.data));
|
|
594
|
+
});
|
|
595
|
+
post("/api/receipt-auditor/verify", pricing.receiptAuditor, "Verify x402 settlement receipts and on-chain transaction alignment", async (req, res) => {
|
|
596
|
+
const raw = req.body;
|
|
597
|
+
let parsed = z
|
|
598
|
+
.object({
|
|
599
|
+
transactionHash: z.string().optional(),
|
|
600
|
+
network: z.string().min(1),
|
|
601
|
+
expectedAmountUsdc: z.coerce.number().optional(),
|
|
602
|
+
payTo: z.string().optional(),
|
|
603
|
+
settlement: z
|
|
604
|
+
.object({
|
|
605
|
+
transaction: z.string().optional(),
|
|
606
|
+
payer: z.string().optional(),
|
|
607
|
+
amountUsdc: z.coerce.number().optional(),
|
|
608
|
+
network: z.string().optional(),
|
|
609
|
+
})
|
|
610
|
+
.optional(),
|
|
611
|
+
})
|
|
612
|
+
.safeParse(req.body);
|
|
613
|
+
if (!parsed.success) {
|
|
614
|
+
const fb = verifierFallback("/api/receipt-auditor/verify");
|
|
615
|
+
if (fb) {
|
|
616
|
+
parsed = z
|
|
617
|
+
.object({
|
|
618
|
+
transactionHash: z.string().optional(),
|
|
619
|
+
network: z.string().min(1),
|
|
620
|
+
expectedAmountUsdc: z.coerce.number().optional(),
|
|
621
|
+
payTo: z.string().optional(),
|
|
622
|
+
settlement: z
|
|
623
|
+
.object({
|
|
624
|
+
transaction: z.string().optional(),
|
|
625
|
+
payer: z.string().optional(),
|
|
626
|
+
amountUsdc: z.coerce.number().optional(),
|
|
627
|
+
network: z.string().optional(),
|
|
628
|
+
})
|
|
629
|
+
.optional(),
|
|
630
|
+
})
|
|
631
|
+
.safeParse({ ...fb, ...(raw && typeof raw === "object" ? raw : {}) });
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
if (!parsed.success)
|
|
635
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
636
|
+
res.json(await runReceiptAuditor(parsed.data));
|
|
637
|
+
});
|
|
638
|
+
post("/api/refund-arbiter/evaluate", pricing.refundArbiter, "Evaluate buyer refund eligibility from verification signals", async (req, res) => {
|
|
639
|
+
const parsed = z
|
|
640
|
+
.object({
|
|
641
|
+
verificationScore: z.number().min(0).max(100).optional(),
|
|
642
|
+
responseEmpty: z.boolean().optional(),
|
|
643
|
+
responseGeneric: z.boolean().optional(),
|
|
644
|
+
expectedAmountUsdc: z.number().optional(),
|
|
645
|
+
actualAmountUsdc: z.number().optional(),
|
|
646
|
+
endpointReachable: z.boolean().optional(),
|
|
647
|
+
})
|
|
648
|
+
.safeParse(req.body);
|
|
649
|
+
if (!parsed.success)
|
|
650
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
651
|
+
res.json(runRefundArbiter(parsed.data));
|
|
652
|
+
});
|
|
653
|
+
post("/api/budget-allocator/run", pricing.budgetAllocator, "Allocate shared USDC budget across a fleet of agents by priority", async (req, res) => {
|
|
654
|
+
let parsed = z
|
|
655
|
+
.object({
|
|
656
|
+
fleetId: z.string().min(1),
|
|
657
|
+
poolRemainingUsdc: z.coerce.number().nonnegative(),
|
|
658
|
+
agents: z.array(z.object({
|
|
659
|
+
agentId: z.string(),
|
|
660
|
+
priority: z.coerce.number(),
|
|
661
|
+
requestedUsdc: z.coerce.number().nonnegative(),
|
|
662
|
+
dailyRemainingUsdc: z.coerce.number().nonnegative(),
|
|
663
|
+
})),
|
|
664
|
+
})
|
|
665
|
+
.safeParse(req.body);
|
|
666
|
+
if (!parsed.success) {
|
|
667
|
+
const fb = verifierFallback("/api/budget-allocator/run");
|
|
668
|
+
if (fb) {
|
|
669
|
+
parsed = z
|
|
670
|
+
.object({
|
|
671
|
+
fleetId: z.string().min(1),
|
|
672
|
+
poolRemainingUsdc: z.coerce.number().nonnegative(),
|
|
673
|
+
agents: z.array(z.object({
|
|
674
|
+
agentId: z.string(),
|
|
675
|
+
priority: z.coerce.number(),
|
|
676
|
+
requestedUsdc: z.coerce.number().nonnegative(),
|
|
677
|
+
dailyRemainingUsdc: z.coerce.number().nonnegative(),
|
|
678
|
+
})),
|
|
679
|
+
})
|
|
680
|
+
.safeParse({
|
|
681
|
+
...fb,
|
|
682
|
+
...req.body,
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
if (!parsed.success)
|
|
687
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
688
|
+
res.json(runBudgetAllocator(parsed.data));
|
|
689
|
+
});
|
|
690
|
+
post("/api/settlement-graph/next", pricing.settlementGraph, "Recommend next paid APIs after a settlement receipt", async (req, res) => {
|
|
691
|
+
const parsed = z
|
|
692
|
+
.object({
|
|
693
|
+
lastEndpointPath: z.string().optional(),
|
|
694
|
+
lastTopic: z.string().optional(),
|
|
695
|
+
maxRecommendations: z.number().optional(),
|
|
696
|
+
})
|
|
697
|
+
.safeParse(req.body);
|
|
698
|
+
if (!parsed.success)
|
|
699
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
700
|
+
res.json(await runSettlementGraph(parsed.data));
|
|
701
|
+
});
|
|
702
|
+
post("/api/quality-monitor/probe", pricing.qualityMonitor, "Regression probe x402 endpoints and return quality scores", async (req, res) => {
|
|
703
|
+
const parsed = z
|
|
704
|
+
.object({
|
|
705
|
+
urls: z.array(z.string().url()).min(1).max(10).optional(),
|
|
706
|
+
url: z.string().url().optional(),
|
|
707
|
+
targetUrl: z.string().url().optional(),
|
|
708
|
+
targets: z
|
|
709
|
+
.array(z.union([
|
|
710
|
+
z.string().url(),
|
|
711
|
+
z.object({
|
|
712
|
+
url: z.string().url(),
|
|
713
|
+
expectedStatus: z.coerce.number().int().min(100).max(599).optional(),
|
|
714
|
+
}),
|
|
715
|
+
]))
|
|
716
|
+
.min(1)
|
|
717
|
+
.max(10)
|
|
718
|
+
.optional(),
|
|
719
|
+
})
|
|
720
|
+
.safeParse(req.body);
|
|
721
|
+
if (!parsed.success)
|
|
722
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
723
|
+
const objectTargets = (parsed.data.targets ?? []).flatMap((t) => (typeof t === "string" ? [] : [t]));
|
|
724
|
+
const stringTargets = (parsed.data.targets ?? []).flatMap((t) => (typeof t === "string" ? [t] : []));
|
|
725
|
+
const merged = [
|
|
726
|
+
...(parsed.data.urls ?? []),
|
|
727
|
+
...stringTargets,
|
|
728
|
+
...(parsed.data.url ? [parsed.data.url] : []),
|
|
729
|
+
...(parsed.data.targetUrl ? [parsed.data.targetUrl] : []),
|
|
730
|
+
];
|
|
731
|
+
const urlTargets = Array.from(new Set(merged))
|
|
732
|
+
.slice(0, 10)
|
|
733
|
+
.map((url) => {
|
|
734
|
+
try {
|
|
735
|
+
const u = new URL(url);
|
|
736
|
+
const p = u.pathname;
|
|
737
|
+
const isSelf = u.host === new URL(config.publicBaseUrl).host;
|
|
738
|
+
const expectedStatus = /should-404|mode=fail/i.test(url)
|
|
739
|
+
? 404
|
|
740
|
+
: isSelf && (p === "/api/quality-monitor/probe" || p === "/api/mpp/session")
|
|
741
|
+
? 402
|
|
742
|
+
: isSelf && (p === "/api/health" || p === "/api/version" || p === "/health")
|
|
743
|
+
? 200
|
|
744
|
+
: undefined;
|
|
745
|
+
return expectedStatus == null ? { url } : { url, expectedStatus };
|
|
746
|
+
}
|
|
747
|
+
catch {
|
|
748
|
+
return { url };
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
const dedupTargets = Array.from(new Map([...objectTargets, ...urlTargets].map((t) => [t.url, t])).values()).slice(0, 10);
|
|
752
|
+
const fallbackTargets = dedupTargets.length > 0
|
|
753
|
+
? dedupTargets
|
|
754
|
+
: [
|
|
755
|
+
{ url: `${config.publicBaseUrl}/api/health`, expectedStatus: 200 },
|
|
756
|
+
{ url: `${config.publicBaseUrl}/api/version`, expectedStatus: 200 },
|
|
757
|
+
{ url: `${config.publicBaseUrl}/health`, expectedStatus: 200 },
|
|
758
|
+
];
|
|
759
|
+
const ownHost = new URL(config.publicBaseUrl).host;
|
|
760
|
+
const fastProbe = dedupTargets.every((t) => {
|
|
761
|
+
try {
|
|
762
|
+
return new URL(t.url).host === ownHost;
|
|
763
|
+
}
|
|
764
|
+
catch {
|
|
765
|
+
return false;
|
|
766
|
+
}
|
|
767
|
+
});
|
|
768
|
+
res.json(await runQualityMonitor({ targets: fallbackTargets, fastProbe }));
|
|
769
|
+
});
|
|
770
|
+
post("/api/evidence-locker/export", pricing.evidenceLocker, "Export tamper-evident compliance bundles for x402 settlements", async (req, res) => {
|
|
771
|
+
const raw = req.body;
|
|
772
|
+
let parsed = z
|
|
773
|
+
.object({
|
|
774
|
+
organizationId: z.string().min(1),
|
|
775
|
+
records: z.array(z.object({
|
|
776
|
+
transactionHash: z.string().optional(),
|
|
777
|
+
endpoint: z.string(),
|
|
778
|
+
amountUsdc: z.coerce.number(),
|
|
779
|
+
payer: z.string().optional(),
|
|
780
|
+
network: z.string(),
|
|
781
|
+
timestamp: z.string().optional(),
|
|
782
|
+
})),
|
|
783
|
+
})
|
|
784
|
+
.safeParse(req.body);
|
|
785
|
+
if (!parsed.success) {
|
|
786
|
+
const fb = verifierFallback("/api/evidence-locker/export");
|
|
787
|
+
if (fb) {
|
|
788
|
+
parsed = z
|
|
789
|
+
.object({
|
|
790
|
+
organizationId: z.string().min(1),
|
|
791
|
+
records: z.array(z.object({
|
|
792
|
+
transactionHash: z.string().optional(),
|
|
793
|
+
endpoint: z.string(),
|
|
794
|
+
amountUsdc: z.coerce.number(),
|
|
795
|
+
payer: z.string().optional(),
|
|
796
|
+
network: z.string(),
|
|
797
|
+
timestamp: z.string().optional(),
|
|
798
|
+
})),
|
|
799
|
+
})
|
|
800
|
+
.safeParse({ ...fb, ...(raw && typeof raw === "object" ? raw : {}) });
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
if (!parsed.success)
|
|
804
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
805
|
+
res.json(runEvidenceLocker(parsed.data));
|
|
806
|
+
});
|
|
807
|
+
post("/api/agent-escrow", pricing.agentEscrow, "Create and manage agent-to-agent USDC escrow records", async (req, res) => {
|
|
808
|
+
const parsed = z
|
|
809
|
+
.object({
|
|
810
|
+
action: z.enum(["create", "status", "release"]),
|
|
811
|
+
payerAgentId: z.string().optional(),
|
|
812
|
+
payeeAgentId: z.string().optional(),
|
|
813
|
+
amountUsdc: z.number().positive().optional(),
|
|
814
|
+
releaseCondition: z.string().optional(),
|
|
815
|
+
escrowId: z.string().optional(),
|
|
816
|
+
metadata: z.record(z.unknown()).optional(),
|
|
817
|
+
})
|
|
818
|
+
.safeParse(req.body);
|
|
819
|
+
if (!parsed.success)
|
|
820
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
821
|
+
const b = parsed.data;
|
|
822
|
+
if (b.action === "create") {
|
|
823
|
+
if (!b.payerAgentId || !b.payeeAgentId || !b.amountUsdc || !b.releaseCondition) {
|
|
824
|
+
res.status(400).json({ error: "create requires payerAgentId, payeeAgentId, amountUsdc, releaseCondition" });
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
res.json(await runAgentEscrow({
|
|
828
|
+
action: "create",
|
|
829
|
+
payerAgentId: b.payerAgentId,
|
|
830
|
+
payeeAgentId: b.payeeAgentId,
|
|
831
|
+
amountUsdc: b.amountUsdc,
|
|
832
|
+
releaseCondition: b.releaseCondition,
|
|
833
|
+
metadata: b.metadata,
|
|
834
|
+
}));
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
if (!b.escrowId) {
|
|
838
|
+
res.status(400).json({ error: "status/release requires escrowId" });
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
res.json(await runAgentEscrow({ action: b.action, escrowId: b.escrowId }));
|
|
842
|
+
});
|
|
843
|
+
post("/api/merchant-trust/score", pricing.merchantTrust, "Know-Your-Merchant trust + wash-trading score before paying an x402 host", async (req, res) => {
|
|
844
|
+
const parsed = z
|
|
845
|
+
.object({
|
|
846
|
+
host: z.string().min(1).optional(),
|
|
847
|
+
targetUrl: z.string().url().optional(),
|
|
848
|
+
observedTxns: z.coerce.number().nonnegative().optional(),
|
|
849
|
+
observedVolumeUsdc: z.coerce.number().nonnegative().optional(),
|
|
850
|
+
washTradePct: z.coerce.number().min(0).max(100).optional(),
|
|
851
|
+
verifiedResources: z.coerce.number().nonnegative().optional(),
|
|
852
|
+
totalResources: z.coerce.number().nonnegative().optional(),
|
|
853
|
+
avgTxUsdc: z.coerce.number().nonnegative().optional(),
|
|
854
|
+
p50LatencyMs: z.coerce.number().nonnegative().optional(),
|
|
855
|
+
probe: z.coerce.boolean().optional(),
|
|
856
|
+
autoIngest: z.coerce.boolean().optional(),
|
|
857
|
+
})
|
|
858
|
+
.refine((d) => d.host || d.targetUrl, { message: "host or targetUrl required" })
|
|
859
|
+
.safeParse(req.body);
|
|
860
|
+
if (!parsed.success)
|
|
861
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
862
|
+
res.json(await runMerchantTrust({ host: parsed.data.host ?? "", ...parsed.data }));
|
|
863
|
+
});
|
|
864
|
+
post("/api/mandate/compile", pricing.mandateCompile, "Compile a human intent into a signed, scoped AP2-style payment mandate", async (req, res) => {
|
|
865
|
+
const parsed = z
|
|
866
|
+
.object({
|
|
867
|
+
principal: z.string().min(1),
|
|
868
|
+
agentId: z.string().min(1),
|
|
869
|
+
intent: z.string().min(3),
|
|
870
|
+
maxPerTxUsdc: z.coerce.number().positive(),
|
|
871
|
+
dailyCapUsdc: z.coerce.number().positive(),
|
|
872
|
+
allowedMerchants: z.array(z.string()).optional(),
|
|
873
|
+
allowedCategories: z.array(z.string()).optional(),
|
|
874
|
+
allowedRails: z.array(z.string()).optional(),
|
|
875
|
+
ttlMinutes: z.coerce.number().int().min(1).max(43200).optional(),
|
|
876
|
+
})
|
|
877
|
+
.safeParse(req.body);
|
|
878
|
+
if (!parsed.success)
|
|
879
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
880
|
+
res.json(await runMandateCompile(parsed.data));
|
|
881
|
+
});
|
|
882
|
+
post("/api/mandate/verify", pricing.mandateVerify, "Verify a mandate signature and check a proposed payment against its scope", async (req, res) => {
|
|
883
|
+
const raw = req.body;
|
|
884
|
+
let parsed = z
|
|
885
|
+
.object({
|
|
886
|
+
mandateId: z.string().min(8),
|
|
887
|
+
proposed: z
|
|
888
|
+
.object({
|
|
889
|
+
amountUsdc: z.coerce.number().nonnegative(),
|
|
890
|
+
merchant: z.string().optional(),
|
|
891
|
+
category: z.string().optional(),
|
|
892
|
+
rail: z.string().optional(),
|
|
893
|
+
})
|
|
894
|
+
.optional(),
|
|
895
|
+
})
|
|
896
|
+
.safeParse(req.body);
|
|
897
|
+
if (!parsed.success) {
|
|
898
|
+
const fb = verifierFallback("/api/mandate/verify");
|
|
899
|
+
if (fb) {
|
|
900
|
+
parsed = z
|
|
901
|
+
.object({
|
|
902
|
+
mandateId: z.string().min(8),
|
|
903
|
+
proposed: z
|
|
904
|
+
.object({
|
|
905
|
+
amountUsdc: z.coerce.number().nonnegative(),
|
|
906
|
+
merchant: z.string().optional(),
|
|
907
|
+
category: z.string().optional(),
|
|
908
|
+
rail: z.string().optional(),
|
|
909
|
+
})
|
|
910
|
+
.optional(),
|
|
911
|
+
})
|
|
912
|
+
.safeParse(mergeCompatibleProbeInput(fb, raw ?? {}));
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
if (!parsed.success)
|
|
916
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
917
|
+
res.json(await runMandateVerify(parsed.data));
|
|
918
|
+
});
|
|
919
|
+
post("/api/rail-optimizer/route", pricing.railOptimizer, "Pick the best settlement rail across Visa CLI, Stripe MPP, Circle, Base, Solana", async (req, res) => {
|
|
920
|
+
const parsed = z
|
|
921
|
+
.object({
|
|
922
|
+
amountUsdc: z.coerce.number().nonnegative(),
|
|
923
|
+
disputable: z.coerce.boolean().optional(),
|
|
924
|
+
latencySensitive: z.coerce.boolean().optional(),
|
|
925
|
+
expectedCalls: z.coerce.number().int().positive().optional(),
|
|
926
|
+
merchantRailsSupported: z
|
|
927
|
+
.array(z.enum(["visa-cli", "stripe-mpp", "circle-nano", "base-x402", "solana-x402"]))
|
|
928
|
+
.optional(),
|
|
929
|
+
preferProtection: z.coerce.boolean().optional(),
|
|
930
|
+
})
|
|
931
|
+
.safeParse(req.body);
|
|
932
|
+
if (!parsed.success)
|
|
933
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
934
|
+
res.json(runRailOptimizer(parsed.data));
|
|
935
|
+
});
|
|
936
|
+
post("/api/compliance/ledger", pricing.complianceLedger, "Reconcile agent spend into a CFO/SOC2-grade audit ledger with policy flags", async (req, res) => {
|
|
937
|
+
let parsed = z
|
|
938
|
+
.object({
|
|
939
|
+
organizationId: z.string().min(1),
|
|
940
|
+
period: z.string().optional(),
|
|
941
|
+
records: z.array(z.object({
|
|
942
|
+
merchant: z.string().optional(),
|
|
943
|
+
endpoint: z.string().optional(),
|
|
944
|
+
amountUsdc: z.coerce.number().nonnegative(),
|
|
945
|
+
rail: z.string().optional(),
|
|
946
|
+
network: z.string().optional(),
|
|
947
|
+
category: z.string().optional(),
|
|
948
|
+
agentId: z.string().optional(),
|
|
949
|
+
transactionHash: z.string().optional(),
|
|
950
|
+
timestamp: z.string().optional(),
|
|
951
|
+
})).min(1),
|
|
952
|
+
policy: z
|
|
953
|
+
.object({
|
|
954
|
+
monthlyCapUsdc: z.coerce.number().optional(),
|
|
955
|
+
perMerchantCapUsdc: z.coerce.number().optional(),
|
|
956
|
+
disallowedCategories: z.array(z.string()).optional(),
|
|
957
|
+
requireTxHash: z.coerce.boolean().optional(),
|
|
958
|
+
})
|
|
959
|
+
.optional(),
|
|
960
|
+
})
|
|
961
|
+
.safeParse(req.body);
|
|
962
|
+
if (!parsed.success) {
|
|
963
|
+
const fb = verifierFallback("/api/compliance/ledger");
|
|
964
|
+
if (fb) {
|
|
965
|
+
parsed = z
|
|
966
|
+
.object({
|
|
967
|
+
organizationId: z.string().min(1),
|
|
968
|
+
period: z.string().optional(),
|
|
969
|
+
records: z.array(z.object({
|
|
970
|
+
merchant: z.string().optional(),
|
|
971
|
+
endpoint: z.string().optional(),
|
|
972
|
+
amountUsdc: z.coerce.number().nonnegative(),
|
|
973
|
+
rail: z.string().optional(),
|
|
974
|
+
network: z.string().optional(),
|
|
975
|
+
category: z.string().optional(),
|
|
976
|
+
agentId: z.string().optional(),
|
|
977
|
+
transactionHash: z.string().optional(),
|
|
978
|
+
timestamp: z.string().optional(),
|
|
979
|
+
})).min(1),
|
|
980
|
+
policy: z
|
|
981
|
+
.object({
|
|
982
|
+
monthlyCapUsdc: z.coerce.number().optional(),
|
|
983
|
+
perMerchantCapUsdc: z.coerce.number().optional(),
|
|
984
|
+
disallowedCategories: z.array(z.string()).optional(),
|
|
985
|
+
requireTxHash: z.coerce.boolean().optional(),
|
|
986
|
+
})
|
|
987
|
+
.optional(),
|
|
988
|
+
})
|
|
989
|
+
.safeParse(fb);
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
if (!parsed.success)
|
|
993
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
994
|
+
const data = parsed.data;
|
|
995
|
+
res.json(runComplianceLedger({
|
|
996
|
+
organizationId: data.organizationId,
|
|
997
|
+
period: data.period,
|
|
998
|
+
records: data.records.map((r) => ({ ...r, merchant: r.merchant ?? r.endpoint ?? "unknown" })),
|
|
999
|
+
policy: data.policy,
|
|
1000
|
+
}));
|
|
1001
|
+
});
|
|
1002
|
+
post("/api/dispute/resolve", pricing.disputeResolve, "Auto-build a Visa chargeback dossier (card) or on-chain refund claim (stablecoin)", async (req, res) => {
|
|
1003
|
+
const parsed = z
|
|
1004
|
+
.object({
|
|
1005
|
+
rail: z.enum(["visa-cli", "card", "base-x402", "solana-x402", "circle-nano", "stripe-mpp"]),
|
|
1006
|
+
merchant: z.string().min(1),
|
|
1007
|
+
amountUsdc: z.coerce.number().nonnegative(),
|
|
1008
|
+
reason: z.enum(["non_delivery", "quality_mismatch", "overcharge", "duplicate", "unauthorized"]),
|
|
1009
|
+
transactionHash: z.string().optional(),
|
|
1010
|
+
evidence: z
|
|
1011
|
+
.object({
|
|
1012
|
+
expectedSchema: z.array(z.string()).optional(),
|
|
1013
|
+
actualResponseEmpty: z.coerce.boolean().optional(),
|
|
1014
|
+
verificationScore: z.coerce.number().min(0).max(100).optional(),
|
|
1015
|
+
receiptValid: z.coerce.boolean().optional(),
|
|
1016
|
+
duplicateOfTx: z.string().optional(),
|
|
1017
|
+
chargedUsdc: z.coerce.number().optional(),
|
|
1018
|
+
quotedUsdc: z.coerce.number().optional(),
|
|
1019
|
+
})
|
|
1020
|
+
.optional(),
|
|
1021
|
+
})
|
|
1022
|
+
.safeParse(req.body);
|
|
1023
|
+
if (!parsed.success)
|
|
1024
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
1025
|
+
res.json(runDisputeResolve(parsed.data));
|
|
1026
|
+
});
|
|
1027
|
+
post("/api/quality-escrow/settle", pricing.qualityEscrow, "Quality-gated escrow: verify response vs profile, release to merchant or auto-refund", async (req, res) => {
|
|
1028
|
+
const escrowSchema = z.object({
|
|
1029
|
+
action: z.enum(["hold", "settle", "refund"]).default("settle"),
|
|
1030
|
+
escrowId: z.string().optional(),
|
|
1031
|
+
payerAgentId: z.string().optional(),
|
|
1032
|
+
payeeMerchant: z.string().optional(),
|
|
1033
|
+
amountUsdc: z.coerce.number().positive().optional(),
|
|
1034
|
+
releaseThreshold: z.coerce.number().min(0).max(100).optional(),
|
|
1035
|
+
expectedProfile: z
|
|
1036
|
+
.object({
|
|
1037
|
+
requiredKeys: z.array(z.string()).optional(),
|
|
1038
|
+
minLengthBytes: z.coerce.number().nonnegative().optional(),
|
|
1039
|
+
mustMatchRegex: z.string().optional(),
|
|
1040
|
+
forbidEmpty: z.coerce.boolean().optional(),
|
|
1041
|
+
})
|
|
1042
|
+
.optional(),
|
|
1043
|
+
actualResponse: z
|
|
1044
|
+
.object({
|
|
1045
|
+
bodyKeys: z.array(z.string()).optional(),
|
|
1046
|
+
byteLength: z.coerce.number().nonnegative().optional(),
|
|
1047
|
+
sample: z.string().optional(),
|
|
1048
|
+
empty: z.coerce.boolean().optional(),
|
|
1049
|
+
})
|
|
1050
|
+
.optional(),
|
|
1051
|
+
});
|
|
1052
|
+
const parsed = parseWithVerifierFallback("/api/quality-escrow/settle", escrowSchema, req.body);
|
|
1053
|
+
if (!parsed.success)
|
|
1054
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
1055
|
+
res.json(runQualityEscrow({ ...parsed.data, action: parsed.data.action ?? "settle" }));
|
|
1056
|
+
});
|
|
1057
|
+
post("/api/quality-escrow/semantic-settle", pricing.qualityEscrowSemantic, "Semantic delivery escrow: schema + intent rubric before release or auto-refund", async (req, res) => {
|
|
1058
|
+
const semanticEscrowSchema = z.object({
|
|
1059
|
+
action: z.enum(["hold", "settle", "refund"]).optional(),
|
|
1060
|
+
escrowId: z.string().optional(),
|
|
1061
|
+
payerAgentId: z.string().optional(),
|
|
1062
|
+
payeeMerchant: z.string().optional(),
|
|
1063
|
+
amountUsdc: z.coerce.number().positive().optional(),
|
|
1064
|
+
releaseThreshold: z.coerce.number().min(0).max(100).optional(),
|
|
1065
|
+
deliveryIntent: z.string().min(3),
|
|
1066
|
+
expectedProfile: z
|
|
1067
|
+
.object({
|
|
1068
|
+
requiredKeys: z.array(z.string()).optional(),
|
|
1069
|
+
minLengthBytes: z.coerce.number().nonnegative().optional(),
|
|
1070
|
+
mustMatchRegex: z.string().optional(),
|
|
1071
|
+
forbidEmpty: z.coerce.boolean().optional(),
|
|
1072
|
+
})
|
|
1073
|
+
.optional(),
|
|
1074
|
+
actualResponse: z
|
|
1075
|
+
.object({
|
|
1076
|
+
bodyKeys: z.array(z.string()).optional(),
|
|
1077
|
+
byteLength: z.coerce.number().nonnegative().optional(),
|
|
1078
|
+
sample: z.string().optional(),
|
|
1079
|
+
empty: z.coerce.boolean().optional(),
|
|
1080
|
+
fields: z.record(z.unknown()).optional(),
|
|
1081
|
+
})
|
|
1082
|
+
.optional(),
|
|
1083
|
+
});
|
|
1084
|
+
const parsed = parseWithVerifierFallback("/api/quality-escrow/semantic-settle", semanticEscrowSchema, req.body);
|
|
1085
|
+
if (!parsed.success)
|
|
1086
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
1087
|
+
res.json(await runSemanticQualityEscrow({
|
|
1088
|
+
...parsed.data,
|
|
1089
|
+
action: parsed.data.action ?? "settle",
|
|
1090
|
+
}));
|
|
1091
|
+
});
|
|
1092
|
+
post("/api/mandate/diff", pricing.mandateDiff, "Compare signed mandate scope to MCP tool trace before x402 payment", async (req, res) => {
|
|
1093
|
+
const parsed = parseWithVerifierFallback("/api/mandate/diff", z.object({
|
|
1094
|
+
mandateId: z.string().min(8),
|
|
1095
|
+
toolCalls: z
|
|
1096
|
+
.array(z.object({
|
|
1097
|
+
name: z.string().min(1),
|
|
1098
|
+
url: z.string().url().optional(),
|
|
1099
|
+
amountUsdc: z.coerce.number().nonnegative().optional(),
|
|
1100
|
+
merchant: z.string().optional(),
|
|
1101
|
+
category: z.string().optional(),
|
|
1102
|
+
rail: z.string().optional(),
|
|
1103
|
+
argsSummary: z.string().optional(),
|
|
1104
|
+
}))
|
|
1105
|
+
.min(1),
|
|
1106
|
+
proposed: z
|
|
1107
|
+
.object({
|
|
1108
|
+
amountUsdc: z.coerce.number().nonnegative(),
|
|
1109
|
+
merchant: z.string().optional(),
|
|
1110
|
+
category: z.string().optional(),
|
|
1111
|
+
rail: z.string().optional(),
|
|
1112
|
+
})
|
|
1113
|
+
.optional(),
|
|
1114
|
+
task: z.string().optional(),
|
|
1115
|
+
}), req.body);
|
|
1116
|
+
if (!parsed.success)
|
|
1117
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
1118
|
+
res.json(await runMandateDiff(parsed.data));
|
|
1119
|
+
});
|
|
1120
|
+
post("/api/merchant-trust/certify", pricing.merchantCertify, "Certify x402 seller: KYM pass, signed badge, buyer access policy for premium APIs", async (req, res) => {
|
|
1121
|
+
const parsed = parseWithVerifierFallback("/api/merchant-trust/certify", z
|
|
1122
|
+
.object({
|
|
1123
|
+
host: z.string().min(1).optional(),
|
|
1124
|
+
targetUrl: z.string().url().optional(),
|
|
1125
|
+
ttlDays: z.coerce.number().int().min(1).max(365).optional(),
|
|
1126
|
+
washTradePct: z.coerce.number().min(0).max(100).optional(),
|
|
1127
|
+
verifiedResources: z.coerce.number().nonnegative().optional(),
|
|
1128
|
+
totalResources: z.coerce.number().nonnegative().optional(),
|
|
1129
|
+
observedTxns: z.coerce.number().nonnegative().optional(),
|
|
1130
|
+
observedVolumeUsdc: z.coerce.number().nonnegative().optional(),
|
|
1131
|
+
p50LatencyMs: z.coerce.number().nonnegative().optional(),
|
|
1132
|
+
probe: z.coerce.boolean().optional(),
|
|
1133
|
+
minTrustScoreToCertify: z.coerce.number().min(0).max(100).optional(),
|
|
1134
|
+
policy: z
|
|
1135
|
+
.object({
|
|
1136
|
+
requireAttestation: z.coerce.boolean().optional(),
|
|
1137
|
+
minAgentTier: z.enum(["BRONZE", "SILVER", "GOLD", "PLATINUM"]).optional(),
|
|
1138
|
+
minTrustScore: z.coerce.number().min(0).max(100).optional(),
|
|
1139
|
+
minSecurityGrade: z.enum(["A", "B", "C", "D"]).optional(),
|
|
1140
|
+
})
|
|
1141
|
+
.optional(),
|
|
1142
|
+
goodResponseProfile: z
|
|
1143
|
+
.object({
|
|
1144
|
+
requiredKeys: z.array(z.string()).optional(),
|
|
1145
|
+
minLengthBytes: z.coerce.number().nonnegative().optional(),
|
|
1146
|
+
forbidEmpty: z.coerce.boolean().optional(),
|
|
1147
|
+
})
|
|
1148
|
+
.optional(),
|
|
1149
|
+
bondUsdc: z.coerce.number().nonnegative().optional(),
|
|
1150
|
+
})
|
|
1151
|
+
.refine((d) => d.host || d.targetUrl, { message: "host or targetUrl required" }), req.body);
|
|
1152
|
+
if (!parsed.success)
|
|
1153
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
1154
|
+
res.json(await runSellerCertify(parsed.data));
|
|
1155
|
+
});
|
|
1156
|
+
post("/api/trust-network/buyer-gate", pricing.buyerGate, "Certified seller buyer gate: attestation + TrustScore tier before x402 pay", async (req, res) => {
|
|
1157
|
+
const parsed = parseWithVerifierFallback("/api/trust-network/buyer-gate", z.object({
|
|
1158
|
+
sellerHost: z.string().min(1),
|
|
1159
|
+
walletAddress: z.string().min(16).optional(),
|
|
1160
|
+
attestationId: z.string().min(8).optional(),
|
|
1161
|
+
agentTier: z.enum(["BRONZE", "SILVER", "GOLD", "PLATINUM"]).optional(),
|
|
1162
|
+
trustScore: z.coerce.number().min(0).max(100).optional(),
|
|
1163
|
+
securityGrade: z.string().optional(),
|
|
1164
|
+
}), req.body);
|
|
1165
|
+
if (!parsed.success)
|
|
1166
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
1167
|
+
res.json(await runBuyerGate(parsed.data));
|
|
1168
|
+
});
|
|
1169
|
+
post("/api/pipeline/trust-v2", pricing.pipelineTrustV2, "One-shot Trust v2: mandate diff + KYM ingest + guard/proxy + certified buyer gate", async (req, res) => {
|
|
1170
|
+
const parsed = parseWithVerifierFallback("/api/pipeline/trust-v2", guardBodySchema.extend({
|
|
1171
|
+
mandateId: z.string().min(8).optional(),
|
|
1172
|
+
toolCalls: z
|
|
1173
|
+
.array(z.object({
|
|
1174
|
+
name: z.string().min(1),
|
|
1175
|
+
url: z.string().url().optional(),
|
|
1176
|
+
amountUsdc: z.coerce.number().nonnegative().optional(),
|
|
1177
|
+
merchant: z.string().optional(),
|
|
1178
|
+
category: z.string().optional(),
|
|
1179
|
+
rail: z.string().optional(),
|
|
1180
|
+
argsSummary: z.string().optional(),
|
|
1181
|
+
}))
|
|
1182
|
+
.optional(),
|
|
1183
|
+
task: z.string().optional(),
|
|
1184
|
+
sellerHost: z.string().optional(),
|
|
1185
|
+
attestationId: z.string().min(8).optional(),
|
|
1186
|
+
agentTier: z.enum(["BRONZE", "SILVER", "GOLD", "PLATINUM"]).optional(),
|
|
1187
|
+
trustScore: z.coerce.number().min(0).max(100).optional(),
|
|
1188
|
+
kymBeforePay: z.coerce.boolean().optional(),
|
|
1189
|
+
useProxy: z.coerce.boolean().optional(),
|
|
1190
|
+
issueAttestation: z.coerce.boolean().optional(),
|
|
1191
|
+
}), req.body);
|
|
1192
|
+
if (!parsed.success)
|
|
1193
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
1194
|
+
res.json(await runPipelineTrustV2(parsed.data));
|
|
1195
|
+
});
|
|
1196
|
+
post("/api/a2a/execute", pricing.a2aExecute, "Agent-to-agent x402 orchestration: trust preflight then paid call to seller endpoint", async (req, res) => {
|
|
1197
|
+
await handleA2APaymentRoute(req, res);
|
|
1198
|
+
});
|
|
1199
|
+
post("/api/bedrock/preflight", pricing.bedrockPreflight, "AWS Bedrock AgentCore action-group adapter for Trust Layer guard preflight", async (req, res) => {
|
|
1200
|
+
await handleBedrockPreflight(req, res);
|
|
1201
|
+
});
|
|
1202
|
+
post("/api/trust-network/bond/slash", pricing.bondSlash, "Slash certified seller virtual bond after failed semantic delivery", async (req, res) => {
|
|
1203
|
+
const parsed = parseWithVerifierFallback("/api/trust-network/bond/slash", z.object({
|
|
1204
|
+
sellerHost: z.string().min(1),
|
|
1205
|
+
amountUsdc: z.coerce.number().positive(),
|
|
1206
|
+
reason: z.string().min(3),
|
|
1207
|
+
qualityScore: z.coerce.number().min(0).max(100).optional(),
|
|
1208
|
+
}), req.body);
|
|
1209
|
+
if (!parsed.success)
|
|
1210
|
+
return void res.status(400).json({ error: parsed.error.flatten() });
|
|
1211
|
+
res.json(await runBondSlash(parsed.data));
|
|
1212
|
+
});
|
|
1213
|
+
ctx.app.get("/api/pipeline/full", (_req, res) => {
|
|
1214
|
+
res.json({
|
|
1215
|
+
name: "x402 Agent Suite Pro — Full Pipeline",
|
|
1216
|
+
primaryEntrypoints: [
|
|
1217
|
+
"POST /api/x402/proxy — killer all-in-one preflight ($0.08)",
|
|
1218
|
+
"POST /api/guard/pre-x402 — lightweight guard ($0.05)",
|
|
1219
|
+
"POST /api/mpp/session — MPP batch savings ($0.03)",
|
|
1220
|
+
"POST /api/attestation/issue — trust registry ($0.04)",
|
|
1221
|
+
"POST /api/pipeline/execute — full orchestration ($0.25)",
|
|
1222
|
+
],
|
|
1223
|
+
recommendedOrder: [
|
|
1224
|
+
"POST /api/pipeline/execute (or guard + steps below)",
|
|
1225
|
+
"POST /api/payment-intent/compile",
|
|
1226
|
+
"POST /api/guard/pre-x402",
|
|
1227
|
+
"POST /api/facilitator/failover",
|
|
1228
|
+
"POST /api/router/route",
|
|
1229
|
+
"(downstream x402 call)",
|
|
1230
|
+
"POST /api/receipt-auditor/verify",
|
|
1231
|
+
"POST /api/settlement-graph/next",
|
|
1232
|
+
"POST /api/refund-arbiter/evaluate",
|
|
1233
|
+
],
|
|
1234
|
+
estimatedSuiteOnlyUsdc: Object.values(SUITE_PRICES).reduce((a, b) => a + b, 0).toFixed(2),
|
|
1235
|
+
bundleSavingsNote: "pre-x402 guard replaces 3 calls ($0.16 → $0.05); pipeline/execute replaces guard+plan+failover+router ($0.27+ → $0.25)",
|
|
1236
|
+
});
|
|
1237
|
+
});
|
|
1238
|
+
registerProtocolRoutes(app, paid, asyncRoute);
|
|
1239
|
+
return ctx.postHandlers;
|
|
1240
|
+
}
|