接续L4-TOOL-DB浏览器Provider协议
结论:浏览器 Worker 已支持可插拔 Python runtime provider 的 line I/O,缺真实 Python/WASM runtime 时仍保持阻塞不解锁。
This commit is contained in:
@@ -577,7 +577,9 @@ private module paths:
|
||||
boundary. The bundled worker reports
|
||||
`blocked_browser_python_wasm_runtime_missing` until a real Python/WASM runtime
|
||||
is installed; the Worker shell alone must not mark `DB_PROGRAM` execution
|
||||
ready.
|
||||
ready. The Worker supports a provider protocol (`start`, `writeLine`,
|
||||
`readLine`, `close`) so a future Python/WASM runtime can provide line-based
|
||||
`DB_PROGRAM` I/O without changing `ToolDbProcessPort`.
|
||||
- `createLinuxCncToolDbNodeRuntimeAdapter()` in
|
||||
`runtime/sdk/src/tool-db-node-runtime-adapter.js` for Node/native verification
|
||||
of the real LinuxCNC `DB_PROGRAM` child process. This adapter is intentionally
|
||||
|
||||
@@ -96,7 +96,14 @@ export function createLinuxCncToolDbBrowserWorkerAdapter({
|
||||
return result.line;
|
||||
},
|
||||
|
||||
close() {
|
||||
async close() {
|
||||
if (worker) {
|
||||
try {
|
||||
await request("close");
|
||||
} catch {
|
||||
// The worker may be blocked or already gone; termination below is authoritative.
|
||||
}
|
||||
}
|
||||
rejectPending(new Error("Tool DB browser worker closed."));
|
||||
worker?.terminate();
|
||||
worker = null;
|
||||
|
||||
@@ -15,12 +15,21 @@ function pythonRuntimeAvailable() {
|
||||
return typeof self.loadPyodide === "function" || Boolean(self.pyodide?.runPythonAsync);
|
||||
}
|
||||
|
||||
function getRuntimeProvider() {
|
||||
return self.linuxCncToolDbPythonRuntimeProvider ?? null;
|
||||
}
|
||||
|
||||
self.addEventListener("message", async (event) => {
|
||||
const message = event.data ?? {};
|
||||
const { id, type } = message;
|
||||
const { id, type, line } = message;
|
||||
try {
|
||||
if (type === "start") {
|
||||
const ready = pythonRuntimeAvailable();
|
||||
const provider = getRuntimeProvider();
|
||||
const providerReady = Boolean(provider?.start && provider?.writeLine && provider?.readLine);
|
||||
const ready = providerReady || pythonRuntimeAvailable();
|
||||
if (providerReady) {
|
||||
await provider.start(message);
|
||||
}
|
||||
postReply(id, type, {
|
||||
runtimeMode: "browser-python-wasm-worker",
|
||||
runtimeExecutionReady: ready,
|
||||
@@ -32,6 +41,25 @@ self.addEventListener("message", async (event) => {
|
||||
});
|
||||
return;
|
||||
}
|
||||
const provider = getRuntimeProvider();
|
||||
if (type === "writeLine" && provider?.writeLine) {
|
||||
await provider.writeLine(line);
|
||||
postReply(id, type, { executionEnabled: false, promotionAllowed: false });
|
||||
return;
|
||||
}
|
||||
if (type === "readLine" && provider?.readLine) {
|
||||
postReply(id, type, {
|
||||
line: await provider.readLine(),
|
||||
executionEnabled: false,
|
||||
promotionAllowed: false,
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (type === "close" && provider?.close) {
|
||||
await provider.close();
|
||||
postReply(id, type, { executionEnabled: false, promotionAllowed: false });
|
||||
return;
|
||||
}
|
||||
throw new Error("blocked_browser_python_wasm_runtime_missing");
|
||||
} catch (error) {
|
||||
postError(id, type, error);
|
||||
|
||||
Reference in New Issue
Block a user