@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,373 @@
1
+ import { type AnswerCheck } from '../../loop/index.js';
2
+ import type { JournalEvent, Seq } from '../../models/index.js';
3
+ import type { ReadonlyState } from '../../util/foldState.js';
4
+ import type { JsonValue, ReadonlyJsonValue } from '../../util/json.js';
5
+ import type { WorkflowDefinition } from './definition.js';
6
+ import { type Citation, type Decided, type Entered, type InstanceRow, type Observation, type Opened } from './record.js';
7
+ /**
8
+ * Where an assignment stands: `scheduled` until its activation input is claimed, `active` from that
9
+ * claim, `candidate` while a submission of it is the answer under check, `accepted` once core
10
+ * accepts that answer, and `superseded` once its authority closed without acceptance.
11
+ */
12
+ export type AssignmentState = 'scheduled' | 'active' | 'candidate' | 'accepted' | 'superseded';
13
+ /**
14
+ * A submitted output, the `tool/result` row that recorded it, and the `tool/call` row of the call
15
+ * that made it (`null` when the result cites none).
16
+ */
17
+ export type Submitted = {
18
+ readonly output: JsonValue;
19
+ readonly seq: Seq;
20
+ readonly call: Seq | null;
21
+ };
22
+ /**
23
+ * The search for a replacement activation input, once the recorded one was removed before its claim
24
+ * (a Stop's clear, a withdrawal): the unsourced inputs queued on the root since that removal and still
25
+ * queued, in queue order, each with whether a person's wake brought it.
26
+ */
27
+ export type Replacement = {
28
+ readonly queued: {
29
+ readonly id: string;
30
+ person: boolean;
31
+ }[];
32
+ };
33
+ export type AssignmentRecord = {
34
+ readonly id: string;
35
+ readonly participant: string;
36
+ /** Whether the conversation participant works it on the root, or an isolated one on its child. */
37
+ readonly context: 'conversation' | 'isolated';
38
+ /** The thread it runs in: the root, or the participant's child. */
39
+ readonly thread: string;
40
+ /** Its delegation task on the child; `null` on the root. */
41
+ readonly task: string | null;
42
+ /** The participant generation it was pinned to; `null` on the root. */
43
+ readonly generation: number | null;
44
+ /** Whether an isolated one's child is the participant's own conversation or its attempt's; `null` on the root. */
45
+ readonly lifetime: 'instance' | 'attempt' | null;
46
+ /** The check providers judging an isolated one's answer, as its entry recorded them; none on the root. */
47
+ readonly checks: readonly string[];
48
+ /**
49
+ * The input recorded as its activation: on the root, the host's first input or its transition's
50
+ * scheduling input; on a child, its task's input.
51
+ */
52
+ readonly activation: string;
53
+ state: AssignmentState;
54
+ /** Set once its root activation input was removed unclaimed; see {@link activationInput}. */
55
+ replacement: Replacement | null;
56
+ /** The root's `input/message` row that claimed its activation input; a child's claim is the child's. */
57
+ claimSeq: Seq | null;
58
+ /** The submission under check on the root, while it is the root's answer. */
59
+ candidate: Submitted | null;
60
+ /**
61
+ * Its latest submission, kept whatever became of it: diagnostic history apart from the answer
62
+ * under check, which a recovery shows its producer and the coordinator, labeled unaccepted.
63
+ */
64
+ submitted: Submitted | null;
65
+ /**
66
+ * The submission accepted: latched, so later input never takes it back. For an isolated
67
+ * participant, its output as the root's observation of the child carried it, at that row.
68
+ */
69
+ accepted: Submitted | null;
70
+ /** The epoch of the latest submission reminder it was sent ({@link submissionReminder}). */
71
+ reminded: Seq | null;
72
+ /**
73
+ * The root row at which its authority closed: the turn ending that accepted it, the observation
74
+ * that carried its child's acceptance, or the row that superseded it. `null` while it is open.
75
+ */
76
+ closed: Seq | null;
77
+ };
78
+ export type AttemptRecord = {
79
+ readonly entered: Entered;
80
+ readonly seq: Seq;
81
+ readonly assignments: readonly AssignmentRecord[];
82
+ /** Its result, once every assignment is accepted; at entry for a pure gate. Never once it recovers. */
83
+ result: string | null;
84
+ /** Its recovery, once an isolated participant's task ended without acceptance. */
85
+ recovery: RecoveryRecord | null;
86
+ };
87
+ /**
88
+ * An attempt that will produce no result, and the one decision a person owes on it: its assignment
89
+ * authority closed at its boundary, and what it shows is frozen there, so later events change none
90
+ * of it. An accepted sibling keeps its history, but never makes a partial result.
91
+ */
92
+ export type RecoveryRecord = {
93
+ /** A participant's task ended without acceptance (`failure`), or a person stopped the attempt (`stop`). */
94
+ readonly cause: 'failure' | 'stop';
95
+ readonly detail: string;
96
+ /** The row that opened it: its boundary. */
97
+ readonly seq: Seq;
98
+ /** By participant, unaccepted: each one's latest submission, and its partial report. */
99
+ readonly candidates: Readonly<Record<string, JsonValue>>;
100
+ readonly reports: Readonly<Record<string, string>>;
101
+ /** The decision on it, once one is recorded. */
102
+ decision: string | null;
103
+ };
104
+ /** An accepted result: the outputs of one attempt, by participant, and what happened to it. */
105
+ export type ResultRecord = {
106
+ readonly revision: string;
107
+ readonly attempt: string;
108
+ readonly step: string;
109
+ readonly outputs: Readonly<Record<string, JsonValue>>;
110
+ /** The row that completed it: the last acceptance, or a pure gate's entry. */
111
+ readonly seq: Seq;
112
+ /** The host decision on it, once one is recorded. */
113
+ decision: string | null;
114
+ /** The transition it, or its decision, made. */
115
+ routed: string | null;
116
+ /** Retired by its own step's re-entry. Its dependents go stale with it ({@link staleResults}). */
117
+ retired: boolean;
118
+ };
119
+ export type DecisionRecord = Decided & {
120
+ readonly seq: Seq;
121
+ };
122
+ /**
123
+ * The fold's records as a reader holds them from `journal.state`: read-only views of what the
124
+ * reducer mutates. A function that only reads takes the view, so the reducer and a reader share it.
125
+ */
126
+ export type AssignmentView = ReadonlyState<AssignmentRecord>;
127
+ export type AttemptView = ReadonlyState<AttemptRecord>;
128
+ export type RecoveryView = ReadonlyState<RecoveryRecord>;
129
+ export type ResultView = ReadonlyState<ResultRecord>;
130
+ /** A cancellation admitted, or a decision recorded, under its operation id: what a replay compares. */
131
+ export type Operation = Extract<InstanceRow, {
132
+ op: 'decided' | 'cancel-requested';
133
+ }>;
134
+ /**
135
+ * One workflow instance as its root's rows leave it, recorded facts only: nothing here depends on
136
+ * which definitions are registered. What is pending, where it goes next and what may run are
137
+ * derived from it, with the definition, by `routing.ts` and `view.ts`.
138
+ */
139
+ export type InstanceState = {
140
+ /** The instance's id: its root thread's, which every identity it derives starts with. */
141
+ instance: string | null;
142
+ opened: Opened | null;
143
+ /** Every attempt by id, in entry order. */
144
+ readonly attempts: Map<string, AttemptRecord>;
145
+ /** The latest attempt. */
146
+ current: AttemptRecord | null;
147
+ /** Every result by revision, in the order they were accepted. */
148
+ readonly results: Map<string, ResultRecord>;
149
+ readonly decisions: Map<string, DecisionRecord>;
150
+ readonly operations: Map<string, Operation>;
151
+ /** Each step's entries over the instance's life. */
152
+ readonly ordinals: Map<string, number>;
153
+ /** Each step's entries since the latest host decision: what its `maxAttempts` bounds. */
154
+ readonly counts: Map<string, number>;
155
+ /** Each restarted participant's conversation generation; see {@link generationOf}. */
156
+ readonly generations: Map<string, number>;
157
+ /** Every acceptance or ending observed of a child, by its task: one per task, the first; later ones are kept nowhere. */
158
+ readonly observed: Map<string, Observation & {
159
+ readonly seq: Seq;
160
+ }>;
161
+ /**
162
+ * The latest person's Stop of the instance (its `stopped` row and why): the boundary a transition
163
+ * owed by a result ready before it is judged against ({@link stopOwed}).
164
+ */
165
+ stop: {
166
+ readonly seq: Seq;
167
+ readonly reason: string;
168
+ } | null;
169
+ cancellation: Extract<InstanceRow, {
170
+ op: 'cancel-requested';
171
+ }> | null;
172
+ terminal: null | {
173
+ readonly kind: 'completed';
174
+ readonly transition: string;
175
+ } | {
176
+ readonly kind: 'cancelled';
177
+ };
178
+ /** The thread's answer under check, as core's stop checks fold it. */
179
+ answer: AnswerCheck;
180
+ /** The root's latest response and its calls, which the response fence orders a call by. */
181
+ readonly calls: Map<Seq, number>;
182
+ response: ResponseCalls['response'];
183
+ /** The root's latest unsourced input: a person's. */
184
+ personAt: Seq | null;
185
+ };
186
+ /**
187
+ * A thread's latest response that asked for calls, and its `tool/call` rows by seq, each with the
188
+ * call's position in that response: what the response fence orders a call by, on the root and on a
189
+ * participant's child alike.
190
+ */
191
+ export type ResponseCalls = {
192
+ readonly calls: Map<Seq, number>;
193
+ /** The latest `assistant/message` that asked for calls, and their ids in order. */
194
+ response: {
195
+ readonly seq: Seq;
196
+ readonly ids: readonly string[];
197
+ } | null;
198
+ };
199
+ /**
200
+ * Whether the call recorded at `callSeq` comes after the submission whose call is `submittedCall` in
201
+ * the response that asked for both: core does not stop the rest of a batch after a concluding
202
+ * result, and records every call of it before any runs, so the calls after a submission under check
203
+ * are fenced by their position in that response, never by row order. The submission's own call is
204
+ * not after itself, so its replay stands.
205
+ */
206
+ export declare function fencedCall(thread: ReadonlyState<ResponseCalls>, submittedCall: Seq | null, callSeq: Seq | undefined): boolean;
207
+ /** What {@link live} reads of an instance's state. */
208
+ type Liveness = {
209
+ readonly opened: unknown;
210
+ readonly terminal: unknown;
211
+ readonly cancellation: unknown;
212
+ };
213
+ /** Whether the instance can still take work: opened, not ending and not ended. */
214
+ export declare const live: (state: Liveness) => boolean;
215
+ /**
216
+ * The instance a root thread holds, folded from this plugin's rows and core's. The root's own
217
+ * assignment activates when a step claims its activation input (`input/message.input_id`), or the
218
+ * person's input replacing it once it was removed unclaimed ({@link activationInput}); its
219
+ * submission is a candidate while it is the answer under check; and it is accepted, latched, when
220
+ * core accepts that exact answer: the turn ending `completed` with the submission's result as the
221
+ * pending answer, read with core's own `answerCheck`. So nothing is written to accept, and core's
222
+ * answer check resetting on later input takes nothing back. An isolated participant's assignment
223
+ * is accepted, or its attempt recovers, by the root's observation of its child (`observed`), which
224
+ * carries the child's facts across, since this fold cannot read them; a person's Stop (`stopped`)
225
+ * recovers an attempt whose isolated work is still open. Submissions, claims, endings and
226
+ * observations outside the current attempt's open assignments are evidence only and advance
227
+ * nothing.
228
+ *
229
+ * Resets at a fork's spawn row: a fork inherits no workflow state.
230
+ */
231
+ export declare const instanceFold: import("../../journal/projection.js").PluginProjection<InstanceState>;
232
+ /**
233
+ * The input whose claim activates a scheduled assignment now: its recorded activation input while
234
+ * that was not removed; after a removal, the first input queued on the root since then that is
235
+ * still queued and that a person's wake brought; `null` while there is none. Each later removal
236
+ * reselects, since a removed input leaves the queue. Sourced input never qualifies, nor unsourced
237
+ * input without a person's wake: the host's own notices are not a person's.
238
+ */
239
+ export declare function activationInput(assignment: AssignmentView): string | null;
240
+ /** A response that asks for calls: the one later `tool/call` rows are placed in. A cut-off reply asks for none. */
241
+ export declare function respond(state: ResponseCalls, event: JournalEvent<'assistant/message'>): void;
242
+ /** A call of the latest response recorded: its position in that response, by its row. */
243
+ export declare function call(state: ResponseCalls, event: JournalEvent<'tool/call'>): void;
244
+ /**
245
+ * The epoch of `assignment`'s submission reminder: the later of its activation's claim and the
246
+ * person's latest input. `null` while it is not active.
247
+ */
248
+ export declare function reminderEpoch(state: ReadonlyState<InstanceState>, assignment: AssignmentView): Seq | null;
249
+ /**
250
+ * What an instance's continuation refers to in its definition, from recorded facts alone, so a
251
+ * root's catalog entry can carry it and the check needs nothing loaded: the definition's id; while it
252
+ * is live, the step it stands on; and each participant whose assignment of the current attempt is
253
+ * still open (`open`), or that has a conversation of its own in the instance, which later steps
254
+ * continue (`persistent`), with the context it was recorded in.
255
+ */
256
+ export type DefinitionReferences = {
257
+ readonly id: string;
258
+ readonly step: string | null;
259
+ readonly participants: Readonly<Record<string, {
260
+ readonly context: 'conversation' | 'isolated';
261
+ readonly open: boolean;
262
+ }>>;
263
+ };
264
+ /**
265
+ * The participants with a conversation of their own in the instance, as their entries recorded
266
+ * them (an isolated assignment of `instance` lifetime), each with its current generation's child:
267
+ * the one later entries continue. A generation a restart superseded is history, not listed.
268
+ */
269
+ export declare function persistentConversations(state: ReadonlyState<InstanceState>): Map<string, string>;
270
+ /** What `state`'s continuation refers to in its definition ({@link DefinitionReferences}). */
271
+ export declare function definitionReferences(state: ReadonlyState<InstanceState>): DefinitionReferences;
272
+ /**
273
+ * Why an instance cannot continue on `registered`, the definition registered under its id now, or
274
+ * `null` when it can (the recovery compatibility check): the one rule every reader of execution
275
+ * applies. Execution always takes the definition registered now, so an edit applies to a running
276
+ * instance from its next action, and accepted results stay as recorded. It is held only where it
277
+ * literally cannot go on: no definition is registered under its id; the step it stands on is gone;
278
+ * a participant with an open assignment is gone, changed context (conversation or isolated) or is no
279
+ * longer assigned by that step; or a participant with a conversation of its own in the instance is
280
+ * gone or no longer isolated. What an entered attempt recorded at entry (each assignment's
281
+ * participant, child, lifetime, generation and checks) is its contract while its assignments are
282
+ * open, so an edit to those applies from the next entry; prompts and schemas apply from the next
283
+ * presentation or submission. Edge targets, options and restart choices are derived from the
284
+ * definition at each read, and registration checks they resolve, so none can dangle; an isolated
285
+ * participant or provider the opening never pinned refuses the entry that needs it.
286
+ */
287
+ export declare function heldBy(references: DefinitionReferences, registered: WorkflowDefinition | undefined): string | null;
288
+ /**
289
+ * The definition an instance executes by: the one registered under its id now, unless the instance
290
+ * cannot continue on it ({@link heldBy}). `undefined` then: execution is blocked
291
+ * (`missing-binding`), while reads, cancellation and a terminal outcome stay, and registering a
292
+ * definition that fits resumes it. An availability condition derived at each read, never part of
293
+ * the fold.
294
+ */
295
+ export declare function executable(state: ReadonlyState<InstanceState>, registered: WorkflowDefinition | undefined): WorkflowDefinition | undefined;
296
+ /** What a decision decides: the step's accepted outputs, and every input its attempt bound at entry. */
297
+ export type Subject = {
298
+ readonly outputs: Readonly<Record<string, ReadonlyJsonValue>>;
299
+ readonly inputs: Readonly<Record<string, {
300
+ readonly value: ReadonlyJsonValue;
301
+ readonly citation: Citation | null;
302
+ }>>;
303
+ };
304
+ /** The decision reasons. */
305
+ export type DecisionReason = 'gate' | 'exhaustion' | 'recovery';
306
+ /** The persistent participants one revise choice may name in `restart`, and those it must name. */
307
+ export type RestartChoice = {
308
+ readonly required: readonly string[];
309
+ readonly allowed: readonly string[];
310
+ };
311
+ /** A decision a person owes, derived from the facts that make it pending; `decide` addresses its `id`. */
312
+ export type PendingDecision = {
313
+ readonly id: string;
314
+ readonly attempt: string;
315
+ readonly reason: DecisionReason;
316
+ /** The cited result revision; `null` for recovery. */
317
+ readonly result: string | null;
318
+ /** Exactly what is decided, from recorded facts: a card renders it and never re-resolves bindings. */
319
+ readonly subject: Subject;
320
+ /** What `decide` would take now. Empty verdicts while execution is blocked or cleanup is pending. */
321
+ readonly actions: {
322
+ /**
323
+ * Whether a recovery's cleanup is not established yet: its attempt's work still ending, or of
324
+ * unknown end. No verdict is offered meanwhile, and `decide` refuses without consuming it.
325
+ */
326
+ readonly cleanupPending: boolean;
327
+ readonly verdicts: readonly ('approve' | 'revise')[];
328
+ readonly options: readonly string[];
329
+ /**
330
+ * By revise choice: a plain retry, and each option offered. Empty but on a recovery, the only
331
+ * decision that restarts anyone; its required restarts are the allowed participants whose
332
+ * conversation delegations would not continue now.
333
+ */
334
+ readonly restart: {
335
+ readonly retry: RestartChoice;
336
+ readonly options: Readonly<Record<string, RestartChoice>>;
337
+ };
338
+ };
339
+ readonly detail: {
340
+ /** The transition exhaustion held back. */
341
+ readonly blocked?: {
342
+ readonly from: string;
343
+ readonly to: string;
344
+ };
345
+ readonly recovery?: {
346
+ readonly cause: 'failure' | 'stop';
347
+ readonly detail: string;
348
+ readonly candidates: Readonly<Record<string, ReadonlyJsonValue>>;
349
+ readonly reports: Readonly<Record<string, string>>;
350
+ };
351
+ };
352
+ };
353
+ /** The routing envelope's decision: what a person decided on a result. */
354
+ export type ResultDecision = {
355
+ readonly reason: DecisionReason;
356
+ readonly verdict: 'approve' | 'revise';
357
+ readonly option: string | null;
358
+ readonly feedback: string | null;
359
+ };
360
+ /** The host decision that opened an attempt, by identity; presented with it, so feedback needs no binding. */
361
+ export type AttemptCause = {
362
+ readonly decision: string;
363
+ /** The attempt the decision was made on. */
364
+ readonly attempt: string;
365
+ readonly verdict: 'approve' | 'revise';
366
+ readonly option: string | null;
367
+ readonly feedback: string | null;
368
+ };
369
+ /** What opened `attempt`, when a host decision did; `null` for the opening and automatic routing. */
370
+ export declare function attemptCause(state: ReadonlyState<InstanceState>, attempt: AttemptView): AttemptCause | null;
371
+ /** The subject of a decision on `attempt`: its result's outputs, and its inputs as bound. */
372
+ export declare function subjectOf(state: ReadonlyState<InstanceState>, attempt: AttemptView): Subject;
373
+ export {};
@@ -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/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 { WorkflowRefusedError } from './service.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 './providers.js';
25
+ export type { DecisionReason, PendingDecision, ResultDecision, Subject } from './fold.js';
26
+ export type { Citation } from './record.js';
27
+ export type { InstanceView } from './view.js';
28
+ export type { Restriction } from './policy.js';