@plitzi/sdk-runtime 0.0.0-stage → 0.39.3
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 +18 -0
- package/README.md +84 -2
- package/dist/chunks/service-DDDJomiH.mjs +2322 -0
- package/dist/contract/runtime.d.ts +3 -0
- package/dist/functions-api.d.ts +724 -0
- package/dist/host/host.d.ts +42 -0
- package/dist/host/index.d.ts +3 -0
- package/dist/host/index.mjs +107 -0
- package/dist/host/runner.d.ts +11 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.mjs +5 -0
- package/dist/prelude.js +1 -0
- package/dist/runner/cpuMeter.d.ts +35 -0
- package/dist/runner/driver.d.ts +37 -0
- package/dist/runner/guest/bytes.d.ts +27 -0
- package/dist/runner/guest/crypto.d.ts +47 -0
- package/dist/runner/guest/events.d.ts +152 -0
- package/dist/runner/guest/fetch.d.ts +305 -0
- package/dist/runner/guest/install.d.ts +23 -0
- package/dist/runner/guest/types.d.ts +38 -0
- package/dist/runner/index.d.ts +6 -0
- package/dist/runner/index.mjs +1 -0
- package/dist/runner/isolate.d.ts +65 -0
- package/dist/runner/memoryGuard.d.ts +25 -0
- package/dist/runner/prelude.d.ts +10 -0
- package/dist/runner/service.d.ts +76 -0
- package/dist/runner/turns.d.ts +12 -0
- package/package.json +64 -3
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { default as http } from 'node:http';
|
|
2
|
+
import { IsolateRunnerOptions } from './isolate';
|
|
3
|
+
import { MemoryReading, StatsConfig } from '@plitzi/sdk-kernel/stats';
|
|
4
|
+
import { FunctionRunner } from '@plitzi/sdk-shared/functions';
|
|
5
|
+
import { AddressInfo } from 'node:net';
|
|
6
|
+
export type FunctionsRunnerServiceOptions = IsolateRunnerOptions & {
|
|
7
|
+
/** What the platform presents as `Authorization: Bearer <secret>`. Required: a runner anybody reaches runs anybody's code. */
|
|
8
|
+
secret: string;
|
|
9
|
+
port?: number;
|
|
10
|
+
host?: string;
|
|
11
|
+
/**
|
|
12
|
+
* The engine; the isolates in this process by default, warmed before the service listens. It keeps the bundles it
|
|
13
|
+
* runs — this service keeps none of its own — and asks the platform for one it does not have.
|
|
14
|
+
*/
|
|
15
|
+
runner?: FunctionRunner;
|
|
16
|
+
/**
|
|
17
|
+
* What answers plain HTTP besides `/health` — a space runtime's endpoints — behind the same secret as the protocol.
|
|
18
|
+
* Answers whether it took the request; one it did not take is a 404.
|
|
19
|
+
*/
|
|
20
|
+
http?: (req: http.IncomingMessage, res: http.ServerResponse) => Promise<boolean>;
|
|
21
|
+
/**
|
|
22
|
+
* How this runner names itself in its stats (`GET /_stats`, behind the same secret as the protocol): its pool —
|
|
23
|
+
* `runner` by default — its instance, and where `degraded` starts. It always keeps them.
|
|
24
|
+
*/
|
|
25
|
+
stats?: Pick<StatsConfig, 'pool' | 'instance' | 'thresholds'>;
|
|
26
|
+
/**
|
|
27
|
+
* The version its stats say it runs — the deployment's, as its page servers' and workers' say theirs: what tells a
|
|
28
|
+
* rolling deploy, or one stopped half-way, from a pool that is all on one version.
|
|
29
|
+
*/
|
|
30
|
+
version?: string;
|
|
31
|
+
/**
|
|
32
|
+
* The share of its memory limit it takes new invocations up to, from 0 to 1: 0.85 by default. An invocation is taken
|
|
33
|
+
* while what it may hold, whole (`invocationFootprintMb`), fits beside what every invocation it runs was reserved —
|
|
34
|
+
* past it the platform is answered `busy` and places it on another runner, or the runner keeps it until there is room,
|
|
35
|
+
* instead of the process being killed for memory with every invocation in it. `concurrency` is the most it runs at
|
|
36
|
+
* once all the same.
|
|
37
|
+
*/
|
|
38
|
+
memoryShare?: number;
|
|
39
|
+
/**
|
|
40
|
+
* Whether it says it listens (`[Functions] runner listening on …`): what a runner of its own does. A host that runs the
|
|
41
|
+
* service inside something else — a space's runtime — says what it is itself, once, and passes `false`.
|
|
42
|
+
*/
|
|
43
|
+
announce?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* How it stops (`close()`): for `announceMs` its `/health` answers 503 and it takes no new invocation — the platform
|
|
46
|
+
* is answered `busy`, and takes it to another runner — while it keeps running what it has; then what is still
|
|
47
|
+
* running has `graceMs` to end before it is cut. 0 and 10000 by default; `graceMs` at least the longest function's
|
|
48
|
+
* time limit, or a deploy cuts one halfway.
|
|
49
|
+
*/
|
|
50
|
+
shutdown?: {
|
|
51
|
+
announceMs?: number;
|
|
52
|
+
graceMs?: number;
|
|
53
|
+
};
|
|
54
|
+
/** How full the process is; its resident memory against its container's limit by default. For tests. */
|
|
55
|
+
readMemory?: () => MemoryReading;
|
|
56
|
+
};
|
|
57
|
+
export type FunctionsRunnerService = {
|
|
58
|
+
/** Where it listens, once it does. */
|
|
59
|
+
address: () => AddressInfo;
|
|
60
|
+
close: () => Promise<void>;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* What one invocation may hold, in MB, as the runner reserves it: its limit, what isolated-vm lets an isolate grow past
|
|
64
|
+
* it before it is stopped, and an isolate's own (measured: 32 MB → ~40, 128 → ~147, 256 → ~262). Reserved whole from
|
|
65
|
+
* the moment it is taken until it ends — as a Lambda's memory is its own — since a share let invocations that grew
|
|
66
|
+
* together kill the runner, every invocation in it with it. One rule, read by the platform's sizing too.
|
|
67
|
+
*/
|
|
68
|
+
export declare const invocationFootprintMb: (memoryMb: number) => number;
|
|
69
|
+
/**
|
|
70
|
+
* The functions runner as a service: a process that holds no secrets, no database and no documents, and runs the
|
|
71
|
+
* spaces' code in isolates for the platform that authenticates to it. What a sandbox escape reaches is this process.
|
|
72
|
+
*
|
|
73
|
+
* `GET /health` answers 200 for the orchestrator; `GET /_stats` its stats and everything else the WebSocket protocol,
|
|
74
|
+
* behind the secret.
|
|
75
|
+
*/
|
|
76
|
+
export declare const startFunctionsRunnerService: ({ secret, port, host, runner, http: answerHttp, stats: naming, version, memoryShare, announce, shutdown, readMemory, ...isolate }: FunctionsRunnerServiceOptions) => Promise<FunctionsRunnerService>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** How long an isolate holds a turn before one waiting is let in beside it, in ms of holding. */
|
|
2
|
+
export declare const TURN_SLICE_MS = 20;
|
|
3
|
+
/**
|
|
4
|
+
* Turns at running JavaScript, handed out in the order they were asked for: as many running at once as the runner has
|
|
5
|
+
* cores — what keeps them from fighting for its CPU. A turn held past a slice no longer counts against them while others
|
|
6
|
+
* wait: a long run shares the CPU with the next, as a scheduler would, rather than holding every other isolate up. Long
|
|
7
|
+
* runs all at once are the CPU truly short, and the service's own CPU gate turns new invocations away to another runner.
|
|
8
|
+
*/
|
|
9
|
+
export declare const createTurns: (size: number) => {
|
|
10
|
+
take: () => Promise<number>;
|
|
11
|
+
give: (id: number) => void;
|
|
12
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plitzi/sdk-runtime",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.39.3",
|
|
4
|
+
"license": "AGPL-3.0",
|
|
5
|
+
"description": "The contract a space's own code is written against, and what runs it with no access: the functions runner, its isolates, and the host of a space's runtime.",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"@plitzi/source": "./src/index.ts",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.mjs",
|
|
14
|
+
"default": "./dist/index.mjs"
|
|
15
|
+
},
|
|
16
|
+
"./functions-api.d.ts": "./dist/functions-api.d.ts",
|
|
17
|
+
"./*": {
|
|
18
|
+
"@plitzi/source": "./src/*/index.ts",
|
|
19
|
+
"types": "./dist/*/index.d.ts",
|
|
20
|
+
"import": "./dist/*/index.mjs",
|
|
21
|
+
"default": "./dist/*/index.mjs"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "https",
|
|
26
|
+
"url": "https://github.com/plitzi/plitzi-workspace.git"
|
|
27
|
+
},
|
|
28
|
+
"type": "module",
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": "^24.22.1 || >=26.12.1"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"lint": "eslint --cache --cache-location .eslintcache --cache-strategy content ./src",
|
|
35
|
+
"typecheck": "tsc -p tsconfig.app.json --noEmit --incremental --tsBuildInfoFile .tsbuildinfo/app.tsbuildinfo",
|
|
36
|
+
"test": "vitest run",
|
|
37
|
+
"build:dev": "vite build --mode development && node scripts/prelude.mjs && node scripts/functions-api.mjs",
|
|
38
|
+
"build:prod": "vite build && node scripts/prelude.mjs && node scripts/functions-api.mjs"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@plitzi/sdk-kernel": "0.39.3",
|
|
42
|
+
"@plitzi/sdk-shared": "0.39.3",
|
|
43
|
+
"ws": "^8.22.2"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"isolated-vm": "^7.0.1"
|
|
47
|
+
},
|
|
48
|
+
"peerDependenciesMeta": {
|
|
49
|
+
"isolated-vm": {
|
|
50
|
+
"optional": true
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@microsoft/api-extractor": "^7.60.1",
|
|
55
|
+
"@types/node": "^26.6.6",
|
|
56
|
+
"@types/ws": "^8.18.2",
|
|
57
|
+
"core-js": "^3.51.0",
|
|
58
|
+
"esbuild": "^0.28.2",
|
|
59
|
+
"eslint": "^9.39.5",
|
|
60
|
+
"eslint-plugin-import": "^2.32.0",
|
|
61
|
+
"isolated-vm": "^7.0.2",
|
|
62
|
+
"typescript": "^6.0.3",
|
|
63
|
+
"vite": "^8.3.7",
|
|
64
|
+
"vite-plugin-dts": "^5.1.2",
|
|
65
|
+
"vitest": "^5.1.0"
|
|
66
|
+
}
|
|
6
67
|
}
|