@opengeni/config 2.0.0 → 2.0.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/claude-subscription-capacity.d.ts +9 -0
- package/dist/claude-subscription-oauth.d.ts +17 -0
- package/dist/claude-subscription-usage.d.ts +13 -0
- package/dist/credit-promotions.d.ts +25 -0
- package/dist/index.d.ts +1839 -51
- package/dist/index.js +3891 -566
- package/dist/index.js.map +1 -1
- package/dist/managed-user-admission.d.ts +2 -0
- package/dist/realtime-voice-pricing.d.ts +30 -0
- package/dist/subscription-account-selection.d.ts +17 -0
- package/dist/web-search.d.ts +174 -0
- package/package.json +5 -5
- package/src/claude-subscription-capacity.ts +129 -0
- package/src/claude-subscription-oauth.ts +33 -0
- package/src/claude-subscription-usage.ts +328 -0
- package/src/credit-promotions.ts +68 -0
- package/src/index.ts +3917 -180
- package/src/managed-user-admission.ts +11 -0
- package/src/realtime-voice-pricing.ts +83 -0
- package/src/subscription-account-selection.ts +36 -0
- package/src/web-search.ts +600 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Deployment admission for native human accounts; never service credentials. */
|
|
2
|
+
export function managedUserEmailAllowed(
|
|
3
|
+
allowedUserEmails: readonly string[] | undefined,
|
|
4
|
+
email: unknown,
|
|
5
|
+
): boolean {
|
|
6
|
+
return (
|
|
7
|
+
allowedUserEmails === undefined ||
|
|
8
|
+
(typeof email === "string" &&
|
|
9
|
+
allowedUserEmails.some((allowed) => allowed.toLowerCase() === email.trim().toLowerCase()))
|
|
10
|
+
);
|
|
11
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Credit pricing for deployment-funded live (speech-to-speech) voice.
|
|
5
|
+
*
|
|
6
|
+
* Live voice is metered by server-observed connection time, billed per started
|
|
7
|
+
* minute. Prices are deployment configuration, never code defaults: when credit
|
|
8
|
+
* billing is active, a deployment-funded voice model without a configured price
|
|
9
|
+
* is not offered and cannot be started.
|
|
10
|
+
*/
|
|
11
|
+
export type RealtimeVoicePricing = {
|
|
12
|
+
/** Upstream cost of one minute of live voice, in USD micros. */
|
|
13
|
+
microsPerMinute: number;
|
|
14
|
+
/** Opengeni margin in basis points added on top of the upstream cost. */
|
|
15
|
+
marginBps?: number | undefined;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const RealtimeVoicePricingSchema = z
|
|
19
|
+
.object({
|
|
20
|
+
microsPerMinute: z.number().int().positive().max(100_000_000),
|
|
21
|
+
marginBps: z.number().int().min(0).max(100_000).optional(),
|
|
22
|
+
})
|
|
23
|
+
.strict();
|
|
24
|
+
|
|
25
|
+
/** Model id of the deployment-hosted Azure GPT Live voice. */
|
|
26
|
+
export const AZURE_LIVE_REALTIME_MODEL_ID = "opengeni-azure/gpt-live-1" as const;
|
|
27
|
+
|
|
28
|
+
function parseJson(raw: string, env: string): unknown {
|
|
29
|
+
try {
|
|
30
|
+
return JSON.parse(raw);
|
|
31
|
+
} catch {
|
|
32
|
+
throw new Error(`${env} must be valid JSON`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function issues(error: z.ZodError): string {
|
|
37
|
+
return error.issues
|
|
38
|
+
.map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`)
|
|
39
|
+
.join("; ");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** One live-voice price, e.g. `{"microsPerMinute":50000,"marginBps":500}`. */
|
|
43
|
+
export function parseRealtimeVoicePricingJson(
|
|
44
|
+
raw: string | undefined,
|
|
45
|
+
env = "live voice pricing JSON",
|
|
46
|
+
): RealtimeVoicePricing | null {
|
|
47
|
+
if (raw === undefined || raw.trim() === "") return null;
|
|
48
|
+
const result = RealtimeVoicePricingSchema.safeParse(parseJson(raw, env));
|
|
49
|
+
if (!result.success) throw new Error(`${env} is invalid: ${issues(result.error)}`);
|
|
50
|
+
return result.data;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Prices keyed by upstream AI Gateway realtime model id, e.g.
|
|
55
|
+
* `{"openai/gpt-realtime-2.1":{"microsPerMinute":120000,"marginBps":500}}`.
|
|
56
|
+
*/
|
|
57
|
+
export function parseRealtimeVoicePricingTableJson(
|
|
58
|
+
raw: string | undefined,
|
|
59
|
+
env = "live voice pricing table JSON",
|
|
60
|
+
): Record<string, RealtimeVoicePricing> {
|
|
61
|
+
if (raw === undefined || raw.trim() === "") return {};
|
|
62
|
+
const result = z
|
|
63
|
+
.record(z.string().min(1).max(256), RealtimeVoicePricingSchema)
|
|
64
|
+
.safeParse(parseJson(raw, env));
|
|
65
|
+
if (!result.success) throw new Error(`${env} is invalid: ${issues(result.error)}`);
|
|
66
|
+
return result.data;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Credit price of one started minute, after margin, rounded up to whole micros. */
|
|
70
|
+
export function realtimeVoiceMinuteCreditMicros(pricing: RealtimeVoicePricing): {
|
|
71
|
+
providerCostMicros: number;
|
|
72
|
+
creditCostMicros: number;
|
|
73
|
+
} {
|
|
74
|
+
const provider = BigInt(pricing.microsPerMinute);
|
|
75
|
+
const credit = (provider * BigInt(10_000 + (pricing.marginBps ?? 0)) + 9_999n) / 10_000n;
|
|
76
|
+
return { providerCostMicros: Number(provider), creditCostMicros: Number(credit) };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Billed minutes for a server-observed interval: every started minute, at least one. */
|
|
80
|
+
export function realtimeVoiceStartedMinutes(startedAt: Date, observedUntil: Date): number {
|
|
81
|
+
const elapsed = Math.max(0, observedUntil.getTime() - startedAt.getTime());
|
|
82
|
+
return Math.max(1, Math.ceil(elapsed / 60_000));
|
|
83
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Stable account affinity shared by subscription providers. Candidate order is durable creation order. */
|
|
2
|
+
export function subscriptionAccountShardIndex(sessionId: string, candidateCount: number): number {
|
|
3
|
+
if (!Number.isSafeInteger(candidateCount) || candidateCount <= 0)
|
|
4
|
+
throw new Error("Subscription shard candidate count must be positive");
|
|
5
|
+
let hash = 0x811c9dc5;
|
|
6
|
+
for (let index = 0; index < sessionId.length; index += 1) {
|
|
7
|
+
hash ^= sessionId.charCodeAt(index);
|
|
8
|
+
hash = Math.imul(hash, 0x01000193);
|
|
9
|
+
}
|
|
10
|
+
return (hash >>> 0) % candidateCount;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Manual pins are binding even when unavailable. Policy homes remain sticky only
|
|
15
|
+
* while rotation is on; an exhausted home re-shards over the eligible survivors.
|
|
16
|
+
* Selection never changes the pool's active pointer.
|
|
17
|
+
*/
|
|
18
|
+
export function selectSubscriptionAccount<T extends { id: string }>(input: {
|
|
19
|
+
sessionId: string;
|
|
20
|
+
eligible: readonly T[];
|
|
21
|
+
rotationEnabled: boolean;
|
|
22
|
+
activeCredentialId: string | null;
|
|
23
|
+
pinnedCredentialId: string | null;
|
|
24
|
+
pinSource: "manual" | "policy" | null;
|
|
25
|
+
}): T | null {
|
|
26
|
+
const pinned = input.eligible.find((account) => account.id === input.pinnedCredentialId);
|
|
27
|
+
if (input.pinnedCredentialId && input.pinSource !== "policy") return pinned ?? null;
|
|
28
|
+
if (!input.rotationEnabled)
|
|
29
|
+
return input.eligible.find((account) => account.id === input.activeCredentialId) ?? null;
|
|
30
|
+
return (
|
|
31
|
+
pinned ??
|
|
32
|
+
(input.eligible.length
|
|
33
|
+
? input.eligible[subscriptionAccountShardIndex(input.sessionId, input.eligible.length)]!
|
|
34
|
+
: null)
|
|
35
|
+
);
|
|
36
|
+
}
|