cred402/lib/services/agent_dossier.ts
caelum0x 5cf86893e3 feat(contracts): deploy Cred402 Odra contracts to Casper Testnet (Casper 2.0)
Migrate the contract suite to Odra 2.x (builds on the Casper 2.0 ABI; fixes the
1.x nightly/edition2024 toolchain deadlock) and deploy 9 contracts live to
casper-test via the Odra livenet deployer:

  AgentRegistry · X402ReceiptRegistry · RWAEvidenceRegistry · RWAAssetRegistry
  ReputationEngine · AgentCreditPool · RiskPolicyManager · AgentPassport · DisputeCourt

- contracts: odra "2", no_std headers, build.rs (odra-build), per-crate Odra.toml +
  build_contract/livenet bins; pinned nightly-2025-01-15 for reproducible wasm.
- tooling: scaffold_livenet.py, deploy_all_testnet.sh, deploy_one.mjs.
- deploys.testnet.json: live manifest; README: on-chain contract hashes.
- Deployer key kept out of git (.secrets/ gitignored); wasm artifacts gitignored.

Verified on-chain: AgentRegistry ContractPackage present in global state.

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

60 lines
2.7 KiB
TypeScript

import type { Ledger } from "../ledger/ledger.js";
import type { AttestationGraph } from "./attestation_graph.js";
import { buildAgentHealthBadge } from "./agent_health.js";
import { buildPeerBenchmark } from "./peer_benchmark.js";
import { buildOnboardingScorecard } from "./onboarding_scorecard.js";
import { buildScoreTrend } from "./score_trend.js";
import { computeTier } from "./reputation_tiers.js";
/**
* Agent dossier — the integrator's one-call snapshot. Dashboards otherwise fan out
* 6+ requests per agent (passport, tier, health, benchmark, readiness, line); this
* bundles the bureau-level view into a single `/v1` round-trip. Each section reuses
* the same canonical services as its standalone endpoint, so the dossier never
* drifts from the individual reads.
*/
export interface AgentDossier {
agent_id: string;
service_type: string;
reputation: number;
credit_score: number;
tier: string;
health: { status: string; score: number };
readiness: { ready: boolean; readiness_pct: number };
benchmark: { cohort_size: number; overall_percentile: number };
reputation_change: number; // net, from the score trend
credit_line: { max_credit_motes: string; drawn_motes: string; status: string } | null;
operator: string | null;
}
export function buildAgentDossier(
ledger: Ledger,
attestations: AttestationGraph,
agentId: string,
): AgentDossier | { error: string } {
const agent = ledger.agents.get(agentId);
if (!agent) return { error: `unknown agent: ${agentId}` };
const tier = computeTier(ledger, agentId);
const health = buildAgentHealthBadge(ledger, agentId);
const readiness = buildOnboardingScorecard(ledger, agentId);
const benchmark = buildPeerBenchmark(ledger, agentId);
const trend = buildScoreTrend(ledger, agentId);
const line = ledger.pool.get(agentId);
return {
agent_id: agentId,
service_type: agent.service_type,
reputation: agent.reputation_score,
credit_score: agent.credit_score,
tier: "tier" in tier ? tier.tier : "unrated",
health: "error" in health ? { status: "unknown", score: 0 } : { status: health.status, score: health.score },
readiness: "error" in readiness ? { ready: false, readiness_pct: 0 } : { ready: readiness.ready, readiness_pct: readiness.readiness_pct },
benchmark: "error" in benchmark ? { cohort_size: 0, overall_percentile: 0 } : { cohort_size: benchmark.cohort_size, overall_percentile: benchmark.overall_percentile },
reputation_change: "error" in trend ? 0 : trend.reputation.change,
credit_line: line ? { max_credit_motes: line.max_credit.toString(), drawn_motes: line.drawn.toString(), status: line.status } : null,
operator: ledger.buildPassport(agentId)?.operator ?? null,
};
}