Commit 8ba804e
feat(auth): env-side AI-seat marker via sys_user.ai_access + resolveCtx synthesis (#2327)
* feat(auth): sys_user.ai_access → synthesize the ai_seat capability (simple AI-seat model)
The env DB (Turso) is single-org and has only sys_user — so the AI seat is best
modeled as a boolean on the user, not a permission set. Add `ai_access` as a
better-auth additionalField (rides on the session user) and have resolveCtx
synthesize the `ai_seat` capability when it is true. The existing per-agent gate
(evaluateAgentAccess → requires ai_seat), catalog filter, and frontend are
unchanged — they now admit a user via the field with NO permission-set grant.
ADDITIVE: the permission-set path still works (a user can get ai_seat from either
source), so there is no regression while the rest of the simplification (have the
entitlement layer SET the field + retire the permission-set seed/junction/cap-
middleware + repoint the management UI) lands. Built clean (plugin-auth + hono).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* fix(ai-seat): own ai_access via objectql SysUser def + guarded read (not a better-auth additionalField)
sys_user is a better-auth-MANAGED table and better-auth SELECTs explicit columns.
Declaring ai_access as a better-auth additionalField (my first cut) would make
getSession query a column that may not exist on every env yet → broken auth on
deploy. Safe-by-construction instead:
• drop the additionalField (better-auth stays oblivious to the column);
• own ai_access on the objectql SysUser object def → provisioned by boot
schema-sync, and editable as a normal field (the management UI is a checkbox);
• resolveCtx reads it via a GUARDED system query (.catch → []), so a missing
column / failed read can only NO-OP — never break auth.
Built clean (platform-objects + plugin-auth + plugin-hono-server). Amends the
prior additionalField approach on this branch.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>1 parent 0885fde commit 8ba804e
3 files changed
Lines changed: 45 additions & 0 deletions
File tree
- packages
- platform-objects/src/identity
- plugins
- plugin-auth/src
- plugin-hono-server/src
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
395 | 395 | | |
396 | 396 | | |
397 | 397 | | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
398 | 411 | | |
399 | 412 | | |
400 | 413 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
324 | 324 | | |
325 | 325 | | |
326 | 326 | | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
327 | 335 | | |
328 | 336 | | |
329 | 337 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
490 | 490 | | |
491 | 491 | | |
492 | 492 | | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
493 | 517 | | |
494 | 518 | | |
495 | 519 | | |
| |||
0 commit comments