@linnlabs/linnkit 0.32.0 → 0.32.1

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 (468) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/context-manager/features/context-compaction/definitions/contextCheckpointFormat.d.cts +3 -0
  3. package/dist/context-manager/features/context-compaction/definitions/contextCheckpointFormat.d.ts +3 -0
  4. package/dist/context-manager/features/context-compaction/definitions/historySummaryDraft.d.cts +22 -0
  5. package/dist/context-manager/features/context-compaction/definitions/historySummaryDraft.d.ts +22 -0
  6. package/dist/context-manager/profiles/agent/config.d.cts +33 -0
  7. package/dist/context-manager/profiles/agent/config.d.ts +33 -0
  8. package/dist/context-manager/profiles/agent/context/AgentContextManager.d.cts +132 -0
  9. package/dist/context-manager/profiles/agent/context/AgentContextManager.d.ts +132 -0
  10. package/dist/context-manager/profiles/agent/context/ConversationSession.d.cts +131 -0
  11. package/dist/context-manager/profiles/agent/context/ConversationSession.d.ts +131 -0
  12. package/dist/context-manager/profiles/agent/context/config.d.cts +191 -0
  13. package/dist/context-manager/profiles/agent/context/config.d.ts +191 -0
  14. package/dist/context-manager/profiles/agent/context/index.d.cts +8 -0
  15. package/dist/context-manager/profiles/agent/context/index.d.ts +8 -0
  16. package/dist/context-manager/profiles/agent/context/providers/AgentCoreContextProvider.d.cts +52 -0
  17. package/dist/context-manager/profiles/agent/context/providers/AgentCoreContextProvider.d.ts +52 -0
  18. package/dist/context-manager/profiles/agent/context/providers/AgentWorkingMemoryProvider.d.cts +50 -0
  19. package/dist/context-manager/profiles/agent/context/providers/AgentWorkingMemoryProvider.d.ts +50 -0
  20. package/dist/context-manager/profiles/agent/context/providers/base.d.cts +11 -0
  21. package/dist/context-manager/profiles/agent/context/providers/base.d.ts +11 -0
  22. package/dist/context-manager/profiles/agent/context/providers/index.d.cts +12 -0
  23. package/dist/context-manager/profiles/agent/context/providers/index.d.ts +12 -0
  24. package/dist/context-manager/profiles/agent/contracts.d.cts +27 -0
  25. package/dist/context-manager/profiles/agent/contracts.d.ts +27 -0
  26. package/dist/context-manager/profiles/agent/orchestration/AgentMessageOrchestrator.d.cts +140 -0
  27. package/dist/context-manager/profiles/agent/orchestration/AgentMessageOrchestrator.d.ts +140 -0
  28. package/dist/context-manager/profiles/agent/orchestration/index.d.cts +1 -0
  29. package/dist/context-manager/profiles/agent/orchestration/index.d.ts +1 -0
  30. package/dist/context-manager/profiles/agent/preprocessors/base.d.cts +17 -0
  31. package/dist/context-manager/profiles/agent/preprocessors/base.d.ts +17 -0
  32. package/dist/context-manager/profiles/agent/preprocessors/index.d.cts +117 -0
  33. package/dist/context-manager/profiles/agent/preprocessors/index.d.ts +117 -0
  34. package/dist/context-manager/profiles/agent/preprocessors/toolHistoryCompressor.d.cts +47 -0
  35. package/dist/context-manager/profiles/agent/preprocessors/toolHistoryCompressor.d.ts +47 -0
  36. package/dist/context-manager/profiles/agent/preprocessors/toolReplayProtocolGuard.d.cts +27 -0
  37. package/dist/context-manager/profiles/agent/preprocessors/toolReplayProtocolGuard.d.ts +27 -0
  38. package/dist/context-manager/profiles/agent/tasks/BaseAgentTask.d.cts +43 -0
  39. package/dist/context-manager/profiles/agent/tasks/BaseAgentTask.d.ts +43 -0
  40. package/dist/context-manager/profiles/agent/tasks/base.d.cts +18 -0
  41. package/dist/context-manager/profiles/agent/tasks/base.d.ts +18 -0
  42. package/dist/context-manager/profiles/agent/tasks/index.d.cts +2 -0
  43. package/dist/context-manager/profiles/agent/tasks/index.d.ts +2 -0
  44. package/dist/context-manager/profiles/agent/tools/ToolManager.d.cts +27 -0
  45. package/dist/context-manager/profiles/agent/tools/ToolManager.d.ts +27 -0
  46. package/dist/context-manager/profiles/agent/tools/index.d.cts +1 -0
  47. package/dist/context-manager/profiles/agent/tools/index.d.ts +1 -0
  48. package/dist/context-manager/profiles/agent/utils/eventConverter.d.cts +15 -0
  49. package/dist/context-manager/profiles/agent/utils/eventConverter.d.ts +15 -0
  50. package/dist/context-manager/profiles/agent/utils/index.d.cts +2 -0
  51. package/dist/context-manager/profiles/agent/utils/index.d.ts +2 -0
  52. package/dist/context-manager/profiles/agent/utils/toolOutputSummarizer.d.cts +26 -0
  53. package/dist/context-manager/profiles/agent/utils/toolOutputSummarizer.d.ts +26 -0
  54. package/dist/context-manager/shared/MessageFormatter.d.cts +55 -0
  55. package/dist/context-manager/shared/MessageFormatter.d.ts +55 -0
  56. package/dist/context-manager/shared/agentSpecAdapter.d.cts +63 -0
  57. package/dist/context-manager/shared/agentSpecAdapter.d.ts +63 -0
  58. package/dist/context-manager/shared/context-manager-base.d.cts +102 -0
  59. package/dist/context-manager/shared/context-manager-base.d.ts +102 -0
  60. package/dist/context-manager/shared/context-pipeline.d.cts +42 -0
  61. package/dist/context-manager/shared/context-pipeline.d.ts +42 -0
  62. package/dist/context-manager/shared/context-trace.d.cts +102 -0
  63. package/dist/context-manager/shared/context-trace.d.ts +102 -0
  64. package/dist/context-manager/shared/contextPolicyMerge.d.cts +19 -0
  65. package/dist/context-manager/shared/contextPolicyMerge.d.ts +19 -0
  66. package/dist/context-manager/shared/contracts/chatLineMessage.d.cts +15 -0
  67. package/dist/context-manager/shared/contracts/chatLineMessage.d.ts +15 -0
  68. package/dist/context-manager/shared/fences/FenceRegistry.d.cts +24 -0
  69. package/dist/context-manager/shared/fences/FenceRegistry.d.ts +24 -0
  70. package/dist/context-manager/shared/image-input-estimation.d.cts +16 -0
  71. package/dist/context-manager/shared/image-input-estimation.d.ts +16 -0
  72. package/dist/context-manager/shared/policies/MustKeepPolicy.d.cts +19 -0
  73. package/dist/context-manager/shared/policies/MustKeepPolicy.d.ts +19 -0
  74. package/dist/context-manager/shared/preprocessors/base.d.cts +43 -0
  75. package/dist/context-manager/shared/preprocessors/base.d.ts +43 -0
  76. package/dist/context-manager/shared/preprocessors/currentTurnMessageAssembler.d.cts +26 -0
  77. package/dist/context-manager/shared/preprocessors/currentTurnMessageAssembler.d.ts +26 -0
  78. package/dist/context-manager/shared/preprocessors/fenceLifetimeManager.d.cts +18 -0
  79. package/dist/context-manager/shared/preprocessors/fenceLifetimeManager.d.ts +18 -0
  80. package/dist/context-manager/shared/preprocessors/historyPurification.d.cts +19 -0
  81. package/dist/context-manager/shared/preprocessors/historyPurification.d.ts +19 -0
  82. package/dist/context-manager/shared/preprocessors/priority.d.cts +17 -0
  83. package/dist/context-manager/shared/preprocessors/priority.d.ts +17 -0
  84. package/dist/context-manager/shared/providers/base.d.cts +106 -0
  85. package/dist/context-manager/shared/providers/base.d.ts +106 -0
  86. package/dist/context-manager/shared/providers/registry.d.cts +11 -0
  87. package/dist/context-manager/shared/providers/registry.d.ts +11 -0
  88. package/dist/context-manager/shared/token-calibration.d.cts +25 -0
  89. package/dist/context-manager/shared/token-calibration.d.ts +25 -0
  90. package/dist/context-manager.d.cts +34 -1559
  91. package/dist/context-manager.d.ts +34 -1559
  92. package/dist/contracts/agentSpec.d.cts +869 -0
  93. package/dist/contracts/agentSpec.d.ts +869 -0
  94. package/dist/{audit-XsNMTt0-.d.cts → contracts/audit.d.cts} +33 -33
  95. package/dist/{audit-XsNMTt0-.d.ts → contracts/audit.d.ts} +33 -33
  96. package/dist/contracts/constants.d.cts +3 -0
  97. package/dist/contracts/constants.d.ts +3 -0
  98. package/dist/contracts/contextCompaction.d.cts +43 -0
  99. package/dist/contracts/contextCompaction.d.ts +43 -0
  100. package/dist/contracts/contextPolicy.d.cts +1121 -0
  101. package/dist/contracts/contextPolicy.d.ts +1121 -0
  102. package/dist/{final-answer-oOQ_7nPt.d.ts → contracts/events.d.cts} +1219 -1222
  103. package/dist/{final-answer-B0_kx5_U.d.cts → contracts/events.d.ts} +1219 -1222
  104. package/dist/{execution-B7e01ZjW.d.cts → contracts/execution.d.cts} +21 -21
  105. package/dist/{execution-B7e01ZjW.d.ts → contracts/execution.d.ts} +21 -21
  106. package/dist/contracts/final-answer.d.cts +7 -0
  107. package/dist/contracts/final-answer.d.ts +7 -0
  108. package/dist/contracts/identity/definitions.d.cts +70 -0
  109. package/dist/contracts/identity/definitions.d.ts +70 -0
  110. package/dist/contracts/identity/generators.d.cts +33 -0
  111. package/dist/contracts/identity/generators.d.ts +33 -0
  112. package/dist/contracts/identity/invariants.d.cts +24 -0
  113. package/dist/contracts/identity/invariants.d.ts +24 -0
  114. package/dist/contracts/json.d.cts +12 -0
  115. package/dist/contracts/json.d.ts +12 -0
  116. package/dist/{provider-continuation-CTZdCB--.d.cts → contracts/messages.d.cts} +210 -957
  117. package/dist/{provider-continuation-CTZdCB--.d.ts → contracts/messages.d.ts} +210 -957
  118. package/dist/contracts/provider-continuation.d.cts +609 -0
  119. package/dist/contracts/provider-continuation.d.ts +609 -0
  120. package/dist/contracts/reasoning.d.cts +77 -0
  121. package/dist/contracts/reasoning.d.ts +77 -0
  122. package/dist/contracts/resource-ref.d.cts +73 -0
  123. package/dist/contracts/resource-ref.d.ts +73 -0
  124. package/dist/contracts/runtime-status.d.cts +8 -0
  125. package/dist/contracts/runtime-status.d.ts +8 -0
  126. package/dist/contracts/sse-framing.d.cts +28 -0
  127. package/dist/contracts/sse-framing.d.ts +28 -0
  128. package/dist/{index-Cp1_oUj0.d.ts → contracts/sse.d.cts} +1218 -1574
  129. package/dist/{index-JYf6n2Ik.d.cts → contracts/sse.d.ts} +1218 -1574
  130. package/dist/contracts/sub-run-trace-payload.d.cts +187 -0
  131. package/dist/contracts/sub-run-trace-payload.d.ts +187 -0
  132. package/dist/{summarization-CMMLhaCe.d.ts → contracts/summarization.d.cts} +2 -2
  133. package/dist/{summarization-kLeweZ5-.d.cts → contracts/summarization.d.ts} +2 -2
  134. package/dist/contracts/token-accounting.d.cts +1177 -0
  135. package/dist/contracts/token-accounting.d.ts +1177 -0
  136. package/dist/{token-calibration-GtFyMJtM.d.cts → contracts/token-calibration.d.cts} +1 -42
  137. package/dist/{token-calibration-GtFyMJtM.d.ts → contracts/token-calibration.d.ts} +1 -42
  138. package/dist/{reasoning-bffu9R2B.d.cts → contracts/token-usage.d.cts} +9 -84
  139. package/dist/{reasoning-bffu9R2B.d.ts → contracts/token-usage.d.ts} +9 -84
  140. package/dist/contracts.d.cts +24 -10
  141. package/dist/contracts.d.ts +24 -10
  142. package/dist/index.d.cts +14 -77
  143. package/dist/index.d.ts +14 -77
  144. package/dist/ports/agent-invocation.d.cts +42 -0
  145. package/dist/ports/agent-invocation.d.ts +42 -0
  146. package/dist/{audit-DnuOSwWE.d.ts → ports/audit.d.cts} +2 -2
  147. package/dist/{audit-C9LPbPib.d.cts → ports/audit.d.ts} +2 -2
  148. package/dist/ports/canonical-inference.d.cts +135 -0
  149. package/dist/ports/canonical-inference.d.ts +135 -0
  150. package/dist/ports/llm-call.d.cts +109 -0
  151. package/dist/ports/llm-call.d.ts +109 -0
  152. package/dist/ports/llm-input-materialization.d.cts +69 -0
  153. package/dist/ports/llm-input-materialization.d.ts +69 -0
  154. package/dist/{token-counter-BjiHQEJ-.d.ts → ports/token-counter.d.cts} +3 -3
  155. package/dist/{token-counter-DiGIoaq2.d.cts → ports/token-counter.d.ts} +3 -3
  156. package/dist/{tokenizer-yIFTTc-W.d.ts → ports/tokenizer.d.cts} +2 -2
  157. package/dist/{tokenizer-Dz5Y3KT0.d.cts → ports/tokenizer.d.ts} +2 -2
  158. package/dist/ports/tool-schema.d.cts +30 -0
  159. package/dist/ports/tool-schema.d.ts +30 -0
  160. package/dist/ports/usage-normalizer.d.cts +16 -0
  161. package/dist/ports/usage-normalizer.d.ts +16 -0
  162. package/dist/ports.d.cts +10 -9
  163. package/dist/ports.d.ts +10 -9
  164. package/dist/quickstart/defineAgent.d.cts +12 -0
  165. package/dist/quickstart/defineAgent.d.ts +12 -0
  166. package/dist/quickstart/defineConfig.d.cts +7 -0
  167. package/dist/quickstart/defineConfig.d.ts +7 -0
  168. package/dist/quickstart/runAgent.d.cts +12 -0
  169. package/dist/quickstart/runAgent.d.ts +12 -0
  170. package/dist/quickstart/toolRuntime.d.cts +14 -0
  171. package/dist/quickstart/toolRuntime.d.ts +14 -0
  172. package/dist/{runAgent-jxZ0uNto.d.ts → quickstart/types.d.cts} +10 -28
  173. package/dist/{runAgent-QiBiFXHR.d.cts → quickstart/types.d.ts} +10 -28
  174. package/dist/quickstart.d.cts +5 -23
  175. package/dist/quickstart.d.ts +5 -23
  176. package/dist/runtime-kernel/audit/compositeAudit.d.cts +23 -0
  177. package/dist/runtime-kernel/audit/compositeAudit.d.ts +23 -0
  178. package/dist/runtime-kernel/audit/consoleAudit.d.cts +10 -0
  179. package/dist/runtime-kernel/audit/consoleAudit.d.ts +10 -0
  180. package/dist/runtime-kernel/audit/emitAudit.d.cts +31 -0
  181. package/dist/runtime-kernel/audit/emitAudit.d.ts +31 -0
  182. package/dist/runtime-kernel/audit/eventStoreAudit.d.cts +27 -0
  183. package/dist/runtime-kernel/audit/eventStoreAudit.d.ts +27 -0
  184. package/dist/runtime-kernel/audit/fileAudit.d.cts +22 -0
  185. package/dist/runtime-kernel/audit/fileAudit.d.ts +22 -0
  186. package/dist/runtime-kernel/audit/index.d.cts +6 -0
  187. package/dist/runtime-kernel/audit/index.d.ts +6 -0
  188. package/dist/runtime-kernel/audit/noopAudit.d.cts +5 -0
  189. package/dist/runtime-kernel/audit/noopAudit.d.ts +5 -0
  190. package/dist/runtime-kernel/child-run-trace/childRunParentTraceProjection.d.cts +26 -0
  191. package/dist/runtime-kernel/child-run-trace/childRunParentTraceProjection.d.ts +26 -0
  192. package/dist/runtime-kernel/child-run-trace/index.d.cts +4 -0
  193. package/dist/runtime-kernel/child-run-trace/index.d.ts +4 -0
  194. package/dist/runtime-kernel/child-run-trace/projectChildRuntimeEventToSubRunTrace.d.cts +10 -0
  195. package/dist/runtime-kernel/child-run-trace/projectChildRuntimeEventToSubRunTrace.d.ts +10 -0
  196. package/dist/runtime-kernel/child-run-trace/runtimeEventSubRunTracePublisher.d.cts +47 -0
  197. package/dist/runtime-kernel/child-run-trace/runtimeEventSubRunTracePublisher.d.ts +47 -0
  198. package/dist/runtime-kernel/child-run-trace/subrunTrace.types.d.cts +81 -0
  199. package/dist/runtime-kernel/child-run-trace/subrunTrace.types.d.ts +81 -0
  200. package/dist/runtime-kernel/child-runs/childRunInvoker.d.cts +101 -0
  201. package/dist/runtime-kernel/child-runs/childRunInvoker.d.ts +101 -0
  202. package/dist/runtime-kernel/child-runs/historyPolicy.d.cts +9 -0
  203. package/dist/runtime-kernel/child-runs/historyPolicy.d.ts +9 -0
  204. package/dist/runtime-kernel/child-runs/index.d.cts +3 -0
  205. package/dist/runtime-kernel/child-runs/index.d.ts +3 -0
  206. package/dist/runtime-kernel/child-runs/types.d.cts +82 -0
  207. package/dist/runtime-kernel/child-runs/types.d.ts +82 -0
  208. package/dist/runtime-kernel/enrichment/index.d.cts +2 -0
  209. package/dist/runtime-kernel/enrichment/index.d.ts +2 -0
  210. package/dist/runtime-kernel/enrichment/registry.d.cts +25 -0
  211. package/dist/runtime-kernel/enrichment/registry.d.ts +25 -0
  212. package/dist/runtime-kernel/enrichment/types.d.cts +83 -0
  213. package/dist/runtime-kernel/enrichment/types.d.ts +83 -0
  214. package/dist/runtime-kernel/events/agent-to-runtime.d.cts +6 -0
  215. package/dist/runtime-kernel/events/agent-to-runtime.d.ts +6 -0
  216. package/dist/{agentEvents-yvamy9xt.d.cts → runtime-kernel/events/agentEvents.d.cts} +127 -126
  217. package/dist/{agentEvents-DhXdKeXD.d.ts → runtime-kernel/events/agentEvents.d.ts} +127 -126
  218. package/dist/runtime-kernel/events/eventGovernance.d.cts +47 -0
  219. package/dist/runtime-kernel/events/eventGovernance.d.ts +47 -0
  220. package/dist/runtime-kernel/events/eventMappers.d.cts +41 -0
  221. package/dist/runtime-kernel/events/eventMappers.d.ts +41 -0
  222. package/dist/runtime-kernel/events/finalAnswerAssembler.d.cts +27 -0
  223. package/dist/runtime-kernel/events/finalAnswerAssembler.d.ts +27 -0
  224. package/dist/runtime-kernel/events/finalAnswerCompletion.d.cts +6 -0
  225. package/dist/runtime-kernel/events/finalAnswerCompletion.d.ts +6 -0
  226. package/dist/runtime-kernel/events/provider-sidecar.d.cts +33 -0
  227. package/dist/runtime-kernel/events/provider-sidecar.d.ts +33 -0
  228. package/dist/runtime-kernel/events/runtime-to-ai-message.d.cts +14 -0
  229. package/dist/runtime-kernel/events/runtime-to-ai-message.d.ts +14 -0
  230. package/dist/runtime-kernel/events.d.cts +7 -5
  231. package/dist/runtime-kernel/events.d.ts +7 -5
  232. package/dist/runtime-kernel/execution/event-bus.d.cts +52 -0
  233. package/dist/runtime-kernel/execution/event-bus.d.ts +52 -0
  234. package/dist/runtime-kernel/execution/eventBusEventPersistence.d.cts +40 -0
  235. package/dist/runtime-kernel/execution/eventBusEventPersistence.d.ts +40 -0
  236. package/dist/runtime-kernel/execution/index.d.cts +5 -0
  237. package/dist/runtime-kernel/execution/index.d.ts +5 -0
  238. package/dist/runtime-kernel/execution/runtimeErrorEventFactory.d.cts +46 -0
  239. package/dist/runtime-kernel/execution/runtimeErrorEventFactory.d.ts +46 -0
  240. package/dist/runtime-kernel/execution/runtimeEventPublisher.d.cts +34 -0
  241. package/dist/runtime-kernel/execution/runtimeEventPublisher.d.ts +34 -0
  242. package/dist/runtime-kernel/execution/sequencer.d.cts +69 -0
  243. package/dist/runtime-kernel/execution/sequencer.d.ts +69 -0
  244. package/dist/runtime-kernel/graph-engine/checkpointer/base.d.cts +59 -0
  245. package/dist/runtime-kernel/graph-engine/checkpointer/base.d.ts +59 -0
  246. package/dist/runtime-kernel/graph-engine/checkpointer/memoryCheckpointer.d.cts +14 -0
  247. package/dist/runtime-kernel/graph-engine/checkpointer/memoryCheckpointer.d.ts +14 -0
  248. package/dist/runtime-kernel/graph-engine/definitions/primaryPromptCapacityError.d.cts +22 -0
  249. package/dist/runtime-kernel/graph-engine/definitions/primaryPromptCapacityError.d.ts +22 -0
  250. package/dist/runtime-kernel/graph-engine/engine.d.cts +64 -0
  251. package/dist/runtime-kernel/graph-engine/engine.d.ts +64 -0
  252. package/dist/runtime-kernel/graph-engine/event-store/base.d.cts +26 -0
  253. package/dist/runtime-kernel/graph-engine/event-store/base.d.ts +26 -0
  254. package/dist/runtime-kernel/graph-engine/event-store/memoryEventStore.d.cts +14 -0
  255. package/dist/runtime-kernel/graph-engine/event-store/memoryEventStore.d.ts +14 -0
  256. package/dist/runtime-kernel/graph-engine/executor.d.cts +59 -0
  257. package/dist/runtime-kernel/graph-engine/executor.d.ts +59 -0
  258. package/dist/runtime-kernel/graph-engine/executorContextBuilder.d.cts +104 -0
  259. package/dist/runtime-kernel/graph-engine/executorContextBuilder.d.ts +104 -0
  260. package/dist/runtime-kernel/graph-engine/functions/createHostToolCallBootstrap.d.cts +41 -0
  261. package/dist/runtime-kernel/graph-engine/functions/createHostToolCallBootstrap.d.ts +41 -0
  262. package/dist/runtime-kernel/graph-engine/functions/engineStateSnapshot.d.cts +23 -0
  263. package/dist/runtime-kernel/graph-engine/functions/engineStateSnapshot.d.ts +23 -0
  264. package/dist/runtime-kernel/graph-engine/functions/evaluatePrimaryPromptCapacity.d.cts +15 -0
  265. package/dist/runtime-kernel/graph-engine/functions/evaluatePrimaryPromptCapacity.d.ts +15 -0
  266. package/dist/runtime-kernel/graph-engine/functions/runtimeFailureFact.d.cts +7 -0
  267. package/dist/runtime-kernel/graph-engine/functions/runtimeFailureFact.d.ts +7 -0
  268. package/dist/runtime-kernel/graph-engine/index.d.cts +18 -0
  269. package/dist/runtime-kernel/graph-engine/index.d.ts +18 -0
  270. package/dist/runtime-kernel/graph-engine/nodes/llmNode.d.cts +26 -0
  271. package/dist/runtime-kernel/graph-engine/nodes/llmNode.d.ts +26 -0
  272. package/dist/runtime-kernel/graph-engine/nodes/llmNode.eventBridge.d.cts +6 -0
  273. package/dist/runtime-kernel/graph-engine/nodes/llmNode.eventBridge.d.ts +6 -0
  274. package/dist/runtime-kernel/graph-engine/nodes/toolNode.d.cts +44 -0
  275. package/dist/runtime-kernel/graph-engine/nodes/toolNode.d.ts +44 -0
  276. package/dist/runtime-kernel/graph-engine/nodes/userNode.d.cts +8 -0
  277. package/dist/runtime-kernel/graph-engine/nodes/userNode.d.ts +8 -0
  278. package/dist/runtime-kernel/graph-engine/nodes/waitUserNode.d.cts +15 -0
  279. package/dist/runtime-kernel/graph-engine/nodes/waitUserNode.d.ts +15 -0
  280. package/dist/runtime-kernel/graph-engine/tick-pipeline/types.d.cts +57 -0
  281. package/dist/runtime-kernel/graph-engine/tick-pipeline/types.d.ts +57 -0
  282. package/dist/runtime-kernel/graph-engine/types.d.cts +143 -0
  283. package/dist/runtime-kernel/graph-engine/types.d.ts +143 -0
  284. package/dist/runtime-kernel/llm/caller.d.cts +50 -0
  285. package/dist/runtime-kernel/llm/caller.d.ts +50 -0
  286. package/dist/runtime-kernel/llm/canonical-inference/definitions/canonicalInferenceStreamState.d.cts +28 -0
  287. package/dist/runtime-kernel/llm/canonical-inference/definitions/canonicalInferenceStreamState.d.ts +28 -0
  288. package/dist/runtime-kernel/llm/canonical-inference/functions/advanceCanonicalInferenceStreamState.d.cts +6 -0
  289. package/dist/runtime-kernel/llm/canonical-inference/functions/advanceCanonicalInferenceStreamState.d.ts +6 -0
  290. package/dist/runtime-kernel/llm/canonical-inference/orchestration/consumeCanonicalInferenceStream.d.cts +6 -0
  291. package/dist/runtime-kernel/llm/canonical-inference/orchestration/consumeCanonicalInferenceStream.d.ts +6 -0
  292. package/dist/runtime-kernel/llm/definitions/llmCallInvocationContext.d.cts +29 -0
  293. package/dist/runtime-kernel/llm/definitions/llmCallInvocationContext.d.ts +29 -0
  294. package/dist/runtime-kernel/llm/definitions/llmFallbackObserver.d.cts +26 -0
  295. package/dist/runtime-kernel/llm/definitions/llmFallbackObserver.d.ts +26 -0
  296. package/dist/runtime-kernel/llm/functions/evaluateFallbackPromptCapacity.d.cts +9 -0
  297. package/dist/runtime-kernel/llm/functions/evaluateFallbackPromptCapacity.d.ts +9 -0
  298. package/dist/runtime-kernel/llm/index.d.cts +22 -0
  299. package/dist/runtime-kernel/llm/index.d.ts +22 -0
  300. package/dist/runtime-kernel/llm/input-capabilities/definitions/modelInputCapability.d.cts +24 -0
  301. package/dist/runtime-kernel/llm/input-capabilities/definitions/modelInputCapability.d.ts +24 -0
  302. package/dist/runtime-kernel/llm/input-capabilities/definitions/modelInputCapabilityError.d.cts +31 -0
  303. package/dist/runtime-kernel/llm/input-capabilities/definitions/modelInputCapabilityError.d.ts +31 -0
  304. package/dist/runtime-kernel/llm/input-capabilities/functions/createModelInputCompatibilityError.d.cts +13 -0
  305. package/dist/runtime-kernel/llm/input-capabilities/functions/createModelInputCompatibilityError.d.ts +13 -0
  306. package/dist/runtime-kernel/llm/input-capabilities/functions/deriveModelInputRequirement.d.cts +6 -0
  307. package/dist/runtime-kernel/llm/input-capabilities/functions/deriveModelInputRequirement.d.ts +6 -0
  308. package/dist/runtime-kernel/llm/input-capabilities/functions/evaluateModelInputCompatibility.d.cts +7 -0
  309. package/dist/runtime-kernel/llm/input-capabilities/functions/evaluateModelInputCompatibility.d.ts +7 -0
  310. package/dist/runtime-kernel/llm/input-capabilities/orchestration/assertModelInputCompatibility.d.cts +10 -0
  311. package/dist/runtime-kernel/llm/input-capabilities/orchestration/assertModelInputCompatibility.d.ts +10 -0
  312. package/dist/runtime-kernel/llm/modelCatalog.d.cts +62 -0
  313. package/dist/runtime-kernel/llm/modelCatalog.d.ts +62 -0
  314. package/dist/runtime-kernel/llm/modelResolver.d.cts +40 -0
  315. package/dist/runtime-kernel/llm/modelResolver.d.ts +40 -0
  316. package/dist/runtime-kernel/llm/policies/defaultPolicyEngine.d.cts +15 -0
  317. package/dist/runtime-kernel/llm/policies/defaultPolicyEngine.d.ts +15 -0
  318. package/dist/runtime-kernel/llm/policies/policyEngine.d.cts +18 -0
  319. package/dist/runtime-kernel/llm/policies/policyEngine.d.ts +18 -0
  320. package/dist/runtime-kernel/llm/policies/types.d.cts +27 -0
  321. package/dist/runtime-kernel/llm/policies/types.d.ts +27 -0
  322. package/dist/runtime-kernel/llm/request-builder.d.cts +22 -0
  323. package/dist/runtime-kernel/llm/request-builder.d.ts +22 -0
  324. package/dist/runtime-kernel/llm/usage-telemetry.d.cts +17 -0
  325. package/dist/runtime-kernel/llm/usage-telemetry.d.ts +17 -0
  326. package/dist/runtime-kernel/run-context/index.d.cts +1 -0
  327. package/dist/runtime-kernel/run-context/index.d.ts +1 -0
  328. package/dist/runtime-kernel/run-context/types.d.cts +44 -0
  329. package/dist/runtime-kernel/run-context/types.d.ts +44 -0
  330. package/dist/runtime-kernel/run-supervisor/definitions/runSupervisorContracts.d.cts +131 -0
  331. package/dist/runtime-kernel/run-supervisor/definitions/runSupervisorContracts.d.ts +131 -0
  332. package/dist/runtime-kernel/run-supervisor/index.d.cts +6 -0
  333. package/dist/runtime-kernel/run-supervisor/index.d.ts +6 -0
  334. package/dist/runtime-kernel/run-supervisor/memoryRunRegistryStore.d.cts +15 -0
  335. package/dist/runtime-kernel/run-supervisor/memoryRunRegistryStore.d.ts +15 -0
  336. package/dist/runtime-kernel/run-supervisor/runErrors.d.cts +24 -0
  337. package/dist/runtime-kernel/run-supervisor/runErrors.d.ts +24 -0
  338. package/dist/runtime-kernel/run-supervisor/runHandle.d.cts +155 -0
  339. package/dist/runtime-kernel/run-supervisor/runHandle.d.ts +155 -0
  340. package/dist/runtime-kernel/run-supervisor/runRegistryStorePort.d.cts +47 -0
  341. package/dist/runtime-kernel/run-supervisor/runRegistryStorePort.d.ts +47 -0
  342. package/dist/runtime-kernel/run-supervisor/runSupervisor.d.cts +57 -0
  343. package/dist/runtime-kernel/run-supervisor/runSupervisor.d.ts +57 -0
  344. package/dist/runtime-kernel/system-reminder/apply.d.cts +38 -0
  345. package/dist/runtime-kernel/system-reminder/apply.d.ts +38 -0
  346. package/dist/runtime-kernel/system-reminder/helpers.d.cts +11 -0
  347. package/dist/runtime-kernel/system-reminder/helpers.d.ts +11 -0
  348. package/dist/runtime-kernel/system-reminder/index.d.cts +7 -0
  349. package/dist/runtime-kernel/system-reminder/index.d.ts +7 -0
  350. package/dist/runtime-kernel/system-reminder/registry.d.cts +17 -0
  351. package/dist/runtime-kernel/system-reminder/registry.d.ts +17 -0
  352. package/dist/runtime-kernel/system-reminder/rules.d.cts +20 -0
  353. package/dist/runtime-kernel/system-reminder/rules.d.ts +20 -0
  354. package/dist/runtime-kernel/system-reminder/templates.d.cts +10 -0
  355. package/dist/runtime-kernel/system-reminder/templates.d.ts +10 -0
  356. package/dist/runtime-kernel/system-reminder/triggers.d.cts +10 -0
  357. package/dist/runtime-kernel/system-reminder/triggers.d.ts +10 -0
  358. package/dist/runtime-kernel/system-reminder/types.d.cts +46 -0
  359. package/dist/runtime-kernel/system-reminder/types.d.ts +46 -0
  360. package/dist/runtime-kernel/telemetry/index.d.cts +3 -0
  361. package/dist/runtime-kernel/telemetry/index.d.ts +3 -0
  362. package/dist/runtime-kernel/telemetry/noopTelemetry.d.cts +5 -0
  363. package/dist/runtime-kernel/telemetry/noopTelemetry.d.ts +5 -0
  364. package/dist/runtime-kernel/telemetry/telemetryEvents.d.cts +5 -0
  365. package/dist/runtime-kernel/telemetry/telemetryEvents.d.ts +5 -0
  366. package/dist/runtime-kernel/telemetry/telemetryPort.d.cts +95 -0
  367. package/dist/runtime-kernel/telemetry/telemetryPort.d.ts +95 -0
  368. package/dist/runtime-kernel/testkit/defaultGraphExecutor.d.cts +23 -0
  369. package/dist/runtime-kernel/testkit/defaultGraphExecutor.d.ts +23 -0
  370. package/dist/runtime-kernel/testkit/graphLoopHarness.d.cts +49 -0
  371. package/dist/runtime-kernel/testkit/graphLoopHarness.d.ts +49 -0
  372. package/dist/runtime-kernel/token-accounting/functions.d.cts +27 -0
  373. package/dist/runtime-kernel/token-accounting/functions.d.ts +27 -0
  374. package/dist/runtime-kernel/token-accounting/index.d.cts +1 -0
  375. package/dist/runtime-kernel/token-accounting/index.d.ts +1 -0
  376. package/dist/runtime-kernel/tools/argNormalizer.d.cts +10 -0
  377. package/dist/runtime-kernel/tools/argNormalizer.d.ts +10 -0
  378. package/dist/runtime-kernel/tools/conversationView.d.cts +22 -0
  379. package/dist/runtime-kernel/tools/conversationView.d.ts +22 -0
  380. package/dist/runtime-kernel/tools/idempotency/toolIdempotency.d.cts +25 -0
  381. package/dist/runtime-kernel/tools/idempotency/toolIdempotency.d.ts +25 -0
  382. package/dist/runtime-kernel/tools/index.d.cts +15 -0
  383. package/dist/runtime-kernel/tools/index.d.ts +15 -0
  384. package/dist/runtime-kernel/tools/model-input/definitions/toolModelInput.d.cts +51 -0
  385. package/dist/runtime-kernel/tools/model-input/definitions/toolModelInput.d.ts +51 -0
  386. package/dist/runtime-kernel/tools/model-input/definitions/toolModelInputPolicy.d.cts +17 -0
  387. package/dist/runtime-kernel/tools/model-input/definitions/toolModelInputPolicy.d.ts +17 -0
  388. package/dist/runtime-kernel/tools/model-input/functions/parseToolModelInputDeclaration.d.cts +17 -0
  389. package/dist/runtime-kernel/tools/model-input/functions/parseToolModelInputDeclaration.d.ts +17 -0
  390. package/dist/runtime-kernel/tools/model-input/orchestration/resolveToolModelInput.d.cts +16 -0
  391. package/dist/runtime-kernel/tools/model-input/orchestration/resolveToolModelInput.d.ts +16 -0
  392. package/dist/runtime-kernel/tools/ports.d.cts +119 -0
  393. package/dist/runtime-kernel/tools/ports.d.ts +119 -0
  394. package/dist/runtime-kernel/tools/schema/functions/assertToolParameterSchema.d.cts +15 -0
  395. package/dist/runtime-kernel/tools/schema/functions/assertToolParameterSchema.d.ts +15 -0
  396. package/dist/runtime-kernel/tools/toolContextPatch.d.cts +14 -0
  397. package/dist/runtime-kernel/tools/toolContextPatch.d.ts +14 -0
  398. package/dist/runtime-kernel/tools/toolContextRuntime.d.cts +37 -0
  399. package/dist/runtime-kernel/tools/toolContextRuntime.d.ts +37 -0
  400. package/dist/runtime-kernel/tools/toolContracts.d.cts +109 -0
  401. package/dist/runtime-kernel/tools/toolContracts.d.ts +109 -0
  402. package/dist/runtime-kernel/tools/toolExecutionContext.d.cts +104 -0
  403. package/dist/runtime-kernel/tools/toolExecutionContext.d.ts +104 -0
  404. package/dist/runtime-kernel/tools/ui-types.d.cts +72 -0
  405. package/dist/runtime-kernel/tools/ui-types.d.ts +72 -0
  406. package/dist/runtime-kernel.d.cts +106 -20
  407. package/dist/runtime-kernel.d.ts +106 -20
  408. package/dist/shared/defaultTokenizerPort.d.cts +29 -0
  409. package/dist/shared/defaultTokenizerPort.d.ts +29 -0
  410. package/dist/shared/errorClassifier.d.cts +42 -0
  411. package/dist/shared/errorClassifier.d.ts +42 -0
  412. package/dist/shared/llmAuditProjection.d.cts +11 -0
  413. package/dist/shared/llmAuditProjection.d.ts +11 -0
  414. package/dist/shared/llmAuditRecorder.d.cts +44 -0
  415. package/dist/shared/llmAuditRecorder.d.ts +44 -0
  416. package/dist/shared/llmImageInputError.d.cts +34 -0
  417. package/dist/shared/llmImageInputError.d.ts +34 -0
  418. package/dist/shared/llmTelemetryContext.d.cts +52 -0
  419. package/dist/shared/llmTelemetryContext.d.ts +52 -0
  420. package/dist/shared/logger.d.cts +12 -0
  421. package/dist/shared/logger.d.ts +12 -0
  422. package/dist/{prompt-budget-yciFkC9U.d.cts → shared/prompt-budget.d.cts} +2 -1
  423. package/dist/{prompt-budget-yciFkC9U.d.ts → shared/prompt-budget.d.ts} +2 -1
  424. package/dist/testkit/agent-harness/assertions.d.cts +10 -0
  425. package/dist/testkit/agent-harness/assertions.d.ts +10 -0
  426. package/dist/testkit/agent-harness/scriptedInferenceHarness.d.cts +52 -0
  427. package/dist/testkit/agent-harness/scriptedInferenceHarness.d.ts +52 -0
  428. package/dist/testkit/context-harness/invariants/index.d.cts +7 -0
  429. package/dist/testkit/context-harness/invariants/index.d.ts +7 -0
  430. package/dist/testkit/context-harness/invariants/types.d.cts +32 -0
  431. package/dist/testkit/context-harness/invariants/types.d.ts +32 -0
  432. package/dist/testkit/context-harness/replayHarness.d.cts +18 -0
  433. package/dist/testkit/context-harness/replayHarness.d.ts +18 -0
  434. package/dist/testkit/mocks/tokenizerPort.d.cts +17 -0
  435. package/dist/testkit/mocks/tokenizerPort.d.ts +17 -0
  436. package/dist/testkit/run-harness/collectingAuditPort.d.cts +21 -0
  437. package/dist/testkit/run-harness/collectingAuditPort.d.ts +21 -0
  438. package/dist/testkit/run-harness/invariants/index.d.cts +7 -0
  439. package/dist/testkit/run-harness/invariants/index.d.ts +7 -0
  440. package/dist/testkit/run-harness/invariants/types.d.cts +48 -0
  441. package/dist/testkit/run-harness/invariants/types.d.ts +48 -0
  442. package/dist/testkit/run-harness/mockTelemetryPort.d.cts +35 -0
  443. package/dist/testkit/run-harness/mockTelemetryPort.d.ts +35 -0
  444. package/dist/testkit/run-harness/runSupervisorHarness.d.cts +60 -0
  445. package/dist/testkit/run-harness/runSupervisorHarness.d.ts +60 -0
  446. package/dist/testkit/tool-fixtures/toolContext.d.cts +19 -0
  447. package/dist/testkit/tool-fixtures/toolContext.d.ts +19 -0
  448. package/dist/testkit.d.cts +17 -277
  449. package/dist/testkit.d.ts +17 -277
  450. package/package.json +6 -4
  451. package/dist/base-DRRrRhxS.d.cts +0 -216
  452. package/dist/base-DVyQIl_d.d.ts +0 -216
  453. package/dist/defaultGraphExecutor-Chr16eYO.d.cts +0 -914
  454. package/dist/defaultGraphExecutor-hT7dchpC.d.ts +0 -914
  455. package/dist/index-1pE6gSpV.d.cts +0 -172
  456. package/dist/index-C2PSqU1I.d.cts +0 -1971
  457. package/dist/index-CZMXtw4h.d.ts +0 -1971
  458. package/dist/index-D_csW7Zl.d.ts +0 -172
  459. package/dist/index-DpSWZ1L6.d.ts +0 -67
  460. package/dist/index-oCM3XEu2.d.cts +0 -67
  461. package/dist/llm-input-materialization-Vce5Swvc.d.ts +0 -366
  462. package/dist/llm-input-materialization-r-V3n9U-.d.cts +0 -366
  463. package/dist/runHandle--l0kE205.d.cts +0 -490
  464. package/dist/runHandle-ouLd6Tgp.d.ts +0 -490
  465. package/dist/token-accounting-19cXG7hM.d.cts +0 -3342
  466. package/dist/token-accounting-CVW37Uri.d.ts +0 -3342
  467. package/dist/toolContracts--KrHHNCY.d.cts +0 -424
  468. package/dist/toolContracts-BQ4kIso_.d.ts +0 -424
@@ -1,914 +0,0 @@
1
- import { i as EventStore, P as PersistedEvent, E as EventRangeOptions, I as RunRegistryStore, H as RunRecord, L as ListRunsFilter, J as RunRequestSnapshot, u as EventBus, y as RunCostCollector, A as RunHandle, G as RunObserveFilter, v as CancelOpts, x as RunAwaitingUserPatch, F as RunMeta, t as ToolRuntimePort, O as ObservationPreviewPort, f as ToolModelInputCapabilityValidatorPort, e as ToolModelInputResolverPort } from './runHandle--l0kE205.cjs';
2
- import { m as AdapterInputSupport, a as ToolExecutionContext, b as ModelInputRequirement, M as ModelInputPlacement, e as ToolCallStreamingPolicy, f as ToolContextConversationView } from './toolContracts--KrHHNCY.cjs';
3
- import { c as RunId, T as ToolCallId, P as ProviderContinuation, a as AssistantReplayPart, E as ExecutionId } from './provider-continuation-CTZdCB--.cjs';
4
- import { R as RuntimeEvent, f as RoutedRuntimeEvent } from './final-answer-B0_kx5_U.cjs';
5
- import { L as LlmUsageTokenLedgerEntry, C as ContextTokenComponent, s as ContextComponentTokenLedgerEntry, b as AgentSpecSystemReminderPolicy, q as AgentSpecToolObservationGovernancePolicy, c as AgentSpec } from './token-accounting-19cXG7hM.cjs';
6
- import { A as AuditPort } from './audit-C9LPbPib.cjs';
7
- import { l as CanonicalInferencePort, v as LlmInputMaterializerPort, T as ToolCall, I as ImageInputAdmissionEvidence, w as LlmRequestMessage, r as LlmCallOptions, b as AgentInvocationRequest } from './llm-input-materialization-r-V3n9U-.cjs';
8
- import { A as AnyAgentEvent } from './agentEvents-yvamy9xt.cjs';
9
- import { C as CanonicalLlmUsage, M as ModelReasoningConfig, T as TokenRoute, c as ContextUsageSnapshot } from './reasoning-bffu9R2B.cjs';
10
- import { C as ContextBuildTokenEstimate, f as ContextCompactionErrorCode } from './token-calibration-GtFyMJtM.cjs';
11
- import { S as SummarizationCallbacks } from './summarization-kLeweZ5-.cjs';
12
-
13
- /**
14
- * @file src/agent/shared/llmTelemetryContext.ts
15
- *
16
- * @description
17
- * LLM Telemetry 上下文(用于审计/统计,不进入模型上下文,不落库到 EventStore)。
18
- *
19
- * 中文备注(设计约束):
20
- * - 某些“多阶段/多子任务”的审计需要一个可聚合的数据源;
21
- * - 这些数据不适合塞进 RuntimeEvent(会污染主时间轴、跨端联动成本高);
22
- * - 因此这里用 AsyncLocalStorage 提供“同一条异步链路内可写入/可聚合”的基础设施;
23
- * - 默认不启用:只有当业务侧显式用 `withLLMTelemetryContext(...)` 包裹执行链路时才会收集。
24
- */
25
-
26
- type NormalizedLlmUsage = {
27
- promptTokens: number;
28
- completionTokens: number;
29
- totalTokens: number;
30
- canonicalUsage?: CanonicalLlmUsage;
31
- };
32
- type LLMTelemetryContext = {
33
- /**
34
- * 预留:用于业务侧注入“聚合维度”。
35
- *
36
- * 中文备注:
37
- * - 该字段不进入模型上下文、不落库,仅用于本地统计/审计聚合;
38
- * - 建议只放稳定标识(如 conversationId/turnId/runId 等),避免塞入大对象。
39
- */
40
- scope?: {
41
- conversationId?: string;
42
- turnId?: string;
43
- runId?: string;
44
- stepId?: string;
45
- stepIndex?: number;
46
- };
47
- };
48
- type LlmCallTelemetry = {
49
- modelId: string;
50
- stream: boolean;
51
- startedAt: number;
52
- durationMs: number;
53
- usage?: NormalizedLlmUsage;
54
- canonicalUsage?: CanonicalLlmUsage;
55
- };
56
- declare function withLLMTelemetryContext<T>(ctx: LLMTelemetryContext, fn: () => Promise<T>): Promise<{
57
- value: T;
58
- calls: LlmCallTelemetry[];
59
- }>;
60
-
61
- declare const TELEMETRY_EVENT_KINDS: readonly ["llm_call", "tool_call", "context_build", "context_compaction", "graph_node", "run_lifecycle"];
62
- type TelemetryEventKind = (typeof TELEMETRY_EVENT_KINDS)[number];
63
-
64
- type TelemetryScope = {
65
- conversationId?: string;
66
- runId?: string;
67
- parentRunId?: string;
68
- turnId?: string;
69
- stepId?: string;
70
- };
71
- type ContextCompactionTelemetryOutcome = 'skipped' | 'completed' | 'failed' | 'insufficient' | 'aborted';
72
- type ContextCompactionSuppressedReason = 'disabled' | 'below_trigger' | 'no_replaceable_range' | 'forced_final_answer' | 'forced_tools' | 'max_compactions_reached' | 'duplicate_plan_fingerprint';
73
- type RunLifecycleTerminalReason = 'completed' | 'awaiting_user' | 'step_budget_forced_completion' | 'step_budget_exhausted' | 'capacity_failed' | 'failed' | 'cancelled';
74
- type TelemetryEvent = {
75
- kind: Extract<TelemetryEventKind, 'llm_call'>;
76
- modelId: string;
77
- stream: boolean;
78
- durationMs: number;
79
- usage?: NormalizedLlmUsage;
80
- canonicalUsage?: CanonicalLlmUsage;
81
- tokenLedgerEntry?: LlmUsageTokenLedgerEntry;
82
- phase?: 'main' | 'context-internal';
83
- purpose?: string;
84
- scope: TelemetryScope;
85
- } | {
86
- kind: Extract<TelemetryEventKind, 'tool_call'>;
87
- toolName: string;
88
- durationMs: number;
89
- ok: boolean;
90
- errorCode?: string;
91
- scope: TelemetryScope;
92
- } | {
93
- kind: Extract<TelemetryEventKind, 'context_build'>;
94
- modelId: string;
95
- tokenEstimate: ContextBuildTokenEstimate;
96
- tokenComponents?: ContextTokenComponent[];
97
- tokenLedgerEntry?: ContextComponentTokenLedgerEntry;
98
- scope: TelemetryScope;
99
- } | {
100
- kind: Extract<TelemetryEventKind, 'context_compaction'>;
101
- modelId: string;
102
- durationMs: number;
103
- compactionIndex: number;
104
- maxCompactionsPerRun: number;
105
- /** 是否已经向当前锁定的 Provider 发出摘要生成请求。 */
106
- generationAttempted: boolean;
107
- triggerRatio: number;
108
- targetRatio: number;
109
- beforeTokens: number;
110
- inputBudgetTokens: number;
111
- compactionInputTokens?: number;
112
- afterTokens?: number;
113
- replacedMessageCount: number;
114
- replacedToolGroupCount: number;
115
- keptToolGroupCount: number;
116
- summaryOutputTokens?: number;
117
- /** 原始摘要 / 被替换区段 token 比率;无效压缩可大于等于 1。 */
118
- compressionRatio?: number;
119
- canonicalUsage?: CanonicalLlmUsage;
120
- outcome: ContextCompactionTelemetryOutcome;
121
- suppressedReason?: ContextCompactionSuppressedReason;
122
- forcedPhaseRecovery: boolean;
123
- targetUnreachable?: boolean;
124
- errorCode?: ContextCompactionErrorCode;
125
- failureReason?: string;
126
- scope: TelemetryScope;
127
- } | {
128
- kind: Extract<TelemetryEventKind, 'graph_node'>;
129
- nodeId: string;
130
- durationMs: number;
131
- scope: TelemetryScope;
132
- } | {
133
- kind: Extract<TelemetryEventKind, 'run_lifecycle'>;
134
- runId: string;
135
- phase: 'spawned';
136
- scope: TelemetryScope;
137
- } | {
138
- kind: Extract<TelemetryEventKind, 'run_lifecycle'>;
139
- runId: string;
140
- phase: 'completed' | 'failed' | 'cancelled';
141
- stepsUsed: number;
142
- maxSteps: number;
143
- terminalReason: RunLifecycleTerminalReason;
144
- scope: TelemetryScope;
145
- };
146
- interface TelemetryPort {
147
- emit(event: TelemetryEvent): void;
148
- flush?(): Promise<void>;
149
- }
150
-
151
- /**
152
- * @file src/agent/runtime-kernel/llm/modelCatalog.ts
153
- *
154
- * @description
155
- * Agent runtime 对“模型目录”的最小协议定义。
156
- * runtime-kernel 只依赖这些查询能力,不直接依赖 app 的 Model Catalog 实现。
157
- */
158
-
159
- interface ModelCatalogEntry {
160
- id: string;
161
- enabled?: boolean;
162
- api_key?: string;
163
- billing_mode?: 'byok' | 'cloud';
164
- /**
165
- * 是否允许客户端侧重试。
166
- *
167
- * 说明:
168
- * - runtime-kernel 会基于该字段与 billing_mode 决定重试策略;
169
- * - 该字段来自上层 Model Catalog(对齐 `src/domains/model-catalog/definitions/modelCatalog.ts`),避免在 runtime 侧出现类型漂移。
170
- */
171
- enable_client_retry?: boolean;
172
- model_name?: string;
173
- capabilities?: readonly string[];
174
- ui_visibility?: readonly string[];
175
- /** Host 根据显式 inference route/capability 解析出的输入 placement 支持。 */
176
- adapter_input_support?: AdapterInputSupport;
177
- /**
178
- * 思考努力程度能力契约。
179
- *
180
- * 说明:
181
- * - 来自上层 Model Catalog 的 `ModelConfig.reasoning`(宿主 `defaultModelCatalog` 透传完整 `ModelConfig`);
182
- * - kernel 侧 `prepareCallStage` 用它 + 用户请求档位调 `resolveEffectiveEffort()` 做统一降级;
183
- * - 缺失表示该模型不支持 reasoning 控制,调用方不发任何思考相关字段。
184
- */
185
- reasoning?: ModelReasoningConfig;
186
- /** Chat route 的容量事实;fallback admission 只能读取正式 route。 */
187
- inference_route?: {
188
- context_window_tokens: number;
189
- max_output_tokens: number;
190
- };
191
- /** Host 已解析的 token accounting route。 */
192
- token_route?: TokenRoute;
193
- }
194
- interface ModelCatalogLike {
195
- getModelById(id: string): ModelCatalogEntry | undefined;
196
- getModelsByCapability(capability: string): ModelCatalogEntry[];
197
- getModelsByUIVisibility(visibility: string): ModelCatalogEntry[];
198
- }
199
- /**
200
- * 为已由调用方提供的外部聊天引擎建立最小 catalog。
201
- *
202
- * quickstart 的 canonical inference port 本身承诺该 ID 可聊天;但它没有 Host route profile,
203
- * 因此图片 placement 必须保持关闭,不能从“能聊天”推断“能识图”。
204
- */
205
- declare function createFixedChatModelCatalog(modelId: string): ModelCatalogLike;
206
-
207
- type ExecutorLlmInvocationKind = 'user_initiated' | 'continuation';
208
- /** 工具批次全部结算后的 Graph 路由策略;缺省继续交还 LLM。 */
209
- type ToolBatchCompletionMode = 'continue_to_llm' | 'yield_after_batch';
210
- interface ExecutorLocalState {
211
- stepCount: number;
212
- phase?: 'running' | 'force_final_answer' | 'force_tools' | string;
213
- maxSteps?: number;
214
- remainingSteps?: number;
215
- finalStepPolicy?: 'final_answer' | 'force_tools';
216
- finalStepForcedTools?: string[];
217
- lastStepsHintThreshold?: number;
218
- systemReminderPolicy?: AgentSpecSystemReminderPolicy;
219
- toolObservationPolicy?: AgentSpecToolObservationGovernancePolicy;
220
- runLockedModelId?: string;
221
- /** 最近一次成功产生当前工具调用决策的真实 provider model。 */
222
- lastSuccessfulLlmModelId?: string;
223
- /**
224
- * 当前这一次 LLM 调用的业务来源。
225
- *
226
- * 中文备注:
227
- * - 该字段由 GraphExecutor 在进入 llm 节点前注入;
228
- * - prepareCallStage 只能读这个显式语义,不能再用 stepCount 推断是否续跑;
229
- * - user_initiated 表示本 run 第一次 LLM 调用,continuation 表示工具/恢复后的后续 LLM 调用。
230
- */
231
- llmInvocationKind?: ExecutorLlmInvocationKind;
232
- /**
233
- * GraphExecutor 内部维护的 LLM 调用次数。
234
- *
235
- * 中文备注:
236
- * - 它用于 child-run 直接从 llm 启动时稳定推导 llmInvocationKind;
237
- * - 业务逻辑不要直接修改它。
238
- */
239
- llmInvocationCount?: number;
240
- /**
241
- * 固定模型运行时约束。
242
- *
243
- * 中文备注:
244
- * - 这是执行期策略,不是业务状态;用于工具内部子 agent 等必须使用确定模型的场景;
245
- * - 为 true 时,LLM 层不得 policy switch,也不得走 cloud quota fallback。
246
- */
247
- lockRequestedModelId?: boolean;
248
- /** 当前 run 的压缩调用次数、成功提交次数与最近已提交计划身份。 */
249
- contextCompaction?: {
250
- attemptCount: number;
251
- committedCount: number;
252
- lastCommittedFingerprint?: string;
253
- };
254
- }
255
- type ExecutorLocalPatch = Partial<Pick<ExecutorLocalState, 'runLockedModelId' | 'lastSuccessfulLlmModelId' | 'contextCompaction'>>;
256
- interface EngineLocalState extends Record<string, unknown> {
257
- runId?: RunId;
258
- parentRunId?: RunId;
259
- conversationId?: string;
260
- turnId?: string;
261
- request?: Record<string, unknown>;
262
- toolContext?: ToolExecutionContext;
263
- history?: RuntimeEvent[];
264
- newEvents?: RuntimeEvent[];
265
- executorLocal?: ExecutorLocalState;
266
- pendingToolCalls?: StandardToolCall[];
267
- /**
268
- * 当前工具批次全部产生 terminal tool_output 后的执行策略。
269
- *
270
- * Host 确定工具结果本身就是调用结果时,可选择 yield_after_batch;普通 Agent
271
- * 调用保持缺省行为,由 LLM 继续消费工具结果。该策略不改变工具自身的 control。
272
- */
273
- toolBatchCompletionMode?: ToolBatchCompletionMode;
274
- pendingInteractionSpec?: Record<string, unknown>;
275
- lastToolResult?: Record<string, unknown>;
276
- finalAnswer?: string;
277
- answerId?: string;
278
- chunkSeq?: number;
279
- signal?: AbortSignal;
280
- runtimeEventSink?: RuntimeEventSink;
281
- /** 在 fan-out 前请求 Host 持久化单个 durable fact。 */
282
- runtimeEventCommitPort?: RuntimeEventCommitPort;
283
- runtimeFailureFactSink?: RuntimeFailureFactSink;
284
- summarizationCallbacks?: SummarizationCallbacks;
285
- /** 最近一次成功完成的 LLM Prompt 占用;可序列化并随 checkpoint 保留。 */
286
- contextUsage?: ContextUsageSnapshot;
287
- }
288
- /** Graph 节点发布标准事实的唯一出口;返回值是 admission 附着身份后的同一事实。 */
289
- type RuntimeEventSink = (event: RuntimeEvent, source: string) => RoutedRuntimeEvent;
290
- /**
291
- * Graph 在 fan-out 前请求 Host 提交一条 durable RuntimeEvent。
292
- *
293
- * Host 必须先完成 run admission 与落盘,并标记随后的正常
294
- * RuntimeEventSink publish 不重复写库;本 port 自身不做 realtime fan-out。
295
- */
296
- type RuntimeEventCommitPort = (event: RuntimeEvent, source: string) => Promise<void>;
297
- /** 已经通过 RuntimeEventSink admission 并发布的执行终态错误事实。 */
298
- type RuntimeFailureFact = Extract<RoutedRuntimeEvent, {
299
- type: 'error';
300
- }> & {
301
- error_code: string;
302
- retryable: boolean;
303
- };
304
- /** Graph 将已发布的终态错误事实交给 Host lifecycle;只观察事实,不拥有发布或结算。 */
305
- type RuntimeFailureFactSink = (event: RuntimeFailureFact) => void;
306
- declare const ENGINE_STATE_SCHEMA_VERSION = 1;
307
- interface EngineState {
308
- nodeId: string;
309
- /**
310
- * 当前 checkpoint 的单调版本。
311
- *
312
- * start/resume session 通过它拒绝重复或过期恢复;每次持久化都会递增。
313
- */
314
- revision?: number;
315
- /**
316
- * 顶层 schema version,供持久化后端在不解读 local 结构时也能快速判断版本。
317
- *
318
- * 当前 save 路径会统一写入该字段;类型先保持向后兼容,直到旧测试/fixture 全部收敛。
319
- */
320
- schemaVersion?: number;
321
- local?: EngineLocalState;
322
- }
323
- interface NodeResult {
324
- kind: 'route' | 'yield' | 'pause';
325
- nextNodeId?: string;
326
- events?: RoutedRuntimeEvent[];
327
- }
328
- interface GraphNode {
329
- id: string;
330
- run(state: EngineState): Promise<NodeResult>;
331
- }
332
- interface StandardToolCall {
333
- id: ToolCallId;
334
- type: 'function';
335
- function: {
336
- name: string;
337
- arguments: string;
338
- };
339
- }
340
-
341
- /**
342
- * @file checkpointer/base.ts
343
- * @description Engine-state Checkpointer 接口定义。
344
- *
345
- * ## 术语:这里说的 "Checkpointer" 是哪个 checkpoint?
346
- *
347
- * 在 agent 生态里,"checkpoint" 是个被严重重载的词。这个接口指的是
348
- * **graph engine 的执行状态快照**——也就是 `EngineState`:
349
- *
350
- * - `nodeId`: 图执行当前停在哪个节点
351
- * - `pendingToolCalls`: 已发出还未回收的 tool call
352
- * - `executorLocal.stepCount`: 循环步数计数
353
- * - `local`: 节点间共享的中间字典(含 history、executorLocal 等)
354
- *
355
- * 这是 **执行控制层** 的概念:让一次 run 在被打断后能从断点恢复继续推理,
356
- * 让宿主能查询"我现在停在哪个节点、还欠几个 tool call"。
357
- *
358
- * ### 这个 Checkpointer **不是**:
359
- *
360
- * - **不是** 上下文压缩的事实存储。摘要仍由 LLM tick pipeline 生成并作为
361
- * `history_summary` RuntimeEvent 提交;本快照只保留同一 run 的
362
- * `executorLocal.contextCompaction` 计数与最近计划身份,以便 wait-user resume
363
- * 不会重复压缩同一段历史。
364
- *
365
- * - **不是** RuntimeEvent 持久化。事件流的持久化由 `EventStore` 接口负责。
366
- *
367
- * - **不是** Run 元数据持久化。Run 注册由 `RunRegistryStore` 负责。
368
- *
369
- * 名字相同语义不同,是历史遗留。如果你在文档里同时看到 "checkpoint",
370
- * 请按上下文区分:本接口语境下的 checkpoint 永远指 EngineState 快照。
371
- */
372
-
373
- type CheckpointMeta = {
374
- checkpointKey: string;
375
- schemaVersion: number;
376
- savedAt: number;
377
- currentNode?: string;
378
- iterations?: number;
379
- hasPendingToolCalls: boolean;
380
- };
381
- type CheckpointListFilter = {
382
- savedAfter?: number;
383
- limit?: number;
384
- cursor?: string;
385
- };
386
- type CheckpointSummary = CheckpointMeta;
387
- interface Checkpointer {
388
- load(checkpointKey: string): Promise<EngineState | null>;
389
- save(checkpointKey: string, state: EngineState): Promise<void>;
390
- clear(checkpointKey: string): Promise<void>;
391
- peekMeta?(checkpointKey: string): Promise<CheckpointMeta | null>;
392
- list?(filter?: CheckpointListFilter): Promise<CheckpointSummary[]>;
393
- }
394
- declare function summarizeCheckpoint(checkpointKey: string, state: EngineState, savedAt: number): CheckpointSummary;
395
-
396
- type GraphRunResult = {
397
- events: RoutedRuntimeEvent[];
398
- checkpoint: EngineState;
399
- stepCount: number;
400
- };
401
- interface GraphResumeSessionInput {
402
- expectedRevision: number;
403
- localPatch: Record<string, unknown>;
404
- nodeId?: string;
405
- expectedNodeId?: string;
406
- /** 本次 session execution 使用的步数预算;未传时沿用已持久化预算或 executor 默认值。 */
407
- maxSteps?: number;
408
- }
409
- interface GraphSessionExecutionOptions {
410
- /** 当前 session execution 的步数预算;用于共享 GraphExecutor 上的不同 Agent run。 */
411
- maxSteps?: number;
412
- }
413
- interface GraphExecutorConfig {
414
- maxSteps?: number;
415
- /**
416
- * 可选:宿主提供的 TelemetryPort 实现。
417
- * 不传时使用 noopTelemetry(observability 默认关闭,零业务影响)。
418
- */
419
- telemetryPort?: TelemetryPort;
420
- }
421
- declare class GraphExecutor {
422
- private readonly checkpointer;
423
- private nodes;
424
- private ephemeralLocals;
425
- private checkpointQueues;
426
- private readonly config;
427
- private readonly telemetryPort;
428
- constructor(checkpointer: Checkpointer, config?: GraphExecutorConfig);
429
- registerNode(node: GraphNode): void;
430
- peekCheckpoint(checkpointKey: string): Promise<EngineState | null>;
431
- private sanitize;
432
- /**
433
- * 原子启动一次 Graph session。
434
- *
435
- * 同一个 checkpointKey 的“创建初态 + 执行到 yield”共享同一临界区,调用方不再
436
- * 需要组合 prime/runUntilYield,也就不会在两步之间被另一个 run 覆盖。
437
- */
438
- startSession(checkpointKey: string, local: Record<string, unknown>, nodeId?: string, options?: GraphSessionExecutionOptions): Promise<GraphRunResult>;
439
- /** 同一个 run 从已持久化 wait_user checkpoint 继续执行。 */
440
- resumeSession(checkpointKey: string, input: GraphResumeSessionInput): Promise<GraphRunResult>;
441
- clearCheckpoint(checkpointKey: string): Promise<void>;
442
- prime(checkpointKey: string, local: Record<string, unknown>, nodeId?: string): Promise<void>;
443
- setNode(checkpointKey: string, nodeId: string, localPatch?: Record<string, unknown>): Promise<void>;
444
- runUntilYield(checkpointKey: string, options?: GraphSessionExecutionOptions): Promise<GraphRunResult>;
445
- private runWithCheckpointQueue;
446
- private runUntilYieldQueued;
447
- private loadInitialState;
448
- private saveCheckpoint;
449
- private saveCheckpointAndBuildResult;
450
- private runUntilYieldInternal;
451
- }
452
-
453
- /**
454
- * @file src/agent/runtime-kernel/llm/policies/types.ts
455
- *
456
- * @description
457
- * LLM Policy 只对失败后的路由动作给出建议。
458
- * Provider 请求、响应和 continuation 的编解码只属于 Host 注入的 canonical inference adapter。
459
- */
460
- type LLMPolicyMatchContext = {
461
- /** Host 提供的逻辑模型 ID;Linnkit 不解释命名结构。 */
462
- modelId?: string;
463
- };
464
- type LLMPolicyErrorDecision = {
465
- action: 'none';
466
- } | {
467
- action: 'switch_model';
468
- reason: string;
469
- };
470
- interface LLMPolicy {
471
- /** 名称仅用于日志/调试 */
472
- name: string;
473
- /** 是否匹配当前请求上下文 */
474
- match(ctx: LLMPolicyMatchContext): boolean;
475
- /** 给主链路一个失败后的路由建议;不得改写 Provider wire 数据。 */
476
- onError?(error: Error, ctx: LLMPolicyMatchContext): LLMPolicyErrorDecision;
477
- }
478
-
479
- interface ModelResolverOptions {
480
- fallbackModelPreferredOrder?: readonly string[];
481
- modelCatalog?: ModelCatalogLike;
482
- }
483
- interface ModelResolverLike {
484
- resolveModelId(requestedModelId?: string): string;
485
- pickFallbackChatModel(excludedModelIds: Set<string>, requirement: ModelInputRequirement): string | null;
486
- }
487
- /**
488
- * 模型解析职责单独收口,避免 caller / executor stage 混入 registry 选模细节。
489
- */
490
- declare class ModelResolver implements ModelResolverLike {
491
- private readonly fallbackModelPreferredOrder;
492
- private readonly modelCatalog;
493
- constructor(options?: ModelResolverOptions);
494
- resolveModelId(requestedModelId?: string): string;
495
- /**
496
- * 选模规则(严格、可解释):
497
- * - “默认聊天模型”应来自主对话下拉(ui_visibility: 'chat'),而不是“任何具备 chat capability 的模型”。
498
- *
499
- * 根因说明:
500
- * - default_models.json 中存在 mock-chat(capabilities: ['chat'],但 ui_visibility 是 'chat1');
501
- * - 若按 capability='chat' 取第一个,会导致内部流程(如 deep_search 子 Agent)默认落到 mock 模型,
502
- * 从而无法产生 tool_calls / final_answer(只会 yield thought)。
503
- */
504
- private getDefaultChatModel;
505
- /**
506
- * 选择一个可用的“策略切模备用聊天模型”:
507
- * - 必须具备 chat 能力
508
- * - 必须已解析到 api_key(否则必然失败)
509
- * - Host 可通过 fallbackModelPreferredOrder 显式声明顺序;Linnkit 不解释 URL 或 Provider 名称
510
- */
511
- pickFallbackChatModel(excludedModelIds: Set<string>, requirement: ModelInputRequirement): string | null;
512
- }
513
-
514
- interface LlmCallerOptions {
515
- maxRetries?: number;
516
- maxTotalAttempts?: number;
517
- enableEmptyResponseRetry?: boolean;
518
- retryDelayMs?: number;
519
- fallbackModelPreferredOrder?: readonly string[];
520
- modelResolver?: ModelResolverLike;
521
- modelCatalog: ModelCatalogLike;
522
- policyEngine?: {
523
- decideOnError(error: Error, ctx: LLMPolicyMatchContext): LLMPolicyErrorDecision;
524
- };
525
- inferencePort: CanonicalInferencePort;
526
- llmInputMaterializer?: LlmInputMaterializerPort;
527
- }
528
-
529
- /**
530
- * Linnkit 的统一调用结果只保留 canonical 字段。
531
- * Provider 原始 usage 只允许作为 canonicalUsage.rawUsage 的审计证据存在。
532
- */
533
- interface LlmCallResult {
534
- readonly content: string;
535
- readonly tool_calls?: ToolCall[];
536
- readonly provider_continuations?: ProviderContinuation[];
537
- readonly assistant_replay_parts?: AssistantReplayPart[];
538
- readonly canonicalUsage?: CanonicalLlmUsage;
539
- }
540
-
541
- type ModelFallbackPolicy = 'policy-switch' | 'cloud-quota';
542
- interface ModelFallbackAppliedInfo {
543
- readonly fromModelId: string;
544
- readonly toModelId: string;
545
- readonly reason: string;
546
- readonly policy: ModelFallbackPolicy;
547
- }
548
- interface ModelFallbackRejectedInfo {
549
- readonly fromModelId: string;
550
- readonly candidateModelId?: string;
551
- readonly reason: string;
552
- readonly policy: ModelFallbackPolicy;
553
- readonly requiredPlacements: readonly ModelInputPlacement[];
554
- }
555
- interface LlmFallbackObserver {
556
- /** 每次调用只在最终真实 provider attempt 成功后触发一次。 */
557
- readonly onLlmAttemptSucceeded?: (activeModelId: string, contextUsage?: ContextUsageSnapshot) => void;
558
- readonly onCloudQuotaFallbackApplied?: (fallbackModelId: string) => void;
559
- readonly onModelFallbackApplied?: (info: ModelFallbackAppliedInfo) => void;
560
- readonly onModelFallbackRejected?: (info: ModelFallbackRejectedInfo) => void;
561
- }
562
-
563
- type FallbackPromptCapacityRejectionReason = 'fallback_inference_route_missing' | 'fallback_output_limit_unsupported' | 'fallback_context_window_exceeded';
564
- type FallbackPromptCapacityAdmission = {
565
- admitted: true;
566
- } | {
567
- admitted: false;
568
- reason: FallbackPromptCapacityRejectionReason;
569
- };
570
-
571
- /**
572
- * 单次 LLM 调用的短生命周期上下文。
573
- *
574
- * 中文备注:这里的信息只参与 runtime preflight,不能混入 LlmCallOptions,
575
- * 否则 provider request builder 可能把内部预算证据原样发到外部服务。
576
- */
577
- interface LlmCallInvocationContext {
578
- readonly imageInputAdmissionEvidence?: ImageInputAdmissionEvidence;
579
- /** 来自本次实际暴露工具的静态输入要求,不会进入 provider options。 */
580
- readonly additionalModelInputRequirement?: ModelInputRequirement;
581
- /**
582
- * 本次实际暴露工具的流式生命周期声明。
583
- * 该调用上下文不会进入 provider options,请求适配器不得接触此字段。
584
- */
585
- readonly toolCallStreamingPolicies?: Readonly<Record<string, ToolCallStreamingPolicy>>;
586
- /** 每个真实 provider attempt 发送前,按 active route 测量最终 Prompt。 */
587
- readonly measurePromptUsage?: (activeModelId: string, messages: readonly LlmRequestMessage[]) => Promise<ContextUsageSnapshot>;
588
- /** fallback candidate 在真实 attempt 前的本地容量 admission。 */
589
- readonly evaluateFallbackPromptCapacity?: (candidateModelId: string) => FallbackPromptCapacityAdmission;
590
- }
591
-
592
- /**
593
- * @file src/agent/runtime-kernel/llm/caller.ts
594
- *
595
- * @brief LLM 调用器 - 统一管理 LLM 调用、流式适配与重试编排
596
- *
597
- * @description
598
- * 这个文件只保留 orchestrator 职责:
599
- * - 构造依赖;
600
- * - 暴露 call / callStream / callWithRetries 公共方法;
601
- * - 把具体实现委托给 request-builder / streaming-adapter / retry-fallback 等模块。
602
- */
603
-
604
- /**
605
- * LLM 调用器。
606
- *
607
- * 中文备注:
608
- * - 具体策略实现拆到同目录小模块,避免 caller.ts 再次膨胀;
609
- * - public method 签名保持原样,保护现有 host / testkit 调用方。
610
- */
611
- declare class LlmCaller {
612
- private readonly deps;
613
- private readonly modelResolver;
614
- constructor(options: LlmCallerOptions);
615
- /**
616
- * 非流式 LLM 调用。
617
- */
618
- call(modelId: string, messages: LlmRequestMessage[], options?: LlmCallOptions, signal?: AbortSignal, invocationContext?: LlmCallInvocationContext): Promise<LlmCallResult>;
619
- /**
620
- * 流式 LLM 调用。
621
- */
622
- callStream(modelId: string, messages: LlmRequestMessage[], options: LlmCallOptions | undefined, eventHandler: (event: AnyAgentEvent) => void, signal?: AbortSignal, invocationContext?: LlmCallInvocationContext): Promise<LlmCallResult>;
623
- /**
624
- * 带智能重试和模型降级的 LLM 调用。
625
- */
626
- callWithRetries(modelId: string, messages: LlmRequestMessage[], options?: LlmCallOptions, eventHandler?: (event: AnyAgentEvent) => void, signal?: AbortSignal, fallbackObserver?: LlmFallbackObserver, invocationContext?: LlmCallInvocationContext): Promise<LlmCallResult>;
627
- /**
628
- * 获取或使用默认模型 ID。
629
- */
630
- resolveModelId(requestedModelId?: string): string;
631
- }
632
-
633
- declare class MemoryEventStore implements EventStore {
634
- private readonly store;
635
- append(event: PersistedEvent): Promise<void>;
636
- range(conversationId: string, opts?: EventRangeOptions): Promise<PersistedEvent[]>;
637
- latestEventStoreId(conversationId: string): Promise<string | null>;
638
- truncate(conversationId: string, opts: {
639
- beforeEventStoreId?: string;
640
- beforeMs?: number;
641
- }): Promise<void>;
642
- }
643
-
644
- type RuntimeEventSource = () => ReadonlyArray<RuntimeEvent>;
645
- interface ToolContextExecutionMeta {
646
- conversationId?: string;
647
- turnId?: string;
648
- runId?: RunId;
649
- parentRunId?: RunId;
650
- parentToolCallId?: ToolCallId;
651
- }
652
- interface ToolContextRuntimeBinding {
653
- readonly conversationView: ToolContextConversationView;
654
- getWorkingHistoryEvents(): ReadonlyArray<RuntimeEvent>;
655
- getPersistedHistoryEvents(): ReadonlyArray<RuntimeEvent>;
656
- setWorkingHistorySource(source: ReadonlyArray<RuntimeEvent> | RuntimeEventSource): void;
657
- setPersistedHistorySource(source: ReadonlyArray<RuntimeEvent> | RuntimeEventSource): void;
658
- bindExecutionMeta(meta: ToolContextExecutionMeta): void;
659
- readExecutionMeta(): Readonly<ToolContextExecutionMeta>;
660
- }
661
- declare const TOOL_CONTEXT_RUNTIME_RESERVED_KEYS: readonly ["conversationView", "userQuery", "modelId", "conversationId", "turnId", "runId", "parentRunId", "childRunDepth", "childRunContextInjections", "parentToolCallId", "modelInputAdmission"];
662
- declare function ensureToolContextRuntimeCapability(params: {
663
- context: ToolExecutionContext;
664
- persistedHistory?: ReadonlyArray<RuntimeEvent> | RuntimeEventSource;
665
- workingHistory?: ReadonlyArray<RuntimeEvent> | RuntimeEventSource;
666
- executionMeta?: ToolContextExecutionMeta;
667
- }): ToolContextRuntimeBinding;
668
- declare function getToolContextRuntimeBinding(context: ToolExecutionContext): ToolContextRuntimeBinding | undefined;
669
- declare function copyToolContextRuntimeCapability(source: ToolExecutionContext, target: ToolExecutionContext): ToolContextRuntimeBinding;
670
- declare function readToolContextWorkingHistory(context: ToolExecutionContext): ReadonlyArray<RuntimeEvent>;
671
- declare function readToolContextPersistedHistory(context: ToolExecutionContext): ReadonlyArray<RuntimeEvent>;
672
- declare function stripRuntimeReservedToolContextPatch(patch: Partial<ToolExecutionContext> | Record<string, unknown> | undefined): Record<string, unknown>;
673
-
674
- type RuntimeReservedToolContextKey = (typeof TOOL_CONTEXT_RUNTIME_RESERVED_KEYS)[number];
675
- /**
676
- * ToolContext patch 的最小合同。
677
- *
678
- * 中文备注:
679
- * - patch 只表达 host/product 追加字段,不能覆盖 runtime-owned capability;
680
- * - 完全 host 白名单需要由具体宿主定义,本层先在类型层排除运行时保留字段。
681
- */
682
- type ToolContextPatch = Partial<Record<Exclude<string, RuntimeReservedToolContextKey>, unknown>> & Partial<Omit<ToolExecutionContext, RuntimeReservedToolContextKey>>;
683
-
684
- declare class MemoryRunRegistryStore implements RunRegistryStore {
685
- private readonly store;
686
- save(record: RunRecord): Promise<void>;
687
- load(runId: RunId): Promise<RunRecord | null>;
688
- list(filter?: ListRunsFilter): Promise<{
689
- runs: RunRecord[];
690
- nextCursor?: string;
691
- }>;
692
- delete(runId: RunId): Promise<void>;
693
- }
694
-
695
- type RunTerminalStatus = Extract<RunRecord['status'], 'completed' | 'failed' | 'cancelled'>;
696
- type RunTerminalError = {
697
- errorCode: string;
698
- message: string;
699
- recoverable: boolean;
700
- };
701
- interface RunOutcome {
702
- runId: RunId;
703
- status: RunTerminalStatus;
704
- completedAt: number;
705
- currentNode?: string;
706
- iterationsUsed?: number;
707
- error?: RunTerminalError;
708
- metadata?: Record<string, unknown>;
709
- }
710
- interface RunSnapshot extends RunMeta {
711
- metadata?: Record<string, unknown>;
712
- }
713
- interface RunTerminalEvent {
714
- runId: RunId;
715
- status: RunTerminalStatus;
716
- outcome: RunOutcome;
717
- }
718
- interface RunWaitForTerminalOptions {
719
- timeoutMs?: number;
720
- signal?: AbortSignal;
721
- }
722
- interface FindActiveByConversationOptions {
723
- includeChildren?: boolean;
724
- agentSpecId?: string;
725
- }
726
- interface FindRunsByConversationOptions extends FindActiveByConversationOptions {
727
- status?: ListRunsFilter['status'];
728
- }
729
- interface RunResumeInteraction {
730
- interactionId: string;
731
- toolCallId: ToolCallId;
732
- checkpointRevision: number;
733
- resumeToken: string;
734
- }
735
- interface RunResumeClaim<TRequest extends RunRequestSnapshot = RunRequestSnapshot> {
736
- readonly runId: RunId;
737
- readonly handle: RunHandle<TRequest>;
738
- /** 同一逻辑 run 的新 execution 身份必须与 claim 激活原子写入。 */
739
- activate(execution?: {
740
- readonly executionId: ExecutionId;
741
- }): Promise<RunHandle<TRequest>>;
742
- release(): Promise<void>;
743
- }
744
- interface RunExecutionContext<TRequest extends RunRequestSnapshot = RunRequestSnapshot> {
745
- runId: RunId;
746
- parentRunId?: RunId;
747
- conversationId: string;
748
- agentSpec: AgentSpec;
749
- request: TRequest;
750
- signal: AbortSignal;
751
- eventBus: EventBus;
752
- eventStore: EventStore;
753
- costCollector: RunCostCollector;
754
- query?: string;
755
- contextFences?: readonly unknown[];
756
- wakeSource?: string;
757
- ephemeral?: Record<string, unknown>;
758
- metadata?: Record<string, unknown>;
759
- }
760
- interface RunExecutorPort<TRequest extends RunRequestSnapshot = RunRequestSnapshot> {
761
- execute(context: RunExecutionContext<TRequest>): Promise<RunOutcome | void>;
762
- }
763
- interface RunRegistrationSpec<TRequest extends RunRequestSnapshot = RunRequestSnapshot> {
764
- runId?: RunId;
765
- /** 同一 supervisor 内,活跃 run 不得共享同一个业务并发 key。 */
766
- concurrencyKey?: string;
767
- parentRunId?: RunId;
768
- parentSignal?: AbortSignal;
769
- conversationId: string;
770
- agentSpec: AgentSpec;
771
- request: TRequest;
772
- eventBus: EventBus;
773
- eventStore: EventStore;
774
- costCollector: RunCostCollector;
775
- iterationBudget?: RunRecord['iterationBudget'];
776
- query?: string;
777
- contextFences?: readonly unknown[];
778
- wakeSource?: string;
779
- ephemeral?: Record<string, unknown>;
780
- metadata?: Record<string, unknown>;
781
- }
782
- interface RunSupervisor<TRequest extends RunRequestSnapshot = RunRequestSnapshot> {
783
- registerRun(spec: RunRegistrationSpec<TRequest>): Promise<RunHandle<TRequest>>;
784
- spawnDetached(spec: RunRegistrationSpec<TRequest>): Promise<RunHandle<TRequest>>;
785
- observeRun(runId: RunId, filter?: RunObserveFilter): AsyncIterable<RuntimeEvent>;
786
- cancel(runId: RunId, opts: CancelOpts): Promise<void>;
787
- markAwaitingUser(runId: RunId, patch?: RunAwaitingUserPatch): Promise<void>;
788
- list(filter?: ListRunsFilter): Promise<{
789
- runs: RunMeta[];
790
- nextCursor?: string;
791
- }>;
792
- peek(runId: RunId): Promise<RunMeta | null>;
793
- waitForTerminal(runId: RunId, opts?: RunWaitForTerminalOptions): Promise<RunOutcome>;
794
- findActiveByConversation(conversationId: string, opts?: FindActiveByConversationOptions): Promise<RunSnapshot[]>;
795
- /**
796
- * 读取持久 registry 中的对话 run,包括终态和 metadata。
797
- * cleanup 恢复需要重新发现“已终态但后置清理未完成”的 owner,不能只依赖内存 handle。
798
- */
799
- findByConversation(conversationId: string, opts?: FindRunsByConversationOptions): Promise<RunSnapshot[]>;
800
- drain(opts?: RunWaitForTerminalOptions): Promise<RunOutcome[]>;
801
- recoverOnBoot(reason?: string): Promise<RunOutcome[]>;
802
- pause(runId: RunId, reason?: string): Promise<never>;
803
- claimResume(runId: RunId, interaction: RunResumeInteraction, eventBus: EventBus, parentSignal?: AbortSignal): Promise<RunResumeClaim<TRequest>>;
804
- runTree(rootRunId: RunId): Promise<never>;
805
- handleFailure(runId: RunId, error: unknown): Promise<never>;
806
- }
807
- interface DefaultRunSupervisorOptions<TRequest extends RunRequestSnapshot = RunRequestSnapshot> {
808
- registryStore: RunRegistryStore;
809
- auditPort?: AuditPort;
810
- executor?: RunExecutorPort<TRequest>;
811
- runIdFactory?: () => RunId;
812
- now?: () => number;
813
- maxActiveRuns?: number;
814
- }
815
-
816
- declare class DefaultRunSupervisor<TRequest extends RunRequestSnapshot = RunRequestSnapshot> implements RunSupervisor<TRequest> {
817
- private readonly registryStore;
818
- private readonly auditPort?;
819
- private readonly executor?;
820
- private readonly runIdFactory;
821
- private readonly now;
822
- private readonly terminalWaiterRegistry;
823
- private readonly runSlotLimiter;
824
- private readonly runConcurrencyKeys;
825
- private readonly awaitingUserWatcher;
826
- private readonly detachedRunExecutor;
827
- private readonly handles;
828
- private readonly controllers;
829
- private readonly inFlight;
830
- private readonly eventWatchDisposers;
831
- private readonly controlOperations;
832
- constructor(options: DefaultRunSupervisorOptions<TRequest>);
833
- registerRun(spec: RunRegistrationSpec<TRequest>): Promise<RunHandle<TRequest>>;
834
- spawnDetached(spec: RunRegistrationSpec<TRequest>): Promise<RunHandle<TRequest>>;
835
- observeRun(runId: RunId, filter?: RunObserveFilter): AsyncIterable<RuntimeEvent>;
836
- cancel(runId: RunId, opts: CancelOpts): Promise<void>;
837
- markAwaitingUser(runId: RunId, patch?: RunAwaitingUserPatch): Promise<void>;
838
- list(filter?: ListRunsFilter): Promise<{
839
- runs: RunMeta[];
840
- nextCursor?: string;
841
- }>;
842
- peek(runId: RunId): Promise<RunMeta | null>;
843
- waitForTerminal(runId: RunId, opts?: RunWaitForTerminalOptions): Promise<RunOutcome>;
844
- findActiveByConversation(conversationId: string, opts?: FindActiveByConversationOptions): Promise<RunSnapshot[]>;
845
- findByConversation(conversationId: string, opts?: FindRunsByConversationOptions): Promise<RunSnapshot[]>;
846
- drain(opts?: RunWaitForTerminalOptions): Promise<RunOutcome[]>;
847
- recoverOnBoot(reason?: string): Promise<RunOutcome[]>;
848
- pause(_runId: RunId, _reason?: string): Promise<never>;
849
- claimResume(runId: RunId, interaction: RunResumeInteraction, eventBus: EventBus, parentSignal?: AbortSignal): Promise<RunResumeClaim<TRequest>>;
850
- runTree(_rootRunId: RunId): Promise<never>;
851
- handleFailure(_runId: RunId, _error: unknown): Promise<never>;
852
- private notifyTerminalWaiters;
853
- private acquireRunAdmission;
854
- private releaseRunAdmission;
855
- private releaseRunHandleResources;
856
- private cleanupRunResources;
857
- private attachAwaitingUserWatcher;
858
- private activateResumeClaim;
859
- private releaseResumeClaim;
860
- private getHandle;
861
- private withRunControlLock;
862
- }
863
-
864
- interface GraphLoopLlmNodeFactoryParams {
865
- llmCaller: LlmCaller;
866
- toolRuntime: ToolRuntimePort;
867
- }
868
- interface GraphLoopHarnessOptions {
869
- conversationId: string;
870
- turnId: string;
871
- /** Graph checkpoint 身份;不传时测试 harness 以单次 turnId 作为 run-scoped key。 */
872
- runId?: string;
873
- query: string;
874
- request: AgentInvocationRequest;
875
- toolContext: ToolExecutionContext;
876
- llmCaller: LlmCaller;
877
- toolRuntime: ToolRuntimePort;
878
- observationPreview: ObservationPreviewPort;
879
- createLlmNode: (params: GraphLoopLlmNodeFactoryParams) => GraphNode;
880
- executorLocal?: ExecutorLocalState;
881
- history?: RuntimeEvent[];
882
- maxSteps?: number;
883
- signal?: AbortSignal;
884
- auditPort?: AuditPort;
885
- telemetryPort?: TelemetryPort;
886
- modelInputCapabilityValidator?: ToolModelInputCapabilityValidatorPort;
887
- modelInputResolver?: ToolModelInputResolverPort;
888
- /** Host/testkit 装配提供的唯一 RuntimeEvent admission/publish 入口。 */
889
- runtimeEventSink: RuntimeEventSink;
890
- }
891
- interface GraphLoopHarnessRunResult {
892
- checkpointNodeId: string;
893
- stepCount: number;
894
- events: RoutedRuntimeEvent[];
895
- }
896
- interface GraphLoopHarness {
897
- run(): Promise<GraphLoopHarnessRunResult>;
898
- }
899
- declare function createGraphLoopHarness(options: GraphLoopHarnessOptions): GraphLoopHarness;
900
-
901
- interface DefaultGraphExecutorOptions {
902
- llmNode: GraphNode;
903
- toolRuntime: ToolRuntimePort;
904
- observationPreview: ObservationPreviewPort;
905
- maxSteps?: number;
906
- checkpointer?: Checkpointer;
907
- auditPort?: AuditPort;
908
- telemetryPort?: TelemetryPort;
909
- modelInputCapabilityValidator?: ToolModelInputCapabilityValidatorPort;
910
- modelInputResolver?: ToolModelInputResolverPort;
911
- }
912
- declare function createDefaultGraphExecutor(options: DefaultGraphExecutorOptions): GraphExecutor;
913
-
914
- export { type RunRegistrationSpec as $, type LLMPolicy as A, type LLMPolicyMatchContext as B, type Checkpointer as C, type LLMPolicyErrorDecision as D, type ExecutorLocalState as E, type LlmCallInvocationContext as F, type GraphNode as G, type LlmFallbackObserver as H, type ModelFallbackAppliedInfo as I, type ModelFallbackPolicy as J, type ModelFallbackRejectedInfo as K, type LlmCallTelemetry as L, type ModelCatalogEntry as M, type NodeResult as N, ModelResolver as O, createFixedChatModelCatalog as P, DefaultRunSupervisor as Q, type RuntimeEventCommitPort as R, type StandardToolCall as S, type TelemetryPort as T, type DefaultRunSupervisorOptions as U, type FindActiveByConversationOptions as V, type FindRunsByConversationOptions as W, MemoryRunRegistryStore as X, type RunExecutionContext as Y, type RunExecutorPort as Z, type RunOutcome as _, type ModelCatalogLike as a, type RunResumeClaim as a0, type RunResumeInteraction as a1, type RunSnapshot as a2, type RunSupervisor as a3, type RunTerminalError as a4, type RunTerminalEvent as a5, type RunTerminalStatus as a6, type RunWaitForTerminalOptions as a7, type ContextCompactionSuppressedReason as a8, type ContextCompactionTelemetryOutcome as a9, TELEMETRY_EVENT_KINDS as aa, type TelemetryEvent as ab, type TelemetryScope as ac, type DefaultGraphExecutorOptions as ad, type GraphLoopHarness as ae, type GraphLoopHarnessOptions as af, type GraphLoopHarnessRunResult as ag, type GraphLoopLlmNodeFactoryParams as ah, createDefaultGraphExecutor as ai, createGraphLoopHarness as aj, type ExecutorLocalPatch as b, type ModelResolverLike as c, LlmCaller as d, type EngineState as e, type CheckpointMeta as f, type CheckpointListFilter as g, type CheckpointSummary as h, type ToolBatchCompletionMode as i, type EngineLocalState as j, type RuntimeFailureFact as k, ENGINE_STATE_SCHEMA_VERSION as l, type ExecutorLlmInvocationKind as m, GraphExecutor as n, MemoryEventStore as o, type RuntimeEventSink as p, type RuntimeFailureFactSink as q, type ToolContextPatch as r, summarizeCheckpoint as s, copyToolContextRuntimeCapability as t, ensureToolContextRuntimeCapability as u, getToolContextRuntimeBinding as v, withLLMTelemetryContext as w, readToolContextPersistedHistory as x, readToolContextWorkingHistory as y, stripRuntimeReservedToolContextPatch as z };