fix(view): run stateless documents and clear Execution output
No-session view Run All now runs the document and renders stdout into Execution; Clear outputs clears Execution output, plots and plan cards as well as cell outputs.
This commit is contained in:
1 parent
bff2f53e52
commit
4757b82edd
4 files changed
+48
-1
No files matched your search
+1
-1
@@ -4,7 +4,7 @@
|
||||
|
||||
### Added
|
||||
|
||||
- **foreign 拥有视图会话**:新增 `foreign.session kernels= cells=`,返回 foreign 会话句柄;`view` 只消费 `会话` 绑定,不再识别 `内核表` / `会话表` 保留名。没有 `会话` 时,view cells 使用无状态一次性执行,不创建内核。清除输出已接通 `/api/session/clear`,普通 view 与 foreign cells 共用,并由 Execution 面板的 Clear 按钮清除页面输出;移除 `In []` / `Out []` 与 Notebook 品牌;没有新增 CLI 或第二个交互模式。
|
||||
- **foreign 拥有视图会话**:新增 `foreign.session kernels= cells=`,返回 foreign 会话句柄;`view` 只消费 `会话` 绑定,不再识别 `内核表` / `会话表` 保留名。没有 `会话` 时,view cells 使用无状态一次性执行,不创建内核。清除输出已接通 `/api/session/clear`,普通 view 与 foreign cells 共用,并由 Execution 面板的 Clear 按钮清除页面输出;无 `会话` 的 view 在 Run All 时执行整个文档并回写 Execution(不再空转);移除 `In []` / `Out []` 与 Notebook 品牌;没有新增 CLI 或第二个交互模式。
|
||||
|
||||
### Fixed
|
||||
|
||||
|
||||
@@ -3623,8 +3623,25 @@ body.notebook-page .stdin-form button {
|
||||
else status(r.error || "run failed");
|
||||
});
|
||||
}
|
||||
function renderDocumentResult(data) {
|
||||
var out = document.getElementById("exec-main");
|
||||
if (out) {
|
||||
out.hidden = false;
|
||||
out.classList.toggle("err", !data.ok);
|
||||
out.textContent = data.ok ? (data.stdout || "(no output)") : (data.error || "run failed");
|
||||
}
|
||||
var block = document.getElementById("exec-block");
|
||||
if (block) block.hidden = false;
|
||||
}
|
||||
function runAll(restart) {
|
||||
status(restart ? "restarting…" : "running all…");
|
||||
if (!state.persistent && Object.keys(state.cells).length === 0) {
|
||||
post("api/session/run_document", {}).then(function (r) {
|
||||
renderDocumentResult(r);
|
||||
status(r.ok ? "document run done" : (r.error || "document run failed"));
|
||||
}).catch(function (e) { status(String(e)); });
|
||||
return;
|
||||
}
|
||||
post("api/session/run_all", { restart: !!restart }).then(function (r) {
|
||||
if (!r.ok) { status(r.error || "run all failed"); return; }
|
||||
if (r.session) renderSummary(r.session);
|
||||
@@ -3687,6 +3704,10 @@ body.notebook-page .stdin-form button {
|
||||
bind("nb-run-all", function () { runAll(false); });
|
||||
bind("nb-restart", function () { runAll(true); });
|
||||
bind("nb-step", function () {
|
||||
if (!state.persistent && Object.keys(state.cells).length === 0) {
|
||||
status("no cells; Run All runs the document");
|
||||
return;
|
||||
}
|
||||
post("api/session/cell/step", {}).then(function (r) {
|
||||
if (!r.ok) { status(r.error || "step failed"); return; }
|
||||
if (r.record) {
|
||||
@@ -3707,6 +3728,7 @@ body.notebook-page .stdin-form button {
|
||||
pre.textContent = JSON.stringify(r.state || r, null, 2);
|
||||
if (actions) actions.hidden = false;
|
||||
if (ki && !ki.value && state.kernels.length) ki.value = state.kernels[0].name;
|
||||
if (!state.persistent) status("stateless: no kernel state");
|
||||
});
|
||||
});
|
||||
bind("nb-push", function () {
|
||||
@@ -3738,6 +3760,7 @@ body.notebook-page .stdin-form button {
|
||||
if (!pre) return;
|
||||
pre.hidden = false;
|
||||
pre.textContent = JSON.stringify(r.journal || r, null, 2);
|
||||
if (!state.persistent) status("stateless: journal is per one-shot run");
|
||||
});
|
||||
});
|
||||
bind("nb-debug", function () {
|
||||
|
||||
@@ -189,6 +189,11 @@ fn handle(root: &ViewRoot, request: Request) -> Result<()> {
|
||||
notebook_api::api_close(&root.root, body)
|
||||
})
|
||||
}
|
||||
"/api/session/run_document" => {
|
||||
return api_debug_post(request, |body| {
|
||||
notebook_api::api_run_document(&root.root, body)
|
||||
})
|
||||
}
|
||||
"/api/session/clear" => {
|
||||
return api_debug_post(request, |body| {
|
||||
notebook_api::api_clear(&root.root, body)
|
||||
|
||||
@@ -67,6 +67,25 @@ fn err(error: String) -> serde_json::Value {
|
||||
serde_json::json!({ "ok": false, "error": error })
|
||||
}
|
||||
|
||||
pub fn api_run_document(root: &Path, body: &str) -> serde_json::Value {
|
||||
let v = body_value(body);
|
||||
let (_rel, abs) = match path_of(root, &v) {
|
||||
Ok(p) => p,
|
||||
Err(e) => return err(e),
|
||||
};
|
||||
let mut opts = crate::RunOptions::default();
|
||||
opts.fs_root = Some(root.to_path_buf());
|
||||
opts.sleep_limit_ms = Some(30_000);
|
||||
match crate::run_file_capture(&abs, &opts) {
|
||||
Ok(cap) => serde_json::json!({
|
||||
"ok": true,
|
||||
"stdout": cap.stdout,
|
||||
"value": json_value(&cap.value),
|
||||
}),
|
||||
Err(e) => serde_json::json!({ "ok": false, "error": format!("{e:#}") }),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn api_open(root: &Path, body: &str) -> serde_json::Value {
|
||||
let v = body_value(body);
|
||||
let (_rel, abs) = match path_of(root, &v) {
|
||||
|
||||
Reference in new issue
Block a user