@ai-ecoverse/slicc-kernel 1.182.0 → 1.184.0
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 +150 -5
- package/dist/async-process.js +14060 -0
- package/dist/async-process.js.map +7 -0
- package/dist/cloudflare-sources.js +2 -0
- package/dist/cloudflare.js +42562 -0
- package/dist/cloudflare.js.map +7 -0
- package/dist/driver-worker.js +290 -90
- package/dist/driver-worker.js.map +4 -4
- package/dist/index.js +328 -102
- package/dist/index.js.map +4 -4
- package/dist/kernel-worker.js +1837 -732
- package/dist/kernel-worker.js.map +4 -4
- package/dist/node-driver-worker.js +298 -98
- package/dist/node-driver-worker.js.map +4 -4
- package/dist/node-process-worker.cjs +4719 -652
- package/dist/node-process-worker.cjs.map +4 -4
- package/dist/node-process-worker.js +4719 -652
- package/dist/node-process-worker.js.map +4 -4
- package/dist/node.js +3341 -924
- package/dist/node.js.map +4 -4
- package/dist/process-worker.js +4625 -558
- package/dist/process-worker.js.map +4 -4
- package/dist/types/async/header-hook.d.ts +3 -0
- package/dist/types/async/link.d.ts +14 -0
- package/dist/types/async/message-link.d.ts +15 -0
- package/dist/types/async/node-host.d.ts +16 -0
- package/dist/types/async/remote-worker.d.ts +12 -0
- package/dist/types/async/snapshots.d.ts +13 -0
- package/dist/types/async/transport.d.ts +28 -0
- package/dist/types/async/wire.d.ts +113 -0
- package/dist/types/cdp/port.d.ts +2 -1
- package/dist/types/client/attach.d.ts +2 -0
- package/dist/types/client/protocol.d.ts +1 -0
- package/dist/types/client/serve-client.d.ts +1 -0
- package/dist/types/cloudflare/clock-skew.d.ts +2 -0
- package/dist/types/cloudflare/computer-driver.d.ts +65 -0
- package/dist/types/cloudflare/computer.d.ts +105 -0
- package/dist/types/cloudflare/fork-tokens.d.ts +17 -0
- package/dist/types/cloudflare/images.d.ts +20 -0
- package/dist/types/cloudflare/isolates.d.ts +17 -0
- package/dist/types/cloudflare/kernel-end.d.ts +45 -0
- package/dist/types/cloudflare/loader.d.ts +54 -0
- package/dist/types/cloudflare/options.d.ts +81 -0
- package/dist/types/cloudflare/placement.d.ts +61 -0
- package/dist/types/cloudflare/rpc-link.d.ts +49 -0
- package/dist/types/cloudflare/rpc-pack.d.ts +7 -0
- package/dist/types/cloudflare/sqlite-meta.d.ts +4 -0
- package/dist/types/cloudflare/sqlite-root.d.ts +5 -0
- package/dist/types/cloudflare/sqlite-store.d.ts +73 -0
- package/dist/types/cloudflare.d.ts +16 -0
- package/dist/types/devices-relay.d.ts +74 -0
- package/dist/types/facade/port.d.ts +2 -1
- package/dist/types/index.d.ts +14 -0
- package/dist/types/kernel/devices.d.ts +155 -0
- package/dist/types/kernel/embedder.d.ts +2 -0
- package/dist/types/kernel/fd-table.d.ts +3 -1
- package/dist/types/kernel/host.d.ts +3 -0
- package/dist/types/kernel/process.d.ts +22 -0
- package/dist/types/kernel/protocol.d.ts +1 -0
- package/dist/types/kernel/serial-ioctl.d.ts +73 -0
- package/dist/types/launcher.d.ts +20 -0
- package/dist/types/mount/hostfs.d.ts +2 -1
- package/dist/types/mount/in-process.d.ts +15 -0
- package/dist/types/node.d.ts +20 -2
- package/dist/types/ports.d.ts +7 -0
- package/dist/types/process/js/js-dev.d.ts +24 -0
- package/dist/types/process/kernel-streams.d.ts +11 -1
- package/dist/types/process/process-pty.d.ts +1 -0
- package/dist/types/process/wasi/wasi-fds.d.ts +1 -0
- package/dist/types/process/wasi/wasi-files.d.ts +1 -0
- package/dist/types/process/wasi/wasi-host.d.ts +3 -2
- package/dist/types/process/wasi/wasi-module.d.ts +2 -0
- package/dist/types/process/wasi/wasi-sigmask.d.ts +2 -1
- package/dist/types/process/wasi/wasi-termios.d.ts +1 -0
- package/dist/types/process/wasi/wasm-reentry.d.ts +1 -0
- package/dist/types/realm/sync-sab-bridge.d.ts +1 -0
- package/dist/types/serve.d.ts +14 -1
- package/package.json +11 -5
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { CronClock } from '../cron/clock.js';
|
|
2
|
+
import type { DenialHook } from '../fs/dac.js';
|
|
3
|
+
import type { MetaStore } from '../fs/meta.js';
|
|
4
|
+
import type { Protection } from '../fs/protect.js';
|
|
5
|
+
import type { UsersMode } from '../fs/types.js';
|
|
6
|
+
import type { ConnectOptions, KernelGroups, KernelUsers, RunOptions, RunResult, Terminal, TerminalOptions } from '../index.js';
|
|
7
|
+
import type { EmbedderHook } from '../kernel/embedder.js';
|
|
8
|
+
import type { RouteTable } from '../kernel/net/routes.js';
|
|
9
|
+
import type { SealedOption } from '../kernel/net/sealed-fetch.js';
|
|
10
|
+
import type { NetworkUplink } from '../kernel/net/uplink.js';
|
|
11
|
+
import type { MountEntry, MountSpec } from '../mount/mount-fs.js';
|
|
12
|
+
import type { ProcessMountPolicy } from '../mount/syscall.js';
|
|
13
|
+
import type { ApproveHook } from '../sudo.js';
|
|
14
|
+
import type { NetworkTransport } from '../transport.js';
|
|
15
|
+
import type { Images } from './images.js';
|
|
16
|
+
import type { IsolateGate } from './isolates.js';
|
|
17
|
+
import type { Processes, ProcessHostCode, WorkerLoaderLike } from './loader.js';
|
|
18
|
+
import type { SqliteOptions, SqlStorageLike } from './sqlite-store.js';
|
|
19
|
+
export interface CloudflareKernelOptions {
|
|
20
|
+
loader: WorkerLoaderLike;
|
|
21
|
+
root?: FileSystemDirectoryHandle;
|
|
22
|
+
meta?: MetaStore;
|
|
23
|
+
ranged?: boolean;
|
|
24
|
+
sql?: SqlStorageLike;
|
|
25
|
+
sqlite?: SqliteOptions;
|
|
26
|
+
processHost?: Partial<ProcessHostCode>;
|
|
27
|
+
isolates?: {
|
|
28
|
+
max?: number;
|
|
29
|
+
waitMs?: number;
|
|
30
|
+
memory?: number;
|
|
31
|
+
perInstance?: number;
|
|
32
|
+
};
|
|
33
|
+
clock?: () => Promise<unknown>;
|
|
34
|
+
modules?: string;
|
|
35
|
+
commands?: {
|
|
36
|
+
append?: readonly string[];
|
|
37
|
+
};
|
|
38
|
+
env?: Record<string, string>;
|
|
39
|
+
network?: {
|
|
40
|
+
transport?: NetworkTransport;
|
|
41
|
+
uplink?: NetworkUplink;
|
|
42
|
+
doh?: string | false;
|
|
43
|
+
};
|
|
44
|
+
processMounts?: ProcessMountPolicy;
|
|
45
|
+
hostname?: string;
|
|
46
|
+
timeZone?: string;
|
|
47
|
+
users?: UsersMode;
|
|
48
|
+
onDenial?: DenialHook;
|
|
49
|
+
sealed?: SealedOption;
|
|
50
|
+
requests?: EmbedderHook;
|
|
51
|
+
approve?: ApproveHook;
|
|
52
|
+
protect?: Protection;
|
|
53
|
+
cron?: {
|
|
54
|
+
clock?: CronClock;
|
|
55
|
+
};
|
|
56
|
+
wasmMemories?: {
|
|
57
|
+
ceiling?: number;
|
|
58
|
+
idleMs?: number;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export interface CloudflareKernel {
|
|
62
|
+
readonly root: FileSystemDirectoryHandle;
|
|
63
|
+
readonly images: Images;
|
|
64
|
+
readonly isolates: IsolateGate;
|
|
65
|
+
readonly processes: Processes;
|
|
66
|
+
run(argv: string[], options?: RunOptions): Promise<RunResult>;
|
|
67
|
+
openTerminal(argv: string[], options?: TerminalOptions): Promise<Terminal>;
|
|
68
|
+
writeFile(path: string, data: string | Uint8Array, options?: {
|
|
69
|
+
mode?: number;
|
|
70
|
+
}): Promise<void>;
|
|
71
|
+
readFile(path: string): Promise<Uint8Array>;
|
|
72
|
+
chmod(path: string, mode: number): Promise<void>;
|
|
73
|
+
connect(options?: ConnectOptions): Promise<MessagePort>;
|
|
74
|
+
readonly users: KernelUsers;
|
|
75
|
+
readonly groups: KernelGroups;
|
|
76
|
+
setRoutes(routes: RouteTable): Promise<void>;
|
|
77
|
+
mount(spec: MountSpec): Promise<MountEntry>;
|
|
78
|
+
umount(target: string): Promise<void>;
|
|
79
|
+
mounts(): Promise<MountEntry[]>;
|
|
80
|
+
terminate(): void;
|
|
81
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { IsolateGate } from './isolates.js';
|
|
2
|
+
export declare const ISOLATE_MEMORY_BUDGET: number;
|
|
3
|
+
export declare const INSTANCE_ALLOWANCE: number;
|
|
4
|
+
export declare const MODULE_ALLOWANCE_FACTOR = 3;
|
|
5
|
+
export declare const MAX_SHARDS = 8;
|
|
6
|
+
export declare const DEPTH_RESERVE = 2;
|
|
7
|
+
export interface PlacementOptions {
|
|
8
|
+
budget?: number;
|
|
9
|
+
perInstance?: number;
|
|
10
|
+
waitMs: number;
|
|
11
|
+
}
|
|
12
|
+
export interface Seat {
|
|
13
|
+
readonly id: string;
|
|
14
|
+
readonly shard: number;
|
|
15
|
+
readonly image: string;
|
|
16
|
+
readonly depth: number;
|
|
17
|
+
readonly forking: number;
|
|
18
|
+
memory(bytes: number): void;
|
|
19
|
+
hold(bytes: number): () => void;
|
|
20
|
+
release(): void;
|
|
21
|
+
}
|
|
22
|
+
export interface ImageSize {
|
|
23
|
+
image: string;
|
|
24
|
+
base: string;
|
|
25
|
+
initial: number;
|
|
26
|
+
module: number;
|
|
27
|
+
}
|
|
28
|
+
export declare function shardId(base: string, index: number): string;
|
|
29
|
+
export declare class Placement {
|
|
30
|
+
private readonly shards;
|
|
31
|
+
private readonly waiters;
|
|
32
|
+
private readonly gate;
|
|
33
|
+
readonly budget: number;
|
|
34
|
+
readonly perInstance: number;
|
|
35
|
+
readonly waitMs: number;
|
|
36
|
+
peakShards: number;
|
|
37
|
+
constructor(gate: IsolateGate, options: PlacementOptions);
|
|
38
|
+
shardsOf(base: string): number[];
|
|
39
|
+
used(id: string): number;
|
|
40
|
+
describe(): Record<string, {
|
|
41
|
+
seats: number;
|
|
42
|
+
used: number;
|
|
43
|
+
pending: number;
|
|
44
|
+
holds: number[];
|
|
45
|
+
}>;
|
|
46
|
+
private pending;
|
|
47
|
+
private expected;
|
|
48
|
+
private fits;
|
|
49
|
+
private perShard;
|
|
50
|
+
spare(size: ImageSize, need: number): number;
|
|
51
|
+
private seat;
|
|
52
|
+
private shard;
|
|
53
|
+
private drop;
|
|
54
|
+
private anyLive;
|
|
55
|
+
private lastSlot;
|
|
56
|
+
tryOn(size: ImageSize, index: number, need?: number, depth?: number): Seat | undefined;
|
|
57
|
+
tryPlace(size: ImageSize, need?: number, depth?: number): Seat | undefined;
|
|
58
|
+
place(size: ImageSize, need?: number, depth?: number, parent?: Seat): Promise<Seat>;
|
|
59
|
+
private wake;
|
|
60
|
+
private changed;
|
|
61
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export interface Answer {
|
|
2
|
+
value: unknown;
|
|
3
|
+
held?: number;
|
|
4
|
+
count?: number;
|
|
5
|
+
}
|
|
6
|
+
export interface WireEnd {
|
|
7
|
+
part(bytes: Uint8Array): unknown;
|
|
8
|
+
post(value: unknown, count: number): unknown;
|
|
9
|
+
}
|
|
10
|
+
export interface KernelEndStub extends WireEnd {
|
|
11
|
+
call(value: unknown, count: number, sent?: number): Promise<Answer>;
|
|
12
|
+
take(held: number, index: number): Promise<Uint8Array>;
|
|
13
|
+
dup(): KernelEndStub;
|
|
14
|
+
}
|
|
15
|
+
export interface ProcessEndStub extends WireEnd {
|
|
16
|
+
close(reason: string): Promise<void>;
|
|
17
|
+
settled(): Promise<string>;
|
|
18
|
+
snapshot(token: string, offset: number, max: number): Promise<Uint8Array | null>;
|
|
19
|
+
dup(): ProcessEndStub;
|
|
20
|
+
}
|
|
21
|
+
export declare function dispose(stub: object): void;
|
|
22
|
+
export declare function quietly(result: unknown): void;
|
|
23
|
+
export declare function send(end: WireEnd, message: unknown): void;
|
|
24
|
+
export declare class Inbox {
|
|
25
|
+
private readonly pieces;
|
|
26
|
+
private readonly early;
|
|
27
|
+
private handlers;
|
|
28
|
+
part(bytes: Uint8Array): void;
|
|
29
|
+
take(value: unknown, count: number): unknown;
|
|
30
|
+
deliver(message: unknown): void;
|
|
31
|
+
listen(handler: (message: unknown) => void): void;
|
|
32
|
+
clear(): void;
|
|
33
|
+
}
|
|
34
|
+
export declare class Held {
|
|
35
|
+
private next;
|
|
36
|
+
private readonly answers;
|
|
37
|
+
answer(result: unknown): Answer;
|
|
38
|
+
take(held: number, index: number): Uint8Array;
|
|
39
|
+
clear(): void;
|
|
40
|
+
}
|
|
41
|
+
export declare function answered(end: KernelEndStub, answer: Answer): Promise<unknown>;
|
|
42
|
+
export declare class Closers {
|
|
43
|
+
private readonly handlers;
|
|
44
|
+
private readonly pending;
|
|
45
|
+
reason: string | undefined;
|
|
46
|
+
listen(handler: (reason: string) => void): void;
|
|
47
|
+
guard<T>(work: Promise<T>): Promise<T>;
|
|
48
|
+
close(reason: string): boolean;
|
|
49
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { MetaStore } from '../fs/meta.js';
|
|
2
|
+
import { type SqliteOptions, type SqlStorageLike } from './sqlite-store.js';
|
|
3
|
+
export type { SqlCursorLike, SqliteOptions, SqlStorageLike } from './sqlite-store.js';
|
|
4
|
+
export declare function sqliteMeta(sql: SqlStorageLike, options?: SqliteOptions): MetaStore;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type SqliteOptions, type SqlStorageLike } from './sqlite-store.js';
|
|
2
|
+
export type { SqlCursorLike, SqliteOptions, SqlStorageLike } from './sqlite-store.js';
|
|
3
|
+
export declare const CHUNK_BYTES: number;
|
|
4
|
+
export declare function sqliteRoot(sql: SqlStorageLike, options?: SqliteOptions): FileSystemDirectoryHandle;
|
|
5
|
+
export declare function isSqliteRoot(handle: FileSystemDirectoryHandle): boolean;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export interface SqlCursorLike {
|
|
2
|
+
toArray(): Record<string, unknown>[];
|
|
3
|
+
one(): Record<string, unknown>;
|
|
4
|
+
readonly rowsWritten: number;
|
|
5
|
+
}
|
|
6
|
+
export interface SqlStorageLike {
|
|
7
|
+
exec(query: string, ...bindings: unknown[]): SqlCursorLike;
|
|
8
|
+
transaction?<T>(fn: () => T): T;
|
|
9
|
+
}
|
|
10
|
+
export interface WriteBehindOptions {
|
|
11
|
+
idleMs?: number;
|
|
12
|
+
maxMs?: number;
|
|
13
|
+
maxBytes?: number;
|
|
14
|
+
maxEntries?: number;
|
|
15
|
+
}
|
|
16
|
+
export interface SqliteOptions {
|
|
17
|
+
transaction?: <T>(fn: () => T) => T;
|
|
18
|
+
writeBehind?: boolean | WriteBehindOptions;
|
|
19
|
+
}
|
|
20
|
+
export interface Overlay {
|
|
21
|
+
flushInto(store: SqlStore): void;
|
|
22
|
+
flushed(): void;
|
|
23
|
+
}
|
|
24
|
+
interface Behind {
|
|
25
|
+
idleMs: number;
|
|
26
|
+
maxMs: number;
|
|
27
|
+
maxBytes: number;
|
|
28
|
+
maxEntries: number;
|
|
29
|
+
}
|
|
30
|
+
export interface FlushStats {
|
|
31
|
+
flushes: number;
|
|
32
|
+
pending: boolean;
|
|
33
|
+
}
|
|
34
|
+
export declare const SCHEMA_VERSION = 1;
|
|
35
|
+
export declare class SqlStore {
|
|
36
|
+
readonly sql: SqlStorageLike;
|
|
37
|
+
transaction: (<T>(fn: () => T) => T) | undefined;
|
|
38
|
+
behind: Behind | undefined;
|
|
39
|
+
private depth;
|
|
40
|
+
private holds;
|
|
41
|
+
private readonly overlays;
|
|
42
|
+
private dirtyBytes;
|
|
43
|
+
private dirtyEntries;
|
|
44
|
+
private firstDirty;
|
|
45
|
+
private lastDirty;
|
|
46
|
+
private timer;
|
|
47
|
+
private flushing;
|
|
48
|
+
private failures;
|
|
49
|
+
flushes: number;
|
|
50
|
+
constructor(sql: SqlStorageLike, options?: SqliteOptions);
|
|
51
|
+
configure(options: SqliteOptions): void;
|
|
52
|
+
register(overlay: Overlay): void;
|
|
53
|
+
get dirty(): boolean;
|
|
54
|
+
changed(entries: number, bytes: number): void;
|
|
55
|
+
batch<T>(fn: () => T): T;
|
|
56
|
+
settle(): void;
|
|
57
|
+
private schedule;
|
|
58
|
+
private tick;
|
|
59
|
+
flush(extra?: () => void): void;
|
|
60
|
+
stats(): FlushStats;
|
|
61
|
+
rows(query: string, ...bindings: unknown[]): Record<string, unknown>[];
|
|
62
|
+
row(query: string, ...bindings: unknown[]): Record<string, unknown> | undefined;
|
|
63
|
+
run(query: string, ...bindings: unknown[]): number;
|
|
64
|
+
atomically<T>(fn: () => T): T;
|
|
65
|
+
private current;
|
|
66
|
+
private migrate;
|
|
67
|
+
}
|
|
68
|
+
export declare function storeOf(sql: SqlStorageLike, options?: SqliteOptions): SqlStore;
|
|
69
|
+
export declare function encodeText(text: string): Uint8Array;
|
|
70
|
+
export declare function decodeText(value: unknown): string;
|
|
71
|
+
export declare function bytesOf(value: unknown): Uint8Array;
|
|
72
|
+
export declare function sqliteFlush(sql: SqlStorageLike): FlushStats;
|
|
73
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CloudflareKernel, CloudflareKernelOptions } from './cloudflare/options.js';
|
|
2
|
+
import { memoryRoot } from './node/memory-root.js';
|
|
3
|
+
export { attachKernel, type KernelClient } from './client/attach.js';
|
|
4
|
+
export { type ExecEvent, type KillSignalName, type ShellExecInput, type SliccBackend, type SliccBackendHandle, type SliccBackendHost, type SliccBackendOptions, type SliccKernelLike, sliccBackend, type WorkspaceDirentLike, type WorkspaceDriver, type WorkspaceDriverOptions, type WorkspaceFilesystemLike, type WorkspaceStatLike, workspaceDriver, } from './cloudflare/computer.js';
|
|
5
|
+
export { type ImageHandle, Images } from './cloudflare/images.js';
|
|
6
|
+
export { ISOLATE_WAIT_MS, IsolateGate, MAX_ISOLATES } from './cloudflare/isolates.js';
|
|
7
|
+
export { cloudflareProcesses, type Processes, type ProcessHostCode, type WorkerCode, type WorkerLoaderLike, } from './cloudflare/loader.js';
|
|
8
|
+
export type { CloudflareKernel, CloudflareKernelOptions } from './cloudflare/options.js';
|
|
9
|
+
export { sqliteMeta } from './cloudflare/sqlite-meta.js';
|
|
10
|
+
export { isSqliteRoot, sqliteRoot } from './cloudflare/sqlite-root.js';
|
|
11
|
+
export type { FlushStats, SqlCursorLike, SqliteOptions, SqlStorageLike, WriteBehindOptions, } from './cloudflare/sqlite-store.js';
|
|
12
|
+
export { sqliteFlush } from './cloudflare/sqlite-store.js';
|
|
13
|
+
export { memoryRoot };
|
|
14
|
+
export declare const PROCESS_HOST_SOURCE: string;
|
|
15
|
+
export declare const ASYNC_PROCESS_SOURCE: string | undefined;
|
|
16
|
+
export declare function createCloudflareKernel(options: CloudflareKernelOptions): Promise<CloudflareKernel>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { DeviceHook, DeviceStamp } from './kernel/devices.js';
|
|
2
|
+
export interface DevicesPort {
|
|
3
|
+
postMessage(message: unknown, transfer?: Transferable[]): void;
|
|
4
|
+
}
|
|
5
|
+
interface Failure {
|
|
6
|
+
name: string;
|
|
7
|
+
message: string;
|
|
8
|
+
}
|
|
9
|
+
export type DevicesToPage = {
|
|
10
|
+
id: number;
|
|
11
|
+
open: {
|
|
12
|
+
client: number;
|
|
13
|
+
path: string;
|
|
14
|
+
flags: number;
|
|
15
|
+
stamp: DeviceStamp;
|
|
16
|
+
};
|
|
17
|
+
} | {
|
|
18
|
+
id: number;
|
|
19
|
+
pull: true;
|
|
20
|
+
} | {
|
|
21
|
+
id: number;
|
|
22
|
+
write: Uint8Array;
|
|
23
|
+
seq: number;
|
|
24
|
+
} | {
|
|
25
|
+
id: number;
|
|
26
|
+
control: {
|
|
27
|
+
seq: number;
|
|
28
|
+
op: string;
|
|
29
|
+
args?: object;
|
|
30
|
+
};
|
|
31
|
+
} | {
|
|
32
|
+
id: number;
|
|
33
|
+
cancel: string;
|
|
34
|
+
};
|
|
35
|
+
export type DevicesToKernel = {
|
|
36
|
+
id: number;
|
|
37
|
+
opened: true;
|
|
38
|
+
} | {
|
|
39
|
+
id: number;
|
|
40
|
+
failed: Failure;
|
|
41
|
+
} | {
|
|
42
|
+
id: number;
|
|
43
|
+
chunk: Uint8Array;
|
|
44
|
+
} | {
|
|
45
|
+
id: number;
|
|
46
|
+
done: true;
|
|
47
|
+
} | {
|
|
48
|
+
id: number;
|
|
49
|
+
readError: Failure;
|
|
50
|
+
} | {
|
|
51
|
+
id: number;
|
|
52
|
+
wrote: number;
|
|
53
|
+
} | {
|
|
54
|
+
id: number;
|
|
55
|
+
writeError: Failure;
|
|
56
|
+
seq: number;
|
|
57
|
+
} | {
|
|
58
|
+
id: number;
|
|
59
|
+
answered: number;
|
|
60
|
+
value?: unknown;
|
|
61
|
+
} | {
|
|
62
|
+
id: number;
|
|
63
|
+
refused: number;
|
|
64
|
+
error: Failure;
|
|
65
|
+
};
|
|
66
|
+
export declare function devicesAsker(port: DevicesPort): {
|
|
67
|
+
hookFor: (client: number) => DeviceHook;
|
|
68
|
+
answer: (message: DevicesToKernel) => void;
|
|
69
|
+
};
|
|
70
|
+
export declare function devicesAnswerer(port: DevicesPort, hookFor: (client: number) => DeviceHook | undefined): {
|
|
71
|
+
handle(data: unknown): boolean;
|
|
72
|
+
};
|
|
73
|
+
export declare function devicesReplyOf(data: unknown): DevicesToKernel | undefined;
|
|
74
|
+
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type MakePortPair } from '../ports.js';
|
|
1
2
|
import type { FacadeHook, FacadeOpenRequest } from './types.js';
|
|
2
3
|
export interface FacadePortLike {
|
|
3
4
|
postMessage(message: unknown, transfer?: Transferable[]): void;
|
|
@@ -13,4 +14,4 @@ export interface FacadeOpen {
|
|
|
13
14
|
}
|
|
14
15
|
export declare const FACADE_GONE = "the facade host is gone";
|
|
15
16
|
export declare function serveFacadePort(port: FacadePortLike, hook: FacadeHook, { name, stamp }: FacadeOpenRequest, onDone?: () => void): () => void;
|
|
16
|
-
export declare function portFacadeHook(ask: (request: FacadeOpenRequest, port: FacadePortLike) => void, gone?: Promise<unknown
|
|
17
|
+
export declare function portFacadeHook(ask: (request: FacadeOpenRequest, port: FacadePortLike) => void, gone?: Promise<unknown>, ports?: MakePortPair): FacadeHook;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type { DenialHook } from './fs/dac.js';
|
|
|
8
8
|
import { type Protection } from './fs/protect.js';
|
|
9
9
|
import { type UsersMode } from './fs/types.js';
|
|
10
10
|
import type { ClipboardHook } from './kernel/clipboard.js';
|
|
11
|
+
import { type DeviceHook, type DeviceSpec } from './kernel/devices.js';
|
|
11
12
|
import { type EmbedderHook } from './kernel/embedder.js';
|
|
12
13
|
import type { RouteTable } from './kernel/net/routes.js';
|
|
13
14
|
import { type SealedOption } from './kernel/net/sealed-fetch.js';
|
|
@@ -26,6 +27,7 @@ export type { FacadeConnection, FacadeHook, FacadeInfo, FacadeSpec, FacadeSpecs,
|
|
|
26
27
|
export type { Attestation, AttestedDir, AttestOptions, AttestTombstone } from './fs/attest.js';
|
|
27
28
|
export type { Denial, DenialHook } from './fs/dac.js';
|
|
28
29
|
export type { ClipboardHook, ClipboardStamp } from './kernel/clipboard.js';
|
|
30
|
+
export type { DeviceHook, DeviceOpenRequest, DeviceSignals, DeviceSpec, DeviceStamp, DeviceStreams, } from './kernel/devices.js';
|
|
29
31
|
export type { EmbedderHook, EmbedderKindPolicy, EmbedderReply, EmbedderRequest, EmbedderStamp, } from './kernel/embedder.js';
|
|
30
32
|
export type { RouteTable } from './kernel/net/routes.js';
|
|
31
33
|
export { SEALED_FETCH_VERSION, type SealedFetchHook, type SealedFetchRequest, type SealedOption, } from './kernel/net/sealed-fetch.js';
|
|
@@ -79,6 +81,7 @@ export interface KernelOptions {
|
|
|
79
81
|
sealed?: SealedOption;
|
|
80
82
|
clipboard?: ClipboardHook;
|
|
81
83
|
requests?: EmbedderHook;
|
|
84
|
+
devices?: DeviceHook;
|
|
82
85
|
approve?: ApproveHook;
|
|
83
86
|
protect?: Protection;
|
|
84
87
|
}
|
|
@@ -108,6 +111,16 @@ export interface ConnectOptions {
|
|
|
108
111
|
user?: string | number;
|
|
109
112
|
tag?: string;
|
|
110
113
|
requests?: EmbedderHook | 'attach';
|
|
114
|
+
devices?: DeviceHook | 'attach';
|
|
115
|
+
}
|
|
116
|
+
export interface DeviceAddOptions extends DeviceSpec {
|
|
117
|
+
client?: MessagePort;
|
|
118
|
+
}
|
|
119
|
+
export interface DeviceNodeHandle {
|
|
120
|
+
remove(): Promise<void>;
|
|
121
|
+
}
|
|
122
|
+
export interface KernelDevices {
|
|
123
|
+
add(spec: DeviceAddOptions): Promise<DeviceNodeHandle>;
|
|
111
124
|
}
|
|
112
125
|
export interface KernelGroups {
|
|
113
126
|
list(): Promise<Group[]>;
|
|
@@ -134,6 +147,7 @@ export interface Kernel {
|
|
|
134
147
|
sudoRun(request: SudoReplay, options?: SudoRunOptions): Promise<SudoRun>;
|
|
135
148
|
readonly users: KernelUsers;
|
|
136
149
|
readonly groups: KernelGroups;
|
|
150
|
+
readonly devices: KernelDevices;
|
|
137
151
|
setRoutes(routes: RouteTable): Promise<void>;
|
|
138
152
|
chmod(path: string, mode: number): Promise<void>;
|
|
139
153
|
readonly integrity: KernelIntegrity;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { type Guard } from '../fs/dac.js';
|
|
2
|
+
import type { UsersMode } from '../fs/types.js';
|
|
3
|
+
import { KernelError, type OpenAccess, OpenFile } from './fd-table.js';
|
|
4
|
+
import { type SerialSettings, type SerialTermios } from './serial-ioctl.js';
|
|
5
|
+
import { KernelTty, type Termios } from './tty.js';
|
|
6
|
+
export declare const DEVICE_NAME: RegExp;
|
|
7
|
+
export declare const BY_ID = "/dev/serial/by-id";
|
|
8
|
+
export interface DeviceSignals {
|
|
9
|
+
clearToSend: boolean;
|
|
10
|
+
dataCarrierDetect: boolean;
|
|
11
|
+
dataSetReady: boolean;
|
|
12
|
+
ringIndicator: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface DeviceStreams {
|
|
15
|
+
readable: ReadableStream<Uint8Array>;
|
|
16
|
+
writable: WritableStream<Uint8Array>;
|
|
17
|
+
control(op: string, args?: object): unknown;
|
|
18
|
+
}
|
|
19
|
+
export interface DeviceStamp {
|
|
20
|
+
pid: number;
|
|
21
|
+
uid: number;
|
|
22
|
+
gid: number;
|
|
23
|
+
groups: number[];
|
|
24
|
+
users: UsersMode;
|
|
25
|
+
tag?: string;
|
|
26
|
+
tags?: string[];
|
|
27
|
+
}
|
|
28
|
+
export interface DeviceOpenRequest {
|
|
29
|
+
path: string;
|
|
30
|
+
flags: number;
|
|
31
|
+
stamp: DeviceStamp;
|
|
32
|
+
signal: AbortSignal;
|
|
33
|
+
}
|
|
34
|
+
export interface DeviceHook {
|
|
35
|
+
open(request: DeviceOpenRequest): DeviceStreams | Promise<DeviceStreams>;
|
|
36
|
+
}
|
|
37
|
+
export interface DeviceSpec {
|
|
38
|
+
path: string;
|
|
39
|
+
owner?: string | number;
|
|
40
|
+
group?: string | number;
|
|
41
|
+
mode?: number;
|
|
42
|
+
links?: readonly string[];
|
|
43
|
+
}
|
|
44
|
+
export interface DeviceNodeInfo {
|
|
45
|
+
path: string;
|
|
46
|
+
uid: number;
|
|
47
|
+
gid: number;
|
|
48
|
+
mode: number;
|
|
49
|
+
major: number;
|
|
50
|
+
minor: number;
|
|
51
|
+
links: string[];
|
|
52
|
+
atimeMs: number;
|
|
53
|
+
mtimeMs: number;
|
|
54
|
+
ctimeMs: number;
|
|
55
|
+
}
|
|
56
|
+
export interface DeviceMetaChange {
|
|
57
|
+
mode?: number;
|
|
58
|
+
uid?: number;
|
|
59
|
+
gid?: number;
|
|
60
|
+
atimeMs?: number | null;
|
|
61
|
+
mtimeMs?: number | null;
|
|
62
|
+
now?: boolean;
|
|
63
|
+
}
|
|
64
|
+
export interface DeviceLookup {
|
|
65
|
+
userId(name: string): Promise<number | undefined>;
|
|
66
|
+
groupId(name: string): Promise<number | undefined>;
|
|
67
|
+
}
|
|
68
|
+
interface DeviceState {
|
|
69
|
+
termios: Termios;
|
|
70
|
+
ispeed: number;
|
|
71
|
+
ospeed: number;
|
|
72
|
+
}
|
|
73
|
+
interface DeviceNode extends DeviceNodeInfo {
|
|
74
|
+
id: number;
|
|
75
|
+
client: number;
|
|
76
|
+
channel?: DeviceChannel;
|
|
77
|
+
opening: boolean;
|
|
78
|
+
saved?: DeviceState;
|
|
79
|
+
}
|
|
80
|
+
export interface DeviceOpener {
|
|
81
|
+
stamp: DeviceStamp;
|
|
82
|
+
guard?: Guard;
|
|
83
|
+
signal: AbortSignal;
|
|
84
|
+
}
|
|
85
|
+
export declare function devicesHook(hook: DeviceHook): DeviceHook;
|
|
86
|
+
export declare class DeviceNodes {
|
|
87
|
+
private readonly hooks;
|
|
88
|
+
private readonly nodes;
|
|
89
|
+
private readonly links;
|
|
90
|
+
private readonly lookup;
|
|
91
|
+
readonly users: UsersMode;
|
|
92
|
+
private next;
|
|
93
|
+
constructor(users: UsersMode, lookup: DeviceLookup);
|
|
94
|
+
register(client: number, hook: DeviceHook): () => void;
|
|
95
|
+
add(spec: DeviceSpec, client: number): Promise<number>;
|
|
96
|
+
remove(id: number): boolean;
|
|
97
|
+
private drop;
|
|
98
|
+
list(): DeviceNodeInfo[];
|
|
99
|
+
meta(path: string, change: DeviceMetaChange, guard?: Guard): void;
|
|
100
|
+
find(path: string): DeviceNode | undefined;
|
|
101
|
+
openTty(path: string): KernelTty | undefined;
|
|
102
|
+
open(path: string, flags: number, opener: DeviceOpener): Promise<OpenFile>;
|
|
103
|
+
}
|
|
104
|
+
export declare class DeviceChannel {
|
|
105
|
+
readonly tty: KernelTty;
|
|
106
|
+
readonly path: string;
|
|
107
|
+
private readonly inner;
|
|
108
|
+
private readonly reader;
|
|
109
|
+
private readonly writer;
|
|
110
|
+
private readonly streams;
|
|
111
|
+
private readonly onClosed;
|
|
112
|
+
private readonly gone;
|
|
113
|
+
private failure;
|
|
114
|
+
private readonly pending;
|
|
115
|
+
private queued;
|
|
116
|
+
private resume;
|
|
117
|
+
private waiters;
|
|
118
|
+
private closed;
|
|
119
|
+
ispeed: number;
|
|
120
|
+
ospeed: number;
|
|
121
|
+
dtr: boolean;
|
|
122
|
+
rts: boolean;
|
|
123
|
+
constructor(path: string, streams: DeviceStreams, saved: DeviceState | undefined, onClosed: (state: DeviceState) => void);
|
|
124
|
+
file(access: OpenAccess): OpenFile;
|
|
125
|
+
lost(err: KernelError): void;
|
|
126
|
+
private control;
|
|
127
|
+
private buffered;
|
|
128
|
+
private pump;
|
|
129
|
+
private send;
|
|
130
|
+
private check;
|
|
131
|
+
private read;
|
|
132
|
+
private ready;
|
|
133
|
+
private write;
|
|
134
|
+
private poll;
|
|
135
|
+
private changed;
|
|
136
|
+
private wake;
|
|
137
|
+
drain(signal?: AbortSignal): Promise<void>;
|
|
138
|
+
restore(): Promise<void>;
|
|
139
|
+
settings(): SerialSettings;
|
|
140
|
+
termios(): SerialTermios;
|
|
141
|
+
setTermios(termios: SerialTermios, how: {
|
|
142
|
+
drain?: boolean;
|
|
143
|
+
flush?: boolean;
|
|
144
|
+
extended?: boolean;
|
|
145
|
+
}, signal?: AbortSignal): Promise<void>;
|
|
146
|
+
private bits;
|
|
147
|
+
modem(): Promise<number>;
|
|
148
|
+
setModem(bits: number): Promise<void>;
|
|
149
|
+
private signals;
|
|
150
|
+
sendBreak(ms: number, signal?: AbortSignal): Promise<void>;
|
|
151
|
+
flush(input: boolean, output: boolean): Promise<void>;
|
|
152
|
+
ioctl(request: number, arg: unknown, signal?: AbortSignal): Promise<unknown>;
|
|
153
|
+
close(): Promise<void>;
|
|
154
|
+
}
|
|
155
|
+
export {};
|
|
@@ -53,7 +53,9 @@ export interface EmbedderLookup {
|
|
|
53
53
|
groupId(name: string): Promise<number | undefined>;
|
|
54
54
|
userId(name: string): Promise<number | undefined>;
|
|
55
55
|
}
|
|
56
|
+
export declare function lineOf(err: unknown): string;
|
|
56
57
|
export declare function embedderFailure(err: unknown): KernelError;
|
|
58
|
+
export declare function interruptible<T>(work: Promise<T>, signal: AbortSignal | undefined): Promise<T>;
|
|
57
59
|
export declare class EmbedderChannel {
|
|
58
60
|
readonly access: OpenAccess;
|
|
59
61
|
readonly owner: number;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { ClipboardChannel } from './clipboard.js';
|
|
2
|
+
import type { DeviceChannel } from './devices.js';
|
|
2
3
|
import type { EmbedderChannel } from './embedder.js';
|
|
3
4
|
import type { PtyPair } from './pty.js';
|
|
4
5
|
import type { SealedChannel } from './sealed.js';
|
|
5
6
|
import type { KernelTty } from './tty.js';
|
|
6
|
-
export type KernelErrno = 'EBADF' | 'EPROTO' | 'EDEADLK' | 'ENOLCK' | 'EEXIST' | 'ELOOP' | 'EOVERFLOW' | 'ENAMETOOLONG' | 'EPIPE' | 'EMFILE' | 'EINVAL' | 'ENOENT' | 'ENOTDIR' | 'ENOEXEC' | 'ECHILD' | 'ENOSYS' | 'ESPIPE' | 'ENOSPC' | 'EINTR' | 'ESRCH' | 'ENOTTY' | 'ENXIO' | 'EPERM' | 'EIO' | 'EACCES' | 'EAGAIN' | 'ENOTSOCK' | 'EAFNOSUPPORT' | 'EPROTONOSUPPORT' | 'EPROTOTYPE' | 'EOPNOTSUPP' | 'EADDRINUSE' | 'EADDRNOTAVAIL' | 'ENETUNREACH' | 'ECONNREFUSED' | 'EINPROGRESS' | 'EISCONN' | 'ENOTCONN' | 'EROFS' | 'EFBIG' | 'EALREADY' | 'ETIMEDOUT' | 'ECONNABORTED' | 'EHOSTUNREACH' | 'ECONNRESET' | 'EMSGSIZE' | 'EDESTADDRREQ' | 'ENOPROTOOPT' | 'ENOTSUP' | 'EILSEQ';
|
|
7
|
+
export type KernelErrno = 'EBADF' | 'EPROTO' | 'EDEADLK' | 'ENOLCK' | 'EEXIST' | 'ELOOP' | 'EOVERFLOW' | 'ENAMETOOLONG' | 'EPIPE' | 'EMFILE' | 'EINVAL' | 'ENOENT' | 'ENOTDIR' | 'ENOEXEC' | 'ECHILD' | 'ENOSYS' | 'ESPIPE' | 'ENOSPC' | 'EINTR' | 'ESRCH' | 'ENOTTY' | 'ENXIO' | 'EPERM' | 'EIO' | 'EACCES' | 'EAGAIN' | 'ENOTSOCK' | 'EAFNOSUPPORT' | 'EPROTONOSUPPORT' | 'EPROTOTYPE' | 'EOPNOTSUPP' | 'EADDRINUSE' | 'EADDRNOTAVAIL' | 'ENETUNREACH' | 'ECONNREFUSED' | 'EINPROGRESS' | 'EISCONN' | 'ENOTCONN' | 'EROFS' | 'EFBIG' | 'EALREADY' | 'ETIMEDOUT' | 'ECONNABORTED' | 'EHOSTUNREACH' | 'ECONNRESET' | 'EMSGSIZE' | 'EDESTADDRREQ' | 'ENOPROTOOPT' | 'ENOTSUP' | 'EILSEQ' | 'EBUSY';
|
|
7
8
|
export declare class KernelError extends Error {
|
|
8
9
|
readonly code: KernelErrno;
|
|
9
10
|
readonly detail?: string;
|
|
@@ -41,6 +42,7 @@ export interface KernelFile {
|
|
|
41
42
|
sealed?: SealedChannel;
|
|
42
43
|
clipboard?: ClipboardChannel;
|
|
43
44
|
embedder?: EmbedderChannel;
|
|
45
|
+
device?: DeviceChannel;
|
|
44
46
|
held?: true;
|
|
45
47
|
heldMeta?: HeldMeta;
|
|
46
48
|
identity?: object;
|
|
@@ -7,6 +7,7 @@ import type { ChildForker, ChildSpawner } from './children.js';
|
|
|
7
7
|
import type { ClipboardBroker } from './clipboard.js';
|
|
8
8
|
import { type CpuTimes } from './cpu-clock.js';
|
|
9
9
|
import { type Cred } from './cred.js';
|
|
10
|
+
import type { DeviceNodes } from './devices.js';
|
|
10
11
|
import type { EmbedderBroker } from './embedder.js';
|
|
11
12
|
import { type FdTable, type OpenFile } from './fd-table.js';
|
|
12
13
|
import type { FifoTable } from './fifo.js';
|
|
@@ -62,6 +63,7 @@ export interface SpawnWasmOptions {
|
|
|
62
63
|
uid: number;
|
|
63
64
|
};
|
|
64
65
|
};
|
|
66
|
+
devices?: DeviceNodes;
|
|
65
67
|
readonlyAt?: (path: string) => boolean;
|
|
66
68
|
dac?: Dac;
|
|
67
69
|
identity?: () => Promise<{
|
|
@@ -69,6 +71,7 @@ export interface SpawnWasmOptions {
|
|
|
69
71
|
ppid: number;
|
|
70
72
|
}>;
|
|
71
73
|
onSyscall?: (req: WasmSyscall) => void;
|
|
74
|
+
durable?: (() => void | Promise<void>) | undefined;
|
|
72
75
|
settling?: () => boolean;
|
|
73
76
|
program: Program;
|
|
74
77
|
argv0: string;
|