/** * Deterministic connected-account selection for a capability intent. The LLM * proposes a provider-neutral capability; this module — never the model — * decides which connected account (and therefore adapter) is eligible, using * policy, health, location, and cost in a fixed total order. A pinned * `requestedAccountId` is honored exactly or fails loudly: an ineligible * pinned account is never silently substituted with a different account * (wrong-account prevention). Failures reuse the typed policy-denial and * unavailable codes from `types/provider-integrations`, and a policy denial * always outranks mere unavailability: an account-independent denial is * decided before any account is inspected, and an account-scoped denial is * preferred over any unavailability collected across candidates. */ import { type CapabilityPolicyDenialCode, type CapabilityRiskLevel, type CapabilityUnavailableCode, type ConnectedAccount, type ConnectedAccountMode } from "../types/provider-integrations.js"; /** Provider-neutral intent evaluated before dispatch binding. */ export interface AccountSelectionIntent { capabilityId: string; riskLevel: CapabilityRiskLevel; /** Exact pinned account, or null to let deterministic ranking choose. */ requestedAccountId: string | null; } /** Deterministic policy inputs; absent constraints are explicitly null. */ export interface AccountSelectionPolicy { allowedModes: readonly ConnectedAccountMode[] | null; allowedProviderIds: readonly string[] | null; blockedAccountIds: readonly string[]; maxRiskLevel: CapabilityRiskLevel; preferredRegion: string | null; maxUnitCostMicros: number | null; } /** Operational signal for one account; every candidate account must have one. */ export interface AccountSelectionSignal { accountId: string; healthy: boolean; region: string | null; unitCostMicros: number; } export interface AccountSelectionRationale { regionMatched: boolean; unitCostMicros: number; consideredAccountIds: readonly string[]; } export type AccountSelectionResult = { outcome: "selected"; account: ConnectedAccount; rationale: AccountSelectionRationale; } | { outcome: "denied"; reasonCode: CapabilityPolicyDenialCode; accountId: string | null; } | { outcome: "unavailable"; code: CapabilityUnavailableCode; retryable: boolean; }; /** * Selects the single eligible account for the intent, or the typed reason * there is none. Deterministic: identical inputs always yield the identical * result, ranked by region match, then unit cost ascending, then most recent * use, then `accountId` ascending. */ export declare function selectConnectedAccount(intent: AccountSelectionIntent, accounts: readonly ConnectedAccount[], policy: AccountSelectionPolicy, signals: readonly AccountSelectionSignal[]): AccountSelectionResult;