Anchor AI runs to Hose flow via exact nodeId with 60s queue delay fallback
This commit is contained in:
1 parent
8264865aec
commit
cfc6ff3b88
2 files changed
+40
-10
No files matched your search
+39
-10
@@ -189,8 +189,16 @@ export function parseHoseTimeline(
|
||||
.map(extractFlowPerson)
|
||||
.filter((p): p is FlowPerson => Boolean(p));
|
||||
|
||||
const nodeId =
|
||||
typeof attributes.nodeId === "string" && attributes.nodeId
|
||||
? attributes.nodeId
|
||||
: typeof log.nodeId === "string" && log.nodeId
|
||||
? log.nodeId
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
id: typeof log.id === "string" ? log.id : undefined,
|
||||
nodeId,
|
||||
time: currentTime,
|
||||
durationMs,
|
||||
state,
|
||||
@@ -964,6 +972,32 @@ export function alignApprovalRunsWithHoseFlow(
|
||||
const run = sortedRuns[i];
|
||||
if (!run) continue;
|
||||
const runTime = Number(run.createdAt) || 0;
|
||||
|
||||
const doc = (run.document as Record<string, unknown> | undefined) || {};
|
||||
const mar =
|
||||
((run as Record<string, unknown>).manualApprovalRecord as Record<string, unknown> | undefined) ||
|
||||
((run.result as Record<string, unknown> | undefined)?.manualApprovalRecord as Record<string, unknown> | undefined) ||
|
||||
((doc as Record<string, unknown>).manualApprovalRecord as Record<string, unknown> | undefined) ||
|
||||
{};
|
||||
|
||||
// 1. 强特征 Node ID 锚定:优先从 sourceExtendData.nodeId 或 manualApprovalRecord.nodeId 反查合思真实节点
|
||||
const sourceNodeId =
|
||||
typeof (run.sourceExtendData as Record<string, unknown> | undefined)?.nodeId === "string"
|
||||
? String((run.sourceExtendData as Record<string, unknown>).nodeId)
|
||||
: undefined;
|
||||
const rawMarNodeId = typeof mar.nodeId === "string" ? String(mar.nodeId) : undefined;
|
||||
const decodedMarNodeId = rawMarNodeId
|
||||
? decodeURIComponent(rawMarNodeId).replace(/^hcnode_/, "").replace(/_r\d+$/, "")
|
||||
: undefined;
|
||||
const targetNodeId = sourceNodeId || decodedMarNodeId;
|
||||
|
||||
const matchedNodeEvent = targetNodeId
|
||||
? history.find((e) => e.nodeId && (e.nodeId === targetNodeId || targetNodeId.includes(e.nodeId)))
|
||||
: undefined;
|
||||
|
||||
// 锚定基准时间:优先采用合思对应节点的真实执行时刻;若无对应节点,放宽多系统排队容差至 60 秒
|
||||
const effectiveRunTime = matchedNodeEvent?.time ?? runTime;
|
||||
|
||||
const nextRun = sortedRuns[i + 1];
|
||||
let nextRunTime = nextRun ? Number(nextRun.createdAt) || Infinity : Infinity;
|
||||
let isLatestRun = i === sortedRuns.length - 1;
|
||||
@@ -974,7 +1008,7 @@ export function alignApprovalRunsWithHoseFlow(
|
||||
// 则直接证明当前 Run 已被后续更新的 AI 轮次所替代,绝非最新终态轮次!
|
||||
const subsequentEbot = history.find(
|
||||
(e) =>
|
||||
(e.time ?? 0) > runTime + 5000 &&
|
||||
(e.time ?? 0) > effectiveRunTime + 5000 &&
|
||||
e.isEbot &&
|
||||
(e.rawAction === "freeflow.agree" || e.action === "智能审批" || e.nodeName?.includes("智能"))
|
||||
);
|
||||
@@ -1010,12 +1044,6 @@ export function alignApprovalRunsWithHoseFlow(
|
||||
else if (isReject) aiAction = isAutomatic ? "驳回" : "添加评论";
|
||||
else if (normDecision === "REVIEW" || normDecision === "转交复核") aiAction = "转交复核";
|
||||
|
||||
const doc = (run.document as Record<string, unknown> | undefined) || {};
|
||||
const mar =
|
||||
((run as Record<string, unknown>).manualApprovalRecord as Record<string, unknown> | undefined) ||
|
||||
(res.manualApprovalRecord as Record<string, unknown> | undefined) ||
|
||||
((doc as Record<string, unknown>).manualApprovalRecord as Record<string, unknown> | undefined) ||
|
||||
{};
|
||||
const marStatus =
|
||||
typeof mar.status === "object" && mar.status !== null
|
||||
? String((mar.status as Record<string, unknown>).type || (mar.status as Record<string, unknown>).label || "").toUpperCase()
|
||||
@@ -1060,10 +1088,11 @@ export function alignApprovalRunsWithHoseFlow(
|
||||
marStatus === "已驳回" ||
|
||||
marStatus === "被驳回");
|
||||
|
||||
// 5-second clock skew tolerance window [runTime - 5000, nextRunTime)
|
||||
// 容差窗口:若已通过 nodeId 准确锚定,前后仅需 1 秒同步边沿;若未锚定,提供 60 秒跨系统排队与处理缓冲
|
||||
const skewToleranceMs = matchedNodeEvent ? 1000 : 60000;
|
||||
const windowEvents = history.filter((e) => {
|
||||
const t = e.time ?? 0;
|
||||
return t >= runTime - 5000 && t < nextRunTime;
|
||||
return t >= effectiveRunTime - skewToleranceMs && t < nextRunTime;
|
||||
});
|
||||
|
||||
let eHumanAction = "-";
|
||||
@@ -1074,7 +1103,7 @@ export function alignApprovalRunsWithHoseFlow(
|
||||
|
||||
// Check for Post-AI Mutation / Audit Drift
|
||||
const isAiApproved = isApprove || isExemptApprove;
|
||||
const postAiEvents = history.filter((e) => (e.time ?? 0) > runTime + 5000);
|
||||
const postAiEvents = history.filter((e) => (e.time ?? 0) > effectiveRunTime + 5000);
|
||||
const hasPostAiRetract = postAiEvents.some(
|
||||
(e) => e.rawAction === "freeflow.retract" || e.action === "单据撤回"
|
||||
);
|
||||
|
||||
@@ -42,6 +42,7 @@ export type FlowPerson = z.infer<typeof FlowPersonSchema>;
|
||||
|
||||
export const HoseFlowTimelineEntrySchema = z.object({
|
||||
id: z.string().optional(),
|
||||
nodeId: z.string().optional(),
|
||||
time: z.number().optional(),
|
||||
durationMs: z.number().optional(),
|
||||
state: z.string().optional(),
|
||||
|
||||
Reference in new issue
Block a user