@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,219 @@
1
+ import { type ModelRoute } from '../../llm/provider.js';
2
+ import type { Journal } from '../../journal/index.js';
3
+ import { type BirthConflict } from '../../loop/index.js';
4
+ import { type BirthSpec, type ForkOpening, type FreshOpening, type RowRef, type WriteRows } from '../../state/index.js';
5
+ import type { InitialInstallation, Installation, JournalEventInput, Seq, ThreadEnvironment, ThreadInput, ThreadOrigin, ThreadSummary } from '../../records/journal.js';
6
+ import type { Wake } from '../../state/index.js';
7
+ import { type DeepReadonly, type ReadonlyJsonValue } from '../../util/json.js';
8
+ import type { InitialInstallationInput, PresetsService } from '../presets/installations.js';
9
+ /**
10
+ * What must match when a creation or fork finds its id taken: `identity` is the thread's agent,
11
+ * origin and whether it is a fork, and for a fork its cut; `configuration` also compares the
12
+ * birth the request resolves to with the one recorded.
13
+ */
14
+ export type Reuse = 'identity' | 'configuration';
15
+ /**
16
+ * What a new thread's opening write carries beside its spawn row, the same for `create` and `fork`:
17
+ * one group, so the thread never exists without them. All of it is creation-only: a thread found
18
+ * again under its id gets none, whichever {@link Reuse} the request names.
19
+ */
20
+ export type Opening = {
21
+ /** The caller chooses the id once per creation and reuses it on retries. */
22
+ id: string;
23
+ /** Never inherited by a fork: application markers belong to the thread they were written on. */
24
+ metadata?: Readonly<Record<string, ReadonlyJsonValue>>;
25
+ /**
26
+ * The thread's first input, queued for a turn of its own. A fork created with one owes only it,
27
+ * not a reply to the conversation it inherited, until a step claims it.
28
+ */
29
+ input?: ThreadInput;
30
+ /** The first input's id, for idempotent re-dispatch; a fresh one when omitted. */
31
+ inputId?: string;
32
+ /** Plugin rows for the same group, or a veto that rejects the creation with its refusal; see {@link WriteRows}. */
33
+ rows?: WriteRows;
34
+ /**
35
+ * A cause in the same group asking the new thread to run, naming its first input, as `send`'s
36
+ * `wake`: how a delegation authorizes a new child's task in the write that opens it. It states no
37
+ * route: the thread is born on its own.
38
+ */
39
+ wake?: Wake;
40
+ };
41
+ /**
42
+ * What a fresh thread is born with, as a request states it. Each field `defaults` or `caller`
43
+ * leaves out is filled from that source; `exact` states a whole {@link BirthSpec} instead.
44
+ */
45
+ export type BirthInput<I> = {
46
+ /**
47
+ * The route the thread is born on, complete: required, since which model a conversation runs on
48
+ * is the caller's choice. A later change travels with a cause's route statement.
49
+ */
50
+ route: ModelRoute;
51
+ /**
52
+ * Where the thread's work happens, field by field. An omitted field is the default: the root's
53
+ * `cwd`, or with `caller` the caller's. The cwd must be absolute.
54
+ */
55
+ environment?: Partial<DeepReadonly<ThreadEnvironment>>;
56
+ /**
57
+ * Preset installations the thread is born with, recorded in its spawn row, so the thread never
58
+ * exists without them and a fork cut anywhere inherits them, each with its lifetime: a `defining`
59
+ * one is never removed, a `configurable` one changes through `Thread.configure` as one applied
60
+ * later does. Validated as a configuration change validates, a preset that defines its thread's
61
+ * agent must define this one, and a creation preset must be `defining`. With `caller`, the
62
+ * installations the caller's live scope hands down follow these, as defining ones.
63
+ */
64
+ installations?: readonly I[];
65
+ /**
66
+ * The constraint owners, by plugin name, that every run of the thread is under: a run waits while
67
+ * one is not registered and repaired, and so does a run of every thread created under it by
68
+ * origin, which records only its own. A set: sorted and deduplicated when recorded.
69
+ */
70
+ requires?: readonly string[];
71
+ };
72
+ /**
73
+ * Where a fresh thread's configuration comes from, and its origin: where the thread came from, in
74
+ * the shape a summary records it, immutable once recorded; creation refuses one whose cited row is
75
+ * not the caller's (`origins.validate`).
76
+ *
77
+ * - `defaults`: fields left out come from core's configuration.
78
+ * - `caller`: fields left out come from the caller, plus what its live scope hands down; the caller
79
+ * must have a live activation, whatever the origin's cause.
80
+ * - `exact`: reads nothing from the caller or core: the spec is the birth.
81
+ */
82
+ export type BirthChoice<I> = {
83
+ origin?: ThreadOrigin;
84
+ birth: {
85
+ from: 'defaults';
86
+ } & BirthInput<I>;
87
+ } | {
88
+ origin: ThreadOrigin;
89
+ birth: {
90
+ from: 'caller';
91
+ } & BirthInput<I>;
92
+ } | {
93
+ origin?: ThreadOrigin;
94
+ birth: {
95
+ from: 'exact';
96
+ spec: BirthSpec;
97
+ };
98
+ };
99
+ /**
100
+ * How `create` starts a thread: its {@link Opening}, a {@link BirthChoice} and a {@link Reuse},
101
+ * both required, with no default. `caller` goes with `identity` only: comparing a birth that came
102
+ * from the caller's live hand-downs would not be a comparison of birth facts. Under `configuration`
103
+ * installations must be named, since generated ids cannot compare.
104
+ */
105
+ export type CreateThreadOptions = Opening & (({
106
+ reuse: 'identity';
107
+ } & BirthChoice<InitialInstallationInput>) | ({
108
+ reuse: 'configuration';
109
+ } & Exclude<BirthChoice<InitialInstallationInput & {
110
+ installationId: string;
111
+ }>, {
112
+ birth: {
113
+ from: 'caller';
114
+ };
115
+ }>));
116
+ /**
117
+ * Where a fork is cut. `at` names the row itself: a `thread/spawned`, `turn/start`, `llm/request`
118
+ * or `turn/end` row of the source's lineage, as a bare seq or as the `{ threadId, seq }` pair the
119
+ * thread helpers return. `atTurn` names any row of the lineage and cuts at the end of the turn
120
+ * holding it, or with `before`, just ahead of the turn, at its `turn/start`: edit and resend, with
121
+ * `input` in the turn's place, which `before` therefore requires. A turn that has not ended cannot
122
+ * be cut at its end.
123
+ */
124
+ export type ForkCut = {
125
+ at: Seq | RowRef;
126
+ atTurn?: never;
127
+ before?: never;
128
+ } | {
129
+ atTurn: Seq | RowRef;
130
+ before?: boolean;
131
+ at?: never;
132
+ };
133
+ /**
134
+ * How to fork a thread; see {@link ThreadsService.fork}. A fork inherits its route and installations
135
+ * at the cut; `reuse` is required: `identity` is the cut, agent and origin, `configuration` also
136
+ * the fork's own environment and `requires`.
137
+ */
138
+ export type ForkOptions = Opening & ForkCut & {
139
+ reuse: Reuse;
140
+ /** Set by a delegating tool; a fork someone asks for directly has none and is a root. */
141
+ origin?: ThreadOrigin;
142
+ /**
143
+ * The environment of the thread `fork` is called on, field by field, where omitted — also when the
144
+ * cut is redirected to an ancestor, whose working directory may differ.
145
+ */
146
+ environment?: Partial<DeepReadonly<ThreadEnvironment>>;
147
+ /** The constraint owners the fork's runs are under, as {@link BirthInput.requires}. None when omitted. */
148
+ requires?: readonly string[];
149
+ };
150
+ /** What resolving a birth reads from outside its options. */
151
+ export type BirthContext = {
152
+ readonly journal: Journal;
153
+ readonly presets: PresetsService;
154
+ /** The `environment.cwd` a thread created without one gets. */
155
+ readonly defaultCwd: string;
156
+ /**
157
+ * The installations the live scope of caller `callerId` hands down to a child on `agent`, refused
158
+ * when the caller has no live activation: its plugins could not say what the child is born with.
159
+ */
160
+ readonly handedDown: (agent: string, own: readonly Installation[], callerId: string) => InitialInstallation[];
161
+ };
162
+ /**
163
+ * A resolved opening: what a creation or fork records, built once and used for validation,
164
+ * comparison, a write-time callback's payload and the spawn row.
165
+ */
166
+ export type ResolvedOpening = {
167
+ readonly kind: 'fresh';
168
+ readonly opening: FreshOpening;
169
+ } | {
170
+ readonly kind: 'fork';
171
+ readonly opening: ForkOpening;
172
+ };
173
+ /** Constraint owners as a spawn row records them: a set, sorted and without repeats. */
174
+ export declare const canonicalRequires: (requires: readonly string[] | undefined) => string[];
175
+ /**
176
+ * Resolves a fresh creation's birth, validated before anything is appended. `origin` is the
177
+ * validated one (`null` for a root). Under `configuration` reuse every installation must name its
178
+ * id: a generated one could never compare.
179
+ */
180
+ export declare function resolveFresh(context: BirthContext, args: {
181
+ agent: string;
182
+ origin: ThreadOrigin | null;
183
+ birth: CreateThreadOptions['birth'];
184
+ reuse: Reuse;
185
+ }): FreshOpening;
186
+ /**
187
+ * Resolves a fork's own configuration: its environment, field by field from `options`, else from the
188
+ * thread `fork` was called on (`named`, even when the cut redirects to an ancestor), and its
189
+ * constraint owners. The route and installations are the cut's, never stated.
190
+ */
191
+ export declare function resolveForkOwn(named: ThreadSummary, options: Pick<ForkOptions, 'environment' | 'requires'>): {
192
+ environment: ThreadEnvironment;
193
+ requires: string[];
194
+ };
195
+ /** What a fork goes on with from its cut and does not record: the route and installations as the lineage folds to there. */
196
+ export declare function inheritsAt(journal: Journal, cut: RowRef): ForkOpening['inherits'];
197
+ /** The spawn row a resolved opening records. */
198
+ export declare function spawnRow(resolved: ResolvedOpening, metadata: NonNullable<Opening['metadata']>): JournalEventInput['thread/spawned'];
199
+ /** What a request must match of an existing thread by identity: its agent, origin and kind, and for a fork its cut. */
200
+ export type Identity = {
201
+ readonly kind: 'fresh' | 'fork';
202
+ readonly agent: string;
203
+ readonly origin: ThreadOrigin | null;
204
+ readonly cut?: RowRef;
205
+ };
206
+ /**
207
+ * What differs between an existing thread and the identity a request asks for: its agent, its
208
+ * origin, whether it is a fork, and for a fork its cut. The origin is compared as the request states it.
209
+ */
210
+ export declare function identityConflicts(summary: ThreadSummary, requested: Identity): BirthConflict[];
211
+ /**
212
+ * What differs between a fresh birth's recorded spawn row and the birth requested: route,
213
+ * environment, installations and `requires`, the last as a set. Installation order is significant.
214
+ */
215
+ export declare function specConflicts(spawn: JournalEventInput['thread/spawned'], requested: BirthSpec): BirthConflict[];
216
+ /** What differs between a fork's recorded own configuration and the one requested. */
217
+ export declare function forkConflicts(summary: ThreadSummary, requested: Pick<ForkOpening, 'environment' | 'requires'>): BirthConflict[];
218
+ /** Throws {@link BirthConflictError} when `conflicts` is not empty. */
219
+ export declare function requireNoConflicts(threadId: string, conflicts: readonly BirthConflict[]): void;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * What the rest of the package uses of `services/threads/`: the thread handle and its read view, run
3
+ * events, run-owner registration and the creation and fork shapes. Code outside this folder imports
4
+ * from here; `admission.ts`, `activation.ts` and the run owner's internals stay private to it.
5
+ */
6
+ export { ThreadsService } from './service.js';
7
+ export type { ConfigurationChange, ConfigurationResult, RetainOptions, RetainedMembers, Retention, ThreadFilter, Threads, ThreadsConfig, } from './service.js';
8
+ export type { Thread } from './thread.js';
9
+ export type { CancelOptions, ConfirmationAnswer } from './thread.js';
10
+ export type { ThreadView } from './view.js';
11
+ export type { BirthChoice, BirthInput, CreateThreadOptions, ForkCut, ForkOptions, Opening, Reuse } from './birth.js';
12
+ export type { MissingDetail, OwnerHandle, OwnerReadiness, OwnerRegistration, StartOptions, StartupPolicy, ThreadInspection, WaitResolution, WaitValue, } from './runOwner.js';
13
+ export { UnknownRunError, heldOrSettled, waitForRun } from './runEvents.js';
14
+ export type { RunEvent, RunSource, RunState } from './runEvents.js';
@@ -0,0 +1,79 @@
1
+ import type { RunOutcomeKind, RunSettledReason } from '../../records/journal.js';
2
+ import type { DurableRunState, Hold, HoldBasis } from '../../state/index.js';
3
+ /**
4
+ * Where one run request stands, as its waiters see it: waiting to be admitted (`requested`), with
5
+ * an execution serving it (`running`, finalization included), held with the request still pending,
6
+ * or settled. A held run carries its structured `hold` and the `basis` it was read on, an immutable
7
+ * observation at publication, not a snapshot of the thread. `{ reason: 'shutdown' }` is what a
8
+ * waiter is told when the application closes under it.
9
+ */
10
+ export type RunState = {
11
+ readonly state: 'requested';
12
+ } | {
13
+ readonly state: 'running';
14
+ } | {
15
+ readonly state: 'held';
16
+ readonly hold: Hold;
17
+ readonly basis: HoldBasis;
18
+ } | {
19
+ readonly state: 'settled';
20
+ readonly outcome: RunOutcomeKind;
21
+ readonly reason: RunSettledReason;
22
+ readonly errorText: string | null;
23
+ };
24
+ /**
25
+ * One change of a run's state, published as it happens: `requested` once its cause is durable,
26
+ * `running` at admission, and `held` or `settled` only after the execution's finalization and its
27
+ * release of the thread, so nothing that reads it can still find the execution running.
28
+ */
29
+ export type RunEvent = {
30
+ readonly threadId: string;
31
+ readonly runId: string;
32
+ } & RunState;
33
+ /**
34
+ * The read rule, the same as the events': a run an execution serves is `running` until that
35
+ * execution releases the thread, even when its settlement row is already durable; a settled run
36
+ * with no live execution is its settlement; a pending one is what the owner's current decision for
37
+ * it says, `held` with its hold or `requested`, since holds have no rows to read. `null` for a
38
+ * run the reader does not know: one the thread never had, or, on a thread out of memory, one older
39
+ * than its pending run and its latest settlement, which its catalog entry does not keep.
40
+ */
41
+ export declare function readRunState(facts: {
42
+ readonly durable: DurableRunState;
43
+ /** Whether an execution serving this run holds the thread now. */
44
+ readonly executing: boolean;
45
+ /** The hold the owner currently reads on the thread's pending request, `null` when it has none to say. */
46
+ readonly held: {
47
+ readonly hold: Hold;
48
+ readonly basis: HoldBasis;
49
+ } | null;
50
+ }): RunState | null;
51
+ /** Where a waiter reads runs from: the event stream, and the read that follows the same rule. */
52
+ export type RunSource = {
53
+ onRunEvent(listener: (event: RunEvent) => void): () => void;
54
+ runState(threadId: string, runId: string): RunState | null;
55
+ };
56
+ /**
57
+ * A run a waiter named is unknown to the catalog: the thread never had it, or the thread is out of
58
+ * memory and the run is older than its pending run and its latest settlement. A read or a hold
59
+ * loads the thread, which knows its every run.
60
+ */
61
+ export declare class UnknownRunError extends Error {
62
+ readonly threadId: string;
63
+ readonly runId: string;
64
+ constructor(threadId: string, runId: string);
65
+ }
66
+ /**
67
+ * Waits until run `runId` on `threadId` reaches a state `until` accepts, and resolves with it, where
68
+ * `source` is `ctx.threads`. The wait is for that run: not for the input that asked for it to be
69
+ * answered, nor for the thread to go quiet, since a cause that lands while an execution finishes is
70
+ * carried to a successor request. `queued.runId` of a `send` names the run to wait for. It
71
+ * subscribes first and reads the state after, so a change that happened before the call is read,
72
+ * not missed; on each event of the run it reads again rather than trust the event, which may be
73
+ * stale by the time it is delivered. Rejects with the signal's reason when aborted (the run goes on),
74
+ * with {@link UnknownRunError} for a run unknown to the catalog, and with whatever the read or
75
+ * `until` threw; unsubscribes however it ends.
76
+ */
77
+ export declare function waitForRun(source: RunSource, threadId: string, runId: string, until: (state: RunState) => boolean, signal?: AbortSignal): Promise<RunState>;
78
+ /** What a caller waiting for a run's work to stop waits for: the run held or settled, as `waitForRun`'s `until`. */
79
+ export declare const heldOrSettled: (state: RunState) => boolean;