@leuduan/lagent 0.0.0-stage → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (327) hide show
  1. package/LICENSE +16 -0
  2. package/README.md +144 -2
  3. package/dist/chunks/2O7ZGEIT.js +1 -0
  4. package/dist/chunks/2OSESBIL.js +1 -0
  5. package/dist/chunks/34KW6VNQ.js +1 -0
  6. package/dist/chunks/37YOGDGY.js +1 -0
  7. package/dist/chunks/3LQHQRIU.js +6 -0
  8. package/dist/chunks/3QCW4WDJ.js +1 -0
  9. package/dist/chunks/4XVRUSCQ.js +1 -0
  10. package/dist/chunks/6ECI2GGV.js +1 -0
  11. package/dist/chunks/74HKUGRR.js +1 -0
  12. package/dist/chunks/ADHERZLW.js +2 -0
  13. package/dist/chunks/AP6Q4EPT.js +36 -0
  14. package/dist/chunks/BM3S37EZ.js +1 -0
  15. package/dist/chunks/C5LYCXJG.js +1 -0
  16. package/dist/chunks/CDQG7RKA.js +1 -0
  17. package/dist/chunks/D7E6EWIE.js +3 -0
  18. package/dist/chunks/DDANMY45.js +3 -0
  19. package/dist/chunks/DRYAN665.js +1 -0
  20. package/dist/chunks/DXFXAYDN.js +17 -0
  21. package/dist/chunks/EGZI4XQX.js +24 -0
  22. package/dist/chunks/ENWFSU27.js +41 -0
  23. package/dist/chunks/G6RXC3AL.js +1 -0
  24. package/dist/chunks/G74AGRAJ.js +15 -0
  25. package/dist/chunks/GQGNVSKB.js +1 -0
  26. package/dist/chunks/IJ2WNMD5.js +7 -0
  27. package/dist/chunks/J5S4URAW.js +1 -0
  28. package/dist/chunks/JPZFKSWT.js +1 -0
  29. package/dist/chunks/KESCTXGO.js +5 -0
  30. package/dist/chunks/L3N4FIEN.js +1 -0
  31. package/dist/chunks/NAOUTU7A.js +4 -0
  32. package/dist/chunks/NDIM7MEW.js +1 -0
  33. package/dist/chunks/O4PPOM5Z.js +2 -0
  34. package/dist/chunks/OVZFGILJ.js +1 -0
  35. package/dist/chunks/P5ZHHOOM.js +6 -0
  36. package/dist/chunks/PUSUPTAT.js +1 -0
  37. package/dist/chunks/QMMLQJBS.js +1 -0
  38. package/dist/chunks/RK3VP2Q4.js +3 -0
  39. package/dist/chunks/SGGMBSBA.js +1 -0
  40. package/dist/chunks/SL2YLB2F.js +1 -0
  41. package/dist/chunks/TOOIB6J2.js +1 -0
  42. package/dist/chunks/TYTQRLTX.js +1 -0
  43. package/dist/chunks/UC3FVVJ2.js +5 -0
  44. package/dist/chunks/UCTEU62F.js +1 -0
  45. package/dist/chunks/UD3VJER6.js +1 -0
  46. package/dist/chunks/UKXMCHHT.js +1 -0
  47. package/dist/chunks/WUUKTSRT.js +7 -0
  48. package/dist/chunks/X65X4KP5.js +7 -0
  49. package/dist/chunks/YIR5MYGU.js +1 -0
  50. package/dist/chunks/YLNJXQ3Z.js +1 -0
  51. package/dist/context.d.ts +101 -0
  52. package/dist/index.d.ts +47 -0
  53. package/dist/index.js +77 -0
  54. package/dist/journal/catalog.d.ts +112 -0
  55. package/dist/journal/forkChain.d.ts +16 -0
  56. package/dist/journal/index.d.ts +15 -0
  57. package/dist/journal/journal.d.ts +475 -0
  58. package/dist/journal/projection.d.ts +87 -0
  59. package/dist/journal/store.d.ts +181 -0
  60. package/dist/kit/claim.d.ts +13 -0
  61. package/dist/kit/drain.d.ts +10 -0
  62. package/dist/kit/extension.d.ts +180 -0
  63. package/dist/kit/grants.d.ts +9 -0
  64. package/dist/kit/modes.d.ts +65 -0
  65. package/dist/kit/retries.d.ts +25 -0
  66. package/dist/kit/scope.d.ts +32 -0
  67. package/dist/kit/service.d.ts +7 -0
  68. package/dist/kit/strategy.d.ts +10 -0
  69. package/dist/kit/timers.d.ts +43 -0
  70. package/dist/kit/tool.d.ts +72 -0
  71. package/dist/llm/client.d.ts +135 -0
  72. package/dist/llm/content.d.ts +52 -0
  73. package/dist/llm/door.d.ts +21 -0
  74. package/dist/llm/door.js +1 -0
  75. package/dist/llm/failure.d.ts +82 -0
  76. package/dist/llm/index.d.ts +16 -0
  77. package/dist/llm/primitives.d.ts +286 -0
  78. package/dist/llm/prompt.d.ts +21 -0
  79. package/dist/llm/provider.d.ts +63 -0
  80. package/dist/llm/readLedger.d.ts +24 -0
  81. package/dist/llm/request.d.ts +58 -0
  82. package/dist/loop/agent.d.ts +134 -0
  83. package/dist/loop/auxiliary.d.ts +54 -0
  84. package/dist/loop/chain.d.ts +46 -0
  85. package/dist/loop/chunks.d.ts +27 -0
  86. package/dist/loop/continuation.d.ts +166 -0
  87. package/dist/loop/decide.d.ts +64 -0
  88. package/dist/loop/errors.d.ts +162 -0
  89. package/dist/loop/forks.d.ts +61 -0
  90. package/dist/loop/holds.d.ts +104 -0
  91. package/dist/loop/hooks.d.ts +241 -0
  92. package/dist/loop/inbox.d.ts +188 -0
  93. package/dist/loop/index.d.ts +37 -0
  94. package/dist/loop/limits.d.ts +14 -0
  95. package/dist/loop/opening.d.ts +42 -0
  96. package/dist/loop/prepare.d.ts +30 -0
  97. package/dist/loop/projections.d.ts +307 -0
  98. package/dist/loop/replace.d.ts +33 -0
  99. package/dist/loop/requests.d.ts +129 -0
  100. package/dist/loop/route.d.ts +53 -0
  101. package/dist/loop/runtime.d.ts +85 -0
  102. package/dist/loop/state.d.ts +70 -0
  103. package/dist/loop/strategy.d.ts +71 -0
  104. package/dist/loop/summary.d.ts +3 -0
  105. package/dist/loop/surface.d.ts +153 -0
  106. package/dist/loop/threadState.d.ts +72 -0
  107. package/dist/loop/tool.d.ts +101 -0
  108. package/dist/loop/toolCalls.d.ts +42 -0
  109. package/dist/loop/wake.d.ts +32 -0
  110. package/dist/models/config/agent.d.ts +18 -0
  111. package/dist/models/config/prompt.d.ts +18 -0
  112. package/dist/models/door.d.ts +12 -0
  113. package/dist/models/door.js +1 -0
  114. package/dist/models/index.d.ts +7 -0
  115. package/dist/models/jsonSchema.d.ts +7 -0
  116. package/dist/models/wire/journal.d.ts +2772 -0
  117. package/dist/models/wire/primitives.d.ts +65 -0
  118. package/dist/plugin.d.ts +53 -0
  119. package/dist/plugin.js +1 -0
  120. package/dist/plugins/agentsMd.d.ts +76 -0
  121. package/dist/plugins/agentsMd.js +1 -0
  122. package/dist/plugins/ask/askQuestion.d.ts +9 -0
  123. package/dist/plugins/ask/index.d.ts +26 -0
  124. package/dist/plugins/ask/index.js +1 -0
  125. package/dist/plugins/ask/service.d.ts +125 -0
  126. package/dist/plugins/commands/background.d.ts +8 -0
  127. package/dist/plugins/commands/foreground.d.ts +4 -0
  128. package/dist/plugins/commands/index.d.ts +40 -0
  129. package/dist/plugins/commands/index.js +1 -0
  130. package/dist/plugins/commands/output.d.ts +115 -0
  131. package/dist/plugins/commands/record.d.ts +549 -0
  132. package/dist/plugins/commands/service.d.ts +314 -0
  133. package/dist/plugins/commands/shell.d.ts +25 -0
  134. package/dist/plugins/compaction/checkpoint.d.ts +91 -0
  135. package/dist/plugins/compaction/config.d.ts +133 -0
  136. package/dist/plugins/compaction/estimate.d.ts +29 -0
  137. package/dist/plugins/compaction/index.d.ts +2 -0
  138. package/dist/plugins/compaction/index.js +7 -0
  139. package/dist/plugins/compaction/log.d.ts +61 -0
  140. package/dist/plugins/compaction/planner.d.ts +207 -0
  141. package/dist/plugins/compaction/preset.d.ts +86 -0
  142. package/dist/plugins/compaction/prune.d.ts +9 -0
  143. package/dist/plugins/compaction/records.d.ts +227 -0
  144. package/dist/plugins/compaction/segments.d.ts +23 -0
  145. package/dist/plugins/compaction/shared.d.ts +14 -0
  146. package/dist/plugins/compaction/summarize.d.ts +13 -0
  147. package/dist/plugins/dateAndBranch.d.ts +47 -0
  148. package/dist/plugins/dateAndBranch.js +1 -0
  149. package/dist/plugins/delegations/answers.d.ts +39 -0
  150. package/dist/plugins/delegations/assignmentKey.d.ts +22 -0
  151. package/dist/plugins/delegations/cleanup.d.ts +161 -0
  152. package/dist/plugins/delegations/constraint.d.ts +76 -0
  153. package/dist/plugins/delegations/index.d.ts +39 -0
  154. package/dist/plugins/delegations/index.js +1 -0
  155. package/dist/plugins/delegations/notices.d.ts +261 -0
  156. package/dist/plugins/delegations/obligations.d.ts +210 -0
  157. package/dist/plugins/delegations/record.d.ts +632 -0
  158. package/dist/plugins/delegations/request.d.ts +381 -0
  159. package/dist/plugins/delegations/role.d.ts +30 -0
  160. package/dist/plugins/delegations/service.d.ts +562 -0
  161. package/dist/plugins/delegations/standing.d.ts +19 -0
  162. package/dist/plugins/delegations/stopCheck.d.ts +21 -0
  163. package/dist/plugins/delegations/testing.d.ts +16 -0
  164. package/dist/plugins/delegations/tools.d.ts +71 -0
  165. package/dist/plugins/delegations/waitBook.d.ts +116 -0
  166. package/dist/plugins/delegations/waits.d.ts +118 -0
  167. package/dist/plugins/diagnostics/digest.d.ts +14 -0
  168. package/dist/plugins/diagnostics/index.d.ts +68 -0
  169. package/dist/plugins/diagnostics/index.js +1 -0
  170. package/dist/plugins/historyRecall/history.d.ts +9 -0
  171. package/dist/plugins/historyRecall/index.d.ts +31 -0
  172. package/dist/plugins/historyRecall/index.js +1 -0
  173. package/dist/plugins/historyRecall/render.d.ts +34 -0
  174. package/dist/plugins/historyRecall/tools.d.ts +4 -0
  175. package/dist/plugins/mcp/catalog.d.ts +36 -0
  176. package/dist/plugins/mcp/config.d.ts +63 -0
  177. package/dist/plugins/mcp/connection.d.ts +53 -0
  178. package/dist/plugins/mcp/errors.d.ts +32 -0
  179. package/dist/plugins/mcp/index.d.ts +33 -0
  180. package/dist/plugins/mcp/index.js +5 -0
  181. package/dist/plugins/mcp/mount.d.ts +98 -0
  182. package/dist/plugins/mcp/names.d.ts +25 -0
  183. package/dist/plugins/mcp/render.d.ts +29 -0
  184. package/dist/plugins/mcp/slots.d.ts +15 -0
  185. package/dist/plugins/mcp/stdio.d.ts +49 -0
  186. package/dist/plugins/mcp/tool.d.ts +41 -0
  187. package/dist/plugins/providers/anthropic.d.ts +175 -0
  188. package/dist/plugins/providers/anthropicMessages.d.ts +65 -0
  189. package/dist/plugins/providers/codex.d.ts +60 -0
  190. package/dist/plugins/providers/codexAuth.d.ts +116 -0
  191. package/dist/plugins/providers/deepseek.d.ts +55 -0
  192. package/dist/plugins/providers/door.d.ts +61 -0
  193. package/dist/plugins/providers/door.js +1 -0
  194. package/dist/plugins/providers/failure.d.ts +23 -0
  195. package/dist/plugins/providers/gateway.d.ts +23 -0
  196. package/dist/plugins/providers/index.d.ts +6 -0
  197. package/dist/plugins/providers/openaiChat.d.ts +62 -0
  198. package/dist/plugins/providers/openaiResponses.d.ts +100 -0
  199. package/dist/plugins/providers/opencodeCopilot.d.ts +23 -0
  200. package/dist/plugins/providers/opencodeGo.d.ts +98 -0
  201. package/dist/plugins/providers/shared.d.ts +104 -0
  202. package/dist/plugins/providers/stream.d.ts +154 -0
  203. package/dist/plugins/routeContext.d.ts +22 -0
  204. package/dist/plugins/routeContext.js +1 -0
  205. package/dist/plugins/schedules/index.d.ts +21 -0
  206. package/dist/plugins/schedules/index.js +5 -0
  207. package/dist/plugins/schedules/record.d.ts +396 -0
  208. package/dist/plugins/schedules/service.d.ts +120 -0
  209. package/dist/plugins/schedules/time.d.ts +26 -0
  210. package/dist/plugins/schedules/tools.d.ts +6 -0
  211. package/dist/plugins/skills/discovery.d.ts +54 -0
  212. package/dist/plugins/skills/index.d.ts +31 -0
  213. package/dist/plugins/skills/index.js +1 -0
  214. package/dist/plugins/skills/tool.d.ts +11 -0
  215. package/dist/plugins/store/durableObject.d.ts +23 -0
  216. package/dist/plugins/store/durableObject.js +1 -0
  217. package/dist/plugins/store/durableObjectConnection.d.ts +27 -0
  218. package/dist/plugins/store/memory.d.ts +29 -0
  219. package/dist/plugins/store/sql.d.ts +59 -0
  220. package/dist/plugins/store/sqlite.d.ts +31 -0
  221. package/dist/plugins/store/sqlite.js +1 -0
  222. package/dist/plugins/subAgents/availableRoutes.d.ts +53 -0
  223. package/dist/plugins/subAgents/fork.d.ts +32 -0
  224. package/dist/plugins/subAgents/index.d.ts +67 -0
  225. package/dist/plugins/subAgents/index.js +1 -0
  226. package/dist/plugins/subAgents/tool.d.ts +38 -0
  227. package/dist/plugins/toolPolicy/index.d.ts +61 -0
  228. package/dist/plugins/toolPolicy/index.js +1 -0
  229. package/dist/plugins/tools/editFiles.d.ts +128 -0
  230. package/dist/plugins/tools/fsRead.d.ts +17 -0
  231. package/dist/plugins/tools/html.d.ts +23 -0
  232. package/dist/plugins/tools/index.d.ts +59 -0
  233. package/dist/plugins/tools/index.js +1 -0
  234. package/dist/plugins/tools/network.d.ts +23 -0
  235. package/dist/plugins/tools/ripgrep.d.ts +20 -0
  236. package/dist/plugins/tools/textEdit.d.ts +67 -0
  237. package/dist/plugins/tools/web.d.ts +32 -0
  238. package/dist/plugins/truncateToolOutput.d.ts +26 -0
  239. package/dist/plugins/truncateToolOutput.js +1 -0
  240. package/dist/plugins/usage/index.d.ts +24 -0
  241. package/dist/plugins/usage/index.js +1 -0
  242. package/dist/plugins/usage/tracker.d.ts +34 -0
  243. package/dist/plugins/verify/facts.d.ts +356 -0
  244. package/dist/plugins/verify/index.d.ts +75 -0
  245. package/dist/plugins/verify/index.js +1 -0
  246. package/dist/plugins/verify/service.d.ts +90 -0
  247. package/dist/plugins/workflows/assignment.d.ts +16 -0
  248. package/dist/plugins/workflows/bindings.d.ts +95 -0
  249. package/dist/plugins/workflows/cleanup.d.ts +38 -0
  250. package/dist/plugins/workflows/definition.d.ts +184 -0
  251. package/dist/plugins/workflows/fold.d.ts +373 -0
  252. package/dist/plugins/workflows/index.d.ts +28 -0
  253. package/dist/plugins/workflows/index.js +6 -0
  254. package/dist/plugins/workflows/observations.d.ts +81 -0
  255. package/dist/plugins/workflows/participants.d.ts +143 -0
  256. package/dist/plugins/workflows/policy.d.ts +112 -0
  257. package/dist/plugins/workflows/providers.d.ts +146 -0
  258. package/dist/plugins/workflows/record.d.ts +2863 -0
  259. package/dist/plugins/workflows/routing.d.ts +116 -0
  260. package/dist/plugins/workflows/schema.d.ts +26 -0
  261. package/dist/plugins/workflows/service.d.ts +477 -0
  262. package/dist/plugins/workflows/submit.d.ts +8 -0
  263. package/dist/plugins/workflows/view.d.ts +103 -0
  264. package/dist/plugins/workflows/work.d.ts +21 -0
  265. package/dist/plugins/workspaceContext.d.ts +38 -0
  266. package/dist/plugins/workspaceContext.js +1 -0
  267. package/dist/presets/agents.d.ts +7 -0
  268. package/dist/presets/base.d.ts +10 -0
  269. package/dist/presets/codex.d.ts +60 -0
  270. package/dist/presets/index.d.ts +4 -0
  271. package/dist/presets/prompts.d.ts +56 -0
  272. package/dist/sandbox/absent.d.ts +32 -0
  273. package/dist/sandbox/client.d.ts +39 -0
  274. package/dist/sandbox/files.d.ts +28 -0
  275. package/dist/sandbox/index.d.ts +49 -0
  276. package/dist/sandbox/index.js +4 -0
  277. package/dist/sandbox/mode.d.ts +57 -0
  278. package/dist/sandbox/policy.d.ts +86 -0
  279. package/dist/sandbox/protocol.d.ts +107 -0
  280. package/dist/sandbox/service.d.ts +143 -0
  281. package/dist/sandbox/worker.d.ts +12 -0
  282. package/dist/sandbox/worker.js +1 -0
  283. package/dist/services/admission.d.ts +174 -0
  284. package/dist/services/agents.d.ts +37 -0
  285. package/dist/services/birth.d.ts +220 -0
  286. package/dist/services/contributions.d.ts +73 -0
  287. package/dist/services/core.d.ts +34 -0
  288. package/dist/services/journal.d.ts +26 -0
  289. package/dist/services/launches.d.ts +104 -0
  290. package/dist/services/llm.d.ts +80 -0
  291. package/dist/services/owner.d.ts +367 -0
  292. package/dist/services/preset.d.ts +154 -0
  293. package/dist/services/presets.d.ts +139 -0
  294. package/dist/services/prompts.d.ts +67 -0
  295. package/dist/services/runEvents.d.ts +79 -0
  296. package/dist/services/thread.d.ts +267 -0
  297. package/dist/services/threadActivation.d.ts +100 -0
  298. package/dist/services/threadDirs.d.ts +38 -0
  299. package/dist/services/threadView.d.ts +92 -0
  300. package/dist/services/threads.d.ts +449 -0
  301. package/dist/services/tools.d.ts +41 -0
  302. package/dist/sys/environment.d.ts +47 -0
  303. package/dist/sys/git.d.ts +60 -0
  304. package/dist/sys/paths.d.ts +56 -0
  305. package/dist/sys/spawn.d.ts +176 -0
  306. package/dist/testing/clock.d.ts +17 -0
  307. package/dist/testing/fakeLlm.d.ts +74 -0
  308. package/dist/testing/fedLlm.d.ts +32 -0
  309. package/dist/testing/helpers.d.ts +344 -0
  310. package/dist/testing/index.d.ts +13 -0
  311. package/dist/testing/index.js +1 -0
  312. package/dist/testing/processes.d.ts +13 -0
  313. package/dist/testing/sandbox.d.ts +71 -0
  314. package/dist/testing/settlement.d.ts +6 -0
  315. package/dist/testing/tmpDirs.d.ts +17 -0
  316. package/dist/util/async.d.ts +8 -0
  317. package/dist/util/diff.d.ts +25 -0
  318. package/dist/util/dispatch.d.ts +8 -0
  319. package/dist/util/errors.d.ts +28 -0
  320. package/dist/util/foldState.d.ts +17 -0
  321. package/dist/util/freeze.d.ts +2 -0
  322. package/dist/util/ids.d.ts +2 -0
  323. package/dist/util/json.d.ts +37 -0
  324. package/dist/util/log.d.ts +6 -0
  325. package/dist/util/text.d.ts +21 -0
  326. package/dist/util/version.d.ts +2 -0
  327. package/package.json +175 -3
@@ -0,0 +1,381 @@
1
+ import type { Context } from '@leuduan/cordis';
2
+ import { z } from 'zod';
3
+ import type { ModelRoute } from '../../llm/index.js';
4
+ import type { InvocationContext, ModelSelection, WriteRows } from '../../loop/index.js';
5
+ import type { Seq, ThreadEnvironment, ToolResultPayloadInput, TurnEndReason } from '../../models/index.js';
6
+ import type { DeepReadonly } from '../../util/json.js';
7
+ import type { InitialInstallationInput } from '../../services/presets.js';
8
+ import type { Thread } from '../../services/thread.js';
9
+ import type { StopBy, TaskRef, TaskSettlement } from './record.js';
10
+ import type { RoleConfig } from './role.js';
11
+ /**
12
+ * The child thread for one start tool's call, so a call re-dispatched after a crash finds the child
13
+ * it made instead of starting a second one. Named after the `tool/call` row (`context.callSeq`), not
14
+ * the provider's call id: a later turn may be handed the same id again, and it must get a thread of
15
+ * its own.
16
+ */
17
+ export declare const childThreadId: (callerThreadId: string, callSeq: Seq) => string;
18
+ /**
19
+ * The task one delegating call opens: its id, which is also the input id the child is handed, so
20
+ * `send` with it queues nothing twice and a re-dispatch finds the `started` row it wrote.
21
+ */
22
+ export declare const taskIdOf: (callerThreadId: string, callSeq: Seq) => string;
23
+ /**
24
+ * The caller and the `tool/call` row that opened task `taskId`, or `null` for an id no call made:
25
+ * only what `taskIdOf` writes parses.
26
+ */
27
+ export declare function openingCallOf(taskId: string): {
28
+ readonly callerThreadId: string;
29
+ readonly callSeq: Seq;
30
+ } | null;
31
+ /**
32
+ * What names a task an owner's assignment opens: the owner, its instance (the root the work runs
33
+ * under), the attempt and assignment, and the participant generation it runs on. Each assignment of
34
+ * a generation is one task, so a repeated start finds the task it opened.
35
+ */
36
+ export type AssignmentTaskKey = {
37
+ readonly owner: string;
38
+ readonly instance: string;
39
+ readonly attempt: string;
40
+ readonly assignment: string;
41
+ readonly generation: number;
42
+ };
43
+ /**
44
+ * What names the conversation an owner's participant runs in: one per participant generation for
45
+ * the instance, or, for a conversation that lives for one attempt (`attempt` not `null`), per
46
+ * attempt too. A restart is a new generation, so it never finds the conversation it replaces.
47
+ */
48
+ export type AssignmentConversationKey = {
49
+ readonly owner: string;
50
+ readonly instance: string;
51
+ readonly participant: string;
52
+ readonly attempt: string | null;
53
+ readonly generation: number;
54
+ };
55
+ /** The task one assignment of one participant generation opens, which is also its input's id on the child. */
56
+ export declare const assignmentTaskId: (key: AssignmentTaskKey) => string;
57
+ /** The child thread a participant generation runs in; an instance-lived one has no attempt part. */
58
+ export declare const assignmentChildId: (key: AssignmentConversationKey) => string;
59
+ /**
60
+ * The input a `message_agent` steer queues on the child, derived from the caller and the call as a
61
+ * task's id is, so the child's rows say whether a given steer landed and a re-dispatch sends nothing
62
+ * twice. Never a task id: a steer opens no task.
63
+ */
64
+ export declare const steerInputId: (callerThreadId: string, callSeq: Seq) => string;
65
+ /**
66
+ * Decodes the caller and call sequence encoded in a task or steering input id, or returns `null`
67
+ * for another format. This does not verify that the call exists or supplied the input.
68
+ */
69
+ export declare function delegatedInputCall(inputId: string): {
70
+ readonly callerThreadId: string;
71
+ readonly callSeq: Seq;
72
+ } | null;
73
+ /** What every steer `callerThreadId` sends starts with. */
74
+ export declare const steerPrefix: (callerThreadId: string) => string;
75
+ /** `threadId` as a child `callerThreadId` created, which only that caller may continue, read, steer or stop; or why it is not one. */
76
+ export declare function ownChild(ctx: Context, callerThreadId: string, threadId: string): Thread | string;
77
+ /**
78
+ * Why a call may not give `child` work, continuing or steering it, or `null` when it may: an owner's
79
+ * assignment created it, so only that owner does. Its caller still reads and stops it.
80
+ */
81
+ export declare function ownerManaged(child: Thread): string | null;
82
+ /** The tool that gives a child that exists more work, whichever tool started it. */
83
+ export declare const MESSAGE_AGENT_TOOL = "message_agent";
84
+ /** What a caller is told when a delegated thread stopped without an answer. */
85
+ export declare const describeFailure: (reason: DeepReadonly<TurnEndReason> | null) => string;
86
+ /** Whether the call returns at once with a receipt, leaving the child to work while the caller goes on. */
87
+ export declare const BackgroundField: z.ZodDefault<z.ZodBoolean>;
88
+ /**
89
+ * The fields every delegating tool takes besides what it delegates: the route to run the child on,
90
+ * and whether to wait for it. Spread into a tool's own parameters, so each delegating tool offers
91
+ * them alike; a fork, which keeps its source's route, takes `background` alone.
92
+ */
93
+ export declare const DelegationFields: {
94
+ background: z.ZodDefault<z.ZodBoolean>;
95
+ provider: z.ZodDefault<z.ZodNullable<z.ZodString>>;
96
+ model: z.ZodDefault<z.ZodNullable<z.ZodString>>;
97
+ thinking_effort: z.ZodDefault<z.ZodNullable<z.ZodEnum<{
98
+ low: "low";
99
+ high: "high";
100
+ none: "none";
101
+ medium: "medium";
102
+ max: "max";
103
+ }>>>;
104
+ };
105
+ export type DelegationFieldValues = {
106
+ [K in keyof typeof DelegationFields]: z.output<(typeof DelegationFields)[K]>;
107
+ };
108
+ /**
109
+ * A delegating tool's parameters: its own `shape` with `DelegationFields`, where a blank string in a
110
+ * field that takes `null` reads as `null`, since some models send "" for "not set". Normalized ahead
111
+ * of validation rather than in the schema, so the schema advertised keeps its choices.
112
+ */
113
+ export declare function delegationParameters<Shape extends z.ZodRawShape>(shape: Shape): z.ZodPreprocess<z.ZodObject<Shape & {
114
+ background: z.ZodDefault<z.ZodBoolean>;
115
+ provider: z.ZodDefault<z.ZodNullable<z.ZodString>>;
116
+ model: z.ZodDefault<z.ZodNullable<z.ZodString>>;
117
+ thinking_effort: z.ZodDefault<z.ZodNullable<z.ZodEnum<{
118
+ low: "low";
119
+ high: "high";
120
+ none: "none";
121
+ medium: "medium";
122
+ max: "max";
123
+ }>>>;
124
+ } extends infer T ? { -readonly [P in keyof T]: T[P]; } : never, z.core.$strip>, unknown>;
125
+ /** The route fields a call named; an unnamed field keeps the route's own (`LlmService.resolveRoute`). */
126
+ export declare const modelSelection: (fields: DelegationFieldValues) => ModelSelection;
127
+ /**
128
+ * What a new child runs on: a registered global agent; a role, the agent named by its id, which the
129
+ * child's defining installation of the `role` preset defines in the child's own layer; or a fork
130
+ * of the caller, cut at the request that produced the call, on the caller's agent and route.
131
+ */
132
+ export type DelegationTarget = {
133
+ readonly kind: 'agent';
134
+ readonly name: string;
135
+ } | {
136
+ readonly kind: 'role';
137
+ readonly role: RoleConfig;
138
+ } | {
139
+ readonly kind: 'fork';
140
+ };
141
+ /** The installation id a role child records its role under. */
142
+ export declare const ROLE_INSTALLATION = "role";
143
+ /**
144
+ * Why no child can be created on `role`, or `null`: its tools are checked against the global layer
145
+ * before anything is prepared, since its installation grants them without checking, and a child
146
+ * created with a missing one would lack it for good.
147
+ */
148
+ export declare function roleRefusal(ctx: Context, role: RoleConfig): string | null;
149
+ /** What a settled task told its caller: the answer, or why there is none. */
150
+ export type DelegationOutcome = {
151
+ status: 'completed';
152
+ output: string;
153
+ } | {
154
+ status: 'failed';
155
+ output: string;
156
+ };
157
+ /** What one delegating call asks for. */
158
+ export type DelegationRequest = {
159
+ /**
160
+ * The child that does the task: a new one on `target`, named after this call, or one this thread
161
+ * created, continued by its id, whichever target made it.
162
+ */
163
+ readonly child: {
164
+ readonly kind: 'start';
165
+ readonly target: DelegationTarget;
166
+ } | {
167
+ readonly kind: 'continue';
168
+ readonly threadId: string;
169
+ };
170
+ /**
171
+ * Route fields folded over the route of the turn making the call for a new child, which is born on
172
+ * it, or over a continued child's own route, which they change; a fork takes none.
173
+ */
174
+ readonly selection?: ModelSelection;
175
+ /**
176
+ * Return a receipt once the task is open rather than wait for its answer; the task's drive
177
+ * outlives the call. Either way the task takes one of its origin root's `maxOpenTasks` slots.
178
+ */
179
+ readonly background?: boolean;
180
+ /** The task to open. A tool that must prepare it does so before it delegates. */
181
+ readonly task: string;
182
+ /**
183
+ * The caller's own rows for the write that opens the task, run inside it after delegations' checks
184
+ * pass and composed with the task's `started` row, input and cause: a creation's or a
185
+ * continuation's alike. A veto leaves nothing, no child created and no task opened, and the call
186
+ * is answered with its reason.
187
+ */
188
+ readonly rows?: WriteRows;
189
+ /**
190
+ * What the caller is told of a settled task, and of a delegation that failed before one: given
191
+ * the failure's text then. Without it, the answer or the failure as it is.
192
+ */
193
+ answer?(outcome: DelegationOutcome): ToolResultPayloadInput;
194
+ };
195
+ /**
196
+ * The authority a task is opened on, which its origin records: a caller's tool `call`, the
197
+ * invocation the call path adapts at the tool boundary (`DelegationsService.delegate`), with the
198
+ * child it names and how; or a registered owner's `assignment`, through its live registration
199
+ * (`DelegationsService.registerOwner`), with the configuration it pinned for the participant.
200
+ */
201
+ export type TaskAuthority = {
202
+ readonly kind: 'call';
203
+ readonly context: InvocationContext;
204
+ /** A new child on `target`, or the existing child continued when `null`. */
205
+ readonly target: DelegationTarget | null;
206
+ readonly selection: ModelSelection;
207
+ readonly background: boolean;
208
+ } | {
209
+ readonly kind: 'assignment';
210
+ readonly registration: AssignmentOwnerRegistration;
211
+ readonly callerThreadId: string;
212
+ readonly assignment: string;
213
+ readonly generation: number;
214
+ /** The caller's row that granted the assignment: ordered against stop obligations, never read as a call. */
215
+ readonly grantedSeq: Seq;
216
+ readonly configuration: PinnedConfiguration;
217
+ };
218
+ /** One start, as delegations' one admission reads it: the authority, the child and task it names, and what the task is. */
219
+ export type TaskStart = {
220
+ readonly authority: TaskAuthority;
221
+ readonly childId: string;
222
+ readonly taskId: string;
223
+ readonly task: string;
224
+ readonly rows: WriteRows | null;
225
+ readonly signal: AbortSignal;
226
+ };
227
+ /**
228
+ * What an owner says of one of its assignments: it still authorizes its task (`allow`), or not,
229
+ * typed by what admission does next (see {@link Admission}): `hold` while what it needs is
230
+ * unavailable, `discard` once the assignment is superseded or stopped, `refusal` when it is refused
231
+ * for good, which the owner turns into its own recovery.
232
+ */
233
+ export type OwnerVerdict = {
234
+ readonly kind: 'allow';
235
+ } | {
236
+ readonly kind: 'hold' | 'discard' | 'refusal';
237
+ readonly reason: string;
238
+ };
239
+ /** One task an owner's assignment opens or opened, as its owner judges it: what its origin records. */
240
+ export type AssignmentTask = TaskRef & {
241
+ readonly callerThreadId: string;
242
+ readonly assignment: string;
243
+ readonly generation: number;
244
+ readonly grantedSeq: Seq;
245
+ };
246
+ /**
247
+ * An owner of assignment-origin tasks, as it registers with delegations: its name, which its tasks'
248
+ * origins record, and its say over them. A name or an id grants nothing: only a live registration
249
+ * opens or runs an owner's task.
250
+ */
251
+ export type AssignmentOwner = {
252
+ readonly name: string;
253
+ /**
254
+ * Whether the assignment still authorizes `task`, read synchronously from facts the owner keeps
255
+ * loaded: in `opening`, inside the write that opens or continues the task, where anything but
256
+ * `allow` refuses that write with its kind; in `running`, whenever core asks whether the task's
257
+ * child may run, where anything but `allow` holds it. Ask again with `AssignmentOwnerHandle.changed`.
258
+ */
259
+ authorize(task: AssignmentTask, phase: 'opening' | 'running'): OwnerVerdict;
260
+ /**
261
+ * Told, in the listener of the write that settled it, that a task of its settled, however it did:
262
+ * completed, failed, or stopped by anyone, a generic stop included; its outcome is durable, read
263
+ * with `AssignmentOwnerHandle.outcome`. Once per task in a process: a task that settled before the owner
264
+ * registered, across a restart included, is told right after it registers, while it is its
265
+ * child's latest.
266
+ */
267
+ settled(task: AssignmentTask): void;
268
+ };
269
+ /** A live registration, as delegations keeps it, until it is disposed. */
270
+ export type AssignmentOwnerRegistration = {
271
+ readonly owner: AssignmentOwner;
272
+ disposed: boolean;
273
+ };
274
+ /**
275
+ * What an owner pins for a participant, exactly as its child is created on it and as a continuation
276
+ * finds it: the agent, the complete route and environment, the defining installations, each named
277
+ * by its id (delegations' admission refuses a start whose pin is not), and the constraint owners the
278
+ * child requires beside delegations' own, such as a check's that judges its answers.
279
+ */
280
+ export type PinnedConfiguration = {
281
+ readonly agent: string;
282
+ readonly route: ModelRoute;
283
+ readonly environment: DeepReadonly<ThreadEnvironment>;
284
+ readonly installations: readonly InitialInstallationInput[];
285
+ readonly requires: readonly string[];
286
+ };
287
+ /**
288
+ * One start an owner asks for: the task of one assignment on one participant generation, under the
289
+ * caller whose row granted it, in the participant's conversation. Delegations derives the task and
290
+ * child ids from these (`assignmentTaskId`, `assignmentChildId`), creates the child on `configuration`
291
+ * when it does not exist and continues it otherwise, so the owner asks the same way whether the
292
+ * conversation is new or kept.
293
+ */
294
+ export type AssignmentRequest = {
295
+ readonly callerThreadId: string;
296
+ readonly grantedSeq: Seq;
297
+ readonly instance: string;
298
+ readonly attempt: string;
299
+ readonly assignment: string;
300
+ readonly participant: string;
301
+ /** Whether the participant's conversation lives for the whole instance or for this attempt. */
302
+ readonly lifetime: 'instance' | 'attempt';
303
+ readonly generation: number;
304
+ readonly configuration: PinnedConfiguration;
305
+ /** The task's input on the child. */
306
+ readonly task: string;
307
+ /** The owner's own rows for the write that opens the task, as a call's `rows`. */
308
+ readonly rows?: WriteRows;
309
+ readonly signal: AbortSignal;
310
+ };
311
+ /** What an owner reads of one of its tasks: how it settled, if it has, who stopped it, if anyone did, and its latest prose. */
312
+ export type AssignmentOutcome = {
313
+ readonly settlement: TaskSettlement | null;
314
+ /** Who stopped it and why: a generic stop (its caller's `stop_agent`, a host, a stop above it) included. */
315
+ readonly stop: {
316
+ readonly by: StopBy;
317
+ readonly reason: string;
318
+ } | null;
319
+ /**
320
+ * The latest assistant text since the task's claim, whatever settled it, open or not: a partial
321
+ * report its owner may show, never an answer.
322
+ */
323
+ readonly latestText: string | null;
324
+ };
325
+ /** An owner's live registration, as `registerOwner` returns it. */
326
+ export type AssignmentOwnerHandle = {
327
+ /** Opens or replays the task `request` names, through delegations' one admission. */
328
+ start(request: AssignmentRequest): Promise<Admission>;
329
+ /** Task `task.taskId` as `task.childId` records it, or `null` when it records none. */
330
+ outcome(task: TaskRef): Promise<AssignmentOutcome | null>;
331
+ /** The owner's verdict on `childId`'s task may have changed: core asks again. */
332
+ changed(childId: string): void;
333
+ /** Withdraws the registration: unfinished starts are refused inside their writes, and its tasks held. */
334
+ dispose(): void;
335
+ };
336
+ /** A task an admission opened or found opened: where it runs, and, when it has settled, what its caller is told. */
337
+ export type AdmittedTask = {
338
+ readonly taskId: string;
339
+ readonly childId: string;
340
+ readonly callerId: string;
341
+ readonly background: boolean;
342
+ /** The run request its opening write joined or opened, then each one it followed. */
343
+ readonly runId: string;
344
+ readonly outcome: DelegationOutcome | null;
345
+ };
346
+ /**
347
+ * What one admission decided, typed by what its starter does next rather than by its words:
348
+ * - `opened`: the task is open, by this write, or `replayed` from the write an earlier start of the
349
+ * same task made, which takes no slot and reopens nothing.
350
+ * - `wait`: try again once it changes: every slot of the origin tree is taken (`capacity`), or the
351
+ * child's earlier task, its run, its notice, its cleanup or its commands are still ending
352
+ * (`predecessor`).
353
+ * - `hold`: something admission must read is unreadable or unavailable now: a task state, the
354
+ * origin root, the owner an assignment needs, or what its owner says it needs.
355
+ * - `discard`: superseded: a stop over the caller, the end of the caller's own task, its owner
356
+ * saying so, or the start's own cancellation, means nothing will open it.
357
+ * - `refusal`: durable for this child as asked: not one delegations manages, cancelled by a person,
358
+ * stopped mid-work, commands with no established end, a role whose tools are missing, a caller
359
+ * at its chain limit, or its owner refusing the assignment.
360
+ * - `conflict`: a start recorded under the task's identity differs from this one (its origin, or an
361
+ * owner's task input or pinned configuration), or the child exists without it or is not the
362
+ * owner's to continue; never adopted or replaced.
363
+ * - `vetoed`: the caller's own `rows` vetoed the write, for the reason it gave.
364
+ * Each kind but `opened` leaves nothing behind.
365
+ */
366
+ export type Admission = {
367
+ readonly kind: 'opened';
368
+ readonly task: AdmittedTask;
369
+ readonly replayed: boolean;
370
+ } | {
371
+ readonly kind: 'wait';
372
+ readonly on: 'capacity' | 'predecessor';
373
+ readonly reason: string;
374
+ } | {
375
+ readonly kind: 'hold' | 'discard' | 'refusal' | 'conflict' | 'vetoed';
376
+ readonly reason: string;
377
+ };
378
+ /** An admission that did not open its task. */
379
+ export type AdmissionRefused = Exclude<Admission, {
380
+ kind: 'opened';
381
+ }>;
@@ -0,0 +1,30 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * A sub-agent type given as configuration. Frozen: restoring requires a recorded configuration to
4
+ * parse back to itself, so any change, even a new field with a default, would strand every existing
5
+ * role child. Hence three fields and no more.
6
+ */
7
+ export declare const RoleConfigSchema: z.ZodObject<{
8
+ id: z.ZodString;
9
+ basePrompt: z.ZodString;
10
+ tools: z.ZodArray<z.ZodString>;
11
+ }, z.core.$strict>;
12
+ export type RoleConfig = z.output<typeof RoleConfigSchema>;
13
+ export type RoleConfigInput = z.input<typeof RoleConfigSchema>;
14
+ /** The role preset's id, registered by the `delegations` plugin when it mounts. */
15
+ export declare const ROLE_PRESET = "role";
16
+ /**
17
+ * Defines a role child's agent in the child's own layer: the agent named by the role id, with the
18
+ * role's base prompt, granted the role's tools. Recorded only at creation, by the delegations
19
+ * service for a role target, on a thread whose agent is the role id; the presets service checks that
20
+ * binding before anything is recorded.
21
+ *
22
+ * It does not check that the tools exist: a grant to a missing tool resolves to nothing, and a check
23
+ * here would stop existing children from ever activating once a root tool is renamed. The
24
+ * delegations service checks them before creating a child.
25
+ */
26
+ export declare const rolePreset: import("../../services/preset.js").Preset<z.ZodObject<{
27
+ id: z.ZodString;
28
+ basePrompt: z.ZodString;
29
+ tools: z.ZodArray<z.ZodString>;
30
+ }, z.core.$strict>>;