@parcha/agentrun-serve 0.1.0-beta.40 → 0.1.0-beta.42

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 (199) hide show
  1. package/CHANGELOG.md +130 -0
  2. package/NOTICE +2 -0
  3. package/README.md +149 -21
  4. package/dist/agent-rows.d.ts +1 -1
  5. package/dist/agents-store.js +3 -1
  6. package/dist/api-only.d.ts +3 -1
  7. package/dist/api-only.js +4 -2
  8. package/dist/api-token.d.ts +30 -0
  9. package/dist/api-token.js +89 -0
  10. package/dist/calendar/address.d.ts +49 -0
  11. package/dist/calendar/address.js +153 -0
  12. package/dist/calendar/fetch.d.ts +24 -0
  13. package/dist/calendar/fetch.js +146 -0
  14. package/dist/calendar/ics-faux.d.ts +39 -0
  15. package/dist/calendar/ics-faux.js +236 -0
  16. package/dist/calendar/labels.d.ts +3 -0
  17. package/dist/calendar/labels.js +61 -0
  18. package/dist/calendar/names.d.ts +52 -0
  19. package/dist/calendar/names.js +54 -0
  20. package/dist/calendar/parse.d.ts +108 -0
  21. package/dist/calendar/parse.js +625 -0
  22. package/dist/calendar/routes.d.ts +17 -0
  23. package/dist/calendar/routes.js +81 -0
  24. package/dist/calendar/tools.d.ts +23 -0
  25. package/dist/calendar/tools.js +124 -0
  26. package/dist/cli.js +22 -6
  27. package/dist/composio-made.d.ts +54 -0
  28. package/dist/composio-made.js +83 -0
  29. package/dist/composio-preset.d.ts +16 -8
  30. package/dist/composio-preset.js +106 -43
  31. package/dist/composio-triggers.d.ts +7 -2
  32. package/dist/composio-triggers.js +13 -7
  33. package/dist/computer-attach.d.ts +29 -11
  34. package/dist/computer-attach.js +141 -47
  35. package/dist/computer-keys.d.ts +4 -0
  36. package/dist/computer-keys.js +5 -0
  37. package/dist/computer-record.d.ts +55 -0
  38. package/dist/computer-record.js +315 -0
  39. package/dist/computer-setting.d.ts +1 -0
  40. package/dist/computer-setting.js +15 -2
  41. package/dist/computers.d.ts +11 -1
  42. package/dist/computers.js +23 -26
  43. package/dist/console/assets/{index-B8Zn1Iqn.css → index-C3gNPz58.css} +1 -1
  44. package/dist/console/assets/index-DYJ_wj27.js +711 -0
  45. package/dist/console/index.html +2 -2
  46. package/dist/decisions.js +9 -2
  47. package/dist/eval-feed.d.ts +26 -0
  48. package/dist/eval-feed.js +72 -0
  49. package/dist/eval-mailbox.d.ts +4 -1
  50. package/dist/eval-mailbox.js +11 -3
  51. package/dist/exa-keyless.d.ts +1 -1
  52. package/dist/exa-keyless.js +1 -1
  53. package/dist/feed/feed-faux.d.ts +62 -0
  54. package/dist/feed/feed-faux.js +123 -0
  55. package/dist/feed/fetch.d.ts +41 -0
  56. package/dist/feed/fetch.js +128 -0
  57. package/dist/feed/parse.d.ts +42 -0
  58. package/dist/feed/parse.js +291 -0
  59. package/dist/feed/pointer.d.ts +2 -0
  60. package/dist/feed/pointer.js +17 -0
  61. package/dist/file-types.js +1 -0
  62. package/dist/host-command.d.ts +3 -0
  63. package/dist/host-command.js +18 -0
  64. package/dist/host.d.ts +3 -0
  65. package/dist/host.js +3 -0
  66. package/dist/learn/check.d.ts +17 -1
  67. package/dist/learn/check.js +240 -5
  68. package/dist/learn/compile.d.ts +48 -27
  69. package/dist/learn/compile.js +134 -101
  70. package/dist/learn/promote.d.ts +61 -5
  71. package/dist/learn/promote.js +12 -2
  72. package/dist/learned-nodes.d.ts +21 -4
  73. package/dist/learned-nodes.js +21 -8
  74. package/dist/learned-workflow.d.ts +3 -3
  75. package/dist/learned-workflow.js +14 -5
  76. package/dist/learning-setting.d.ts +23 -0
  77. package/dist/learning-setting.js +51 -0
  78. package/dist/learning-words.d.ts +3 -0
  79. package/dist/learning-words.js +3 -0
  80. package/dist/learning.d.ts +3 -2
  81. package/dist/learning.js +5 -3
  82. package/dist/mcp-oauth.d.ts +23 -1
  83. package/dist/mcp-oauth.js +46 -5
  84. package/dist/mcp-pin-first.d.ts +4 -2
  85. package/dist/mcp-pin-first.js +4 -3
  86. package/dist/mcp-private-hosts.d.ts +13 -0
  87. package/dist/mcp-private-hosts.js +16 -0
  88. package/dist/mcp-servers-store.d.ts +58 -5
  89. package/dist/mcp-servers-store.js +136 -17
  90. package/dist/mcp.d.ts +2 -2
  91. package/dist/mcp.js +2 -2
  92. package/dist/observation/http.d.ts +4 -1
  93. package/dist/observation/http.js +5 -4
  94. package/dist/openapi.d.ts +1 -0
  95. package/dist/openapi.js +151 -21
  96. package/dist/print.d.ts +6 -3
  97. package/dist/print.js +4 -2
  98. package/dist/run-files.d.ts +6 -2
  99. package/dist/run-files.js +29 -7
  100. package/dist/run-labels.d.ts +23 -0
  101. package/dist/run-labels.js +79 -0
  102. package/dist/run-learning-served.d.ts +1 -1
  103. package/dist/run-reads-over-store.d.ts +5 -1
  104. package/dist/run-reads-over-store.js +8 -4
  105. package/dist/run-recordings.d.ts +20 -0
  106. package/dist/run-recordings.js +133 -0
  107. package/dist/run-secrets.js +12 -4
  108. package/dist/runner/adapter-loop.d.ts +1 -1
  109. package/dist/runner/adapter-loop.js +94 -16
  110. package/dist/runner/adapter-run-spec.d.ts +19 -0
  111. package/dist/runner/adapter-run-spec.js +57 -36
  112. package/dist/runner/beside.d.ts +6 -3
  113. package/dist/runner/beside.js +9 -7
  114. package/dist/runner/cli-run-spec.js +41 -32
  115. package/dist/runner/conformance/harness.js +69 -14
  116. package/dist/runner/conformance/subject.d.ts +4 -1
  117. package/dist/runner/feedback-round.d.ts +9 -25
  118. package/dist/runner/feedback-round.js +22 -40
  119. package/dist/runner/learning-end.d.ts +17 -7
  120. package/dist/runner/learning-end.js +79 -53
  121. package/dist/runner/main.d.ts +12 -1
  122. package/dist/runner/main.js +31 -4
  123. package/dist/runner/mcp-claim.d.ts +3 -0
  124. package/dist/runner/mcp-claim.js +1 -1
  125. package/dist/runner/mcp-run.d.ts +6 -2
  126. package/dist/runner/mcp-run.js +5 -3
  127. package/dist/runner/model-route.d.ts +4 -2
  128. package/dist/runner/model-route.js +8 -8
  129. package/dist/runner/promotion.d.ts +44 -4
  130. package/dist/runner/promotion.js +323 -21
  131. package/dist/runner/reflect-hook.d.ts +5 -0
  132. package/dist/runner/reflect-hook.js +22 -14
  133. package/dist/runner/store-secrets.js +3 -1
  134. package/dist/runner/workflow-first.d.ts +6 -11
  135. package/dist/runner/workflow-first.js +16 -20
  136. package/dist/runs-over-store.d.ts +1 -1
  137. package/dist/runs-over-store.js +5 -2
  138. package/dist/sdk/runs.d.ts +7 -1
  139. package/dist/sdk/runs.js +21 -7
  140. package/dist/secret-cut.js +3 -1
  141. package/dist/secrets.js +5 -3
  142. package/dist/server.d.ts +31 -5
  143. package/dist/server.js +240 -61
  144. package/dist/store/agent-body.d.ts +5 -3
  145. package/dist/store/agent-body.js +14 -10
  146. package/dist/store/dialect.d.ts +3 -0
  147. package/dist/store/dialect.js +1 -0
  148. package/dist/store/index.d.ts +1 -1
  149. package/dist/store/postgres/dialect.js +1 -0
  150. package/dist/store/postgres/migrations/0015_run_labels.sql +5 -0
  151. package/dist/store/postgres/migrations/0016_minted_tokens.sql +21 -0
  152. package/dist/store/schema.d.ts +9 -0
  153. package/dist/store/schema.js +26 -2
  154. package/dist/store/sqlite/connection.js +11 -3
  155. package/dist/store/sqlite/run-patch.d.ts +2 -1
  156. package/dist/store/sqlite/run-patch.js +3 -2
  157. package/dist/store/sqlite/store.js +64 -10
  158. package/dist/store/store.d.ts +38 -1
  159. package/dist/store-reads/journal.js +2 -1
  160. package/dist/store-reads/learning.d.ts +1 -1
  161. package/dist/store-reads/learning.js +6 -1
  162. package/dist/store-reads/loop.d.ts +1 -0
  163. package/dist/store-reads/loop.js +14 -4
  164. package/dist/store-reads/runs.d.ts +4 -3
  165. package/dist/store-reads/runs.js +3 -2
  166. package/dist/store-view.d.ts +5 -0
  167. package/dist/store-view.js +8 -2
  168. package/dist/template-eval.d.ts +11 -0
  169. package/dist/template-eval.js +177 -52
  170. package/dist/templates.d.ts +13 -1
  171. package/dist/templates.js +89 -18
  172. package/dist/timeline/computer.js +2 -1
  173. package/dist/timeline/origin.d.ts +1 -1
  174. package/dist/timeline/origin.js +2 -2
  175. package/dist/tool-list.js +1 -0
  176. package/dist/tools.d.ts +7 -0
  177. package/dist/tools.js +11 -0
  178. package/dist/trigger-adapter.d.ts +9 -4
  179. package/dist/trigger-adapters.js +2 -1
  180. package/dist/trigger-feed.d.ts +12 -0
  181. package/dist/trigger-feed.js +420 -0
  182. package/dist/triggers.d.ts +2 -1
  183. package/dist/triggers.js +23 -5
  184. package/dist/validate.js +7 -2
  185. package/dist/webhooks.js +9 -5
  186. package/dist/workspace/computer-deps.d.ts +5 -1
  187. package/dist/workspace/computer-deps.js +2 -2
  188. package/dist/workspace/computer-for-claim.d.ts +7 -0
  189. package/dist/workspace/computer-for-claim.js +12 -2
  190. package/dist/workspace/index.d.ts +1 -0
  191. package/dist/workspace/index.js +2 -0
  192. package/dist/workspace/paths.d.ts +4 -0
  193. package/dist/workspace/paths.js +9 -0
  194. package/dist/workspace/resolve-computer.d.ts +35 -4
  195. package/dist/workspace/resolve-computer.js +47 -9
  196. package/launcher/agentrun-serve +34 -22
  197. package/package.json +11 -9
  198. package/templates/README.md +38 -4
  199. package/dist/console/assets/index-Jbxjcmdp.js +0 -705
@@ -1,6 +1,7 @@
1
- /** The journal entry a learned_workflow call keeps beside itself: `{ call, workflow, nodes, guards? }`, its call's id, the
2
- * workflow's name, each of its nodes that ran (LearnedNode, at most LEARNED_NODES_MAX) and every guard check it made
3
- * (GuardRow, never capped: a map over more items than the trace holds keeps each); on a replay run's call that a write
1
+ /** The journal entry a learned_workflow call keeps beside itself: `{ call, workflow, nodes, guards?, loops? }`, its call's
2
+ * id, the workflow's name, each of its nodes that ran (LearnedNode, at most LEARNED_NODES_MAX), every guard check it made
3
+ * (GuardRow) and every loop exit (LoopRow), these two never capped (a map over more items than the trace holds keeps
4
+ * each); on a replay run's call that a write
4
5
  * stopped (learn/replay-calls.ts: one the graded run's recording does not have), `replay_skipped: { tool, step }` too; and
5
6
  * `ended`, how the workflow ended (LearnedEnded), on a call that ended (a replay run's call always keeps its entry). */
6
7
  export const LEARNED_NODES = "agentrun.learned_nodes";
@@ -8,7 +9,7 @@ export const LEARNED_NODES = "agentrun.learned_nodes";
8
9
  export const LEARNED_NODES_MAX = 64;
9
10
  /** The LEARNED_NODES entry that counts for each learned_workflow call in `entries`, by the call's id, as its index in
10
11
  * `entries`. A call run again (after a park or a crash: it nests calls) keeps an entry each time; the one that counts is
11
- * its last that ran a node or made a check, as it holds every node and check its rerun made again. A rerun refused before
12
+ * its last that ran a node, made a check or exited a loop, as it holds every node and check its rerun made again. A rerun refused before
12
13
  * any node ran (a replay run keeps that entry: `nodes: []`, ended `failed`) leaves the attempt before it standing; a call
13
14
  * none of whose entries ran a node counts its last. What the run's guard rows (guardsOf) and its timeline rows'
14
15
  * `learned_nodes` (store-reads/journal.ts) both read, so the two never pick apart. */
@@ -21,7 +22,8 @@ export function learnedCallEntries(entries) {
21
22
  const data = entry.data;
22
23
  if (typeof data?.call !== "string")
23
24
  return;
24
- const made = (Array.isArray(data.nodes) && data.nodes.length > 0) || (Array.isArray(data.guards) && data.guards.length > 0);
25
+ // A loop's exit is a run's row as a check is (a loop over an empty map exits with no node ended).
26
+ const made = [data.nodes, data.guards, data.loops].some((rows) => Array.isArray(rows) && rows.length > 0);
25
27
  if (made)
26
28
  ran.add(data.call);
27
29
  if (made || !ran.has(data.call))
@@ -33,6 +35,16 @@ export function learnedCallEntries(entries) {
33
35
  * never the capped trace's), in order, each with its call's workflow, from the entry that counts for each call
34
36
  * (learnedCallEntries). What its metrics keep as `guards`. */
35
37
  export function guardsOf(entries) {
38
+ return rowsOf(entries, "guards");
39
+ }
40
+ /** A run's loop rows, from its root entries: every loop exit of every learned_workflow call (LEARNED_NODES `loops`), read
41
+ * as guardsOf reads `guards`. What its metrics keep as `loops`. */
42
+ export function loopsOf(entries) {
43
+ return rowsOf(entries, "loops");
44
+ }
45
+ /** The rows at `key` of each LEARNED_NODES entry that counts for its call (learnedCallEntries), in order, each with its
46
+ * call's workflow. */
47
+ function rowsOf(entries, key) {
36
48
  const rows = [];
37
49
  const last = learnedCallEntries(entries);
38
50
  for (const [index, entry] of entries.entries()) {
@@ -41,10 +53,11 @@ export function guardsOf(entries) {
41
53
  const data = entry.data;
42
54
  if (typeof data?.call === "string" && last.get(data.call) !== index)
43
55
  continue;
44
- if (!Array.isArray(data?.guards))
56
+ const kept = data?.[key];
57
+ if (!Array.isArray(kept))
45
58
  continue;
46
- const workflow = typeof data.workflow === "string" ? data.workflow : undefined;
47
- for (const row of data.guards)
59
+ const workflow = typeof data?.workflow === "string" ? data.workflow : undefined;
60
+ for (const row of kept)
48
61
  if (row && typeof row === "object")
49
62
  rows.push(workflow ? { ...row, workflow } : row);
50
63
  }
@@ -1,5 +1,5 @@
1
1
  import { type ToolRegistration } from "@earendil-works/pi-durable";
2
- import { type GuardRow, type LearnedEnded, type LearnedNode } from "./learned-nodes.js";
2
+ import { type GuardRow, type LearnedEnded, type LearnedNode, type LoopRow } from "./learned-nodes.js";
3
3
  import { type LearnedWorkflow } from "./learning.js";
4
4
  import type { ModelRef } from "./model.js";
5
5
  import { type Ledger } from "./paid-calls.js";
@@ -155,8 +155,8 @@ export declare function learnedWorkflowTool(run: LearnedWorkflowRun): ToolRegist
155
155
  * `nested`: the session's tools as calls nested in this one, which its MCP nodes run as; and the values its first run
156
156
  * fixed (`memo`), so a rerun of the call (after a park, a crash) goes on from what its model, decision and call nodes
157
157
  * answered then, its MCP calls with the arguments they were asked and approved with, each recorded one answered from its
158
- * record, never sent twice. */
159
- export declare function runLearned(run: LearnedWorkflowRun, flow: LearnedWorkflow, input: unknown, signal?: AbortSignal, ledger?: Ledger, nodes?: LearnedNode[], guards?: GuardRow[], nested?: NestedCalls): Promise<{
158
+ * record, never sent twice. `loops`: where each loop's exit is added (LoopRow), as `guards` are. */
159
+ export declare function runLearned(run: LearnedWorkflowRun, flow: LearnedWorkflow, input: unknown, signal?: AbortSignal, ledger?: Ledger, nodes?: LearnedNode[], guards?: GuardRow[], nested?: NestedCalls, loops?: LoopRow[]): Promise<{
160
160
  text: string;
161
161
  isError: boolean;
162
162
  nodes: LearnedNode[];
@@ -273,18 +273,21 @@ export function learnedWorkflowTool(run) {
273
273
  // written outside the stopped call's context, and still ends as a stop.
274
274
  const trace = [];
275
275
  const guards = [];
276
+ // Every loop's exit (`loops`, uncapped too: a quote re-pick is a loop's second pass, which the run's metrics count).
277
+ const loops = [];
276
278
  // A replay's write the recording did not have (learn/replay-calls.ts) rides on the same entry, ran a node or not; so
277
279
  // does how the workflow ended (`ended`, LearnedEnded), the one thing a replay's outcome reads (workflow-first.ts
278
280
  // pathMetrics): a replay run keeps its entry whatever ran, so a refusal before any node is read as one.
279
281
  const keep = (signal, ended) => {
280
282
  const skipped = run.replay?.skipped;
281
- if (!trace.length && !guards.length && !skipped && !(run.replay && ended))
283
+ // A loop's exit counts too: a loop over an empty map ends no node, yet its row is the run's (metrics `loops`).
284
+ if (!trace.length && !guards.length && !loops.length && !skipped && !(run.replay && ended))
282
285
  return undefined;
283
- return api.commit(async (tx) => void (await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: LEARNED_NODES, data: { call: ledger.call, workflow: flow.name, nodes: trace, ...(guards.length ? { guards } : {}), ...(skipped ? { replay_skipped: skipped } : {}), ...(ended ? { ended } : {}) } })), signal).catch(() => undefined);
286
+ return api.commit(async (tx) => void (await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: LEARNED_NODES, data: { call: ledger.call, workflow: flow.name, nodes: trace, ...(guards.length ? { guards } : {}), ...(loops.length ? { loops } : {}), ...(skipped ? { replay_skipped: skipped } : {}), ...(ended ? { ended } : {}) } })), signal).catch(() => undefined);
284
287
  };
285
288
  let said;
286
289
  try {
287
- said = await runLearned(run, flow, input, context?.abortSignal, ledger, trace, guards, run.nestedOf?.(api.callId));
290
+ said = await runLearned(run, flow, input, context?.abortSignal, ledger, trace, guards, run.nestedOf?.(api.callId), loops);
288
291
  }
289
292
  catch (error) {
290
293
  await keep(BACKGROUND_CONTEXT);
@@ -303,8 +306,8 @@ export function learnedWorkflowTool(run) {
303
306
  * `nested`: the session's tools as calls nested in this one, which its MCP nodes run as; and the values its first run
304
307
  * fixed (`memo`), so a rerun of the call (after a park, a crash) goes on from what its model, decision and call nodes
305
308
  * answered then, its MCP calls with the arguments they were asked and approved with, each recorded one answered from its
306
- * record, never sent twice. */
307
- export async function runLearned(run, flow, input, signal, ledger, nodes = [], guards = [], nested) {
309
+ * record, never sent twice. `loops`: where each loop's exit is added (LoopRow), as `guards` are. */
310
+ export async function runLearned(run, flow, input, signal, ledger, nodes = [], guards = [], nested, loops = []) {
308
311
  const refuse = (why) => ({ text: `The learned workflow ${flow.name} was not run: ${why}`, isError: true, nodes, ended: "failed" });
309
312
  if (!input || typeof input !== "object" || Array.isArray(input))
310
313
  return refuse("its input must be a JSON object");
@@ -461,6 +464,12 @@ export async function runLearned(run, flow, input, signal, ledger, nodes = [], g
461
464
  const soft = replay ? dsl.softEscalates(doc) : undefined;
462
465
  // Each node as it ends, by the DSL's own event: what the call's timeline row shows of it.
463
466
  const onEvent = (event) => {
467
+ if (event.type === "loop.exited") {
468
+ const detail = (event.detail ?? {});
469
+ if (typeof detail.iterations === "number")
470
+ loops.push({ node: String(event.label), iterations: detail.iterations, met: detail.reason === "condition_met" });
471
+ return;
472
+ }
464
473
  if (event.type === "escalate.evaluated") {
465
474
  const detail = (event.detail ?? {});
466
475
  if (detail.soft === true)
@@ -0,0 +1,23 @@
1
+ /** The loop's numbers as a definition may set them (each optional: its default stands in). */
2
+ export interface LearningLoop {
3
+ readonly compile_after?: number;
4
+ readonly agree_min?: number;
5
+ readonly alone_min?: number;
6
+ }
7
+ /** A definition's `learning`, as kept on an agentic revision. */
8
+ export type LearningSetting = boolean | "notes" | LearningLoop;
9
+ export declare const COMPILE_AFTER_DEFAULT = 20;
10
+ export declare const AGREE_MIN_DEFAULT = 0.8;
11
+ export declare const ALONE_MIN_DEFAULT = 0.7;
12
+ /** The most completed runs a compile may wait for: the newest this many of an agent's runs are what it counts and checks. */
13
+ export declare const COMPILE_AFTER_MAX = 200;
14
+ /** Whether `learning` has the agent's runs learn workflows too (true, or an object): never "notes", false or absent. */
15
+ export declare const learnsWorkflowsOf: (learning: unknown) => boolean;
16
+ /** The loop's numbers for a revision's `learning`: its object's, each one it leaves out at its default. */
17
+ export declare function loopOf(learning: unknown): Required<LearningLoop>;
18
+ /** What is wrong with a definition's `learning`, in words naming the field (`at` its path), or undefined when it is one
19
+ * of true, false, "notes" or an object of the loop's numbers. */
20
+ export declare function learningSettingIssue(value: unknown, at?: string): string | undefined;
21
+ /** A valid `learning` as a revision keeps it: an object's numbers in one order, so two definitions that say the same are
22
+ * one body. */
23
+ export declare function learningSettingOf(value: LearningSetting): LearningSetting;
@@ -0,0 +1,51 @@
1
+ // An agent definition's `learning`: true, false, "notes", or an object, which is on (as true) with the loop's numbers set
2
+ // on it. Every number of the loop lives here, on the agent, each with a default: none is an engine constant.
3
+ // compile_after (N): the agent's job compiles into a workflow once it has this many completed agent runs;
4
+ // agree_min (A): the compiled draft is checked once on the inputs of those N runs, and promoted only when, of the inputs
5
+ // it answered alone, at least this share say what the agent's own recorded answer said;
6
+ // alone_min (S): ...and when it answered at least this share of them alone (no escalate, no failed step).
7
+ // learn/compile.ts compileDue reads compile_after; runner/promotion.ts's check reads all three.
8
+ export const COMPILE_AFTER_DEFAULT = 20;
9
+ export const AGREE_MIN_DEFAULT = 0.8;
10
+ export const ALONE_MIN_DEFAULT = 0.7;
11
+ /** The most completed runs a compile may wait for: the newest this many of an agent's runs are what it counts and checks. */
12
+ export const COMPILE_AFTER_MAX = 200;
13
+ const LOOP_KEYS = ["compile_after", "agree_min", "alone_min"];
14
+ const isLoop = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
15
+ /** Whether `learning` has the agent's runs learn workflows too (true, or an object): never "notes", false or absent. */
16
+ export const learnsWorkflowsOf = (learning) => learning === true || isLoop(learning);
17
+ /** The loop's numbers for a revision's `learning`: its object's, each one it leaves out at its default. */
18
+ export function loopOf(learning) {
19
+ const set = isLoop(learning) ? learning : {};
20
+ return {
21
+ compile_after: set.compile_after ?? COMPILE_AFTER_DEFAULT,
22
+ agree_min: set.agree_min ?? AGREE_MIN_DEFAULT,
23
+ alone_min: set.alone_min ?? ALONE_MIN_DEFAULT,
24
+ };
25
+ }
26
+ /** What is wrong with a definition's `learning`, in words naming the field (`at` its path), or undefined when it is one
27
+ * of true, false, "notes" or an object of the loop's numbers. */
28
+ export function learningSettingIssue(value, at = "learning") {
29
+ if (typeof value === "boolean" || value === "notes")
30
+ return undefined;
31
+ if (!isLoop(value))
32
+ return `${at} is true, false, "notes" or an object of the loop's numbers ({compile_after?, agree_min?, alone_min?}, on with those set)`;
33
+ const other = Object.keys(value).find((key) => !LOOP_KEYS.includes(key));
34
+ if (other !== undefined)
35
+ return `${at}.${other} is not one of the loop's numbers: ${LOOP_KEYS.join(", ")}`;
36
+ const { compile_after: after, agree_min: agree, alone_min: alone } = value;
37
+ if (after !== undefined && !(Number.isInteger(after) && after >= 1 && after <= COMPILE_AFTER_MAX))
38
+ return `${at}.compile_after is a whole number of completed runs from 1 to ${COMPILE_AFTER_MAX}`;
39
+ for (const [key, share] of [["agree_min", agree], ["alone_min", alone]]) {
40
+ if (share !== undefined && !(typeof share === "number" && Number.isFinite(share) && share >= 0 && share <= 1))
41
+ return `${at}.${key} is a share from 0 to 1`;
42
+ }
43
+ return undefined;
44
+ }
45
+ /** A valid `learning` as a revision keeps it: an object's numbers in one order, so two definitions that say the same are
46
+ * one body. */
47
+ export function learningSettingOf(value) {
48
+ if (!isLoop(value))
49
+ return value;
50
+ return Object.fromEntries(LOOP_KEYS.flatMap((key) => (value[key] !== undefined ? [[key, value[key]]] : [])));
51
+ }
@@ -56,6 +56,9 @@ export declare const said: {
56
56
  /** A run whose only work was its learned workflows, each answering, with nothing said after its first message: it was
57
57
  * not asked to look back (runner/learning-end.ts onlyLearnedWorkflows). */
58
58
  onlyWorkflow: string;
59
+ /** A run of an agent that learns workflows, with no feedback from its owner (no grade's words, no message after its
60
+ * first): it was not asked to look back (runner/learning-end.ts ownerSaid); its trace is what a compile reads. */
61
+ noFeedback: string;
59
62
  /** A run started with `learning: "use"`: it read what its agent learned and kept nothing, as asked. */
60
63
  use: string;
61
64
  /** A merge whose every item the owner has since retired: nothing it learned is kept now. */
@@ -133,6 +133,9 @@ export const said = {
133
133
  /** A run whose only work was its learned workflows, each answering, with nothing said after its first message: it was
134
134
  * not asked to look back (runner/learning-end.ts onlyLearnedWorkflows). */
135
135
  onlyWorkflow: "Nothing new: the run only ran a learned workflow.",
136
+ /** A run of an agent that learns workflows, with no feedback from its owner (no grade's words, no message after its
137
+ * first): it was not asked to look back (runner/learning-end.ts ownerSaid); its trace is what a compile reads. */
138
+ noFeedback: "Not looked back on: this agent learns workflows, and it looks back only on your feedback.",
136
139
  /** A run started with `learning: "use"`: it read what its agent learned and kept nothing, as asked. */
137
140
  use: "Used what its agent learned; this run keeps nothing.",
138
141
  /** A merge whose every item the owner has since retired: nothing it learned is kept now. */
@@ -5,8 +5,9 @@ import { type Workspace } from "./workspace/index.js";
5
5
  * default: a run learns when its agent's definition says `learning: true`. `off`: no run this server starts does. */
6
6
  export declare const LEARNING_MODES: readonly ["on", "off"];
7
7
  export type LearningMode = (typeof LEARNING_MODES)[number];
8
- /** Whether a revision's `learning` (its definition's: true, false or "notes") has its runs learn: true learns notes, skills
9
- * and workflows; "notes" learns notes and skills alone, never given a learned workflow nor asked to draft one. */
8
+ /** Whether a revision's `learning` (its definition's: true, false, "notes" or the loop's numbers, learning-setting.ts) has
9
+ * its runs learn: true (or an object) learns notes, skills and workflows; "notes" learns notes and skills alone, never
10
+ * given a learned workflow nor asked to draft one. */
10
11
  export declare const learnsOf: (learning: unknown) => boolean;
11
12
  export declare const LEARNING_ENV = "AGENTRUN_SERVE_LEARNING";
12
13
  /** The switch: `given`, else AGENTRUN_SERVE_LEARNING, else on. Any other value is an error, and the server does not start. */
package/dist/learning.js CHANGED
@@ -40,14 +40,16 @@ import { readSeed as readFolderSeed } from "./learn/seed-check.js";
40
40
  import { agentFolderOf, serialBy, writeDurable } from "./files.js";
41
41
  import { withoutLoopbackAddresses } from "./key-refusal.js";
42
42
  import { DETAIL_MAX, LIST_DETAIL, said, short, wordsOf } from "./learning-words.js";
43
+ import { learnsWorkflowsOf } from "./learning-setting.js";
43
44
  import { isObject } from "./validate.js";
44
45
  import { isWorkspaceError, WorkspaceError, workspaceAt } from "./workspace/index.js";
45
46
  /** The server's learning switch (`--learning`, AGENTRUN_SERVE_LEARNING; capabilities.features.learning). `on`, the
46
47
  * default: a run learns when its agent's definition says `learning: true`. `off`: no run this server starts does. */
47
48
  export const LEARNING_MODES = ["on", "off"];
48
- /** Whether a revision's `learning` (its definition's: true, false or "notes") has its runs learn: true learns notes, skills
49
- * and workflows; "notes" learns notes and skills alone, never given a learned workflow nor asked to draft one. */
50
- export const learnsOf = (learning) => learning === true || learning === "notes";
49
+ /** Whether a revision's `learning` (its definition's: true, false, "notes" or the loop's numbers, learning-setting.ts) has
50
+ * its runs learn: true (or an object) learns notes, skills and workflows; "notes" learns notes and skills alone, never
51
+ * given a learned workflow nor asked to draft one. */
52
+ export const learnsOf = (learning) => learnsWorkflowsOf(learning) || learning === "notes";
51
53
  export const LEARNING_ENV = "AGENTRUN_SERVE_LEARNING";
52
54
  /** The switch: `given`, else AGENTRUN_SERVE_LEARNING, else on. Any other value is an error, and the server does not start. */
53
55
  export function learningOf(env, given) {
@@ -101,6 +101,17 @@ export type Reach = {
101
101
  allowed?: readonly string[];
102
102
  loopback?: boolean;
103
103
  };
104
+ /** Where a feed trigger's read of `url` (feed/fetch.ts readFeed, each redirect again) may go, before anything is sent:
105
+ * `checked`'s rule, an MCP server's, with plain http allowed on a public address alone (a feed is public text, and many
106
+ * are served over http; a private host the owner allows, `reach.allowed`, is read over https). A URL on loopback as
107
+ * written where `reach.loopback` allows it (a local install, as for an MCP server) on any port but this server's own:
108
+ * `address` undefined, dialled as written. A URL that isn't http(s) is refused. */
109
+ export declare function feedAt(url: URL, signal: AbortSignal, network: OAuthNetwork, reach?: Reach): Promise<{
110
+ refused: string;
111
+ unresolved?: true;
112
+ } | {
113
+ address: string | undefined;
114
+ }>;
104
115
  /** Where a request to the MCP server at `url` may go, before anything is sent to it: the preview, the save, the tools'
105
116
  * refresh and the sign-in on this server, and each request of a run's calls on the runner. The rule is `checked`'s, the
106
117
  * one an authorization server's endpoint is held to: a public https address; a private-network one only for a host the
@@ -115,6 +126,14 @@ export declare function mcpServerAt(url: URL, signal: AbortSignal, network: OAut
115
126
  } | {
116
127
  address: string | undefined;
117
128
  }>;
129
+ /** Where a read of a calendar's file at `url` may go (calendar/fetch.ts, each redirect hop): `mcpServerAt`'s rule, the
130
+ * server's one, in the calendar's words. Dialled with dialAt. */
131
+ export declare function calendarAt(url: URL, signal: AbortSignal, network: OAuthNetwork, reach?: Reach): Promise<{
132
+ refused: string;
133
+ unresolved?: true;
134
+ } | {
135
+ address: string | undefined;
136
+ }>;
118
137
  /** A fetch to the MCP server `mcpServerAt` checked: dialled at `address` (the network's dial, else its fetch), or as
119
138
  * written when there is none (a loopback URL a local install allows), through `plain`. */
120
139
  export declare const dialAt: (network: OAuthNetwork, address: string | undefined, plain?: typeof fetch) => (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
@@ -142,9 +161,12 @@ export declare class McpSignIns {
142
161
  /** Whether this server is a local install (McpServersOverStore.attach): only then may a loopback MCP server's
143
162
  * authorization server be on loopback too. */
144
163
  loopback: boolean;
164
+ /** A runner's registry (mcp-pin-first.ts registryListing), which listens nowhere: the own addresses of the
165
+ * local-install server beside it (Serve.own), held to as this server's own are. Set by McpServersOverStore.attach. */
166
+ beside: readonly string[];
145
167
  /** This server's own local addresses, whose ports a loopback authorization server may never name: where it listens,
146
168
  * and its public address too when that is on loopback (a local https proxy on another port, in front of the
147
- * listener, reaches this server). */
169
+ * listener, reaches this server); on a runner, the server's beside it. */
148
170
  get own(): string[];
149
171
  /** CIMD only from a public https address: an authorization server must be able to fetch the document. */
150
172
  private get metadataUrl();
package/dist/mcp-oauth.js CHANGED
@@ -74,6 +74,22 @@ export const systemNetwork = {
74
74
  }
75
75
  },
76
76
  };
77
+ /** The authorization endpoints, by host, that give a refresh token only when the sign-in asks for offline access in
78
+ * their own words, and the parameters that ask: Google's, which gives one only with access_type=offline, and on a
79
+ * sign-in again only with prompt=consent. The page the owner opens there carries them (askingOffline); any other
80
+ * authorization server's is the SDK's, unchanged. */
81
+ const OFFLINE_ACCESS = { "accounts.google.com": { access_type: "offline", prompt: "consent" } };
82
+ /** `url`, the authorization page the owner opens (the discovered authorization endpoint, as the SDK builds it), with
83
+ * what its host asks for a refresh token (OFFLINE_ACCESS), each once; any other host's, as it is. */
84
+ function askingOffline(url) {
85
+ const asks = Object.hasOwn(OFFLINE_ACCESS, url.hostname) ? OFFLINE_ACCESS[url.hostname] : undefined;
86
+ if (!asks)
87
+ return url;
88
+ const out = new URL(url);
89
+ for (const [key, value] of Object.entries(asks))
90
+ out.searchParams.set(key, value);
91
+ return out;
92
+ }
77
93
  /** A request the address check refused before anything was sent (checked's words): no try again reaches it. */
78
94
  export class EndpointRefused extends Error {
79
95
  name = "EndpointRefused";
@@ -168,7 +184,7 @@ function loopbackAllowed(url, mcpUrl, own) {
168
184
  * link-local, unspecified, multicast or broadcast, never this machine's (`network.local`) nor this server's own
169
185
  * (`reach.own`). Every address its name resolves to must pass, and the one dialled is one checked. An unlisted host
170
186
  * whose private addresses the list could allow is refused in words that name it and where to allow it. */
171
- async function checked(subject, url, signal, network, reach = {}) {
187
+ async function checked(subject, url, signal, network, reach = {}, plain = false) {
172
188
  let at;
173
189
  try {
174
190
  at = new URL(url);
@@ -202,15 +218,30 @@ async function checked(subject, url, signal, network, reach = {}) {
202
218
  const own = [...(network.local ?? localAddresses)(), ...(reach.own ?? []).map((one) => URL.parse(one)?.hostname.replace(/^\[|\]$/g, "") ?? "")];
203
219
  if (!inside.every((address) => privateAllowed(address, own)))
204
220
  return { refused: `${subject} is a private address; refused` };
221
+ // Plain http is for a public address alone: a private host, allowed or not, is read over https.
222
+ if (plain && at.protocol === "http:")
223
+ return { refused: `${subject} is a private address; refused` };
205
224
  const named = hostKey(at.hostname);
206
225
  // Allowing it helps only an https endpoint: a plain-http one keeps the private-address words.
207
226
  if (!(reach.allowed ?? []).includes(named))
208
227
  return { refused: at.protocol === "https:" ? `${subject} is on a private network, refused: an owner can allow ${named} in ${PRIVATE_HOSTS_PAGE}` : `${subject} is a private address; refused` };
209
228
  }
210
- if (at.protocol !== "https:")
229
+ if (at.protocol !== "https:" && !(plain && at.protocol === "http:"))
211
230
  return { refused: `${subject} is not https; refused` };
212
231
  return { address: addresses[0] };
213
232
  }
233
+ /** Where a feed trigger's read of `url` (feed/fetch.ts readFeed, each redirect again) may go, before anything is sent:
234
+ * `checked`'s rule, an MCP server's, with plain http allowed on a public address alone (a feed is public text, and many
235
+ * are served over http; a private host the owner allows, `reach.allowed`, is read over https). A URL on loopback as
236
+ * written where `reach.loopback` allows it (a local install, as for an MCP server) on any port but this server's own:
237
+ * `address` undefined, dialled as written. A URL that isn't http(s) is refused. */
238
+ export async function feedAt(url, signal, network, reach = {}) {
239
+ if (url.protocol !== "http:" && url.protocol !== "https:")
240
+ return { refused: `the feed at ${url.href.slice(0, 200)} is not http or https; refused` };
241
+ if (reach.loopback && loopbackAllowed(url, url.href, reach.own ?? []))
242
+ return { address: undefined };
243
+ return checked(`the feed at ${url.host}`, url.href, signal, network, reach, true);
244
+ }
214
245
  /** Where a request to the MCP server at `url` may go, before anything is sent to it: the preview, the save, the tools'
215
246
  * refresh and the sign-in on this server, and each request of a run's calls on the runner. The rule is `checked`'s, the
216
247
  * one an authorization server's endpoint is held to: a public https address; a private-network one only for a host the
@@ -224,6 +255,13 @@ export async function mcpServerAt(url, signal, network, reach = {}) {
224
255
  return { address: undefined };
225
256
  return checked(`the MCP server at ${url.host}`, url.href, signal, network, reach);
226
257
  }
258
+ /** Where a read of a calendar's file at `url` may go (calendar/fetch.ts, each redirect hop): `mcpServerAt`'s rule, the
259
+ * server's one, in the calendar's words. Dialled with dialAt. */
260
+ export async function calendarAt(url, signal, network, reach = {}) {
261
+ if (reach.loopback && loopbackAllowed(url, url.href, reach.own ?? []))
262
+ return { address: undefined };
263
+ return checked(`the calendar at ${url.host}`, url.href, signal, network, reach);
264
+ }
227
265
  /** A fetch to the MCP server `mcpServerAt` checked: dialled at `address` (the network's dial, else its fetch), or as
228
266
  * written when there is none (a loopback URL a local install allows), through `plain`. */
229
267
  export const dialAt = (network, address, plain = fetch) => (input, init = {}) => {
@@ -301,12 +339,15 @@ export class McpSignIns {
301
339
  /** Whether this server is a local install (McpServersOverStore.attach): only then may a loopback MCP server's
302
340
  * authorization server be on loopback too. */
303
341
  loopback = false;
342
+ /** A runner's registry (mcp-pin-first.ts registryListing), which listens nowhere: the own addresses of the
343
+ * local-install server beside it (Serve.own), held to as this server's own are. Set by McpServersOverStore.attach. */
344
+ beside = [];
304
345
  /** This server's own local addresses, whose ports a loopback authorization server may never name: where it listens,
305
346
  * and its public address too when that is on loopback (a local https proxy on another port, in front of the
306
- * listener, reaches this server). */
347
+ * listener, reaches this server); on a runner, the server's beside it. */
307
348
  get own() {
308
349
  const base = URL.parse(this.base);
309
- return [this.listening, ...(base && LOOPBACK.test(base.hostname) ? [this.base] : [])].filter(Boolean);
350
+ return [this.listening, ...(base && LOOPBACK.test(base.hostname) ? [this.base] : []), ...this.beside].filter(Boolean);
310
351
  }
311
352
  /** CIMD only from a public https address: an authorization server must be able to fetch the document. */
312
353
  get metadataUrl() {
@@ -442,7 +483,7 @@ export class McpSignIns {
442
483
  saveClientInformation: (client) => void (entry.client = client),
443
484
  tokens: () => undefined,
444
485
  saveTokens: (tokens) => hooks.saved?.(tokens),
445
- redirectToAuthorization: (url) => hooks.redirect?.(url),
486
+ redirectToAuthorization: (url) => hooks.redirect?.(askingOffline(url)),
446
487
  saveCodeVerifier: (verifier) => void (entry.verifier = verifier),
447
488
  codeVerifier: () => entry.verifier ?? "",
448
489
  // Checked before anything discovery found is used: registration, the page the owner opens, the code exchange.
@@ -25,12 +25,14 @@ export declare function pinFirst(revision: {
25
25
  readonly mcpPin?: unknown;
26
26
  }, deps: PinFirstDeps): Promise<McpPin | undefined>;
27
27
  /** A runner's pinListing (PinFirstDeps): the owner's registry over the one store, opened with the runner's seal key (the
28
- * server's) on the first listing it is asked for, loopback allowed only for a runner beside a local install. `githubApp`:
28
+ * server's) on the first listing it is asked for, loopback allowed only for a runner beside a local install, never to
29
+ * that server's own ports (`own`, Serve.own). `githubApp`:
29
30
  * the run's GitHub App access (runner/mcp-github.ts), which lists a `github_app` server with a token of the run's
30
31
  * repository, metadata read alone, as a save lists it with one (github-connection.ts tokenForListing); without it such a
31
32
  * server can't be listed. `appOrigin`: a test's fake GitHub MCP (McpServersOverStore.appOrigin). */
32
- export declare function registryListing(store: Parameters<typeof mcpServersOverStore>[0], sealKey: Buffer, { loopback, network, githubApp, appOrigin }?: {
33
+ export declare function registryListing(store: Parameters<typeof mcpServersOverStore>[0], sealKey: Buffer, { loopback, own, network, githubApp, appOrigin }?: {
33
34
  loopback?: boolean;
35
+ own?: readonly string[];
34
36
  network?: OAuthNetwork;
35
37
  githubApp?: GithubAppAccess;
36
38
  appOrigin?: string;
@@ -63,11 +63,12 @@ export async function pinFirst(revision, deps) {
63
63
  return ((await deps.pinOnce(revision.id, pin)) ?? undefined);
64
64
  }
65
65
  /** A runner's pinListing (PinFirstDeps): the owner's registry over the one store, opened with the runner's seal key (the
66
- * server's) on the first listing it is asked for, loopback allowed only for a runner beside a local install. `githubApp`:
66
+ * server's) on the first listing it is asked for, loopback allowed only for a runner beside a local install, never to
67
+ * that server's own ports (`own`, Serve.own). `githubApp`:
67
68
  * the run's GitHub App access (runner/mcp-github.ts), which lists a `github_app` server with a token of the run's
68
69
  * repository, metadata read alone, as a save lists it with one (github-connection.ts tokenForListing); without it such a
69
70
  * server can't be listed. `appOrigin`: a test's fake GitHub MCP (McpServersOverStore.appOrigin). */
70
- export function registryListing(store, sealKey, { loopback = false, network, githubApp, appOrigin } = {}) {
71
+ export function registryListing(store, sealKey, { loopback = false, own = [], network, githubApp, appOrigin } = {}) {
71
72
  let registry;
72
73
  // The listing tokens minted and not yet revoked, and how many listings are under way: no one holds a listing token
73
74
  // after its listing (the claim's cleanup reaches only githubTokens' tokens), so once no listing is under way, each is
@@ -77,7 +78,7 @@ export function registryListing(store, sealKey, { loopback = false, network, git
77
78
  const open = async () => {
78
79
  const { version } = JSON.parse(await readFile(new URL("../package.json", import.meta.url), "utf8"));
79
80
  const opened = mcpServersOverStore(store, { [SEAL_KEY_ENV]: sealKey.toString("base64") }, version, network);
80
- opened.attach("", "", loopback);
81
+ opened.attach("", "", loopback, own);
81
82
  if (appOrigin)
82
83
  opened.appOrigin = appOrigin;
83
84
  if (githubApp)
@@ -19,6 +19,19 @@ export declare function privateAllowed(address: string, own: readonly string[]):
19
19
  export declare function privateOAuthHosts(store: {
20
20
  settings: Pick<Settings, "get">;
21
21
  }): Promise<string[]>;
22
+ /** The store.settings key a server keeps its own addresses under at each start (Serve.own: where it listens, and its
23
+ * public address when that is on loopback): `{ own: string[] }`. Addresses alone, never its loopback opt-in, which each
24
+ * process reads from its own environment: a runner in its own process with its own opt-in reads them so its runs never
25
+ * reach that server's ports on loopback (runner/main.ts runnerLoop), whatever port the server was started on. */
26
+ export declare const MCP_SERVER_OWN_KEY = "mcp.server_own";
27
+ /** The server's start: its own addresses, replacing the last start's. */
28
+ export declare function saveServerOwn(store: {
29
+ settings: Pick<Settings, "put">;
30
+ }, own: readonly string[]): Promise<void>;
31
+ /** The addresses the server kept at its last start (saveServerOwn), read at each use; none before a server started. */
32
+ export declare function serverOwn(store: {
33
+ settings: Pick<Settings, "get">;
34
+ }): Promise<string[]>;
22
35
  /** The list replaced with `hosts` (already checked: checkPrivateHosts). */
23
36
  export declare function savePrivateOAuthHosts(store: {
24
37
  settings: Pick<Settings, "put">;
@@ -62,6 +62,22 @@ function hostsOf(value) {
62
62
  export async function privateOAuthHosts(store) {
63
63
  return hostsOf(await store.settings.get(MCP_PRIVATE_HOSTS_KEY));
64
64
  }
65
+ /** The store.settings key a server keeps its own addresses under at each start (Serve.own: where it listens, and its
66
+ * public address when that is on loopback): `{ own: string[] }`. Addresses alone, never its loopback opt-in, which each
67
+ * process reads from its own environment: a runner in its own process with its own opt-in reads them so its runs never
68
+ * reach that server's ports on loopback (runner/main.ts runnerLoop), whatever port the server was started on. */
69
+ export const MCP_SERVER_OWN_KEY = "mcp.server_own";
70
+ /** The server's start: its own addresses, replacing the last start's. */
71
+ export async function saveServerOwn(store, own) {
72
+ await store.settings.put(MCP_SERVER_OWN_KEY, { own: [...own] });
73
+ }
74
+ /** The addresses the server kept at its last start (saveServerOwn), read at each use; none before a server started. */
75
+ export async function serverOwn(store) {
76
+ const value = await store.settings.get(MCP_SERVER_OWN_KEY);
77
+ if (typeof value !== "object" || value === null || !Array.isArray(value.own))
78
+ return [];
79
+ return (value.own).filter((one) => typeof one === "string");
80
+ }
65
81
  /** The list replaced with `hosts` (already checked: checkPrivateHosts). */
66
82
  export async function savePrivateOAuthHosts(store, hosts) {
67
83
  await store.settings.put(MCP_PRIVATE_HOSTS_KEY, { hosts: [...hosts] });
@@ -1,6 +1,7 @@
1
1
  import { type Listed, type McpPrices, type McpTool } from "./mcp-probe.js";
2
2
  import { type SecretMeta } from "./secret-writes.js";
3
3
  import { type ClientKind, type OAuthNetwork } from "./mcp-oauth.js";
4
+ import { type Cleanup, type ComposioMade } from "./composio-made.js";
4
5
  import { type RecordedRow, type SourceRecord } from "./mcp-sources.js";
5
6
  import { type ToolSettingsMap } from "./tool-plane.js";
6
7
  import { type McpCredentialMark, type Mcp, type McpOauth, type Settings, type Store } from "./store/index.js";
@@ -17,11 +18,32 @@ type McpServersStore = {
17
18
  * `unusable` when either can't be had (a key that does not open here, an address that names no server): the delete of
18
19
  * our row still stands, and the answer says to remove it in Composio by hand. Taken from the row actually removed, never
19
20
  * a row read before it, so a server saved again under the name meanwhile is not the one deleted on Composio. */
20
- export type ComposioHandle = {
21
+ export type ComposioHandle = ({
21
22
  id: string;
22
23
  key: string;
23
24
  } | {
24
25
  unusable: true;
26
+ }) & {
27
+ cleanup?: Cleanup;
28
+ };
29
+ /** What a save over a preset server leaves to do at Composio, with the key the server was saved with before, which made
30
+ * what it left; `unusable` when that key does not open here. `mcp`: the Composio MCP server the row named before, which
31
+ * the preset made and the row names no longer (a preset save over it makes a new one; an ordinary save moves it off
32
+ * Composio). `cleanup`: what that save had made there besides that this one no longer stands on (composio-made.ts
33
+ * droppedOf; all of it, as a delete's cleanupOf, for a row moved off Composio). */
34
+ export type ComposioDropped = ({
35
+ key: string;
36
+ } | {
37
+ unusable: true;
38
+ }) & {
39
+ cleanup: Cleanup;
40
+ mcp?: string;
41
+ };
42
+ /** A preset row's save guard (McpServersOverStore.save): `turn`, the Composio turns its write and cleanup take; `inUse`,
43
+ * refused while Composio triggers use the server (composio-triggers.ts inUse). */
44
+ export type SaveGuard = {
45
+ turn: <T>(work: () => Promise<T>) => Promise<T>;
46
+ inUse: () => Promise<void>;
25
47
  };
26
48
  export declare class McpServersOverStore {
27
49
  private readonly store;
@@ -55,8 +77,12 @@ export declare class McpServersOverStore {
55
77
  /** This server's address as a browser reaches it and where it listens (McpServers.attach). `local`: whether its
56
78
  * operator said this is a local install (ServeOptions.mcpLoopback, the CLI's AGENTRUN_MCP_ALLOW_LOOPBACK=1), the one kind
57
79
  * of server an MCP server's URL may be on loopback for. Never inferred from where it listens: a hosted container
58
- * listens on loopback behind its proxy too. Omitted, or never attached, it is not one. */
59
- attach(base: string, listening: string, local?: boolean): void;
80
+ * listens on loopback behind its proxy too. Omitted, or never attached, it is not one. `beside`: a runner's registry
81
+ * (registryListing), attached at no address of its own, is held to the own addresses of the server beside it. */
82
+ attach(base: string, listening: string, local?: boolean, beside?: readonly string[]): void;
83
+ /** This server's own addresses (McpSignIns.own): where it listens, and its public address when that is on loopback. A
84
+ * read on loopback, here or by the runner beside it (Serve.own), never goes to their ports. */
85
+ get own(): readonly string[];
60
86
  clientDocument(): {
61
87
  redirect_uris: string[];
62
88
  token_endpoint_auth_method?: string | undefined;
@@ -79,6 +105,18 @@ export declare class McpServersOverStore {
79
105
  };
80
106
  /** The origin the authorization server sends the browser back to. */
81
107
  get callbackOrigin(): string;
108
+ /** Where a server-side read of a URL may go (a feed's, a calendar's), as an MCP server's requests may: this server's
109
+ * network, its own addresses (never read), the private-network hosts the owner allows (read now, at each call), loopback
110
+ * only on a local install, and stopped with the server. */
111
+ outboundReach(): Promise<{
112
+ network: OAuthNetwork;
113
+ reach: {
114
+ own: readonly string[];
115
+ allowed: readonly string[];
116
+ loopback: boolean;
117
+ };
118
+ signal: AbortSignal;
119
+ }>;
82
120
  /** The server's own tool settings, set as the server starts. */
83
121
  toolSettings: () => ToolSettingsMap;
84
122
  close(boundMs?: number): Promise<void>;
@@ -195,8 +233,15 @@ export declare class McpServersOverStore {
195
233
  private signInNoted;
196
234
  /** PUT: preview, then keep the server with the tools listed. A body with no credential keeps the sealed one, while the
197
235
  * auth type and the URL's origin stay the same. `made`: what made the server, when that is the Composio preset (its
198
- * source and toolkit, recorded as they are). */
199
- save(name: string, body: Record<string, unknown>, stop?: AbortSignal, checkedAgainst?: McpCredentialMark, made?: SourceRecord): Promise<{
236
+ * source and toolkit, recorded as they are), and `stands`, what it stands on at Composio (composio-made.ts), recorded
237
+ * for its delete. `dropped` is told what a save over a preset server leaves to do there, once the row is written: the
238
+ * MCP server the save before made, when the row names it no longer, and what else that save made that this one no
239
+ * longer stands on (all of it, for an ordinary save that moves the row off Composio, as a delete), which another saved
240
+ * server's record now owns or the caller removes. `guard`, a preset row's: the turn its write and cleanup take, once
241
+ * the listing is done (never across it), and the check of the triggers that use it, made in that turn before a write
242
+ * that leaves what they stand on (an ordinary save moving the row off Composio, a preset save as another user or auth
243
+ * config): refused, nothing written. */
244
+ save(name: string, body: Record<string, unknown>, stop?: AbortSignal, checkedAgainst?: McpCredentialMark, made?: SourceRecord, stands?: ComposioMade, dropped?: (left: ComposioDropped) => void, guard?: SaveGuard): Promise<{
200
245
  listed_at: string;
201
246
  updated_at: string;
202
247
  secret: SecretMeta;
@@ -294,6 +339,14 @@ export declare class McpServersOverStore {
294
339
  remove(name: string, checkedAgainst?: McpCredentialMark): Promise<{
295
340
  composio?: ComposioHandle;
296
341
  }>;
342
+ /** Whether `name` is a Composio preset server now (auth headers, source composio): a save of it takes the Composio turn,
343
+ * since one that moves it off Composio removes there what the preset made for it. */
344
+ composioPreset(name: string): Promise<boolean>;
345
+ /** Writes each record a cleanup passes a thing to (composio-made.ts `handover`), for its own row of `others`. */
346
+ private handOver;
347
+ /** The saved servers' records of what they stand on at Composio (composio-made.ts), each read for its own row: name,
348
+ * record and the row's created_at. */
349
+ private composioRecords;
297
350
  /** POST .../{name}/oauth/start: `{url, scopes?, client_id?, client_secret?, toolkit?}`; answers the URL the owner opens.
298
351
  * Its toolkit, as a save's, is written for the server the sign-in saves. */
299
352
  oauthStart(name: string, body: Record<string, unknown>): Promise<{