mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 15:58:27 +00:00
refactor(daemon): share runtime and service probe helpers
This commit is contained in:
27
src/infra/pairing-pending.ts
Normal file
27
src/infra/pairing-pending.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
type PendingState<TPending> = {
|
||||
pendingById: Record<string, TPending>;
|
||||
};
|
||||
|
||||
export async function rejectPendingPairingRequest<
|
||||
TPending,
|
||||
TState extends PendingState<TPending>,
|
||||
TIdKey extends string,
|
||||
>(params: {
|
||||
requestId: string;
|
||||
idKey: TIdKey;
|
||||
loadState: () => Promise<TState>;
|
||||
persistState: (state: TState) => Promise<void>;
|
||||
getId: (pending: TPending) => string;
|
||||
}): Promise<({ requestId: string } & Record<TIdKey, string>) | null> {
|
||||
const state = await params.loadState();
|
||||
const pending = state.pendingById[params.requestId];
|
||||
if (!pending) {
|
||||
return null;
|
||||
}
|
||||
delete state.pendingById[params.requestId];
|
||||
await params.persistState(state);
|
||||
return {
|
||||
requestId: params.requestId,
|
||||
[params.idKey]: params.getId(pending),
|
||||
} as { requestId: string } & Record<TIdKey, string>;
|
||||
}
|
||||
Reference in New Issue
Block a user