[taskboard] auto-dispatch telegram swarm tasks
This commit is contained in:
@@ -3,6 +3,11 @@ import { NextResponse } from "next/server";
|
||||
import { findAgentByAssignmentKey } from "@/lib/agents";
|
||||
import { createTask, listTasks, validateTaskPayload } from "@/lib/tasks";
|
||||
|
||||
function extractTagValue(tags: string[], prefix: string) {
|
||||
const match = tags.find((tag) => tag.startsWith(prefix));
|
||||
return match ? match.slice(prefix.length) : null;
|
||||
}
|
||||
|
||||
export async function GET() {
|
||||
return NextResponse.json(await listTasks());
|
||||
}
|
||||
@@ -15,28 +20,44 @@ export async function POST(request: Request) {
|
||||
}
|
||||
|
||||
const assignee = typeof payload.assignee === "string" ? payload.assignee : "";
|
||||
const tags = Array.isArray(payload.tags) ? payload.tags.filter((tag) => typeof tag === "string") : [];
|
||||
const assigneeAgent = assignee ? await findAgentByAssignmentKey(assignee) : null;
|
||||
const derivedRepoSlug = typeof payload.repo_slug === "string" ? payload.repo_slug : extractTagValue(tags, "repo:");
|
||||
const derivedPreferredAgent =
|
||||
typeof payload.preferred_agent === "string" ? payload.preferred_agent : extractTagValue(tags, "agent:");
|
||||
const requestedFamily = payload.family === null ? null : (payload.family as never);
|
||||
const requestedDispatchMethod = payload.dispatch_method as never;
|
||||
const wantsOpenClawSwarm =
|
||||
requestedFamily === "openclaw" ||
|
||||
requestedDispatchMethod === "openclaw-swarm" ||
|
||||
tags.includes("swarm") ||
|
||||
Boolean(derivedRepoSlug) ||
|
||||
Boolean(derivedPreferredAgent && ["codex", "opencode", "gemini"].includes(derivedPreferredAgent));
|
||||
|
||||
const task = await createTask({
|
||||
title: String(payload.title),
|
||||
description: typeof payload.description === "string" ? payload.description : "",
|
||||
assignee,
|
||||
family: (payload.family as never) || assigneeAgent?.family || null,
|
||||
target_host: typeof payload.target_host === "string" ? payload.target_host : assigneeAgent?.host || "",
|
||||
family: requestedFamily || assigneeAgent?.family || (wantsOpenClawSwarm ? "openclaw" : null),
|
||||
target_host:
|
||||
typeof payload.target_host === "string"
|
||||
? payload.target_host
|
||||
: assigneeAgent?.host || (wantsOpenClawSwarm ? "ubuntu" : ""),
|
||||
target_channel:
|
||||
typeof payload.target_channel === "string"
|
||||
? payload.target_channel
|
||||
: assigneeAgent?.channels[0]?.value || "",
|
||||
: assigneeAgent?.channels[0]?.value || (wantsOpenClawSwarm ? "OpenClaw swarm registry" : ""),
|
||||
dispatch_method:
|
||||
(payload.dispatch_method as never) || assigneeAgent?.defaultDispatchMethod || "manual",
|
||||
requestedDispatchMethod || assigneeAgent?.defaultDispatchMethod || (wantsOpenClawSwarm ? "openclaw-swarm" : "manual"),
|
||||
template_key: typeof payload.template_key === "string" ? payload.template_key : null,
|
||||
repo_slug: typeof payload.repo_slug === "string" ? payload.repo_slug : null,
|
||||
repo_slug: derivedRepoSlug,
|
||||
base_branch: typeof payload.base_branch === "string" ? payload.base_branch : null,
|
||||
preferred_agent: typeof payload.preferred_agent === "string" ? payload.preferred_agent : null,
|
||||
preferred_agent: derivedPreferredAgent,
|
||||
reasoning_effort: typeof payload.reasoning_effort === "string" ? payload.reasoning_effort : null,
|
||||
model_hint: typeof payload.model_hint === "string" ? payload.model_hint : null,
|
||||
priority: payload.priority as never,
|
||||
status: (payload.status as never) || "Backlog",
|
||||
tags: Array.isArray(payload.tags) ? payload.tags.filter((tag) => typeof tag === "string") : [],
|
||||
tags,
|
||||
});
|
||||
|
||||
return NextResponse.json(task, { status: 201 });
|
||||
|
||||
Reference in New Issue
Block a user