chore: production rollout for external traffic monitoring, SDK ecosystem, and admin observability
Some checks failed
Deploy to 110 WOOO Server / deploy (push) Failing after 9s
Some checks failed
Deploy to 110 WOOO Server / deploy (push) Failing after 9s
This commit is contained in:
171
scripts/swarm-commander.ts
Normal file
171
scripts/swarm-commander.ts
Normal file
@@ -0,0 +1,171 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import crypto from 'crypto';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
|
||||
const AGENT_TYPES = ["BUILDER", "EVALUATOR", "JUDGE", "SCOUT"];
|
||||
const SKILLS = ["React", "Node.js", "Python", "Rust", "Go", "Solidity", "DevOps", "AI", "Design"];
|
||||
|
||||
function randomChoice<T>(arr: T[]): T {
|
||||
return arr[Math.floor(Math.random() * arr.length)];
|
||||
}
|
||||
|
||||
function randomSkills(count: number) {
|
||||
const shuffled = [...SKILLS].sort(() => 0.5 - Math.random());
|
||||
return shuffled.slice(0, count);
|
||||
}
|
||||
|
||||
async function runSimulation() {
|
||||
console.log("🌊 The Great Swarm Commander Initiated 🌊");
|
||||
|
||||
// 1. Generate 50 Agents
|
||||
console.log("[1/4] Generating 50 Agents...");
|
||||
const agentIds: string[] = [];
|
||||
for (let i = 0; i < 50; i++) {
|
||||
const id = `agent_sim_${crypto.randomBytes(4).toString("hex")}`;
|
||||
const type = randomChoice(AGENT_TYPES);
|
||||
const wallet = `0x${crypto.randomBytes(20).toString("hex")}`;
|
||||
await prisma.agentProfile.upsert({
|
||||
where: { agent_id: id },
|
||||
update: { status: "WHITELISTED" },
|
||||
create: {
|
||||
agent_id: id,
|
||||
type: type,
|
||||
status: "WHITELISTED",
|
||||
capabilities: randomSkills(3),
|
||||
discovery_source: "SIMULATION",
|
||||
crypto_address: wallet,
|
||||
}
|
||||
});
|
||||
agentIds.push(id);
|
||||
if (i % 10 === 0) console.log(` - Generated ${i} agents...`);
|
||||
}
|
||||
console.log(`✅ 50 Agents ready.`);
|
||||
|
||||
// Infinite simulation loop
|
||||
console.log("🔥 Commencing Chaos Loop. Watch the Explorer! 🔥");
|
||||
|
||||
let loopCount = 0;
|
||||
while (true) {
|
||||
loopCount++;
|
||||
console.log(`\n--- Cycle ${loopCount} ---`);
|
||||
|
||||
// A. Create 1-3 new tasks
|
||||
const numTasks = Math.floor(Math.random() * 3) + 1;
|
||||
for (let i = 0; i < numTasks; i++) {
|
||||
const difficulty = randomChoice(["BASIC", "HARD", "EPIC", "EPIC"]);
|
||||
let reward = 0;
|
||||
if (difficulty === "BASIC") reward = Math.floor(Math.random() * 100) + 50;
|
||||
if (difficulty === "HARD") reward = Math.floor(Math.random() * 1000) + 500;
|
||||
if (difficulty === "EPIC") reward = Math.floor(Math.random() * 10000) + 5000;
|
||||
|
||||
const task = await prisma.task.create({
|
||||
data: {
|
||||
title: `[Sim] Auto-generated Task ${Date.now()}`,
|
||||
description: `This is an automated simulation task needing ${randomChoice(SKILLS)}.`,
|
||||
difficulty: difficulty,
|
||||
status: "OPEN",
|
||||
reward_amount: reward,
|
||||
scout_id: randomChoice(agentIds),
|
||||
}
|
||||
});
|
||||
console.log(`[+] Task Created: ${task.id} (${difficulty} - $${reward})`);
|
||||
}
|
||||
|
||||
// B. Find some OPEN tasks and add bids
|
||||
const openTasks = await prisma.task.findMany({ where: { status: "OPEN" }, take: 5 });
|
||||
for (const task of openTasks) {
|
||||
const builder = randomChoice(agentIds);
|
||||
const bidAmount = Math.floor(task.reward_amount * (Math.random() * 0.5 + 0.5));
|
||||
await prisma.bidProposal.create({
|
||||
data: {
|
||||
task_id: task.id,
|
||||
agent_id: builder,
|
||||
bid_amount: bidAmount,
|
||||
status: "PENDING",
|
||||
broker_agent_id: Math.random() > 0.7 ? randomChoice(agentIds) : null,
|
||||
broker_fee_percentage: Math.random() > 0.7 ? 5 : null,
|
||||
}
|
||||
});
|
||||
console.log(` └─ Bid placed on ${task.id} by ${builder} for $${bidAmount}`);
|
||||
|
||||
// 50% chance to accept a bid and move to IN_PROGRESS
|
||||
if (Math.random() > 0.5) {
|
||||
await prisma.task.update({
|
||||
where: { id: task.id },
|
||||
data: { status: "IN_PROGRESS", builder_id: builder }
|
||||
});
|
||||
await prisma.bidProposal.updateMany({
|
||||
where: { task_id: task.id, agent_id: builder },
|
||||
data: { status: "ACCEPTED" }
|
||||
});
|
||||
console.log(` └─ Task ${task.id} assigned to ${builder}!`);
|
||||
}
|
||||
}
|
||||
|
||||
// C. Find some IN_PROGRESS tasks and complete or dispute them
|
||||
const inProgressTasks = await prisma.task.findMany({ where: { status: "IN_PROGRESS" }, take: 5 });
|
||||
for (const task of inProgressTasks) {
|
||||
if (Math.random() > 0.3) {
|
||||
// 70% chance to complete normally
|
||||
await prisma.task.update({
|
||||
where: { id: task.id },
|
||||
data: { status: "COMPLETED" }
|
||||
});
|
||||
console.log(` [✓] Task ${task.id} completed successfully.`);
|
||||
} else {
|
||||
// 30% chance to DISPUTE
|
||||
await prisma.task.update({
|
||||
where: { id: task.id },
|
||||
data: { status: "DISPUTED" }
|
||||
});
|
||||
// Create an arbitration case
|
||||
const judges = randomSkills(3).map(() => randomChoice(agentIds)); // Just pick 3 random agents
|
||||
const arb = await prisma.arbitration.create({
|
||||
data: {
|
||||
task_id: task.id,
|
||||
status: "IN_PROGRESS",
|
||||
judge_agents: judges,
|
||||
}
|
||||
});
|
||||
console.log(` [!] DISPUTE RAISED on ${task.id}! Arbitration ${arb.id} started.`);
|
||||
}
|
||||
}
|
||||
|
||||
// D. Resolve Arbitrations
|
||||
const arbitrations = await prisma.arbitration.findMany({ where: { status: "IN_PROGRESS" }, take: 3 });
|
||||
for (const arb of arbitrations) {
|
||||
if (Math.random() > 0.5) {
|
||||
// Simulate a vote resolution
|
||||
const wonBy = Math.random() > 0.5 ? "BUILDER" : "EVALUATOR";
|
||||
await prisma.arbitration.update({
|
||||
where: { id: arb.id },
|
||||
data: {
|
||||
status: "RESOLVED",
|
||||
resolution: `Ruled in favor of ${wonBy}`,
|
||||
}
|
||||
});
|
||||
|
||||
await prisma.task.update({
|
||||
where: { id: arb.task_id },
|
||||
data: { status: wonBy === "BUILDER" ? "COMPLETED" : "OPEN", builder_id: null }
|
||||
});
|
||||
console.log(` [⚖] Arbitration ${arb.id} resolved in favor of ${wonBy}!`);
|
||||
}
|
||||
}
|
||||
|
||||
// Wait 5 seconds before next cycle
|
||||
await sleep(5000);
|
||||
}
|
||||
}
|
||||
|
||||
runSimulation()
|
||||
.catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
Reference in New Issue
Block a user