@opengeni/db 1.4.0 → 1.4.2

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 (68) hide show
  1. package/dist/canonical-human-identities.js +2 -2
  2. package/dist/capability-reconciliation.js +1 -1
  3. package/dist/{chunk-7QWWTVYH.js → chunk-5ROHLEN6.js} +29 -4
  4. package/dist/chunk-5ROHLEN6.js.map +1 -0
  5. package/dist/{chunk-BA52ITIY.js → chunk-A4J7EECR.js} +2 -2
  6. package/dist/{chunk-3WUCM7YF.js → chunk-B5C5SBSI.js} +2 -2
  7. package/dist/{chunk-VCHK4D6S.js → chunk-DKFEUGM4.js} +2 -2
  8. package/dist/{chunk-EFANLEWI.js → chunk-HUKBIZGH.js} +2 -2
  9. package/dist/{chunk-27T4AP25.js → chunk-IT3EYY2C.js} +5 -3
  10. package/dist/{chunk-27T4AP25.js.map → chunk-IT3EYY2C.js.map} +1 -1
  11. package/dist/{chunk-NT7OGKYX.js → chunk-JWBEE4CL.js} +3 -3
  12. package/dist/{chunk-AMK3FNOW.js → chunk-K5MTNKJU.js} +3 -3
  13. package/dist/{chunk-GC5GUTV3.js → chunk-NZ2SP55O.js} +2 -2
  14. package/dist/{chunk-TRUEH4I2.js → chunk-OKCBARX6.js} +2 -2
  15. package/dist/{chunk-EMYA6XNE.js → chunk-OV5AUIBA.js} +2 -2
  16. package/dist/{chunk-T3CYF3DH.js → chunk-TODVDGMO.js} +35 -17
  17. package/dist/{chunk-T3CYF3DH.js.map → chunk-TODVDGMO.js.map} +1 -1
  18. package/dist/{chunk-CKDHKQS4.js → chunk-W75DRYG3.js} +4 -4
  19. package/dist/{chunk-UQELJ6OM.js → chunk-Y72DP3JF.js} +2 -2
  20. package/dist/codemode-approvals.d.ts +7 -1
  21. package/dist/connect-attempts.js +2 -2
  22. package/dist/credit-balances.d.ts +25 -4
  23. package/dist/database.d.ts +7 -1
  24. package/dist/editable-artifact-durable-export.js +1 -1
  25. package/dist/editable-artifacts.js +2 -2
  26. package/dist/index.d.ts +24 -2
  27. package/dist/index.js +2778 -2508
  28. package/dist/index.js.map +1 -1
  29. package/dist/managed-auth-session-sets.js +2 -2
  30. package/dist/mcp-operations.js +1 -1
  31. package/dist/modal-native-live-origin.d.ts +75 -0
  32. package/dist/organization-integration-policy.js +2 -2
  33. package/dist/provision-roles.js +1 -1
  34. package/dist/retained-provider-commands.d.ts +21 -21
  35. package/dist/retained-provider-commands.js +5 -5
  36. package/dist/runtime-posture.d.ts +1 -1
  37. package/dist/sandbox-interaction-idle.d.ts +22 -0
  38. package/dist/session-background-commands.js +3 -3
  39. package/dist/session-command-output.js +4 -4
  40. package/dist/session-event-slices.js +2 -2
  41. package/dist/session-mcp-credential-rotation.js +4 -4
  42. package/dist/session-tenancy.js +2 -2
  43. package/dist/video-generation.js +2 -2
  44. package/dist/workspace-tool-defaults.js +3 -3
  45. package/drizzle/0632_modal_native_live_origin.sql +239 -0
  46. package/package.json +7 -7
  47. package/src/codemode-approvals.ts +52 -22
  48. package/src/codemode-operations.ts +198 -181
  49. package/src/credit-balances.ts +58 -17
  50. package/src/database.ts +9 -0
  51. package/src/index.ts +449 -254
  52. package/src/modal-native-live-origin.ts +148 -0
  53. package/src/provision-roles.ts +12 -0
  54. package/src/runtime-posture.ts +32 -3
  55. package/src/sandbox-interaction-idle.ts +91 -0
  56. package/src/transcription-recordings.ts +3 -1
  57. package/dist/chunk-7QWWTVYH.js.map +0 -1
  58. /package/dist/{chunk-BA52ITIY.js.map → chunk-A4J7EECR.js.map} +0 -0
  59. /package/dist/{chunk-3WUCM7YF.js.map → chunk-B5C5SBSI.js.map} +0 -0
  60. /package/dist/{chunk-VCHK4D6S.js.map → chunk-DKFEUGM4.js.map} +0 -0
  61. /package/dist/{chunk-EFANLEWI.js.map → chunk-HUKBIZGH.js.map} +0 -0
  62. /package/dist/{chunk-NT7OGKYX.js.map → chunk-JWBEE4CL.js.map} +0 -0
  63. /package/dist/{chunk-AMK3FNOW.js.map → chunk-K5MTNKJU.js.map} +0 -0
  64. /package/dist/{chunk-GC5GUTV3.js.map → chunk-NZ2SP55O.js.map} +0 -0
  65. /package/dist/{chunk-TRUEH4I2.js.map → chunk-OKCBARX6.js.map} +0 -0
  66. /package/dist/{chunk-EMYA6XNE.js.map → chunk-OV5AUIBA.js.map} +0 -0
  67. /package/dist/{chunk-CKDHKQS4.js.map → chunk-W75DRYG3.js.map} +0 -0
  68. /package/dist/{chunk-UQELJ6OM.js.map → chunk-Y72DP3JF.js.map} +0 -0
@@ -7,7 +7,7 @@ import {
7
7
  withAccountRls,
8
8
  withRlsContext,
9
9
  withWorkspaceRls
10
- } from "./chunk-27T4AP25.js";
10
+ } from "./chunk-IT3EYY2C.js";
11
11
  import {
12
12
  connections,
13
13
  creditDebitAllocations,
@@ -345,7 +345,8 @@ async function getBillingBalance(db, accountId, policyRevision) {
345
345
  else policy->'offers'->(g.metadata->>'creditOfferId')->'eligibleModelIds' end,
346
346
  policy->'defaultModelIds'
347
347
  ) from current_policy), to_jsonb(g.eligible_model_ids)),
348
- 'remainingMicros', g.amount_micros - coalesce(used.amount, 0)
348
+ 'remainingMicros', g.amount_micros - coalesce(used.amount, 0),
349
+ 'coversVoice', g.source_type = 'verified_signup_trial'
349
350
  ) order by g.created_at, g.id)
350
351
  from ${creditLedgerEntries} g
351
352
  left join (
@@ -371,30 +372,45 @@ async function getBillingBalance(db, accountId, policyRevision) {
371
372
  };
372
373
  });
373
374
  }
374
- function spendableCreditMicros(balance, modelId) {
375
+ var VOICE_CREDIT_USAGE = Object.freeze({ kind: "voice" });
376
+ function grantCovers(grant, usage) {
377
+ if (!usage) return false;
378
+ if (typeof usage === "string") return grant.eligibleModelIds.includes(usage);
379
+ return grant.coversVoice === true;
380
+ }
381
+ function spendableCreditMicros(balance, usage) {
375
382
  return Math.max(0, balance.generalBalanceMicros ?? balance.balanceMicros) + (balance.promotionalCredits ?? []).reduce(
376
- (sum, grant) => sum + (modelId && grant.eligibleModelIds.includes(modelId) ? grant.remainingMicros : 0),
383
+ (sum, grant) => sum + (grantCovers(grant, usage) ? grant.remainingMicros : 0),
377
384
  0
378
385
  );
379
386
  }
380
- async function getSpendableCreditBalance(db, accountId, modelId, policyRevision) {
387
+ async function getSpendableCreditBalance(db, accountId, usage, policyRevision) {
381
388
  const balance = await getBillingBalance(db, accountId, policyRevision);
382
- return { ...balance, balanceMicros: spendableCreditMicros(balance, modelId) };
389
+ return { ...balance, balanceMicros: spendableCreditMicros(balance, usage) };
390
+ }
391
+ function allocateToCoveringGrants(balance, amountMicros, usage) {
392
+ let remaining = amountMicros;
393
+ const allocations = [];
394
+ for (const grant of balance.promotionalCredits ?? []) {
395
+ if (!remaining || !grantCovers(grant, usage) || grant.remainingMicros <= 0) continue;
396
+ const allocated = Math.min(remaining, grant.remainingMicros);
397
+ allocations.push({ grantEntryId: grant.grantId, amountMicros: allocated });
398
+ remaining -= allocated;
399
+ }
400
+ return allocations;
383
401
  }
384
- function planCreditDebit(balance, requestedMicros, modelId) {
402
+ function planCreditDebit(balance, requestedMicros, usage) {
385
403
  if (!Number.isSafeInteger(requestedMicros) || requestedMicros <= 0) {
386
404
  throw new Error("credit debit requires a positive, safe integer micro amount");
387
405
  }
388
- const debitedMicros = Math.min(requestedMicros, spendableCreditMicros(balance, modelId));
389
- let remaining = debitedMicros;
390
- const allocations = [];
391
- for (const grant of balance.promotionalCredits ?? []) {
392
- if (!remaining || !modelId || !grant.eligibleModelIds.includes(modelId)) continue;
393
- const amountMicros = Math.min(remaining, grant.remainingMicros);
394
- allocations.push({ grantEntryId: grant.grantId, amountMicros });
395
- remaining -= amountMicros;
406
+ const debitedMicros = Math.min(requestedMicros, spendableCreditMicros(balance, usage));
407
+ return { debitedMicros, allocations: allocateToCoveringGrants(balance, debitedMicros, usage) };
408
+ }
409
+ function planPostUseCreditAllocations(balance, amountMicros, usage) {
410
+ if (!Number.isSafeInteger(amountMicros) || amountMicros <= 0) {
411
+ throw new Error("credit debit requires a positive, safe integer micro amount");
396
412
  }
397
- return { debitedMicros, allocations };
413
+ return allocateToCoveringGrants(balance, amountMicros, usage);
398
414
  }
399
415
 
400
416
  // src/video-generation.ts
@@ -1378,9 +1394,11 @@ export {
1378
1394
  checkWorkspaceAllowance,
1379
1395
  maintainWorkspaceAllowances,
1380
1396
  getBillingBalance,
1397
+ VOICE_CREDIT_USAGE,
1381
1398
  spendableCreditMicros,
1382
1399
  getSpendableCreditBalance,
1383
1400
  planCreditDebit,
1401
+ planPostUseCreditAllocations,
1384
1402
  ACTIVE_VIDEO_GENERATION_STATUSES,
1385
1403
  VideoGenerationConflictError,
1386
1404
  VideoGenerationCapacityError,
@@ -1412,4 +1430,4 @@ export {
1412
1430
  mediaGenerationResultForStoredOperation,
1413
1431
  getVideoGenerationOperationSummary
1414
1432
  };
1415
- //# sourceMappingURL=chunk-T3CYF3DH.js.map
1433
+ //# sourceMappingURL=chunk-TODVDGMO.js.map