chore: open conversion flow + disable scout import noise
Some checks failed
Deploy to 110 WOOO Server / deploy (push) Failing after 8s

This commit is contained in:
OG T
2026-06-07 18:56:45 +08:00
parent 4f639c2654
commit 4fd89a447e
10 changed files with 423 additions and 117 deletions

View File

@@ -146,110 +146,136 @@ export async function GET(request: Request) {
const isPublicIp = !isPrivateIp(sourceIp);
const trafficAction = isPublicIp ? "EXTERNAL_LIST_OPEN_TASKS" : "INTERNAL_LIST_OPEN_TASKS";
const tasks = await prisma.task.findMany({
where: {
status: TaskStatus.OPEN,
title: {
not: {
startsWith: "GitHub Issue:",
try {
const tasks = await prisma.task.findMany({
where: {
status: TaskStatus.OPEN,
title: {
not: {
startsWith: "GitHub Issue:",
},
},
},
},
orderBy: { created_at: "desc" },
select: {
id: true,
title: true,
description: true,
reward_amount: true,
reward_currency: true,
required_stack: true,
status: true,
difficulty: true,
scope_clarity_score: true,
created_at: true,
updated_at: true,
scout_id: true,
stripe_checkout_session_id: true,
stripe_payment_intent_id: true,
},
});
orderBy: { created_at: "desc" },
select: {
id: true,
title: true,
description: true,
reward_amount: true,
reward_currency: true,
required_stack: true,
status: true,
difficulty: true,
scope_clarity_score: true,
created_at: true,
updated_at: true,
scout_id: true,
stripe_checkout_session_id: true,
stripe_payment_intent_id: true,
},
});
const publicPayload = tasks.map((task) => ({
task_id: task.id,
title: task.title,
status: task.status,
difficulty: task.difficulty,
reward_amount_cents: task.reward_amount,
reward_display: `$${(task.reward_amount / 100).toFixed(2)} ${task.reward_currency}`,
required_stack: task.required_stack,
scope_clarity_score: task.scope_clarity_score,
created_at: task.created_at.toISOString(),
updated_at: task.updated_at.toISOString(),
source: task.scout_id ? "scout" : "human",
payout_mode: getPayoutMode(task),
task_url: `https://agent.wooo.work/tasks/${task.id}`,
}));
const publicPayload = tasks.map((task) => ({
task_id: task.id,
title: task.title,
status: task.status,
difficulty: task.difficulty,
reward_amount_cents: task.reward_amount,
reward_display: `$${(task.reward_amount / 100).toFixed(2)} ${task.reward_currency}`,
required_stack: task.required_stack,
scope_clarity_score: task.scope_clarity_score,
created_at: task.created_at.toISOString(),
updated_at: task.updated_at.toISOString(),
source: task.scout_id ? "scout" : "human",
payout_mode: getPayoutMode(task),
task_url: `https://agent.wooo.work/tasks/${task.id}`,
}));
const actor = resolveExternalActor(request);
const actor = resolveExternalActor(request);
void sendTrafficAlert({
level: "info",
action: trafficAction,
surface: "public-open-tasks",
actorType: actor.actorType,
actorId: actor.actorId,
taskId: "open-tasks",
message: `External discovery call for open tasks (${publicPayload.length} items)`,
metadata: {
source: "public-open-tasks",
task_count: publicPayload.length,
source_ip: sourceIp,
user_agent: request.headers.get("user-agent") ?? "unknown",
},
});
// Light-weight surge signal: when this endpoint is hit in large bursts,
// emit a warning once every 25 requests in a 10-minute window.
const surgeWindow = 10;
const surgeWindowStart = new Date(Date.now() - surgeWindow * 60 * 1000);
void prisma.auditEvent.count({
where: {
createdAt: { gte: surgeWindowStart },
void sendTrafficAlert({
level: "info",
action: trafficAction,
},
}).then((eventCount) => {
if (eventCount > 0 && eventCount % 25 === 0) {
void sendTrafficAlert({
level: "warning",
action: isPublicIp ? "EXTERNAL_LIST_OPEN_TASKS_SURGE" : "INTERNAL_LIST_OPEN_TASKS_SURGE",
surface: "public-open-tasks",
actorType: "SYSTEM",
actorId: "traffic-monitor",
taskId: "open-tasks",
message: `Open tasks discovery surge detected: ${eventCount} hits in ${surgeWindow}m`,
metadata: {
alert_window_minutes: surgeWindow,
event_count: eventCount,
surface: "public-open-tasks",
actorType: actor.actorType,
actorId: actor.actorId,
taskId: "open-tasks",
message: `External discovery call for open tasks (${publicPayload.length} items)`,
metadata: {
source: "public-open-tasks",
task_count: publicPayload.length,
source_ip: sourceIp,
user_agent: request.headers.get("user-agent") ?? "unknown",
},
});
// Light-weight surge signal: when this endpoint is hit in large bursts,
// emit a warning once every 25 requests in a 10-minute window.
const surgeWindow = 10;
const surgeWindowStart = new Date(Date.now() - surgeWindow * 60 * 1000);
void prisma.auditEvent.count({
where: {
createdAt: { gte: surgeWindowStart },
action: trafficAction,
},
}).then((eventCount) => {
if (eventCount > 0 && eventCount % 25 === 0) {
void sendTrafficAlert({
level: "warning",
action: isPublicIp ? "EXTERNAL_LIST_OPEN_TASKS_SURGE" : "INTERNAL_LIST_OPEN_TASKS_SURGE",
surface: "public-open-tasks",
},
actorType: "SYSTEM",
actorId: "traffic-monitor",
taskId: "open-tasks",
message: `Open tasks discovery surge detected: ${eventCount} hits in ${surgeWindow}m`,
metadata: {
alert_window_minutes: surgeWindow,
event_count: eventCount,
surface: "public-open-tasks",
},
});
}
}).catch(() => {});
if (isPublicIp) {
void evaluateExternalFunnelHealth({
surface: "public-open-tasks",
periodMinutes: 10,
});
}
}).catch(() => {});
if (isPublicIp) {
void evaluateExternalFunnelHealth({
surface: "public-open-tasks",
periodMinutes: 10,
return NextResponse.json({
platform: "VibeWork",
version: "v1",
discovery_mode: "ai-first",
beta_program: "VibeWork Beta Zero Friction + 0% Platform Fee for promoted tasks",
tasks: publicPayload,
total_open: publicPayload.length,
last_refreshed_at: new Date().toISOString(),
});
}
} catch (error: any) {
console.error("[open-tasks] Internal error", error);
return NextResponse.json({
platform: "VibeWork",
version: "v1",
discovery_mode: "ai-first",
beta_program: "VibeWork Beta Zero Friction + 0% Platform Fee for promoted tasks",
tasks: publicPayload,
total_open: publicPayload.length,
last_refreshed_at: new Date().toISOString(),
});
const actor = resolveExternalActor(request);
const msg = error?.message ?? "internal_error";
void sendTrafficAlert({
level: "error",
action: isPublicIp ? "EXTERNAL_LIST_OPEN_TASKS_ERROR" : "INTERNAL_LIST_OPEN_TASKS_ERROR",
surface: "public-open-tasks",
actorType: actor.actorType,
actorId: actor.actorId,
taskId: "open-tasks",
message: `open-tasks 查詢失敗: ${msg}`,
metadata: {
source: "public-open-tasks",
source_ip: sourceIp,
user_agent: request.headers.get("user-agent") ?? "unknown",
},
});
return NextResponse.json(
{ error_type: "InternalError", message: msg },
{ status: 500 }
);
}
}