1 | import Stagehand from './stagehand';
|
2 | import { RemoteType, HandlerType, MethodsOnly } from './utils/types';
|
3 | declare const STAGEHAND_INSTANCE = "--stagehand-instance";
|
4 | /**
|
5 | * The remote implementation of a type `T`. It only includes `T`s methods, and the return values
|
6 | * of those methods are all made async if they weren't already.
|
7 | */
|
8 | export type Remote<T> = RemoteType<MethodsOnly<T>> & {
|
9 | [STAGEHAND_INSTANCE]: Stagehand<T>;
|
10 | };
|
11 | /**
|
12 | * The necessarily implementation type of an intended remote interface `T`. All methods in
|
13 | * `Implementation<T>` are allowed to return promises even if the corresponding method in `T`
|
14 | * does not, but `Implementation<T>` also requires that all incoming callbacks be async, since
|
15 | * they correspond to a remote type themselves.
|
16 | */
|
17 | export type Implementation<T> = HandlerType<T>;
|
18 | /**
|
19 | * The minimal interface needed for stagehand communication. The `adapters` directory contains
|
20 | * utilities for converting common types (e.g. Node's `ChildProcess` or the Web's `MessagePort`)
|
21 | * into `MessageEndpoint`s.
|
22 | */
|
23 | export interface MessageEndpoint {
|
24 | onMessage(callback: (message: unknown) => void): void;
|
25 | sendMessage(message: unknown): void;
|
26 | disconnect(): void;
|
27 | }
|
28 | /**
|
29 | * Given a message endpoint and a backing implementation object, listens for a connection on the
|
30 | * given endpoint and responds to commands that come in over it. This function will typically be
|
31 | * called in whatever secondary thread/process will be servicing commands from the primary.
|
32 | */
|
33 | export declare function launch<T>(endpoint: MessageEndpoint, implementation: Implementation<T>): Promise<Stagehand<T>>;
|
34 | /**
|
35 | * Given a message endpoint (and typically an explicit type parameter indicating the interface of
|
36 | * the remote implementation), returns a promise that will resolve when successfully connected to
|
37 | * the implementation on the other side of that endpoint.
|
38 | *
|
39 | * The resulting object will have methods defined on it that correspond to those of the backing
|
40 | * implementation, returning a promise for the eventual result of that method.
|
41 | */
|
42 | export declare function connect<T>(endpoint: MessageEndpoint): Promise<Remote<T>>;
|
43 | /**
|
44 | * Given a remote object (as returned from `connect`), disconnects from the source and closes the connection.
|
45 | */
|
46 | export declare function disconnect<T>(remote: Remote<T>): void;
|
47 | export {};
|