import{r as e}from"./authSession-Dulxhbeq.js";import{n as t,r as n}from"./norm-f7iXVy-b.js";import{n as r}from"./llmSettings-8VBl-FQI.js";import{n as i,r as a}from"./piiScan-nPVX_DKq.js";import{n as o,t as s}from"./llm-DjSVhhgj.js";var c=e=>String(e||``).replace(/\r\n/g,`
`).replace(/\n{3,}/g,`

`).trim(),l=async t=>{try{let t=await e(),n=String(t?.user?.id||``).trim();if(n)return`u:${n}`.slice(0,120)}catch{}return String(t||`public`).slice(0,120)||`public`},u=e=>{let t=String(e||``);return t=t.replace(/\r\n/g,`
`),t=t.replace(/[，]/g,`, `),t=t.replace(/[。]/g,`. `),t=t.replace(/[；]/g,`; `),t=t.replace(/[：]/g,`: `),t=t.replace(/[（]/g,` (`),t=t.replace(/[）]/g,`) `),t=t.replace(/[【]/g,` [`),t=t.replace(/[】]/g,`] `),t=t.replace(/\s{2,}/g,` `),t=t.replace(/[ \t]+\n/g,`
`),t=t.replace(/\n{3,}/g,`

`),t=t.replace(/\b(19|20)\d{2}\.(0?[1-9]|1[0-2])\b/g,(e,t,n)=>`${t}-${String(n).padStart(2,`0`)}`),t=t.replace(/\b(19|20)\d{2}\/(0?[1-9]|1[0-2])\b/g,(e,t,n)=>`${t}-${String(n).padStart(2,`0`)}`),t=t.replace(/\b(19|20)\d{2}-(0?[1-9]|1[0-2])\s*-\s*(19|20)\d{2}-(0?[1-9]|1[0-2])\b/g,(e,t,n,r,i)=>`${t}-${String(n).padStart(2,`0`)} — ${r}-${String(i).padStart(2,`0`)}`),t=t.split(`
`).map(e=>e.replace(/^\s*[•·]\s+/,`- `)).join(`
`),t.trim()},d=e=>{let t=String(e||``).replace(/\r\n/g,`
`).trim();t=t.replace(/[ \t]+\n/g,`
`),t=t.replace(/\n{3,}/g,`

`),t=t.replace(/(?:^|\s)[•·]\s+/g,`
- `),t.split(`
`).map(e=>e.trim()).filter(Boolean).length<=4&&t.length>=600&&(t=t.replace(/\s+(?=[•·]\s+)/g,`
`),t=t.replace(/([.!?])\s+(?=[A-Z0-9])/g,`$1
`),t=t.replace(/([。？！])\s*/g,`$1
`),t=t.replace(/\s*(Experience|Work Experience|Professional Experience|Employment|Education|Projects|Project Experience|Skills|Technical Skills|Summary|Profile|Contact|Certifications|Awards|Publications|Languages)\s*[:：-]\s*/gi,`

$1
`)),t=t.replace(/^\s*[-–—•·]\s*/gm,`- `),t=t.replace(/\n{3,}/g,`

`).trim();let n=new Set([`SUMMARY`,`PROFILE`,`CONTACT`,`EXPERIENCE`,`WORK EXPERIENCE`,`PROFESSIONAL EXPERIENCE`,`PROJECTS`,`PROJECT EXPERIENCE`,`EDUCATION`,`SKILLS`,`TECHNICAL SKILLS`,`CERTIFICATIONS`,`AWARDS`,`PUBLICATIONS`,`LANGUAGES`]),r=t.split(`
`),i=[],a=e=>{let t=String(e||``).trim();if(!t||t.length>40||/[.]/.test(t))return!1;let r=t.toUpperCase();return!!(n.has(r)||n.has(r.replace(/\s+/g,` `)))};for(let e of r){let t=String(e||``).trimEnd();if(!t.trim()){i.length&&i[i.length-1]!==``&&i.push(``);continue}if(a(t)){i.length&&i[i.length-1]!==``&&i.push(``),i.push(t.trim());continue}i.push(t)}return i.join(`
`).replace(/\n{3,}/g,`

`).trim()},f=(e,t)=>{let n=String(t||``);return d(e===`en`||e===`fr`||e===`de`||e===`it`||e===`es`||e===`pt`||e===`nl`||e===`fi`||e===`sv`||e===`ru`?u(n):c(n))},p=e=>String(e||``).replace(/\r\n/g,`
`).replace(/[ \t]+\n/g,`
`).replace(/\n{4,}/g,`


`),m=e=>new Promise(t=>window.setTimeout(t,e)),h=async(e,t,n=12)=>{let r=e=>{try{t?.onProgress?.(Math.max(1,Math.min(100,Math.round(e))))}catch{}},i=e=>{try{t?.onPartial?.({en:e})}catch{}};r(n);let a=``;for(let o=0;o<e.length;){if(t?.signal?.aborted)throw Error(`已停止`);let s=e.length-o,c=Math.min(s,Math.max(18,Math.min(64,24+Math.floor(Math.random()*28))));a=e.slice(0,o+c),o+=c,i(a);let l=n+Math.floor(o/Math.max(1,e.length)*(100-n));r(Math.min(100,l)),await m(28+Math.floor(Math.random()*42))}i(e),r(100)},g=async(c,u)=>{let d=await r();if(!d.enabled||!d.proxyUrl)throw Error(`AI 服务未启用或配置不完整，请先在设置中开启/配置 AI 代理`);let m=t();if(!n((await e())?.user?.id))throw Error(m.toLowerCase().startsWith(`zh`)?`请先登录后使用简历翻译`:`Please sign in to use resume translation`);let g=await l(d.clientId||`public`),_=n(c);if(!_)throw Error(m.toLowerCase().startsWith(`zh`)?`请先粘贴中文简历`:`Please paste your Chinese resume first`);let v=a(_),y=v.length?i(_):_;try{u?.onProgress?.(6)}catch{}let b=u?.tone||`formal`,x=u?.to||`en`,S=Math.max(800,Math.floor(y.length*1.45)),C=``,w=``,T=!1,E=e=>{try{u?.onProgress?.(Math.max(1,Math.min(100,Math.round(e))))}catch{}},D=e=>{let t=p(e);try{u?.onPartial?.({en:t})}catch{}let n=Math.max(0,Math.min(.98,t.length/Math.max(1,S)));E(10+Math.floor(n*86))},O=e=>{try{u?.onThinking?.(String(e||``))}catch{}},k=()=>s({proxyUrl:d.proxyUrl,gatewayApiKey:d.gatewayApiKey,clientId:g,tier:d.tier,preset:`resume_translate`,data:{lang:m,to:x,tone:b,resume:y,pii:!!v.length},thinking:!0,onThinking:e=>{try{u?.onThinking?.(String(e||``))}catch{}},signal:u?.signal}),A=await(async()=>{try{return{ok:!0,content:await o({proxyUrl:d.proxyUrl,gatewayApiKey:d.gatewayApiKey,clientId:g,tier:d.tier,preset:`resume_translate`,data:{lang:m,to:x,tone:b,resume:y,pii:!!v.length},thinking:!0,signal:u?.signal,onThinkingDelta:e=>{w+=String(e||``),O(w)},onTextDelta:e=>{T=!0,C+=String(e||``),D(C)},onThinking:e=>{w=String(e||w||``),O(w)},onText:e=>{C=String(e||C||``),D(C)}})}}catch(e){return{ok:!1,err:e}}})(),j=A.ok?A.content:await k();if(A.ok&&!n(j)&&(j=await k()),!n(j))throw Error(m.toLowerCase().startsWith(`zh`)?`翻译结果为空，请重试或暂时切换模型。`:`The translation result is empty. Please retry or switch models temporarily.`);let M=f(x,j);if(A.ok)if(T){try{u?.onPartial?.({en:M})}catch{}try{u?.onProgress?.(100)}catch{}}else await h(M,u,12);else await h(M,u,12);return{zh:c,en:M,piiFound:v.length>0}};export{g as t};