feat(tuning): release V0.8.2 Agent 界面重构
This commit is contained in:
@@ -129,18 +129,44 @@ export function LocalTrainingPanel({ onPolicyReady }: { onPolicyReady(file: File
|
||||
typeof event.data !== 'object'
|
||||
)
|
||||
return;
|
||||
const data = event.data as { type?: string; sessionId?: string };
|
||||
const data = event.data as { type?: string; sessionId?: string; policy?: unknown };
|
||||
const source = event.source as Window;
|
||||
if (data.type === 'mujoco-tuning-ready') {
|
||||
(event.source as Window).postMessage(
|
||||
{ type: 'mujoco-tuning-credentials', endpoint, token },
|
||||
event.origin,
|
||||
);
|
||||
source.postMessage({ type: 'mujoco-tuning-credentials', endpoint, token }, event.origin);
|
||||
}
|
||||
if (data.type === 'mujoco-tuning-import-policy' && data.sessionId) {
|
||||
void new LocalTrainingClient(endpoint, token)
|
||||
.downloadBestPolicy(data.sessionId)
|
||||
.then(onPolicyReady)
|
||||
.catch((value: unknown) => setError(errorText(value)));
|
||||
const reply = (ok: boolean, message?: string) => {
|
||||
try {
|
||||
source.postMessage(
|
||||
{
|
||||
type: 'mujoco-tuning-import-policy-result',
|
||||
sessionId: data.sessionId,
|
||||
ok,
|
||||
error: message,
|
||||
},
|
||||
event.origin,
|
||||
);
|
||||
} catch {
|
||||
/* 调参窗口可能已关闭;不影响主工作台继续导入 */
|
||||
}
|
||||
};
|
||||
void (async () => {
|
||||
try {
|
||||
const policy =
|
||||
data.policy === undefined
|
||||
? await new LocalTrainingClient(endpoint, token).downloadBestPolicy(data.sessionId!)
|
||||
: data.policy;
|
||||
if (!(policy instanceof File) || !/\.onnx$/i.test(policy.name))
|
||||
throw new Error('调参工作台返回的 ONNX 策略无效');
|
||||
if (policy.size > 64 * 1024 * 1024) throw new Error('ONNX 策略不能超过 64 MiB');
|
||||
onPolicyReady(policy);
|
||||
reply(true);
|
||||
} catch (value) {
|
||||
const message = errorText(value);
|
||||
setError(message);
|
||||
reply(false, message);
|
||||
}
|
||||
})();
|
||||
}
|
||||
};
|
||||
window.addEventListener('message', receive);
|
||||
|
||||
Reference in New Issue
Block a user