UNPKG

@adonis-agora/agent

Version:

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

100 lines • 5.22 kB
/** * What the federated console's channel needs to authenticate a console with a token (authkit's * service tenants, typically): where the console gets its token, how the owning app verifies it, * and the capability rule. The same contract every Agora control plane uses, so * `authkitTenantToken(...)` and `authkitTenantVerifier(...)` from `@adonis-agora/authkit-client` * plug in without a wrapper. */ /** The resource (RFC 8707) an agent app's console commands answer for: the `aud` of its tokens. */ export declare const AGENT_CONSOLE_RESOURCE = "urn:agora:agent"; /** * What a console's token (and the viewer the console sends) must hold for each command. A granted * `agent:*` or `*` covers them all (see {@link capabilityAllows}). */ export declare const AGENT_CONSOLE_SCOPES: { /** Approve or reject a pending tool call (`decide`). */ readonly decide: 'agent:approvals:decide'; /** Change a model price (`upsertPrice`). */ readonly pricingWrite: 'agent:pricing:write'; /** * Every action of the console (the uniform Agora name): covers `decide` and `upsertPrice`, as do * `agent:console:*`, `agent:*` and `*`. */ readonly consoleWrite: 'agent:console:write'; /** * Every console read (the uniform Agora name). A known alias that grants nothing today: the * agent's console has no read command (it reads the other app's tables directly). */ readonly consoleRead: 'agent:console:read'; }; /** Where a console gets the token each command carries. */ export interface TenantToken { get(): Promise<string>; /** Drops a cached token (after the app refused it), so the next `get` fetches a fresh one. */ reset?(): void; } /** * A fixed token, a function returning one (`authkitTenantToken(...)`, which also has a `reset()`), * or an object with `get()`. */ export type TenantTokenSource = string | (() => Promise<string>) | { get(): Promise<string>; reset?(): void; invalidate?(): void; }; /** Normalizes every accepted token source into {@link TenantToken}. */ export declare function resolveTenantToken(source: TenantTokenSource): TenantToken; /** What the owning app trusts about a console: derived from its verified token, never the message. */ export interface VerifiedTenant { /** The app the token is for. A command runs only when it is this app. */ partition: string; /** What the token may do (`agent:approvals:decide`, `agent:pricing:write`). Never defaulted. */ capabilities: string[]; /** The service-tenant client behind the token, when it says. */ clientId?: string; /** * The token's audience already names this app (an authkit app-call token, `aud = * urn:agora:app:<this app>`): `partition` is then the CALLING app (the console's), and the rule * "the token's partition is this app" does not apply. Set only by a verifier, never by a message. */ audienceBound?: boolean; environment?: string; label?: string; expiresAt?: number; } /** What a verifier receives. Only `token` is trusted, once verified. */ export interface TenantAuthRequest { token?: string | undefined; /** The app the command is for (this app). Advisory: the verified `partition` decides. */ partition?: string | undefined; tenant?: string | undefined; app?: string | undefined; headers?: Readonly<Record<string, string | undefined>> | undefined; } export type TenantVerifier = (request: TenantAuthRequest) => VerifiedTenant | null | Promise<VerifiedTenant | null>; export interface TenantVerifierObject { verify(request: TenantAuthRequest): VerifiedTenant | null | Promise<VerifiedTenant | null>; } export interface TenantVerifierModule { default?: TenantVerifier | TenantVerifierObject | (new () => TenantVerifierObject); verify?: TenantVerifier | TenantVerifierObject; tenantVerifier?: TenantVerifier | TenantVerifierObject; } /** A function, a class instance, a class, or a lazy `() => import(...)` of one. */ export type TenantVerifierInput = TenantVerifier | TenantVerifierObject | (new () => TenantVerifierObject) | (() => Promise<TenantVerifierModule> | TenantVerifierModule); /** * `null` refuses; `{ partition, capabilities }` accepts; anything else throws, so a malformed * answer is never taken for an accepted console. Capabilities are not defaulted. */ export declare function checkVerifiedTenant(result: unknown): VerifiedTenant | null; /** Turns any `verifyTenant` form into the function the channel calls. */ export declare function resolveTenantVerifier(input: TenantVerifierInput): (request: TenantAuthRequest) => Promise<VerifiedTenant | null>; /** * Whether `granted` covers `required`: the Agora-wide rule. Both sides split on `:`; a granted `*` * segment matches exactly one segment, and a trailing `*` also matches any further ones. So `*` * and `agent:*` cover `agent:approvals:decide`; nothing else is implied. */ export declare function capabilityAllows(granted: readonly string[], required: string): boolean; /** JSON with sorted object keys: the same value always has the same text (and MAC). */ export declare function canonicalJson(value: unknown): string; //# sourceMappingURL=tenant_auth.d.ts.map