Expand description
宿主能力的类型化封装(spec §6.5「插件 → host」方法)。 每个函数对应一个 host_call 方法;所需能力见 spec §7,未授权时返回 code=“forbidden”。
Structs§
- AiOptions
ai.complete的可选项;model缺省用宿主配置。宿主钳制 temperature 0..=2、max_tokens 1..=32768。- Folder
Ref - 笔记本条目(spec §6.5 FolderRef)。
- Http
Request - HTTP 请求(能力
host:http,spec 0.2)。二进制体在这里做 base64 编解码。 - Http
Response - Message
- 对话消息(spec §6.5 Message);
role∈ system|user|assistant。 - NoteRef
- 搜索结果条目(spec §6.5 NoteRef)。
- Upsert
Result notes.upsert/notes.create的结果。pending=true= 提案已交宿主 UI 确认、 尚未落盘(spec §6.5 写确认=提案回传);插件不应把它当成写入成功。
Functions§
- ai_
complete ai.complete:宿主代理的一次性补全(能力host:ai)。密钥/端点在宿主,插件不可见; 宿主未配置 AI → code=“internal”(message 指明去设置页配置)。网络等待不计插件 CPU 墙钟。- http_
request http.request:宿主代理执行 HTTP(S)。网络失败(连接/超时)→ Err(internal); 拿到响应(含 4xx/5xx)→ Ok(HttpResponse)。- log
log:宿主日志(无需能力)。失败静默忽略——日志不该让业务失败。- notes_
create notes.create:新建笔记(能力notes:write)。parent_id必须是已存在笔记本(否则 invalid)。pending=true时note.id为空串——id 由宿主在用户批准时生成,无法链式写入。- notes_
get notes.get:按 id 取完整笔记(能力notes:read)。不存在 → code=“not_found”。- notes_
list_ folders notes.list_folders:全部笔记本(能力notes:read),宿主按 (title, id) 排序。- notes_
search notes.search:标题/正文全文搜索(能力notes:read)。limit缺省宿主取 20、上限 100。- notes_
upsert notes.upsert:改标题/正文(能力notes:write)。None字段保持原值; 其余元数据宿主逐字保留。默认走提案回传(见UpsertResult)。- now_ms
time.now:当前时间 Unix 毫秒(无需能力,spec 0.2)。 沙箱内没有时钟(SystemTime::now()在 wasm32 会 panic)——签名协议(S3 SigV4 等)用这个。- settings_
get settings.get:读插件作用域 KV(能力settings)。键不存在返回 Null。- settings_
set settings.set:写插件作用域 KV(能力settings)。- system_
locale system.locale:当前 UI 语言代码(如en/zh/fr;无需能力,spec 0.4)。 供插件本地化自己运行时产出的文字(chat 回复 / 动态 UI 文案等)。宿主把 UI 语言 持久化在配置里,前端切换时同步;未设置时回落"en"(总返回有效代码)。