@parcha/agentrun-serve 0.1.0-beta.48 → 0.1.0-beta.50

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 (170) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +236 -26
  3. package/dist/agent-delete.d.ts +36 -12
  4. package/dist/agent-delete.js +213 -30
  5. package/dist/agents-store.d.ts +6 -2
  6. package/dist/agents-store.js +18 -5
  7. package/dist/agents.d.ts +8 -1
  8. package/dist/agents.js +14 -4
  9. package/dist/answer-json.d.ts +2 -2
  10. package/dist/answer-json.js +3 -4
  11. package/dist/api-only.d.ts +7 -10
  12. package/dist/api-only.js +9 -11
  13. package/dist/archil-routes.d.ts +1 -1
  14. package/dist/archil-routes.js +4 -3
  15. package/dist/browser-sessions.d.ts +56 -0
  16. package/dist/browser-sessions.js +117 -0
  17. package/dist/compute-cost.d.ts +101 -0
  18. package/dist/compute-cost.js +250 -0
  19. package/dist/computer-routes.d.ts +4 -15
  20. package/dist/computer-routes.js +6 -10
  21. package/dist/console/assets/index-D0mr9wfZ.css +1 -0
  22. package/dist/console/assets/index-D7G6o-1E.js +720 -0
  23. package/dist/console/index.html +2 -2
  24. package/dist/errors.d.ts +4 -1
  25. package/dist/errors.js +15 -5
  26. package/dist/eval-previous.d.ts +52 -0
  27. package/dist/eval-previous.js +164 -0
  28. package/dist/file-types.d.ts +2 -0
  29. package/dist/file-types.js +3 -1
  30. package/dist/harness.js +2 -1
  31. package/dist/import.js +4 -3
  32. package/dist/learn/check.d.ts +16 -4
  33. package/dist/learn/check.js +30 -26
  34. package/dist/learn/promote.d.ts +7 -1
  35. package/dist/learn/promote.js +47 -0
  36. package/dist/learn/repick.d.ts +43 -0
  37. package/dist/learn/repick.js +202 -0
  38. package/dist/learn/workflow-draft.d.ts +4 -0
  39. package/dist/learn/workflow-draft.js +10 -7
  40. package/dist/learned-workflow.d.ts +2 -0
  41. package/dist/learned-workflow.js +19 -2
  42. package/dist/learning-setting.d.ts +13 -0
  43. package/dist/learning-setting.js +23 -1
  44. package/dist/llms.txt +1 -1
  45. package/dist/openapi.js +180 -14
  46. package/dist/paid-calls.d.ts +17 -7
  47. package/dist/paid-calls.js +15 -9
  48. package/dist/run-launch.d.ts +2 -2
  49. package/dist/run-launch.js +2 -1
  50. package/dist/run-learning-served.d.ts +1 -1
  51. package/dist/run-timeline-served.js +5 -3
  52. package/dist/run-usage.d.ts +125 -0
  53. package/dist/run-usage.js +394 -0
  54. package/dist/runner/adapter-loop.d.ts +4 -0
  55. package/dist/runner/adapter-loop.js +66 -21
  56. package/dist/runner/adapter-run-spec.d.ts +8 -3
  57. package/dist/runner/adapter-run-spec.js +13 -6
  58. package/dist/runner/big-writes.d.ts +33 -0
  59. package/dist/runner/big-writes.js +105 -0
  60. package/dist/runner/cli-run-spec.js +14 -6
  61. package/dist/runner/conformance/harness.d.ts +2 -0
  62. package/dist/runner/conformance/harness.js +18 -4
  63. package/dist/runner/feedback-round.d.ts +29 -1
  64. package/dist/runner/feedback-round.js +54 -3
  65. package/dist/runner/held.d.ts +4 -1
  66. package/dist/runner/journal-kinds.d.ts +3 -1
  67. package/dist/runner/learning-end.js +54 -18
  68. package/dist/runner/loop-contract.d.ts +3 -0
  69. package/dist/runner/metrics.d.ts +4 -0
  70. package/dist/runner/metrics.js +9 -0
  71. package/dist/runner/monid-run.js +2 -2
  72. package/dist/runner/promotion.js +8 -2
  73. package/dist/runner/reflect-hook.js +3 -2
  74. package/dist/runner/run-child-host.d.ts +15 -2
  75. package/dist/runner/run-child-host.js +24 -8
  76. package/dist/runner/run-child.js +3 -0
  77. package/dist/runner/save-slots.d.ts +9 -0
  78. package/dist/runner/save-slots.js +91 -0
  79. package/dist/runs-over-store.d.ts +3 -2
  80. package/dist/runs-over-store.js +9 -7
  81. package/dist/sdk/runs.d.ts +3 -4
  82. package/dist/sdk/runs.js +10 -7
  83. package/dist/sdk/runtimes.d.ts +19 -0
  84. package/dist/sdk/runtimes.js +23 -0
  85. package/dist/sdk/schema.d.ts +14 -8
  86. package/dist/sdk/schema.js +18 -6
  87. package/dist/server.d.ts +7 -3
  88. package/dist/server.js +223 -100
  89. package/dist/store/agent-body.d.ts +2 -3
  90. package/dist/store/agent-body.js +3 -2
  91. package/dist/store/index.d.ts +2 -2
  92. package/dist/store/index.js +1 -1
  93. package/dist/store/journal/storage.js +1 -1
  94. package/dist/store/open.d.ts +1 -1
  95. package/dist/store/open.js +1 -1
  96. package/dist/store/postgres/migrations/0021_purged.sql +13 -0
  97. package/dist/store/postgres/migrations/0022_computer_intervals.sql +27 -0
  98. package/dist/store/postgres/migrations/0023_computer_interval_resources.sql +14 -0
  99. package/dist/store/schema.d.ts +20 -1
  100. package/dist/store/schema.js +60 -5
  101. package/dist/store/sqlite/connection.d.ts +4 -1
  102. package/dist/store/sqlite/connection.js +5 -0
  103. package/dist/store/sqlite/run-patch.d.ts +8 -3
  104. package/dist/store/sqlite/run-patch.js +15 -7
  105. package/dist/store/sqlite/store.d.ts +2 -1
  106. package/dist/store/sqlite/store.js +279 -68
  107. package/dist/store/sqlite/worker.d.ts +9 -0
  108. package/dist/store/sqlite/worker.js +18 -1
  109. package/dist/store/store.d.ts +149 -9
  110. package/dist/store/store.js +63 -0
  111. package/dist/store-reads/analytics.js +2 -1
  112. package/dist/store-reads/cap.d.ts +17 -7
  113. package/dist/store-reads/cap.js +54 -4
  114. package/dist/store-reads/decisions.d.ts +21 -0
  115. package/dist/store-reads/decisions.js +22 -0
  116. package/dist/store-reads/journal.d.ts +8 -2
  117. package/dist/store-reads/journal.js +27 -8
  118. package/dist/store-reads/learning.d.ts +1 -1
  119. package/dist/store-reads/learning.js +5 -2
  120. package/dist/store-reads/runs.js +2 -0
  121. package/dist/store-reads/stats.js +4 -2
  122. package/dist/store-view.d.ts +12 -1
  123. package/dist/store-view.js +98 -38
  124. package/dist/template-eval.d.ts +15 -1
  125. package/dist/template-eval.js +92 -13
  126. package/dist/templates.d.ts +1 -1
  127. package/dist/templates.js +4 -3
  128. package/dist/timeline/labels.js +17 -0
  129. package/dist/tool-list.js +1 -0
  130. package/dist/tools.d.ts +6 -2
  131. package/dist/tools.js +22 -1
  132. package/dist/trigger-targets.d.ts +28 -9
  133. package/dist/trigger-targets.js +19 -16
  134. package/dist/triggers.d.ts +2 -1
  135. package/dist/triggers.js +5 -2
  136. package/dist/validate.d.ts +4 -2
  137. package/dist/validate.js +13 -3
  138. package/dist/viewer-credential.d.ts +3 -4
  139. package/dist/viewer-credential.js +6 -4
  140. package/dist/web-fake.d.ts +25 -0
  141. package/dist/web-fake.js +38 -1
  142. package/dist/web-save.d.ts +75 -0
  143. package/dist/web-save.js +235 -0
  144. package/dist/workspace/archil-claim.d.ts +5 -2
  145. package/dist/workspace/archil-claim.js +5 -2
  146. package/dist/workspace/archil-disk.d.ts +10 -1
  147. package/dist/workspace/archil-disk.js +19 -1
  148. package/dist/workspace/archil.d.ts +3 -0
  149. package/dist/workspace/archil.js +101 -16
  150. package/dist/workspace/computer-for-claim.d.ts +19 -1
  151. package/dist/workspace/computer-for-claim.js +88 -20
  152. package/dist/workspace/computer-intervals.d.ts +26 -0
  153. package/dist/workspace/computer-intervals.js +58 -0
  154. package/dist/workspace/computer-janitor.d.ts +7 -3
  155. package/dist/workspace/computer-janitor.js +14 -6
  156. package/dist/workspace/computer-kept.d.ts +7 -2
  157. package/dist/workspace/computer-kept.js +9 -2
  158. package/dist/workspace/pieced.d.ts +14 -0
  159. package/dist/workspace/pieced.js +23 -0
  160. package/dist/workspace/resolve-computer.d.ts +7 -4
  161. package/dist/workspace/resolve-computer.js +21 -32
  162. package/dist/workspace/run-disk.js +32 -12
  163. package/dist/workspace/run-end-computers.d.ts +1 -0
  164. package/dist/workspace/run-end-computers.js +4 -1
  165. package/dist/workspace/run-workspace.d.ts +1 -1
  166. package/dist/workspace/run-workspace.js +11 -6
  167. package/package.json +10 -10
  168. package/templates/README.md +36 -7
  169. package/dist/console/assets/index-CTGegcKt.css +0 -1
  170. package/dist/console/assets/index-D1Se6mgG.js +0 -715
@@ -1,7 +1,31 @@
1
1
  // DELETE /v2/agents/{agent_id}: an agent another system owns (made by an inline run, POST /runs with `external`) deleted
2
- // whole, for a host that must delete what it sent. An agent made here is archived instead (409 agent_not_external).
2
+ // whole, for a host that must delete what it sent (deleteExternalAgent). An agent made here is purged once it is archived
3
+ // (purgeAgent; 409 agent_not_archived before). DELETE /v2/runs/{run_id}: one run purged (purgeRun), with the runs made
4
+ // from it. An owner must be able to delete what a run read; what it cost stays in every total. So a purge keeps each
5
+ // run's row, and an agent's, as a tombstone, and removes everything else of it.
3
6
  //
4
- // In order, each step finished before the next:
7
+ // A run's purge (purgeRun), only once it is not live (409 run_not_final otherwise, nothing purged: live is not final, or
8
+ // held by a runner; a run that ended and can take a follow-up is not live), nor any run made from it: first each run made
9
+ // from it (the replay runs of its input, its audit's shadow run, a learning run its kept learning names; each one's own
10
+ // such runs before it), then the grades its agent keeps of it and the content its promotion records copied from it (each
11
+ // disagreement's input and answers, learn/promote.ts forgetRunCopies), then the run, each by purgeOne: the figures its spend's
12
+ // readers read from its journal (kept on the tombstone, PurgeKept), its folders (its own folder on the agent's Archil disk
13
+ // it resolved to, and on a disk its launch named), settings and kept answers, then its rows (store runs.purge, which sets
14
+ // its purge time last). A replay of its input or an audit's shadow made by a claim (in a runner, maybe another process)
15
+ // after the DELETE read the runs made from it is found by the store's purge, under the run's row lock: 409 run_not_final
16
+ // naming it, the run kept for the next DELETE, which purges it first (RunsMadeFromLeft); one made once the run is purged
17
+ // is refused at its create, nothing written (RunPurged). A DELETE stopped part way finds the run not purged yet and the
18
+ // next DELETE finishes it; a DELETE of a purged run is 204 again, and every other route of it is 410 purged with its
19
+ // tombstone.
20
+ //
21
+ // An archived agent made here (purgeAgent), by the same rule: 409 run_not_final while a run of it is live. Then its
22
+ // learning, its things (triggers, sign-ins, its own computer, its disk), each of its runs by purgeOne (the runs made from
23
+ // it first, as a run's purge does them), its folders, settings and kept answers, and its rows (store agents.purge: its
24
+ // revisions' content, its name and description blanked, its purge time last). Each step is idempotent, so a DELETE stopped part way is finished by the next. Archived, the agent
25
+ // takes no new run and no trigger fires it; a run that reached it anyway keeps it unpurged (the store refuses), for the
26
+ // next DELETE.
27
+ //
28
+ // Another system's agent (deleteExternalAgent), in order, each step finished before the next:
5
29
  // 1. The agent refuses new runs, as a mark in the store that outlives a restart: its archive time, which only this
6
30
  // delete writes on an agent another system owns (its archive route is refused), set by the trigger engine with its
7
31
  // triggers off in the same commit. From that commit a person's run, an inline run, a trigger's firing, an SDK run and
@@ -27,7 +51,8 @@
27
51
  // same 503, and the next DELETE removes that trigger as it removes the others.
28
52
  import { ApiError } from "./errors.js";
29
53
  import { LearningInFlight } from "./learn/delete.js";
30
- import { FINAL_STATES, TriggersLeft } from "./store/index.js";
54
+ import { FINAL_STATES, RunsMadeFromLeft, StoreConstraint, TriggersLeft } from "./store/index.js";
55
+ import { forgetServed } from "./store-view.js";
31
56
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
32
57
  const isFinal = (state) => FINAL_STATES.includes(state);
33
58
  /** Deletes agent `agentId` (another system's, as the route checked) in the three steps above. Throws ApiError
@@ -37,7 +62,159 @@ export async function deleteExternalAgent(host, agentId) {
37
62
  await host.refuse(agentId);
38
63
  await stopRuns(host, agentId);
39
64
  await host.at?.("after_step_1", agentId);
40
- // 2. Its learning. Its refusal while learning work is in flight is learning_busy; any other failure is the server's own.
65
+ // 2. Its learning.
66
+ await learningGone(host, agentId);
67
+ await host.at?.("after_step_2", agentId);
68
+ // 3. Its things, then its rows; the agent's row last.
69
+ await thingsGone(host, agentId);
70
+ let first = true;
71
+ for (const run of await host.store.runs.every(agentId)) {
72
+ await host.forgetRun(agentId, run.id, false);
73
+ await host.store.runs.remove(run.id);
74
+ forgetServed(host.store, run.id);
75
+ if (first)
76
+ await host.at?.("in_step_3", agentId);
77
+ first = false;
78
+ }
79
+ await host.forgetAgent(agentId);
80
+ try {
81
+ await host.store.agents.remove(agentId);
82
+ }
83
+ catch (error) {
84
+ throw triggersLeft(error, agentId);
85
+ }
86
+ }
87
+ /** Purges archived agent `agentId`, made here (as the route checked), as the header says: 409 run_not_final, nothing
88
+ * purged, while a run of it is live; learning_busy while its learning refuses. */
89
+ export async function purgeAgent(host, agentId) {
90
+ const live = await liveOf(host, (await host.store.runs.every(agentId)).filter((run) => run.purgedAt === null));
91
+ if (live.length)
92
+ throw liveRuns(`The agent ${agentId} has ${live.length === 1 ? "a run" : "runs"} that ${live.length === 1 ? "has" : "have"} not ended (${live.join(", ")}): cancel ${live.length === 1 ? "it" : "them"} (POST /v2/runs/{run_id}/cancel), then send the DELETE again. Nothing was purged.`, live);
93
+ // Marked before anything goes, and kept until its tombstone is written: a purge stopped part way leaves the agent
94
+ // refusing an unarchive and every write (server.ts agentWrite) until a DELETE finishes it.
95
+ await host.store.settings.put(purgingKey(agentId), true);
96
+ await learningGone(host, agentId);
97
+ await host.at?.("after_step_2", agentId);
98
+ await thingsGone(host, agentId);
99
+ let first = true;
100
+ for (const run of await host.store.runs.every(agentId)) {
101
+ if (run.purgedAt !== null)
102
+ continue;
103
+ // The runs made from it first, each one's own before it, as purgeRun does: the store refuses a run's purge while one
104
+ // made from it (an audit's shadow, a replay, each started after it) is not purged. Its disk went whole above, each
105
+ // of its runs' folders there with it; a run of another agent keeps that agent's disk.
106
+ for (const one of await madeFromAll(host, run.id))
107
+ await purgeOneOrRefuse(host, one.agentId, one.id, agentId, one.agentId !== agentId);
108
+ // A later run of the list may be gone as one made from an earlier.
109
+ if ((await host.store.runs.get(run.id))?.purgedAt !== null)
110
+ continue;
111
+ await purgeOneOrRefuse(host, agentId, run.id, agentId, false);
112
+ if (first)
113
+ await host.at?.("in_step_3", agentId);
114
+ first = false;
115
+ }
116
+ await host.forgetAgent(agentId);
117
+ try {
118
+ await host.store.agents.purge(agentId);
119
+ }
120
+ catch (error) {
121
+ if (error instanceof StoreConstraint)
122
+ throw liveRuns(`The agent ${agentId} has a run started while it was being purged (${error.message}): send the DELETE again once it has ended. Its runs purged so far stay purged.`, []);
123
+ throw triggersLeft(error, agentId);
124
+ }
125
+ // Its tombstone refuses every write from here (410 purged).
126
+ await host.store.settings.remove(purgingKey(agentId));
127
+ }
128
+ /** The setting that marks agent `agentId`'s purge begun and not finished (purgeAgent). */
129
+ export const purgingKey = (agentId) => `agent.purging.${agentId}`;
130
+ /** Purges run `runId` with every run made from it, as the header says. 404 not_found when it is not there; 409
131
+ * run_not_final, nothing purged, while it or a run made from it is live. A purged run is no work. */
132
+ export async function purgeRun(host, runId) {
133
+ const run = await host.store.runs.get(runId);
134
+ if (!run)
135
+ throw new ApiError("not_found", `no run ${runId}`);
136
+ if (run.purgedAt !== null)
137
+ return;
138
+ const made = await madeFromAll(host, runId);
139
+ const live = await liveOf(host, [run, ...made]);
140
+ if (live.length)
141
+ throw notFinal(runId, live);
142
+ for (const one of made)
143
+ await purgeOneOrRefuse(host, one.agentId, one.id, runId, true);
144
+ await host.at?.("run_made_from_gone", runId);
145
+ await host.forgetCopies(run.agentId, runId);
146
+ await purgeOneOrRefuse(host, run.agentId, runId, runId, true);
147
+ }
148
+ /** The one per-run step of both purges: the figures its spend's readers read from its journal, its things outside its
149
+ * rows, then its rows (a tombstone). Its store's refusal of a run gone live again since it was read (a follow-up opened
150
+ * it) is 409 run_not_final, as a run read live is (`purged`: the run or agent the DELETE names; `alone`: its agent's disk
151
+ * stays, AgentDeleteHost.forgetRun). */
152
+ async function purgeOneOrRefuse(host, agentId, runId, purged, alone) {
153
+ const kept = await host.kept(runId);
154
+ await host.forgetRun(agentId, runId, alone);
155
+ await host.at?.("run_forgotten", runId);
156
+ try {
157
+ await host.store.runs.purge(runId, kept);
158
+ }
159
+ catch (error) {
160
+ // A replay or shadow made from it after the runs made from it were read: named, for the next DELETE to purge first.
161
+ if (error instanceof RunsMadeFromLeft)
162
+ throw notFinal(purged, error.runs);
163
+ if (error instanceof StoreConstraint)
164
+ throw notFinal(purged, [runId]);
165
+ throw error;
166
+ }
167
+ finally {
168
+ // Its answer and input as this process last served them, dropped whatever the purge answered: every route of it is 410
169
+ // once it committed, so none is read again. A purge can commit and still throw (its checkpoint held back and the
170
+ // scrub's marker not written, sqlite/store.ts #purged), and no later DELETE comes back here (purgeRun: a purged run is
171
+ // no work). One that did not commit loses a cache its next read fills again.
172
+ forgetServed(host.store, runId);
173
+ }
174
+ }
175
+ /** Every run made from run `runId` that is there and not purged, each one's own before it (deepest first), never `runId`. */
176
+ async function madeFromAll(host, runId, seen = new Set([runId])) {
177
+ const out = [];
178
+ for (const id of await host.madeFrom(runId)) {
179
+ if (seen.has(id))
180
+ continue;
181
+ seen.add(id);
182
+ const row = await host.store.runs.get(id);
183
+ if (!row || row.purgedAt !== null)
184
+ continue;
185
+ out.push(...(await madeFromAll(host, id, seen)), { id, agentId: row.agentId, state: row.state, runner: row.runner });
186
+ }
187
+ return out;
188
+ }
189
+ /** Live: not final, or held by a runner. A run that ended and can take a follow-up (it reads idle) is not. */
190
+ const isLive = (run) => !isFinal(run.state) || run.runner !== null;
191
+ /** Of `runs`, the ids of the live ones. A run whose turn is over (it reads idle: a person's stop, or its turn's end) is
192
+ * written final by its runner a moment after it reads so, so while every live run is such a one, each is read again
193
+ * every host.pollMs, for host.waitMs at most, until it is final and let go. A live run whose turn is not over makes the
194
+ * answer at once, and so does one still live at the end. */
195
+ async function liveOf(host, runs) {
196
+ const deadline = Date.now() + host.waitMs;
197
+ let live = runs.filter(isLive).map((run) => run.id);
198
+ for (;;) {
199
+ if (!live.length)
200
+ return live;
201
+ for (const id of live)
202
+ if (!(await host.turnOver(id)))
203
+ return live;
204
+ if (Date.now() >= deadline)
205
+ return live;
206
+ await sleep(host.pollMs);
207
+ const rows = await Promise.all(live.map((id) => host.store.runs.get(id)));
208
+ live = rows.filter((row) => row !== undefined && row.purgedAt === null && isLive(row)).map((row) => row.id);
209
+ }
210
+ }
211
+ const liveRuns = (message, runs) => new ApiError("run_not_final", message, { details: { runs: [...runs] } });
212
+ const notFinal = (runId, live) => liveRuns(live.length === 1 && live[0] === runId
213
+ ? `The run ${runId} has not ended: cancel it first (POST /v2/runs/${runId}/cancel), then send the DELETE again. Nothing was purged.`
214
+ : `${runId} has ${live.length === 1 ? "a run" : "runs"} that ${live.length === 1 ? "has" : "have"} not ended (${live.join(", ")}): send the DELETE again once ${live.length === 1 ? "it has" : "they have"} ended. Runs purged so far stay purged.`, live);
215
+ /** An agent's learning deleted (step 2 of a delete, the first of a purge). Its refusal while learning work is in flight is
216
+ * learning_busy; any other failure is the server's own. */
217
+ async function learningGone(host, agentId) {
41
218
  try {
42
219
  await host.deleteLearning(host.store, agentId);
43
220
  }
@@ -46,10 +223,12 @@ export async function deleteExternalAgent(host, agentId) {
46
223
  throw error;
47
224
  throw new ApiError("learning_busy", `The agent ${agentId}'s learning could not be deleted yet (${error.message}). The agent starts no run meanwhile: send the DELETE again later to finish it.`, { details: { runs: [...error.runs] }, retry_after_ms: 5_000 });
48
225
  }
49
- await host.at?.("after_step_2", agentId);
50
- // 3. Its things, then its rows; the agent's row last.
226
+ }
227
+ /** An agent's things outside the store's rows: its triggers through the trigger engine (each one's registration upstream
228
+ * first, then its settings, then its row: the row names what is left to remove until each is gone), its saved sign-ins,
229
+ * its own computer, its Archil disk. */
230
+ async function thingsGone(host, agentId) {
51
231
  for (const trigger of await host.store.triggers.list(agentId)) {
52
- // Upstream first, then its settings, then its row: the row names what is left to remove until each is gone.
53
232
  await host.removeTriggerThere(trigger.id);
54
233
  await host.at?.("in_step_3_trigger", agentId);
55
234
  await host.removeTriggerSettings(trigger.id);
@@ -59,25 +238,13 @@ export async function deleteExternalAgent(host, agentId) {
59
238
  await host.forgetSignIns(agentId);
60
239
  await host.removeOwnComputer(agentId);
61
240
  await host.removeDisk(agentId);
62
- let first = true;
63
- for (const run of await host.store.runs.every(agentId)) {
64
- await host.forgetRun(agentId, run.id);
65
- await host.store.runs.remove(run.id);
66
- if (first)
67
- await host.at?.("in_step_3", agentId);
68
- first = false;
69
- }
70
- await host.forgetAgent(agentId);
71
- try {
72
- await host.store.agents.remove(agentId);
73
- }
74
- catch (error) {
75
- // A trigger that reached the agent after the listing above (the store refuses one once the agent is marked; this is
76
- // its backstop): the agent is kept, refusing, for the next DELETE to remove it upstream, its settings, then its row.
77
- if (!(error instanceof TriggersLeft))
78
- throw error;
79
- throw new ApiError("unavailable", `The agent ${agentId} has ${error.triggerIds.length === 1 ? "a trigger" : "triggers"} made while it was being deleted (${error.triggerIds.join(", ")}), not removed yet. It starts no run meanwhile: send the DELETE again to finish it.`, { details: { triggers: error.triggerIds }, retry_after_ms: 5_000 });
80
- }
241
+ }
242
+ /** A trigger that reached the agent after its delete listed them (the store refuses one once the agent is marked; this is
243
+ * its backstop): the agent is kept for the next DELETE to remove it upstream, its settings, then its row. */
244
+ function triggersLeft(error, agentId) {
245
+ if (!(error instanceof TriggersLeft))
246
+ return error;
247
+ return new ApiError("unavailable", `The agent ${agentId} has ${error.triggerIds.length === 1 ? "a trigger" : "triggers"} made while it was being deleted (${error.triggerIds.join(", ")}), not removed yet. It starts no run meanwhile: send the DELETE again to finish it.`, { details: { triggers: error.triggerIds }, retry_after_ms: 5_000 });
81
248
  }
82
249
  /** Step 1's second half: each run of the agent not final cancelled once, then read again until every one is final. A run's
83
250
  * end may queue its learning run, so the runs are listed again on each read. A run this server cannot end, or one still
@@ -108,12 +275,28 @@ async function stopRuns(host, agentId) {
108
275
  }
109
276
  }
110
277
  /** One delete of an agent at a time: a second DELETE of the same agent waits for the first, then finds it gone (404) or
111
- * finishes what the first left. */
112
- export function oneAtATime() {
278
+ * finishes what the first left. `queued`, a test's seam: told each time a work waits behind another of its agent's,
279
+ * with how many of that agent's wait now (the one running not counted). */
280
+ export function oneAtATime(queued) {
113
281
  const turns = new Map();
282
+ const waiting = new Map();
114
283
  return (agentId, work) => {
115
- const before = turns.get(agentId) ?? Promise.resolve();
116
- const turn = before.then(work, work);
284
+ const held = turns.get(agentId);
285
+ let run = work;
286
+ if (held && queued) {
287
+ waiting.set(agentId, (waiting.get(agentId) ?? 0) + 1);
288
+ run = () => {
289
+ const left = waiting.get(agentId) - 1;
290
+ if (left)
291
+ waiting.set(agentId, left);
292
+ else
293
+ waiting.delete(agentId);
294
+ return work();
295
+ };
296
+ queued(agentId, waiting.get(agentId));
297
+ }
298
+ const before = held ?? Promise.resolve();
299
+ const turn = before.then(run, run);
117
300
  const settled = turn.then(() => undefined, () => undefined);
118
301
  turns.set(agentId, settled);
119
302
  void settled.then(() => {
@@ -70,6 +70,8 @@ export declare function createAgent(store: AgentsStore, { definition, skills, no
70
70
  export declare function makeRevision(definition: Json, files: Record<string, string>, note: string | undefined): NewRevision & {
71
71
  note?: string;
72
72
  };
73
+ /** Runs a write's last read and its commit in the agent's delete turn (server.ts agentWrite). */
74
+ export type InTurn = <T>(work: () => Promise<T>) => Promise<T>;
73
75
  /** An edit: a new revision of the agent, made current. Without `skills` the current revision's skill files carry over. An
74
76
  * edit that is the current revision writes nothing, so a PUT sent twice makes one revision. The agent keeps its id and name
75
77
  * from its creation (a changed one is input_invalid). Its description is a label: an edit that names a new one makes a
@@ -83,13 +85,15 @@ export declare function makeRevision(definition: Json, files: Record<string, str
83
85
  * revision it does not follow. `contract`: an edit that always makes a new revision, even one equal to the current.
84
86
  * `template`: the package an apply with agent_id wrote it from, kept on the revision (getAgent's `template`).
85
87
  * `fromPackage`: the definition is a whole package's (an apply with agent_id), so what it leaves out is not carried over
86
- * (editOn). */
87
- export declare function commitAgent(store: AgentsStore, read: AgentEntry, { definition, skills, note }: DefinitionBody, { ifCurrent, check, contract, template, fromPackage }?: {
88
+ * (editOn). `inTurn`: where the agent is read again and the revision written (the server's agentWrite, which refuses a
89
+ * purged agent, or one whose purge stopped part way); the check runs outside it. */
90
+ export declare function commitAgent(store: AgentsStore, read: AgentEntry, { definition, skills, note }: DefinitionBody, { ifCurrent, check, contract, template, fromPackage, inTurn }?: {
88
91
  ifCurrent?: string | null;
89
92
  check?: SaveCheck;
90
93
  contract?: boolean;
91
94
  template?: TemplatePackage;
92
95
  fromPackage?: boolean;
96
+ inTurn?: InTurn;
93
97
  }): Promise<AgentEntry>;
94
98
  /** Makes `revisionId`, one of the agent's own, its current one (POST /agents/{id}/current). */
95
99
  export declare function setCurrentRevision(store: AgentsStore, entry: AgentEntry, revisionId: string): Promise<AgentEntry>;
@@ -6,6 +6,7 @@
6
6
  //
7
7
  // The run counts an agent view shows (runs.count, runs.live) are E3's run reads, not this module's; agentView takes them.
8
8
  import { randomBytes } from "node:crypto";
9
+ import { purgedAgent } from "./agents.js";
9
10
  import { agentLink } from "./console-links.js";
10
11
  import { approvalsOf } from "./approvals.js";
11
12
  import { ApiError, invalid } from "./errors.js";
@@ -241,8 +242,9 @@ const EDIT_TRIES = 5;
241
242
  * revision it does not follow. `contract`: an edit that always makes a new revision, even one equal to the current.
242
243
  * `template`: the package an apply with agent_id wrote it from, kept on the revision (getAgent's `template`).
243
244
  * `fromPackage`: the definition is a whole package's (an apply with agent_id), so what it leaves out is not carried over
244
- * (editOn). */
245
- export async function commitAgent(store, read, { definition, skills, note }, { ifCurrent, check, contract = false, template, fromPackage = false } = {}) {
245
+ * (editOn). `inTurn`: where the agent is read again and the revision written (the server's agentWrite, which refuses a
246
+ * purged agent, or one whose purge stopped part way); the check runs outside it. */
247
+ export async function commitAgent(store, read, { definition, skills, note }, { ifCurrent, check, contract = false, template, fromPackage = false, inTurn } = {}) {
246
248
  const stale = () => new ApiError("precondition_failed", "the agent's current revision moved since the If-Match it was read at: read the agent again");
247
249
  const held = (entry) => {
248
250
  if (ifCurrent !== undefined && (entry.revision?.id ?? null) !== ifCurrent)
@@ -250,6 +252,9 @@ export async function commitAgent(store, read, { definition, skills, note }, { i
250
252
  return entry;
251
253
  };
252
254
  let entry = (await getAgent(store, read.agent.id)) ?? read;
255
+ // Purged since the request read it: 410 before anything is checked (the commit's turn and the store refuse it too).
256
+ if (entry.agent.purgedAt !== null)
257
+ throw purgedAgent(entry.agent);
253
258
  refuseExternal(entry.agent);
254
259
  held(entry);
255
260
  const { agent } = entry;
@@ -270,8 +275,13 @@ export async function commitAgent(store, read, { definition, skills, note }, { i
270
275
  const edit = template ? { ...made, package: template } : made;
271
276
  const revision = stamped(edit, await check?.(edit, entry.revision));
272
277
  const base = entry.revision?.id ?? null;
273
- const now = held((await getAgent(store, agent.id)) ?? entry);
274
- if ((now.revision?.id ?? null) === base) {
278
+ // The agent read again and the revision written in `inTurn` (the server's agent delete turn): the check above, which
279
+ // may wait on a server's listing, runs outside it, so edits of one agent are checked at once and a DELETE never waits
280
+ // on a check.
281
+ const landed = await (inTurn ?? ((work) => work()))(async () => {
282
+ const now = held((await getAgent(store, agent.id)) ?? entry);
283
+ if ((now.revision?.id ?? null) !== base)
284
+ return undefined;
275
285
  // A new description is a real edit: a revision, even with the body unchanged. The same one again writes nothing.
276
286
  const described = description !== undefined && description !== now.agent.description;
277
287
  if (!contract && !described && now.revision && sameRevision(now.revision, revision)) {
@@ -291,8 +301,11 @@ export async function commitAgent(store, read, { definition, skills, note }, { i
291
301
  catch (error) {
292
302
  if (!(error instanceof RevisionMoved))
293
303
  storeError(error);
304
+ return undefined;
294
305
  }
295
- }
306
+ });
307
+ if (landed)
308
+ return landed;
296
309
  // Moved while it was checked or written: with If-Match that is stale; without, built and checked again on it.
297
310
  if (ifCurrent !== undefined)
298
311
  throw stale();
package/dist/agents.d.ts CHANGED
@@ -16,9 +16,16 @@ export declare const homeBusy: () => ApiError;
16
16
  /** The answer to a run, a trigger or a write refused because its agent is being deleted (the store's AgentDeleting, read
17
17
  * in the transaction that would start or reopen the run or write the trigger; the server's own check for a write). */
18
18
  export declare const agentDeleting: (agentId: string) => ApiError;
19
+ /** 410 purged for a route of a purged agent (Agents.purge), or a write the store refused because it is (AgentPurged):
20
+ * its tombstone in the details. */
21
+ export declare const purgedAgent: (agent: {
22
+ id: string;
23
+ archivedAt: number | null;
24
+ purgedAt: number | null;
25
+ }) => ApiError;
19
26
  /** What a request's error answers, over HTTP and through an MCP tool alike (server.ts, mcp.ts dispatch): an ApiError as
20
27
  * it is; a busy store home_busy (409, retryable), never 500; a run of an agent being deleted agent_not_runnable (409);
21
- * anything else internal, its message kept. */
28
+ * a write to a purged agent purged (410); anything else internal, its message kept. */
22
29
  export declare const answerOf: (error: unknown) => ApiError;
23
30
  /** Whether a request's error goes to the server's log: every fault the server did not answer on purpose. A busy wait
24
31
  * is not one; a transaction past its deadline is (something held the store that long). */
package/dist/agents.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // (whenFree), then answered home_busy. The agents themselves are over the one store (agents-store.ts).
3
3
  import { ApiError } from "./errors.js";
4
4
  import { isObject } from "./validate.js";
5
- import { AgentDeleting, StoreBusy, StoreDeadline } from "./store/index.js";
5
+ import { AgentDeleting, AgentPurged, StoreBusy, StoreDeadline } from "./store/index.js";
6
6
  /** SQLITE_BUSY or SQLITE_LOCKED: another connection holds the database. */
7
7
  export const sqliteBusy = (error) => isObject(error) && error.code === "ERR_SQLITE_ERROR" && typeof error.errcode === "number" && [5, 6].includes(error.errcode & 0xff);
8
8
  /** How long a request waits for a busy agent store, step by step: short first, so a reader's overlap costs
@@ -36,10 +36,20 @@ export const homeBusy = () => new ApiError("home_busy", "the agent store is busy
36
36
  /** The answer to a run, a trigger or a write refused because its agent is being deleted (the store's AgentDeleting, read
37
37
  * in the transaction that would start or reopen the run or write the trigger; the server's own check for a write). */
38
38
  export const agentDeleting = (agentId) => new ApiError("agent_not_runnable", `The agent ${agentId} is being deleted (DELETE /v2/agents/${agentId}): it starts no run, opens none again and takes no new trigger or write. Send the DELETE again to finish it.`);
39
+ const isoOrNull = (ms) => (ms === null ? null : new Date(ms).toISOString());
40
+ /** 410 purged for a route of a purged agent (Agents.purge), or a write the store refused because it is (AgentPurged):
41
+ * its tombstone in the details. */
42
+ export const purgedAgent = (agent) => new ApiError("purged", `The agent ${agent.id} was purged: its definition, learning and runs' content are gone, and its runs' cost stays in every total.`, {
43
+ details: { agent_id: agent.id, archived_at: isoOrNull(agent.archivedAt), purged_at: isoOrNull(agent.purgedAt) },
44
+ });
39
45
  /** What a request's error answers, over HTTP and through an MCP tool alike (server.ts, mcp.ts dispatch): an ApiError as
40
46
  * it is; a busy store home_busy (409, retryable), never 500; a run of an agent being deleted agent_not_runnable (409);
41
- * anything else internal, its message kept. */
42
- export const answerOf = (error) => error instanceof ApiError ? error : storeBusy(error) ? homeBusy() : error instanceof AgentDeleting ? agentDeleting(error.agentId) : new ApiError("internal", error?.message ?? String(error));
47
+ * a write to a purged agent purged (410); anything else internal, its message kept. */
48
+ export const answerOf = (error) => error instanceof ApiError ? error
49
+ : storeBusy(error) ? homeBusy()
50
+ : error instanceof AgentDeleting ? agentDeleting(error.agentId)
51
+ : error instanceof AgentPurged ? purgedAgent({ id: error.agentId, archivedAt: error.archivedAt, purgedAt: error.purgedAt })
52
+ : new ApiError("internal", error?.message ?? String(error));
43
53
  /** Whether a request's error goes to the server's log: every fault the server did not answer on purpose. A busy wait
44
54
  * is not one; a transaction past its deadline is (something held the store that long). */
45
- export const logged = (error) => !(error instanceof ApiError) && !(error instanceof AgentDeleting) && (!storeBusy(error) || error instanceof StoreDeadline);
55
+ export const logged = (error) => !(error instanceof ApiError) && !(error instanceof AgentDeleting) && !(error instanceof AgentPurged) && (!storeBusy(error) || error instanceof StoreDeadline);
@@ -60,7 +60,7 @@ export declare function answerAsServed(output: string, schema: unknown): {
60
60
  export declare const X_CARRIED = "x-carried";
61
61
  /** Why `schema`'s `x-carried` is not a list of unique names of the root's `properties`; undefined when it is, or absent. */
62
62
  export declare function carriedProblem(schema: Record<string, unknown>): string | undefined;
63
- /** The fields `schema` names in `x-carried`, when it names a list of them (one saved before the save checked it may not):
64
- * undefined for none. */
63
+ /** The fields `schema` names in `x-carried`, read by the save's rule (carriedProblem): undefined for none, or for one the
64
+ * save would refuse, so its run gets the too-large line. */
65
65
  export declare function carriedFields(schema: unknown): readonly string[] | undefined;
66
66
  export {};
@@ -156,9 +156,8 @@ export function carriedProblem(schema) {
156
156
  const unknown = carried.filter((name) => !Object.hasOwn(properties, name));
157
157
  return unknown.length ? `names ${unknown.map((name) => JSON.stringify(name)).join(", ")}, which the root's properties have no field for` : undefined;
158
158
  }
159
- /** The fields `schema` names in `x-carried`, when it names a list of them (one saved before the save checked it may not):
160
- * undefined for none. */
159
+ /** The fields `schema` names in `x-carried`, read by the save's rule (carriedProblem): undefined for none, or for one the
160
+ * save would refuse, so its run gets the too-large line. */
161
161
  export function carriedFields(schema) {
162
- const carried = isObject(schema) ? schema[X_CARRIED] : undefined;
163
- return Array.isArray(carried) && carried.length > 0 && carried.every((name) => typeof name === "string") ? carried : undefined;
162
+ return isObject(schema) && !carriedProblem(schema) ? schema[X_CARRIED] : undefined;
164
163
  }
@@ -1,16 +1,13 @@
1
1
  import type { Route } from "./server.js";
2
2
  /** The variable that turns the profile on. */
3
3
  export declare const API_ONLY_ENV = "AGENTRUN_API_ONLY";
4
- /** The routes (server.ts ROUTES, by name) an API-only server serves. Those past a run's own:
5
- * - getComputerDaemon: a run's hosted machine that dials fetches computerd with its own token, as the attach upgrade
6
- * takes such a machine alone (a paired computer is the console's).
7
- * - listComputers, getWorkspaceArchil: the two reads a backend checks before it launches, naming keys and never a
8
- * value; their writes and tests stay the console's.
9
- * - getAgentArchil, deleteAgentArchil, deleteAgent: an agent's disk and the delete of an agent its inline runs made,
10
- * which the backend that made it sends.
11
- * - getRunComputer, takeOverRunComputer, handBackRunComputer, createRunComputerViewer: a run's computer, its take-over
12
- * and hand-back, and its viewer credential's mint (viewer-credential.ts), by the server's token, the backend's own;
13
- * the live page and socket take that credential. */
4
+ /** The routes (server.ts ROUTES, by name) an API-only server serves. Past a run's own, why each group is here:
5
+ * - a run's hosted machine fetches computerd with the token its create minted, not the server's;
6
+ * - the computers list and the Archil settings are read before a launch, naming keys, never a value;
7
+ * - an agent its inline runs made has its disk and its delete sent by the backend that made it;
8
+ * - a run's computer, take-over, hand-back and viewer link go to the backend, which has no owner's session here;
9
+ * - a backend reads what its agents learned (loop, promotions, cost per run, a run's learning), cut as the console's;
10
+ * - a run's usage lines (what its cost.usd joins, by meter) are a read of that run alone, cut as the run's read is. */
14
11
  export declare const API_ONLY_ROUTES: ReadonlySet<string>;
15
12
  /** Whether `env` turns the profile on: `1` or `true` on; unset, empty, `0` or `false` off. Any other value is refused in
16
13
  * words (a TypeError), so a typo never leaves the console open on a server meant to be API-only. */
package/dist/api-only.js CHANGED
@@ -1,21 +1,19 @@
1
1
  /** The variable that turns the profile on. */
2
2
  export const API_ONLY_ENV = "AGENTRUN_API_ONLY";
3
- /** The routes (server.ts ROUTES, by name) an API-only server serves. Those past a run's own:
4
- * - getComputerDaemon: a run's hosted machine that dials fetches computerd with its own token, as the attach upgrade
5
- * takes such a machine alone (a paired computer is the console's).
6
- * - listComputers, getWorkspaceArchil: the two reads a backend checks before it launches, naming keys and never a
7
- * value; their writes and tests stay the console's.
8
- * - getAgentArchil, deleteAgentArchil, deleteAgent: an agent's disk and the delete of an agent its inline runs made,
9
- * which the backend that made it sends.
10
- * - getRunComputer, takeOverRunComputer, handBackRunComputer, createRunComputerViewer: a run's computer, its take-over
11
- * and hand-back, and its viewer credential's mint (viewer-credential.ts), by the server's token, the backend's own;
12
- * the live page and socket take that credential. */
3
+ /** The routes (server.ts ROUTES, by name) an API-only server serves. Past a run's own, why each group is here:
4
+ * - a run's hosted machine fetches computerd with the token its create minted, not the server's;
5
+ * - the computers list and the Archil settings are read before a launch, naming keys, never a value;
6
+ * - an agent its inline runs made has its disk and its delete sent by the backend that made it;
7
+ * - a run's computer, take-over, hand-back and viewer link go to the backend, which has no owner's session here;
8
+ * - a backend reads what its agents learned (loop, promotions, cost per run, a run's learning), cut as the console's;
9
+ * - a run's usage lines (what its cost.usd joins, by meter) are a read of that run alone, cut as the run's read is. */
13
10
  export const API_ONLY_ROUTES = new Set([
14
11
  "createRun", "createInlineRun", "getComputerDaemon",
15
12
  "getRunComputer", "takeOverRunComputer", "handBackRunComputer", "createRunComputerViewer",
16
13
  "listComputers", "getWorkspaceArchil",
17
14
  "getAgentArchil", "deleteAgentArchil", "deleteAgent",
18
- "getRun", "listRuns", "listAllRuns", "getTimeline",
15
+ "getLearningLoop", "listLearningPromotions", "getLearningCost", "getRunLearning",
16
+ "getRun", "getRunUsage", "listRuns", "listAllRuns", "getTimeline",
19
17
  "sendMessage", "stopRun", "cancelRun", "raiseRunCap", "gradeRun",
20
18
  "listRunFiles", "readRunFile",
21
19
  "createFile", "listFiles", "getFile", "uploadFile", "deleteFile",
@@ -70,7 +70,7 @@ export declare function createArchilRoutes(options: ArchilRoutesOptions): {
70
70
  } | null;
71
71
  }>;
72
72
  checkLaunchDisk: (diskId: string, signal?: AbortSignal) => Promise<void>;
73
- removeRunFolder: (agentId: string, runId: string, diskId: string) => Promise<void>;
73
+ removeRunFolder: (agentId: string, runId: string, diskId: string, whose?: "launch" | "agent") => Promise<void>;
74
74
  };
75
75
  export type ArchilRoutes = ReturnType<typeof createArchilRoutes>;
76
76
  /** One of the owner's Archil routes at its handler: its answer (sent 200), or an ApiError (sent with its status). An
@@ -253,9 +253,10 @@ export function createArchilRoutes(options) {
253
253
  * so is the folder of a disk Archil says is gone, which has nothing left to delete (one the caller deleted, or the
254
254
  * agent's own disk named in the launch, which the agent's delete removed whole before its runs' folders).
255
255
  * Archil off, or no account key, is 503 unavailable; a delete Archil refuses (a computer that still holds the folder,
256
- * Archil not reached) is 424 upstream_failed, what was not deleted left for the next call. */
257
- async function removeRunFolder(agentId, runId, diskId) {
258
- const what = `The run ${runId}'s folder on the Archil disk ${diskId}, which its launch named,`;
256
+ * Archil not reached) is 424 upstream_failed, what was not deleted left for the next call. `whose` "agent": the run is
257
+ * deleted alone (DELETE /runs/{id}), its folder on its agent's own disk, which stays. */
258
+ async function removeRunFolder(agentId, runId, diskId, whose = "launch") {
259
+ const what = `The run ${runId}'s folder on the Archil disk ${diskId}, ${whose === "launch" ? "which its launch named" : "its agent's own"},`;
259
260
  const settings = await loadArchilSettings(store, env);
260
261
  if (settings === undefined)
261
262
  throw new ApiError("unavailable", `${what} is not deleted yet: Archil is off on this server, so it can't be reached. Turn Archil on again (PUT /v2/workspace/archil)`);
@@ -0,0 +1,56 @@
1
+ import { type Tx } from "@earendil-works/pi-durable";
2
+ import type { BrowserSessionUsage } from "@parcha/agentrun-computer";
3
+ import type { EntryLike } from "./timeline/index.js";
4
+ /** The run journal's record of a browser session let go (on the root): see the file's head. */
5
+ export declare const BROWSER_SESSION_ENDED = "agentrun.browser_session_ended";
6
+ /** How long the provider's record is waited for at a release before the session's end is written without it. */
7
+ export declare const PROVIDER_RECORD_TIMEOUT_MS = 5000;
8
+ /** What came of reading the provider's own record: `read`, it answered; `not_offered`, the provider keeps none this
9
+ * server reads; `not_found`, it does not know the session; `failed`, the read failed or timed out; `no_session`, no
10
+ * session was made (its create failed), so there was nothing to read. */
11
+ export type ProviderRecordStatus = "read" | "not_offered" | "not_found" | "failed" | "no_session";
12
+ /** The provider's record as this server keeps it: each field null where the provider does not say it. */
13
+ export type ProviderRecord = {
14
+ started_at: string | null;
15
+ ended_at: string | null;
16
+ proxy_bytes: number | null;
17
+ };
18
+ /** A browser session as the usage read gives it. */
19
+ export type BrowserSessionLine = {
20
+ provider: string;
21
+ /** pi-browser's tag for the session: the run's own name for it, which its charges name too. */
22
+ tag: string;
23
+ /** The provider's id for the session; null when none was made, or its end is not recorded. */
24
+ provider_session_id: string | null;
25
+ /** When this server began opening the session, and when it let it go (null: no end recorded). */
26
+ started_at: string | null;
27
+ ended_at: string | null;
28
+ release_reason: string | null;
29
+ /** The seconds this server charged for the session's time (its BROWSER_CHARGED records), unrounded; null when none
30
+ * was charged (a free provider's, or a session with no charge yet). */
31
+ charged_seconds: number | null;
32
+ provider_record: ProviderRecord | null;
33
+ provider_record_status: ProviderRecordStatus | null;
34
+ };
35
+ /** A session as pi-browser's release tells it (its SessionRecord), only what is recorded. */
36
+ type Released = {
37
+ tag: string;
38
+ resourceId: string | null;
39
+ createdAt: string;
40
+ endedAt: string | null;
41
+ releaseReason: string | null;
42
+ provider: string;
43
+ };
44
+ /** The writer of each session's end, once per session in this process (pi-browser tells a release at least once):
45
+ * the provider's record read first (`usage`, bounded), then the end written on the root (`commit`). It never throws: a
46
+ * session whose end cannot be written is said in `log`, and reads as not ended. */
47
+ export declare function sessionEnds(options: {
48
+ usage: ((id: string, signal?: AbortSignal) => Promise<BrowserSessionUsage | undefined>) | undefined;
49
+ commit: ((change: (tx: Tx) => Promise<void>) => Promise<unknown>) | undefined;
50
+ log?: (line: string) => void;
51
+ timeoutMs?: number;
52
+ }): (session: Released, conversation: number) => Promise<void>;
53
+ /** A run's browser sessions from its journal `entries`, in the order they were opened: one per tag its root names in an
54
+ * open, an end or a charge. The first end recorded for a tag is its end. */
55
+ export declare function browserSessionsOf(entries: readonly EntryLike[]): BrowserSessionLine[];
56
+ export {};