opencode-anthropic-multi-account 0.2.0 → 0.2.2
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/index.js +35 -3
- package/dist/ui/auth-menu.d.ts +3 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -699,8 +699,16 @@ function createAccountManagerForProvider(dependencies) {
|
|
|
699
699
|
}
|
|
700
700
|
async applyUsageCache(uuid, usage) {
|
|
701
701
|
await this.store.mutateAccount(uuid, (account) => {
|
|
702
|
+
const now = Date.now();
|
|
703
|
+
const exhaustedTierResetTimes = [usage.five_hour, usage.seven_day].flatMap((tier) => {
|
|
704
|
+
if (tier == null || tier.utilization < 100 || tier.resets_at == null) {
|
|
705
|
+
return [];
|
|
706
|
+
}
|
|
707
|
+
return [Date.parse(tier.resets_at)];
|
|
708
|
+
}).filter((resetAt) => Number.isFinite(resetAt) && resetAt > now);
|
|
702
709
|
account.cachedUsage = usage;
|
|
703
710
|
account.cachedUsageAt = Date.now();
|
|
711
|
+
account.rateLimitResetAt = exhaustedTierResetTimes.length > 0 ? Math.min(...exhaustedTierResetTimes) : void 0;
|
|
704
712
|
});
|
|
705
713
|
}
|
|
706
714
|
async applyProfileCache(uuid, profile) {
|
|
@@ -2019,11 +2027,11 @@ function getUsageSummary(account) {
|
|
|
2019
2027
|
const parts = [];
|
|
2020
2028
|
const { five_hour, seven_day } = account.cachedUsage;
|
|
2021
2029
|
if (five_hour) {
|
|
2022
|
-
const reset = five_hour.resets_at ? ` (resets ${formatTimeRemaining(five_hour.resets_at)})` : "";
|
|
2030
|
+
const reset = five_hour.utilization >= 100 && five_hour.resets_at ? ` (resets ${formatTimeRemaining(five_hour.resets_at)})` : "";
|
|
2023
2031
|
parts.push(`5h: ${five_hour.utilization.toFixed(0)}%${reset}`);
|
|
2024
2032
|
}
|
|
2025
2033
|
if (seven_day) {
|
|
2026
|
-
const reset = seven_day.resets_at ? ` (resets ${formatTimeRemaining(seven_day.resets_at)})` : "";
|
|
2034
|
+
const reset = seven_day.utilization >= 100 && seven_day.resets_at ? ` (resets ${formatTimeRemaining(seven_day.resets_at)})` : "";
|
|
2027
2035
|
parts.push(`7d: ${seven_day.utilization.toFixed(0)}%${reset}`);
|
|
2028
2036
|
}
|
|
2029
2037
|
return parts.length > 0 ? parts.join(", ") : "no data";
|
|
@@ -2078,6 +2086,20 @@ function formatDate(timestamp) {
|
|
|
2078
2086
|
function getAccountStatus(account) {
|
|
2079
2087
|
if (account.isAuthDisabled) return "auth-disabled";
|
|
2080
2088
|
if (!account.enabled) return "disabled";
|
|
2089
|
+
if (account.cachedUsage) {
|
|
2090
|
+
const now = Date.now();
|
|
2091
|
+
const usage = account.cachedUsage;
|
|
2092
|
+
const hasEvaluableUsageTier = [usage.five_hour, usage.seven_day].some((tier) => tier != null);
|
|
2093
|
+
const exhaustedTiers = [usage.five_hour, usage.seven_day].filter(
|
|
2094
|
+
(tier) => tier && tier.utilization >= 100 && tier.resets_at != null && Date.parse(tier.resets_at) > now
|
|
2095
|
+
);
|
|
2096
|
+
if (exhaustedTiers.length > 0) {
|
|
2097
|
+
return "rate-limited";
|
|
2098
|
+
}
|
|
2099
|
+
if (hasEvaluableUsageTier) {
|
|
2100
|
+
return "active";
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2081
2103
|
if (account.rateLimitResetAt && account.rateLimitResetAt > Date.now()) return "rate-limited";
|
|
2082
2104
|
return "active";
|
|
2083
2105
|
}
|
|
@@ -2198,7 +2220,7 @@ function printUsageEntry(name, entry, isLast) {
|
|
|
2198
2220
|
return;
|
|
2199
2221
|
}
|
|
2200
2222
|
const bar = createProgressBar(entry.utilization);
|
|
2201
|
-
const reset = formatResetTime(entry.resets_at);
|
|
2223
|
+
const reset = entry.utilization >= 100 && entry.resets_at ? formatResetTime(entry.resets_at) : "";
|
|
2202
2224
|
console.log(` ${connector} ${name.padEnd(16)} ${bar}${reset}`);
|
|
2203
2225
|
}
|
|
2204
2226
|
function printQuotaReport(account, usage) {
|
|
@@ -2725,6 +2747,16 @@ var ClaudeMultiAuthPlugin = async (ctx) => {
|
|
|
2725
2747
|
const remaining = formatWaitTime(account.rateLimitResetAt - Date.now());
|
|
2726
2748
|
statusParts.push(`RATE LIMITED (resets in ${remaining})`);
|
|
2727
2749
|
}
|
|
2750
|
+
if (account.cachedUsage) {
|
|
2751
|
+
const now = Date.now();
|
|
2752
|
+
const usage2 = account.cachedUsage;
|
|
2753
|
+
const exhaustedTiers = [usage2.five_hour, usage2.seven_day].filter(
|
|
2754
|
+
(tier) => tier && tier.utilization >= 100 && tier.resets_at != null && Date.parse(tier.resets_at) > now
|
|
2755
|
+
);
|
|
2756
|
+
if (exhaustedTiers.length > 0) {
|
|
2757
|
+
statusParts.push("USAGE EXHAUSTED");
|
|
2758
|
+
}
|
|
2759
|
+
}
|
|
2728
2760
|
lines.push(
|
|
2729
2761
|
`- **${label}**${planBadge}${marker}: ${statusParts.join(" | ")} | ${usage}`
|
|
2730
2762
|
);
|
package/dist/ui/auth-menu.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export type AuthMenuAction = {
|
|
|
13
13
|
type: "cancel";
|
|
14
14
|
};
|
|
15
15
|
export type AccountAction = "back" | "toggle" | "delete" | "retry-auth" | "cancel";
|
|
16
|
+
type AccountStatus = "active" | "rate-limited" | "auth-disabled" | "disabled";
|
|
17
|
+
export declare function getAccountStatus(account: ManagedAccount): AccountStatus;
|
|
16
18
|
export declare function showAuthMenu(accounts: ManagedAccount[]): Promise<AuthMenuAction>;
|
|
17
19
|
export declare function showManageAccounts(accounts: ManagedAccount[]): Promise<{
|
|
18
20
|
action: AccountAction;
|
|
@@ -21,3 +23,4 @@ export declare function showManageAccounts(accounts: ManagedAccount[]): Promise<
|
|
|
21
23
|
export declare function printQuotaReport(account: ManagedAccount, usage: UsageLimits): void;
|
|
22
24
|
export declare function showStrategySelect(current: AccountSelectionStrategy): Promise<AccountSelectionStrategy | null>;
|
|
23
25
|
export declare function printQuotaError(account: ManagedAccount, error: string): void;
|
|
26
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-anthropic-multi-account",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "OpenCode plugin for Anthropic multi-account management with automatic rate limit switching",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"directory": "packages/anthropic-multi-account"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"opencode-multi-account-core": "^0.2.
|
|
42
|
+
"opencode-multi-account-core": "^0.2.2",
|
|
43
43
|
"opencode-anthropic-auth": "^0.0.13",
|
|
44
44
|
"valibot": "^1.2.0"
|
|
45
45
|
},
|