@yugimob/pi-opencode-go-rotation 1.6.0 → 1.6.1
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 +30 -6
- 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 {
|
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.1",
|
|
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",
|