@azumag/opencode-rate-limit-fallback 1.0.21 → 1.0.22
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 +6 -8
- package/dist/index.js +12 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -89,16 +89,14 @@ If no configuration is provided, the following models are used:
|
|
|
89
89
|
|
|
90
90
|
## How It Works
|
|
91
91
|
|
|
92
|
-
1. **Detection**: The plugin listens for rate limit errors via:
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
92
|
+
1. **Detection**: The plugin listens for rate limit errors via:
|
|
93
|
+
- `session.error` events
|
|
94
|
+
- `message.updated` events with errors
|
|
95
|
+
- `session.status` events with `type: "retry"`
|
|
96
96
|
|
|
97
|
-
2. **
|
|
97
|
+
2. **Fallback**: The plugin selects the next available model from the fallback list and resends the last user message using the `promptAsync` API.
|
|
98
98
|
|
|
99
|
-
3. **
|
|
100
|
-
|
|
101
|
-
4. **Cooldown**: Rate-limited models are tracked and skipped for the configured cooldown period.
|
|
99
|
+
3. **Cooldown**: Rate-limited models are tracked and skipped for the configured cooldown period.
|
|
102
100
|
|
|
103
101
|
## License
|
|
104
102
|
|
package/dist/index.js
CHANGED
|
@@ -316,13 +316,12 @@ export const RateLimitFallback = async ({ client, directory }) => {
|
|
|
316
316
|
parts: parts,
|
|
317
317
|
model: { providerID: nextModel.providerID, modelID: nextModel.modelID },
|
|
318
318
|
};
|
|
319
|
-
// abort → promptAsync: abort the old request first, then send fallback prompt
|
|
320
|
-
// This prevents the abort from killing the new fallback prompt.
|
|
321
|
-
//
|
|
322
|
-
// For session.error events, the request is already in error state, so we
|
|
323
|
-
// only send promptAsync (skipAbort = true). For retry status, we send both.
|
|
324
|
-
//
|
|
325
319
|
// promptAsync: HTTP POST /session/{id}/prompt_async → 204 (SDK sdk.gen.js).
|
|
320
|
+
//
|
|
321
|
+
// For session.error and retry status events, we skip abort (skipAbort = true)
|
|
322
|
+
// because the request is already in an error or delayed state. Calling abort
|
|
323
|
+
// in these cases can trigger interrupted events that cancel the new fallback
|
|
324
|
+
// prompt.
|
|
326
325
|
const t0 = Date.now();
|
|
327
326
|
if (!skipAbort) {
|
|
328
327
|
try {
|
|
@@ -458,8 +457,10 @@ export const RateLimitFallback = async ({ client, directory }) => {
|
|
|
458
457
|
catch {
|
|
459
458
|
console.log("[rate-limit-fallback] session.status:", status);
|
|
460
459
|
}
|
|
461
|
-
// Note: interrupted status is
|
|
462
|
-
//
|
|
460
|
+
// Note: interrupted status is ignored here. Since we no longer call abort
|
|
461
|
+
// for retry status events, interrupted events should not be triggered by
|
|
462
|
+
// our fallback logic. If they occur (e.g., from user action), we let them
|
|
463
|
+
// be handled by the system.
|
|
463
464
|
if (status?.type === "retry" && status?.message) {
|
|
464
465
|
const message = status.message.toLowerCase();
|
|
465
466
|
const isRateLimitRetry = message.includes("usage limit") ||
|
|
@@ -494,7 +495,9 @@ export const RateLimitFallback = async ({ client, directory }) => {
|
|
|
494
495
|
catch {
|
|
495
496
|
console.log("[rate-limit-fallback] Attempting fallback for rate limit retry");
|
|
496
497
|
}
|
|
497
|
-
|
|
498
|
+
// skipAbort = true for retry status to avoid triggering interrupted events
|
|
499
|
+
// that could cancel the new fallback prompt
|
|
500
|
+
await handleRateLimitFallback(props.sessionID, "", "", true);
|
|
498
501
|
}
|
|
499
502
|
}
|
|
500
503
|
}
|
package/package.json
CHANGED