@crystalfluxay/opencode-rate-limiter 0.1.1 → 0.1.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 +31 -33
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -688,34 +688,39 @@ var RateLimitPlugin = async ({ client, directory, worktree }) => {
|
|
|
688
688
|
tokenCounter.startResetTimer();
|
|
689
689
|
return {
|
|
690
690
|
async config(cfg) {
|
|
691
|
-
if (
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
pc.options =
|
|
715
|
-
|
|
716
|
-
|
|
691
|
+
if (config.fetchInterception) {
|
|
692
|
+
const providers = cfg.provider ?? {};
|
|
693
|
+
for (const [pid, pCfg] of Object.entries(providers)) {
|
|
694
|
+
if (!pCfg || typeof pCfg !== "object")
|
|
695
|
+
continue;
|
|
696
|
+
const pc = pCfg;
|
|
697
|
+
const models = pc.models ?? {};
|
|
698
|
+
for (const [mid] of Object.entries(models)) {
|
|
699
|
+
const origFetch = pc.options?.fetch;
|
|
700
|
+
const baseFetch = origFetch ?? globalThis.fetch.bind(globalThis);
|
|
701
|
+
const wrapped = createWrappedFetch(baseFetch, {
|
|
702
|
+
config,
|
|
703
|
+
providerId: pid,
|
|
704
|
+
modelId: mid,
|
|
705
|
+
onRateLimited: (p, m, reason) => {
|
|
706
|
+
logger.warn(`Fallback triggered: ${p}/${m} — ${reason}`);
|
|
707
|
+
},
|
|
708
|
+
onFatalError: (p, m, reason) => {
|
|
709
|
+
logger.error(`Fatal: ${p}/${m} — ${reason}`);
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
if (!pc.options)
|
|
713
|
+
pc.options = {};
|
|
714
|
+
pc.options.fetch = wrapped;
|
|
715
|
+
logger.info(`Fetch injected: ${pid}/${mid}`);
|
|
716
|
+
}
|
|
717
717
|
}
|
|
718
718
|
}
|
|
719
|
+
cfg.command = cfg.command ?? {};
|
|
720
|
+
cfg.command["rate-limit-status"] = {
|
|
721
|
+
description: "Show rate limit status and statistics",
|
|
722
|
+
template: buildStatusReport(config)
|
|
723
|
+
};
|
|
719
724
|
},
|
|
720
725
|
event: async ({ event }) => {
|
|
721
726
|
handleEvent(event, {
|
|
@@ -725,13 +730,6 @@ var RateLimitPlugin = async ({ client, directory, worktree }) => {
|
|
|
725
730
|
}
|
|
726
731
|
});
|
|
727
732
|
},
|
|
728
|
-
async command(cfg) {
|
|
729
|
-
cfg.command = cfg.command ?? {};
|
|
730
|
-
cfg.command["rate-limit-status"] = {
|
|
731
|
-
description: "Show rate limit status and statistics",
|
|
732
|
-
template: buildStatusReport(config)
|
|
733
|
-
};
|
|
734
|
-
},
|
|
735
733
|
cleanup: () => {
|
|
736
734
|
tokenCounter.destroy();
|
|
737
735
|
}
|
package/package.json
CHANGED