Files
infiplot-web/lib/engine/prompts/registry.ts
T
Kai ki e31bd16b15 fix(engine): prevent directScene hang + enforce segment ID uniqueness in prod
Two defensive fixes surfaced by the PR #95 review (PR-Agent), applied on
top of the staging sync:

1. directScene: routeTaggedStream rejecting BEFORE onPlan fires would leave
   planPromise unsettled, hanging `await planPromise` — and thus the whole
   /api/start and /api/scene request — forever. Add a .catch that settles
   the plan with a minimal fallback and resolves routing to a degraded
   result, so the pipeline produces a playable fallback scene (graceful
   degradation) instead of hanging.

2. prompts/registry: the duplicate-segment-ID guard only ran under
   NODE_ENV=development, so a bad merge introducing a duplicate ID would
   silently shadow a segment in production. Run the check in all
   environments (once at module load; negligible cost).
2026-06-23 19:06:19 +08:00

44 lines
1.6 KiB
TypeScript

import type { PromptSegment } from "./types";
import { WRITER_IDENTITY } from "./segments/writer/identity";
import { WRITER_COT } from "./segments/writer/cot";
import { WRITER_BIBLE } from "./segments/writer/bible";
import { WRITER_STYLE_BASE } from "./segments/writer/style-base";
import { WRITER_SENSES_ENHANCE } from "./segments/writer/senses-enhance";
import { WRITER_BAIMIAO_ADVANCED } from "./segments/writer/baimiao-advanced";
import { WRITER_ALIVE_FEEL } from "./segments/writer/alive-feel";
import { WRITER_NARRATIVE_RULES } from "./segments/writer/narrative-rules";
import { WRITER_DIALOGUE } from "./segments/writer/dialogue";
import { WRITER_GUARDRAILS } from "./segments/writer/guardrails";
import { WRITER_PACING } from "./segments/writer/pacing";
import { WRITER_FORMAT } from "./segments/writer/format";
export const WRITER_SEGMENTS: PromptSegment[] = [
WRITER_IDENTITY,
WRITER_COT,
WRITER_BIBLE,
WRITER_STYLE_BASE,
WRITER_SENSES_ENHANCE,
WRITER_BAIMIAO_ADVANCED,
WRITER_ALIVE_FEEL,
WRITER_NARRATIVE_RULES,
WRITER_DIALOGUE,
WRITER_GUARDRAILS,
WRITER_PACING,
WRITER_FORMAT,
];
// Validate unique segment IDs in ALL environments (not just development).
// A duplicate ID — e.g. introduced by a bad merge — would otherwise silently
// shadow a segment in production. This runs once at module load; the cost is
// negligible. Throwing fast surfaces the misconfiguration at startup.
{
const ids = WRITER_SEGMENTS.map((s) => s.id);
const seen = new Set<string>();
for (const id of ids) {
if (seen.has(id)) {
throw new Error(`[PromptRegistry] Duplicate segment ID: "${id}"`);
}
seen.add(id);
}
}