UNPKG

@adonis-agora/agent

Version:

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

102 lines • 5.71 kB
import type { AgentConsoleCommandsConfig } from '../define_config.js'; import { type AuthkitClientLike, type CryptoRuntimeLike } from './auto_crypto.js'; import type { FederatedConsoleApp } from './console.js'; import { type ConsoleCryptoOptions } from './redis_channel.js'; import type { TenantVerifierInput } from './tenant_auth.js'; /** The siblings found in the app. */ export interface ConsoleAuthEnv { crypto?: CryptoRuntimeLike | undefined; authkit?: AuthkitClientLike | undefined; /** Where the console side warns that a command went without its optional token (§13b). */ warn?: ((line: string) => void) | undefined; /** The same, at `info`: when the reason is only a missing grant (§13b). */ info?: ((line: string) => void) | undefined; } /** What the app side (`consoleCommands`) resolved. */ export interface AppConsoleAuth { /** One line per accepted mode, e.g. `crypto (auto, key console-agent)`. Empty: unauthenticated. */ modes: string[]; /** Why an automatic mode did not apply (for the boot error), when none resolved. */ notes?: string[]; secret?: AgentConsoleCommandsConfig['secret']; crypto?: ConsoleCryptoOptions; verifyTenant?: TenantVerifierInput; /** Token mode without crypto: commands arrive sealed to the APP_KEY-derived key pair. */ sealedToAppKey: boolean; /** Crypto mode with a fallback verifier: a command without a token is accepted. */ tokenOptional?: boolean; /** Explicit `crypto` + explicit `verifyTenant`: every crypto command must carry a token. */ tokenRequired?: boolean; /** Automatic crypto mode: the key, in this app's crypto partition. */ auto?: { key: string; partition: string; embedded: boolean; } | undefined; /** * Automatic crypto mode on a crypto tenant, with `logKey`: checks the key once (call it when the * channel starts); later commands' decrypts are the retry ({@link watchTenantConsoleKey}). */ checkKey?: (() => Promise<void>) | undefined; } /** * The label of a key read from authkit's directory: it is fetched on the first command (never at * boot, so a console does not depend on authkit, or on the app having booted first). */ export declare const DIRECTORY_KEY_LABEL = "sealed to the key the app publishes"; /** Where the federated console's authentication is documented. */ export declare const CONSOLE_AUTH_DOCS = "https://davidecarvalho.github.io/agora/docs/agent/governance/federated-console#authenticating-the-console"; /** A side of the federated console that cannot authenticate: thrown at boot (web processes). */ export declare class ConsoleAuthConfigError extends Error { constructor(message: string); } /** The boot error of an app side that resolves no mode (the same wording in every Agora lib). */ export declare function appUnauthenticatedMessage(notes?: readonly string[]): string; /** The app side's boot log line: its modes, then whether it takes actions. */ export declare function appConsoleModesLine(modes: readonly string[], actions: boolean): string; /** * The app side's modes. Tokens: an explicit `verifyTenant` only; else (unless `verifyTenant: false`) * authkit's app-call verifier. Explicit `crypto` / `secret` never suppress that fallback. Crypto: * explicit `crypto` as given; automatic crypto only when nothing is explicit. A crypto command must * carry a token only with explicit `crypto` + explicit `verifyTenant`; with a fallback verifier a * token is checked when sent. Token mode (sealed to the APP_KEY-derived key) is available, beside * crypto, whenever there is a verifier and an APP_KEY. */ export declare function resolveAppConsoleAuth(options: AgentConsoleCommandsConfig, env: ConsoleAuthEnv & { hasAppKey: boolean; /** The short id of the APP_KEY-derived public key (token mode's label); never its material. */ appKeyId?: string | undefined; /** Where the tenant key check logs (automatic crypto on a crypto tenant). */ logKey?: ((note: { level: 'info' | 'warn'; line: string; }) => void) | undefined; }): AppConsoleAuth; /** What the console side resolved for one `dashboard.apps` entry. */ export interface FederatedAppAuth { /** `false`: browse-only (`actions: false`), no command is sent. */ actions: boolean; /** One line per sending mode. Empty with `actions` on: unauthenticated (a boot error). */ modes: string[]; /** Why an automatic mode did not apply (for the boot error), when none resolved. */ notes?: string[]; /** The entry with what was resolved automatically filled in (unchanged otherwise). */ entry: FederatedConsoleApp; /** Automatic crypto mode with crypto embedded in this app: the key to ensure in `partition`. */ ensureKey?: { key: string; partition: string; } | undefined; } /** The boot error of a console entry that resolves no mode while it may take actions. */ export declare function consoleUnauthenticatedMessage(key: string, notes?: readonly string[]): string; /** The console side's mode for one other app (see the module comment for what wins). */ export declare function resolveFederatedAppAuth(key: string, entry: FederatedConsoleApp, env: ConsoleAuthEnv): FederatedAppAuth; /** * Whether a failed mint means only that the console's client is not granted that app (§13b, the * same rule in every lib): the code `invalid_target`, or a message mentioning `invalid_target`, * "not granted" or "no grant" (any case). Anything else (`unauthorized_client`, `invalid_client`, * authkit unreachable) is not. */ export declare function isMissingGrant(error: unknown): boolean; //# sourceMappingURL=console_auth.d.ts.map