/** * Describes how a serializable initialization payload becomes a stable object * in the main-thread runtime. * * @public */ export interface MainThreadObjectTypeDefinition { /** A globally unique and stable type key. */ readonly type: string; /** * Create the realized main-thread object. * * This must be a capture-free Main Thread Function. Imports used by the * function must come from shared-runtime modules. */ readonly create: (initialValue: I) => O; } /** * An immutable MainThreadObject type token with source-handle inspection. * * The factory function belongs to the input definition and is not exposed * by the returned token. In the background runtime they compile to opaque * Main Thread Function descriptors rather than bundling their implementation. * * @public */ export interface MainThreadObjectType { /** A globally unique and stable type key. */ readonly type: string; /** * Narrow a value to a source-runtime handle of this exact type. * * This does not create or access the realized main-thread object. */ readonly downcast: (value: unknown) => MainThreadObjectHandle | undefined; } /** * An opaque source-runtime handle for an object realized on the main thread. * * A handle has logical identity and is serializable, but it is not the target * object or an RPC stub. Capturing it in a main-thread function resolves it to * the corresponding local target object. Development builds may wrap the * background handle in a throwing guard solely to diagnose invalid access; * that guard never forwards operations between runtimes. * * @public */ export declare abstract class MainThreadObjectHandle { /** * The payload used to create the realized object. * * Readonly is a TypeScript contract; the value is not frozen at runtime. */ get creationPayload(): Readonly; } /** * Define a main-thread object type for use by a library-provided hook. * * @param definition - Stable type key and target-object factory function. * @returns An immutable object type definition. * @public */ export declare function defineMainThreadObjectType(definition: MainThreadObjectTypeDefinition): MainThreadObjectType; /** * Create a stable handle that resolves to an object of the supplied type in * main-thread functions. * * This primitive is intended for library hooks. The returned target type is * only callable in a main-thread function; it must not be used from the * background runtime. * * @param objectType - Definition used to realize the target object. * @param initialValue - JSON-serializable initialization payload. * @returns The main-thread-only target type. * @public */ export declare function useMainThreadObject(objectType: MainThreadObjectType, initialValue: I): O;