Skip to content

host-api/node/guest-hooks

host-api/node/guest-hooks

Import from @norbital-ai/host-api/node/guest-hooks

The prelude's host hooks and the guest module as a classic script: what every guest runner serves (GuestIsolatesPort) and bolt check's declaration evaluation reuse. Bolt runs no guest itself: each host owns its runner as HostPorts.guests (bolt-cli's node_guests, which bolt-server and bolt dev use; Colony's isolated-vm).

guest-hooks

GUEST_CONSOLE const

const GUEST_CONSOLE: { readonly lines: 200; readonly lineChars: 8000; readonly chars: number; }

What one guest turn keeps of its console: lines, characters per line and in all; past them, lines are counted.

Members

NameTypeDescription
lines200
lineChars8000
charsnumber

Source: packages/host-api/src/node/guest-hooks.ts:19

GUEST_CRYPTO const

const GUEST_CRYPTO: { readonly maxDigestBytes: number; readonly maxSessionDigestBytes: number; readonly maxSessionRandomBytes: number; }

Host-side caps on synchronous guest crypto hooks so an isolate cannot stall the host event loop.

Members

NameTypeDescription
maxDigestBytesnumber
maxSessionDigestBytesnumber
maxSessionRandomBytesnumber

Source: packages/host-api/src/node/guest-hooks.ts:44

GuestHooks type

type GuestHooks = readonly [
    say: (level: unknown, line: unknown) => void,
    random: (n: unknown) => Uint8Array,
    digest: (name: unknown, bytes: unknown) => Uint8Array,
    asset: (sha: unknown) => Uint8Array | undefined
];

The prelude's hooks as the host serves them (GuestSessionOptions.prelude).

Source: packages/host-api/src/node/guest-hooks.ts:175

GuestSaid type

type GuestSaid = {
    readonly lines: [level: string, line: string][];
    chars: number;
    dropped: number;
};

A session's console lines since its last turn; the runner resets chars and dropped with each turn it reads.

Members

NameTypeDescription
lines[level: string, line: string][]
charsnumber
droppednumber

Source: packages/host-api/src/node/guest-hooks.ts:21

ImportDeclaration type

type ImportDeclaration = Extract<Statement, {
    type: 'ImportDeclaration';
}>;

An import statement of the parsed guest module, as module_script hands it to its imports rewriter.

Source: packages/host-api/src/node/guest-hooks.ts:104

asset_hook function

function asset_hook(assets: GuestProgram["assets"]): (sha: unknown) => Uint8Array | undefined

The prelude's $3: a ?bytes import's bytes by sha256, or undefined (the guest then throws naming the sha).

Parameters

NameTypeDescription
assetsGuestProgram['assets']

Source: packages/host-api/src/node/guest-hooks.ts:11

console_hook function

function console_hook(said: GuestSaid): (level: unknown, line: unknown) => void

The prelude's $0, host side. The guest's own clip is guest code it can replace, so the bound is here: only strings are kept (never a guest object's toString), each clipped to its share before the host keeps it.

Parameters

NameTypeDescription
saidGuestSaid
  • lines: [level: string, line: string][]
  • chars: number
  • dropped: number

Source: packages/host-api/src/node/guest-hooks.ts:26

digest function

function digest(name: unknown, bytes: unknown): Uint8Array

crypto.subtle.digest's host half, capped per call so a guest cannot stall the host event loop.

Parameters

NameTypeDescription
nameunknown
bytesunknown

Source: packages/host-api/src/node/guest-hooks.ts:58

digest_hook function

function digest_hook(maxBytes?: number): (name: unknown, bytes: unknown) => Uint8Array

Stateful crypto.subtle.digest hook with a per-invocation cumulative byte ceiling.

Parameters

NameTypeDescription
maxBytes?number

Source: packages/host-api/src/node/guest-hooks.ts:68

module_script function

function module_script(source: string, imports: (node: ImportDeclaration) => string): string

guest.mjs as a classic script whose completion value is its namespace, for a runner that evaluates scripts only. An import becomes imports' statement, import.meta an empty object; exports stay live bindings. Replacements keep their spans' columns, and the wrapper is a line of its own (lineOffset: -1).

Parameters

NameTypeDescription
sourcestring
imports(node: ImportDeclaration) => string

Source: packages/host-api/src/node/guest-hooks.ts:115

random_stream function

function random_stream(seed: string, maxBytes?: number): (n: unknown) => Uint8Array

The invocation's deterministic entropy stream (AES-256-CTR keyed by sha256(seed)), capped per invocation.

Parameters

NameTypeDescription
seedstring
maxBytes?number

Source: packages/host-api/src/node/guest-hooks.ts:84