@adonis-agora/agent
Version:
Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.
50 lines • 2.74 kB
JavaScript
import { FEDERATED_APP_KEY } from '../federation/app_key.js';
/** Fill defaults for the optional dashboard config block. */
export function resolveDashboardConfig(config) {
const resolved = {
enabled: config?.enabled ?? true,
viewer: config?.viewer ?? null,
signOut: config?.signOut ?? null,
apps: validApps(config?.apps),
appLabel: config?.appLabel ?? 'This app',
};
if (config?.path !== undefined)
resolved.path = config.path;
if (config?.authorize !== undefined)
resolved.authorize = config.authorize;
if (config?.accessDenied !== undefined)
resolved.accessDenied = config.accessDenied;
return resolved;
}
function validApps(apps) {
for (const key of Object.keys(apps ?? {})) {
if (!FEDERATED_APP_KEY.test(key)) {
throw new Error(`[@adonis-agora/agent] dashboard.apps: "${key}" is not a valid app key (1–64 characters of A-Z, a-z, 0-9, _ . -)`);
}
}
return { ...(apps ?? {}) };
}
/** The wording logged when the read-model the console reads was turned off. */
const NO_GOVERNANCE_QUERIES_WARNING = '[@adonis-agora/agent-dashboard] the governance console was NOT mounted: `governanceQueries` is set to `false` in config/agent.ts, so the cross-actor read-model was never built and the `/agent/governance/*` routes it serves do not exist — the console would load and then fail on every panel but Quota. Remove `governanceQueries: false` (omit it to get the Lucid read-model when the main store is Lucid, or pass a store/factory explicitly) to mount the read-model and this console. To keep the console off on purpose and silence this, set `dashboard: { enabled: false }`.';
/**
* Decide whether to register the console's routes at all — the router-free core of the provider's
* mount check. The console mounts unless `dashboard: { enabled: false }`, or unless
* `governanceQueries: false` removed the `/agent/governance/*` routes every panel but Quota reads
* (a shell that can only 404 its own data is worse than none, so that case says so at boot).
* Access is `dashboard.authorize`'s job, not this one.
*/
export function decideDashboardMount(enabled, governanceQueries) {
if (!enabled)
return { mount: false, reason: 'disabled' };
// ONLY an explicit `false` is decidable here. `undefined` does NOT mean "no read-model": the agent
// provider defaults it to the Lucid read-model whenever the main store is Lucid.
if (governanceQueries === false) {
return {
mount: false,
reason: 'no-governance-queries',
warning: NO_GOVERNANCE_QUERIES_WARNING,
};
}
return { mount: true };
}
//# sourceMappingURL=define_config.js.map