@leuduan/lagent 0.1.2 → 44.0.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 (353) hide show
  1. package/README.md +28 -15
  2. package/dist/chunks/{UC3FVVJ2.js → 2GCIWSOA.js} +2 -2
  3. package/dist/chunks/2P47AHNK.js +7 -0
  4. package/dist/chunks/3UMZMPWW.js +1 -0
  5. package/dist/chunks/5IRF47YB.js +1 -0
  6. package/dist/chunks/6DRCKZ2C.js +1 -0
  7. package/dist/chunks/6FRNHMCV.js +1 -0
  8. package/dist/chunks/7LI64H5X.js +17 -0
  9. package/dist/chunks/{SL2YLB2F.js → 7VAPNE3L.js} +1 -1
  10. package/dist/chunks/{BM3S37EZ.js → ASSQZH3F.js} +1 -1
  11. package/dist/chunks/B4FXK5ER.js +77 -0
  12. package/dist/chunks/{37YOGDGY.js → BBCW2FZK.js} +1 -1
  13. package/dist/chunks/BPRCULZH.js +1 -0
  14. package/dist/chunks/CANPZYTH.js +24 -0
  15. package/dist/chunks/CQEVREBT.js +1 -0
  16. package/dist/chunks/CUK7CGC7.js +1 -0
  17. package/dist/chunks/D4PQP5MA.js +3 -0
  18. package/dist/chunks/{CDQG7RKA.js → DDZ7YF26.js} +1 -1
  19. package/dist/chunks/EMRB4KCN.js +6 -0
  20. package/dist/chunks/EPYQ5M3B.js +3 -0
  21. package/dist/chunks/G44LG6VL.js +1 -0
  22. package/dist/chunks/GGSVIIWJ.js +2 -0
  23. package/dist/chunks/IAAEP6VL.js +30 -0
  24. package/dist/chunks/{AP6Q4EPT.js → JCTBX33H.js} +1 -1
  25. package/dist/chunks/JFX2MXBA.js +4 -0
  26. package/dist/chunks/JFZZXVWD.js +15 -0
  27. package/dist/chunks/KUZCL2SH.js +1 -0
  28. package/dist/chunks/MHC6VPB4.js +7 -0
  29. package/dist/chunks/MMNNZCBO.js +5 -0
  30. package/dist/chunks/{C5LYCXJG.js → MNJ4SRF7.js} +1 -1
  31. package/dist/chunks/N6IXG2VL.js +1 -0
  32. package/dist/chunks/OCBPT7KE.js +1 -0
  33. package/dist/chunks/OL5A6ITQ.js +1 -0
  34. package/dist/chunks/Q75FUN7D.js +2 -0
  35. package/dist/chunks/Q7S5LFGN.js +1 -0
  36. package/dist/chunks/RCIHV3KG.js +1 -0
  37. package/dist/chunks/S34ZA2R6.js +1 -0
  38. package/dist/chunks/SS3B5W34.js +12 -0
  39. package/dist/chunks/VYMT4TXD.js +1 -0
  40. package/dist/chunks/W57RW55W.js +1 -0
  41. package/dist/compositions/base.d.ts +11 -0
  42. package/dist/{presets → compositions}/codex.d.ts +12 -6
  43. package/dist/{presets/prompts.d.ts → compositions/codexPrompts.d.ts} +1 -1
  44. package/dist/context.d.ts +18 -10
  45. package/dist/index.d.ts +31 -23
  46. package/dist/index.js +1 -77
  47. package/dist/journal/catalog.d.ts +1 -1
  48. package/dist/journal/journal.d.ts +3 -3
  49. package/dist/journal/projection.d.ts +1 -1
  50. package/dist/journal/store.d.ts +3 -3
  51. package/dist/llm/index.d.ts +19 -13
  52. package/dist/llm/index.js +1 -0
  53. package/dist/llm/provider.d.ts +11 -0
  54. package/dist/loop/agent.d.ts +16 -132
  55. package/dist/loop/authorization.d.ts +41 -0
  56. package/dist/loop/auxiliary.d.ts +7 -3
  57. package/dist/loop/chunks.d.ts +3 -3
  58. package/dist/loop/completion.d.ts +17 -0
  59. package/dist/loop/errors.d.ts +6 -29
  60. package/dist/loop/hooks.d.ts +39 -6
  61. package/dist/loop/index.d.ts +7 -28
  62. package/dist/loop/runner.d.ts +134 -0
  63. package/dist/loop/runtime.d.ts +7 -16
  64. package/dist/loop/strategy.d.ts +12 -3
  65. package/dist/loop/{prepare.d.ts → surfacePrepare.d.ts} +2 -2
  66. package/dist/loop/tool.d.ts +11 -6
  67. package/dist/loop/toolCalls.d.ts +3 -10
  68. package/dist/plugin.d.ts +31 -34
  69. package/dist/plugin.js +1 -1
  70. package/dist/plugins/agentsMd.d.ts +24 -20
  71. package/dist/plugins/agentsMd.js +1 -1
  72. package/dist/plugins/ask/index.d.ts +2 -2
  73. package/dist/plugins/ask/index.js +1 -1
  74. package/dist/plugins/ask/service.d.ts +2 -2
  75. package/dist/plugins/commands/index.d.ts +5 -2
  76. package/dist/plugins/commands/index.js +1 -1
  77. package/dist/plugins/commands/output.d.ts +1 -1
  78. package/dist/plugins/commands/record.d.ts +31 -22
  79. package/dist/plugins/commands/service.d.ts +18 -11
  80. package/dist/plugins/commands/{background.d.ts → tools.d.ts} +2 -0
  81. package/dist/plugins/compaction/checkpoint.d.ts +4 -1
  82. package/dist/plugins/compaction/config.d.ts +3 -3
  83. package/dist/plugins/compaction/estimate.d.ts +9 -1
  84. package/dist/plugins/compaction/index.d.ts +87 -2
  85. package/dist/plugins/compaction/index.js +5 -5
  86. package/dist/plugins/compaction/{records.d.ts → record.d.ts} +36 -36
  87. package/dist/plugins/compaction/{log.d.ts → state.d.ts} +8 -1
  88. package/dist/plugins/dateAndBranch.js +1 -1
  89. package/dist/plugins/delegations/answers.d.ts +1 -1
  90. package/dist/plugins/delegations/assignmentKey.d.ts +1 -1
  91. package/dist/plugins/delegations/cleanup.d.ts +1 -1
  92. package/dist/plugins/delegations/index.js +1 -1
  93. package/dist/plugins/delegations/notices.d.ts +8 -8
  94. package/dist/plugins/delegations/obligations.d.ts +13 -13
  95. package/dist/plugins/delegations/record.d.ts +11 -10
  96. package/dist/plugins/delegations/request.d.ts +8 -5
  97. package/dist/plugins/delegations/role.d.ts +1 -1
  98. package/dist/plugins/delegations/service.d.ts +9 -8
  99. package/dist/plugins/delegations/{waitBook.d.ts → waitResolver.d.ts} +9 -9
  100. package/dist/plugins/diagnostics/digest.d.ts +1 -1
  101. package/dist/plugins/diagnostics/index.d.ts +1 -1
  102. package/dist/plugins/diagnostics/index.js +1 -1
  103. package/dist/plugins/fileTools/config.d.ts +10 -0
  104. package/dist/plugins/{tools → fileTools}/editFiles.d.ts +16 -27
  105. package/dist/plugins/fileTools/gitDiscovery.d.ts +9 -0
  106. package/dist/plugins/fileTools/index.d.ts +18 -0
  107. package/dist/plugins/fileTools/index.js +1 -0
  108. package/dist/plugins/fileTools/tools.d.ts +6 -0
  109. package/dist/plugins/historyRecall/history.d.ts +1 -1
  110. package/dist/plugins/historyRecall/index.js +1 -1
  111. package/dist/plugins/historyRecall/render.d.ts +1 -1
  112. package/dist/plugins/mcp/catalog.d.ts +1 -1
  113. package/dist/plugins/mcp/index.d.ts +2 -2
  114. package/dist/plugins/mcp/index.js +1 -1
  115. package/dist/plugins/mcp/mount.d.ts +2 -2
  116. package/dist/plugins/mcp/render.d.ts +1 -1
  117. package/dist/plugins/mcp/{tool.d.ts → tools.d.ts} +1 -1
  118. package/dist/plugins/{routeContext.d.ts → routeNotice.d.ts} +2 -2
  119. package/dist/plugins/routeNotice.js +1 -0
  120. package/dist/{sandbox → plugins/sandbox}/absent.d.ts +11 -10
  121. package/dist/{sandbox → plugins/sandbox}/index.d.ts +5 -2
  122. package/dist/plugins/sandbox/index.js +4 -0
  123. package/dist/{sandbox → plugins/sandbox}/mode.d.ts +5 -5
  124. package/dist/plugins/sandbox/policy.d.ts +163 -0
  125. package/dist/{sandbox → plugins/sandbox}/service.d.ts +23 -13
  126. package/dist/plugins/schedules/index.js +3 -3
  127. package/dist/plugins/schedules/record.d.ts +18 -18
  128. package/dist/plugins/schedules/service.d.ts +2 -2
  129. package/dist/plugins/skills/discovery.d.ts +38 -9
  130. package/dist/plugins/skills/index.d.ts +1 -1
  131. package/dist/plugins/skills/index.js +1 -1
  132. package/dist/plugins/subAgents/index.js +1 -1
  133. package/dist/plugins/subAgents/{fork.d.ts → tools.d.ts} +36 -1
  134. package/dist/plugins/threadDirs.d.ts +36 -0
  135. package/dist/plugins/threadDirs.js +1 -0
  136. package/dist/plugins/toolPolicy/index.d.ts +2 -2
  137. package/dist/plugins/toolPolicy/index.js +1 -1
  138. package/dist/plugins/truncateToolOutput.d.ts +14 -10
  139. package/dist/plugins/truncateToolOutput.js +6 -1
  140. package/dist/plugins/usage/index.d.ts +4 -2
  141. package/dist/plugins/usage/index.js +1 -1
  142. package/dist/plugins/usage/tracker.d.ts +1 -1
  143. package/dist/plugins/verify/index.d.ts +7 -55
  144. package/dist/plugins/verify/index.js +6 -1
  145. package/dist/plugins/verify/judgement.d.ts +16 -0
  146. package/dist/plugins/verify/record.d.ts +382 -0
  147. package/dist/plugins/verify/service.d.ts +7 -4
  148. package/dist/plugins/verify/state.d.ts +58 -0
  149. package/dist/plugins/webTools/index.d.ts +34 -0
  150. package/dist/plugins/webTools/index.js +1 -0
  151. package/dist/plugins/workflows/assignment.d.ts +6 -2
  152. package/dist/plugins/workflows/cleanup.d.ts +1 -1
  153. package/dist/plugins/workflows/definition.d.ts +2 -2
  154. package/dist/plugins/workflows/{bindings.d.ts → entryPlan.d.ts} +2 -2
  155. package/dist/plugins/workflows/{providers.d.ts → hostBindings.d.ts} +2 -2
  156. package/dist/plugins/workflows/index.d.ts +4 -4
  157. package/dist/plugins/workflows/index.js +10 -5
  158. package/dist/plugins/workflows/observations.d.ts +3 -3
  159. package/dist/plugins/workflows/participantModels.d.ts +28 -0
  160. package/dist/plugins/workflows/participants.d.ts +2 -2
  161. package/dist/plugins/workflows/policy.d.ts +2 -2
  162. package/dist/plugins/workflows/record.d.ts +51 -65
  163. package/dist/plugins/workflows/routing.d.ts +2 -2
  164. package/dist/plugins/workflows/service.d.ts +24 -24
  165. package/dist/plugins/workflows/{fold.d.ts → state.d.ts} +2 -2
  166. package/dist/plugins/workflows/stopCheck.d.ts +13 -0
  167. package/dist/plugins/workflows/tools.d.ts +13 -0
  168. package/dist/plugins/workflows/view.d.ts +2 -2
  169. package/dist/plugins/{workspaceContext.d.ts → workspaceNotice.d.ts} +5 -7
  170. package/dist/plugins/workspaceNotice.js +1 -0
  171. package/dist/{plugins/providers → providers}/anthropic.d.ts +6 -3
  172. package/dist/{plugins/providers → providers}/anthropicMessages.d.ts +2 -1
  173. package/dist/{plugins/providers → providers}/codex.d.ts +14 -3
  174. package/dist/{plugins/providers → providers}/deepseek.d.ts +6 -2
  175. package/dist/{plugins/providers → providers}/failure.d.ts +1 -1
  176. package/dist/{plugins/providers → providers}/gateway.d.ts +2 -1
  177. package/dist/providers/index.d.ts +18 -0
  178. package/dist/providers/index.js +6 -0
  179. package/dist/{plugins/providers → providers}/openaiChat.d.ts +13 -2
  180. package/dist/{plugins/providers → providers}/openaiResponses.d.ts +12 -3
  181. package/dist/{plugins/providers → providers}/opencodeCopilot.d.ts +2 -2
  182. package/dist/{plugins/providers → providers}/opencodeGo.d.ts +18 -7
  183. package/dist/{plugins/providers → providers}/shared.d.ts +9 -1
  184. package/dist/{plugins/providers → providers}/stream.d.ts +4 -2
  185. package/dist/{models/door.d.ts → records/index.d.ts} +8 -7
  186. package/dist/records/index.js +1 -0
  187. package/dist/{models/wire → records}/journal.d.ts +210 -14
  188. package/dist/{models/wire/primitives.d.ts → records/toolResult.d.ts} +1 -1
  189. package/dist/services/agents.d.ts +26 -1
  190. package/dist/services/confinement/files.d.ts +118 -0
  191. package/dist/services/confinement/service.d.ts +219 -0
  192. package/dist/services/core.d.ts +2 -8
  193. package/dist/{kit/extension.d.ts → services/extensionEvents.d.ts} +5 -4
  194. package/dist/services/journal.d.ts +1 -1
  195. package/dist/services/llm.d.ts +4 -2
  196. package/dist/{kit → services}/modes.d.ts +1 -1
  197. package/dist/services/plugins.d.ts +34 -0
  198. package/dist/services/{preset.d.ts → presets/definition.d.ts} +4 -4
  199. package/dist/services/{presets.d.ts → presets/installations.d.ts} +3 -3
  200. package/dist/services/prompts.d.ts +23 -5
  201. package/dist/services/{threadActivation.d.ts → threads/activation.d.ts} +3 -3
  202. package/dist/services/{admission.d.ts → threads/admission.d.ts} +3 -3
  203. package/dist/services/{birth.d.ts → threads/birth.d.ts} +9 -10
  204. package/dist/services/threads/index.d.ts +14 -0
  205. package/dist/services/{runEvents.d.ts → threads/runEvents.d.ts} +2 -2
  206. package/dist/services/{owner.d.ts → threads/runOwner.d.ts} +5 -4
  207. package/dist/services/{threads.d.ts → threads/service.d.ts} +9 -8
  208. package/dist/services/{thread.d.ts → threads/thread.d.ts} +8 -7
  209. package/dist/services/{threadView.d.ts → threads/view.d.ts} +7 -6
  210. package/dist/services/tools.d.ts +79 -2
  211. package/dist/{loop/opening.d.ts → state/birth.d.ts} +22 -2
  212. package/dist/{loop → state}/chain.d.ts +3 -3
  213. package/dist/state/confirmations.d.ts +64 -0
  214. package/dist/{loop → state}/continuation.d.ts +3 -2
  215. package/dist/{loop → state}/decide.d.ts +10 -2
  216. package/dist/state/dispatches.d.ts +54 -0
  217. package/dist/state/errors.d.ts +26 -0
  218. package/dist/{loop → state}/forks.d.ts +1 -1
  219. package/dist/{loop → state}/holds.d.ts +1 -1
  220. package/dist/{loop → state}/inbox.d.ts +2 -2
  221. package/dist/state/index.d.ts +31 -0
  222. package/dist/state/inputs.d.ts +58 -0
  223. package/dist/state/installations.d.ts +28 -0
  224. package/dist/state/prompt.d.ts +13 -0
  225. package/dist/state/recovery.d.ts +7 -0
  226. package/dist/{loop → state}/replace.d.ts +2 -2
  227. package/dist/{loop → state}/requests.d.ts +3 -3
  228. package/dist/{loop → state}/route.d.ts +10 -2
  229. package/dist/state/summary.d.ts +16 -0
  230. package/dist/{loop → state}/surface.d.ts +3 -3
  231. package/dist/state/surfaceRead.d.ts +20 -0
  232. package/dist/{loop/threadState.d.ts → state/thread.d.ts} +12 -11
  233. package/dist/state/turns.d.ts +87 -0
  234. package/dist/state/waits.d.ts +38 -0
  235. package/dist/{loop → state}/wake.d.ts +1 -1
  236. package/dist/stores/durableObject.js +1 -0
  237. package/dist/{plugins/store → stores}/memory.d.ts +2 -2
  238. package/dist/{plugins/store → stores}/sql.d.ts +2 -2
  239. package/dist/stores/sqlite.js +1 -0
  240. package/dist/sys/environment.d.ts +0 -5
  241. package/dist/sys/git.d.ts +0 -13
  242. package/dist/sys/paths.d.ts +0 -47
  243. package/dist/sys/spawn.d.ts +16 -6
  244. package/dist/testing/clock.d.ts +1 -1
  245. package/dist/testing/fakeLlm.d.ts +4 -2
  246. package/dist/testing/fedLlm.d.ts +3 -1
  247. package/dist/testing/helpers.d.ts +31 -13
  248. package/dist/testing/index.js +1 -1
  249. package/dist/testing/settlement.d.ts +1 -1
  250. package/package.json +36 -28
  251. package/dist/chunks/2O7ZGEIT.js +0 -1
  252. package/dist/chunks/2OSESBIL.js +0 -1
  253. package/dist/chunks/3LQHQRIU.js +0 -6
  254. package/dist/chunks/3QCW4WDJ.js +0 -1
  255. package/dist/chunks/4XVRUSCQ.js +0 -1
  256. package/dist/chunks/6ECI2GGV.js +0 -1
  257. package/dist/chunks/74HKUGRR.js +0 -1
  258. package/dist/chunks/ADHERZLW.js +0 -2
  259. package/dist/chunks/D7E6EWIE.js +0 -3
  260. package/dist/chunks/DRYAN665.js +0 -1
  261. package/dist/chunks/DXFXAYDN.js +0 -17
  262. package/dist/chunks/EGZI4XQX.js +0 -24
  263. package/dist/chunks/ENWFSU27.js +0 -41
  264. package/dist/chunks/G6RXC3AL.js +0 -1
  265. package/dist/chunks/G74AGRAJ.js +0 -15
  266. package/dist/chunks/GQGNVSKB.js +0 -1
  267. package/dist/chunks/IJ2WNMD5.js +0 -7
  268. package/dist/chunks/JPZFKSWT.js +0 -1
  269. package/dist/chunks/KESCTXGO.js +0 -5
  270. package/dist/chunks/L3N4FIEN.js +0 -1
  271. package/dist/chunks/NAOUTU7A.js +0 -4
  272. package/dist/chunks/NDIM7MEW.js +0 -1
  273. package/dist/chunks/O4PPOM5Z.js +0 -2
  274. package/dist/chunks/OVZFGILJ.js +0 -1
  275. package/dist/chunks/P5ZHHOOM.js +0 -6
  276. package/dist/chunks/QMMLQJBS.js +0 -1
  277. package/dist/chunks/RK3VP2Q4.js +0 -3
  278. package/dist/chunks/SGGMBSBA.js +0 -1
  279. package/dist/chunks/TOOIB6J2.js +0 -1
  280. package/dist/chunks/TYTQRLTX.js +0 -1
  281. package/dist/chunks/UCTEU62F.js +0 -1
  282. package/dist/chunks/UD3VJER6.js +0 -1
  283. package/dist/chunks/WUUKTSRT.js +0 -7
  284. package/dist/chunks/X65X4KP5.js +0 -7
  285. package/dist/chunks/YIR5MYGU.js +0 -1
  286. package/dist/chunks/YLNJXQ3Z.js +0 -1
  287. package/dist/kit/claim.d.ts +0 -13
  288. package/dist/kit/drain.d.ts +0 -10
  289. package/dist/kit/grants.d.ts +0 -9
  290. package/dist/kit/scope.d.ts +0 -32
  291. package/dist/kit/service.d.ts +0 -7
  292. package/dist/kit/strategy.d.ts +0 -10
  293. package/dist/kit/tool.d.ts +0 -72
  294. package/dist/llm/door.d.ts +0 -21
  295. package/dist/llm/door.js +0 -1
  296. package/dist/loop/projections.d.ts +0 -307
  297. package/dist/loop/state.d.ts +0 -70
  298. package/dist/loop/summary.d.ts +0 -3
  299. package/dist/models/config/agent.d.ts +0 -18
  300. package/dist/models/config/prompt.d.ts +0 -18
  301. package/dist/models/door.js +0 -1
  302. package/dist/models/index.d.ts +0 -7
  303. package/dist/plugins/commands/foreground.d.ts +0 -4
  304. package/dist/plugins/compaction/preset.d.ts +0 -86
  305. package/dist/plugins/compaction/shared.d.ts +0 -14
  306. package/dist/plugins/delegations/testing.d.ts +0 -16
  307. package/dist/plugins/providers/door.d.ts +0 -61
  308. package/dist/plugins/providers/door.js +0 -1
  309. package/dist/plugins/providers/index.d.ts +0 -6
  310. package/dist/plugins/routeContext.js +0 -1
  311. package/dist/plugins/store/durableObject.js +0 -1
  312. package/dist/plugins/store/sqlite.js +0 -1
  313. package/dist/plugins/subAgents/tool.d.ts +0 -38
  314. package/dist/plugins/tools/index.d.ts +0 -59
  315. package/dist/plugins/tools/index.js +0 -1
  316. package/dist/plugins/verify/facts.d.ts +0 -356
  317. package/dist/plugins/workflows/submit.d.ts +0 -8
  318. package/dist/plugins/workspaceContext.js +0 -1
  319. package/dist/presets/agents.d.ts +0 -7
  320. package/dist/presets/base.d.ts +0 -10
  321. package/dist/presets/index.d.ts +0 -4
  322. package/dist/sandbox/index.js +0 -4
  323. package/dist/sandbox/policy.d.ts +0 -86
  324. package/dist/services/launches.d.ts +0 -104
  325. package/dist/services/threadDirs.d.ts +0 -38
  326. package/dist/testing/sandbox.d.ts +0 -71
  327. /package/dist/chunks/{UKXMCHHT.js → FJLU4UH3.js} +0 -0
  328. /package/dist/chunks/{J5S4URAW.js → HK6ZSONF.js} +0 -0
  329. /package/dist/plugins/ask/{askQuestion.d.ts → tools.d.ts} +0 -0
  330. /package/dist/plugins/delegations/{waits.d.ts → waitContracts.d.ts} +0 -0
  331. /package/dist/plugins/{tools → fileTools}/fsRead.d.ts +0 -0
  332. /package/dist/plugins/{tools → fileTools}/ripgrep.d.ts +0 -0
  333. /package/dist/plugins/{tools → fileTools}/textEdit.d.ts +0 -0
  334. /package/dist/{util → plugins/mcp}/version.d.ts +0 -0
  335. /package/dist/{sandbox → plugins/sandbox}/client.d.ts +0 -0
  336. /package/dist/{sandbox → plugins/sandbox}/files.d.ts +0 -0
  337. /package/dist/{sandbox → plugins/sandbox}/protocol.d.ts +0 -0
  338. /package/dist/{sandbox → plugins/sandbox}/worker.d.ts +0 -0
  339. /package/dist/{sandbox → plugins/sandbox}/worker.js +0 -0
  340. /package/dist/plugins/skills/{tool.d.ts → tools.d.ts} +0 -0
  341. /package/dist/plugins/{tools → webTools}/html.d.ts +0 -0
  342. /package/dist/plugins/{tools → webTools}/network.d.ts +0 -0
  343. /package/dist/plugins/{tools → webTools}/web.d.ts +0 -0
  344. /package/dist/plugins/workflows/{work.d.ts → workStatus.d.ts} +0 -0
  345. /package/dist/{plugins/providers → providers}/codexAuth.d.ts +0 -0
  346. /package/dist/services/{contributions.d.ts → catalogContributions.d.ts} +0 -0
  347. /package/dist/{loop → state}/limits.d.ts +0 -0
  348. /package/dist/{plugins/store → stores}/durableObject.d.ts +0 -0
  349. /package/dist/{plugins/store → stores}/durableObjectConnection.d.ts +0 -0
  350. /package/dist/{plugins/store → stores}/sqlite.d.ts +0 -0
  351. /package/dist/{models → util}/jsonSchema.d.ts +0 -0
  352. /package/dist/{kit → util}/retries.d.ts +0 -0
  353. /package/dist/{kit → util}/timers.d.ts +0 -0
@@ -1,5 +1,5 @@
1
1
  import type { CoreFold } from '../journal/index.js';
2
- import type { JournalEvent } from '../models/index.js';
2
+ import type { JournalEvent } from '../records/journal.js';
3
3
  /**
4
4
  * One concern of a thread's state: where it starts, and what a row does to it. `apply` may mutate
5
5
  * `state` and return it, or return a fresh value; it never reads another concern.
@@ -14,16 +14,17 @@ declare const REDUCERS: {
14
14
  readonly turnBoundary: Reducer<{
15
15
  lastTurn: number;
16
16
  step: number;
17
- lastReason: import("../models/index.js").TurnEndReason | null;
17
+ lastReason: import("../records/journal.js").TurnEndReason | null;
18
18
  turnOpen: boolean;
19
19
  concludedTurn: number | null;
20
20
  }>;
21
- readonly answerCheck: Reducer<import("./projections.js").AnswerCheck>;
21
+ readonly answerCheck: Reducer<import("./turns.js").AnswerCheck>;
22
22
  readonly dispatchedCalls: Reducer<Map<string, number>>;
23
- readonly dispatchAttempts: Reducer<Map<string, import("./projections.js").DispatchAttempt>>;
24
- readonly waits: Reducer<Map<number, import("./projections.js").WaitEntry>>;
25
- readonly confirmations: Reducer<Map<string, import("./projections.js").ConfirmationState>>;
26
- readonly threadRecord: Reducer<import("./projections.js").ThreadRecord | null>;
23
+ readonly dispatchAttempts: Reducer<Map<string, import("./dispatches.js").DispatchAttempt>>;
24
+ readonly waits: Reducer<Map<number, import("./waits.js").WaitEntry>>;
25
+ readonly confirmations: Reducer<Map<string, import("./confirmations.js").ConfirmationState>>;
26
+ readonly executions: Reducer<Map<number, import("./confirmations.js").RuntimeExecution>>;
27
+ readonly threadRecord: Reducer<import("./birth.js").ThreadRecord | null>;
27
28
  readonly threadRoute: Reducer<{
28
29
  provider: string;
29
30
  model: string;
@@ -40,12 +41,12 @@ declare const REDUCERS: {
40
41
  description: string;
41
42
  }[] | null>;
42
43
  readonly forkTask: Reducer<{
43
- spawnSeq: import("../models/index.js").Seq | null;
44
+ spawnSeq: import("../records/journal.js").Seq | null;
44
45
  unclaimed: boolean;
45
46
  }>;
46
- readonly inbox: Reducer<import("./projections.js").InboxState>;
47
- readonly inputs: Reducer<Map<string, import("./projections.js").InputRows>>;
48
- readonly installations: Reducer<import("./projections.js").InstallationsState>;
47
+ readonly inbox: Reducer<import("./inputs.js").InboxState>;
48
+ readonly inputs: Reducer<Map<string, import("./inputs.js").InputRows>>;
49
+ readonly installations: Reducer<import("./installations.js").InstallationsState>;
49
50
  readonly lastAnswer: Reducer<number | null>;
50
51
  readonly requests: Reducer<import("./requests.js").RequestsState>;
51
52
  readonly chain: Reducer<import("./chain.js").ChainState>;
@@ -0,0 +1,87 @@
1
+ import type { Seq, TurnEndReason } from '../records/journal.js';
2
+ import { type ResponseFinish } from '../llm/primitives.js';
3
+ import type { Journal } from '../journal/index.js';
4
+ import type { Reducer } from './thread.js';
5
+ /**
6
+ * Where a thread is in its turns: the highest one opened, how many steps it has taken, how it ended,
7
+ * and whether a tool asked it to stop.
8
+ *
9
+ * `step` counts `step/start` since the last `turn/start`, so it is only meaningful while that turn
10
+ * is in flight — a finished turn's count says nothing about the next one. It is folded rather than
11
+ * counted in memory so the loop's decision stays a function of the journal across a restart.
12
+ * `turnOpen` holds while a turn is in flight — including one whose process died, which the thread
13
+ * closes as `interrupted` before it opens another.
14
+ *
15
+ * A fork continues the turn numbering and inherits `concludedTurn`, so a fork taken after a
16
+ * concluding result is not owed a reply either. Everything else here describes the source's
17
+ * execution and resets: a fork has no turn in flight and no outcome of its own, even when it was cut
18
+ * inside one of its source's turns.
19
+ */
20
+ export declare const turnBoundary: Reducer<{
21
+ lastTurn: number;
22
+ step: number;
23
+ /** How this thread's own last turn ended; `null` before its first ends, or while one is open. */
24
+ lastReason: TurnEndReason | null;
25
+ turnOpen: boolean;
26
+ /**
27
+ * The turn in which a tool result asked for the turn to end, until input arrives. Holds across
28
+ * the turn boundary: the concluding result is not a reply the model owes, so nothing happens until
29
+ * someone sends something new — but only the turn it landed in is cut short by it.
30
+ */
31
+ concludedTurn: number | null;
32
+ }>;
33
+ /** Whether a thread's latest answer has been judged by its stop checks. */
34
+ export type AnswerCheck = {
35
+ status: 'none';
36
+ } | ({
37
+ status: 'pending' | 'accepted' | 'rejected';
38
+ seq: Seq;
39
+ text: string;
40
+ } & ({
41
+ kind: 'reply';
42
+ finish: ResponseFinish;
43
+ } | {
44
+ kind: 'concluded';
45
+ }));
46
+ /**
47
+ * The conversation's latest answer — a reply with no tool calls, or a result that concluded the
48
+ * turn — and whether a stop check has judged it.
49
+ *
50
+ * An answer is `pending` from the moment it is recorded until its turn ends `completed` (accepted)
51
+ * or `rejected`. Every other ending leaves it pending, so a check a crash, an abort or a failing
52
+ * listener cut short is still owed; new input supersedes the answer altogether. Folded from rows
53
+ * the loop writes anyway, so there is no marker for a crash to fall in front of.
54
+ *
55
+ * A fork resets it (see `threadState`'s fork table); a fork is never cut where a check is still owed,
56
+ * so nothing is lost.
57
+ */
58
+ export declare const answerCheck: Reducer<AnswerCheck>;
59
+ /**
60
+ * How the run that began after a row ended, and what it answered, read from the thread's events
61
+ * after that row. A run's outcome, not a delegation task's: an `aborted` turn ends a run, while a
62
+ * task stays open across it (the delegations plugin's own fold).
63
+ */
64
+ export type RunOutcome = {
65
+ /** The last turn ending seen for this run, if any. */
66
+ reason: TurnEndReason | null;
67
+ /**
68
+ * The accepted answer: the reply, or the output of the tool result that concluded the turn. Empty
69
+ * until the run has answered — a provisional or rejected answer is not one.
70
+ */
71
+ output: string;
72
+ /** Whether the conversation has reached an answer: a complete reply, or a result that concluded the turn. */
73
+ answered: boolean;
74
+ };
75
+ /**
76
+ * How the run that began after `fromSeq` ended, and what it answered.
77
+ *
78
+ * The `answerCheck` reducer folded over the rows after `fromSeq`: the same rule the loop and its stop
79
+ * checks read, so an answer is a complete reply with nothing left to call, or a tool result that
80
+ * concluded the turn, and it becomes the run's answer only at the `turn/end(completed)` that
81
+ * accepted it. A process that died before that ending leaves it unaccepted, and the scan goes on to
82
+ * the turn that checks it. Scanning stops at the first turn ending that settles the run, answered or
83
+ * failed outright, so a later turn of the same thread is never mistaken for this run's.
84
+ */
85
+ export declare function outcomeSince(journal: Journal, threadId: string, fromSeq: Seq): RunOutcome;
86
+ /** A turn ending after which the run will not produce an answer without new input. */
87
+ export declare const isRunFailure: (reason: TurnEndReason | null) => boolean;
@@ -0,0 +1,38 @@
1
+ import type { Seq } from '../records/journal.js';
2
+ import type { ReadonlyJsonValue } from '../util/json.js';
3
+ import type { Reducer } from './thread.js';
4
+ /** A call's `wait/declared` row, as the waits fold keeps it. */
5
+ export type WaitDeclaration = {
6
+ /** The `wait/declared` row. */
7
+ readonly seq: Seq;
8
+ readonly turn: number;
9
+ readonly step: number;
10
+ readonly call_id: string;
11
+ readonly call_seq: Seq;
12
+ readonly owner: string;
13
+ readonly dependency: {
14
+ readonly [key: string]: ReadonlyJsonValue;
15
+ };
16
+ readonly deadline_at: number | null;
17
+ readonly reason: string;
18
+ };
19
+ /** One declared wait: its declaration, the value it resolved with, and whether its call was answered. */
20
+ export type WaitEntry = {
21
+ readonly declaration: WaitDeclaration;
22
+ value: {
23
+ readonly [key: string]: ReadonlyJsonValue;
24
+ } | null;
25
+ /** The call's `tool/result` landed: by its dispatch from the value, or by a cancel. */
26
+ answered: boolean;
27
+ };
28
+ /**
29
+ * Every wait the thread declared, by `call_seq`, kept after its call is answered, so answer-once can
30
+ * report a value recorded before. A fork starts with none: it is never cut with a call unanswered.
31
+ */
32
+ export declare const waits: Reducer<Map<Seq, WaitEntry>>;
33
+ /** Declared, with no value and no answer: what holds the thread, and what its owner still resolves. */
34
+ export declare const isUnresolved: (entry: WaitEntry | undefined) => boolean;
35
+ /** Declared and unanswered, resolved or not: the waiting call's authority, which a cancel answers. */
36
+ export declare const isSuspended: (entry: WaitEntry | undefined) => boolean;
37
+ /** The thread's suspended waits, in declaration order. */
38
+ export declare const suspendedWaits: (state: ReadonlyMap<Seq, WaitEntry>) => WaitEntry[];
@@ -1,5 +1,5 @@
1
1
  import type { AppendEntry } from '../journal/index.js';
2
- import type { RunChain } from '../models/index.js';
2
+ import type { RunChain } from '../records/journal.js';
3
3
  import type { PendingRun } from './requests.js';
4
4
  import { type RouteAuthority, type RouteStatement } from './route.js';
5
5
  /**
@@ -0,0 +1 @@
1
+ import{a as c}from"../chunks/JCTBX33H.js";import{l as i}from"../chunks/BBCW2FZK.js";import"../chunks/MMNNZCBO.js";import"../chunks/G44LG6VL.js";import"../chunks/D4PQP5MA.js";function o(e){return{exec:t=>{e.sql.exec(t).toArray()},run:(t,...r)=>{e.sql.exec(t,...r).toArray()},all:(t,...r)=>e.sql.exec(t,...r).toArray(),transaction:async t=>{let r=e.transactionSync(t);return await e.sync(),r},close:()=>{}}}var n=new WeakMap;function s(e,t){if(n.has(e))throw new i(t);let r={};return n.set(e,r),{identity:t,release:()=>{n.get(e)===r&&n.delete(e)}}}var l=class extends c{storage;identity;constructor(t,r){super(r.identity),this.storage=t,this.identity=r.identity}connect(){return o(this.storage)}async exclusive(){return s(this.storage,this.identity)}};export{l as DurableObjectJournalStore};
@@ -1,5 +1,5 @@
1
- import type { JournalEvent, Seq, ThreadSummary } from '../../models/index.js';
2
- import { JournalStore, type AppendOutcome, type Attempt, type ThreadIndexEntry, type WriterLease } from '../../journal/index.js';
1
+ import type { JournalEvent, Seq, ThreadSummary } from '../records/journal.js';
2
+ import { JournalStore, type AppendOutcome, type Attempt, type ThreadIndexEntry, type WriterLease } from '../journal/index.js';
3
3
  /**
4
4
  * In-memory backing, keeping serialized rows so it exercises the same round trip as SQLite. Its
5
5
  * writer lease is exclusive within the process, which is as far as its rows reach.
@@ -1,5 +1,5 @@
1
- import type { JournalEvent, Seq, ThreadSummary } from '../../models/index.js';
2
- import { JournalStore, type AppendOutcome, type Attempt, type ThreadIndexEntry, type WriterLease } from '../../journal/index.js';
1
+ import type { JournalEvent, Seq, ThreadSummary } from '../records/journal.js';
2
+ import { JournalStore, type AppendOutcome, type Attempt, type ThreadIndexEntry, type WriterLease } from '../journal/index.js';
3
3
  export type SqlValue = string | number | null;
4
4
  /** A synchronous SQLite connection: what the two stores differ in, except exclusivity. */
5
5
  export type SqlConnection = {
@@ -0,0 +1 @@
1
+ import{a as m}from"../chunks/JCTBX33H.js";import{l as u,m as h}from"../chunks/BBCW2FZK.js";import"../chunks/MMNNZCBO.js";import"../chunks/G44LG6VL.js";import"../chunks/D4PQP5MA.js";import{closeSync as d,mkdirSync as c,openSync as w,realpathSync as f,statSync as p}from"node:fs";import{isAbsolute as M,join as n}from"node:path";import{DatabaseSync as y}from"node:sqlite";var b=class extends m{lockDirectory;busyTimeoutMs;directory;constructor(t,e){super(n(t,"journal.db")),this.directory=t;let{lockDirectory:r,busyTimeoutMs:s}=e;if(!M(r))throw new TypeError(`lockDirectory must be an absolute path: ${r}`);if(!Number.isFinite(s)||s<0)throw new TypeError(`busyTimeoutMs must be a finite number of milliseconds, zero or more: ${s}`);this.lockDirectory=r,this.busyTimeoutMs=s}get databasePath(){return n(this.directory,"journal.db")}connect(){return c(this.directory,{recursive:!0}),new a(this.databasePath,this.busyTimeoutMs)}async exclusive(){c(this.directory,{recursive:!0}),d(w(this.databasePath,"a",384));let t=f(this.databasePath),{dev:e,ino:r}=p(t,{bigint:!0});c(this.lockDirectory,{recursive:!0,mode:448});let s=new y(n(this.lockDirectory,`${e}-${r}.db`));try{s.exec("PRAGMA busy_timeout=0; BEGIN EXCLUSIVE")}catch(i){throw s.close(),l(i)?new u(t):i}return{identity:`sqlite:${e}:${r}`,release:()=>s.close()}}},a=class{db;path;busyTimeoutMs;statements=new Map;writes=Promise.resolve();constructor(t,e){this.path=t,this.busyTimeoutMs=e,this.db=new y(t);try{this.db.exec("PRAGMA journal_mode=WAL")}catch(r){throw this.db.close(),r}}exec(t){this.db.exec(t)}run(t,...e){this.statement(t).run(...e)}all(t,...e){return this.statement(t).all(...e)}transaction(t){let e=()=>this.write(t),r=this.writes.then(e,e);return this.writes=r.catch(()=>{}),r}close(){this.statements.clear(),this.db.close()}statement(t){let e=this.statements.get(t);return e===void 0&&(e=this.db.prepare(t),this.statements.set(t,e)),e}async write(t){await this.beginWrite();try{let e=t();return this.db.exec("COMMIT"),e}catch(e){throw this.rollback(),e}}async beginWrite(){let t=Date.now();for(let e=5;;e=Math.min(e*2,100))try{this.db.exec("BEGIN IMMEDIATE");return}catch(r){if(!l(r))throw r;let s=Date.now()-t;if(s>=this.busyTimeoutMs)throw new h(this.path,s);await new Promise(i=>setTimeout(i,Math.min(e,this.busyTimeoutMs-s)))}}rollback(){if(this.db.isTransaction)try{this.db.exec("ROLLBACK")}catch(t){console.error(t)}}},l=o=>{let t=o?.errcode;return typeof t=="number"&&(t&255)===5};export{b as SqliteJournalStore};
@@ -22,11 +22,6 @@ export type SpawnEnvironmentPolicy = {
22
22
  /** Set over what remains. */
23
23
  readonly set: Readonly<Record<string, string>>;
24
24
  };
25
- /**
26
- * Codex's policy: variables that look like credentials are dropped, the locale is fixed to UTF-8,
27
- * and the {@link NON_INTERACTIVE_ENVIRONMENT} overrides are set.
28
- */
29
- export declare const CODEX_ENVIRONMENT_POLICY: SpawnEnvironmentPolicy;
30
25
  /** `source` filtered and overridden by `policy`: the whole environment a spawned process gets. */
31
26
  export declare function buildSpawnEnvironment(source: Readonly<Record<string, string | undefined>>, policy: SpawnEnvironmentPolicy): Record<string, string>;
32
27
  /**
package/dist/sys/git.d.ts CHANGED
@@ -31,19 +31,6 @@ export type RepositoryLocation = {
31
31
  * repository. `null` outside every repository.
32
32
  */
33
33
  export declare function findRepository(path: string): RepositoryLocation | null;
34
- /**
35
- * Read roots for a thread working in `cwd`: the top of the git repository holding it, when that is
36
- * above it, so the file tools reach the code around a package and every `AGENTS.md` from the
37
- * repository root down; none outside a repository, nor at its top. Never more than the repository: a
38
- * sibling checkout stays out of reach. A host's choice to record when it creates a thread; lagent
39
- * applies it nowhere itself.
40
- */
41
- export declare function repositoryReadRoots(cwd: string): string[];
42
- /**
43
- * `path` with its symbolic links resolved, the part that does not exist yet kept as named; the
44
- * lexical path when it cannot be resolved, such as behind a directory that may not be listed.
45
- */
46
- export declare function physical(path: string): string;
47
34
  /** What a repository's `HEAD` names: a branch, or a commit it is detached at. */
48
35
  export type GitHead = {
49
36
  readonly kind: 'branch';
@@ -1,50 +1,3 @@
1
- import type { InvocationContext } from '../loop/index.js';
2
- import type { ThreadEnvironment } from '../models/index.js';
3
- import type { DeepReadonly } from '../util/json.js';
4
- /**
5
- * What a file tool does with a path. `write` is for anything that can modify what the path reaches.
6
- */
7
- export type PathAccess = 'read' | 'write';
8
- /**
9
- * Where one call of a tool may reach: the thread's workspace and the application's data directory,
10
- * and for a read also the read roots its environment names.
11
- *
12
- * Every comparison is made between real locations: the roots and each path checked against them
13
- * have their symlinks resolved first, so a link inside a root cannot carry a read or a write
14
- * outside it. A path that does not exist yet, such as a file about to be created, is located
15
- * through its nearest existing ancestor, and a dangling link through its target.
16
- */
17
- export type PathBoundary = {
18
- /** The thread's working directory, which relative paths are resolved against. */
19
- readonly cwd: string;
20
- /**
21
- * `pathValue` resolved against the cwd: the path a tool then opens, without its symlinks
22
- * resolved, so results name what the model named. Throws when its real location is outside
23
- * every root.
24
- */
25
- resolve(pathValue: string): string;
26
- /** Whether the real location of an absolute path is inside a root: for the entries a walk finds. */
27
- contains(path: string): Promise<boolean>;
28
- /** `contains` for a caller that cannot await, such as a step listener; tools use `contains`. */
29
- containsSync(path: string): boolean;
30
- };
31
- /**
32
- * What a boundary is drawn from: a tool call's context, or the same facts about a thread for a
33
- * plugin that reads on the thread's behalf, as `agentsMd` does.
34
- */
35
- export type BoundaryScope = Pick<InvocationContext, 'ctx'> & {
36
- readonly environment: DeepReadonly<ThreadEnvironment>;
37
- };
38
- export declare function pathBoundary(context: BoundaryScope, access: PathAccess): PathBoundary;
39
- /**
40
- * Where an absolute path really is: its symlinks resolved, for a path that exists. For one that
41
- * does not, its nearest existing ancestor's real location with the rest appended, following a
42
- * dangling link to its target, since opening it to write would create that target. What the
43
- * boundary compares, and what a tool that must tell two names of one file apart compares too.
44
- */
45
- export declare function realLocation(path: string): string;
46
- /** `realLocation` without blocking the event loop, for a walk that checks every entry it finds. */
47
- export declare function realLocationAsync(path: string): Promise<string>;
48
1
  /** Whether `candidate` is `root` or a path inside it, by whole segments: `/a/bc` is not inside `/a/b`. Both normalized. */
49
2
  export declare const isWithin: (candidate: string, root: string) => boolean;
50
3
  /** A path as results show it: relative to the cwd inside it, absolute outside it. */
@@ -16,6 +16,14 @@ import type { Readable, Writable } from 'node:stream';
16
16
  */
17
17
  /** How long SIGTERM gets before SIGKILL, and SIGKILL before a stop is reported failed. */
18
18
  export declare const DEFAULT_KILL_GRACE_MS = 3000;
19
+ /** A command never passed its startup gate; a wrapper group may still need cleanup. */
20
+ export declare class CommandStartFailure extends Error {
21
+ readonly stopFailed: boolean;
22
+ readonly code: string | undefined;
23
+ constructor(cause: unknown, cleanup: {
24
+ readonly stopFailed: boolean;
25
+ });
26
+ }
19
27
  /**
20
28
  * A process's whole environment; an `undefined` value leaves the variable unset. lagent never
21
29
  * builds one from its own: a host does (`sys/environment`), and every spawn passes one.
@@ -100,6 +108,8 @@ export interface SpawnedPipes extends SpawnedGroup {
100
108
  * Spawns a command in a process group of its own. Resolves once the group is registered,
101
109
  * `beforeRelease` has settled and the command released; rejects, having run nothing, when it cannot
102
110
  * be spawned or registered, when `beforeRelease` rejects, or when `signal` aborts first.
111
+ * Each rejection owns a `CommandStartFailure` recording cleanup of its gated wrapper, with the
112
+ * original failure as its cause.
103
113
  */
104
114
  export declare function spawnCommand(options: SpawnOptions & {
105
115
  stdio?: 'joined';
@@ -117,7 +127,7 @@ export declare function runToCompletion(options: SpawnOptions & {
117
127
  }): Promise<SpawnResult & {
118
128
  output: string;
119
129
  }>;
120
- /** How {@link runLines} hands a command's stdout over. */
130
+ /** How {@link readLines} hands a command's stdout over. */
121
131
  export type LineReader = {
122
132
  /**
123
133
  * Called with each line of stdout, without its delimiter, as it arrives. Returning `false` stops the
@@ -133,12 +143,12 @@ export type LineReader = {
133
143
  maxLineChars: number;
134
144
  };
135
145
  /**
136
- * Runs a command and hands its stdout to `onLine` line by line, holding at most one line: for
137
- * output whose size is not bounded, such as a search's, where the caller stops the command once it
138
- * has what it needs. The command gets no input. stderr is read separately and kept as a bounded
139
- * tail, for diagnostics.
146
+ * Hands a spawned command's stdout to `onLine` line by line, holding at most one line, and waits for
147
+ * the command to end: for output whose size is not bounded, such as a search's, where the caller
148
+ * stops the command once it has what it needs. The command gets no input. stderr is read separately
149
+ * and kept as a bounded tail, for diagnostics.
140
150
  */
141
- export declare function runLines(options: Omit<SpawnOptions, 'stdio' | 'beforeRelease'> & LineReader): Promise<SpawnResult & {
151
+ export declare function readLines(command: SpawnedPipes, reader: LineReader): Promise<SpawnResult & {
142
152
  stderr: string;
143
153
  }>;
144
154
  /** Whether any process remains in the group; a zombie still counts. */
@@ -1,4 +1,4 @@
1
- import type { Clock } from '../kit/timers.js';
1
+ import type { Clock } from '../util/timers.js';
2
2
  /**
3
3
  * A {@link Clock} a test moves by hand. Wall time and elapsed time move apart: `advance` moves
4
4
  * both, as time passing does; `jump` sets the wall clock forward or back without any timer
@@ -1,6 +1,8 @@
1
1
  import type { z } from 'zod';
2
- import type { ConversationMessage, LLMClient, LLMStreamChunk, MalformedToolCall, ModelRequest, ModelResponse, ResponseFinish, StreamingLLMResponse } from '../llm/index.js';
3
- import { LLMStreamChunkSchema } from '../llm/index.js';
2
+ import type { ConversationMessage, LLMStreamChunk, MalformedToolCall, ModelResponse, ResponseFinish } from '../llm/primitives.js';
3
+ import type { LLMClient, StreamingLLMResponse } from '../llm/client.js';
4
+ import type { ModelRequest } from '../llm/request.js';
5
+ import { LLMStreamChunkSchema } from '../llm/primitives.js';
4
6
  /** A chunk as a test writes one: anything the schema defaults may be left out. */
5
7
  export type FakeChunk = z.input<typeof LLMStreamChunkSchema>;
6
8
  /** Every request the fake was handed, exactly as the loop built it. */
@@ -1,4 +1,6 @@
1
- import type { ConversationMessage, LLMClient, ModelRequest, StreamingLLMResponse } from '../llm/index.js';
1
+ import type { ConversationMessage } from '../llm/primitives.js';
2
+ import type { LLMClient, StreamingLLMResponse } from '../llm/client.js';
3
+ import type { ModelRequest } from '../llm/request.js';
2
4
  import { type FakeChunk } from './fakeLlm.js';
3
5
  /** One model call whose stream the test feeds: `push` chunks, then `finish` or `fail`. */
4
6
  export declare class FedCall {
@@ -1,19 +1,27 @@
1
1
  import { Context, type Plugin } from '@leuduan/cordis';
2
2
  import { Journal, type CoreFold, type JournalStore, type PluginJournal, type Summarizer } from '../journal/index.js';
3
- import type { ConfirmationState, InvocationContext, RouteStatement, ResolvedWait, RowRef, SendOutcome, Tool, TurnLimits } from '../loop/index.js';
4
- import type { ConversationMessage, FailureClassification, LLMClient, ModelCapacity, ModelRequest, ModelRoute, PromptBlock, ThinkingEffort } from '../llm/index.js';
3
+ import type { ConfirmationState, RouteStatement, RowRef, SendOutcome, TurnLimits } from '../state/index.js';
4
+ import type { InvocationContext, ResolvedWait, Tool } from '../loop/index.js';
5
+ import type { ConversationMessage, ThinkingEffort } from '../llm/primitives.js';
6
+ import type { FailureClassification } from '../llm/failure.js';
7
+ import type { LLMClient, ModelCapacity } from '../llm/client.js';
8
+ import type { ModelRequest } from '../llm/request.js';
9
+ import type { ModelRoute } from '../llm/provider.js';
10
+ import type { PromptBlock } from '../llm/prompt.js';
5
11
  import type { DeepReadonly, ReadonlyJsonValue } from '../util/json.js';
6
- import type { AgentDefinitionInput, ExtensionRecord, JournalEvent, Seq, ThreadOrigin, ThreadSummary, TurnEndReason } from '../models/index.js';
12
+ import type { AgentDefinitionInput } from '../loop/index.js';
13
+ import type { ExtensionRecord, JournalEvent, Seq, ThreadOrigin, ThreadSummary, TurnEndReason } from '../records/journal.js';
7
14
  import { type TrustedPrograms } from '../sys/environment.js';
8
- import { MemoryJournalStore } from '../plugins/store/memory.js';
15
+ import type { ConfinementService, Launched, LaunchOptions, LaunchRequest } from '../services/confinement/service.js';
16
+ import { MemoryJournalStore } from '../stores/memory.js';
9
17
  import { type PromptContribution } from '../services/prompts.js';
10
18
  import { type RetryPolicy } from '../services/llm.js';
11
- import type { Thread } from '../services/thread.js';
12
- import type { BirthInput, CreateThreadOptions, Opening } from '../services/birth.js';
13
- import type { InitialInstallationInput } from '../services/presets.js';
14
- import type { OwnerHandle, StartOptions } from '../services/owner.js';
19
+ import type { Thread } from '../services/threads/index.js';
20
+ import type { BirthInput, CreateThreadOptions, Opening } from '../services/threads/index.js';
21
+ import type { InitialInstallationInput } from '../services/presets/installations.js';
22
+ import type { OwnerHandle, StartOptions } from '../services/threads/index.js';
15
23
  import type { DelegationsConfig } from '../plugins/delegations/service.js';
16
- import type { ThreadView } from '../services/threadView.js';
24
+ import type { ThreadView } from '../services/threads/index.js';
17
25
  import { ownedTmpDir, tmpWorkspace } from './tmpDirs.js';
18
26
  /**
19
27
  * A provider plugin that hands out one fixed client, for tests and embedding. Like the real ones,
@@ -36,7 +44,10 @@ export type TestRootOptions = {
36
44
  /** Start from an existing journal, as reopening does. */
37
45
  store?: JournalStore;
38
46
  cwd?: string;
39
- /** Where thread directories live; a temporary directory, removed with the root, when omitted; `null` for none. */
47
+ /**
48
+ * Where `threadDirs` keeps thread directories: a temporary directory, removed with the
49
+ * root, when omitted; `null` mounts no thread directories, as on a host with no file system.
50
+ */
40
51
  dataDir?: string | null;
41
52
  limits?: Partial<TurnLimits>;
42
53
  /** Agents to register, each granted its `tools`; one `main_agent` that can read files when omitted. */
@@ -122,7 +133,7 @@ export declare function createTestRoot(options: TestRootOptions): Promise<TestRo
122
133
  export declare const testEnvironment: () => Record<string, string>;
123
134
  /** The trusted programs tests run, found on this process's `PATH`. */
124
135
  export declare const testPrograms: () => TrustedPrograms;
125
- /** Minimal file reader so loop tests can exercise the tool path without the builtin tools. */
136
+ /** Minimal file reader so loop tests can exercise the tool path without the file tools. */
126
137
  export declare const testReadFileTool: Tool;
127
138
  export type TestToolEntry = {
128
139
  name: string;
@@ -217,8 +228,6 @@ export declare function testInvocationContext(root: Context, options?: {
217
228
  callId?: string;
218
229
  callSeq?: number;
219
230
  cwd?: string;
220
- /** The thread's read roots; none when omitted. */
221
- readRoots?: string[];
222
231
  /** The turn's route; the fake provider's when omitted. */
223
232
  route?: ModelRoute;
224
233
  /** The resolved wait of a dispatch again; none when omitted. */
@@ -342,3 +351,12 @@ export declare function assignmentOrigin(root: Context, callerId: string, owner:
342
351
  export declare const testAgentPlugin: (agent: AgentDefinitionInput) => Plugin.Object<undefined>;
343
352
  /** Mounts one prompt contribution as a plugin, for tests that need it with a fiber of its own. */
344
353
  export declare const testPromptPlugin: (contribution: PromptContribution) => Plugin.Object<undefined>;
354
+ /** One shell launch for `request.threadId` as its own operation: a snapshot, then the launch under it. */
355
+ export declare function launchOnce(service: ConfinementService, { threadId, ...request }: LaunchRequest & {
356
+ threadId: string;
357
+ program: {
358
+ shell: string;
359
+ };
360
+ }, options: LaunchOptions): Promise<Launched>;
361
+ /** Makes every launch through `confinement` report that its stop could not be confirmed, as a launcher that cannot confirm the group ended. */
362
+ export declare function failStops(confinement: ConfinementService): void;
@@ -1 +1 @@
1
- import{a as C,c as j,d as m}from"../chunks/2O7ZGEIT.js";import"../chunks/4XVRUSCQ.js";import{a as N}from"../chunks/OVZFGILJ.js";import{c as M,d as D}from"../chunks/UD3VJER6.js";import{b as R,c as B}from"../chunks/SGGMBSBA.js";import"../chunks/3QCW4WDJ.js";import{b as J}from"../chunks/J5S4URAW.js";import{c as F,d as W,f as $}from"../chunks/JPZFKSWT.js";import{b as I}from"../chunks/RK3VP2Q4.js";import{b as A}from"../chunks/74HKUGRR.js";import"../chunks/YIR5MYGU.js";import"../chunks/L3N4FIEN.js";import{a as z}from"../chunks/NAOUTU7A.js";import"../chunks/UKXMCHHT.js";import{a as v}from"../chunks/NDIM7MEW.js";import"../chunks/34KW6VNQ.js";import{a as L}from"../chunks/G6RXC3AL.js";import"../chunks/GQGNVSKB.js";import"../chunks/DXFXAYDN.js";import"../chunks/2OSESBIL.js";import{F as S,S as b,ha as P,o as E}from"../chunks/YLNJXQ3Z.js";import{f as O}from"../chunks/DDANMY45.js";import{w as q}from"../chunks/37YOGDGY.js";import"../chunks/KESCTXGO.js";import"../chunks/TYTQRLTX.js";import{t as T,v as p,w}from"../chunks/D7E6EWIE.js";var u=class{claimed=!1;ledger=new v;failure;chunks;settled;options;constructor(e,r,n={}){this.chunks=e,this.settled=r,this.options=n}[Symbol.asyncIterator](){if(this.claimed)throw new Error("A response is read once: it has been claimed already");this.claimed=!0;let e=this.read();return{next:()=>this.ledger.operation(()=>e.next()),return:r=>this.ledger.operation(()=>e.return(r),!0),throw:r=>this.ledger.operation(()=>e.throw(r),!0)}}async*read(){try{for await(let r of this.chunks)yield T.parse(r);let e=this.options.readFailure===!0?this.settlement():void 0;if(e instanceof Error)throw e}catch(e){throw this.failure={error:e},e}finally{this.ledger.finish()}}settlement(){return typeof this.settled=="function"?this.settled():this.settled}async completed(){if(this.claimed){if(!this.ledger.ended)throw new Error("A response is settled before its read or after it, not while the read is under way")}else for await(let r of this);if(this.failure!==void 0)throw this.failure.error;let e=this.settlement();if(e instanceof Error)throw e;return"finish"in e?e:{message:e,finish:this.options.finish??"completed",provider_metadata:{}}}},g=class t{providerName="fake";requests=[];handler;constructor(e){this.handler=e}static scripted(...e){let r=0;return new t(()=>{let n=e[r];if(n===void 0)throw new Error(`Unexpected LLM call #${r+1}`);return r+=1,n})}async chat(e){if(this.requests.push(e),e.signal?.aborted)throw e.signal.reason instanceof Error?e.signal.reason:new Error("aborted");let r=await this.handler(e.messages,e);return"failure"in r?new u(r.chunks,r.failure):"chunks"in r?new u(r.chunks,r.message):new u([],r)}},ie=(t,e={})=>p({role:"assistant",content:t,...e}),le=(t,e=null)=>p({role:"assistant",content:e,tool_calls:t.map(r=>r.arguments===void 0?{...r,arguments:{}}:r)});var y=class{request;queue=[];ended=null;text="";wake=null;constructor(e){this.request=e,e.signal?.addEventListener("abort",()=>{this.ended??={cutOff:!0},this.wake?.()},{once:!0})}push(e){this.queue.push(e),this.wake?.()}finish(e,r={}){this.ended??={message:p({role:"assistant",content:e,...r})},this.wake?.()}fail(e){this.ended??={error:e},this.wake?.()}stream=new u(this.feed(),()=>this.ended!==null&&"cutOff"in this.ended?{message:p({role:"assistant",content:this.text||null}),finish:"other",provider_metadata:{}}:this.ended!==null&&"message"in this.ended?this.ended.message:new Error("The stream did not finish"));async*feed(){for(;;){let e=this.queue.shift();if(e!==void 0){this.text+=e.text_delta??"",yield e;continue}if(this.ended!==null){if("error"in this.ended)throw this.ended.error;return}await new Promise(r=>this.wake=r),this.wake=null}}},x=class{providerName="fake";calls=[];waiting=[];taken=0;async chat(e){let r=new y(e);return this.calls.push(r),this.waiting.shift()?.(r),r.stream}next(){let e=this.taken++,r=this.calls[e];return r!==void 0?Promise.resolve(r):new Promise(n=>this.waiting.push(n))}};import{randomUUID as _}from"node:crypto";import{readFileSync as me}from"node:fs";import{Context as he,scopeOf as we}from"@leuduan/cordis";import{onTestFinished as ge,vi as tt}from"vitest";import{z as Q}from"zod";import{mkdtempSync as de,rmSync as ce}from"node:fs";import{tmpdir as ue}from"node:os";import{join as pe}from"node:path";import{onTestFinished as fe}from"vitest";var U=new Set;function H(t){let e=de(pe(ue(),t));return U.add(e),e}function V(t){U.delete(t),ce(t,{recursive:!0,force:!0})}function Y(t="lagent-test-"){let e=H(t);return fe(()=>V(e)),{root:e}}function G(t,e="lagent-test-"){let r=H(e);return t.effect(()=>()=>V(r)),r}var Z=(t,e="fake")=>({name:`test:provider:${e}`,inject:["llm"],apply:(r,n)=>C(r,{name:e,defaultModel:"test-model",...n?.thinkingEffort===void 0?{}:{defaultThinkingEffort:n.thinkingEffort},capacity:n?.capacity??(()=>({contextWindow:null,providerTools:!1,toolResultImages:!1})),createClient:()=>t,classify:n?.classify??(()=>({kind:"other"}))},{retry:n?.retry??xe})}),ye=Object.freeze({provider:"fake",model:"test-model",thinking_effort:null}),xe={maxAttempts:1,baseDelayMs:0,maxDelayMs:0},_e=10,K={resume:"all",startLimit:64};function ee(t={}){return{from:"defaults",route:ye,...t}}async function ke(t){let e=new he;return t.disposal!=="manual"&&ge(()=>e.fiber.dispose()),await e.plugin(j,{store:t.store??new m,cwd:t.cwd??process.cwd(),dataDir:t.dataDir===void 0?G(e,"lagent-data-"):t.dataDir,retention:t.retention??"keep",chainLimit:t.chainLimit??_e,...t.limits===void 0?{}:{limits:t.limits}}),await e.plugin(Z(t.llm),{...t.capacity===void 0?{}:{capacity:t.capacity},...t.classify===void 0?{}:{classify:t.classify},...t.retry===void 0?{}:{retry:t.retry}}),await e.plugin(te(t.agents??re())),await e.plugin({name:"test:tools",inject:["tools"],apply(r){for(let{name:n,tool:a}of t.tools??Se())r.effect(()=>r.tools.register(we(r),n,a))}}),e.appended=[],e.journal.subscribe(r=>e.appended.push(r)),e.newThread=({id:r=_(),agent:n="main_agent",...a}={})=>e.threads.create(n,{id:r,...a.birth===void 0?{reuse:"identity",birth:ee()}:{},...a}),t.start!=="defer"&&await e.threads.start(K),e}var Te=()=>{let t=W(process.env,F);for(let e of N)delete t[e];return t},ve=()=>$(process.env.PATH??""),qe=Q.strictObject({path:Q.string()}),Ee=z({name:"read_file",description:"Read a file from the workspace.",parameters:qe,onInterrupted:"rerun",executionMode:"parallel",async execute(t,e){let r=L(e,"read").resolve(t.path);return{output:me(r,"utf8")}}}),Se=()=>[{name:"read_file",tool:Ee}],te=t=>({name:"test:agents",inject:["agents","tools"],apply(e){for(let{tools:r=[],...n}of t){R(e,n);for(let a of r)B(e,a,[n.name])}}}),X=(t={})=>({name:"main_agent",tools:["read_file"],...t}),re=(...t)=>t.length>0?t.map(e=>X(e)):[X()];async function be(t,e={}){let{route:r,signal:n,untilWait:a=!1}=e,l=()=>t.cancel(n===void 0?"Turn cancelled":O(n.reason),{intent:"user"});if(n?.aborted)return await l(),{thread_id:t.id,ended:"cancelled",reason:null,pending_confirmations:null};let s,o=()=>{s=l(),s.catch(()=>{})};n?.addEventListener("abort",o,{once:!0});let d=t.service,h=t.summary.through_seq;try{let f=await t.resume(r===void 0?{}:{route:r});if(s!==void 0)return await s,{thread_id:t.id,ended:"cancelled",reason:null,pending_confirmations:null};let c=await M(d,t.id,f,i=>D(i)&&(a||i.state!=="held"||i.hold.reason!=="wait"));await s;let k=await t.read(i=>i.replay().filter(oe=>oe.seq>h)),se=n?.aborted===!0||c.state==="held"&&c.hold.reason==="shutdown"||c.state==="settled"&&(c.outcome==="cancelled"||c.outcome==="superseded");return{thread_id:t.id,ended:se?"cancelled":k.some(i=>i.type==="turn/start")?"turns":"none",reason:k.some(i=>i.type==="turn/end")?t.lastOutcome():null,pending_confirmations:await t.read(i=>i.pendingConfirmations())}}finally{n?.removeEventListener("abort",o)}}var Oe=(t={})=>({maxOpenTasks:8,clock:J,...t});async function Pe(t,e,r,n,a={}){let l=t,[s]=await P(l,e,{trigger:"request",turn:null,step:null},[{kind:"span",stand_in:{role:a.role??"user",content:n},source:a.source??{plugin:"test:strategy",kind:"checkpoint",version:1,data:null},source_seqs:r.map(o=>o.seq)}]);return l.eventAt(s.seq)}var Re=t=>t===void 0?"":w(t);var Ae=t=>{let e=[...t].reverse().find(r=>r.role==="tool");return e===void 0?null:w(e)},Ce=t=>t.service.view(t.id);function Ie(t=new m,e={}){return new q(t,{summarize:e.summarize??((r,n)=>b(r,n,S())),...e.onListenerError===void 0?{}:{onListenerError:e.onListenerError},coreFolds:e.coreFolds??(e.summarize===void 0?[E]:[])})}async function Le(t){let e=t;return await Promise.all(t.summaries().map(r=>e.load(r.thread_id))),t.summaries().flatMap(r=>t.rows(r.thread_id)).sort((r,n)=>r.seq-n.seq)}async function ne(t){let e=t.isOpen;e||await t.open();try{let r=await t.threads();return(await Promise.all(r.map(({threadId:a})=>t.read(a)))).flat().sort((a,l)=>a.seq-l.seq)}finally{e||await t.close()}}async function ae(t,e,r){let n=await t.acquireWriter();try{for(let a of e)await t.append({id:_(),baseHead:await t.head(),writer:n.acquisitionId,rows:[a]});await t.putSummaries(r,n.acquisitionId)}finally{await n.release()}}async function Me(t){let e=new m;await e.open();let r=t.isOpen;r||await t.open();try{await ae(e,await ne(t),await t.summaries())}finally{r||await t.close()}return e}async function De(t){let e=new m;await e.open(),await ae(e,t,[]);let r=Ie(e);return await r.open(),await r.close(),e}async function je(t,e){let r=await A(t).append("tool/call",{turn:1,step:1,call_id:`call-${_()}`,name:"test_call"},{threadId:e});return{caller_thread_id:e,source_seq:r.seq,cause:{kind:"call"}}}var Ne=t=>({name:`test:prompt:${t.tag}`,inject:["prompts"],apply:e=>I(e,t)});function Fe(t=Date.parse("2026-01-05T09:00:00Z")){let e=t,r=0,n=0,a=new Map,l=(s,o)=>{for(;;){let d;for(let c of a)c[1].due<=s&&(d===void 0||c[1].due<d[1].due)&&(d=c);if(d===void 0)break;let[h,f]=d;o&&(e+=f.due-r),r=f.due,a.delete(h),f.fire()}o&&(e+=s-r),r=s};return{now:()=>e,setTimer(s,o){let d=n++;return a.set(d,{due:r+Math.max(0,s),fire:o}),()=>{a.delete(d)}},advance:s=>l(r+s,!0),jump(s){e+=s},elapse:s=>l(r+s,!1),pending:()=>[...a.values()].map(s=>s.due-r).sort((s,o)=>s-o)}}export{g as FakeLLMClient,x as FedLLM,K as TEST_START,ie as assistant,je as callOrigin,Me as copyStore,ke as createTestRoot,be as drive,Z as fakeProvider,Le as journalRows,Ae as lastToolMessage,Fe as manualClock,Pe as replaceSpan,De as replayStore,ne as storeRows,re as testAgents,te as testAgentsPlugin,ee as testBirth,Oe as testDelegations,Te as testEnvironment,ve as testPrograms,Ne as testPromptPlugin,Re as textOf,Y as tmpWorkspace,Ce as viewOf,le as withToolCalls};
1
+ import{a as B}from"../chunks/W57RW55W.js";import{a as E,b as I,c as N,f as J,h as m}from"../chunks/B4FXK5ER.js";import"../chunks/SS3B5W34.js";import"../chunks/IAAEP6VL.js";import"../chunks/OCBPT7KE.js";import"../chunks/2P47AHNK.js";import"../chunks/MHC6VPB4.js";import"../chunks/EMRB4KCN.js";import"../chunks/RCIHV3KG.js";import"../chunks/2GCIWSOA.js";import{a as z}from"../chunks/GGSVIIWJ.js";import{c as L,d as M}from"../chunks/CANPZYTH.js";import"../chunks/VYMT4TXD.js";import"../chunks/MNJ4SRF7.js";import"../chunks/JFZZXVWD.js";import{c as F,e as W}from"../chunks/N6IXG2VL.js";import"../chunks/6DRCKZ2C.js";import"../chunks/7LI64H5X.js";import"../chunks/3UMZMPWW.js";import{a as A}from"../chunks/Q75FUN7D.js";import"../chunks/PUSUPTAT.js";import"../chunks/34KW6VNQ.js";import"../chunks/KUZCL2SH.js";import"../chunks/CQEVREBT.js";import{b as $}from"../chunks/HK6ZSONF.js";import"../chunks/7VAPNE3L.js";import{b as C}from"../chunks/EPYQ5M3B.js";import{a as b,c as R}from"../chunks/5IRF47YB.js";import"../chunks/OL5A6ITQ.js";import{b as D,e as j}from"../chunks/JFX2MXBA.js";import"../chunks/S34ZA2R6.js";import"../chunks/6FRNHMCV.js";import{b as P}from"../chunks/CUK7CGC7.js";import{H as S,s as q}from"../chunks/BPRCULZH.js";import"../chunks/FJLU4UH3.js";import{f as O}from"../chunks/DDANMY45.js";import{w as v}from"../chunks/BBCW2FZK.js";import"../chunks/MMNNZCBO.js";import"../chunks/G44LG6VL.js";import{o as T,q as p,r as w}from"../chunks/D4PQP5MA.js";var u=class{claimed=!1;ledger=new A;failure;chunks;settled;options;constructor(e,n,r={}){this.chunks=e,this.settled=n,this.options=r}[Symbol.asyncIterator](){if(this.claimed)throw new Error("A response is read once: it has been claimed already");this.claimed=!0;let e=this.read();return{next:()=>this.ledger.operation(()=>e.next()),return:n=>this.ledger.operation(()=>e.return(n),!0),throw:n=>this.ledger.operation(()=>e.throw(n),!0)}}async*read(){try{for await(let n of this.chunks)yield T.parse(n);let e=this.options.readFailure===!0?this.settlement():void 0;if(e instanceof Error)throw e}catch(e){throw this.failure={error:e},e}finally{this.ledger.finish()}}settlement(){return typeof this.settled=="function"?this.settled():this.settled}async completed(){if(this.claimed){if(!this.ledger.ended)throw new Error("A response is settled before its read or after it, not while the read is under way")}else for await(let n of this);if(this.failure!==void 0)throw this.failure.error;let e=this.settlement();if(e instanceof Error)throw e;return"finish"in e?e:{message:e,finish:this.options.finish??"completed",provider_metadata:{}}}},g=class t{providerName="fake";requests=[];handler;constructor(e){this.handler=e}static scripted(...e){let n=0;return new t(()=>{let r=e[n];if(r===void 0)throw new Error(`Unexpected LLM call #${n+1}`);return n+=1,r})}async chat(e){if(this.requests.push(e),e.signal?.aborted)throw e.signal.reason instanceof Error?e.signal.reason:new Error("aborted");let n=await this.handler(e.messages,e);return"failure"in n?new u(n.chunks,n.failure):"chunks"in n?new u(n.chunks,n.message):new u([],n)}},ie=(t,e={})=>p({role:"assistant",content:t,...e}),le=(t,e=null)=>p({role:"assistant",content:e,tool_calls:t.map(n=>n.arguments===void 0?{...n,arguments:{}}:n)});var y=class{request;queue=[];ended=null;text="";wake=null;constructor(e){this.request=e,e.signal?.addEventListener("abort",()=>{this.ended??={cutOff:!0},this.wake?.()},{once:!0})}push(e){this.queue.push(e),this.wake?.()}finish(e,n={}){this.ended??={message:p({role:"assistant",content:e,...n})},this.wake?.()}fail(e){this.ended??={error:e},this.wake?.()}stream=new u(this.feed(),()=>this.ended!==null&&"cutOff"in this.ended?{message:p({role:"assistant",content:this.text||null}),finish:"other",provider_metadata:{}}:this.ended!==null&&"message"in this.ended?this.ended.message:new Error("The stream did not finish"));async*feed(){for(;;){let e=this.queue.shift();if(e!==void 0){this.text+=e.text_delta??"",yield e;continue}if(this.ended!==null){if("error"in this.ended)throw this.ended.error;return}await new Promise(n=>this.wake=n),this.wake=null}}},x=class{providerName="fake";calls=[];waiting=[];taken=0;async chat(e){let n=new y(e);return this.calls.push(n),this.waiting.shift()?.(n),n.stream}next(){let e=this.taken++,n=this.calls[e];return n!==void 0?Promise.resolve(n):new Promise(r=>this.waiting.push(r))}};import{randomUUID as _}from"node:crypto";import{resolve as me}from"node:path";import{Context as he,scopeOf as we}from"@leuduan/cordis";import{onTestFinished as ge,vi as tt}from"vitest";import{z as Q}from"zod";import{mkdtempSync as de,rmSync as ce}from"node:fs";import{tmpdir as ue}from"node:os";import{join as pe}from"node:path";import{onTestFinished as fe}from"vitest";var U=new Set;function H(t){let e=de(pe(ue(),t));return U.add(e),e}function V(t){U.delete(t),ce(t,{recursive:!0,force:!0})}function Y(t="lagent-test-"){let e=H(t);return fe(()=>V(e)),{root:e}}function G(t,e="lagent-test-"){let n=H(e);return t.effect(()=>()=>V(n)),n}var Z=(t,e="fake")=>({name:`test:provider:${e}`,inject:["llm"],apply:(n,r)=>I(n,{name:e,defaultModel:"test-model",...r?.thinkingEffort===void 0?{}:{defaultThinkingEffort:r.thinkingEffort},capacity:r?.capacity??(()=>({contextWindow:null,providerTools:!1,toolResultImages:!1})),createClient:()=>t,classify:r?.classify??(()=>({kind:"other"}))},{retry:r?.retry??xe})}),ye=Object.freeze({provider:"fake",model:"test-model",thinking_effort:null}),xe={maxAttempts:1,baseDelayMs:0,maxDelayMs:0},_e=10,K={resume:"all",startLimit:64};function ee(t={}){return{from:"defaults",route:ye,...t}}async function ke(t){let e=new he;t.disposal!=="manual"&&ge(()=>e.fiber.dispose()),await e.plugin(N,{store:t.store??new m,cwd:t.cwd??process.cwd(),retention:t.retention??"keep",chainLimit:t.chainLimit??_e,...t.limits===void 0?{}:{limits:t.limits}});let n=t.dataDir===void 0?G(e,"lagent-data-"):t.dataDir;return n!==null&&await e.plugin(B,{dataDir:n}),await e.plugin(Z(t.llm),{...t.capacity===void 0?{}:{capacity:t.capacity},...t.classify===void 0?{}:{classify:t.classify},...t.retry===void 0?{}:{retry:t.retry}}),await e.plugin(te(t.agents??ne())),await e.plugin({name:"test:tools",inject:["tools"],apply(r){for(let{name:s,tool:o}of t.tools??Se())r.effect(()=>r.tools.register(we(r),s,o))}}),e.appended=[],e.journal.subscribe(r=>e.appended.push(r)),e.newThread=({id:r=_(),agent:s="main_agent",...o}={})=>e.threads.create(s,{id:r,...o.birth===void 0?{reuse:"identity",birth:ee()}:{},...o}),t.start!=="defer"&&await e.threads.start(K),e}var Te=()=>{let t=F(process.env,J);for(let e of z)delete t[e];return t},ve=()=>W(process.env.PATH??""),qe=Q.strictObject({path:Q.string()}),Ee=D({name:"read_file",description:"Read a file from the workspace.",parameters:qe,onInterrupted:"rerun",executionMode:"parallel",async execute(t,e){let n=await e.operation.files.open(me(e.environment.cwd,t.path));try{return{output:(await n.readAll()).toString("utf8")}}finally{await n.close()}}}),Se=()=>[{name:"read_file",tool:Ee}],te=t=>({name:"test:agents",inject:["agents","tools"],apply(e){for(let{tools:n=[],...r}of t){P(e,r);for(let s of n)j(e,s,[r.name])}}}),X=(t={})=>({name:"main_agent",tools:["read_file"],...t}),ne=(...t)=>t.length>0?t.map(e=>X(e)):[X()];async function be(t,e={}){let{route:n,signal:r,untilWait:s=!1}=e,o=()=>t.cancel(r===void 0?"Turn cancelled":O(r.reason),{intent:"user"});if(r?.aborted)return await o(),{thread_id:t.id,ended:"cancelled",reason:null,pending_confirmations:null};let a,i=()=>{a=o(),a.catch(()=>{})};r?.addEventListener("abort",i,{once:!0});let d=t.service,h=t.summary.through_seq;try{let f=await t.resume(n===void 0?{}:{route:n});if(a!==void 0)return await a,{thread_id:t.id,ended:"cancelled",reason:null,pending_confirmations:null};let c=await L(d,t.id,f,l=>M(l)&&(s||l.state!=="held"||l.hold.reason!=="wait"));await a;let k=await t.read(l=>l.replay().filter(oe=>oe.seq>h)),se=r?.aborted===!0||c.state==="held"&&c.hold.reason==="shutdown"||c.state==="settled"&&(c.outcome==="cancelled"||c.outcome==="superseded");return{thread_id:t.id,ended:se?"cancelled":k.some(l=>l.type==="turn/start")?"turns":"none",reason:k.some(l=>l.type==="turn/end")?t.lastOutcome():null,pending_confirmations:await t.read(l=>l.pendingConfirmations())}}finally{r?.removeEventListener("abort",i)}}var Oe=(t={})=>({maxOpenTasks:8,clock:$,...t});async function Pe(t,e,n,r,s={}){let o=t,[a]=await S(o,e,{trigger:"request",turn:null,step:null},[{kind:"span",stand_in:{role:s.role??"user",content:r},source:s.source??{plugin:"test:strategy",kind:"checkpoint",version:1,data:null},source_seqs:n.map(i=>i.seq)}]);return o.eventAt(a.seq)}var Re=t=>t===void 0?"":w(t);var Ae=t=>{let e=[...t].reverse().find(n=>n.role==="tool");return e===void 0?null:w(e)},Ie=t=>t.service.view(t.id);function Ce(t=new m,e={}){return new v(t,{summarize:e.summarize??((n,r)=>b(n,r,E())),...e.onListenerError===void 0?{}:{onListenerError:e.onListenerError},coreFolds:e.coreFolds??(e.summarize===void 0?[q]:[])})}async function Le(t){let e=t;return await Promise.all(t.summaries().map(n=>e.load(n.thread_id))),t.summaries().flatMap(n=>t.rows(n.thread_id)).sort((n,r)=>n.seq-r.seq)}async function re(t){let e=t.isOpen;e||await t.open();try{let n=await t.threads();return(await Promise.all(n.map(({threadId:s})=>t.read(s)))).flat().sort((s,o)=>s.seq-o.seq)}finally{e||await t.close()}}async function ae(t,e,n){let r=await t.acquireWriter();try{for(let s of e)await t.append({id:_(),baseHead:await t.head(),writer:r.acquisitionId,rows:[s]});await t.putSummaries(n,r.acquisitionId)}finally{await r.release()}}async function Me(t){let e=new m;await e.open();let n=t.isOpen;n||await t.open();try{await ae(e,await re(t),await t.summaries())}finally{n||await t.close()}return e}async function De(t){let e=new m;await e.open(),await ae(e,t,[]);let n=Ce(e);return await n.open(),await n.close(),e}async function je(t,e){let n=await R(t).append("tool/call",{turn:1,step:1,call_id:`call-${_()}`,name:"test_call"},{threadId:e});return{caller_thread_id:e,source_seq:n.seq,cause:{kind:"call"}}}var Ne=t=>({name:`test:prompt:${t.tag}`,inject:["prompts"],apply:e=>C(e,t)});function Fe(t=Date.parse("2026-01-05T09:00:00Z")){let e=t,n=0,r=0,s=new Map,o=(a,i)=>{for(;;){let d;for(let c of s)c[1].due<=a&&(d===void 0||c[1].due<d[1].due)&&(d=c);if(d===void 0)break;let[h,f]=d;i&&(e+=f.due-n),n=f.due,s.delete(h),f.fire()}i&&(e+=a-n),n=a};return{now:()=>e,setTimer(a,i){let d=r++;return s.set(d,{due:n+Math.max(0,a),fire:i}),()=>{s.delete(d)}},advance:a=>o(n+a,!0),jump(a){e+=a},elapse:a=>o(n+a,!1),pending:()=>[...s.values()].map(a=>a.due-n).sort((a,i)=>a-i)}}export{g as FakeLLMClient,x as FedLLM,K as TEST_START,ie as assistant,je as callOrigin,Me as copyStore,ke as createTestRoot,be as drive,Z as fakeProvider,Le as journalRows,Ae as lastToolMessage,Fe as manualClock,Pe as replaceSpan,De as replayStore,re as storeRows,ne as testAgents,te as testAgentsPlugin,ee as testBirth,Oe as testDelegations,Te as testEnvironment,ve as testPrograms,Ne as testPromptPlugin,Re as textOf,Y as tmpWorkspace,Ie as viewOf,le as withToolCalls};
@@ -1,4 +1,4 @@
1
- import type { StreamingLLMResponse } from '../llm/index.js';
1
+ import type { StreamingLLMResponse } from '../llm/client.js';
2
2
  /**
3
3
  * Asks `stream` to settle at every turn of the microtask queue while `closing` is pending, and fails
4
4
  * when one settles with `closing` still pending at the moment it was asked: the read is not over.