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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
71
|
-
|
|
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 : "
|
|
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
|
});
|