simpl-liste/web
le king fu 88d8976445 feat(web): personal agent tokens, their management routes and the pilot (#200)
An AI assistant will reach an account through a personal token created by a
user signed in on the site. This commit issues, verifies and revokes those
tokens, and adds the pilot switch. The MCP route (#202) and the page (#205)
come later in the stack.

- origin.ts: the list of allowed origins, moved as is from ws.ts, and
  isAllowedOrigin(). ws.ts imports it; no origin check reads request.url,
  whose origin is the container's in production.
- accountLock.ts: lockAccount(tx, userId), a transaction advisory lock per
  account.
- agentAccess.ts: mcpAllowed() reads MCP_ALLOWED_SUBS at every call (absent
  or empty: nobody; `*`: everyone; else a comma-separated list).
  requireAssistantsSession() guards the management routes: any Authorization
  header answers 401 first, then 401 without a site session, then 404 outside
  the pilot.
- agentTokens.ts: slmcp_ + 43 base64url characters; only the SHA-256 and the
  last four characters are stored. Ten tokens per account, counted under the
  account lock; expiry of 90 days, one year (same UTC day) or never;
  verifyAgentToken() accepts the exact Bearer shape only, refuses an expired
  token and writes last_used_at at most once per minute.
- GET and POST /api/agent-tokens, DELETE /api/agent-tokens/[id]: guard, rate
  limit, Origin on writes (403), body, action. Only the 201 of the POST
  carries the token; the eleventh token answers 409 token_limit.
- requireAuth() answers 401 to a Bearer that starts with slmcp_, before any
  call to Logto.
- .env.template: MCP_ALLOWED_SUBS, empty.

Tests: the real requireAuth with next/headers replaced and fetch spied, the
real /api/sync route with an agent token, the three routes on PGlite (two
accounts, cap, Origin with a request URL on the container's host, any
Authorization header, pilot, what the responses and the columns hold), the
token and pilot modules, the shared origin list and the WebSocket upgrade.

Resolves #200

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-16 20:50:30 -05:00
..
public feat: setup Next.js web project with Drizzle + PostgreSQL schema (#35) 2026-04-06 11:03:34 -04:00
scripts feat(web): schema for agent tokens and the agent action journal (#199) 2026-11-16 20:50:30 -05:00
src feat(web): personal agent tokens, their management routes and the pilot (#200) 2026-11-16 20:50:30 -05:00
.env.template feat(web): personal agent tokens, their management routes and the pilot (#200) 2026-11-16 20:50:30 -05:00
.gitignore feat: setup Next.js web project with Drizzle + PostgreSQL schema (#35) 2026-04-06 11:03:34 -04:00
AGENTS.md feat: setup Next.js web project with Drizzle + PostgreSQL schema (#35) 2026-04-06 11:03:34 -04:00
CLAUDE.md feat: setup Next.js web project with Drizzle + PostgreSQL schema (#35) 2026-04-06 11:03:34 -04:00
Dockerfile fix: auto-apply migrations on startup + cleanup duplicate inboxes (#60) 2026-04-09 08:53:09 -04:00
drizzle.config.ts feat: setup Next.js web project with Drizzle + PostgreSQL schema (#35) 2026-04-06 11:03:34 -04:00
eslint.config.mjs feat: setup Next.js web project with Drizzle + PostgreSQL schema (#35) 2026-04-06 11:03:34 -04:00
next.config.ts feat: setup Next.js web project with Drizzle + PostgreSQL schema (#35) 2026-04-06 11:03:34 -04:00
package-lock.json fix(deps): bump tsx to 4.23.15 in web to drop esbuild 0.27.7 2026-11-07 21:08:15 -05:00
package.json test(sync): automate the post-merge sync checks against the real companion (#169) 2026-11-08 15:36:12 +00:00
postcss.config.mjs feat: setup Next.js web project with Drizzle + PostgreSQL schema (#35) 2026-04-06 11:03:34 -04:00
README.md feat: setup Next.js web project with Drizzle + PostgreSQL schema (#35) 2026-04-06 11:03:34 -04:00
server.ts fix: auto-apply migrations on startup + cleanup duplicate inboxes (#60) 2026-04-09 08:53:09 -04:00
tsconfig.json test(sync): automate the post-merge sync checks against the real companion (#169) 2026-11-08 15:36:12 +00:00
vitest.config.mts fix(web): accept a date alone as a task due date and show save errors (#198) 2026-11-14 18:43:55 -05:00

This is a Next.js project bootstrapped with create-next-app.

Getting Started

First, run the development server:

npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev

Open http://localhost:3000 with your browser to see the result.

You can start editing the page by modifying app/page.tsx. The page auto-updates as you edit the file.

This project uses next/font to automatically optimize and load Geist, a new font family for Vercel.

Learn More

To learn more about Next.js, take a look at the following resources:

You can check out the Next.js GitHub repository - your feedback and contributions are welcome!

Deploy on Vercel

The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.

Check out our Next.js deployment documentation for more details.