32 lines
881 B
TypeScript
32 lines
881 B
TypeScript
import {
|
|
GLOBAL_PAUSE_REASON_KEY,
|
|
GLOBAL_PAUSE_SOURCE_KEY,
|
|
GLOBAL_PAUSE_UNTIL_KEY,
|
|
isOrchestratorSession,
|
|
parsePauseUntil,
|
|
} from "@composio/ao-core";
|
|
|
|
export interface GlobalPauseState {
|
|
pausedUntil: string;
|
|
reason: string;
|
|
sourceSessionId: string | null;
|
|
}
|
|
|
|
export function resolveGlobalPause(
|
|
sessions: Array<{ id: string; metadata: Record<string, string> }>,
|
|
): GlobalPauseState | null {
|
|
for (const session of sessions) {
|
|
if (!isOrchestratorSession(session)) continue;
|
|
const parsed = parsePauseUntil(session.metadata[GLOBAL_PAUSE_UNTIL_KEY]);
|
|
if (!parsed || parsed.getTime() <= Date.now()) continue;
|
|
|
|
return {
|
|
pausedUntil: parsed.toISOString(),
|
|
reason: session.metadata[GLOBAL_PAUSE_REASON_KEY] ?? "Model rate limit reached",
|
|
sourceSessionId: session.metadata[GLOBAL_PAUSE_SOURCE_KEY] ?? null,
|
|
};
|
|
}
|
|
|
|
return null;
|
|
}
|