@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
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @plitzi/sdk-runtime
|
|
2
|
+
|
|
3
|
+
## 0.39.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @plitzi/sdk-kernel@0.39.3
|
|
8
|
+
- @plitzi/sdk-shared@0.39.3
|
|
9
|
+
|
|
10
|
+
## 0.39.2
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- fad1264: Released with every `@plitzi` package at this version. What changed in each, and what to do when you upgrade, is in
|
|
15
|
+
`@plitzi/cli`'s `CHANGELOG.md`: one copy of the notes, not one per package.
|
|
16
|
+
- Updated dependencies [fad1264]
|
|
17
|
+
- @plitzi/sdk-kernel@0.39.2
|
|
18
|
+
- @plitzi/sdk-shared@0.39.2
|
package/README.md
CHANGED
|
@@ -1,3 +1,85 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @plitzi/sdk-runtime
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The contract a space's own code is written against, and what runs that code with no access: the functions runner, its
|
|
4
|
+
isolates, and the host a space's runtime runs in.
|
|
5
|
+
|
|
6
|
+
It holds nothing of a run. A run's secrets, its store and its log are the platform's, and every `ctx` call the code makes
|
|
7
|
+
is answered there. Neither the page server nor the actions engine is imported here, not even for their types.
|
|
8
|
+
|
|
9
|
+
## Entries
|
|
10
|
+
|
|
11
|
+
| Entry | What it holds |
|
|
12
|
+
|---|---|
|
|
13
|
+
| `@plitzi/sdk-runtime` | The contract: `defineFunctions`, `ActionRefusal`, the `ctx` types (`FunctionContext`, `FunctionTask`…), and `defineRuntime` with its types |
|
|
14
|
+
| `@plitzi/sdk-runtime/runner` | `startFunctionsRunnerService`, the runner as a service of its own, and `createIsolateRunner`, the same isolates in this process |
|
|
15
|
+
| `@plitzi/sdk-runtime/host` | `startSpaceRuntime`, the host a space's runtime runs in, and `createRuntimeRunner` |
|
|
16
|
+
| `@plitzi/sdk-runtime/functions-api.d.ts` | The contract as one declaration file, every type it reaches inlined: what the builder's editor types a space's code with |
|
|
17
|
+
|
|
18
|
+
## A space's functions
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { ActionRefusal, defineFunctions } from '@plitzi/sdk-runtime';
|
|
22
|
+
|
|
23
|
+
export default defineFunctions({
|
|
24
|
+
tasks: [
|
|
25
|
+
{
|
|
26
|
+
namespace: 'shop',
|
|
27
|
+
action: 'quote',
|
|
28
|
+
title: 'Quote',
|
|
29
|
+
params: {},
|
|
30
|
+
run: async ({ zip }, ctx) => {
|
|
31
|
+
if (typeof zip !== 'string') {
|
|
32
|
+
throw new ActionRefusal('A quote needs a zip code');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return { zip, cents: Number(await ctx.kv.get(`rate:${zip}`)) };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Files import each other by relative path, and `@plitzi/sdk-runtime`: nothing else. The platform builds them and runs
|
|
43
|
+
the bundle in an isolate; a self-hosted server loads the same files natively. The whole guide is `docs/en/functions.md`.
|
|
44
|
+
|
|
45
|
+
## Running the code
|
|
46
|
+
|
|
47
|
+
The runner is a service of its own, behind a secret, in a process that reaches nothing:
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { startFunctionsRunnerService } from '@plitzi/sdk-runtime/runner';
|
|
51
|
+
|
|
52
|
+
const secret = process.env.RUNNER_SECRET;
|
|
53
|
+
if (!secret) {
|
|
54
|
+
throw new Error('RUNNER_SECRET is the secret this runner shares with the platform alone');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
await startFunctionsRunnerService({ secret, port: 8790 });
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The isolates are `isolated-vm`'s, an optional peer: a process that runs them installs it and starts Node with
|
|
61
|
+
`--no-node-snapshot`. The web APIs a bare isolate lacks (`URL`, `atob`, `structuredClone`, `DOMException`) come built
|
|
62
|
+
in `dist/prelude.js`, so a runner installs neither core-js nor esbuild.
|
|
63
|
+
|
|
64
|
+
It answers `GET /health` for an orchestrator, and `GET /_stats` behind the same secret: its isolates in flight against
|
|
65
|
+
its `concurrency`, its invocations' outcomes, the protocol it speaks (`@plitzi/sdk-kernel/stats`). What it holds is its
|
|
66
|
+
isolates' budget — invocations at once × about twice `memoryMb` — so its levers are the plan's `memoryMb` (32 MB by
|
|
67
|
+
default), `concurrency`, `cacheBytes` (32 MB) and `memoryShare`, past which it answers `busy`; its own JavaScript is
|
|
68
|
+
little, so it starts well with `--max-semi-space-size=1` beside `--no-node-snapshot`.
|
|
69
|
+
|
|
70
|
+
What holds the runs is handed a runner, never builds one. The page server's `functions.runner` takes a
|
|
71
|
+
`createIsolateRunner()` or the remote client of `@plitzi/sdk-actions/functions`, and so does `createLocalFunctions`,
|
|
72
|
+
what `plitzi functions dev` runs.
|
|
73
|
+
|
|
74
|
+
## A space's runtime
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import { defineRuntime } from '@plitzi/sdk-runtime';
|
|
78
|
+
|
|
79
|
+
export default defineRuntime({
|
|
80
|
+
start: ({ env }) => ({ endpoints: { '/mcp': request => new Response(`hello from ${env.REGION ?? 'here'}`) } })
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The platform starts it with `startSpaceRuntime` (`./host`), and forwards to it the paths it declares. The guide is
|
|
85
|
+
`docs/en/runtimes.md`.
|