llm-simple-router 0.9.21 → 0.9.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.
@@ -2,6 +2,7 @@ import { ProviderSwitchNeeded } from "../types.js";
2
2
  import { ResilienceLayer as ResilienceLayerClass } from "./resilience.js";
3
3
  import { SemaphoreScope as SemaphoreScopeClass } from "./scope.js";
4
4
  import { TrackerScope as TrackerScopeClass } from "./scope.js";
5
+ import { SemaphoreTimeoutError, SemaphoreQueueFullError } from "@llm-router/core";
5
6
  const DEFAULT_BASE_DELAY_MS = 1000;
6
7
  const DEFAULT_FAILOVER_THRESHOLD = 400;
7
8
  /**
@@ -40,7 +41,10 @@ export class ProxyOrchestrator {
40
41
  providerId: a.target.provider_id,
41
42
  })));
42
43
  const { status, statusCode } = this.extractTrackStatus(result);
43
- this.deps.adaptiveController?.onRequestComplete(providerId, { success: status === "completed", statusCode });
44
+ // 如果有重试尝试(非 throw 类型),说明 resilience 层的重试规则匹配了,
45
+ // 意味着这是一个"有意义的失败"——即使上游返回 200 body error 也应该计入退避
46
+ const retryRuleMatched = status === "failed" && result.attempts.length > 1;
47
+ this.deps.adaptiveController?.onRequestComplete(providerId, { success: status === "completed", statusCode, retryRuleMatched, requestId: config.trackerId });
44
48
  this.sendResponse(reply, result.result, ctx);
45
49
  return result;
46
50
  }
@@ -48,7 +52,11 @@ export class ProxyOrchestrator {
48
52
  if (e instanceof ProviderSwitchNeeded) {
49
53
  const lastResult = e.lastResult;
50
54
  const statusCode = lastResult && "statusCode" in lastResult ? lastResult.statusCode : undefined;
51
- this.deps.adaptiveController?.onRequestComplete(providerId, { success: false, statusCode });
55
+ this.deps.adaptiveController?.onRequestComplete(providerId, { success: false, statusCode, retryRuleMatched: true, requestId: config.trackerId });
56
+ }
57
+ else if (e instanceof SemaphoreTimeoutError || e instanceof SemaphoreQueueFullError) {
58
+ // 信号量超时或队列满:说明并发压力大,上报给自适应控制器
59
+ this.deps.adaptiveController?.onRequestComplete(providerId, { success: false, requestId: config.trackerId });
52
60
  }
53
61
  throw e;
54
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "llm-simple-router",
3
- "version": "0.9.21",
3
+ "version": "0.9.22",
4
4
  "description": "LLM API proxy router with OpenAI/Anthropic support, model mapping, retry strategies, and admin dashboard",
5
5
  "license": "MIT",
6
6
  "author": "ZZzzswszzZZ",