mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-22 13:28:10 +00:00
Adds broad inline comments and JSDoc for CLI, cron, outbound/channel, plugin SDK, ACP, shared helpers, net policy, and related utility contracts. Proof: git diff --check on latest exact head plus focused cron tests passed; CI had no failing checks observed before merge attempt.
47 lines
1.7 KiB
TypeScript
47 lines
1.7 KiB
TypeScript
export type ThreadBindingLifecycleRecord = {
|
|
boundAt: number;
|
|
lastActivityAt: number;
|
|
idleTimeoutMs?: number;
|
|
maxAgeMs?: number;
|
|
};
|
|
|
|
/** Resolves the next expiration for a channel thread binding from idle and max-age limits. */
|
|
export function resolveThreadBindingLifecycle(params: {
|
|
record: ThreadBindingLifecycleRecord;
|
|
defaultIdleTimeoutMs: number;
|
|
defaultMaxAgeMs: number;
|
|
}): {
|
|
expiresAt?: number;
|
|
reason?: "idle-expired" | "max-age-expired";
|
|
} {
|
|
const idleTimeoutMs =
|
|
typeof params.record.idleTimeoutMs === "number"
|
|
? Math.max(0, Math.floor(params.record.idleTimeoutMs))
|
|
: params.defaultIdleTimeoutMs;
|
|
const maxAgeMs =
|
|
typeof params.record.maxAgeMs === "number"
|
|
? Math.max(0, Math.floor(params.record.maxAgeMs))
|
|
: params.defaultMaxAgeMs;
|
|
|
|
// Activity imported from older stores may predate the binding; never expire before bind time.
|
|
const inactivityExpiresAt =
|
|
idleTimeoutMs > 0
|
|
? Math.max(params.record.lastActivityAt, params.record.boundAt) + idleTimeoutMs
|
|
: undefined;
|
|
const maxAgeExpiresAt = maxAgeMs > 0 ? params.record.boundAt + maxAgeMs : undefined;
|
|
|
|
// The lifecycle reports the first real reason so callers can prune or surface it accurately.
|
|
if (inactivityExpiresAt != null && maxAgeExpiresAt != null) {
|
|
return inactivityExpiresAt <= maxAgeExpiresAt
|
|
? { expiresAt: inactivityExpiresAt, reason: "idle-expired" }
|
|
: { expiresAt: maxAgeExpiresAt, reason: "max-age-expired" };
|
|
}
|
|
if (inactivityExpiresAt != null) {
|
|
return { expiresAt: inactivityExpiresAt, reason: "idle-expired" };
|
|
}
|
|
if (maxAgeExpiresAt != null) {
|
|
return { expiresAt: maxAgeExpiresAt, reason: "max-age-expired" };
|
|
}
|
|
return {};
|
|
}
|