/** * SuperGrok's legacy route shapes on the shared subscription core (design * docs/design/subscription-core-2026-10-07.md, 5.3 "SuperGrok track", X2b). * * The pools, settings and writers are the provider-neutral ones (`subscription-core/administration`, * `subscription-core/connections`); this module only projects neutral rows * into the legacy SuperGrok account shape and encodes a device-code sign-in * as the adapter's stored credential. Nothing here reads or writes a legacy * SuperGrok table or returns credential material. */ import type { Database } from "./database.js"; import { type SubscriptionCoreConnectionRow } from "./subscription-core/administration.js"; import { type SubscriptionCoreConnectResult, type SubscriptionCoreConnectScope } from "./subscription-core/connections.js"; import { type SubscriptionCoreXaiTokens } from "./subscription-core-xai-adapter.js"; export type SubscriptionCoreXaiScope = "workspace" | "user" | "organization"; /** The legacy SuperGrok account shape the SuperGrok routes render. */ export type XaiSubscriptionAccountMetadata = import("./subscription-core/account-projection.js").SubscriptionCorePoolAccount; /** * One core connection in the legacy SuperGrok account shape. The cutover * maps the legacy quota to one window (design 5.3, "Health and quota"), so * the first window is the legacy percentage and reset. Fields no SuperGrok * route projects (`version`, the allocator counters) are not carried. */ export declare function projectSubscriptionCoreXaiAccount(row: SubscriptionCoreConnectionRow, scope: SubscriptionCoreXaiScope, allocatorEnabled?: boolean): XaiSubscriptionAccountMetadata; export type SubscriptionCoreXaiPoolProjection = { /** * The legacy pool name: `user` when the viewer's own personal connections * are listed (their Personal workspace), `organization` while an available * organization pool serves the workspace, else `workspace`. */ source: SubscriptionCoreXaiScope; accounts: XaiSubscriptionAccountMetadata[]; activeCredentialId: string | null; rotationEnabled: boolean; }; /** * A workspace's SuperGrok pool for one viewer in the legacy shapes. Shared * connections carry the pool they serve this workspace from; personal ones * (listed only to their owner, only in the owner's Personal workspace) are * `user`. */ export declare function getSubscriptionCoreXaiWorkspaceProjection(db: Database, input: { accountId: string; workspaceId: string; viewerSubjectId: string; }): Promise; /** The organization's own SuperGrok accounts and rotation; empty for a non-administrator. */ export declare function getSubscriptionCoreXaiOrganizationProjection(db: Database, input: { organizationId: string; subjectId: string; }): Promise; /** * Connect (or reconnect) one SuperGrok account from a completed device-code * sign-in through the neutral connect writer: a personal connection in the * person's own Personal workspace (and only there for `personal`, a legacy * `user` scope), else a shared one. The stored credential * is the adapter's format; the token identity subject is both the upstream * account and the signed-in person. The caller delivers `wake` after commit. */ export declare function connectSubscriptionCoreXaiConnection(db: Database, input: SubscriptionCoreConnectScope & { encryptionKey: Uint8Array; tokens: SubscriptionCoreXaiTokens; identitySubject: string; accountEmail: string | null; label: string | null; expiresAt: Date | null; connectedBySubjectId: string | null; }): Promise;