@parcha/agentrun-serve 0.1.0-beta.48 → 0.1.0-beta.50
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 +37 -0
- package/README.md +236 -26
- package/dist/agent-delete.d.ts +36 -12
- package/dist/agent-delete.js +213 -30
- package/dist/agents-store.d.ts +6 -2
- package/dist/agents-store.js +18 -5
- package/dist/agents.d.ts +8 -1
- package/dist/agents.js +14 -4
- package/dist/answer-json.d.ts +2 -2
- package/dist/answer-json.js +3 -4
- package/dist/api-only.d.ts +7 -10
- package/dist/api-only.js +9 -11
- package/dist/archil-routes.d.ts +1 -1
- package/dist/archil-routes.js +4 -3
- package/dist/browser-sessions.d.ts +56 -0
- package/dist/browser-sessions.js +117 -0
- package/dist/compute-cost.d.ts +101 -0
- package/dist/compute-cost.js +250 -0
- package/dist/computer-routes.d.ts +4 -15
- package/dist/computer-routes.js +6 -10
- package/dist/console/assets/index-D0mr9wfZ.css +1 -0
- package/dist/console/assets/index-D7G6o-1E.js +720 -0
- package/dist/console/index.html +2 -2
- package/dist/errors.d.ts +4 -1
- package/dist/errors.js +15 -5
- package/dist/eval-previous.d.ts +52 -0
- package/dist/eval-previous.js +164 -0
- package/dist/file-types.d.ts +2 -0
- package/dist/file-types.js +3 -1
- package/dist/harness.js +2 -1
- package/dist/import.js +4 -3
- package/dist/learn/check.d.ts +16 -4
- package/dist/learn/check.js +30 -26
- package/dist/learn/promote.d.ts +7 -1
- package/dist/learn/promote.js +47 -0
- package/dist/learn/repick.d.ts +43 -0
- package/dist/learn/repick.js +202 -0
- package/dist/learn/workflow-draft.d.ts +4 -0
- package/dist/learn/workflow-draft.js +10 -7
- package/dist/learned-workflow.d.ts +2 -0
- package/dist/learned-workflow.js +19 -2
- package/dist/learning-setting.d.ts +13 -0
- package/dist/learning-setting.js +23 -1
- package/dist/llms.txt +1 -1
- package/dist/openapi.js +180 -14
- package/dist/paid-calls.d.ts +17 -7
- package/dist/paid-calls.js +15 -9
- package/dist/run-launch.d.ts +2 -2
- package/dist/run-launch.js +2 -1
- package/dist/run-learning-served.d.ts +1 -1
- package/dist/run-timeline-served.js +5 -3
- package/dist/run-usage.d.ts +125 -0
- package/dist/run-usage.js +394 -0
- package/dist/runner/adapter-loop.d.ts +4 -0
- package/dist/runner/adapter-loop.js +66 -21
- package/dist/runner/adapter-run-spec.d.ts +8 -3
- package/dist/runner/adapter-run-spec.js +13 -6
- package/dist/runner/big-writes.d.ts +33 -0
- package/dist/runner/big-writes.js +105 -0
- package/dist/runner/cli-run-spec.js +14 -6
- package/dist/runner/conformance/harness.d.ts +2 -0
- package/dist/runner/conformance/harness.js +18 -4
- package/dist/runner/feedback-round.d.ts +29 -1
- package/dist/runner/feedback-round.js +54 -3
- package/dist/runner/held.d.ts +4 -1
- package/dist/runner/journal-kinds.d.ts +3 -1
- package/dist/runner/learning-end.js +54 -18
- package/dist/runner/loop-contract.d.ts +3 -0
- package/dist/runner/metrics.d.ts +4 -0
- package/dist/runner/metrics.js +9 -0
- package/dist/runner/monid-run.js +2 -2
- package/dist/runner/promotion.js +8 -2
- package/dist/runner/reflect-hook.js +3 -2
- package/dist/runner/run-child-host.d.ts +15 -2
- package/dist/runner/run-child-host.js +24 -8
- package/dist/runner/run-child.js +3 -0
- package/dist/runner/save-slots.d.ts +9 -0
- package/dist/runner/save-slots.js +91 -0
- package/dist/runs-over-store.d.ts +3 -2
- package/dist/runs-over-store.js +9 -7
- package/dist/sdk/runs.d.ts +3 -4
- package/dist/sdk/runs.js +10 -7
- package/dist/sdk/runtimes.d.ts +19 -0
- package/dist/sdk/runtimes.js +23 -0
- package/dist/sdk/schema.d.ts +14 -8
- package/dist/sdk/schema.js +18 -6
- package/dist/server.d.ts +7 -3
- package/dist/server.js +223 -100
- package/dist/store/agent-body.d.ts +2 -3
- package/dist/store/agent-body.js +3 -2
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/journal/storage.js +1 -1
- package/dist/store/open.d.ts +1 -1
- package/dist/store/open.js +1 -1
- package/dist/store/postgres/migrations/0021_purged.sql +13 -0
- package/dist/store/postgres/migrations/0022_computer_intervals.sql +27 -0
- package/dist/store/postgres/migrations/0023_computer_interval_resources.sql +14 -0
- package/dist/store/schema.d.ts +20 -1
- package/dist/store/schema.js +60 -5
- package/dist/store/sqlite/connection.d.ts +4 -1
- package/dist/store/sqlite/connection.js +5 -0
- package/dist/store/sqlite/run-patch.d.ts +8 -3
- package/dist/store/sqlite/run-patch.js +15 -7
- package/dist/store/sqlite/store.d.ts +2 -1
- package/dist/store/sqlite/store.js +279 -68
- package/dist/store/sqlite/worker.d.ts +9 -0
- package/dist/store/sqlite/worker.js +18 -1
- package/dist/store/store.d.ts +149 -9
- package/dist/store/store.js +63 -0
- package/dist/store-reads/analytics.js +2 -1
- package/dist/store-reads/cap.d.ts +17 -7
- package/dist/store-reads/cap.js +54 -4
- package/dist/store-reads/decisions.d.ts +21 -0
- package/dist/store-reads/decisions.js +22 -0
- package/dist/store-reads/journal.d.ts +8 -2
- package/dist/store-reads/journal.js +27 -8
- package/dist/store-reads/learning.d.ts +1 -1
- package/dist/store-reads/learning.js +5 -2
- package/dist/store-reads/runs.js +2 -0
- package/dist/store-reads/stats.js +4 -2
- package/dist/store-view.d.ts +12 -1
- package/dist/store-view.js +98 -38
- package/dist/template-eval.d.ts +15 -1
- package/dist/template-eval.js +92 -13
- package/dist/templates.d.ts +1 -1
- package/dist/templates.js +4 -3
- package/dist/timeline/labels.js +17 -0
- package/dist/tool-list.js +1 -0
- package/dist/tools.d.ts +6 -2
- package/dist/tools.js +22 -1
- package/dist/trigger-targets.d.ts +28 -9
- package/dist/trigger-targets.js +19 -16
- package/dist/triggers.d.ts +2 -1
- package/dist/triggers.js +5 -2
- package/dist/validate.d.ts +4 -2
- package/dist/validate.js +13 -3
- package/dist/viewer-credential.d.ts +3 -4
- package/dist/viewer-credential.js +6 -4
- package/dist/web-fake.d.ts +25 -0
- package/dist/web-fake.js +38 -1
- package/dist/web-save.d.ts +75 -0
- package/dist/web-save.js +235 -0
- package/dist/workspace/archil-claim.d.ts +5 -2
- package/dist/workspace/archil-claim.js +5 -2
- package/dist/workspace/archil-disk.d.ts +10 -1
- package/dist/workspace/archil-disk.js +19 -1
- package/dist/workspace/archil.d.ts +3 -0
- package/dist/workspace/archil.js +101 -16
- package/dist/workspace/computer-for-claim.d.ts +19 -1
- package/dist/workspace/computer-for-claim.js +88 -20
- package/dist/workspace/computer-intervals.d.ts +26 -0
- package/dist/workspace/computer-intervals.js +58 -0
- package/dist/workspace/computer-janitor.d.ts +7 -3
- package/dist/workspace/computer-janitor.js +14 -6
- package/dist/workspace/computer-kept.d.ts +7 -2
- package/dist/workspace/computer-kept.js +9 -2
- package/dist/workspace/pieced.d.ts +14 -0
- package/dist/workspace/pieced.js +23 -0
- package/dist/workspace/resolve-computer.d.ts +7 -4
- package/dist/workspace/resolve-computer.js +21 -32
- package/dist/workspace/run-disk.js +32 -12
- package/dist/workspace/run-end-computers.d.ts +1 -0
- package/dist/workspace/run-end-computers.js +4 -1
- package/dist/workspace/run-workspace.d.ts +1 -1
- package/dist/workspace/run-workspace.js +11 -6
- package/package.json +10 -10
- package/templates/README.md +36 -7
- package/dist/console/assets/index-CTGegcKt.css +0 -1
- package/dist/console/assets/index-D1Se6mgG.js +0 -715
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// A run's browser sessions, one record each (GET /runs/{run_id}/usage `browser_sessions`): how long each ran, how it
|
|
2
|
+
// ended, and its provider's id, by which the provider's own dashboard and invoice find it. Two records on the run's root say a session: its open
|
|
3
|
+
// (BROWSER_SESSION_OPEN, written before the provider is asked to create it, browser-cost.ts) and its end
|
|
4
|
+
// (BROWSER_SESSION_ENDED, below, written once pi-browser lets it go). The end carries the provider's session id, when
|
|
5
|
+
// this server saw the session start and end, why it ended, and the provider's own record of it where the provider keeps
|
|
6
|
+
// one (BrowserComputerProvider.sessionUsage: its start, its end, its proxy bytes), read once at that release. The
|
|
7
|
+
// seconds this server charged for it are its BROWSER_CHARGED records', the provider's minimum included where the
|
|
8
|
+
// release topped the session up to it; nothing is priced here. How long it ran is its end less its start.
|
|
9
|
+
//
|
|
10
|
+
// Unknown is never 0. A session with no end record yet (its run's process lost before the release was told) says
|
|
11
|
+
// `ended_at` null; a provider that keeps no record, or one whose read failed, says so (`provider_record_status`) with
|
|
12
|
+
// `provider_record` null; a field the provider's record does not hold is null in it.
|
|
13
|
+
import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
14
|
+
import { BROWSER_CHARGED, BROWSER_SESSION_OPEN } from "./browser-cost.js";
|
|
15
|
+
/** The run journal's record of a browser session let go (on the root): see the file's head. */
|
|
16
|
+
export const BROWSER_SESSION_ENDED = "agentrun.browser_session_ended";
|
|
17
|
+
/** How long the provider's record is waited for at a release before the session's end is written without it. */
|
|
18
|
+
export const PROVIDER_RECORD_TIMEOUT_MS = 5_000;
|
|
19
|
+
/** The writer of each session's end, once per session in this process (pi-browser tells a release at least once):
|
|
20
|
+
* the provider's record read first (`usage`, bounded), then the end written on the root (`commit`). It never throws: a
|
|
21
|
+
* session whose end cannot be written is said in `log`, and reads as not ended. */
|
|
22
|
+
export function sessionEnds(options) {
|
|
23
|
+
const written = new Set();
|
|
24
|
+
const log = options.log ?? ((line) => void process.stderr.write(`agentrun-serve: ${line}\n`));
|
|
25
|
+
return async (session, conversation) => {
|
|
26
|
+
if (written.has(session.tag) || !options.commit)
|
|
27
|
+
return;
|
|
28
|
+
written.add(session.tag);
|
|
29
|
+
const { record, status } = await providerRecord(session.resourceId, options.usage, options.timeoutMs ?? PROVIDER_RECORD_TIMEOUT_MS);
|
|
30
|
+
const data = {
|
|
31
|
+
tag: session.tag,
|
|
32
|
+
conversation,
|
|
33
|
+
provider: session.provider,
|
|
34
|
+
provider_session_id: session.resourceId,
|
|
35
|
+
started_at: session.createdAt,
|
|
36
|
+
ended_at: session.endedAt ?? new Date().toISOString(),
|
|
37
|
+
release_reason: session.releaseReason,
|
|
38
|
+
provider_record: record,
|
|
39
|
+
provider_record_status: status,
|
|
40
|
+
};
|
|
41
|
+
try {
|
|
42
|
+
await options.commit(async (tx) => void (await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: BROWSER_SESSION_ENDED, data })));
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
written.delete(session.tag);
|
|
46
|
+
log(`the end of browser session ${session.tag} was not recorded (${String(error?.message ?? error).slice(0, 200)}): its usage reads it as not ended`);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
async function providerRecord(id, usage, timeoutMs) {
|
|
51
|
+
if (id === null)
|
|
52
|
+
return { record: null, status: "no_session" };
|
|
53
|
+
if (!usage)
|
|
54
|
+
return { record: null, status: "not_offered" };
|
|
55
|
+
let timer;
|
|
56
|
+
try {
|
|
57
|
+
const signal = AbortSignal.timeout(timeoutMs);
|
|
58
|
+
const read = await Promise.race([usage(id, signal), new Promise((resolve) => { timer = setTimeout(() => resolve("late"), timeoutMs); })]);
|
|
59
|
+
if (read === "late")
|
|
60
|
+
return { record: null, status: "failed" };
|
|
61
|
+
if (read === undefined)
|
|
62
|
+
return { record: null, status: "not_found" };
|
|
63
|
+
return { record: { started_at: read.startedAt, ended_at: read.endedAt, proxy_bytes: read.proxyBytes }, status: "read" };
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return { record: null, status: "failed" };
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
clearTimeout(timer);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const text = (value) => (typeof value === "string" ? value : null);
|
|
73
|
+
const count = (value) => (typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : null);
|
|
74
|
+
const STATUSES = ["read", "not_offered", "not_found", "failed", "no_session"];
|
|
75
|
+
/** A run's browser sessions from its journal `entries`, in the order they were opened: one per tag its root names in an
|
|
76
|
+
* open, an end or a charge. The first end recorded for a tag is its end. */
|
|
77
|
+
export function browserSessionsOf(entries) {
|
|
78
|
+
const sessions = new Map();
|
|
79
|
+
const of = (tag, provider) => {
|
|
80
|
+
let line = sessions.get(tag);
|
|
81
|
+
if (!line) {
|
|
82
|
+
line = { provider, tag, provider_session_id: null, started_at: null, ended_at: null, release_reason: null, charged_seconds: null, provider_record: null, provider_record_status: null };
|
|
83
|
+
sessions.set(tag, line);
|
|
84
|
+
}
|
|
85
|
+
return line;
|
|
86
|
+
};
|
|
87
|
+
const ended = new Set();
|
|
88
|
+
for (const e of entries) {
|
|
89
|
+
const d = (e.data ?? {});
|
|
90
|
+
const tag = text(d.tag);
|
|
91
|
+
if (tag === null)
|
|
92
|
+
continue;
|
|
93
|
+
if (e.kind === BROWSER_SESSION_OPEN)
|
|
94
|
+
of(tag, text(d.provider) ?? "");
|
|
95
|
+
else if (e.kind === BROWSER_CHARGED && d.tool === "browser" && typeof d.seconds === "number" && Number.isFinite(d.seconds)) {
|
|
96
|
+
const line = of(tag, text(d.charged_by) ?? "");
|
|
97
|
+
line.charged_seconds = Math.round(((line.charged_seconds ?? 0) + d.seconds) * 1e6) / 1e6;
|
|
98
|
+
}
|
|
99
|
+
else if (e.kind === BROWSER_SESSION_ENDED && !ended.has(tag)) {
|
|
100
|
+
ended.add(tag);
|
|
101
|
+
const line = of(tag, text(d.provider) ?? "");
|
|
102
|
+
if (line.provider === "")
|
|
103
|
+
line.provider = text(d.provider) ?? "";
|
|
104
|
+
const record = d.provider_record;
|
|
105
|
+
const status = STATUSES.find((one) => one === d.provider_record_status) ?? null;
|
|
106
|
+
Object.assign(line, {
|
|
107
|
+
provider_session_id: text(d.provider_session_id),
|
|
108
|
+
started_at: text(d.started_at),
|
|
109
|
+
ended_at: text(d.ended_at),
|
|
110
|
+
release_reason: text(d.release_reason),
|
|
111
|
+
provider_record: record && typeof record === "object" ? { started_at: text(record.started_at), ended_at: text(record.ended_at), proxy_bytes: count(record.proxy_bytes) } : null,
|
|
112
|
+
provider_record_status: status,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return [...sessions.values()];
|
|
117
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { Refusal } from "@parcha/agentrun-kernel";
|
|
2
|
+
import { type PaidBooking } from "./paid-calls.js";
|
|
3
|
+
/** The resources computer time is priced by. */
|
|
4
|
+
export type ComputeResource = "vcpu" | "memory" | "gpu" | "disk";
|
|
5
|
+
/** The unit each resource's time is counted in. */
|
|
6
|
+
export declare const COMPUTE_UNITS: {
|
|
7
|
+
readonly vcpu: "vcpu_second";
|
|
8
|
+
readonly memory: "gib_second";
|
|
9
|
+
readonly gpu: "gpu_second";
|
|
10
|
+
readonly disk: "gb_month";
|
|
11
|
+
};
|
|
12
|
+
export type ComputeUnit = (typeof COMPUTE_UNITS)[ComputeResource];
|
|
13
|
+
/** A month of disk, as providers bill one: 730 hours. */
|
|
14
|
+
export declare const SECONDS_PER_MONTH: number;
|
|
15
|
+
/** The settings' prefixes, by resource (the provider's name, and a GPU's type, follow in capitals). */
|
|
16
|
+
export declare const COMPUTE_PRICE_ENV: {
|
|
17
|
+
readonly vcpu: "AGENTRUN_COMPUTE_USD_PER_VCPU_SECOND_";
|
|
18
|
+
readonly memory: "AGENTRUN_COMPUTE_USD_PER_GIB_SECOND_";
|
|
19
|
+
readonly gpu: "AGENTRUN_COMPUTE_USD_PER_GPU_SECOND_";
|
|
20
|
+
readonly disk: "AGENTRUN_COMPUTE_USD_PER_DISK_GB_MONTH_";
|
|
21
|
+
};
|
|
22
|
+
/** The setting that prices `resource` of `provider` (a GPU's by its type). */
|
|
23
|
+
export declare const computePriceEnvOf: (resource: ComputeResource, provider: string, gpuType?: string | null) => string;
|
|
24
|
+
/** What a computer held, as its interval keeps it (store computer_intervals): each null where nothing says it. */
|
|
25
|
+
export type ComputeFigures = {
|
|
26
|
+
readonly cpus: number | null;
|
|
27
|
+
readonly memoryMb: number | null;
|
|
28
|
+
readonly gpuType: string | null;
|
|
29
|
+
readonly gpuCount: number | null;
|
|
30
|
+
readonly diskGb: number | null;
|
|
31
|
+
};
|
|
32
|
+
/** One resource of a computer: its line's key (a GPU's by its type), and how many of its unit each second of the
|
|
33
|
+
* computer's life is (null when its figure is unknown). */
|
|
34
|
+
export type ResourceOf = {
|
|
35
|
+
readonly resource: ComputeResource;
|
|
36
|
+
readonly gpuType: string | null;
|
|
37
|
+
readonly perSecond: number | null;
|
|
38
|
+
};
|
|
39
|
+
/** The resources a computer held: its vCPUs and memory always (a figure no one said is null, never 0); its GPUs when it
|
|
40
|
+
* has any; its disk when its provider said it. */
|
|
41
|
+
export declare function resourcesOf(figures: ComputeFigures): ResourceOf[];
|
|
42
|
+
/** Whether `provider`'s descriptor says it bills nothing (Local's Docker): its time is $0, never by its id alone. */
|
|
43
|
+
export declare const unmetered: (provider: string) => boolean;
|
|
44
|
+
/** The operator's price of `resource` of `provider`, in USD per its unit: a non-negative decimal, $0 for a provider
|
|
45
|
+
* that bills nothing; null when none is set or the setting can't be read (unpriced, never $0). */
|
|
46
|
+
export declare function computeRate(provider: string, resource: ComputeResource, gpuType: string | null, env: NodeJS.ProcessEnv): number | null;
|
|
47
|
+
/** One priced resource of a computer: what a second of its life costs (its rate times its figure), with its words. */
|
|
48
|
+
type Priced = ResourceOf & {
|
|
49
|
+
readonly rate: number;
|
|
50
|
+
readonly usdPerSecond: number;
|
|
51
|
+
};
|
|
52
|
+
/** A computer's priced resources: those with a known figure and a price. The rest are unpriced and held by nothing. */
|
|
53
|
+
export declare function pricedOf(provider: string, figures: ComputeFigures, env: NodeJS.ProcessEnv): Priced[];
|
|
54
|
+
/** How long a stretch is: what the claim holds ahead, and how often it books what ran. */
|
|
55
|
+
export declare const COMPUTE_STRETCH_S = 300;
|
|
56
|
+
/** The tool a computer's time names on the run's ledger (GET /runs/{run_id}/usage reads its bookings as compute lines). */
|
|
57
|
+
export declare const COMPUTE_TOOL = "compute";
|
|
58
|
+
/** The tag of a booking of one resource: its resource, and a GPU's type. */
|
|
59
|
+
export declare const computeTag: (one: Pick<ResourceOf, "resource" | "gpuType">) => string;
|
|
60
|
+
/** The run's ledger as the meter books on it, the run's pause for a refusal of the next stretch, and whether its cap can
|
|
61
|
+
* judge a step now (`judges`, RunLedger.judges: false while the run's spec, whose cap it is, is still built). */
|
|
62
|
+
export type ComputeLedger = {
|
|
63
|
+
readonly paid?: PaidBooking;
|
|
64
|
+
readonly pause?: (refusal: Refusal) => Promise<void>;
|
|
65
|
+
readonly judges?: () => boolean;
|
|
66
|
+
};
|
|
67
|
+
/** A hold-only step on the ledger, given back by `drop` (answered once the ledger has it back). */
|
|
68
|
+
type Hold = {
|
|
69
|
+
drop(): Promise<void>;
|
|
70
|
+
};
|
|
71
|
+
/** A computer the claim refused to create: the cap had no room for its first stretch. Its words are the cap's. */
|
|
72
|
+
export declare class ComputeRefused extends Error {
|
|
73
|
+
readonly code = "spend_cap_reached";
|
|
74
|
+
}
|
|
75
|
+
export interface ComputeMeter {
|
|
76
|
+
/** Before the claim creates a computer of `provider` asking for `figures`: one stretch of its priced resources held on
|
|
77
|
+
* the run's ledger (none where nothing is priced, or with no ledger). Refused for room or for good: ComputeRefused, in
|
|
78
|
+
* the cap's words, and nothing should be made. The hold answered is the caller's to hand to `start` (or `drop`). */
|
|
79
|
+
before(provider: string, figures: ComputeFigures): Promise<Hold | undefined>;
|
|
80
|
+
/** The claim holds computer `providerId` of `provider` from now, with `figures` (its provider's where it said them):
|
|
81
|
+
* its time is booked each stretch, the next one held; `ahead` (before's hold) is let go once the first is. */
|
|
82
|
+
start(provider: string, providerId: string, figures: ComputeFigures, ahead?: Hold): void;
|
|
83
|
+
/** The claim lets the computer go (its delete answered ok, or its run's park kept it): the time since its last
|
|
84
|
+
* booking booked, its hold let go. Once; one the meter never started is nothing. */
|
|
85
|
+
stop(provider: string, providerId: string): Promise<void>;
|
|
86
|
+
/** Every computer it holds let go as `stop` does (the claim's release). */
|
|
87
|
+
stopAll(): Promise<void>;
|
|
88
|
+
}
|
|
89
|
+
export type ComputeMeterOptions = {
|
|
90
|
+
readonly env: NodeJS.ProcessEnv;
|
|
91
|
+
readonly ledger: ComputeLedger;
|
|
92
|
+
/** Told each booked stretch of a computer's time, in ms (its interval's booked time, computer-intervals.ts). */
|
|
93
|
+
readonly booked?: (provider: string, providerId: string, ms: number) => Promise<void>;
|
|
94
|
+
readonly now?: () => number;
|
|
95
|
+
/** Runs `tick` every `ms` until the answer is called; default setInterval, unref'd. */
|
|
96
|
+
readonly every?: (tick: () => void, ms: number) => () => void;
|
|
97
|
+
readonly log?: (line: string) => void;
|
|
98
|
+
};
|
|
99
|
+
/** One claim's meter of the computers it holds (ComputeMeter). */
|
|
100
|
+
export declare function computeMeter(options: ComputeMeterOptions): ComputeMeter;
|
|
101
|
+
export {};
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
// Computer time, priced the way providers bill it: by the resources a computer holds, for as long as it holds them. A
|
|
2
|
+
// computer has no size here. Its CPUs, memory, GPUs and disk are the provider's own figures where its answer gives them
|
|
3
|
+
// (CreatedComputer.resources), else what its create asked, else unknown (computer-intervals.ts figuresOf), and the operator
|
|
4
|
+
// sets a price per provider and per resource, as browser time is priced (browser-cost.ts):
|
|
5
|
+
//
|
|
6
|
+
// AGENTRUN_COMPUTE_USD_PER_VCPU_SECOND_<PROVIDER> USD per vCPU-second
|
|
7
|
+
// AGENTRUN_COMPUTE_USD_PER_GIB_SECOND_<PROVIDER> USD per GiB-second of memory
|
|
8
|
+
// AGENTRUN_COMPUTE_USD_PER_GPU_SECOND_<PROVIDER>_<GPU_TYPE> USD per GPU-second, by the provider's own GPU type name
|
|
9
|
+
// AGENTRUN_COMPUTE_USD_PER_DISK_GB_MONTH_<PROVIDER> USD per GB-month of disk (a month: 730 hours)
|
|
10
|
+
//
|
|
11
|
+
// <PROVIDER> and <GPU_TYPE> in capitals, every other character an underscore (daytona, H100 → DAYTONA_H100). No price is
|
|
12
|
+
// built in: a provider whose descriptor bills nothing (metered false) is $0, as is a resource set at 0 (booked at $0, its
|
|
13
|
+
// usage line $0, never `unpriced`), and any other resource with no price set, or
|
|
14
|
+
// with a figure its provider never said, is unpriced: its time is never $0 and never refused. An unpriced resource runs
|
|
15
|
+
// outside the cap, as a tool call with no price does (TOOL_UNMETERED): nothing of it is held or booked, and its usage line
|
|
16
|
+
// says `unpriced`.
|
|
17
|
+
//
|
|
18
|
+
// The cap (computeMeter): a priced computer's time is held on the run's one ledger, under the run's max_cost_usd, one
|
|
19
|
+
// stretch ahead, as browser time is. A claim's first computer is made while the run's spec is built, before its cap can
|
|
20
|
+
// judge: its first stretch is held once the cap can (owed: it is made), so the run's first request is judged beside it,
|
|
21
|
+
// and a cap with no room parks the run there. A computer made once the cap judges (a lost sandbox's new one) has one
|
|
22
|
+
// stretch at what its create asks for held first (a refusal makes nothing, in the cap's words). Each stretch it ran is
|
|
23
|
+
// then booked (owed: its provider is owed it, so the cap never refuses it) and the next stretch held, a refusal of which
|
|
24
|
+
// pauses the run as a browser call's does. Before the run's end or park is written (the spec's beforeRelease: settle),
|
|
25
|
+
// what it ran since is booked and its hold let go, so the end's cost holds it; the moments between that and its delete
|
|
26
|
+
// are no claim's. Time no claim holds (a computer kept
|
|
27
|
+
// past its claim for a follow-up, one deleted after its run ended, one whose delete failed) is booked by none: it is on the
|
|
28
|
+
// usage read (`unheld_quantity`) and in no cap.
|
|
29
|
+
import { PROVIDERS } from "@parcha/agentrun-computer";
|
|
30
|
+
import { paidStep } from "./paid-calls.js";
|
|
31
|
+
import { logLine } from "./print.js";
|
|
32
|
+
/** The unit each resource's time is counted in. */
|
|
33
|
+
export const COMPUTE_UNITS = { vcpu: "vcpu_second", memory: "gib_second", gpu: "gpu_second", disk: "gb_month" };
|
|
34
|
+
/** A month of disk, as providers bill one: 730 hours. */
|
|
35
|
+
export const SECONDS_PER_MONTH = 730 * 3600;
|
|
36
|
+
/** The settings' prefixes, by resource (the provider's name, and a GPU's type, follow in capitals). */
|
|
37
|
+
export const COMPUTE_PRICE_ENV = {
|
|
38
|
+
vcpu: "AGENTRUN_COMPUTE_USD_PER_VCPU_SECOND_",
|
|
39
|
+
memory: "AGENTRUN_COMPUTE_USD_PER_GIB_SECOND_",
|
|
40
|
+
gpu: "AGENTRUN_COMPUTE_USD_PER_GPU_SECOND_",
|
|
41
|
+
disk: "AGENTRUN_COMPUTE_USD_PER_DISK_GB_MONTH_",
|
|
42
|
+
};
|
|
43
|
+
const named = (text) => text.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
44
|
+
/** The setting that prices `resource` of `provider` (a GPU's by its type). */
|
|
45
|
+
export const computePriceEnvOf = (resource, provider, gpuType) => `${COMPUTE_PRICE_ENV[resource]}${named(provider)}${resource === "gpu" ? `_${named(gpuType ?? "")}` : ""}`;
|
|
46
|
+
/** The resources a computer held: its vCPUs and memory always (a figure no one said is null, never 0); its GPUs when it
|
|
47
|
+
* has any; its disk when its provider said it. */
|
|
48
|
+
export function resourcesOf(figures) {
|
|
49
|
+
const gpu = figures.gpuType !== null || figures.gpuCount !== null;
|
|
50
|
+
return [
|
|
51
|
+
{ resource: "vcpu", gpuType: null, perSecond: figures.cpus },
|
|
52
|
+
{ resource: "memory", gpuType: null, perSecond: figures.memoryMb === null ? null : figures.memoryMb / 1024 },
|
|
53
|
+
...(gpu ? [{ resource: "gpu", gpuType: figures.gpuType, perSecond: figures.gpuType === null ? null : figures.gpuCount }] : []),
|
|
54
|
+
...(figures.diskGb !== null ? [{ resource: "disk", gpuType: null, perSecond: figures.diskGb / SECONDS_PER_MONTH }] : []),
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
/** Whether `provider`'s descriptor says it bills nothing (Local's Docker): its time is $0, never by its id alone. */
|
|
58
|
+
export const unmetered = (provider) => PROVIDERS.some((entry) => entry.id === provider && !entry.metered);
|
|
59
|
+
/** The operator's price of `resource` of `provider`, in USD per its unit: a non-negative decimal, $0 for a provider
|
|
60
|
+
* that bills nothing; null when none is set or the setting can't be read (unpriced, never $0). */
|
|
61
|
+
export function computeRate(provider, resource, gpuType, env) {
|
|
62
|
+
if (unmetered(provider))
|
|
63
|
+
return 0;
|
|
64
|
+
if (resource === "gpu" && gpuType === null)
|
|
65
|
+
return null;
|
|
66
|
+
const text = env[computePriceEnvOf(resource, provider, gpuType)]?.trim();
|
|
67
|
+
if (!text || !/^(\d+(\.\d*)?|\.\d+)$/.test(text))
|
|
68
|
+
return null;
|
|
69
|
+
const rate = Number(text);
|
|
70
|
+
return Number.isFinite(rate) ? rate : null;
|
|
71
|
+
}
|
|
72
|
+
/** A computer's priced resources: those with a known figure and a price. The rest are unpriced and held by nothing. */
|
|
73
|
+
export function pricedOf(provider, figures, env) {
|
|
74
|
+
return resourcesOf(figures).flatMap((one) => {
|
|
75
|
+
const rate = computeRate(provider, one.resource, one.gpuType, env);
|
|
76
|
+
return rate === null || one.perSecond === null ? [] : [{ ...one, rate, usdPerSecond: rate * one.perSecond }];
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/** How long a stretch is: what the claim holds ahead, and how often it books what ran. */
|
|
80
|
+
export const COMPUTE_STRETCH_S = 300;
|
|
81
|
+
/** The tool a computer's time names on the run's ledger (GET /runs/{run_id}/usage reads its bookings as compute lines). */
|
|
82
|
+
export const COMPUTE_TOOL = "compute";
|
|
83
|
+
/** The tag of a booking of one resource: its resource, and a GPU's type. */
|
|
84
|
+
export const computeTag = (one) => (one.resource === "gpu" ? `gpu:${one.gpuType ?? ""}` : one.resource);
|
|
85
|
+
/** Up to the millionth of a dollar, so the cap's words name a figure never below the hold. */
|
|
86
|
+
const microUsd = (usd) => Math.ceil(Math.round(usd * 1e12) / 1e6) / 1e6;
|
|
87
|
+
/** A computer the claim refused to create: the cap had no room for its first stretch. Its words are the cap's. */
|
|
88
|
+
export class ComputeRefused extends Error {
|
|
89
|
+
code = "spend_cap_reached";
|
|
90
|
+
}
|
|
91
|
+
const everyDefault = (tick, ms) => {
|
|
92
|
+
const timer = setInterval(tick, ms);
|
|
93
|
+
timer.unref?.();
|
|
94
|
+
return () => clearInterval(timer);
|
|
95
|
+
};
|
|
96
|
+
/** One claim's meter of the computers it holds (ComputeMeter). */
|
|
97
|
+
export function computeMeter(options) {
|
|
98
|
+
const { env, ledger } = options;
|
|
99
|
+
const now = options.now ?? Date.now;
|
|
100
|
+
const every = options.every ?? everyDefault;
|
|
101
|
+
const log = options.log ?? ((line) => void process.stderr.write(`agentrun-serve runner: ${line}\n`));
|
|
102
|
+
let seq = 0;
|
|
103
|
+
/** A hold of `usd` for `provider`'s next stretch: admitted (refused in the cap's words, with its refusal); `owed`, time
|
|
104
|
+
* its provider is already owed (a computer already made), never refused. */
|
|
105
|
+
const holdOf = async (provider, usd, basis, given = {}) => {
|
|
106
|
+
const paid = ledger.paid;
|
|
107
|
+
// Nothing to hold: no ledger, or a stretch of resources whose operator set them at $0.
|
|
108
|
+
if (!paid || usd === 0)
|
|
109
|
+
return { hold: { drop: async () => { } } };
|
|
110
|
+
const id = `compute:${provider}#hold-${(seq += 1)}`;
|
|
111
|
+
try {
|
|
112
|
+
await paid.admit({ id, name: `${provider}'s computer time`, holdUsd: usd, basis, chargedBy: provider, tool: COMPUTE_TOOL, hold: true, ...(given.owed ? { owed: true } : {}) });
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
const capped = error?.code === "spend_cap_reached";
|
|
116
|
+
const given = error;
|
|
117
|
+
const refused = capped ? String(error.message) : `${provider}'s computer time could not be held: ${String(error?.message ?? error)}`;
|
|
118
|
+
return { refused, ...(capped ? { refusal: { refuse: refused, code: "spend_cap_reached", forGood: given.forGood ?? true, ...(given.figures ? { figures: given.figures } : {}) } } : {}) };
|
|
119
|
+
}
|
|
120
|
+
let dropped;
|
|
121
|
+
return { hold: { drop: () => (dropped ??= paid.settle(id, 0, { givenBack: true }).then(() => undefined, () => undefined)) } };
|
|
122
|
+
};
|
|
123
|
+
/** Whether the run's cap can judge a step now: false while the run's spec, whose cap it is, is built. */
|
|
124
|
+
const judging = () => ledger.judges?.() !== false;
|
|
125
|
+
const stretchUsd = (priced) => microUsd(priced.reduce((sum, one) => sum + one.usdPerSecond, 0) * COMPUTE_STRETCH_S);
|
|
126
|
+
const basisOf = (provider, priced) => `${provider}'s computer time for its next ${COMPUTE_STRETCH_S} s: ${priced.map((one) => `${one.perSecond} ${COMPUTE_UNITS[one.resource].replace("_second", "")}${one.gpuType ? ` ${one.gpuType}` : ""} at $${one.rate} a ${COMPUTE_UNITS[one.resource].replace(/^[a-z]+_/, "")}`).join(", ")}`;
|
|
127
|
+
const held = new Map();
|
|
128
|
+
const key = (provider, providerId) => `${provider}\u0000${providerId}`;
|
|
129
|
+
/** The time `one` ran since its last booking, up to `to`, booked on the ledger: one owed step per priced resource, each
|
|
130
|
+
* named by its computer, resource and time (ref), so it is booked once; then its interval's booked time. */
|
|
131
|
+
const book = async (one, to) => {
|
|
132
|
+
// A cap that can't judge yet would keep this booking waiting on the run's spec, which may be what is let go now (a
|
|
133
|
+
// computer deleted because its spec's build failed): nothing is booked, and its time is the run's unheld time.
|
|
134
|
+
if (!judging())
|
|
135
|
+
return;
|
|
136
|
+
const from = one.from;
|
|
137
|
+
const ms = Math.max(0, Math.floor(to - from));
|
|
138
|
+
one.from = from + ms;
|
|
139
|
+
if (ms === 0 || one.priced.length === 0)
|
|
140
|
+
return;
|
|
141
|
+
const paid = ledger.paid;
|
|
142
|
+
if (paid) {
|
|
143
|
+
await Promise.all(one.priced.map(async (resource) => {
|
|
144
|
+
const usd = resource.usdPerSecond * (ms / 1000);
|
|
145
|
+
const tag = computeTag(resource);
|
|
146
|
+
const stepped = await paidStep(paid, undefined, { name: `${one.provider}'s computer time (${tag})`, holdUsd: usd, basis: `${ms / 1000} s of ${resource.perSecond} ${COMPUTE_UNITS[resource.resource]} at $${resource.rate}`, by: one.provider, tool: COMPUTE_TOOL, tag, owed: true, ref: `compute:${one.provider}:${one.providerId}:${tag}@${from}-${from + ms}` }, async () => undefined, () => usd).catch((error) => ({ refused: String(error?.message ?? error) }));
|
|
147
|
+
if ("refused" in stepped)
|
|
148
|
+
log(logLine("compute_spend_unbooked", { said: `${ms / 1000} s of ${one.provider} ${one.providerId}'s ${tag} time was not booked on the run's ledger (${stepped.refused.slice(0, 200)})` }));
|
|
149
|
+
}));
|
|
150
|
+
}
|
|
151
|
+
await options.booked?.(one.provider, one.providerId, ms).catch(() => undefined);
|
|
152
|
+
};
|
|
153
|
+
/** Each stretch: what ran booked, the next stretch held (a refusal pauses the run, once until a hold is taken again). */
|
|
154
|
+
const tick = async (one) => {
|
|
155
|
+
// A stretch that passes while the run's spec is still built (a long image build) waits for the next: what ran is
|
|
156
|
+
// booked from where it was then.
|
|
157
|
+
if (!judging())
|
|
158
|
+
return;
|
|
159
|
+
await book(one, now());
|
|
160
|
+
// The stretch just booked is no longer ahead: its hold is given back, and the ledger has it back, before the next
|
|
161
|
+
// stretch is asked for. Else the cap would count that stretch twice (booked and still held), and refuse a next one
|
|
162
|
+
// it has room for.
|
|
163
|
+
const last = one.hold;
|
|
164
|
+
one.hold = undefined;
|
|
165
|
+
await last?.drop();
|
|
166
|
+
const next = await holdOf(one.provider, stretchUsd(one.priced), basisOf(one.provider, one.priced));
|
|
167
|
+
if ("hold" in next) {
|
|
168
|
+
if (one.stopped)
|
|
169
|
+
await next.hold.drop();
|
|
170
|
+
else
|
|
171
|
+
one.hold = next.hold;
|
|
172
|
+
// Held again (the run's cap was raised, or room came back): a later refusal pauses the run again.
|
|
173
|
+
one.paused = false;
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
if (!one.paused && next.refusal && ledger.pause) {
|
|
177
|
+
one.paused = true;
|
|
178
|
+
await ledger.pause(next.refusal).catch(() => undefined);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
const stop = (provider, providerId) => {
|
|
182
|
+
const one = held.get(key(provider, providerId));
|
|
183
|
+
if (!one)
|
|
184
|
+
return Promise.resolve();
|
|
185
|
+
return (one.stopped ??= (async () => {
|
|
186
|
+
one.cancel();
|
|
187
|
+
await one.ticking;
|
|
188
|
+
await book(one, now());
|
|
189
|
+
const last = one.hold;
|
|
190
|
+
one.hold = undefined;
|
|
191
|
+
await last?.drop();
|
|
192
|
+
held.delete(key(provider, providerId));
|
|
193
|
+
})());
|
|
194
|
+
};
|
|
195
|
+
return {
|
|
196
|
+
async before(provider, figures) {
|
|
197
|
+
const priced = pricedOf(provider, figures, env);
|
|
198
|
+
const usd = stretchUsd(priced);
|
|
199
|
+
// A cap that can't judge yet (the claim's first computer, made while the run's spec is built) holds nothing ahead:
|
|
200
|
+
// the computer's first stretch is held, owed, once it can (start), before the run's first request is judged.
|
|
201
|
+
if (!ledger.paid || usd === 0 || ledger.judges?.() === false)
|
|
202
|
+
return undefined;
|
|
203
|
+
const held = await holdOf(provider, usd, basisOf(provider, priced));
|
|
204
|
+
if ("refused" in held)
|
|
205
|
+
throw new ComputeRefused(held.refused);
|
|
206
|
+
return held.hold;
|
|
207
|
+
},
|
|
208
|
+
start(provider, providerId, figures, ahead) {
|
|
209
|
+
const priced = pricedOf(provider, figures, env);
|
|
210
|
+
const k = key(provider, providerId);
|
|
211
|
+
// A computer with nothing priced is held and booked by nothing (its time unpriced), as is a provider that bills
|
|
212
|
+
// nothing. One whose resources the operator priced at $0 is booked at $0 each stretch, so its usage read says $0
|
|
213
|
+
// (never `unpriced`): nothing of it is held.
|
|
214
|
+
if (held.has(k) || priced.length === 0 || unmetered(provider)) {
|
|
215
|
+
void ahead?.drop();
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const one = { provider, providerId, priced, from: now(), hold: undefined, cancel: () => { }, ticking: Promise.resolve(), paused: false };
|
|
219
|
+
held.set(k, one);
|
|
220
|
+
// Its first stretch held at what it was made with (owed: it is made, so never refused), then the hold taken before
|
|
221
|
+
// its create let go. The stretch's ticks wait for it, so a tick never drops a hold this has not set yet. Made
|
|
222
|
+
// while the run's spec is built, the hold waits for the spec's cap: then nothing waits on it (a stop while the spec
|
|
223
|
+
// fails would wait forever), and the hold, once the cap can judge, is let go at once if the computer was stopped.
|
|
224
|
+
const first = holdOf(provider, stretchUsd(priced), basisOf(provider, priced), { owed: true }).then((answer) => {
|
|
225
|
+
if ("hold" in answer) {
|
|
226
|
+
if (one.stopped)
|
|
227
|
+
void answer.hold.drop();
|
|
228
|
+
else
|
|
229
|
+
one.hold = answer.hold;
|
|
230
|
+
}
|
|
231
|
+
void ahead?.drop();
|
|
232
|
+
});
|
|
233
|
+
if (judging())
|
|
234
|
+
one.ticking = first;
|
|
235
|
+
else
|
|
236
|
+
void first.catch(() => undefined);
|
|
237
|
+
const cancel = every(() => {
|
|
238
|
+
one.ticking = one.ticking.then(() => (one.stopped ? undefined : tick(one))).catch(() => undefined);
|
|
239
|
+
}, COMPUTE_STRETCH_S * 1000);
|
|
240
|
+
one.cancel = () => {
|
|
241
|
+
cancel();
|
|
242
|
+
one.cancel = () => { };
|
|
243
|
+
};
|
|
244
|
+
},
|
|
245
|
+
stop,
|
|
246
|
+
async stopAll() {
|
|
247
|
+
await Promise.all([...held.values()].map((one) => stop(one.provider, one.providerId)));
|
|
248
|
+
},
|
|
249
|
+
};
|
|
250
|
+
}
|
|
@@ -19,20 +19,9 @@ export declare const COMPUTER_ROUTES: ReadonlySet<string>;
|
|
|
19
19
|
export declare const TAKE_OVER_MINUTES: number;
|
|
20
20
|
/** Run `runId`'s desktop or phone, from the store: its kind, whether it is up, and who drives it. */
|
|
21
21
|
export declare function computerViewOf(store: ComputerCallStore, runId: string, options?: ComputerCallOptions): Promise<ComputerViewRead>;
|
|
22
|
-
/** How a request to one of the routes came: by the owner's signed-in page, or with a token (the server's, checked before
|
|
23
|
-
* this); whether this server is API-only (its token is then its backend's, and takes the routes); whether this server
|
|
24
|
-
* has accounts (for the refusal's words); its body. */
|
|
25
|
-
export type ComputerRequest = {
|
|
26
|
-
readonly ownerSession: boolean;
|
|
27
|
-
readonly token: boolean;
|
|
28
|
-
readonly apiOnly: boolean;
|
|
29
|
-
readonly accounts: boolean;
|
|
30
|
-
readonly body?: unknown;
|
|
31
|
-
};
|
|
32
22
|
/**
|
|
33
|
-
* One of our routes (COMPUTER_ROUTES, by its name in serve's route table) for run `runId
|
|
34
|
-
* ApiError.
|
|
35
|
-
*
|
|
36
|
-
* empty body; the hand-back an `outcome` (done or cancelled) at most. Serve's dispatch sends what this answers.
|
|
23
|
+
* One of our routes (COMPUTER_ROUTES, by its name in serve's route table) for run `runId`, with the request's body:
|
|
24
|
+
* { hold, outcome? }, or an ApiError. The caller was admitted already (server.ts). The take-over takes an empty body; the
|
|
25
|
+
* hand-back an `outcome` (done or cancelled) at most. Serve's dispatch sends what this answers.
|
|
37
26
|
*/
|
|
38
|
-
export declare function computerRoute(name: string, runId: string, request:
|
|
27
|
+
export declare function computerRoute(name: string, runId: string, request: unknown, store: ComputerCallStore, options?: ComputerCallOptions): Promise<ComputerHoldAnswer>;
|
package/dist/computer-routes.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// A run's desktop or phone, as its owner takes it: POST /v2/runs/{id}/computer/take-over and POST .../computer/hand-back
|
|
2
2
|
// (the hand-back for every kind: a browser's answers its agent's ask, as POST .../browser/hand-back does). Owner-only, as
|
|
3
|
-
// a run's browser is
|
|
4
|
-
//
|
|
3
|
+
// a run's browser is; server.ts decides who may call them, with GET /v2/runs/{id}/computer, under one guard (the owner's
|
|
4
|
+
// password session, or on an API-only server the server's token). GET /v2/runs/{id}/computer is answered by
|
|
5
5
|
// server.ts from computerView (computer-view.ts) over computerHoldOf; computerViewOf is the store-backed read of the run's
|
|
6
6
|
// computer the take-over tests check against.
|
|
7
7
|
//
|
|
@@ -30,16 +30,12 @@ export async function computerViewOf(store, runId, options = {}) {
|
|
|
30
30
|
return { kind, state: "live", hold: holdShown(hold, await store.commands(runId, 0)).state };
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
|
-
* One of our routes (COMPUTER_ROUTES, by its name in serve's route table) for run `runId
|
|
34
|
-
* ApiError.
|
|
35
|
-
*
|
|
36
|
-
* empty body; the hand-back an `outcome` (done or cancelled) at most. Serve's dispatch sends what this answers.
|
|
33
|
+
* One of our routes (COMPUTER_ROUTES, by its name in serve's route table) for run `runId`, with the request's body:
|
|
34
|
+
* { hold, outcome? }, or an ApiError. The caller was admitted already (server.ts). The take-over takes an empty body; the
|
|
35
|
+
* hand-back an `outcome` (done or cancelled) at most. Serve's dispatch sends what this answers.
|
|
37
36
|
*/
|
|
38
37
|
export async function computerRoute(name, runId, request, store, options = {}) {
|
|
39
|
-
|
|
40
|
-
throw new ApiError("forbidden", request.accounts ? "A run's computer takes the owner's password sign-in in the console, never a token." : "A run's computer takes the owner's password sign-in, and this server has no accounts (AGENTRUN_ACCOUNTS=0).");
|
|
41
|
-
}
|
|
42
|
-
const body = request.body ?? {};
|
|
38
|
+
const body = request ?? {};
|
|
43
39
|
if (typeof body !== "object" || body === null || Array.isArray(body))
|
|
44
40
|
throw new ApiError("input_invalid", "the body is a JSON object");
|
|
45
41
|
const given = body;
|