@sema-agent/core
Version:
Stateless, task-oriented AI agent core
20 lines (19 loc) • 1.52 kB
TypeScript
/**
* Whether the engine treats a value a host store or callback returned as asynchronous, at the places that used to judge
* with `instanceof Promise`: the global `instanceof Promise` accepts it (as before — subclasses, objects inheriting
* `Promise.prototype` and Proxies around a Promise included), or it is a native Promise that judgment does not accept
* (one of another realm, one whose prototype chain was changed, or this realm's own intrinsic Promise on a host that
* replaced `globalThis.Promise`). A plain object that only carries a `then` is not asynchronous. The value's `then` is
* not read.
*/
export declare function isHostPromise(v: unknown): v is Promise<unknown>;
/**
* The asynchronous form of a host-returned value, judged as {@link isHostPromise} judges it. A value the global
* `instanceof Promise` accepts is returned as it is (the same object: its own `then` / `catch` are the ones the caller
* calls), and so is an intrinsic Promise the global judgment does not accept because a host replaced the global. A native
* Promise of another realm, or one whose prototype chain was changed, is adopted into a new intrinsic Promise that
* settles as it settles, attached through the intrinsic `then` (the value's own `then` is never read; an attachment that
* throws becomes the new Promise's rejection). Every other value answers `undefined`. `T` is what the caller knows the
* value settles to.
*/
export declare function adoptHostPromise<T>(v: unknown): Promise<T> | undefined;