@omnicross/daemon 0.4.0 → 0.4.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/cli.cjs +292 -81
- package/dist/cli.js +287 -71
- package/dist/index.cjs +290 -79
- package/dist/index.d.cts +58 -3
- package/dist/index.d.ts +58 -3
- package/dist/index.js +285 -69
- package/package.json +6 -6
package/dist/cli.js
CHANGED
|
@@ -1156,7 +1156,7 @@ import { dirname as dirname17 } from "path";
|
|
|
1156
1156
|
import { DEFAULT_AUDIT_CONFIG } from "@omnicross/contracts/audit-types";
|
|
1157
1157
|
import { DEFAULT_BILLING_CONFIG } from "@omnicross/contracts/billing-types";
|
|
1158
1158
|
import { OpenAIOperationRegistry } from "@omnicross/core";
|
|
1159
|
-
import { getGeminiCodeAssistProjectResolver } from "@omnicross/core/auth/GeminiCodeAssistProjectResolver";
|
|
1159
|
+
import { getGeminiCodeAssistProjectResolver as getGeminiCodeAssistProjectResolver2 } from "@omnicross/core/auth/GeminiCodeAssistProjectResolver";
|
|
1160
1160
|
import { ApiKeyPoolService } from "@omnicross/core/completion/ApiKeyPoolService";
|
|
1161
1161
|
import {
|
|
1162
1162
|
__resetOutboundApiServerForTests,
|
|
@@ -1170,14 +1170,14 @@ import { setSubscriptionRegistryForOutbound } from "@omnicross/core/outbound-api
|
|
|
1170
1170
|
import { getSharedAccountHealth as getSharedAccountHealth4 } from "@omnicross/core/pipeline/SubscriptionAccountHealth";
|
|
1171
1171
|
import {
|
|
1172
1172
|
__resetSharedAccountAllowanceStoreForTests,
|
|
1173
|
-
AccountAllowanceStore as
|
|
1173
|
+
AccountAllowanceStore as AccountAllowanceStore9,
|
|
1174
1174
|
setSharedAccountAllowanceStore
|
|
1175
1175
|
} from "@omnicross/core/pipeline/AccountAllowanceStore";
|
|
1176
1176
|
import {
|
|
1177
1177
|
__resetSharedAccountAllowanceSchedulingForTests,
|
|
1178
1178
|
getSharedAccountAllowanceScheduling as getSharedAccountAllowanceScheduling5
|
|
1179
1179
|
} from "@omnicross/core/pipeline/AccountAllowanceScheduling";
|
|
1180
|
-
import { fetchUpstream as
|
|
1180
|
+
import { fetchUpstream as fetchUpstream14, setUpstreamProxyResolver } from "@omnicross/core/pipeline/upstreamFetch";
|
|
1181
1181
|
import { __resetSharedIdentityStoreForTests } from "@omnicross/core/provider-proxy/identity/SubscriptionIdentityStore";
|
|
1182
1182
|
import { setGeminiCodeAssistResolver } from "@omnicross/core/ports/gemini-code-assist-resolver";
|
|
1183
1183
|
import {
|
|
@@ -1563,7 +1563,7 @@ function handleCopilotOAuthStatus(sessionId, deps) {
|
|
|
1563
1563
|
|
|
1564
1564
|
// src/allowance/AccountAllowanceService.ts
|
|
1565
1565
|
import {
|
|
1566
|
-
getSharedAccountAllowanceStore as
|
|
1566
|
+
getSharedAccountAllowanceStore as getSharedAccountAllowanceStore8
|
|
1567
1567
|
} from "@omnicross/core/pipeline/AccountAllowanceStore";
|
|
1568
1568
|
import {
|
|
1569
1569
|
getSharedAccountAllowanceScheduling
|
|
@@ -2766,11 +2766,198 @@ var CopilotAllowanceCollector = class {
|
|
|
2766
2766
|
}
|
|
2767
2767
|
};
|
|
2768
2768
|
|
|
2769
|
-
// src/allowance/
|
|
2769
|
+
// src/allowance/GeminiAllowanceCollector.ts
|
|
2770
|
+
import { getGeminiCodeAssistProjectResolver } from "@omnicross/core/auth/GeminiCodeAssistProjectResolver";
|
|
2770
2771
|
import {
|
|
2771
2772
|
getSharedAccountAllowanceStore as getSharedAccountAllowanceStore6
|
|
2772
2773
|
} from "@omnicross/core/pipeline/AccountAllowanceStore";
|
|
2773
2774
|
import { fetchUpstream as fetchUpstream6 } from "@omnicross/core/pipeline/upstreamFetch";
|
|
2775
|
+
import {
|
|
2776
|
+
getGeminiCliIdentityHeaders,
|
|
2777
|
+
resolveCodeAssistEndpoint
|
|
2778
|
+
} from "@omnicross/core/transformer/transformers";
|
|
2779
|
+
var GEMINI_ALLOWANCE_CACHE_MS = 5 * 6e4;
|
|
2780
|
+
function isRecord4(value) {
|
|
2781
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
2782
|
+
}
|
|
2783
|
+
function secondsUntil6(instant, now) {
|
|
2784
|
+
if (!instant) return void 0;
|
|
2785
|
+
return Math.max(0, Math.floor((Date.parse(instant) - now) / 1e3));
|
|
2786
|
+
}
|
|
2787
|
+
function parseGeminiQuotaPayload(payload, now) {
|
|
2788
|
+
if (!isRecord4(payload)) return null;
|
|
2789
|
+
const buckets = Array.isArray(payload["buckets"]) ? payload["buckets"] : [];
|
|
2790
|
+
const windows = [];
|
|
2791
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2792
|
+
for (const raw of buckets) {
|
|
2793
|
+
if (!isRecord4(raw)) continue;
|
|
2794
|
+
const modelId = typeof raw["modelId"] === "string" && raw["modelId"].trim() ? raw["modelId"].trim() : void 0;
|
|
2795
|
+
const id = `gemini:${modelId ?? "all"}`;
|
|
2796
|
+
if (seen.has(id)) continue;
|
|
2797
|
+
seen.add(id);
|
|
2798
|
+
const fractionRaw = typeof raw["remainingFraction"] === "number" ? raw["remainingFraction"] : Number(raw["remainingFraction"]);
|
|
2799
|
+
const usedPercent = Number.isFinite(fractionRaw) ? Math.round(Math.min(100, Math.max(0, (1 - Math.min(1, Math.max(0, fractionRaw))) * 100)) * 10) / 10 : null;
|
|
2800
|
+
const resetRaw = typeof raw["resetTime"] === "string" && raw["resetTime"].trim() ? raw["resetTime"] : void 0;
|
|
2801
|
+
const resetsAt = resetRaw !== void 0 && Number.isFinite(Date.parse(resetRaw)) ? new Date(Date.parse(resetRaw)).toISOString() : void 0;
|
|
2802
|
+
windows.push({
|
|
2803
|
+
id,
|
|
2804
|
+
label: modelId ? `Gemini ${modelId}` : "Gemini quota",
|
|
2805
|
+
scope: modelId ? "model-family" : "all",
|
|
2806
|
+
...modelId ? { modelFamily: modelId } : {},
|
|
2807
|
+
usedPercent,
|
|
2808
|
+
...resetsAt !== void 0 ? { resetsAt } : {},
|
|
2809
|
+
remainingSeconds: secondsUntil6(resetsAt, now),
|
|
2810
|
+
state: "fresh"
|
|
2811
|
+
});
|
|
2812
|
+
}
|
|
2813
|
+
return windows.length > 0 ? windows : null;
|
|
2814
|
+
}
|
|
2815
|
+
var GeminiAllowanceCollector = class {
|
|
2816
|
+
constructor(credentials, store = getSharedAccountAllowanceStore6(), fetchImpl = (url, init, accountId) => fetchUpstream6(url, init, { providerId: "gemini", accountId, redactBodies: true }), now = Date.now, projectResolver = getGeminiCodeAssistProjectResolver()) {
|
|
2817
|
+
this.credentials = credentials;
|
|
2818
|
+
this.store = store;
|
|
2819
|
+
this.fetchImpl = fetchImpl;
|
|
2820
|
+
this.now = now;
|
|
2821
|
+
this.projectResolver = projectResolver;
|
|
2822
|
+
}
|
|
2823
|
+
credentials;
|
|
2824
|
+
store;
|
|
2825
|
+
fetchImpl;
|
|
2826
|
+
now;
|
|
2827
|
+
projectResolver;
|
|
2828
|
+
inFlight = /* @__PURE__ */ new Map();
|
|
2829
|
+
async collectMany(accounts, options = {}) {
|
|
2830
|
+
const settled = await Promise.allSettled(
|
|
2831
|
+
accounts.map((account) => this.collect(account, options))
|
|
2832
|
+
);
|
|
2833
|
+
return settled.flatMap((result) => result.status === "fulfilled" ? [result.value] : []);
|
|
2834
|
+
}
|
|
2835
|
+
collect(account, options = {}) {
|
|
2836
|
+
const now = this.now();
|
|
2837
|
+
if (account.tokens.authMethod !== "oauth") {
|
|
2838
|
+
const existing = this.store.get("gemini", account.id, now);
|
|
2839
|
+
if (existing?.windows.every((window) => window.state === "unsupported")) {
|
|
2840
|
+
return Promise.resolve(existing);
|
|
2841
|
+
}
|
|
2842
|
+
const snapshot = this.unsupportedSnapshot(account.id, now);
|
|
2843
|
+
this.store.set(snapshot);
|
|
2844
|
+
return Promise.resolve(snapshot);
|
|
2845
|
+
}
|
|
2846
|
+
const cached = this.store.get("gemini", account.id, now);
|
|
2847
|
+
if (!options.force && cached && this.isCacheValid(cached, now, options.refreshAheadMs)) {
|
|
2848
|
+
return Promise.resolve(cached);
|
|
2849
|
+
}
|
|
2850
|
+
const running = this.inFlight.get(account.id);
|
|
2851
|
+
if (running) return running;
|
|
2852
|
+
const promise = this.fetchAccount(account.id).catch(() => this.failureSnapshot(account.id, "gemini_usage_request_failed", this.now())).finally(() => this.inFlight.delete(account.id));
|
|
2853
|
+
this.inFlight.set(account.id, promise);
|
|
2854
|
+
return promise;
|
|
2855
|
+
}
|
|
2856
|
+
isCacheValid(snapshot, now, refreshAheadMs) {
|
|
2857
|
+
if (snapshot.windows.every((window) => window.state === "unsupported")) return true;
|
|
2858
|
+
const expiresAt = snapshot.expiresAt ? Date.parse(snapshot.expiresAt) : 0;
|
|
2859
|
+
const ahead = typeof refreshAheadMs === "number" && Number.isFinite(refreshAheadMs) ? Math.max(0, refreshAheadMs) : 0;
|
|
2860
|
+
return Number.isFinite(expiresAt) && expiresAt > now + ahead;
|
|
2861
|
+
}
|
|
2862
|
+
async fetchAccount(accountId) {
|
|
2863
|
+
let accessToken = await this.credentials.getAccessTokenForAccount("gemini", accountId);
|
|
2864
|
+
if (!accessToken) return this.failureSnapshot(accountId, "gemini_usage_token_unavailable", this.now());
|
|
2865
|
+
let project;
|
|
2866
|
+
try {
|
|
2867
|
+
project = await this.projectResolver.resolveProject(accessToken);
|
|
2868
|
+
} catch {
|
|
2869
|
+
project = void 0;
|
|
2870
|
+
}
|
|
2871
|
+
let response = await this.request(accountId, accessToken, project);
|
|
2872
|
+
if (response.status === 401 || response.status === 403) {
|
|
2873
|
+
const refreshed = await this.credentials.refreshAccountToken("gemini", accountId);
|
|
2874
|
+
if (!refreshed) return this.failureSnapshot(accountId, "gemini_usage_unauthorized", this.now());
|
|
2875
|
+
accessToken = await this.credentials.getAccessTokenForAccount("gemini", accountId);
|
|
2876
|
+
if (!accessToken) return this.failureSnapshot(accountId, "gemini_usage_token_unavailable", this.now());
|
|
2877
|
+
response = await this.request(accountId, accessToken, project);
|
|
2878
|
+
if (response.status === 401 || response.status === 403) {
|
|
2879
|
+
return this.failureSnapshot(accountId, "gemini_usage_unauthorized", this.now());
|
|
2880
|
+
}
|
|
2881
|
+
}
|
|
2882
|
+
if (!response.ok) return this.failureSnapshot(accountId, "gemini_usage_http_error", this.now());
|
|
2883
|
+
let payload;
|
|
2884
|
+
try {
|
|
2885
|
+
payload = await response.json();
|
|
2886
|
+
} catch {
|
|
2887
|
+
return this.failureSnapshot(accountId, "gemini_usage_invalid_response", this.now());
|
|
2888
|
+
}
|
|
2889
|
+
const now = this.now();
|
|
2890
|
+
const windows = parseGeminiQuotaPayload(payload, now);
|
|
2891
|
+
const snapshot = {
|
|
2892
|
+
providerId: "gemini",
|
|
2893
|
+
accountId,
|
|
2894
|
+
source: "oauth-usage-api",
|
|
2895
|
+
observedAt: new Date(now).toISOString(),
|
|
2896
|
+
expiresAt: new Date(now + GEMINI_ALLOWANCE_CACHE_MS).toISOString(),
|
|
2897
|
+
windows: windows ?? [
|
|
2898
|
+
{ id: "gemini-quota", label: "Gemini quota", scope: "all", usedPercent: null, state: "unavailable" }
|
|
2899
|
+
],
|
|
2900
|
+
...windows ? {} : { lastErrorCode: "gemini_usage_invalid_response" }
|
|
2901
|
+
};
|
|
2902
|
+
this.store.set(snapshot);
|
|
2903
|
+
return snapshot;
|
|
2904
|
+
}
|
|
2905
|
+
request(accountId, accessToken, project) {
|
|
2906
|
+
return this.fetchImpl(`${resolveCodeAssistEndpoint()}/v1internal:retrieveUserQuota`, {
|
|
2907
|
+
method: "POST",
|
|
2908
|
+
headers: {
|
|
2909
|
+
Authorization: `Bearer ${accessToken}`,
|
|
2910
|
+
Accept: "application/json",
|
|
2911
|
+
"Content-Type": "application/json",
|
|
2912
|
+
...getGeminiCliIdentityHeaders()
|
|
2913
|
+
},
|
|
2914
|
+
body: JSON.stringify(project ? { project } : {}),
|
|
2915
|
+
signal: AbortSignal.timeout(15e3)
|
|
2916
|
+
}, accountId);
|
|
2917
|
+
}
|
|
2918
|
+
failureSnapshot(accountId, code, now) {
|
|
2919
|
+
const existing = this.store.get("gemini", accountId, now);
|
|
2920
|
+
const snapshot = existing ? {
|
|
2921
|
+
...existing,
|
|
2922
|
+
expiresAt: new Date(now + GEMINI_ALLOWANCE_CACHE_MS).toISOString(),
|
|
2923
|
+
windows: existing.windows.map((window) => ({
|
|
2924
|
+
...window,
|
|
2925
|
+
state: window.state === "unsupported" ? "unsupported" : window.usedPercent !== null || window.resetsAt ? "stale" : "unavailable"
|
|
2926
|
+
})),
|
|
2927
|
+
lastErrorCode: code
|
|
2928
|
+
} : {
|
|
2929
|
+
providerId: "gemini",
|
|
2930
|
+
accountId,
|
|
2931
|
+
source: "oauth-usage-api",
|
|
2932
|
+
observedAt: new Date(now).toISOString(),
|
|
2933
|
+
expiresAt: new Date(now + GEMINI_ALLOWANCE_CACHE_MS).toISOString(),
|
|
2934
|
+
windows: [
|
|
2935
|
+
{ id: "gemini-quota", label: "Gemini quota", scope: "all", usedPercent: null, state: "unavailable" }
|
|
2936
|
+
],
|
|
2937
|
+
lastErrorCode: code
|
|
2938
|
+
};
|
|
2939
|
+
this.store.set(snapshot);
|
|
2940
|
+
return snapshot;
|
|
2941
|
+
}
|
|
2942
|
+
unsupportedSnapshot(accountId, now) {
|
|
2943
|
+
return {
|
|
2944
|
+
providerId: "gemini",
|
|
2945
|
+
accountId,
|
|
2946
|
+
source: "oauth-usage-api",
|
|
2947
|
+
observedAt: new Date(now).toISOString(),
|
|
2948
|
+
windows: [
|
|
2949
|
+
{ id: "gemini-quota", label: "Gemini quota", scope: "all", usedPercent: null, state: "unsupported" }
|
|
2950
|
+
],
|
|
2951
|
+
lastErrorCode: "gemini_usage_unsupported_auth"
|
|
2952
|
+
};
|
|
2953
|
+
}
|
|
2954
|
+
};
|
|
2955
|
+
|
|
2956
|
+
// src/allowance/OpenCodeGoAllowanceCollector.ts
|
|
2957
|
+
import {
|
|
2958
|
+
getSharedAccountAllowanceStore as getSharedAccountAllowanceStore7
|
|
2959
|
+
} from "@omnicross/core/pipeline/AccountAllowanceStore";
|
|
2960
|
+
import { fetchUpstream as fetchUpstream7 } from "@omnicross/core/pipeline/upstreamFetch";
|
|
2774
2961
|
import { normalizeOpenCodeGoBaseUrl } from "@omnicross/subscriptions";
|
|
2775
2962
|
var OPENCODEGO_ALLOWANCE_CACHE_MS = 5 * 6e4;
|
|
2776
2963
|
var OPENCODEGO_DEFAULT_GO_BASE = "https://opencode.ai/zen/go";
|
|
@@ -2784,7 +2971,7 @@ function isoInstant2(value) {
|
|
|
2784
2971
|
const time = Date.parse(value);
|
|
2785
2972
|
return Number.isFinite(time) ? new Date(time).toISOString() : void 0;
|
|
2786
2973
|
}
|
|
2787
|
-
function
|
|
2974
|
+
function secondsUntil7(instant, now) {
|
|
2788
2975
|
if (!instant) return void 0;
|
|
2789
2976
|
return Math.max(0, Math.floor((Date.parse(instant) - now) / 1e3));
|
|
2790
2977
|
}
|
|
@@ -2799,12 +2986,12 @@ function windowFromPayload3(id, label, minutes, payload, now) {
|
|
|
2799
2986
|
usedPercent,
|
|
2800
2987
|
windowMinutes: minutes,
|
|
2801
2988
|
...resetsAt !== void 0 ? { resetsAt } : {},
|
|
2802
|
-
remainingSeconds:
|
|
2989
|
+
remainingSeconds: secondsUntil7(resetsAt, now),
|
|
2803
2990
|
state: usedPercent !== null || resetsAt ? "fresh" : "unavailable"
|
|
2804
2991
|
};
|
|
2805
2992
|
}
|
|
2806
2993
|
var OpenCodeGoAllowanceCollector = class {
|
|
2807
|
-
constructor(credentials, store =
|
|
2994
|
+
constructor(credentials, store = getSharedAccountAllowanceStore7(), fetchImpl = (url, init, accountId) => fetchUpstream7(url, init, { providerId: "opencodego", accountId, redactBodies: true }), now = Date.now) {
|
|
2808
2995
|
this.credentials = credentials;
|
|
2809
2996
|
this.store = store;
|
|
2810
2997
|
this.fetchImpl = fetchImpl;
|
|
@@ -2909,7 +3096,7 @@ function codexUnavailable(accountId, now) {
|
|
|
2909
3096
|
};
|
|
2910
3097
|
}
|
|
2911
3098
|
var AccountAllowanceService = class {
|
|
2912
|
-
constructor(credentials, store =
|
|
3099
|
+
constructor(credentials, store = getSharedAccountAllowanceStore8(), collector, codexCollector, kimiCollector, opencodegoCollector, grokCollector, copilotCollector, geminiCollector, now = Date.now) {
|
|
2913
3100
|
this.credentials = credentials;
|
|
2914
3101
|
this.store = store;
|
|
2915
3102
|
this.now = now;
|
|
@@ -2919,6 +3106,7 @@ var AccountAllowanceService = class {
|
|
|
2919
3106
|
this.opencodegoCollector = opencodegoCollector ?? new OpenCodeGoAllowanceCollector(credentials, store);
|
|
2920
3107
|
this.grokCollector = grokCollector ?? new GrokAllowanceCollector(credentials, store);
|
|
2921
3108
|
this.copilotCollector = copilotCollector ?? new CopilotAllowanceCollector(credentials, store);
|
|
3109
|
+
this.geminiCollector = geminiCollector ?? new GeminiAllowanceCollector(credentials, store);
|
|
2922
3110
|
}
|
|
2923
3111
|
credentials;
|
|
2924
3112
|
store;
|
|
@@ -2929,6 +3117,7 @@ var AccountAllowanceService = class {
|
|
|
2929
3117
|
grokCollector;
|
|
2930
3118
|
copilotCollector;
|
|
2931
3119
|
opencodegoCollector;
|
|
3120
|
+
geminiCollector;
|
|
2932
3121
|
/**
|
|
2933
3122
|
* Read all/filtered snapshots. Claude's and Codex's five-minute caches are
|
|
2934
3123
|
* refreshed lazily on read (Codex polls `/backend-api/wham/usage`; the
|
|
@@ -2972,6 +3161,11 @@ var AccountAllowanceService = class {
|
|
|
2972
3161
|
(account) => !filter.accountId || account.id === filter.accountId
|
|
2973
3162
|
);
|
|
2974
3163
|
if (wantsCopilot) await this.copilotCollector.collectMany(copilotAccounts);
|
|
3164
|
+
const wantsGemini = !filter.providerId || filter.providerId === "gemini";
|
|
3165
|
+
const geminiAccounts = (config.geminiAccounts ?? []).filter(
|
|
3166
|
+
(account) => !filter.accountId || account.id === filter.accountId
|
|
3167
|
+
);
|
|
3168
|
+
if (wantsGemini) await this.geminiCollector.collectMany(geminiAccounts);
|
|
2975
3169
|
const known = /* @__PURE__ */ new Set();
|
|
2976
3170
|
if (wantsClaude) for (const account of claudeAccounts) known.add(`claude\0${account.id}`);
|
|
2977
3171
|
if (wantsCodex) for (const account of codexAccounts) known.add(`codex\0${account.id}`);
|
|
@@ -2979,6 +3173,7 @@ var AccountAllowanceService = class {
|
|
|
2979
3173
|
if (wantsOpenCodeGo) for (const account of opencodegoAccounts) known.add(`opencodego\0${account.id}`);
|
|
2980
3174
|
if (wantsGrok) for (const account of grokAccounts) known.add(`grok\0${account.id}`);
|
|
2981
3175
|
if (wantsCopilot) for (const account of copilotAccounts) known.add(`copilot\0${account.id}`);
|
|
3176
|
+
if (wantsGemini) for (const account of geminiAccounts) known.add(`gemini\0${account.id}`);
|
|
2982
3177
|
return this.store.list(filter).filter((snapshot) => known.has(`${snapshot.providerId}\0${snapshot.accountId}`));
|
|
2983
3178
|
}
|
|
2984
3179
|
knownAccounts(config) {
|
|
@@ -2988,7 +3183,8 @@ var AccountAllowanceService = class {
|
|
|
2988
3183
|
...(config.kimiAccounts ?? []).map((account) => ({ providerId: "kimi", accountId: account.id })),
|
|
2989
3184
|
...(config.opencodegoAccounts ?? []).map((account) => ({ providerId: "opencodego", accountId: account.id })),
|
|
2990
3185
|
...(config.grokAccounts ?? []).map((account) => ({ providerId: "grok", accountId: account.id })),
|
|
2991
|
-
...(config.copilotAccounts ?? []).map((account) => ({ providerId: "copilot", accountId: account.id }))
|
|
3186
|
+
...(config.copilotAccounts ?? []).map((account) => ({ providerId: "copilot", accountId: account.id })),
|
|
3187
|
+
...(config.geminiAccounts ?? []).map((account) => ({ providerId: "gemini", accountId: account.id }))
|
|
2992
3188
|
];
|
|
2993
3189
|
}
|
|
2994
3190
|
/** Force-refresh Claude usage for one account or every stored Claude account. */
|
|
@@ -3049,6 +3245,15 @@ var AccountAllowanceService = class {
|
|
|
3049
3245
|
);
|
|
3050
3246
|
return this.grokCollector.collectMany(accounts, { force: true });
|
|
3051
3247
|
}
|
|
3248
|
+
/** Force-refresh Gemini usage (Code Assist retrieveUserQuota) for one/all accounts. */
|
|
3249
|
+
async refreshGemini(accountId) {
|
|
3250
|
+
const config = await this.credentials.getFullConfig();
|
|
3251
|
+
this.store.pruneToKnownAccounts(this.knownAccounts(config));
|
|
3252
|
+
const accounts = (config.geminiAccounts ?? []).filter(
|
|
3253
|
+
(account) => !accountId || account.id === accountId
|
|
3254
|
+
);
|
|
3255
|
+
return this.geminiCollector.collectMany(accounts, { force: true });
|
|
3256
|
+
}
|
|
3052
3257
|
/**
|
|
3053
3258
|
* Keep Claude + Codex + Kimi snapshots warm for allowance-aware routing. All
|
|
3054
3259
|
* collectors preserve their cache + per-account in-flight coalescing; a tick
|
|
@@ -3065,6 +3270,7 @@ var AccountAllowanceService = class {
|
|
|
3065
3270
|
await this.opencodegoCollector.collectMany(config.opencodegoAccounts ?? [], { refreshAheadMs });
|
|
3066
3271
|
await this.grokCollector.collectMany(config.grokAccounts ?? [], { refreshAheadMs });
|
|
3067
3272
|
await this.copilotCollector.collectMany(config.copilotAccounts ?? [], { refreshAheadMs });
|
|
3273
|
+
await this.geminiCollector.collectMany(config.geminiAccounts ?? [], { refreshAheadMs });
|
|
3068
3274
|
}
|
|
3069
3275
|
/** Remove a cache row as soon as an account is deleted by the admin path. */
|
|
3070
3276
|
removeAccountSnapshot(providerId, accountId) {
|
|
@@ -3494,7 +3700,7 @@ import {
|
|
|
3494
3700
|
} from "@omnicross/contracts/image-generation-types";
|
|
3495
3701
|
import { getSharedAccountAllowanceScheduling as getSharedAccountAllowanceScheduling2 } from "@omnicross/core/pipeline/AccountAllowanceScheduling";
|
|
3496
3702
|
import { getSharedAccountHealth } from "@omnicross/core/pipeline/SubscriptionAccountHealth";
|
|
3497
|
-
import { fetchUpstream as
|
|
3703
|
+
import { fetchUpstream as fetchUpstream8 } from "@omnicross/core/pipeline/upstreamFetch";
|
|
3498
3704
|
import { mergeExtraHeaders } from "@omnicross/core";
|
|
3499
3705
|
|
|
3500
3706
|
// src/image-generation/imagesConfigValidation.ts
|
|
@@ -6561,7 +6767,7 @@ async function handleSearchQuery(req, res, deps) {
|
|
|
6561
6767
|
// src/admin/searchAdminView.ts
|
|
6562
6768
|
var API_KEY_PROVIDERS = /* @__PURE__ */ new Set(["tavily", "jina", "zhipu", "z.ai"]);
|
|
6563
6769
|
var BASIC_AUTH_PROVIDERS = /* @__PURE__ */ new Set(["searxng"]);
|
|
6564
|
-
function
|
|
6770
|
+
function isRecord5(value) {
|
|
6565
6771
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
6566
6772
|
}
|
|
6567
6773
|
function redactSearchServerConfig(search) {
|
|
@@ -6611,13 +6817,13 @@ function resolveSecretField(entry, field, stored) {
|
|
|
6611
6817
|
else delete entry[field];
|
|
6612
6818
|
}
|
|
6613
6819
|
function preserveSearchSecrets(incoming, current) {
|
|
6614
|
-
if (!
|
|
6820
|
+
if (!isRecord5(incoming)) return incoming;
|
|
6615
6821
|
const section = { ...incoming };
|
|
6616
6822
|
const providersValue = section["providers"];
|
|
6617
|
-
if (!
|
|
6823
|
+
if (!isRecord5(providersValue)) return section;
|
|
6618
6824
|
const providers = {};
|
|
6619
6825
|
for (const [id, entryValue] of Object.entries(providersValue)) {
|
|
6620
|
-
if (!
|
|
6826
|
+
if (!isRecord5(entryValue)) {
|
|
6621
6827
|
providers[id] = entryValue;
|
|
6622
6828
|
continue;
|
|
6623
6829
|
}
|
|
@@ -6695,7 +6901,7 @@ function parseKeyPolicyBody(body) {
|
|
|
6695
6901
|
var ENDPOINTS = /* @__PURE__ */ new Set(["chat", "responses", "messages", "gemini"]);
|
|
6696
6902
|
var TARGET_KINDS = /* @__PURE__ */ new Set(["account", "account-group", "account-pool", "provider"]);
|
|
6697
6903
|
var FALLBACKS = /* @__PURE__ */ new Set(["next", "fail", "global"]);
|
|
6698
|
-
function
|
|
6904
|
+
function isRecord6(value) {
|
|
6699
6905
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
6700
6906
|
}
|
|
6701
6907
|
function nonBlank(value) {
|
|
@@ -6715,7 +6921,7 @@ function validateGatewayBindingsSegment(patch) {
|
|
|
6715
6921
|
const ids = /* @__PURE__ */ new Set();
|
|
6716
6922
|
raw.forEach((entry, index) => {
|
|
6717
6923
|
const path2 = `bindings[${index}]`;
|
|
6718
|
-
if (!
|
|
6924
|
+
if (!isRecord6(entry)) {
|
|
6719
6925
|
errors.push(`${path2} must be an object`);
|
|
6720
6926
|
return;
|
|
6721
6927
|
}
|
|
@@ -6744,12 +6950,12 @@ function validateGatewayBindingsSegment(patch) {
|
|
|
6744
6950
|
} else if (entry.modelMappings.length > 100) {
|
|
6745
6951
|
errors.push(`${path2}.modelMappings cannot contain more than 100 entries`);
|
|
6746
6952
|
} else if (entry.modelMappings.some(
|
|
6747
|
-
(mapping) => !
|
|
6953
|
+
(mapping) => !isRecord6(mapping) || !nonBlank(mapping.source) || !nonBlank(mapping.target)
|
|
6748
6954
|
)) {
|
|
6749
6955
|
errors.push(`${path2}.modelMappings must contain non-empty source and target strings`);
|
|
6750
6956
|
}
|
|
6751
6957
|
}
|
|
6752
|
-
if (!
|
|
6958
|
+
if (!isRecord6(entry.target) || !TARGET_KINDS.has(String(entry.target.kind))) {
|
|
6753
6959
|
errors.push(`${path2}.target is invalid`);
|
|
6754
6960
|
} else {
|
|
6755
6961
|
if (!nonBlank(entry.target.providerId)) errors.push(`${path2}.target.providerId is required`);
|
|
@@ -6764,7 +6970,7 @@ function validateGatewayBindingsSegment(patch) {
|
|
|
6764
6970
|
}
|
|
6765
6971
|
}
|
|
6766
6972
|
if (entry.modelMap !== void 0) {
|
|
6767
|
-
if (!
|
|
6973
|
+
if (!isRecord6(entry.modelMap) || Object.values(entry.modelMap).some((value) => typeof value !== "string")) {
|
|
6768
6974
|
errors.push(`${path2}.modelMap must contain string values`);
|
|
6769
6975
|
}
|
|
6770
6976
|
}
|
|
@@ -7837,7 +8043,7 @@ function query(req) {
|
|
|
7837
8043
|
}
|
|
7838
8044
|
function allowanceProvider(value) {
|
|
7839
8045
|
if (!value) return void 0;
|
|
7840
|
-
return value === "claude" || value === "codex" || value === "kimi" || value === "opencodego" || value === "grok" || value === "copilot" ? value : null;
|
|
8046
|
+
return value === "claude" || value === "codex" || value === "kimi" || value === "opencodego" || value === "grok" || value === "copilot" || value === "gemini" ? value : null;
|
|
7841
8047
|
}
|
|
7842
8048
|
async function handleAccountAllowanceApi(req, res, method, rest, service) {
|
|
7843
8049
|
if (!service) return writeError2(res, 501, "account allowance service is not available");
|
|
@@ -7852,7 +8058,7 @@ async function handleAccountAllowanceApi(req, res, method, rest, service) {
|
|
|
7852
8058
|
const pathProvider = rest.length >= 2 ? rest[0] : null;
|
|
7853
8059
|
const providerId = allowanceProvider(pathProvider ?? params.get("providerId") ?? params.get("provider"));
|
|
7854
8060
|
if (providerId === null) {
|
|
7855
|
-
return writeError2(res, 400, "providerId must be claude, codex, kimi, opencodego, grok, or
|
|
8061
|
+
return writeError2(res, 400, "providerId must be claude, codex, kimi, opencodego, grok, copilot, or gemini");
|
|
7856
8062
|
}
|
|
7857
8063
|
const accountId = rest.length >= 2 ? rest[1] : params.get("accountId") ?? void 0;
|
|
7858
8064
|
const allowances = await service.list({ providerId, accountId });
|
|
@@ -7914,6 +8120,16 @@ async function handleAccountAllowanceApi(req, res, method, rest, service) {
|
|
|
7914
8120
|
}
|
|
7915
8121
|
return writeJson3(res, 200, { allowances: allowances2 });
|
|
7916
8122
|
}
|
|
8123
|
+
if (requestedProvider === "gemini") {
|
|
8124
|
+
if (!service.refreshGemini) {
|
|
8125
|
+
return writeError2(res, 501, "gemini allowance refresh is not available");
|
|
8126
|
+
}
|
|
8127
|
+
const allowances2 = await service.refreshGemini(accountId);
|
|
8128
|
+
if (accountId && allowances2.length === 0) {
|
|
8129
|
+
return writeError2(res, 404, `Gemini account '${accountId}' not found`);
|
|
8130
|
+
}
|
|
8131
|
+
return writeJson3(res, 200, { allowances: allowances2 });
|
|
8132
|
+
}
|
|
7917
8133
|
const allowances = await service.refreshClaude(accountId);
|
|
7918
8134
|
if (accountId && allowances.length === 0) {
|
|
7919
8135
|
return writeError2(res, 404, `Claude account '${accountId}' not found`);
|
|
@@ -8263,7 +8479,7 @@ async function handleDiscoverModels(res, id, cfg) {
|
|
|
8263
8479
|
const headers = { Accept: "application/json" };
|
|
8264
8480
|
if (resolvedKey) headers["Authorization"] = `Bearer ${resolvedKey}`;
|
|
8265
8481
|
Object.assign(headers, expandRowExtraHeaders(row));
|
|
8266
|
-
const response = await
|
|
8482
|
+
const response = await fetchUpstream8(url, { method: "GET", headers }, { providerId: "byo" });
|
|
8267
8483
|
if (!response.ok) {
|
|
8268
8484
|
const text = await response.text().catch(() => "");
|
|
8269
8485
|
let message = text.slice(0, 300);
|
|
@@ -8323,7 +8539,7 @@ async function handleTestModel(req, res, id, cfg) {
|
|
|
8323
8539
|
Object.assign(headers, expandRowExtraHeaders(row));
|
|
8324
8540
|
const startedAt = Date.now();
|
|
8325
8541
|
try {
|
|
8326
|
-
const response = await
|
|
8542
|
+
const response = await fetchUpstream8(
|
|
8327
8543
|
url,
|
|
8328
8544
|
{ method: "POST", headers, body: JSON.stringify(payload) },
|
|
8329
8545
|
{ providerId: "byo" }
|
|
@@ -9730,12 +9946,12 @@ async function handlePlayground(req, res, method, deps) {
|
|
|
9730
9946
|
const payload = body["body"];
|
|
9731
9947
|
const status = deps.outboundApiServer.getStatus();
|
|
9732
9948
|
if (!status.running || !status.port) return writeJsonError(res, 503, "outbound server not running");
|
|
9733
|
-
const path2 = resolvePlaygroundPath(endpoint,
|
|
9949
|
+
const path2 = resolvePlaygroundPath(endpoint, isRecord7(payload) ? payload : {});
|
|
9734
9950
|
if (!path2) return writeJsonError(res, 400, `unknown endpoint '${endpoint}'`);
|
|
9735
9951
|
const upstreamBody = typeof payload === "string" ? payload : JSON.stringify(payload ?? {});
|
|
9736
9952
|
await proxyToOutbound(res, status.port, path2, key, upstreamBody);
|
|
9737
9953
|
}
|
|
9738
|
-
function
|
|
9954
|
+
function isRecord7(v) {
|
|
9739
9955
|
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
9740
9956
|
}
|
|
9741
9957
|
function proxyToOutbound(res, outboundPort, path2, key, body) {
|
|
@@ -9870,7 +10086,7 @@ async function handleUiStatic(req, res, urlPath, uiDist) {
|
|
|
9870
10086
|
}
|
|
9871
10087
|
|
|
9872
10088
|
// src/admin/version.ts
|
|
9873
|
-
var DAEMON_VERSION = true ? "0.4.
|
|
10089
|
+
var DAEMON_VERSION = true ? "0.4.1" : "0.0.0-dev";
|
|
9874
10090
|
|
|
9875
10091
|
// src/admin/AdminServer.ts
|
|
9876
10092
|
var LOOPBACK_ADDR = "127.0.0.1";
|
|
@@ -10290,7 +10506,7 @@ function createPoolKeysLoader(getProviderRow, autoDisabled) {
|
|
|
10290
10506
|
|
|
10291
10507
|
// src/allowance/ProviderKeyQuotaService.ts
|
|
10292
10508
|
import { mergeExtraHeaders as mergeExtraHeaders2 } from "@omnicross/core";
|
|
10293
|
-
import { fetchUpstream as
|
|
10509
|
+
import { fetchUpstream as fetchUpstream9 } from "@omnicross/core/pipeline/upstreamFetch";
|
|
10294
10510
|
|
|
10295
10511
|
// src/allowance/ProviderKeyQuota.ts
|
|
10296
10512
|
var MINUTE_MS3 = 6e4;
|
|
@@ -10319,11 +10535,11 @@ function isoInstant3(value) {
|
|
|
10319
10535
|
}
|
|
10320
10536
|
return void 0;
|
|
10321
10537
|
}
|
|
10322
|
-
function
|
|
10538
|
+
function secondsUntil8(instant, now) {
|
|
10323
10539
|
if (!instant) return void 0;
|
|
10324
10540
|
return Math.max(0, Math.floor((Date.parse(instant) - now) / 1e3));
|
|
10325
10541
|
}
|
|
10326
|
-
function
|
|
10542
|
+
function isRecord8(value) {
|
|
10327
10543
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
10328
10544
|
}
|
|
10329
10545
|
function detectProviderKeyQuotaAdapter(baseUrl) {
|
|
@@ -10336,7 +10552,7 @@ function detectProviderKeyQuotaAdapter(baseUrl) {
|
|
|
10336
10552
|
}
|
|
10337
10553
|
const host = url.hostname.toLowerCase();
|
|
10338
10554
|
const path2 = url.pathname.toLowerCase();
|
|
10339
|
-
if ((host === "api.z.ai" || host === "open.bigmodel.cn") && path2.includes("/coding")) {
|
|
10555
|
+
if ((host === "api.z.ai" || host === "open.bigmodel.cn") && (path2.includes("/coding") || path2.includes("/anthropic"))) {
|
|
10340
10556
|
return "zai";
|
|
10341
10557
|
}
|
|
10342
10558
|
if ((host === "api.minimax.io" || host === "api.minimaxi.com") && // Token Plan rides the plain openai `/v1` (chat completions) surface; the
|
|
@@ -10390,17 +10606,17 @@ function zaiWindowIdLabel(durationMs) {
|
|
|
10390
10606
|
return { id: "quota", label: "Quota" };
|
|
10391
10607
|
}
|
|
10392
10608
|
function parseZaiQuotaPayload(payload, now) {
|
|
10393
|
-
if (!
|
|
10394
|
-
const data =
|
|
10609
|
+
if (!isRecord8(payload)) return null;
|
|
10610
|
+
const data = isRecord8(payload["data"]) ? payload["data"] : payload;
|
|
10395
10611
|
if (payload["success"] === false) return null;
|
|
10396
10612
|
const limits = Array.isArray(data["limits"]) ? data["limits"] : [];
|
|
10397
10613
|
const byWindow = /* @__PURE__ */ new Map();
|
|
10398
10614
|
for (const raw of limits) {
|
|
10399
|
-
if (!
|
|
10615
|
+
if (!isRecord8(raw)) continue;
|
|
10400
10616
|
const item = raw;
|
|
10401
10617
|
if (item.type === void 0) continue;
|
|
10402
10618
|
const details = raw["usageDetails"];
|
|
10403
|
-
if (Array.isArray(details) && details.some((d) =>
|
|
10619
|
+
if (Array.isArray(details) && details.some((d) => isRecord8(d) && d["modelCode"] === "zread")) {
|
|
10404
10620
|
continue;
|
|
10405
10621
|
}
|
|
10406
10622
|
const durationMs = zaiWindowDurationMs(item);
|
|
@@ -10419,7 +10635,7 @@ function parseZaiQuotaPayload(payload, now) {
|
|
|
10419
10635
|
usedPercent,
|
|
10420
10636
|
...durationMs !== void 0 ? { windowMinutes: Math.round(durationMs / MINUTE_MS3) } : {},
|
|
10421
10637
|
...resetsAt !== void 0 ? { resetsAt } : {},
|
|
10422
|
-
remainingSeconds:
|
|
10638
|
+
remainingSeconds: secondsUntil8(resetsAt, now),
|
|
10423
10639
|
state: "fresh"
|
|
10424
10640
|
};
|
|
10425
10641
|
const existing = byWindow.get(id);
|
|
@@ -10433,7 +10649,7 @@ function parseZaiQuotaPayload(payload, now) {
|
|
|
10433
10649
|
var MINIMAX_STATUS_EXHAUSTED = 2;
|
|
10434
10650
|
var MINIMAX_SHARED_BUCKET = "general";
|
|
10435
10651
|
function parseMiniMaxBucket(value) {
|
|
10436
|
-
if (!
|
|
10652
|
+
if (!isRecord8(value)) return null;
|
|
10437
10653
|
const modelName = typeof value["model_name"] === "string" ? value["model_name"].trim() : "";
|
|
10438
10654
|
if (!modelName) return null;
|
|
10439
10655
|
const instant = (v) => {
|
|
@@ -10460,14 +10676,14 @@ function minimaxWindow(id, label, windowMinutes, resetsAtMs, remainingPercent, s
|
|
|
10460
10676
|
usedPercent,
|
|
10461
10677
|
...windowMinutes !== void 0 ? { windowMinutes } : {},
|
|
10462
10678
|
...resetsAt !== void 0 ? { resetsAt } : {},
|
|
10463
|
-
remainingSeconds:
|
|
10679
|
+
remainingSeconds: secondsUntil8(resetsAt, now),
|
|
10464
10680
|
state: usedPercent !== null ? "fresh" : "unavailable"
|
|
10465
10681
|
};
|
|
10466
10682
|
}
|
|
10467
10683
|
function parseMiniMaxTokenPlanPayload(payload, now) {
|
|
10468
|
-
if (!
|
|
10684
|
+
if (!isRecord8(payload)) return null;
|
|
10469
10685
|
const baseResp = payload["base_resp"];
|
|
10470
|
-
if (!
|
|
10686
|
+
if (!isRecord8(baseResp) || baseResp["status_code"] !== 0) return null;
|
|
10471
10687
|
const buckets = Array.isArray(payload["model_remains"]) ? payload["model_remains"] : [];
|
|
10472
10688
|
let general = null;
|
|
10473
10689
|
for (const raw of buckets) {
|
|
@@ -10500,11 +10716,11 @@ function parseMiniMaxTokenPlanPayload(payload, now) {
|
|
|
10500
10716
|
];
|
|
10501
10717
|
}
|
|
10502
10718
|
function parseUmansUsagePayload(payload, now) {
|
|
10503
|
-
if (!
|
|
10504
|
-
const limits =
|
|
10505
|
-
const requests = limits &&
|
|
10506
|
-
const usage =
|
|
10507
|
-
const window =
|
|
10719
|
+
if (!isRecord8(payload)) return null;
|
|
10720
|
+
const limits = isRecord8(payload["limits"]) ? payload["limits"] : void 0;
|
|
10721
|
+
const requests = limits && isRecord8(limits["requests"]) ? limits["requests"] : void 0;
|
|
10722
|
+
const usage = isRecord8(payload["usage"]) ? payload["usage"] : void 0;
|
|
10723
|
+
const window = isRecord8(payload["window"]) ? payload["window"] : void 0;
|
|
10508
10724
|
const hardCap = finiteNumber5(requests?.["hard_cap"]);
|
|
10509
10725
|
const softLimit = finiteNumber5(requests?.["limit"]);
|
|
10510
10726
|
const requestsInWindow = finiteNumber5(usage?.["requests_in_window"]);
|
|
@@ -10525,15 +10741,15 @@ function parseUmansUsagePayload(payload, now) {
|
|
|
10525
10741
|
usedPercent,
|
|
10526
10742
|
windowMinutes: 5 * 60,
|
|
10527
10743
|
...resetsAt !== void 0 ? { resetsAt } : {},
|
|
10528
|
-
remainingSeconds:
|
|
10744
|
+
remainingSeconds: secondsUntil8(resetsAt, now),
|
|
10529
10745
|
state: "fresh"
|
|
10530
10746
|
}
|
|
10531
10747
|
];
|
|
10532
10748
|
}
|
|
10533
10749
|
function parseSyntheticQuotasPayload(payload, now) {
|
|
10534
|
-
if (!
|
|
10535
|
-
const fiveHour =
|
|
10536
|
-
const weekly =
|
|
10750
|
+
if (!isRecord8(payload)) return null;
|
|
10751
|
+
const fiveHour = isRecord8(payload["rollingFiveHourLimit"]) ? payload["rollingFiveHourLimit"] : void 0;
|
|
10752
|
+
const weekly = isRecord8(payload["weeklyTokenLimit"]) ? payload["weeklyTokenLimit"] : void 0;
|
|
10537
10753
|
const windows = [];
|
|
10538
10754
|
if (fiveHour) {
|
|
10539
10755
|
const max = finiteNumber5(fiveHour["max"]);
|
|
@@ -10547,7 +10763,7 @@ function parseSyntheticQuotasPayload(payload, now) {
|
|
|
10547
10763
|
usedPercent,
|
|
10548
10764
|
windowMinutes: 5 * 60,
|
|
10549
10765
|
...resetsAt !== void 0 ? { resetsAt } : {},
|
|
10550
|
-
remainingSeconds:
|
|
10766
|
+
remainingSeconds: secondsUntil8(resetsAt, now),
|
|
10551
10767
|
state: usedPercent !== null || resetsAt ? "fresh" : "unavailable"
|
|
10552
10768
|
});
|
|
10553
10769
|
}
|
|
@@ -10562,7 +10778,7 @@ function parseSyntheticQuotasPayload(payload, now) {
|
|
|
10562
10778
|
usedPercent,
|
|
10563
10779
|
windowMinutes: 7 * 24 * 60,
|
|
10564
10780
|
...resetsAt !== void 0 ? { resetsAt } : {},
|
|
10565
|
-
remainingSeconds:
|
|
10781
|
+
remainingSeconds: secondsUntil8(resetsAt, now),
|
|
10566
10782
|
state: usedPercent !== null || resetsAt ? "fresh" : "unavailable"
|
|
10567
10783
|
});
|
|
10568
10784
|
}
|
|
@@ -10574,12 +10790,12 @@ var CLINE_WINDOW_CONFIG = {
|
|
|
10574
10790
|
monthly: { id: "thirty-day", label: "30 days", minutes: 30 * 24 * 60 }
|
|
10575
10791
|
};
|
|
10576
10792
|
function parseClinePassUsageLimitsPayload(payload, now) {
|
|
10577
|
-
if (!
|
|
10578
|
-
const data =
|
|
10793
|
+
if (!isRecord8(payload)) return null;
|
|
10794
|
+
const data = isRecord8(payload["data"]) ? payload["data"] : payload;
|
|
10579
10795
|
const limits = Array.isArray(data["limits"]) ? data["limits"] : [];
|
|
10580
10796
|
const windows = [];
|
|
10581
10797
|
for (const raw of limits) {
|
|
10582
|
-
if (!
|
|
10798
|
+
if (!isRecord8(raw)) continue;
|
|
10583
10799
|
const config = CLINE_WINDOW_CONFIG[typeof raw["type"] === "string" ? raw["type"] : ""];
|
|
10584
10800
|
if (!config) continue;
|
|
10585
10801
|
const usedPercent = finitePercent4(raw["percentUsed"]);
|
|
@@ -10592,7 +10808,7 @@ function parseClinePassUsageLimitsPayload(payload, now) {
|
|
|
10592
10808
|
usedPercent,
|
|
10593
10809
|
windowMinutes: config.minutes,
|
|
10594
10810
|
...resetsAt !== void 0 ? { resetsAt } : {},
|
|
10595
|
-
remainingSeconds:
|
|
10811
|
+
remainingSeconds: secondsUntil8(resetsAt, now),
|
|
10596
10812
|
state: "fresh"
|
|
10597
10813
|
});
|
|
10598
10814
|
}
|
|
@@ -10631,7 +10847,7 @@ function rowKeyEntries(row) {
|
|
|
10631
10847
|
return [];
|
|
10632
10848
|
}
|
|
10633
10849
|
var ProviderKeyQuotaService = class {
|
|
10634
|
-
constructor(box, fetchImpl = (url, init) =>
|
|
10850
|
+
constructor(box, fetchImpl = (url, init) => fetchUpstream9(url, init, { redactBodies: true }), now = Date.now) {
|
|
10635
10851
|
this.box = box;
|
|
10636
10852
|
this.fetchImpl = fetchImpl;
|
|
10637
10853
|
this.now = now;
|
|
@@ -17421,7 +17637,7 @@ import { existsSync as existsSync24, mkdirSync as mkdirSync6, readFileSync as re
|
|
|
17421
17637
|
import { dirname as dirname15 } from "path";
|
|
17422
17638
|
import { getSharedAccountHealth as getSharedAccountHealth2 } from "@omnicross/core/pipeline/SubscriptionAccountHealth";
|
|
17423
17639
|
import { getSharedAccountAllowanceScheduling as getSharedAccountAllowanceScheduling3 } from "@omnicross/core/pipeline/AccountAllowanceScheduling";
|
|
17424
|
-
import { fetchUpstream as
|
|
17640
|
+
import { fetchUpstream as fetchUpstream10 } from "@omnicross/core/pipeline/upstreamFetch";
|
|
17425
17641
|
import { getSharedIdentityStore as getSharedIdentityStore2 } from "@omnicross/core/provider-proxy/identity/SubscriptionIdentityStore";
|
|
17426
17642
|
import {
|
|
17427
17643
|
claudeOAuth as claudeOAuth2,
|
|
@@ -17577,7 +17793,7 @@ var JsonSubscriptionCredentialStore = class {
|
|
|
17577
17793
|
* a plaintext token pair into `upstream-trace.jsonl`.
|
|
17578
17794
|
*/
|
|
17579
17795
|
buildRefreshFetch(providerId, accountId) {
|
|
17580
|
-
return this.fetchImpl ?? ((url, init) =>
|
|
17796
|
+
return this.fetchImpl ?? ((url, init) => fetchUpstream10(url, init, { providerId, accountId, redactBodies: true }));
|
|
17581
17797
|
}
|
|
17582
17798
|
/**
|
|
17583
17799
|
* In-flight refresh coalescing. OAuth refresh tokens are
|
|
@@ -18307,7 +18523,7 @@ var JsonSubscriptionCredentialStore = class {
|
|
|
18307
18523
|
};
|
|
18308
18524
|
|
|
18309
18525
|
// src/AccountHealthProbeScheduler.ts
|
|
18310
|
-
import { fetchUpstream as
|
|
18526
|
+
import { fetchUpstream as fetchUpstream11 } from "@omnicross/core/pipeline/upstreamFetch";
|
|
18311
18527
|
|
|
18312
18528
|
// src/probe/CodexGenerationProbe.ts
|
|
18313
18529
|
import {
|
|
@@ -18484,7 +18700,7 @@ var AccountHealthProbeScheduler = class {
|
|
|
18484
18700
|
this.logger = logger;
|
|
18485
18701
|
this.config = config;
|
|
18486
18702
|
this.now = opts.now ?? Date.now;
|
|
18487
|
-
this.fetchImpl = opts.fetchImpl ??
|
|
18703
|
+
this.fetchImpl = opts.fetchImpl ?? fetchUpstream11;
|
|
18488
18704
|
this.sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
18489
18705
|
this.planFor = opts.planFor ?? probePlanFor;
|
|
18490
18706
|
}
|
|
@@ -19647,7 +19863,7 @@ var AuditWriter = class {
|
|
|
19647
19863
|
import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync8 } from "fs";
|
|
19648
19864
|
import { createHmac as createHmac5 } from "crypto";
|
|
19649
19865
|
import { join as join27 } from "path";
|
|
19650
|
-
import { fetchUpstream as
|
|
19866
|
+
import { fetchUpstream as fetchUpstream12 } from "@omnicross/core/pipeline/upstreamFetch";
|
|
19651
19867
|
|
|
19652
19868
|
// src/billing/billingFiles.ts
|
|
19653
19869
|
var BILLING_FILE_RE = /^billing-(\d{4})-(\d{2})-(\d{2})\.jsonl$/;
|
|
@@ -19670,7 +19886,7 @@ var BillingPublisher = class {
|
|
|
19670
19886
|
constructor(billingDir, logger, opts = {}) {
|
|
19671
19887
|
this.billingDir = billingDir;
|
|
19672
19888
|
this.logger = logger;
|
|
19673
|
-
this.fetchImpl = opts.fetchImpl ?? ((url, init) =>
|
|
19889
|
+
this.fetchImpl = opts.fetchImpl ?? ((url, init) => fetchUpstream12(url, init));
|
|
19674
19890
|
this.defer = opts.defer ?? ((fn) => setTimeout(fn, 0));
|
|
19675
19891
|
this.timeoutMs = opts.timeoutMs ?? BILLING_POST_TIMEOUT_MS;
|
|
19676
19892
|
this.now = opts.now ?? Date.now;
|
|
@@ -20089,7 +20305,7 @@ function createRouteLeaseSubscriptionPreflight(credentials) {
|
|
|
20089
20305
|
|
|
20090
20306
|
// src/webhook/WebhookDispatcher.ts
|
|
20091
20307
|
import { createHmac as createHmac6 } from "crypto";
|
|
20092
|
-
import { fetchUpstream as
|
|
20308
|
+
import { fetchUpstream as fetchUpstream13 } from "@omnicross/core/pipeline/upstreamFetch";
|
|
20093
20309
|
var WEBHOOK_MAX_ATTEMPTS = 3;
|
|
20094
20310
|
var WEBHOOK_QUEUE_MAX = 1e3;
|
|
20095
20311
|
var WEBHOOK_SEND_TIMEOUT_MS = 1e4;
|
|
@@ -20109,7 +20325,7 @@ var WebhookDispatcher = class {
|
|
|
20109
20325
|
sleep;
|
|
20110
20326
|
now;
|
|
20111
20327
|
constructor(opts = {}) {
|
|
20112
|
-
this.fetchImpl = opts.fetchImpl ?? ((url, init) =>
|
|
20328
|
+
this.fetchImpl = opts.fetchImpl ?? ((url, init) => fetchUpstream13(url, init));
|
|
20113
20329
|
this.logger = opts.logger;
|
|
20114
20330
|
this.maxAttempts = opts.maxAttempts ?? WEBHOOK_MAX_ATTEMPTS;
|
|
20115
20331
|
this.queueMax = opts.queueMax ?? WEBHOOK_QUEUE_MAX;
|
|
@@ -20333,7 +20549,7 @@ function buildDaemon(config, paths) {
|
|
|
20333
20549
|
setSecretBox(secretBox3);
|
|
20334
20550
|
setSecretBox2(secretBox3);
|
|
20335
20551
|
const decryptedConfig = decryptConfigSecrets(config, secretBox3);
|
|
20336
|
-
const accountAllowanceStore = new
|
|
20552
|
+
const accountAllowanceStore = new AccountAllowanceStore9(
|
|
20337
20553
|
Date.now,
|
|
20338
20554
|
void 0,
|
|
20339
20555
|
new JsonAccountAllowancePersistence(defaultAccountAllowancePath(paths.configPath))
|
|
@@ -20376,7 +20592,7 @@ function buildDaemon(config, paths) {
|
|
|
20376
20592
|
getAccountProxy: (providerId, accountId) => credentialStore.getAccountProxy(providerId, accountId)
|
|
20377
20593
|
})
|
|
20378
20594
|
);
|
|
20379
|
-
setGeminiCodeAssistResolver(
|
|
20595
|
+
setGeminiCodeAssistResolver(getGeminiCodeAssistProjectResolver2());
|
|
20380
20596
|
const autoDisableStore = new AutoDisableStore();
|
|
20381
20597
|
const providerKeyQuotaService = new ProviderKeyQuotaService(secretBox3);
|
|
20382
20598
|
const apiKeyPool = new ApiKeyPoolService(
|
|
@@ -20395,7 +20611,7 @@ function buildDaemon(config, paths) {
|
|
|
20395
20611
|
const pricingEngine = new PricingEngine(pricingStore, logger, {
|
|
20396
20612
|
// Catalog egress follows the same global/env proxy policy as every other
|
|
20397
20613
|
// daemon upstream call; no provider/account override applies here.
|
|
20398
|
-
fetchImpl: ((input, init) =>
|
|
20614
|
+
fetchImpl: ((input, init) => fetchUpstream14(String(input), init ?? {}))
|
|
20399
20615
|
});
|
|
20400
20616
|
const pricingRefreshScheduler = new PricingRefreshScheduler(
|
|
20401
20617
|
pricingEngine,
|
|
@@ -20680,7 +20896,7 @@ function buildDaemon(config, paths) {
|
|
|
20680
20896
|
// — `server.proxy.byProvider[...]` was silently skipped — and the call was
|
|
20681
20897
|
// excluded from the upstream trace, so a failing login left no evidence.
|
|
20682
20898
|
// `redactBodies` keeps the code/verifier + minted token out of that trace.
|
|
20683
|
-
oauthExchangeFetch: paths.oauthExchangeFetch ? () => paths.oauthExchangeFetch : (providerId) => (url, init) =>
|
|
20899
|
+
oauthExchangeFetch: paths.oauthExchangeFetch ? () => paths.oauthExchangeFetch : (providerId) => (url, init) => fetchUpstream14(url, init, { providerId, redactBodies: true }),
|
|
20684
20900
|
subscriptionAccountAppender: credentialStore,
|
|
20685
20901
|
// Codex interactive OAuth (app-parity-2 child 5) — the async loopback flow store
|
|
20686
20902
|
// + the one-shot 127.0.0.1:1455 listener. Token captured + persisted daemon-side;
|
|
@@ -20753,7 +20969,7 @@ function buildDaemon(config, paths) {
|
|
|
20753
20969
|
});
|
|
20754
20970
|
const webhookDispatcher = new WebhookDispatcher({
|
|
20755
20971
|
logger,
|
|
20756
|
-
fetchImpl: (url, init) =>
|
|
20972
|
+
fetchImpl: (url, init) => fetchUpstream14(url, init)
|
|
20757
20973
|
});
|
|
20758
20974
|
setWebhookRuntime(webhookDispatcher, getSharedAccountHealth4());
|
|
20759
20975
|
const auditWriter = new AuditWriter(auditDir, logger);
|
|
@@ -21621,7 +21837,7 @@ function spawnCliInherit(plan) {
|
|
|
21621
21837
|
import { spawn as spawn3 } from "child_process";
|
|
21622
21838
|
import { createInterface as createInterface2 } from "readline";
|
|
21623
21839
|
import { parseArgs as parseArgs7 } from "util";
|
|
21624
|
-
import { fetchUpstream as
|
|
21840
|
+
import { fetchUpstream as fetchUpstream15, setUpstreamProxyResolver as setUpstreamProxyResolver2 } from "@omnicross/core/pipeline/upstreamFetch";
|
|
21625
21841
|
import {
|
|
21626
21842
|
claudeOAuth as claudeOAuth3,
|
|
21627
21843
|
codexOAuth as codexOAuth3,
|
|
@@ -21673,7 +21889,7 @@ async function runLogin(argv, deps) {
|
|
|
21673
21889
|
setUpstreamProxyResolver2(createUpstreamProxyResolver());
|
|
21674
21890
|
try {
|
|
21675
21891
|
const tokensPath = defaultTokensPath(values.config);
|
|
21676
|
-
const exchangeFetch = resolved.tokensFetch ?? ((url, init) =>
|
|
21892
|
+
const exchangeFetch = resolved.tokensFetch ?? ((url, init) => fetchUpstream15(url, init, { providerId: provider, redactBodies: true }));
|
|
21677
21893
|
const store = new JsonSubscriptionCredentialStore(tokensPath, box, exchangeFetch);
|
|
21678
21894
|
const expiresAt = await runProviderLogin(
|
|
21679
21895
|
provider,
|