import { Domain } from '@things-factory/shell'; import type { AIClient } from '../types.js'; import { type AiAgentEntry } from './agent-directory.js'; /** * **The one door to a model** (design/ai/agent-settings.md ยง4). * * Every call that reaches a provider gets its client here, for a domain: the agent is the one asked for, or the * domain's default, and its key is the closest one on the domain chain. There is no deployment-wide client - a domain * with no usable agent has no AI (user decision 2026-10-12). * * The client handed back is metered: each provider request writes one AiUsage row with the domain, the person, the * agent and what was used (ADR-0061 decision 6). */ export interface AiClientRequest { domain: Domain; /** The person calling. Empty for a call with no person, such as a webhook. */ user?: { id: string; } | null; /** The agent the person picked. Empty takes the domain's default. */ agentId?: string | null; /** The conversation mode, when the call is part of a conversation. */ modeKind?: string | null; /** The conversation, by id. */ sessionId?: string | null; } /** The client of one agent, as a call got it. */ export interface AgentClient extends AIClient { readonly agent: { id: string; name: string; provider: string; model: string; }; } /** * Once every usage row asked for so far is written (or failed and said so). For a process that closes its database * after its last call -- a script running scenarios -- so the last rows are not lost to a closed handle. */ export declare function aiUsageRecorded(): Promise; export declare function aiClientFor(request: AiClientRequest): Promise; /** * The agent a request is answered by. A named agent that this domain cannot use is refused, never swapped for * another; no agent at all is "not configured". */ export declare function pickAgent(entries: AiAgentEntry[], agentId: string | null | undefined, defaultAgentId?: string): AiAgentEntry; /** The UTC hour a moment falls in. */ export declare function hourOf(moment: Date): Date; /** Why a provider request failed, as the usage row keeps it. */ export declare function outcomeOf(error: any): string; type TestClientResolver = (request: AiClientRequest) => AgentClient; export declare function isAIClientForTesting(): boolean; /** * Tests answer aiClientFor with a client of their own - no database, no provider, no usage rows. A client is wrapped * as an agent named after it; a function decides per request. `undefined` puts the real door back. */ export declare function setAIClientForTesting(client: AIClient | TestClientResolver | undefined): void; export {};