@adonis-agora/agent
Version:
Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.
102 lines • 5.02 kB
TypeScript
import { type Discovered, HttpJsonCache } from './discovery.js';
import { DpopKey } from './dpop.js';
import { PoppyHttp, type PoppyRequestInit } from './http.js';
import type { AgentIdentity } from './identity.js';
import type { AccountTokenRecord, CompanyState, StateStore, TokenRecord } from './store.js';
import { type NarrowingParams, TokenClient } from './token_client.js';
import type { AuthServerMetadata, PoppyDocument, TokenResponse } from './types.js';
import { type FetchLike, type SecurityOptions } from './util.js';
export interface PoppyAgentOptions extends SecurityOptions {
store: StateStore;
identity: AgentIdentity;
/** Local user ("profile") the agent acts for. Defaults to `default`. */
profile?: string | undefined;
fetch?: FetchLike | undefined;
log?: ((line: string) => void) | undefined;
maxRetryAfterSeconds?: number | undefined;
}
/** Entry point: one agent identity, one local state file, one local user. */
export declare class PoppyAgent {
readonly opts: PoppyAgentOptions;
readonly http: PoppyHttp;
readonly cache: HttpJsonCache;
readonly profile: string;
constructor(opts: PoppyAgentOptions);
get identity(): AgentIdentity;
get store(): StateStore;
log(line: string): void;
/** Discovers a Company and loads (or creates) this user's state there, by its identifier. */
company(domain: string): Promise<CompanyClient>;
}
interface TokenOptions extends NarrowingParams {
/** No DPoP proof: MCP servers take Bearer tokens (section 7). */
bearer?: boolean | undefined;
forceRenew?: boolean | undefined;
}
export interface SignInResult {
grantedScope: string;
/** Requested scopes the User didn't grant (4.7: "checks scope before continuing"). */
missingScopes: string[];
}
export type CompanyFetchInit = Omit<PoppyRequestInit, 'dpop' | 'accessToken' | 'scheme' | 'session'> & NarrowingParams & {
/** The service's URL, whose protected resource metadata says if it needs its own tokens (4.5). */
service?: string | undefined;
bearer?: boolean | undefined;
/** Only the Session header, even with a refresh token. */
signedOut?: boolean | undefined;
};
/** One User at one Company: the Session, the refresh token, and requests to its endpoints. */
export declare class CompanyClient {
#private;
readonly agent: PoppyAgent;
readonly discovered: Discovered;
readonly state: CompanyState;
readonly dpop: DpopKey;
constructor(agent: PoppyAgent, discovered: Discovered, state: CompanyState);
/** The Company's OAuth calls. A Company without an issuer offers no sign-in (3.2). */
get tokens(): TokenClient;
get document(): PoppyDocument;
get metadata(): AuthServerMetadata;
/** The Company's identifier (3.2): its issuer, or its HTTPS domain without one. */
get issuer(): string;
get userId(): string;
get http(): PoppyHttp;
get security(): SecurityOptions;
get accountToken(): AccountTokenRecord | undefined;
/** The current Session's `sid`, chosen here at random (5.2). */
get sessionId(): string;
save(): Promise<void>;
/** Stops using the current `sid`; the next request starts a new Session (5.5). */
newSession(): Promise<void>;
/** Sends a proof with token requests when the issuer's metadata lists ES256 (4.5). */
tokenDpop(): DpopKey | undefined;
/** A `Poppy-Session` JWT good for this one request (5.2). */
sessionJwt(method: string, url: string, accessToken?: string | undefined): Promise<string>;
/**
* An access token, refreshed when close to expiry, or `null` when signed out. A refresh answered
* with `invalid_grant` means the sign-in is gone: the Session continues signed out (5.5).
*/
token(opts?: TokenOptions): Promise<TokenRecord | null>;
/** Stores the result of any sign-in type (4.7): the refresh token and the access token. */
applySignIn(resp: TokenResponse, via: AccountTokenRecord['via'], requestedScope: string): Promise<SignInResult>;
/** Sign out (5.5): revoke the refresh token. Sessions carry on signed out. */
signOut(): Promise<boolean>;
/**
* A request to one of the Company's APIs or endpoints: the Session header and, when signed in, an
* access token (5.2, 4.5). `invalid_session` starts a new Session once (section 7), and
* `invalid_token` refreshes once, falling back to signed out when the sign-in is gone (5.5).
*/
fetch(url: string, init?: CompanyFetchInit): Promise<Response>;
/** `fetch` + JSON, mapping failures to typed errors (section 7, 8.13). */
json<T>(url: string, init?: CompanyFetchInit): Promise<{
status: number;
body: T;
}>;
}
/**
* Maps a failed resource response to a typed error. A challenge without an error code means the
* request needs the account: it's handled as `insufficient_scope` (section 7).
*/
export declare function throwForResponse(res: Response): Promise<never>;
export {};
//# sourceMappingURL=company.d.ts.map