mirror of
https://github.com/morluto/rea.git
synced 2026-11-15 11:13:21 +00:00
Introduce deterministic deep-provider discovery and immutable per-target routing while retaining disjoint artifact and native capability families. Expose provider selection consistently through MCP, CLI, environment configuration, session status, prompt completion, typed diagnostics, and generated documentation. Preserve exact provider/profile provenance without request racing or transparent fallback. Cover overlapping providers, ambiguity, rejection details, cancellation, restoration, package installation, and real Hopper target switching.
26 lines
925 B
TypeScript
26 lines
925 B
TypeScript
/** Sentinel returned when an abort signal wins an asynchronous race. */
|
|
export const ABORTED = Symbol("aborted");
|
|
|
|
/**
|
|
* Await a promise without depending on the producer to observe cancellation.
|
|
* The producer still receives its signal separately and remains responsible for
|
|
* releasing any resources that it owns.
|
|
*/
|
|
export const waitForAbortable = async <Value>(
|
|
pending: Promise<Value>,
|
|
signal: AbortSignal | undefined,
|
|
): Promise<Value | typeof ABORTED> => {
|
|
if (signal === undefined) return pending;
|
|
if (signal.aborted) return ABORTED;
|
|
let onAbort: (() => void) | undefined;
|
|
const cancelled = new Promise<typeof ABORTED>((resolve) => {
|
|
onAbort = () => resolve(ABORTED);
|
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
});
|
|
try {
|
|
return await Promise.race([pending, cancelled]);
|
|
} finally {
|
|
if (onAbort !== undefined) signal.removeEventListener("abort", onAbort);
|
|
}
|
|
};
|