@elaraai/e3-api-server 1.0.104 → 1.0.105
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/README.md +114 -9
- package/dist/src/call-limits.d.ts +72 -0
- package/dist/src/call-limits.d.ts.map +1 -0
- package/dist/src/call-limits.js +104 -0
- package/dist/src/call-limits.js.map +1 -0
- package/dist/src/call-limits.spec.d.ts +6 -0
- package/dist/src/call-limits.spec.d.ts.map +1 -0
- package/dist/src/call-limits.spec.js +264 -0
- package/dist/src/call-limits.spec.js.map +1 -0
- package/dist/src/cli.js +10 -0
- package/dist/src/cli.js.map +1 -1
- package/dist/src/handlers/calls.d.ts +238 -0
- package/dist/src/handlers/calls.d.ts.map +1 -0
- package/dist/src/handlers/calls.js +383 -0
- package/dist/src/handlers/calls.js.map +1 -0
- package/dist/src/handlers/functions.d.ts +40 -9
- package/dist/src/handlers/functions.d.ts.map +1 -1
- package/dist/src/handlers/functions.js +129 -75
- package/dist/src/handlers/functions.js.map +1 -1
- package/dist/src/handlers/functions.spec.js +33 -2
- package/dist/src/handlers/functions.spec.js.map +1 -1
- package/dist/src/handlers/index.d.ts +2 -1
- package/dist/src/handlers/index.d.ts.map +1 -1
- package/dist/src/handlers/index.js +2 -1
- package/dist/src/handlers/index.js.map +1 -1
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/portable.d.ts +2 -1
- package/dist/src/portable.d.ts.map +1 -1
- package/dist/src/portable.js +4 -1
- package/dist/src/portable.js.map +1 -1
- package/dist/src/portable.spec.js +1 -0
- package/dist/src/portable.spec.js.map +1 -1
- package/dist/src/routes/calls.d.ts +81 -0
- package/dist/src/routes/calls.d.ts.map +1 -0
- package/dist/src/routes/calls.js +141 -0
- package/dist/src/routes/calls.js.map +1 -0
- package/dist/src/routes/functions.d.ts +97 -25
- package/dist/src/routes/functions.d.ts.map +1 -1
- package/dist/src/routes/functions.js +147 -30
- package/dist/src/routes/functions.js.map +1 -1
- package/dist/src/routes/index.d.ts +2 -1
- package/dist/src/routes/index.d.ts.map +1 -1
- package/dist/src/routes/index.js +2 -1
- package/dist/src/routes/index.js.map +1 -1
- package/dist/src/server.d.ts +15 -1
- package/dist/src/server.d.ts.map +1 -1
- package/dist/src/server.js +43 -10
- package/dist/src/server.js.map +1 -1
- package/dist/src/types.d.ts +291 -2
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +13 -2
- package/dist/src/types.js.map +1 -1
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -42,6 +42,9 @@ e3-api-server --repo /path/to/repo --oidc
|
|
|
42
42
|
|
|
43
43
|
# Custom port and host
|
|
44
44
|
e3-api-server --repo /path/to/repo --port 8080 --host 0.0.0.0
|
|
45
|
+
|
|
46
|
+
# Longer split calls, and larger results
|
|
47
|
+
e3-api-server --repo /path/to/repo --job-timeout 1h --max-result 8M
|
|
45
48
|
```
|
|
46
49
|
|
|
47
50
|
### CLI Options
|
|
@@ -58,6 +61,13 @@ e3-api-server --repo /path/to/repo --port 8080 --host 0.0.0.0
|
|
|
58
61
|
| `--refresh-token-expiry <duration>` | Refresh token expiry, e.g., "7d", "90d" (default: 90d) |
|
|
59
62
|
| `-j, --jobs <n>` | Cores: runner processes in flight at once, across every run and call the server serves and every upload it takes in (default: `E3_JOBS`, else the CPUs available) |
|
|
60
63
|
| `--memory <size>` | Memory those runner processes may reserve between them, as `8G` or `512M` (default: `E3_MEMORY`, else the memory available, less a reserve for e3 and the OS) |
|
|
64
|
+
| `--call-deadline <duration>` | How long a one-shot call, or a function called through its sync route, may run before it answers, as `90s` or `15m` (default: 120s). A call that names no timeout of its own gets 60s within it |
|
|
65
|
+
| `--job-timeout <duration>` | How long a split call's job, or a kept call — of a workspace's function, or a one-shot started as a call — may run, as `30m` or `2h`, which is also the longest timeout a one-shot call may ask for (default: 10m) |
|
|
66
|
+
| `--max-result <size>` | The largest result a one-shot, split or kept call answers, as `8M` (default: 1M). The server holds a result in memory while it answers it, so a larger limit takes more of it; a split call's larger result is read from its stored output, by its hash |
|
|
67
|
+
| `--max-log <size>` | The most of each of a call's stdout and stderr its answer may carry, as `1M` (default: 256K; a call that names no limit gets 64K) |
|
|
68
|
+
|
|
69
|
+
A malformed value, or one that is not positive, is refused naming its flag,
|
|
70
|
+
and the server does not start.
|
|
61
71
|
|
|
62
72
|
## Programmatic Usage
|
|
63
73
|
|
|
@@ -144,9 +154,41 @@ interface ServerConfig {
|
|
|
144
154
|
|
|
145
155
|
// Runner processes (optional)
|
|
146
156
|
budget?: Budget | BudgetSettings; // Cores and memory every runner the server spawns shares (default: from E3_JOBS / E3_MEMORY, else the machine)
|
|
157
|
+
|
|
158
|
+
// Calls (optional)
|
|
159
|
+
calls?: CallLimits; // A sync call's deadline, the most a call may ask for, and how a kept call is waited for and kept (below)
|
|
147
160
|
}
|
|
148
161
|
```
|
|
149
162
|
|
|
163
|
+
`calls` sets the limits the one-shot, function and split calls run under, as
|
|
164
|
+
the CLI's `--call-deadline`, `--job-timeout`, `--max-result` and `--max-log`
|
|
165
|
+
do (`resolveCallLimits` turns those flags into it), and how the server waits
|
|
166
|
+
for and keeps a call through a workspace — of one of its functions, or a
|
|
167
|
+
one-shot started as a call — which outlives its request:
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
const server = await createServer({
|
|
171
|
+
singleRepoPath: '/path/to/repo',
|
|
172
|
+
calls: {
|
|
173
|
+
syncDeadlineMs: 300_000, // a one-shot or sync function call answers within 5 minutes (default: 120 000)
|
|
174
|
+
ceilings: {
|
|
175
|
+
timeoutMs: 60 * 60_000, // a split call's job, or a kept call, runs up to an hour (default: 10 minutes)
|
|
176
|
+
maxResultBytes: 8 * 1024 ** 2, // results up to 8 MiB are answered inline (default: 1 MiB)
|
|
177
|
+
maxLogBytes: 1024 ** 2, // log tails up to 1 MiB (default: 256 KiB)
|
|
178
|
+
},
|
|
179
|
+
windowMs: 20_000, // a kept call's start waits up to 20 s for it to end (default: 20 000)
|
|
180
|
+
pollWaitMs: 20_000, // a poll of one is held up to 20 s (default: 20 000)
|
|
181
|
+
lifetimes: { succeededMs: 60 * 60_000, failedMs: 7 * 24 * 60 * 60_000 }, // how long one is kept (default: an hour, a week)
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
The deadline applies to one-shot calls and to a function's sync route, and the
|
|
187
|
+
ceilings to one-shot calls, split calls and kept calls, a workspace function's
|
|
188
|
+
or a one-shot's. A limit no call could meet — a deadline, ceiling or lifetime that
|
|
189
|
+
is not positive, or a negative window or wait — makes `createServer` throw a
|
|
190
|
+
`RangeError`.
|
|
191
|
+
|
|
150
192
|
### Mounting the routes on another host
|
|
151
193
|
|
|
152
194
|
The route factories are exported, so a host that runs e3 on its own backends
|
|
@@ -242,7 +284,38 @@ A host whose requests have a time limit gives it to the routes that run a
|
|
|
242
284
|
program for a request, so that each answers its typed outcome before the host
|
|
243
285
|
cuts it off: the function and one-shot routes take `syncDeadlineMs`, and so do
|
|
244
286
|
the record routes, whose mutation and compaction answer `timed_out` or
|
|
245
|
-
`conflict` 2 s under it.
|
|
287
|
+
`conflict` 2 s under it. A call through a workspace outlives any request, so
|
|
288
|
+
its start and its poll are held only while the host allows: the workspace
|
|
289
|
+
function routes and the one-shot routes take `windowMs`, the longest a start
|
|
290
|
+
waits (20 s), and the call routes `pollWaitMs`, the longest a poll is held
|
|
291
|
+
(20 s), which a host whose held requests cost it keeps short. Each takes the
|
|
292
|
+
transfer backend, whose `functionCalls` dispatch runs each call where the host
|
|
293
|
+
runs calls — this server in its own process, e3-cloud on its own compute — and
|
|
294
|
+
the routes read the storage backend's call store for whatever the dispatch
|
|
295
|
+
cannot say, so a poll is answered alike by whichever instance it reaches. A
|
|
296
|
+
one-shot started as a call is held to the one-shot routes' `callCeilings`, the
|
|
297
|
+
most it may ask for, which are their `ceilings` unless the host gives others:
|
|
298
|
+
a host that runs its calls on other compute than its one-shots and split calls
|
|
299
|
+
gives that compute's. Who made a call is `callerOf` (the identity's email, else
|
|
300
|
+
its subject), and who may read or cancel one the call routes' `access`, unset
|
|
301
|
+
here, where every caller the routes admit may.
|
|
302
|
+
|
|
303
|
+
```typescript
|
|
304
|
+
app.route('/api/repos/:repo/workspaces/:ws/functions', createWorkspaceFunctionRoutes(storage, getRepoPath, transferBackend, {
|
|
305
|
+
access, syncDeadlineMs: 25_000, windowMs: 20_000, ceilings: { timeoutMs: 13 * 60_000 },
|
|
306
|
+
}));
|
|
307
|
+
// A one-shot started as a call runs where the calls above run, under their ceilings
|
|
308
|
+
app.route('/api/repos/:repo/workspaces/:ws/one-shot', createOneShotRoutes(storage, getRepoPath, transferBackend, getRunner, {
|
|
309
|
+
access, syncDeadlineMs: 25_000, windowMs: 20_000, callCeilings: { timeoutMs: 13 * 60_000 },
|
|
310
|
+
}));
|
|
311
|
+
app.route('/api/repos/:repo/workspaces/:ws/calls', createWorkspaceCallRoutes(storage, getRepoPath, transferBackend, {
|
|
312
|
+
pollWaitMs: 2_000,
|
|
313
|
+
// An app's users read and cancel the calls they made; an owner any
|
|
314
|
+
access: (c, call) => isOwner(c) || madeBy(call.caller, c),
|
|
315
|
+
}));
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
The record routes' `historyLimit` is how many commits
|
|
246
319
|
a history request that names no `limit` is answered with; the client pages on
|
|
247
320
|
from the last one's parent. Unset, as on this server, neither is bounded. A
|
|
248
321
|
limit no request could meet is refused when the routes are mounted.
|
|
@@ -491,13 +564,20 @@ and its commit takes it in.
|
|
|
491
564
|
|--------|----------|-------------|
|
|
492
565
|
| GET | `/api/repos/:repo/packages/:pkg/:version/functions` | A package's functions and their signatures |
|
|
493
566
|
| GET | `/api/repos/:repo/packages/:pkg/:version/functions/:fn` | One function's signature |
|
|
494
|
-
| POST | `/api/repos/:repo/packages/:pkg/:version/functions/:fn` | Call a package's function with values: its result, inline. A dataset argument is `invalid` here, with no workspace to read it from |
|
|
567
|
+
| POST | `/api/repos/:repo/packages/:pkg/:version/functions/:fn` | Call a package's function with values: its result, inline, within the request, keeping nothing. A dataset argument is `invalid` here, with no workspace to read it from |
|
|
495
568
|
| GET | `/api/repos/:repo/workspaces/:ws/functions` | The deployed package's functions |
|
|
496
569
|
| GET | `/api/repos/:repo/workspaces/:ws/functions/:fn` | One function's signature |
|
|
497
|
-
| POST | `/api/repos/:repo/workspaces/:ws/functions/:fn` |
|
|
498
|
-
| POST | `/api/repos/:repo/workspaces/:ws/
|
|
570
|
+
| POST | `/api/repos/:repo/workspaces/:ws/functions/:fn/calls` | Start a call of one of them, kept for its lifetime: each argument a value, or one of the workspace's datasets, pinned at its hash when the call starts. Waits up to `?wait=` ms for it to end — at most the window, 20 s, which it waits when none is given; `?wait=0` answers at once — and answers its id and status: `completed` with its result, or `running`. `?id=`, a UUIDv7 of now the client chose, names the call, so the client can cancel it before the start answers: one more than five minutes from the server's clock is set aside for an id of the server's, one the workspace keeps a call under already is refused, and one that is no UUIDv7 is refused 400 `bad_request` |
|
|
571
|
+
| POST | `/api/repos/:repo/workspaces/:ws/functions/:fn` | Call one of them within the request: the same call, kept, its timeout clamped under the sync deadline, answered as its result; the result names the inputs and datasets it read (`inputs`) |
|
|
572
|
+
| GET | `/api/repos/:repo/workspaces/:ws/calls` | The workspace's calls, the latest first: `?function=` (a one-shot call names none), `?state=` (a state's tag), `?before=` (the last page's `next`) and `?limit=` (50, at most 200), each with who made it, when, and how it stands or ended |
|
|
573
|
+
| GET | `/api/repos/:repo/workspaces/:ws/calls/:id` | One call whole: its function and package (none for a one-shot), its arguments, the inputs it read, its limits, its value's object, its log tails and when it is forgotten |
|
|
574
|
+
| GET | `/api/repos/:repo/workspaces/:ws/calls/:id/status` | A call's status: `running`; `completed` with its result, its value inline; `cancelled`, naming who asked; or `lost`. Held up to `?wait=` ms, at most `pollWaitMs`, until the call ends |
|
|
575
|
+
| POST | `/api/repos/:repo/workspaces/:ws/calls/:id/cancel` | Ask a running call to stop: its runner is stopped, and it ends `cancelled`, naming who asked. Answers its status once it has stopped, or `running` while it stops; a call that has ended is left as it is |
|
|
576
|
+
| POST | `/api/repos/:repo/workspaces/:ws/one-shot` | Run a caller's program over the workspace's datasets within the request, keeping nothing: its result, naming the datasets it read (`inputs`) |
|
|
577
|
+
| POST | `/api/repos/:repo/workspaces/:ws/one-shot/calls` | Start a caller's program as a call, under the same grant: kept for its lifetime among the workspace's calls, naming no function or package, its dataset arguments pinned at their hashes when it starts. Waits up to `?wait=` ms and takes the client's `?id=` as a function's start does, and answers as it does: its id and status, `completed` with its result, or `running`, which the call routes poll and cancel |
|
|
499
578
|
| POST | `/api/repos/:repo/workspaces/:ws/one-shot/split` | Launch a split call — a caller's program over a dataset's pieces — as a job: answers the job's id; with `?explain=1` the job plans the pieces the call would run, and runs nothing |
|
|
500
|
-
| GET | `/api/repos/:repo/workspaces/:ws/one-shot/split/:id` | Poll a split call: how far it has got, its result, the pieces an explain planned,
|
|
579
|
+
| GET | `/api/repos/:repo/workspaces/:ws/one-shot/split/:id` | Poll a split call: how far it has got, its result, the pieces an explain planned, why it failed, or that it was cancelled |
|
|
580
|
+
| POST | `/api/repos/:repo/workspaces/:ws/one-shot/split/:id/cancel` | Cancel a split call: one still running ends `cancelled`, and its units are stopped; one that has ended is left as it is. Answers its status after, as a poll does |
|
|
501
581
|
|
|
502
582
|
What a caller may run through one-shot is the grant the host gives it
|
|
503
583
|
(`OneShotAccess`). This server's, with auth, gives an elevated role (`admin`,
|
|
@@ -513,12 +593,37 @@ function's own runner does not is refused `permission_denied` (path `runner`)
|
|
|
513
593
|
without the elevated grant. A host that mounts the function routes without
|
|
514
594
|
`access` refuses every caller such a runner.
|
|
515
595
|
|
|
596
|
+
A call through a workspace is the server's, and outlives the request that
|
|
597
|
+
starts it: it is filed — the function as deployed then, its inputs and dataset
|
|
598
|
+
arguments pinned, each value argument stored as an object — run on the server's
|
|
599
|
+
runner, held to its own timeout (the server's job limit, `--job-timeout`, ten
|
|
600
|
+
minutes by default, unless it asks for less), and kept until the lifetime its
|
|
601
|
+
end gives it: an hour for a success
|
|
602
|
+
or a cancel, a week for any other end, with no job run to forget it, since
|
|
603
|
+
every read leaves out a call past its `expiresAt`. A kept call names its
|
|
604
|
+
arguments, the inputs it read and its value by hash, and gc keeps what a live
|
|
605
|
+
call names. A call still recorded running past its deadline and a grace — its
|
|
606
|
+
server stopped before it ended — is answered `lost`. A call found wrong is kept
|
|
607
|
+
`invalid`, answered at once. A workspace's removal removes its calls.
|
|
608
|
+
|
|
609
|
+
A one-shot started as a call (`…/one-shot/calls`) is kept the same way, under
|
|
610
|
+
the caller's one-shot grant: its program is stored and filed with the call as
|
|
611
|
+
an anonymous function, which no package holds and the call alone keeps from
|
|
612
|
+
gc, and the call names no function or package. It runs on the server's runner,
|
|
613
|
+
under the job limit unless it asks for less, and is polled, cancelled and
|
|
614
|
+
listed as a function's call is. e3-ui's query builder runs its queries so,
|
|
615
|
+
through e3-api-client's `oneShotCall`, which runs one within a request
|
|
616
|
+
(`…/one-shot`) on a server that has no such route.
|
|
617
|
+
|
|
516
618
|
A split call runs as a split task, so each
|
|
517
619
|
piece and merge is cached: a relaunch is served from the cache, and one after
|
|
518
620
|
an append reruns only the pieces the append reached. Its timeout is one budget
|
|
519
|
-
for the whole job, counted from its launch
|
|
520
|
-
|
|
521
|
-
|
|
621
|
+
for the whole job, counted from its launch: the server's job limit
|
|
622
|
+
(`--job-timeout`, 10 minutes by default) unless the call asks for less. A call
|
|
623
|
+
is polled, and cancelled, only through the repository and workspace that
|
|
624
|
+
launched it, and a caller with a platform-free grant polls or cancels only a
|
|
625
|
+
platform-free call, or one such a caller launched. A cancel stops the units
|
|
626
|
+
running, and those that finished stay cached, so a relaunch is served them.
|
|
522
627
|
|
|
523
628
|
### Records
|
|
524
629
|
|
|
@@ -558,7 +663,7 @@ Error variants include:
|
|
|
558
663
|
- `package_exists` - Package already exists
|
|
559
664
|
- `dataset_not_found` - Dataset path doesn't exist
|
|
560
665
|
- `task_not_found` - Task doesn't exist
|
|
561
|
-
- `permission_denied` - The caller's grant does not run the request: a one-shot or split call (path `one-shot`),
|
|
666
|
+
- `permission_denied` - The caller's grant does not run the request: a one-shot or split call (path `one-shot`), a function call's runner (path `runner`), or a kept call the host's `access` does not let the caller read or cancel (path `call`)
|
|
562
667
|
- `internal` - Internal server error
|
|
563
668
|
|
|
564
669
|
## Using with e3-api-client
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
import { type ExecuteCeilings, type FunctionCallLifetimes } from '@elaraai/e3-core';
|
|
6
|
+
/**
|
|
7
|
+
* The limits of the calls a server runs: a sync call's deadline, the most a
|
|
8
|
+
* request may ask for, and how a kept call of a workspace's function is
|
|
9
|
+
* waited for and kept.
|
|
10
|
+
*/
|
|
11
|
+
export interface CallLimits {
|
|
12
|
+
/** How long a one-shot or sync function call may run before it answers, in
|
|
13
|
+
* milliseconds: a call's timeout is held under it (default 120 000). A
|
|
14
|
+
* call that names no timeout of its own gets 60 000 within it. */
|
|
15
|
+
syncDeadlineMs?: number;
|
|
16
|
+
/** The most a one-shot call's, a split call's or a function call's request
|
|
17
|
+
* may ask for, through a package or a workspace: the longest timeout, which
|
|
18
|
+
* a split call's job and a kept call take when they name none (default 10
|
|
19
|
+
* minutes); the largest result, which is also a request's default (default
|
|
20
|
+
* 1 MiB); and the most of each log's tail (default 256 KiB). A result is
|
|
21
|
+
* held in the server's memory while it is answered. */
|
|
22
|
+
ceilings?: ExecuteCeilings;
|
|
23
|
+
/** How long a kept call's start waits for it to end before it answers
|
|
24
|
+
* `running`, in milliseconds (default 20 000) */
|
|
25
|
+
windowMs?: number;
|
|
26
|
+
/** The longest a poll of a kept call is held, in milliseconds (default
|
|
27
|
+
* 20 000) */
|
|
28
|
+
pollWaitMs?: number;
|
|
29
|
+
/** How long a kept call is kept once it ends (default: an hour for a
|
|
30
|
+
* success or a cancel, a week for any other end) */
|
|
31
|
+
lifetimes?: FunctionCallLifetimes;
|
|
32
|
+
}
|
|
33
|
+
/** A server's call limits, as `--call-deadline`, `--job-timeout`,
|
|
34
|
+
* `--max-result` and `--max-log` give them. */
|
|
35
|
+
export interface CallLimitSettings {
|
|
36
|
+
/** A sync call's deadline (`--call-deadline`), as `90s` or `15m`. */
|
|
37
|
+
callDeadline?: string;
|
|
38
|
+
/** The longest a split call's job, or a kept call, may run
|
|
39
|
+
* (`--job-timeout`), as `30m` or `2h`. */
|
|
40
|
+
jobTimeout?: string;
|
|
41
|
+
/** The largest result (`--max-result`), as `8M`. */
|
|
42
|
+
maxResult?: string;
|
|
43
|
+
/** The most of each log's tail (`--max-log`), as `1M`. */
|
|
44
|
+
maxLog?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The call limits the flags give, each left to the server's default when its
|
|
48
|
+
* flag is not given.
|
|
49
|
+
*
|
|
50
|
+
* @param settings - The flags given
|
|
51
|
+
* @returns The limits
|
|
52
|
+
* @throws {RangeError} When a value given is not a positive duration or a
|
|
53
|
+
* positive size, or a duration is longer than a timer waits, naming the
|
|
54
|
+
* flag it came from.
|
|
55
|
+
*/
|
|
56
|
+
export declare function resolveCallLimits(settings: CallLimitSettings): CallLimits;
|
|
57
|
+
/**
|
|
58
|
+
* Checks a server's call limits: a limit no call could meet would refuse
|
|
59
|
+
* every one, so the server is told as it is made. A kept call's window and a
|
|
60
|
+
* poll's wait may be 0, which answers at once. A deadline, a timeout, a window
|
|
61
|
+
* and a wait each become a timer, which fires at once past the longest it
|
|
62
|
+
* waits, so none may be longer; a lifetime is a time a call is kept until,
|
|
63
|
+
* and may be.
|
|
64
|
+
*
|
|
65
|
+
* @param limits - The limits
|
|
66
|
+
* @returns The limits
|
|
67
|
+
* @throws {RangeError} When a limit is not a positive number of milliseconds,
|
|
68
|
+
* or of bytes, naming it, or a window or wait is negative, or one that
|
|
69
|
+
* becomes a timer is longer than a timer waits.
|
|
70
|
+
*/
|
|
71
|
+
export declare function checkCallLimits(limits: CallLimits): CallLimits;
|
|
72
|
+
//# sourceMappingURL=call-limits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call-limits.d.ts","sourceRoot":"","sources":["../../src/call-limits.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAe,KAAK,eAAe,EAAE,KAAK,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAGjG;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB;;uEAEmE;IACnE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;4DAKwD;IACxD,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B;sDACkD;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;kBACc;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;yDACqD;IACrD,SAAS,CAAC,EAAE,qBAAqB,CAAC;CACnC;AAED;gDACgD;AAChD,MAAM,WAAW,iBAAiB;IAChC,qEAAqE;IACrE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;+CAC2C;IAC3C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oDAAoD;IACpD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0DAA0D;IAC1D,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAmBD;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,UAAU,CAyBzE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CA0B9D"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
import { parseMemory } from '@elaraai/e3-core';
|
|
6
|
+
import { parseDuration } from './auth/index.js';
|
|
7
|
+
/** The longest a timer waits, in milliseconds: a call's deadline, its timeout,
|
|
8
|
+
* a start's window and a poll's wait each become one, and Node's
|
|
9
|
+
* `setTimeout`, as a browser's, fires at once for a delay past 2^31 - 1 ms,
|
|
10
|
+
* about 24.8 days. */
|
|
11
|
+
const LONGEST_TIMER_MS = 2 ** 31 - 1;
|
|
12
|
+
/** The milliseconds of a duration a flag gives, or `null` when it is not a
|
|
13
|
+
* positive one. */
|
|
14
|
+
function durationMs(text) {
|
|
15
|
+
try {
|
|
16
|
+
const seconds = parseDuration(text.trim());
|
|
17
|
+
return seconds > 0 ? seconds * 1000 : null;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The call limits the flags give, each left to the server's default when its
|
|
25
|
+
* flag is not given.
|
|
26
|
+
*
|
|
27
|
+
* @param settings - The flags given
|
|
28
|
+
* @returns The limits
|
|
29
|
+
* @throws {RangeError} When a value given is not a positive duration or a
|
|
30
|
+
* positive size, or a duration is longer than a timer waits, naming the
|
|
31
|
+
* flag it came from.
|
|
32
|
+
*/
|
|
33
|
+
export function resolveCallLimits(settings) {
|
|
34
|
+
const duration = (flag, text) => {
|
|
35
|
+
const ms = durationMs(text);
|
|
36
|
+
if (ms === null)
|
|
37
|
+
throw new RangeError(`${flag} must be a duration, as 90s, 15m or 2h, got '${text}'`);
|
|
38
|
+
if (ms > LONGEST_TIMER_MS) {
|
|
39
|
+
throw new RangeError(`${flag} must be at most about 24.8 days (${LONGEST_TIMER_MS} ms), the longest a timer waits, got '${text}'`);
|
|
40
|
+
}
|
|
41
|
+
return ms;
|
|
42
|
+
};
|
|
43
|
+
const size = (flag, text) => {
|
|
44
|
+
const bytes = parseMemory(text);
|
|
45
|
+
if (bytes === null) {
|
|
46
|
+
throw new RangeError(`${flag} must be a size in bytes, or with a K, M, G or T suffix (binary units, as 8M), got '${text}'`);
|
|
47
|
+
}
|
|
48
|
+
return bytes;
|
|
49
|
+
};
|
|
50
|
+
const ceilings = {
|
|
51
|
+
...(settings.jobTimeout !== undefined && { timeoutMs: duration('--job-timeout', settings.jobTimeout) }),
|
|
52
|
+
...(settings.maxResult !== undefined && { maxResultBytes: size('--max-result', settings.maxResult) }),
|
|
53
|
+
...(settings.maxLog !== undefined && { maxLogBytes: size('--max-log', settings.maxLog) }),
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
...(settings.callDeadline !== undefined && { syncDeadlineMs: duration('--call-deadline', settings.callDeadline) }),
|
|
57
|
+
...(Object.keys(ceilings).length > 0 && { ceilings }),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Checks a server's call limits: a limit no call could meet would refuse
|
|
62
|
+
* every one, so the server is told as it is made. A kept call's window and a
|
|
63
|
+
* poll's wait may be 0, which answers at once. A deadline, a timeout, a window
|
|
64
|
+
* and a wait each become a timer, which fires at once past the longest it
|
|
65
|
+
* waits, so none may be longer; a lifetime is a time a call is kept until,
|
|
66
|
+
* and may be.
|
|
67
|
+
*
|
|
68
|
+
* @param limits - The limits
|
|
69
|
+
* @returns The limits
|
|
70
|
+
* @throws {RangeError} When a limit is not a positive number of milliseconds,
|
|
71
|
+
* or of bytes, naming it, or a window or wait is negative, or one that
|
|
72
|
+
* becomes a timer is longer than a timer waits.
|
|
73
|
+
*/
|
|
74
|
+
export function checkCallLimits(limits) {
|
|
75
|
+
const check = (name, value, bytes) => {
|
|
76
|
+
if (value === undefined || (bytes ? Number.isSafeInteger(value) : Number.isFinite(value)) && value > 0)
|
|
77
|
+
return;
|
|
78
|
+
throw new RangeError(`calls.${name} must be a positive ${bytes ? 'whole number of bytes' : 'number of milliseconds'}, got ${value}`);
|
|
79
|
+
};
|
|
80
|
+
const checkWait = (name, value) => {
|
|
81
|
+
if (value === undefined || Number.isFinite(value) && value >= 0)
|
|
82
|
+
return;
|
|
83
|
+
throw new RangeError(`calls.${name} must be a number of milliseconds, 0 or more, got ${value}`);
|
|
84
|
+
};
|
|
85
|
+
const checkTimer = (name, value) => {
|
|
86
|
+
if (value === undefined || value <= LONGEST_TIMER_MS)
|
|
87
|
+
return;
|
|
88
|
+
throw new RangeError(`calls.${name} must be at most ${LONGEST_TIMER_MS} ms (about 24.8 days), the longest a timer waits, got ${value}`);
|
|
89
|
+
};
|
|
90
|
+
check('syncDeadlineMs', limits.syncDeadlineMs, false);
|
|
91
|
+
check('ceilings.timeoutMs', limits.ceilings?.timeoutMs, false);
|
|
92
|
+
check('ceilings.maxResultBytes', limits.ceilings?.maxResultBytes, true);
|
|
93
|
+
check('ceilings.maxLogBytes', limits.ceilings?.maxLogBytes, true);
|
|
94
|
+
checkWait('windowMs', limits.windowMs);
|
|
95
|
+
checkWait('pollWaitMs', limits.pollWaitMs);
|
|
96
|
+
check('lifetimes.succeededMs', limits.lifetimes?.succeededMs, false);
|
|
97
|
+
check('lifetimes.failedMs', limits.lifetimes?.failedMs, false);
|
|
98
|
+
checkTimer('syncDeadlineMs', limits.syncDeadlineMs);
|
|
99
|
+
checkTimer('ceilings.timeoutMs', limits.ceilings?.timeoutMs);
|
|
100
|
+
checkTimer('windowMs', limits.windowMs);
|
|
101
|
+
checkTimer('pollWaitMs', limits.pollWaitMs);
|
|
102
|
+
return limits;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=call-limits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call-limits.js","sourceRoot":"","sources":["../../src/call-limits.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAoD,MAAM,kBAAkB,CAAC;AACjG,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AA4ChD;;;uBAGuB;AACvB,MAAM,gBAAgB,GAAG,CAAC,IAAI,EAAE,GAAG,CA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