@opengeni/db 0.27.9 → 0.28.1

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.
package/dist/index.d.ts CHANGED
@@ -1895,6 +1895,61 @@ export declare function upsertCodexSubscriptionCredential(db: Database, input: {
1895
1895
  /** Direct managed-cookie human who most recently connected this row. */
1896
1896
  connectedBySubjectId?: string | null;
1897
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>;
1898
1953
  /**
1899
1954
  * The ONLY decrypt-read accessor. Fails closed. Never call from an API route that
1900
1955
  * returns the result.
@@ -2039,8 +2094,6 @@ export type CodexAccountStatus = {
2039
2094
  secondaryResetAt: Date | null;
2040
2095
  usageCheckedAt: Date | null;
2041
2096
  exhaustedUntil: Date | null;
2042
- connectorNamespaces: string[] | null;
2043
- connectorsCheckedAt: Date | null;
2044
2097
  };
2045
2098
  /**
2046
2099
  * A metadata-only scheduling candidate observed while the workspace's rotation
@@ -2137,8 +2190,6 @@ export declare function acquireCodexCredentialLease<T, TPolicyScope = never, TUn
2137
2190
  holderId: string;
2138
2191
  /** Pins must not move the workspace-global cursor. */
2139
2192
  advanceActivePointer: boolean;
2140
- /** Exact frozen credential for this same durable turn, if it is resuming. */
2141
- continuationCredentialId?: string | null;
2142
2193
  /**
2143
2194
  * Optional downstream parser for private accepted-turn policy metadata.
2144
2195
  * It is pure, runs under the turn/rotation transaction, and must not query
@@ -2147,8 +2198,8 @@ export declare function acquireCodexCredentialLease<T, TPolicyScope = never, TUn
2147
2198
  resolvePolicyScope?: CodexCredentialLeasePolicyScopeResolver<TPolicyScope>;
2148
2199
  /**
2149
2200
  * Optional downstream membership policy for NEW allocations only. A live
2150
- * lease or validated frozen credential is offered to the selector against
2151
- * 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.
2152
2203
  */
2153
2204
  filterNewAllocationCandidates?: CodexCredentialLeaseCandidateFilter<TPolicyScope, TUnavailableDiagnostic>;
2154
2205
  leaseTtlMs?: number;
@@ -2619,20 +2670,6 @@ export declare function setCodexCredentialExhaustedWithWakeTargets(db: Database,
2619
2670
  * the Temporal re-dispatch (each failover is a NEW turn, but its event survives).
2620
2671
  */
2621
2672
  export declare function countConsecutiveReactiveRotations(db: Database, workspaceId: string, sessionId: string): Promise<number>;
2622
- /**
2623
- * P4 connector-set cache writer: persist the set of ORIGINAL-dotted connector
2624
- * namespaces a SPECIFIC credential exposes via codex_apps (+ the freshness clock).
2625
- * Modeled byte-for-byte on recordCodexAccountUsage / setCodexCredentialExhausted:
2626
- * RLS-scoped, guarded by (id, workspace_id), and — critically — NO `version` bump and
2627
- * NO `updatedAt` touch, so it can never race the (id, version) token-refresh CAS.
2628
- *
2629
- * The CALLER must only invoke this with a NON-EMPTY set: codex_apps connects
2630
- * best-effort (a transient failure yields an empty tools/list), and overwriting a
2631
- * known non-empty set with [] would falsely "drop" coverage on a flaky turn. A
2632
- * genuinely connector-less account stays null (the ranker treats null as unknown).
2633
- * Returns true iff a row was updated (false ⇒ the credential was disconnected under us).
2634
- */
2635
- export declare function recordCodexAccountConnectors(db: Database, workspaceId: string, credentialId: string, namespaces: string[]): Promise<boolean>;
2636
2673
  /** The supported rotation strategies (P3). */
2637
2674
  export declare const CODEX_ROTATION_STRATEGIES: readonly ["most_remaining", "round_robin", "drain_then_next", "sharded"];
2638
2675
  export type CodexRotationStrategy = (typeof CODEX_ROTATION_STRATEGIES)[number];
@@ -2678,13 +2715,13 @@ export declare function recordSessionActiveCodexCredential(db: Database, workspa
2678
2715
  * re-picks the most-recently-connected remaining account as active, atomically in
2679
2716
  * the same RLS txn. Returns whether a row was removed + the new active id.
2680
2717
  */
2681
- 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<{
2682
2719
  removed: boolean;
2683
2720
  newActiveCredentialId: string | null;
2684
2721
  blockedByUnresolvedRedemption: boolean;
2685
2722
  }>;
2686
2723
  /** Legacy "disconnect all"; atomically rejects when any provider work is unresolved. */
2687
- export declare function disconnectAllCodexAccounts(db: Database, workspaceId: string): Promise<{
2724
+ export declare function disconnectAllCodexAccounts(db: Database, workspaceId: string, actorSubjectId?: string | null): Promise<{
2688
2725
  removed: number;
2689
2726
  blockedCredentialIds: string[];
2690
2727
  }>;
@@ -3224,7 +3261,6 @@ export declare function getLatestRunState(db: Database, workspaceId: string, ses
3224
3261
  turnId: string | null;
3225
3262
  serializedRunState: string;
3226
3263
  pendingApprovals: unknown[];
3227
- frozenCodexCredentialId: string | null;
3228
3264
  providerArtifactInvalidatedAt: Date | null;
3229
3265
  } | null>;
3230
3266
  export declare class HumanInputResponseValidationError extends Error {
@@ -3316,7 +3352,6 @@ export declare function appendSessionHistoryItems(db: Database, input: {
3316
3352
  turnId: string;
3317
3353
  expectedExecutionGeneration: number;
3318
3354
  expectedAttemptId: string;
3319
- producerCodexCredentialId?: string | null;
3320
3355
  modelToolOutputTruncationTokens?: number;
3321
3356
  items: Array<{
3322
3357
  position: number;
@@ -3387,9 +3422,9 @@ export declare function getSessionHistoryItems(db: Database, workspaceId: string
3387
3422
  * the table as an audit trail.
3388
3423
  */
3389
3424
  export declare function getActiveSessionHistoryItems(db: Database, workspaceId: string, sessionId: string): Promise<Array<{
3425
+ id: string;
3390
3426
  position: number;
3391
3427
  item: Record<string, unknown>;
3392
- producerCodexCredentialId: string | null;
3393
3428
  providerArtifactInvalidatedAt: Date | null;
3394
3429
  }>>;
3395
3430
  /** Bounded finalized voice turns used only to resume a later realtime call. */
@@ -3458,11 +3493,8 @@ export declare function applyContextCompaction(db: Database, input: {
3458
3493
  expectedAttemptId: string;
3459
3494
  replacementItems: Array<Record<string, unknown>>;
3460
3495
  summaryItem: Record<string, unknown>;
3461
- replacementInputTokens: number;
3462
3496
  clearRequestedCompaction?: boolean;
3463
3497
  eventPayload?: Record<string, unknown>;
3464
- /** Tag inserted history rows with the Codex credential that produced them. */
3465
- producerCodexCredentialId?: string | null;
3466
3498
  }): Promise<ApplyContextCompactionResult>;
3467
3499
  /**
3468
3500
  * Attempt-fenced visible start of a compaction provider call. Emitted before
@@ -3525,8 +3557,9 @@ export declare function recordSkippedContextCompaction(db: Database, input: {
3525
3557
  */
3526
3558
  export declare function nextSessionHistoryPosition(db: Database, workspaceId: string, sessionId: string): Promise<number>;
3527
3559
  /**
3528
- * Record the actual input-token count of the most recent turn's final model
3529
- * call, for the next turn's pre-read compaction trigger.
3560
+ * Replace the input-token count for the most recent authoritative terminal
3561
+ * response. Null means that response supplied no usable final-call count, so
3562
+ * the next turn must not reuse an older response's value for compaction.
3530
3563
  */
3531
3564
  export declare function setSessionLastInputTokensForTurnAttempt(db: Database, input: {
3532
3565
  workspaceId: string;
@@ -3534,7 +3567,7 @@ export declare function setSessionLastInputTokensForTurnAttempt(db: Database, in
3534
3567
  turnId: string;
3535
3568
  expectedExecutionGeneration: number;
3536
3569
  expectedAttemptId: string;
3537
- lastInputTokens: number;
3570
+ lastInputTokens: number | null;
3538
3571
  }): Promise<boolean>;
3539
3572
  /** The neutral boundary left as the sole active history row after a clear. */
3540
3573
  export declare function clearedContextMarkerItem(): Record<string, unknown>;
@@ -3560,8 +3593,8 @@ export declare class SessionContextBusyError extends Error {
3560
3593
  * reserved for an approval that paused mid-turn, and the API forbids a
3561
3594
  * clear while such an approval or active turn exists.
3562
3595
  *
3563
- * Also resets last_input_tokens to 0 so the next turn's compaction trigger
3564
- * starts fresh against the now-short context.
3596
+ * Also clears last_input_tokens because no provider has observed the new
3597
+ * context yet.
3565
3598
  *
3566
3599
  * Idempotent: a re-run supersedes the (now sole, already-marker) active row,
3567
3600
  * inserts another marker at the next position. The post-condition (one active
@@ -5661,7 +5694,6 @@ export declare function saveRunState(db: Database, input: {
5661
5694
  expectedAttemptId: string;
5662
5695
  serializedRunState: string;
5663
5696
  pendingApprovals: unknown[];
5664
- frozenCodexCredentialId?: string | null;
5665
5697
  }): Promise<boolean>;
5666
5698
  export type CreateSessionGoalInput = {
5667
5699
  accountId: string;
@@ -6117,7 +6149,6 @@ export type ApplySessionTurnSettlementInput = {
6117
6149
  runState?: {
6118
6150
  serializedRunState: string;
6119
6151
  pendingApprovals: unknown[];
6120
- frozenCodexCredentialId?: string | null;
6121
6152
  humanInputRequests?: Array<{
6122
6153
  id: string;
6123
6154
  toolCallId: string;
@@ -6241,7 +6272,8 @@ export type RequestSessionTurnRecoveryInput = {
6241
6272
  providerRecoveryCount?: number;
6242
6273
  fromStatuses?: SessionTurnStatus[];
6243
6274
  providerArtifactInvalidation?: {
6244
- codexCredentialId: string;
6275
+ historyItemIds: string[];
6276
+ runStateId?: string;
6245
6277
  reason: "encrypted_content_rejected";
6246
6278
  };
6247
6279
  };
@@ -6536,3 +6568,4 @@ export declare function buildConnectionTokenResolver(db: Database, settings: Set
6536
6568
  export { withCodexTokenDeadline, type CodexAccountUsageSnapshot, type CodexAuthDeps, type CodexCredentialForRun, type CodexCredentialTokens, type CodexRateLimitResetCreditsAccountResult, type CodexTokenDeadlineClock, type CodexTokenDeadlineOptions, } from "./codex-token-resolver";
6537
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";
6538
6570
  export * from "./workspace-artifacts";
6571
+ export * from "./transcription-recordings";