feat(ai-review 對話收斂): 讀 PR review 留言判斷解決狀態並收斂 findings #42
+8
-2
@@ -83,6 +83,13 @@ export function resetRunUsage() {
|
||||
/** 最近一次回應的速率配額(rate limit)快照,用來計算「當前視窗剩餘百分比」。 */
|
||||
const rateLimit = { hasData: false, remaining: null, limit: null, kind: null };
|
||||
|
||||
/** 將物件的 key 全部轉小寫,方便對大小寫不敏感的 HTTP header 取值。 */
|
||||
function lowerCaseKeys(obj) {
|
||||
const out = {};
|
||||
for (const k of Object.keys(obj)) out[k.toLowerCase()] = obj[k];
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* 從回應 header 擷取速率配額剩餘量/上限。
|
||||
* 支援 OpenAI 相容(x-ratelimit-*-tokens)與 Anthropic(anthropic-ratelimit-tokens-*),
|
||||
@@ -90,8 +97,7 @@ const rateLimit = { hasData: false, remaining: null, limit: null, kind: null };
|
||||
*/
|
||||
export function recordRateLimit(headers) {
|
||||
if (!headers || typeof headers !== 'object') return;
|
||||
const h = {};
|
||||
for (const k of Object.keys(headers)) h[k.toLowerCase()] = headers[k];
|
||||
const h = lowerCaseKeys(headers);
|
||||
|
||||
let remaining = h['x-ratelimit-remaining-tokens'] ?? h['anthropic-ratelimit-tokens-remaining'];
|
||||
let limit = h['x-ratelimit-limit-tokens'] ?? h['anthropic-ratelimit-tokens-limit'];
|
||||
|
||||
Reference in New Issue
Block a user