@adonis-agora/agent
Version:
Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.
90 lines • 5.02 kB
TypeScript
import type { AuthServerMetadata, PoppyDocument } from './types.js';
import { type FetchLike, type SecurityOptions } from './util.js';
/** The protocol versions this client implements, as `major.minor` (3.4). */
export declare const SUPPORTED_PROTOCOL_VERSIONS: string[];
export declare const WELL_KNOWN_POPPY_PATH = "/.well-known/poppy.json";
export interface DiscoveryOptions extends SecurityOptions {
/** Use Companies on ports other than 443, for testing (3.1). `insecureDev` implies it. */
allowPorts?: boolean | undefined;
fetch?: FetchLike | undefined;
/** Shared cache honoring `Cache-Control: max-age` (3, 3.2: SHOULD cache). */
cache?: HttpJsonCache | undefined;
/** Don't use a cached copy, as after `version_unsupported` (3.4). Fresh copies are still cached. */
fresh?: boolean | undefined;
}
export interface Discovered {
/** The host that served the document, after any redirects (with its port when not 443). */
domain: string;
wellKnownUrl: string;
/** The document of the chosen version: `poppy.json` itself, or one of its `supported_versions`. */
document: PoppyDocument;
/** The version this client implements that is compatible with the chosen document: `Poppy-Version` (3.4). */
version: string;
/** `scopes_supported` of the domain's protected resource metadata (3.2), when it lists them. */
resourceScopes?: string[] | undefined;
/** The Company's identifier (3.2): its issuer, or `https://{domain}` without one. */
identifier: string;
/** Absent when the Company has no issuer: it offers only signed-out Sessions. */
metadata?: AuthServerMetadata | undefined;
/**
* How discovery established there is no issuer. Only `metadata` says so explicitly, which is what
* lets an agent that knew an issuer accept its removal (3.2).
*/
noIssuer?: 'not_found' | 'metadata' | undefined;
}
/** In-memory cache of JSON documents by URL, by `Cache-Control: max-age`. */
export declare class HttpJsonCache {
private readonly entries;
get(url: string): FetchedJson | undefined;
set(url: string, value: FetchedJson, cacheControl: string | null): void;
}
/**
* Turns user input into the well-known URL. `example.com` → `https://example.com/...`.
* With `insecureDev`, an explicit `http://host:port` is kept, and a bare loopback host
* (`localhost:3333`) defaults to `http:`.
*/
interface FetchedJson {
json: unknown;
finalUrl: URL;
}
export declare function wellKnownUrlFor(input: string, sec?: SecurityOptions): URL;
/** `major.minor` → numbers, or `undefined` when it isn't one. */
export declare function parseVersion(v: unknown): {
major: number;
minor: number;
} | undefined;
/**
* The version this client implements that is compatible with `version`: the same major and, before
* 1.0, the same minor (3.4). The newest one, when several are.
*/
export declare function implementedVersionFor(version: string): string | undefined;
/**
* Chooses the newest version, among `protocol_version` and `supported_versions`, compatible with one
* this client implements (3.4). `undefined` when none is: then no document may be used.
*/
export declare function chooseVersion(json: Record<string, unknown>): string | undefined;
/**
* Validates a Poppy document against 3.1. Unknown fields are ignored, never rejected. The version is
* checked by `chooseVersion`; `expectedVersion` is the one a `supported_versions` link listed it under.
*/
export declare function validatePoppyDocument(json: unknown, servedHost: string, sec?: SecurityOptions, expectedVersion?: string | undefined): PoppyDocument;
/** RFC 9728 section 3.1: the well-known suffix goes between the host and the resource's path. */
export declare function protectedResourceMetadataUrl(resource: string | URL): URL;
/**
* Validates the domain's protected resource metadata (3.2) and answers the issuer the Personal
* Agent uses, or `undefined` when valid metadata names none.
*/
export declare function validateProtectedResourceMetadata(json: unknown, doc: PoppyDocument, domainUrl: string, sec?: SecurityOptions): string | undefined;
/** RFC 8414 section 3: the well-known suffix goes between the host and the issuer's path. */
export declare function authServerMetadataUrl(issuer: string): URL;
/** Validates the issuer metadata against 3.2. */
export declare function validateMetadata(json: unknown, issuer: string, domainUrl: string, sec?: SecurityOptions): AuthServerMetadata;
/**
* Discovery (section 3): fetches `/.well-known/poppy.json`, which must end at that exact path after
* HTTPS-only redirects, then finds the issuer from the domain's protected resource metadata and
* checks both directions of the link. A timeout, another error status or invalid metadata throws:
* only a 404 or valid metadata without servers means there is no issuer (3.2).
*/
export declare function discover(input: string, opts?: DiscoveryOptions): Promise<Discovered>;
export {};
//# sourceMappingURL=discovery.d.ts.map