@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,139 @@
1
+ import { Service, type Context, type ScopeKey } from '@leuduan/cordis';
2
+ import type { InitialInstallation, Installation, InstallationLifetime } from '../../records/journal.js';
3
+ import { type AnyPreset } from './definition.js';
4
+ import type { Thread } from '../threads/index.js';
5
+ /**
6
+ * An installation a caller asks for, at creation (as an {@link InitialInstallationInput}) or later
7
+ * (`Thread.configure`).
8
+ */
9
+ export type InstallationInput = {
10
+ readonly presetId: string;
11
+ readonly config?: unknown;
12
+ /**
13
+ * Unique within the change or the creation; generated when omitted. Given, it makes a retried
14
+ * application idempotent. A removed id is never accepted again.
15
+ */
16
+ readonly installationId?: string;
17
+ };
18
+ /**
19
+ * An installation a thread is created with (`create`'s `installations`), with how long it lasts:
20
+ * `defining` ones are never removed, `configurable` ones are installations like any applied later.
21
+ * A creation preset is only ever `defining`.
22
+ */
23
+ export type InitialInstallationInput = InstallationInput & {
24
+ readonly lifetime: InstallationLifetime;
25
+ };
26
+ /**
27
+ * An installation a thread's scope hands down to every thread a call there creates; see
28
+ * {@link handDown}. The id is required: it is what keeps a hand-down from colliding with another in
29
+ * its layer or with the child's own installations.
30
+ */
31
+ export type HandDown = {
32
+ readonly presetId: string;
33
+ readonly config?: unknown;
34
+ readonly installationId: string;
35
+ };
36
+ /** What a configuration change records, decided against the thread's installations as they stand. */
37
+ export type ConfigurationPlan = {
38
+ readonly rows: readonly ({
39
+ type: 'installation/applied';
40
+ data: Installation;
41
+ options: {
42
+ threadId: string;
43
+ };
44
+ } | {
45
+ type: 'installation/removed';
46
+ data: {
47
+ installation_id: string;
48
+ };
49
+ options: {
50
+ threadId: string;
51
+ };
52
+ })[];
53
+ /** Every installation the change applies, an earlier application of the same id included. */
54
+ readonly applied: readonly string[];
55
+ /** The installations it takes off; an id not installed is none. */
56
+ readonly removed: readonly string[];
57
+ };
58
+ /**
59
+ * What a preset installation means: the registry of presets a thread can install, how an
60
+ * installation is validated, an agent-defining one against its thread's agent included, which
61
+ * installations a thread's scope hands down to the children its calls create, and how a thread's
62
+ * recorded installations are mounted when it activates. A core service: the thread owner
63
+ * orchestrates creation, configuration and activation, and hands this service the thread, the scope
64
+ * or the state each question is about. Registrations do not survive a reload.
65
+ */
66
+ export declare class PresetsService extends Service {
67
+ static inject: string[];
68
+ private readonly registry;
69
+ /** Each thread scope's hand-downs, in declaration order; the global layer stays empty. */
70
+ private readonly handDowns;
71
+ constructor(ctx: Context);
72
+ /** Makes `preset` installable on threads; returns the unregister function. */
73
+ register(preset: AnyPreset): () => void;
74
+ /** Whether a preset is registered under `presetId`. */
75
+ has(presetId: string): boolean;
76
+ /**
77
+ * The installations `entries` record, validated before anything is appended: a registered
78
+ * preset whose placement allows the use, a configuration its schema accepts and parses back to
79
+ * itself, and ids unique among them. At a creation on `agentName`, a preset that defines its
80
+ * thread's agent must define that one. Reads no thread state, so it fails only on a composition
81
+ * bug.
82
+ */
83
+ installationsFor(entries: readonly InstallationInput[], use: 'creation' | 'change', agentName?: string): Installation[];
84
+ /**
85
+ * The installations a creation on `agentName` records, each with its lifetime: validated as
86
+ * {@link installationsFor} validates a creation's, and a creation preset refused unless it is
87
+ * `defining`, since it can never be applied again once removed.
88
+ */
89
+ initialInstallations(entries: readonly InitialInstallationInput[], agentName: string): InitialInstallation[];
90
+ /**
91
+ * What a change records on `threadId`, decided against its installations as they stand:
92
+ * removals first, then applications, each id once. Removing an id not installed is no change; a
93
+ * defining installation is never removed. An application whose id is already this very
94
+ * installation, compared after defaults, is no change, which makes a retry idempotent; one whose
95
+ * id names another installation, or a removed one, is refused. The owner calls this before
96
+ * admitting the change and again inside its write.
97
+ */
98
+ plan(threadId: string, apply: readonly Installation[], remove: readonly string[]): ConfigurationPlan;
99
+ /**
100
+ * Declares in `scope` that every thread a call there creates is born with `handDown` installed,
101
+ * as a defining installation; returns the withdraw function. Use {@link handDown}, which ties it
102
+ * to the declaring plugin. Refused in the global layer, where it would reach the children of every
103
+ * conversation; for a preset that is not registered, since a child restores it from the registry
104
+ * whether or not its parent is live; for a configuration its preset would not record; and for an
105
+ * installation id already handed down in the same layer, so no rule has to choose between two
106
+ * declarations.
107
+ */
108
+ handDown(scope: ScopeKey | undefined, handDown: HandDown): () => void;
109
+ /**
110
+ * The installations a new thread on `agentName` is born with because the scope of the call
111
+ * creating it hands them down, each defining: from the closest layer out, each in declaration
112
+ * order, a closer declaration winning an id. Validated as the creation's own installations are,
113
+ * and refused when an id is also one of those: two owners for one installation is a composition
114
+ * bug, not something to resolve.
115
+ */
116
+ handedDown(scope: ScopeKey, threadId: string, agentName: string, own: readonly Installation[]): InitialInstallation[];
117
+ /**
118
+ * Mounts every recorded installation of `thread`, one at a time in recorded order so that
119
+ * registration order is stable across reopening; the owner calls it once the activation's
120
+ * listeners have settled, so installations follow the listeners' own plugins. Any failure fails
121
+ * the activation, which a run turns into a rejection with the input kept.
122
+ */
123
+ restore(thread: Thread): Promise<void>;
124
+ private requireRegistered;
125
+ /**
126
+ * Whether `installation`'s id is already this very installation. Throws when the id names a
127
+ * different installation, or one that was removed.
128
+ */
129
+ private alreadyApplied;
130
+ }
131
+ /** Makes `preset` installable on threads for the lifetime of the calling plugin. */
132
+ export declare const registerPreset: (ctx: Context, preset: AnyPreset) => (() => void | Promise<void>);
133
+ /**
134
+ * Hands `handDown` down, for the lifetime of the calling plugin, from the thread scope it is
135
+ * mounted in to every new thread a call there creates: each child is born with it as a defining
136
+ * installation, recorded with its spawn row. See {@link PresetsService.handDown} for what is
137
+ * refused. Looks the service up, so a caller need not inject it.
138
+ */
139
+ export declare function handDown(ctx: Context, handDown: HandDown): () => void | Promise<void>;
@@ -0,0 +1,85 @@
1
+ import { Context, Service, type ScopeKey } from '@leuduan/cordis';
2
+ import { type PromptBlock } from '../llm/prompt.js';
3
+ import { type ToolEntry } from '../loop/index.js';
4
+ import type { AgentDefinition } from '../loop/index.js';
5
+ import type { ThreadSummary } from '../records/journal.js';
6
+ import { type AgentSelector } from './agents.js';
7
+ export type PromptSlot = 'base' | 'instruction' | 'context';
8
+ /**
9
+ * What a contribution is rendered against: the agent, where the thread works, and the tools it
10
+ * reaches.
11
+ *
12
+ * Deliberately not the thread's id or metadata. A recorded prompt is the head of every request a
13
+ * provider caches, so it must not depend on which thread it is: threads of one agent in one
14
+ * workspace then render the same prompt. Anything thread-specific belongs in the conversation, as
15
+ * a step contribution (see `workspaceNotice`).
16
+ */
17
+ export type PromptRenderInput = {
18
+ readonly agent: AgentDefinition;
19
+ readonly thread: {
20
+ readonly environment: ThreadSummary['environment'];
21
+ };
22
+ /** What the agent may call from the rendering scope, as the registries stand at render time. */
23
+ readonly tools: readonly ToolEntry[];
24
+ };
25
+ /**
26
+ * One section a plugin adds to an agent's prompt.
27
+ *
28
+ * `render` is synchronous and pure in its inputs: anything needing IO reads it when the plugin
29
+ * mounts, and returns the cached value here. Returning `null` contributes nothing — or, for a tag
30
+ * that already exists, removes it.
31
+ */
32
+ export type PromptContribution = {
33
+ readonly tag: string;
34
+ readonly slot: PromptSlot;
35
+ /** Which agents get it; see `AgentSelector`. */
36
+ readonly agents: AgentSelector;
37
+ /** Render order within the slot; ties break on `tag`. Default 0. */
38
+ readonly order?: number;
39
+ render(input: PromptRenderInput): string | null;
40
+ };
41
+ /**
42
+ * Prompt contributions, live like the other registries and layered by Cordis scope like tools:
43
+ * an untagged contribution is global, a contribution registered through a thread's context belongs
44
+ * to that thread's layer. The prompt itself is rendered once, when a thread first runs and every
45
+ * activation plugin is ready, and recorded on it; this service only says what that render
46
+ * would be right now.
47
+ */
48
+ export declare class PromptsService extends Service {
49
+ static inject: string[];
50
+ private readonly layers;
51
+ constructor(ctx: Context);
52
+ /** Adds a contribution to one layer; returns the function that removes it. */
53
+ contribute(scope: ScopeKey | undefined, contribution: PromptContribution): () => void;
54
+ /**
55
+ * The prompt `agentName` would send on a thread rendered now from `scope`: the agent's base
56
+ * prompt, then the global layer's contributions, then each closer layer outward-in, each in
57
+ * declared order, never mount order. A contribution whose tag is already present replaces that
58
+ * section in place — so the closest layer wins a tag — and `null` removes it.
59
+ *
60
+ * The base prompt is seeded at the layer that defines the agent, so only that layer and closer
61
+ * ones can replace or remove it with a `base` contribution: for a global agent every layer can,
62
+ * while a scoped agent's own base prompt outranks every layer farther out. Instruction and context
63
+ * contributions apply from every layer. Throws for an agent unknown from `scope`.
64
+ */
65
+ render(scope: ScopeKey | undefined, agentName: string, thread: PromptRenderInput['thread']): PromptBlock[];
66
+ }
67
+ /** Registers a contribution in the calling plugin's layer for the lifetime of its fiber. */
68
+ export declare const contributePrompt: (ctx: Context, contribution: PromptContribution) => (() => void | Promise<void>);
69
+ export type TaggedSection = {
70
+ tag: string;
71
+ content: string;
72
+ };
73
+ /**
74
+ * A prompt as `ctx.prompts` assembles it: the agent's base prompt, then instruction sections, then
75
+ * context sections, so a section's bucket is what decides its position. The rendered result is
76
+ * recorded per thread.
77
+ */
78
+ export type SystemPrompt = {
79
+ basePrompt: string;
80
+ instructions: TaggedSection[];
81
+ contextSections: TaggedSection[];
82
+ };
83
+ /** The prompt as ordered blocks — the one place its order is decided. */
84
+ export declare function systemPromptBlocks(prompt: SystemPrompt): PromptBlock[];
85
+ export declare const renderSystemPrompt: (prompt: SystemPrompt) => string;
@@ -0,0 +1,100 @@
1
+ import { type Context, type Scope, type Scoped, type ScopeKey } from '@leuduan/cordis';
2
+ import { type CompactOptions, type Lease, type LoopServices, type SurfacePrepareOutcome } from '../../loop/index.js';
3
+ import type { ServedRun } from '../../loop/index.js';
4
+ import type { Thread } from './thread.js';
5
+ import type { AdmissionView } from './admission.js';
6
+ import type { ThreadsService } from './service.js';
7
+ /**
8
+ * One process-local activation: the thread's Cordis scope, the plugins mounted in it, their
9
+ * readiness, and the loop that runs in it. It owns resources, never admission: which operation
10
+ * holds the thread, and its cancellation, are the admission owner's, which the threads service
11
+ * keeps and which hands each run or compaction its signal and lease.
12
+ */
13
+ export declare class ThreadActivation {
14
+ readonly scope: Scope;
15
+ readonly target: Scoped;
16
+ private readonly runtime;
17
+ private readonly loop;
18
+ private readiness;
19
+ private readonly controller;
20
+ private failed;
21
+ private prepared;
22
+ /** The plugin tree as it was when the activation became ready, which is what it runs with. */
23
+ private readyTree;
24
+ private staleBecause;
25
+ private draining;
26
+ private closingDone;
27
+ private readonly service;
28
+ private readonly admission;
29
+ readonly thread: Thread;
30
+ private readonly released;
31
+ constructor(service: ThreadsService,
32
+ /** The admission owner's reads, given by the service that owns it. */
33
+ admission: AdmissionView, owner: Context, thread: Thread, loopServices: (scope: ScopeKey) => LoopServices, released: () => void);
34
+ /**
35
+ * From readiness on, the plugin tree is what the activation runs with. A guard on each of its
36
+ * plugins marks the activation stale before that plugin's disposers run, whatever unloads it: a
37
+ * dependency gone, a root mount disposed, a reload. Its own release marks it too, harmlessly.
38
+ */
39
+ private watchTree;
40
+ private markStale;
41
+ /**
42
+ * Whether the plugins changed since readiness: one unloaded or reloaded, or one added through
43
+ * `thread.ctx`, which is reported once. A stale activation dispatches nothing new, and the owner
44
+ * replaces it once the operation holding the thread settles.
45
+ */
46
+ isStale(): boolean;
47
+ /**
48
+ * Whether a setup in this activation is still running: its listeners and installations have not
49
+ * settled, or a plugin of its tree is in transition, one mounted later through `thread.ctx` or one
50
+ * reloading included. A change that waits for this activation to go, made from one of those
51
+ * setups, would wait on itself, so it is refused meanwhile. Not a readiness check: readiness is
52
+ * settled once.
53
+ */
54
+ get activating(): boolean;
55
+ private observe;
56
+ /** Aborts on release and on stop; what the activate listeners receive. */
57
+ get signal(): AbortSignal;
58
+ /** Whether readiness failed: the owner releases such an activation once its operation settles. */
59
+ get hasFailed(): boolean;
60
+ /** Set once `release()` has begun: resolves when the scope is disposed. The owner waits for it before activating again. */
61
+ get closed(): Promise<void> | undefined;
62
+ private settle;
63
+ /** One execution of the run `served`, under the admitted operation's signal and lease. */
64
+ run(options: {
65
+ signal: AbortSignal;
66
+ lease: Lease;
67
+ served: ServedRun;
68
+ }): Promise<void>;
69
+ /**
70
+ * One request to prepare the surface, under the admitted operation's signal and lease; see
71
+ * `Thread.compact`. Resolves with the outcome, `cancelled` when the signal aborts first.
72
+ */
73
+ compact(options: CompactOptions & {
74
+ signal: AbortSignal;
75
+ lease: Lease;
76
+ }): Promise<SurfacePrepareOutcome>;
77
+ /**
78
+ * Waits for readiness, settled once when the activation began, then checks the agent and records
79
+ * the prompt if the thread has none. Only then is the scope complete: the thread's plugins may
80
+ * define its agent, and an unknown one fails here, before a prompt is recorded or a turn opens,
81
+ * so input waits for a retry. A stale activation never gets here: the owner replaces it first.
82
+ */
83
+ private ready;
84
+ /**
85
+ * Resolves once the activation is ready: its listeners and installations settled, every plugin of
86
+ * its tree active. The same barrier a run uses: a settled but PENDING plugin is not ready, so a
87
+ * caller never reads a half-configured scope.
88
+ */
89
+ whenReady(): Promise<void>;
90
+ /** The owner releases scopes only after every thread has drained, including failed setup. */
91
+ stop(reason: Error): void;
92
+ /** Resolves once setup has ended, however, and every plugin mounted since is settled. */
93
+ whenIdle(): Promise<void>;
94
+ /**
95
+ * Disposes the scope once setup has ended. The owner calls this with no executing operation on
96
+ * the thread, or from the operation that is settling; the scope's own unload guard is what waits
97
+ * for a loop when something else disposes the scope.
98
+ */
99
+ release(): Promise<void>;
100
+ }
@@ -0,0 +1,174 @@
1
+ import type { Lease } from '../../loop/index.js';
2
+ import type { CancelIntent, InboxTarget } from '../../records/journal.js';
3
+ /**
4
+ * An exclusive operation on one thread; see `Admission.onOperation`. A `cancel` holds the thread from a
5
+ * `cancel()` until its write has landed and what it cancelled has released the thread.
6
+ */
7
+ export type OperationKind = 'run' | 'compact' | 'rebuild' | 'configure' | 'release' | 'cancel';
8
+ /** How an operation ended: as asked, by throwing, or because it was cancelled or lagent closed. */
9
+ export type OperationEnding = 'completed' | 'failed' | 'cancelled';
10
+ /** What holds a thread: the operation's kind, and the run request a run serves (`null` for any other). */
11
+ export type OperationHolder = {
12
+ readonly kind: OperationKind;
13
+ readonly runId: string | null;
14
+ };
15
+ /**
16
+ * What `onOperation` listeners are told: an operation was admitted on a thread, or it settled and
17
+ * how. Process-local and never a journal row; `settled` is published once admission is released,
18
+ * so a listener may start the thread's next operation from it.
19
+ */
20
+ export type OperationEvent = {
21
+ readonly thread_id: string;
22
+ readonly kind: OperationKind;
23
+ readonly phase: 'admitted';
24
+ } | {
25
+ readonly thread_id: string;
26
+ readonly kind: OperationKind;
27
+ readonly phase: 'settled';
28
+ readonly ended: OperationEnding;
29
+ };
30
+ /**
31
+ * An admitted operation as the code running it sees it: what it is, and the signal and lease it
32
+ * hands to the work. Everything else about it is the owner's.
33
+ */
34
+ export type AdmittedOperation = {
35
+ readonly threadId: string;
36
+ readonly kind: OperationKind;
37
+ /** The run request a run serves; `null` for any other operation. */
38
+ readonly runId: string | null;
39
+ readonly signal: AbortSignal;
40
+ readonly lease: Lease;
41
+ };
42
+ /**
43
+ * What a thread's handle and its activation ask the owner: whether it runs, where input waits, the
44
+ * cancel, and the unload guard's wait. Nothing that admits or settles an operation.
45
+ */
46
+ export type AdmissionView = Pick<Admission, 'isRunning' | 'inputTarget' | 'cancel' | 'whenSettled' | 'isAdmitted'>;
47
+ /**
48
+ * What one `cancel()` gets back: the run of the execution the thread's cancel captured, if it
49
+ * captured a run, and the one settlement of that cancel. `wrote` reports the call's own write,
50
+ * once it is queued, and only then aborts what the call captured, so a cancel an abort listener
51
+ * makes is written after this one. `capturedSettles` says, read inside that write, whether the
52
+ * captured execution's finalization is still to build its run's settlement: until then the
53
+ * finalization settles it by the cancel's intent; after, what it built stands, and a run it left
54
+ * pending is the cancel's to settle.
55
+ */
56
+ export type CancelHandle = {
57
+ readonly capturedRunId: string | null;
58
+ readonly settled: Promise<void>;
59
+ capturedSettles(): boolean;
60
+ wrote(write: Promise<unknown>): void;
61
+ };
62
+ /**
63
+ * The one owner of which operation holds each thread: admission or refusal, the releasing phase,
64
+ * cancellation, and the publication of admission and settlement in the order
65
+ * docs/guides/threads.md#ordering states. It knows nothing of activations; the threads service runs
66
+ * each operation's work, and disposes activations under it, through `hold`.
67
+ */
68
+ export declare class Admission {
69
+ /**
70
+ * The one operation admitted on each thread, from before its first `await` until its work and
71
+ * cleanup settled: what `cancel()` aborts and awaits, what refuses a second operation as busy,
72
+ * and what says whether input joins a run's next step.
73
+ */
74
+ private readonly admitted;
75
+ /** The cancel in progress on each thread, from its first call until it settles. */
76
+ private readonly cancels;
77
+ private readonly listeners;
78
+ private readonly closing;
79
+ private readonly report;
80
+ /**
81
+ * @param closing aborts once lagent is closing: nothing is admitted after, and it is composed
82
+ * into every operation's signal.
83
+ */
84
+ constructor(closing: AbortSignal, report: (error: unknown) => void);
85
+ /** Refuses as admission would, without admitting: once lagent is closing, or busy while an operation holds the thread. */
86
+ requireFree(threadId: string): void;
87
+ /**
88
+ * Admits `kind` on the thread, or refuses it busy, synchronously, and publishes `admitted` before
89
+ * returning. The operation's signal composes shutdown's, `cancel()`'s and the caller's; its lease
90
+ * says whether it still holds the thread, for a callback that escaped it. A configuration change
91
+ * is admitted releasing: it starts by releasing the live activation, before anything can see it.
92
+ */
93
+ admit(threadId: string, kind: OperationKind, options?: {
94
+ readonly signal?: AbortSignal | undefined;
95
+ readonly runId?: string | undefined;
96
+ }): AdmittedOperation;
97
+ private operation;
98
+ /**
99
+ * Runs `work` as the admitted operation, then the disposal `cleanup` returns, if any, then its
100
+ * `finalize`, if any, both still under it, then releases admission and publishes `settled` in the
101
+ * same synchronous step, however `work` ended. `finalize` runs in the releasing phase: the
102
+ * operation still holds the thread, so nothing else is admitted and nothing mounts, but it executes
103
+ * nothing more, and input sent meanwhile waits for the next turn. It runs again when a cancel
104
+ * captured the operation while it ran, so it must be safe to repeat. Without either step nothing is
105
+ * awaited between the work's end and the release. The value `work` returns is its own, taken
106
+ * before admission is released. A failing finalization or disposal is reported; the admission is
107
+ * released all the same.
108
+ */
109
+ hold<T>(admitted: AdmittedOperation, work: () => Promise<T>, steps?: {
110
+ readonly finalize?: () => Promise<void>;
111
+ readonly cleanup?: () => Promise<void> | undefined;
112
+ }): Promise<T>;
113
+ /**
114
+ * Enters or leaves the operation's releasing phase; entering wakes whatever waits for it to stop
115
+ * executing. Set by whoever disposes an activation under the operation, before the disposal starts.
116
+ */
117
+ setReleasing(admitted: AdmittedOperation, releasing: boolean): void;
118
+ /**
119
+ * Starts the thread's cancel, or joins the one in progress, synchronously. The first call captures
120
+ * the operation admitted now, if any, and marks it with its intent; `wrote` aborts it (a release is
121
+ * waited for, never aborted). The run that operation serves settles by the intent of the first
122
+ * cancel that reached it. With nothing
123
+ * admitted, a `cancel` operation holds the thread at once, closing or not, since a shutdown still
124
+ * cancels. Either way the cancel holds the thread, refusing a run as busy, until every joined
125
+ * call's write has finished, landed or failed (`wrote`), and the captured operation has released;
126
+ * its `settled` then resolves, once for every call.
127
+ */
128
+ cancel(threadId: string, reason: string, intent: CancelIntent): CancelHandle;
129
+ /** The intent of the first cancel that captured `admitted`, or `null`: what the run it serves settles by. */
130
+ cancelIntent(admitted: AdmittedOperation): CancelIntent | null;
131
+ /**
132
+ * Records, inside the finalization's write, that `admitted` built its run's settlement: a cancel
133
+ * written after it settles a run that build left pending.
134
+ */
135
+ settlementBuilt(admitted: AdmittedOperation): void;
136
+ /** The thread's cancel holds the thread as a `cancel` operation of its own; published by the caller. */
137
+ private holdForCancel;
138
+ private wroteCancel;
139
+ /** Settles the thread's cancel once every joined write finished and what it captured released. */
140
+ private finishCancel;
141
+ /** What holds the thread now, or `null`. */
142
+ holder(threadId: string): OperationHolder | null;
143
+ /** Whether any operation holds the thread. */
144
+ isAdmitted(threadId: string): boolean;
145
+ /** Whether a run or a compaction holds the thread: what `Thread.status()` calls running. */
146
+ isRunning(threadId: string): boolean;
147
+ /**
148
+ * Whether the operation holding the thread is disposing its activation, a release or another in
149
+ * its releasing phase: nothing of the thread may be mounted meanwhile, and it executes nothing.
150
+ */
151
+ isReleasing(threadId: string): boolean;
152
+ /** Where input sent now waits: a run's next step while a run holds the thread and is not cancelled, else the next turn. */
153
+ inputTarget(threadId: string): InboxTarget;
154
+ /** Resolves once the operation holding the thread now, if any, has settled. */
155
+ settlement(threadId: string): Promise<void>;
156
+ /**
157
+ * Resolves once no operation that executes holds the thread: what an activation waits for before
158
+ * it disposes, so a scope never goes under a running loop. An operation disposing the activation
159
+ * is not waited for, since that would be the disposal waiting on itself.
160
+ */
161
+ whenSettled(threadId: string): Promise<void>;
162
+ /**
163
+ * Resolves once no operation holds any thread and no cancel is in progress: what shutdown waits
164
+ * for before releasing scopes. Read again after each wait, since a cancel takes over a thread its
165
+ * captured operation releases, and a shutdown still cancels.
166
+ */
167
+ drain(): Promise<void>;
168
+ /** Tells `listener` when an operation is admitted on any thread and when it settled; see {@link OperationEvent}. */
169
+ onOperation(listener: (event: OperationEvent) => void): () => void;
170
+ /** The owner's record of `admitted`, which must hold its thread: anything else is a caller bug. */
171
+ private holding;
172
+ /** One frozen copy for every listener, so no listener can change what the next one sees. */
173
+ private publish;
174
+ }