feat(bounty): add A2A create_sub_task mechanism
Some checks failed
Deploy to 110 WOOO Server / deploy (push) Failing after 7s
Some checks failed
Deploy to 110 WOOO Server / deploy (push) Failing after 7s
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
ListOpenTasksRequestSchema,
|
||||
ClaimTaskRequestSchema,
|
||||
SubmitSolutionRequestSchema,
|
||||
CreateSubTaskRequestSchema,
|
||||
TaskStatus,
|
||||
JudgeOverallResult
|
||||
} from "@agent-bounty/contracts";
|
||||
@@ -684,6 +685,70 @@ export async function POST(request: NextRequest, props: { params: Promise<{ tool
|
||||
});
|
||||
}
|
||||
|
||||
case "create_sub_task": {
|
||||
const parsed = CreateSubTaskRequestSchema.parse(body);
|
||||
|
||||
const subTask = await prisma.$transaction(async (tx) => {
|
||||
const claim = await tx.claim.findUnique({ where: { claim_token: parsed.claim_token } });
|
||||
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) {
|
||||
throw new Error("Sub-task reward cannot exceed parent task reward");
|
||||
}
|
||||
|
||||
const newTask = await tx.task.create({
|
||||
data: {
|
||||
title: `[Sub-Task] ${parsed.title}`,
|
||||
description: parsed.description,
|
||||
status: TaskStatus.OPEN,
|
||||
difficulty: "HELLO_WORLD",
|
||||
reward_amount: parsed.reward_amount,
|
||||
reward_currency: claim.held_currency,
|
||||
required_stack: ["A2A", "Agent Sub-Task"],
|
||||
scope_clarity_score: 1.0,
|
||||
parent_task_id: parsed.parent_task_id,
|
||||
created_by_agent: claim.agent_id,
|
||||
acceptance_criteria: parsed.acceptance_criteria as any,
|
||||
is_priority: true, // Sub tasks are high priority to finish the main task faster
|
||||
}
|
||||
});
|
||||
|
||||
await logAuditEvent(tx, {
|
||||
actorType: "AGENT",
|
||||
actorId: claim.agent_id,
|
||||
action: "CREATE_SUB_TASK",
|
||||
entityType: "TASK",
|
||||
entityId: newTask.id,
|
||||
beforeState: null,
|
||||
afterState: { status: TaskStatus.OPEN, parent: claim.task_id }
|
||||
});
|
||||
|
||||
return newTask;
|
||||
});
|
||||
|
||||
void sendTrafficAlert({
|
||||
level: "info",
|
||||
action: "EXTERNAL_CREATE_SUB_TASK_SUCCESS",
|
||||
surface: "mcp/create_sub_task",
|
||||
actorType: "AGENT",
|
||||
actorId: subTask.created_by_agent!,
|
||||
taskId: subTask.id,
|
||||
message: `A2A 內循環!Agent 發佈了子任務: ${subTask.id}`,
|
||||
metadata: {
|
||||
parent_task_id: parsed.parent_task_id,
|
||||
reward: parsed.reward_amount,
|
||||
payload_summary: summarizeRequestPayload(tool, body),
|
||||
}
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
sub_task_id: subTask.id,
|
||||
status: subTask.status,
|
||||
request_id: requestContext.request_id,
|
||||
});
|
||||
}
|
||||
|
||||
case "check_payout_status": {
|
||||
const parsed = z.object({ task_id: z.string().uuid() }).parse(body);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user