Spaces:
Paused
Paused
anurag008w commited on
Commit ·
a29d948
1
Parent(s): 58a85c0
fix: rotator quota safety diagnostics
Browse files- health-server.js +38 -0
- key-rotator-manager.html +4 -3
- multi-provider-key-rotator.cjs +14 -3
health-server.js
CHANGED
|
@@ -595,6 +595,43 @@ function maskApiKey(value) {
|
|
| 595 |
return key.length > 12 ? `${key.slice(0, 4)}...${key.slice(-6)}` : "***";
|
| 596 |
}
|
| 597 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 598 |
function providerKeySummary() {
|
| 599 |
const providers = [
|
| 600 |
{ name: "gemini", env: ["GEMINI_API_KEYS", "GEMINI_API_KEY"], aliases: ["GOOGLE_API_KEYS", "GOOGLE_API_KEY", "GOOGLE_GENERATIVE_AI_API_KEYS", "GOOGLE_GENERATIVE_AI_API_KEY", "GOOGLE_AI_API_KEYS", "GOOGLE_AI_API_KEY"] },
|
|
@@ -918,6 +955,7 @@ const server = http.createServer(async (req, res) => {
|
|
| 918 |
return res.end(JSON.stringify({
|
| 919 |
file: KEY_ROTATOR_EVENT_LOG_FILE,
|
| 920 |
log: keyRotatorEventLogStatus(),
|
|
|
|
| 921 |
providers: providerKeySummary(),
|
| 922 |
events: readKeyRotatorEvents(limit),
|
| 923 |
}));
|
|
|
|
| 595 |
return key.length > 12 ? `${key.slice(0, 4)}...${key.slice(-6)}` : "***";
|
| 596 |
}
|
| 597 |
|
| 598 |
+
function modelProviderToRotatorProvider(model) {
|
| 599 |
+
const provider = String(model || "").split("/")[0].toLowerCase();
|
| 600 |
+
const aliases = {
|
| 601 |
+
google: "gemini",
|
| 602 |
+
gemini: "gemini",
|
| 603 |
+
"google-vertex": "gemini",
|
| 604 |
+
moonshot: "kimi-moonshot",
|
| 605 |
+
"kimi-coding": "kimi-moonshot",
|
| 606 |
+
qwen: "modelstudio",
|
| 607 |
+
mistralai: "mistral",
|
| 608 |
+
"x-ai": "xai",
|
| 609 |
+
"z-ai": "zai",
|
| 610 |
+
"z.ai": "zai",
|
| 611 |
+
zhipu: "zai",
|
| 612 |
+
"volcengine-plan": "volcengine",
|
| 613 |
+
"byteplus-plan": "byteplus",
|
| 614 |
+
"opencode-go": "opencode",
|
| 615 |
+
};
|
| 616 |
+
return aliases[provider] || provider;
|
| 617 |
+
}
|
| 618 |
+
|
| 619 |
+
function keyRotatorRuntimeSummary() {
|
| 620 |
+
const primary = LLM_MODEL || "";
|
| 621 |
+
const fallbackModels = String(process.env.LLM_FALLBACK_MODELS || "")
|
| 622 |
+
.split(/[\n\r,]+/)
|
| 623 |
+
.map((s) => s.trim())
|
| 624 |
+
.filter(Boolean);
|
| 625 |
+
const routes = [primary, ...fallbackModels]
|
| 626 |
+
.filter(Boolean)
|
| 627 |
+
.map((model, idx) => ({
|
| 628 |
+
role: idx === 0 ? "primary" : "fallback",
|
| 629 |
+
model,
|
| 630 |
+
provider: modelProviderToRotatorProvider(model),
|
| 631 |
+
}));
|
| 632 |
+
return { primary, routes };
|
| 633 |
+
}
|
| 634 |
+
|
| 635 |
function providerKeySummary() {
|
| 636 |
const providers = [
|
| 637 |
{ name: "gemini", env: ["GEMINI_API_KEYS", "GEMINI_API_KEY"], aliases: ["GOOGLE_API_KEYS", "GOOGLE_API_KEY", "GOOGLE_GENERATIVE_AI_API_KEYS", "GOOGLE_GENERATIVE_AI_API_KEY", "GOOGLE_AI_API_KEYS", "GOOGLE_AI_API_KEY"] },
|
|
|
|
| 955 |
return res.end(JSON.stringify({
|
| 956 |
file: KEY_ROTATOR_EVENT_LOG_FILE,
|
| 957 |
log: keyRotatorEventLogStatus(),
|
| 958 |
+
runtime: keyRotatorRuntimeSummary(),
|
| 959 |
providers: providerKeySummary(),
|
| 960 |
events: readKeyRotatorEvents(limit),
|
| 961 |
}));
|
key-rotator-manager.html
CHANGED
|
@@ -53,7 +53,7 @@
|
|
| 53 |
</section>
|
| 54 |
</main>
|
| 55 |
<script>
|
| 56 |
-
let state={events:[],providers:[],paused:false,selected:localStorage.getItem('hc.keyRotator.provider')||''};
|
| 57 |
const $=id=>document.getElementById(id), HTML_ESCAPE={'&':'&','<':'<','>':'>','"':'"',"'":'''};
|
| 58 |
const PICK_TYPES=['pick','pick_retry_fresh','all_suspended_pick','saturated_reuse'];
|
| 59 |
function esc(v){return String(v??'').replace(/[&<>"']/g,ch=>HTML_ESCAPE[ch]);}
|
|
@@ -66,9 +66,10 @@ function emptyStat(provider,slot,total,key){return{provider,slot,total,key,picks
|
|
| 66 |
function buildStats(){const stats=new Map();for(const p of state.providers){for(const k of (p.keys||[]))stats.set(keyId(p.name,k.slot,k.key),emptyStat(p.name,k.slot,k.total,k.key));}for(const e of state.events){if(!isKeyEvent(e))continue;const id=keyId(e.provider,e.slot,e.key);if(!stats.has(id))stats.set(id,emptyStat(e.provider,e.slot,e.total,e.key||'***'));const s=stats.get(id);if(PICK_TYPES.includes(e.type))s.picks++;if(e.type==='success')s.success++;if(e.type==='rate_limited')s.rate++;if(e.type==='network_retryable')s.retry++;if(e.type==='auth_failed')s.auth++;if(e.type==='transient_status')s.transient++;s.last=e.ts||s.last;if(e.model){const m=s.models.get(e.model)||{picks:0,success:0,rate:0,retry:0,auth:0,transient:0};if(PICK_TYPES.includes(e.type))m.picks++;if(e.type==='success')m.success++;if(e.type==='rate_limited')m.rate++;if(e.type==='network_retryable')m.retry++;if(e.type==='auth_failed')m.auth++;if(e.type==='transient_status')m.transient++;s.models.set(e.model,m);}}return stats;}
|
| 67 |
function providerRows(provider,stats){return (provider?.keys||[]).map(k=>stats.get(keyId(provider.name,k.slot,k.key))||emptyStat(provider.name,k.slot,k.total,k.key));}
|
| 68 |
function modelChips(row){const entries=[...row.models.entries()];if(!entries.length){const total=row.picks+row.success+row.rate+row.retry+row.transient+row.auth;return total?`<span class="model-chip">unscoped · p:${row.picks} ok:${row.success} rl:${row.rate} retry:${row.retry+row.transient}</span>`:'<span class="model-chip">no model events yet</span>';}return entries.map(([m,v])=>`<span class="model-chip">${esc(m)} · p:${v.picks} ok:${v.success} rl:${v.rate} retry:${v.retry+v.transient}</span>`).join('');}
|
| 69 |
-
function
|
|
|
|
| 70 |
function render(){const q=$('q').value.trim().toLowerCase(),type=$('type').value,providers=state.providers||[],events=state.events||[],stats=buildStats();if(!providers.some(p=>p.name===state.selected)&&providers[0])state.selected=providers[0].name;const totalKeys=providers.reduce((a,p)=>a+(Number(p.total)||0),0),usedKeyCount=[...stats.values()].filter(s=>s.picks||s.success).length;$('mKeys').textContent=totalKeys;$('mUsed').textContent=usedKeyCount;$('mUnused').textContent=Math.max(0,totalKeys-usedKeyCount);$('mRate').textContent=events.filter(e=>e.type==='rate_limited').length;$('mUpdate').textContent=new Date().toLocaleTimeString();$('providerCount').textContent=`${providers.length} active`;$('eventCount').textContent=`${events.length} events`;$('providers').innerHTML=providers.length?providers.map(p=>{const rows=providerRows(p,stats),used=rows.filter(r=>r.picks||r.success).length,total=Number(p.total)||0,aliases=p.aliases?' · '+esc(p.aliases):'';return `<button class="provider ${p.name===state.selected?'active':''}" data-provider="${esc(p.name)}" type="button"><div class="provider-top"><div class="provider-name">${esc(p.name)}</div><span class="pill">${used}/${total} used</span></div><div class="provider-meta">${esc(p.env||'configured pool')}${aliases}</div><div class="bar"><span style="width:${total?Math.round((used/total)*100):0}%"></span></div></button>`;}).join(''):'<div class="empty">No key pools detected in this process env.</div>';$('providers').querySelectorAll('[data-provider]').forEach(el=>el.onclick=()=>{state.selected=el.dataset.provider;localStorage.setItem('hc.keyRotator.provider',state.selected);render();});renderProviderDetails(providers.find(p=>p.name===state.selected)||providers[0],stats);let filtered=events.slice().reverse().filter(e=>(!type||e.type===type));if($('scope').checked&&state.selected)filtered=filtered.filter(e=>!e.provider||e.provider==='system'||e.provider===state.selected);if(q)filtered=filtered.filter(e=>JSON.stringify(e).toLowerCase().includes(q));$('events').innerHTML=filtered.length?filtered.map(e=>`<article class="event ${eventClass(e.type)}"><div class="time">${esc(fmtTime(e.ts))}</div><div><div class="etype">${esc(e.type||'event')}</div><div class="msg">${esc(eventText(e)||'system event')}</div></div><div class="key">${esc(e.key||'')}</div></article>`).join(''):'<div class="empty">No matching events yet. Send a message or disable provider scope to view other providers.</div>';}
|
| 71 |
-
async function load(){if(state.paused)return;try{const r=await fetch('/api/key-rotator/logs?limit=1000',{cache:'no-store'});if(r.status===401){location.href='/login?next='+encodeURIComponent('/key-rotator');return;}const d=await r.json();state.events=d.events||[];state.providers=d.providers||[];state.lastPayload=d;const log=d.log||{};$('source').textContent=log.exists?`${d.file||'event log'} · ${Math.round((log.size||0)/1024)} KiB`:`${d.file||'event log'} · waiting`;render();}catch(e){$('events').innerHTML='<div class="empty bad">Could not load rotator logs: '+esc(e.message)+'</div>';}}
|
| 72 |
$('q').addEventListener('input',render);$('type').addEventListener('change',render);$('scope').addEventListener('change',render);$('refresh').onclick=load;$('pause').onclick=()=>{state.paused=!state.paused;$('pause').textContent=state.paused?'Resume':'Pause';$('liveDot').classList.toggle('live',!state.paused);$('liveText').textContent=state.paused?'Paused':'Live';};$('export').onclick=()=>{const data=JSON.stringify(state.lastPayload||{providers:state.providers,events:state.events},null,2),blob=new Blob([data],{type:'application/json'}),url=URL.createObjectURL(blob),a=document.createElement('a');a.href=url;a.download='huggingclaw-key-rotator.json';a.click();URL.revokeObjectURL(url);};load();setInterval(load,2500);
|
| 73 |
</script>
|
| 74 |
</body>
|
|
|
|
| 53 |
</section>
|
| 54 |
</main>
|
| 55 |
<script>
|
| 56 |
+
let state={events:[],providers:[],runtime:{routes:[]},paused:false,selected:localStorage.getItem('hc.keyRotator.provider')||''};
|
| 57 |
const $=id=>document.getElementById(id), HTML_ESCAPE={'&':'&','<':'<','>':'>','"':'"',"'":'''};
|
| 58 |
const PICK_TYPES=['pick','pick_retry_fresh','all_suspended_pick','saturated_reuse'];
|
| 59 |
function esc(v){return String(v??'').replace(/[&<>"']/g,ch=>HTML_ESCAPE[ch]);}
|
|
|
|
| 66 |
function buildStats(){const stats=new Map();for(const p of state.providers){for(const k of (p.keys||[]))stats.set(keyId(p.name,k.slot,k.key),emptyStat(p.name,k.slot,k.total,k.key));}for(const e of state.events){if(!isKeyEvent(e))continue;const id=keyId(e.provider,e.slot,e.key);if(!stats.has(id))stats.set(id,emptyStat(e.provider,e.slot,e.total,e.key||'***'));const s=stats.get(id);if(PICK_TYPES.includes(e.type))s.picks++;if(e.type==='success')s.success++;if(e.type==='rate_limited')s.rate++;if(e.type==='network_retryable')s.retry++;if(e.type==='auth_failed')s.auth++;if(e.type==='transient_status')s.transient++;s.last=e.ts||s.last;if(e.model){const m=s.models.get(e.model)||{picks:0,success:0,rate:0,retry:0,auth:0,transient:0};if(PICK_TYPES.includes(e.type))m.picks++;if(e.type==='success')m.success++;if(e.type==='rate_limited')m.rate++;if(e.type==='network_retryable')m.retry++;if(e.type==='auth_failed')m.auth++;if(e.type==='transient_status')m.transient++;s.models.set(e.model,m);}}return stats;}
|
| 67 |
function providerRows(provider,stats){return (provider?.keys||[]).map(k=>stats.get(keyId(provider.name,k.slot,k.key))||emptyStat(provider.name,k.slot,k.total,k.key));}
|
| 68 |
function modelChips(row){const entries=[...row.models.entries()];if(!entries.length){const total=row.picks+row.success+row.rate+row.retry+row.transient+row.auth;return total?`<span class="model-chip">unscoped · p:${row.picks} ok:${row.success} rl:${row.rate} retry:${row.retry+row.transient}</span>`:'<span class="model-chip">no model events yet</span>';}return entries.map(([m,v])=>`<span class="model-chip">${esc(m)} · p:${v.picks} ok:${v.success} rl:${v.rate} retry:${v.retry+v.transient}</span>`).join('');}
|
| 69 |
+
function routeNote(provider){const routes=(state.runtime&&state.runtime.routes)||[],hits=routes.filter(r=>r.provider===provider.name);if(!routes.length)return '<div class="session-note">Current LLM route is unknown to this view. Usage appears only after OpenClaw sends a request to this provider hostname.</div>';if(hits.length)return `<div class="session-note"><b>Active route:</b> ${hits.map(r=>`${esc(r.role)} ${esc(r.model)}`).join(' · ')}. New messages using this route should create pick/success events below.</div>`;return `<div class="session-note bad"><b>Not on current model route.</b> Current route is ${routes.map(r=>`${esc(r.role)} ${esc(r.model)} → ${esc(r.provider)}`).join(' · ')}. ${esc(provider.name)} keys stay unused until you select a ${esc(provider.name)} model or a fallback reaches it.</div>`;}
|
| 70 |
+
function renderProviderDetails(provider,stats){if(!provider){$('detailTitle').textContent='Provider details';$('details').innerHTML='<div class="empty">Select a provider to see key/session usage.</div>';return;}const rows=providerRows(provider,stats),used=rows.filter(r=>r.picks||r.success).length,rates=rows.reduce((a,r)=>a+r.rate,0),retries=rows.reduce((a,r)=>a+r.retry+r.transient,0),auths=rows.reduce((a,r)=>a+r.auth,0);$('detailTitle').textContent=`${provider.name} · provider session`;const modelSet=new Set();rows.forEach(r=>r.models.forEach((_,m)=>modelSet.add(m)));const table=rows.map(r=>{const usedKey=(r.picks||r.success)>0;return `<tr><td><b class="mono">#${r.slot}/${r.total}</b><div class="key">${esc(r.key)}</div></td><td><span class="status ${usedKey?'used':'unused'}">${usedKey?'USED':'UNUSED'}</span><div class="metric-detail">last: ${esc(r.last?fmtTime(r.last):'never')}</div></td><td>pick ${r.picks}<br>success ${r.success}<br>rate ${r.rate}</td><td>retry ${r.retry}<br>transient ${r.transient}<br>auth ${r.auth}</td><td>${modelChips(r)}</td></tr>`;}).join('');$('details').innerHTML=`${routeNote(provider)}<div class="session-note">Session: <b>${esc(provider.name)}</b>. Raw keys are never returned here; this page only shows masked keys and slot numbers from the configured pool.</div><div class="detail-grid"><div class="mini"><span class="metric-title">Total keys</span><b>${provider.total||0}</b></div><div class="mini"><span class="metric-title">Used / unused</span><b>${used}/${Math.max(0,(provider.total||0)-used)}</b></div><div class="mini"><span class="metric-title">Rate limits</span><b>${rates}</b></div><div class="mini"><span class="metric-title">Retry/auth</span><b>${retries}/${auths}</b></div></div>${provider.name==='gemini'?`<p class="foot">Gemini quota is tracked per key + model. Models seen: ${modelSet.size?[...modelSet].map(m=>`<span class="model-chip">${esc(m)}</span>`).join(''):'<span class="kbd">none yet — new requests will show per-model once the rotator can read the request body</span>'}</p>`:''}<div class="key-table-wrap"><table class="key-table"><thead><tr><th>Hidden key slot</th><th>Status</th><th>Usage</th><th>Failures</th><th>Per-model / details</th></tr></thead><tbody>${table||'<tr><td colspan="5">No keys configured</td></tr>'}</tbody></table></div>`;}
|
| 71 |
function render(){const q=$('q').value.trim().toLowerCase(),type=$('type').value,providers=state.providers||[],events=state.events||[],stats=buildStats();if(!providers.some(p=>p.name===state.selected)&&providers[0])state.selected=providers[0].name;const totalKeys=providers.reduce((a,p)=>a+(Number(p.total)||0),0),usedKeyCount=[...stats.values()].filter(s=>s.picks||s.success).length;$('mKeys').textContent=totalKeys;$('mUsed').textContent=usedKeyCount;$('mUnused').textContent=Math.max(0,totalKeys-usedKeyCount);$('mRate').textContent=events.filter(e=>e.type==='rate_limited').length;$('mUpdate').textContent=new Date().toLocaleTimeString();$('providerCount').textContent=`${providers.length} active`;$('eventCount').textContent=`${events.length} events`;$('providers').innerHTML=providers.length?providers.map(p=>{const rows=providerRows(p,stats),used=rows.filter(r=>r.picks||r.success).length,total=Number(p.total)||0,aliases=p.aliases?' · '+esc(p.aliases):'';return `<button class="provider ${p.name===state.selected?'active':''}" data-provider="${esc(p.name)}" type="button"><div class="provider-top"><div class="provider-name">${esc(p.name)}</div><span class="pill">${used}/${total} used</span></div><div class="provider-meta">${esc(p.env||'configured pool')}${aliases}</div><div class="bar"><span style="width:${total?Math.round((used/total)*100):0}%"></span></div></button>`;}).join(''):'<div class="empty">No key pools detected in this process env.</div>';$('providers').querySelectorAll('[data-provider]').forEach(el=>el.onclick=()=>{state.selected=el.dataset.provider;localStorage.setItem('hc.keyRotator.provider',state.selected);render();});renderProviderDetails(providers.find(p=>p.name===state.selected)||providers[0],stats);let filtered=events.slice().reverse().filter(e=>(!type||e.type===type));if($('scope').checked&&state.selected)filtered=filtered.filter(e=>!e.provider||e.provider==='system'||e.provider===state.selected);if(q)filtered=filtered.filter(e=>JSON.stringify(e).toLowerCase().includes(q));$('events').innerHTML=filtered.length?filtered.map(e=>`<article class="event ${eventClass(e.type)}"><div class="time">${esc(fmtTime(e.ts))}</div><div><div class="etype">${esc(e.type||'event')}</div><div class="msg">${esc(eventText(e)||'system event')}</div></div><div class="key">${esc(e.key||'')}</div></article>`).join(''):'<div class="empty">No matching events yet. Send a message or disable provider scope to view other providers.</div>';}
|
| 72 |
+
async function load(){if(state.paused)return;try{const r=await fetch('/api/key-rotator/logs?limit=1000',{cache:'no-store'});if(r.status===401){location.href='/login?next='+encodeURIComponent('/key-rotator');return;}const d=await r.json();state.events=d.events||[];state.providers=d.providers||[];state.runtime=d.runtime||{routes:[]};state.lastPayload=d;const log=d.log||{};$('source').textContent=log.exists?`${d.file||'event log'} · ${Math.round((log.size||0)/1024)} KiB`:`${d.file||'event log'} · waiting`;render();}catch(e){$('events').innerHTML='<div class="empty bad">Could not load rotator logs: '+esc(e.message)+'</div>';}}
|
| 73 |
$('q').addEventListener('input',render);$('type').addEventListener('change',render);$('scope').addEventListener('change',render);$('refresh').onclick=load;$('pause').onclick=()=>{state.paused=!state.paused;$('pause').textContent=state.paused?'Resume':'Pause';$('liveDot').classList.toggle('live',!state.paused);$('liveText').textContent=state.paused?'Paused':'Live';};$('export').onclick=()=>{const data=JSON.stringify(state.lastPayload||{providers:state.providers,events:state.events},null,2),blob=new Blob([data],{type:'application/json'}),url=URL.createObjectURL(blob),a=document.createElement('a');a.href=url;a.download='huggingclaw-key-rotator.json';a.click();URL.revokeObjectURL(url);};load();setInterval(load,2500);
|
| 74 |
</script>
|
| 75 |
</body>
|
multi-provider-key-rotator.cjs
CHANGED
|
@@ -660,6 +660,14 @@ function matchProvider(hostname) {
|
|
| 660 |
if (!hostname) return null;
|
| 661 |
return providerState.find(p => p.hostname.test(hostname)) || null;
|
| 662 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 663 |
|
| 664 |
function setAuthHeader(headers, key) {
|
| 665 |
if (!key) return headers;
|
|
@@ -1130,7 +1138,7 @@ function patchUndiciDispatch(proto, tag) {
|
|
| 1130 |
hostname = String(origin || '').replace(/^https?:\/\//, '').split(/[/:?]/)[0];
|
| 1131 |
}
|
| 1132 |
|
| 1133 |
-
|
| 1134 |
if (provider) {
|
| 1135 |
const pathStr = options.path || '/';
|
| 1136 |
let model = provider.perModelLimits
|
|
@@ -1267,7 +1275,9 @@ function patchFetch() {
|
|
| 1267 |
const urlLike = typeof input === 'string' || input instanceof URL
|
| 1268 |
? input
|
| 1269 |
: (input && typeof input.url === 'string' ? input.url : null);
|
| 1270 |
-
const
|
|
|
|
|
|
|
| 1271 |
if (!provider) return await orig(input, init);
|
| 1272 |
|
| 1273 |
// Extract model for per-model-limit providers (gemini etc.)
|
|
@@ -1430,7 +1440,8 @@ function patchHttpModule(mod) {
|
|
| 1430 |
|
| 1431 |
try {
|
| 1432 |
const options = args[0];
|
| 1433 |
-
const
|
|
|
|
| 1434 |
|
| 1435 |
if (provider) {
|
| 1436 |
// Extract model for per-model-limit providers from the request path.
|
|
|
|
| 660 |
if (!hostname) return null;
|
| 661 |
return providerState.find(p => p.hostname.test(hostname)) || null;
|
| 662 |
}
|
| 663 |
+
function resolveProviderFromHeaders(headers) {
|
| 664 |
+
const targetHost = uGetHeader(headers || [], 'x-target-host');
|
| 665 |
+
return targetHost ? matchProvider(targetHost) : null;
|
| 666 |
+
}
|
| 667 |
+
|
| 668 |
+
function resolveProviderForUrl(urlLike, headers) {
|
| 669 |
+
return matchProvider(resolveHostname(urlLike)) || resolveProviderFromHeaders(headers);
|
| 670 |
+
}
|
| 671 |
|
| 672 |
function setAuthHeader(headers, key) {
|
| 673 |
if (!key) return headers;
|
|
|
|
| 1138 |
hostname = String(origin || '').replace(/^https?:\/\//, '').split(/[/:?]/)[0];
|
| 1139 |
}
|
| 1140 |
|
| 1141 |
+
let provider = matchProvider(hostname) || resolveProviderFromHeaders(options.headers || []);
|
| 1142 |
if (provider) {
|
| 1143 |
const pathStr = options.path || '/';
|
| 1144 |
let model = provider.perModelLimits
|
|
|
|
| 1275 |
const urlLike = typeof input === 'string' || input instanceof URL
|
| 1276 |
? input
|
| 1277 |
: (input && typeof input.url === 'string' ? input.url : null);
|
| 1278 |
+
const inputHeaders = typeof Request !== 'undefined' && input instanceof Request ? input.headers : undefined;
|
| 1279 |
+
const initHeaders = init && typeof init === 'object' ? init.headers : undefined;
|
| 1280 |
+
const provider = resolveProviderForUrl(urlLike, initHeaders || inputHeaders);
|
| 1281 |
if (!provider) return await orig(input, init);
|
| 1282 |
|
| 1283 |
// Extract model for per-model-limit providers (gemini etc.)
|
|
|
|
| 1440 |
|
| 1441 |
try {
|
| 1442 |
const options = args[0];
|
| 1443 |
+
const optionHeaders = options && typeof options === 'object' ? options.headers : undefined;
|
| 1444 |
+
const provider = resolveProviderForUrl(options, optionHeaders);
|
| 1445 |
|
| 1446 |
if (provider) {
|
| 1447 |
// Extract model for per-model-limit providers from the request path.
|