import { Domain } from '@things-factory/shell'; import { type AiAgentSpec, type AiAgentsSetting } from './agent-spec.js'; /** * Which agents a domain can use, read up its chain of domains (design/ai/agent-settings.md §3-3). * * A domain sees its own agents and every agent of the domains above it. The definition belongs to the domain that * declared it; the key is the closest `AiAgent::::apiKey` EnvVar, so a domain below can answer an inherited agent * with a key of its own. */ /** * Where the key an agent answers with comes from, seen from the domain asking: * own - this domain's key for its own agent * inherited - a domain above holds the key * overridden - an inherited agent answered with this domain's key * missing - no key anywhere on the chain; the agent cannot answer */ export type AiAgentKeyState = 'own' | 'inherited' | 'overridden' | 'missing'; export interface AiAgentEntry { spec: AiAgentSpec; /** The domain that declared the agent. */ ownerDomainId: string; inherited: boolean; /** An inherited agent this domain turned off for itself. */ turnedOff: boolean; keyState: AiAgentKeyState; /** The domain whose key answers. */ keyDomainId?: string; /** Shown only for a key of this domain (ADR-0112 decision 5). A key from above is never hinted below. */ keyHint?: string; /** Active, not turned off here, and has a key. */ usable: boolean; /** Server-only - never put on a GraphQL type. */ apiKey?: string; /** For a client cache: changes whenever the key does. */ keyVersion?: string; } export interface AiAgentDirectory { domainId: string; /** The domain and its ancestors, closest first, with names for the screen. */ chain: { id: string; name: string; }[]; /** This domain's own agents first, then each ancestor's, closest first. */ entries: AiAgentEntry[]; /** This domain's stored setting, as parsed. */ own: AiAgentsSetting; /** The agent a request without a choice gets, and how it was decided. */ defaultAgentId?: string; defaultFrom: 'own' | 'inherited' | 'first' | 'none'; } export declare function readAiAgentDirectory(given: Domain | { id: string; }): Promise; /** * A caller that holds only the domain's id (a background job, a webhook) still gets the domain's whole chain: the walk * needs `parentId`, which an id alone does not carry. */ export declare function fullDomain(given: Domain | { id: string; }): Promise; /** Every domain below this one, any depth. */ export declare function readDescendantDomains(domain: Domain): Promise; /** * For each of this domain's agents, the domains below that use it - every descendant that has not turned it off. * The owner sees these before deleting, turning off or rekeying an agent (§3-3 point 8). */ export declare function readAgentUsersBelow(domain: Domain, agentIds: string[]): Promise>;