mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-21 02:06:43 +00:00
* refactor(infra): consolidate retry scheduling * fix(build): wire shared retry package * fix(build): resolve retry package in source graphs * fix(infra): keep retry adapter dependency-free
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
// Adapts the dependency-free retry scheduler to core runtime facilities.
|
|
import {
|
|
createRetryRunner,
|
|
resolveRetryConfig,
|
|
toRetryError,
|
|
type RetryConfig,
|
|
type RetryInfo,
|
|
type RetryOptions,
|
|
} from "../../packages/retry/src/index.js";
|
|
import { getRetryAttemptErrors, recordRetryAttemptErrors } from "./retry-attempt-errors.js";
|
|
import { generateSecureFraction } from "./secure-random.js";
|
|
|
|
export { resolveRetryConfig, type RetryConfig, type RetryInfo, type RetryOptions };
|
|
|
|
function createRetryFailure(rawAttemptErrors: readonly unknown[]): Error {
|
|
const attemptErrors = rawAttemptErrors.flatMap((err) => getRetryAttemptErrors(err) ?? [err]);
|
|
const failure = toRetryError(
|
|
attemptErrors.at(-1) ?? new Error("Retry failed"),
|
|
"Non-Error thrown",
|
|
);
|
|
if (attemptErrors.length > 1) {
|
|
// Preserve terminal-error identity while carrying all attempts into
|
|
// duplicate-send decisions outside the channel adapter.
|
|
recordRetryAttemptErrors(failure, attemptErrors);
|
|
}
|
|
return failure;
|
|
}
|
|
|
|
/** Runs an async operation until it succeeds, policy stops, or attempts are exhausted. */
|
|
export const retryAsync = createRetryRunner({
|
|
random: generateSecureFraction,
|
|
createFailure: createRetryFailure,
|
|
});
|