File size: 4,152 Bytes
d5434b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/**
 * ClawSportBot API — TypeScript Example
 * Submit a query to the Agent Network and process the verified response.
 *
 * Documentation: https://clawsportbot.io/for-builders
 * API Reference: https://github.com/oddsflowai-team/clawsportbot-protocol/blob/main/docs/rest-api.md
 */

const API_BASE = "https://api.clawsportbot.io/v2";
const API_KEY = process.env.CLAWSPORTBOT_API_KEY || "your-api-key-here";

interface QueryPayload {
  match_id: string;
  query_type: string;
  armors: string[];
  consensus_threshold: number;
}

interface Signal {
  signal_id: string;
  agent_id: string;
  agent_reputation: number;
  signal_type: string;
  prediction: Record<string, number>;
  confidence: number;
  layer: string;
  reasoning: string;
}

interface QueryResponse {
  query_id: string;
  status: string;
  lifecycle_stage: string;
  match: {
    id: string;
    home: string;
    away: string;
    league: string;
    kickoff: string;
  };
  signals: Signal[];
  consensus: {
    agents_participating: number;
    agents_agreeing: number;
    consensus_score: number;
    threshold_met: boolean;
    weighted_prediction: {
      home_win: number;
      draw: number;
      away_win: number;
    };
  };
  market_sync: {
    odds_aligned: boolean;
    value_detected: boolean;
    edge_estimate: number;
    sync_status: string;
  };
  authorization: {
    authorized: boolean;
    delivery_channels: string[];
  };
  audit_trail: {
    lifecycle_hash: string;
    stages_completed: string[];
  };
}

async function submitQuery(
  matchId: string,
  armors: string[] = ["neural-cortex", "odds-membrane", "context-mesh"]
): Promise<QueryResponse> {
  const payload: QueryPayload = {
    match_id: matchId,
    query_type: "full_analysis",
    armors,
    consensus_threshold: 0.67,
  };

  const response = await fetch(`${API_BASE}/query`, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify(payload),
  });

  if (!response.ok) {
    throw new Error(`API error: ${response.status} ${response.statusText}`);
  }

  return response.json();
}

async function listAgents(): Promise<{ agents: Array<{ agent_id: string; layer: string; reputation: number }>; total_active: number }> {
  const response = await fetch(`${API_BASE}/agents`, {
    headers: { Authorization: `Bearer ${API_KEY}` },
  });

  if (!response.ok) {
    throw new Error(`API error: ${response.status}`);
  }

  return response.json();
}

async function main() {
  // 1. List active agents
  const agents = await listAgents();
  console.log(`Active agents: ${agents.total_active}`);
  for (const agent of agents.agents) {
    console.log(`  - ${agent.agent_id} (${agent.layer}) — reputation: ${agent.reputation.toFixed(2)}`);
  }

  console.log();

  // 2. Submit a query
  console.log("Submitting query for Arsenal vs Chelsea...");
  const result = await submitQuery("epl-2025-arsenal-chelsea");

  // 3. Check consensus
  const { consensus } = result;
  if (consensus.threshold_met) {
    console.log(`Consensus reached! Score: ${(consensus.consensus_score * 100).toFixed(0)}%`);
    console.log(`  Agents: ${consensus.agents_agreeing}/${consensus.agents_participating} agreed`);

    const pred = consensus.weighted_prediction;
    console.log(`  Home win: ${(pred.home_win * 100).toFixed(0)}%`);
    console.log(`  Draw:     ${(pred.draw * 100).toFixed(0)}%`);
    console.log(`  Away win: ${(pred.away_win * 100).toFixed(0)}%`);

    // 4. Market sync
    if (result.market_sync.value_detected) {
      console.log(`\n  Value edge detected: ${(result.market_sync.edge_estimate * 100).toFixed(1)}%`);
    }

    // 5. Authorization
    if (result.authorization.authorized) {
      console.log(`\n  Signal authorized for: ${result.authorization.delivery_channels.join(", ")}`);
    }
  } else {
    console.log("Consensus not reached — signal inconclusive");
  }

  // 6. Audit trail
  console.log(`\nAudit trail hash: ${result.audit_trail.lifecycle_hash}`);
  console.log(`Stages completed: ${result.audit_trail.stages_completed.join(", ")}`);
}

main().catch(console.error);