@parcha/agentrun-serve 0.1.0-beta.57 → 0.1.0-beta.59
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 +376 -0
- package/README.md +393 -118
- package/dist/acp-package.d.ts +5 -1
- package/dist/acp-package.js +19 -2
- package/dist/adapters.d.ts +23 -2
- package/dist/adapters.js +106 -33
- package/dist/agents-store.js +1 -1
- package/dist/answer-text.d.ts +3 -0
- package/dist/answer-text.js +22 -0
- package/dist/api-only.d.ts +2 -4
- package/dist/api-only.js +2 -4
- package/dist/attach-conformance.js +5 -4
- package/dist/box-paths.d.ts +7 -5
- package/dist/box-paths.js +12 -8
- package/dist/browser-computer.d.ts +3 -8
- package/dist/browser-computer.js +12 -35
- package/dist/browser-cost.js +94 -20
- package/dist/capacity.d.ts +1 -1
- package/dist/capacity.js +3 -3
- package/dist/chatgpt-plan.d.ts +5 -0
- package/dist/chatgpt-plan.js +25 -11
- package/dist/claude-login-token.d.ts +121 -0
- package/dist/claude-login-token.js +797 -0
- package/dist/claude-login.d.ts +119 -34
- package/dist/claude-login.js +551 -79
- package/dist/claude-sign-in.d.ts +3 -0
- package/dist/claude-sign-in.js +10 -1
- package/dist/cli.js +325 -328
- package/dist/composio-made.d.ts +1 -6
- package/dist/composio-made.js +1 -6
- package/dist/composio-owners.d.ts +26 -0
- package/dist/composio-owners.js +36 -0
- package/dist/composio-preset.d.ts +56 -23
- package/dist/composio-preset.js +173 -77
- package/dist/composio-triggers.d.ts +4 -4
- package/dist/composio-triggers.js +6 -7
- package/dist/compute-cost.js +11 -2
- package/dist/computer-attach.d.ts +40 -19
- package/dist/computer-attach.js +326 -62
- package/dist/computer-held-routes.d.ts +1 -1
- package/dist/computer-held-routes.js +9 -4
- package/dist/computer-keys.d.ts +11 -1
- package/dist/computer-keys.js +26 -1
- package/dist/computer-record.js +3 -1
- package/dist/computer-view.d.ts +5 -3
- package/dist/computer-view.js +10 -6
- package/dist/computer-viewer.js +36 -7
- package/dist/computers.d.ts +12 -11
- package/dist/computers.js +11 -8
- package/dist/console/THIRD-PARTY-NOTICES.txt +50 -0
- package/dist/console/assets/backend-BztxEAvb.js +166 -0
- package/dist/console/assets/index-LwNL4L9q.js +619 -0
- package/dist/console/assets/share-L84tlUDW.js +6 -0
- package/dist/console/assets/styles-CaRKlHke.js +291 -0
- package/dist/console/assets/styles-DQo8rzY-.css +1 -0
- package/dist/console/index.html +4 -3
- package/dist/console/share.html +17 -0
- package/dist/decisions.d.ts +17 -7
- package/dist/decisions.js +41 -15
- package/dist/dial-relay.d.ts +25 -4
- package/dist/dial-relay.js +139 -5
- package/dist/docker-daemon.js +4 -5
- package/dist/docker-host-addresses.js +29 -11
- package/dist/email/account.d.ts +6 -0
- package/dist/email/account.js +6 -0
- package/dist/email/authentication.d.ts +21 -0
- package/dist/email/authentication.js +106 -0
- package/dist/email/email-faux.d.ts +11 -2
- package/dist/email/email-faux.js +21 -5
- package/dist/email/mail.d.ts +25 -0
- package/dist/email/mail.js +58 -2
- package/dist/email/names.js +2 -2
- package/dist/email/tools.d.ts +9 -4
- package/dist/email/tools.js +95 -13
- package/dist/env-switch.d.ts +13 -5
- package/dist/env-switch.js +24 -6
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- package/dist/fal-price.d.ts +12 -4
- package/dist/fal-price.js +110 -26
- package/dist/faux-computers.js +1 -1
- package/dist/filed-answer.d.ts +2 -2
- package/dist/filed-answer.js +2 -2
- package/dist/graph-served.d.ts +10 -5
- package/dist/graph-served.js +40 -10
- package/dist/handed-values.js +1 -2
- package/dist/harness-check.d.ts +2 -1
- package/dist/harness-check.js +45 -12
- package/dist/harness-keys.js +9 -6
- package/dist/harness-opencode/facts.js +2 -0
- package/dist/harness-recipe-entry.d.ts +9 -3
- package/dist/harness-recipe-entry.js +18 -9
- package/dist/harness-recipe.d.ts +21 -0
- package/dist/harness-recipe.js +25 -3
- package/dist/harness-table.d.ts +8 -0
- package/dist/harness-table.js +17 -6
- package/dist/helper-env.d.ts +4 -1
- package/dist/helper-env.js +4 -1
- package/dist/host-check.d.ts +2 -3
- package/dist/host-check.js +13 -7
- package/dist/hosted-search.js +1 -1
- package/dist/import.d.ts +11 -8
- package/dist/import.js +437 -186
- package/dist/key-refusal.d.ts +9 -2
- package/dist/key-refusal.js +86 -32
- package/dist/learn/audit.d.ts +8 -5
- package/dist/learn/audit.js +15 -7
- package/dist/learn/compile.d.ts +5 -2
- package/dist/learn/compile.js +45 -21
- package/dist/learn/field-check.d.ts +111 -0
- package/dist/learn/field-check.js +174 -0
- package/dist/learn/ledger.d.ts +173 -0
- package/dist/learn/ledger.js +225 -0
- package/dist/learn/promote.d.ts +82 -39
- package/dist/learn/promote.js +61 -66
- package/dist/learn/secrets.d.ts +4 -0
- package/dist/learn/secrets.js +12 -0
- package/dist/learned-nodes.d.ts +8 -5
- package/dist/learned-nodes.js +8 -5
- package/dist/learned-workflow.d.ts +2 -1
- package/dist/learned-workflow.js +13 -10
- package/dist/learning-cost.d.ts +40 -21
- package/dist/learning-cost.js +30 -21
- package/dist/learning-setting.d.ts +6 -0
- package/dist/learning-setting.js +11 -1
- package/dist/listen-first.d.ts +5 -4
- package/dist/listen-first.js +4 -5
- package/dist/live-reach.d.ts +9 -0
- package/dist/live-reach.js +9 -0
- package/dist/mcp-api-only-origins.d.ts +23 -3
- package/dist/mcp-api-only-origins.js +57 -17
- package/dist/mcp-gateway.d.ts +16 -2
- package/dist/mcp-gateway.js +41 -3
- package/dist/mcp-oauth.d.ts +1 -1
- package/dist/mcp-oauth.js +3 -2
- package/dist/mcp-probe.d.ts +3 -0
- package/dist/mcp-probe.js +3 -0
- package/dist/mcp-secret-writes.d.ts +24 -2
- package/dist/mcp-secret-writes.js +30 -2
- package/dist/mcp-servers-store.d.ts +52 -14
- package/dist/mcp-servers-store.js +165 -61
- package/dist/mcp-sources.d.ts +1 -2
- package/dist/mcp-sources.js +1 -2
- package/dist/mcp-store.d.ts +5 -5
- package/dist/mcp-store.js +3 -3
- package/dist/mcp.js +1 -1
- package/dist/micro.d.ts +2 -0
- package/dist/micro.js +2 -0
- package/dist/model-gateway.d.ts +1 -1
- package/dist/model-gateway.js +20 -36
- package/dist/model.d.ts +5 -4
- package/dist/model.js +7 -6
- package/dist/monid.d.ts +14 -1
- package/dist/monid.js +103 -26
- package/dist/ollama-provider.d.ts +23 -9
- package/dist/ollama-provider.js +49 -20
- package/dist/openapi.js +234 -61
- package/dist/otel/genai.d.ts +83 -7
- package/dist/otel/genai.js +69 -9
- package/dist/otel/tracer.d.ts +42 -13
- package/dist/otel/tracer.js +241 -56
- package/dist/page.d.ts +7 -1
- package/dist/page.js +76 -22
- package/dist/paid-calls.d.ts +6 -4
- package/dist/paid-calls.js +15 -7
- package/dist/place-offers.d.ts +59 -34
- package/dist/place-offers.js +100 -58
- package/dist/place.d.ts +13 -14
- package/dist/place.js +56 -41
- package/dist/print.js +1 -1
- package/dist/provider.d.ts +5 -4
- package/dist/provider.js +26 -13
- package/dist/redact/match.d.ts +27 -9
- package/dist/redact/match.js +266 -57
- package/dist/run-census.d.ts +1 -1
- package/dist/run-census.js +4 -5
- package/dist/run-cut.js +4 -5
- package/dist/run-export-store.d.ts +15 -0
- package/dist/run-export-store.js +30 -0
- package/dist/run-export.d.ts +139 -0
- package/dist/run-export.js +379 -0
- package/dist/run-file-cut.d.ts +5 -0
- package/dist/run-file-cut.js +13 -0
- package/dist/run-launch.js +16 -3
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-model-key.d.ts +15 -6
- package/dist/run-model-key.js +30 -31
- package/dist/run-reads-over-store.js +4 -4
- package/dist/run-secrets.js +3 -5
- package/dist/run-timeline-served.js +3 -1
- package/dist/run-view.d.ts +1 -2
- package/dist/run-view.js +2 -1
- package/dist/runnable.js +2 -2
- package/dist/runner/adapter-loop.d.ts +35 -18
- package/dist/runner/adapter-loop.js +97 -63
- package/dist/runner/adapter-run-spec.d.ts +34 -14
- package/dist/runner/adapter-run-spec.js +120 -75
- package/dist/runner/adapters/pi.js +4 -2
- package/dist/runner/audit.d.ts +8 -5
- package/dist/runner/audit.js +37 -17
- package/dist/runner/beside.d.ts +9 -2
- package/dist/runner/beside.js +29 -13
- package/dist/runner/claim-secrets.d.ts +27 -18
- package/dist/runner/claim-secrets.js +61 -47
- package/dist/runner/cli-run-spec.d.ts +18 -0
- package/dist/runner/cli-run-spec.js +93 -46
- package/dist/runner/compare-end.d.ts +2 -1
- package/dist/runner/compare-end.js +25 -10
- package/dist/runner/conformance/harness.js +2 -3
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/harness-loops.js +3 -3
- package/dist/runner/held.d.ts +19 -4
- package/dist/runner/journal-kinds.d.ts +4 -1
- package/dist/runner/journal-kinds.js +22 -4
- package/dist/runner/learned-first.js +20 -4
- package/dist/runner/learning-end.d.ts +2 -8
- package/dist/runner/learning-end.js +11 -19
- package/dist/runner/live-ticker.js +7 -5
- package/dist/runner/loop-contract.d.ts +0 -2
- package/dist/runner/loop.d.ts +7 -0
- package/dist/runner/loop.js +1 -0
- package/dist/runner/main.d.ts +11 -6
- package/dist/runner/main.js +24 -18
- package/dist/runner/mcp-claim.js +24 -7
- package/dist/runner/mcp-run.d.ts +3 -6
- package/dist/runner/mcp-run.js +3 -4
- package/dist/runner/meta-tools.js +3 -2
- package/dist/runner/metrics.d.ts +7 -0
- package/dist/runner/metrics.js +19 -0
- package/dist/runner/model-route.d.ts +10 -7
- package/dist/runner/model-route.js +79 -15
- package/dist/runner/native-loop.js +10 -8
- package/dist/runner/presence.d.ts +11 -4
- package/dist/runner/presence.js +11 -6
- package/dist/runner/promotion.d.ts +25 -13
- package/dist/runner/promotion.js +125 -50
- package/dist/runner/redact.d.ts +3 -1
- package/dist/runner/redact.js +5 -3
- package/dist/runner/reflect-hook.js +1 -1
- package/dist/runner/responses-fetch.d.ts +36 -0
- package/dist/runner/responses-fetch.js +511 -0
- package/dist/runner/run-child-host.d.ts +38 -12
- package/dist/runner/run-child-host.js +231 -83
- package/dist/runner/run-child.js +11 -4
- package/dist/runner/runner-check.js +5 -1
- package/dist/runner/runner.d.ts +5 -3
- package/dist/runner/runner.js +14 -10
- package/dist/runner/save-slots.js +2 -1
- package/dist/runner/sdk-loop.js +8 -8
- package/dist/runner/spec-holds.d.ts +8 -1
- package/dist/runner/spec-holds.js +9 -4
- package/dist/runner/subagent.d.ts +11 -0
- package/dist/runner/subagent.js +17 -3
- package/dist/runner/workflow-calls.d.ts +9 -0
- package/dist/runner/workflow-calls.js +150 -0
- package/dist/runner/workflow-first.d.ts +138 -37
- package/dist/runner/workflow-first.js +230 -99
- package/dist/runner/workflow-spec.js +2 -2
- package/dist/runs-over-store.js +8 -7
- package/dist/save-once.d.ts +14 -0
- package/dist/save-once.js +31 -0
- package/dist/scrub-command.d.ts +34 -31
- package/dist/scrub-command.js +116 -147
- package/dist/sdk/runs.d.ts +6 -0
- package/dist/sdk/runs.js +89 -10
- package/dist/seal-key.js +4 -4
- package/dist/secret-cut.d.ts +3 -0
- package/dist/secret-cut.js +7 -1
- package/dist/secret-rules.d.ts +8 -1
- package/dist/secret-rules.js +482 -53
- package/dist/secrets.d.ts +51 -9
- package/dist/secrets.js +311 -21
- package/dist/server-keys.d.ts +4 -3
- package/dist/server-keys.js +4 -3
- package/dist/server-secrets-store.js +2 -4
- package/dist/server.d.ts +33 -10
- package/dist/server.js +454 -136
- package/dist/share-context.d.ts +22 -0
- package/dist/share-context.js +76 -0
- package/dist/shell-lex.d.ts +105 -0
- package/dist/shell-lex.js +646 -0
- package/dist/sign-ins-store.d.ts +5 -7
- package/dist/sign-ins-store.js +12 -16
- package/dist/sign-ins.d.ts +7 -11
- package/dist/sign-ins.js +40 -41
- package/dist/skills/agentrun-serve/SKILL.md +5 -2
- package/dist/slots.d.ts +9 -0
- package/dist/slots.js +45 -0
- package/dist/start-switches.d.ts +6 -5
- package/dist/start-switches.js +8 -4
- package/dist/stats.d.ts +5 -1
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.js +2 -2
- package/dist/store/dialect.d.ts +4 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/mcp-record-keys.d.ts +10 -0
- package/dist/store/mcp-record-keys.js +13 -0
- package/dist/store/postgres/dialect.js +2 -0
- package/dist/store/postgres/migrations/0028_learning_ledger.sql +44 -0
- package/dist/store/postgres/migrations/0029_run_launch_census_settle.sql +28 -0
- package/dist/store/postgres/migrations/0030_learning_ledger_epoch.sql +40 -0
- package/dist/store/postgres/migrations/0031_learning_ledger_calls.sql +12 -0
- package/dist/store/postgres/store.js +4 -0
- package/dist/store/schema.d.ts +44 -4
- package/dist/store/schema.js +111 -11
- package/dist/store/seal.d.ts +4 -1
- package/dist/store/sqlite/run-launch.d.ts +3 -10
- package/dist/store/sqlite/run-launch.js +12 -23
- package/dist/store/sqlite/run-patch.d.ts +19 -2
- package/dist/store/sqlite/run-patch.js +67 -2
- package/dist/store/sqlite/store.d.ts +3 -0
- package/dist/store/sqlite/store.js +177 -32
- package/dist/store/store-schema.js +3 -4
- package/dist/store/store.d.ts +74 -25
- package/dist/store/store.js +14 -11
- package/dist/store-reads/analytics.d.ts +2 -1
- package/dist/store-reads/analytics.js +7 -5
- package/dist/store-reads/learning.d.ts +102 -136
- package/dist/store-reads/learning.js +251 -302
- package/dist/store-reads/stats.d.ts +2 -2
- package/dist/store-reads/stats.js +13 -7
- package/dist/store-view.js +10 -7
- package/dist/suggestions.d.ts +1 -1
- package/dist/suggestions.js +29 -13
- package/dist/template-eval.d.ts +91 -9
- package/dist/template-eval.js +448 -105
- package/dist/template-import.d.ts +0 -10
- package/dist/template-import.js +5 -10
- package/dist/timeline/labels.d.ts +1 -1
- package/dist/timeline/labels.js +4 -3
- package/dist/timeline/timeline.d.ts +23 -11
- package/dist/timeline/timeline.js +115 -31
- package/dist/timeline/web-calls.d.ts +14 -14
- package/dist/timeline/web-calls.js +18 -30
- package/dist/tool-gate.d.ts +13 -1
- package/dist/tool-gate.js +43 -3
- package/dist/tool-keys-store.js +2 -4
- package/dist/tool-keys.d.ts +11 -0
- package/dist/tool-keys.js +16 -0
- package/dist/tool-plane.d.ts +50 -11
- package/dist/tool-plane.js +94 -30
- package/dist/tools.d.ts +5 -1
- package/dist/tools.js +7 -7
- package/dist/trigger-email.js +12 -6
- package/dist/triggers.d.ts +15 -34
- package/dist/triggers.js +119 -126
- package/dist/validate.d.ts +8 -1
- package/dist/validate.js +163 -23
- package/dist/web-fake.d.ts +2 -1
- package/dist/web-fake.js +8 -6
- package/dist/web-fetch.d.ts +8 -6
- package/dist/web-fetch.js +13 -11
- package/dist/web-holds.d.ts +32 -0
- package/dist/web-holds.js +86 -0
- package/dist/web-run.d.ts +32 -5
- package/dist/web-run.js +75 -28
- package/dist/web-save.d.ts +4 -9
- package/dist/web-save.js +27 -55
- package/dist/web-search.js +14 -25
- package/dist/wires.d.ts +4 -3
- package/dist/wires.js +5 -4
- package/dist/workspace/archil-claim.d.ts +12 -5
- package/dist/workspace/archil-claim.js +45 -5
- package/dist/workspace/attach.js +52 -19
- package/dist/workspace/attached-computers.d.ts +38 -11
- package/dist/workspace/attached-computers.js +81 -16
- package/dist/workspace/computer-deps.d.ts +29 -7
- package/dist/workspace/computer-deps.js +36 -18
- package/dist/workspace/computer-for-claim.d.ts +21 -4
- package/dist/workspace/computer-for-claim.js +166 -57
- package/dist/workspace/computer-intervals.d.ts +2 -0
- package/dist/workspace/computer-intervals.js +1 -1
- package/dist/workspace/computer-janitor.d.ts +48 -14
- package/dist/workspace/computer-janitor.js +153 -44
- package/dist/workspace/computer-kept.d.ts +158 -32
- package/dist/workspace/computer-kept.js +288 -63
- package/dist/workspace/computer-providers.d.ts +8 -3
- package/dist/workspace/computer-providers.js +12 -5
- package/dist/workspace/index.d.ts +1 -1
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/local.js +41 -1
- package/dist/workspace/mount-revoke-left.d.ts +31 -0
- package/dist/workspace/mount-revoke-left.js +72 -0
- package/dist/workspace/paired-route.d.ts +91 -0
- package/dist/workspace/paired-route.js +152 -0
- package/dist/workspace/resolve-computer.d.ts +5 -2
- package/dist/workspace/resolve-computer.js +9 -3
- package/dist/workspace/run-end-computers.d.ts +11 -5
- package/dist/workspace/run-end-computers.js +153 -28
- package/dist/workspace/run-tools.d.ts +22 -3
- package/dist/workspace/run-tools.js +17 -5
- package/dist/workspace/run-workspace.d.ts +14 -1
- package/dist/workspace/run-workspace.js +34 -1
- package/dist/workspace/workspace.d.ts +6 -0
- package/dist/wrapped.d.ts +8 -2
- package/dist/wrapped.js +21 -6
- package/package.json +12 -13
- package/skills/agentrun-serve/SKILL.md +5 -2
- package/templates/README.md +25 -9
- package/dist/console/assets/backend-DVhHzJX2.js +0 -166
- package/dist/console/assets/index-Bwn1oTem.css +0 -1
- package/dist/console/assets/index-okP-y8PK.js +0 -747
package/dist/server.js
CHANGED
|
@@ -27,18 +27,19 @@ import { isNativeRuntime, NATIVE_RUNTIME_FACTS } from "./native/runtimes.js";
|
|
|
27
27
|
import { connectNative, launchNative, updateNative, verifyConnection } from "./native/connection.js";
|
|
28
28
|
// The /v2 API over the agent store in a data directory: the contract agentrun.v2/0, served on loopback with a bearer
|
|
29
29
|
// token.
|
|
30
|
-
import { createHash, createHmac, randomBytes } from "node:crypto";
|
|
30
|
+
import { createHash, createHmac, randomBytes, randomUUID } from "node:crypto";
|
|
31
31
|
import { chmod, lstat, mkdir, readFile, realpath, rename, stat, writeFile } from "node:fs/promises";
|
|
32
32
|
import { createServer } from "node:http";
|
|
33
33
|
import proxyaddr from "proxy-addr";
|
|
34
34
|
import { API_ONLY_HOOKED_KINDS, apiOnlyMcpSave, apiOnlyRefusal, apiOnlyTriggerSkipped, servedApiOnly } from "./api-only.js";
|
|
35
35
|
import { API_ONLY_MCP_ORIGINS_ENV, apiOnlyMcpOriginsFrom, RUN_KEYS_ENV } from "./env-switch.js";
|
|
36
|
-
import { holdApiOnlyMcpOrigins, offApiOnlyMcpServers } from "./mcp-api-only-origins.js";
|
|
36
|
+
import { composioOutsideNamespaceServers, holdApiOnlyMcpOrigins, offApiOnlyMcpServers } from "./mcp-api-only-origins.js";
|
|
37
37
|
import { declaredKeys, keysOwed, keysOwedRefusal, runKeysOf, runKeysTriggerSkipped, undeclaredKeys, withCarried } from "./run-keys.js";
|
|
38
38
|
import { capacityOverStore, capacityWindowOf } from "./capacity.js";
|
|
39
39
|
import { carriedFields } from "./answer-json.js";
|
|
40
40
|
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
41
41
|
import { pathToFileURL } from "node:url";
|
|
42
|
+
import { isDeepStrictEqual } from "node:util";
|
|
42
43
|
import { Worker } from "node:worker_threads";
|
|
43
44
|
import { once } from "node:events";
|
|
44
45
|
import { existsSync } from "node:fs";
|
|
@@ -50,15 +51,15 @@ import { uuidv7 } from "./ids.js";
|
|
|
50
51
|
import { agentRevision, agentRevisions, agentView, commitAgent, createAgent, definitionOf, etagOf, externalKey, getAgent, listAgents, makeRevision, ownedElsewhere, refuseExternal, revisionView, setAgentArchived, setCurrentRevision } from "./agents-store.js";
|
|
51
52
|
import { WORKFLOW_ADAPTERS } from "./runner/workflow-adapters.js";
|
|
52
53
|
import { DECISION_ADAPTER, decisionsOf, FAUX_JEV_ENV, FAUX_OPENROUTER_ENV, FAUX_PARALLEL_ENV, fauxFetch } from "./decisions.js";
|
|
53
|
-
import { FAUX_EXA_ENV, FAUX_FIRECRAWL_ENV, FAUX_WEB_ENV } from "./web-run.js";
|
|
54
|
-
import { FAUX_MONID_ENV, MONID_KEY_ENV, pinMonid, PRICED_BY_USAGE } from "./monid.js";
|
|
54
|
+
import { FAUX_EXA_ENV, FAUX_FIRECRAWL_ENV, FAUX_WEB_ENV, withHeld } from "./web-run.js";
|
|
55
|
+
import { FAUX_MONID_ENV, MONID_KEY_ENV, monidReads, pinMonid, PRICED_BY_USAGE } from "./monid.js";
|
|
55
56
|
import { FAUX_BROWSER_ENV, NODE_TOOLS, shellTools, toolingOf, toolOf, toolsView } from "./tools.js";
|
|
56
57
|
import { ApiError, invalid, sentence, unsupported } from "./errors.js";
|
|
57
58
|
import { deref, explain } from "./explain.js";
|
|
58
59
|
import { HOME_HOST_OWNED } from "./files.js";
|
|
59
60
|
import { DATA_ENV, syncDir, TOKEN_FILE, writeDurable } from "./server-fs.js";
|
|
60
61
|
import { homePath, hostOwnedOf } from "./home-path.js";
|
|
61
|
-
import { asksOllama, chooseModel, EFFORTS, FAUX_ENV, MODEL_NODES, modelSource, THINKING_LEVELS, unpricedModels, withoutFaux } from "./model.js";
|
|
62
|
+
import { asksOllama, chooseModel, EFFORTS, FAUX_ENV, hostModel, MODEL_NODES, modelSource, THINKING_LEVELS, unpricedModels, withoutFaux } from "./model.js";
|
|
62
63
|
import { DEFAULT_HARNESS, HARNESSES, harnessOfBody, harnessOffers } from "./harness.js";
|
|
63
64
|
import { HARNESS_MODULES_ENV, HARNESS_MODULES_SETTING, HARNESS_RECIPES_ENV, HARNESS_RECIPES_SETTING, HARNESS_TABLE_ENV, harnessIds, harnessModulesEnv, harnessOf, harnessRecipesEnv, planRecipesOf, recipeHarness, tableIds } from "./harness-table.js";
|
|
64
65
|
import { claudeCliIn, HarnessInstall, installDirOf, NPM_STOP_GRACE_MS, npmInstall } from "./harness-install.js";
|
|
@@ -106,7 +107,9 @@ import { agentPointers, cutHanded, handedSecretValues, launchValuesOf, RETIRED_M
|
|
|
106
107
|
import { runCutValues } from "./run-cut.js";
|
|
107
108
|
import { readLaunchBody } from "./run-launch.js";
|
|
108
109
|
import { modelKeyMisfit, modelKeyOf, modelKeyRequired, noServerKeyFor, runModelOrigin, serverKeyMissing } from "./run-model-key.js";
|
|
110
|
+
import { exportReadsOverStore } from "./run-export-store.js";
|
|
109
111
|
import { listRunFiles as listRunFilesOverStore, readRunFile as readRunFileOverStore, runGraphView, runTimelines } from "./run-reads-over-store.js";
|
|
112
|
+
import { ExportFailed, restoreIdsOf, runExport } from "./run-export.js";
|
|
110
113
|
import { triggerTargets } from "./trigger-targets.js";
|
|
111
114
|
import { labelFilter, labelsIssues } from "./run-labels.js";
|
|
112
115
|
import { listRuns as listRunsOverStore, readRun as readRunOverStore, runOfOrigin as runOfOriginOverStore } from "./store-reads/runs.js";
|
|
@@ -122,7 +125,7 @@ import { keepGrade } from "./runner/feedback-round.js";
|
|
|
122
125
|
import { gradeRow, notAuditableOf } from "./runner/audit.js";
|
|
123
126
|
import { namedDisksOf } from "./learn/learning-of.js";
|
|
124
127
|
import { auditsOffWords, auditWriterOf, isShadowRun, readAudits, servingLinesOf, shadowRunId } from "./learn/audit.js";
|
|
125
|
-
import { auditLoopOf, COMPILE_AFTER_MAX } from "./learning-setting.js";
|
|
128
|
+
import { auditLoopOf, COMPILE_AFTER_MAX, holdsReservedKey, RESERVED_SEGMENT } from "./learning-setting.js";
|
|
126
129
|
import { FINAL_STATES, RUN_CHANGES_PAGE } from "./store/store.js";
|
|
127
130
|
import { championOf, forgetRunCopies, GRADE_SOURCES, gradeView, LABEL_MAX, promotionsOf, promotionsShown, servingOf, servingStateOf, shownDeep } from "./learn/promote.js";
|
|
128
131
|
import { workflowNodesOf } from "./learn/workflow-nodes.js";
|
|
@@ -133,7 +136,7 @@ import { REDACTED } from "./secret-cut.js";
|
|
|
133
136
|
// The v2 run statuses, as the run view names them (run-view.ts Status), for the list filter's validation. */
|
|
134
137
|
const STATUSES = ["queued", "working", "paused", "input_required", "completed", "failed", "cancelled"];
|
|
135
138
|
import { runLines } from "./usage-lines.js";
|
|
136
|
-
import { boxesByDefault, boxesLog, enabledBoxes, placeOffers, withNetworks } from "./place-offers.js";
|
|
139
|
+
import { boxesByDefault, boxesLog, DOCKER_NO_SOCKET, enabledBoxes, LOCAL_BOXES, placeOffers, withNetworks } from "./place-offers.js";
|
|
137
140
|
import { dockerComputerRefusal, dockerPathsOf, FAUX_MOUNTINFO_ENV, remoteDockerOnce } from "./box-paths.js";
|
|
138
141
|
import { dockerDaemonCheck } from "./docker-daemon.js";
|
|
139
142
|
import { hostAddressesOnce, noHostAddresses, retryHostAddresses, unionOf } from "./docker-host-addresses.js";
|
|
@@ -144,15 +147,16 @@ import { hostSecrets, SECRET_NAMES, secret, withSecrets } from "./secrets.js";
|
|
|
144
147
|
import { isSecretWriteOperation, secretPageFor, secretsWritableFields, secretWriteRefusal, secretWriterFacts, writesSecretFor, writesSecretsAllowed } from "./secret-writes.js";
|
|
145
148
|
import { ChatGPTPlan, planOf, PlanSignInRefused, SIGN_OUT_UNCONFIRMED, withPlan } from "./chatgpt-plan.js";
|
|
146
149
|
import { modelGatewayRoute, readSavedGateway, withSavedGateway } from "./model-gateway.js";
|
|
147
|
-
import { CLAUDE_LOGIN_ROUTES, LOGIN_REFUSES_API_KEYS, oneOwnerDeps, ClaudeLoginRefused, claudeLoginOf, claudeLoginRouteOff, claudeLoginSwitchedOff, claudeLoginSetting, claudeLoginView, dropRefusedLogin, envAtPlace, LOGIN_HARNESS, loginOf, loopback, startLoginHere, turnOffClaudeLogin, turnOnClaudeLogin, withClaudeLogin } from "./claude-login.js";
|
|
150
|
+
import { CLAUDE_LOGIN_ROUTES, LOGIN_REFUSES_API_KEYS, oneOwnerDeps, ClaudeLoginRefused, claudeLoginOf, claudeLoginRouteOff, claudeLoginServed, claudeLoginSwitchedOff, claudeLoginSetting, claudeLoginView, dropRefusedLogin, envAtPlace, LOGIN_HARNESS, loginOf, loginOnRunnerOnly, loopback, startLoginHere, turnOffClaudeLogin, turnOnClaudeLogin, withClaudeLogin } from "./claude-login.js";
|
|
148
151
|
import { ClaudeSignIns } from "./claude-sign-in.js";
|
|
149
152
|
import { bootSealKey, parametersDigest, withSealKey } from "./seal-key.js";
|
|
150
153
|
import { ServerLockHeldError, takeServerLock } from "./server-lock.js";
|
|
151
154
|
import { recordDataRoot } from "./runner/disk-free.js";
|
|
152
155
|
import { recordRunEnv, runFacingNames } from "./runner/runner-check.js";
|
|
153
156
|
import { DRAIN_TIMEOUT } from "./runner/beside.js";
|
|
154
|
-
import {
|
|
155
|
-
import {
|
|
157
|
+
import { runnerName } from "./runner/runner.js";
|
|
158
|
+
import { analyticsFilter, analyticsView, statsView, utcOf } from "./stats.js";
|
|
159
|
+
import { loggedReads, within, WRAPPED_WAIT_MS, wrappedView } from "./wrapped.js";
|
|
156
160
|
import { joinedBasis } from "./runner/metrics.js";
|
|
157
161
|
import { unifiedUsage } from "./unified-usage.js";
|
|
158
162
|
import { agentLoopOverStore } from "./store-reads/loop.js";
|
|
@@ -166,7 +170,8 @@ import { SIGN_INS_DIR, vendorsOver } from "./sign-ins.js";
|
|
|
166
170
|
import { signInsOverStore } from "./sign-ins-store.js";
|
|
167
171
|
import { boundTool, MCP_AUTH_TYPES, marked, mcpAuthOf, nameOf as mcpNameOf } from "./mcp-probe.js";
|
|
168
172
|
import { composioEnvKey, composioMadeKey, composioPerRun } from "./composio-made.js";
|
|
169
|
-
import {
|
|
173
|
+
import { ownersComposioUsers, ownersUser } from "./composio-owners.js";
|
|
174
|
+
import { COMPOSIO_PER_RUN, composioForget, composioNote, composioSave, composioTokenUser, composioToolkits, composioTools } from "./composio-preset.js";
|
|
170
175
|
import { ComposioTriggers, composioNoPublicUrl } from "./composio-triggers.js";
|
|
171
176
|
import { loopbackWords, mcpServersOverStore } from "./mcp-servers-store.js";
|
|
172
177
|
import { MCP_ALLOW_LOOPBACK_ENV, startSwitches, WEBHOOK_PRIVATE_TARGETS_ENV } from "./start-switches.js";
|
|
@@ -201,7 +206,7 @@ import { hereOf, Marketplace, marketplaceUrlOf } from "./marketplace.js";
|
|
|
201
206
|
import { templateInstallLink, templateLink, templatesLink } from "./console-links.js";
|
|
202
207
|
import { GITHUB_HOSTS, IMPORT_LIMITS } from "./template-source.js";
|
|
203
208
|
import { checkDefinitionBody, DEFAULT_INPUT_SCHEMA, definitionBodyIssues, EXTERNAL_NAME, ID, IDEMPOTENCY_TTL_S, inputIssues, inputSchemaOf, isObject, stable, unknownFields } from "./validate.js";
|
|
204
|
-
import { agentTools, BROWSER_VENDOR_IDS, browserKeyRow, isUnavailable, keptVendor, loadToolSettings, recheckPlane, settingsIssues, whyUnavailable, withDefaults } from "./tool-plane.js";
|
|
209
|
+
import { agentTools, BROWSER_VENDOR_IDS, browserKeyRow, DEFAULT_BROWSER_VENDOR, isUnavailable, keptVendor, loadToolSettings, recheckPlane, settingsIssues, whyUnavailable, withDefaults } from "./tool-plane.js";
|
|
205
210
|
import { wakeAnsweredBySetting } from "./settings-wake.js";
|
|
206
211
|
import { toolSettingsOverStore } from "./tool-settings-store.js";
|
|
207
212
|
import { readApprovers, writeApprovers } from "./server-approvers.js";
|
|
@@ -214,9 +219,11 @@ import { heldRoute, holdIssues, runComputerRead } from "./computer-held-routes.j
|
|
|
214
219
|
import { COMPUTER_ROUTES, computerHoldOf, computerRoute, runComputerKind } from "./computer-routes.js";
|
|
215
220
|
import { runOver } from "./computer-commands.js";
|
|
216
221
|
import { mintViewerCredential, VIEWER_PARAM, viewerCookie, viewerCredentialFor, viewerCredentialKey, viewerCredentialOf } from "./viewer-credential.js";
|
|
217
|
-
import { ATTACH_PATH, AttachHub, PROVIDERS as COMPUTER_PROVIDERS, SETTING_KINDS, servingRefusals } from "@parcha/agentrun-computer";
|
|
222
|
+
import { ATTACH_PATH, AttachHub, containerSigns, PROVIDERS as COMPUTER_PROVIDERS, SETTING_KINDS, servingRefusals } from "@parcha/agentrun-computer";
|
|
223
|
+
import { dockerDaemonOf } from "@parcha/agentrun-computer/docker";
|
|
218
224
|
import { createAttachRoutes, liveRelays, pairedView } from "./computer-attach.js";
|
|
219
225
|
import { pairedRefusal, withPaired } from "./workspace/attached-computers.js";
|
|
226
|
+
import { PAIRED_ROUTE_MS, readRoute } from "./workspace/paired-route.js";
|
|
220
227
|
import { COMPUTER_TOOLS, hostToolDefs } from "@parcha/agentrun-kernel/kernel";
|
|
221
228
|
import { freeModelRequestsOf } from "@parcha/agentrun-kernel/kernel/cap";
|
|
222
229
|
import { archilRoute, createArchilRoutes, liveRunsOnDisk } from "./archil-routes.js";
|
|
@@ -265,6 +272,14 @@ const MAX_WAIT_MS = 25_000;
|
|
|
265
272
|
const HANDED_FIXED = ["revision", "hold", "hold_minutes"];
|
|
266
273
|
/** How often the server fails the runs still queued while no runner here can take them (runner/presence.ts). */
|
|
267
274
|
const REFUSED_SWEEP_MS = 2_000;
|
|
275
|
+
/** How long the server's stop waits for a ChatGPT sign-in it cancelled to end (ChatGPTPlan.close): one past its code's
|
|
276
|
+
* exchange saves its row before the store closes; one OpenAI holds longer does not hold the stop. */
|
|
277
|
+
const PLAN_CLOSE_MS = 2_000;
|
|
278
|
+
/** The ChatGPT sign-ins `plan` cancels, ended, or `ms` gone. */
|
|
279
|
+
const planClosed = (plan, ms) => {
|
|
280
|
+
let timer;
|
|
281
|
+
return Promise.race([plan.close(), new Promise((done) => (timer = setTimeout(done, ms)))]).finally(() => clearTimeout(timer));
|
|
282
|
+
};
|
|
268
283
|
const PAGE_ROWS = 500;
|
|
269
284
|
const FILE_LIST_CAP = 2_000;
|
|
270
285
|
/** Where the stop's lines go (ServeOptions.notice). Best-effort: a notice that throws never stops a close or a start. */
|
|
@@ -368,6 +383,7 @@ export const ROUTES = [
|
|
|
368
383
|
{ method: "PUT", pattern: /^\/agents\/([^/]+)\/definition$/, name: "updateDefinition" },
|
|
369
384
|
{ method: "GET", pattern: /^\/agents\/([^/]+)\/revisions$/, name: "listRevisions" },
|
|
370
385
|
{ method: "GET", pattern: /^\/agents\/([^/]+)\/package$/, name: "getAgentPackage" },
|
|
386
|
+
{ method: "GET", pattern: /^\/agents\/([^/]+)\/revisions\/([^/]+)\/skills$/, name: "getRevisionSkills" },
|
|
371
387
|
{ method: "POST", pattern: /^\/agents\/([^/]+)\/current$/, name: "setCurrent" },
|
|
372
388
|
{ method: "POST", pattern: /^\/agents\/([^/]+)\/archive$/, name: "archiveAgent" },
|
|
373
389
|
{ method: "POST", pattern: /^\/agents\/([^/]+)\/unarchive$/, name: "unarchiveAgent" },
|
|
@@ -401,6 +417,8 @@ export const ROUTES = [
|
|
|
401
417
|
{ method: "GET", pattern: /^\/runs\/([^/]+)\/trace$/, name: "getRunTrace" },
|
|
402
418
|
// A run's usage lines (run-usage.ts): by meter, model, charger and provider, each with its quantity and its cost.
|
|
403
419
|
{ method: "GET", pattern: /^\/runs\/([^/]+)\/usage$/, name: "getRunUsage" },
|
|
420
|
+
// A run's share bundle (run-export.ts): an ended run as one agentrun.share/1 document, every string cut by the scrubber.
|
|
421
|
+
{ method: "GET", pattern: /^\/runs\/([^/]+)\/export$/, name: "getRunExport" },
|
|
404
422
|
{ method: "POST", pattern: /^\/workflows\/validate$/, name: "validateWorkflow" },
|
|
405
423
|
{ method: "POST", pattern: /^\/runs\/([^/]+)\/pause$/, name: "pauseRun" },
|
|
406
424
|
{ method: "POST", pattern: /^\/runs\/([^/]+)\/resume$/, name: "resumeRun" },
|
|
@@ -615,7 +633,7 @@ async function keptBrowserOf(store, runId) {
|
|
|
615
633
|
const kept = plane ? keptVendor(plane).browser : undefined;
|
|
616
634
|
if (kept !== undefined)
|
|
617
635
|
return kept;
|
|
618
|
-
return granted ?
|
|
636
|
+
return granted ? DEFAULT_BROWSER_VENDOR : undefined;
|
|
619
637
|
}
|
|
620
638
|
/** keptBrowserOf's answer for a run whose browser is its agent's browser computer. */
|
|
621
639
|
const ON_COMPUTER = Symbol("the agent's browser computer");
|
|
@@ -653,7 +671,7 @@ const GATEWAY_VARS = ["AGENT_MODEL_BASE_URL", "AGENT_MODEL_GATEWAY_IDS", "AGENT_
|
|
|
653
671
|
* saved key is one of those; the rest of the environment is the server's start's), and the models the Ollama here
|
|
654
672
|
* listed when last asked (ollamaListing). Held to tell whether a write, or a new listing, needs the offers probed again,
|
|
655
673
|
* never shown. */
|
|
656
|
-
const offersInputs = (env) => [...SECRET_NAMES.filter((name) => !TOOL_FIELDS.includes(name)).map((name) => env[name]), ...GATEWAY_VARS.map((name) => env[name]), planOf(env)?.state, planOf(env)?.models.join(" "), claudeLoginOf(env)
|
|
674
|
+
const offersInputs = (env) => [...SECRET_NAMES.filter((name) => !TOOL_FIELDS.includes(name)).map((name) => env[name]), ...GATEWAY_VARS.map((name) => env[name]), planOf(env)?.state, planOf(env)?.models.join(" "), ...[claudeLoginOf(env)].map((login) => (login && "dir" in login ? login.dir : undefined)), ollamaListing(env)];
|
|
657
675
|
/** A sign-in step's answer; its refusal (a stale or bad pasted address, no sign-in waiting, OpenAI's no) a 400 in words. */
|
|
658
676
|
async function planStep(step) {
|
|
659
677
|
try {
|
|
@@ -715,7 +733,7 @@ function capabilitiesWith(env, maxRuns, harnesses, learning, { needs, priced, le
|
|
|
715
733
|
const memory = hostMemory();
|
|
716
734
|
// The browser's key is its vendor's row: Kernel's where Kernel is picked or resolved (tool-plane.ts browserKeyRow).
|
|
717
735
|
const keyFor = (tool) => (tool.name === "browser" ? browserKeyRow(tool.provider, tool.resolves?.[DEFAULT_HARNESS]) : keyOf(tool.name));
|
|
718
|
-
const tools = toolsView(env, toolSettings, noBoxReason(boxes), refused, runnerShell).map((tool) => (keyFor(tool) ? { ...tool, key: keyFor(tool) } : tool));
|
|
736
|
+
const tools = toolsView(env, toolSettings, noBoxReason(boxes, enabledBoxes(env)), refused, runnerShell).map((tool) => (keyFor(tool) ? { ...tool, key: keyFor(tool) } : tool));
|
|
719
737
|
const browser = tools.find((tool) => tool.name === "browser");
|
|
720
738
|
return {
|
|
721
739
|
backend: "local",
|
|
@@ -778,7 +796,7 @@ function capabilitiesWith(env, maxRuns, harnesses, learning, { needs, priced, le
|
|
|
778
796
|
thinking: [...THINKING_LEVELS],
|
|
779
797
|
/** The browser a run's `browser` tool drives: the vendor it resolves to under the server's settings when the tool is
|
|
780
798
|
* available here (tools[]), a browser provider's id (tool-plane.ts BROWSER_VENDOR_IDS), else none. */
|
|
781
|
-
browser: browser?.available ? ((resolved) => (BROWSER_VENDOR_IDS.includes(resolved ?? "") ? resolved :
|
|
799
|
+
browser: browser?.available ? ((resolved) => (BROWSER_VENDOR_IDS.includes(resolved ?? "") ? resolved : DEFAULT_BROWSER_VENDOR))(browser.resolves?.[DEFAULT_HARNESS]) : "none",
|
|
782
800
|
/** A tool setting's `permission` (definition.tool_settings, /v2/settings/tools): allow, ask or deny, which the tool
|
|
783
801
|
* gate holds every tool call to (tool-gate.ts); an ask is answered at POST /runs/{id}/approvals/{approval_id}. */
|
|
784
802
|
tool_permissions: true,
|
|
@@ -892,8 +910,9 @@ export function whyNotOwnMachine(options, data, ownUser) {
|
|
|
892
910
|
}
|
|
893
911
|
/** Why `options` on `data` is not one owner's server on their own machine as far as who reaches it goes, each reason in
|
|
894
912
|
* words: whyNotOwnMachine's facts but its runner's. What may read this machine's own files for whoever asks (GET
|
|
895
|
-
* /v2/wrapped).
|
|
896
|
-
|
|
913
|
+
* /v2/wrapped). `keys`: the live API keys made in the console (api-keys.ts), each one more caller, as a second token is
|
|
914
|
+
* (claude-login.ts whyNotOneOwner counts them too); 0 where none can open the server. */
|
|
915
|
+
export function whyNotOwnersServer(options, data, keys = 0) {
|
|
897
916
|
const host = options.host ?? DEFAULT_HOST;
|
|
898
917
|
// Every token the server takes (acceptedTokens): AGENTRUN_TOKEN's as `default` beside the list's, or else DIR/.token's alone.
|
|
899
918
|
const tokens = (options.token === undefined ? 0 : 1) + (options.tokens?.length ?? 0);
|
|
@@ -902,6 +921,7 @@ export function whyNotOwnersServer(options, data) {
|
|
|
902
921
|
...(options.publicUrl ? [`has a public address (${options.publicUrl})`] : []),
|
|
903
922
|
...(options.apiOnly ? ["has no owner (the API-only profile), so anyone with its token starts runs"] : []),
|
|
904
923
|
...(tokens > 1 ? [`takes ${tokens} API tokens (AGENTRUN_TOKEN and AGENTRUN_TOKENS together), so more than one person starts runs`] : []),
|
|
924
|
+
...(keys > 0 ? [`has ${keys === 1 ? "an API key" : `${keys} API keys`} made for apps (Settings → AgentRun API keys), so more than one caller reaches it`] : []),
|
|
905
925
|
...(storeTarget(data).kind === "sqlite" ? [] : ["keeps its store in Postgres (AGENTRUN_STORE_URL), which servers elsewhere share"]),
|
|
906
926
|
];
|
|
907
927
|
}
|
|
@@ -1083,6 +1103,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1083
1103
|
// which the runner beside the server shares (Serve.attachHub), so one process holds them. A second server on this
|
|
1084
1104
|
// store is refused above (its owner lock).
|
|
1085
1105
|
const attachHub = new AttachHub();
|
|
1106
|
+
// The runner beside this server, as its run's route of a paired box names it (Serve.beside): a new name and
|
|
1107
|
+
// incarnation at each start, so a route an earlier start's runner left names a runner that is gone, and goes stale.
|
|
1108
|
+
const beside = { runner: runnerName(), incarnation: randomUUID() };
|
|
1086
1109
|
// The data root's own lock, once the store is held (so a deploy on Postgres waits at the store's owner lock first): the
|
|
1087
1110
|
// store's lock holds one store, but the data root also holds what the server writes beside it (its token, its seal key,
|
|
1088
1111
|
// uploads, harness installs, learning folders), which two servers on two stores (two Postgres schemas, or SQLite and
|
|
@@ -1126,12 +1149,26 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1126
1149
|
// the proxy's proof under the seal key (live-reach.ts); any other host is never dialled. A hosted machine a runner in a
|
|
1127
1150
|
// process of its own made is relayed to that runner's attach listener the same way (dial-relay.ts).
|
|
1128
1151
|
const reach = liveReachOf(process.env, seal.key);
|
|
1152
|
+
// A runner in a process of its own that relays its dials (dial-relay.ts): one whose attach listener said it is there
|
|
1153
|
+
// within RUNNER_STALE_MS on the store's clock (liveRelays), at a host this server dials.
|
|
1154
|
+
const relayedNow = async () => (await liveRelays(store.runners)).some((row) => dialHost(row.host, reach) !== undefined);
|
|
1155
|
+
const attachLog = (event, fields) => (log ? log(logLine(event, fields)) : void process.stderr.write(`agentrun-serve: ${logLine(event, fields)}\n`));
|
|
1129
1156
|
const attach = createAttachRoutes({
|
|
1130
|
-
store, hub: attachHub, machinesOnly: options.apiOnly === true, runnerApart: options.runnerApart === true,
|
|
1157
|
+
store, hub: attachHub, machinesOnly: options.apiOnly === true, runnerApart: options.runnerApart === true, relayed: relayedNow,
|
|
1131
1158
|
relay: { runners: store.runners, reach },
|
|
1159
|
+
beside,
|
|
1132
1160
|
...(options.attachTiming ? { timing: options.attachTiming } : {}),
|
|
1133
|
-
log:
|
|
1161
|
+
log: attachLog,
|
|
1134
1162
|
});
|
|
1163
|
+
// A paired computer's socket goes where its route says (workspace/paired-route.ts): the tick moves a socket in the
|
|
1164
|
+
// wrong place, every PAIRED_ROUTE_MS. A runner apart takes a route whether this server's own runner runs beside it or
|
|
1165
|
+
// not (its runners on other hosts, AGENTRUN_RUNNER_HOSTS), so the tick runs on both. It does nothing while no computer
|
|
1166
|
+
// is paired; with a runner beside it, nothing past its one read of the routes while no route row is there and no box
|
|
1167
|
+
// is relayed (computer-attach.ts tick).
|
|
1168
|
+
const routeTick = options.apiOnly !== true
|
|
1169
|
+
? setInterval(() => void attach.tick().catch((error) => attachLog("computer_route_tick_failed", { error: error instanceof Error ? error.message : String(error) })), PAIRED_ROUTE_MS)
|
|
1170
|
+
: undefined;
|
|
1171
|
+
routeTick?.unref();
|
|
1135
1172
|
// This server's own key on every environment it reads its secrets from, so a reader opens what this store holds with the
|
|
1136
1173
|
// key checked against it, never another data directory's that this process booted too (secrets.ts holds one made key).
|
|
1137
1174
|
const own = (env) => withSealKey(env, seal.text);
|
|
@@ -1156,6 +1193,8 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1156
1193
|
// A start that fails aborts it too: what began on it (the host-address read's retry) stops with that start.
|
|
1157
1194
|
const stopping = new AbortController();
|
|
1158
1195
|
stops.push(async () => stopping.abort());
|
|
1196
|
+
/** monid's listing and inspects as this server's saves read them: a burst of saves reads each once (monid.ts monidReads). */
|
|
1197
|
+
const monidShared = monidReads();
|
|
1159
1198
|
/** The after-start seal by the events' schemas (composio-triggers.ts sealMarked), drained by stop. */
|
|
1160
1199
|
let schemaSealed = Promise.resolve();
|
|
1161
1200
|
// The start's sweep of ended runs whose stored cost is unknown (cost-heal.ts), once this server listens; stop drains it.
|
|
@@ -1177,11 +1216,20 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1177
1216
|
const fields = { count: offList.length, servers: offList.join(","), line: `runs that grant these per_run MCP servers the API token saved are refused, nothing sent, until ${API_ONLY_MCP_ORIGINS_ENV} lists their origin` };
|
|
1178
1217
|
log ? log(logLine("api_only_mcp_off_list", fields)) : void process.stderr.write(`agentrun-serve: ${logLine("api_only_mcp_off_list", fields)}\n`);
|
|
1179
1218
|
}
|
|
1219
|
+
// And the Composio servers the token saved before its users were namespaced, which may call as the owner's user: refused
|
|
1220
|
+
// at every claim (composioOutsideNamespace) until deleted. Their names alone, never a user or an address.
|
|
1221
|
+
const outside = options.apiOnly ? await composioOutsideNamespaceServers(store) : [];
|
|
1222
|
+
if (outside.length) {
|
|
1223
|
+
const fields = { count: outside.length, servers: outside.join(","), line: "runs that grant these Composio servers the API token saved before its Composio users were namespaced are refused, nothing sent: delete each, then save it again" };
|
|
1224
|
+
log ? log(logLine("api_only_composio_outside_namespace", fields)) : void process.stderr.write(`agentrun-serve: ${logLine("api_only_composio_outside_namespace", fields)}\n`);
|
|
1225
|
+
}
|
|
1180
1226
|
const mcpServers = mcpServersOverStore(store, own(withSecrets(base, "own")), VERSION);
|
|
1181
1227
|
if (options.githubMcpOrigin)
|
|
1182
1228
|
mcpServers.appOrigin = options.githubMcpOrigin;
|
|
1183
1229
|
if (options.composioMcpOrigin)
|
|
1184
1230
|
mcpServers.composioOrigin = options.composioMcpOrigin;
|
|
1231
|
+
if (options.composioControl)
|
|
1232
|
+
mcpServers.composioControl = options.composioControl;
|
|
1185
1233
|
mcpServers.standIns = options.mcpStandIns === true;
|
|
1186
1234
|
// The saved MCP servers' metadata (their addresses and the tools they list), a snapshot the checks read in step (which
|
|
1187
1235
|
// servers are saved, a workflow's grants, the template apply): the server is the one writer of these rows (a save,
|
|
@@ -1223,11 +1271,13 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1223
1271
|
// where it is signed in. A sign-in, a sign-out or an expiry it sees makes the reading again, as a key's save does.
|
|
1224
1272
|
const plan = new ChatGPTPlan({ store, sealKey: seal.key, log: (fields) => (log ? log(logLine("chatgpt", fields)) : void process.stderr.write(`agentrun-serve: ${logLine("chatgpt", fields)}\n`)), changed: () => keysChanged() });
|
|
1225
1273
|
await plan.load();
|
|
1226
|
-
stops.push(
|
|
1274
|
+
stops.push(() => planClosed(plan, options.planCloseMs ?? PLAN_CLOSE_MS));
|
|
1227
1275
|
// Claude Code's login on this machine (claude-login.ts): env carries where it is while the owner has it on, so
|
|
1228
1276
|
// claude-agent's model checks see a model without a key. Unset, its switch follows the listen address: there on
|
|
1229
1277
|
// loopback, off past it. A setting kept where the mode is now off or refused goes first.
|
|
1230
1278
|
const loginOff = claudeLoginSwitchedOff(base, options.host ?? DEFAULT_HOST);
|
|
1279
|
+
// The routes' gate and capabilities' features.claude_login, from one rule (claude-login.ts claudeLoginServed).
|
|
1280
|
+
const loginServed = claudeLoginServed(loginOff, options.apiOnly === true);
|
|
1231
1281
|
// The API keys made in the console (api-keys.ts), read once here: this process is the store's one server, so the keys
|
|
1232
1282
|
// it holds are the store's. No value is kept, so none joins the server's secrets: a key in a text is cut by its shape
|
|
1233
1283
|
// (redact/match.ts).
|
|
@@ -1246,15 +1296,18 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1246
1296
|
// since keys are made and revoked while the server runs, and the login's turn-on takes the keys' turn (oneOwnerDeps).
|
|
1247
1297
|
const oneOwner = oneOwnerDeps({ apiOnly: options.apiOnly === true, tokens: tokens.length, keysDormant: options.harnessSignIn === true }, apiKeys);
|
|
1248
1298
|
/** Why this server makes no API key now, in words; undefined when it does. The one-owner rule from its other side: a
|
|
1249
|
-
* recipe on the owner's own sign-in, and Claude Code's login on this machine while it is on, are one person's.
|
|
1299
|
+
* recipe on the owner's own sign-in, and Claude Code's login on this machine while it is on, are one person's. A
|
|
1300
|
+
* login kept while its folders are refused (the view's `refused`) counts as on: a mended folder brings it back with
|
|
1301
|
+
* no turn-on, so a key made meanwhile would open the person's plan to an app. Its turn-off removes it, and a key then. */
|
|
1250
1302
|
const apiKeysRefused = async () => options.harnessSignIn ? HARNESS_SIGN_IN_REFUSES_API_KEYS : (await claudeLoginSetting(store.settings)) ? LOGIN_REFUSES_API_KEYS : undefined;
|
|
1251
1303
|
// Making a key, revoking one and turning the login on each take a turn (ApiKeys.inTurn; the login's is taken in
|
|
1252
1304
|
// turnOnClaudeLogin, through oneOwnerDeps' `turn`), one at a time: each decides by what the others left once their writes
|
|
1253
1305
|
// landed or were undone, never by a key taken out for a removal that then fails.
|
|
1254
1306
|
// The sign-in this server starts, kept for this process (claude-sign-in.ts). Its queue is the one way the login's
|
|
1255
|
-
// setting changes, the drop here included.
|
|
1307
|
+
// setting changes, the drop here included. A server whose user may not use the saved login's folders (its home, or
|
|
1308
|
+
// those its env gives this machine's login: loginRefused) keeps it, refused in words, and logs why.
|
|
1256
1309
|
const claudeSignIns = new ClaudeSignIns({ limitMs: options.claudeSignInLimitMs });
|
|
1257
|
-
await dropRefusedLogin(claudeSignIns, store.settings, loginOff ?? oneOwner.refused(), (line) => (log ? log(logLine("claude_login", { line })) : void process.stderr.write(`agentrun-serve: ${line}\n`)));
|
|
1310
|
+
await dropRefusedLogin(claudeSignIns, store.settings, loginOff ?? oneOwner.refused(), base, (line) => (log ? log(logLine("claude_login", { line })) : void process.stderr.write(`agentrun-serve: ${line}\n`)));
|
|
1258
1311
|
// The status checks' folders a server killed mid-check left in the temporary folder, each with a copy of the account
|
|
1259
1312
|
// file (the harness's sweepClaudeStatusFolders): this user's alone, and only once the check has ended by the end it
|
|
1260
1313
|
// wrote in its folder, so a check another server on this host runs now stays. Where the mode is there, as status
|
|
@@ -1285,7 +1338,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1285
1338
|
const isolation = await runIsolationOf(base, 1, () => { }).then(runIsolationName, () => "process");
|
|
1286
1339
|
// The start-time switches as this server was started: its options, else the CLI's variables. mcpLoopback is the
|
|
1287
1340
|
// option alone, as everywhere it is read here (localInstall): the CLI sets it from AGENTRUN_MCP_ALLOW_LOOPBACK.
|
|
1288
|
-
const switched = { mcpLoopback: options.mcpLoopback === true, webhookPrivateTargets: switchedOnBy(process.env, options).webhookPrivateTargets };
|
|
1341
|
+
const switched = { mcpLoopback: options.mcpLoopback === true, webhookPrivateTargets: switchedOnBy(process.env, options).webhookPrivateTargets, apiOnlyMcpOrigins };
|
|
1289
1342
|
// harness_keys.kept from the store's snapshot, made again at each key's save or removal (harnessKeysChanged's probe).
|
|
1290
1343
|
const compose = (runnerShell) => {
|
|
1291
1344
|
const made = askNeeds(capabilitiesWith(env, maxRuns, offers, learning, needs, settings.get(), boxOffers, toolKeys.refused(), runnerShell, isolation, switched));
|
|
@@ -1295,26 +1348,43 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1295
1348
|
// What the offers held now were made from (offersInputs), and the latest probe: one a later probe overtook is dropped.
|
|
1296
1349
|
let offersFrom;
|
|
1297
1350
|
let probes = 0;
|
|
1298
|
-
// What the latest probe is made from, once it has read it, until it lands: none while no probe is out. A
|
|
1299
|
-
//
|
|
1300
|
-
// when they are made from them, and a change with any other inputs probes again.
|
|
1351
|
+
// What the latest probe is made from, once it has read it, until it lands or fails: none while no probe is out. A
|
|
1352
|
+
// probe that fails never lands; when it is the latest, it clears this as it fails, so no probe is out after it.
|
|
1301
1353
|
let probing;
|
|
1302
|
-
|
|
1354
|
+
// The latest probe's turn: it ends as that probe lands or fails, or as a later probe starts and overtakes it, whichever
|
|
1355
|
+
// is first, and never fails. A change that waits for the probe out waits for its turn (keysChanged), so a dropped
|
|
1356
|
+
// probe holds no one up and its failure is no one else's.
|
|
1357
|
+
let turn = Promise.resolve();
|
|
1358
|
+
let endTurn = () => { };
|
|
1359
|
+
const probe = (why) => {
|
|
1360
|
+
endTurn();
|
|
1361
|
+
turn = new Promise((resolve) => (endTurn = resolve));
|
|
1362
|
+
const probed = probeOffers(why);
|
|
1363
|
+
probed.then(endTurn, endTurn);
|
|
1364
|
+
return probed;
|
|
1365
|
+
};
|
|
1366
|
+
const probeOffers = async (why) => {
|
|
1303
1367
|
const mine = ++probes;
|
|
1304
1368
|
probing = undefined;
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1369
|
+
try {
|
|
1370
|
+
// The Ollama listing the offers are made from is read before they are, so the first capabilities do not remake them.
|
|
1371
|
+
if (asksOllama(env))
|
|
1372
|
+
await ollamaModels(env);
|
|
1373
|
+
const from = offersInputs(env);
|
|
1374
|
+
if (mine === probes)
|
|
1375
|
+
probing = from;
|
|
1376
|
+
const started = performance.now();
|
|
1377
|
+
const next = await harnessOffers(offersEnvOf(env));
|
|
1378
|
+
log?.(logLine("harness_offers", { why, ms: Math.round(performance.now() - started) }));
|
|
1379
|
+
if (mine !== probes)
|
|
1380
|
+
return;
|
|
1381
|
+
[offers, offersFrom] = [next, from];
|
|
1382
|
+
recompose();
|
|
1383
|
+
}
|
|
1384
|
+
finally {
|
|
1385
|
+
if (mine === probes)
|
|
1386
|
+
probing = undefined;
|
|
1387
|
+
}
|
|
1318
1388
|
};
|
|
1319
1389
|
/** Whether `a` and `b` are the same offers' inputs (offersInputs). */
|
|
1320
1390
|
const sameInputs = (a, b) => a.length === b.length && a.every((value, i) => value === b[i]);
|
|
@@ -1342,15 +1412,29 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1342
1412
|
const next = await needsOf(env);
|
|
1343
1413
|
if (mine === needsAsked)
|
|
1344
1414
|
needs = next;
|
|
1345
|
-
const inputs = offersInputs(env);
|
|
1346
1415
|
// A probe still out from other inputs (a turn-on's, after its turn-off) would put back offers made from them as it
|
|
1347
|
-
// lands: a probe of these overtakes it. Only a change starts one, one per change, so nothing loops.
|
|
1348
|
-
//
|
|
1349
|
-
//
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1416
|
+
// lands: a probe of these overtakes it. Only a change starts one, at most one per change, so nothing loops. While the
|
|
1417
|
+
// probe out has read these inputs, a change starts none: with the offers held made from them too it recomposes at
|
|
1418
|
+
// once; with them behind (a tool key saved while a turn-on's probe is out) it waits for that probe's turn, then
|
|
1419
|
+
// decides again from the inputs read then (a later change's, if one landed meanwhile): the probe landed, and it
|
|
1420
|
+
// recomposes; it failed, and the change probes for itself; a later probe overtook it, and the change goes by that
|
|
1421
|
+
// one. So it never answers another request's failure, and never waits on a dropped probe. With no probe out that has
|
|
1422
|
+
// read its inputs (none out, or the latest still reading the Ollama listing), it recomposes when the offers held are
|
|
1423
|
+
// made from these inputs and probes when not; a probe it starts itself fails it if it fails.
|
|
1424
|
+
for (;;) {
|
|
1425
|
+
const inputs = offersInputs(env);
|
|
1426
|
+
const out = probing !== undefined && sameInputs(probing, inputs);
|
|
1427
|
+
if (out && !offersMadeFrom(inputs)) {
|
|
1428
|
+
log?.(logLine("harness_offers_wait", { why: "key" }));
|
|
1429
|
+
await turn;
|
|
1430
|
+
continue;
|
|
1431
|
+
}
|
|
1432
|
+
if (offersMadeFrom(inputs) && (probing === undefined || out))
|
|
1433
|
+
recompose();
|
|
1434
|
+
else
|
|
1435
|
+
await probe("key");
|
|
1436
|
+
return;
|
|
1437
|
+
}
|
|
1354
1438
|
};
|
|
1355
1439
|
/** The Ollama here, as capabilities read it: its listing asked again behind the answer once stale (ollamaModels), and
|
|
1356
1440
|
* the reading made again, as a key's save does, once a listing differs from the one the offers were made from. So a
|
|
@@ -1380,29 +1464,121 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1380
1464
|
* key's save does. A sign-in this server starts opens a browser on its machine, so only where the console is on
|
|
1381
1465
|
* loopback here; it is kept for this process (claudeSignIns, above), and one still waiting is ended at the stop. */
|
|
1382
1466
|
stops.push(async () => claudeSignIns.close());
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1467
|
+
// The latest hand-over of the login (a turn on or off, or a refresh), until env, needs and the offers are made from
|
|
1468
|
+
// it. It never fails: a failed reading is answered to the request that handed the login over, as a key's save is.
|
|
1469
|
+
let handing = Promise.resolve();
|
|
1470
|
+
// Which the latest hand-over was (`why`: a refresh's or a turn on's or off's), whether its reading is still going
|
|
1471
|
+
// (`out`), and whether it failed (`failed`): the login held is then one env, needs and the offers were not made from,
|
|
1472
|
+
// and the next refresh hands it over again, though it finds it unchanged.
|
|
1473
|
+
let handed = { n: 0, why: "turn", out: false, failed: false };
|
|
1474
|
+
/** The server's login replaced by `login`, then env, needs and the offers made again from it (keysChanged). */
|
|
1475
|
+
const handOver = (login, why) => {
|
|
1476
|
+
claudeLogin = login;
|
|
1477
|
+
const mine = { n: handed.n + 1, why, out: true, failed: false };
|
|
1478
|
+
handed = mine;
|
|
1479
|
+
const made = keysChanged();
|
|
1480
|
+
// Only the latest hand-over's end counts: an earlier one that ends after it says nothing of the login held.
|
|
1481
|
+
const ended = (failed) => void (handed === mine && (handed = { ...mine, out: false, failed }));
|
|
1482
|
+
handing = made.then(() => ended(false), () => ended(true));
|
|
1483
|
+
return made;
|
|
1484
|
+
};
|
|
1485
|
+
const loginDeps = () => {
|
|
1486
|
+
// A turn hands the login over inside its turn (`saved`) and waits for the reading after it (`changed`), outside the
|
|
1487
|
+
// turn, so a sign-in pressed meanwhile never waits on it; a refresh asked meanwhile waits for it (`handing`).
|
|
1488
|
+
let made = Promise.resolve();
|
|
1489
|
+
return {
|
|
1490
|
+
signIns: claudeSignIns,
|
|
1491
|
+
settings: store.settings,
|
|
1492
|
+
data,
|
|
1493
|
+
env: base,
|
|
1494
|
+
pinned: async () => claudeCliIn(installDirOf(data, LOGIN_HARNESS), (await import("@parcha/agentrun-harness-claude")).claudeAgentPlatform()),
|
|
1495
|
+
// `refused` and `turn`: the keys are counted when the refusal is asked (inside the turn-on's turn, the keys' own).
|
|
1496
|
+
...oneOwner,
|
|
1497
|
+
sameMachine: isLoopback(host) && !options.publicUrl,
|
|
1498
|
+
claude: () => import("@parcha/agentrun-harness-claude"),
|
|
1499
|
+
saved: (login) => {
|
|
1500
|
+
made = handOver(login, "turn");
|
|
1501
|
+
},
|
|
1502
|
+
changed: () => made,
|
|
1503
|
+
};
|
|
1504
|
+
};
|
|
1505
|
+
// The refresh asked and not yet started: a request that asks for one meanwhile shares it, since its look at the
|
|
1506
|
+
// folders comes after that request asked. It answers the hand-over it waited for (handed.n).
|
|
1507
|
+
let asked;
|
|
1508
|
+
// How many times a request looks at the login's folders (loginNow) before it gives up on a login that keeps changing.
|
|
1509
|
+
const LOGIN_ROUNDS = 3;
|
|
1510
|
+
/** One look at the login's folders (loginNow), and the wait for the latest hand-over's reading after it: answers which
|
|
1511
|
+
* hand-over that was, once its reading has ended. */
|
|
1512
|
+
const refreshOnce = () => {
|
|
1513
|
+
if (asked)
|
|
1514
|
+
return asked;
|
|
1515
|
+
if (claudeSignIns.busy)
|
|
1516
|
+
log?.(logLine("claude_login_wait", { why: "queue" }));
|
|
1517
|
+
asked = claudeSignIns
|
|
1518
|
+
.serial(async () => {
|
|
1519
|
+
asked = undefined;
|
|
1520
|
+
const login = loginOf(await claudeLoginSetting(store.settings), data, base);
|
|
1521
|
+
if (!isDeepStrictEqual(login, claudeLogin) || handed.failed)
|
|
1522
|
+
return { made: handOver(login, "refresh"), n: handed.n };
|
|
1523
|
+
if (handed.out)
|
|
1524
|
+
log?.(logLine("claude_login_wait", { why: handed.why }));
|
|
1525
|
+
return { made: handing, n: handed.n };
|
|
1526
|
+
})
|
|
1527
|
+
.then(async ({ made, n }) => {
|
|
1528
|
+
await made;
|
|
1529
|
+
return n;
|
|
1530
|
+
});
|
|
1531
|
+
return asked;
|
|
1532
|
+
};
|
|
1533
|
+
/** The login runs here go on, as its folders are now (loginOf, one look at them), handed over where it differs from
|
|
1534
|
+
* the one held. The held one is the start's or the last turn's, and a folder mended with a chmod since (or refused
|
|
1535
|
+
* since) changes it with no turn: a run's check, a save's, a template's plan or apply (prepareApply) and capabilities
|
|
1536
|
+
* ask this first, so they agree with the Settings view, which looks at the folders itself (loginAt). It answers once env,
|
|
1537
|
+
* needs and the offers are made from the login it found, so no request sees a new login with the offers made before
|
|
1538
|
+
* it. The look and the hand-over are one turn on the sign-ins' queue, the one way the setting changes, so a turn on or
|
|
1539
|
+
* off asked meanwhile lands before the look or after the hand-over, never between them. The reading after the
|
|
1540
|
+
* hand-over (keysChanged) goes on outside the queue, as a turn on's or off's does, so a sign-in, a turn on or off and
|
|
1541
|
+
* the server's stop never wait on its probe of the offers; where a turn off lands during it, the turn off's own
|
|
1542
|
+
* reading overtakes it (keysChanged's latest probe stands). Every refresh then waits for the latest hand-over's
|
|
1543
|
+
* reading, its own or another's (a turn's, or another refresh's). A refresh that finds the login as held, where the
|
|
1544
|
+
* latest reading failed, hands it over again, so a failed reading is made again by the next request, never left. The
|
|
1545
|
+
* log says when a refresh waits: for its turn (why=queue), or for another's reading (why=refresh or why=turn).
|
|
1546
|
+
* A reading that ends is not always one the offers were made by: a later hand-over (a turn on or off asked meanwhile)
|
|
1547
|
+
* may have started a probe that dropped its own, or another's reading it waited for failed. So once its wait ends, a
|
|
1548
|
+
* request goes on only where the hand-over it waited for is still the latest and did not fail; else it looks again
|
|
1549
|
+
* (refreshOnce), which waits for the later one or hands a failed one over again. A reading its own hand-over started
|
|
1550
|
+
* that fails is answered to it. A probe with no hand-over (a key's save, a harness key's, a new Ollama listing) can
|
|
1551
|
+
* drop the hand-over's too, and then fail or still be out: the hand-over is still the latest and did not fail, yet the
|
|
1552
|
+
* offers held were made before it. So the request also goes on only where the offers held are made from the inputs
|
|
1553
|
+
* now (offersMadeFrom); where not, it makes them as a key's save does (keysChanged: it waits for the probe out of
|
|
1554
|
+
* these inputs, or probes itself, and a probe of its own that fails is answered to it). It looks at most LOGIN_ROUNDS
|
|
1555
|
+
* times, then is refused (unavailable, retryable), so turns that keep coming never hold it for ever. */
|
|
1556
|
+
const loginNow = async () => {
|
|
1557
|
+
if (loginOff !== undefined)
|
|
1558
|
+
return;
|
|
1559
|
+
for (let round = 1;; round++) {
|
|
1560
|
+
const n = await refreshOnce();
|
|
1561
|
+
const latest = () => handed.n === n && !handed.failed;
|
|
1562
|
+
if (latest() && !offersMadeFrom(offersInputs(env)))
|
|
1563
|
+
await keysChanged();
|
|
1564
|
+
if (latest() && offersMadeFrom(offersInputs(env)))
|
|
1565
|
+
return;
|
|
1566
|
+
if (round >= LOGIN_ROUNDS)
|
|
1567
|
+
throw new ApiError("unavailable", `Claude Code's login on this machine was handed over again, or the offers made from it failed, each time this request waited for them, ${LOGIN_ROUNDS} times: ask again.`);
|
|
1568
|
+
}
|
|
1569
|
+
};
|
|
1398
1570
|
// The boxes a place may name, read once from the computers runs execute on (place-offers.ts): AGENTRUN_BOXES lists
|
|
1399
|
-
// them,
|
|
1400
|
-
// run's claim reads them. Under --faux, `fauxDocker` stands in for Docker's
|
|
1571
|
+
// them, the local box (Docker's) alone when it is not set; the local box by Docker's probe, a vendor's by its
|
|
1572
|
+
// provider's required keys, read as a run's claim reads them. Under --faux, `fauxDocker` stands in for Docker's
|
|
1573
|
+
// answer, and nothing asks Docker.
|
|
1401
1574
|
const fauxDocker = Boolean(options.faux) && options.fauxDocker === true;
|
|
1402
|
-
//
|
|
1403
|
-
// `probeContainer`
|
|
1404
|
-
|
|
1405
|
-
|
|
1575
|
+
// Where the probe takes this server to be is its own marks (place-offers.ts containerOf), faux or not, so a faux server
|
|
1576
|
+
// in AgentRun's image (the deploy walk's) says the image's words; `probeContainer` pins it for a test.
|
|
1577
|
+
// The probe names Docker's architecture too, which says which computerd build a Docker computer binds (below).
|
|
1578
|
+
let dockerArch;
|
|
1579
|
+
const found = await placeOffers(env, { keyOf: keyReader(store, seal.key, env), fauxDocker, dockerArch: (arch) => (dockerArch = arch), ...(options.probeContainer ? { container: options.probeContainer } : {}) });
|
|
1580
|
+
// Docker answers here: the local box (on this machine's container engine) is available.
|
|
1581
|
+
const docker = found.some((offer) => LOCAL_BOXES.includes(offer.id) && offer.available);
|
|
1406
1582
|
// Under --faux, the mountinfo a test gives (fauxMountinfo, or FAUX_MOUNTINFO_ENV in the process's own environment, which
|
|
1407
1583
|
// `env` leaves out: a server under test in a container names its own /proc/self/mountinfo there); with none, a faux
|
|
1408
1584
|
// server is on a host.
|
|
@@ -1416,9 +1592,14 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1416
1592
|
// A run's Docker computer mounts the run's folder, and the computer's daemon, by this server's paths: as they are on
|
|
1417
1593
|
// its Docker's own host, or as its named data volume's subpaths from a container of that Docker's (compose.yaml).
|
|
1418
1594
|
// Any other layout, or a daemon of another machine (DOCKER_HOST, or the current context's endpoint: box-paths.ts
|
|
1419
|
-
// remoteDockerOnce), can't run one, and
|
|
1420
|
-
//
|
|
1421
|
-
|
|
1595
|
+
// remoteDockerOnce), can't run one, and neither can a server with no computerd build for its Docker's architecture as
|
|
1596
|
+
// the probe named it (`npm run build` without `npm run build:daemon`): the computer package's dockerDaemonOf, the file
|
|
1597
|
+
// and words its create() takes. Each says so here (dockerComputerRefusal), where capabilities, the run's start
|
|
1598
|
+
// (dockerAnswers) and a place's box check all read it: no run starts only to fail at its create. A faux server checks
|
|
1599
|
+
// the build only in the directory a test names (fauxDaemonDir); an architecture the probe didn't name is left to create().
|
|
1600
|
+
const daemonDir = options.faux ? options.fauxDaemonDir : undefined;
|
|
1601
|
+
const noDaemon = dockerArch === undefined || (options.faux && daemonDir === undefined) ? undefined : (daemonDir === undefined ? dockerDaemonOf(dockerArch) : dockerDaemonOf(dockerArch, daemonDir)).missing;
|
|
1602
|
+
const dockerUnrunnable = fauxDocker || !docker ? undefined : dockerComputerRefusal(dockerPaths, await remoteDockerOnce(env), noDaemon);
|
|
1422
1603
|
// From a container, a Docker computer keeps this server's allow-list only knowing the Docker host's own addresses: the
|
|
1423
1604
|
// union of the read through the socket and AGENTRUN_DOCKER_HOST_ADDRESSES (docker-host-addresses.ts), the same read the
|
|
1424
1605
|
// runner beside this server takes. Said at the start with what was found; with none, Docker isn't offered, in words.
|
|
@@ -1431,13 +1612,13 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1431
1612
|
const boxesOf = (hostAddresses) => {
|
|
1432
1613
|
if (hostAddresses)
|
|
1433
1614
|
log?.(logLine("docker_host_addresses", { addresses: hostAddresses.addresses.join(",") || "none", ...(hostAddresses.why ? { read: hostAddresses.why } : {}) }));
|
|
1434
|
-
const dockerRefused =
|
|
1615
|
+
const dockerRefused = dockerUnrunnable ?? (hostAddresses && hostAddresses.addresses.length === 0 ? noHostAddresses(hostAddresses.why ?? "the read through Docker's socket found none") : undefined);
|
|
1435
1616
|
// Each box with what it reaches (place-offers.ts withNetworks).
|
|
1436
1617
|
const offers = withNetworks(found, boxAllow, { ...(dockerRefused !== undefined ? { refused: dockerRefused } : {}), ...(hostAddresses ? { hostAddresses: hostAddresses.addresses } : {}), faux: fauxDocker });
|
|
1437
1618
|
log?.(logLine("boxes", boxesLog(offers, enabledBoxes(env))));
|
|
1438
1619
|
return offers;
|
|
1439
1620
|
};
|
|
1440
|
-
const hostAddresses =
|
|
1621
|
+
const hostAddresses = dockerUnrunnable === undefined && "paths" in dockerPaths && boxAllow !== "none" ? unionOf(await hostAddressesOnce(env), dockerHostAddressesOf(env)) : undefined;
|
|
1441
1622
|
let boxOffers = boxesOf(hostAddresses);
|
|
1442
1623
|
const hostRetried = hostAddresses === undefined || hostAddresses.why === undefined
|
|
1443
1624
|
? Promise.resolve()
|
|
@@ -1497,7 +1678,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1497
1678
|
}
|
|
1498
1679
|
else if (box?.available)
|
|
1499
1680
|
return { up: true };
|
|
1500
|
-
|
|
1681
|
+
// A container with no Docker socket at the start had no daemon there, as Settings → Computers words none
|
|
1682
|
+
// (noDockerWords, the vendors that fit each kind): not the start's words, which point at that very page.
|
|
1683
|
+
return { up: false, absent: box?.reason === DOCKER_NO_SOCKET, reason: box?.reason ?? `${provider} is not a box this server has` };
|
|
1501
1684
|
};
|
|
1502
1685
|
let computerRoutes;
|
|
1503
1686
|
// The programs a provider runs on this machine (the phone's adb), looked for on PATH once, at the start, as the boxes
|
|
@@ -1507,19 +1690,20 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1507
1690
|
// A provider's key set where the server starts is one of its secrets, held off process.env (secrets.ts): read by name
|
|
1508
1691
|
// from what the server was started with, as computerReady below reads it.
|
|
1509
1692
|
store, sealKey, tools: kindTools, mode: folderModeOf(store, process.env), env: withSecrets(process.env, "own"),
|
|
1510
|
-
|
|
1693
|
+
// Each with its route (who holds it, on which runner, and why a route was refused), and online while relayed.
|
|
1694
|
+
paired: { rows: () => store.pairedComputers.list(), viewOf: async (row, serves, runsRefused) => pairedView(row, attachHub, serves, runsRefused, await readRoute(store.settings, row.id), attach.relayedTo(row.id) !== undefined) },
|
|
1511
1695
|
runnerApart: options.runnerApart === true,
|
|
1512
|
-
|
|
1513
|
-
// within PRESENCE_STALE_MS on the store's clock (liveRelays), at a host this server dials.
|
|
1514
|
-
relayed: async () => (await liveRelays(store.runners)).some((row) => dialHost(row.host, reach) !== undefined),
|
|
1696
|
+
relayed: relayedNow,
|
|
1515
1697
|
...(options.faux
|
|
1516
1698
|
// --faux's providers stand in for every vendor's, a local one's daemon included.
|
|
1517
1699
|
? { kinds: fauxOf().kinds, factories: fauxOf().factories, keyTable: fauxOf().keyTable }
|
|
1518
1700
|
: {
|
|
1519
1701
|
hostWhy,
|
|
1520
1702
|
kinds: { SETTING_KINDS, PROVIDERS: COMPUTER_PROVIDERS, servingRefusals },
|
|
1521
|
-
// The one place serve builds a provider (workspace/computer-providers.ts), the claim's makers' own
|
|
1522
|
-
|
|
1703
|
+
// The one place serve builds a provider (workspace/computer-providers.ts), the claim's makers' own, each given the
|
|
1704
|
+
// server's values of the host variables its descriptor reads (Docker's PATH, HOME and DOCKER_HOST, for its test and
|
|
1705
|
+
// an agent computer's release).
|
|
1706
|
+
factories: computerProviderFactories(computerProviderMakers({ env: process.env }), (id) => storeLedger(store.computerLedger, id)),
|
|
1523
1707
|
answers: dockerAnswers,
|
|
1524
1708
|
}),
|
|
1525
1709
|
}));
|
|
@@ -1537,11 +1721,11 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1537
1721
|
/** A key as the runner reads it: the secrets this process was started with (withSecrets "own"), else the saved one. */
|
|
1538
1722
|
const runnerKeys = () => keyReader(store, sealKey, own(withSecrets(process.env, "own")));
|
|
1539
1723
|
// A paired computer is one more provider of the registry (workspace/attached-computers.ts), ready while its driver is
|
|
1540
|
-
// attached to this process's hub.
|
|
1724
|
+
// attached: to this process's hub, or relayed to the runner that holds a run of it.
|
|
1541
1725
|
const computerReady = async (setting) => {
|
|
1542
1726
|
const paired = await store.pairedComputers.list();
|
|
1543
1727
|
const row = paired.find((one) => one.id === setting.provider);
|
|
1544
|
-
const offline = row ? pairedRefusal(row, attachHub) : undefined;
|
|
1728
|
+
const offline = row ? pairedRefusal(row, { online: (id) => attachHub.online(id) || attach.relayedTo(id) !== undefined }) : undefined;
|
|
1545
1729
|
if (offline)
|
|
1546
1730
|
return { refused: offline };
|
|
1547
1731
|
return computerReadiness(setting, await modeNow(), withPaired(claimRegistry(), paired), runnerKeys(), dockerAnswers, boxAllow, (provider) => (Object.hasOwn(hostWhy, provider) ? hostWhy[provider] : undefined));
|
|
@@ -1600,7 +1784,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1600
1784
|
};
|
|
1601
1785
|
/** The run read's costs (A8, store-reads/learning.ts runAllInOverStore): `cost.usd` its own spend, the
|
|
1602
1786
|
* job's (its compile turn is learning's), null while unknown; what learning spent for it
|
|
1603
|
-
* (`learning_usd`) and the two (`all_in_usd`)
|
|
1787
|
+
* (`learning_usd`) and the two (`all_in_usd`), with what makes up `learning_usd` (`compile_usd`, `followup_usd`,
|
|
1788
|
+
* `shadow_usd`, `share_usd`): the figures the agent's cost page gives the run (learn/ledger.ts figuresOf, one formula).
|
|
1789
|
+
* A cost known only as a bound keeps its bound, and all-in is unknown.
|
|
1604
1790
|
* `tools_usd`: the part of `usd` its paid tool calls cost (store-view.ts toolsUsdOverStore). */
|
|
1605
1791
|
const allInViewOf = async (runId, view) => {
|
|
1606
1792
|
const cost = (view.cost ?? {});
|
|
@@ -1622,9 +1808,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1622
1808
|
}));
|
|
1623
1809
|
if (!all)
|
|
1624
1810
|
return {};
|
|
1625
|
-
// A bound stays the view's bound. Otherwise usd is the job's (
|
|
1811
|
+
// A bound stays the view's bound. Otherwise usd is the job's (its ledger row's, the same figure the cost series
|
|
1626
1812
|
// gives): known as it answered even when its compile turn's cost is not; the row's while the run is at work.
|
|
1627
|
-
|
|
1813
|
+
const { learning_usd, all_in_usd, compile_usd, followup_usd, shadow_usd, share_usd } = all;
|
|
1814
|
+
return { cost: { ...cost, ...(cost.upper_bound === true ? {} : { usd: all.usd }), tools_usd: await toolsUsdOverStore(store, runId), learning_usd, all_in_usd, compile_usd, followup_usd, shadow_usd, share_usd, ...(degraded ? { degraded: true } : {}) } };
|
|
1628
1815
|
};
|
|
1629
1816
|
// The agents accessor the routes call, over the one store (module A): the agents-store functions, with the run-row reads
|
|
1630
1817
|
// the server makes (store-reads) under `.store`. `.request` is a thin pass-through — the store runs its own transactions,
|
|
@@ -2002,6 +2189,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2002
2189
|
const servedTimelineDeps = { serverSecrets, signIns, sealKey, keyEnv: () => withSavedGateway(own(withSecrets(process.env, "all", storedKeys)), savedGateway), statuses };
|
|
2003
2190
|
const timelines = runTimelines({
|
|
2004
2191
|
context: ctx,
|
|
2192
|
+
...(options.timelinePollMs !== undefined ? { pollMs: options.timelinePollMs } : {}),
|
|
2005
2193
|
// The run's rows as served (run-timeline-served.ts), by its one cut (run-cut.ts, read for each page: a secret rotated
|
|
2006
2194
|
// or saved since is cut at once), the set its view's words, title and error are cut of: each secret this server never
|
|
2007
2195
|
// shows and each browser sign-in pointer the run was handed; its decision rows among them, its error rows in the
|
|
@@ -2012,15 +2200,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2012
2200
|
// A live run's model requests sent and not answered (in-flight.ts), from its booking's records in its journal.
|
|
2013
2201
|
inFlight: async (forStore, runId, context) => modelsInFlight(await runEntries(forStore, runId, context)),
|
|
2014
2202
|
});
|
|
2015
|
-
/** `text
|
|
2016
|
-
*
|
|
2017
|
-
* open here
|
|
2018
|
-
*
|
|
2019
|
-
* cut, and a message written uncut would show those values once the run's end lets its reads go uncut-withheld.
|
|
2020
|
-
* Read inside the turn that writes the message (runWrite), never before it: a message written first in that turn
|
|
2021
|
-
* (one that hands a new key) is in the seal read here, so a message that says that key without handing it is cut of
|
|
2022
|
-
* it too. Both writers of a message read it: a person's (sendMessage) and a trigger's (trigger-targets.ts
|
|
2023
|
-
* message_run, which skips with those words). */
|
|
2203
|
+
/** `text`, a person's words written into run `runId`, cut of `handed` and of what the run holds now, read inside runWrite:
|
|
2204
|
+
* a message (sendMessage, and a trigger's message_run) and an approval's note (answerApproval). A seal that doesn't
|
|
2205
|
+
* open here refuses the words (409 not_continuable, reason withheld, WITHHELD_MESSAGE) and nothing is written: unread
|
|
2206
|
+
* values can't be cut. */
|
|
2024
2207
|
async function cutHeld(runId, text, handed = []) {
|
|
2025
2208
|
const held = launchValuesOf(sealKey, runId, (await store.runs.launch(runId)).sealed);
|
|
2026
2209
|
if (held === "unreadable")
|
|
@@ -2482,8 +2665,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2482
2665
|
});
|
|
2483
2666
|
});
|
|
2484
2667
|
// GET /v2/wrapped's reads of this machine's home (wrapped.ts), each year's on the import worker, so its parsing never holds
|
|
2485
|
-
// up a request; shared and kept as keptReads says. A read the close ended answers `stopped
|
|
2486
|
-
|
|
2668
|
+
// up a request; shared and kept as keptReads says. A read the close ended answers `stopped`, a failure like any other. A
|
|
2669
|
+
// failure is logged here, once per read: the ask that started it may have had its 503 long before.
|
|
2670
|
+
const readWrapped = loggedReads((year) => onWorker("wrapped", undefined, year).then((answer) => ("wrapped" in answer ? answer : Promise.reject(new Error("the server stopped before this machine's session history was read")))), (year, error) => void (closing || process.stderr.write(`agentrun-serve: the read of this machine's session history for ${year} failed: ${error.message}\n`)));
|
|
2487
2671
|
// The count of what setup would import: started once (at start, or by the page's first read), read as it stands. One
|
|
2488
2672
|
// stopped (by close, or by setup) starts again on the next read; one that failed stays failed.
|
|
2489
2673
|
let count;
|
|
@@ -3065,6 +3249,8 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3065
3249
|
await launchNative(native);
|
|
3066
3250
|
return;
|
|
3067
3251
|
}
|
|
3252
|
+
// Claude Code's login as its folders are now, before the checks read env and the offers made with it.
|
|
3253
|
+
await loginNow();
|
|
3068
3254
|
const shape = { ...shapeOf(revision), place, ...(revision.body.place ? {} : { unnamed: true }) };
|
|
3069
3255
|
// An agentic revision's MCP tools are checked as its save pinned them (its pin, never the server's listing now), for
|
|
3070
3256
|
// a server still saved here; a granted tool its pin does not hold is said first, with how to pin it.
|
|
@@ -3119,7 +3305,13 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3119
3305
|
const blockers = await blockersOf(withCarried(envAtPlace(env, shape.place), carried), shape, settings.get(), { capped, boxes: boxOffers, computerReady, shellOf, offers, mcp: revision.kind === "agentic" ? pinnedTools : mcpTools, monid, decisionPrice: price });
|
|
3120
3306
|
if (!blockers.length)
|
|
3121
3307
|
return;
|
|
3122
|
-
|
|
3308
|
+
// An agent refused for its model in a box while its harness runs on the login at the runner, on a model the login
|
|
3309
|
+
// runs: the words say so, and how to run it there (details.login_on_runner, the console's offer to move it). Its
|
|
3310
|
+
// model is the blocker whichever field names it (runnable.ts Blocker.model: an agent that names none is refused on its
|
|
3311
|
+
// harness), and the model it would run on the runner is its own, else the runner's default for its harness
|
|
3312
|
+
// (hostModel: AGENT_MODEL first), so one whose default there is an OpenRouter model is offered no move.
|
|
3313
|
+
const runnerOnly = shape.kind === "agentic" && blockers.some((b) => b.model && b.reason === NOT_SET_UP && !b.unpriced) ? loginOnRunnerOnly(env, shape.harness, shape.model || hostModel(envAtPlace(env, { mode: "runner" }), "default", shape.harness), shape.place) : undefined;
|
|
3314
|
+
const message = [...blockers.map((b) => b.message), ...(runnerOnly ? [runnerOnly] : [])].join(" ");
|
|
3123
3315
|
// Each blocker as a 422 names its issue: its field, reason and message, and the fix when it has one.
|
|
3124
3316
|
const fields = blockers.map(issueOf);
|
|
3125
3317
|
const unbound = blockers.flatMap((b) => (b.tool ? [b.tool] : []));
|
|
@@ -3130,7 +3322,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3130
3322
|
const box = blockers.find((b) => b.box)?.box;
|
|
3131
3323
|
const named = { ...(harness ? { harness } : {}), ...(box ? { box } : {}), ...(notGrantable.length ? { not_grantable: notGrantable } : {}) };
|
|
3132
3324
|
if (revision.kind === "agentic") {
|
|
3133
|
-
const details = { unbound, missing, ...named };
|
|
3325
|
+
const details = { unbound, missing, ...named, ...(runnerOnly ? { login_on_runner: true } : {}) };
|
|
3134
3326
|
// A held run kept from running by its model alone opens (runnable.ts Blocker.model: a CLI harness that lacks only a
|
|
3135
3327
|
// model key here among them): its computer is its owner's to call, and these words are its start's refusal
|
|
3136
3328
|
// (computer-held.ts). Any other blocker refuses it here, as any run.
|
|
@@ -3234,6 +3426,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3234
3426
|
}
|
|
3235
3427
|
if (cliLearningOf(body) || sdkOf(body))
|
|
3236
3428
|
return { warnings: [], stamp: {} };
|
|
3429
|
+
await loginNow();
|
|
3237
3430
|
// A workflow's own issues, as POST /workflows/validate lists them (workflowIssues: the DSL's checks, the durable
|
|
3238
3431
|
// runner's refusal), refuse its save before anything is written, each at its path under definition.workflow. Asked
|
|
3239
3432
|
// with no tools list: its run binds every tool its call nodes name whether `tools` lists it or not (tools.ts
|
|
@@ -3289,7 +3482,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3289
3482
|
const send = await checkFetch("monid");
|
|
3290
3483
|
const before = previous?.kind === "agentic" ? { grants: previous.body.tools ?? [], pin: previous.monidPin } : undefined;
|
|
3291
3484
|
// The key as the server reads it (env: what it was started with, its handed secrets and its saved keys).
|
|
3292
|
-
const pinned = await pinMonid(tools, { key: env[MONID_KEY_ENV]?.trim(), fetch: send ?? (async () => { throw new Error("no fake of monid's API under faux"); }), signal: stopping.signal, ...(before ? { previous: before } : {}) });
|
|
3485
|
+
const pinned = await pinMonid(tools, { key: env[MONID_KEY_ENV]?.trim(), fetch: send ?? (async () => { throw new Error("no fake of monid's API under faux"); }), signal: stopping.signal, shared: monidShared, ...(before ? { previous: before } : {}) });
|
|
3293
3486
|
if (pinned && "refused" in pinned)
|
|
3294
3487
|
throw invalid(pinned.refused.map(({ tool, message }) => ({ field: tools.includes(tool) ? `definition.tools[${tools.indexOf(tool)}]` : "definition.tools", reason: "not_an_option", message })));
|
|
3295
3488
|
return pinned && { monid: pinned.pin, warnings: pinned.warnings.map(({ tool, message }) => ({ field: `definition.tools[${tools.indexOf(tool)}]`, reason: PRICED_BY_USAGE, message })) };
|
|
@@ -3514,6 +3707,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3514
3707
|
const had = onto ? await store.triggers.list(onto.agent.id) : [];
|
|
3515
3708
|
if (onto && !plan && options.templateApplyRead)
|
|
3516
3709
|
await options.templateApplyRead(onto.agent.id);
|
|
3710
|
+
// Claude Code's login as its folders are now, before the choice, the harness and the model are read from env and the
|
|
3711
|
+
// offers made with it.
|
|
3712
|
+
await loginNow();
|
|
3517
3713
|
// A model choice's own keys are needed as the package's are: missing, the apply is refused and nothing is made. Under
|
|
3518
3714
|
// the run-keys setting, a tool key is each run's to carry (run-keys.ts): its agent is made, the warning says so, and a
|
|
3519
3715
|
// run that does not carry it is refused. A model key is still the server's, and so is monid's: the agent's monid tools
|
|
@@ -3865,6 +4061,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3865
4061
|
* tunnel's own port, say); else, with no Host, its own. Links made outside a request (the owner's, the webhooks') are
|
|
3866
4062
|
* at the public URL or the server's own address. */
|
|
3867
4063
|
const linkOrigin = (req) => (options.publicUrl ?? (req.headers.host ? ownOrigin(req) : url)).replace(/\/+$/, "");
|
|
4064
|
+
/** Who hands a run's launch secrets: the API token (every caller on an API-only server; elsewhere a request with an
|
|
4065
|
+
* Authorization header that may not write a secret), or the owner's session. */
|
|
4066
|
+
const handedBy = (req) => (options.apiOnly || (req.headers.authorization !== undefined && !mayHoldSecrets(req)) ? "token" : "owner");
|
|
3868
4067
|
/** A run body's launch secrets taken out of it, before anything else reads the body: `mcp_auth`, the credentials a run's
|
|
3869
4068
|
* caller hands its per_run MCP servers for this run alone (mcp-probe.ts mcpAuthOf), and `model_key`, the run's own model
|
|
3870
4069
|
* key (run-model-key.ts), such as a LiteLLM virtual key minted for it. They never reach the run's saved body, its
|
|
@@ -3875,8 +4074,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3875
4074
|
* the model key must be text, else 422, nothing written. A retry its key already answered replays that answer even
|
|
3876
4075
|
* when the server has since changed or gone, since it does no new work. `keys`, the run's own tool keys (run-keys.ts),
|
|
3877
4076
|
* go the same way: each a tool key name to its value as text, else 422 by name, never with the value; whether the
|
|
3878
|
-
* run's revision reads each is its start's check (prepareLaunch), by name alone.
|
|
3879
|
-
|
|
4077
|
+
* run's revision reads each is its start's check (prepareLaunch), by name alone. `by`: who hands them (handedBy). A
|
|
4078
|
+
* per-run Composio binding is sealed with it, and the token's binding of a Composio user the owner connects here
|
|
4079
|
+
* (composio-owners.ts, read at this check) is 422 at its composio_user_id, nothing written. */
|
|
4080
|
+
function handedLaunchSecrets(body, by) {
|
|
3880
4081
|
if (body.mcp_auth === undefined && body.model_key === undefined && body.keys === undefined)
|
|
3881
4082
|
return { body, handed: async () => ({}) };
|
|
3882
4083
|
const { mcp_auth, model_key, keys: given, ...rest } = body;
|
|
@@ -3884,6 +4085,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3884
4085
|
const issues = [];
|
|
3885
4086
|
const mcp = mcp_auth === undefined ? undefined : mcpAuthOf(mcp_auth, issues);
|
|
3886
4087
|
const auth = {};
|
|
4088
|
+
let owners;
|
|
3887
4089
|
for (const [server, entry] of Object.entries(mcp ?? {})) {
|
|
3888
4090
|
const row = await getMcpServer(store, server);
|
|
3889
4091
|
const field = `mcp_auth.${server}`;
|
|
@@ -3894,10 +4096,18 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3894
4096
|
// A per-run Composio server takes a binding (its key is its own); a per_run server takes headers; no other takes either.
|
|
3895
4097
|
const perRunComposio = composioPerRun(row, await store.settings.get(composioMadeKey(server)));
|
|
3896
4098
|
if ("composio" in entry) {
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
|
|
4099
|
+
// A token's binding never calls as a user the owner calls as here (composio-owners.ts), one refusal per profile: on
|
|
4100
|
+
// API-only, where every caller is the token, McpServersOverStore.tokenBinding (which also checks a named account
|
|
4101
|
+
// is listed under the user); on the full profile, the token's binding here. The owner's session binds any user.
|
|
4102
|
+
const refused = perRunComposio && options.apiOnly ? await mcpServers.tokenBinding(server, row, entry.composio, field, options.composioControl ?? {}, stopping.signal) : undefined;
|
|
4103
|
+
if (!perRunComposio)
|
|
3900
4104
|
issues.push({ field, reason: "not_an_option", message: `The MCP server ${server} is not a per-run Composio server: only one saved through the Composio preset with user_id "${COMPOSIO_PER_RUN}" takes a Composio account from a run.` });
|
|
4105
|
+
else if (refused)
|
|
4106
|
+
issues.push(refused);
|
|
4107
|
+
else if (!options.apiOnly && by === "token" && ownersUser((owners ??= await ownersComposioUsers(store)), entry.composio.user_id))
|
|
4108
|
+
issues.push({ field: `${field}.composio_user_id`, reason: "not_allowed", message: "That composio_user_id is a Composio user the owner connects on this install: a run the API token starts or messages binds its own person's Composio user, never the owner's." });
|
|
4109
|
+
else
|
|
4110
|
+
auth[server] = { composio: { ...entry.composio, by }, origin: new URL(row.url).origin };
|
|
3901
4111
|
}
|
|
3902
4112
|
else if (row.auth === "per_run")
|
|
3903
4113
|
auth[server] = { headers: entry.headers, origin: new URL(row.url).origin };
|
|
@@ -3931,7 +4141,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3931
4141
|
throw misfit(why);
|
|
3932
4142
|
}
|
|
3933
4143
|
else if (serverKeyMissing(env, target))
|
|
3934
|
-
throw modelKeyRequired(false);
|
|
4144
|
+
throw modelKeyRequired(false, env);
|
|
3935
4145
|
const origin = runModelOrigin(env);
|
|
3936
4146
|
return sealRunLaunch(sealKey, runId, { ...(handed.mcp ? { mcp: handed.mcp } : {}), ...(handed.model !== undefined && origin ? { model: { key: handed.model, origin } } : {}), ...(handed.keys ? { keys: handed.keys } : {}) });
|
|
3937
4147
|
};
|
|
@@ -3978,7 +4188,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3978
4188
|
const model = handed.model !== undefined && origin ? { key: handed.model, origin } : held.model;
|
|
3979
4189
|
const keys = handed.keys ?? held.keys;
|
|
3980
4190
|
if (!model && needsKey)
|
|
3981
|
-
throw modelKeyRequired(true);
|
|
4191
|
+
throw modelKeyRequired(true, env);
|
|
3982
4192
|
const unpaid = owed.length && revision ? keysOwed(revision, env, Object.keys(keys ?? {})) : [];
|
|
3983
4193
|
if (unpaid.length)
|
|
3984
4194
|
throw keysOwedRefusal(unpaid);
|
|
@@ -3990,7 +4200,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3990
4200
|
}
|
|
3991
4201
|
async function createRun(req, agentId) {
|
|
3992
4202
|
const entry = await needRunnableAgent(agentId);
|
|
3993
|
-
const { body, handed } = handedLaunchSecrets(await bodyOf(req));
|
|
4203
|
+
const { body, handed } = handedLaunchSecrets(await bodyOf(req), handedBy(req));
|
|
3994
4204
|
// The host's run for a firing the launch hook handed it: the firing's own run, under the firing's key (a second start
|
|
3995
4205
|
// answers that run), started by the trigger's target policy as a firing here starts one (its cap, which the host's may
|
|
3996
4206
|
// lower, its effort when it sets one, its previous result, its trigger, origin and title), with the host's body and
|
|
@@ -4037,7 +4247,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4037
4247
|
* Its first run makes the agent, a version's first run its revision; a later run of the version reuses both
|
|
4038
4248
|
* (runs-over-store startInline). The answer is POST /agents/{agent_id}/runs' own: 202 and the run. */
|
|
4039
4249
|
async function createInlineRun(req) {
|
|
4040
|
-
const { body, handed } = handedLaunchSecrets(await bodyOf(req));
|
|
4250
|
+
const { body, handed } = handedLaunchSecrets(await bodyOf(req), handedBy(req));
|
|
4041
4251
|
if (isObject(body.definition) && body.definition.cli_learning !== undefined)
|
|
4042
4252
|
throw new ApiError("input_invalid", "CLI learning references are registered only through /cli-learning/connections on the source machine.");
|
|
4043
4253
|
if (isObject(body.definition) && body.definition.native !== undefined)
|
|
@@ -4176,7 +4386,48 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4176
4386
|
throw new ApiError("bad_request", "archived is true or false");
|
|
4177
4387
|
return value === "true";
|
|
4178
4388
|
}
|
|
4179
|
-
|
|
4389
|
+
/** GET /runs' `source`, once: a source's name (claude-code, codex, ...) keeps the runs imported from it, `live` the runs not imported. */
|
|
4390
|
+
function sourceParam(url) {
|
|
4391
|
+
const given = url.searchParams.getAll("source");
|
|
4392
|
+
if (given.length === 0)
|
|
4393
|
+
return undefined;
|
|
4394
|
+
if (given.length > 1 || !/^[a-z][a-z0-9-]{0,31}$/.test(given[0]))
|
|
4395
|
+
throw new ApiError("bad_request", "source is one source's name (claude-code, codex, ...), or live; once");
|
|
4396
|
+
return given[0];
|
|
4397
|
+
}
|
|
4398
|
+
/** GET /runs' `from` and `to`, each once: ISO instants with a zone (the server reads no time zone of its own), the window
|
|
4399
|
+
* [from, to) of the runs' starts, in ms. Either one alone; a `from` after `to` is 400, one equal to it an empty window. */
|
|
4400
|
+
function windowParams(url) {
|
|
4401
|
+
const instant = (name) => {
|
|
4402
|
+
const given = url.searchParams.getAll(name);
|
|
4403
|
+
if (given.length === 0)
|
|
4404
|
+
return undefined;
|
|
4405
|
+
// As the analytics' bounds read (stats.ts utcOf): an RFC 3339 date-time that exists, to the ms.
|
|
4406
|
+
const iso = given.length === 1 ? utcOf(given[0]) : undefined;
|
|
4407
|
+
if (iso === undefined)
|
|
4408
|
+
throw new ApiError("bad_request", `${name} is one RFC 3339 date-time with its zone (2026-11-01T00:00:00Z, or an offset such as +01:00), to the millisecond; once`);
|
|
4409
|
+
return Date.parse(iso);
|
|
4410
|
+
};
|
|
4411
|
+
const from = instant("from"), to = instant("to");
|
|
4412
|
+
if (from !== undefined && to !== undefined && from > to)
|
|
4413
|
+
throw new ApiError("bad_request", "from is at or before to: the window [from, to) of the runs' starts");
|
|
4414
|
+
return { ...(from !== undefined ? { startedFrom: from } : {}), ...(to !== undefined ? { startedBefore: to } : {}) };
|
|
4415
|
+
}
|
|
4416
|
+
/** GET /runs' `model`, once: a model as a run's metrics name it, `provider/model`. */
|
|
4417
|
+
function modelParam(url) {
|
|
4418
|
+
const given = url.searchParams.getAll("model");
|
|
4419
|
+
if (given.length === 0)
|
|
4420
|
+
return undefined;
|
|
4421
|
+
if (given.length > 1 || !/^[^\u0000-\u001f\u007f]{1,256}$/.test(given[0]))
|
|
4422
|
+
throw new ApiError("bad_request", "model is one model as a run's metrics name it (provider/model); once");
|
|
4423
|
+
return given[0];
|
|
4424
|
+
}
|
|
4425
|
+
/** GET /runs' own filters: `source`, the window (`from`, `to`) and `model`. */
|
|
4426
|
+
function runsOnly(url) {
|
|
4427
|
+
const source = sourceParam(url), model = modelParam(url);
|
|
4428
|
+
return { ...(source !== undefined ? { source } : {}), ...windowParams(url), ...(model !== undefined ? { model } : {}) };
|
|
4429
|
+
}
|
|
4430
|
+
async function runsPage(url, filter, origin, only = {}) {
|
|
4180
4431
|
const limit = limitOf(url.searchParams.get("limit"));
|
|
4181
4432
|
const offset = cursorOf(url.searchParams.get("cursor"));
|
|
4182
4433
|
const status = url.searchParams.get("status");
|
|
@@ -4193,7 +4444,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4193
4444
|
// ordered and cut to the page in one query, so a list costs the same at ten runs and at thousands, however long their
|
|
4194
4445
|
// journals. An audit's shadow run is no row of the list (learn/audit.ts): it is read by id, and its cost is its served
|
|
4195
4446
|
// run's. A run's archive is its own or its agent's.
|
|
4196
|
-
const where = { ...(filter.agent !== undefined ? { agentId: filter.agent } : {}), ...(filter.revision !== undefined ? { revisionId: filter.revision } : {}), ...(labels ? { labels } : {}), archived };
|
|
4447
|
+
const where = { ...(filter.agent !== undefined ? { agentId: filter.agent } : {}), ...(filter.revision !== undefined ? { revisionId: filter.revision } : {}), ...(labels ? { labels } : {}), ...only, archived };
|
|
4197
4448
|
// A listing is built by the server's lister (run-listing.ts) once per change, so a list finds it current. One that is
|
|
4198
4449
|
// behind (a write landed since, or the lister has not reached it since the store was upgraded) is built here, written
|
|
4199
4450
|
// back, and shown as built: for a status filter, first every run still going whose listing is behind (its row's
|
|
@@ -4686,6 +4937,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4686
4937
|
const found = matching.find((r) => r.method === req.method || (req.method === "HEAD" && r.method === "GET"));
|
|
4687
4938
|
if (!found)
|
|
4688
4939
|
throw new ApiError("method_not_allowed", `${req.method} is not a method of ${path}`, {}, { allow: [...new Set(matching.map((r) => r.method))].join(", ") });
|
|
4940
|
+
// On API-only, a login route never gets here: the API-only gate refused it before routing.
|
|
4689
4941
|
if (CLAUDE_LOGIN_ROUTES.has(found.name) && loginOff)
|
|
4690
4942
|
throw new ApiError("not_found", claudeLoginRouteOff(found.name, loginOff));
|
|
4691
4943
|
if (found.name === "getCapabilities") {
|
|
@@ -4695,6 +4947,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4695
4947
|
const runnerShell = shellTools(await shellOf({ kind: "none" }));
|
|
4696
4948
|
await planNow();
|
|
4697
4949
|
await ollamaNow();
|
|
4950
|
+
await loginNow();
|
|
4698
4951
|
const answer = forCaller(runnerShell.size ? compose(runnerShell) : caps, byOwnerSession(req));
|
|
4699
4952
|
// features.triggers.public_url: whether Composio (or any sender) has a public address to reach, never the address.
|
|
4700
4953
|
// runner_refused: why no runner here can take a run, in their words, while every runner there refused to claim
|
|
@@ -4705,11 +4958,15 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4705
4958
|
const state = await store.schemaState?.().catch(() => undefined);
|
|
4706
4959
|
const storeSchema = state ? { store_schema: { version: state.version, runner_floor: state.runnerFloor, known: state.known } } : {};
|
|
4707
4960
|
// features.harness_keys.kept names which harness ids still have keys stored: the owner's session or a holder of
|
|
4708
|
-
// the server's token reads it; a caller with neither (this route answers before any bearer check) reads none.
|
|
4961
|
+
// the server's token reads it; a caller with neither (this route answers before any bearer check) reads none. A
|
|
4962
|
+
// bearer this server does not take still gets the answer, and the auth_failed line any other route writes for it.
|
|
4709
4963
|
const keptShown = byOwnerSession(req) || bearer(req.headers.authorization, req);
|
|
4964
|
+
if (!keptShown && req.headers.authorization !== undefined)
|
|
4965
|
+
authFailed(`/v2${path}`, "wrong_token");
|
|
4710
4966
|
const keptCap = { ...answer.features.harness_keys, kept: keptShown ? answer.features.harness_keys.kept : [] };
|
|
4967
|
+
// tools[].held: the server's keyless holds on each web tool now (web-run.ts withHeld), never cached.
|
|
4711
4968
|
// features.api_keys.routes: false on an API-only server, which serves none of the keys' routes and reads no key.
|
|
4712
|
-
return send(res, 200, { ...answer, ...storeSchema, runner_refused: runnerRefused, features: { ...answer.features, harness_keys: keptCap, computers: await computerCapabilities(computersOf()), triggers: { ...answer.features.triggers, public_url: Boolean(options.publicUrl) }, claude_login:
|
|
4969
|
+
return send(res, 200, { ...answer, tools: withHeld(answer.tools), ...storeSchema, runner_refused: runnerRefused, features: { ...answer.features, harness_keys: keptCap, computers: await computerCapabilities(computersOf()), triggers: { ...answer.features.triggers, public_url: Boolean(options.publicUrl) }, claude_login: loginServed, api_keys: { ...answer.features.api_keys, routes: !options.apiOnly } } });
|
|
4713
4970
|
}
|
|
4714
4971
|
if (found.name === "getOpenapi")
|
|
4715
4972
|
return send(res, 200, servedOpenapi(openapi, ownerCookieName(req)));
|
|
@@ -5251,6 +5508,17 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5251
5508
|
const page = all.slice(offset, offset + limit).map((row) => revisionView(entry.agent, row));
|
|
5252
5509
|
return send(res, 200, { revisions: page, next_cursor: nextCursor(offset + limit, all.length) });
|
|
5253
5510
|
}
|
|
5511
|
+
case "getRevisionSkills": {
|
|
5512
|
+
// Only the named revision is needed: the full agent view and numbered history load every skill bundle.
|
|
5513
|
+
if (!ID.test(id) || !await store.agents.get(id))
|
|
5514
|
+
throw new ApiError("not_found", `no agent ${id}`);
|
|
5515
|
+
const selected = await store.agents.revision(decodeURIComponent(second));
|
|
5516
|
+
if (!selected || selected.agentId !== id)
|
|
5517
|
+
throw new ApiError("not_found", "no such revision for this agent");
|
|
5518
|
+
// The complete immutable file map is needed before replacing skills in a definition edit. Native discovery
|
|
5519
|
+
// metadata is separate: this read never follows a connection to its source machine or filesystem.
|
|
5520
|
+
return send(res, 200, { revision: selected.id, skills: selected.skills ?? {} });
|
|
5521
|
+
}
|
|
5254
5522
|
case "getAgentPackage": {
|
|
5255
5523
|
const entry = await needAgent(id);
|
|
5256
5524
|
const { agent, revision } = entry;
|
|
@@ -5390,7 +5658,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5390
5658
|
case "listAllRuns": {
|
|
5391
5659
|
const agent = url.searchParams.get("agent") ?? undefined;
|
|
5392
5660
|
const revision = url.searchParams.get("revision") ?? undefined;
|
|
5393
|
-
return send(res, 200, await runsPage(url, { ...(agent ? { agent } : {}), ...(revision ? { revision } : {}) }, linkOrigin(req)));
|
|
5661
|
+
return send(res, 200, await runsPage(url, { ...(agent ? { agent } : {}), ...(revision ? { revision } : {}) }, linkOrigin(req), runsOnly(url)));
|
|
5394
5662
|
}
|
|
5395
5663
|
case "getRun": {
|
|
5396
5664
|
const run = await runRead(id, linkOrigin(req));
|
|
@@ -5407,7 +5675,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5407
5675
|
const run = await needRun(id);
|
|
5408
5676
|
if (run.kind === "workflow")
|
|
5409
5677
|
throw unsupported("messages.steer_workflow_runs", "A workflow run takes no messages here: its workflow runs to its end, or a cancel ends it.");
|
|
5410
|
-
const { body, handed } = handedLaunchSecrets(await bodyOf(req));
|
|
5678
|
+
const { body, handed } = handedLaunchSecrets(await bodyOf(req), handedBy(req));
|
|
5411
5679
|
const answer = await idempotent(req, `/runs/${id}/messages`, body, async () => {
|
|
5412
5680
|
const secrets = await handed();
|
|
5413
5681
|
const seal = await messageSeal(run, secrets);
|
|
@@ -5490,7 +5758,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5490
5758
|
issues.push({ field: "note", reason: "wrong_type", message: "note is a string of at most 2000 characters" });
|
|
5491
5759
|
if (issues.length)
|
|
5492
5760
|
throw invalid(issues);
|
|
5493
|
-
|
|
5761
|
+
// A note is cut as a message is, in the turn that writes it (cutHeld): refused when the seal does not open here.
|
|
5762
|
+
const note = typeof body.note === "string" && body.note.trim() ? body.note.trim() : undefined;
|
|
5763
|
+
await runWrite(run.agentId, run.id, async () => approve(store, run, decodeURIComponent(second), body.decision, note === undefined ? undefined : await cutHeld(run.id, note), body.confirm_destructive === true));
|
|
5494
5764
|
res.writeHead(204, { "cache-control": "no-store", "x-content-type-options": "nosniff" });
|
|
5495
5765
|
return void res.end();
|
|
5496
5766
|
}
|
|
@@ -5506,6 +5776,8 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5506
5776
|
throw invalid([{ field: "correct", reason: body.correct === undefined ? "missing" : "wrong_type", message: "correct is true or false: whether the run's answer was right" }]);
|
|
5507
5777
|
if (body.expected !== undefined && !isObject(body.expected))
|
|
5508
5778
|
throw invalid([{ field: "expected", reason: "wrong_type", message: "expected is an object: the fields a right answer's JSON holds" }]);
|
|
5779
|
+
if (holdsReservedKey(body.expected))
|
|
5780
|
+
throw invalid([{ field: "expected", reason: "not_allowed", message: `expected holds no key named ${RESERVED_SEGMENT}, at any depth` }]);
|
|
5509
5781
|
if (body.source !== undefined && !GRADE_SOURCES.includes(body.source))
|
|
5510
5782
|
throw invalid([{ field: "source", reason: "not_an_option", message: `source is one of ${GRADE_SOURCES.join(", ")}` }]);
|
|
5511
5783
|
if (body.label !== undefined && (typeof body.label !== "string" || body.label.length > LABEL_MAX))
|
|
@@ -5536,7 +5808,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5536
5808
|
// A grade of a run its learned workflow answered alone is an audit row too (runner/audit.ts gradeRow): the hold rule
|
|
5537
5809
|
// reads it with the shadows'. A row not written now is logged, never the grade refused.
|
|
5538
5810
|
const said = (line) => log?.(logLine("audit", { run: row.id, said: line }));
|
|
5539
|
-
await gradeRow({ store, agentId: row.agentId, revisionId: row.revisionId, context: ctx, folder: () => learningFolderOf(data, row.agentId), shown: () => learningShown(row.agentId), log: said }, row, grade.correct).catch((error) => said(`the grade wrote no audit row (${error?.message ?? error})`));
|
|
5811
|
+
await gradeRow({ store, agentId: row.agentId, revisionId: row.revisionId, context: ctx, folder: () => learningFolderOf(data, row.agentId), shown: () => learningShown(row.agentId), log: said }, row, grade.correct, grade.expected).catch((error) => said(`the grade wrote no audit row (${error?.message ?? error})`));
|
|
5540
5812
|
return graded;
|
|
5541
5813
|
});
|
|
5542
5814
|
// Its workflow's name cut as GET /runs/{id}/learning cuts it (learningShown); withheld whole when that cut can't be
|
|
@@ -5579,7 +5851,14 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5579
5851
|
},
|
|
5580
5852
|
computer: () => (viewed ? { kind: viewed } : computerOf(kept, env, family, own)),
|
|
5581
5853
|
session: (kind) => sessionIn(kind, entries, run.terminal || (parked && kind !== "browser")),
|
|
5582
|
-
|
|
5854
|
+
// The keep's `until` is on the store's clock (computer-kept.ts Kept.until), so its lapse is judged on it; a
|
|
5855
|
+
// clock or a row that can't be read says nothing.
|
|
5856
|
+
lapsed: async (kind) => {
|
|
5857
|
+
if (!parked)
|
|
5858
|
+
return undefined;
|
|
5859
|
+
const at = await store.sealedKeys.clock().catch(() => undefined);
|
|
5860
|
+
return at === undefined ? undefined : lapsedOf(kind, await readKept(store.settings, run.id).catch(() => undefined), at);
|
|
5861
|
+
},
|
|
5583
5862
|
hold: () => hold,
|
|
5584
5863
|
// A going run's browser let go while it waited for its person: the Screen tab says so, with when. One settings
|
|
5585
5864
|
// row (browser-wait-ended.ts), never the run's journal: this is read on every Screen poll.
|
|
@@ -5776,6 +6055,26 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5776
6055
|
// or where its figure is not its booking's.
|
|
5777
6056
|
// Names through the run's cut, and a withheld run refused (403), as its trace is.
|
|
5778
6057
|
return send(res, 200, await servedRunUsage({ serverSecrets, signIns, sealKey }, store, id));
|
|
6058
|
+
case "getRunExport": {
|
|
6059
|
+
await needRun(id);
|
|
6060
|
+
const restore = restoreIdsOf(url);
|
|
6061
|
+
const viewDeps = viewDepsFor(ownOriginOf());
|
|
6062
|
+
let bundle;
|
|
6063
|
+
try {
|
|
6064
|
+
bundle = await runExport(id, exportReadsOverStore(store, id, { view: viewDeps, timeline: servedTimelineDeps, runReads: runReadsDeps, cut: { serverSecrets, signIns, sealKey } }, ctx), { restore, version: VERSION, ...(options.shareScrub ? { scrub: options.shareScrub } : {}) });
|
|
6065
|
+
}
|
|
6066
|
+
catch (error) {
|
|
6067
|
+
if (error instanceof ApiError)
|
|
6068
|
+
throw error;
|
|
6069
|
+
// Fails closed: a scrub that failed, a read-back that found a value, or anything else that threw while the
|
|
6070
|
+
// bundle was made. Not one byte of it: a 500 with an empty body. The log names why, never a word of the run.
|
|
6071
|
+
log?.(logLine("export_failed", { run: id, why: error instanceof ExportFailed ? error.message : error?.name ?? "error" }));
|
|
6072
|
+
res.writeHead(500, { "cache-control": "no-store", "content-length": "0" });
|
|
6073
|
+
return void res.end();
|
|
6074
|
+
}
|
|
6075
|
+
res.writeHead(200, { "content-type": "application/json", "cache-control": "no-store", "x-content-type-options": "nosniff", "content-length": String(Buffer.byteLength(bundle.body)) });
|
|
6076
|
+
return void res.end(bundle.body);
|
|
6077
|
+
}
|
|
5779
6078
|
case "getRunTrace":
|
|
5780
6079
|
await needRun(id);
|
|
5781
6080
|
// The run's spans over its served Timeline rows and its journal (run-trace.ts): cut by the run's one cut, as its
|
|
@@ -5841,10 +6140,11 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5841
6140
|
return send(res, 200, await capacityOverStore(store.runners, capacityWindowOf(url)));
|
|
5842
6141
|
case "getWrapped": {
|
|
5843
6142
|
// The session files of the machine this server runs on, read for whoever holds a token: only one owner's server on
|
|
5844
|
-
// their own machine answers (whyNotOwnersServer: loopback, no public URL, an owner, one API token
|
|
5845
|
-
//
|
|
6143
|
+
// their own machine answers (whyNotOwnersServer: loopback, no public URL, an owner, one API token and no live API key
|
|
6144
|
+
// made in the console, its own SQLite store). Keys are counted at each ask: they are made and revoked while it runs.
|
|
6145
|
+
// Dormant keys (API-only, --harness-sign-in) open nothing, so they are not callers here. A name an operator allowed (--allow-host) passes the server's Host check for its other routes, but a page
|
|
5846
6146
|
// that rebound one to this address must not read the machine's files: here the Host is a loopback name or address.
|
|
5847
|
-
const notOwn = whyNotOwnersServer(options, data);
|
|
6147
|
+
const notOwn = whyNotOwnersServer(options, data, options.apiOnly === true || options.harnessSignIn === true ? 0 : apiKeys.count);
|
|
5848
6148
|
if (!isLoopbackName(hostName(req.headers.host)))
|
|
5849
6149
|
notOwn.push("was reached at a name that is not this machine's own");
|
|
5850
6150
|
if (notOwn.length)
|
|
@@ -5856,7 +6156,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5856
6156
|
if (year > new Date().getFullYear())
|
|
5857
6157
|
throw new ApiError("bad_request", "year is this year or an earlier one");
|
|
5858
6158
|
// A long home is read on, shared, past the wait: the answer says when to ask again rather than hold the request.
|
|
5859
|
-
|
|
6159
|
+
// A failed read is kept for its minute (keptReads): each ask in it is this 500, the reason in the server's log.
|
|
6160
|
+
const read = await within(readWrapped(year), options.wrappedWaitMs ?? WRAPPED_WAIT_MS).catch(() => {
|
|
6161
|
+
throw new ApiError("internal", `This machine's session history for ${year} could not be read: the server's log says why. Ask again in a minute to read it again.`);
|
|
6162
|
+
});
|
|
5860
6163
|
if (!read)
|
|
5861
6164
|
throw new ApiError("unavailable", `This machine's session history for ${year} is still being read: ask again in a few seconds.`, { retry_after_ms: 5_000 });
|
|
5862
6165
|
const analytics = await analyticsOverStore(store, { from: new Date(year, 0, 1).toISOString(), to: new Date(year + 1, 0, 1).toISOString() });
|
|
@@ -6005,7 +6308,8 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6005
6308
|
case "getMcpServer":
|
|
6006
6309
|
return send(res, 200, await mcpServers.get(id));
|
|
6007
6310
|
case "previewMcpServer":
|
|
6008
|
-
|
|
6311
|
+
// The API token's preview, as the gate reads a token's save: a server it saved is previewed at its shown address.
|
|
6312
|
+
return send(res, 200, await mcpServers.preview(await bodyOf(req), stopping.signal, req.headers.authorization !== undefined && !mayHoldSecrets(req)));
|
|
6009
6313
|
case "saveMcpServer": {
|
|
6010
6314
|
const body = await bodyOf(req);
|
|
6011
6315
|
const preset = await mcpServers.composioPreset(id);
|
|
@@ -6040,10 +6344,18 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6040
6344
|
return send(res, 200, over.note ? { ...saved, composio: over.note } : saved);
|
|
6041
6345
|
}
|
|
6042
6346
|
// Composio makes the managed MCP server; what is kept is the ordinary MCP save, so the key is a sealed header.
|
|
6043
|
-
|
|
6044
|
-
|
|
6045
|
-
case "
|
|
6046
|
-
|
|
6347
|
+
// A listing stops at Composio when the console stops asking (Cancel, a key edit: the response closes), or the server
|
|
6348
|
+
// stops.
|
|
6349
|
+
case "listComposioTools": {
|
|
6350
|
+
const done = new AbortController();
|
|
6351
|
+
res.once("close", () => done.abort());
|
|
6352
|
+
return send(res, 200, await composioTools(await bodyOf(req), options.composioControl ?? {}, AbortSignal.any([stopping.signal, done.signal])), { "cache-control": "no-store" });
|
|
6353
|
+
}
|
|
6354
|
+
case "listComposioToolkits": {
|
|
6355
|
+
const done = new AbortController();
|
|
6356
|
+
res.once("close", () => done.abort());
|
|
6357
|
+
return send(res, 200, await composioToolkits(await bodyOf(req), options.composioControl ?? {}, AbortSignal.any([stopping.signal, done.signal])), { "cache-control": "no-store" });
|
|
6358
|
+
}
|
|
6047
6359
|
case "saveComposioServer": {
|
|
6048
6360
|
// The name is checked before Composio is called: a refused name leaves nothing made there.
|
|
6049
6361
|
mcpNameOf(id);
|
|
@@ -6055,11 +6367,13 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6055
6367
|
// server, in the delete's words, checked in its project's turn before the row is written. An API-only server's token
|
|
6056
6368
|
// saves one that names its key by api_key_env (the secret-write gate), and over a saved server only one it saved
|
|
6057
6369
|
// (mcp-secret-writes.ts tokenWriteOverRefused), landing only while the row still has the credential the gate read
|
|
6058
|
-
// (secretSeen) and the token's mark. The
|
|
6370
|
+
// (secretSeen) and the token's mark. The token's save stands on no auth config or ACTIVE account that no server it
|
|
6371
|
+
// saved holds (tokenStandsOn, tokenAccountOn), as a Composio user in its own namespace (composioTokenUser). The body
|
|
6372
|
+
// names no address or headers (composioSave refuses them).
|
|
6059
6373
|
const answer = await inComposioTurn(async () => {
|
|
6060
6374
|
const over = {};
|
|
6061
6375
|
const guard = { turn: (work) => composioTriggers.inTurnOf(id, work), inUse: () => composioTriggers.inUse(id, SAVE_AFTER_TRIGGERS) };
|
|
6062
|
-
const saved = await composioSave(body, options.composioControl ?? {}, (mcp, made, stands) => mcpServers.save(id, mcp, stopping.signal, secretSeen, made, stands, (left) => (over.dropped = left), guard, byToken), id, stopping.signal, async () => (await mcpServers.get(id)).url);
|
|
6376
|
+
const saved = await composioSave(body, options.composioControl ?? {}, (mcp, made, stands) => mcpServers.save(id, mcp, stopping.signal, secretSeen, made, stands, (left) => (over.dropped = left), guard, byToken), id, stopping.signal, async () => (await mcpServers.get(id)).url, byToken ? (config) => mcpServers.tokenStandsOn(config) : undefined, byToken ? (user, account) => mcpServers.tokenAccountOn(user, account) : undefined, byToken ? composioTokenUser : undefined);
|
|
6063
6377
|
await refreshMcpMeta();
|
|
6064
6378
|
return over.dropped ? { ...saved, composio: await composioLeft(id, over.dropped) } : saved;
|
|
6065
6379
|
});
|
|
@@ -6074,7 +6388,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6074
6388
|
case "deleteComposioSubscription":
|
|
6075
6389
|
return send(res, 200, await composioTriggers.forget(id), { "cache-control": "no-store" });
|
|
6076
6390
|
case "refreshMcpServer": {
|
|
6077
|
-
const refreshed = await mcpServers.refresh(id, stopping.signal
|
|
6391
|
+
const refreshed = await mcpServers.refresh(id, stopping.signal);
|
|
6078
6392
|
await refreshMcpMeta();
|
|
6079
6393
|
return send(res, 200, refreshed);
|
|
6080
6394
|
}
|
|
@@ -6799,7 +7113,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6799
7113
|
names = loopbackNames(host, options.allowHosts, options.publicUrl);
|
|
6800
7114
|
// An address of every interface is reached on this machine at its loopback one.
|
|
6801
7115
|
const url = urlOf(server, host);
|
|
6802
|
-
owner?.attach(options.publicUrl ?? url, options.publicUrl ? [] : elsewhereOf(host, server.address().port));
|
|
7116
|
+
owner?.attach(options.publicUrl ?? url, options.publicUrl ? [] : elsewhereOf(host, server.address().port, { container: () => containerSigns() !== undefined }));
|
|
6803
7117
|
webhooks.attach(options.publicUrl ?? url);
|
|
6804
7118
|
slack.attach(options.publicUrl ?? url);
|
|
6805
7119
|
// A local install is the one server an MCP server's URL may be on loopback for (anywhere else, loopback is this machine's
|
|
@@ -7125,8 +7439,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
7125
7439
|
closing = true;
|
|
7126
7440
|
stopping.abort();
|
|
7127
7441
|
clearInterval(localSourceTimer);
|
|
7128
|
-
// Cancel a pending ChatGPT callback without signing out or changing the saved credential
|
|
7129
|
-
|
|
7442
|
+
// Cancel a pending ChatGPT callback without signing out or changing the saved credential. One past its code's
|
|
7443
|
+
// exchange is waited for a short while (planClosed), so its row lands before the store closes.
|
|
7444
|
+
const planStopped = planClosed(plan, options.planCloseMs ?? PLAN_CLOSE_MS);
|
|
7130
7445
|
// The CLI's sign-in still waiting for its browser ends with the server, which forgets it: left running, its CLI would
|
|
7131
7446
|
// keep the browser's callback port from the next server's sign-in. Awaited until its process is gone.
|
|
7132
7447
|
const signInStopped = claudeSignIns.close();
|
|
@@ -7151,6 +7466,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
7151
7466
|
await schemaSealed;
|
|
7152
7467
|
await installStopped;
|
|
7153
7468
|
await signInStopped;
|
|
7469
|
+
await planStopped;
|
|
7154
7470
|
await observationStopped;
|
|
7155
7471
|
await localSourceSweep;
|
|
7156
7472
|
// The ends' follower stops before the webhooks it feeds and the store it reads.
|
|
@@ -7160,6 +7476,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
7160
7476
|
await slack.close();
|
|
7161
7477
|
// An upgraded socket is no connection closeAllConnections ends, and server.close waits for it.
|
|
7162
7478
|
viewers.close();
|
|
7479
|
+
clearInterval(routeTick);
|
|
7163
7480
|
await attach.close();
|
|
7164
7481
|
await new Promise((done) => (server.close(done), server.closeAllConnections()));
|
|
7165
7482
|
// No request is left to use a key: its last-use writes end before the store they write to closes.
|
|
@@ -7199,6 +7516,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
7199
7516
|
...(consoleSessions ? { launchCode: consoleSessions.code } : {}),
|
|
7200
7517
|
boxesLine: boxesLine(boxOffers, enabledBoxes(env), boxAllow, boxesByDefault(env)),
|
|
7201
7518
|
attachHub,
|
|
7519
|
+
beside,
|
|
7202
7520
|
dial: { ...(options.publicUrl ? { url: options.publicUrl.replace(/\/+$/, "") } : {}), tokens: attach.machineTokens, hub: attachHub },
|
|
7203
7521
|
localInstall,
|
|
7204
7522
|
ollamaHost,
|