UNPKG

@adonis-agora/agent

Version:

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

60 lines • 2.79 kB
import type { HttpContext } from '@adonisjs/core/http'; import { type ConsoleAuthorize } from '../console-authorize.js'; import type { DevToolsCaller } from './contract.js'; /** The action tool a {@link DevToolsActionsAuthorizer} is asked about. */ export interface DevToolsActionRequest { /** The lib id: `'payments'`. */ lib: string; /** The full tool name: `'payments_refund_payment'`. */ tool: string; /** Whether the lib marked it as cancelling, refunding, revoking or deleting something. */ destructive: boolean; /** Who is calling (`'user:42'`, `'token:…'`, `'dev-open'`). */ caller: DevToolsCaller; } /** * The function form of `devTools.actions`: decides each action tool for this request. Run while the * request's tools are assembled, so a `false` both hides the tool from `tools/list` and refuses a call * to it. Anything but `true`, or a throw, * refuses. */ export type DevToolsActionsAuthorizer = (ctx: HttpContext, action: DevToolsActionRequest) => boolean | Promise<boolean>; /** * The map form of `devTools.actions`: lib ids and full tool names, each to a console `authorize` * (function, authorizer class or lazy import). A tool-name key wins over its lib's key; an action in * neither is refused. */ export type DevToolsActionsMap = Record<string, ConsoleAuthorize>; /** * What `devTools.actions` may say: * - `'refuse'` (default): no action tool is listed or callable. * - `'execute'`: every action tool of an allowed lib. * - `string[]`: those of these lib ids or tool names. * - {@link DevToolsActionsMap}: per lib or per tool, each with its own `authorize`. * - {@link DevToolsActionsAuthorizer}: a function deciding each action tool. */ export type DevToolsActions = 'refuse' | 'execute' | string[] | DevToolsActionsMap | DevToolsActionsAuthorizer; /** Why an action tool was left out, for the debug line. */ export interface DevToolsActionRefusal { reason: 'not-configured' | 'denied' | 'threw'; error?: unknown; } /** * One request's view of `devTools.actions`: each distinct `authorize` of the map runs at most once, * however many tools point at it. */ export declare class DevToolsActionsGate { #private; constructor(actions: DevToolsActions, ctx: HttpContext, caller: DevToolsCaller); /** Whether `actions` decides per caller (map or function), rather than statically. */ get dynamic(): boolean; /** `true` when the action tool is served to this request, else why not. */ decide(action: { lib: string; tool: string; destructive: boolean; }): Promise<true | DevToolsActionRefusal>; } /** Whether `actions` is the map or function form. */ export declare function isDynamicActions(actions: DevToolsActions): boolean; //# sourceMappingURL=actions.d.ts.map