import type { DecisionRow } from "@umt/db"; import type { ServerContext } from "./types.ts"; // 待处理"处理"端点(sources-identity routes/decisions.ts)的执行钩子:其它模块按 dedupe_key 认领自己的事项, // 在事项关闭前同步执行所选处理(失败抛错 → 事项保持打开,错误回给用户)。按 ctx 隔离(测试里多个装配互不影响)。 export interface DecisionResolveBody { optionKey?: string | undefined; dismiss?: boolean | undefined; note?: string | undefined; identity?: | { mediaEntityId?: string | undefined; tmdb?: { type: "movie" | "tv"; id: string } | undefined } | undefined; } export interface DecisionHookActor { type: string; id: string | null; } export interface DecisionHook { /** 认领该事项(通常按 dedupe_key 前缀) */ match(d: DecisionRow): boolean; /** 执行所选处理;返回写进 resolution.execution 的摘要 */ execute(d: DecisionRow, body: DecisionResolveBody, actor: DecisionHookActor): Promise>; } const hooks = new WeakMap(); export function registerDecisionHook(ctx: ServerContext, hook: DecisionHook): void { const list = hooks.get(ctx) ?? []; list.push(hook); hooks.set(ctx, list); } export function decisionHookFor(ctx: ServerContext, d: DecisionRow): DecisionHook | undefined { return hooks.get(ctx)?.find((h) => h.match(d)); }