@omnicross/core 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/auth/GeminiCodeAssistProjectResolver.cjs +3 -3
  2. package/dist/auth/GeminiCodeAssistProjectResolver.js +2 -2
  3. package/dist/{chunk-HVBBDBS3.cjs → chunk-2T6D7LWE.cjs} +96 -9
  4. package/dist/{chunk-VL5TUDTM.js → chunk-5DJSOFEP.js} +6 -1
  5. package/dist/{chunk-LKDAN4D7.js → chunk-5TEWZN5J.js} +112 -38
  6. package/dist/{chunk-6QQG7YG3.cjs → chunk-BKXC4XM6.cjs} +3 -3
  7. package/dist/{chunk-OPRS4IQZ.js → chunk-C3NPMQTK.js} +2 -2
  8. package/dist/{chunk-HOMUGKHR.js → chunk-GTDQCW3H.js} +29 -2
  9. package/dist/{chunk-23S5OPIO.js → chunk-HDXSPXIN.js} +1 -1
  10. package/dist/{chunk-MKF46GNZ.js → chunk-PF7YQBKX.js} +91 -4
  11. package/dist/{chunk-VSYQ6XYN.cjs → chunk-QEOV6Y4E.cjs} +516 -442
  12. package/dist/{chunk-U47LQXPB.js → chunk-QRXOLINS.js} +4 -1
  13. package/dist/{chunk-YNJNTCSQ.cjs → chunk-TX3AEV6H.cjs} +2 -2
  14. package/dist/{chunk-OIKREZVQ.cjs → chunk-TX4UCSOP.cjs} +30 -3
  15. package/dist/{chunk-T6NWPIYZ.cjs → chunk-YEVWA4C7.cjs} +4 -1
  16. package/dist/{chunk-4Z3ZLLC2.cjs → chunk-ZSA44G7J.cjs} +13 -8
  17. package/dist/completion/CompletionService.cjs +8 -8
  18. package/dist/completion/CompletionService.js +7 -7
  19. package/dist/completion.cjs +14 -8
  20. package/dist/completion.d.cts +22 -1
  21. package/dist/completion.d.ts +22 -1
  22. package/dist/completion.js +14 -8
  23. package/dist/index.cjs +14 -8
  24. package/dist/index.d.cts +1 -1
  25. package/dist/index.d.ts +1 -1
  26. package/dist/index.js +14 -8
  27. package/dist/outbound-api/routeResolver.cjs +2 -2
  28. package/dist/outbound-api/routeResolver.js +1 -1
  29. package/dist/outbound-api.cjs +8 -8
  30. package/dist/outbound-api.js +7 -7
  31. package/dist/pipeline/AccountAllowanceScheduling.cjs +3 -3
  32. package/dist/pipeline/AccountAllowanceScheduling.js +2 -2
  33. package/dist/pipeline/AccountAllowanceStore.cjs +6 -2
  34. package/dist/pipeline/AccountAllowanceStore.d.cts +41 -1
  35. package/dist/pipeline/AccountAllowanceStore.d.ts +41 -1
  36. package/dist/pipeline/AccountAllowanceStore.js +5 -1
  37. package/dist/pipeline/LlmConfigProviderAuth.cjs +2 -2
  38. package/dist/pipeline/LlmConfigProviderAuth.js +1 -1
  39. package/dist/pipeline/SubscriptionAuthSource.cjs +4 -4
  40. package/dist/pipeline/SubscriptionAuthSource.js +3 -3
  41. package/dist/pipeline/upstreamFetch.cjs +3 -3
  42. package/dist/pipeline/upstreamFetch.js +2 -2
  43. package/dist/provider-proxy/ProviderProxy.cjs +8 -8
  44. package/dist/provider-proxy/ProviderProxy.js +7 -7
  45. package/dist/provider-proxy/ingress/providerProxyShared.cjs +8 -8
  46. package/dist/provider-proxy/ingress/providerProxyShared.js +7 -7
  47. package/dist/provider-proxy.cjs +8 -8
  48. package/dist/provider-proxy.js +7 -7
  49. package/package.json +2 -2
@@ -1,5 +1,6 @@
1
1
  // src/pipeline/AccountAllowanceStore.ts
2
2
  var DEFAULT_CODEX_ALLOWANCE_FRESH_MS = 15 * 6e4;
3
+ var CLAUDE_HEADER_FRESH_MS = 5 * 6e4;
3
4
  var DEFAULT_ALLOWANCE_MAX_SNAPSHOTS = 256;
4
5
  var MAX_WINDOWS_PER_SNAPSHOT = 8;
5
6
  var MAX_TEXT_LENGTH = 200;
@@ -55,7 +56,7 @@ function normalizedInstant(value) {
55
56
  return Number.isFinite(parsed) ? new Date(parsed).toISOString() : void 0;
56
57
  }
57
58
  function isAllowanceProvider(value) {
58
- return value === "claude" || value === "codex" || value === "gemini" || value === "opencodego";
59
+ return value === "claude" || value === "codex" || value === "gemini" || value === "opencodego" || value === "kimi" || value === "grok" || value === "copilot";
59
60
  }
60
61
  function isWindowState(value) {
61
62
  return value === "fresh" || value === "stale" || value === "unavailable" || value === "unsupported";
@@ -135,11 +136,15 @@ function parseWindow(headers, prefix) {
135
136
  const resetAfterSeconds = finiteNumber(
136
137
  headerValue(headers, `x-codex-${prefix}-reset-after-seconds`)
137
138
  );
139
+ const resetAtSeconds = finiteNumber(headerValue(headers, `x-codex-${prefix}-reset-at`));
138
140
  const windowMinutes = finiteNumber(headerValue(headers, `x-codex-${prefix}-window-minutes`));
139
- if (usedPercent === void 0 && resetAfterSeconds === void 0 && windowMinutes === void 0) {
141
+ if (usedPercent === void 0 && resetAfterSeconds === void 0 && resetAtSeconds === void 0 && windowMinutes === void 0) {
140
142
  return void 0;
141
143
  }
142
- return { usedPercent, resetAfterSeconds, windowMinutes };
144
+ return { usedPercent, resetAfterSeconds, resetAtSeconds, windowMinutes };
145
+ }
146
+ function epochMsFromMaybeSeconds(value) {
147
+ return value > 1e11 ? value : value * 1e3;
143
148
  }
144
149
  function parseCodexAllowanceHeaders(headers) {
145
150
  const primary = parseWindow(headers, "primary");
@@ -150,6 +155,23 @@ function parseCodexAllowanceHeaders(headers) {
150
155
  if (!primary && !secondary && primaryOverSecondaryLimitPercent === void 0) return null;
151
156
  return { primary, secondary, primaryOverSecondaryLimitPercent };
152
157
  }
158
+ function parseUnifiedWindow(headers, windowId) {
159
+ const prefix = `anthropic-ratelimit-unified-${windowId}-`;
160
+ const fraction = finiteNumber(headerValue(headers, `${prefix}utilization`));
161
+ const resetSeconds = finiteNumber(headerValue(headers, `${prefix}reset`));
162
+ if (fraction === void 0 && resetSeconds === void 0) return void 0;
163
+ return {
164
+ ...fraction !== void 0 ? { usedPercent: Math.round(Math.min(100, Math.max(0, fraction * 100))) } : {},
165
+ ...resetSeconds !== void 0 && resetSeconds > 0 ? { resetAtMs: epochMsFromMaybeSeconds(resetSeconds) } : {}
166
+ };
167
+ }
168
+ function parseClaudeAllowanceHeaders(headers) {
169
+ const fiveHour = parseUnifiedWindow(headers, "5h");
170
+ const sevenDay = parseUnifiedWindow(headers, "7d");
171
+ const scopedSevenDay = parseUnifiedWindow(headers, "7d_oi");
172
+ if (!fiveHour && !sevenDay && !scopedSevenDay) return null;
173
+ return { fiveHour, sevenDay, scopedSevenDay };
174
+ }
153
175
  function durationLabel(minutes) {
154
176
  if (minutes === void 0) return void 0;
155
177
  if (minutes % (7 * 24 * 60) === 0) {
@@ -183,7 +205,7 @@ function remainingSeconds(resetsAt, now) {
183
205
  }
184
206
  function mergeCodexWindow(id, observation, existing, observedMs) {
185
207
  const windowMinutes = observation?.windowMinutes ?? existing?.windowMinutes;
186
- const nextResetAt = observation?.resetAfterSeconds !== void 0 ? resetAt(observedMs, observation.resetAfterSeconds) : existing?.resetsAt;
208
+ const nextResetAt = observation?.resetAtSeconds !== void 0 ? new Date(epochMsFromMaybeSeconds(observation.resetAtSeconds)).toISOString() : observation?.resetAfterSeconds !== void 0 ? resetAt(observedMs, observation.resetAfterSeconds) : existing?.resetsAt;
187
209
  const hasExistingData = !!existing && (existing.usedPercent !== null || existing.windowMinutes !== void 0 || existing.resetsAt !== void 0);
188
210
  return {
189
211
  id,
@@ -297,6 +319,69 @@ var AccountAllowanceStore = class {
297
319
  this.set(snapshot);
298
320
  return this.get("codex", accountId, observedMs);
299
321
  }
322
+ /**
323
+ * Merge one real Claude upstream response's `anthropic-ratelimit-unified-*`
324
+ * headers into the selected account's snapshot. Live-traffic updates are the
325
+ * passive complement to the daemon's `/api/oauth/usage` poll: they keep the
326
+ * 5h/7d windows fresh between polls WITHOUT an extra request. A response with
327
+ * no recognized headers is a strict no-op; an existing snapshot keeps its
328
+ * provenance (`source`) and any windows the headers did not mention.
329
+ */
330
+ recordClaudeHeaders(accountId, headers, observedMs = this.now()) {
331
+ if (!accountId) return null;
332
+ const observation = parseClaudeAllowanceHeaders(headers);
333
+ if (!observation) return this.get("claude", accountId, observedMs);
334
+ const previous = this.snapshots.get(snapshotKey("claude", accountId));
335
+ const observedAt = new Date(observedMs).toISOString();
336
+ const expiresAt = new Date(observedMs + CLAUDE_HEADER_FRESH_MS).toISOString();
337
+ const mergeWindow = (existing, observed, defaults) => ({
338
+ id: defaults.id,
339
+ label: defaults.label,
340
+ scope: defaults.scope,
341
+ ...defaults.scope === "model-family" && defaults.modelFamily ? { modelFamily: defaults.modelFamily } : {},
342
+ // An unobserved window keeps its last value and merely ages to stale.
343
+ usedPercent: observed?.usedPercent ?? existing?.usedPercent ?? null,
344
+ windowMinutes: defaults.windowMinutes,
345
+ resetsAt: observed?.resetAtMs !== void 0 ? new Date(observed.resetAtMs).toISOString() : existing?.resetsAt,
346
+ remainingSeconds: void 0,
347
+ state: observed ? "fresh" : existing && (existing.usedPercent !== null || existing.resetsAt) ? "stale" : "unavailable"
348
+ });
349
+ const previousWindow = (id) => previous?.windows.find((window) => window.id === id);
350
+ const windows = [
351
+ mergeWindow(previousWindow("five-hour"), observation.fiveHour, {
352
+ id: "five-hour",
353
+ label: "5 hours",
354
+ scope: "all",
355
+ windowMinutes: 5 * 60
356
+ }),
357
+ mergeWindow(previousWindow("seven-day"), observation.sevenDay, {
358
+ id: "seven-day",
359
+ label: "7 days",
360
+ scope: "all",
361
+ windowMinutes: 7 * 24 * 60
362
+ }),
363
+ mergeWindow(previousWindow("seven-day-fable"), observation.scopedSevenDay, {
364
+ id: "seven-day-fable",
365
+ label: "7 days \xB7 Fable",
366
+ scope: "model-family",
367
+ modelFamily: "fable",
368
+ windowMinutes: 7 * 24 * 60
369
+ }),
370
+ ...(previous?.windows ?? []).filter(
371
+ (window) => !["five-hour", "seven-day", "seven-day-fable"].includes(window.id)
372
+ )
373
+ ].slice(0, 8);
374
+ const snapshot = {
375
+ providerId: "claude",
376
+ accountId,
377
+ source: previous?.source ?? "response-headers",
378
+ observedAt,
379
+ expiresAt,
380
+ windows
381
+ };
382
+ this.set(snapshot);
383
+ return this.get("claude", accountId, observedMs);
384
+ }
300
385
  clear() {
301
386
  if (this.snapshots.size === 0) return;
302
387
  this.snapshots.clear();
@@ -340,9 +425,11 @@ function __resetSharedAccountAllowanceStoreForTests() {
340
425
 
341
426
  export {
342
427
  DEFAULT_CODEX_ALLOWANCE_FRESH_MS,
428
+ CLAUDE_HEADER_FRESH_MS,
343
429
  DEFAULT_ALLOWANCE_MAX_SNAPSHOTS,
344
430
  normalizeAccountAllowanceSnapshot,
345
431
  parseCodexAllowanceHeaders,
432
+ parseClaudeAllowanceHeaders,
346
433
  AccountAllowanceStore,
347
434
  getSharedAccountAllowanceStore,
348
435
  setSharedAccountAllowanceStore,