dsh-cost-meter 1.9.47 → 1.9.49

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.
@@ -1,4 +1,4 @@
1
- window.__ModuleLoader__.load({id:"dsh-cost-meter",chunk:"client.pricing.js",factory:le=>{const{createElement:e,Fragment:me,useState:O,useEffect:te,useLayoutEffect:re,useMemo:Z,useRef:ae,useId:ve}=le("react");let oe=null;try{oe=le("react-dom")?.createPortal??null}catch{}const ye=["at","before","after","days","sessions","skipped"],ke=a=>["deepseek-official:deepseek-web-search","deepseek-official:deepseek-web-fetch","deepseek-official:deepseek-search-api","deepseek-official:deepseek-fetch-api","deepseek-official:deepseek-search-server"].includes(a),ie={parse:a=>{if(!Array.isArray(a)||!a.every(r=>ye.every(m=>Number.isFinite(r?.[m])&&r[m]>=0)&&(r.model===void 0||typeof r.model=="string")))throw new Error("Invalid recalculation history");return a}},se={parse:a=>{if(typeof a?.ok!="boolean"||typeof a?.message!="string")throw new Error("Invalid recalculation result");return a}},ce={parse:a=>{if(typeof a!="boolean")throw new Error("Expected confirmation");return a}},de={parse:a=>{if(typeof a!="string"||a.length>2048||a.indexOf(":")<=0||a.endsWith(":")||/[\r\n]/.test(a))throw new Error("Expected channel/model");return a}},pe={parse:a=>{if(!a||typeof a!="object"||Array.isArray(a))throw new Error("Invalid price catalog");return a}},G=(a,r)=>({mode:"strict",typeSymbol:"dsh-cost-meter#"+a,schema:r,create:()=>r}),ue={package:"dsh-cost-meter-pricing",face:"host",descriptors:[{id:"dsh-cost-meter#costMeter/getPriceCatalog",service:"costMeter",namespace:"costMeter",method:"getPriceCatalog",invocation:{kind:"direct"},parameters:[],result:G("PriceCatalog",pe)},{id:"dsh-cost-meter#costMeter/getRepricingHistory",service:"costMeter",namespace:"costMeter",method:"getRepricingHistory",invocation:{kind:"direct"},parameters:[],result:G("RepricingHistory",ie)},{id:"dsh-cost-meter#costMeter/repriceHistory",service:"costMeter",namespace:"costMeter",method:"repriceHistory",invocation:{kind:"direct"},parameters:[{name:"confirmed",wire:"confirmed",source:"json",codec:G("RepricingConfirmation",ce)}],result:G("FetchPricesResult",se)},{id:"dsh-cost-meter#costMeter/repriceModelHistory",service:"costMeter",namespace:"costMeter",method:"repriceModelHistory",invocation:{kind:"direct"},parameters:[{name:"confirmed",wire:"confirmed",source:"json",codec:G("RepricingConfirmation",ce)},{name:"model",wire:"model",source:"json",codec:G("RepricingModel",de)}],result:G("FetchPricesResult",se)}]},Ne=a=>(a.label+" "+a.value).toLowerCase();function ne({options:a,value:r,placeholder:m,label:v,ariaLabel:t,locale:o,onChange:d}){const f=o==="en",u=ve(),p=u+"-list",[w,s]=O(""),[b,c]=O(!1),[g,x]=O(0),[N,H]=O(null),C=ae(null),y=ae(null),k=ae(null),P=a.find(l=>l.value===r),M=w.toLowerCase().trim().split(/\s+/).filter(Boolean),S=Z(()=>a.map(l=>({option:l,search:Ne(l)})),[a]),L=l=>{const _=l.toLowerCase().trim().split(/\s+/).filter(Boolean);return _.length?S.filter(I=>_.every(i=>I.search.includes(i))).map(I=>I.option):a},h=L(w),D=P&&!h.includes(P)?[P,...h]:h,B=Math.max(0,Math.min(g,D.length-1)),U=()=>{c(!1),s("")},$=()=>{b||(H(null),s(""),x(Math.max(0,D.findIndex(l=>l.value===r))),c(!0))},n=l=>{l&&(l.value!==r&&d(l.value),U())},T=()=>{if(b&&w){s(""),x(0);return}r&&d(""),U()};re(()=>{if(!b||typeof document>"u")return;const l=y.current,_=typeof window>"u"?null:window,I=()=>{const i=l?.getBoundingClientRect?.();if(!i||!_)return;const A=_.innerHeight,j=12,E=A-i.bottom-j,F=i.top-j,R=E<180&&F>E,V=Math.max(60,R?F:E),q=Math.max(0,Math.min(280,V,A-j*2)),ee=Math.max(j,Math.min(R?i.top-q-6:i.bottom+6,A-q-j));H(K=>K&&K.left===i.left&&K.top===ee&&K.width===i.width&&K.maxHeight===q?K:{left:i.left,top:ee,width:i.width,maxHeight:q})};if(I(),typeof _?.addEventListener=="function")return _.addEventListener("scroll",I,!0),_.addEventListener("resize",I),()=>{_.removeEventListener("scroll",I,!0),_.removeEventListener("resize",I)}},[b]),te(()=>{if(!b||typeof document>"u"||typeof document.addEventListener!="function")return;const l=_=>{C.current?.contains?.(_.target)||k.current?.contains?.(_.target)||U()};return document.addEventListener("pointerdown",l,!0),()=>document.removeEventListener("pointerdown",l,!0)},[b]),re(()=>{!b||!N||k.current?.querySelector?.('[data-active="true"]')?.scrollIntoView?.({block:"nearest"})},[b,B,N,w]);const W=l=>u+"-opt-"+l,X=M.length?h.length?f?`${h.length} matches`:`${h.length} 个结果`:D.length?f?"No matches · showing the current choice":"没有匹配的模型 · 下面是当前选择":f?"No matches":"没有匹配的模型":null,Y=b?e("div",{ref:k,className:"cm-combo-panel",style:N??{visibility:"hidden"}},D.length?e("div",{className:"cm-combo-list",id:p,role:"listbox","aria-label":v},D.map((l,_)=>e("button",{key:l.value,id:W(_),type:"button",role:"option",className:"cm-combo-option"+(_===B?" active":""),"data-active":String(_===B),"aria-selected":String(l.value===r),onMouseEnter:()=>x(_),onMouseDown:I=>I.preventDefault(),onClick:()=>n(l)},l.label))):null,X?e("p",{className:"cm-combo-note",role:"status"},X):null):null;return e("div",{ref:C,className:"cm-price-search cm-combo"},e("div",{className:"cm-combo-control"},e("input",{ref:y,type:"search",className:"cm-input cm-combo-input",autoComplete:"off",value:b?w:P?.label??"",role:"combobox","aria-expanded":String(b),"aria-autocomplete":"list","aria-controls":b&&D.length?p:void 0,"aria-activedescendant":b&&D.length?W(B):void 0,"aria-label":t??v+(f?" · Price model":" · 价格模型"),placeholder:b&&P?P.label:m,onFocus:$,onClick:()=>{b||$()},onChange:l=>{const _=l.target.value,I=!b&&P&&_.startsWith(P.label)?_.slice(P.label.length):_,i=L(I);s(I),c(!0),x(P&&i.length>0&&!i.includes(P)?1:0)},onKeyDown:l=>{if(!l.nativeEvent?.isComposing){if(l.key==="Escape"){if(l.preventDefault(),!b)return;U(),l.stopPropagation();return}if(l.key==="ArrowDown"||l.key==="ArrowUp"){if(l.preventDefault(),!b){$();return}x(Math.max(0,Math.min(D.length-1,B+(l.key==="ArrowDown"?1:-1))));return}if(l.key==="Enter"&&b&&D[B]){l.preventDefault(),n(D[B]);return}l.key==="Tab"&&U()}}}),r||w?e("button",{type:"button",className:"cm-combo-clear","aria-label":(f?"Clear ":"清空 ")+v,onMouseDown:l=>l.preventDefault(),onClick:T},"×"):null,e("button",{type:"button",className:"cm-combo-caret",tabIndex:-1,"aria-hidden":"true",onMouseDown:l=>l.preventDefault(),onClick:()=>{b?U():(y.current?.focus?.(),$())}},"▾")),Y&&oe?oe(Y,document.body):Y)}function ge({state:a,draft:r,setDraft:m,locale:v,rpc:t}){const[o,d]=O(!1),[f,u]=O(null),[p,w]=O(""),[s,b]=O(""),[c,g]=O(0),x=a.config.prices.currency??"USD",N=v==="en";te(()=>{if(!o)return;let k=!0;return u(null),b(""),w(""),t("getPriceCatalog").then(P=>{k&&u(P)},P=>{k&&b(String(P.message??P))}),()=>{k=!1}},[o,x,c,t]);const H=[];for(const[k,P]of Object.entries(f??{}))for(const M of Object.values(P))for(const[S,L]of Object.entries(M))!(k==="deepseek"?r?.prices.models[S]:r?.prices.providers?.[k]?.models?.[S])&&!L.unpriced&&H.push({value:k+":"+S,label:k+" · "+S,provider:k,id:S,entry:L});const C=H.find(k=>k.value===p),y=()=>{if(!C||!r)return;const{provider:k,id:P,entry:M}=C,S=JSON.parse(JSON.stringify(M)),L=r.prices;m({...r,prices:k==="deepseek"?{...L,models:{...L.models,[P]:S}}:{...L,providers:{...L.providers,[k]:{...L.providers?.[k],models:{...L.providers?.[k]?.models,[P]:S}}}}}),w("")};return e("div",{className:"cm-restore-prices"},e("button",{type:"button",className:"cm-btn small","aria-expanded":o,onClick:()=>d(k=>!k)},o?N?"Close restore":"收起恢复入口":N?"Restore bundled model":"恢复内置模型"),o?e("div",{className:"cm-collapse-body"},s?e("div",{role:"alert",className:"cm-err"},s,e("button",{type:"button",className:"cm-btn small",onClick:()=>g(k=>k+1)},N?"Retry":"重试")):f===null?e("p",{role:"status",className:"cm-hint"},N?"Loading prices…":"读取价格…"):H.length?e(me,null,e(ne,{options:H,value:C?p:"",placeholder:N?"Select a model":"选择模型",label:N?"Restore model":"恢复模型",locale:v,onChange:w}),e("button",{type:"button",className:"cm-btn small",disabled:!C,onClick:y},N?"Restore":"恢复")):e("p",{className:"cm-hint"},N?"All bundled models are mounted.":"内置模型均已挂载。")):null)}function Ce(a){const{state:r,draft:m,setDraft:v,t}=a,{peakPhaseAt:o,resolveLocale:d,peakNoticeEl:f}=a.peakHelpers,u=r.config,p=(c,g)=>{m!==null&&v({...m,[c]:g})},w=m===null?u:{...u,...m},s=(()=>{if(w.peakEnabled!==!0)return t("peakOff");const c=Date.parse(w.peakEffectiveAt||""),g=Date.now();if(Number.isFinite(c)&&g<c)return t("peakNotEffective",{time:new Date(c).toLocaleString()});const x=w.peakWindows??[],N=o(g,x,w.peakHolidays);return N===null?t("offPeakActive"):N.holiday===!0?t("holidayAllOffPeak"):N.weekend===!0?t("weekendAllOffPeak"):N.inPeak?t("peakActive"):t("offPeakActive")})(),b=(w.peakWindows?.length??0)>0?t("peakSummary",{windows:w.peakWindows.map(c=>c.start+":00-"+c.end+":00").join(d(w)==="zh"?"、":", "),time:w.peakEffectiveAt||t("unknown"),status:s}):t("noPeakWindows",{status:s});return e("div",{className:"cm-budget"},e("div",{className:"cm-budget-head"},e("h3",{className:"cm-h"},t("peakPanelTitle")),e("label",{className:"cm-check"},e("input",{type:"checkbox",checked:m?.peakEnabled!==!1,onChange:c=>p("peakEnabled",c.target.checked)}),e("span",null,t("peakEnabledLabel")))),e("div",{className:"cm-grid"},e("div",{className:"cm-field"},e("label",{className:"cm-check"},e("input",{type:"checkbox",checked:m?.peakNotice!==!1,onChange:c=>p("peakNotice",c.target.checked)}),e("span",null,t("peakNoticeLabel")))),e("div",{className:"cm-field"},e("label",null,t("peakStyleLabel")),e("select",{className:"cm-input",value:m?.peakStyle??"compact",onChange:c=>p("peakStyle",c.target.value)},e("option",{value:"progress"},d(m)==="en"?"Time progress":"时间进度条"),e("option",{value:"compact"},t("peakStyleCompact")),e("option",{value:"classic"},t("peakStyleClassic"))))),e("div",{className:"cm-grid"},e("div",{className:"cm-field"},e("label",{className:"cm-check"},e("input",{type:"checkbox",checked:m?.peakAlertEnabled!==!1,onChange:c=>p("peakAlertEnabled",c.target.checked)}),e("span",null,t("peakAlertLabel")))),e("div",{className:"cm-field"},e("label",null,t("peakAlertAheadLabel")),e("input",{className:"cm-input narrow",type:"number",min:"1",max:"30",step:"1",value:String(typeof m?.peakAlertAhead=="number"&&Number.isFinite(m.peakAlertAhead)&&m.peakAlertAhead>=1&&m.peakAlertAhead<=30?m.peakAlertAhead:2),onChange:c=>{const g=Number(c.target.value);Number.isInteger(g)&&g>=1&&g<=30&&p("peakAlertAhead",g)}})),e("div",{className:"cm-field"},e("label",null,t("peakAlertTargetLabel")),e("select",{className:"cm-input",value:m?.peakAlertTarget==="peak"||m?.peakAlertTarget==="offpeak"?m.peakAlertTarget:"both",onChange:c=>p("peakAlertTarget",c.target.value)},e("option",{value:"both"},t("peakAlertTargetBoth")),e("option",{value:"peak"},t("peakAlertTargetPeak")),e("option",{value:"offpeak"},t("peakAlertTargetOffPeak"))))),e("div",{className:"cm-grid"},e("div",{className:"cm-field"},e("label",null,t("peakAlertPositionLabel")),e("select",{className:"cm-input",value:m?.peakAlertPosition==="center"?"center":"corner",onChange:c=>p("peakAlertPosition",c.target.value)},e("option",{value:"corner"},t("peakAlertPositionCorner")),e("option",{value:"center"},t("peakAlertPositionCenter")))),e("div",{className:"cm-field"},e("label",{className:"cm-check"},e("input",{type:"checkbox",checked:m?.peakAlertWebNotify===!0,onChange:c=>{p("peakAlertWebNotify",c.target.checked),c.target.checked&&window.Notification&&Notification.permission==="default"&&Promise.resolve(Notification.requestPermission()).catch(()=>{})}}),e("span",null,t("peakAlertWebNotifyLabel"))),e("p",{className:"cm-hint"},t("peakAlertWebNotifyHint")))),e("div",{className:"cm-field"},e("label",null,t("peakAlertPreviewLabel")),e("div",{className:"cm-row"},e("button",{className:"cm-btn",onClick:()=>window.cmPeakAlertPreview?.("peak")},t("peakAlertPreviewPeak")),e("button",{className:"cm-btn",onClick:()=>window.cmPeakAlertPreview?.("offpeak")},t("peakAlertPreviewOffPeak")))),e("div",{className:"cm-peak-preview"},m?.peakEnabled!==!1&&m?.peakNotice!==!1?f(r,w,t):e("p",{className:"cm-hint"},t("peakNoticeHiddenHint"))),e("p",{className:"cm-hint"},b),e("div",{className:"cm-field"},e("label",null,t("peakHolidaysLabel")),e("input",{className:"cm-input",defaultValue:(w.peakHolidays??[]).join(", "),onBlur:c=>p("peakHolidays",c.target.value.split(/[,,\s]+/).filter(Boolean))})),e("p",{className:"cm-hint"},t("weekendRuleNote")))}function he({value:a,onChange:r,locale:m,defaults:v=[]}){const t=m==="en",o=a.peakWindows,d=c=>c.map(g=>g.start+"-"+g.end).join(", "),[f,u]=O(()=>d(o??v)),[p,w]=O("");te(()=>u(d(o??v)),[JSON.stringify(o),JSON.stringify(v)]);const s=(c,g)=>{const x={...a};g===void 0?delete x[c]:x[c]=g,r(x)},b=()=>{const g=(f.trim()?f.split(/[,,]/).map(x=>x.trim()):[]).map(x=>{const N=x.match(/^(\d+(?:\.\d+)?)\s*-\s*(\d+(?:\.\d+)?)$/);return N?{start:Number(N[1]),end:Number(N[2])}:null});if(g.length>24||g.some(x=>!x||x.start>=24||x.end>24||x.start===x.end)){w(t?"Use UTC hours, e.g. 1-4, 6-10 or 22-2.":"填写 UTC 小时,例如 1-4, 6-10,跨午夜可填 22-2。");return}w(""),s("peakWindows",g)};return e("fieldset",{className:"cm-peak-schedule"},e("legend",null,t?"Peak schedule":"峰谷时段"),e("label",{className:"cm-check"},e("input",{type:"checkbox",checked:o!==void 0,onChange:c=>{w(""),s("peakWindows",c.target.checked?structuredClone(v):void 0)}}),t?"Override peak hours":"自定义峰时段"),o!==void 0?e("label",{className:"cm-field"},t?"Peak hours (UTC)":"峰时段(UTC)",e("input",{className:"cm-input",value:f,onChange:c=>u(c.target.value),onBlur:b,onKeyDown:c=>{c.key==="Enter"&&(c.preventDefault(),b())}})):null,e("label",{className:"cm-field"},t?"Calendar":"日历规则",e("select",{className:"cm-input","aria-label":t?"Calendar":"日历规则",value:a.peakSchedule??"",onChange:c=>s("peakSchedule",c.target.value||void 0)},...[["","沿用上级/渠道默认","Inherit channel/default"],["daily","每天","Every day"],["deepseek","北京时间工作日","Beijing weekdays"],["utc-weekdays","UTC 工作日","UTC weekdays"],["ollama","Ollama Cloud","Ollama Cloud"],["volcengine","火山方舟","Volcano Ark"]].map(([c,g,x])=>e("option",{key:c,value:c},t?x:g)))),e("label",{className:"cm-field"},t?"Holidays":"节假日",e("select",{className:"cm-input","aria-label":t?"Holidays":"节假日",value:a.peakHolidays===null?"none":Array.isArray(a.peakHolidays)?"custom":"inherit",onChange:c=>s("peakHolidays",c.target.value==="none"?null:c.target.value==="custom"?[]:void 0)},e("option",{value:"inherit"},t?"Inherit":"沿用上级/渠道默认"),e("option",{value:"none"},t?"No holiday table":"不使用节假日表"),e("option",{value:"custom"},t?"Custom dates":"自定义日期"))),Array.isArray(a.peakHolidays)?e("label",{className:"cm-field"},t?"Off-peak Beijing dates":"全天谷价日期(北京时间)",e("input",{className:"cm-input",key:JSON.stringify(a.peakHolidays),defaultValue:a.peakHolidays.join(", "),placeholder:"2026-11-01, 2026-11-02",onBlur:c=>{const g=c.target.value.split(/[,,\s]+/).filter(Boolean);if(g.length>366||g.some(x=>!/^\d{4}-\d{2}-\d{2}$/.test(x)||!Number.isFinite(Date.parse(x+"T00:00:00Z"))||new Date(x+"T00:00:00Z").toISOString().slice(0,10)!==x)){w(t?"Use valid YYYY-MM-DD dates.":"请填写有效的 YYYY-MM-DD 日期。");return}w(""),s("peakHolidays",[...new Set(g)].sort())}})):null,p?e("p",{className:"cm-err",role:"alert"},p):null,e("p",{className:"cm-hint"},t?"Hours use UTC; Beijing time is UTC + 8. Windows include the start and exclude the end. Empty hours mean all off-peak. Model settings override channel settings.":"小时采用 UTC,北京时间减 8 小时后填写。包含起点、不含终点,时段留空表示全天谷价。模型设置优先于渠道设置。"))}function fe({value:a,onChange:r,locale:m,defaults:v}){const t=m==="en",o=a.billingMode==="deepseek-peak"||!!(a.peak||a.offPeak),d={cacheMiss:a.cacheMiss??a.input??0,cacheHit:a.cacheHit??a.cachedInput??a.input??0,output:a.output??0};return e("details",{className:"cm-custom-more"},e("summary",null,t?"Peak / off-peak pricing":"峰谷价格与时段"),e("label",{className:"cm-check"},e("input",{type:"checkbox",checked:o,onChange:f=>{const u={...a,billingMode:f.target.checked?"deepseek-peak":"flat"};f.target.checked?(u.peak=a.peak??{...d},u.offPeak=a.offPeak??{...d}):(delete u.peak,delete u.offPeak),r(u)}}),t?"Enable peak / off-peak prices":"启用峰谷价格"),o?e(me,null,...["peak","offPeak"].map(f=>e("fieldset",{key:f},e("legend",null,f==="peak"?t?"Peak":"峰价":t?"Off-peak":"谷价"),e("div",{className:"cm-custom-grid"},...[["cacheMiss","输入","Input"],["cacheHit","缓存读取","Cached input"],["output","输出","Output"],["cacheWrite","缓存写入","Cache write"],["reasoning","单独推理","Reasoning"]].map(([u,p,w])=>e("label",{key:u},t?w:p,e("input",{type:"number",min:0,step:"any",className:"cm-input",value:a[f]?.[u]??"",onChange:s=>{const b={...a,[f]:{...d,...a[f]}};if(s.target.value==="")if(["cacheWrite","reasoning"].includes(u))delete b[f][u];else return;else if(Number.isFinite(s.target.valueAsNumber)&&s.target.valueAsNumber>=0)b[f][u]=s.target.valueAsNumber;else return;r(b)}})))))),e(he,{value:a,onChange:r,locale:m,defaults:v})):null)}function Me({state:a,draft:r,setDraft:m,locale:v}){const t=v==="en",o=r??a.config,[d,f]=O("deepseek"),u=d.trim().toLowerCase().replace(/^llm-/,""),p=o.prices?.providers?.[u]??{models:{}},w=[...new Set(["deepseek",...Object.keys(o.prices?.providers??{}),...Object.keys(a.today?.byProviderModel??{}).map(s=>s.split(":")[0])])].sort();return e("details",{className:"cm-provider-schedules"},e("summary",null,t?"Channel peak schedules":"按渠道设置峰谷时段"),e("label",{className:"cm-field"},t?"Provider ID":"渠道 ID",e("input",{className:"cm-input",list:"cm-peak-providers",value:d,onChange:s=>f(s.target.value)})),e("datalist",{id:"cm-peak-providers"},...w.map(s=>e("option",{key:s,value:s}))),/^[a-z0-9][a-z0-9_.-]{0,99}$/.test(u)&&!["constructor","prototype","__proto__"].includes(u)?e(he,{key:u,value:p,locale:v,defaults:u==="ollama-cloud"?[{start:12,end:18}]:o.peakWindows,onChange:s=>m({...o,prices:{...o.prices,providers:{...o.prices.providers,[u]:s}}})}):null,e("p",{className:"cm-hint"},t?"Use the channel ID from model pricing. Applies to peak-enabled models and is retained when official prices sync.":"填写模型定价中显示的渠道 ID。规则用于已启用峰谷价格的模型,同步官方价格时会保留。"))}function Pe({value:a,label:r,locale:m,onChange:v,t,priceEditor:o}){const d=m==="en",{PriceInput:f,priceFactor:u,setPriceFactor:p,multiplierOptions:w}=o,s=[["cacheMiss",d?"Input · cache miss":"输入 · 未命中缓存"],["cacheHit",d?"Cached input":"缓存读取"],["output",d?"Output":"输出"],["cacheWrite",d?"Cache write":"缓存写入"],["reasoning",d?"Separate reasoning":"单独推理费用"]],b=(g,x,N)=>{const H={...a};x===null?delete H[g]:H[g]=x,p(H,"base."+g,N),v(H)},c=([g,x])=>e("label",{key:g},x,e("span",{className:"cm-custom-amount"},e("span",{"aria-hidden":!0},a.currency==="CNY"?"¥":"$"),e(f,{entry:a,value:a[g]??null,path:"base."+g,t,emptyMode:["cacheWrite","reasoning"].includes(g)?"clear":"ignore",label:r+" · "+x,placeholder:g==="cacheWrite"?d?"Same as cached input":"跟随缓存读取":g==="reasoning"?d?"Included in output":"含在输出中":"0",onCommit:(N,H)=>b(g,N,H)})));return e("fieldset",{className:"cm-custom-price","aria-label":r+(d?" · Custom price":" · 自定义价格")},e("legend",null,d?"Custom price · per 1M tokens":"自定义价格 · 每百万 Token"),e("div",{className:"cm-custom-head"},e("span",null,d?"Only this channel and model":"仅用于此渠道的这个模型"),e("label",null,d?"Currency":"币种",e("select",{className:"cm-input",value:a.currency,onChange:g=>v({...a,currency:g.target.value})},e("option",{value:"USD"},d?"USD · US dollar":"USD · 美元"),e("option",{value:"CNY"},d?"CNY · Yuan":"CNY · 人民币")))),e("div",{className:"cm-custom-grid"},...s.slice(0,3).map(c)),w(a,t,g=>v({...a,separateMultipliers:g,multipliers:{}})),e(fe,{value:a,onChange:v,locale:m,defaults:[{start:1,end:4},{start:6,end:10}]}),e("div",{className:"cm-custom-effective",role:"status"},e("div",{className:"cm-effective-heading"},e("span",null,d?"Effective prices":"实际单价"),e("small",null,d?"Price × multiplier / 1M tokens":"单价 × 倍率 / 百万 Token")),e("div",{className:"cm-effective-grid"},...s.slice(0,3).map(([g,x])=>e("div",{key:g},e("span",null,x),e("strong",null,(a.currency==="CNY"?"¥":"$")+Number((a[g]*u(a,"base."+g)).toPrecision(8)).toLocaleString(d?"en-US":"zh-CN",{maximumFractionDigits:8})))))),e("details",{className:"cm-custom-more"},e("summary",null,d?"More billing fields":"更多计费项"),e("div",{className:"cm-custom-grid"},...s.slice(3).map(c)),e("p",{className:"cm-hint"},d?"Leave reasoning blank when it is included in output. Leave cache write blank to use the cached input rate.":"推理已包含在输出中时无需另填。缓存写入留空则使用缓存读取价格。")),e("p",{className:"cm-hint"},d?"Enter or leave a field to save. Switching the price source keeps your custom values.":"回车或离开输入框后保存;切换价格来源会保留已填的自定义价格。"))}function be({entry:a,currency:r,priceEditor:m,locale:v,local:t=!1}){const o=v==="en",d=a?m?.priceAt?.(a)??a:null;return e("span",{className:"cm-rate-summary"},...[["cacheMiss","input",o?"Input":"输入"],["cacheHit","cachedInput",o?"Cached input":"缓存读取"],["output","output",o?"Output":"输出"]].map(([u,p,w])=>{const s=t?0:d?.unpriced?null:d?.[u]??d?.[p],b=s==null?null:s*(m?.priceFactor?.(d??{},"base."+u)??1);return e("span",{key:u,className:"cm-rate-item"},e("span",null,w),e("strong",null,b===null?"—":(r==="CNY"?"¥":"$")+Number(b.toPrecision(8)).toLocaleString(o?"en-US":"zh-CN",{maximumFractionDigits:8})))}))}function _e({state:a,draft:r,setDraft:m,locale:v}){if(a.ourFreeModel?.enabled!==!0)return null;const t=v==="en",o=r?.priceOverrides??a.config.priceOverrides??{},d=["our-free-model:*","our-free-model-region:*"],f=d.every(u=>o[u]==="__free__");return e("section",{className:"cm-free-model","aria-label":"dsh-our-free-model"},e("label",{className:"cm-check"},e("input",{type:"checkbox",role:"switch",checked:f,onChange:u=>{if(!r)return;const p={...o};for(const w of d)u.target.checked?p[w]="__free__":p[w]==="__free__"&&delete p[w];m({...r,priceOverrides:p})}}),e("span",null,t?"Count dsh-our-free-model calls as free":"dsh-our-free-model 调用按免费计算")),e("p",{className:"cm-hint"},t?"Future calls through this plugin cost 0; tokens are still counted. Historical costs and other providers stay unchanged.":"仅此插件后续调用记为免费,Token 照常统计;历史费用和其他渠道不变。"))}function Se({state:a,draft:r,setDraft:m,t:v,locale:t,resolveClientPrice:o,prettyProviderKey:d,setField:f,priceEditor:u}){const[p,w]=O(""),[s,b]=O(24),[c,g]=O(null),[x,N]=O({}),H=ae(new Map),C=ae(null),y=t==="en",k=a.config,P=r?.priceOverrides??k.priceOverrides??{},M=r?.priceMatchDismissed??k.priceMatchDismissed??[],S=r?.prices??k.prices,L=r?.modelStatistics??k.modelStatistics??{},h=[["today","今日费用","Today"],["summary","月度与累计","Monthly / all-time"],["budget","预算","Budget"]],D=Z(()=>({...a.total?.byProviderModel,...a.month?.byProviderModel,...a.today?.byProviderModel,...Object.fromEntries(Object.keys(L).map(i=>[i,null]))}),[a.total?.byProviderModel,a.month?.byProviderModel,a.today?.byProviderModel,L]),B=a.modelDirectory,U=Z(()=>[...new Set([...Object.keys(D),...Object.keys(P)])].filter(i=>{if(M.includes(i)||ke(i)||["our-free-model:*","our-free-model-region:*"].includes(i))return!1;if(!Array.isArray(B?.providers))return!0;const A=i.slice(0,i.indexOf(":"));return B.providers.includes(A)&&!B.missingModels?.includes(i)}).sort(),[D,P,M,B]);re(()=>{const i=H.current.get(C.current)?.querySelector(".cm-custom-price");i&&(C.current=null,i.scrollIntoView({block:"start",inline:"nearest"}),i.querySelector("input")?.focus({preventScroll:!0}))},[S,x]);const $=Z(()=>[{value:"deepseek:__default__",label:v("overrideTargetDefault")},...Object.keys(S.models??{}).map(i=>({value:"deepseek:"+i,label:"DeepSeek · "+i})),...Object.entries(S.providers??{}).flatMap(([i,A])=>Object.keys(A?.models??{}).map(j=>({value:i+":"+j,label:i+" · "+j})))],[S.models,S.providers,t,v]),n=(i,A)=>{if(r===null)return;const j={...r.priceOverrides??{}};if(A===""?delete j[i]:j[i]=A,A==="__custom__"&&!S.custom?.[i]){const E=i.indexOf(":"),F=o(i.slice(0,E),i.slice(E+1),{...k,...r}),R=F.entry??{},V={currency:F.currency??"USD",billingMode:"flat",...u?.priceMultiplierSettings(R),cacheMiss:R.cacheMiss??R.input??0,cacheHit:R.cacheHit??R.cachedInput??R.cacheMiss??R.input??0,output:R.output??0,...R.cacheWrite!==void 0?{cacheWrite:R.cacheWrite}:{},...R.reasoning!==void 0?{reasoning:R.reasoning}:{}};m({...r,priceOverrides:j,prices:{...S,custom:{...S.custom,[i]:V}}})}else m({...r,priceOverrides:j})},T=i=>{if(r===null)return;const A={...r.priceOverrides??{}};delete A[i],m({...r,priceOverrides:A,priceMatchDismissed:[...new Set([...M,i])]})},W=p.trim().toLowerCase().split(/\s+/).filter(Boolean),Y=(i=>i.filter(A=>W.every(j=>(A+" "+d(A)).toLowerCase().includes(j))))(U),l=Y.length,_=Y.slice(0,s),I=i=>{const A=d(i),j=A.indexOf(":"),E=P[i],F=c===i,R=x[i]??(E==="__custom__"?"custom":E==="__local__"?"local":E?"catalog":"auto"),V=i.indexOf(":"),q=o(V>0?i.slice(0,V):"deepseek",V>0?i.slice(V+1):i,{...k,...r}),ee=!E&&q.matched===!0,K=z=>{z==="custom"&&(C.current=i),N({...x,[i]:z}),z!=="catalog"&&n(i,z==="custom"?"__custom__":z==="local"?"__local__":"")},we=h.filter(([z])=>L[i]?.[z]!==!1),He=(z,J)=>{if(!r)return;const Q={...L,[i]:{today:!0,summary:!0,budget:!0,...L[i],[z]:J}};Object.values(Q[i]).every(Boolean)&&delete Q[i],m({...r,modelStatistics:Q})},Le=ee?y?"Automatic":"自动匹配":E==="__custom__"?y?"Custom price":"自定义价格":E==="__local__"?y?"Local · free":"本地 · 零费用":E?y?"Price table":"指定价格表":y?"Needs a price":"待设置价格";return e("div",{key:i,className:"cm-match-row","data-model-key":i,"data-open":F,ref:z=>{z?H.current.set(i,z):H.current.delete(i)}},e("div",{className:"cm-model-head"},e("div",{className:"cm-model-identity",title:A},e("strong",null,j>0?A.slice(j+1):A),e("span",{className:"cm-model-meta"},e("span",{className:"cm-model-provider"},j>0?A.slice(0,j):"DeepSeek"),e("span",{className:"cm-model-badge"+(!ee&&!E?" needs-price":"")},Le))),e("div",{className:"cm-model-current",title:y?"Effective rates per 1M tokens, including multipliers":"每百万 Token 实际单价,已含倍率"},e(be,{entry:q.entry,currency:q.currency,priceEditor:u,locale:t,local:E==="__local__"})),e("button",{type:"button",className:"cm-btn small cm-model-edit","aria-expanded":F,"aria-label":A+(y?" · Set price":" · 设置价格"),onClick:()=>g(F?null:i)},F?y?"Collapse":"收起":y?"Set price":"设置价格")),e("details",{className:"cm-model-statistics","data-model-statistics":i},e("summary",null,y?"Include in statistics":"计入统计",we.length===3?null:e("span",{className:"cm-note"},we.map(([,z,J])=>y?J:z).join(" · ")||(y?"None":"均不计入"))),e("div",{className:"cm-model-statistics-options"},...h.map(([z,J,Q])=>e("label",{key:z,className:"cm-check"},e("input",{type:"checkbox",checked:L[i]?.[z]!==!1,"aria-label":A+" · "+(y?Q:J),onChange:De=>He(z,De.target.checked)}),y?Q:J)))),F?e("div",{className:"cm-model-editor"},e("div",{className:"cm-source-choices",role:"group","aria-label":y?"Price source":"价格来源"},...[["auto","自动匹配","Automatic"],["catalog","价格表","Price table"],["custom","自定义","Custom"],["local","本地","Local"]].map(([z,J,Q])=>e("button",{key:z,type:"button",className:"cm-source-choice"+(R===z?" active":""),"aria-pressed":R===z,onClick:()=>K(z)},y?Q:J))),R==="catalog"?e("div",{className:"cm-model-source"},e("span",null,y?"Select a reference model":"选择参考模型"),e(ne,{value:E&&!E.startsWith("__")?E:"",options:$,placeholder:y?"Choose a price table entry":"选择价格表条目",label:A,locale:t,onChange:z=>{z?n(i,z):K("auto")}}),!E||E.startsWith("__")?e("p",{className:"cm-note"},y?"Current pricing stays in effect until you choose an entry.":"选定条目后生效,选择前仍使用原价格。"):null):null,R==="custom"&&E==="__custom__"&&S.custom?.[i]?e(Pe,{value:S.custom[i],label:A,locale:t,t:v,priceEditor:u,onChange:z=>m({...r,prices:{...S,custom:{...S.custom,[i]:z}}})}):null,R==="auto"?e("p",{className:"cm-source-explanation"},q.matched?y?"The model uses its automatically matched reference price.":"已自动匹配参考价格,后续调用按该价格计费。":y?"No exact price found. Choose a table entry or enter a custom quote.":"尚未命中参考价格,可选择价格表条目或填写自定义价格。"):null,R==="local"?e("p",{className:"cm-source-explanation"},y?"Tokens are tracked; new calls have zero API cost.":"保留 Token 统计,后续调用的 API 费用记为 0。"):null,ee?null:e("button",{type:"button",className:"cm-model-dismiss",title:v("removePriceMatchHint"),onClick:()=>T(i)},v("overrideRemove"))):null)};return e("div",{className:"cm-model-matching"},e(_e,{state:a,draft:r,setDraft:m,locale:t}),e("div",{className:"cm-model-toolbar"},e("input",{type:"search",className:"cm-input",value:p,placeholder:y?"Find a model or channel…":"查找模型或渠道…","aria-label":y?"Find configured models":"查找已用模型",onChange:i=>{w(i.target.value),b(24)},onKeyDown:i=>{i.key==="Escape"&&(w(""),b(24),i.stopPropagation())}}),e("span",{className:"cm-note",role:"status"},y?`${l} models`:`${l} 个模型`)),_.length?e("div",{className:"cm-model-list"},e("div",{className:"cm-model-columns","aria-hidden":!0},e("span",null,y?"Model / channel":"模型 / 渠道"),e("span",{className:"cm-rate-summary"},...[y?"Input":"输入",y?"Cached input":"缓存读取",y?"Output":"输出"].map(i=>e("span",{key:i},i))),e("span",{title:y?"Per 1M tokens":"每百万 Token"},"/ 1M tok")),..._.map(I)):null,l===0?e("p",{className:"cm-pricing-empty"},p?y?"No models found. Try another keyword.":"没有找到模型,试试其他关键词。":y?"Models appear here after their first call.":"调用过的模型会显示在这里,之后可按渠道设置价格。"):null,l>s?e("button",{type:"button",className:"cm-btn",onClick:()=>b(i=>i+24)},y?`Show more · ${l-s} remaining`:`显示更多 · 还有 ${l-s} 个`):null,M.length>0?e("button",{type:"button",className:"cm-btn small",onClick:()=>f("priceMatchDismissed",[])},v("restorePriceMatches",{count:M.length})):null,e("details",{className:"cm-pricing-rules"},e("summary",null,y?"Automatic matching rules":"自动匹配规则"),e("label",{className:"cm-field"},e("span",null,v("priceMatchLabel")),e("select",{className:"cm-input",value:r?.priceMatch==="exact"?"exact":"auto",onChange:i=>f("priceMatch",i.target.value)},e("option",{value:"auto"},v("priceMatchAuto")),e("option",{value:"exact"},v("priceMatchExact")))),e("p",{className:"cm-note"},v("priceMatchNote"))))}function xe({open:a,className:r}){return e("svg",{className:"cm-pricing-chevron "+r+(a?" is-open":""),width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.8,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0},e("path",{d:"m9 5 7 7-7 7"}))}function Ae({state:a,draft:r,setDraft:m,t:v,locale:t,rpc:o,renderEditor:d,vendorLabels:f,priceEditor:u}){const p=t==="en",[w,s]=O(""),[b,c]=O(""),[g,x]=O({}),[N,H]=O({}),[C,y]=O(null),[k,P]=O(""),M=r?.prices??a.config.prices,S=Z(()=>({...M.providers,deepseek:{models:{...M.models,__default__:M.default}}}),[M.models,M.default,M.providers]),L=Object.keys(S).filter(n=>Object.keys(S[n]?.models??{}).length).sort((n,T)=>n===T?0:n==="deepseek"?-1:T==="deepseek"?1:n.localeCompare(T)),h=w.toLowerCase().trim().split(/\s+/).filter(Boolean),D=L.filter(n=>!b||b===n).map(n=>({id:n,ids:Object.keys(S[n].models).filter(T=>h.every(W=>(n+" "+(f[n]??"")+" "+(T==="__default__"?v("defaultModelId"):T)).toLowerCase().includes(W))).sort((T,W)=>T===W?0:T==="__default__"?1:W==="__default__"?-1:T.localeCompare(W))})).filter(n=>n.ids.length),B=D.reduce((n,T)=>n+T.ids.length,0),U=n=>{s(n),H({}),x({})},$=()=>{const n=k.trim().toLowerCase();!r||!/^[a-z0-9_.-]+$/.test(n)||Object.hasOwn(M.models,n)||(m({...r,prices:{...M,models:{...M.models,[n]:{cacheHit:0,cacheMiss:0,output:0}}}}),P(""),c("deepseek"),s(n),x(T=>({...T,deepseek:!0})),y("deepseek:"+n))};return e("div",{className:"cm-reference-prices"},e("p",{className:"cm-note"},p?"Base rates include multipliers. Open a model to edit rates, currencies and peak/off-peak tiers.":"列表展示含倍率的基础单价。点开模型可编辑币种、单价和峰谷档位。"),e("div",{className:"cm-catalog-toolbar"},e("input",{type:"search",className:"cm-input",value:w,"aria-label":p?"Search mounted prices":"搜索已挂载价格",placeholder:p?"Search models or providers…":"搜索模型或厂商…",onChange:n=>U(n.target.value),onKeyDown:n=>{n.key==="Escape"&&(U(""),n.stopPropagation())}}),e("select",{className:"cm-input",value:b,"aria-label":p?"Filter price provider":"筛选价格厂商",onChange:n=>{c(n.target.value),H({}),x({})}},e("option",{value:""},p?"All providers":"全部厂商"),...L.map(n=>e("option",{key:n,value:n},f[n]??n))),e("span",{className:"cm-note",role:"status"},p?`${B} models`:`${B} 个模型`)),...D.map(({id:n,ids:T})=>{const W=g[n]??(n==="deepseek"||h.length>0||b===n),X=n==="deepseek"?M.currency??"USD":"USD",Y=N[n]??16;return e("section",{key:n,className:"cm-catalog-group"},e("button",{type:"button",className:"cm-catalog-vendor cm-vendor-toggle","aria-expanded":W,onClick:()=>x(l=>({...l,[n]:!W}))},e("span",null,e(xe,{className:"cm-catalog-caret",open:W}),f[n]??n,e("small",null,T.length)),e("span",{className:"cm-catalog-unit"},X+(p?" / 1M tokens":" / 百万 Token"))),W?e("div",{className:"cm-catalog-list"},e("div",{className:"cm-catalog-columns","aria-hidden":!0},...[p?"Model":"模型",p?"Input":"输入",p?"Cached input":"缓存读取",p?"Output":"输出",""].map((l,_)=>e("span",{key:_},l))),...T.slice(0,Y).map(l=>{const _=n+":"+l,I=S[n].models[l],i=C===_,A=l==="__default__"?v("defaultModelId"):l,j=I?.peak||I?.offPeak?p?"Peak / off-peak":"含峰谷价格":I?.longContext?p?"Long context":"含长上下文档位":I?.cny?p?"USD + CNY":"美元 / 人民币":null;return e("div",{key:_,className:"cm-catalog-entry"+(i?" editing":"")},e("button",{type:"button",className:"cm-catalog-model","aria-label":A+(p?" · Edit price":" · 编辑价格"),"aria-expanded":i,onClick:()=>y(i?null:_)},e("span",{className:"cm-catalog-model-name"},e("strong",null,A),j?e("small",null,j):null),e(be,{entry:I,currency:X,priceEditor:u,locale:t}),e(xe,{className:"cm-catalog-edit-caret",open:i})),i?e("div",{className:"cm-catalog-editor"},d(n,l,I),e(fe,{value:I,locale:t,defaults:M.providers?.[n]?.peakWindows??r.peakWindows,onChange:E=>{const F=n==="deepseek"?{...M,...l==="__default__"?{default:E}:{models:{...M.models,[l]:E}}}:{...M,providers:{...M.providers,[n]:{...M.providers[n],models:{...M.providers[n].models,[l]:E}}}};m({...r,prices:F})}})):null)}),T.length>Y?e("button",{type:"button",className:"cm-catalog-more",onClick:()=>H(l=>({...l,[n]:Y+16}))},p?`Show more · ${T.length-Y} remaining`:`显示更多 · 还有 ${T.length-Y} 个`):null):null)}),B===0?e("p",{className:"cm-pricing-empty"},p?"No matching models.":"没有找到匹配的模型。"):null,e("details",{className:"cm-pricing-rules"},e("summary",null,p?"Pricing notes":"计价说明"),e("p",{className:"cm-note"},v("priceTableNote"))),e("details",{className:"cm-catalog-manage"},e("summary",null,p?"Add or restore models":"添加与恢复模型"),e("div",{className:"cm-catalog-add"},e("input",{className:"cm-input",value:k,"aria-label":v("newModelPlaceholder"),placeholder:v("newModelPlaceholder"),onChange:n=>P(n.target.value),onKeyDown:n=>{n.key==="Enter"&&(n.preventDefault(),$())}}),e("button",{type:"button",className:"cm-btn small",disabled:!/^[a-z0-9_.-]+$/.test(k.trim().toLowerCase())||Object.hasOwn(M.models,k.trim().toLowerCase()),onClick:$},v("addModel"))),e(ge,{state:a,draft:r,setDraft:m,locale:t,rpc:o})))}function Oe({state:a,locale:r,formatMoneyUsd:m,api:v,rpc:t,disabled:o}){const[d,f]=O(!1),[u,p]=O(!1),[w,s]=O(""),[b,c]=O([]),[g,x]=O(""),[N,H]=O(""),C=r==="en",y=(h,D)=>{const B=a.config.currency==="CNY"?"Cny":a.config.currency==="EUR"?"Eur":"",U=B&&h[D+B],$=Number(a.config.exchangeRate);return m(typeof U=="number"&&$>0?U/$:h[D],a.config)},k=C?"All models":"全部模型",P=Z(()=>[...new Set([a.today,a.month,...a.history??[]].flatMap(h=>Object.keys(h?.byProviderModel??{})))].filter(h=>h.indexOf(":")>0).sort(),[a.today,a.month,a.history]),M=Z(()=>[{value:"",label:k},...P.map(h=>({value:h,label:h}))],[P,k]),S=()=>t("getRepricingHistory").then(h=>{c(ie.parse(h)),x("")}).catch(h=>x(String(h.message??h)));te(()=>{let h=!0;return t("getRepricingHistory").then(D=>{h&&c(ie.parse(D))},D=>{h&&x(String(D.message??D))}),()=>{h=!1}},[t]);const L=async()=>{if(!(!d||u||o)){p(!0),x(""),s("");try{const h=N?await t("repriceModelHistory",!0,N):await t("repriceHistory",!0);if(!h.ok)throw new Error(h.message);s(h.message),f(!1),await S(),await v.reload()}catch(h){x(String(h.message??h))}finally{p(!1)}}};return e("section",{className:"cm-repricing"},e("h3",{className:"cm-h"},C?"Historical pricing":"历史费用"),e("p",{className:"cm-note"},C?"Rate changes apply to new calls. Recorded historical rates remain fixed.":"修改价格只影响后续调用,历史费用沿用原价格。"),e("div",{className:"cm-repricing-scope"},e("label",null,C?"Recalculation scope":"重算范围"),e(ne,{options:M,value:N,locale:r,label:C?"Choose channel and model":"选择渠道与模型",ariaLabel:C?"Choose channel and model":"选择渠道与模型",placeholder:C?"Search historical models":"搜索历史渠道或模型",onChange:h=>{u||(H(h),f(!1),s(""))}}),e("p",{className:"cm-hint"},N?C?"Only this channel/model changes. Other models and original exchange rates remain unchanged.":"仅重算此渠道下的这个模型,其他模型及原调用汇率保持不变。":C?"Choose a single channel/model to limit the recalculation.":"可选择单个渠道模型,缩小重算范围。")),d?e("div",{className:"cm-repricing-warning",role:"alert",onKeyDown:h=>{h.key==="Escape"&&!u&&(f(!1),h.stopPropagation())}},e("strong",null,(N||k)+(C?" · Historical amounts will change":" · 将修改历史费用")),e("p",null,C?"Recalculate retained calls using current rates and replace their amounts in statistics. Original amounts, price versions and a full ledger backup are kept. Records with incomplete logs are unchanged.":"确认后,将按当前价格重新计算保留的历史调用,并更新统计金额。原金额、原价格版本和完整账本备份都会保留;日志不完整的记录不改。"),e("div",{className:"cm-buttons"},e("button",{type:"button",className:"cm-btn",disabled:u,onClick:()=>f(!1)},C?"Cancel":"取消"),e("button",{type:"button",className:"cm-btn danger",disabled:u||o,onClick:L},u?C?"Recalculating…":"正在重算…":C?"Confirm recalculation":"确认重算"))):e("button",{type:"button",className:"cm-btn",disabled:o||u,onClick:()=>f(!0)},N?C?"Recalculate this model":"重算此模型的历史费用":C?"Recalculate history at current rates":"按当前价格重算历史"),w?e("p",{role:"status",className:"cm-note"},w):null,g?e("p",{role:"alert",className:"cm-err"},g):null,b.length?e("details",{className:"cm-repricing-history"},e("summary",null,C?"Recalculation records · original amounts retained":"重算记录 · 原金额已保留"),e("div",{className:"cm-stat-scroll"},e("table",{className:"cm-stat-table"},e("thead",null,e("tr",null,...(C?["Time","Scope","Before","After","Session/day records"]:["重算时间","范围","原金额","重算后","会话日期记录"]).map(h=>e("th",{key:h,scope:"col"},h)))),e("tbody",null,...b.map(h=>e("tr",{key:h.at},e("td",null,new Date(h.at).toLocaleString(r)),e("td",null,h.model||k),e("td",null,y(h,"before")),e("td",null,y(h,"after")),e("td",null,h.sessions))))))):null)}function ze({state:a,draft:r,setDraft:m,locale:v}){const t=r??a.config,o=(s,b)=>v==="en"?b:s,d=Object.keys(a.total?.byProviderModel??{}).filter(s=>s.indexOf(":")>0).map(s=>s.slice(0,s.indexOf(":"))),f=[...new Set([...d,...Object.keys(t.planBilling?.providers??{})])],[u,p]=O(d[0]??"go"),w=f.includes(u)?u:f[0]??"go";return e("section",{className:"cm-budget","data-provider-billing":!0},e("h3",{className:"cm-h"},o("渠道计费方式","Channel billing")),e("div",{className:"cm-grid"},e("label",{className:"cm-field"},e("span",null,o("渠道","Channel")),e("select",{className:"cm-input","aria-label":o("计费渠道","Billing channel"),value:w,onChange:s=>p(s.target.value)},f.map(s=>e("option",{value:s,key:s},s==="go"?"OpenCode Go (go)":s)))),e("label",{className:"cm-field"},e("span",null,o("计费方式","Billing type")),e("select",{className:"cm-input","aria-label":o("渠道计费方式","Channel billing type"),value:t.planBilling?.providers?.[w]??"auto",disabled:r==null,onChange:s=>m({...t,planBilling:{...t.planBilling,providers:{...t.planBilling?.providers,[w]:s.target.value}}})},[["auto",o("自动","Automatic")],["plan",o("Plan 订阅","Plan subscription")],["api",o("API 按量","Metered API")]].map(([s,b])=>e("option",{value:s,key:s},b))))),e("p",{className:"cm-note"},o("适用于该渠道的所有模型,模型单独设置优先。修改后更新历史 API/Plan 归属,保留 Token 和 API 等值金额。额度查询开关单独控制。","Applies to all models on this channel; model overrides take priority. Changes update historical API/Plan classification while preserving tokens and API-equivalent amounts. Quota queries are controlled separately.")))}async function Ee(a){const r=await a.get("remote").$mount(ue);a.effect(()=>()=>r(),"cost-meter: pricing settings contribution");const m=a.get("remote.costMeter"),v=async(o,...d)=>{(o==="repriceHistory"||o==="repriceModelHistory")&&ce.parse(d[0]),o==="repriceModelHistory"&&de.parse(d[1]);const f=await m[o](...d);if(f?.ok!==!0)throw new Error(f?.error?.message??"Pricing request failed");return(o==="getPriceCatalog"?pe:o==="getRepricingHistory"?ie:se).parse(f.value)},t=document.createElement("style");return t.textContent=".cm-repricing-scope{display:grid;gap:8px;max-width:620px;margin:16px 0}.cm-repricing-scope>label{font-size:13px;color:var(--dsw-alias-label-secondary)}.cm-repricing-scope .cm-hint{margin:0;line-height:1.6}",t.textContent+=".cm-price-search{display:grid;gap:6px;min-width:0}.cm-price-search small{color:var(--dsw-alias-label-tertiary)}.cm-price-search select,.cm-price-search input{width:100%;min-width:0}.cm-repricing-warning{padding:12px;border:1px solid var(--dsw-alias-state-warn-primary,#c58a25);border-radius:10px;background:var(--dsw-alias-bg-layer-1)}.cm-repricing-warning p{margin:8px 0 12px;line-height:1.6}.cm-repricing-history{margin-top:12px}.cm-repricing-history table{width:100%;text-align:left;font-variant-numeric:tabular-nums}.cm-repricing-history td,.cm-repricing-history th{padding:8px;border-bottom:1px solid var(--dsw-alias-border-l1)}",t.textContent+=".cm-repricing-history .cm-stat-scroll{overflow-x:auto;max-width:100%}.cm-repricing-history table{min-width:560px}.cm-repricing-history th{white-space:nowrap}.cm-repricing-history td:nth-child(2){min-width:150px;max-width:260px;overflow-wrap:anywhere}",t.textContent+=".cm-pricing-page .cm-free-model{margin:0 0 12px;padding:10px 12px;border:1px solid var(--dsw-alias-border-l1);border-radius:8px;background:transparent}.cm-pricing-page .cm-free-model>.cm-check{display:flex;align-items:center;gap:8px;margin:0;font-size:12px;line-height:20px;color:var(--dsw-alias-label-primary)}.cm-pricing-page .cm-free-model input{flex:none;width:16px;height:16px;margin:0;accent-color:var(--dsw-alias-state-business-primary)}.cm-pricing-page .cm-free-model>.cm-hint{display:block;margin:4px 0 0 24px;font-size:11px;line-height:1.5}",t.textContent+=".cm-provider-schedules{margin:12px 0}.cm-provider-schedules>.cm-field{max-width:360px;margin:12px 0}.cm-peak-schedule,.cm-custom-more fieldset{min-width:0;margin:12px 0;padding:12px;border:1px solid var(--dsw-alias-border-l1);border-radius:8px}.cm-peak-schedule{display:grid;gap:12px}.cm-custom-more .cm-check{display:flex;align-items:center;gap:8px;margin:12px 0}.cm-custom-more .cm-check input{width:auto;flex:none;margin:0}.cm-peak-schedule legend{font-size:12px}.cm-peak-schedule .cm-hint{margin:0;line-height:1.6}",t.textContent+=".cm-custom-price{grid-column:1/-1;display:grid;gap:14px;margin:4px 0 12px;padding:16px;border:1px solid var(--dsw-alias-border-l1);border-radius:var(--dsw-radius-lg,12px);background:var(--dsw-alias-bg-layer-1);min-width:0}.cm-custom-price legend{padding:0 6px;font-weight:500;font-size:13px}.cm-custom-price label{display:grid;gap:7px;font-size:12px;min-width:0;color:var(--dsw-alias-label-secondary)}.cm-custom-price .cm-input{width:100%;min-width:0}.cm-custom-head{display:flex;justify-content:space-between;align-items:center;gap:12px;color:var(--dsw-alias-label-secondary);font-size:12px}.cm-custom-head label{display:flex;align-items:center;gap:8px}.cm-custom-head select{width:auto!important}.cm-custom-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:12px}.cm-custom-amount{position:relative;display:block}.cm-custom-amount>span{position:absolute;inset-inline-start:11px;top:50%;transform:translateY(-50%);pointer-events:none;color:var(--dsw-alias-label-tertiary)}.cm-custom-amount input{padding-inline-start:28px}.cm-custom-more summary{cursor:pointer;font-size:12px;color:var(--dsw-alias-label-secondary)}.cm-custom-more .cm-custom-grid{grid-template-columns:repeat(2,minmax(0,1fr));margin:12px 0 8px}.cm-custom-price p{margin:0;line-height:1.6}@media(max-width:700px){.cm-custom-grid{grid-template-columns:1fr}.cm-custom-head{flex-wrap:wrap}}",document.head.appendChild(t),t.textContent+=`
1
+ ;(function(e){const Z=window.__ModuleLoader__,C=Z[Symbol.for("@dsh-plugin/dsh-loader:load-wrap")];return(e.id==="dsh-cost-meter"&&Z.load===C?.ours&&typeof C.original=="function"?C.original:Z.load).call(Z,e)})({id:"dsh-cost-meter",chunk:"client.pricing.js",factory:ce=>{const{createElement:e,Fragment:Z,useState:C,useEffect:te,useLayoutEffect:oe,useMemo:G,useRef:ie,useId:ye}=ce("react");let se=null;try{se=ce("react-dom")?.createPortal??null}catch{}const ve=["at","before","after","days","sessions","skipped"],ke=a=>["deepseek-official:deepseek-web-search","deepseek-official:deepseek-web-fetch","deepseek-official:deepseek-search-api","deepseek-official:deepseek-fetch-api","deepseek-official:deepseek-search-server"].includes(a),re={parse:a=>{if(!Array.isArray(a)||!a.every(r=>ve.every(n=>Number.isFinite(r?.[n])&&r[n]>=0)&&(r.model===void 0||typeof r.model=="string")))throw new Error("Invalid recalculation history");return a}},ne={parse:a=>{if(typeof a?.ok!="boolean"||typeof a?.message!="string")throw new Error("Invalid recalculation result");return a}},le={parse:a=>{if(typeof a!="boolean")throw new Error("Expected confirmation");return a}},de={parse:a=>{if(typeof a!="string"||a.length>2048||a.indexOf(":")<=0||a.endsWith(":")||/[\r\n]/.test(a))throw new Error("Expected channel/model");return a}},pe={parse:a=>{if(!a||typeof a!="object"||Array.isArray(a))throw new Error("Invalid price catalog");return a}},X=(a,r)=>({mode:"strict",typeSymbol:"dsh-cost-meter#"+a,schema:r,create:()=>r}),ue={package:"dsh-cost-meter-pricing",face:"host",descriptors:[{id:"dsh-cost-meter#costMeter/getPriceCatalog",service:"costMeter",namespace:"costMeter",method:"getPriceCatalog",invocation:{kind:"direct"},parameters:[],result:X("PriceCatalog",pe)},{id:"dsh-cost-meter#costMeter/getRepricingHistory",service:"costMeter",namespace:"costMeter",method:"getRepricingHistory",invocation:{kind:"direct"},parameters:[],result:X("RepricingHistory",re)},{id:"dsh-cost-meter#costMeter/repriceHistory",service:"costMeter",namespace:"costMeter",method:"repriceHistory",invocation:{kind:"direct"},parameters:[{name:"confirmed",wire:"confirmed",source:"json",codec:X("RepricingConfirmation",le)}],result:X("FetchPricesResult",ne)},{id:"dsh-cost-meter#costMeter/repriceModelHistory",service:"costMeter",namespace:"costMeter",method:"repriceModelHistory",invocation:{kind:"direct"},parameters:[{name:"confirmed",wire:"confirmed",source:"json",codec:X("RepricingConfirmation",le)},{name:"model",wire:"model",source:"json",codec:X("RepricingModel",de)}],result:X("FetchPricesResult",ne)}]},Ne=a=>(a.label+" "+a.value).toLowerCase();function me({options:a,value:r,placeholder:n,label:f,ariaLabel:t,locale:o,onChange:d}){const b=o==="en",g=ye(),u=g+"-list",[w,l]=C(""),[x,m]=C(!1),[c,s]=C(0),[k,D]=C(null),M=ie(null),v=ie(null),N=ie(null),S=a.find(h=>h.value===r),P=w.toLowerCase().trim().split(/\s+/).filter(Boolean),_=G(()=>a.map(h=>({option:h,search:Ne(h)})),[a]),T=h=>{const A=h.toLowerCase().trim().split(/\s+/).filter(Boolean);return A.length?_.filter(I=>A.every(i=>I.search.includes(i))).map(I=>I.option):a},y=T(w),H=S&&!y.includes(S)?[S,...y]:y,W=Math.max(0,Math.min(c,H.length-1)),B=()=>{m(!1),l("")},F=()=>{x||(D(null),l(""),s(Math.max(0,H.findIndex(h=>h.value===r))),m(!0))},p=h=>{h&&(h.value!==r&&d(h.value),B())},L=()=>{if(x&&w){l(""),s(0);return}r&&d(""),B()};oe(()=>{if(!x||typeof document>"u")return;const h=v.current,A=typeof window>"u"?null:window,I=()=>{const i=h?.getBoundingClientRect?.();if(!i||!A)return;const O=A.innerHeight,R=12,E=O-i.bottom-R,Y=i.top-R,j=E<180&&Y>E,V=Math.max(60,j?Y:E),q=Math.max(0,Math.min(280,V,O-R*2)),ae=Math.max(R,Math.min(j?i.top-q-6:i.bottom+6,O-q-R));D(K=>K&&K.left===i.left&&K.top===ae&&K.width===i.width&&K.maxHeight===q?K:{left:i.left,top:ae,width:i.width,maxHeight:q})};if(I(),typeof A?.addEventListener=="function")return A.addEventListener("scroll",I,!0),A.addEventListener("resize",I),()=>{A.removeEventListener("scroll",I,!0),A.removeEventListener("resize",I)}},[x]),te(()=>{if(!x||typeof document>"u"||typeof document.addEventListener!="function")return;const h=A=>{M.current?.contains?.(A.target)||N.current?.contains?.(A.target)||B()};return document.addEventListener("pointerdown",h,!0),()=>document.removeEventListener("pointerdown",h,!0)},[x]),oe(()=>{!x||!k||N.current?.querySelector?.('[data-active="true"]')?.scrollIntoView?.({block:"nearest"})},[x,W,k,w]);const U=h=>g+"-opt-"+h,ee=P.length?y.length?b?`${y.length} matches`:`${y.length} 个结果`:H.length?b?"No matches · showing the current choice":"没有匹配的模型 · 下面是当前选择":b?"No matches":"没有匹配的模型":null,$=x?e("div",{ref:N,className:"cm-combo-panel",style:k??{visibility:"hidden"}},H.length?e("div",{className:"cm-combo-list",id:u,role:"listbox","aria-label":f},H.map((h,A)=>e("button",{key:h.value,id:U(A),type:"button",role:"option",className:"cm-combo-option"+(A===W?" active":""),"data-active":String(A===W),"aria-selected":String(h.value===r),onMouseEnter:()=>s(A),onMouseDown:I=>I.preventDefault(),onClick:()=>p(h)},h.label))):null,ee?e("p",{className:"cm-combo-note",role:"status"},ee):null):null;return e("div",{ref:M,className:"cm-price-search cm-combo"},e("div",{className:"cm-combo-control"},e("input",{ref:v,type:"search",className:"cm-input cm-combo-input",autoComplete:"off",value:x?w:S?.label??"",role:"combobox","aria-expanded":String(x),"aria-autocomplete":"list","aria-controls":x&&H.length?u:void 0,"aria-activedescendant":x&&H.length?U(W):void 0,"aria-label":t??f+(b?" · Price model":" · 价格模型"),placeholder:x&&S?S.label:n,onFocus:F,onClick:()=>{x||F()},onChange:h=>{const A=h.target.value,I=!x&&S&&A.startsWith(S.label)?A.slice(S.label.length):A,i=T(I);l(I),m(!0),s(S&&i.length>0&&!i.includes(S)?1:0)},onKeyDown:h=>{if(!h.nativeEvent?.isComposing){if(h.key==="Escape"){if(h.preventDefault(),!x)return;B(),h.stopPropagation();return}if(h.key==="ArrowDown"||h.key==="ArrowUp"){if(h.preventDefault(),!x){F();return}s(Math.max(0,Math.min(H.length-1,W+(h.key==="ArrowDown"?1:-1))));return}if(h.key==="Enter"&&x&&H[W]){h.preventDefault(),p(H[W]);return}h.key==="Tab"&&B()}}}),r||w?e("button",{type:"button",className:"cm-combo-clear","aria-label":(b?"Clear ":"清空 ")+f,onMouseDown:h=>h.preventDefault(),onClick:L},"×"):null,e("button",{type:"button",className:"cm-combo-caret",tabIndex:-1,"aria-hidden":"true",onMouseDown:h=>h.preventDefault(),onClick:()=>{x?B():(v.current?.focus?.(),F())}},"▾")),$&&se?se($,document.body):$)}function ge({state:a,draft:r,setDraft:n,locale:f,rpc:t}){const[o,d]=C(!1),[b,g]=C(null),[u,w]=C(""),[l,x]=C(""),[m,c]=C(0),s=a.config.prices.currency??"USD",k=f==="en";te(()=>{if(!o)return;let N=!0;return g(null),x(""),w(""),t("getPriceCatalog").then(S=>{N&&g(S)},S=>{N&&x(String(S.message??S))}),()=>{N=!1}},[o,s,m,t]);const D=[];for(const[N,S]of Object.entries(b??{}))for(const P of Object.values(S))for(const[_,T]of Object.entries(P))!(N==="deepseek"?r?.prices.models[_]:r?.prices.providers?.[N]?.models?.[_])&&!T.unpriced&&D.push({value:N+":"+_,label:N+" · "+_,provider:N,id:_,entry:T});const M=D.find(N=>N.value===u),v=()=>{if(!M||!r)return;const{provider:N,id:S,entry:P}=M,_=JSON.parse(JSON.stringify(P)),T=r.prices;n({...r,prices:N==="deepseek"?{...T,models:{...T.models,[S]:_}}:{...T,providers:{...T.providers,[N]:{...T.providers?.[N],models:{...T.providers?.[N]?.models,[S]:_}}}}}),w("")};return e("div",{className:"cm-restore-prices"},e("button",{type:"button",className:"cm-btn small","aria-expanded":o,onClick:()=>d(N=>!N)},o?k?"Close restore":"收起恢复入口":k?"Restore bundled model":"恢复内置模型"),o?e("div",{className:"cm-collapse-body"},l?e("div",{role:"alert",className:"cm-err"},l,e("button",{type:"button",className:"cm-btn small",onClick:()=>c(N=>N+1)},k?"Retry":"重试")):b===null?e("p",{role:"status",className:"cm-hint"},k?"Loading prices…":"读取价格…"):D.length?e(Z,null,e(me,{options:D,value:M?u:"",placeholder:k?"Select a model":"选择模型",label:k?"Restore model":"恢复模型",locale:f,onChange:w}),e("button",{type:"button",className:"cm-btn small",disabled:!M,onClick:v},k?"Restore":"恢复")):e("p",{className:"cm-hint"},k?"All bundled models are mounted.":"内置模型均已挂载。")):null)}function Ce(a){const{state:r,draft:n,setDraft:f,t}=a,{peakPhaseAt:o,resolveLocale:d,peakNoticeEl:b}=a.peakHelpers,g=r.config,u=(m,c)=>{n!==null&&f({...n,[m]:c})},w=n===null?g:{...g,...n},l=(()=>{if(w.peakEnabled!==!0)return t("peakOff");const m=Date.parse(w.peakEffectiveAt||""),c=Date.now();if(Number.isFinite(m)&&c<m)return t("peakNotEffective",{time:new Date(m).toLocaleString()});const s=w.peakWindows??[],k=o(c,s,w.peakHolidays);return k===null?t("offPeakActive"):k.holiday===!0?t("holidayAllOffPeak"):k.weekend===!0?t("weekendAllOffPeak"):k.inPeak?t("peakActive"):t("offPeakActive")})(),x=(w.peakWindows?.length??0)>0?t("peakSummary",{windows:w.peakWindows.map(m=>m.start+":00-"+m.end+":00").join(d(w)==="zh"?"、":", "),time:w.peakEffectiveAt||t("unknown"),status:l}):t("noPeakWindows",{status:l});return e("div",{className:"cm-budget"},e("div",{className:"cm-budget-head"},e("h3",{className:"cm-h"},t("peakPanelTitle")),e("label",{className:"cm-check"},e("input",{type:"checkbox",checked:n?.peakEnabled!==!1,onChange:m=>u("peakEnabled",m.target.checked)}),e("span",null,t("peakEnabledLabel")))),e("div",{className:"cm-grid"},e("div",{className:"cm-field"},e("label",{className:"cm-check"},e("input",{type:"checkbox",checked:n?.peakNotice!==!1,onChange:m=>u("peakNotice",m.target.checked)}),e("span",null,t("peakNoticeLabel")))),e("div",{className:"cm-field"},e("label",null,t("peakStyleLabel")),e("select",{className:"cm-input",value:n?.peakStyle??"compact",onChange:m=>u("peakStyle",m.target.value)},e("option",{value:"progress"},d(n)==="en"?"Time progress":"时间进度条"),e("option",{value:"compact"},t("peakStyleCompact")),e("option",{value:"classic"},t("peakStyleClassic"))))),e("div",{className:"cm-grid"},e("div",{className:"cm-field"},e("label",{className:"cm-check"},e("input",{type:"checkbox",checked:n?.peakAlertEnabled!==!1,onChange:m=>u("peakAlertEnabled",m.target.checked)}),e("span",null,t("peakAlertLabel")))),e("div",{className:"cm-field"},e("label",null,t("peakAlertAheadLabel")),e("input",{className:"cm-input narrow",type:"number",min:"1",max:"30",step:"1",value:String(typeof n?.peakAlertAhead=="number"&&Number.isFinite(n.peakAlertAhead)&&n.peakAlertAhead>=1&&n.peakAlertAhead<=30?n.peakAlertAhead:2),onChange:m=>{const c=Number(m.target.value);Number.isInteger(c)&&c>=1&&c<=30&&u("peakAlertAhead",c)}})),e("div",{className:"cm-field"},e("label",null,t("peakAlertTargetLabel")),e("select",{className:"cm-input",value:n?.peakAlertTarget==="peak"||n?.peakAlertTarget==="offpeak"?n.peakAlertTarget:"both",onChange:m=>u("peakAlertTarget",m.target.value)},e("option",{value:"both"},t("peakAlertTargetBoth")),e("option",{value:"peak"},t("peakAlertTargetPeak")),e("option",{value:"offpeak"},t("peakAlertTargetOffPeak"))))),e("div",{className:"cm-grid"},e("div",{className:"cm-field"},e("label",null,t("peakAlertPositionLabel")),e("select",{className:"cm-input",value:n?.peakAlertPosition==="center"?"center":"corner",onChange:m=>u("peakAlertPosition",m.target.value)},e("option",{value:"corner"},t("peakAlertPositionCorner")),e("option",{value:"center"},t("peakAlertPositionCenter")))),e("div",{className:"cm-field"},e("label",{className:"cm-check"},e("input",{type:"checkbox",checked:n?.peakAlertWebNotify===!0,onChange:m=>{u("peakAlertWebNotify",m.target.checked),m.target.checked&&window.Notification&&Notification.permission==="default"&&Promise.resolve(Notification.requestPermission()).catch(()=>{})}}),e("span",null,t("peakAlertWebNotifyLabel"))),e("p",{className:"cm-hint"},t("peakAlertWebNotifyHint")))),e("div",{className:"cm-field"},e("label",null,t("peakAlertPreviewLabel")),e("div",{className:"cm-row"},e("button",{className:"cm-btn",onClick:()=>window.cmPeakAlertPreview?.("peak")},t("peakAlertPreviewPeak")),e("button",{className:"cm-btn",onClick:()=>window.cmPeakAlertPreview?.("offpeak")},t("peakAlertPreviewOffPeak")))),e("div",{className:"cm-peak-preview"},n?.peakEnabled!==!1&&n?.peakNotice!==!1?b(r,w,t):e("p",{className:"cm-hint"},t("peakNoticeHiddenHint"))),e("p",{className:"cm-hint"},x),e("div",{className:"cm-field"},e("label",null,t("peakHolidaysLabel")),e("input",{className:"cm-input",defaultValue:(w.peakHolidays??[]).join(", "),onBlur:m=>u("peakHolidays",m.target.value.split(/[,,\s]+/).filter(Boolean))})),e("p",{className:"cm-hint"},t("weekendRuleNote")))}function he({value:a,onChange:r,locale:n,defaults:f=[]}){const t=n==="en",o=a.peakWindows,d=m=>m.map(c=>c.start+"-"+c.end).join(", "),[b,g]=C(()=>d(o??f)),[u,w]=C("");te(()=>g(d(o??f)),[JSON.stringify(o),JSON.stringify(f)]);const l=(m,c)=>{const s={...a};c===void 0?delete s[m]:s[m]=c,r(s)},x=()=>{const c=(b.trim()?b.split(/[,,]/).map(s=>s.trim()):[]).map(s=>{const k=s.match(/^(\d+(?:\.\d+)?)\s*-\s*(\d+(?:\.\d+)?)$/);return k?{start:Number(k[1]),end:Number(k[2])}:null});if(c.length>24||c.some(s=>!s||s.start>=24||s.end>24||s.start===s.end)){w(t?"Use UTC hours, e.g. 1-4, 6-10 or 22-2.":"填写 UTC 小时,例如 1-4, 6-10,跨午夜可填 22-2。");return}w(""),l("peakWindows",c)};return e("fieldset",{className:"cm-peak-schedule"},e("legend",null,t?"Peak schedule":"峰谷时段"),e("label",{className:"cm-check"},e("input",{type:"checkbox",checked:o!==void 0,onChange:m=>{w(""),l("peakWindows",m.target.checked?structuredClone(f):void 0)}}),t?"Override peak hours":"自定义峰时段"),o!==void 0?e("label",{className:"cm-field"},t?"Peak hours (UTC)":"峰时段(UTC)",e("input",{className:"cm-input",value:b,onChange:m=>g(m.target.value),onBlur:x,onKeyDown:m=>{m.key==="Enter"&&(m.preventDefault(),x())}})):null,e("label",{className:"cm-field"},t?"Calendar":"日历规则",e("select",{className:"cm-input","aria-label":t?"Calendar":"日历规则",value:a.peakSchedule??"",onChange:m=>l("peakSchedule",m.target.value||void 0)},...[["","沿用上级/渠道默认","Inherit channel/default"],["daily","每天","Every day"],["deepseek","北京时间工作日","Beijing weekdays"],["utc-weekdays","UTC 工作日","UTC weekdays"],["ollama","Ollama Cloud","Ollama Cloud"],["volcengine","火山方舟","Volcano Ark"]].map(([m,c,s])=>e("option",{key:m,value:m},t?s:c)))),e("label",{className:"cm-field"},t?"Holidays":"节假日",e("select",{className:"cm-input","aria-label":t?"Holidays":"节假日",value:a.peakHolidays===null?"none":Array.isArray(a.peakHolidays)?"custom":"inherit",onChange:m=>l("peakHolidays",m.target.value==="none"?null:m.target.value==="custom"?[]:void 0)},e("option",{value:"inherit"},t?"Inherit":"沿用上级/渠道默认"),e("option",{value:"none"},t?"No holiday table":"不使用节假日表"),e("option",{value:"custom"},t?"Custom dates":"自定义日期"))),Array.isArray(a.peakHolidays)?e("label",{className:"cm-field"},t?"Off-peak Beijing dates":"全天谷价日期(北京时间)",e("input",{className:"cm-input",key:JSON.stringify(a.peakHolidays),defaultValue:a.peakHolidays.join(", "),placeholder:"2026-11-01, 2026-11-02",onBlur:m=>{const c=m.target.value.split(/[,,\s]+/).filter(Boolean);if(c.length>366||c.some(s=>!/^\d{4}-\d{2}-\d{2}$/.test(s)||!Number.isFinite(Date.parse(s+"T00:00:00Z"))||new Date(s+"T00:00:00Z").toISOString().slice(0,10)!==s)){w(t?"Use valid YYYY-MM-DD dates.":"请填写有效的 YYYY-MM-DD 日期。");return}w(""),l("peakHolidays",[...new Set(c)].sort())}})):null,u?e("p",{className:"cm-err",role:"alert"},u):null,e("p",{className:"cm-hint"},t?"Hours use UTC; Beijing time is UTC + 8. Windows include the start and exclude the end. Empty hours mean all off-peak. Model settings override channel settings.":"小时采用 UTC,北京时间减 8 小时后填写。包含起点、不含终点,时段留空表示全天谷价。模型设置优先于渠道设置。"))}function fe({value:a,onChange:r,locale:n,defaults:f}){const t=n==="en",o=a.billingMode==="deepseek-peak"||!!(a.peak||a.offPeak),d={cacheMiss:a.cacheMiss??a.input??0,cacheHit:a.cacheHit??a.cachedInput??a.input??0,output:a.output??0};return e("details",{className:"cm-custom-more"},e("summary",null,t?"Peak / off-peak pricing":"峰谷价格与时段"),e("label",{className:"cm-check"},e("input",{type:"checkbox",checked:o,onChange:b=>{const g={...a,billingMode:b.target.checked?"deepseek-peak":"flat"};b.target.checked?(g.peak=a.peak??{...d},g.offPeak=a.offPeak??{...d}):(delete g.peak,delete g.offPeak),r(g)}}),t?"Enable peak / off-peak prices":"启用峰谷价格"),o?e(Z,null,...["peak","offPeak"].map(b=>e("fieldset",{key:b},e("legend",null,b==="peak"?t?"Peak":"峰价":t?"Off-peak":"谷价"),e("div",{className:"cm-custom-grid"},...[["cacheMiss","输入","Input"],["cacheHit","缓存读取","Cached input"],["output","输出","Output"],["cacheWrite","缓存写入","Cache write"],["reasoning","单独推理","Reasoning"]].map(([g,u,w])=>e("label",{key:g},t?w:u,e("input",{type:"number",min:0,step:"any",className:"cm-input",value:a[b]?.[g]??"",onChange:l=>{const x={...a,[b]:{...d,...a[b]}};if(l.target.value==="")if(["cacheWrite","reasoning"].includes(g))delete x[b][g];else return;else if(Number.isFinite(l.target.valueAsNumber)&&l.target.valueAsNumber>=0)x[b][g]=l.target.valueAsNumber;else return;r(x)}})))))),e(he,{value:a,onChange:r,locale:n,defaults:f})):null)}function Me({state:a,draft:r,setDraft:n,locale:f}){const t=f==="en",o=r??a.config,[d,b]=C("deepseek"),g=d.trim().toLowerCase().replace(/^llm-/,""),u=o.prices?.providers?.[g]??{models:{}},w=[...new Set(["deepseek",...Object.keys(o.prices?.providers??{}),...Object.keys(a.today?.byProviderModel??{}).map(l=>l.split(":")[0])])].sort();return e("details",{className:"cm-provider-schedules"},e("summary",null,t?"Channel peak schedules":"按渠道设置峰谷时段"),e("label",{className:"cm-field"},t?"Provider ID":"渠道 ID",e("input",{className:"cm-input",list:"cm-peak-providers",value:d,onChange:l=>b(l.target.value)})),e("datalist",{id:"cm-peak-providers"},...w.map(l=>e("option",{key:l,value:l}))),/^[a-z0-9][a-z0-9_.-]{0,99}$/.test(g)&&!["constructor","prototype","__proto__"].includes(g)?e(he,{key:g,value:u,locale:f,defaults:g==="ollama-cloud"?[{start:12,end:18}]:o.peakWindows,onChange:l=>n({...o,prices:{...o.prices,providers:{...o.prices.providers,[g]:l}}})}):null,e("p",{className:"cm-hint"},t?"Use the channel ID from model pricing. Applies to peak-enabled models and is retained when official prices sync.":"填写模型定价中显示的渠道 ID。规则用于已启用峰谷价格的模型,同步官方价格时会保留。"))}function Pe({value:a,label:r,locale:n,onChange:f,t,priceEditor:o}){const d=n==="en",{PriceInput:b,priceFactor:g,setPriceFactor:u,multiplierOptions:w}=o,l=[["cacheMiss",d?"Input · cache miss":"输入 · 未命中缓存"],["cacheHit",d?"Cached input":"缓存读取"],["output",d?"Output":"输出"],["cacheWrite",d?"Cache write":"缓存写入"],["reasoning",d?"Separate reasoning":"单独推理费用"]],x=(c,s,k)=>{const D={...a};s===null?delete D[c]:D[c]=s,u(D,"base."+c,k),f(D)},m=([c,s])=>e("label",{key:c},s,e("span",{className:"cm-custom-amount"},e("span",{"aria-hidden":!0},a.currency==="CNY"?"¥":"$"),e(b,{entry:a,value:a[c]??null,path:"base."+c,t,emptyMode:["cacheWrite","reasoning"].includes(c)?"clear":"ignore",label:r+" · "+s,placeholder:c==="cacheWrite"?d?"Same as cached input":"跟随缓存读取":c==="reasoning"?d?"Included in output":"含在输出中":"0",onCommit:(k,D)=>x(c,k,D)})));return e("fieldset",{className:"cm-custom-price","aria-label":r+(d?" · Custom price":" · 自定义价格")},e("legend",null,d?"Custom price · per 1M tokens":"自定义价格 · 每百万 Token"),e("div",{className:"cm-custom-head"},e("span",null,d?"Only this channel and model":"仅用于此渠道的这个模型"),e("label",null,d?"Currency":"币种",e("select",{className:"cm-input",value:a.currency,onChange:c=>f({...a,currency:c.target.value})},e("option",{value:"USD"},d?"USD · US dollar":"USD · 美元"),e("option",{value:"CNY"},d?"CNY · Yuan":"CNY · 人民币")))),e("div",{className:"cm-custom-grid"},...l.slice(0,3).map(m)),w(a,t,c=>f({...a,separateMultipliers:c,multipliers:{}})),e(fe,{value:a,onChange:f,locale:n,defaults:[{start:1,end:4},{start:6,end:10}]}),e("div",{className:"cm-custom-effective",role:"status"},e("div",{className:"cm-effective-heading"},e("span",null,d?"Effective prices":"实际单价"),e("small",null,d?"Price × multiplier / 1M tokens":"单价 × 倍率 / 百万 Token")),e("div",{className:"cm-effective-grid"},...l.slice(0,3).map(([c,s])=>e("div",{key:c},e("span",null,s),e("strong",null,(a.currency==="CNY"?"¥":"$")+Number((a[c]*g(a,"base."+c)).toPrecision(8)).toLocaleString(d?"en-US":"zh-CN",{maximumFractionDigits:8})))))),e("details",{className:"cm-custom-more"},e("summary",null,d?"More billing fields":"更多计费项"),e("div",{className:"cm-custom-grid"},...l.slice(3).map(m)),e("p",{className:"cm-hint"},d?"Leave reasoning blank when it is included in output. Leave cache write blank to use the cached input rate.":"推理已包含在输出中时无需另填。缓存写入留空则使用缓存读取价格。")),e("p",{className:"cm-hint"},d?"Enter or leave a field to save. Switching the price source keeps your custom values.":"回车或离开输入框后保存;切换价格来源会保留已填的自定义价格。"))}function be({entry:a,currency:r,priceEditor:n,locale:f,local:t=!1}){const o=f==="en",d=a?n?.priceAt?.(a)??a:null;return e("span",{className:"cm-rate-summary"},...[["cacheMiss","input",o?"Input":"输入"],["cacheHit","cachedInput",o?"Cached input":"缓存读取"],["output","output",o?"Output":"输出"]].map(([g,u,w])=>{const l=t?0:d?.unpriced?null:d?.[g]??d?.[u],x=l==null?null:l*(n?.priceFactor?.(d??{},"base."+g)??1);return e("span",{key:g,className:"cm-rate-item"},e("span",null,w),e("strong",null,x===null?"—":(r==="CNY"?"¥":"$")+Number(x.toPrecision(8)).toLocaleString(o?"en-US":"zh-CN",{maximumFractionDigits:8})))}))}function Se({state:a,draft:r,setDraft:n,locale:f}){if(a.ourFreeModel?.enabled!==!0)return null;const t=f==="en",o=r?.priceOverrides??a.config.priceOverrides??{},d=["our-free-model:*","our-free-model-region:*"],b=d.every(g=>o[g]==="__free__");return e("section",{className:"cm-free-model","aria-label":"dsh-our-free-model"},e("label",{className:"cm-check"},e("input",{type:"checkbox",role:"switch",checked:b,onChange:g=>{if(!r)return;const u={...o};for(const w of d)g.target.checked?u[w]="__free__":u[w]==="__free__"&&delete u[w];n({...r,priceOverrides:u})}}),e("span",null,t?"Count dsh-our-free-model calls as free":"dsh-our-free-model 调用按免费计算")),e("p",{className:"cm-hint"},t?"Future calls through this plugin cost 0; tokens are still counted. Historical costs and other providers stay unchanged.":"仅此插件后续调用记为免费,Token 照常统计;历史费用和其他渠道不变。"))}function Ae({state:a,draft:r,setDraft:n,t:f,locale:t,resolveClientPrice:o,prettyProviderKey:d,setField:b,priceEditor:g}){const[u,w]=C(""),[l,x]=C(24),[m,c]=C(null),[s,k]=C({}),D=ie(new Map),M=ie(null),v=t==="en",N=a.config,S=r?.priceOverrides??N.priceOverrides??{},P=r?.priceMatchDismissed??N.priceMatchDismissed??[],_=r?.prices??N.prices,T=r?.modelStatistics??N.modelStatistics??{},y=[["today","今日费用","Today"],["summary","月度与累计","Monthly / all-time"],["budget","预算","Budget"]],H=G(()=>({...a.total?.byProviderModel,...a.month?.byProviderModel,...a.today?.byProviderModel,...Object.fromEntries(Object.keys(T).map(i=>[i,null]))}),[a.total?.byProviderModel,a.month?.byProviderModel,a.today?.byProviderModel,T]),W=a.modelDirectory,B=G(()=>[...new Set([...Object.keys(H),...Object.keys(S)])].filter(i=>{if(P.includes(i)||ke(i)||["our-free-model:*","our-free-model-region:*"].includes(i))return!1;if(!Array.isArray(W?.providers))return!0;const O=i.slice(0,i.indexOf(":"));return W.providers.includes(O)&&!W.missingModels?.includes(i)}).sort(),[H,S,P,W]);oe(()=>{const i=D.current.get(M.current)?.querySelector(".cm-custom-price");i&&(M.current=null,i.scrollIntoView({block:"start",inline:"nearest"}),i.querySelector("input")?.focus({preventScroll:!0}))},[_,s]);const F=G(()=>[{value:"deepseek:__default__",label:f("overrideTargetDefault")},...Object.keys(_.models??{}).map(i=>({value:"deepseek:"+i,label:"DeepSeek · "+i})),...Object.entries(_.providers??{}).flatMap(([i,O])=>Object.keys(O?.models??{}).map(R=>({value:i+":"+R,label:i+" · "+R})))],[_.models,_.providers,t,f]),p=(i,O)=>{if(r===null)return;const R={...r.priceOverrides??{}};if(O===""?delete R[i]:R[i]=O,O==="__custom__"&&!_.custom?.[i]){const E=i.indexOf(":"),Y=o(i.slice(0,E),i.slice(E+1),{...N,...r}),j=Y.entry??{},V={currency:Y.currency??"USD",billingMode:"flat",...g?.priceMultiplierSettings(j),cacheMiss:j.cacheMiss??j.input??0,cacheHit:j.cacheHit??j.cachedInput??j.cacheMiss??j.input??0,output:j.output??0,...j.cacheWrite!==void 0?{cacheWrite:j.cacheWrite}:{},...j.reasoning!==void 0?{reasoning:j.reasoning}:{}};n({...r,priceOverrides:R,prices:{..._,custom:{..._.custom,[i]:V}}})}else n({...r,priceOverrides:R})},L=i=>{if(r===null)return;const O={...r.priceOverrides??{}};delete O[i],n({...r,priceOverrides:O,priceMatchDismissed:[...new Set([...P,i])]})},U=u.trim().toLowerCase().split(/\s+/).filter(Boolean),$=(i=>i.filter(O=>U.every(R=>(O+" "+d(O)).toLowerCase().includes(R))))(B),h=$.length,A=$.slice(0,l),I=i=>{const O=d(i),R=O.indexOf(":"),E=S[i],Y=m===i,j=s[i]??(E==="__custom__"?"custom":E==="__local__"?"local":E?"catalog":"auto"),V=i.indexOf(":"),q=o(V>0?i.slice(0,V):"deepseek",V>0?i.slice(V+1):i,{...N,...r}),ae=!E&&q.matched===!0,K=z=>{z==="custom"&&(M.current=i),k({...s,[i]:z}),z!=="catalog"&&p(i,z==="custom"?"__custom__":z==="local"?"__local__":"")},we=y.filter(([z])=>T[i]?.[z]!==!1),He=(z,J)=>{if(!r)return;const Q={...T,[i]:{today:!0,summary:!0,budget:!0,...T[i],[z]:J}};Object.values(Q[i]).every(Boolean)&&delete Q[i],n({...r,modelStatistics:Q})},Le=ae?v?"Automatic":"自动匹配":E==="__custom__"?v?"Custom price":"自定义价格":E==="__local__"?v?"Local · free":"本地 · 零费用":E?v?"Price table":"指定价格表":v?"Needs a price":"待设置价格";return e("div",{key:i,className:"cm-match-row","data-model-key":i,"data-open":Y,ref:z=>{z?D.current.set(i,z):D.current.delete(i)}},e("div",{className:"cm-model-head"},e("div",{className:"cm-model-identity",title:O},e("strong",null,R>0?O.slice(R+1):O),e("span",{className:"cm-model-meta"},e("span",{className:"cm-model-provider"},R>0?O.slice(0,R):"DeepSeek"),e("span",{className:"cm-model-badge"+(!ae&&!E?" needs-price":"")},Le))),e("div",{className:"cm-model-current",title:v?"Effective rates per 1M tokens, including multipliers":"每百万 Token 实际单价,已含倍率"},e(be,{entry:q.entry,currency:q.currency,priceEditor:g,locale:t,local:E==="__local__"})),e("button",{type:"button",className:"cm-btn small cm-model-edit","aria-expanded":Y,"aria-label":O+(v?" · Set price":" · 设置价格"),onClick:()=>c(Y?null:i)},Y?v?"Collapse":"收起":v?"Set price":"设置价格")),e("details",{className:"cm-model-statistics","data-model-statistics":i},e("summary",null,v?"Include in statistics":"计入统计",we.length===3?null:e("span",{className:"cm-note"},we.map(([,z,J])=>v?J:z).join(" · ")||(v?"None":"均不计入"))),e("div",{className:"cm-model-statistics-options"},...y.map(([z,J,Q])=>e("label",{key:z,className:"cm-check"},e("input",{type:"checkbox",checked:T[i]?.[z]!==!1,"aria-label":O+" · "+(v?Q:J),onChange:Ie=>He(z,Ie.target.checked)}),v?Q:J)))),Y?e("div",{className:"cm-model-editor"},e("div",{className:"cm-source-choices",role:"group","aria-label":v?"Price source":"价格来源"},...[["auto","自动匹配","Automatic"],["catalog","价格表","Price table"],["custom","自定义","Custom"],["local","本地","Local"]].map(([z,J,Q])=>e("button",{key:z,type:"button",className:"cm-source-choice"+(j===z?" active":""),"aria-pressed":j===z,onClick:()=>K(z)},v?Q:J))),j==="catalog"?e("div",{className:"cm-model-source"},e("span",null,v?"Select a reference model":"选择参考模型"),e(me,{value:E&&!E.startsWith("__")?E:"",options:F,placeholder:v?"Choose a price table entry":"选择价格表条目",label:O,locale:t,onChange:z=>{z?p(i,z):K("auto")}}),!E||E.startsWith("__")?e("p",{className:"cm-note"},v?"Current pricing stays in effect until you choose an entry.":"选定条目后生效,选择前仍使用原价格。"):null):null,j==="custom"&&E==="__custom__"&&_.custom?.[i]?e(Pe,{value:_.custom[i],label:O,locale:t,t:f,priceEditor:g,onChange:z=>n({...r,prices:{..._,custom:{..._.custom,[i]:z}}})}):null,j==="auto"?e("p",{className:"cm-source-explanation"},q.matched?v?"The model uses its automatically matched reference price.":"已自动匹配参考价格,后续调用按该价格计费。":v?"No exact price found. Choose a table entry or enter a custom quote.":"尚未命中参考价格,可选择价格表条目或填写自定义价格。"):null,j==="local"?e("p",{className:"cm-source-explanation"},v?"Tokens are tracked; new calls have zero API cost.":"保留 Token 统计,后续调用的 API 费用记为 0。"):null,ae?null:e("button",{type:"button",className:"cm-model-dismiss",title:f("removePriceMatchHint"),onClick:()=>L(i)},f("overrideRemove"))):null)};return e("div",{className:"cm-model-matching"},e(Se,{state:a,draft:r,setDraft:n,locale:t}),e("div",{className:"cm-model-toolbar"},e("input",{type:"search",className:"cm-input",value:u,placeholder:v?"Find a model or channel…":"查找模型或渠道…","aria-label":v?"Find configured models":"查找已用模型",onChange:i=>{w(i.target.value),x(24)},onKeyDown:i=>{i.key==="Escape"&&(w(""),x(24),i.stopPropagation())}}),e("span",{className:"cm-note",role:"status"},v?`${h} models`:`${h} 个模型`)),A.length?e("div",{className:"cm-model-list"},e("div",{className:"cm-model-columns","aria-hidden":!0},e("span",null,v?"Model / channel":"模型 / 渠道"),e("span",{className:"cm-rate-summary"},...[v?"Input":"输入",v?"Cached input":"缓存读取",v?"Output":"输出"].map(i=>e("span",{key:i},i))),e("span",{title:v?"Per 1M tokens":"每百万 Token"},"/ 1M tok")),...A.map(I)):null,h===0?e("p",{className:"cm-pricing-empty"},u?v?"No models found. Try another keyword.":"没有找到模型,试试其他关键词。":v?"Models appear here after their first call.":"调用过的模型会显示在这里,之后可按渠道设置价格。"):null,h>l?e("button",{type:"button",className:"cm-btn",onClick:()=>x(i=>i+24)},v?`Show more · ${h-l} remaining`:`显示更多 · 还有 ${h-l} 个`):null,P.length>0?e("button",{type:"button",className:"cm-btn small",onClick:()=>b("priceMatchDismissed",[])},f("restorePriceMatches",{count:P.length})):null,e("details",{className:"cm-pricing-rules"},e("summary",null,v?"Automatic matching rules":"自动匹配规则"),e("label",{className:"cm-field"},e("span",null,f("priceMatchLabel")),e("select",{className:"cm-input",value:r?.priceMatch==="exact"?"exact":"auto",onChange:i=>b("priceMatch",i.target.value)},e("option",{value:"auto"},f("priceMatchAuto")),e("option",{value:"exact"},f("priceMatchExact")))),e("p",{className:"cm-note"},f("priceMatchNote"))))}function xe({open:a,className:r}){return e("svg",{className:"cm-pricing-chevron "+r+(a?" is-open":""),width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.8,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0},e("path",{d:"m9 5 7 7-7 7"}))}function _e({state:a,draft:r,setDraft:n,t:f,locale:t,rpc:o,renderEditor:d,vendorLabels:b,priceEditor:g}){const u=t==="en",[w,l]=C(""),[x,m]=C(""),[c,s]=C({}),[k,D]=C({}),[M,v]=C(null),[N,S]=C(""),P=r?.prices??a.config.prices,_=G(()=>({...P.providers,deepseek:{models:{...P.models,__default__:P.default}}}),[P.models,P.default,P.providers]),T=Object.keys(_).filter(p=>Object.keys(_[p]?.models??{}).length).sort((p,L)=>p===L?0:p==="deepseek"?-1:L==="deepseek"?1:p.localeCompare(L)),y=w.toLowerCase().trim().split(/\s+/).filter(Boolean),H=T.filter(p=>!x||x===p).map(p=>({id:p,ids:Object.keys(_[p].models).filter(L=>y.every(U=>(p+" "+(b[p]??"")+" "+(L==="__default__"?f("defaultModelId"):L)).toLowerCase().includes(U))).sort((L,U)=>L===U?0:L==="__default__"?1:U==="__default__"?-1:L.localeCompare(U))})).filter(p=>p.ids.length),W=H.reduce((p,L)=>p+L.ids.length,0),B=p=>{l(p),D({}),s({})},F=()=>{const p=N.trim().toLowerCase();!r||!/^[a-z0-9_.-]+$/.test(p)||Object.hasOwn(P.models,p)||(n({...r,prices:{...P,models:{...P.models,[p]:{cacheHit:0,cacheMiss:0,output:0}}}}),S(""),m("deepseek"),l(p),s(L=>({...L,deepseek:!0})),v("deepseek:"+p))};return e("div",{className:"cm-reference-prices"},e("p",{className:"cm-note"},u?"Base rates include multipliers. Open a model to edit rates, currencies and peak/off-peak tiers.":"列表展示含倍率的基础单价。点开模型可编辑币种、单价和峰谷档位。"),e("div",{className:"cm-catalog-toolbar"},e("input",{type:"search",className:"cm-input",value:w,"aria-label":u?"Search mounted prices":"搜索已挂载价格",placeholder:u?"Search models or providers…":"搜索模型或厂商…",onChange:p=>B(p.target.value),onKeyDown:p=>{p.key==="Escape"&&(B(""),p.stopPropagation())}}),e("select",{className:"cm-input",value:x,"aria-label":u?"Filter price provider":"筛选价格厂商",onChange:p=>{m(p.target.value),D({}),s({})}},e("option",{value:""},u?"All providers":"全部厂商"),...T.map(p=>e("option",{key:p,value:p},b[p]??p))),e("span",{className:"cm-note",role:"status"},u?`${W} models`:`${W} 个模型`)),...H.map(({id:p,ids:L})=>{const U=c[p]??(p==="deepseek"||y.length>0||x===p),ee=p==="deepseek"?P.currency??"USD":"USD",$=k[p]??16;return e("section",{key:p,className:"cm-catalog-group"},e("button",{type:"button",className:"cm-catalog-vendor cm-vendor-toggle","aria-expanded":U,onClick:()=>s(h=>({...h,[p]:!U}))},e("span",null,e(xe,{className:"cm-catalog-caret",open:U}),b[p]??p,e("small",null,L.length)),e("span",{className:"cm-catalog-unit"},ee+(u?" / 1M tokens":" / 百万 Token"))),U?e("div",{className:"cm-catalog-list"},e("div",{className:"cm-catalog-columns","aria-hidden":!0},...[u?"Model":"模型",u?"Input":"输入",u?"Cached input":"缓存读取",u?"Output":"输出",""].map((h,A)=>e("span",{key:A},h))),...L.slice(0,$).map(h=>{const A=p+":"+h,I=_[p].models[h],i=M===A,O=h==="__default__"?f("defaultModelId"):h,R=I?.peak||I?.offPeak?u?"Peak / off-peak":"含峰谷价格":I?.longContext?u?"Long context":"含长上下文档位":I?.cny?u?"USD + CNY":"美元 / 人民币":null;return e("div",{key:A,className:"cm-catalog-entry"+(i?" editing":"")},e("button",{type:"button",className:"cm-catalog-model","aria-label":O+(u?" · Edit price":" · 编辑价格"),"aria-expanded":i,onClick:()=>v(i?null:A)},e("span",{className:"cm-catalog-model-name"},e("strong",null,O),R?e("small",null,R):null),e(be,{entry:I,currency:ee,priceEditor:g,locale:t}),e(xe,{className:"cm-catalog-edit-caret",open:i})),i?e("div",{className:"cm-catalog-editor"},d(p,h,I),e(fe,{value:I,locale:t,defaults:P.providers?.[p]?.peakWindows??r.peakWindows,onChange:E=>{const Y=p==="deepseek"?{...P,...h==="__default__"?{default:E}:{models:{...P.models,[h]:E}}}:{...P,providers:{...P.providers,[p]:{...P.providers[p],models:{...P.providers[p].models,[h]:E}}}};n({...r,prices:Y})}})):null)}),L.length>$?e("button",{type:"button",className:"cm-catalog-more",onClick:()=>D(h=>({...h,[p]:$+16}))},u?`Show more · ${L.length-$} remaining`:`显示更多 · 还有 ${L.length-$} 个`):null):null)}),W===0?e("p",{className:"cm-pricing-empty"},u?"No matching models.":"没有找到匹配的模型。"):null,e("details",{className:"cm-pricing-rules"},e("summary",null,u?"Pricing notes":"计价说明"),e("p",{className:"cm-note"},f("priceTableNote"))),e("details",{className:"cm-catalog-manage"},e("summary",null,u?"Add or restore models":"添加与恢复模型"),e("div",{className:"cm-catalog-add"},e("input",{className:"cm-input",value:N,"aria-label":f("newModelPlaceholder"),placeholder:f("newModelPlaceholder"),onChange:p=>S(p.target.value),onKeyDown:p=>{p.key==="Enter"&&(p.preventDefault(),F())}}),e("button",{type:"button",className:"cm-btn small",disabled:!/^[a-z0-9_.-]+$/.test(N.trim().toLowerCase())||Object.hasOwn(P.models,N.trim().toLowerCase()),onClick:F},f("addModel"))),e(ge,{state:a,draft:r,setDraft:n,locale:t,rpc:o})))}function Oe({state:a,locale:r,formatMoneyUsd:n,api:f,rpc:t,disabled:o}){const[d,b]=C(!1),[g,u]=C(!1),[w,l]=C(""),[x,m]=C([]),[c,s]=C(""),[k,D]=C(""),M=r==="en",v=(y,H)=>{const W=a.config.currency==="CNY"?"Cny":a.config.currency==="EUR"?"Eur":"",B=W&&y[H+W],F=Number(a.config.exchangeRate);return n(typeof B=="number"&&F>0?B/F:y[H],a.config)},N=M?"All models":"全部模型",S=G(()=>[...new Set([a.today,a.month,...a.history??[]].flatMap(y=>Object.keys(y?.byProviderModel??{})))].filter(y=>y.indexOf(":")>0).sort(),[a.today,a.month,a.history]),P=G(()=>[{value:"",label:N},...S.map(y=>({value:y,label:y}))],[S,N]),_=()=>t("getRepricingHistory").then(y=>{m(re.parse(y)),s("")}).catch(y=>s(String(y.message??y)));te(()=>{let y=!0;return t("getRepricingHistory").then(H=>{y&&m(re.parse(H))},H=>{y&&s(String(H.message??H))}),()=>{y=!1}},[t]);const T=async()=>{if(!(!d||g||o)){u(!0),s(""),l("");try{const y=k?await t("repriceModelHistory",!0,k):await t("repriceHistory",!0);if(!y.ok)throw new Error(y.message);l(y.message),b(!1),await _(),await f.reload()}catch(y){s(String(y.message??y))}finally{u(!1)}}};return e("section",{className:"cm-repricing"},e("h3",{className:"cm-h"},M?"Historical pricing":"历史费用"),e("p",{className:"cm-note"},M?"Rate changes apply to new calls. Recorded historical rates remain fixed.":"修改价格只影响后续调用,历史费用沿用原价格。"),e("div",{className:"cm-repricing-scope"},e("label",null,M?"Recalculation scope":"重算范围"),e(me,{options:P,value:k,locale:r,label:M?"Choose channel and model":"选择渠道与模型",ariaLabel:M?"Choose channel and model":"选择渠道与模型",placeholder:M?"Search historical models":"搜索历史渠道或模型",onChange:y=>{g||(D(y),b(!1),l(""))}}),e("p",{className:"cm-hint"},k?M?"Only this channel/model changes. Other models and original exchange rates remain unchanged.":"仅重算此渠道下的这个模型,其他模型及原调用汇率保持不变。":M?"Choose a single channel/model to limit the recalculation.":"可选择单个渠道模型,缩小重算范围。")),d?e("div",{className:"cm-repricing-warning",role:"alert",onKeyDown:y=>{y.key==="Escape"&&!g&&(b(!1),y.stopPropagation())}},e("strong",null,(k||N)+(M?" · Historical amounts will change":" · 将修改历史费用")),e("p",null,M?"Recalculate retained calls using current rates and replace their amounts in statistics. Original amounts, price versions and a full ledger backup are kept. Records with incomplete logs are unchanged.":"确认后,将按当前价格重新计算保留的历史调用,并更新统计金额。原金额、原价格版本和完整账本备份都会保留;日志不完整的记录不改。"),e("div",{className:"cm-buttons"},e("button",{type:"button",className:"cm-btn",disabled:g,onClick:()=>b(!1)},M?"Cancel":"取消"),e("button",{type:"button",className:"cm-btn danger",disabled:g||o,onClick:T},g?M?"Recalculating…":"正在重算…":M?"Confirm recalculation":"确认重算"))):e("button",{type:"button",className:"cm-btn",disabled:o||g,onClick:()=>b(!0)},k?M?"Recalculate this model":"重算此模型的历史费用":M?"Recalculate history at current rates":"按当前价格重算历史"),w?e("p",{role:"status",className:"cm-note"},w):null,c?e("p",{role:"alert",className:"cm-err"},c):null,x.length?e("details",{className:"cm-repricing-history"},e("summary",null,M?"Recalculation records · original amounts retained":"重算记录 · 原金额已保留"),e("div",{className:"cm-stat-scroll"},e("table",{className:"cm-stat-table"},e("thead",null,e("tr",null,...(M?["Time","Scope","Before","After","Session/day records"]:["重算时间","范围","原金额","重算后","会话日期记录"]).map(y=>e("th",{key:y,scope:"col"},y)))),e("tbody",null,...x.map(y=>e("tr",{key:y.at},e("td",null,new Date(y.at).toLocaleString(r)),e("td",null,y.model||N),e("td",null,v(y,"before")),e("td",null,v(y,"after")),e("td",null,y.sessions))))))):null)}function ze({state:a,draft:r,setDraft:n,locale:f}){const t=r??a.config,o=(l,x)=>f==="en"?x:l,d=Object.keys(a.total?.byProviderModel??{}).filter(l=>l.indexOf(":")>0).map(l=>l.slice(0,l.indexOf(":"))),b=[...new Set([...d,...Object.keys(t.planBilling?.providers??{})])],[g,u]=C(d[0]??"go"),w=b.includes(g)?g:b[0]??"go";return e("section",{className:"cm-budget","data-provider-billing":!0},e("h3",{className:"cm-h"},o("渠道计费方式","Channel billing")),e("div",{className:"cm-grid"},e("label",{className:"cm-field"},e("span",null,o("渠道","Channel")),e("select",{className:"cm-input","aria-label":o("计费渠道","Billing channel"),value:w,onChange:l=>u(l.target.value)},b.map(l=>e("option",{value:l,key:l},l==="go"?"OpenCode Go (go)":l)))),e("label",{className:"cm-field"},e("span",null,o("计费方式","Billing type")),e("select",{className:"cm-input","aria-label":o("渠道计费方式","Channel billing type"),value:t.planBilling?.providers?.[w]??"auto",disabled:r==null,onChange:l=>n({...t,planBilling:{...t.planBilling,providers:{...t.planBilling?.providers,[w]:l.target.value}}})},[["auto",o("自动","Automatic")],["plan",o("Plan 订阅","Plan subscription")],["api",o("API 按量","Metered API")]].map(([l,x])=>e("option",{value:l,key:l},x))))),e("p",{className:"cm-note"},o("适用于该渠道的所有模型,模型单独设置优先。修改后更新历史 API/Plan 归属,保留 Token 和 API 等值金额。额度查询开关单独控制。","Applies to all models on this channel; model overrides take priority. Changes update historical API/Plan classification while preserving tokens and API-equivalent amounts. Quota queries are controlled separately.")))}function Ee({state:a,t:r,formatMoneyUsd:n,formatTokens:f,helpers:t}){const{Card:o,displayCostOf:d}=t,b=a.externalUsage;if(!b)return null;const g=a.config,u=c=>n(d(c,g),g),w=c=>r("callsTokens",{calls:c.calls,input:f(c.input),cache:f(c.cacheRead+c.cacheWrite),output:f(c.output)}),l=(c,s)=>({calls:c.calls+s.calls,input:c.input+s.input,output:c.output+s.output,cacheRead:c.cacheRead+s.cacheRead,cacheWrite:c.cacheWrite+s.cacheWrite,cost:d(c,g)+s.cost,apiCost:d(c,g)+s.cost}),x=(c,s)=>e("tr",{key:c},e("td",null,c),e("td",{className:"num"},String(s.calls)),e("td",{className:"num"},f(s.input)),e("td",{className:"num"},f(s.cacheRead+s.cacheWrite)),e("td",{className:"num"},f(s.output)),e("td",{className:"num"},u(s))),m=c=>e("div",{className:"cm-scroll"},e("table",{className:"cm-table"},e("thead",null,e("tr",null,e("th",null,r("colDate")),...["colCalls","colInTok","colCacheTok","colOutTok","colCost"].map(s=>e("th",{className:"num"},r(s))))),e("tbody",null,c)));return e("section",{className:"cm-budget"},e("h3",{className:"cm-h"},r("externalUsage")),b.stale?e("p",{className:"cm-note"},r("externalStale")):null,e("div",{className:"cm-cards"},["today","month","total"].map((c,s)=>{const k=l(a[c],b.combined[c]);return e(o,{key:c,title:r("combinedUsage")+" · "+r(["cardToday","cardMonth","cardTotal"][s]),value:u(k),sub:w(k)})})),...b.sources.map(c=>e("details",{key:c.source},e("summary",null,c.source+" · "+r("cardToday")+" "+u(c.today)+" · "+r("cardMonth")+" "+u(c.month)+" · "+w(c.today)),m(["today","month","total"].map((s,k)=>x(r(["cardToday","cardMonth","cardTotal"][k]),c[s]))),e("p",{className:"cm-note"},r("externalHistory")),m(c.history.map(s=>x(s.date,s))))))}function De({state:a,onPrices:r}){const n=a.config,f=(n.locale==="auto"?n.activeLocale:n.locale)==="en",t=(b,g)=>f?g:b,o=n.prices?.currency==="CNY"?"CNY":"USD",d=n.currency==="CNY"&&o==="USD";return e("details",{className:"cm-note","data-billing-check":!0,open:d||void 0},e("summary",null,t("计费核对","Check billing")),e("p",null,t("当前 DeepSeek 价表:","Active DeepSeek price table: ")+o+t(";显示币种:","; display currency: ")+n.currency),d?e("p",{"data-billing-currency-mismatch":!0},t("当前金额由美元单价换算,美元价 × 汇率不等于官网人民币报价。按人民币账单核对时,请选择人民币官方价并同步;只切换显示币种不会更换价表。","Amounts currently convert USD rates. USD rates × exchange rate differ from official CNY prices. To compare with a CNY bill, select CNY official prices and sync them; changing the display currency does not change the price table.")):null,n.pricingCurrency!==o?e("p",null,t("所选同步币种尚未生效,当前仍使用 ","The selected sync currency is not active yet; billing still uses ")+o):null,e("p",null,t("金额口径:","Cost basis: ")+t(n.showTotalWithPlan?"含套餐 API 等值,不等于账户扣款。":"API 费用;套餐等值已排除。",n.showTotalWithPlan?"Includes subscription API-equivalent costs, not account deductions.":"API costs; subscription equivalents are excluded.")),e("p",null,t("核对时使用同一账户、渠道和时段;费用明细可查看每次调用的缓存、输出、费率和搜索请求费。自定义价格、倍率与历史价表也会影响金额。","Compare the same account, provider and time range. Cost details show each call’s cache, output, rates and search request fees. Custom prices, multipliers and historical rates also affect totals.")),r?e("button",{type:"button",className:"cm-btn small",onClick:r},t("查看并同步官方价表","Review and sync official prices")):null)}async function Te(a){const r=await a.get("remote").$mount(ue);a.effect(()=>()=>r(),"cost-meter: pricing settings contribution");const n=a.get("remote.costMeter"),f=async(o,...d)=>{(o==="repriceHistory"||o==="repriceModelHistory")&&le.parse(d[0]),o==="repriceModelHistory"&&de.parse(d[1]);const b=await n[o](...d);if(b?.ok!==!0)throw new Error(b?.error?.message??"Pricing request failed");return(o==="getPriceCatalog"?pe:o==="getRepricingHistory"?re:ne).parse(b.value)},t=document.createElement("style");return t.textContent=".cm-repricing-scope{display:grid;gap:8px;max-width:620px;margin:16px 0}.cm-repricing-scope>label{font-size:13px;color:var(--dsw-alias-label-secondary)}.cm-repricing-scope .cm-hint{margin:0;line-height:1.6}",t.textContent+=".cm-price-search{display:grid;gap:6px;min-width:0}.cm-price-search small{color:var(--dsw-alias-label-tertiary)}.cm-price-search select,.cm-price-search input{width:100%;min-width:0}.cm-repricing-warning{padding:12px;border:1px solid var(--dsw-alias-state-warn-primary,#c58a25);border-radius:10px;background:var(--dsw-alias-bg-layer-1)}.cm-repricing-warning p{margin:8px 0 12px;line-height:1.6}.cm-repricing-history{margin-top:12px}.cm-repricing-history table{width:100%;text-align:left;font-variant-numeric:tabular-nums}.cm-repricing-history td,.cm-repricing-history th{padding:8px;border-bottom:1px solid var(--dsw-alias-border-l1)}",t.textContent+=".cm-repricing-history .cm-stat-scroll{overflow-x:auto;max-width:100%}.cm-repricing-history table{min-width:560px}.cm-repricing-history th{white-space:nowrap}.cm-repricing-history td:nth-child(2){min-width:150px;max-width:260px;overflow-wrap:anywhere}",t.textContent+=".cm-pricing-page .cm-free-model{margin:0 0 12px;padding:10px 12px;border:1px solid var(--dsw-alias-border-l1);border-radius:8px;background:transparent}.cm-pricing-page .cm-free-model>.cm-check{display:flex;align-items:center;gap:8px;margin:0;font-size:12px;line-height:20px;color:var(--dsw-alias-label-primary)}.cm-pricing-page .cm-free-model input{flex:none;width:16px;height:16px;margin:0;accent-color:var(--dsw-alias-state-business-primary)}.cm-pricing-page .cm-free-model>.cm-hint{display:block;margin:4px 0 0 24px;font-size:11px;line-height:1.5}",t.textContent+=".cm-provider-schedules{margin:12px 0}.cm-provider-schedules>.cm-field{max-width:360px;margin:12px 0}.cm-peak-schedule,.cm-custom-more fieldset{min-width:0;margin:12px 0;padding:12px;border:1px solid var(--dsw-alias-border-l1);border-radius:8px}.cm-peak-schedule{display:grid;gap:12px}.cm-custom-more .cm-check{display:flex;align-items:center;gap:8px;margin:12px 0}.cm-custom-more .cm-check input{width:auto;flex:none;margin:0}.cm-peak-schedule legend{font-size:12px}.cm-peak-schedule .cm-hint{margin:0;line-height:1.6}",t.textContent+=".cm-custom-price{grid-column:1/-1;display:grid;gap:14px;margin:4px 0 12px;padding:16px;border:1px solid var(--dsw-alias-border-l1);border-radius:var(--dsw-radius-lg,12px);background:var(--dsw-alias-bg-layer-1);min-width:0}.cm-custom-price legend{padding:0 6px;font-weight:500;font-size:13px}.cm-custom-price label{display:grid;gap:7px;font-size:12px;min-width:0;color:var(--dsw-alias-label-secondary)}.cm-custom-price .cm-input{width:100%;min-width:0}.cm-custom-head{display:flex;justify-content:space-between;align-items:center;gap:12px;color:var(--dsw-alias-label-secondary);font-size:12px}.cm-custom-head label{display:flex;align-items:center;gap:8px}.cm-custom-head select{width:auto!important}.cm-custom-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:12px}.cm-custom-amount{position:relative;display:block}.cm-custom-amount>span{position:absolute;inset-inline-start:11px;top:50%;transform:translateY(-50%);pointer-events:none;color:var(--dsw-alias-label-tertiary)}.cm-custom-amount input{padding-inline-start:28px}.cm-custom-more summary{cursor:pointer;font-size:12px;color:var(--dsw-alias-label-secondary)}.cm-custom-more .cm-custom-grid{grid-template-columns:repeat(2,minmax(0,1fr));margin:12px 0 8px}.cm-custom-price p{margin:0;line-height:1.6}@media(max-width:700px){.cm-custom-grid{grid-template-columns:1fr}.cm-custom-head{flex-wrap:wrap}}",document.head.appendChild(t),t.textContent+=`
2
2
  .cm-model-matching{display:grid;gap:12px;min-width:0;container:cm-models / inline-size;overflow-anchor:none}
3
3
  .cm-pricing-intro{display:grid;gap:6px}.cm-pricing-intro p{line-height:1.65}
4
4
  .cm-model-toolbar{display:flex;align-items:center;gap:12px}.cm-model-toolbar>.cm-input{flex:1;width:100%;min-width:0;box-sizing:border-box}.cm-model-toolbar>.cm-note{white-space:nowrap}
@@ -27,4 +27,4 @@ window.__ModuleLoader__.load({id:"dsh-cost-meter",chunk:"client.pricing.js",fact
27
27
  @container cm-price-list (max-width:560px){.cm-catalog-columns{display:none}.cm-catalog-model{grid-template-columns:repeat(3,minmax(0,1fr));gap:14px}.cm-catalog-model-name{grid-column:1/-1;padding-inline-end:20px}.cm-catalog-model .cm-rate-item>span{display:block}.cm-catalog-edit-caret{position:absolute;inset-inline-end:16px;top:12px}.cm-catalog-unit{font-size:10px}.cm-catalog-editor{padding:0 10px 10px}}
28
28
  @container cm-price-editor (max-width:520px){.cm-price-row.cm-price-columns{display:none}.cm-price-row:not(.cm-price-columns){grid-template-columns:repeat(2,minmax(0,1fr));gap:12px;padding:10px;border:1px solid var(--dsw-alias-border-l1);border-radius:8px}.cm-price-row>span:first-child{grid-column:1/-1;font-weight:600;color:var(--dsw-alias-label-secondary)}.cm-price-cell>.cm-price-cell-label{display:block;font-size:11px;line-height:1.5}}
29
29
  @media(max-width:480px){.cm-source-choices{grid-template-columns:repeat(2,minmax(0,1fr))}.cm-catalog-toolbar>select{flex:1 1 140px}}
30
- `,t.textContent+=[".cm-price-search{display:block;min-width:0}",".cm-combo-control{position:relative;display:flex;align-items:center;min-width:0}",".cm-combo .cm-input{width:100%;min-width:0;padding-right:46px;text-overflow:ellipsis}",".cm-combo .cm-combo-input::-webkit-search-cancel-button{display:none}",".cm-combo-clear,.cm-combo-caret{position:absolute;display:flex;align-items:center;justify-content:center;width:18px;height:18px;padding:0;border:0;background:transparent;color:var(--dsw-alias-label-tertiary);line-height:1;cursor:pointer}",".cm-combo-clear{right:26px;border-radius:50%;font-size:14px}",".cm-combo-clear:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.14));color:var(--dsw-alias-label-primary)}",".cm-combo-caret{right:6px;font-size:10px}",".cm-combo-panel{position:fixed;z-index:10000;display:flex;flex-direction:column;gap:2px;box-sizing:border-box;padding:4px;border-radius:12px;background:var(--cm-opaque-base,#fff);background:rgb(from var(--dsw-alias-bg-layer-2,var(--dsw-alias-bg-base,#fff)) r g b / 1);box-shadow:var(--dsw-elevation-panel,0 3px 8px rgba(0,0,0,.06),0 0 16px rgba(0,0,0,.04))}",".cm-combo-list{display:flex;flex-direction:column;gap:2px;min-height:0;overflow:auto;overscroll-behavior:contain;scrollbar-width:thin}",".cm-combo-option{flex:none;font:inherit;font-size:12px;line-height:1.5;text-align:left;padding:6px 8px;border:0;border-radius:6px;background:transparent;color:var(--dsw-alias-label-primary);cursor:pointer;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}",".cm-combo-option.active{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.14))}",'.cm-combo-option[aria-selected="true"]{color:var(--dsw-alias-state-business-primary);font-weight:600}',".cm-combo-note{margin:0;padding:4px 8px;font-size:10px;color:var(--dsw-alias-label-tertiary)}",".cm-match-row .cm-combo{flex:1;min-width:160px}",".cm-repricing-warning{padding:12px;border:1px solid var(--dsw-alias-state-warn-primary,#c58a25);border-radius:10px;background:var(--dsw-alias-bg-layer-1)}.cm-repricing-warning p{margin:8px 0 12px;line-height:1.6}.cm-repricing-history{margin-top:12px}.cm-repricing-history table{width:100%;text-align:left;font-variant-numeric:tabular-nums}.cm-repricing-history td,.cm-repricing-history th{padding:8px;border-bottom:1px solid var(--dsw-alias-border-l1)}",'@media (max-width:1023px){.cm-custom-grid,.cm-effective-grid,.cm-rate-summary{grid-template-columns:1fr}.cm-model-toolbar,.cm-custom-head,.cm-catalog-toolbar{flex-wrap:wrap}.cm-repricing-history table{min-width:480px}.cm-model-matching .cm-match-row{padding:8px 10px}}body[data-dsh-pocket-layout="mobile"] .cm-custom-grid{grid-template-columns:1fr}body[data-dsh-pocket-layout="mobile"] .cm-rate-summary{grid-template-columns:1fr}'].join(""),a.effect(()=>()=>t.remove(),"cost-meter: pricing settings styles"),o=>o.mode==="peak-settings"?e(Ce,o):o.mode==="schedule"?e(Me,o):o.mode==="billing"?e(ze,o):o.mode==="matching"?e(Se,o):e(o.mode==="catalog"?Ae:o.mode==="restore"?ge:Oe,{...o,rpc:v})}return{mount:Ee,CONTRIBUTION:ue}}});
30
+ `,t.textContent+=[".cm-price-search{display:block;min-width:0}",".cm-combo-control{position:relative;display:flex;align-items:center;min-width:0}",".cm-combo .cm-input{width:100%;min-width:0;padding-right:46px;text-overflow:ellipsis}",".cm-combo .cm-combo-input::-webkit-search-cancel-button{display:none}",".cm-combo-clear,.cm-combo-caret{position:absolute;display:flex;align-items:center;justify-content:center;width:18px;height:18px;padding:0;border:0;background:transparent;color:var(--dsw-alias-label-tertiary);line-height:1;cursor:pointer}",".cm-combo-clear{right:26px;border-radius:50%;font-size:14px}",".cm-combo-clear:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.14));color:var(--dsw-alias-label-primary)}",".cm-combo-caret{right:6px;font-size:10px}",".cm-combo-panel{position:fixed;z-index:10000;display:flex;flex-direction:column;gap:2px;box-sizing:border-box;padding:4px;border-radius:12px;background:var(--cm-opaque-base,#fff);background:rgb(from var(--dsw-alias-bg-layer-2,var(--dsw-alias-bg-base,#fff)) r g b / 1);box-shadow:var(--dsw-elevation-panel,0 3px 8px rgba(0,0,0,.06),0 0 16px rgba(0,0,0,.04))}",".cm-combo-list{display:flex;flex-direction:column;gap:2px;min-height:0;overflow:auto;overscroll-behavior:contain;scrollbar-width:thin}",".cm-combo-option{flex:none;font:inherit;font-size:12px;line-height:1.5;text-align:left;padding:6px 8px;border:0;border-radius:6px;background:transparent;color:var(--dsw-alias-label-primary);cursor:pointer;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}",".cm-combo-option.active{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.14))}",'.cm-combo-option[aria-selected="true"]{color:var(--dsw-alias-state-business-primary);font-weight:600}',".cm-combo-note{margin:0;padding:4px 8px;font-size:10px;color:var(--dsw-alias-label-tertiary)}",".cm-match-row .cm-combo{flex:1;min-width:160px}",".cm-repricing-warning{padding:12px;border:1px solid var(--dsw-alias-state-warn-primary,#c58a25);border-radius:10px;background:var(--dsw-alias-bg-layer-1)}.cm-repricing-warning p{margin:8px 0 12px;line-height:1.6}.cm-repricing-history{margin-top:12px}.cm-repricing-history table{width:100%;text-align:left;font-variant-numeric:tabular-nums}.cm-repricing-history td,.cm-repricing-history th{padding:8px;border-bottom:1px solid var(--dsw-alias-border-l1)}",'@media (max-width:1023px){.cm-custom-grid,.cm-effective-grid,.cm-rate-summary{grid-template-columns:1fr}.cm-model-toolbar,.cm-custom-head,.cm-catalog-toolbar{flex-wrap:wrap}.cm-repricing-history table{min-width:480px}.cm-model-matching .cm-match-row{padding:8px 10px}}body[data-dsh-pocket-layout="mobile"] .cm-custom-grid{grid-template-columns:1fr}body[data-dsh-pocket-layout="mobile"] .cm-rate-summary{grid-template-columns:1fr}'].join(""),a.effect(()=>()=>t.remove(),"cost-meter: pricing settings styles"),o=>o.mode==="external"?e(Ee,o):o.mode==="check"?e(De,o):o.mode==="peak-settings"?e(Ce,o):o.mode==="schedule"?e(Me,o):o.mode==="billing"?e(ze,o):o.mode==="matching"?e(Ae,o):e(o.mode==="catalog"?_e:o.mode==="restore"?ge:Oe,{...o,rpc:f})}return{mount:Te,CONTRIBUTION:ue}}});
@@ -1,2 +1,2 @@
1
- window.__ModuleLoader__.load({id:"dsh-cost-meter",chunk:"client.session-list.js",factory:B=>{const D=B("react"),{createElement:k,useEffect:Q,useRef:W,useSyncExternalStore:x}=D,N=e=>{if(typeof e!="number"||!Number.isFinite(e))throw Error("Invalid session amount");return e},F=e=>{if(typeof e!="string")throw Error("Invalid session identity");return e},A=e=>{if(!Array.isArray(e?.sessionIds)||e.sessionIds.length>100||!e.sessionIds.every(t=>typeof t=="string"&&t.length>0&&t.length<=512)||!["total","today"].includes(e.period))throw Error("Invalid session list query");return{sessionIds:e.sessionIds,period:e.period}},L=e=>{if(!Array.isArray(e))throw Error("Invalid session list amounts");return e.map(t=>{if(typeof t?.found!="boolean")throw Error("Invalid session amount status");return{id:F(t.id),found:t.found,...Object.fromEntries(["input","output","cacheRead","cacheWrite","calls","cost"].map(s=>[s,N(t[s])])),...Object.fromEntries(["apiCost","reasoning","costCny","apiCostCny","costEur","apiCostEur"].filter(s=>t[s]!==void 0).map(s=>[s,N(t[s])]))}})},T=(e,t)=>{const s={parse:t};return{mode:"strict",typeSymbol:"dsh-cost-meter#"+e,schema:s,create:()=>s}},_={package:"dsh-cost-meter-session-list",face:"host",descriptors:[{id:"dsh-cost-meter#costMeter/getSessionListCosts",service:"costMeter",namespace:"costMeter",method:"getSessionListCosts",invocation:{kind:"direct"},parameters:[{name:"query",wire:"query",source:"json",codec:T("SessionListQuery",A)}],result:T("SessionListCosts",L)}]};function q(e,t){const s=new Map,c=new Map,p=new Set;let m=0,u=0,h,y=!1,r=!1;const g=()=>{m++;for(const o of p)o()},d=()=>{!r&&!h&&(h=setTimeout(I,30))};async function I(){h=null;const o=t();if(r||y||!o?.config?.sessionListCosts||document.hidden)return;const a=[...s.keys()].filter(l=>Date.now()-(c.get(l)?.at??0)>=5e3).slice(0,100);if(!a.length)return;const w=u;y=!0;try{const l=L(await e({sessionIds:a,period:o.config.sessionListCostPeriod??"total"}));if(r||u!==w)return;for(const b of l)a.includes(b.id)&&c.set(b.id,{at:Date.now(),row:b});for(;c.size>500;)c.delete(c.keys().next().value);g()}catch{}finally{y=!1,!r&&(u!==w||[...s.keys()].some(l=>!a.includes(l)&&!c.has(l)))&&d()}}return{subscribe:o=>(p.add(o),()=>p.delete(o)),snapshot:()=>m,row:o=>c.get(o)?.row,show:o=>(s.set(o,(s.get(o)??0)+1),d(),()=>{const a=s.get(o)-1;a>0?s.set(o,a):s.delete(o)}),refresh:d,invalidate:()=>{u++,c.clear(),g(),d()},dispose:()=>{r=!0,u++,clearTimeout(h),s.clear(),c.clear(),p.clear()}}}async function J(e,t,s,{formatMoneyUsd:c,displayCostOf:p,formatTokens:m}){const u=await e.get("remote").$mount(_),h=e.get("remote.costMeter"),y=()=>t.getSnapshot().state,r=q(async n=>{const i=await h.getSessionListCosts(n);if(!i?.ok)throw Error("Session list amounts unavailable");return i.value},y),g=document.createElement("style");g.textContent=".cm-session-list-price{font-size:11px;color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums;white-space:nowrap;flex:none;order:-1}.cm-session-list-detail{font-size:12px;white-space:pre-line;color:var(--dsw-alias-label-secondary)}span:has(>.cm-session-list-price){display:inline-flex}:not(:hover):not(:focus-within)>span:has(>.cm-session-list-price)>:not(.cm-session-list-price){display:none}",document.head.append(g);function d({sessionId:n,detail:i=!1}){const S=x(t.subscribe,t.getSnapshot),O=S.state,v=O?.config??{},R=W(null);x(r.subscribe,r.snapshot);const M=v.sessionListCosts===!0;if(Q(()=>{if(!M||!n)return;let E;if(i||typeof IntersectionObserver>"u")return r.show(n);const P=new IntersectionObserver(U=>{U.some($=>$.isIntersecting)?E||(E=r.show(n)):(E?.(),E=null)});return R.current&&P.observe(R.current),()=>{P.disconnect(),E?.()}},[n,M,i]),!M)return null;const f=r.row(n),C=s(v)==="en",K=v.sessionListCostPeriod==="today"?C?"Today":"今日":C?"Total":"累计",z=f?.found?c(p(f,v),v):"—",j=K+" "+z+(f?.found?`
2
- `+(C?"Input ":"输入 ")+m(f.input)+" · "+(C?"Cache ":"缓存 ")+m(f.cacheRead+f.cacheWrite)+" · "+(C?"Output ":"输出 ")+m(f.output):"");return k(i?"div":"span",{ref:R,className:i?"cm-session-list-detail":"cm-session-list-price",title:j,"aria-label":j},i?j:z)}const I=e.get("slots"),o=[];for(const[n,i]of[["sidebar.workspaces.session.row.action",!1],["sidebar.session.row.hover",!0]]){const S=()=>I.register({name:n,id:"cost-meter-session-list",order:10},O=>k(d,{...O,detail:i}));o.push(I.inject(n,S))}let a;const w=()=>{const n=y(),i=JSON.stringify([n?.config?.sessionListCosts,n?.config?.sessionListCostPeriod,n?.config?.includeSubagentCost,n?.meta?.dayKey,n?.total?.calls,n?.total?.cost]);i!==a&&(a=i,r.invalidate())};w();const l=t.subscribe(w),b=setInterval(r.refresh,1e4);return document.addEventListener("visibilitychange",r.refresh),e.effect(()=>()=>{l(),clearInterval(b),document.removeEventListener("visibilitychange",r.refresh),r.dispose(),g.remove();for(const n of o)n?.();u()},"cost-meter: session list amounts"),{Row:d}}return{mount:J,CONTRIBUTION:_,createBatchReader:q,parseQuery:A,parseRows:L}}});
1
+ ;(function(L){const d=window.__ModuleLoader__,b=d[Symbol.for("@dsh-plugin/dsh-loader:load-wrap")];return(L.id==="dsh-cost-meter"&&d.load===b?.ours&&typeof b.original=="function"?b.original:d.load).call(d,L)})({id:"dsh-cost-meter",chunk:"client.session-list.js",factory:A=>{const L=A("react"),{createElement:d,useEffect:b,useRef:T,useSyncExternalStore:_}=L,q=e=>{if(typeof e!="number"||!Number.isFinite(e))throw Error("Invalid session amount");return e},F=e=>{if(typeof e!="string")throw Error("Invalid session identity");return e},z=e=>{if(!Array.isArray(e?.sessionIds)||e.sessionIds.length>100||!e.sessionIds.every(t=>typeof t=="string"&&t.length>0&&t.length<=512)||!["total","today"].includes(e.period))throw Error("Invalid session list query");return{sessionIds:e.sessionIds,period:e.period}},O=e=>{if(!Array.isArray(e))throw Error("Invalid session list amounts");return e.map(t=>{if(typeof t?.found!="boolean")throw Error("Invalid session amount status");return{id:F(t.id),found:t.found,...Object.fromEntries(["input","output","cacheRead","cacheWrite","calls","cost"].map(s=>[s,q(t[s])])),...Object.fromEntries(["apiCost","reasoning","costCny","apiCostCny","costEur","apiCostEur"].filter(s=>t[s]!==void 0).map(s=>[s,q(t[s])]))}})},P=(e,t)=>{const s={parse:t};return{mode:"strict",typeSymbol:"dsh-cost-meter#"+e,schema:s,create:()=>s}},B={package:"dsh-cost-meter-session-list",face:"host",descriptors:[{id:"dsh-cost-meter#costMeter/getSessionListCosts",service:"costMeter",namespace:"costMeter",method:"getSessionListCosts",invocation:{kind:"direct"},parameters:[{name:"query",wire:"query",source:"json",codec:P("SessionListQuery",z)}],result:P("SessionListCosts",O)}]};function D(e,t){const s=new Map,c=new Map,m=new Set;let h=0,u=0,y,g=!1,r=!1;const w=()=>{h++;for(const o of m)o()},f=()=>{!r&&!y&&(y=setTimeout(M,30))};async function M(){y=null;const o=t();if(r||g||!o?.config?.sessionListCosts||document.hidden)return;const a=[...s.keys()].filter(l=>Date.now()-(c.get(l)?.at??0)>=5e3).slice(0,100);if(!a.length)return;const v=u;g=!0;try{const l=O(await e({sessionIds:a,period:o.config.sessionListCostPeriod??"total"}));if(r||u!==v)return;for(const C of l)a.includes(C.id)&&c.set(C.id,{at:Date.now(),row:C});for(;c.size>500;)c.delete(c.keys().next().value);w()}catch{}finally{g=!1,!r&&(u!==v||[...s.keys()].some(l=>!a.includes(l)&&!c.has(l)))&&f()}}return{subscribe:o=>(m.add(o),()=>m.delete(o)),snapshot:()=>h,row:o=>c.get(o)?.row,show:o=>(s.set(o,(s.get(o)??0)+1),f(),()=>{const a=s.get(o)-1;a>0?s.set(o,a):s.delete(o)}),refresh:f,invalidate:()=>{u++,c.clear(),w(),f()},dispose:()=>{r=!0,u++,clearTimeout(y),s.clear(),c.clear(),m.clear()}}}async function J(e,t,s,{formatMoneyUsd:c,displayCostOf:m,formatTokens:h}){const u=await e.get("remote").$mount(B),y=e.get("remote.costMeter"),g=()=>t.getSnapshot().state,r=D(async n=>{const i=await y.getSessionListCosts(n);if(!i?.ok)throw Error("Session list amounts unavailable");return i.value},g),w=document.createElement("style");w.textContent=".cm-session-list-price{font-size:11px;color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums;white-space:nowrap;flex:none;order:-1}.cm-session-list-detail{font-size:12px;white-space:pre-line;color:var(--dsw-alias-label-secondary)}span:has(>.cm-session-list-price){display:inline-flex}:not(:hover):not(:focus-within)>span:has(>.cm-session-list-price)>:not(.cm-session-list-price){display:none}",document.head.append(w);function f({sessionId:n,detail:i=!1}){const R=_(t.subscribe,t.getSnapshot),j=R.state,E=j?.config??{},k=T(null);_(r.subscribe,r.snapshot);const x=E.sessionListCosts===!0;if(b(()=>{if(!x||!n)return;let S;if(i||typeof IntersectionObserver>"u")return r.show(n);const W=new IntersectionObserver(U=>{U.some($=>$.isIntersecting)?S||(S=r.show(n)):(S?.(),S=null)});return k.current&&W.observe(k.current),()=>{W.disconnect(),S?.()}},[n,x,i]),!x)return null;const p=r.row(n),I=s(E)==="en",K=E.sessionListCostPeriod==="today"?I?"Today":"今日":I?"Total":"累计",Q=p?.found?c(m(p,E),E):"—",N=K+" "+Q+(p?.found?`
2
+ `+(I?"Input ":"输入 ")+h(p.input)+" · "+(I?"Cache ":"缓存 ")+h(p.cacheRead+p.cacheWrite)+" · "+(I?"Output ":"输出 ")+h(p.output):"");return d(i?"div":"span",{ref:k,className:i?"cm-session-list-detail":"cm-session-list-price",title:N,"aria-label":N},i?N:Q)}const M=e.get("slots"),o=[];for(const[n,i]of[["sidebar.workspaces.session.row.action",!1],["sidebar.session.row.hover",!0]]){const R=()=>M.register({name:n,id:"cost-meter-session-list",order:10},j=>d(f,{...j,detail:i}));o.push(M.inject(n,R))}let a;const v=()=>{const n=g(),i=JSON.stringify([n?.config?.sessionListCosts,n?.config?.sessionListCostPeriod,n?.config?.includeSubagentCost,n?.meta?.dayKey,n?.total?.calls,n?.total?.cost]);i!==a&&(a=i,r.invalidate())};v();const l=t.subscribe(v),C=setInterval(r.refresh,1e4);return document.addEventListener("visibilitychange",r.refresh),e.effect(()=>()=>{l(),clearInterval(C),document.removeEventListener("visibilitychange",r.refresh),r.dispose(),w.remove();for(const n of o)n?.();u()},"cost-meter: session list amounts"),{Row:f}}return{mount:J,CONTRIBUTION:B,createBatchReader:D,parseQuery:z,parseRows:O}}});
@@ -1 +1 @@
1
- window.__ModuleLoader__.load({id:"dsh-cost-meter",chunk:"client.settings-overview.js",factory:B=>{const{createElement:o,Fragment:Q}=B("react");function C({state:i,snapshot:m,helpers:s,resolveLocale:P,formatMoneyUsd:T,formatTokens:N}){const t=i?.config??{activeLocale:m?.locale},b=P(t),l=s.makeT(b),g=(e,c)=>b==="en"?c:e,v=s.useCodexQuota(t.codexQuotaEnabled===!0,t.codexQuotaSource);if(!i)return o("div",{className:"cm-section",role:m?.error?"alert":"status"},m?.error||l(m?.status==="loading"?"readingLedger":"ledgerUnavailable"));const f=(e,c,n)=>o("section",{key:e,className:"cm-budget","data-overview-source":e},o("h3",{className:"cm-h"},c),n),d=e=>o("p",{className:"cm-note"},e),W=e=>e?.fetchedAt>0?d(l("goQuotaFetchedAt",{time:new Date(e.fetchedAt).toLocaleString(b==="en"?"en-US":"zh-CN")})):null,w=(e,c)=>o(Q,null,["ok","partial"].includes(e?.status)?c:o("p",{className:e?.status==="error"?"cm-err":"cm-note",role:e?.status==="error"?"alert":void 0},e?.message||l("codingPlanNotQueried")),["ok","partial"].includes(e?.status)&&e.message?d(e.message):null,W(e)),p=(e,c)=>{const n=(s.codingPlanWindowEntries?s.codingPlanWindowEntries(e,c):Object.entries(e??{})).filter(([,a])=>a!=null);return n.length?o("div",{className:"cm-go-list"},n.map(([a,u])=>s.quotaWindowRow(l,(u.label||s.codingPlanWindowLabel(a==="five"?"5h":a,l))+(typeof u.percent=="number"?g(" · 剩余"," · remaining"):""),u,"remaining",!1,a))):d(l("codingPlanNotQueried"))},r=[];if(t.balance?.display!=="off"&&t.hideOfficialBalance!==!0){const e=i.balance;r.push(f("balance",l("accountBalance"),w(e,o("div",{className:"cm-card-value cm-num"},e?.totalBalance==null?"—":s.formatBalanceMoney(e.totalBalance,t,e.currency)))))}if(t.goQuota?.enabled!==!1&&t.goQuota?.display!=="off"){const e=i.goQuota;r.push(f("go",l("goQuotaTitle"),w(e,p({[l("goWindowRolling")]:e?.rolling,[l("goWindowWeekly")]:e?.weekly,[l("goWindowMonthly")]:e?.monthly}))))}t.codexQuotaEnabled===!0&&r.push(f("codex",l("codexQuotaTitle"),w(v,p(v.windows))));for(const{id:e,labelKey:c}of s.CODING_PLAN_ROWS){const n=t.codingPlans?.[e],a=i.codingPlans?.[e];n?.enabled===!0&&n.display!=="off"&&r.push(f(e,l(c),w(a,p(a?.windows,e))))}(t.customBalances?.length?t.customBalances:t.customBalance?[t.customBalance]:[]).forEach((e,c)=>{if(!e.enabled||e.display==="off")return;const n=i.customBalances?.find(a=>a.index===c)??(c===0&&!i.customBalances?.length?i.customBalance:null);r.push(f("custom-"+c,b==="en"&&e.labelEn||e.label||l("customBalanceTitle"),w(n,o("div",{className:"cm-card-value cm-num"},n?.remaining==null?"—":s.formatCustomBalanceMoney(n.remaining,t,n,e)))))});for(const e of t.gatewayQuotas?.sources??[]){if(!e.enabled||e.display==="off")continue;const c=i.gatewayQuotas?.find(a=>a.id===e.id),n=(a,u)=>a?o("p",{key:u,className:"cm-note cm-num"},(a.label||a.unit||"Credits")+" · "+g("剩余 ","Remaining ")+(a.remaining??"—")+" / "+(a.limit??"—")):null;r.push(f("gateway-"+e.id,e.label||e.id,w(c,c?.accounts?.length?c.accounts.map((a,u)=>o("div",{key:a.id||u},o("h4",{className:"cm-h"},a.label||a.provider),a.message?d(a.message):null,p(Object.fromEntries((a.windows??[]).map((h,y)=>[h.id||y,h]))),n(a.credits),(a.credits?.packages??[]).map((h,y)=>n(h,h.id||y)))):d(l("gatewaySourceNoAccounts")))))}return o("div",{className:"cm-section","data-settings-overview":!0},d(g("费用和额度随当前数据更新。调整配置请前往「插件 → 费用计量」。","Costs and quotas update with the current data. Configure them in Plugins → Cost meter.")),m?.error?o("p",{className:"cm-err",role:"alert"},l("ledgerReadFailed",{message:m.error})):null,o("div",{className:"cm-overview-grid"},o("div",{className:"cm-cards",style:{"--cm-overview-count":t.hideTodayCost===!0?2:3}},[["today","cardToday"],["month","cardMonth"],["total","cardTotal"]].filter(([e])=>e!=="today"||t.hideTodayCost!==!0).map(([e,c])=>{const n=i[e];return o(s.Card,{key:e,title:l(c),value:T(s.displayCostOf(n,t),t),sub:l("callsTokens",{calls:n.calls,input:N(n.input),cache:N(n.cacheRead+n.cacheWrite),output:N(n.output)})})}))),d(l("cardsFootnote")),o(s.BillingAccuracyNote,{state:i}),d(l("cardsTogglePlanTotal")+": "+g(t.showTotalWithPlan?"已开启":"已关闭",t.showTotalWithPlan?"On":"Off")),t.budget?.enabled&&t.hideBudget!==!0?o(s.BudgetBoxContent,{state:i,wide:!0}):null,o("h3",{className:"cm-h"},g("余额与额度","Balances and quotas")),r.length?o("div",{className:"cm-quota-list"},r):d(g("尚未启用余额或额度来源。","No balance or quota sources enabled.")),o(s.UsagePanel,{state:i,t:l,locale:b}),o("h3",{className:"cm-h"},l("todaySessions")),o(s.TodaySessions,{state:i}))}return{mount:()=>C}}});
1
+ ;(function(a){const m=window.__ModuleLoader__,h=m[Symbol.for("@dsh-plugin/dsh-loader:load-wrap")];return(a.id==="dsh-cost-meter"&&m.load===h?.ours&&typeof h.original=="function"?h.original:m.load).call(m,a)})({id:"dsh-cost-meter",chunk:"client.settings-overview.js",factory:C=>{const{createElement:a,Fragment:m}=C("react");function h({state:s,snapshot:g,helpers:i,resolveLocale:P,formatMoneyUsd:T,formatTokens:v}){const t=s?.config??{activeLocale:g?.locale},b=P(t),l=i.makeT(b),f=(e,c)=>b==="en"?c:e,Q=i.useCodexQuota(t.codexQuotaEnabled===!0,t.codexQuotaSource);if(!s)return a("div",{className:"cm-section",role:g?.error?"alert":"status"},g?.error||l(g?.status==="loading"?"readingLedger":"ledgerUnavailable"));const w=(e,c,n)=>a("section",{key:e,className:"cm-budget","data-overview-source":e},a("h3",{className:"cm-h"},c),n),r=e=>a("p",{className:"cm-note"},e),W=e=>e?.fetchedAt>0?r(l("goQuotaFetchedAt",{time:new Date(e.fetchedAt).toLocaleString(b==="en"?"en-US":"zh-CN")})):null,p=(e,c)=>a(m,null,["ok","partial"].includes(e?.status)?c:a("p",{className:e?.status==="error"?"cm-err":"cm-note",role:e?.status==="error"?"alert":void 0},e?.message||l("codingPlanNotQueried")),["ok","partial"].includes(e?.status)&&e.message?r(e.message):null,W(e)),N=(e,c)=>{const n=(i.codingPlanWindowEntries?i.codingPlanWindowEntries(e,c):Object.entries(e??{})).filter(([,o])=>o!=null);return n.length?a("div",{className:"cm-go-list"},n.map(([o,u])=>i.quotaWindowRow(l,(u.label||i.codingPlanWindowLabel(o==="five"?"5h":o,l))+(typeof u.percent=="number"?f(" · 剩余"," · remaining"):""),u,"remaining",!1,o))):r(l("codingPlanNotQueried"))},d=[];if(t.balance?.display!=="off"&&t.hideOfficialBalance!==!0){const e=s.balance;d.push(w("balance",l("accountBalance"),p(e,a("div",{className:"cm-card-value cm-num"},e?.totalBalance==null?"—":i.formatBalanceMoney(e.totalBalance,t,e.currency)))))}if(t.goQuota?.enabled!==!1&&t.goQuota?.display!=="off"){const e=s.goQuota;d.push(w("go",l("goQuotaTitle"),p(e,N({[l("goWindowRolling")]:e?.rolling,[l("goWindowWeekly")]:e?.weekly,[l("goWindowMonthly")]:e?.monthly}))))}t.codexQuotaEnabled===!0&&d.push(w("codex",l("codexQuotaTitle"),p(Q,N(Q.windows))));for(const{id:e,labelKey:c}of i.CODING_PLAN_ROWS){const n=t.codingPlans?.[e],o=s.codingPlans?.[e];n?.enabled===!0&&n.display!=="off"&&d.push(w(e,l(c),p(o,N(o?.windows,e))))}(t.customBalances?.length?t.customBalances:t.customBalance?[t.customBalance]:[]).forEach((e,c)=>{if(!e.enabled||e.display==="off")return;const n=s.customBalances?.find(o=>o.index===c)??(c===0&&!s.customBalances?.length?s.customBalance:null);d.push(w("custom-"+c,b==="en"&&e.labelEn||e.label||l("customBalanceTitle"),p(n,a("div",{className:"cm-card-value cm-num"},n?.remaining==null?"—":i.formatCustomBalanceMoney(n.remaining,t,n,e)))))});for(const e of t.gatewayQuotas?.sources??[]){if(!e.enabled||e.display==="off")continue;const c=s.gatewayQuotas?.find(o=>o.id===e.id),n=(o,u)=>o?a("p",{key:u,className:"cm-note cm-num"},(o.label||o.unit||"Credits")+" · "+f("剩余 ","Remaining ")+(o.remaining??"—")+" / "+(o.limit??"—")):null;d.push(w("gateway-"+e.id,e.label||e.id,p(c,c?.accounts?.length?c.accounts.map((o,u)=>a("div",{key:o.id||u},a("h4",{className:"cm-h"},o.label||o.provider),o.message?r(o.message):null,N(Object.fromEntries((o.windows??[]).map((y,B)=>[y.id||B,y]))),n(o.credits),(o.credits?.packages??[]).map((y,B)=>n(y,y.id||B)))):r(l("gatewaySourceNoAccounts")))))}return a("div",{className:"cm-section","data-settings-overview":!0},r(f("费用和额度随当前数据更新。调整配置请前往「插件 → 费用计量」。","Costs and quotas update with the current data. Configure them in Plugins → Cost meter.")),g?.error?a("p",{className:"cm-err",role:"alert"},l("ledgerReadFailed",{message:g.error})):null,a("div",{className:"cm-overview-grid"},a("div",{className:"cm-cards",style:{"--cm-overview-count":t.hideTodayCost===!0?2:3}},[["today","cardToday"],["month","cardMonth"],["total","cardTotal"]].filter(([e])=>e!=="today"||t.hideTodayCost!==!0).map(([e,c])=>{const n=s[e];return a(i.Card,{key:e,title:l(c),value:T(i.displayCostOf(n,t),t),sub:l("callsTokens",{calls:n.calls,input:v(n.input),cache:v(n.cacheRead+n.cacheWrite),output:v(n.output)})})}))),r(l("cardsFootnote")),a(i.BillingAccuracyNote,{state:s}),r(l("cardsTogglePlanTotal")+": "+f(t.showTotalWithPlan?"已开启":"已关闭",t.showTotalWithPlan?"On":"Off")),t.budget?.enabled&&t.hideBudget!==!0?a(i.BudgetBoxContent,{state:s,wide:!0}):null,a("h3",{className:"cm-h"},f("余额与额度","Balances and quotas")),d.length?a("div",{className:"cm-quota-list"},d):r(f("尚未启用余额或额度来源。","No balance or quota sources enabled.")),a(i.UsagePanel,{state:s,t:l,locale:b}),a("h3",{className:"cm-h"},l("todaySessions")),a(i.TodaySessions,{state:s}))}return{mount:()=>h}}});
@@ -1,4 +1,4 @@
1
- window.__ModuleLoader__.load({id:"dsh-cost-meter",chunk:"client.sidebar-order.js",factory:()=>{const p=l=>typeof l=="string"&&/^(balance|customBalance|today|peak|models|go|budget|codex|(plan|gateway):[A-Za-z0-9_-]{1,100})$/.test(l);function k(l,f,o,d,u){const s=[...new Set([...l,...f])].filter(y=>p(y)&&y!==o),m=s.indexOf(d);return!p(o)||o===d||m<0||!f.includes(o)?null:(s.splice(m+Number(u),0,o),s.slice(0,64))}function L(l,f){let o=null;const d=document.createElement("style");d.textContent=`
1
+ ;(function(b){const m=window.__ModuleLoader__,c=m[Symbol.for("@dsh-plugin/dsh-loader:load-wrap")];return(b.id==="dsh-cost-meter"&&m.load===c?.ours&&typeof c.original=="function"?c.original:m.load).call(m,b)})({id:"dsh-cost-meter",chunk:"client.sidebar-order.js",factory:()=>{const y=c=>typeof c=="string"&&/^(balance|customBalance|today|peak|models|go|budget|codex|(plan|gateway):[A-Za-z0-9_-]{1,100})$/.test(c);function b(c,f,r,l,h){const d=[...new Set([...c,...f])].filter(u=>y(u)&&u!==r),p=d.indexOf(l);return!y(r)||r===l||p<0||!f.includes(r)?null:(d.splice(p+Number(h),0,r),d.slice(0,64))}function m(c,f){let r=null;const l=document.createElement("style");l.textContent=`
2
2
  .cm-footer-stack{--cm-sidebar-inset:11px}.cm-footer-stack.simple{--cm-sidebar-inset:8px}.cm-footer-stack.summary{--cm-sidebar-inset:0px}
3
3
  body .cm-footer-stack:not(.rail)>.cm-foot,body .cm-footer-stack:not(.rail)>.cm-peak-progress{padding-left:var(--cm-sidebar-inset);padding-right:var(--cm-sidebar-inset)}
4
4
  body .cm-footer-stack:not(.rail)>:is(.cm-peak-strip,.cm-peak-classic){margin-left:var(--cm-sidebar-inset);margin-right:var(--cm-sidebar-inset);padding-left:0;padding-right:0}
@@ -21,8 +21,8 @@ window.__ModuleLoader__.load({id:"dsh-cost-meter",chunk:"client.sidebar-order.js
21
21
  body .cm-footer-stack.summary>.cm-bbox{padding:8px 0 2px;border-top:1px solid var(--dsw-alias-border-l1,#ddd)}
22
22
  [data-cm-order-drop=before]{box-shadow:0 -2px var(--dsw-alias-state-business-primary,#4d6bfe)!important}
23
23
  [data-cm-order-drop=after]{box-shadow:0 2px var(--dsw-alias-state-business-primary,#4d6bfe)!important}
24
- `,d.textContent+=` body .cm-footer-stack.cm-inline-ready:not(.rail){display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);column-gap:10px;align-items:start}.cm-inline-ready>[data-cm-display]{grid-column:1/-1;min-width:0}.cm-inline-ready>.cm-inline-today{grid-column:1;grid-row:var(--cm-inline-row)}.cm-inline-ready>.cm-inline-balance{grid-column:2;grid-row:var(--cm-inline-row)}
24
+ `,l.textContent+=` body .cm-footer-stack.cm-inline-ready:not(.rail){display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);column-gap:10px;align-items:start}.cm-inline-ready>[data-cm-display]{grid-column:1/-1;min-width:0}.cm-inline-ready>.cm-inline-today{grid-column:1;grid-row:var(--cm-inline-row)}.cm-inline-ready>.cm-inline-balance{grid-column:2;grid-row:var(--cm-inline-row)}
25
25
  body .cm-footer-stack.cm-inline-ready>:is(.cm-inline-today,.cm-inline-balance){padding:4px 0;min-height:22px;font-size:12px;border:0;background:transparent;box-shadow:none;gap:4px;align-self:start}.cm-inline-ready :is(.cm-inline-today,.cm-inline-balance) :is(.cm-num,.cm-bbox-pct,.cm-bbox-label){font-size:12px}.cm-inline-ready :is(.cm-inline-today,.cm-inline-balance) .cm-bbox-head{gap:4px;margin:0 0 4px;min-height:19px}.cm-inline-ready .cm-inline-balance .cm-balance-name a{display:none}.cm-inline-ready :is(.cm-inline-today,.cm-inline-balance) :is(.cm-bal-label,.cm-balance-name){min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.cm-inline-ready :is(.cm-inline-today,.cm-inline-balance) .cm-num{min-width:0;overflow:hidden;text-overflow:ellipsis}.cm-inline-ready .cm-today-values{gap:4px;flex-wrap:wrap}.cm-inline-ready .cm-inline-today>.cm-num{flex:1;text-align:right}
26
26
  body .cm-footer-stack.cm-inline-ready>.cm-inline-today{padding-left:var(--cm-sidebar-inset)}body .cm-footer-stack.cm-inline-ready>.cm-inline-balance{padding-right:var(--cm-sidebar-inset)}
27
27
  body .cm-footer-stack.cm-inline-ready>.cm-inline-today{height:auto;align-items:flex-start;line-height:19px}.cm-inline-ready .cm-inline-balance .cm-bbox-head{line-height:19px}.cm-inline-ready .cm-inline-today .cm-today-values{display:flex;flex-direction:column;align-items:flex-end;justify-content:flex-start;gap:0;line-height:19px}.cm-inline-ready .cm-today-values>[data-cm-today]{max-width:100%;overflow:hidden;text-overflow:ellipsis}.cm-inline-ready .cm-today-values>[data-cm-today=cost]{order:0}.cm-inline-ready .cm-today-values>[data-cm-today=tokens]{order:1}
28
- `,document.head.appendChild(d);const u=e=>{const t=[...e.children].filter(r=>r.dataset.cmDisplay),a=t.find(r=>r.dataset.cmDisplay==="today"),i=t.find(r=>r.dataset.cmDisplay==="balance")??t.find(r=>r.dataset.cmDisplay==="customBalance"),n=e.classList.contains("same-line")&&!e.classList.contains("rail")&&a&&i,c=(r,S,E)=>{r.classList.contains(S)!==E&&r.classList.toggle(S,E)};c(e,"cm-inline-ready",!!n);for(const r of t)c(r,"cm-inline-today",!!n&&r===a),c(r,"cm-inline-balance",!!n&&r===i);n?e.style.setProperty("--cm-inline-row",Math.min(t.indexOf(a),t.indexOf(i))+1):e.style.removeProperty("--cm-inline-row")};let s=0,m=!1,y=!1;const j=()=>{if(s=0,!m)for(const e of document.querySelectorAll(".cm-footer-stack.same-line,.cm-footer-stack.cm-inline-ready"))u(e)},w=()=>{!s&&!m&&(s=requestAnimationFrame(j))},g=new MutationObserver(e=>{e.some(t=>t.target.closest?.(".cm-footer-stack")||[...t.addedNodes].some(a=>a.nodeType===1&&(a.matches(".cm-footer-stack")||a.querySelector(".cm-footer-stack"))))&&w()}),v=()=>{const e=f?.getSnapshot().state?.config?.sidebarTodayBalanceInline===!0;!e&&!y||(y=e,g.disconnect(),e&&g.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["class"]}),w())},q=f?.subscribe(v);v();const x=e=>e?.closest?.(".cm-sidebar-selection"),h=e=>[...e.querySelectorAll("[data-cm-order-key]")].map(t=>({node:t,key:t.dataset.cmOrderKey})).filter((t,a,i)=>p(t.key)&&i.findIndex(n=>n.key===t.key)===a),b=()=>{o?.root.querySelectorAll("[data-cm-order-drop]").forEach(e=>e.removeAttribute("data-cm-order-drop")),o=null},O=(e,t,a,i)=>{const n=JSON.parse(e.dataset.cmOrder||"[]"),c=k(n,h(e).map(r=>r.key),t,a,i);c&&JSON.stringify(n)!==JSON.stringify(c)&&e.dispatchEvent(new CustomEvent("cost-meter:sidebar-reorder",{detail:c}))},z=e=>{const t=e.target.closest?.("[data-cm-order-key]"),a=x(t);!a||!p(t.dataset.cmOrderKey)||(o={root:a,key:t.dataset.cmOrderKey},e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("application/x-dsh-cost-sidebar",o.key),e.stopPropagation())},A=e=>{if(!o)return null;const t=x(e.target);if(t!==o.root)return null;const a=h(t).find(i=>i.node===e.target||i.node.contains(e.target));return!a||a.key===o.key?null:{...a,after:e.clientY>a.node.getBoundingClientRect().top+a.node.getBoundingClientRect().height/2}},D={dragstart:z,dragover:e=>{const t=A(e);t&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect="move",o.root.querySelectorAll("[data-cm-order-drop]").forEach(a=>a.removeAttribute("data-cm-order-drop")),t.node.dataset.cmOrderDrop=t.after?"after":"before")},drop:e=>{const t=A(e),a=o;t&&(e.preventDefault(),e.stopPropagation(),b(),O(a.root,a.key,t.key,t.after))},dragend:b,keydown:e=>{if(e.key==="Escape"){b();return}const t=e.target.closest?.("[data-cm-order-key]"),a=x(t);if(!a||!["ArrowUp","ArrowDown"].includes(e.key))return;const i=h(a),n=i.findIndex(r=>r.key===t.dataset.cmOrderKey),c=i[n+(e.key==="ArrowUp"?-1:1)];c&&(e.preventDefault(),e.stopPropagation(),O(a,t.dataset.cmOrderKey,c.key,e.key==="ArrowDown"))}};for(const[e,t]of Object.entries(D))document.addEventListener(e,t,!0);return l.effect(()=>()=>{m=!0,q?.(),g.disconnect(),cancelAnimationFrame(s),b();for(const[e,t]of Object.entries(D))document.removeEventListener(e,t,!0);d.remove()},"cost-meter: display preview reorder"),()=>null}return{mount:L,move:k}}});
28
+ `,document.head.appendChild(l);const h=e=>{const t=[...e.children].filter(o=>o.dataset.cmDisplay),a=t.find(o=>o.dataset.cmDisplay==="today"),n=t.find(o=>o.dataset.cmDisplay==="balance")??t.find(o=>o.dataset.cmDisplay==="customBalance"),i=e.classList.contains("same-line")&&!e.classList.contains("rail")&&a&&n,s=(o,E,C)=>{o.classList.contains(E)!==C&&o.classList.toggle(E,C)};s(e,"cm-inline-ready",!!i);for(const o of t)s(o,"cm-inline-today",!!i&&o===a),s(o,"cm-inline-balance",!!i&&o===n);i?e.style.setProperty("--cm-inline-row",Math.min(t.indexOf(a),t.indexOf(n))+1):e.style.removeProperty("--cm-inline-row")};let d=0,p=!1,u=!1;const L=()=>{if(d=0,!p)for(const e of document.querySelectorAll(".cm-footer-stack.same-line,.cm-footer-stack.cm-inline-ready"))h(e)},v=()=>{!d&&!p&&(d=requestAnimationFrame(L))},x=new MutationObserver(e=>{e.some(t=>t.target.closest?.(".cm-footer-stack")||[...t.addedNodes].some(a=>a.nodeType===1&&(a.matches(".cm-footer-stack")||a.querySelector(".cm-footer-stack"))))&&v()}),O=()=>{const e=f?.getSnapshot().state?.config?.sidebarTodayBalanceInline===!0;!e&&!u||(u=e,x.disconnect(),e&&x.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["class"]}),v())},j=f?.subscribe(O);O();const w=e=>e?.closest?.(".cm-sidebar-selection"),k=e=>[...e.querySelectorAll("[data-cm-order-key]")].map(t=>({node:t,key:t.dataset.cmOrderKey})).filter((t,a,n)=>y(t.key)&&n.findIndex(i=>i.key===t.key)===a),g=()=>{r?.root.querySelectorAll("[data-cm-order-drop]").forEach(e=>e.removeAttribute("data-cm-order-drop")),r=null},A=(e,t,a,n)=>{const i=JSON.parse(e.dataset.cmOrder||"[]"),s=b(i,k(e).map(o=>o.key),t,a,n);s&&JSON.stringify(i)!==JSON.stringify(s)&&e.dispatchEvent(new CustomEvent("cost-meter:sidebar-reorder",{detail:s}))},q=e=>{const t=e.target.closest?.("[data-cm-order-key]"),a=w(t);!a||!y(t.dataset.cmOrderKey)||(r={root:a,key:t.dataset.cmOrderKey},e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("application/x-dsh-cost-sidebar",r.key),e.stopPropagation())},D=e=>{if(!r)return null;const t=w(e.target);if(t!==r.root)return null;const a=k(t).find(n=>n.node===e.target||n.node.contains(e.target));return!a||a.key===r.key?null:{...a,after:e.clientY>a.node.getBoundingClientRect().top+a.node.getBoundingClientRect().height/2}},S={dragstart:q,dragover:e=>{const t=D(e);t&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect="move",r.root.querySelectorAll("[data-cm-order-drop]").forEach(a=>a.removeAttribute("data-cm-order-drop")),t.node.dataset.cmOrderDrop=t.after?"after":"before")},drop:e=>{const t=D(e),a=r;t&&(e.preventDefault(),e.stopPropagation(),g(),A(a.root,a.key,t.key,t.after))},dragend:g,keydown:e=>{if(e.key==="Escape"){g();return}const t=e.target.closest?.("[data-cm-order-key]"),a=w(t);if(!a||!["ArrowUp","ArrowDown"].includes(e.key))return;const n=k(a),i=n.findIndex(o=>o.key===t.dataset.cmOrderKey),s=n[i+(e.key==="ArrowUp"?-1:1)];s&&(e.preventDefault(),e.stopPropagation(),A(a,t.dataset.cmOrderKey,s.key,e.key==="ArrowDown"))}};for(const[e,t]of Object.entries(S))document.addEventListener(e,t,!0);return c.effect(()=>()=>{p=!0,j?.(),x.disconnect(),cancelAnimationFrame(d),g();for(const[e,t]of Object.entries(S))document.removeEventListener(e,t,!0);l.remove()},"cost-meter: display preview reorder"),()=>null}return{mount:m,move:b}}});