@jetcrab/pi-desk-quota-viewer 1.0.1-dev.9001 → 1.0.1-dev.9002

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.
@@ -0,0 +1,166 @@
1
+ import{a as Ee,b as Ke,c as ne,d as Fe,e as z}from"./chunk-UK7X7FVF.js";import{createRoot as Ra}from"react-dom/client";import{PluginErrorBoundary as Ca}from"@jetcrab/pi-desk-sdk/react/base";import{Fragment as la,useEffect as ua,useMemo as Te,useRef as ca,useState as gt}from"react";import{PluginAlert as ft,PluginButton as ge,PluginEmptyState as da,PluginScroll as ma,PluginSurface as pa}from"@jetcrab/pi-desk-sdk/react/base";import{useMemo as $t,useState as It}from"react";function K(e){let t=e.locale?.getSnapshot(),r;if(!t?.locale||!t.timeZone)try{r=new Intl.DateTimeFormat().resolvedOptions()}catch{}return{locale:t?.locale??(r?.locale.toLowerCase().startsWith("zh")?"zh-CN":"en"),timeZone:t?.timeZone??r?.timeZone??"UTC"}}var Dt={\u5168\u90E8\u6E20\u9053:"All channels",\u6E20\u9053:"Channel",\u989D\u5EA6\u6E20\u9053:"Quota channels","\u641C\u7D22\u6E20\u9053\u3001\u6765\u6E90\u6216\u8D26\u53F7":"Search channels, sources or accounts",\u641C\u7D22\u6E20\u9053\u6216\u663E\u793A\u5185\u5BB9:"Search channels or display items",\u663E\u793A\u9879:"Display items",\u989D\u5EA6\u8BB0\u5F55:"Quota records",\u5237\u65B0:"Refresh",\u5237\u65B0\u4E2D:"Refreshing","\u5237\u65B0\u4E2D\u2026":"Refreshing\u2026",\u4FDD\u5B58:"Save","\u4FDD\u5B58\u4E2D\u2026":"Saving\u2026",\u53D6\u6D88:"Cancel",\u5168\u90E8\u663E\u793A:"Show all",\u4EC5\u5468:"Weekly only",\u8BE6\u60C5:"Details",\u6536\u8D77:"Collapse",\u5C55\u5F00:"Expand",\u6765\u6E90\u5F02\u5E38:"Source error",\u5DF2\u8FC7\u671F:"Stale",\u4F59\u989D:"Balance",\u53EF\u7528:"Available",\u5269\u4F59:"Remaining",\u5DF2\u7528:"Used",\u603B\u989D:"Limit",\u989D\u5EA6:"Quota",\u672A\u77E5:"Unknown",\u65E0\u9650:"Unlimited",\u8BF7\u6C42:"requests",\u6B21:"resets",\u5269\u4F59\u91CD\u7F6E\u6B21\u6570:"Remaining resets","5 \u5C0F\u65F6\u989D\u5EA6":"5-hour quota",\u5468\u989D\u5EA6:"Weekly quota",\u6708\u989D\u5EA6:"Monthly quota",\u4E3B\u989D\u5EA6:"Primary quota",\u6B21\u989D\u5EA6:"Secondary quota","\u53EF\u7528 Credits":"Available credits",\u53EF\u7528\u4F59\u989D:"Available balance",\u73B0\u91D1\u4F59\u989D:"Cash balance",\u4EE3\u91D1\u5238\u4F59\u989D:"Voucher balance","\u6708\u5EA6 Credits":"Monthly credits","\u8D2D\u4E70 Credits":"Purchased credits","\u8D60\u9001 Credits":"Free credits","\u5B98\u65B9 API":"Official API",\u5B98\u65B9\u4EA7\u54C1:"Official product","\u5185\u90E8 API":"Internal API",\u672C\u5730\u4F30\u7B97:"Local estimate",\u5E76\u53D1\u989D\u5EA6:"Concurrent quota",\u8D26\u671F\u989D\u5EA6:"Billing-period quota",\u6EDA\u52A8\u7A97\u53E3:"Rolling window",\u56FA\u5B9A\u7A97\u53E3:"Fixed window",\u7A97\u53E3\u672A\u77E5:"Unknown window",\u7EC4\u7EC7:"Organization",\u9879\u76EE:"Project",\u6A21\u578B:"Model",\u529F\u80FD:"Feature",\u533A\u57DF:"Region",\u5BC6\u94A5:"Key","Codex\uFF08\u901A\u8FC7 CPA\uFF09":"Codex (via CPA)","\u667A\u8C31 Coding Plan":"Zhipu Coding Plan",\u91CD\u7F6E\u65F6\u95F4\u683C\u5F0F:"Reset time format",\u5012\u8BA1\u65F6:"Countdown",\u5177\u4F53\u65F6\u95F4:"Date and time",\u663E\u793A\u8BBE\u7F6E:"Display settings",\u989D\u5EA6\u6765\u6E90:"Quota sources",\u91CD\u65B0\u52A0\u8F7D:"Reload","\u52A0\u8F7D\u4E2D\u2026":"Loading\u2026",\u6DFB\u52A0\u6765\u6E90:"Add source",\u641C\u7D22\u6765\u6E90:"Search sources",\u989D\u5EA6\u6765\u6E90\u5BFC\u822A:"Quota source navigation",\u6765\u6E90\u5217\u8868:"Sources","\u6B63\u5728\u8BFB\u53D6\u2026":"Loading\u2026",\u6CA1\u6709\u5339\u914D\u6765\u6E90:"No matching sources",\u672A\u547D\u540D\u6765\u6E90:"Unnamed source",\u5F85\u5B8C\u5584:"Incomplete",\u672A\u4FDD\u5B58:"Unsaved",\u542F\u7528:"Enabled",\u505C\u7528:"Disabled",\u6765\u6E90\u7F16\u8F91:"Source editor",\u8FD4\u56DE\u6765\u6E90:"Back to sources",\u9009\u62E9\u6E20\u9053:"Select a channel",\u5220\u9664\u6765\u6E90:"Delete source","\u6B63\u5728\u8BFB\u53D6\u989D\u5EA6\u6765\u6E90\u2026":"Loading quota sources\u2026",\u5C1A\u672A\u914D\u7F6E\u989D\u5EA6\u6765\u6E90:"No quota sources configured",\u6709\u672A\u4FDD\u5B58\u66F4\u6539:"Unsaved changes",\u653E\u5F03\u66F4\u6539:"Discard changes",\u4FDD\u5B58\u5168\u90E8\u66F4\u6539:"Save all changes","\u653E\u5F03\u672A\u4FDD\u5B58\u7684\u66F4\u6539\uFF1F":"Discard unsaved changes?","\u989D\u5EA6\u8BBE\u7F6E\u6709\u672A\u4FDD\u5B58\u7684\u66F4\u6539\u3002":"Quota settings have unsaved changes.",\u663E\u793A\u540D\u79F0:"Display name",\u542F\u7528\u6765\u6E90:"Enable source","\u5F53\u524D\u6E20\u9053\u4E0D\u53EF\u7528\uFF0C\u53EF\u5220\u9664\u6B64\u6765\u6E90\u3002":"This channel is unavailable. You can delete this source.",\u6E05\u9664\u641C\u7D22:"Clear search",\u6062\u590D\u663E\u793A\u9879:"Restore display items",\u6CA1\u6709\u5339\u914D\u7684\u663E\u793A\u5185\u5BB9:"No matching display items",\u6682\u65E0\u53EF\u9009\u62E9\u7684\u989D\u5EA6:"No quota items available",\u8BB0\u5F55\u5206\u9875:"Record pages",\u4E0A\u4E00\u9875:"Previous",\u4E0B\u4E00\u9875:"Next",\u5C1A\u672A\u53D6\u5F97\u6570\u636E:"No data yet",\u672A\u53D6\u5F97\u989D\u5EA6\u6570\u636E:"Quota data unavailable",\u6682\u65E0\u989D\u5EA6\u6570\u636E:"No quota data","\u6B63\u5728\u67E5\u8BE2\u2026":"Querying\u2026",\u5F53\u524D\u989D\u5EA6\u5DF2\u5168\u90E8\u9690\u85CF:"All quota items are hidden",\u6CA1\u6709\u5339\u914D\u7684\u53EF\u89C1\u8BB0\u5F55:"No matching visible records","\u6B63\u5728\u8BFB\u53D6\u989D\u5EA6\u2026":"Loading quotas\u2026",\u6682\u65F6\u65E0\u6CD5\u8BFB\u53D6\u989D\u5EA6\u6765\u6E90:"Quota sources are temporarily unavailable","\u5C1A\u672A\u542F\u7528\u989D\u5EA6\u6765\u6E90\uFF0C\u8BF7\u5728\u201C\u8BBE\u7F6E \u2192 \u989D\u5EA6\u8BBE\u7F6E\u201D\u4E2D\u6DFB\u52A0\u3002":"Add a quota source in Settings \u2192 Quotas.",\u663E\u793A\u9879\u5DF2\u4FDD\u5B58:"Display items saved",\u989D\u5EA6\u8BBE\u7F6E\u5DF2\u4FDD\u5B58:"Quota settings saved"};function f(e,t,r){return e==="zh-CN"?t:r??Dt[t]??t}var W=10,ze=new Intl.Collator("zh-CN",{numeric:!0,sensitivity:"base"});function j(e){let t=new Map;for(let r of e){let a=t.get(r.adapter);a?a.push(r):t.set(r.adapter,[r])}return[...t.values()]}function Me(e,t){return`${e}:${JSON.stringify([t.kind,t.label,t.scope.feature??""])}`}function be(e){let t=new Map;for(let r of e)for(let a of r.resources){let i=Me(r.adapter,a);t.has(i)||t.set(i,{key:i,adapter:r.adapter,adapterLabel:r.adapterLabel,resource:a})}return[...t.values()]}function Oe(e){let t=e.key.split("/");return t.length===3&&t[0]&&["primary","secondary"].includes(t[2])?t[0]:null}function je(e,t=new Set){return j(e).flatMap(r=>r.flatMap(a=>{let i=new Map;for(let o of a.resources){if(t.has(Me(a.adapter,o)))continue;let s=o.scope.account?.trim()||null,d=a.adapter==="cpa-codex"?`cpa:${Oe(o)??o.key}`:s??"source",n=JSON.stringify([a.sourceId,d]),l=i.get(n);l?l.resources.push(o):i.set(n,{key:n,source:a,account:s,resources:[o]})}return a.resources.length===0?[{key:JSON.stringify([a.sourceId]),source:a,account:null,resources:[]}]:[...i.values()].sort((o,s)=>ze.compare(X(o),X(s))||ze.compare(o.key,s.key))}))}function X(e){return e.account??e.source.name}function He(e){if(e.source.adapter!=="cpa-codex"||!e.resources[0])return null;let t=Oe(e.resources[0]);return t===null?null:decodeURIComponent(t)}function Je(e){return e.resources.find(t=>t.scope.plan)?.scope.plan??null}function pe(e,...t){let r=e.trim().toLocaleLowerCase();return!r||t.some(a=>a?.toLocaleLowerCase().includes(r))}function Ve(e,t,r){return e.filter(a=>(!t||a.source.adapter===t)&&pe(r,a.account,a.source.name,a.source.adapterLabel))}var _e={openrouter:["account-credits","api-key-quota"],moonshot:["available-balance"],siliconflow:["total-balance"],"opencode-go":["five-hour-quota","weekly-quota","monthly-quota"],commandcode:["five-hour-quota","weekly-quota","monthly-credits"]};function Bt(e){let t=e.resources.filter(s=>e.source.adapter!=="cpa-codex"||s.key.split("/")[1]!=="reset-credits"),r=_e[e.source.adapter],a,i;r?(a=r.flatMap(s=>t.filter(d=>d.key===s)),i=r.length):e.source.adapter==="cpa-codex"?(a=t.filter(s=>s.key.split("/")[1]==="codex"),i=2):(a=t.filter(s=>s.kind==="quota"&&s.window.durationSeconds!==null),i=3);let o=new Set(a.map(s=>s.key));return[...a,...t.filter(s=>!o.has(s.key))].slice(0,Math.min(3,i))}function Ue(e){let t=Bt(e),r=_e[e.source.adapter],a;if(r)a=r.map(s=>t.find(d=>d.key===s)??null);else if(e.source.adapter==="cpa-codex")a=["primary","secondary"].map(s=>t.find(d=>{let n=d.key.split("/");return n[1]==="codex"&&n[2]===s})??null);else if(e.source.adapter==="zhipu-coding-plan")a=[t.find(s=>s.kind==="quota"&&s.window.durationSeconds!==null&&s.window.durationSeconds<86400)??null,t.find(Ne)??null,null];else return t;let i=new Set(a.flatMap(s=>s?[s.key]:[])),o=t.filter(s=>!i.has(s.key));return a.map(s=>s??o.shift()??null)}function ie(e,t="zh-CN"){let r=e.scope.feature?.trim(),a=f(t,e.label);return r?`${r} \xB7 ${a}`:a}function Ne(e){if(e.kind!=="quota")return!1;let t=e.window.durationSeconds;return t!==null&&t>=6*86400&&t<=8*86400}function Y(e,t){return e===null?"\u2014":new Intl.DateTimeFormat(t.locale==="en"?"en-US":t.locale,{timeZone:t.timeZone,month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hour12:!1}).format(e)}function Ze(e,t,r){if(e===null)return null;let a=e-t;if(a<=0)return f(r,"\u9884\u8BA1\u5DF2\u91CD\u7F6E","Reset expected");let i=Math.floor(a/6e4);if(i===0)return f(r,"1 \u5206\u949F\u5185\u91CD\u7F6E","Resets in less than 1m");let o=Math.floor(i/60),s=Math.floor(o/24),n=(s>0?[f(r,`${s} \u5929`,`${s}d`),o%24?f(r,`${o%24} \u5C0F\u65F6`,`${o%24}h`):""]:[o?f(r,`${o} \u5C0F\u65F6`,`${o}h`):"",i%60?f(r,`${i%60} \u5206\u949F`,`${i%60}m`):""]).filter(Boolean).join(" ");return f(r,`${n}\u540E\u91CD\u7F6E`,`Resets in ${n}`)}function M(e,t){return new Intl.NumberFormat(t,{maximumFractionDigits:4}).format(e)}function G(e,t,r="zh-CN"){if(e.state==="unknown")return f(r,"\u672A\u77E5");if(e.state==="unlimited")return f(r,"\u65E0\u9650");if(e.state==="not_applicable")return"\u2014";if(t.kind==="currency")try{return new Intl.NumberFormat(r,{style:"currency",currency:t.code,maximumFractionDigits:4}).format(e.value)}catch{return`${M(e.value,r)} ${t.code}`}return t.kind==="percentage"?`${M(e.value,r)}%`:t.kind==="tokens"?`${M(e.value,r)} Tokens`:t.kind==="requests"?`${M(e.value,r)} ${f(r,"\u8BF7\u6C42")}`:`${M(e.value,r)} ${f(r,t.label)}`}function Xe(e,t="zh-CN"){return new Intl.NumberFormat(t,{style:"percent",maximumFractionDigits:2}).format(e)}function We(e){let{remaining:t,used:r,limit:a}=e.values;return t.state==="known"||t.state==="unlimited"?{label:"\u5269\u4F59",value:t}:r.state==="known"||r.state==="unlimited"?{label:"\u5DF2\u7528",value:r}:a.state==="known"||a.state==="unlimited"?{label:"\u603B\u989D",value:a}:{label:"\u989D\u5EA6",value:t}}function Ye(e){let{remaining:t,limit:r}=e.values;return t.state!=="known"||r.state!=="known"||r.value<=0?null:Math.max(0,Math.min(1,t.value/r.value))}function Ge(e){return e===null||e>=.5?"neutral":e>=.2?"warning":"error"}function et(e){return{official_api:"\u5B98\u65B9 API",official_product:"\u5B98\u65B9\u4EA7\u54C1",internal_api:"\u5185\u90E8 API",local_estimate:"\u672C\u5730\u4F30\u7B97"}[e]}function tt(e,t="zh-CN"){let{kind:r,durationSeconds:a}=e.window;if(r==="concurrent")return f(t,"\u5E76\u53D1\u989D\u5EA6");if(r==="billing")return f(t,"\u8D26\u671F\u989D\u5EA6");if(a===null)return f(t,r==="rolling"?"\u6EDA\u52A8\u7A97\u53E3":r==="fixed"?"\u56FA\u5B9A\u7A97\u53E3":"\u7A97\u53E3\u672A\u77E5");let i=a/3600,o=i<24?f(t,`${M(i,t)} \u5C0F\u65F6`,`${M(i,t)} hours`):f(t,`${M(i/24,t)} \u5929`,`${M(i/24,t)} days`);return f(t,`${o}${r==="rolling"?"\u6EDA\u52A8\u7A97\u53E3":"\u7A97\u53E3"}`,`${o} ${r==="rolling"?"rolling window":"window"}`)}function at(e,t="zh-CN"){let r={organization:"\u7EC4\u7EC7",project:"\u9879\u76EE",model:"\u6A21\u578B",feature:"\u529F\u80FD",region:"\u533A\u57DF",key:"\u5BC6\u94A5"};return Object.entries(e.scope).flatMap(([i,o])=>["account","plan"].includes(i)||!o.trim()?[]:[`${f(t,r[i]??i)}\uFF1A${o}`]).join(" \xB7 ")||null}function rt(e,t){let[r,a]=It({adapter:"",query:"",page:1}),i=t.some(n=>n.adapter===r.adapter)?r.adapter:"",o=$t(()=>Ve(e,i,r.query),[i,e,r.query]),s=Math.max(1,Math.ceil(o.length/W)),d=i!==r.adapter?1:Math.min(r.page,s);return(i!==r.adapter||d!==r.page)&&a({...r,adapter:i,page:d}),{adapter:i,query:r.query,page:d,pageCount:s,total:o.length,items:o.slice((d-1)*W,d*W),setAdapter:n=>{a(l=>({...l,adapter:n,page:1}))},setQuery:n=>{a(l=>({...l,query:n,page:1}))},setPage:n=>{a(l=>({...l,page:n}))}}}import{useCallback as Et,useEffect as ot,useRef as Kt,useState as we,useSyncExternalStore as Ft}from"react";function Re(e){return{error:typeof e.error=="string"?e.error:null,adapters:Array.isArray(e.adapters)?JSON.parse(JSON.stringify(e.adapters)):[],sources:Array.isArray(e.sources)?JSON.parse(JSON.stringify(e.sources)):[],display:Ee(e.display)}}async function qe(e,t,r={}){try{return await e.piDesk.invokeGlobal(t,JSON.parse(JSON.stringify(r)))}catch(a){throw console.error("[\u989D\u5EA6\u67E5\u770B\u5668] \u64CD\u4F5C\u5931\u8D25",{method:t,message:a instanceof Error?a.message:String(a)}),a}}var ee={async query(e,t){return Ke(await qe(e,"state-get",{force:t}))},async loadSettings(e){return Re(await qe(e,"settings-get"))},async saveSources(e,t,r){return Re(await qe(e,"settings-save",{sources:t,...r?{display:{resetTimeFormat:r}}:{}}))},async saveVisibility(e,t){return Re(await qe(e,"settings-save",{display:{hiddenItemKeys:t}}))}};function zt(){return Ft(Fe,z,z)}function nt(){let[e,t]=we(()=>Date.now());return ot(()=>{let r=window.setInterval(()=>t(Date.now()),6e4);return()=>window.clearInterval(r)},[]),e}function it(e,t){let r=zt(),[a,i]=we(!0),[o,s]=we(!1),[d,n]=we(null),l=Kt(!1),p=Et(async h=>{if(l.current||t.aborted)return;l.current=!0,s(!0),n(null);let m=z();try{let g=await ee.query(e,h);!t.aborted&&z()===m&&ne(g)}catch(g){t.aborted||n(g instanceof Error?g.message:String(g))}finally{l.current=!1,t.aborted||(i(!1),s(!1))}},[e,t]);return ot(()=>{let h=!0;queueMicrotask(()=>{h&&p(!0)});let m=e.connection.subscribe(()=>{e.connection.getSnapshot().status==="ready"&&p(!1)});return()=>{h=!1,m()}},[e,p]),{snapshot:r,loading:a,requesting:o,error:d,refresh:()=>{p(!0)}}}var Se=`
2
+ .quota-application {
3
+ display: flex;
4
+ flex-direction: column;
5
+ width: min(960px, calc(100dvw - 2rem));
6
+ max-height: min(820px, calc(100dvh - 7rem));
7
+ min-height: 0;
8
+ gap: .75rem;
9
+ padding: 1rem;
10
+ overflow: hidden;
11
+ container: quota-panel / inline-size;
12
+ }
13
+ .quota-actions, .quota-toolbar, .quota-pagination, .quota-settings-head, .quota-editor-head {
14
+ display: flex;
15
+ min-width: 0;
16
+ align-items: center;
17
+ gap: .5rem;
18
+ }
19
+ .quota-actions { flex-wrap: wrap; flex-shrink: 0; }
20
+ .quota-toolbar { flex-wrap: wrap; justify-content: space-between; }
21
+ .quota-search { flex: 1; min-width: min(220px, 100%); }
22
+ .quota-filters { display: grid; min-width: 0; gap: .5rem; flex: none; }
23
+ .quota-channel-tabs { min-width: 0; }
24
+ .quota-tabs { flex-wrap: nowrap; width: max-content; min-width: 100%; }
25
+ .quota-tabs > button { flex: none; white-space: nowrap; }
26
+ .quota-filters .quota-channel-select { display: none; }
27
+ .quota-meta {
28
+ color: var(--pi-desk-plugin-muted-foreground, var(--muted-foreground));
29
+ font-size: .75rem;
30
+ line-height: 1.5;
31
+ }
32
+ .quota-warning { color: var(--status-warning, var(--foreground)); font-size: .75rem; line-height: 1.5; }
33
+ .quota-truncate { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
34
+ .quota-section-title, .quota-channel-heading {
35
+ margin: 0;
36
+ font-size: .875rem;
37
+ line-height: 1.5;
38
+ font-weight: 600;
39
+ overflow-wrap: anywhere;
40
+ }
41
+ .quota-channel-heading {
42
+ padding: .5rem .75rem;
43
+ background: var(--pi-desk-plugin-muted, var(--muted));
44
+ }
45
+ .quota-record + .quota-channel-heading { margin-top: 1rem; }
46
+ .quota-record-scroll { flex: 1 1 auto; min-height: 0; }
47
+ .quota-record-viewport { min-width: 0; }
48
+ .quota-record { min-width: 0; border-bottom: 1px solid var(--border); }
49
+ .quota-record-summary {
50
+ display: grid;
51
+ grid-template-columns: minmax(11rem, 1fr) minmax(0, 2fr) auto;
52
+ gap: .75rem;
53
+ align-items: center;
54
+ min-height: 3.5rem;
55
+ padding: .5rem .75rem;
56
+ }
57
+ .quota-record-identity, .quota-editor-title, .quota-detail-identity {
58
+ display: grid;
59
+ min-width: 0;
60
+ gap: .25rem;
61
+ }
62
+ .quota-record-label { display: flex; min-width: 0; align-items: baseline; gap: .5rem; }
63
+ .quota-plan { flex: none; }
64
+ .quota-record-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
65
+ .quota-record-state { display: flex; flex-wrap: wrap; gap: .5rem; }
66
+ .quota-record-state:empty { display: none; }
67
+ .quota-metrics { display: grid; min-width: 0; gap: .75rem; align-items: start; }
68
+ .quota-metric { display: grid; min-width: 0; gap: .25rem; text-align: right; overflow-wrap: anywhere; }
69
+ .quota-metric-reading { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: baseline; gap: 0 .5rem; }
70
+ .quota-metric-value { margin-left: auto; font-size: .875rem; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.5; }
71
+ .quota-progress { height: 4px; border-radius: 999px; overflow: hidden; background: var(--muted); }
72
+ .quota-progress > span { display: block; height: 100%; border-radius: inherit; background: var(--primary); transition: width 150ms ease-out; }
73
+ .quota-metric[data-quota-tone="warning"] .quota-progress > span { background: var(--status-warning, var(--foreground)); }
74
+ .quota-metric[data-quota-tone="error"] .quota-progress > span { background: var(--destructive); }
75
+ .quota-record-detail { display: grid; gap: .75rem; padding: .75rem; background: var(--muted); }
76
+ .quota-detail-identity, .quota-error-text, .quota-full-name { overflow-wrap: anywhere; }
77
+ .quota-resource-detail { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr); gap: .75rem; border-top: 1px solid var(--border); padding-top: .75rem; }
78
+ .quota-detail-resource-name, .quota-detail-values { display: grid; min-width: 0; gap: .25rem; overflow-wrap: anywhere; }
79
+ .quota-detail-resource-name strong { font-weight: 500; }
80
+ .quota-detail-values { text-align: right; font-variant-numeric: tabular-nums; }
81
+ .quota-pagination { flex: none; justify-content: space-between; flex-wrap: wrap; padding-top: .5rem; border-top: 1px solid var(--border); }
82
+ .quota-empty-actions { justify-content: center; margin-top: .75rem; }
83
+ .quota-source-notices { padding: .5rem .75rem; border-bottom: 1px solid var(--border); }
84
+ .quota-source-notices summary { cursor: pointer; min-height: 1.75rem; line-height: 1.75rem; }
85
+ .quota-source-notices summary:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; }
86
+ .quota-source-errors { display: grid; gap: .75rem; padding: .5rem 0; }
87
+ .quota-error-text { margin-top: .25rem; }
88
+ .quota-visibility { display: grid; min-width: 0; gap: .5rem; container: quota-panel / inline-size; }
89
+ .quota-visibility-filters { display: grid; grid-template-columns: minmax(140px, 1fr) minmax(0, 2fr); align-items: end; gap: .75rem; margin-bottom: .5rem; }
90
+ .quota-visibility-channel + .quota-visibility-channel { border-top: 1px solid var(--border); padding-top: .75rem; }
91
+ .quota-visibility-heading { display: flex; align-items: center; justify-content: space-between; gap: .5rem; min-height: 1.75rem; }
92
+ .quota-selection { display: flex; min-width: 0; min-height: 1.75rem; align-items: center; gap: .5rem; cursor: pointer; }
93
+ .quota-selection > input { flex: none; }
94
+ .quota-visibility-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem .75rem; padding: .5rem 0; }
95
+ .quota-visibility-options .quota-selection { align-items: flex-start; overflow-wrap: anywhere; }
96
+ .quota-settings {
97
+ display: grid;
98
+ grid-template-rows: auto minmax(0, 1fr) auto;
99
+ width: 100%;
100
+ height: 100%;
101
+ max-height: 100%;
102
+ min-height: 0;
103
+ overflow: hidden;
104
+ container-name: quota-settings;
105
+ }
106
+ .quota-settings-head { justify-content: space-between; padding: 1rem; flex-wrap: wrap; }
107
+ .quota-display-settings { display: grid; align-content: start; gap: .75rem; padding: 0 1rem 1rem; }
108
+ .quota-display-settings > * { max-width: 640px; }
109
+ .quota-settings-body { display: grid; grid-template-columns: 224px minmax(0, 1fr); min-height: 0; min-width: 0; overflow: hidden; }
110
+ .quota-settings-navigation { display: flex; flex-direction: column; gap: .75rem; min-height: 0; min-width: 0; padding: 0 .75rem 1rem 1rem; border-right: 1px solid var(--border); }
111
+ .quota-source-navigation-scroll { min-height: 0; flex: 1; }
112
+ .quota-source-navigation-viewport { min-width: 0; }
113
+ .quota-source-group + .quota-source-group { margin-top: .75rem; }
114
+ .quota-source-group-title { margin: 0; padding: .25rem .5rem; color: var(--muted-foreground); font-size: .75rem; font-weight: 500; overflow-wrap: anywhere; }
115
+ .quota-settings .quota-source-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; width: 100%; min-height: 2.25rem; }
116
+ .quota-source-item-state { white-space: nowrap; }
117
+ .quota-editor-scroll { min-height: 0; min-width: 0; }
118
+ .quota-editor-viewport { padding: 0 1rem 1rem; scroll-padding-block: .5rem; container: quota-editor / inline-size; }
119
+ .quota-editor-head { justify-content: space-between; align-items: flex-start; max-width: 640px; margin-bottom: 1rem; }
120
+ .quota-editor-head .quota-section-title { font-size: .875rem; }
121
+ .quota-source-form { display: grid; max-width: 640px; gap: .75rem; grid-template-columns: minmax(0, 1fr); }
122
+ .quota-field-wide { grid-column: 1 / -1; }
123
+ .quota-source-enabled { display: flex; min-height: 2rem; align-items: center; align-self: end; gap: .5rem; cursor: pointer; }
124
+ .quota-add-source { max-width: 640px; }
125
+ .quota-settings-footer {
126
+ display: flex;
127
+ flex-wrap: wrap;
128
+ min-width: 0;
129
+ align-items: center;
130
+ justify-content: space-between;
131
+ gap: .5rem;
132
+ padding: .75rem 1rem;
133
+ border-top: 1px solid var(--border);
134
+ background: var(--popover);
135
+ }
136
+ .quota-settings-footer > .quota-actions { margin-left: auto; }
137
+ .quota-settings .quota-back { display: none; margin-bottom: .75rem; }
138
+ .quota-settings-body[data-empty="true"] { grid-template-columns: minmax(0, 1fr); }
139
+ .quota-settings-body[data-empty="true"] .quota-settings-navigation { display: none; }
140
+ @container quota-panel (max-width: 44rem) {
141
+ .quota-filters .quota-channel-tabs { display: none; }
142
+ .quota-filters .quota-channel-select { display: block; }
143
+ .quota-record-summary { grid-template-columns: minmax(0, 1fr) auto; gap: .5rem; }
144
+ .quota-record-identity { grid-column: 1; grid-row: 1; }
145
+ .quota-detail-toggle { grid-column: 2; grid-row: 1; }
146
+ .quota-metrics { grid-column: 1 / -1; }
147
+ .quota-metric { text-align: left; }
148
+ .quota-metric-reading { justify-content: flex-start; }
149
+ .quota-resource-detail { grid-template-columns: minmax(0, 1fr); }
150
+ .quota-detail-values { text-align: left; }
151
+ .quota-visibility-options, .quota-visibility-filters { grid-template-columns: minmax(0, 1fr); }
152
+ }
153
+ @container quota-settings (max-width: 51.999rem) {
154
+ .quota-settings-body { grid-template-columns: minmax(0, 1fr); }
155
+ .quota-settings-navigation { border-right: 0; padding-right: 1rem; }
156
+ .quota-settings[data-editing="true"] .quota-settings-navigation { display: none; }
157
+ .quota-settings[data-editing="false"] .quota-editor-scroll { display: none; }
158
+ .quota-settings .quota-back { display: inline-flex; }
159
+ }
160
+ @container quota-editor (min-width: 32rem) {
161
+ .quota-source-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
162
+ }
163
+ @media (prefers-reduced-motion: reduce) {
164
+ .quota-progress > span { transition: none; }
165
+ }
166
+ `;import{PluginButton as st,PluginInput as Mt,PluginScroll as Ot,PluginSelect as jt,PluginTab as Ht,PluginTabList as Jt}from"@jetcrab/pi-desk-sdk/react/base";import{Fragment as Vt,jsx as H,jsxs as te}from"react/jsx-runtime";function lt({sources:e,locale:t,adapter:r,query:a,onAdapter:i,onQuery:o,actions:s,disabled:d=!1}){let n=p=>f(t,p),l=[{value:"",label:n("\u5168\u90E8\u6E20\u9053")},...j(e).map(([p])=>({value:p.adapter,label:n(p.adapterLabel)}))];return te("div",{className:"quota-filters",children:[te("div",{className:"quota-toolbar",children:[H(Mt,{className:"quota-search","aria-label":n("\u641C\u7D22\u6E20\u9053\u3001\u6765\u6E90\u6216\u8D26\u53F7"),placeholder:n("\u641C\u7D22\u6E20\u9053\u3001\u6765\u6E90\u6216\u8D26\u53F7"),value:a,disabled:d,onChange:p=>o(p.target.value)}),H("div",{className:"quota-actions",children:s})]}),l.length>2?te(Vt,{children:[H(Ot,{orientation:"horizontal",className:"quota-channel-tabs","aria-label":n("\u989D\u5EA6\u6E20\u9053"),children:H(Jt,{label:n("\u989D\u5EA6\u6E20\u9053"),className:"quota-tabs",children:l.map(p=>H(Ht,{active:r===p.value,disabled:d,onClick:()=>i(p.value),children:p.label},p.value))})}),H(jt,{className:"quota-channel-select",label:n("\u6E20\u9053"),value:r,options:l,disabled:d,onValueChange:p=>i(p??"")})]}):null]})}function ut({locale:e,page:t,pageCount:r,total:a,onPage:i,disabled:o=!1}){if(r<=1)return null;let s=d=>f(e,d);return te("nav",{className:"quota-pagination","aria-label":s("\u8BB0\u5F55\u5206\u9875"),children:[te("span",{className:"quota-meta",children:[(t-1)*W+1,"\u2013",Math.min(t*W,a)," / ",a," ",f(e,"\u6761","records")]}),te("div",{className:"quota-actions",children:[H(st,{size:"sm",variant:"ghost",disabled:o||t<=1,onClick:()=>i(t-1),children:s("\u4E0A\u4E00\u9875")}),te("span",{className:"quota-meta",children:[t," / ",r]}),H(st,{size:"sm",variant:"ghost",disabled:o||t>=r,onClick:()=>i(t+1),children:s("\u4E0B\u4E00\u9875")})]})]})}import{useId as _t}from"react";import{PluginAlert as Ut,PluginButton as Zt}from"@jetcrab/pi-desk-sdk/react/base";import{jsx as P,jsxs as S}from"react/jsx-runtime";function Xt({resource:e,now:t,region:r,resetTimeFormat:a}){let i=e.kind==="balance"?{label:"\u4F59\u989D",value:e.available}:We(e),o=e.kind==="quota"?Ye(e):null,s=ie(e,r.locale),d=e.kind==="quota"?e.window.resetAt:null,n=d===null?null:a==="countdown"?Ze(d,t,r.locale):f(r.locale,`${Y(d,r)} \u91CD\u7F6E`,`Resets ${Y(d,r)}`);return S("div",{className:"quota-metric","data-quota-resource":e.key,"data-quota-tone":Ge(o),children:[S("span",{className:"quota-meta",children:[s,e.kind==="quota"?` \xB7 ${f(r.locale,i.label)}`:""]}),S("div",{className:"quota-metric-reading",children:[n?P("span",{className:"quota-meta",children:n}):null,S("span",{className:"quota-metric-value",children:[G(i.value,e.unit,r.locale),e.unit.kind!=="percentage"&&o!==null?S("span",{className:"quota-meta",children:[" ",Xe(o,r.locale)]}):null]})]}),o!==null?P("div",{className:"quota-progress",role:"progressbar","aria-label":f(r.locale,`${s}\u5269\u4F59\u989D\u5EA6`,`${s} remaining`),"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(o*100),children:P("span",{style:{width:`${o*100}%`}})}):null]})}function Wt({resource:e,region:t}){let r=at(e,t.locale),a=(i,o)=>f(t.locale,i,o);return S("div",{className:"quota-resource-detail","data-quota-detail-resource":e.key,children:[S("div",{className:"quota-detail-resource-name",children:[P("strong",{children:ie(e,t.locale)}),r?P("span",{className:"quota-meta",children:r}):null,e.kind==="quota"?P("span",{className:"quota-meta",children:tt(e,t.locale)}):null]}),e.kind==="balance"?S("div",{className:"quota-detail-values",children:[S("span",{children:[a(e.unit.kind==="currency"?"\u4F59\u989D":"\u53EF\u7528")," ",P("strong",{children:G(e.available,e.unit,t.locale)})]}),e.expiresAt!==null?S("span",{className:"quota-meta",children:[a("\u5230\u671F","Expires")," ",Y(e.expiresAt,t)]}):null]}):S("div",{className:"quota-detail-values",children:[S("span",{children:[a("\u5269\u4F59")," ",P("strong",{children:G(e.values.remaining,e.unit,t.locale)})]}),S("span",{children:[a("\u5DF2\u7528")," ",G(e.values.used,e.unit,t.locale)]}),e.unit.kind!=="percentage"?S("span",{children:[a("\u603B\u989D")," ",G(e.values.limit,e.unit,t.locale)]}):null,e.window.resetAt!==null?S("span",{className:"quota-meta",children:[a("\u91CD\u7F6E","Resets")," ",Y(e.window.resetAt,t)]}):null]})]})}function ct({record:e,now:t,expanded:r,duplicateName:a,region:i,resetTimeFormat:o,onToggle:s}){let d=_t(),{source:n}=e,l=(k,c)=>f(i.locale,k,c),p=X(e),h=n.staleAt!==null&&t>=n.staleAt,m=He(e),g=Ue(e).filter(k=>k!==null),x=Je(e),A=n.adapter==="cpa-codex"?e.resources.find(k=>k.kind==="balance"&&k.key.split("/")[1]==="reset-credits"):void 0,q=[e.account&&n.name!==n.adapterLabel?n.name:null,a?`${n.sourceId.slice(0,8)}${m?` / ${m}`:""}`:null].filter(Boolean).join(" \xB7 ");return S("section",{className:"quota-record","data-quota-record":e.key,children:[S("div",{className:"quota-record-summary",children:[S("div",{className:"quota-record-identity",children:[S("div",{className:"quota-record-label",children:[P("span",{className:"quota-record-name",children:p}),x?P("span",{className:"quota-meta quota-plan",children:x}):null]}),q?P("span",{className:"quota-meta quota-truncate",children:q}):null,S("div",{className:"quota-record-state",children:[A?.kind==="balance"?S("span",{className:"quota-meta",children:[l("\u5269\u4F59\u91CD\u7F6E\u6B21\u6570"),"\uFF1A",G(A.available,A.unit,i.locale)]}):null,n.error?P("span",{className:"quota-warning",children:l("\u6765\u6E90\u5F02\u5E38")}):null,h?P("span",{className:"quota-warning",children:l("\u5DF2\u8FC7\u671F")}):null,n.refreshing?P("span",{className:"quota-meta",children:l("\u5237\u65B0\u4E2D")}):null]})]}),P("div",{className:"quota-metrics",style:{gridTemplateColumns:`repeat(${g.length||1}, minmax(0, 1fr))`},children:e.resources.length>0?g.map(k=>P(Xt,{resource:k,now:t,region:i,resetTimeFormat:o},k.key)):P("span",{className:"quota-meta",children:l(n.refreshing?"\u6B63\u5728\u67E5\u8BE2\u2026":n.error?"\u672A\u53D6\u5F97\u989D\u5EA6\u6570\u636E":"\u6682\u65E0\u989D\u5EA6\u6570\u636E")})}),P(Zt,{size:"sm",variant:"ghost",className:"quota-detail-toggle","aria-label":l(`${r?"\u6536\u8D77":"\u67E5\u770B"}${p}\u8BE6\u60C5`,`${r?"Collapse":"View"} ${p} details`),"aria-expanded":r,"aria-controls":d,onClick:s,children:l(r?"\u6536\u8D77":"\u8BE6\u60C5")})]}),r?S("div",{className:"quota-record-detail",id:d,children:[S("div",{className:"quota-detail-identity",children:[P("strong",{children:p}),S("span",{className:"quota-meta",children:[l("\u6765\u6E90","Source"),"\uFF1A",n.name," \xB7 ",l(et(n.dataSource))]}),m?S("span",{className:"quota-meta",children:[l("CPA \u7D22\u5F15","CPA index"),"\uFF1A",m]}):null,a?S("span",{className:"quota-meta",children:[l("\u6765\u6E90 ID","Source ID"),"\uFF1A",n.sourceId]}):null,P("span",{className:"quota-meta",children:n.observedAt===null?l("\u5C1A\u672A\u53D6\u5F97\u6570\u636E"):l(`\u6570\u636E\u66F4\u65B0\u4E8E ${Y(n.observedAt,i)}`,`Updated ${Y(n.observedAt,i)}`)})]}),n.error?P(Ut,{tone:"warning",density:"compact",children:n.error}):null,e.resources.map(k=>P(Wt,{resource:k,region:i},k.key))]}):null]})}import{useMemo as ea,useState as mt}from"react";import{PluginAlert as ta,PluginButton as ke,PluginCheckbox as aa,PluginDialog as ra,PluginEmptyState as oa,PluginInput as na,PluginSelect as ia}from"@jetcrab/pi-desk-sdk/react/base";import{useMemo as Yt,useRef as Gt,useState as Ae}from"react";function dt(e,t,r,a){let i=K(t).locale,[o,s]=Ae(()=>new Set(e.display.hiddenItemKeys)),[d,n]=Ae(!1),l=Gt(!1),[p,h]=Ae(null),m=Yt(()=>new Set(e.display.hiddenItemKeys),[e.display.hiddenItemKeys]),g=o.size!==m.size||[...o].some(q=>!m.has(q));return{hidden:o,dirty:g,saving:d,error:p,select:(q,k)=>{if(l.current)return;let c=new Set(k),Q=new Set(o);for(let B of q)c.has(B)?Q.delete(B):Q.add(B);if(Q.size>500){h(f(i,`\u6700\u591A\u9690\u85CF ${500} \u9879\uFF0C\u8BF7\u5148\u6062\u590D\u90E8\u5206\u663E\u793A\u9879\u3002`,`You can hide up to ${500} items. Restore some items first.`));return}h(null),s(Q)},save:()=>{l.current||!g||(l.current=!0,n(!0),h(null),ee.saveVisibility(t,[...o]).then(q=>{r.aborted||(ne({...z(),display:q.display}),t.notify({level:"success",title:f(i,"\u663E\u793A\u9879\u5DF2\u4FDD\u5B58")}),a())}).catch(q=>{r.aborted||h(q instanceof Error?q.message:String(q))}).finally(()=>{l.current=!1,r.aborted||n(!1)}))},showAll:()=>{l.current||(s(new Set),h(null))}}}import{Fragment as sa,jsx as D,jsxs as se}from"react/jsx-runtime";function pt({snapshot:e,host:t,signal:r,onClose:a}){let i=dt(e,t,r,a),o=K(t).locale,s=g=>f(o,g),d=ea(()=>be(e.sources),[e.sources]),[n,l]=mt(""),[p,h]=mt(""),m=d.filter(g=>(!n||g.adapter===n)&&pe(p,s(g.adapterLabel),ie(g.resource,o)));return D(ra,{open:!0,title:s("\u663E\u793A\u9879"),size:"lg",onOpenChange:g=>{!g&&!i.saving&&a()},footer:se(sa,{children:[D(ke,{size:"sm",variant:"ghost",disabled:i.saving||i.hidden.size===0,onClick:i.showAll,children:s("\u5168\u90E8\u663E\u793A")}),D(ke,{size:"sm",variant:"secondary",disabled:i.saving,onClick:a,children:s("\u53D6\u6D88")}),D(ke,{size:"sm",variant:"primary","data-quota-visibility-save":"",disabled:i.saving||!i.dirty,onClick:i.save,children:s(i.saving?"\u4FDD\u5B58\u4E2D\u2026":"\u4FDD\u5B58")})]}),children:se("div",{className:"quota-visibility",children:[se("div",{className:"quota-visibility-filters",children:[D(ia,{label:s("\u6E20\u9053"),value:n||"all",disabled:i.saving,options:[{value:"all",label:s("\u5168\u90E8\u6E20\u9053")},...j(d).map(([g])=>({value:g.adapter,label:s(g.adapterLabel)}))],onValueChange:g=>l(g==="all"?"":g??"")}),D(na,{"aria-label":s("\u641C\u7D22\u6E20\u9053\u6216\u663E\u793A\u5185\u5BB9"),placeholder:s("\u641C\u7D22\u6E20\u9053\u6216\u663E\u793A\u5185\u5BB9"),value:p,disabled:i.saving,onChange:g=>h(g.target.value)})]}),i.error?D(ta,{tone:"error",density:"compact",children:i.error}):null,m.length===0?D(oa,{density:"compact",children:s(d.length===0?"\u6682\u65E0\u53EF\u9009\u62E9\u7684\u989D\u5EA6":"\u6CA1\u6709\u5339\u914D\u7684\u663E\u793A\u5185\u5BB9")}):j(m).map(g=>{let x=g[0],A=d.filter(c=>c.adapter===x.adapter),q=A.map(c=>c.key),k=A.filter(c=>Ne(c.resource)).map(c=>c.key);return se("section",{className:"quota-visibility-channel",children:[se("div",{className:"quota-visibility-heading",children:[D("h3",{className:"quota-section-title",children:s(x.adapterLabel)}),k.length>0&&k.length<q.length?D(ke,{size:"sm",variant:"ghost",disabled:i.saving,onClick:()=>i.select(q,k),children:s("\u4EC5\u5468")}):null]}),D("div",{className:"quota-visibility-options",children:g.map(c=>se("label",{className:"quota-selection",children:[D(aa,{checked:!i.hidden.has(c.key),disabled:i.saving,onChange:Q=>i.select([c.key],Q.target.checked?[c.key]:[])}),D("span",{children:ie(c.resource,o)})]},c.key))})]},x.adapter)})]})})}import{Fragment as ga,jsx as C,jsxs as J}from"react/jsx-runtime";function yt({host:e,signal:t}){let{snapshot:r,loading:a,requesting:i,error:o,refresh:s}=it(e,t),d=nt(),n=K(e),l=(y,E)=>f(n.locale,y,E),p=Te(()=>new Set(r.display.hiddenItemKeys),[r.display.hiddenItemKeys]),h=Te(()=>je(r.sources,p),[p,r.sources]),m=rt(h,r.sources),[g,x]=gt(null),[A,q]=gt(!1),k=ca(null),c=r.sources.some(y=>y.refreshing),Q=r.sources.filter(y=>y.error),B=r.sources.reduce((y,E)=>y+E.resources.length,0),$=be(r.sources).filter(y=>p.has(y.key)).length,ce=Te(()=>{let y=new Map;for(let E of h){let me=JSON.stringify([E.source.adapter,X(E)]);y.set(me,(y.get(me)??0)+1)}return y},[h]);ua(()=>{k.current?.scrollTo({top:0})},[m.adapter,m.query,m.page]);let de=g&&h.some(y=>y.key===g)?g:null,T=y=>{x(null),m.setAdapter(y)},ye=y=>{x(null),m.setQuery(y)},U=y=>{x(null),m.setPage(y)},I;return r.sources.length===0&&a?I="\u6B63\u5728\u8BFB\u53D6\u989D\u5EA6\u2026":r.sources.length===0&&(o||r.error)?I="\u6682\u65F6\u65E0\u6CD5\u8BFB\u53D6\u989D\u5EA6\u6765\u6E90":r.sources.length===0?I="\u5C1A\u672A\u542F\u7528\u989D\u5EA6\u6765\u6E90\uFF0C\u8BF7\u5728\u201C\u8BBE\u7F6E \u2192 \u989D\u5EA6\u8BBE\u7F6E\u201D\u4E2D\u6DFB\u52A0\u3002":m.query||m.adapter?I="\u6CA1\u6709\u5339\u914D\u7684\u53EF\u89C1\u8BB0\u5F55":I="\u5F53\u524D\u989D\u5EA6\u5DF2\u5168\u90E8\u9690\u85CF",J(pa,{className:"quota-application","data-quota-application":"",children:[C("style",{children:Se}),C(lt,{sources:r.sources,locale:n.locale,adapter:m.adapter,query:m.query,onAdapter:T,onQuery:ye,actions:J(ga,{children:[C(ge,{size:"sm",variant:"secondary","data-quota-visibility":"",disabled:B===0,onClick:()=>q(!0),children:$>0?l(`\u663E\u793A\u9879 \xB7 ${$} \u9879\u9690\u85CF`,`Display items \xB7 ${$} hidden`):l("\u663E\u793A\u9879")}),C(ge,{size:"sm",variant:"secondary","data-quota-refresh":"",disabled:i||c,onClick:s,children:l(i||c?"\u5237\u65B0\u4E2D\u2026":"\u5237\u65B0")})]})}),J(ma,{className:"quota-record-scroll",viewportClassName:"quota-record-viewport",viewportRef:k,"aria-label":l("\u989D\u5EA6\u8BB0\u5F55"),children:[r.error?C(ft,{tone:"error",density:"compact",children:r.error}):null,o?C(ft,{tone:"error",density:"compact",children:o}):null,Q.length>0?J("details",{className:"quota-source-notices",children:[C("summary",{className:"quota-warning",children:l(`${Q.length} \u4E2A\u6765\u6E90\u5F02\u5E38`,`${Q.length} source errors`)}),C("div",{className:"quota-source-errors",children:Q.map(y=>J("div",{children:[C("strong",{children:y.name}),C("div",{className:"quota-error-text",children:y.error})]},y.sourceId))})]}):null,m.items.length===0?J(da,{density:"compact",children:[l(I),J("div",{className:"quota-actions quota-empty-actions",children:[m.query?C(ge,{size:"sm",variant:"ghost",onClick:()=>ye(""),children:l("\u6E05\u9664\u641C\u7D22")}):null,m.adapter?C(ge,{size:"sm",variant:"ghost",onClick:()=>T(""),children:l("\u5168\u90E8\u6E20\u9053")}):null,$>0?C(ge,{size:"sm",variant:"secondary",onClick:()=>q(!0),children:l("\u6062\u590D\u663E\u793A\u9879")}):null]})]}):m.items.map((y,E)=>J(la,{children:[m.items[E-1]?.source.adapter!==y.source.adapter?C("h2",{className:"quota-channel-heading",children:l(y.source.adapterLabel)}):null,C(ct,{record:y,now:d,region:n,resetTimeFormat:r.display.resetTimeFormat,expanded:de===y.key,duplicateName:(ce.get(JSON.stringify([y.source.adapter,X(y)]))??0)>1,onToggle:()=>x(de===y.key?null:y.key)})]},y.key))]}),C(ut,{locale:n.locale,page:m.page,pageCount:m.pageCount,total:m.total,onPage:U}),A?C(pt,{snapshot:r,host:e,signal:t,onClose:()=>q(!1)}):null]})}import{useMemo as wa,useState as xe}from"react";import{PluginAlert as De,PluginButton as _,PluginConfirmDialog as Sa,PluginEmptyState as kt,PluginInput as ka,PluginListItem as xa,PluginScroll as Be,PluginSelect as xt,PluginSurface as Qa,PluginTab as Qt,PluginTabList as Pa}from"@jetcrab/pi-desk-sdk/react/base";import{useCallback as fe,useEffect as Le,useMemo as vt,useRef as V,useState as F}from"react";function le(e){return JSON.stringify(e.map(({draftKey:t,...r})=>r))}function ue(e,t){return`quota-${e.draftKey}-${t}`.replace(/[^a-zA-Z0-9_-]/g,"-")}function fa(e,t){let r=e.values[t.key]?.trim()??"";if(t.required&&!r)return`${t.label}\u4E0D\u80FD\u4E3A\u7A7A`;if(t.kind==="select"&&r&&!t.options.some(a=>a.value===r))return`${t.label}\u9009\u9879\u65E0\u6548`;if(t.kind==="url"&&r)try{new URL(r)}catch{return`${t.label}\u5FC5\u987B\u662F\u6709\u6548 URL`}return null}function ht(e,t,r){let[a,i]=F({error:null,adapters:[],sources:[],display:{resetTimeFormat:"countdown",hiddenItemKeys:[]}}),o=K(e).locale,[s,d]=F("countdown"),n=V(s),l=V(s),[p,h]=F([]),[m,g]=F([]),x=V(p),A=V(m),[q,k]=F(null),c=V(q),[Q,B]=F(!0),$=V(!1),[ce,de]=F(!1),T=V(!1),[ye,U]=F(null),[I,y]=F(null),[E,me]=F(!1),ae=V(null),Rt=u=>{T.current||(n.current=u,d(u))},Z=fe(u=>{c.current=u,k(u)},[]),re=fe(u=>{x.current=u,h(u)},[]),oe=fe(()=>le(x.current)!==le(A.current)||n.current!==l.current,[]),Qe=fe((u,v)=>{let N=u.sources.map(L=>({...structuredClone(L),draftKey:L.sourceId}));i(u),n.current=u.display.resetTimeFormat,l.current=u.display.resetTimeFormat,d(u.display.resetTimeFormat),A.current=N,g(N),re(N);let w=v??c.current;Z(N.some(L=>L.draftKey===w)?w:N[0]?.draftKey??null)},[re,Z]),ve=fe(async()=>{if(!(r.aborted||$.current||T.current||oe())){$.current=!0,B(!0),U(null);try{let u=await ee.loadSettings(e);!r.aborted&&!oe()&&!T.current&&Qe(u)}catch(u){r.aborted||U(u instanceof Error?u.message:String(u))}finally{$.current=!1,r.aborted||B(!1)}}},[Qe,e,oe,r]);Le(()=>{let u=!0;queueMicrotask(()=>{u&&ve()});let v=e.connection.subscribe(()=>{e.connection.getSnapshot().status==="ready"&&ve()});return()=>{u=!1,v()}},[e,ve]),Le(()=>(t.setBeforeLeave(()=>T.current?!1:oe()?new Promise(u=>{ae.current?.(!1),ae.current=u,me(!0)}):!0),()=>{t.setBeforeLeave(null),ae.current?.(!1),ae.current=null}),[oe,t]),Le(()=>{if(!I)return;let u=window.requestAnimationFrame(()=>{let v=document.getElementById(I.id);v?.focus(),v?.scrollIntoView({block:"nearest"})});return()=>window.cancelAnimationFrame(u)},[I]);let he=vt(()=>new Map(a.adapters.map(u=>[u.adapter,u])),[a.adapters]),Ie=vt(()=>{let u=new Map;for(let v of p){v.name.trim()||u.set(`${v.draftKey}:name`,"\u6765\u6E90\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A");let N=he.get(v.adapter);if(!N){u.set(`${v.draftKey}:adapter`,"\u5F53\u524D\u6E20\u9053\u4E0D\u53EF\u7528");continue}for(let w of N.fields){let L=fa(v,w);L&&u.set(`${v.draftKey}:${w.key}`,L)}}return u},[he,p]),Ct=u=>{let v=he.get(u);if(!v||T.current||x.current.length>=50)return;let N={draftKey:`draft-${crypto.randomUUID()}`,adapter:u,name:v.label,enabled:!0,values:Object.fromEntries(v.fields.map(w=>[w.key,w.defaultValue??""]))};re([...x.current,N]),Z(N.draftKey),y({id:ue(N,v.fields.find(w=>w.required)?.key??"name")})},At=u=>{T.current||re(x.current.map(v=>v.draftKey===c.current?u(v):v))},Tt=()=>{if(T.current)return;let u=x.current.findIndex(N=>N.draftKey===c.current),v=x.current.filter(N=>N.draftKey!==c.current);re(v),Z(v[Math.min(u,v.length-1)]?.draftKey??null)},Lt=()=>{if(T.current||$.current||!oe())return;let u=Ie.keys().next().value;if(u){let w=p.find(L=>u.startsWith(`${L.draftKey}:`));if(w){Z(w.draftKey);let L=u.slice(w.draftKey.length+1);y({id:ue(w,L==="adapter"?"name":L)})}return}T.current=!0,de(!0),U(null);let v=x.current,N=v.findIndex(w=>w.draftKey===c.current);ee.saveSources(e,v.map(({draftKey:w,...L})=>L),n.current!==l.current?n.current:void 0).then(w=>{r.aborted||(Qe(w,w.sources[N]?.sourceId),ne({...z(),display:w.display}),e.notify({level:"success",title:f(o,"\u989D\u5EA6\u8BBE\u7F6E\u5DF2\u4FDD\u5B58")}))}).catch(w=>{r.aborted||U(w instanceof Error?w.message:String(w))}).finally(()=>{T.current=!1,r.aborted||de(!1)})},Pe=p.find(u=>u.draftKey===q)??null;return{settings:a,draft:p,selected:Pe,selectedKey:q,descriptor:Pe?he.get(Pe.adapter):void 0,validationErrors:Ie,changedKeys:new Set(p.filter(u=>{let v=m.find(N=>N.draftKey===u.draftKey);return!v||le([u])!==le([v])}).map(u=>u.draftKey)),dirty:le(p)!==le(m)||s!==a.display.resetTimeFormat,loading:Q,saving:ce,error:ye,leaveOpen:E,resetTimeFormat:s,setResetTimeFormat:Rt,removedCount:m.filter(u=>!p.some(v=>v.sourceId===u.sourceId)).length,select:Z,add:Ct,update:At,remove:Tt,save:Lt,discard:()=>{if(T.current)return;let u=structuredClone(A.current);re(u),n.current=l.current,d(l.current),U(null),Z(u.some(v=>v.draftKey===c.current)?c.current:u[0]?.draftKey??null)},reload:()=>{ve()},finishLeave:u=>{let v=ae.current;ae.current=null,me(!1),v?.(u)}}}import{PluginAlert as ya,PluginCheckbox as va,PluginField as bt,PluginInput as qt,PluginSecretInput as ha,PluginSelect as ba,PluginTextarea as qa}from"@jetcrab/pi-desk-sdk/react/base";import{jsx as O,jsxs as wt}from"react/jsx-runtime";function St({source:e,locale:t,descriptor:r,errors:a,disabled:i,onChange:o}){let s=n=>f(t,n),d=(n,l)=>{o({...e,values:{...e.values,[n]:l}})};return wt("div",{className:"quota-source-form","data-quota-settings-source":e.draftKey,children:[r?null:O(ya,{tone:"error",density:"compact",children:s("\u5F53\u524D\u6E20\u9053\u4E0D\u53EF\u7528\uFF0C\u53EF\u5220\u9664\u6B64\u6765\u6E90\u3002")}),O(bt,{label:s("\u663E\u793A\u540D\u79F0"),htmlFor:ue(e,"name"),error:a.get(`${e.draftKey}:name`),children:O(qt,{id:ue(e,"name"),value:e.name,maxLength:100,disabled:i,onChange:n=>o({...e,name:n.target.value})})}),wt("label",{className:"quota-source-enabled",children:[O(va,{checked:e.enabled,disabled:i,onChange:n=>o({...e,enabled:n.target.checked})}),s("\u542F\u7528\u6765\u6E90")]}),r?.fields.map(n=>{let l=ue(e,n.key),p=a.get(`${e.draftKey}:${n.key}`);if(n.kind==="select")return O(ba,{id:l,label:s(n.label),description:n.description,error:p,value:e.values[n.key]??"",disabled:i,options:n.options.map(m=>({...m,label:s(m.label)})),onValueChange:m=>d(n.key,m??"")},n.key);let h={id:l,value:e.values[n.key]??"",disabled:i,placeholder:n.placeholder,onChange:m=>d(n.key,m.target.value)};return O(bt,{label:s(n.label),htmlFor:l,description:n.description,error:p,className:["secret","url","textarea"].includes(n.kind)?"quota-field-wide":void 0,children:n.kind==="secret"?O(ha,{...h}):n.kind==="textarea"?O(qa,{...h}):O(qt,{...h,type:n.kind==="url"?"url":"text"})},n.key)})]})}import{Fragment as Na,jsx as b,jsxs as R}from"react/jsx-runtime";function Pt({host:e,target:t,signal:r}){let a=ht(e,t,r),i=K(e).locale,o=(c,Q)=>f(i,c,Q),[s,d]=xe(!1),[n,l]=xe(""),[p,h]=xe(!1),[m,g]=xe(!1),x=wa(()=>new Map(a.settings.adapters.map(c=>[c.adapter,c])),[a.settings.adapters]),A=a.draft.filter(c=>pe(n,c.name,x.get(c.adapter)?.label??c.adapter)),q=()=>{g(!0),h(!0)},k=()=>{l(""),g(!1),h(!0),a.save()};return R(Qa,{className:"quota-settings","data-quota-settings":"","data-editing":p||m||a.draft.length===0,children:[b("style",{children:Se}),R("div",{className:"quota-settings-head",children:[R(Pa,{label:o("\u989D\u5EA6\u8BBE\u7F6E","Quota settings"),children:[b(Qt,{active:!s,onClick:()=>d(!1),children:o("\u989D\u5EA6\u6765\u6E90")}),b(Qt,{active:s,onClick:()=>d(!0),children:o("\u663E\u793A\u8BBE\u7F6E")})]}),R("div",{className:"quota-actions",children:[b(_,{size:"sm",variant:"ghost",disabled:a.dirty||a.loading||a.saving,onClick:a.reload,children:o(a.loading?"\u52A0\u8F7D\u4E2D\u2026":"\u91CD\u65B0\u52A0\u8F7D")}),s?null:b(_,{size:"sm",variant:"secondary",disabled:a.loading||a.saving||a.draft.length>=50||a.settings.adapters.length===0,onClick:q,children:o("\u6DFB\u52A0\u6765\u6E90")})]})]}),s?R(Be,{className:"quota-editor-scroll",viewportClassName:"quota-display-settings","aria-label":o("\u663E\u793A\u8BBE\u7F6E"),children:[a.settings.error||a.error?b(De,{tone:"error",density:"compact",children:a.error??a.settings.error}):null,b(xt,{label:o("\u91CD\u7F6E\u65F6\u95F4\u683C\u5F0F"),value:a.resetTimeFormat,disabled:a.loading||a.saving,options:[{value:"countdown",label:o("\u5012\u8BA1\u65F6")},{value:"absolute",label:o("\u5177\u4F53\u65F6\u95F4")}],onValueChange:c=>{(c==="countdown"||c==="absolute")&&a.setResetTimeFormat(c)}})]}):R("div",{className:"quota-settings-body","data-empty":a.draft.length===0,children:[R("aside",{className:"quota-settings-navigation","aria-label":o("\u989D\u5EA6\u6765\u6E90\u5BFC\u822A"),children:[b(ka,{"aria-label":o("\u641C\u7D22\u6765\u6E90"),placeholder:o("\u641C\u7D22\u6765\u6E90"),value:n,onChange:c=>l(c.target.value)}),b(Be,{className:"quota-source-navigation-scroll",viewportClassName:"quota-source-navigation-viewport","aria-label":o("\u6765\u6E90\u5217\u8868"),children:A.length===0?b(kt,{density:"compact",children:o(a.loading?"\u6B63\u5728\u8BFB\u53D6\u2026":"\u6CA1\u6709\u5339\u914D\u6765\u6E90")}):j(A).map(c=>R("div",{className:"quota-source-group",children:[b("h3",{className:"quota-source-group-title",children:o(x.get(c[0].adapter)?.label??c[0].adapter)}),c.map(Q=>{let B=[...a.validationErrors.keys()].some(ce=>ce.startsWith(`${Q.draftKey}:`)),$=a.changedKeys.has(Q.draftKey);return R(xa,{density:"compact",className:"quota-source-item","data-quota-settings-nav-source":Q.draftKey,selected:!m&&a.selectedKey===Q.draftKey,disabled:a.saving,onClick:()=>{a.select(Q.draftKey),g(!1),h(!0)},children:[b("span",{className:"quota-truncate",children:Q.name.trim()||o("\u672A\u547D\u540D\u6765\u6E90")}),b("span",{className:B?"quota-warning quota-source-item-state":"quota-meta quota-source-item-state",children:o(B?"\u5F85\u5B8C\u5584":$?"\u672A\u4FDD\u5B58":Q.enabled?"\u542F\u7528":"\u505C\u7528")})]},Q.draftKey)})]},c[0].adapter))})]}),R(Be,{className:"quota-editor-scroll",viewportClassName:"quota-editor-viewport","aria-label":o("\u6765\u6E90\u7F16\u8F91"),children:[a.draft.length>0?b(_,{size:"sm",variant:"ghost",className:"quota-back",disabled:a.saving,onClick:()=>{h(!1),g(!1)},children:o("\u8FD4\u56DE\u6765\u6E90")}):null,a.settings.error?b(De,{density:"compact",tone:"error",children:a.settings.error}):null,a.error?b(De,{density:"compact",tone:"error",children:a.error}):null,m?R("div",{className:"quota-add-source",children:[R("div",{className:"quota-editor-head",children:[b("h3",{className:"quota-section-title",children:o("\u6DFB\u52A0\u6765\u6E90")}),b(_,{size:"sm",variant:"ghost",onClick:()=>g(!1),children:o("\u53D6\u6D88")})]}),b(xt,{label:o("\u6E20\u9053"),value:null,placeholder:o("\u9009\u62E9\u6E20\u9053"),options:a.settings.adapters.map(c=>({value:c.adapter,label:o(c.label)})),onValueChange:c=>{c&&(a.add(c),g(!1),l(""))}})]}):a.selected?R(Na,{children:[R("div",{className:"quota-editor-head",children:[R("div",{className:"quota-editor-title",children:[b("h3",{className:"quota-section-title",children:a.selected.name.trim()||o("\u672A\u547D\u540D\u6765\u6E90")}),a.selected.name!==a.descriptor?.label?b("span",{className:"quota-meta",children:a.descriptor?.label??a.selected.adapter}):null]}),b(_,{size:"sm",variant:"danger",disabled:a.saving,onClick:a.remove,children:o("\u5220\u9664\u6765\u6E90")})]}),b(St,{source:a.selected,locale:i,descriptor:a.descriptor,errors:a.validationErrors,disabled:a.saving,onChange:c=>a.update(()=>c)})]}):R(kt,{density:"compact",children:[o(a.loading?"\u6B63\u5728\u8BFB\u53D6\u989D\u5EA6\u6765\u6E90\u2026":"\u5C1A\u672A\u914D\u7F6E\u989D\u5EA6\u6765\u6E90"),!a.loading&&a.settings.adapters.length>0?b(_,{size:"sm",variant:"secondary",onClick:q,children:o("\u6DFB\u52A0\u6765\u6E90")}):null]})]})]}),R("footer",{className:"quota-settings-footer",children:[b("div",{className:"quota-meta",role:"status",children:a.removedCount>0?o(`\u5DF2\u79FB\u9664 ${a.removedCount} \u4E2A\u6765\u6E90\uFF0C\u4FDD\u5B58\u540E\u751F\u6548`,`${a.removedCount} sources will be removed on save`):a.dirty?o("\u6709\u672A\u4FDD\u5B58\u66F4\u6539"):null}),R("div",{className:"quota-actions",children:[a.dirty?b(_,{size:"sm",variant:"ghost",disabled:a.saving,onClick:()=>{a.discard(),g(!1)},children:o("\u653E\u5F03\u66F4\u6539")}):null,b(_,{variant:"primary","data-quota-settings-save":"",disabled:!a.dirty||a.saving||a.loading,onClick:k,children:o(a.saving?"\u4FDD\u5B58\u4E2D\u2026":"\u4FDD\u5B58\u5168\u90E8\u66F4\u6539")})]})]}),b(Sa,{open:a.leaveOpen,title:o("\u653E\u5F03\u672A\u4FDD\u5B58\u7684\u66F4\u6539\uFF1F"),description:o("\u989D\u5EA6\u8BBE\u7F6E\u6709\u672A\u4FDD\u5B58\u7684\u66F4\u6539\u3002"),confirmLabel:o("\u653E\u5F03\u66F4\u6539"),tone:"danger",onConfirm:()=>a.finishLeave(!0),onOpenChange:c=>{c||a.finishLeave(!1)}})]})}import{jsx as $e}from"react/jsx-runtime";function Nt(e,t,r){let a=Ra(e);return a.render($e(Ca,{onError:r,children:t})),()=>a.unmount()}var Ur={mount({container:e,host:t,signal:r}){return Nt(e,$e(yt,{host:t,signal:r}),a=>{t.notify({level:"error",title:"\u989D\u5EA6\u9875\u9762\u6E32\u67D3\u5931\u8D25",description:a.message})})}},Zr={mount({container:e,target:t,host:r,signal:a}){return Nt(e,$e(Pt,{target:t,host:r,signal:a}),i=>{r.notify({level:"error",title:"\u989D\u5EA6\u8BBE\u7F6E\u6E32\u67D3\u5931\u8D25",description:i.message})})}};export{Ur as quotaApplication,Zr as quotaSettingsPage};
@@ -1 +1 @@
1
- import{b as o,c as a,f as r}from"./chunks/chunk-UK7X7FVF.js";function i(e){if(typeof e!="function")throw new Error("Browser Entry factory must be a function");return e}var s=()=>import("./chunks/browser-JQSARJGE.js"),d=i(e=>{let n=e.host.locale?.getSnapshot().locale==="en",c=e.onPush(t=>{t.event==="state"&&a(o(t.data))});return e.registerContribution("application","quota-viewer",{label:n?"Quotas":"\u989D\u5EA6",title:n?"Quota viewer":"\u989D\u5EA6\u67E5\u770B\u5668",icon:{type:"builtin",name:"database"},chrome:"host",load:()=>s().then(t=>t.quotaApplication)}),e.registerContribution("settings-page","quota-sources",{label:n?"Quota settings":"\u989D\u5EA6\u8BBE\u7F6E",icon:{type:"builtin",name:"settings"},load:()=>s().then(t=>t.quotaSettingsPage)}),()=>{c(),r()}});export{d as default};
1
+ import{b as o,c as a,f as r}from"./chunks/chunk-UK7X7FVF.js";function i(e){if(typeof e!="function")throw new Error("Browser Entry factory must be a function");return e}var s=()=>import("./chunks/browser-543MXXEU.js"),d=i(e=>{let n=e.host.locale?.getSnapshot().locale==="en",c=e.onPush(t=>{t.event==="state"&&a(o(t.data))});return e.registerContribution("application","quota-viewer",{label:n?"Quotas":"\u989D\u5EA6",title:n?"Quota viewer":"\u989D\u5EA6\u67E5\u770B\u5668",icon:{type:"builtin",name:"database"},chrome:"host",load:()=>s().then(t=>t.quotaApplication)}),e.registerContribution("settings-page","quota-sources",{label:n?"Quota settings":"\u989D\u5EA6\u8BBE\u7F6E",icon:{type:"builtin",name:"settings"},load:()=>s().then(t=>t.quotaSettingsPage)}),()=>{c(),r()}});export{d as default};
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { PluginButton, PluginInput, PluginScroll, PluginSelectField, PluginTab, PluginTabList } from '@jetcrab/pi-desk-sdk/react/base';
2
+ import { PluginButton, PluginInput, PluginScroll, PluginSelect, PluginTab, PluginTabList } from '@jetcrab/pi-desk-sdk/react/base';
3
3
  import { groupChannels, QUOTA_PAGE_SIZE } from '../l2-quota-model.js';
4
4
  import { quotaText } from '../l2-quota-locale.js';
5
5
  export function QuotaFilters({ sources, locale, adapter, query, onAdapter, onQuery, actions, disabled = false }) {
@@ -11,7 +11,7 @@ export function QuotaFilters({ sources, locale, adapter, query, onAdapter, onQue
11
11
  label: t(source.adapterLabel)
12
12
  }))
13
13
  ];
14
- return (_jsxs("div", { className: "quota-filters", children: [_jsxs("div", { className: "quota-toolbar", children: [_jsx(PluginInput, { className: "quota-search", "aria-label": t('搜索渠道、来源或账号'), placeholder: t('搜索渠道、来源或账号'), value: query, disabled: disabled, onChange: (event) => onQuery(event.target.value) }), _jsx("div", { className: "quota-actions", children: actions })] }), options.length > 2 ? (_jsxs(_Fragment, { children: [_jsx(PluginScroll, { orientation: "horizontal", className: "quota-channel-tabs", "aria-label": t('额度渠道'), children: _jsx(PluginTabList, { label: t('额度渠道'), className: "quota-tabs", children: options.map((option) => (_jsx(PluginTab, { active: adapter === option.value, disabled: disabled, onClick: () => onAdapter(option.value), children: option.label }, option.value))) }) }), _jsx(PluginSelectField, { className: "quota-channel-select", label: t('渠道'), value: adapter, options: options, disabled: disabled, onValueChange: (value) => onAdapter(value ?? '') })] })) : null] }));
14
+ return (_jsxs("div", { className: "quota-filters", children: [_jsxs("div", { className: "quota-toolbar", children: [_jsx(PluginInput, { className: "quota-search", "aria-label": t('搜索渠道、来源或账号'), placeholder: t('搜索渠道、来源或账号'), value: query, disabled: disabled, onChange: (event) => onQuery(event.target.value) }), _jsx("div", { className: "quota-actions", children: actions })] }), options.length > 2 ? (_jsxs(_Fragment, { children: [_jsx(PluginScroll, { orientation: "horizontal", className: "quota-channel-tabs", "aria-label": t('额度渠道'), children: _jsx(PluginTabList, { label: t('额度渠道'), className: "quota-tabs", children: options.map((option) => (_jsx(PluginTab, { active: adapter === option.value, disabled: disabled, onClick: () => onAdapter(option.value), children: option.label }, option.value))) }) }), _jsx(PluginSelect, { className: "quota-channel-select", label: t('渠道'), value: adapter, options: options, disabled: disabled, onValueChange: (value) => onAdapter(value ?? '') })] })) : null] }));
15
15
  }
16
16
  export function QuotaPagination({ locale, page, pageCount, total, onPage, disabled = false }) {
17
17
  if (pageCount <= 1)
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { useMemo, useState } from 'react';
3
- import { PluginAlert, PluginButton, PluginConfirmDialog, PluginEmptyState, PluginInput, PluginListItem, PluginScroll, PluginSelectField, PluginSurface, PluginTab, PluginTabList } from '@jetcrab/pi-desk-sdk/react/base';
3
+ import { PluginAlert, PluginButton, PluginConfirmDialog, PluginEmptyState, PluginInput, PluginListItem, PluginScroll, PluginSelect, PluginSurface, PluginTab, PluginTabList } from '@jetcrab/pi-desk-sdk/react/base';
4
4
  import { useQuotaSettings } from '../hooks/l2-quota-settings.js';
5
5
  import { groupChannels, matchesSearch } from '../l2-quota-model.js';
6
6
  import { quotaText, readQuotaRegion } from '../l2-quota-locale.js';
@@ -29,7 +29,7 @@ export function QuotaSettingsPage({ host, target, signal }) {
29
29
  return (_jsxs(PluginSurface, { className: "quota-settings", "data-quota-settings": "", "data-editing": editing || adding || model.draft.length === 0, children: [_jsx("style", { children: QUOTA_STYLES }), _jsxs("div", { className: "quota-settings-head", children: [_jsxs(PluginTabList, { label: t('额度设置', 'Quota settings'), children: [_jsx(PluginTab, { active: !displayEditing, onClick: () => setDisplayEditing(false), children: t('额度来源') }), _jsx(PluginTab, { active: displayEditing, onClick: () => setDisplayEditing(true), children: t('显示设置') })] }), _jsxs("div", { className: "quota-actions", children: [_jsx(PluginButton, { size: "sm", variant: "ghost", disabled: model.dirty || model.loading || model.saving, onClick: model.reload, children: t(model.loading ? '加载中…' : '重新加载') }), !displayEditing ? (_jsx(PluginButton, { size: "sm", variant: "secondary", disabled: model.loading ||
30
30
  model.saving ||
31
31
  model.draft.length >= 50 ||
32
- model.settings.adapters.length === 0, onClick: startAdd, children: t('添加来源') })) : null] })] }), displayEditing ? (_jsxs(PluginScroll, { className: "quota-editor-scroll", viewportClassName: "quota-display-settings", "aria-label": t('显示设置'), children: [model.settings.error || model.error ? (_jsx(PluginAlert, { tone: "error", density: "compact", children: model.error ?? model.settings.error })) : null, _jsx(PluginSelectField, { label: t('重置时间格式'), value: model.resetTimeFormat, disabled: model.loading || model.saving, options: [
32
+ model.settings.adapters.length === 0, onClick: startAdd, children: t('添加来源') })) : null] })] }), displayEditing ? (_jsxs(PluginScroll, { className: "quota-editor-scroll", viewportClassName: "quota-display-settings", "aria-label": t('显示设置'), children: [model.settings.error || model.error ? (_jsx(PluginAlert, { tone: "error", density: "compact", children: model.error ?? model.settings.error })) : null, _jsx(PluginSelect, { label: t('重置时间格式'), value: model.resetTimeFormat, disabled: model.loading || model.saving, options: [
33
33
  { value: 'countdown', label: t('倒计时') },
34
34
  { value: 'absolute', label: t('具体时间') }
35
35
  ], onValueChange: (value) => {
@@ -54,7 +54,7 @@ export function QuotaSettingsPage({ host, target, signal }) {
54
54
  })] }, channel[0].adapter)))) })] }), _jsxs(PluginScroll, { className: "quota-editor-scroll", viewportClassName: "quota-editor-viewport", "aria-label": t('来源编辑'), children: [model.draft.length > 0 ? (_jsx(PluginButton, { size: "sm", variant: "ghost", className: "quota-back", disabled: model.saving, onClick: () => {
55
55
  setEditing(false);
56
56
  setAdding(false);
57
- }, children: t('返回来源') })) : null, model.settings.error ? (_jsx(PluginAlert, { density: "compact", tone: "error", children: model.settings.error })) : null, model.error ? (_jsx(PluginAlert, { density: "compact", tone: "error", children: model.error })) : null, adding ? (_jsxs("div", { className: "quota-add-source", children: [_jsxs("div", { className: "quota-editor-head", children: [_jsx("h3", { className: "quota-section-title", children: t('添加来源') }), _jsx(PluginButton, { size: "sm", variant: "ghost", onClick: () => setAdding(false), children: t('取消') })] }), _jsx(PluginSelectField, { label: t('渠道'), value: null, placeholder: t('选择渠道'), options: model.settings.adapters.map((adapter) => ({
57
+ }, children: t('返回来源') })) : null, model.settings.error ? (_jsx(PluginAlert, { density: "compact", tone: "error", children: model.settings.error })) : null, model.error ? (_jsx(PluginAlert, { density: "compact", tone: "error", children: model.error })) : null, adding ? (_jsxs("div", { className: "quota-add-source", children: [_jsxs("div", { className: "quota-editor-head", children: [_jsx("h3", { className: "quota-section-title", children: t('添加来源') }), _jsx(PluginButton, { size: "sm", variant: "ghost", onClick: () => setAdding(false), children: t('取消') })] }), _jsx(PluginSelect, { label: t('渠道'), value: null, placeholder: t('选择渠道'), options: model.settings.adapters.map((adapter) => ({
58
58
  value: adapter.adapter,
59
59
  label: t(adapter.label)
60
60
  })), onValueChange: (adapter) => {
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { PluginAlert, PluginCheckbox, PluginField, PluginInput, PluginSecretInput, PluginSelectField, PluginTextarea } from '@jetcrab/pi-desk-sdk/react/base';
2
+ import { PluginAlert, PluginCheckbox, PluginField, PluginInput, PluginSecretInput, PluginSelect, PluginTextarea } from '@jetcrab/pi-desk-sdk/react/base';
3
3
  import { fieldId } from '../hooks/l2-quota-settings.js';
4
4
  import { quotaText } from '../l2-quota-locale.js';
5
5
  export function QuotaSourceForm({ source, locale, descriptor, errors, disabled, onChange }) {
@@ -11,7 +11,7 @@ export function QuotaSourceForm({ source, locale, descriptor, errors, disabled,
11
11
  const id = fieldId(source, field.key);
12
12
  const error = errors.get(`${source.draftKey}:${field.key}`);
13
13
  if (field.kind === 'select') {
14
- return (_jsx(PluginSelectField, { id: id, label: t(field.label), description: field.description, error: error, value: source.values[field.key] ?? '', disabled: disabled, options: field.options.map((option) => ({ ...option, label: t(option.label) })), onValueChange: (value) => updateValue(field.key, value ?? '') }, field.key));
14
+ return (_jsx(PluginSelect, { id: id, label: t(field.label), description: field.description, error: error, value: source.values[field.key] ?? '', disabled: disabled, options: field.options.map((option) => ({ ...option, label: t(option.label) })), onValueChange: (value) => updateValue(field.key, value ?? '') }, field.key));
15
15
  }
16
16
  const common = {
17
17
  id,
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { useMemo, useState } from 'react';
3
- import { PluginAlert, PluginButton, PluginCheckbox, PluginDialog, PluginEmptyState, PluginInput, PluginSelectField } from '@jetcrab/pi-desk-sdk/react/base';
3
+ import { PluginAlert, PluginButton, PluginCheckbox, PluginDialog, PluginEmptyState, PluginInput, PluginSelect } from '@jetcrab/pi-desk-sdk/react/base';
4
4
  import { useQuotaVisibility } from '../hooks/l2-quota-visibility.js';
5
5
  import { quotaText, readQuotaRegion } from '../l2-quota-locale.js';
6
6
  import { displayItems, groupChannels, isWeeklyResource, matchesSearch, resourceLabel } from '../l2-quota-model.js';
@@ -16,7 +16,7 @@ export function QuotaVisibilityDialog({ snapshot, host, signal, onClose }) {
16
16
  return (_jsx(PluginDialog, { open: true, title: t('显示项'), size: "lg", onOpenChange: (open) => {
17
17
  if (!open && !model.saving)
18
18
  onClose();
19
- }, footer: _jsxs(_Fragment, { children: [_jsx(PluginButton, { size: "sm", variant: "ghost", disabled: model.saving || model.hidden.size === 0, onClick: model.showAll, children: t('全部显示') }), _jsx(PluginButton, { size: "sm", variant: "secondary", disabled: model.saving, onClick: onClose, children: t('取消') }), _jsx(PluginButton, { size: "sm", variant: "primary", "data-quota-visibility-save": "", disabled: model.saving || !model.dirty, onClick: model.save, children: t(model.saving ? '保存中…' : '保存') })] }), children: _jsxs("div", { className: "quota-visibility", children: [_jsxs("div", { className: "quota-visibility-filters", children: [_jsx(PluginSelectField, { label: t('渠道'), value: adapter || 'all', disabled: model.saving, options: [
19
+ }, footer: _jsxs(_Fragment, { children: [_jsx(PluginButton, { size: "sm", variant: "ghost", disabled: model.saving || model.hidden.size === 0, onClick: model.showAll, children: t('全部显示') }), _jsx(PluginButton, { size: "sm", variant: "secondary", disabled: model.saving, onClick: onClose, children: t('取消') }), _jsx(PluginButton, { size: "sm", variant: "primary", "data-quota-visibility-save": "", disabled: model.saving || !model.dirty, onClick: model.save, children: t(model.saving ? '保存中…' : '保存') })] }), children: _jsxs("div", { className: "quota-visibility", children: [_jsxs("div", { className: "quota-visibility-filters", children: [_jsx(PluginSelect, { label: t('渠道'), value: adapter || 'all', disabled: model.saving, options: [
20
20
  { value: 'all', label: t('全部渠道') },
21
21
  ...groupChannels(items).map(([item]) => ({
22
22
  value: item.adapter,
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "url": "git+https://github.com/JetCrab/pi-desk.git",
6
6
  "directory": "plugins/pi-desk-quota-viewer"
7
7
  },
8
- "version": "1.0.1-dev.9001",
8
+ "version": "1.0.1-dev.9002",
9
9
  "license": "Apache-2.0",
10
10
  "publishConfig": {
11
11
  "registry": "https://registry.npmjs.org",
@@ -26,14 +26,20 @@
26
26
  "README.md"
27
27
  ],
28
28
  "keywords": [
29
- "pi-package"
29
+ "pi-package",
30
+ "pi-desk-plugin"
30
31
  ],
31
32
  "piDesk": {
32
- "entry": "./dist/pi-desk.js"
33
+ "entry": "./dist/pi-desk.js",
34
+ "i18n": {
35
+ "zh-CN": {
36
+ "description": "通过可配置的服务适配器查看账户余额、剩余额度与用量。"
37
+ }
38
+ }
33
39
  },
34
40
  "dependencies": {
35
41
  "zod": "^4.4.3",
36
- "@jetcrab/pi-desk-sdk": "^1.0.1-dev.9001"
42
+ "@jetcrab/pi-desk-sdk": "^1.0.1-dev.9002"
37
43
  },
38
44
  "devDependencies": {
39
45
  "@base-ui/react": "^1.7.0",
@@ -1,166 +0,0 @@
1
- import{a as Ee,b as Fe,c as ne,d as Ke,e as z}from"./chunk-UK7X7FVF.js";import{createRoot as Ra}from"react-dom/client";import{PluginErrorBoundary as Ca}from"@jetcrab/pi-desk-sdk/react/base";import{Fragment as la,useEffect as ua,useMemo as Te,useRef as ca,useState as gt}from"react";import{PluginAlert as ft,PluginButton as ge,PluginEmptyState as da,PluginScroll as ma,PluginSurface as pa}from"@jetcrab/pi-desk-sdk/react/base";import{useMemo as $t,useState as It}from"react";function F(e){let t=e.locale?.getSnapshot(),r;if(!t?.locale||!t.timeZone)try{r=new Intl.DateTimeFormat().resolvedOptions()}catch{}return{locale:t?.locale??(r?.locale.toLowerCase().startsWith("zh")?"zh-CN":"en"),timeZone:t?.timeZone??r?.timeZone??"UTC"}}var Dt={\u5168\u90E8\u6E20\u9053:"All channels",\u6E20\u9053:"Channel",\u989D\u5EA6\u6E20\u9053:"Quota channels","\u641C\u7D22\u6E20\u9053\u3001\u6765\u6E90\u6216\u8D26\u53F7":"Search channels, sources or accounts",\u641C\u7D22\u6E20\u9053\u6216\u663E\u793A\u5185\u5BB9:"Search channels or display items",\u663E\u793A\u9879:"Display items",\u989D\u5EA6\u8BB0\u5F55:"Quota records",\u5237\u65B0:"Refresh",\u5237\u65B0\u4E2D:"Refreshing","\u5237\u65B0\u4E2D\u2026":"Refreshing\u2026",\u4FDD\u5B58:"Save","\u4FDD\u5B58\u4E2D\u2026":"Saving\u2026",\u53D6\u6D88:"Cancel",\u5168\u90E8\u663E\u793A:"Show all",\u4EC5\u5468:"Weekly only",\u8BE6\u60C5:"Details",\u6536\u8D77:"Collapse",\u5C55\u5F00:"Expand",\u6765\u6E90\u5F02\u5E38:"Source error",\u5DF2\u8FC7\u671F:"Stale",\u4F59\u989D:"Balance",\u53EF\u7528:"Available",\u5269\u4F59:"Remaining",\u5DF2\u7528:"Used",\u603B\u989D:"Limit",\u989D\u5EA6:"Quota",\u672A\u77E5:"Unknown",\u65E0\u9650:"Unlimited",\u8BF7\u6C42:"requests",\u6B21:"resets",\u5269\u4F59\u91CD\u7F6E\u6B21\u6570:"Remaining resets","5 \u5C0F\u65F6\u989D\u5EA6":"5-hour quota",\u5468\u989D\u5EA6:"Weekly quota",\u6708\u989D\u5EA6:"Monthly quota",\u4E3B\u989D\u5EA6:"Primary quota",\u6B21\u989D\u5EA6:"Secondary quota","\u53EF\u7528 Credits":"Available credits",\u53EF\u7528\u4F59\u989D:"Available balance",\u73B0\u91D1\u4F59\u989D:"Cash balance",\u4EE3\u91D1\u5238\u4F59\u989D:"Voucher balance","\u6708\u5EA6 Credits":"Monthly credits","\u8D2D\u4E70 Credits":"Purchased credits","\u8D60\u9001 Credits":"Free credits","\u5B98\u65B9 API":"Official API",\u5B98\u65B9\u4EA7\u54C1:"Official product","\u5185\u90E8 API":"Internal API",\u672C\u5730\u4F30\u7B97:"Local estimate",\u5E76\u53D1\u989D\u5EA6:"Concurrent quota",\u8D26\u671F\u989D\u5EA6:"Billing-period quota",\u6EDA\u52A8\u7A97\u53E3:"Rolling window",\u56FA\u5B9A\u7A97\u53E3:"Fixed window",\u7A97\u53E3\u672A\u77E5:"Unknown window",\u7EC4\u7EC7:"Organization",\u9879\u76EE:"Project",\u6A21\u578B:"Model",\u529F\u80FD:"Feature",\u533A\u57DF:"Region",\u5BC6\u94A5:"Key","Codex\uFF08\u901A\u8FC7 CPA\uFF09":"Codex (via CPA)","\u667A\u8C31 Coding Plan":"Zhipu Coding Plan",\u91CD\u7F6E\u65F6\u95F4\u683C\u5F0F:"Reset time format",\u5012\u8BA1\u65F6:"Countdown",\u5177\u4F53\u65F6\u95F4:"Date and time",\u663E\u793A\u8BBE\u7F6E:"Display settings",\u989D\u5EA6\u6765\u6E90:"Quota sources",\u91CD\u65B0\u52A0\u8F7D:"Reload","\u52A0\u8F7D\u4E2D\u2026":"Loading\u2026",\u6DFB\u52A0\u6765\u6E90:"Add source",\u641C\u7D22\u6765\u6E90:"Search sources",\u989D\u5EA6\u6765\u6E90\u5BFC\u822A:"Quota source navigation",\u6765\u6E90\u5217\u8868:"Sources","\u6B63\u5728\u8BFB\u53D6\u2026":"Loading\u2026",\u6CA1\u6709\u5339\u914D\u6765\u6E90:"No matching sources",\u672A\u547D\u540D\u6765\u6E90:"Unnamed source",\u5F85\u5B8C\u5584:"Incomplete",\u672A\u4FDD\u5B58:"Unsaved",\u542F\u7528:"Enabled",\u505C\u7528:"Disabled",\u6765\u6E90\u7F16\u8F91:"Source editor",\u8FD4\u56DE\u6765\u6E90:"Back to sources",\u9009\u62E9\u6E20\u9053:"Select a channel",\u5220\u9664\u6765\u6E90:"Delete source","\u6B63\u5728\u8BFB\u53D6\u989D\u5EA6\u6765\u6E90\u2026":"Loading quota sources\u2026",\u5C1A\u672A\u914D\u7F6E\u989D\u5EA6\u6765\u6E90:"No quota sources configured",\u6709\u672A\u4FDD\u5B58\u66F4\u6539:"Unsaved changes",\u653E\u5F03\u66F4\u6539:"Discard changes",\u4FDD\u5B58\u5168\u90E8\u66F4\u6539:"Save all changes","\u653E\u5F03\u672A\u4FDD\u5B58\u7684\u66F4\u6539\uFF1F":"Discard unsaved changes?","\u989D\u5EA6\u8BBE\u7F6E\u6709\u672A\u4FDD\u5B58\u7684\u66F4\u6539\u3002":"Quota settings have unsaved changes.",\u663E\u793A\u540D\u79F0:"Display name",\u542F\u7528\u6765\u6E90:"Enable source","\u5F53\u524D\u6E20\u9053\u4E0D\u53EF\u7528\uFF0C\u53EF\u5220\u9664\u6B64\u6765\u6E90\u3002":"This channel is unavailable. You can delete this source.",\u6E05\u9664\u641C\u7D22:"Clear search",\u6062\u590D\u663E\u793A\u9879:"Restore display items",\u6CA1\u6709\u5339\u914D\u7684\u663E\u793A\u5185\u5BB9:"No matching display items",\u6682\u65E0\u53EF\u9009\u62E9\u7684\u989D\u5EA6:"No quota items available",\u8BB0\u5F55\u5206\u9875:"Record pages",\u4E0A\u4E00\u9875:"Previous",\u4E0B\u4E00\u9875:"Next",\u5C1A\u672A\u53D6\u5F97\u6570\u636E:"No data yet",\u672A\u53D6\u5F97\u989D\u5EA6\u6570\u636E:"Quota data unavailable",\u6682\u65E0\u989D\u5EA6\u6570\u636E:"No quota data","\u6B63\u5728\u67E5\u8BE2\u2026":"Querying\u2026",\u5F53\u524D\u989D\u5EA6\u5DF2\u5168\u90E8\u9690\u85CF:"All quota items are hidden",\u6CA1\u6709\u5339\u914D\u7684\u53EF\u89C1\u8BB0\u5F55:"No matching visible records","\u6B63\u5728\u8BFB\u53D6\u989D\u5EA6\u2026":"Loading quotas\u2026",\u6682\u65F6\u65E0\u6CD5\u8BFB\u53D6\u989D\u5EA6\u6765\u6E90:"Quota sources are temporarily unavailable","\u5C1A\u672A\u542F\u7528\u989D\u5EA6\u6765\u6E90\uFF0C\u8BF7\u5728\u201C\u8BBE\u7F6E \u2192 \u989D\u5EA6\u8BBE\u7F6E\u201D\u4E2D\u6DFB\u52A0\u3002":"Add a quota source in Settings \u2192 Quotas.",\u663E\u793A\u9879\u5DF2\u4FDD\u5B58:"Display items saved",\u989D\u5EA6\u8BBE\u7F6E\u5DF2\u4FDD\u5B58:"Quota settings saved"};function f(e,t,r){return e==="zh-CN"?t:r??Dt[t]??t}var W=10,ze=new Intl.Collator("zh-CN",{numeric:!0,sensitivity:"base"});function j(e){let t=new Map;for(let r of e){let a=t.get(r.adapter);a?a.push(r):t.set(r.adapter,[r])}return[...t.values()]}function Me(e,t){return`${e}:${JSON.stringify([t.kind,t.label,t.scope.feature??""])}`}function be(e){let t=new Map;for(let r of e)for(let a of r.resources){let i=Me(r.adapter,a);t.has(i)||t.set(i,{key:i,adapter:r.adapter,adapterLabel:r.adapterLabel,resource:a})}return[...t.values()]}function Oe(e){let t=e.key.split("/");return t.length===3&&t[0]&&["primary","secondary"].includes(t[2])?t[0]:null}function je(e,t=new Set){return j(e).flatMap(r=>r.flatMap(a=>{let i=new Map;for(let o of a.resources){if(t.has(Me(a.adapter,o)))continue;let s=o.scope.account?.trim()||null,d=a.adapter==="cpa-codex"?`cpa:${Oe(o)??o.key}`:s??"source",n=JSON.stringify([a.sourceId,d]),l=i.get(n);l?l.resources.push(o):i.set(n,{key:n,source:a,account:s,resources:[o]})}return a.resources.length===0?[{key:JSON.stringify([a.sourceId]),source:a,account:null,resources:[]}]:[...i.values()].sort((o,s)=>ze.compare(X(o),X(s))||ze.compare(o.key,s.key))}))}function X(e){return e.account??e.source.name}function He(e){if(e.source.adapter!=="cpa-codex"||!e.resources[0])return null;let t=Oe(e.resources[0]);return t===null?null:decodeURIComponent(t)}function Je(e){return e.resources.find(t=>t.scope.plan)?.scope.plan??null}function pe(e,...t){let r=e.trim().toLocaleLowerCase();return!r||t.some(a=>a?.toLocaleLowerCase().includes(r))}function Ve(e,t,r){return e.filter(a=>(!t||a.source.adapter===t)&&pe(r,a.account,a.source.name,a.source.adapterLabel))}var _e={openrouter:["account-credits","api-key-quota"],moonshot:["available-balance"],siliconflow:["total-balance"],"opencode-go":["five-hour-quota","weekly-quota","monthly-quota"],commandcode:["five-hour-quota","weekly-quota","monthly-credits"]};function Bt(e){let t=e.resources.filter(s=>e.source.adapter!=="cpa-codex"||s.key.split("/")[1]!=="reset-credits"),r=_e[e.source.adapter],a,i;r?(a=r.flatMap(s=>t.filter(d=>d.key===s)),i=r.length):e.source.adapter==="cpa-codex"?(a=t.filter(s=>s.key.split("/")[1]==="codex"),i=2):(a=t.filter(s=>s.kind==="quota"&&s.window.durationSeconds!==null),i=3);let o=new Set(a.map(s=>s.key));return[...a,...t.filter(s=>!o.has(s.key))].slice(0,Math.min(3,i))}function Ue(e){let t=Bt(e),r=_e[e.source.adapter],a;if(r)a=r.map(s=>t.find(d=>d.key===s)??null);else if(e.source.adapter==="cpa-codex")a=["primary","secondary"].map(s=>t.find(d=>{let n=d.key.split("/");return n[1]==="codex"&&n[2]===s})??null);else if(e.source.adapter==="zhipu-coding-plan")a=[t.find(s=>s.kind==="quota"&&s.window.durationSeconds!==null&&s.window.durationSeconds<86400)??null,t.find(Ne)??null,null];else return t;let i=new Set(a.flatMap(s=>s?[s.key]:[])),o=t.filter(s=>!i.has(s.key));return a.map(s=>s??o.shift()??null)}function ie(e,t="zh-CN"){let r=e.scope.feature?.trim(),a=f(t,e.label);return r?`${r} \xB7 ${a}`:a}function Ne(e){if(e.kind!=="quota")return!1;let t=e.window.durationSeconds;return t!==null&&t>=6*86400&&t<=8*86400}function Y(e,t){return e===null?"\u2014":new Intl.DateTimeFormat(t.locale==="en"?"en-US":t.locale,{timeZone:t.timeZone,month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hour12:!1}).format(e)}function Ze(e,t,r){if(e===null)return null;let a=e-t;if(a<=0)return f(r,"\u9884\u8BA1\u5DF2\u91CD\u7F6E","Reset expected");let i=Math.floor(a/6e4);if(i===0)return f(r,"1 \u5206\u949F\u5185\u91CD\u7F6E","Resets in less than 1m");let o=Math.floor(i/60),s=Math.floor(o/24),n=(s>0?[f(r,`${s} \u5929`,`${s}d`),o%24?f(r,`${o%24} \u5C0F\u65F6`,`${o%24}h`):""]:[o?f(r,`${o} \u5C0F\u65F6`,`${o}h`):"",i%60?f(r,`${i%60} \u5206\u949F`,`${i%60}m`):""]).filter(Boolean).join(" ");return f(r,`${n}\u540E\u91CD\u7F6E`,`Resets in ${n}`)}function M(e,t){return new Intl.NumberFormat(t,{maximumFractionDigits:4}).format(e)}function G(e,t,r="zh-CN"){if(e.state==="unknown")return f(r,"\u672A\u77E5");if(e.state==="unlimited")return f(r,"\u65E0\u9650");if(e.state==="not_applicable")return"\u2014";if(t.kind==="currency")try{return new Intl.NumberFormat(r,{style:"currency",currency:t.code,maximumFractionDigits:4}).format(e.value)}catch{return`${M(e.value,r)} ${t.code}`}return t.kind==="percentage"?`${M(e.value,r)}%`:t.kind==="tokens"?`${M(e.value,r)} Tokens`:t.kind==="requests"?`${M(e.value,r)} ${f(r,"\u8BF7\u6C42")}`:`${M(e.value,r)} ${f(r,t.label)}`}function Xe(e,t="zh-CN"){return new Intl.NumberFormat(t,{style:"percent",maximumFractionDigits:2}).format(e)}function We(e){let{remaining:t,used:r,limit:a}=e.values;return t.state==="known"||t.state==="unlimited"?{label:"\u5269\u4F59",value:t}:r.state==="known"||r.state==="unlimited"?{label:"\u5DF2\u7528",value:r}:a.state==="known"||a.state==="unlimited"?{label:"\u603B\u989D",value:a}:{label:"\u989D\u5EA6",value:t}}function Ye(e){let{remaining:t,limit:r}=e.values;return t.state!=="known"||r.state!=="known"||r.value<=0?null:Math.max(0,Math.min(1,t.value/r.value))}function Ge(e){return e===null||e>=.5?"neutral":e>=.2?"warning":"error"}function et(e){return{official_api:"\u5B98\u65B9 API",official_product:"\u5B98\u65B9\u4EA7\u54C1",internal_api:"\u5185\u90E8 API",local_estimate:"\u672C\u5730\u4F30\u7B97"}[e]}function tt(e,t="zh-CN"){let{kind:r,durationSeconds:a}=e.window;if(r==="concurrent")return f(t,"\u5E76\u53D1\u989D\u5EA6");if(r==="billing")return f(t,"\u8D26\u671F\u989D\u5EA6");if(a===null)return f(t,r==="rolling"?"\u6EDA\u52A8\u7A97\u53E3":r==="fixed"?"\u56FA\u5B9A\u7A97\u53E3":"\u7A97\u53E3\u672A\u77E5");let i=a/3600,o=i<24?f(t,`${M(i,t)} \u5C0F\u65F6`,`${M(i,t)} hours`):f(t,`${M(i/24,t)} \u5929`,`${M(i/24,t)} days`);return f(t,`${o}${r==="rolling"?"\u6EDA\u52A8\u7A97\u53E3":"\u7A97\u53E3"}`,`${o} ${r==="rolling"?"rolling window":"window"}`)}function at(e,t="zh-CN"){let r={organization:"\u7EC4\u7EC7",project:"\u9879\u76EE",model:"\u6A21\u578B",feature:"\u529F\u80FD",region:"\u533A\u57DF",key:"\u5BC6\u94A5"};return Object.entries(e.scope).flatMap(([i,o])=>["account","plan"].includes(i)||!o.trim()?[]:[`${f(t,r[i]??i)}\uFF1A${o}`]).join(" \xB7 ")||null}function rt(e,t){let[r,a]=It({adapter:"",query:"",page:1}),i=t.some(n=>n.adapter===r.adapter)?r.adapter:"",o=$t(()=>Ve(e,i,r.query),[i,e,r.query]),s=Math.max(1,Math.ceil(o.length/W)),d=i!==r.adapter?1:Math.min(r.page,s);return(i!==r.adapter||d!==r.page)&&a({...r,adapter:i,page:d}),{adapter:i,query:r.query,page:d,pageCount:s,total:o.length,items:o.slice((d-1)*W,d*W),setAdapter:n=>{a(l=>({...l,adapter:n,page:1}))},setQuery:n=>{a(l=>({...l,query:n,page:1}))},setPage:n=>{a(l=>({...l,page:n}))}}}import{useCallback as Et,useEffect as ot,useRef as Ft,useState as we,useSyncExternalStore as Kt}from"react";function Re(e){return{error:typeof e.error=="string"?e.error:null,adapters:Array.isArray(e.adapters)?JSON.parse(JSON.stringify(e.adapters)):[],sources:Array.isArray(e.sources)?JSON.parse(JSON.stringify(e.sources)):[],display:Ee(e.display)}}async function qe(e,t,r={}){try{return await e.piDesk.invokeGlobal(t,JSON.parse(JSON.stringify(r)))}catch(a){throw console.error("[\u989D\u5EA6\u67E5\u770B\u5668] \u64CD\u4F5C\u5931\u8D25",{method:t,message:a instanceof Error?a.message:String(a)}),a}}var ee={async query(e,t){return Fe(await qe(e,"state-get",{force:t}))},async loadSettings(e){return Re(await qe(e,"settings-get"))},async saveSources(e,t,r){return Re(await qe(e,"settings-save",{sources:t,...r?{display:{resetTimeFormat:r}}:{}}))},async saveVisibility(e,t){return Re(await qe(e,"settings-save",{display:{hiddenItemKeys:t}}))}};function zt(){return Kt(Ke,z,z)}function nt(){let[e,t]=we(()=>Date.now());return ot(()=>{let r=window.setInterval(()=>t(Date.now()),6e4);return()=>window.clearInterval(r)},[]),e}function it(e,t){let r=zt(),[a,i]=we(!0),[o,s]=we(!1),[d,n]=we(null),l=Ft(!1),p=Et(async h=>{if(l.current||t.aborted)return;l.current=!0,s(!0),n(null);let m=z();try{let g=await ee.query(e,h);!t.aborted&&z()===m&&ne(g)}catch(g){t.aborted||n(g instanceof Error?g.message:String(g))}finally{l.current=!1,t.aborted||(i(!1),s(!1))}},[e,t]);return ot(()=>{let h=!0;queueMicrotask(()=>{h&&p(!0)});let m=e.connection.subscribe(()=>{e.connection.getSnapshot().status==="ready"&&p(!1)});return()=>{h=!1,m()}},[e,p]),{snapshot:r,loading:a,requesting:o,error:d,refresh:()=>{p(!0)}}}var Se=`
2
- .quota-application {
3
- display: flex;
4
- flex-direction: column;
5
- width: min(960px, calc(100dvw - 2rem));
6
- max-height: min(820px, calc(100dvh - 7rem));
7
- min-height: 0;
8
- gap: .75rem;
9
- padding: 1rem;
10
- overflow: hidden;
11
- container: quota-panel / inline-size;
12
- }
13
- .quota-actions, .quota-toolbar, .quota-pagination, .quota-settings-head, .quota-editor-head {
14
- display: flex;
15
- min-width: 0;
16
- align-items: center;
17
- gap: .5rem;
18
- }
19
- .quota-actions { flex-wrap: wrap; flex-shrink: 0; }
20
- .quota-toolbar { flex-wrap: wrap; justify-content: space-between; }
21
- .quota-search { flex: 1; min-width: min(220px, 100%); }
22
- .quota-filters { display: grid; min-width: 0; gap: .5rem; flex: none; }
23
- .quota-channel-tabs { min-width: 0; }
24
- .quota-tabs { flex-wrap: nowrap; width: max-content; min-width: 100%; }
25
- .quota-tabs > button { flex: none; white-space: nowrap; }
26
- .quota-filters .quota-channel-select { display: none; }
27
- .quota-meta {
28
- color: var(--pi-desk-plugin-muted-foreground, var(--muted-foreground));
29
- font-size: .75rem;
30
- line-height: 1.5;
31
- }
32
- .quota-warning { color: var(--status-warning, var(--foreground)); font-size: .75rem; line-height: 1.5; }
33
- .quota-truncate { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
34
- .quota-section-title, .quota-channel-heading {
35
- margin: 0;
36
- font-size: .875rem;
37
- line-height: 1.5;
38
- font-weight: 600;
39
- overflow-wrap: anywhere;
40
- }
41
- .quota-channel-heading {
42
- padding: .5rem .75rem;
43
- background: var(--pi-desk-plugin-muted, var(--muted));
44
- }
45
- .quota-record + .quota-channel-heading { margin-top: 1rem; }
46
- .quota-record-scroll { flex: 1 1 auto; min-height: 0; }
47
- .quota-record-viewport { min-width: 0; }
48
- .quota-record { min-width: 0; border-bottom: 1px solid var(--border); }
49
- .quota-record-summary {
50
- display: grid;
51
- grid-template-columns: minmax(11rem, 1fr) minmax(0, 2fr) auto;
52
- gap: .75rem;
53
- align-items: center;
54
- min-height: 3.5rem;
55
- padding: .5rem .75rem;
56
- }
57
- .quota-record-identity, .quota-editor-title, .quota-detail-identity {
58
- display: grid;
59
- min-width: 0;
60
- gap: .25rem;
61
- }
62
- .quota-record-label { display: flex; min-width: 0; align-items: baseline; gap: .5rem; }
63
- .quota-plan { flex: none; }
64
- .quota-record-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
65
- .quota-record-state { display: flex; flex-wrap: wrap; gap: .5rem; }
66
- .quota-record-state:empty { display: none; }
67
- .quota-metrics { display: grid; min-width: 0; gap: .75rem; align-items: start; }
68
- .quota-metric { display: grid; min-width: 0; gap: .25rem; text-align: right; overflow-wrap: anywhere; }
69
- .quota-metric-reading { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: baseline; gap: 0 .5rem; }
70
- .quota-metric-value { margin-left: auto; font-size: .875rem; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.5; }
71
- .quota-progress { height: 4px; border-radius: 999px; overflow: hidden; background: var(--muted); }
72
- .quota-progress > span { display: block; height: 100%; border-radius: inherit; background: var(--primary); transition: width 150ms ease-out; }
73
- .quota-metric[data-quota-tone="warning"] .quota-progress > span { background: var(--status-warning, var(--foreground)); }
74
- .quota-metric[data-quota-tone="error"] .quota-progress > span { background: var(--destructive); }
75
- .quota-record-detail { display: grid; gap: .75rem; padding: .75rem; background: var(--muted); }
76
- .quota-detail-identity, .quota-error-text, .quota-full-name { overflow-wrap: anywhere; }
77
- .quota-resource-detail { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr); gap: .75rem; border-top: 1px solid var(--border); padding-top: .75rem; }
78
- .quota-detail-resource-name, .quota-detail-values { display: grid; min-width: 0; gap: .25rem; overflow-wrap: anywhere; }
79
- .quota-detail-resource-name strong { font-weight: 500; }
80
- .quota-detail-values { text-align: right; font-variant-numeric: tabular-nums; }
81
- .quota-pagination { flex: none; justify-content: space-between; flex-wrap: wrap; padding-top: .5rem; border-top: 1px solid var(--border); }
82
- .quota-empty-actions { justify-content: center; margin-top: .75rem; }
83
- .quota-source-notices { padding: .5rem .75rem; border-bottom: 1px solid var(--border); }
84
- .quota-source-notices summary { cursor: pointer; min-height: 1.75rem; line-height: 1.75rem; }
85
- .quota-source-notices summary:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; }
86
- .quota-source-errors { display: grid; gap: .75rem; padding: .5rem 0; }
87
- .quota-error-text { margin-top: .25rem; }
88
- .quota-visibility { display: grid; min-width: 0; gap: .5rem; container: quota-panel / inline-size; }
89
- .quota-visibility-filters { display: grid; grid-template-columns: minmax(140px, 1fr) minmax(0, 2fr); align-items: end; gap: .75rem; margin-bottom: .5rem; }
90
- .quota-visibility-channel + .quota-visibility-channel { border-top: 1px solid var(--border); padding-top: .75rem; }
91
- .quota-visibility-heading { display: flex; align-items: center; justify-content: space-between; gap: .5rem; min-height: 1.75rem; }
92
- .quota-selection { display: flex; min-width: 0; min-height: 1.75rem; align-items: center; gap: .5rem; cursor: pointer; }
93
- .quota-selection > input { flex: none; }
94
- .quota-visibility-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem .75rem; padding: .5rem 0; }
95
- .quota-visibility-options .quota-selection { align-items: flex-start; overflow-wrap: anywhere; }
96
- .quota-settings {
97
- display: grid;
98
- grid-template-rows: auto minmax(0, 1fr) auto;
99
- width: 100%;
100
- height: 100%;
101
- max-height: 100%;
102
- min-height: 0;
103
- overflow: hidden;
104
- container-name: quota-settings;
105
- }
106
- .quota-settings-head { justify-content: space-between; padding: 1rem; flex-wrap: wrap; }
107
- .quota-display-settings { display: grid; align-content: start; gap: .75rem; padding: 0 1rem 1rem; }
108
- .quota-display-settings > * { max-width: 640px; }
109
- .quota-settings-body { display: grid; grid-template-columns: 224px minmax(0, 1fr); min-height: 0; min-width: 0; overflow: hidden; }
110
- .quota-settings-navigation { display: flex; flex-direction: column; gap: .75rem; min-height: 0; min-width: 0; padding: 0 .75rem 1rem 1rem; border-right: 1px solid var(--border); }
111
- .quota-source-navigation-scroll { min-height: 0; flex: 1; }
112
- .quota-source-navigation-viewport { min-width: 0; }
113
- .quota-source-group + .quota-source-group { margin-top: .75rem; }
114
- .quota-source-group-title { margin: 0; padding: .25rem .5rem; color: var(--muted-foreground); font-size: .75rem; font-weight: 500; overflow-wrap: anywhere; }
115
- .quota-settings .quota-source-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; width: 100%; min-height: 2.25rem; }
116
- .quota-source-item-state { white-space: nowrap; }
117
- .quota-editor-scroll { min-height: 0; min-width: 0; }
118
- .quota-editor-viewport { padding: 0 1rem 1rem; scroll-padding-block: .5rem; container: quota-editor / inline-size; }
119
- .quota-editor-head { justify-content: space-between; align-items: flex-start; max-width: 640px; margin-bottom: 1rem; }
120
- .quota-editor-head .quota-section-title { font-size: .875rem; }
121
- .quota-source-form { display: grid; max-width: 640px; gap: .75rem; grid-template-columns: minmax(0, 1fr); }
122
- .quota-field-wide { grid-column: 1 / -1; }
123
- .quota-source-enabled { display: flex; min-height: 2rem; align-items: center; align-self: end; gap: .5rem; cursor: pointer; }
124
- .quota-add-source { max-width: 640px; }
125
- .quota-settings-footer {
126
- display: flex;
127
- flex-wrap: wrap;
128
- min-width: 0;
129
- align-items: center;
130
- justify-content: space-between;
131
- gap: .5rem;
132
- padding: .75rem 1rem;
133
- border-top: 1px solid var(--border);
134
- background: var(--popover);
135
- }
136
- .quota-settings-footer > .quota-actions { margin-left: auto; }
137
- .quota-settings .quota-back { display: none; margin-bottom: .75rem; }
138
- .quota-settings-body[data-empty="true"] { grid-template-columns: minmax(0, 1fr); }
139
- .quota-settings-body[data-empty="true"] .quota-settings-navigation { display: none; }
140
- @container quota-panel (max-width: 44rem) {
141
- .quota-filters .quota-channel-tabs { display: none; }
142
- .quota-filters .quota-channel-select { display: block; }
143
- .quota-record-summary { grid-template-columns: minmax(0, 1fr) auto; gap: .5rem; }
144
- .quota-record-identity { grid-column: 1; grid-row: 1; }
145
- .quota-detail-toggle { grid-column: 2; grid-row: 1; }
146
- .quota-metrics { grid-column: 1 / -1; }
147
- .quota-metric { text-align: left; }
148
- .quota-metric-reading { justify-content: flex-start; }
149
- .quota-resource-detail { grid-template-columns: minmax(0, 1fr); }
150
- .quota-detail-values { text-align: left; }
151
- .quota-visibility-options, .quota-visibility-filters { grid-template-columns: minmax(0, 1fr); }
152
- }
153
- @container quota-settings (max-width: 51.999rem) {
154
- .quota-settings-body { grid-template-columns: minmax(0, 1fr); }
155
- .quota-settings-navigation { border-right: 0; padding-right: 1rem; }
156
- .quota-settings[data-editing="true"] .quota-settings-navigation { display: none; }
157
- .quota-settings[data-editing="false"] .quota-editor-scroll { display: none; }
158
- .quota-settings .quota-back { display: inline-flex; }
159
- }
160
- @container quota-editor (min-width: 32rem) {
161
- .quota-source-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
162
- }
163
- @media (prefers-reduced-motion: reduce) {
164
- .quota-progress > span { transition: none; }
165
- }
166
- `;import{PluginButton as st,PluginInput as Mt,PluginScroll as Ot,PluginSelectField as jt,PluginTab as Ht,PluginTabList as Jt}from"@jetcrab/pi-desk-sdk/react/base";import{Fragment as Vt,jsx as H,jsxs as te}from"react/jsx-runtime";function lt({sources:e,locale:t,adapter:r,query:a,onAdapter:i,onQuery:o,actions:s,disabled:d=!1}){let n=p=>f(t,p),l=[{value:"",label:n("\u5168\u90E8\u6E20\u9053")},...j(e).map(([p])=>({value:p.adapter,label:n(p.adapterLabel)}))];return te("div",{className:"quota-filters",children:[te("div",{className:"quota-toolbar",children:[H(Mt,{className:"quota-search","aria-label":n("\u641C\u7D22\u6E20\u9053\u3001\u6765\u6E90\u6216\u8D26\u53F7"),placeholder:n("\u641C\u7D22\u6E20\u9053\u3001\u6765\u6E90\u6216\u8D26\u53F7"),value:a,disabled:d,onChange:p=>o(p.target.value)}),H("div",{className:"quota-actions",children:s})]}),l.length>2?te(Vt,{children:[H(Ot,{orientation:"horizontal",className:"quota-channel-tabs","aria-label":n("\u989D\u5EA6\u6E20\u9053"),children:H(Jt,{label:n("\u989D\u5EA6\u6E20\u9053"),className:"quota-tabs",children:l.map(p=>H(Ht,{active:r===p.value,disabled:d,onClick:()=>i(p.value),children:p.label},p.value))})}),H(jt,{className:"quota-channel-select",label:n("\u6E20\u9053"),value:r,options:l,disabled:d,onValueChange:p=>i(p??"")})]}):null]})}function ut({locale:e,page:t,pageCount:r,total:a,onPage:i,disabled:o=!1}){if(r<=1)return null;let s=d=>f(e,d);return te("nav",{className:"quota-pagination","aria-label":s("\u8BB0\u5F55\u5206\u9875"),children:[te("span",{className:"quota-meta",children:[(t-1)*W+1,"\u2013",Math.min(t*W,a)," / ",a," ",f(e,"\u6761","records")]}),te("div",{className:"quota-actions",children:[H(st,{size:"sm",variant:"ghost",disabled:o||t<=1,onClick:()=>i(t-1),children:s("\u4E0A\u4E00\u9875")}),te("span",{className:"quota-meta",children:[t," / ",r]}),H(st,{size:"sm",variant:"ghost",disabled:o||t>=r,onClick:()=>i(t+1),children:s("\u4E0B\u4E00\u9875")})]})]})}import{useId as _t}from"react";import{PluginAlert as Ut,PluginButton as Zt}from"@jetcrab/pi-desk-sdk/react/base";import{jsx as P,jsxs as S}from"react/jsx-runtime";function Xt({resource:e,now:t,region:r,resetTimeFormat:a}){let i=e.kind==="balance"?{label:"\u4F59\u989D",value:e.available}:We(e),o=e.kind==="quota"?Ye(e):null,s=ie(e,r.locale),d=e.kind==="quota"?e.window.resetAt:null,n=d===null?null:a==="countdown"?Ze(d,t,r.locale):f(r.locale,`${Y(d,r)} \u91CD\u7F6E`,`Resets ${Y(d,r)}`);return S("div",{className:"quota-metric","data-quota-resource":e.key,"data-quota-tone":Ge(o),children:[S("span",{className:"quota-meta",children:[s,e.kind==="quota"?` \xB7 ${f(r.locale,i.label)}`:""]}),S("div",{className:"quota-metric-reading",children:[n?P("span",{className:"quota-meta",children:n}):null,S("span",{className:"quota-metric-value",children:[G(i.value,e.unit,r.locale),e.unit.kind!=="percentage"&&o!==null?S("span",{className:"quota-meta",children:[" ",Xe(o,r.locale)]}):null]})]}),o!==null?P("div",{className:"quota-progress",role:"progressbar","aria-label":f(r.locale,`${s}\u5269\u4F59\u989D\u5EA6`,`${s} remaining`),"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(o*100),children:P("span",{style:{width:`${o*100}%`}})}):null]})}function Wt({resource:e,region:t}){let r=at(e,t.locale),a=(i,o)=>f(t.locale,i,o);return S("div",{className:"quota-resource-detail","data-quota-detail-resource":e.key,children:[S("div",{className:"quota-detail-resource-name",children:[P("strong",{children:ie(e,t.locale)}),r?P("span",{className:"quota-meta",children:r}):null,e.kind==="quota"?P("span",{className:"quota-meta",children:tt(e,t.locale)}):null]}),e.kind==="balance"?S("div",{className:"quota-detail-values",children:[S("span",{children:[a(e.unit.kind==="currency"?"\u4F59\u989D":"\u53EF\u7528")," ",P("strong",{children:G(e.available,e.unit,t.locale)})]}),e.expiresAt!==null?S("span",{className:"quota-meta",children:[a("\u5230\u671F","Expires")," ",Y(e.expiresAt,t)]}):null]}):S("div",{className:"quota-detail-values",children:[S("span",{children:[a("\u5269\u4F59")," ",P("strong",{children:G(e.values.remaining,e.unit,t.locale)})]}),S("span",{children:[a("\u5DF2\u7528")," ",G(e.values.used,e.unit,t.locale)]}),e.unit.kind!=="percentage"?S("span",{children:[a("\u603B\u989D")," ",G(e.values.limit,e.unit,t.locale)]}):null,e.window.resetAt!==null?S("span",{className:"quota-meta",children:[a("\u91CD\u7F6E","Resets")," ",Y(e.window.resetAt,t)]}):null]})]})}function ct({record:e,now:t,expanded:r,duplicateName:a,region:i,resetTimeFormat:o,onToggle:s}){let d=_t(),{source:n}=e,l=(k,c)=>f(i.locale,k,c),p=X(e),h=n.staleAt!==null&&t>=n.staleAt,m=He(e),g=Ue(e).filter(k=>k!==null),x=Je(e),A=n.adapter==="cpa-codex"?e.resources.find(k=>k.kind==="balance"&&k.key.split("/")[1]==="reset-credits"):void 0,q=[e.account&&n.name!==n.adapterLabel?n.name:null,a?`${n.sourceId.slice(0,8)}${m?` / ${m}`:""}`:null].filter(Boolean).join(" \xB7 ");return S("section",{className:"quota-record","data-quota-record":e.key,children:[S("div",{className:"quota-record-summary",children:[S("div",{className:"quota-record-identity",children:[S("div",{className:"quota-record-label",children:[P("span",{className:"quota-record-name",children:p}),x?P("span",{className:"quota-meta quota-plan",children:x}):null]}),q?P("span",{className:"quota-meta quota-truncate",children:q}):null,S("div",{className:"quota-record-state",children:[A?.kind==="balance"?S("span",{className:"quota-meta",children:[l("\u5269\u4F59\u91CD\u7F6E\u6B21\u6570"),"\uFF1A",G(A.available,A.unit,i.locale)]}):null,n.error?P("span",{className:"quota-warning",children:l("\u6765\u6E90\u5F02\u5E38")}):null,h?P("span",{className:"quota-warning",children:l("\u5DF2\u8FC7\u671F")}):null,n.refreshing?P("span",{className:"quota-meta",children:l("\u5237\u65B0\u4E2D")}):null]})]}),P("div",{className:"quota-metrics",style:{gridTemplateColumns:`repeat(${g.length||1}, minmax(0, 1fr))`},children:e.resources.length>0?g.map(k=>P(Xt,{resource:k,now:t,region:i,resetTimeFormat:o},k.key)):P("span",{className:"quota-meta",children:l(n.refreshing?"\u6B63\u5728\u67E5\u8BE2\u2026":n.error?"\u672A\u53D6\u5F97\u989D\u5EA6\u6570\u636E":"\u6682\u65E0\u989D\u5EA6\u6570\u636E")})}),P(Zt,{size:"sm",variant:"ghost",className:"quota-detail-toggle","aria-label":l(`${r?"\u6536\u8D77":"\u67E5\u770B"}${p}\u8BE6\u60C5`,`${r?"Collapse":"View"} ${p} details`),"aria-expanded":r,"aria-controls":d,onClick:s,children:l(r?"\u6536\u8D77":"\u8BE6\u60C5")})]}),r?S("div",{className:"quota-record-detail",id:d,children:[S("div",{className:"quota-detail-identity",children:[P("strong",{children:p}),S("span",{className:"quota-meta",children:[l("\u6765\u6E90","Source"),"\uFF1A",n.name," \xB7 ",l(et(n.dataSource))]}),m?S("span",{className:"quota-meta",children:[l("CPA \u7D22\u5F15","CPA index"),"\uFF1A",m]}):null,a?S("span",{className:"quota-meta",children:[l("\u6765\u6E90 ID","Source ID"),"\uFF1A",n.sourceId]}):null,P("span",{className:"quota-meta",children:n.observedAt===null?l("\u5C1A\u672A\u53D6\u5F97\u6570\u636E"):l(`\u6570\u636E\u66F4\u65B0\u4E8E ${Y(n.observedAt,i)}`,`Updated ${Y(n.observedAt,i)}`)})]}),n.error?P(Ut,{tone:"warning",density:"compact",children:n.error}):null,e.resources.map(k=>P(Wt,{resource:k,region:i},k.key))]}):null]})}import{useMemo as ea,useState as mt}from"react";import{PluginAlert as ta,PluginButton as ke,PluginCheckbox as aa,PluginDialog as ra,PluginEmptyState as oa,PluginInput as na,PluginSelectField as ia}from"@jetcrab/pi-desk-sdk/react/base";import{useMemo as Yt,useRef as Gt,useState as Ae}from"react";function dt(e,t,r,a){let i=F(t).locale,[o,s]=Ae(()=>new Set(e.display.hiddenItemKeys)),[d,n]=Ae(!1),l=Gt(!1),[p,h]=Ae(null),m=Yt(()=>new Set(e.display.hiddenItemKeys),[e.display.hiddenItemKeys]),g=o.size!==m.size||[...o].some(q=>!m.has(q));return{hidden:o,dirty:g,saving:d,error:p,select:(q,k)=>{if(l.current)return;let c=new Set(k),Q=new Set(o);for(let B of q)c.has(B)?Q.delete(B):Q.add(B);if(Q.size>500){h(f(i,`\u6700\u591A\u9690\u85CF ${500} \u9879\uFF0C\u8BF7\u5148\u6062\u590D\u90E8\u5206\u663E\u793A\u9879\u3002`,`You can hide up to ${500} items. Restore some items first.`));return}h(null),s(Q)},save:()=>{l.current||!g||(l.current=!0,n(!0),h(null),ee.saveVisibility(t,[...o]).then(q=>{r.aborted||(ne({...z(),display:q.display}),t.notify({level:"success",title:f(i,"\u663E\u793A\u9879\u5DF2\u4FDD\u5B58")}),a())}).catch(q=>{r.aborted||h(q instanceof Error?q.message:String(q))}).finally(()=>{l.current=!1,r.aborted||n(!1)}))},showAll:()=>{l.current||(s(new Set),h(null))}}}import{Fragment as sa,jsx as D,jsxs as se}from"react/jsx-runtime";function pt({snapshot:e,host:t,signal:r,onClose:a}){let i=dt(e,t,r,a),o=F(t).locale,s=g=>f(o,g),d=ea(()=>be(e.sources),[e.sources]),[n,l]=mt(""),[p,h]=mt(""),m=d.filter(g=>(!n||g.adapter===n)&&pe(p,s(g.adapterLabel),ie(g.resource,o)));return D(ra,{open:!0,title:s("\u663E\u793A\u9879"),size:"lg",onOpenChange:g=>{!g&&!i.saving&&a()},footer:se(sa,{children:[D(ke,{size:"sm",variant:"ghost",disabled:i.saving||i.hidden.size===0,onClick:i.showAll,children:s("\u5168\u90E8\u663E\u793A")}),D(ke,{size:"sm",variant:"secondary",disabled:i.saving,onClick:a,children:s("\u53D6\u6D88")}),D(ke,{size:"sm",variant:"primary","data-quota-visibility-save":"",disabled:i.saving||!i.dirty,onClick:i.save,children:s(i.saving?"\u4FDD\u5B58\u4E2D\u2026":"\u4FDD\u5B58")})]}),children:se("div",{className:"quota-visibility",children:[se("div",{className:"quota-visibility-filters",children:[D(ia,{label:s("\u6E20\u9053"),value:n||"all",disabled:i.saving,options:[{value:"all",label:s("\u5168\u90E8\u6E20\u9053")},...j(d).map(([g])=>({value:g.adapter,label:s(g.adapterLabel)}))],onValueChange:g=>l(g==="all"?"":g??"")}),D(na,{"aria-label":s("\u641C\u7D22\u6E20\u9053\u6216\u663E\u793A\u5185\u5BB9"),placeholder:s("\u641C\u7D22\u6E20\u9053\u6216\u663E\u793A\u5185\u5BB9"),value:p,disabled:i.saving,onChange:g=>h(g.target.value)})]}),i.error?D(ta,{tone:"error",density:"compact",children:i.error}):null,m.length===0?D(oa,{density:"compact",children:s(d.length===0?"\u6682\u65E0\u53EF\u9009\u62E9\u7684\u989D\u5EA6":"\u6CA1\u6709\u5339\u914D\u7684\u663E\u793A\u5185\u5BB9")}):j(m).map(g=>{let x=g[0],A=d.filter(c=>c.adapter===x.adapter),q=A.map(c=>c.key),k=A.filter(c=>Ne(c.resource)).map(c=>c.key);return se("section",{className:"quota-visibility-channel",children:[se("div",{className:"quota-visibility-heading",children:[D("h3",{className:"quota-section-title",children:s(x.adapterLabel)}),k.length>0&&k.length<q.length?D(ke,{size:"sm",variant:"ghost",disabled:i.saving,onClick:()=>i.select(q,k),children:s("\u4EC5\u5468")}):null]}),D("div",{className:"quota-visibility-options",children:g.map(c=>se("label",{className:"quota-selection",children:[D(aa,{checked:!i.hidden.has(c.key),disabled:i.saving,onChange:Q=>i.select([c.key],Q.target.checked?[c.key]:[])}),D("span",{children:ie(c.resource,o)})]},c.key))})]},x.adapter)})]})})}import{Fragment as ga,jsx as C,jsxs as J}from"react/jsx-runtime";function yt({host:e,signal:t}){let{snapshot:r,loading:a,requesting:i,error:o,refresh:s}=it(e,t),d=nt(),n=F(e),l=(y,E)=>f(n.locale,y,E),p=Te(()=>new Set(r.display.hiddenItemKeys),[r.display.hiddenItemKeys]),h=Te(()=>je(r.sources,p),[p,r.sources]),m=rt(h,r.sources),[g,x]=gt(null),[A,q]=gt(!1),k=ca(null),c=r.sources.some(y=>y.refreshing),Q=r.sources.filter(y=>y.error),B=r.sources.reduce((y,E)=>y+E.resources.length,0),$=be(r.sources).filter(y=>p.has(y.key)).length,ce=Te(()=>{let y=new Map;for(let E of h){let me=JSON.stringify([E.source.adapter,X(E)]);y.set(me,(y.get(me)??0)+1)}return y},[h]);ua(()=>{k.current?.scrollTo({top:0})},[m.adapter,m.query,m.page]);let de=g&&h.some(y=>y.key===g)?g:null,T=y=>{x(null),m.setAdapter(y)},ye=y=>{x(null),m.setQuery(y)},U=y=>{x(null),m.setPage(y)},I;return r.sources.length===0&&a?I="\u6B63\u5728\u8BFB\u53D6\u989D\u5EA6\u2026":r.sources.length===0&&(o||r.error)?I="\u6682\u65F6\u65E0\u6CD5\u8BFB\u53D6\u989D\u5EA6\u6765\u6E90":r.sources.length===0?I="\u5C1A\u672A\u542F\u7528\u989D\u5EA6\u6765\u6E90\uFF0C\u8BF7\u5728\u201C\u8BBE\u7F6E \u2192 \u989D\u5EA6\u8BBE\u7F6E\u201D\u4E2D\u6DFB\u52A0\u3002":m.query||m.adapter?I="\u6CA1\u6709\u5339\u914D\u7684\u53EF\u89C1\u8BB0\u5F55":I="\u5F53\u524D\u989D\u5EA6\u5DF2\u5168\u90E8\u9690\u85CF",J(pa,{className:"quota-application","data-quota-application":"",children:[C("style",{children:Se}),C(lt,{sources:r.sources,locale:n.locale,adapter:m.adapter,query:m.query,onAdapter:T,onQuery:ye,actions:J(ga,{children:[C(ge,{size:"sm",variant:"secondary","data-quota-visibility":"",disabled:B===0,onClick:()=>q(!0),children:$>0?l(`\u663E\u793A\u9879 \xB7 ${$} \u9879\u9690\u85CF`,`Display items \xB7 ${$} hidden`):l("\u663E\u793A\u9879")}),C(ge,{size:"sm",variant:"secondary","data-quota-refresh":"",disabled:i||c,onClick:s,children:l(i||c?"\u5237\u65B0\u4E2D\u2026":"\u5237\u65B0")})]})}),J(ma,{className:"quota-record-scroll",viewportClassName:"quota-record-viewport",viewportRef:k,"aria-label":l("\u989D\u5EA6\u8BB0\u5F55"),children:[r.error?C(ft,{tone:"error",density:"compact",children:r.error}):null,o?C(ft,{tone:"error",density:"compact",children:o}):null,Q.length>0?J("details",{className:"quota-source-notices",children:[C("summary",{className:"quota-warning",children:l(`${Q.length} \u4E2A\u6765\u6E90\u5F02\u5E38`,`${Q.length} source errors`)}),C("div",{className:"quota-source-errors",children:Q.map(y=>J("div",{children:[C("strong",{children:y.name}),C("div",{className:"quota-error-text",children:y.error})]},y.sourceId))})]}):null,m.items.length===0?J(da,{density:"compact",children:[l(I),J("div",{className:"quota-actions quota-empty-actions",children:[m.query?C(ge,{size:"sm",variant:"ghost",onClick:()=>ye(""),children:l("\u6E05\u9664\u641C\u7D22")}):null,m.adapter?C(ge,{size:"sm",variant:"ghost",onClick:()=>T(""),children:l("\u5168\u90E8\u6E20\u9053")}):null,$>0?C(ge,{size:"sm",variant:"secondary",onClick:()=>q(!0),children:l("\u6062\u590D\u663E\u793A\u9879")}):null]})]}):m.items.map((y,E)=>J(la,{children:[m.items[E-1]?.source.adapter!==y.source.adapter?C("h2",{className:"quota-channel-heading",children:l(y.source.adapterLabel)}):null,C(ct,{record:y,now:d,region:n,resetTimeFormat:r.display.resetTimeFormat,expanded:de===y.key,duplicateName:(ce.get(JSON.stringify([y.source.adapter,X(y)]))??0)>1,onToggle:()=>x(de===y.key?null:y.key)})]},y.key))]}),C(ut,{locale:n.locale,page:m.page,pageCount:m.pageCount,total:m.total,onPage:U}),A?C(pt,{snapshot:r,host:e,signal:t,onClose:()=>q(!1)}):null]})}import{useMemo as wa,useState as xe}from"react";import{PluginAlert as De,PluginButton as _,PluginConfirmDialog as Sa,PluginEmptyState as kt,PluginInput as ka,PluginListItem as xa,PluginScroll as Be,PluginSelectField as xt,PluginSurface as Qa,PluginTab as Qt,PluginTabList as Pa}from"@jetcrab/pi-desk-sdk/react/base";import{useCallback as fe,useEffect as Le,useMemo as vt,useRef as V,useState as K}from"react";function le(e){return JSON.stringify(e.map(({draftKey:t,...r})=>r))}function ue(e,t){return`quota-${e.draftKey}-${t}`.replace(/[^a-zA-Z0-9_-]/g,"-")}function fa(e,t){let r=e.values[t.key]?.trim()??"";if(t.required&&!r)return`${t.label}\u4E0D\u80FD\u4E3A\u7A7A`;if(t.kind==="select"&&r&&!t.options.some(a=>a.value===r))return`${t.label}\u9009\u9879\u65E0\u6548`;if(t.kind==="url"&&r)try{new URL(r)}catch{return`${t.label}\u5FC5\u987B\u662F\u6709\u6548 URL`}return null}function ht(e,t,r){let[a,i]=K({error:null,adapters:[],sources:[],display:{resetTimeFormat:"countdown",hiddenItemKeys:[]}}),o=F(e).locale,[s,d]=K("countdown"),n=V(s),l=V(s),[p,h]=K([]),[m,g]=K([]),x=V(p),A=V(m),[q,k]=K(null),c=V(q),[Q,B]=K(!0),$=V(!1),[ce,de]=K(!1),T=V(!1),[ye,U]=K(null),[I,y]=K(null),[E,me]=K(!1),ae=V(null),Rt=u=>{T.current||(n.current=u,d(u))},Z=fe(u=>{c.current=u,k(u)},[]),re=fe(u=>{x.current=u,h(u)},[]),oe=fe(()=>le(x.current)!==le(A.current)||n.current!==l.current,[]),Qe=fe((u,v)=>{let N=u.sources.map(L=>({...structuredClone(L),draftKey:L.sourceId}));i(u),n.current=u.display.resetTimeFormat,l.current=u.display.resetTimeFormat,d(u.display.resetTimeFormat),A.current=N,g(N),re(N);let w=v??c.current;Z(N.some(L=>L.draftKey===w)?w:N[0]?.draftKey??null)},[re,Z]),ve=fe(async()=>{if(!(r.aborted||$.current||T.current||oe())){$.current=!0,B(!0),U(null);try{let u=await ee.loadSettings(e);!r.aborted&&!oe()&&!T.current&&Qe(u)}catch(u){r.aborted||U(u instanceof Error?u.message:String(u))}finally{$.current=!1,r.aborted||B(!1)}}},[Qe,e,oe,r]);Le(()=>{let u=!0;queueMicrotask(()=>{u&&ve()});let v=e.connection.subscribe(()=>{e.connection.getSnapshot().status==="ready"&&ve()});return()=>{u=!1,v()}},[e,ve]),Le(()=>(t.setBeforeLeave(()=>T.current?!1:oe()?new Promise(u=>{ae.current?.(!1),ae.current=u,me(!0)}):!0),()=>{t.setBeforeLeave(null),ae.current?.(!1),ae.current=null}),[oe,t]),Le(()=>{if(!I)return;let u=window.requestAnimationFrame(()=>{let v=document.getElementById(I.id);v?.focus(),v?.scrollIntoView({block:"nearest"})});return()=>window.cancelAnimationFrame(u)},[I]);let he=vt(()=>new Map(a.adapters.map(u=>[u.adapter,u])),[a.adapters]),Ie=vt(()=>{let u=new Map;for(let v of p){v.name.trim()||u.set(`${v.draftKey}:name`,"\u6765\u6E90\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A");let N=he.get(v.adapter);if(!N){u.set(`${v.draftKey}:adapter`,"\u5F53\u524D\u6E20\u9053\u4E0D\u53EF\u7528");continue}for(let w of N.fields){let L=fa(v,w);L&&u.set(`${v.draftKey}:${w.key}`,L)}}return u},[he,p]),Ct=u=>{let v=he.get(u);if(!v||T.current||x.current.length>=50)return;let N={draftKey:`draft-${crypto.randomUUID()}`,adapter:u,name:v.label,enabled:!0,values:Object.fromEntries(v.fields.map(w=>[w.key,w.defaultValue??""]))};re([...x.current,N]),Z(N.draftKey),y({id:ue(N,v.fields.find(w=>w.required)?.key??"name")})},At=u=>{T.current||re(x.current.map(v=>v.draftKey===c.current?u(v):v))},Tt=()=>{if(T.current)return;let u=x.current.findIndex(N=>N.draftKey===c.current),v=x.current.filter(N=>N.draftKey!==c.current);re(v),Z(v[Math.min(u,v.length-1)]?.draftKey??null)},Lt=()=>{if(T.current||$.current||!oe())return;let u=Ie.keys().next().value;if(u){let w=p.find(L=>u.startsWith(`${L.draftKey}:`));if(w){Z(w.draftKey);let L=u.slice(w.draftKey.length+1);y({id:ue(w,L==="adapter"?"name":L)})}return}T.current=!0,de(!0),U(null);let v=x.current,N=v.findIndex(w=>w.draftKey===c.current);ee.saveSources(e,v.map(({draftKey:w,...L})=>L),n.current!==l.current?n.current:void 0).then(w=>{r.aborted||(Qe(w,w.sources[N]?.sourceId),ne({...z(),display:w.display}),e.notify({level:"success",title:f(o,"\u989D\u5EA6\u8BBE\u7F6E\u5DF2\u4FDD\u5B58")}))}).catch(w=>{r.aborted||U(w instanceof Error?w.message:String(w))}).finally(()=>{T.current=!1,r.aborted||de(!1)})},Pe=p.find(u=>u.draftKey===q)??null;return{settings:a,draft:p,selected:Pe,selectedKey:q,descriptor:Pe?he.get(Pe.adapter):void 0,validationErrors:Ie,changedKeys:new Set(p.filter(u=>{let v=m.find(N=>N.draftKey===u.draftKey);return!v||le([u])!==le([v])}).map(u=>u.draftKey)),dirty:le(p)!==le(m)||s!==a.display.resetTimeFormat,loading:Q,saving:ce,error:ye,leaveOpen:E,resetTimeFormat:s,setResetTimeFormat:Rt,removedCount:m.filter(u=>!p.some(v=>v.sourceId===u.sourceId)).length,select:Z,add:Ct,update:At,remove:Tt,save:Lt,discard:()=>{if(T.current)return;let u=structuredClone(A.current);re(u),n.current=l.current,d(l.current),U(null),Z(u.some(v=>v.draftKey===c.current)?c.current:u[0]?.draftKey??null)},reload:()=>{ve()},finishLeave:u=>{let v=ae.current;ae.current=null,me(!1),v?.(u)}}}import{PluginAlert as ya,PluginCheckbox as va,PluginField as bt,PluginInput as qt,PluginSecretInput as ha,PluginSelectField as ba,PluginTextarea as qa}from"@jetcrab/pi-desk-sdk/react/base";import{jsx as O,jsxs as wt}from"react/jsx-runtime";function St({source:e,locale:t,descriptor:r,errors:a,disabled:i,onChange:o}){let s=n=>f(t,n),d=(n,l)=>{o({...e,values:{...e.values,[n]:l}})};return wt("div",{className:"quota-source-form","data-quota-settings-source":e.draftKey,children:[r?null:O(ya,{tone:"error",density:"compact",children:s("\u5F53\u524D\u6E20\u9053\u4E0D\u53EF\u7528\uFF0C\u53EF\u5220\u9664\u6B64\u6765\u6E90\u3002")}),O(bt,{label:s("\u663E\u793A\u540D\u79F0"),htmlFor:ue(e,"name"),error:a.get(`${e.draftKey}:name`),children:O(qt,{id:ue(e,"name"),value:e.name,maxLength:100,disabled:i,onChange:n=>o({...e,name:n.target.value})})}),wt("label",{className:"quota-source-enabled",children:[O(va,{checked:e.enabled,disabled:i,onChange:n=>o({...e,enabled:n.target.checked})}),s("\u542F\u7528\u6765\u6E90")]}),r?.fields.map(n=>{let l=ue(e,n.key),p=a.get(`${e.draftKey}:${n.key}`);if(n.kind==="select")return O(ba,{id:l,label:s(n.label),description:n.description,error:p,value:e.values[n.key]??"",disabled:i,options:n.options.map(m=>({...m,label:s(m.label)})),onValueChange:m=>d(n.key,m??"")},n.key);let h={id:l,value:e.values[n.key]??"",disabled:i,placeholder:n.placeholder,onChange:m=>d(n.key,m.target.value)};return O(bt,{label:s(n.label),htmlFor:l,description:n.description,error:p,className:["secret","url","textarea"].includes(n.kind)?"quota-field-wide":void 0,children:n.kind==="secret"?O(ha,{...h}):n.kind==="textarea"?O(qa,{...h}):O(qt,{...h,type:n.kind==="url"?"url":"text"})},n.key)})]})}import{Fragment as Na,jsx as b,jsxs as R}from"react/jsx-runtime";function Pt({host:e,target:t,signal:r}){let a=ht(e,t,r),i=F(e).locale,o=(c,Q)=>f(i,c,Q),[s,d]=xe(!1),[n,l]=xe(""),[p,h]=xe(!1),[m,g]=xe(!1),x=wa(()=>new Map(a.settings.adapters.map(c=>[c.adapter,c])),[a.settings.adapters]),A=a.draft.filter(c=>pe(n,c.name,x.get(c.adapter)?.label??c.adapter)),q=()=>{g(!0),h(!0)},k=()=>{l(""),g(!1),h(!0),a.save()};return R(Qa,{className:"quota-settings","data-quota-settings":"","data-editing":p||m||a.draft.length===0,children:[b("style",{children:Se}),R("div",{className:"quota-settings-head",children:[R(Pa,{label:o("\u989D\u5EA6\u8BBE\u7F6E","Quota settings"),children:[b(Qt,{active:!s,onClick:()=>d(!1),children:o("\u989D\u5EA6\u6765\u6E90")}),b(Qt,{active:s,onClick:()=>d(!0),children:o("\u663E\u793A\u8BBE\u7F6E")})]}),R("div",{className:"quota-actions",children:[b(_,{size:"sm",variant:"ghost",disabled:a.dirty||a.loading||a.saving,onClick:a.reload,children:o(a.loading?"\u52A0\u8F7D\u4E2D\u2026":"\u91CD\u65B0\u52A0\u8F7D")}),s?null:b(_,{size:"sm",variant:"secondary",disabled:a.loading||a.saving||a.draft.length>=50||a.settings.adapters.length===0,onClick:q,children:o("\u6DFB\u52A0\u6765\u6E90")})]})]}),s?R(Be,{className:"quota-editor-scroll",viewportClassName:"quota-display-settings","aria-label":o("\u663E\u793A\u8BBE\u7F6E"),children:[a.settings.error||a.error?b(De,{tone:"error",density:"compact",children:a.error??a.settings.error}):null,b(xt,{label:o("\u91CD\u7F6E\u65F6\u95F4\u683C\u5F0F"),value:a.resetTimeFormat,disabled:a.loading||a.saving,options:[{value:"countdown",label:o("\u5012\u8BA1\u65F6")},{value:"absolute",label:o("\u5177\u4F53\u65F6\u95F4")}],onValueChange:c=>{(c==="countdown"||c==="absolute")&&a.setResetTimeFormat(c)}})]}):R("div",{className:"quota-settings-body","data-empty":a.draft.length===0,children:[R("aside",{className:"quota-settings-navigation","aria-label":o("\u989D\u5EA6\u6765\u6E90\u5BFC\u822A"),children:[b(ka,{"aria-label":o("\u641C\u7D22\u6765\u6E90"),placeholder:o("\u641C\u7D22\u6765\u6E90"),value:n,onChange:c=>l(c.target.value)}),b(Be,{className:"quota-source-navigation-scroll",viewportClassName:"quota-source-navigation-viewport","aria-label":o("\u6765\u6E90\u5217\u8868"),children:A.length===0?b(kt,{density:"compact",children:o(a.loading?"\u6B63\u5728\u8BFB\u53D6\u2026":"\u6CA1\u6709\u5339\u914D\u6765\u6E90")}):j(A).map(c=>R("div",{className:"quota-source-group",children:[b("h3",{className:"quota-source-group-title",children:o(x.get(c[0].adapter)?.label??c[0].adapter)}),c.map(Q=>{let B=[...a.validationErrors.keys()].some(ce=>ce.startsWith(`${Q.draftKey}:`)),$=a.changedKeys.has(Q.draftKey);return R(xa,{density:"compact",className:"quota-source-item","data-quota-settings-nav-source":Q.draftKey,selected:!m&&a.selectedKey===Q.draftKey,disabled:a.saving,onClick:()=>{a.select(Q.draftKey),g(!1),h(!0)},children:[b("span",{className:"quota-truncate",children:Q.name.trim()||o("\u672A\u547D\u540D\u6765\u6E90")}),b("span",{className:B?"quota-warning quota-source-item-state":"quota-meta quota-source-item-state",children:o(B?"\u5F85\u5B8C\u5584":$?"\u672A\u4FDD\u5B58":Q.enabled?"\u542F\u7528":"\u505C\u7528")})]},Q.draftKey)})]},c[0].adapter))})]}),R(Be,{className:"quota-editor-scroll",viewportClassName:"quota-editor-viewport","aria-label":o("\u6765\u6E90\u7F16\u8F91"),children:[a.draft.length>0?b(_,{size:"sm",variant:"ghost",className:"quota-back",disabled:a.saving,onClick:()=>{h(!1),g(!1)},children:o("\u8FD4\u56DE\u6765\u6E90")}):null,a.settings.error?b(De,{density:"compact",tone:"error",children:a.settings.error}):null,a.error?b(De,{density:"compact",tone:"error",children:a.error}):null,m?R("div",{className:"quota-add-source",children:[R("div",{className:"quota-editor-head",children:[b("h3",{className:"quota-section-title",children:o("\u6DFB\u52A0\u6765\u6E90")}),b(_,{size:"sm",variant:"ghost",onClick:()=>g(!1),children:o("\u53D6\u6D88")})]}),b(xt,{label:o("\u6E20\u9053"),value:null,placeholder:o("\u9009\u62E9\u6E20\u9053"),options:a.settings.adapters.map(c=>({value:c.adapter,label:o(c.label)})),onValueChange:c=>{c&&(a.add(c),g(!1),l(""))}})]}):a.selected?R(Na,{children:[R("div",{className:"quota-editor-head",children:[R("div",{className:"quota-editor-title",children:[b("h3",{className:"quota-section-title",children:a.selected.name.trim()||o("\u672A\u547D\u540D\u6765\u6E90")}),a.selected.name!==a.descriptor?.label?b("span",{className:"quota-meta",children:a.descriptor?.label??a.selected.adapter}):null]}),b(_,{size:"sm",variant:"danger",disabled:a.saving,onClick:a.remove,children:o("\u5220\u9664\u6765\u6E90")})]}),b(St,{source:a.selected,locale:i,descriptor:a.descriptor,errors:a.validationErrors,disabled:a.saving,onChange:c=>a.update(()=>c)})]}):R(kt,{density:"compact",children:[o(a.loading?"\u6B63\u5728\u8BFB\u53D6\u989D\u5EA6\u6765\u6E90\u2026":"\u5C1A\u672A\u914D\u7F6E\u989D\u5EA6\u6765\u6E90"),!a.loading&&a.settings.adapters.length>0?b(_,{size:"sm",variant:"secondary",onClick:q,children:o("\u6DFB\u52A0\u6765\u6E90")}):null]})]})]}),R("footer",{className:"quota-settings-footer",children:[b("div",{className:"quota-meta",role:"status",children:a.removedCount>0?o(`\u5DF2\u79FB\u9664 ${a.removedCount} \u4E2A\u6765\u6E90\uFF0C\u4FDD\u5B58\u540E\u751F\u6548`,`${a.removedCount} sources will be removed on save`):a.dirty?o("\u6709\u672A\u4FDD\u5B58\u66F4\u6539"):null}),R("div",{className:"quota-actions",children:[a.dirty?b(_,{size:"sm",variant:"ghost",disabled:a.saving,onClick:()=>{a.discard(),g(!1)},children:o("\u653E\u5F03\u66F4\u6539")}):null,b(_,{variant:"primary","data-quota-settings-save":"",disabled:!a.dirty||a.saving||a.loading,onClick:k,children:o(a.saving?"\u4FDD\u5B58\u4E2D\u2026":"\u4FDD\u5B58\u5168\u90E8\u66F4\u6539")})]})]}),b(Sa,{open:a.leaveOpen,title:o("\u653E\u5F03\u672A\u4FDD\u5B58\u7684\u66F4\u6539\uFF1F"),description:o("\u989D\u5EA6\u8BBE\u7F6E\u6709\u672A\u4FDD\u5B58\u7684\u66F4\u6539\u3002"),confirmLabel:o("\u653E\u5F03\u66F4\u6539"),tone:"danger",onConfirm:()=>a.finishLeave(!0),onOpenChange:c=>{c||a.finishLeave(!1)}})]})}import{jsx as $e}from"react/jsx-runtime";function Nt(e,t,r){let a=Ra(e);return a.render($e(Ca,{onError:r,children:t})),()=>a.unmount()}var Ur={mount({container:e,host:t,signal:r}){return Nt(e,$e(yt,{host:t,signal:r}),a=>{t.notify({level:"error",title:"\u989D\u5EA6\u9875\u9762\u6E32\u67D3\u5931\u8D25",description:a.message})})}},Zr={mount({container:e,target:t,host:r,signal:a}){return Nt(e,$e(Pt,{target:t,host:r,signal:a}),i=>{r.notify({level:"error",title:"\u989D\u5EA6\u8BBE\u7F6E\u6E32\u67D3\u5931\u8D25",description:i.message})})}};export{Ur as quotaApplication,Zr as quotaSettingsPage};