@parcha/agentrun-serve 0.1.0-beta.60 → 0.1.0-beta.62
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 +124 -0
- package/README.md +139 -22
- package/dist/acp-package.d.ts +4 -0
- package/dist/api-only.d.ts +23 -1
- package/dist/api-only.js +43 -4
- package/dist/archil-settings.d.ts +9 -0
- package/dist/archil-settings.js +8 -1
- package/dist/bash-read-only.d.ts +3 -0
- package/dist/bash-read-only.js +6 -3
- package/dist/browser-person.d.ts +1 -1
- package/dist/browser-person.js +1 -1
- package/dist/calendar/tools.js +1 -1
- package/dist/chatgpt-plan.d.ts +26 -8
- package/dist/chatgpt-plan.js +89 -21
- package/dist/claude-login.d.ts +12 -5
- package/dist/claude-login.js +28 -3
- package/dist/cli.js +61 -18
- package/dist/composio-triggers.d.ts +9 -3
- package/dist/computers.d.ts +3 -0
- package/dist/computers.js +2 -1
- package/dist/console/assets/{backend-QnwGVBeU.js → backend-DEgVn5lC.js} +1 -1
- package/dist/console/assets/index-CG5tELph.js +639 -0
- package/dist/console/assets/share-CIeFK2Oe.js +6 -0
- package/dist/console/assets/{styles-CcceGcu2.js → styles-BGZxYkky.js} +2 -2
- package/dist/console/assets/{styles-fjQBFfMv.css → styles-D0SufbzK.css} +1 -1
- package/dist/console/index.html +3 -3
- package/dist/console/share.html +3 -3
- package/dist/cut-pool.d.ts +14 -0
- package/dist/cut-pool.js +98 -0
- package/dist/cut-worker.d.ts +14 -0
- package/dist/cut-worker.js +16 -0
- package/dist/decisions.d.ts +4 -0
- package/dist/decisions.js +9 -1
- package/dist/env-switch.d.ts +3 -0
- package/dist/env-switch.js +3 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- package/dist/harness-check.js +2 -1
- package/dist/harness-recipe.d.ts +13 -2
- package/dist/harness-recipe.js +30 -7
- package/dist/harness-sign-in.js +2 -1
- package/dist/harness-table.d.ts +12 -3
- package/dist/harness-table.js +13 -8
- package/dist/import.d.ts +8 -1
- package/dist/import.js +36 -5
- package/dist/key-check.js +22 -8
- package/dist/key-refusal.js +6 -4
- package/dist/learn/secrets.d.ts +2 -1
- package/dist/learn/secrets.js +2 -2
- package/dist/learned-nodes.d.ts +37 -0
- package/dist/learned-nodes.js +24 -0
- package/dist/local-model.d.ts +144 -0
- package/dist/local-model.js +214 -0
- package/dist/mcp-gateway.d.ts +24 -0
- package/dist/mcp-gateway.js +97 -8
- package/dist/mcp-probe.d.ts +7 -0
- package/dist/mcp-probe.js +7 -0
- package/dist/mcp-servers-store.d.ts +7 -10
- package/dist/mcp-servers-store.js +15 -9
- package/dist/native/cli.js +5 -1
- package/dist/ollama-provider.d.ts +42 -0
- package/dist/ollama-provider.js +118 -2
- package/dist/openapi.js +85 -16
- package/dist/otel/tracer.d.ts +6 -3
- package/dist/otel/tracer.js +24 -6
- package/dist/page.d.ts +7 -0
- package/dist/page.js +17 -4
- package/dist/place.d.ts +28 -11
- package/dist/place.js +43 -14
- package/dist/print.d.ts +3 -2
- package/dist/print.js +8 -6
- package/dist/redact/match.d.ts +17 -4
- package/dist/redact/match.js +57 -15
- package/dist/run-export.js +4 -2
- package/dist/run-launch.js +16 -3
- package/dist/run-model-key.d.ts +2 -1
- package/dist/run-model-key.js +2 -1
- package/dist/run-reads-over-store.d.ts +7 -0
- package/dist/run-reads-over-store.js +32 -4
- package/dist/run-usage.js +3 -2
- package/dist/runnable.d.ts +6 -3
- package/dist/runnable.js +16 -6
- package/dist/runner/adapter-loop.d.ts +8 -1
- package/dist/runner/adapter-loop.js +148 -29
- package/dist/runner/adapter-run-spec.d.ts +9 -6
- package/dist/runner/adapter-run-spec.js +38 -52
- package/dist/runner/adapters/index.d.ts +4 -0
- package/dist/runner/adapters/index.js +2 -1
- package/dist/runner/adapters/pi.d.ts +3 -2
- package/dist/runner/adapters/pi.js +3 -1
- package/dist/runner/audit.d.ts +1 -1
- package/dist/runner/claim-secrets.d.ts +3 -1
- package/dist/runner/claim-secrets.js +18 -7
- package/dist/runner/cli-run-spec.js +24 -17
- package/dist/runner/compare-end.d.ts +1 -1
- package/dist/runner/dispatch.js +4 -2
- package/dist/runner/harness-loops.d.ts +14 -0
- package/dist/runner/harness-loops.js +51 -5
- package/dist/runner/held.d.ts +4 -1
- package/dist/runner/live-ticker.js +5 -4
- package/dist/runner/loop-contract.d.ts +4 -1
- package/dist/runner/mcp-claim.js +3 -2
- package/dist/runner/mcp-run.d.ts +24 -4
- package/dist/runner/mcp-run.js +47 -2
- package/dist/runner/meta-tools.js +4 -4
- package/dist/runner/metrics.d.ts +6 -0
- package/dist/runner/metrics.js +12 -4
- package/dist/runner/monid-run.js +3 -1
- package/dist/runner/native-loop.js +3 -3
- package/dist/runner/redact.d.ts +3 -0
- package/dist/runner/redact.js +7 -0
- package/dist/runner/run-child-host.d.ts +10 -6
- package/dist/runner/run-child-host.js +44 -29
- package/dist/runner/run-child.js +1 -0
- package/dist/runner/runner.js +2 -0
- package/dist/runner/sdk-loop.js +5 -3
- package/dist/runner/workflow-calls.d.ts +5 -1
- package/dist/runner/workflow-calls.js +65 -19
- package/dist/runner/workflow-loop.d.ts +1 -1
- package/dist/runner/workflow-loop.js +3 -1
- package/dist/runner/workflow-spec.d.ts +4 -0
- package/dist/runner/workflow-spec.js +18 -13
- package/dist/runs-over-store.d.ts +2 -2
- package/dist/runs-over-store.js +1 -1
- package/dist/secret-cut.js +7 -4
- package/dist/secret-rules.d.ts +0 -1
- package/dist/secret-rules.js +122 -88
- package/dist/server.d.ts +17 -1
- package/dist/server.js +208 -69
- package/dist/share-host.d.ts +111 -0
- package/dist/share-host.js +666 -0
- package/dist/slack.js +2 -1
- package/dist/store/postgres/migrate.js +3 -1
- package/dist/store-reads/analytics.d.ts +15 -0
- package/dist/store-reads/analytics.js +17 -0
- package/dist/store-reads/learning.d.ts +5 -4
- package/dist/store-reads/learning.js +7 -4
- package/dist/suggestions.js +32 -3
- package/dist/templates.d.ts +3 -1
- package/dist/templates.js +7 -3
- package/dist/tool-gate.d.ts +25 -9
- package/dist/tool-gate.js +58 -19
- package/dist/tool-plane.d.ts +24 -1
- package/dist/tool-plane.js +75 -3
- package/dist/tools.d.ts +12 -2
- package/dist/tools.js +42 -7
- package/dist/trigger-composio.js +1 -1
- package/dist/trigger-launch-hook.d.ts +2 -2
- package/dist/trigger-launch-hook.js +1 -1
- package/dist/triggers.d.ts +7 -4
- package/dist/triggers.js +4 -4
- package/dist/webhooks.d.ts +3 -0
- package/dist/webhooks.js +5 -0
- package/dist/workspace/archil-claim.d.ts +7 -3
- package/dist/workspace/archil-claim.js +13 -5
- package/dist/workspace/archil-mount-credential.d.ts +6 -0
- package/dist/workspace/archil-mount-credential.js +11 -0
- package/dist/workspace/computer-deps.d.ts +5 -3
- package/dist/workspace/computer-deps.js +11 -9
- package/dist/workspace/computer-for-claim.d.ts +6 -2
- package/dist/workspace/computer-for-claim.js +43 -12
- package/dist/workspace/computer-janitor.d.ts +7 -4
- package/dist/workspace/computer-janitor.js +7 -4
- package/dist/workspace/computer-kept.d.ts +7 -1
- package/dist/workspace/computer-kept.js +7 -1
- package/dist/workspace/kind-skills/desktop/SKILL.md +12 -3
- package/dist/workspace/mount-revoke-left.d.ts +16 -4
- package/dist/workspace/mount-revoke-left.js +42 -22
- package/dist/workspace/resolve-computer.d.ts +11 -5
- package/dist/workspace/resolve-computer.js +22 -13
- package/dist/workspace/run-end-computers.js +1 -1
- package/dist/workspace/run-tools.d.ts +10 -3
- package/dist/workspace/run-tools.js +5 -4
- package/dist/wrapped.d.ts +29 -2
- package/dist/wrapped.js +20 -3
- package/launcher/agentrun-serve +1 -1
- package/package.json +12 -12
- package/dist/console/assets/index-DZi-muIj.js +0 -629
- package/dist/console/assets/share-pz61zIn9.js +0 -6
package/dist/server.js
CHANGED
|
@@ -31,8 +31,8 @@ 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
|
-
import {
|
|
35
|
-
import { API_ONLY_MCP_ORIGINS_ENV, apiOnlyMcpOriginsFrom, RUN_KEYS_ENV } from "./env-switch.js";
|
|
34
|
+
import { apiOnlyMcpSave, apiOnlyRefusal, apiOnlyTriggerEdit, apiOnlyTriggerSkipped, apiOnlyTurnsOn, servedApiOnly } from "./api-only.js";
|
|
35
|
+
import { API_ONLY_ENV, API_ONLY_MCP_ORIGINS_ENV, apiOnlyMcpOriginsFrom, RUN_KEYS_ENV } from "./env-switch.js";
|
|
36
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";
|
|
@@ -110,6 +110,7 @@ import { modelKeyMisfit, modelKeyOf, modelKeyRequired, noServerKeyFor, runModelO
|
|
|
110
110
|
import { exportReadsOverStore } from "./run-export-store.js";
|
|
111
111
|
import { listRunFiles as listRunFilesOverStore, readRunFile as readRunFileOverStore, runGraphView, runTimelines } from "./run-reads-over-store.js";
|
|
112
112
|
import { ExportFailed, restoreIdsOf, runExport } from "./run-export.js";
|
|
113
|
+
import { shareHost } from "./share-host.js";
|
|
113
114
|
import { triggerTargets } from "./trigger-targets.js";
|
|
114
115
|
import { labelFilter, labelsIssues } from "./run-labels.js";
|
|
115
116
|
import { listRuns as listRunsOverStore, readRun as readRunOverStore, runOfOrigin as runOfOriginOverStore } from "./store-reads/runs.js";
|
|
@@ -133,7 +134,8 @@ import { workflowNodesOf } from "./learn/workflow-nodes.js";
|
|
|
133
134
|
import { deleteLearning } from "./learn/delete.js";
|
|
134
135
|
import { forgetLegacyRunLearning, legacyGradesKey, legacyPromotionsKey } from "./learn/legacy/scrub.js";
|
|
135
136
|
import { runModelRef } from "./model.js";
|
|
136
|
-
import {
|
|
137
|
+
import { fullTag, localModelView, localPulls, pullLocalModel, pullThrough, readMachine } from "./local-model.js";
|
|
138
|
+
import { ollamaForget, ollamaHostOf, ollamaHostRefused, ollamaListing, ollamaModels, ollamaReading } from "./ollama-provider.js";
|
|
137
139
|
import { REDACTED } from "./secret-cut.js";
|
|
138
140
|
// The v2 run statuses, as the run view names them (run-view.ts Status), for the list filter's validation. */
|
|
139
141
|
const STATUSES = ["queued", "working", "paused", "input_required", "completed", "failed", "cancelled"];
|
|
@@ -233,7 +235,7 @@ import { noAccount, openAccount } from "./email/account.js";
|
|
|
233
235
|
import { emailRoute } from "./email/routes.js";
|
|
234
236
|
import { addressForms, openCalendar } from "./calendar/address.js";
|
|
235
237
|
import { calendarRoute } from "./calendar/routes.js";
|
|
236
|
-
import { agentDiskOf, ARCHIL_DISK_ID, archilSettingsFromEnv, inArchilMode, loadArchilSettings, runDiskKept, runDiskKey } from "./archil-settings.js";
|
|
238
|
+
import { agentDiskOf, ARCHIL_DISK_ID, archilSettingsFromEnv, inArchilMode, loadArchilSettings, noExecRegionOf, noExecWords, runDiskKept, runDiskKey } from "./archil-settings.js";
|
|
237
239
|
import { computerOfPlace, settingOfDefinition } from "./computer-setting.js";
|
|
238
240
|
import { computerCapabilities, createComputerRoutes, folderModeOf, hostCommandRefusals, settingsComputerRoute } from "./computers.js";
|
|
239
241
|
import { runningComputers } from "./computers-running.js";
|
|
@@ -501,6 +503,9 @@ export const ROUTES = [
|
|
|
501
503
|
{ method: "PUT", pattern: /^\/settings\/model-gateway$/, name: "saveModelGateway" },
|
|
502
504
|
{ method: "DELETE", pattern: /^\/settings\/model-gateway$/, name: "deleteModelGateway" },
|
|
503
505
|
{ method: "POST", pattern: /^\/settings\/model-gateway\/test$/, name: "testModelGateway" },
|
|
506
|
+
// A free local model (local-model.ts): this machine and its recommended model, and one pull of it, the owner's alone.
|
|
507
|
+
{ method: "GET", pattern: /^\/settings\/local-model$/, name: "getLocalModel" },
|
|
508
|
+
{ method: "POST", pattern: /^\/settings\/local-model\/pull$/, name: "pullLocalModel" },
|
|
504
509
|
{ method: "GET", pattern: /^\/settings\/mcp-servers$/, name: "listMcpServers" },
|
|
505
510
|
{ method: "GET", pattern: /^\/settings\/mcp-server-names$/, name: "listMcpServerNames" },
|
|
506
511
|
{ method: "POST", pattern: /^\/settings\/mcp-servers\/preview$/, name: "previewMcpServer" },
|
|
@@ -724,16 +729,20 @@ export function forCaller(caps, ownerSession) {
|
|
|
724
729
|
}
|
|
725
730
|
/** The capabilities document from offers already resolved, under the server's learning switch, tool settings and box
|
|
726
731
|
* offers: cheap, made again after each key or tool-settings write with the offers the server holds; and `needs` as
|
|
727
|
-
* needsOf says it for a revision that names no model (null when it runs). `
|
|
728
|
-
*
|
|
729
|
-
*
|
|
730
|
-
|
|
732
|
+
* needsOf says it for a revision that names no model (null when it runs). `runner`: where a revision that names no
|
|
733
|
+
* place has its shell (place.ts RunnerShell): on the runner, whose sandbox-only tools (tools.ts shellTools; bash in
|
|
734
|
+
* Mode 2) are available with no box; on a Mode 2 region with no serverless exec, nowhere, so they are unavailable,
|
|
735
|
+
* saying why, Docker answering or not. `switched`: the two start-time switches the server takes as options
|
|
736
|
+
* (switchedOnBy reads them from `env`, as the CLI sets them). */
|
|
737
|
+
function capabilitiesWith(env, maxRuns, harnesses, learning, { needs, priced, learning_model }, toolSettings, boxes, refused = {}, runner = false, isolation = "process", switched = switchedOnBy(env)) {
|
|
738
|
+
const runnerShell = runner === true ? shellTools("local") : new Set();
|
|
739
|
+
const noBox = typeof runner === "object" ? `${noExecWords(runner.noExec)}, so a run with no computer has no shell, and the docker box can't mount Archil: give the agent a sandbox computer (a box), or leave bash out of its tools` : noBoxReason(boxes, enabledBoxes(env));
|
|
731
740
|
const models = { ...modelSource(env), ready: needs === null, needs, priced };
|
|
732
741
|
// Both limits apply: the cap on the count, and the memory each run reserves (host.ts).
|
|
733
742
|
const memory = hostMemory();
|
|
734
743
|
// The browser's key is its vendor's row: Kernel's where Kernel is picked or resolved (tool-plane.ts browserKeyRow).
|
|
735
744
|
const keyFor = (tool) => (tool.name === "browser" ? browserKeyRow(tool.provider, tool.resolves?.[DEFAULT_HARNESS]) : keyOf(tool.name));
|
|
736
|
-
const tools = toolsView(env, toolSettings,
|
|
745
|
+
const tools = toolsView(env, toolSettings, noBox, refused, runnerShell).map((tool) => (keyFor(tool) ? { ...tool, key: keyFor(tool) } : tool));
|
|
737
746
|
const browser = tools.find((tool) => tool.name === "browser");
|
|
738
747
|
return {
|
|
739
748
|
backend: "local",
|
|
@@ -753,7 +762,7 @@ function capabilitiesWith(env, maxRuns, harnesses, learning, { needs, priced, le
|
|
|
753
762
|
harnesses: harnesses.map(({ keys: _keys, noModelRuns, ...offer }) => ({ ...offer, available: offer.available && !noModelRuns, max_concurrent_runs: Math.min(maxRuns, runsThatFit(offer.id, memory, env)) })),
|
|
754
763
|
/** The places a revision may name (`definition.place`), this host's default (null where a new agent must name one),
|
|
755
764
|
* and whether this server has each box. */
|
|
756
|
-
places: placesOf(boxes, boxAllowOf(env),
|
|
765
|
+
places: placesOf(boxes, boxAllowOf(env), runner),
|
|
757
766
|
models,
|
|
758
767
|
learning_model,
|
|
759
768
|
/** `pending`: a workflow draft with a call no price covers is kept to wait for its owner's OK, served to no run;
|
|
@@ -938,6 +947,14 @@ export async function startServe(options) {
|
|
|
938
947
|
// API-only: no console, so no owner to sign in to it (and no setup code printed for a page that is refused).
|
|
939
948
|
if (options.apiOnly)
|
|
940
949
|
options = { ...options, accounts: false, openSetup: false };
|
|
950
|
+
// The share host: no console, owner or runner either, and its share URLs on its public address alone.
|
|
951
|
+
if (options.shareHost) {
|
|
952
|
+
if (options.apiOnly)
|
|
953
|
+
throw new Error(`a server is a share host (--share-host) or API-only (${API_ONLY_ENV}=1), not both`);
|
|
954
|
+
if (!options.publicUrl && !isLoopback(options.host ?? DEFAULT_HOST))
|
|
955
|
+
throw new Error("a share host on an address other than loopback names its shares' address in AGENTRUN_PUBLIC_URL (the origin people open its /r/ links at): a request's Host header never names it");
|
|
956
|
+
options = { ...options, accounts: false, openSetup: false, runnerApart: true };
|
|
957
|
+
}
|
|
941
958
|
// A harness table module is the server's to name, from `harnessTable` alone, for itself and its runs: one in its own
|
|
942
959
|
// environment (an operator's export, a leftover) never loads, wherever the server reads its environment.
|
|
943
960
|
delete process.env[HARNESS_TABLE_ENV];
|
|
@@ -958,7 +975,8 @@ export async function startServe(options) {
|
|
|
958
975
|
}
|
|
959
976
|
// The Ollama this server asks, and its runner beside it: OLLAMA_HOST, else the default address on one owner's own machine
|
|
960
977
|
// alone (ollamaHostOf). Read once, at the start: a refused one is said once, here, in the base rule's words.
|
|
961
|
-
const
|
|
978
|
+
const notOwn = whyNotOwnMachine(options, data, ownUser);
|
|
979
|
+
const ollamaHost = ollamaHostOf(process.env, notOwn.length === 0);
|
|
962
980
|
const tokenRefused = options.token === undefined ? undefined : tokenProblem(options.token);
|
|
963
981
|
if (tokenRefused)
|
|
964
982
|
throw new Error(tokenRefused);
|
|
@@ -1000,7 +1018,7 @@ export async function startServe(options) {
|
|
|
1000
1018
|
// would write the next server's outbox.
|
|
1001
1019
|
const stops = [];
|
|
1002
1020
|
try {
|
|
1003
|
-
return await startHolding(options, data, { maxRuns, minFreeBytes, learning, boxAllow, templates, ollamaHost }, stops);
|
|
1021
|
+
return await startHolding(options, data, { maxRuns, minFreeBytes, learning, boxAllow, templates, ollamaHost, notOwn }, stops);
|
|
1004
1022
|
}
|
|
1005
1023
|
catch (error) {
|
|
1006
1024
|
for (const stop of stops)
|
|
@@ -1030,7 +1048,7 @@ async function whileReplaced(take, held, until, waiting) {
|
|
|
1030
1048
|
}
|
|
1031
1049
|
}
|
|
1032
1050
|
async function startHolding(options, data, checked, stops) {
|
|
1033
|
-
const { maxRuns, minFreeBytes, learning, boxAllow, templates, ollamaHost } = checked;
|
|
1051
|
+
const { maxRuns, minFreeBytes, learning, boxAllow, templates, ollamaHost, notOwn } = checked;
|
|
1034
1052
|
/** What an agent's view says of its learning: how many learned items wait for its owner's OK, for an agent that learns
|
|
1035
1053
|
* on this server (learning on, its current revision `learning: true`); none for another, or when the count cannot be
|
|
1036
1054
|
* read (the view never fails for it). */
|
|
@@ -1354,7 +1372,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1354
1372
|
// The start-time switches as this server was started: its options, else the CLI's variables. mcpLoopback is the
|
|
1355
1373
|
// option alone, as everywhere it is read here (localInstall): the CLI sets it from AGENTRUN_MCP_ALLOW_LOOPBACK.
|
|
1356
1374
|
const switched = { mcpLoopback: options.mcpLoopback === true, webhookPrivateTargets: switchedOnBy(process.env, options).webhookPrivateTargets, apiOnlyMcpOrigins };
|
|
1357
|
-
const compose = (
|
|
1375
|
+
const compose = (runner = false) => askNeeds(capabilitiesWith(env, maxRuns, offers, learning, needs, settings.get(), boxOffers, toolKeys.refused(), runner, isolation, switched));
|
|
1358
1376
|
const recompose = () => void (caps = compose());
|
|
1359
1377
|
// What the offers held now were made from (offersInputs), and the latest probe: one a later probe overtook is dropped.
|
|
1360
1378
|
let offersFrom;
|
|
@@ -1363,7 +1381,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1363
1381
|
// probe that fails never lands; when it is the latest, it clears this as it fails, so no probe is out after it.
|
|
1364
1382
|
let probing;
|
|
1365
1383
|
// The latest probe's turn: it ends as that probe lands or fails, or as a later probe starts and overtakes it, whichever
|
|
1366
|
-
// is first, and never fails. A change that waits for the probe out waits for its turn (
|
|
1384
|
+
// is first, and never fails. A change that waits for the probe out waits for its turn (offersNow), so a dropped
|
|
1367
1385
|
// probe holds no one up and its failure is no one else's.
|
|
1368
1386
|
let turn = Promise.resolve();
|
|
1369
1387
|
let endTurn = () => { };
|
|
@@ -1413,16 +1431,17 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1413
1431
|
});
|
|
1414
1432
|
/** Whether the offers held now were made from `inputs` (offersInputs). */
|
|
1415
1433
|
const offersMadeFrom = (inputs) => offersFrom !== undefined && sameInputs(inputs, offersFrom);
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
// serverSecrets live, store-view), and a list builds a listing cut of other keys again (builtOfNow). A failed run's error words
|
|
1419
|
-
// name a refused key by the keys and settings, so those listings are built again.
|
|
1420
|
-
await lister.keysChanged();
|
|
1421
|
-
env = readEnv(base);
|
|
1434
|
+
/** What a revision that names no model needs (needsOf), made again from env as it is now: the latest ask's stands. */
|
|
1435
|
+
const needsNow = async () => {
|
|
1422
1436
|
const mine = ++needsAsked;
|
|
1423
1437
|
const next = await needsOf(env);
|
|
1424
1438
|
if (mine === needsAsked)
|
|
1425
1439
|
needs = next;
|
|
1440
|
+
};
|
|
1441
|
+
/** The offers made again from the inputs read now (offersInputs), with no listing built again and env not read again:
|
|
1442
|
+
* the end of a key's change (keysChanged), and all of a refresh of the login, or of a new Ollama listing, whose offers
|
|
1443
|
+
* are not made from the inputs now, since no key changed there. */
|
|
1444
|
+
const offersNow = async () => {
|
|
1426
1445
|
// A probe still out from other inputs (a turn-on's, after its turn-off) would put back offers made from them as it
|
|
1427
1446
|
// lands: a probe of these overtakes it. Only a change starts one, at most one per change, so nothing loops. While the
|
|
1428
1447
|
// probe out has read these inputs, a change starts none: with the offers held made from them too it recomposes at
|
|
@@ -1447,16 +1466,51 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1447
1466
|
return;
|
|
1448
1467
|
}
|
|
1449
1468
|
};
|
|
1469
|
+
const keysChanged = async () => {
|
|
1470
|
+
// A run's learning, view, list and timeline row are cut of the keys saved now by the run view at read time (it reads
|
|
1471
|
+
// serverSecrets live, store-view), and a list builds a listing cut of other keys again (builtOfNow). A failed run's error words
|
|
1472
|
+
// name a refused key by the keys and settings, so those listings are built again.
|
|
1473
|
+
await lister.keysChanged();
|
|
1474
|
+
env = readEnv(base);
|
|
1475
|
+
await needsNow();
|
|
1476
|
+
await offersNow();
|
|
1477
|
+
};
|
|
1450
1478
|
/** The Ollama here, as capabilities read it: its listing asked again behind the answer once stale (ollamaModels), and
|
|
1451
|
-
*
|
|
1479
|
+
* once a listing differs from the one the offers were made from, what a revision that names no model needs (its
|
|
1480
|
+
* default is the listing's: needsOf) and the offers made again from it. No key changed, so no run is relisted. So a
|
|
1452
1481
|
* model pulled, or Ollama started after this server, shows in a later answer with no restart. */
|
|
1453
1482
|
const ollamaNow = async () => {
|
|
1454
1483
|
if (!asksOllama(env))
|
|
1455
1484
|
return;
|
|
1456
1485
|
void ollamaModels(env);
|
|
1457
|
-
if (offersFrom
|
|
1458
|
-
|
|
1486
|
+
if (!offersFrom || offersMadeFrom(offersInputs(env)))
|
|
1487
|
+
return;
|
|
1488
|
+
await needsNow();
|
|
1489
|
+
await offersNow();
|
|
1459
1490
|
};
|
|
1491
|
+
/** How many times a pull's end reads the Ollama listing for its tag before it fails (ollamaPulled). */
|
|
1492
|
+
const PULL_LISTED_TRIES = 6;
|
|
1493
|
+
/** After a pull of `tag` here ends (local-model.ts): the kept listing dropped and read again at once until it lists
|
|
1494
|
+
* `tag` (a listing whose ask of one model failed lists it not), and the reading made again where it differs, so the
|
|
1495
|
+
* model is in the picker and is the default with no wait for OLLAMA_TTL_MS before the pull says done. Never listed
|
|
1496
|
+
* after PULL_LISTED_TRIES reads, the pull fails in words, so the card never runs a template on another model. */
|
|
1497
|
+
const ollamaPulled = async (tag) => {
|
|
1498
|
+
for (let tries = 1;; tries++) {
|
|
1499
|
+
ollamaForget(env);
|
|
1500
|
+
const listed = await ollamaModels(env);
|
|
1501
|
+
if (listed.some((model) => model.name === fullTag(tag)))
|
|
1502
|
+
break;
|
|
1503
|
+
if (tries >= PULL_LISTED_TRIES)
|
|
1504
|
+
throw new Error(`Ollama finished pulling ${tag} but does not list it yet. Press Pull again.`);
|
|
1505
|
+
await new Promise((resolve) => setTimeout(resolve, 250 * tries));
|
|
1506
|
+
}
|
|
1507
|
+
await ollamaNow();
|
|
1508
|
+
};
|
|
1509
|
+
/** This machine, read once (local-model.ts readMachine), or a test's. */
|
|
1510
|
+
let machineRead;
|
|
1511
|
+
const machineOf = () => (machineRead ??= (options.machine ?? readMachine)());
|
|
1512
|
+
const pulls = localPulls({ pull: pullThrough(() => env, options.pullStallMs), finished: ollamaPulled, ...(log ? { log } : {}), signal: stopping.signal });
|
|
1513
|
+
const localModelDeps = () => ({ env, notOwn, machine: machineOf, pulls });
|
|
1460
1514
|
/** After a harness key is saved or removed (harness-keys.ts): the listings built again, cut of it, and the offers probed
|
|
1461
1515
|
* again, as a recipe is offered once every key it runs on is saved here (harnessKeysSavedHere). No environment changes. */
|
|
1462
1516
|
const harnessKeysChanged = async () => {
|
|
@@ -1561,8 +1615,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1561
1615
|
* 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
|
|
1562
1616
|
* 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
|
|
1563
1617
|
* offers held were made before it. So the request also goes on only where the offers held are made from the inputs
|
|
1564
|
-
* now (offersMadeFrom); where not, it makes them as a key's save
|
|
1565
|
-
* these inputs, or probes itself, and a probe of its own that fails is answered to it)
|
|
1618
|
+
* now (offersMadeFrom); where not, it makes them again as a key's save ends (offersNow: it waits for the probe out of
|
|
1619
|
+
* these inputs, or probes itself, and a probe of its own that fails is answered to it), with no run relisted, as no
|
|
1620
|
+
* key changed. It looks at most LOGIN_ROUNDS
|
|
1566
1621
|
* times, then is refused (unavailable, retryable), so turns that keep coming never hold it for ever. */
|
|
1567
1622
|
const loginNow = async () => {
|
|
1568
1623
|
if (loginOff !== undefined)
|
|
@@ -1570,8 +1625,12 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1570
1625
|
for (let round = 1;; round++) {
|
|
1571
1626
|
const n = await refreshOnce();
|
|
1572
1627
|
const latest = () => handed.n === n && !handed.failed;
|
|
1573
|
-
|
|
1574
|
-
|
|
1628
|
+
// The inputs moved on with no key changed (a new Ollama listing, the login): what a revision that names no model
|
|
1629
|
+
// needs is made again from them first, as ollamaNow does, or the offers come back with a default it never read.
|
|
1630
|
+
if (latest() && !offersMadeFrom(offersInputs(env))) {
|
|
1631
|
+
await needsNow();
|
|
1632
|
+
await offersNow();
|
|
1633
|
+
}
|
|
1575
1634
|
if (latest() && offersMadeFrom(offersInputs(env)))
|
|
1576
1635
|
return;
|
|
1577
1636
|
if (round >= LOGIN_ROUNDS)
|
|
@@ -1700,7 +1759,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1700
1759
|
const computersOf = () => (computerRoutes ??= createComputerRoutes({
|
|
1701
1760
|
// A provider's key set where the server starts is one of its secrets, held off process.env (secrets.ts): read by name
|
|
1702
1761
|
// from what the server was started with, as computerReady below reads it.
|
|
1703
|
-
store, sealKey, tools: kindTools, mode: folderModeOf(store, process.env), env: withSecrets(process.env, "own"),
|
|
1762
|
+
store, sealKey, tools: kindTools, mode: folderModeOf(store, process.env), noExec: () => noExecNow(), env: withSecrets(process.env, "own"),
|
|
1704
1763
|
// Each with its route (who holds it, on which runner, and why a route was refused), and online while relayed.
|
|
1705
1764
|
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) },
|
|
1706
1765
|
runnerApart: options.runnerApart === true,
|
|
@@ -1727,6 +1786,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1727
1786
|
* provider's program is on this machine is hostWhy's, read at the start. */
|
|
1728
1787
|
/** The server's folder mode now: 2 when the owner's Archil settings are saved (the run's folder on the disk), else 1. */
|
|
1729
1788
|
const modeNow = async () => ((await folderModeOf(store, process.env)()) === "disk" ? 2 : 1);
|
|
1789
|
+
/** In Mode 2, this server's Archil region now where it has no serverless exec (archil-settings.ts noExecRegionOf), read
|
|
1790
|
+
* as the claim reads it (the environment's settings, else the saved ones); else undefined. */
|
|
1791
|
+
const noExecNow = async () => noExecRegionOf(await loadArchilSettings(store, process.env));
|
|
1730
1792
|
/** The registry a run's claim resolves against (claimKinds), as its runner composes it. */
|
|
1731
1793
|
const claimRegistry = () => claimKinds(options.faux ? { faux: fauxOf() } : {});
|
|
1732
1794
|
/** A key as the runner reads it: the secrets this process was started with (withSecrets "own"), else the saved one. */
|
|
@@ -1743,18 +1805,32 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1743
1805
|
};
|
|
1744
1806
|
/** Where a run of an agent with computer `setting` has its shell here now (resolve-computer.ts runShellOf, in the
|
|
1745
1807
|
* folder mode of now, over the registry the claim reads): what runnable.ts lets a sandbox-only tool on the runner by,
|
|
1746
|
-
* and capabilities show bash by. In Mode 2 a run with no computer has bash on Archil's serverless exec
|
|
1747
|
-
|
|
1808
|
+
* and capabilities show bash by. In Mode 2 a run with no computer has bash on Archil's serverless exec, where the
|
|
1809
|
+
* server's Archil region has it (noExecNow). */
|
|
1810
|
+
const shellOf = async (setting) => runShellOf(setting, await modeNow(), await registryHere(setting.provider === undefined ? claimRegistry() : withPaired(claimRegistry(), await store.pairedComputers.list()), runnerKeys()), await noExecNow());
|
|
1811
|
+
/** Where a revision that names no place has a shell now, besides a box (place.ts RunnerShell): on the runner where a
|
|
1812
|
+
* run with no computer has one here (shellOf); else, in Mode 2 on a region with no exec, nowhere (Docker's box can't
|
|
1813
|
+
* mount Archil), naming the region; else (Mode 1) in Docker's box. */
|
|
1814
|
+
const runnerShellNow = async () => {
|
|
1815
|
+
if ((await shellOf({ kind: "none" })) === "local")
|
|
1816
|
+
return true;
|
|
1817
|
+
const noExec = await noExecNow();
|
|
1818
|
+
return noExec === undefined ? false : { noExec };
|
|
1819
|
+
};
|
|
1748
1820
|
/** The shell this server can give a template's agent now (templates.ts pickComputer's `shell`), by the rules a run
|
|
1749
1821
|
* has it by (shellOf): Archil's serverless exec on the runner in Mode 2 (bash alone); else the box a new agent is saved
|
|
1750
1822
|
* with (Docker), where it answers now (computerReady asks the daemon, not the start's offers: a Docker stopped since
|
|
1751
1823
|
* is no shell), whose shell runs the shell tools; else none, and why. A package that needs programs (`sandbox`) asks
|
|
1752
1824
|
* for a sandbox alone, whose box a run checks for them: Archil's exec is none, so in Mode 2 it is told why no sandbox
|
|
1753
|
-
* answers (the Docker box can't mount Archil's workspaces), never given the exec.
|
|
1825
|
+
* answers (the Docker box can't mount Archil's workspaces), never given the exec. In Mode 2 on a region with no
|
|
1826
|
+
* serverless exec there is neither: none, saying why and the fix. */
|
|
1754
1827
|
const shellHere = async (wants = {}) => {
|
|
1755
1828
|
const exec = (await shellOf({ kind: "none" })) === "local";
|
|
1756
1829
|
if (exec && !wants.sandbox)
|
|
1757
1830
|
return { computer: { kind: "none" }, tools: [...shellTools("local")], words: "Archil's serverless exec" };
|
|
1831
|
+
const noExec = exec ? undefined : await noExecNow();
|
|
1832
|
+
if (noExec !== undefined)
|
|
1833
|
+
return { none: `this server has no shell to give an agent now: ${noExecWords(noExec)}, and the docker box can't mount Archil`, fix: "Give the agent a sandbox computer (a box) to run bash, or leave bash out of its tools." };
|
|
1758
1834
|
const fresh = newAgentPlace(boxOffers);
|
|
1759
1835
|
let why = "why" in fresh ? fresh.why : "it is not set up";
|
|
1760
1836
|
if ("place" in fresh && fresh.place.mode === "sandbox") {
|
|
@@ -1791,7 +1867,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1791
1867
|
* list reads it, so a tool of bash's family the run would not have shows unavailable (tool-plane.ts shellUnavailable). */
|
|
1792
1868
|
const shellOfRevision = async (revision) => {
|
|
1793
1869
|
const body = revision.body;
|
|
1794
|
-
return shellOf(settingOfDefinition(body)?.computer ?? computerOfPlace(fallbackPlace(revision.kind, revision.kind === "agentic" ? (body.tools ?? []) : [])));
|
|
1870
|
+
return shellOf(settingOfDefinition(body)?.computer ?? computerOfPlace(await fallbackPlace(revision.kind, revision.kind === "agentic" ? (body.tools ?? []) : [])));
|
|
1795
1871
|
};
|
|
1796
1872
|
/** The run read's costs (A8, store-reads/learning.ts runAllInOverStore): `cost.usd` its own spend, the
|
|
1797
1873
|
* job's (its compile turn is learning's), null while unknown; what learning spent for it
|
|
@@ -1874,7 +1950,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1874
1950
|
});
|
|
1875
1951
|
// The outbound webhook's secret, as it stands (set by a PUT, gone with a DELETE), and each it held before.
|
|
1876
1952
|
stops.push(() => webhooks.close());
|
|
1877
|
-
|
|
1953
|
+
// A share host sends no message: a data folder it reuses may hold a webhook, a Slack URL and messages left queued, about
|
|
1954
|
+
// runs it neither runs nor answers for. Its outboxes are never read, so nothing is resumed or sent; their saved secrets
|
|
1955
|
+
// are, so they stay held values its uploads are scrubbed with.
|
|
1956
|
+
await (options.shareHost ? webhooks.readSecrets() : webhooks.load());
|
|
1878
1957
|
// Where an earlier version kept the webhook: no longer read.
|
|
1879
1958
|
if (existsSync(join(data, WEBHOOK_FILE)))
|
|
1880
1959
|
log?.(logLine("webhook", { condition: "webhook_left_over", file: join(data, WEBHOOK_FILE), effect: "not read: the webhook is kept in the store now; set it again with PUT /v2/settings/webhook" }));
|
|
@@ -1890,7 +1969,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1890
1969
|
serverSecrets: () => serverSecrets(),
|
|
1891
1970
|
});
|
|
1892
1971
|
stops.push(() => slack.close());
|
|
1893
|
-
await slack.load();
|
|
1972
|
+
await (options.shareHost ? slack.readSecrets() : slack.load());
|
|
1894
1973
|
secretStores.add("slack", () => slack.urlForms());
|
|
1895
1974
|
const uploads = new Uploads(join(data, UPLOADS_DIR));
|
|
1896
1975
|
// Under the data directory's lock and before this server answers anything, so no PUT of its own is in flight: an upload
|
|
@@ -2056,8 +2135,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2056
2135
|
}).finally(() => { localSourceBusy = false; });
|
|
2057
2136
|
return localSourceSweep;
|
|
2058
2137
|
};
|
|
2059
|
-
|
|
2060
|
-
|
|
2138
|
+
// A share host publishes no agent's sources: a reused folder's agent with source sync on would get new revisions there,
|
|
2139
|
+
// and the host answers none of the routes that show or stop that sync.
|
|
2140
|
+
const localSourceTimer = options.shareHost ? undefined : setInterval(() => void sweepLocalSources(), 30_000);
|
|
2141
|
+
localSourceTimer?.unref();
|
|
2061
2142
|
// As close() does: aborted first, so a sync in flight stops instead of being waited out.
|
|
2062
2143
|
stops.unshift(async () => {
|
|
2063
2144
|
stopping.abort();
|
|
@@ -2177,6 +2258,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2177
2258
|
context: ctx,
|
|
2178
2259
|
sealKey,
|
|
2179
2260
|
liveViewer: (runId) => liveViewerLink(store, sealKey, runId, answers(runId)),
|
|
2261
|
+
...(options.cutMs !== undefined ? { cutMs: options.cutMs } : {}),
|
|
2180
2262
|
};
|
|
2181
2263
|
// The run timeline reader over the store (run-reads-over-store runTimelines): one change-numbered RowLog per run, synced
|
|
2182
2264
|
// from its journal (store-reads) on each read, its view (viewOverStore) for status/state/cost and whether it is final.
|
|
@@ -2255,6 +2337,19 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2255
2337
|
keyUsed.set(req, key);
|
|
2256
2338
|
return started || key !== undefined;
|
|
2257
2339
|
};
|
|
2340
|
+
// The share host's routes (share-host.ts), with its own store under DIR/shares: a token's id owns each share, and the
|
|
2341
|
+
// values it holds (its keys, its tokens) refuse an upload that carries one.
|
|
2342
|
+
const shareRoute = options.shareHost ? shareHost({
|
|
2343
|
+
data,
|
|
2344
|
+
who: (req) => (bearer(req.headers.authorization, req) ? tokenUsed.get(req) : undefined),
|
|
2345
|
+
authFailed,
|
|
2346
|
+
held: () => [...serverSecrets(), ...tokens.map((entry) => entry.token)],
|
|
2347
|
+
// AGENTRUN_PUBLIC_URL, else (a loopback start alone, as the start checked) the address this server listens at.
|
|
2348
|
+
origin: () => options.publicUrl ?? urlOf(server, host),
|
|
2349
|
+
console: options.console,
|
|
2350
|
+
version: VERSION,
|
|
2351
|
+
...(options.shareScrub ? { scrub: options.shareScrub } : {}),
|
|
2352
|
+
}) : undefined;
|
|
2258
2353
|
// Answered keys are kept in the data directory for the retention capabilities state, and written before the answer
|
|
2259
2354
|
// is sent, so a client that retries after a restart gets the first answer back.
|
|
2260
2355
|
// A key's fingerprint is an HMAC of its request's body (stable JSON) under a key derived from the server's seal key:
|
|
@@ -2327,6 +2422,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2327
2422
|
// A saved key is read by name from here, past the checks that refuse a start and before any run (a recovered one too)
|
|
2328
2423
|
// is launched: each launch hands over what is saved then. One server in a process reads them: the last started.
|
|
2329
2424
|
await probe("start");
|
|
2425
|
+
// What a stop left in the ChatGPT sign-in's row (a sign-in saved, its models unlisted or the sign-in it replaced not
|
|
2426
|
+
// yet revoked) is settled now, out of the start's way, once the first offers are made: models it lists make them
|
|
2427
|
+
// again (keysChanged). The server's alone: a runner's reader never settles.
|
|
2428
|
+
plan.settleLeft();
|
|
2330
2429
|
// Under faux, a key the server starts with is checked only against a check's own fake (fauxBrowserbase,
|
|
2331
2430
|
// fauxMonidCheck, fauxKernel): the fakes the runs use (monid, Parallel, Jev) see the runs' calls alone, and a key with no check fake
|
|
2332
2431
|
// is not checked.
|
|
@@ -2609,10 +2708,14 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2609
2708
|
stops.push(async () => triggers.close());
|
|
2610
2709
|
// The firing loop runs against the server's own opened store: due firings start their runs through the run write half,
|
|
2611
2710
|
// times missed while it was down are recorded, and the timer is armed for the next. (A test may inject its own store.)
|
|
2612
|
-
|
|
2613
|
-
//
|
|
2614
|
-
|
|
2615
|
-
|
|
2711
|
+
// A share host runs none of them: a data folder it reuses may hold enabled schedules and feeds, whose runs it can
|
|
2712
|
+
// neither run nor answer for, and it reads no GitHub installation.
|
|
2713
|
+
if (!options.shareHost) {
|
|
2714
|
+
void triggers.start().catch((error) => void process.stderr.write(`agentrun-serve: the triggers' start: ${error.message}\n`));
|
|
2715
|
+
// The App's installations repaired from GitHub's own, once, as the server starts: events missed while it was down.
|
|
2716
|
+
// It never rejects, and close (or a start that fails) aborts it and waits for it before it closes.
|
|
2717
|
+
void githubConnect.reconcile((detail) => triggers.turnOff("github", detail), { force: true });
|
|
2718
|
+
}
|
|
2616
2719
|
// Setup's import of this machine's sessions: offered by a server on this machine only (no public address, listening
|
|
2617
2720
|
// on loopback), counted once (a listing, no transcript kept), run once, each on a worker thread (import-worker.ts) so
|
|
2618
2721
|
// a busy store's wait and the sessions' parsing never hold up a request.
|
|
@@ -3180,7 +3283,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3180
3283
|
if (!revision.mcpPin && tools.some((tool) => mcpToolOf(tool)))
|
|
3181
3284
|
return null;
|
|
3182
3285
|
try {
|
|
3183
|
-
await runnable(revision, resolvePlace(body.place, fallbackPlace(revision.kind, tools)), { capped: body.maxCostUsd !== undefined, price: readDecisionPrice });
|
|
3286
|
+
await runnable(revision, resolvePlace(body.place, await fallbackPlace(revision.kind, tools)), { capped: body.maxCostUsd !== undefined, price: readDecisionPrice });
|
|
3184
3287
|
return null;
|
|
3185
3288
|
}
|
|
3186
3289
|
catch (error) {
|
|
@@ -3277,7 +3380,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3277
3380
|
if (owed.length)
|
|
3278
3381
|
throw keysOwedRefusal(owed);
|
|
3279
3382
|
// Claude Code's login on this machine is a runner place's alone: a sandbox run is checked for a key, as it runs.
|
|
3280
|
-
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 });
|
|
3383
|
+
const blockers = await blockersOf(withCarried(envAtPlace(env, shape.place), carried), shape, settings.get(), { capped, boxes: boxOffers, computerReady, shellOf, noExec: await noExecNow(), offers, mcp: revision.kind === "agentic" ? pinnedTools : mcpTools, monid, decisionPrice: price });
|
|
3281
3384
|
if (!blockers.length)
|
|
3282
3385
|
return;
|
|
3283
3386
|
// An agent refused for its model in a box while its harness runs on the login at the runner, on a model the login
|
|
@@ -3311,8 +3414,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3311
3414
|
const asks = blockers.flatMap((b) => (b.asks ? [b.asks] : []));
|
|
3312
3415
|
throw new ApiError("agent_not_runnable", message, { fields, details: { adapters: [...new Set(blockers.flatMap((b) => (b.adapter ? [b.adapter] : [])))], unbound, missing, code: blockers.some((b) => b.codeNodes || b.shell), ...(tier ? { tier } : {}), ...(Object.keys(decisions).length ? { decisions } : {}), ...(denied.length ? { denied } : {}), ...(asks.length ? { asks } : {}), ...named } });
|
|
3313
3416
|
}
|
|
3314
|
-
/** Where a revision of `kind` naming `tools` and no place runs here: the place a new agent would be saved with
|
|
3315
|
-
|
|
3417
|
+
/** Where a revision of `kind` naming `tools` and no place runs here: the place a new agent would be saved with, in the
|
|
3418
|
+
* folder mode of now (Mode 2: the runner, never Docker's box, which can't mount Archil; on a region with no exec its
|
|
3419
|
+
* shell tools are refused there, runnerShellNow). */
|
|
3420
|
+
const fallbackPlace = async (kind, tools) => defaultPlaceOf(kind, tools, boxOffers, toolOf, await runnerShellNow());
|
|
3316
3421
|
/** What a save of `revision` pins of the MCP tools it grants (an agentic revision's: a workflow's nodes bind none): each
|
|
3317
3422
|
* granted server listed once, now, with its saved credential (McpServersOverStore.pinListing), as `tools` each server's
|
|
3318
3423
|
* listing in the harnesses' shape for the save's checks (blockersOf's `mcp`), and `pin` making the pin from them. A server
|
|
@@ -3421,18 +3526,18 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3421
3526
|
void install.ensure().catch((error) => log?.(logLine("harness_install_failed", { harness: install.entry.id, message: error.message })));
|
|
3422
3527
|
}
|
|
3423
3528
|
const named = (revision.kind === "agentic" ? { kind: "agentic", ...body } : workflowShape(body));
|
|
3424
|
-
const shape = named.place ? named : { ...named, place: fallbackPlace(named.kind, named.tools ?? []), unnamed: true };
|
|
3529
|
+
const shape = named.place ? named : { ...named, place: await fallbackPlace(named.kind, named.tools ?? []), unnamed: true };
|
|
3425
3530
|
const listing = await mcpListingOf(revision, previous?.mcpPin);
|
|
3426
3531
|
const mcp = listing.tools;
|
|
3427
3532
|
const { monid, warnings: usage = [] } = (await monidPinOf(revision, previous)) ?? {};
|
|
3428
|
-
const blockers = await blockersOf(envAtPlace(env, shape.place), shape, settings.get(), { boxes: boxOffers, computerReady, shellOf, offers, mcp, monid });
|
|
3533
|
+
const blockers = await blockersOf(envAtPlace(env, shape.place), shape, settings.get(), { boxes: boxOffers, computerReady, shellOf, noExec: await noExecNow(), offers, mcp, monid });
|
|
3429
3534
|
// An agent's default cap caps each run started without one of its own, and a web tool resolves by the cap: what a cap
|
|
3430
3535
|
// alone keeps from running under the definition's own picks, whatever this host's settings, would keep every such run
|
|
3431
3536
|
// from running, so the save is refused, not each run (claude-agent's or codex's own search, picked, under a cap).
|
|
3432
3537
|
if ((body.maxCostUsd ?? 0) > 0) {
|
|
3433
3538
|
const key = (b) => `${b.field}\n${b.message}`;
|
|
3434
|
-
const plain = new Set((await blockersOf(env, shape, {}, { boxes: boxOffers, computerReady, shellOf, offers, mcp, monid })).map(key));
|
|
3435
|
-
const capped = await blockersOf(env, shape, {}, { capped: true, capUsd: body.maxCostUsd, boxes: boxOffers, computerReady, shellOf, offers, mcp, monid, decisionPrice });
|
|
3539
|
+
const plain = new Set((await blockersOf(env, shape, {}, { boxes: boxOffers, computerReady, shellOf, noExec: await noExecNow(), offers, mcp, monid })).map(key));
|
|
3540
|
+
const capped = await blockersOf(env, shape, {}, { capped: true, capUsd: body.maxCostUsd, boxes: boxOffers, computerReady, shellOf, noExec: await noExecNow(), offers, mcp, monid, decisionPrice });
|
|
3436
3541
|
// A model with no price (`unpriced`) is a setting this host fixes (AGENT_MODEL_PRICE): a warning, as it is; the
|
|
3437
3542
|
// agent saves and updates, and only a run under the cap is refused (409). So is a cap below what the model needs for
|
|
3438
3543
|
// one more step and an answer (`short`): the agent saves, and its runs wrap up at their first tool call. A tool's
|
|
@@ -3457,14 +3562,17 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3457
3562
|
* (planTemplate) both make, so a plan never says a create the apply refuses: an agentic revision that names no place
|
|
3458
3563
|
* and would be given Docker's box (no tools named, `toolsUnnamed`, or a shell tool), where this server has none and the
|
|
3459
3564
|
* runner has no shell (Mode 1), is refused, naming a box or the runner, never given another box (place.ts
|
|
3460
|
-
* noBoxRefusal). On Mode 2 it saves for the runner, as it always did
|
|
3565
|
+
* noBoxRefusal). On Mode 2 it saves for the runner, as it always did, except on an Archil region with no serverless
|
|
3566
|
+
* exec, where one that names a shell tool is refused, naming a sandbox computer, Docker answering or not
|
|
3567
|
+
* (runnerShellNow); one that names no tools saves on the runner with none (defaultToolsAt). Native,
|
|
3568
|
+
* CLI-learning and SDK agents run elsewhere. */
|
|
3461
3569
|
async function noPlaceOf(revision, toolsUnnamed) {
|
|
3462
3570
|
const body = revision.body;
|
|
3463
3571
|
if (revision.kind !== "agentic" || nativeOf(body) || cliLearningOf(body) || sdkOf(body))
|
|
3464
3572
|
return undefined;
|
|
3465
3573
|
if (body.place !== undefined || body.computer !== undefined)
|
|
3466
3574
|
return undefined;
|
|
3467
|
-
return noBoxRefusal(toolsUnnamed ? undefined : body.tools ?? [], boxOffers, toolOf,
|
|
3575
|
+
return noBoxRefusal(toolsUnnamed ? undefined : body.tools ?? [], boxOffers, toolOf, await runnerShellNow());
|
|
3468
3576
|
}
|
|
3469
3577
|
/** An agentic `revision`'s monid pin (monid.ts pinMonid) and a warning per endpoint priced by usage; a grant that
|
|
3470
3578
|
* cannot be pinned refuses the save (422). Undefined when it grants none. */
|
|
@@ -3502,7 +3610,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3502
3610
|
let warnings = [];
|
|
3503
3611
|
const definition = checkDefinitionBody(body, { harnesses });
|
|
3504
3612
|
const named = Array.isArray(definition.definition.tools) ? definition.definition.tools : [];
|
|
3505
|
-
const place = fallbackPlace("agentic", definition.definition.tools === undefined ? NEW_AGENT_TOOLS : named);
|
|
3613
|
+
const place = await fallbackPlace("agentic", definition.definition.tools === undefined ? NEW_AGENT_TOOLS : named);
|
|
3506
3614
|
const tools = defaultToolsAt(place);
|
|
3507
3615
|
const entry = await agents.create(definition, async (revision) => {
|
|
3508
3616
|
// A template's apply says whether its package named its tools (applyWith): one that named none, and no computer
|
|
@@ -3769,7 +3877,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3769
3877
|
// The model of each tier its subagents run on (packageTiers): the package's where this server runs it.
|
|
3770
3878
|
const tiers = await packageTiers(env, pkg.model, harness ?? DEFAULT_HARNESS, model);
|
|
3771
3879
|
const modelWarnings = [...("warning" in picked && picked.warning ? [picked.warning] : []), ...(tiers.warning ? [tiers.warning] : [])].map((message) => ({ field: "model", reason: "not_an_option", message }));
|
|
3772
|
-
|
|
3880
|
+
// A package that names no tools gets a new agent's where a new agent goes (fallbackPlace): the box's shell tools in
|
|
3881
|
+
// Docker's box; none on the runner, Mode 2's included.
|
|
3882
|
+
const defaultTools = defaultToolsAt(await fallbackPlace("agentic", NEW_AGENT_TOOLS)) ?? [];
|
|
3773
3883
|
// A grant never lifts a deny the owner set on this server: that tool keeps it, and the answer says so.
|
|
3774
3884
|
const server = settings.get();
|
|
3775
3885
|
const denied = grants.filter((tool) => { const set = permissionFrom(tool, server); return set.from === "server" && set.permission === "deny"; });
|
|
@@ -3789,13 +3899,18 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3789
3899
|
// agent has by its name is left as it is, never removed. One left on still fires, so its skip says so and how to stop it.
|
|
3790
3900
|
const hooked = options.launchHook !== undefined;
|
|
3791
3901
|
const hostless = new Map(made.triggers.flatMap((trigger, i) => {
|
|
3792
|
-
const
|
|
3902
|
+
const apiOnlySkip = options.apiOnly ? apiOnlyTriggerSkipped(pkg.name, trigger, hooked) : undefined;
|
|
3903
|
+
const skip = apiOnlySkip ?? runKeysTriggerSkipped(pkg.name, trigger, brought, hooked);
|
|
3793
3904
|
if (!skip)
|
|
3794
3905
|
return [];
|
|
3795
3906
|
const keptOn = had.find((row) => row.enabled && row.name === String(trigger.name).trim());
|
|
3796
|
-
//
|
|
3797
|
-
|
|
3798
|
-
|
|
3907
|
+
// Under the run-keys setting the kept one's firings bring no keys. One that starts a run of this revision is refused
|
|
3908
|
+
// for the keys it owes, but the kept trigger's target is not checked here: a message_run trigger whose run is pinned
|
|
3909
|
+
// to an earlier revision that owes no keys still messages it, and that run may spend. So the warning promises no refusal.
|
|
3910
|
+
const kept = apiOnlySkip
|
|
3911
|
+
? `is kept as it was, and still fires: PATCH /v2/triggers/${keptOn?.id} with {"enabled": false} turns it off`
|
|
3912
|
+
: `is kept as it was and still fires until you turn it off (PATCH /v2/triggers/${keptOn?.id} with {"enabled": false}): a firing that would start a run of this revision is refused 409 for the keys it owes, but one aimed at a run of an earlier revision that owes none still reaches that run, which may spend`;
|
|
3913
|
+
return [[i, keptOn ? { ...skip, message: `${skip.message} The agent's trigger ${keptOn.id} of that name ${kept}.` } : skip]];
|
|
3799
3914
|
}));
|
|
3800
3915
|
const unmade = (i) => emptyFeeds.has(i) || hostless.has(i);
|
|
3801
3916
|
const refusedTriggers = madeTriggerIssues(made.triggers, options.triggerClock?.now() ?? Date.now(), pkg.inputSchema).filter((issue) => !unmade(Number(/^triggers\.(\d+)\./.exec(issue.field)?.[1])));
|
|
@@ -4982,12 +5097,13 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4982
5097
|
if (found.name === "getCapabilities") {
|
|
4983
5098
|
// features.computers: the computer kinds this server offers now (computers.ts), read at each answer, since turning
|
|
4984
5099
|
// Archil on or off, or saving a key, changes them. So does a shell on the runner (bash on Archil's serverless exec
|
|
4985
|
-
// in Mode 2): where there is one, the document is made again with it (cheap), its tools available with no box
|
|
4986
|
-
|
|
5100
|
+
// in Mode 2): where there is one, the document is made again with it (cheap), its tools available with no box; and
|
|
5101
|
+
// so does a Mode 2 region with no exec, where there is none and Docker's box is no default (runnerShellNow).
|
|
5102
|
+
const runner = await runnerShellNow();
|
|
4987
5103
|
await planNow();
|
|
4988
5104
|
await ollamaNow();
|
|
4989
5105
|
await loginNow();
|
|
4990
|
-
const answer = forCaller(
|
|
5106
|
+
const answer = forCaller(runner !== false ? compose(runner) : caps, byOwnerSession(req));
|
|
4991
5107
|
// features.triggers.public_url: whether Composio (or any sender) has a public address to reach, never the address.
|
|
4992
5108
|
// runner_refused: why no runner here can take a run, in their words, while every runner there refused to claim
|
|
4993
5109
|
// (runner/presence.ts); null while one can, or none is there yet.
|
|
@@ -5649,9 +5765,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5649
5765
|
// the archive, each turned on again by PATCH /triggers/{id} {enabled: true}.
|
|
5650
5766
|
// In the agent's delete turn (agentWrite): an unarchive sent while its purge runs waits for it and is 410, so no
|
|
5651
5767
|
// run of it starts between the purge's live check and its tombstone.
|
|
5652
|
-
// On an API-only server with the launch hook
|
|
5653
|
-
//
|
|
5654
|
-
const turnOn = options.apiOnly && options.launchHook ? (
|
|
5768
|
+
// On an API-only server with the launch hook the unarchive turns its schedule and feed triggers on again (the ones
|
|
5769
|
+
// its apply makes there), so a backend's redeploy needs no PATCH of each.
|
|
5770
|
+
const turnOn = options.apiOnly && options.launchHook ? (trigger) => apiOnlyTurnsOn(trigger.source.kind, trigger.target.kind, true) : undefined;
|
|
5655
5771
|
const triggersOff = await agentWrite(id, () => (found.name === "archiveAgent" ? triggers.agentArchived(id) : triggers.agentUnarchived(id, turnOn)));
|
|
5656
5772
|
// An archived agent's own computer is deleted (an unarchived one gets a new one at its next persistent run).
|
|
5657
5773
|
if (found.name === "archiveAgent")
|
|
@@ -6204,7 +6320,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6204
6320
|
if (!read)
|
|
6205
6321
|
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 });
|
|
6206
6322
|
const analytics = await analyticsOverStore(store, { from: new Date(year, 0, 1).toISOString(), to: new Date(year + 1, 0, 1).toISOString() });
|
|
6207
|
-
return send(res, 200, wrappedView(read.wrapped, analytics.bySource.filter((g) => g.source !== "live").map((g) => ({ source: g.source, runs: g.runs })), read.unread));
|
|
6323
|
+
return send(res, 200, wrappedView(read.wrapped, analytics.bySource.filter((g) => g.source !== "live").map((g) => ({ source: g.source, runs: g.runs })), read.unread, analytics.cache));
|
|
6208
6324
|
}
|
|
6209
6325
|
case "getStats": {
|
|
6210
6326
|
const filter = analyticsFilter(url);
|
|
@@ -6351,6 +6467,11 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6351
6467
|
const answer = await modelGatewayRoute({ store, sealKey: seal.key, env: own(withSecrets(base, "own")), changed: gatewayChanged }, found.name, { ...(body !== undefined ? { body } : {}), signal: stopping.signal });
|
|
6352
6468
|
return send(res, 200, answer, { "cache-control": "no-store" });
|
|
6353
6469
|
}
|
|
6470
|
+
// A free local model (local-model.ts): never through `idempotent`, as a pull is one at a time and says so itself.
|
|
6471
|
+
case "getLocalModel":
|
|
6472
|
+
return send(res, 200, await localModelView(localModelDeps()), { "cache-control": "no-store" });
|
|
6473
|
+
case "pullLocalModel":
|
|
6474
|
+
return send(res, 202, await pullLocalModel(localModelDeps(), await bodyOf(req)), { "cache-control": "no-store" });
|
|
6354
6475
|
// Never through `idempotent`: its record keeps the body, and a body may hold a credential.
|
|
6355
6476
|
case "listMcpServers":
|
|
6356
6477
|
return send(res, 200, await mcpServers.list());
|
|
@@ -6561,7 +6682,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6561
6682
|
const records = await promotionsOf(store.learning, id);
|
|
6562
6683
|
const costStop = await costStopOverStore(store, id);
|
|
6563
6684
|
const body = entry.revision?.body;
|
|
6564
|
-
const modelEnv = !body || sdkOf(body) || nativeOf(body) ? env : envAtPlace(env, resolvePlace(body.place, fallbackPlace(entry.revision.kind === "workflow" ? "workflow" : "agentic", body.tools ?? [])));
|
|
6685
|
+
const modelEnv = !body || sdkOf(body) || nativeOf(body) ? env : envAtPlace(env, resolvePlace(body.place, await fallbackPlace(entry.revision.kind === "workflow" ? "workflow" : "agentic", body.tools ?? [])));
|
|
6565
6686
|
return send(res, 200, { ...await agentLearning(store, id, await learningShown(id), counts, impact, (workflow) => servingStateOf(records, workflow, costStop)), learning_model: await learningModelOf(modelEnv, entry.revision) });
|
|
6566
6687
|
}
|
|
6567
6688
|
case "getLearningCost": {
|
|
@@ -6873,9 +6994,18 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6873
6994
|
return send(res, 200, triggerRotated(id, (await triggers.rotate(id)).secret, new Date().toISOString()));
|
|
6874
6995
|
case "getTrigger":
|
|
6875
6996
|
return send(res, 200, withSecretOf(await triggers.get(id)));
|
|
6876
|
-
case "updateTrigger":
|
|
6997
|
+
case "updateTrigger": {
|
|
6998
|
+
const body = await bodyOf(req);
|
|
6999
|
+
// On an API-only server, `enabled` alone, and on only where its apply would make the trigger (api-only.ts).
|
|
7000
|
+
if (options.apiOnly) {
|
|
7001
|
+
const trigger = await triggers.get(id);
|
|
7002
|
+
const refused = apiOnlyTriggerEdit(body, trigger.source.kind, options.launchHook !== undefined, trigger.target.kind);
|
|
7003
|
+
if (refused.length)
|
|
7004
|
+
throw invalid(refused);
|
|
7005
|
+
}
|
|
6877
7006
|
// Its secret's metadata as a read answers it, so a page showing the changed trigger keeps saying it is set.
|
|
6878
|
-
return send(res, 200, withSecretOf(await triggers.update(id,
|
|
7007
|
+
return send(res, 200, withSecretOf(await triggers.update(id, body)));
|
|
7008
|
+
}
|
|
6879
7009
|
case "deleteTrigger": {
|
|
6880
7010
|
// Deleted here whatever its sender says; what could not be removed there is answered (Composio's instance).
|
|
6881
7011
|
const said = await triggers.remove(id);
|
|
@@ -7037,6 +7167,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
7037
7167
|
}
|
|
7038
7168
|
// Routed on the path as sent: a parsed URL folds `..` and `%2E%2E` segments away, and a file path must see them.
|
|
7039
7169
|
const raw = (req.url ?? "/").split("?")[0];
|
|
7170
|
+
// The share host (share-host.ts): /r/ alone, before the page, the owner's routes, the MCP endpoint, the token-less
|
|
7171
|
+
// hooks or the token check read anything of the request; every other address is its 404.
|
|
7172
|
+
if (shareRoute)
|
|
7173
|
+
return void shareRoute(req, res, raw).catch(fail);
|
|
7040
7174
|
// API-only (api-only.ts): any address but the run routes is refused here, before the page, the owner's routes, the
|
|
7041
7175
|
// MCP endpoint, the token-less hooks or the token check read anything of the request.
|
|
7042
7176
|
if (options.apiOnly && !servedApiOnly(ROUTES, req.method, raw, apiOnlyMcpOrigins.length > 0))
|
|
@@ -7078,6 +7212,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
7078
7212
|
// away. Its name alone, on any port, as the HTTP routes check it.
|
|
7079
7213
|
if (names && !names.has(hostName(req.headers.host) ?? ""))
|
|
7080
7214
|
return deny("403 Forbidden");
|
|
7215
|
+
// A share host takes no upgrade: it has no live view, computer or paired machine.
|
|
7216
|
+
if (options.shareHost)
|
|
7217
|
+
return deny("404 Not Found");
|
|
7081
7218
|
// API-only: paired computers are the console's (Settings), and refused with it, whose tokens the attach socket takes as
|
|
7082
7219
|
// unknown there (machinesOnly). A run's hosted machine that dials still reaches it, and a run's computer live view takes
|
|
7083
7220
|
// its viewer credential (below); a browser's live view stays the console's.
|
|
@@ -7475,7 +7612,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
7475
7612
|
if (!closing && (letGo(row) || stopRow(row)) && !(await tellWait(row).catch((error) => (sayUnread(row.id, error.message), false))))
|
|
7476
7613
|
waitsLeft.add(row.id);
|
|
7477
7614
|
};
|
|
7478
|
-
|
|
7615
|
+
// Nor does a share host follow the runs' changes: it tells no one of a run's end or wait.
|
|
7616
|
+
if (!options.shareHost)
|
|
7617
|
+
followChanges();
|
|
7479
7618
|
const setupUrl = owner && !owner.hasPassword() ? owner.setupLink() : undefined;
|
|
7480
7619
|
/** The server's stop: once (`close` keeps its promise). */
|
|
7481
7620
|
let stopped;
|
|
@@ -7564,7 +7703,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
7564
7703
|
tokenMade: stored?.made ?? false,
|
|
7565
7704
|
...(setupUrl ? { setupUrl, setupOpen: openSetup } : {}),
|
|
7566
7705
|
...(consoleSessions ? { launchCode: consoleSessions.code } : {}),
|
|
7567
|
-
boxesLine: boxesLine(boxOffers, enabledBoxes(env), boxAllow, boxesByDefault(env),
|
|
7706
|
+
boxesLine: boxesLine(boxOffers, enabledBoxes(env), boxAllow, boxesByDefault(env), await runnerShellNow()),
|
|
7568
7707
|
attachHub,
|
|
7569
7708
|
beside,
|
|
7570
7709
|
dial: { ...(options.publicUrl ? { url: options.publicUrl.replace(/\/+$/, "") } : {}), tokens: attach.machineTokens, hub: attachHub },
|