import type { WorkflowTask } from "../types.js"; import { resolvePiperBaseUrl } from "../../../../core/http/piper-endpoints.js"; /** 复制的工作流需要独立的 Webhook 地址和样本。 */ export function resetCopiedWebhookTrigger(task?: WorkflowTask): void { if (task?.type !== "webhook") return; task.urlPath = crypto.randomUUID(); delete task.sampleId; } export function ensureWebhookTriggerPath(task: WorkflowTask): void { if (task.type === "webhook" && !task.urlPath) task.urlPath = crypto.randomUUID(); } export function webhookTriggerUrl(task: WorkflowTask): string | undefined { const rawPath = [task.urlPath, task.url, task.path].find((value) => typeof value === "string" && value); if (typeof rawPath !== "string") return undefined; return rawPath.startsWith("http") ? rawPath : `${resolvePiperBaseUrl()}/api/webhook/${rawPath.replace(/^\/+/, "")}`; }