import{i as e}from"./jsx-runtime-CutOxEx1.js";import{r as t}from"./authSession-Dulxhbeq.js";import{n,t as r}from"./norm-f7iXVy-b.js";import{f as i,o as a}from"./cloudModel-CkCu0fP6.js";import{n as o,t as s}from"./llmSettings-8VBl-FQI.js";import{_ as c,a as l,d as u,f as d,g as f,h as p,m,n as h,t as g,u as _}from"./llm-DjSVhhgj.js";import{t as v}from"./privacyMask-RjOeeXKn.js";import{t as y}from"./roleTaxonomy-BS4qXB9y.js";import{t as b}from"./universityDictionary-BaVUJ_Wo.js";var x=e({generateOptimizeResumeSplitWithAiGateway:()=>F,generateOptimizeResumeWithAiGateway:()=>P}),S=async e=>{try{let e=await t(),n=String(e?.user?.id||``).trim();if(n)return`u:${n}`.slice(0,120)}catch{}return String(e||`public`).slice(0,120)||`public`},C=(e,t)=>{let n=String(e||``).trim().toLowerCase();if(!/^[a-f0-9]{12,64}$/.test(n))return;let r=`${n}:${String(t||``).trim().toLowerCase()}`,i=2166136261,a=2654435769,o=2246822507;for(let e=0;e<r.length;e++){let t=r.charCodeAt(e);i^=t,i=Math.imul(i,16777619),a^=t+e,a=Math.imul(a,2246822507),o^=t+e*17,o=Math.imul(o,3266489909)}return[(i>>>0).toString(16).padStart(8,`0`),(a>>>0).toString(16).padStart(8,`0`),(o>>>0).toString(16).padStart(8,`0`)].join(``).slice(0,24)},w=async e=>{let t=await r();return t?e.map(e=>({...e,jd:v(String(e?.jd||``),t)})):e},T=(e,t)=>{let n=String(e||``).trim();return n?n.length>t?`${n.slice(0,t)}…`:n:``},ee=(e,t,n)=>{let r=Math.min(Math.max(1,Number(n?.maxJobs||12)||12),e.length),i=Math.max(120,Math.min(8e3,Number(n?.excerptLen||4e3)||4e3));return e.slice(0,r).map(e=>{let n=String(e.description||``),r=t===`none`?``:t===`full`?n:T(n,i);return{id:String(e.id||``),title:String(e.title||``),company:String(e.company||``),location:String(e.location||e.city_name||e.province_name||``),experience:String(e.experience||``),education:String(e.education||``),salary_text:String(e.salary?.text||``),salary_min:Number(e.salary?.min||0)||0,salary_max:Number(e.salary?.max||0)||0,platform:String(e.platform||``),jd:r}})},E=(e,t)=>{let n=e=>Array.isArray(e)?e.map(e=>String(e||``).trim()).filter(Boolean):[],r=String(e?.title||``).trim()||(t.toLowerCase().startsWith(`zh`)?`简历优化结果`:`Resume Optimization`);return{lang:String(e?.lang||t||`zh-CN`),title:r,atsKeywords:n(e?.atsKeywords),softSkills:n(e?.softSkills),selfIntro:String(e?.selfIntro||``).trim(),projectRewrite:String(e?.projectRewrite||``).trim(),optimizedResume:String(e?.optimizedResume||``).trim(),changes:n(e?.changes),caveats:n(e?.caveats)}},D=(e,t)=>{let n=t.toLowerCase().startsWith(`zh`),r=[],i=Array.isArray(e.gaps)?e.gaps.slice(0,6):[];(e.atsKeywords||[]).length<6&&r.push(n?`ATS 关键词覆盖偏少，建议继续补强岗位原词。`:`ATS keyword coverage is limited; add more exact JD terms.`),i.length>=4&&r.push(n?`仍有多个关键缺口未被正文充分承接。`:`Several key gaps are not fully addressed in the rewritten resume.`),String(e.optimizedResume||``).includes(`待补充`)&&r.push(n?`正文中仍有待补充占位，投递前请先补全。`:`Placeholders remain in the resume; fill them before applying.`);let a=i.slice(0,5).map(e=>({requirement:e,resumeStatus:n?`证据不足`:`Insufficient evidence`,gapType:`gap`})),o=i.slice(0,6);return{atsNotes:Array.from(new Set(r)).slice(0,6),matchMatrix:a,missingCriticalKeywords:o}},O=(e,t)=>{let n=e=>Array.isArray(e)?e.map(e=>String(e||``).trim()).filter(Boolean):[],r=String(e?.jobId||t.id||``).trim(),i=String(e?.jobTitle||t.title||``).trim(),a=String(e?.company||t.company||``).trim(),o=String(e?.fitLevel||e?.fit_level||``).trim(),s=String(e?.fitSummary||e?.fit_summary||e?.verdict||``).trim(),c=Number(e?.fitScore??e?.fit_score);return{jobId:r,jobTitle:i,company:a,fitLevel:o||void 0,fitScore:Number.isFinite(c)?Math.max(0,Math.min(100,Math.round(c))):void 0,fitSummary:s||void 0,gaps:n(e?.gaps||e?.gapSummary||e?.gap_summary).slice(0,10),optimizedResume:String(e?.optimizedResume||``).trim(),atsKeywords:n(e?.atsKeywords).slice(0,18),missingCriticalKeywords:n(e?.missingCriticalKeywords||e?.missing_keywords||e?.criticalKeywordsMissing).slice(0,12),atsNotes:n(e?.atsNotes||e?.ats_notes).slice(0,10),matchMatrix:(Array.isArray(e?.matchMatrix)?e.matchMatrix:[]).map(e=>({requirement:String(e?.requirement||``).trim(),resumeStatus:String(e?.resumeStatus||e?.resume_status||``).trim(),gapType:String(e?.gapType||e?.gap_type||``).trim()||`partial`})).filter(e=>e.requirement&&e.resumeStatus).slice(0,10),highlights:n(e?.highlights).slice(0,10),changes:n(e?.changes).slice(0,14),caveats:n(e?.caveats).slice(0,12)}},k=(e,t)=>{let n=String(e||``),r=`"${t}"`,i=n.indexOf(r);if(i<0)return``;let a=n.indexOf(`:`,i+r.length);if(a<0)return``;let o=a+1;for(;o<n.length&&/\s/.test(n[o]);)o++;if(n[o]!==`"`)return``;o++;let s=``;for(let e=o;e<n.length;e++){let t=n[e];if(t===`"`)return s;if(t===`\\`){let t=n[e+1];if(t==null)return s;if(t===`n`){s+=`
`,e++;continue}if(t===`r`){s+=`\r`,e++;continue}if(t===`t`){s+=`	`,e++;continue}if(t===`"`||t===`\\`||t===`/`){s+=t,e++;continue}}s+=t}return s},A=(e,t,n=40)=>{let r=String(e||``),i=`"${t}"`,a=r.indexOf(i);if(a<0)return[];let o=r.indexOf(`:`,a+i.length);if(o<0)return[];let s=o+1;for(;s<r.length&&/\s/.test(r[s]);)s++;if(r[s]!==`[`)return[];let c=[],l=``,u=!1,d=!1;for(let e=s+1;e<r.length;e++){let t=r[e];if(!u){if(t===`]`)break;t===`"`&&(u=!0,l=``);continue}if(d){l+=t===`n`?`
`:t===`r`?`\r`:t===`t`?`	`:t,d=!1;continue}if(t===`\\`){d=!0;continue}if(t===`"`){if(String(l||``).trim()&&c.push(String(l).trim()),c.length>=n)break;u=!1;continue}l+=t}return c},j=(e,t)=>O({jobId:t.id,jobTitle:t.title,company:t.company,fitLevel:k(e,`fitLevel`)||`partial`,fitSummary:k(e,`fitSummary`),optimizedResume:k(e,`optimizedResume`),gaps:A(e,`gaps`,10),atsKeywords:A(e,`atsKeywords`,18),missingCriticalKeywords:A(e,`missingCriticalKeywords`,12),atsNotes:A(e,`atsNotes`,10),highlights:A(e,`highlights`,10),changes:A(e,`changes`,14),caveats:A(e,`caveats`,12)},t),M=e=>{if(!e)return!1;let t=e=>String(e||``).trim(),n=e=>Array.isArray(e)?e.map(e=>t(e)).filter(Boolean).length:0;return!!(t(e.optimizedResume)||t(e.fitSummary)||t(e.fitLevel)&&t(e.fitLevel)!==`partial`||n(e.atsKeywords)>0||n(e.highlights)>0||n(e.changes)>0||n(e.gaps)>0)},N=async e=>{let t=await a(),n=i(t),r=String(e?.provider||``).trim(),o=String(e?.model||``).trim();return{modelChoice:t,effectiveProvider:r||n?.provider||``,effectiveModel:o||(r?``:String(n?.model||``).trim())}},P=async(e,t,i)=>{let a=await o();if(!a.enabled||!a.proxyUrl)throw Error(`AI 网关未启用或配置不完整`);let h=await S(a.clientId||`public`),_=await s(),{modelChoice:x,effectiveProvider:C,effectiveModel:D}=await N({provider:i?.provider,model:i?.model}),O=m({modelChoice:x,provider:C,model:D}),k=p({modelChoice:x,provider:C,model:D}),A=c({modelChoice:x,provider:C,model:D}),j=f({modelChoice:x,provider:C,model:D}),M=d({modelChoice:x,provider:C,model:D}),P=C===`glm`,F=n();if(!String(t||``).trim())throw Error(F.toLowerCase().startsWith(`zh`)?`请先粘贴简历内容`:`Please paste your resume first`);let I=(e||[]).slice(0,5);if(I.length<1)throw Error(F.toLowerCase().startsWith(`zh`)?`请先选择岗位`:`Select jobs first`);let L=await r(),R=(()=>{let e=String(D||x||``).toLowerCase();return C===`kimi`||e===`kimi`||e.startsWith(`kimi`)})(),z=(()=>{let e=String(D||x||``).toLowerCase();return C===`deepseek`||e.includes(`deepseek`)})(),B=(()=>{let e=String(D||x||``).toLowerCase();return C===`minimax`||e===`minimax_m27`||e.startsWith(`minimax`)})(),V=O?u.glm5x:A?u.gpt54:j?u.gpt54mini:k?u.gpt4o:M?u.gemini31lite:P?u.glm:R?u.kimi:z?u.deepseek:B?u.minimax:u.default,H=L?v(T(t,V),L):T(t,V),U=y.buildRoleContextFromText(`${t}\n${I.map(e=>`${e.title}\n${e.description||``}`).join(`

`)}`),W=await b.buildUniversityContextFromText(t).catch(()=>``),G=[H,U,W].filter(Boolean).join(`

`),te=await w(ee(I,P&&_.jdMode===`full`?`excerpt`:_.jdMode,{maxJobs:5,excerptLen:O?6e3:M?12e4:A?12e3:j?6e3:k?3200:P?520:1100})),K=await g({proxyUrl:a.proxyUrl,gatewayApiKey:a.gatewayApiKey,clientId:h,tier:a.tier,preset:`optimize_resume`,provider:C||void 0,model:D||void 0,data:{lang:F,resume:G,jobs:te,roleContext:U,universityContext:W},signal:i?.signal}),q=null;try{q=JSON.parse(l(K))}catch{let e=String(K||``).slice(0,220).replace(/\s+/g,` `).trim();throw Error(e?`代理未返回可解析的 JSON：${e}`:`代理未返回可解析的 JSON`)}let J=E(q,F),Y=J.caveats||[],X=F.toLowerCase().startsWith(`zh`)?`该优化由云端大模型生成，输出可能不准确；请勿将占位符内容当作事实。`:`Optimization generated by a cloud LLM; output may be inaccurate. Do not treat placeholders as facts.`;return Y.includes(X)||Y.unshift(X),J.caveats=Y.slice(0,10),J},F=async(e,t,i)=>{let a=await o();if(!a.enabled||!a.proxyUrl)throw Error(`AI 网关未启用或配置不完整`);let u=await S(a.clientId||`public`),x=await s(),{modelChoice:E,effectiveProvider:k,effectiveModel:A}=await N({provider:i?.provider,model:i?.model}),P=m({modelChoice:E,provider:k,model:A}),F=p({modelChoice:E,provider:k,model:A}),I=c({modelChoice:E,provider:k,model:A}),L=f({modelChoice:E,provider:k,model:A}),R=d({modelChoice:E,provider:k,model:A}),z=k===`glm`,B=n();if(!String(t||``).trim())throw Error(B.toLowerCase().startsWith(`zh`)?`请先粘贴简历内容`:`Please paste your resume first`);let V=(e||[]).slice(0,5);if(V.length<1)throw Error(B.toLowerCase().startsWith(`zh`)?`请先选择岗位`:`Select jobs first`);let H=(()=>{try{let e=String(globalThis?.location?.protocol||``);return!(!e||e===`chrome-extension:`||e===`moz-extension:`||e===`safari-extension:`)}catch{return!1}})(),U=await r(),W=(()=>{let e=String(A||E||``).toLowerCase();return k===`minimax`||e===`minimax_m27`||e.startsWith(`minimax`)})(),G=P?_.glm5x:I?_.gpt54:L?_.gpt54mini:F?_.gpt4o:R?_.gemini31lite:z?_.glm:W?_.minimax:_.default,te=U?v(T(t,G),U):T(t,G),K=y.buildRoleContextFromText(`${t}\n${V.map(e=>`${e.title}\n${e.description||``}`).join(`

`)}`),q=await b.buildUniversityContextFromText(t).catch(()=>``),J=[te,K,q].filter(Boolean).join(`

`),Y=z&&x.jdMode===`full`?`excerpt`:x.jdMode,X=e=>{try{i?.onProgress?.(Math.max(1,Math.min(100,Math.round(e))))}catch{}},Z=e=>{try{i?.onPartial?.(e)}catch{}},ne=(e,t)=>{let n={fromProvider:String(e?.fromProvider||e?.from_provider||``).trim(),fromModel:String(e?.fromModel||e?.from_model||``).trim(),provider:String(e?.provider||``).trim(),model:String(e?.model||``).trim(),reason:String(t?.reason||e?.reason||``).trim(),stage:String(t?.stage||e?.stage||``).trim()};return!n.fromProvider&&!n.fromModel&&!n.provider&&!n.model&&!n.reason&&!n.stage?null:n},Q=null,re=(e,t)=>{let n=ne(e,t);n&&(Q=Q?{...Q,...Object.fromEntries(Object.entries(n).filter(([,e])=>!!String(e||``).trim()))}:n)},$=V.map(e=>({jobId:String(e?.id||``).trim(),jobTitle:String(e?.title||``).trim(),company:String(e?.company||``).trim(),fitLevel:`partial`,fitScore:0,fitSummary:``,gaps:[],optimizedResume:``,atsKeywords:[],highlights:[],changes:[],caveats:[]}));Z({items:$.slice(0,5)}),X(8);for(let e=0;e<V.length;e++){if(i?.signal?.aborted)throw Error(`user_cancelled`);let t=V[e],n=await w(ee([t],Y,{maxJobs:1,excerptLen:P?6e3:R?12e4:I?12e3:L?6e3:F?3200:z?520:1100})),r=Array.isArray(n)?n[0]??{}:n,o={id:String(t?.id||``).trim(),title:String(t?.title||``).trim(),company:String(t?.company||``).trim()},s=async(t,n=1)=>{let s=t?.force_rewrite?`rewrite`:t?.force_json?`json`:`initial`,c=`optimize_${e+1}_of_${V.length}_${s}_a${n}`,d=C(i?.requestId,c),f=`优化 ${e+1}/${V.length}${s===`initial`?``:` · Retry`}`,p=10+Math.round(e/Math.max(1,V.length)*80),m=10+Math.round((e+1)/Math.max(1,V.length)*80)-2,_=!1,v=p,y=e=>{let t=Math.min(m,Math.max(p,v+e));if(t>v){v=t;try{X(t)}catch{}}},b=H?await h({proxyUrl:a.proxyUrl,gatewayApiKey:a.gatewayApiKey,clientId:u,tier:a.tier,preset:`optimize_resume_item`,provider:k||void 0,model:A||void 0,thinking:i?.thinking,data:{lang:B,resume:J,job:r,roleContext:K,universityContext:q,...t||{}},signal:i?.signal,requestId:d,suppressGlobalSync:i?.suppressGlobalSync,onMeta:e=>{if(e.type!==`start`)return;e?.fallback&&re(e.fallback,{stage:`optimize_resume_item`});let t=String(e.provider||``).trim(),r=String(e.model||``).trim();Z({_streamSegment:c,_streamStage:f,_streamActor:[t||r?`Model: ${[t,r].filter(Boolean).join(`/`)}`:``,`Skill: optimize_resume_item`].filter(Boolean).join(` 路 `),_attempt:n,_retryPhase:s})},onText:e=>{_=!0,y(1);let t=String(e||``).slice(-24e3);Z({_streamSegment:c,_streamStage:`${f} · 正文生成中`,_streamActor:`Skill: optimize_resume_item`,_streamText:t,_attempt:n,_retryPhase:s})},onThinking:e=>{y(1);let t=String(e||``).slice(-9e3);Z({_streamSegment:c,_streamStage:_?`${f} · 正文生成中`:`${f} · 深度思考中…`,_streamActor:`Skill: optimize_resume_item`,_streamThinking:t,_attempt:n,_retryPhase:s})}}):await g({proxyUrl:a.proxyUrl,gatewayApiKey:a.gatewayApiKey,clientId:u,tier:a.tier,preset:`optimize_resume_item`,provider:k||void 0,model:A||void 0,data:{lang:B,resume:J,job:r,roleContext:K,universityContext:q,...t||{}},signal:i?.signal,requestId:d,onResponseMeta:e=>{e?.fallback&&re(e.fallback,{stage:`optimize_resume_item`})}}),x=null;try{x=JSON.parse(l(b))}catch(e){console.warn(`[resumeOptimize] item JSON parse failed`,e),x=null}let S=O(x||{},o);return M(S)?S:j(b,o)},c=await s(void 0,1);M(c)||(c=await s({force_json:!0},2)),M(c)||(c=await s({force_json:!0,force_rewrite:!0},3));let d=D(c,B);(!Array.isArray(c.atsNotes)||!c.atsNotes.length)&&(c.atsNotes=d.atsNotes),(!Array.isArray(c.matchMatrix)||!c.matchMatrix.length)&&(c.matchMatrix=d.matchMatrix),(!Array.isArray(c.missingCriticalKeywords)||!c.missingCriticalKeywords.length)&&(c.missingCriticalKeywords=d.missingCriticalKeywords),$[e]=c,Z({items:$.slice(0,5)}),X(10+Math.round((e+1)/V.length*86))}return X(100),{items:$.slice(0,5),...Q?{_fallback:Q}:{}}};export{F as n,x as t};