@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
package/dist/openapi.js CHANGED
@@ -8,7 +8,8 @@ import { NATIVE_BINDING, NATIVE_RUN, NATIVE_PATHS } from "./native/schema.js";
8
8
  // `x-agentrun-serve` (true, or the addition that made it, as `stats/1`), listed in `info.x-agentrun-serve`.
9
9
  import { readFileSync } from "node:fs";
10
10
  import { CALL_RESULT_CHARS, CAPS, TRIGGER_SOURCES } from "./timeline/index.js";
11
- import { EMAIL_SCOPES, SCOPED_TOOLS } from "./email/names.js";
11
+ import { EMAIL_SCOPES, PASSWORD_MAX, SCOPED_TOOLS, SEND_CAP } from "./email/names.js";
12
+ import { PAYLOAD_KEPT_BYTES } from "./trigger-adapter.js";
12
13
  import { TRIGGER_ADAPTERS } from "./trigger-adapters.js";
13
14
  import { NOTE_ORIGINS, NOTE_STATUSES, NOTE_TYPES } from "./learn/index.js";
14
15
  import { ERROR_STATUS } from "./errors.js";
@@ -19,7 +20,7 @@ import { LAUNCH_LOST, SETUP_LOST } from "./files.js";
19
20
  import { HARNESSES } from "./harness.js";
20
21
  import { LEARNING_LABEL, LEARNING_MODES, LEARNING_REASONS, LEARNING_STATES, RUN_LEARNING_USE } from "./learning.js";
21
22
  import { BATCH_CELL_MAX, BATCH_ROWS_MAX } from "./learning-batch.js";
22
- import { CHEAPER_AFTER_RUNS, COST_CSV_COLUMNS, COST_WINDOW, COST_RUNS_DEFAULT, COST_RUNS_MAX, RUN_PATHS } from "./learning-cost.js";
23
+ import { AFTER_STATES, CHEAPER_AFTER_RUNS, COST_CSV_COLUMNS, COST_WINDOW, COST_RUNS_DEFAULT, COST_RUNS_MAX, RUN_PATHS } from "./learning-cost.js";
23
24
  import { FEEDBACK_ROUNDS, FEEDBACK_STATUSES } from "./runner/feedback-round.js";
24
25
  import { EVAL_JOBS_MAX, EVAL_TEXT_MAX, EVALS_KEPT } from "./learning-evals.js";
25
26
  import { LOOP_COMPILES_MAX, LOOP_POINTS_MAX } from "./store-reads/loop.js";
@@ -40,7 +41,7 @@ import { MCP_SETTINGS_PAGE } from "./mcp-oauth.js";
40
41
  import { ATTEMPTS_KEPT, MESSAGE_TYPES, WEBHOOK_EVENTS } from "./webhooks.js";
41
42
  import { DEFAULT_SCHEME, SCHEME_NAMES, SIGNATURE_SCHEMES } from "./trigger-signatures.js";
42
43
  import { HOOK_BODY_MS } from "./push-handler.js";
43
- import { CATCHUP_WINDOW_S, DUE_KEPT, MAX_ACTIVE_RUNS, SEEN_KEPT, FAILURES_TO_PAUSE, FIRING_STATUSES, PAYLOAD_KEPT_BYTES, HISTORY_KEPT, MAX_EVERY_S, SOURCE_KINDS, TARGET_KINDS } from "./triggers.js";
44
+ import { CATCHUP_WINDOW_S, DUE_KEPT, MAX_ACTIVE_RUNS, SEEN_KEPT, FAILURES_TO_PAUSE, FIRING_STATUSES, HISTORY_KEPT, MAX_EVERY_S, SOURCE_KINDS, TARGET_KINDS } from "./triggers.js";
44
45
  import { DEFINITION_FIELDS, EXTERNAL_NAME, MODEL_REF } from "./validate.js";
45
46
  import { CATEGORIES, COMPUTER_ENTRIES, GRADER_TYPES, MODEL_TIERS } from "./templates.js";
46
47
  import { MCP_SOURCES } from "./mcp-sources.js";
@@ -50,13 +51,29 @@ import { APPROVAL_ROW, ARGS_PREVIEW_BYTES, MAX_PIN_ARGS, MAX_PIN_CHOICES, PERMIS
50
51
  import { BROWSER_VENDOR_IDS, DECISION_PROVIDER_KEYS, KIND_KEYS, MAX_PIN_TEXT, permissionsOf, PICKABLE, PROVIDERS } from "./tool-plane.js";
51
52
  import { tableTools } from "./tool-list.js";
52
53
  import { SECRET_META_SCHEMA } from "./secret-writes.js";
54
+ import { LABEL_KEY, MAX_LABEL_VALUE, MAX_LABELS } from "./run-labels.js";
53
55
  import { BASH_POLICIES } from "./bash-read-only.js";
54
56
  // The modules that own the computer and Archil key writes: loading the document loads their secret-write predicates
55
57
  // (secret-writes.ts registerSecretWrite), so every operation the document marks has its predicate wherever it is read.
56
58
  import "./computers.js";
57
59
  import { ARCHIL_KEY_NAMES } from "./archil-routes.js";
58
60
  import { ATTACH_HEARTBEAT_MS, ATTACH_IDLE_MS, ATTACH_SUBPROTOCOL, MAX_LINE_BYTES, PAIRING_CODE_PATTERN, PAIRING_CODE_TTL_MS, PROTOCOL_VERSION } from "@parcha/agentrun-computer";
59
- import { PAIR_TRIES_PER_MINUTE, PAIRED_NAME_MAX } from "./computer-attach.js";
61
+ import { DAEMON_FETCHES_PER_MINUTE, PAIR_TRIES_PER_MINUTE, PAIRED_NAME_MAX } from "./computer-attach.js";
62
+ /** runlabels/1: a run's labels, given at its start and served on every read of it (run-labels.ts). */
63
+ const RUN_LABELS = {
64
+ type: "object",
65
+ maxProperties: MAX_LABELS,
66
+ propertyNames: { pattern: LABEL_KEY.source },
67
+ additionalProperties: { type: "string", minLength: 1, maxLength: MAX_LABEL_VALUE },
68
+ "x-agentrun-serve": "runlabels/1",
69
+ };
70
+ /** runlabels/1: GET /runs' and GET /agents/{agent_id}/runs' filter on a run's labels. */
71
+ const LABEL_PARAMETER = {
72
+ name: "label", in: "query", required: false,
73
+ description: "Only runs holding this label: `<key>:<value>`, split at the first `:` (a key holds none). Once per request; a second `label`, or one that does not read as a label, is 400.",
74
+ schema: { type: "string" },
75
+ "x-agentrun-serve": "runlabels/1",
76
+ };
60
77
  /** Why each capability this server turns off answers 501, by the route's capability. */
61
78
  export const UNSUPPORTED = {
62
79
  quotes: "This server has no billing, so it gives no quotes.",
@@ -208,7 +225,7 @@ const EMAIL_ACCOUNT_BODY = {
208
225
  preset: { enum: ["gmail", "fastmail", "icloud", "other", "outlook"], default: "other", description: "gmail, fastmail and icloud fill imap and smtp; other takes both. outlook is refused in words: Outlook needs Microsoft sign-in, which this server doesn't do yet." },
209
226
  address: { type: "string", minLength: 1, maxLength: 320, description: "The address it sends as." },
210
227
  user: { type: "string", minLength: 1, maxLength: 320, description: "Who signs in. Default: the address." },
211
- password: { type: "string", minLength: 1, maxLength: 320, "x-agentrun-secret": true, description: "The account's app password (Gmail, iCloud and Fastmail each make one for an app): sealed, never answered or shown again. A test of the saved account may leave it out." },
228
+ password: { type: "string", minLength: 1, maxLength: PASSWORD_MAX, "x-agentrun-secret": true, description: "The account's app password (Gmail, iCloud and Fastmail each make one for an app): sealed, never answered or shown again. A test of the saved account may leave it out." },
212
229
  imap: MAIL_ENDPOINT,
213
230
  smtp: MAIL_ENDPOINT,
214
231
  },
@@ -971,7 +988,7 @@ const TRIGGER_FIELDS = closed({
971
988
  catchup_window_s: { type: "integer", minimum: 0, maximum: MAX_EVERY_S, description: `How late a missed time may still fire, once: of the times that came while the server was down (or its timer was late), the latest fires if it is this recent, under its own key, and the rest are one \`missed\` firing. 0: a missed time never fires. Default ${CATCHUP_WINDOW_S}.` },
972
989
  max_active_runs: { type: ["integer", "null"], minimum: 1, maximum: MAX_ACTIVE_RUNS, description: `For a \`start_run\` trigger of a pushed source (a webhook, with or without \`accept\`): each event starts its own run, never skipped behind the last, and this is the most of its runs active at once. A firing past it waits due and is tried again; past 20 due an event is 429 \`rate_limited\`. Null: a trigger with \`accept\` takes every run this server has room for, and one without keeps the overlap skip. A schedule or a \`message_run\` target is 422 with it set.` },
973
990
  failures_in_a_row: { type: "integer", minimum: 0, description: `Failed firings since the last that started a run; at ${FAILURES_TO_PAUSE} the trigger turns itself off (\`disabled\`). Turned on again, it counts from 0.` },
974
- disabled: { oneOf: [closed({ at: DATE_TIME, reason: { const: "auto_paused" } }), closed({ at: DATE_TIME, reason: { const: "source_unreadable" }, detail: { type: "string", description: "Why the source no longer reads." } }), closed({ at: DATE_TIME, reason: { const: "agent_archived" }, detail: { type: "string", description: "The agent it runs as, archived." } }), closed({ at: DATE_TIME, reason: { const: "connection_lost" }, detail: { type: "string", description: "Which connection went (GitHub disconnected here, or the App's installation deleted or suspended on GitHub)." } }), closed({ at: DATE_TIME, reason: { const: "sign_in_refused" }, detail: { type: "string", description: "What to fix: the account in Settings → Email." } }), { type: "null" }], description: `Why it is off, when the server turned it off: \`agent_archived\`, the agent it runs as was archived (turning it on is 409 agent_archived until the agent is unarchived); \`auto_paused\`, ${FAILURES_TO_PAUSE} failed firings in a row; \`connection_lost\`, the connection it needs went (GitHub disconnected here, or the App's installation deleted or suspended on GitHub); \`sign_in_refused\`, an email trigger's mail server refused the sign-in 3 times in a row (fix the account in Settings → Email, then turn it on); \`source_unreadable\`, its cron line or zone no longer reads here (a newer cron library or time zone data refuses it) or its every_s is out of range (a hand edit of its row), found at a start or when it came due, and only this trigger is turned off. Null once it is on again, which for \`source_unreadable\` takes a new source.` },
991
+ disabled: { oneOf: [closed({ at: DATE_TIME, reason: { const: "auto_paused" } }), closed({ at: DATE_TIME, reason: { const: "source_unreadable" }, detail: { type: "string", description: "Why the source no longer reads." } }), closed({ at: DATE_TIME, reason: { const: "agent_archived" }, detail: { type: "string", description: "The agent it runs as, archived." } }), closed({ at: DATE_TIME, reason: { const: "connection_lost" }, detail: { type: "string", description: "Which connection went (GitHub disconnected here, or the App's installation deleted or suspended on GitHub)." } }), closed({ at: DATE_TIME, reason: { const: "sign_in_refused" }, detail: { type: "string", description: "What to fix: the account in Settings → Email." } }), { type: "null" }], description: `Why it is off, when the server turned it off: \`agent_archived\`, the agent it runs as was archived (turning it on is 409 agent_archived until the agent is unarchived); \`auto_paused\`, ${FAILURES_TO_PAUSE} failed firings in a row; \`connection_lost\`, the connection it needs went (GitHub disconnected here, or the App's installation deleted or suspended on GitHub); \`sign_in_refused\`, an email trigger's mail server refused the sign-in 3 times in a row (fix the account in Settings → Email, then turn it on); \`source_unreadable\`, its cron line or zone no longer reads here (a newer cron library or time zone data refuses it) or its every_s is out of range (a hand edit of its row), found at a start or when it came due, and only this trigger is turned off, or every feed a feed trigger reads has stopped (a 410, or a 404 three checks running, each), which turning it on again reads from the start (edit its urls first). Null once it is on again, which for \`source_unreadable\` takes a new source.` },
975
992
  next_at: { type: ["string", "null"], format: "date-time", description: "When it fires next; null while it is off." },
976
993
  last_run_id: { type: ["string", "null"], description: "The run its last firing that started one started; while that run is active (working, or waiting on a person), each firing is skipped, unless its firings each start their own run (a webhook with `accept`, or a pushed trigger with `max_active_runs`). Null until one starts." },
977
994
  created_at: DATE_TIME,
@@ -979,7 +996,7 @@ const TRIGGER_FIELDS = closed({
979
996
  last_firing: { oneOf: [TRIGGER_FIRING, { type: "null" }] },
980
997
  }, "A trigger. A firing while its last run is active (working, or waiting on a person) is skipped, and recorded as a skipped firing with why: never queued, since a firing queued behind a run parked on a person would wait as long as the person does. A webhook trigger with `accept` is the exception: each event it takes starts its own run.");
981
998
  /** A trigger's view: its fields, all there, and `hook_url`, a pushed source's alone. */
982
- const TRIGGER = { ...TRIGGER_FIELDS, properties: { ...TRIGGER_FIELDS.properties, last_check: { oneOf: [closed({ at: DATE_TIME, ok: { type: "boolean" }, message: { type: "string" } }), { type: "null" }], description: "A polled source's (an email's) last check of its mailbox: when, whether it read, and in words (\"Read INBOX: 2 messages new.\", or why not: a server that couldn't be reached is said here and tried at the next time). Null before its first; absent for any other source.", "x-agentrun-serve": "email/1" }, hook_url: { type: "string", description: "Where its sender posts, for a pushed source alone (absent for a schedule): a webhook's own hook, `/v2/hooks/{id}`, at this server's public URL (AGENTRUN_PUBLIC_URL) when it has one, else the path." } } };
999
+ const TRIGGER = { ...TRIGGER_FIELDS, properties: { ...TRIGGER_FIELDS.properties, last_check: { oneOf: [closed({ at: DATE_TIME, ok: { type: "boolean" }, message: { type: "string" } }), { type: "null" }], description: "A polled source's (an email's or a feed's) last check of its mailbox or its feeds: when, whether it read, and in words (\"Read INBOX: 2 messages new.\", \"Read 2 feeds: 1 new.\", or why not: a server that couldn't be reached is said here and tried at the next time). Null before its first; absent for any other source.", "x-agentrun-serve": "email/1" }, hook_url: { type: "string", description: "Where its sender posts, for a pushed source alone (absent for a schedule): a webhook's own hook, `/v2/hooks/{id}`, at this server's public URL (AGENTRUN_PUBLIC_URL) when it has one, else the path." } } };
983
1000
  const TRIGGER_WRITE = {
984
1001
  name: { type: "string", minLength: 1, maxLength: 200, description: "Default the trigger's id." },
985
1002
  enabled: { type: "boolean", default: true, description: "Off, it fires nothing; on again, it goes on from now: the time it was off is skipped, never caught up." },
@@ -1231,15 +1248,16 @@ const LEARNING_COST = closed({
1231
1248
  workflows: { type: "array", items: closed({
1232
1249
  workflow: { type: "string", description: "The learned workflow, by name." },
1233
1250
  digest: { type: "string", description: "The version of it its newest run served first ran: the first 16 hex characters of its workflow.json's sha256. A new version starts its count from zero." },
1234
- state: { enum: ["serving", "needs_revision"], description: `\`serving\`: it runs first on every run it fits. \`needs_revision\`: over its last ${COST_WINDOW} runs served at this version, its mean all-in cost (\`served\`) is at or over the agent's cost by hand (\`by_hand\`), so it no longer runs first; each run it would have served asks the agent for a new version, which runs first again.` },
1235
- served: COST_MEAN(`The mean all-in cost (\`total_usd\`: the run's own cost, the workflow's nodes and, after a handback, the agent's work, with every learning round booked for it) of its newest ${COST_WINDOW} runs served first at this version whose all-in cost is known; null when none is.`),
1251
+ state: { enum: ["serving", "needs_revision"], description: `\`serving\`: it runs first on every run it fits. \`needs_revision\`: over its newest ${COST_WINDOW} priced runs served at this version, its mean all-in cost (\`served\`) is at or over the agent's cost by hand (\`by_hand\`), so it no longer runs first; each run it would have served asks the agent for a new version, which runs first again.` },
1252
+ served: COST_MEAN(`The mean all-in cost (\`total_usd\`: the run's own cost, the workflow's nodes and, after a handback, the agent's work, with every learning round booked for it) of its newest ${COST_WINDOW} runs served first at this version whose all-in cost is known (a window, never how many runs it served: \`runs\` stops at ${COST_WINDOW}); null when none is.`),
1236
1253
  by_hand: COST_MEAN("The agent's cost by hand: the mean all-in cost (`total_usd`) of its runs on the `agent` path whose all-in cost is known or, with none, of its runs before the workflow first ran; null when there are none: the workflow then keeps serving."),
1237
1254
  unknown_cost_runs: { ...COUNT, description: "How many runs `served` and `by_hand` would have read have no known all-in cost: left out of their means, never read as 0." },
1238
1255
  }), description: "Each learned workflow that has run first on one of these runs, at its newest version, and where it stands against the money rule: it runs first while its cost a run stays under the agent's by hand. It does not catch a workflow that answers wrong with confidence." },
1239
1256
  summary: closed({
1240
1257
  takeover: { oneOf: [closed({ n: { type: "integer", minimum: 1 }, run_id: { type: "string" } }), { type: "null" }], description: "The first run a learned workflow finished alone (`path` `workflow`); null before one." },
1241
1258
  before: COST_MEAN("The mean of the job's own cost (`cost_usd`, learning left out) over the `agent` runs before the takeover (all of them when there is none yet) whose cost is known exactly (never `cost_upper_bound`); null when there is none."),
1242
- after: COST_MEAN("The mean all-in cost (`total_usd`, learning included) of every run from the takeover on whose total is known exactly (never `cost_upper_bound`); null before a takeover."),
1259
+ after: COST_MEAN("The mean all-in cost (`total_usd`, learning included) of the runs a learned workflow served from the takeover on (`path` `workflow` or `handed_back`; never a `replay`, which checks a revision and serves no one, nor an `agent` run) whose total is known exactly (never `cost_upper_bound`); null when there is none, and `after_state` says why."),
1260
+ after_state: { enum: [...AFTER_STATES], description: "Why `after` is what it is: `priced`, it is the mean of the served runs whose cost is known; `no_served_runs`, no learned workflow has taken over yet (replays are not served runs), so there is no after side; `cost_unknown`, runs were served but no served run's all-in cost is known exactly. A reader says these in words, never as a figure." },
1243
1261
  times_cheaper: { type: ["number", "null"], minimum: 0, description: `\`before\` over \`after\`, to a tenth, once \`after\` counts ${CHEAPER_AFTER_RUNS} runs or more and \`withheld\` is null; else null. Learning is left out of the before side and kept in the after side, so it never flatters learning.` },
1244
1262
  hand_backs: { oneOf: [closed({ ran: COUNT, back: COUNT }), { type: "null" }], description: "Of the runs a learned workflow ran first on from the takeover on (`path` `workflow` or `handed_back`), how many (`ran`) and how many it handed back to the agent (`back`); null before a takeover." },
1245
1263
  withheld: { oneOf: [closed({ unknown: { ...COUNT, description: "Runs whose cost is unknown." }, at_most: { ...COUNT, description: "Runs whose cost is known only as at most (`cost_upper_bound`)." } }), { type: "null" }], description: "After a takeover, the runs `before` and `after` would read whose cost is not known exactly: while any is, `times_cheaper` is null, so the ratio is never over a partial set. Null when every one is known, and before a takeover." },
@@ -1292,7 +1310,7 @@ const PROMOTION = closedWith({
1292
1310
  workflow: { type: "string" },
1293
1311
  digest: { type: "string", description: "The revision the record decides: the first 16 hex of its workflow.json's sha256." },
1294
1312
  at: DATE_TIME,
1295
- decided: { enum: ["promote", "hold", "replaying", "superseded"], description: "`promote`: it serves first on the runs it fits. `hold`: it does not; the champion (the revision promoted last) takes them, else the agent, until a new revision. `replaying`: its replay runs are at work; the champion serves meanwhile, else the agent. `superseded`: a newer revision (`superseded_by`) came while it replayed; one revision replays at a time, so its replay runs were cancelled (what they spent stays on them) and it never serves." },
1313
+ decided: { enum: ["promote", "hold", "replaying", "queued", "skipped"], description: "`promote`: it serves first on the runs it fits. `hold`: it does not; the champion (the revision promoted last) takes them, else the agent, until a new revision. `replaying`: its replay runs are at work; the champion serves meanwhile, else the agent. `queued`: it came while another revision replayed; one revision replays at a time and a running replay finishes, so it replays next, at the first run's claim once that replay is decided (the finished replay's verdict stands). `skipped`: a newer revision (`skipped_by`) came while it was queued; only the newest queued revision replays next, so it never replayed and never serves." },
1296
1314
  source: { enum: ["replay", "dry_run", "refit", "graded"], description: `\`replay\`: decided on a replay of it on the agent's last ${REPLAY_INPUTS} graded inputs it fits, or those its owner asked for (POST .../revisions/{digest}/replays). \`dry_run\`: fewer than ${REPLAY_MIN} graded inputs, promoted on its passing dry run. \`refit\`: a threshold refit wrote this revision, decided on the rows it was fit on. \`graded\`: the graded runs it served fell more than ${PROMOTE_BAR * 100} points under the agent's accuracy by hand.` },
1297
1315
  reason: { type: "string", description: "Why, in words, with the numbers." },
1298
1316
  }, {
@@ -1305,7 +1323,7 @@ const PROMOTION = closedWith({
1305
1323
  since: { ...COUNT, description: "On a replay's promote: the place among the agent's grades of the newest grade when this promotion began, which names it. Its checks count only the graded runs this promotion served, so a revision promoted again after a hold is never held again on the grades it was held on, nor on a run served before it and graded after." },
1306
1324
  held_on: { type: "array", items: { type: "string" }, description: `The runs it served that were graded wrong when its graded runs held it (newest first, at most ${REPLAY_INPUTS}), kept on that hold, on its next replay (those still graded that it fits, each among its inputs) and on that replay's hold. A replay promotes it only once it answered or handed back on each of them, and is within the bar on them alone (gains on other inputs never pay for repeating their wrong answers).` },
1307
1325
  commit: { type: "string", description: "The learning commit whose workflow.json is this revision's text: what it serves from as the champion while a newer revision replays." },
1308
- superseded_by: { type: "string", description: "A superseded revision's newer one: the digest whose replay replaced its own." },
1326
+ skipped_by: { type: "string", description: "A skipped revision's newer one: the digest that came while it was queued, and replays in its place." },
1309
1327
  });
1310
1328
  const SERVING = closed({
1311
1329
  workflow: { type: "string" },
@@ -1372,7 +1390,7 @@ const LEARNING_EXTENSIONS = {
1372
1390
  from_notes: { type: "array", items: { type: "string" }, description: "The notes it absorbed, by file name (each marked \`compiled_into\` once it merged)." },
1373
1391
  attempts: { type: "array", items: closed({ ok: { type: "boolean" }, errors: { type: "array", items: { type: "string" } } }), description: "Each attempt in order: whether its checks and dry run passed, and what they refused." },
1374
1392
  digest: { ...NULL_STRING, description: "The kept draft's digest; null when none passed." },
1375
- promoted: { type: ["boolean", "null"], description: "Whether that revision was promoted, as its records say now: true promoted (or a refit of it was), false held or superseded, null undecided or none passed. It may no longer serve: the promotions read's \`serving\` says which revision does." },
1393
+ promoted: { type: ["boolean", "null"], description: "Whether that revision was promoted, as its records say now: true promoted (or a refit of it was), false held or skipped, null queued, undecided or none passed. It may no longer serve: the promotions read's \`serving\` says which revision does." },
1376
1394
  draft_errors: { type: "array", items: { type: "string" }, description: "A draft that never passed: its last errors. Empty when one passed." },
1377
1395
  withheld: { type: "boolean", description: "The run's handed values can't be read here: its error texts are left out (the counts stand)." },
1378
1396
  }), description: "Newest first." },
@@ -1397,7 +1415,7 @@ const LEARNING_EXTENSIONS = {
1397
1415
  "/agents/{agent_id}/learning/promotions": {
1398
1416
  get: {
1399
1417
  operationId: "listLearningPromotions", tags: ["agents"], summary: "Each learned workflow revision's promotion: its replay's numbers and whether it serves",
1400
- description: "Every promotion record of the agent's learned workflows, oldest first: a new revision's replay on the agent's graded inputs (replaying, then promoted or held, with its numbers), one promoted on its dry run, a threshold refit's new revision, a serving revision held on its graded runs. A revision serves only once its replay promotes it; the champion (the revision promoted last) keeps serving while a newer one replays or after it is held, and `serving` says which digest serves and which replays. Aggregates only: no input or answer. What the console's Learning tab marks on its cost chart.",
1418
+ description: "Every promotion record of the agent's learned workflows, oldest first: a new revision's replay on the agent's graded inputs (replaying, then promoted or held, with its numbers), one promoted on its dry run, a threshold refit's new revision, a serving revision held on its graded runs. A revision serves only once its replay promotes it; the champion (the revision promoted last) keeps serving while a newer one replays or after it is held, and `serving` says which digest serves and which replays. One revision replays at a time and a running replay finishes: a newer one that comes meanwhile is queued, and replays next; one queued before it is skipped, its record naming the newer one. Aggregates only: no input or answer. What the console's Learning tab marks on its cost chart.",
1401
1419
  parameters: [AGENT_ID],
1402
1420
  responses: { "200": json(closed({ agent: { type: "string" }, promotions: { type: "array", items: PROMOTION }, serving: { type: "array", items: SERVING, description: "Each learned workflow with a record: the revision that serves and the one replaying." } }), "The agent's promotion records, and what serves."), ...errors(401, 403, 404, 429, 500) },
1403
1421
  "x-agentrun-serve": "promotion/1",
@@ -1562,7 +1580,7 @@ const LEARNING_EXTENSIONS = {
1562
1580
  "/agents/{agent_id}/learning/workflows/{name}/revisions/{digest}/replays": {
1563
1581
  post: {
1564
1582
  operationId: "startLearnedWorkflowReplay", tags: ["agents"], summary: "Replay a learned workflow's revision on the agent's graded inputs: re-check a held revision, or an edited one",
1565
- description: `Starts the replay a run's claim starts for a new revision (GET /agents/{agent_id}/learning/promotions explains them): one replay run of the agent per graded input, each the workflow alone at workflow cost, its reads live and its writes answered only from the graded run's recording, never sent. \`inputs\`: \`held\` (the default), the graded runs the revision's last replay or hold was decided on, or, with none, the agent's newest ${REPLAY_INPUTS}; a number from 1 to ${GRADES_KEPT}, that many of the agent's newest graded runs. Either way, a revision held on runs it served that were graded wrong is replayed on those too (its hold's \`held_on\`), and promoted only once it answered or handed back on each and is within the bar on them alone. Each is a graded run the agent answered (path \`agent\` or \`handed_back\`) or the workflow answered alone (\`workflow\`), with no uploaded file, whose input the revision takes. Its record is a replay's (\`source: replay\`, \`replaying\` then promoted or held, with its numbers, as a claim-started one is), decided once every replay run ended: at a run's claim that lays the revision, or at its read (GET .../replays/{replay_id}). A promoted revision serves first, and a held one may be refit, as after any replay. Its replay runs are handed no per-run MCP credentials. The revision is \`digest\`, the first 16 hex of its workflow.json's sha256: one a promotion record names (read at its commit), or the one on the learning folder's main. 404 for an unknown agent, workflow or revision. 409 \`replay_conflict\` when it is replaying already, another revision of the workflow replays (one at a time), it is promoted (it serves already), fewer than ${REPLAY_MIN} of the graded inputs asked for fit it (a replay on fewer could only hold it, so nothing is reserved and no run starts), or the agent's runs take no learned workflow here. 409 \`agent_not_runnable\` for an archived agent, as a run's start is: nothing is reserved. 400 for any other \`inputs\`. Only the owner, signed in with their password, starts one: the console's password session alone, from this server's own origin with a JSON body; every token is 403 \`forbidden\`.`,
1583
+ description: `Starts the replay a run's claim starts for a new revision (GET /agents/{agent_id}/learning/promotions explains them): one replay run of the agent per graded input, each the workflow alone at workflow cost, its reads live and its writes answered only from the graded run's recording, never sent. \`inputs\`: \`held\` (the default), the graded runs the revision's last replay or hold was decided on, or, with none, the agent's newest ${REPLAY_INPUTS}; a number from 1 to ${GRADES_KEPT}, that many of the agent's newest graded runs. Either way, a revision held on runs it served that were graded wrong is replayed on those too (its hold's \`held_on\`), and promoted only once it answered or handed back on each and is within the bar on them alone. Each is a graded run the agent answered (path \`agent\` or \`handed_back\`) or the workflow answered alone (\`workflow\`), with no uploaded file, whose input the revision takes. Its record is a replay's (\`source: replay\`, \`replaying\` then promoted or held, with its numbers, as a claim-started one is), decided once every replay run ended: at a run's claim that lays the revision, or at its read (GET .../replays/{replay_id}). A promoted revision serves first, and a held one may be refit, as after any replay. Its replay runs are handed no per-run MCP credentials. The revision is \`digest\`, the first 16 hex of its workflow.json's sha256: one a promotion record names (read at its commit), or the one on the learning folder's main. 404 for an unknown agent, workflow or revision. 409 \`replay_conflict\` when it is replaying already, another revision of the workflow replays (one at a time, and a running replay finishes: a revision queued behind it, \`queued\` in the promotions, replays at the first run's claim once it ends, no POST needed), it is promoted (it serves already), fewer than ${REPLAY_MIN} of the graded inputs asked for fit it (a replay on fewer could only hold it, so nothing is reserved and no run starts), or the agent's runs take no learned workflow here. 409 \`agent_not_runnable\` for an archived agent, as a run's start is: nothing is reserved. 400 for any other \`inputs\`. Only the owner, signed in with their password, starts one: the console's password session alone, from this server's own origin with a JSON body; every token is 403 \`forbidden\`.`,
1566
1584
  security: [{ ownerSession: [] }],
1567
1585
  parameters: [AGENT_ID, { name: "name", in: "path", required: true, description: "The learned workflow's folder name, `workflows/<name>/`.", schema: { type: "string" } }, { name: "digest", in: "path", required: true, description: "The revision: the first 16 hex of its workflow.json's sha256.", schema: { type: "string" } }],
1568
1586
  requestBody: { required: true, content: { "application/json": { schema: { type: "object", additionalProperties: false, properties: { inputs: { oneOf: [{ const: "held" }, { type: "integer", minimum: 1, maximum: GRADES_KEPT }], default: "held", description: "`held`: the graded inputs it was last decided on; a number: the agent's newest that many." } } } } } },
@@ -1572,7 +1590,7 @@ const LEARNING_EXTENSIONS = {
1572
1590
  "/agents/{agent_id}/learning/workflows/{name}/revisions/{digest}/replays/{replay_id}": {
1573
1591
  get: {
1574
1592
  operationId: "getLearnedWorkflowReplay", tags: ["agents"], summary: "Read a replay's result: running, done or failed, its counts and its score (start one from the console's Learning tab)",
1575
- description: "A replay a run's claim or the agent's owner started. This read decides it as a claim would, once every replay run ended or its deadline passed (promoted within 2 points of the agent, else held, then one refit), so a replay of a revision no run lays is decided too. It never starts a run: a replay whose launch was interrupted (the server stopped before creating its runs) reads `running` until its deadline. `status`: `running` while it replays, `done` once promoted or held (`decided`, with its `reason`), `failed` when a newer revision superseded it and its runs were cancelled, or when none of its runs started by its deadline (held, nothing replayed; its `reason` says so and to start it again with POST). `outcomes` counts its replay runs so far (once decided, those it was decided on, as its promotion record keeps them): `answered` alone, `handed_back` (the agent's recorded answer), `failed` (no evidence either way), `skipped_write` (a write its recording does not have). `score` is the decided record's, else the runs ended so far at the revision's serving thresholds. Aggregates only, its words cut as the promotions list's are.",
1593
+ description: "A replay a run's claim or the agent's owner started. This read decides it as a claim would, once every replay run ended or its deadline passed (promoted within 2 points of the agent, else held, then one refit), so a replay of a revision no run lays is decided too. It never starts a run: a replay whose launch was interrupted (the server stopped before creating its runs) reads `running` until its deadline. `status`: `running` while it replays, `done` once promoted or held (`decided`, with its `reason`; a newer revision that came meanwhile queued behind it, never cancelling it), `failed` when none of its runs started by its deadline (held, nothing replayed; its `reason` says so and to start it again with POST). `outcomes` counts its replay runs so far (once decided, those it was decided on, as its promotion record keeps them): `answered` alone, `handed_back` (the agent's recorded answer), `failed` (no evidence either way), `skipped_write` (a write its recording does not have). `score` is the decided record's, else the runs ended so far at the revision's serving thresholds. Aggregates only, its words cut as the promotions list's are.",
1576
1594
  parameters: [AGENT_ID, { name: "name", in: "path", required: true, description: "The learned workflow's folder name.", schema: { type: "string" } }, { name: "digest", in: "path", required: true, description: "The revision's digest.", schema: { type: "string" } }, { name: "replay_id", in: "path", required: true, description: "The replay's id: POST .../replays answered it, and its promotion records carry it (`replay_id`).", schema: { type: "string" } }],
1577
1595
  responses: { "200": json(closedWith({
1578
1596
  replay: { type: "string" }, workflow: { type: "string" }, digest: { type: "string" },
@@ -1582,7 +1600,7 @@ const LEARNING_EXTENSIONS = {
1582
1600
  score: closed(REPLAY_SCORE),
1583
1601
  cost_usd: { type: ["number", "null"], minimum: 0, description: "What its replay runs cost together; null while one's cost is unknown (one not created or not ended yet), never a part of it." },
1584
1602
  }, {
1585
- decided: { enum: ["promote", "hold", "superseded"], description: "Once it is not running: what it decided." },
1603
+ decided: { enum: ["promote", "hold"], description: "Once it is not running: what it decided." },
1586
1604
  reason: { type: "string", description: "Why, in words, with the numbers." },
1587
1605
  }), "The replay."), ...errors(401, 403, 404, 429, 500) }, ...MARK,
1588
1606
  },
@@ -1711,6 +1729,7 @@ const EXTENSIONS = {
1711
1729
  { name: "revision", in: "query", required: false, description: "Only runs of this revision.", schema: { type: "string" } },
1712
1730
  { name: "status", in: "query", required: false, description: "Only runs with this status.", schema: ref("schemas/RunStatus") },
1713
1731
  { name: "archived", in: "query", required: false, description: "true lists only archived runs; false, the default, the others.", schema: { type: "boolean" } },
1732
+ LABEL_PARAMETER,
1714
1733
  ],
1715
1734
  responses: { "200": json(ref("schemas/RunList"), "One page of runs, newest first."), ...errors(400, 401, 429, 500) },
1716
1735
  },
@@ -1978,11 +1997,21 @@ const EXTENSIONS = {
1978
1997
  "/computers/attach": {
1979
1998
  get: {
1980
1999
  operationId: "attachComputer", tags: ["local"], summary: "The attach socket: a paired computer's driver dials it (a WebSocket)",
1981
- description: `A WebSocket (spec/computer/attach.md). The driver dials it with \`Authorization: Bearer <its token>\` (POST /computers/pair) and the subprotocol \`${ATTACH_SUBPROTOCOL}\`. A token no paired computer has (unknown, or its computer removed) is 401 before the upgrade; another subprotocol is 426. Frames are text, one JSON-RPC message each, at most ${MAX_LINE_BYTES} bytes (a bigger one closes the socket with 1009, a binary frame with 1003). The server is the caller: it sends hello, and the computer is attached while its hello is what it paired as (else closed with 4400, or 4426 for another protocol version); then the server sends a run's calls. Each side pings every ${ATTACH_HEARTBEAT_MS / 1000} s, and one that hears nothing for ${ATTACH_IDLE_MS / 1000} s closes with 4408. The same computer dialing again replaces its older socket (4409); removing it closes the socket with 4401. A request with no upgrade is 400. One server process holds the socket, so a run uses a paired computer only on a runner in that process (the start's runner beside the server).`,
2000
+ description: `A WebSocket (spec/computer/attach.md). The driver dials it with \`Authorization: Bearer <its token>\` (POST /computers/pair) and the subprotocol \`${ATTACH_SUBPROTOCOL}\`. A hosted machine of a dial provider dials it the same way with the token its create minted (GET /computers/daemon), and its socket stands for that create's machine, whose hello must say the kind, os and arch it was made as (else 4400). A token no paired computer or hosted machine has good (unknown, its computer removed, its machine deleted or past its backstop) is 401 before the upgrade; another subprotocol is 426. Frames are text, one JSON-RPC message each, at most ${MAX_LINE_BYTES} bytes (a bigger one closes the socket with 1009, a binary frame with 1003). The server is the caller: it sends hello, and the computer is attached while its hello is what it paired as (else closed with 4400, or 4426 for another protocol version); then the server sends a run's calls. Each side pings every ${ATTACH_HEARTBEAT_MS / 1000} s, and one that hears nothing for ${ATTACH_IDLE_MS / 1000} s closes with 4408. The same computer dialing again replaces its older socket (4409); removing it closes the socket with 4401. A request with no upgrade is 400. One server process holds the socket, so a run uses a paired computer only on a runner in that process (the start's runner beside the server).`,
1982
2001
  responses: { "101": { description: "Switching to the attach WebSocket." }, ...errors(400, 401, 500) },
1983
2002
  ...ATTACH_MARK,
1984
2003
  },
1985
2004
  },
2005
+ "/computers/daemon": {
2006
+ get: {
2007
+ operationId: "getComputerDaemon", tags: ["local"], summary: "This server's computerd build, for a hosted machine that dials it (its minted token)",
2008
+ description: `A hosted machine of a provider whose host has no exec (a dial provider's) fetches its daemon here as it boots, with \`Authorization: Bearer <its token>\`: the token the machine's create minted, which its env holds (AGENTRUN_ATTACH_TOKEN). The answer is this server's own computerd build for \`arch\`, the same bytes a hosted provider uploads, whose SHA-256 the create put in the machine's env (AGENTRUN_DAEMON_SHA256) for the machine to check before it runs it. A token no machine has good (unknown, revoked at the machine's delete, or past its backstop) is 401; each machine's token gets ${DAEMON_FETCHES_PER_MINUTE} fetches a minute (429 past them, with Retry-After); an arch other than amd64 or arm64 is 422. The owner's token and session are not a machine's token: 401.`,
2009
+ security: [],
2010
+ parameters: [{ name: "arch", in: "query", required: true, description: "The machine's architecture.", schema: { type: "string", enum: ["amd64", "arm64"] } }],
2011
+ responses: { "200": { description: "The daemon's bytes.", content: { "application/octet-stream": { schema: { type: "string", contentMediaType: "application/octet-stream" } } } }, ...errors(401, 422, 429, 500, 503) },
2012
+ ...ATTACH_MARK,
2013
+ },
2014
+ },
1986
2015
  "/computers/{computer_id}": {
1987
2016
  delete: {
1988
2017
  operationId: "deleteComputer", tags: ["local"], summary: "Remove a paired computer: its token ends and its socket closes",
@@ -2204,19 +2233,19 @@ const EXTENSIONS = {
2204
2233
  },
2205
2234
  put: {
2206
2235
  operationId: "saveMcpServer", tags: ["local"], summary: "Preview a remote MCP server, then save it with the tools listed and its credential sealed",
2207
- description: `The credential is sealed under the server's seal key, bound to the server's name and its URL's origin, and kept in the data directory as ciphertext alone. 403 forbidden to the API token for a save that sends a credential's value, or that would drop or change the credential the server holds (another \`auth.type\`, or none): the owner's signed-in session alone. 412 precondition_failed when a save that sends a new credential, or none, finds the server's credential changed while it listed its tools (another save, a sign-in or a removal landed): nothing is written over it. A body with no credential keeps the sealed one while the type and the URL's origin stay the same; else it is 422. A body with no \`prices\` keeps the saved ones for the tools still listed at the same URL, so a save from any client never leaves a paid tool unmetered; \`prices: {}\` clears them. 422 too for a bad name, URL or auth, or a price that is not a finite number 0 or more or names a tool the server does not list. ${MCP_CONNECTS} Nothing is saved unless the listing succeeds.`,
2236
+ description: `The credential is sealed under the server's seal key, bound to the server's name and its URL's origin, and kept in the data directory as ciphertext alone. 403 forbidden to the API token for a save that sends a credential's value, or that would drop or change the credential the server holds (another \`auth.type\`, or none): the owner's signed-in session alone. 412 precondition_failed when a save that sends a new credential, or none, finds the server's credential changed while it listed its tools (another save, a sign-in or a removal landed), or a save that keeps it finds the server at another address or holding another kind of credential by then (a Composio save over it moved it): nothing is written over it. A body with no credential keeps the sealed one while the type and the URL's origin stay the same; else it is 422. A body with no \`prices\` keeps the saved ones for the tools still listed at the same URL, so a save from any client never leaves a paid tool unmetered; \`prices: {}\` clears them. 422 too for a bad name, URL or auth, or a price that is not a finite number 0 or more or names a tool the server does not list. ${MCP_CONNECTS} Nothing is saved unless the listing succeeds. A save that moves a server the Composio preset made to another address makes it another service's server, and removes in the owner's Composio account what the preset made for it, as its delete does (the MCP server, then the connected account its connect link started and the auth config it made, unless another saved server uses them), with the key it was saved with, and answers \`composio\` saying so; 409 composio_in_use, naming them in \`details.triggers\`, while Composio triggers use it: delete them first. A save of a server the preset made lists its tools at once, then writes and cleans up one at a time with the preset's saves and the MCP servers' deletes, in its Composio project's turn.`,
2208
2237
  parameters: [MCP_NAME],
2209
2238
  requestBody: { required: true, content: { "application/json": { schema: { type: "object", additionalProperties: false, required: ["url"], properties: { url: MCP_URL, auth: MCP_AUTH, prices: MCP_PRICES, ...MCP_TOOLKIT_BODY } } } } },
2210
- responses: { "200": json(MCP_SERVER_VIEW, "The server, as saved."), ...errors(400, 401, 403, 409, 412, 415, 422, 429, 500), ...MCP_FAILED },
2239
+ responses: { "200": json({ ...MCP_SERVER_VIEW, properties: { ...MCP_SERVER_VIEW.properties, composio: closed({ removed: { type: "boolean", description: "Nothing the save was to remove at Composio is left there." }, note: { type: "string", description: "What it removed at Composio, what it kept and why, and what is left, with the dashboard's address to remove that by hand." } }, "Present when the save moved a server the Composio preset made off Composio: what became of what the preset made there.") } }, "The server, as saved."), ...errors(400, 401, 403, 409, 412, 415, 422, 429, 500), ...MCP_FAILED },
2211
2240
  "x-agentrun-serve": "mcpservers/1",
2212
2241
  },
2213
2242
  delete: {
2214
2243
  operationId: "deleteMcpServer", tags: ["local"], summary: "Forget a saved MCP server and its credential",
2215
- description: "409 composio_in_use, naming them in `details.triggers`, for a Composio server that Composio triggers still use: delete them first. A server the Composio preset made also has its MCP server deleted in the owner's Composio account, with the saved key, after the row is removed: the row is already gone while that delete waits on Composio. Composio's 404 means it is already gone; when Composio refuses or does not answer, or the saved key does not open, the answer is 200 with `composio.removed: false` and a note to remove it there. 403 forbidden to the API token when the server holds a credential: removing it drops a secret, the owner's signed-in session's alone. A server saved with none is the token's to remove. 412 precondition_failed when the server's credential changed between that check and the removal (a save or a sign-in landed): nothing is removed, and nothing is sent to Composio.",
2244
+ description: "409 composio_in_use, naming them in `details.triggers`, for a Composio server that Composio triggers still use: delete them first. A server the Composio preset made also has its MCP server deleted in the owner's Composio account, with the saved key, after the row is removed: the row is already gone while that delete waits on Composio. So does what its save made for it there that no other saved server uses: the connected account its connect link started (the link with it), and the auth config it made. What another saved server uses is kept, and goes with the last of them; what the save found there already (an auth config or an account the owner had) is never deleted. A preset's delete answers 200 with `composio`: `removed` true when nothing it was to remove is left, and `note`, what it removed, kept (and why) and left, in words. Composio's 404 means that one is already gone; when Composio refuses or does not answer, or the saved key does not open, `removed` is false and the note names what is left, to remove there. 403 forbidden to the API token when the server holds a credential: removing it drops a secret, the owner's signed-in session's alone. A server saved with none is the token's to remove. 412 precondition_failed when the server's credential changed between that check and the removal (a save or a sign-in landed): nothing is removed, and nothing is sent to Composio.",
2216
2245
  parameters: [MCP_NAME],
2217
2246
  responses: {
2218
- "204": { description: "Forgotten (and, for a Composio preset server, its Composio MCP server deleted, or already gone there)." },
2219
- "200": json(closed({ deleted: { type: "boolean", enum: [true] }, composio: closed({ removed: { type: "boolean", enum: [false] }, note: { type: "string", description: "What to do by hand: remove the server in Composio yourself, with the dashboard's address." } }) }), "Forgotten here, but the Composio MCP server a preset made could not be deleted (Composio refused or did not answer): it stays in the owner's Composio account until removed there. The row is gone either way."),
2247
+ "204": { description: "Forgotten: a server the Composio preset did not make." },
2248
+ "200": json(closed({ deleted: { type: "boolean", enum: [true] }, composio: closed({ removed: { type: "boolean", description: "Nothing the delete was to remove at Composio is left there." }, note: { type: "string", description: "What it removed at Composio, what it kept and why, and what is left, with the dashboard's address to remove that by hand." } }) }), "Forgotten here, a Composio preset server: what its delete did in the owner's Composio account. The row is gone either way."),
2220
2249
  ...errors(401, 403, 404, 409, 412, 429, 500),
2221
2250
  },
2222
2251
  "x-agentrun-serve": "mcpservers/1",
@@ -2243,10 +2272,10 @@ const EXTENSIONS = {
2243
2272
  "/settings/mcp-servers/{name}/composio": {
2244
2273
  put: {
2245
2274
  operationId: "saveComposioServer", tags: ["local"], summary: "Have Composio make a managed MCP server for a toolkit's chosen actions, and save it as an MCP server",
2246
- description: COMPOSIO_NOTE + " Makes (or reuses) a Composio-managed auth config for a toolkit that needs the person's account, makes a Composio MCP server allowing only `tools`, asks for its address (the helper actions that connect an account left off; its path ends in `/mcp`), and saves that address as the MCP server `name` through the one MCP save: the key is sealed as an `x-api-key` header, the tools listed, none priced (\"not metered\"). When the toolkit needs an account and `user_id` has no active one, `connect_url` is Composio's page to connect it; nothing here signs in. `user_id` defaults to `agentrun`. 422 for a bad name, key, toolkit or tools, a key or request Composio refuses (each says the step); 424 `upstream_failed` when Composio fails or the saved address does not list its tools. Nothing is saved unless every step succeeds. The owner's signed-in session alone: 403 forbidden to the API token.",
2275
+ description: COMPOSIO_NOTE + " Makes (or reuses) a Composio-managed auth config for a toolkit that needs the person's account, makes a Composio MCP server allowing only `tools`, asks for its address (the helper actions that connect an account left off; its path ends in `/mcp`), and saves that address as the MCP server `name` through the one MCP save: the key is sealed as an `x-api-key` header, the tools listed, none priced (\"not metered\"). When the toolkit needs an account and `user_id` has no active one, `connect_url` is Composio's page to connect it; nothing here signs in. `user_id` defaults to `agentrun`. 422 for a bad name, key, toolkit or tools, a key or request Composio refuses (each says the step); 424 `upstream_failed` when Composio fails or the saved address does not list its tools. Nothing is saved unless every step succeeds, and a save that fails removes in Composio what it made there (the MCP server, the connected account its connect link started, the auth config it made), never what it found; when Composio refuses that too, its error's message names what is left, with the dashboard's address (and a 422 on a field says it in \`details.composio\` as well). A save over a server the preset made removes, once it is saved, the MCP server that server's earlier save made, and what that save made and this one no longer stands on (the account of another `user_id`, the auth config of another toolkit), with the key it was made with, unless another saved server uses it (then it is that one's), and answers `composio` saying so, as a delete does. A save over a server as another `user_id` or auth config is 409 composio_in_use, naming them in `details.triggers`, while Composio triggers use it: delete them first; a save that leaves what they stand on alone goes through. Preset saves, the saves of the servers they made, and deletes of MCP servers run one at a time. The owner's signed-in session alone: 403 forbidden to the API token.",
2247
2276
  parameters: [MCP_NAME],
2248
2277
  requestBody: { required: true, content: { "application/json": { schema: closedWith({ api_key: COMPOSIO_KEY, toolkit: COMPOSIO_TOOLKIT, tools: { type: "array", minItems: 1, maxItems: 500, items: { type: "string", minLength: 1 }, description: "The slugs of the actions to grant, from the listing." } }, { user_id: { type: "string", pattern: "^[A-Za-z0-9._@-]{1,128}$", description: "The Composio user the actions run as; default `agentrun`." } }) } } },
2249
- responses: { "200": json(closedWith({ server: MCP_SERVER_VIEW }, { connect_url: { type: "string", format: "uri", description: "Present when the toolkit needs an account and the user has no active one: Composio's page to connect it." }, not_served: { type: "array", items: { type: "string" }, description: "Present when Composio's server leaves out some of `tools` (it can, for an action it was allowed): the slugs it doesn't list, which a run can't call." } }), "The server as saved, and where to connect the account when it must be."), ...errors(400, 401, 403, 409, 415, 422, 429, 500), ...MCP_FAILED },
2278
+ responses: { "200": json(closedWith({ server: MCP_SERVER_VIEW }, { connect_url: { type: "string", format: "uri", description: "Present when the toolkit needs an account and the user has no active one: Composio's page to connect it." }, not_served: { type: "array", items: { type: "string" }, description: "Present when Composio's server leaves out some of `tools` (it can, for an action it was allowed): the slugs it doesn't list, which a run can't call." }, composio: closed({ removed: { type: "boolean", description: "Nothing the save was to remove at Composio is left there." }, note: { type: "string", description: "What it removed at Composio, what it kept and why, and what is left, with the dashboard's address to remove that by hand." } }, "Present when the save was over a server whose earlier save made something at Composio that this one no longer stands on: what became of it.") }), "The server as saved, and where to connect the account when it must be."), ...errors(400, 401, 403, 409, 415, 422, 429, 500), ...MCP_FAILED },
2250
2279
  "x-agentrun-serve": "mcpservers/1",
2251
2280
  },
2252
2281
  },
@@ -2681,6 +2710,7 @@ const RUN_FIELDS = {
2681
2710
  revision: { type: "string", description: "The id of the agent revision the run runs.", "x-agentrun-serve": "serve/1" },
2682
2711
  kind: { enum: ["agentic", "workflow"], description: "The revision's kind: an agentic run, or a workflow run.", "x-agentrun-serve": "serve/1" },
2683
2712
  archived_at: { type: ["string", "null"], description: "When the run, or its agent, was archived, while it is; else null.", "x-agentrun-serve": "serve/1" },
2713
+ labels: { ...RUN_LABELS, description: "The labels the run was started with (RunCreate.labels), as given; `{}` when none. Always sent by a server that keeps labels (`runlabels/1`); absent from an earlier one's answer." },
2684
2714
  };
2685
2715
  /** What a run waits on, one field for every kind, told apart by `kind`: a question it asked a person, or a tool call
2686
2716
  * that waits for approval. */
@@ -2699,7 +2729,7 @@ const PENDING = {
2699
2729
  tool: { type: "string" },
2700
2730
  call_id: { type: "string", description: "The call's id, as its tool_result row's tool_use_id." },
2701
2731
  args_preview: { type: "string", maxLength: ARGS_PREVIEW_BYTES, description: `The call's arguments as JSON, cut at ${ARGS_PREVIEW_BYTES} bytes.` },
2702
- summary: { type: "string", description: "What the call does, in words, where its tool says: email_send's \"Send email to <to>, cc <cc>: <subject>\", a blank line, then the text's first 300 characters; email_file's \"File <message_id> under <to>\". Redacted as args_preview is.", "x-agentrun-serve": "email/1" },
2732
+ summary: { type: "string", description: `What the call does, in words, where its tool says: email_send's "Send email to <to>, cc <cc>: <subject>", a blank line, then the text's first 300 characters; email_file's "File <message_id> under <to>". When the call asks though its setting allows it (its tool's own ask: email_send past ${SEND_CAP} sends in a run, or to anyone outside the thread of the email that started the run), it ends "Asks because <why>.", and args_preview carries the why as asked_because. Redacted as args_preview is.`, "x-agentrun-serve": "email/1" },
2703
2733
  requested_at: { type: "string", format: "date-time" },
2704
2734
  price: { oneOf: [{ type: "number", minimum: 0 }, { const: "not metered" }, { const: "priced by usage" }], description: "What the call costs, in USD, where its tool declares a price; \"not metered\" for an unpriced MCP call; \"priced by usage\" for a monid endpoint priced by usage: monid estimates its cost only when the call runs, after the allow (the call is held at that estimate, and a charge above it stops the run), so nothing is sent to monid while it waits. Absent when the tool names none." },
2705
2735
  destructive: { const: true, description: `Present on an MCP tool's call that is destructive by the annotations the run pinned (destructiveHint true, readOnlyHint not true), and on a call whose allow lets such a tool run (a learned workflow's, its card naming the tool in \`mcp_calls\`): its allow needs \`confirm_destructive: true\`. Absent on every other call.`, "x-agentrun-serve": "allowreads/1" },
@@ -2821,6 +2851,7 @@ const FIELD_EXTENSIONS = {
2821
2851
  },
2822
2852
  RunCreate: {
2823
2853
  mcp_auth: { ...MCP_RUN_AUTH, description: `${MCP_RUN_AUTH.description} Each names a saved MCP server whose \`auth.type\` is per_run (422 at \`mcp_auth.<server>\` otherwise, no run made). Sealed into the run's launch for its life, read at each claim, and erased by the write that ends it; never in its saved body, its timeline, its view or an Idempotency-Key's fingerprint (a retry with a new credential answers the first request's run).` },
2854
+ labels: { ...RUN_LABELS, description: `The caller's own labels for the run: at most ${MAX_LABELS} keys, each 1 to 63 letters, digits, \`.\`, \`_\`, \`-\` or \`/\` starting with a letter or a digit; each value text of 1 to ${MAX_LABEL_VALUE} characters with no control character. Kept on the run as given, served on every read of it (\`labels\` on Run and RunSummary) and matched by GET /runs' \`label\`; set once, at the start. The server reads nothing else from them: put no secret in one. Another shape is 422 under \`labels\` or \`labels.<key>\`. Absent: none.` },
2824
2855
  workflow_first: {
2825
2856
  type: "boolean",
2826
2857
  description: "Whether a run of an agent that learns may start on one of its learned workflows. On (absent or true), a run whose input fits exactly one active learned workflow (its input schema has a required field, and the run's input passes it) runs that workflow first, with no turn of the agent's model: its answer is the run's answer, and if it hands the job back (it escalates, a step fails), the same run goes on with the agent, given what the workflow found. The run keeps which path it took: `workflow`, `handed_back` or `agent`. false: the agent takes the run from its first turn.",
@@ -3546,6 +3577,11 @@ export function openapiDocument(capabilityOf, adapters = TRIGGER_ADAPTERS) {
3546
3577
  listAgents.parameters = [...listAgents.parameters, { name: "archived", in: "query", required: false, description: "true lists only archived agents; false, the default, the others.", schema: { type: "boolean" } }];
3547
3578
  listAgents["x-agentrun-serve-changed"] = { archived: "archivedparam/1" };
3548
3579
  changed.push("GET /agents");
3580
+ // GET /agents/{agent_id}/runs takes GET /runs' `label` filter too (server.ts runsPage, shared by both routes).
3581
+ const listAgentRuns = doc.paths["/agents/{agent_id}/runs"].get;
3582
+ listAgentRuns.parameters = [...listAgentRuns.parameters, LABEL_PARAMETER];
3583
+ listAgentRuns["x-agentrun-serve-changed"] = { ...listAgentRuns["x-agentrun-serve-changed"], label: "runlabels/1" };
3584
+ changed.push("GET /agents/{agent_id}/runs");
3549
3585
  // GET /agents/{agent_id} always sends the agent's `tools` (server.ts getAgent; [] before it has a revision), which the
3550
3586
  // agent in a list, a create or a save does not: its 200 is the contract's Agent with `tools` required.
3551
3587
  const getAgent = doc.paths["/agents/{agent_id}"].get;
@@ -3714,7 +3750,7 @@ export function openapiDocument(capabilityOf, adapters = TRIGGER_ADAPTERS) {
3714
3750
  }, {
3715
3751
  oauth: { ...MCP_SIGN_IN_CLIENT, description: "With `auth: oauth`, when the sign-in's discovery could be made." },
3716
3752
  }),
3717
- input_invalid: { type: "object", additionalProperties: false, properties: { oauth: { ...MCP_SIGN_IN_CLIENT, description: "With field `client_id`, reason `registration_unavailable` (POST .../oauth/start): as a preview's `details.oauth`, `registration` false." } } },
3753
+ input_invalid: { type: "object", additionalProperties: false, properties: { oauth: { ...MCP_SIGN_IN_CLIENT, description: "With field `client_id`, reason `registration_unavailable` (POST .../oauth/start): as a preview's `details.oauth`, `registration` false." }, composio: { type: "string", description: "A Composio preset save refused on a field (PUT .../composio) whose removal of what it made there Composio refused too: what is left there and where to remove it, in words, as its message ends." } } },
3718
3754
  upstream_failed: { type: "object", additionalProperties: false, properties: { status: { type: "integer", description: "The MCP server's HTTP status, when it answered one." } } },
3719
3755
  sign_in_held: { type: "object", additionalProperties: false, minProperties: 1, maxProperties: 1, properties: { held_by: { type: "string", description: "The run that holds the sign-in's save lease." }, handed_to: { type: "string", description: "A run still going that was handed the sign-in (signins/1)." } } },
3720
3756
  wrong_origin: closed({ open: { type: "string", format: "uri", description: "Where to open the console to sign in: the address the authorization server sends the browser back to." } }),
@@ -15,11 +15,14 @@ export type ThinkingLevelMap = NonNullable<Model<Api>["thinkingLevelMap"]>;
15
15
  /** The catalog's entry for a session's model, as its route carries it (model-route.ts `like`): its reasoning, price,
16
16
  * window and ceiling, the effort each thinking level asks for, and what it takes as input with its input limits. */
17
17
  /** `developerRole`: on Responses, the instructions go as a developer message, not a system one (a ChatGPT plan's route,
18
- * which takes no system message). */
18
+ * which takes no system message). `adaptiveThinking`: on Messages, the session asks its thinking level as an adaptive
19
+ * effort (pi-ai's `forceAdaptiveThinking`), never a token budget: the route's own translation reads that level back
20
+ * (model-route.ts LEVELS_BY_NAME). */
19
21
  export type SessionLike = Partial<Pick<Model<Api>, "reasoning" | "cost" | "contextWindow" | "maxTokens" | "thinkingLevelMap">> & {
20
22
  readonly input?: readonly string[];
21
23
  readonly inputLimits?: unknown;
22
24
  readonly developerRole?: boolean;
25
+ readonly adaptiveThinking?: boolean;
23
26
  };
24
27
  /** The one model of a session's route as pi-ai lists it, for the port's requests and for pi's own (runner adapters/pi.ts):
25
28
  * `model` in `api` at the proxy `url` (sessionBaseUrl), under `provider`, with `headers` (the session key as the proxy
@@ -32,6 +32,7 @@ export function sessionModel(api, url, model, options) {
32
32
  cost: like?.cost ?? { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
33
33
  contextWindow: like?.contextWindow ?? 200_000, maxTokens: like?.maxTokens ?? 32_000,
34
34
  ...(api === "openai-responses" ? { compat: { supportsDeveloperRole: like?.developerRole === true } } : {}),
35
+ ...(api === "anthropic-messages" && like?.adaptiveThinking ? { compat: { forceAdaptiveThinking: true } } : {}),
35
36
  };
36
37
  }
37
38
  /** pi-ai's provider for the one model of a session's proxy on its wire: pi-ai's client of `api` (Anthropic's Messages or
package/dist/print.d.ts CHANGED
@@ -1,9 +1,11 @@
1
- /** Where the token came from: made at this start (printed this once), kept in DIR/.token, or the environment's. */
2
- export type TokenSource = "made" | "file" | "env";
1
+ /** Where the token came from: made at this start (printed this once), kept in DIR/.token, the environment's
2
+ * (AGENTRUN_TOKEN), or the token list's alone (AGENTRUN_TOKENS). */
3
+ export type TokenSource = "made" | "file" | "env" | "list";
3
4
  /** The banner's lines. The token is printed only when this start made it; else where it is. `publicUrl` is the address
4
5
  * people open (AGENTRUN_PUBLIC_URL), which the base URL and the link use. With `accounts` the page is the owner's
5
6
  * password, so its link holds nothing; with none, the link holds this start's launch code (`launchCode`), never the
6
- * token. `apiOnly`: no console to open, so the line says what is served instead. `boxes`: which boxes are ready, in
7
+ * token. `tokenIds`: the ids of the tokens the server takes (api-token.ts), named when there is more than one or a list
8
+ * gave them, never a secret. `apiOnly`: no console to open, so the line says what is served instead. `boxes`: which boxes are ready, in
7
9
  * words (Serve's boxesLine), last. */
8
10
  export declare function banner(o: {
9
11
  url: string;
@@ -11,6 +13,7 @@ export declare function banner(o: {
11
13
  data: string;
12
14
  token: string;
13
15
  source: TokenSource;
16
+ tokenIds?: readonly string[];
14
17
  listen?: string;
15
18
  publicUrl?: string;
16
19
  accounts?: boolean;
package/dist/print.js CHANGED
@@ -4,15 +4,17 @@ import { join } from "node:path";
4
4
  /** The banner's lines. The token is printed only when this start made it; else where it is. `publicUrl` is the address
5
5
  * people open (AGENTRUN_PUBLIC_URL), which the base URL and the link use. With `accounts` the page is the owner's
6
6
  * password, so its link holds nothing; with none, the link holds this start's launch code (`launchCode`), never the
7
- * token. `apiOnly`: no console to open, so the line says what is served instead. `boxes`: which boxes are ready, in
7
+ * token. `tokenIds`: the ids of the tokens the server takes (api-token.ts), named when there is more than one or a list
8
+ * gave them, never a secret. `apiOnly`: no console to open, so the line says what is served instead. `boxes`: which boxes are ready, in
8
9
  * words (Serve's boxesLine), last. */
9
10
  export function banner(o) {
10
- const where = o.source === "env" ? "$AGENTRUN_TOKEN" : `<in ${join(o.data, ".token")}>`;
11
+ const where = o.source === "env" ? "$AGENTRUN_TOKEN" : o.source === "list" ? "<a secret in $AGENTRUN_TOKENS>" : `<in ${join(o.data, ".token")}>`;
11
12
  const key = o.source === "made" ? o.token : where;
12
13
  return [
13
14
  `agentrun-serve on ${o.baseUrl} (agent store in ${o.data}${o.listen ? `, listening on ${o.listen}` : ""})`,
14
15
  `AGENTRUN_BASE_URL=${o.publicUrl ? `${o.publicUrl}/v2` : o.baseUrl}`,
15
16
  `AGENTRUN_API_KEY=${key}`,
17
+ ...(o.tokenIds && (o.tokenIds.length > 1 || o.source === "list") ? [`API tokens taken (ids): ${o.tokenIds.join(", ")}`] : []),
16
18
  o.apiOnly
17
19
  ? "API only (AGENTRUN_API_ONLY=1): the run routes are served; the console, sign-in, setup, settings, MCP, triggers and hooks are refused."
18
20
  : o.accounts || o.launchCode === undefined ? `Open ${o.publicUrl ?? o.url}/` : `Open ${o.publicUrl ?? o.url}/?launch=${o.launchCode}`,
@@ -9,6 +9,9 @@ export declare const STOPPED_WHILE_WAITING = "Not run: the run was stopped while
9
9
  export declare const ENDED_WHILE_WAITING = "Not run: the run ended while it waited";
10
10
  /** How a refusal of a setting's deny, or of an ask no one can approve, opens (deniedText, noApproverText). */
11
11
  export declare const DENIED_OPENING = "Permission denied: ";
12
+ /** The field of an asked call's card that says why a call its setting allows asks a person anyway (a tool's own ask,
13
+ * tools.ts ToolEntry.asks): written by the gate alone, so the model's own arguments never carry it onto the card. */
14
+ export declare const ASKED_BECAUSE = "asked_because";
12
15
  /** How a person's deny opens (refusedText). */
13
16
  export declare const USER_DENIED_OPENING = "The user denied this ";
14
17
  /** What a read-only bash policy's refusal says after the tool's name (bash-read-only.ts readOnlyText). */
@@ -11,6 +11,9 @@ export const STOPPED_WHILE_WAITING = "Not run: the run was stopped while it wait
11
11
  export const ENDED_WHILE_WAITING = "Not run: the run ended while it waited";
12
12
  /** How a refusal of a setting's deny, or of an ask no one can approve, opens (deniedText, noApproverText). */
13
13
  export const DENIED_OPENING = "Permission denied: ";
14
+ /** The field of an asked call's card that says why a call its setting allows asks a person anyway (a tool's own ask,
15
+ * tools.ts ToolEntry.asks): written by the gate alone, so the model's own arguments never carry it onto the card. */
16
+ export const ASKED_BECAUSE = "asked_because";
14
17
  /** How a person's deny opens (refusedText). */
15
18
  export const USER_DENIED_OPENING = "The user denied this ";
16
19
  /** What a read-only bash policy's refusal says after the tool's name (bash-read-only.ts readOnlyText). */
@@ -0,0 +1,23 @@
1
+ import { type InputIssue } from "./errors.js";
2
+ import type { RunLabels } from "./store/store.js";
3
+ /** At most this many labels on a run. */
4
+ export declare const MAX_LABELS = 16;
5
+ /** A label's key: 1 to 63 characters, letters, digits and `.`, `_`, `-`, `/`, starting with a letter or a digit. No `:`, so
6
+ * a filter's `<key>:<value>` splits at its first one. */
7
+ export declare const LABEL_KEY: RegExp;
8
+ /** A label's value: text of 1 to this many characters, counted as Unicode code points (as JSON Schema's maxLength counts
9
+ * them), never UTF-16 units: an emoji is one character. */
10
+ export declare const MAX_LABEL_VALUE = 256;
11
+ /** A UTF-16 surrogate standing alone, half of no character (in `u` mode a whole pair is one code point, so only a lone half
12
+ * matches). JSON.stringify keeps one as a `\ud800` escape that Postgres' json check takes but json_each_text cannot
13
+ * decode: kept on a run, it would fail every later label search that scans that run. */
14
+ export declare const LONE_SURROGATE: RegExp;
15
+ /** A create body's `labels`, field by field: an object of at most MAX_LABELS keys, each matching LABEL_KEY, each value text
16
+ * of 1 to MAX_LABEL_VALUE characters with no control character. Absent is none. */
17
+ export declare function labelsIssues(labels: unknown): InputIssue[];
18
+ /** A create body's labels, once labelsIssues found none: the map as given, or undefined when absent or empty. */
19
+ export declare function labelsOf(labels: unknown): RunLabels | undefined;
20
+ /** GET /runs' `label` parameter, `<key>:<value>` (split at the first `:`, which a key never holds): the label a run must
21
+ * hold. One per request: the document declares a single string, and a client generated from it sends one, so a second
22
+ * is 400 bad_request rather than read here and dropped by a client. 400 too for one that does not read as a label. */
23
+ export declare function labelFilter(given: readonly string[]): RunLabels | undefined;
@@ -0,0 +1,79 @@
1
+ // A run's labels: a small map of the caller's own strings, given at its start (POST /agents/{agent_id}/runs, POST /runs),
2
+ // kept on the run, served on every read of it, and filtered on by GET /runs (`label=<key>:<value>`, one per request: the
3
+ // OpenAPI document declares it a single string, which every generated client sends once). The server never reads
4
+ // them otherwise: they are the caller's way to find its runs again (its own ids for a run, a job, a tenant). They are no
5
+ // place for a secret: every read of the run serves them as given.
6
+ import { ApiError } from "./errors.js";
7
+ /** At most this many labels on a run. */
8
+ export const MAX_LABELS = 16;
9
+ /** A label's key: 1 to 63 characters, letters, digits and `.`, `_`, `-`, `/`, starting with a letter or a digit. No `:`, so
10
+ * a filter's `<key>:<value>` splits at its first one. */
11
+ export const LABEL_KEY = /^[A-Za-z0-9][A-Za-z0-9._/-]{0,62}$/;
12
+ /** A label's value: text of 1 to this many characters, counted as Unicode code points (as JSON Schema's maxLength counts
13
+ * them), never UTF-16 units: an emoji is one character. */
14
+ export const MAX_LABEL_VALUE = 256;
15
+ /** No control character in a value: a label is shown as one line. */
16
+ const CONTROL = /[\u0000-\u001f\u007f]/;
17
+ /** A UTF-16 surrogate standing alone, half of no character (in `u` mode a whole pair is one code point, so only a lone half
18
+ * matches). JSON.stringify keeps one as a `\ud800` escape that Postgres' json check takes but json_each_text cannot
19
+ * decode: kept on a run, it would fail every later label search that scans that run. */
20
+ export const LONE_SURROGATE = /[\ud800-\udfff]/u;
21
+ const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
22
+ /** Why a value is not a label's, or undefined when it is one. */
23
+ function valueProblem(value) {
24
+ if (typeof value !== "string")
25
+ return "is text";
26
+ const characters = [...value].length;
27
+ if (characters < 1 || characters > MAX_LABEL_VALUE)
28
+ return `is text of 1 to ${MAX_LABEL_VALUE} characters`;
29
+ if (CONTROL.test(value))
30
+ return "holds no control character (a newline, a tab, NUL)";
31
+ if (LONE_SURROGATE.test(value))
32
+ return "is whole Unicode characters (no lone UTF-16 surrogate)";
33
+ return undefined;
34
+ }
35
+ /** A create body's `labels`, field by field: an object of at most MAX_LABELS keys, each matching LABEL_KEY, each value text
36
+ * of 1 to MAX_LABEL_VALUE characters with no control character. Absent is none. */
37
+ export function labelsIssues(labels) {
38
+ if (labels === undefined)
39
+ return [];
40
+ if (!isObject(labels))
41
+ return [{ field: "labels", reason: "wrong_type", message: "labels is an object of text values: {\"<key>\": \"<value>\"}" }];
42
+ const issues = [];
43
+ const keys = Object.keys(labels);
44
+ if (keys.length > MAX_LABELS)
45
+ issues.push({ field: "labels", reason: "too_many", message: `labels holds at most ${MAX_LABELS} keys; it holds ${keys.length}.` });
46
+ for (const key of keys) {
47
+ if (!LABEL_KEY.test(key)) {
48
+ issues.push({ field: `labels.${key}`, reason: "bad_format", message: `A label's key is 1 to 63 letters, digits, '.', '_', '-' or '/', starting with a letter or a digit: ${JSON.stringify(key)} is not one.` });
49
+ continue;
50
+ }
51
+ const problem = valueProblem(labels[key]);
52
+ if (problem)
53
+ issues.push({ field: `labels.${key}`, reason: typeof labels[key] === "string" ? "bad_format" : "wrong_type", message: `labels.${key} ${problem}.` });
54
+ }
55
+ return issues;
56
+ }
57
+ /** A create body's labels, once labelsIssues found none: the map as given, or undefined when absent or empty. */
58
+ export function labelsOf(labels) {
59
+ if (!isObject(labels) || Object.keys(labels).length === 0)
60
+ return undefined;
61
+ return Object.fromEntries(Object.entries(labels).map(([key, value]) => [key, String(value)]));
62
+ }
63
+ /** GET /runs' `label` parameter, `<key>:<value>` (split at the first `:`, which a key never holds): the label a run must
64
+ * hold. One per request: the document declares a single string, and a client generated from it sends one, so a second
65
+ * is 400 bad_request rather than read here and dropped by a client. 400 too for one that does not read as a label. */
66
+ export function labelFilter(given) {
67
+ if (given.length === 0)
68
+ return undefined;
69
+ if (given.length > 1)
70
+ throw new ApiError("bad_request", "label is given once: one <key>:<value> per request");
71
+ const one = given[0];
72
+ const at = one.indexOf(":");
73
+ const key = at < 0 ? one : one.slice(0, at);
74
+ const value = at < 0 ? undefined : one.slice(at + 1);
75
+ if (!LABEL_KEY.test(key) || value === undefined || valueProblem(value) !== undefined) {
76
+ throw new ApiError("bad_request", `label is <key>:<value>, a label's key and its value (${JSON.stringify(one)} is not one)`);
77
+ }
78
+ return { [key]: value };
79
+ }
@@ -129,6 +129,8 @@ export declare function readLaunchBody(stored: unknown): RunLaunch | undefined;
129
129
  /** The run's learning start (its given notes, its seed sha and its # Learned section), read from one place by learning's
130
130
  * routes and the runner; undefined when the run does not learn. */
131
131
  export declare const learningStartOf: (launch: RunLaunch) => RunLaunch["learning"];
132
+ /** The same start read from a launch body's `learning` member alone (Store.runs.learningStarts), as readLaunchBody reads it. */
133
+ export declare const learningStartOfStored: (stored: unknown) => RunLaunch["learning"];
132
134
  /** Why a learning run starts with nothing learned, as main says it: its agent's learning folder could not be read
133
135
  * (`unreadable`, STOPPED.unreadable), or what was read could not be made into its start (`not_copied`,
134
136
  * STOPPED.notCopied). */
@@ -134,6 +134,8 @@ export function readLaunchBody(stored) {
134
134
  /** The run's learning start (its given notes, its seed sha and its # Learned section), read from one place by learning's
135
135
  * routes and the runner; undefined when the run does not learn. */
136
136
  export const learningStartOf = (launch) => launch.learning;
137
+ /** The same start read from a launch body's `learning` member alone (Store.runs.learningStarts), as readLaunchBody reads it. */
138
+ export const learningStartOfStored = (stored) => (stored === undefined ? undefined : readLearning(stored) ?? { given: [], seed: null, section: "" });
137
139
  const SEED_FAILURES = ["unreadable", "not_copied"];
138
140
  /** A learning start with no seed (no commit of main, runs-over-store.ts learningStartFor): the run learns nothing, is
139
141
  * never asked what to keep, and so is never told it learns. Why is its `seedFailed`, when its start records one. */