feat: integrate safer vehicle CAN reasoning
This commit is contained in:
@@ -36,6 +36,7 @@ function loadHardwareClientId() {
|
||||
|
||||
const state = {
|
||||
provider: "openai",
|
||||
reasoningEffort: localStorage.getItem("cognitive-agent.reasoning-effort") || "medium",
|
||||
executionMode: "dry_run",
|
||||
conversationId: loadConversationId(),
|
||||
vehicleId: null,
|
||||
@@ -3929,6 +3930,35 @@ function openModeGallery() {
|
||||
backdrop.classList.add("open");
|
||||
$("#modeGalleryClose").focus();
|
||||
});
|
||||
syncReasoningControls();
|
||||
}
|
||||
|
||||
function availableReasoningEfforts() {
|
||||
const configured = state.runtime?.openai_reasoning_efforts;
|
||||
return Array.isArray(configured) && configured.length ? configured : ["low", "medium", "high"];
|
||||
}
|
||||
|
||||
function selectReasoningEffort(effort, { persist = true } = {}) {
|
||||
if (!availableReasoningEfforts().includes(effort)) return false;
|
||||
state.reasoningEffort = effort;
|
||||
if (persist) localStorage.setItem("cognitive-agent.reasoning-effort", effort);
|
||||
syncReasoningControls();
|
||||
return true;
|
||||
}
|
||||
|
||||
function syncReasoningControls() {
|
||||
const enabled = state.provider === "openai" && state.runtime?.openai_available === true;
|
||||
const descriptions = {
|
||||
low: "极速模式优先降低指令解析延迟",
|
||||
medium: "均衡模式兼顾自然语言解析精度与响应速度",
|
||||
high: "深度模式适合多设备、相对动作与复杂约束指令",
|
||||
};
|
||||
$$('[data-reasoning-effort]').forEach((button) => {
|
||||
button.disabled = !enabled || !availableReasoningEfforts().includes(button.dataset.reasoningEffort);
|
||||
button.classList.toggle("active", button.dataset.reasoningEffort === state.reasoningEffort);
|
||||
});
|
||||
const note = $("#reasoningNote");
|
||||
if (note) note.textContent = enabled ? descriptions[state.reasoningEffort] : "本地规则解析不调用模型推理";
|
||||
}
|
||||
|
||||
function closeModeGallery({ restoreFocus = true } = {}) {
|
||||
@@ -4292,6 +4322,10 @@ async function loadRuntime() {
|
||||
applyRuntimeTargetPolicy(state.runtime);
|
||||
populateVehicleSelector();
|
||||
populateModeChips();
|
||||
const configuredEffort = state.runtime.openai_reasoning_effort_default || "medium";
|
||||
if (!availableReasoningEfforts().includes(state.reasoningEffort)) {
|
||||
state.reasoningEffort = configuredEffort;
|
||||
}
|
||||
const hardware = state.runtime.hardware || {};
|
||||
const vehicleCan = state.runtime.vehicle_can || {};
|
||||
const linkedHardwareReady = Boolean(hardware.configured && vehicleCan.configured);
|
||||
@@ -4315,6 +4349,7 @@ async function loadRuntime() {
|
||||
$("#providerNote").textContent = "未设置 OPENAI_API_KEY,已切换为本地规则解析";
|
||||
selectProvider("local");
|
||||
}
|
||||
syncReasoningControls();
|
||||
$("#matrixCount").textContent = `${state.runtime.matrix.messages} / ${state.runtime.matrix.signals}`;
|
||||
const hardwareButton = $("#hardwareMode");
|
||||
hardwareButton.disabled = !hardwareExecutionReady;
|
||||
@@ -5575,6 +5610,9 @@ function renderResult(result) {
|
||||
const conversationLabel = result.conversation_id?.slice(-8) || "no-context";
|
||||
$("#requestMeta").textContent = `${result.request_id} / context:${conversationLabel} / turn:${result.conversation_turn} / ${result.provider_used || result.provider_requested}`;
|
||||
$("#requestMeta").textContent += ` / ${result.execution_report?.spec?.mode || result.execution_mode || "dry_run"}`;
|
||||
if (result.reasoning_effort_used) {
|
||||
$("#requestMeta").textContent += ` / reasoning:${result.reasoning_effort_used}`;
|
||||
}
|
||||
setRunStatus(
|
||||
partiallySucceeded ? "partial" : executionSucceeded ? "succeeded" : "failed",
|
||||
result.status.toUpperCase(),
|
||||
@@ -5647,6 +5685,7 @@ async function submitRequest(event) {
|
||||
conversation_id: state.conversationId,
|
||||
vehicle_id: state.vehicleId || state.runtime?.default_vehicle_id,
|
||||
execution_mode: state.executionMode,
|
||||
...(state.provider === "openai" ? { reasoning_effort: state.reasoningEffort } : {}),
|
||||
...(state.executionMode === "hardware" && !driverOnlyCh1
|
||||
? { hardware_client_id: state.hardwareClientId }
|
||||
: {}),
|
||||
@@ -5892,6 +5931,7 @@ document.addEventListener("DOMContentLoaded", async () => {
|
||||
}
|
||||
});
|
||||
$$(".segment[data-provider]").forEach((button) => button.addEventListener("click", () => selectProvider(button.dataset.provider)));
|
||||
$$('[data-reasoning-effort]').forEach((button) => button.addEventListener("click", () => selectReasoningEffort(button.dataset.reasoningEffort)));
|
||||
$$('[data-execution-mode]').forEach((button) => button.addEventListener("click", () => selectExecutionMode(button.dataset.executionMode)));
|
||||
$$(".example-command").forEach((button) => button.addEventListener("click", () => {
|
||||
$("#utterance").value = button.dataset.example;
|
||||
|
||||
Reference in New Issue
Block a user