Skip to content

[Epic] PAGS Admin / Operator Portal #27

Description

@serge-ivo

Epic: PAGS Admin / Operator Portal

PAGS has no working admin portal. Today there is only a static stub at platform/store/admin/index.html that lists published agents from the public /v1/agents endpoint; its "All Users" and "Recent Usage" tables are hard-coded placeholders that are never populated. requireAdmin() exists (workers/api/src/lib/auth.ts) but is called by zero routes — there is no cross-user/operator API of any kind. As the operator you cannot see: all users, all agents/instances, aggregate usage, or platform AI spend.

This is now urgent because PLATFORM_AI_ENABLED="true" (workers/api/wrangler.toml) means the platform pays for internal AI (embeddings + conversation summaries + translation fallback) on its own Cloudflare account, and that spend is invisible in-app — the ai_usage ledger records CF calls at cost_micros≈0, so today it only shows in the raw Cloudflare dashboard.

Goal

A real operator portal: all-users, all-agents/instances, aggregate usage + spending (with platform-paid-vs-BYOK split), errors/trace/ops monitoring, moderation, and an admin-action audit log — modeled on the sibling stores but fit to PAGS's data model.

Cross-store reference (surveyed 2026-08-01)

  • FGS (fgs/admin/) — the most complete: React SPA served by a CF Worker (hash routing, Tailwind). Pages: Overview, Ops (stuck/failed sessions), Games, Errors, Users, User Detail, Sessions, Session View (+ inject prompt), Provision. Auth = Google sign-in + ADMIN_EMAILS allowlist. Endpoints: /api/stats, /api/users, /api/allusers, /api/errors, /api/sessions, /api/comp (grants), /api/userkey.
  • FAS (fas/admin/ + packages/backend/routes/content-admin.ts) — adds CF-Access JWT gating, moderation (browse/delete KV/collections/counters), traffic analytics (CF Analytics Engine), deprovision, /v1/admin/{users,apps,stats,agent-sessions,agent-errors} behind requireAdmin (ADMIN_GITHUB_LOGINS).
  • PAS (pas/console AdminView + packages/backend) — the financial layer: submission review (approve/reject → provision), platform analytics (/v1/analytics/admin/platform, ClickHouse), Stripe Connect payouts. PAS's own documented gaps (no all-users list, no error UI, no usage/cost admin, no moderation, no audit trail) are exactly what this epic should NOT repeat.

Architecture decision (PAGS-fit)

Do not stand up a separate admin worker/DNS like FAS/FGS. PAGS is a single self-contained monorepo; the host worker already serves store/ (incl. /admin). Plan:

  • Gating: reuse the existing requireAdmin + session.roles model (admin role lives in users.roles JSON, baked into the session JWT at sign-in). No new auth system.
  • API: new /v1/admin/* route group in workers/api, every handler behind requireAdmin.
  • UI: a React admin app (mirror store/console — React 19 + Tailwind v4 + Vite) served at /admin by the host worker, replacing the static stub. Client-side gate via /v1/auth/me roles; the real enforcement is server-side.

Child issues

Non-goals (for this epic)

Backend APIs (need #28):

Frontend (need #29 + #35):

Suggested order: #28#29 → APIs (#30#34, parallel) → #35 → UI pages (#36#41, parallel). Start #32/#39 early — they close the invisible-platform-spend gap that motivated this epic.

Spend-metering follow-ups (split out of #32):

Progress: API tier #28/#32/#44/#30 + admin SPA (#29/#35/#36/#37/#39) all live on main + deployed. proagentstore.online/admin is up. Remaining: #31 Agents/Instances, #33 Errors/Ops, #34 Moderation, #38/#40/#41 UI; spend follow-ups #45/#46; CF Access with #35 note.

Metadata

Metadata

Assignees

No one assigned

    Labels

    admin-portalPAGS admin/operator portalenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions