@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
31 lines • 1.57 kB
JavaScript
import { listSlots } from "@earendil-works/pi-ai/auth/pool/slots";
import { writeHealthUnlessStoreBusy } from "./health-write.js";
import { CredentialSlotRepository } from "./state-store.js";
/**
* The stored slots a login started: every slot it created and every slot whose material it replaced. Pool health
* is keyed to the account, so a token refresh keeps a block (senpi#4093). A login is different: it is the user's own
* step to repair an account, or it puts another account under a slot name a removed or signed-out one used (an opaque
* token's account key is its slot name). Neither may inherit the verdicts recorded before it.
*/
function slotsStartedByLogin(before, after) {
const previous = new Map(listSlots(before).map((slot) => [slot.name, slot]));
return listSlots(after)
.filter((slot) => {
const old = previous.get(slot.name);
return old === undefined || !sameMaterial(old, slot);
})
.map((slot) => slot.name);
}
function sameMaterial(a, b) {
return a.access === b.access && a.refresh === b.refresh && a.key === b.key;
}
export async function retireLoginSlotHealth(statePath, providerId, before, after) {
const started = slotsStartedByLogin(before, after);
if (started.length === 0)
return;
const repository = new CredentialSlotRepository(statePath);
for (const name of started) {
await writeHealthUnlessStoreBusy(`login of ${name}`, () => repository.mutateSlotState(providerId, "stored", name, () => undefined));
}
}
//# sourceMappingURL=login-health.js.map