@cortexkit/opencode-openai-auth 0.9.0 → 0.10.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.
@@ -473,6 +473,14 @@ interface OAuthQuotaSnapshot {
473
473
  resetCreditsAvailable?: number;
474
474
  resetCreditsApplicable?: number;
475
475
  spendControl?: OAuthSpendControlReading;
476
+ /**
477
+ * Set when the source explicitly reported that the account has no credit
478
+ * budget (wham's `spend_control` or `individual_limit` is null). An absent
479
+ * `spendControl` alone only means the source did not carry the field: header
480
+ * and WebSocket pushes never do, so merges keep the previous budget for them.
481
+ * This marker is what lets a merge drop a budget that no longer exists.
482
+ */
483
+ spendControlCleared?: true;
476
484
  credits?: OAuthCredits;
477
485
  }
478
486
  interface OAuthSpendControlReading {
@@ -575,7 +583,6 @@ type AccountStorage = {
575
583
  fallbackOn?: number[];
576
584
  refresh?: {
577
585
  enabled?: boolean;
578
- intervalMinutes?: number;
579
586
  refreshBeforeExpiryMinutes?: number;
580
587
  mainLastRefreshError?: AccountOperationError;
581
588
  mainRefreshLeaseId?: string;
@@ -588,7 +595,6 @@ type AccountStorage = {
588
595
  refreshEveryNRequests?: number;
589
596
  minimumRemaining?: Partial<Record<QuotaWindowName | '5h' | '1w', number>>;
590
597
  failClosedOnUnknownQuota?: boolean;
591
- showToasts?: boolean;
592
598
  mainQuota?: OAuthQuotaSnapshot;
593
599
  mainQuotaCheckedAt?: number;
594
600
  mainQuotaToken?: string;
@@ -0,0 +1 @@
1
+ import{lb as a,mb as b,nb as c,ob as d,pb as e}from"./index-hh52v8sb.js";import"./index-9ehhb051.js";export{a as toResetIso,d as normalizeWsFrame,e as normalizeWham,b as normalizeQuotaHeaders,c as isCompleteQuotaHeaderFrame};
@@ -1 +1 @@
1
- import{I as a,J as b,K as c}from"../index-w42s0g6m.js";import"../index-338z7171.js";import"../index-301y4qa1.js";import"../index-9ehhb051.js";export{a as writePortFile,b as sweepRpcState,c as discoverPortFile};
1
+ import{I as a,J as b,K as c}from"../index-4effjmr6.js";import"../index-sq36b120.js";import"../index-hh52v8sb.js";import"../index-9ehhb051.js";export{a as writePortFile,b as sweepRpcState,c as discoverPortFile};
@@ -1,2 +1,2 @@
1
- import { a as CommandModalName, i as ApplyResult, o as OpenDialogPayload, r as ApplyRequest, s as RpcNotification } from "../internal-Y7QNVDJT.js";
1
+ import { a as CommandModalName, i as ApplyResult, o as OpenDialogPayload, r as ApplyRequest, s as RpcNotification } from "../internal-BTndPmW2.js";
2
2
  export type { ApplyRequest, ApplyResult, CommandModalName, OpenDialogPayload, RpcNotification };
@@ -1,4 +1,4 @@
1
- import { i as ApplyResult, r as ApplyRequest, s as RpcNotification } from "../internal-Y7QNVDJT.js";
1
+ import { i as ApplyResult, r as ApplyRequest, s as RpcNotification } from "../internal-BTndPmW2.js";
2
2
  import { PortFileEntry } from "./port-file.js";
3
3
  import "./protocol.js";
4
4
  //#region src/rpc/rpc-client.d.ts
@@ -1 +1 @@
1
- import{K as c}from"../index-w42s0g6m.js";import"../index-338z7171.js";import"../index-301y4qa1.js";import"../index-9ehhb051.js";var y=2000;async function p(n,r,s,o,i,e=y){let t=await c(n,r);if(s?.(t),!t)return null;let l=new AbortController,u=setTimeout(()=>l.abort(),e);try{let a=await fetch(`http://127.0.0.1:${t.port}/rpc/${o}`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${t.token}`},body:JSON.stringify(i),signal:l.signal});if(!a.ok)return null;return await a.json()}catch{return null}finally{clearTimeout(u)}}function m(n,r,s){let o=!1,i=(e)=>{if(o)return;o=!0,s?.(e)};return{async pending(e,t){return(await p(n,r,i,"pending-notifications",{lastReceivedId:e,sessionId:t}))?.messages??[]},async apply(e,t){return await p(n,r,i,"apply",{...e},t)??{text:"apply failed",knobs:{}}}}}export{m as createRpcClient,y as DEFAULT_RPC_TIMEOUT_MS};
1
+ import{K as c}from"../index-4effjmr6.js";import"../index-sq36b120.js";import"../index-hh52v8sb.js";import"../index-9ehhb051.js";var y=2000;async function p(n,r,s,o,i,e=y){let t=await c(n,r);if(s?.(t),!t)return null;let l=new AbortController,u=setTimeout(()=>l.abort(),e);try{let a=await fetch(`http://127.0.0.1:${t.port}/rpc/${o}`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${t.token}`},body:JSON.stringify(i),signal:l.signal});if(!a.ok)return null;return await a.json()}catch{return null}finally{clearTimeout(u)}}function m(n,r,s){let o=!1,i=(e)=>{if(o)return;o=!0,s?.(e)};return{async pending(e,t){return(await p(n,r,i,"pending-notifications",{lastReceivedId:e,sessionId:t}))?.messages??[]},async apply(e,t){return await p(n,r,i,"apply",{...e},t)??{text:"apply failed",knobs:{}}}}}export{m as createRpcClient,y as DEFAULT_RPC_TIMEOUT_MS};
@@ -42,6 +42,7 @@ interface AccountQuota {
42
42
  primary?: QuotaWindow;
43
43
  secondary?: QuotaWindow;
44
44
  spendControl?: SpendControlReading;
45
+ spendControlCleared?: true;
45
46
  resetCreditsAvailable?: number;
46
47
  }
47
48
  type QuotaWindowKey = 'primary' | 'secondary';
@@ -1,2 +1,2 @@
1
- import { A as getCollapsedQuotaSummary, B as pruneStickyAssignments, C as StickyAssignmentChoice, D as drainSidebarWrites, E as computeQuotaPacing, F as isQuotaExhausted, G as resolveSidebarStickyAssignment, H as resolveActiveAccount, I as isUsableRoutingEntry, J as setSidebarState, K as setSidebarLegacyRouting, L as normalizeSidebarState, M as getSidebarState, N as getSidebarStateFile, O as exhaustedQuotaResetAt, P as hashSidebarSessionId, R as projectCustodyForSidebar, S as StickyAssignment, T as clearSidebarStickyAssignment, U as resolveSessionSidebarRouting, V as removeSidebarActiveRouting, W as resolveSessionStickyAccount, X as upsertSidebarActiveRouting, Y as spendControlExhaustedResetAt, _ as SidebarCustodyState, a as ActiveRoutingMap, b as SidebarState, c as QuotaPacing, d as ResolveStickyAssignmentInput, f as STICKY_ASSIGNMENT_MAX_AGE_MS, g as SidebarCustodyReason, h as SidebarAccountState, i as ActiveRoutingEntry, j as getPresentQuotaWindows, k as formatWindowLabel, l as QuotaWindow, m as SidebarAccountCustody, n as ACTIVE_ROUTING_MAX_ENTRIES, o as DEFAULT_SIDEBAR_STATE, p as STICKY_ASSIGNMENT_MAX_ENTRIES, q as setSidebarMachineState, r as AccountQuota, s as PresentQuotaWindow, t as ACTIVE_ROUTING_MAX_AGE_MS, u as QuotaWindowKey, v as SidebarMachineState, w as StickyAssignmentMap, x as SpendControlReading, y as SidebarRoutingAccount, z as pruneActiveRouting } from "./sidebar-state-B98sERYt.js";
1
+ import { A as getCollapsedQuotaSummary, B as pruneStickyAssignments, C as StickyAssignmentChoice, D as drainSidebarWrites, E as computeQuotaPacing, F as isQuotaExhausted, G as resolveSidebarStickyAssignment, H as resolveActiveAccount, I as isUsableRoutingEntry, J as setSidebarState, K as setSidebarLegacyRouting, L as normalizeSidebarState, M as getSidebarState, N as getSidebarStateFile, O as exhaustedQuotaResetAt, P as hashSidebarSessionId, R as projectCustodyForSidebar, S as StickyAssignment, T as clearSidebarStickyAssignment, U as resolveSessionSidebarRouting, V as removeSidebarActiveRouting, W as resolveSessionStickyAccount, X as upsertSidebarActiveRouting, Y as spendControlExhaustedResetAt, _ as SidebarCustodyState, a as ActiveRoutingMap, b as SidebarState, c as QuotaPacing, d as ResolveStickyAssignmentInput, f as STICKY_ASSIGNMENT_MAX_AGE_MS, g as SidebarCustodyReason, h as SidebarAccountState, i as ActiveRoutingEntry, j as getPresentQuotaWindows, k as formatWindowLabel, l as QuotaWindow, m as SidebarAccountCustody, n as ACTIVE_ROUTING_MAX_ENTRIES, o as DEFAULT_SIDEBAR_STATE, p as STICKY_ASSIGNMENT_MAX_ENTRIES, q as setSidebarMachineState, r as AccountQuota, s as PresentQuotaWindow, t as ACTIVE_ROUTING_MAX_AGE_MS, u as QuotaWindowKey, v as SidebarMachineState, w as StickyAssignmentMap, x as SpendControlReading, y as SidebarRoutingAccount, z as pruneActiveRouting } from "./sidebar-state-CoKYKcLn.js";
2
2
  export { ACTIVE_ROUTING_MAX_AGE_MS, ACTIVE_ROUTING_MAX_ENTRIES, AccountQuota, ActiveRoutingEntry, ActiveRoutingMap, DEFAULT_SIDEBAR_STATE, PresentQuotaWindow, QuotaPacing, QuotaWindow, QuotaWindowKey, ResolveStickyAssignmentInput, STICKY_ASSIGNMENT_MAX_AGE_MS, STICKY_ASSIGNMENT_MAX_ENTRIES, SidebarAccountCustody, SidebarAccountState, SidebarCustodyReason, SidebarCustodyState, SidebarMachineState, SidebarRoutingAccount, SidebarState, SpendControlReading, StickyAssignment, StickyAssignmentChoice, StickyAssignmentMap, clearSidebarStickyAssignment, computeQuotaPacing, drainSidebarWrites, exhaustedQuotaResetAt, formatWindowLabel, getCollapsedQuotaSummary, getPresentQuotaWindows, getSidebarState, getSidebarStateFile, hashSidebarSessionId, isQuotaExhausted, isUsableRoutingEntry, normalizeSidebarState, projectCustodyForSidebar, pruneActiveRouting, pruneStickyAssignments, removeSidebarActiveRouting, resolveActiveAccount, resolveSessionSidebarRouting, resolveSessionStickyAccount, resolveSidebarStickyAssignment, setSidebarLegacyRouting, setSidebarMachineState, setSidebarState, spendControlExhaustedResetAt, upsertSidebarActiveRouting };
@@ -1 +1 @@
1
- import{A as x,B as y,C as z,D as A,E as B,F as C,G as D,H as E,d as a,e as b,f as c,g as d,h as e,i as f,j as g,k as h,l as i,m as j,n as k,o as l,p as m,q as n,r as o,s as p,t as q,u as r,v as s,w as t,x as u,y as v,z as w}from"./index-5y4vzdf8.js";import"./index-338z7171.js";import"./index-301y4qa1.js";import"./index-9ehhb051.js";export{w as upsertSidebarActiveRouting,n as spendControlExhaustedResetAt,u as setSidebarState,v as setSidebarMachineState,x as setSidebarLegacyRouting,z as resolveSidebarStickyAssignment,q as resolveSessionStickyAccount,r as resolveSessionSidebarRouting,C as resolveActiveAccount,y as removeSidebarActiveRouting,t as pruneStickyAssignments,s as pruneActiveRouting,g as projectCustodyForSidebar,i as normalizeSidebarState,m as isUsableRoutingEntry,p as isQuotaExhausted,e as hashSidebarSessionId,f as getSidebarStateFile,j as getSidebarState,b as getPresentQuotaWindows,D as getCollapsedQuotaSummary,a as formatWindowLabel,o as exhaustedQuotaResetAt,B as drainSidebarWrites,E as computeQuotaPacing,A as clearSidebarStickyAssignment,d as STICKY_ASSIGNMENT_MAX_ENTRIES,c as STICKY_ASSIGNMENT_MAX_AGE_MS,h as DEFAULT_SIDEBAR_STATE,l as ACTIVE_ROUTING_MAX_ENTRIES,k as ACTIVE_ROUTING_MAX_AGE_MS};
1
+ import{A as x,B as y,C as z,D as A,E as B,F as C,G as D,H as E,d as a,e as b,f as c,g as d,h as e,i as f,j as g,k as h,l as i,m as j,n as k,o as l,p as m,q as n,r as o,s as p,t as q,u as r,v as s,w as t,x as u,y as v,z as w}from"./index-g3hsdjh4.js";import"./index-sq36b120.js";import"./index-hh52v8sb.js";import"./index-9ehhb051.js";export{w as upsertSidebarActiveRouting,n as spendControlExhaustedResetAt,u as setSidebarState,v as setSidebarMachineState,x as setSidebarLegacyRouting,z as resolveSidebarStickyAssignment,q as resolveSessionStickyAccount,r as resolveSessionSidebarRouting,C as resolveActiveAccount,y as removeSidebarActiveRouting,t as pruneStickyAssignments,s as pruneActiveRouting,g as projectCustodyForSidebar,i as normalizeSidebarState,m as isUsableRoutingEntry,p as isQuotaExhausted,e as hashSidebarSessionId,f as getSidebarStateFile,j as getSidebarState,b as getPresentQuotaWindows,D as getCollapsedQuotaSummary,a as formatWindowLabel,o as exhaustedQuotaResetAt,B as drainSidebarWrites,E as computeQuotaPacing,A as clearSidebarStickyAssignment,d as STICKY_ASSIGNMENT_MAX_ENTRIES,c as STICKY_ASSIGNMENT_MAX_AGE_MS,h as DEFAULT_SIDEBAR_STATE,l as ACTIVE_ROUTING_MAX_ENTRIES,k as ACTIVE_ROUTING_MAX_AGE_MS};
package/dist/tui.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { a as CommandModalName, r as ApplyRequest } from "./internal-Y7QNVDJT.js";
2
- import { b as SidebarState, c as QuotaPacing, l as QuotaWindow, r as AccountQuota, x as SpendControlReading } from "./sidebar-state-B98sERYt.js";
1
+ import { a as CommandModalName, r as ApplyRequest } from "./internal-BTndPmW2.js";
2
+ import { b as SidebarState, c as QuotaPacing, l as QuotaWindow, r as AccountQuota, x as SpendControlReading } from "./sidebar-state-CoKYKcLn.js";
3
3
  import "./rpc/protocol.js";
4
4
  import { TuiPluginModule } from "@opencode-ai/plugin/tui";
5
5
  //#region src/tui.d.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/opencode-openai-auth",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {
@@ -58,7 +58,7 @@
58
58
  "@cortexkit/subc-client": "^0.8.1",
59
59
  "@opentui/core": ">=0.5.11",
60
60
  "@opentui/solid": ">=0.5.11",
61
- "ai": "^7.0.99",
61
+ "ai": "^7.0.107",
62
62
  "jsonc-parser": "^3.3.1",
63
63
  "solid-js": "1.9.12"
64
64
  }
@@ -23,6 +23,8 @@ export interface AccountQuota {
23
23
  primary?: QuotaWindow
24
24
  secondary?: QuotaWindow
25
25
  spendControl?: SpendControlReading
26
+ // The source reported that no credit budget exists; see OAuthQuotaSnapshot.
27
+ spendControlCleared?: true
26
28
  resetCreditsAvailable?: number
27
29
  }
28
30
 
@@ -1104,6 +1106,19 @@ function freshestWindow(
1104
1106
  // of the merged result. Only safe when both snapshots share an account identity
1105
1107
  // (sameAccountIdentity) — an identity switch must whole-pick (freshestQuota) so
1106
1108
  // windows from two accounts are never combined.
1109
+ // The fresher side decides the budget when it knows anything about it: its own
1110
+ // reading, or its report that no budget exists. Only when it says nothing (a
1111
+ // header or WebSocket push, which never carries spend control) does the other
1112
+ // side's reading survive, and even then not if that side reported none.
1113
+ function mergeSpendControl(
1114
+ fresher: AccountQuota,
1115
+ older: AccountQuota,
1116
+ ): SpendControlReading | undefined {
1117
+ if (fresher.spendControl !== undefined) return fresher.spendControl
1118
+ if (fresher.spendControlCleared === true) return undefined
1119
+ return older.spendControl
1120
+ }
1121
+
1107
1122
  function mergeQuotaByWindow(
1108
1123
  incoming: AccountQuota | null,
1109
1124
  existing: AccountQuota | null,
@@ -1130,8 +1145,12 @@ function mergeQuotaByWindow(
1130
1145
  existing.checkedAt,
1131
1146
  )
1132
1147
  const spendControl = existingSnapshotIsFresher
1133
- ? (existing.spendControl ?? incoming.spendControl)
1134
- : (incoming.spendControl ?? existing.spendControl)
1148
+ ? mergeSpendControl(existing, incoming)
1149
+ : mergeSpendControl(incoming, existing)
1150
+ const spendControlCleared =
1151
+ spendControl === undefined &&
1152
+ (incoming.spendControlCleared === true ||
1153
+ existing.spendControlCleared === true)
1135
1154
  let checkedAt: number | undefined
1136
1155
  for (const stamp of [
1137
1156
  finiteWindowCheckedAt(primary),
@@ -1141,11 +1160,19 @@ function mergeQuotaByWindow(
1141
1160
  checkedAt = checkedAt === undefined ? stamp : Math.max(checkedAt, stamp)
1142
1161
  }
1143
1162
  }
1163
+ // Both budget fields are decided above, so neither may leak in from the
1164
+ // spread: an older incoming budget must not survive a fresher "no budget".
1165
+ const {
1166
+ spendControl: _incomingSpendControl,
1167
+ spendControlCleared: _incomingCleared,
1168
+ ...incomingRest
1169
+ } = incoming
1144
1170
  return {
1145
- ...incoming,
1171
+ ...incomingRest,
1146
1172
  primary,
1147
1173
  secondary,
1148
1174
  ...(spendControl !== undefined ? { spendControl } : {}),
1175
+ ...(spendControlCleared ? { spendControlCleared: true as const } : {}),
1149
1176
  checkedAt: checkedAt ?? incoming.checkedAt,
1150
1177
  }
1151
1178
  }
@@ -23,6 +23,8 @@ export interface AccountQuota {
23
23
  primary?: QuotaWindow
24
24
  secondary?: QuotaWindow
25
25
  spendControl?: SpendControlReading
26
+ // The source reported that no credit budget exists; see OAuthQuotaSnapshot.
27
+ spendControlCleared?: true
26
28
  resetCreditsAvailable?: number
27
29
  }
28
30
 
@@ -1104,6 +1106,19 @@ function freshestWindow(
1104
1106
  // of the merged result. Only safe when both snapshots share an account identity
1105
1107
  // (sameAccountIdentity) — an identity switch must whole-pick (freshestQuota) so
1106
1108
  // windows from two accounts are never combined.
1109
+ // The fresher side decides the budget when it knows anything about it: its own
1110
+ // reading, or its report that no budget exists. Only when it says nothing (a
1111
+ // header or WebSocket push, which never carries spend control) does the other
1112
+ // side's reading survive, and even then not if that side reported none.
1113
+ function mergeSpendControl(
1114
+ fresher: AccountQuota,
1115
+ older: AccountQuota,
1116
+ ): SpendControlReading | undefined {
1117
+ if (fresher.spendControl !== undefined) return fresher.spendControl
1118
+ if (fresher.spendControlCleared === true) return undefined
1119
+ return older.spendControl
1120
+ }
1121
+
1107
1122
  function mergeQuotaByWindow(
1108
1123
  incoming: AccountQuota | null,
1109
1124
  existing: AccountQuota | null,
@@ -1130,8 +1145,12 @@ function mergeQuotaByWindow(
1130
1145
  existing.checkedAt,
1131
1146
  )
1132
1147
  const spendControl = existingSnapshotIsFresher
1133
- ? (existing.spendControl ?? incoming.spendControl)
1134
- : (incoming.spendControl ?? existing.spendControl)
1148
+ ? mergeSpendControl(existing, incoming)
1149
+ : mergeSpendControl(incoming, existing)
1150
+ const spendControlCleared =
1151
+ spendControl === undefined &&
1152
+ (incoming.spendControlCleared === true ||
1153
+ existing.spendControlCleared === true)
1135
1154
  let checkedAt: number | undefined
1136
1155
  for (const stamp of [
1137
1156
  finiteWindowCheckedAt(primary),
@@ -1141,11 +1160,19 @@ function mergeQuotaByWindow(
1141
1160
  checkedAt = checkedAt === undefined ? stamp : Math.max(checkedAt, stamp)
1142
1161
  }
1143
1162
  }
1163
+ // Both budget fields are decided above, so neither may leak in from the
1164
+ // spread: an older incoming budget must not survive a fresher "no budget".
1165
+ const {
1166
+ spendControl: _incomingSpendControl,
1167
+ spendControlCleared: _incomingCleared,
1168
+ ...incomingRest
1169
+ } = incoming
1144
1170
  return {
1145
- ...incoming,
1171
+ ...incomingRest,
1146
1172
  primary,
1147
1173
  secondary,
1148
1174
  ...(spendControl !== undefined ? { spendControl } : {}),
1175
+ ...(spendControlCleared ? { spendControlCleared: true as const } : {}),
1149
1176
  checkedAt: checkedAt ?? incoming.checkedAt,
1150
1177
  }
1151
1178
  }
@@ -1,2 +0,0 @@
1
- function Z(k){if(k==null||k==="")return;let q=typeof k==="number"?k:Number(k);if(Number.isFinite(q)){let B=q<100000000000?q*1000:q,J=new Date(B);return Number.isNaN(J.getTime())?void 0:J.toISOString()}let z=new Date(k);return Number.isNaN(z.getTime())?void 0:z.toISOString()}function $(k){let q=Number(k);return Number.isFinite(q)&&q>0?q:void 0}function D(k){return typeof k==="number"&&Number.isFinite(k)&&k>=0?k:void 0}function I(k,q){let z=k.get(q);if(z===null||z.trim()==="")return;let B=Number(z);if(!Number.isFinite(B)||B<0||B>100)return;let J=q.slice(0,-13),X=$(k.get(`${J}-window-minutes`)),G=Z(k.get(`${J}-reset-at`)??void 0);if(B===0&&k.get(`${J}-window-minutes`)==="0"&&!G)return;return{usedPercent:B,remainingPercent:100-B,resetsAt:G,checkedAt:Date.now(),...X!==void 0?{windowMinutes:X}:{}}}var W=["x-codex-primary-used-percent","x-codex-secondary-used-percent"];function M(k,q){let z=k.get(q);if(z===null)return"absent";if(z.trim()==="")return"invalid";let B=Number(z);return Number.isFinite(B)&&B>=0&&B<=100?"valid":"invalid"}function C(k){if(W.some((J)=>M(k,J)==="invalid"))return{};let q={},z=I(k,"x-codex-primary-used-percent");if(z)q.primary=z;let B=I(k,"x-codex-secondary-used-percent");if(B)q.secondary=B;return q}function H(k){let q=W.map((z)=>M(k,z));return q.includes("valid")&&!q.includes("invalid")}function T(k){if(!k)return;if(!Number.isFinite(k.used_percent)||k.used_percent<0||k.used_percent>100)return;let q=$(k.window_minutes),z=Z(k.reset_at);if(k.used_percent===0&&q===void 0&&!z)return;return{usedPercent:k.used_percent,remainingPercent:100-k.used_percent,resetsAt:z,checkedAt:Date.now(),...q!==void 0?{windowMinutes:q}:{}}}function _(k){let q={},z=T(k.rate_limits?.primary);if(z)q.primary=z;let B=T(k.rate_limits?.secondary);if(B)q.secondary=B;return q}function V(k){if(k==null||k==="")return;let q=Number(k);return Number.isFinite(q)&&q>=0?q:void 0}function U(k){if(!k)return;if(!Number.isFinite(k.used_percent)||k.used_percent<0||k.used_percent>100)return;let q=$(k.limit_window_seconds),z=Z(k.reset_at);if(k.used_percent===0&&q===void 0&&!z)return;return{usedPercent:k.used_percent,remainingPercent:100-k.used_percent,resetsAt:z,checkedAt:Date.now(),...q!==void 0?{windowMinutes:q/60}:{}}}function R(k){let q={},z=U(k.rate_limit?.primary_window);if(z)q.primary=z;let B=U(k.rate_limit?.secondary_window);if(B)q.secondary=B;let J=D(k.rate_limit_reset_credits?.available_count);if(J!==void 0)q.resetCreditsAvailable=J;let X=D(k.rate_limit_reset_credits?.applicable_available_count);if(X!==void 0)q.resetCreditsApplicable=X;let G=k.spend_control?.individual_limit;if(G&&typeof k.spend_control?.reached==="boolean"){let Y=V(G.limit),O=V(G.used),Q=V(G.remaining),f=V(G.used_percent),x=V(G.remaining_percent);if(Y!==void 0&&O!==void 0&&Q!==void 0&&f!==void 0&&x!==void 0)q.spendControl={limit:Y,used:O,remaining:Q,usedPercent:f,remainingPercent:x,resetsAt:Z(G.reset_at),unit:G.unit,source:G.source,reached:k.spend_control.reached}}let K=k.credits;if(K&&typeof K.has_credits==="boolean"&&typeof K.unlimited==="boolean"&&typeof K.overage_limit_reached==="boolean"){let Y=V(K.balance);q.credits={hasCredits:K.has_credits,unlimited:K.unlimited,overageLimitReached:K.overage_limit_reached,...Y!==void 0?{balance:Y}:{}}}return q}
2
- export{Z as lb,C as mb,H as nb,_ as ob,R as pb};
@@ -1,2 +0,0 @@
1
- import{Ea as c,Z as o}from"./index-338z7171.js";import{createHash as YT,randomUUID as zT}from"node:crypto";import{chmod as DT,mkdir as KT,readFile as s,rename as UT,rm as BT,writeFile as QT}from"node:fs/promises";import{tmpdir as bT}from"node:os";import{dirname as PT,join as i}from"node:path";var k=["needs-login","mode-mismatch","corrupt-under-binding","manifest-unreadable","unbound-under-claustrum","orphan-tombstone","vault-cold","vault-reauth","identity-mismatch","no-handle","takeover-incomplete","new-local-family-under-claustrum","takeover-incomplete/vault-unavailable","takeover-incomplete/slot-absent"];function O(T){return T}function B(T,V){return T==="empty"?{...V,canonicalize:!0}:V}function CT(T){switch(T){case"real":return{kind:"LOCAL"};case"tombstone":case"empty":case"slot-absent":return{kind:"NEEDS_LOGIN"};case"gone":return{kind:"NEEDS_LOGIN",reason:"corrupt"}}return O(T)}function RT(T,V){switch(T){case"real":return V?{kind:"LOCAL"}:{kind:"INERT",reason:"needs-login"};case"tombstone":case"empty":case"slot-absent":return{kind:"INERT",reason:"mode-mismatch"};case"gone":return{kind:"INERT",reason:"corrupt-under-binding"}}return O(T)}function _T(T){switch(T){case"tombstone":case"empty":return{kind:"INERT",reason:"orphan-tombstone"};case"real":case"gone":case"slot-absent":return{kind:"INERT",reason:"unbound-under-claustrum"}}return O(T)}function jT(T,V){switch(V){case"serves":return B(T,{kind:"VAULT"});case"cold":return B(T,{kind:"INERT",reason:"vault-cold"});case"needs_reauth":return B(T,{kind:"INERT",reason:"vault-reauth"});case"identity_mismatch":return B(T,{kind:"INERT",reason:"identity-mismatch"});case"no_handle":return B(T,{kind:"INERT",reason:"no-handle"})}return O(V)}function JT(T,V){switch(T){case"serves":return V===!1?{kind:"INERT",reason:"new-local-family-under-claustrum"}:{kind:"INERT",reason:"takeover-incomplete"};case"cold":case"needs_reauth":return{kind:"INERT",reason:"takeover-incomplete/vault-unavailable"};case"identity_mismatch":return{kind:"INERT",reason:"identity-mismatch"};case"no_handle":return{kind:"INERT",reason:"no-handle"}}return O(T)}function ZT(T){switch(T){case"serves":return{kind:"VAULT",installTombstone:!0};case"cold":return{kind:"INERT",reason:"vault-cold",installTombstone:!0};case"needs_reauth":return{kind:"INERT",reason:"vault-reauth",installTombstone:!0};case"identity_mismatch":return{kind:"INERT",reason:"identity-mismatch"};case"no_handle":return{kind:"INERT",reason:"no-handle"}}return O(T)}function $T(T){switch(T){case"serves":case"cold":case"needs_reauth":return{kind:"INERT",reason:"takeover-incomplete/slot-absent"};case"identity_mismatch":return{kind:"INERT",reason:"identity-mismatch"};case"no_handle":return{kind:"INERT",reason:"no-handle"}}return O(T)}function GT(T,V,L){switch(T){case"tombstone":case"empty":return jT(T,V);case"real":return JT(V,L);case"gone":return ZT(V);case"slot-absent":return $T(V)}return O(T)}function aT(T){if(T.manifest==="unreadable")return{kind:"INERT",reason:"manifest-unreadable"};switch(T.mode){case"local":return T.manifest==="present"?RT(T.local,T.verifiedInProcessLogin):CT(T.local);case"claustrum":if(T.manifest==="absent")return _T(T.local);if(T.manifest==="present")return GT(T.local,T.vault(),T.fingerprintMatch);return O(T.manifest)}return O(T.mode)}var a=["primary","secondary"],n={primary:300,secondary:10080};function y(T){return Number.isInteger(T)?String(T):String(Math.round(T*10)/10)}function XT(T,V){let L=T!==void 0&&Number.isFinite(T)&&T>0?T:n[V];if(L<60)return`${y(L)}m`;if(L<1440)return`${y(L/60)}h`;return`${y(L/1440)}d`}function OT(T){if(!T)return[];let V=[];for(let L of a){let N=T[L];if(!N)continue;let E=N.windowMinutes,C=E!==void 0&&Number.isFinite(E)&&E>0?E:n[L];V.push({key:L,label:XT(C,L),window:N,windowMs:C*60000})}return V}var I=o("sidebar"),FT="OPENCODE_OPENAI_AUTH_SIDEBAR_STATE_FILE",WT=i(bT(),"opencode-openai-auth"),e=i(WT,"sidebar-state.json"),yT=/^[a-f0-9]{64}$/,S=604800000,HT=256,t=3600000;function F(T){return YT("sha256").update(T).digest("hex")}function MT(T){return typeof T==="number"&&Number.isFinite(T)&&T>=0?T:void 0}function A(T){let V=MT(T);return V!==void 0?{resetCredits:V}:{}}var qT=new Set(["vault","needsLogin","local","inert"]),IT=new Set([...k,"corrupt"]);function h(T){if(T===null||typeof T!=="object"||Array.isArray(T))return;let V=T;if(typeof V.state!=="string"||!qT.has(V.state))return;let N={state:V.state};if(typeof V.reason==="string"&&IT.has(V.reason))N.reason=V.reason;return N}function ST(T){if(T===null||typeof T!=="object"||Array.isArray(T))return;let V={};for(let[L,N]of Object.entries(T)){if(N===null||typeof N!=="object"||Array.isArray(N))continue;let E=N;if(typeof E.activeId!=="string"||typeof E.route!=="string"||typeof E.updatedAt!=="number"||!Number.isFinite(E.updatedAt))continue;V[L]={activeId:E.activeId,route:E.route,updatedAt:E.updatedAt}}return Object.keys(V).length>0?V:void 0}function fT(T){if(T===null||typeof T!=="object"||Array.isArray(T))return;let V={};for(let[L,N]of Object.entries(T)){if(!yT.test(L)||N===null||typeof N!=="object"||Array.isArray(N))continue;let E=N;if(typeof E.accountId!=="string"||E.accountId.length===0||typeof E.assignedAt!=="number"||!Number.isFinite(E.assignedAt)||E.assignedAt<0||typeof E.lastSeenAt!=="number"||!Number.isFinite(E.lastSeenAt)||E.lastSeenAt<0||typeof E.inputBytes!=="number"||!Number.isFinite(E.inputBytes)||E.inputBytes<0)continue;let C=E.quotaCheckedAt;if(C!==void 0&&(typeof C!=="number"||!Number.isFinite(C)||C<0))continue;let R=E.wireAccountId;V[L]={accountId:E.accountId,assignedAt:E.assignedAt,lastSeenAt:E.lastSeenAt,inputBytes:E.inputBytes,...C===void 0?{}:{quotaCheckedAt:C},...typeof R==="string"?{wireAccountId:R}:{}}}return Object.keys(V).length>0?V:void 0}function z(){return process.env[FT]||e}function NV(T){switch(T.kind){case"LOCAL":return{state:"local"};case"VAULT":return{state:"vault"};case"INERT":return{state:"inert",reason:T.reason};case"NEEDS_LOGIN":return T.reason==="corrupt"?{state:"needsLogin",reason:"corrupt"}:{state:"needsLogin"}}}var K={main:{quota:null,killed:!1},fallbacks:[],activeId:void 0,route:"main",lastUpdated:0};function f(T){if(T===null||typeof T!=="object"||Array.isArray(T))return K;let V=T,L=V.main,N;if(L!==null&&typeof L==="object"&&!Array.isArray(L)){let _=L;N={quota:"quota"in _?_.quota:null,killed:typeof _.killed==="boolean"?_.killed:!1,...typeof _.mainAccountId==="string"?{mainAccountId:_.mainAccountId}:{},...(()=>{let Y=h(_.custody);return Y?{custody:Y}:{}})(),...typeof _.quotaBackedOff==="boolean"?{quotaBackedOff:_.quotaBackedOff}:{},...typeof _.quotaBackoffUntil==="number"?{quotaBackoffUntil:_.quotaBackoffUntil}:{},...typeof _.refreshBackedOff==="boolean"?{refreshBackedOff:_.refreshBackedOff}:{},...typeof _.refreshBackoffUntil==="number"?{refreshBackoffUntil:_.refreshBackoffUntil}:{},...A(_.resetCredits)}}else N={quota:null,killed:!1};let E=V.fallbacks,C=Array.isArray(E)?E.filter((_)=>_!==null&&typeof _==="object"&&!Array.isArray(_)&&typeof _.id==="string").map((_)=>{let Y=h(_.custody);return{id:_.id,label:typeof _.label==="string"?_.label:void 0,...typeof _.accountId==="string"?{accountId:_.accountId}:{},quota:"quota"in _?_.quota:null,killed:typeof _.killed==="boolean"?_.killed:!1,enabled:typeof _.enabled==="boolean"?_.enabled:!0,...A(_.resetCredits),...Y?{custody:Y}:{}}}):[],R=typeof V.activeId==="string"?V.activeId:void 0,j=typeof V.route==="string"?V.route:K.route,J=typeof V.lastUpdated==="number"?V.lastUpdated:0,Z=typeof V.planType==="string"?V.planType:void 0,G=typeof V.credits==="number"?V.credits:void 0,$=ST(V.activeRouting),X=fT(V.stickyAssignments);return{main:N,fallbacks:C,activeId:R,route:j,lastUpdated:J,...$!==void 0?{activeRouting:$}:{},...X!==void 0?{stickyAssignments:X}:{},...Z!==void 0?{planType:Z}:{},...G!==void 0?{credits:G}:{}}}async function EV(T=z()){try{let V=await s(T,"utf8");return f(JSON.parse(V))}catch{return K}}var vT=3600000,p=128;function TT(T,V,L=Date.now()){if(!(T.updatedAt>=L-vT&&T.updatedAt<=L))return!1;if(V===void 0)return!0;return T.activeId==="main"||V.some((E)=>E.enabled!==!1&&E.killed!==!0&&E.id===T.activeId)}function xT(T,V=Date.now()){let L=T?.spendControl;if(L?.reached!==!0||typeof L.resetsAt!=="string")return;let N=Date.parse(L.resetsAt);if(!Number.isFinite(N)||N<=V)return;return{resetsAt:L.resetsAt,resetAtMs:N}}function kT(T,V=Date.now()){let L;for(let E of a){let C=T?.[E];if(typeof C?.resetsAt!=="string"||!Number.isFinite(C.usedPercent)||C.usedPercent<100)continue;let R=Date.parse(C.resetsAt);if(!Number.isFinite(R)||R<=V)continue;if(!L||R<L.resetAtMs)L={resetsAt:C.resetsAt,resetAtMs:R}}let N=xT(T,V);if(N&&(!L||N.resetAtMs<L.resetAtMs))L=N;return L}function Q(T,V=Date.now()){return kT(T,V)!==void 0}function AT(T,V,L=Date.now()){if(!V||T.route!=="sticky-balanced")return;let N=T.stickyAssignments?.[F(V)];if(!N||N.lastSeenAt<L-S)return;if(N.accountId==="main")return T.main?.killed||Q(T.main?.quota,L)?void 0:"main";let E=T.fallbacks?.find((C)=>C.id===N.accountId);if(!E||E.enabled===!1||E.killed===!0||Q(E.quota,L))return;return E.id}function CV(T,V,L=Date.now()){if(!V)return{activeId:T.activeId??"main",route:T.route};let N=V?T.activeRouting?.[V]:void 0,E=N?.activeId==="main"?T.main.quota:T.fallbacks.find((J)=>J.id===N?.activeId)?.quota;if(N&&TT(N,T.fallbacks,L)&&!Q(E,L))return{activeId:N.activeId,route:N.route};let C=AT(T,V,L);if(C)return{activeId:C,route:T.route};let R=T.fallbacks.filter((J)=>J.enabled&&!J.killed),j=R.find((J)=>!Q(J.quota,L))??R[0];return{activeId:T.route==="fallback-first"&&j?j.id:"main",route:T.route}}function VT(T,V,L=Date.now(),N){if(!T)return;let E=Object.entries(T).filter(([R,j])=>R!==N&&TT(j,V,L)),C=E.length<=p?E:E.sort((R,j)=>j[1].updatedAt-R[1].updatedAt).slice(0,p);return C.length>0?Object.fromEntries(C):void 0}function W(T,V,L=Date.now(),N){if(!T)return;let E=0,C=0,R=0,j=[];for(let[Z,G]of Object.entries(T)){if(Z===N){R+=1;continue}if(G.lastSeenAt<L-S){C+=1;continue}if(V!==void 0&&!V.has(G.accountId)){E+=1;continue}j.push([Z,G])}let J=E+C+R;if(J>0)I.debug("pruned sticky assignments",{pid:process.pid,removed:J,reasons:{"account-not-in-roster":E,expired:C,"explicit-removal":R}});return j.length>0?Object.fromEntries(j):void 0}function hT(T,V){let L=Object.keys(T).length-HT;if(L<=0)return T;let N=new Set(Object.entries(T).filter(([E])=>E!==V).sort(([E,C],[R,j])=>C.lastSeenAt-j.lastSeenAt||E.localeCompare(R)).slice(0,L).map(([E])=>E));return Object.fromEntries(Object.entries(T).filter(([E])=>!N.has(E)))}function pT(T,V){if(T===V)return!0;if(!T||!V)return!1;let L=Object.entries(T);if(L.length!==Object.keys(V).length)return!1;return L.every(([N,E])=>Object.is(V[N],E))}function r(T,V,L,N){return T!==void 0&&V.has(T.accountId)&&!L.has(T.accountId)&&T.lastSeenAt>=N-S}function w(T,V,L,N){return V>T.inputBytes||L-T.lastSeenAt>=t||T.wireAccountId===void 0&&N!==void 0}function m(T,V){return typeof T.wireAccountId==="string"&&typeof V==="string"&&T.wireAccountId!==V}function rT(T){let V=new Map(T),L={get size(){return V.size},has:(N)=>V.has(N),get:(N)=>V.get(N),entries:()=>V.entries(),keys:()=>V.keys(),values:()=>V.values(),forEach:(N,E)=>{V.forEach((C,R)=>{N.call(E,C,R,L)})},[Symbol.iterator]:()=>V[Symbol.iterator]()};return Object.freeze(L)}function wT(T,V,L){let N=new Map;for(let[E,C]of Object.entries(T??{})){if(E===L)continue;if(C.quotaCheckedAt!==V[C.accountId])continue;N.set(C.accountId,(N.get(C.accountId)??0)+C.inputBytes)}return rT(N)}function v(T){if(T===void 0)return;return new Set(["main",...T.filter((V)=>V.enabled!==!1&&V.killed!==!0).map((V)=>V.id)])}var H=Promise.resolve(),mT=3,dT=1e4,uT=15000;function D(T){let V=H.then(T);return H=V.catch(()=>{}),V}function RV(T,V=z()){return D(()=>q(T,V))}async function LT(T){try{return NT(await M(T))}catch{return K}}async function M(T){try{return await s(T,"utf8")}catch(V){if(V.code==="ENOENT")return"";throw V}}function NT(T){if(T==="")return K;try{return f(JSON.parse(T))}catch{return K}}async function lT(T){await ET(T);let V=Date.now()+uT;while(Date.now()<=V){let L=await c({name:"sidebar-write",path:T,ttlMs:dT,renew:!0});if(L)return L;await new Promise((N)=>setTimeout(N,10))}throw Error("Timed out waiting for the sidebar state write lock")}async function ET(T){let V=PT(T);if(await KT(V,{recursive:!0,mode:448}),T!==e)return;await DT(V,448).catch((L)=>{I.warn("sidebar directory permission remediation failed",{pid:process.pid,error:L instanceof Error?L.message:String(L)})})}async function U(T,V,L){let N=await lT(T);try{for(let R=0;R<mT;R+=1){let j=await M(T),J=V(NT(j));if(!J)return;if(R===0)await L?.beforeRecheck?.();if(await M(T)!==j)continue;await q(J,T);return}let E=await LT(T),C=V(E);if(C)await q(C,T)}finally{await N.release()}}function b(T){let V;for(let L of[T?.primary?.checkedAt,T?.secondary?.checkedAt,T?.checkedAt])if(typeof L==="number"&&Number.isFinite(L))V=V===void 0?L:Math.max(V,L);return V}function d(T,V){let L=b(T),N=b(V);if(N!==void 0&&(L===void 0||N>L))return V;return T}function u(T,V){return T!==void 0&&V!==void 0&&T===V}function P(T,V){let L=T?.checkedAt;if(typeof L==="number"&&Number.isFinite(L))return L;if(typeof V==="number"&&Number.isFinite(V))return V;return}function l(T,V,L,N,E){if(T&&V){let C=P(T,N),R=P(V,E);if(R!==void 0&&(C===void 0||R>C))return V;return T}return L?V:T}function g(T,V){if(!T)return V;if(!V)return T;let L=b(T),N=b(V),E=N!==void 0&&(L===void 0||N>L),C=l(T.primary,V.primary,E,T.checkedAt,V.checkedAt),R=l(T.secondary,V.secondary,E,T.checkedAt,V.checkedAt),j=E?V.spendControl??T.spendControl:T.spendControl??V.spendControl,J;for(let Z of[P(C),P(R)])if(Z!==void 0)J=J===void 0?Z:Math.max(J,Z);return{...T,primary:C,secondary:R,...j!==void 0?{spendControl:j}:{},checkedAt:J??T.checkedAt}}function _V(T,V=z(),L){return D(async()=>{await U(V,(N)=>{let E=new Map(N.fallbacks.map((Z)=>[Z.id,Z])),C=u(T.main.mainAccountId,N.main.mainAccountId),R=C?g(T.main.quota,N.main.quota):d(T.main.quota,N.main.quota),j=Date.now(),J=W(N.stickyAssignments,v(T.fallbacks),j);return{...N,...T,main:{...T.main,quota:R,mainAccountId:C?T.main.mainAccountId:R===N.main.quota&&R!==T.main.quota?N.main.mainAccountId:T.main.mainAccountId},fallbacks:T.fallbacks.map((Z)=>{let G=E.get(Z.id),$=u(Z.accountId,G?.accountId),X=$?g(Z.quota,G?.quota??null):d(Z.quota,G?.quota??null);return{...Z,quota:X,accountId:$?Z.accountId:X===G?.quota&&X!==Z.quota?G?.accountId:Z.accountId}}),activeId:N.activeId,activeRouting:N.activeRouting,stickyAssignments:J,lastUpdated:Math.max(j,N.lastUpdated+1)}},L)})}function jV(T,V,L=z(),N){return D(async()=>{await U(L,(E)=>{let C=VT({...E.activeRouting,[T.sessionId]:{activeId:T.activeId,route:T.route,updatedAt:T.updatedAt}},V,Date.now()),R=W(E.stickyAssignments,v(V),Date.now());return{...E,activeId:T.activeId,route:T.route,activeRouting:C,stickyAssignments:R,lastUpdated:Math.max(Date.now(),E.lastUpdated+1)}},N)})}function JV(T,V=z()){return D(async()=>{await U(V,(L)=>({...L,activeId:T.activeId,route:T.route,lastUpdated:Math.max(Date.now(),L.lastUpdated+1)}))})}function ZV(T,V,L=z(),N){return D(async()=>{await U(L,(E)=>{let C=Date.now(),R=VT(E.activeRouting,V,C,T),j=W(E.stickyAssignments,v(V),C,F(T));return{...E,activeRouting:R,stickyAssignments:j,lastUpdated:Math.max(Date.now(),E.lastUpdated+1)}},N)})}async function $V(T,V=z(),L){let N=F(T.sessionId),E=new Set(T.validPinnedAccountIds),C=new Set(T.excludeAccountIds),R=(await LT(V)).stickyAssignments?.[N];if(r(R,E,C,T.now)&&!m(R,T.wireAccountIdByAccount?.[R.accountId])&&!w(R,T.requestBytes,T.now,T.wireAccountIdByAccount?.[R.accountId]))return R;let j;return await D(async()=>{await U(V,(J)=>{let Z=W(J.stickyAssignments,E,T.now),G=!pT(J.stickyAssignments,Z),$=Z?.[N],X=$!==void 0&&m($,T.wireAccountIdByAccount?.[$.accountId]);if(r($,E,C,T.now)&&!X){let Y=w($,T.requestBytes,T.now,T.wireAccountIdByAccount?.[$.accountId]),x=Y?{...$,inputBytes:Math.max($.inputBytes,T.requestBytes),...$.wireAccountId===void 0&&T.wireAccountIdByAccount?.[$.accountId]!==void 0?{wireAccountId:T.wireAccountIdByAccount?.[$.accountId]}:{},...T.now-$.lastSeenAt>=t?{lastSeenAt:T.now}:{}}:$;if(j=x,!G&&!Y)return;return{...J,stickyAssignments:{...Z,[N]:x},lastUpdated:Math.max(T.now,J.lastUpdated+1)}}let _=T.choose(wT(Z,T.quotaCheckedAtByAccount,X?N:void 0));if(!_){if(j=void 0,!G)return;return{...J,stickyAssignments:Z,lastUpdated:Math.max(T.now,J.lastUpdated+1)}}return j={accountId:_.accountId,assignedAt:T.now,lastSeenAt:T.now,inputBytes:T.requestBytes,..._.quotaCheckedAt===void 0?{}:{quotaCheckedAt:_.quotaCheckedAt},...T.wireAccountIdByAccount?.[_.accountId]===void 0?{}:{wireAccountId:T.wireAccountIdByAccount?.[_.accountId]}},{...J,stickyAssignments:hT({...Z,[N]:j},N),lastUpdated:Math.max(T.now,J.lastUpdated+1)}},L)}),j}async function GV(T,V=z()){let L=F(T),N=!1;return await D(async()=>{await U(V,(E)=>{let C=E.stickyAssignments;if(C?.[L]===void 0){N=!1;return}N=!0;let{[L]:R,...j}=C;return{...E,...Object.keys(j).length>0?{stickyAssignments:j}:{stickyAssignments:void 0},lastUpdated:Math.max(Date.now(),E.lastUpdated+1)}})}),N}async function q(T,V){let L=`${V}.${zT()}.tmp`;try{await ET(V),await QT(L,JSON.stringify(f(T)),{encoding:"utf8",mode:384}),await UT(L,V)}catch(N){throw await BT(L,{force:!0}).catch(()=>{}),I.warn("sidebar write failed",{pid:process.pid,error:N instanceof Error?N.message:String(N)}),N}}function XV(){return H}function OV(T){let V=T.activeId;if(V&&V!=="main"){let L=T.fallbacks.find((N)=>N.enabled&&N.id===V);if(L)return{id:L.id,name:L.label??L.id,quota:L.quota,killed:L.killed}}return{id:"main",name:"main",quota:T.main.quota,killed:T.main.killed}}function YV(T){let V=T?.primary?.usedPercent??null,L=T?.secondary?.usedPercent??null,N=OT(T);return{primaryUsedPercent:V,secondaryUsedPercent:L,text:N.length===0?null:N.map(({label:E,window:C})=>`${E}: ${Math.round(C.usedPercent)}%`).join(" ")}}var gT=300000,oT=0.01,cT=1;function zV(T,V,L){if(!T.resetsAt)return null;let N=new Date(T.resetsAt).getTime();if(!Number.isFinite(N))return null;let E=N-V,C=L-E;if(C<gT)return null;if(C<V*oT)return null;if(C>=V)return null;let R=T.usedPercent,j=Math.min(Math.max(C/V*100,0),100),J=R-j,Z=Math.abs(J)<cT?"on-pace":J>0?"deficit":"reserve",G=null;if(R>0){let $=C*100/R,X=E+$;if(X<N)G=new Date(X).toISOString()}return{pacePercent:j,deltaPercent:J,state:Z,runsOutAt:G}}
2
- export{aT as c,XT as d,OT as e,S as f,HT as g,F as h,z as i,NV as j,K as k,f as l,EV as m,vT as n,p as o,TT as p,xT as q,kT as r,Q as s,AT as t,CV as u,VT as v,W as w,RV as x,_V as y,jV as z,JV as A,ZV as B,$V as C,GV as D,XV as E,OV as F,YV as G,zV as H};
@@ -1 +0,0 @@
1
- import{lb as a,mb as b,nb as c,ob as d,pb as e}from"./index-301y4qa1.js";import"./index-9ehhb051.js";export{a as toResetIso,d as normalizeWsFrame,e as normalizeWham,b as normalizeQuotaHeaders,c as isCompleteQuotaHeaderFrame};