@opengeni/xai-subscription 0.1.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.
- package/LICENSE +190 -0
- package/README.md +20 -0
- package/dist/bounded-operation.d.ts +8 -0
- package/dist/chunk-JEFGIUGN.js +80 -0
- package/dist/chunk-JEFGIUGN.js.map +1 -0
- package/dist/constants.d.ts +32 -0
- package/dist/constants.js +69 -0
- package/dist/constants.js.map +1 -0
- package/dist/errors.d.ts +12 -0
- package/dist/fetch.d.ts +7 -0
- package/dist/images.d.ts +22 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +1245 -0
- package/dist/index.js.map +1 -0
- package/dist/models.d.ts +18 -0
- package/dist/normalize.d.ts +6 -0
- package/dist/oauth.d.ts +55 -0
- package/dist/proxy.d.ts +17 -0
- package/dist/quota.d.ts +24 -0
- package/dist/request-context.d.ts +26 -0
- package/dist/video.d.ts +53 -0
- package/package.json +45 -0
- package/src/bounded-operation.ts +33 -0
- package/src/constants.ts +53 -0
- package/src/errors.ts +34 -0
- package/src/fetch.ts +234 -0
- package/src/images.ts +176 -0
- package/src/index.ts +12 -0
- package/src/models.ts +99 -0
- package/src/normalize.ts +146 -0
- package/src/oauth.ts +335 -0
- package/src/proxy.ts +86 -0
- package/src/quota.ts +101 -0
- package/src/request-context.ts +31 -0
- package/src/video.ts +388 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 Cloudgeni-ai
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# `@opengeni/xai-subscription`
|
|
2
|
+
|
|
3
|
+
Pure protocol helpers for OpenGeni's explicit `workspace | user` SuperGrok/xAI
|
|
4
|
+
connected-subscription rail. Workspace scope is the default shared path; tenant
|
|
5
|
+
authority and persistence remain outside this package.
|
|
6
|
+
|
|
7
|
+
The package owns:
|
|
8
|
+
|
|
9
|
+
- xAI OAuth 2.0 device-code login, refresh, and verified OIDC user-info lookup;
|
|
10
|
+
- per-request credential context and the authenticated Responses transport;
|
|
11
|
+
- provider request normalization for encrypted reasoning and hosted search tools;
|
|
12
|
+
- bounded quota reads and credential validation against the Grok CLI proxy; and
|
|
13
|
+
- direct xAI image/video generation helpers.
|
|
14
|
+
|
|
15
|
+
It deliberately has no database dependency. Workspace/user authority,
|
|
16
|
+
encrypted persistence, account selection, allocator state, leases, and durable
|
|
17
|
+
request receipts remain in OpenGeni's DB/worker layers.
|
|
18
|
+
|
|
19
|
+
See [`docs/supergrok-subscription.md`](../../docs/supergrok-subscription.md) for
|
|
20
|
+
the canonical authority, rotation, and durable-capacity contract.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type XaiOperationFailureReason = "network_error" | "timeout";
|
|
2
|
+
export declare function runBoundedXaiOperation<T>(operation: (signal: AbortSignal) => Promise<T>, timeoutMs: number): Promise<{
|
|
3
|
+
ok: true;
|
|
4
|
+
value: T;
|
|
5
|
+
} | {
|
|
6
|
+
ok: false;
|
|
7
|
+
reason: XaiOperationFailureReason;
|
|
8
|
+
}>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// src/constants.ts
|
|
2
|
+
var XAI_OAUTH_ISSUER = "https://auth.x.ai";
|
|
3
|
+
var XAI_OAUTH_CLIENT_ID = "b1a00492-073a-47ea-816f-4c329264a828";
|
|
4
|
+
var XAI_OAUTH_SCOPES = [
|
|
5
|
+
"openid",
|
|
6
|
+
"profile",
|
|
7
|
+
"email",
|
|
8
|
+
"offline_access",
|
|
9
|
+
"grok-cli:access",
|
|
10
|
+
"api:access"
|
|
11
|
+
];
|
|
12
|
+
var XAI_DEVICE_AUTHORIZATION_URL = `${XAI_OAUTH_ISSUER}/oauth2/device/code`;
|
|
13
|
+
var XAI_TOKEN_URL = `${XAI_OAUTH_ISSUER}/oauth2/token`;
|
|
14
|
+
var XAI_USERINFO_URL = `${XAI_OAUTH_ISSUER}/oauth2/userinfo`;
|
|
15
|
+
var XAI_DEVICE_CODE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
|
|
16
|
+
var XAI_SUBSCRIPTION_PROXY_BASE_URL = "https://cli-chat-proxy.grok.com/v1";
|
|
17
|
+
var XAI_PUBLIC_API_BASE_URL = "https://api.x.ai/v1";
|
|
18
|
+
var XAI_TOKEN_AUTH_HEADER_VALUE = "xai-grok-cli";
|
|
19
|
+
var XAI_CLIENT_VERSION = "1.0.3";
|
|
20
|
+
var XAI_CLIENT_MODE = "opengeni";
|
|
21
|
+
var XAI_SUBSCRIPTION_PROVIDER_ID = "supergrok-subscription";
|
|
22
|
+
var XAI_SUBSCRIPTION_MODEL_ID_PREFIX = "supergrok/";
|
|
23
|
+
var XAI_SUBSCRIPTION_MODEL_SLUGS = ["grok-4.6"];
|
|
24
|
+
var XAI_SUBSCRIPTION_MODEL_CONTEXT_WINDOW_TOKENS = 5e5;
|
|
25
|
+
var XAI_SUBSCRIPTION_EFFECTIVE_CONTEXT_PERCENT = 95;
|
|
26
|
+
var XAI_SUBSCRIPTION_MODEL_EFFECTIVE_CONTEXT_WINDOW_TOKENS = Math.floor(
|
|
27
|
+
XAI_SUBSCRIPTION_MODEL_CONTEXT_WINDOW_TOKENS * XAI_SUBSCRIPTION_EFFECTIVE_CONTEXT_PERCENT / 100
|
|
28
|
+
);
|
|
29
|
+
var XAI_SUBSCRIPTION_AUTO_COMPACTION_PERCENT = 80;
|
|
30
|
+
var XAI_SUBSCRIPTION_MODEL_AUTO_COMPACT_TOKEN_LIMIT = Math.floor(
|
|
31
|
+
XAI_SUBSCRIPTION_MODEL_CONTEXT_WINDOW_TOKENS * XAI_SUBSCRIPTION_AUTO_COMPACTION_PERCENT / 100
|
|
32
|
+
);
|
|
33
|
+
var XAI_IMAGE_MODEL = "grok-imagine-image-quality";
|
|
34
|
+
var XAI_VIDEO_MODEL = "grok-imagine-video-1.5";
|
|
35
|
+
var XAI_OAUTH_OPERATION_TIMEOUT_MS = 15e3;
|
|
36
|
+
var XAI_REFRESH_WINDOW_MS = 2 * 6e4;
|
|
37
|
+
var XAI_REFRESH_FALLBACK_MS = 60 * 6e4;
|
|
38
|
+
var XAI_RESPONSE_SDK_OUTER_TIMEOUT_MS = 35 * 6e4;
|
|
39
|
+
var XAI_IMAGE_REQUEST_TIMEOUT_MS = 5 * 6e4;
|
|
40
|
+
var XAI_VIDEO_START_TIMEOUT_MS = 6e4;
|
|
41
|
+
var XAI_VIDEO_POLL_REQUEST_TIMEOUT_MS = 3e4;
|
|
42
|
+
var XAI_VIDEO_POLL_INTERVAL_MS = 5e3;
|
|
43
|
+
var XAI_VIDEO_GENERATION_TIMEOUT_MS = 5 * 6e4;
|
|
44
|
+
var XAI_VIDEO_DOWNLOAD_TIMEOUT_MS = 2 * 6e4;
|
|
45
|
+
|
|
46
|
+
export {
|
|
47
|
+
XAI_OAUTH_ISSUER,
|
|
48
|
+
XAI_OAUTH_CLIENT_ID,
|
|
49
|
+
XAI_OAUTH_SCOPES,
|
|
50
|
+
XAI_DEVICE_AUTHORIZATION_URL,
|
|
51
|
+
XAI_TOKEN_URL,
|
|
52
|
+
XAI_USERINFO_URL,
|
|
53
|
+
XAI_DEVICE_CODE_GRANT_TYPE,
|
|
54
|
+
XAI_SUBSCRIPTION_PROXY_BASE_URL,
|
|
55
|
+
XAI_PUBLIC_API_BASE_URL,
|
|
56
|
+
XAI_TOKEN_AUTH_HEADER_VALUE,
|
|
57
|
+
XAI_CLIENT_VERSION,
|
|
58
|
+
XAI_CLIENT_MODE,
|
|
59
|
+
XAI_SUBSCRIPTION_PROVIDER_ID,
|
|
60
|
+
XAI_SUBSCRIPTION_MODEL_ID_PREFIX,
|
|
61
|
+
XAI_SUBSCRIPTION_MODEL_SLUGS,
|
|
62
|
+
XAI_SUBSCRIPTION_MODEL_CONTEXT_WINDOW_TOKENS,
|
|
63
|
+
XAI_SUBSCRIPTION_EFFECTIVE_CONTEXT_PERCENT,
|
|
64
|
+
XAI_SUBSCRIPTION_MODEL_EFFECTIVE_CONTEXT_WINDOW_TOKENS,
|
|
65
|
+
XAI_SUBSCRIPTION_AUTO_COMPACTION_PERCENT,
|
|
66
|
+
XAI_SUBSCRIPTION_MODEL_AUTO_COMPACT_TOKEN_LIMIT,
|
|
67
|
+
XAI_IMAGE_MODEL,
|
|
68
|
+
XAI_VIDEO_MODEL,
|
|
69
|
+
XAI_OAUTH_OPERATION_TIMEOUT_MS,
|
|
70
|
+
XAI_REFRESH_WINDOW_MS,
|
|
71
|
+
XAI_REFRESH_FALLBACK_MS,
|
|
72
|
+
XAI_RESPONSE_SDK_OUTER_TIMEOUT_MS,
|
|
73
|
+
XAI_IMAGE_REQUEST_TIMEOUT_MS,
|
|
74
|
+
XAI_VIDEO_START_TIMEOUT_MS,
|
|
75
|
+
XAI_VIDEO_POLL_REQUEST_TIMEOUT_MS,
|
|
76
|
+
XAI_VIDEO_POLL_INTERVAL_MS,
|
|
77
|
+
XAI_VIDEO_GENERATION_TIMEOUT_MS,
|
|
78
|
+
XAI_VIDEO_DOWNLOAD_TIMEOUT_MS
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=chunk-JEFGIUGN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts"],"sourcesContent":["// Verified against xAI's public OIDC discovery document and Grok Build 1.0.3.\n\nexport const XAI_OAUTH_ISSUER = \"https://auth.x.ai\";\nexport const XAI_OAUTH_CLIENT_ID = \"b1a00492-073a-47ea-816f-4c329264a828\";\nexport const XAI_OAUTH_SCOPES = [\n \"openid\",\n \"profile\",\n \"email\",\n \"offline_access\",\n \"grok-cli:access\",\n \"api:access\",\n] as const;\nexport const XAI_DEVICE_AUTHORIZATION_URL = `${XAI_OAUTH_ISSUER}/oauth2/device/code`;\nexport const XAI_TOKEN_URL = `${XAI_OAUTH_ISSUER}/oauth2/token`;\nexport const XAI_USERINFO_URL = `${XAI_OAUTH_ISSUER}/oauth2/userinfo`;\nexport const XAI_DEVICE_CODE_GRANT_TYPE = \"urn:ietf:params:oauth:grant-type:device_code\";\n\n// Subscription inference goes through the Grok CLI session proxy. The existing\n// xai/* API-key provider continues to use api.x.ai and remains a distinct rail.\nexport const XAI_SUBSCRIPTION_PROXY_BASE_URL = \"https://cli-chat-proxy.grok.com/v1\";\nexport const XAI_PUBLIC_API_BASE_URL = \"https://api.x.ai/v1\";\nexport const XAI_TOKEN_AUTH_HEADER_VALUE = \"xai-grok-cli\";\nexport const XAI_CLIENT_VERSION = \"1.0.3\";\nexport const XAI_CLIENT_MODE = \"opengeni\";\n\nexport const XAI_SUBSCRIPTION_PROVIDER_ID = \"supergrok-subscription\";\nexport const XAI_SUBSCRIPTION_MODEL_ID_PREFIX = \"supergrok/\";\nexport const XAI_SUBSCRIPTION_MODEL_SLUGS = [\"grok-4.6\"] as const;\n\n// Static product limits used by the OpenGeni catalog, matching the Codex seam.\nexport const XAI_SUBSCRIPTION_MODEL_CONTEXT_WINDOW_TOKENS = 500_000;\nexport const XAI_SUBSCRIPTION_EFFECTIVE_CONTEXT_PERCENT = 95;\nexport const XAI_SUBSCRIPTION_MODEL_EFFECTIVE_CONTEXT_WINDOW_TOKENS = Math.floor(\n (XAI_SUBSCRIPTION_MODEL_CONTEXT_WINDOW_TOKENS * XAI_SUBSCRIPTION_EFFECTIVE_CONTEXT_PERCENT) / 100,\n);\nexport const XAI_SUBSCRIPTION_AUTO_COMPACTION_PERCENT = 80;\nexport const XAI_SUBSCRIPTION_MODEL_AUTO_COMPACT_TOKEN_LIMIT = Math.floor(\n (XAI_SUBSCRIPTION_MODEL_CONTEXT_WINDOW_TOKENS * XAI_SUBSCRIPTION_AUTO_COMPACTION_PERCENT) / 100,\n);\n\nexport const XAI_IMAGE_MODEL = \"grok-imagine-image-quality\";\nexport const XAI_VIDEO_MODEL = \"grok-imagine-video-1.5\";\n\nexport const XAI_OAUTH_OPERATION_TIMEOUT_MS = 15_000;\nexport const XAI_REFRESH_WINDOW_MS = 2 * 60_000;\nexport const XAI_REFRESH_FALLBACK_MS = 60 * 60_000;\nexport const XAI_RESPONSE_SDK_OUTER_TIMEOUT_MS = 35 * 60_000;\nexport const XAI_IMAGE_REQUEST_TIMEOUT_MS = 5 * 60_000;\nexport const XAI_VIDEO_START_TIMEOUT_MS = 60_000;\nexport const XAI_VIDEO_POLL_REQUEST_TIMEOUT_MS = 30_000;\nexport const XAI_VIDEO_POLL_INTERVAL_MS = 5_000;\nexport const XAI_VIDEO_GENERATION_TIMEOUT_MS = 5 * 60_000;\nexport const XAI_VIDEO_DOWNLOAD_TIMEOUT_MS = 2 * 60_000;\n"],"mappings":";AAEO,IAAM,mBAAmB;AACzB,IAAM,sBAAsB;AAC5B,IAAM,mBAAmB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AACO,IAAM,+BAA+B,GAAG,gBAAgB;AACxD,IAAM,gBAAgB,GAAG,gBAAgB;AACzC,IAAM,mBAAmB,GAAG,gBAAgB;AAC5C,IAAM,6BAA6B;AAInC,IAAM,kCAAkC;AACxC,IAAM,0BAA0B;AAChC,IAAM,8BAA8B;AACpC,IAAM,qBAAqB;AAC3B,IAAM,kBAAkB;AAExB,IAAM,+BAA+B;AACrC,IAAM,mCAAmC;AACzC,IAAM,+BAA+B,CAAC,UAAU;AAGhD,IAAM,+CAA+C;AACrD,IAAM,6CAA6C;AACnD,IAAM,yDAAyD,KAAK;AAAA,EACxE,+CAA+C,6CAA8C;AAChG;AACO,IAAM,2CAA2C;AACjD,IAAM,kDAAkD,KAAK;AAAA,EACjE,+CAA+C,2CAA4C;AAC9F;AAEO,IAAM,kBAAkB;AACxB,IAAM,kBAAkB;AAExB,IAAM,iCAAiC;AACvC,IAAM,wBAAwB,IAAI;AAClC,IAAM,0BAA0B,KAAK;AACrC,IAAM,oCAAoC,KAAK;AAC/C,IAAM,+BAA+B,IAAI;AACzC,IAAM,6BAA6B;AACnC,IAAM,oCAAoC;AAC1C,IAAM,6BAA6B;AACnC,IAAM,kCAAkC,IAAI;AAC5C,IAAM,gCAAgC,IAAI;","names":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare const XAI_OAUTH_ISSUER = "https://auth.x.ai";
|
|
2
|
+
export declare const XAI_OAUTH_CLIENT_ID = "b1a00492-073a-47ea-816f-4c329264a828";
|
|
3
|
+
export declare const XAI_OAUTH_SCOPES: readonly ["openid", "profile", "email", "offline_access", "grok-cli:access", "api:access"];
|
|
4
|
+
export declare const XAI_DEVICE_AUTHORIZATION_URL = "https://auth.x.ai/oauth2/device/code";
|
|
5
|
+
export declare const XAI_TOKEN_URL = "https://auth.x.ai/oauth2/token";
|
|
6
|
+
export declare const XAI_USERINFO_URL = "https://auth.x.ai/oauth2/userinfo";
|
|
7
|
+
export declare const XAI_DEVICE_CODE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
|
|
8
|
+
export declare const XAI_SUBSCRIPTION_PROXY_BASE_URL = "https://cli-chat-proxy.grok.com/v1";
|
|
9
|
+
export declare const XAI_PUBLIC_API_BASE_URL = "https://api.x.ai/v1";
|
|
10
|
+
export declare const XAI_TOKEN_AUTH_HEADER_VALUE = "xai-grok-cli";
|
|
11
|
+
export declare const XAI_CLIENT_VERSION = "1.0.3";
|
|
12
|
+
export declare const XAI_CLIENT_MODE = "opengeni";
|
|
13
|
+
export declare const XAI_SUBSCRIPTION_PROVIDER_ID = "supergrok-subscription";
|
|
14
|
+
export declare const XAI_SUBSCRIPTION_MODEL_ID_PREFIX = "supergrok/";
|
|
15
|
+
export declare const XAI_SUBSCRIPTION_MODEL_SLUGS: readonly ["grok-4.6"];
|
|
16
|
+
export declare const XAI_SUBSCRIPTION_MODEL_CONTEXT_WINDOW_TOKENS = 500000;
|
|
17
|
+
export declare const XAI_SUBSCRIPTION_EFFECTIVE_CONTEXT_PERCENT = 95;
|
|
18
|
+
export declare const XAI_SUBSCRIPTION_MODEL_EFFECTIVE_CONTEXT_WINDOW_TOKENS: number;
|
|
19
|
+
export declare const XAI_SUBSCRIPTION_AUTO_COMPACTION_PERCENT = 80;
|
|
20
|
+
export declare const XAI_SUBSCRIPTION_MODEL_AUTO_COMPACT_TOKEN_LIMIT: number;
|
|
21
|
+
export declare const XAI_IMAGE_MODEL = "grok-imagine-image-quality";
|
|
22
|
+
export declare const XAI_VIDEO_MODEL = "grok-imagine-video-1.5";
|
|
23
|
+
export declare const XAI_OAUTH_OPERATION_TIMEOUT_MS = 15000;
|
|
24
|
+
export declare const XAI_REFRESH_WINDOW_MS: number;
|
|
25
|
+
export declare const XAI_REFRESH_FALLBACK_MS: number;
|
|
26
|
+
export declare const XAI_RESPONSE_SDK_OUTER_TIMEOUT_MS: number;
|
|
27
|
+
export declare const XAI_IMAGE_REQUEST_TIMEOUT_MS: number;
|
|
28
|
+
export declare const XAI_VIDEO_START_TIMEOUT_MS = 60000;
|
|
29
|
+
export declare const XAI_VIDEO_POLL_REQUEST_TIMEOUT_MS = 30000;
|
|
30
|
+
export declare const XAI_VIDEO_POLL_INTERVAL_MS = 5000;
|
|
31
|
+
export declare const XAI_VIDEO_GENERATION_TIMEOUT_MS: number;
|
|
32
|
+
export declare const XAI_VIDEO_DOWNLOAD_TIMEOUT_MS: number;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
XAI_CLIENT_MODE,
|
|
3
|
+
XAI_CLIENT_VERSION,
|
|
4
|
+
XAI_DEVICE_AUTHORIZATION_URL,
|
|
5
|
+
XAI_DEVICE_CODE_GRANT_TYPE,
|
|
6
|
+
XAI_IMAGE_MODEL,
|
|
7
|
+
XAI_IMAGE_REQUEST_TIMEOUT_MS,
|
|
8
|
+
XAI_OAUTH_CLIENT_ID,
|
|
9
|
+
XAI_OAUTH_ISSUER,
|
|
10
|
+
XAI_OAUTH_OPERATION_TIMEOUT_MS,
|
|
11
|
+
XAI_OAUTH_SCOPES,
|
|
12
|
+
XAI_PUBLIC_API_BASE_URL,
|
|
13
|
+
XAI_REFRESH_FALLBACK_MS,
|
|
14
|
+
XAI_REFRESH_WINDOW_MS,
|
|
15
|
+
XAI_RESPONSE_SDK_OUTER_TIMEOUT_MS,
|
|
16
|
+
XAI_SUBSCRIPTION_AUTO_COMPACTION_PERCENT,
|
|
17
|
+
XAI_SUBSCRIPTION_EFFECTIVE_CONTEXT_PERCENT,
|
|
18
|
+
XAI_SUBSCRIPTION_MODEL_AUTO_COMPACT_TOKEN_LIMIT,
|
|
19
|
+
XAI_SUBSCRIPTION_MODEL_CONTEXT_WINDOW_TOKENS,
|
|
20
|
+
XAI_SUBSCRIPTION_MODEL_EFFECTIVE_CONTEXT_WINDOW_TOKENS,
|
|
21
|
+
XAI_SUBSCRIPTION_MODEL_ID_PREFIX,
|
|
22
|
+
XAI_SUBSCRIPTION_MODEL_SLUGS,
|
|
23
|
+
XAI_SUBSCRIPTION_PROVIDER_ID,
|
|
24
|
+
XAI_SUBSCRIPTION_PROXY_BASE_URL,
|
|
25
|
+
XAI_TOKEN_AUTH_HEADER_VALUE,
|
|
26
|
+
XAI_TOKEN_URL,
|
|
27
|
+
XAI_USERINFO_URL,
|
|
28
|
+
XAI_VIDEO_DOWNLOAD_TIMEOUT_MS,
|
|
29
|
+
XAI_VIDEO_GENERATION_TIMEOUT_MS,
|
|
30
|
+
XAI_VIDEO_MODEL,
|
|
31
|
+
XAI_VIDEO_POLL_INTERVAL_MS,
|
|
32
|
+
XAI_VIDEO_POLL_REQUEST_TIMEOUT_MS,
|
|
33
|
+
XAI_VIDEO_START_TIMEOUT_MS
|
|
34
|
+
} from "./chunk-JEFGIUGN.js";
|
|
35
|
+
export {
|
|
36
|
+
XAI_CLIENT_MODE,
|
|
37
|
+
XAI_CLIENT_VERSION,
|
|
38
|
+
XAI_DEVICE_AUTHORIZATION_URL,
|
|
39
|
+
XAI_DEVICE_CODE_GRANT_TYPE,
|
|
40
|
+
XAI_IMAGE_MODEL,
|
|
41
|
+
XAI_IMAGE_REQUEST_TIMEOUT_MS,
|
|
42
|
+
XAI_OAUTH_CLIENT_ID,
|
|
43
|
+
XAI_OAUTH_ISSUER,
|
|
44
|
+
XAI_OAUTH_OPERATION_TIMEOUT_MS,
|
|
45
|
+
XAI_OAUTH_SCOPES,
|
|
46
|
+
XAI_PUBLIC_API_BASE_URL,
|
|
47
|
+
XAI_REFRESH_FALLBACK_MS,
|
|
48
|
+
XAI_REFRESH_WINDOW_MS,
|
|
49
|
+
XAI_RESPONSE_SDK_OUTER_TIMEOUT_MS,
|
|
50
|
+
XAI_SUBSCRIPTION_AUTO_COMPACTION_PERCENT,
|
|
51
|
+
XAI_SUBSCRIPTION_EFFECTIVE_CONTEXT_PERCENT,
|
|
52
|
+
XAI_SUBSCRIPTION_MODEL_AUTO_COMPACT_TOKEN_LIMIT,
|
|
53
|
+
XAI_SUBSCRIPTION_MODEL_CONTEXT_WINDOW_TOKENS,
|
|
54
|
+
XAI_SUBSCRIPTION_MODEL_EFFECTIVE_CONTEXT_WINDOW_TOKENS,
|
|
55
|
+
XAI_SUBSCRIPTION_MODEL_ID_PREFIX,
|
|
56
|
+
XAI_SUBSCRIPTION_MODEL_SLUGS,
|
|
57
|
+
XAI_SUBSCRIPTION_PROVIDER_ID,
|
|
58
|
+
XAI_SUBSCRIPTION_PROXY_BASE_URL,
|
|
59
|
+
XAI_TOKEN_AUTH_HEADER_VALUE,
|
|
60
|
+
XAI_TOKEN_URL,
|
|
61
|
+
XAI_USERINFO_URL,
|
|
62
|
+
XAI_VIDEO_DOWNLOAD_TIMEOUT_MS,
|
|
63
|
+
XAI_VIDEO_GENERATION_TIMEOUT_MS,
|
|
64
|
+
XAI_VIDEO_MODEL,
|
|
65
|
+
XAI_VIDEO_POLL_INTERVAL_MS,
|
|
66
|
+
XAI_VIDEO_POLL_REQUEST_TIMEOUT_MS,
|
|
67
|
+
XAI_VIDEO_START_TIMEOUT_MS
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type XaiSubscriptionErrorKind = "invalid_response" | "not_enabled" | "authorization_denied" | "device_code_expired" | "relogin_required" | "transient" | "provider_rejected" | "timeout";
|
|
2
|
+
export declare class XaiSubscriptionError extends Error {
|
|
3
|
+
readonly kind: XaiSubscriptionErrorKind;
|
|
4
|
+
readonly status?: number | undefined;
|
|
5
|
+
constructor(kind: XaiSubscriptionErrorKind, message: string, status?: number | undefined);
|
|
6
|
+
}
|
|
7
|
+
export declare class XaiSubscriptionReloginRequired extends XaiSubscriptionError {
|
|
8
|
+
constructor(message?: string);
|
|
9
|
+
}
|
|
10
|
+
export declare class XaiSubscriptionTransientError extends XaiSubscriptionError {
|
|
11
|
+
constructor(message: string, status?: number);
|
|
12
|
+
}
|
package/dist/fetch.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type XaiFetchLike = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
2
|
+
export declare const XAI_SUBSCRIPTION_TRANSPORT_ERROR_HEADER = "x-opengeni-xai-subscription-transport-error";
|
|
3
|
+
export declare const XAI_SUBSCRIPTION_REQUEST_BODY_NORMALIZED_HEADER = "x-opengeni-xai-subscription-body-normalized";
|
|
4
|
+
export declare const XAI_SUBSCRIPTION_REQUEST_MODEL_HEADER = "x-opengeni-xai-subscription-model";
|
|
5
|
+
export declare const XAI_SUBSCRIPTION_REQUEST_ID_HEADER = "x-opengeni-xai-subscription-request-id";
|
|
6
|
+
export declare function xaiSubscriptionFetch(base: XaiFetchLike): XaiFetchLike;
|
|
7
|
+
export declare function isXaiSubscriptionTransportError(error: unknown): boolean;
|
package/dist/images.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { XaiFetchLike } from "./fetch.js";
|
|
2
|
+
import type { XaiSubscriptionTokenSnapshot } from "./request-context.js";
|
|
3
|
+
export type XaiImageReference = Readonly<{
|
|
4
|
+
mediaType: "image/png" | "image/jpeg" | "image/webp";
|
|
5
|
+
bytes: Uint8Array;
|
|
6
|
+
}>;
|
|
7
|
+
export type XaiGeneratedImage = {
|
|
8
|
+
bytes: Uint8Array;
|
|
9
|
+
declaredMediaType: "image/png" | "image/jpeg" | "image/webp";
|
|
10
|
+
};
|
|
11
|
+
export declare function generateXaiSubscriptionImage(input: {
|
|
12
|
+
prompt: string;
|
|
13
|
+
aspectRatio?: string;
|
|
14
|
+
references?: readonly XaiImageReference[];
|
|
15
|
+
sessionId?: string;
|
|
16
|
+
getToken: () => Promise<XaiSubscriptionTokenSnapshot>;
|
|
17
|
+
refresh: () => Promise<XaiSubscriptionTokenSnapshot>;
|
|
18
|
+
abortSignal?: AbortSignal;
|
|
19
|
+
fetch?: XaiFetchLike;
|
|
20
|
+
requestTimeoutMs?: number;
|
|
21
|
+
baseUrl?: string;
|
|
22
|
+
}): Promise<XaiGeneratedImage>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "./constants.js";
|
|
2
|
+
export * from "./errors.js";
|
|
3
|
+
export * from "./bounded-operation.js";
|
|
4
|
+
export * from "./oauth.js";
|
|
5
|
+
export * from "./request-context.js";
|
|
6
|
+
export * from "./normalize.js";
|
|
7
|
+
export * from "./fetch.js";
|
|
8
|
+
export * from "./proxy.js";
|
|
9
|
+
export * from "./quota.js";
|
|
10
|
+
export * from "./models.js";
|
|
11
|
+
export * from "./images.js";
|
|
12
|
+
export * from "./video.js";
|