@yugimob/pi-opencode-go-rotation 1.6.0 → 1.6.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/README.md +3 -3
- package/dist/index.d.ts +6 -1
- package/dist/index.js +38 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -44,13 +44,13 @@ Usage commands use `https://opencode.ai/zen/go/v1/usage` and stop waiting after
|
|
|
44
44
|
|
|
45
45
|
## Footer usage
|
|
46
46
|
|
|
47
|
-
While the selected model uses the `opencode-go` provider, the extension keeps a status line in pi's footer with the active key and
|
|
47
|
+
While the selected model uses the `opencode-go` provider, the extension keeps a status line in pi's footer with the active key's name, the usage windows, and the monthly renewal date:
|
|
48
48
|
|
|
49
49
|
```text
|
|
50
|
-
|
|
50
|
+
personal · 5h 12% · wk 40% · mo 55% | ↻ Nov 12
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
It refreshes on session start, model changes, turns, key rotations, manual key commands, and every 5 minutes.
|
|
53
|
+
It refreshes on session start, model changes, turns, key rotations, manual key commands, and every 5 minutes. The active key's name leads the line, and switching to another provider clears it.
|
|
54
54
|
|
|
55
55
|
## Commands
|
|
56
56
|
|
package/dist/index.d.ts
CHANGED
|
@@ -91,7 +91,12 @@ export declare function parseOpenCodeGoUsage(value: unknown): OpenCodeGoUsageRes
|
|
|
91
91
|
export declare function formatResetIn(seconds: number): string;
|
|
92
92
|
export declare function formatUsageStatus(result: UsageFetchResult): string;
|
|
93
93
|
export declare function shortUsageWindowLabel(name: string | undefined, index: number): string;
|
|
94
|
-
export
|
|
94
|
+
export interface FooterUsageOptions {
|
|
95
|
+
keyName?: string;
|
|
96
|
+
nowMs?: number;
|
|
97
|
+
error?: string;
|
|
98
|
+
}
|
|
99
|
+
export declare function formatFooterUsage(windows: OpenCodeGoUsageWindow[], options?: FooterUsageOptions): string;
|
|
95
100
|
export declare function createOpencodeGoRotationExtension(options?: ExtensionOptions): (pi: ExtensionAPI) => void;
|
|
96
101
|
declare const extension: (pi: ExtensionAPI) => void;
|
|
97
102
|
export default extension;
|
package/dist/index.js
CHANGED
|
@@ -606,18 +606,40 @@ export function shortUsageWindowLabel(name, index) {
|
|
|
606
606
|
return "mo";
|
|
607
607
|
return name;
|
|
608
608
|
}
|
|
609
|
-
export function formatFooterUsage(
|
|
610
|
-
|
|
611
|
-
|
|
609
|
+
export function formatFooterUsage(windows, options = {}) {
|
|
610
|
+
const prefix = `${options.keyName ?? "opencode-go"} · `;
|
|
611
|
+
if (options.error !== undefined)
|
|
612
|
+
return `${prefix}usage unavailable: ${options.error}`;
|
|
612
613
|
if (windows.length === 0)
|
|
613
|
-
return
|
|
614
|
+
return `${prefix}no usage windows`;
|
|
614
615
|
const parts = windows.map((window, index) => {
|
|
615
616
|
const label = shortUsageWindowLabel(window.name, index);
|
|
616
617
|
const percent = usageWindowPercent(window);
|
|
617
618
|
return `${label} ${percent === undefined ? "?" : `${Math.round(percent)}%`}`;
|
|
618
619
|
});
|
|
619
620
|
const rateLimited = windows.some((window) => window.status === "rate-limited");
|
|
620
|
-
|
|
621
|
+
const renewal = monthlyRenewalDate(windows, options.nowMs ?? Date.now());
|
|
622
|
+
return `${prefix}${parts.join(" · ")}${rateLimited ? " · rate-limited" : ""}${renewal === undefined ? "" : ` | ↻ ${formatRenewalDate(renewal)}`}`;
|
|
623
|
+
}
|
|
624
|
+
function monthlyRenewalDate(windows, nowMs) {
|
|
625
|
+
const monthly = windows.find((window, index) => shortUsageWindowLabel(window.name, index) === "mo");
|
|
626
|
+
if (!monthly)
|
|
627
|
+
return undefined;
|
|
628
|
+
for (const value of [monthly.resetAt, monthly.endAt]) {
|
|
629
|
+
if (!value)
|
|
630
|
+
continue;
|
|
631
|
+
const parsed = Date.parse(value);
|
|
632
|
+
if (Number.isFinite(parsed))
|
|
633
|
+
return parsed;
|
|
634
|
+
}
|
|
635
|
+
if (monthly.resetInSec !== undefined && Number.isFinite(monthly.resetInSec))
|
|
636
|
+
return nowMs + monthly.resetInSec * 1000;
|
|
637
|
+
return undefined;
|
|
638
|
+
}
|
|
639
|
+
const MONTH_NAMES = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
640
|
+
function formatRenewalDate(ms) {
|
|
641
|
+
const date = new Date(ms);
|
|
642
|
+
return `${MONTH_NAMES[date.getUTCMonth()]} ${date.getUTCDate()}`;
|
|
621
643
|
}
|
|
622
644
|
function usageWindowPercent(window) {
|
|
623
645
|
if (window.usagePercent !== undefined)
|
|
@@ -825,7 +847,9 @@ export function createOpencodeGoRotationExtension(options = {}) {
|
|
|
825
847
|
return;
|
|
826
848
|
if (!refreshConfig() || getActiveUsageTarget(config)?.keyIndex !== target.keyIndex)
|
|
827
849
|
return;
|
|
828
|
-
setUsageStatus(usage.ok
|
|
850
|
+
setUsageStatus(usage.ok
|
|
851
|
+
? formatFooterUsage(usage.usage.windows, { keyName: target.keyName, nowMs: currentTime })
|
|
852
|
+
: formatFooterUsage([], { keyName: target.keyName, nowMs: currentTime, error: usage.message }));
|
|
829
853
|
})();
|
|
830
854
|
usageStatusInFlight = request;
|
|
831
855
|
try {
|
|
@@ -898,16 +922,13 @@ export function createOpencodeGoRotationExtension(options = {}) {
|
|
|
898
922
|
const candidates = getQuotaBlockedTargets(config, currentTime, skipKeyIndex)
|
|
899
923
|
.map((target) => captureSelectionSnapshot(config, currentTime, target.keyIndex))
|
|
900
924
|
.filter((snapshot) => snapshot !== undefined);
|
|
901
|
-
const
|
|
902
|
-
for (const candidate of candidates) {
|
|
925
|
+
const results = await Promise.all(candidates.map(async (candidate) => {
|
|
903
926
|
const usage = await fetchOpenCodeGoUsage(candidate, fetchApi, options.timers);
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
}
|
|
910
|
-
return recovered;
|
|
927
|
+
return hasConfirmedHeadroom(usage) ? candidate : undefined;
|
|
928
|
+
}));
|
|
929
|
+
if (!refreshConfig())
|
|
930
|
+
return [];
|
|
931
|
+
return results.filter((snapshot) => snapshot !== undefined);
|
|
911
932
|
}
|
|
912
933
|
function selectNextKey(mode, freshConfig, startIndex, currentTime) {
|
|
913
934
|
return mode.kind === "quota"
|
|
@@ -1151,9 +1172,7 @@ export function createOpencodeGoRotationExtension(options = {}) {
|
|
|
1151
1172
|
}
|
|
1152
1173
|
// On reload: re-apply active key, skip auto-import
|
|
1153
1174
|
if (event.reason === "reload") {
|
|
1154
|
-
|
|
1155
|
-
if (keyName)
|
|
1156
|
-
ctx.ui.notify(`OpenCode: Active key → ${keyName}`, "info");
|
|
1175
|
+
applySynchronizedActiveKey(ctx);
|
|
1157
1176
|
syncUsageStatus(ctx, true);
|
|
1158
1177
|
return;
|
|
1159
1178
|
}
|
|
@@ -1173,9 +1192,7 @@ export function createOpencodeGoRotationExtension(options = {}) {
|
|
|
1173
1192
|
return;
|
|
1174
1193
|
}
|
|
1175
1194
|
}
|
|
1176
|
-
|
|
1177
|
-
if (keyName)
|
|
1178
|
-
ctx.ui.notify(`OpenCode: Active key → ${keyName}`, "info");
|
|
1195
|
+
applySynchronizedActiveKey(ctx);
|
|
1179
1196
|
syncUsageStatus(ctx, true);
|
|
1180
1197
|
});
|
|
1181
1198
|
pi.on("model_select", (_event, ctx) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yugimob/pi-opencode-go-rotation",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.2",
|
|
4
4
|
"description": "Rotate between multiple OpenCode Go API keys with reactive 429, rate-limit, and watchdog stall detection, plus live footer usage for the active key",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|