@parcha/agentrun-serve 0.1.0-beta.34 → 0.1.0-beta.35
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 +135 -0
- package/README.md +84 -16
- package/dist/adapters.d.ts +3 -0
- package/dist/adapters.js +7 -0
- package/dist/agent-rows.d.ts +1 -0
- package/dist/agents-store.js +17 -2
- package/dist/archil-settings.d.ts +11 -1
- package/dist/archil-settings.js +10 -0
- package/dist/bash-read-only.d.ts +13 -0
- package/dist/bash-read-only.js +77 -0
- package/dist/browser-cost.d.ts +2 -2
- package/dist/browser-cost.js +6 -4
- package/dist/budget.d.ts +0 -5
- package/dist/budget.js +0 -5
- package/dist/cap.d.ts +6 -3
- package/dist/cap.js +7 -4
- package/dist/cli.js +32 -5
- package/dist/computer-keys.d.ts +20 -10
- package/dist/computer-keys.js +36 -57
- package/dist/computer-setting.d.ts +6 -5
- package/dist/computer-setting.js +54 -26
- package/dist/computers.d.ts +9 -4
- package/dist/computers.js +4 -2
- package/dist/console/assets/index-B7NKTU8E.css +1 -0
- package/dist/console/assets/index-CXZMgJE7.js +550 -0
- package/dist/console/index.html +2 -2
- package/dist/content-filter.d.ts +7 -0
- package/dist/content-filter.js +23 -0
- package/dist/decision-cap.d.ts +7 -29
- package/dist/decision-cap.js +3 -94
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +3 -0
- package/dist/explain.js +3 -1
- package/dist/github-connection.js +25 -7
- package/dist/github-faux.d.ts +26 -0
- package/dist/github-faux.js +76 -0
- package/dist/github.d.ts +6 -2
- package/dist/github.js +5 -3
- package/dist/graph-served.d.ts +5 -3
- package/dist/graph-served.js +14 -6
- package/dist/graph-view.js +5 -2
- package/dist/harness-opencode/harness.js +0 -1
- package/dist/harness-opencode/host/policy.js +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/learn/check.d.ts +3 -1
- package/dist/learn/check.js +3 -3
- package/dist/learn/folder.d.ts +6 -3
- package/dist/learn/folder.js +7 -16
- package/dist/learn/grade.d.ts +4 -1
- package/dist/learn/grade.js +43 -5
- package/dist/learn/index.d.ts +2 -2
- package/dist/learn/index.js +2 -2
- package/dist/learn/learning.sh +1 -14
- package/dist/learn/notes.d.ts +14 -3
- package/dist/learn/notes.js +16 -6
- package/dist/learn/reflect.js +5 -3
- package/dist/learn/skills.d.ts +48 -5
- package/dist/learn/skills.js +97 -21
- package/dist/learned-nodes.d.ts +14 -0
- package/dist/learned-nodes.js +8 -0
- package/dist/learned-workflow.d.ts +9 -5
- package/dist/learned-workflow.js +53 -9
- package/dist/learning-routes.d.ts +41 -0
- package/dist/learning-routes.js +94 -26
- package/dist/learning-run.d.ts +7 -5
- package/dist/learning-run.js +9 -6
- package/dist/learning.d.ts +0 -22
- package/dist/learning.js +0 -16
- package/dist/llm.d.ts +4 -1
- package/dist/llm.js +4 -2
- package/dist/mcp-gateway.d.ts +6 -0
- package/dist/mcp-gateway.js +11 -1
- package/dist/mcp-servers-store.d.ts +12 -12
- package/dist/model.d.ts +3 -0
- package/dist/model.js +8 -0
- package/dist/openapi.js +37 -13
- package/dist/paid-calls.js +1 -1
- package/dist/pause.d.ts +2 -19
- package/dist/pause.js +5 -74
- package/dist/port-models.d.ts +10 -3
- package/dist/port-models.js +26 -6
- package/dist/propose.d.ts +2 -0
- package/dist/propose.js +1 -10
- package/dist/run-launch.d.ts +5 -3
- package/dist/run-launch.js +6 -5
- package/dist/run-learning-served.d.ts +11 -0
- package/dist/run-reads-over-store.d.ts +4 -2
- package/dist/run-reads-over-store.js +10 -8
- package/dist/run-timeline-served.js +12 -2
- package/dist/run-view.d.ts +30 -14
- package/dist/run-view.js +60 -32
- package/dist/runnable.d.ts +4 -1
- package/dist/runnable.js +14 -2
- package/dist/runner/adapter-loop.d.ts +30 -4
- package/dist/runner/adapter-loop.js +253 -29
- package/dist/runner/adapter-run-spec.d.ts +21 -0
- package/dist/runner/adapter-run-spec.js +104 -28
- package/dist/runner/adapters/pi.d.ts +29 -1
- package/dist/runner/adapters/pi.js +95 -23
- package/dist/runner/beside.d.ts +8 -0
- package/dist/runner/beside.js +18 -0
- package/dist/runner/claim-secrets.d.ts +6 -0
- package/dist/runner/claim-secrets.js +15 -1
- package/dist/runner/cli-run-spec.d.ts +3 -0
- package/dist/runner/cli-run-spec.js +123 -34
- package/dist/runner/conformance/harness.d.ts +1 -0
- package/dist/runner/conformance/harness.js +5 -5
- package/dist/runner/github-app.d.ts +7 -2
- package/dist/runner/github-app.js +46 -15
- package/dist/runner/harness-loops.d.ts +6 -1
- package/dist/runner/harness-loops.js +23 -0
- package/dist/runner/journal-kinds.d.ts +38 -2
- package/dist/runner/journal-kinds.js +23 -0
- package/dist/runner/learning-end.js +88 -16
- package/dist/runner/learning-loop.d.ts +2 -0
- package/dist/runner/learning-loop.js +13 -5
- package/dist/runner/learning-seed.d.ts +6 -0
- package/dist/runner/learning-seed.js +6 -0
- package/dist/runner/loop-contract.d.ts +4 -0
- package/dist/runner/main.d.ts +9 -4
- package/dist/runner/main.js +26 -11
- package/dist/runner/mcp-claim.d.ts +3 -0
- package/dist/runner/mcp-claim.js +6 -1
- package/dist/runner/mcp-github.d.ts +11 -2
- package/dist/runner/mcp-github.js +55 -4
- package/dist/runner/mcp-run.js +1 -0
- package/dist/runner/metrics.d.ts +14 -1
- package/dist/runner/metrics.js +72 -1
- package/dist/runner/model-route.d.ts +3 -0
- package/dist/runner/model-route.js +1 -1
- package/dist/runner/runner.js +90 -8
- package/dist/runner/spec-holds.d.ts +7 -2
- package/dist/runner/spec-holds.js +4 -3
- package/dist/runner/workflow-host.d.ts +7 -2
- package/dist/runner/workflow-host.js +3 -1
- package/dist/runner/workflow-loop.d.ts +4 -1
- package/dist/runner/workflow-loop.js +8 -2
- package/dist/runner/workflow-spec.d.ts +3 -0
- package/dist/runner/workflow-spec.js +156 -78
- package/dist/runs-over-store.d.ts +7 -1
- package/dist/runs-over-store.js +42 -11
- package/dist/seal-key.d.ts +0 -2
- package/dist/seal-key.js +0 -2
- package/dist/server-lock.js +4 -5
- package/dist/server.d.ts +21 -18
- package/dist/server.js +183 -34
- package/dist/stop-signals.d.ts +4 -2
- package/dist/stop-signals.js +5 -3
- package/dist/store/agent-body.d.ts +5 -1
- package/dist/store/agent-body.js +11 -5
- package/dist/store/deadline.d.ts +18 -0
- package/dist/store/deadline.js +45 -0
- package/dist/store/postgres/connection.d.ts +4 -0
- package/dist/store/postgres/connection.js +55 -9
- package/dist/store/sqlite/connection.js +3 -38
- package/dist/store-reads/journal.js +39 -4
- package/dist/store-reads/learning.d.ts +58 -2
- package/dist/store-reads/learning.js +172 -7
- package/dist/store-view.d.ts +15 -1
- package/dist/store-view.js +45 -12
- package/dist/templates.d.ts +9 -4
- package/dist/templates.js +14 -9
- package/dist/timeline/timeline.d.ts +8 -0
- package/dist/tool-budget.d.ts +18 -0
- package/dist/tool-budget.js +50 -0
- package/dist/tool-gate.d.ts +6 -2
- package/dist/tool-gate.js +8 -5
- package/dist/tool-plane.d.ts +9 -10
- package/dist/tools.d.ts +37 -7
- package/dist/tools.js +73 -12
- package/dist/uploads.d.ts +28 -5
- package/dist/uploads.js +82 -9
- package/dist/usage.d.ts +1 -47
- package/dist/usage.js +3 -82
- package/dist/validate.d.ts +2 -0
- package/dist/validate.js +11 -1
- package/dist/workspace/archil-claim.d.ts +2 -2
- package/dist/workspace/archil-claim.js +4 -3
- package/dist/workspace/archil-disk.d.ts +10 -1
- package/dist/workspace/archil-disk.js +4 -0
- package/dist/workspace/archil-exec.d.ts +12 -2
- package/dist/workspace/archil-exec.js +16 -0
- package/dist/workspace/archil.d.ts +2 -2
- package/dist/workspace/archil.js +25 -5
- package/dist/workspace/attach.js +2 -0
- package/dist/workspace/computer-deps.d.ts +9 -10
- package/dist/workspace/computer-deps.js +53 -40
- package/dist/workspace/computer-for-claim.d.ts +5 -3
- package/dist/workspace/computer-for-claim.js +28 -16
- package/dist/workspace/computer-ledger.d.ts +1 -8
- package/dist/workspace/computer-ledger.js +0 -3
- package/dist/workspace/computer-providers.d.ts +5 -3
- package/dist/workspace/computer-providers.js +11 -9
- package/dist/workspace/hands.d.ts +5 -2
- package/dist/workspace/hands.js +4 -3
- package/dist/workspace/index.d.ts +3 -3
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/local.d.ts +3 -0
- package/dist/workspace/local.js +9 -0
- package/dist/workspace/paths.js +3 -2
- package/dist/workspace/pi-env.d.ts +4 -0
- package/dist/workspace/pi-env.js +3 -2
- package/dist/workspace/resolve-computer.d.ts +8 -3
- package/dist/workspace/resolve-computer.js +28 -11
- package/dist/workspace/run-tools.d.ts +2 -0
- package/dist/workspace/run-tools.js +9 -3
- package/dist/workspace/workspace.d.ts +5 -0
- package/dist/workspace.d.ts +0 -3
- package/dist/workspace.js +1 -14
- package/package.json +14 -14
- package/skills/agentrun-serve/SKILL.md +1 -1
- package/templates/README.md +2 -2
- package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
- package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
- package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
- package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
- package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
- package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
- package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
- package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
- package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
- package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
- package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
- package/templates/release-notes/agent.md +11 -0
- package/dist/console/assets/index-RPHGlXmM.js +0 -540
- package/dist/console/assets/index-opTN5Naq.css +0 -1
package/dist/bash-read-only.js
CHANGED
|
@@ -35,6 +35,9 @@
|
|
|
35
35
|
// runs one command in the foreground); bash_output, bash_list and bash_signal, which reach only processes this run
|
|
36
36
|
// started, pass. A CLI harness's own shell call (codex's `shell`, an argv) is read as the command it runs.
|
|
37
37
|
//
|
|
38
|
+
// - The shell's environment: a shell under a policy runs git with its config locked down (policyEnv, below): no
|
|
39
|
+
// system or global config, and command-line config that turns off what a repository's config could run.
|
|
40
|
+
//
|
|
38
41
|
// What it does not hold: the policy reads bash alone. An agent that may also write or edit can change what a read
|
|
39
42
|
// program obeys (a repository's .git/config names programs git runs), so a read-only agent's tools are read and bash.
|
|
40
43
|
// The never-open list refuses a command that names such a file; it is no fence around the folder's contents: a recursive
|
|
@@ -43,6 +46,80 @@
|
|
|
43
46
|
import { posix } from "node:path";
|
|
44
47
|
/** The policies an agent may set on bash (tool_settings.bash.policy). */
|
|
45
48
|
export const BASH_POLICIES = ["read-only"];
|
|
49
|
+
/** An agent's bash policy as its own tool settings write it (tool_settings.bash.policy), or undefined for none: any
|
|
50
|
+
* value, a policy this server does not know too (the gate refuses its every call; policyEnv holds its shell all the same). */
|
|
51
|
+
export function bashPolicyOf(toolSettings) {
|
|
52
|
+
const bash = typeof toolSettings === "object" && toolSettings !== null ? toolSettings.bash : undefined;
|
|
53
|
+
const policy = typeof bash === "object" && bash !== null ? bash.policy : undefined;
|
|
54
|
+
return policy === undefined ? undefined : String(policy);
|
|
55
|
+
}
|
|
56
|
+
// git's config under a policy. The policy refuses `git -c`, `--config-env`, `--ext-diff`, `--textconv` and `--paginate`,
|
|
57
|
+
// but git also reads config from files, and config can name a program git runs on a plain read (core.fsmonitor on
|
|
58
|
+
// status and diff, core.pager, a hook on an index write, a diff or filter driver that an attribute attaches to a path, a
|
|
59
|
+
// signature program for log's %G?, a transport for a partial clone's lazy fetch). A checkout of someone else's code can
|
|
60
|
+
// hold such config: a bare repository planted in the tree, found when a command runs from inside it. So a shell under a
|
|
61
|
+
// policy runs git with:
|
|
62
|
+
// - no system or global config (the image's and HOME's are no business of a read);
|
|
63
|
+
// - command-line config (GIT_CONFIG_COUNT, which outranks every file) turning those programs off: no fsmonitor, hooks
|
|
64
|
+
// from /dev/null, cat as the pager, attributes from an empty tree and no attributes file (so no in-tree .gitattributes
|
|
65
|
+
// attaches a textconv, external diff or filter driver), a bare repository only when named (safe.bareRepository,
|
|
66
|
+
// which git reads from command-line config, never a repository's own), no transport at all, and no signature program;
|
|
67
|
+
// - GIT_PAGER and PAGER cat, no prompt, no optional lock (status leaves the index unwritten) and no lazy fetch.
|
|
68
|
+
// The config needs git 2.43 (attr.tree; safe.bareRepository is 2.38), and an older git ignores what it does not know,
|
|
69
|
+
// so a shell under a policy runs with a prelude (policyPrelude) defining `git` as a function that runs git only at 2.43
|
|
70
|
+
// or later and otherwise refuses, in words, before anything runs: fail closed, never a read with half the lock-down.
|
|
71
|
+
// Archil's stock exec image has git 2.34 (archil.ts), so a Mode 2 server runs its execs in DEFAULT_ARCHIL_EXEC_IMAGE
|
|
72
|
+
// (archil-settings.ts, git 2.47) unless the owner saved another, which needs git 2.43 too. The model cannot step around the function: the policy refuses `command`, a path to a program, `$`,
|
|
73
|
+
// `unset` and every program but git by name.
|
|
74
|
+
// What config cannot turn off: diff.external (an empty value makes git diff fail; git has no unset on the command
|
|
75
|
+
// line). It needs a repository's own config, which the policy never lets a command write and safe.bareRepository keeps
|
|
76
|
+
// a planted repository from supplying.
|
|
77
|
+
/** The empty tree's id, as attr.tree's value: attributes read from no tree (an id that does not resolve, a sha256
|
|
78
|
+
* repository's case, reads as the empty tree too). */
|
|
79
|
+
const EMPTY_TREE = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
|
|
80
|
+
/** The command-line config a shell under a policy gives git (GIT_CONFIG_KEY_n / GIT_CONFIG_VALUE_n). */
|
|
81
|
+
export const POLICY_GIT_CONFIG = [
|
|
82
|
+
["core.fsmonitor", "false"],
|
|
83
|
+
["core.hooksPath", "/dev/null"],
|
|
84
|
+
["core.pager", "cat"],
|
|
85
|
+
["core.attributesFile", "/dev/null"],
|
|
86
|
+
["attr.tree", EMPTY_TREE],
|
|
87
|
+
["safe.bareRepository", "explicit"],
|
|
88
|
+
["protocol.allow", "never"],
|
|
89
|
+
["log.showSignature", "false"],
|
|
90
|
+
["gpg.program", "false"],
|
|
91
|
+
["gpg.openpgp.program", "false"],
|
|
92
|
+
["gpg.x509.program", "false"],
|
|
93
|
+
["gpg.ssh.program", "false"],
|
|
94
|
+
];
|
|
95
|
+
/** What a shell under bash policy `policy` adds to the run's fixed environment (hands.ts shellEnv): git's config locked
|
|
96
|
+
* down (POLICY_GIT_CONFIG and the variables above); nothing without a policy. */
|
|
97
|
+
export function policyEnv(policy) {
|
|
98
|
+
if (policy === undefined)
|
|
99
|
+
return {};
|
|
100
|
+
return {
|
|
101
|
+
GIT_CONFIG_NOSYSTEM: "1",
|
|
102
|
+
GIT_CONFIG_GLOBAL: "/dev/null",
|
|
103
|
+
GIT_ATTR_NOSYSTEM: "1",
|
|
104
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
105
|
+
GIT_PAGER: "cat",
|
|
106
|
+
PAGER: "cat",
|
|
107
|
+
GIT_OPTIONAL_LOCKS: "0",
|
|
108
|
+
GIT_NO_LAZY_FETCH: "1",
|
|
109
|
+
GIT_CONFIG_COUNT: String(POLICY_GIT_CONFIG.length),
|
|
110
|
+
...Object.fromEntries(POLICY_GIT_CONFIG.flatMap(([key, value], n) => [[`GIT_CONFIG_KEY_${n}`, key], [`GIT_CONFIG_VALUE_${n}`, value]])),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/** The oldest git that holds the whole lock-down (attr.tree). */
|
|
114
|
+
export const POLICY_GIT_FLOOR = "2.43";
|
|
115
|
+
// `git version` at the floor or later: 2.43-2.49, 2.50-2.99, 2.100 and up, 3 and up.
|
|
116
|
+
const GIT_AT_FLOOR = `"git version 2.4"[3-9]*|"git version 2."[5-9][0-9]*|"git version 2."[1-9][0-9][0-9]*|"git version "[3-9]*|"git version "[1-9][0-9]*`;
|
|
117
|
+
const GIT_FUNCTION = `git() { case "$(command git version 2>/dev/null)" in ${GIT_AT_FLOOR}) command git "$@" ;; *) echo "git refused: this agent's bash policy needs git ${POLICY_GIT_FLOOR} or later to keep a repository's config from running a program, and this shell has $(command git version 2>/dev/null || echo no git); nothing ran." >&2; return 126 ;; esac; }`;
|
|
118
|
+
/** What a shell under bash policy `policy` runs before the command, on a line of its own: `git` as a function that runs
|
|
119
|
+
* git only at POLICY_GIT_FLOOR or later. Empty without a policy. POSIX sh, for bash and the sh fallback alike. */
|
|
120
|
+
export function policyPrelude(policy) {
|
|
121
|
+
return policy === undefined ? "" : `${GIT_FUNCTION}\n`;
|
|
122
|
+
}
|
|
46
123
|
/** The programs a read-only command may run. */
|
|
47
124
|
export const PROGRAMS = new Set(["git", "grep", "egrep", "fgrep", "rg", "sed", "ls", "cat", "head", "tail", "wc", "nl", "sort", "uniq", "cut", "tr", "find", "diff", "basename", "dirname", "true", "echo"]);
|
|
48
125
|
/** The programs a command may pipe into: filters of their input. */
|
package/dist/browser-cost.d.ts
CHANGED
|
@@ -11,8 +11,8 @@ import { type PaidBooking } from "./paid-calls.js";
|
|
|
11
11
|
* leaves a session billed that no record in the store names. */
|
|
12
12
|
export declare const BROWSER_SESSION_OPEN = "agentrun.browser_session_open";
|
|
13
13
|
/** List prices by pi-browser provider name (`provider.name`): Browserbase's (pi-browser's LIST_PRICES), $0.12 an hour with
|
|
14
|
-
* a one-minute minimum; Kernel's headless browser, about $0.06 an hour billed by the second; a local Chrome (`cdp
|
|
15
|
-
*
|
|
14
|
+
* a one-minute minimum; Kernel's headless browser, about $0.06 an hour billed by the second; a local Chrome (`cdp`),
|
|
15
|
+
* free. A computer provider whose descriptor bills nothing (metered false: Local Chrome's) is free too (browserPrice). */
|
|
16
16
|
export declare const BROWSER_PRICES: Readonly<Record<string, {
|
|
17
17
|
usdPerHour: number;
|
|
18
18
|
minimumS: number;
|
package/dist/browser-cost.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
2
|
+
import { PROVIDERS } from "@parcha/agentrun-computer";
|
|
2
3
|
import { TOOL_COST } from "./timeline/index.js";
|
|
3
4
|
import { addSpend, BROWSER_CHARGED, keepHold, paidCall, runCap, SPEND_CAP_REACHED } from "./cap.js";
|
|
4
5
|
import { paidStep } from "./paid-calls.js";
|
|
@@ -10,14 +11,15 @@ import { forModel } from "./result.js";
|
|
|
10
11
|
* leaves a session billed that no record in the store names. */
|
|
11
12
|
export const BROWSER_SESSION_OPEN = "agentrun.browser_session_open";
|
|
12
13
|
/** List prices by pi-browser provider name (`provider.name`): Browserbase's (pi-browser's LIST_PRICES), $0.12 an hour with
|
|
13
|
-
* a one-minute minimum; Kernel's headless browser, about $0.06 an hour billed by the second; a local Chrome (`cdp
|
|
14
|
-
*
|
|
14
|
+
* a one-minute minimum; Kernel's headless browser, about $0.06 an hour billed by the second; a local Chrome (`cdp`),
|
|
15
|
+
* free. A computer provider whose descriptor bills nothing (metered false: Local Chrome's) is free too (browserPrice). */
|
|
15
16
|
export const BROWSER_PRICES = Object.freeze({
|
|
16
17
|
browserbase: { usdPerHour: 0.12, minimumS: 60 },
|
|
17
18
|
kernel: { usdPerHour: 0.06, minimumS: 0 },
|
|
18
19
|
cdp: { usdPerHour: 0, minimumS: 0 },
|
|
19
|
-
local: { usdPerHour: 0, minimumS: 0 },
|
|
20
20
|
});
|
|
21
|
+
/** The free price of a computer provider whose descriptor says it bills nothing, never by its id. */
|
|
22
|
+
const unmeteredPrice = (provider) => PROVIDERS.some((entry) => entry.id === provider && !entry.metered) ? { usdPerHour: 0, minimumS: 0 } : undefined;
|
|
21
23
|
/** An operator's price for a provider, in USD an hour: this prefix and the provider's name in capitals
|
|
22
24
|
* (AGENTRUN_BROWSER_USD_PER_HOUR_BROWSERBASE, _KERNEL, _CDP). */
|
|
23
25
|
export const BROWSER_PRICE_ENV = "AGENTRUN_BROWSER_USD_PER_HOUR_";
|
|
@@ -30,7 +32,7 @@ export const priceEnvOf = (provider) => `${BROWSER_PRICE_ENV}${provider.toUpperC
|
|
|
30
32
|
/** `provider`'s session price: the operator's (a non-negative decimal), else the list's; `usdPerHour` null when neither
|
|
31
33
|
* names one or the operator's cannot be read, which is no price, never $0. */
|
|
32
34
|
export function browserPrice(provider, env) {
|
|
33
|
-
const listed = Object.hasOwn(BROWSER_PRICES, provider) ? BROWSER_PRICES[provider] :
|
|
35
|
+
const listed = Object.hasOwn(BROWSER_PRICES, provider) ? BROWSER_PRICES[provider] : unmeteredPrice(provider);
|
|
34
36
|
const text = env[priceEnvOf(provider)]?.trim();
|
|
35
37
|
const given = text ? (/^(\d+(\.\d*)?|\.\d+)$/.test(text) ? Number(text) : NaN) : undefined;
|
|
36
38
|
return { usdPerHour: given === undefined ? (listed?.usdPerHour ?? null) : Number.isFinite(given) ? given : null, minimumS: listed?.minimumS ?? 0 };
|
package/dist/budget.d.ts
CHANGED
|
@@ -38,13 +38,8 @@ export declare class CapStop extends Error {
|
|
|
38
38
|
}
|
|
39
39
|
/** The pause the run at `root` stands at, as its process wrote it; undefined when it waits at none. */
|
|
40
40
|
export declare const budgetPausedIn: (root: string) => BudgetMark | undefined;
|
|
41
|
-
/** A raise's cap, for the run's process to read (the server writes it after serve.json keeps it). */
|
|
42
|
-
export declare const writeRaisedCap: (root: string, usd: number) => void;
|
|
43
41
|
/** The pause's mark taken away: a raise sent its run on, here when no process waits at it (it was let go). */
|
|
44
42
|
export declare const clearBudgetPause: (root: string) => void;
|
|
45
|
-
/** Whether a raise to `capUsd` finishes the pause `mark` names (the server's finishRaise opens a let-go run again on it):
|
|
46
|
-
* only a cap above the one still refused. No mark, or a cap at or under it, opens nothing. */
|
|
47
|
-
export declare const raiseFinishes: (capUsd: number, mark: BudgetMark | undefined) => boolean;
|
|
48
43
|
/** The run's waits for a raise, in its process: `spend` is the run's spend (cap.ts), `holdMs` how long a pause keeps the
|
|
49
44
|
* process, `letGo` what lets it go. `step` counts the steps in flight (app.ts wraps each node, call and decision
|
|
50
45
|
* with it), a step run inside another (a model node's verification decision) as part of that one; a pause lets the
|
package/dist/budget.js
CHANGED
|
@@ -55,13 +55,8 @@ export const budgetPausedIn = (root) => {
|
|
|
55
55
|
const mark = readJson(join(root, BUDGET_PAUSE));
|
|
56
56
|
return mark && typeof mark.words === "string" && typeof mark.cap_usd === "number" ? mark : undefined;
|
|
57
57
|
};
|
|
58
|
-
/** A raise's cap, for the run's process to read (the server writes it after serve.json keeps it). */
|
|
59
|
-
export const writeRaisedCap = (root, usd) => writeWhole(join(root, CAP_RAISED), { max_cost_usd: usd });
|
|
60
58
|
/** The pause's mark taken away: a raise sent its run on, here when no process waits at it (it was let go). */
|
|
61
59
|
export const clearBudgetPause = (root) => rmSync(join(root, BUDGET_PAUSE), { force: true });
|
|
62
|
-
/** Whether a raise to `capUsd` finishes the pause `mark` names (the server's finishRaise opens a let-go run again on it):
|
|
63
|
-
* only a cap above the one still refused. No mark, or a cap at or under it, opens nothing. */
|
|
64
|
-
export const raiseFinishes = (capUsd, mark) => mark !== undefined && capUsd > mark.cap_usd + CAP_TOLERANCE;
|
|
65
60
|
/** The raised cap the run at `root` was given, if any. */
|
|
66
61
|
const raisedIn = (root) => {
|
|
67
62
|
const usd = readJson(join(root, CAP_RAISED))?.max_cost_usd;
|
package/dist/cap.d.ts
CHANGED
|
@@ -387,13 +387,16 @@ export declare function holdPaid(name: string, hold: {
|
|
|
387
387
|
* raise a request's ceiling up to the model's, whatever maxTokens it asked for. */
|
|
388
388
|
export declare const ceilingTokens: (model: Pick<Model<Api>, "maxTokens" | "contextWindow">) => number;
|
|
389
389
|
/** A request's input tokens, bounded above: one per UTF-8 byte of what is sent (a byte-level tokenizer never takes
|
|
390
|
-
* fewer than one byte a token,
|
|
391
|
-
*
|
|
390
|
+
* fewer than one byte a token), plus `overhead`: what the provider adds server-side that the body does not hold, and
|
|
391
|
+
* each image at what it is billed as in place of its base64's bytes (below 0 for a large image: piOverhead). The same
|
|
392
|
+
* bound on every harness. */
|
|
392
393
|
export declare const inputBound: (sent: string, overhead?: number) => number;
|
|
393
394
|
/** What pi's provider adds server-side to a request of `context`, the same table the model proxy uses, by the model's API
|
|
394
395
|
* kind: undefined for a kind whose additions are not known. The context does not say how the request chooses a tool,
|
|
395
396
|
* so the dearer choice is taken. */
|
|
396
|
-
export declare function piOverhead(model: Pick<Model<Api>, "api"
|
|
397
|
+
export declare function piOverhead(model: Pick<Model<Api>, "api"> & {
|
|
398
|
+
id?: string;
|
|
399
|
+
}, context: Context): number | undefined;
|
|
397
400
|
/** An amount in words: two decimals, or as many as it takes (up to eight) to show it whole ($0.50, $0.105, $0.0005). */
|
|
398
401
|
export declare function money(usd: number): string;
|
|
399
402
|
/** The code a cap's refusal begins with: `spend_cap_reached`, which the server ends the run with, and "out of budget",
|
package/dist/cap.js
CHANGED
|
@@ -48,7 +48,7 @@ import { readRunDbSync } from "./run-db.js";
|
|
|
48
48
|
import { durableDecisions } from "@parcha/agentrun-pi/durable";
|
|
49
49
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
50
50
|
import { existsSync } from "node:fs";
|
|
51
|
-
import { providerInputOverhead } from "@parcha/agentrun-kernel/host";
|
|
51
|
+
import { imageInputOf, providerInputOverhead } from "@parcha/agentrun-kernel/host";
|
|
52
52
|
import { bookRequest, isConnectCode, isGatewayTimeout, rejectionCode } from "@parcha/agentrun-kernel";
|
|
53
53
|
import { CAP_WRAPUP, REQUEST_CONTINUED, REQUEST_COST, REQUEST_COST_LATE, REQUEST_ENDED, REQUEST_REFUSED, REQUEST_STARTED, timelineOf, TOOL_COST, TOOL_STARTED } from "./timeline/index.js";
|
|
54
54
|
/** How a request the cap refused begins its error, which the server ends the run with. */
|
|
@@ -879,15 +879,18 @@ function outputBound(model) {
|
|
|
879
879
|
return [model.cost, ...(model.cost?.tiers ?? [])].every((rates) => rates?.output === 0) ? 0 : undefined;
|
|
880
880
|
}
|
|
881
881
|
/** A request's input tokens, bounded above: one per UTF-8 byte of what is sent (a byte-level tokenizer never takes
|
|
882
|
-
* fewer than one byte a token,
|
|
883
|
-
*
|
|
882
|
+
* fewer than one byte a token), plus `overhead`: what the provider adds server-side that the body does not hold, and
|
|
883
|
+
* each image at what it is billed as in place of its base64's bytes (below 0 for a large image: piOverhead). The same
|
|
884
|
+
* bound on every harness. */
|
|
884
885
|
export const inputBound = (sent, overhead = 0) => Buffer.byteLength(sent, "utf8") + overhead;
|
|
885
886
|
/** What pi's provider adds server-side to a request of `context`, the same table the model proxy uses, by the model's API
|
|
886
887
|
* kind: undefined for a kind whose additions are not known. The context does not say how the request chooses a tool,
|
|
887
888
|
* so the dearer choice is taken. */
|
|
888
889
|
export function piOverhead(model, context) {
|
|
889
890
|
const parts = (context.messages ?? []).flatMap((message) => (Array.isArray(message.content) ? (message.content) : []));
|
|
890
|
-
|
|
891
|
+
// Each image, in every turn, at what the model's provider bills it as by its size, in place of its base64's bytes in
|
|
892
|
+
// what is sent (imageInputOf, imageTokens).
|
|
893
|
+
return providerInputOverhead(model.api, { tools: (context.tools?.length ?? 0) > 0, toolChoice: "any", images: parts.filter((part) => part?.type === "image").map((part) => imageInputOf(part.data)), ...(model.id ? { model: model.id } : {}) });
|
|
891
894
|
}
|
|
892
895
|
const unmeasured = (cap) => `${SPEND_CAP_REACHED}: Not sent: the size of the next model request's input is unknown, so the run's cap of ${money(cap)} cannot be kept: the run is out of budget.`;
|
|
893
896
|
const noPrice = (cap) => `${SPEND_CAP_REACHED}: Not sent: the next model request's model has no price here, so the run's cap of ${money(cap)} cannot be kept: the run is out of budget.`;
|
package/dist/cli.js
CHANGED
|
@@ -22,7 +22,7 @@ import { surviveClosedPipes } from "./closed-pipes.js";
|
|
|
22
22
|
// A stdout or stderr its reader closed loses the lines written after, never the process (closed-pipes.ts): for every
|
|
23
23
|
// command, the server and the runner alike.
|
|
24
24
|
surviveClosedPipes();
|
|
25
|
-
const USAGE = `usage: agentrun-serve [--data DIR] [--listen ADDR] [--port N] [--open] [--faux MODULE] [--faux-browser MODULE] [--allow-host NAME ...] [--max-runs N] [--drain-timeout D] [--documents DIR] [--allow-code-nodes] [--learning on|off] [--learning-budget BYTES] [--grade-model MODEL] [--no-runner]
|
|
25
|
+
const USAGE = `usage: agentrun-serve [--data DIR] [--listen ADDR] [--port N] [--open] [--faux MODULE] [--faux-browser MODULE] [--faux-github] [--allow-host NAME ...] [--max-runs N] [--drain-timeout D] [--documents DIR] [--allow-code-nodes] [--learning on|off] [--learning-budget BYTES] [--grade-model MODEL] [--no-runner]
|
|
26
26
|
agentrun-serve reset-password [--data DIR]
|
|
27
27
|
agentrun-serve validate-template DIR
|
|
28
28
|
agentrun-serve eval-template DIR [--case NAME ...] [--runs N] [--server URL] [--grader-model PROVIDER/MODEL] [--report FILE] [--faux MODULE]
|
|
@@ -40,6 +40,9 @@ const USAGE = `usage: agentrun-serve [--data DIR] [--listen ADDR] [--port N] [--
|
|
|
40
40
|
--faux-browser MODULE
|
|
41
41
|
with --faux only: the browser tool's provider and driver from MODULE's default export (a fake
|
|
42
42
|
browser, no vendor, no key), for the console's real-browser tests
|
|
43
|
+
--faux-github with --faux only: a fake GitHub App, connected at the start and answered in this process, so
|
|
44
|
+
GitHub triggers run with nothing sent to GitHub; its webhook secret is in DIR/faux-github.json.
|
|
45
|
+
On a scratch data directory: refused where another GitHub App is connected
|
|
43
46
|
--allow-host NAME another Host name to accept (repeatable)
|
|
44
47
|
--max-runs N the most runs the runner beside the server holds at once, the rest waiting queued (default
|
|
45
48
|
AGENTRUN_MAX_RUNS, else as many pi runs as this host's memory holds); the capabilities'
|
|
@@ -249,6 +252,7 @@ try {
|
|
|
249
252
|
open: { type: "boolean", default: false },
|
|
250
253
|
faux: { type: "string" },
|
|
251
254
|
"faux-browser": { type: "string" },
|
|
255
|
+
"faux-github": { type: "boolean", default: false },
|
|
252
256
|
"allow-host": { type: "string", multiple: true, default: [] },
|
|
253
257
|
"max-runs": { type: "string" },
|
|
254
258
|
"drain-timeout": { type: "string" },
|
|
@@ -291,6 +295,10 @@ if (values["faux-browser"] && !values.faux) {
|
|
|
291
295
|
console.error(`--faux-browser goes with --faux\n\n${USAGE}`);
|
|
292
296
|
process.exit(2);
|
|
293
297
|
}
|
|
298
|
+
if (values["faux-github"] && !values.faux) {
|
|
299
|
+
console.error(`--faux-github goes with --faux\n\n${USAGE}`);
|
|
300
|
+
process.exit(2);
|
|
301
|
+
}
|
|
294
302
|
const budget = values["learning-budget"];
|
|
295
303
|
if (budget !== undefined && !/^\d+$/.test(budget)) {
|
|
296
304
|
console.error(`--learning-budget takes a whole number of bytes\n\n${USAGE}`);
|
|
@@ -298,6 +306,22 @@ if (budget !== undefined && !/^\d+$/.test(budget)) {
|
|
|
298
306
|
}
|
|
299
307
|
const data = values.data ?? defaultData();
|
|
300
308
|
const given = secret("AGENTRUN_TOKEN") || undefined;
|
|
309
|
+
// The stop is listened for before anything starts: a SIGTERM or SIGINT during the start (a platform's redeploy, the
|
|
310
|
+
// moment the banner shows) is kept, never the default end by signal that cuts what the start began. Once the start has
|
|
311
|
+
// what a stop closes, the stop below takes over (stopOnSignals), and a stop asked meanwhile runs it, through the same
|
|
312
|
+
// drain. A second signal a while after the first, still during the start, is a person who wants out now: exit 130.
|
|
313
|
+
let stopping;
|
|
314
|
+
let askedAt;
|
|
315
|
+
const signalled = () => {
|
|
316
|
+
if (stopping)
|
|
317
|
+
return stopping();
|
|
318
|
+
if (askedAt === undefined)
|
|
319
|
+
askedAt = Date.now();
|
|
320
|
+
else if (Date.now() - askedAt >= REPEAT_MS)
|
|
321
|
+
process.exit(130);
|
|
322
|
+
};
|
|
323
|
+
process.on("SIGINT", signalled);
|
|
324
|
+
process.on("SIGTERM", signalled);
|
|
301
325
|
// AGENTRUN_API_ONLY=1: the run routes alone (api-only.ts), and no owner; a value that is neither on nor off stops here.
|
|
302
326
|
let apiOnly;
|
|
303
327
|
try {
|
|
@@ -337,7 +361,7 @@ try {
|
|
|
337
361
|
console.error(`agentrun-serve: ${error.message}`);
|
|
338
362
|
process.exit(1);
|
|
339
363
|
},
|
|
340
|
-
data, port, ...(values.port === undefined ? { nextFreePort: true } : {}), ...(values.listen ? { host: values.listen } : {}), ...(given ? { token: given } : {}), ...(values.faux ? { faux: values.faux } : {}), ...(values["faux-browser"] ? { fauxBrowser: values["faux-browser"] } : {}), allowHosts: values["allow-host"],
|
|
364
|
+
data, port, ...(values.port === undefined ? { nextFreePort: true } : {}), ...(values.listen ? { host: values.listen } : {}), ...(given ? { token: given } : {}), ...(values.faux ? { faux: values.faux } : {}), ...(values["faux-browser"] ? { fauxBrowser: values["faux-browser"] } : {}), ...(values["faux-github"] ? { fauxGitHub: true } : {}), allowHosts: values["allow-host"],
|
|
341
365
|
...(values["max-runs"] !== undefined ? { maxRuns: Number(values["max-runs"]) } : {}),
|
|
342
366
|
...(values["drain-timeout"] ? { drainTimeout: values["drain-timeout"] } : {}), ...(values.documents ? { documents: values.documents } : {}), ...(values["allow-code-nodes"] ? { allowCodeNodes: true } : {}), ...(values.learning !== undefined ? { learning: values.learning } : {}), ...(values["grade-model"] ? { gradeModel: values["grade-model"] } : {}), ...(budget !== undefined ? { learningBudget: Number(budget) } : {}), log: (line) => void process.stdout.write(`${line}\n`),
|
|
343
367
|
// The public address is the server's with accounts on or off: the Host names it serves, the webhook URLs it gives.
|
|
@@ -358,7 +382,8 @@ catch (error) {
|
|
|
358
382
|
// its turn for up to --drain-timeout.
|
|
359
383
|
let runnerProc;
|
|
360
384
|
const { loops, drainMs } = besideRunnerOptions(serveOptions, process.env);
|
|
361
|
-
|
|
385
|
+
// A stop asked during the server's start starts no runner: nothing is claimed for the stop to cut.
|
|
386
|
+
if (!values["no-runner"] && askedAt === undefined) {
|
|
362
387
|
try {
|
|
363
388
|
// The beside-runner sees the server's test switches (server.ts fauxEnvOf: --faux and its modules), which the CLI hands
|
|
364
389
|
// the server as options, never through this process's environment: without them a --faux start's runner looks its faux
|
|
@@ -410,9 +435,11 @@ const stop = stopOnSignals({
|
|
|
410
435
|
done: (code) => (removeOwnRecord(record), process.exit(code)),
|
|
411
436
|
say: (line) => console.error(line),
|
|
412
437
|
});
|
|
413
|
-
|
|
414
|
-
process.on("SIGTERM", stop);
|
|
438
|
+
stopping = stop;
|
|
415
439
|
// Written whole under a name of its own, then renamed into place: a reader in another process (the npx command, a test
|
|
416
440
|
// waiting for this server) that finds the record reads all of it, never a file made but not yet filled.
|
|
417
441
|
writeDurableSync(record, `${JSON.stringify({ base_url: serve.baseUrl, pid: process.pid, ...(serve.tokenFile ? { token_file: serve.tokenFile } : {}) })}\n`);
|
|
418
442
|
chmodSync(record, 0o600);
|
|
443
|
+
// A stop asked during the start runs now, as one asked from here on would.
|
|
444
|
+
if (askedAt !== undefined)
|
|
445
|
+
stop(askedAt);
|
package/dist/computer-keys.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
import { type ProviderEntry } from "@parcha/agentrun-computer";
|
|
2
|
+
/** One key a provider takes: its name in its descriptor, the create() option it fills, and whether it is needed. */
|
|
2
3
|
export interface ProviderKey {
|
|
3
4
|
readonly name: string;
|
|
4
5
|
readonly option: string;
|
|
5
6
|
readonly required: boolean;
|
|
6
7
|
}
|
|
7
|
-
/**
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export interface ProviderSettings {
|
|
13
|
-
readonly modalApp?: string;
|
|
8
|
+
/** A setting that is no key but fills a create() option: its name in the server's settings, and its default. */
|
|
9
|
+
export interface ProviderSetting {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly option: string;
|
|
12
|
+
readonly default?: string;
|
|
14
13
|
}
|
|
14
|
+
/** The server's settings that are no key, by their names in the descriptors (modalApp): what fills each setting. */
|
|
15
|
+
export type ProviderSettings = Readonly<Record<string, string | undefined>>;
|
|
15
16
|
/** An answer in the registry's shape: a value, or an error with its code and words. */
|
|
16
17
|
export type KeyResult<T> = {
|
|
17
18
|
ok: true;
|
|
@@ -48,13 +49,22 @@ export interface TestableProvider {
|
|
|
48
49
|
}
|
|
49
50
|
/** A provider module's create(), by provider id: the computer package's, or a test's stand-in. */
|
|
50
51
|
export type ProviderFactories = Readonly<Partial<Record<string, (options: Record<string, string>) => TestableProvider | Promise<TestableProvider>>>>;
|
|
51
|
-
/** The table the map reads: each provider's keys and
|
|
52
|
+
/** The table the map reads: each provider's keys, settings and name in words, by id. Serve's own (KEY_TABLE, the
|
|
53
|
+
* computer package's descriptors), or --faux's (keyTableOf its entries). */
|
|
52
54
|
export interface KeyTable {
|
|
53
55
|
readonly keys: Readonly<Record<string, readonly ProviderKey[]>>;
|
|
54
56
|
readonly labels: Readonly<Record<string, string>>;
|
|
57
|
+
readonly settings?: Readonly<Record<string, readonly ProviderSetting[]>>;
|
|
55
58
|
}
|
|
59
|
+
/** The key table of `entries` (the kind registry's PROVIDERS, each from its descriptor). */
|
|
60
|
+
export declare function keyTableOf(entries: readonly Pick<ProviderEntry, "id" | "label" | "keys" | "settings">[]): KeyTable;
|
|
61
|
+
/** Serve's table: every provider the computer package declares. */
|
|
56
62
|
export declare const KEY_TABLE: KeyTable;
|
|
57
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* Provider `providerId`'s create() options from its saved keys (by its descriptor's names) and the server's settings
|
|
65
|
+
* (each of its descriptor's settings, by name, else its default). An id the table does not list is refused, naming the
|
|
66
|
+
* providers it does.
|
|
67
|
+
*/
|
|
58
68
|
export declare function providerOptions(providerId: string, keys: Readonly<Record<string, string>>, settings?: ProviderSettings, table?: KeyTable): OptionsAnswer;
|
|
59
69
|
/**
|
|
60
70
|
* Settings' "test connection" for `providerId` (the kind registry's TestConnection, and serve's ComputerRegistry.test):
|
package/dist/computer-keys.js
CHANGED
|
@@ -1,57 +1,36 @@
|
|
|
1
|
-
// Settings → Computers' keys, serve side: a provider's saved keys, by the names
|
|
2
|
-
//
|
|
3
|
-
// (the registry's TestConnection: one account-level read that never makes a computer), its coded
|
|
1
|
+
// Settings → Computers' keys, serve side: a provider's saved keys, by the names its descriptor declares (the computer
|
|
2
|
+
// package's PROVIDERS, derived from each provider's descriptor), as that provider's create() options, and Settings' "test
|
|
3
|
+
// connection" over them (the registry's TestConnection: one account-level read that never makes a computer), its coded
|
|
4
|
+
// errors in plain words.
|
|
4
5
|
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// on; an empty optional key is left out; a required one not saved refuses in
|
|
8
|
-
// is made. The provider modules themselves (each one's create()) are passed
|
|
9
|
-
// computer package's; a test gives stand-ins): a provider with no module
|
|
10
|
-
// No key is ever in an answer: each value is scrubbed from the provider's
|
|
11
|
-
// only by their names.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
{ name
|
|
17
|
-
|
|
18
|
-
{ name:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
],
|
|
24
|
-
e2b: [{ name: "E2B_API_KEY", option: "apiKey", required: true }],
|
|
25
|
-
orgo: [{ name: "ORGO_API_KEY", option: "apiKey", required: true }],
|
|
26
|
-
"phone-harness": [{ name: "PHONE_HARNESS_API_KEY", option: "apiKey", required: true }],
|
|
27
|
-
browserbase: [
|
|
28
|
-
{ name: "BROWSERBASE_API_KEY", option: "apiKey", required: true },
|
|
29
|
-
{ name: "BROWSERBASE_PROJECT_ID", option: "projectId", required: true },
|
|
30
|
-
],
|
|
31
|
-
kernel: [{ name: "KERNEL_API_KEY", option: "apiKey", required: true }],
|
|
32
|
-
// This machine's Chrome: no key.
|
|
33
|
-
local: [],
|
|
34
|
-
};
|
|
35
|
-
/** Each provider's name in words (the registry's labels). */
|
|
36
|
-
const LABELS = {
|
|
37
|
-
docker: "Docker",
|
|
38
|
-
daytona: "Daytona",
|
|
39
|
-
modal: "Modal",
|
|
40
|
-
e2b: "E2B",
|
|
41
|
-
orgo: "Orgo",
|
|
42
|
-
"phone-harness": "Phone harness",
|
|
43
|
-
browserbase: "Browserbase",
|
|
44
|
-
kernel: "Kernel",
|
|
45
|
-
local: "Local Chrome",
|
|
46
|
-
};
|
|
47
|
-
/** The Modal app a server's computers live in when its settings name none (serve's box app until now). */
|
|
48
|
-
export const DEFAULT_MODAL_APP = "agentrun";
|
|
49
|
-
export const KEY_TABLE = { keys: PROVIDER_KEYS, labels: LABELS };
|
|
6
|
+
// Serve knows no vendor here: each key's name and the option it fills, each setting that is no key (its name in the
|
|
7
|
+
// server's settings, its option and its default), and each provider's label all come from the descriptor. A name a
|
|
8
|
+
// provider does not declare is never passed on; an empty optional key is left out; a required one not saved refuses in
|
|
9
|
+
// words naming what to save, before anything is made. The provider modules themselves (each one's create()) are passed
|
|
10
|
+
// in (workspace/computer-providers.ts makes the computer package's; a test gives stand-ins): a provider with no module
|
|
11
|
+
// here answers that its test is not available. No key is ever in an answer: each value is scrubbed from the provider's
|
|
12
|
+
// words, and the words this module adds name keys only by their names.
|
|
13
|
+
import { PROVIDERS } from "@parcha/agentrun-computer";
|
|
14
|
+
/** The key table of `entries` (the kind registry's PROVIDERS, each from its descriptor). */
|
|
15
|
+
export function keyTableOf(entries) {
|
|
16
|
+
return {
|
|
17
|
+
keys: Object.fromEntries(entries.map((entry) => [entry.id, entry.keys.map(({ name, option, required }) => ({ name, option, required }))])),
|
|
18
|
+
labels: Object.fromEntries(entries.map((entry) => [entry.id, entry.label])),
|
|
19
|
+
settings: Object.fromEntries(entries.map((entry) => [entry.id, (entry.settings ?? []).map(({ name, option, default: fallback }) => ({ name, option, ...(fallback === undefined ? {} : { default: fallback }) }))])),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** Serve's table: every provider the computer package declares. */
|
|
23
|
+
export const KEY_TABLE = keyTableOf(PROVIDERS);
|
|
50
24
|
const has = (record, key) => Object.prototype.hasOwnProperty.call(record, key);
|
|
51
25
|
const labelOf = (providerId, table) => (has(table.labels, providerId) ? table.labels[providerId] : providerId);
|
|
52
26
|
const refused = (code, message) => ({ ok: false, error: { code, message } });
|
|
53
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Provider `providerId`'s create() options from its saved keys (by its descriptor's names) and the server's settings
|
|
29
|
+
* (each of its descriptor's settings, by name, else its default). An id the table does not list is refused, naming the
|
|
30
|
+
* providers it does.
|
|
31
|
+
*/
|
|
54
32
|
export function providerOptions(providerId, keys, settings = {}, table = KEY_TABLE) {
|
|
33
|
+
// The table is every descriptor's (keyTableOf(PROVIDERS)), so an id it does not list is no provider at all.
|
|
55
34
|
if (!has(table.keys, providerId))
|
|
56
35
|
return refused("unsupported", `${providerId} is not a computer provider: ${Object.keys(table.keys).join(", ")}`);
|
|
57
36
|
const label = labelOf(providerId, table);
|
|
@@ -67,8 +46,12 @@ export function providerOptions(providerId, keys, settings = {}, table = KEY_TAB
|
|
|
67
46
|
if (missing.length > 0) {
|
|
68
47
|
return refused("missing_key", `${label} needs ${missing.join(" and ")} saved: save ${missing.length > 1 ? "them" : "it"} in Settings → Computers (PUT /v2/computers/${providerId}/keys)`);
|
|
69
48
|
}
|
|
70
|
-
|
|
71
|
-
|
|
49
|
+
for (const setting of table.settings && has(table.settings, providerId) ? table.settings[providerId] : []) {
|
|
50
|
+
const given = has(settings, setting.name) ? settings[setting.name]?.trim() : undefined;
|
|
51
|
+
const value = given || setting.default;
|
|
52
|
+
if (value !== undefined && value !== "")
|
|
53
|
+
options[setting.option] = value;
|
|
54
|
+
}
|
|
72
55
|
return { ok: true, options };
|
|
73
56
|
}
|
|
74
57
|
/** `text` with every key value in `values` replaced by "[the key]". */
|
|
@@ -101,12 +84,8 @@ function wordsFor(code, providerId, said, table) {
|
|
|
101
84
|
return `${label}'s settings are not valid.${vendor}`;
|
|
102
85
|
case "unsupported":
|
|
103
86
|
return `${label} can't be tested here.${vendor}`;
|
|
104
|
-
|
|
105
|
-
case "
|
|
106
|
-
case "modal":
|
|
107
|
-
case "e2b":
|
|
108
|
-
case "orgo":
|
|
109
|
-
case "phone":
|
|
87
|
+
// The computer package's one code for a vendor's own failure (ComputerErrorCode "vendor"), whatever the vendor.
|
|
88
|
+
case "vendor":
|
|
110
89
|
return `${label} answered with an error.${vendor}`;
|
|
111
90
|
default:
|
|
112
91
|
return `The test of ${label} failed.${vendor}`;
|
|
@@ -7,16 +7,19 @@ export type GpuSetting = {
|
|
|
7
7
|
readonly type: string;
|
|
8
8
|
readonly count: number;
|
|
9
9
|
};
|
|
10
|
-
/** The setting as a revision keeps it.
|
|
10
|
+
/** The setting as a revision keeps it. `image`: one the provider's descriptor offers for the kind (Orgo's `windows`);
|
|
11
|
+
* absent, the kind's default. A sandbox may ask for GPUs; whether its provider gives them is the claim's check. */
|
|
11
12
|
export type ComputerSetting = {
|
|
12
13
|
readonly kind: "none";
|
|
13
14
|
} | {
|
|
14
15
|
readonly kind: "sandbox";
|
|
15
16
|
readonly provider: string;
|
|
17
|
+
readonly image?: string;
|
|
16
18
|
readonly gpu?: GpuSetting;
|
|
17
19
|
} | {
|
|
18
20
|
readonly kind: Exclude<ComputerKind, "none" | "sandbox">;
|
|
19
21
|
readonly provider: string;
|
|
22
|
+
readonly image?: string;
|
|
20
23
|
};
|
|
21
24
|
/** The GPUs a setting asks for, or undefined. */
|
|
22
25
|
export declare const gpuOf: (computer: {
|
|
@@ -34,11 +37,9 @@ export type PlaceView = {
|
|
|
34
37
|
export declare const placeOfComputer: (computer: ComputerSetting) => PlaceView;
|
|
35
38
|
/** The setting a place says: runner is no computer, a sandbox place a sandbox on its box. */
|
|
36
39
|
export declare const computerOfPlace: (place: PlaceView) => ComputerSetting;
|
|
37
|
-
/** Whether two settings are the one setting: the kind and
|
|
40
|
+
/** Whether two settings are the one setting: the same kind and provider, and the same of each optional field. */
|
|
38
41
|
export declare const sameComputer: (a: ComputerSetting, b: ComputerSetting) => boolean;
|
|
39
|
-
/** What is wrong with `value` as a computer setting, at `field`: its shape only (the providers are the server's).
|
|
40
|
-
* sandbox's gpu is { type, count } in the words the computer package's checkGpu uses; whether its provider offers that
|
|
41
|
-
* type and count is the readiness check's and the claim's (resolve-computer.ts), in checkGpu's own words. */
|
|
42
|
+
/** What is wrong with `value` as a computer setting, at `field`: its shape only (the providers are the server's). */
|
|
42
43
|
export declare function computerIssues(value: unknown, field: string): InputIssue[];
|
|
43
44
|
/** The setting and its place a definition says, from `computer` or `place` (both: they must agree), or undefined when
|
|
44
45
|
* it says neither. Each is checked already (computerIssues, placeIssues). */
|