UNPKG

@adonis-agora/agent

Version:

Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.

38 lines • 1.53 kB
/** * Resolve what a console viewer sees under tenancy: * * 1. `authorize` granted no `tenants` → the viewer's own active tenant (none → nothing, and the * console asks to choose an organization). * 2. `tenants: [...]` → those; `'*'` → every tenant, plus rows with none. * 3. `?tenant=<id>` narrows to one of them; an id outside them reads as empty (`forged`). */ export function resolveConsoleTenantScope(input) { const nullRows = input.nullRows ?? 'tenantless'; const allowed = input.granted ?? (input.own.mode === 'tenant' ? [input.own.tenant.id] : input.own.mode === 'tenantless' ? [] : '*'); const selected = typeof input.selected === 'string' && input.selected !== '' ? input.selected : null; if (selected !== null) { const ok = allowed === '*' || allowed.includes(selected); return ok ? { allowed, scope: { tenants: [selected], includeNull: nullRows === 'shared' }, selected, forged: false, } : { allowed, scope: { tenants: [], includeNull: false }, selected: null, forged: true }; } if (allowed === '*') return { allowed, scope: undefined, selected: null, forged: false }; return { allowed, scope: { tenants: allowed, includeNull: allowed.length > 0 && nullRows === 'shared' }, selected: null, forged: false, }; } //# sourceMappingURL=tenant-scope.js.map