From c028d2ad00ad7ba3e9b6f71f01037fe8bdb1cbcb Mon Sep 17 00:00:00 2001 From: 134 Date: Mon, 27 Jul 2026 20:54:33 +0800 Subject: [PATCH] fix: normalize HiCAD engine responses --- .../HicadManufacturingPanel.tsx.template | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/vendor/zoo-modeling-app/HicadManufacturingPanel.tsx.template b/vendor/zoo-modeling-app/HicadManufacturingPanel.tsx.template index 600036f22..993a4365d 100644 --- a/vendor/zoo-modeling-app/HicadManufacturingPanel.tsx.template +++ b/vendor/zoo-modeling-app/HicadManufacturingPanel.tsx.template @@ -84,10 +84,11 @@ function resolveBodyName( } function modelingResponseData(response: unknown): ModelingResponse { - if (!isModelingResponse(response)) { + const normalized = Array.isArray(response) ? response[0] : response + if (!isModelingResponse(normalized)) { throw new Error('HiCAD 引擎未返回有效结果') } - return response.resp.data.modeling_response as ModelingResponse + return normalized.resp.data.modeling_response as ModelingResponse } function numberValue(data: unknown, key: string) { @@ -160,12 +161,27 @@ export function HicadManufacturingPanel({ } const sendModelingCommand = async (cmd: ModelingCmd) => { - const response = await kclManager.engineCommandManager.sendSceneCommand({ - type: 'modeling_cmd_req', - cmd_id: uuidv4(), - cmd, - }) - return modelingResponseData(response) + const maxAttempts = 15 + + for (let attempt = 0; attempt < maxAttempts; attempt += 1) { + const response = await kclManager.engineCommandManager.sendSceneCommand({ + type: 'modeling_cmd_req', + cmd_id: uuidv4(), + cmd, + }) + const normalized = Array.isArray(response) ? response[0] : response + + if (isModelingResponse(normalized)) { + return modelingResponseData(normalized) + } + if (response !== null && response !== undefined) { + return modelingResponseData(response) + } + + await new Promise((resolve) => setTimeout(resolve, 200)) + } + + throw new Error('HiCAD 引擎连接尚未就绪,请稍后重新分析') } const captureSnapshot = async () => {