From a1d9de406bdd55d81b32ffa3584a7b36ce38fbc9 Mon Sep 17 00:00:00 2001 From: OG T Date: Mon, 8 Jun 2026 00:54:13 +0800 Subject: [PATCH] fix(web): create_sub_task reward_amount object access --- apps/web/src/app/api/mcp/[tool]/route.ts | 4 +- scripts/simulate_agent.ts | 68 ++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 scripts/simulate_agent.ts diff --git a/apps/web/src/app/api/mcp/[tool]/route.ts b/apps/web/src/app/api/mcp/[tool]/route.ts index 16cae0e..ac88ee9 100644 --- a/apps/web/src/app/api/mcp/[tool]/route.ts +++ b/apps/web/src/app/api/mcp/[tool]/route.ts @@ -712,7 +712,7 @@ export async function POST(request: NextRequest, props: { params: Promise<{ tool if (!claim || claim.task_id !== parsed.parent_task_id || claim.status !== TaskStatus.EXECUTING) { throw new Error("Invalid claim token or parent task is not EXECUTING"); } - if (parsed.reward_amount >= claim.held_amount) { + if (parsed.reward_amount.amount >= claim.held_amount) { throw new Error("Sub-task reward cannot exceed parent task reward"); } @@ -722,7 +722,7 @@ export async function POST(request: NextRequest, props: { params: Promise<{ tool description: parsed.description, status: TaskStatus.OPEN, difficulty: "HELLO_WORLD", - reward_amount: parsed.reward_amount, + reward_amount: parsed.reward_amount.amount, reward_currency: claim.held_currency, required_stack: ["A2A", "Agent Sub-Task"], scope_clarity_score: 1.0, diff --git a/scripts/simulate_agent.ts b/scripts/simulate_agent.ts new file mode 100644 index 0000000..caa8604 --- /dev/null +++ b/scripts/simulate_agent.ts @@ -0,0 +1,68 @@ +import { v4 as uuidv4 } from "uuid"; + +const API_BASE = "http://192.168.0.110:3000/api/mcp"; +const API_KEY = "super-secret-mcp-key"; + +async function callTool(tool: string, payload: any) { + const res = await fetch(`${API_BASE}/${tool}`, { + method: "POST", + headers: { + "Content-Type": "application/json", + "Authorization": `Bearer ${API_KEY}` + }, + body: JSON.stringify(payload) + }); + const data = await res.json(); + if (!res.ok) { + console.error(`Tool ${tool} failed with status ${res.status}:`, JSON.stringify(data, null, 2)); + throw new Error(`Tool ${tool} failed.`); + } + return data; +} + +async function main() { + console.log("šŸ¤– [Simulated Agent] Booting up..."); + const agentId = "agent-simulator-" + Math.floor(Math.random() * 1000); + + const targetTaskId = "5b7e923e-6a5b-4395-9b24-7df84d1bc81e"; + console.log(`Selecting Task ID: ${targetTaskId}`); + + console.log("\nšŸ’° 2. Claiming Task..."); + const claimRes = await callTool("claim_task", { + task_id: targetTaskId, + agent_id: agentId, + developer_wallet: "0x1234567890123456789012345678901234567890" + }); + console.log("Claimed successfully. Claim Token:", claimRes.claim_token); + + console.log("\nšŸ¤–šŸ”„šŸ¤– 3. Demonstrating A2A (Agent-to-Agent) Subcontracting..."); + // Now we create a subtask! + const subTaskRes = await callTool("create_sub_task", { + parent_task_id: targetTaskId, + claim_token: claimRes.claim_token, + title: "Write unit tests for the fibonacci function", + description: "Write comprehensive unit tests in Jest for fib(n).", + reward_amount: { amount: 1000, currency: "USD" }, // $10 out of the $500 + acceptance_criteria: { + validation_mode: "AST_PARSING", + test_file_content: "import { test } from 'jest'; test('fake', () => { /* min 20 chars */ });" + } + }); + console.log("Sub-task created successfully! Sub Task ID:", subTaskRes.sub_task_id); + + console.log("\nšŸš€ 4. Submitting Solution for Main Task..."); + const solutionRes = await callTool("submit_solution", { + task_id: targetTaskId, + claim_token: claimRes.claim_token, + deliverables: { + "index.ts": "export function fib(n: number): number {\n if(n<=1) return n;\n let a=0, b=1, c=0;\n for(let i=2; i<=n; i++) { c=a+b; a=b; b=c; }\n return b;\n}" + }, + github_pr_url: "https://github.com/example/pr/1" + }); + console.log("Solution submitted! Submission ID:", solutionRes.submission_id); + console.log("Status:", solutionRes.status); + + console.log("\nāœ… Simulation complete. Now we wait for the E2B Sandbox judge and the FOMO broadcaster to trigger!"); +} + +main().catch(console.error);