@linnlabs/linnkit 0.8.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 (123) hide show
  1. package/CHANGELOG.md +84 -0
  2. package/LICENSE +21 -0
  3. package/README.md +178 -0
  4. package/README.zh-CN.md +182 -0
  5. package/dist/agent-invocation-BHcNfrBV.d.cts +30 -0
  6. package/dist/agent-invocation-BznDaXDs.d.ts +30 -0
  7. package/dist/agentEvents-DEB7Fy_J.d.cts +81 -0
  8. package/dist/agentEvents-DEB7Fy_J.d.ts +81 -0
  9. package/dist/agentSpec-EkmviZjy.d.cts +2621 -0
  10. package/dist/agentSpec-EkmviZjy.d.ts +2621 -0
  11. package/dist/ai-engine.types-BpeU_XQG.d.cts +158 -0
  12. package/dist/ai-engine.types-vZRnQcJa.d.ts +158 -0
  13. package/dist/audit-BaRUGaqv.d.cts +307 -0
  14. package/dist/audit-BaRUGaqv.d.ts +307 -0
  15. package/dist/audit-CtcfART1.d.ts +33 -0
  16. package/dist/audit-LeOrm2hX.d.cts +33 -0
  17. package/dist/checkpointMarker-DAI3wUQu.d.cts +8 -0
  18. package/dist/checkpointMarker-DAI3wUQu.d.ts +8 -0
  19. package/dist/cli.cjs +8028 -0
  20. package/dist/cli.cjs.map +1 -0
  21. package/dist/cli.d.cts +4 -0
  22. package/dist/cli.d.ts +4 -0
  23. package/dist/cli.js +8025 -0
  24. package/dist/cli.js.map +1 -0
  25. package/dist/context-manager.cjs +8704 -0
  26. package/dist/context-manager.cjs.map +1 -0
  27. package/dist/context-manager.d.cts +2190 -0
  28. package/dist/context-manager.d.ts +2190 -0
  29. package/dist/context-manager.js +8650 -0
  30. package/dist/context-manager.js.map +1 -0
  31. package/dist/context-trace-DRi5M4lX.d.ts +239 -0
  32. package/dist/context-trace-HE2qY5Q-.d.cts +239 -0
  33. package/dist/contracts.cjs +1333 -0
  34. package/dist/contracts.cjs.map +1 -0
  35. package/dist/contracts.d.cts +8 -0
  36. package/dist/contracts.d.ts +8 -0
  37. package/dist/contracts.js +1214 -0
  38. package/dist/contracts.js.map +1 -0
  39. package/dist/defaultGraphExecutor-BBswR8wn.d.ts +624 -0
  40. package/dist/defaultGraphExecutor-BIjJj7WF.d.cts +624 -0
  41. package/dist/execution-CAIypb41.d.cts +129 -0
  42. package/dist/execution-CAIypb41.d.ts +129 -0
  43. package/dist/index-CHqwkvGp.d.ts +149 -0
  44. package/dist/index-CJeWHopy.d.ts +584 -0
  45. package/dist/index-Cm-JbzTH.d.cts +1450 -0
  46. package/dist/index-Cvr23YCl.d.cts +23 -0
  47. package/dist/index-DDzuSb0n.d.ts +23 -0
  48. package/dist/index-DO4dQgf2.d.cts +584 -0
  49. package/dist/index-DRBWi1fy.d.ts +1450 -0
  50. package/dist/index-Dl5PLgAv.d.cts +149 -0
  51. package/dist/index.cjs +9577 -0
  52. package/dist/index.cjs.map +1 -0
  53. package/dist/index.d.cts +89 -0
  54. package/dist/index.d.ts +89 -0
  55. package/dist/index.js +9563 -0
  56. package/dist/index.js.map +1 -0
  57. package/dist/messages-XthmnHZ3.d.cts +8007 -0
  58. package/dist/messages-XthmnHZ3.d.ts +8007 -0
  59. package/dist/ports-DaatKJXp.d.cts +90 -0
  60. package/dist/ports-DnLuKfpE.d.ts +90 -0
  61. package/dist/ports.cjs +4 -0
  62. package/dist/ports.cjs.map +1 -0
  63. package/dist/ports.d.cts +7 -0
  64. package/dist/ports.d.ts +7 -0
  65. package/dist/ports.js +3 -0
  66. package/dist/ports.js.map +1 -0
  67. package/dist/quickstart.cjs +7697 -0
  68. package/dist/quickstart.cjs.map +1 -0
  69. package/dist/quickstart.d.cts +24 -0
  70. package/dist/quickstart.d.ts +24 -0
  71. package/dist/quickstart.js +7691 -0
  72. package/dist/quickstart.js.map +1 -0
  73. package/dist/runAgent-CPj_9e58.d.ts +88 -0
  74. package/dist/runAgent-HYKlXbVr.d.cts +88 -0
  75. package/dist/runHandle-CyXvzgzk.d.ts +239 -0
  76. package/dist/runHandle-D3gPsD7B.d.cts +239 -0
  77. package/dist/runtime-kernel/events.cjs +1485 -0
  78. package/dist/runtime-kernel/events.cjs.map +1 -0
  79. package/dist/runtime-kernel/events.d.cts +8 -0
  80. package/dist/runtime-kernel/events.d.ts +8 -0
  81. package/dist/runtime-kernel/events.js +1475 -0
  82. package/dist/runtime-kernel/events.js.map +1 -0
  83. package/dist/runtime-kernel.cjs +8656 -0
  84. package/dist/runtime-kernel.cjs.map +1 -0
  85. package/dist/runtime-kernel.d.cts +19 -0
  86. package/dist/runtime-kernel.d.ts +19 -0
  87. package/dist/runtime-kernel.js +8568 -0
  88. package/dist/runtime-kernel.js.map +1 -0
  89. package/dist/sse-vPyrOPa0.d.cts +1687 -0
  90. package/dist/sse-vPyrOPa0.d.ts +1687 -0
  91. package/dist/testkit.cjs +10613 -0
  92. package/dist/testkit.cjs.map +1 -0
  93. package/dist/testkit.d.cts +284 -0
  94. package/dist/testkit.d.ts +284 -0
  95. package/dist/testkit.js +10593 -0
  96. package/dist/testkit.js.map +1 -0
  97. package/dist/todo-B1PmDlp3.d.cts +2253 -0
  98. package/dist/todo-B1PmDlp3.d.ts +2253 -0
  99. package/dist/tokenizer-DFL4I7-I.d.ts +28 -0
  100. package/dist/tokenizer-DH_JXv-H.d.cts +28 -0
  101. package/dist/toolContracts-Blll0241.d.ts +463 -0
  102. package/dist/toolContracts-CLkQmhTG.d.cts +463 -0
  103. package/docs/README.md +76 -0
  104. package/docs/integration/01-installation.md +94 -0
  105. package/docs/integration/02-quickstart.md +104 -0
  106. package/docs/integration/README.md +223 -0
  107. package/docs/integration/agent-registration-guide.md +330 -0
  108. package/docs/integration/audit.md +64 -0
  109. package/docs/integration/child-runs.md +87 -0
  110. package/docs/integration/constraints-and-pitfalls.md +87 -0
  111. package/docs/integration/context-engineering.md +650 -0
  112. package/docs/integration/context-fences.md +289 -0
  113. package/docs/integration/glossary.md +69 -0
  114. package/docs/integration/llm-provider.md +76 -0
  115. package/docs/integration/persistence.md +44 -0
  116. package/docs/integration/realtime.md +76 -0
  117. package/docs/integration/run-supervisor.md +69 -0
  118. package/docs/integration/telemetry.md +48 -0
  119. package/docs/integration/testing.md +95 -0
  120. package/docs/integration/tool-development-guide.md +362 -0
  121. package/docs/integration/tool-history.md +202 -0
  122. package/docs/integration/tools.md +188 -0
  123. package/package.json +115 -0
@@ -0,0 +1,584 @@
1
+ import * as zod from 'zod';
2
+ import { A as AnyAgentEvent } from './agentEvents-DEB7Fy_J.js';
3
+ import { e as RuntimeEvent } from './todo-B1PmDlp3.js';
4
+ import { A as AiMessage } from './messages-XthmnHZ3.js';
5
+ import { a as ToolPresentationPort } from './ports-DnLuKfpE.js';
6
+ import { a as SSEEvent } from './sse-vPyrOPa0.js';
7
+
8
+ interface EventMappingContext {
9
+ conversationId: string;
10
+ turnId: string;
11
+ timestamp?: number;
12
+ /**
13
+ * 事件级扩展元数据(透传到 SSE/RuntimeEvent.metadata)。
14
+ *
15
+ * 中文备注:这里只放跨事件归类信息,不放 ui.hidden 这类单事件展示语义。
16
+ */
17
+ metadata?: Record<string, unknown>;
18
+ }
19
+ interface SSEMappingOptions {
20
+ emitSse?: boolean;
21
+ skipAlreadyDispatched?: boolean;
22
+ toolPresentationPort?: ToolPresentationPort;
23
+ }
24
+ interface RuntimeMappingOptions {
25
+ collectRuntime?: boolean;
26
+ skipIncomplete?: boolean;
27
+ toolPresentationPort?: ToolPresentationPort;
28
+ }
29
+ /**
30
+ * RuntimeEvent 回放所需的最小会话内存端口。
31
+ *
32
+ * 中文备注:
33
+ * - core 只依赖“写入消息”的最小能力;
34
+ * - 具体产品实现只要结构兼容即可接入。
35
+ */
36
+ interface ConversationMemoryPort {
37
+ addUserMessage(content: string, id?: string): void;
38
+ addAssistantMessage(content: string | null, type: AiMessage['type'] & ('thought' | 'final_answer' | 'tool_calls'), metadata?: AiMessage['metadata'], id?: string): void;
39
+ addToolResponse(toolCallId: string, content: string, toolName?: string, id?: string): void;
40
+ appendMessage(message: AiMessage): void;
41
+ }
42
+
43
+ declare function agentEventToRuntime(agentEvent: AnyAgentEvent | RuntimeEvent, context: EventMappingContext, options?: RuntimeMappingOptions): RuntimeEvent | null;
44
+
45
+ declare function applyRuntimeEventToMemory(event: RuntimeEvent, memory: ConversationMemoryPort): void;
46
+
47
+ declare function agentEventToSSE(agentEvent: AnyAgentEvent, context: EventMappingContext, options?: SSEMappingOptions): SSEEvent | null;
48
+
49
+ /**
50
+ * 统一的事件映射器。
51
+ *
52
+ * 中文备注:
53
+ * - 保持旧调用方式 `eventMapper.xxx` 不变;
54
+ * - 新逻辑不要继续写回本文件,按职责放到拆分后的模块。
55
+ */
56
+ declare const eventMapper: {
57
+ /**
58
+ * 将 AgentEvent 转换为 SSEEvent。
59
+ */
60
+ agentToSse: typeof agentEventToSSE;
61
+ /**
62
+ * 将 AgentEvent 转换为 RuntimeEvent。
63
+ */
64
+ agentToRuntime: typeof agentEventToRuntime;
65
+ /**
66
+ * 将 RuntimeEvent 应用到 ConversationMemoryPort。
67
+ */
68
+ applyToMemory: typeof applyRuntimeEventToMemory;
69
+ /**
70
+ * 批量处理 AgentEvent → SSEEvent + RuntimeEvent。
71
+ */
72
+ agentToBoth: (agentEvent: AnyAgentEvent, context: EventMappingContext, options?: {
73
+ sseOptions?: SSEMappingOptions;
74
+ runtimeOptions?: RuntimeMappingOptions;
75
+ }) => {
76
+ sseEvent: {
77
+ type: "thought";
78
+ id: string;
79
+ timestamp: number;
80
+ conversation_id: string;
81
+ turn_id: string;
82
+ is_complete: boolean;
83
+ content?: string | undefined;
84
+ metadata?: Record<string, unknown> | undefined;
85
+ thought_message_id?: string | undefined;
86
+ delta?: string | undefined;
87
+ } | {
88
+ type: "final_answer_chunk";
89
+ id: string;
90
+ timestamp: number;
91
+ conversation_id: string;
92
+ turn_id: string;
93
+ answer_id: string;
94
+ seq: number;
95
+ chunk: string;
96
+ metadata?: Record<string, unknown> | undefined;
97
+ is_last?: boolean | undefined;
98
+ } | {
99
+ type: "final_answer";
100
+ id: string;
101
+ content: string;
102
+ timestamp: number;
103
+ conversation_id: string;
104
+ turn_id: string;
105
+ answer_id: string;
106
+ metadata?: Record<string, unknown> | undefined;
107
+ meta?: Record<string, any> | undefined;
108
+ } | {
109
+ type: "markdown_chunk";
110
+ id: string;
111
+ timestamp: number;
112
+ conversation_id: string;
113
+ turn_id: string;
114
+ text: string;
115
+ content_type: "code" | "image" | "text" | "table";
116
+ metadata?: Record<string, unknown> | undefined;
117
+ seq?: number | undefined;
118
+ } | {
119
+ type: "tool_call_decision";
120
+ status: "error" | "loading" | "success";
121
+ id: string;
122
+ tool_name: string;
123
+ tool_call_id: string;
124
+ timestamp: number;
125
+ conversation_id: string;
126
+ turn_id: string;
127
+ phase: "start" | "update" | "complete" | "error";
128
+ args?: any;
129
+ metadata?: Record<string, unknown> | undefined;
130
+ payload?: any;
131
+ meta?: Record<string, any> | undefined;
132
+ } | {
133
+ type: "tool_process";
134
+ status: "error" | "loading" | "success";
135
+ id: string;
136
+ tool_name: string;
137
+ tool_call_id: string;
138
+ timestamp: number;
139
+ conversation_id: string;
140
+ turn_id: string;
141
+ phase: "start" | "update" | "complete" | "error";
142
+ args?: any;
143
+ metadata?: Record<string, unknown> | undefined;
144
+ payload?: any;
145
+ meta?: Record<string, any> | undefined;
146
+ } | {
147
+ type: "tool_output";
148
+ status: "error" | "success";
149
+ id: string;
150
+ tool_name: string;
151
+ tool_call_id: string;
152
+ timestamp: number;
153
+ conversation_id: string;
154
+ turn_id: string;
155
+ metadata?: Record<string, unknown> | undefined;
156
+ payload?: Record<string, any> | undefined;
157
+ output?: any;
158
+ duration_ms?: number | undefined;
159
+ } | {
160
+ type: "todo_updated";
161
+ id: string;
162
+ timestamp: number;
163
+ conversation_id: string;
164
+ turn_id: string;
165
+ todo_list_id: string;
166
+ todo_list_version: number;
167
+ items: {
168
+ status: "in_progress" | "completed" | "cancelled" | "pending";
169
+ id: string;
170
+ content: string;
171
+ }[];
172
+ metadata?: Record<string, unknown> | undefined;
173
+ } | {
174
+ type: "subrun_trace";
175
+ id: string;
176
+ timestamp: number;
177
+ kind: "final_answer" | "tool_output" | "tool_call_decision" | "tool_process" | "thought_delta" | "thought_complete" | "final_answer_chunk";
178
+ conversation_id: string;
179
+ turn_id: string;
180
+ parent_tool_call_id: string;
181
+ subrun_id: string;
182
+ status?: "error" | "loading" | "success" | undefined;
183
+ tool_name?: string | undefined;
184
+ args?: unknown;
185
+ tool_call_id?: string | undefined;
186
+ content?: string | undefined;
187
+ metadata?: Record<string, unknown> | undefined;
188
+ delta?: string | undefined;
189
+ phase?: "start" | "update" | "complete" | "error" | undefined;
190
+ meta?: Record<string, unknown> | undefined;
191
+ output?: unknown;
192
+ duration_ms?: number | undefined;
193
+ subrun_parent_id?: string | undefined;
194
+ } | {
195
+ type: "requires_user_interaction";
196
+ id: string;
197
+ timestamp: number;
198
+ conversation_id: string;
199
+ turn_id: string;
200
+ metadata?: Record<string, unknown> | undefined;
201
+ form?: any;
202
+ interaction_type?: string | undefined;
203
+ prompt?: string | undefined;
204
+ } | {
205
+ type: "error";
206
+ id: string;
207
+ timestamp: number;
208
+ conversation_id: string;
209
+ turn_id: string;
210
+ error: string;
211
+ metadata?: Record<string, unknown> | undefined;
212
+ details?: any;
213
+ error_code?: string | undefined;
214
+ retryable?: boolean | undefined;
215
+ } | {
216
+ type: "stream_end";
217
+ id: string;
218
+ timestamp: number;
219
+ conversation_id: string;
220
+ turn_id: string;
221
+ metadata?: Record<string, unknown> | undefined;
222
+ reason?: "complete" | "error" | "interrupted" | "timeout" | undefined;
223
+ reason_message?: string | undefined;
224
+ stats?: {
225
+ duration_ms?: number | undefined;
226
+ total_events?: number | undefined;
227
+ error_count?: number | undefined;
228
+ benchmark?: Record<string, unknown> | undefined;
229
+ } | undefined;
230
+ } | {
231
+ type: "history_summary";
232
+ id: string;
233
+ content: string;
234
+ timestamp: number;
235
+ conversation_id: string;
236
+ turn_id: string;
237
+ summary_seq: number;
238
+ original_message_count: number;
239
+ summary_id: string;
240
+ metadata?: Record<string, unknown> | undefined;
241
+ } | {
242
+ type: "summarization_start";
243
+ id: string;
244
+ timestamp: number;
245
+ conversation_id: string;
246
+ turn_id: string;
247
+ metadata?: Record<string, unknown> | undefined;
248
+ originalMessages?: number | undefined;
249
+ } | {
250
+ type: "summarization_end";
251
+ id: string;
252
+ timestamp: number;
253
+ conversation_id: string;
254
+ turn_id: string;
255
+ compressionRatio?: string | undefined;
256
+ metadata?: Record<string, unknown> | undefined;
257
+ originalMessages?: number | undefined;
258
+ compressedMessages?: number | undefined;
259
+ timeSaved?: string | undefined;
260
+ } | {
261
+ type: "summarization_error";
262
+ id: string;
263
+ timestamp: number;
264
+ conversation_id: string;
265
+ turn_id: string;
266
+ error: string;
267
+ metadata?: Record<string, unknown> | undefined;
268
+ } | null;
269
+ runtimeEvent: {
270
+ type: "user_input";
271
+ id: string;
272
+ content: string;
273
+ timestamp: number;
274
+ version: 1;
275
+ conversation_id: string;
276
+ turn_id: string;
277
+ source: "system" | "user" | "editor";
278
+ metadata?: Record<string, unknown> | undefined;
279
+ ephemeral?: boolean | undefined;
280
+ raw_content?: string | undefined;
281
+ } | {
282
+ type: "thought";
283
+ id: string;
284
+ content: string;
285
+ timestamp: number;
286
+ version: 1;
287
+ conversation_id: string;
288
+ turn_id: string;
289
+ is_complete: boolean;
290
+ metadata?: Record<string, unknown> | undefined;
291
+ ephemeral?: boolean | undefined;
292
+ thought_message_id?: string | undefined;
293
+ delta?: string | undefined;
294
+ } | {
295
+ type: "tool_call_decision";
296
+ status: "error" | "loading" | "success";
297
+ id: string;
298
+ tool_name: string;
299
+ tool_call_id: string;
300
+ timestamp: number;
301
+ version: 1;
302
+ conversation_id: string;
303
+ turn_id: string;
304
+ phase: "start" | "update" | "complete" | "error";
305
+ args?: Record<string, any> | undefined;
306
+ metadata?: Record<string, unknown> | undefined;
307
+ ephemeral?: boolean | undefined;
308
+ payload?: zod.objectOutputType<{
309
+ args: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodAny>>;
310
+ tool_calls: zod.ZodOptional<zod.ZodArray<zod.ZodUnknown, "many">>;
311
+ reasoning_details: zod.ZodOptional<zod.ZodArray<zod.ZodUnknown, "many">>;
312
+ }, zod.ZodTypeAny, "passthrough"> | undefined;
313
+ parent_tool_call_id?: string | undefined;
314
+ meta?: Record<string, any> | undefined;
315
+ } | {
316
+ type: "tool_process";
317
+ status: "error" | "loading" | "success";
318
+ id: string;
319
+ tool_name: string;
320
+ tool_call_id: string;
321
+ timestamp: number;
322
+ version: 1;
323
+ conversation_id: string;
324
+ turn_id: string;
325
+ phase: "start" | "update" | "complete" | "error";
326
+ args?: Record<string, any> | undefined;
327
+ metadata?: Record<string, unknown> | undefined;
328
+ ephemeral?: boolean | undefined;
329
+ payload?: Record<string, any> | undefined;
330
+ parent_tool_call_id?: string | undefined;
331
+ meta?: Record<string, any> | undefined;
332
+ } | {
333
+ type: "tool_output";
334
+ status: "error" | "success";
335
+ id: string;
336
+ tool_name: string;
337
+ tool_call_id: string;
338
+ timestamp: number;
339
+ version: 1;
340
+ conversation_id: string;
341
+ turn_id: string;
342
+ metadata?: Record<string, unknown> | undefined;
343
+ ephemeral?: boolean | undefined;
344
+ error?: string | undefined;
345
+ payload?: Record<string, any> | undefined;
346
+ output?: any;
347
+ duration_ms?: number | undefined;
348
+ } | {
349
+ type: "todo_updated";
350
+ id: string;
351
+ timestamp: number;
352
+ version: 1;
353
+ conversation_id: string;
354
+ turn_id: string;
355
+ todo_list_id: string;
356
+ todo_list_version: number;
357
+ items: {
358
+ status: "in_progress" | "completed" | "cancelled" | "pending";
359
+ id: string;
360
+ content: string;
361
+ }[];
362
+ metadata?: Record<string, unknown> | undefined;
363
+ ephemeral?: boolean | undefined;
364
+ } | {
365
+ type: "subrun_trace";
366
+ id: string;
367
+ timestamp: number;
368
+ kind: "final_answer" | "tool_output" | "tool_call_decision" | "tool_process" | "thought_delta" | "thought_complete" | "final_answer_chunk";
369
+ version: 1;
370
+ conversation_id: string;
371
+ turn_id: string;
372
+ parent_tool_call_id: string;
373
+ subrun_id: string;
374
+ status?: "error" | "loading" | "success" | undefined;
375
+ tool_name?: string | undefined;
376
+ args?: unknown;
377
+ tool_call_id?: string | undefined;
378
+ content?: string | undefined;
379
+ metadata?: Record<string, unknown> | undefined;
380
+ ephemeral?: boolean | undefined;
381
+ delta?: string | undefined;
382
+ phase?: "start" | "update" | "complete" | "error" | undefined;
383
+ meta?: Record<string, unknown> | undefined;
384
+ output?: unknown;
385
+ duration_ms?: number | undefined;
386
+ subrun_parent_id?: string | undefined;
387
+ } | {
388
+ type: "requires_user_interaction";
389
+ id: string;
390
+ timestamp: number;
391
+ version: 1;
392
+ conversation_id: string;
393
+ turn_id: string;
394
+ metadata?: Record<string, unknown> | undefined;
395
+ ephemeral?: boolean | undefined;
396
+ form?: any;
397
+ interaction_type?: string | undefined;
398
+ prompt?: string | undefined;
399
+ } | {
400
+ type: "audit_envelope";
401
+ id: string;
402
+ timestamp: number;
403
+ version: 1;
404
+ conversation_id: string;
405
+ turn_id: string;
406
+ envelope: {
407
+ runId: string;
408
+ envelopeId: string;
409
+ ts: number;
410
+ actor: {
411
+ kind: "system" | "user" | "tool" | "agent" | "host" | "model";
412
+ id?: string | undefined;
413
+ name?: string | undefined;
414
+ };
415
+ action: string;
416
+ parentRunId?: string | undefined;
417
+ decision?: {
418
+ outcome: "requested" | "allowed" | "denied" | "fallback" | "retry" | "cancelled" | "paused" | "resumed" | "recorded";
419
+ metadata?: Record<string, unknown> | undefined;
420
+ reason?: string | undefined;
421
+ policy?: string | undefined;
422
+ } | undefined;
423
+ evidence?: {
424
+ kind: string;
425
+ summary?: string | undefined;
426
+ metadata?: Record<string, unknown> | undefined;
427
+ ref?: string | undefined;
428
+ }[] | undefined;
429
+ costDelta?: {
430
+ tokensInput?: number | undefined;
431
+ tokensOutput?: number | undefined;
432
+ totalCostUsd?: number | undefined;
433
+ latencyMs?: number | undefined;
434
+ } | undefined;
435
+ scope?: {
436
+ metadata?: Record<string, unknown> | undefined;
437
+ toolName?: string | undefined;
438
+ conversationId?: string | undefined;
439
+ runId?: string | undefined;
440
+ parentRunId?: string | undefined;
441
+ turnId?: string | undefined;
442
+ traceId?: string | undefined;
443
+ agentSpecId?: string | undefined;
444
+ toolCallId?: string | undefined;
445
+ modelId?: string | undefined;
446
+ nodeId?: string | undefined;
447
+ } | undefined;
448
+ };
449
+ metadata?: Record<string, unknown> | undefined;
450
+ ephemeral?: boolean | undefined;
451
+ } | {
452
+ type: "final_answer";
453
+ id: string;
454
+ content: string;
455
+ timestamp: number;
456
+ version: 1;
457
+ conversation_id: string;
458
+ turn_id: string;
459
+ is_complete: boolean;
460
+ answer_id: string;
461
+ reasoning_details?: unknown[] | undefined;
462
+ metadata?: Record<string, unknown> | undefined;
463
+ ephemeral?: boolean | undefined;
464
+ meta?: Record<string, any> | undefined;
465
+ } | {
466
+ type: "final_answer_chunk";
467
+ id: string;
468
+ content: string;
469
+ timestamp: number;
470
+ version: 1;
471
+ conversation_id: string;
472
+ turn_id: string;
473
+ answer_id: string;
474
+ seq: number;
475
+ metadata?: Record<string, unknown> | undefined;
476
+ ephemeral?: boolean | undefined;
477
+ is_last?: boolean | undefined;
478
+ } | {
479
+ type: "history_summary";
480
+ id: string;
481
+ content: string;
482
+ timestamp: number;
483
+ version: 1;
484
+ conversation_id: string;
485
+ turn_id: string;
486
+ replaced_message_ids: string[];
487
+ summary_seq: number;
488
+ metadata?: Record<string, unknown> | undefined;
489
+ ephemeral?: boolean | undefined;
490
+ original_message_count?: number | undefined;
491
+ compression_ratio?: number | undefined;
492
+ included_old_summary?: boolean | undefined;
493
+ } | {
494
+ type: "error";
495
+ id: string;
496
+ timestamp: number;
497
+ version: 1;
498
+ conversation_id: string;
499
+ turn_id: string;
500
+ error: string;
501
+ metadata?: Record<string, unknown> | undefined;
502
+ ephemeral?: boolean | undefined;
503
+ details?: any;
504
+ error_code?: string | undefined;
505
+ retryable?: boolean | undefined;
506
+ } | {
507
+ type: "control";
508
+ id: string;
509
+ timestamp: number;
510
+ version: 1;
511
+ conversation_id: string;
512
+ turn_id: string;
513
+ op: "truncate_after" | "replace" | "redo" | "branch";
514
+ metadata?: Record<string, unknown> | undefined;
515
+ reason?: string | undefined;
516
+ ephemeral?: boolean | undefined;
517
+ meta?: any;
518
+ target_id?: string | undefined;
519
+ } | {
520
+ type: "stream_end";
521
+ id: string;
522
+ timestamp: number;
523
+ version: 1;
524
+ conversation_id: string;
525
+ turn_id: string;
526
+ metadata?: Record<string, unknown> | undefined;
527
+ reason?: "complete" | "error" | "interrupted" | "timeout" | undefined;
528
+ ephemeral?: boolean | undefined;
529
+ reason_message?: string | undefined;
530
+ stats?: {
531
+ duration_ms?: number | undefined;
532
+ total_events?: number | undefined;
533
+ error_count?: number | undefined;
534
+ } | undefined;
535
+ } | null;
536
+ };
537
+ /**
538
+ * 批量重建内存。
539
+ */
540
+ rebuildMemory: (events: RuntimeEvent[], memory: ConversationMemoryPort) => void;
541
+ };
542
+
543
+ type RuntimeEventUiProjectionKind = 'hidden' | 'user_input' | 'thought' | 'final_answer' | 'final_answer_chunk' | 'tool_call_decision' | 'tool_process' | 'tool_output' | 'requires_user_interaction' | 'audit_envelope' | 'todo_updated' | 'subrun_trace' | 'error' | 'stream_end' | 'history_summary' | 'checkpoint_history_summary' | 'unsupported';
544
+ type RuntimeEventRealtimeChannel = 'event_bus_sse' | 'none';
545
+ interface RuntimeEventLifecycleDecision {
546
+ uiProjectionKind: RuntimeEventUiProjectionKind;
547
+ persist: boolean;
548
+ replayToUi: boolean;
549
+ enterAgentContext: boolean;
550
+ realtimeChannel: RuntimeEventRealtimeChannel;
551
+ }
552
+ declare function isToolCallDecisionEvent<T extends {
553
+ type: string;
554
+ }>(event: T): event is T & {
555
+ type: 'tool_call_decision';
556
+ };
557
+ declare function shouldPersistRuntimeEvent(event: RuntimeEvent): boolean;
558
+ declare function shouldReplayRuntimeEventToUi(event: RuntimeEvent): boolean;
559
+ declare function shouldEnterAgentContext(event: RuntimeEvent): boolean;
560
+ declare function isCheckpointHistorySummaryEvent(event: RuntimeEvent): event is Extract<RuntimeEvent, {
561
+ type: 'history_summary';
562
+ }>;
563
+ declare function getRuntimeEventUiProjectionKind(event: RuntimeEvent): RuntimeEventUiProjectionKind;
564
+ declare function describeRuntimeEventLifecycle(event: RuntimeEvent): RuntimeEventLifecycleDecision;
565
+ declare function shouldEmitRuntimeEventToSse(event: RuntimeEvent): boolean;
566
+
567
+ declare const index_AnyAgentEvent: typeof AnyAgentEvent;
568
+ type index_ConversationMemoryPort = ConversationMemoryPort;
569
+ type index_EventMappingContext = EventMappingContext;
570
+ type index_RuntimeEventLifecycleDecision = RuntimeEventLifecycleDecision;
571
+ declare const index_describeRuntimeEventLifecycle: typeof describeRuntimeEventLifecycle;
572
+ declare const index_eventMapper: typeof eventMapper;
573
+ declare const index_getRuntimeEventUiProjectionKind: typeof getRuntimeEventUiProjectionKind;
574
+ declare const index_isCheckpointHistorySummaryEvent: typeof isCheckpointHistorySummaryEvent;
575
+ declare const index_isToolCallDecisionEvent: typeof isToolCallDecisionEvent;
576
+ declare const index_shouldEmitRuntimeEventToSse: typeof shouldEmitRuntimeEventToSse;
577
+ declare const index_shouldEnterAgentContext: typeof shouldEnterAgentContext;
578
+ declare const index_shouldPersistRuntimeEvent: typeof shouldPersistRuntimeEvent;
579
+ declare const index_shouldReplayRuntimeEventToUi: typeof shouldReplayRuntimeEventToUi;
580
+ declare namespace index {
581
+ export { index_AnyAgentEvent as AnyAgentEvent, type index_ConversationMemoryPort as ConversationMemoryPort, type index_EventMappingContext as EventMappingContext, type index_RuntimeEventLifecycleDecision as RuntimeEventLifecycleDecision, index_describeRuntimeEventLifecycle as describeRuntimeEventLifecycle, index_eventMapper as eventMapper, index_getRuntimeEventUiProjectionKind as getRuntimeEventUiProjectionKind, index_isCheckpointHistorySummaryEvent as isCheckpointHistorySummaryEvent, index_isToolCallDecisionEvent as isToolCallDecisionEvent, index_shouldEmitRuntimeEventToSse as shouldEmitRuntimeEventToSse, index_shouldEnterAgentContext as shouldEnterAgentContext, index_shouldPersistRuntimeEvent as shouldPersistRuntimeEvent, index_shouldReplayRuntimeEventToUi as shouldReplayRuntimeEventToUi };
582
+ }
583
+
584
+ export { type ConversationMemoryPort as C, type EventMappingContext as E, type RuntimeEventLifecycleDecision as R, isCheckpointHistorySummaryEvent as a, isToolCallDecisionEvent as b, shouldEnterAgentContext as c, describeRuntimeEventLifecycle as d, eventMapper as e, shouldPersistRuntimeEvent as f, getRuntimeEventUiProjectionKind as g, shouldReplayRuntimeEventToUi as h, index as i, shouldEmitRuntimeEventToSse as s };