@opengeni/db 1.1.0 → 1.2.0

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 (77) hide show
  1. package/dist/canonical-human-identities.js +3 -3
  2. package/dist/capability-reconciliation.js +2 -2
  3. package/dist/{chunk-J4WFOVBV.js → chunk-3GAR5UN3.js} +2 -2
  4. package/dist/{chunk-Z5HJXH3X.js → chunk-3TGYFFZR.js} +2 -2
  5. package/dist/{chunk-GLA5YCQS.js → chunk-6EIEGHPK.js} +4 -4
  6. package/dist/{chunk-BLUQG54M.js → chunk-CONWNUSL.js} +2 -2
  7. package/dist/{chunk-EKXCF3FH.js → chunk-CYP72JTQ.js} +11 -4
  8. package/dist/{chunk-EKXCF3FH.js.map → chunk-CYP72JTQ.js.map} +1 -1
  9. package/dist/{chunk-VOB6TXSJ.js → chunk-FWQNHNOU.js} +39 -2
  10. package/dist/chunk-FWQNHNOU.js.map +1 -0
  11. package/dist/{chunk-7Z7ALFRE.js → chunk-GDN5TSZP.js} +2 -2
  12. package/dist/{chunk-M3SWH4MU.js → chunk-JICUP7ZR.js} +2 -2
  13. package/dist/{chunk-KJVOBLFC.js → chunk-JLVWBIEM.js} +3 -3
  14. package/dist/{chunk-BZV5ZDRY.js → chunk-LXPFNG4L.js} +2 -2
  15. package/dist/{chunk-SKYRM7R7.js → chunk-O2Y5E5M3.js} +68 -32
  16. package/dist/chunk-O2Y5E5M3.js.map +1 -0
  17. package/dist/{chunk-M2YGXCCQ.js → chunk-QFJNEXFL.js} +2 -2
  18. package/dist/{chunk-CIGHXFPD.js → chunk-UCIMHNII.js} +101 -21
  19. package/dist/chunk-UCIMHNII.js.map +1 -0
  20. package/dist/{chunk-ODKYBA3C.js → chunk-VDPCIFKL.js} +5 -5
  21. package/dist/{chunk-T5NHDEZW.js → chunk-YOYILDLY.js} +26 -1
  22. package/dist/chunk-YOYILDLY.js.map +1 -0
  23. package/dist/connect-attempts.js +3 -3
  24. package/dist/credit-balances.d.ts +18 -0
  25. package/dist/credit-promotion-policy.d.ts +10 -0
  26. package/dist/editable-artifact-durable-export.js +2 -2
  27. package/dist/editable-artifacts.js +3 -3
  28. package/dist/index.d.ts +21 -5
  29. package/dist/index.js +2369 -2247
  30. package/dist/index.js.map +1 -1
  31. package/dist/managed-auth-session-sets.js +3 -3
  32. package/dist/managed-user-setup.d.ts +1 -0
  33. package/dist/mcp-operations.js +2 -2
  34. package/dist/organization-integration-policy.js +3 -3
  35. package/dist/organization-membership-lifecycle.d.ts +1 -0
  36. package/dist/persistence-errors.d.ts +9 -6
  37. package/dist/provision-roles.js +1 -1
  38. package/dist/retained-provider-commands.js +6 -6
  39. package/dist/runtime-posture.d.ts +4 -4
  40. package/dist/schema.d.ts +121 -2
  41. package/dist/schema.js +3 -1
  42. package/dist/session-background-commands.js +4 -4
  43. package/dist/session-command-output.js +5 -5
  44. package/dist/session-event-slices.js +3 -3
  45. package/dist/session-mcp-credential-rotation.js +5 -5
  46. package/dist/session-tenancy.js +3 -3
  47. package/dist/video-generation.js +3 -3
  48. package/dist/workspace-tool-defaults.js +4 -4
  49. package/drizzle/0613_model_scoped_promotional_credits.sql +238 -0
  50. package/drizzle/0614_quiescence_command_containment.sql +7 -0
  51. package/drizzle/0615_credit_promotion_policy_validation.sql +63 -0
  52. package/package.json +7 -7
  53. package/src/credit-balances.ts +109 -0
  54. package/src/credit-promotion-policy.ts +12 -0
  55. package/src/database.ts +81 -42
  56. package/src/index.ts +201 -60
  57. package/src/managed-user-setup.ts +8 -0
  58. package/src/organization-membership-lifecycle.ts +8 -0
  59. package/src/persistence-errors.ts +17 -6
  60. package/src/provision-roles.ts +9 -0
  61. package/src/runtime-posture.ts +22 -0
  62. package/src/schema.ts +40 -1
  63. package/src/video-generation.ts +2 -7
  64. package/dist/chunk-CIGHXFPD.js.map +0 -1
  65. package/dist/chunk-SKYRM7R7.js.map +0 -1
  66. package/dist/chunk-T5NHDEZW.js.map +0 -1
  67. package/dist/chunk-VOB6TXSJ.js.map +0 -1
  68. /package/dist/{chunk-J4WFOVBV.js.map → chunk-3GAR5UN3.js.map} +0 -0
  69. /package/dist/{chunk-Z5HJXH3X.js.map → chunk-3TGYFFZR.js.map} +0 -0
  70. /package/dist/{chunk-GLA5YCQS.js.map → chunk-6EIEGHPK.js.map} +0 -0
  71. /package/dist/{chunk-BLUQG54M.js.map → chunk-CONWNUSL.js.map} +0 -0
  72. /package/dist/{chunk-7Z7ALFRE.js.map → chunk-GDN5TSZP.js.map} +0 -0
  73. /package/dist/{chunk-M3SWH4MU.js.map → chunk-JICUP7ZR.js.map} +0 -0
  74. /package/dist/{chunk-KJVOBLFC.js.map → chunk-JLVWBIEM.js.map} +0 -0
  75. /package/dist/{chunk-BZV5ZDRY.js.map → chunk-LXPFNG4L.js.map} +0 -0
  76. /package/dist/{chunk-M2YGXCCQ.js.map → chunk-QFJNEXFL.js.map} +0 -0
  77. /package/dist/{chunk-ODKYBA3C.js.map → chunk-VDPCIFKL.js.map} +0 -0
@@ -7,9 +7,9 @@ import {
7
7
  getConnectAttempt,
8
8
  getConnectBeginReplay,
9
9
  listPendingConnectAttempts
10
- } from "./chunk-BLUQG54M.js";
11
- import "./chunk-SKYRM7R7.js";
12
- import "./chunk-VOB6TXSJ.js";
10
+ } from "./chunk-CONWNUSL.js";
11
+ import "./chunk-O2Y5E5M3.js";
12
+ import "./chunk-FWQNHNOU.js";
13
13
  import "./chunk-P7YDM2RI.js";
14
14
  import "./chunk-PZ5AY32C.js";
15
15
  export {
@@ -0,0 +1,18 @@
1
+ import type { BillingBalance } from "@opengeni/contracts";
2
+ import type { Database } from "./database.js";
3
+ /** Read totals and grant remainders from one database snapshot. */
4
+ type CreditBalanceSnapshot = BillingBalance & {
5
+ creditPolicyRevision?: number;
6
+ };
7
+ export declare function getBillingBalance(db: Database, accountId: string, policyRevision?: number): Promise<CreditBalanceSnapshot>;
8
+ /** Missing model means a non-model resource, which can only use general credits. */
9
+ export declare function spendableCreditMicros(balance: BillingBalance, modelId?: string): number;
10
+ export declare function getSpendableCreditBalance(db: Database, accountId: string, modelId?: string, policyRevision?: number): Promise<CreditBalanceSnapshot>;
11
+ export declare function planCreditDebit(balance: BillingBalance, requestedMicros: number, modelId?: string): {
12
+ debitedMicros: number;
13
+ allocations: {
14
+ grantEntryId: string;
15
+ amountMicros: number;
16
+ }[];
17
+ };
18
+ export {};
@@ -0,0 +1,10 @@
1
+ import { type Database } from "./database.js";
2
+ /** Runtime policy supersedes deployment bootstrap configuration. No process cache. */
3
+ export declare function readCreditPromotionPolicy(db: Database): Promise<{
4
+ defaultModelIds?: string[] | undefined;
5
+ signupModelIds?: string[] | undefined;
6
+ offers: Record<string, {
7
+ label: string;
8
+ eligibleModelIds?: string[] | undefined;
9
+ }>;
10
+ } | null>;
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  rawRows,
3
3
  withRlsContext
4
- } from "./chunk-SKYRM7R7.js";
5
- import "./chunk-VOB6TXSJ.js";
4
+ } from "./chunk-O2Y5E5M3.js";
5
+ import "./chunk-FWQNHNOU.js";
6
6
  import "./chunk-P7YDM2RI.js";
7
7
  import "./chunk-PZ5AY32C.js";
8
8
 
@@ -10,9 +10,9 @@ import {
10
10
  listEditableArtifactIdsForSession,
11
11
  touchEditableArtifactSessionLink,
12
12
  transactionallyAuthorizeEditableArtifactActor
13
- } from "./chunk-BZV5ZDRY.js";
14
- import "./chunk-SKYRM7R7.js";
15
- import "./chunk-VOB6TXSJ.js";
13
+ } from "./chunk-LXPFNG4L.js";
14
+ import "./chunk-O2Y5E5M3.js";
15
+ import "./chunk-FWQNHNOU.js";
16
16
  import "./chunk-P7YDM2RI.js";
17
17
  import "./chunk-PZ5AY32C.js";
18
18
  export {
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export { readCreditPromotionPolicy } from "./credit-promotion-policy.js";
2
+ export { getBillingBalance, getSpendableCreditBalance, spendableCreditMicros, } from "./credit-balances.js";
1
3
  export { SubscriptionAccountChangedError } from "./subscription-account-conflict.js";
2
4
  import type { GoalAdmissionPausedReason } from "@opengeni/contracts";
3
5
  export declare const getScheduledTaskClaudeProviderAccountAuthoritySnapshot: (db: Database, workspaceId: string, taskId: string) => Promise<{
@@ -96,6 +98,7 @@ import { type SQL } from "drizzle-orm";
96
98
  export { frozenInitiatorForCommandActor, type FrozenTurnInitiator } from "./turn-initiator.js";
97
99
  export { LOSSLESS_TEXT_PREFIX } from "./lossless-json.js";
98
100
  import { type NewSessionDraftSnapshot } from "./new-session-drafts.js";
101
+ export { DatabaseTransactionError } from "./persistence-errors.js";
99
102
  import { type SessionDiscoveryControl, type SessionCommandActor, type SessionTurnAttemptOutcome } from "./session-control.js";
100
103
  import { type ConnectedMachineBackgroundCommandClaim } from "./session-background-commands.js";
101
104
  import { type SessionRealtimeContinuityEntry } from "./session-realtime-context.js";
@@ -1046,6 +1049,7 @@ export declare function applyCreditLedgerEntry(db: Database, input: {
1046
1049
  workspaceId?: string | null;
1047
1050
  type: string;
1048
1051
  amountMicros: number;
1052
+ eligibleModelIds?: string[] | undefined;
1049
1053
  sourceType?: string | null;
1050
1054
  sourceId?: string | null;
1051
1055
  idempotencyKey: string;
@@ -1057,6 +1061,9 @@ export declare function applyCreditDebitUpToBalance(db: Database, input: {
1057
1061
  workspaceId?: string | null;
1058
1062
  type: string;
1059
1063
  requestedAmountMicros: number;
1064
+ /** Canonical, accepted model ID. Omitted for non-model usage. */
1065
+ modelId?: string;
1066
+ creditPolicyRevision?: number | undefined;
1060
1067
  sourceType?: string | null;
1061
1068
  sourceId?: string | null;
1062
1069
  idempotencyKey: string;
@@ -1112,7 +1119,6 @@ export declare function recordStripeWebhookEvent(db: Database, input: {
1112
1119
  }): Promise<boolean>;
1113
1120
  export declare function isStripeWebhookProcessed(db: Database, id: string): Promise<boolean>;
1114
1121
  export declare function markStripeWebhookProcessed(db: Database, id: string): Promise<void>;
1115
- export declare function getBillingBalance(db: Database, accountId: string): Promise<BillingBalance>;
1116
1122
  /**
1117
1123
  * Whether the organization holds a positive OpenGeni credit balance, whatever
1118
1124
  * its source: a purchase, an operator grant, a test credit, or the one-time
@@ -8296,16 +8302,24 @@ export declare function reapStaleLeaseHolders(db: Database, input: {
8296
8302
  drained: ReapDrainable[];
8297
8303
  }>;
8298
8304
  /** Settlement reasons for legacy retained commands that containment stopped
8299
- * after a verified checkpoint. Neither is exit proof: the command settles
8305
+ * after a verified checkpoint. None is exit proof: the command settles
8300
8306
  * `lost` with no exit code. */
8301
8307
  export declare const IDLE_COMMAND_CONTAINMENT_REASON = "idle_containment";
8302
8308
  export declare const DEADLINE_COMMAND_CONTAINMENT_REASON = "provider_deadline_containment";
8309
+ export declare const QUIESCENCE_COMMAND_CONTAINMENT_REASON = "quiescence_containment";
8310
+ type SettledCommandOwner = {
8311
+ sessionId: string;
8312
+ attemptId: string;
8313
+ temporalWorkflowId: string;
8314
+ temporalWorkflowRunId: string;
8315
+ temporalActivityId: string;
8316
+ };
8303
8317
  /** Bounded per-candidate containment inspection outcomes (metric labels). */
8304
- export type CommandContainmentInspection = "idle_enrolled" | "deadline_enrolled" | "resumed_enrolled" | "not_eligible" | "inspection_failed";
8318
+ export type CommandContainmentInspection = "idle_enrolled" | "deadline_enrolled" | "quiescence_enrolled" | "resumed_enrolled" | "not_eligible" | "inspection_failed";
8305
8319
  export type CommandContainmentEnrollment = ReapDrainable & {
8306
- /** `idle`/`deadline` newly enrolled this call; `resumed` continues an
8320
+ /** `idle`/`deadline`/`quiescence` newly enrolled this call; `resumed` continues an
8307
8321
  * existing enrollment whose drain has not committed yet. */
8308
- mode: "idle" | "deadline" | "resumed";
8322
+ mode: "idle" | "deadline" | "quiescence" | "resumed";
8309
8323
  };
8310
8324
  /** Pending machine input that would start a turn in an idle session, by the
8311
8325
  * wake class map: every immediate kind except terminal command results (held
@@ -8337,6 +8351,8 @@ export declare function enrollRetainedCommandContainment(db: Database, input: {
8337
8351
  sandboxGroupId: string;
8338
8352
  /** Omit to evaluate only the provider-deadline rule. */
8339
8353
  idleCommandContainmentMs?: number | undefined;
8354
+ /** Internal recovery authority: caller verified exact Temporal settlement. */
8355
+ settledOwner?: SettledCommandOwner;
8340
8356
  }): Promise<CommandContainmentEnrollment | null>;
8341
8357
  export declare function reapStaleLeaseHoldersGlobal(db: Database, input: {
8342
8358
  viewerHolderTtlMs: number;