@leuduan/lagent 0.0.0-stage → 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 (328) hide show
  1. package/LICENSE +16 -0
  2. package/README.md +157 -2
  3. package/dist/chunks/2GCIWSOA.js +5 -0
  4. package/dist/chunks/2P47AHNK.js +7 -0
  5. package/dist/chunks/34KW6VNQ.js +1 -0
  6. package/dist/chunks/3UMZMPWW.js +1 -0
  7. package/dist/chunks/5IRF47YB.js +1 -0
  8. package/dist/chunks/6DRCKZ2C.js +1 -0
  9. package/dist/chunks/6FRNHMCV.js +1 -0
  10. package/dist/chunks/7LI64H5X.js +17 -0
  11. package/dist/chunks/7VAPNE3L.js +1 -0
  12. package/dist/chunks/ASSQZH3F.js +1 -0
  13. package/dist/chunks/B4FXK5ER.js +77 -0
  14. package/dist/chunks/BBCW2FZK.js +1 -0
  15. package/dist/chunks/BPRCULZH.js +1 -0
  16. package/dist/chunks/CANPZYTH.js +24 -0
  17. package/dist/chunks/CQEVREBT.js +1 -0
  18. package/dist/chunks/CUK7CGC7.js +1 -0
  19. package/dist/chunks/D4PQP5MA.js +3 -0
  20. package/dist/chunks/DDANMY45.js +3 -0
  21. package/dist/chunks/DDZ7YF26.js +1 -0
  22. package/dist/chunks/EMRB4KCN.js +6 -0
  23. package/dist/chunks/EPYQ5M3B.js +3 -0
  24. package/dist/chunks/FJLU4UH3.js +1 -0
  25. package/dist/chunks/G44LG6VL.js +1 -0
  26. package/dist/chunks/GGSVIIWJ.js +2 -0
  27. package/dist/chunks/HK6ZSONF.js +1 -0
  28. package/dist/chunks/IAAEP6VL.js +30 -0
  29. package/dist/chunks/JCTBX33H.js +36 -0
  30. package/dist/chunks/JFX2MXBA.js +4 -0
  31. package/dist/chunks/JFZZXVWD.js +15 -0
  32. package/dist/chunks/KUZCL2SH.js +1 -0
  33. package/dist/chunks/MHC6VPB4.js +7 -0
  34. package/dist/chunks/MMNNZCBO.js +5 -0
  35. package/dist/chunks/MNJ4SRF7.js +1 -0
  36. package/dist/chunks/N6IXG2VL.js +1 -0
  37. package/dist/chunks/OCBPT7KE.js +1 -0
  38. package/dist/chunks/OL5A6ITQ.js +1 -0
  39. package/dist/chunks/PUSUPTAT.js +1 -0
  40. package/dist/chunks/Q75FUN7D.js +2 -0
  41. package/dist/chunks/Q7S5LFGN.js +1 -0
  42. package/dist/chunks/RCIHV3KG.js +1 -0
  43. package/dist/chunks/S34ZA2R6.js +1 -0
  44. package/dist/chunks/SS3B5W34.js +12 -0
  45. package/dist/chunks/VYMT4TXD.js +1 -0
  46. package/dist/chunks/W57RW55W.js +1 -0
  47. package/dist/compositions/base.d.ts +11 -0
  48. package/dist/compositions/codex.d.ts +66 -0
  49. package/dist/compositions/codexPrompts.d.ts +56 -0
  50. package/dist/context.d.ts +109 -0
  51. package/dist/index.d.ts +55 -0
  52. package/dist/index.js +1 -0
  53. package/dist/journal/catalog.d.ts +112 -0
  54. package/dist/journal/forkChain.d.ts +16 -0
  55. package/dist/journal/index.d.ts +15 -0
  56. package/dist/journal/journal.d.ts +475 -0
  57. package/dist/journal/projection.d.ts +87 -0
  58. package/dist/journal/store.d.ts +181 -0
  59. package/dist/llm/client.d.ts +135 -0
  60. package/dist/llm/content.d.ts +52 -0
  61. package/dist/llm/failure.d.ts +82 -0
  62. package/dist/llm/index.d.ts +22 -0
  63. package/dist/llm/index.js +1 -0
  64. package/dist/llm/primitives.d.ts +286 -0
  65. package/dist/llm/prompt.d.ts +21 -0
  66. package/dist/llm/provider.d.ts +74 -0
  67. package/dist/llm/readLedger.d.ts +24 -0
  68. package/dist/llm/request.d.ts +58 -0
  69. package/dist/loop/agent.d.ts +18 -0
  70. package/dist/loop/authorization.d.ts +41 -0
  71. package/dist/loop/auxiliary.d.ts +58 -0
  72. package/dist/loop/chunks.d.ts +27 -0
  73. package/dist/loop/completion.d.ts +17 -0
  74. package/dist/loop/errors.d.ts +139 -0
  75. package/dist/loop/hooks.d.ts +274 -0
  76. package/dist/loop/index.d.ts +16 -0
  77. package/dist/loop/runner.d.ts +134 -0
  78. package/dist/loop/runtime.d.ts +76 -0
  79. package/dist/loop/strategy.d.ts +80 -0
  80. package/dist/loop/surfacePrepare.d.ts +30 -0
  81. package/dist/loop/tool.d.ts +106 -0
  82. package/dist/loop/toolCalls.d.ts +35 -0
  83. package/dist/plugin.d.ts +50 -0
  84. package/dist/plugin.js +1 -0
  85. package/dist/plugins/agentsMd.d.ts +80 -0
  86. package/dist/plugins/agentsMd.js +1 -0
  87. package/dist/plugins/ask/index.d.ts +26 -0
  88. package/dist/plugins/ask/index.js +1 -0
  89. package/dist/plugins/ask/service.d.ts +125 -0
  90. package/dist/plugins/ask/tools.d.ts +9 -0
  91. package/dist/plugins/commands/index.d.ts +43 -0
  92. package/dist/plugins/commands/index.js +1 -0
  93. package/dist/plugins/commands/output.d.ts +115 -0
  94. package/dist/plugins/commands/record.d.ts +558 -0
  95. package/dist/plugins/commands/service.d.ts +321 -0
  96. package/dist/plugins/commands/shell.d.ts +25 -0
  97. package/dist/plugins/commands/tools.d.ts +10 -0
  98. package/dist/plugins/compaction/checkpoint.d.ts +94 -0
  99. package/dist/plugins/compaction/config.d.ts +133 -0
  100. package/dist/plugins/compaction/estimate.d.ts +37 -0
  101. package/dist/plugins/compaction/index.d.ts +87 -0
  102. package/dist/plugins/compaction/index.js +7 -0
  103. package/dist/plugins/compaction/planner.d.ts +207 -0
  104. package/dist/plugins/compaction/prune.d.ts +9 -0
  105. package/dist/plugins/compaction/record.d.ts +227 -0
  106. package/dist/plugins/compaction/segments.d.ts +23 -0
  107. package/dist/plugins/compaction/state.d.ts +68 -0
  108. package/dist/plugins/compaction/summarize.d.ts +13 -0
  109. package/dist/plugins/dateAndBranch.d.ts +47 -0
  110. package/dist/plugins/dateAndBranch.js +1 -0
  111. package/dist/plugins/delegations/answers.d.ts +39 -0
  112. package/dist/plugins/delegations/assignmentKey.d.ts +22 -0
  113. package/dist/plugins/delegations/cleanup.d.ts +161 -0
  114. package/dist/plugins/delegations/constraint.d.ts +76 -0
  115. package/dist/plugins/delegations/index.d.ts +39 -0
  116. package/dist/plugins/delegations/index.js +1 -0
  117. package/dist/plugins/delegations/notices.d.ts +261 -0
  118. package/dist/plugins/delegations/obligations.d.ts +210 -0
  119. package/dist/plugins/delegations/record.d.ts +633 -0
  120. package/dist/plugins/delegations/request.d.ts +384 -0
  121. package/dist/plugins/delegations/role.d.ts +30 -0
  122. package/dist/plugins/delegations/service.d.ts +563 -0
  123. package/dist/plugins/delegations/standing.d.ts +19 -0
  124. package/dist/plugins/delegations/stopCheck.d.ts +21 -0
  125. package/dist/plugins/delegations/tools.d.ts +71 -0
  126. package/dist/plugins/delegations/waitContracts.d.ts +118 -0
  127. package/dist/plugins/delegations/waitResolver.d.ts +116 -0
  128. package/dist/plugins/diagnostics/digest.d.ts +14 -0
  129. package/dist/plugins/diagnostics/index.d.ts +68 -0
  130. package/dist/plugins/diagnostics/index.js +1 -0
  131. package/dist/plugins/fileTools/config.d.ts +10 -0
  132. package/dist/plugins/fileTools/editFiles.d.ts +117 -0
  133. package/dist/plugins/fileTools/fsRead.d.ts +17 -0
  134. package/dist/plugins/fileTools/gitDiscovery.d.ts +9 -0
  135. package/dist/plugins/fileTools/index.d.ts +18 -0
  136. package/dist/plugins/fileTools/index.js +1 -0
  137. package/dist/plugins/fileTools/ripgrep.d.ts +20 -0
  138. package/dist/plugins/fileTools/textEdit.d.ts +67 -0
  139. package/dist/plugins/fileTools/tools.d.ts +6 -0
  140. package/dist/plugins/historyRecall/history.d.ts +9 -0
  141. package/dist/plugins/historyRecall/index.d.ts +31 -0
  142. package/dist/plugins/historyRecall/index.js +1 -0
  143. package/dist/plugins/historyRecall/render.d.ts +34 -0
  144. package/dist/plugins/historyRecall/tools.d.ts +4 -0
  145. package/dist/plugins/mcp/catalog.d.ts +36 -0
  146. package/dist/plugins/mcp/config.d.ts +63 -0
  147. package/dist/plugins/mcp/connection.d.ts +53 -0
  148. package/dist/plugins/mcp/errors.d.ts +32 -0
  149. package/dist/plugins/mcp/index.d.ts +33 -0
  150. package/dist/plugins/mcp/index.js +5 -0
  151. package/dist/plugins/mcp/mount.d.ts +98 -0
  152. package/dist/plugins/mcp/names.d.ts +25 -0
  153. package/dist/plugins/mcp/render.d.ts +29 -0
  154. package/dist/plugins/mcp/slots.d.ts +15 -0
  155. package/dist/plugins/mcp/stdio.d.ts +49 -0
  156. package/dist/plugins/mcp/tools.d.ts +41 -0
  157. package/dist/plugins/mcp/version.d.ts +2 -0
  158. package/dist/plugins/routeNotice.d.ts +22 -0
  159. package/dist/plugins/routeNotice.js +1 -0
  160. package/dist/plugins/sandbox/absent.d.ts +33 -0
  161. package/dist/plugins/sandbox/client.d.ts +39 -0
  162. package/dist/plugins/sandbox/files.d.ts +28 -0
  163. package/dist/plugins/sandbox/index.d.ts +52 -0
  164. package/dist/plugins/sandbox/index.js +4 -0
  165. package/dist/plugins/sandbox/mode.d.ts +57 -0
  166. package/dist/plugins/sandbox/policy.d.ts +163 -0
  167. package/dist/plugins/sandbox/protocol.d.ts +107 -0
  168. package/dist/plugins/sandbox/service.d.ts +153 -0
  169. package/dist/plugins/sandbox/worker.d.ts +12 -0
  170. package/dist/plugins/sandbox/worker.js +1 -0
  171. package/dist/plugins/schedules/index.d.ts +21 -0
  172. package/dist/plugins/schedules/index.js +5 -0
  173. package/dist/plugins/schedules/record.d.ts +396 -0
  174. package/dist/plugins/schedules/service.d.ts +120 -0
  175. package/dist/plugins/schedules/time.d.ts +26 -0
  176. package/dist/plugins/schedules/tools.d.ts +6 -0
  177. package/dist/plugins/skills/discovery.d.ts +83 -0
  178. package/dist/plugins/skills/index.d.ts +31 -0
  179. package/dist/plugins/skills/index.js +1 -0
  180. package/dist/plugins/skills/tools.d.ts +11 -0
  181. package/dist/plugins/subAgents/availableRoutes.d.ts +53 -0
  182. package/dist/plugins/subAgents/index.d.ts +67 -0
  183. package/dist/plugins/subAgents/index.js +1 -0
  184. package/dist/plugins/subAgents/tools.d.ts +67 -0
  185. package/dist/plugins/threadDirs.d.ts +36 -0
  186. package/dist/plugins/threadDirs.js +1 -0
  187. package/dist/plugins/toolPolicy/index.d.ts +61 -0
  188. package/dist/plugins/toolPolicy/index.js +1 -0
  189. package/dist/plugins/truncateToolOutput.d.ts +30 -0
  190. package/dist/plugins/truncateToolOutput.js +6 -0
  191. package/dist/plugins/usage/index.d.ts +26 -0
  192. package/dist/plugins/usage/index.js +1 -0
  193. package/dist/plugins/usage/tracker.d.ts +34 -0
  194. package/dist/plugins/verify/index.d.ts +27 -0
  195. package/dist/plugins/verify/index.js +6 -0
  196. package/dist/plugins/verify/judgement.d.ts +16 -0
  197. package/dist/plugins/verify/record.d.ts +382 -0
  198. package/dist/plugins/verify/service.d.ts +93 -0
  199. package/dist/plugins/verify/state.d.ts +58 -0
  200. package/dist/plugins/webTools/html.d.ts +23 -0
  201. package/dist/plugins/webTools/index.d.ts +34 -0
  202. package/dist/plugins/webTools/index.js +1 -0
  203. package/dist/plugins/webTools/network.d.ts +23 -0
  204. package/dist/plugins/webTools/web.d.ts +32 -0
  205. package/dist/plugins/workflows/assignment.d.ts +20 -0
  206. package/dist/plugins/workflows/cleanup.d.ts +38 -0
  207. package/dist/plugins/workflows/definition.d.ts +184 -0
  208. package/dist/plugins/workflows/entryPlan.d.ts +95 -0
  209. package/dist/plugins/workflows/hostBindings.d.ts +146 -0
  210. package/dist/plugins/workflows/index.d.ts +28 -0
  211. package/dist/plugins/workflows/index.js +11 -0
  212. package/dist/plugins/workflows/observations.d.ts +81 -0
  213. package/dist/plugins/workflows/participantModels.d.ts +28 -0
  214. package/dist/plugins/workflows/participants.d.ts +143 -0
  215. package/dist/plugins/workflows/policy.d.ts +112 -0
  216. package/dist/plugins/workflows/record.d.ts +2849 -0
  217. package/dist/plugins/workflows/routing.d.ts +116 -0
  218. package/dist/plugins/workflows/schema.d.ts +26 -0
  219. package/dist/plugins/workflows/service.d.ts +477 -0
  220. package/dist/plugins/workflows/state.d.ts +373 -0
  221. package/dist/plugins/workflows/stopCheck.d.ts +13 -0
  222. package/dist/plugins/workflows/tools.d.ts +13 -0
  223. package/dist/plugins/workflows/view.d.ts +103 -0
  224. package/dist/plugins/workflows/workStatus.d.ts +21 -0
  225. package/dist/plugins/workspaceNotice.d.ts +36 -0
  226. package/dist/plugins/workspaceNotice.js +1 -0
  227. package/dist/providers/anthropic.d.ts +178 -0
  228. package/dist/providers/anthropicMessages.d.ts +66 -0
  229. package/dist/providers/codex.d.ts +71 -0
  230. package/dist/providers/codexAuth.d.ts +116 -0
  231. package/dist/providers/deepseek.d.ts +59 -0
  232. package/dist/providers/failure.d.ts +23 -0
  233. package/dist/providers/gateway.d.ts +24 -0
  234. package/dist/providers/index.d.ts +18 -0
  235. package/dist/providers/index.js +6 -0
  236. package/dist/providers/openaiChat.d.ts +73 -0
  237. package/dist/providers/openaiResponses.d.ts +109 -0
  238. package/dist/providers/opencodeCopilot.d.ts +23 -0
  239. package/dist/providers/opencodeGo.d.ts +109 -0
  240. package/dist/providers/shared.d.ts +112 -0
  241. package/dist/providers/stream.d.ts +156 -0
  242. package/dist/records/index.d.ts +13 -0
  243. package/dist/records/index.js +1 -0
  244. package/dist/records/journal.d.ts +2968 -0
  245. package/dist/records/toolResult.d.ts +65 -0
  246. package/dist/services/agents.d.ts +62 -0
  247. package/dist/services/catalogContributions.d.ts +73 -0
  248. package/dist/services/confinement/files.d.ts +118 -0
  249. package/dist/services/confinement/service.d.ts +219 -0
  250. package/dist/services/core.d.ts +28 -0
  251. package/dist/services/extensionEvents.d.ts +181 -0
  252. package/dist/services/journal.d.ts +26 -0
  253. package/dist/services/llm.d.ts +82 -0
  254. package/dist/services/modes.d.ts +65 -0
  255. package/dist/services/plugins.d.ts +34 -0
  256. package/dist/services/presets/definition.d.ts +154 -0
  257. package/dist/services/presets/installations.d.ts +139 -0
  258. package/dist/services/prompts.d.ts +85 -0
  259. package/dist/services/threads/activation.d.ts +100 -0
  260. package/dist/services/threads/admission.d.ts +174 -0
  261. package/dist/services/threads/birth.d.ts +219 -0
  262. package/dist/services/threads/index.d.ts +14 -0
  263. package/dist/services/threads/runEvents.d.ts +79 -0
  264. package/dist/services/threads/runOwner.d.ts +368 -0
  265. package/dist/services/threads/service.d.ts +450 -0
  266. package/dist/services/threads/thread.d.ts +268 -0
  267. package/dist/services/threads/view.d.ts +93 -0
  268. package/dist/services/tools.d.ts +118 -0
  269. package/dist/state/birth.d.ts +62 -0
  270. package/dist/state/chain.d.ts +46 -0
  271. package/dist/state/confirmations.d.ts +64 -0
  272. package/dist/state/continuation.d.ts +167 -0
  273. package/dist/state/decide.d.ts +72 -0
  274. package/dist/state/dispatches.d.ts +54 -0
  275. package/dist/state/errors.d.ts +26 -0
  276. package/dist/state/forks.d.ts +61 -0
  277. package/dist/state/holds.d.ts +104 -0
  278. package/dist/state/inbox.d.ts +188 -0
  279. package/dist/state/index.d.ts +31 -0
  280. package/dist/state/inputs.d.ts +58 -0
  281. package/dist/state/installations.d.ts +28 -0
  282. package/dist/state/limits.d.ts +14 -0
  283. package/dist/state/prompt.d.ts +13 -0
  284. package/dist/state/recovery.d.ts +7 -0
  285. package/dist/state/replace.d.ts +33 -0
  286. package/dist/state/requests.d.ts +129 -0
  287. package/dist/state/route.d.ts +61 -0
  288. package/dist/state/summary.d.ts +16 -0
  289. package/dist/state/surface.d.ts +153 -0
  290. package/dist/state/surfaceRead.d.ts +20 -0
  291. package/dist/state/thread.d.ts +73 -0
  292. package/dist/state/turns.d.ts +87 -0
  293. package/dist/state/waits.d.ts +38 -0
  294. package/dist/state/wake.d.ts +32 -0
  295. package/dist/stores/durableObject.d.ts +23 -0
  296. package/dist/stores/durableObject.js +1 -0
  297. package/dist/stores/durableObjectConnection.d.ts +27 -0
  298. package/dist/stores/memory.d.ts +29 -0
  299. package/dist/stores/sql.d.ts +59 -0
  300. package/dist/stores/sqlite.d.ts +31 -0
  301. package/dist/stores/sqlite.js +1 -0
  302. package/dist/sys/environment.d.ts +42 -0
  303. package/dist/sys/git.d.ts +47 -0
  304. package/dist/sys/paths.d.ts +9 -0
  305. package/dist/sys/spawn.d.ts +186 -0
  306. package/dist/testing/clock.d.ts +17 -0
  307. package/dist/testing/fakeLlm.d.ts +76 -0
  308. package/dist/testing/fedLlm.d.ts +34 -0
  309. package/dist/testing/helpers.d.ts +362 -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/settlement.d.ts +6 -0
  314. package/dist/testing/tmpDirs.d.ts +17 -0
  315. package/dist/util/async.d.ts +8 -0
  316. package/dist/util/diff.d.ts +25 -0
  317. package/dist/util/dispatch.d.ts +8 -0
  318. package/dist/util/errors.d.ts +28 -0
  319. package/dist/util/foldState.d.ts +17 -0
  320. package/dist/util/freeze.d.ts +2 -0
  321. package/dist/util/ids.d.ts +2 -0
  322. package/dist/util/json.d.ts +37 -0
  323. package/dist/util/jsonSchema.d.ts +7 -0
  324. package/dist/util/log.d.ts +6 -0
  325. package/dist/util/retries.d.ts +25 -0
  326. package/dist/util/text.d.ts +21 -0
  327. package/dist/util/timers.d.ts +43 -0
  328. package/package.json +183 -3
@@ -0,0 +1,450 @@
1
+ import { Context, Service, type ScopeKey } from '@leuduan/cordis';
2
+ import type { PromptBlock } from '../../llm/prompt.js';
3
+ import type { ChainStanding, ConfirmationState, RouteAuthority, Target, TurnLimits, BirthSpec, HoldBasis } from '../../state/index.js';
4
+ import type { CompactOptions, StreamedChunk, SurfacePrepareOutcome, BirthConflict } from '../../loop/index.js';
5
+ import { ChunkChannel } from '../../loop/index.js';
6
+ import type { ThreadOrigin } from '../../records/journal.js';
7
+ import { type DeepReadonly } from '../../util/json.js';
8
+ import { type OwnerHandle, type OwnerRegistration, type StartOptions, type ThreadInspection } from './runOwner.js';
9
+ import type { RunEvent, RunState } from './runEvents.js';
10
+ import type { InstallationInput } from '../presets/installations.js';
11
+ import { type CreateThreadOptions, type ForkOptions } from './birth.js';
12
+ import { Thread } from './thread.js';
13
+ import { ThreadView } from './view.js';
14
+ export type ThreadsConfig = {
15
+ /** Default `environment.cwd` for threads created without one; absolute. */
16
+ cwd: string;
17
+ /** The turn limits, resolved once by `core`, which hands the journal the same ones. */
18
+ limits: TurnLimits;
19
+ /**
20
+ * What becomes of a thread the owner loaded to run once its execution lets go and nothing else
21
+ * holds it: `retire` takes it out of memory, `keep` leaves it loaded. The application's choice.
22
+ */
23
+ retention: RetainOptions['lastRelease'];
24
+ /** How many reactive turns in a row a thread may run before its chain is at the limit. */
25
+ chainLimit: number;
26
+ };
27
+ /**
28
+ * A change to one thread's preset installations; see `Thread.configure`. Removals are recorded
29
+ * before applications, so a change that replaces an installation lists the old id in `remove` and
30
+ * the new one in `apply`.
31
+ */
32
+ export type ConfigurationChange = {
33
+ readonly apply?: readonly InstallationInput[];
34
+ /** Installation ids to take off; one not installed is no change. */
35
+ readonly remove?: readonly string[];
36
+ /**
37
+ * Render the recorded prompt again once the change is restored, the one way a preset's prompt
38
+ * sections reach a thread that has already run. A thread with no recorded prompt records one on
39
+ * its first run anyway.
40
+ */
41
+ readonly rebuildPrompt?: boolean;
42
+ };
43
+ /** What a configuration change did. */
44
+ export type ConfigurationResult = {
45
+ /** The id of every installation the change applies, in order, one applied before included. */
46
+ readonly applied: readonly string[];
47
+ /** The installations it took off. */
48
+ readonly removed: readonly string[];
49
+ };
50
+ export type ThreadFilter = {
51
+ /** Threads whose `origin` is this one, caller and cause alike. */
52
+ origin?: ThreadOrigin;
53
+ /** Threads a caller thread created, by any cause. */
54
+ callerThreadId?: string;
55
+ agentName?: string;
56
+ /**
57
+ * This thread, and every thread created under it at any depth, by `origin`, in spawn order. One
58
+ * catalog read; an unknown thread has nothing under it.
59
+ */
60
+ under?: string;
61
+ };
62
+ /**
63
+ * `ctx.threads` as an application sees it: the questions about the set of threads, and what starts
64
+ * one. Everything about one thread is on its {@link Thread}.
65
+ */
66
+ export interface Threads {
67
+ /**
68
+ * Aborts once lagent is closing: no thread is created, run or released after that. A refusal
69
+ * because lagent is closing throws `signal.reason` itself, so a host recognizes it by identity
70
+ * (`error === threads.signal.reason`), never by message.
71
+ */
72
+ readonly signal: AbortSignal;
73
+ /** The `environment.cwd` a thread created without one gets. */
74
+ readonly defaultCwd: string;
75
+ create(agentName: string, options: CreateThreadOptions): Promise<Thread>;
76
+ fork(sourceId: string, options: ForkOptions): Promise<Thread>;
77
+ get(threadId: string): Thread | undefined;
78
+ list(filter?: ThreadFilter): Thread[];
79
+ liveThreads(): Thread[];
80
+ /**
81
+ * Starts running threads, once, after the application composed its plugins and attached its
82
+ * observers: nothing runs before. Repairs the registered constraints' owners first, then runs the
83
+ * requests pending at boot that `resume` accepts, at most `startLimit` at once; the rest are held
84
+ * (`startup`) until a releasing cause. A second call is refused.
85
+ */
86
+ start(options: StartOptions): Promise<void>;
87
+ /**
88
+ * Where a thread stands: its state, current operation and primary hold, and what is behind a
89
+ * `missing` hold; `null` for an unknown thread. Synchronous: it admits nothing, changes no backoff
90
+ * and publishes nothing. `catalog` loads and activates nothing and reports the screening the
91
+ * catalog shows with this process's owners; `loaded` decides the hold from the thread's folds and
92
+ * throws unless the thread and the callers above it are loaded already.
93
+ */
94
+ inspect(threadId: string, options: {
95
+ readonly basis: HoldBasis;
96
+ }): ThreadInspection | null;
97
+ /** Every run's state changes, as {@link RunEvent}s. Returns the unsubscribe. */
98
+ onRunEvent(listener: (event: RunEvent) => void): () => void;
99
+ /**
100
+ * Where run `runId` of the thread stands, by the rule its events follow; `null` for a run it never
101
+ * had. Out of memory, a thread answers from its catalog entry, which knows its pending run and its
102
+ * latest settlement only: an older run reads `null` until the thread is loaded (a read or a hold).
103
+ */
104
+ runState(threadId: string, runId: string): RunState | null;
105
+ /**
106
+ * Where the thread's chain of unattended work stands: whether its open turn has a person's
107
+ * authority, how many reactive turns in a row it has run, and whether that reached the configured
108
+ * limit, which a producer of more unattended work (a background start, a notifying command)
109
+ * refuses at. Synchronous, by a caller that holds the thread, as `view` is.
110
+ */
111
+ chain(threadId: string): ChainStanding;
112
+ /**
113
+ * What differs between thread `threadId`'s recorded birth and `request`'s: the agent, that the
114
+ * thread is a fresh one and not a fork, then the route, environment, installations and `requires`
115
+ * its spawn row recorded, against the {@link BirthSpec} asked for. Empty when it is the same birth.
116
+ * The origin is not compared: an owner continuing its child on a later assignment checks the
117
+ * configuration it pinned for the participant. This is **birth** equality, read from the immutable
118
+ * spawn row outside any write, not the equality of the thread's current configuration. An unknown
119
+ * thread throws `UnknownThreadError`.
120
+ */
121
+ birthConflicts(threadId: string, request: {
122
+ agent: string;
123
+ spec: BirthSpec;
124
+ }): Promise<BirthConflict[]>;
125
+ /** Registers a feature as an owner, with its say over when its threads run; see {@link OwnerRegistration}. */
126
+ registerOwner(registration: OwnerRegistration): OwnerHandle;
127
+ pendingConfirmations(options?: {
128
+ under?: string;
129
+ }): Promise<DeepReadonly<ConfirmationState[]>>;
130
+ onChunk(listener: (chunk: StreamedChunk) => void): () => void;
131
+ retain(members: RetainedMembers, options: RetainOptions): Promise<Retention>;
132
+ /**
133
+ * What a thread's folds say, read synchronously by a caller that already holds the thread: inside
134
+ * a journal write or a contributor running for it, during its run, or under a retention. Loads
135
+ * nothing; a caller that holds nothing reads through `thread.read`. A view of a thread nothing
136
+ * holds may find it unloaded and throws `ThreadNotLoadedError`.
137
+ */
138
+ view(threadId: string): ThreadView;
139
+ }
140
+ /**
141
+ * A set of threads held in memory until `release()`; see `ctx.threads.retain`. Its members are
142
+ * read through `ctx.threads.view` while it holds them.
143
+ */
144
+ export interface Retention {
145
+ /** Gives the set back; see `RetainOptions.lastRelease`. Releasing twice does nothing. */
146
+ release(): void;
147
+ }
148
+ /**
149
+ * The threads a retention keeps in memory, as a function the engine asks for them: read at the
150
+ * start, to load them, and again at release and by every other retention's check, since the set a
151
+ * host means (a conversation and what it delegated to, say) can grow while it is held. A constant
152
+ * set is `() => ids`. A member that appears later is covered by the live check, not loaded.
153
+ */
154
+ export type RetainedMembers = () => Iterable<string>;
155
+ export type RetainOptions = {
156
+ /**
157
+ * What releasing this retention does to its members that no other retention covers: `retire`
158
+ * takes them out of memory, as `close()` does, once any operation holding one has settled; `keep`
159
+ * leaves them loaded. Named by the caller, since what to cache is the host's choice.
160
+ */
161
+ readonly lastRelease: 'retire' | 'keep';
162
+ };
163
+ /**
164
+ * Durable handles, live activations, and application-wide shutdown. Registry lookups stay live;
165
+ * journal operations never require an execution runtime. Every question about the set of threads —
166
+ * listing, finding, lineage, what needs resuming — is answered from the journal's catalog, so a
167
+ * thread's rows are in memory only once something reads or runs it.
168
+ */
169
+ export declare class ThreadsService extends Service<ThreadsConfig> {
170
+ static inject: string[];
171
+ readonly chunks: ChunkChannel;
172
+ readonly limits: TurnLimits;
173
+ readonly defaultCwd: string;
174
+ private readonly live;
175
+ /** The retentions not yet released, each with its membership as it reads now. */
176
+ private readonly retentions;
177
+ /** Retirements in flight, by thread: a new retention waits for one before it loads. */
178
+ private readonly retiring;
179
+ /** Which operation holds each thread; the handle and the activation are given its view at construction. */
180
+ private readonly admission;
181
+ /** When threads run: see {@link RunOwner}. */
182
+ private readonly owner;
183
+ private readonly retention;
184
+ private readonly chainLimit;
185
+ private readonly handles;
186
+ /** Threads whose corrupt history was reported; see `reportCorrupt`. */
187
+ private readonly reportedCorrupt;
188
+ private readonly controller;
189
+ private closing;
190
+ constructor(ctx: Context, config: ThreadsConfig);
191
+ /** See {@link Threads.signal}: refusals because lagent is closing throw this signal's reason itself. */
192
+ get signal(): AbortSignal;
193
+ /** Close execution admission and abort every loop before waiting for any one to finish. */
194
+ private shutdown;
195
+ /** Every thread in creation order, or those matching `filter`; from the catalog, loading nothing. */
196
+ list(filter?: ThreadFilter): Thread[];
197
+ get(threadId: string): Thread | undefined;
198
+ /** Threads with a live activation, running or not, in the order they activated. */
199
+ liveThreads(): Thread[];
200
+ start(options: StartOptions): Promise<void>;
201
+ inspect(threadId: string, { basis }: {
202
+ readonly basis: HoldBasis;
203
+ }): ThreadInspection | null;
204
+ onRunEvent(listener: (event: RunEvent) => void): () => void;
205
+ runState(threadId: string, runId: string): RunState | null;
206
+ chain(threadId: string): ChainStanding;
207
+ registerOwner(registration: OwnerRegistration): OwnerHandle;
208
+ /** The release as an admitted operation: the activation goes, then `after` runs, under one admission. */
209
+ private releaseUnder;
210
+ /**
211
+ * Keeps `members` loaded until the returned function is called. Releasing a `retire` retention
212
+ * then retires each of its members, its membership read again, that no other retention's current
213
+ * membership covers; releasing a `keep` one retires nothing. Waits for a retirement already in
214
+ * flight on a member before loading it, so a thread is never read as it is being dropped. A
215
+ * thread whose operation is admitted is retired once it settles; an ancestor a retained fork folds
216
+ * through stays, as the journal keeps it. Releasing twice does nothing, and once lagent is
217
+ * closing releasing only gives the hold back. `waitOn`, for the engine's own acquisition alone and
218
+ * not part of {@link RetainOptions}, names the members whose retirement in flight is waited for,
219
+ * all of them when omitted.
220
+ */
221
+ retain(members: RetainedMembers, options: RetainOptions & {
222
+ readonly waitOn?: readonly string[];
223
+ }): Promise<Retention>;
224
+ view(threadId: string): ThreadView;
225
+ /** The threads the retentions not yet released cover, by their membership as it reads now. */
226
+ private covered;
227
+ /**
228
+ * Takes a thread no retention covers out of memory: one retirement at a time per thread, after the
229
+ * operation admitted on it settles, and only if no retention covers it by then; refused quietly
230
+ * when an operation is admitted again meanwhile, since that operation's caller is reading it.
231
+ */
232
+ private retire;
233
+ /**
234
+ * Takes the thread out of the working set: releases an idle activation, then drops the thread's
235
+ * rows and folds from memory under the same admission, so nothing runs it in between; the catalog
236
+ * entry stays, and the next touch loads the thread again. The rows stay while a retention covers
237
+ * the thread, or a covered fork folds through it. Refused busy while an operation holds the
238
+ * thread. The threads it inherited from or delegated to are their own, closed on their own.
239
+ */
240
+ close(threadId: string): Promise<void>;
241
+ /**
242
+ * Starts a thread that continues `sourceId`'s conversation from the row `at`, on the same agent.
243
+ *
244
+ * The fork is one spawn row that names its source and cut; the journal folds the source's lineage
245
+ * up to there into every thread-scoped projection, so the fork inherits the conversation, the
246
+ * prompt, the route and plugin state without a copy, and nothing its source does later. What
247
+ * described the source's execution — queued input, calls in flight, usage — starts fresh.
248
+ *
249
+ * With `input`, the first input is queued in the same append, so the fork never exists without
250
+ * its task, and `rows` adds a plugin's rows to it or refuses it (see {@link Opening}). A cut at
251
+ * a row the source inherited is redirected to the thread that owns the row. Forking only reads
252
+ * the journal; the source may be running.
253
+ *
254
+ * Get-or-create, as `create` is: the recorded fork is returned when it matches by `reuse`, its
255
+ * resolved cut, agent and origin under `identity`, and also its own environment and `requires`
256
+ * under `configuration`; any other holder of the id throws `BirthConflictError`. Nothing else is
257
+ * compared or written.
258
+ */
259
+ fork(sourceId: string, options: ForkOptions): Promise<Thread>;
260
+ private forkHeld;
261
+ /** A fork found under its id: returned when it is the fork asked for, by its {@link Reuse}, else a conflict. */
262
+ private reuseFork;
263
+ /**
264
+ * A new thread's one group: its spawn row; its first input, if any, queued for a turn of its own
265
+ * and citing the spawn row, which is how a fork's folds tell its task from what it inherited; the
266
+ * cause its `wake` asks for, opening the thread's first run request; and last the rows the
267
+ * caller's `rows` adds, built inside the write. A veto of those rejects the creation, as a
268
+ * callback that threw does: the thread is never recorded.
269
+ */
270
+ private openingGroup;
271
+ /**
272
+ * Starts a thread on `agentName`, with its first input and a plugin's rows in the same append
273
+ * when given (see {@link Opening}). Get-or-create, the idempotent entry point a re-dispatched
274
+ * delegating call relies on.
275
+ *
276
+ * Two explicit choices say what is created and what an existing id must match. `birth.from` says
277
+ * where the thread's configuration comes from: `defaults` fills what is left out from core's
278
+ * configuration; `caller` from the origin's caller, whose live activation it requires, plus the
279
+ * installations its scope hands down; `exact` takes a whole spec and reads nothing. `reuse` says
280
+ * what an existing thread under the id must match to be returned: `identity`, its agent, origin and
281
+ * that it is not a fork, checked before anything of the request is resolved, or `configuration`,
282
+ * which also resolves the request and compares its birth with the recorded spawn row. A thread
283
+ * that does not match is never adopted: it throws {@link BirthConflictError}. Metadata, input,
284
+ * wake and rows apply to a new thread only; a write-time veto throws {@link WriteRefusedError}.
285
+ */
286
+ create(agentName: string, options: CreateThreadOptions): Promise<Thread>;
287
+ /** What resolving `threadId`'s birth reads beyond its options; see {@link BirthContext}. */
288
+ private birthContext;
289
+ /**
290
+ * A fresh creation's id already taken: the thread is returned when it is the one asked for. Its
291
+ * identity is always compared, and returned on, before the request is resolved or a live caller
292
+ * touched; under `configuration` reuse the request is resolved and its birth compared with the
293
+ * spawn row.
294
+ */
295
+ private reuseFresh;
296
+ /** What differs between `summary`'s recorded spawn row and the birth `spec`; read outside any write. */
297
+ private specConflictsOf;
298
+ birthConflicts(threadId: string, request: {
299
+ agent: string;
300
+ spec: BirthSpec;
301
+ }): Promise<BirthConflict[]>;
302
+ /**
303
+ * Requests waiting on the user: across every thread, or only on `under` and the threads created
304
+ * beneath it — the set one conversation's driver is responsible for answering. The threads that
305
+ * have any are found in the flushed catalog; only those are retained for the requests themselves,
306
+ * without activating plugins. Returns owned frozen snapshots and releases its retention even on failure.
307
+ */
308
+ pendingConfirmations(options?: {
309
+ under?: string;
310
+ }): Promise<DeepReadonly<ConfirmationState[]>>;
311
+ /**
312
+ * Loads a thread so its synchronous reads answer: its lineage — its own rows and those of the
313
+ * threads it was forked from — and the threads that called it, whose policies a running thread
314
+ * may read. A run, `compact()` and every write load what they need themselves; a host loads what
315
+ * it reads.
316
+ */
317
+ load(threadId: string): Promise<void>;
318
+ /**
319
+ * Reports, once per thread and process, a loaded thread whose surface refused a replacement: where
320
+ * its corrupt history is first seen. Nothing executes on it (`requireExecutable`).
321
+ */
322
+ private reportCorrupt;
323
+ /** Refuses to execute on a thread whose surface refused a replacement; it stays readable. */
324
+ private requireExecutable;
325
+ /** A thread and the threads that called it, out to its origin root: what a run of it reads. */
326
+ private readSet;
327
+ /**
328
+ * What an execution of `threadId`, a run or a compaction, reads, loaded and held for the whole of
329
+ * it: the thread and the callers out to its origin root, as they stand now, held by one retention
330
+ * that releases with `keep`, so the end of a child's run never retires a caller's activation. The
331
+ * callers are held loaded, never waited on: a retirement in flight is waited for on the thread
332
+ * alone, since a caller's own teardown may be waiting for this very execution. The release, once
333
+ * only, then retires the thread alone when the application's policy is `retire` and `retiring`
334
+ * says so, as a run's does; so does a failed acquisition, once the retention undid its holds. A
335
+ * compaction passes `retiring: false`: it releases every member with `keep`, so it never starts a
336
+ * retirement its own cleanup, or an activation's teardown reading the thread, could wait on. A
337
+ * retirement waits for the operation admitted on the thread to settle and is not started before.
338
+ * The one acquisition for an execution's reads: a storage or load failure is the caller's, a
339
+ * corrupt thread is `requireExecutable`'s to refuse.
340
+ */
341
+ private retainExecutionReads;
342
+ /** The model's output as it streams, on every thread. Returns the unsubscribe function. */
343
+ onChunk(listener: (chunk: StreamedChunk) => void): () => void;
344
+ /** `ancestorId` and every thread under it by `origin`, from the catalog. */
345
+ private subtreeIds;
346
+ /**
347
+ * The installations a new child is born with because its caller's scope hands them down, read
348
+ * from the caller's live activation, so only what the caller's own plugins declared applies.
349
+ */
350
+ private handedDown;
351
+ /**
352
+ * Changes a thread's preset installations as one operation; see `Thread.configure`. Validated,
353
+ * then admitted before anything is awaited (busy while another operation holds the thread,
354
+ * refused with `ThreadActivatingError` while the activation is still getting ready, and after
355
+ * shutdown), then decided against the installations as they stand: a change that records nothing,
356
+ * such as a retry, returns without touching the thread, even with a confirmation unfinished.
357
+ * Otherwise it is refused with `ThreadUnsettledError` for an unfinished confirmation, releases the live activation, records every installation change in
358
+ * one write decided again inside it, and restores the thread when it should.
359
+ */
360
+ configure(threadId: string, change: ConfigurationChange): Promise<ConfigurationResult>;
361
+ /** What a change may not be recorded under: shutdown, or a confirmation still unfinished (`ThreadUnsettledError`). */
362
+ private refuseRecording;
363
+ /**
364
+ * Throws `UnknownAgentError` for a global agent name that is not registered. A scoped name passes:
365
+ * only the thread's own installations can define it, and they are known once it is ready.
366
+ */
367
+ private requireGlobalAgent;
368
+ /**
369
+ * The origin `threadId` records, validated: a known caller within the delegation depth, citing a row
370
+ * of its lineage that is the cause it claims (`origins.validate`).
371
+ */
372
+ private originFor;
373
+ /** The prompt `threadId` would record if rendered now from `scope`, with the thread's plugins in it. */
374
+ private renderPrompt;
375
+ /** Records the thread's prompt the first time it is about to run; later turns reuse it. */
376
+ recordPromptOnce(scope: ScopeKey): Promise<void>;
377
+ /** Re-renders through the thread's activation, waiting for its plugins, and records the result. */
378
+ rebuildPrompt(threadId: string): Promise<PromptBlock[]>;
379
+ /**
380
+ * Activates the thread if need be and waits for its plugins. Readiness is a barrier, not an
381
+ * exclusive operation: a release or a configuration change in progress is waited for, since an
382
+ * activation on its way out is not ready, and the fresh one is then activated.
383
+ */
384
+ whenReady(threadId: string): Promise<void>;
385
+ /** The thread's live context, activating it; see `Thread.ctx`. */
386
+ contextOf(threadId: string): Context;
387
+ /** The current activation's signal, activating the thread; see `Thread.signal`. */
388
+ signalOf(threadId: string): AbortSignal;
389
+ private activate;
390
+ /**
391
+ * One execution of a run request under its admitted operation, the owner's to call: whatever the
392
+ * run reads is held (`retainExecutionReads`), and an interrupted turn is closed first, as a write,
393
+ * so it lands after any `send()` queued before this run, and what the run decides from is what
394
+ * that send left. The owner's continuation decision is asked at its entry and after every turn and
395
+ * recorded on `execution`, which the owner's finalization settles the request by. Resolves once
396
+ * the work is done, however it ended, a setup failure, settled as one, included; only a failure
397
+ * past its setup rejects.
398
+ */
399
+ private execute;
400
+ /**
401
+ * The thread's route as a statement is checked against, read where it is called: inside a write,
402
+ * as the write's rows stand. A route change is accepted only while no run serving the pending
403
+ * request holds the thread (a compaction does not count), and while no request is pending, the
404
+ * route cannot run, or the request is held by a failure or a cancellation (whatever else holds it):
405
+ * such a request runs only on a releasing cause, so changing its route moves nothing that is
406
+ * running or about to run. A runnable pending request is never moved under itself.
407
+ */
408
+ target(threadId: string): Target;
409
+ /** What checks every route statement, inside the write that records it: the one guard on route changes. */
410
+ readonly routes: RouteAuthority;
411
+ /**
412
+ * One request to prepare the surface; see `Thread.compact`. Cancellation owns it from this call:
413
+ * `cancel()`, the caller's signal or shutdown ends it at any point, and it then resolves
414
+ * `cancelled`, with nothing dispatched if it had not yet begun.
415
+ */
416
+ compact(threadId: string, options: CompactOptions): Promise<SurfacePrepareOutcome>;
417
+ /**
418
+ * Releases an activation whose setup failed while no operation held the thread; one that fails
419
+ * while an operation holds the thread is released by that operation as it settles. An operation
420
+ * admitted meanwhile waits for the disposal (`settledLive`) before it activates the thread again,
421
+ * so a retry never finds the failed scope's resources still held.
422
+ */
423
+ releaseFailed(threadId: string): Promise<void>;
424
+ /**
425
+ * The thread's activation for `operation`: one whose plugins changed since it was ready is
426
+ * released first, under the operation, marked as releasing so the scope's unload guard does not
427
+ * wait for it, and a fresh one is activated from the thread's listeners and installations.
428
+ */
429
+ private activationFor;
430
+ /** Resolves once the thread's activation, if one is being released, is gone: what every operation awaits before activating. */
431
+ private settledLive;
432
+ /** The loop's view of the registries, bound to one activation's scope. */
433
+ private loopServices;
434
+ /** The journal with core's writes, which the thread owner and the loop record through; never handed to a plugin. */
435
+ private get journal();
436
+ /**
437
+ * Runs `work` as an admitted operation other than a run, whose envelope is the owner's; see
438
+ * `Admission.hold`. An activation whose setup failed, or that went stale, could not be released
439
+ * while this operation held the thread: it is released as the operation's cleanup (`cleanup`).
440
+ */
441
+ private under;
442
+ /**
443
+ * The cleanup of every admitted operation, a run included, still under its admission: an
444
+ * activation whose setup failed, or that went stale, is released so a run meanwhile is busy and
445
+ * nothing activates afresh, in the releasing phase so the scope's unload guard does not wait for it.
446
+ */
447
+ private cleanup;
448
+ private requireThread;
449
+ private handle;
450
+ }