Skip to main content

Module host

Module host 

Source
Expand description

宿主能力的类型化封装(spec §6.5「插件 → host」方法)。 每个函数对应一个 host_call 方法;所需能力见 spec §7,未授权时返回 code=“forbidden”。

Structs§

AiOptions
ai.complete 的可选项;model 缺省用宿主配置。宿主钳制 temperature 0..=2、max_tokens 1..=32768。
FolderRef
笔记本条目(spec §6.5 FolderRef)。
HttpRequest
HTTP 请求(能力 host:http,spec 0.2)。二进制体在这里做 base64 编解码。
HttpResponse
Message
对话消息(spec §6.5 Message);role ∈ system|user|assistant。
NoteRef
搜索结果条目(spec §6.5 NoteRef)。
UpsertResult
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=truenote.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"(总返回有效代码)。