host-api/node/guest-hooks
host-api/node/guest-hooks
此内容目前仅提供英文版。
导入自 @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.
成员
| 名称 | 类型 | 说明 |
|---|---|---|
lines | 200 | |
lineChars | 8000 | |
chars | number |
源码: 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.
成员
| 名称 | 类型 | 说明 |
|---|---|---|
maxDigestBytes | number | |
maxSessionDigestBytes | number | |
maxSessionRandomBytes | number |
源码: 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).
源码: 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.
成员
| 名称 | 类型 | 说明 |
|---|---|---|
lines | [level: string, line: string][] | |
chars | number | |
dropped | number |
源码: 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.
源码: 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).
参数
| 名称 | 类型 | 说明 |
|---|---|---|
assets | GuestProgram['assets'] |
源码: 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.
参数
| 名称 | 类型 | 说明 |
|---|---|---|
said | GuestSaid |
|
源码: 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.
参数
| 名称 | 类型 | 说明 |
|---|---|---|
name | unknown | |
bytes | unknown |
源码: 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.
参数
| 名称 | 类型 | 说明 |
|---|---|---|
maxBytes? | number |
源码: 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).
参数
| 名称 | 类型 | 说明 |
|---|---|---|
source | string | |
imports | (node: ImportDeclaration) => string |
源码: 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.
参数
| 名称 | 类型 | 说明 |
|---|---|---|
seed | string | |
maxBytes? | number |