import { type Settings } from "@opengeni/config"; import { type Database } from "./database.js"; import * as schema from "./schema.js"; /** * An organization's Anthropic API connection can hold several API keys: its * own key is the first member, and the others are stored beside it. They * serve only the connection's `organization-anthropic/` models, never Claude * subscription models. */ export declare const ORGANIZATION_ANTHROPIC_API_KEY_LIMIT = 64; /** The member id of the connection's own key, which changes when that key is replaced. */ export declare function organizationAnthropicConnectionKeyMemberId(connectionVersion: number): string; export type OrganizationAnthropicApiKey = { id: string; /** Null for the connection's own key. */ label: string | null; connectionKey: boolean; /** The Anthropic organization the key belongs to, when known. */ anthropicOrganizationId: string | null; /** When Anthropic refused the key for lack of credits; null while it serves. */ creditRefusedAt: Date | null; createdAt: Date; }; export type OrganizationAnthropicApiKeys = { connectionVersion: number; keys: OrganizationAnthropicApiKey[]; }; type ConnectionRow = typeof schema.organizationModelProviderConnections.$inferSelect; /** * The keys a request may send, as `[{id, credentialEncrypted}]` with the * connection's own key first, leaving out keys refused for lack of credits. * Null when the connection has only its own key: it then serves exactly as a * single-key connection always has. */ export declare function organizationAnthropicApiKeyPool(row: Pick): { id: string; credentialEncrypted: string; }[] | null; /** The organization's Anthropic API keys (never their values); null without an active connection. */ export declare function listOrganizationAnthropicApiKeys(db: Database, input: { organizationId: string; actorSubjectId: string; }): Promise; /** * Add a further API key to the organization's active Anthropic API * connection. Adding a key that is already a member (same digest) returns * that member unchanged, so a retried request adds it once. Null without an * active connection: the first key is the connection itself. */ export declare function addOrganizationAnthropicApiKey(db: Database, input: { organizationId: string; actorSubjectId: string; label: string; credentialEncrypted: string; credentialDigest: string; anthropicOrganizationId: string | null; }): Promise<{ key: OrganizationAnthropicApiKey; added: boolean; } | null>; /** Rename a further key; the connection's own key has no label. Null when there is no such key. */ export declare function relabelOrganizationAnthropicApiKey(db: Database, input: { organizationId: string; actorSubjectId: string; keyId: string; label: string; }): Promise; /** * Remove a further key. The connection's own key is replaced or disconnected * through the connection instead. False when there is no such key. */ export declare function removeOrganizationAnthropicApiKey(db: Database, input: { organizationId: string; actorSubjectId: string; keyId: string; }): Promise; /** * Let a key Anthropic refused for lack of credits serve again (after the * administrator added credits); if it is still out of credits, the next * request refused marks it again. Null when there is no such key. */ export declare function clearOrganizationAnthropicApiKeyCreditRefusal(db: Database, input: { organizationId: string; actorSubjectId: string; keyId: string; }): Promise; /** * Record that Anthropic refused one of the organization's pooled API keys * for lack of credits, from a turn of one of its workspaces, so later turns * skip it. Only a current member is recorded; a key replaced or removed since * is ignored. Never touches the connection's version or keys. */ export declare function markOrganizationAnthropicApiKeyCreditRefused(db: Database, input: { accountId: string; workspaceId: string; keyId: string; at?: Date; }): Promise; /** * The pooled keys (encrypted) a workspace's turn may send, read under the * workspace's RLS scope; null for a single-key or missing connection. */ export declare function loadOrganizationAnthropicApiKeyPoolForWorkspace(db: Database, input: { accountId: string; workspaceId: string; }): Promise<{ id: string; credentialEncrypted: string; }[] | null>; /** * The organization's pooled Anthropic API keys a workspace's turn may send, * decrypted; null for a single-key or missing connection, or without an * encryption key (then nothing loads, as for the connection's own key). */ export declare function loadOrganizationAnthropicApiKeysForExecution(db: Database, settings: Settings, input: { accountId: string; workspaceId: string; }, prepared?: { loadOrganizationCredentials: boolean; organizationAnthropicApiKeys: { id: string; credentialEncrypted: string; }[] | null; }): Promise<{ id: string; apiKey: string; }[] | null>; export {};