feat: improve mode and peripheral orchestration

This commit is contained in:
Miayui
2026-09-21 00:13:47 +08:00
parent 89707a42e2
commit 448c8b31a0
39 changed files with 3068 additions and 277 deletions
+51 -6
View File
@@ -548,6 +548,7 @@
"door.set_rear_lock": "后排门锁",
"door.set_vehicle_lock": "整车门锁",
"infrared.emit": "红外外设",
"android.launch_app": "打开视频媒体",
};
function assistantControlCategory(operation = {}, fallback = "控制指令") {
@@ -745,6 +746,22 @@
const brightness = numericValue(parameters.brightness_level);
if (brightness !== null) return `${brightness}级`;
const level = numericValue(parameters.level ?? parameters.fan_level);
const capability = String(item.operation?.capability || "");
if (capability === "android.launch_app") {
const packageName = String(parameters.package_name || "").trim();
const activityName = String(parameters.activity_name || "").trim();
return [
packageName ? `应用 ${packageName}` : "视频应用",
activityName ? `页面 ${activityName}` : "",
].filter(Boolean).join(" · ");
}
if (
level !== null
&& ["seat.set_driver_ventilation_native", "seat.set_driver_heating_native"]
.includes(capability)
) {
return ({ 1: "3档", 2: "1档" })[level] || "档位待确认";
}
if (level !== null) return `${level}档`;
const state = parameters.motion
?? parameters.state
@@ -769,6 +786,7 @@
if (capability.startsWith("seat.") || category.includes("座椅")) return "armchair";
if (capability.startsWith("door.") || category.includes("门锁")) return "lock-keyhole";
if (capability === "infrared.emit") return "radio-tower";
if (capability === "android.launch_app") return "clapperboard";
return "binary";
}
@@ -985,6 +1003,7 @@
"ambient_light.set_power": "氛围灯",
"ambient_light.set_mode": "氛围灯模式",
"infrared.emit": "红外外设",
"android.launch_app": "打开视频媒体",
};
const zeroGravityIndexes = actions
@@ -1166,9 +1185,10 @@
? `${params.position_pct}%${params.angle_deg != null ? `(${params.angle_deg}°)` : ""}`
: motionLabel(params.state || params.mode_id);
if (["seat.set_driver_ventilation_native", "seat.set_driver_heating_native"].includes(capability)) {
// CH1 driver controls encode high as 1 and low as 2; passenger
// comfort levels use a different scale and must not reuse this map.
const level = { 1: "高档", 2: "低档" }[params.level ?? 2] || "档位待确认";
// CH1 encodes high as 1 and low as 2 internally. Present the
// occupant-facing three-speed scale instead of leaking CAN enums.
const level = { 1: "3档(高)", 2: "1档(低)" }[params.level ?? 2]
|| "档位待确认";
value = params.state === "off" ? "关闭"
: params.state === "on" ? `开启 · ${level}` : "开关状态待确认";
} else if (["seat.set_ventilation", "seat.set_heating"].includes(capability)) {
@@ -1529,10 +1549,23 @@
return /(?:构建|创建|新建|新增|生成|添加)(?:一下)?(?:一个|个|一套|套)?[^,。!?!?]{1,64}?模式/.test(compact);
}
function validatedHardwareClientId() {
const sharedClientId = window.CognitiveAgentConsole?.getHardwareClientId?.();
let storedClientId = null;
try {
storedClientId = localStorage.getItem("cognitive-agent.hardware-client-id");
} catch (_error) {
// The shared console identity remains authoritative when storage is unavailable.
}
return [sharedClientId, storedClientId]
.map((value) => String(value || "").trim())
.find((value) => /^hwc-[a-z0-9-]{8,80}$/.test(value)) || null;
}
function requestBody(message) {
const configuredExecutionMode = window.CognitiveAgentConsole?.getExecutionMode?.() || "dry_run";
const controlTransport = localStorage.getItem("cognitive-agent.control-transport") || "wired_can";
const hardwareClientId = localStorage.getItem("cognitive-agent.hardware-client-id");
const hardwareClientId = validatedHardwareClientId();
const vehicleId = $("#vehicleSelect")?.value || null;
const modeProfileDraftContext = requestModeDraftContext(message);
const modeConfigurationPreview = Boolean(modeProfileDraftContext)
@@ -1967,6 +2000,11 @@
&& result?.schedule_execution?.status === "running";
const dryRun = result?.execution_mode === "dry_run";
const waitingForFeedback = result?.execution_outcome === "submitted_unverified";
const delegatedCount = Array.isArray(result?.deferred_requests)
? result.deferred_requests.filter(
(item) => item?.execution_backend === "n7_vehicle_transfer",
).length
: 0;
let content = `${modeName}执行未完成,请查看控制指令状态。`;
let statusText = "功能模式执行未完成";
@@ -1991,8 +2029,15 @@
: "功能模式执行已完成";
statusState = "success";
} else if (status === "partially_succeeded") {
content = `${modeName}仅部分完成,请查看未完成的控制指令。`;
statusText = "功能模式部分完成";
content = delegatedCount > 0
? `${modeName}指令已提交,未由 PC 执行的 ${delegatedCount} 项动作将由车机继续处理。`
: waitingForFeedback
? `${modeName}指令已提交,正在等待车辆状态确认。`
: `${modeName}执行结果已更新,请查看各控制指令状态。`;
statusText = waitingForFeedback || delegatedCount > 0
? "功能模式指令已提交"
: "功能模式执行结果已更新";
statusState = waitingForFeedback || delegatedCount > 0 ? "working" : "success";
}
setMessageContent(message, content, { final: true });