QueryHandle
runQuery 返回句柄(《07》§1.6 ⑨:排队输入只经 enqueueUserInput 进入屏障)
events
Section titled “events”events: AsyncGenerator<KernelEvent, void, undefined>;事件流:protocol 完整事件(包络+负载),seq 单调
abort()
Section titled “abort()”abort(reason?): void;立即中断;reason 缺省时按当下状态推导(streaming→aborted_streaming 等)。 显式 reason = 「外部中止来源」注入缝(RFC-SC-1 R3,contract-v0.21):驱动层 按来源指定终局词(serve 每轮墙钟 ‘timeout’、注册仓孤儿策略 ‘client_gone’ 等),kernel 原样签发进 turn.aborted;不传 = 现状零漂移(TUI/headless/acp)。
reason?
Section titled “reason?”void
compactNow()?
Section titled “compactNow()?”optional compactNow(options?): Promise<CompactNowResult>;手动压缩(/compact 接线语义):请求排队到下一个轮间屏障点执行
(运行中轮不可就地压缩——流式/工具期间历史正在生长,折叠边界无从落定),
返回的 promise 在屏障点执行后兑现;并发调用合流到同一次执行。
未接压缩缝立即拒绝 not_configured;已终态(或排队后直到终态未再经过
屏障点)拒绝 turn_ended——轮与轮之间的手动压缩由装配层直接走
ContextManager.compact(本句柄生命周期只覆盖单轮)。
注意:promise 由事件流消费驱动兑现,须与 events 消费并发等待。
可选能力位:runQuery 恒提供;第三方最小实现(测试假句柄等)可缺省,
消费方以 handle.compactNow?.() 探测。
options.instructions:并发调用合流时后到者胜(用户最新意图)。
options?
Section titled “options?”Promise<CompactNowResult>
counters()
Section titled “counters()”counters(): QueryCounters;四计数快照
enqueueUserInput()
Section titled “enqueueUserInput()”enqueueUserInput(text): void;注入用户输入:流式期间不打断当前模型调用,统一在下一次 assembling 前 的屏障点消费;终态后调用为无害空操作(运行时竞态,非编程错误)。
string
void
inputReceipts()?
Section titled “inputReceipts()?”optional inputReceipts(): readonly QueryInputReceipt[];readonly QueryInputReceipt[]
inputTarget()?
Section titled “inputTarget()?”optional inputTarget(): QueryInputTarget & { open: boolean;};QueryInputTarget & {
open: boolean;
}
messages()
Section titled “messages()”messages(): IRMessage[];消息历史快照(深拷贝;含 initialMessages 与本次查询累计的 user/assistant/tool_result 消息)。多轮会话装配(TUI/serve)在终态后 取走,作为下一次 runQuery 的 initialMessages——事件流不承载完整消息体, 历史保真以此为唯一出口。压缩成功后快照即压缩后形态。
reserveUserInput()?
Section titled “reserveUserInput()?”optional reserveUserInput(input): QueryInputReservationResult;预约式输入(加法能力);旧句柄可缺席。目标为本轮,不隐式创建后续轮。
QueryInputSubmission
QueryInputReservationResult
settle()?
Section titled “settle()?”optional settle(options?): Promise<QuerySettlement>;等待已经启动的查询及模型/工具生成器真实收尾,不消费事件、不中止。 终态事件仅代表逻辑结束;timeout/cancelled保留实际在飞工作,可再次等待。 runQuery恒提供;第三方旧句柄可缺席,此时调用方只能证明其既有迭代器合同。
options?
Section titled “options?”Promise<QuerySettlement>
state()
Section titled “state()”state(): | "idle" | "assembling" | "streaming" | "awaiting_permission" | "executing_tools" | "compacting" | "terminated";当前状态(可随时查询)
| "idle"
| "assembling"
| "streaming"
| "awaiting_permission"
| "executing_tools"
| "compacting"
| "terminated"
本文是否有帮助?
感谢反馈,我们会持续改进这篇文章。