@parcha/agentrun-serve 0.1.0-beta.39 → 0.1.0-beta.41

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 (173) hide show
  1. package/CHANGELOG.md +114 -0
  2. package/README.md +129 -16
  3. package/dist/api-only.d.ts +3 -1
  4. package/dist/api-only.js +4 -2
  5. package/dist/api-token.d.ts +30 -0
  6. package/dist/api-token.js +89 -0
  7. package/dist/cli.js +19 -5
  8. package/dist/composio-made.d.ts +54 -0
  9. package/dist/composio-made.js +83 -0
  10. package/dist/composio-preset.d.ts +16 -8
  11. package/dist/composio-preset.js +106 -43
  12. package/dist/composio-triggers.d.ts +7 -2
  13. package/dist/composio-triggers.js +13 -7
  14. package/dist/computer-attach.d.ts +29 -11
  15. package/dist/computer-attach.js +141 -47
  16. package/dist/computer-keys.d.ts +4 -0
  17. package/dist/computer-keys.js +5 -0
  18. package/dist/computers.d.ts +11 -1
  19. package/dist/computers.js +21 -12
  20. package/dist/console/assets/index-C3gNPz58.css +1 -0
  21. package/dist/console/assets/index-COGhx_2Z.js +711 -0
  22. package/dist/console/index.html +2 -2
  23. package/dist/decisions.js +9 -2
  24. package/dist/email/account.d.ts +0 -1
  25. package/dist/email/account.js +3 -3
  26. package/dist/email/answer.d.ts +5 -0
  27. package/dist/email/answer.js +35 -0
  28. package/dist/email/mail.js +19 -26
  29. package/dist/email/names.d.ts +30 -0
  30. package/dist/email/names.js +34 -0
  31. package/dist/email/routes.d.ts +1 -0
  32. package/dist/email/routes.js +1 -1
  33. package/dist/email/tools.d.ts +11 -4
  34. package/dist/email/tools.js +91 -46
  35. package/dist/eval-feed.d.ts +26 -0
  36. package/dist/eval-feed.js +68 -0
  37. package/dist/eval-mailbox.d.ts +5 -2
  38. package/dist/eval-mailbox.js +14 -6
  39. package/dist/exa-keyless.d.ts +1 -1
  40. package/dist/exa-keyless.js +1 -1
  41. package/dist/feed/feed-faux.d.ts +62 -0
  42. package/dist/feed/feed-faux.js +123 -0
  43. package/dist/feed/fetch.d.ts +41 -0
  44. package/dist/feed/fetch.js +128 -0
  45. package/dist/feed/parse.d.ts +41 -0
  46. package/dist/feed/parse.js +300 -0
  47. package/dist/learn/check.d.ts +3 -1
  48. package/dist/learn/check.js +57 -2
  49. package/dist/learn/compile.d.ts +3 -2
  50. package/dist/learn/compile.js +7 -6
  51. package/dist/learn/promote.d.ts +25 -14
  52. package/dist/learn/promote.js +32 -14
  53. package/dist/learned-nodes.d.ts +21 -4
  54. package/dist/learned-nodes.js +21 -8
  55. package/dist/learned-workflow.d.ts +3 -3
  56. package/dist/learned-workflow.js +14 -5
  57. package/dist/learning-cost.d.ts +17 -8
  58. package/dist/learning-cost.js +12 -4
  59. package/dist/local-models.d.ts +7 -1
  60. package/dist/local-models.js +11 -5
  61. package/dist/mcp-oauth.d.ts +15 -1
  62. package/dist/mcp-oauth.js +39 -5
  63. package/dist/mcp-pin-first.d.ts +4 -2
  64. package/dist/mcp-pin-first.js +4 -3
  65. package/dist/mcp-servers-store.d.ts +58 -5
  66. package/dist/mcp-servers-store.js +136 -17
  67. package/dist/mcp.d.ts +2 -2
  68. package/dist/mcp.js +2 -2
  69. package/dist/observation/http.d.ts +4 -1
  70. package/dist/observation/http.js +5 -4
  71. package/dist/openapi.d.ts +1 -1
  72. package/dist/openapi.js +63 -27
  73. package/dist/port-models.d.ts +4 -1
  74. package/dist/port-models.js +1 -0
  75. package/dist/print.d.ts +6 -3
  76. package/dist/print.js +4 -2
  77. package/dist/refusal-words.d.ts +3 -0
  78. package/dist/refusal-words.js +3 -0
  79. package/dist/run-labels.d.ts +23 -0
  80. package/dist/run-labels.js +79 -0
  81. package/dist/run-launch.d.ts +2 -0
  82. package/dist/run-launch.js +2 -0
  83. package/dist/run-secrets.js +12 -4
  84. package/dist/run-view.d.ts +3 -4
  85. package/dist/run-view.js +26 -24
  86. package/dist/runner/adapter-loop.d.ts +6 -2
  87. package/dist/runner/adapter-loop.js +136 -22
  88. package/dist/runner/adapter-run-spec.d.ts +5 -0
  89. package/dist/runner/adapter-run-spec.js +75 -32
  90. package/dist/runner/beside.d.ts +6 -3
  91. package/dist/runner/beside.js +9 -7
  92. package/dist/runner/cli-run-spec.js +33 -26
  93. package/dist/runner/conformance/harness.js +69 -14
  94. package/dist/runner/conformance/subject.d.ts +4 -1
  95. package/dist/runner/journal-kinds.d.ts +22 -0
  96. package/dist/runner/journal-kinds.js +39 -0
  97. package/dist/runner/main.d.ts +1 -1
  98. package/dist/runner/main.js +2 -2
  99. package/dist/runner/mcp-claim.d.ts +3 -0
  100. package/dist/runner/mcp-claim.js +1 -1
  101. package/dist/runner/mcp-run.d.ts +4 -0
  102. package/dist/runner/mcp-run.js +5 -3
  103. package/dist/runner/model-route.d.ts +7 -3
  104. package/dist/runner/model-route.js +24 -9
  105. package/dist/runner/promotion.d.ts +16 -8
  106. package/dist/runner/promotion.js +178 -55
  107. package/dist/runner/workflow-first.d.ts +6 -5
  108. package/dist/runner/workflow-first.js +9 -7
  109. package/dist/runs-over-store.js +5 -2
  110. package/dist/sdk/runs.d.ts +7 -1
  111. package/dist/sdk/runs.js +19 -6
  112. package/dist/secret-cut.js +3 -1
  113. package/dist/secrets.js +3 -1
  114. package/dist/server.d.ts +27 -2
  115. package/dist/server.js +181 -56
  116. package/dist/store/dialect.d.ts +6 -0
  117. package/dist/store/dialect.js +2 -0
  118. package/dist/store/index.d.ts +1 -1
  119. package/dist/store/postgres/connection.d.ts +11 -5
  120. package/dist/store/postgres/connection.js +44 -17
  121. package/dist/store/postgres/dialect.js +6 -0
  122. package/dist/store/postgres/migrations/0015_run_labels.sql +5 -0
  123. package/dist/store/postgres/migrations/0016_minted_tokens.sql +21 -0
  124. package/dist/store/postgres/store.d.ts +7 -3
  125. package/dist/store/postgres/store.js +1 -0
  126. package/dist/store/schema.d.ts +9 -0
  127. package/dist/store/schema.js +26 -2
  128. package/dist/store/sqlite/connection.js +80 -8
  129. package/dist/store/sqlite/run-launch.d.ts +11 -0
  130. package/dist/store/sqlite/run-launch.js +8 -0
  131. package/dist/store/sqlite/run-patch.d.ts +2 -1
  132. package/dist/store/sqlite/run-patch.js +3 -2
  133. package/dist/store/sqlite/store.js +101 -26
  134. package/dist/store/sqlite/worker.d.ts +2 -0
  135. package/dist/store/sqlite/worker.js +13 -10
  136. package/dist/store/store.d.ts +53 -1
  137. package/dist/store-reads/journal.js +2 -1
  138. package/dist/store-reads/learning.d.ts +30 -13
  139. package/dist/store-reads/learning.js +130 -51
  140. package/dist/store-reads/runs.d.ts +4 -3
  141. package/dist/store-reads/runs.js +3 -2
  142. package/dist/store-view.js +4 -2
  143. package/dist/template-eval.d.ts +4 -0
  144. package/dist/template-eval.js +127 -50
  145. package/dist/templates.d.ts +24 -1
  146. package/dist/templates.js +129 -21
  147. package/dist/timeline/origin.d.ts +1 -1
  148. package/dist/timeline/origin.js +2 -2
  149. package/dist/tool-gate.d.ts +5 -3
  150. package/dist/tool-gate.js +5 -2
  151. package/dist/tools.d.ts +13 -0
  152. package/dist/tools.js +15 -10
  153. package/dist/trigger-adapter.d.ts +12 -36
  154. package/dist/trigger-adapters.js +2 -1
  155. package/dist/trigger-email.js +30 -77
  156. package/dist/trigger-feed.d.ts +12 -0
  157. package/dist/trigger-feed.js +371 -0
  158. package/dist/triggers.d.ts +27 -14
  159. package/dist/triggers.js +121 -80
  160. package/dist/webhooks.js +9 -5
  161. package/dist/workflow/decision-recovery.js +5 -2
  162. package/dist/workflow/decisions.d.ts +7 -0
  163. package/dist/workspace/computer-deps.d.ts +5 -1
  164. package/dist/workspace/computer-deps.js +2 -2
  165. package/dist/workspace/index.d.ts +1 -0
  166. package/dist/workspace/index.js +2 -0
  167. package/dist/workspace/resolve-computer.d.ts +32 -3
  168. package/dist/workspace/resolve-computer.js +47 -9
  169. package/launcher/agentrun-serve +6 -1
  170. package/package.json +10 -9
  171. package/templates/README.md +27 -2
  172. package/dist/console/assets/index-BNhZs-jp.css +0 -1
  173. package/dist/console/assets/index-BQv5aOGB.js +0 -700
@@ -70,8 +70,17 @@ export const markGradeRound = async (settings, agentId, grade, opened) => {
70
70
  await updateKept(settings, gradesKey(agentId), (items) => items.map((one) => (one.run === grade.run && one.at === grade.at && one.seq === grade.seq ? { ...one, ...mark } : one)));
71
71
  return { ...grade, ...mark };
72
72
  };
73
- /** The agent's promotion records, oldest first. */
74
- export const promotionsOf = async (settings, agentId) => itemsOf(await settings.get(promotionsKey(agentId)));
73
+ /** The agent's promotion records, oldest first. A beta.39 store may hold `decided: "superseded"` (a replay a newer draft
74
+ * cancelled; beta.40 writes `skipped` for an older draft instead): read as `skipped`, `skipped_by` the draft that
75
+ * superseded it, with a reason that says when. Only the read maps (readAs, also what a guarded write compares): the stored
76
+ * record is never rewritten. */
77
+ export const readAs = (one) => {
78
+ if (one.decided !== "superseded")
79
+ return one;
80
+ const { superseded_by: by, ...rest } = one;
81
+ return { ...rest, decided: "skipped", reason: "a newer draft arrived while it replayed (before beta.40)", ...(by ? { skipped_by: by } : {}) };
82
+ };
83
+ export const promotionsOf = async (settings, agentId) => itemsOf(await settings.get(promotionsKey(agentId))).map(readAs);
75
84
  /** The newest record of `workflow` at `digest`, or undefined. */
76
85
  export const promotionOf = (records, workflow, digest) => records.findLast((one) => one.workflow === workflow && one.digest === digest);
77
86
  /** The champion of `workflow`: the newest record of the digest promoted last (a digest's place is its latest win's,
@@ -109,21 +118,22 @@ function lastPromotedOf(records, workflow) {
109
118
  last = records[i].digest;
110
119
  return last;
111
120
  }
112
- /** The revisions of `workflow` other than `digest` whose newest record still says replaying, newest first: at most one
113
- * once each new revision supersedes the one replaying (runner/promotion.ts). */
114
- export function replayingOf(records, workflow, digest) {
121
+ /** The revisions of `workflow` other than `digest` whose newest record still says `decided` (replaying, else queued),
122
+ * newest first: at most one replaying (one replay at a time, the reservation's guarded write), and at most one queued
123
+ * once each newer one skips the one queued before it (runner/promotion.ts). */
124
+ export function replayingOf(records, workflow, digest, decided = "replaying") {
115
125
  const out = [];
116
126
  for (const one of [...records].reverse()) {
117
127
  if (one.workflow !== workflow || one.digest === digest || out.some((seen) => seen.digest === one.digest))
118
128
  continue;
119
- if (promotionOf(records, workflow, one.digest) === one && one.decided === "replaying")
129
+ if (promotionOf(records, workflow, one.digest) === one && one.decided === decided)
120
130
  out.push(one);
121
131
  }
122
132
  return out;
123
133
  }
124
134
  /** What each learned workflow with a record serves, by name: `digest`, its champion's (championOf; null: none serves,
125
- * the agent takes its runs), and `replaying`, the revision other than it whose replay is at work (null: none; a
126
- * superseded one's replay was cancelled, never at work). What the promotions list says beside the records
135
+ * the agent takes its runs), and `replaying`, the revision other than it whose replay is at work (null: none; a queued
136
+ * one is not at work yet). What the promotions list says beside the records
127
137
  * (GET /agents/{id}/learning/promotions). */
128
138
  export function servingOf(records) {
129
139
  const names = [...new Set(records.map((one) => one.workflow))].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
@@ -146,17 +156,20 @@ export function promotionsShown(records, shown) {
146
156
  }
147
157
  /** Keeps `record` as the newest of its workflow at its digest, when `still` holds of the one there now (none: undefined)
148
158
  * and of every record kept (`items`: a check across revisions, one challenger at a time, in the same guarded write): so
149
- * of two claims deciding at once only the first decision is kept, and only its claim acts on it (Recorded.won). */
150
- export async function recordPromotion(settings, agentId, record, still) {
159
+ * of two claims deciding at once only the first decision is kept, and only its claim acts on it (Recorded.won). `also`:
160
+ * records kept after it in the same write, all or none (a queue change and the skips it makes, runner/promotion.ts). */
161
+ export async function recordPromotion(settings, agentId, record, still, also = []) {
151
162
  let out = { record, won: true };
152
163
  await updateKept(settings, promotionsKey(agentId), (items) => {
153
- const now = promotionOf(items, record.workflow, record.digest);
154
- if (!still(now, items)) {
164
+ // `still` compares what a read shows (readAs); the write keeps the stored items as they are.
165
+ const read = items.map(readAs);
166
+ const now = promotionOf(read, record.workflow, record.digest);
167
+ if (!still(now, read)) {
155
168
  out = { record: now, won: false };
156
169
  return items;
157
170
  }
158
171
  out = { record, won: true };
159
- return trimPromotions([...items, record]);
172
+ return trimPromotions([...items, record, ...also]);
160
173
  });
161
174
  return out;
162
175
  }
@@ -166,7 +179,10 @@ export async function recordPromotion(settings, agentId, record, still) {
166
179
  * never reads as a newer promotion), and the digest promoted last, its latest win and its newest record (so a held last
167
180
  * revision is never trimmed into handing the champion back). The kept records are a run of the newest plus those wins,
168
181
  * and a win's own run reaches no further back than it: a record that ended an older run of the same digest is newer
169
- * than every record of that run, so a run is never joined to an older one by the trim. */
182
+ * than every record of that run, so a run is never joined to an older one by the trim. The queue's state is kept too,
183
+ * whatever its age: a replaying revision's newest record (what its settle, its runs' claims and the one-replay-at-a-time
184
+ * check read: dropped, a newer revision would start a second replay while its runs run, and its verdict would never
185
+ * land) and a queued one's (what replays next). Neither is a promote record, so championOf reads the same. */
170
186
  export function trimPromotions(items) {
171
187
  if (items.length <= PROMOTIONS_KEPT)
172
188
  return [...items];
@@ -174,6 +190,8 @@ export function trimPromotions(items) {
174
190
  const placeOf = (i) => wins.get(i);
175
191
  const keep = new Set();
176
192
  for (const workflow of new Set(items.map((one) => one.workflow))) {
193
+ for (const one of [...replayingOf(items, workflow, null), ...replayingOf(items, workflow, null, "queued")])
194
+ keep.add(items.lastIndexOf(one));
177
195
  const last = lastPromotedOf(items, workflow);
178
196
  if (last === undefined)
179
197
  continue;
@@ -1,7 +1,8 @@
1
1
  import type { Skipped } from "./learn/replay-calls.js";
2
- /** The journal entry a learned_workflow call keeps beside itself: `{ call, workflow, nodes, guards? }`, its call's id, the
3
- * workflow's name, each of its nodes that ran (LearnedNode, at most LEARNED_NODES_MAX) and every guard check it made
4
- * (GuardRow, never capped: a map over more items than the trace holds keeps each); on a replay run's call that a write
2
+ /** The journal entry a learned_workflow call keeps beside itself: `{ call, workflow, nodes, guards?, loops? }`, its call's
3
+ * id, the workflow's name, each of its nodes that ran (LearnedNode, at most LEARNED_NODES_MAX), every guard check it made
4
+ * (GuardRow) and every loop exit (LoopRow), these two never capped (a map over more items than the trace holds keeps
5
+ * each); on a replay run's call that a write
5
6
  * stopped (learn/replay-calls.ts: one the graded run's recording does not have), `replay_skipped: { tool, step }` too; and
6
7
  * `ended`, how the workflow ended (LearnedEnded), on a call that ended (a replay run's call always keeps its entry). */
7
8
  export declare const LEARNED_NODES = "agentrun.learned_nodes";
@@ -42,9 +43,19 @@ export type GuardRow = {
42
43
  readonly escalated: boolean;
43
44
  readonly workflow?: string;
44
45
  };
46
+ /** One loop's exit (the DSL's `loop.exited`): its label, how many passes its body ran and whether its `until` held (false:
47
+ * it reached maxIters). A compiled answer's quote re-pick (learn/check.ts) is a loop of 2 until its quote check passes:
48
+ * `iterations` 2 is a re-pick, `met` whether it found its quotes. Rows, uncapped, are a run's metrics' `loops`, each
49
+ * naming the workflow whose call ran it (`workflow`), as `guards` are. */
50
+ export type LoopRow = {
51
+ readonly node: string;
52
+ readonly iterations: number;
53
+ readonly met: boolean;
54
+ readonly workflow?: string;
55
+ };
45
56
  /** The LEARNED_NODES entry that counts for each learned_workflow call in `entries`, by the call's id, as its index in
46
57
  * `entries`. A call run again (after a park or a crash: it nests calls) keeps an entry each time; the one that counts is
47
- * 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
58
+ * 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
48
59
  * any node ran (a replay run keeps that entry: `nodes: []`, ended `failed`) leaves the attempt before it standing; a call
49
60
  * none of whose entries ran a node counts its last. What the run's guard rows (guardsOf) and its timeline rows'
50
61
  * `learned_nodes` (store-reads/journal.ts) both read, so the two never pick apart. */
@@ -59,6 +70,12 @@ export declare function guardsOf(entries: readonly {
59
70
  readonly kind: string;
60
71
  readonly data?: unknown;
61
72
  }[]): GuardRow[];
73
+ /** A run's loop rows, from its root entries: every loop exit of every learned_workflow call (LEARNED_NODES `loops`), read
74
+ * as guardsOf reads `guards`. What its metrics keep as `loops`. */
75
+ export declare function loopsOf(entries: readonly {
76
+ readonly kind: string;
77
+ readonly data?: unknown;
78
+ }[]): LoopRow[];
62
79
  /** How the newest learned_workflow call of `workflow` in `entries` (its root's) ended (LEARNED_NODES `ended`), or undefined
63
80
  * when no entry says. */
64
81
  export declare function endedIn(entries: readonly {
@@ -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)
@@ -61,16 +61,24 @@ export type CostReplay = {
61
61
  agent_pct: number;
62
62
  cleared: boolean;
63
63
  };
64
+ /** The paths a learned workflow served a run on: it ran first and answered alone (`workflow`) or handed back
65
+ * (`handed_back`). A `replay` checks a new revision on a graded input and serves no one; an `agent` run is by hand. */
66
+ export declare const SERVED_PATHS: readonly RunPath[];
67
+ /** Why the after side has a figure or not: `priced`, it has; `no_served_runs`, no learned workflow has taken over (a
68
+ * replay is no served run); `cost_unknown`, runs were served but none's all-in cost is known exactly. */
69
+ export declare const AFTER_STATES: readonly ["priced", "no_served_runs", "cost_unknown"];
70
+ export type AfterState = (typeof AFTER_STATES)[number];
64
71
  /** What the series shows: `takeover`, its first `workflow` run, null before one; `before`, the mean of the job's own $
65
72
  * (learning left out) over its `agent` runs before the takeover (every one when there is none yet), whose cost is known
66
- * exactly; `after`, the mean all-in $ (learning included) of every run from the takeover on whose total is known exactly;
67
- * and `times_cheaper`, before over after to a tenth, once `after` counts CHEAPER_AFTER_RUNS runs or more and every run
68
- * either side reads is known exactly, else null. The before side leaves learning out and the after side keeps it in, so
69
- * the figure never flatters learning. `withheld`: after a takeover, how many runs either side reads have an unknown cost
70
- * and how many one known only as at most (`cost_upper_bound`); while any does there is no ratio, null when none does.
71
- * `hand_backs`: of the runs a learned workflow ran first on from the takeover on (`workflow` or `handed_back`), how many
72
- * handed back; null before a takeover. `replay`: the serving promotion's, as given. Every one is over every run, never
73
- * only the latest a read lists. */
73
+ * exactly; `after`, the mean all-in $ (learning included) of the runs a learned workflow served from the takeover on
74
+ * (SERVED_PATHS: never a replay, which checks a revision and serves no one, nor a run by hand) whose total is known
75
+ * exactly, and `after_state` why it is null when it is; and `times_cheaper`, before over after to a tenth, once `after`
76
+ * counts CHEAPER_AFTER_RUNS runs or more and every run either side reads is known exactly, else null. The before side
77
+ * leaves learning out and the after side keeps it in, so the figure never flatters learning. `withheld`: after a
78
+ * takeover, how many runs either side reads have an unknown cost and how many one known only as at most
79
+ * (`cost_upper_bound`); while any does there is no ratio, null when none does. `hand_backs`: of the served runs from
80
+ * the takeover on, how many handed back; null before a takeover. `replay`: the serving promotion's, as given. Every one
81
+ * is over every run, never only the latest a read lists. */
74
82
  export type CostSummary = {
75
83
  takeover: {
76
84
  n: number;
@@ -84,6 +92,7 @@ export type CostSummary = {
84
92
  runs: number;
85
93
  mean_usd: number;
86
94
  } | null;
95
+ after_state: AfterState;
87
96
  times_cheaper: number | null;
88
97
  hand_backs: {
89
98
  ran: number;
@@ -41,10 +41,18 @@ export const COST_WINDOW = 10;
41
41
  /** The latest runs the route answers by default, and at most. */
42
42
  export const COST_RUNS_DEFAULT = 1000;
43
43
  export const COST_RUNS_MAX = 10_000;
44
+ /** The paths a learned workflow served a run on: it ran first and answered alone (`workflow`) or handed back
45
+ * (`handed_back`). A `replay` checks a new revision on a graded input and serves no one; an `agent` run is by hand. */
46
+ export const SERVED_PATHS = ["workflow", "handed_back"];
47
+ /** Why the after side has a figure or not: `priced`, it has; `no_served_runs`, no learned workflow has taken over (a
48
+ * replay is no served run); `cost_unknown`, runs were served but none's all-in cost is known exactly. */
49
+ export const AFTER_STATES = ["priced", "no_served_runs", "cost_unknown"];
44
50
  export function costSummary(runs, replay = null) {
45
51
  const first = runs.findIndex((run) => run.path === "workflow");
46
52
  const beforeSide = (first < 0 ? runs : runs.slice(0, first)).filter((run) => run.path === "agent").map((run) => ({ value: run.cost_usd, bound: run.cost_upper_bound }));
47
- const afterSide = first < 0 ? [] : runs.slice(first).map((run) => ({ value: run.total_usd, bound: run.cost_upper_bound }));
53
+ // Served runs alone: a replay (a check of a new revision, at workflow cost) and a run by hand are never the after side.
54
+ const served = first < 0 ? [] : runs.slice(first).filter((run) => SERVED_PATHS.includes(run.path));
55
+ const afterSide = served.map((run) => ({ value: run.total_usd, bound: run.cost_upper_bound }));
48
56
  const mean = (side) => {
49
57
  const values = side.flatMap(({ value, bound }) => (value === null || bound ? [] : [value]));
50
58
  return values.length ? { runs: values.length, mean_usd: usd(values.reduce((a, b) => a + b, 0) / values.length) } : null;
@@ -57,9 +65,9 @@ export function costSummary(runs, replay = null) {
57
65
  const atMost = read.filter(({ bound }) => bound).length;
58
66
  const withheld = first >= 0 && unknown + atMost > 0 ? { unknown, at_most: atMost } : null;
59
67
  const times = !withheld && before && after && after.runs >= CHEAPER_AFTER_RUNS && after.mean_usd > 0 ? Math.round((before.mean_usd / after.mean_usd) * 10) / 10 : null;
60
- const ranFirst = first < 0 ? [] : runs.slice(first).filter((run) => run.path === "workflow" || run.path === "handed_back");
61
- const handBacks = first < 0 ? null : { ran: ranFirst.length, back: ranFirst.filter((run) => run.path === "handed_back").length };
62
- return { takeover: first < 0 ? null : { n: runs[first].n, run_id: runs[first].run_id }, before, after, times_cheaper: times, hand_backs: handBacks, withheld, replay };
68
+ const handBacks = first < 0 ? null : { ran: served.length, back: served.filter((run) => run.path === "handed_back").length };
69
+ const afterState = after ? "priced" : first < 0 ? "no_served_runs" : "cost_unknown";
70
+ return { takeover: first < 0 ? null : { n: runs[first].n, run_id: runs[first].run_id }, before, after, after_state: afterState, times_cheaper: times, hand_backs: handBacks, withheld, replay };
63
71
  }
64
72
  /** The series as CSV (RFC 4180, a header line, `\r\n` line ends): one row a run, an unknown figure empty. A text cell that
65
73
  * a spreadsheet would read as a formula (one starting with =, +, -, @, a tab or a carriage return) starts with a `'`, so
@@ -30,7 +30,12 @@ export declare const PRICE_OVERRIDES: readonly {
30
30
  * id, name, input, context window and output ceiling, at $0, taking its tools natively (the `like` entry's `toolsAs` is
31
31
  * not copied). Context and output ceiling are OpenRouter's (GET https://openrouter.ai/api/v1/models, read 2026-11-15:
32
32
  * context_length and top_provider.max_completion_tokens; pricing "0" prompt and completion). Each one answered a request
33
- * that defined a tool with a call to that tool, through OpenRouter, on 2026-11-15, billed $0. */
33
+ * that defined a tool with a call to that tool, through OpenRouter, on 2026-11-15, billed $0. `mustReason` is that list's
34
+ * `reasoning.mandatory` (read 2026-11-16): a model that must reason has thinking off mapped to no effort (thinkingLevelMap
35
+ * `off: null`, as pi-ai's catalog maps Claude Sonnet 5.5's), so pi-ai never sends it `reasoning: {effort: "none"}`, which
36
+ * OpenRouter refuses with "Reasoning is mandatory for this endpoint and cannot be disabled", and the model reasons at
37
+ * its default. A model that lists `reasoning` among its supported parameters need not reason (Ling 3.2 Flash): only
38
+ * `mandatory` says so. */
34
39
  export declare const ADDED_MODELS: readonly {
35
40
  readonly provider: string;
36
41
  readonly id: string;
@@ -39,6 +44,7 @@ export declare const ADDED_MODELS: readonly {
39
44
  readonly input: readonly ("text" | "image")[];
40
45
  readonly contextWindow: number;
41
46
  readonly maxTokens: number;
47
+ readonly mustReason: boolean;
42
48
  }[];
43
49
  /** Whether `provider`/`id` is one of OpenRouter's routers, each of which picks a model per request (the kernel cap's
44
50
  * ROUTERS, the one list). OpenRouter lists the price of `auto`, `openrouter/auto*`, `openrouter/fusion`,
@@ -29,21 +29,27 @@ const ZERO = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
29
29
  * id, name, input, context window and output ceiling, at $0, taking its tools natively (the `like` entry's `toolsAs` is
30
30
  * not copied). Context and output ceiling are OpenRouter's (GET https://openrouter.ai/api/v1/models, read 2026-11-15:
31
31
  * context_length and top_provider.max_completion_tokens; pricing "0" prompt and completion). Each one answered a request
32
- * that defined a tool with a call to that tool, through OpenRouter, on 2026-11-15, billed $0. */
32
+ * that defined a tool with a call to that tool, through OpenRouter, on 2026-11-15, billed $0. `mustReason` is that list's
33
+ * `reasoning.mandatory` (read 2026-11-16): a model that must reason has thinking off mapped to no effort (thinkingLevelMap
34
+ * `off: null`, as pi-ai's catalog maps Claude Sonnet 5.5's), so pi-ai never sends it `reasoning: {effort: "none"}`, which
35
+ * OpenRouter refuses with "Reasoning is mandatory for this endpoint and cannot be disabled", and the model reasons at
36
+ * its default. A model that lists `reasoning` among its supported parameters need not reason (Ling 3.2 Flash): only
37
+ * `mandatory` says so. */
33
38
  export const ADDED_MODELS = [
34
- { provider: "openrouter", id: "baidu/ernie-5.5-flash-preview:free", like: "inclusionai/ling-3.1-flash", name: "Baidu: ERNIE 5.5 Flash Preview (free)", input: ["text"], contextWindow: 1_024_000, maxTokens: 921_600 },
35
- { provider: "openrouter", id: "inclusionai/ling-3.2-flash:free", like: "inclusionai/ling-3.1-flash", name: "inclusionAI: Ling 3.2 Flash (free)", input: ["text"], contextWindow: 1_048_576, maxTokens: 262_144 },
39
+ { provider: "openrouter", id: "baidu/ernie-5.5-flash-preview:free", like: "inclusionai/ling-3.1-flash", name: "Baidu: ERNIE 5.5 Flash Preview (free)", input: ["text"], contextWindow: 1_024_000, maxTokens: 921_600, mustReason: true },
40
+ { provider: "openrouter", id: "inclusionai/ling-3.2-flash:free", like: "inclusionai/ling-3.1-flash", name: "inclusionAI: Ling 3.2 Flash (free)", input: ["text"], contextWindow: 1_048_576, maxTokens: 262_144, mustReason: false },
36
41
  ];
37
42
  /** `list` with ADDED_MODELS appended, each built on its `like` entry in `list` (one whose `like` the list lacks is left
38
43
  * out) and never twice: once pi-ai lists an id itself, its own entry stands. */
39
44
  const added = (list, adds) => [
40
45
  ...list,
41
- ...adds.flatMap(({ id, like, name, input, contextWindow, maxTokens }) => {
46
+ ...adds.flatMap(({ id, like, name, input, contextWindow, maxTokens, mustReason }) => {
42
47
  const base = list.find((model) => model.id === like);
43
48
  if (!base || list.some((model) => model.id === id))
44
49
  return [];
45
50
  const { toolsAs: _base, ...rest } = base;
46
- return [{ ...rest, id, name, input: [...input], contextWindow, maxTokens, cost: { ...ZERO } }];
51
+ const levels = rest.thinkingLevelMap;
52
+ return [{ ...rest, id, name, input: [...input], contextWindow, maxTokens, cost: { ...ZERO }, ...(mustReason ? { reasoning: true, thinkingLevelMap: { ...levels, off: null } } : {}) }];
47
53
  }),
48
54
  ];
49
55
  /** Whether `provider`/`id` is one of OpenRouter's routers, each of which picks a model per request (the kernel cap's
@@ -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
@@ -142,9 +153,12 @@ export declare class McpSignIns {
142
153
  /** Whether this server is a local install (McpServersOverStore.attach): only then may a loopback MCP server's
143
154
  * authorization server be on loopback too. */
144
155
  loopback: boolean;
156
+ /** A runner's registry (mcp-pin-first.ts registryListing), which listens nowhere: the own addresses of the
157
+ * local-install server beside it (Serve.own), held to as this server's own are. Set by McpServersOverStore.attach. */
158
+ beside: readonly string[];
145
159
  /** This server's own local addresses, whose ports a loopback authorization server may never name: where it listens,
146
160
  * 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). */
161
+ * listener, reaches this server); on a runner, the server's beside it. */
148
162
  get own(): string[];
149
163
  /** CIMD only from a public https address: an authorization server must be able to fetch the document. */
150
164
  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
@@ -301,12 +332,15 @@ export class McpSignIns {
301
332
  /** Whether this server is a local install (McpServersOverStore.attach): only then may a loopback MCP server's
302
333
  * authorization server be on loopback too. */
303
334
  loopback = false;
335
+ /** A runner's registry (mcp-pin-first.ts registryListing), which listens nowhere: the own addresses of the
336
+ * local-install server beside it (Serve.own), held to as this server's own are. Set by McpServersOverStore.attach. */
337
+ beside = [];
304
338
  /** This server's own local addresses, whose ports a loopback authorization server may never name: where it listens,
305
339
  * 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). */
340
+ * listener, reaches this server); on a runner, the server's beside it. */
307
341
  get own() {
308
342
  const base = URL.parse(this.base);
309
- return [this.listening, ...(base && LOOPBACK.test(base.hostname) ? [this.base] : [])].filter(Boolean);
343
+ return [this.listening, ...(base && LOOPBACK.test(base.hostname) ? [this.base] : []), ...this.beside].filter(Boolean);
310
344
  }
311
345
  /** CIMD only from a public https address: an authorization server must be able to fetch the document. */
312
346
  get metadataUrl() {
@@ -442,7 +476,7 @@ export class McpSignIns {
442
476
  saveClientInformation: (client) => void (entry.client = client),
443
477
  tokens: () => undefined,
444
478
  saveTokens: (tokens) => hooks.saved?.(tokens),
445
- redirectToAuthorization: (url) => hooks.redirect?.(url),
479
+ redirectToAuthorization: (url) => hooks.redirect?.(askingOffline(url)),
446
480
  saveCodeVerifier: (verifier) => void (entry.verifier = verifier),
447
481
  codeVerifier: () => entry.verifier ?? "",
448
482
  // 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)