@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.
Files changed (2) hide show
  1. package/dist/index.js +31 -33
  2. 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 (!config.fetchInterception)
692
- return;
693
- const providers = cfg.provider ?? {};
694
- for (const [pid, pCfg] of Object.entries(providers)) {
695
- if (!pCfg || typeof pCfg !== "object")
696
- continue;
697
- const pc = pCfg;
698
- const models = pc.models ?? {};
699
- for (const [mid] of Object.entries(models)) {
700
- const origFetch = pc.options?.fetch;
701
- const baseFetch = origFetch ?? globalThis.fetch.bind(globalThis);
702
- const wrapped = createWrappedFetch(baseFetch, {
703
- config,
704
- providerId: pid,
705
- modelId: mid,
706
- onRateLimited: (p, m, reason) => {
707
- logger.warn(`Fallback triggered: ${p}/${m} — ${reason}`);
708
- },
709
- onFatalError: (p, m, reason) => {
710
- logger.error(`Fatal: ${p}/${m} — ${reason}`);
711
- }
712
- });
713
- if (!pc.options)
714
- pc.options = {};
715
- pc.options.fetch = wrapped;
716
- logger.info(`Fetch injected: ${pid}/${mid}`);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crystalfluxay/opencode-rate-limiter",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "OpenCode plugin for proactive TPM/RPM rate limiting with multi-provider fallback and fuzzy error matching",
5
5
  "author": {
6
6
  "name": "crystalfluxay"