import{r as e,x as t}from"./authSession-CrP9lMPq.js";import{r as n}from"./norm-CeclA1Tu.js";import{d as r,f as i}from"./cloudModel-CGo_el7I.js";var a=`https://api2.bysjob.com`,o=()=>{let e=String(globalThis?.location?.protocol||``);return e===`chrome-extension:`||e===`moz-extension:`||e===`safari-extension:`},s=()=>{try{return`https://api2.bysjob.com`.replace(/\/+$/g,``)}catch{}if(!o()){let e=String(globalThis?.location?.origin||``).replace(/\/+$/g,``);if(e.includes(`localhost`)||e.includes(`127.0.0.1`))return e}return a},c=(e,t)=>{let r=n(e?.error).toLowerCase();return r===`auth_required`||r===`unauthorized`||r===`invalid_session`||r===`session_expired`?`请先登录后再开始任务。`:r===`balance_query_failed`?`无法确认积分余额，请稍后重试。`:r===`missing_quote_items`?`缺少可报价的模型和 token 预算。`:String(e?.message||e?.error||t||`积分预检失败`)},l=async r=>{let i=`${s()}/api/billing/quote`,a=await e(),o=n(a?.accessToken||a?.token);if(!o)throw Error(`请先登录`);let l={"Content-Type":`application/json`};l.Authorization=`Bearer ${o}`,l[`x-auth-token`]=o;try{let e=String(await t()||``).slice(0,64);e&&(l[`x-device-key`]=e)}catch{}let u={tool:n(r.tool),items:Array.isArray(r.items)?r.items:[],fallbackInputTokens:Math.max(0,Math.floor(Number(r.fallbackInputTokens||0)||0)),fallbackOutputTokens:Math.max(0,Math.floor(Number(r.fallbackOutputTokens||0)||0))},d=await fetch(i,{method:`POST`,headers:l,body:JSON.stringify(u)}),f=await d.text(),p=null;try{p=f?JSON.parse(f):null}catch{}if(!d.ok)throw Error(c(p,f));return p||{}},u={resume_match:`简历匹配`,resume_optimize:`简历优化`,resume_translate:`简历翻译`,job_compare:`岗位对比`,multi_model_resume_match:`多模型简历匹配`,multi_model_resume_optimize:`多模型简历优化`,interview_coach:`面试辅导`,salary_negotiation:`薪酬谈判`,career_coach:`职业教练`},d={qwen_flash:6,deepseek:6,minimax_m27:6,qwen_plus_adv:6,deepseek_pro:12,glm5:8,kimi:10,gemini31_pro:2e3},f=(e,t=800)=>Math.max(1,Math.ceil(Math.max(0,Number(e||0))*1.25)+t),p=e=>e.reduce((e,t)=>e+Math.max(0,Math.floor(Number(t||0))),0),m=e=>e===`resume_optimize`||e===`multi_model_resume_optimize`?{inputTokens:18e3,outputTokens:6e3,structured:!0}:e===`resume_translate`?{inputTokens:1e4,outputTokens:3e3,structured:!1}:e===`job_compare`?{inputTokens:14e3,outputTokens:5e3,structured:!0}:e===`resume_match`||e===`multi_model_resume_match`?{inputTokens:12e3,outputTokens:4e3,structured:!0}:{inputTokens:1e4,outputTokens:5e3,structured:!0},h=e=>{let t=(Array.isArray(e.modelChoices)?e.modelChoices:[]).map(e=>r(String(e||`qwen_flash`))).filter((e,t,n)=>n.indexOf(e)===t);return t.length?t:[r(String(e.modelChoice||`qwen_flash`))]},g=e=>{let t=h(e),n=p([e.inputChars,e.resumeChars,e.jdChars,e.docsChars,e.chatChars,e.dialogChars]),r=m(e.tool),a=f(n,r.inputTokens),o=f(Number(e.outputChars||0),r.outputTokens);return t.map(t=>{let n=i(t)||i(`qwen_flash`);return{providerUsed:n?.provider||`qwen`,modelUsed:n?.model||`qwen-flash`,inputTokens:a,outputTokens:o,includeStructuredRepairReserve:r.structured,searchCostPoints:Math.max(0,Math.floor(Number(e.searchCostPoints||0)||0)),minPoints:d[t]||0}})},_=e=>g(e).reduce((e,t)=>e+Math.max(1,Number(t.minPoints||0))+Math.max(0,Number(t.searchCostPoints||0)),0),v=e=>`${u[e.tool]} 预计需要 ${Math.max(1,Math.round(Number(e.requiredPoints||0)))} 积分（先预扣锁定，按实际用量结算，多余部分会原路退回）；当前账户积分余额 ${Math.max(0,Math.round(Number(e.balancePoints||0)))}、资源包积分余额 ${Math.max(0,Math.round(Number(e.resourcePointsBalance||0)))}，请先购买资源包或单独充值后再开始。`,y=async e=>{let t=e.tool,n=u[t],r=`/me?tab=billing&source=${encodeURIComponent(t)}`,i=g(e),a=_(e);try{let e=await l({tool:t,items:i,fallbackInputTokens:i[0]?.inputTokens||0,fallbackOutputTokens:i[0]?.outputTokens||0});if(!e?.ok)return{ok:!1,canRun:!1,tool:t,label:n,requiredPoints:a,balancePoints:0,resourcePointsBalance:0,rechargeHref:r,message:String(e?.message||`余额校验失败，请稍后重试。`)};let o=Math.max(1,Math.round(Number(e.requiredPoints||a||0))),s=Math.max(0,Math.round(Number(e.balancePoints||0))),c=Math.max(0,Math.round(Number(e.resourcePointsBalance||0)));return e.canRun||s>=o||c>=o?{ok:!0,canRun:!0,tool:t,label:n,requiredPoints:o,balancePoints:s,resourcePointsBalance:c,rechargeHref:r,pricingVersion:String(e?.pricingVersion||``),message:String(e?.message||``)}:{ok:!1,canRun:!1,tool:t,label:n,requiredPoints:o,balancePoints:s,resourcePointsBalance:c,rechargeHref:r,pricingVersion:String(e?.pricingVersion||``),message:v({tool:t,requiredPoints:o,balancePoints:s,resourcePointsBalance:c})}}catch(e){return{ok:!1,canRun:!1,tool:t,label:n,requiredPoints:a,balancePoints:0,resourcePointsBalance:0,rechargeHref:r,message:String(e?.message||`余额校验失败，请稍后重试。`)}}};export{y as n,_ as t};