@opengeni/db 1.3.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.
- package/dist/canonical-human-identities.js +3 -3
- package/dist/capability-reconciliation.js +2 -2
- package/dist/{chunk-7QWWTVYH.js → chunk-5ROHLEN6.js} +29 -4
- package/dist/chunk-5ROHLEN6.js.map +1 -0
- package/dist/{chunk-AQMH2ZEH.js → chunk-A4J7EECR.js} +2 -2
- package/dist/{chunk-VQX54TK3.js → chunk-B5C5SBSI.js} +3 -3
- package/dist/{chunk-OI6YZXTU.js → chunk-DKFEUGM4.js} +2 -2
- package/dist/{chunk-HYBQABBJ.js → chunk-HUKBIZGH.js} +2 -2
- package/dist/{chunk-LRSIODCQ.js → chunk-IT3EYY2C.js} +6 -4
- package/dist/{chunk-LRSIODCQ.js.map → chunk-IT3EYY2C.js.map} +1 -1
- package/dist/{chunk-DSNEIW5E.js → chunk-JL6TBB76.js} +2 -1
- package/dist/chunk-JL6TBB76.js.map +1 -0
- package/dist/{chunk-OEFNTGR3.js → chunk-JWBEE4CL.js} +4 -4
- package/dist/{chunk-BRVBLQAL.js → chunk-K5MTNKJU.js} +4 -4
- package/dist/{chunk-6UKNJ43T.js → chunk-NZ2SP55O.js} +2 -2
- package/dist/{chunk-3XHC5KC5.js → chunk-OKCBARX6.js} +2 -2
- package/dist/{chunk-PNWWNEDM.js → chunk-OV5AUIBA.js} +2 -2
- package/dist/{chunk-BID3CNN3.js → chunk-TODVDGMO.js} +36 -18
- package/dist/{chunk-BID3CNN3.js.map → chunk-TODVDGMO.js.map} +1 -1
- package/dist/{chunk-6S5T6FSP.js → chunk-W75DRYG3.js} +5 -5
- package/dist/{chunk-7S3O33NM.js → chunk-Y72DP3JF.js} +2 -2
- package/dist/codemode-approvals.d.ts +7 -1
- package/dist/connect-attempts.js +3 -3
- package/dist/connection-metadata.d.ts +416 -0
- package/dist/credit-balances.d.ts +25 -4
- package/dist/database.d.ts +7 -1
- package/dist/editable-artifact-durable-export.js +2 -2
- package/dist/editable-artifacts.js +3 -3
- package/dist/index.d.ts +51 -8
- package/dist/index.js +10826 -10129
- package/dist/index.js.map +1 -1
- package/dist/legacy-tool-action-reviews.d.ts +75 -0
- package/dist/managed-auth-session-sets.js +3 -3
- package/dist/mcp-operations.js +2 -2
- package/dist/modal-native-live-origin.d.ts +75 -0
- package/dist/organization-integration-policy.js +3 -3
- package/dist/organization-slack-bots.d.ts +1 -1
- package/dist/provision-roles.js +1 -1
- package/dist/retained-provider-commands.d.ts +21 -21
- package/dist/retained-provider-commands.js +6 -6
- package/dist/runtime-posture.d.ts +1 -1
- package/dist/sandbox-interaction-idle.d.ts +22 -0
- package/dist/schema.js +1 -1
- package/dist/session-background-commands.js +4 -4
- package/dist/session-command-output.js +5 -5
- package/dist/session-event-slices.js +3 -3
- package/dist/session-mcp-credential-rotation.js +5 -5
- package/dist/session-realtime-billing.d.ts +48 -0
- package/dist/session-realtime.d.ts +8 -2
- package/dist/session-tenancy.js +3 -3
- package/dist/video-generation.js +3 -3
- package/dist/voice-transcription-settlement.d.ts +36 -0
- package/dist/workspace-tool-defaults.js +4 -4
- package/drizzle/0623_voice_transcription_attribution.sql +128 -0
- package/drizzle/0624_azure_live_realtime_model.sql +30 -0
- package/drizzle/0625_transcription_billing_refusal_codes.sql +29 -0
- package/drizzle/0632_modal_native_live_origin.sql +239 -0
- package/package.json +7 -7
- package/src/codemode-approvals.ts +52 -22
- package/src/codemode-operations.ts +198 -181
- package/src/connection-metadata.ts +166 -0
- package/src/credit-balances.ts +58 -17
- package/src/database.ts +9 -0
- package/src/index.ts +540 -412
- package/src/insights-unified.ts +2 -1
- package/src/legacy-tool-action-reviews.ts +242 -0
- package/src/modal-native-live-origin.ts +148 -0
- package/src/organization-slack-bots.ts +1 -1
- package/src/provision-roles.ts +12 -0
- package/src/runtime-posture.ts +32 -3
- package/src/sandbox-interaction-idle.ts +91 -0
- package/src/schema.ts +1 -0
- package/src/session-realtime-billing.ts +135 -0
- package/src/session-realtime-ledger.ts +9 -4
- package/src/session-realtime.ts +20 -2
- package/src/tool-action-reviews.ts +129 -18
- package/src/transcription-recordings.ts +3 -1
- package/src/voice-transcription-settlement.ts +94 -0
- package/dist/chunk-7QWWTVYH.js.map +0 -1
- package/dist/chunk-DSNEIW5E.js.map +0 -1
- /package/dist/{chunk-AQMH2ZEH.js.map → chunk-A4J7EECR.js.map} +0 -0
- /package/dist/{chunk-VQX54TK3.js.map → chunk-B5C5SBSI.js.map} +0 -0
- /package/dist/{chunk-OI6YZXTU.js.map → chunk-DKFEUGM4.js.map} +0 -0
- /package/dist/{chunk-HYBQABBJ.js.map → chunk-HUKBIZGH.js.map} +0 -0
- /package/dist/{chunk-OEFNTGR3.js.map → chunk-JWBEE4CL.js.map} +0 -0
- /package/dist/{chunk-BRVBLQAL.js.map → chunk-K5MTNKJU.js.map} +0 -0
- /package/dist/{chunk-6UKNJ43T.js.map → chunk-NZ2SP55O.js.map} +0 -0
- /package/dist/{chunk-3XHC5KC5.js.map → chunk-OKCBARX6.js.map} +0 -0
- /package/dist/{chunk-PNWWNEDM.js.map → chunk-OV5AUIBA.js.map} +0 -0
- /package/dist/{chunk-6S5T6FSP.js.map → chunk-W75DRYG3.js.map} +0 -0
- /package/dist/{chunk-7S3O33NM.js.map → chunk-Y72DP3JF.js.map} +0 -0
package/src/credit-balances.ts
CHANGED
|
@@ -38,7 +38,8 @@ export async function getBillingBalance(
|
|
|
38
38
|
else policy->'offers'->(g.metadata->>'creditOfferId')->'eligibleModelIds' end,
|
|
39
39
|
policy->'defaultModelIds'
|
|
40
40
|
) from current_policy), to_jsonb(g.eligible_model_ids)),
|
|
41
|
-
'remainingMicros', g.amount_micros - coalesce(used.amount, 0)
|
|
41
|
+
'remainingMicros', g.amount_micros - coalesce(used.amount, 0),
|
|
42
|
+
'coversVoice', g.source_type = 'verified_signup_trial'
|
|
42
43
|
) order by g.created_at, g.id)
|
|
43
44
|
from ${schema.creditLedgerEntries} g
|
|
44
45
|
left join (
|
|
@@ -66,13 +67,28 @@ export async function getBillingBalance(
|
|
|
66
67
|
});
|
|
67
68
|
}
|
|
68
69
|
|
|
69
|
-
/**
|
|
70
|
-
|
|
70
|
+
/**
|
|
71
|
+
* What a charge pays for. A canonical model ID uses grants scoped to that
|
|
72
|
+
* model; {@link VOICE_CREDIT_USAGE} (dictation and live voice) uses grants
|
|
73
|
+
* that cover voice, which are the verified-signup trial credits. Omitted means
|
|
74
|
+
* a non-model resource, which can only use general credits.
|
|
75
|
+
*/
|
|
76
|
+
export type CreditUsage = string | { readonly kind: "voice" } | undefined;
|
|
77
|
+
|
|
78
|
+
/** Deployment-funded dictation and live voice. */
|
|
79
|
+
export const VOICE_CREDIT_USAGE: { readonly kind: "voice" } = Object.freeze({ kind: "voice" });
|
|
80
|
+
|
|
81
|
+
function grantCovers(grant: PromotionalCreditBalance, usage: CreditUsage): boolean {
|
|
82
|
+
if (!usage) return false;
|
|
83
|
+
if (typeof usage === "string") return grant.eligibleModelIds.includes(usage);
|
|
84
|
+
return grant.coversVoice === true;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function spendableCreditMicros(balance: BillingBalance, usage?: CreditUsage): number {
|
|
71
88
|
return (
|
|
72
89
|
Math.max(0, balance.generalBalanceMicros ?? balance.balanceMicros) +
|
|
73
90
|
(balance.promotionalCredits ?? []).reduce(
|
|
74
|
-
(sum, grant) =>
|
|
75
|
-
sum + (modelId && grant.eligibleModelIds.includes(modelId) ? grant.remainingMicros : 0),
|
|
91
|
+
(sum, grant) => sum + (grantCovers(grant, usage) ? grant.remainingMicros : 0),
|
|
76
92
|
0,
|
|
77
93
|
)
|
|
78
94
|
);
|
|
@@ -81,29 +97,54 @@ export function spendableCreditMicros(balance: BillingBalance, modelId?: string)
|
|
|
81
97
|
export async function getSpendableCreditBalance(
|
|
82
98
|
db: Database,
|
|
83
99
|
accountId: string,
|
|
84
|
-
|
|
100
|
+
usage?: CreditUsage,
|
|
85
101
|
policyRevision?: number,
|
|
86
102
|
): Promise<CreditBalanceSnapshot> {
|
|
87
103
|
const balance = await getBillingBalance(db, accountId, policyRevision);
|
|
88
|
-
return { ...balance, balanceMicros: spendableCreditMicros(balance,
|
|
104
|
+
return { ...balance, balanceMicros: spendableCreditMicros(balance, usage) };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Covering grants pay first, oldest first; the rest is general credit. */
|
|
108
|
+
function allocateToCoveringGrants(
|
|
109
|
+
balance: BillingBalance,
|
|
110
|
+
amountMicros: number,
|
|
111
|
+
usage: CreditUsage,
|
|
112
|
+
) {
|
|
113
|
+
let remaining = amountMicros;
|
|
114
|
+
const allocations: { grantEntryId: string; amountMicros: number }[] = [];
|
|
115
|
+
for (const grant of balance.promotionalCredits ?? []) {
|
|
116
|
+
if (!remaining || !grantCovers(grant, usage) || grant.remainingMicros <= 0) continue;
|
|
117
|
+
const allocated = Math.min(remaining, grant.remainingMicros);
|
|
118
|
+
allocations.push({ grantEntryId: grant.grantId, amountMicros: allocated });
|
|
119
|
+
remaining -= allocated;
|
|
120
|
+
}
|
|
121
|
+
return allocations;
|
|
89
122
|
}
|
|
90
123
|
|
|
91
124
|
export function planCreditDebit(
|
|
92
125
|
balance: BillingBalance,
|
|
93
126
|
requestedMicros: number,
|
|
94
|
-
|
|
127
|
+
usage?: CreditUsage,
|
|
95
128
|
) {
|
|
96
129
|
if (!Number.isSafeInteger(requestedMicros) || requestedMicros <= 0) {
|
|
97
130
|
throw new Error("credit debit requires a positive, safe integer micro amount");
|
|
98
131
|
}
|
|
99
|
-
const debitedMicros = Math.min(requestedMicros, spendableCreditMicros(balance,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
132
|
+
const debitedMicros = Math.min(requestedMicros, spendableCreditMicros(balance, usage));
|
|
133
|
+
return { debitedMicros, allocations: allocateToCoveringGrants(balance, debitedMicros, usage) };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Allocations for an already-consumed charge of the full amount: covering
|
|
138
|
+
* grants pay what they can and general credit takes the rest, possibly going
|
|
139
|
+
* negative.
|
|
140
|
+
*/
|
|
141
|
+
export function planPostUseCreditAllocations(
|
|
142
|
+
balance: BillingBalance,
|
|
143
|
+
amountMicros: number,
|
|
144
|
+
usage: CreditUsage,
|
|
145
|
+
) {
|
|
146
|
+
if (!Number.isSafeInteger(amountMicros) || amountMicros <= 0) {
|
|
147
|
+
throw new Error("credit debit requires a positive, safe integer micro amount");
|
|
107
148
|
}
|
|
108
|
-
return
|
|
149
|
+
return allocateToCoveringGrants(balance, amountMicros, usage);
|
|
109
150
|
}
|
package/src/database.ts
CHANGED
|
@@ -898,17 +898,26 @@ export async function withSessionActivityRlsContext<T>(
|
|
|
898
898
|
);
|
|
899
899
|
}
|
|
900
900
|
|
|
901
|
+
/**
|
|
902
|
+
* `organizationMembershipFence` is required when the callback takes the
|
|
903
|
+
* organization-membership lifecycle lock (for example external-actor
|
|
904
|
+
* reauthorization): that lock precedes the session-tenancy fence and the
|
|
905
|
+
* canonical control/workspace/session prefix, never follows it.
|
|
906
|
+
*/
|
|
901
907
|
export async function withWorkspaceSessionActivityRls<T>(
|
|
902
908
|
db: Database,
|
|
903
909
|
workspaceId: string,
|
|
904
910
|
fn: (db: SessionActivityDatabase) => Promise<T>,
|
|
905
911
|
transactionConfig?: PgTransactionConfig,
|
|
912
|
+
organizationMembershipFence = false,
|
|
906
913
|
): Promise<T> {
|
|
907
914
|
return await withSessionActivityRlsContext(
|
|
908
915
|
db,
|
|
909
916
|
{ ...(await rlsContextForWorkspace(db, workspaceId)), workspaceId },
|
|
910
917
|
fn,
|
|
911
918
|
transactionConfig,
|
|
919
|
+
"shared",
|
|
920
|
+
organizationMembershipFence,
|
|
912
921
|
);
|
|
913
922
|
}
|
|
914
923
|
|