@plitzi/sdk-runtime 0.39.6 → 0.39.7
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
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @plitzi/sdk-runtime
|
|
2
2
|
|
|
3
|
+
## 0.39.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 081d94e: Released with every `@plitzi` package at this version. What changed in each, and what to do when you upgrade, is in
|
|
8
|
+
`@plitzi/cli`'s `CHANGELOG.md`: one copy of the notes, not one per package.
|
|
9
|
+
- Updated dependencies [081d94e]
|
|
10
|
+
- @plitzi/sdk-kernel@0.39.7
|
|
11
|
+
- @plitzi/sdk-shared@0.39.7
|
|
12
|
+
|
|
3
13
|
## 0.39.6
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -1631,7 +1631,7 @@ var cryptoAnswer = async (message, charge) => {
|
|
|
1631
1631
|
* Sets the guest up in a fresh context: the runner's four calls, taken off the global the moment they are captured,
|
|
1632
1632
|
* and the guest printed from its own source, its web APIs first, a part at a time — with the platform's functions it runs
|
|
1633
1633
|
* as they are (`GuestShared`),
|
|
1634
|
-
* printed from theirs. Answers the driver.
|
|
1634
|
+
* printed from theirs. Answers the driver, with the `settle` the runner hands its answers over by.
|
|
1635
1635
|
*/
|
|
1636
1636
|
var BOOTSTRAP = `(() => {
|
|
1637
1637
|
const refs = { call: __plitziCall, sleep: __plitziSleep, random: __plitziRandom, crypto: __plitziCrypto };
|
|
@@ -1640,11 +1640,26 @@ var BOOTSTRAP = `(() => {
|
|
|
1640
1640
|
delete globalThis.__plitziRandom;
|
|
1641
1641
|
delete globalThis.__plitziCrypto;
|
|
1642
1642
|
const transfer = { arguments: { copy: true }, result: { promise: true, copy: true } };
|
|
1643
|
+
// What the host answers is handed over by its calling \`settle\`, never as the result of the call that asked: an
|
|
1644
|
+
// answer the isolate has no room for then stops this isolate, where as a result it ended the host's process.
|
|
1645
|
+
const asked = new Map();
|
|
1646
|
+
let asking = 0;
|
|
1647
|
+
const ask = (ref, message) =>
|
|
1648
|
+
new Promise(resolve => {
|
|
1649
|
+
asking += 1;
|
|
1650
|
+
asked.set(asking, resolve);
|
|
1651
|
+
ref.applyIgnored(undefined, [asking, message], { arguments: { copy: true } });
|
|
1652
|
+
});
|
|
1653
|
+
const settle = (id, text) => {
|
|
1654
|
+
const heard = asked.get(id);
|
|
1655
|
+
asked.delete(id);
|
|
1656
|
+
if (heard) heard(text);
|
|
1657
|
+
};
|
|
1643
1658
|
const host = {
|
|
1644
|
-
call: message => refs.call
|
|
1659
|
+
call: message => ask(refs.call, message),
|
|
1645
1660
|
sleep: ms => refs.sleep.apply(undefined, [ms], transfer),
|
|
1646
1661
|
random: length => refs.random(length),
|
|
1647
|
-
crypto: message => refs.crypto
|
|
1662
|
+
crypto: message => ask(refs.crypto, message)
|
|
1648
1663
|
};
|
|
1649
1664
|
const bytes = (${guestBytes.toString()})();
|
|
1650
1665
|
const events = (${guestEvents.toString()})(host);
|
|
@@ -1654,7 +1669,8 @@ var BOOTSTRAP = `(() => {
|
|
|
1654
1669
|
fetch: (${guestFetch.toString()})(bytes, events),
|
|
1655
1670
|
crypto: (${guestCrypto.toString()})(host, bytes)
|
|
1656
1671
|
};
|
|
1657
|
-
|
|
1672
|
+
const driver = (${installGuest.toString()})(globalThis, host, { changeKv: ${changeKv.toString()}, changeListEntry: ${changeListEntry.toString()}, describeFunctions: ${describeFunctions.toString()}, createFunctionsDriver: ${createFunctionsDriver.toString()} }, parts);
|
|
1673
|
+
return Object.assign(driver, { settle });
|
|
1658
1674
|
})()`;
|
|
1659
1675
|
var createIsolateRunner = ({ concurrency = 8, cacheBytes = 33554432, turns: turnCount = Math.max(1, Math.round(cpuLimitCores())), cpuMeter: cpu = createCpuMeter(WATCHDOG_MS, cpuLimitCores()) } = {}) => {
|
|
1660
1676
|
const turns = createTurns(turnCount);
|
|
@@ -1769,6 +1785,21 @@ var createIsolateRunner = ({ concurrency = 8, cacheBytes = 33554432, turns: turn
|
|
|
1769
1785
|
}, ms);
|
|
1770
1786
|
timers.add(timer);
|
|
1771
1787
|
};
|
|
1788
|
+
/** The guest's `settle`, once the guest is there: how the code hears back from the host. */
|
|
1789
|
+
let settle;
|
|
1790
|
+
/**
|
|
1791
|
+
* Hands the code what the host answers, by CALLING the guest with it (`settle`) — never as the result of the call
|
|
1792
|
+
* that asked.
|
|
1793
|
+
*
|
|
1794
|
+
* An answer is copied into the isolate once the code is waiting for it. Handed over as the result of the guest's
|
|
1795
|
+
* own call, a copy that takes the isolate past its memory is not stopped by isolated-vm: it throws where nothing
|
|
1796
|
+
* catches (`ivm::FatalRuntimeError`) and the PROCESS ends — the runner, with every other space's invocation in it.
|
|
1797
|
+
* A call the host makes into the guest is run as any other: past its memory the isolate alone is disposed of, and
|
|
1798
|
+
* the invocation ends stopped at its memory, as it would have a line of its own code later.
|
|
1799
|
+
*/
|
|
1800
|
+
const answered = (id, text) => {
|
|
1801
|
+
text.catch((error) => JSON.stringify(failedAnswerOf(error))).then((said) => isolate.isDisposed || !settle ? void 0 : settle.apply(void 0, [id, said], { arguments: { copy: true } })).catch(() => void 0);
|
|
1802
|
+
};
|
|
1772
1803
|
const watchdog = setInterval(() => {
|
|
1773
1804
|
const cpuMs = readCpu();
|
|
1774
1805
|
const over = isolate.isDisposed ? void 0 : clock.overLimit(limits);
|
|
@@ -1788,16 +1819,17 @@ var createIsolateRunner = ({ concurrency = 8, cacheBytes = 33554432, turns: turn
|
|
|
1788
1819
|
const context = isolate.createContextSync();
|
|
1789
1820
|
const global = context.global;
|
|
1790
1821
|
global.setSync("globalThis", global.derefInto());
|
|
1791
|
-
global.setSync("__plitziCall", new ivm.Reference(
|
|
1822
|
+
global.setSync("__plitziCall", new ivm.Reference((id, message) => {
|
|
1792
1823
|
calls++;
|
|
1793
1824
|
if (calls > limits.calls) {
|
|
1794
1825
|
stop("calls");
|
|
1795
|
-
|
|
1826
|
+
answered(id, Promise.resolve(JSON.stringify({
|
|
1796
1827
|
ok: false,
|
|
1797
1828
|
error: stopMessage("calls", limits)
|
|
1798
|
-
});
|
|
1829
|
+
})));
|
|
1830
|
+
return;
|
|
1799
1831
|
}
|
|
1800
|
-
|
|
1832
|
+
answered(id, waitingOn(async () => {
|
|
1801
1833
|
try {
|
|
1802
1834
|
const value = await answer(JSON.parse(message));
|
|
1803
1835
|
return JSON.stringify({
|
|
@@ -1807,7 +1839,7 @@ var createIsolateRunner = ({ concurrency = 8, cacheBytes = 33554432, turns: turn
|
|
|
1807
1839
|
} catch (error) {
|
|
1808
1840
|
return JSON.stringify(failedAnswerOf(error));
|
|
1809
1841
|
}
|
|
1810
|
-
});
|
|
1842
|
+
}));
|
|
1811
1843
|
}));
|
|
1812
1844
|
global.setSync("__plitziSleep", new ivm.Reference((ms) => {
|
|
1813
1845
|
const plan = clock.sleep(ms, limits.wallMs);
|
|
@@ -1823,16 +1855,19 @@ var createIsolateRunner = ({ concurrency = 8, cacheBytes = 33554432, turns: turn
|
|
|
1823
1855
|
}));
|
|
1824
1856
|
}));
|
|
1825
1857
|
global.setSync("__plitziRandom", new ivm.Callback((length) => [...randomBytes(Math.min(Math.max(0, length), 65536))]));
|
|
1826
|
-
global.setSync("__plitziCrypto", new ivm.Reference((
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1858
|
+
global.setSync("__plitziCrypto", new ivm.Reference((id, message) => {
|
|
1859
|
+
answered(id, waitingOn(() => cryptoAnswer(message, (ms) => {
|
|
1860
|
+
clock.chargeHost(ms);
|
|
1861
|
+
if (clock.chargedCpu() > limits.cpuMs) stop("cpu");
|
|
1862
|
+
})));
|
|
1863
|
+
}));
|
|
1830
1864
|
const guestScript = isolate.compileScriptSync(BOOTSTRAP, {
|
|
1831
1865
|
filename: "plitzi:guest",
|
|
1832
1866
|
...guestCache ? { cachedData: guestCache } : { produceCachedData: true }
|
|
1833
1867
|
});
|
|
1834
1868
|
guestCache ??= cachedDataOf(ivm, guestScript);
|
|
1835
1869
|
driver = guestScript.runSync(context, { reference: true });
|
|
1870
|
+
settle = driver.getSync("settle", { reference: true });
|
|
1836
1871
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
1837
1872
|
if (signal?.aborted) onAbort();
|
|
1838
1873
|
const module = isolate.compileModuleSync(entry.code, {
|
package/dist/host/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as describeFunctions, n as startFunctionsRunnerService, s as createFunctionsDriver } from "../chunks/service-
|
|
1
|
+
import { c as describeFunctions, n as startFunctionsRunnerService, s as createFunctionsDriver } from "../chunks/service-BcYwkety.mjs";
|
|
2
2
|
import { ActionRefusal, FunctionFailure, PLATFORM_HEADERS, RUNTIME_DESCRIBE_PATH, changeKv, changeListEntry, endpointFor, endpointProblem, isActionRefusal, requestFromWire, responseOf, wireResponseFrom, wireResponseOf } from "@plitzi/sdk-shared/functions";
|
|
3
3
|
import { webRequestOf, writeWebResponse } from "@plitzi/sdk-kernel/http";
|
|
4
4
|
import { reachSpaceInside } from "@plitzi/sdk-kernel/outbound";
|
|
@@ -34,5 +34,12 @@ export type GuestDriver = {
|
|
|
34
34
|
/** The run was aborted: `ctx.signal` fires, for code that listens, before the runner stops it. */
|
|
35
35
|
abort: (reason: string) => void;
|
|
36
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* What the guest's bootstrap answers: the driver, and how the runner hands the code an answer to what it asked
|
|
39
|
+
* (`host.call`, `host.crypto`) — by calling `settle` with the id the guest asked under, never as that call's result.
|
|
40
|
+
*/
|
|
41
|
+
export type GuestInstalled = GuestDriver & {
|
|
42
|
+
settle: (id: number, text: string) => void;
|
|
43
|
+
};
|
|
37
44
|
/** The bytes every part of the guest reads and writes. */
|
|
38
45
|
export type Bytes = Uint8Array<ArrayBuffer>;
|
package/dist/runner/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { r as PBKDF2_MAX_BITS, i as PBKDF2_MAX_ITERATIONS, o as createCpuMeter, a as createIsolateRunner, t as invocationFootprintMb, n as startFunctionsRunnerService } from "../chunks/service-
|
|
1
|
+
export { r as PBKDF2_MAX_BITS, i as PBKDF2_MAX_ITERATIONS, o as createCpuMeter, a as createIsolateRunner, t as invocationFootprintMb, n as startFunctionsRunnerService } from "../chunks/service-BcYwkety.mjs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plitzi/sdk-runtime",
|
|
3
|
-
"version": "0.39.
|
|
3
|
+
"version": "0.39.7",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
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
6
|
"files": [
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"build:prod": "vite build && node scripts/prelude.mjs && node scripts/functions-api.mjs"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@plitzi/sdk-kernel": "0.39.
|
|
42
|
-
"@plitzi/sdk-shared": "0.39.
|
|
41
|
+
"@plitzi/sdk-kernel": "0.39.7",
|
|
42
|
+
"@plitzi/sdk-shared": "0.39.7",
|
|
43
43
|
"ws": "^8.23.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|