@capybara-hq/plugin-sdk 0.1.0-rc.75 → 0.1.0-rc.76
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/dist/device-provider.d.ts +18 -3
- package/dist/device-provider.js +15 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -315,7 +315,20 @@ export interface DeviceServiceStatus {
|
|
|
315
315
|
* `node <codeDir ?? stateDir>/<entry>`, so a provider runs exactly that.
|
|
316
316
|
*/
|
|
317
317
|
codeDir?: string;
|
|
318
|
+
/**
|
|
319
|
+
* The {@link deviceServiceFilesDigest} of the files the running process was started from, when
|
|
320
|
+
* the provider knows it (absent when stopped). The kernel compares it with the spec's files: a
|
|
321
|
+
* running service on other files (an upgraded extension) gets a reviewed start, which restarts
|
|
322
|
+
* it on the new files.
|
|
323
|
+
*/
|
|
324
|
+
filesDigest?: string;
|
|
318
325
|
}
|
|
326
|
+
/**
|
|
327
|
+
* The digest of a service's files: `sha256:` and the hex SHA-256 over each file in path order
|
|
328
|
+
* (path, NUL, byte length, NUL, bytes). Providers report it in {@link DeviceServiceStatus} and
|
|
329
|
+
* may send it to a machine instead of the files.
|
|
330
|
+
*/
|
|
331
|
+
export declare function deviceServiceFilesDigest(files: Record<string, Uint8Array>): string;
|
|
319
332
|
/**
|
|
320
333
|
* A message stream to a device service ({@link DeviceProvider.openStream},
|
|
321
334
|
* `DialInChannel.openStream`): whole messages both ways, flow-controlled by credit.
|
|
@@ -644,8 +657,9 @@ export interface DeviceProvider {
|
|
|
644
657
|
* `<extension>.<name>`, {@link DEVICE_SERVICE_ID_RE}), never by the extension's bare name.
|
|
645
658
|
* It writes `spec.files` into the service's code directory, then runs `spec.entry` with Node, the
|
|
646
659
|
* service socket and state directory named in its environment (`DEVICE_SERVICE_SOCKET_ENV`,
|
|
647
|
-
* `DEVICE_SERVICE_STATE_ENV`). A service already running under the name is kept as is
|
|
648
|
-
*
|
|
660
|
+
* `DEVICE_SERVICE_STATE_ENV`). A service already running under the name is kept as is, unless
|
|
661
|
+
* it runs other files than the spec's: then it is stopped and started on them. The kernel has
|
|
662
|
+
* passed the launch through the command review before it calls this.
|
|
649
663
|
*
|
|
650
664
|
* With `opts.ifRunning` it never starts anything and reads only `spec.name` (the kernel sends
|
|
651
665
|
* `{ name, runtime: "node", entry: "", args: [], files: {} }`, which must not be refused): a
|
|
@@ -653,7 +667,8 @@ export interface DeviceProvider {
|
|
|
653
667
|
* a restart for that runs the spec it was launched with and its stored code (the kernel calls
|
|
654
668
|
* this after the device's allowlist changed, and before reviewing a launch); a stopped one
|
|
655
669
|
* answers its `stopped` status (with `stateDir`, and `codeDir` where kept apart) and stays
|
|
656
|
-
* stopped.
|
|
670
|
+
* stopped. A running one answers its `filesDigest` when known, so the kernel reviews a start on
|
|
671
|
+
* new files before calling this without `ifRunning`.
|
|
657
672
|
*/
|
|
658
673
|
ensureService?(h: SandboxHandle, spec: DeviceServiceSpec, signal: AbortSignal, opts?: {
|
|
659
674
|
ifRunning?: boolean;
|
package/dist/device-provider.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* (`createFileSystem`) lives until the device is deleted (`destroyFileSystem`); instances
|
|
9
9
|
* (`create`) attach to it and come and go (`destroy` drops the instance and keeps the files).
|
|
10
10
|
*/
|
|
11
|
+
import { createHash } from "node:crypto";
|
|
11
12
|
/** Device provider extension point ref. */
|
|
12
13
|
export const DEVICE_PROVIDER_EXTENSION_POINT = "device-provider@1";
|
|
13
14
|
/** The roots inside the sandbox the model may access. */
|
|
@@ -214,6 +215,20 @@ export function deviceServiceId(extension, name) {
|
|
|
214
215
|
throw new TypeError(`Invalid device service ${JSON.stringify(name)} of extension ${JSON.stringify(extension)}`);
|
|
215
216
|
return id;
|
|
216
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* The digest of a service's files: `sha256:` and the hex SHA-256 over each file in path order
|
|
220
|
+
* (path, NUL, byte length, NUL, bytes). Providers report it in {@link DeviceServiceStatus} and
|
|
221
|
+
* may send it to a machine instead of the files.
|
|
222
|
+
*/
|
|
223
|
+
export function deviceServiceFilesDigest(files) {
|
|
224
|
+
const h = createHash("sha256");
|
|
225
|
+
for (const path of Object.keys(files).sort()) {
|
|
226
|
+
const data = files[path];
|
|
227
|
+
h.update(`${path}\0${data.byteLength}\0`);
|
|
228
|
+
h.update(data);
|
|
229
|
+
}
|
|
230
|
+
return `sha256:${h.digest("hex")}`;
|
|
231
|
+
}
|
|
217
232
|
// biome-ignore lint/suspicious/noControlCharactersInRegex: control characters are exactly what must be blocked
|
|
218
233
|
const CONTROL = /[\u0000-\u001f\u007f]/;
|
|
219
234
|
/**
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED