cred402/lib/services/fleet_overview.ts
caelum0x 2d43618725 feat: real integrations (Casper Testnet, x402/EIP-712, MCP, RealFi, cross-chain), wallet sign-in, branding
Replace the design-note docs (p1–p7) with the implemented "make it real" phase
docs (p8–p10) and wire production-grade, env-gated real integrations:

- p8 Casper Testnet: byte-exact deploys + WASM install via casper-js-sdk; live
  node reads (node.testnet.casper.network); CRED402_CHAIN=sim|testnet transport.
- p9 x402 + data + MCP: real EIP-712 typed-data digests (@casper-ecosystem/
  casper-eip-712); casper-x402 facilitator client (x402 V2); live Open-Meteo GHI;
  official @modelcontextprotocol/sdk server; casper-sidecar SSE event feed.
- p10 RealFi + cross-chain: real Stripe test-mode webhooks (HMAC-verified) and
  Plaid sandbox → privacy-preserving on-chain envelopes; Base Sepolia EVM deploy
  (Foundry); reachable via /api/realfi/* and /api/x402/facilitator routes.
- Sign-in with Casper Wallet: real extension provider + challenge/ed25519/session
  flow (/v1/auth/wallet/*), console connect + sign-in button.
- Branding: Cred402 logo mark, favicon, OG image; Vercel config for the console.

All env-gated with sim/free-API fallbacks; full suite green, all toolchains
(TS/Rust/Go/Solidity) build.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-17 00:37:36 +03:00

69 lines
2.2 KiB
TypeScript

import type { Ledger } from "../ledger/ledger.js";
import type { AttestationGraph } from "./attestation_graph.js";
import { discoverAgents } from "./discovery.js";
import { buildOnboardingScorecard } from "./onboarding_scorecard.js";
/**
* Fleet overview — for an operator running many agents, a one-call dashboard that
* joins each agent's discovery standing with its credit readiness and current line.
* Unknown ids are surfaced rather than dropped so the caller can reconcile its list.
*/
export interface FleetAgentRow {
agent_id: string;
exists: boolean;
service_type?: string;
reputation?: number;
credit_score?: number;
discovery_score?: number;
tier?: string;
ready?: boolean;
readiness_pct?: number;
has_credit_line?: boolean;
drawn_motes?: string;
}
export interface FleetOverview {
count: number;
ready: number;
not_ready: number;
unknown: number;
agents: FleetAgentRow[];
}
export function buildFleetOverview(ledger: Ledger, attestations: AttestationGraph, agentIds: string[]): FleetOverview {
const discovery = discoverAgents(ledger, attestations, { limit: 200 });
const rankByAgent = new Map(discovery.results.map((r) => [r.agent_id, r]));
const agents: FleetAgentRow[] = agentIds.map((id) => {
const agent = ledger.agents.get(id);
if (!agent) return { agent_id: id, exists: false };
const readiness = buildOnboardingScorecard(ledger, id);
const rank = rankByAgent.get(id);
const line = ledger.pool.get(id);
return {
agent_id: id,
exists: true,
service_type: agent.service_type,
reputation: agent.reputation_score,
credit_score: agent.credit_score,
discovery_score: rank?.score ?? 0,
tier: rank?.tier ?? "unrated",
ready: "error" in readiness ? false : readiness.ready,
readiness_pct: "error" in readiness ? 0 : readiness.readiness_pct,
has_credit_line: line !== undefined,
drawn_motes: line ? line.drawn.toString() : "0",
};
});
const existing = agents.filter((r) => r.exists);
const ready = existing.filter((r) => r.ready).length;
return {
count: agents.length,
ready,
not_ready: existing.length - ready,
unknown: agents.length - existing.length,
agents,
};
}