feat(foreign): own view sessions and clear outputs

foreign.session returns a handle from ordinary kernel/cell tables; view consumes only the 会话 binding. Sessions live in host foreign_doc. Without 会话, view cells run stateless one-shot. Add /api/session/clear and a Clear outputs button for every view page; clearing keeps persistent kernel state.
This commit is contained in:
cflmy committed 2026-10-18 12:42:15 +08:00
1 parent 01468ad976
commit fb28eee62f
21 files changed
+379 -75

No files matched your search

+16
View File
@@ -1,6 +1,7 @@
---
title: lib/foreign
description: Run bound code fences and inline sources via local interpreters
import table:lib/table.mq.md
---
Run bound code fences and inline sources via local interpreters.
@@ -148,6 +149,21 @@ in input order. Raises with the failing index after all workers finish.
*> host_foreign_call_many inputs=`inputs` code=`code` lang=`lang` source=`source` cmd=`cmd` env=`env` cwd=`cwd` timeout=`timeout` args=`args` max_output=`max_output` concurrency=`concurrency`*
## session
+ `kernels`=None
+ `cells`=None
Declare a document view session. `kernels` and `cells` are ordinary tables:
kernels are `|名称|语言|命令|` (ZH or EN), cells are `|单元|内核|`.
Returns a foreign session handle consumed by `view`; without this handle the
view has no persistent kernel state.
**p = > table.empty_map**
**p = > table.put in=`p` at="kind" value="foreign-session"**
**p = > table.put in=`p` at="kernels" value=`kernels`**
**p = > table.put in=`p` at="cells" value=`cells`**
*p*
## session_open
+ `lang`
+ `cmd`=None
+14
View File
@@ -1,6 +1,7 @@
---
title: lib/外联
description: 通过本机解释器运行绑定的代码围栏与内联源码
import table:lib/table.mq.md
---
通过本机解释器运行绑定的代码围栏与内联源码。
@@ -146,6 +147,19 @@ JSON 进 / JSON 出:把 `输入` 编码到 stdin,解析 stdout JSON 返回
*> host_foreign_call_many inputs=`输入表` code=`代码` lang=`语言` source=`源码` cmd=`命令` env=`环境` cwd=`工作目录` timeout=`超时` args=`参数` max_output=`最大输出` concurrency=`并发`*
## 会话
+ `内核表`=None
+ `单元表`=None
声明文档视图会话。内核表和单元表都是普通表格;返回一个 foreign 会话句柄,
供 view 消费。没有这个句柄时,view 的 cells 是无状态的。
**p = > table.empty_map**
**p = > table.put in=`p` at="kind" value="foreign-session"**
**p = > table.put in=`p` at="kernels" value=`内核表`**
**p = > table.put in=`p` at="cells" value=`单元表`**
*p*
## 会话开启
+ `语言`
+ `命令`=None