@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 CHANGED
@@ -1171,14 +1171,14 @@ var import_node_path36 = require("path");
1171
1171
  var import_audit_types = require("@omnicross/contracts/audit-types");
1172
1172
  var import_billing_types = require("@omnicross/contracts/billing-types");
1173
1173
  var import_core7 = require("@omnicross/core");
1174
- var import_GeminiCodeAssistProjectResolver = require("@omnicross/core/auth/GeminiCodeAssistProjectResolver");
1174
+ var import_GeminiCodeAssistProjectResolver2 = require("@omnicross/core/auth/GeminiCodeAssistProjectResolver");
1175
1175
  var import_ApiKeyPoolService = require("@omnicross/core/completion/ApiKeyPoolService");
1176
1176
  var import_outbound_api10 = require("@omnicross/core/outbound-api");
1177
1177
  var import_subscriptionRegistryPort = require("@omnicross/core/outbound-api/subscriptionRegistryPort");
1178
1178
  var import_SubscriptionAccountHealth4 = require("@omnicross/core/pipeline/SubscriptionAccountHealth");
1179
- var import_AccountAllowanceStore9 = require("@omnicross/core/pipeline/AccountAllowanceStore");
1179
+ var import_AccountAllowanceStore10 = require("@omnicross/core/pipeline/AccountAllowanceStore");
1180
1180
  var import_AccountAllowanceScheduling5 = require("@omnicross/core/pipeline/AccountAllowanceScheduling");
1181
- var import_upstreamFetch15 = require("@omnicross/core/pipeline/upstreamFetch");
1181
+ var import_upstreamFetch16 = require("@omnicross/core/pipeline/upstreamFetch");
1182
1182
  var import_SubscriptionIdentityStore3 = require("@omnicross/core/provider-proxy/identity/SubscriptionIdentityStore");
1183
1183
  var import_gemini_code_assist_resolver = require("@omnicross/core/ports/gemini-code-assist-resolver");
1184
1184
  var import_provider_proxy4 = require("@omnicross/core/provider-proxy");
@@ -1547,7 +1547,7 @@ function handleCopilotOAuthStatus(sessionId, deps) {
1547
1547
  }
1548
1548
 
1549
1549
  // src/allowance/AccountAllowanceService.ts
1550
- var import_AccountAllowanceStore7 = require("@omnicross/core/pipeline/AccountAllowanceStore");
1550
+ var import_AccountAllowanceStore8 = require("@omnicross/core/pipeline/AccountAllowanceStore");
1551
1551
  var import_AccountAllowanceScheduling = require("@omnicross/core/pipeline/AccountAllowanceScheduling");
1552
1552
 
1553
1553
  // src/allowance/ClaudeAllowanceCollector.ts
@@ -2735,9 +2735,191 @@ var CopilotAllowanceCollector = class {
2735
2735
  }
2736
2736
  };
2737
2737
 
2738
- // src/allowance/OpenCodeGoAllowanceCollector.ts
2738
+ // src/allowance/GeminiAllowanceCollector.ts
2739
+ var import_GeminiCodeAssistProjectResolver = require("@omnicross/core/auth/GeminiCodeAssistProjectResolver");
2739
2740
  var import_AccountAllowanceStore6 = require("@omnicross/core/pipeline/AccountAllowanceStore");
2740
2741
  var import_upstreamFetch6 = require("@omnicross/core/pipeline/upstreamFetch");
2742
+ var import_transformers = require("@omnicross/core/transformer/transformers");
2743
+ var GEMINI_ALLOWANCE_CACHE_MS = 5 * 6e4;
2744
+ function isRecord4(value) {
2745
+ return !!value && typeof value === "object" && !Array.isArray(value);
2746
+ }
2747
+ function secondsUntil6(instant, now) {
2748
+ if (!instant) return void 0;
2749
+ return Math.max(0, Math.floor((Date.parse(instant) - now) / 1e3));
2750
+ }
2751
+ function parseGeminiQuotaPayload(payload, now) {
2752
+ if (!isRecord4(payload)) return null;
2753
+ const buckets = Array.isArray(payload["buckets"]) ? payload["buckets"] : [];
2754
+ const windows = [];
2755
+ const seen = /* @__PURE__ */ new Set();
2756
+ for (const raw of buckets) {
2757
+ if (!isRecord4(raw)) continue;
2758
+ const modelId = typeof raw["modelId"] === "string" && raw["modelId"].trim() ? raw["modelId"].trim() : void 0;
2759
+ const id = `gemini:${modelId ?? "all"}`;
2760
+ if (seen.has(id)) continue;
2761
+ seen.add(id);
2762
+ const fractionRaw = typeof raw["remainingFraction"] === "number" ? raw["remainingFraction"] : Number(raw["remainingFraction"]);
2763
+ 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;
2764
+ const resetRaw = typeof raw["resetTime"] === "string" && raw["resetTime"].trim() ? raw["resetTime"] : void 0;
2765
+ const resetsAt = resetRaw !== void 0 && Number.isFinite(Date.parse(resetRaw)) ? new Date(Date.parse(resetRaw)).toISOString() : void 0;
2766
+ windows.push({
2767
+ id,
2768
+ label: modelId ? `Gemini ${modelId}` : "Gemini quota",
2769
+ scope: modelId ? "model-family" : "all",
2770
+ ...modelId ? { modelFamily: modelId } : {},
2771
+ usedPercent,
2772
+ ...resetsAt !== void 0 ? { resetsAt } : {},
2773
+ remainingSeconds: secondsUntil6(resetsAt, now),
2774
+ state: "fresh"
2775
+ });
2776
+ }
2777
+ return windows.length > 0 ? windows : null;
2778
+ }
2779
+ var GeminiAllowanceCollector = class {
2780
+ constructor(credentials, store = (0, import_AccountAllowanceStore6.getSharedAccountAllowanceStore)(), fetchImpl = (url, init, accountId) => (0, import_upstreamFetch6.fetchUpstream)(url, init, { providerId: "gemini", accountId, redactBodies: true }), now = Date.now, projectResolver = (0, import_GeminiCodeAssistProjectResolver.getGeminiCodeAssistProjectResolver)()) {
2781
+ this.credentials = credentials;
2782
+ this.store = store;
2783
+ this.fetchImpl = fetchImpl;
2784
+ this.now = now;
2785
+ this.projectResolver = projectResolver;
2786
+ }
2787
+ credentials;
2788
+ store;
2789
+ fetchImpl;
2790
+ now;
2791
+ projectResolver;
2792
+ inFlight = /* @__PURE__ */ new Map();
2793
+ async collectMany(accounts, options = {}) {
2794
+ const settled = await Promise.allSettled(
2795
+ accounts.map((account) => this.collect(account, options))
2796
+ );
2797
+ return settled.flatMap((result) => result.status === "fulfilled" ? [result.value] : []);
2798
+ }
2799
+ collect(account, options = {}) {
2800
+ const now = this.now();
2801
+ if (account.tokens.authMethod !== "oauth") {
2802
+ const existing = this.store.get("gemini", account.id, now);
2803
+ if (existing?.windows.every((window) => window.state === "unsupported")) {
2804
+ return Promise.resolve(existing);
2805
+ }
2806
+ const snapshot = this.unsupportedSnapshot(account.id, now);
2807
+ this.store.set(snapshot);
2808
+ return Promise.resolve(snapshot);
2809
+ }
2810
+ const cached = this.store.get("gemini", account.id, now);
2811
+ if (!options.force && cached && this.isCacheValid(cached, now, options.refreshAheadMs)) {
2812
+ return Promise.resolve(cached);
2813
+ }
2814
+ const running = this.inFlight.get(account.id);
2815
+ if (running) return running;
2816
+ const promise = this.fetchAccount(account.id).catch(() => this.failureSnapshot(account.id, "gemini_usage_request_failed", this.now())).finally(() => this.inFlight.delete(account.id));
2817
+ this.inFlight.set(account.id, promise);
2818
+ return promise;
2819
+ }
2820
+ isCacheValid(snapshot, now, refreshAheadMs) {
2821
+ if (snapshot.windows.every((window) => window.state === "unsupported")) return true;
2822
+ const expiresAt = snapshot.expiresAt ? Date.parse(snapshot.expiresAt) : 0;
2823
+ const ahead = typeof refreshAheadMs === "number" && Number.isFinite(refreshAheadMs) ? Math.max(0, refreshAheadMs) : 0;
2824
+ return Number.isFinite(expiresAt) && expiresAt > now + ahead;
2825
+ }
2826
+ async fetchAccount(accountId) {
2827
+ let accessToken = await this.credentials.getAccessTokenForAccount("gemini", accountId);
2828
+ if (!accessToken) return this.failureSnapshot(accountId, "gemini_usage_token_unavailable", this.now());
2829
+ let project;
2830
+ try {
2831
+ project = await this.projectResolver.resolveProject(accessToken);
2832
+ } catch {
2833
+ project = void 0;
2834
+ }
2835
+ let response = await this.request(accountId, accessToken, project);
2836
+ if (response.status === 401 || response.status === 403) {
2837
+ const refreshed = await this.credentials.refreshAccountToken("gemini", accountId);
2838
+ if (!refreshed) return this.failureSnapshot(accountId, "gemini_usage_unauthorized", this.now());
2839
+ accessToken = await this.credentials.getAccessTokenForAccount("gemini", accountId);
2840
+ if (!accessToken) return this.failureSnapshot(accountId, "gemini_usage_token_unavailable", this.now());
2841
+ response = await this.request(accountId, accessToken, project);
2842
+ if (response.status === 401 || response.status === 403) {
2843
+ return this.failureSnapshot(accountId, "gemini_usage_unauthorized", this.now());
2844
+ }
2845
+ }
2846
+ if (!response.ok) return this.failureSnapshot(accountId, "gemini_usage_http_error", this.now());
2847
+ let payload;
2848
+ try {
2849
+ payload = await response.json();
2850
+ } catch {
2851
+ return this.failureSnapshot(accountId, "gemini_usage_invalid_response", this.now());
2852
+ }
2853
+ const now = this.now();
2854
+ const windows = parseGeminiQuotaPayload(payload, now);
2855
+ const snapshot = {
2856
+ providerId: "gemini",
2857
+ accountId,
2858
+ source: "oauth-usage-api",
2859
+ observedAt: new Date(now).toISOString(),
2860
+ expiresAt: new Date(now + GEMINI_ALLOWANCE_CACHE_MS).toISOString(),
2861
+ windows: windows ?? [
2862
+ { id: "gemini-quota", label: "Gemini quota", scope: "all", usedPercent: null, state: "unavailable" }
2863
+ ],
2864
+ ...windows ? {} : { lastErrorCode: "gemini_usage_invalid_response" }
2865
+ };
2866
+ this.store.set(snapshot);
2867
+ return snapshot;
2868
+ }
2869
+ request(accountId, accessToken, project) {
2870
+ return this.fetchImpl(`${(0, import_transformers.resolveCodeAssistEndpoint)()}/v1internal:retrieveUserQuota`, {
2871
+ method: "POST",
2872
+ headers: {
2873
+ Authorization: `Bearer ${accessToken}`,
2874
+ Accept: "application/json",
2875
+ "Content-Type": "application/json",
2876
+ ...(0, import_transformers.getGeminiCliIdentityHeaders)()
2877
+ },
2878
+ body: JSON.stringify(project ? { project } : {}),
2879
+ signal: AbortSignal.timeout(15e3)
2880
+ }, accountId);
2881
+ }
2882
+ failureSnapshot(accountId, code, now) {
2883
+ const existing = this.store.get("gemini", accountId, now);
2884
+ const snapshot = existing ? {
2885
+ ...existing,
2886
+ expiresAt: new Date(now + GEMINI_ALLOWANCE_CACHE_MS).toISOString(),
2887
+ windows: existing.windows.map((window) => ({
2888
+ ...window,
2889
+ state: window.state === "unsupported" ? "unsupported" : window.usedPercent !== null || window.resetsAt ? "stale" : "unavailable"
2890
+ })),
2891
+ lastErrorCode: code
2892
+ } : {
2893
+ providerId: "gemini",
2894
+ accountId,
2895
+ source: "oauth-usage-api",
2896
+ observedAt: new Date(now).toISOString(),
2897
+ expiresAt: new Date(now + GEMINI_ALLOWANCE_CACHE_MS).toISOString(),
2898
+ windows: [
2899
+ { id: "gemini-quota", label: "Gemini quota", scope: "all", usedPercent: null, state: "unavailable" }
2900
+ ],
2901
+ lastErrorCode: code
2902
+ };
2903
+ this.store.set(snapshot);
2904
+ return snapshot;
2905
+ }
2906
+ unsupportedSnapshot(accountId, now) {
2907
+ return {
2908
+ providerId: "gemini",
2909
+ accountId,
2910
+ source: "oauth-usage-api",
2911
+ observedAt: new Date(now).toISOString(),
2912
+ windows: [
2913
+ { id: "gemini-quota", label: "Gemini quota", scope: "all", usedPercent: null, state: "unsupported" }
2914
+ ],
2915
+ lastErrorCode: "gemini_usage_unsupported_auth"
2916
+ };
2917
+ }
2918
+ };
2919
+
2920
+ // src/allowance/OpenCodeGoAllowanceCollector.ts
2921
+ var import_AccountAllowanceStore7 = require("@omnicross/core/pipeline/AccountAllowanceStore");
2922
+ var import_upstreamFetch7 = require("@omnicross/core/pipeline/upstreamFetch");
2741
2923
  var import_subscriptions7 = require("@omnicross/subscriptions");
2742
2924
  var OPENCODEGO_ALLOWANCE_CACHE_MS = 5 * 6e4;
2743
2925
  var OPENCODEGO_DEFAULT_GO_BASE = "https://opencode.ai/zen/go";
@@ -2751,7 +2933,7 @@ function isoInstant2(value) {
2751
2933
  const time = Date.parse(value);
2752
2934
  return Number.isFinite(time) ? new Date(time).toISOString() : void 0;
2753
2935
  }
2754
- function secondsUntil6(instant, now) {
2936
+ function secondsUntil7(instant, now) {
2755
2937
  if (!instant) return void 0;
2756
2938
  return Math.max(0, Math.floor((Date.parse(instant) - now) / 1e3));
2757
2939
  }
@@ -2766,12 +2948,12 @@ function windowFromPayload3(id, label, minutes, payload, now) {
2766
2948
  usedPercent,
2767
2949
  windowMinutes: minutes,
2768
2950
  ...resetsAt !== void 0 ? { resetsAt } : {},
2769
- remainingSeconds: secondsUntil6(resetsAt, now),
2951
+ remainingSeconds: secondsUntil7(resetsAt, now),
2770
2952
  state: usedPercent !== null || resetsAt ? "fresh" : "unavailable"
2771
2953
  };
2772
2954
  }
2773
2955
  var OpenCodeGoAllowanceCollector = class {
2774
- constructor(credentials, store = (0, import_AccountAllowanceStore6.getSharedAccountAllowanceStore)(), fetchImpl = (url, init, accountId) => (0, import_upstreamFetch6.fetchUpstream)(url, init, { providerId: "opencodego", accountId, redactBodies: true }), now = Date.now) {
2956
+ constructor(credentials, store = (0, import_AccountAllowanceStore7.getSharedAccountAllowanceStore)(), fetchImpl = (url, init, accountId) => (0, import_upstreamFetch7.fetchUpstream)(url, init, { providerId: "opencodego", accountId, redactBodies: true }), now = Date.now) {
2775
2957
  this.credentials = credentials;
2776
2958
  this.store = store;
2777
2959
  this.fetchImpl = fetchImpl;
@@ -2876,7 +3058,7 @@ function codexUnavailable(accountId, now) {
2876
3058
  };
2877
3059
  }
2878
3060
  var AccountAllowanceService = class {
2879
- constructor(credentials, store = (0, import_AccountAllowanceStore7.getSharedAccountAllowanceStore)(), collector, codexCollector, kimiCollector, opencodegoCollector, grokCollector, copilotCollector, now = Date.now) {
3061
+ constructor(credentials, store = (0, import_AccountAllowanceStore8.getSharedAccountAllowanceStore)(), collector, codexCollector, kimiCollector, opencodegoCollector, grokCollector, copilotCollector, geminiCollector, now = Date.now) {
2880
3062
  this.credentials = credentials;
2881
3063
  this.store = store;
2882
3064
  this.now = now;
@@ -2886,6 +3068,7 @@ var AccountAllowanceService = class {
2886
3068
  this.opencodegoCollector = opencodegoCollector ?? new OpenCodeGoAllowanceCollector(credentials, store);
2887
3069
  this.grokCollector = grokCollector ?? new GrokAllowanceCollector(credentials, store);
2888
3070
  this.copilotCollector = copilotCollector ?? new CopilotAllowanceCollector(credentials, store);
3071
+ this.geminiCollector = geminiCollector ?? new GeminiAllowanceCollector(credentials, store);
2889
3072
  }
2890
3073
  credentials;
2891
3074
  store;
@@ -2896,6 +3079,7 @@ var AccountAllowanceService = class {
2896
3079
  grokCollector;
2897
3080
  copilotCollector;
2898
3081
  opencodegoCollector;
3082
+ geminiCollector;
2899
3083
  /**
2900
3084
  * Read all/filtered snapshots. Claude's and Codex's five-minute caches are
2901
3085
  * refreshed lazily on read (Codex polls `/backend-api/wham/usage`; the
@@ -2939,6 +3123,11 @@ var AccountAllowanceService = class {
2939
3123
  (account) => !filter.accountId || account.id === filter.accountId
2940
3124
  );
2941
3125
  if (wantsCopilot) await this.copilotCollector.collectMany(copilotAccounts);
3126
+ const wantsGemini = !filter.providerId || filter.providerId === "gemini";
3127
+ const geminiAccounts = (config.geminiAccounts ?? []).filter(
3128
+ (account) => !filter.accountId || account.id === filter.accountId
3129
+ );
3130
+ if (wantsGemini) await this.geminiCollector.collectMany(geminiAccounts);
2942
3131
  const known = /* @__PURE__ */ new Set();
2943
3132
  if (wantsClaude) for (const account of claudeAccounts) known.add(`claude\0${account.id}`);
2944
3133
  if (wantsCodex) for (const account of codexAccounts) known.add(`codex\0${account.id}`);
@@ -2946,6 +3135,7 @@ var AccountAllowanceService = class {
2946
3135
  if (wantsOpenCodeGo) for (const account of opencodegoAccounts) known.add(`opencodego\0${account.id}`);
2947
3136
  if (wantsGrok) for (const account of grokAccounts) known.add(`grok\0${account.id}`);
2948
3137
  if (wantsCopilot) for (const account of copilotAccounts) known.add(`copilot\0${account.id}`);
3138
+ if (wantsGemini) for (const account of geminiAccounts) known.add(`gemini\0${account.id}`);
2949
3139
  return this.store.list(filter).filter((snapshot) => known.has(`${snapshot.providerId}\0${snapshot.accountId}`));
2950
3140
  }
2951
3141
  knownAccounts(config) {
@@ -2955,7 +3145,8 @@ var AccountAllowanceService = class {
2955
3145
  ...(config.kimiAccounts ?? []).map((account) => ({ providerId: "kimi", accountId: account.id })),
2956
3146
  ...(config.opencodegoAccounts ?? []).map((account) => ({ providerId: "opencodego", accountId: account.id })),
2957
3147
  ...(config.grokAccounts ?? []).map((account) => ({ providerId: "grok", accountId: account.id })),
2958
- ...(config.copilotAccounts ?? []).map((account) => ({ providerId: "copilot", accountId: account.id }))
3148
+ ...(config.copilotAccounts ?? []).map((account) => ({ providerId: "copilot", accountId: account.id })),
3149
+ ...(config.geminiAccounts ?? []).map((account) => ({ providerId: "gemini", accountId: account.id }))
2959
3150
  ];
2960
3151
  }
2961
3152
  /** Force-refresh Claude usage for one account or every stored Claude account. */
@@ -3016,6 +3207,15 @@ var AccountAllowanceService = class {
3016
3207
  );
3017
3208
  return this.grokCollector.collectMany(accounts, { force: true });
3018
3209
  }
3210
+ /** Force-refresh Gemini usage (Code Assist retrieveUserQuota) for one/all accounts. */
3211
+ async refreshGemini(accountId) {
3212
+ const config = await this.credentials.getFullConfig();
3213
+ this.store.pruneToKnownAccounts(this.knownAccounts(config));
3214
+ const accounts = (config.geminiAccounts ?? []).filter(
3215
+ (account) => !accountId || account.id === accountId
3216
+ );
3217
+ return this.geminiCollector.collectMany(accounts, { force: true });
3218
+ }
3019
3219
  /**
3020
3220
  * Keep Claude + Codex + Kimi snapshots warm for allowance-aware routing. All
3021
3221
  * collectors preserve their cache + per-account in-flight coalescing; a tick
@@ -3032,6 +3232,7 @@ var AccountAllowanceService = class {
3032
3232
  await this.opencodegoCollector.collectMany(config.opencodegoAccounts ?? [], { refreshAheadMs });
3033
3233
  await this.grokCollector.collectMany(config.grokAccounts ?? [], { refreshAheadMs });
3034
3234
  await this.copilotCollector.collectMany(config.copilotAccounts ?? [], { refreshAheadMs });
3235
+ await this.geminiCollector.collectMany(config.geminiAccounts ?? [], { refreshAheadMs });
3035
3236
  }
3036
3237
  /** Remove a cache row as soon as an account is deleted by the admin path. */
3037
3238
  removeAccountSnapshot(providerId, accountId) {
@@ -3126,7 +3327,7 @@ var ClaudeAllowanceRefreshScheduler = class {
3126
3327
  var import_node_crypto4 = require("crypto");
3127
3328
  var import_node_fs6 = require("fs");
3128
3329
  var import_node_path6 = require("path");
3129
- var import_AccountAllowanceStore8 = require("@omnicross/core/pipeline/AccountAllowanceStore");
3330
+ var import_AccountAllowanceStore9 = require("@omnicross/core/pipeline/AccountAllowanceStore");
3130
3331
  var ACCOUNT_ALLOWANCE_CACHE_VERSION = 1;
3131
3332
  var MAX_PERSISTED_ALLOWANCE_SNAPSHOTS = 256;
3132
3333
  var MAX_ALLOWANCE_CACHE_BYTES = 1e6;
@@ -3155,7 +3356,7 @@ var JsonAccountAllowancePersistence = class {
3155
3356
  save(snapshots) {
3156
3357
  const rows = [];
3157
3358
  for (const snapshot of snapshots) {
3158
- const normalized2 = (0, import_AccountAllowanceStore8.normalizeAccountAllowanceSnapshot)(snapshot);
3359
+ const normalized2 = (0, import_AccountAllowanceStore9.normalizeAccountAllowanceSnapshot)(snapshot);
3159
3360
  if (!normalized2) continue;
3160
3361
  rows.push(normalized2);
3161
3362
  if (rows.length >= MAX_PERSISTED_ALLOWANCE_SNAPSHOTS) break;
@@ -3431,7 +3632,7 @@ var import_outbound_api5 = require("@omnicross/core/outbound-api");
3431
3632
  var import_image_generation_types = require("@omnicross/contracts/image-generation-types");
3432
3633
  var import_AccountAllowanceScheduling2 = require("@omnicross/core/pipeline/AccountAllowanceScheduling");
3433
3634
  var import_SubscriptionAccountHealth = require("@omnicross/core/pipeline/SubscriptionAccountHealth");
3434
- var import_upstreamFetch9 = require("@omnicross/core/pipeline/upstreamFetch");
3635
+ var import_upstreamFetch10 = require("@omnicross/core/pipeline/upstreamFetch");
3435
3636
  var import_core3 = require("@omnicross/core");
3436
3637
 
3437
3638
  // src/image-generation/imagesConfigValidation.ts
@@ -5085,11 +5286,11 @@ function preserveOutboundProxySecrets(incoming, current) {
5085
5286
  }
5086
5287
 
5087
5288
  // src/proxy/upstreamProxyResolver.ts
5088
- var import_upstreamFetch7 = require("@omnicross/core/pipeline/upstreamFetch");
5289
+ var import_upstreamFetch8 = require("@omnicross/core/pipeline/upstreamFetch");
5089
5290
  var serverProxy;
5090
5291
  function setServerProxyConfig(proxy) {
5091
5292
  serverProxy = proxy;
5092
- (0, import_upstreamFetch7.bumpUpstreamProxyGeneration)();
5293
+ (0, import_upstreamFetch8.bumpUpstreamProxyGeneration)();
5093
5294
  }
5094
5295
  function getServerProxyConfig() {
5095
5296
  return serverProxy;
@@ -6152,7 +6353,7 @@ async function runSearchLiveChecks(contributions, now = () => (/* @__PURE__ */ n
6152
6353
  }
6153
6354
 
6154
6355
  // src/search/SearchAssembly.ts
6155
- var import_upstreamFetch8 = require("@omnicross/core/pipeline/upstreamFetch");
6356
+ var import_upstreamFetch9 = require("@omnicross/core/pipeline/upstreamFetch");
6156
6357
  var import_search = require("@omnicross/core/search");
6157
6358
  var import_api2 = require("@omnicross/core/search/api");
6158
6359
  var import_http2 = require("@omnicross/core/search/http");
@@ -6170,7 +6371,7 @@ function searchPolicyFrom(config) {
6170
6371
  };
6171
6372
  }
6172
6373
  function resolveSearchUpstreamDispatcher(url) {
6173
- return (0, import_upstreamFetch8.resolveUpstreamDispatcher)({ url });
6374
+ return (0, import_upstreamFetch9.resolveUpstreamDispatcher)({ url });
6174
6375
  }
6175
6376
  var searchUpstreamProxyConfig = createUpstreamProxyResolver();
6176
6377
  function resolveSearchUpstreamProxyConfig(url) {
@@ -6452,7 +6653,7 @@ async function handleSearchQuery(req, res, deps) {
6452
6653
  // src/admin/searchAdminView.ts
6453
6654
  var API_KEY_PROVIDERS = /* @__PURE__ */ new Set(["tavily", "jina", "zhipu", "z.ai"]);
6454
6655
  var BASIC_AUTH_PROVIDERS = /* @__PURE__ */ new Set(["searxng"]);
6455
- function isRecord4(value) {
6656
+ function isRecord5(value) {
6456
6657
  return value !== null && typeof value === "object" && !Array.isArray(value);
6457
6658
  }
6458
6659
  function redactSearchServerConfig(search) {
@@ -6502,13 +6703,13 @@ function resolveSecretField(entry, field, stored) {
6502
6703
  else delete entry[field];
6503
6704
  }
6504
6705
  function preserveSearchSecrets(incoming, current) {
6505
- if (!isRecord4(incoming)) return incoming;
6706
+ if (!isRecord5(incoming)) return incoming;
6506
6707
  const section = { ...incoming };
6507
6708
  const providersValue = section["providers"];
6508
- if (!isRecord4(providersValue)) return section;
6709
+ if (!isRecord5(providersValue)) return section;
6509
6710
  const providers = {};
6510
6711
  for (const [id, entryValue] of Object.entries(providersValue)) {
6511
- if (!isRecord4(entryValue)) {
6712
+ if (!isRecord5(entryValue)) {
6512
6713
  providers[id] = entryValue;
6513
6714
  continue;
6514
6715
  }
@@ -6586,7 +6787,7 @@ function parseKeyPolicyBody(body) {
6586
6787
  var ENDPOINTS = /* @__PURE__ */ new Set(["chat", "responses", "messages", "gemini"]);
6587
6788
  var TARGET_KINDS = /* @__PURE__ */ new Set(["account", "account-group", "account-pool", "provider"]);
6588
6789
  var FALLBACKS = /* @__PURE__ */ new Set(["next", "fail", "global"]);
6589
- function isRecord5(value) {
6790
+ function isRecord6(value) {
6590
6791
  return !!value && typeof value === "object" && !Array.isArray(value);
6591
6792
  }
6592
6793
  function nonBlank(value) {
@@ -6606,7 +6807,7 @@ function validateGatewayBindingsSegment(patch) {
6606
6807
  const ids = /* @__PURE__ */ new Set();
6607
6808
  raw.forEach((entry, index) => {
6608
6809
  const path2 = `bindings[${index}]`;
6609
- if (!isRecord5(entry)) {
6810
+ if (!isRecord6(entry)) {
6610
6811
  errors.push(`${path2} must be an object`);
6611
6812
  return;
6612
6813
  }
@@ -6635,12 +6836,12 @@ function validateGatewayBindingsSegment(patch) {
6635
6836
  } else if (entry.modelMappings.length > 100) {
6636
6837
  errors.push(`${path2}.modelMappings cannot contain more than 100 entries`);
6637
6838
  } else if (entry.modelMappings.some(
6638
- (mapping) => !isRecord5(mapping) || !nonBlank(mapping.source) || !nonBlank(mapping.target)
6839
+ (mapping) => !isRecord6(mapping) || !nonBlank(mapping.source) || !nonBlank(mapping.target)
6639
6840
  )) {
6640
6841
  errors.push(`${path2}.modelMappings must contain non-empty source and target strings`);
6641
6842
  }
6642
6843
  }
6643
- if (!isRecord5(entry.target) || !TARGET_KINDS.has(String(entry.target.kind))) {
6844
+ if (!isRecord6(entry.target) || !TARGET_KINDS.has(String(entry.target.kind))) {
6644
6845
  errors.push(`${path2}.target is invalid`);
6645
6846
  } else {
6646
6847
  if (!nonBlank(entry.target.providerId)) errors.push(`${path2}.target.providerId is required`);
@@ -6655,7 +6856,7 @@ function validateGatewayBindingsSegment(patch) {
6655
6856
  }
6656
6857
  }
6657
6858
  if (entry.modelMap !== void 0) {
6658
- if (!isRecord5(entry.modelMap) || Object.values(entry.modelMap).some((value) => typeof value !== "string")) {
6859
+ if (!isRecord6(entry.modelMap) || Object.values(entry.modelMap).some((value) => typeof value !== "string")) {
6659
6860
  errors.push(`${path2}.modelMap must contain string values`);
6660
6861
  }
6661
6862
  }
@@ -7716,7 +7917,7 @@ function query(req) {
7716
7917
  }
7717
7918
  function allowanceProvider(value) {
7718
7919
  if (!value) return void 0;
7719
- return value === "claude" || value === "codex" || value === "kimi" || value === "opencodego" || value === "grok" || value === "copilot" ? value : null;
7920
+ return value === "claude" || value === "codex" || value === "kimi" || value === "opencodego" || value === "grok" || value === "copilot" || value === "gemini" ? value : null;
7720
7921
  }
7721
7922
  async function handleAccountAllowanceApi(req, res, method, rest, service) {
7722
7923
  if (!service) return writeError2(res, 501, "account allowance service is not available");
@@ -7731,7 +7932,7 @@ async function handleAccountAllowanceApi(req, res, method, rest, service) {
7731
7932
  const pathProvider = rest.length >= 2 ? rest[0] : null;
7732
7933
  const providerId = allowanceProvider(pathProvider ?? params.get("providerId") ?? params.get("provider"));
7733
7934
  if (providerId === null) {
7734
- return writeError2(res, 400, "providerId must be claude, codex, kimi, opencodego, grok, or copilot");
7935
+ return writeError2(res, 400, "providerId must be claude, codex, kimi, opencodego, grok, copilot, or gemini");
7735
7936
  }
7736
7937
  const accountId = rest.length >= 2 ? rest[1] : params.get("accountId") ?? void 0;
7737
7938
  const allowances = await service.list({ providerId, accountId });
@@ -7793,6 +7994,16 @@ async function handleAccountAllowanceApi(req, res, method, rest, service) {
7793
7994
  }
7794
7995
  return writeJson3(res, 200, { allowances: allowances2 });
7795
7996
  }
7997
+ if (requestedProvider === "gemini") {
7998
+ if (!service.refreshGemini) {
7999
+ return writeError2(res, 501, "gemini allowance refresh is not available");
8000
+ }
8001
+ const allowances2 = await service.refreshGemini(accountId);
8002
+ if (accountId && allowances2.length === 0) {
8003
+ return writeError2(res, 404, `Gemini account '${accountId}' not found`);
8004
+ }
8005
+ return writeJson3(res, 200, { allowances: allowances2 });
8006
+ }
7796
8007
  const allowances = await service.refreshClaude(accountId);
7797
8008
  if (accountId && allowances.length === 0) {
7798
8009
  return writeError2(res, 404, `Claude account '${accountId}' not found`);
@@ -8139,7 +8350,7 @@ async function handleDiscoverModels(res, id, cfg) {
8139
8350
  const headers = { Accept: "application/json" };
8140
8351
  if (resolvedKey) headers["Authorization"] = `Bearer ${resolvedKey}`;
8141
8352
  Object.assign(headers, expandRowExtraHeaders(row));
8142
- const response = await (0, import_upstreamFetch9.fetchUpstream)(url, { method: "GET", headers }, { providerId: "byo" });
8353
+ const response = await (0, import_upstreamFetch10.fetchUpstream)(url, { method: "GET", headers }, { providerId: "byo" });
8143
8354
  if (!response.ok) {
8144
8355
  const text = await response.text().catch(() => "");
8145
8356
  let message = text.slice(0, 300);
@@ -8199,7 +8410,7 @@ async function handleTestModel(req, res, id, cfg) {
8199
8410
  Object.assign(headers, expandRowExtraHeaders(row));
8200
8411
  const startedAt = Date.now();
8201
8412
  try {
8202
- const response = await (0, import_upstreamFetch9.fetchUpstream)(
8413
+ const response = await (0, import_upstreamFetch10.fetchUpstream)(
8203
8414
  url,
8204
8415
  { method: "POST", headers, body: JSON.stringify(payload) },
8205
8416
  { providerId: "byo" }
@@ -9606,12 +9817,12 @@ async function handlePlayground(req, res, method, deps) {
9606
9817
  const payload = body["body"];
9607
9818
  const status = deps.outboundApiServer.getStatus();
9608
9819
  if (!status.running || !status.port) return writeJsonError(res, 503, "outbound server not running");
9609
- const path2 = resolvePlaygroundPath(endpoint, isRecord6(payload) ? payload : {});
9820
+ const path2 = resolvePlaygroundPath(endpoint, isRecord7(payload) ? payload : {});
9610
9821
  if (!path2) return writeJsonError(res, 400, `unknown endpoint '${endpoint}'`);
9611
9822
  const upstreamBody = typeof payload === "string" ? payload : JSON.stringify(payload ?? {});
9612
9823
  await proxyToOutbound(res, status.port, path2, key, upstreamBody);
9613
9824
  }
9614
- function isRecord6(v) {
9825
+ function isRecord7(v) {
9615
9826
  return !!v && typeof v === "object" && !Array.isArray(v);
9616
9827
  }
9617
9828
  function proxyToOutbound(res, outboundPort, path2, key, body) {
@@ -9747,7 +9958,7 @@ async function handleUiStatic(req, res, urlPath, uiDist) {
9747
9958
  }
9748
9959
 
9749
9960
  // src/admin/version.ts
9750
- var DAEMON_VERSION = true ? "0.4.0" : "0.0.0-dev";
9961
+ var DAEMON_VERSION = true ? "0.4.1" : "0.0.0-dev";
9751
9962
 
9752
9963
  // src/admin/AdminServer.ts
9753
9964
  var LOOPBACK_ADDR = "127.0.0.1";
@@ -10167,7 +10378,7 @@ function createPoolKeysLoader(getProviderRow, autoDisabled) {
10167
10378
 
10168
10379
  // src/allowance/ProviderKeyQuotaService.ts
10169
10380
  var import_core4 = require("@omnicross/core");
10170
- var import_upstreamFetch10 = require("@omnicross/core/pipeline/upstreamFetch");
10381
+ var import_upstreamFetch11 = require("@omnicross/core/pipeline/upstreamFetch");
10171
10382
 
10172
10383
  // src/allowance/ProviderKeyQuota.ts
10173
10384
  var MINUTE_MS3 = 6e4;
@@ -10196,11 +10407,11 @@ function isoInstant3(value) {
10196
10407
  }
10197
10408
  return void 0;
10198
10409
  }
10199
- function secondsUntil7(instant, now) {
10410
+ function secondsUntil8(instant, now) {
10200
10411
  if (!instant) return void 0;
10201
10412
  return Math.max(0, Math.floor((Date.parse(instant) - now) / 1e3));
10202
10413
  }
10203
- function isRecord7(value) {
10414
+ function isRecord8(value) {
10204
10415
  return !!value && typeof value === "object" && !Array.isArray(value);
10205
10416
  }
10206
10417
  function detectProviderKeyQuotaAdapter(baseUrl) {
@@ -10213,7 +10424,7 @@ function detectProviderKeyQuotaAdapter(baseUrl) {
10213
10424
  }
10214
10425
  const host = url.hostname.toLowerCase();
10215
10426
  const path2 = url.pathname.toLowerCase();
10216
- if ((host === "api.z.ai" || host === "open.bigmodel.cn") && path2.includes("/coding")) {
10427
+ if ((host === "api.z.ai" || host === "open.bigmodel.cn") && (path2.includes("/coding") || path2.includes("/anthropic"))) {
10217
10428
  return "zai";
10218
10429
  }
10219
10430
  if ((host === "api.minimax.io" || host === "api.minimaxi.com") && // Token Plan rides the plain openai `/v1` (chat completions) surface; the
@@ -10267,17 +10478,17 @@ function zaiWindowIdLabel(durationMs) {
10267
10478
  return { id: "quota", label: "Quota" };
10268
10479
  }
10269
10480
  function parseZaiQuotaPayload(payload, now) {
10270
- if (!isRecord7(payload)) return null;
10271
- const data = isRecord7(payload["data"]) ? payload["data"] : payload;
10481
+ if (!isRecord8(payload)) return null;
10482
+ const data = isRecord8(payload["data"]) ? payload["data"] : payload;
10272
10483
  if (payload["success"] === false) return null;
10273
10484
  const limits = Array.isArray(data["limits"]) ? data["limits"] : [];
10274
10485
  const byWindow = /* @__PURE__ */ new Map();
10275
10486
  for (const raw of limits) {
10276
- if (!isRecord7(raw)) continue;
10487
+ if (!isRecord8(raw)) continue;
10277
10488
  const item = raw;
10278
10489
  if (item.type === void 0) continue;
10279
10490
  const details = raw["usageDetails"];
10280
- if (Array.isArray(details) && details.some((d) => isRecord7(d) && d["modelCode"] === "zread")) {
10491
+ if (Array.isArray(details) && details.some((d) => isRecord8(d) && d["modelCode"] === "zread")) {
10281
10492
  continue;
10282
10493
  }
10283
10494
  const durationMs = zaiWindowDurationMs(item);
@@ -10296,7 +10507,7 @@ function parseZaiQuotaPayload(payload, now) {
10296
10507
  usedPercent,
10297
10508
  ...durationMs !== void 0 ? { windowMinutes: Math.round(durationMs / MINUTE_MS3) } : {},
10298
10509
  ...resetsAt !== void 0 ? { resetsAt } : {},
10299
- remainingSeconds: secondsUntil7(resetsAt, now),
10510
+ remainingSeconds: secondsUntil8(resetsAt, now),
10300
10511
  state: "fresh"
10301
10512
  };
10302
10513
  const existing = byWindow.get(id);
@@ -10310,7 +10521,7 @@ function parseZaiQuotaPayload(payload, now) {
10310
10521
  var MINIMAX_STATUS_EXHAUSTED = 2;
10311
10522
  var MINIMAX_SHARED_BUCKET = "general";
10312
10523
  function parseMiniMaxBucket(value) {
10313
- if (!isRecord7(value)) return null;
10524
+ if (!isRecord8(value)) return null;
10314
10525
  const modelName = typeof value["model_name"] === "string" ? value["model_name"].trim() : "";
10315
10526
  if (!modelName) return null;
10316
10527
  const instant = (v) => {
@@ -10337,14 +10548,14 @@ function minimaxWindow(id, label, windowMinutes, resetsAtMs, remainingPercent, s
10337
10548
  usedPercent,
10338
10549
  ...windowMinutes !== void 0 ? { windowMinutes } : {},
10339
10550
  ...resetsAt !== void 0 ? { resetsAt } : {},
10340
- remainingSeconds: secondsUntil7(resetsAt, now),
10551
+ remainingSeconds: secondsUntil8(resetsAt, now),
10341
10552
  state: usedPercent !== null ? "fresh" : "unavailable"
10342
10553
  };
10343
10554
  }
10344
10555
  function parseMiniMaxTokenPlanPayload(payload, now) {
10345
- if (!isRecord7(payload)) return null;
10556
+ if (!isRecord8(payload)) return null;
10346
10557
  const baseResp = payload["base_resp"];
10347
- if (!isRecord7(baseResp) || baseResp["status_code"] !== 0) return null;
10558
+ if (!isRecord8(baseResp) || baseResp["status_code"] !== 0) return null;
10348
10559
  const buckets = Array.isArray(payload["model_remains"]) ? payload["model_remains"] : [];
10349
10560
  let general = null;
10350
10561
  for (const raw of buckets) {
@@ -10377,11 +10588,11 @@ function parseMiniMaxTokenPlanPayload(payload, now) {
10377
10588
  ];
10378
10589
  }
10379
10590
  function parseUmansUsagePayload(payload, now) {
10380
- if (!isRecord7(payload)) return null;
10381
- const limits = isRecord7(payload["limits"]) ? payload["limits"] : void 0;
10382
- const requests = limits && isRecord7(limits["requests"]) ? limits["requests"] : void 0;
10383
- const usage = isRecord7(payload["usage"]) ? payload["usage"] : void 0;
10384
- const window = isRecord7(payload["window"]) ? payload["window"] : void 0;
10591
+ if (!isRecord8(payload)) return null;
10592
+ const limits = isRecord8(payload["limits"]) ? payload["limits"] : void 0;
10593
+ const requests = limits && isRecord8(limits["requests"]) ? limits["requests"] : void 0;
10594
+ const usage = isRecord8(payload["usage"]) ? payload["usage"] : void 0;
10595
+ const window = isRecord8(payload["window"]) ? payload["window"] : void 0;
10385
10596
  const hardCap = finiteNumber5(requests?.["hard_cap"]);
10386
10597
  const softLimit = finiteNumber5(requests?.["limit"]);
10387
10598
  const requestsInWindow = finiteNumber5(usage?.["requests_in_window"]);
@@ -10402,15 +10613,15 @@ function parseUmansUsagePayload(payload, now) {
10402
10613
  usedPercent,
10403
10614
  windowMinutes: 5 * 60,
10404
10615
  ...resetsAt !== void 0 ? { resetsAt } : {},
10405
- remainingSeconds: secondsUntil7(resetsAt, now),
10616
+ remainingSeconds: secondsUntil8(resetsAt, now),
10406
10617
  state: "fresh"
10407
10618
  }
10408
10619
  ];
10409
10620
  }
10410
10621
  function parseSyntheticQuotasPayload(payload, now) {
10411
- if (!isRecord7(payload)) return null;
10412
- const fiveHour = isRecord7(payload["rollingFiveHourLimit"]) ? payload["rollingFiveHourLimit"] : void 0;
10413
- const weekly = isRecord7(payload["weeklyTokenLimit"]) ? payload["weeklyTokenLimit"] : void 0;
10622
+ if (!isRecord8(payload)) return null;
10623
+ const fiveHour = isRecord8(payload["rollingFiveHourLimit"]) ? payload["rollingFiveHourLimit"] : void 0;
10624
+ const weekly = isRecord8(payload["weeklyTokenLimit"]) ? payload["weeklyTokenLimit"] : void 0;
10414
10625
  const windows = [];
10415
10626
  if (fiveHour) {
10416
10627
  const max = finiteNumber5(fiveHour["max"]);
@@ -10424,7 +10635,7 @@ function parseSyntheticQuotasPayload(payload, now) {
10424
10635
  usedPercent,
10425
10636
  windowMinutes: 5 * 60,
10426
10637
  ...resetsAt !== void 0 ? { resetsAt } : {},
10427
- remainingSeconds: secondsUntil7(resetsAt, now),
10638
+ remainingSeconds: secondsUntil8(resetsAt, now),
10428
10639
  state: usedPercent !== null || resetsAt ? "fresh" : "unavailable"
10429
10640
  });
10430
10641
  }
@@ -10439,7 +10650,7 @@ function parseSyntheticQuotasPayload(payload, now) {
10439
10650
  usedPercent,
10440
10651
  windowMinutes: 7 * 24 * 60,
10441
10652
  ...resetsAt !== void 0 ? { resetsAt } : {},
10442
- remainingSeconds: secondsUntil7(resetsAt, now),
10653
+ remainingSeconds: secondsUntil8(resetsAt, now),
10443
10654
  state: usedPercent !== null || resetsAt ? "fresh" : "unavailable"
10444
10655
  });
10445
10656
  }
@@ -10451,12 +10662,12 @@ var CLINE_WINDOW_CONFIG = {
10451
10662
  monthly: { id: "thirty-day", label: "30 days", minutes: 30 * 24 * 60 }
10452
10663
  };
10453
10664
  function parseClinePassUsageLimitsPayload(payload, now) {
10454
- if (!isRecord7(payload)) return null;
10455
- const data = isRecord7(payload["data"]) ? payload["data"] : payload;
10665
+ if (!isRecord8(payload)) return null;
10666
+ const data = isRecord8(payload["data"]) ? payload["data"] : payload;
10456
10667
  const limits = Array.isArray(data["limits"]) ? data["limits"] : [];
10457
10668
  const windows = [];
10458
10669
  for (const raw of limits) {
10459
- if (!isRecord7(raw)) continue;
10670
+ if (!isRecord8(raw)) continue;
10460
10671
  const config = CLINE_WINDOW_CONFIG[typeof raw["type"] === "string" ? raw["type"] : ""];
10461
10672
  if (!config) continue;
10462
10673
  const usedPercent = finitePercent4(raw["percentUsed"]);
@@ -10469,7 +10680,7 @@ function parseClinePassUsageLimitsPayload(payload, now) {
10469
10680
  usedPercent,
10470
10681
  windowMinutes: config.minutes,
10471
10682
  ...resetsAt !== void 0 ? { resetsAt } : {},
10472
- remainingSeconds: secondsUntil7(resetsAt, now),
10683
+ remainingSeconds: secondsUntil8(resetsAt, now),
10473
10684
  state: "fresh"
10474
10685
  });
10475
10686
  }
@@ -10508,7 +10719,7 @@ function rowKeyEntries(row) {
10508
10719
  return [];
10509
10720
  }
10510
10721
  var ProviderKeyQuotaService = class {
10511
- constructor(box, fetchImpl = (url, init) => (0, import_upstreamFetch10.fetchUpstream)(url, init, { redactBodies: true }), now = Date.now) {
10722
+ constructor(box, fetchImpl = (url, init) => (0, import_upstreamFetch11.fetchUpstream)(url, init, { redactBodies: true }), now = Date.now) {
10512
10723
  this.box = box;
10513
10724
  this.fetchImpl = fetchImpl;
10514
10725
  this.now = now;
@@ -17172,7 +17383,7 @@ var import_node_fs28 = require("fs");
17172
17383
  var import_node_path27 = require("path");
17173
17384
  var import_SubscriptionAccountHealth2 = require("@omnicross/core/pipeline/SubscriptionAccountHealth");
17174
17385
  var import_AccountAllowanceScheduling3 = require("@omnicross/core/pipeline/AccountAllowanceScheduling");
17175
- var import_upstreamFetch11 = require("@omnicross/core/pipeline/upstreamFetch");
17386
+ var import_upstreamFetch12 = require("@omnicross/core/pipeline/upstreamFetch");
17176
17387
  var import_SubscriptionIdentityStore2 = require("@omnicross/core/provider-proxy/identity/SubscriptionIdentityStore");
17177
17388
  var import_subscriptions11 = require("@omnicross/subscriptions");
17178
17389
 
@@ -17322,7 +17533,7 @@ var JsonSubscriptionCredentialStore = class {
17322
17533
  * a plaintext token pair into `upstream-trace.jsonl`.
17323
17534
  */
17324
17535
  buildRefreshFetch(providerId, accountId) {
17325
- return this.fetchImpl ?? ((url, init) => (0, import_upstreamFetch11.fetchUpstream)(url, init, { providerId, accountId, redactBodies: true }));
17536
+ return this.fetchImpl ?? ((url, init) => (0, import_upstreamFetch12.fetchUpstream)(url, init, { providerId, accountId, redactBodies: true }));
17326
17537
  }
17327
17538
  /**
17328
17539
  * In-flight refresh coalescing. OAuth refresh tokens are
@@ -18052,7 +18263,7 @@ var JsonSubscriptionCredentialStore = class {
18052
18263
  };
18053
18264
 
18054
18265
  // src/AccountHealthProbeScheduler.ts
18055
- var import_upstreamFetch12 = require("@omnicross/core/pipeline/upstreamFetch");
18266
+ var import_upstreamFetch13 = require("@omnicross/core/pipeline/upstreamFetch");
18056
18267
 
18057
18268
  // src/probe/CodexGenerationProbe.ts
18058
18269
  var import_codexCliHeaders = require("@omnicross/core/provider-proxy/identity/codexCliHeaders");
@@ -18226,7 +18437,7 @@ var AccountHealthProbeScheduler = class {
18226
18437
  this.logger = logger;
18227
18438
  this.config = config;
18228
18439
  this.now = opts.now ?? Date.now;
18229
- this.fetchImpl = opts.fetchImpl ?? import_upstreamFetch12.fetchUpstream;
18440
+ this.fetchImpl = opts.fetchImpl ?? import_upstreamFetch13.fetchUpstream;
18230
18441
  this.sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
18231
18442
  this.planFor = opts.planFor ?? probePlanFor;
18232
18443
  }
@@ -19382,7 +19593,7 @@ var AuditWriter = class {
19382
19593
  var import_node_fs34 = require("fs");
19383
19594
  var import_node_crypto24 = require("crypto");
19384
19595
  var import_node_path34 = require("path");
19385
- var import_upstreamFetch13 = require("@omnicross/core/pipeline/upstreamFetch");
19596
+ var import_upstreamFetch14 = require("@omnicross/core/pipeline/upstreamFetch");
19386
19597
 
19387
19598
  // src/billing/billingFiles.ts
19388
19599
  var BILLING_FILE_RE = /^billing-(\d{4})-(\d{2})-(\d{2})\.jsonl$/;
@@ -19405,7 +19616,7 @@ var BillingPublisher = class {
19405
19616
  constructor(billingDir, logger, opts = {}) {
19406
19617
  this.billingDir = billingDir;
19407
19618
  this.logger = logger;
19408
- this.fetchImpl = opts.fetchImpl ?? ((url, init) => (0, import_upstreamFetch13.fetchUpstream)(url, init));
19619
+ this.fetchImpl = opts.fetchImpl ?? ((url, init) => (0, import_upstreamFetch14.fetchUpstream)(url, init));
19409
19620
  this.defer = opts.defer ?? ((fn) => setTimeout(fn, 0));
19410
19621
  this.timeoutMs = opts.timeoutMs ?? BILLING_POST_TIMEOUT_MS;
19411
19622
  this.now = opts.now ?? Date.now;
@@ -19822,7 +20033,7 @@ function createRouteLeaseSubscriptionPreflight(credentials) {
19822
20033
 
19823
20034
  // src/webhook/WebhookDispatcher.ts
19824
20035
  var import_node_crypto25 = require("crypto");
19825
- var import_upstreamFetch14 = require("@omnicross/core/pipeline/upstreamFetch");
20036
+ var import_upstreamFetch15 = require("@omnicross/core/pipeline/upstreamFetch");
19826
20037
  var WEBHOOK_MAX_ATTEMPTS = 3;
19827
20038
  var WEBHOOK_QUEUE_MAX = 1e3;
19828
20039
  var WEBHOOK_SEND_TIMEOUT_MS = 1e4;
@@ -19842,7 +20053,7 @@ var WebhookDispatcher = class {
19842
20053
  sleep;
19843
20054
  now;
19844
20055
  constructor(opts = {}) {
19845
- this.fetchImpl = opts.fetchImpl ?? ((url, init) => (0, import_upstreamFetch14.fetchUpstream)(url, init));
20056
+ this.fetchImpl = opts.fetchImpl ?? ((url, init) => (0, import_upstreamFetch15.fetchUpstream)(url, init));
19846
20057
  this.logger = opts.logger;
19847
20058
  this.maxAttempts = opts.maxAttempts ?? WEBHOOK_MAX_ATTEMPTS;
19848
20059
  this.queueMax = opts.queueMax ?? WEBHOOK_QUEUE_MAX;
@@ -20066,12 +20277,12 @@ function buildDaemon(config, paths) {
20066
20277
  setSecretBox(secretBox3);
20067
20278
  setSecretBox2(secretBox3);
20068
20279
  const decryptedConfig = decryptConfigSecrets(config, secretBox3);
20069
- const accountAllowanceStore = new import_AccountAllowanceStore9.AccountAllowanceStore(
20280
+ const accountAllowanceStore = new import_AccountAllowanceStore10.AccountAllowanceStore(
20070
20281
  Date.now,
20071
20282
  void 0,
20072
20283
  new JsonAccountAllowancePersistence(defaultAccountAllowancePath(paths.configPath))
20073
20284
  );
20074
- (0, import_AccountAllowanceStore9.setSharedAccountAllowanceStore)(accountAllowanceStore);
20285
+ (0, import_AccountAllowanceStore10.setSharedAccountAllowanceStore)(accountAllowanceStore);
20075
20286
  (0, import_AccountAllowanceScheduling5.getSharedAccountAllowanceScheduling)().configure(
20076
20287
  (0, import_outbound_api10.normalizeServerConfig)(decryptedConfig.server).allowanceScheduling
20077
20288
  );
@@ -20104,12 +20315,12 @@ function buildDaemon(config, paths) {
20104
20315
  );
20105
20316
  (0, import_subscriptions12.setSubscriptionProviderRegistry)(subscriptionRegistry);
20106
20317
  setServerProxyConfig(decryptedConfig.server?.proxy);
20107
- (0, import_upstreamFetch15.setUpstreamProxyResolver)(
20318
+ (0, import_upstreamFetch16.setUpstreamProxyResolver)(
20108
20319
  createUpstreamProxyResolver({
20109
20320
  getAccountProxy: (providerId, accountId) => credentialStore.getAccountProxy(providerId, accountId)
20110
20321
  })
20111
20322
  );
20112
- (0, import_gemini_code_assist_resolver.setGeminiCodeAssistResolver)((0, import_GeminiCodeAssistProjectResolver.getGeminiCodeAssistProjectResolver)());
20323
+ (0, import_gemini_code_assist_resolver.setGeminiCodeAssistResolver)((0, import_GeminiCodeAssistProjectResolver2.getGeminiCodeAssistProjectResolver)());
20113
20324
  const autoDisableStore = new AutoDisableStore();
20114
20325
  const providerKeyQuotaService = new ProviderKeyQuotaService(secretBox3);
20115
20326
  const apiKeyPool = new import_ApiKeyPoolService.ApiKeyPoolService(
@@ -20128,7 +20339,7 @@ function buildDaemon(config, paths) {
20128
20339
  const pricingEngine = new import_usage2.PricingEngine(pricingStore, logger, {
20129
20340
  // Catalog egress follows the same global/env proxy policy as every other
20130
20341
  // daemon upstream call; no provider/account override applies here.
20131
- fetchImpl: ((input, init) => (0, import_upstreamFetch15.fetchUpstream)(String(input), init ?? {}))
20342
+ fetchImpl: ((input, init) => (0, import_upstreamFetch16.fetchUpstream)(String(input), init ?? {}))
20132
20343
  });
20133
20344
  const pricingRefreshScheduler = new PricingRefreshScheduler(
20134
20345
  pricingEngine,
@@ -20413,7 +20624,7 @@ function buildDaemon(config, paths) {
20413
20624
  // — `server.proxy.byProvider[...]` was silently skipped — and the call was
20414
20625
  // excluded from the upstream trace, so a failing login left no evidence.
20415
20626
  // `redactBodies` keeps the code/verifier + minted token out of that trace.
20416
- oauthExchangeFetch: paths.oauthExchangeFetch ? () => paths.oauthExchangeFetch : (providerId) => (url, init) => (0, import_upstreamFetch15.fetchUpstream)(url, init, { providerId, redactBodies: true }),
20627
+ oauthExchangeFetch: paths.oauthExchangeFetch ? () => paths.oauthExchangeFetch : (providerId) => (url, init) => (0, import_upstreamFetch16.fetchUpstream)(url, init, { providerId, redactBodies: true }),
20417
20628
  subscriptionAccountAppender: credentialStore,
20418
20629
  // Codex interactive OAuth (app-parity-2 child 5) — the async loopback flow store
20419
20630
  // + the one-shot 127.0.0.1:1455 listener. Token captured + persisted daemon-side;
@@ -20486,7 +20697,7 @@ function buildDaemon(config, paths) {
20486
20697
  });
20487
20698
  const webhookDispatcher = new WebhookDispatcher({
20488
20699
  logger,
20489
- fetchImpl: (url, init) => (0, import_upstreamFetch15.fetchUpstream)(url, init)
20700
+ fetchImpl: (url, init) => (0, import_upstreamFetch16.fetchUpstream)(url, init)
20490
20701
  });
20491
20702
  setWebhookRuntime(webhookDispatcher, (0, import_SubscriptionAccountHealth4.getSharedAccountHealth)());
20492
20703
  const auditWriter = new AuditWriter(auditDir, logger);
@@ -21351,7 +21562,7 @@ function spawnCliInherit(plan) {
21351
21562
  var import_node_child_process3 = require("child_process");
21352
21563
  var import_node_readline2 = require("readline");
21353
21564
  var import_node_util7 = require("util");
21354
- var import_upstreamFetch16 = require("@omnicross/core/pipeline/upstreamFetch");
21565
+ var import_upstreamFetch17 = require("@omnicross/core/pipeline/upstreamFetch");
21355
21566
  var import_subscriptions13 = require("@omnicross/subscriptions");
21356
21567
  var PROVIDERS2 = ["claude", "codex", "gemini", "kimi", "grok", "copilot"];
21357
21568
  async function runLogin(argv, deps) {
@@ -21393,10 +21604,10 @@ async function runLogin(argv, deps) {
21393
21604
  const resolvedOpenBrowser = resolved.openBrowser;
21394
21605
  const box = resolveSecretBox(values["master-key-file"]);
21395
21606
  setSecretBox(box);
21396
- (0, import_upstreamFetch16.setUpstreamProxyResolver)(createUpstreamProxyResolver());
21607
+ (0, import_upstreamFetch17.setUpstreamProxyResolver)(createUpstreamProxyResolver());
21397
21608
  try {
21398
21609
  const tokensPath = defaultTokensPath(values.config);
21399
- const exchangeFetch = resolved.tokensFetch ?? ((url, init) => (0, import_upstreamFetch16.fetchUpstream)(url, init, { providerId: provider, redactBodies: true }));
21610
+ const exchangeFetch = resolved.tokensFetch ?? ((url, init) => (0, import_upstreamFetch17.fetchUpstream)(url, init, { providerId: provider, redactBodies: true }));
21400
21611
  const store = new JsonSubscriptionCredentialStore(tokensPath, box, exchangeFetch);
21401
21612
  const expiresAt = await runProviderLogin(
21402
21613
  provider,
@@ -21410,7 +21621,7 @@ async function runLogin(argv, deps) {
21410
21621
  console.info(` token: [stored, encrypted] expiresAt: ${expiresAt ?? "n/a"}`);
21411
21622
  } finally {
21412
21623
  setSecretBox(null);
21413
- (0, import_upstreamFetch16.setUpstreamProxyResolver)(null);
21624
+ (0, import_upstreamFetch17.setUpstreamProxyResolver)(null);
21414
21625
  }
21415
21626
  }
21416
21627
  async function runProviderLogin(provider, store, deps, exchangeFetch, label, enterpriseUrl) {