Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
792 changes: 681 additions & 111 deletions backend/package-lock.json

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
"lint": "eslint src/",
"format": "prettier --write src/",
"test": "vitest run",
"test:watch": "vitest"
"test:watch": "vitest",
"mcp": "npx tsx src/mcp/server.ts"
},
"dependencies": {
"@modelcontextprotocol/sdk": "^1.12.1",
"@casper-ecosystem/casper-eip-712": "1.2.1",
"@make-software/casper-x402": "1.0.0",
"@noble/hashes": "1.4.0",
Expand All @@ -23,7 +25,8 @@
"cors": "2.8.5",
"dotenv": "16.4.5",
"express": "4.19.2",
"express-rate-limit": "7.3.1"
"express-rate-limit": "7.3.1",
"zod": "^3.24.4"
},
"devDependencies": {
"@types/cors": "2.8.17",
Expand Down
29 changes: 26 additions & 3 deletions backend/src/agentStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ export interface AgentRecord {
active: boolean;
reputationScore: number;
tasksCompleted: number;
tasksFailed: number;
lastUpdated: string; // ISO timestamp of last reputation change
source: "on-chain" | "local";
demo?: boolean; // true for seeded coordinator agents
}

const STORE_PATH = path.resolve(__dirname, "..", "data", "agents.json");
Expand All @@ -34,7 +37,12 @@ function loadLocal(): void {
removed++;
continue;
}
agents.set(k, { ...rec, source: rec.source ?? "local" });
agents.set(k, {
...rec,
source: rec.source ?? "local",
tasksFailed: rec.tasksFailed ?? 0,
lastUpdated: rec.lastUpdated ?? new Date(0).toISOString(),
});
}
if (removed > 0) {
console.warn(`[AgentStore] Removed ${removed} agents with invalid account hashes`);
Expand Down Expand Up @@ -106,6 +114,8 @@ export function addAgent(
active: true,
reputationScore: 5000,
tasksCompleted: 0,
tasksFailed: 0,
lastUpdated: new Date().toISOString(),
source: "local",
});
saveLocal();
Expand Down Expand Up @@ -173,9 +183,22 @@ export async function seedCoordinatorAgents(): Promise<void> {
const priceMotes = "500000000";
const caps = ["research", "risk", "coding", "design", "audit", "report"];
for (const cap of caps) {
addAgent(acctHash, `coordinator://${cap}`, cap, priceMotes);
agents.set(acctHash, {
accountHash: acctHash,
endpoint: `coordinator://${cap}`,
capability: cap,
pricePerTask: priceMotes,
active: true,
reputationScore: 5000,
tasksCompleted: 0,
tasksFailed: 0,
lastUpdated: new Date().toISOString(),
source: "local",
demo: true,
});
}
console.log(`[AgentStore] Seeded ${caps.length} coordinator agents with hash ${acctHash.slice(0, 14)}…`);
saveLocal();
console.log(`[AgentStore] Seeded ${caps.length} coordinator agents (demo=true) with hash ${acctHash.slice(0, 14)}…`);
} catch (err) {
console.warn(`[AgentStore] Could not seed coordinator agents: ${err}`);
}
Expand Down
16 changes: 13 additions & 3 deletions backend/src/casperHandler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import axios, { AxiosInstance } from "axios";

const SDK = require("casper-js-sdk");
const { TypedJSON } = require("typedjson");
let sdkMod: typeof import("casper-js-sdk") | null = null;
let typedJsonMod: typeof import("typedjson") | null = null;

async function loadSdk() {
if (!sdkMod) sdkMod = await import("casper-js-sdk");
return sdkMod;
}
async function loadTypedJson() {
if (!typedJsonMod) typedJsonMod = await import("typedjson");
return typedJsonMod;
}

/**
* Standalone RPC handler using standard axios (not fetch adapter).
Expand All @@ -19,12 +28,13 @@
});
}

async processCall(payload: object): Promise<any> {

Check warning on line 31 in backend/src/casperHandler.ts

View workflow job for this annotation

GitHub Actions / Backend Tests

Unexpected any. Specify a different type
const ser = new TypedJSON(SDK.RpcRequest);
const [SDK, { TypedJSON }] = await Promise.all([loadSdk(), loadTypedJson()]);
const ser = new TypedJSON(SDK.RpcRequest as any);

Check warning on line 33 in backend/src/casperHandler.ts

View workflow job for this annotation

GitHub Actions / Backend Tests

Unexpected any. Specify a different type
let jsonStr: string;
try {
jsonStr = ser.stringify(payload);
} catch (e: any) {

Check warning on line 37 in backend/src/casperHandler.ts

View workflow job for this annotation

GitHub Actions / Backend Tests

Unexpected any. Specify a different type
throw new Error(`Failed to serialize RPC request: ${e.message}`);
}

Expand All @@ -50,7 +60,7 @@
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
try {
return await fn();
} catch (err: any) {

Check warning on line 63 in backend/src/casperHandler.ts

View workflow job for this annotation

GitHub Actions / Backend Tests

Unexpected any. Specify a different type
lastError = err instanceof Error ? err : new Error(String(err));
if (attempt < maxAttempts) {
const delay = baseDelayMs * Math.pow(2, attempt - 1);
Expand Down
Loading
Loading