@opengeni/contracts 2.9.2-canary.0 → 2.9.2-canary.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.
@@ -0,0 +1,75 @@
1
+ export type ModelPickerBillingClass =
2
+ | "opengeni_credits"
3
+ | "external"
4
+ | "codex_subscription"
5
+ | "supergrok_subscription"
6
+ | "byok";
7
+
8
+ // Every closed billing class has a unique first character. Keeping the order
9
+ // as initials avoids duplicating the full public labels in browser bundles.
10
+ const MODEL_PICKER_BILLING_CLASS_INITIAL_ORDER = "oecsb";
11
+
12
+ export type ModelPickerBillingCandidate = {
13
+ source?: string | undefined;
14
+ cost?: "free" | "credits" | "subscription" | "workspace" | undefined;
15
+ billing?:
16
+ | {
17
+ upstreamPayer?: string | undefined;
18
+ metering?: string | undefined;
19
+ }
20
+ | undefined;
21
+ credentialSource?:
22
+ | {
23
+ kind?: string | undefined;
24
+ provider?: string | undefined;
25
+ }
26
+ | undefined;
27
+ };
28
+
29
+ export function modelPickerBillingClassFor(
30
+ model: ModelPickerBillingCandidate,
31
+ ): ModelPickerBillingClass {
32
+ if (model.cost === "credits") return "opengeni_credits";
33
+ if (model.cost === "workspace") return "byok";
34
+ const source = model.source;
35
+ const credential = model.credentialSource;
36
+ const payer = model.billing?.upstreamPayer;
37
+ if (model.billing?.metering === "external" && payer === "deployment") {
38
+ return "external";
39
+ }
40
+ if (
41
+ source === "supergrok" ||
42
+ (credential?.kind === "connected_subscription" && credential.provider === "xai")
43
+ ) {
44
+ return "supergrok_subscription";
45
+ }
46
+ if (
47
+ source === "codex" ||
48
+ credential?.kind === "connected_subscription" ||
49
+ payer === "connected_subscription"
50
+ ) {
51
+ return "codex_subscription";
52
+ }
53
+ if (
54
+ source === "workspace_gateway" ||
55
+ credential?.kind === "workspace_connection" ||
56
+ payer === "workspace"
57
+ ) {
58
+ return "byok";
59
+ }
60
+ return "opengeni_credits";
61
+ }
62
+
63
+ export function compareModelPickerOrder(
64
+ left: { billingClass: ModelPickerBillingClass; selectable: boolean; label: string },
65
+ right: { billingClass: ModelPickerBillingClass; selectable: boolean; label: string },
66
+ ): number {
67
+ const classDelta =
68
+ MODEL_PICKER_BILLING_CLASS_INITIAL_ORDER.indexOf(left.billingClass[0]!) -
69
+ MODEL_PICKER_BILLING_CLASS_INITIAL_ORDER.indexOf(right.billingClass[0]!);
70
+ return (
71
+ classDelta ||
72
+ +right.selectable - +left.selectable ||
73
+ (left.label < right.label ? -1 : left.label > right.label ? 1 : 0)
74
+ );
75
+ }