@tansr/protocol 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +74 -0
  3. package/dist/canonical/common.d.ts +37 -0
  4. package/dist/canonical/common.js +149 -0
  5. package/dist/canonical/digest.d.ts +12 -0
  6. package/dist/canonical/digest.js +58 -0
  7. package/dist/canonical/encode.d.ts +15 -0
  8. package/dist/canonical/encode.js +157 -0
  9. package/dist/canonical/errors.d.ts +81 -0
  10. package/dist/canonical/errors.js +89 -0
  11. package/dist/canonical/index.d.ts +21 -0
  12. package/dist/canonical/index.js +21 -0
  13. package/dist/canonical/parse.d.ts +21 -0
  14. package/dist/canonical/parse.js +295 -0
  15. package/dist/client.d.ts +42 -0
  16. package/dist/client.js +1 -0
  17. package/dist/config.d.ts +4990 -0
  18. package/dist/config.js +657 -0
  19. package/dist/daemon.d.ts +70 -0
  20. package/dist/daemon.js +48 -0
  21. package/dist/events.d.ts +2152 -0
  22. package/dist/events.js +625 -0
  23. package/dist/governance.d.ts +445 -0
  24. package/dist/governance.js +183 -0
  25. package/dist/headless.d.ts +97 -0
  26. package/dist/headless.js +39 -0
  27. package/dist/identity.d.ts +96 -0
  28. package/dist/identity.js +45 -0
  29. package/dist/index.d.ts +525 -0
  30. package/dist/index.js +529 -0
  31. package/dist/ir.d.ts +1418 -0
  32. package/dist/ir.js +283 -0
  33. package/dist/journal.d.ts +297 -0
  34. package/dist/journal.js +150 -0
  35. package/dist/media.d.ts +563 -0
  36. package/dist/media.js +190 -0
  37. package/dist/metering.d.ts +225 -0
  38. package/dist/metering.js +90 -0
  39. package/dist/orchestration.d.ts +1551 -0
  40. package/dist/orchestration.js +333 -0
  41. package/dist/redact-patterns.d.ts +49 -0
  42. package/dist/redact-patterns.js +141 -0
  43. package/dist/storage.d.ts +507 -0
  44. package/dist/storage.js +110 -0
  45. package/dist/tool-result-artifact.d.ts +257 -0
  46. package/dist/tool-result-artifact.js +263 -0
  47. package/package.json +30 -0
@@ -0,0 +1,2152 @@
1
+ /**
2
+ * 内核事件协议(一份数据三用:UI 渲染 / 审计 / 编排)
3
+ *
4
+ * 设计要点:
5
+ * - 事件族与包络分离;
6
+ * - 一等 error 事件、tombstone→message.retracted;
7
+ * - 审计 schema 的关联链字段:trace/span/prompt/agent。
8
+ *
9
+ * 兼容规则:消费端必须容忍未知事件 type(向前兼容),据包络 `v` 字段判断。
10
+ */
11
+ import { z } from 'zod';
12
+ /** 事件包络——每个事件都携带,seq 单调支持断线重放(serve 模式 Last-Event-ID) */
13
+ export declare const EventEnvelopeSchema: z.ZodObject<{
14
+ sessionId: z.ZodString;
15
+ turnId: z.ZodOptional<z.ZodString>;
16
+ /** 会话内单调递增序号 */
17
+ seq: z.ZodNumber;
18
+ /** UTC 毫秒时间戳 */
19
+ ts: z.ZodNumber;
20
+ /** 协议版本,当前 "v0" */
21
+ v: z.ZodString;
22
+ /** 事件产生源:kernel / tool / provider / hook / extension */
23
+ source: z.ZodString;
24
+ }, "strip", z.ZodTypeAny, {
25
+ seq: number;
26
+ ts: number;
27
+ sessionId: string;
28
+ v: string;
29
+ source: string;
30
+ turnId?: string | undefined;
31
+ }, {
32
+ seq: number;
33
+ ts: number;
34
+ sessionId: string;
35
+ v: string;
36
+ source: string;
37
+ turnId?: string | undefined;
38
+ }>;
39
+ /** 事件包络(EventEnvelopeSchema 推导)。 */
40
+ export type EventEnvelope = z.infer<typeof EventEnvelopeSchema>;
41
+ /** 一轮查询的终止原因词表:正常完成、各类上限触顶、模型错误、中断 / 超时 / 关停、hook 阻断等。 */
42
+ export declare const TerminalReasonSchema: z.ZodEnum<["completed", "blocking_limit", "aborted_streaming", "aborted_tools", "model_error", "prompt_too_long", "max_turns", "max_tool_rounds", "injection_limit", "hook_stopped", "structured_output", "timeout", "shutdown", "budget_exceeded", "stop_hook_limit", "internal_error", "client_gone"]>;
43
+ /** 一轮查询的终止原因(TerminalReasonSchema 推导)。 */
44
+ export type TerminalReason = z.infer<typeof TerminalReasonSchema>;
45
+ /**
46
+ * tool.failed 的错误分类(contract-v0.2:由宽 string 收窄)。
47
+ * 取值集合 = kernel 调度器(DispatchingToolExecutor/SequentialToolExecutor)
48
+ * 实际签发全集:参数解析失败 / 未注册工具 / 硬超时 / 外部中断 / 执行抛错。
49
+ */
50
+ export declare const ToolErrorTypeSchema: z.ZodEnum<["invalid_args", "unknown_tool", "timeout", "aborted", "execution_error"]>;
51
+ /** tool.failed 的错误分类(ToolErrorTypeSchema 推导)。 */
52
+ export type ToolErrorType = z.infer<typeof ToolErrorTypeSchema>;
53
+ /** 权限决策三值:allow 放行 / deny 拒绝 / ask 交用户终审。 */
54
+ export declare const PermissionDecisionSchema: z.ZodEnum<["allow", "deny", "ask"]>;
55
+ /** 权限决策(PermissionDecisionSchema 推导)。 */
56
+ export type PermissionDecision = z.infer<typeof PermissionDecisionSchema>;
57
+ /**
58
+ * 决策来源——全部落审计。
59
+ * contract-v0.3:增 'hook'——PreToolUse hook 收紧(deny/升格 ask)
60
+ * 的专属归因;此前临时借记 'policy' 会损失「引擎策略 vs 外部执行体」的审计粒度。
61
+ * contract-v0.7:增 'builtin'——内置安全基线(权限管线
62
+ * 4.5 段)命中的专属归因;此前临时借记 'rule' 会与用户/企业配置规则混淆审计来源。
63
+ * contract-v0.8:增 'classifier'——LLM 权限分类器
64
+ * 裁决的专属归因(auto 模式放行/收紧,或 ask 决策的分类器收紧);借记
65
+ * 'policy'/'mode' 都会损失「机器裁决」这一审计维度。
66
+ */
67
+ export declare const DecisionSourceSchema: z.ZodEnum<["rule", "user", "mode", "policy", "hook", "builtin", "classifier"]>;
68
+ /** 权限决策来源(DecisionSourceSchema 推导)。 */
69
+ export type DecisionSource = z.infer<typeof DecisionSourceSchema>;
70
+ /**
71
+ * hook 执行终态(contract-v0.3):hook.completed 的可选 status 取值。
72
+ * 'blocked' 不在此集合——阻断走独立的 hook.blocked 事件(互斥拆分)。
73
+ */
74
+ export declare const HookOutcomeStatusSchema: z.ZodEnum<["ok", "error", "timeout", "aborted"]>;
75
+ /** hook 执行终态(HookOutcomeStatusSchema 推导)。 */
76
+ export type HookOutcomeStatus = z.infer<typeof HookOutcomeStatusSchema>;
77
+ /** 事件负载联合(不含包络)。命名按 session/turn/msg/tool/agent/hook/cost/plan 分族。 */
78
+ export declare const EventBodySchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
79
+ type: z.ZodLiteral<"session.created">;
80
+ cwd: z.ZodString;
81
+ }, "strip", z.ZodTypeAny, {
82
+ type: "session.created";
83
+ cwd: string;
84
+ }, {
85
+ type: "session.created";
86
+ cwd: string;
87
+ }>, z.ZodObject<{
88
+ type: z.ZodLiteral<"session.resumed">;
89
+ fromSeq: z.ZodNumber;
90
+ }, "strip", z.ZodTypeAny, {
91
+ type: "session.resumed";
92
+ fromSeq: number;
93
+ }, {
94
+ type: "session.resumed";
95
+ fromSeq: number;
96
+ }>, z.ZodObject<{
97
+ type: z.ZodLiteral<"session.compacted">;
98
+ /** 被移除消息的 index 闭区间 [first, last](原数组坐标) */
99
+ removedRange: z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>;
100
+ /**
101
+ * 被移除消息的精确 index 清单(contract-v0.4):pinned
102
+ * 挖洞时 removedRange 是外包络,重放/审计按本清单才能精确复原折叠面;
103
+ * 表面层折叠计数也应优先取本清单长度。升序;缺省时按 removedRange 连续。
104
+ */
105
+ removedIndices: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
106
+ /** 候选区内整体保留的 pinned 消息数(contract-v0.4;可观测性) */
107
+ keptPinnedCount: z.ZodOptional<z.ZodNumber>;
108
+ /**
109
+ * 压缩执行关联 id(contract-v0.15,RFC-CTX12-2):与 journal
110
+ * compact_boundary 记录、context-events.jsonl 埋点行(T-CTX14a)同源
111
+ * 互指。旧签发方缺省;消费方忽略无害。
112
+ */
113
+ compactionId: z.ZodOptional<z.ZodString>;
114
+ /**
115
+ * 折叠机制标记(P-CTX2 K9,G-A7 纯增量可选键):缺席 = 常规模型压缩;
116
+ * 'breaker_fallback' = 压缩熔断打开时的无模型硬截断保底(blocking 闸门
117
+ * 熔断感知径),表面层据此渲染专用文案。词表锚定 kernel
118
+ * CompactionFoldMechanism,自由文本仅兜底——kernel 扩值不 bump 契约
119
+ * (compact_boundary trigger 同先例)。
120
+ */
121
+ mechanism: z.ZodOptional<z.ZodString>;
122
+ /**
123
+ * 压缩前落盘的上下文快照 id(contract-v0.23,doc/116 §4.1 / doc/117 K-4·K-5):
124
+ * 装配层在本次压缩前写 pre_compaction Checkpoint 时携带,与
125
+ * session.checkpointed / journal compact_boundary.checkpointId 三方互指;
126
+ * 未落快照(选项关闭或未接线)缺席。消费方忽略无害。
127
+ */
128
+ checkpointId: z.ZodOptional<z.ZodString>;
129
+ }, "strip", z.ZodTypeAny, {
130
+ type: "session.compacted";
131
+ removedRange: [number, number];
132
+ compactionId?: string | undefined;
133
+ removedIndices?: number[] | undefined;
134
+ keptPinnedCount?: number | undefined;
135
+ mechanism?: string | undefined;
136
+ checkpointId?: string | undefined;
137
+ }, {
138
+ type: "session.compacted";
139
+ removedRange: [number, number];
140
+ compactionId?: string | undefined;
141
+ removedIndices?: number[] | undefined;
142
+ keptPinnedCount?: number | undefined;
143
+ mechanism?: string | undefined;
144
+ checkpointId?: string | undefined;
145
+ }>, z.ZodObject<{
146
+ type: z.ZodLiteral<"session.checkpointed">;
147
+ checkpointId: z.ZodString;
148
+ trigger: z.ZodString;
149
+ label: z.ZodOptional<z.ZodString>;
150
+ messageCount: z.ZodNumber;
151
+ }, "strip", z.ZodTypeAny, {
152
+ type: "session.checkpointed";
153
+ checkpointId: string;
154
+ trigger: string;
155
+ messageCount: number;
156
+ label?: string | undefined;
157
+ }, {
158
+ type: "session.checkpointed";
159
+ checkpointId: string;
160
+ trigger: string;
161
+ messageCount: number;
162
+ label?: string | undefined;
163
+ }>, z.ZodObject<{
164
+ type: z.ZodLiteral<"session.restored">;
165
+ checkpointId: z.ZodString;
166
+ fromMessages: z.ZodNumber;
167
+ toMessages: z.ZodNumber;
168
+ }, "strip", z.ZodTypeAny, {
169
+ type: "session.restored";
170
+ checkpointId: string;
171
+ fromMessages: number;
172
+ toMessages: number;
173
+ }, {
174
+ type: "session.restored";
175
+ checkpointId: string;
176
+ fromMessages: number;
177
+ toMessages: number;
178
+ }>, z.ZodObject<{
179
+ type: z.ZodLiteral<"session.forked">;
180
+ sourceSessionId: z.ZodString;
181
+ checkpointId: z.ZodString;
182
+ sessionId: z.ZodString;
183
+ }, "strip", z.ZodTypeAny, {
184
+ type: "session.forked";
185
+ sessionId: string;
186
+ checkpointId: string;
187
+ sourceSessionId: string;
188
+ }, {
189
+ type: "session.forked";
190
+ sessionId: string;
191
+ checkpointId: string;
192
+ sourceSessionId: string;
193
+ }>, z.ZodObject<{
194
+ type: z.ZodLiteral<"session.microcompacted">;
195
+ /**
196
+ * 本次存根化淘汰(evict 迁移)的 tool_result 块数。contract-v0.18 起
197
+ * ≥0(纯剪枝屏障为 0);与 prunedBlocks 不同时为零。
198
+ */
199
+ evictedBlocks: z.ZodNumber;
200
+ /** 估算口径淘汰回收量(tokens;Σ 每块存根化前后估算差,非权威计量) */
201
+ recoveredTokens: z.ZodNumber;
202
+ /** 同步执行墙钟耗时(ms;签发方计时,观测口径,不参与决策) */
203
+ durationMs: z.ZodNumber;
204
+ /** 淘汰前本地估算占用(tokens;水位审计) */
205
+ beforeTokens: z.ZodOptional<z.ZodNumber>;
206
+ /** 淘汰后本地估算占用(tokens) */
207
+ afterTokens: z.ZodOptional<z.ZodNumber>;
208
+ /**
209
+ * 本次原位剪枝(prune 迁移:头+尾+标记收束)的 tool_result 块数
210
+ * (contract-v0.18;零剪枝屏障键缺席)。
211
+ */
212
+ prunedBlocks: z.ZodOptional<z.ZodNumber>;
213
+ /** 估算口径剪枝回收量(tokens;与 recoveredTokens 分账不重叠) */
214
+ pruneRecoveredTokens: z.ZodOptional<z.ZodNumber>;
215
+ }, "strip", z.ZodTypeAny, {
216
+ type: "session.microcompacted";
217
+ evictedBlocks: number;
218
+ recoveredTokens: number;
219
+ durationMs: number;
220
+ beforeTokens?: number | undefined;
221
+ afterTokens?: number | undefined;
222
+ prunedBlocks?: number | undefined;
223
+ pruneRecoveredTokens?: number | undefined;
224
+ }, {
225
+ type: "session.microcompacted";
226
+ evictedBlocks: number;
227
+ recoveredTokens: number;
228
+ durationMs: number;
229
+ beforeTokens?: number | undefined;
230
+ afterTokens?: number | undefined;
231
+ prunedBlocks?: number | undefined;
232
+ pruneRecoveredTokens?: number | undefined;
233
+ }>, z.ZodObject<{
234
+ type: z.ZodLiteral<"session.locale.changed">;
235
+ locale: z.ZodString;
236
+ previous: z.ZodString;
237
+ }, "strip", z.ZodTypeAny, {
238
+ type: "session.locale.changed";
239
+ locale: string;
240
+ previous: string;
241
+ }, {
242
+ type: "session.locale.changed";
243
+ locale: string;
244
+ previous: string;
245
+ }>, z.ZodObject<{
246
+ type: z.ZodLiteral<"session.output_style.changed">;
247
+ style: z.ZodString;
248
+ previous: z.ZodString;
249
+ }, "strip", z.ZodTypeAny, {
250
+ type: "session.output_style.changed";
251
+ previous: string;
252
+ style: string;
253
+ }, {
254
+ type: "session.output_style.changed";
255
+ previous: string;
256
+ style: string;
257
+ }>, z.ZodObject<{
258
+ type: z.ZodLiteral<"session.workspace_trust.changed">;
259
+ trusted: z.ZodBoolean;
260
+ persisted: z.ZodOptional<z.ZodBoolean>;
261
+ }, "strip", z.ZodTypeAny, {
262
+ type: "session.workspace_trust.changed";
263
+ trusted: boolean;
264
+ persisted?: boolean | undefined;
265
+ }, {
266
+ type: "session.workspace_trust.changed";
267
+ trusted: boolean;
268
+ persisted?: boolean | undefined;
269
+ }>, z.ZodObject<{
270
+ type: z.ZodLiteral<"session.cwd_changed">;
271
+ from: z.ZodString;
272
+ to: z.ZodString;
273
+ }, "strip", z.ZodTypeAny, {
274
+ type: "session.cwd_changed";
275
+ from: string;
276
+ to: string;
277
+ }, {
278
+ type: "session.cwd_changed";
279
+ from: string;
280
+ to: string;
281
+ }>, z.ZodObject<{
282
+ type: z.ZodLiteral<"session.events_dropped">;
283
+ /** 累计丢弃条数(≥1;重复溢出只更新累计) */
284
+ droppedCount: z.ZodNumber;
285
+ /** 最近一次触发的上界 */
286
+ reason: z.ZodEnum<["count_limit", "bytes_limit"]>;
287
+ /** 丢弃发生的队列归属;词表首值 'sdk.events',自由文本兜底(扩词不 bump) */
288
+ scope: z.ZodString;
289
+ /** 累计丢弃近似度量(签发方有账才填) */
290
+ droppedBytes: z.ZodOptional<z.ZodNumber>;
291
+ /** 首条被丢事件的 seq */
292
+ firstDroppedSeq: z.ZodOptional<z.ZodNumber>;
293
+ /** 末条被丢事件的 seq(≥ firstDroppedSeq) */
294
+ lastDroppedSeq: z.ZodOptional<z.ZodNumber>;
295
+ /** 生效条数上界(Infinity 不可 JSON 化 → 缺席 = 不限) */
296
+ maxEvents: z.ZodOptional<z.ZodNumber>;
297
+ /** 生效近似度量上界(同上) */
298
+ maxBytes: z.ZodOptional<z.ZodNumber>;
299
+ }, "strip", z.ZodTypeAny, {
300
+ type: "session.events_dropped";
301
+ droppedCount: number;
302
+ reason: "count_limit" | "bytes_limit";
303
+ scope: string;
304
+ droppedBytes?: number | undefined;
305
+ firstDroppedSeq?: number | undefined;
306
+ lastDroppedSeq?: number | undefined;
307
+ maxEvents?: number | undefined;
308
+ maxBytes?: number | undefined;
309
+ }, {
310
+ type: "session.events_dropped";
311
+ droppedCount: number;
312
+ reason: "count_limit" | "bytes_limit";
313
+ scope: string;
314
+ droppedBytes?: number | undefined;
315
+ firstDroppedSeq?: number | undefined;
316
+ lastDroppedSeq?: number | undefined;
317
+ maxEvents?: number | undefined;
318
+ maxBytes?: number | undefined;
319
+ }>, z.ZodObject<{
320
+ type: z.ZodLiteral<"session.ended">;
321
+ }, "strip", z.ZodTypeAny, {
322
+ type: "session.ended";
323
+ }, {
324
+ type: "session.ended";
325
+ }>, z.ZodObject<{
326
+ type: z.ZodLiteral<"turn.started">;
327
+ }, "strip", z.ZodTypeAny, {
328
+ type: "turn.started";
329
+ }, {
330
+ type: "turn.started";
331
+ }>, z.ZodObject<{
332
+ type: z.ZodLiteral<"turn.completed">;
333
+ reason: z.ZodEnum<["completed", "blocking_limit", "aborted_streaming", "aborted_tools", "model_error", "prompt_too_long", "max_turns", "max_tool_rounds", "injection_limit", "hook_stopped", "structured_output", "timeout", "shutdown", "budget_exceeded", "stop_hook_limit", "internal_error", "client_gone"]>;
334
+ }, "strip", z.ZodTypeAny, {
335
+ type: "turn.completed";
336
+ reason: "completed" | "blocking_limit" | "aborted_streaming" | "aborted_tools" | "model_error" | "prompt_too_long" | "max_turns" | "max_tool_rounds" | "injection_limit" | "hook_stopped" | "structured_output" | "timeout" | "shutdown" | "budget_exceeded" | "stop_hook_limit" | "internal_error" | "client_gone";
337
+ }, {
338
+ type: "turn.completed";
339
+ reason: "completed" | "blocking_limit" | "aborted_streaming" | "aborted_tools" | "model_error" | "prompt_too_long" | "max_turns" | "max_tool_rounds" | "injection_limit" | "hook_stopped" | "structured_output" | "timeout" | "shutdown" | "budget_exceeded" | "stop_hook_limit" | "internal_error" | "client_gone";
340
+ }>, z.ZodObject<{
341
+ type: z.ZodLiteral<"turn.aborted">;
342
+ reason: z.ZodEnum<["completed", "blocking_limit", "aborted_streaming", "aborted_tools", "model_error", "prompt_too_long", "max_turns", "max_tool_rounds", "injection_limit", "hook_stopped", "structured_output", "timeout", "shutdown", "budget_exceeded", "stop_hook_limit", "internal_error", "client_gone"]>;
343
+ }, "strip", z.ZodTypeAny, {
344
+ type: "turn.aborted";
345
+ reason: "completed" | "blocking_limit" | "aborted_streaming" | "aborted_tools" | "model_error" | "prompt_too_long" | "max_turns" | "max_tool_rounds" | "injection_limit" | "hook_stopped" | "structured_output" | "timeout" | "shutdown" | "budget_exceeded" | "stop_hook_limit" | "internal_error" | "client_gone";
346
+ }, {
347
+ type: "turn.aborted";
348
+ reason: "completed" | "blocking_limit" | "aborted_streaming" | "aborted_tools" | "model_error" | "prompt_too_long" | "max_turns" | "max_tool_rounds" | "injection_limit" | "hook_stopped" | "structured_output" | "timeout" | "shutdown" | "budget_exceeded" | "stop_hook_limit" | "internal_error" | "client_gone";
349
+ }>, z.ZodObject<{
350
+ type: z.ZodLiteral<"turn.error">;
351
+ scope: z.ZodString;
352
+ message: z.ZodString;
353
+ recoverable: z.ZodBoolean;
354
+ /**
355
+ * 错误类别标记(P-CTX2 K10,G-A8 纯增量可选键):scope='model' 时为
356
+ * IRErrorKind 透传('policy_denied'/'context_overflow'/'server'/…),
357
+ * 表面层据此做链路归属([端点]/[平台])与自救指引模板化。缺席 =
358
+ * 旧签发方或非模型 scope,渲染回落 scope 归属。词表锚定 IRErrorKind,
359
+ * 自由文本仅兜底——kind 扩值不 bump 契约(compacted.mechanism 同先例)。
360
+ */
361
+ errorKind: z.ZodOptional<z.ZodString>;
362
+ /**
363
+ * 结构化事实位(contract-v0.26;加法可选键):scope='model' 时
364
+ * = IR error 事件 `detail` 透传(providers 自服务端信封带出的机器可判事实;首个取值
365
+ * `{ scope: 'plan' }` = 平台套餐配额拒绝,与 HTTP 面 `error.detail.scope`
366
+ * 同键同值)。三端 reducer 归约:`recoverable:true` → `SessionNotice.detail`,失败形 →
367
+ * `ErrorView.detail`;端侧 `ErrorEnvelope.scope` 取值器同一读法。缺席 = 无附加事实
368
+ * (既有事件体字节零变)。值恒不含 endUser 身份 / 令牌 / 内部 id。
369
+ */
370
+ detail: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
371
+ }, "strip", z.ZodTypeAny, {
372
+ message: string;
373
+ type: "turn.error";
374
+ recoverable: boolean;
375
+ scope: string;
376
+ detail?: Record<string, unknown> | undefined;
377
+ errorKind?: string | undefined;
378
+ }, {
379
+ message: string;
380
+ type: "turn.error";
381
+ recoverable: boolean;
382
+ scope: string;
383
+ detail?: Record<string, unknown> | undefined;
384
+ errorKind?: string | undefined;
385
+ }>, z.ZodObject<{
386
+ type: z.ZodLiteral<"msg.block.start">;
387
+ index: z.ZodNumber;
388
+ blockType: z.ZodString;
389
+ }, "strip", z.ZodTypeAny, {
390
+ type: "msg.block.start";
391
+ index: number;
392
+ blockType: string;
393
+ }, {
394
+ type: "msg.block.start";
395
+ index: number;
396
+ blockType: string;
397
+ }>, z.ZodObject<{
398
+ type: z.ZodLiteral<"msg.text.delta">;
399
+ index: z.ZodNumber;
400
+ text: z.ZodString;
401
+ }, "strip", z.ZodTypeAny, {
402
+ type: "msg.text.delta";
403
+ text: string;
404
+ index: number;
405
+ }, {
406
+ type: "msg.text.delta";
407
+ text: string;
408
+ index: number;
409
+ }>, z.ZodObject<{
410
+ type: z.ZodLiteral<"msg.thinking.delta">;
411
+ index: z.ZodNumber;
412
+ text: z.ZodString;
413
+ }, "strip", z.ZodTypeAny, {
414
+ type: "msg.thinking.delta";
415
+ text: string;
416
+ index: number;
417
+ }, {
418
+ type: "msg.thinking.delta";
419
+ text: string;
420
+ index: number;
421
+ }>, z.ZodObject<{
422
+ type: z.ZodLiteral<"msg.block.end">;
423
+ index: z.ZodNumber;
424
+ }, "strip", z.ZodTypeAny, {
425
+ type: "msg.block.end";
426
+ index: number;
427
+ }, {
428
+ type: "msg.block.end";
429
+ index: number;
430
+ }>, z.ZodObject<{
431
+ type: z.ZodLiteral<"msg.retracted">;
432
+ index: z.ZodNumber;
433
+ }, "strip", z.ZodTypeAny, {
434
+ type: "msg.retracted";
435
+ index: number;
436
+ }, {
437
+ type: "msg.retracted";
438
+ index: number;
439
+ }>, z.ZodObject<{
440
+ type: z.ZodLiteral<"tool.proposed">;
441
+ toolCallId: z.ZodString;
442
+ name: z.ZodString;
443
+ args: z.ZodUnknown;
444
+ }, "strip", z.ZodTypeAny, {
445
+ type: "tool.proposed";
446
+ name: string;
447
+ toolCallId: string;
448
+ args?: unknown;
449
+ }, {
450
+ type: "tool.proposed";
451
+ name: string;
452
+ toolCallId: string;
453
+ args?: unknown;
454
+ }>, z.ZodObject<{
455
+ type: z.ZodLiteral<"tool.permission.requested">;
456
+ toolCallId: z.ZodString;
457
+ name: z.ZodString;
458
+ }, "strip", z.ZodTypeAny, {
459
+ type: "tool.permission.requested";
460
+ name: string;
461
+ toolCallId: string;
462
+ }, {
463
+ type: "tool.permission.requested";
464
+ name: string;
465
+ toolCallId: string;
466
+ }>, z.ZodObject<{
467
+ type: z.ZodLiteral<"tool.permission.decided">;
468
+ toolCallId: z.ZodString;
469
+ decision: z.ZodEnum<["allow", "deny", "ask"]>;
470
+ decisionSource: z.ZodEnum<["rule", "user", "mode", "policy", "hook", "builtin", "classifier"]>;
471
+ /**
472
+ * 命中的规则原文(如 `Shell(git *)`;contract-v0.2)。
473
+ * 审计链由此可答"哪条规则拒的";模式短路/兜底 ask 等无规则命中时不落键。
474
+ */
475
+ matchedRule: z.ZodOptional<z.ZodString>;
476
+ }, "strip", z.ZodTypeAny, {
477
+ type: "tool.permission.decided";
478
+ toolCallId: string;
479
+ decision: "allow" | "deny" | "ask";
480
+ decisionSource: "user" | "mode" | "classifier" | "policy" | "rule" | "hook" | "builtin";
481
+ matchedRule?: string | undefined;
482
+ }, {
483
+ type: "tool.permission.decided";
484
+ toolCallId: string;
485
+ decision: "allow" | "deny" | "ask";
486
+ decisionSource: "user" | "mode" | "classifier" | "policy" | "rule" | "hook" | "builtin";
487
+ matchedRule?: string | undefined;
488
+ }>, z.ZodObject<{
489
+ type: z.ZodLiteral<"tool.started">;
490
+ toolCallId: z.ZodString;
491
+ }, "strip", z.ZodTypeAny, {
492
+ type: "tool.started";
493
+ toolCallId: string;
494
+ }, {
495
+ type: "tool.started";
496
+ toolCallId: string;
497
+ }>, z.ZodObject<{
498
+ type: z.ZodLiteral<"tool.progress">;
499
+ toolCallId: z.ZodString;
500
+ message: z.ZodString;
501
+ }, "strip", z.ZodTypeAny, {
502
+ message: string;
503
+ type: "tool.progress";
504
+ toolCallId: string;
505
+ }, {
506
+ message: string;
507
+ type: "tool.progress";
508
+ toolCallId: string;
509
+ }>, z.ZodObject<{
510
+ type: z.ZodLiteral<"tool.output.delta">;
511
+ toolCallId: z.ZodString;
512
+ chunk: z.ZodString;
513
+ }, "strip", z.ZodTypeAny, {
514
+ type: "tool.output.delta";
515
+ toolCallId: string;
516
+ chunk: string;
517
+ }, {
518
+ type: "tool.output.delta";
519
+ toolCallId: string;
520
+ chunk: string;
521
+ }>, z.ZodObject<{
522
+ type: z.ZodLiteral<"tool.completed">;
523
+ toolCallId: z.ZodString;
524
+ durationMs: z.ZodNumber;
525
+ /**
526
+ * ToolResult.data 透传位(contract-v0.3):工具产出的结构化
527
+ * 渲染数据(AGENTS.md「工具只产出结构化数据」铁律的事件流出口)。
528
+ * 表面层按工具名注册渲染器消费;无 data 的工具不落键,消费方忽略无害。
529
+ */
530
+ data: z.ZodOptional<z.ZodUnknown>;
531
+ /**
532
+ * 模型可见文本投影(contract-v0.8):喂回模型的 tool_result
533
+ * 文本(截断后形态)。cc-compat stream-json 包络与 SDK 消费方由此拿到
534
+ * 与模型一致的结果文本,不必反推 data;与 data 正交(结构化渲染 vs
535
+ * 模型文本)。大结果按工具结果预算截断后的文本为准,不另存全量。
536
+ */
537
+ content: z.ZodOptional<z.ZodString>;
538
+ /**
539
+ * 工具结构化失败位(contract-v0.25):`ToolResult.isError`
540
+ * 透传。工具以 **return isError** 表达的业务级失败(非零退出 / 用户中断 / SSRF 拒 /
541
+ * 媒体错误形)与 throw 径的 `tool.failed` 在表面层归约为同一 failed 态——此前 TUI /
542
+ * sdk / 端侧对这类结果一律 ✓。缺席 = 旧签发方或成功完成(completed 语义不变);
543
+ * 消费方(TUI / sdk / Android / iOS reducer)只判 `isError === true → failed`。
544
+ * 纯可选加法,包络 `v` 不 bump;端侧 vendored 同步另行跟进。
545
+ */
546
+ isError: z.ZodOptional<z.ZodBoolean>;
547
+ }, "strip", z.ZodTypeAny, {
548
+ type: "tool.completed";
549
+ durationMs: number;
550
+ toolCallId: string;
551
+ data?: unknown;
552
+ content?: string | undefined;
553
+ isError?: boolean | undefined;
554
+ }, {
555
+ type: "tool.completed";
556
+ durationMs: number;
557
+ toolCallId: string;
558
+ data?: unknown;
559
+ content?: string | undefined;
560
+ isError?: boolean | undefined;
561
+ }>, z.ZodObject<{
562
+ type: z.ZodLiteral<"tool.failed">;
563
+ toolCallId: z.ZodString;
564
+ errorType: z.ZodEnum<["invalid_args", "unknown_tool", "timeout", "aborted", "execution_error"]>;
565
+ message: z.ZodString;
566
+ }, "strip", z.ZodTypeAny, {
567
+ message: string;
568
+ type: "tool.failed";
569
+ toolCallId: string;
570
+ errorType: "aborted" | "timeout" | "invalid_args" | "unknown_tool" | "execution_error";
571
+ }, {
572
+ message: string;
573
+ type: "tool.failed";
574
+ toolCallId: string;
575
+ errorType: "aborted" | "timeout" | "invalid_args" | "unknown_tool" | "execution_error";
576
+ }>, z.ZodObject<{
577
+ type: z.ZodLiteral<"agent.spawned">;
578
+ agentId: z.ZodString;
579
+ parentAgentId: z.ZodOptional<z.ZodString>;
580
+ }, "strip", z.ZodTypeAny, {
581
+ type: "agent.spawned";
582
+ agentId: string;
583
+ parentAgentId?: string | undefined;
584
+ }, {
585
+ type: "agent.spawned";
586
+ agentId: string;
587
+ parentAgentId?: string | undefined;
588
+ }>, z.ZodObject<{
589
+ type: z.ZodLiteral<"agent.progress">;
590
+ agentId: z.ZodString;
591
+ message: z.ZodString;
592
+ }, "strip", z.ZodTypeAny, {
593
+ message: string;
594
+ type: "agent.progress";
595
+ agentId: string;
596
+ }, {
597
+ message: string;
598
+ type: "agent.progress";
599
+ agentId: string;
600
+ }>, z.ZodObject<{
601
+ type: z.ZodLiteral<"agent.completed">;
602
+ agentId: z.ZodString;
603
+ }, "strip", z.ZodTypeAny, {
604
+ type: "agent.completed";
605
+ agentId: string;
606
+ }, {
607
+ type: "agent.completed";
608
+ agentId: string;
609
+ }>, z.ZodObject<{
610
+ type: z.ZodLiteral<"agent.followup">;
611
+ agentId: z.ZodString;
612
+ messageId: z.ZodString;
613
+ }, "strip", z.ZodTypeAny, {
614
+ type: "agent.followup";
615
+ agentId: string;
616
+ messageId: string;
617
+ }, {
618
+ type: "agent.followup";
619
+ agentId: string;
620
+ messageId: string;
621
+ }>, z.ZodObject<{
622
+ type: z.ZodLiteral<"agent.report">;
623
+ agentId: z.ZodString;
624
+ message: z.ZodString;
625
+ wake: z.ZodBoolean;
626
+ }, "strip", z.ZodTypeAny, {
627
+ message: string;
628
+ type: "agent.report";
629
+ agentId: string;
630
+ wake: boolean;
631
+ }, {
632
+ message: string;
633
+ type: "agent.report";
634
+ agentId: string;
635
+ wake: boolean;
636
+ }>, z.ZodObject<{
637
+ type: z.ZodLiteral<"agent.settled">;
638
+ agentId: z.ZodString;
639
+ outcome: z.ZodString;
640
+ }, "strip", z.ZodTypeAny, {
641
+ type: "agent.settled";
642
+ agentId: string;
643
+ outcome: string;
644
+ }, {
645
+ type: "agent.settled";
646
+ agentId: string;
647
+ outcome: string;
648
+ }>, z.ZodObject<{
649
+ type: z.ZodLiteral<"agent.interrupted">;
650
+ agentId: z.ZodString;
651
+ by: z.ZodEnum<["user", "parent", "system"]>;
652
+ }, "strip", z.ZodTypeAny, {
653
+ type: "agent.interrupted";
654
+ agentId: string;
655
+ by: "user" | "system" | "parent";
656
+ }, {
657
+ type: "agent.interrupted";
658
+ agentId: string;
659
+ by: "user" | "system" | "parent";
660
+ }>, z.ZodObject<{
661
+ type: z.ZodLiteral<"hook.triggered">;
662
+ event: z.ZodString;
663
+ hookId: z.ZodString;
664
+ }, "strip", z.ZodTypeAny, {
665
+ type: "hook.triggered";
666
+ event: string;
667
+ hookId: string;
668
+ }, {
669
+ type: "hook.triggered";
670
+ event: string;
671
+ hookId: string;
672
+ }>, z.ZodObject<{
673
+ type: z.ZodLiteral<"hook.completed">;
674
+ hookId: z.ZodString;
675
+ event: z.ZodOptional<z.ZodString>;
676
+ durationMs: z.ZodOptional<z.ZodNumber>;
677
+ status: z.ZodOptional<z.ZodEnum<["ok", "error", "timeout", "aborted"]>>;
678
+ }, "strip", z.ZodTypeAny, {
679
+ type: "hook.completed";
680
+ hookId: string;
681
+ status?: "aborted" | "error" | "timeout" | "ok" | undefined;
682
+ durationMs?: number | undefined;
683
+ event?: string | undefined;
684
+ }, {
685
+ type: "hook.completed";
686
+ hookId: string;
687
+ status?: "aborted" | "error" | "timeout" | "ok" | undefined;
688
+ durationMs?: number | undefined;
689
+ event?: string | undefined;
690
+ }>, z.ZodObject<{
691
+ type: z.ZodLiteral<"hook.blocked">;
692
+ hookId: z.ZodString;
693
+ event: z.ZodOptional<z.ZodString>;
694
+ reason: z.ZodString;
695
+ durationMs: z.ZodOptional<z.ZodNumber>;
696
+ }, "strip", z.ZodTypeAny, {
697
+ type: "hook.blocked";
698
+ reason: string;
699
+ hookId: string;
700
+ durationMs?: number | undefined;
701
+ event?: string | undefined;
702
+ }, {
703
+ type: "hook.blocked";
704
+ reason: string;
705
+ hookId: string;
706
+ durationMs?: number | undefined;
707
+ event?: string | undefined;
708
+ }>, z.ZodObject<{
709
+ type: z.ZodLiteral<"cost.usage.updated">;
710
+ model: z.ZodString;
711
+ usage: z.ZodObject<{
712
+ inputTokens: z.ZodNumber;
713
+ outputTokens: z.ZodNumber;
714
+ cacheReadInputTokens: z.ZodOptional<z.ZodNumber>;
715
+ cacheCreationInputTokens: z.ZodOptional<z.ZodNumber>;
716
+ reasoningOutputTokens: z.ZodOptional<z.ZodNumber>;
717
+ cacheDeletedInputTokens: z.ZodOptional<z.ZodNumber>;
718
+ dims: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
719
+ saved: z.ZodOptional<z.ZodString>;
720
+ }, "strip", z.ZodTypeAny, {
721
+ inputTokens: number;
722
+ outputTokens: number;
723
+ cacheReadInputTokens?: number | undefined;
724
+ cacheCreationInputTokens?: number | undefined;
725
+ reasoningOutputTokens?: number | undefined;
726
+ cacheDeletedInputTokens?: number | undefined;
727
+ dims?: Record<string, number> | undefined;
728
+ saved?: string | undefined;
729
+ }, {
730
+ inputTokens: number;
731
+ outputTokens: number;
732
+ cacheReadInputTokens?: number | undefined;
733
+ cacheCreationInputTokens?: number | undefined;
734
+ reasoningOutputTokens?: number | undefined;
735
+ cacheDeletedInputTokens?: number | undefined;
736
+ dims?: Record<string, number> | undefined;
737
+ saved?: string | undefined;
738
+ }>;
739
+ costUsd: z.ZodOptional<z.ZodNumber>;
740
+ /**
741
+ * 上下文窗口分母(contract-v0.3):签发方(查询环)从装配层
742
+ * 注入的 provider capability.maxContext 透传。状态栏水位 = 最近 prompt
743
+ * 规模 / 本值;缺省时表面层隐藏水位段(或回退装配注入的静态值)。
744
+ * 随 usage 更新携带——/model 热切换后分母随下一轮事件自动矫正。
745
+ */
746
+ contextWindowTokens: z.ZodOptional<z.ZodNumber>;
747
+ /** 签发方 ResolvedModel.provider 透传;缺省时消费端可按 model 反查 */
748
+ provider: z.ZodOptional<z.ZodString>;
749
+ /** 子代理归因(Task 链上抛时由运行器注入;嵌套保留最内层) */
750
+ agentId: z.ZodOptional<z.ZodString>;
751
+ /** 按次计费/按调用归因的工具调用 id(如 Task、WebSearch) */
752
+ toolUseId: z.ZodOptional<z.ZodString>;
753
+ /**
754
+ * 用量目的:非对话主流的模型调用标注来源。词表:'compaction'(上下文
755
+ * 压缩轮)/ 'title'(会话标题生成,contract-v0.8
756
+ * 扩容;辅助任务降档的归因面)/ 'permission_classifier'(LLM 权限
757
+ * 分类器调用)/ 'memory'(记忆四面 fork:提取/固化/晋升/召回
758
+ * 选择;随本地记账闭环扩词)。新目的先扩词表再签发
759
+ * (自由文本仅兜底);缺省即对话主流。
760
+ *
761
+ * 词表分叉注记:同一分类器子系统在 request-
762
+ * measurement 观测面与 TWP 出线面用词 'classifier'(kernel context/
763
+ * request-measurement.ts RequestPurpose、providers twp/contract.ts
764
+ * TWP_PURPOSE_VALUES——现为扁平单表,分版常量已退役),与本词表
765
+ * 'permission_classifier' 属两套近义词并存;且本词当前全仓零签发方
766
+ * (分类器 usage 走遥测与测量面,不落本地 cost 事件)。统一到单一词属
767
+ * 契约面决策,待定;届时 kernel cost/tracker.ts KNOWN_COST_PURPOSES
768
+ * 须同步,勿单侧改词。
769
+ */
770
+ purpose: z.ZodOptional<z.ZodString>;
771
+ }, "strip", z.ZodTypeAny, {
772
+ type: "cost.usage.updated";
773
+ model: string;
774
+ usage: {
775
+ inputTokens: number;
776
+ outputTokens: number;
777
+ cacheReadInputTokens?: number | undefined;
778
+ cacheCreationInputTokens?: number | undefined;
779
+ reasoningOutputTokens?: number | undefined;
780
+ cacheDeletedInputTokens?: number | undefined;
781
+ dims?: Record<string, number> | undefined;
782
+ saved?: string | undefined;
783
+ };
784
+ provider?: string | undefined;
785
+ agentId?: string | undefined;
786
+ costUsd?: number | undefined;
787
+ contextWindowTokens?: number | undefined;
788
+ toolUseId?: string | undefined;
789
+ purpose?: string | undefined;
790
+ }, {
791
+ type: "cost.usage.updated";
792
+ model: string;
793
+ usage: {
794
+ inputTokens: number;
795
+ outputTokens: number;
796
+ cacheReadInputTokens?: number | undefined;
797
+ cacheCreationInputTokens?: number | undefined;
798
+ reasoningOutputTokens?: number | undefined;
799
+ cacheDeletedInputTokens?: number | undefined;
800
+ dims?: Record<string, number> | undefined;
801
+ saved?: string | undefined;
802
+ };
803
+ provider?: string | undefined;
804
+ agentId?: string | undefined;
805
+ costUsd?: number | undefined;
806
+ contextWindowTokens?: number | undefined;
807
+ toolUseId?: string | undefined;
808
+ purpose?: string | undefined;
809
+ }>, z.ZodObject<{
810
+ type: z.ZodLiteral<"cost.cache_miss">;
811
+ model: z.ZodString;
812
+ /** 本轮未命中缓存的输入规模(prompt tokens) */
813
+ inputTokens: z.ZodNumber;
814
+ /** 触发告警的输入规模阈值(签发方配置;可观测性) */
815
+ threshold: z.ZodOptional<z.ZodNumber>;
816
+ }, "strip", z.ZodTypeAny, {
817
+ type: "cost.cache_miss";
818
+ model: string;
819
+ inputTokens: number;
820
+ threshold?: number | undefined;
821
+ }, {
822
+ type: "cost.cache_miss";
823
+ model: string;
824
+ inputTokens: number;
825
+ threshold?: number | undefined;
826
+ }>, z.ZodObject<{
827
+ type: z.ZodLiteral<"cost.model.mismatch">;
828
+ /** 请求申报模型(IRRequest.model.model) */
829
+ requested: z.ZodString;
830
+ /** message_start 实回模型 */
831
+ actual: z.ZodString;
832
+ /** 请求申报 provider(签发方 ResolvedModel.provider 透传;归因辅助) */
833
+ provider: z.ZodOptional<z.ZodString>;
834
+ }, "strip", z.ZodTypeAny, {
835
+ type: "cost.model.mismatch";
836
+ requested: string;
837
+ actual: string;
838
+ provider?: string | undefined;
839
+ }, {
840
+ type: "cost.model.mismatch";
841
+ requested: string;
842
+ actual: string;
843
+ provider?: string | undefined;
844
+ }>, z.ZodObject<{
845
+ type: z.ZodLiteral<"cost.provider.switched">;
846
+ from: z.ZodString;
847
+ to: z.ZodString;
848
+ /** 切换原因;词表锚定 IRErrorKind(rate_limited/auth/server/…),自由文本仅兜底 */
849
+ reason: z.ZodString;
850
+ /** 全链尝试的 entry 数(含最终命中/耗尽的那个) */
851
+ attempts: z.ZodOptional<z.ZodNumber>;
852
+ /** 各落选 entry 的失败轨迹(按链序;kind 复用 IR 错误归一化枚举) */
853
+ failures: z.ZodOptional<z.ZodArray<z.ZodObject<{
854
+ provider: z.ZodString;
855
+ kind: z.ZodEnum<["rate_limited", "context_overflow", "auth", "server", "network", "connect", "stream_interrupted", "invalid_request", "policy_denied"]>;
856
+ }, "strip", z.ZodTypeAny, {
857
+ provider: string;
858
+ kind: "rate_limited" | "context_overflow" | "auth" | "server" | "network" | "connect" | "stream_interrupted" | "invalid_request" | "policy_denied";
859
+ }, {
860
+ provider: string;
861
+ kind: "rate_limited" | "context_overflow" | "auth" | "server" | "network" | "connect" | "stream_interrupted" | "invalid_request" | "policy_denied";
862
+ }>, "many">>;
863
+ }, "strip", z.ZodTypeAny, {
864
+ type: "cost.provider.switched";
865
+ from: string;
866
+ to: string;
867
+ reason: string;
868
+ attempts?: number | undefined;
869
+ failures?: {
870
+ provider: string;
871
+ kind: "rate_limited" | "context_overflow" | "auth" | "server" | "network" | "connect" | "stream_interrupted" | "invalid_request" | "policy_denied";
872
+ }[] | undefined;
873
+ }, {
874
+ type: "cost.provider.switched";
875
+ from: string;
876
+ to: string;
877
+ reason: string;
878
+ attempts?: number | undefined;
879
+ failures?: {
880
+ provider: string;
881
+ kind: "rate_limited" | "context_overflow" | "auth" | "server" | "network" | "connect" | "stream_interrupted" | "invalid_request" | "policy_denied";
882
+ }[] | undefined;
883
+ }>, z.ZodObject<{
884
+ type: z.ZodLiteral<"mcp.connected">;
885
+ server: z.ZodString;
886
+ transport: z.ZodEnum<["stdio", "http"]>;
887
+ protocolVersion: z.ZodString;
888
+ }, "strip", z.ZodTypeAny, {
889
+ type: "mcp.connected";
890
+ server: string;
891
+ transport: "http" | "stdio";
892
+ protocolVersion: string;
893
+ }, {
894
+ type: "mcp.connected";
895
+ server: string;
896
+ transport: "http" | "stdio";
897
+ protocolVersion: string;
898
+ }>, z.ZodObject<{
899
+ type: z.ZodLiteral<"mcp.connect_failed">;
900
+ server: z.ZodString;
901
+ /** 错误码;词表锚定 kernel McpErrorCode(connect_failed/handshake_failed/timeout/…) */
902
+ code: z.ZodString;
903
+ message: z.ZodString;
904
+ }, "strip", z.ZodTypeAny, {
905
+ code: string;
906
+ message: string;
907
+ type: "mcp.connect_failed";
908
+ server: string;
909
+ }, {
910
+ code: string;
911
+ message: string;
912
+ type: "mcp.connect_failed";
913
+ server: string;
914
+ }>, z.ZodObject<{
915
+ type: z.ZodLiteral<"mcp.closed">;
916
+ server: z.ZodString;
917
+ reason: z.ZodEnum<["closed", "server_exit", "error"]>;
918
+ detail: z.ZodOptional<z.ZodString>;
919
+ }, "strip", z.ZodTypeAny, {
920
+ type: "mcp.closed";
921
+ server: string;
922
+ reason: "error" | "closed" | "server_exit";
923
+ detail?: string | undefined;
924
+ }, {
925
+ type: "mcp.closed";
926
+ server: string;
927
+ reason: "error" | "closed" | "server_exit";
928
+ detail?: string | undefined;
929
+ }>, z.ZodObject<{
930
+ type: z.ZodLiteral<"mcp.elicitation_declined">;
931
+ server: z.ZodString;
932
+ mode: z.ZodEnum<["form", "url"]>;
933
+ message: z.ZodOptional<z.ZodString>;
934
+ }, "strip", z.ZodTypeAny, {
935
+ type: "mcp.elicitation_declined";
936
+ server: string;
937
+ mode: "url" | "form";
938
+ message?: string | undefined;
939
+ }, {
940
+ type: "mcp.elicitation_declined";
941
+ server: string;
942
+ mode: "url" | "form";
943
+ message?: string | undefined;
944
+ }>, z.ZodObject<{
945
+ type: z.ZodLiteral<"mcp.tool_skipped">;
946
+ server: z.ZodString;
947
+ tool: z.ZodString;
948
+ reason: z.ZodEnum<["duplicate_name", "invalid_name"]>;
949
+ }, "strip", z.ZodTypeAny, {
950
+ type: "mcp.tool_skipped";
951
+ server: string;
952
+ reason: "duplicate_name" | "invalid_name";
953
+ tool: string;
954
+ }, {
955
+ type: "mcp.tool_skipped";
956
+ server: string;
957
+ reason: "duplicate_name" | "invalid_name";
958
+ tool: string;
959
+ }>, z.ZodObject<{
960
+ type: z.ZodLiteral<"mcp.discovered">;
961
+ server: z.ZodString;
962
+ phase: z.ZodEnum<["catalog", "expand"]>;
963
+ origin: z.ZodEnum<["catalog-cache", "live"]>;
964
+ tools: z.ZodArray<z.ZodString, "many">;
965
+ durationMs: z.ZodNumber;
966
+ /** 64 字符帽折叠映射(仅 phase='expand' 且发生折叠时携带;审计面) */
967
+ folds: z.ZodOptional<z.ZodArray<z.ZodObject<{
968
+ tool: z.ZodString;
969
+ bridged: z.ZodString;
970
+ }, "strip", z.ZodTypeAny, {
971
+ tool: string;
972
+ bridged: string;
973
+ }, {
974
+ tool: string;
975
+ bridged: string;
976
+ }>, "many">>;
977
+ }, "strip", z.ZodTypeAny, {
978
+ type: "mcp.discovered";
979
+ tools: string[];
980
+ server: string;
981
+ durationMs: number;
982
+ phase: "catalog" | "expand";
983
+ origin: "catalog-cache" | "live";
984
+ folds?: {
985
+ tool: string;
986
+ bridged: string;
987
+ }[] | undefined;
988
+ }, {
989
+ type: "mcp.discovered";
990
+ tools: string[];
991
+ server: string;
992
+ durationMs: number;
993
+ phase: "catalog" | "expand";
994
+ origin: "catalog-cache" | "live";
995
+ folds?: {
996
+ tool: string;
997
+ bridged: string;
998
+ }[] | undefined;
999
+ }>, z.ZodObject<{
1000
+ type: z.ZodLiteral<"mcp.catalog_updated">;
1001
+ server: z.ZodString;
1002
+ added: z.ZodNumber;
1003
+ removed: z.ZodNumber;
1004
+ changed: z.ZodNumber;
1005
+ }, "strip", z.ZodTypeAny, {
1006
+ type: "mcp.catalog_updated";
1007
+ server: string;
1008
+ added: number;
1009
+ removed: number;
1010
+ changed: number;
1011
+ }, {
1012
+ type: "mcp.catalog_updated";
1013
+ server: string;
1014
+ added: number;
1015
+ removed: number;
1016
+ changed: number;
1017
+ }>, z.ZodObject<{
1018
+ type: z.ZodLiteral<"mcp.reconnecting">;
1019
+ server: z.ZodString;
1020
+ connection: z.ZodNumber;
1021
+ attempt: z.ZodNumber;
1022
+ delayMs: z.ZodNumber;
1023
+ }, "strip", z.ZodTypeAny, {
1024
+ type: "mcp.reconnecting";
1025
+ server: string;
1026
+ connection: number;
1027
+ attempt: number;
1028
+ delayMs: number;
1029
+ }, {
1030
+ type: "mcp.reconnecting";
1031
+ server: string;
1032
+ connection: number;
1033
+ attempt: number;
1034
+ delayMs: number;
1035
+ }>, z.ZodObject<{
1036
+ type: z.ZodLiteral<"mcp.reconnected">;
1037
+ server: z.ZodString;
1038
+ connection: z.ZodNumber;
1039
+ attempt: z.ZodNumber;
1040
+ downtimeMs: z.ZodNumber;
1041
+ }, "strip", z.ZodTypeAny, {
1042
+ type: "mcp.reconnected";
1043
+ server: string;
1044
+ connection: number;
1045
+ attempt: number;
1046
+ downtimeMs: number;
1047
+ }, {
1048
+ type: "mcp.reconnected";
1049
+ server: string;
1050
+ connection: number;
1051
+ attempt: number;
1052
+ downtimeMs: number;
1053
+ }>, z.ZodObject<{
1054
+ type: z.ZodLiteral<"mcp.reconnect_exhausted">;
1055
+ server: z.ZodString;
1056
+ connection: z.ZodNumber;
1057
+ attempts: z.ZodNumber;
1058
+ }, "strip", z.ZodTypeAny, {
1059
+ type: "mcp.reconnect_exhausted";
1060
+ server: string;
1061
+ attempts: number;
1062
+ connection: number;
1063
+ }, {
1064
+ type: "mcp.reconnect_exhausted";
1065
+ server: string;
1066
+ attempts: number;
1067
+ connection: number;
1068
+ }>, z.ZodObject<{
1069
+ type: z.ZodLiteral<"plan.todo.updated">;
1070
+ items: z.ZodArray<z.ZodObject<{
1071
+ id: z.ZodString;
1072
+ content: z.ZodString;
1073
+ status: z.ZodEnum<["pending", "in_progress", "completed", "cancelled"]>;
1074
+ }, "strip", z.ZodTypeAny, {
1075
+ status: "completed" | "pending" | "in_progress" | "cancelled";
1076
+ id: string;
1077
+ content: string;
1078
+ }, {
1079
+ status: "completed" | "pending" | "in_progress" | "cancelled";
1080
+ id: string;
1081
+ content: string;
1082
+ }>, "many">;
1083
+ }, "strip", z.ZodTypeAny, {
1084
+ type: "plan.todo.updated";
1085
+ items: {
1086
+ status: "completed" | "pending" | "in_progress" | "cancelled";
1087
+ id: string;
1088
+ content: string;
1089
+ }[];
1090
+ }, {
1091
+ type: "plan.todo.updated";
1092
+ items: {
1093
+ status: "completed" | "pending" | "in_progress" | "cancelled";
1094
+ id: string;
1095
+ content: string;
1096
+ }[];
1097
+ }>]>;
1098
+ /** 事件负载联合(EventBodySchema 推导)。 */
1099
+ export type EventBody = z.infer<typeof EventBodySchema>;
1100
+ /** 完整事件 = 包络 + 负载 */
1101
+ export declare const KernelEventSchema: z.ZodIntersection<z.ZodObject<{
1102
+ sessionId: z.ZodString;
1103
+ turnId: z.ZodOptional<z.ZodString>;
1104
+ /** 会话内单调递增序号 */
1105
+ seq: z.ZodNumber;
1106
+ /** UTC 毫秒时间戳 */
1107
+ ts: z.ZodNumber;
1108
+ /** 协议版本,当前 "v0" */
1109
+ v: z.ZodString;
1110
+ /** 事件产生源:kernel / tool / provider / hook / extension */
1111
+ source: z.ZodString;
1112
+ }, "strip", z.ZodTypeAny, {
1113
+ seq: number;
1114
+ ts: number;
1115
+ sessionId: string;
1116
+ v: string;
1117
+ source: string;
1118
+ turnId?: string | undefined;
1119
+ }, {
1120
+ seq: number;
1121
+ ts: number;
1122
+ sessionId: string;
1123
+ v: string;
1124
+ source: string;
1125
+ turnId?: string | undefined;
1126
+ }>, z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
1127
+ type: z.ZodLiteral<"session.created">;
1128
+ cwd: z.ZodString;
1129
+ }, "strip", z.ZodTypeAny, {
1130
+ type: "session.created";
1131
+ cwd: string;
1132
+ }, {
1133
+ type: "session.created";
1134
+ cwd: string;
1135
+ }>, z.ZodObject<{
1136
+ type: z.ZodLiteral<"session.resumed">;
1137
+ fromSeq: z.ZodNumber;
1138
+ }, "strip", z.ZodTypeAny, {
1139
+ type: "session.resumed";
1140
+ fromSeq: number;
1141
+ }, {
1142
+ type: "session.resumed";
1143
+ fromSeq: number;
1144
+ }>, z.ZodObject<{
1145
+ type: z.ZodLiteral<"session.compacted">;
1146
+ /** 被移除消息的 index 闭区间 [first, last](原数组坐标) */
1147
+ removedRange: z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>;
1148
+ /**
1149
+ * 被移除消息的精确 index 清单(contract-v0.4):pinned
1150
+ * 挖洞时 removedRange 是外包络,重放/审计按本清单才能精确复原折叠面;
1151
+ * 表面层折叠计数也应优先取本清单长度。升序;缺省时按 removedRange 连续。
1152
+ */
1153
+ removedIndices: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
1154
+ /** 候选区内整体保留的 pinned 消息数(contract-v0.4;可观测性) */
1155
+ keptPinnedCount: z.ZodOptional<z.ZodNumber>;
1156
+ /**
1157
+ * 压缩执行关联 id(contract-v0.15,RFC-CTX12-2):与 journal
1158
+ * compact_boundary 记录、context-events.jsonl 埋点行(T-CTX14a)同源
1159
+ * 互指。旧签发方缺省;消费方忽略无害。
1160
+ */
1161
+ compactionId: z.ZodOptional<z.ZodString>;
1162
+ /**
1163
+ * 折叠机制标记(P-CTX2 K9,G-A7 纯增量可选键):缺席 = 常规模型压缩;
1164
+ * 'breaker_fallback' = 压缩熔断打开时的无模型硬截断保底(blocking 闸门
1165
+ * 熔断感知径),表面层据此渲染专用文案。词表锚定 kernel
1166
+ * CompactionFoldMechanism,自由文本仅兜底——kernel 扩值不 bump 契约
1167
+ * (compact_boundary trigger 同先例)。
1168
+ */
1169
+ mechanism: z.ZodOptional<z.ZodString>;
1170
+ /**
1171
+ * 压缩前落盘的上下文快照 id(contract-v0.23,doc/116 §4.1 / doc/117 K-4·K-5):
1172
+ * 装配层在本次压缩前写 pre_compaction Checkpoint 时携带,与
1173
+ * session.checkpointed / journal compact_boundary.checkpointId 三方互指;
1174
+ * 未落快照(选项关闭或未接线)缺席。消费方忽略无害。
1175
+ */
1176
+ checkpointId: z.ZodOptional<z.ZodString>;
1177
+ }, "strip", z.ZodTypeAny, {
1178
+ type: "session.compacted";
1179
+ removedRange: [number, number];
1180
+ compactionId?: string | undefined;
1181
+ removedIndices?: number[] | undefined;
1182
+ keptPinnedCount?: number | undefined;
1183
+ mechanism?: string | undefined;
1184
+ checkpointId?: string | undefined;
1185
+ }, {
1186
+ type: "session.compacted";
1187
+ removedRange: [number, number];
1188
+ compactionId?: string | undefined;
1189
+ removedIndices?: number[] | undefined;
1190
+ keptPinnedCount?: number | undefined;
1191
+ mechanism?: string | undefined;
1192
+ checkpointId?: string | undefined;
1193
+ }>, z.ZodObject<{
1194
+ type: z.ZodLiteral<"session.checkpointed">;
1195
+ checkpointId: z.ZodString;
1196
+ trigger: z.ZodString;
1197
+ label: z.ZodOptional<z.ZodString>;
1198
+ messageCount: z.ZodNumber;
1199
+ }, "strip", z.ZodTypeAny, {
1200
+ type: "session.checkpointed";
1201
+ checkpointId: string;
1202
+ trigger: string;
1203
+ messageCount: number;
1204
+ label?: string | undefined;
1205
+ }, {
1206
+ type: "session.checkpointed";
1207
+ checkpointId: string;
1208
+ trigger: string;
1209
+ messageCount: number;
1210
+ label?: string | undefined;
1211
+ }>, z.ZodObject<{
1212
+ type: z.ZodLiteral<"session.restored">;
1213
+ checkpointId: z.ZodString;
1214
+ fromMessages: z.ZodNumber;
1215
+ toMessages: z.ZodNumber;
1216
+ }, "strip", z.ZodTypeAny, {
1217
+ type: "session.restored";
1218
+ checkpointId: string;
1219
+ fromMessages: number;
1220
+ toMessages: number;
1221
+ }, {
1222
+ type: "session.restored";
1223
+ checkpointId: string;
1224
+ fromMessages: number;
1225
+ toMessages: number;
1226
+ }>, z.ZodObject<{
1227
+ type: z.ZodLiteral<"session.forked">;
1228
+ sourceSessionId: z.ZodString;
1229
+ checkpointId: z.ZodString;
1230
+ sessionId: z.ZodString;
1231
+ }, "strip", z.ZodTypeAny, {
1232
+ type: "session.forked";
1233
+ sessionId: string;
1234
+ checkpointId: string;
1235
+ sourceSessionId: string;
1236
+ }, {
1237
+ type: "session.forked";
1238
+ sessionId: string;
1239
+ checkpointId: string;
1240
+ sourceSessionId: string;
1241
+ }>, z.ZodObject<{
1242
+ type: z.ZodLiteral<"session.microcompacted">;
1243
+ /**
1244
+ * 本次存根化淘汰(evict 迁移)的 tool_result 块数。contract-v0.18 起
1245
+ * ≥0(纯剪枝屏障为 0);与 prunedBlocks 不同时为零。
1246
+ */
1247
+ evictedBlocks: z.ZodNumber;
1248
+ /** 估算口径淘汰回收量(tokens;Σ 每块存根化前后估算差,非权威计量) */
1249
+ recoveredTokens: z.ZodNumber;
1250
+ /** 同步执行墙钟耗时(ms;签发方计时,观测口径,不参与决策) */
1251
+ durationMs: z.ZodNumber;
1252
+ /** 淘汰前本地估算占用(tokens;水位审计) */
1253
+ beforeTokens: z.ZodOptional<z.ZodNumber>;
1254
+ /** 淘汰后本地估算占用(tokens) */
1255
+ afterTokens: z.ZodOptional<z.ZodNumber>;
1256
+ /**
1257
+ * 本次原位剪枝(prune 迁移:头+尾+标记收束)的 tool_result 块数
1258
+ * (contract-v0.18;零剪枝屏障键缺席)。
1259
+ */
1260
+ prunedBlocks: z.ZodOptional<z.ZodNumber>;
1261
+ /** 估算口径剪枝回收量(tokens;与 recoveredTokens 分账不重叠) */
1262
+ pruneRecoveredTokens: z.ZodOptional<z.ZodNumber>;
1263
+ }, "strip", z.ZodTypeAny, {
1264
+ type: "session.microcompacted";
1265
+ evictedBlocks: number;
1266
+ recoveredTokens: number;
1267
+ durationMs: number;
1268
+ beforeTokens?: number | undefined;
1269
+ afterTokens?: number | undefined;
1270
+ prunedBlocks?: number | undefined;
1271
+ pruneRecoveredTokens?: number | undefined;
1272
+ }, {
1273
+ type: "session.microcompacted";
1274
+ evictedBlocks: number;
1275
+ recoveredTokens: number;
1276
+ durationMs: number;
1277
+ beforeTokens?: number | undefined;
1278
+ afterTokens?: number | undefined;
1279
+ prunedBlocks?: number | undefined;
1280
+ pruneRecoveredTokens?: number | undefined;
1281
+ }>, z.ZodObject<{
1282
+ type: z.ZodLiteral<"session.locale.changed">;
1283
+ locale: z.ZodString;
1284
+ previous: z.ZodString;
1285
+ }, "strip", z.ZodTypeAny, {
1286
+ type: "session.locale.changed";
1287
+ locale: string;
1288
+ previous: string;
1289
+ }, {
1290
+ type: "session.locale.changed";
1291
+ locale: string;
1292
+ previous: string;
1293
+ }>, z.ZodObject<{
1294
+ type: z.ZodLiteral<"session.output_style.changed">;
1295
+ style: z.ZodString;
1296
+ previous: z.ZodString;
1297
+ }, "strip", z.ZodTypeAny, {
1298
+ type: "session.output_style.changed";
1299
+ previous: string;
1300
+ style: string;
1301
+ }, {
1302
+ type: "session.output_style.changed";
1303
+ previous: string;
1304
+ style: string;
1305
+ }>, z.ZodObject<{
1306
+ type: z.ZodLiteral<"session.workspace_trust.changed">;
1307
+ trusted: z.ZodBoolean;
1308
+ persisted: z.ZodOptional<z.ZodBoolean>;
1309
+ }, "strip", z.ZodTypeAny, {
1310
+ type: "session.workspace_trust.changed";
1311
+ trusted: boolean;
1312
+ persisted?: boolean | undefined;
1313
+ }, {
1314
+ type: "session.workspace_trust.changed";
1315
+ trusted: boolean;
1316
+ persisted?: boolean | undefined;
1317
+ }>, z.ZodObject<{
1318
+ type: z.ZodLiteral<"session.cwd_changed">;
1319
+ from: z.ZodString;
1320
+ to: z.ZodString;
1321
+ }, "strip", z.ZodTypeAny, {
1322
+ type: "session.cwd_changed";
1323
+ from: string;
1324
+ to: string;
1325
+ }, {
1326
+ type: "session.cwd_changed";
1327
+ from: string;
1328
+ to: string;
1329
+ }>, z.ZodObject<{
1330
+ type: z.ZodLiteral<"session.events_dropped">;
1331
+ /** 累计丢弃条数(≥1;重复溢出只更新累计) */
1332
+ droppedCount: z.ZodNumber;
1333
+ /** 最近一次触发的上界 */
1334
+ reason: z.ZodEnum<["count_limit", "bytes_limit"]>;
1335
+ /** 丢弃发生的队列归属;词表首值 'sdk.events',自由文本兜底(扩词不 bump) */
1336
+ scope: z.ZodString;
1337
+ /** 累计丢弃近似度量(签发方有账才填) */
1338
+ droppedBytes: z.ZodOptional<z.ZodNumber>;
1339
+ /** 首条被丢事件的 seq */
1340
+ firstDroppedSeq: z.ZodOptional<z.ZodNumber>;
1341
+ /** 末条被丢事件的 seq(≥ firstDroppedSeq) */
1342
+ lastDroppedSeq: z.ZodOptional<z.ZodNumber>;
1343
+ /** 生效条数上界(Infinity 不可 JSON 化 → 缺席 = 不限) */
1344
+ maxEvents: z.ZodOptional<z.ZodNumber>;
1345
+ /** 生效近似度量上界(同上) */
1346
+ maxBytes: z.ZodOptional<z.ZodNumber>;
1347
+ }, "strip", z.ZodTypeAny, {
1348
+ type: "session.events_dropped";
1349
+ droppedCount: number;
1350
+ reason: "count_limit" | "bytes_limit";
1351
+ scope: string;
1352
+ droppedBytes?: number | undefined;
1353
+ firstDroppedSeq?: number | undefined;
1354
+ lastDroppedSeq?: number | undefined;
1355
+ maxEvents?: number | undefined;
1356
+ maxBytes?: number | undefined;
1357
+ }, {
1358
+ type: "session.events_dropped";
1359
+ droppedCount: number;
1360
+ reason: "count_limit" | "bytes_limit";
1361
+ scope: string;
1362
+ droppedBytes?: number | undefined;
1363
+ firstDroppedSeq?: number | undefined;
1364
+ lastDroppedSeq?: number | undefined;
1365
+ maxEvents?: number | undefined;
1366
+ maxBytes?: number | undefined;
1367
+ }>, z.ZodObject<{
1368
+ type: z.ZodLiteral<"session.ended">;
1369
+ }, "strip", z.ZodTypeAny, {
1370
+ type: "session.ended";
1371
+ }, {
1372
+ type: "session.ended";
1373
+ }>, z.ZodObject<{
1374
+ type: z.ZodLiteral<"turn.started">;
1375
+ }, "strip", z.ZodTypeAny, {
1376
+ type: "turn.started";
1377
+ }, {
1378
+ type: "turn.started";
1379
+ }>, z.ZodObject<{
1380
+ type: z.ZodLiteral<"turn.completed">;
1381
+ reason: z.ZodEnum<["completed", "blocking_limit", "aborted_streaming", "aborted_tools", "model_error", "prompt_too_long", "max_turns", "max_tool_rounds", "injection_limit", "hook_stopped", "structured_output", "timeout", "shutdown", "budget_exceeded", "stop_hook_limit", "internal_error", "client_gone"]>;
1382
+ }, "strip", z.ZodTypeAny, {
1383
+ type: "turn.completed";
1384
+ reason: "completed" | "blocking_limit" | "aborted_streaming" | "aborted_tools" | "model_error" | "prompt_too_long" | "max_turns" | "max_tool_rounds" | "injection_limit" | "hook_stopped" | "structured_output" | "timeout" | "shutdown" | "budget_exceeded" | "stop_hook_limit" | "internal_error" | "client_gone";
1385
+ }, {
1386
+ type: "turn.completed";
1387
+ reason: "completed" | "blocking_limit" | "aborted_streaming" | "aborted_tools" | "model_error" | "prompt_too_long" | "max_turns" | "max_tool_rounds" | "injection_limit" | "hook_stopped" | "structured_output" | "timeout" | "shutdown" | "budget_exceeded" | "stop_hook_limit" | "internal_error" | "client_gone";
1388
+ }>, z.ZodObject<{
1389
+ type: z.ZodLiteral<"turn.aborted">;
1390
+ reason: z.ZodEnum<["completed", "blocking_limit", "aborted_streaming", "aborted_tools", "model_error", "prompt_too_long", "max_turns", "max_tool_rounds", "injection_limit", "hook_stopped", "structured_output", "timeout", "shutdown", "budget_exceeded", "stop_hook_limit", "internal_error", "client_gone"]>;
1391
+ }, "strip", z.ZodTypeAny, {
1392
+ type: "turn.aborted";
1393
+ reason: "completed" | "blocking_limit" | "aborted_streaming" | "aborted_tools" | "model_error" | "prompt_too_long" | "max_turns" | "max_tool_rounds" | "injection_limit" | "hook_stopped" | "structured_output" | "timeout" | "shutdown" | "budget_exceeded" | "stop_hook_limit" | "internal_error" | "client_gone";
1394
+ }, {
1395
+ type: "turn.aborted";
1396
+ reason: "completed" | "blocking_limit" | "aborted_streaming" | "aborted_tools" | "model_error" | "prompt_too_long" | "max_turns" | "max_tool_rounds" | "injection_limit" | "hook_stopped" | "structured_output" | "timeout" | "shutdown" | "budget_exceeded" | "stop_hook_limit" | "internal_error" | "client_gone";
1397
+ }>, z.ZodObject<{
1398
+ type: z.ZodLiteral<"turn.error">;
1399
+ scope: z.ZodString;
1400
+ message: z.ZodString;
1401
+ recoverable: z.ZodBoolean;
1402
+ /**
1403
+ * 错误类别标记(P-CTX2 K10,G-A8 纯增量可选键):scope='model' 时为
1404
+ * IRErrorKind 透传('policy_denied'/'context_overflow'/'server'/…),
1405
+ * 表面层据此做链路归属([端点]/[平台])与自救指引模板化。缺席 =
1406
+ * 旧签发方或非模型 scope,渲染回落 scope 归属。词表锚定 IRErrorKind,
1407
+ * 自由文本仅兜底——kind 扩值不 bump 契约(compacted.mechanism 同先例)。
1408
+ */
1409
+ errorKind: z.ZodOptional<z.ZodString>;
1410
+ /**
1411
+ * 结构化事实位(contract-v0.26;加法可选键):scope='model' 时
1412
+ * = IR error 事件 `detail` 透传(providers 自服务端信封带出的机器可判事实;首个取值
1413
+ * `{ scope: 'plan' }` = 平台套餐配额拒绝,与 HTTP 面 `error.detail.scope`
1414
+ * 同键同值)。三端 reducer 归约:`recoverable:true` → `SessionNotice.detail`,失败形 →
1415
+ * `ErrorView.detail`;端侧 `ErrorEnvelope.scope` 取值器同一读法。缺席 = 无附加事实
1416
+ * (既有事件体字节零变)。值恒不含 endUser 身份 / 令牌 / 内部 id。
1417
+ */
1418
+ detail: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1419
+ }, "strip", z.ZodTypeAny, {
1420
+ message: string;
1421
+ type: "turn.error";
1422
+ recoverable: boolean;
1423
+ scope: string;
1424
+ detail?: Record<string, unknown> | undefined;
1425
+ errorKind?: string | undefined;
1426
+ }, {
1427
+ message: string;
1428
+ type: "turn.error";
1429
+ recoverable: boolean;
1430
+ scope: string;
1431
+ detail?: Record<string, unknown> | undefined;
1432
+ errorKind?: string | undefined;
1433
+ }>, z.ZodObject<{
1434
+ type: z.ZodLiteral<"msg.block.start">;
1435
+ index: z.ZodNumber;
1436
+ blockType: z.ZodString;
1437
+ }, "strip", z.ZodTypeAny, {
1438
+ type: "msg.block.start";
1439
+ index: number;
1440
+ blockType: string;
1441
+ }, {
1442
+ type: "msg.block.start";
1443
+ index: number;
1444
+ blockType: string;
1445
+ }>, z.ZodObject<{
1446
+ type: z.ZodLiteral<"msg.text.delta">;
1447
+ index: z.ZodNumber;
1448
+ text: z.ZodString;
1449
+ }, "strip", z.ZodTypeAny, {
1450
+ type: "msg.text.delta";
1451
+ text: string;
1452
+ index: number;
1453
+ }, {
1454
+ type: "msg.text.delta";
1455
+ text: string;
1456
+ index: number;
1457
+ }>, z.ZodObject<{
1458
+ type: z.ZodLiteral<"msg.thinking.delta">;
1459
+ index: z.ZodNumber;
1460
+ text: z.ZodString;
1461
+ }, "strip", z.ZodTypeAny, {
1462
+ type: "msg.thinking.delta";
1463
+ text: string;
1464
+ index: number;
1465
+ }, {
1466
+ type: "msg.thinking.delta";
1467
+ text: string;
1468
+ index: number;
1469
+ }>, z.ZodObject<{
1470
+ type: z.ZodLiteral<"msg.block.end">;
1471
+ index: z.ZodNumber;
1472
+ }, "strip", z.ZodTypeAny, {
1473
+ type: "msg.block.end";
1474
+ index: number;
1475
+ }, {
1476
+ type: "msg.block.end";
1477
+ index: number;
1478
+ }>, z.ZodObject<{
1479
+ type: z.ZodLiteral<"msg.retracted">;
1480
+ index: z.ZodNumber;
1481
+ }, "strip", z.ZodTypeAny, {
1482
+ type: "msg.retracted";
1483
+ index: number;
1484
+ }, {
1485
+ type: "msg.retracted";
1486
+ index: number;
1487
+ }>, z.ZodObject<{
1488
+ type: z.ZodLiteral<"tool.proposed">;
1489
+ toolCallId: z.ZodString;
1490
+ name: z.ZodString;
1491
+ args: z.ZodUnknown;
1492
+ }, "strip", z.ZodTypeAny, {
1493
+ type: "tool.proposed";
1494
+ name: string;
1495
+ toolCallId: string;
1496
+ args?: unknown;
1497
+ }, {
1498
+ type: "tool.proposed";
1499
+ name: string;
1500
+ toolCallId: string;
1501
+ args?: unknown;
1502
+ }>, z.ZodObject<{
1503
+ type: z.ZodLiteral<"tool.permission.requested">;
1504
+ toolCallId: z.ZodString;
1505
+ name: z.ZodString;
1506
+ }, "strip", z.ZodTypeAny, {
1507
+ type: "tool.permission.requested";
1508
+ name: string;
1509
+ toolCallId: string;
1510
+ }, {
1511
+ type: "tool.permission.requested";
1512
+ name: string;
1513
+ toolCallId: string;
1514
+ }>, z.ZodObject<{
1515
+ type: z.ZodLiteral<"tool.permission.decided">;
1516
+ toolCallId: z.ZodString;
1517
+ decision: z.ZodEnum<["allow", "deny", "ask"]>;
1518
+ decisionSource: z.ZodEnum<["rule", "user", "mode", "policy", "hook", "builtin", "classifier"]>;
1519
+ /**
1520
+ * 命中的规则原文(如 `Shell(git *)`;contract-v0.2)。
1521
+ * 审计链由此可答"哪条规则拒的";模式短路/兜底 ask 等无规则命中时不落键。
1522
+ */
1523
+ matchedRule: z.ZodOptional<z.ZodString>;
1524
+ }, "strip", z.ZodTypeAny, {
1525
+ type: "tool.permission.decided";
1526
+ toolCallId: string;
1527
+ decision: "allow" | "deny" | "ask";
1528
+ decisionSource: "user" | "mode" | "classifier" | "policy" | "rule" | "hook" | "builtin";
1529
+ matchedRule?: string | undefined;
1530
+ }, {
1531
+ type: "tool.permission.decided";
1532
+ toolCallId: string;
1533
+ decision: "allow" | "deny" | "ask";
1534
+ decisionSource: "user" | "mode" | "classifier" | "policy" | "rule" | "hook" | "builtin";
1535
+ matchedRule?: string | undefined;
1536
+ }>, z.ZodObject<{
1537
+ type: z.ZodLiteral<"tool.started">;
1538
+ toolCallId: z.ZodString;
1539
+ }, "strip", z.ZodTypeAny, {
1540
+ type: "tool.started";
1541
+ toolCallId: string;
1542
+ }, {
1543
+ type: "tool.started";
1544
+ toolCallId: string;
1545
+ }>, z.ZodObject<{
1546
+ type: z.ZodLiteral<"tool.progress">;
1547
+ toolCallId: z.ZodString;
1548
+ message: z.ZodString;
1549
+ }, "strip", z.ZodTypeAny, {
1550
+ message: string;
1551
+ type: "tool.progress";
1552
+ toolCallId: string;
1553
+ }, {
1554
+ message: string;
1555
+ type: "tool.progress";
1556
+ toolCallId: string;
1557
+ }>, z.ZodObject<{
1558
+ type: z.ZodLiteral<"tool.output.delta">;
1559
+ toolCallId: z.ZodString;
1560
+ chunk: z.ZodString;
1561
+ }, "strip", z.ZodTypeAny, {
1562
+ type: "tool.output.delta";
1563
+ toolCallId: string;
1564
+ chunk: string;
1565
+ }, {
1566
+ type: "tool.output.delta";
1567
+ toolCallId: string;
1568
+ chunk: string;
1569
+ }>, z.ZodObject<{
1570
+ type: z.ZodLiteral<"tool.completed">;
1571
+ toolCallId: z.ZodString;
1572
+ durationMs: z.ZodNumber;
1573
+ /**
1574
+ * ToolResult.data 透传位(contract-v0.3):工具产出的结构化
1575
+ * 渲染数据(AGENTS.md「工具只产出结构化数据」铁律的事件流出口)。
1576
+ * 表面层按工具名注册渲染器消费;无 data 的工具不落键,消费方忽略无害。
1577
+ */
1578
+ data: z.ZodOptional<z.ZodUnknown>;
1579
+ /**
1580
+ * 模型可见文本投影(contract-v0.8):喂回模型的 tool_result
1581
+ * 文本(截断后形态)。cc-compat stream-json 包络与 SDK 消费方由此拿到
1582
+ * 与模型一致的结果文本,不必反推 data;与 data 正交(结构化渲染 vs
1583
+ * 模型文本)。大结果按工具结果预算截断后的文本为准,不另存全量。
1584
+ */
1585
+ content: z.ZodOptional<z.ZodString>;
1586
+ /**
1587
+ * 工具结构化失败位(contract-v0.25):`ToolResult.isError`
1588
+ * 透传。工具以 **return isError** 表达的业务级失败(非零退出 / 用户中断 / SSRF 拒 /
1589
+ * 媒体错误形)与 throw 径的 `tool.failed` 在表面层归约为同一 failed 态——此前 TUI /
1590
+ * sdk / 端侧对这类结果一律 ✓。缺席 = 旧签发方或成功完成(completed 语义不变);
1591
+ * 消费方(TUI / sdk / Android / iOS reducer)只判 `isError === true → failed`。
1592
+ * 纯可选加法,包络 `v` 不 bump;端侧 vendored 同步另行跟进。
1593
+ */
1594
+ isError: z.ZodOptional<z.ZodBoolean>;
1595
+ }, "strip", z.ZodTypeAny, {
1596
+ type: "tool.completed";
1597
+ durationMs: number;
1598
+ toolCallId: string;
1599
+ data?: unknown;
1600
+ content?: string | undefined;
1601
+ isError?: boolean | undefined;
1602
+ }, {
1603
+ type: "tool.completed";
1604
+ durationMs: number;
1605
+ toolCallId: string;
1606
+ data?: unknown;
1607
+ content?: string | undefined;
1608
+ isError?: boolean | undefined;
1609
+ }>, z.ZodObject<{
1610
+ type: z.ZodLiteral<"tool.failed">;
1611
+ toolCallId: z.ZodString;
1612
+ errorType: z.ZodEnum<["invalid_args", "unknown_tool", "timeout", "aborted", "execution_error"]>;
1613
+ message: z.ZodString;
1614
+ }, "strip", z.ZodTypeAny, {
1615
+ message: string;
1616
+ type: "tool.failed";
1617
+ toolCallId: string;
1618
+ errorType: "aborted" | "timeout" | "invalid_args" | "unknown_tool" | "execution_error";
1619
+ }, {
1620
+ message: string;
1621
+ type: "tool.failed";
1622
+ toolCallId: string;
1623
+ errorType: "aborted" | "timeout" | "invalid_args" | "unknown_tool" | "execution_error";
1624
+ }>, z.ZodObject<{
1625
+ type: z.ZodLiteral<"agent.spawned">;
1626
+ agentId: z.ZodString;
1627
+ parentAgentId: z.ZodOptional<z.ZodString>;
1628
+ }, "strip", z.ZodTypeAny, {
1629
+ type: "agent.spawned";
1630
+ agentId: string;
1631
+ parentAgentId?: string | undefined;
1632
+ }, {
1633
+ type: "agent.spawned";
1634
+ agentId: string;
1635
+ parentAgentId?: string | undefined;
1636
+ }>, z.ZodObject<{
1637
+ type: z.ZodLiteral<"agent.progress">;
1638
+ agentId: z.ZodString;
1639
+ message: z.ZodString;
1640
+ }, "strip", z.ZodTypeAny, {
1641
+ message: string;
1642
+ type: "agent.progress";
1643
+ agentId: string;
1644
+ }, {
1645
+ message: string;
1646
+ type: "agent.progress";
1647
+ agentId: string;
1648
+ }>, z.ZodObject<{
1649
+ type: z.ZodLiteral<"agent.completed">;
1650
+ agentId: z.ZodString;
1651
+ }, "strip", z.ZodTypeAny, {
1652
+ type: "agent.completed";
1653
+ agentId: string;
1654
+ }, {
1655
+ type: "agent.completed";
1656
+ agentId: string;
1657
+ }>, z.ZodObject<{
1658
+ type: z.ZodLiteral<"agent.followup">;
1659
+ agentId: z.ZodString;
1660
+ messageId: z.ZodString;
1661
+ }, "strip", z.ZodTypeAny, {
1662
+ type: "agent.followup";
1663
+ agentId: string;
1664
+ messageId: string;
1665
+ }, {
1666
+ type: "agent.followup";
1667
+ agentId: string;
1668
+ messageId: string;
1669
+ }>, z.ZodObject<{
1670
+ type: z.ZodLiteral<"agent.report">;
1671
+ agentId: z.ZodString;
1672
+ message: z.ZodString;
1673
+ wake: z.ZodBoolean;
1674
+ }, "strip", z.ZodTypeAny, {
1675
+ message: string;
1676
+ type: "agent.report";
1677
+ agentId: string;
1678
+ wake: boolean;
1679
+ }, {
1680
+ message: string;
1681
+ type: "agent.report";
1682
+ agentId: string;
1683
+ wake: boolean;
1684
+ }>, z.ZodObject<{
1685
+ type: z.ZodLiteral<"agent.settled">;
1686
+ agentId: z.ZodString;
1687
+ outcome: z.ZodString;
1688
+ }, "strip", z.ZodTypeAny, {
1689
+ type: "agent.settled";
1690
+ agentId: string;
1691
+ outcome: string;
1692
+ }, {
1693
+ type: "agent.settled";
1694
+ agentId: string;
1695
+ outcome: string;
1696
+ }>, z.ZodObject<{
1697
+ type: z.ZodLiteral<"agent.interrupted">;
1698
+ agentId: z.ZodString;
1699
+ by: z.ZodEnum<["user", "parent", "system"]>;
1700
+ }, "strip", z.ZodTypeAny, {
1701
+ type: "agent.interrupted";
1702
+ agentId: string;
1703
+ by: "user" | "system" | "parent";
1704
+ }, {
1705
+ type: "agent.interrupted";
1706
+ agentId: string;
1707
+ by: "user" | "system" | "parent";
1708
+ }>, z.ZodObject<{
1709
+ type: z.ZodLiteral<"hook.triggered">;
1710
+ event: z.ZodString;
1711
+ hookId: z.ZodString;
1712
+ }, "strip", z.ZodTypeAny, {
1713
+ type: "hook.triggered";
1714
+ event: string;
1715
+ hookId: string;
1716
+ }, {
1717
+ type: "hook.triggered";
1718
+ event: string;
1719
+ hookId: string;
1720
+ }>, z.ZodObject<{
1721
+ type: z.ZodLiteral<"hook.completed">;
1722
+ hookId: z.ZodString;
1723
+ event: z.ZodOptional<z.ZodString>;
1724
+ durationMs: z.ZodOptional<z.ZodNumber>;
1725
+ status: z.ZodOptional<z.ZodEnum<["ok", "error", "timeout", "aborted"]>>;
1726
+ }, "strip", z.ZodTypeAny, {
1727
+ type: "hook.completed";
1728
+ hookId: string;
1729
+ status?: "aborted" | "error" | "timeout" | "ok" | undefined;
1730
+ durationMs?: number | undefined;
1731
+ event?: string | undefined;
1732
+ }, {
1733
+ type: "hook.completed";
1734
+ hookId: string;
1735
+ status?: "aborted" | "error" | "timeout" | "ok" | undefined;
1736
+ durationMs?: number | undefined;
1737
+ event?: string | undefined;
1738
+ }>, z.ZodObject<{
1739
+ type: z.ZodLiteral<"hook.blocked">;
1740
+ hookId: z.ZodString;
1741
+ event: z.ZodOptional<z.ZodString>;
1742
+ reason: z.ZodString;
1743
+ durationMs: z.ZodOptional<z.ZodNumber>;
1744
+ }, "strip", z.ZodTypeAny, {
1745
+ type: "hook.blocked";
1746
+ reason: string;
1747
+ hookId: string;
1748
+ durationMs?: number | undefined;
1749
+ event?: string | undefined;
1750
+ }, {
1751
+ type: "hook.blocked";
1752
+ reason: string;
1753
+ hookId: string;
1754
+ durationMs?: number | undefined;
1755
+ event?: string | undefined;
1756
+ }>, z.ZodObject<{
1757
+ type: z.ZodLiteral<"cost.usage.updated">;
1758
+ model: z.ZodString;
1759
+ usage: z.ZodObject<{
1760
+ inputTokens: z.ZodNumber;
1761
+ outputTokens: z.ZodNumber;
1762
+ cacheReadInputTokens: z.ZodOptional<z.ZodNumber>;
1763
+ cacheCreationInputTokens: z.ZodOptional<z.ZodNumber>;
1764
+ reasoningOutputTokens: z.ZodOptional<z.ZodNumber>;
1765
+ cacheDeletedInputTokens: z.ZodOptional<z.ZodNumber>;
1766
+ dims: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
1767
+ saved: z.ZodOptional<z.ZodString>;
1768
+ }, "strip", z.ZodTypeAny, {
1769
+ inputTokens: number;
1770
+ outputTokens: number;
1771
+ cacheReadInputTokens?: number | undefined;
1772
+ cacheCreationInputTokens?: number | undefined;
1773
+ reasoningOutputTokens?: number | undefined;
1774
+ cacheDeletedInputTokens?: number | undefined;
1775
+ dims?: Record<string, number> | undefined;
1776
+ saved?: string | undefined;
1777
+ }, {
1778
+ inputTokens: number;
1779
+ outputTokens: number;
1780
+ cacheReadInputTokens?: number | undefined;
1781
+ cacheCreationInputTokens?: number | undefined;
1782
+ reasoningOutputTokens?: number | undefined;
1783
+ cacheDeletedInputTokens?: number | undefined;
1784
+ dims?: Record<string, number> | undefined;
1785
+ saved?: string | undefined;
1786
+ }>;
1787
+ costUsd: z.ZodOptional<z.ZodNumber>;
1788
+ /**
1789
+ * 上下文窗口分母(contract-v0.3):签发方(查询环)从装配层
1790
+ * 注入的 provider capability.maxContext 透传。状态栏水位 = 最近 prompt
1791
+ * 规模 / 本值;缺省时表面层隐藏水位段(或回退装配注入的静态值)。
1792
+ * 随 usage 更新携带——/model 热切换后分母随下一轮事件自动矫正。
1793
+ */
1794
+ contextWindowTokens: z.ZodOptional<z.ZodNumber>;
1795
+ /** 签发方 ResolvedModel.provider 透传;缺省时消费端可按 model 反查 */
1796
+ provider: z.ZodOptional<z.ZodString>;
1797
+ /** 子代理归因(Task 链上抛时由运行器注入;嵌套保留最内层) */
1798
+ agentId: z.ZodOptional<z.ZodString>;
1799
+ /** 按次计费/按调用归因的工具调用 id(如 Task、WebSearch) */
1800
+ toolUseId: z.ZodOptional<z.ZodString>;
1801
+ /**
1802
+ * 用量目的:非对话主流的模型调用标注来源。词表:'compaction'(上下文
1803
+ * 压缩轮)/ 'title'(会话标题生成,contract-v0.8
1804
+ * 扩容;辅助任务降档的归因面)/ 'permission_classifier'(LLM 权限
1805
+ * 分类器调用)/ 'memory'(记忆四面 fork:提取/固化/晋升/召回
1806
+ * 选择;随本地记账闭环扩词)。新目的先扩词表再签发
1807
+ * (自由文本仅兜底);缺省即对话主流。
1808
+ *
1809
+ * 词表分叉注记:同一分类器子系统在 request-
1810
+ * measurement 观测面与 TWP 出线面用词 'classifier'(kernel context/
1811
+ * request-measurement.ts RequestPurpose、providers twp/contract.ts
1812
+ * TWP_PURPOSE_VALUES——现为扁平单表,分版常量已退役),与本词表
1813
+ * 'permission_classifier' 属两套近义词并存;且本词当前全仓零签发方
1814
+ * (分类器 usage 走遥测与测量面,不落本地 cost 事件)。统一到单一词属
1815
+ * 契约面决策,待定;届时 kernel cost/tracker.ts KNOWN_COST_PURPOSES
1816
+ * 须同步,勿单侧改词。
1817
+ */
1818
+ purpose: z.ZodOptional<z.ZodString>;
1819
+ }, "strip", z.ZodTypeAny, {
1820
+ type: "cost.usage.updated";
1821
+ model: string;
1822
+ usage: {
1823
+ inputTokens: number;
1824
+ outputTokens: number;
1825
+ cacheReadInputTokens?: number | undefined;
1826
+ cacheCreationInputTokens?: number | undefined;
1827
+ reasoningOutputTokens?: number | undefined;
1828
+ cacheDeletedInputTokens?: number | undefined;
1829
+ dims?: Record<string, number> | undefined;
1830
+ saved?: string | undefined;
1831
+ };
1832
+ provider?: string | undefined;
1833
+ agentId?: string | undefined;
1834
+ costUsd?: number | undefined;
1835
+ contextWindowTokens?: number | undefined;
1836
+ toolUseId?: string | undefined;
1837
+ purpose?: string | undefined;
1838
+ }, {
1839
+ type: "cost.usage.updated";
1840
+ model: string;
1841
+ usage: {
1842
+ inputTokens: number;
1843
+ outputTokens: number;
1844
+ cacheReadInputTokens?: number | undefined;
1845
+ cacheCreationInputTokens?: number | undefined;
1846
+ reasoningOutputTokens?: number | undefined;
1847
+ cacheDeletedInputTokens?: number | undefined;
1848
+ dims?: Record<string, number> | undefined;
1849
+ saved?: string | undefined;
1850
+ };
1851
+ provider?: string | undefined;
1852
+ agentId?: string | undefined;
1853
+ costUsd?: number | undefined;
1854
+ contextWindowTokens?: number | undefined;
1855
+ toolUseId?: string | undefined;
1856
+ purpose?: string | undefined;
1857
+ }>, z.ZodObject<{
1858
+ type: z.ZodLiteral<"cost.cache_miss">;
1859
+ model: z.ZodString;
1860
+ /** 本轮未命中缓存的输入规模(prompt tokens) */
1861
+ inputTokens: z.ZodNumber;
1862
+ /** 触发告警的输入规模阈值(签发方配置;可观测性) */
1863
+ threshold: z.ZodOptional<z.ZodNumber>;
1864
+ }, "strip", z.ZodTypeAny, {
1865
+ type: "cost.cache_miss";
1866
+ model: string;
1867
+ inputTokens: number;
1868
+ threshold?: number | undefined;
1869
+ }, {
1870
+ type: "cost.cache_miss";
1871
+ model: string;
1872
+ inputTokens: number;
1873
+ threshold?: number | undefined;
1874
+ }>, z.ZodObject<{
1875
+ type: z.ZodLiteral<"cost.model.mismatch">;
1876
+ /** 请求申报模型(IRRequest.model.model) */
1877
+ requested: z.ZodString;
1878
+ /** message_start 实回模型 */
1879
+ actual: z.ZodString;
1880
+ /** 请求申报 provider(签发方 ResolvedModel.provider 透传;归因辅助) */
1881
+ provider: z.ZodOptional<z.ZodString>;
1882
+ }, "strip", z.ZodTypeAny, {
1883
+ type: "cost.model.mismatch";
1884
+ requested: string;
1885
+ actual: string;
1886
+ provider?: string | undefined;
1887
+ }, {
1888
+ type: "cost.model.mismatch";
1889
+ requested: string;
1890
+ actual: string;
1891
+ provider?: string | undefined;
1892
+ }>, z.ZodObject<{
1893
+ type: z.ZodLiteral<"cost.provider.switched">;
1894
+ from: z.ZodString;
1895
+ to: z.ZodString;
1896
+ /** 切换原因;词表锚定 IRErrorKind(rate_limited/auth/server/…),自由文本仅兜底 */
1897
+ reason: z.ZodString;
1898
+ /** 全链尝试的 entry 数(含最终命中/耗尽的那个) */
1899
+ attempts: z.ZodOptional<z.ZodNumber>;
1900
+ /** 各落选 entry 的失败轨迹(按链序;kind 复用 IR 错误归一化枚举) */
1901
+ failures: z.ZodOptional<z.ZodArray<z.ZodObject<{
1902
+ provider: z.ZodString;
1903
+ kind: z.ZodEnum<["rate_limited", "context_overflow", "auth", "server", "network", "connect", "stream_interrupted", "invalid_request", "policy_denied"]>;
1904
+ }, "strip", z.ZodTypeAny, {
1905
+ provider: string;
1906
+ kind: "rate_limited" | "context_overflow" | "auth" | "server" | "network" | "connect" | "stream_interrupted" | "invalid_request" | "policy_denied";
1907
+ }, {
1908
+ provider: string;
1909
+ kind: "rate_limited" | "context_overflow" | "auth" | "server" | "network" | "connect" | "stream_interrupted" | "invalid_request" | "policy_denied";
1910
+ }>, "many">>;
1911
+ }, "strip", z.ZodTypeAny, {
1912
+ type: "cost.provider.switched";
1913
+ from: string;
1914
+ to: string;
1915
+ reason: string;
1916
+ attempts?: number | undefined;
1917
+ failures?: {
1918
+ provider: string;
1919
+ kind: "rate_limited" | "context_overflow" | "auth" | "server" | "network" | "connect" | "stream_interrupted" | "invalid_request" | "policy_denied";
1920
+ }[] | undefined;
1921
+ }, {
1922
+ type: "cost.provider.switched";
1923
+ from: string;
1924
+ to: string;
1925
+ reason: string;
1926
+ attempts?: number | undefined;
1927
+ failures?: {
1928
+ provider: string;
1929
+ kind: "rate_limited" | "context_overflow" | "auth" | "server" | "network" | "connect" | "stream_interrupted" | "invalid_request" | "policy_denied";
1930
+ }[] | undefined;
1931
+ }>, z.ZodObject<{
1932
+ type: z.ZodLiteral<"mcp.connected">;
1933
+ server: z.ZodString;
1934
+ transport: z.ZodEnum<["stdio", "http"]>;
1935
+ protocolVersion: z.ZodString;
1936
+ }, "strip", z.ZodTypeAny, {
1937
+ type: "mcp.connected";
1938
+ server: string;
1939
+ transport: "http" | "stdio";
1940
+ protocolVersion: string;
1941
+ }, {
1942
+ type: "mcp.connected";
1943
+ server: string;
1944
+ transport: "http" | "stdio";
1945
+ protocolVersion: string;
1946
+ }>, z.ZodObject<{
1947
+ type: z.ZodLiteral<"mcp.connect_failed">;
1948
+ server: z.ZodString;
1949
+ /** 错误码;词表锚定 kernel McpErrorCode(connect_failed/handshake_failed/timeout/…) */
1950
+ code: z.ZodString;
1951
+ message: z.ZodString;
1952
+ }, "strip", z.ZodTypeAny, {
1953
+ code: string;
1954
+ message: string;
1955
+ type: "mcp.connect_failed";
1956
+ server: string;
1957
+ }, {
1958
+ code: string;
1959
+ message: string;
1960
+ type: "mcp.connect_failed";
1961
+ server: string;
1962
+ }>, z.ZodObject<{
1963
+ type: z.ZodLiteral<"mcp.closed">;
1964
+ server: z.ZodString;
1965
+ reason: z.ZodEnum<["closed", "server_exit", "error"]>;
1966
+ detail: z.ZodOptional<z.ZodString>;
1967
+ }, "strip", z.ZodTypeAny, {
1968
+ type: "mcp.closed";
1969
+ server: string;
1970
+ reason: "error" | "closed" | "server_exit";
1971
+ detail?: string | undefined;
1972
+ }, {
1973
+ type: "mcp.closed";
1974
+ server: string;
1975
+ reason: "error" | "closed" | "server_exit";
1976
+ detail?: string | undefined;
1977
+ }>, z.ZodObject<{
1978
+ type: z.ZodLiteral<"mcp.elicitation_declined">;
1979
+ server: z.ZodString;
1980
+ mode: z.ZodEnum<["form", "url"]>;
1981
+ message: z.ZodOptional<z.ZodString>;
1982
+ }, "strip", z.ZodTypeAny, {
1983
+ type: "mcp.elicitation_declined";
1984
+ server: string;
1985
+ mode: "url" | "form";
1986
+ message?: string | undefined;
1987
+ }, {
1988
+ type: "mcp.elicitation_declined";
1989
+ server: string;
1990
+ mode: "url" | "form";
1991
+ message?: string | undefined;
1992
+ }>, z.ZodObject<{
1993
+ type: z.ZodLiteral<"mcp.tool_skipped">;
1994
+ server: z.ZodString;
1995
+ tool: z.ZodString;
1996
+ reason: z.ZodEnum<["duplicate_name", "invalid_name"]>;
1997
+ }, "strip", z.ZodTypeAny, {
1998
+ type: "mcp.tool_skipped";
1999
+ server: string;
2000
+ reason: "duplicate_name" | "invalid_name";
2001
+ tool: string;
2002
+ }, {
2003
+ type: "mcp.tool_skipped";
2004
+ server: string;
2005
+ reason: "duplicate_name" | "invalid_name";
2006
+ tool: string;
2007
+ }>, z.ZodObject<{
2008
+ type: z.ZodLiteral<"mcp.discovered">;
2009
+ server: z.ZodString;
2010
+ phase: z.ZodEnum<["catalog", "expand"]>;
2011
+ origin: z.ZodEnum<["catalog-cache", "live"]>;
2012
+ tools: z.ZodArray<z.ZodString, "many">;
2013
+ durationMs: z.ZodNumber;
2014
+ /** 64 字符帽折叠映射(仅 phase='expand' 且发生折叠时携带;审计面) */
2015
+ folds: z.ZodOptional<z.ZodArray<z.ZodObject<{
2016
+ tool: z.ZodString;
2017
+ bridged: z.ZodString;
2018
+ }, "strip", z.ZodTypeAny, {
2019
+ tool: string;
2020
+ bridged: string;
2021
+ }, {
2022
+ tool: string;
2023
+ bridged: string;
2024
+ }>, "many">>;
2025
+ }, "strip", z.ZodTypeAny, {
2026
+ type: "mcp.discovered";
2027
+ tools: string[];
2028
+ server: string;
2029
+ durationMs: number;
2030
+ phase: "catalog" | "expand";
2031
+ origin: "catalog-cache" | "live";
2032
+ folds?: {
2033
+ tool: string;
2034
+ bridged: string;
2035
+ }[] | undefined;
2036
+ }, {
2037
+ type: "mcp.discovered";
2038
+ tools: string[];
2039
+ server: string;
2040
+ durationMs: number;
2041
+ phase: "catalog" | "expand";
2042
+ origin: "catalog-cache" | "live";
2043
+ folds?: {
2044
+ tool: string;
2045
+ bridged: string;
2046
+ }[] | undefined;
2047
+ }>, z.ZodObject<{
2048
+ type: z.ZodLiteral<"mcp.catalog_updated">;
2049
+ server: z.ZodString;
2050
+ added: z.ZodNumber;
2051
+ removed: z.ZodNumber;
2052
+ changed: z.ZodNumber;
2053
+ }, "strip", z.ZodTypeAny, {
2054
+ type: "mcp.catalog_updated";
2055
+ server: string;
2056
+ added: number;
2057
+ removed: number;
2058
+ changed: number;
2059
+ }, {
2060
+ type: "mcp.catalog_updated";
2061
+ server: string;
2062
+ added: number;
2063
+ removed: number;
2064
+ changed: number;
2065
+ }>, z.ZodObject<{
2066
+ type: z.ZodLiteral<"mcp.reconnecting">;
2067
+ server: z.ZodString;
2068
+ connection: z.ZodNumber;
2069
+ attempt: z.ZodNumber;
2070
+ delayMs: z.ZodNumber;
2071
+ }, "strip", z.ZodTypeAny, {
2072
+ type: "mcp.reconnecting";
2073
+ server: string;
2074
+ connection: number;
2075
+ attempt: number;
2076
+ delayMs: number;
2077
+ }, {
2078
+ type: "mcp.reconnecting";
2079
+ server: string;
2080
+ connection: number;
2081
+ attempt: number;
2082
+ delayMs: number;
2083
+ }>, z.ZodObject<{
2084
+ type: z.ZodLiteral<"mcp.reconnected">;
2085
+ server: z.ZodString;
2086
+ connection: z.ZodNumber;
2087
+ attempt: z.ZodNumber;
2088
+ downtimeMs: z.ZodNumber;
2089
+ }, "strip", z.ZodTypeAny, {
2090
+ type: "mcp.reconnected";
2091
+ server: string;
2092
+ connection: number;
2093
+ attempt: number;
2094
+ downtimeMs: number;
2095
+ }, {
2096
+ type: "mcp.reconnected";
2097
+ server: string;
2098
+ connection: number;
2099
+ attempt: number;
2100
+ downtimeMs: number;
2101
+ }>, z.ZodObject<{
2102
+ type: z.ZodLiteral<"mcp.reconnect_exhausted">;
2103
+ server: z.ZodString;
2104
+ connection: z.ZodNumber;
2105
+ attempts: z.ZodNumber;
2106
+ }, "strip", z.ZodTypeAny, {
2107
+ type: "mcp.reconnect_exhausted";
2108
+ server: string;
2109
+ attempts: number;
2110
+ connection: number;
2111
+ }, {
2112
+ type: "mcp.reconnect_exhausted";
2113
+ server: string;
2114
+ attempts: number;
2115
+ connection: number;
2116
+ }>, z.ZodObject<{
2117
+ type: z.ZodLiteral<"plan.todo.updated">;
2118
+ items: z.ZodArray<z.ZodObject<{
2119
+ id: z.ZodString;
2120
+ content: z.ZodString;
2121
+ status: z.ZodEnum<["pending", "in_progress", "completed", "cancelled"]>;
2122
+ }, "strip", z.ZodTypeAny, {
2123
+ status: "completed" | "pending" | "in_progress" | "cancelled";
2124
+ id: string;
2125
+ content: string;
2126
+ }, {
2127
+ status: "completed" | "pending" | "in_progress" | "cancelled";
2128
+ id: string;
2129
+ content: string;
2130
+ }>, "many">;
2131
+ }, "strip", z.ZodTypeAny, {
2132
+ type: "plan.todo.updated";
2133
+ items: {
2134
+ status: "completed" | "pending" | "in_progress" | "cancelled";
2135
+ id: string;
2136
+ content: string;
2137
+ }[];
2138
+ }, {
2139
+ type: "plan.todo.updated";
2140
+ items: {
2141
+ status: "completed" | "pending" | "in_progress" | "cancelled";
2142
+ id: string;
2143
+ content: string;
2144
+ }[];
2145
+ }>]>>;
2146
+ /** 完整内核事件:包络 + 负载(KernelEventSchema 推导)。 */
2147
+ export type KernelEvent = z.infer<typeof KernelEventSchema>;
2148
+ /** 构造器:补齐包络默认值,业务侧只传 body 与关键包络字段 */
2149
+ export declare function makeEvent(body: EventBody, env: Omit<EventEnvelope, 'v' | 'ts'> & {
2150
+ v?: string;
2151
+ ts?: number;
2152
+ }): KernelEvent;