feat(n7web): enhance control workflows and status feedback

This commit is contained in:
Miayui
2026-09-16 12:52:07 +08:00
parent 84a3cd73bb
commit 0e4328f548
45 changed files with 7317 additions and 1001 deletions
+100 -5
View File
@@ -544,7 +544,27 @@
if (capability.startsWith("seat.")) {
const target = String(operation.target?.zone || operation.target?.instance || "")
.replaceAll("_", "-");
return `${["passenger", "front-right"].includes(target) ? "副驾" : "主驾"}座椅`;
const seat = ["passenger", "front-right"].includes(target) ? "副驾座椅" : "主驾座椅";
const component = {
"seat.set_longitudinal_position": "前后位置",
"seat.set_cushion_tilt": "坐盆",
"seat.set_backrest_recline": "靠背",
"seat.set_legrest_height": "腿托",
"seat.set_legrest_extension": "腿托",
}[capability];
if (component) return `${seat}${component}`;
if (capability === "seat.set_driver_axis_native") {
const axis = String(operation.parameters?.axis || "").replaceAll("_", "-");
const axisComponent = {
horizontal: "前后位置",
height: "坐盆",
basin: "坐盆",
backrest: "靠背",
legrest: "腿托",
}[axis];
if (axisComponent) return `${seat}${axisComponent}`;
}
return seat;
}
if (capability.startsWith("outlet.")) return "空调风口";
return String(fallback || capability || "控制指令");
@@ -589,6 +609,24 @@
String(presentation?.operation?.id || ""),
presentation?.operation || {},
]));
const operationByRef = new Map();
const configurations = result.function_configs && typeof result.function_configs === "object"
? Object.values(result.function_configs)
: [];
if (result.function_config && typeof result.function_config === "object") {
configurations.push(result.function_config);
}
configurations.forEach((configuration) => {
const operations = Array.isArray(configuration?.spec?.operations)
? configuration.spec.operations
: [];
operations.forEach((operation) => {
const operationRef = String(operation?.id || "");
if (operationRef && !operationByRef.has(operationRef)) {
operationByRef.set(operationRef, operation);
}
});
});
let commands = [];
try {
const sharedCommands = window.CognitiveAgentConsoleV2?.getParsedCanCommands?.(result);
@@ -599,10 +637,19 @@
if (!commands.length) return fallbackAssistantControlCommands(result);
return commands.map((item, index) => {
const operation = projectionByRef.get(String(item.operationRef || ""))
|| operationByRef.get(String(item.operationRef || ""))
|| projections[index]?.operation
|| {};
const pendingDelivery = result.status === "processing"
? {
deliveryState: "submitting",
deliveryLabel: "正在下发",
deliveryDetail: "",
}
: {};
return {
...item,
...pendingDelivery,
category: assistantControlCategory(operation, item.category),
operation,
};
@@ -1459,14 +1506,54 @@
}
}
function announceModeExecution(profile, result = null, { command = "", error = null } = {}) {
function modeExecutionPreviewResult(profile) {
const flow = profile?.command_flow && typeof profile.command_flow === "object"
? profile.command_flow
: {};
return {
status: "processing",
function_configs: flow.function_configs && typeof flow.function_configs === "object"
? flow.function_configs
: {},
command_plans: flow.plans && typeof flow.plans === "object" ? flow.plans : {},
control_transport: String(flow.control_transport || ""),
execution_report: null,
operation_results: [],
};
}
function beginModeExecution(profile, { command = "" } = {}) {
const modeName = String(profile?.name || profile?.id || "功能模式");
const commandText = String(command || `进入${modeName}`).trim();
setDrawerOpen(true);
createMessage("user", commandText);
const message = createMessage("assistant", `已加载${modeName}控制指令流,正在下发。`);
setActionStatus(message, "模式控制指令正在下发", "working");
appendDispatchedControls(message, modeExecutionPreviewResult(profile));
persistMessages();
return {
message,
modeName,
commandText,
profileId: String(profile?.id || ""),
};
}
function completeModeExecution(
handle,
profile,
result = null,
{ command = "", error = null } = {},
) {
const modeName = String(handle?.modeName || profile?.name || profile?.id || "功能模式");
const commandText = String(handle?.commandText || command || `进入${modeName}`).trim();
const activeHandle = handle?.message?.body
? handle
: beginModeExecution(profile, { command: commandText });
const message = activeHandle.message;
const status = String(result?.status || "");
const dryRun = result?.execution_mode === "dry_run";
const waitingForFeedback = result?.execution_outcome === "submitted_unverified";
setDrawerOpen(true);
createMessage("user", commandText);
let content = `${modeName}执行未完成,请查看控制指令状态。`;
let statusText = "功能模式执行未完成";
@@ -1491,10 +1578,16 @@
statusText = "功能模式部分完成";
}
const message = createMessage("assistant", content);
setMessageContent(message, content, { final: true });
setActionStatus(message, statusText, statusState);
if (result) appendDispatchedControls(message, result);
persistMessages();
return activeHandle;
}
function announceModeExecution(profile, result = null, { command = "", error = null } = {}) {
const handle = beginModeExecution(profile, { command });
return completeModeExecution(handle, profile, result, { command, error });
}
function renderInitialMessages() {
@@ -1584,6 +1677,8 @@
close: () => setDrawerOpen(false),
resetConversation,
startModeCreation,
beginModeExecution,
completeModeExecution,
announceModeExecution,
announceModeCreated(profile) {
if (!profile?.id) return;