@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,38 @@
1
+ import type { Context } from '@leuduan/cordis';
2
+ import type { AppendEntry } from '../../journal/index.js';
3
+ import { type InstanceState } from './state.js';
4
+ import type { InstanceRowInput } from './record.js';
5
+ import type { Barrier } from './routing.js';
6
+ import type { ReadonlyState } from '../../util/foldState.js';
7
+ /**
8
+ * The one evidence barrier an instance's cancellation, its pending recovery's decision, the restarts
9
+ * that decision names and the successor it opens all wait on (decision 18 of the slice-2 plan). The
10
+ * lifetime owners answer for their own work, from durable evidence ({@link workUnder}): commands for
11
+ * whether each command ended, delegations for each task's settlement, cleanup and stop
12
+ * acknowledgement, and for whether a conversation can take another task (`continuation`). This
13
+ * combines them over what the instance owns:
14
+ *
15
+ * - an admitted cancellation: everything under the root;
16
+ * - a pending recovery: its attempt's isolated participants' children and everything under them,
17
+ * with the root's stops of them; on a mixed step, whose root assignment it superseded too, also
18
+ * the root's own work: its commands, the threads it started and the run that was under way at
19
+ * the recovery's boundary; and each persistent participant's conversation, which is
20
+ * draining while delegations says to wait, unknown while it cannot be asked (delegations not
21
+ * mounted, the child not loaded), unresolved while its task state cannot be read, and
22
+ * uncontinuable, so a decision must restart it, once delegations refuses it more work.
23
+ *
24
+ * Either way, a participant's start still in flight (`starting`, its assignments) is work still
25
+ * ending: it may yet open a task, or find its assignment superseded and open none. Anything else
26
+ * waits on nothing. Read synchronously, inside a write or while the threads it reads are held loaded.
27
+ */
28
+ export declare function barrierOf(ctx: Context, state: ReadonlyState<InstanceState>, starting: readonly string[]): Barrier;
29
+ /**
30
+ * The stop obligation, for the root write that records `row`, over the tasks a recovery it opens
31
+ * leaves running: when one of its observations ends a task without acceptance, the attempt recovers,
32
+ * and every other open isolated assignment's task that delegations' records show open or still
33
+ * draining is stopped for good, so nothing of the attempt keeps working while a person decides.
34
+ * Delegations carries it out from that write, or at its next repair. None otherwise.
35
+ */
36
+ export declare function siblingStops(ctx: Context, state: ReadonlyState<InstanceState>, row: Extract<InstanceRowInput, {
37
+ op: 'observed';
38
+ }>): AppendEntry<'ext'>[];
@@ -0,0 +1,184 @@
1
+ import { z } from 'zod';
2
+ import { type ThinkingEffort } from '../../llm/primitives.js';
3
+ import { type ReadonlyJsonValue } from '../../util/json.js';
4
+ import type { ResultDecision } from './state.js';
5
+ /** The edge target that completes an instance. */
6
+ export declare const COMPLETE = "$complete";
7
+ /** A value an edge predicate compares a field with. */
8
+ export type JsonScalar = string | number | boolean | null;
9
+ /** An isolated participant's model: a default, and whether the instance's starter may change it. */
10
+ export type ParticipantModel = {
11
+ readonly provider: string;
12
+ readonly model: string;
13
+ readonly thinkingEffort?: ThinkingEffort;
14
+ readonly configurable: boolean;
15
+ };
16
+ export type Participant =
17
+ /** The root's own agent. */
18
+ {
19
+ readonly context: 'conversation';
20
+ }
21
+ /** A delegated agent the workflow starts itself, under a host-bound role. */
22
+ | {
23
+ readonly context: 'isolated';
24
+ readonly lifetime: 'instance' | 'attempt';
25
+ readonly role: string;
26
+ readonly model: ParticipantModel;
27
+ };
28
+ export type Binding = {
29
+ /** The instance's input, a step's whole result, or one participant's output in it. */
30
+ readonly source: '$input' | {
31
+ readonly step: string;
32
+ readonly participant?: string;
33
+ };
34
+ readonly mode: 'current' | 'historical';
35
+ readonly optional: boolean;
36
+ }
37
+ /** A host-bound evidence provider, resolved at attempt entry. */
38
+ | {
39
+ readonly evidence: string;
40
+ readonly optional: boolean;
41
+ };
42
+ export type Assignment = {
43
+ readonly participant: string;
44
+ /** The step inputs this assignment receives. */
45
+ readonly reads: readonly string[];
46
+ readonly prompt: string;
47
+ readonly output: z.ZodType;
48
+ /** Host-bound check providers judging an isolated participant's answer; omitted = []. */
49
+ readonly checks?: readonly string[];
50
+ };
51
+ /** A choice a person may attach to a `revise`, with the decision reasons it may accompany. */
52
+ export type StepOption = {
53
+ readonly name: string;
54
+ readonly on: readonly ('gate' | 'recovery')[];
55
+ };
56
+ /** One condition of an edge: the JSON Pointer `field` of the routing envelope equals `equals`. */
57
+ export type Condition = {
58
+ readonly field: string;
59
+ readonly equals: JsonScalar;
60
+ };
61
+ export type Edge = {
62
+ readonly when: readonly Condition[] | 'otherwise';
63
+ readonly to: string;
64
+ };
65
+ export type Step = {
66
+ readonly inputs: Readonly<Record<string, Binding>>;
67
+ readonly assignments: readonly Assignment[];
68
+ /** A person's decision after every assignment is accepted. */
69
+ readonly gate: boolean;
70
+ /** Omitted = []. */
71
+ readonly options?: readonly StepOption[];
72
+ /** A host-bound allowlist policy name; `null` adds no step restriction. */
73
+ readonly restriction: string | null;
74
+ readonly maxAttempts: number;
75
+ /** Evaluated in order over the step's result; the first match is taken. The last is `otherwise`. */
76
+ readonly edges: readonly Edge[];
77
+ };
78
+ /**
79
+ * A workflow as its author writes it, handed to {@link defineWorkflow}. Its `id` is its whole
80
+ * identity: an edit that keeps the procedure's meaning (a prompt, a schema, an allowance) keeps the
81
+ * id and applies to running instances from their next action; a breaking one gets a new id.
82
+ */
83
+ export type Definition = {
84
+ readonly id: string;
85
+ /** The instance's input. */
86
+ readonly input: z.ZodType;
87
+ readonly entry: string;
88
+ /** Host-bound checks on the conversation participant's agent; omitted = []. */
89
+ readonly prerequisites?: readonly string[];
90
+ readonly participants: Readonly<Record<string, Participant>>;
91
+ readonly steps: Readonly<Record<string, Step>>;
92
+ };
93
+ /** A definition's data with every omitted list filled in: what is validated. */
94
+ export type DefinitionData = Omit<Definition, 'prerequisites' | 'steps'> & {
95
+ readonly prerequisites: readonly string[];
96
+ readonly steps: Readonly<Record<string, Omit<Step, 'options' | 'assignments'> & {
97
+ readonly options: readonly StepOption[];
98
+ readonly assignments: readonly (Assignment & {
99
+ readonly checks: readonly string[];
100
+ })[];
101
+ }>>;
102
+ };
103
+ /** A schema as its JSON Schema rendering: what the model is shown and an instance records. */
104
+ export type JsonSchema = {
105
+ readonly [key: string]: ReadonlyJsonValue;
106
+ };
107
+ /**
108
+ * A definition as plain JSON: its data, omitted lists filled in, with every schema replaced by its
109
+ * rendering. It is the readable copy an instance records for audit and display, never executed.
110
+ */
111
+ export type CanonicalDefinition = Omit<DefinitionData, 'input' | 'steps'> & {
112
+ readonly input: JsonSchema;
113
+ readonly steps: Readonly<Record<string, Omit<DefinitionData['steps'][string], 'assignments'> & {
114
+ readonly assignments: readonly (Omit<DefinitionData['steps'][string]['assignments'][number], 'output'> & {
115
+ readonly output: JsonSchema;
116
+ })[];
117
+ }>>;
118
+ };
119
+ /**
120
+ * A defined workflow: a frozen, canonical copy of the author's definition, admitted. Only
121
+ * {@link defineWorkflow} makes one, and registration takes nothing else. Its validators are rebuilt
122
+ * from the admitted schemas and held apart ({@link schemaOf}), so nothing the host holds, and
123
+ * nothing reachable from the definition, can change what it validates.
124
+ */
125
+ export type WorkflowDefinition = CanonicalDefinition;
126
+ /** A definition refused, with every problem found. */
127
+ export declare class WorkflowDefinitionError extends Error {
128
+ readonly workflow: string;
129
+ readonly problems: readonly string[];
130
+ constructor(workflow: string, problems: readonly string[]);
131
+ }
132
+ export declare const isWorkflowDefinition: (value: unknown) => value is WorkflowDefinition;
133
+ /** The schema `definition` validates its input, or one assignment's output, with; for this plugin only. */
134
+ export declare function schemaOf(definition: WorkflowDefinition, target: '$input' | {
135
+ readonly step: string;
136
+ readonly participant: string;
137
+ }): z.ZodType;
138
+ /**
139
+ * Admits a workflow definition (§5 of the design): checks its shape, schemas and graph, then copies
140
+ * and freezes it. Every problem is reported at once in a {@link WorkflowDefinitionError}.
141
+ * Later changes to the object passed in change nothing about the definition returned. Names the host
142
+ * binds (restrictions, prerequisites, roles, providers) are checked when the definition is registered.
143
+ */
144
+ export declare function defineWorkflow(definition: Definition): WorkflowDefinition;
145
+ /** Splits a JSON Pointer into unescaped tokens, or `undefined` when it is not one. */
146
+ export declare function pointerTokens(pointer: string): string[] | undefined;
147
+ /** What a step's edges test: its accepted outputs by participant, and the decision on them. */
148
+ export type Envelope = {
149
+ readonly outputs: Readonly<Record<string, ReadonlyJsonValue>>;
150
+ readonly decision: ResultDecision | null;
151
+ };
152
+ /**
153
+ * The edge routing takes: the first, in declaration order, whose every condition holds over
154
+ * `envelope`; a missing field holds no condition. Registration makes the last edge `otherwise`, so
155
+ * one always matches.
156
+ */
157
+ export declare function selectEdge(edges: readonly Edge[], envelope: Envelope): Edge;
158
+ /** What a recovery's revise with `option` routes over: no outputs, and the decision. */
159
+ export declare const recoveryEnvelope: (option: string, feedback: string | null) => Envelope;
160
+ /**
161
+ * Why `edge`, selected for a recovery's revise with `option`, cannot take it, or `null`: it must
162
+ * guard both `/decision/reason = recovery` and `/decision/option = option`, so an `otherwise` or a
163
+ * match that happens to hold never routes a recovery, and it must enter a step, not complete the
164
+ * instance, which a recovery has no result to complete with.
165
+ */
166
+ export declare function recoveryEdgeProblem(edge: Edge, option: string): string | null;
167
+ /** What a host binds by name for its definitions: what registration checks they name. */
168
+ export type DefinitionBindings = {
169
+ /** Restriction policies, by name. */
170
+ readonly restrictions: ReadonlySet<string>;
171
+ /** Prerequisites the host checks, by name. */
172
+ readonly prerequisites: ReadonlySet<string>;
173
+ /** Roles isolated participants run under, by name. */
174
+ readonly roles: ReadonlySet<string>;
175
+ /** Check providers, by name. */
176
+ readonly checks: ReadonlySet<string>;
177
+ /** Evidence providers, by name. */
178
+ readonly evidence: ReadonlySet<string>;
179
+ };
180
+ /**
181
+ * Why `definition` cannot be registered against `bindings`: names it uses that the host does not
182
+ * bind. Whether a bound provider is available is asked at each opening, never here.
183
+ */
184
+ export declare function bindingProblems(definition: WorkflowDefinition, bindings: DefinitionBindings): string[];
@@ -0,0 +1,95 @@
1
+ import type { ReadonlyJsonValue } from '../../util/json.js';
2
+ import type { CanonicalDefinition } from './definition.js';
3
+ import type { InstanceState, ResultDecision } from './state.js';
4
+ import type { Acquired } from './hostBindings.js';
5
+ import type { ReadonlyState } from '../../util/foldState.js';
6
+ import { type Entered, type InstanceRowInput, type TransitionCause } from './record.js';
7
+ /**
8
+ * The results no longer current: each retired by its own step's re-entry (and `retiring`, retired
9
+ * by an entry being planned), and transitively each result whose attempt bound a stale one as a
10
+ * `current` input. Historical bindings need no freshness. A result binds only results accepted
11
+ * before it, so one pass in acceptance order settles every chain.
12
+ */
13
+ export declare const staleResults: (state: ReadonlyState<InstanceState>, retiring?: ReadonlySet<string>) => Set<string>;
14
+ /**
15
+ * The results that were no longer current when row `seq` was recorded: retired by the entries
16
+ * recorded up to it, and what was bound to those. What went stale after it is the difference from
17
+ * {@link staleResults}.
18
+ */
19
+ export declare function staleAsOf(state: ReadonlyState<InstanceState>, seq: number): Set<string>;
20
+ /** A recorded decision as the routing envelope carries it. */
21
+ export declare function resultDecision(state: ReadonlyState<InstanceState>, decision: string | null): ResultDecision | null;
22
+ /**
23
+ * The value input `name` of an attempt was bound to, as recorded: immutable results make a result's
24
+ * citation exact, and evidence is read from the entry that recorded it, never acquired again.
25
+ */
26
+ export declare function boundValue(state: ReadonlyState<InstanceState>, entered: ReadonlyState<Entered>, name: string): ReadonlyJsonValue;
27
+ /**
28
+ * A decision being planned in the same write as the entry: what it records on `result` (`null` for
29
+ * a recovery's), and the persistent participants it restarts, whose new generation the entry pins.
30
+ */
31
+ export type Deciding = {
32
+ readonly result: string | null;
33
+ readonly id: string;
34
+ readonly decision: ResultDecision;
35
+ readonly restart: readonly string[];
36
+ };
37
+ /** An entry refused: the input that could not be bound, and why. Nothing is retired or consumed. */
38
+ export type EntryRefusal = {
39
+ readonly refused: string;
40
+ };
41
+ /** The evidence an entry needs before it can be planned: what to acquire, for exactly this attempt. */
42
+ export type EvidenceNeeds = {
43
+ readonly transition: string;
44
+ readonly attempt: string;
45
+ readonly step: string;
46
+ readonly inputs: readonly {
47
+ readonly input: string;
48
+ readonly provider: string;
49
+ }[];
50
+ };
51
+ /** Evidence acquired outside the write, for one transition into one attempt, by input. */
52
+ export type EntryEvidence = {
53
+ readonly transition: string;
54
+ readonly attempt: string;
55
+ readonly inputs: ReadonlyMap<string, Acquired>;
56
+ };
57
+ /**
58
+ * Plans entering `step`, atomically: re-entry retires the step's current result, then every input
59
+ * binds against what remains, then the attempt opens with its assignments. The plan is one
60
+ * `entered` row, so its write retires, binds, opens and consumes the step's allowance together, or,
61
+ * refused, does none of it. Each assignment records where it runs and what activates it: the
62
+ * conversation participant's runs on the root, activated by `activation`, the host's first input at
63
+ * opening and the transition's scheduling input after; an isolated participant's runs as the task
64
+ * of its assignment on the child of its generation (the one a restart being decided gives it), its
65
+ * task's input activating it.
66
+ *
67
+ * - A `current` binding needs the producer's current result, approved if the step is gated; an
68
+ * optional one binds `null` only when the producer has accepted nothing (for that participant).
69
+ * A stale or unapproved result is not absence. The step's own current result is always retired
70
+ * by its entry, so an optional current self-binding binds `null`.
71
+ * - A `historical` binding takes the producer's latest accepted result, retired or stale included,
72
+ * such as the one this entry retires; optional when there is none yet.
73
+ * - An isolated participant the opening did not pin (one the definition registered now added, or
74
+ * moved off the conversation) cannot run: the entry is refused.
75
+ * - An evidence binding takes what its provider acquired for this very attempt (`evidence`), with
76
+ * the provider's citation, the value recorded in the row; once every other input binds, what is
77
+ * not acquired yet is returned as `needs`. Absence binds `null` when the binding is optional and
78
+ * refuses the entry otherwise; an unavailable answer refuses it either way.
79
+ */
80
+ export declare function planEntry(state: ReadonlyState<InstanceState>, definition: CanonicalDefinition, request: {
81
+ readonly instance: string;
82
+ readonly step: string;
83
+ readonly cause: TransitionCause;
84
+ readonly activation: string;
85
+ /** The decision this entry's write records, which bindings already see. */
86
+ readonly deciding?: Deciding;
87
+ /** Evidence acquired for the entry; used only when it is for this very transition and attempt. */
88
+ readonly evidence?: EntryEvidence;
89
+ }): {
90
+ readonly row: Extract<InstanceRowInput, {
91
+ op: 'entered';
92
+ }>;
93
+ } | EntryRefusal | {
94
+ readonly needs: EvidenceNeeds;
95
+ };
@@ -0,0 +1,146 @@
1
+ import { z } from 'zod';
2
+ import type { WriteRows } from '../../state/index.js';
3
+ import type { InitialInstallation, ThreadEnvironment } from '../../records/journal.js';
4
+ import type { DeepReadonly, JsonValue } from '../../util/json.js';
5
+ /**
6
+ * A conversation's configuration as a provider pins from it: the root's, as the host proposes to
7
+ * create it, or an isolated participant's, as its opening resolved it. Installation ids are left
8
+ * out: they name installations, they do not configure them.
9
+ */
10
+ export type Configured = DeepReadonly<{
11
+ environment: ThreadEnvironment;
12
+ installations: Omit<InitialInstallation, 'installation_id'>[];
13
+ }>;
14
+ /** What a binding tells the workflows that subscribe to it: its availability may have changed, or it is gone for good. */
15
+ export type ProviderNotice = 'availability' | 'disposed';
16
+ /** The pin a provider gives an opening, from which everything the instance asks of it is served; or why it cannot. */
17
+ export type PinOutcome = {
18
+ readonly config: JsonValue;
19
+ } | {
20
+ readonly refused: string;
21
+ };
22
+ /**
23
+ * What every provider binding is: a direct host binding, named by the definitions that use it. Its
24
+ * name is its whole identity, as a definition's id is: a change that would break the instances
25
+ * running on it binds under a new name. An instance records the serializable pin it was opened
26
+ * with, and runs only on a binding that still accepts that pin.
27
+ */
28
+ export type ProviderBinding = {
29
+ /** Why it cannot serve now, or `null` when it can; synchronous. */
30
+ unavailable(): string | null;
31
+ /** Why it cannot serve a pin recorded earlier, or `null` when it can. */
32
+ validate(config: DeepReadonly<JsonValue>): string | null;
33
+ /** The pin an opening records from `configured`; asked outside any write, cancellable. */
34
+ pin(configured: Configured, signal: AbortSignal): Promise<PinOutcome>;
35
+ /**
36
+ * Calls `listener` when what `unavailable` answers may have changed, and once with `disposed`
37
+ * when the binding is gone for good. Returns the unsubscribe.
38
+ */
39
+ subscribe(listener: (notice: ProviderNotice) => void): () => void;
40
+ };
41
+ /**
42
+ * One requirement a check records for an assignment, in the write that opens the assignment's task:
43
+ * the pin the instance recorded, the owner and assignment it is for, the participant generation
44
+ * serving it, and the input whose claim activates it, the task's.
45
+ */
46
+ export type CheckRequest = {
47
+ readonly config: DeepReadonly<JsonValue>;
48
+ readonly owner: string;
49
+ readonly assignment: string;
50
+ readonly generation: number;
51
+ readonly inputId: string;
52
+ };
53
+ /**
54
+ * A check provider: judges an isolated participant's answer through a requirement it owns. Its pin
55
+ * is taken from the configuration of each participant whose assignments list it. Every thread such
56
+ * an assignment runs on is created requiring `requires`, the constraint owners its judgement needs,
57
+ * so the thread is held rather than its answer accepted unchecked while the check's owner is
58
+ * missing; `owed` gives the rows recording the requirement, decided inside the write that opens the
59
+ * assignment's task, which they may refuse.
60
+ */
61
+ export type CheckProvider = ProviderBinding & {
62
+ readonly requires: readonly string[];
63
+ owed(request: CheckRequest): WriteRows;
64
+ };
65
+ /** What one acquisition found: a value with its citation detail, a genuine absence, or no answer now. */
66
+ export type Acquired = {
67
+ readonly kind: 'value';
68
+ readonly value: JsonValue;
69
+ /** Whether the value is a snapshot (`true`) or describes something live that can change. */
70
+ readonly immutable: boolean;
71
+ /** What the citation records of how it was acquired, such as a baseline. */
72
+ readonly detail: JsonValue;
73
+ }
74
+ /** There is nothing to bind: an optional binding binds `null`. */
75
+ | {
76
+ readonly kind: 'absent';
77
+ }
78
+ /** It could not be acquired now: never absence, so the entry is refused. */
79
+ | {
80
+ readonly kind: 'unavailable';
81
+ readonly reason: string;
82
+ };
83
+ /** One acquisition for an attempt's entry. */
84
+ export type EvidenceRequest = {
85
+ /** The pin the instance recorded at its opening. */
86
+ readonly config: DeepReadonly<JsonValue>;
87
+ readonly instance: string;
88
+ readonly attempt: string;
89
+ readonly step: string;
90
+ readonly input: string;
91
+ readonly signal: AbortSignal;
92
+ };
93
+ /**
94
+ * An evidence provider: supplies an input no participant produced, acquired at attempt entry
95
+ * outside the journal write. Its pin is taken from the root's configuration. A throw is an
96
+ * `unavailable` answer; an abort of the request's signal cancels the entry.
97
+ */
98
+ export type EvidenceProvider = ProviderBinding & {
99
+ acquire(request: EvidenceRequest): Promise<Acquired>;
100
+ };
101
+ export declare const CheckProviderSchema: z.ZodCustom<CheckProvider, CheckProvider>;
102
+ export declare const EvidenceProviderSchema: z.ZodCustom<EvidenceProvider, EvidenceProvider>;
103
+ /** What an instance records of one provider at its opening. */
104
+ export type ProviderPin = {
105
+ readonly config: JsonValue;
106
+ };
107
+ /**
108
+ * The providers one mount binds, as workflows holds them: it owns the subscription to each, the
109
+ * bindings that told it they are gone, and every acquisition in flight, which a provider's disposal
110
+ * or the mount's drain aborts and awaits. A binding is usable for a recorded pin only while it is
111
+ * not disposed, says it is available and accepts the pinned configuration.
112
+ */
113
+ export declare class Providers {
114
+ private readonly disposed;
115
+ private readonly inFlight;
116
+ private readonly drained;
117
+ private readonly bindings;
118
+ constructor(bindings: Providers['bindings']);
119
+ /** Subscribes to every binding: `changed` hears each notice, after a disposal is taken in. Returns the unsubscribe. */
120
+ watch(changed: (kind: 'check' | 'evidence', name: string, notice: ProviderNotice) => void): () => void;
121
+ /** Why `name` cannot serve `pin` now, or `null`: absent, gone, unavailable, or refusing the pin. */
122
+ problem(kind: 'check' | 'evidence', name: string, pin: DeepReadonly<ProviderPin> | undefined): string | null;
123
+ /**
124
+ * The pin an opening records for `name`, refused when it is unavailable or refuses `configured`;
125
+ * rejects only with {@link CancelledError}.
126
+ */
127
+ pin(kind: 'check' | 'evidence', name: string, configured: Configured, signal: AbortSignal): Promise<ProviderPin | {
128
+ readonly refused: string;
129
+ }>;
130
+ /**
131
+ * Acquires evidence from `name` under the instance's pin: `unavailable` when the binding cannot
132
+ * serve the pin or the provider fails; rejects only with {@link CancelledError}, cancelled by the
133
+ * request's signal, the provider's disposal or the drain.
134
+ */
135
+ acquire(name: string, pin: DeepReadonly<ProviderPin> | undefined, request: Omit<EvidenceRequest, 'config'>): Promise<Acquired>;
136
+ /** Aborts every acquisition and pin in flight, and waits for each provider's own work to settle. */
137
+ drain(): Promise<void>;
138
+ private table;
139
+ private dispose;
140
+ /** Runs `work` under a signal the caller's, the drain or the provider's disposal aborts, kept until it settles. */
141
+ private tracked;
142
+ }
143
+ /** An acquisition or pin cancelled: by its caller's signal, the provider's disposal or the mount's drain. */
144
+ export declare class CancelledError extends Error {
145
+ constructor(cause: unknown);
146
+ }
@@ -0,0 +1,28 @@
1
+ import type { Plugin } from '@leuduan/cordis';
2
+ import { type WorkflowsConfig } from './service.js';
3
+ /**
4
+ * Structured workflows: definitions made with `defineWorkflow` and registered here by the host, with
5
+ * the restriction policies and prerequisite checks they name, and the instances that run them,
6
+ * through the `ctx.workflows` service: `opening` for a root's creation, `read`, `decide`, `cancel`,
7
+ * and `stop` for a person's Stop of a root, which recovers isolated work it stops. Each
8
+ * instance's root and isolated participant is told its assignments at its model steps, granted
9
+ * `submit_workflow_output`, whose accepted answer alone advances it, and reminded once per epoch to
10
+ * submit; each, and every thread it starts, is restricted through the exact assignment serving it
11
+ * until the instance ends. An opening pins what the instance runs on (participants' configuration,
12
+ * the host's check and evidence providers), and entries acquire their evidence outside the journal
13
+ * write. Isolated participants' tasks are started by the plugin itself, as delegations' owner of
14
+ * them, independently of the root's turns; a definition with isolated participants needs
15
+ * delegations mounted first. All configuration is required. Root-only, mounted once by the
16
+ * application. See `docs/records/workflows.md`.
17
+ */
18
+ export declare const workflows: Plugin.Object<WorkflowsConfig>;
19
+ export { defineWorkflow, WorkflowDefinitionError } from './definition.js';
20
+ export type { Assignment, Binding, CanonicalDefinition, Condition, Definition, Edge, JsonScalar, JsonSchema, Participant, ParticipantModel, Step, StepOption, WorkflowDefinition, } from './definition.js';
21
+ export { resolveParticipantModels, WorkflowRefusedError } from './participantModels.js';
22
+ export { SUBMIT_TOOL, WORKFLOWS_OWNER } from './record.js';
23
+ export type { CancelRequest, CatalogEntry, DecideRequest, OpeningRequest, Prerequisite, StopCancel, RoleBinding, WorkflowsConfig, WorkflowsService, } from './service.js';
24
+ export type { Acquired, CheckProvider, CheckRequest, Configured, EvidenceProvider, EvidenceRequest, PinOutcome, ProviderBinding, ProviderNotice, } from './hostBindings.js';
25
+ export type { DecisionReason, PendingDecision, ResultDecision, Subject } from './state.js';
26
+ export type { Citation } from './record.js';
27
+ export type { InstanceView } from './view.js';
28
+ export type { Restriction } from './policy.js';