///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
import * as golem_core_types_2_0_0 from 'golem:core/types@2.0.0';
import { Secret, QuotaToken, SchemaValueStream, SchemaValueTree, PermissionCard, Uuid as Uuid$1, TypeId, NumericRestrictions, MetadataEnvelope, TextRestrictions, BinaryRestrictions, PathSpec, UrlRestrictions, QuantitySpec, DiscriminatorRule, SecretSpec, QuotaTokenSpec, PermissionCardSpec, Datetime, QuantityValue, TypeNodeIndex, SchemaGraph as SchemaGraph$1, SchemaValueNode, TypedSchemaValue as TypedSchemaValue$1, ValueNodeIndex } from 'golem:core/types@2.0.0';
export { BinaryRestrictions, Datetime, DiscriminatorRule, EnvironmentId, FieldDiscriminator, MetadataEnvelope, NumericBound, NumericRestrictions, PathDirection, PathKind, PathSpec, PermissionCardSpec, QuantitySpec, QuantityValue, QuotaTokenSpec, Role, SecretSpec, TextRestrictions, TypeId, UrlRestrictions, Uuid } from 'golem:core/types@2.0.0';
/** Raised when encoding an in-memory schema/value into its flat WIT carrier fails. */
declare class SchemaEncodeError extends Error {
constructor(message: string);
}
/** Raised when decoding a flat WIT carrier into the in-memory model fails. */
declare class SchemaDecodeError extends Error {
constructor(message: string);
}
/**
* Raised when merging per-root schema graphs encounters two definitions that
* share the same `type-id` but have structurally different bodies.
*/
declare class SchemaConflictError extends Error {
readonly typeId: string;
constructor(typeId: string, message?: string);
}
declare const SECRET_INTERNAL: unique symbol;
type SecretInternal = typeof SECRET_INTERNAL;
declare class GuestSecretHandle {
constructor(key: SecretInternal, raw: Secret, onTake?: () => void, tracked?: boolean);
toJSON(): never;
}
declare function createGuestSecretHandle(key: SecretInternal, raw: Secret, onTake?: () => void): GuestSecretHandle;
declare function createUntrackedGuestSecretHandle(key: SecretInternal, raw: Secret): GuestSecretHandle;
declare function adoptGuestSecretHandle(key: SecretInternal, raw: Secret): GuestSecretHandle;
declare function peekGuestSecretHandle(key: SecretInternal, handle: GuestSecretHandle): Secret | undefined;
declare function takeGuestSecretHandle(key: SecretInternal, handle: GuestSecretHandle): Secret | undefined;
declare function takeGuestSecretHandleToWire(key: SecretInternal, handle: GuestSecretHandle, wireOwner: object): Secret | undefined;
declare function assertGuestSecretHandleCanLiftFromWire(key: SecretInternal, raw: Secret, wireOwner: object): void;
declare function liftGuestSecretHandleFromWire(key: SecretInternal, raw: Secret, wireOwner: object): GuestSecretHandle;
declare function releaseGuestSecretHandle(key: SecretInternal, handle: GuestSecretHandle): Secret | undefined;
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;
}
declare function createGuestQuotaTokenHandle(key: QuotaInternal, raw: QuotaToken): GuestQuotaTokenHandle;
declare function createUntrackedGuestQuotaTokenHandle(key: QuotaInternal, raw: QuotaToken): GuestQuotaTokenHandle;
declare function adoptGuestQuotaTokenHandle(key: QuotaInternal, raw: QuotaToken): GuestQuotaTokenHandle;
declare function peekGuestQuotaTokenHandle(key: QuotaInternal, handle: GuestQuotaTokenHandle): QuotaToken | undefined;
declare function takeGuestQuotaTokenHandle(key: QuotaInternal, handle: GuestQuotaTokenHandle): QuotaToken | undefined;
declare function takeGuestQuotaTokenHandleToWire(key: QuotaInternal, handle: GuestQuotaTokenHandle, wireOwner: object): QuotaToken | undefined;
declare function assertGuestQuotaTokenHandleCanLiftFromWire(key: QuotaInternal, raw: QuotaToken, wireOwner: object): void;
declare function liftGuestQuotaTokenHandleFromWire(key: QuotaInternal, raw: QuotaToken, wireOwner: object): GuestQuotaTokenHandle;
declare function abandonGuestQuotaTokenWireHandle(key: QuotaInternal, raw: QuotaToken, wireOwner: object): void;
declare function releaseGuestQuotaTokenHandle(key: QuotaInternal, handle: GuestQuotaTokenHandle): QuotaToken | undefined;
type GuestSchemaValueStream = {
kind: 'wrapped';
value: SchemaValueStream;
} | {
kind: 'native';
value: AsyncIterable;
};
declare class GuestSchemaValueStreamHandle {
#private;
constructor(value: GuestSchemaValueStream);
peek(): GuestSchemaValueStream | undefined;
close(): Promise;
take(): GuestSchemaValueStream | undefined;
}
declare const PERMISSION_CARD_INTERNAL: unique symbol;
/** The type of the {@link PERMISSION_CARD_INTERNAL} capability key. */
type PermissionCardInternal = typeof PERMISSION_CARD_INTERNAL;
/** Register a public card object so that structural equality compares it by identity. */
declare function registerPermissionCardObject(key: PermissionCardInternal, card: object): void;
declare function isPermissionCardObject(value: unknown): boolean;
/**
* `true` when `raw` is an instance of the host `golem:core/types` permission-card
* resource class. Wire lifting accepts only such values, so a plain object or
* other data does not pass. This is a JavaScript `instanceof` check, not proof
* that the value is a live host resource: an object made with
* `Object.create(PermissionCard.prototype)` passes it. Such an object grants no
* authority, because the host validates the resource when the SDK lowers it
* into a host call or a wire value.
*/
declare function isHostPermissionCardResource(raw: unknown): boolean;
/** 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;
}
declare function createGuestPermissionCardHandle(key: PermissionCardInternal, raw: PermissionCard): GuestPermissionCardHandle;
/** `true` when the SDK tracks `raw` as held by a handle, a wire value or the host. */
declare function guestPermissionCardResourceIsTracked(key: PermissionCardInternal, raw: PermissionCard): boolean;
declare function createUntrackedGuestPermissionCardHandle(key: PermissionCardInternal, raw: PermissionCard): GuestPermissionCardHandle;
declare function adoptGuestPermissionCardHandle(key: PermissionCardInternal, raw: PermissionCard): GuestPermissionCardHandle;
declare function peekGuestPermissionCardHandle(key: PermissionCardInternal, handle: GuestPermissionCardHandle): PermissionCard | undefined;
declare function takeGuestPermissionCardHandle(key: PermissionCardInternal, handle: GuestPermissionCardHandle): PermissionCard | undefined;
declare function takeGuestPermissionCardHandleToWire(key: PermissionCardInternal, handle: GuestPermissionCardHandle, wireOwner: object): PermissionCard | undefined;
/**
* Give a resource that was lowered into a wire tree but never sent back to the
* handle it came from. Returns `false` when the resource has no such handle.
*/
declare function restoreGuestPermissionCardHandleFromWire(key: PermissionCardInternal, raw: PermissionCard, wireOwner: object): boolean;
/**
* Detach a resource that is about to be disposed from the handle that holds it,
* so that the card wrapping the handle reports itself as moved.
*/
declare function detachGuestPermissionCardResource(key: PermissionCardInternal, raw: PermissionCard): void;
declare function assertGuestPermissionCardHandleCanLiftFromWire(key: PermissionCardInternal, raw: PermissionCard, wireOwner: object): void;
declare function liftGuestPermissionCardHandleFromWire(key: PermissionCardInternal, raw: PermissionCard, wireOwner: object): GuestPermissionCardHandle;
declare function permissionCardHandleWasLiftedFromWire(key: PermissionCardInternal, handle: GuestPermissionCardHandle): boolean;
declare function abandonGuestPermissionCardWireHandle(key: PermissionCardInternal, raw: PermissionCard, wireOwner: object): void;
/** Bind a handle to the public card that wraps it. A handle has at most one card. */
declare function bindGuestPermissionCardHandleToCard(key: PermissionCardInternal, handle: GuestPermissionCardHandle, card: object): void;
/** `true` when a public card object already wraps `handle`. */
declare function guestPermissionCardHandleIsBoundToCard(key: PermissionCardInternal, handle: GuestPermissionCardHandle): boolean;
/** The resource currently held by a public card object, or `undefined` for any other value. */
declare function peekPermissionCardObjectResource(key: PermissionCardInternal, value: unknown): PermissionCard | undefined;
/**
* Give up a schema value's claim on a handle after a failed conversion. A
* handle that a `PermissionCard` owns stays with the card.
*/
declare function relinquishGuestPermissionCardHandle(key: PermissionCardInternal, handle: GuestPermissionCardHandle): void;
declare function releaseGuestPermissionCardHandle(key: PermissionCardInternal, handle: GuestPermissionCardHandle): PermissionCard | undefined;
type Rollback = () => void;
/**
* Atomically build a schema value that may adopt owned capability handles.
* Nested conversions share the outer journal, while a failed nested conversion
* rolls back only the handles it adopted.
*/
declare function withCapabilityAdoptionTransaction(encode: () => T): T;
/**
* Run a public root conversion in a journal isolated from any conversion that
* synchronously invoked it. Successful adoptions belong only to this call.
*/
declare function withIsolatedCapabilityAdoptionTransaction(encode: () => T): T;
/** Make an encoder an isolated public root while retaining its joining child encoder. */
declare function isolateCapabilityRoot(encode: (value: unknown) => T): (value: unknown) => T;
/** Encode one structural child without re-entering that child's public root boundary. */
declare function encodeChild(codec: {
readonly toValue: (value: unknown) => T;
}, value: unknown): T;
/** Register a newly adopted handle with the active synchronous conversion. */
declare function registerCapabilityAdoption(rollback: Rollback): void;
/**
* 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;
}
/** 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;
}
/** Compare canonical value shape while ignoring metadata and refinable restrictions. */
declare function schemaShapesMatch(left: SchemaGraph, right: SchemaGraph): boolean;
/** Compare exact value semantics across graphs while ignoring refs, definition IDs, and metadata. */
declare function schemaGraphsEquivalent(left: SchemaGraph, right: SchemaGraph): boolean;
declare function resolveShapeType(graph: SchemaGraph, type: SchemaType): SchemaTypeBody | undefined;
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 TypedSchemaValue {
graph: SchemaGraph;
value: SchemaValue;
}
declare function emptyMetadata(): MetadataEnvelope;
/** Wrap a body into a `SchemaType` node with empty metadata. */
declare function schemaType(body: SchemaTypeBody, metadata?: MetadataEnvelope): SchemaType;
/** Compact constructors for schema types (anonymous unless wrapped in a def). */
declare const t: {
ref: (id: TypeId) => SchemaType;
bool: () => SchemaType;
s8: (restrictions?: NumericRestrictions) => SchemaType;
s16: (restrictions?: NumericRestrictions) => SchemaType;
s32: (restrictions?: NumericRestrictions) => SchemaType;
s64: (restrictions?: NumericRestrictions) => SchemaType;
u8: (restrictions?: NumericRestrictions) => SchemaType;
u16: (restrictions?: NumericRestrictions) => SchemaType;
u32: (restrictions?: NumericRestrictions) => SchemaType;
u64: (restrictions?: NumericRestrictions) => SchemaType;
f32: (restrictions?: NumericRestrictions) => SchemaType;
f64: (restrictions?: NumericRestrictions) => SchemaType;
char: () => SchemaType;
string: () => SchemaType;
uuid: () => SchemaType;
record: (fields: NamedFieldType[]) => SchemaType;
variant: (cases: VariantCaseType[]) => SchemaType;
enum: (cases: string[]) => SchemaType;
flags: (names: string[]) => SchemaType;
tuple: (elements: SchemaType[]) => SchemaType;
list: (element: SchemaType) => SchemaType;
fixedList: (element: SchemaType, length: number) => SchemaType;
map: (key: SchemaType, value: SchemaType) => SchemaType;
option: (element: SchemaType) => SchemaType;
result: (ok?: SchemaType, err?: SchemaType) => SchemaType;
path: (spec: PathSpec) => SchemaType;
url: (restrictions: UrlRestrictions) => SchemaType;
datetime: () => SchemaType;
duration: () => SchemaType;
quantity: (spec: QuantitySpec) => SchemaType;
secret: (inner: SchemaType, spec?: Omit) => SchemaType;
quotaToken: (spec: QuotaTokenSpec) => SchemaType;
stream: (element?: SchemaType) => SchemaType;
permissionCard: (spec: PermissionCardSpec) => SchemaType;
};
/** Compact constructors for schema field/case helpers. */
declare function field(name: string, body: SchemaType, metadata?: MetadataEnvelope): NamedFieldType;
declare function variantCase(name: string, payload?: SchemaType, metadata?: MetadataEnvelope): VariantCaseType;
/** Compact constructors for schema values. */
declare const v: {
bool: (value: boolean) => SchemaValue;
s8: (value: number) => SchemaValue;
s16: (value: number) => SchemaValue;
s32: (value: number) => SchemaValue;
s64: (value: bigint) => SchemaValue;
u8: (value: number) => SchemaValue;
u16: (value: number) => SchemaValue;
u32: (value: number) => SchemaValue;
u64: (value: bigint) => SchemaValue;
f32: (value: number) => SchemaValue;
f64: (value: number) => SchemaValue;
char: (value: string) => SchemaValue;
string: (value: string) => SchemaValue;
uuid: (value: Uuid) => SchemaValue;
record: (fields: SchemaValue[]) => SchemaValue;
variant: (caseIndex: number, payload?: SchemaValue) => SchemaValue;
enum: (caseIndex: number) => SchemaValue;
flags: (flags: boolean[]) => SchemaValue;
tuple: (elements: SchemaValue[]) => SchemaValue;
list: (elements: SchemaValue[]) => SchemaValue;
fixedList: (elements: SchemaValue[]) => SchemaValue;
map: (entries: SchemaMapEntry[]) => SchemaValue;
option: (value?: SchemaValue) => SchemaValue;
ok: (value?: SchemaValue) => SchemaValue;
err: (value?: SchemaValue) => SchemaValue;
text: (text: string, language?: string) => SchemaValue;
binary: (bytes: Uint8Array, mimeType?: string) => SchemaValue;
path: (value: string) => SchemaValue;
url: (value: string) => SchemaValue;
datetime: (value: Datetime) => SchemaValue;
duration: (nanoseconds: bigint) => SchemaValue;
quantity: (value: QuantityValue) => SchemaValue;
union: (unionTag: string, body: SchemaValue) => SchemaValue;
secret: (handle: GuestSecretHandle) => SchemaValue;
quotaToken: (handle: GuestQuotaTokenHandle) => SchemaValue;
stream: (handle: SchemaValueStreamHandle) => SchemaValue;
permissionCard: (handle: GuestPermissionCardHandle) => SchemaValue;
};
/** Clone a schema value without duplicating affine capability handles. */
declare function cloneSchemaValue(value: SchemaValue): SchemaValue;
/**
* Deep structural equality that understands the value shapes used by the schema
* model: bigint, Uint8Array, Map, arrays, and plain objects. Object keys whose
* value is `undefined` are ignored, matching the WIT option lifting convention
* (and Vitest's `toEqual`).
*/
declare function deepEqual(a: unknown, b: unknown, equivalent?: (a: unknown, b: unknown) => boolean): boolean;
/** Structural equality for two schema types. */
declare function schemaTypeEquals(a: SchemaType, b: SchemaType): boolean;
/** Structural equality for two schema values. */
declare function schemaValueEquals(a: SchemaValue, b: SchemaValue): boolean;
declare class SchemaBuilder {
private readonly defs;
/** Whether the given id is already reserved or committed. */
contains(id: TypeId): boolean;
/** Reserve a slot for `id` so recursive references can close to a `ref`. */
reserve(id: TypeId, name?: string): void;
/** Commit the body of a previously reserved (or new) `id`. */
commit(id: TypeId, body: SchemaType, name?: string): void;
/** A `ref` schema type pointing at `id`. */
ref(id: TypeId): SchemaType;
/**
* Register a nominal type. If `id` is not yet known it is reserved, then
* `build` is invoked to produce its body (during which recursive references
* to `id` resolve to a `ref`), then committed. Always returns a `ref` to
* `id` for use at the call site.
*/
register(id: TypeId, build: () => SchemaType, name?: string): SchemaType;
/** Finalize the registered definitions, ensuring every reservation was committed. */
finish(): Map;
/** Build a complete graph with the given root and all registered definitions. */
buildGraph(root: SchemaType): SchemaGraph;
}
/** Merge definitions from several graphs, rejecting conflicting same-id bodies. */
declare function mergeGraphDefs(graphs: Iterable): Map;
/** An agent-level merged graph: a shared def registry plus the roots it backs. */
interface MergedAgentGraph {
defs: Map;
roots: SchemaType[];
}
/**
* Combine the per-root graphs of an agent (one per constructor / method input /
* output / config root) into a single deduplicated def registry plus the list
* of roots, in input order. Conflicting same-id definitions raise
* `SchemaConflictError`.
*/
declare function mergeAgentGraphs(graphs: SchemaGraph[]): MergedAgentGraph;
/**
* Incremental encoder for a single flat {@link WitSchemaGraph} that holds
* several independent root types in one shared `type-nodes` pool. Mirrors the
* Rust `golem-schema` `GraphEncoder`.
*
* Seed the encoder with the agent's merged named definitions, then call
* {@link GraphEncoder.encodeType} once per inline root (constructor / method /
* config), collecting the returned `type-node-index` values, and finally
* {@link GraphEncoder.finish} to obtain the graph with a placeholder root. The
* graph's own `root` is a structurally-required placeholder (an empty record);
* agent-layer carriers never consult it — the real roots are the returned
* indices.
*
* Do NOT encode each agent root via {@link schemaGraphToWit} and reuse those
* indices: per-graph node indices are only valid within a single encoding.
*/
declare class GraphEncoder {
private readonly typeNodes;
private readonly defIndexById;
private readonly witDefs;
constructor(defs: ReadonlyMap);
/** Flatten one (possibly recursive) schema type into the shared pool and return its index. */
encodeType(st: SchemaType): TypeNodeIndex;
private encodeBody;
/** Encode `root` as the graph root and return the finished flat graph. */
encodeGraphRoot(root: SchemaType): SchemaGraph$1;
/**
* Finish the graph with a placeholder empty-record root. Use after collecting
* the real root indices via {@link GraphEncoder.encodeType}.
*/
finish(): SchemaGraph$1;
}
declare function schemaGraphToWit(graph: SchemaGraph): SchemaGraph$1;
/** Definitions and selected roots decoded from one Component Model graph. */
interface DecodedSchemaGraphRoots {
readonly defs: Map;
readonly roots: readonly SchemaType[];
}
/** Decode one WIT graph and any number of roots while sharing decoded nodes and definitions. */
declare function schemaGraphRootsFromWit(wit: SchemaGraph$1, roots: readonly TypeNodeIndex[]): DecodedSchemaGraphRoots;
/** Decode a Component Model carrier into the recursive SDK model. */
declare function schemaGraphFromWit(wit: SchemaGraph$1): SchemaGraph;
declare function assertDenseModelArray(value: unknown, name: string): asserts value is unknown[];
/**
* Validate every node of `value` *before* {@link schemaValueToWit} moves any
* owned capability handle, so a value tree that the WIT boundary would reject
* never destroys a still-valid capability.
*
* This enforces the same invariants the Component Model boundary and the host
* decoder enforce — narrow-integer ranges, valid `s64`/`u64` magnitudes, a
* single-code-point non-surrogate `char`, a signed-`s64` duration, and a
* `datetime` whose nanoseconds are in `[0, 1_000_000_000)` — plus that every
* owned capability is still present and that no underlying owned resource
* appears more than once. Handles are deduplicated by the identity of the
* underlying owned resource (peeked without consuming), not merely by holder
* identity, so two holders that somehow wrap the same resource are also rejected.
* Recurse through this module-level function: a self-referential local visitor
* creates collectible cycles even for each scalar encoded by a direct codec.
*/
declare function assertSchemaValueRepresentable(v: SchemaValue, allowNativeStreams?: boolean, seen?: Set): void;
declare function schemaValueToWit(value: SchemaValue): SchemaValueTree;
declare function schemaValueToWitAsync(value: SchemaValue): Promise;
/**
* Validate a flat value tree by reference without lifting or mutating handles.
* For reachable nodes, this checks dense carrier payloads and the cross-node
* invariants and domains that lifting relies on. Across the whole node array it
* enforces handle/object safety; unreachable nodes otherwise receive shape and
* handle-safety checks only. If this returns, the lifting walk cannot fail
* because of carrier structure. Any new lift-time invariant must be mirrored
* here.
*
* This intentionally duplicates the structure of `fromNode` below; the two must
* be kept in sync (a new node kind must be handled in both, or it will be
* reported as an unknown tag here).
*/
declare function preflightWitValueTree(nodes: SchemaValueNode[], root: ValueNodeIndex): void;
declare function schemaValueFromWit(wit: SchemaValueTree): SchemaValue;
/**
* Clear every owned quota-token, permission-card, or schema-value-stream handle still present in
* `nodes` (i.e. not moved out during decode) and return the index of the first
* one found, or `undefined` if none remained.
*/
declare function drainUnconsumedQuotaAndPermissionCardHandles(nodes: SchemaValueNode[]): number | undefined;
declare function typedSchemaValueToWit(tv: TypedSchemaValue): TypedSchemaValue$1;
declare function typedSchemaValueToWitAsync(tv: TypedSchemaValue): Promise;
/**
* Validate a wire typed schema value without lifting or mutating any owned
* resources. This combines graph decoding with {@link preflightWitValueTree}
* so it mirrors the structural checks required before full decoding.
*/
declare function preflightWitTypedSchemaValue(wit: TypedSchemaValue$1): void;
declare function typedSchemaValueFromWit(wit: TypedSchemaValue$1): TypedSchemaValue;
type SchemaValidationErrorCode = 'dangling-ref' | 'recursive-alias' | 'inline-cycle' | 'empty-variant' | 'empty-enum' | 'empty-union' | 'empty-flags' | 'duplicate-field-name' | 'duplicate-variant-case' | 'duplicate-enum-case' | 'duplicate-flag-name' | 'duplicate-union-tag' | 'map-key-not-primitive' | 'invalid-fixed-list-length' | 'quantity-min-greater-than-max' | 'quantity-min-unit-mismatch' | 'quantity-max-unit-mismatch' | 'quantity-comparison-overflow' | 'invalid-quantity-bound' | 'union-string-rule-on-non-string-body' | 'union-field-rule-on-non-record-body' | 'union-field-equals-literal-on-non-string-field' | 'union-field-rule-missing-field' | 'union-ambiguous-discriminators' | 'union-unsatisfiable-field-absent' | 'invalid-union-regex' | 'invalid-text-regex' | 'invalid-text-length-range' | 'invalid-binary-byte-range' | 'invalid-numeric-restriction' | 'nullable-nesting';
interface SchemaValidationError {
readonly code: SchemaValidationErrorCode;
readonly message: string;
readonly refId?: TypeId;
}
/**
* Validate every definition body followed by the graph root, in deterministic order.
*
* Regex restrictions are compiled with the platform's Unicode-mode ECMAScript `RegExp`
* implementation.
* Rust validates the same schema fields with the `regex` crate, so engine-specific syntax can
* be accepted by one SDK and rejected by the other. Cross-SDK schemas should use their common
* regular-expression subset.
*/
declare function validateSchemaGraph(graph: SchemaGraph): SchemaValidationError[];
/** Validate one root against an existing graph's definitions. */
declare function validateSchemaRoot(graph: SchemaGraph, root: SchemaType): SchemaValidationError[];
declare function floatFromBits(bits: bigint): number | undefined;
declare function numericRestrictionsMatch(restrictions: NumericRestrictions | undefined, value: number | bigint): boolean;
declare function isQuantityValueRepresentable(value: unknown): value is QuantityValue;
declare function quantityLessOrEqual(left: QuantityValue, right: QuantityValue): boolean | undefined;
type DiscriminatorPairClassification = {
readonly tag: 'reject';
readonly reason: string;
} | {
readonly tag: 'disjoint';
} | {
readonly tag: 'indeterminate';
};
declare function classifyDiscriminatorPair(left: DiscriminatorRule, right: DiscriminatorRule): DiscriminatorPairClassification;
/** Clone a caller-owned graph before the SDK turns it into immutable public state. */
declare function cloneSchemaGraph(graph: SchemaGraph): SchemaGraph;
/** Recursively freezes a schema graph, including the mutable methods of its definition map. */
declare function freezeSchemaGraph(graph: SchemaGraph): SchemaGraph;
declare function freezeSchemaValue(value: unknown, seen: WeakSet