dsh-cost-meter 1.9.21 → 1.9.23
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.
- package/README.md +586 -586
- package/README.zh-CN.md +590 -590
- package/docs/billing-statistics.md +2 -2
- package/docs/context-costs-design.md +1 -1
- package/docs/update-notes-1.9.22.md +23 -0
- package/docs/update-notes-1.9.23.md +21 -0
- package/lib/client.js +1 -1
- package/lib/client.pricing.js +3 -3
- package/lib/client.statistics.js +8 -8
- package/lib/index.js +10 -1
- package/lib/model-labels.js +18 -7
- package/lib/plan-billing.js +9 -6
- package/lib/session-cost-source.js +1 -1
- package/lib/session-tree.js +21 -7
- package/lib/store.js +8 -3
- package/lib/typert.host.js +1 -0
- package/package.json +217 -215
package/lib/client.pricing.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
window.__ModuleLoader__.load({id:"dsh-cost-meter",chunk:"client.pricing.js",factory:le=>{const{createElement:e,Fragment:fe,useState:P,useEffect:re,useLayoutEffect:ie,useMemo:G,useRef:ee,useId:be}=le("react");let oe=null;try{oe=le("react-dom")?.createPortal??null}catch{}const xe=["at","before","after","days","sessions","skipped"],we=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),ae={parse:a=>{if(!Array.isArray(a)||!a.every(r=>xe.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}},ce={parse:a=>{if(typeof a?.ok!="boolean"||typeof a?.message!="string")throw new Error("Invalid recalculation result");return a}},se={parse:a=>{if(typeof a!="boolean")throw new Error("Expected confirmation");return a}},me={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}},de={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}),pe={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",de)},{id:"dsh-cost-meter#costMeter/getRepricingHistory",service:"costMeter",namespace:"costMeter",method:"getRepricingHistory",invocation:{kind:"direct"},parameters:[],result:X("RepricingHistory",ae)},{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",se)}],result:X("FetchPricesResult",ce)},{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",se)},{name:"model",wire:"model",source:"json",codec:X("RepricingModel",me)}],result:X("FetchPricesResult",ce)}]},ye=a=>(a.label+" "+a.value).toLowerCase();function ne({options:a,value:r,placeholder:M,label:h,ariaLabel:p,locale:g,onChange:n}){const x=g==="en",k=be(),m=k+"-list",[_,O]=P(""),[u,A]=P(!1),[w,y]=P(0),[S,R]=P(null),f=ee(null),s=ee(null),d=ee(null),b=a.find(o=>o.value===r),E=_.toLowerCase().trim().split(/\s+/).filter(Boolean),v=G(()=>a.map(o=>({option:o,search:ye(o)})),[a]),L=o=>{const N=o.toLowerCase().trim().split(/\s+/).filter(Boolean);return N.length?v.filter(t=>N.every(l=>t.search.includes(l))).map(t=>t.option):a},c=L(_),j=b&&!c.includes(b)?[b,...c]:c,T=Math.max(0,Math.min(w,j.length-1)),$=()=>{A(!1),O("")},B=()=>{u||(R(null),O(""),y(Math.max(0,j.findIndex(o=>o.value===r))),A(!0))},i=o=>{o&&(o.value!==r&&n(o.value),$())},D=()=>{if(u&&_){O(""),y(0);return}r&&n(""),$()};ie(()=>{if(!u||typeof document>"u")return;const o=s.current,N=typeof window>"u"?null:window,t=()=>{const l=o?.getBoundingClientRect?.();if(!l||!N)return;const I=N.innerHeight,z=12,W=I-l.bottom-z,H=l.top-z,Y=W<180&&H>W,Z=Math.max(60,Y?H:W),Q=Math.max(0,Math.min(280,Z,I-z*2)),te=Math.max(z,Math.min(Y?l.top-Q-6:l.bottom+6,I-Q-z));R(q=>q&&q.left===l.left&&q.top===te&&q.width===l.width&&q.maxHeight===Q?q:{left:l.left,top:te,width:l.width,maxHeight:Q})};if(t(),typeof N?.addEventListener=="function")return N.addEventListener("scroll",t,!0),N.addEventListener("resize",t),()=>{N.removeEventListener("scroll",t,!0),N.removeEventListener("resize",t)}},[u]),re(()=>{if(!u||typeof document>"u"||typeof document.addEventListener!="function")return;const o=N=>{f.current?.contains?.(N.target)||d.current?.contains?.(N.target)||$()};return document.addEventListener("pointerdown",o,!0),()=>document.removeEventListener("pointerdown",o,!0)},[u]),ie(()=>{!u||!S||d.current?.querySelector?.('[data-active="true"]')?.scrollIntoView?.({block:"nearest"})},[u,T,S,_]);const U=o=>k+"-opt-"+o,K=E.length?c.length?x?`${c.length} matches`:`${c.length} 个结果`:j.length?x?"No matches · showing the current choice":"没有匹配的模型 · 下面是当前选择":x?"No matches":"没有匹配的模型":null,F=u?e("div",{ref:d,className:"cm-combo-panel",style:S??{visibility:"hidden"}},j.length?e("div",{className:"cm-combo-list",id:m,role:"listbox","aria-label":h},j.map((o,N)=>e("button",{key:o.value,id:U(N),type:"button",role:"option",className:"cm-combo-option"+(N===T?" active":""),"data-active":String(N===T),"aria-selected":String(o.value===r),onMouseEnter:()=>y(N),onMouseDown:t=>t.preventDefault(),onClick:()=>i(o)},o.label))):null,K?e("p",{className:"cm-combo-note",role:"status"},K):null):null;return e("div",{ref:f,className:"cm-price-search cm-combo"},e("div",{className:"cm-combo-control"},e("input",{ref:s,type:"search",className:"cm-input cm-combo-input",autoComplete:"off",value:u?_:b?.label??"",role:"combobox","aria-expanded":String(u),"aria-autocomplete":"list","aria-controls":u&&j.length?m:void 0,"aria-activedescendant":u&&j.length?U(T):void 0,"aria-label":p??h+(x?" · Price model":" · 价格模型"),placeholder:u&&b?b.label:M,onFocus:B,onClick:()=>{u||B()},onChange:o=>{const N=o.target.value,t=!u&&b&&N.startsWith(b.label)?N.slice(b.label.length):N,l=L(t);O(t),A(!0),y(b&&l.length>0&&!l.includes(b)?1:0)},onKeyDown:o=>{if(!o.nativeEvent?.isComposing){if(o.key==="Escape"){if(o.preventDefault(),!u)return;$(),o.stopPropagation();return}if(o.key==="ArrowDown"||o.key==="ArrowUp"){if(o.preventDefault(),!u){B();return}y(Math.max(0,Math.min(j.length-1,T+(o.key==="ArrowDown"?1:-1))));return}if(o.key==="Enter"&&u&&j[T]){o.preventDefault(),i(j[T]);return}o.key==="Tab"&&$()}}}),r||_?e("button",{type:"button",className:"cm-combo-clear","aria-label":(x?"Clear ":"清空 ")+h,onMouseDown:o=>o.preventDefault(),onClick:D},"×"):null,e("button",{type:"button",className:"cm-combo-caret",tabIndex:-1,"aria-hidden":"true",onMouseDown:o=>o.preventDefault(),onClick:()=>{u?$():(s.current?.focus?.(),B())}},"▾")),F&&oe?oe(F,document.body):F)}function ue({state:a,draft:r,setDraft:M,locale:h,rpc:p}){const[g,n]=P(!1),[x,k]=P(null),[m,_]=P(""),[O,u]=P(""),[A,w]=P(0),y=a.config.prices.currency??"USD",S=h==="en";re(()=>{if(!g)return;let d=!0;return k(null),u(""),_(""),p("getPriceCatalog").then(b=>{d&&k(b)},b=>{d&&u(String(b.message??b))}),()=>{d=!1}},[g,y,A,p]);const R=[];for(const[d,b]of Object.entries(x??{}))for(const E of Object.values(b))for(const[v,L]of Object.entries(E))!(d==="deepseek"?r?.prices.models[v]:r?.prices.providers?.[d]?.models?.[v])&&!L.unpriced&&R.push({value:d+":"+v,label:d+" · "+v,provider:d,id:v,entry:L});const f=R.find(d=>d.value===m),s=()=>{if(!f||!r)return;const{provider:d,id:b,entry:E}=f,v=JSON.parse(JSON.stringify(E)),L=r.prices;M({...r,prices:d==="deepseek"?{...L,models:{...L.models,[b]:v}}:{...L,providers:{...L.providers,[d]:{...L.providers?.[d],models:{...L.providers?.[d]?.models,[b]:v}}}}}),_("")};return e("div",{className:"cm-restore-prices"},e("button",{type:"button",className:"cm-btn small","aria-expanded":g,onClick:()=>n(d=>!d)},g?S?"Close restore":"收起恢复入口":S?"Restore bundled model":"恢复内置模型"),g?e("div",{className:"cm-collapse-body"},O?e("div",{role:"alert",className:"cm-err"},O,e("button",{type:"button",className:"cm-btn small",onClick:()=>w(d=>d+1)},S?"Retry":"重试")):x===null?e("p",{role:"status",className:"cm-hint"},S?"Loading prices…":"读取价格…"):R.length?e(fe,null,e(ne,{options:R,value:f?m:"",placeholder:S?"Select a model":"选择模型",label:S?"Restore model":"恢复模型",locale:h,onChange:_}),e("button",{type:"button",className:"cm-btn small",disabled:!f,onClick:s},S?"Restore":"恢复")):e("p",{className:"cm-hint"},S?"All bundled models are mounted.":"内置模型均已挂载。")):null)}function ve({value:a,label:r,locale:M,onChange:h,t:p,priceEditor:g}){const n=M==="en",{PriceInput:x,priceFactor:k,setPriceFactor:m,multiplierOptions:_}=g,O=[["cacheMiss",n?"Input · cache miss":"输入 · 未命中缓存"],["cacheHit",n?"Cached input":"缓存读取"],["output",n?"Output":"输出"],["cacheWrite",n?"Cache write":"缓存写入"],["reasoning",n?"Separate reasoning":"单独推理费用"]],u=(w,y,S)=>{const R={...a};y===null?delete R[w]:R[w]=y,m(R,"base."+w,S),h(R)},A=([w,y])=>e("label",{key:w},y,e("span",{className:"cm-custom-amount"},e("span",{"aria-hidden":!0},a.currency==="CNY"?"¥":"$"),e(x,{entry:a,value:a[w]??null,path:"base."+w,t:p,emptyMode:["cacheWrite","reasoning"].includes(w)?"clear":"ignore",label:r+" · "+y,placeholder:w==="cacheWrite"?n?"Same as cached input":"跟随缓存读取":w==="reasoning"?n?"Included in output":"含在输出中":"0",onCommit:(S,R)=>u(w,S,R)})));return e("fieldset",{className:"cm-custom-price","aria-label":r+(n?" · Custom price":" · 自定义价格")},e("legend",null,n?"Custom price · per 1M tokens":"自定义价格 · 每百万 Token"),e("div",{className:"cm-custom-head"},e("span",null,n?"Only this channel and model":"仅用于此渠道的这个模型"),e("label",null,n?"Currency":"币种",e("select",{className:"cm-input",value:a.currency,onChange:w=>h({...a,currency:w.target.value})},e("option",{value:"USD"},n?"USD · US dollar":"USD · 美元"),e("option",{value:"CNY"},n?"CNY · Yuan":"CNY · 人民币")))),e("div",{className:"cm-custom-grid"},...O.slice(0,3).map(A)),_(a,p,w=>h({...a,separateMultipliers:w,multipliers:{}})),e("div",{className:"cm-custom-effective",role:"status"},e("div",{className:"cm-effective-heading"},e("span",null,n?"Effective prices":"实际单价"),e("small",null,n?"Price × multiplier / 1M tokens":"单价 × 倍率 / 百万 Token")),e("div",{className:"cm-effective-grid"},...O.slice(0,3).map(([w,y])=>e("div",{key:w},e("span",null,y),e("strong",null,(a.currency==="CNY"?"¥":"$")+Number((a[w]*k(a,"base."+w)).toPrecision(8)).toLocaleString(n?"en-US":"zh-CN",{maximumFractionDigits:8})))))),e("details",{className:"cm-custom-more"},e("summary",null,n?"More billing fields":"更多计费项"),e("div",{className:"cm-custom-grid"},...O.slice(3).map(A)),e("p",{className:"cm-hint"},n?"Leave reasoning blank when it is included in output. Leave cache write blank to use the cached input rate.":"推理已包含在输出中时无需另填。缓存写入留空则使用缓存读取价格。")),e("p",{className:"cm-hint"},n?"Enter or leave a field to save. Switching the price source keeps your custom values.":"回车或离开输入框后保存;切换价格来源会保留已填的自定义价格。"))}function ge({entry:a,currency:r,priceEditor:M,locale:h,local:p=!1}){const g=h==="en",n=a?M?.priceAt?.(a)??a:null;return e("span",{className:"cm-rate-summary"},...[["cacheMiss","input",g?"Input":"输入"],["cacheHit","cachedInput",g?"Cached input":"缓存读取"],["output","output",g?"Output":"输出"]].map(([k,m,_])=>{const O=p?0:n?.unpriced?null:n?.[k]??n?.[m],u=O==null?null:O*(M?.priceFactor?.(n??{},"base."+k)??1);return e("span",{key:k,className:"cm-rate-item"},e("span",null,_),e("strong",null,u===null?"—":(r==="CNY"?"¥":"$")+Number(u.toPrecision(8)).toLocaleString(g?"en-US":"zh-CN",{maximumFractionDigits:8})))}))}function Ne({state:a,draft:r,setDraft:M,locale:h}){if(a.ourFreeModel?.enabled!==!0)return null;const p=h==="en",g=r?.priceOverrides??a.config.priceOverrides??{},n=["our-free-model:*","our-free-model-region:*"],x=n.every(k=>g[k]==="__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:x,onChange:k=>{if(!r)return;const m={...g};for(const _ of n)k.target.checked?m[_]="__free__":m[_]==="__free__"&&delete m[_];M({...r,priceOverrides:m})}}),e("span",null,p?"Count dsh-our-free-model calls as free":"dsh-our-free-model 调用按免费计算")),e("p",{className:"cm-hint"},p?"Future calls through this plugin cost 0; tokens are still counted. Historical costs and other providers stay unchanged.":"仅此插件后续调用记为免费,Token 照常统计;历史费用和其他渠道不变。"))}function ke({state:a,draft:r,setDraft:M,t:h,locale:p,resolveClientPrice:g,prettyProviderKey:n,setField:x,priceEditor:k}){const[m,_]=P(""),[O,u]=P(24),[A,w]=P(null),[y,S]=P({}),R=ee(new Map),f=ee(null),s=p==="en",d=a.config,b=r?.priceOverrides??d.priceOverrides??{},E=r?.priceMatchDismissed??d.priceMatchDismissed??[],v=r?.prices??d.prices,L=r?.modelStatistics??d.modelStatistics??{},c=[["today","今日费用","Today"],["summary","月度与累计","Monthly / all-time"],["budget","预算","Budget"]],j=G(()=>({...a.total?.byProviderModel,...a.month?.byProviderModel,...a.today?.byProviderModel,...Object.fromEntries(Object.keys(L).map(t=>[t,null]))}),[a.total?.byProviderModel,a.month?.byProviderModel,a.today?.byProviderModel,L]),T=G(()=>[...new Set([...Object.keys(j),...Object.keys(b)])].filter(t=>!E.includes(t)&&!we(t)&&!["our-free-model:*","our-free-model-region:*"].includes(t)).sort(),[j,b,E]);ie(()=>{const t=R.current.get(f.current)?.querySelector(".cm-custom-price");t&&(f.current=null,t.scrollIntoView({block:"start",inline:"nearest"}),t.querySelector("input")?.focus({preventScroll:!0}))},[v,y]);const $=G(()=>[{value:"deepseek:__default__",label:h("overrideTargetDefault")},...Object.keys(v.models??{}).map(t=>({value:"deepseek:"+t,label:"DeepSeek · "+t})),...Object.entries(v.providers??{}).flatMap(([t,l])=>Object.keys(l?.models??{}).map(I=>({value:t+":"+I,label:t+" · "+I})))],[v.models,v.providers,p,h]),B=(t,l)=>{if(r===null)return;const I={...r.priceOverrides??{}};if(l===""?delete I[t]:I[t]=l,l==="__custom__"&&!v.custom?.[t]){const z=t.indexOf(":"),W=g(t.slice(0,z),t.slice(z+1),{...d,...r}),H=W.entry??{},Y={currency:W.currency??"USD",billingMode:"flat",...k?.priceMultiplierSettings(H),cacheMiss:H.cacheMiss??H.input??0,cacheHit:H.cacheHit??H.cachedInput??H.cacheMiss??H.input??0,output:H.output??0,...H.cacheWrite!==void 0?{cacheWrite:H.cacheWrite}:{},...H.reasoning!==void 0?{reasoning:H.reasoning}:{}};M({...r,priceOverrides:I,prices:{...v,custom:{...v.custom,[t]:Y}}})}else M({...r,priceOverrides:I})},i=t=>{if(r===null)return;const l={...r.priceOverrides??{}};delete l[t],M({...r,priceOverrides:l,priceMatchDismissed:[...new Set([...E,t])]})},D=m.trim().toLowerCase().split(/\s+/).filter(Boolean),K=(t=>t.filter(l=>D.every(I=>(l+" "+n(l)).toLowerCase().includes(I))))(T),F=K.length,o=K.slice(0,O),N=t=>{const l=n(t),I=l.indexOf(":"),z=b[t],W=A===t,H=y[t]??(z==="__custom__"?"custom":z==="__local__"?"local":z?"catalog":"auto"),Y=t.indexOf(":"),Z=g(Y>0?t.slice(0,Y):"deepseek",Y>0?t.slice(Y+1):t,{...d,...r}),Q=!z&&Z.matched===!0,te=C=>{C==="custom"&&(f.current=t),S({...y,[t]:C}),C!=="catalog"&&B(t,C==="custom"?"__custom__":C==="local"?"__local__":"")},q=c.filter(([C])=>L[t]?.[C]!==!1),Se=(C,V)=>{if(!r)return;const J={...L,[t]:{today:!0,summary:!0,budget:!0,...L[t],[C]:V}};Object.values(J[t]).every(Boolean)&&delete J[t],M({...r,modelStatistics:J})},ze=Q?s?"Automatic":"自动匹配":z==="__custom__"?s?"Custom price":"自定义价格":z==="__local__"?s?"Local · free":"本地 · 零费用":z?s?"Price table":"指定价格表":s?"Needs a price":"待设置价格";return e("div",{key:t,className:"cm-match-row","data-model-key":t,"data-open":W,ref:C=>{C?R.current.set(t,C):R.current.delete(t)}},e("div",{className:"cm-model-head"},e("div",{className:"cm-model-identity",title:l},e("strong",null,I>0?l.slice(I+1):l),e("span",{className:"cm-model-meta"},e("span",{className:"cm-model-provider"},I>0?l.slice(0,I):"DeepSeek"),e("span",{className:"cm-model-badge"+(!Q&&!z?" needs-price":"")},ze))),e("div",{className:"cm-model-current",title:s?"Effective rates per 1M tokens, including multipliers":"每百万 Token 实际单价,已含倍率"},e(ge,{entry:Z.entry,currency:Z.currency,priceEditor:k,locale:p,local:z==="__local__"})),e("button",{type:"button",className:"cm-btn small cm-model-edit","aria-expanded":W,"aria-label":l+(s?" · Set price":" · 设置价格"),onClick:()=>w(W?null:t)},W?s?"Collapse":"收起":s?"Set price":"设置价格")),e("details",{className:"cm-model-statistics","data-model-statistics":t},e("summary",null,s?"Include in statistics":"计入统计",q.length===3?null:e("span",{className:"cm-note"},q.map(([,C,V])=>s?V:C).join(" · ")||(s?"None":"均不计入"))),e("div",{className:"cm-model-statistics-options"},...c.map(([C,V,J])=>e("label",{key:C,className:"cm-check"},e("input",{type:"checkbox",checked:L[t]?.[C]!==!1,"aria-label":l+" · "+(s?J:V),onChange:Oe=>Se(C,Oe.target.checked)}),s?J:V)))),W?e("div",{className:"cm-model-editor"},e("div",{className:"cm-source-choices",role:"group","aria-label":s?"Price source":"价格来源"},...[["auto","自动匹配","Automatic"],["catalog","价格表","Price table"],["custom","自定义","Custom"],["local","本地","Local"]].map(([C,V,J])=>e("button",{key:C,type:"button",className:"cm-source-choice"+(H===C?" active":""),"aria-pressed":H===C,onClick:()=>te(C)},s?J:V))),H==="catalog"?e("div",{className:"cm-model-source"},e("span",null,s?"Select a reference model":"选择参考模型"),e(ne,{value:z&&!z.startsWith("__")?z:"",options:$,placeholder:s?"Choose a price table entry":"选择价格表条目",label:l,locale:p,onChange:C=>{C?B(t,C):te("auto")}}),!z||z.startsWith("__")?e("p",{className:"cm-note"},s?"Current pricing stays in effect until you choose an entry.":"选定条目后生效,选择前仍使用原价格。"):null):null,H==="custom"&&z==="__custom__"&&v.custom?.[t]?e(ve,{value:v.custom[t],label:l,locale:p,t:h,priceEditor:k,onChange:C=>M({...r,prices:{...v,custom:{...v.custom,[t]:C}}})}):null,H==="auto"?e("p",{className:"cm-source-explanation"},Z.matched?s?"The model uses its automatically matched reference price.":"已自动匹配参考价格,后续调用按该价格计费。":s?"No exact price found. Choose a table entry or enter a custom quote.":"尚未命中参考价格,可选择价格表条目或填写自定义价格。"):null,H==="local"?e("p",{className:"cm-source-explanation"},s?"Tokens are tracked; new calls have zero API cost.":"保留 Token 统计,后续调用的 API 费用记为 0。"):null,Q?null:e("button",{type:"button",className:"cm-model-dismiss",title:h("removePriceMatchHint"),onClick:()=>i(t)},h("overrideRemove"))):null)};return e("div",{className:"cm-model-matching"},e(Ne,{state:a,draft:r,setDraft:M,locale:p}),e("div",{className:"cm-model-toolbar"},e("input",{type:"search",className:"cm-input",value:m,placeholder:s?"Find a model or channel…":"查找模型或渠道…","aria-label":s?"Find configured models":"查找已用模型",onChange:t=>{_(t.target.value),u(24)},onKeyDown:t=>{t.key==="Escape"&&(_(""),u(24),t.stopPropagation())}}),e("span",{className:"cm-note",role:"status"},s?`${F} models`:`${F} 个模型`)),o.length?e("div",{className:"cm-model-list"},e("div",{className:"cm-model-columns","aria-hidden":!0},e("span",null,s?"Model / channel":"模型 / 渠道"),e("span",{className:"cm-rate-summary"},...[s?"Input":"输入",s?"Cached input":"缓存读取",s?"Output":"输出"].map(t=>e("span",{key:t},t))),e("span",{title:s?"Per 1M tokens":"每百万 Token"},"/ 1M tok")),...o.map(N)):null,F===0?e("p",{className:"cm-pricing-empty"},m?s?"No models found. Try another keyword.":"没有找到模型,试试其他关键词。":s?"Models appear here after their first call.":"调用过的模型会显示在这里,之后可按渠道设置价格。"):null,F>O?e("button",{type:"button",className:"cm-btn",onClick:()=>u(t=>t+24)},s?`Show more · ${F-O} remaining`:`显示更多 · 还有 ${F-O} 个`):null,E.length>0?e("button",{type:"button",className:"cm-btn small",onClick:()=>x("priceMatchDismissed",[])},h("restorePriceMatches",{count:E.length})):null,e("details",{className:"cm-pricing-rules"},e("summary",null,s?"Automatic matching rules":"自动匹配规则"),e("label",{className:"cm-field"},e("span",null,h("priceMatchLabel")),e("select",{className:"cm-input",value:r?.priceMatch==="exact"?"exact":"auto",onChange:t=>x("priceMatch",t.target.value)},e("option",{value:"auto"},h("priceMatchAuto")),e("option",{value:"exact"},h("priceMatchExact")))),e("p",{className:"cm-note"},h("priceMatchNote"))))}function he({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 Ce({state:a,draft:r,setDraft:M,t:h,locale:p,rpc:g,renderEditor:n,vendorLabels:x,priceEditor:k}){const m=p==="en",[_,O]=P(""),[u,A]=P(""),[w,y]=P({}),[S,R]=P({}),[f,s]=P(null),[d,b]=P(""),E=r?.prices??a.config.prices,v=G(()=>({...E.providers,deepseek:{models:{...E.models,__default__:E.default}}}),[E.models,E.default,E.providers]),L=Object.keys(v).filter(i=>Object.keys(v[i]?.models??{}).length).sort((i,D)=>i===D?0:i==="deepseek"?-1:D==="deepseek"?1:i.localeCompare(D)),c=_.toLowerCase().trim().split(/\s+/).filter(Boolean),j=L.filter(i=>!u||u===i).map(i=>({id:i,ids:Object.keys(v[i].models).filter(D=>c.every(U=>(i+" "+(x[i]??"")+" "+(D==="__default__"?h("defaultModelId"):D)).toLowerCase().includes(U))).sort((D,U)=>D===U?0:D==="__default__"?1:U==="__default__"?-1:D.localeCompare(U))})).filter(i=>i.ids.length),T=j.reduce((i,D)=>i+D.ids.length,0),$=i=>{O(i),R({}),y({})},B=()=>{const i=d.trim().toLowerCase();!r||!/^[a-z0-9_.-]+$/.test(i)||Object.hasOwn(E.models,i)||(M({...r,prices:{...E,models:{...E.models,[i]:{cacheHit:0,cacheMiss:0,output:0}}}}),b(""),A("deepseek"),O(i),y(D=>({...D,deepseek:!0})),s("deepseek:"+i))};return e("div",{className:"cm-reference-prices"},e("p",{className:"cm-note"},m?"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:_,"aria-label":m?"Search mounted prices":"搜索已挂载价格",placeholder:m?"Search models or providers…":"搜索模型或厂商…",onChange:i=>$(i.target.value),onKeyDown:i=>{i.key==="Escape"&&($(""),i.stopPropagation())}}),e("select",{className:"cm-input",value:u,"aria-label":m?"Filter price provider":"筛选价格厂商",onChange:i=>{A(i.target.value),R({}),y({})}},e("option",{value:""},m?"All providers":"全部厂商"),...L.map(i=>e("option",{key:i,value:i},x[i]??i))),e("span",{className:"cm-note",role:"status"},m?`${T} models`:`${T} 个模型`)),...j.map(({id:i,ids:D})=>{const U=w[i]??(i==="deepseek"||c.length>0||u===i),K=i==="deepseek"?E.currency??"USD":"USD",F=S[i]??16;return e("section",{key:i,className:"cm-catalog-group"},e("button",{type:"button",className:"cm-catalog-vendor cm-vendor-toggle","aria-expanded":U,onClick:()=>y(o=>({...o,[i]:!U}))},e("span",null,e(he,{className:"cm-catalog-caret",open:U}),x[i]??i,e("small",null,D.length)),e("span",{className:"cm-catalog-unit"},K+(m?" / 1M tokens":" / 百万 Token"))),U?e("div",{className:"cm-catalog-list"},e("div",{className:"cm-catalog-columns","aria-hidden":!0},...[m?"Model":"模型",m?"Input":"输入",m?"Cached input":"缓存读取",m?"Output":"输出",""].map((o,N)=>e("span",{key:N},o))),...D.slice(0,F).map(o=>{const N=i+":"+o,t=v[i].models[o],l=f===N,I=o==="__default__"?h("defaultModelId"):o,z=t?.peak||t?.offPeak?m?"Peak / off-peak":"含峰谷价格":t?.longContext?m?"Long context":"含长上下文档位":t?.cny?m?"USD + CNY":"美元 / 人民币":null;return e("div",{key:N,className:"cm-catalog-entry"+(l?" editing":"")},e("button",{type:"button",className:"cm-catalog-model","aria-label":I+(m?" · Edit price":" · 编辑价格"),"aria-expanded":l,onClick:()=>s(l?null:N)},e("span",{className:"cm-catalog-model-name"},e("strong",null,I),z?e("small",null,z):null),e(ge,{entry:t,currency:K,priceEditor:k,locale:p}),e(he,{className:"cm-catalog-edit-caret",open:l})),l?e("div",{className:"cm-catalog-editor"},n(i,o,t)):null)}),D.length>F?e("button",{type:"button",className:"cm-catalog-more",onClick:()=>R(o=>({...o,[i]:F+16}))},m?`Show more · ${D.length-F} remaining`:`显示更多 · 还有 ${D.length-F} 个`):null):null)}),T===0?e("p",{className:"cm-pricing-empty"},m?"No matching models.":"没有找到匹配的模型。"):null,e("details",{className:"cm-pricing-rules"},e("summary",null,m?"Pricing notes":"计价说明"),e("p",{className:"cm-note"},h("priceTableNote"))),e("details",{className:"cm-catalog-manage"},e("summary",null,m?"Add or restore models":"添加与恢复模型"),e("div",{className:"cm-catalog-add"},e("input",{className:"cm-input",value:d,"aria-label":h("newModelPlaceholder"),placeholder:h("newModelPlaceholder"),onChange:i=>b(i.target.value),onKeyDown:i=>{i.key==="Enter"&&(i.preventDefault(),B())}}),e("button",{type:"button",className:"cm-btn small",disabled:!/^[a-z0-9_.-]+$/.test(d.trim().toLowerCase())||Object.hasOwn(E.models,d.trim().toLowerCase()),onClick:B},h("addModel"))),e(ue,{state:a,draft:r,setDraft:M,locale:p,rpc:g})))}function Me({state:a,locale:r,formatMoneyUsd:M,api:h,rpc:p,disabled:g}){const[n,x]=P(!1),[k,m]=P(!1),[_,O]=P(""),[u,A]=P([]),[w,y]=P(""),[S,R]=P(""),f=r==="en",s=(c,j)=>{const T=a.config.currency==="CNY"?"Cny":a.config.currency==="EUR"?"Eur":"",$=T&&c[j+T],B=Number(a.config.exchangeRate);return M(typeof $=="number"&&B>0?$/B:c[j],a.config)},d=f?"All models":"全部模型",b=G(()=>[...new Set([a.today,a.month,...a.history??[]].flatMap(c=>Object.keys(c?.byProviderModel??{})))].filter(c=>c.indexOf(":")>0).sort(),[a.today,a.month,a.history]),E=G(()=>[{value:"",label:d},...b.map(c=>({value:c,label:c}))],[b,d]),v=()=>p("getRepricingHistory").then(c=>{A(ae.parse(c)),y("")}).catch(c=>y(String(c.message??c)));re(()=>{let c=!0;return p("getRepricingHistory").then(j=>{c&&A(ae.parse(j))},j=>{c&&y(String(j.message??j))}),()=>{c=!1}},[p]);const L=async()=>{if(!(!n||k||g)){m(!0),y(""),O("");try{const c=S?await p("repriceModelHistory",!0,S):await p("repriceHistory",!0);if(!c.ok)throw new Error(c.message);O(c.message),x(!1),await v(),await h.reload()}catch(c){y(String(c.message??c))}finally{m(!1)}}};return e("section",{className:"cm-repricing"},e("h3",{className:"cm-h"},f?"Historical pricing":"历史费用"),e("p",{className:"cm-note"},f?"Rate changes apply to new calls. Recorded historical rates remain fixed.":"修改价格只影响后续调用,历史费用沿用原价格。"),e("div",{className:"cm-repricing-scope"},e("label",null,f?"Recalculation scope":"重算范围"),e(ne,{options:E,value:S,locale:r,label:f?"Choose channel and model":"选择渠道与模型",ariaLabel:f?"Choose channel and model":"选择渠道与模型",placeholder:f?"Search historical models":"搜索历史渠道或模型",onChange:c=>{k||(R(c),x(!1),O(""))}}),e("p",{className:"cm-hint"},S?f?"Only this channel/model changes. Other models and original exchange rates remain unchanged.":"仅重算此渠道下的这个模型,其他模型及原调用汇率保持不变。":f?"Choose a single channel/model to limit the recalculation.":"可选择单个渠道模型,缩小重算范围。")),n?e("div",{className:"cm-repricing-warning",role:"alert",onKeyDown:c=>{c.key==="Escape"&&!k&&(x(!1),c.stopPropagation())}},e("strong",null,(S||d)+(f?" · Historical amounts will change":" · 将修改历史费用")),e("p",null,f?"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:k,onClick:()=>x(!1)},f?"Cancel":"取消"),e("button",{type:"button",className:"cm-btn danger",disabled:k||g,onClick:L},k?f?"Recalculating…":"正在重算…":f?"Confirm recalculation":"确认重算"))):e("button",{type:"button",className:"cm-btn",disabled:g||k,onClick:()=>x(!0)},S?f?"Recalculate this model":"重算此模型的历史费用":f?"Recalculate history at current rates":"按当前价格重算历史"),_?e("p",{role:"status",className:"cm-note"},_):null,w?e("p",{role:"alert",className:"cm-err"},w):null,u.length?e("details",{className:"cm-repricing-history"},e("summary",null,f?"Recalculation records · original amounts retained":"重算记录 · 原金额已保留"),e("div",{className:"cm-stat-scroll"},e("table",{className:"cm-stat-table"},e("thead",null,e("tr",null,...(f?["Time","Scope","Before","After","Session/day records"]:["重算时间","范围","原金额","重算后","会话日期记录"]).map(c=>e("th",{key:c,scope:"col"},c)))),e("tbody",null,...u.map(c=>e("tr",{key:c.at},e("td",null,new Date(c.at).toLocaleString(r)),e("td",null,c.model||d),e("td",null,s(c,"before")),e("td",null,s(c,"after")),e("td",null,c.sessions))))))):null)}async function _e(a){const r=await a.get("remote").$mount(pe);a.effect(()=>()=>r(),"cost-meter: pricing settings contribution");const M=a.get("remote.costMeter"),h=async(g,...n)=>{(g==="repriceHistory"||g==="repriceModelHistory")&&se.parse(n[0]),g==="repriceModelHistory"&&me.parse(n[1]);const x=await M[g](...n);if(x?.ok!==!0)throw new Error(x?.error?.message??"Pricing request failed");return(g==="getPriceCatalog"?de:g==="getRepricingHistory"?ae:ce).parse(x.value)},p=document.createElement("style");return p.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}",p.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)}",p.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}",p.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}",p.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(p),p.textContent+=`
|
|
1
|
+
window.__ModuleLoader__.load({id:"dsh-cost-meter",chunk:"client.pricing.js",factory:le=>{const{createElement:e,Fragment:be,useState:O,useEffect:re,useLayoutEffect:ie,useMemo:G,useRef:te,useId:xe}=le("react");let oe=null;try{oe=le("react-dom")?.createPortal??null}catch{}const we=["at","before","after","days","sessions","skipped"],ye=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),ae={parse:a=>{if(!Array.isArray(a)||!a.every(r=>we.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}},ce={parse:a=>{if(typeof a?.ok!="boolean"||typeof a?.message!="string")throw new Error("Invalid recalculation result");return a}},se={parse:a=>{if(typeof a!="boolean")throw new Error("Expected confirmation");return a}},me={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}},de={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}),pe={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",de)},{id:"dsh-cost-meter#costMeter/getRepricingHistory",service:"costMeter",namespace:"costMeter",method:"getRepricingHistory",invocation:{kind:"direct"},parameters:[],result:X("RepricingHistory",ae)},{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",se)}],result:X("FetchPricesResult",ce)},{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",se)},{name:"model",wire:"model",source:"json",codec:X("RepricingModel",me)}],result:X("FetchPricesResult",ce)}]},ve=a=>(a.label+" "+a.value).toLowerCase();function ne({options:a,value:r,placeholder:M,label:g,ariaLabel:d,locale:u,onChange:n}){const x=u==="en",k=xe(),l=k+"-list",[_,z]=O(""),[p,F]=O(!1),[w,y]=O(0),[S,E]=O(null),h=te(null),s=te(null),m=te(null),f=a.find(o=>o.value===r),P=_.toLowerCase().trim().split(/\s+/).filter(Boolean),v=G(()=>a.map(o=>({option:o,search:ve(o)})),[a]),R=o=>{const b=o.toLowerCase().trim().split(/\s+/).filter(Boolean);return b.length?v.filter(D=>b.every(t=>D.search.includes(t))).map(D=>D.option):a},c=R(_),L=f&&!c.includes(f)?[f,...c]:c,T=Math.max(0,Math.min(w,L.length-1)),U=()=>{F(!1),z("")},B=()=>{p||(E(null),z(""),y(Math.max(0,L.findIndex(o=>o.value===r))),F(!0))},i=o=>{o&&(o.value!==r&&n(o.value),U())},j=()=>{if(p&&_){z(""),y(0);return}r&&n(""),U()};ie(()=>{if(!p||typeof document>"u")return;const o=s.current,b=typeof window>"u"?null:window,D=()=>{const t=o?.getBoundingClientRect?.();if(!t||!b)return;const N=b.innerHeight,H=12,I=N-t.bottom-H,Y=t.top-H,A=I<180&&Y>I,Q=Math.max(60,A?Y:I),q=Math.max(0,Math.min(280,Q,N-H*2)),ee=Math.max(H,Math.min(A?t.top-q-6:t.bottom+6,N-q-H));E(K=>K&&K.left===t.left&&K.top===ee&&K.width===t.width&&K.maxHeight===q?K:{left:t.left,top:ee,width:t.width,maxHeight:q})};if(D(),typeof b?.addEventListener=="function")return b.addEventListener("scroll",D,!0),b.addEventListener("resize",D),()=>{b.removeEventListener("scroll",D,!0),b.removeEventListener("resize",D)}},[p]),re(()=>{if(!p||typeof document>"u"||typeof document.addEventListener!="function")return;const o=b=>{h.current?.contains?.(b.target)||m.current?.contains?.(b.target)||U()};return document.addEventListener("pointerdown",o,!0),()=>document.removeEventListener("pointerdown",o,!0)},[p]),ie(()=>{!p||!S||m.current?.querySelector?.('[data-active="true"]')?.scrollIntoView?.({block:"nearest"})},[p,T,S,_]);const $=o=>k+"-opt-"+o,Z=P.length?c.length?x?`${c.length} matches`:`${c.length} 个结果`:L.length?x?"No matches · showing the current choice":"没有匹配的模型 · 下面是当前选择":x?"No matches":"没有匹配的模型":null,W=p?e("div",{ref:m,className:"cm-combo-panel",style:S??{visibility:"hidden"}},L.length?e("div",{className:"cm-combo-list",id:l,role:"listbox","aria-label":g},L.map((o,b)=>e("button",{key:o.value,id:$(b),type:"button",role:"option",className:"cm-combo-option"+(b===T?" active":""),"data-active":String(b===T),"aria-selected":String(o.value===r),onMouseEnter:()=>y(b),onMouseDown:D=>D.preventDefault(),onClick:()=>i(o)},o.label))):null,Z?e("p",{className:"cm-combo-note",role:"status"},Z):null):null;return e("div",{ref:h,className:"cm-price-search cm-combo"},e("div",{className:"cm-combo-control"},e("input",{ref:s,type:"search",className:"cm-input cm-combo-input",autoComplete:"off",value:p?_:f?.label??"",role:"combobox","aria-expanded":String(p),"aria-autocomplete":"list","aria-controls":p&&L.length?l:void 0,"aria-activedescendant":p&&L.length?$(T):void 0,"aria-label":d??g+(x?" · Price model":" · 价格模型"),placeholder:p&&f?f.label:M,onFocus:B,onClick:()=>{p||B()},onChange:o=>{const b=o.target.value,D=!p&&f&&b.startsWith(f.label)?b.slice(f.label.length):b,t=R(D);z(D),F(!0),y(f&&t.length>0&&!t.includes(f)?1:0)},onKeyDown:o=>{if(!o.nativeEvent?.isComposing){if(o.key==="Escape"){if(o.preventDefault(),!p)return;U(),o.stopPropagation();return}if(o.key==="ArrowDown"||o.key==="ArrowUp"){if(o.preventDefault(),!p){B();return}y(Math.max(0,Math.min(L.length-1,T+(o.key==="ArrowDown"?1:-1))));return}if(o.key==="Enter"&&p&&L[T]){o.preventDefault(),i(L[T]);return}o.key==="Tab"&&U()}}}),r||_?e("button",{type:"button",className:"cm-combo-clear","aria-label":(x?"Clear ":"清空 ")+g,onMouseDown:o=>o.preventDefault(),onClick:j},"×"):null,e("button",{type:"button",className:"cm-combo-caret",tabIndex:-1,"aria-hidden":"true",onMouseDown:o=>o.preventDefault(),onClick:()=>{p?U():(s.current?.focus?.(),B())}},"▾")),W&&oe?oe(W,document.body):W)}function ue({state:a,draft:r,setDraft:M,locale:g,rpc:d}){const[u,n]=O(!1),[x,k]=O(null),[l,_]=O(""),[z,p]=O(""),[F,w]=O(0),y=a.config.prices.currency??"USD",S=g==="en";re(()=>{if(!u)return;let m=!0;return k(null),p(""),_(""),d("getPriceCatalog").then(f=>{m&&k(f)},f=>{m&&p(String(f.message??f))}),()=>{m=!1}},[u,y,F,d]);const E=[];for(const[m,f]of Object.entries(x??{}))for(const P of Object.values(f))for(const[v,R]of Object.entries(P))!(m==="deepseek"?r?.prices.models[v]:r?.prices.providers?.[m]?.models?.[v])&&!R.unpriced&&E.push({value:m+":"+v,label:m+" · "+v,provider:m,id:v,entry:R});const h=E.find(m=>m.value===l),s=()=>{if(!h||!r)return;const{provider:m,id:f,entry:P}=h,v=JSON.parse(JSON.stringify(P)),R=r.prices;M({...r,prices:m==="deepseek"?{...R,models:{...R.models,[f]:v}}:{...R,providers:{...R.providers,[m]:{...R.providers?.[m],models:{...R.providers?.[m]?.models,[f]:v}}}}}),_("")};return e("div",{className:"cm-restore-prices"},e("button",{type:"button",className:"cm-btn small","aria-expanded":u,onClick:()=>n(m=>!m)},u?S?"Close restore":"收起恢复入口":S?"Restore bundled model":"恢复内置模型"),u?e("div",{className:"cm-collapse-body"},z?e("div",{role:"alert",className:"cm-err"},z,e("button",{type:"button",className:"cm-btn small",onClick:()=>w(m=>m+1)},S?"Retry":"重试")):x===null?e("p",{role:"status",className:"cm-hint"},S?"Loading prices…":"读取价格…"):E.length?e(be,null,e(ne,{options:E,value:h?l:"",placeholder:S?"Select a model":"选择模型",label:S?"Restore model":"恢复模型",locale:g,onChange:_}),e("button",{type:"button",className:"cm-btn small",disabled:!h,onClick:s},S?"Restore":"恢复")):e("p",{className:"cm-hint"},S?"All bundled models are mounted.":"内置模型均已挂载。")):null)}function Ne({value:a,label:r,locale:M,onChange:g,t:d,priceEditor:u}){const n=M==="en",{PriceInput:x,priceFactor:k,setPriceFactor:l,multiplierOptions:_}=u,z=[["cacheMiss",n?"Input · cache miss":"输入 · 未命中缓存"],["cacheHit",n?"Cached input":"缓存读取"],["output",n?"Output":"输出"],["cacheWrite",n?"Cache write":"缓存写入"],["reasoning",n?"Separate reasoning":"单独推理费用"]],p=(w,y,S)=>{const E={...a};y===null?delete E[w]:E[w]=y,l(E,"base."+w,S),g(E)},F=([w,y])=>e("label",{key:w},y,e("span",{className:"cm-custom-amount"},e("span",{"aria-hidden":!0},a.currency==="CNY"?"¥":"$"),e(x,{entry:a,value:a[w]??null,path:"base."+w,t:d,emptyMode:["cacheWrite","reasoning"].includes(w)?"clear":"ignore",label:r+" · "+y,placeholder:w==="cacheWrite"?n?"Same as cached input":"跟随缓存读取":w==="reasoning"?n?"Included in output":"含在输出中":"0",onCommit:(S,E)=>p(w,S,E)})));return e("fieldset",{className:"cm-custom-price","aria-label":r+(n?" · Custom price":" · 自定义价格")},e("legend",null,n?"Custom price · per 1M tokens":"自定义价格 · 每百万 Token"),e("div",{className:"cm-custom-head"},e("span",null,n?"Only this channel and model":"仅用于此渠道的这个模型"),e("label",null,n?"Currency":"币种",e("select",{className:"cm-input",value:a.currency,onChange:w=>g({...a,currency:w.target.value})},e("option",{value:"USD"},n?"USD · US dollar":"USD · 美元"),e("option",{value:"CNY"},n?"CNY · Yuan":"CNY · 人民币")))),e("div",{className:"cm-custom-grid"},...z.slice(0,3).map(F)),_(a,d,w=>g({...a,separateMultipliers:w,multipliers:{}})),e("div",{className:"cm-custom-effective",role:"status"},e("div",{className:"cm-effective-heading"},e("span",null,n?"Effective prices":"实际单价"),e("small",null,n?"Price × multiplier / 1M tokens":"单价 × 倍率 / 百万 Token")),e("div",{className:"cm-effective-grid"},...z.slice(0,3).map(([w,y])=>e("div",{key:w},e("span",null,y),e("strong",null,(a.currency==="CNY"?"¥":"$")+Number((a[w]*k(a,"base."+w)).toPrecision(8)).toLocaleString(n?"en-US":"zh-CN",{maximumFractionDigits:8})))))),e("details",{className:"cm-custom-more"},e("summary",null,n?"More billing fields":"更多计费项"),e("div",{className:"cm-custom-grid"},...z.slice(3).map(F)),e("p",{className:"cm-hint"},n?"Leave reasoning blank when it is included in output. Leave cache write blank to use the cached input rate.":"推理已包含在输出中时无需另填。缓存写入留空则使用缓存读取价格。")),e("p",{className:"cm-hint"},n?"Enter or leave a field to save. Switching the price source keeps your custom values.":"回车或离开输入框后保存;切换价格来源会保留已填的自定义价格。"))}function ge({entry:a,currency:r,priceEditor:M,locale:g,local:d=!1}){const u=g==="en",n=a?M?.priceAt?.(a)??a:null;return e("span",{className:"cm-rate-summary"},...[["cacheMiss","input",u?"Input":"输入"],["cacheHit","cachedInput",u?"Cached input":"缓存读取"],["output","output",u?"Output":"输出"]].map(([k,l,_])=>{const z=d?0:n?.unpriced?null:n?.[k]??n?.[l],p=z==null?null:z*(M?.priceFactor?.(n??{},"base."+k)??1);return e("span",{key:k,className:"cm-rate-item"},e("span",null,_),e("strong",null,p===null?"—":(r==="CNY"?"¥":"$")+Number(p.toPrecision(8)).toLocaleString(u?"en-US":"zh-CN",{maximumFractionDigits:8})))}))}function ke({state:a,draft:r,setDraft:M,locale:g}){if(a.ourFreeModel?.enabled!==!0)return null;const d=g==="en",u=r?.priceOverrides??a.config.priceOverrides??{},n=["our-free-model:*","our-free-model-region:*"],x=n.every(k=>u[k]==="__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:x,onChange:k=>{if(!r)return;const l={...u};for(const _ of n)k.target.checked?l[_]="__free__":l[_]==="__free__"&&delete l[_];M({...r,priceOverrides:l})}}),e("span",null,d?"Count dsh-our-free-model calls as free":"dsh-our-free-model 调用按免费计算")),e("p",{className:"cm-hint"},d?"Future calls through this plugin cost 0; tokens are still counted. Historical costs and other providers stay unchanged.":"仅此插件后续调用记为免费,Token 照常统计;历史费用和其他渠道不变。"))}function Ce({state:a,draft:r,setDraft:M,t:g,locale:d,resolveClientPrice:u,prettyProviderKey:n,setField:x,priceEditor:k}){const[l,_]=O(""),[z,p]=O(24),[F,w]=O(null),[y,S]=O({}),E=te(new Map),h=te(null),s=d==="en",m=a.config,f=r?.priceOverrides??m.priceOverrides??{},P=r?.priceMatchDismissed??m.priceMatchDismissed??[],v=r?.prices??m.prices,R=r?.modelStatistics??m.modelStatistics??{},c=[["today","今日费用","Today"],["summary","月度与累计","Monthly / all-time"],["budget","预算","Budget"]],L=G(()=>({...a.total?.byProviderModel,...a.month?.byProviderModel,...a.today?.byProviderModel,...Object.fromEntries(Object.keys(R).map(t=>[t,null]))}),[a.total?.byProviderModel,a.month?.byProviderModel,a.today?.byProviderModel,R]),T=a.modelDirectory,U=G(()=>[...new Set([...Object.keys(L),...Object.keys(f)])].filter(t=>{if(P.includes(t)||ye(t)||["our-free-model:*","our-free-model-region:*"].includes(t))return!1;if(!Array.isArray(T?.providers))return!0;const N=t.slice(0,t.indexOf(":"));return T.providers.includes(N)&&!T.missingModels?.includes(t)}).sort(),[L,f,P,T]);ie(()=>{const t=E.current.get(h.current)?.querySelector(".cm-custom-price");t&&(h.current=null,t.scrollIntoView({block:"start",inline:"nearest"}),t.querySelector("input")?.focus({preventScroll:!0}))},[v,y]);const B=G(()=>[{value:"deepseek:__default__",label:g("overrideTargetDefault")},...Object.keys(v.models??{}).map(t=>({value:"deepseek:"+t,label:"DeepSeek · "+t})),...Object.entries(v.providers??{}).flatMap(([t,N])=>Object.keys(N?.models??{}).map(H=>({value:t+":"+H,label:t+" · "+H})))],[v.models,v.providers,d,g]),i=(t,N)=>{if(r===null)return;const H={...r.priceOverrides??{}};if(N===""?delete H[t]:H[t]=N,N==="__custom__"&&!v.custom?.[t]){const I=t.indexOf(":"),Y=u(t.slice(0,I),t.slice(I+1),{...m,...r}),A=Y.entry??{},Q={currency:Y.currency??"USD",billingMode:"flat",...k?.priceMultiplierSettings(A),cacheMiss:A.cacheMiss??A.input??0,cacheHit:A.cacheHit??A.cachedInput??A.cacheMiss??A.input??0,output:A.output??0,...A.cacheWrite!==void 0?{cacheWrite:A.cacheWrite}:{},...A.reasoning!==void 0?{reasoning:A.reasoning}:{}};M({...r,priceOverrides:H,prices:{...v,custom:{...v.custom,[t]:Q}}})}else M({...r,priceOverrides:H})},j=t=>{if(r===null)return;const N={...r.priceOverrides??{}};delete N[t],M({...r,priceOverrides:N,priceMatchDismissed:[...new Set([...P,t])]})},$=l.trim().toLowerCase().split(/\s+/).filter(Boolean),W=(t=>t.filter(N=>$.every(H=>(N+" "+n(N)).toLowerCase().includes(H))))(U),o=W.length,b=W.slice(0,z),D=t=>{const N=n(t),H=N.indexOf(":"),I=f[t],Y=F===t,A=y[t]??(I==="__custom__"?"custom":I==="__local__"?"local":I?"catalog":"auto"),Q=t.indexOf(":"),q=u(Q>0?t.slice(0,Q):"deepseek",Q>0?t.slice(Q+1):t,{...m,...r}),ee=!I&&q.matched===!0,K=C=>{C==="custom"&&(h.current=t),S({...y,[t]:C}),C!=="catalog"&&i(t,C==="custom"?"__custom__":C==="local"?"__local__":"")},fe=c.filter(([C])=>R[t]?.[C]!==!1),ze=(C,V)=>{if(!r)return;const J={...R,[t]:{today:!0,summary:!0,budget:!0,...R[t],[C]:V}};Object.values(J[t]).every(Boolean)&&delete J[t],M({...r,modelStatistics:J})},Oe=ee?s?"Automatic":"自动匹配":I==="__custom__"?s?"Custom price":"自定义价格":I==="__local__"?s?"Local · free":"本地 · 零费用":I?s?"Price table":"指定价格表":s?"Needs a price":"待设置价格";return e("div",{key:t,className:"cm-match-row","data-model-key":t,"data-open":Y,ref:C=>{C?E.current.set(t,C):E.current.delete(t)}},e("div",{className:"cm-model-head"},e("div",{className:"cm-model-identity",title:N},e("strong",null,H>0?N.slice(H+1):N),e("span",{className:"cm-model-meta"},e("span",{className:"cm-model-provider"},H>0?N.slice(0,H):"DeepSeek"),e("span",{className:"cm-model-badge"+(!ee&&!I?" needs-price":"")},Oe))),e("div",{className:"cm-model-current",title:s?"Effective rates per 1M tokens, including multipliers":"每百万 Token 实际单价,已含倍率"},e(ge,{entry:q.entry,currency:q.currency,priceEditor:k,locale:d,local:I==="__local__"})),e("button",{type:"button",className:"cm-btn small cm-model-edit","aria-expanded":Y,"aria-label":N+(s?" · Set price":" · 设置价格"),onClick:()=>w(Y?null:t)},Y?s?"Collapse":"收起":s?"Set price":"设置价格")),e("details",{className:"cm-model-statistics","data-model-statistics":t},e("summary",null,s?"Include in statistics":"计入统计",fe.length===3?null:e("span",{className:"cm-note"},fe.map(([,C,V])=>s?V:C).join(" · ")||(s?"None":"均不计入"))),e("div",{className:"cm-model-statistics-options"},...c.map(([C,V,J])=>e("label",{key:C,className:"cm-check"},e("input",{type:"checkbox",checked:R[t]?.[C]!==!1,"aria-label":N+" · "+(s?J:V),onChange:Pe=>ze(C,Pe.target.checked)}),s?J:V)))),Y?e("div",{className:"cm-model-editor"},e("div",{className:"cm-source-choices",role:"group","aria-label":s?"Price source":"价格来源"},...[["auto","自动匹配","Automatic"],["catalog","价格表","Price table"],["custom","自定义","Custom"],["local","本地","Local"]].map(([C,V,J])=>e("button",{key:C,type:"button",className:"cm-source-choice"+(A===C?" active":""),"aria-pressed":A===C,onClick:()=>K(C)},s?J:V))),A==="catalog"?e("div",{className:"cm-model-source"},e("span",null,s?"Select a reference model":"选择参考模型"),e(ne,{value:I&&!I.startsWith("__")?I:"",options:B,placeholder:s?"Choose a price table entry":"选择价格表条目",label:N,locale:d,onChange:C=>{C?i(t,C):K("auto")}}),!I||I.startsWith("__")?e("p",{className:"cm-note"},s?"Current pricing stays in effect until you choose an entry.":"选定条目后生效,选择前仍使用原价格。"):null):null,A==="custom"&&I==="__custom__"&&v.custom?.[t]?e(Ne,{value:v.custom[t],label:N,locale:d,t:g,priceEditor:k,onChange:C=>M({...r,prices:{...v,custom:{...v.custom,[t]:C}}})}):null,A==="auto"?e("p",{className:"cm-source-explanation"},q.matched?s?"The model uses its automatically matched reference price.":"已自动匹配参考价格,后续调用按该价格计费。":s?"No exact price found. Choose a table entry or enter a custom quote.":"尚未命中参考价格,可选择价格表条目或填写自定义价格。"):null,A==="local"?e("p",{className:"cm-source-explanation"},s?"Tokens are tracked; new calls have zero API cost.":"保留 Token 统计,后续调用的 API 费用记为 0。"):null,ee?null:e("button",{type:"button",className:"cm-model-dismiss",title:g("removePriceMatchHint"),onClick:()=>j(t)},g("overrideRemove"))):null)};return e("div",{className:"cm-model-matching"},e(ke,{state:a,draft:r,setDraft:M,locale:d}),e("div",{className:"cm-model-toolbar"},e("input",{type:"search",className:"cm-input",value:l,placeholder:s?"Find a model or channel…":"查找模型或渠道…","aria-label":s?"Find configured models":"查找已用模型",onChange:t=>{_(t.target.value),p(24)},onKeyDown:t=>{t.key==="Escape"&&(_(""),p(24),t.stopPropagation())}}),e("span",{className:"cm-note",role:"status"},s?`${o} models`:`${o} 个模型`)),b.length?e("div",{className:"cm-model-list"},e("div",{className:"cm-model-columns","aria-hidden":!0},e("span",null,s?"Model / channel":"模型 / 渠道"),e("span",{className:"cm-rate-summary"},...[s?"Input":"输入",s?"Cached input":"缓存读取",s?"Output":"输出"].map(t=>e("span",{key:t},t))),e("span",{title:s?"Per 1M tokens":"每百万 Token"},"/ 1M tok")),...b.map(D)):null,o===0?e("p",{className:"cm-pricing-empty"},l?s?"No models found. Try another keyword.":"没有找到模型,试试其他关键词。":s?"Models appear here after their first call.":"调用过的模型会显示在这里,之后可按渠道设置价格。"):null,o>z?e("button",{type:"button",className:"cm-btn",onClick:()=>p(t=>t+24)},s?`Show more · ${o-z} remaining`:`显示更多 · 还有 ${o-z} 个`):null,P.length>0?e("button",{type:"button",className:"cm-btn small",onClick:()=>x("priceMatchDismissed",[])},g("restorePriceMatches",{count:P.length})):null,e("details",{className:"cm-pricing-rules"},e("summary",null,s?"Automatic matching rules":"自动匹配规则"),e("label",{className:"cm-field"},e("span",null,g("priceMatchLabel")),e("select",{className:"cm-input",value:r?.priceMatch==="exact"?"exact":"auto",onChange:t=>x("priceMatch",t.target.value)},e("option",{value:"auto"},g("priceMatchAuto")),e("option",{value:"exact"},g("priceMatchExact")))),e("p",{className:"cm-note"},g("priceMatchNote"))))}function he({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 Me({state:a,draft:r,setDraft:M,t:g,locale:d,rpc:u,renderEditor:n,vendorLabels:x,priceEditor:k}){const l=d==="en",[_,z]=O(""),[p,F]=O(""),[w,y]=O({}),[S,E]=O({}),[h,s]=O(null),[m,f]=O(""),P=r?.prices??a.config.prices,v=G(()=>({...P.providers,deepseek:{models:{...P.models,__default__:P.default}}}),[P.models,P.default,P.providers]),R=Object.keys(v).filter(i=>Object.keys(v[i]?.models??{}).length).sort((i,j)=>i===j?0:i==="deepseek"?-1:j==="deepseek"?1:i.localeCompare(j)),c=_.toLowerCase().trim().split(/\s+/).filter(Boolean),L=R.filter(i=>!p||p===i).map(i=>({id:i,ids:Object.keys(v[i].models).filter(j=>c.every($=>(i+" "+(x[i]??"")+" "+(j==="__default__"?g("defaultModelId"):j)).toLowerCase().includes($))).sort((j,$)=>j===$?0:j==="__default__"?1:$==="__default__"?-1:j.localeCompare($))})).filter(i=>i.ids.length),T=L.reduce((i,j)=>i+j.ids.length,0),U=i=>{z(i),E({}),y({})},B=()=>{const i=m.trim().toLowerCase();!r||!/^[a-z0-9_.-]+$/.test(i)||Object.hasOwn(P.models,i)||(M({...r,prices:{...P,models:{...P.models,[i]:{cacheHit:0,cacheMiss:0,output:0}}}}),f(""),F("deepseek"),z(i),y(j=>({...j,deepseek:!0})),s("deepseek:"+i))};return e("div",{className:"cm-reference-prices"},e("p",{className:"cm-note"},l?"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:_,"aria-label":l?"Search mounted prices":"搜索已挂载价格",placeholder:l?"Search models or providers…":"搜索模型或厂商…",onChange:i=>U(i.target.value),onKeyDown:i=>{i.key==="Escape"&&(U(""),i.stopPropagation())}}),e("select",{className:"cm-input",value:p,"aria-label":l?"Filter price provider":"筛选价格厂商",onChange:i=>{F(i.target.value),E({}),y({})}},e("option",{value:""},l?"All providers":"全部厂商"),...R.map(i=>e("option",{key:i,value:i},x[i]??i))),e("span",{className:"cm-note",role:"status"},l?`${T} models`:`${T} 个模型`)),...L.map(({id:i,ids:j})=>{const $=w[i]??(i==="deepseek"||c.length>0||p===i),Z=i==="deepseek"?P.currency??"USD":"USD",W=S[i]??16;return e("section",{key:i,className:"cm-catalog-group"},e("button",{type:"button",className:"cm-catalog-vendor cm-vendor-toggle","aria-expanded":$,onClick:()=>y(o=>({...o,[i]:!$}))},e("span",null,e(he,{className:"cm-catalog-caret",open:$}),x[i]??i,e("small",null,j.length)),e("span",{className:"cm-catalog-unit"},Z+(l?" / 1M tokens":" / 百万 Token"))),$?e("div",{className:"cm-catalog-list"},e("div",{className:"cm-catalog-columns","aria-hidden":!0},...[l?"Model":"模型",l?"Input":"输入",l?"Cached input":"缓存读取",l?"Output":"输出",""].map((o,b)=>e("span",{key:b},o))),...j.slice(0,W).map(o=>{const b=i+":"+o,D=v[i].models[o],t=h===b,N=o==="__default__"?g("defaultModelId"):o,H=D?.peak||D?.offPeak?l?"Peak / off-peak":"含峰谷价格":D?.longContext?l?"Long context":"含长上下文档位":D?.cny?l?"USD + CNY":"美元 / 人民币":null;return e("div",{key:b,className:"cm-catalog-entry"+(t?" editing":"")},e("button",{type:"button",className:"cm-catalog-model","aria-label":N+(l?" · Edit price":" · 编辑价格"),"aria-expanded":t,onClick:()=>s(t?null:b)},e("span",{className:"cm-catalog-model-name"},e("strong",null,N),H?e("small",null,H):null),e(ge,{entry:D,currency:Z,priceEditor:k,locale:d}),e(he,{className:"cm-catalog-edit-caret",open:t})),t?e("div",{className:"cm-catalog-editor"},n(i,o,D)):null)}),j.length>W?e("button",{type:"button",className:"cm-catalog-more",onClick:()=>E(o=>({...o,[i]:W+16}))},l?`Show more · ${j.length-W} remaining`:`显示更多 · 还有 ${j.length-W} 个`):null):null)}),T===0?e("p",{className:"cm-pricing-empty"},l?"No matching models.":"没有找到匹配的模型。"):null,e("details",{className:"cm-pricing-rules"},e("summary",null,l?"Pricing notes":"计价说明"),e("p",{className:"cm-note"},g("priceTableNote"))),e("details",{className:"cm-catalog-manage"},e("summary",null,l?"Add or restore models":"添加与恢复模型"),e("div",{className:"cm-catalog-add"},e("input",{className:"cm-input",value:m,"aria-label":g("newModelPlaceholder"),placeholder:g("newModelPlaceholder"),onChange:i=>f(i.target.value),onKeyDown:i=>{i.key==="Enter"&&(i.preventDefault(),B())}}),e("button",{type:"button",className:"cm-btn small",disabled:!/^[a-z0-9_.-]+$/.test(m.trim().toLowerCase())||Object.hasOwn(P.models,m.trim().toLowerCase()),onClick:B},g("addModel"))),e(ue,{state:a,draft:r,setDraft:M,locale:d,rpc:u})))}function _e({state:a,locale:r,formatMoneyUsd:M,api:g,rpc:d,disabled:u}){const[n,x]=O(!1),[k,l]=O(!1),[_,z]=O(""),[p,F]=O([]),[w,y]=O(""),[S,E]=O(""),h=r==="en",s=(c,L)=>{const T=a.config.currency==="CNY"?"Cny":a.config.currency==="EUR"?"Eur":"",U=T&&c[L+T],B=Number(a.config.exchangeRate);return M(typeof U=="number"&&B>0?U/B:c[L],a.config)},m=h?"All models":"全部模型",f=G(()=>[...new Set([a.today,a.month,...a.history??[]].flatMap(c=>Object.keys(c?.byProviderModel??{})))].filter(c=>c.indexOf(":")>0).sort(),[a.today,a.month,a.history]),P=G(()=>[{value:"",label:m},...f.map(c=>({value:c,label:c}))],[f,m]),v=()=>d("getRepricingHistory").then(c=>{F(ae.parse(c)),y("")}).catch(c=>y(String(c.message??c)));re(()=>{let c=!0;return d("getRepricingHistory").then(L=>{c&&F(ae.parse(L))},L=>{c&&y(String(L.message??L))}),()=>{c=!1}},[d]);const R=async()=>{if(!(!n||k||u)){l(!0),y(""),z("");try{const c=S?await d("repriceModelHistory",!0,S):await d("repriceHistory",!0);if(!c.ok)throw new Error(c.message);z(c.message),x(!1),await v(),await g.reload()}catch(c){y(String(c.message??c))}finally{l(!1)}}};return e("section",{className:"cm-repricing"},e("h3",{className:"cm-h"},h?"Historical pricing":"历史费用"),e("p",{className:"cm-note"},h?"Rate changes apply to new calls. Recorded historical rates remain fixed.":"修改价格只影响后续调用,历史费用沿用原价格。"),e("div",{className:"cm-repricing-scope"},e("label",null,h?"Recalculation scope":"重算范围"),e(ne,{options:P,value:S,locale:r,label:h?"Choose channel and model":"选择渠道与模型",ariaLabel:h?"Choose channel and model":"选择渠道与模型",placeholder:h?"Search historical models":"搜索历史渠道或模型",onChange:c=>{k||(E(c),x(!1),z(""))}}),e("p",{className:"cm-hint"},S?h?"Only this channel/model changes. Other models and original exchange rates remain unchanged.":"仅重算此渠道下的这个模型,其他模型及原调用汇率保持不变。":h?"Choose a single channel/model to limit the recalculation.":"可选择单个渠道模型,缩小重算范围。")),n?e("div",{className:"cm-repricing-warning",role:"alert",onKeyDown:c=>{c.key==="Escape"&&!k&&(x(!1),c.stopPropagation())}},e("strong",null,(S||m)+(h?" · Historical amounts will change":" · 将修改历史费用")),e("p",null,h?"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:k,onClick:()=>x(!1)},h?"Cancel":"取消"),e("button",{type:"button",className:"cm-btn danger",disabled:k||u,onClick:R},k?h?"Recalculating…":"正在重算…":h?"Confirm recalculation":"确认重算"))):e("button",{type:"button",className:"cm-btn",disabled:u||k,onClick:()=>x(!0)},S?h?"Recalculate this model":"重算此模型的历史费用":h?"Recalculate history at current rates":"按当前价格重算历史"),_?e("p",{role:"status",className:"cm-note"},_):null,w?e("p",{role:"alert",className:"cm-err"},w):null,p.length?e("details",{className:"cm-repricing-history"},e("summary",null,h?"Recalculation records · original amounts retained":"重算记录 · 原金额已保留"),e("div",{className:"cm-stat-scroll"},e("table",{className:"cm-stat-table"},e("thead",null,e("tr",null,...(h?["Time","Scope","Before","After","Session/day records"]:["重算时间","范围","原金额","重算后","会话日期记录"]).map(c=>e("th",{key:c,scope:"col"},c)))),e("tbody",null,...p.map(c=>e("tr",{key:c.at},e("td",null,new Date(c.at).toLocaleString(r)),e("td",null,c.model||m),e("td",null,s(c,"before")),e("td",null,s(c,"after")),e("td",null,c.sessions))))))):null)}async function Se(a){const r=await a.get("remote").$mount(pe);a.effect(()=>()=>r(),"cost-meter: pricing settings contribution");const M=a.get("remote.costMeter"),g=async(u,...n)=>{(u==="repriceHistory"||u==="repriceModelHistory")&&se.parse(n[0]),u==="repriceModelHistory"&&me.parse(n[1]);const x=await M[u](...n);if(x?.ok!==!0)throw new Error(x?.error?.message??"Pricing request failed");return(u==="getPriceCatalog"?de:u==="getRepricingHistory"?ae:ce).parse(x.value)},d=document.createElement("style");return d.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}",d.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)}",d.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}",d.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}",d.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(d),d.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}
|
|
@@ -14,7 +14,7 @@ window.__ModuleLoader__.load({id:"dsh-cost-meter",chunk:"client.pricing.js",fact
|
|
|
14
14
|
.cm-custom-effective{display:grid;gap:12px;padding:12px;background:var(--dsw-alias-bg-layer-1);border-radius:8px;font-size:12px;font-variant-numeric:tabular-nums}.cm-effective-heading{display:flex;justify-content:space-between;gap:6px;flex-wrap:wrap}.cm-effective-heading>span{font-weight:500}.cm-effective-heading small,.cm-effective-grid span{color:var(--dsw-alias-label-tertiary);font-size:11px}.cm-effective-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:10px}.cm-effective-grid>div{display:grid;gap:5px;min-width:0}.cm-effective-grid strong{font-size:14px;font-weight:600;overflow-wrap:anywhere}
|
|
15
15
|
.cm-pricing-page .cm-price-card{min-width:0;container:cm-price-editor / inline-size}.cm-pricing-page .cm-price-row{min-width:0}.cm-pricing-page .cm-price-row input{max-width:none;font-variant-numeric:tabular-nums}.cm-pricing-catalog .cm-catalog-vendor{margin-top:8px}
|
|
16
16
|
@media(max-width:480px){.cm-model-matching .cm-match-row{padding:8px 10px}.cm-model-matching .cm-custom-price{padding:10px}.cm-custom-more .cm-custom-grid{grid-template-columns:1fr}.cm-effective-grid{gap:8px}.cm-model-identity{flex-basis:100%}}
|
|
17
|
-
`,
|
|
17
|
+
`,d.textContent+=`
|
|
18
18
|
.cm-model-current{min-width:0}
|
|
19
19
|
.cm-rate-summary{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:12px;min-width:0;font-variant-numeric:tabular-nums}.cm-rate-item{display:grid;gap:4px;min-width:0}.cm-rate-item>span{font-size:11px;color:var(--dsw-alias-label-tertiary)}.cm-rate-item>strong{font-size:14px;font-weight:500;color:var(--dsw-alias-label-primary);overflow-wrap:anywhere}
|
|
20
20
|
.cm-model-list .cm-rate-summary{grid-template-columns:repeat(3,minmax(0,1fr));gap:8px}.cm-model-list .cm-rate-item{gap:0}.cm-model-list .cm-rate-item>span{position:absolute;width:1px;height:1px;clip-path:inset(50%);overflow:hidden}.cm-model-list .cm-rate-item>strong{font-size:13px}
|
|
@@ -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
|
-
`,
|
|
30
|
+
`,d.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(()=>()=>d.remove(),"cost-meter: pricing settings styles"),u=>u.mode==="matching"?e(Ce,u):e(u.mode==="catalog"?Me:u.mode==="restore"?ue:_e,{...u,rpc:g})}return{mount:Se,CONTRIBUTION:pe}}});
|