minecodex 2.0.46 → 2.0.47

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.
@@ -31,11 +31,16 @@ function nativeContext(rail) {
31
31
  }
32
32
  function currentWindows(context) {
33
33
  const { auth, client } = context;
34
- if (auth?.isLoading || !auth?.userId || !auth?.accountId || !["chatgpt", "chatgptAuthTokens"].includes(auth.authMethod)) return null;
35
- const data = client?.getQueryData(["rate-limit-status"]);
36
- // 账号与缓存必须同时一致;旧账号的最后一次响应不能留在导航栏。
37
- if (!data || data.user_id !== auth.userId || data.account_id !== auth.accountId) return null;
38
- return remainingWindows(data, client.getQueryState?.(["rate-limit-status"])?.dataUpdatedAt);
34
+ if (auth?.isLoading || !auth?.userId || !auth?.accountId || !["chatgpt", "chatgptAuthTokens"].includes(auth.authMethod)) return {windows:null,reason:"account-unavailable"};
35
+ // 只依赖查询族;Codex 可在键尾增加身份或宿主范围。响应身份才是归属依据。
36
+ const queries = client?.getQueryCache().findAll({queryKey:["rate-limit-status"]}) ?? [];
37
+ const current = queries.filter(query => query.state.data?.user_id === auth.userId
38
+ && query.state.data?.account_id === auth.accountId)
39
+ .sort((a,b) => (b.state.dataUpdatedAt ?? 0) - (a.state.dataUpdatedAt ?? 0))[0];
40
+ if (!current) return {windows:null,reason:queries.some(query => query.state.data)
41
+ ? "current-account-quota-unavailable" : "quota-cache-pending"};
42
+ const windows=remainingWindows(current.state.data,current.state.dataUpdatedAt);
43
+ return {windows,reason:windows ? null : "quota-window-contract-unavailable"};
39
44
  }
40
45
  function findAvatar(rail) {
41
46
  const buttons = [...(rail?.querySelectorAll("button") ?? [])];
@@ -65,10 +70,12 @@ function avatarAnchor(avatar, rail) {
65
70
  unsubscribe?.(); client=context.client;
66
71
  unsubscribe=client?.getQueryCache().subscribe(event=>{ if (event.query?.queryKey?.[0] === "rate-limit-status") invalidate(); });
67
72
  }
68
- const windows=currentWindows(context), avatar=findAvatar(rail), usage=findUsage(rail);
73
+ const {windows,reason:quotaReason}=currentWindows(context), avatar=findAvatar(rail), usage=findUsage(rail);
69
74
  const available=Boolean((usage || avatar) && context.router && windows);
70
- codex.report("usage-meter",available,available ? null : "account-quota-or-anchor-unavailable");
71
- return { rail,avatar,usage,windows,available,anchorAvailable:Boolean((usage || avatar) && context.router),
75
+ const reason=available ? null : !rail ? "rail-unavailable" : !(usage || avatar)
76
+ ? "usage-anchor-unavailable" : !context.router ? "usage-navigation-unavailable" : quotaReason;
77
+ codex.report("usage-meter",available,reason);
78
+ return { rail,avatar,usage,windows,available,reason,anchorAvailable:Boolean((usage || avatar) && context.router),
72
79
  applicable:context.auth?.isLoading ? null : context.auth ? ["chatgpt","chatgptAuthTokens"].includes(context.auth.authMethod) : null };
73
80
  }
74
81
  function open(rail) { const {router}=nativeContext(rail); return router?.navigate("/settings/usage?tab=overview",{state:router.state?.location?.state}); }
@@ -200,7 +200,7 @@ sync();
200
200
  config.registerSelfCheck?.(() => {
201
201
  const snapshot=nativeUsage.read();
202
202
  const available=Boolean(snapshot.available && record?.button.isConnected);
203
- return {state:available ? "available" : snapshot.applicable === false ? "not-applicable" : !snapshot.anchorAvailable && snapshot.rail ? "unavailable" : "unknown",reason:available ? null : "quota-data-or-anchor-unavailable",
203
+ return {state:available ? "available" : snapshot.applicable === false ? "not-applicable" : ((!snapshot.anchorAvailable && snapshot.rail) || snapshot.reason === "quota-window-contract-unavailable") ? "unavailable" : "unknown",reason:available ? null : snapshot.reason ?? "usage-meter-mount-unavailable",
204
204
  checks:[{name:"usage-anchor",available:Boolean(snapshot.usage || snapshot.avatar)},{name:"account-quota",available:Boolean(snapshot.windows)},{name:"usage-meter-mount",available:Boolean(record?.button.isConnected)}],
205
205
  scopes:[{name:"account",element:snapshot.usage || snapshot.avatar}]};
206
206
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minecodex",
3
- "version": "2.0.46",
3
+ "version": "2.0.47",
4
4
  "description": "Lightweight, local-first plugins for the Codex desktop app.",
5
5
  "license": "MIT",
6
6
  "type": "module",