feat(markup): finish v0.3 stock migration and green gold

Migrate remaining .mq.md (tests/ext/public/examples), stop elevating local assigns to params, inject form_target in Go libweb, and skip live LLM gold without a real key.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-09-13 23:43:44 +08:00
1 parent bfb10d172b
commit b5c07385e9
324 files changed
+4572 -4339

No files matched your search

+1123 -1123
View File
File diff suppressed because it is too large. Load diff
+28 -28
View File
@@ -12,50 +12,50 @@ import table:lib/table.mq.md
Load `.env` from cwd (optional named arg `path=`). Does not override existing variables.
**> sys.load_dotenv path=`path`**
*> sys.load_dotenv path=`path`*
## stream_result
+ `events`
Reduce a `complete stream=True` event list to the final `done.result` text (or `error.message`). Unknown types (e.g. `reasoning`) are ignored.
*answer = ""*
**answer = ""**
- [ev](events)
*t = ev[^type]*
**t = ev[^type]**
1. `t` == "done"
*answer = ev[^result]*
**answer = ev[^result]**
2. `t` == "error"
*answer = ev[^message]*
**answer = ev[^message]**
3. `t` == "delta"
4. *
*_ = 1*
**_ = 1**
**answer**
*answer*
# llm
Construct an LLM handle from `OPENAI_*` / `MARQDO_LLM_*`.
*api_key = > sys.env_get name="OPENAI_API_KEY"*
**api_key = > sys.env_get name="OPENAI_API_KEY"**
1. not `api_key`
*api_key = > sys.env_get name="MARQDO_LLM_API_KEY"*
**api_key = > sys.env_get name="MARQDO_LLM_API_KEY"**
1. not `api_key`
> print text=ext/ai/llm: set OPENAI_API_KEY or MARQDO_LLM_API_KEY
> sys.exit code=1
*base_url = > sys.env_get name="OPENAI_BASE_URL"*
**base_url = > sys.env_get name="OPENAI_BASE_URL"**
1. not `base_url`
*base_url = > sys.env_get name="MARQDO_LLM_BASE_URL"*
**base_url = > sys.env_get name="MARQDO_LLM_BASE_URL"**
1. not `base_url`
*base_url = "https://api.openai.com/v1"*
**base_url = "https://api.openai.com/v1"**
*model = > sys.env_get name="OPENAI_MODEL"*
**model = > sys.env_get name="OPENAI_MODEL"**
1. not `model`
*model = > sys.env_get name="MARQDO_LLM_MODEL"*
**model = > sys.env_get name="MARQDO_LLM_MODEL"**
1. not `model`
*model = "gpt-4o-mini"*
**model = "gpt-4o-mini"**
`h` =
@@ -63,7 +63,7 @@ Construct an LLM handle from `OPENAI_*` / `MARQDO_LLM_*`.
|---------|----------|-------|--------|--------|
| `api_key` | `base_url` | `model` | /chat/completions | "Bearer " |
**h**
*h*
## complete
+ `prompt`
@@ -74,9 +74,9 @@ Chat completion using `self` handle fields.
Wire body is `{model, messages:[{role,content}], stream?}`. Messages are an `@` row table; headers and optional `stream` use `table.put`. `json` is only for stringify/parse.
*url = self[^base_url] + self[^suffix]*
*auth = self[^bearer] + self[^api_key]*
*headers = > table.put in=None at="Authorization" value=`auth`*
**url = self[^base_url] + self[^suffix]**
**auth = self[^bearer] + self[^api_key]**
**headers = > table.put in=None at="Authorization" value=`auth`**
`messages` =
@@ -91,21 +91,21 @@ Wire body is `{model, messages:[{role,content}], stream?}`. Messages are an `@`
| self[^model] | `messages` |
1. `stream`
*req = > table.put in=`req` at="stream" value=True*
*body = > json.stringify value=`req`*
*resp = > net.http_post_sse url=`url` body=`body` headers=`headers` echo=`echo`*
**req = > table.put in=`req` at="stream" value=True**
**body = > json.stringify value=`req`**
**resp = > net.http_post_sse url=`url` body=`body` headers=`headers` echo=`echo`**
1. resp[^status] == 200
**resp[^events]**
*resp[^events]*
2. *
> print text=ext/ai/llm: HTTP error (stream)
> print text=resp[^status]
> sys.exit code=1
2. *
*body = > json.stringify value=`req`*
*resp = > net.http_post url=`url` body=`body` headers=`headers`*
**body = > json.stringify value=`req`**
**resp = > net.http_post url=`url` body=`body` headers=`headers`**
1. resp[^status] == 200
*data = > json.parse text=resp[^body]*
**data[^choices][^1][^message][^content]**
**data = > json.parse text=resp[^body]**
*data[^choices][^1][^message][^content]*
2. *
> print text=ext/ai/llm: HTTP error
> print text=resp[^status]
@@ -121,4 +121,4 @@ Wire body is `{model, messages:[{role,content}], stream?}`. Messages are an `@`
Alias for `complete`.
**> self.complete prompt=`prompt` stream=`stream` echo=`echo`**
*> self.complete prompt=`prompt` stream=`stream` echo=`echo`*
+28 -28
View File
@@ -12,50 +12,50 @@ import json:lib/json.mq.md
从工作目录加载 `.env`(可选命名实参 `路径=`)。不覆盖已有变量。
**> 系统.加载环境 路径=`路径`**
*> 系统.加载环境 路径=`路径`*
## 流式结果
+ `事件`
把 `运行 流式=真` 的事件列表收成最终 `done.result`(或 `error.message`)。未知类型(如 `reasoning`)忽略。
*answer = ""*
**answer = ""**
- [ev](事件)
*t = ev[^type]*
**t = ev[^type]**
1. `t` == "done"
*answer = ev[^result]*
**answer = ev[^result]**
2. `t` == "error"
*answer = ev[^message]*
**answer = ev[^message]**
3. `t` == "delta"
4. *
*_ = 1*
**_ = 1**
**answer**
*answer*
# 大模型
从 `OPENAI_*` / `MARQDO_LLM_*` 构造句柄。
*api_key = > 系统.取环境 名="OPENAI_API_KEY"*
**api_key = > 系统.取环境 名="OPENAI_API_KEY"**
1. 非 `api_key`
*api_key = > 系统.取环境 名="MARQDO_LLM_API_KEY"*
**api_key = > 系统.取环境 名="MARQDO_LLM_API_KEY"**
1. 非 `api_key`
> 打印 内容=ext/ai/大模型: 请设置 OPENAI_API_KEY 或 MARQDO_LLM_API_KEY
> 系统.退出 码=1
*base_url = > 系统.取环境 名="OPENAI_BASE_URL"*
**base_url = > 系统.取环境 名="OPENAI_BASE_URL"**
1. 非 `base_url`
*base_url = > 系统.取环境 名="MARQDO_LLM_BASE_URL"*
**base_url = > 系统.取环境 名="MARQDO_LLM_BASE_URL"**
1. 非 `base_url`
*base_url = "https://api.openai.com/v1"*
**base_url = "https://api.openai.com/v1"**
*model = > 系统.取环境 名="OPENAI_MODEL"*
**model = > 系统.取环境 名="OPENAI_MODEL"**
1. 非 `model`
*model = > 系统.取环境 名="MARQDO_LLM_MODEL"*
**model = > 系统.取环境 名="MARQDO_LLM_MODEL"**
1. 非 `model`
*model = "gpt-4o-mini"*
**model = "gpt-4o-mini"**
`h` =
@@ -63,7 +63,7 @@ import json:lib/json.mq.md
|---------|----------|-------|--------|--------|
| `api_key` | `base_url` | `model` | /chat/completions | "Bearer " |
**h**
*h*
## 运行
+ `提示`
@@ -74,9 +74,9 @@ import json:lib/json.mq.md
线上 body 为 `{model, messages:[{role,content}], stream?}`。消息用 `@` 行向表;headers 与可选 `stream` 用 `表.改`。`json` 只做 stringify/parse。
*url = 自[^base_url] + 自[^suffix]*
*auth = 自[^bearer] + 自[^api_key]*
*headers = > 表.改 入=None 于="Authorization" 值=`auth`*
**url = 自[^base_url] + 自[^suffix]**
**auth = 自[^bearer] + 自[^api_key]**
**headers = > 表.改 入=None 于="Authorization" 值=`auth`**
`messages` =
@@ -91,21 +91,21 @@ import json:lib/json.mq.md
| 自[^model] | `messages` |
1. `流式`
*req = > 表.改 入=`req` 于="stream" 值=True*
*body = > json.stringify value=`req`*
*resp = > 网络.提交流式 地址=`url` 内容=`body` headers=`headers` 打印增量=`打印增量`*
**req = > 表.改 入=`req` 于="stream" 值=True**
**body = > json.stringify value=`req`**
**resp = > 网络.提交流式 地址=`url` 内容=`body` headers=`headers` 打印增量=`打印增量`**
1. resp[^status] == 200
**resp[^events]**
*resp[^events]*
2. *
> 打印 内容=ext/ai/大模型: HTTP 错误(流式)
> 打印 内容=resp[^status]
> 系统.退出 码=1
2. *
*body = > json.stringify value=`req`*
*resp = > 网络.提交 地址=`url` 内容=`body` headers=`headers`*
**body = > json.stringify value=`req`**
**resp = > 网络.提交 地址=`url` 内容=`body` headers=`headers`**
1. resp[^status] == 200
*data = > json.parse text=resp[^body]*
**data[^choices][^1][^message][^content]**
**data = > json.parse text=resp[^body]**
*data[^choices][^1][^message][^content]*
2. *
> 打印 内容=ext/ai/大模型: HTTP 错误
> 打印 内容=resp[^status]
@@ -121,4 +121,4 @@ import json:lib/json.mq.md
运行 的别名。
**> 自.运行 提示=`提示` 流式=`流式` 打印增量=`打印增量`**
*> 自.运行 提示=`提示` 流式=`流式` 打印增量=`打印增量`*
+83 -83
View File
@@ -16,11 +16,11 @@ import json:lib/json.mq.md
+ `源码深度`=default
+ `技能深度`=default
组装可读提示:站立提示、任务、**调用位置**、工具、**预算**源码 + Skill,以及人可见的行动约定。
组装可读提示:站立提示、任务、*调用位置*、工具、*预算*源码 + Skill,以及人可见的行动约定。
编排 `.mq.md` 即真相源(代码即文档)。默认预算防爆窗;可先 `读取:source|skill` 加深再答或 `调用:`。
实现委托 `agent.build_step_context`(与英文版同源)。
**> agent.build_step_context agent=`智能体` task=`任务` source_depth=`源码深度` skill_depth=`技能深度`**
*> agent.build_step_context agent=`智能体` task=`任务` source_depth=`源码深度` skill_depth=`技能深度`*
---
@@ -29,31 +29,31 @@ import json:lib/json.mq.md
解析人可读调用行:`CALL:<名>` 或 `调用:<名>` / `调用:<名>`。
*esc = > json.parse text={"nl":"\n"}*
*nl = > json.get value=`esc` key="nl"*
*text = > trim value=`回复`*
*lines = > split value=`text` sep=`nl`*
*found = 空*
**esc = > json.parse text={"nl":"\n"}**
**nl = > json.get value=`esc` key="nl"**
**text = > trim value=`回复`**
**lines = > split value=`text` sep=`nl`**
**found = 空**
- [`line`](`lines`)
*t = > trim value=`line`*
*parts = > split value=`t` sep=:*
*n = > len value=`parts`*
**t = > trim value=`line`**
**parts = > split value=`t` sep=:**
**n = > len value=`parts`**
1. `n` > 1
*head = > at value=`parts` index=0*
*head = > trim value=`head`*
*rest = > at value=`parts` index=1*
*rest = > trim value=`rest`*
**head = > at value=`parts` index=0**
**head = > trim value=`head`**
**rest = > at value=`parts` index=1**
**rest = > trim value=`rest`**
1. `head` == CALL
*found = rest*
**found = rest**
2. `head` == 调用
*found = rest*
**found = rest**
3. *
*_ = 1*
**_ = 1**
2. *
*_ = 1*
**_ = 1**
**found**
*found*
---
@@ -63,13 +63,13 @@ import json:lib/json.mq.md
白名单校验后,经 `lib/子任务`(`启动 函数=` → `等待`)调用 runbook 中的 `##`。
*allowed = > agent_tool_allowed tools=`工具` name=`名`*
**allowed = > agent_tool_allowed tools=`工具` name=`名`**
1. `allowed`
*id = > 子任务.启动 函数=`名`*
**> 子任务.等待 id=`id`**
**id = > 子任务.启动 函数=`名`**
*> 子任务.等待 id=`id`*
2. *
*msg = "Tool not allowed:"*
**msg + `名`**
**msg = "Tool not allowed:"**
*msg + `名`*
# 智能体
+ `大模型`
@@ -78,31 +78,31 @@ import json:lib/json.mq.md
加载 ABI v2 agent 插件(会话袋 + 上下文查询)。
*p = > 插件.原生路径 名="agent"*
**p = > 插件.原生路径 名="agent"**
1. `p`
> 插件.加载 路径=`p`
2. *
> 打印 内容=ext/ai/智能体: 未找到原生 agent 插件(请先 cargo build -p marqdo_plugin_agent 或 marqdo ext add agent)
> 系统.退出 码=1
*id = > agent_alloc*
*h = > json.parse text={"_type":"智能体"}*
*h = > json.set map=`h` key="id" value=`id`*
*h = > json.set map=`h` key="model" value=`大模型`*
*h = > json.set map=`h` key="tools" value=`工具`*
**id = > agent_alloc**
**h = > json.parse text={"_type":"智能体"}**
**h = > json.set map=`h` key="id" value=`id`**
**h = > json.set map=`h` key="model" value=`大模型`**
**h = > json.set map=`h` key="tools" value=`工具`**
1. `站立提示`
*h = > json.set map=`h` key="standing" value=`站立提示`*
**h = > json.set map=`h` key="standing" value=`站立提示`**
2. *
*_ = 1*
**_ = 1**
**h**
*h*
## 清空历史
清空本智能体 id 的插件会话袋。
*id = > json.get value=`自` key="id"*
**id = > json.get value=`自` key="id"**
> agent_history_clear id=`id`
****
@@ -112,76 +112,76 @@ import json:lib/json.mq.md
+ `流式`=假
+ `打印增量`=假
原子一轮:上下文 → 大模型 → 可选子任务调工具。返回 **map**(`status`、`task`、`decision`;成功含 `result`,可选 `tool` / `tool_result`;失败含 `error`)。默认(`写回=真`)将结果写入调用行下的命名槽 `ok` / `error`;传 `写回=假` 可关闭。
原子一轮:上下文 → 大模型 → 可选子任务调工具。返回 *map*(`status`、`task`、`decision`;成功含 `result`,可选 `tool` / `tool_result`;失败含 `error`)。默认(`写回=真`)将结果写入调用行下的命名槽 `ok` / `error`;传 `写回=假` 可关闭。
流式=真 时走 SSE;打印增量=真 边读边打印。返回 map 仍是最终 result 文本。
*ctx = > 构建单步上下文 智能体=`自` 任务=`任务`*
*id = > json.get value=`自` key="id"*
*model = > json.get value=`自` key="model"*
*tools = > json.get value=`自` key="tools"*
**ctx = > 构建单步上下文 智能体=`自` 任务=`任务`**
**id = > json.get value=`自` key="id"**
**model = > json.get value=`自` key="model"**
**tools = > json.get value=`自` key="tools"**
*user_turn = > json.parse text={"role":"user"}*
*user_turn = > json.set map=`user_turn` key="content" value=`任务`*
**user_turn = > json.parse text={"role":"user"}**
**user_turn = > json.set map=`user_turn` key="content" value=`任务`**
> agent_history_append id=`id` item=`user_turn`
1. `流式`
*evs = > model.运行 提示=`ctx` 流式=真 打印增量=`打印增量`*
*reply = > 大模型.流式结果 事件=`evs`*
**evs = > model.运行 提示=`ctx` 流式=真 打印增量=`打印增量`**
**reply = > 大模型.流式结果 事件=`evs`**
2. *
*reply = > model.运行 提示=`ctx`*
**reply = > model.运行 提示=`ctx`**
*reply = > trim value=`reply`*
*decision = reply*
*tool_name = > 提取工具名 回复=`reply`*
*out = > json.parse text={"status":"ok"}*
*out = > json.set map=`out` key="task" value=`任务`*
*out = > json.set map=`out` key="decision" value=`decision`*
**reply = > trim value=`reply`**
**decision = reply**
**tool_name = > 提取工具名 回复=`reply`**
**out = > json.parse text={"status":"ok"}**
**out = > json.set map=`out` key="task" value=`任务`**
**out = > json.set map=`out` key="decision" value=`decision`**
1. `tool_name`
*tool_out = > 运行工具 工具=`tools` 名=`tool_name`*
*tool_s = > json.stringify value=`tool_out`*
*deny = > split value=`tool_s` sep="Tool not allowed"*
*deny_n = > len value=`deny`*
**tool_out = > 运行工具 工具=`tools` 名=`tool_name`**
**tool_s = > json.stringify value=`tool_out`**
**deny = > split value=`tool_s` sep="Tool not allowed"**
**deny_n = > len value=`deny`**
1. `deny_n` > 1
*out = > json.set map=`out` key="status" value="error"*
*out = > json.set map=`out` key="error" value=`tool_s`*
*reply = tool_s*
**out = > json.set map=`out` key="status" value="error"**
**out = > json.set map=`out` key="error" value=`tool_s`**
**reply = tool_s**
2. *
*task_s = > json.stringify value=`任务`*
*fp = "The user asked:"*
*fp = fp + task_s*
*fp = fp + ". Tool"*
*fp = fp + tool_name*
*fp = fp + "ran via subtask and returned:"*
*fp = fp + tool_s*
*fp = fp + ". Reply to the user briefly."*
**task_s = > json.stringify value=`任务`**
**fp = "The user asked:"**
**fp = fp + task_s**
**fp = fp + ". Tool"**
**fp = fp + tool_name**
**fp = fp + "ran via subtask and returned:"**
**fp = fp + tool_s**
**fp = fp + ". Reply to the user briefly."**
1. `流式`
*evs2 = > model.运行 提示=`fp` 流式=真 打印增量=`打印增量`*
*reply = > 大模型.流式结果 事件=`evs2`*
**evs2 = > model.运行 提示=`fp` 流式=真 打印增量=`打印增量`**
**reply = > 大模型.流式结果 事件=`evs2`**
2. *
*reply = > model.运行 提示=`fp`*
*out = > json.set map=`out` key="tool" value=`tool_name`*
*out = > json.set map=`out` key="tool_result" value=`tool_s`*
*out = > json.set map=`out` key="result" value=`reply`*
**reply = > model.运行 提示=`fp`**
**out = > json.set map=`out` key="tool" value=`tool_name`**
**out = > json.set map=`out` key="tool_result" value=`tool_s`**
**out = > json.set map=`out` key="result" value=`reply`**
2. *
*out = > json.set map=`out` key="result" value=`reply`*
**out = > json.set map=`out` key="result" value=`reply`**
*as_turn = > json.parse text={"role":"assistant"}*
*as_turn = > json.set map=`as_turn` key="content" value=`reply`*
**as_turn = > json.parse text={"role":"assistant"}**
**as_turn = > json.set map=`as_turn` key="content" value=`reply`**
> agent_history_append id=`id` item=`as_turn`
1. `写回`
*body = > json.stringify value=`out`*
*st = > json.get value=`out` key="status"*
**body = > json.stringify value=`out`**
**st = > json.get value=`out` key="status"**
1. `st` == "ok"
> 自写回.写回 值=`body` 键="ok"
2. *
> 自写回.写回 值=`body` 键="error"
2. *
*_ = 1*
**_ = 1**
**out**
*out*
## 多步
+ `目标`
@@ -207,8 +207,8 @@ import json:lib/json.mq.md
多步工作簿默认写入 OKF `知识库目录/resources/<slug>.mq.md`;仅当传入 `工作簿目录` 时才用临时 runs。转发至英文 `agent.plan`。`流式` / `打印增量` / `轨迹` 对应 `stream` / `echo` / `trace`;`软命中` → `soft_match`;`近义命中` / `近义阈值` → `near_match` / `near_threshold`。
*model = > json.get value=`self` key="model"*
*tools = > json.get value=`self` key="tools"*
*standing = > json.get value=`self` key="standing"*
*en = > agent.agent model=`model` tools=`tools` standing=`standing`*
**> en.plan goal=`目标` workbook_dir=`工作簿目录` workbook=`工作簿` max_rounds=`最大轮次` confirm=`确认分解` writeback=`写回` skeleton=`骨架` reuse=`复用` optimize=`优化` force=`强制` soft_match=`软命中` near_match=`近义命中` near_threshold=`近义阈值` promote=`晋升` kb_dir=`知识库目录` improve_every=`改进周期` explore_n=`探索次数` stream=`流式` echo=`打印增量` trace=`轨迹`**
**model = > json.get value=`self` key="model"**
**tools = > json.get value=`self` key="tools"**
**standing = > json.get value=`self` key="standing"**
**en = > agent.agent model=`model` tools=`tools` standing=`standing`**
*> en.plan goal=`目标` workbook_dir=`工作簿目录` workbook=`工作簿` max_rounds=`最大轮次` confirm=`确认分解` writeback=`写回` skeleton=`骨架` reuse=`复用` optimize=`优化` force=`强制` soft_match=`软命中` near_match=`近义命中` near_threshold=`近义阈值` promote=`晋升` kb_dir=`知识库目录` improve_every=`改进周期` explore_n=`探索次数` stream=`流式` echo=`打印增量` trace=`轨迹`*
+58 -58
View File
@@ -9,7 +9,7 @@ import sys:lib/sys.mq.md
Load the ABI v2 `linalg` plugin once.
*p = > plugin.native_path name="linalg"*
**p = > plugin.native_path name="linalg"**
1. `p`
> plugin.load path=`p`
2. *
@@ -20,7 +20,7 @@ Load the ABI v2 `linalg` plugin once.
## ping
> ensure_plugin
**> linalg_ping**
*> linalg_ping*
## mul
+ `a`
@@ -29,27 +29,27 @@ Load the ABI v2 `linalg` plugin once.
Matrix product (lazy MatMul; shape-checked).
> ensure_plugin
**> linalg_mul a=`a` b=`b`**
*> linalg_mul a=`a` b=`b`*
## add
+ `a`
+ `b`
> ensure_plugin
**> linalg_add a=`a` b=`b`**
*> linalg_add a=`a` b=`b`*
## sub
+ `a`
+ `b`
> ensure_plugin
**> linalg_sub a=`a` b=`b`**
*> linalg_sub a=`a` b=`b`*
## transpose
+ `expr`
> ensure_plugin
**> linalg_transpose expr=`expr`**
*> linalg_transpose expr=`expr`*
## inv
+ `expr`
@@ -57,7 +57,7 @@ Matrix product (lazy MatMul; shape-checked).
Symbolic inverse (lazy).
> ensure_plugin
**> linalg_inv expr=`expr`**
*> linalg_inv expr=`expr`*
## simplify
+ `expr`
@@ -65,29 +65,29 @@ Symbolic inverse (lazy).
Apply MatExpr rewrite rules (R1–R5).
> ensure_plugin
**> linalg_simplify expr=`expr`**
*> linalg_simplify expr=`expr`*
## ascii
+ `expr`
+ `raw`=False
Display ASCII (default **simplify** first). Pass `raw=True` to keep the written tree.
Display ASCII (default simplify first). Pass `raw=True` to keep the written tree.
> ensure_plugin
**> linalg_ascii expr=`expr` raw=`raw`**
*> linalg_ascii expr=`expr` raw=`raw`*
## latex
+ `expr`
+ `raw`=False
> ensure_plugin
**> linalg_latex expr=`expr` raw=`raw`**
*> linalg_latex expr=`expr` raw=`raw`*
## shape
+ `expr`
> ensure_plugin
**> linalg_shape expr=`expr`**
*> linalg_shape expr=`expr`*
## show
+ `expr`
@@ -97,20 +97,20 @@ Display ASCII (default **simplify** first). Pass `raw=True` to keep the written
Record a formula SVG via host plot channel (default simplify). Returns the expr map.
> ensure_plugin
**> linalg_show expr=`expr` path=`path` raw=`raw`**
*> linalg_show expr=`expr` path=`path` raw=`raw`*
## eye
+ `n`
> ensure_plugin
**> linalg_eye n=`n`**
*> linalg_eye n=`n`*
## zeros
+ `rows`
+ `cols`
> ensure_plugin
**> linalg_zeros rows=`rows` cols=`cols`**
*> linalg_zeros rows=`rows` cols=`cols`*
## from_list
+ `data`
@@ -118,7 +118,7 @@ Record a formula SVG via host plot channel (default simplify). Returns the expr
Dense leaf from nested list.
> ensure_plugin
**> linalg_from_list data=`data`**
*> linalg_from_list data=`data`*
## from_formula
+ `formula`
@@ -126,28 +126,28 @@ Dense leaf from nested list.
Absorb a `$$` numeric matrix formula (or nested list / dense map) as a dense leaf.
> ensure_plugin
**> linalg_from_formula formula=`formula`**
*> linalg_from_formula formula=`formula`*
## explicit
+ `expr`
+ `raw`=False
Evaluate to dense (default **simplify** first).
Evaluate to dense (default simplify first).
> ensure_plugin
**> linalg_explicit expr=`expr` raw=`raw`**
*> linalg_explicit expr=`expr` raw=`raw`*
## det
+ `expr`
> ensure_plugin
**> linalg_det expr=`expr`**
*> linalg_det expr=`expr`*
## trace
+ `expr`
> ensure_plugin
**> linalg_trace expr=`expr`**
*> linalg_trace expr=`expr`*
## solve
+ `a`=None
@@ -157,7 +157,7 @@ Evaluate to dense (default **simplify** first).
Solve `a x = b` (Gaussian elimination), or reuse `factorize kind=lu` via `factor` + `b`.
> ensure_plugin
**> linalg_solve a=`a` b=`b` factor=`factor`**
*> linalg_solve a=`a` b=`b` factor=`factor`*
## matmul
+ `a`
@@ -166,7 +166,7 @@ Solve `a x = b` (Gaussian elimination), or reuse `factorize kind=lu` via `factor
Dense matrix product → `linalg_dense`.
> ensure_plugin
**> linalg_matmul a=`a` b=`b`**
*> linalg_matmul a=`a` b=`b`*
## kron
+ `a`
@@ -175,7 +175,7 @@ Dense matrix product → `linalg_dense`.
Lazy Kronecker product (does not expand).
> ensure_plugin
**> linalg_kron a=`a` b=`b`**
*> linalg_kron a=`a` b=`b`*
## block
+ `blocks`
@@ -183,7 +183,7 @@ Lazy Kronecker product (does not expand).
Block matrix from a nested list of expressions.
> ensure_plugin
**> linalg_block blocks=`blocks`**
*> linalg_block blocks=`blocks`*
## collapse
+ `expr`
@@ -191,7 +191,7 @@ Block matrix from a nested list of expressions.
Block-level collapse (`Block*Block` → block of products).
> ensure_plugin
**> linalg_collapse expr=`expr`**
*> linalg_collapse expr=`expr`*
## factorize
+ `matrix`
@@ -200,7 +200,7 @@ Block-level collapse (`Block*Block` → block of products).
Dense factorization → `linalg_factor` (`kind` = `lu` | `qr` | `svd` | `eig` | `chol`).
> ensure_plugin
**> linalg_factorize matrix=`matrix` kind=`kind`**
*> linalg_factorize matrix=`matrix` kind=`kind`*
## draw
+ `factor`
@@ -211,7 +211,7 @@ Dense factorization → `linalg_factor` (`kind` = `lu` | `qr` | `svd` | `eig` |
Structure SVG (`eig` | `svd` | `qr` | `lu` | `ge` | `chol` | `structure` | `heatmap` | `hinton`). Theme tokens match quantum Q8: `light` | `dark` | `bw`.
> ensure_plugin
**> linalg_draw factor=`factor` kind=`kind` path=`path` theme=`theme`**
*> linalg_draw factor=`factor` kind=`kind` path=`path` theme=`theme`*
## lstsq
+ `a`
@@ -220,7 +220,7 @@ Structure SVG (`eig` | `svd` | `qr` | `lu` | `ge` | `chol` | `structure` | `heat
Least squares `min ||a x - b||` (QR if tall, SVD if wide).
> ensure_plugin
**> linalg_lstsq a=`a` b=`b`**
*> linalg_lstsq a=`a` b=`b`*
## norm
+ `expr`
@@ -229,7 +229,7 @@ Least squares `min ||a x - b||` (QR if tall, SVD if wide).
Matrix norm: `fro` | `1` | `inf` | `2`. Complex dense supports `fro` only.
> ensure_plugin
**> linalg_norm expr=`expr` ord=`ord`**
*> linalg_norm expr=`expr` ord=`ord`*
## cond
+ `expr`
@@ -237,7 +237,7 @@ Matrix norm: `fro` | `1` | `inf` | `2`. Complex dense supports `fro` only.
Spectral condition number via SVD (`ord=2`).
> ensure_plugin
**> linalg_cond expr=`expr`**
*> linalg_cond expr=`expr`*
## rank
+ `expr`
@@ -245,7 +245,7 @@ Spectral condition number via SVD (`ord=2`).
Numerical rank (SVD).
> ensure_plugin
**> linalg_rank expr=`expr`**
*> linalg_rank expr=`expr`*
## declare
+ `table`
@@ -253,7 +253,7 @@ Numerical rank (SVD).
Declare several matrix symbols from an `@` record table (`name` / `rows` / `cols`). Returns a map env.
> ensure_plugin
**> linalg_declare table=`table` type_tag="matrix"**
*> linalg_declare table=`table` type_tag="matrix"*
## symbol
+ `name`
@@ -263,7 +263,7 @@ Declare several matrix symbols from an `@` record table (`name` / `rows` / `cols
Abstract matrix symbol. Returns a `# matrix` instance (supports `+` / `*` and methods).
> ensure_plugin
**> matrix name=`name` rows=`rows` cols=`cols`**
*> matrix name=`name` rows=`rows` cols=`cols`*
# matrix
+ `name`=None
@@ -277,96 +277,96 @@ Matrix value (`_type=matrix`). Prefer infix `A + B` / `A * B`, or methods `` `A`
> ensure_plugin
1. `formula`
**> linalg_from_formula formula=`formula`**
*> linalg_from_formula formula=`formula`*
2. `data`
**> linalg_from_list data=`data`**
*> linalg_from_list data=`data`*
3. `name`
**> linalg_symbol name=`name` rows=`rows` cols=`cols`**
*> linalg_symbol name=`name` rows=`rows` cols=`cols`*
4. `n`
**> linalg_eye n=`n`**
*> linalg_eye n=`n`*
5. `rows`
**> linalg_zeros rows=`rows` cols=`cols`**
*> linalg_zeros rows=`rows` cols=`cols`*
6. *
> print text=ext/linalg: matrix needs name= / data= / formula= / n= / rows=
**None**
*None*
## T
**> linalg_transpose expr=`self`**
*> linalg_transpose expr=`self`*
## T_ascii
Transpose then display ASCII (auto-simplified). Handy for lecture identities.
*`Pt` = > linalg_transpose expr=`self`*
**> linalg_ascii expr=`Pt` raw=False**
**`Pt` = > linalg_transpose expr=`self`**
*> linalg_ascii expr=`Pt` raw=False*
## add
+ `b`
**> linalg_add a=`self` b=`b`**
*> linalg_add a=`self` b=`b`*
## sub
+ `b`
**> linalg_sub a=`self` b=`b`**
*> linalg_sub a=`self` b=`b`*
## mul
+ `b`
**> linalg_mul a=`self` b=`b`**
*> linalg_mul a=`self` b=`b`*
## inv
**> linalg_inv expr=`self`**
*> linalg_inv expr=`self`*
## simplify
**> linalg_simplify expr=`self`**
*> linalg_simplify expr=`self`*
## ascii
**> linalg_ascii expr=`self` raw=False**
*> linalg_ascii expr=`self` raw=False*
## latex
**> linalg_latex expr=`self` raw=False**
*> linalg_latex expr=`self` raw=False*
## explicit
**> linalg_explicit expr=`self` raw=False**
*> linalg_explicit expr=`self` raw=False*
## det
**> linalg_det expr=`self`**
*> linalg_det expr=`self`*
## trace
**> linalg_trace expr=`self`**
*> linalg_trace expr=`self`*
## show
+ `path`=None
+ `raw`=False
**> linalg_show expr=`self` path=`path` raw=`raw`**
*> linalg_show expr=`self` path=`path` raw=`raw`*
## eye
+ `n`
**> linalg_eye n=`n`**
*> linalg_eye n=`n`*
## zeros
+ `rows`
+ `cols`
**> linalg_zeros rows=`rows` cols=`cols`**
*> linalg_zeros rows=`rows` cols=`cols`*
## from_list
+ `data`
**> linalg_from_list data=`data`**
*> linalg_from_list data=`data`*
## from_formula
+ `formula`
**> linalg_from_formula formula=`formula`**
*> linalg_from_formula formula=`formula`*
+58 -58
View File
@@ -9,7 +9,7 @@ import sys:lib/sys.mq.md
加载 ABI v2 `linalg` 插件一次。
*p = > plugin.native_path name="linalg"*
**p = > plugin.native_path name="linalg"**
1. `p`
> plugin.load path=`p`
2. *
@@ -20,7 +20,7 @@ import sys:lib/sys.mq.md
## 探测
> 确保插件
**> linalg_ping**
*> linalg_ping*
## 乘
+ `左`
@@ -29,33 +29,33 @@ import sys:lib/sys.mq.md
矩阵乘(惰性;检查形状)。
> 确保插件
**> linalg_mul a=`左` b=`右`**
*> linalg_mul a=`左` b=`右`*
## 加
+ `左`
+ `右`
> 确保插件
**> linalg_add a=`左` b=`右`**
*> linalg_add a=`左` b=`右`*
## 减
+ `左`
+ `右`
> 确保插件
**> linalg_sub a=`左` b=`右`**
*> linalg_sub a=`左` b=`右`*
## 转置
+ `式`
> 确保插件
**> linalg_transpose expr=`式`**
*> linalg_transpose expr=`式`*
## 逆
+ `式`
> 确保插件
**> linalg_inv expr=`式`**
*> linalg_inv expr=`式`*
## 化简
+ `式`
@@ -63,29 +63,29 @@ import sys:lib/sys.mq.md
应用矩阵表达式重写规则(R1–R5)。
> 确保插件
**> linalg_simplify expr=`式`**
*> linalg_simplify expr=`式`*
## 文本
+ `式`
+ `原始`=False
展示 ASCII(默认先 **化简**)。`原始=True` 保留书写树。
展示 ASCII(默认先 化简)。`原始=True` 保留书写树。
> 确保插件
**> linalg_ascii expr=`式` raw=`原始`**
*> linalg_ascii expr=`式` raw=`原始`*
## 乳胶
+ `式`
+ `原始`=False
> 确保插件
**> linalg_latex expr=`式` raw=`原始`**
*> linalg_latex expr=`式` raw=`原始`*
## 形状
+ `式`
> 确保插件
**> linalg_shape expr=`式`**
*> linalg_shape expr=`式`*
## 展示
+ `式`
@@ -95,26 +95,26 @@ import sys:lib/sys.mq.md
写入公式 SVG(默认化简)。
> 确保插件
**> linalg_show expr=`式` path=`路径` raw=`原始`**
*> linalg_show expr=`式` path=`路径` raw=`原始`*
## 单位
+ `阶`
> 确保插件
**> linalg_eye n=`阶`**
*> linalg_eye n=`阶`*
## 零阵
+ `行`
+ `列`
> 确保插件
**> linalg_zeros rows=`行` cols=`列`**
*> linalg_zeros rows=`行` cols=`列`*
## 自列表
+ `数据`
> 确保插件
**> linalg_from_list data=`数据`**
*> linalg_from_list data=`数据`*
## 自公式
+ `公式`
@@ -122,28 +122,28 @@ import sys:lib/sys.mq.md
吸收 `$$` 数值矩阵公式为稠密叶。
> 确保插件
**> linalg_from_formula formula=`公式`**
*> linalg_from_formula formula=`公式`*
## 求值
+ `式`
+ `原始`=False
求成稠密(默认先 **化简**)。
求成稠密(默认先 化简)。
> 确保插件
**> linalg_explicit expr=`式` raw=`原始`**
*> linalg_explicit expr=`式` raw=`原始`*
## 行列式
+ `式`
> 确保插件
**> linalg_det expr=`式`**
*> linalg_det expr=`式`*
## 迹
+ `式`
> 确保插件
**> linalg_trace expr=`式`**
*> linalg_trace expr=`式`*
## 求解
+ `左`=None
@@ -153,14 +153,14 @@ import sys:lib/sys.mq.md
解 `左 · x = 右`,或复用 `分解`(`kind=lu`)+ `右`。
> 确保插件
**> linalg_solve a=`左` b=`右` factor=`分解`**
*> linalg_solve a=`左` b=`右` factor=`分解`*
## 稠密乘
+ `左`
+ `右`
> 确保插件
**> linalg_matmul a=`左` b=`右`**
*> linalg_matmul a=`左` b=`右`*
## 克罗内克
+ `左`
@@ -169,7 +169,7 @@ import sys:lib/sys.mq.md
惰性 Kronecker 积(默认不展开)。
> 确保插件
**> linalg_kron a=`左` b=`右`**
*> linalg_kron a=`左` b=`右`*
## 分块
+ `块`
@@ -177,7 +177,7 @@ import sys:lib/sys.mq.md
由嵌套表达式列表构造分块矩阵。
> 确保插件
**> linalg_block blocks=`块`**
*> linalg_block blocks=`块`*
## 分块化简
+ `式`
@@ -185,7 +185,7 @@ import sys:lib/sys.mq.md
分块级塌缩(`Block*Block` → 块乘加)。
> 确保插件
**> linalg_collapse expr=`式`**
*> linalg_collapse expr=`式`*
## 分解
+ `矩阵`
@@ -194,7 +194,7 @@ import sys:lib/sys.mq.md
稠密分解 → `linalg_factor`(`类型` = `lu` | `qr` | `svd` | `eig` | `chol`)。
> 确保插件
**> linalg_factorize matrix=`矩阵` kind=`类型`**
*> linalg_factorize matrix=`矩阵` kind=`类型`*
## 绘图
+ `分解`
@@ -205,7 +205,7 @@ import sys:lib/sys.mq.md
结构 SVG(`eig` | `svd` | `qr` | `lu` | `ge` | `chol` | `structure` | `heatmap` | `hinton`)。主题与 quantum Q8 对齐:`light` | `dark` | `bw`。
> 确保插件
**> linalg_draw factor=`分解` kind=`类型` path=`路径` theme=`主题`**
*> linalg_draw factor=`分解` kind=`类型` path=`路径` theme=`主题`*
## 最小二乘
+ `左`
@@ -214,7 +214,7 @@ import sys:lib/sys.mq.md
最小二乘 `min ||左 · x - 右||`(高瘦用 QR,宽用 SVD)。
> 确保插件
**> linalg_lstsq a=`左` b=`右`**
*> linalg_lstsq a=`左` b=`右`*
## 范数
+ `式`
@@ -223,7 +223,7 @@ import sys:lib/sys.mq.md
矩阵范数:`fro` | `1` | `inf` | `2`。复数稠密暂仅 `fro`。
> 确保插件
**> linalg_norm expr=`式` ord=`范数`**
*> linalg_norm expr=`式` ord=`范数`*
## 条件数
+ `式`
@@ -231,7 +231,7 @@ import sys:lib/sys.mq.md
谱条件数(SVD,`ord=2`)。
> 确保插件
**> linalg_cond expr=`式`**
*> linalg_cond expr=`式`*
## 秩
+ `式`
@@ -239,7 +239,7 @@ import sys:lib/sys.mq.md
数值秩(SVD)。
> 确保插件
**> linalg_rank expr=`式`**
*> linalg_rank expr=`式`*
## 声明
+ `表`
@@ -247,7 +247,7 @@ import sys:lib/sys.mq.md
用 `@` 记录表一次声明多个符号矩阵(`名` / `行` / `列`)。返回环境 map。
> 确保插件
**> linalg_declare table=`表` type_tag="矩阵"**
*> linalg_declare table=`表` type_tag="矩阵"*
## 符号
+ `名`
@@ -257,7 +257,7 @@ import sys:lib/sys.mq.md
抽象矩阵符号。返回 `# 矩阵` 实例(可用 `+` / `*` 与方法)。
> 确保插件
**> 矩阵 名=`名` 行=`行` 列=`列`**
*> 矩阵 名=`名` 行=`行` 列=`列`*
# 矩阵
+ `名`=None
@@ -271,97 +271,97 @@ import sys:lib/sys.mq.md
> 确保插件
1. `公式`
**> linalg_from_formula formula=`公式`**
*> linalg_from_formula formula=`公式`*
2. `数据`
**> linalg_from_list data=`数据`**
*> linalg_from_list data=`数据`*
3. `名`
**> linalg_symbol name=`名` rows=`行` cols=`列`**
*> linalg_symbol name=`名` rows=`行` cols=`列`*
4. `阶`
**> linalg_eye n=`阶`**
*> linalg_eye n=`阶`*
5. `行`
**> linalg_zeros rows=`行` cols=`列`**
*> linalg_zeros rows=`行` cols=`列`*
6. *
> print text=ext/linalg: 矩阵需要 名= / 数据= / 公式= / 阶= / 行=
**None**
*None*
## 转置
**> linalg_transpose expr=`self`**
*> linalg_transpose expr=`self`*
## 转置文本
转置后输出 ASCII(默认化简)。适合讲义恒等式验收。
*`转` = > linalg_transpose expr=`self`*
**> linalg_ascii expr=`转` raw=False**
**`转` = > linalg_transpose expr=`self`**
*> linalg_ascii expr=`转` raw=False*
## 加
+ `右`
**> linalg_add a=`self` b=`右`**
*> linalg_add a=`self` b=`右`*
## 减
+ `右`
**> linalg_sub a=`self` b=`右`**
*> linalg_sub a=`self` b=`右`*
## 乘
+ `右`
**> linalg_mul a=`self` b=`右`**
*> linalg_mul a=`self` b=`右`*
## 逆
**> linalg_inv expr=`self`**
*> linalg_inv expr=`self`*
## 化简
**> linalg_simplify expr=`self`**
*> linalg_simplify expr=`self`*
## 文本
**> linalg_ascii expr=`self` raw=False**
*> linalg_ascii expr=`self` raw=False*
## 乳胶
**> linalg_latex expr=`self` raw=False**
*> linalg_latex expr=`self` raw=False*
## 求值
+ `原始`=False
**> linalg_explicit expr=`self` raw=`原始`**
*> linalg_explicit expr=`self` raw=`原始`*
## 行列式
**> linalg_det expr=`self`**
*> linalg_det expr=`self`*
## 迹
**> linalg_trace expr=`self`**
*> linalg_trace expr=`self`*
## 展示
+ `路径`=None
+ `原始`=False
**> linalg_show expr=`self` path=`路径` raw=`原始`**
*> linalg_show expr=`self` path=`路径` raw=`原始`*
## 单位
+ `阶`
**> linalg_eye n=`阶`**
*> linalg_eye n=`阶`*
## 零阵
+ `行`
+ `列`
**> linalg_zeros rows=`行` cols=`列`**
*> linalg_zeros rows=`行` cols=`列`*
## 自列表
+ `数据`
**> linalg_from_list data=`数据`**
*> linalg_from_list data=`数据`*
## 自公式
+ `公式`
**> linalg_from_formula formula=`公式`**
*> linalg_from_formula formula=`公式`*
+43 -43
View File
@@ -10,7 +10,7 @@ import json:lib/json.mq.md
Load the ABI v2 `quantum` plugin once.
*p = > plugin.native_path name="quantum"*
**p = > plugin.native_path name="quantum"**
1. `p`
> plugin.load path=`p`
2. *
@@ -25,7 +25,7 @@ Load the ABI v2 `quantum` plugin once.
Tensor product of two states or square matrices.
> ensure_plugin
**> quantum_kron a=`a` b=`b`**
*> quantum_kron a=`a` b=`b`*
## schmidt
+ `state`
@@ -34,7 +34,7 @@ Tensor product of two states or square matrices.
Schmidt decomposition of a pure state / circuit across `cut` (subsystem A = low qubits).
> ensure_plugin
**> quantum_schmidt state=`state` cut=`cut`**
*> quantum_schmidt state=`state` cut=`cut`*
## fidelity
+ `a`
@@ -43,7 +43,7 @@ Schmidt decomposition of a pure state / circuit across `cut` (subsystem A = low
Pure-state fidelity |⟨a|b⟩|².
> ensure_plugin
**> quantum_fidelity a=`a` b=`b`**
*> quantum_fidelity a=`a` b=`b`*
# circuit
+ `qubits`=1
@@ -52,98 +52,98 @@ Pure-state fidelity |⟨a|b⟩|².
State-vector circuit (default |0…0⟩). Optional `steps=` gate table (column or row records). Methods append gates and return an updated handle.
> ensure_plugin
**> quantum_circuit_new qubits=`qubits` steps=`steps`**
*> quantum_circuit_new qubits=`qubits` steps=`steps`*
## h
+ `qubit`=0
**> quantum_h circuit=`self` qubit=`qubit`**
*> quantum_h circuit=`self` qubit=`qubit`*
## x
+ `qubit`=0
**> quantum_x circuit=`self` qubit=`qubit`**
*> quantum_x circuit=`self` qubit=`qubit`*
## y
+ `qubit`=0
**> quantum_y circuit=`self` qubit=`qubit`**
*> quantum_y circuit=`self` qubit=`qubit`*
## z
+ `qubit`=0
**> quantum_z circuit=`self` qubit=`qubit`**
*> quantum_z circuit=`self` qubit=`qubit`*
## s
+ `qubit`=0
**> quantum_s circuit=`self` qubit=`qubit`**
*> quantum_s circuit=`self` qubit=`qubit`*
## t
+ `qubit`=0
**> quantum_t circuit=`self` qubit=`qubit`**
*> quantum_t circuit=`self` qubit=`qubit`*
## i
+ `qubit`=0
**> quantum_i circuit=`self` qubit=`qubit`**
*> quantum_i circuit=`self` qubit=`qubit`*
## rx
+ `qubit`=0
+ `theta`
**> quantum_rx circuit=`self` qubit=`qubit` theta=`theta`**
*> quantum_rx circuit=`self` qubit=`qubit` theta=`theta`*
## ry
+ `qubit`=0
+ `theta`
**> quantum_ry circuit=`self` qubit=`qubit` theta=`theta`**
*> quantum_ry circuit=`self` qubit=`qubit` theta=`theta`*
## rz
+ `qubit`=0
+ `theta`
**> quantum_rz circuit=`self` qubit=`qubit` theta=`theta`**
*> quantum_rz circuit=`self` qubit=`qubit` theta=`theta`*
## cx
+ `control`=0
+ `target`=1
**> quantum_cx circuit=`self` control=`control` target=`target`**
*> quantum_cx circuit=`self` control=`control` target=`target`*
## cz
+ `control`=0
+ `target`=1
**> quantum_cz circuit=`self` control=`control` target=`target`**
*> quantum_cz circuit=`self` control=`control` target=`target`*
## swap
+ `a`=0
+ `b`=1
**> quantum_swap circuit=`self` a=`a` b=`b`**
*> quantum_swap circuit=`self` a=`a` b=`b`*
## barrier
Visual separator only (no state change).
**> quantum_barrier circuit=`self`**
*> quantum_barrier circuit=`self`*
## measure
+ `qubits`=None
Mark computational-basis readout (`None` / empty = all qubits). Affects which bits `run` reports.
**> quantum_measure circuit=`self` qubits=`qubits`**
*> quantum_measure circuit=`self` qubits=`qubits`*
## append
+ `op`
Append another circuit's ops or a `{gate,qubits}` op map.
**> quantum_append circuit=`self` op=`op`**
*> quantum_append circuit=`self` op=`op`*
## apply
+ `gate`
@@ -151,7 +151,7 @@ Append another circuit's ops or a `{gate,qubits}` op map.
Apply a gate handle (named or custom `matrix=`) on `qubits` (int or list).
**> quantum_apply circuit=`self` gate=`gate` qubits=`qubits`**
*> quantum_apply circuit=`self` gate=`gate` qubits=`qubits`*
## noise
+ `kind`
@@ -159,25 +159,25 @@ Apply a gate handle (named or custom `matrix=`) on `qubits` (int or list).
Teaching noise for `run` trajectories (`bitflip` / `depolarizing` / `amplitude_damping`). Ignored by `simulate` / `probabilities`.
**> quantum_noise circuit=`self` kind=`kind` p=`p`**
*> quantum_noise circuit=`self` kind=`kind` p=`p`*
## simulate
Return state vector amplitudes `{re,im}` (ideal; no noise).
**> quantum_simulate circuit=`self`**
*> quantum_simulate circuit=`self`*
## state
Ideal state vector (same amplitudes as `simulate`).
**> quantum_state circuit=`self`**
*> quantum_state circuit=`self`*
## probabilities
Return map of basis label → probability (qubit 0 = rightmost bit). Ideal; ignores noise.
**> quantum_probabilities circuit=`self`**
*> quantum_probabilities circuit=`self`*
## run
+ `shots`=1024
@@ -185,7 +185,7 @@ Return map of basis label → probability (qubit 0 = rightmost bit). Ideal; igno
Sample computational-basis shots (deterministic with `seed=`). Applies circuit `noise` if set.
**> quantum_run circuit=`self` shots=`shots` seed=`seed`**
*> quantum_run circuit=`self` shots=`shots` seed=`seed`*
## draw
+ `path`=None
@@ -195,27 +195,27 @@ Sample computational-basis shots (deterministic with `seed=`). Applies circuit `
Circuit rail / probability bars / Bloch / advanced state plots (`kind=circuit|probs|bloch|hinton|city|density|paulivec|qsphere|multibloch`). Theme `dark` (default tech lab) / `light` / `bw`. Records into view/CLI plots via host `record_plot`.
**> quantum_draw_circuit circuit=`self` path=`path` kind=`kind` qubit=`qubit` theme=`theme`**
*> quantum_draw_circuit circuit=`self` path=`path` kind=`kind` qubit=`qubit` theme=`theme`*
## density
Pure-state density matrix ρ=|ψ⟩⟨ψ| after ideal simulate.
**> density state=`self`**
*> density state=`self`*
## expect
+ `obs`
Pauli string (left = high bit) or matrix expectation on the ideal state.
**> quantum_density_expect density=`self` obs=`obs`**
*> quantum_density_expect density=`self` obs=`obs`*
## schmidt
+ `cut`=1
Schmidt / singular values across a bipartition (`cut` = qubits in subsystem A, low bits).
**> quantum_schmidt state=`self` cut=`cut`**
*> quantum_schmidt state=`self` cut=`cut`*
# gate
+ `name`=None
@@ -225,17 +225,17 @@ Schmidt / singular values across a bipartition (`cut` = qubits in subsystem A, l
Named built-in gate (`name=H`) or custom unitary from `matrix=` (nested list or formula matrix fence). Optional `name=` label for custom gates (default `U`).
> ensure_plugin
**> quantum_gate_new name=`name` theta=`theta` matrix=`matrix`**
*> quantum_gate_new name=`name` theta=`theta` matrix=`matrix`*
## matrix
**> quantum_gate_matrix gate=`self`**
*> quantum_gate_matrix gate=`self`*
## matches_matrix
+ `matrix`
+ `tol`=0.000000001
**> quantum_gate_matches_matrix gate=`self` matrix=`matrix` tol=`tol`**
*> quantum_gate_matches_matrix gate=`self` matrix=`matrix` tol=`tol`*
## draw
+ `path`=None
@@ -243,7 +243,7 @@ Named built-in gate (`name=H`) or custom unitary from `matrix=` (nested list or
Gate glyph or complex-matrix heatmap (`kind=gate|matrix`). Records via host `record_plot`.
**> quantum_gate_draw gate=`self` path=`path` kind=`kind`**
*> quantum_gate_draw gate=`self` path=`path` kind=`kind`*
# density
+ `state`=None
@@ -253,37 +253,37 @@ Density matrix from a state/circuit (`state=`) or an explicit Hermitian `matrix=
> ensure_plugin
1. `matrix`
**> quantum_density_from_matrix matrix=`matrix`**
*> quantum_density_from_matrix matrix=`matrix`*
2. *
**> quantum_density_from_state state=`state`**
*> quantum_density_from_state state=`state`*
## matrix
**> quantum_density_matrix density=`self`**
*> quantum_density_matrix density=`self`*
## purity
Tr(ρ²).
**> quantum_density_purity density=`self`**
*> quantum_density_purity density=`self`*
## partial_trace
+ `keep`
Keep listed qubits (LSB=0); trace out the rest.
**> quantum_density_partial_trace density=`self` keep=`keep`**
*> quantum_density_partial_trace density=`self` keep=`keep`*
## eig
Hermitian spectrum → `{eigenvalues, eigenvectors}`.
**> quantum_density_eig density=`self`**
*> quantum_density_eig density=`self`*
## expect
+ `obs`
**> quantum_density_expect density=`self` obs=`obs`**
*> quantum_density_expect density=`self` obs=`obs`*
## draw
+ `path`=None
@@ -291,4 +291,4 @@ Hermitian spectrum → `{eigenvalues, eigenvectors}`.
Hinton / city / density-cells / Pauli vector SVG (`kind=hinton` or city or density or paulivec).
**> quantum_density_draw density=`self` path=`path` kind=`kind`**
*> quantum_density_draw density=`self` path=`path` kind=`kind`*
+43 -43
View File
@@ -10,7 +10,7 @@ import json:lib/json.mq.md
加载 ABI v2 `quantum` 插件。
*p = > plugin.native_path name="quantum"*
**p = > plugin.native_path name="quantum"**
1. `p`
> plugin.load path=`p`
2. *
@@ -25,14 +25,14 @@ import json:lib/json.mq.md
两态或方阵的张量积。
> 确保插件
**> quantum_kron a=`左` b=`右`**
*> quantum_kron a=`左` b=`右`*
## 施密特分解
+ `态`
+ `分割`=1
> 确保插件
**> quantum_schmidt state=`态` cut=`分割`**
*> quantum_schmidt state=`态` cut=`分割`*
## 保真度
+ `左`
@@ -41,7 +41,7 @@ import json:lib/json.mq.md
纯态保真度 |⟨a|b⟩|²。
> 确保插件
**> quantum_fidelity a=`左` b=`右`**
*> quantum_fidelity a=`左` b=`右`*
# 电路
+ `比特数`=1
@@ -50,98 +50,98 @@ import json:lib/json.mq.md
状态向量电路(默认 |0…0⟩)。可选 `步骤=` 门序列表。方法追加门并返回更新后的句柄。
> 确保插件
**> quantum_circuit_new qubits=`比特数` steps=`步骤`**
*> quantum_circuit_new qubits=`比特数` steps=`步骤`*
## 哈达玛
+ `比特`=0
**> quantum_h circuit=`self` qubit=`比特`**
*> quantum_h circuit=`self` qubit=`比特`*
## 泡利X
+ `比特`=0
**> quantum_x circuit=`self` qubit=`比特`**
*> quantum_x circuit=`self` qubit=`比特`*
## 泡利Y
+ `比特`=0
**> quantum_y circuit=`self` qubit=`比特`**
*> quantum_y circuit=`self` qubit=`比特`*
## 泡利Z
+ `比特`=0
**> quantum_z circuit=`self` qubit=`比特`**
*> quantum_z circuit=`self` qubit=`比特`*
## 相位S
+ `比特`=0
**> quantum_s circuit=`self` qubit=`比特`**
*> quantum_s circuit=`self` qubit=`比特`*
## 相位T
+ `比特`=0
**> quantum_t circuit=`self` qubit=`比特`**
*> quantum_t circuit=`self` qubit=`比特`*
## 单位
+ `比特`=0
**> quantum_i circuit=`self` qubit=`比特`**
*> quantum_i circuit=`self` qubit=`比特`*
## 绕X
+ `比特`=0
+ `参数`
**> quantum_rx circuit=`self` qubit=`比特` theta=`参数`**
*> quantum_rx circuit=`self` qubit=`比特` theta=`参数`*
## 绕Y
+ `比特`=0
+ `参数`
**> quantum_ry circuit=`self` qubit=`比特` theta=`参数`**
*> quantum_ry circuit=`self` qubit=`比特` theta=`参数`*
## 绕Z
+ `比特`=0
+ `参数`
**> quantum_rz circuit=`self` qubit=`比特` theta=`参数`**
*> quantum_rz circuit=`self` qubit=`比特` theta=`参数`*
## 控非
+ `控制`=0
+ `目标`=1
**> quantum_cx circuit=`self` control=`控制` target=`目标`**
*> quantum_cx circuit=`self` control=`控制` target=`目标`*
## 控相
+ `控制`=0
+ `目标`=1
**> quantum_cz circuit=`self` control=`控制` target=`目标`**
*> quantum_cz circuit=`self` control=`控制` target=`目标`*
## 交换
+ `比特甲`=0
+ `比特乙`=1
**> quantum_swap circuit=`self` a=`比特甲` b=`比特乙`**
*> quantum_swap circuit=`self` a=`比特甲` b=`比特乙`*
## 屏障
仅可视化分隔(不改态)。
**> quantum_barrier circuit=`self`**
*> quantum_barrier circuit=`self`*
## 测量
+ `比特`=None
标记计算基读出(空 = 全部比特)。影响 `运行` 报告哪些位。
**> quantum_measure circuit=`self` qubits=`比特`**
*> quantum_measure circuit=`self` qubits=`比特`*
## 追加
+ `操作`
追加另一电路的 ops,或 `{gate,qubits}` 操作表。
**> quantum_append circuit=`self` op=`操作`**
*> quantum_append circuit=`self` op=`操作`*
## 施加
+ `门`
@@ -149,7 +149,7 @@ import json:lib/json.mq.md
将门句柄(具名或 `矩阵=` 自定义)施加到 `比特`(整数或列表)。
**> quantum_apply circuit=`self` gate=`门` qubits=`比特`**
*> quantum_apply circuit=`self` gate=`门` qubits=`比特`*
## 噪声
+ `种类`
@@ -157,25 +157,25 @@ import json:lib/json.mq.md
教学噪声,供 `运行` 轨迹使用(`bitflip` / `depolarizing` / `amplitude_damping`,或中文:比特翻转 / 退极化 / 振幅阻尼)。`模拟` / `概率` 忽略。
**> quantum_noise circuit=`self` kind=`种类` p=`概率`**
*> quantum_noise circuit=`self` kind=`种类` p=`概率`*
## 模拟
返回态矢量振幅 `{re,im}`(理想;无噪声)。
**> quantum_simulate circuit=`self`**
*> quantum_simulate circuit=`self`*
## 态
理想态矢量(与 `模拟` 相同振幅)。
**> quantum_state circuit=`self`**
*> quantum_state circuit=`self`*
## 概率
基矢标签 → 概率(qubit 0 为最右侧比特)。理想;忽略噪声。
**> quantum_probabilities circuit=`self`**
*> quantum_probabilities circuit=`self`*
## 运行
+ `次数`=1024
@@ -183,7 +183,7 @@ import json:lib/json.mq.md
计算基采样(`种子=` 可复现)。若设置了电路噪声则启用。
**> quantum_run circuit=`self` shots=`次数` seed=`种子`**
*> quantum_run circuit=`self` shots=`次数` seed=`种子`*
## 绘图
+ `路径`=None
@@ -193,27 +193,27 @@ import json:lib/json.mq.md
电路轨线 / 概率条 / 布洛赫 / 高级态图(种类 circuit、probs、bloch、hinton、city、density、paulivec、qsphere、multibloch)。主题 dark(默认科技感)/ light / bw。经 record_plot 进入 view/CLI plots。
**> quantum_draw_circuit circuit=`self` path=`路径` kind=`种类` qubit=`比特` theme=`主题`**
*> quantum_draw_circuit circuit=`self` path=`路径` kind=`种类` qubit=`比特` theme=`主题`*
## 密度
理想模拟后的纯态密度矩阵 ρ=|ψ⟩⟨ψ|。
**> 密度 态=`self`**
*> 密度 态=`self`*
## 期望
+ `可观测量`
Pauli 串(左端=高比特)或矩阵期望值。
**> quantum_density_expect density=`self` obs=`可观测量`**
*> quantum_density_expect density=`self` obs=`可观测量`*
## 施密特
+ `分割`=1
二分施密特分解(`分割`=子系统 A 的比特数,低位)。
**> quantum_schmidt state=`self` cut=`分割`**
*> quantum_schmidt state=`self` cut=`分割`*
# 门
+ `名`=None
@@ -223,17 +223,17 @@ Pauli 串(左端=高比特)或矩阵期望值。
具名内置门(`名=H`)或由 `矩阵=`(嵌套 list 或公式矩阵围栏)定义的自定义酉门。自定义门可选 `名=`(默认 `U`)。
> 确保插件
**> quantum_gate_new name=`名` theta=`参数` matrix=`矩阵`**
*> quantum_gate_new name=`名` theta=`参数` matrix=`矩阵`*
## 矩阵
**> quantum_gate_matrix gate=`self`**
*> quantum_gate_matrix gate=`self`*
## 匹配矩阵
+ `矩阵`
+ `容差`=0.000000001
**> quantum_gate_matches_matrix gate=`self` matrix=`矩阵` tol=`容差`**
*> quantum_gate_matches_matrix gate=`self` matrix=`矩阵` tol=`容差`*
## 绘图
+ `路径`=None
@@ -241,7 +241,7 @@ Pauli 串(左端=高比特)或矩阵期望值。
门符号或复矩阵热力图(`种类=gate|matrix`)。经 `record_plot` 记录。
**> quantum_gate_draw gate=`self` path=`路径` kind=`种类`**
*> quantum_gate_draw gate=`self` path=`路径` kind=`种类`*
# 密度
+ `态`=None
@@ -251,37 +251,37 @@ Pauli 串(左端=高比特)或矩阵期望值。
> 确保插件
1. `矩阵`
**> quantum_density_from_matrix matrix=`矩阵`**
*> quantum_density_from_matrix matrix=`矩阵`*
2. *
**> quantum_density_from_state state=`态`**
*> quantum_density_from_state state=`态`*
## 矩阵
**> quantum_density_matrix density=`self`**
*> quantum_density_matrix density=`self`*
## 纯度
Tr(ρ²)。
**> quantum_density_purity density=`self`**
*> quantum_density_purity density=`self`*
## 部分迹
+ `保留`
保留所列比特(LSB=0),对其余求迹。
**> quantum_density_partial_trace density=`self` keep=`保留`**
*> quantum_density_partial_trace density=`self` keep=`保留`*
## 本征
厄米谱 → `{eigenvalues, eigenvectors}`。
**> quantum_density_eig density=`self`**
*> quantum_density_eig density=`self`*
## 期望
+ `可观测量`
**> quantum_density_expect density=`self` obs=`可观测量`**
*> quantum_density_expect density=`self` obs=`可观测量`*
## 绘图
+ `路径`=None
@@ -289,4 +289,4 @@ Tr(ρ²)。
Hinton / 城市 / 密度格 / 泡利向量 SVG(`种类=hinton` 或 city / density / paulivec)。
**> quantum_density_draw density=`self` path=`路径` kind=`种类`**
*> quantum_density_draw density=`self` path=`路径` kind=`种类`*
+187 -187
View File
@@ -10,7 +10,7 @@ import table:lib/table.mq.md
Load the ABI v2 `web` plugin once.
*p = > plugin.native_path name="web"*
**p = > plugin.native_path name="web"**
1. `p`
> plugin.load path=`p`
2. *
@@ -36,7 +36,7 @@ For complex themes prefer `page.css` (raw string, no table eval) or an external
them into CSS — 样式即数据、装配即函数.
> ensure_plugin
**> web_style name=`name` table=`table` strict=`strict`**
*> web_style name=`name` table=`table` strict=`strict`*
## make_images
+ `table`
@@ -47,7 +47,7 @@ Assemble a GFM image table into an HTML fragment (`div.mq-images` of
`链接`/`宽度`/`高度`/`加载`/`图注`). Images stay as data — 图片即数据、装配即函数.
> ensure_plugin
**> web_images table=`table`**
*> web_images table=`table`*
## make_head
+ `table`
@@ -56,7 +56,7 @@ Assemble a Head resource table into HTML (`<link>` / `<script>`). Useful for
preview; prefer `page.head` to attach resources to a page.
> ensure_plugin
**> web_head table=`table`**
*> web_head table=`table`*
## client_embed
+ `bridge`="/static/marqdo-bridge.js"
@@ -65,16 +65,16 @@ preview; prefer `page.head` to attach resources to a page.
+ `boot`=True
Return an HTML snippet that loads the official browser Marqdo bridge (route C/D).
With `boot` and non-empty `source` (URL path to `.mq.md`), emits `data-mq-wasm` / `data-mq-source-url` so the bridge **auto-mounts** (author zero JS).
With `boot` and non-empty `source` (URL path to `.mq.md`), emits `data-mq-wasm` / `data-mq-source-url` so the bridge auto-mounts (author zero JS).
Run `marqdo wasm build -o static` and `app.static dir=static`. Design: [browser-marqdo-wasm.md](../../doc/design/browser-marqdo-wasm.md) §16.
1. `boot`
1. `source` != ""
**"<script type=\"module\" src=\"" + bridge + "\" data-mq-wasm=\"" + wasm + "\" data-mq-source-url=\"" + source + "\"></script>"**
*"<script type=\"module\" src=\"" + bridge + "\" data-mq-wasm=\"" + wasm + "\" data-mq-source-url=\"" + source + "\"></script>"*
2. *
**"<script type=\"module\" src=\"" + bridge + "\"></script>"**
*"<script type=\"module\" src=\"" + bridge + "\"></script>"*
2. *
**"<script type=\"module\" src=\"" + bridge + "\" data-mq-no-boot=\"1\"></script>"**
*"<script type=\"module\" src=\"" + bridge + "\" data-mq-no-boot=\"1\"></script>"*
## text_patch
+ `sel`
@@ -83,8 +83,8 @@ Run `marqdo wasm build -o static` and `app.static dir=static`. Design: [browser-
Shortcut: build a `set_text` effects map `{ set_text: { sel: text } }` for browser return values.
Prefer authoring with `lib/browser` + GFM tables in client `.mq.md` ([marqdo-dev](../../.cursor/skills/marqdo-dev/SKILL.md)).
*`m` = > table.put in=None at=sel value=text*
**> table.put in=None at="set_text" value=m**
**`m` = > table.put in=None at=sel value=text**
*> table.put in=None at="set_text" value=m*
## dom_patch
+ `set_text`=None
@@ -115,58 +115,58 @@ Prefer authoring with `lib/browser` + GFM tables in client `.mq.md` ([marqdo-dev
Merge browser effect keys into one return map (omit `None`). Route E/F effects included.
*`out` = > table.put in=None at="_mq" value=True*
**`out` = > table.put in=None at="_mq" value=True**
1. `set_text` != None
*`out` = > table.put in=`out` at="set_text" value=set_text*
**`out` = > table.put in=`out` at="set_text" value=set_text**
1. `set_value` != None
*`out` = > table.put in=`out` at="set_value" value=set_value*
**`out` = > table.put in=`out` at="set_value" value=set_value**
1. `set_attr` != None
*`out` = > table.put in=`out` at="set_attr" value=set_attr*
**`out` = > table.put in=`out` at="set_attr" value=set_attr**
1. `set_class` != None
*`out` = > table.put in=`out` at="set_class" value=set_class*
**`out` = > table.put in=`out` at="set_class" value=set_class**
1. `toggle_class` != None
*`out` = > table.put in=`out` at="toggle_class" value=toggle_class*
**`out` = > table.put in=`out` at="toggle_class" value=toggle_class**
1. `set_style` != None
*`out` = > table.put in=`out` at="set_style" value=set_style*
**`out` = > table.put in=`out` at="set_style" value=set_style**
1. `set_html` != None
*`out` = > table.put in=`out` at="set_html" value=set_html*
**`out` = > table.put in=`out` at="set_html" value=set_html**
1. `render_list` != None
*`out` = > table.put in=`out` at="render_list" value=render_list*
**`out` = > table.put in=`out` at="render_list" value=render_list**
1. `navigate` != None
*`out` = > table.put in=`out` at="navigate" value=navigate*
**`out` = > table.put in=`out` at="navigate" value=navigate**
1. `storage` != None
*`out` = > table.put in=`out` at="storage" value=storage*
**`out` = > table.put in=`out` at="storage" value=storage**
1. `ws` != None
*`out` = > table.put in=`out` at="ws" value=ws*
**`out` = > table.put in=`out` at="ws" value=ws**
1. `fetch` != None
*`out` = > table.put in=`out` at="fetch" value=fetch*
**`out` = > table.put in=`out` at="fetch" value=fetch**
1. `fetch_all` != None
*`out` = > table.put in=`out` at="fetch_all" value=fetch_all*
**`out` = > table.put in=`out` at="fetch_all" value=fetch_all**
1. `after` != None
*`out` = > table.put in=`out` at="after" value=after*
**`out` = > table.put in=`out` at="after" value=after**
1. `interval` != None
*`out` = > table.put in=`out` at="interval" value=interval*
**`out` = > table.put in=`out` at="interval" value=interval**
1. `clear_interval` != None
*`out` = > table.put in=`out` at="clear_interval" value=clear_interval*
**`out` = > table.put in=`out` at="clear_interval" value=clear_interval**
1. `focus` != None
*`out` = > table.put in=`out` at="focus" value=focus*
**`out` = > table.put in=`out` at="focus" value=focus**
1. `blur` != None
*`out` = > table.put in=`out` at="blur" value=blur*
**`out` = > table.put in=`out` at="blur" value=blur**
1. `scroll_into` != None
*`out` = > table.put in=`out` at="scroll_into" value=scroll_into*
**`out` = > table.put in=`out` at="scroll_into" value=scroll_into**
1. `canvas` != None
*`out` = > table.put in=`out` at="canvas" value=canvas*
**`out` = > table.put in=`out` at="canvas" value=canvas**
1. `audio` != None
*`out` = > table.put in=`out` at="audio" value=audio*
**`out` = > table.put in=`out` at="audio" value=audio**
1. `read_file` != None
*`out` = > table.put in=`out` at="read_file" value=read_file*
**`out` = > table.put in=`out` at="read_file" value=read_file**
1. `observe` != None
*`out` = > table.put in=`out` at="observe" value=observe*
**`out` = > table.put in=`out` at="observe" value=observe**
1. `unobserve` != None
*`out` = > table.put in=`out` at="unobserve" value=unobserve*
**`out` = > table.put in=`out` at="unobserve" value=unobserve**
1. `wire` != None
*`out` = > table.put in=`out` at="wire" value=wire*
**out**
**`out` = > table.put in=`out` at="wire" value=wire**
*out*
## list_html
+ `sel`
@@ -175,10 +175,10 @@ Merge browser effect keys into one return map (omit `None`). Route E/F effects i
Build a `render_list` effect: `{ render_list: { sel: { tag, items } } }`.
*`spec` = > table.put in=None at="tag" value=tag*
*`spec` = > table.put in=`spec` at="items" value=items*
*`m` = > table.put in=None at=sel value=spec*
**> table.put in=None at="render_list" value=m**
**`spec` = > table.put in=None at="tag" value=tag**
**`spec` = > table.put in=`spec` at="items" value=items**
**`m` = > table.put in=None at=sel value=spec**
*> table.put in=None at="render_list" value=m*
# page
+ `title`="Marqdo Web"
@@ -188,31 +188,31 @@ Build a `render_list` effect: `{ render_list: { sel: { tag, items } } }`.
+ `asset_version`=None
> ensure_plugin
**> web_page_new title=`title` intro=`intro` shell_css=`shell_css` layout=`layout` asset_version=`asset_version`**
*> web_page_new title=`title` intro=`intro` shell_css=`shell_css` layout=`layout` asset_version=`asset_version`*
## shell_css
+ `mode`=full
Framework shell CSS mode for this page: `full` (default), `minimal` (vars only), or `off`/`none`.
*`out` = > table.put in=`self` at="shell_css" value=mode*
**out**
**`out` = > table.put in=`self` at="shell_css" value=mode**
*out*
## layout
+ `layout`=sidebar
Page chrome layout: `sidebar` (default when a side slot exists), `stacked` (single column; no `has-sidebar` grid), `bare` (main only), or `rail`.
*`out` = > table.put in=`self` at="layout" value=layout*
**out**
**`out` = > table.put in=`self` at="layout" value=layout**
*out*
## asset_version
+ `version`=""
Default `?v=` bump for head scripts/styles that omit a per-row `version` column.
*`out` = > table.put in=`self` at="asset_version" value=version*
**out**
**`out` = > table.put in=`self` at="asset_version" value=version**
*out*
## compose_components
+ `components`
@@ -221,14 +221,14 @@ Assemble nav / sidebar / footer from a page table (`|组件|样式|` or `|src|st
Nav bind tables may include optional `媒体`/`media` (responsive show) and `当`/`when`
(`auth` / `guest` / `hide`) columns — see C4 conditional nav.
**> web_compose_components page=`self` components=`components`**
*> web_compose_components page=`self` components=`components`*
## compose_main
+ `main`
Assemble main from a bind table (`|属性|值|样式|` or `|front|back|css|`).
**> web_compose_main page=`self` main=`main`**
*> web_compose_main page=`self` main=`main`*
## query
+ `query`
@@ -236,14 +236,14 @@ Assemble main from a bind table (`|属性|值|样式|` or `|front|back|css|`).
Attach a DB where-condition map for the main bind. Values may contain `{param}`
placeholders that are resolved from dynamic-route params (e.g. `/post/{slug}`).
**> web_page_query page=`self` query=`query`**
*> web_page_query page=`self` query=`query`*
## order
+ `order`
Set a default `ORDER BY` for the main bind (e.g. `-created_at` for newest first).
**> web_page_order page=`self` order=`order`**
*> web_page_order page=`self` order=`order`*
## link_prefix
+ `prefix`
@@ -251,16 +251,16 @@ Set a default `ORDER BY` for the main bind (e.g. `-created_at` for newest first)
Prefix for card links in the main bind (default `/post/`). Cards whose bind has
an `href`/`链接` field become `<a href="{prefix}{href}">`.
**> web_page_link_prefix page=`self` prefix=`prefix`**
*> web_page_link_prefix page=`self` prefix=`prefix`*
## css
+ `css`
Append a **raw** CSS string to the page's stylesheet (`styles_css`). Skips table-cell
Append a *raw* CSS string to the page's stylesheet (`styles_css`). Skips table-cell
expression evaluation — use for themes with `/`, `@keyframes`, or long media queries.
Hand-written theme alongside the assembled shell; or link `static/theme.css` via `head`.
**> web_page_css page=`self` css=`css`**
*> web_page_css page=`self` css=`css`*
## detail
+ `detail`=True
@@ -268,7 +268,7 @@ Hand-written theme alongside the assembled shell; or link `static/theme.css` via
Render the main bind's first row as a full article (title/meta/tags/body) instead
of a list of cards. Set on the dynamic post page so `/post/{slug}` shows one post.
**> web_page_detail page=`self` detail=`detail`**
*> web_page_detail page=`self` detail=`detail`*
## chrome
+ `nav_html`=""
@@ -277,28 +277,28 @@ of a list of cards. Set on the dynamic post page so `/post/{slug}` shows one pos
Override default header/footer list chrome with raw HTML (site navbar / footer). Optional `body_class` is appended to `<body class>`.
**> web_page_chrome page=`self` nav_html=`nav_html` footer_html=`footer_html` body_class=`body_class`**
*> web_page_chrome page=`self` nav_html=`nav_html` footer_html=`footer_html` body_class=`body_class`*
## meta
+ `meta`
SEO / OpenGraph metadata as a data table (`|key|value|`). Keys such as `title`, `description`, `canonical`, `og:type` become `<head>` tags at render time. Special keys `icon` / `favicon` / `apple-touch-icon` emit `<link rel="…">` (not `<meta name>`).
**> web_page_meta page=`self` meta=`meta`**
*> web_page_meta page=`self` meta=`meta`*
## head
+ `table`
Assemble `<head>` resources from a GFM table (`|rel|href|type|sizes|media|as|crossorigin|defer|async|version|` or ZH `|关系|地址|…|推迟|异步|版本|`). `rel=script` / `module` become `<script>`; other rows become `<link>`. Classic scripts emit `defer` / `async` only when those columns are true (compat: missing `defer` stays synchronous). Non-empty `version` appends `?v=`; else page/app `asset_version` is used. Merges with any existing `head` on the page.
**> web_page_head page=`self` table=`table`**
*> web_page_head page=`self` table=`table`*
## images
+ `table`
Assemble an image table (`|src|alt|title|class|href|width|height|loading|caption|`) into HTML and attach it as `images_html` (rendered in main before intro). Same table shape as module-level `make_images`.
**> web_page_images page=`self` table=`table`**
*> web_page_images page=`self` table=`table`*
## paginate
+ `offset`=0
@@ -307,16 +307,16 @@ Assemble an image table (`|src|alt|title|class|href|width|height|loading|caption
List pagination for the main bind: sets DB `limit`/`offset` and renders previous/next navigation.
**> web_page_paginate page=`self` offset=`offset` limit=`limit` path=`path`**
*> web_page_paginate page=`self` offset=`offset` limit=`limit` path=`path`*
## compose_form
+ `form`
+ `id`
+ `target`=None
Embed a form into the page main slot. Optional `target` / `form_slot` (CSS id, e.g. `#qd-note-form-mount`) injects the form **inside** that element in `intro` HTML instead of a sibling `.site-form` after `.main-intro` (GAP-11). Missing mount falls back to sibling. `listen` auto-registers `GET|POST /_form/{id}` from page/route forms (optional `app.mount_form`).
Embed a form into the page main slot. Optional `target` / `form_slot` (CSS id, e.g. `#qd-note-form-mount`) injects the form inside that element in `intro` HTML instead of a sibling `.site-form` after `.main-intro` (GAP-11). Missing mount falls back to sibling. `listen` auto-registers `GET|POST /_form/{id}` from page/route forms (optional `app.mount_form`).
**> web_compose_form page=`self` form=`form` id=`id` target=`target`**
*> web_compose_form page=`self` form=`form` id=`id` target=`target`*
## render
+ `db`=None
@@ -324,24 +324,24 @@ Embed a form into the page main slot. Optional `target` / `form_slot` (CSS id, e
Offline HTML for tests / previews.
1. `db`
*url = db[^url]*
**> web_render page=`self` url=`url`**
**url = db[^url]**
*> web_render page=`self` url=`url`*
2. *
**> web_render page=`self`**
*> web_render page=`self`*
# style
+ `name`=""
Style tables live as `##` exports in site style modules; compose resolves them by path.
**self**
*self*
## process
+ `style`=None
+ `name`=None
+ `path`=None
**self**
*self*
# db
+ `url`="sqlite:site.db"
@@ -349,7 +349,7 @@ Style tables live as `##` exports in site style modules; compose resolves them b
Open a database handle. URL schemes: `sqlite:path` (default), `postgres://…` / `postgresql://…` (same CRUD methods).
> ensure_plugin
**> web_db_new url=`url`**
*> web_db_new url=`url`*
## init
+ `name`
@@ -357,16 +357,16 @@ Open a database handle. URL schemes: `sqlite:path` (default), `postgres://…` /
Create a table from a schema table. Optional columns: `唯一`/`unique`, `索引`/`index` (creates UNIQUE / INDEX), `外键`/`fk`/`references` (e.g. `posts.id` or `posts(id)`). Columns named `created_at` / `updated_at` are filled automatically on insert/update when present.
*url = self[^url]*
**> web_db_init url=`url` name=`name` fields=`fields`**
**url = self[^url]**
*> web_db_init url=`url` name=`name` fields=`fields`*
## insert
+ `table`
+ `rows`
+ `txn`=None
*url = self[^url]*
**> web_db_insert url=`url` table=`table` rows=`rows` txn=`txn`**
**url = self[^url]**
*> web_db_insert url=`url` table=`table` rows=`rows` txn=`txn`*
## select
+ `table`
@@ -377,9 +377,9 @@ Create a table from a schema table. Optional columns: `唯一`/`unique`, `索引
Simple filters: one-row map of column→value (AND `=`), or rows `|字段|操作|值|` (`=` `!=` `>` `>=` `<` `<=` `like` `in` `between` `is null`; add `|或|` = `是` to join a row with `OR`). `order` is a column name with optional `-` prefix for descending (`"created_at"`, `"-created_at"`), comma-separated for multiple keys. Pass `txn` to read inside an open transaction. For pages (with a total), use `paginate`.
*url = self[^url]*
*r = > web_db_select url=`url` table=`table` where=`where` limit=`limit` order=`order` offset=None txn=`txn`*
**r[^rows]**
**url = self[^url]**
**r = > web_db_select url=`url` table=`table` where=`where` limit=`limit` order=`order` offset=None txn=`txn`**
*r[^rows]*
## paginate
+ `table`
@@ -391,16 +391,16 @@ Simple filters: one-row map of column→value (AND `=`), or rows `|字段|操作
Like `select` but returns `{ rows, total }` — the total counts rows matching `where` regardless of `limit`/`跳过`, so you can render `上一页 / 下一页`. Set `跳过` to the number of rows to skip (e.g. page 2 with 10 per page ⇒ `跳过`=10).
*url = self[^url]*
**> web_db_select url=`url` table=`table` where=`where` limit=`limit` order=`order` offset=`跳过` txn=`txn`**
**url = self[^url]**
*> web_db_select url=`url` table=`table` where=`where` limit=`limit` order=`order` offset=`跳过` txn=`txn`*
## get
+ `table`
+ `id`
+ `txn`=None
*url = self[^url]*
**> web_db_get url=`url` table=`table` id=`id` txn=`txn`**
**url = self[^url]**
*> web_db_get url=`url` table=`table` id=`id` txn=`txn`*
## update
+ `table`
@@ -408,24 +408,24 @@ Like `select` but returns `{ rows, total }` — the total counts rows matching `
+ `row`
+ `txn`=None
*url = self[^url]*
**> web_db_update url=`url` table=`table` id=`id` row=`row` txn=`txn`**
**url = self[^url]**
*> web_db_update url=`url` table=`table` id=`id` row=`row` txn=`txn`*
## delete
+ `table`
+ `id`
+ `txn`=None
*url = self[^url]*
**> web_db_delete url=`url` table=`table` id=`id` txn=`txn`**
**url = self[^url]**
*> web_db_delete url=`url` table=`table` id=`id` txn=`txn`*
## exec
+ `sql`
+ `args`=None
+ `txn`=None
*url = self[^url]*
**> web_db_exec url=`url` sql=`sql` args=`args` txn=`txn`**
**url = self[^url]**
*> web_db_exec url=`url` sql=`sql` args=`args` txn=`txn`*
## query
+ `sql`
@@ -434,8 +434,8 @@ Like `select` but returns `{ rows, total }` — the total counts rows matching `
Run bare SQL and return the result set — count / join / group / subqueries. Returns `{ rows, count }`.
*url = self[^url]*
**> web_db_query url=`url` sql=`sql` args=`args` txn=`txn`**
**url = self[^url]**
*> web_db_query url=`url` sql=`sql` args=`args` txn=`txn`*
## count
+ `table`
@@ -444,17 +444,17 @@ Run bare SQL and return the result set — count / join / group / subqueries. Re
Count rows matching a `where` filter (same syntax as `select`). Returns a number.
*url = self[^url]*
*r = > web_db_count url=`url` table=`table` where=`where` txn=`txn`*
**r[^count]**
**url = self[^url]**
**r = > web_db_count url=`url` table=`table` where=`where` txn=`txn`**
*r[^count]*
## migrate
+ `steps`
Apply versioned SQL migrations. `steps` is a `|version|sql|` / `|版本|SQL|` table. Applied versions are recorded in `_marqdo_migrations`. Re-running is a no-op for already-applied versions. SQLite only.
*url = self[^url]*
**> web_db_migrate url=`url` steps=`steps`**
**url = self[^url]**
*> web_db_migrate url=`url` steps=`steps`*
## fts
+ `table`
@@ -463,8 +463,8 @@ Apply versioned SQL migrations. `steps` is a `|version|sql|` / `|版本|SQL|` ta
Create an FTS5 index on `table` for the listed content columns (CSV string or list). Default FTS name is `{table}_fts`. Keeps the index in sync via triggers. Requires integer `id` PK. SQLite only.
*url = self[^url]*
**> web_db_fts_create url=`url` table=`table` columns=`columns` name=`name`**
**url = self[^url]**
*> web_db_fts_create url=`url` table=`table` columns=`columns` name=`name`*
## search
+ `table`
@@ -474,8 +474,8 @@ Create an FTS5 index on `table` for the listed content columns (CSV string or li
Full-text search (`MATCH`) against the FTS5 index from `fts`. Returns `{ rows, count }` with a `rank` column (bm25). SQLite only.
*url = self[^url]*
**> web_db_search url=`url` table=`table` q=`q` limit=`limit` name=`name`**
**url = self[^url]**
*> web_db_search url=`url` table=`table` q=`q` limit=`limit` name=`name`*
## 事务
@@ -483,8 +483,8 @@ Begin a transaction: borrows the pooled connection exclusively and returns a
`txn` handle. Write inside it, then `提交` (commit) or `回滚` (roll back).
Every statement runs on the same connection, so a batch is atomic.
*url = self[^url]*
**> web_db_begin url=`url`**
**url = self[^url]**
*> web_db_begin url=`url`*
# txn
+ `txn`
@@ -493,15 +493,15 @@ Every statement runs on the same connection, so a batch is atomic.
A transaction handle from `db.事务`. All CRUD here runs on the transaction's
connection; finish with `提交` or `回滚`.
**self**
*self*
## insert
+ `table`
+ `rows`
*url = self[^url]*
*txn = self[^txn]*
**> web_db_insert url=`url` table=`table` rows=`rows` txn=`txn`**
**url = self[^url]**
**txn = self[^txn]**
*> web_db_insert url=`url` table=`table` rows=`rows` txn=`txn`*
## select
+ `table`
@@ -511,57 +511,57 @@ connection; finish with `提交` or `回滚`.
Same filters as `db.select`; runs inside the transaction.
*url = self[^url]*
*txn = self[^txn]*
*r = > web_db_select url=`url` table=`table` where=`where` limit=`limit` order=`order` offset=None txn=`txn`*
**r[^rows]**
**url = self[^url]**
**txn = self[^txn]**
**r = > web_db_select url=`url` table=`table` where=`where` limit=`limit` order=`order` offset=None txn=`txn`**
*r[^rows]*
## get
+ `table`
+ `id`
*url = self[^url]*
*txn = self[^txn]*
**> web_db_get url=`url` table=`table` id=`id` txn=`txn`**
**url = self[^url]**
**txn = self[^txn]**
*> web_db_get url=`url` table=`table` id=`id` txn=`txn`*
## update
+ `table`
+ `id`
+ `row`
*url = self[^url]*
*txn = self[^txn]*
**> web_db_update url=`url` table=`table` id=`id` row=`row` txn=`txn`**
**url = self[^url]**
**txn = self[^txn]**
*> web_db_update url=`url` table=`table` id=`id` row=`row` txn=`txn`*
## delete
+ `table`
+ `id`
*url = self[^url]*
*txn = self[^txn]*
**> web_db_delete url=`url` table=`table` id=`id` txn=`txn`**
**url = self[^url]**
**txn = self[^txn]**
*> web_db_delete url=`url` table=`table` id=`id` txn=`txn`*
## exec
+ `sql`
+ `args`=None
*url = self[^url]*
*txn = self[^txn]*
**> web_db_exec url=`url` sql=`sql` args=`args` txn=`txn`**
**url = self[^url]**
**txn = self[^txn]**
*> web_db_exec url=`url` sql=`sql` args=`args` txn=`txn`*
## 提交
Commit the transaction and return its connection to the pool.
*txn = self[^txn]*
**> web_db_commit txn=`txn`**
**txn = self[^txn]**
*> web_db_commit txn=`txn`*
## 回滚
Roll the transaction back (undo every write) and return its connection.
*txn = self[^txn]*
**> web_db_rollback txn=`txn`**
**txn = self[^txn]**
*> web_db_rollback txn=`txn`*
# form
+ `table`=None
@@ -571,37 +571,37 @@ Roll the transaction back (undo every write) and return its connection.
Field table + rules table; submit writes through `# db`.
> ensure_plugin
**> web_form_new table=`table` action=`action` id=`id`**
*> web_form_new table=`table` action=`action` id=`id`*
## fields
+ `fields`
**> web_form_fields form=`self` fields=`fields`**
*> web_form_fields form=`self` fields=`fields`*
## rules
+ `rules`
**> web_form_rules form=`self` rules=`rules`**
*> web_form_rules form=`self` rules=`rules`*
## validate
+ `rules`=None
+ `data`
**> web_form_validate form=`self` rules=`rules` data=`data`**
*> web_form_validate form=`self` rules=`rules` data=`data`*
## render
+ `id`=form
+ `data`=None
+ `errors`=None
**> web_form_render form=`self` id=`id` data=`data` errors=`errors`**
*> web_form_render form=`self` id=`id` data=`data` errors=`errors`*
## submit
+ `data`
+ `db`
*url = db[^url]*
**> web_form_submit form=`self` data=`data` url=`url`**
**url = db[^url]**
*> web_form_submit form=`self` data=`data` url=`url`*
# app
+ `page`
@@ -616,10 +616,10 @@ Field table + rules table; submit writes through `# db`.
+ `layout`=None
+ `asset_version`=None
Construct an app. `admin=True` mounts the built-in CRUD UI under `admin_prefix` (default `/admin`). When `admin=False`, that prefix is **not** reserved — you may `route` your own pages there. Optional `login_redirect` / `logout_redirect` override post-auth landing. Optional `shell_css` / `layout` / `asset_version` become defaults for pages that do not set their own (see `page.shell_css` / `page.layout` / `page.asset_version`).
Construct an app. `admin=True` mounts the built-in CRUD UI under `admin_prefix` (default `/admin`). When `admin=False`, that prefix is not reserved — you may `route` your own pages there. Optional `login_redirect` / `logout_redirect` override post-auth landing. Optional `shell_css` / `layout` / `asset_version` become defaults for pages that do not set their own (see `page.shell_css` / `page.layout` / `page.asset_version`).
> ensure_plugin
**> web_app_new page=`page` db=`db` admin=`admin` host=`host` port=`port` admin_prefix=`admin_prefix` login_redirect=`login_redirect` logout_redirect=`logout_redirect` shell_css=`shell_css` layout=`layout` asset_version=`asset_version`**
*> web_app_new page=`page` db=`db` admin=`admin` host=`host` port=`port` admin_prefix=`admin_prefix` login_redirect=`login_redirect` logout_redirect=`logout_redirect` shell_css=`shell_css` layout=`layout` asset_version=`asset_version`*
## route
+ `path`
@@ -627,7 +627,7 @@ Construct an app. `admin=True` mounts the built-in CRUD UI under `admin_prefix`
Mount an assembled page at `path` (e.g. `/about`). `/` is the home `page=`.
**> web_app_route app=`self` path=`path` page=`page`**
*> web_app_route app=`self` path=`path` page=`page`*
## mount_form
+ `id`
@@ -635,7 +635,7 @@ Mount an assembled page at `path` (e.g. `/about`). `/` is the home `page=`.
Register `GET|POST /_form/{id}` for listen when the form is not already embedded via `page.compose_form`.
**> web_app_mount_form app=`self` id=`id` form=`form`**
*> web_app_mount_form app=`self` id=`id` form=`form`*
## static
+ `dir`
@@ -643,7 +643,7 @@ Register `GET|POST /_form/{id}` for listen when the form is not already embedded
Serve files from `dir` under `mount` (default `/static`). Path is resolved from the process working directory at listen time. If `dir` contains `favicon.ico` / `favicon.png` / `favicon.svg` and `icons` was not set, listen also serves `GET /favicon.ico` and injects a default `<link rel="icon">` on every page.
**> web_app_static app=`self` dir=`dir` mount=`mount`**
*> web_app_static app=`self` dir=`dir` mount=`mount`*
## icons
+ `table`
@@ -653,7 +653,7 @@ Register site icons from a GFM table (`|path|rel|type|sizes|url|` or ZH
`/favicon.ico` for `.ico` icons, else `/icons/{filename}`), and injects matching
`<link>` tags into every page via `site_head`. See [web-assets-and-images.md](../../doc/design/web-assets-and-images.md).
**> web_app_icons app=`self` table=`table`**
*> web_app_icons app=`self` table=`table`*
## configure
+ `cors`=None
@@ -670,7 +670,7 @@ Each capability is declared as a data table and assembled at listen time. The `c
Tables stay as data; `configure` assembles them. 配置即数据、装配即函数.
**> web_app_middleware app=`self` cors=`cors` security=`security` compress=`compress` body_limit=`body_limit` json_routes=`json` access_log=`access_log` cache_control=`cache_control` proxy=`proxy` invoke=`invoke`**
*> web_app_middleware app=`self` cors=`cors` security=`security` compress=`compress` body_limit=`body_limit` json_routes=`json` access_log=`access_log` cache_control=`cache_control` proxy=`proxy` invoke=`invoke`*
## proxy
+ `path`
@@ -683,7 +683,7 @@ Tables stay as data; `configure` assembles them. 配置即数据、装配即函
Same-origin reverse proxy to an upstream HTTP(S) URL. When `stream` is True (default), the response body — including `text/event-stream` SSE — is piped without buffering the full payload, and responses include `Cache-Control: no-cache, no-transform` plus `X-Accel-Buffering: no` for Nginx/CDN. `upstream` may contain `$ENV` / `${ENV}`. `headers_from_env` is `ENV=Header-Name` (comma-separated); secrets stay on the server. Prefer this over a side Python LLM proxy.
**> web_app_proxy app=`self` path=`path` upstream=`upstream` stream=`stream` strip_prefix=`strip_prefix` methods=`methods` headers_from_env=`headers_from_env` timeout_ms=`timeout_ms`**
*> web_app_proxy app=`self` path=`path` upstream=`upstream` stream=`stream` strip_prefix=`strip_prefix` methods=`methods` headers_from_env=`headers_from_env` timeout_ms=`timeout_ms`*
## invoke
+ `path`
@@ -694,13 +694,13 @@ Same-origin reverse proxy to an upstream HTTP(S) URL. When `stream` is True (def
Call a user `##` on each HTTP request. `fn` must be `lib.member` imported on the entry module. `body` is `json` / `form` / `query` / `raw`; object keys map to named params (plus `payload`). Returns JSON by default.
**> web_app_invoke app=`self` path=`path` method=`method` fn=`fn` body=`body` return=`return`**
*> web_app_invoke app=`self` path=`path` method=`method` fn=`fn` body=`body` return=`return`*
## listen
Serve `/`, routed pages, `/_part/{id}` (home) and `{path}/_part/{id}` (routes), `/_form/{id}` (from mounts + page embeds), optional `/static` (or custom mount), optional `/admin`, upload/download/WebSocket/RSS/sitemap/robots routes, redirects, proxy/invoke routes, and a custom 404 fallback. Production HTTPS should terminate at a reverse proxy; set `cookie_secure=True` when serving over TLS.
**> web_listen app=`self`**
*> web_listen app=`self`*
## route_ws
+ `path`
@@ -709,7 +709,7 @@ Serve `/`, routed pages, `/_part/{id}` (home) and `{path}/_part/{id}` (routes),
Register a WebSocket endpoint at `path` (e.g. `/live`). `mode` is `echo` (default), `broadcast` (fan-out text to all sockets on this path), or `drain`. Legacy `echo=False` maps to `drain`. Connect from a client with `web.ws.connect`.
**> web_app_route_ws app=`self` path=`path` echo=`echo` mode=`mode`**
*> web_app_route_ws app=`self` path=`path` echo=`echo` mode=`mode`*
## auth
+ `users`
@@ -719,9 +719,9 @@ Register a WebSocket endpoint at `path` (e.g. `/live`). `mode` is `echo` (defaul
+ `logout_redirect`=None
+ `login_path`=None
Keep the app's `admin=True`, and gate `{admin_prefix}` (segment-boundary prefix) behind a login page (default `/admin`). Unauthenticated requests **redirect** to `login_path` (default `{admin_prefix}/login`, auto-excluded). Does **not** match `/admin-publish`-style siblings.
Keep the app's `admin=True`, and gate `{admin_prefix}` (segment-boundary prefix) behind a login page (default `/admin`). Unauthenticated requests redirect to `login_path` (default `{admin_prefix}/login`, auto-excluded). Does not match `/admin-publish`-style siblings.
**> web_app_auth app=`self` users=`users` session_ttl=`session_ttl` admin_prefix=`admin_prefix` login_redirect=`login_redirect` logout_redirect=`logout_redirect` login_path=`login_path`**
*> web_app_auth app=`self` users=`users` session_ttl=`session_ttl` admin_prefix=`admin_prefix` login_redirect=`login_redirect` logout_redirect=`logout_redirect` login_path=`login_path`*
## gate
+ `path`
@@ -732,7 +732,7 @@ Keep the app's `admin=True`, and gate `{admin_prefix}` (segment-boundary prefix)
Require one of `roles` (CSV) for `path`. `match=prefix` uses segment boundaries; `exact` is equality. Trailing `*` on `path` means prefix. `on_deny=redirect` sends visitors to `login_path` (with `?next=`); `forbid` returns 403. `exclude` is CSV or list of open paths.
**> web_app_gate app=`self` path=`path` roles=`roles` match=`match` on_deny=`on_deny` exclude=`exclude`**
*> web_app_gate app=`self` path=`path` roles=`roles` match=`match` on_deny=`on_deny` exclude=`exclude`*
## gallery
+ `path`=/gallery
@@ -743,7 +743,7 @@ Require one of `roles` (CSV) for `path`. `match=prefix` uses segment boundaries;
Serve an HTML media gallery listing objects under `prefix` in `storage`, linking through `download_base`.
**> web_app_gallery app=`self` path=`path` storage=`storage` prefix=`prefix` title=`title` download_base=`download_base`**
*> web_app_gallery app=`self` path=`path` storage=`storage` prefix=`prefix` title=`title` download_base=`download_base`*
## route_rss
+ `path`
@@ -756,7 +756,7 @@ Serve an HTML media gallery listing objects under `prefix` in `storage`, linking
Register an RSS 2.0 feed at `path` (e.g. `/feed.xml`) backed by a DB table.
**> web_app_route_rss app=`self` path=`path` table=`table` limit=`limit` order=`order` title=`title` link=`link` description=`description`**
*> web_app_route_rss app=`self` path=`path` table=`table` limit=`limit` order=`order` title=`title` link=`link` description=`description`*
## redirect
+ `from`
@@ -765,7 +765,7 @@ Register an RSS 2.0 feed at `path` (e.g. `/feed.xml`) backed by a DB table.
Register a redirect from `from` to `to`. `permanent=True` issues HTTP 301; otherwise 307.
**> web_app_redirect app=`self` from=`from` to=`to` permanent=`permanent`**
*> web_app_redirect app=`self` from=`from` to=`to` permanent=`permanent`*
## error_page
+ `status`=404
@@ -773,7 +773,7 @@ Register a redirect from `from` to `to`. `permanent=True` issues HTTP 301; other
Bind an assembled page for HTTP `404` or `500` responses.
**> web_app_error_page app=`self` status=`status` page=`page`**
*> web_app_error_page app=`self` status=`status` page=`page`*
## sitemap
+ `path`=/sitemap.xml
@@ -785,7 +785,7 @@ Bind an assembled page for HTTP `404` or `500` responses.
Serve `sitemap.xml`. Prefer `table` + `loc` column from the DB, or pass an `items` table with `loc`/`路径` rows.
**> web_app_sitemap app=`self` path=`path` base=`base` table=`table` loc=`loc` limit=`limit` items=`items`**
*> web_app_sitemap app=`self` path=`path` base=`base` table=`table` loc=`loc` limit=`limit` items=`items`*
## robots
+ `body`=None
@@ -793,7 +793,7 @@ Serve `sitemap.xml`. Prefer `table` + `loc` column from the DB, or pass an `item
Serve `/robots.txt`. Omit `body` to emit a default Allow-all file, optionally with a `Sitemap:` line.
**> web_app_robots app=`self` body=`body` sitemap=`sitemap`**
*> web_app_robots app=`self` body=`body` sitemap=`sitemap`*
## upload
+ `path`=/_upload
@@ -805,7 +805,7 @@ Serve `/robots.txt`. Omit `body` to emit a default Allow-all file, optionally wi
Mount `POST path` for multipart file upload. `storage` is a `# storage` handle or `file:…` / `s3://…` URL. Optional `types` is a `|type|ext|` / `|类型|扩展名|` allowlist (or a MIME CSV string). Success returns JSON `{ok,key,size,content_type}`.
**> web_app_upload app=`self` path=`path` field=`field` storage=`storage` prefix=`prefix` max_bytes=`max_bytes` types=`types`**
*> web_app_upload app=`self` path=`path` field=`field` storage=`storage` prefix=`prefix` max_bytes=`max_bytes` types=`types`*
## download
+ `path`=/_media/{*key}
@@ -814,7 +814,7 @@ Mount `POST path` for multipart file upload. `storage` is a `# storage` handle o
Mount `GET path` to stream an object. Path must capture `key` (use `{*key}` for nested keys). `disposition` is `attachment` or `inline`.
**> web_app_download app=`self` path=`path` storage=`storage` disposition=`disposition`**
*> web_app_download app=`self` path=`path` storage=`storage` disposition=`disposition`*
# auth
+ `users`
@@ -823,7 +823,7 @@ Mount `GET path` to stream an object. Path must capture `key` (use `{*key}` for
Session/auth helper. Constructs a config object; `login` validates against the users table. To gate `/admin` on this app, use `app.auth users=…` instead.
> ensure_plugin
**> web_auth_new users=`users` session_ttl=`session_ttl`**
*> web_auth_new users=`users` session_ttl=`session_ttl`*
## login
+ `username`
@@ -831,30 +831,30 @@ Session/auth helper. Constructs a config object; `login` validates against the u
Validate credentials against the users table and create a session. Returns `{ok, session_id, username, role}`.
*users = self[^users]*
*ttl = self[^session_ttl]*
**> web_auth_login username=`username` password=`password` users=`users` session_ttl=`ttl`**
**users = self[^users]**
**ttl = self[^session_ttl]**
*> web_auth_login username=`username` password=`password` users=`users` session_ttl=`ttl`*
## check
+ `session_id`
Returns `{ok, username, role}` when the session is valid.
**> web_auth_check session_id=`session_id`**
*> web_auth_check session_id=`session_id`*
## logout
+ `session_id`
Destroy the session.
**> web_auth_logout session_id=`session_id`**
*> web_auth_logout session_id=`session_id`*
## hash_password
+ `password`
Hash a plaintext password for storage in admin user tables (argon2id). Store the returned `hash` in the `password` column; login verifies automatically.
**> web_password_hash password=`password`**
*> web_password_hash password=`password`*
# cache
+ `url`="memory:"
@@ -862,13 +862,13 @@ Hash a plaintext password for storage in admin user tables (argon2id). Store the
Key–value cache. Use `memory:` for in-process (tests / single process) or `redis://host:6379/0` for Redis.
> ensure_plugin
**> web_cache_new url=`url`**
*> web_cache_new url=`url`*
## get
+ `key`
*url = self[^url]*
**> web_cache_get url=`url` key=`key`**
**url = self[^url]**
*> web_cache_get url=`url` key=`key`*
## set
+ `key`
@@ -877,26 +877,26 @@ Key–value cache. Use `memory:` for in-process (tests / single process) or `red
Optional `ttl` is seconds until expiry.
*url = self[^url]*
**> web_cache_set url=`url` key=`key` value=`value` ttl=`ttl`**
**url = self[^url]**
*> web_cache_set url=`url` key=`key` value=`value` ttl=`ttl`*
## del
+ `key`
*url = self[^url]*
**> web_cache_del url=`url` key=`key`**
**url = self[^url]**
*> web_cache_del url=`url` key=`key`*
## exists
+ `key`
*url = self[^url]*
**> web_cache_exists url=`url` key=`key`**
**url = self[^url]**
*> web_cache_exists url=`url` key=`key`*
## ttl
+ `key`
*url = self[^url]*
**> web_cache_ttl url=`url` key=`key`**
**url = self[^url]**
*> web_cache_ttl url=`url` key=`key`*
# storage
+ `url`="file:data/blobs"
@@ -904,7 +904,7 @@ Optional `ttl` is seconds until expiry.
Object storage. `file:dir` stores blobs on disk (offline / gold). `s3://bucket?endpoint=http://127.0.0.1:9000&access_key=…&secret_key=…` talks to MinIO / S3.
> ensure_plugin
**> web_storage_new url=`url`**
*> web_storage_new url=`url`*
## put
+ `key`
@@ -914,26 +914,26 @@ Object storage. `file:dir` stores blobs on disk (offline / gold). `s3://bucket?e
Provide either `body` (text) or `path` (local file to upload).
*url = self[^url]*
**> web_storage_put url=`url` key=`key` body=`body` path=`path` content_type=`content_type`**
**url = self[^url]**
*> web_storage_put url=`url` key=`key` body=`body` path=`path` content_type=`content_type`*
## get
+ `key`
*url = self[^url]*
**> web_storage_get url=`url` key=`key`**
**url = self[^url]**
*> web_storage_get url=`url` key=`key`*
## delete
+ `key`
*url = self[^url]*
**> web_storage_delete url=`url` key=`key`**
**url = self[^url]**
*> web_storage_delete url=`url` key=`key`*
## list
+ `prefix`=""
*url = self[^url]*
**> web_storage_list url=`url` prefix=`prefix`**
**url = self[^url]**
*> web_storage_list url=`url` prefix=`prefix`*
# media
+ `storage`=None
@@ -941,7 +941,7 @@ Provide either `body` (text) or `path` (local file to upload).
Offline helpers for upload validation and saving into `# storage` (also used by HTTP `app.upload`).
> ensure_plugin
**> web_media_new storage=`storage`**
*> web_media_new storage=`storage`*
## validate
+ `filename`
@@ -950,7 +950,7 @@ Offline helpers for upload validation and saving into `# storage` (also used by
+ `max_bytes`=5242880
+ `types`=None
**> web_upload_validate filename=`filename` content_type=`content_type` size=`size` max_bytes=`max_bytes` types=`types`**
*> web_upload_validate filename=`filename` content_type=`content_type` size=`size` max_bytes=`max_bytes` types=`types`*
## save
+ `path`
@@ -959,12 +959,12 @@ Offline helpers for upload validation and saving into `# storage` (also used by
+ `prefix`=uploads/
+ `storage`=None
*st = storage*
**st = storage**
1. `st` == None
*st = self[^storage]*
**st = self[^storage]**
2. *
**> web_upload_save storage=`st` path=`path` key=`key` content_type=`content_type` prefix=`prefix`**
*> web_upload_save storage=`st` path=`path` key=`key` content_type=`content_type` prefix=`prefix`*
# ws
+ `timeout_sec`=30
@@ -978,7 +978,7 @@ WebSocket client helper.
|-------------|-------|
| `timeout_sec` | ws |
**out**
*out*
## connect
+ `url`
@@ -987,5 +987,5 @@ WebSocket client helper.
Single request–response: connect to `url`, send `message`, collect all server text replies, close. Returns `{ok, messages}`.
*timeout = self[^timeout_sec]*
**> web_ws_connect url=`url` message=`message` headers=`headers` timeout_sec=`timeout`**
**timeout = self[^timeout_sec]**
*> web_ws_connect url=`url` message=`message` headers=`headers` timeout_sec=`timeout`*
+186 -186
View File
@@ -10,7 +10,7 @@ import table:lib/table.mq.md
加载 ABI v2 `web` 插件。
*p = > plugin.native_path name="web"*
**p = > plugin.native_path name="web"**
1. `p`
> plugin.load path=`p`
2. *
@@ -33,7 +33,7 @@ import table:lib/table.mq.md
样式即数据、装配即函数 —— 主题模块据此把样式表拼成完整样式表。
> 确保插件
**> web_style name=`名` table=`表` strict=`严格`**
*> web_style name=`名` table=`表` strict=`严格`*
## 图片装配
+ `表`
@@ -43,7 +43,7 @@ import table:lib/table.mq.md
图片即数据、装配即函数。
> 确保插件
**> web_images table=`表`**
*> web_images table=`表`*
## 头资源装配
+ `表`
@@ -51,7 +51,7 @@ import table:lib/table.mq.md
把 Head 资源表装配成 HTML(`<link>` / `<script>`)。预览用;挂到页面请用 `页面.头装配`。
> 确保插件
**> web_head table=`表`**
*> web_head table=`表`*
## 客户端挂载
+ `桥`="/static/marqdo-bridge.js"
@@ -59,16 +59,16 @@ import table:lib/table.mq.md
+ `源`=""
+ `启动`=True
返回挂载浏览器 Marqdo(路线 C/D)的 HTML。`启动` 且 `源` 非空(客户端 `.mq.md` URL)时写入 `data-mq-wasm` / `data-mq-source-url`,官方 bridge **自动 mount**(作者零业务 JS)。
返回挂载浏览器 Marqdo(路线 C/D)的 HTML。`启动` 且 `源` 非空(客户端 `.mq.md` URL)时写入 `data-mq-wasm` / `data-mq-source-url`,官方 bridge 自动 mount(作者零业务 JS)。
请先 `marqdo wasm build -o static`,并用 `app.静态` 提供该目录。设计见 [browser-marqdo-wasm.md](../../doc/design/browser-marqdo-wasm.md) §16。
1. `启动`
1. `源` != ""
**"<script type=\"module\" src=\"" + 桥 + "\" data-mq-wasm=\"" + wasm + "\" data-mq-source-url=\"" + 源 + "\"></script>"**
*"<script type=\"module\" src=\"" + 桥 + "\" data-mq-wasm=\"" + wasm + "\" data-mq-source-url=\"" + 源 + "\"></script>"*
2. *
**"<script type=\"module\" src=\"" + 桥 + "\"></script>"**
*"<script type=\"module\" src=\"" + 桥 + "\"></script>"*
2. *
**"<script type=\"module\" src=\"" + 桥 + "\" data-mq-no-boot=\"1\"></script>"**
*"<script type=\"module\" src=\"" + 桥 + "\" data-mq-no-boot=\"1\"></script>"*
## 文本补丁
+ `选择器`
@@ -76,8 +76,8 @@ import table:lib/table.mq.md
快捷构造 `set_text` 效应表。客户端优先 `lib/浏览器` + GFM 表格。
*`m` = > table.put in=None at=选择器 value=文本*
**> table.put in=None at="set_text" value=m**
**`m` = > table.put in=None at=选择器 value=文本**
*> table.put in=None at="set_text" value=m*
## DOM补丁
+ `set_text`=None
@@ -108,58 +108,58 @@ import table:lib/table.mq.md
合并浏览器效应键(含路线 E/F)为一张返回表(跳过 `None`)。
*`out` = > table.put in=None at="_mq" value=True*
**`out` = > table.put in=None at="_mq" value=True**
1. `set_text` != None
*`out` = > table.put in=`out` at="set_text" value=set_text*
**`out` = > table.put in=`out` at="set_text" value=set_text**
1. `set_value` != None
*`out` = > table.put in=`out` at="set_value" value=set_value*
**`out` = > table.put in=`out` at="set_value" value=set_value**
1. `set_attr` != None
*`out` = > table.put in=`out` at="set_attr" value=set_attr*
**`out` = > table.put in=`out` at="set_attr" value=set_attr**
1. `set_class` != None
*`out` = > table.put in=`out` at="set_class" value=set_class*
**`out` = > table.put in=`out` at="set_class" value=set_class**
1. `toggle_class` != None
*`out` = > table.put in=`out` at="toggle_class" value=toggle_class*
**`out` = > table.put in=`out` at="toggle_class" value=toggle_class**
1. `set_style` != None
*`out` = > table.put in=`out` at="set_style" value=set_style*
**`out` = > table.put in=`out` at="set_style" value=set_style**
1. `set_html` != None
*`out` = > table.put in=`out` at="set_html" value=set_html*
**`out` = > table.put in=`out` at="set_html" value=set_html**
1. `render_list` != None
*`out` = > table.put in=`out` at="render_list" value=render_list*
**`out` = > table.put in=`out` at="render_list" value=render_list**
1. `navigate` != None
*`out` = > table.put in=`out` at="navigate" value=navigate*
**`out` = > table.put in=`out` at="navigate" value=navigate**
1. `storage` != None
*`out` = > table.put in=`out` at="storage" value=storage*
**`out` = > table.put in=`out` at="storage" value=storage**
1. `ws` != None
*`out` = > table.put in=`out` at="ws" value=ws*
**`out` = > table.put in=`out` at="ws" value=ws**
1. `fetch` != None
*`out` = > table.put in=`out` at="fetch" value=fetch*
**`out` = > table.put in=`out` at="fetch" value=fetch**
1. `fetch_all` != None
*`out` = > table.put in=`out` at="fetch_all" value=fetch_all*
**`out` = > table.put in=`out` at="fetch_all" value=fetch_all**
1. `after` != None
*`out` = > table.put in=`out` at="after" value=after*
**`out` = > table.put in=`out` at="after" value=after**
1. `interval` != None
*`out` = > table.put in=`out` at="interval" value=interval*
**`out` = > table.put in=`out` at="interval" value=interval**
1. `clear_interval` != None
*`out` = > table.put in=`out` at="clear_interval" value=clear_interval*
**`out` = > table.put in=`out` at="clear_interval" value=clear_interval**
1. `focus` != None
*`out` = > table.put in=`out` at="focus" value=focus*
**`out` = > table.put in=`out` at="focus" value=focus**
1. `blur` != None
*`out` = > table.put in=`out` at="blur" value=blur*
**`out` = > table.put in=`out` at="blur" value=blur**
1. `scroll_into` != None
*`out` = > table.put in=`out` at="scroll_into" value=scroll_into*
**`out` = > table.put in=`out` at="scroll_into" value=scroll_into**
1. `canvas` != None
*`out` = > table.put in=`out` at="canvas" value=canvas*
**`out` = > table.put in=`out` at="canvas" value=canvas**
1. `audio` != None
*`out` = > table.put in=`out` at="audio" value=audio*
**`out` = > table.put in=`out` at="audio" value=audio**
1. `read_file` != None
*`out` = > table.put in=`out` at="read_file" value=read_file*
**`out` = > table.put in=`out` at="read_file" value=read_file**
1. `observe` != None
*`out` = > table.put in=`out` at="observe" value=observe*
**`out` = > table.put in=`out` at="observe" value=observe**
1. `unobserve` != None
*`out` = > table.put in=`out` at="unobserve" value=unobserve*
**`out` = > table.put in=`out` at="unobserve" value=unobserve**
1. `wire` != None
*`out` = > table.put in=`out` at="wire" value=wire*
**out**
**`out` = > table.put in=`out` at="wire" value=wire**
*out*
## 列表HTML
+ `选择器`
@@ -168,10 +168,10 @@ import table:lib/table.mq.md
构造 `render_list` 效应。
*`spec` = > table.put in=None at="tag" value=标签*
*`spec` = > table.put in=`spec` at="items" value=项*
*`m` = > table.put in=None at=选择器 value=spec*
**> table.put in=None at="render_list" value=m**
**`spec` = > table.put in=None at="tag" value=标签**
**`spec` = > table.put in=`spec` at="items" value=项**
**`m` = > table.put in=None at=选择器 value=spec**
*> table.put in=None at="render_list" value=m*
# 页面
+ `标题`="站点"
@@ -181,76 +181,76 @@ import table:lib/table.mq.md
+ `资源版本`=None
> 确保插件
**> web_page_new title=`标题` intro=`引言` shell_css=`壳样式` layout=`布局` asset_version=`资源版本`**
*> web_page_new title=`标题` intro=`引言` shell_css=`壳样式` layout=`布局` asset_version=`资源版本`*
## 壳样式
+ `模式`=full
框架壳 CSS:`full`(默认)/ `minimal`(仅变量)/ `off`。
*`out` = > table.put in=`自` at="shell_css" value=模式*
**out**
**`out` = > table.put in=`自` at="shell_css" value=模式**
*out*
## 布局
+ `布局`=sidebar
页面壳:`sidebar`(有侧栏时默认双列)/ `stacked`(单列、不加 has-sidebar)/ `bare`(仅 main)/ `rail`。
*`out` = > table.put in=`自` at="layout" value=布局*
**out**
**`out` = > table.put in=`自` at="layout" value=布局**
*out*
## 资源版本
+ `版本`=""
为未写 `版本` 列的 head 脚本/样式统一追加 `?v=`。
*`out` = > table.put in=`自` at="asset_version" value=版本*
**out**
**`out` = > table.put in=`自` at="asset_version" value=版本**
*out*
## 组件装配
+ `组件`
**> web_compose_components page=`self` components=`组件`**
*> web_compose_components page=`self` components=`组件`*
## 主体装配
+ `主体`
**> web_compose_main page=`self` main=`主体`**
*> web_compose_main page=`self` main=`主体`*
## 查询条件
+ `条件`
为主主体绑定附加 DB 条件映射。值可含 `{参数}` 占位符,由动态路由参数替换(如 `/post/{slug}`)。
**> web_page_query page=`self` query=`条件`**
*> web_page_query page=`self` query=`条件`*
## 排序
+ `排序`
设置主主体绑定的默认 `ORDER BY`(如 `-created_at` 表示最新在前)。
**> web_page_order page=`self` order=`排序`**
*> web_page_order page=`self` order=`排序`*
## 链接前缀
+ `前缀`
卡片链接前缀(默认 `/post/`)。主体绑定中含 `链接`/`href` 字段时,卡片标题会包成 `<a href="{前缀}{值}">`。
**> web_page_link_prefix page=`self` prefix=`前缀`**
*> web_page_link_prefix page=`self` prefix=`前缀`*
## 样式
+ `样式`
把一段**原始** CSS 字符串追加到页面样式表(`styles_css`),不经表单元格表达式求值——适合含 `/`、`@keyframes` 或长 media 的主题。也可外链 `static/theme.css` 再经 `头装配`。
把一段原始 CSS 字符串追加到页面样式表(`styles_css`),不经表单元格表达式求值——适合含 `/`、`@keyframes` 或长 media 的主题。也可外链 `static/theme.css` 再经 `头装配`。
**> web_page_css page=`self` css=`样式`**
*> web_page_css page=`self` css=`样式`*
## 详情
+ `详情`=True
把主体绑定的首行渲染成完整文章(标题/日期/标签/正文)而非卡片列表。用于动态文章页 `/post/{slug}`。
**> web_page_detail page=`self` detail=`详情`**
*> web_page_detail page=`self` detail=`详情`*
## 壳HTML
+ `导航`=""
@@ -259,28 +259,28 @@ import table:lib/table.mq.md
覆盖默认 `<header>` / `<footer>` 列表渲染,改为原站级原始 HTML(如 Django navbar / site_footer)。可选 `体类` 追加到 `<body class>`。
**> web_page_chrome page=`self` nav_html=`导航` footer_html=`页脚` body_class=`体类`**
*> web_page_chrome page=`self` nav_html=`导航` footer_html=`页脚` body_class=`体类`*
## 元数据
+ `元数据`
SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`canonical`、`og:type` 等会在渲染时写入 `<head>`。特殊键 `icon` / `favicon` / `apple-touch-icon` 会写成 `<link rel="…">`(不会误写成 `<meta name>`)。
**> web_page_meta page=`self` meta=`元数据`**
*> web_page_meta page=`self` meta=`元数据`*
## 头装配
+ `表`
把 Head 资源表(`|关系|地址|类型|尺寸|媒体|作为|跨域|推迟|异步|版本|`)挂到页面的 `head`。`关系=script` / `module` 生成 `<script>`,其余生成 `<link>`。经典脚本仅在 `推迟`/`异步` 为真时输出对应属性(缺省仍同步,兼容旧站)。非空 `版本` 追加 `?v=`,否则用页面/应用的 `资源版本`。与已有 `head` 合并。
**> web_page_head page=`self` table=`表`**
*> web_page_head page=`self` table=`表`*
## 图片装配
+ `表`
把图片表装配为 HTML,写入 `images_html`(渲染时插在主区引言之前)。表形与模块级 `网页.图片装配` 相同。
**> web_page_images page=`self` table=`表`**
*> web_page_images page=`self` table=`表`*
## 分页
+ `偏移`=0
@@ -289,7 +289,7 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
为主体列表绑定设置 DB 分页(`limit`/`offset`),并渲染上一页/下一页导航。
**> web_page_paginate page=`self` offset=`偏移` limit=`上限` path=`路径`**
*> web_page_paginate page=`self` offset=`偏移` limit=`上限` path=`路径`*
## 表单装配
+ `表单`
@@ -298,28 +298,28 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
将表单嵌入页面主区。可选 `表单插槽`(元素 id,如 `#qd-note-form-mount`):把表单注入引言 HTML 内该节点,而不是 `.main-intro` 后的兄弟 `.site-form`(GAP-11)。插槽缺失时回退为兄弟节点。`listen` 会从页面/路由上的表单自动挂载 `GET|POST /_form/{id}`(可选再 `挂载表单`)。
**> web_compose_form page=`self` form=`表单` id=`id` target=`表单插槽`**
*> web_compose_form page=`self` form=`表单` id=`id` target=`表单插槽`*
## 渲染
+ `数据库`=None
1. `数据库`
*url = 数据库[^url]*
**> web_render page=`self` url=`url`**
**url = 数据库[^url]**
*> web_render page=`self` url=`url`*
2. *
**> web_render page=`self`**
*> web_render page=`self`*
# 样式
+ `名`=""
**self**
*self*
## 样式处理
+ `样式`=None
+ `名`=None
+ `路径`=None
**self**
*self*
# 数据库
+ `地址`="sqlite:site.db"
@@ -327,7 +327,7 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
打开数据库句柄。URL 方案:`sqlite:路径`(默认)、`postgres://…` / `postgresql://…`(CRUD 方法相同)。
> 确保插件
**> web_db_new url=`地址`**
*> web_db_new url=`地址`*
## 初始化
+ `名`
@@ -335,16 +335,16 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
从表结构创建表。可选列:`唯一`/`unique`、`索引`/`index`、`外键`/`fk`/`references`(如 `posts.id`)。若存在 `created_at` / `updated_at` 列,插入/更新时自动写入。
*url = self[^url]*
**> web_db_init url=`url` name=`名` fields=`字段`**
**url = self[^url]**
*> web_db_init url=`url` name=`名` fields=`字段`*
## 插入
+ `表`
+ `行`
+ `事务`=None
*url = self[^url]*
**> web_db_insert url=`url` table=`表` rows=`行` txn=`事务`**
**url = self[^url]**
*> web_db_insert url=`url` table=`表` rows=`行` txn=`事务`*
## 查询
+ `表`
@@ -355,9 +355,9 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
简单条件:单行列→值映射(AND `=`),或 `|字段|操作|值|` 表(`=` `!=` `>` `>=` `<` `<=` `like` `in` `between` `is null`;加 `|或|` 为 `是` 可让该行与前一行用 `OR` 连接)。`排序` 是列名,`-` 前缀表示倒序(`"created_at"`、`"-created_at"`),可逗号分隔多列。传入 `事务` 可在已开启的事务内读取。要分页(带总数)用 `分页`。
*url = self[^url]*
*r = > web_db_select url=`url` table=`表` where=`条件` limit=`上限` order=`排序` offset=None txn=`事务`*
**r[^rows]**
**url = self[^url]**
**r = > web_db_select url=`url` table=`表` where=`条件` limit=`上限` order=`排序` offset=None txn=`事务`**
*r[^rows]*
## 分页
+ `表`
@@ -369,16 +369,16 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
同 `查询`,但返回 `{ rows, total }`——`total` 是满足 `条件` 的行数(不受 `上限`/`跳过` 影响),供渲染 `上一页 / 下一页`。`跳过` 为要跳过的行数(如每页 10 条的第 2 页 ⇒ `跳过`=10)。
*url = self[^url]*
**> web_db_select url=`url` table=`表` where=`条件` limit=`上限` order=`排序` offset=`跳过` txn=`事务`**
**url = self[^url]**
*> web_db_select url=`url` table=`表` where=`条件` limit=`上限` order=`排序` offset=`跳过` txn=`事务`*
## 获取
+ `表`
+ `id`
+ `事务`=None
*url = self[^url]*
**> web_db_get url=`url` table=`表` id=`id` txn=`事务`**
**url = self[^url]**
*> web_db_get url=`url` table=`表` id=`id` txn=`事务`*
## 更新
+ `表`
@@ -386,24 +386,24 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
+ `行`
+ `事务`=None
*url = self[^url]*
**> web_db_update url=`url` table=`表` id=`id` row=`行` txn=`事务`**
**url = self[^url]**
*> web_db_update url=`url` table=`表` id=`id` row=`行` txn=`事务`*
## 删除
+ `表`
+ `id`
+ `事务`=None
*url = self[^url]*
**> web_db_delete url=`url` table=`表` id=`id` txn=`事务`**
**url = self[^url]**
*> web_db_delete url=`url` table=`表` id=`id` txn=`事务`*
## 执行
+ `sql`
+ `参数`=None
+ `事务`=None
*url = self[^url]*
**> web_db_exec url=`url` sql=`sql` args=`参数` txn=`事务`**
**url = self[^url]**
*> web_db_exec url=`url` sql=`sql` args=`参数` txn=`事务`*
## 原生查询
+ `sql`
@@ -412,8 +412,8 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
执行裸 SQL 并返回结果集——count / join / group / 子查询都行。返回 `{ rows, count }`。
*url = self[^url]*
**> web_db_query url=`url` sql=`sql` args=`参数` txn=`事务`**
**url = self[^url]**
*> web_db_query url=`url` sql=`sql` args=`参数` txn=`事务`*
## 计数
+ `表`
@@ -422,17 +422,17 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
统计满足 `条件` 的行数(语法同 `查询`)。返回数字。
*url = self[^url]*
*r = > web_db_count url=`url` table=`表` where=`条件` txn=`事务`*
**r[^count]**
**url = self[^url]**
**r = > web_db_count url=`url` table=`表` where=`条件` txn=`事务`**
*r[^count]*
## 迁移
+ `步骤`
按版本执行 SQL 迁移。`步骤` 为 `|版本|SQL|` 表;已应用版本记入 `_marqdo_migrations`。重复执行对已应用版本是空操作。仅 SQLite。
*url = self[^url]*
**> web_db_migrate url=`url` steps=`步骤`**
**url = self[^url]**
*> web_db_migrate url=`url` steps=`步骤`*
## 全文
+ `表`
@@ -441,8 +441,8 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
为 `表` 的内容列创建 FTS5 索引(CSV 或列表)。默认索引名 `{表}_fts`,用触发器保持同步。需要整数 `id` 主键。仅 SQLite。
*url = self[^url]*
**> web_db_fts_create url=`url` table=`表` columns=`列` name=`名`**
**url = self[^url]**
*> web_db_fts_create url=`url` table=`表` columns=`列` name=`名`*
## 搜索
+ `表`
@@ -452,15 +452,15 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
对 `全文` 建立的索引做 `MATCH` 检索。返回 `{ rows, count }`,含 `rank`(bm25)。仅 SQLite。
*url = self[^url]*
**> web_db_search url=`url` table=`表` q=`关键词` limit=`上限` name=`名`**
**url = self[^url]**
*> web_db_search url=`url` table=`表` q=`关键词` limit=`上限` name=`名`*
## 事务
开启一个事务:从连接池独占借用连接,返回 `事务` 句柄。在事务内写入,然后 `提交` 或 `回滚`。所有语句在同一连接上执行,整批写入是原子的。
*url = self[^url]*
**> web_db_begin url=`url`**
**url = self[^url]**
*> web_db_begin url=`url`*
# 事务
+ `事务`
@@ -468,15 +468,15 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
数据库.事务 返回的句柄。这里的所有 CRUD 都在该事务连接上执行;结束时 提交 或 回滚。
**self**
*self*
## 插入
+ `表`
+ `行`
*url = self[^地址]*
*txn = self[^事务]*
**> web_db_insert url=`url` table=`表` rows=`行` txn=`txn`**
**url = self[^地址]**
**txn = self[^事务]**
*> web_db_insert url=`url` table=`表` rows=`行` txn=`txn`*
## 查询
+ `表`
@@ -486,57 +486,57 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
筛选语法同 `数据库.查询`;在事务内执行。
*url = self[^地址]*
*txn = self[^事务]*
*r = > web_db_select url=`url` table=`表` where=`条件` limit=`上限` order=`排序` offset=None txn=`txn`*
**r[^rows]**
**url = self[^地址]**
**txn = self[^事务]**
**r = > web_db_select url=`url` table=`表` where=`条件` limit=`上限` order=`排序` offset=None txn=`txn`**
*r[^rows]*
## 获取
+ `表`
+ `id`
*url = self[^地址]*
*txn = self[^事务]*
**> web_db_get url=`url` table=`表` id=`id` txn=`txn`**
**url = self[^地址]**
**txn = self[^事务]**
*> web_db_get url=`url` table=`表` id=`id` txn=`txn`*
## 更新
+ `表`
+ `id`
+ `行`
*url = self[^地址]*
*txn = self[^事务]*
**> web_db_update url=`url` table=`表` id=`id` row=`行` txn=`txn`**
**url = self[^地址]**
**txn = self[^事务]**
*> web_db_update url=`url` table=`表` id=`id` row=`行` txn=`txn`*
## 删除
+ `表`
+ `id`
*url = self[^地址]*
*txn = self[^事务]*
**> web_db_delete url=`url` table=`表` id=`id` txn=`txn`**
**url = self[^地址]**
**txn = self[^事务]**
*> web_db_delete url=`url` table=`表` id=`id` txn=`txn`*
## 执行
+ `sql`
+ `参数`=None
*url = self[^地址]*
*txn = self[^事务]*
**> web_db_exec url=`url` sql=`sql` args=`参数` txn=`txn`**
**url = self[^地址]**
**txn = self[^事务]**
*> web_db_exec url=`url` sql=`sql` args=`参数` txn=`txn`*
## 提交
提交事务,并把连接归还连接池。
*txn = self[^事务]*
**> web_db_commit txn=`txn`**
**txn = self[^事务]**
*> web_db_commit txn=`txn`*
## 回滚
回滚事务(撤销所有写入),并归还连接。
*txn = self[^事务]*
**> web_db_rollback txn=`txn`**
**txn = self[^事务]**
*> web_db_rollback txn=`txn`*
# 表单
+ `表`=None
@@ -546,37 +546,37 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
字段表 + 校验表;提交经 `# 数据库` 写入。
> 确保插件
**> web_form_new table=`表` action=`动作` id=`id`**
*> web_form_new table=`表` action=`动作` id=`id`*
## 字段
+ `字段`
**> web_form_fields form=`self` fields=`字段`**
*> web_form_fields form=`self` fields=`字段`*
## 规则
+ `规则`
**> web_form_rules form=`self` rules=`规则`**
*> web_form_rules form=`self` rules=`规则`*
## 校验
+ `规则`=None
+ `数据`
**> web_form_validate form=`self` rules=`规则` data=`数据`**
*> web_form_validate form=`self` rules=`规则` data=`数据`*
## 渲染
+ `id`=form
+ `数据`=None
+ `错误`=None
**> web_form_render form=`self` id=`id` data=`数据` errors=`错误`**
*> web_form_render form=`self` id=`id` data=`数据` errors=`错误`*
## 提交
+ `数据`
+ `数据库`
*url = 数据库[^url]*
**> web_form_submit form=`self` data=`数据` url=`url`**
**url = 数据库[^url]**
*> web_form_submit form=`self` data=`数据` url=`url`*
# 应用
+ `页面`
@@ -591,10 +591,10 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
+ `布局`=None
+ `资源版本`=None
构造应用。`后台=真` 时在 `后台前缀`(默认 `/admin`)挂载内置 CRUD。`后台=假` 时该前缀**不再保留**,可自行 `路由` 到 `/admin…`。可选 `登录回跳` / `登出回跳`。可选 `壳样式` / `布局` / `资源版本` 作为未自设页面的默认(见 `页面.壳样式` / `页面.布局` / `页面.资源版本`)。
构造应用。`后台=真` 时在 `后台前缀`(默认 `/admin`)挂载内置 CRUD。`后台=假` 时该前缀不再保留,可自行 `路由` 到 `/admin…`。可选 `登录回跳` / `登出回跳`。可选 `壳样式` / `布局` / `资源版本` 作为未自设页面的默认(见 `页面.壳样式` / `页面.布局` / `页面.资源版本`)。
> 确保插件
**> web_app_new page=`页面` db=`数据库` admin=`后台` host=`主机` port=`端口` admin_prefix=`后台前缀` login_redirect=`登录回跳` logout_redirect=`登出回跳` shell_css=`壳样式` layout=`布局` asset_version=`资源版本`**
*> web_app_new page=`页面` db=`数据库` admin=`后台` host=`主机` port=`端口` admin_prefix=`后台前缀` login_redirect=`登录回跳` logout_redirect=`登出回跳` shell_css=`壳样式` layout=`布局` asset_version=`资源版本`*
## 路由
+ `路径`
@@ -602,13 +602,13 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
将已装配页面挂到 `路径`(如 `/about`)。`/` 由首页 `页面=` 提供。
**> web_app_route app=`self` path=`路径` page=`页面`**
*> web_app_route app=`self` path=`路径` page=`页面`*
## 挂载表单
+ `id`
+ `表单`
**> web_app_mount_form app=`self` id=`id` form=`表单`**
*> web_app_mount_form app=`self` id=`id` form=`表单`*
## 静态
+ `目录`
@@ -616,14 +616,14 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
将 `目录` 下的文件挂到 `挂载`(默认 `/static`)。路径在 `监听` 时相对进程工作目录解析。若目录内有 `favicon.ico` / `favicon.png` / `favicon.svg` 且未配置 `图标`,则额外提供 `GET /favicon.ico` 并为每页注入默认 `<link rel="icon">`。
**> web_app_static app=`self` dir=`目录` mount=`挂载`**
*> web_app_static app=`self` dir=`目录` mount=`挂载`*
## 图标
+ `表`
用 GFM 表注册站点图标(`|路径|关系|类型|尺寸|地址|`)。`监听` 时按 `地址` 提供文件(`.ico` 默认 `/favicon.ico`,否则 `/icons/{文件名}`),并通过 `site_head` 向全站页面注入对应 `<link>`。设计见 [web-assets-and-images.md](../../doc/design/web-assets-and-images.md)。
**> web_app_icons app=`self` table=`表`**
*> web_app_icons app=`self` table=`表`*
## 装配
+ `跨域`=None
@@ -640,7 +640,7 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
表仍是数据,`装配` 把它们变成能力。配置即数据、装配即函数。
**> web_app_middleware app=`self` cors=`跨域` security=`安全` compress=`压缩` body_limit=`请求体上限` json_routes=`接口` access_log=`访问日志` cache_control=`缓存控制` proxy=`代理` invoke=`调用`**
*> web_app_middleware app=`self` cors=`跨域` security=`安全` compress=`压缩` body_limit=`请求体上限` json_routes=`接口` access_log=`访问日志` cache_control=`缓存控制` proxy=`代理` invoke=`调用`*
## 代理
+ `路径`
@@ -653,7 +653,7 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
同域反向代理到上游 HTTP(S)。`流式` 为真(默认)时管道转发响应体(含 `text/event-stream`),不整段缓冲。`上游` 可含 `$ENV` / `${ENV}`。`环境头` 为 `ENV=Header-Name`(逗号分隔),密钥留在服务端。
**> web_app_proxy app=`self` path=`路径` upstream=`上游` stream=`流式` strip_prefix=`去前缀` methods=`方法` headers_from_env=`环境头` timeout_ms=`超时`**
*> web_app_proxy app=`self` path=`路径` upstream=`上游` stream=`流式` strip_prefix=`去前缀` methods=`方法` headers_from_env=`环境头` timeout_ms=`超时`*
## 调用
+ `路径`
@@ -664,13 +664,13 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
每个 HTTP 请求调用用户 `##`。`函数` 必须是入口模块已 `导入` 的 `库.成员`。`正文` 为 `json` / `form` / `query` / `raw`;对象键映射为具名形参(另有 `payload`)。默认返回 JSON。
**> web_app_invoke app=`self` path=`路径` method=`方法` fn=`函数` body=`正文` return=`返回`**
*> web_app_invoke app=`self` path=`路径` method=`方法` fn=`函数` body=`正文` return=`返回`*
## 监听
提供 `/`、路由页、首页 `/_part/{id}`、路由 `{路径}/_part/{id}`、`/_form/{id}`、可选静态目录、可选 `/admin`,上传/下载/WebSocket/RSS/sitemap/robots、重定向、代理/调用路由,以及自定义 404。生产 HTTPS 请在反向代理终止;启用 TLS 时设 `cookie_secure`。
**> web_listen app=`self`**
*> web_listen app=`self`*
## 路由实时
+ `路径`
@@ -679,7 +679,7 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
在 `路径`(如 `/live`)注册 WebSocket 端点。`模式` 为 `echo`(默认)、`broadcast`(同路径全体广播)或 `drain`。旧参数 `回显=假` 等价于 `drain`。客户端用 `网页.实时` 的 `连接` 接入。
**> web_app_route_ws app=`self` path=`路径` echo=`回显` mode=`模式`**
*> web_app_route_ws app=`self` path=`路径` echo=`回显` mode=`模式`*
## 鉴权
+ `用户表`
@@ -689,9 +689,9 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
+ `登出回跳`=None
+ `登录路径`=None
在保持 `后台=真` 的同时,为 `{后台前缀}` 加**段边界**前缀门禁(默认 `/admin`)。未登录 **重定向** 到 `登录路径`(默认 `{前缀}/login`,自动排除)。不会匹配 `/admin-publish` 这类旁系路径。
在保持 `后台=真` 的同时,为 `{后台前缀}` 加段边界前缀门禁(默认 `/admin`)。未登录 重定向 到 `登录路径`(默认 `{前缀}/login`,自动排除)。不会匹配 `/admin-publish` 这类旁系路径。
**> web_app_auth app=`self` users=`用户表` session_ttl=`会话时长` admin_prefix=`后台前缀` login_redirect=`登录回跳` logout_redirect=`登出回跳` login_path=`登录路径`**
*> web_app_auth app=`self` users=`用户表` session_ttl=`会话时长` admin_prefix=`后台前缀` login_redirect=`登录回跳` logout_redirect=`登出回跳` login_path=`登录路径`*
## 门禁
+ `路径`
@@ -702,7 +702,7 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
要求会话角色落在 `角色`(CSV)之一。`匹配=prefix` 为段边界前缀;`exact` 为精确路径。路径末尾 `*` 亦表示前缀。`拒绝=redirect` 时访客跳转登录页(带 `?next=`);`forbid` 返回 403。`排除` 为 CSV/列表(如登录页)。
**> web_app_gate app=`self` path=`路径` roles=`角色` match=`匹配` on_deny=`拒绝` exclude=`排除`**
*> web_app_gate app=`self` path=`路径` roles=`角色` match=`匹配` on_deny=`拒绝` exclude=`排除`*
## 相册
+ `路径`=/gallery
@@ -713,7 +713,7 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
列出 `存储` 下 `前缀` 对象,生成 HTML 相册页,链接走 `下载基址`。
**> web_app_gallery app=`self` path=`路径` storage=`存储` prefix=`前缀` title=`标题` download_base=`下载基址`**
*> web_app_gallery app=`self` path=`路径` storage=`存储` prefix=`前缀` title=`标题` download_base=`下载基址`*
## 路由订阅
+ `路径`
@@ -726,7 +726,7 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
在 `路径`(如 `/feed.xml`)注册 RSS 2.0 订阅源,数据来自数据库表。
**> web_app_route_rss app=`self` path=`路径` table=`表` limit=`上限` order=`排序` title=`标题` link=`链接` description=`描述`**
*> web_app_route_rss app=`self` path=`路径` table=`表` limit=`上限` order=`排序` title=`标题` link=`链接` description=`描述`*
## 重定向
+ `来源`
@@ -735,7 +735,7 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
将 `来源` 重定向到 `目标`。`永久=真` 返回 301,否则 307。
**> web_app_redirect app=`self` from=`来源` to=`目标` permanent=`永久`**
*> web_app_redirect app=`self` from=`来源` to=`目标` permanent=`永久`*
## 错误页
+ `状态`=404
@@ -743,7 +743,7 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
为 HTTP `404` 或 `500` 绑定已装配页面。
**> web_app_error_page app=`self` status=`状态` page=`页面`**
*> web_app_error_page app=`self` status=`状态` page=`页面`*
## 站点地图
+ `路径`=/sitemap.xml
@@ -755,7 +755,7 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
提供 sitemap.xml。优先用数据库 `表` + `定位列`,或传入带 `loc`/`路径` 的 `条目` 表。
**> web_app_sitemap app=`self` path=`路径` base=`基址` table=`表` loc=`定位列` limit=`上限` items=`条目`**
*> web_app_sitemap app=`self` path=`路径` base=`基址` table=`表` loc=`定位列` limit=`上限` items=`条目`*
## 爬虫协议
+ `正文`=None
@@ -763,7 +763,7 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
提供 `/robots.txt`。省略 `正文` 时生成默认 Allow-all,可附带 `Sitemap:` 行。
**> web_app_robots app=`self` body=`正文` sitemap=`站点地图`**
*> web_app_robots app=`self` body=`正文` sitemap=`站点地图`*
## 上传
+ `路径`=/_upload
@@ -775,7 +775,7 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
挂载 `POST 路径` 接收 multipart 文件。`存储` 为 `# 存储` 句柄或 `file:…` / `s3://…` URL。可选 `类型` 为 `|类型|扩展名|` 允许表(或 MIME CSV)。成功返回 JSON `{ok,key,size,content_type}`。
**> web_app_upload app=`self` path=`路径` field=`字段` storage=`存储` prefix=`前缀` max_bytes=`最大字节` types=`类型`**
*> web_app_upload app=`self` path=`路径` field=`字段` storage=`存储` prefix=`前缀` max_bytes=`最大字节` types=`类型`*
## 下载
+ `路径`=/_media/{*key}
@@ -784,7 +784,7 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
挂载 `GET 路径` 流式返回对象。路径须捕获 `key`(嵌套键用 `{*key}`)。`处置` 为 `attachment` 或 `inline`。
**> web_app_download app=`self` path=`路径` storage=`存储` disposition=`处置`**
*> web_app_download app=`self` path=`路径` storage=`存储` disposition=`处置`*
# 鉴权
+ `用户表`
@@ -793,7 +793,7 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
会话/登录工具类。`登录` 用 `用户表` 校验。要给应用加 `/admin` 门禁,用 `应用` 的 `鉴权` 方法。
> 确保插件
**> web_auth_new users=`用户表` session_ttl=`会话时长`**
*> web_auth_new users=`用户表` session_ttl=`会话时长`*
## 登录
+ `用户名`
@@ -801,30 +801,30 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
用用户表校验并创建会话。返回 `{ok, session_id, username}`。
*users = self[^users]*
*ttl = self[^session_ttl]*
**> web_auth_login username=`用户名` password=`密码` users=`users` session_ttl=`ttl`**
**users = self[^users]**
**ttl = self[^session_ttl]**
*> web_auth_login username=`用户名` password=`密码` users=`users` session_ttl=`ttl`*
## 校验
+ `会话id`
会话有效时返回 `{ok, username}`。
**> web_auth_check session_id=`会话id`**
*> web_auth_check session_id=`会话id`*
## 登出
+ `会话id`
销毁会话。
**> web_auth_logout session_id=`会话id`**
*> web_auth_logout session_id=`会话id`*
## 哈希密码
+ `密码`
将明文口令哈希为 argon2id 字符串,写入用户表的 `密码` 列;登录时自动校验。
**> web_password_hash password=`密码`**
*> web_password_hash password=`密码`*
# 缓存
+ `地址`="memory:"
@@ -832,13 +832,13 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
键值缓存。`memory:` 为进程内(测试 / 单进程);`redis://主机:6379/0` 连 Redis。
> 确保插件
**> web_cache_new url=`地址`**
*> web_cache_new url=`地址`*
## 获取
+ `键`
*url = self[^url]*
**> web_cache_get url=`url` key=`键`**
**url = self[^url]**
*> web_cache_get url=`url` key=`键`*
## 设置
+ `键`
@@ -847,26 +847,26 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
过期时间为秒;省略则不过期。
*url = self[^url]*
**> web_cache_set url=`url` key=`键` value=`值` ttl=`过期`**
**url = self[^url]**
*> web_cache_set url=`url` key=`键` value=`值` ttl=`过期`*
## 删除
+ `键`
*url = self[^url]*
**> web_cache_del url=`url` key=`键`**
**url = self[^url]**
*> web_cache_del url=`url` key=`键`*
## 存在
+ `键`
*url = self[^url]*
**> web_cache_exists url=`url` key=`键`**
**url = self[^url]**
*> web_cache_exists url=`url` key=`键`*
## 剩余时间
+ `键`
*url = self[^url]*
**> web_cache_ttl url=`url` key=`键`**
**url = self[^url]**
*> web_cache_ttl url=`url` key=`键`*
# 存储
+ `地址`="file:data/blobs"
@@ -874,7 +874,7 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
对象存储。`file:目录` 落本地盘(离线 / 金样);`s3://桶?endpoint=http://127.0.0.1:9000&access_key=…&secret_key=…` 连 MinIO / S3。
> 确保插件
**> web_storage_new url=`地址`**
*> web_storage_new url=`地址`*
## 上传
+ `键`
@@ -884,26 +884,26 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
正文(文本)与路径(本地文件)二选一。
*url = self[^url]*
**> web_storage_put url=`url` key=`键` body=`正文` path=`路径` content_type=`类型`**
**url = self[^url]**
*> web_storage_put url=`url` key=`键` body=`正文` path=`路径` content_type=`类型`*
## 下载
+ `键`
*url = self[^url]*
**> web_storage_get url=`url` key=`键`**
**url = self[^url]**
*> web_storage_get url=`url` key=`键`*
## 删除对象
+ `键`
*url = self[^url]*
**> web_storage_delete url=`url` key=`键`**
**url = self[^url]**
*> web_storage_delete url=`url` key=`键`*
## 列出
+ `前缀`=""
*url = self[^url]*
**> web_storage_list url=`url` prefix=`前缀`**
**url = self[^url]**
*> web_storage_list url=`url` prefix=`前缀`*
# 媒体
+ `存储`=None
@@ -911,7 +911,7 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
上传校验与落盘辅助(HTTP `应用.上传` 亦用同一套规则)。
> 确保插件
**> web_media_new storage=`存储`**
*> web_media_new storage=`存储`*
## 校验
+ `文件名`
@@ -920,7 +920,7 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
+ `最大字节`=5242880
+ `允许`=None
**> web_upload_validate filename=`文件名` content_type=`类型` size=`大小` max_bytes=`最大字节` types=`允许`**
*> web_upload_validate filename=`文件名` content_type=`类型` size=`大小` max_bytes=`最大字节` types=`允许`*
## 保存
+ `路径`
@@ -929,12 +929,12 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
+ `前缀`=uploads/
+ `存储`=None
*st = 存储*
**st = 存储**
1. `st` == None
*st = self[^storage]*
**st = self[^storage]**
2. *
**> web_upload_save storage=`st` path=`路径` key=`键` content_type=`类型` prefix=`前缀`**
*> web_upload_save storage=`st` path=`路径` key=`键` content_type=`类型` prefix=`前缀`*
# 实时
+ `超时秒`=30
@@ -948,7 +948,7 @@ WebSocket 客户端工具。
|-------------|-------|
| `超时秒` | ws |
**out**
*out*
## 连接
+ `地址`
@@ -957,5 +957,5 @@ WebSocket 客户端工具。
单次请求-响应:连接 `地址`,发送 `消息`,收集服务器全部文本回复后关闭。返回 `{ok, messages}`。
*timeout = self[^timeout_sec]*
**> web_ws_connect url=`地址` message=`消息` headers=`headers` timeout_sec=`timeout`**
**timeout = self[^timeout_sec]**
*> web_ws_connect url=`地址` message=`消息` headers=`headers` timeout_sec=`timeout`*