feat(foreign): JSON call and parallel fan-out

F2: call/call_many JSON bridge, run_many ordered parallel execution with per-item isolation and concurrency cap, plus node gold tests for call and call_many.
This commit is contained in:
cflmy committed 2026-10-18 01:29:15 +08:00
1 parent e32ff8f6b3
commit 7859170aec
8 files changed
+597 -19

No files matched your search

+43
View File
@@ -105,6 +105,49 @@ tables read.
*> host_foreign_load_config path=`path`*
## call
+ `code`=None
+ `lang`=None
+ `source`=None
+ `input`=None
+ `stdin`=None
+ `env`=None
+ `cwd`=None
+ `timeout`=None
+ `args`=None
JSON-in / JSON-out call: encode `input` on stdin, parse stdout JSON and return
the value (empty stdout -> None). Raises on process failure or invalid JSON.
*> host_foreign_call code=`code` lang=`lang` source=`source` input=`input` stdin=`stdin` env=`env` cwd=`cwd` timeout=`timeout` args=`args`*
## run_many
+ `runs`
+ `concurrency`=4
Run a list of code values or invoke-option maps in parallel; returns records in
input order. One failing item does not stop the others.
*> host_foreign_run_many runs=`runs` concurrency=`concurrency`*
## call_many
+ `inputs`
+ `code`=None
+ `lang`=None
+ `source`=None
+ `cmd`=None
+ `env`=None
+ `cwd`=None
+ `timeout`=None
+ `args`=None
+ `max_output`=None
+ `concurrency`=4
Apply one code/function to each input in parallel; returns parsed JSON results
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`*
## langs
List configured foreign languages.
+42
View File
@@ -104,6 +104,48 @@ auto | text | json | lines。`命令` 仅本次覆盖解释器。
*> host_foreign_load_config path=`路径`*
## 调用
+ `代码`=None
+ `语言`=None
+ `源码`=None
+ `输入`=None
+ `标准输入`=None
+ `环境`=None
+ `工作目录`=None
+ `超时`=None
+ `参数`=None
JSON 进 / JSON 出:把 `输入` 编码到 stdin,解析 stdout JSON 返回值
(stdout 为空 → None)。进程失败或 JSON 非法时报错。
*> host_foreign_call code=`代码` lang=`语言` source=`源码` input=`输入` stdin=`标准输入` env=`环境` cwd=`工作目录` timeout=`超时` args=`参数`*
## 批量运行
+ `任务表`
+ `并发`=4
并行运行一组代码值或 invoke 选项 map;按输入顺序返回记录。单项失败不影响其它项。
*> host_foreign_run_many runs=`任务表` concurrency=`并发`*
## 批量调用
+ `输入表`
+ `代码`=None
+ `语言`=None
+ `源码`=None
+ `命令`=None
+ `环境`=None
+ `工作目录`=None
+ `超时`=None
+ `参数`=None
+ `最大输出`=None
+ `并发`=4
把同一段代码并行作用到每个输入;按输入顺序返回解析后的 JSON 结果。
全部结束后若任一项失败,报错并指出下标。
*> host_foreign_call_many inputs=`输入表` code=`代码` lang=`语言` source=`源码` cmd=`命令` env=`环境` cwd=`工作目录` timeout=`超时` args=`参数` max_output=`最大输出` concurrency=`并发`*
## 语言表
列出已配置的外联语言。