@adonis-agora/agent
Version:
Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.
45 lines • 1.97 kB
JavaScript
/**
* Is this tool part of this deployment right now? `ToolSpec.enabled` and the handler's
* `isEnabled()` are ANDed — either one saying no is enough — and both default to yes.
*
* Resolved per turn rather than at registration, so the answer can come from configuration that
* did not exist when the tool was registered.
*/
export async function isToolEnabled(spec, handler) {
const declared = typeof spec.enabled === 'function' ? await spec.enabled() : (spec.enabled ?? true);
if (!declared) {
return false;
}
return handler?.isEnabled === undefined ? true : await handler.isEnabled();
}
/**
* Drop tools this deployment has turned off, before anyone asks who may call them. A disabled tool
* is absent, not forbidden — the difference matters, because "forbidden" tells the model (and the
* user reading a refusal) that the capability exists.
*/
export async function filterToolsByEnabled(entries) {
const checked = await Promise.all(entries.map(async (entry) => ({
entry,
enabled: await isToolEnabled(entry.spec, entry.handler),
})));
return checked.filter((row) => row.enabled).map((row) => row.entry);
}
/**
* May this actor use this tool, per the tool's OWN gate? Tools without a `canUse` say yes and are
* governed by the `RolesPolicy` alone.
*/
export async function canActorUseTool(actor, handler) {
return handler?.canUse === undefined ? true : await handler.canUse(actor);
}
/**
* Drop tools whose own `canUse` refuses this actor. Runs after the app-wide `RolesPolicy`, and is
* additive to it — a tool can narrow who reaches it, never widen.
*/
export async function filterToolsByCanUse(entries, actor) {
const checked = await Promise.all(entries.map(async (entry) => ({
entry,
allowed: await canActorUseTool(actor, entry.handler),
})));
return checked.filter((row) => row.allowed).map((row) => row.entry);
}
//# sourceMappingURL=tool-filters.js.map