@azumag/opencode-rate-limit-fallback 1.0.20 → 1.0.21
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 +11 -26
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -316,7 +316,7 @@ export const RateLimitFallback = async ({ client, directory }) => {
|
|
|
316
316
|
parts: parts,
|
|
317
317
|
model: { providerID: nextModel.providerID, modelID: nextModel.modelID },
|
|
318
318
|
};
|
|
319
|
-
//
|
|
319
|
+
// abort → promptAsync: abort the old request first, then send fallback prompt
|
|
320
320
|
// This prevents the abort from killing the new fallback prompt.
|
|
321
321
|
//
|
|
322
322
|
// For session.error events, the request is already in error state, so we
|
|
@@ -324,21 +324,21 @@ export const RateLimitFallback = async ({ client, directory }) => {
|
|
|
324
324
|
//
|
|
325
325
|
// promptAsync: HTTP POST /session/{id}/prompt_async → 204 (SDK sdk.gen.js).
|
|
326
326
|
const t0 = Date.now();
|
|
327
|
-
await client.session.promptAsync({
|
|
328
|
-
path: { id: sessionID },
|
|
329
|
-
body: promptBody,
|
|
330
|
-
});
|
|
331
|
-
const t1 = Date.now();
|
|
332
327
|
if (!skipAbort) {
|
|
333
328
|
try {
|
|
334
329
|
await client.session.abort({ path: { id: sessionID } });
|
|
335
|
-
logToFile(`abort succeeded for session ${sessionID} (${Date.now() -
|
|
330
|
+
logToFile(`abort succeeded for session ${sessionID} (${Date.now() - t0}ms)`);
|
|
336
331
|
}
|
|
337
332
|
catch (abortErr) {
|
|
338
|
-
logToFile(`abort failed (${Date.now() -
|
|
333
|
+
logToFile(`abort failed (${Date.now() - t0}ms): ${abortErr}`);
|
|
339
334
|
}
|
|
340
335
|
}
|
|
341
|
-
|
|
336
|
+
const t1 = Date.now();
|
|
337
|
+
await client.session.promptAsync({
|
|
338
|
+
path: { id: sessionID },
|
|
339
|
+
body: promptBody,
|
|
340
|
+
});
|
|
341
|
+
logToFile(`promptAsync completed for session ${sessionID} (${Date.now() - t1}ms, total ${Date.now() - t0}ms) with model ${nextModel.providerID}/${nextModel.modelID}`);
|
|
342
342
|
// Toast is best-effort notification. The toast() function (line ~185) has
|
|
343
343
|
// built-in fallback: showToast failure → app.log. After promptAsync the
|
|
344
344
|
// server may already be disposing, so both showToast and app.log could fail.
|
|
@@ -458,23 +458,8 @@ export const RateLimitFallback = async ({ client, directory }) => {
|
|
|
458
458
|
catch {
|
|
459
459
|
console.log("[rate-limit-fallback] session.status:", status);
|
|
460
460
|
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
logToFile("Session interrupted, attempting to resend prompt");
|
|
464
|
-
try {
|
|
465
|
-
await client.app.log({
|
|
466
|
-
body: {
|
|
467
|
-
service: "rate-limit-fallback",
|
|
468
|
-
level: "info",
|
|
469
|
-
message: "Session interrupted, attempting to resend prompt",
|
|
470
|
-
},
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
catch {
|
|
474
|
-
console.log("[rate-limit-fallback] Session interrupted, attempting to resend prompt");
|
|
475
|
-
}
|
|
476
|
-
await handleRateLimitFallback(props.sessionID, "", "", true); // skipAbort = true
|
|
477
|
-
}
|
|
461
|
+
// Note: interrupted status is handled by the fallback sequence (abort → promptAsync).
|
|
462
|
+
// We don't need to handle it separately here as it would cause duplicate prompt sends.
|
|
478
463
|
if (status?.type === "retry" && status?.message) {
|
|
479
464
|
const message = status.message.toLowerCase();
|
|
480
465
|
const isRateLimitRetry = message.includes("usage limit") ||
|
package/package.json
CHANGED