@adonis-agora/agent
Version:
Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.
147 lines • 6.34 kB
TypeScript
import type { HttpContext } from '@adonisjs/core/http';
/**
* The console switcher contract, version 1.
*
* Every `@adonis-agora` console registers itself into ONE data-only registry bound as a value at
* `'agora.consoles'` (created by whichever lib boots first). Each console then shows a switcher to
* the other consoles the viewer may open. The types are declared locally in every lib (TypeScript is
* structural), so no lib imports another.
*/
declare module '@adonisjs/core/http' {
interface HttpContext {
/**
* `true` while a console switcher runs this console's `authorize` on behalf of another console
* (it only asks whether to list it). An authorizer that audits every call can skip then.
*/
agoraProbe?: boolean;
}
}
/** The container binding the registry lives at. */
export declare const AGORA_CONSOLES_BINDING = "agora.consoles";
/** Bound as a VALUE under `'agora.consoles'`. Data only, so every lib's copy is identical. */
export interface AgoraConsoleRegistry {
readonly version: 1;
readonly entries: AgoraConsoleEntry[];
/**
* Optional, set by an account console (authkit): how a viewer signs out of the app. Every console
* reads it structurally to offer "Sign out" in its sidebar footer. A string is a POST action path.
*/
account?: {
signOut?: string | {
action: string;
} | {
href: string;
};
};
}
export type AgoraConsoleIcon = 'workflow' | 'telescope' | 'media' | 'payments' | 'agent' | 'identity' | 'flags' | 'cms' | 'generic';
/** The decision a console's gate returns. Never throws. */
export interface AgoraConsoleDecision {
allowed: boolean;
reason?: string;
redirectTo?: string;
}
/** One search hit. `href` is a same-origin absolute path. */
export interface AgoraConsoleSearchHit {
title: string;
subtitle?: string;
href: string;
}
export interface AgoraConsoleEntry {
/** `/^[a-z][a-z0-9-]*$/`: `'durable'`, `'telescope'`, `'authkit'`, … */
id: string;
/** Product title (`'Identity'`). */
title: string;
/** Package name, shown as secondary text (`'@adonis-agora/agent'`). */
package?: string;
/** Unknown values render as `'generic'`. */
icon: AgoraConsoleIcon;
/** Same-origin absolute path of the console shell (`'/agent/dashboard'`). */
path: string;
/** Lower first. durable 10, telescope 20, agent 30, payments 40, media 50, authkit 90. */
order: number;
/**
* The console's resolved gate (the one its own routes run). While a switcher runs it for another
* console, `ctx.agoraProbe` is `true`, so an authorizer that writes an audit entry per call can skip.
*/
authorize(ctx: HttpContext): Promise<AgoraConsoleDecision>;
/** Global search provider. Only called after `authorize` allowed the viewer. */
search?(ctx: HttpContext, query: string, limit: number): Promise<AgoraConsoleSearchHit[]>;
}
/** What `GET <console api>/consoles` answers. */
export interface VisibleConsoles {
version: 1;
current: string;
consoles: Array<{
id: string;
title: string;
package?: string;
icon: AgoraConsoleIcon;
href: string;
}>;
}
/** What `GET <console api>/consoles/search?q=` answers. */
export interface ConsoleSearchResults {
version: 1;
query: string;
groups: Array<{
id: string;
title: string;
icon: AgoraConsoleIcon;
hits: AgoraConsoleSearchHit[];
}>;
}
/** Default time each console's `authorize` (and `search`) gets before it counts as hidden. */
export declare const CONSOLE_PROBE_TIMEOUT_MS = 300;
/** Hits returned per console by the global search. */
export declare const CONSOLE_SEARCH_LIMIT = 5;
interface ContainerLike {
hasBinding(binding: string): boolean;
bindValue(binding: string, value: unknown): void;
make(binding: string): Promise<unknown>;
}
interface AppLike {
container: ContainerLike;
}
interface LoggerLike {
warn(message: string): void;
debug?(message: string): void;
}
/** A same-origin absolute path: starts with `/`, not `//`, no backslash, no control characters. */
export declare function isSameOriginPath(value: unknown): value is string;
/**
* Add a console to the shared `'agora.consoles'` registry, creating it when absent. Skips (never
* throws) a registry of another version; warns and skips a duplicate id. Throws on an invalid `id`
* or `path`: that is a programming error. Apps can call it to register a console they mount by hand.
*
* ```ts
* await registerAgoraConsole(app, { id: 'reports', title: 'Reports', icon: 'generic', path: '/reports',
* order: 100, authorize: async (ctx) => ({ allowed: await isStaff(ctx) }) })
* ```
*/
export declare function registerAgoraConsole(app: AppLike, entry: AgoraConsoleEntry, logger?: LoggerLike): Promise<boolean>;
/** The registry, when one is bound and is version 1. */
export declare function readAgoraConsoles(app: AppLike): Promise<AgoraConsoleRegistry | null>;
/** How many consoles besides `selfId` are registered (the shell's `switcher.others`). */
export declare function countOtherConsoles(registry: AgoraConsoleRegistry | null, selfId: string): number;
/**
* The consoles (other than `selfId`) the viewer may open: every `authorize` runs in parallel, each
* raced against 300 ms; a timeout, a rejection or anything but `allowed: true` hides the console.
*/
export declare function listVisibleConsoles(registry: AgoraConsoleRegistry | null, selfId: string, ctx: HttpContext, options?: {
timeoutMs?: number;
logger?: LoggerLike;
}): Promise<VisibleConsoles>;
/**
* Global search across the consoles the viewer may open. The current console (`selfId`, already
* authorized by its own route guard) is searched without re-running its gate; the others only after
* their `authorize` allowed. Each `search` gets `timeoutMs` and returns at most `limit` hits; a hit
* whose `href` is not a same-origin path is dropped.
*/
export declare function searchConsoles(registry: AgoraConsoleRegistry | null, selfId: string, ctx: HttpContext, query: string, options?: {
timeoutMs?: number;
limit?: number;
logger?: LoggerLike;
}): Promise<ConsoleSearchResults>;
export {};
//# sourceMappingURL=console-switcher.d.ts.map