@parcha/agentrun-serve 0.0.0-stage → 0.1.0-beta.30
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.
- package/CHANGELOG.md +748 -0
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +2190 -2
- package/dist/adapters.d.ts +234 -0
- package/dist/adapters.js +585 -0
- package/dist/agents.d.ts +130 -0
- package/dist/agents.js +308 -0
- package/dist/app.d.ts +7 -0
- package/dist/app.js +384 -0
- package/dist/background.d.ts +28 -0
- package/dist/background.js +376 -0
- package/dist/bound-files.d.ts +4 -0
- package/dist/bound-files.js +164 -0
- package/dist/box/record.d.ts +6 -0
- package/dist/box/record.js +41 -0
- package/dist/box/sweep.d.ts +53 -0
- package/dist/box/sweep.js +193 -0
- package/dist/box-egress.d.ts +98 -0
- package/dist/box-egress.js +259 -0
- package/dist/box-image.d.ts +98 -0
- package/dist/box-image.js +285 -0
- package/dist/box-relay-vm.d.ts +80 -0
- package/dist/box-relay-vm.js +389 -0
- package/dist/box-relay.d.ts +45 -0
- package/dist/box-relay.js +227 -0
- package/dist/boxes.d.ts +72 -0
- package/dist/boxes.js +189 -0
- package/dist/browser-cost.d.ts +41 -0
- package/dist/browser-cost.js +158 -0
- package/dist/cap.d.ts +332 -0
- package/dist/cap.js +992 -0
- package/dist/catalog.d.ts +20 -0
- package/dist/catalog.js +53 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +167 -0
- package/dist/coding-tools.d.ts +35 -0
- package/dist/coding-tools.js +87 -0
- package/dist/console/THIRD-PARTY-NOTICES.txt +1721 -0
- package/dist/console/assets/index-34jfpIbQ.js +481 -0
- package/dist/console/assets/index-DUHbWcIP.css +1 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-CIEtRijs.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-BB5xRk30.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-EVf6-Yzo.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-BHyURHCj.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-C_uLvvQ5.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-Dj6eZy5f.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-DpeVePZf.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-greek-400-normal-CNojz0t3.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-600-normal-3KAm9r92.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-600-normal-H7WoG9Et.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-400-normal-B11XCQ5g.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-600-normal-DXv3JcnD.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-DHMOLxAi.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-BfB_LPfz.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-DiQlUoE6.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-BeU3T8wf.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-ByoDsISC.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-CSpzN4cI.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-Dtizs43-.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-400-normal-Cph9ettZ.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-400-normal-DfGZKnlb.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-600-normal-BGBUNdzT.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-600-normal-COje25QW.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-4l4lq8zr.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-BGzXWJeR.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-8_E36CQj.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-C27an7Zc.woff +0 -0
- package/dist/console/index.html +15 -0
- package/dist/content-filter.d.ts +7 -0
- package/dist/content-filter.js +23 -0
- package/dist/daytona-api.d.ts +21 -0
- package/dist/daytona-api.js +101 -0
- package/dist/decision-rows.d.ts +19 -0
- package/dist/decision-rows.js +123 -0
- package/dist/decisions.d.ts +94 -0
- package/dist/decisions.js +184 -0
- package/dist/effort-guidance.d.ts +5 -0
- package/dist/effort-guidance.js +14 -0
- package/dist/environment.d.ts +5 -0
- package/dist/environment.js +11 -0
- package/dist/errors.d.ts +74 -0
- package/dist/errors.js +69 -0
- package/dist/exa-keyless.d.ts +35 -0
- package/dist/exa-keyless.js +202 -0
- package/dist/fetch-page.d.ts +114 -0
- package/dist/fetch-page.js +182 -0
- package/dist/files.d.ts +65 -0
- package/dist/files.js +158 -0
- package/dist/grade.d.ts +93 -0
- package/dist/grade.js +328 -0
- package/dist/graph-served.d.ts +23 -0
- package/dist/graph-served.js +75 -0
- package/dist/graph-view.d.ts +102 -0
- package/dist/graph-view.js +219 -0
- package/dist/harness-app.d.ts +40 -0
- package/dist/harness-app.js +708 -0
- package/dist/harness-opencode/adapter.d.ts +45 -0
- package/dist/harness-opencode/adapter.js +272 -0
- package/dist/harness-opencode/binary.d.ts +18 -0
- package/dist/harness-opencode/binary.js +87 -0
- package/dist/harness-opencode/config.d.ts +24 -0
- package/dist/harness-opencode/config.js +61 -0
- package/dist/harness-opencode/harness.d.ts +77 -0
- package/dist/harness-opencode/harness.js +620 -0
- package/dist/harness-opencode/host/mcp.d.ts +40 -0
- package/dist/harness-opencode/host/mcp.js +208 -0
- package/dist/harness-opencode/host/policy.d.ts +71 -0
- package/dist/harness-opencode/host/policy.js +419 -0
- package/dist/harness-opencode/host/server.d.ts +55 -0
- package/dist/harness-opencode/host/server.js +165 -0
- package/dist/harness-opencode/index.d.ts +9 -0
- package/dist/harness-opencode/index.js +6 -0
- package/dist/harness-opencode/verify.d.ts +32 -0
- package/dist/harness-opencode/verify.js +75 -0
- package/dist/harness-opencode/versions.d.ts +33 -0
- package/dist/harness-opencode/versions.js +64 -0
- package/dist/harness.d.ts +56 -0
- package/dist/harness.js +77 -0
- package/dist/home-path.d.ts +27 -0
- package/dist/home-path.js +78 -0
- package/dist/host-tools.d.ts +30 -0
- package/dist/host-tools.js +154 -0
- package/dist/host.d.ts +39 -0
- package/dist/host.js +85 -0
- package/dist/hosted-search.d.ts +27 -0
- package/dist/hosted-search.js +133 -0
- package/dist/import-sources.d.ts +104 -0
- package/dist/import-sources.js +629 -0
- package/dist/import-summary.d.ts +25 -0
- package/dist/import-summary.js +75 -0
- package/dist/import-worker.d.ts +26 -0
- package/dist/import-worker.js +41 -0
- package/dist/import.d.ts +145 -0
- package/dist/import.js +1222 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +6 -0
- package/dist/key-check.d.ts +37 -0
- package/dist/key-check.js +112 -0
- package/dist/key-refusal.d.ts +51 -0
- package/dist/key-refusal.js +191 -0
- package/dist/learn/check.d.ts +108 -0
- package/dist/learn/check.js +277 -0
- package/dist/learn/grade.d.ts +80 -0
- package/dist/learn/grade.js +445 -0
- package/dist/learn/index.d.ts +7 -0
- package/dist/learn/index.js +11 -0
- package/dist/learn/invisible.d.ts +5 -0
- package/dist/learn/invisible.js +42 -0
- package/dist/learn/notes.d.ts +59 -0
- package/dist/learn/notes.js +147 -0
- package/dist/learn/reflect.d.ts +49 -0
- package/dist/learn/reflect.js +213 -0
- package/dist/learn/secrets.d.ts +18 -0
- package/dist/learn/secrets.js +131 -0
- package/dist/learn/skills.d.ts +97 -0
- package/dist/learn/skills.js +271 -0
- package/dist/learned-workflow.d.ts +59 -0
- package/dist/learned-workflow.js +191 -0
- package/dist/learning-routes.d.ts +196 -0
- package/dist/learning-routes.js +609 -0
- package/dist/learning-run.d.ts +306 -0
- package/dist/learning-run.js +819 -0
- package/dist/learning-words.d.ts +76 -0
- package/dist/learning-words.js +174 -0
- package/dist/learning.d.ts +418 -0
- package/dist/learning.js +946 -0
- package/dist/llm.d.ts +40 -0
- package/dist/llm.js +37 -0
- package/dist/llms.txt +37 -0
- package/dist/mcp-servers.d.ts +118 -0
- package/dist/mcp-servers.js +450 -0
- package/dist/mcp.d.ts +51 -0
- package/dist/mcp.js +392 -0
- package/dist/model.d.ts +186 -0
- package/dist/model.js +485 -0
- package/dist/monid.d.ts +74 -0
- package/dist/monid.js +277 -0
- package/dist/openapi/agentrun-v2.openapi.json +4806 -0
- package/dist/openapi.d.ts +10 -0
- package/dist/openapi.js +1727 -0
- package/dist/owner.d.ts +55 -0
- package/dist/owner.js +222 -0
- package/dist/packs.d.ts +71 -0
- package/dist/packs.js +180 -0
- package/dist/page.d.ts +32 -0
- package/dist/page.js +133 -0
- package/dist/paid-calls.d.ts +50 -0
- package/dist/paid-calls.js +110 -0
- package/dist/pause.d.ts +70 -0
- package/dist/pause.js +97 -0
- package/dist/pdf-pages.d.ts +44 -0
- package/dist/pdf-pages.js +147 -0
- package/dist/place.d.ts +69 -0
- package/dist/place.js +137 -0
- package/dist/print.d.ts +20 -0
- package/dist/print.js +29 -0
- package/dist/propose.d.ts +40 -0
- package/dist/propose.js +112 -0
- package/dist/quiet-sqlite-warning.d.ts +1 -0
- package/dist/quiet-sqlite-warning.js +14 -0
- package/dist/request-start.d.ts +22 -0
- package/dist/request-start.js +350 -0
- package/dist/result.d.ts +3 -0
- package/dist/result.js +5 -0
- package/dist/rows.d.ts +46 -0
- package/dist/rows.js +121 -0
- package/dist/run-box.d.ts +186 -0
- package/dist/run-box.js +590 -0
- package/dist/run-manifest.d.ts +27 -0
- package/dist/run-manifest.js +60 -0
- package/dist/runnable.d.ts +83 -0
- package/dist/runnable.js +170 -0
- package/dist/runs.d.ts +1062 -0
- package/dist/runs.js +3020 -0
- package/dist/secret-cut.d.ts +27 -0
- package/dist/secret-cut.js +109 -0
- package/dist/secrets.d.ts +62 -0
- package/dist/secrets.js +158 -0
- package/dist/server-lock.d.ts +44 -0
- package/dist/server-lock.js +140 -0
- package/dist/server.d.ts +722 -0
- package/dist/server.js +2118 -0
- package/dist/sessions.d.ts +4 -0
- package/dist/sessions.js +105 -0
- package/dist/sign-ins.d.ts +99 -0
- package/dist/sign-ins.js +288 -0
- package/dist/skills.d.ts +43 -0
- package/dist/skills.js +96 -0
- package/dist/stats.d.ts +106 -0
- package/dist/stats.js +103 -0
- package/dist/tool-gate.d.ts +266 -0
- package/dist/tool-gate.js +554 -0
- package/dist/tool-keys.d.ts +187 -0
- package/dist/tool-keys.js +315 -0
- package/dist/tool-plane.d.ts +228 -0
- package/dist/tool-plane.js +400 -0
- package/dist/tools.d.ts +202 -0
- package/dist/tools.js +372 -0
- package/dist/trigger-secrets.d.ts +32 -0
- package/dist/trigger-secrets.js +143 -0
- package/dist/triggers.d.ts +439 -0
- package/dist/triggers.js +863 -0
- package/dist/turn-end.d.ts +24 -0
- package/dist/turn-end.js +15 -0
- package/dist/turns.d.ts +34 -0
- package/dist/turns.js +202 -0
- package/dist/uploads.d.ts +104 -0
- package/dist/uploads.js +474 -0
- package/dist/usage-lines.d.ts +26 -0
- package/dist/usage-lines.js +28 -0
- package/dist/usage.d.ts +29 -0
- package/dist/usage.js +58 -0
- package/dist/validate.d.ts +57 -0
- package/dist/validate.js +184 -0
- package/dist/web-fetch.d.ts +64 -0
- package/dist/web-fetch.js +262 -0
- package/dist/web-search.d.ts +54 -0
- package/dist/web-search.js +136 -0
- package/dist/webhooks.d.ts +189 -0
- package/dist/webhooks.js +503 -0
- package/dist/workspace-paths.d.ts +33 -0
- package/dist/workspace-paths.js +104 -0
- package/dist/workspace.d.ts +88 -0
- package/dist/workspace.js +369 -0
- package/launcher/agentrun-serve +109 -0
- package/package.json +100 -4
- package/skills/agentrun-serve/SKILL.md +128 -0
package/dist/openapi.js
ADDED
|
@@ -0,0 +1,1727 @@
|
|
|
1
|
+
// The OpenAPI document this server serves at GET /v2/openapi.json: the agentrun.v2/0 contract as vendored in
|
|
2
|
+
// src/openapi/agentrun-v2.openapi.json (its source is in its info), with this server's marks. The contract's operations are
|
|
3
|
+
// not changed: an operation answered 501 here carries `x-agentrun-serve-unsupported` with the reason, and this server's
|
|
4
|
+
// own routes are added as operations marked `x-agentrun-serve` (true, or the addition that made it, as `stats/1`), listed
|
|
5
|
+
// in `info.x-agentrun-serve`.
|
|
6
|
+
import { readFileSync } from "node:fs";
|
|
7
|
+
import { NOTE_ORIGINS, NOTE_STATUSES, NOTE_TYPES } from "./learn/index.js";
|
|
8
|
+
import { ERROR_STATUS } from "./errors.js";
|
|
9
|
+
import { LAUNCH_LOST, SETUP_LOST } from "./files.js";
|
|
10
|
+
import { HARNESSES } from "./harness.js";
|
|
11
|
+
import { LEARNING_LABEL, LEARNING_MODES, LEARNING_REASONS, LEARNING_STATES } from "./learning.js";
|
|
12
|
+
import { MODEL_SOURCES, THINKING_LEVELS } from "./model.js";
|
|
13
|
+
import { BOX_IDS, BOX_NETWORKS, BOX_STATES } from "./boxes.js";
|
|
14
|
+
import { PLACE_MODES } from "./place.js";
|
|
15
|
+
import { TOOL_KEYS, UNREADABLE } from "./tool-keys.js";
|
|
16
|
+
import { MCP_AUTH_TYPES, MCP_SERVER_NAME } from "./mcp-servers.js";
|
|
17
|
+
import { ATTEMPTS_KEPT, MESSAGE_TYPES, WEBHOOK_EVENTS } from "./webhooks.js";
|
|
18
|
+
import { HOOK_TOLERANCE_S } from "./trigger-secrets.js";
|
|
19
|
+
import { CATCHUP_WINDOW_S, DUE_KEPT, FAILURES_TO_PAUSE, FIRING_STATUSES, PAYLOAD_KEPT_BYTES, HISTORY_KEPT, MAX_EVERY_S, MIN_EVERY_S, OVERLAP, SOURCE_KINDS, TARGET_KINDS } from "./triggers.js";
|
|
20
|
+
import { DEFINITION_FIELDS, NOT_KEPT } from "./validate.js";
|
|
21
|
+
import { APPROVAL_ROW, ARGS_PREVIEW_BYTES, PERMISSIONS } from "./tool-gate.js";
|
|
22
|
+
import { LEGACY_NAMES, permissionsOf, PICKABLE, PROVIDERS, TABLE_TOOLS } from "./tool-plane.js";
|
|
23
|
+
/** Why each capability this server turns off answers 501, by the route's capability. */
|
|
24
|
+
export const UNSUPPORTED = {
|
|
25
|
+
"home.export": "This server does not export a home yet.",
|
|
26
|
+
"home.import": "This server does not import a home yet.",
|
|
27
|
+
"runs.kill": "This server does not kill a run's process yet.",
|
|
28
|
+
quotes: "This server has no billing, so it gives no quotes.",
|
|
29
|
+
};
|
|
30
|
+
const ref = (name) => ({ $ref: `#/components/${name}` });
|
|
31
|
+
const errors = (...codes) => Object.fromEntries(codes.map((code) => [String(code), ref(`responses/${{ 400: "BadRequest", 401: "Unauthenticated", 403: "Forbidden", 404: "NotFound", 409: "Conflict", 412: "PreconditionFailed", 413: "PayloadTooLarge", 415: "UnsupportedMediaType", 422: "Unprocessable", 429: "RateLimited", 500: "Internal", 501: "Unsupported", 503: "Unavailable" }[code]}`)]));
|
|
32
|
+
const json = (schema, description) => ({ description, content: { "application/json": { schema } } });
|
|
33
|
+
/** GET /health's answer (host.ts Health). */
|
|
34
|
+
const HEALTH = {
|
|
35
|
+
type: "object", additionalProperties: false, required: ["status", "checks"],
|
|
36
|
+
properties: {
|
|
37
|
+
status: { enum: ["ok", "failing"] },
|
|
38
|
+
checks: { type: "object", additionalProperties: false, required: ["store", "disk"], properties: { store: { enum: ["ok", "does_not_open"] }, disk: { enum: ["ok", "below_floor", "cannot_check"] } } },
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
const COUNT = { type: "integer", minimum: 0 };
|
|
42
|
+
const closed = (properties, description) => ({ type: "object", additionalProperties: false, required: Object.keys(properties), properties, ...(description ? { description } : {}) });
|
|
43
|
+
const USD = { type: ["number", "null"], minimum: 0, description: "The sum of the known costs, rounded to 1e-6; null when no run's cost is known, never 0 for unknown." };
|
|
44
|
+
/** Runs counted together (AgentStoreReader.analytics's AnalyticsGroup). */
|
|
45
|
+
const GROUP = {
|
|
46
|
+
runs: COUNT, completed: { ...COUNT, description: "Completed, escalated runs included: one completed and waits for a person's review." },
|
|
47
|
+
needs_review: { ...COUNT, description: "Of `completed`, the escalated runs, which wait for a person's review.", "x-agentrun-serve": "stats/3" },
|
|
48
|
+
failed: { ...COUNT, description: "Failed: never an escalated run." },
|
|
49
|
+
runs_with_metrics: { ...COUNT, description: "Of `runs`, those that ended with metrics: a running run, and a run whose end wrote none, has none." },
|
|
50
|
+
tokens: { ...COUNT, description: "Input, cache read, cache write and output tokens, summed over `runs_with_metrics`." },
|
|
51
|
+
cost_usd: USD, unknown_cost_runs: { ...COUNT, description: "Runs with no known cost: running, or ended without one." },
|
|
52
|
+
};
|
|
53
|
+
/** GET /stats's `analytics` (stats.ts analyticsView). */
|
|
54
|
+
const ANALYTICS = closed({
|
|
55
|
+
filter: closed({ from: { type: ["string", "null"], format: "date-time" }, to: { type: ["string", "null"], format: "date-time" }, agent: { type: ["string", "null"] } }, "The query's bounds, each null when not given: runs started at or after `from` and before `to`, of `agent`."),
|
|
56
|
+
totals: closed({
|
|
57
|
+
...GROUP, input: COUNT, cache_read: COUNT, cache_write: COUNT, output: COUNT,
|
|
58
|
+
requests: { ...COUNT, description: "Model requests." }, unmetered: { ...COUNT, description: "Of `requests`, those whose tokens are unknown: in no token sum." },
|
|
59
|
+
}, "Over every run the filter picks. `input` excludes cached input: the whole input is `input + cache_read + cache_write`."),
|
|
60
|
+
time: closed({ ended_runs: COUNT, wall_ms: { ...COUNT, description: "Ended minus started, summed over `ended_runs`." }, active_runs: COUNT, active_ms: { ...COUNT, description: "How long the runs were at work, summed over the `active_runs` whose metrics say." } }),
|
|
61
|
+
by_harness_effort: { type: "array", description: "By the revision's harness (`pi` when it names none, `workflow` for a workflow revision), then the effort the run's metrics name (null: unset, or no metrics).", items: closed({ harness: { type: "string" }, effort: { type: ["string", "null"] }, ...GROUP }) },
|
|
62
|
+
by_day: { type: "array", description: "By the UTC date the run started, oldest first.", items: closed({ day: { type: "string", format: "date" }, ...GROUP }) },
|
|
63
|
+
by_source: { type: "array", description: "`live`, run here, first, then each source runs were imported from.", items: closed({ source: { enum: ["live", "claude-code", "codex", "pi"] }, ...GROUP }) },
|
|
64
|
+
tools: { type: "array", maxItems: 20, description: "The 20 tools with the most calls, by name on a tie; `errors` counts the calls that failed (an error, a result the tool reads as failed such as a refused fetch, or no result at all).", items: closed({ tool: { type: "string", description: "The name the tool was called by." }, label: { type: "string", description: "What a person calls the tool, from the timeline's label registry; the name it was called by when it has none.", "x-agentrun-serve": "stats/3" }, calls: COUNT, errors: COUNT }) },
|
|
65
|
+
}, "The runs' tokens, requests, time and tool calls from their metrics, over the runs not archived that the query picks; a run with no metrics counts in `runs` alone.");
|
|
66
|
+
/** GET /stats's answer (stats.ts). */
|
|
67
|
+
const STATS = closed({
|
|
68
|
+
agents: { ...COUNT, description: "Agents not archived." },
|
|
69
|
+
runs: closed({ total: COUNT, active: COUNT, needs_input: COUNT, failed: COUNT, needs_review: { ...COUNT, "x-agentrun-serve": "stats/3" }, status_unknown: COUNT }, "Runs not archived. `total` counts them all; a completed or cancelled run is counted in `total` alone, but for an escalated one, which completed and waits for a person's review: it is in `needs_review`, never in `failed`. Each running run is in exactly one of `active` (this server holds it, queued, working or paused), `needs_input` (it holds it, input_required) and `status_unknown` (it does not hold it, or holds it as ended before its end is written)."),
|
|
70
|
+
per_agent: {
|
|
71
|
+
type: "array", description: "Each agent not archived, by name then id, with how many of its runs are not archived; an agent with no runs is listed with 0.",
|
|
72
|
+
items: closed({ agent_id: ref("schemas/Id"), name: { type: "string" }, runs: COUNT }),
|
|
73
|
+
},
|
|
74
|
+
cost: closed({
|
|
75
|
+
usd: { type: ["number", "null"], minimum: 0, description: "The sum of the known costs, rounded to 1e-6; null when no run's cost is known, never 0 for unknown." },
|
|
76
|
+
basis: { type: ["string", "null"], enum: ["estimate", null], description: "`estimate` (what the runs report: their model requests' cost and their paid tools' charges) when `usd` is a number; null when it is null." },
|
|
77
|
+
unknown_runs: COUNT,
|
|
78
|
+
}, "Over the runs not archived: `usd` sums the cost of each run that ended with one; every other run (running, or ended with no cost) is in `unknown_runs`."),
|
|
79
|
+
archived: closed({ agents: COUNT, runs: COUNT }, "Agents archived, and runs archived or of an archived agent: counted here and in nothing else."),
|
|
80
|
+
analytics: { ...ANALYTICS, "x-agentrun-serve": "stats/2" },
|
|
81
|
+
learning: {
|
|
82
|
+
...closed({
|
|
83
|
+
runs: { ...COUNT, description: "Runs that tried to learn: each with a `learning` block. A run with learning off, a workflow's or an imported one has none." },
|
|
84
|
+
merged: COUNT,
|
|
85
|
+
dropped: { type: "object", additionalProperties: COUNT, propertyNames: { enum: [...LEARNING_REASONS] }, description: "The dropped runs, by reason (Run.learning.reason): only reasons with one run or more." },
|
|
86
|
+
in_progress: { ...COUNT, description: "Seeded, reflecting or proposed: runs this server holds." },
|
|
87
|
+
}, "How the runs that tried to learn fared, over the runs not archived that `from`, `to` and `agent` pick, as `analytics` counts them."),
|
|
88
|
+
"x-agentrun-serve": "learning/1",
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
const NODE_STATUS = { enum: ["pending", "working", "done", "failed", "stopped", "escalated", "not_run", "needs_review"] };
|
|
92
|
+
const nullable = (type) => ({ type: [type, "null"] });
|
|
93
|
+
/** GET /runs/{run_id}/graph's answer (graph-view.ts). */
|
|
94
|
+
const RUN_GRAPH = {
|
|
95
|
+
type: "object", additionalProperties: false, required: ["run", "workflow", "graph", "nodes", "decisions", "effects", "totals", "stale", "read_at"],
|
|
96
|
+
properties: {
|
|
97
|
+
read_at: { type: "string", format: "date-time", description: "When the view shown was read: the run process's last live view while it goes, else the read itself." },
|
|
98
|
+
stale: { type: "boolean", description: "True when the run's store was busy and this is the last view read whole: the next poll reads it again. A poll never answers home_busy." },
|
|
99
|
+
run: {
|
|
100
|
+
type: "object", additionalProperties: false, required: ["id", "agent", "revision", "status", "paused", "startedAt", "endedAt"],
|
|
101
|
+
properties: { id: { type: "string" }, agent: { type: "string" }, revision: { type: "string" }, status: ref("schemas/RunStatus"), paused: { type: "boolean" }, startedAt: { type: "string", format: "date-time" }, endedAt: { type: ["string", "null"], format: "date-time" } },
|
|
102
|
+
},
|
|
103
|
+
workflow: { type: "object", description: "The revision's workflow definition." },
|
|
104
|
+
graph: { type: "object", required: ["nodes", "edges"], description: "The DSL's workflowGraph of the definition: nodes { path, kind, label, via?, changeCheck } and edges { from, to, kind }." },
|
|
105
|
+
nodes: {
|
|
106
|
+
type: "object", description: "Each graph node's state, by its path.",
|
|
107
|
+
additionalProperties: {
|
|
108
|
+
type: "object", additionalProperties: false, required: ["status"],
|
|
109
|
+
properties: {
|
|
110
|
+
status: NODE_STATUS, startedAt: { type: "string", format: "date-time" }, endedAt: { type: "string", format: "date-time" },
|
|
111
|
+
branch: { type: "string", description: "A route's branch taken." },
|
|
112
|
+
items: { type: "array", description: "A map's items, one per item of its list.", items: { type: "object", additionalProperties: false, required: ["index", "status", "executionPath"], properties: { index: { type: "integer" }, status: NODE_STATUS, executionPath: { type: "string" }, label: { type: "string" }, branches: { type: "object", additionalProperties: { type: "string" }, description: "Each route in the map's body that ran for this item (by graph path) and the branch it took." } } } },
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
decisions: {
|
|
117
|
+
type: "array", description: "Each decision receipt, joined to its graph node by its execution path.",
|
|
118
|
+
items: {
|
|
119
|
+
type: "object", additionalProperties: false,
|
|
120
|
+
required: ["id", "node", "executionPath", "item", "kind", "provider", "model", "status", "questions", "answers", "evidence", "rule", "action", "cost_usd", "cost_basis", "latency_ms", "state", "state_truncated", "images", "error"],
|
|
121
|
+
properties: {
|
|
122
|
+
id: nullable("string"), node: nullable("string"), executionPath: nullable("string"), item: nullable("integer"), kind: nullable("string"), provider: nullable("string"), model: nullable("string"), status: nullable("string"),
|
|
123
|
+
questions: {}, answers: {}, evidence: { type: "array" }, rule: {}, action: {}, cost_usd: nullable("number"), cost_basis: nullable("string"), latency_ms: nullable("number"),
|
|
124
|
+
state: { description: "The state the judge saw, when the receipt kept it." }, state_truncated: { type: "boolean" }, error: { type: ["string", "null"], description: "A failed or cancelled request's reason." },
|
|
125
|
+
images: { type: "array", items: { type: "object", additionalProperties: false, required: ["token", "ref", "url"], properties: { token: nullable("string"), ref: nullable("string"), url: nullable("string") } } },
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
effects: {
|
|
130
|
+
type: "array", description: "Each call node's call: its input and output, in the order they started.",
|
|
131
|
+
items: {
|
|
132
|
+
type: "object", additionalProperties: false, required: ["node", "executionPath", "item", "tool", "status", "input", "output", "error", "startedAt", "endedAt"],
|
|
133
|
+
properties: { node: nullable("string"), executionPath: nullable("string"), item: nullable("integer"), tool: { type: "string" }, status: { enum: ["working", "done", "failed", "stopped"] }, input: {}, output: {}, error: nullable("string"), startedAt: { type: "string", format: "date-time" }, endedAt: { type: ["string", "null"], format: "date-time" } },
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
totals: {
|
|
137
|
+
type: "object", additionalProperties: false, required: ["cost_usd", "decisions", "effects", "elapsed_ms"],
|
|
138
|
+
properties: { cost_usd: { type: ["number", "null"], description: "Null when any part is unknown." }, decisions: { type: "integer" }, effects: { type: "integer" }, elapsed_ms: { type: ["integer", "null"] } },
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
/** POST /workflows/validate's answer: the DSL's validateWorkflow (code not run), and what a save would refuse. */
|
|
143
|
+
const VALIDATED = {
|
|
144
|
+
type: "object", additionalProperties: false, required: ["ok", "issues", "warnings"],
|
|
145
|
+
properties: {
|
|
146
|
+
ok: { type: "boolean" },
|
|
147
|
+
issues: { type: "array", items: { type: "object", additionalProperties: false, required: ["path", "code", "message"], properties: { path: { type: "string", description: "A JSON Pointer into the workflow; empty for its root." }, code: { type: "string" }, message: { type: "string" } } } },
|
|
148
|
+
warnings: { type: "array", items: { type: "string" } },
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
/** GET /settings/tool-keys's answer (tool-keys.ts): each key's fields by name and where each is set, never a value. */
|
|
152
|
+
const TOOL_KEYS_VIEW = closed({
|
|
153
|
+
keys: {
|
|
154
|
+
type: "array",
|
|
155
|
+
items: closed({
|
|
156
|
+
id: { enum: TOOL_KEYS.map((row) => row.id) }, kind: { enum: ["tool", "model"], description: "`tool`: it unlocks tools, and reaches only the runs that name one; `model`: a model provider's key, which every run gets, and which gives the default model when the host names none (`capabilities.models`)." }, label: { type: "string" },
|
|
157
|
+
unlocks: { type: "array", items: { type: "string" }, description: "What the key unlocks on this server: tools capabilities' `tools` lists, and `decisions.<id>` for a provider its `workflows.decisions.providers` lists. Empty when the key unlocks nothing this server binds." },
|
|
158
|
+
harnesses: { type: "array", items: { enum: [...HARNESSES] }, description: "The harnesses that run the tools in `unlocks`: the union of their `harnesses` in capabilities' `tools`. A `model` key's: pi and the provider's own harness (OpenRouter's, all three), of those capabilities' `harnesses` say this server runs or would run once the key is set: one unavailable only for want of a model key is listed before the key is saved." },
|
|
159
|
+
fields: {
|
|
160
|
+
type: "array",
|
|
161
|
+
items: {
|
|
162
|
+
type: "object", additionalProperties: false, required: ["name", "set", "source"],
|
|
163
|
+
properties: {
|
|
164
|
+
name: { type: "string" }, set: { type: "boolean" },
|
|
165
|
+
source: { enum: ["server", "stored", null], description: "`server`: the server is started with it (its launcher), and that one wins; `stored`: saved here, sealed; null: neither." },
|
|
166
|
+
stored_unreadable: { type: "boolean", const: true, description: "A value is stored for it that does not open here: `reenter` says why." },
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
check: {
|
|
171
|
+
oneOf: [
|
|
172
|
+
closed({ state: { const: "accepted" }, at: { type: "string", format: "date-time", description: "When it was saved and checked; the server's own key, when the server started and checked it." } }),
|
|
173
|
+
closed({ state: { const: "refused" }, reason: { type: "string", description: "The server's own key only (a saved one the provider refuses is never kept): who refused which key, in the provider's first sentence (never any of the key), and what to do. The tools that need it read unavailable in capabilities, with the same words." }, at: { type: "string", format: "date-time", description: "When the server started and checked it." } }),
|
|
174
|
+
{
|
|
175
|
+
type: "object", additionalProperties: false, required: ["state", "reason"],
|
|
176
|
+
properties: {
|
|
177
|
+
state: { const: "not_checked" },
|
|
178
|
+
reason: { type: "string", description: "Why, in plain words: the provider would not answer the check (403: the key may still work for its tools), did not answer in 5 s, could not be reached, answered a redirect (never followed, so the key goes nowhere else), or answered neither yes nor no (its status and first sentence); it has no call that costs nothing to check a key with; or the key was saved before this server checked keys." },
|
|
179
|
+
at: { type: "string", format: "date-time", description: "When it was saved. Absent for a key saved before this server checked keys." },
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
{ type: "null" },
|
|
183
|
+
],
|
|
184
|
+
description: "Whether the key (its first field) was checked against its provider, with one call that costs nothing: a key stored here when it was saved (`accepted`, or `not_checked` and why; a key the provider refuses is never saved, PUT's 422), a tool's key the server is started with once as it starts (`accepted`, `not_checked`, or `refused`). Null when the key is not set, or is the server's and its check has not answered yet.",
|
|
185
|
+
},
|
|
186
|
+
}),
|
|
187
|
+
},
|
|
188
|
+
reenter: {
|
|
189
|
+
oneOf: [closed({ reason: { enum: [...UNREADABLE] }, fields: { type: "array", items: { type: "string" } } }), { type: "null" }],
|
|
190
|
+
description: "The stored values that do not open here, to be entered again (a PUT seals them under the current key), and why: `seal_key_missing` (the server was handed no seal key), `seal_key_changed` (sealed under another), `file_unreadable` (damaged; `fields` is empty when the file as a whole does not read). Null when every stored value opens.",
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
const KEY_ID = { name: "key_id", in: "path", required: true, description: "The tool key: one of GET /settings/tool-keys' ids.", schema: { type: "string" } };
|
|
194
|
+
/** A remote MCP server's tools as it listed them (mcp-servers.ts), and the server as saved: never its credential. */
|
|
195
|
+
const MCP_TOOL = {
|
|
196
|
+
type: "object", additionalProperties: false, required: ["name", "input_schema"],
|
|
197
|
+
properties: {
|
|
198
|
+
name: { type: "string" }, title: { type: "string" }, description: { type: "string" },
|
|
199
|
+
input_schema: { type: "object", description: "The JSON Schema of the tool's arguments, as the server gave it." },
|
|
200
|
+
output_schema: { type: "object", description: "The JSON Schema of its structured result, when the server gives one." },
|
|
201
|
+
annotations: { type: "object", description: "The server's own claims about the tool (read-only, destructive, and so on): the server's word, not checked." },
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
const MCP_LISTING = {
|
|
205
|
+
protocol: { type: "string", description: "The MCP revision agreed: `2026-07-28` with a server that speaks it, else the 2025-era revision its `initialize` agreed." },
|
|
206
|
+
server_info: { type: ["object", "null"], description: "The server's name and version, as it gave them." },
|
|
207
|
+
instructions: { type: "string", description: "The server's instructions for its client, when it gives any." },
|
|
208
|
+
tools: { type: "array", items: MCP_TOOL, description: "Every tool it lists, all pages." },
|
|
209
|
+
};
|
|
210
|
+
const MCP_PREVIEW = { type: "object", additionalProperties: false, required: ["protocol", "server_info", "tools"], properties: MCP_LISTING };
|
|
211
|
+
const MCP_SERVER_VIEW = {
|
|
212
|
+
type: "object", additionalProperties: false, required: ["name", "url", "auth", "credential", "protocol", "server_info", "tools", "listed_at", "updated_at"],
|
|
213
|
+
properties: {
|
|
214
|
+
name: { type: "string" }, url: { type: "string", format: "uri" },
|
|
215
|
+
auth: { type: "object", additionalProperties: false, required: ["type"], properties: { type: { enum: [...MCP_AUTH_TYPES] }, headers: { type: "array", items: { type: "string" }, description: "For `headers`: the names of the headers kept (lowercase), never a value." } } },
|
|
216
|
+
credential: { enum: ["sealed", "seal_key_missing", "unreadable", null], description: "`sealed`: kept sealed and opens here; `seal_key_missing`: the server was handed no seal key, so it does not open; `unreadable`: sealed under another seal key, or damaged: a PUT with the credential seals it again. Null for `auth.type` none. Never a value." },
|
|
217
|
+
...MCP_LISTING,
|
|
218
|
+
listed_at: { type: "string", format: "date-time", description: "When its tools were last listed (a PUT or a refresh)." },
|
|
219
|
+
updated_at: { type: "string", format: "date-time", description: "When it was last saved." },
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
const MCP_AUTH = {
|
|
223
|
+
type: "object", additionalProperties: false, required: ["type"],
|
|
224
|
+
properties: {
|
|
225
|
+
type: { enum: [...MCP_AUTH_TYPES, "oauth"], description: `\`none\`; \`bearer\` (\`token\`, sent as \`Authorization: Bearer <token>\`); \`headers\` (each named header and its value). \`oauth\` is refused: 422 input_invalid, reason not_yet.` },
|
|
226
|
+
token: { type: "string", minLength: 1, maxLength: 8192 },
|
|
227
|
+
headers: { type: "object", minProperties: 1, maxProperties: 8, additionalProperties: { type: "string", minLength: 1, maxLength: 8192 }, description: "Header names a credential may go in: not Host, Content-Type, Accept, Content-Length, Connection, Transfer-Encoding, Last-Event-ID or an Mcp- header the transport sets." },
|
|
228
|
+
},
|
|
229
|
+
description: "Absent: none. A PUT that sends no `token` (no `headers`) keeps the sealed credential, when the type and the URL's origin are unchanged.",
|
|
230
|
+
};
|
|
231
|
+
const MCP_URL = { type: "string", format: "uri", maxLength: 2048, description: "The server's Streamable HTTP endpoint: https, or http on a loopback address of this machine; no user or password." };
|
|
232
|
+
const MCP_NAME = { name: "name", in: "path", required: true, description: "The server's name: lowercase letters, digits and dashes, starting with a letter, at most 32 (no underscores, so `mcp__<server>__<tool>` splits one way). `hands` and `monid` are reserved for AgentRun's own tools: a PUT under either is 422 input_invalid, field `name`, reason `reserved`.", schema: { type: "string", pattern: MCP_SERVER_NAME.source } };
|
|
233
|
+
const MCP_FAILED = {
|
|
234
|
+
"424": { description: "`upstream_failed`: the MCP server could not be reached, did not answer within 15 s (30 s for the whole listing), answered 5xx or more than 4 MiB at once, or failed to list its tools. `details.status` holds its HTTP status when it answered one.", content: { "application/json": { schema: ref("schemas/Error") } } },
|
|
235
|
+
};
|
|
236
|
+
const MCP_CONNECTS = "Connects with the official MCP SDK client: `server/discover` (2026-07-28) first, a 2025-era server by its `initialize`; then `tools/list`, every page. No redirect is followed: a 3xx is 422 input_invalid (field `url`, reason `redirect`, naming where it points), so a credential goes only where it is sent. A server that asks for a credential (401 or 403) is 422 `auth_required`, `details.auth` `oauth` when it names protected-resource metadata (its WWW-Authenticate or `/.well-known/oauth-protected-resource`), else `bearer`; a URL whose answers hold no JSON-RPC reply is 422 `not_mcp`; a server listing more than 500 tools, or more than 1 MiB of them (names, descriptions, schemas), is 422 input_invalid (field `url`, reason `too_many_tools` or `tools_too_large`), the listing stopped at that page; any other failure is 424.";
|
|
237
|
+
/** A tool's permission (tool-gate.ts). */
|
|
238
|
+
const PERMISSION = {
|
|
239
|
+
enum: [...PERMISSIONS],
|
|
240
|
+
description: "What the tool gate does with each call a model makes: allow runs it; ask parks the run until the owner answers (POST /runs/{run_id}/approvals/{approval_id}); deny refuses it at once, and the model reads why. The owner's defaults: allow for this server's tools, ask for a catalog tool (monid.<tool>, mcp:<server>/<tool>). ask is offered for the tools whose approved call the kernel runs itself (read, write, edit, bash, fetch_page, web_fetch, web_search) and for catalog tools; any other is allow or deny.",
|
|
241
|
+
};
|
|
242
|
+
/** The table's tools a setting may name: its legacy names (fetch_page) are set by the capability they fold into. */
|
|
243
|
+
const SETTINGS_TOOLS = TABLE_TOOLS.filter((name) => !Object.hasOwn(LEGACY_NAMES, name));
|
|
244
|
+
/** A catalog tool's settings key, or an MCP server's wildcard, which sets each of its tools. */
|
|
245
|
+
const CATALOG_KEY = { type: "string", pattern: "^(monid\\.[^/]+|mcp:[^/]+/.+)$" };
|
|
246
|
+
/** The tool settings map (tool-plane.ts): the server's (/settings/tools) and an agent's own (definition.tool_settings),
|
|
247
|
+
* by settings key: each tool of the table, a catalog tool by name, an MCP server's wildcard; a provider only for the
|
|
248
|
+
* two that have a choice. */
|
|
249
|
+
const TOOL_SETTINGS = {
|
|
250
|
+
type: "object",
|
|
251
|
+
propertyNames: { anyOf: [{ enum: SETTINGS_TOOLS }, CATALOG_KEY] },
|
|
252
|
+
properties: Object.fromEntries(SETTINGS_TOOLS.map((name) => [name, {
|
|
253
|
+
type: "object", additionalProperties: false,
|
|
254
|
+
properties: {
|
|
255
|
+
...(PICKABLE.includes(name) ? { provider: { enum: [...PROVIDERS[name]], description: `Default ${PROVIDERS[name][0]}.` } } : {}),
|
|
256
|
+
permission: { ...PERMISSION, enum: [...permissionsOf(name)] },
|
|
257
|
+
},
|
|
258
|
+
}])),
|
|
259
|
+
additionalProperties: { type: "object", additionalProperties: false, properties: { permission: PERMISSION } },
|
|
260
|
+
};
|
|
261
|
+
/** What a capability resolves to on each harness: `native`, `kernel`, `exa-keyless`, `parallel`, `browserbase`, or `unavailable: <reason>`. */
|
|
262
|
+
const RESOLUTION = { type: "string", pattern: "^(native|kernel|exa-keyless|parallel|browserbase|unavailable: .+)$" };
|
|
263
|
+
const RESOLVES = {
|
|
264
|
+
type: "object", additionalProperties: false, required: [...HARNESSES], properties: Object.fromEntries(HARNESSES.map((harness) => [harness, RESOLUTION])),
|
|
265
|
+
description: "What the tool resolves to on each harness: native (the harness's own tool, or on pi one request to the model provider's hosted search), kernel (the guarded direct fetch; on browser, Kernel's hosted browser), exa-keyless (Exa's keyless MCP search), parallel, browserbase (Browserbase's hosted browser), or unavailable: <reason>.",
|
|
266
|
+
};
|
|
267
|
+
/** Why a capability resolves as it does on each harness: one plain sentence each, from the same resolution. */
|
|
268
|
+
const WHY = {
|
|
269
|
+
type: "object", additionalProperties: false, required: [...HARNESSES], properties: Object.fromEntries(HARNESSES.map((harness) => [harness, { type: "string" }])),
|
|
270
|
+
description: "Why the tool resolves as it does on each harness, one plain sentence each, made by the same resolution as resolves: the harness's or model provider's own search (`Codex's own search`), what leaves none and what serves instead (`behind a gateway Codex has no own search; your Parallel key (saved)`, where saved is a key saved on Tool keys and server the server's own), a pick (`keyless Exa, picked in settings: Exa's free search, no key`), or `turned off in settings`. A client shows it as is.",
|
|
271
|
+
};
|
|
272
|
+
/** GET and PUT /settings/tools's answer: each capability's provider, its default where none is set, and each permission
|
|
273
|
+
* set, by settings key. */
|
|
274
|
+
const TOOL_SETTINGS_ANSWER = {
|
|
275
|
+
type: "object", required: [...PICKABLE], propertyNames: TOOL_SETTINGS.propertyNames,
|
|
276
|
+
properties: Object.fromEntries(PICKABLE.map((name) => [name, { type: "object", additionalProperties: false, required: ["provider"], properties: { provider: { enum: [...PROVIDERS[name]] }, permission: PERMISSION } }])),
|
|
277
|
+
additionalProperties: { type: "object", additionalProperties: false, required: ["permission"], properties: { permission: PERMISSION } },
|
|
278
|
+
};
|
|
279
|
+
/** GET /agents/{agent_id}'s `tools`: each tool the agent's current revision grants, in capabilities.tools' order; one
|
|
280
|
+
* with a provider choice with the provider in force, where it came from, the server's (its default), and what it
|
|
281
|
+
* resolves to on the agent's harness and model. */
|
|
282
|
+
const AGENT_TOOLS = {
|
|
283
|
+
type: "array",
|
|
284
|
+
description: "Each tool the agent's current revision grants, in capabilities.tools' order, with its permission (permission, where it came from as permission_from, default_permission, permissions). A tool with a provider choice (web_search, web_fetch, and fetch_page, web_fetch's legacy name; browser) carries the provider in force (provider), where it came from (provider_from: agent, its own tool_settings; server, the server's settings; default, the built-in default), the one that applies when the agent sets none (default_provider, the server's), and what it resolves to on the agent's harness and model (resolved). Only GET /agents/{agent_id} answers it.",
|
|
285
|
+
items: {
|
|
286
|
+
type: "object", additionalProperties: false, required: ["name", "permission", "permission_from", "default_permission", "permissions"],
|
|
287
|
+
properties: {
|
|
288
|
+
name: { type: "string" }, provider: { type: "string" }, provider_from: { enum: ["agent", "server", "default"] }, default_provider: { type: "string" }, resolved: RESOLUTION,
|
|
289
|
+
permission: { ...PERMISSION, description: "The permission in force: the agent's own (tool_settings), else the server's, else the owner's default.", "x-agentrun-serve": "approvals/1" },
|
|
290
|
+
permission_from: { enum: ["agent", "server", "default"], description: "Where the permission came from: agent, its own tool_settings (the tool's key, or its MCP server's wildcard); server, the server's settings; default, the owner's default.", "x-agentrun-serve": "approvals/1" },
|
|
291
|
+
default_permission: { enum: [...PERMISSIONS], description: "The one that applies when the agent sets none: the server's, else the owner's default.", "x-agentrun-serve": "approvals/1" },
|
|
292
|
+
permissions: { type: "array", items: { enum: [...PERMISSIONS] }, description: "The permissions it may be set to.", "x-agentrun-serve": "approvals/1" },
|
|
293
|
+
},
|
|
294
|
+
},
|
|
295
|
+
"x-agentrun-serve": "providers/1",
|
|
296
|
+
};
|
|
297
|
+
const WEBHOOK_ID = { name: "webhook_id", in: "path", required: true, description: "The message, as its `webhook-id` names it.", schema: { type: "string" } };
|
|
298
|
+
const WEBHOOK_SET_FIELDS = {
|
|
299
|
+
configured: { const: true }, url: { type: "string" },
|
|
300
|
+
signing: { enum: ["sealed", "seal_key_missing", "unreadable"], description: "Whether the secret signs here: `sealed`; `seal_key_missing` (the server was handed no seal key) or `unreadable` (sealed under another key, or damaged), when nothing is sent until the webhook is removed and set again. Never the secret." },
|
|
301
|
+
disabled: { oneOf: [closed({ at: { type: "string", format: "date-time" }, reason: { type: "string" } }), { type: "null" }], description: "Set when the receiver answered 410 Gone: nothing is sent until a PUT sets the webhook again." },
|
|
302
|
+
updated_at: { type: "string", format: "date-time" },
|
|
303
|
+
};
|
|
304
|
+
const WEBHOOK_SET = closed(WEBHOOK_SET_FIELDS);
|
|
305
|
+
/** GET /settings/webhook (webhooks.ts): the webhook, or none; never its secret. */
|
|
306
|
+
const WEBHOOK_VIEW = { oneOf: [closed({ configured: { const: false } }), WEBHOOK_SET] };
|
|
307
|
+
const WEBHOOK_SECRET = { type: "string", pattern: "^whsec_[A-Za-z0-9+/]+={0,2}$", description: "The signing secret, shown this once: `whsec_` and 32 random bytes in base64, as the Standard Webhooks spec gives it. Keep it where the receiver checks `webhook-signature`." };
|
|
308
|
+
const WEBHOOK_ATTEMPT = closed({
|
|
309
|
+
webhook_id: { type: "string", description: "The message's `webhook-id`: the same on each of its tries, and on a redelivery." },
|
|
310
|
+
type: { enum: [...MESSAGE_TYPES] }, at: { type: "string", format: "date-time" },
|
|
311
|
+
status_code: { type: ["integer", "null"], description: "The receiver's answer; null when it was not reached." },
|
|
312
|
+
latency_ms: { type: "integer", minimum: 0 },
|
|
313
|
+
error: { type: ["string", "null"], description: "Why the try failed: an answer not 2xx (a redirect is not followed), no answer in 15 s, not reached, or the webhook removed or off." },
|
|
314
|
+
retry_at: { type: ["string", "null"], format: "date-time", description: "When the message is tried again after this one, if it is." },
|
|
315
|
+
redelivery: { type: "boolean", description: "Sent again by POST .../redeliver." },
|
|
316
|
+
});
|
|
317
|
+
const PAUSED = { type: "object", additionalProperties: false, required: ["run_id", "paused", "status"], properties: { run_id: { type: "string" }, paused: { type: "boolean" }, status: ref("schemas/RunStatus") } };
|
|
318
|
+
/** POST .../archive and .../unarchive: hide an agent and its runs, or one run, from the lists, and show them again. */
|
|
319
|
+
const archiving = (collection, noun, id, answer) => Object.fromEntries(["archive", "unarchive"].map((verb) => [
|
|
320
|
+
`/${collection}/{${noun.toLowerCase()}_id}/${verb}`,
|
|
321
|
+
{
|
|
322
|
+
post: {
|
|
323
|
+
operationId: `${verb}${noun}`, tags: [collection], parameters: [id],
|
|
324
|
+
summary: verb === "archive" ? `Archive the ${noun.toLowerCase()}: hidden from the lists, kept with its history` : `Show the archived ${noun.toLowerCase()} in the lists again`,
|
|
325
|
+
responses: { "200": json({ type: "object" }, answer), ...errors(401, 404, 429, 500) },
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
]));
|
|
329
|
+
const LEARNING_REASON = {
|
|
330
|
+
enum: [...LEARNING_REASONS, null],
|
|
331
|
+
description: [
|
|
332
|
+
"Set only when `state` is `dropped`, from a closed list; a new reason is announced before it ships.",
|
|
333
|
+
"`seed_failed`: the agent's learning folder could not be read or made, or its notes copied, so the run started with nothing learned.",
|
|
334
|
+
"`no_budget`: the run's cap left no room for the end-of-run turn, or refused its request. `unknown_cost`: a capped run whose spend is unknown.",
|
|
335
|
+
"`no_write_tool`, `tool_denied`: older runs only, from before the end-of-run turn answered with its notes (an agent with no `write` tool, or one a tool gate denied it); no run gets them now.",
|
|
336
|
+
"`cancelled`: a person cancelled the run. `crashed`: the run's process went. `reflect_timeout`, `reflect_failed`: the end-of-run turn did not end in time, or ended on an error.",
|
|
337
|
+
"`empty`: the turn's answer gave no note. `unparsed`: it gave notes out of format (no ```note block, one not closed or named twice), and none was kept. `propose_failed`: what it answered could not be checked. `checker`: the checks refused it, at its end or at the merge, and nothing was written to git.",
|
|
338
|
+
"`screen`, `screen_down`: no longer produced (the injection screen is gone; the grader's Planted question decides); older runs may still hold them. `grader`: the grader's verdict was not to keep them. `grade_failed`: the grader gave no verdict, or the grade or the merge failed.",
|
|
339
|
+
].join(" "),
|
|
340
|
+
};
|
|
341
|
+
// ---- learning/1: what a person sees and controls of an agent's learning (learning-routes.ts) ---------------------------
|
|
342
|
+
const NULL_STRING = { type: ["string", "null"] };
|
|
343
|
+
const MARK = { "x-agentrun-serve": "learning/1" };
|
|
344
|
+
const PAGE = (item, description) => closed({ items: { type: "array", items: item }, total: { ...COUNT, description: "How many there are in all, at the commit the page was read at." }, next_cursor: { ...NULL_STRING, description: "The next page, read at the same commit of main as this one: opaque. Null on the last." } }, description);
|
|
345
|
+
const LEARNING_NOTE = closed({
|
|
346
|
+
file: { type: "string", description: "The note's file name, `<slug>.md`, at the folder's top; `[redacted]` when it holds one of the host's secrets as they are now (its route still answers the real name)." },
|
|
347
|
+
name: { type: "string" }, description: { type: "string" }, type: { enum: [...NOTE_TYPES] },
|
|
348
|
+
status: { enum: [...NOTE_STATUSES], description: "Absent from the note's front matter: active. Only an active note is in MEMORY.md. `pending`: a rule the grader held as risky, the user's or the run's own, to wait for its owner's OK; no run reads it." },
|
|
349
|
+
origin: { enum: [...NOTE_ORIGINS], description: "`you`: kept from what the user asked in their own words; `run`: what the run worked out (absent from older notes: `run`)." },
|
|
350
|
+
superseded_by: { ...NULL_STRING, description: "The note that superseded it, on a superseded note; `[redacted]` as `file` is." },
|
|
351
|
+
text: { type: "string", description: "The note's whole file, front matter included." },
|
|
352
|
+
etag: { type: "string", description: "The note's version on main, the same ETag as `GET .../learning/files/{file}` answers: send it as `If-Match` to edit or retire the version shown, and a 412 means it changed since.", "x-agentrun-serve": "learning/2" },
|
|
353
|
+
});
|
|
354
|
+
const LEARNING_CHANGE = closed({
|
|
355
|
+
by: { oneOf: [closed({ run: { type: "string" } }), { type: "object", additionalProperties: false, required: ["user"], properties: { user: { type: "boolean", const: true }, via: { type: "string", description: "On an approval: how it came, `console` (the owner's signed-in page)." } } }], description: "A run's merge (its commit's `Run-Id` trailer), or a person's edit, creation, retirement or approval through this API (`Changed-By: user`, and `Approved-Via` on an approval)." },
|
|
356
|
+
commit: { type: "string" }, at: { type: "string", format: "date-time" },
|
|
357
|
+
reason: { type: "string", description: "A merge's: the grader's reason. A person's: what was done, `edited by a person: <file>`." },
|
|
358
|
+
files: { type: "array", items: { type: "string" }, description: "The files the commit changed, MEMORY.md among them; a name holding one of the host's secrets reads `[redacted]`." },
|
|
359
|
+
});
|
|
360
|
+
const LEARNING_COUNTS = closed({
|
|
361
|
+
merged: COUNT,
|
|
362
|
+
dropped: { type: "object", additionalProperties: COUNT, propertyNames: { enum: [...LEARNING_REASONS] }, description: "By reason (Run.learning.reason): only reasons with one run or more." },
|
|
363
|
+
in_progress: { ...COUNT, description: "Seeded, reflecting or proposed: runs this server holds." },
|
|
364
|
+
}, "How the agent's runs that tried to learn fared, archived runs left out: GET /stats' `learning` with `agent`, less `runs`, counted as it counts them, from the runs this server holds and its learning ledger, no run's files opened.");
|
|
365
|
+
/** One side of an agent's impact (learning-run.ts learningImpact). */
|
|
366
|
+
const IMPACT_SIDE = (side) => closed({
|
|
367
|
+
runs: { ...COUNT, description: side === "before" ? "The completed runs that started before the agent's first note." : "The completed runs that started from at least one active note." },
|
|
368
|
+
median_duration_s: { type: "number", minimum: 0, description: "Their median time to the answer, in seconds to a tenth: from the run's start to the moment its job's answer was final, before it looks back (a run that does not look back: to its end)." },
|
|
369
|
+
median_cost_usd: { type: ["number", "null"], minimum: 0, description: "The median of the job's own cost, without its end-of-run turn, over the `cost_runs` whose cost is known, rounded to 1e-6; null when none is." },
|
|
370
|
+
cost_runs: { ...COUNT, description: "Of `runs`, those whose job's cost is known: the ones `median_cost_usd` is the median of." },
|
|
371
|
+
median_learning_usd: { type: ["number", "null"], minimum: 0, description: "The median of what learning itself cost a run, its end-of-run turn and its grade (the grade's is on GET /usage's `learning` meter), over the runs that learn whose learning cost is known, rounded to 1e-6; null when none is (a side of runs with learning off)." },
|
|
372
|
+
});
|
|
373
|
+
/** A skill or a workflow draft the agent learned, as the agent's learning lists it (learning-routes.ts learnedAt). */
|
|
374
|
+
const LEARNED_ITEM = (kind) => ({
|
|
375
|
+
type: "object", additionalProperties: false,
|
|
376
|
+
required: ["name", "file", ...(kind === "workflow" ? ["readme"] : []), "description", "status", "run", "bytes", "etag"],
|
|
377
|
+
properties: {
|
|
378
|
+
name: { type: "string", description: `The ${kind}'s folder name; \`[redacted]\` when it holds one of the host's secrets as they are now.` },
|
|
379
|
+
file: { type: "string", description: kind === "skill" ? "Its SKILL.md, `skills/<name>/SKILL.md`: GET .../learning/files/{file}, percent-encoded, reads it." : "Its draft, `workflows/<name>/workflow.json`: GET .../learning/files/{file}, percent-encoded, reads it as JSON." },
|
|
380
|
+
...(kind === "workflow" ? { readme: { type: "string", description: "Its README.md, which the server writes from the description the run gave: the file that says whether it waits, and the one an approval names." } } : {}),
|
|
381
|
+
description: { type: "string", description: `What its ${kind === "skill" ? "SKILL.md" : "README.md"}'s front matter says it is for, cut of the host's secrets.` },
|
|
382
|
+
status: { enum: ["active", "pending", "retired"], description: `\`pending\`: the grader held it as risky to wait for its owner's OK (\`status: pending\` in its ${kind === "skill" ? "SKILL.md" : "README.md"}), and no run is given it until it is approved (POST .../learning/files/{file}/approve on its ${kind === "skill" ? "SKILL.md" : "README.md"}). \`retired\`: a person retired it (POST .../learning/files/{file}/retire on its ${kind === "skill" ? "SKILL.md" : "README.md"}), and no later run is given it.` },
|
|
383
|
+
run: { ...NULL_STRING, description: "The run whose merge last changed it; null when no merge names one." },
|
|
384
|
+
bytes: { ...COUNT, description: `The size of its ${kind === "skill" ? "SKILL.md" : "workflow.json"} on main.` },
|
|
385
|
+
etag: { type: "string", description: `The version of its ${kind === "skill" ? "SKILL.md" : "README.md"} on main, as its file's GET answers it: an approval sends it as If-Match.` },
|
|
386
|
+
},
|
|
387
|
+
"x-agentrun-serve": "learning/3",
|
|
388
|
+
});
|
|
389
|
+
const AGENT_LEARNING = closed({
|
|
390
|
+
agent: { type: "string" },
|
|
391
|
+
main: { ...NULL_STRING, description: "Main's head commit; null while the agent has no learning folder (its learning was never on), when every page is empty." },
|
|
392
|
+
index: { type: "string", description: "MEMORY.md on main: what the agent's next run reads, one line per active note, built by the server." },
|
|
393
|
+
notes: PAGE(LEARNING_NOTE, "The first 50 notes: active first, then by their newest change, newest first. GET .../learning/notes for more."),
|
|
394
|
+
skills: { type: "array", items: LEARNED_ITEM("skill"), description: "Every skill on main, `skills/<name>/SKILL.md`, by name: what a later run is given as a skill once it is active. Empty when there is none.", "x-agentrun-serve": "learning/3" },
|
|
395
|
+
workflows: { type: "array", items: LEARNED_ITEM("workflow"), description: "Every workflow draft on main, `workflows/<name>/workflow.json` with its README.md, by name. Empty when there is none.", "x-agentrun-serve": "learning/3" },
|
|
396
|
+
log: PAGE(LEARNING_CHANGE, "The first 20 changes on main, newest first. GET .../learning/log for more."),
|
|
397
|
+
counts: LEARNING_COUNTS,
|
|
398
|
+
impact: {
|
|
399
|
+
oneOf: [closed({ before: IMPACT_SIDE("before"), after: IMPACT_SIDE("after") }), { type: "null" }],
|
|
400
|
+
description: "What learning changed for the agent: its completed agentic runs that started from at least one active note (`after`) against those that started before its first note (`before`: before the earlier of its first merge and the start of its first run that started from a note, so a person's first note counts too). A later run with learning off, or seeded with no note (every note retired), an imported and an archived run are on neither side. Null unless both sides count 2 runs or more: say it \"on N runs\", N `after.runs`. Read from the runs' rows and the learning ledger, no run's files opened.",
|
|
401
|
+
"x-agentrun-serve": "learning/2",
|
|
402
|
+
},
|
|
403
|
+
});
|
|
404
|
+
const PROBLEM = { type: "object", additionalProperties: false, required: ["rule", "detail"], properties: { rule: { type: "string" }, path: { type: "string" }, detail: { type: "string" } } };
|
|
405
|
+
const VERDICT_ITEM = {
|
|
406
|
+
type: "object", additionalProperties: false, required: ["file", "keep", "why"],
|
|
407
|
+
properties: {
|
|
408
|
+
file: { type: "string", description: "The new note's file name; `[redacted]` when it holds one of the host's secrets as they are now." },
|
|
409
|
+
keep: { type: "boolean", description: "Whether the rubric keeps the note: true for one that waits for the owner's OK too." },
|
|
410
|
+
pending: { type: "boolean", const: true, description: "Present on a note kept to wait for the owner's OK: a risky rule, the user's or the run's own (its question is Risky)." },
|
|
411
|
+
origin: { enum: [...NOTE_ORIGINS], description: "On a kept note: `you`, from what the user asked in their own words, or `run`." },
|
|
412
|
+
question: { type: "string", description: "The rubric's question the note failed (General, Planted, Secret, Duplicate or Contradicts) when it is not kept, or Risky when it waits." },
|
|
413
|
+
why: { type: "string", description: "One sentence, the grader's, cut of the host's secrets." },
|
|
414
|
+
},
|
|
415
|
+
};
|
|
416
|
+
/** A note's file name, as a run's learning names one. */
|
|
417
|
+
const NOTE_NAME_FILE = { type: "string", description: "The note's file name, `<slug>.md`, in the agent's learning folder (GET /agents/{agent_id}/learning/files/{file}); `[redacted]` when it holds one of the host's secrets as they are now." };
|
|
418
|
+
/** The notes a run read and learned, on its learning block (runs.ts, learning.ts notesView): each present only when it
|
|
419
|
+
* holds a note. */
|
|
420
|
+
const LEARNING_NOTES = {
|
|
421
|
+
used: {
|
|
422
|
+
type: "array", minItems: 1,
|
|
423
|
+
items: closed({ file: NOTE_NAME_FILE, name: { type: "string", description: "The note's front-matter `name`, cut of the host's secrets as they are now." } }),
|
|
424
|
+
description: "The notes this run read from `.learning/` in its working directory, in the order it first read each: every `read` call of its job (on any harness) whose result was a success and that names a note the run started from. A note read another way, through a command (`bash`'s `cat .learning/<file>`, say), is not counted. MEMORY.md, the index every run gets in its instructions, is not one; nor is a read the run's end-of-run turn made. Found once, as the run settles, and kept with the run: absent while it runs (a follow-up included) and when it read none.",
|
|
425
|
+
"x-agentrun-serve": "learning/2",
|
|
426
|
+
},
|
|
427
|
+
learned: {
|
|
428
|
+
type: "array", minItems: 1,
|
|
429
|
+
items: closed({ file: NOTE_NAME_FILE, name: { type: "string", description: "The note's front-matter `name`, cut of the host's secrets as they are now." }, supersedes: { type: "array", items: NOTE_NAME_FILE, description: "The older notes it replaced, each now `superseded` by it; empty when it replaced none." } }),
|
|
430
|
+
description: "The notes this run's learning added to the agent's learning folder: present once `state` is `merged`, absent otherwise.",
|
|
431
|
+
"x-agentrun-serve": "learning/2",
|
|
432
|
+
},
|
|
433
|
+
skills: {
|
|
434
|
+
type: "array", minItems: 1,
|
|
435
|
+
items: { type: "object", additionalProperties: false, required: ["file", "name"], properties: { file: { type: "string", description: "Its SKILL.md, `skills/<name>/SKILL.md`; `[redacted]` when it holds one of the host's secrets as they are now." }, name: { type: "string", description: "The skill's folder name, `[redacted]` as `file` is." }, pending: { type: "boolean", const: true, description: "Present while it waits for the owner's OK: no run is given it until approved." } } },
|
|
436
|
+
description: "The skill this run's learning added or changed: present once `state` is `merged` and it kept one, absent otherwise.",
|
|
437
|
+
"x-agentrun-serve": "learning/3",
|
|
438
|
+
},
|
|
439
|
+
workflows: {
|
|
440
|
+
type: "array", minItems: 1,
|
|
441
|
+
items: { type: "object", additionalProperties: false, required: ["file", "name"], properties: { file: { type: "string", description: "Its draft, `workflows/<name>/workflow.json`; `[redacted]` when it holds one of the host's secrets as they are now." }, name: { type: "string", description: "The workflow's folder name, `[redacted]` as `file` is." }, pending: { type: "boolean", const: true, description: "Present while it waits for the owner's OK." } } },
|
|
442
|
+
description: "The workflow draft this run's learning added or changed: present once `state` is `merged` and it kept one, absent otherwise.",
|
|
443
|
+
"x-agentrun-serve": "learning/3",
|
|
444
|
+
},
|
|
445
|
+
};
|
|
446
|
+
/** A run's learning block, past its read and learned notes: the notes its merge holds for the owner's OK. The run's
|
|
447
|
+
* learning whole (RUN_LEARNING) says the same as a list that is always there. */
|
|
448
|
+
const RUN_NOTES = {
|
|
449
|
+
...LEARNING_NOTES,
|
|
450
|
+
pending: {
|
|
451
|
+
type: "array", minItems: 1,
|
|
452
|
+
items: closed({ file: NOTE_NAME_FILE, name: { type: "string", description: "The note's front-matter `name`, cut of the host's secrets as they are now." } }),
|
|
453
|
+
description: "The notes this run's merge holds for the owner's OK (status `pending` in the folder: a risky rule, the user's or the run's own), in no index and read by no run until approved, never among `learned`: present once `state` is `merged` and one waits, absent otherwise.",
|
|
454
|
+
"x-agentrun-serve": "learning/2",
|
|
455
|
+
},
|
|
456
|
+
};
|
|
457
|
+
/** `properties` as a closed object, its `optional` ones left out of `required`. */
|
|
458
|
+
const closedWith = (properties, optional) => ({ ...closed(properties), properties: { ...properties, ...optional } });
|
|
459
|
+
/** trigger/1: schedules that start an agent's capped runs (triggers.ts). */
|
|
460
|
+
const TRIGGER_MARK = { "x-agentrun-serve": "trigger/1" };
|
|
461
|
+
/** A run's `trigger`, on Run and on RunSummary alike. */
|
|
462
|
+
const RUN_TRIGGER = {
|
|
463
|
+
oneOf: [closed({ id: { type: "string", description: "The trigger (GET /triggers/{trigger_id}); it may have been deleted since." }, firing_key: { type: "string", pattern: "^fir_[0-9a-f]{32}$", description: "The firing that started it." } }), { type: "null" }],
|
|
464
|
+
description: "The trigger that started the run, and its firing; null for a run a caller started.",
|
|
465
|
+
...TRIGGER_MARK,
|
|
466
|
+
};
|
|
467
|
+
const DATE_TIME = { type: "string", format: "date-time" };
|
|
468
|
+
const TRIGGER_SOURCE = {
|
|
469
|
+
oneOf: [
|
|
470
|
+
closedWith({ kind: { const: "schedule" }, cron: { type: "string", description: "Five fields, minute hour day-of-month month day-of-week, as cron reads them (croner): at most once a minute. A time a clock change repeats fires once, at its first pass; one it skips fires at the first time after the gap." } }, { timezone: { type: "string", default: "UTC", description: "The IANA zone the cron line is read in." } }),
|
|
471
|
+
closed({ kind: { const: "schedule" }, at: { ...DATE_TIME, description: "Once, at this time (to the second, in the future); the trigger turns itself off after." } }),
|
|
472
|
+
closedWith({ kind: { const: "schedule" }, every_s: { type: "integer", minimum: MIN_EVERY_S, maximum: MAX_EVERY_S, description: "Every this many seconds, on the grid from start_at." } }, { start_at: { ...DATE_TIME, description: "The grid's origin, to the second: the first firing is at it when it is ahead, else at the first point of the grid after now. Default the time the trigger was made." } }),
|
|
473
|
+
closed({ kind: { const: "webhook" } }),
|
|
474
|
+
],
|
|
475
|
+
description: `When it fires: a cron line in a zone, one time, every N seconds (${MIN_EVERY_S} or more), or a signed request to /hooks/{trigger_id} (\`webhook\`). Each next time is reckoned from the last nominal one, never from when the timer woke. Times missed while the server was down, or more than a minute late, are one \`missed\` firing with their count, and the schedule goes on from now.`,
|
|
476
|
+
};
|
|
477
|
+
const START_RUN = closedWith({
|
|
478
|
+
kind: { const: "start_run" },
|
|
479
|
+
agent_id: { type: "string", description: "The agent whose run each firing starts: an agent, not a workflow, since a workflow run's spend is not capped here." },
|
|
480
|
+
input: { type: "object", description: "The run's input, as POST /agents/{agent_id}/runs takes it: `{content}`. Each run's content ends with a line naming the schedule and the time it fired for, in its zone." },
|
|
481
|
+
}, { effort: { $ref: "#/components/schemas/Effort" }, max_cost_usd: { type: "number", exclusiveMinimum: 0, description: "Each run's spend cap. Absent, the agent's default (its definition's `max_cost_usd`) as it stands when the firing starts; one of the two is required, so every run a trigger starts is capped: a target with neither is 422, and a firing that finds neither (the agent's default removed since) fails." } });
|
|
482
|
+
const TRIGGER_TARGET = {
|
|
483
|
+
oneOf: [
|
|
484
|
+
START_RUN,
|
|
485
|
+
closed({
|
|
486
|
+
kind: { const: "message_run" },
|
|
487
|
+
run_id: { type: "string", description: "The run each firing messages, as POST /runs/{run_id}/messages would: a steer while it works, a follow-up after it ended (a completed run opens again), under its own cap, which it must have (422 otherwise). A firing never answers a run that waits on its person (a question, an approval, its cap): it is skipped." },
|
|
488
|
+
input: closed({ content: { type: "string", minLength: 1 } }, "The message: its content, then a webhook's payload marked untrusted, then a line naming the trigger and when it fired."),
|
|
489
|
+
}),
|
|
490
|
+
],
|
|
491
|
+
description: "What each firing does: start a run of an agent, capped, or send a message to one run.",
|
|
492
|
+
};
|
|
493
|
+
const TRIGGER_FIRING = closedWith({
|
|
494
|
+
key: { type: "string", pattern: "^fir_[0-9a-f]{32}$", description: "The firing's key: from the trigger and its nominal time, or from the trigger and the Idempotency-Key of a run now. Its run is started under it, once." },
|
|
495
|
+
by: { enum: ["schedule", "manual", "webhook"], description: "`webhook`: a signed request to /hooks/{trigger_id}, its key from the trigger and the request's `webhook-id`." },
|
|
496
|
+
nominal_at: { ...DATE_TIME, description: "The time it fires for, to the second; a run now's is when it was asked." },
|
|
497
|
+
status: { enum: [...FIRING_STATUSES], description: `\`due\`: recorded, its run not started yet (a full server keeps it due, with \`retry_at\`). \`started\`: its run is \`run_id\`. \`sent\`: a message_run firing's message reached \`run_id\`. \`skipped\`: the trigger's last run was still active (working, or waiting on a person), or an earlier firing was still due; \`reason\` says which. \`failed\`: the run was refused, with \`error\`; a trigger.failed webhook message says so. \`missed\`: times not fired while the server was down or its timer late (older than the catch-up window, or before the one that caught up), \`count\` of them from \`nominal_at\` on.` },
|
|
498
|
+
at: { ...DATE_TIME, description: "When it was recorded." },
|
|
499
|
+
run_id: { type: ["string", "null"] },
|
|
500
|
+
reason: { type: ["string", "null"] },
|
|
501
|
+
error: { oneOf: [closed({ code: { type: "string" }, message: { type: "string" } }), { type: "null" }] },
|
|
502
|
+
}, { count: { type: "integer", minimum: 1, description: "On a `missed` firing: how many times it stands for, from `nominal_at` on; a cron line's are counted to 10000, and `reason` says \"or more\" past that." }, attempts: { type: "integer", minimum: 0 }, retry_at: DATE_TIME, catch_up: { const: true, description: "A time that fired late, within the trigger's catch-up window: the server was down, or its timer late." } });
|
|
503
|
+
const TRIGGER = closed({
|
|
504
|
+
id: { type: "string" },
|
|
505
|
+
name: { type: "string", maxLength: 200 },
|
|
506
|
+
enabled: { type: "boolean" },
|
|
507
|
+
source: TRIGGER_SOURCE,
|
|
508
|
+
target: TRIGGER_TARGET,
|
|
509
|
+
overlap: { enum: [...OVERLAP], description: "What a firing does while the trigger's last run is active (working, or waiting on a person): `skip`, recorded as a skipped firing with why. Never queued: a firing queued behind a run parked on a person would wait as long as the person does." },
|
|
510
|
+
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}.` },
|
|
511
|
+
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.` },
|
|
512
|
+
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." } }), { type: "null" }], description: `Why it is off, when the server turned it off: \`auto_paused\`, ${FAILURES_TO_PAUSE} failed firings in a row; \`source_unreadable\`, its cron line or zone no longer reads here (a newer cron library or time zone data refuses it), 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.` },
|
|
513
|
+
next_at: { type: ["string", "null"], format: "date-time", description: "When it fires next; null while it is off." },
|
|
514
|
+
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. Null until one starts." },
|
|
515
|
+
created_at: DATE_TIME,
|
|
516
|
+
updated_at: DATE_TIME,
|
|
517
|
+
last_firing: { oneOf: [TRIGGER_FIRING, { type: "null" }] },
|
|
518
|
+
});
|
|
519
|
+
const TRIGGER_WRITE = {
|
|
520
|
+
name: { type: "string", minLength: 1, maxLength: 200, description: "Default the trigger's id." },
|
|
521
|
+
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." },
|
|
522
|
+
source: TRIGGER_SOURCE,
|
|
523
|
+
target: TRIGGER_TARGET,
|
|
524
|
+
catchup_window_s: { type: "integer", minimum: 0, maximum: MAX_EVERY_S, default: CATCHUP_WINDOW_S },
|
|
525
|
+
};
|
|
526
|
+
const TRIGGER_ID = { name: "trigger_id", in: "path", required: true, schema: { type: "string" } };
|
|
527
|
+
const TRIGGER_SECRET = { type: "string", pattern: "^whsec_[A-Za-z0-9+/]+={0,2}$", description: "A webhook trigger's signing secret, shown this once: `whsec_` and 32 random bytes in base64, as the Standard Webhooks spec gives it. Never in any GET; kept sealed under the seal key. Sign each request to /hooks/{trigger_id} with it." };
|
|
528
|
+
const TRIGGER_ERRORS = "409 store_unreadable when triggers.json in the data directory does not read: nothing fires, and nothing is written over it.";
|
|
529
|
+
const RUN_LEARNING = {
|
|
530
|
+
oneOf: [
|
|
531
|
+
closedWith({
|
|
532
|
+
run: { type: "string" }, state: { enum: [...LEARNING_STATES] }, reason: LEARNING_REASON,
|
|
533
|
+
detail: { ...NULL_STRING, maxLength: 300, description: "Run.learning's detail, the same words: at most 300 characters, cut of the host's secrets as they are now before it is cut short." }, at: { type: "string", format: "date-time" },
|
|
534
|
+
seed: { ...NULL_STRING, description: "The commit of main the run started from; null when its seed failed." },
|
|
535
|
+
merged: { ...NULL_STRING, description: "Its merge commit on main, once merged." },
|
|
536
|
+
pending: { type: "array", items: closed({ file: { type: "string" }, name: { type: "string" } }), description: "The merge's notes that wait for the owner's OK (status `pending` on main), in no index and read by no run until approved; empty when none." },
|
|
537
|
+
verdict: { oneOf: [closed({ merge: { type: "boolean" }, reason: { type: "string" }, items: { type: "array", items: VERDICT_ITEM, description: "One for each new note the run proposed." } }), { type: "null" }], description: "The grader's, once it judged; null when no grade ran." },
|
|
538
|
+
problems: { type: "array", items: PROBLEM, description: "The checker's, when the reason is `checker`; otherwise, the items the checks left out while the rest went on to the grader (on a merge, a grader's drop or a grade that failed)." },
|
|
539
|
+
cost_usd: closed({ grade: { type: ["number", "null"], description: "The grade's, outside the run (GET /usage's `learning` meter); null before a grade ran, or when its cost is unknown. The end-of-run turn's cost is in the run's own totals." } }),
|
|
540
|
+
tokens: closed({ grade: { oneOf: [closed({ input: COUNT, cache_read: COUNT, cache_write: COUNT, output: COUNT }), { type: "null" }], description: "The grade's tokens; `input` excludes cached input." } }),
|
|
541
|
+
}, LEARNING_NOTES),
|
|
542
|
+
{ type: "null" },
|
|
543
|
+
],
|
|
544
|
+
description: "The run's learning whole. Null for a run that does not learn.",
|
|
545
|
+
};
|
|
546
|
+
const LEARNING_DIFF = closed({
|
|
547
|
+
base: { ...NULL_STRING, description: "A merged run's merge's parent; else the commit the run's proposal was checked against (its seed)." },
|
|
548
|
+
head: { ...NULL_STRING, description: "A merged run's merge commit; null before (the proposal is in the run's own folder, not a commit)." },
|
|
549
|
+
files: {
|
|
550
|
+
type: "array",
|
|
551
|
+
items: {
|
|
552
|
+
type: "object", additionalProperties: false, required: ["path", "status"],
|
|
553
|
+
properties: {
|
|
554
|
+
path: { type: "string", description: "The file's name; `[redacted]` when it holds one of the host's secrets." }, status: { enum: ["added", "modified", "deleted"] },
|
|
555
|
+
patch: { type: "string", description: "The file's unified diff as git writes it, hunks only: from the first `@@` line, 3 lines of context. An added file diffs against nothing (`@@ -0,0 +1,N @@`)." },
|
|
556
|
+
withheld: { enum: ["too_large", "secret"], description: "Set instead of `patch` when the file is not shown: its patch is over 64 KiB, or holds one of the host's secrets." },
|
|
557
|
+
},
|
|
558
|
+
},
|
|
559
|
+
},
|
|
560
|
+
}, "What the run proposed: once merged, its merge commit against its parent, MEMORY.md and superseded notes included; before, its new notes against its seed; a run that proposed nothing, no file.");
|
|
561
|
+
const AGENT_ID = ref("parameters/AgentId");
|
|
562
|
+
const NOTE_PARAM = { name: "file", in: "path", required: true, description: "A note's file name at the folder's top (`<slug>.md`), percent-encoded; on a read, `MEMORY.md` too, and a skill's `skills/<name>/SKILL.md` or a draft's `workflows/<name>/workflow.json` or `README.md`, its slashes percent-encoded (`skills%2F<name>%2FSKILL.md`); on an approval, a skill's SKILL.md or a draft's README.md. Any other name is 400, and so is a skill's or a draft's file on an edit, which is for notes; on a retire, a skill's SKILL.md or a draft's README.md too; a path with a bare `/` is no route (404).", schema: { type: "string" } };
|
|
563
|
+
const ETAG = { ETag: { description: "The note's version on main: its git blob id, quoted. If-Match on a write takes it.", schema: { type: "string" } }, "X-Content-Type-Options": ref("headers/NoSniff") };
|
|
564
|
+
const NOTE_TEXT = (description, json = false) => ({ description, headers: ETAG, content: { "text/markdown": { schema: { type: "string" } }, ...(json ? { "application/json": { schema: {}, description: "A draft's workflow.json, as it is on main." } } : {}) } });
|
|
565
|
+
const PRECONDITION_REQUIRED = { description: "`precondition_required`: the write names no version it read: If-Match with the note's ETag (an edit or a retire), or If-None-Match: * (a new note). If-Match: * is not one.", content: { "application/json": { schema: ref("schemas/Error") } } };
|
|
566
|
+
const IF_MATCH = { name: "If-Match", in: "header", required: false, description: "The note's ETag, as a GET answered it: an edit or a retire lands only on that version, else 412.", schema: { type: "string" } };
|
|
567
|
+
const WRITE_ERRORS = { ...errors(400, 401, 404, 412, 429, 500), "428": PRECONDITION_REQUIRED };
|
|
568
|
+
const WRITE_DESCRIPTION = "As a person, with no grader: one host commit on main in the agent's queue, `learning: <edited|created|retired> by a person: <file>` with a `Changed-By: user` trailer, MEMORY.md rebuilt from the active notes, and the folder's files brought in line. A note that fails the structural checks a run's notes pass (front matter, the 4 KB cap, UTF-8, hidden characters, text shaped like a secret or holding one of the host's) is 400 `bad_request` with `problems`, and nothing is written; so is an index past 200 lines. MEMORY.md is 400: the server builds it. Answers the note as it now is, with its new ETag. An archived agent's notes are written as its definition is.";
|
|
569
|
+
const LEARNING_EXTENSIONS = {
|
|
570
|
+
"/agents/{agent_id}/learning": {
|
|
571
|
+
get: {
|
|
572
|
+
operationId: "getAgentLearning", tags: ["agents"], summary: "What the agent has learned: its index, notes, log of changes and counts",
|
|
573
|
+
description: "Read at main's head with git's plumbing; every text cut of the host's secrets as they are now, and a file name holding one `[redacted]` whole. An agent whose learning was never on has no folder: `main` null and every page empty. An archived agent's is readable.",
|
|
574
|
+
parameters: [AGENT_ID], responses: { "200": json(AGENT_LEARNING, "The agent's learning."), ...errors(401, 404, 429, 500) }, ...MARK,
|
|
575
|
+
},
|
|
576
|
+
},
|
|
577
|
+
"/agents/{agent_id}/learning/notes": {
|
|
578
|
+
get: {
|
|
579
|
+
operationId: "listLearningNotes", tags: ["agents"], summary: "A page of the agent's notes",
|
|
580
|
+
parameters: [
|
|
581
|
+
AGENT_ID,
|
|
582
|
+
{ name: "cursor", in: "query", required: false, description: "`next_cursor` from the previous page: opaque, read at the commit the first page was.", schema: { type: "string" } },
|
|
583
|
+
{ name: "limit", in: "query", required: false, description: "At most 200.", schema: { type: "integer", minimum: 1, maximum: 200, default: 50 } },
|
|
584
|
+
{ name: "status", in: "query", required: false, description: "Only notes with this status.", schema: { enum: [...NOTE_STATUSES] } },
|
|
585
|
+
],
|
|
586
|
+
responses: { "200": json(PAGE(LEARNING_NOTE, "Active first, then newest first."), "One page of notes."), ...errors(400, 401, 404, 429, 500) }, ...MARK,
|
|
587
|
+
},
|
|
588
|
+
},
|
|
589
|
+
"/agents/{agent_id}/learning/log": {
|
|
590
|
+
get: {
|
|
591
|
+
operationId: "listLearningLog", tags: ["agents"], summary: "A page of the changes on the agent's main, newest first",
|
|
592
|
+
parameters: [
|
|
593
|
+
AGENT_ID,
|
|
594
|
+
{ name: "cursor", in: "query", required: false, description: "`next_cursor` from the previous page: opaque.", schema: { type: "string" } },
|
|
595
|
+
{ name: "limit", in: "query", required: false, description: "At most 200.", schema: { type: "integer", minimum: 1, maximum: 200, default: 20 } },
|
|
596
|
+
],
|
|
597
|
+
responses: { "200": json(PAGE(LEARNING_CHANGE, "Newest first."), "One page of changes."), ...errors(400, 401, 404, 429, 500) }, ...MARK,
|
|
598
|
+
},
|
|
599
|
+
},
|
|
600
|
+
"/agents/{agent_id}/learning/files/{file}": {
|
|
601
|
+
get: {
|
|
602
|
+
operationId: "readLearningFile", tags: ["agents"], summary: "One note (or MEMORY.md, a skill's SKILL.md or a draft's file) on main, as text, with its ETag",
|
|
603
|
+
description: "A note, MEMORY.md, a SKILL.md and a README.md are `text/markdown`; a draft's workflow.json is `application/json`.",
|
|
604
|
+
parameters: [AGENT_ID, NOTE_PARAM], responses: { "200": NOTE_TEXT("The file's text, cut of the host's secrets.", true), ...errors(400, 401, 404, 429, 500) }, ...MARK,
|
|
605
|
+
},
|
|
606
|
+
put: {
|
|
607
|
+
operationId: "writeLearningFile", tags: ["agents"], summary: "Edit a note (If-Match) or create one (If-None-Match: *)",
|
|
608
|
+
description: `The body is the note's whole text, front matter included; a person may set any field, \`status\` too (an active note is in the index), except that a note waiting for its owner's OK stays waiting: an edit of a \`pending\` note that drops or changes its status is 400 \`bad_request\` with the rule \`status\`, and only an approval makes it active. With neither header, 428. ${WRITE_DESCRIPTION}`,
|
|
609
|
+
parameters: [AGENT_ID, NOTE_PARAM, IF_MATCH, { name: "If-None-Match", in: "header", required: false, description: "`*`: create the note, only if the name is not taken, else 412.", schema: { type: "string", const: "*" } }],
|
|
610
|
+
requestBody: {
|
|
611
|
+
required: true,
|
|
612
|
+
description: "The note's whole text: as text, or as JSON `{text}`, the form the console's page sends under its session (a write from the page is JSON from its own origin). A JSON body that is not an object is 400; a missing or wrong `text`, or another field, is 422 by field.",
|
|
613
|
+
content: {
|
|
614
|
+
"text/markdown": { schema: { type: "string" } }, "text/plain": { schema: { type: "string" } },
|
|
615
|
+
"application/json": { schema: closed({ text: { type: "string", description: "The note's whole text, front matter included." } }) },
|
|
616
|
+
},
|
|
617
|
+
},
|
|
618
|
+
responses: { "200": NOTE_TEXT("Edited: the note as it now is."), "201": NOTE_TEXT("Created: the note."), ...WRITE_ERRORS, ...errors(413, 415, 422) }, ...MARK,
|
|
619
|
+
},
|
|
620
|
+
},
|
|
621
|
+
"/agents/{agent_id}/learning/files/{file}/retire": {
|
|
622
|
+
post: {
|
|
623
|
+
operationId: "retireLearningFile", tags: ["agents"], summary: "Retire a note, a skill or a workflow draft: out of every later run, kept in history",
|
|
624
|
+
description: `A learned skill (its \`skills/<name>/SKILL.md\`) or a workflow draft (its \`workflows/<name>/README.md\`; its workflow.json is 400) is retired the same way: \`status: retired\` last in its front matter, one host commit \`learning: retired by a person: <file>\` that changes that file alone, listed \`retired\`, and no later run is given it; one already retired is answered as it is. Sets \`status: retired\` (and drops \`superseded_by\`), on an active note or one that waits for its owner's OK (\`pending\`); any other note is answered as it is. A retire is how a person revokes a note, so only its format is checked: its front matter as retired, and the 4 KB cap with the status line on top (400 \`bad_request\` with \`problems\` otherwise). A secret shape or one of the host's values in its name or text never blocks it; the answer is cut of them. ${WRITE_DESCRIPTION}`,
|
|
625
|
+
parameters: [AGENT_ID, NOTE_PARAM, IF_MATCH], responses: { "200": NOTE_TEXT("The note, retired."), ...WRITE_ERRORS }, ...MARK,
|
|
626
|
+
},
|
|
627
|
+
},
|
|
628
|
+
"/agents/{agent_id}/learning/files/{file}/approve": {
|
|
629
|
+
post: {
|
|
630
|
+
operationId: "approveLearningFile", tags: ["agents"], summary: "Approve a note, a skill or a workflow draft that waits for its owner's OK",
|
|
631
|
+
description: `A skill (its SKILL.md) or a workflow draft (its README.md) that waits is made active the same way, by the same session, in one commit that drops its \`status: pending\` line and changes nothing else: every later run is given it. Makes a pending note active: in MEMORY.md, read by every later run, and each note it supersedes that is active still marked superseded. One host commit on main, \`learning: approved by a person: <file>\`, with the trailers \`Changed-By: user\` and \`Approved-Via: console\`; the log shows it as \`by: {user: true, via: "console"}\` at the commit's time, and never the note's text. Only the owner, signed in with their password, approves: the route takes the console's password session alone, from this server's own origin with a JSON body (as every page write), and answers 403 \`forbidden\` to every token, the server's own included, since an agent's MCP client, the MCP endpoint's tools or a script may hold one, to a run's door token, and to every request on a server with accounts off, whose page cookie the token mints (\`capabilities.learning.approve\` is false there, with \`approve_needs: "password"\`); with no credential at all it is 401, as every route. A run that uses bash on the host runs as the server's user and can read its files, so for untrusted tasks use the sandbox. A note that is not pending is 400 \`bad_request\`. Under If-Match, as a retire: a stale ETag is 412, none 428.`,
|
|
632
|
+
// The owner's password session alone (ownerSession), never the document's bearer, with the empty JSON body every
|
|
633
|
+
// page write sends: a client generated from this document sends what the route takes.
|
|
634
|
+
security: [{ ownerSession: [] }],
|
|
635
|
+
requestBody: { required: true, content: { "application/json": { schema: { type: "object", additionalProperties: false, maxProperties: 0 } } } },
|
|
636
|
+
parameters: [AGENT_ID, NOTE_PARAM, IF_MATCH], responses: { "200": NOTE_TEXT("The note, approved."), ...WRITE_ERRORS, ...errors(403) }, ...MARK,
|
|
637
|
+
},
|
|
638
|
+
},
|
|
639
|
+
"/runs/{run_id}/learning": {
|
|
640
|
+
get: {
|
|
641
|
+
operationId: "getRunLearning", tags: ["runs"], summary: "The run's learning whole: its seed, merge, verdict, problems and cost",
|
|
642
|
+
parameters: [ref("parameters/RunId")], responses: { "200": json(RUN_LEARNING, "The run's learning, or null."), ...errors(401, 404, 429, 500) }, ...MARK,
|
|
643
|
+
},
|
|
644
|
+
},
|
|
645
|
+
"/runs/{run_id}/learning/diff": {
|
|
646
|
+
get: {
|
|
647
|
+
operationId: "getRunLearningDiff", tags: ["runs"], summary: "What the run proposed, file by file",
|
|
648
|
+
description: "404 for a run that does not learn, or whose merge is not in its agent's folder.",
|
|
649
|
+
parameters: [ref("parameters/RunId")], responses: { "200": json(LEARNING_DIFF, "The run's diff."), ...errors(401, 404, 429, 500) }, ...MARK,
|
|
650
|
+
},
|
|
651
|
+
},
|
|
652
|
+
};
|
|
653
|
+
/** A file of an agent's home, listed as a run's file is (RunFile). */
|
|
654
|
+
const HOME_FILE = {
|
|
655
|
+
type: "object", additionalProperties: false, required: ["path", "size_bytes", "modified_at"],
|
|
656
|
+
properties: {
|
|
657
|
+
path: { type: "string", description: "Relative to the agent's home, `/` between segments." },
|
|
658
|
+
size_bytes: { type: "integer", minimum: 0 },
|
|
659
|
+
modified_at: ref("schemas/Timestamp"),
|
|
660
|
+
content_type: { type: ["string", "null"] },
|
|
661
|
+
unreadable: { type: "boolean", const: true, description: "Present when this server cannot read the file (another user made it private): reading it answers 403 `system_file_forbidden` with `details.reason` `unreadable`." },
|
|
662
|
+
},
|
|
663
|
+
};
|
|
664
|
+
/** A host-owned path of the home that is there: one entry by its name, with nothing of what is in it. */
|
|
665
|
+
const HOME_HOST_ENTRY = {
|
|
666
|
+
type: "object", additionalProperties: false, required: ["path", "host_owned"],
|
|
667
|
+
properties: {
|
|
668
|
+
path: { type: "string", description: "Its name at the top of the home, as it is on disk (`learning`)." },
|
|
669
|
+
host_owned: { type: "boolean", const: true, description: "A path of `capabilities.home.host_owned`: only the server writes it, and what is in it is never listed or served here: `learning` is read through the learning API (`/v2/agents/{agent_id}/learning`, on a server that has it), `sign-ins` (sealed pointers) only as GET /agents/{agent_id}'s `sign_ins`, never a pointer." },
|
|
670
|
+
},
|
|
671
|
+
};
|
|
672
|
+
const HOME_FILES = {
|
|
673
|
+
type: "object", additionalProperties: false, required: ["agent_id", "files", "complete", "truncated"],
|
|
674
|
+
properties: { agent_id: ref("schemas/Id"), files: { type: "array", items: { oneOf: [HOME_FILE, HOME_HOST_ENTRY] } }, complete: { type: "boolean", description: "Always true here: the home is on this server's disk." }, truncated: { type: "boolean", description: "The list stopped at the server's cap: its count of files, or a directory more than 16 deep." } },
|
|
675
|
+
};
|
|
676
|
+
/** Where an agent's home's files are listed; each file's own path is below it. */
|
|
677
|
+
const HOME_FILES_AT = "/agents/{agent_id}/home/files";
|
|
678
|
+
const HOME_PATH = {
|
|
679
|
+
name: "path", in: "path", required: true,
|
|
680
|
+
description: "A path relative to the agent's home. It may hold `/` between segments, sent as is; each segment is percent-encoded. The server matches the rest of the URL after `/files/`.",
|
|
681
|
+
schema: { type: "string", minLength: 1, maxLength: 1024 },
|
|
682
|
+
};
|
|
683
|
+
const RAW = { "application/octet-stream": { schema: { type: "string", contentMediaType: "application/octet-stream" } }, "*/*": { schema: { type: "string" } } };
|
|
684
|
+
const HOME_PATHS = "A path with an empty, `.` or `..` segment, a backslash, a NUL or a leading `/`, a segment that is not plain text (not its own NFC form, or holding a default-ignorable code point), or over 1024 characters, is `400 invalid_file_path`; a segment that starts with `.` is `403 system_file_forbidden`.";
|
|
685
|
+
const HOME_WRITES = "A path more than 16 directories deep, past where the list goes, is `400 invalid_file_path`. A path at or under one of `capabilities.home.host_owned` (`learning/`, `sign-ins/`) is `403 system_file_forbidden` with `details.reason` `host_owned`: matched on the path as normalized, by its first segment folded (compatibility form, any case, no combining marks), so `./Learning/x` too, and by identity (the same device and inode) where that segment and the host-owned path are both on disk. A link on the way, or as the file, is `403 system_file_forbidden` with `details.reason` `link`: never followed. A path that names a directory, or runs through a file, is `400 invalid_file_path`. An archived agent's home is written as any other's. Where \`capabilities.home.writes\` is false (no /proc/self/fd, as on macOS), the write or delete is \`501 unsupported_here\`.";
|
|
686
|
+
/** This server's own routes, outside the contract. */
|
|
687
|
+
/** One JSON-RPC 2.0 message, and the answer to a request (POST /mcp). */
|
|
688
|
+
const RPC_MESSAGE = { type: "object", required: ["jsonrpc"], properties: { jsonrpc: { const: "2.0" }, id: { type: ["string", "number"] }, method: { type: "string" }, params: { type: "object" } } };
|
|
689
|
+
const RPC_ANSWER = {
|
|
690
|
+
type: "object", required: ["jsonrpc", "id"],
|
|
691
|
+
properties: { jsonrpc: { const: "2.0" }, id: { type: ["string", "number", "null"] }, result: {}, error: { type: "object", required: ["code", "message"], properties: { code: { type: "integer" }, message: { type: "string" } } } },
|
|
692
|
+
};
|
|
693
|
+
/** GET /files's answer: a page of this server's uploads, newest first. */
|
|
694
|
+
const FILE_LIST = { type: "object", additionalProperties: false, required: ["files", "next_cursor"], properties: { files: { type: "array", items: ref("schemas/File") }, next_cursor: { type: ["string", "null"] } } };
|
|
695
|
+
const EXTENSIONS = {
|
|
696
|
+
"/files": {
|
|
697
|
+
get: {
|
|
698
|
+
operationId: "listFiles", tags: ["files"], summary: "This server's uploads, newest first",
|
|
699
|
+
description: "Every file reserved or sent here, pending or ready, a page at a time, so a file whose id was lost is found again. A run that copied a file keeps its copy whatever happens to the upload.",
|
|
700
|
+
parameters: [ref("parameters/Limit"), ref("parameters/Cursor")],
|
|
701
|
+
responses: { "200": json(FILE_LIST, "One page of files, newest first."), ...errors(400, 401, 429, 500) },
|
|
702
|
+
"x-agentrun-serve": "files/1",
|
|
703
|
+
},
|
|
704
|
+
},
|
|
705
|
+
"/files/{file_id}": {
|
|
706
|
+
get: {
|
|
707
|
+
operationId: "getFile", tags: ["files"], summary: "An upload's record",
|
|
708
|
+
description: "The file as POST /files answered it, with its status now: `pending` until its bytes arrive, then `ready` with their `sha256`.",
|
|
709
|
+
responses: { "200": json(ref("schemas/File"), "The file."), ...errors(401, 404, 429, 500) },
|
|
710
|
+
"x-agentrun-serve": "files/1",
|
|
711
|
+
},
|
|
712
|
+
delete: {
|
|
713
|
+
operationId: "deleteFile", tags: ["files"], summary: "Delete an upload",
|
|
714
|
+
description: "Removes the file and its bytes, pending or ready. A run that already copied it into its workspace keeps its copy; a run started after names it in vain (`422` at `file_ids`).",
|
|
715
|
+
responses: { "204": { description: "Deleted." }, ...errors(401, 404, 429, 500) },
|
|
716
|
+
"x-agentrun-serve": "files/1",
|
|
717
|
+
},
|
|
718
|
+
},
|
|
719
|
+
"/mcp": {
|
|
720
|
+
post: {
|
|
721
|
+
operationId: "callMcp", tags: ["local"], summary: "The MCP endpoint: this API's tools, for a coding agent",
|
|
722
|
+
description: "The Model Context Protocol over Streamable HTTP: one JSON-RPC 2.0 message per POST (initialize, ping, tools/list, tools/call), answered as JSON, stateless: no stream (any other method is 405) and no session. Ten tools: whoami, agents_list, agents_create, agents_revise, runs_start, runs_get, runs_events, runs_files, runs_respond and runs_cancel. Each calls this API's routes in process, with the caller's token, and answers as they do: the route's JSON as structured content, a refusal as a result with isError and the route's error. A run is started, then polled; no call is held open for one. The token only: the page's session cookie is never taken here, and a browser Origin other than this server's own is 403. A refusal of the request itself carries a JSON-RPC error.",
|
|
723
|
+
requestBody: { required: true, content: { "application/json": { schema: RPC_MESSAGE } } },
|
|
724
|
+
responses: {
|
|
725
|
+
"200": json(RPC_ANSWER, "The request's answer: its result, or its JSON-RPC error."),
|
|
726
|
+
"202": { description: "A notification, or a response, taken. No body." },
|
|
727
|
+
"400": json(RPC_ANSWER, "Not one JSON-RPC 2.0 request (a batch is not taken), or an MCP-Protocol-Version this server does not speak."),
|
|
728
|
+
"401": json(RPC_ANSWER, "No token, or not this server's."),
|
|
729
|
+
"403": json(RPC_ANSWER, "An Origin other than this server's own."),
|
|
730
|
+
"413": json(RPC_ANSWER, "The body is over 1 MiB."),
|
|
731
|
+
"415": json(RPC_ANSWER, "The body is not application/json."),
|
|
732
|
+
},
|
|
733
|
+
"x-agentrun-serve": "mcp/1",
|
|
734
|
+
},
|
|
735
|
+
},
|
|
736
|
+
"/openapi.json": {
|
|
737
|
+
get: {
|
|
738
|
+
operationId: "getOpenapi", tags: ["capabilities"], summary: "This document", security: [{}],
|
|
739
|
+
description: "Readable without a credential, as capabilities are.",
|
|
740
|
+
responses: { "200": json({ type: "object" }, "The OpenAPI document: the contract, with this server's marks."), ...errors(429, 500) },
|
|
741
|
+
},
|
|
742
|
+
},
|
|
743
|
+
"/health": {
|
|
744
|
+
get: {
|
|
745
|
+
operationId: "getHealth", tags: ["capabilities"], summary: "Whether this server can serve", security: [{}],
|
|
746
|
+
description: "Readable without a credential: the store opens and the data directory's disk is above its floor. 503 with the same shape when either fails.",
|
|
747
|
+
responses: {
|
|
748
|
+
"200": json(HEALTH, "Healthy."),
|
|
749
|
+
"503": json(HEALTH, "Not healthy: which check failed."),
|
|
750
|
+
...errors(429, 500),
|
|
751
|
+
},
|
|
752
|
+
},
|
|
753
|
+
},
|
|
754
|
+
"/runs": {
|
|
755
|
+
get: {
|
|
756
|
+
operationId: "listAllRuns", tags: ["runs"], summary: "Every agent's runs, newest first",
|
|
757
|
+
parameters: [
|
|
758
|
+
ref("parameters/Limit"), ref("parameters/Cursor"),
|
|
759
|
+
{ name: "agent", in: "query", required: false, description: "Only this agent's runs.", schema: ref("schemas/Id") },
|
|
760
|
+
{ name: "revision", in: "query", required: false, description: "Only runs of this revision.", schema: { type: "string" } },
|
|
761
|
+
{ name: "status", in: "query", required: false, description: "Only runs with this status.", schema: ref("schemas/RunStatus") },
|
|
762
|
+
{ name: "archived", in: "query", required: false, description: "true lists only archived runs; false, the default, the others.", schema: { type: "boolean" } },
|
|
763
|
+
],
|
|
764
|
+
responses: { "200": json(ref("schemas/RunList"), "One page of runs, newest first."), ...errors(400, 401, 429, 500) },
|
|
765
|
+
},
|
|
766
|
+
},
|
|
767
|
+
"/agents/{agent_id}/revisions": {
|
|
768
|
+
get: {
|
|
769
|
+
operationId: "listRevisions", tags: ["agents"], summary: "The agent's revisions, newest first",
|
|
770
|
+
parameters: [ref("parameters/AgentId"), ref("parameters/Limit"), ref("parameters/Cursor")],
|
|
771
|
+
responses: {
|
|
772
|
+
"200": json({
|
|
773
|
+
type: "object", required: ["revisions", "next_cursor"],
|
|
774
|
+
properties: {
|
|
775
|
+
revisions: {
|
|
776
|
+
type: "array",
|
|
777
|
+
items: {
|
|
778
|
+
type: "object", required: ["revision", "version", "parent", "kind", "current", "note", "created_at", "definition"],
|
|
779
|
+
properties: {
|
|
780
|
+
revision: { type: "string" }, version: { type: "integer", minimum: 1 }, parent: { type: ["string", "null"] },
|
|
781
|
+
kind: { type: "string", enum: ["agentic", "workflow"] }, current: { type: "boolean" }, note: { type: ["string", "null"] },
|
|
782
|
+
created_at: ref("schemas/Timestamp"), definition: ref("schemas/Definition"),
|
|
783
|
+
},
|
|
784
|
+
},
|
|
785
|
+
},
|
|
786
|
+
next_cursor: { type: ["string", "null"] },
|
|
787
|
+
},
|
|
788
|
+
}, "One page of the agent's revisions."),
|
|
789
|
+
...errors(400, 401, 404, 429, 500),
|
|
790
|
+
},
|
|
791
|
+
},
|
|
792
|
+
},
|
|
793
|
+
"/agents/{agent_id}/current": {
|
|
794
|
+
post: {
|
|
795
|
+
operationId: "setCurrent", tags: ["agents"], summary: "Make one of the agent's revisions current again",
|
|
796
|
+
parameters: [ref("parameters/AgentId")],
|
|
797
|
+
requestBody: { required: true, content: { "application/json": { schema: { type: "object", additionalProperties: false, required: ["revision"], properties: { revision: { type: "string" } } } } } },
|
|
798
|
+
responses: { "200": json(ref("schemas/Agent"), "The agent, its current revision the one named."), ...errors(401, 404, 415, 422, 429, 500) },
|
|
799
|
+
},
|
|
800
|
+
},
|
|
801
|
+
"/stats": {
|
|
802
|
+
get: {
|
|
803
|
+
operationId: "getStats", tags: ["runs"], summary: "Counts and cost over every agent and run",
|
|
804
|
+
description: "Read from the agent store's aggregates, and `learning` from the runs this server holds and its learning ledger, where each run's learning end is written: no run's files are opened. Archived agents and runs are left out of every number but their own counts. `from`, `to` and `agent` bound `analytics` and `learning` only; every other number is the whole store's.",
|
|
805
|
+
parameters: [
|
|
806
|
+
{ name: "from", in: "query", required: false, description: "Runs started at or after this RFC 3339 date-time, to the millisecond (a finer fraction is a 400). Default no bound.", schema: { type: "string", format: "date-time" }, "x-agentrun-serve": "stats/2" },
|
|
807
|
+
{ name: "to", in: "query", required: false, description: "Runs started before this RFC 3339 date-time, to the millisecond (a finer fraction is a 400). Default no bound.", schema: { type: "string", format: "date-time" }, "x-agentrun-serve": "stats/2" },
|
|
808
|
+
{ name: "agent", in: "query", required: false, description: "One agent's runs.", schema: ref("schemas/Id"), "x-agentrun-serve": "stats/2" },
|
|
809
|
+
],
|
|
810
|
+
responses: { "200": json(STATS, "The counts and the cost."), ...errors(400, 401, 429, 500) },
|
|
811
|
+
"x-agentrun-serve": "stats/1",
|
|
812
|
+
},
|
|
813
|
+
},
|
|
814
|
+
"/runs/{run_id}/graph": {
|
|
815
|
+
get: {
|
|
816
|
+
operationId: "getRunGraph", tags: ["runs"], summary: "A workflow run's graph, live",
|
|
817
|
+
description: "The revision's workflow and its graph, each node's state (a map's items, a route's branch taken), the decisions with their receipts, the calls with their input and output, and the totals. Readable while the run goes. 404 for an agentic run.",
|
|
818
|
+
parameters: [ref("parameters/RunId")],
|
|
819
|
+
responses: { "200": json(RUN_GRAPH, "The run's graph as it stands."), ...errors(401, 404, 429, 500) },
|
|
820
|
+
},
|
|
821
|
+
},
|
|
822
|
+
"/workflows/validate": {
|
|
823
|
+
post: {
|
|
824
|
+
operationId: "validateWorkflow", tags: ["agents"], summary: "Check a workflow definition without saving it",
|
|
825
|
+
description: "Every issue a save of it as a workflow revision would refuse (the DSL's validation with code not run, a call node's tool the revision does not list, what the durable runner refuses before any step), each with its JSON Pointer path, and the DSL's warnings. Writes nothing. `tools` is the revision's tool list; absent, every tool this server binds.",
|
|
826
|
+
requestBody: { required: true, content: { "application/json": { schema: { type: "object", additionalProperties: false, required: ["workflow"], properties: { workflow: { type: "object" }, tools: { type: "array", items: { type: "string" } } } } } } },
|
|
827
|
+
responses: { "200": json(VALIDATED, "The workflow's issues and warnings; ok when it has no issue."), ...errors(400, 401, 415, 422, 429, 500) },
|
|
828
|
+
},
|
|
829
|
+
},
|
|
830
|
+
"/runs/{run_id}": {
|
|
831
|
+
patch: {
|
|
832
|
+
operationId: "raiseRunCap", tags: ["runs"], summary: "Raise a run's spend cap",
|
|
833
|
+
description: "Raises `max_cost_usd` of an agentic run that named one; only a raise: the new cap is above the run's current cap, its last raise included (422 otherwise, and for a run with no cap or a workflow run); the same raise sent again (a retry) changes nothing and answers as the first did. The run's serve.json keeps it before anything else, so its next process and a server started again run under it. A run paused at its cap (`pending.kind` budget) goes on: the answer comes at once (`resumed` true, its `message_id`), and once its process has been let go the server sends it one follow-up turn under that id, \"The cap was raised to $X; continue the task.\", which runs under the new cap; it is sent once, by a server started again if this one stopped before it went. A second raise before it goes answers the same `message_id`; one that cannot be sent is tried again, then the run ends failed, saying why. Caps within 1e-9 are the same cap. A run working keeps the cap its process was opened with until its next process (`note` says so). 409 not_continuable for an ended run.",
|
|
834
|
+
parameters: [ref("parameters/RunId")],
|
|
835
|
+
requestBody: { required: true, content: { "application/json": { schema: { type: "object", additionalProperties: false, required: ["max_cost_usd"], properties: { max_cost_usd: { type: "number", exclusiveMinimum: 0, description: "The new cap, above the run's current cap." } } } } } },
|
|
836
|
+
responses: {
|
|
837
|
+
"200": json({ type: "object", additionalProperties: false, required: ["run_id", "max_cost_usd", "resumed", "status", "state"], properties: {
|
|
838
|
+
run_id: { type: "string" }, max_cost_usd: { type: "number" }, resumed: { type: "boolean", description: "A run paused at its cap goes on: its follow-up turn is sent once its process has been let go." },
|
|
839
|
+
message_id: { type: "string", description: "That follow-up's id, when `resumed`." }, note: { type: "string", description: "Said when the run's live process keeps its old cap until its next process." },
|
|
840
|
+
status: ref("schemas/RunStatus"), state: ref("schemas/RunState"),
|
|
841
|
+
} }, "The run, its cap raised."),
|
|
842
|
+
...errors(401, 404, 409, 422, 429, 500),
|
|
843
|
+
},
|
|
844
|
+
"x-agentrun-serve": "cappause/1",
|
|
845
|
+
},
|
|
846
|
+
},
|
|
847
|
+
"/runs/{run_id}/pause": {
|
|
848
|
+
post: {
|
|
849
|
+
operationId: "pauseRun", tags: ["runs"], summary: "Pause a workflow run",
|
|
850
|
+
description: "What is in flight finishes; no node, model call or decision starts until the run is resumed. The run's status reads `paused`, and stays so across a restart of the server. 501 for an agentic run, 409 not_continuable for an ended one.",
|
|
851
|
+
parameters: [ref("parameters/RunId")],
|
|
852
|
+
responses: { "200": json(PAUSED, "The run, paused."), ...errors(401, 404, 409, 429, 500) },
|
|
853
|
+
},
|
|
854
|
+
},
|
|
855
|
+
"/runs/{run_id}/resume": {
|
|
856
|
+
post: {
|
|
857
|
+
operationId: "resumeRun", tags: ["runs"], summary: "Resume a paused workflow run",
|
|
858
|
+
parameters: [ref("parameters/RunId")],
|
|
859
|
+
responses: { "200": json(PAUSED, "The run, going again."), ...errors(401, 404, 409, 429, 500) },
|
|
860
|
+
},
|
|
861
|
+
},
|
|
862
|
+
"/settings/tool-keys": {
|
|
863
|
+
get: {
|
|
864
|
+
operationId: "listToolKeys", tags: ["local"], summary: "The tool keys a person may save, and which are set: names only, never a value",
|
|
865
|
+
responses: { "200": json(TOOL_KEYS_VIEW, "Each tool key, its fields and what it unlocks."), ...errors(401, 429, 500) },
|
|
866
|
+
"x-agentrun-serve": "toolkeys/1",
|
|
867
|
+
},
|
|
868
|
+
},
|
|
869
|
+
"/settings/tool-keys/{key_id}": {
|
|
870
|
+
put: {
|
|
871
|
+
operationId: "saveToolKey", tags: ["local"], summary: "Save a tool key's fields, sealed",
|
|
872
|
+
description: "Each value is sealed under the server's seal key and kept in the data directory as ciphertext alone; the key's other fields stay as they are. The key (the first field) is first checked against its provider with one call that costs nothing, given 5 s: a key the provider refuses (401) is 422 input_invalid, its field's reason `refused_by_provider` and the message in plain words with the provider's first sentence (never any of the key), and nothing is kept; otherwise it is kept, and GET's `check` says `accepted` or `not_checked` and why (a 403 is not_checked: a key scoped away from the check's call may still work for its tools). A save whose check is still waiting when the server begins to close keeps nothing (503 unavailable, while its connection lasts). 422 also for an unknown key or field, or a value that is empty, holds a control character or is over 1024 bytes; 409 key_set_by_server for a field the server is started with; 409 no_sealing_key when the server was handed no seal key.",
|
|
873
|
+
parameters: [KEY_ID],
|
|
874
|
+
requestBody: { required: true, content: { "application/json": { schema: { type: "object", additionalProperties: false, required: ["values"], properties: { values: { type: "object", minProperties: 1, additionalProperties: { type: "string", minLength: 1 } } } } } } },
|
|
875
|
+
responses: { "204": { description: "Saved." }, ...errors(400, 401, 409, 415, 422, 429, 500, 503) },
|
|
876
|
+
"x-agentrun-serve": "toolkeys/1",
|
|
877
|
+
},
|
|
878
|
+
delete: {
|
|
879
|
+
operationId: "deleteToolKey", tags: ["local"], summary: "Forget a tool key's stored fields",
|
|
880
|
+
description: "409 key_set_by_server when the server is started with every field of it.",
|
|
881
|
+
parameters: [KEY_ID],
|
|
882
|
+
responses: { "204": { description: "Forgotten." }, ...errors(401, 409, 422, 429, 500) },
|
|
883
|
+
"x-agentrun-serve": "toolkeys/1",
|
|
884
|
+
},
|
|
885
|
+
},
|
|
886
|
+
"/settings/mcp-servers": {
|
|
887
|
+
get: {
|
|
888
|
+
operationId: "listMcpServers", tags: ["local"], summary: "The remote MCP servers saved here, with their tools; never a credential",
|
|
889
|
+
description: "When the saved-servers file does not read (damaged, or another format), `servers` is empty and `file_unreadable` is true; every other route on it is 409 store_unreadable, and nothing writes over it.",
|
|
890
|
+
responses: { "200": json({ type: "object", additionalProperties: false, required: ["servers"], properties: { servers: { type: "array", items: MCP_SERVER_VIEW }, file_unreadable: { const: true, description: "Present when the saved-servers file does not read." } } }, "Each server, by name."), ...errors(401, 429, 500) },
|
|
891
|
+
"x-agentrun-serve": "mcpservers/1",
|
|
892
|
+
},
|
|
893
|
+
},
|
|
894
|
+
"/settings/mcp-servers/preview": {
|
|
895
|
+
post: {
|
|
896
|
+
operationId: "previewMcpServer", tags: ["local"], summary: "Connect to a remote MCP server and list its tools, storing nothing",
|
|
897
|
+
description: `\`{url, auth}\`, or \`{name}\` for a saved server with its sealed credential (409 no_sealing_key when it does not open for want of a seal key; 422 when it does not open otherwise). ${MCP_CONNECTS}`,
|
|
898
|
+
requestBody: { required: true, content: { "application/json": { schema: { oneOf: [{ type: "object", additionalProperties: false, required: ["url"], properties: { url: MCP_URL, auth: MCP_AUTH } }, { type: "object", additionalProperties: false, required: ["name"], properties: { name: { type: "string" } } }] } } } },
|
|
899
|
+
responses: { "200": json(MCP_PREVIEW, "What the server offers."), ...errors(400, 401, 404, 409, 415, 422, 429, 500), ...MCP_FAILED },
|
|
900
|
+
"x-agentrun-serve": "mcpservers/1",
|
|
901
|
+
},
|
|
902
|
+
},
|
|
903
|
+
"/settings/mcp-servers/{name}": {
|
|
904
|
+
get: {
|
|
905
|
+
operationId: "getMcpServer", tags: ["local"], summary: "One saved MCP server; never its credential",
|
|
906
|
+
parameters: [MCP_NAME],
|
|
907
|
+
responses: { "200": json(MCP_SERVER_VIEW, "The server."), ...errors(401, 404, 409, 429, 500) },
|
|
908
|
+
"x-agentrun-serve": "mcpservers/1",
|
|
909
|
+
},
|
|
910
|
+
put: {
|
|
911
|
+
operationId: "saveMcpServer", tags: ["local"], summary: "Preview a remote MCP server, then save it with the tools listed and its credential sealed",
|
|
912
|
+
description: `Each credential header's value is sealed under the server's seal key and bound to the server's name and the header, and kept in the data directory as ciphertext alone. 409 no_sealing_key when the server was handed no seal key and \`auth.type\` is not none (nothing is contacted). A body with no credential keeps the sealed one while the type and the URL's origin stay the same; else it is 422. 422 too for a bad name, URL or auth. ${MCP_CONNECTS} Nothing is saved unless the listing succeeds.`,
|
|
913
|
+
parameters: [MCP_NAME],
|
|
914
|
+
requestBody: { required: true, content: { "application/json": { schema: { type: "object", additionalProperties: false, required: ["url"], properties: { url: MCP_URL, auth: MCP_AUTH } } } } },
|
|
915
|
+
responses: { "200": json(MCP_SERVER_VIEW, "The server, as saved."), ...errors(400, 401, 409, 415, 422, 429, 500), ...MCP_FAILED },
|
|
916
|
+
"x-agentrun-serve": "mcpservers/1",
|
|
917
|
+
},
|
|
918
|
+
delete: {
|
|
919
|
+
operationId: "deleteMcpServer", tags: ["local"], summary: "Forget a saved MCP server and its credential",
|
|
920
|
+
parameters: [MCP_NAME],
|
|
921
|
+
responses: { "204": { description: "Forgotten." }, ...errors(401, 404, 409, 429, 500) },
|
|
922
|
+
"x-agentrun-serve": "mcpservers/1",
|
|
923
|
+
},
|
|
924
|
+
},
|
|
925
|
+
"/settings/mcp-servers/{name}/refresh": {
|
|
926
|
+
post: {
|
|
927
|
+
operationId: "refreshMcpServer", tags: ["local"], summary: "List a saved MCP server's tools again, keep them, and say what changed",
|
|
928
|
+
description: `With its saved URL and sealed credential. \`added\` and \`removed\` are tool names; \`changed\` names a tool whose title, description, schemas or annotations differ. ${MCP_CONNECTS}`,
|
|
929
|
+
parameters: [MCP_NAME],
|
|
930
|
+
responses: { "200": json(closed({ added: { type: "array", items: { type: "string" } }, removed: { type: "array", items: { type: "string" } }, changed: { type: "array", items: { type: "string" } }, server: MCP_SERVER_VIEW }), "What changed, and the server now."), ...errors(401, 404, 409, 422, 429, 500, 503), ...MCP_FAILED },
|
|
931
|
+
"x-agentrun-serve": "mcpservers/1",
|
|
932
|
+
},
|
|
933
|
+
},
|
|
934
|
+
"/settings/tools": {
|
|
935
|
+
get: {
|
|
936
|
+
operationId: "getToolSettings", tags: ["capabilities"], summary: "The server's tool settings",
|
|
937
|
+
description: "Each capability that has a choice, and its provider, and each tool's permission that is set (an MCP server's wildcard mcp:<server>/* among them): web_search auto (codex's own search or, on pi, the model provider's hosted one, else Parallel where the server holds its key, which bills it, else Exa's keyless search; claude-agent's own search only as native), native (that alone), exa-keyless (that alone) or parallel; web_fetch kernel or parallel; browser auto (Browserbase where the server holds its keys, else Kernel where it holds Kernel's), browserbase, kernel (each that alone) or chrome (a Chrome on the server's host, not set up on any server yet: unavailable). An agent's definition.tool_settings is over these. capabilities.tools say what each resolves to on each harness, and GET /agents/{agent_id} for that agent.",
|
|
938
|
+
responses: { "200": json(TOOL_SETTINGS_ANSWER, "Each capability's provider."), ...errors(401, 429, 500) },
|
|
939
|
+
"x-agentrun-serve": "providers/1",
|
|
940
|
+
},
|
|
941
|
+
put: {
|
|
942
|
+
operationId: "putToolSettings", tags: ["capabilities"], summary: "Set the providers of web_search, web_fetch and browser, and each tool's permission",
|
|
943
|
+
description: "Replaces the settings: a tool the body leaves out takes its defaults. Kept in the data directory, and capabilities say so at once. A provider is read by every run launched from then on; a permission by the tool gate at each call, live runs' included (a claude-agent or codex run's own web search takes a change of web_search's at its next launch). An MCP server's wildcard, mcp:<server>/*, sets each of its tools, under a tool's own key. A pick of parallel without PARALLEL_API_KEY resolves unavailable, never to another provider, and so does a browser vendor picked without its key. An unknown tool, a provider not offered for it and a permission not offered for it are refused.",
|
|
944
|
+
requestBody: { required: true, content: { "application/json": { schema: TOOL_SETTINGS } } },
|
|
945
|
+
responses: { "200": json(TOOL_SETTINGS_ANSWER, "Each capability's provider now."), ...errors(400, 401, 415, 422, 429, 500) },
|
|
946
|
+
"x-agentrun-serve": "providers/1",
|
|
947
|
+
},
|
|
948
|
+
},
|
|
949
|
+
[HOME_FILES_AT]: {
|
|
950
|
+
get: {
|
|
951
|
+
operationId: "listHomeFiles", tags: ["agents"], summary: "Every file in the agent's home",
|
|
952
|
+
description: "The agent's home is a directory of its own on this server's disk, kept across its runs (runs do not see it yet). Every regular file in it, recursively, listed as a run's files are (`GET /runs/{run_id}/files`): reached through no link, a name that starts with `.` left out. A home never written to lists none. A path of `capabilities.home.host_owned` that is there (`learning`, `sign-ins`) is one entry, `{path, host_owned: true}`, with none of what is in it.",
|
|
953
|
+
parameters: [ref("parameters/AgentId")],
|
|
954
|
+
responses: { "200": json(HOME_FILES, "The files."), ...errors(401, 404, 429, 500) },
|
|
955
|
+
"x-agentrun-serve": "home/1",
|
|
956
|
+
},
|
|
957
|
+
},
|
|
958
|
+
[`${HOME_FILES_AT}/{path}`]: {
|
|
959
|
+
get: {
|
|
960
|
+
operationId: "readHomeFile", tags: ["agents"], summary: "One file of the agent's home, raw",
|
|
961
|
+
description: `Raw bytes with the file's content type, as a run's file is read (\`GET /runs/{run_id}/files/{path}\`): \`nosniff\`, a CSP on HTML, \`?download=1\` for an attachment. ${HOME_PATHS} A path at or under one of \`capabilities.home.host_owned\` (\`learning/\`, \`sign-ins/\`), as normalized, folded and by identity on disk, is \`403 system_file_forbidden\` with \`details.reason\` \`host_owned\`. Its message names the learning API (\`/v2/agents/{agent_id}/learning\`) on a server that has that route, and says this server has none on one that does not. A link on the way is \`404 not_found\`.`,
|
|
962
|
+
parameters: [ref("parameters/AgentId"), HOME_PATH, { name: "download", in: "query", required: false, description: "`1` forces a download.", schema: { type: "integer", enum: [0, 1], default: 0 } }],
|
|
963
|
+
responses: {
|
|
964
|
+
"200": { description: "The whole file.", headers: { "Content-Disposition": ref("headers/ContentDisposition"), "X-Content-Type-Options": ref("headers/NoSniff") }, content: RAW },
|
|
965
|
+
...errors(400, 401, 403, 404, 429, 500),
|
|
966
|
+
},
|
|
967
|
+
"x-agentrun-serve": "home/1",
|
|
968
|
+
},
|
|
969
|
+
put: {
|
|
970
|
+
operationId: "writeHomeFile", tags: ["agents"], summary: "Write one file of the agent's home",
|
|
971
|
+
description: `The raw body becomes the file, whole: written to a temporary file beside it and renamed over it (0600), the directories on the way made. Of two writes of one file at once, each lands whole and the last wins. A body over \`capabilities.home.max_file_bytes\` is \`413 payload_too_large\`. ${HOME_PATHS} ${HOME_WRITES}`,
|
|
972
|
+
parameters: [ref("parameters/AgentId"), HOME_PATH],
|
|
973
|
+
requestBody: { required: true, content: RAW },
|
|
974
|
+
responses: { "200": json(HOME_FILE, "The file, as the list shows it."), ...errors(400, 401, 403, 404, 413, 429, 500, 501) },
|
|
975
|
+
"x-agentrun-serve": "home/1",
|
|
976
|
+
},
|
|
977
|
+
delete: {
|
|
978
|
+
operationId: "deleteHomeFile", tags: ["agents"], summary: "Delete one file of the agent's home",
|
|
979
|
+
description: `Removes the file; a directory it leaves empty stays. A file that is not there is \`404 not_found\`. ${HOME_PATHS} ${HOME_WRITES}`,
|
|
980
|
+
parameters: [ref("parameters/AgentId"), HOME_PATH],
|
|
981
|
+
responses: { "204": { description: "The file is gone." }, ...errors(400, 401, 403, 404, 429, 500, 501) },
|
|
982
|
+
"x-agentrun-serve": "home/1",
|
|
983
|
+
},
|
|
984
|
+
},
|
|
985
|
+
"/runs/{run_id}/approvals/{approval_id}": {
|
|
986
|
+
post: {
|
|
987
|
+
operationId: "answerApproval", tags: ["runs"], summary: "Answer a tool call that waits for the owner's approval",
|
|
988
|
+
description: "A tool set to ask parks its run at each call: status input_required, state waiting, and its view's and its summary's pending (kind approval) naming the call; a timeline row of kind tool_approval_requested follows the call's result. allow runs the call once, then resumes the session with one message that names the call and carries its result; deny resumes it with the refusal, the note as its reason. The first answer wins: the same answer again is 204, another 409 not_continuable with details {reason: already_answered, decision}. A cancel of the run marks the call canceled, and a stop withdraws it. A person's message while it waits declines it, with the message as the reason: the run resumes in one turn with the refusal and their words, its row reads `Declined by your message`, and a later answer is 409 with details.decision deny. Only the owner's password session answers, on the page's own origin with a JSON body: a bearer token is 403 forbidden, since a run's process, an agent's MCP client or a script may hold one.",
|
|
989
|
+
parameters: [ref("parameters/RunId"), { name: "approval_id", in: "path", required: true, description: "The run's pending.id.", schema: { type: "string" } }],
|
|
990
|
+
requestBody: { required: true, content: { "application/json": { schema: { type: "object", additionalProperties: false, required: ["decision"], properties: { decision: { enum: ["allow", "deny"] }, note: { type: "string", maxLength: 2000, description: "Why: with deny, the refusal's reason the model is told." } } } } } },
|
|
991
|
+
responses: { "204": { description: "Answered: the run goes on." }, ...errors(400, 401, 403, 404, 409, 415, 422, 429, 500) },
|
|
992
|
+
"x-agentrun-serve": "approvals/1",
|
|
993
|
+
},
|
|
994
|
+
},
|
|
995
|
+
...archiving("agents", "Agent", ref("parameters/AgentId"), "The agent, with archived_at."),
|
|
996
|
+
...archiving("runs", "Run", ref("parameters/RunId"), "The run, with archived_at."),
|
|
997
|
+
...LEARNING_EXTENSIONS,
|
|
998
|
+
"/agents/{agent_id}/sign-ins/{key}": {
|
|
999
|
+
delete: {
|
|
1000
|
+
operationId: "forgetSignIn", tags: ["agents"], summary: "Forget one of the agent's saved sign-ins",
|
|
1001
|
+
description: "Deletes the browser vendor's object the sign-in points to (a Browserbase context, a Kernel profile), then the sealed pointer this server kept; GET /agents/{agent_id} lists it no more, and the agent's next run with the browser starts signed out, on a new one. Best effort at the vendor: a delete it does not answer, or refuses, is said in `removed[].message` (`at_vendor: not_deleted`), and the pointer is forgotten all the same. 404 for a key the agent has no sign-in under; 409 `sign_in_held` while a run holds its save lease (`details.held_by`), until that run ends.",
|
|
1002
|
+
parameters: [ref("parameters/AgentId"), { name: "key", in: "path", required: true, description: "The sign-in's key, as GET /agents/{agent_id} lists it (`default`).", schema: { type: "string" } }],
|
|
1003
|
+
responses: {
|
|
1004
|
+
"200": json({ type: "object", additionalProperties: false, required: ["key", "removed"], properties: { key: { type: "string" }, removed: { type: "array", items: { type: "object", additionalProperties: false, required: ["provider", "at_vendor"], properties: { provider: { type: "string" }, at_vendor: { enum: ["deleted", "not_deleted"] }, message: { type: "string" } } } } } }, "Forgotten: what was deleted at each vendor."),
|
|
1005
|
+
...errors(400, 401, 404, 409, 429, 500),
|
|
1006
|
+
},
|
|
1007
|
+
"x-agentrun-serve": "signins/1",
|
|
1008
|
+
},
|
|
1009
|
+
},
|
|
1010
|
+
"/settings/webhook": {
|
|
1011
|
+
get: {
|
|
1012
|
+
operationId: "getWebhook", tags: ["local"], summary: "The webhook this server POSTs run notices to, if one is set; never its secret",
|
|
1013
|
+
responses: { "200": json(WEBHOOK_VIEW, "The webhook, or `configured: false`."), ...errors(401, 429, 500) },
|
|
1014
|
+
"x-agentrun-serve": "webhook/1",
|
|
1015
|
+
},
|
|
1016
|
+
put: {
|
|
1017
|
+
operationId: "saveWebhook", tags: ["local"], summary: "Set the webhook's URL",
|
|
1018
|
+
description: `Messages follow the Standard Webhooks spec (standardwebhooks.com), so a receiver verifies them with any of its libraries. Each is POSTed to \`url\` as JSON \`{type, timestamp, data}\`: \`run.needs_input\` when a run comes to need its person (status input_required; \`data.pending.kind\` \`question\` for an ask_person question, \`approval\` for a tool call that waits for a person's approval, \`stopped\` for a stopped turn, \`budget\` for a run paused at its spend cap) and \`run.ended\` when it ends (completed, failed or cancelled), with \`data: {run_id, agent_id, status, title, url}\`, \`url\` the run on the page; and \`trigger.failed\` when a trigger's firing could not start its run (/triggers), with \`data: {trigger_id, name, firing_key, nominal_at, error: {code, message}, auto_paused}\`, \`auto_paused\` true when it was the ${FAILURES_TO_PAUSE}th in a row and turned the trigger off, its \`webhook-id\` the same for the same firing, after a restart too; never a tool's arguments, an output or an input, which the API reads. Headers: \`webhook-id\` (the same on every try, the receiver's idempotency key), \`webhook-timestamp\` (Unix seconds) and \`webhook-signature: v1,<base64 HMAC-SHA256 of "{id}.{timestamp}.{body}">\` under the secret's 32 bytes; a receiver refuses a timestamp more than 5 minutes from its clock. A try not answered 2xx in 15 s (no redirect followed) is tried again after about 5 s, 5 min, 30 min, 2 h, 5 h and 10 h, with jitter, then logged as failed; pending messages go on after a restart. A 410 turns the webhook off until it is set again. The first PUT makes the secret and answers 201 with it, once; a later PUT keeps it, turns the webhook on again and answers 200. 422 for a URL that is not http or https, holds a user or password, or is over 2048 characters; 409 no_sealing_key when the server was handed no seal key to keep the secret under.`,
|
|
1019
|
+
requestBody: { required: true, content: { "application/json": { schema: { type: "object", additionalProperties: false, required: ["url"], properties: { url: { type: "string", format: "uri", maxLength: 2048 } } } } } },
|
|
1020
|
+
responses: {
|
|
1021
|
+
"201": json(closed({ ...WEBHOOK_SET_FIELDS, secret: WEBHOOK_SECRET }), "Set, with its secret, shown this once."),
|
|
1022
|
+
"200": json(WEBHOOK_SET, "Changed; the secret is kept."),
|
|
1023
|
+
...errors(400, 401, 409, 415, 422, 429, 500),
|
|
1024
|
+
},
|
|
1025
|
+
"x-agentrun-serve": "webhook/1",
|
|
1026
|
+
},
|
|
1027
|
+
delete: {
|
|
1028
|
+
operationId: "deleteWebhook", tags: ["local"], summary: "Remove the webhook; its pending messages are dropped, the log of attempts is kept",
|
|
1029
|
+
responses: { "204": { description: "Removed." }, ...errors(401, 429, 500) },
|
|
1030
|
+
"x-agentrun-serve": "webhook/1",
|
|
1031
|
+
},
|
|
1032
|
+
},
|
|
1033
|
+
"/settings/webhook/test": {
|
|
1034
|
+
post: {
|
|
1035
|
+
operationId: "testWebhook", tags: ["local"], summary: "Send a `webhook.test` message now, once, and say how it went",
|
|
1036
|
+
description: "The body is `{type: \"webhook.test\", timestamp, data: {}}`, signed as every message is. It is tried once, never again, and kept in the log. 409 webhook_off when a 410 turned the webhook off: nothing is sent until a PUT sets it again.",
|
|
1037
|
+
responses: { "200": json(WEBHOOK_ATTEMPT, "Its attempt."), ...errors(401, 404, 409, 429, 500) },
|
|
1038
|
+
"x-agentrun-serve": "webhook/1",
|
|
1039
|
+
},
|
|
1040
|
+
},
|
|
1041
|
+
"/settings/webhook/deliveries": {
|
|
1042
|
+
get: {
|
|
1043
|
+
operationId: "listWebhookDeliveries", tags: ["local"], summary: `The last ${ATTEMPTS_KEPT} attempts, newest first`,
|
|
1044
|
+
responses: { "200": json(closed({ attempts: { type: "array", items: WEBHOOK_ATTEMPT } }), "Each attempt."), ...errors(401, 429, 500) },
|
|
1045
|
+
"x-agentrun-serve": "webhook/1",
|
|
1046
|
+
},
|
|
1047
|
+
},
|
|
1048
|
+
"/triggers": {
|
|
1049
|
+
get: {
|
|
1050
|
+
operationId: "listTriggers", tags: ["local"], summary: "The triggers: schedules that start an agent's capped runs",
|
|
1051
|
+
description: TRIGGER_ERRORS,
|
|
1052
|
+
responses: { "200": json(closed({ triggers: { type: "array", items: TRIGGER } }), "Each trigger, oldest first, with its last firing."), ...errors(401, 409, 429, 500) },
|
|
1053
|
+
...TRIGGER_MARK,
|
|
1054
|
+
},
|
|
1055
|
+
post: {
|
|
1056
|
+
operationId: "createTrigger", tags: ["local"], summary: "Make a trigger: a schedule or a signed webhook that starts a capped run of an agent, or messages a run",
|
|
1057
|
+
description: `Each firing starts one run of \`target.agent_id\` with \`target.input\` and its \`max_cost_usd\` (else the agent's default), as POST /agents/{agent_id}/runs would, and the run's \`trigger\` names it. A firing starts its run once, across retries and restarts. While the trigger's last run is active (working, or waiting on a person: a question, an approval, its cap), a firing is skipped. The last ${HISTORY_KEPT} firings are kept. A \`webhook\` source fires on each request to /hooks/{trigger_id} signed by its secret, which this answer holds (\`secret\`) this once: a retry under the same Idempotency-Key answers the same trigger with a \`note\` in its place, as the key's record never keeps a secret. A \`message_run\` target sends each firing's input to one run, under the firing's key, which the run's store takes once. 422 for another source kind, a start_run target with no max_cost_usd whose agent has no default one, an agent that is a workflow or does not take the input, or a run that is a workflow's; 409 no_sealing_key for a webhook trigger on a server handed no seal key.`,
|
|
1058
|
+
parameters: [ref("parameters/IdempotencyKey")],
|
|
1059
|
+
requestBody: { required: true, content: { "application/json": { schema: { type: "object", additionalProperties: false, required: ["source", "target"], properties: TRIGGER_WRITE } } } },
|
|
1060
|
+
responses: { "201": json({ ...TRIGGER, properties: { ...TRIGGER.properties, secret: TRIGGER_SECRET, note: { type: "string", description: "On a retry under the same Idempotency-Key, in place of a webhook trigger's secret: it was shown once, and POST /triggers/{trigger_id}/secret makes a new one." } } }, "Made; a webhook trigger's first answer holds its `secret`, this once."), ...errors(400, 401, 409, 415, 422, 429, 500) },
|
|
1061
|
+
...TRIGGER_MARK,
|
|
1062
|
+
},
|
|
1063
|
+
},
|
|
1064
|
+
"/triggers/{trigger_id}": {
|
|
1065
|
+
get: {
|
|
1066
|
+
operationId: "getTrigger", tags: ["local"], summary: "One trigger",
|
|
1067
|
+
parameters: [TRIGGER_ID],
|
|
1068
|
+
responses: { "200": json(TRIGGER, "The trigger."), ...errors(401, 404, 409, 429, 500) },
|
|
1069
|
+
...TRIGGER_MARK,
|
|
1070
|
+
},
|
|
1071
|
+
patch: {
|
|
1072
|
+
operationId: "updateTrigger", tags: ["local"], summary: "Change a trigger, or turn it off and on",
|
|
1073
|
+
description: "Any of its fields. `enabled: false` stops its firings; `enabled: true` again, or a new source, goes on from now: the time it was off is skipped, never caught up. A firing already due goes on.",
|
|
1074
|
+
parameters: [TRIGGER_ID],
|
|
1075
|
+
requestBody: { required: true, content: { "application/json": { schema: { type: "object", additionalProperties: false, properties: TRIGGER_WRITE } } } },
|
|
1076
|
+
responses: { "200": json(TRIGGER, "Changed."), ...errors(400, 401, 404, 409, 415, 422, 429, 500) },
|
|
1077
|
+
...TRIGGER_MARK,
|
|
1078
|
+
},
|
|
1079
|
+
delete: {
|
|
1080
|
+
operationId: "deleteTrigger", tags: ["local"], summary: "Delete a trigger and its firings; the runs it started stay",
|
|
1081
|
+
parameters: [TRIGGER_ID],
|
|
1082
|
+
responses: { "204": { description: "Deleted." }, ...errors(401, 404, 409, 429, 500) },
|
|
1083
|
+
...TRIGGER_MARK,
|
|
1084
|
+
},
|
|
1085
|
+
},
|
|
1086
|
+
"/triggers/{trigger_id}/fire": {
|
|
1087
|
+
post: {
|
|
1088
|
+
operationId: "fireTrigger", tags: ["local"], summary: "Run it now: one firing per Idempotency-Key",
|
|
1089
|
+
description: "A firing now, on or off, under the same overlap rule as a scheduled one; it is driven before the answer. The same key again answers its firing as it stands (200, `Idempotent-Replayed: true`), and starts no second run, for `limits.idempotency_ttl_s` after it fired, even once the firing has left the history; past that it is a new firing, which a run the key started still answers. A firing never moves `last_run_id` back to an older run. 400 with no Idempotency-Key. 429 `rate_limited`, with Retry-After, while the trigger holds " + DUE_KEPT + " firings due.",
|
|
1090
|
+
parameters: [TRIGGER_ID, { name: "Idempotency-Key", in: "header", required: true, description: "Required here: a retry with the same key fires once.", schema: { type: "string", minLength: 1, maxLength: 255 } }],
|
|
1091
|
+
responses: { "202": json(TRIGGER_FIRING, "Fired: its run started, or why not."), "200": json(TRIGGER_FIRING, "This key's firing, as it stands."), ...errors(400, 401, 404, 409, 429, 500) },
|
|
1092
|
+
...TRIGGER_MARK,
|
|
1093
|
+
},
|
|
1094
|
+
},
|
|
1095
|
+
"/triggers/{trigger_id}/secret": {
|
|
1096
|
+
post: {
|
|
1097
|
+
operationId: "rotateTriggerSecret", tags: ["local"], summary: "A webhook trigger's new secret, shown once; the old one signs nothing from now on",
|
|
1098
|
+
description: "422 for a trigger that is not a webhook's; 409 no_sealing_key when the server was handed no seal key.",
|
|
1099
|
+
parameters: [TRIGGER_ID],
|
|
1100
|
+
responses: { "200": json(closed({ secret: TRIGGER_SECRET }), "The new secret, this once."), ...errors(401, 404, 409, 422, 429, 500) },
|
|
1101
|
+
...TRIGGER_MARK,
|
|
1102
|
+
},
|
|
1103
|
+
},
|
|
1104
|
+
"/hooks/{trigger_id}": {
|
|
1105
|
+
post: {
|
|
1106
|
+
operationId: "receiveHook", tags: ["local"], summary: "Fire a webhook trigger: a request signed by its secret, no token",
|
|
1107
|
+
description: `This server's one route with no token: the request's signature is its credential, checked on the raw body before anything else. It follows the Standard Webhooks spec, so a sender signs with any of its libraries: \`webhook-id\` (1 to 255 printable ASCII characters, no space; the firing's idempotency key), \`webhook-timestamp\` (Unix seconds, within ${HOOK_TOLERANCE_S} s of this server's clock either way) and \`webhook-signature\`, space-separated \`v1,<base64 HMAC-SHA256 of "{webhook-id}.{webhook-timestamp}.{body}">\` under the secret's 32 bytes (at most 2048 characters in all), any one of which may match. The body's bytes are signed as sent, whatever its content type. The body is any text, at most 256 KiB (413 past it); its first ${PAYLOAD_KEPT_BYTES / 1024} KiB reach the agent inside \`<trigger-payload source="webhook" untrusted>\`. A bad or missing signature, a stale or future timestamp, an unknown trigger, one that is off and one that is not a webhook's all answer the same 401. The first request with a webhook-id answers 202 once its firing is recorded, and its run starts after; the same webhook-id again, for a day after, answers 200 with that firing and starts nothing. A trigger holds at most ${DUE_KEPT} firings due (a message_run firing waits while its run works): past them a new webhook-id answers 429 \`rate_limited\` with Retry-After and records nothing, so the sender sends it again later.`,
|
|
1108
|
+
security: [],
|
|
1109
|
+
parameters: [TRIGGER_ID],
|
|
1110
|
+
requestBody: { required: true, content: { "*/*": { schema: {} } } },
|
|
1111
|
+
responses: { "202": json(TRIGGER_FIRING, "Recorded: its run starts (or its message goes) after this answer."), "200": json(TRIGGER_FIRING, "This webhook-id's firing, as it stands."), ...errors(401, 413, 429, 500) },
|
|
1112
|
+
...TRIGGER_MARK,
|
|
1113
|
+
},
|
|
1114
|
+
},
|
|
1115
|
+
"/triggers/{trigger_id}/firings": {
|
|
1116
|
+
get: {
|
|
1117
|
+
operationId: "listTriggerFirings", tags: ["local"], summary: `The trigger's last ${HISTORY_KEPT} firings, newest first`,
|
|
1118
|
+
parameters: [TRIGGER_ID],
|
|
1119
|
+
responses: { "200": json(closed({ firings: { type: "array", items: TRIGGER_FIRING } }), "Each firing."), ...errors(401, 404, 409, 429, 500) },
|
|
1120
|
+
...TRIGGER_MARK,
|
|
1121
|
+
},
|
|
1122
|
+
},
|
|
1123
|
+
"/settings/webhook/deliveries/{webhook_id}/redeliver": {
|
|
1124
|
+
post: {
|
|
1125
|
+
operationId: "redeliverWebhook", tags: ["local"], summary: "Send a message of the log again, once now, under the same webhook-id and body",
|
|
1126
|
+
description: "Signed again at a new timestamp. A message still pending that this try delivers is settled; one this try fails keeps its own schedule. 409 webhook_off when a 410 turned the webhook off.",
|
|
1127
|
+
parameters: [WEBHOOK_ID],
|
|
1128
|
+
responses: { "200": json(WEBHOOK_ATTEMPT, "Its attempt."), ...errors(401, 404, 409, 429, 500) },
|
|
1129
|
+
"x-agentrun-serve": "webhook/1",
|
|
1130
|
+
},
|
|
1131
|
+
},
|
|
1132
|
+
};
|
|
1133
|
+
let vendored;
|
|
1134
|
+
/** Why an escalated workflow run waits for a person. Such a run is `completed` with no error and no output; every other
|
|
1135
|
+
* run's review is null. */
|
|
1136
|
+
const REVIEW = {
|
|
1137
|
+
oneOf: [
|
|
1138
|
+
{
|
|
1139
|
+
type: "object", additionalProperties: false, required: ["kind", "node", "reason", "at"],
|
|
1140
|
+
properties: {
|
|
1141
|
+
kind: { type: ["string", "null"], description: "The escalation's kind, as its escalate node names it (`coi_review`, say)." },
|
|
1142
|
+
node: { type: ["string", "null"], description: "The label of the node the run escalated at." },
|
|
1143
|
+
reason: { type: "string", description: "The escalation's summary: what the person is to look at." },
|
|
1144
|
+
at: { type: "string", format: "date-time", description: "When the run ended: its `ended_at`, one saved time." },
|
|
1145
|
+
},
|
|
1146
|
+
},
|
|
1147
|
+
{ type: "null" },
|
|
1148
|
+
],
|
|
1149
|
+
description: "Set when a workflow run escalated: it completed, and waits for a person to review it. Like every workflow run, it takes no messages (501 unsupported_here).",
|
|
1150
|
+
"x-agentrun-serve": "review/1",
|
|
1151
|
+
};
|
|
1152
|
+
const LEARNING_NULL = "Null for a run that does not learn: its agent's `learning` is not true, the server's learning was off when it started (`capabilities.features.learning`), or it is a workflow's or an imported run.";
|
|
1153
|
+
/** A run's learning (runs.ts): whether it started from what its agent learned. */
|
|
1154
|
+
const LEARNING = {
|
|
1155
|
+
oneOf: [
|
|
1156
|
+
closedWith({
|
|
1157
|
+
state: { enum: [...LEARNING_STATES], description: "`seeded` when the run started from what its agent learned; `reflecting` while its end-of-run turn runs, and until what it wrote is checked (after the run ended, so it may still read `reflecting` once the run reads completed or failed); `proposed` once the new notes passed the checks, while they are graded; `merged` once they are on the folder's main; `dropped` when learning was skipped or refused, with `reason`." },
|
|
1158
|
+
reason: LEARNING_REASON,
|
|
1159
|
+
detail: { type: ["string", "null"], maxLength: 300, description: "Where the run's learning stands, in one sentence in a person's words (at most 300 characters, ending in an ellipsis when cut; a note's name or the grader's reason in it is cut of the host's secrets as they are now before it is cut short, so none is shown in part), the same as its timeline row says: \"Started from 2 notes.\", \"Looking back on this run…\", \"Checking 1 new note…\", \"Learned: <note's name> (replaces 1 older note)\", \"Learned: <note's name>. Waiting for your OK: <note's name>.\", \"Nothing new to remember from this run.\", \"Not kept: <the grader's reason, its first sentence>\", \"Not kept: its notes weren't in the expected format.\", \"Not kept: learning stopped (<why>).\" and so on. Never a secret or a value from the input, cut of the host's secrets as they are now. For a person: a client that acts on it reads `state` and `reason`, whose codes do not change." },
|
|
1160
|
+
at: { type: "string", format: "date-time", description: "When the state last changed." },
|
|
1161
|
+
}, RUN_NOTES),
|
|
1162
|
+
{ type: "null" },
|
|
1163
|
+
],
|
|
1164
|
+
description: `What the run learns from and what it learned: a run of an agent whose \`learning\` is true starts from its active notes, whole, in its instructions within the learning budget (past it, the index and the notes changed last, whole), and from the notes in \`.learning/\` in its working directory. Once it answers or fails, the server asks the same harness one more turn, under the run's cap, which answers with the notes it would keep (no tool is needed, and nothing the run writes in \`.learning/\` counts); what it answers is checked, graded by one grader (on the server's grade model or strong tier, else the agent's own model), and merged into the folder, or dropped. ${LEARNING_NULL}`,
|
|
1165
|
+
"x-agentrun-serve": "learning/1",
|
|
1166
|
+
};
|
|
1167
|
+
const LEARNING_SHORT = {
|
|
1168
|
+
oneOf: [closedWith({
|
|
1169
|
+
state: { enum: [...LEARNING_STATES] }, reason: LEARNING_REASON,
|
|
1170
|
+
detail: { type: ["string", "null"], maxLength: 140, description: "Run.learning's detail, in the same words, cut short: at most 140 characters, ending in an ellipsis when cut (a grader's long reason). Cut of the host's secrets first, so none is ever shown in part.", "x-agentrun-serve": "learning/2" },
|
|
1171
|
+
}, RUN_NOTES), { type: "null" }],
|
|
1172
|
+
description: `The run's learning, in short (GET /runs/{run_id} has it whole, with its whole detail and its time). ${LEARNING_NULL}`,
|
|
1173
|
+
"x-agentrun-serve": "learning/1",
|
|
1174
|
+
};
|
|
1175
|
+
/** What this server's run answers carry beyond the contract's Run and RunSummary: added before they were marked, so
|
|
1176
|
+
* `serve/1`. */
|
|
1177
|
+
const RUN_FIELDS = {
|
|
1178
|
+
revision: { type: "string", description: "The id of the agent revision the run runs.", "x-agentrun-serve": "serve/1" },
|
|
1179
|
+
kind: { enum: ["agentic", "workflow"], description: "The revision's kind: an agentic run, or a workflow run.", "x-agentrun-serve": "serve/1" },
|
|
1180
|
+
archived_at: { type: ["string", "null"], description: "When the run, or its agent, was archived, while it is; else null.", "x-agentrun-serve": "serve/1" },
|
|
1181
|
+
};
|
|
1182
|
+
/** What a run waits on, one field for every kind, told apart by `kind`: a question it asked a person, or a tool call
|
|
1183
|
+
* that waits for approval. */
|
|
1184
|
+
const PENDING = {
|
|
1185
|
+
oneOf: [
|
|
1186
|
+
{
|
|
1187
|
+
type: "object", additionalProperties: false, required: ["kind", "question", "asked_at"],
|
|
1188
|
+
properties: { kind: { const: "question" }, question: { type: "string", description: "What it asked, at most 2000 characters." }, asked_at: { type: "string", format: "date-time" } },
|
|
1189
|
+
description: "A question the run asked a person (status input_required, state waiting): a message answers it.",
|
|
1190
|
+
},
|
|
1191
|
+
{
|
|
1192
|
+
type: "object", additionalProperties: false, required: ["kind", "id", "tool", "call_id", "args_preview", "requested_at"],
|
|
1193
|
+
properties: {
|
|
1194
|
+
kind: { const: "approval" },
|
|
1195
|
+
id: { type: "string", description: "Answered at POST /runs/{run_id}/approvals/{id}; the same for the same call after a restart." },
|
|
1196
|
+
tool: { type: "string" },
|
|
1197
|
+
call_id: { type: "string", description: "The call's id, as its tool_result row's tool_use_id." },
|
|
1198
|
+
args_preview: { type: "string", maxLength: ARGS_PREVIEW_BYTES, description: `The call's arguments as JSON, cut at ${ARGS_PREVIEW_BYTES} bytes.` },
|
|
1199
|
+
requested_at: { type: "string", format: "date-time" },
|
|
1200
|
+
price: { oneOf: [{ type: "number", minimum: 0 }, { const: "not metered" }], description: "What the call costs, in USD, where its tool declares a price; \"not metered\" for an unpriced MCP call. Absent when the tool names none." },
|
|
1201
|
+
},
|
|
1202
|
+
description: "A tool call set to ask waits for the owner's approval (status input_required, state waiting): POST /runs/{run_id}/approvals/{id} answers it.",
|
|
1203
|
+
"x-agentrun-serve": "approvals/1",
|
|
1204
|
+
},
|
|
1205
|
+
{
|
|
1206
|
+
type: "object", additionalProperties: false, required: ["kind", "cap_usd", "said", "at"],
|
|
1207
|
+
properties: {
|
|
1208
|
+
kind: { const: "budget" },
|
|
1209
|
+
cap_usd: { type: "number", exclusiveMinimum: 0, description: "The run's cap (`max_cost_usd`)." },
|
|
1210
|
+
spent_usd: { type: "number", minimum: 0, description: "What the cap counted as taken when it refused: spent, and held for requests still answering; once the paused process is gone, the store's spend when that is lower (those requests settled). Absent for a refusal written before the figures were kept." },
|
|
1211
|
+
needs_usd: { type: "number", minimum: 0, description: "The least the refused request needs. A cap above `spent_usd` + `needs_usd` sends it. Absent with `spent_usd`." },
|
|
1212
|
+
suggested_cap_usd: { type: "number", exclusiveMinimum: 0, description: "The raise this run is offered: `spent_usd` + 10 × `needs_usd`, rounded up to a whole dollar, and always above `cap_usd`, so `PATCH /runs/{run_id}` with it as `max_cost_usd` is a raise that resumes the run. Absent with `spent_usd`." },
|
|
1213
|
+
said: { type: "string", description: "The cap's refusal, in its words: what was spent, what the refused request needs at the least, and the cap that would run it. At most 2000 characters." },
|
|
1214
|
+
at: { type: "string", format: "date-time", description: "When the request was refused." },
|
|
1215
|
+
},
|
|
1216
|
+
description: "A run paused at its spend cap (status input_required, state waiting): what is left of the cap cannot buy its next request's least, which was not sent. A message is 409 budget_reached until the cap is raised. Only a refusal for room pauses a run, a paid tool call's as a model request's (its hold is needs_usd); one no cap fixes (an unknown spend, a model with no price or no output ceiling, an input not measured) still ends it failed, spend_cap_reached.",
|
|
1217
|
+
"x-agentrun-serve": "cappause/1",
|
|
1218
|
+
},
|
|
1219
|
+
{ type: "null" },
|
|
1220
|
+
],
|
|
1221
|
+
description: "What the run waits on, told apart by kind; null when it waits on nothing. A run read from its stored row alone has ended, so null.",
|
|
1222
|
+
"x-agentrun-serve": "pending/1",
|
|
1223
|
+
};
|
|
1224
|
+
/** This server's own properties on the contract's objects, outside the contract, by where they go (a schema of
|
|
1225
|
+
* components.schemas, then property names down to the object that takes them). Each is marked x-agentrun-serve with
|
|
1226
|
+
* the addition that made it: `harness/1` and `place/1` are ones a later contract version would take on; `model/1` and
|
|
1227
|
+
* `serve/1` are what this server added before it marked them. */
|
|
1228
|
+
/** A run's place, as its start resolved it. */
|
|
1229
|
+
const RUN_PLACE = {
|
|
1230
|
+
oneOf: [
|
|
1231
|
+
{ type: "object", additionalProperties: false, required: ["mode"], properties: { mode: { const: "runner" } } },
|
|
1232
|
+
{ type: "object", additionalProperties: false, required: ["mode", "box"], properties: { mode: { const: "sandbox" }, box: { enum: [...BOX_IDS] } } },
|
|
1233
|
+
],
|
|
1234
|
+
description: "Where the run executes, as its start resolved it: its revision's place, else runner. In a sandbox place the agent's bash runs in the box, which binds only the run's work/ and has no network and no key; read, write and edit run in the box too, or on this server's copy of that work/ where the box binds it and this server holds directory handles (Docker on Linux), following no link. Its loop, its log and every key stay on the server. The Modal sandbox (box `modal`, Modal's default gVisor runtime, not a VM) never has a network: Modal takes a host list, but this server cannot read a sandbox's list back to check that it holds, so each is made blocked, and capabilities.places.boxes says so in its network_reason (unless AGENTRUN_BOX_ALLOW is none).",
|
|
1235
|
+
"x-agentrun-serve": "place/1",
|
|
1236
|
+
};
|
|
1237
|
+
/** costsofar/1: a cost no one fully knows, said as what is known and how much is not, with no ceiling claimed. */
|
|
1238
|
+
const SO_FAR = {
|
|
1239
|
+
so_far_usd: { type: "number", minimum: 0, description: "Set only while `usd` is null: the sum of the charges whose cost is known (model requests, a workflow's decisions, paid tool calls). Never the cost: the charges counted in `unpriced` are not in it, and nothing bounds them.", "x-agentrun-serve": "costsofar/1" },
|
|
1240
|
+
unpriced: { type: "integer", minimum: 1, description: "Set only while `usd` is null: how many charges have no known cost (a model request cut, stopped, still pending or with no price; a decision whose cost is unknown; a paid tool call charged an unknown amount or cut).", "x-agentrun-serve": "costsofar/1" },
|
|
1241
|
+
};
|
|
1242
|
+
const FIELD_EXTENSIONS = {
|
|
1243
|
+
Cost: SO_FAR,
|
|
1244
|
+
TimelineUsage: SO_FAR,
|
|
1245
|
+
Run: {
|
|
1246
|
+
...RUN_FIELDS,
|
|
1247
|
+
last_progress_at: {
|
|
1248
|
+
type: ["string", "null"],
|
|
1249
|
+
format: "date-time",
|
|
1250
|
+
description: "While a message the run took is still open (an agentic run, working or queued): when its turn last wrote anything, a request's start included; it holds still while a tool or a model request runs, and moves as the turn writes. Null once every message has had its turn, and on a workflow run.",
|
|
1251
|
+
"x-agentrun-serve": "turnend/1",
|
|
1252
|
+
},
|
|
1253
|
+
place: RUN_PLACE,
|
|
1254
|
+
learning: LEARNING,
|
|
1255
|
+
review: REVIEW,
|
|
1256
|
+
pending: PENDING,
|
|
1257
|
+
imported_from: {
|
|
1258
|
+
type: ["object", "null"],
|
|
1259
|
+
additionalProperties: false,
|
|
1260
|
+
required: ["source", "session"],
|
|
1261
|
+
properties: { source: { enum: ["claude-code", "codex", "pi"] }, session: { type: "string", description: "The session's id in its source." } },
|
|
1262
|
+
description: "Imported history (`agentrun-serve import`): where the run was run, and its session there; else null. An imported run takes no message (`409 not_continuable`, `details.reason` `imported`); a stop or a cancel answers as for an ended run.",
|
|
1263
|
+
"x-agentrun-serve": "imported/1",
|
|
1264
|
+
},
|
|
1265
|
+
trigger: RUN_TRIGGER,
|
|
1266
|
+
},
|
|
1267
|
+
InputIssue: { code: { type: "string", description: "A workflow definition's issue: the DSL's validation code (`STATE_PATH_UNPRODUCED`, say), with `field` the path to it under `definition.workflow`.", "x-agentrun-serve": "validate/1" } },
|
|
1268
|
+
RunSummary: {
|
|
1269
|
+
...RUN_FIELDS,
|
|
1270
|
+
effort: { $ref: "#/components/schemas/Effort", description: "The effort the run was started with, as the run shows it; absent when it was started with none.", "x-agentrun-serve": "effort/1" },
|
|
1271
|
+
error: { oneOf: [{ $ref: "#/components/schemas/RunError" }, { type: "null" }], description: "Set when `failed`, as the run's own.", "x-agentrun-serve": "serve/1" },
|
|
1272
|
+
learning: LEARNING_SHORT,
|
|
1273
|
+
review: REVIEW,
|
|
1274
|
+
pending: PENDING,
|
|
1275
|
+
imported_from: {
|
|
1276
|
+
type: ["object", "null"],
|
|
1277
|
+
additionalProperties: false,
|
|
1278
|
+
required: ["source", "session"],
|
|
1279
|
+
properties: { source: { enum: ["claude-code", "codex", "pi"] }, session: { type: "string", description: "The session's id in its source." } },
|
|
1280
|
+
description: "Imported history (`agentrun-serve import`): where the run was run, and its session there; else null. An imported run takes no message (`409 not_continuable`, `details.reason` `imported`); a stop or a cancel answers as for an ended run.",
|
|
1281
|
+
"x-agentrun-serve": "imported/1",
|
|
1282
|
+
},
|
|
1283
|
+
trigger: RUN_TRIGGER,
|
|
1284
|
+
},
|
|
1285
|
+
RunError: {
|
|
1286
|
+
details: {
|
|
1287
|
+
type: "object", additionalProperties: false, required: ["reason"],
|
|
1288
|
+
properties: { reason: { enum: [LAUNCH_LOST, SETUP_LOST] } },
|
|
1289
|
+
description: `Why the run failed, when its code alone does not say: \`${LAUNCH_LOST}\`, the server went down while it started the run's process, which never came up, so the next start failed the run rather than start it again; \`${SETUP_LOST}\`, the server went down after the run was made and before it was set up, so it never started.`,
|
|
1290
|
+
"x-agentrun-serve": "launch/1",
|
|
1291
|
+
},
|
|
1292
|
+
},
|
|
1293
|
+
TimelineRow: {
|
|
1294
|
+
origin: {
|
|
1295
|
+
const: "server",
|
|
1296
|
+
description: "On the row of a message the server wrote into the run (a raised cap's follow-up, an approval's resume): a `phase` row, \"AgentRun: <its first line>\", where a person's message would be a `user_message` one. It counts, as a person's does, as the message its turn took. Absent on every other row.",
|
|
1297
|
+
"x-agentrun-serve": "origin/1",
|
|
1298
|
+
},
|
|
1299
|
+
learning: {
|
|
1300
|
+
...closed({ state: { enum: [...LEARNING_STATES] }, reason: LEARNING_REASON, detail: { type: ["string", "null"] } }),
|
|
1301
|
+
description: `On a row of kind \`learning\` alone, labelled \`${LEARNING_LABEL}\`: where the run's learning ended (proposed, merged or dropped, \`seed_failed\` included), and why: one row, changed in place as it moves. Its \`summary\` and \`text\` are its \`detail\` (Run.learning.detail), in a person's words. The rows of the run's end-of-run turn are labelled \`${LEARNING_LABEL}\` too, its message and answer included, and are never the run's answer.`,
|
|
1302
|
+
"x-agentrun-serve": "learning/1",
|
|
1303
|
+
},
|
|
1304
|
+
},
|
|
1305
|
+
ErrorBody: {
|
|
1306
|
+
problems: { type: "array", items: PROBLEM, description: "`bad_request` from a write of a learning note only: each structural check it fails, printable (never a secret).", "x-agentrun-serve": "learning/1" },
|
|
1307
|
+
},
|
|
1308
|
+
RunFile: {
|
|
1309
|
+
unreadable: { type: "boolean", const: true, description: "Present when this server cannot read the file: a tool in the run's box created it private (owner-only). Reading it answers 403 `system_file_forbidden` with `details.reason` `unreadable`.", "x-agentrun-serve": "unreadable/1" },
|
|
1310
|
+
},
|
|
1311
|
+
DefinitionInput: {
|
|
1312
|
+
model: { type: "string", description: "`provider/model-id`, the model an agentic revision runs on; absent, this host's default. A workflow revision keeps none.", "x-agentrun-serve": "model/1" },
|
|
1313
|
+
thinking: { enum: [...THINKING_LEVELS], description: "An agentic revision's thinking level; absent, the model's. A workflow revision keeps none.", "x-agentrun-serve": "model/1" },
|
|
1314
|
+
harness: { enum: [...HARNESSES], description: "The harness that runs the revision. Absent on a request, pi; every answer names it. One this server does not run saves with a warning, and its runs are 409 agent_not_runnable naming it (capabilities.harnesses).", "x-agentrun-serve": "harness/1" },
|
|
1315
|
+
place: {
|
|
1316
|
+
oneOf: [
|
|
1317
|
+
{ type: "object", additionalProperties: false, required: ["mode"], properties: { mode: { const: "runner" } } },
|
|
1318
|
+
{ type: "object", additionalProperties: false, required: ["mode", "box"], properties: { mode: { const: "sandbox" }, box: { enum: [...BOX_IDS] } } },
|
|
1319
|
+
],
|
|
1320
|
+
description: "Where the revision's runs execute: `runner` (no box and no shell) or `sandbox` (the agent's file and shell tools run in the box; its loop, its log and every key stay on the server). Absent on a create of an agentic revision, the place this server gives a new agent (capabilities.places.default_place): the Docker box where this server has docker, ready or preparing, written on the revision so an answer shows it, with tools [\"bash\"] when the definition names no tools (a list it names, an empty one included, is kept as named); where docker is unavailable, or the definition names a tool a box refuses (browser), none, as before. A revision saved with no place (before this, where docker was unavailable, or a workflow) runs on the runner (capabilities.places.default), whatever this server has now. A revision keeps the place it names, runner included. An edit that names none keeps the agent's. A box this server does not have saves with a warning, and its runs are 409 agent_not_runnable naming it (capabilities.places.boxes). Only an agentic revision in a sandbox place may name `bash` or a background tool (`bash_background`, `bash_output`, `bash_input`, `bash_signal`, `bash_list`); a workflow revision's place is runner or none (a sandbox place is 422).",
|
|
1321
|
+
"x-agentrun-serve": "place/1",
|
|
1322
|
+
},
|
|
1323
|
+
tool_settings: { ...TOOL_SETTINGS, description: "The agent's own tool settings (web_search's, web_fetch's and browser's provider, any tool's permission, an MCP server's wildcard mcp:<server>/*), over the server's (GET /settings/tools); absent, the server's. A grant in tools names the capability, never a provider.", "x-agentrun-serve": "providers/1" },
|
|
1324
|
+
learning: { type: "boolean", default: false, description: "Whether an agentic revision's runs learn: each starts from what its agent has learned, its notes in its instructions under `# Learned` (each whole within the server's learning budget, else the index and the notes changed last, whole) and in `.learning/` in its working directory, and once it answers or fails is asked one more turn to add notes there, which are checked, graded and merged. Kept when a definition says so, true or false; absent, off, and an answer shows none. An edit that leaves it out keeps the agent's. A workflow revision keeps none. On a server whose learning is off (`capabilities.features.learning`), no run learns, whatever this says.", "x-agentrun-serve": "learning/1" },
|
|
1325
|
+
},
|
|
1326
|
+
AgentCreate: {
|
|
1327
|
+
note: { type: "string", maxLength: 2000, description: "What the revision changes, kept with it (GET /agents/{agent_id}/revisions).", "x-agentrun-serve": "definitionbody/1" },
|
|
1328
|
+
},
|
|
1329
|
+
Agent: {
|
|
1330
|
+
tools: AGENT_TOOLS,
|
|
1331
|
+
kind: { enum: ["agentic", "workflow", null], description: "The current revision's kind; null before the agent has one.", "x-agentrun-serve": "serve/1" },
|
|
1332
|
+
revision: { type: ["string", "null"], description: "The current revision's id; null before the agent has one.", "x-agentrun-serve": "serve/1" },
|
|
1333
|
+
revisions: { type: "integer", minimum: 0, description: "How many revisions the agent has.", "x-agentrun-serve": "serve/1" },
|
|
1334
|
+
archived_at: { type: ["string", "null"], description: "When the agent was archived, while it is; else null.", "x-agentrun-serve": "serve/1" },
|
|
1335
|
+
},
|
|
1336
|
+
Capabilities: {
|
|
1337
|
+
learning: {
|
|
1338
|
+
type: "object", additionalProperties: false, required: ["grade_model", "pending", "approve"],
|
|
1339
|
+
properties: {
|
|
1340
|
+
grade_model: { type: ["string", "null"], description: "The model that grades what a run proposes to learn: `--grade-model` (AGENTRUN_SERVE_GRADE_MODEL), else the strong tier (AGENT_MODEL_STRONG), named as the strong tier takes one; null when the server names none, and each run is graded on its agent's own model." },
|
|
1341
|
+
pending: { type: "boolean", const: true, description: "A risky rule, one a run's user asked for or one the run worked out (to trust a site or a seller, skip or loosen an approval or a check, or send money or data somewhere), is kept to wait for its owner's OK: committed as a note with status `pending`, in no MEMORY.md and read by no run. Its owner approves it (POST /agents/{agent_id}/learning/files/{file}/approve) or retires it." },
|
|
1342
|
+
approve: { type: "boolean", description: "Whether this caller can approve a note that waits for its owner's OK: true only for the owner's password session in the console. A token (the server's own included), a run, and every caller on a server with accounts off (AGENTRUN_ACCOUNTS=0) read false." },
|
|
1343
|
+
approve_needs: { type: "string", enum: ["password"], description: "Present when `approve` is false: what approving needs, the owner's password sign-in (set one in Settings, or sign in with it)." },
|
|
1344
|
+
},
|
|
1345
|
+
description: "How this server judges what a run proposes to learn, and who approves what waits.",
|
|
1346
|
+
"x-agentrun-serve": "learning/1",
|
|
1347
|
+
},
|
|
1348
|
+
places: {
|
|
1349
|
+
type: "object", additionalProperties: false, required: ["modes", "default", "boxes", "allow"],
|
|
1350
|
+
properties: {
|
|
1351
|
+
modes: { type: "array", items: { enum: [...PLACE_MODES] } },
|
|
1352
|
+
default: { enum: [...PLACE_MODES], description: "Where a revision that names no place runs: `runner`. It stays `runner` because a revision saved with no place (an agent made before new agents were given a box, or where docker was unavailable, or a workflow) keeps running where it ran. What a NEW agent gets is `default_place`." },
|
|
1353
|
+
boxes: { type: "array", items: { type: "object", additionalProperties: false, required: ["id", "available", "state"], properties: { id: { enum: [...BOX_IDS] }, available: { type: "boolean" }, state: { enum: [...BOX_STATES], description: "`ready`; `preparing`, available while the server builds (or pulls) the Docker box's image at its start (a sandbox run's first box waits for it, with a timeline row); `unavailable`, with the `reason`." }, reason: { type: "string", description: "Why the box is unavailable, or what a preparing one waits for." }, network: { enum: [...BOX_NETWORKS], description: "What an available box reaches: `allowlist`, the hosts in `allow`, and nothing else (a Docker box through its egress proxy, on Linux with a daemon of that machine's own; a program that skips the proxy has no route; a Daytona box through Daytona's domain list, whose proxy re-signs TLS with Daytona's CA), or `none`. A Docker box's `none` comes with `network_reason`, and so does a Daytona box's when Daytona could not keep a list here (a tier that takes none); neither has one when AGENTRUN_BOX_ALLOW is `none`.", "x-agentrun-serve": "place/2" }, network_reason: { type: "string", description: "Why an available box has no network for a cause of its own, naming what the server found: a Docker in a VM, a daemon on another machine, docker info that did not answer; or a Daytona that could not keep its domain list.", "x-agentrun-serve": "place/2" } } } },
|
|
1354
|
+
},
|
|
1355
|
+
description: "The places a revision may name, this host's default, each box (whether this server has it, its state: ready, preparing or unavailable, and when not, why) and the hosts a box may reach.",
|
|
1356
|
+
"x-agentrun-serve": "place/1",
|
|
1357
|
+
},
|
|
1358
|
+
harnesses: {
|
|
1359
|
+
type: "array",
|
|
1360
|
+
description: "Each harness a revision may name, and whether this server runs it; when not, why. A harness whose one run needs more memory than this server has for runs is unavailable, its reason naming the numbers, and its runs are 409 agent_not_runnable.",
|
|
1361
|
+
items: { type: "object", additionalProperties: false, required: ["id", "available", "steer", "default_model", "run_memory_mib", "max_concurrent_runs"], properties: { id: { enum: [...HARNESSES] }, available: { type: "boolean" }, run_memory_mib: { type: "integer", minimum: 1, description: "The memory a run of this harness reserves while its process lives, in MiB, measured. A start is admitted while the runs going and it fit in this server's memory less its own; over that, 429 rate_limited with retry-after, as over `limits.max_concurrent_runs`." }, max_concurrent_runs: { type: "integer", minimum: 0, description: "The most runs of this harness alone at once here: by memory and by the cap on the count, whichever is fewer. 0 when one never fits. `limits.max_concurrent_runs` is pi's, the smallest run." }, default_model: { type: ["string", "null"], description: "The model this server runs for the harness when a definition names none (provider/model-id), or null when it runs none: the harness does not run here, or no default model here runs on it." }, steer: { type: "boolean", description: "Whether a message sent while the run works lands mid-turn (`steer`); when false, it waits for the turn's end and the answer's mode is `follow_up`." }, reason: { type: "string" } } },
|
|
1362
|
+
// harness/2: each entry took on its memory and count (run_memory_mib, max_concurrent_runs). A client that validates
|
|
1363
|
+
// against harness/1 refuses them, so it is a mark of its own.
|
|
1364
|
+
"x-agentrun-serve": "harness/2",
|
|
1365
|
+
},
|
|
1366
|
+
tools: {
|
|
1367
|
+
type: "array",
|
|
1368
|
+
description: "Every tool a revision may name (this server's closed table): whether a workflow's model nodes may use it (`nodes`), whether its code may call it (`calls`), and whether it runs here, else the variables it is missing; and its permission (the server's, its default and those offered).",
|
|
1369
|
+
items: {
|
|
1370
|
+
type: "object", additionalProperties: false, required: ["name", "summary", "nodes", "calls", "available", "harnesses", "permission", "default_permission", "permissions"],
|
|
1371
|
+
properties: {
|
|
1372
|
+
name: { type: "string" }, summary: { type: "string" }, nodes: { type: "boolean" }, calls: { type: "boolean" }, call_only: { type: "boolean", description: "Only a workflow's call node runs it (pdf_pages, llm): no agentic revision or model node names it." }, sandbox_only: { type: "boolean", description: "Only an agent whose place is a sandbox names it (bash, and the background tools bash_background, bash_output, bash_input, bash_signal and bash_list): it runs in the box, and a runner has no shell." }, available: { type: "boolean" }, reason: { type: "string", description: "Why the tool is unavailable here, present whenever `available` is false: a provider pick's own words (`web_search is turned off in settings`, `parallel picked, no PARALLEL_API_KEY`), or `Needs` and the variables it is missing; for a sandbox-only tool (bash, the background tools) that no box this server has can run, `no box is set up on this server: …` with each box's own reason (`places.boxes`)." }, missing: { type: "array", items: { type: "string" } },
|
|
1373
|
+
harnesses: { type: "array", items: { enum: [...HARNESSES] }, description: "The harnesses that run the tool here; a revision naming it on another harness saves with a warning and its runs are 409 agent_not_runnable.", "x-agentrun-serve": "tool-harness/1" },
|
|
1374
|
+
providers: { type: "array", items: { type: "string" }, description: "A tool with a provider choice: the providers offered for it, its default first.", "x-agentrun-serve": "providers/1" },
|
|
1375
|
+
provider: { type: "string", description: "A tool with a provider choice: the server's, its default where it sets none.", "x-agentrun-serve": "providers/1" },
|
|
1376
|
+
default_provider: { type: "string", description: "A tool with a provider choice: the built-in default.", "x-agentrun-serve": "providers/1" },
|
|
1377
|
+
resolves: { ...RESOLVES, "x-agentrun-serve": "providers/1" },
|
|
1378
|
+
why: { ...WHY, "x-agentrun-serve": "providers/1" },
|
|
1379
|
+
permission: { ...PERMISSION, description: "The server's permission of the tool: its setting, else the owner's default.", "x-agentrun-serve": "approvals/1" },
|
|
1380
|
+
default_permission: { enum: [...PERMISSIONS], description: "The owner's default: allow for this server's tools, ask for a catalog tool.", "x-agentrun-serve": "approvals/1" },
|
|
1381
|
+
permissions: { type: "array", items: { enum: [...PERMISSIONS] }, description: "The permissions it may be set to.", "x-agentrun-serve": "approvals/1" },
|
|
1382
|
+
ask_needs: { const: "password", description: "Present on a server with accounts off (AGENTRUN_ACCOUNTS=0), on each tool ask is offered for: an approval takes the owner's password sign-in, which this server has none of, so an ask is refused at each call (`needs the owner's approval, and this server has accounts off`), never parked. Absent with accounts on.", "x-agentrun-serve": "approvals/1" },
|
|
1383
|
+
key: { enum: TOOL_KEYS.map((row) => row.id), description: "The tool key that unlocks it (GET /settings/tool-keys' id; the browser's, its vendor's: kernel where Kernel is picked or resolved, else browserbase): saved there, it is read by name like a secret the server is started with, and the tool's `missing` goes at once. Absent when no tool key does.", "x-agentrun-serve": "toolkeys/1" },
|
|
1384
|
+
},
|
|
1385
|
+
},
|
|
1386
|
+
"x-agentrun-serve": "serve/1",
|
|
1387
|
+
},
|
|
1388
|
+
workflows: {
|
|
1389
|
+
type: "object", additionalProperties: false, required: ["nodes", "node_tools", "adapters", "decisions"],
|
|
1390
|
+
properties: {
|
|
1391
|
+
nodes: { type: "array", items: { type: "string" } }, node_tools: { type: "array", items: { type: "string" } }, adapters: { type: "array", items: { type: "string" } },
|
|
1392
|
+
},
|
|
1393
|
+
description: "What a workflow revision's run gets: the model nodes it runs, the tools they may name, the adapters it binds, and the decision providers its typed questions run on.",
|
|
1394
|
+
"x-agentrun-serve": "serve/1",
|
|
1395
|
+
},
|
|
1396
|
+
links: { type: "object", additionalProperties: false, required: ["openapi"], properties: { openapi: { type: "string" } }, description: "This document's address.", "x-agentrun-serve": "serve/1" },
|
|
1397
|
+
home: {
|
|
1398
|
+
type: "object", additionalProperties: false, required: ["disk", "host_owned", "max_file_bytes", "writes"],
|
|
1399
|
+
properties: {
|
|
1400
|
+
disk: { enum: ["local"], description: "Where the homes are: this server's disk, under its data directory." },
|
|
1401
|
+
host_owned: { type: "array", items: { type: "string" }, description: "The paths in a home only the server writes, never served here: each that is there is one entry of the list (`host_owned: true`), and a GET, PUT or DELETE at or under one, matched by its name folded (compatibility form, any case, no combining marks) or by identity on disk, is 403 `system_file_forbidden`." },
|
|
1402
|
+
max_file_bytes: { type: "integer", minimum: 1, description: "The largest file a PUT takes: `limits.max_body_bytes`. Over it, 413 `payload_too_large` naming `max_body_bytes`." },
|
|
1403
|
+
writes: { type: "boolean", description: "Whether PUT and DELETE write a home's files here. True only where this server reaches its held directory handles through /proc/self/fd (Linux), probed once at start, the probe its confinement walks by; false elsewhere (macOS), where both answer 501 `unsupported_here` and nothing is written or removed. The list and reads work either way." },
|
|
1404
|
+
},
|
|
1405
|
+
description: "Each agent's home: a directory of its own (its id in lower case and 16 hex digits of the id's SHA-256, so ids that differ only in case never share one), kept across its runs, its files listed, read, written and deleted at `/agents/{agent_id}/home/files`.",
|
|
1406
|
+
"x-agentrun-serve": "home/1",
|
|
1407
|
+
},
|
|
1408
|
+
secrets: {
|
|
1409
|
+
type: "object", additionalProperties: false, required: ["names", "handoff", "condition", "limit"],
|
|
1410
|
+
properties: { names: { type: "array", items: { type: "string" } }, handoff: { enum: ["pipe"] }, condition: { type: "string" }, limit: { type: "string" } },
|
|
1411
|
+
description: "How this server holds its secrets: the names it treats as secrets, handed over a pipe, the condition that rests on, and what it does not cover.",
|
|
1412
|
+
"x-agentrun-serve": "serve/1",
|
|
1413
|
+
},
|
|
1414
|
+
},
|
|
1415
|
+
// decisions/2: the providers took on parallel (and, here, openrouter). A client that validates against decisions/1 refuses it, so the
|
|
1416
|
+
// widening is a mark of its own.
|
|
1417
|
+
"Capabilities/places": {
|
|
1418
|
+
default_place: {
|
|
1419
|
+
oneOf: [
|
|
1420
|
+
{ type: "object", additionalProperties: false, required: ["mode"], properties: { mode: { const: "runner" } } },
|
|
1421
|
+
{ type: "object", additionalProperties: false, required: ["mode", "box"], properties: { mode: { const: "sandbox" }, box: { enum: [...BOX_IDS] } } },
|
|
1422
|
+
],
|
|
1423
|
+
description: "The place a NEW agentic agent that names none is saved with, written on its revision at its create: the Docker box (`{\"mode\": \"sandbox\", \"box\": \"docker\"}`) where this server has docker, ready or preparing (its first run waits for the image, with a timeline row), with tools [\"bash\"] when the definition names no tools; else the runner, with `default_reason`. It is not `default`: that one is where a revision saved with no place runs, and stays `runner`, so an agent made before keeps running where it ran.",
|
|
1424
|
+
"x-agentrun-serve": "place/3",
|
|
1425
|
+
},
|
|
1426
|
+
default_reason: { type: "string", description: "Why a new agent is not given a box here, when `default_place` is the runner, in docker's own words: `new agents run on the runner, because the docker box is unavailable here: <docker's reason>`.", "x-agentrun-serve": "place/3" },
|
|
1427
|
+
allow: { type: "array", items: { type: "string" }, description: "The hosts a box whose `network` is `allowlist` may reach: AGENTRUN_BOX_ALLOW's, else the package registries and GitHub; empty when it is `none`.", "x-agentrun-serve": "place/2" },
|
|
1428
|
+
},
|
|
1429
|
+
"Capabilities/workflows": {
|
|
1430
|
+
decisions: {
|
|
1431
|
+
type: "object", additionalProperties: false, required: ["providers"],
|
|
1432
|
+
description: "The decision providers a workflow's typed questions (judge, pick, sift, route, ask) run on, and whether this server runs each: when not, why (`reason`); when it runs in a way an operator should know of, a `note`. `runJudge` is among `adapters` once one runs.",
|
|
1433
|
+
properties: {
|
|
1434
|
+
providers: { type: "array", items: { type: "object", additionalProperties: false, required: ["id", "available"], properties: { id: { enum: ["jev", "parallel", "openrouter"] }, available: { type: "boolean" }, reason: { type: "string" }, note: { type: "string" } } } },
|
|
1435
|
+
},
|
|
1436
|
+
"x-agentrun-serve": "decisions/2",
|
|
1437
|
+
},
|
|
1438
|
+
},
|
|
1439
|
+
"Capabilities/models": {
|
|
1440
|
+
fast: { type: ["string", "null"], description: "`provider/model` of the fast tier, when one is fixed.", "x-agentrun-serve": "serve/1" },
|
|
1441
|
+
strong: { type: ["string", "null"], description: "`provider/model` of the strong tier, when one is fixed.", "x-agentrun-serve": "serve/1" },
|
|
1442
|
+
route_prefix: { type: ["string", "null"], description: "With `source` `gateway`, the routing prefix this server puts before the gateway's model ids (`agent-model`): every tier's model and every harness's `default_model` here is the prefix, a slash and the gateway's own id. Null with any other source, where ids are shown whole.", "x-agentrun-serve": "model/2" },
|
|
1443
|
+
ready: { type: "boolean", description: "Whether a revision that names no model runs here: the host names a default (`AGENT_MODEL`), or a model provider's key is here, saved (`PUT /settings/tool-keys/{key_id}`, a `model` key) or the server's own, and gives its default model, the first of anthropic, openai, openrouter that has one.", "x-agentrun-serve": "toolkeys/1" },
|
|
1444
|
+
needs: { enum: ["key", "model", null], description: "When `ready` is false, what would make it true: `key`, a model provider's key (none is here, or the default model's provider has none); `model`, another default model (`AGENT_MODEL` names one this server does not know). Null when ready.", "x-agentrun-serve": "toolkeys/1" },
|
|
1445
|
+
},
|
|
1446
|
+
Features: {
|
|
1447
|
+
archive: {
|
|
1448
|
+
type: "object", additionalProperties: false, required: ["agents", "runs", "list_param", "routes"],
|
|
1449
|
+
properties: { agents: { type: "boolean" }, runs: { type: "boolean" }, list_param: { type: "string" }, routes: { type: "array", items: { type: "string" } } },
|
|
1450
|
+
description: "Archiving agents and runs: hidden from the lists, kept with their history.",
|
|
1451
|
+
"x-agentrun-serve": "serve/1",
|
|
1452
|
+
},
|
|
1453
|
+
thinking: { type: "array", items: { type: "string" }, description: "The thinking levels an agentic revision may name.", "x-agentrun-serve": "serve/1" },
|
|
1454
|
+
learning: { enum: [...LEARNING_MODES], description: "This server's learning switch (`--learning`): `on`, a run of an agent whose definition says `learning: true` starts from what its agent learned and adds to it; `off`, no run this server starts does, whatever its agent says, and its `learning` is null.", "x-agentrun-serve": "learning/1" },
|
|
1455
|
+
tool_keys: {
|
|
1456
|
+
type: "object", additionalProperties: false, required: ["routes", "at_rest"],
|
|
1457
|
+
properties: { routes: { type: "boolean" }, at_rest: { enum: ["sealed", "unavailable"] } },
|
|
1458
|
+
description: "GET, PUT and DELETE /settings/tool-keys: a tool's key saved by name, kept `sealed` under the seal key the server was handed; `unavailable` with none, when nothing is kept.",
|
|
1459
|
+
"x-agentrun-serve": "toolkeys/1",
|
|
1460
|
+
},
|
|
1461
|
+
mcp_client: {
|
|
1462
|
+
type: "object", additionalProperties: false, required: ["routes", "transports", "auth", "at_rest"],
|
|
1463
|
+
properties: { routes: { type: "boolean" }, transports: { type: "array", items: { const: "streamable-http" } }, auth: { type: "array", items: { enum: [...MCP_AUTH_TYPES] } }, at_rest: { enum: ["sealed", "unavailable"] } },
|
|
1464
|
+
description: "/settings/mcp-servers: remote MCP servers over Streamable HTTP, previewed and saved with the auth types listed; a credential kept `sealed` under the seal key the server was handed, `unavailable` with none, when only servers that take no credential are kept.",
|
|
1465
|
+
"x-agentrun-serve": "mcpservers/1",
|
|
1466
|
+
},
|
|
1467
|
+
tool_permissions: { type: "boolean", description: "Whether a tool setting may carry a permission (allow, ask, deny), which the tool gate holds every tool call to.", "x-agentrun-serve": "providers/1" },
|
|
1468
|
+
webhooks: {
|
|
1469
|
+
type: "object", additionalProperties: false, required: ["routes", "events", "signing", "at_rest"],
|
|
1470
|
+
properties: { routes: { type: "boolean" }, events: { type: "array", items: { enum: [...WEBHOOK_EVENTS] } }, signing: { const: "standard-webhooks/v1" }, at_rest: { enum: ["sealed", "unavailable"] } },
|
|
1471
|
+
description: "/settings/webhook: one URL each of `events` is POSTed to, signed by the Standard Webhooks spec; its secret kept `sealed` under the seal key the server was handed, `unavailable` with none, when no webhook is set.",
|
|
1472
|
+
"x-agentrun-serve": "webhook/1",
|
|
1473
|
+
},
|
|
1474
|
+
triggers: {
|
|
1475
|
+
...closed({ routes: { type: "boolean" }, sources: { type: "array", items: { enum: [...SOURCE_KINDS] } }, targets: { type: "array", items: { enum: [...TARGET_KINDS] } }, overlap: { type: "array", items: { enum: [...OVERLAP] } }, min_every_s: { type: "integer" }, history_kept: { type: "integer" }, catchup_window_s: { type: "integer" }, failures_to_pause: { type: "integer" }, webhook: closed({ signing: { const: "standard-webhooks/v1" }, tolerance_s: { type: "integer" }, max_body_bytes: { type: "integer" }, payload_kept_bytes: { type: "integer" }, at_rest: { enum: ["sealed", "unavailable"] } }) }),
|
|
1476
|
+
description: "/triggers: schedules that start an agent's capped runs: the source and target kinds this server takes, what a firing does while the last run is active, the shortest interval, how many firings each trigger keeps, the default catch-up window, and how many failed firings in a row turn a trigger off.",
|
|
1477
|
+
...TRIGGER_MARK,
|
|
1478
|
+
},
|
|
1479
|
+
},
|
|
1480
|
+
"Features/agents": { revisions: { type: "boolean", description: "`GET /agents/{agent_id}/revisions` and `POST /agents/{agent_id}/current`.", "x-agentrun-serve": "serve/1" } },
|
|
1481
|
+
"Features/runs": {
|
|
1482
|
+
pause_workflow_runs: { type: "boolean", description: "POST /runs/{run_id}/pause and /resume hold and release a workflow run.", "x-agentrun-serve": "pause/1" },
|
|
1483
|
+
graph: { type: "boolean", description: "GET /runs/{run_id}/graph draws a workflow run, live.", "x-agentrun-serve": "pause/1" },
|
|
1484
|
+
list: { type: "boolean", description: "`GET /runs`.", "x-agentrun-serve": "serve/1" },
|
|
1485
|
+
kinds: { type: "array", items: { enum: ["agentic", "workflow"] }, description: "The kinds of run this server starts.", "x-agentrun-serve": "serve/1" },
|
|
1486
|
+
},
|
|
1487
|
+
"Features/timeline": { live_workflow_rows: { type: "boolean", description: "Whether a workflow run's rows arrive while it runs.", "x-agentrun-serve": "serve/1" } },
|
|
1488
|
+
};
|
|
1489
|
+
/** What a run refused `409 agent_not_runnable` holds in `error.details` here: what keeps its revision from running
|
|
1490
|
+
* (server.ts, from runnable.ts's blockers), or, for an archived agent, when it was archived (server.ts, runs.ts). */
|
|
1491
|
+
const BLOCKED_DETAILS = {
|
|
1492
|
+
type: "object", additionalProperties: false, required: ["unbound", "missing"],
|
|
1493
|
+
properties: {
|
|
1494
|
+
unbound: { type: "array", items: { type: "string" }, description: "The tools the revision names that this server does not bind, or does not bind on its harness." },
|
|
1495
|
+
missing: { type: "object", additionalProperties: { type: "array", items: { type: "string" } }, description: "Each bound tool this host cannot run yet, with the variables it is missing." },
|
|
1496
|
+
harness: { enum: [...HARNESSES], description: "The revision's harness, when this server does not run it (capabilities.harnesses)." },
|
|
1497
|
+
denied: { type: "array", items: { type: "string" }, description: "A workflow revision: the tools its call nodes call that are set to deny here." },
|
|
1498
|
+
asks: { type: "array", items: { type: "string" }, description: "A workflow revision: the tools its call nodes call that are set to ask here (a catalog tool's default among them). A call node cannot wait for an approval: set the tool to allow for the agent." },
|
|
1499
|
+
box: { enum: [...BOX_IDS], description: "The box of the revision's place, when this server does not have it (capabilities.places.boxes)." },
|
|
1500
|
+
adapters: { type: "array", items: { type: "string" }, description: "A workflow revision: the adapters it needs that this server does not bind." },
|
|
1501
|
+
code: { type: "boolean", description: "A workflow revision: whether it needs code this server does not run." },
|
|
1502
|
+
tier: { type: "string", description: "A workflow revision: the model tier this host has no model for." },
|
|
1503
|
+
decisions: { type: "object", description: "A workflow revision: each decision provider it needs that this host has not set up, with why and the variables it needs.", additionalProperties: { type: "object", additionalProperties: false, required: ["reason", "needs"], properties: { reason: { type: "string" }, needs: { type: "array", items: { type: "string" } } } } },
|
|
1504
|
+
},
|
|
1505
|
+
};
|
|
1506
|
+
const ARCHIVED_DETAILS = {
|
|
1507
|
+
type: "object", additionalProperties: false, required: ["archived_at"],
|
|
1508
|
+
properties: { archived_at: { type: "string", format: "date-time", description: "When the agent was archived: unarchive it to run it." } },
|
|
1509
|
+
};
|
|
1510
|
+
const NOT_RUNNABLE_DETAILS = { oneOf: [BLOCKED_DETAILS, ARCHIVED_DETAILS] };
|
|
1511
|
+
/** What a file refused `403 system_file_forbidden` holds in `error.details` here, when it holds any (a dot-name holds none). */
|
|
1512
|
+
const FORBIDDEN_DETAILS = {
|
|
1513
|
+
type: "object", additionalProperties: false, required: ["reason"],
|
|
1514
|
+
properties: { reason: { enum: ["unreadable", "host_owned", "link"], description: "`unreadable`: another user made the file private. `host_owned`: a read, write or delete in an agent's home at or under a path only the server writes, in any case. `link`: a write or a delete in an agent's home through a link." } },
|
|
1515
|
+
};
|
|
1516
|
+
/** The contract as vendored, read once. */
|
|
1517
|
+
function contract() {
|
|
1518
|
+
vendored ??= JSON.parse(readFileSync(new URL("./openapi/agentrun-v2.openapi.json", import.meta.url), "utf8"));
|
|
1519
|
+
return vendored;
|
|
1520
|
+
}
|
|
1521
|
+
/** The document: the contract, its operations this server turns off marked with why (`capabilityOf` gives an
|
|
1522
|
+
* operation's capability here, by its operationId), and this server's own routes added and marked. */
|
|
1523
|
+
export function openapiDocument(capabilityOf) {
|
|
1524
|
+
const doc = structuredClone(contract());
|
|
1525
|
+
const unsupported = [];
|
|
1526
|
+
for (const [path, item] of Object.entries(doc.paths)) {
|
|
1527
|
+
for (const [method, op] of Object.entries(item)) {
|
|
1528
|
+
const capability = typeof op.operationId === "string" ? capabilityOf(op.operationId) : undefined;
|
|
1529
|
+
if (capability === undefined)
|
|
1530
|
+
continue;
|
|
1531
|
+
op["x-agentrun-serve-unsupported"] = { capability, reason: UNSUPPORTED[capability] ?? "This server does not offer it." };
|
|
1532
|
+
unsupported.push(`${method.toUpperCase()} ${path}`);
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
// The console's password session, the one credential approving a note takes (approveLearningFile).
|
|
1536
|
+
doc.components.securitySchemes.ownerSession = {
|
|
1537
|
+
type: "apiKey", in: "cookie", name: "agentrun-<port>",
|
|
1538
|
+
description: "The owner's console session: the cookie `agentrun-<port>`, this server's port (the document as served names it), that the console sets when the owner signs in with their password (accounts on). Sent from this server's own origin; a token never stands for it.",
|
|
1539
|
+
"x-agentrun-serve": "learning/2",
|
|
1540
|
+
};
|
|
1541
|
+
const schemas = doc.components.schemas;
|
|
1542
|
+
const fields = [];
|
|
1543
|
+
for (const [where, added] of Object.entries(FIELD_EXTENSIONS)) {
|
|
1544
|
+
const [name, ...down] = where.split("/");
|
|
1545
|
+
let object = schemas[name];
|
|
1546
|
+
for (const key of down)
|
|
1547
|
+
object = object.properties[key];
|
|
1548
|
+
for (const [field, schema] of Object.entries(added)) {
|
|
1549
|
+
object.properties[field] = schema;
|
|
1550
|
+
fields.push([name, ...down, field].join("."));
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
// The contract's definition fields this server refuses (validate.ts), each marked with the reason its 422 gives.
|
|
1554
|
+
const definition = schemas.DefinitionInput;
|
|
1555
|
+
const refused = [];
|
|
1556
|
+
for (const field of Object.keys(definition.properties)) {
|
|
1557
|
+
if (DEFINITION_FIELDS.includes(field))
|
|
1558
|
+
continue;
|
|
1559
|
+
definition.properties[field] = { ...definition.properties[field], "x-agentrun-serve-unsupported": { reason: NOT_KEPT[field] ?? `The definition keeps no field ${field}.` } };
|
|
1560
|
+
refused.push(`DefinitionInput.${field}`);
|
|
1561
|
+
}
|
|
1562
|
+
// A contract field this server takes with a meaning of its own, said on it.
|
|
1563
|
+
definition.properties.max_cost_usd = { ...definition.properties.max_cost_usd, "x-agentrun-serve-note": "The agent's default cap of each run started without a max_cost_usd of its own (a run's own wins), kept with its revision: above 0 sets it, 0 clears it (no default), and an edit that leaves the field out keeps the agent's, so leaving a field out never removes a spend limit. An agentic definition only: on a workflow's, above 0 is 422 not_allowed, as a workflow run is not capped here." };
|
|
1564
|
+
const noted = ["DefinitionInput.max_cost_usd"];
|
|
1565
|
+
// PUT .../definition takes the contract's body (the definition itself) or this server's own, POST /agents' body with a
|
|
1566
|
+
// note: exactly one, as only this server's holds `definition` and both are closed. If-Match is the contract's
|
|
1567
|
+
// precondition for its body; this server's own body may leave it out.
|
|
1568
|
+
const update = doc.paths["/agents/{agent_id}/definition"].put;
|
|
1569
|
+
const media = update.requestBody.content["application/json"];
|
|
1570
|
+
media.schema = { oneOf: [media.schema, { $ref: "#/components/schemas/AgentCreate" }] };
|
|
1571
|
+
for (const parameter of update.parameters) {
|
|
1572
|
+
if (parameter.name === "If-Match")
|
|
1573
|
+
Object.assign(parameter, { required: false, description: `${parameter.description} Required with the contract's body; this server's own body (\`{definition, skills?, note?}\`) may leave it out.` });
|
|
1574
|
+
}
|
|
1575
|
+
// What this server changes in a contract operation, by the addition that made it.
|
|
1576
|
+
update["x-agentrun-serve-changed"] = { requestBody: "definitionbody/1", "If-Match": "definitionbody/1" };
|
|
1577
|
+
const changed = ["PUT /agents/{agent_id}/definition"];
|
|
1578
|
+
// A workflow run's decisions are rows of its timeline here (decision-rows.ts), of a kind the contract does not list.
|
|
1579
|
+
const timelineKind = schemas.TimelineKind;
|
|
1580
|
+
if (Array.isArray(timelineKind.enum) && !timelineKind.enum.includes("decision")) {
|
|
1581
|
+
timelineKind.enum = [...timelineKind.enum, "decision"];
|
|
1582
|
+
timelineKind["x-agentrun-serve"] = "decision-rows/1";
|
|
1583
|
+
fields.push("TimelineKind.decision");
|
|
1584
|
+
}
|
|
1585
|
+
// A timeline page of at most `limit` rows: the contract's pages hold up to 500, more than a small client reads at once.
|
|
1586
|
+
const timeline = doc.paths["/runs/{run_id}/timeline"].get;
|
|
1587
|
+
timeline.parameters = [...timeline.parameters, { name: "limit", in: "query", required: false, description: "At most this many rows in a page (1 to 500, default 500); has_more says when another waits.", schema: { type: "integer", minimum: 1, maximum: 500, default: 500 } }];
|
|
1588
|
+
timeline["x-agentrun-serve-changed"] = { limit: "timelinelimit/1" };
|
|
1589
|
+
changed.push("GET /runs/{run_id}/timeline");
|
|
1590
|
+
// upload/2: POST /files also takes a file's bytes in one call (`path` in the query, the bytes the body), answered as
|
|
1591
|
+
// a reservation is with the file ready; and `upload.url` is a path from the server's root, `/v2/files/{file_id}`.
|
|
1592
|
+
const createFile = doc.paths["/files"].post;
|
|
1593
|
+
createFile.requestBody.description = "Without `path` in the query: the contract's JSON reservation (application/json, FileCreate), its bytes sent after with PUT /files/{file_id}. With `path` in the query: the file's bytes themselves, in any type, application/json included (a multipart form is 415), sent in one call, the length the body's and the hash its own.";
|
|
1594
|
+
Object.assign(createFile.requestBody.content, structuredClone(RAW));
|
|
1595
|
+
const query = (name, description, schema) => ({ name, in: "query", required: false, description, schema });
|
|
1596
|
+
createFile.parameters = [
|
|
1597
|
+
...createFile.parameters,
|
|
1598
|
+
query("path", "With the file's bytes as the body: the file's path (FilePathString). Its presence makes the body the file.", ref("schemas/FilePathString")),
|
|
1599
|
+
query("content_type", "With `path`: the file's type. Absent, the request's own type when it names one (not application/octet-stream, not application/x-www-form-urlencoded), else the path's extension's, else application/octet-stream.", { type: "string" }),
|
|
1600
|
+
query("sha256", "With `path`: the hash the bytes must have (`422 input_invalid` at sha256 when they do not).", { type: "string", pattern: "^[0-9a-f]{64}$" }),
|
|
1601
|
+
];
|
|
1602
|
+
createFile.responses["201"] = { ...createFile.responses["201"], description: "The file and where to send its bytes; sent in one call, the file is ready. `upload.url` is a path from the server's root (`/v2/files/{file_id}`): resolve it against the server's address, do not append it to the `/v2` base." };
|
|
1603
|
+
createFile.responses["415"] = ref("responses/UnsupportedMediaType");
|
|
1604
|
+
createFile["x-agentrun-serve-changed"] = { requestBody: "upload/2", parameters: "upload/2", responses: "upload/2" };
|
|
1605
|
+
changed.push("POST /files");
|
|
1606
|
+
// An agentic run's cancel is its end at once: the 202 reads `cancelled`, and no later end of its turn moves it.
|
|
1607
|
+
const cancel = doc.paths["/runs/{run_id}/cancel"].post;
|
|
1608
|
+
cancel.description = `${String(cancel.description).trimEnd()}\nHere an agentic run reads \`cancelled\` from the 202 on, \`final\` once it has stopped: a run's first terminal status is its last, so nothing its cut turn writes later (an answer, a cost over its cap) moves it. A workflow run reads \`cancelled\` once its workflow has stopped.\n`;
|
|
1609
|
+
cancel["x-agentrun-serve-changed"] = { description: "turnend/1" };
|
|
1610
|
+
changed.push("POST /runs/{run_id}/cancel");
|
|
1611
|
+
// A run create's key is kept with its run in the agent store (its origin), so it replays that run past the key's day.
|
|
1612
|
+
const createRun = doc.paths["/agents/{agent_id}/runs"].post;
|
|
1613
|
+
createRun.description = `${String(createRun.description).trimEnd()}\nHere a create's \`Idempotency-Key\` is also kept with the run it started, written in the agent store with the run itself: the same key and body replays that run, as it reads now, for as long as the run exists (after any restart, and past \`limits.idempotency_ttl_s\`, which bounds the other creates' keys); another body under the key is \`409 idempotency_mismatch\`.\n`;
|
|
1614
|
+
createRun["x-agentrun-serve-changed"] = { description: "runorigin/1" };
|
|
1615
|
+
changed.push("POST /agents/{agent_id}/runs");
|
|
1616
|
+
// models/2: capabilities' `models.source` takes on the values this server answers with that the contract's enum (managed,
|
|
1617
|
+
// chatgpt, env, faux) lacks, `gateway` and `providers`. A client that validates against the contract's enum refuses them,
|
|
1618
|
+
// so the widening is a mark of its own, each value listed, as RunStatus's `paused` is.
|
|
1619
|
+
const modelsSource = schemas.Capabilities.properties.models.properties.source;
|
|
1620
|
+
const sourcesAdded = MODEL_SOURCES.filter((value) => Array.isArray(modelsSource.enum) && !modelsSource.enum.includes(value));
|
|
1621
|
+
if (sourcesAdded.length) {
|
|
1622
|
+
modelsSource.enum = [...modelsSource.enum, ...sourcesAdded];
|
|
1623
|
+
modelsSource.description = "Where this server's models come from. `gateway`: every model through the OpenAI-compatible gateway at `AGENT_MODEL_BASE_URL`, its ids under `route_prefix`. `providers`: each model from its own provider, with that provider's key. `faux`: a scripted model, with no key and no network. `managed`, `chatgpt` and `env` are the hosted API's.";
|
|
1624
|
+
modelsSource["x-agentrun-serve"] = "models/2";
|
|
1625
|
+
fields.push(...sourcesAdded.map((value) => `Capabilities.models.source.${value}`));
|
|
1626
|
+
}
|
|
1627
|
+
// browser/1: the browser tool runs on Browserbase or Kernel, picked per server and per agent (tool-plane.ts), so
|
|
1628
|
+
// capabilities' `features.browser` names Kernel's where the server's settings resolve to it, which the contract's enum
|
|
1629
|
+
// (browserbase, chrome, none) lacks.
|
|
1630
|
+
const browser = schemas.Features.properties.browser;
|
|
1631
|
+
if (Array.isArray(browser.enum) && !browser.enum.includes("kernel")) {
|
|
1632
|
+
browser.enum = [...browser.enum, "kernel"];
|
|
1633
|
+
browser["x-agentrun-serve"] = "browser/1";
|
|
1634
|
+
fields.push("Features.browser.kernel");
|
|
1635
|
+
}
|
|
1636
|
+
// signins/1: a saved sign-in whose pointer does not open under this server's seal key (sign-ins.ts) reads `unreadable`,
|
|
1637
|
+
// which the contract's SignIn.state (ready, held) lacks.
|
|
1638
|
+
const signInState = schemas.SignIn.properties.state;
|
|
1639
|
+
if (Array.isArray(signInState.enum) && !signInState.enum.includes("unreadable")) {
|
|
1640
|
+
signInState.enum = [...signInState.enum, "unreadable"];
|
|
1641
|
+
signInState.description = "`held` while a run holds its save lease, else `ready`. `unreadable` (this server's own): its pointer does not open under this server's seal key (none now, or another), so runs start signed out and none is made in its place until it is forgotten (DELETE /agents/{agent_id}/sign-ins/{key}); its `held_by` names a run that still holds its lease, else null.";
|
|
1642
|
+
signInState["x-agentrun-serve"] = "signins/1";
|
|
1643
|
+
fields.push("SignIn.state.unreadable");
|
|
1644
|
+
// An unreadable sign-in still names a run that holds its lease (held_by), as a held one does; a ready one never.
|
|
1645
|
+
const signIn = schemas.SignIn;
|
|
1646
|
+
if (signIn.else) {
|
|
1647
|
+
signIn.else = { if: { properties: { state: { const: "unreadable" } } }, then: { properties: { held_by: { oneOf: [ref("schemas/Id"), { type: "null" }] } } }, else: signIn.else, "x-agentrun-serve": "signins/1" };
|
|
1648
|
+
fields.push("SignIn.else");
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
// A workflow run pauses here (POST /runs/{run_id}/pause): its status reads `paused` until it is resumed.
|
|
1652
|
+
const runStatus = schemas.RunStatus;
|
|
1653
|
+
if (Array.isArray(runStatus.enum) && !runStatus.enum.includes("paused")) {
|
|
1654
|
+
runStatus.enum = [...runStatus.enum.slice(0, runStatus.enum.indexOf("working") + 1), "paused", ...runStatus.enum.slice(runStatus.enum.indexOf("working") + 1)];
|
|
1655
|
+
runStatus["x-agentrun-serve"] = "pause/1";
|
|
1656
|
+
fields.push("RunStatus.paused");
|
|
1657
|
+
}
|
|
1658
|
+
// A paid tool's charges (monid's) are a meter of their own on /usage, beside the model's tokens.
|
|
1659
|
+
const meter = schemas.Meter;
|
|
1660
|
+
if (Array.isArray(meter.enum) && !meter.enum.includes("tools")) {
|
|
1661
|
+
meter.enum = [...meter.enum, "tools"];
|
|
1662
|
+
meter["x-agentrun-serve"] = "toolcost/1";
|
|
1663
|
+
fields.push("Meter.tools");
|
|
1664
|
+
}
|
|
1665
|
+
// A tool call that waited for a person's approval has a row of its own (runs.ts).
|
|
1666
|
+
if (Array.isArray(timelineKind.enum) && !timelineKind.enum.includes(APPROVAL_ROW)) {
|
|
1667
|
+
timelineKind.enum = [...timelineKind.enum, APPROVAL_ROW];
|
|
1668
|
+
fields.push(`TimelineKind.${APPROVAL_ROW}`);
|
|
1669
|
+
}
|
|
1670
|
+
// A run's learning row (runs.ts) beside the contract's row kinds, and GET /usage's `learning` meter (usage.ts): what a
|
|
1671
|
+
// run's grade spends on this server, outside any run.
|
|
1672
|
+
for (const [name, value] of [["TimelineKind", "learning"], ["Meter", "learning"]]) {
|
|
1673
|
+
const schema = schemas[name];
|
|
1674
|
+
if (!Array.isArray(schema.enum) || schema.enum.includes(value))
|
|
1675
|
+
continue;
|
|
1676
|
+
schema.enum = [...schema.enum, value];
|
|
1677
|
+
// A schema two additions widen keeps the first one's mark; each value's own mark is in info's fields.
|
|
1678
|
+
schema["x-agentrun-serve"] ??= "learning/1";
|
|
1679
|
+
fields.push(`${name}.${value}`);
|
|
1680
|
+
}
|
|
1681
|
+
// This server's own error codes (errors.ts), beside the contract's closed list.
|
|
1682
|
+
const errorCode = schemas.ErrorCode;
|
|
1683
|
+
const own = Object.keys(ERROR_STATUS).filter((code) => Array.isArray(errorCode.enum) && !errorCode.enum.includes(code));
|
|
1684
|
+
if (own.length) {
|
|
1685
|
+
errorCode.enum = [...errorCode.enum, ...own];
|
|
1686
|
+
// The newest addition that widened it: a client that validates against mcpservers/1 refuses budget_reached.
|
|
1687
|
+
errorCode["x-agentrun-serve"] = "cappause/1";
|
|
1688
|
+
fields.push(...own.map((code) => `ErrorCode.${code}`));
|
|
1689
|
+
}
|
|
1690
|
+
const details = schemas.ErrorBody.properties.details;
|
|
1691
|
+
details["x-agentrun-serve-details"] = {
|
|
1692
|
+
agent_not_runnable: NOT_RUNNABLE_DETAILS, system_file_forbidden: FORBIDDEN_DETAILS,
|
|
1693
|
+
auth_required: closed({ auth: { enum: ["bearer", "oauth"], description: "What the MCP server asks for: `oauth` when it names protected-resource metadata, else `bearer`." }, status: { enum: [401, 403] } }),
|
|
1694
|
+
upstream_failed: { type: "object", additionalProperties: false, properties: { status: { type: "integer", description: "The MCP server's HTTP status, when it answered one." } } },
|
|
1695
|
+
};
|
|
1696
|
+
const extensions = [];
|
|
1697
|
+
for (const [path, item] of Object.entries(EXTENSIONS)) {
|
|
1698
|
+
for (const [method, op] of Object.entries(item)) {
|
|
1699
|
+
(doc.paths[path] ??= {})[method] = { "x-agentrun-serve": true, ...op };
|
|
1700
|
+
extensions.push(`${method.toUpperCase()} ${path}`);
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
doc.info["x-agentrun-serve"] = {
|
|
1704
|
+
description: "Served by @parcha/agentrun-serve: the contract as vendored, unchanged, with this server's marks. Operations and schema properties marked x-agentrun-serve are this server's own, outside the contract (fields lists the properties, each marked with the addition that made it); operations marked x-agentrun-serve-unsupported answer 501 unsupported_here here; operations marked x-agentrun-serve-changed take more than the contract gives, each change named (changed lists them); a contract property marked x-agentrun-serve-unsupported is one this server refuses (unsupported_fields, with why); x-agentrun-serve-details gives what a code's details hold here (details lists where); x-agentrun-serve-note says what a contract property means here (notes lists them). servers is this server, relative to this document; the contract's own are in contract_servers.",
|
|
1705
|
+
extensions,
|
|
1706
|
+
changed,
|
|
1707
|
+
fields,
|
|
1708
|
+
unsupported_fields: refused,
|
|
1709
|
+
details: ["ErrorBody.details"],
|
|
1710
|
+
notes: noted,
|
|
1711
|
+
unsupported,
|
|
1712
|
+
contract_servers: doc.servers,
|
|
1713
|
+
};
|
|
1714
|
+
// This document is read from the server it describes, wherever it is published: a client generated from it calls
|
|
1715
|
+
// that server, not the first of the contract's.
|
|
1716
|
+
doc.servers = [{ url: "/v2", description: "This server." }];
|
|
1717
|
+
return doc;
|
|
1718
|
+
}
|
|
1719
|
+
/** The document as served on `port`: the owner's session cookie named as the console sets it on that port
|
|
1720
|
+
* (page.ts: `agentrun-<port>`). Without a port, the document as built. */
|
|
1721
|
+
export function servedOpenapi(doc, port) {
|
|
1722
|
+
if (port === undefined)
|
|
1723
|
+
return doc;
|
|
1724
|
+
const components = doc.components;
|
|
1725
|
+
const schemes = components.securitySchemes;
|
|
1726
|
+
return { ...doc, components: { ...components, securitySchemes: { ...schemes, ownerSession: { ...schemes.ownerSession, name: `agentrun-${port}` } } } };
|
|
1727
|
+
}
|