@omnicross/subscriptions 0.3.0 → 0.4.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/dist/chunk-L77HJY6V.js +1109 -0
- package/dist/chunk-QKWL53TJ.cjs +1109 -0
- package/dist/index.cjs +207 -63
- package/dist/index.d.cts +75 -2
- package/dist/index.d.ts +75 -2
- package/dist/index.js +157 -13
- package/dist/oauth.cjs +12 -2
- package/dist/oauth.d.cts +411 -1
- package/dist/oauth.d.ts +411 -1
- package/dist/oauth.js +13 -3
- package/package.json +3 -3
- package/dist/chunk-4HYDPKHR.js +0 -394
- package/dist/chunk-UXUMAXZJ.cjs +0 -394
package/dist/index.cjs
CHANGED
|
@@ -2,7 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
var _chunkQKWL53TJcjs = require('./chunk-QKWL53TJ.cjs');
|
|
6
17
|
|
|
7
18
|
|
|
8
19
|
|
|
@@ -125,13 +136,19 @@ var ACCOUNTS_KEY = {
|
|
|
125
136
|
claude: "claudeAccounts",
|
|
126
137
|
codex: "codexAccounts",
|
|
127
138
|
gemini: "geminiAccounts",
|
|
128
|
-
opencodego: "opencodegoAccounts"
|
|
139
|
+
opencodego: "opencodegoAccounts",
|
|
140
|
+
kimi: "kimiAccounts",
|
|
141
|
+
grok: "grokAccounts",
|
|
142
|
+
copilot: "copilotAccounts"
|
|
129
143
|
};
|
|
130
144
|
var ACTIVE_KEY = {
|
|
131
145
|
claude: "activeClaudeAccountId",
|
|
132
146
|
codex: "activeCodexAccountId",
|
|
133
147
|
gemini: "activeGeminiAccountId",
|
|
134
|
-
opencodego: "activeOpencodegoAccountId"
|
|
148
|
+
opencodego: "activeOpencodegoAccountId",
|
|
149
|
+
kimi: "activeKimiAccountId",
|
|
150
|
+
grok: "activeGrokAccountId",
|
|
151
|
+
copilot: "activeCopilotAccountId"
|
|
135
152
|
};
|
|
136
153
|
function gateSchedulable(accounts, providerId, health, now, resolvedModel, supportedModelsById) {
|
|
137
154
|
if (!health && !resolvedModel || accounts.length < 2) return accounts;
|
|
@@ -421,13 +438,20 @@ var OAuthBearerAuthStrategy = (_class2 = class {
|
|
|
421
438
|
return;
|
|
422
439
|
}
|
|
423
440
|
headers["Authorization"] = `Bearer ${token}`;
|
|
441
|
+
if (this.providerId === "kimi") {
|
|
442
|
+
const deviceId = await this.resolveKimiDeviceId(_optionalChain([hints, 'optionalAccess', _29 => _29.sessionKey]));
|
|
443
|
+
Object.assign(headers, _chunkQKWL53TJcjs.kimiFingerprintHeaders.call(void 0, deviceId));
|
|
444
|
+
}
|
|
445
|
+
if (this.providerId === "copilot") {
|
|
446
|
+
Object.assign(headers, _chunkQKWL53TJcjs.COPILOT_API_HEADERS);
|
|
447
|
+
}
|
|
424
448
|
}
|
|
425
449
|
async onUnauthorized(sessionKey) {
|
|
426
450
|
const byId = await refreshSelectedAccount(this.selector, this.tokens, this.mutex, this.providerId, sessionKey);
|
|
427
451
|
if (byId !== null) return byId;
|
|
428
452
|
return this.mutex.run(`${this.providerId}:refresh`, async () => {
|
|
429
453
|
try {
|
|
430
|
-
return this.
|
|
454
|
+
return this.refreshActive();
|
|
431
455
|
} catch (err) {
|
|
432
456
|
console.warn(`[OAuthBearerAuthStrategy] ${this.providerId} refresh failed:`, err);
|
|
433
457
|
return false;
|
|
@@ -436,8 +460,8 @@ var OAuthBearerAuthStrategy = (_class2 = class {
|
|
|
436
460
|
}
|
|
437
461
|
async describeStatus() {
|
|
438
462
|
const config = await this.tokens.getFullConfig();
|
|
439
|
-
const entry = this.
|
|
440
|
-
if (!_optionalChain([entry, 'optionalAccess',
|
|
463
|
+
const entry = this.tokenBlock(config);
|
|
464
|
+
if (!_optionalChain([entry, 'optionalAccess', _30 => _30.accessToken])) {
|
|
441
465
|
return { providerId: this.providerId, ok: false, reason: "missing-credential" };
|
|
442
466
|
}
|
|
443
467
|
if (entry.status === "expired") {
|
|
@@ -453,22 +477,61 @@ var OAuthBearerAuthStrategy = (_class2 = class {
|
|
|
453
477
|
/** Read the current token, refreshing in-line if it's within the lead window. */
|
|
454
478
|
async resolveAccessToken() {
|
|
455
479
|
const config = await this.tokens.getFullConfig();
|
|
456
|
-
const entry = this.
|
|
457
|
-
if (!_optionalChain([entry, 'optionalAccess',
|
|
480
|
+
const entry = this.tokenBlock(config);
|
|
481
|
+
if (!_optionalChain([entry, 'optionalAccess', _31 => _31.accessToken])) return null;
|
|
458
482
|
const expiresAtMs = entry.expiresAt ? new Date(entry.expiresAt).getTime() : 0;
|
|
459
483
|
const expiringSoon = expiresAtMs > 0 && Date.now() >= expiresAtMs - REFRESH_LEAD_MS;
|
|
460
484
|
if (expiringSoon && entry.refreshToken) {
|
|
461
485
|
const refreshed = await this.mutex.run(`${this.providerId}:refresh`, async () => {
|
|
462
|
-
return this.
|
|
486
|
+
return this.refreshActive();
|
|
463
487
|
});
|
|
464
488
|
if (!refreshed) return null;
|
|
465
489
|
const fresh = await this.tokens.getFullConfig();
|
|
466
|
-
|
|
467
|
-
return _nullishCoalesce(_optionalChain([freshEntry, 'optionalAccess', _31 => _31.accessToken]), () => ( null));
|
|
490
|
+
return _nullishCoalesce(_optionalChain([this, 'access', _32 => _32.tokenBlock, 'call', _33 => _33(fresh), 'optionalAccess', _34 => _34.accessToken]), () => ( null));
|
|
468
491
|
}
|
|
469
492
|
if (entry.status === "expired") return null;
|
|
470
493
|
return entry.accessToken;
|
|
471
494
|
}
|
|
495
|
+
/** The active account's refresh, dispatched per provider. */
|
|
496
|
+
refreshActive() {
|
|
497
|
+
switch (this.providerId) {
|
|
498
|
+
case "codex":
|
|
499
|
+
return this.tokens.refreshCodexToken();
|
|
500
|
+
case "gemini":
|
|
501
|
+
return this.tokens.refreshGeminiToken();
|
|
502
|
+
case "kimi":
|
|
503
|
+
return this.tokens.refreshKimiToken ? this.tokens.refreshKimiToken() : Promise.resolve(false);
|
|
504
|
+
case "grok":
|
|
505
|
+
return this.tokens.refreshGrokToken ? this.tokens.refreshGrokToken() : Promise.resolve(false);
|
|
506
|
+
case "copilot":
|
|
507
|
+
return this.tokens.refreshCopilotToken ? this.tokens.refreshCopilotToken() : Promise.resolve(false);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
tokenBlock(config) {
|
|
511
|
+
switch (this.providerId) {
|
|
512
|
+
case "codex":
|
|
513
|
+
return config.codex;
|
|
514
|
+
case "gemini":
|
|
515
|
+
return config.gemini;
|
|
516
|
+
case "kimi":
|
|
517
|
+
return config.kimi;
|
|
518
|
+
case "grok":
|
|
519
|
+
return config.grok;
|
|
520
|
+
case "copilot":
|
|
521
|
+
return config.copilot;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Best-effort device id for the fingerprint header. Selection already ran in
|
|
526
|
+
* `applyHeaders`; rather than re-deriving it, read the active block's id (a
|
|
527
|
+
* pool-served non-active account momentarily reports the active id — the
|
|
528
|
+
* header is per-INSTALL identity, so this is cosmetic, not auth).
|
|
529
|
+
*/
|
|
530
|
+
async resolveKimiDeviceId(_sessionKey) {
|
|
531
|
+
void _sessionKey;
|
|
532
|
+
const config = await this.tokens.getFullConfig();
|
|
533
|
+
return _nullishCoalesce(_optionalChain([config, 'access', _35 => _35.kimi, 'optionalAccess', _36 => _36.deviceId]), () => ( _optionalChain([config, 'access', _37 => _37.kimiAccounts, 'optionalAccess', _38 => _38[0], 'optionalAccess', _39 => _39.tokens, 'access', _40 => _40.deviceId])));
|
|
534
|
+
}
|
|
472
535
|
}, _class2);
|
|
473
536
|
|
|
474
537
|
// src/auth/PassThroughAuthStrategy.ts
|
|
@@ -490,15 +553,15 @@ var PassThroughAuthStrategy = (_class3 = class {
|
|
|
490
553
|
this.selector,
|
|
491
554
|
this.tokens,
|
|
492
555
|
"claude",
|
|
493
|
-
_optionalChain([hints, 'optionalAccess',
|
|
556
|
+
_optionalChain([hints, 'optionalAccess', _41 => _41.sessionKey]),
|
|
494
557
|
() => this.tokens.getValidClaudeAccessToken(),
|
|
495
558
|
{
|
|
496
559
|
health: this.health,
|
|
497
|
-
reportSelection: _optionalChain([hints, 'optionalAccess',
|
|
498
|
-
resolvedModel: _optionalChain([hints, 'optionalAccess',
|
|
499
|
-
preferredAccountId: _optionalChain([hints, 'optionalAccess',
|
|
500
|
-
preferredAccountGroup: _optionalChain([hints, 'optionalAccess',
|
|
501
|
-
boundAccountFallbackPolicy: _optionalChain([hints, 'optionalAccess',
|
|
560
|
+
reportSelection: _optionalChain([hints, 'optionalAccess', _42 => _42.reportSelection]),
|
|
561
|
+
resolvedModel: _optionalChain([hints, 'optionalAccess', _43 => _43.resolvedModel]),
|
|
562
|
+
preferredAccountId: _optionalChain([hints, 'optionalAccess', _44 => _44.preferredAccountId]),
|
|
563
|
+
preferredAccountGroup: _optionalChain([hints, 'optionalAccess', _45 => _45.preferredAccountGroup]),
|
|
564
|
+
boundAccountFallbackPolicy: _optionalChain([hints, 'optionalAccess', _46 => _46.boundAccountFallbackPolicy])
|
|
502
565
|
}
|
|
503
566
|
);
|
|
504
567
|
if (!token) return;
|
|
@@ -519,7 +582,7 @@ var PassThroughAuthStrategy = (_class3 = class {
|
|
|
519
582
|
async describeStatus() {
|
|
520
583
|
const config = await this.tokens.getFullConfig();
|
|
521
584
|
const claude = config.claude;
|
|
522
|
-
if (!_optionalChain([claude, 'optionalAccess',
|
|
585
|
+
if (!_optionalChain([claude, 'optionalAccess', _47 => _47.accessToken])) {
|
|
523
586
|
return { providerId: "claude", ok: false, reason: "missing-credential" };
|
|
524
587
|
}
|
|
525
588
|
if (claude.status === "expired") {
|
|
@@ -575,22 +638,22 @@ var StaticBearerAuthStrategy = (_class5 = class {
|
|
|
575
638
|
this.selector,
|
|
576
639
|
this.tokens,
|
|
577
640
|
"opencodego",
|
|
578
|
-
_optionalChain([hints, 'optionalAccess',
|
|
641
|
+
_optionalChain([hints, 'optionalAccess', _48 => _48.sessionKey]),
|
|
579
642
|
() => this.tokens.getValidOpenCodeGoApiKey(),
|
|
580
643
|
{
|
|
581
644
|
health: this.health,
|
|
582
|
-
reportSelection: _optionalChain([hints, 'optionalAccess',
|
|
583
|
-
resolvedModel: _optionalChain([hints, 'optionalAccess',
|
|
584
|
-
preferredAccountId: _optionalChain([hints, 'optionalAccess',
|
|
585
|
-
preferredAccountGroup: _optionalChain([hints, 'optionalAccess',
|
|
586
|
-
boundAccountFallbackPolicy: _optionalChain([hints, 'optionalAccess',
|
|
645
|
+
reportSelection: _optionalChain([hints, 'optionalAccess', _49 => _49.reportSelection]),
|
|
646
|
+
resolvedModel: _optionalChain([hints, 'optionalAccess', _50 => _50.resolvedModel]),
|
|
647
|
+
preferredAccountId: _optionalChain([hints, 'optionalAccess', _51 => _51.preferredAccountId]),
|
|
648
|
+
preferredAccountGroup: _optionalChain([hints, 'optionalAccess', _52 => _52.preferredAccountGroup]),
|
|
649
|
+
boundAccountFallbackPolicy: _optionalChain([hints, 'optionalAccess', _53 => _53.boundAccountFallbackPolicy])
|
|
587
650
|
}
|
|
588
651
|
);
|
|
589
652
|
if (!key) {
|
|
590
653
|
return;
|
|
591
654
|
}
|
|
592
655
|
headers["Authorization"] = `Bearer ${key}`;
|
|
593
|
-
if (_optionalChain([hints, 'optionalAccess',
|
|
656
|
+
if (_optionalChain([hints, 'optionalAccess', _54 => _54.upstreamUrl, 'optionalAccess', _55 => _55.includes, 'call', _56 => _56(ANTHROPIC_SHAPE_PATH)])) {
|
|
594
657
|
headers["x-api-key"] = key;
|
|
595
658
|
}
|
|
596
659
|
}
|
|
@@ -600,7 +663,7 @@ var StaticBearerAuthStrategy = (_class5 = class {
|
|
|
600
663
|
async describeStatus() {
|
|
601
664
|
const config = await this.tokens.getFullConfig();
|
|
602
665
|
const oc = config.opencodego;
|
|
603
|
-
if (!_optionalChain([oc, 'optionalAccess',
|
|
666
|
+
if (!_optionalChain([oc, 'optionalAccess', _57 => _57.apiKey])) {
|
|
604
667
|
return { providerId: "opencodego", ok: false, reason: "missing-credential" };
|
|
605
668
|
}
|
|
606
669
|
if (oc.status === "error") {
|
|
@@ -615,7 +678,10 @@ var DISPLAY_NAMES = {
|
|
|
615
678
|
claude: "Claude (Anthropic OAuth)",
|
|
616
679
|
codex: "Codex (ChatGPT OAuth)",
|
|
617
680
|
gemini: "Gemini (Google OAuth)",
|
|
618
|
-
opencodego: "OpenCodeGo (Bearer key)"
|
|
681
|
+
opencodego: "OpenCodeGo (Bearer key)",
|
|
682
|
+
kimi: "Kimi Code (Moonshot OAuth)",
|
|
683
|
+
grok: "Grok (xAI SuperGrok OAuth)",
|
|
684
|
+
copilot: "Copilot (GitHub OAuth)"
|
|
619
685
|
};
|
|
620
686
|
var SubscriptionAccountService = (_class6 = class {
|
|
621
687
|
__init10() {this.mutex = new RefreshMutex()}
|
|
@@ -629,7 +695,10 @@ var SubscriptionAccountService = (_class6 = class {
|
|
|
629
695
|
["claude", new PassThroughAuthStrategy(tokens, this.mutex, this.selector, health)],
|
|
630
696
|
["codex", new OAuthBearerAuthStrategy("codex", tokens, this.mutex, this.selector, health)],
|
|
631
697
|
["gemini", new OAuthBearerAuthStrategy("gemini", tokens, this.mutex, this.selector, health)],
|
|
632
|
-
["opencodego", new StaticBearerAuthStrategy(tokens, this.selector, health)]
|
|
698
|
+
["opencodego", new StaticBearerAuthStrategy(tokens, this.selector, health)],
|
|
699
|
+
["kimi", new OAuthBearerAuthStrategy("kimi", tokens, this.mutex, this.selector, health)],
|
|
700
|
+
["grok", new OAuthBearerAuthStrategy("grok", tokens, this.mutex, this.selector, health)],
|
|
701
|
+
["copilot", new OAuthBearerAuthStrategy("copilot", tokens, this.mutex, this.selector, health)]
|
|
633
702
|
]);
|
|
634
703
|
}
|
|
635
704
|
/** Returns the strategy bound to a subscription provider, or `null` for unknown ids. */
|
|
@@ -958,11 +1027,11 @@ function resolveOpenCodeGoShape(entry) {
|
|
|
958
1027
|
function resolveOpenCodeGoHalf(modelId, config) {
|
|
959
1028
|
if (!config) return "go";
|
|
960
1029
|
for (const entry of Object.values(_nullishCoalesce(config.modelMap, () => ( {})))) {
|
|
961
|
-
if (_optionalChain([entry, 'optionalAccess',
|
|
1030
|
+
if (_optionalChain([entry, 'optionalAccess', _58 => _58.modelId]) === modelId) return _nullishCoalesce(entry.provider, () => ( "go"));
|
|
962
1031
|
}
|
|
963
1032
|
for (const list of Object.values(_nullishCoalesce(config.fallbacks, () => ( {})))) {
|
|
964
1033
|
for (const entry of _nullishCoalesce(list, () => ( []))) {
|
|
965
|
-
if (_optionalChain([entry, 'optionalAccess',
|
|
1034
|
+
if (_optionalChain([entry, 'optionalAccess', _59 => _59.modelId]) === modelId) return _nullishCoalesce(entry.provider, () => ( "go"));
|
|
966
1035
|
}
|
|
967
1036
|
}
|
|
968
1037
|
return "go";
|
|
@@ -1039,7 +1108,7 @@ function hasBackgroundPattern(loweredSlices) {
|
|
|
1039
1108
|
return containsAny(loweredSlices, BACKGROUND_KEYWORDS);
|
|
1040
1109
|
}
|
|
1041
1110
|
function resolveOpenCodeGoScenario(summary, config) {
|
|
1042
|
-
const longContextThreshold = _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
1111
|
+
const longContextThreshold = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _60 => _60.modelMap, 'optionalAccess', _61 => _61.long_context, 'optionalAccess', _62 => _62.contextThreshold]), () => ( DEFAULT_OPENCODEGO_LONG_CONTEXT_THRESHOLD));
|
|
1043
1112
|
if (summary.estimatedInputTokens >= longContextThreshold) {
|
|
1044
1113
|
return "long_context";
|
|
1045
1114
|
}
|
|
@@ -1079,7 +1148,10 @@ var SubscriptionProviderRegistry = (_class9 = class {
|
|
|
1079
1148
|
const codex = this.accounts.getStrategy("codex");
|
|
1080
1149
|
const gemini = this.accounts.getStrategy("gemini");
|
|
1081
1150
|
const opencodego = this.accounts.getStrategy("opencodego");
|
|
1082
|
-
|
|
1151
|
+
const kimi = this.accounts.getStrategy("kimi");
|
|
1152
|
+
const grok = this.accounts.getStrategy("grok");
|
|
1153
|
+
const copilot = this.accounts.getStrategy("copilot");
|
|
1154
|
+
if (!claude || !codex || !gemini || !opencodego || !kimi || !grok || !copilot) {
|
|
1083
1155
|
throw new Error("[SubscriptionProviderRegistry] Missing strategy in SubscriptionAccountService");
|
|
1084
1156
|
}
|
|
1085
1157
|
this.profiles = /* @__PURE__ */ new Map([
|
|
@@ -1169,7 +1241,7 @@ var SubscriptionProviderRegistry = (_class9 = class {
|
|
|
1169
1241
|
resolveUpstreamUrl: (model, config) => {
|
|
1170
1242
|
const oc = config;
|
|
1171
1243
|
const { half, shape } = resolveOpenCodeGoTarget(model, oc);
|
|
1172
|
-
const override = half === "zen" ? _optionalChain([oc, 'optionalAccess',
|
|
1244
|
+
const override = half === "zen" ? _optionalChain([oc, 'optionalAccess', _63 => _63.zenBaseUrl]) : _optionalChain([oc, 'optionalAccess', _64 => _64.baseUrl]);
|
|
1173
1245
|
return buildOpenCodeGoUrl(half, shape, override);
|
|
1174
1246
|
},
|
|
1175
1247
|
// zen seam (Decision 3): vary the provider transformer chain by resolved
|
|
@@ -1187,7 +1259,7 @@ var SubscriptionProviderRegistry = (_class9 = class {
|
|
|
1187
1259
|
modelTransformerNames: [],
|
|
1188
1260
|
modelMapper: (sdkModel, summary, config) => {
|
|
1189
1261
|
const scenario = resolveOpenCodeGoScenario(summary, config);
|
|
1190
|
-
const entry = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
1262
|
+
const entry = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([config, 'optionalAccess', _65 => _65.modelMap, 'optionalAccess', _66 => _66[scenario]]), () => ( _optionalChain([config, 'optionalAccess', _67 => _67.modelMap, 'optionalAccess', _68 => _68.default]))), () => ( DEFAULT_OPENCODEGO_MODEL_MAP[scenario])), () => ( DEFAULT_OPENCODEGO_MODEL_MAP.default));
|
|
1191
1263
|
if (!entry) {
|
|
1192
1264
|
return { resolvedModel: sdkModel, scenario };
|
|
1193
1265
|
}
|
|
@@ -1205,7 +1277,7 @@ var SubscriptionProviderRegistry = (_class9 = class {
|
|
|
1205
1277
|
// wedge permanently in half-open). When NO circuit is open this returns
|
|
1206
1278
|
// the same first non-attempted entry as the prior `!attempted` filter.
|
|
1207
1279
|
nextFallback: (scenario, attempted, config) => {
|
|
1208
|
-
const list = _nullishCoalesce(_nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
1280
|
+
const list = _nullishCoalesce(_nullishCoalesce(_optionalChain([config, 'optionalAccess', _69 => _69.fallbacks, 'optionalAccess', _70 => _70[scenario]]), () => ( DEFAULT_OPENCODEGO_FALLBACKS[scenario])), () => ( []));
|
|
1209
1281
|
for (const entry of list) {
|
|
1210
1282
|
if (attempted.includes(entry.modelId)) continue;
|
|
1211
1283
|
if (this.breaker.allowRequest(entry.modelId)) return entry;
|
|
@@ -1221,6 +1293,67 @@ var SubscriptionProviderRegistry = (_class9 = class {
|
|
|
1221
1293
|
// profile sets it — claude / codex / gemini leave it UNSET (no-op).
|
|
1222
1294
|
recordModelOutcome: (modelId, ok) => ok ? this.breaker.recordSuccess(modelId) : this.breaker.recordFailure(modelId)
|
|
1223
1295
|
}
|
|
1296
|
+
],
|
|
1297
|
+
[
|
|
1298
|
+
"kimi",
|
|
1299
|
+
{
|
|
1300
|
+
providerId: "kimi",
|
|
1301
|
+
displayName: "Kimi Code (Moonshot OAuth)",
|
|
1302
|
+
authStrategy: kimi,
|
|
1303
|
+
mode: "transformer",
|
|
1304
|
+
// Kimi Code's subscription surface speaks standard Anthropic Messages
|
|
1305
|
+
// at `api.kimi.com/coding/v1/messages` (plus an OpenAI chat face on
|
|
1306
|
+
// /chat/completions that a BYO kimi row already covers). The messages
|
|
1307
|
+
// URL ending in `/v1/messages` makes the core plan builder treat it as
|
|
1308
|
+
// same-format — the SDK's Anthropic body relays verbatim, with the
|
|
1309
|
+
// OAuth bearer + X-Msh-* fingerprint headers injected by the strategy.
|
|
1310
|
+
resolveUpstreamUrl: () => "https://api.kimi.com/coding/v1/messages",
|
|
1311
|
+
// Route-to only (Responses/Chat ingress): Unified → Anthropic Messages.
|
|
1312
|
+
providerTransformerNames: ["anthropic"],
|
|
1313
|
+
modelTransformerNames: []
|
|
1314
|
+
}
|
|
1315
|
+
],
|
|
1316
|
+
[
|
|
1317
|
+
"grok",
|
|
1318
|
+
{
|
|
1319
|
+
providerId: "grok",
|
|
1320
|
+
displayName: "Grok (xAI SuperGrok OAuth)",
|
|
1321
|
+
authStrategy: grok,
|
|
1322
|
+
mode: "transformer",
|
|
1323
|
+
// SuperGrok's subscription surface speaks the OpenAI Responses API at
|
|
1324
|
+
// `api.x.ai/v1/responses` with the OAuth access token as Bearer (the
|
|
1325
|
+
// same token shape the paid API-key product uses on this endpoint).
|
|
1326
|
+
// Mirrors the codex profile: Unified → Responses via the
|
|
1327
|
+
// `openai-response` encoder; effort negotiation is capability-driven
|
|
1328
|
+
// (the omit-effort grok models carry `thinkingLevels: ['none']` in the
|
|
1329
|
+
// canonical registry, so `reasoning.effort` is never sent to them).
|
|
1330
|
+
resolveUpstreamUrl: () => "https://api.x.ai/v1/responses",
|
|
1331
|
+
providerTransformerNames: ["openai-response"],
|
|
1332
|
+
modelTransformerNames: []
|
|
1333
|
+
}
|
|
1334
|
+
],
|
|
1335
|
+
[
|
|
1336
|
+
"copilot",
|
|
1337
|
+
{
|
|
1338
|
+
providerId: "copilot",
|
|
1339
|
+
displayName: "Copilot (GitHub OAuth)",
|
|
1340
|
+
authStrategy: copilot,
|
|
1341
|
+
mode: "transformer",
|
|
1342
|
+
// GitHub Copilot serves THREE wires on ONE host, per model (the
|
|
1343
|
+
// opencodego shape-seam pattern): the Claude family rides
|
|
1344
|
+
// anthropic-messages at `/v1/messages` (same-format verbatim relay
|
|
1345
|
+
// for Anthropic-shape clients), the GPT/Grok/mai-code families ride
|
|
1346
|
+
// Responses at `/v1/responses`, and the Gemini/Kimi/raptor families
|
|
1347
|
+
// ride chat-completions at `/v1/chat/completions`. The base honors
|
|
1348
|
+
// the account's discovered `apiEndpoint` (or GHE domain) via the
|
|
1349
|
+
// threaded config, defaulting to api.githubcopilot.com. The identity
|
|
1350
|
+
// header set (incl. X-GitHub-Api-Version, which unlocks long-context
|
|
1351
|
+
// tiers) is injected by the auth strategy.
|
|
1352
|
+
resolveUpstreamUrl: (model, config) => `${_chunkQKWL53TJcjs.copilotBaseUrl.call(void 0, config)}${_chunkQKWL53TJcjs.copilotPathFor.call(void 0, _chunkQKWL53TJcjs.copilotWireFor.call(void 0, model))}`,
|
|
1353
|
+
resolveProviderTransformerNames: (model) => _chunkQKWL53TJcjs.copilotTransformerNamesForWire.call(void 0, _chunkQKWL53TJcjs.copilotWireFor.call(void 0, model)),
|
|
1354
|
+
providerTransformerNames: ["openai-response"],
|
|
1355
|
+
modelTransformerNames: []
|
|
1356
|
+
}
|
|
1224
1357
|
]
|
|
1225
1358
|
]);
|
|
1226
1359
|
}
|
|
@@ -1308,7 +1441,7 @@ var SubscriptionDispatcher = class {
|
|
|
1308
1441
|
scenario = mapped.scenario;
|
|
1309
1442
|
req.anthropicBody.model = resolvedModel;
|
|
1310
1443
|
}
|
|
1311
|
-
const upstreamUrl = _optionalChain([this, 'access',
|
|
1444
|
+
const upstreamUrl = _optionalChain([this, 'access', _71 => _71.profile, 'access', _72 => _72.resolveUpstreamUrl, 'optionalCall', _73 => _73(resolvedModel, ocConfig)]);
|
|
1312
1445
|
if (!upstreamUrl) {
|
|
1313
1446
|
throw new Error(`[SubscriptionDispatcher] profile=${this.profile.providerId} missing resolveUpstreamUrl`);
|
|
1314
1447
|
}
|
|
@@ -1340,7 +1473,7 @@ var SubscriptionDispatcher = class {
|
|
|
1340
1473
|
);
|
|
1341
1474
|
try {
|
|
1342
1475
|
const upstream = await this.hooks.fetchWithRetry(upstreamUrl, headers, req.anthropicBody, currentModel);
|
|
1343
|
-
_optionalChain([this, 'access',
|
|
1476
|
+
_optionalChain([this, 'access', _74 => _74.profile, 'access', _75 => _75.recordModelOutcome, 'optionalCall', _76 => _76(currentModel, true)]);
|
|
1344
1477
|
this.markHealth(usedAccountId, 200);
|
|
1345
1478
|
await this.hooks.writeProxyResponse(req.res, upstream, req.isStream, req.reqId);
|
|
1346
1479
|
return;
|
|
@@ -1349,7 +1482,7 @@ var SubscriptionDispatcher = class {
|
|
|
1349
1482
|
if (handled.retryOnce) {
|
|
1350
1483
|
try {
|
|
1351
1484
|
const upstream = await this.hooks.fetchWithRetry(upstreamUrl, handled.headers, req.anthropicBody, currentModel);
|
|
1352
|
-
_optionalChain([this, 'access',
|
|
1485
|
+
_optionalChain([this, 'access', _77 => _77.profile, 'access', _78 => _78.recordModelOutcome, 'optionalCall', _79 => _79(currentModel, true)]);
|
|
1353
1486
|
this.markHealth(usedAccountId, 200);
|
|
1354
1487
|
await this.hooks.writeProxyResponse(req.res, upstream, req.isStream, req.reqId);
|
|
1355
1488
|
return;
|
|
@@ -1359,10 +1492,10 @@ var SubscriptionDispatcher = class {
|
|
|
1359
1492
|
}
|
|
1360
1493
|
}
|
|
1361
1494
|
if (caughtErrorBreakerOutcome(err) === "failure") {
|
|
1362
|
-
_optionalChain([this, 'access',
|
|
1495
|
+
_optionalChain([this, 'access', _80 => _80.profile, 'access', _81 => _81.recordModelOutcome, 'optionalCall', _82 => _82(currentModel, false)]);
|
|
1363
1496
|
}
|
|
1364
1497
|
this.markHealth(usedAccountId, errStatus(err), err);
|
|
1365
|
-
const next = _optionalChain([this, 'access',
|
|
1498
|
+
const next = _optionalChain([this, 'access', _83 => _83.profile, 'access', _84 => _84.nextFallback, 'optionalCall', _85 => _85(scenario, attempted, ocConfig)]);
|
|
1366
1499
|
if (!next || attempted.length >= MAX_FALLBACK_ATTEMPTS_LOCAL) {
|
|
1367
1500
|
throw err;
|
|
1368
1501
|
}
|
|
@@ -1376,7 +1509,7 @@ var SubscriptionDispatcher = class {
|
|
|
1376
1509
|
}
|
|
1377
1510
|
/** Standard subscription transformer chain — Codex/Gemini/OpenCodeGo OpenAI-shape. */
|
|
1378
1511
|
async dispatchTransformerChain(req, upstreamUrl, resolvedModel, scenario, ocConfig, sessionKey) {
|
|
1379
|
-
const providerNames = _nullishCoalesce(_optionalChain([this, 'access',
|
|
1512
|
+
const providerNames = _nullishCoalesce(_optionalChain([this, 'access', _86 => _86.profile, 'access', _87 => _87.resolveProviderTransformerNames, 'optionalCall', _88 => _88(resolvedModel, ocConfig)]), () => ( this.profile.providerTransformerNames));
|
|
1380
1513
|
const providerTransformers = this.resolveTransformers(providerNames);
|
|
1381
1514
|
const modelTransformers = this.resolveTransformers(this.profile.modelTransformerNames);
|
|
1382
1515
|
const transformerProvider = {
|
|
@@ -1417,7 +1550,7 @@ var SubscriptionDispatcher = class {
|
|
|
1417
1550
|
);
|
|
1418
1551
|
try {
|
|
1419
1552
|
const upstream = await this.hooks.fetchWithRetry(fetchUrl, headers, requestBody, currentModel);
|
|
1420
|
-
_optionalChain([this, 'access',
|
|
1553
|
+
_optionalChain([this, 'access', _89 => _89.profile, 'access', _90 => _90.recordModelOutcome, 'optionalCall', _91 => _91(currentModel, true)]);
|
|
1421
1554
|
this.markHealth(usedAccountId, 200);
|
|
1422
1555
|
const finalResponse = await this.hooks.executor.executeResponseChain(
|
|
1423
1556
|
requestBody,
|
|
@@ -1433,7 +1566,7 @@ var SubscriptionDispatcher = class {
|
|
|
1433
1566
|
if (handled.retryOnce) {
|
|
1434
1567
|
try {
|
|
1435
1568
|
const upstream = await this.hooks.fetchWithRetry(fetchUrl, handled.headers, requestBody, currentModel);
|
|
1436
|
-
_optionalChain([this, 'access',
|
|
1569
|
+
_optionalChain([this, 'access', _92 => _92.profile, 'access', _93 => _93.recordModelOutcome, 'optionalCall', _94 => _94(currentModel, true)]);
|
|
1437
1570
|
this.markHealth(usedAccountId, 200);
|
|
1438
1571
|
const finalResponse = await this.hooks.executor.executeResponseChain(
|
|
1439
1572
|
requestBody,
|
|
@@ -1450,10 +1583,10 @@ var SubscriptionDispatcher = class {
|
|
|
1450
1583
|
}
|
|
1451
1584
|
}
|
|
1452
1585
|
if (caughtErrorBreakerOutcome(err) === "failure") {
|
|
1453
|
-
_optionalChain([this, 'access',
|
|
1586
|
+
_optionalChain([this, 'access', _95 => _95.profile, 'access', _96 => _96.recordModelOutcome, 'optionalCall', _97 => _97(currentModel, false)]);
|
|
1454
1587
|
}
|
|
1455
1588
|
this.markHealth(usedAccountId, errStatus(err), err);
|
|
1456
|
-
const next = _optionalChain([this, 'access',
|
|
1589
|
+
const next = _optionalChain([this, 'access', _98 => _98.profile, 'access', _99 => _99.nextFallback, 'optionalCall', _100 => _100(scenario, attempted, ocConfig)]);
|
|
1457
1590
|
if (!next || attempted.length >= MAX_FALLBACK_ATTEMPTS_LOCAL) {
|
|
1458
1591
|
throw err;
|
|
1459
1592
|
}
|
|
@@ -1483,7 +1616,7 @@ var SubscriptionDispatcher = class {
|
|
|
1483
1616
|
return { firstModel: primaryModel, attempted: [] };
|
|
1484
1617
|
}
|
|
1485
1618
|
const skipped = [primaryModel];
|
|
1486
|
-
const firstAdmitting = _optionalChain([this, 'access',
|
|
1619
|
+
const firstAdmitting = _optionalChain([this, 'access', _101 => _101.profile, 'access', _102 => _102.nextFallback, 'optionalCall', _103 => _103(scenario, skipped, ocConfig)]);
|
|
1487
1620
|
if (firstAdmitting) {
|
|
1488
1621
|
console.warn(
|
|
1489
1622
|
`[AgentProxy:subscription] opencodego primary ${primaryModel} circuit open -> first admitting fallback ${firstAdmitting.modelId}`
|
|
@@ -1501,7 +1634,7 @@ var SubscriptionDispatcher = class {
|
|
|
1501
1634
|
* successfully (caller should retry once); otherwise re-throws.
|
|
1502
1635
|
*/
|
|
1503
1636
|
async maybeRetryAfterError(err, headers, req, resolvedModel, sessionKey) {
|
|
1504
|
-
const status = _nullishCoalesce(_optionalChain([err, 'optionalAccess',
|
|
1637
|
+
const status = _nullishCoalesce(_optionalChain([err, 'optionalAccess', _104 => _104.status]), () => ( 0));
|
|
1505
1638
|
if (status !== 401) {
|
|
1506
1639
|
return { retryOnce: false, headers };
|
|
1507
1640
|
}
|
|
@@ -1624,11 +1757,11 @@ var SubscriptionDispatcher = class {
|
|
|
1624
1757
|
};
|
|
1625
1758
|
var MAX_FALLBACK_ATTEMPTS_LOCAL = 3;
|
|
1626
1759
|
function errStatus(err) {
|
|
1627
|
-
const status = _optionalChain([err, 'optionalAccess',
|
|
1760
|
+
const status = _optionalChain([err, 'optionalAccess', _105 => _105.status]);
|
|
1628
1761
|
return typeof status === "number" ? status : null;
|
|
1629
1762
|
}
|
|
1630
1763
|
function errHeaders(err) {
|
|
1631
|
-
const h = _optionalChain([err, 'optionalAccess',
|
|
1764
|
+
const h = _optionalChain([err, 'optionalAccess', _106 => _106.headers]);
|
|
1632
1765
|
if (!h) return void 0;
|
|
1633
1766
|
if (typeof h.get === "function") return h;
|
|
1634
1767
|
if (typeof h === "object") return h;
|
|
@@ -1636,11 +1769,11 @@ function errHeaders(err) {
|
|
|
1636
1769
|
}
|
|
1637
1770
|
function errBodyText(err) {
|
|
1638
1771
|
const e = err;
|
|
1639
|
-
const raw = typeof _optionalChain([e, 'optionalAccess',
|
|
1640
|
-
return _optionalChain([raw, 'optionalAccess',
|
|
1772
|
+
const raw = typeof _optionalChain([e, 'optionalAccess', _107 => _107.bodyText]) === "string" ? e.bodyText : typeof _optionalChain([e, 'optionalAccess', _108 => _108.body]) === "string" ? e.body : void 0;
|
|
1773
|
+
return _optionalChain([raw, 'optionalAccess', _109 => _109.slice, 'call', _110 => _110(0, 2048)]);
|
|
1641
1774
|
}
|
|
1642
1775
|
function caughtErrorBreakerOutcome(err) {
|
|
1643
|
-
const status = _optionalChain([err, 'optionalAccess',
|
|
1776
|
+
const status = _optionalChain([err, 'optionalAccess', _111 => _111.status]);
|
|
1644
1777
|
if (typeof status !== "number") return "failure";
|
|
1645
1778
|
if (status === 0) return "neutral";
|
|
1646
1779
|
if (status >= 500 || status === 429) return "failure";
|
|
@@ -1797,7 +1930,7 @@ async function encodeInputImage(asset, signal) {
|
|
|
1797
1930
|
try {
|
|
1798
1931
|
bytes = await _imagegeneration.readImageAssetBytes.call(void 0, asset, MAX_INPUT_IMAGE_BYTES, signal);
|
|
1799
1932
|
} catch (cause) {
|
|
1800
|
-
if (_optionalChain([signal, 'optionalAccess',
|
|
1933
|
+
if (_optionalChain([signal, 'optionalAccess', _112 => _112.aborted])) throw signal.reason;
|
|
1801
1934
|
if (cause instanceof RangeError) {
|
|
1802
1935
|
throw new (0, _imagegeneration.ImageGenerationError)("image_too_large", { param: "image", cause });
|
|
1803
1936
|
}
|
|
@@ -1901,8 +2034,8 @@ async function readCandidateCodexImageResponseBody(response) {
|
|
|
1901
2034
|
}
|
|
1902
2035
|
function selectVerifiedCandidateResponseMetadata(parsed, verified) {
|
|
1903
2036
|
return {
|
|
1904
|
-
..._optionalChain([verified, 'optionalAccess',
|
|
1905
|
-
..._optionalChain([verified, 'optionalAccess',
|
|
2037
|
+
..._optionalChain([verified, 'optionalAccess', _113 => _113.usage]) && parsed.usage ? { usage: parsed.usage } : {},
|
|
2038
|
+
..._optionalChain([verified, 'optionalAccess', _114 => _114.revisedPrompt]) && parsed.revisedPrompt ? { revisedPrompt: parsed.revisedPrompt } : {}
|
|
1906
2039
|
};
|
|
1907
2040
|
}
|
|
1908
2041
|
function protocolChanged(cause) {
|
|
@@ -2032,7 +2165,7 @@ async function parseCandidateCodexImageResponse(body, expectedCount, expectedFor
|
|
|
2032
2165
|
return item;
|
|
2033
2166
|
});
|
|
2034
2167
|
const images2 = await Promise.all(rows.map((item) => createAsset(item.b64_json, expectedFormat)));
|
|
2035
|
-
const revised2 = rows.length === 1 && typeof _optionalChain([rows, 'access',
|
|
2168
|
+
const revised2 = rows.length === 1 && typeof _optionalChain([rows, 'access', _115 => _115[0], 'optionalAccess', _116 => _116.revised_prompt]) === "string" ? rows[0].revised_prompt : void 0;
|
|
2036
2169
|
return {
|
|
2037
2170
|
images: images2,
|
|
2038
2171
|
revisedPrompt: revised2,
|
|
@@ -2048,7 +2181,7 @@ async function parseCandidateCodexImageResponse(body, expectedCount, expectedFor
|
|
|
2048
2181
|
if (call.status !== "completed" || typeof call.result !== "string") return protocolChanged();
|
|
2049
2182
|
return createAsset(call.result, expectedFormat);
|
|
2050
2183
|
}));
|
|
2051
|
-
const revised = calls.length === 1 && typeof _optionalChain([calls, 'access',
|
|
2184
|
+
const revised = calls.length === 1 && typeof _optionalChain([calls, 'access', _117 => _117[0], 'optionalAccess', _118 => _118.revised_prompt]) === "string" ? calls[0].revised_prompt : void 0;
|
|
2052
2185
|
return {
|
|
2053
2186
|
images,
|
|
2054
2187
|
revisedPrompt: revised,
|
|
@@ -2092,7 +2225,7 @@ async function parseCandidateCodexImageSse(body, expectedCount, expectedFormat)
|
|
|
2092
2225
|
}
|
|
2093
2226
|
}
|
|
2094
2227
|
}
|
|
2095
|
-
const output = _optionalChain([completedResponse, 'optionalAccess',
|
|
2228
|
+
const output = _optionalChain([completedResponse, 'optionalAccess', _119 => _119.output]);
|
|
2096
2229
|
const calls = Array.isArray(output) ? output.filter(
|
|
2097
2230
|
(item) => !!item && typeof item === "object" && !Array.isArray(item) && item.type === "image_generation_call"
|
|
2098
2231
|
) : [];
|
|
@@ -2103,15 +2236,15 @@ async function parseCandidateCodexImageSse(body, expectedCount, expectedFormat)
|
|
|
2103
2236
|
return protocolChanged();
|
|
2104
2237
|
}
|
|
2105
2238
|
const images = await Promise.all(Array.from({ length: expectedCount }, async (_unused, index) => {
|
|
2106
|
-
const encoded = _nullishCoalesce(_nullishCoalesce(best.get(index), () => ( completedEventResults[index])), () => ( _optionalChain([finalResults, 'access',
|
|
2239
|
+
const encoded = _nullishCoalesce(_nullishCoalesce(best.get(index), () => ( completedEventResults[index])), () => ( _optionalChain([finalResults, 'access', _120 => _120[index], 'optionalAccess', _121 => _121.result])));
|
|
2107
2240
|
if (!encoded) return protocolChanged();
|
|
2108
2241
|
return createAsset(encoded, expectedFormat);
|
|
2109
2242
|
}));
|
|
2110
|
-
const revised = calls.length === 1 && typeof _optionalChain([calls, 'access',
|
|
2243
|
+
const revised = calls.length === 1 && typeof _optionalChain([calls, 'access', _122 => _122[0], 'optionalAccess', _123 => _123.revised_prompt]) === "string" ? calls[0].revised_prompt : void 0;
|
|
2111
2244
|
return {
|
|
2112
2245
|
images,
|
|
2113
2246
|
revisedPrompt: revised,
|
|
2114
|
-
usage: parseUsage(_optionalChain([completedResponse, 'optionalAccess',
|
|
2247
|
+
usage: parseUsage(_optionalChain([completedResponse, 'optionalAccess', _124 => _124.usage]))
|
|
2115
2248
|
};
|
|
2116
2249
|
}
|
|
2117
2250
|
|
|
@@ -2266,7 +2399,7 @@ var CodexSubscriptionImageProvider = (_class10 = class {
|
|
|
2266
2399
|
}
|
|
2267
2400
|
schedulerGrantSignal = schedulerGrant.signal;
|
|
2268
2401
|
if (schedulerGrantSignal) {
|
|
2269
|
-
onSchedulerAbort = () => controller.abort(_optionalChain([schedulerGrantSignal, 'optionalAccess',
|
|
2402
|
+
onSchedulerAbort = () => controller.abort(_optionalChain([schedulerGrantSignal, 'optionalAccess', _125 => _125.reason]));
|
|
2270
2403
|
if (schedulerGrantSignal.aborted) onSchedulerAbort();
|
|
2271
2404
|
else schedulerGrantSignal.addEventListener("abort", onSchedulerAbort, { once: true });
|
|
2272
2405
|
}
|
|
@@ -2550,4 +2683,15 @@ function createCodexImageLiveVerifier(options) {
|
|
|
2550
2683
|
|
|
2551
2684
|
|
|
2552
2685
|
|
|
2553
|
-
|
|
2686
|
+
|
|
2687
|
+
|
|
2688
|
+
|
|
2689
|
+
|
|
2690
|
+
|
|
2691
|
+
|
|
2692
|
+
|
|
2693
|
+
|
|
2694
|
+
|
|
2695
|
+
|
|
2696
|
+
|
|
2697
|
+
exports.COPILOT_GITHUB_HEADERS = _chunkQKWL53TJcjs.COPILOT_GITHUB_HEADERS; exports.DEFAULT_ACCOUNT_PRIORITY = DEFAULT_ACCOUNT_PRIORITY; exports.LAST_USED_PERSIST_THROTTLE_MS = LAST_USED_PERSIST_THROTTLE_MS; exports.SESSION_AFFINITY_TTL_MS = SESSION_AFFINITY_TTL_MS; exports.SubscriptionAccountSelector = SubscriptionAccountSelector; exports.SubscriptionAccountService = SubscriptionAccountService; exports.SubscriptionDispatcher = SubscriptionDispatcher; exports.SubscriptionProviderRegistry = SubscriptionProviderRegistry; exports.claudeOAuth = _chunkQKWL53TJcjs.claude_exports; exports.codexOAuth = _chunkQKWL53TJcjs.codex_exports; exports.copilotBaseUrl = _chunkQKWL53TJcjs.copilotBaseUrl; exports.copilotGitHubApiBase = _chunkQKWL53TJcjs.copilotGitHubApiBase; exports.copilotOAuth = _chunkQKWL53TJcjs.copilot_exports; exports.copilotPathFor = _chunkQKWL53TJcjs.copilotPathFor; exports.copilotTransformerNamesForWire = _chunkQKWL53TJcjs.copilotTransformerNamesForWire; exports.copilotWireFor = _chunkQKWL53TJcjs.copilotWireFor; exports.createCodexImageLiveVerifier = createCodexImageLiveVerifier; exports.createCodexSubscriptionImageProvider = createCodexSubscriptionImageProvider; exports.geminiOAuth = _chunkQKWL53TJcjs.gemini_exports; exports.getSubscriptionAccountService = getSubscriptionAccountService; exports.getSubscriptionProviderRegistry = getSubscriptionProviderRegistry; exports.grokOAuth = _chunkQKWL53TJcjs.grok_exports; exports.kimiFingerprintHeaders = _chunkQKWL53TJcjs.kimiFingerprintHeaders; exports.kimiOAuth = _chunkQKWL53TJcjs.kimi_exports; exports.normalizeOpenCodeGoBaseUrl = normalizeOpenCodeGoBaseUrl; exports.setSubscriptionAccountService = setSubscriptionAccountService; exports.setSubscriptionProviderRegistry = setSubscriptionProviderRegistry;
|