import { type Settings } from "@opengeni/config"; import type { CompatibleModelReasoning } from "@opengeni/contracts"; import { type Database } from "./database.js"; import { type ConnectedModelListPrice, type ConnectedModelListPricing } from "./organization-model-providers.js"; /** Active endpoints one organization can connect at once. */ export declare const ORGANIZATION_COMPATIBLE_ENDPOINT_LIMIT = 50; export type OrganizationCompatibleEndpointApi = "chat" | "responses"; export type OrganizationCompatibleEndpoint = { id: string; status: "active" | "revoked"; version: number; /** The non-secret public HTTPS base URL, usually ending in /v1. */ baseUrl: string; api: OrganizationCompatibleEndpointApi; label: string | null; createdAt: Date; updatedAt: Date; }; export type OrganizationCompatibleEndpointModel = { id: string; connectionId: string; upstreamModelId: string; label: string | null; /** The reasoning levels the model accepts; null when it declares none. */ reasoning: CompatibleModelReasoning | null; /** The catalogue model whose list rate prices it; null when unknown or custom. */ listPricingModelId: string | null; /** The administrator's own list rate; null when unknown or priced from a model. */ listPricing: ConnectedModelListPricing | null; version: number; retiredAt: Date | null; createdAt: Date; updatedAt: Date; }; /** An active endpoint a workspace can use, with its active models. */ export type OrganizationCompatibleEndpointForWorkspace = { id: string; baseUrl: string; api: OrganizationCompatibleEndpointApi; label: string | null; models: OrganizationCompatibleEndpointModel[]; /** Present only when credentials were requested and an encryption key is configured. */ credentialEncrypted?: string; }; /** The organization's active endpoints with their active models, for its administrators. */ export declare function listOrganizationCompatibleEndpoints(db: Database, input: { organizationId: string; actorSubjectId: string; }): Promise<{ endpoint: OrganizationCompatibleEndpoint; models: OrganizationCompatibleEndpointModel[]; }[]>; /** One endpoint of the organization, active or revoked, for its administrators. */ export declare function getOrganizationCompatibleEndpoint(db: Database, input: { organizationId: string; actorSubjectId: string; connectionId: string; }): Promise; /** * Connect a new endpoint with its first model, which the caller has already * checked against the endpoint with this key. A replay of the same operation * returns what it created; any other request under its id conflicts. */ export declare function createOrganizationCompatibleEndpoint(db: Database, input: { organizationId: string; actorSubjectId: string; credentialEncrypted: string; credentialDigest: string; baseUrl: string; api: OrganizationCompatibleEndpointApi; label?: string | null; upstreamModelId: string; /** The first model's reasoning levels, already resolved by the caller. */ reasoning?: CompatibleModelReasoning | null; operationId: string; }): Promise<{ endpoint: OrganizationCompatibleEndpoint; model: OrganizationCompatibleEndpointModel; }>; export declare function replaceOrganizationCompatibleEndpointKey(db: Database, input: { organizationId: string; actorSubjectId: string; connectionId: string; credentialEncrypted: string; credentialDigest: string; operationId: string; expectedVersion: number; }): Promise; /** Disconnect an endpoint: its key is erased and its models leave every workspace. */ export declare function revokeOrganizationCompatibleEndpoint(db: Database, input: { organizationId: string; actorSubjectId: string; connectionId: string; operationId: string; expectedVersion: number; }): Promise; /** * The administrator's view of an active endpoint and its decrypted key, for * checking a model or a replacement key before it is saved. Never returned * to a client. Null without an active endpoint or an encryption key. */ export declare function loadOrganizationCompatibleEndpointCredentialForAdministrator(db: Database, settings: Settings, input: { organizationId: string; actorSubjectId: string; connectionId: string; }): Promise<{ endpoint: OrganizationCompatibleEndpoint; apiKey: string; } | null>; export declare function listOrganizationCompatibleEndpointModels(db: Database, input: { organizationId: string; actorSubjectId: string; connectionId: string; }): Promise; /** Add a model (already checked against the endpoint) to an active endpoint. */ export declare function createOrganizationCompatibleEndpointModel(db: Database, input: { organizationId: string; actorSubjectId: string; connectionId: string; upstreamModelId: string; label?: string; /** The model's reasoning levels, already resolved by the caller. */ reasoning?: CompatibleModelReasoning | null; operationId: string; }): Promise; /** Set what one active endpoint model's usage costs (see the shared setter). */ export declare function setOrganizationCompatibleEndpointModelListPrice(db: Database, input: { organizationId: string; actorSubjectId: string; connectionId: string; customModelId: string; expectedVersion: number; price: ConnectedModelListPrice; }): Promise; /** * Set the reasoning levels of one active endpoint model. The model's version * guards concurrent edits; repeating the change that produced the current * version returns the model unchanged. */ export declare function setOrganizationCompatibleEndpointModelReasoning(db: Database, input: { organizationId: string; actorSubjectId: string; connectionId: string; customModelId: string; expectedVersion: number; reasoning: CompatibleModelReasoning | null; }): Promise; export declare function retireOrganizationCompatibleEndpointModel(db: Database, input: { organizationId: string; actorSubjectId: string; connectionId: string; customModelId: string; expectedVersion: number; operationId: string; }): Promise; /** * The active endpoints a workspace can use (the connection's access policy * decides, as for every organization account) with their active models. * Internal reader: the caller owns the workspace's tenant scope. Encrypted * keys are read only on request. */ export declare function listOrganizationCompatibleEndpointsInScope(scopedDb: Database, input: { accountId: string; includeCredentials?: boolean; }): Promise; /** The organization endpoints one workspace can use; secret-free unless credentials are asked for. */ export declare function listOrganizationCompatibleEndpointsForWorkspace(db: Database, input: { accountId: string; workspaceId: string; includeCredentials?: boolean; }): Promise; /** * The endpoints with their decrypted keys, for the execution overlay. An * endpoint keeps no key when none was read or no encryption key is * configured, so its requests fail closed. */ export declare function decryptOrganizationCompatibleEndpointKeys(settings: Settings, endpoints: readonly OrganizationCompatibleEndpointForWorkspace[]): (Omit & { apiKey?: string; })[]; /** * The decrypted key of one active endpoint a workspace can use, read under * the workspace's scope like the execution catalog. Null when the endpoint is * gone, out of the workspace's reach or no encryption key is configured. */ export declare function loadOrganizationCompatibleEndpointApiKey(db: Database, settings: Settings, input: { accountId: string; workspaceId: string; connectionId: string; }): Promise;