@parcha/agentrun-serve 0.1.0-beta.49 → 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 +26 -9
- package/README.md +104 -22
- package/dist/agent-delete.d.ts +3 -2
- package/dist/agent-delete.js +29 -4
- package/dist/api-only.d.ts +7 -10
- package/dist/api-only.js +9 -11
- package/dist/compute-cost.d.ts +101 -0
- package/dist/compute-cost.js +250 -0
- package/dist/console/assets/{index-CR2ZGei1.css → index-D0mr9wfZ.css} +1 -1
- package/dist/console/assets/index-D7G6o-1E.js +720 -0
- package/dist/console/index.html +2 -2
- 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/learn/check.d.ts +8 -5
- package/dist/learn/check.js +25 -24
- package/dist/learn/repick.d.ts +22 -13
- package/dist/learn/repick.js +57 -56
- package/dist/learn/workflow-draft.d.ts +4 -0
- package/dist/learn/workflow-draft.js +10 -7
- package/dist/learned-workflow.js +8 -8
- package/dist/learning-setting.js +2 -2
- package/dist/openapi.js +25 -17
- package/dist/paid-calls.d.ts +13 -6
- package/dist/paid-calls.js +14 -8
- package/dist/run-launch.d.ts +2 -2
- package/dist/run-launch.js +2 -1
- package/dist/run-timeline-served.js +5 -3
- package/dist/run-usage.d.ts +23 -8
- package/dist/run-usage.js +100 -18
- package/dist/runner/adapter-loop.d.ts +4 -0
- package/dist/runner/adapter-loop.js +15 -1
- 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/held.d.ts +4 -1
- package/dist/runner/learning-end.js +9 -4
- package/dist/runner/metrics.d.ts +4 -0
- package/dist/runner/metrics.js +9 -0
- 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/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 +4 -0
- package/dist/server.js +3 -3
- package/dist/store/agent-body.d.ts +2 -3
- package/dist/store/agent-body.js +3 -2
- package/dist/store/postgres/migrations/0023_computer_interval_resources.sql +14 -0
- package/dist/store/schema.d.ts +8 -3
- package/dist/store/schema.js +12 -2
- package/dist/store/sqlite/connection.d.ts +3 -3
- package/dist/store/sqlite/connection.js +3 -3
- package/dist/store/sqlite/store.d.ts +2 -4
- package/dist/store/sqlite/store.js +95 -85
- package/dist/store/store.d.ts +8 -1
- package/dist/store-reads/cap.d.ts +9 -5
- package/dist/store-reads/cap.js +28 -2
- 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-view.d.ts +5 -1
- package/dist/store-view.js +37 -18
- 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 +13 -1
- package/dist/trigger-targets.d.ts +21 -5
- package/dist/trigger-targets.js +13 -10
- 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 +14 -0
- package/dist/workspace/computer-for-claim.js +46 -7
- package/dist/workspace/computer-intervals.d.ts +9 -3
- package/dist/workspace/computer-intervals.js +17 -8
- package/dist/workspace/pieced.d.ts +14 -0
- package/dist/workspace/pieced.js +23 -0
- package/dist/workspace/run-disk.js +32 -12
- 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-Bzn4eUYF.js +0 -715
|
@@ -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
|
+
}
|