Now that the CLI and the Next.js app are one package, nesting it inside app/ served no purpose - the repo root itself becomes the published npm package. Merges app/.gitignore and app/README.md into the root versions, drops the now-duplicate app/LICENSE, and updates path references (README, docs/ARCHITECTURE.md, docs/CONFIG_REFERENCE.md, package.json's repository.directory) that assumed the app/ nesting. Also fixes a real bug this surfaced: the in-app docs viewer resolved docs/ relative to process.cwd(), which only worked by accident when the CLI happened to be invoked from app/'s parent directory. A first attempt at fixing it with import.meta.dirname broke instead, for the same cross-module-graph reason config-path resolution already documented - Next compiles Route Handlers through a separate module graph that doesn't preserve source-relative import.meta paths. Fixed by exposing the app root via TRIGGERSHELL_APP_ROOT (set once in server.ts, where import.meta *does* resolve correctly), the same pattern already used for TRIGGERSHELL_CONFIG_PATH. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
export const dynamic = "force-dynamic";
|
|
|
|
import { eq } from "drizzle-orm";
|
|
import { requireAuth, unauthorizedResponse } from "@/lib/auth/guard";
|
|
import { getDb } from "@/lib/db/client";
|
|
import { runs } from "@/lib/db/schema";
|
|
import { cancelRun } from "@/lib/runner/registry";
|
|
|
|
export async function POST(
|
|
request: Request,
|
|
{ params }: { params: Promise<{ runId: string }> },
|
|
) {
|
|
const auth = await requireAuth(request);
|
|
if (!auth.authenticated) return unauthorizedResponse();
|
|
|
|
const { runId } = await params;
|
|
const db = getDb();
|
|
const run = db.select().from(runs).where(eq(runs.id, runId)).get();
|
|
if (!run) return Response.json({ error: "Run not found" }, { status: 404 });
|
|
|
|
if (run.status !== "queued" && run.status !== "running") {
|
|
return Response.json(
|
|
{ error: `Run already ${run.status}` },
|
|
{ status: 409 },
|
|
);
|
|
}
|
|
|
|
const cancelled = cancelRun(runId);
|
|
if (!cancelled) {
|
|
return Response.json(
|
|
{ error: "Run is not active in this server process" },
|
|
{ status: 409 },
|
|
);
|
|
}
|
|
|
|
return Response.json({ status: "cancelling" }, { status: 202 });
|
|
}
|