///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
import { FileMapping, HttpMountDetails, HttpEndpointDetails } from 'golem:agent/common@2.0.0';
import { Uuid as Uuid$1, Secret as Secret$1, QuotaToken, SchemaValueStream, SchemaValueTree, PermissionCard, TypeId, NumericRestrictions, MetadataEnvelope, TextRestrictions, BinaryRestrictions, PathSpec, UrlRestrictions, QuantitySpec, DiscriminatorRule, SecretSpec, QuotaTokenSpec, PermissionCardSpec, Datetime, QuantityValue, SchemaValueNode } from 'golem:core/types@2.0.0';
import * as originalHttp from 'node:http';
import { EventEmitter } from 'node:events';
import { Writable } from 'node:stream';
import { Buffer } from 'node:buffer';
/** A canonical field occurrence. Values are bytes, not UTF-8 text. */
interface HttpHeader {
readonly name: string;
readonly value: Uint8Array;
}
/** The original public request; undefined query differs from an empty query. */
interface HttpRequest
{
readonly method: string;
readonly scheme: string;
readonly authority: string;
readonly path: string;
readonly query: string | undefined;
readonly headers: readonly HttpHeader[];
readonly body: Body;
}
/** Canonical response. Body ownership is supplied by the language runtime. */
interface HttpResponse {
readonly status: number;
readonly headers: readonly HttpHeader[];
readonly body: Body;
}
interface FileExposure {
readonly route: string;
readonly path: string;
}
/** Response headers applied by the host when serving mounted files. */
type FileResponseHeaders = Readonly>;
/** Copy ergonomic file response headers into their ordered WIT representation. */
declare function compileFileResponseHeaders(headers: FileResponseHeaders | undefined): Array<{
name: string;
value: string;
}>;
/** Safe diagnostics never contain document, header, or body contents. */
declare class HttpRouterError extends TypeError {
readonly category: string;
constructor(category: string);
}
/** Compile once to WIT mappings. Only identical compiled pairs are duplicates. */
declare function compileFileMappings(mappings: readonly FileExposure[]): FileMapping[];
interface RouterMountOptions {
readonly mount: string;
readonly auth?: boolean;
readonly cors?: readonly string[];
readonly fileResponseHeaders?: FileResponseHeaders;
/** Validated structural mappings returned by compileFileMappings. */
readonly staticBindings?: readonly FileMapping[];
readonly handlerMethod?: string;
readonly openapiProviderMethod?: string;
}
/** Framework-neutral mount/role metadata; schemas and registration stay with the SDK. */
declare function compileRouterMount(options: RouterMountOptions): {
mount: HttpMountDetails;
handlerBinding: HttpEndpointDetails | undefined;
};
/** Validate and copy canonical headers without normalizing away occurrences. */
declare function copyHttpHeaders(headers: readonly HttpHeader[]): HttpHeader[];
/** OpenAPI 3.1 provider input. Full semantic validation/merging belongs to the host. */
declare function serializeOpenApi(document: unknown): string;
/**
* Rich UUID class that is structurally compatible with the WIT binding type
* `{ highBits: bigint; lowBits: bigint }` from `golem:core/types@2.0.0`.
*/
declare class Uuid {
readonly highBits: bigint;
readonly lowBits: bigint;
constructor(highBits: bigint, lowBits: bigint);
/**
* Formats the UUID as a standard hyphenated string.
*/
toString(): string;
/**
* Parses a UUID string.
*/
static parse(value: string): Uuid;
/**
* Generates a random UUID.
*/
static generate(): Uuid;
/**
* Wraps a raw WIT UUID object in a Uuid instance.
* If the value is already a Uuid, it is returned directly.
*/
static from(value: Uuid$1): Uuid;
}
declare const SECRET_INTERNAL: unique symbol;
type SecretInternal = typeof SECRET_INTERNAL;
declare class GuestSecretHandle {
constructor(key: SecretInternal, raw: Secret$1, onTake?: () => void, tracked?: boolean);
toJSON(): never;
}
declare const QUOTA_INTERNAL: unique symbol;
/** The type of the {@link QUOTA_INTERNAL} capability key. */
type QuotaInternal = typeof QUOTA_INTERNAL;
declare class GuestQuotaTokenHandle {
constructor(key: QuotaInternal, raw: QuotaToken, tracked?: boolean);
/**
* Quota-token handles are unforgeable capabilities, not data: serializing one
* (e.g. via `JSON.stringify`) is always an error. Transfer them only by
* passing the owning `QuotaToken` through a WIT `schema-value-tree`.
*/
toJSON(): never;
}
type GuestSchemaValueStream = {
kind: 'wrapped';
value: SchemaValueStream;
} | {
kind: 'native';
value: AsyncIterable;
};
declare const PERMISSION_CARD_INTERNAL: unique symbol;
/** The type of the {@link PERMISSION_CARD_INTERNAL} capability key. */
type PermissionCardInternal = typeof PERMISSION_CARD_INTERNAL;
/** Guest-side take-once carrier for an owned, opaque permission-card resource. */
declare class GuestPermissionCardHandle {
constructor(key: PermissionCardInternal, raw: PermissionCard, tracked?: boolean, lifted?: boolean);
toJSON(): never;
}
/** A schema type node: a structural body plus its metadata envelope. */
interface SchemaType {
readonly body: SchemaTypeBody;
readonly metadata: MetadataEnvelope;
}
type SchemaTypeBody = {
tag: 'ref';
id: TypeId;
} | {
tag: 'bool';
} | {
tag: 's8';
restrictions?: NumericRestrictions;
} | {
tag: 's16';
restrictions?: NumericRestrictions;
} | {
tag: 's32';
restrictions?: NumericRestrictions;
} | {
tag: 's64';
restrictions?: NumericRestrictions;
} | {
tag: 'u8';
restrictions?: NumericRestrictions;
} | {
tag: 'u16';
restrictions?: NumericRestrictions;
} | {
tag: 'u32';
restrictions?: NumericRestrictions;
} | {
tag: 'u64';
restrictions?: NumericRestrictions;
} | {
tag: 'f32';
restrictions?: NumericRestrictions;
} | {
tag: 'f64';
restrictions?: NumericRestrictions;
} | {
tag: 'char';
} | {
tag: 'string';
} | {
tag: 'uuid';
} | {
tag: 'record';
fields: NamedFieldType[];
} | {
tag: 'variant';
cases: VariantCaseType[];
} | {
tag: 'enum';
cases: string[];
} | {
tag: 'flags';
names: string[];
} | {
tag: 'tuple';
elements: SchemaType[];
} | {
tag: 'list';
element: SchemaType;
} | {
tag: 'fixed-list';
element: SchemaType;
length: number;
} | {
tag: 'map';
key: SchemaType;
value: SchemaType;
} | {
tag: 'option';
element: SchemaType;
} | {
tag: 'result';
ok?: SchemaType;
err?: SchemaType;
} | {
tag: 'text';
restrictions: TextRestrictions;
} | {
tag: 'binary';
restrictions: BinaryRestrictions;
} | {
tag: 'path';
spec: PathSpec;
} | {
tag: 'url';
restrictions: UrlRestrictions;
} | {
tag: 'datetime';
} | {
tag: 'duration';
} | {
tag: 'quantity';
spec: QuantitySpec;
} | {
tag: 'union';
branches: UnionBranch[];
} | {
tag: 'secret';
spec: Omit;
inner: SchemaType;
} | {
tag: 'quota-token';
spec: QuotaTokenSpec;
} | {
tag: 'permission-card';
spec: PermissionCardSpec;
} | {
tag: 'future';
element?: SchemaType;
} | {
tag: 'stream';
element?: SchemaType;
};
interface NamedFieldType {
name: string;
body: SchemaType;
metadata: MetadataEnvelope;
}
interface VariantCaseType {
name: string;
payload?: SchemaType;
metadata: MetadataEnvelope;
}
interface UnionBranch {
/** Logical branch name (carried in `union` values). */
tag: string;
body: SchemaType;
discriminator: DiscriminatorRule;
metadata: MetadataEnvelope;
}
interface SchemaTypeDef {
/** Optional human-readable qualified name (display only). */
readonly name?: string;
readonly body: SchemaType;
}
/**
* A self-contained schema graph: a registry of named definitions (keyed by
* stable `type-id`) plus a root type. `ref` bodies reference entries in `defs`.
*/
interface SchemaGraph {
readonly defs: ReadonlyMap;
readonly root: SchemaType;
}
type SchemaValue = {
tag: 'bool';
value: boolean;
} | {
tag: 's8';
value: number;
} | {
tag: 's16';
value: number;
} | {
tag: 's32';
value: number;
} | {
tag: 's64';
value: bigint;
} | {
tag: 'u8';
value: number;
} | {
tag: 'u16';
value: number;
} | {
tag: 'u32';
value: number;
} | {
tag: 'u64';
value: bigint;
} | {
tag: 'f32';
value: number;
} | {
tag: 'f64';
value: number;
} | {
tag: 'char';
value: string;
} | {
tag: 'string';
value: string;
} | {
tag: 'uuid';
value: Uuid;
} | {
tag: 'record';
fields: SchemaValue[];
} | {
tag: 'variant';
caseIndex: number;
payload?: SchemaValue;
} | {
tag: 'enum';
caseIndex: number;
} | {
tag: 'flags';
flags: boolean[];
} | {
tag: 'tuple';
elements: SchemaValue[];
} | {
tag: 'list';
elements: SchemaValue[];
} | {
tag: 'fixed-list';
elements: SchemaValue[];
} | {
tag: 'map';
entries: SchemaMapEntry[];
} | {
tag: 'option';
value?: SchemaValue;
} | {
tag: 'result';
result: SchemaResult;
} | {
tag: 'text';
text: string;
language?: string;
} | {
tag: 'binary';
bytes: Uint8Array;
mimeType?: string;
} | {
tag: 'path';
value: string;
} | {
tag: 'url';
value: string;
} | {
tag: 'datetime';
value: Datetime;
} | {
tag: 'duration';
nanoseconds: bigint;
} | {
tag: 'quantity';
value: QuantityValue;
} | {
tag: 'union';
unionTag: string;
body: SchemaValue;
} | {
tag: 'secret';
handle: GuestSecretHandle;
} | {
tag: 'quota-token';
handle: GuestQuotaTokenHandle;
} | {
tag: 'stream';
handle: SchemaValueStreamHandle;
} | {
tag: 'permission-card';
handle: GuestPermissionCardHandle;
};
interface SchemaMapEntry {
key: SchemaValue;
value: SchemaValue;
}
interface SchemaValueStreamHandle {
peek(): GuestSchemaValueStream | undefined;
take(): GuestSchemaValueStream | undefined;
close(): Promise;
}
type SchemaResult = {
tag: 'ok';
value?: SchemaValue;
} | {
tag: 'err';
value?: SchemaValue;
};
interface StandardSchemaV1 {
readonly '~standard': StandardSchemaV1.Props;
}
declare namespace StandardSchemaV1 {
interface Props {
readonly version: 1;
readonly vendor: string;
readonly validate: (value: unknown) => Result