@parcha/agentrun-serve 0.1.0-beta.61 → 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 +66 -0
- package/README.md +102 -13
- package/dist/api-only.d.ts +4 -0
- package/dist/api-only.js +5 -1
- 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/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 +19 -8
- 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-C9ffXUR5.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-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/harness-table.d.ts +7 -0
- package/dist/harness-table.js +6 -3
- package/dist/import.d.ts +8 -1
- package/dist/import.js +36 -5
- package/dist/key-check.js +22 -8
- package/dist/learned-nodes.d.ts +2 -1
- package/dist/learned-nodes.js +2 -1
- package/dist/mcp-gateway.d.ts +24 -0
- package/dist/mcp-gateway.js +97 -8
- 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 +10 -3
- package/dist/ollama-provider.js +17 -7
- package/dist/openapi.js +29 -12
- 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 +25 -9
- package/dist/place.js +37 -11
- package/dist/print.d.ts +3 -2
- package/dist/print.js +8 -6
- 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/runnable.d.ts +6 -3
- package/dist/runnable.js +16 -6
- package/dist/runner/adapter-loop.js +64 -25
- package/dist/runner/adapter-run-spec.d.ts +6 -1
- package/dist/runner/adapter-run-spec.js +14 -11
- package/dist/runner/adapters/index.d.ts +4 -0
- package/dist/runner/adapters/index.js +2 -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 +12 -8
- package/dist/runner/dispatch.js +2 -0
- package/dist/runner/harness-loops.d.ts +5 -0
- package/dist/runner/harness-loops.js +4 -1
- package/dist/runner/live-ticker.js +3 -1
- package/dist/runner/loop-contract.d.ts +4 -1
- package/dist/runner/mcp-run.d.ts +5 -0
- package/dist/runner/mcp-run.js +18 -0
- package/dist/runner/meta-tools.js +4 -4
- package/dist/runner/metrics.d.ts +4 -2
- package/dist/runner/metrics.js +5 -3
- package/dist/runner/native-loop.js +2 -2
- 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/workflow-calls.d.ts +4 -3
- package/dist/runner/workflow-calls.js +41 -12
- package/dist/runner/workflow-spec.js +1 -1
- package/dist/secret-rules.d.ts +0 -1
- package/dist/secret-rules.js +25 -5
- package/dist/server.d.ts +10 -1
- package/dist/server.js +114 -38
- package/dist/share-host.d.ts +111 -0
- package/dist/share-host.js +666 -0
- package/dist/store-reads/analytics.d.ts +15 -0
- package/dist/store-reads/analytics.js +17 -0
- 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 +1 -0
- package/dist/tool-plane.js +6 -2
- package/dist/trigger-composio.js +1 -1
- 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-BnZV3lvW.js +0 -639
- package/dist/console/assets/share-B1o5mJ56.js +0 -6
- /package/dist/console/assets/{styles-D_znYrHR.js → styles-BGZxYkky.js} +0 -0
package/dist/server.js
CHANGED
|
@@ -32,7 +32,7 @@ import { chmod, lstat, mkdir, readFile, realpath, rename, stat, writeFile } from
|
|
|
32
32
|
import { createServer } from "node:http";
|
|
33
33
|
import proxyaddr from "proxy-addr";
|
|
34
34
|
import { apiOnlyMcpSave, apiOnlyRefusal, apiOnlyTriggerEdit, apiOnlyTriggerSkipped, apiOnlyTurnsOn, servedApiOnly } from "./api-only.js";
|
|
35
|
-
import { API_ONLY_MCP_ORIGINS_ENV, apiOnlyMcpOriginsFrom, RUN_KEYS_ENV } from "./env-switch.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";
|
|
@@ -234,7 +235,7 @@ import { noAccount, openAccount } from "./email/account.js";
|
|
|
234
235
|
import { emailRoute } from "./email/routes.js";
|
|
235
236
|
import { addressForms, openCalendar } from "./calendar/address.js";
|
|
236
237
|
import { calendarRoute } from "./calendar/routes.js";
|
|
237
|
-
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";
|
|
238
239
|
import { computerOfPlace, settingOfDefinition } from "./computer-setting.js";
|
|
239
240
|
import { computerCapabilities, createComputerRoutes, folderModeOf, hostCommandRefusals, settingsComputerRoute } from "./computers.js";
|
|
240
241
|
import { runningComputers } from "./computers-running.js";
|
|
@@ -728,16 +729,20 @@ export function forCaller(caps, ownerSession) {
|
|
|
728
729
|
}
|
|
729
730
|
/** The capabilities document from offers already resolved, under the server's learning switch, tool settings and box
|
|
730
731
|
* offers: cheap, made again after each key or tool-settings write with the offers the server holds; and `needs` as
|
|
731
|
-
* needsOf says it for a revision that names no model (null when it runs). `
|
|
732
|
-
*
|
|
733
|
-
*
|
|
734
|
-
|
|
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));
|
|
735
740
|
const models = { ...modelSource(env), ready: needs === null, needs, priced };
|
|
736
741
|
// Both limits apply: the cap on the count, and the memory each run reserves (host.ts).
|
|
737
742
|
const memory = hostMemory();
|
|
738
743
|
// The browser's key is its vendor's row: Kernel's where Kernel is picked or resolved (tool-plane.ts browserKeyRow).
|
|
739
744
|
const keyFor = (tool) => (tool.name === "browser" ? browserKeyRow(tool.provider, tool.resolves?.[DEFAULT_HARNESS]) : keyOf(tool.name));
|
|
740
|
-
const tools = toolsView(env, toolSettings,
|
|
745
|
+
const tools = toolsView(env, toolSettings, noBox, refused, runnerShell).map((tool) => (keyFor(tool) ? { ...tool, key: keyFor(tool) } : tool));
|
|
741
746
|
const browser = tools.find((tool) => tool.name === "browser");
|
|
742
747
|
return {
|
|
743
748
|
backend: "local",
|
|
@@ -757,7 +762,7 @@ function capabilitiesWith(env, maxRuns, harnesses, learning, { needs, priced, le
|
|
|
757
762
|
harnesses: harnesses.map(({ keys: _keys, noModelRuns, ...offer }) => ({ ...offer, available: offer.available && !noModelRuns, max_concurrent_runs: Math.min(maxRuns, runsThatFit(offer.id, memory, env)) })),
|
|
758
763
|
/** The places a revision may name (`definition.place`), this host's default (null where a new agent must name one),
|
|
759
764
|
* and whether this server has each box. */
|
|
760
|
-
places: placesOf(boxes, boxAllowOf(env),
|
|
765
|
+
places: placesOf(boxes, boxAllowOf(env), runner),
|
|
761
766
|
models,
|
|
762
767
|
learning_model,
|
|
763
768
|
/** `pending`: a workflow draft with a call no price covers is kept to wait for its owner's OK, served to no run;
|
|
@@ -942,6 +947,14 @@ export async function startServe(options) {
|
|
|
942
947
|
// API-only: no console, so no owner to sign in to it (and no setup code printed for a page that is refused).
|
|
943
948
|
if (options.apiOnly)
|
|
944
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
|
+
}
|
|
945
958
|
// A harness table module is the server's to name, from `harnessTable` alone, for itself and its runs: one in its own
|
|
946
959
|
// environment (an operator's export, a leftover) never loads, wherever the server reads its environment.
|
|
947
960
|
delete process.env[HARNESS_TABLE_ENV];
|
|
@@ -1359,7 +1372,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1359
1372
|
// The start-time switches as this server was started: its options, else the CLI's variables. mcpLoopback is the
|
|
1360
1373
|
// option alone, as everywhere it is read here (localInstall): the CLI sets it from AGENTRUN_MCP_ALLOW_LOOPBACK.
|
|
1361
1374
|
const switched = { mcpLoopback: options.mcpLoopback === true, webhookPrivateTargets: switchedOnBy(process.env, options).webhookPrivateTargets, apiOnlyMcpOrigins };
|
|
1362
|
-
const compose = (
|
|
1375
|
+
const compose = (runner = false) => askNeeds(capabilitiesWith(env, maxRuns, offers, learning, needs, settings.get(), boxOffers, toolKeys.refused(), runner, isolation, switched));
|
|
1363
1376
|
const recompose = () => void (caps = compose());
|
|
1364
1377
|
// What the offers held now were made from (offersInputs), and the latest probe: one a later probe overtook is dropped.
|
|
1365
1378
|
let offersFrom;
|
|
@@ -1612,8 +1625,12 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1612
1625
|
for (let round = 1;; round++) {
|
|
1613
1626
|
const n = await refreshOnce();
|
|
1614
1627
|
const latest = () => handed.n === n && !handed.failed;
|
|
1615
|
-
|
|
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();
|
|
1616
1632
|
await offersNow();
|
|
1633
|
+
}
|
|
1617
1634
|
if (latest() && offersMadeFrom(offersInputs(env)))
|
|
1618
1635
|
return;
|
|
1619
1636
|
if (round >= LOGIN_ROUNDS)
|
|
@@ -1742,7 +1759,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1742
1759
|
const computersOf = () => (computerRoutes ??= createComputerRoutes({
|
|
1743
1760
|
// A provider's key set where the server starts is one of its secrets, held off process.env (secrets.ts): read by name
|
|
1744
1761
|
// from what the server was started with, as computerReady below reads it.
|
|
1745
|
-
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"),
|
|
1746
1763
|
// Each with its route (who holds it, on which runner, and why a route was refused), and online while relayed.
|
|
1747
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) },
|
|
1748
1765
|
runnerApart: options.runnerApart === true,
|
|
@@ -1769,6 +1786,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1769
1786
|
* provider's program is on this machine is hostWhy's, read at the start. */
|
|
1770
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. */
|
|
1771
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));
|
|
1772
1792
|
/** The registry a run's claim resolves against (claimKinds), as its runner composes it. */
|
|
1773
1793
|
const claimRegistry = () => claimKinds(options.faux ? { faux: fauxOf() } : {});
|
|
1774
1794
|
/** A key as the runner reads it: the secrets this process was started with (withSecrets "own"), else the saved one. */
|
|
@@ -1785,18 +1805,32 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1785
1805
|
};
|
|
1786
1806
|
/** Where a run of an agent with computer `setting` has its shell here now (resolve-computer.ts runShellOf, in the
|
|
1787
1807
|
* folder mode of now, over the registry the claim reads): what runnable.ts lets a sandbox-only tool on the runner by,
|
|
1788
|
-
* and capabilities show bash by. In Mode 2 a run with no computer has bash on Archil's serverless exec
|
|
1789
|
-
|
|
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
|
+
};
|
|
1790
1820
|
/** The shell this server can give a template's agent now (templates.ts pickComputer's `shell`), by the rules a run
|
|
1791
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
|
|
1792
1822
|
* with (Docker), where it answers now (computerReady asks the daemon, not the start's offers: a Docker stopped since
|
|
1793
1823
|
* is no shell), whose shell runs the shell tools; else none, and why. A package that needs programs (`sandbox`) asks
|
|
1794
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
|
|
1795
|
-
* 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. */
|
|
1796
1827
|
const shellHere = async (wants = {}) => {
|
|
1797
1828
|
const exec = (await shellOf({ kind: "none" })) === "local";
|
|
1798
1829
|
if (exec && !wants.sandbox)
|
|
1799
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." };
|
|
1800
1834
|
const fresh = newAgentPlace(boxOffers);
|
|
1801
1835
|
let why = "why" in fresh ? fresh.why : "it is not set up";
|
|
1802
1836
|
if ("place" in fresh && fresh.place.mode === "sandbox") {
|
|
@@ -1916,7 +1950,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1916
1950
|
});
|
|
1917
1951
|
// The outbound webhook's secret, as it stands (set by a PUT, gone with a DELETE), and each it held before.
|
|
1918
1952
|
stops.push(() => webhooks.close());
|
|
1919
|
-
|
|
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());
|
|
1920
1957
|
// Where an earlier version kept the webhook: no longer read.
|
|
1921
1958
|
if (existsSync(join(data, WEBHOOK_FILE)))
|
|
1922
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" }));
|
|
@@ -1932,7 +1969,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1932
1969
|
serverSecrets: () => serverSecrets(),
|
|
1933
1970
|
});
|
|
1934
1971
|
stops.push(() => slack.close());
|
|
1935
|
-
await slack.load();
|
|
1972
|
+
await (options.shareHost ? slack.readSecrets() : slack.load());
|
|
1936
1973
|
secretStores.add("slack", () => slack.urlForms());
|
|
1937
1974
|
const uploads = new Uploads(join(data, UPLOADS_DIR));
|
|
1938
1975
|
// Under the data directory's lock and before this server answers anything, so no PUT of its own is in flight: an upload
|
|
@@ -2098,8 +2135,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2098
2135
|
}).finally(() => { localSourceBusy = false; });
|
|
2099
2136
|
return localSourceSweep;
|
|
2100
2137
|
};
|
|
2101
|
-
|
|
2102
|
-
|
|
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();
|
|
2103
2142
|
// As close() does: aborted first, so a sync in flight stops instead of being waited out.
|
|
2104
2143
|
stops.unshift(async () => {
|
|
2105
2144
|
stopping.abort();
|
|
@@ -2219,6 +2258,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2219
2258
|
context: ctx,
|
|
2220
2259
|
sealKey,
|
|
2221
2260
|
liveViewer: (runId) => liveViewerLink(store, sealKey, runId, answers(runId)),
|
|
2261
|
+
...(options.cutMs !== undefined ? { cutMs: options.cutMs } : {}),
|
|
2222
2262
|
};
|
|
2223
2263
|
// The run timeline reader over the store (run-reads-over-store runTimelines): one change-numbered RowLog per run, synced
|
|
2224
2264
|
// from its journal (store-reads) on each read, its view (viewOverStore) for status/state/cost and whether it is final.
|
|
@@ -2297,6 +2337,19 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2297
2337
|
keyUsed.set(req, key);
|
|
2298
2338
|
return started || key !== undefined;
|
|
2299
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;
|
|
2300
2353
|
// Answered keys are kept in the data directory for the retention capabilities state, and written before the answer
|
|
2301
2354
|
// is sent, so a client that retries after a restart gets the first answer back.
|
|
2302
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:
|
|
@@ -2369,6 +2422,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2369
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)
|
|
2370
2423
|
// is launched: each launch hands over what is saved then. One server in a process reads them: the last started.
|
|
2371
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();
|
|
2372
2429
|
// Under faux, a key the server starts with is checked only against a check's own fake (fauxBrowserbase,
|
|
2373
2430
|
// fauxMonidCheck, fauxKernel): the fakes the runs use (monid, Parallel, Jev) see the runs' calls alone, and a key with no check fake
|
|
2374
2431
|
// is not checked.
|
|
@@ -2651,10 +2708,14 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2651
2708
|
stops.push(async () => triggers.close());
|
|
2652
2709
|
// The firing loop runs against the server's own opened store: due firings start their runs through the run write half,
|
|
2653
2710
|
// times missed while it was down are recorded, and the timer is armed for the next. (A test may inject its own store.)
|
|
2654
|
-
|
|
2655
|
-
//
|
|
2656
|
-
|
|
2657
|
-
|
|
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
|
+
}
|
|
2658
2719
|
// Setup's import of this machine's sessions: offered by a server on this machine only (no public address, listening
|
|
2659
2720
|
// on loopback), counted once (a listing, no transcript kept), run once, each on a worker thread (import-worker.ts) so
|
|
2660
2721
|
// a busy store's wait and the sessions' parsing never hold up a request.
|
|
@@ -3319,7 +3380,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3319
3380
|
if (owed.length)
|
|
3320
3381
|
throw keysOwedRefusal(owed);
|
|
3321
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.
|
|
3322
|
-
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 });
|
|
3323
3384
|
if (!blockers.length)
|
|
3324
3385
|
return;
|
|
3325
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
|
|
@@ -3354,8 +3415,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3354
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 } });
|
|
3355
3416
|
}
|
|
3356
3417
|
/** Where a revision of `kind` naming `tools` and no place runs here: the place a new agent would be saved with, in the
|
|
3357
|
-
* folder mode of now (Mode 2
|
|
3358
|
-
|
|
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());
|
|
3359
3421
|
/** What a save of `revision` pins of the MCP tools it grants (an agentic revision's: a workflow's nodes bind none): each
|
|
3360
3422
|
* granted server listed once, now, with its saved credential (McpServersOverStore.pinListing), as `tools` each server's
|
|
3361
3423
|
* listing in the harnesses' shape for the save's checks (blockersOf's `mcp`), and `pin` making the pin from them. A server
|
|
@@ -3468,14 +3530,14 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3468
3530
|
const listing = await mcpListingOf(revision, previous?.mcpPin);
|
|
3469
3531
|
const mcp = listing.tools;
|
|
3470
3532
|
const { monid, warnings: usage = [] } = (await monidPinOf(revision, previous)) ?? {};
|
|
3471
|
-
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 });
|
|
3472
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
|
|
3473
3535
|
// alone keeps from running under the definition's own picks, whatever this host's settings, would keep every such run
|
|
3474
3536
|
// from running, so the save is refused, not each run (claude-agent's or codex's own search, picked, under a cap).
|
|
3475
3537
|
if ((body.maxCostUsd ?? 0) > 0) {
|
|
3476
3538
|
const key = (b) => `${b.field}\n${b.message}`;
|
|
3477
|
-
const plain = new Set((await blockersOf(env, shape, {}, { boxes: boxOffers, computerReady, shellOf, offers, mcp, monid })).map(key));
|
|
3478
|
-
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 });
|
|
3479
3541
|
// A model with no price (`unpriced`) is a setting this host fixes (AGENT_MODEL_PRICE): a warning, as it is; the
|
|
3480
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
|
|
3481
3543
|
// one more step and an answer (`short`): the agent saves, and its runs wrap up at their first tool call. A tool's
|
|
@@ -3500,14 +3562,17 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3500
3562
|
* (planTemplate) both make, so a plan never says a create the apply refuses: an agentic revision that names no place
|
|
3501
3563
|
* and would be given Docker's box (no tools named, `toolsUnnamed`, or a shell tool), where this server has none and the
|
|
3502
3564
|
* runner has no shell (Mode 1), is refused, naming a box or the runner, never given another box (place.ts
|
|
3503
|
-
* 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. */
|
|
3504
3569
|
async function noPlaceOf(revision, toolsUnnamed) {
|
|
3505
3570
|
const body = revision.body;
|
|
3506
3571
|
if (revision.kind !== "agentic" || nativeOf(body) || cliLearningOf(body) || sdkOf(body))
|
|
3507
3572
|
return undefined;
|
|
3508
3573
|
if (body.place !== undefined || body.computer !== undefined)
|
|
3509
3574
|
return undefined;
|
|
3510
|
-
return noBoxRefusal(toolsUnnamed ? undefined : body.tools ?? [], boxOffers, toolOf,
|
|
3575
|
+
return noBoxRefusal(toolsUnnamed ? undefined : body.tools ?? [], boxOffers, toolOf, await runnerShellNow());
|
|
3511
3576
|
}
|
|
3512
3577
|
/** An agentic `revision`'s monid pin (monid.ts pinMonid) and a warning per endpoint priced by usage; a grant that
|
|
3513
3578
|
* cannot be pinned refuses the save (422). Undefined when it grants none. */
|
|
@@ -3834,14 +3899,15 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3834
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.
|
|
3835
3900
|
const hooked = options.launchHook !== undefined;
|
|
3836
3901
|
const hostless = new Map(made.triggers.flatMap((trigger, i) => {
|
|
3837
|
-
const
|
|
3902
|
+
const apiOnlySkip = options.apiOnly ? apiOnlyTriggerSkipped(pkg.name, trigger, hooked) : undefined;
|
|
3903
|
+
const skip = apiOnlySkip ?? runKeysTriggerSkipped(pkg.name, trigger, brought, hooked);
|
|
3838
3904
|
if (!skip)
|
|
3839
3905
|
return [];
|
|
3840
3906
|
const keptOn = had.find((row) => row.enabled && row.name === String(trigger.name).trim());
|
|
3841
3907
|
// Under the run-keys setting the kept one's firings bring no keys. One that starts a run of this revision is refused
|
|
3842
3908
|
// for the keys it owes, but the kept trigger's target is not checked here: a message_run trigger whose run is pinned
|
|
3843
3909
|
// to an earlier revision that owes no keys still messages it, and that run may spend. So the warning promises no refusal.
|
|
3844
|
-
const kept =
|
|
3910
|
+
const kept = apiOnlySkip
|
|
3845
3911
|
? `is kept as it was, and still fires: PATCH /v2/triggers/${keptOn?.id} with {"enabled": false} turns it off`
|
|
3846
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`;
|
|
3847
3913
|
return [[i, keptOn ? { ...skip, message: `${skip.message} The agent's trigger ${keptOn.id} of that name ${kept}.` } : skip]];
|
|
@@ -5031,12 +5097,13 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5031
5097
|
if (found.name === "getCapabilities") {
|
|
5032
5098
|
// features.computers: the computer kinds this server offers now (computers.ts), read at each answer, since turning
|
|
5033
5099
|
// Archil on or off, or saving a key, changes them. So does a shell on the runner (bash on Archil's serverless exec
|
|
5034
|
-
// in Mode 2): where there is one, the document is made again with it (cheap), its tools available with no box
|
|
5035
|
-
|
|
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();
|
|
5036
5103
|
await planNow();
|
|
5037
5104
|
await ollamaNow();
|
|
5038
5105
|
await loginNow();
|
|
5039
|
-
const answer = forCaller(
|
|
5106
|
+
const answer = forCaller(runner !== false ? compose(runner) : caps, byOwnerSession(req));
|
|
5040
5107
|
// features.triggers.public_url: whether Composio (or any sender) has a public address to reach, never the address.
|
|
5041
5108
|
// runner_refused: why no runner here can take a run, in their words, while every runner there refused to claim
|
|
5042
5109
|
// (runner/presence.ts); null while one can, or none is there yet.
|
|
@@ -6253,7 +6320,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6253
6320
|
if (!read)
|
|
6254
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 });
|
|
6255
6322
|
const analytics = await analyticsOverStore(store, { from: new Date(year, 0, 1).toISOString(), to: new Date(year + 1, 0, 1).toISOString() });
|
|
6256
|
-
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));
|
|
6257
6324
|
}
|
|
6258
6325
|
case "getStats": {
|
|
6259
6326
|
const filter = analyticsFilter(url);
|
|
@@ -7100,6 +7167,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
7100
7167
|
}
|
|
7101
7168
|
// Routed on the path as sent: a parsed URL folds `..` and `%2E%2E` segments away, and a file path must see them.
|
|
7102
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);
|
|
7103
7174
|
// API-only (api-only.ts): any address but the run routes is refused here, before the page, the owner's routes, the
|
|
7104
7175
|
// MCP endpoint, the token-less hooks or the token check read anything of the request.
|
|
7105
7176
|
if (options.apiOnly && !servedApiOnly(ROUTES, req.method, raw, apiOnlyMcpOrigins.length > 0))
|
|
@@ -7141,6 +7212,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
7141
7212
|
// away. Its name alone, on any port, as the HTTP routes check it.
|
|
7142
7213
|
if (names && !names.has(hostName(req.headers.host) ?? ""))
|
|
7143
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");
|
|
7144
7218
|
// API-only: paired computers are the console's (Settings), and refused with it, whose tokens the attach socket takes as
|
|
7145
7219
|
// unknown there (machinesOnly). A run's hosted machine that dials still reaches it, and a run's computer live view takes
|
|
7146
7220
|
// its viewer credential (below); a browser's live view stays the console's.
|
|
@@ -7538,7 +7612,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
7538
7612
|
if (!closing && (letGo(row) || stopRow(row)) && !(await tellWait(row).catch((error) => (sayUnread(row.id, error.message), false))))
|
|
7539
7613
|
waitsLeft.add(row.id);
|
|
7540
7614
|
};
|
|
7541
|
-
|
|
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();
|
|
7542
7618
|
const setupUrl = owner && !owner.hasPassword() ? owner.setupLink() : undefined;
|
|
7543
7619
|
/** The server's stop: once (`close` keeps its promise). */
|
|
7544
7620
|
let stopped;
|
|
@@ -7627,7 +7703,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
7627
7703
|
tokenMade: stored?.made ?? false,
|
|
7628
7704
|
...(setupUrl ? { setupUrl, setupOpen: openSetup } : {}),
|
|
7629
7705
|
...(consoleSessions ? { launchCode: consoleSessions.code } : {}),
|
|
7630
|
-
boxesLine: boxesLine(boxOffers, enabledBoxes(env), boxAllow, boxesByDefault(env),
|
|
7706
|
+
boxesLine: boxesLine(boxOffers, enabledBoxes(env), boxAllow, boxesByDefault(env), await runnerShellNow()),
|
|
7631
7707
|
attachHub,
|
|
7632
7708
|
beside,
|
|
7633
7709
|
dial: { ...(options.publicUrl ? { url: options.publicUrl.replace(/\/+$/, "") } : {}), tokens: attach.machineTokens, hub: attachHub },
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import { type CutScrub } from "./run-export.js";
|
|
3
|
+
export { SHARE_HOST_CSP } from "./page.js";
|
|
4
|
+
/** Where everything a share host serves lives. */
|
|
5
|
+
export declare const SHARE_ROOT = "/r/";
|
|
6
|
+
/** The share host's API. */
|
|
7
|
+
export declare const SHARE_API = "/r/v2/";
|
|
8
|
+
/** The most shares one token keeps: a delete makes room. No share expires. */
|
|
9
|
+
export declare const SHARE_QUOTA = 100;
|
|
10
|
+
/** The most reads one upload's per-string scrub makes, a distinct string once per context it stands under (a file's
|
|
11
|
+
* path, a call's command): each is a scrub of its own (about 0.1 ms), so past it the upload is 413 before any is read.
|
|
12
|
+
* With the body's cap it bounds what one upload asks of the scrubber: the whole body once, and at most this many reads,
|
|
13
|
+
* each of a string with a place of its own in the body, so together no more than the body; each context's command is
|
|
14
|
+
* read once (screenShare). */
|
|
15
|
+
export declare const SHARE_STRINGS = 50000;
|
|
16
|
+
/** The rule ids of Jev's cuts (Scrubber beta 3; "jev" until its id is fixed). A share host never runs Jev (it holds no
|
|
17
|
+
* model key), so a restored record of one names a value the host can't find: it is not checked, and counted in the
|
|
18
|
+
* answer, never refused. The value itself is scrubbed as every other, and a hit there needs its own record. */
|
|
19
|
+
export declare const SHARE_JEV_RULES: ReadonlySet<string>;
|
|
20
|
+
/** The most bytes an upload's body may hold: the export's document cap, and room for nothing else. */
|
|
21
|
+
export declare const SHARE_BODY_BYTES: number;
|
|
22
|
+
/** A share's id: 128 bits of randomness in base32 (lowercase, no padding). The URL is the capability. */
|
|
23
|
+
export declare const SHARE_ID: RegExp;
|
|
24
|
+
/** The share host's API, by method, path and name. Nothing else under /r/v2/ is served. */
|
|
25
|
+
export declare const SHARE_HOST_ROUTES: readonly {
|
|
26
|
+
method: string;
|
|
27
|
+
path: string;
|
|
28
|
+
pattern: RegExp;
|
|
29
|
+
name: string;
|
|
30
|
+
}[];
|
|
31
|
+
/** A new share id: 16 random bytes as 26 base32 letters. */
|
|
32
|
+
export declare function newShareId(): string;
|
|
33
|
+
/** `text` read as a share bundle the host takes, or a 400 that says why (never quoting a value of it): canonical JSON (the
|
|
34
|
+
* bytes the export writes: what is hashed, scanned and stored is one text), `agentrun.share/1`, the export's closed keys
|
|
35
|
+
* at every level it fixes (the run's allowlist, agent, source, files, omitted, cuts, restored; rows and the graph are
|
|
36
|
+
* the served shapes, read by the scrubber whole), its caps on files, each file's size and digest, and the document's
|
|
37
|
+
* sha256. */
|
|
38
|
+
export declare function checkShareBundle(text: string): {
|
|
39
|
+
sha256: string;
|
|
40
|
+
};
|
|
41
|
+
/** The scrubber over a bundle as a host reads it, refusing (422, counts by rule id, never a value or where) unless every
|
|
42
|
+
* value it finds is a declared restore.
|
|
43
|
+
*
|
|
44
|
+
* Strict at its core: the scrubber in cut mode with `held` over the whole body, and again over every string value alone
|
|
45
|
+
* (as the export cut them: each at its pointer, so a value a string's own context gives away is found though its JSON
|
|
46
|
+
* escaping hides it from the whole-body read). A scrub that fails or throws is `scrub_failed`. The one exception is a
|
|
47
|
+
* filter over those hits: a hit of one string is excused when the scrubber's table says its kind restores (label,
|
|
48
|
+
* personal, jev; never format, held or dump) AND one `restored` record names it exactly (at, rule, start, end); a hit of
|
|
49
|
+
* the whole body is excused when it lies in one string and overlaps an excused hit there of its rule. Any hit left is
|
|
50
|
+
* `scrub_found`; a `restored` record that excuses no hit (a stale or edited bundle) is `restored_unmatched`, unless its
|
|
51
|
+
* rule is Jev's (SHARE_JEV_RULES), which the host never runs: that one is counted in `unchecked`, by rule, and taken.
|
|
52
|
+
* The kind a record says is never read. More than `strings` reads (each distinct string once per context it stands
|
|
53
|
+
* under) is 413 before any scrub. The cut text is
|
|
54
|
+
* never used: the host stores what was sent or nothing. */
|
|
55
|
+
export declare function screenShare(text: string, held: readonly string[], cutPass?: CutScrub, strings?: number): Promise<{
|
|
56
|
+
unchecked: Record<string, number>;
|
|
57
|
+
}>;
|
|
58
|
+
/** What the host keeps of a share beside its bytes. `deleted_at` marks one its owner deleted: its bytes are gone, and its
|
|
59
|
+
* page answers 410. */
|
|
60
|
+
export type ShareMeta = {
|
|
61
|
+
id: string;
|
|
62
|
+
sha256: string;
|
|
63
|
+
token_id: string;
|
|
64
|
+
created_at: string;
|
|
65
|
+
bytes: number;
|
|
66
|
+
deleted_at?: string;
|
|
67
|
+
};
|
|
68
|
+
/** The shares of one host, in files under `dir`, written to a temp file and renamed, 0600 in 0700 folders. Kept in
|
|
69
|
+
* memory once read: this process is the folder's one writer. */
|
|
70
|
+
export declare class ShareStore {
|
|
71
|
+
readonly dir: string;
|
|
72
|
+
private index;
|
|
73
|
+
private queue;
|
|
74
|
+
constructor(dir: string);
|
|
75
|
+
private all;
|
|
76
|
+
/** One write at a time: a quota is read and a share made in one step. */
|
|
77
|
+
private serial;
|
|
78
|
+
get(id: string): Promise<ShareMeta | undefined>;
|
|
79
|
+
/** The live shares `tokenId` made, oldest first. */
|
|
80
|
+
list(tokenId: string): Promise<ShareMeta[]>;
|
|
81
|
+
/** A 403 when `tokenId` keeps its quota of shares already. */
|
|
82
|
+
roomFor(tokenId: string, quota: number): Promise<void>;
|
|
83
|
+
/** Stores `body` as a new share of `tokenId`, the quota checked again inside the write. */
|
|
84
|
+
create(tokenId: string, body: string, sha256: string, quota: number): Promise<ShareMeta>;
|
|
85
|
+
/** The stored bytes of live share `id`. */
|
|
86
|
+
bytes(id: string): Promise<Buffer>;
|
|
87
|
+
/** Deletes share `id` of `tokenId`: its bytes go, its meta stays as the tombstone its page's 410 reads. */
|
|
88
|
+
delete(id: string, tokenId: string): Promise<void>;
|
|
89
|
+
}
|
|
90
|
+
export interface ShareHostDeps {
|
|
91
|
+
/** The server's data folder: shares live in its `shares/`. */
|
|
92
|
+
readonly data: string;
|
|
93
|
+
/** The id of the token an Authorization header carries (api-token.ts bearerCheck), else undefined. */
|
|
94
|
+
who(req: IncomingMessage): string | undefined;
|
|
95
|
+
/** A refused credential, for the server's log line. */
|
|
96
|
+
authFailed?(route: string, reason: string): void;
|
|
97
|
+
/** The values this host holds (its own keys and tokens): a bundle that holds one is refused. */
|
|
98
|
+
held(): readonly string[];
|
|
99
|
+
/** The origin a share's URL is on: AGENTRUN_PUBLIC_URL, else the server's own address. Never a request's Host. */
|
|
100
|
+
origin(): string;
|
|
101
|
+
/** The console's build (share.html and its assets); the one beside the server when undefined. */
|
|
102
|
+
console: string | undefined;
|
|
103
|
+
version: string;
|
|
104
|
+
/** The scrubber in cut mode, or a test's stand-in. */
|
|
105
|
+
scrub?: CutScrub;
|
|
106
|
+
quota?: number;
|
|
107
|
+
/** The most distinct strings an upload may hold (SHARE_STRINGS), for a test. */
|
|
108
|
+
strings?: number;
|
|
109
|
+
}
|
|
110
|
+
/** The share host's answer to every request, under /r/ or not: `fail` renders a refusal (server.ts's envelope). */
|
|
111
|
+
export declare function shareHost(deps: ShareHostDeps): (req: IncomingMessage, res: ServerResponse, raw: string) => Promise<void>;
|