76 lines
2.4 KiB
TypeScript
76 lines
2.4 KiB
TypeScript
import type { AgentEventTriggerContext } from "@/features/agent";
|
|
import type { ScheduledConditionRecord } from "../types";
|
|
import type { PeripheralWorkOrder } from "./client";
|
|
|
|
export const WATER_QUALITY_SCENARIO_CODE = "WQ-SECONDARY-SUPPLY-001" as const;
|
|
|
|
export function toWaterQualityAgentTrigger(
|
|
workOrder: PeripheralWorkOrder
|
|
): AgentEventTriggerContext | null {
|
|
if (
|
|
workOrder.revision !== 1 ||
|
|
workOrder.status !== "open" ||
|
|
workOrder.work_order_type !== "water_quality_complaint" ||
|
|
workOrder.scenario_code !== WATER_QUALITY_SCENARIO_CODE
|
|
) {
|
|
return null;
|
|
}
|
|
|
|
return {
|
|
schema_version: "agent-trigger@1",
|
|
kind: "event",
|
|
trigger_id: [
|
|
"peripheral.work_order.created",
|
|
workOrder.project_id,
|
|
workOrder.work_order_id,
|
|
workOrder.revision
|
|
].join(":"),
|
|
occurred_at: workOrder.created_at,
|
|
source: "peripheral_sample",
|
|
subject_type: "work_order",
|
|
subject_id: workOrder.work_order_id,
|
|
workflow: "water_quality_complaint",
|
|
payload: {
|
|
title: workOrder.title,
|
|
summary: workOrder.summary,
|
|
location: workOrder.location,
|
|
priority: workOrder.priority,
|
|
scenario_code: WATER_QUALITY_SCENARIO_CODE,
|
|
origin: "synthetic"
|
|
}
|
|
};
|
|
}
|
|
|
|
export function waterQualityTriggerPrompt(workOrder: PeripheralWorkOrder) {
|
|
return `外围样板新增水质投诉工单:${workOrder.title}。请启动水质事件调查。`;
|
|
}
|
|
|
|
export function toWaterQualityConditionTask(
|
|
workOrder: PeripheralWorkOrder,
|
|
sessionId: string,
|
|
now = new Date()
|
|
): ScheduledConditionRecord {
|
|
return {
|
|
id: `peripheral-water-quality-${workOrder.work_order_id}`,
|
|
kind: "condition",
|
|
taskId: "water-quality-complaint",
|
|
dataSource: "mock",
|
|
sessionId,
|
|
title: "水质投诉调查",
|
|
summary: workOrder.summary,
|
|
status: "running",
|
|
riskLevel: workOrder.priority === "urgent" ? "critical" : "attention",
|
|
scheduledAt: now.toISOString(),
|
|
updatedAt: now.getTime(),
|
|
durationMinutes: 15,
|
|
detail: `${workOrder.location ?? "位置待确认"} · 由外围工单事件触发`,
|
|
recommendation: "优先校验上游监测点数据质量;若上游指标正常,再转向二次供水设施和运维记录核查。",
|
|
evidence: [
|
|
`来源工单:${workOrder.work_order_id}`,
|
|
`投诉位置:${workOrder.location ?? "待确认"}`,
|
|
`投诉内容:${workOrder.title}`
|
|
],
|
|
modelName: "TJWater Agent 事件任务"
|
|
};
|
|
}
|