@leuduan/lagent 0.0.0-stage → 0.1.2

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 (327) hide show
  1. package/LICENSE +16 -0
  2. package/README.md +144 -2
  3. package/dist/chunks/2O7ZGEIT.js +1 -0
  4. package/dist/chunks/2OSESBIL.js +1 -0
  5. package/dist/chunks/34KW6VNQ.js +1 -0
  6. package/dist/chunks/37YOGDGY.js +1 -0
  7. package/dist/chunks/3LQHQRIU.js +6 -0
  8. package/dist/chunks/3QCW4WDJ.js +1 -0
  9. package/dist/chunks/4XVRUSCQ.js +1 -0
  10. package/dist/chunks/6ECI2GGV.js +1 -0
  11. package/dist/chunks/74HKUGRR.js +1 -0
  12. package/dist/chunks/ADHERZLW.js +2 -0
  13. package/dist/chunks/AP6Q4EPT.js +36 -0
  14. package/dist/chunks/BM3S37EZ.js +1 -0
  15. package/dist/chunks/C5LYCXJG.js +1 -0
  16. package/dist/chunks/CDQG7RKA.js +1 -0
  17. package/dist/chunks/D7E6EWIE.js +3 -0
  18. package/dist/chunks/DDANMY45.js +3 -0
  19. package/dist/chunks/DRYAN665.js +1 -0
  20. package/dist/chunks/DXFXAYDN.js +17 -0
  21. package/dist/chunks/EGZI4XQX.js +24 -0
  22. package/dist/chunks/ENWFSU27.js +41 -0
  23. package/dist/chunks/G6RXC3AL.js +1 -0
  24. package/dist/chunks/G74AGRAJ.js +15 -0
  25. package/dist/chunks/GQGNVSKB.js +1 -0
  26. package/dist/chunks/IJ2WNMD5.js +7 -0
  27. package/dist/chunks/J5S4URAW.js +1 -0
  28. package/dist/chunks/JPZFKSWT.js +1 -0
  29. package/dist/chunks/KESCTXGO.js +5 -0
  30. package/dist/chunks/L3N4FIEN.js +1 -0
  31. package/dist/chunks/NAOUTU7A.js +4 -0
  32. package/dist/chunks/NDIM7MEW.js +1 -0
  33. package/dist/chunks/O4PPOM5Z.js +2 -0
  34. package/dist/chunks/OVZFGILJ.js +1 -0
  35. package/dist/chunks/P5ZHHOOM.js +6 -0
  36. package/dist/chunks/PUSUPTAT.js +1 -0
  37. package/dist/chunks/QMMLQJBS.js +1 -0
  38. package/dist/chunks/RK3VP2Q4.js +3 -0
  39. package/dist/chunks/SGGMBSBA.js +1 -0
  40. package/dist/chunks/SL2YLB2F.js +1 -0
  41. package/dist/chunks/TOOIB6J2.js +1 -0
  42. package/dist/chunks/TYTQRLTX.js +1 -0
  43. package/dist/chunks/UC3FVVJ2.js +5 -0
  44. package/dist/chunks/UCTEU62F.js +1 -0
  45. package/dist/chunks/UD3VJER6.js +1 -0
  46. package/dist/chunks/UKXMCHHT.js +1 -0
  47. package/dist/chunks/WUUKTSRT.js +7 -0
  48. package/dist/chunks/X65X4KP5.js +7 -0
  49. package/dist/chunks/YIR5MYGU.js +1 -0
  50. package/dist/chunks/YLNJXQ3Z.js +1 -0
  51. package/dist/context.d.ts +101 -0
  52. package/dist/index.d.ts +47 -0
  53. package/dist/index.js +77 -0
  54. package/dist/journal/catalog.d.ts +112 -0
  55. package/dist/journal/forkChain.d.ts +16 -0
  56. package/dist/journal/index.d.ts +15 -0
  57. package/dist/journal/journal.d.ts +475 -0
  58. package/dist/journal/projection.d.ts +87 -0
  59. package/dist/journal/store.d.ts +181 -0
  60. package/dist/kit/claim.d.ts +13 -0
  61. package/dist/kit/drain.d.ts +10 -0
  62. package/dist/kit/extension.d.ts +180 -0
  63. package/dist/kit/grants.d.ts +9 -0
  64. package/dist/kit/modes.d.ts +65 -0
  65. package/dist/kit/retries.d.ts +25 -0
  66. package/dist/kit/scope.d.ts +32 -0
  67. package/dist/kit/service.d.ts +7 -0
  68. package/dist/kit/strategy.d.ts +10 -0
  69. package/dist/kit/timers.d.ts +43 -0
  70. package/dist/kit/tool.d.ts +72 -0
  71. package/dist/llm/client.d.ts +135 -0
  72. package/dist/llm/content.d.ts +52 -0
  73. package/dist/llm/door.d.ts +21 -0
  74. package/dist/llm/door.js +1 -0
  75. package/dist/llm/failure.d.ts +82 -0
  76. package/dist/llm/index.d.ts +16 -0
  77. package/dist/llm/primitives.d.ts +286 -0
  78. package/dist/llm/prompt.d.ts +21 -0
  79. package/dist/llm/provider.d.ts +63 -0
  80. package/dist/llm/readLedger.d.ts +24 -0
  81. package/dist/llm/request.d.ts +58 -0
  82. package/dist/loop/agent.d.ts +134 -0
  83. package/dist/loop/auxiliary.d.ts +54 -0
  84. package/dist/loop/chain.d.ts +46 -0
  85. package/dist/loop/chunks.d.ts +27 -0
  86. package/dist/loop/continuation.d.ts +166 -0
  87. package/dist/loop/decide.d.ts +64 -0
  88. package/dist/loop/errors.d.ts +162 -0
  89. package/dist/loop/forks.d.ts +61 -0
  90. package/dist/loop/holds.d.ts +104 -0
  91. package/dist/loop/hooks.d.ts +241 -0
  92. package/dist/loop/inbox.d.ts +188 -0
  93. package/dist/loop/index.d.ts +37 -0
  94. package/dist/loop/limits.d.ts +14 -0
  95. package/dist/loop/opening.d.ts +42 -0
  96. package/dist/loop/prepare.d.ts +30 -0
  97. package/dist/loop/projections.d.ts +307 -0
  98. package/dist/loop/replace.d.ts +33 -0
  99. package/dist/loop/requests.d.ts +129 -0
  100. package/dist/loop/route.d.ts +53 -0
  101. package/dist/loop/runtime.d.ts +85 -0
  102. package/dist/loop/state.d.ts +70 -0
  103. package/dist/loop/strategy.d.ts +71 -0
  104. package/dist/loop/summary.d.ts +3 -0
  105. package/dist/loop/surface.d.ts +153 -0
  106. package/dist/loop/threadState.d.ts +72 -0
  107. package/dist/loop/tool.d.ts +101 -0
  108. package/dist/loop/toolCalls.d.ts +42 -0
  109. package/dist/loop/wake.d.ts +32 -0
  110. package/dist/models/config/agent.d.ts +18 -0
  111. package/dist/models/config/prompt.d.ts +18 -0
  112. package/dist/models/door.d.ts +12 -0
  113. package/dist/models/door.js +1 -0
  114. package/dist/models/index.d.ts +7 -0
  115. package/dist/models/jsonSchema.d.ts +7 -0
  116. package/dist/models/wire/journal.d.ts +2772 -0
  117. package/dist/models/wire/primitives.d.ts +65 -0
  118. package/dist/plugin.d.ts +53 -0
  119. package/dist/plugin.js +1 -0
  120. package/dist/plugins/agentsMd.d.ts +76 -0
  121. package/dist/plugins/agentsMd.js +1 -0
  122. package/dist/plugins/ask/askQuestion.d.ts +9 -0
  123. package/dist/plugins/ask/index.d.ts +26 -0
  124. package/dist/plugins/ask/index.js +1 -0
  125. package/dist/plugins/ask/service.d.ts +125 -0
  126. package/dist/plugins/commands/background.d.ts +8 -0
  127. package/dist/plugins/commands/foreground.d.ts +4 -0
  128. package/dist/plugins/commands/index.d.ts +40 -0
  129. package/dist/plugins/commands/index.js +1 -0
  130. package/dist/plugins/commands/output.d.ts +115 -0
  131. package/dist/plugins/commands/record.d.ts +549 -0
  132. package/dist/plugins/commands/service.d.ts +314 -0
  133. package/dist/plugins/commands/shell.d.ts +25 -0
  134. package/dist/plugins/compaction/checkpoint.d.ts +91 -0
  135. package/dist/plugins/compaction/config.d.ts +133 -0
  136. package/dist/plugins/compaction/estimate.d.ts +29 -0
  137. package/dist/plugins/compaction/index.d.ts +2 -0
  138. package/dist/plugins/compaction/index.js +7 -0
  139. package/dist/plugins/compaction/log.d.ts +61 -0
  140. package/dist/plugins/compaction/planner.d.ts +207 -0
  141. package/dist/plugins/compaction/preset.d.ts +86 -0
  142. package/dist/plugins/compaction/prune.d.ts +9 -0
  143. package/dist/plugins/compaction/records.d.ts +227 -0
  144. package/dist/plugins/compaction/segments.d.ts +23 -0
  145. package/dist/plugins/compaction/shared.d.ts +14 -0
  146. package/dist/plugins/compaction/summarize.d.ts +13 -0
  147. package/dist/plugins/dateAndBranch.d.ts +47 -0
  148. package/dist/plugins/dateAndBranch.js +1 -0
  149. package/dist/plugins/delegations/answers.d.ts +39 -0
  150. package/dist/plugins/delegations/assignmentKey.d.ts +22 -0
  151. package/dist/plugins/delegations/cleanup.d.ts +161 -0
  152. package/dist/plugins/delegations/constraint.d.ts +76 -0
  153. package/dist/plugins/delegations/index.d.ts +39 -0
  154. package/dist/plugins/delegations/index.js +1 -0
  155. package/dist/plugins/delegations/notices.d.ts +261 -0
  156. package/dist/plugins/delegations/obligations.d.ts +210 -0
  157. package/dist/plugins/delegations/record.d.ts +632 -0
  158. package/dist/plugins/delegations/request.d.ts +381 -0
  159. package/dist/plugins/delegations/role.d.ts +30 -0
  160. package/dist/plugins/delegations/service.d.ts +562 -0
  161. package/dist/plugins/delegations/standing.d.ts +19 -0
  162. package/dist/plugins/delegations/stopCheck.d.ts +21 -0
  163. package/dist/plugins/delegations/testing.d.ts +16 -0
  164. package/dist/plugins/delegations/tools.d.ts +71 -0
  165. package/dist/plugins/delegations/waitBook.d.ts +116 -0
  166. package/dist/plugins/delegations/waits.d.ts +118 -0
  167. package/dist/plugins/diagnostics/digest.d.ts +14 -0
  168. package/dist/plugins/diagnostics/index.d.ts +68 -0
  169. package/dist/plugins/diagnostics/index.js +1 -0
  170. package/dist/plugins/historyRecall/history.d.ts +9 -0
  171. package/dist/plugins/historyRecall/index.d.ts +31 -0
  172. package/dist/plugins/historyRecall/index.js +1 -0
  173. package/dist/plugins/historyRecall/render.d.ts +34 -0
  174. package/dist/plugins/historyRecall/tools.d.ts +4 -0
  175. package/dist/plugins/mcp/catalog.d.ts +36 -0
  176. package/dist/plugins/mcp/config.d.ts +63 -0
  177. package/dist/plugins/mcp/connection.d.ts +53 -0
  178. package/dist/plugins/mcp/errors.d.ts +32 -0
  179. package/dist/plugins/mcp/index.d.ts +33 -0
  180. package/dist/plugins/mcp/index.js +5 -0
  181. package/dist/plugins/mcp/mount.d.ts +98 -0
  182. package/dist/plugins/mcp/names.d.ts +25 -0
  183. package/dist/plugins/mcp/render.d.ts +29 -0
  184. package/dist/plugins/mcp/slots.d.ts +15 -0
  185. package/dist/plugins/mcp/stdio.d.ts +49 -0
  186. package/dist/plugins/mcp/tool.d.ts +41 -0
  187. package/dist/plugins/providers/anthropic.d.ts +175 -0
  188. package/dist/plugins/providers/anthropicMessages.d.ts +65 -0
  189. package/dist/plugins/providers/codex.d.ts +60 -0
  190. package/dist/plugins/providers/codexAuth.d.ts +116 -0
  191. package/dist/plugins/providers/deepseek.d.ts +55 -0
  192. package/dist/plugins/providers/door.d.ts +61 -0
  193. package/dist/plugins/providers/door.js +1 -0
  194. package/dist/plugins/providers/failure.d.ts +23 -0
  195. package/dist/plugins/providers/gateway.d.ts +23 -0
  196. package/dist/plugins/providers/index.d.ts +6 -0
  197. package/dist/plugins/providers/openaiChat.d.ts +62 -0
  198. package/dist/plugins/providers/openaiResponses.d.ts +100 -0
  199. package/dist/plugins/providers/opencodeCopilot.d.ts +23 -0
  200. package/dist/plugins/providers/opencodeGo.d.ts +98 -0
  201. package/dist/plugins/providers/shared.d.ts +104 -0
  202. package/dist/plugins/providers/stream.d.ts +154 -0
  203. package/dist/plugins/routeContext.d.ts +22 -0
  204. package/dist/plugins/routeContext.js +1 -0
  205. package/dist/plugins/schedules/index.d.ts +21 -0
  206. package/dist/plugins/schedules/index.js +5 -0
  207. package/dist/plugins/schedules/record.d.ts +396 -0
  208. package/dist/plugins/schedules/service.d.ts +120 -0
  209. package/dist/plugins/schedules/time.d.ts +26 -0
  210. package/dist/plugins/schedules/tools.d.ts +6 -0
  211. package/dist/plugins/skills/discovery.d.ts +54 -0
  212. package/dist/plugins/skills/index.d.ts +31 -0
  213. package/dist/plugins/skills/index.js +1 -0
  214. package/dist/plugins/skills/tool.d.ts +11 -0
  215. package/dist/plugins/store/durableObject.d.ts +23 -0
  216. package/dist/plugins/store/durableObject.js +1 -0
  217. package/dist/plugins/store/durableObjectConnection.d.ts +27 -0
  218. package/dist/plugins/store/memory.d.ts +29 -0
  219. package/dist/plugins/store/sql.d.ts +59 -0
  220. package/dist/plugins/store/sqlite.d.ts +31 -0
  221. package/dist/plugins/store/sqlite.js +1 -0
  222. package/dist/plugins/subAgents/availableRoutes.d.ts +53 -0
  223. package/dist/plugins/subAgents/fork.d.ts +32 -0
  224. package/dist/plugins/subAgents/index.d.ts +67 -0
  225. package/dist/plugins/subAgents/index.js +1 -0
  226. package/dist/plugins/subAgents/tool.d.ts +38 -0
  227. package/dist/plugins/toolPolicy/index.d.ts +61 -0
  228. package/dist/plugins/toolPolicy/index.js +1 -0
  229. package/dist/plugins/tools/editFiles.d.ts +128 -0
  230. package/dist/plugins/tools/fsRead.d.ts +17 -0
  231. package/dist/plugins/tools/html.d.ts +23 -0
  232. package/dist/plugins/tools/index.d.ts +59 -0
  233. package/dist/plugins/tools/index.js +1 -0
  234. package/dist/plugins/tools/network.d.ts +23 -0
  235. package/dist/plugins/tools/ripgrep.d.ts +20 -0
  236. package/dist/plugins/tools/textEdit.d.ts +67 -0
  237. package/dist/plugins/tools/web.d.ts +32 -0
  238. package/dist/plugins/truncateToolOutput.d.ts +26 -0
  239. package/dist/plugins/truncateToolOutput.js +1 -0
  240. package/dist/plugins/usage/index.d.ts +24 -0
  241. package/dist/plugins/usage/index.js +1 -0
  242. package/dist/plugins/usage/tracker.d.ts +34 -0
  243. package/dist/plugins/verify/facts.d.ts +356 -0
  244. package/dist/plugins/verify/index.d.ts +75 -0
  245. package/dist/plugins/verify/index.js +1 -0
  246. package/dist/plugins/verify/service.d.ts +90 -0
  247. package/dist/plugins/workflows/assignment.d.ts +16 -0
  248. package/dist/plugins/workflows/bindings.d.ts +95 -0
  249. package/dist/plugins/workflows/cleanup.d.ts +38 -0
  250. package/dist/plugins/workflows/definition.d.ts +184 -0
  251. package/dist/plugins/workflows/fold.d.ts +373 -0
  252. package/dist/plugins/workflows/index.d.ts +28 -0
  253. package/dist/plugins/workflows/index.js +6 -0
  254. package/dist/plugins/workflows/observations.d.ts +81 -0
  255. package/dist/plugins/workflows/participants.d.ts +143 -0
  256. package/dist/plugins/workflows/policy.d.ts +112 -0
  257. package/dist/plugins/workflows/providers.d.ts +146 -0
  258. package/dist/plugins/workflows/record.d.ts +2863 -0
  259. package/dist/plugins/workflows/routing.d.ts +116 -0
  260. package/dist/plugins/workflows/schema.d.ts +26 -0
  261. package/dist/plugins/workflows/service.d.ts +477 -0
  262. package/dist/plugins/workflows/submit.d.ts +8 -0
  263. package/dist/plugins/workflows/view.d.ts +103 -0
  264. package/dist/plugins/workflows/work.d.ts +21 -0
  265. package/dist/plugins/workspaceContext.d.ts +38 -0
  266. package/dist/plugins/workspaceContext.js +1 -0
  267. package/dist/presets/agents.d.ts +7 -0
  268. package/dist/presets/base.d.ts +10 -0
  269. package/dist/presets/codex.d.ts +60 -0
  270. package/dist/presets/index.d.ts +4 -0
  271. package/dist/presets/prompts.d.ts +56 -0
  272. package/dist/sandbox/absent.d.ts +32 -0
  273. package/dist/sandbox/client.d.ts +39 -0
  274. package/dist/sandbox/files.d.ts +28 -0
  275. package/dist/sandbox/index.d.ts +49 -0
  276. package/dist/sandbox/index.js +4 -0
  277. package/dist/sandbox/mode.d.ts +57 -0
  278. package/dist/sandbox/policy.d.ts +86 -0
  279. package/dist/sandbox/protocol.d.ts +107 -0
  280. package/dist/sandbox/service.d.ts +143 -0
  281. package/dist/sandbox/worker.d.ts +12 -0
  282. package/dist/sandbox/worker.js +1 -0
  283. package/dist/services/admission.d.ts +174 -0
  284. package/dist/services/agents.d.ts +37 -0
  285. package/dist/services/birth.d.ts +220 -0
  286. package/dist/services/contributions.d.ts +73 -0
  287. package/dist/services/core.d.ts +34 -0
  288. package/dist/services/journal.d.ts +26 -0
  289. package/dist/services/launches.d.ts +104 -0
  290. package/dist/services/llm.d.ts +80 -0
  291. package/dist/services/owner.d.ts +367 -0
  292. package/dist/services/preset.d.ts +154 -0
  293. package/dist/services/presets.d.ts +139 -0
  294. package/dist/services/prompts.d.ts +67 -0
  295. package/dist/services/runEvents.d.ts +79 -0
  296. package/dist/services/thread.d.ts +267 -0
  297. package/dist/services/threadActivation.d.ts +100 -0
  298. package/dist/services/threadDirs.d.ts +38 -0
  299. package/dist/services/threadView.d.ts +92 -0
  300. package/dist/services/threads.d.ts +449 -0
  301. package/dist/services/tools.d.ts +41 -0
  302. package/dist/sys/environment.d.ts +47 -0
  303. package/dist/sys/git.d.ts +60 -0
  304. package/dist/sys/paths.d.ts +56 -0
  305. package/dist/sys/spawn.d.ts +176 -0
  306. package/dist/testing/clock.d.ts +17 -0
  307. package/dist/testing/fakeLlm.d.ts +74 -0
  308. package/dist/testing/fedLlm.d.ts +32 -0
  309. package/dist/testing/helpers.d.ts +344 -0
  310. package/dist/testing/index.d.ts +13 -0
  311. package/dist/testing/index.js +1 -0
  312. package/dist/testing/processes.d.ts +13 -0
  313. package/dist/testing/sandbox.d.ts +71 -0
  314. package/dist/testing/settlement.d.ts +6 -0
  315. package/dist/testing/tmpDirs.d.ts +17 -0
  316. package/dist/util/async.d.ts +8 -0
  317. package/dist/util/diff.d.ts +25 -0
  318. package/dist/util/dispatch.d.ts +8 -0
  319. package/dist/util/errors.d.ts +28 -0
  320. package/dist/util/foldState.d.ts +17 -0
  321. package/dist/util/freeze.d.ts +2 -0
  322. package/dist/util/ids.d.ts +2 -0
  323. package/dist/util/json.d.ts +37 -0
  324. package/dist/util/log.d.ts +6 -0
  325. package/dist/util/text.d.ts +21 -0
  326. package/dist/util/version.d.ts +2 -0
  327. package/package.json +175 -3
@@ -0,0 +1,71 @@
1
+ import { z } from 'zod';
2
+ export declare const LIST_AGENTS_TOOL = "list_agents";
3
+ export declare const READ_AGENT_TOOL = "read_agent";
4
+ export declare const STOP_AGENT_TOOL = "stop_agent";
5
+ /**
6
+ * The tools the `delegations` plugin registers, granted to nobody: continuing, listing, reading and
7
+ * stopping the children a thread started, whichever tool started them. A preset grants them wherever
8
+ * it grants a start tool.
9
+ */
10
+ export declare const DELEGATION_TOOLS: readonly ["message_agent", "list_agents", "read_agent", "stop_agent"];
11
+ /**
12
+ * Validates a `message_agent` call, and is the source of the schema advertised to the model: one
13
+ * object, whose `kind` says which of the two gestures the call is. `background` and the route fields
14
+ * belong to `continue`; a steer naming one is refused as invalid arguments.
15
+ */
16
+ export declare const MessageAgentParameters: z.ZodPreprocess<z.ZodObject<{
17
+ thread_id: z.ZodString;
18
+ kind: z.ZodEnum<{
19
+ continue: "continue";
20
+ steer: "steer";
21
+ }>;
22
+ message: z.ZodString;
23
+ background: z.ZodDefault<z.ZodBoolean>;
24
+ provider: z.ZodDefault<z.ZodNullable<z.ZodString>>;
25
+ model: z.ZodDefault<z.ZodNullable<z.ZodString>>;
26
+ thinking_effort: z.ZodDefault<z.ZodNullable<z.ZodEnum<{
27
+ low: "low";
28
+ high: "high";
29
+ none: "none";
30
+ medium: "medium";
31
+ max: "max";
32
+ }>>>;
33
+ }, z.core.$strip>, unknown>;
34
+ /**
35
+ * Messages a child this thread created, whichever start tool made it; `kind` is required and kept
36
+ * across a re-dispatch, so a correction never becomes a new assignment.
37
+ *
38
+ * `continue` opens the child's next task, queued as plain input with the task's `started` row under
39
+ * an id derived from this call, and the child runs on its own history; blocking, it waits for the
40
+ * answer, and with `background` it returns a receipt. A fork is not framed as a fork task again.
41
+ * Refused without a turn when the id names no thread, a thread this one did not create, or a child
42
+ * that stopped mid-work or still has a task open; a child a run holds is refused busy. A
43
+ * re-dispatch returns the recorded answer, or the receipt, without judging the route again.
44
+ *
45
+ * `steer` queues a correction into the task the call addresses, by row order as `read_agent` and
46
+ * `stop_agent` do, while that task's own drive runs the child (`ctx.delegations.steer`), and returns
47
+ * at once; it is refused, naming the outcome, on a task that has ended, and naming the state on one
48
+ * nothing runs now, a child whose run has not started yet included: the call never waits for a run
49
+ * to start, since the caller's own run slot may be what that run waits for, and its model tries
50
+ * again later. A re-dispatch reports what became of the message it sent.
51
+ */
52
+ export declare const messageAgentTool: import("../../loop/tool.js").Tool;
53
+ /** `list_agents`: this thread's children, however they were started, from the catalog. */
54
+ export declare const listAgentsTool: import("../../loop/tool.js").Tool;
55
+ /**
56
+ * `read_agent`: each named child's addressed task, its state and, once it settled, its answer or
57
+ * its failure (a background task's only when its notice does not carry it, or with `full`), or
58
+ * before that its recent activity; and the child's status now. Waits through `ctx.delegations.read`,
59
+ * a durable wait that releases the caller's run slot, for any named task to settle, or with
60
+ * `activity` for any named child to record anything, until nothing can advance them or the time is
61
+ * up; dispatched again once that wait resolves, it reports where the tasks stand then.
62
+ */
63
+ export declare const readAgentTool: import("../../loop/tool.js").Tool;
64
+ /**
65
+ * `stop_agent`: stops the addressed task of a child this thread started, by `ctx.delegations.stop`
66
+ * with this call's seq, and returns once the stop is durable. A settled task keeps its outcome, and
67
+ * a late turn its run still runs is cut off; a newer task of the child is never touched. A rerun
68
+ * repeats its own reply: the `stopped` row names the call that wrote it. The reply also says what
69
+ * the child is doing now.
70
+ */
71
+ export declare const stopAgentTool: import("../../loop/tool.js").Tool;
@@ -0,0 +1,116 @@
1
+ import type { Context } from '@leuduan/cordis';
2
+ import { type Clock } from '../../kit/timers.js';
3
+ import type { JournalEvent } from '../../models/index.js';
4
+ import type { OwnerHandle } from '../../services/owner.js';
5
+ import type { NoticeDelivery } from './notices.js';
6
+ import { type ReadWait, type ReadWhy } from './waits.js';
7
+ /**
8
+ * Why a read wait returns now, or `null` while it waits: a named task ended (`settled`); with
9
+ * `activity`, a named child recorded a row after the read looked; nothing can advance a named open
10
+ * task (`no_progress`): none of their children runs, waits to run, or is held for something that
11
+ * passes, such as an approval, a wait of its own, the startup policy, a missing owner or a
12
+ * constraint. Read from the catalog and the owner, synchronously.
13
+ */
14
+ export declare function readCondition(ctx: Context, wait: ReadWait): ReadWhy | null;
15
+ /** What the book is handed by the service that mounts it. */
16
+ export type WaitBookOptions = {
17
+ /** The clock `read_agent`'s deadlines and the retries of failed decisions are kept on. */
18
+ readonly clock: Clock;
19
+ /** Resolves once the task state can be served: no decision is taken before. */
20
+ readonly ready: Promise<void>;
21
+ /** Whose notices a read that finds a task ended waits to be durable. */
22
+ readonly notices: NoticeDelivery;
23
+ /** The task constraint's registration, which resolves the waits; `undefined` while not registered. */
24
+ readonly constraint: () => OwnerHandle | undefined;
25
+ };
26
+ /**
27
+ * Every delegation wait, from its `wait/declared` row to its call's answer: the one owner of when a
28
+ * blocking call's or a `read_agent` call's wait resolves, and with what. A blocking call's wait
29
+ * resolves once its task's serving run settles, not handed on to a successor, or is held for a
30
+ * person's cancellation or a failure, with the answer chosen then; a read's once a named task ended,
31
+ * after that task's notice is durable, a named child recorded anything, nothing can advance them, or
32
+ * its deadline. The condition is read again inside the resolving write, which declines when it no
33
+ * longer holds.
34
+ *
35
+ * Its index is kept by rows alone, never by reading core's wait state: a declaration under
36
+ * delegations is booked, its resolution stops its deadline and its decisions, and its call's answer
37
+ * forgets it; any row or run event of a child a wait names decides that wait again. One decision at
38
+ * a time per wait: a trigger meanwhile is handed the one under way, and decides again after it. A
39
+ * decision that fails, reading or writing, is reported and taken again later, so a wait nothing else
40
+ * would trigger again is not lost with it. Its task's child is told whenever a blocking call starts
41
+ * or stops being its task's authority: as the wait is declared, and as the call is answered.
42
+ *
43
+ * The repair books every wait the catalog shows suspended on delegations, and decides at once those
44
+ * satisfied while the process was down; the drain stops deciding at shutdown, leaving what is due to
45
+ * the next startup's repair.
46
+ */
47
+ export declare class WaitBook {
48
+ /** Every delegation wait whose call is not answered yet, by caller and call. */
49
+ private readonly waits;
50
+ /** The unresolved waits by each child they name. */
51
+ private readonly waitsOn;
52
+ /** The decision under way for each wait, and the waits to decide again once it is done. */
53
+ private readonly checking;
54
+ private readonly recheck;
55
+ /** Decisions that failed, by wait: each is taken again later (`retryLater`). */
56
+ private readonly retries;
57
+ /** `read_agent`'s deadlines. */
58
+ private readonly deadlines;
59
+ private closing;
60
+ private readonly ctx;
61
+ private readonly options;
62
+ constructor(ctx: Context, options: WaitBookOptions);
63
+ /**
64
+ * What a row does to the book: a declaration naming delegations is booked; a resolution stops
65
+ * deciding its wait, and a result of a booked call forgets it, telling a blocking call's task's
66
+ * child, whose authority the call was; any row of a child a wait names decides that wait again, so
67
+ * `until: 'activity'` sees the row and a task that ended is seen at once.
68
+ */
69
+ onRow(event: JournalEvent): void;
70
+ /** Decides again every unresolved wait naming `threadId`, after a run event of it. */
71
+ onRunEvent(threadId: string): void;
72
+ /**
73
+ * The startup repair of delegation waits: every caller the catalog shows suspended on delegations
74
+ * is read, its waits booked, and the unresolved ones decided, so a read's deadline that passed
75
+ * meanwhile times out and a wait whose child finished while the process was down resolves now.
76
+ * Resolves once those writes have landed, so the startup policy judges their causes.
77
+ */
78
+ repair(): Promise<void>;
79
+ /** Stops deciding, so the next startup's repair decides what is due; resolves once each decision under way has landed. */
80
+ drain(): Promise<void>;
81
+ /**
82
+ * Books a declared delegation wait: indexed by its caller's call and, until it resolves, by each
83
+ * child it names, a read's deadline armed, and its condition checked at once, since the child may
84
+ * have finished first. Its task's child is told: the call waiting is now its task's authority. A
85
+ * wait the repair finds resolved is only kept until its call is answered.
86
+ */
87
+ private book;
88
+ /** Stops deciding a wait whose value is recorded: its call waits only to be dispatched again. */
89
+ private resolved;
90
+ /** Forgets a wait whose call was answered, resolved or not; a blocking call's task's child is told. */
91
+ private answered;
92
+ private stopDeciding;
93
+ /** Checks every unresolved wait naming `childId`, after a row or a run event of it. */
94
+ private checkWaitsOn;
95
+ /** Resolves the wait under `key` if its condition holds, one decision at a time; see the class. */
96
+ private check;
97
+ /** One decision of `check`. */
98
+ private resolveIfDue;
99
+ /** Takes a failed decision again later, while its wait is still decided. */
100
+ private retryLater;
101
+ /**
102
+ * Where a blocking task's serving run stands once it lets its call's wait resolve, or `null` while
103
+ * the call keeps waiting: settled, not handed on to a successor (the task fold follows the run
104
+ * while the task is open, so a settled serving run is the last); or held for a person's
105
+ * cancellation or a failure. It keeps waiting through every hold that passes, an approval or a
106
+ * startup decline included. Read at the owner's published boundary, never from a raw row.
107
+ */
108
+ private taskRun;
109
+ /**
110
+ * What a blocking call is told once its task's serving run lets its wait resolve: the task's
111
+ * outcome once it settled; otherwise why the task did not end, which the call's result then ends
112
+ * it for: a person's cancel of the child, a failure it is held on, or a run that settled with the
113
+ * task still open.
114
+ */
115
+ private taskOutcome;
116
+ }
@@ -0,0 +1,118 @@
1
+ import { z } from 'zod';
2
+ import type { ResolvedWait } from '../../loop/index.js';
3
+ import type { TaskRef } from './record.js';
4
+ import type { DelegationOutcome } from './request.js';
5
+ export declare const TaskWaitSchema: z.ZodObject<{
6
+ task_id: z.ZodString;
7
+ child_id: z.ZodString;
8
+ v: z.ZodLiteral<1>;
9
+ kind: z.ZodLiteral<"task">;
10
+ }, z.core.$strict>;
11
+ export type TaskWait = z.output<typeof TaskWaitSchema>;
12
+ export declare const ReadWaitSchema: z.ZodObject<{
13
+ v: z.ZodLiteral<1>;
14
+ kind: z.ZodLiteral<"read">;
15
+ tasks: z.ZodArray<z.ZodObject<{
16
+ task_id: z.ZodString;
17
+ child_id: z.ZodString;
18
+ }, z.core.$strict>>;
19
+ until: z.ZodEnum<{
20
+ settled: "settled";
21
+ activity: "activity";
22
+ }>;
23
+ since: z.ZodRecord<z.ZodString, z.ZodNumber>;
24
+ }, z.core.$strict>;
25
+ export type ReadWait = z.output<typeof ReadWaitSchema>;
26
+ /**
27
+ * What a delegating call waits on, as its `wait/declared` row records it, versioned by delegations:
28
+ * a blocking call waits on its `task`; `read_agent` on the first of its named tasks to settle, or
29
+ * with `until: 'activity'` to record anything after `since` (each child's `through_seq` as the call
30
+ * looked), until its deadline.
31
+ */
32
+ export declare const DelegationWaitSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
33
+ task_id: z.ZodString;
34
+ child_id: z.ZodString;
35
+ v: z.ZodLiteral<1>;
36
+ kind: z.ZodLiteral<"task">;
37
+ }, z.core.$strict>, z.ZodObject<{
38
+ v: z.ZodLiteral<1>;
39
+ kind: z.ZodLiteral<"read">;
40
+ tasks: z.ZodArray<z.ZodObject<{
41
+ task_id: z.ZodString;
42
+ child_id: z.ZodString;
43
+ }, z.core.$strict>>;
44
+ until: z.ZodEnum<{
45
+ settled: "settled";
46
+ activity: "activity";
47
+ }>;
48
+ since: z.ZodRecord<z.ZodString, z.ZodNumber>;
49
+ }, z.core.$strict>], "kind">;
50
+ export type DelegationWait = z.output<typeof DelegationWaitSchema>;
51
+ /**
52
+ * A blocking call's value: the answer chosen as its task's serving run settled, not handed on to a
53
+ * successor, or was held for a cancellation or a failure; and that run's state then. A later change
54
+ * of the task's state cannot change an answer recorded.
55
+ */
56
+ export declare const TaskValueSchema: z.ZodObject<{
57
+ v: z.ZodLiteral<1>;
58
+ kind: z.ZodLiteral<"task">;
59
+ outcome: z.ZodObject<{
60
+ status: z.ZodEnum<{
61
+ completed: "completed";
62
+ failed: "failed";
63
+ }>;
64
+ output: z.ZodString;
65
+ }, z.core.$strict>;
66
+ run_id: z.ZodString;
67
+ state: z.ZodEnum<{
68
+ settled: "settled";
69
+ held: "held";
70
+ }>;
71
+ reason: z.ZodString;
72
+ error_text: z.ZodNullable<z.ZodString>;
73
+ }, z.core.$strict>;
74
+ export type TaskValue = z.output<typeof TaskValueSchema>;
75
+ /**
76
+ * Why a `read_agent` wait returned: a named task ended (`settled`); a named child recorded anything,
77
+ * with `until: 'activity'`; nothing can advance a named open task (`no_progress`); or the deadline.
78
+ */
79
+ export declare const ReadWhySchema: z.ZodEnum<{
80
+ timeout: "timeout";
81
+ settled: "settled";
82
+ activity: "activity";
83
+ no_progress: "no_progress";
84
+ }>;
85
+ export type ReadWhy = z.output<typeof ReadWhySchema>;
86
+ export declare const ReadValueSchema: z.ZodObject<{
87
+ v: z.ZodLiteral<1>;
88
+ kind: z.ZodLiteral<"read">;
89
+ why: z.ZodEnum<{
90
+ timeout: "timeout";
91
+ settled: "settled";
92
+ activity: "activity";
93
+ no_progress: "no_progress";
94
+ }>;
95
+ }, z.core.$strict>;
96
+ /** A blocking call's dependency. */
97
+ export declare const taskWait: (task: TaskRef) => TaskWait;
98
+ /** A blocking call's value. */
99
+ export declare const taskValue: (outcome: DelegationOutcome, run: {
100
+ readonly runId: string;
101
+ readonly state: "settled" | "held";
102
+ readonly reason: string;
103
+ readonly errorText: string | null;
104
+ }) => TaskValue;
105
+ /** The children a wait names: a blocking call's task's, or each a read names. */
106
+ export declare const waitedOn: (wait: DelegationWait) => string[];
107
+ /** The tasks a read wait names, as task references. */
108
+ export declare const readTasks: (wait: ReadWait) => TaskRef[];
109
+ /** A blocking call's recorded answer, from the wait it resolved; throws on a payload of another version or kind. */
110
+ export declare function taskAnswer(wait: ResolvedWait): {
111
+ readonly childId: string;
112
+ readonly outcome: DelegationOutcome;
113
+ };
114
+ /** A `read_agent` call's resolved wait: the tasks it named, and why it returned. */
115
+ export declare function readAnswer(wait: ResolvedWait): {
116
+ readonly tasks: TaskRef[];
117
+ readonly why: ReadWhy;
118
+ };
@@ -0,0 +1,14 @@
1
+ import type { ConversationMessage } from '../../llm/index.js';
2
+ import { type DeepReadonly } from '../../util/json.js';
3
+ import type { SentModelRequest } from '../../loop/index.js';
4
+ /** Enough of a fingerprint to tell one value from another across restarts. */
5
+ export declare const digestOf: (text: string) => string;
6
+ /**
7
+ * A digest of everything a request sends ahead of its messages: the prompt,
8
+ * the tools and every option, the model included. Correlation, the ids and the purpose, is left
9
+ * out, so two threads sending the same head get the same digest — which is what a fork's prefix
10
+ * check compares.
11
+ */
12
+ export declare function headDigest(request: SentModelRequest): string;
13
+ /** A digest of a message list; a prefix of it digests the same as the same messages sent alone. */
14
+ export declare const messagesDigest: (messages: readonly DeepReadonly<ConversationMessage>[]) => string;
@@ -0,0 +1,68 @@
1
+ import type { Plugin } from '@leuduan/cordis';
2
+ import { z } from 'zod';
3
+ import type { PluginJournal } from '../../journal/index.js';
4
+ import type { RowRef } from '../../loop/index.js';
5
+ /**
6
+ * How a fork's first request compares with its source's request at the cut: whether it sent the
7
+ * same head and route, and extended the same messages. `unavailable` when there is nothing to
8
+ * compare with: the fork was cut before its source asked the model, or that request was never
9
+ * measured. Measured, not enforced: nothing sent is altered.
10
+ */
11
+ export declare const PrefixCheckSchema: z.ZodObject<{
12
+ status: z.ZodEnum<{
13
+ unavailable: "unavailable";
14
+ matched: "matched";
15
+ mismatched: "mismatched";
16
+ }>;
17
+ differs: z.ZodArray<z.ZodEnum<{
18
+ route: "route";
19
+ head: "head";
20
+ messages: "messages";
21
+ }>>;
22
+ replaced: z.ZodNullable<z.ZodNumber>;
23
+ }, z.core.$strict>;
24
+ export type PrefixCheck = z.infer<typeof PrefixCheckSchema>;
25
+ declare const MeasuresSchema: z.ZodObject<{
26
+ purpose: z.ZodEnum<{
27
+ step: "step";
28
+ auxiliary: "auxiliary";
29
+ }>;
30
+ system_prompt_chars: z.ZodNumber;
31
+ system_prompt_digest: z.ZodString;
32
+ head_digest: z.ZodString;
33
+ messages_digest: z.ZodString;
34
+ prefix_check: z.ZodNullable<z.ZodObject<{
35
+ status: z.ZodEnum<{
36
+ unavailable: "unavailable";
37
+ matched: "matched";
38
+ mismatched: "mismatched";
39
+ }>;
40
+ differs: z.ZodArray<z.ZodEnum<{
41
+ route: "route";
42
+ head: "head";
43
+ messages: "messages";
44
+ }>>;
45
+ replaced: z.ZodNullable<z.ZodNumber>;
46
+ }, z.core.$strict>>;
47
+ }, z.core.$strict>;
48
+ /** What the plugin measured of one request. */
49
+ export type RequestMeasures = z.output<typeof MeasuresSchema>;
50
+ /**
51
+ * Measures every model request a thread sends, through `lagent/llm/sent`, and records it as an `ext`
52
+ * row citing the request row: the prompt's size and digest, a digest of the head, one of the
53
+ * messages, and on a fork's first model step how it compares with its source's request at the cut,
54
+ * which tells whether it can reuse the source's cached prefix. A mismatch with no replacement since
55
+ * the reference is reported. Mount it on the untagged application context.
56
+ *
57
+ * ```ts
58
+ * await root.plugin(diagnostics)
59
+ * ```
60
+ */
61
+ export declare const diagnostics: Plugin.Object<undefined>;
62
+ /**
63
+ * What was measured of the request recorded at `row`, or `undefined` when it was not: the plugin
64
+ * was not mounted then, or the request row is not loaded. Found on the request's own thread, by
65
+ * the citation, wherever it lies, since a fork cut at a request row is cut before its measures.
66
+ */
67
+ export declare function requestMeasures(journal: Pick<PluginJournal, 'rowsAfter'>, row: RowRef): RequestMeasures | undefined;
68
+ export {};
@@ -0,0 +1 @@
1
+ import{b as q}from"../../chunks/DRYAN665.js";import{d as y}from"../../chunks/2OSESBIL.js";import"../../chunks/YLNJXQ3Z.js";import"../../chunks/DDANMY45.js";import{d as c}from"../../chunks/37YOGDGY.js";import"../../chunks/KESCTXGO.js";import"../../chunks/TYTQRLTX.js";import{A as _}from"../../chunks/D7E6EWIE.js";import{z as r}from"zod";import{createHash as I}from"node:crypto";var m=e=>I("sha256").update(e).digest("hex").slice(0,12);function b(e){let{messages:s,agentName:t,threadId:a,llmCallId:o,purpose:n,...u}=e;return m(c(u))}var f=e=>m(c(e));var S=r.strictObject({status:r.enum(["matched","mismatched","unavailable"]),differs:r.array(r.enum(["head","route","messages"])),replaced:r.number().int().positive().nullable()}),j=r.strictObject({purpose:r.enum(["step","auxiliary"]),system_prompt_chars:r.number().int().nonnegative(),system_prompt_digest:r.string(),head_digest:r.string(),messages_digest:r.string(),prefix_check:S.nullable()}),x=q({plugin:"lagent:diagnostics",kind:"request",version:1,schema:j}),L={name:"lagent:diagnostics",inject:["journal"],apply(e){y(e,"diagnostics"),e.on("lagent/llm/sent",async({request:s,row:t})=>{let a=_(s.systemPrompt),o=b(s),n=t.type==="llm/request"?E(e.journal,t,o,s.messages):null;await x.append(e.journal,{purpose:s.purpose,system_prompt_chars:a.length,system_prompt_digest:m(a),head_digest:o,messages_digest:f(s.messages),prefix_check:n},{threadId:t.thread_id,sourceSeqs:[t.seq]}),n?.status==="mismatched"&&n.replaced===null&&e.reportError(new Error(`Thread ${t.thread_id}: a fork's first request differs from its source's in ${n.differs.join(", ")}`))})}};function D(e,s){for(let t of e.rowsAfter(s.threadId,s.seq)){if(!t.source_seqs.includes(s.seq))continue;let a=x.read(t);if(a!==void 0)return a}}function E(e,s,t,a){let o=e.rows(s.thread_id),n=o[0];if(n?.type!=="thread/spawned"||n.data.fork===null||o.some(i=>i.type==="llm/request"&&i.seq!==s.seq))return null;let{thread_id:u,seq:v}=n.data.fork,d=e.lineage(u,v).findLast(i=>i.type==="llm/request");if(d===void 0||d.type!=="llm/request")return k;let p=D(e,{threadId:d.thread_id,seq:d.seq});if(p===void 0)return k;let l=[];t!==p.head_digest&&l.push("head"),c(s.data.route)!==c(d.data.route)&&l.push("route");let g=d.data.message_count,h=null;return(a.length<g||f(a.slice(0,g))!==p.messages_digest)&&(l.push("messages"),h=e.lineage(s.thread_id).find(i=>i.type==="surface/replaced"&&i.seq>d.seq&&i.seq<s.seq)?.seq??null),{status:l.length===0?"matched":"mismatched",differs:l,replaced:h}}var k={status:"unavailable",differs:[],replaced:null};export{S as PrefixCheckSchema,L as diagnostics,D as requestMeasures};
@@ -0,0 +1,9 @@
1
+ import type { Journal } from '../../journal/index.js';
2
+ import type { Seq } from '../../models/index.js';
3
+ /**
4
+ * Every message that has ever been on a thread's surface, numbered from 1 in lineage order, by the
5
+ * row behind it. Stand-ins are not numbered, so a number never moves: not across compactions,
6
+ * reopening or forks, which share their source's numbers up to the cut. The one numbering a
7
+ * checkpoint's footer names messages by and recall reads them back by, so the two always agree.
8
+ */
9
+ export declare function historyNumbers(journal: Pick<Journal, 'lineage'>, threadId: string): Map<Seq, number>;
@@ -0,0 +1,31 @@
1
+ import type { Plugin } from '@leuduan/cordis';
2
+ import { z } from 'zod';
3
+ import { HISTORY_RECALL_TOOLS } from './tools.js';
4
+ export { HISTORY_RECALL_TOOLS };
5
+ /** Message numbering, which compaction's checkpoints and stand-ins cite as recall reads it back. */
6
+ export { historyNumbers } from './history.js';
7
+ /**
8
+ * The line a stand-in ends on when its agent has both tools: where to read the `count` replaced
9
+ * messages back, `first` being the number of the first of them. Written here, beside the tools it
10
+ * names, so the pointer and what it points at change together. The form for several is the longer.
11
+ */
12
+ export declare const renderRecall: (first: number, count: number) => string;
13
+ export declare const HistoryRecallConfigSchema: z.ZodObject<{
14
+ agents: z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodLiteral<"global">, z.ZodLiteral<"all">]>;
15
+ }, z.core.$strict>;
16
+ export type HistoryRecallConfig = z.input<typeof HistoryRecallConfigSchema>;
17
+ /**
18
+ * Registers `history_read` and `history_search`: read-only tools over the journal that bring back
19
+ * what a replacement condensed, by the message numbers a checkpoint names. Each reads the calling
20
+ * thread's own lineage, a fork's inherited rows included, and nothing of any other thread. They are
21
+ * advertised to the selected agents from a thread's first request, and answer that nothing has been
22
+ * condensed until something has. Independent of any strategy: it reads the journal, not how the
23
+ * surface was replaced. A strategy that sees `history_read` granted points its checkpoints at it.
24
+ *
25
+ * Mounted on the untagged application context only: the tools are one grant for every thread.
26
+ *
27
+ * ```ts
28
+ * await root.plugin(historyRecall, { agents: ['main_agent'] })
29
+ * ```
30
+ */
31
+ export declare const historyRecall: Plugin.Object<HistoryRecallConfig>;
@@ -0,0 +1 @@
1
+ import{a,b,c,d,e}from"../../chunks/UC3FVVJ2.js";import"../../chunks/NAOUTU7A.js";import"../../chunks/UKXMCHHT.js";import"../../chunks/2OSESBIL.js";import"../../chunks/YLNJXQ3Z.js";import"../../chunks/DDANMY45.js";import"../../chunks/37YOGDGY.js";import"../../chunks/KESCTXGO.js";import"../../chunks/TYTQRLTX.js";import"../../chunks/D7E6EWIE.js";export{b as HISTORY_RECALL_TOOLS,d as HistoryRecallConfigSchema,a as historyNumbers,e as historyRecall,c as renderRecall};
@@ -0,0 +1,34 @@
1
+ import type { PluginJournal } from '../../journal/index.js';
2
+ import { type MessageRole } from '../../llm/index.js';
3
+ /** One message that has been on a thread's surface, as recall shows it. */
4
+ export type HistoryMessage = {
5
+ /** Its history number: 1 for the first message the thread's conversation ever held. */
6
+ readonly number: number;
7
+ readonly role: MessageRole;
8
+ /** The tool a result answers; `null` for any other message. */
9
+ readonly name: string | null;
10
+ /** The message as rendered, without its header. */
11
+ readonly body: string;
12
+ /**
13
+ * Whether the surface no longer holds this message as itself: a replacement stands for it, as a
14
+ * span's checkpoint or a rewrite's shorter text.
15
+ */
16
+ readonly condensed: boolean;
17
+ };
18
+ /**
19
+ * Every message that has ever been on a thread's surface, in lineage order, numbered as
20
+ * `historyNumbers` numbers them and rendered as the model saw it: the same row-to-message logic the
21
+ * surface fold uses, with replacements ignored. A pure read over the journal: nothing here depends
22
+ * on how, or whether, the surface was ever replaced, except which messages `condensed` marks.
23
+ *
24
+ * A fork reads its source's rows up to its cut as its own, so it shares their numbers and text.
25
+ */
26
+ export declare function history(journal: Pick<PluginJournal, 'lineage' | 'state'>, threadId: string): HistoryMessage[];
27
+ /**
28
+ * A message in a transcript: its body in an envelope the code writes, which names its number, role
29
+ * and, for a result, its tool. A body cannot end the envelope or fake another, since every closing
30
+ * `</message` in it is turned into `<\/message`: nothing a message said speaks as the harness.
31
+ */
32
+ export declare const renderMessage: (message: HistoryMessage) => string;
33
+ /** A message named in a listing: `Message 5 (user)`, `Message 6 (tool read_file)`. */
34
+ export declare const describeMessage: (message: HistoryMessage) => string;
@@ -0,0 +1,4 @@
1
+ /** The tools the plugin grants, for a host's allowlist or an agent's tool list. */
2
+ export declare const HISTORY_RECALL_TOOLS: readonly ["history_read", "history_search"];
3
+ export declare const historyReadTool: import("../../loop/tool.js").Tool;
4
+ export declare const historySearchTool: import("../../loop/tool.js").Tool;
@@ -0,0 +1,36 @@
1
+ import type { Client } from '@modelcontextprotocol/sdk/client/index.js';
2
+ import { type Tool as RemoteTool } from '@modelcontextprotocol/sdk/types.js';
3
+ import { type ToolSpec } from '../../llm/index.js';
4
+ import type { McpConfig } from './config.js';
5
+ import type { UnexposableTool } from './errors.js';
6
+ /** One exposable tool: its lagent name, the definition the server listed, and the spec built from it. */
7
+ export type CatalogEntry = {
8
+ readonly name: string;
9
+ readonly remoteName: string;
10
+ readonly definition: RemoteTool;
11
+ readonly spec: ToolSpec;
12
+ /** Equal for equal definitions; a changed definition is a different tool. */
13
+ readonly fingerprint: string;
14
+ };
15
+ /** A complete, immutable snapshot of what a server offers, as lagent can expose it. */
16
+ export type Catalog = {
17
+ readonly entries: ReadonlyMap<string, CatalogEntry>;
18
+ readonly unexposable: readonly UnexposableTool[];
19
+ };
20
+ export declare const EMPTY_CATALOG: Catalog;
21
+ /**
22
+ * Every page of `tools/list`, requested directly. The SDK's `listTools()` replaces the client's
23
+ * validator and task caches on every page, and its list-changed refresh fetches only the first one.
24
+ */
25
+ export declare function listAllTools(client: Client, signal: AbortSignal): Promise<RemoteTool[]>;
26
+ /**
27
+ * What lagent can expose of a complete listing. With an allowlist only the listed tools are
28
+ * considered, under their aliases, and a listed tool the server does not offer is unexposable.
29
+ * Collisions are found over the whole listing, so the outcome never depends on how the server
30
+ * paged: every tool of a colliding group is unexposable.
31
+ */
32
+ export declare function buildCatalog(config: Pick<McpConfig, 'name' | 'tools'>, listed: readonly RemoteTool[]): Catalog;
33
+ /** Unexposable tools in one order, by tool and then reason, whatever order they were found in. */
34
+ export declare const sortUnexposable: (tools: readonly UnexposableTool[]) => UnexposableTool[];
35
+ /** Whether two reports of unexposable tools say the same thing. */
36
+ export declare const sameUnexposable: (left: readonly UnexposableTool[], right: readonly UnexposableTool[]) => boolean;
@@ -0,0 +1,63 @@
1
+ import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
2
+ import { z } from 'zod';
3
+ /**
4
+ * The longest server name: `mcp__` and `__` around it still leave 33 of the 64 characters a tool
5
+ * name may have for the tool segment.
6
+ */
7
+ export declare const MAX_SERVER_NAME_LENGTH = 24;
8
+ /**
9
+ * A factory for any SDK transport. A transport is single-use, so every connection asks for a new one.
10
+ * `signal` aborts when the opening is abandoned (its deadline, the owner's signal, disposal): stop
11
+ * working then. A transport that arrives after that is closed by the mount.
12
+ */
13
+ export type McpTransportFactory = (signal: AbortSignal) => Transport | Promise<Transport>;
14
+ export declare const McpTransportSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
15
+ kind: z.ZodLiteral<"stdio">;
16
+ command: z.ZodTuple<[z.ZodString], z.ZodString>;
17
+ cwd: z.ZodString;
18
+ env: z.ZodRecord<z.ZodString, z.ZodString>;
19
+ }, z.core.$strict>, z.ZodObject<{
20
+ kind: z.ZodLiteral<"streamable-http">;
21
+ url: z.ZodURL;
22
+ headers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
23
+ }, z.core.$strict>, z.ZodObject<{
24
+ kind: z.ZodLiteral<"custom">;
25
+ create: z.ZodCustom<McpTransportFactory, McpTransportFactory>;
26
+ }, z.core.$strict>], "kind">;
27
+ export type McpTransportConfig = z.output<typeof McpTransportSchema>;
28
+ export declare const McpConfigSchema: z.ZodObject<{
29
+ name: z.ZodString;
30
+ transport: z.ZodDiscriminatedUnion<[z.ZodObject<{
31
+ kind: z.ZodLiteral<"stdio">;
32
+ command: z.ZodTuple<[z.ZodString], z.ZodString>;
33
+ cwd: z.ZodString;
34
+ env: z.ZodRecord<z.ZodString, z.ZodString>;
35
+ }, z.core.$strict>, z.ZodObject<{
36
+ kind: z.ZodLiteral<"streamable-http">;
37
+ url: z.ZodURL;
38
+ headers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
39
+ }, z.core.$strict>, z.ZodObject<{
40
+ kind: z.ZodLiteral<"custom">;
41
+ create: z.ZodCustom<McpTransportFactory, McpTransportFactory>;
42
+ }, z.core.$strict>], "kind">;
43
+ agents: z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodLiteral<"global">, z.ZodLiteral<"all">]>;
44
+ confirm: z.ZodUnion<readonly [z.ZodLiteral<"all">, z.ZodLiteral<"none">, z.ZodObject<{
45
+ except: z.ZodArray<z.ZodString>;
46
+ }, z.core.$strict>]>;
47
+ onInterrupted: z.ZodUnion<readonly [z.ZodLiteral<"report">, z.ZodLiteral<"annotations">, z.ZodObject<{
48
+ rerun: z.ZodArray<z.ZodString>;
49
+ }, z.core.$strict>]>;
50
+ maxConcurrentCalls: z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unbounded">]>;
51
+ tools: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
52
+ name: z.ZodString;
53
+ as: z.ZodString;
54
+ }, z.core.$strict>]>>>;
55
+ instructions: z.ZodDefault<z.ZodBoolean>;
56
+ connectTimeoutSeconds: z.ZodDefault<z.ZodNumber>;
57
+ callTimeoutSeconds: z.ZodDefault<z.ZodNumber>;
58
+ maxCallSeconds: z.ZodDefault<z.ZodNumber>;
59
+ maxContentBytes: z.ZodDefault<z.ZodNumber>;
60
+ signal: z.ZodOptional<z.ZodCustom<AbortSignal, AbortSignal>>;
61
+ }, z.core.$strict>;
62
+ export type McpConfig = z.output<typeof McpConfigSchema>;
63
+ export type McpConfigInput = z.input<typeof McpConfigSchema>;
@@ -0,0 +1,53 @@
1
+ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
2
+ import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
3
+ import type { McpTransportConfig } from './config.js';
4
+ /** One successful initialization: a client, its transport, and the server's instructions. */
5
+ export type Generation = {
6
+ readonly number: number;
7
+ readonly client: Client;
8
+ readonly transport: Transport;
9
+ readonly instructions: string | null;
10
+ /** False once the transport closed or the session ended; a dead generation is never reused. */
11
+ alive: boolean;
12
+ };
13
+ export type ConnectionOptions = {
14
+ readonly server: string;
15
+ readonly transport: McpTransportConfig;
16
+ /** The mount's lifetime: aborting it stops a stdio server's group. */
17
+ readonly lifetime: AbortSignal;
18
+ /** The live generation's server says its tools changed. */
19
+ readonly onToolsChanged: (generation: Generation) => void;
20
+ /** The live generation went away on its own. */
21
+ readonly onLost: (generation: Generation, reason: string) => void;
22
+ };
23
+ /**
24
+ * The transport, initialization and lifetime of one server's connection. Each successful
25
+ * initialization is a new generation; whoever holds one can tell whether it is still the live one.
26
+ * The client declares no capabilities, so the server can ask it for nothing: no sampling,
27
+ * elicitation or roots.
28
+ */
29
+ export declare class McpConnection {
30
+ private live;
31
+ private count;
32
+ private disposed;
33
+ private readonly options;
34
+ constructor(options: ConnectionOptions);
35
+ /** The live generation, if there is one. */
36
+ get current(): Generation | null;
37
+ /**
38
+ * Connects and initializes a new generation, which becomes the live one. `signal` bounds the whole
39
+ * opening: creating the transport (a custom factory gets the signal), starting it, `initialize` and
40
+ * the `initialized` notification. The SDK bounds only `initialize`; the rest could wait for ever.
41
+ * On expiry the client is closed, which closes the transport and deletes an HTTP session the server
42
+ * already granted (`closeOnce`); a factory that answers after that has its result closed.
43
+ */
44
+ open(signal: AbortSignal, timeoutMs: number): Promise<Generation>;
45
+ /** Ends a generation the server no longer recognizes, such as a session it answered 404 for. */
46
+ invalidate(generation: Generation): Promise<void>;
47
+ /** Ends the live generation: closing shuts a stdio server down and deletes an HTTP session (`closeOnce`). */
48
+ dispose(): Promise<void>;
49
+ private createTransport;
50
+ private describeClose;
51
+ }
52
+ /** Whether an error is the HTTP 404 a server answers for a session it ended. */
53
+ export declare const isSessionGone: (error: unknown) => boolean;