diff --git a/apps/web/app/(app)/subscriptions/actions.ts b/apps/web/app/(app)/subscriptions/actions.ts index 69106286..975ce5db 100644 --- a/apps/web/app/(app)/subscriptions/actions.ts +++ b/apps/web/app/(app)/subscriptions/actions.ts @@ -2,7 +2,7 @@ // «Подписки» (PEP-67): every action is superadmin-only (others get "not found"). import { createPool, deletePool, getProject, lendSubscription, PeppaError, returnLoanNow, requireSuperadmin, setProjectPool, updatePool, updateSubscription, type SubscriptionProvider } from "@peppa/core"; -import { addPoolSubscription, addSubscription, cancelLogin, checkSubscription, finishClaudeLogin, removeSubscription, startClaudeLogin, startCodexLogin } from "@peppa/runner"; +import { addPoolSubscription, addSubscription, switchAgents, cancelLogin, checkSubscription, finishClaudeLogin, removeSubscription, startClaudeLogin, startCodexLogin } from "@peppa/runner"; import { revalidatePath } from "next/cache"; import { redirect } from "next/navigation"; import { asWebActor, requireUser } from "@/lib/auth"; @@ -60,6 +60,16 @@ export async function addPoolSubscriptionAction(f: FormData) { }); } +/** PEP-176: the superadmin moves the agents off a subscription by hand. */ +export async function switchAgentsAction(f: FormData) { + await attempt(f, async () => { + const fromId = Number(str(f, "fromId")); + const to = str(f, "toId"); + const r = await switchAgents(db, { fromId, toId: to ? Number(to) : null }); + return `${BASE}?switched=${r.moved}&left=${r.skipped}#s-${fromId}`; + }); +} + export async function reconnectSubscription(f: FormData) { await attempt(f, async () => { const id = Number(str(f, "id")); diff --git a/apps/web/app/(app)/subscriptions/page.tsx b/apps/web/app/(app)/subscriptions/page.tsx index 320fe248..8db4c00c 100644 --- a/apps/web/app/(app)/subscriptions/page.tsx +++ b/apps/web/app/(app)/subscriptions/page.tsx @@ -23,6 +23,7 @@ import { deletePoolAction, deleteSubscriptionAction, addPoolSubscriptionAction, + switchAgentsAction, returnLoanAction, reconnectSubscription, submitLoginCode, @@ -136,6 +137,25 @@ function SetCard({ o, subs, t }: { o: PoolOverview; subs: SubscriptionView[]; t: o={o} action={(s) => ( <> + {/* PEP-176: move this subscription's agents by hand — to one of the pool's working subscriptions or to any free one. */} + {s.activeSessions > 0 && ( +
+ + + + {o.subscriptions + .filter((x) => x.id !== s.id && x.usable) + .map((x) => ( + + ))} + + + + )}