Files
MonkeyCode/monkeyai/web
..
2026-12-03 14:44:40 +08:00

MonkeyAI admin frontend

中文原文

This React application is the MonkeyAI admin console. It manages members and groups, AI resources, billing, analytics, registered devices, and cloud environments. It also serves browser pages for client sign-in and authorization. The general web workspace is still a placeholder; it is not a replacement for the installed member client.

Where to start

Path Responsibility
src/pages/admin/ Admin screens.
src/pages/ and src/lib/routes.ts Public and client authorization pages, with route metadata for the app.
src/components/ and src/hooks/ Shared UI, reusable feature components, and hooks. shadcn/ui components live in src/components/ui/.
src/lib/ and src/i18n/ API helpers, browser compatibility, and localization.
test/ and scripts/ Node tests, browser regressions, and the local cloud-environment fixture.
nginx/ and Dockerfile Nginx ingress configuration and the production static image.

Run locally

Use a Node release supported by the locked dependencies (Node 22.18 is sufficient for a local build; the Docker builder uses Node 26.13.1) and pnpm 10.12.4 as pinned in package.json. Run from monkeyai/web. Keep pnpm-lock.yaml and the patch declared in pnpm-workspace.yaml together.

pnpm install --frozen-lockfile
MONKEYAI_DEV_BACKEND_URL=http://localhost:8080 MONKEYAI_DEV_API_URL=http://localhost:8080 pnpm dev --force

Open http://localhost:5173/. For real sign-in, use a development backend with member writers and set its MONKEYAI_PUBLIC_URL to the browser-visible Vite origin. Set both proxy variables explicitly for local work. In vite.config.ts, MONKEYAI_DEV_BACKEND_URL handles /oauth, /mcp and /v1; MONKEYAI_DEV_API_URL handles /api, device routes and OAuth discovery metadata. The latter defaults to a remote service, not localhost. Restart Vite with --force after changing PostCSS or reinstalling patched dependencies so it doesn't reuse an old prebundle.

To work on cloud-environment screens without a backend, build the UI and start the local fixture:

pnpm build
pnpm dev:environments

Open http://127.0.0.1:4187/admin/environments/instances. The fixture binds to loopback, accepts a PORT override, and uses disposable in-memory data. /__fixture is test-only. A running container in the UI is not proof that its runtime is connected; see the environment control guide for state meanings.

Build and test

pnpm build     # tsc -b, then Vite; writes dist/
pnpm preview   # serves the build locally, not a complete backend
pnpm test      # Node test runner over test/*.test.mjs
pnpm lint      # ESLint

The Vite build targets Chrome 86 for JavaScript and CSS. Browser tests use playwright-core and a real Chrome/Chromium binary, not a spoofed User-Agent. Build first, then run the suite with each browser you need to support:

CHROME_BIN=/path/to/chrome86 pnpm test:browser
CHROME_BIN=/path/to/current-chrome pnpm test:browser

The default harness serves the built app with simulated API responses. Only use ADMIN_DEV_URL with an isolated development server and test data: the base harness then lets unmatched requests reach that server. The test scripts also expose focused regressions; set CHROME_BIN for each of these:

Script Coverage
test:browser:members, test:browser:quotas Virtualized member and quota lists, measured rows, selection, focus, and large fixtures.
test:browser:task-analysis Session/model metrics, responsive layouts, loading/empty states, and retry.
test:browser:billing-users, test:browser:account-links Billing user selection and account links that carry the selected user.
test:browser:table-query Bookmarks, filters, pagination, and history navigation (use SCENARIO_FILTER=task:390 for that case only).
test:browser:client-devices, test:browser:auth Registration inventory and client authorization.

Contributor notes

  • Chrome 86: Keep Tailwind CSS on 3.4 and selectors compatible with PostCSS. Do not introduce cascade layers, OKLCH, or other unsupported CSS into shared styles. browser-compat.ts and platform-compat.ts preserve native behavior where available. Keep ResizeObserver breakpoints and fallback aspect ratios where required. Recheck the versioned Base UI click-event patch when upgrading; use both old and current Chromium. ZIP remains a fallback for large imports on browsers that cannot stage files to disk. Clipboard access still follows browser permissions and secure-context rules.
  • Components: From this directory, npx shadcn@latest add button is the generator entry point. Review the output before applying it: current templates may use Tailwind 4 syntax. Import the local button as @/components/ui/button. GroupSelect is controlled and does not fetch data or grant access. Supply group/user options, localized labels, and a controlled { groupIds, userIds } value; reset it when changing selection modes. Searching uses names, optional emails, and pinyin without changing the saved expansion state. Cascaded grants are computed against the complete tree, not just visible results.
  • Virtual lists: The group tree and measured member cards keep expansion and selection outside mounted rows. Preserve source keys for users who appear in several groups and keep focused, menu, and drag rows mounted while active. Virtualization reduces mounted elements, not the records fetched. Quota cards retain search and sorting when account details close.
  • Analytics: Session metrics and the model overview each come from a server snapshot, not generated sample data. Preserve the distinction between zero counts, missing duration/percentile data, loading, and errors. Trend buckets use Beijing time; overflow segments are grouped as “Other.”
  • Filters and CSV: Persist submitted filters and pagination to the URL; leave unsubmitted input in the form. User-picker results use exact IDs; preserve the handling of older text-query links. CSV exports reuse the active filters without changing the page and cap a request at 5,000 rows, with a UTF-8 BOM.
  • Device registration and client authorization: A device row represents (user_id, machine_id), not an online session or version history. Preserve the distinction between OS and OS version, list/chart filter parity, and separate chart retries. /client-login requires an explicit confirmation even with no additional scopes; keep approved_scopes and X-CSRF-Token on confirmation and validate the final redirect against the approved destination.