You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Return 401 instead of a 500 when the host has not resolved a principal
A stock mount 500s on every knowledge route.
The routes read c.get("principal") but mount at /api/knowledge/*, which is
outside /api/tenants/:tenantId/* — the prefix Interchange's createResolveTenant
covers, and where it reads the tenant from the path param. Nothing populates the
context for our prefix, so a host that just calls mountKnowledgeEngine per the
README gets:
TypeError: undefined is not an object (evaluating 'principal.id')
at packages/hub-api/src/middleware/grant.ts:55:9
requireGrant dereferences the principal with no guard of its own, so it throws
before caller() runs — and caller() already has a good error message for exactly
this case that nobody ever sees. The failure surfaces as a 500 with a stack
trace pointing into Interchange, which reads as this SDK being broken rather
than as the host missing middleware.
Adds requirePrincipal(), mounted ahead of grantGuard on all three routes,
returning 401 principal_required with an actionable message. The README
documents the middleware the host has to supply.
This is the minimum fix. Moving the routes under /api/tenants/:tenantId/ would
remove the requirement entirely and need no host glue — worth considering, but
it is a breaking path change so it should be a deliberate call rather than
folded in here.
Tests: 145 pass, 0 fail. Typecheck clean.
Refs CL-4506
Claude-Session: https://claude.ai/code/session_017GTgGzn5xAwvkU2GAPAHpF
0 commit comments