@opengeni/db 0.27.8 → 0.27.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/dist/{chunk-M6EOXYHK.js → chunk-JYQPJ6Y5.js} +59 -50
  2. package/dist/chunk-JYQPJ6Y5.js.map +1 -0
  3. package/dist/{chunk-IHPCI4GV.js → chunk-RPHPNVWW.js} +3 -1
  4. package/dist/chunk-RPHPNVWW.js.map +1 -0
  5. package/dist/codex-token-resolver.d.ts +50 -8
  6. package/dist/connection-token-resolver.d.ts +45 -7
  7. package/dist/database.d.ts +137 -0
  8. package/dist/index.d.ts +83 -184
  9. package/dist/index.js +2983 -2691
  10. package/dist/index.js.map +1 -1
  11. package/dist/insights.d.ts +1 -1
  12. package/dist/memory-governance.d.ts +1 -1
  13. package/dist/new-session-drafts.d.ts +1 -1
  14. package/dist/preference-registry.d.ts +1 -1
  15. package/dist/provision-roles.d.ts +1 -1
  16. package/dist/provision-roles.js +1 -1
  17. package/dist/runtime-posture.d.ts +3 -3
  18. package/dist/schema.d.ts +155 -96
  19. package/dist/schema.js +3 -1
  20. package/dist/scoped-knowledge.d.ts +1 -1
  21. package/dist/session-control.d.ts +1 -1
  22. package/dist/session-queue-commands.d.ts +1 -1
  23. package/dist/session-realtime-context.d.ts +1 -1
  24. package/dist/session-realtime-ledger.d.ts +1 -1
  25. package/dist/session-realtime-mirror.d.ts +1 -1
  26. package/dist/session-realtime-state.d.ts +1 -1
  27. package/dist/session-realtime-terminal.d.ts +1 -1
  28. package/dist/session-realtime.d.ts +1 -1
  29. package/dist/session-tool-call-settlement.d.ts +1 -1
  30. package/dist/turn-initiator.d.ts +1 -1
  31. package/dist/workspace-artifacts.d.ts +1 -1
  32. package/dist/workspace-instruction-policies.d.ts +1 -1
  33. package/drizzle/0171_social_connection_subject_ownership.sql +53 -0
  34. package/drizzle/0172_retire_model_visible_github_token.sql +86 -0
  35. package/drizzle/0173_codex_auth_boundaries.sql +107 -0
  36. package/drizzle/0174_session_wake_live_interruption.sql +80 -0
  37. package/package.json +4 -4
  38. package/src/codex-token-resolver.ts +102 -49
  39. package/src/connection-token-resolver.ts +67 -26
  40. package/src/database.ts +393 -0
  41. package/src/index.ts +747 -645
  42. package/src/insights.ts +2 -2
  43. package/src/memory-governance.ts +2 -2
  44. package/src/new-session-drafts.ts +1 -1
  45. package/src/preference-registry.ts +2 -2
  46. package/src/provision-roles.ts +1 -1
  47. package/src/runtime-posture.ts +3 -1
  48. package/src/schema.ts +70 -50
  49. package/src/scoped-knowledge.ts +2 -2
  50. package/src/session-control.ts +1 -1
  51. package/src/session-queue-commands.ts +1 -1
  52. package/src/session-realtime-context.ts +1 -1
  53. package/src/session-realtime-ledger.ts +1 -1
  54. package/src/session-realtime-mirror.ts +1 -1
  55. package/src/session-realtime-state.ts +1 -1
  56. package/src/session-realtime-terminal.ts +1 -1
  57. package/src/session-realtime.ts +1 -1
  58. package/src/session-tool-call-settlement.ts +1 -1
  59. package/src/turn-initiator.ts +1 -1
  60. package/src/workspace-artifacts.ts +2 -2
  61. package/src/workspace-instruction-policies.ts +2 -2
  62. package/dist/chunk-IHPCI4GV.js.map +0 -1
  63. package/dist/chunk-M6EOXYHK.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,11 +1,10 @@
1
1
  import type { AccessContext, AccessGrant, AccessPrincipalKind, ApiKey, BillingBalance, CapabilityCatalogItem, CapabilityInstallation, CapabilityKind, CapabilityPack, CapabilitySource, ConnectionKind, ConnectionMetadata, ConnectionStatus, DocumentAuthorityKind, McpServerConnectionRef, FileAsset, FileUploadStatus, FirstPartyMcpToolName, HumanInputQuestion, HumanInputResponse, KnowledgeMemory, KnowledgeMemoryKind, KnowledgeMemoryStatus, KnowledgeSourceRef, GitHubInstallationAuthorityKind, GitHubRepositoryScope, HostEventExportBatch, HostUsageExportBatch, ManagedAccount, McpPersonalConnectionDelegation, Permission, PackInstallation, PackInstallationStatus, ResourceRef, SandboxBackend, SandboxOs, ScheduledTask, ScheduledTaskAgentConfig, ScheduledTaskOverlapPolicy, ScheduledTaskRun, ScheduledTaskRunMode, ScheduledTaskRunStatus, ScheduledTaskScheduleSpec, ScheduledTaskStatus, ScheduledTaskTriggerType, Session, SessionAuthorizationListScope, SessionListResponse, SessionEvent, SessionEventPayloadMode, SessionEventReadDirection, SessionEventSemanticClass, SessionEventType, SessionGoal, SessionGoalCreatedBy, SessionGoalStatus, SessionHumanInputRequest, LineageNode, SessionMcpApprovalPolicy, SessionSkill, SessionMcpServerMetadata, SessionStatus, SessionToolPolicy, SessionTurn, SessionQueueSnapshot, SessionSystemUpdate, SessionSystemUpdateKind, SystemUpdateClassification, SessionTurnSource, SessionTurnStatus, TurnInitiator, TurnInitiatorContext, SocialConnection, SocialConnectionStatus, SocialPost, SocialProvider, ToolRef, ReasoningEffort, UsageEvent, Workspace, WorkspaceControlEvent, VariableSet, VariableSetVariableMetadata, WorkspaceMember, WorkspaceRegisteredPack, Rig, RigVersion, RigChange, RigChangeKind, RigChangeStatus, RigCheck, NativeSnapshotDescriptor, TarWorkspaceArchiveDescriptor, WorkspaceArchiveDescriptor, ModalCheckpointProviderBinding } from "@opengeni/contracts";
2
2
  import { type LatencyMode, SessionSystemUpdatePayload, TurnExecutionPolicyV1 } from "@opengeni/contracts";
3
3
  import { type Settings } from "@opengeni/config";
4
+ import { type CodexFetch } from "@opengeni/codex";
4
5
  export { isCodexBilledModel } from "@opengeni/codex";
5
6
  import { type SQL } from "drizzle-orm";
6
7
  export { frozenInitiatorForCommandActor, type FrozenTurnInitiator } from "./turn-initiator";
7
- import type { PgDatabase, PgTransactionConfig } from "drizzle-orm/pg-core";
8
- import postgres from "postgres";
9
8
  import { type SessionDiscoveryControl, type SessionCommandActor, type SessionTurnAttemptOutcome } from "./session-control";
10
9
  import { type SessionRealtimeContinuityEntry } from "./session-realtime-context";
11
10
  import * as schema from "./schema";
@@ -31,21 +30,16 @@ export { sanitizeMemoryText } from "./memory-domain";
31
30
  export { migrate, runMigrations } from "./migrate";
32
31
  export { provisionRoles, type ProvisionResult, type ProvisionRolesOptions, } from "./provision-roles";
33
32
  export * from "./memory-domain";
34
- export type Database = PgDatabase<any, typeof schema>;
33
+ import { type Database } from "./database";
34
+ export { createDb, registerDbBinding, rlsContextForWorkspace, rlsStrategyFor, setRlsContext, setSubjectRlsContext, withAccountRls, withDatabaseStatementTimeout, withRlsContext, withWorkspaceRls, withWorkspaceSubjectRls, withWorkspaceUsageLock, type CreateDbOptions, type Database, type DbClient, type RlsContext, type RlsStrategy, type UserLookup, } from "./database";
35
+ import { buildCodexTokenResolver as buildCodexTokenResolverCore, fetchCodexRateLimitResetCreditsForAccount as fetchCodexRateLimitResetCreditsForAccountCore, fetchCodexUsageForAccount as fetchCodexUsageForAccountCore, type CodexAccountUsageSnapshot, type CodexAuthDeps, type CodexCredentialForRun } from "./codex-token-resolver";
36
+ import { buildConnectionTokenResolver as buildConnectionTokenResolverCore, type ConnectionBrokerDeps, type ConnectionCredentialForBroker, type ConnectionTokenResolverOptions } from "./connection-token-resolver";
35
37
  /** Raised when a durable session tool-policy write lost its version fence. */
36
38
  export declare class SessionToolPolicyVersionConflictError extends Error {
37
39
  readonly currentVersion: number;
38
40
  readonly code = "SESSION_TOOL_POLICY_CONFLICT";
39
41
  constructor(currentVersion: number);
40
42
  }
41
- export type DbClient = {
42
- db: Database;
43
- close: () => Promise<void>;
44
- };
45
- export type RlsContext = {
46
- accountId: string;
47
- workspaceId?: string | null;
48
- };
49
43
  export type NestedAgentDepthPolicySource = "session" | "workspace" | "deployment" | "default";
50
44
  export type SessionDepthPolicy = {
51
45
  rootSessionId: string;
@@ -94,77 +88,6 @@ export declare class SessionSpawnDeniedDbError extends Error {
94
88
  readonly denial: SessionSpawnDenial;
95
89
  constructor(denial: SessionSpawnDenial);
96
90
  }
97
- /**
98
- * RLS posture for the connection OpenGeni's query layer runs over (Step I, §7.7).
99
- *
100
- * - `"force"` (DEFAULT — today's standalone behavior, byte-for-byte): OpenGeni
101
- * connects as a NON-OWNER role (`opengeni_app`) and every table carries
102
- * `FORCE ROW LEVEL SECURITY`, so the workspace/account GUCs set by
103
- * `setRlsContext` are the ONLY thing that admits rows — even the table owner
104
- * is subject to RLS. This is the Fork-A isolation guarantee.
105
- * - `"scoped"` (embedded Fork-B opt-in): the host runs OpenGeni's queries over a
106
- * role that OWNS the dedicated schema (RLS need not be forced for that role),
107
- * relying on the host's own tenant boundary. OpenGeni STILL emits the
108
- * `set_config('opengeni.account_id'/'workspace_id', …)` GUCs defensively on
109
- * every scoped query, so the application query path is byte-identical between
110
- * the two strategies and the app code is RLS-mode-agnostic. The strategy is a
111
- * declared posture (consumed by `provisionRoles` and as a documented
112
- * invariant), NOT a query-path branch — there is deliberately no `if
113
- * (strategy === …)` anywhere in the helpers below. Picking `"scoped"` does not
114
- * relax any GUC; it only changes which DB role the host provisions/connects as
115
- * and asserts that the host accepts owning the isolation boundary.
116
- */
117
- export type RlsStrategy = "force" | "scoped";
118
- /**
119
- * Resolve a host-IdP/Better-Auth user *identifier* by email. Injected via
120
- * `createDb({ userLookup })` (Step I). UNSET → today's raw parameterized select
121
- * against Better Auth's `auth_users` table (see `getManagedUserByEmail`), which
122
- * relies on the postgres-js array-shaped `db.execute` result. An embedded host
123
- * whose identity lives elsewhere (a different IdP table, a different driver, or
124
- * a non-`auth_users` user store) injects this closure so OpenGeni never touches
125
- * `auth_users` directly. Returns the user id, or null when no such user exists.
126
- */
127
- export type UserLookup = (db: Database, email: string) => Promise<string | null>;
128
- export type CreateDbOptions = {
129
- /**
130
- * The Postgres `search_path` for this connection (Step I, §7.8 runtime half).
131
- * UNSET → today's behavior: NO `search_path` startup parameter is sent, so the
132
- * server default applies (`public` for standalone, where every table + the
133
- * `vector` extension + `gen_random_uuid()` live). For an embedded dedicated
134
- * schema, pass e.g. `"opengeni,opengeni_private,public"` — postgres-js sends
135
- * it as a per-session startup parameter (the supported, query-param-free way;
136
- * URL `?search_path=` is IGNORED by postgres-js). Keep `public` LAST so the
137
- * `vector` type and `gen_random_uuid()` (which live in `public` on the
138
- * pgvector image) still resolve — the schema-isolation contract live footgun.
139
- */
140
- searchPath?: string;
141
- /** RLS posture; defaults to `"force"` (today's standalone). */
142
- rlsStrategy?: RlsStrategy;
143
- /** Host-provided user-by-email resolver; unset → today's raw `auth_users` query. */
144
- userLookup?: UserLookup;
145
- /** postgres-js pool size; defaults to today's `10`. */
146
- max?: number;
147
- /**
148
- * Connection-local default transaction isolation sent in the postgres-js
149
- * startup parameters. This is intentionally not a role/database default:
150
- * tests and embedded callers can exercise a different ambient isolation
151
- * without mutating a shared PostgreSQL role or affecting other connections.
152
- */
153
- isolationLevel?: postgres.ConnectionParameters["default_transaction_isolation"];
154
- };
155
- /** The strategy bound to a handle (or the `"force"` default). */
156
- export declare function rlsStrategyFor(db: Database): RlsStrategy;
157
- export declare function createDb(databaseUrl: string, options?: CreateDbOptions): DbClient;
158
- /**
159
- * Register a host's `rlsStrategy`/`userLookup` against an externally-constructed
160
- * `Database` handle (e.g. one the embedded host built from its own driver and
161
- * injected, rather than via `createDb`). Lets the same WeakMap-backed lookups
162
- * work for injected handles. Standalone never calls this (it uses `createDb`).
163
- */
164
- export declare function registerDbBinding(db: Database, binding: {
165
- rlsStrategy?: RlsStrategy;
166
- userLookup?: UserLookup;
167
- }): void;
168
91
  export type HostExportKind = "session_event" | "usage_event";
169
92
  /**
170
93
  * A leased row did not satisfy this consumer build's export contract. Only
@@ -274,27 +197,6 @@ export declare function getHostExportConsumerStatus(db: Database, input: {
274
197
  kind: HostExportKind;
275
198
  consumerId: string;
276
199
  }): Promise<HostExportConsumerStatus | null>;
277
- export declare function setRlsContext(db: Database, context: RlsContext): Promise<void>;
278
- export declare function withRlsContext<T>(db: Database, context: RlsContext, fn: (db: Database) => Promise<T>, transactionConfig?: PgTransactionConfig): Promise<T>;
279
- /**
280
- * Run one bounded database operation on a transaction-pinned backend.
281
- *
282
- * Callers that also have an application deadline should check their abort
283
- * signal before returning from `fn`; throwing there rolls the transaction back
284
- * even when the application deadline won a surrounding Promise race.
285
- */
286
- export declare function withDatabaseStatementTimeout<T>(db: Database, timeoutMs: number, fn: (db: Database) => Promise<T>): Promise<T>;
287
- export declare function rlsContextForWorkspace(db: Database, workspaceId: string): Promise<RlsContext>;
288
- export declare function withWorkspaceRls<T>(db: Database, workspaceId: string, fn: (db: Database) => Promise<T>): Promise<T>;
289
- /**
290
- * Personal workspace data needs both tenant and authenticated-principal GUCs.
291
- * `session_pins` uses this helper so FORCE RLS rejects another member's rows
292
- * even if a future query accidentally omits its explicit subject predicate.
293
- */
294
- export declare function withWorkspaceSubjectRls<T>(db: Database, workspaceId: string, subjectId: string, fn: (db: Database) => Promise<T>, transactionConfig?: PgTransactionConfig): Promise<T>;
295
- /** Apply and verify actor-private RLS on an already transaction-pinned handle. */
296
- export declare function setSubjectRlsContext(db: Database, subjectId: string): Promise<void>;
297
- export declare function withWorkspaceUsageLock<T>(db: Database, workspaceId: string, fn: (db: Database) => Promise<T>): Promise<T>;
298
200
  export type DocumentIndexAuthority = {
299
201
  authorityKind: DocumentAuthorityKind;
300
202
  authorityWorkspaceId: string | null;
@@ -313,7 +215,6 @@ export declare function resolveDocumentIndexAuthority(db: Database, input: {
313
215
  workspaceId: string;
314
216
  documentId: string;
315
217
  }): Promise<DocumentIndexAuthority | null>;
316
- export declare function withAccountRls<T>(db: Database, accountId: string, fn: (db: Database) => Promise<T>): Promise<T>;
317
218
  export declare const allWorkspacePermissions: Permission[];
318
219
  export declare const allAccountPermissions: Permission[];
319
220
  export type BootstrapWorkspaceInput = {
@@ -710,6 +611,7 @@ export type WorkspaceStateMemoryRecord = {
710
611
  export type CreateSocialConnectionInput = {
711
612
  accountId: string;
712
613
  workspaceId: string;
614
+ subjectId?: string | null;
713
615
  provider: SocialProvider;
714
616
  accountHandle: string;
715
617
  accountName?: string | null;
@@ -724,6 +626,7 @@ export type CreateSocialConnectionInput = {
724
626
  export type UpsertSocialOAuthConnectionInput = {
725
627
  accountId: string;
726
628
  workspaceId: string;
629
+ subjectId?: string | null;
727
630
  provider: SocialProvider;
728
631
  accountHandle: string;
729
632
  accountName?: string | null;
@@ -735,6 +638,7 @@ export type UpsertSocialOAuthConnectionInput = {
735
638
  export type UpdateSocialConnectionCredentialInput = {
736
639
  workspaceId: string;
737
640
  connectionId: string;
641
+ subjectId?: string | null;
738
642
  credentialEncrypted?: string | null;
739
643
  status?: SocialConnectionStatus;
740
644
  tokenMetadata?: Record<string, unknown>;
@@ -742,6 +646,7 @@ export type UpdateSocialConnectionCredentialInput = {
742
646
  export type CreateSocialPostInput = {
743
647
  accountId: string;
744
648
  workspaceId: string;
649
+ subjectId?: string | null;
745
650
  connectionId: string;
746
651
  externalPostId?: string | null;
747
652
  url?: string | null;
@@ -862,21 +767,6 @@ export type SlackBotDeleteOperation = {
862
767
  createdAt: Date;
863
768
  updatedAt: Date;
864
769
  };
865
- export type ConnectionCredentialForBroker = {
866
- id: string;
867
- accountId: string;
868
- workspaceId: string;
869
- subjectId: string | null;
870
- providerDomain: string;
871
- kind: ConnectionKind;
872
- status: ConnectionStatus;
873
- credential: Record<string, unknown>;
874
- grantedScopes: string[];
875
- expiresAt: Date | null;
876
- lastRefreshAt: Date | null;
877
- version: number;
878
- metadata: Record<string, unknown>;
879
- };
880
770
  export type IntegrationOAuthClientForUse = {
881
771
  id: string;
882
772
  issuer: string;
@@ -1681,14 +1571,14 @@ export declare function upsertSocialOAuthConnection(db: Database, input: UpsertS
1681
1571
  * of mapSocialConnection so the encrypted bundle never rides along on list or
1682
1572
  * MCP responses.
1683
1573
  */
1684
- export declare function loadSocialConnectionCredential(db: Database, workspaceId: string, connectionId: string): Promise<{
1574
+ export declare function loadSocialConnectionCredential(db: Database, workspaceId: string, connectionId: string, subjectId?: string | null): Promise<{
1685
1575
  connection: SocialConnection;
1686
1576
  credentialEncrypted: string | null;
1687
1577
  } | null>;
1688
1578
  export declare function updateSocialConnectionCredential(db: Database, input: UpdateSocialConnectionCredentialInput): Promise<SocialConnection | null>;
1689
- export declare function listSocialConnections(db: Database, workspaceId: string, limit?: number): Promise<SocialConnection[]>;
1690
- export declare function getSocialConnection(db: Database, workspaceId: string, connectionId: string): Promise<SocialConnection | null>;
1691
- export declare function requireSocialConnection(db: Database, workspaceId: string, connectionId: string): Promise<SocialConnection>;
1579
+ export declare function listSocialConnections(db: Database, workspaceId: string, limit?: number, subjectId?: string | null): Promise<SocialConnection[]>;
1580
+ export declare function getSocialConnection(db: Database, workspaceId: string, connectionId: string, subjectId?: string | null): Promise<SocialConnection | null>;
1581
+ export declare function requireSocialConnection(db: Database, workspaceId: string, connectionId: string, subjectId?: string | null): Promise<SocialConnection>;
1692
1582
  export declare function createSocialPost(db: Database, input: CreateSocialPostInput): Promise<SocialPost>;
1693
1583
  /**
1694
1584
  * Idempotent bulk ingest for provider sync: rows already present under the
@@ -1699,6 +1589,7 @@ export declare function recordSyncedSocialPosts(db: Database, input: {
1699
1589
  accountId: string;
1700
1590
  workspaceId: string;
1701
1591
  connectionId: string;
1592
+ subjectId?: string | null;
1702
1593
  posts: Array<{
1703
1594
  externalPostId: string;
1704
1595
  url?: string | null;
@@ -1714,6 +1605,7 @@ export declare function recordSyncedSocialPosts(db: Database, input: {
1714
1605
  }>;
1715
1606
  export declare function listSocialPosts(db: Database, options: {
1716
1607
  workspaceId: string;
1608
+ subjectId?: string | null;
1717
1609
  connectionIds?: string[];
1718
1610
  since?: Date;
1719
1611
  limit?: number;
@@ -1970,25 +1862,6 @@ export declare function loadVariableSetForRun(db: Database, settings: Settings,
1970
1862
  export declare const loadWorkspaceEnvironmentForRun: typeof loadVariableSetForRun;
1971
1863
  /** @deprecated use VariableSetForRun */
1972
1864
  export type WorkspaceEnvironmentForRun = VariableSetForRun;
1973
- export type CodexCredentialTokens = {
1974
- accessToken: string;
1975
- refreshToken: string;
1976
- idToken: string;
1977
- };
1978
- export type CodexCredentialForRun = {
1979
- id: string;
1980
- version: number;
1981
- workspaceId: string;
1982
- tokens: CodexCredentialTokens;
1983
- chatgptAccountId: string | null;
1984
- scopes: string | null;
1985
- planType: string | null;
1986
- isFedramp: boolean;
1987
- expiresAt: Date | null;
1988
- lastRefreshAt: Date | null;
1989
- status: string;
1990
- lastError: string | null;
1991
- };
1992
1865
  /**
1993
1866
  * Login / rotation write (multi-account P1). Caller passes the PRE-encrypted
1994
1867
  * credential blob. Keyed on the composite partial index (workspace, chatgpt
@@ -2022,6 +1895,61 @@ export declare function upsertCodexSubscriptionCredential(db: Database, input: {
2022
1895
  /** Direct managed-cookie human who most recently connected this row. */
2023
1896
  connectedBySubjectId?: string | null;
2024
1897
  }): Promise<UpsertCodexSubscriptionCredentialResult>;
1898
+ export type CodexAppsSettings = {
1899
+ credentialId: string | null;
1900
+ version: number;
1901
+ designatedAt: Date | null;
1902
+ };
1903
+ export declare function getCodexAppsSettings(db: Database, workspaceId: string): Promise<CodexAppsSettings>;
1904
+ export type CodexAppsCredentialAuthorization = {
1905
+ credentialId: string;
1906
+ ownerSubjectId: string;
1907
+ };
1908
+ export declare class CodexAppsAuthorizationRevokedError extends Error {
1909
+ constructor();
1910
+ }
1911
+ /** Exact Apps credential and owner, independent of every inference-capacity field. */
1912
+ export declare function getCodexAppsCredentialAuthorizationForRun(db: Database, workspaceId: string): Promise<CodexAppsCredentialAuthorization | null>;
1913
+ /**
1914
+ * Hold the exact designation, credential, and owner-membership authorization
1915
+ * stable through one outbound Apps request. Clear/disconnect operations share
1916
+ * the workspace advisory lock; credential or membership revocation must wait on
1917
+ * the row locks. The callback deliberately runs inside this short transaction so
1918
+ * no revocation can commit in the gap between a final check and network dispatch.
1919
+ */
1920
+ export declare function withCodexAppsRequestAuthorization<T>(db: Database, input: {
1921
+ workspaceId: string;
1922
+ credentialId: string;
1923
+ }, use: () => Promise<T>): Promise<T>;
1924
+ export type DesignateCodexAppsCredentialResult = ({
1925
+ kind: "updated";
1926
+ } & CodexAppsSettings) | ({
1927
+ kind: "conflict" | "already_designated";
1928
+ } & CodexAppsSettings) | {
1929
+ kind: "not_found";
1930
+ } | {
1931
+ kind: "not_owner";
1932
+ } | {
1933
+ kind: "forbidden";
1934
+ } | {
1935
+ kind: "unavailable";
1936
+ };
1937
+ export declare function designateCodexAppsCredential(db: Database, input: {
1938
+ accountId: string;
1939
+ workspaceId: string;
1940
+ credentialId: string;
1941
+ subjectId: string;
1942
+ expectedVersion: number;
1943
+ }): Promise<DesignateCodexAppsCredentialResult>;
1944
+ export type ClearCodexAppsCredentialResult = {
1945
+ kind: "updated" | "unchanged" | "conflict" | "forbidden";
1946
+ } & CodexAppsSettings;
1947
+ export declare function clearCodexAppsCredential(db: Database, input: {
1948
+ accountId: string;
1949
+ workspaceId: string;
1950
+ subjectId: string;
1951
+ expectedVersion: number;
1952
+ }): Promise<ClearCodexAppsCredentialResult>;
2025
1953
  /**
2026
1954
  * The ONLY decrypt-read accessor. Fails closed. Never call from an API route that
2027
1955
  * returns the result.
@@ -2166,8 +2094,6 @@ export type CodexAccountStatus = {
2166
2094
  secondaryResetAt: Date | null;
2167
2095
  usageCheckedAt: Date | null;
2168
2096
  exhaustedUntil: Date | null;
2169
- connectorNamespaces: string[] | null;
2170
- connectorsCheckedAt: Date | null;
2171
2097
  };
2172
2098
  /**
2173
2099
  * A metadata-only scheduling candidate observed while the workspace's rotation
@@ -2264,8 +2190,6 @@ export declare function acquireCodexCredentialLease<T, TPolicyScope = never, TUn
2264
2190
  holderId: string;
2265
2191
  /** Pins must not move the workspace-global cursor. */
2266
2192
  advanceActivePointer: boolean;
2267
- /** Exact frozen credential for this same durable turn, if it is resuming. */
2268
- continuationCredentialId?: string | null;
2269
2193
  /**
2270
2194
  * Optional downstream parser for private accepted-turn policy metadata.
2271
2195
  * It is pure, runs under the turn/rotation transaction, and must not query
@@ -2274,8 +2198,8 @@ export declare function acquireCodexCredentialLease<T, TPolicyScope = never, TUn
2274
2198
  resolvePolicyScope?: CodexCredentialLeasePolicyScopeResolver<TPolicyScope>;
2275
2199
  /**
2276
2200
  * Optional downstream membership policy for NEW allocations only. A live
2277
- * lease or validated frozen credential is offered to the selector against
2278
- * the complete workspace rows first and can never be filtered out here.
2201
+ * exact-turn lease is offered to the selector against the complete workspace
2202
+ * rows first and can never be filtered out here.
2279
2203
  */
2280
2204
  filterNewAllocationCandidates?: CodexCredentialLeaseCandidateFilter<TPolicyScope, TUnavailableDiagnostic>;
2281
2205
  leaseTtlMs?: number;
@@ -2664,16 +2588,6 @@ export declare function completeCodexResetRedemption(db: Database, input: {
2664
2588
  outcome: CodexResetRedemptionOutcome;
2665
2589
  }): Promise<CodexCapacityMutationResult<CodexResetRedemptionAttempt | null>>;
2666
2590
  /** The P2 usage-cache snapshot written by the refreshing usage wrapper. */
2667
- export type CodexAccountUsageSnapshot = {
2668
- primaryUsedPercent?: number | null;
2669
- primaryResetAt?: Date | null;
2670
- secondaryUsedPercent?: number | null;
2671
- secondaryResetAt?: Date | null;
2672
- /** Present only when the quota body parsed successfully. */
2673
- checkedAt?: Date;
2674
- resetCreditAvailableCount?: number | null;
2675
- resetCreditsCheckedAt?: Date | null;
2676
- };
2677
2591
  /**
2678
2592
  * Cache-write for P2 quota bars: persist the five plaintext usage columns on a
2679
2593
  * SPECIFIC credential row. NEVER touches credential_encrypted. RLS-scoped, guarded
@@ -2756,20 +2670,6 @@ export declare function setCodexCredentialExhaustedWithWakeTargets(db: Database,
2756
2670
  * the Temporal re-dispatch (each failover is a NEW turn, but its event survives).
2757
2671
  */
2758
2672
  export declare function countConsecutiveReactiveRotations(db: Database, workspaceId: string, sessionId: string): Promise<number>;
2759
- /**
2760
- * P4 connector-set cache writer: persist the set of ORIGINAL-dotted connector
2761
- * namespaces a SPECIFIC credential exposes via codex_apps (+ the freshness clock).
2762
- * Modeled byte-for-byte on recordCodexAccountUsage / setCodexCredentialExhausted:
2763
- * RLS-scoped, guarded by (id, workspace_id), and — critically — NO `version` bump and
2764
- * NO `updatedAt` touch, so it can never race the (id, version) token-refresh CAS.
2765
- *
2766
- * The CALLER must only invoke this with a NON-EMPTY set: codex_apps connects
2767
- * best-effort (a transient failure yields an empty tools/list), and overwriting a
2768
- * known non-empty set with [] would falsely "drop" coverage on a flaky turn. A
2769
- * genuinely connector-less account stays null (the ranker treats null as unknown).
2770
- * Returns true iff a row was updated (false ⇒ the credential was disconnected under us).
2771
- */
2772
- export declare function recordCodexAccountConnectors(db: Database, workspaceId: string, credentialId: string, namespaces: string[]): Promise<boolean>;
2773
2673
  /** The supported rotation strategies (P3). */
2774
2674
  export declare const CODEX_ROTATION_STRATEGIES: readonly ["most_remaining", "round_robin", "drain_then_next", "sharded"];
2775
2675
  export type CodexRotationStrategy = (typeof CODEX_ROTATION_STRATEGIES)[number];
@@ -2815,13 +2715,13 @@ export declare function recordSessionActiveCodexCredential(db: Database, workspa
2815
2715
  * re-picks the most-recently-connected remaining account as active, atomically in
2816
2716
  * the same RLS txn. Returns whether a row was removed + the new active id.
2817
2717
  */
2818
- export declare function disconnectCodexAccount(db: Database, workspaceId: string, credentialId: string): Promise<{
2718
+ export declare function disconnectCodexAccount(db: Database, workspaceId: string, credentialId: string, actorSubjectId?: string | null): Promise<{
2819
2719
  removed: boolean;
2820
2720
  newActiveCredentialId: string | null;
2821
2721
  blockedByUnresolvedRedemption: boolean;
2822
2722
  }>;
2823
2723
  /** Legacy "disconnect all"; atomically rejects when any provider work is unresolved. */
2824
- export declare function disconnectAllCodexAccounts(db: Database, workspaceId: string): Promise<{
2724
+ export declare function disconnectAllCodexAccounts(db: Database, workspaceId: string, actorSubjectId?: string | null): Promise<{
2825
2725
  removed: number;
2826
2726
  blockedCredentialIds: string[];
2827
2727
  }>;
@@ -3361,7 +3261,6 @@ export declare function getLatestRunState(db: Database, workspaceId: string, ses
3361
3261
  turnId: string | null;
3362
3262
  serializedRunState: string;
3363
3263
  pendingApprovals: unknown[];
3364
- frozenCodexCredentialId: string | null;
3365
3264
  providerArtifactInvalidatedAt: Date | null;
3366
3265
  } | null>;
3367
3266
  export declare class HumanInputResponseValidationError extends Error {
@@ -3453,7 +3352,6 @@ export declare function appendSessionHistoryItems(db: Database, input: {
3453
3352
  turnId: string;
3454
3353
  expectedExecutionGeneration: number;
3455
3354
  expectedAttemptId: string;
3456
- producerCodexCredentialId?: string | null;
3457
3355
  modelToolOutputTruncationTokens?: number;
3458
3356
  items: Array<{
3459
3357
  position: number;
@@ -3524,9 +3422,9 @@ export declare function getSessionHistoryItems(db: Database, workspaceId: string
3524
3422
  * the table as an audit trail.
3525
3423
  */
3526
3424
  export declare function getActiveSessionHistoryItems(db: Database, workspaceId: string, sessionId: string): Promise<Array<{
3425
+ id: string;
3527
3426
  position: number;
3528
3427
  item: Record<string, unknown>;
3529
- producerCodexCredentialId: string | null;
3530
3428
  providerArtifactInvalidatedAt: Date | null;
3531
3429
  }>>;
3532
3430
  /** Bounded finalized voice turns used only to resume a later realtime call. */
@@ -3598,8 +3496,6 @@ export declare function applyContextCompaction(db: Database, input: {
3598
3496
  replacementInputTokens: number;
3599
3497
  clearRequestedCompaction?: boolean;
3600
3498
  eventPayload?: Record<string, unknown>;
3601
- /** Tag inserted history rows with the Codex credential that produced them. */
3602
- producerCodexCredentialId?: string | null;
3603
3499
  }): Promise<ApplyContextCompactionResult>;
3604
3500
  /**
3605
3501
  * Attempt-fenced visible start of a compaction provider call. Emitted before
@@ -5798,7 +5694,6 @@ export declare function saveRunState(db: Database, input: {
5798
5694
  expectedAttemptId: string;
5799
5695
  serializedRunState: string;
5800
5696
  pendingApprovals: unknown[];
5801
- frozenCodexCredentialId?: string | null;
5802
5697
  }): Promise<boolean>;
5803
5698
  export type CreateSessionGoalInput = {
5804
5699
  accountId: string;
@@ -6254,7 +6149,6 @@ export type ApplySessionTurnSettlementInput = {
6254
6149
  runState?: {
6255
6150
  serializedRunState: string;
6256
6151
  pendingApprovals: unknown[];
6257
- frozenCodexCredentialId?: string | null;
6258
6152
  humanInputRequests?: Array<{
6259
6153
  id: string;
6260
6154
  toolCallId: string;
@@ -6378,7 +6272,8 @@ export type RequestSessionTurnRecoveryInput = {
6378
6272
  providerRecoveryCount?: number;
6379
6273
  fromStatuses?: SessionTurnStatus[];
6380
6274
  providerArtifactInvalidation?: {
6381
- codexCredentialId: string;
6275
+ historyItemIds: string[];
6276
+ runStateId?: string;
6382
6277
  reason: "encrypted_content_rejected";
6383
6278
  };
6384
6279
  };
@@ -6666,6 +6561,10 @@ export declare function appendSessionEventsWithLockedSessionUpdate(db: Database,
6666
6561
  lockParentSession?: boolean;
6667
6562
  }): Promise<SessionEvent[]>;
6668
6563
  export declare function sessionSubject(workspaceId: string, sessionId: string): string;
6669
- export * from "./codex-token-resolver";
6670
- export * from "./connection-token-resolver";
6564
+ export declare function buildCodexTokenResolver(db: Database, settings: Settings, workspaceId: string, credentialId: string, deps?: CodexAuthDeps): ReturnType<typeof buildCodexTokenResolverCore>;
6565
+ export declare function fetchCodexUsageForAccount(db: Database, settings: Settings, workspaceId: string, credentialId: string, fetchImpl?: CodexFetch): ReturnType<typeof fetchCodexUsageForAccountCore>;
6566
+ export declare function fetchCodexRateLimitResetCreditsForAccount(db: Database, settings: Settings, workspaceId: string, credentialId: string, fetchImpl?: CodexFetch): ReturnType<typeof fetchCodexRateLimitResetCreditsForAccountCore>;
6567
+ export declare function buildConnectionTokenResolver(db: Database, settings: Settings, deps?: ConnectionBrokerDeps, options?: ConnectionTokenResolverOptions): ReturnType<typeof buildConnectionTokenResolverCore>;
6568
+ export { withCodexTokenDeadline, type CodexAccountUsageSnapshot, type CodexAuthDeps, type CodexCredentialForRun, type CodexCredentialTokens, type CodexRateLimitResetCreditsAccountResult, type CodexTokenDeadlineClock, type CodexTokenDeadlineOptions, } from "./codex-token-resolver";
6569
+ export { buildHostConnectionTokenResolver, ConnectionRefreshHttpError, HostMcpCredentialBindingError, HostMcpCredentialScopeError, isPrivateAddress, normalizeBearerScheme, refreshOAuthConnectionCredential, type ConnectionBrokerDeps, type ConnectionCredentialForBroker, type ConnectionCredentialLookupInput, type ConnectionStatusGuard, type ConnectionTokenRefreshInput, type ConnectionTokenResolverOptions, type HostMcpCredentialResolverContext, type PermanentConnectionRefreshFailure, type RefreshTransportOptions, type ResolveConnectionCredentialInput, type ResolveConnectionCredentialResult, } from "./connection-token-resolver";
6671
6570
  export * from "./workspace-artifacts";