/* * SPEC: PJ2026-010103 HWPOD 服务。 * 实现引用: draft-2026-07-20-hwpod-temporal-split。 * 责任: 独立 HWPOD API、worker 和 Web 共用的稳定输入输出合同。 */ export type HwpodOperationInput = { operationId: string; plan: Record; runtimeApiUrl: string; authorization?: string; }; export type HwpodOperationResult = { ok: boolean; status: string; operationId: string; workflowId: string; workflowRunId: string | null; result?: Record | null; error?: { code: string; message: string } | null; }; export function validateHwpodOperationInput(value: unknown): HwpodOperationInput { if (!value || typeof value !== "object" || Array.isArray(value)) throw codedError("hwpod_operation_input_invalid", "HWPOD operation input must be an object"); const input = value as Record; const operationId = text(input.operationId); const runtimeApiUrl = text(input.runtimeApiUrl); const plan = input.plan; if (!operationId) throw codedError("hwpod_operation_id_required", "operationId is required"); if (!runtimeApiUrl) throw codedError("hwpod_runtime_api_url_required", "runtimeApiUrl is required"); if (!plan || typeof plan !== "object" || Array.isArray(plan)) throw codedError("hwpod_operation_plan_required", "plan must be an object"); return { operationId, runtimeApiUrl: runtimeApiUrl.replace(/\/+$/u, ""), plan: plan as Record, authorization: text(input.authorization) || undefined }; } function text(value: unknown) { return typeof value === "string" ? value.trim() : ""; } function codedError(code: string, message: string) { return Object.assign(new Error(message), { code }); }