mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-24 02:21:12 +00:00
* refactor(matrix): retire pre-2026.4 legacy crypto and flat-storage migrations * refactor(cli): drop pre-tsdown daemon-cli dist compat shim from the build * refactor(diffs): remove deprecated image*/format tool params and output aliases * refactor(ui): drop pre-gateway-scoped localStorage readers and legacy theme map * refactor: remove assorted pre-2026.4 compat shims and deprecated aliases * fix(discord): map legacy thread-binding fields in the doctor JSON import * fix(msteams): keep bot read fallback for legacy imported conversation rows * test(msteams): cover legacy bot-only imported conversation references * fix(ui): keep channel-prefixed session key display fallback * chore: refresh native i18n inventory and build-docker step count * chore(matrix): drop now-unused migration-config module * chore: re-pin plugin SDK public export budget after compat removals * chore: refresh native i18n inventory after rebase * chore: re-pin plugin SDK callable budget and refresh i18n inventory after rebase
70 lines
2.4 KiB
TypeScript
70 lines
2.4 KiB
TypeScript
// Gateway Client module implements readiness behavior.
|
|
import type { GatewayClientOptions } from "./client.js";
|
|
import {
|
|
waitForEventLoopReady,
|
|
type EventLoopReadyOptions,
|
|
type EventLoopReadyResult,
|
|
} from "./event-loop-ready.js";
|
|
import { resolveConnectChallengeTimeoutMs } from "./timeouts.js";
|
|
|
|
export type GatewayClientStartable = {
|
|
start(): void;
|
|
};
|
|
|
|
/** Injectable readiness waiter used by tests and alternate event-loop probes. */
|
|
export type EventLoopReadyWaiter = (
|
|
options?: EventLoopReadyOptions,
|
|
) => Promise<EventLoopReadyResult>;
|
|
|
|
/** Timeout and abort controls for delaying client start until the loop can process IO. */
|
|
export type GatewayClientStartReadinessOptions = {
|
|
timeoutMs?: number;
|
|
clientOptions?: Pick<
|
|
GatewayClientOptions,
|
|
"connectChallengeTimeoutMs" | "env" | "preauthHandshakeTimeoutMs"
|
|
>;
|
|
signal?: AbortSignal;
|
|
};
|
|
|
|
function resolveGatewayClientStartReadinessTimeoutMs(
|
|
options: GatewayClientStartReadinessOptions = {},
|
|
): number {
|
|
if (typeof options.timeoutMs === "number" && Number.isFinite(options.timeoutMs)) {
|
|
return options.timeoutMs;
|
|
}
|
|
const clientOptions = options.clientOptions ?? {};
|
|
const timeoutOverride =
|
|
typeof clientOptions.connectChallengeTimeoutMs === "number" &&
|
|
Number.isFinite(clientOptions.connectChallengeTimeoutMs)
|
|
? clientOptions.connectChallengeTimeoutMs
|
|
: undefined;
|
|
return resolveConnectChallengeTimeoutMs(timeoutOverride, {
|
|
env: clientOptions.env,
|
|
configuredTimeoutMs: clientOptions.preauthHandshakeTimeoutMs,
|
|
});
|
|
}
|
|
|
|
/** Starts a gateway client only after the supplied readiness probe succeeds. */
|
|
export async function startGatewayClientWithReadinessWait(
|
|
waitForReady: EventLoopReadyWaiter,
|
|
client: GatewayClientStartable,
|
|
options: GatewayClientStartReadinessOptions = {},
|
|
): Promise<EventLoopReadyResult> {
|
|
const readiness = await waitForReady({
|
|
maxWaitMs: resolveGatewayClientStartReadinessTimeoutMs(options),
|
|
signal: options.signal,
|
|
});
|
|
if (readiness.ready && !readiness.aborted && options.signal?.aborted !== true) {
|
|
client.start();
|
|
}
|
|
return readiness;
|
|
}
|
|
|
|
/** Starts a gateway client after the default event-loop readiness probe succeeds. */
|
|
export async function startGatewayClientWhenEventLoopReady(
|
|
client: GatewayClientStartable,
|
|
options: GatewayClientStartReadinessOptions = {},
|
|
): Promise<EventLoopReadyResult> {
|
|
return startGatewayClientWithReadinessWait(waitForEventLoopReady, client, options);
|
|
}
|