refactor(api-server): extract IMPORTANT_DOC_TYPES constant

Move the duplicated important-document-type list out of routes-tasks.ts
and routes-files.ts into src/shared/document-categories.ts so the array
and lookup set live in one place.
This commit is contained in:
ZacharyZhang-NY committed 2026-04-16 22:27:56 -04:00
1 parent 12027562e3
commit 18bcd0abfc
3 files changed
+26 -3

No files matched your search

+2 -2
View File
@@ -1,4 +1,5 @@
import { z } from "zod";
import { IMPORTANT_DOC_TYPE_SET } from "@shared/document-categories";
import { requireParam, type AgentApiServer } from "./server-core";
type DocumentRow = {
@@ -133,8 +134,7 @@ export function registerFileRoutes(server: AgentApiServer) {
// Deliverable review gate: check at document creation time (most reliable).
// In ai_cofounder mode, checkpoint-engine handles document reviews via the
// onDocumentCreated callback, so skip the direct approval here to avoid duplicates.
const IMPORTANT_DOC_TYPES = new Set(["prd","technical_spec","design_doc","project_brief","proposal","budget_proposal","architecture_decision","contract","sop"]);
if (IMPORTANT_DOC_TYPES.has(docType)) {
if (IMPORTANT_DOC_TYPE_SET.has(docType)) {
try {
const companySettings = db.getCompanyApprovalSettings(token.companyId);
const company = companySettings ? { reviewDeliverables: companySettings.reviewDeliverables } : null;
+2 -1
View File
@@ -1,5 +1,6 @@
import { z } from "zod";
import { taskInputSchema } from "@shared/contracts";
import { IMPORTANT_DOC_TYPES } from "@shared/document-categories";
import { canAssignTask, canUpdateTask } from "../agent-permissions";
import { inferTaskType } from "../connector-matching";
import { validateTaskCreation } from "../task-quality-gates";
@@ -138,7 +139,7 @@ export function registerTaskRoutes(server: AgentApiServer) {
// Deliverable review gate: intercept agent trying to advance a flagged task to "done".
// This MUST succeed — silently skipping review would let unreviewed work advance.
if (update.status === "done" && task.requiresUserReview) {
const importantTypes = ["prd","technical_spec","design_doc","project_brief","proposal","budget_proposal","architecture_decision","contract","sop"];
const importantTypes = IMPORTANT_DOC_TYPES;
const placeholders = importantTypes.map(() => "?").join(", ");
const docs = db.queryAll<{ id: string; type: string; title: string }>(
`select id, type, title from documents where company_id = ? and type in (${placeholders})
+22
View File
@@ -0,0 +1,22 @@
/**
* Document type categories shared between db, route handlers, and clients.
*
* IMPORTANT_DOC_TYPES are the document types that trigger deliverable-review
* approvals (PRDs, specs, design docs, contracts, etc.). The ordering matters
* for some lookup queries; keep this in sync with database/documents.ts.
*/
export const IMPORTANT_DOC_TYPES = [
"prd",
"technical_spec",
"design_doc",
"project_brief",
"proposal",
"budget_proposal",
"architecture_decision",
"contract",
"sop",
] as const;
export type ImportantDocType = (typeof IMPORTANT_DOC_TYPES)[number];
export const IMPORTANT_DOC_TYPE_SET: ReadonlySet<string> = new Set(IMPORTANT_DOC_TYPES);