docs+test: Lua stage 写回能力文档与测试(与 C ABI v2 对齐)

This commit is contained in:
JianFeeeee
2026-08-15 18:08:01 +08:00
parent b4006212e7
commit 59c9dd5153
2 changed files with 30 additions and 0 deletions

View File

@ -594,6 +594,21 @@ The `sdk.*` API of Lua plugins is fully aligned with external plugins (C ABI / t
Stage handlers receive the full context (same as external plugins): `raw_message`, `user_id`, `group_id`, `phase`, `llm_text`, `final_text`, `no_memory`, `response` (when responded), `tool_calls`, `tool_results`.
**Stage writeback (ABI v2)**: the `ctx` table passed to the handler is a reference — mutating writable fields inside the handler syncs back to the core `StageContext` (aligned with the C ABI v2 external-plugin capability):
```lua
sdk.register_stage("on_input", function(ctx)
ctx.raw_message = "[clean]" .. ctx.raw_message -- modify input, adopted by core
end)
sdk.register_stage("post_action", function(ctx)
ctx.llm_text = ctx.llm_text .. "[tail]" -- modify LLM output
ctx.tool_results = { { call_id = "x", result = "rewritten" } }
end)
```
Writable fields: `raw_message`, `llm_text`, `final_text`, `user_id`, `group_id`, `no_memory`, `response`, `tool_calls`, `tool_results`. Other fields are read-only.
**IO and config**
| Function | Description |