@tencent-ai/codebuddy-code 0.0.1-beta.19 → 0.0.1-beta.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";exports.id=422,exports.ids=[422],exports.modules={7422:(e,t,n)=>{n.a(e,(async(e,r)=>{try{n.r(t),n.d(t,{LoginView:()=>LoginView});var l=n(80932),a=n(14083),o=n(96540),c=n(66814),i=n(9813),s=n(82101),u=n(34209),m=n(53829),E=n(49034),d=n(47693),g=n(83175),b=n(42790),y=e([a,s,m,E,b]);[a,s,m,E,b]=y.then?(await y)():y;const LoginView=()=>{const{staticKey:e}=(0,E._W)();return o.createElement(o.Fragment,null,o.createElement(a.jC,{key:`login-view-${e}`,items:[o.createElement(LogoBox,{key:"logo-box"}),o.createElement(NewVersionBox,{key:"new-version-box"})]},(e=>e)),o.createElement(LoginBox,null))},LogoBox=()=>{const e=`Welcome to ${u.KR}`,t=e.length+8;return o.createElement(o.Fragment,null,o.createElement(a.az,{marginBottom:1,paddingLeft:1,borderStyle:"round",borderColor:g.Q.brand,width:t},o.createElement(a.EY,{color:g.Q.brand},"✻ ",e)),o.createElement(b.H,null))},NewVersionBox=()=>{const e="cyan",t=i.CW.getCurrentPackageJson(),n=t.version.includes("beta"),r=t.version.includes("alpha"),l=n?"@beta":r?"@alpha":"";return o.createElement(a.az,{paddingX:1,flexDirection:"column",borderStyle:"round",borderColor:e},o.createElement(a.EY,{color:e},"New Version Updated v",t.version," Release! Please visit ",u.KR," website to read changelog."),o.createElement(a.EY,{color:e},"Run npm install -g ",u.JP,l))},LoginBox=()=>{const{authSession:e,navigate:t}=(0,c.i7)(m.aO,(e=>({authSession:e.authSession,navigate:e.navigate}))),[n,r]=(0,o.useState)("idle"),[i,u]=(0,o.useState)(""),[b,y]=(0,o.useState)(""),h=(0,o.useRef)(new AbortController);return(0,o.useEffect)((()=>{const e=(0,d.bi)().urlSubject.subscribe(u);return()=>e.unsubscribe()}),[]),(0,a.Ge)(((l,a)=>{if(E.Om.RETURN(a)&&"idle"===n)try{r("loading"),y(""),(0,d.Yf)().login(h.current)}catch(e){r("error"),y(e instanceof Error?e.message:"Unknown error occurred")}else E.Om.ESCAPE(a)&&("loading"===n?(h.current.abort(),r("idle")):e&&t("/chat"))})),o.createElement(a.az,{paddingX:1,flexDirection:"column",gap:1,borderStyle:"round",borderColor:"grey"},"idle"===n?o.createElement(o.Fragment,null,o.createElement(a.az,null,o.createElement(a.EY,null,"Select login method:")),o.createElement(a.az,null,o.createElement(a.EY,{color:"green"},l.Ay.bullet," Login with Tencent Cloud CodeBuddy")),o.createElement(a.az,{justifyContent:"space-between"},o.createElement(a.EY,{color:"grey"},"(Press Enter to login)"))):"loading"===n?o.createElement(a.az,{paddingY:1,gap:1,flexDirection:"column"},o.createElement(a.az,null,o.createElement(a.EY,{color:"grey"},"Browser didn't open? User the url below to sign in:")),i&&o.createElement(a.az,null,o.createElement(a.EY,{color:"grey"},i)),o.createElement(a.az,{marginTop:1,gap:1},o.createElement(a.EY,{color:g.Q.brand},o.createElement(s.y$,{type:"star"})),o.createElement(a.EY,null,"Waiting for auth... (Press ESC to cancel)"))):"error"===n?o.createElement(o.Fragment,null,o.createElement(a.EY,{color:"red"},"Failed to login."),b&&o.createElement(a.EY,{color:"red"},"Message: ",b)):void 0)};r()}catch(e){r(e)}}))},42790:(e,t,n)=>{n.a(e,(async(e,r)=>{try{n.d(t,{H:()=>LogoText});var l=n(1597),a=n(14083),o=n(96540),c=n(83175),i=e([a]);a=(i.then?(await i)():i)[0];const LogoText=()=>{const e=(0,o.useRef)((0,l.Ay)(c.Q.GradientColors)),t=(0,o.useCallback)((t=>e.current.multiline(t)),[e]);return o.createElement(a.dL,{transform:t},o.createElement(a.EY,null,"\n ██████╗ ██████╗ ██████╗ ███████╗██████╗ ██╗ ██╗██████╗ ██████╗ ██╗ ██╗ ██████╗ ██████╗ ██████╗ ███████╗\n██╔════╝██╔═══██╗██╔══██╗██╔════╝██╔══██╗██║ ██║██╔══██╗██╔══██╗╚██╗ ██╔╝ ██╔════╝██╔═══██╗██╔══██╗██╔════╝\n██║ ██║ ██║██║ ██║█████╗ ██████╔╝██║ ██║██║ ██║██║ ██║ ╚████╔╝ ██║ ██║ ██║██║ ██║█████╗ \n██║ ██║ ██║██║ ██║██╔══╝ ██╔══██╗██║ ██║██║ ██║██║ ██║ ╚██╔╝ ██║ ██║ ██║██║ ██║██╔══╝ \n╚██████╗╚██████╔╝██████╔╝███████╗██████╔╝╚██████╔╝██████╔╝██████╔╝ ██║ ╚██████╗╚██████╔╝██████╔╝███████╗\n ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝╚═════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝\n \n\n . * . * . *\n /\\_/\\ \n ( o.o ) * . * \n > ^ < . \n"))};r()}catch(e){r(e)}}))}};
1
+ "use strict";exports.id=422,exports.ids=[422],exports.modules={7422:(e,t,n)=>{n.a(e,(async(e,r)=>{try{n.r(t),n.d(t,{LoginView:()=>LoginView});var l=n(80932),a=n(14083),o=n(96540),c=n(66814),i=n(75101),s=n(82101),u=n(34209),m=n(53829),E=n(49034),d=n(47693),g=n(83175),b=n(42790),y=e([a,s,m,E,b]);[a,s,m,E,b]=y.then?(await y)():y;const LoginView=()=>{const{staticKey:e}=(0,E._W)();return o.createElement(o.Fragment,null,o.createElement(a.jC,{key:`login-view-${e}`,items:[o.createElement(LogoBox,{key:"logo-box"}),o.createElement(NewVersionBox,{key:"new-version-box"})]},(e=>e)),o.createElement(LoginBox,null))},LogoBox=()=>{const e=`Welcome to ${u.KR}`,t=e.length+8;return o.createElement(o.Fragment,null,o.createElement(a.az,{marginBottom:1,paddingLeft:1,borderStyle:"round",borderColor:g.Q.brand,width:t},o.createElement(a.EY,{color:g.Q.brand},"✻ ",e)),o.createElement(b.H,null))},NewVersionBox=()=>{const e="cyan",t=i.CW.getCurrentPackageJson(),n=t.version.includes("beta"),r=t.version.includes("alpha"),l=n?"@beta":r?"@alpha":"";return o.createElement(a.az,{paddingX:1,flexDirection:"column",borderStyle:"round",borderColor:e},o.createElement(a.EY,{color:e},"New Version Updated v",t.version," Release! Please visit ",u.KR," website to read changelog."),o.createElement(a.EY,{color:e},"Run npm install -g ",u.JP,l))},LoginBox=()=>{const{authSession:e,navigate:t}=(0,c.i7)(m.aO,(e=>({authSession:e.authSession,navigate:e.navigate}))),[n,r]=(0,o.useState)("idle"),[i,u]=(0,o.useState)(""),[b,y]=(0,o.useState)(""),h=(0,o.useRef)(new AbortController);return(0,o.useEffect)((()=>{const e=(0,d.bi)().urlSubject.subscribe(u);return()=>e.unsubscribe()}),[]),(0,a.Ge)(((l,a)=>{if(E.Om.RETURN(a)&&"idle"===n)try{r("loading"),y(""),(0,d.Yf)().login(h.current)}catch(e){r("error"),y(e instanceof Error?e.message:"Unknown error occurred")}else E.Om.ESCAPE(a)&&("loading"===n?(h.current.abort(),r("idle")):e&&t("/chat"))})),o.createElement(a.az,{paddingX:1,flexDirection:"column",gap:1,borderStyle:"round",borderColor:"grey"},"idle"===n?o.createElement(o.Fragment,null,o.createElement(a.az,null,o.createElement(a.EY,null,"Select login method:")),o.createElement(a.az,null,o.createElement(a.EY,{color:"green"},l.Ay.bullet," Login with Tencent Cloud CodeBuddy")),o.createElement(a.az,{justifyContent:"space-between"},o.createElement(a.EY,{color:"grey"},"(Press Enter to login)"))):"loading"===n?o.createElement(a.az,{paddingY:1,gap:1,flexDirection:"column"},o.createElement(a.az,null,o.createElement(a.EY,{color:"grey"},"Browser didn't open? User the url below to sign in:")),i&&o.createElement(a.az,null,o.createElement(a.EY,{color:"grey"},i)),o.createElement(a.az,{marginTop:1,gap:1},o.createElement(a.EY,{color:g.Q.brand},o.createElement(s.y$,{type:"star"})),o.createElement(a.EY,null,"Waiting for auth... (Press ESC to cancel)"))):"error"===n?o.createElement(o.Fragment,null,o.createElement(a.EY,{color:"red"},"Failed to login."),b&&o.createElement(a.EY,{color:"red"},"Message: ",b)):void 0)};r()}catch(e){r(e)}}))},42790:(e,t,n)=>{n.a(e,(async(e,r)=>{try{n.d(t,{H:()=>LogoText});var l=n(1597),a=n(14083),o=n(96540),c=n(83175),i=e([a]);a=(i.then?(await i)():i)[0];const LogoText=()=>{const e=(0,o.useRef)((0,l.Ay)(c.Q.GradientColors)),t=(0,o.useCallback)((t=>e.current.multiline(t)),[e]);return o.createElement(a.dL,{transform:t},o.createElement(a.EY,null,"\n ██████╗ ██████╗ ██████╗ ███████╗██████╗ ██╗ ██╗██████╗ ██████╗ ██╗ ██╗ ██████╗ ██████╗ ██████╗ ███████╗\n██╔════╝██╔═══██╗██╔══██╗██╔════╝██╔══██╗██║ ██║██╔══██╗██╔══██╗╚██╗ ██╔╝ ██╔════╝██╔═══██╗██╔══██╗██╔════╝\n██║ ██║ ██║██║ ██║█████╗ ██████╔╝██║ ██║██║ ██║██║ ██║ ╚████╔╝ ██║ ██║ ██║██║ ██║█████╗ \n██║ ██║ ██║██║ ██║██╔══╝ ██╔══██╗██║ ██║██║ ██║██║ ██║ ╚██╔╝ ██║ ██║ ██║██║ ██║██╔══╝ \n╚██████╗╚██████╔╝██████╔╝███████╗██████╔╝╚██████╔╝██████╔╝██████╔╝ ██║ ╚██████╗╚██████╔╝██████╔╝███████╗\n ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝╚═════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝\n \n\n . * . * . *\n /\\_/\\ \n ( o.o ) * . * \n > ^ < . \n"))};r()}catch(e){r(e)}}))}};
@@ -1 +1 @@
1
- "use strict";exports.id=566,exports.ids=[566],exports.modules={19250:(e,t,a)=>{a.a(e,(async(e,n)=>{try{a.d(t,{NH:()=>m.NH,pF:()=>o.pF});var r=a(77146),c=a(89536),l=a(70790),o=a(62875),m=a(82388),s=e([r,c,l,o,m]);[r,c,l,o,m]=s.then?(await s)():s,n()}catch(e){n(e)}}))},24960:(e,t,a)=>{a.a(e,(async(e,n)=>{try{a.d(t,{Er:()=>d,Tt:()=>u,hB:()=>i});var r=a(96540),c=a(36330),l=a(82101),o=a(49034),m=a(54156),s=e([c,l,o,m]);[c,l,o,m]=s.then?(await s)():s;const i=r.memo((({msg:e})=>e.content.map((t=>{const{columns:a}=(0,o.HP)(),n="output_text"===t.type?t.text:"";return e.providerData?.skipRun?r.createElement(c.HA,null,r.createElement(l.EY,{color:"incomplete"===e.status?"red":"white"},n)):r.createElement(l.az,{alignItems:"flex-start",marginTop:1,key:`${e.id}-${n}`},r.createElement(l.az,{flexShrink:0},r.createElement(l.EY,{color:"white"},"● ")),r.createElement(l.az,{width:a-2},r.createElement(l.oz,{content:n})))})))),u=r.memo((({msg:e,expanded:t})=>r.createElement(l.az,{key:`${e.id}-${e.callId}-call-${e.status}`,marginTop:1},r.createElement(m.Jv,{msg:e,expanded:t})))),d=r.memo((({msg:e,expanded:t})=>r.createElement(l.az,{key:`${e.id}-${e.callId}-result`},r.createElement(m.KR,{msg:e,expanded:t}))));n()}catch(e){n(e)}}))},28143:(e,t,a)=>{a.a(e,(async(e,n)=>{try{a.d(t,{a:()=>o});var r=a(96540),c=a(82101),l=e([c]);c=(l.then?(await l)():l)[0];const MessageBox=({text:e})=>r.createElement(c.az,{marginTop:1},r.createElement(c.az,{flexShrink:0},r.createElement(c.EY,{color:"grey"},"> ")),r.createElement(c.EY,{color:"grey"},e)),o=(0,r.memo)((({msg:e})=>{const t=(0,r.useCallback)(((e,t)=>t?.content??e),[e]);return"string"==typeof e.content?r.createElement(MessageBox,{key:`${e.id}-${e.content}`,text:t(e.content,e.providerData)}):e.content.map((a=>"input_text"===a.type?r.createElement(MessageBox,{text:t(a.text,a.providerData),key:`${e.id}-${a.text}`}):r.createElement(r.Fragment,null)))}));n()}catch(e){n(e)}}))},66530:(e,t,a)=>{a.a(e,(async(e,n)=>{try{a.d(t,{f:()=>ChatHeaderBox});var r=a(1708),c=a(96540),l=a(66814),o=a(3238),m=a(82101),s=a(34209),i=a(53829),u=a(83175),d=e([m,i]);[m,i]=d.then?(await d)():d;const ChatHeaderBox=()=>c.createElement(c.Fragment,null,c.createElement(WelcomeBox,null),c.createElement(TipsBox,null),c.createElement(HelloBox,null)),WelcomeBox=()=>{const e="Working in",t=(0,r.cwd)(),a=[`Welcome to ${s.KR}!`,"/help for help, /status for your current setup",`${e} ${t}`],n=Math.max(...a.map((e=>e.length)))+8,l=u.Q.brand,o="grey";return c.createElement(m.az,{marginBottom:1,paddingX:1,gap:1,borderStyle:"round",borderColor:l,width:n},c.createElement(m.az,{flexShrink:0},c.createElement(m.EY,{color:l},"✻")),c.createElement(m.az,{flexDirection:"column"},c.createElement(m.EY,null,a[0],"\n"),c.createElement(m.EY,{color:o},a[1],"\n"),c.createElement(m.az,{gap:1},c.createElement(m.EY,{color:o},e),c.createElement(m.EY,{color:u.Q.brand},t))))},TipsBox=()=>c.createElement(m.az,{marginBottom:1,paddingLeft:1,flexDirection:"column"},c.createElement(m.EY,{color:"grey"},"※ Tips for getting started:"),c.createElement(m.EY,{color:"grey"},"1. Ask questions, edit files, or run commands."),c.createElement(m.EY,{color:"grey"},"2. Be specific for the best results."),c.createElement(m.az,{gap:1},c.createElement(m.EY,{color:"grey"},"3. Run /init to create a"),c.createElement(m.EY,null,o._b),c.createElement(m.EY,{color:"grey"},"file with instructions for codebase."))),HelloBox=()=>{const e=(0,l.i7)(i.aO,(e=>e.authSession)),t=e?.account.nickname,a="grey",n=`What can I help you with today? You've got a well-structured project (${s.Dt}) with CLI and core packages, documentation, tests, and various configurations. Or just here to chat! Let me know. 🚀`;return c.createElement(m.az,{marginBottom:1,paddingLeft:1,flexDirection:"column",borderStyle:"round",borderColor:a},c.createElement(m.EY,{color:a},"Hi ",t,"! 👋","\n"),c.createElement(m.az,{paddingX:3},c.createElement(m.EY,{color:a},n)))};n()}catch(e){n(e)}}))},88851:(e,t,a)=>{a.a(e,(async(e,n)=>{try{a.d(t,{i:()=>m});var r=a(96540),c=a(36330),l=a(66438),o=e([c,l]);[c,l]=o.then?(await o)():o;const m=r.memo((({msg:e,expanded:t})=>e.content.map((a=>{const n="output_text"===a.type?a.text:"";return r.createElement(c.HA,{key:`${e.id}-compact-branch`},r.createElement(l._g,{result:n,expanded:t}))}))));n()}catch(e){n(e)}}))},90566:(e,t,a)=>{a.a(e,(async(e,n)=>{try{a.r(t),a.d(t,{ChatView:()=>ChatView});var r=a(14083),c=a(96540),l=a(66814),o=a(26730),m=a(53829),s=a(59505),i=a(19250),u=a(66530),d=a(92709),E=e([r,o,m,s,i,u,d]);[r,o,m,s,i,u,d]=E.then?(await E)():E;const g=c.memo((()=>{const e=(0,l.i7)(m.Gb,(e=>e.staticKey)),t=(0,l.i7)(m.rZ,(e=>e.messageGroups)),a=(0,d.A)(t),[n,o]=(0,c.useState)([]);(0,c.useEffect)((()=>{o((()=>t.reduce(((e,t)=>(e.push(...t.messages),e)),[])))}),[t]);const s=c.useMemo((()=>[c.createElement(u.f,{key:"chat-header-box"}),...n.map((e=>c.createElement(d.h,{key:`message-item-${e.id}`,msg:e,expanded:a(e.id)})))]),[n,a]);return c.createElement(r.jC,{key:e,items:s},(e=>e))})),ChatContainer=()=>((0,o.o)(),(0,s.f)(),c.createElement(c.Fragment,null,c.createElement(g,null),c.createElement(i.NH,null,c.createElement(i.pF,null)))),ChatView=()=>c.createElement(m.Fn,null,c.createElement(m.N7,null,c.createElement(m.Y5,null,c.createElement(ChatContainer,null))));n()}catch(e){n(e)}}))},92709:(e,t,a)=>{a.a(e,(async(e,n)=>{try{a.d(t,{A:()=>useExpandedResult,h:()=>g});var r=a(96540),c=a(66814),l=a(31943),o=a(82101),m=a(53829),s=a(49034),i=a(24960),u=a(88851),d=a(28143),E=e([o,m,s,i,u,d]);[o,m,s,i,u,d]=E.then?(await E)():E;const renderMessage=(e,t)=>{const a=`${e.type}-${e.id}`;if("message"===e.type){const{agent:n}=e.providerData||{};switch(e.role){case"user":return r.createElement(d.a,{key:a,msg:e});case"assistant":return n===l.QY.COMPACT?r.createElement(u.i,{key:a,msg:e,expanded:t}):r.createElement(i.hB,{key:a,msg:e});default:return}}switch(e.type){case"function_call":return r.createElement(i.Tt,{key:a,msg:e,expanded:t});case"function_call_result":return r.createElement(i.Er,{key:a,msg:e,expanded:t});default:return}},g=(0,r.memo)((({msg:e,expanded:t})=>renderMessage(e,t))),useExpandedResult=e=>{const t=(0,c.i7)(m.Gb,(e=>e.refreshStatic)),[a,n]=(0,r.useState)([]);(0,r.useEffect)((()=>{const t=e.flatMap((e=>e.messages));if(0===t.length)return void n((e=>0===e.length?e:[]));let a=-1;for(let e=t.length-1;e>=0;e--){const n=t[e];if("message"===n.type&&"user"===n.role){a=e;break}}if(-1===a)for(let e=t.length-1;e>=0;e--)if("function_call"===t[e].type){a=e;break}const r=-1!==a?t.slice(a):[];n((e=>e.length===r.length&&e.every(((e,t)=>e.id===r[t]?.id))?e:r))}),[e]);const[l,i]=(0,r.useState)(!1);return(0,o.Ge)(((e,a)=>{s.Om.CTRL_R(e,a)&&(i(!l),setTimeout((()=>{t()}),0))})),(0,r.useCallback)((e=>-1!==a.findIndex((t=>t.id===e))&&l),[l,a])};n()}catch(e){n(e)}}))}};
1
+ "use strict";exports.id=566,exports.ids=[566],exports.modules={19250:(e,t,a)=>{a.a(e,(async(e,n)=>{try{a.d(t,{NH:()=>r.NH,pF:()=>m.pF});var l=a(77146),s=a(89536),c=a(70790),m=a(62875),r=a(82388),i=e([l,s,c,m,r]);[l,s,c,m,r]=i.then?(await i)():i,n()}catch(e){n(e)}}))},90566:(e,t,a)=>{a.a(e,(async(e,n)=>{try{a.r(t),a.d(t,{ChatView:()=>ChatView});var l=a(14083),s=a(96540),c=a(66814),m=a(26730),r=a(53829),i=a(49034),u=a(59505),o=a(19250),g=a(66530),h=a(92709),p=e([l,m,r,i,u,o,g,h]);[l,m,r,i,u,o,g,h]=p.then?(await p)():p;const E=2,d=2,f=s.memo((({availableHeight:e})=>{const t=(0,c.i7)(r.Gb,(e=>e.staticKey)),a=(0,c.i7)(r.rZ,(e=>e.messageGroups)),n=(0,h.A)(a),[m,i]=(0,s.useState)([]),[u,o]=(0,s.useState)([]);(0,s.useEffect)((()=>{i([]),o([]);for(const e of a){if("function_call_group"===e.type){if(!e.messages.find((e=>"function_call"===e.type&&e.status&&["completed","incomplete"].includes(e.status)))){o((t=>(t.push(...e.messages),t)));continue}}i((t=>(t.push(...e.messages),t)))}}),[a]);const p=s.useMemo((()=>[s.createElement(g.f,{key:"chat-header-box"}),...m.map((e=>s.createElement(h.h,{key:`message-item-${e.id}`,msg:e,expanded:n(e.id)})))]),[m,n]);return s.createElement(s.Fragment,null,s.createElement(l.jC,{key:t,items:p},(e=>e)),u.length?s.createElement(l.az,{flexDirection:"column",height:E},...u.map((e=>s.createElement(h.h,{key:`message-item-${e.id}`,msg:e,expanded:n(e.id)})))):s.createElement(s.Fragment,null))})),ChatContainer=()=>{const{terminalHeight:e}=(0,i._W)(),[t,a]=(0,s.useState)(0);return(0,s.useEffect)((()=>{a(e-d)}),[e]),(0,m.o)(),(0,u.f)(),s.createElement(s.Fragment,null,s.createElement(f,{availableHeight:t}),s.createElement(l.az,{flexDirection:"column"},s.createElement(o.NH,null,s.createElement(o.pF,{availableHeight:t}))))},ChatView=()=>s.createElement(r.Fn,null,s.createElement(r.N7,null,s.createElement(r.Y5,null,s.createElement(ChatContainer,null))));n()}catch(e){n(e)}}))}};
@@ -0,0 +1 @@
1
+ "use strict";exports.id=952,exports.ids=[952],exports.modules={26952:(e,t,n)=>{n.d(t,{toFormData:()=>toFormData});var a=n(48695),r=n(79814);let i=0;const o={START_BOUNDARY:i++,HEADER_FIELD_START:i++,HEADER_FIELD:i++,HEADER_VALUE_START:i++,HEADER_VALUE:i++,HEADER_VALUE_ALMOST_DONE:i++,HEADERS_ALMOST_DONE:i++,PART_DATA_START:i++,PART_DATA:i++,END:i++};let s=1;const d=s,E=s*=2,lower=e=>32|e,noop=()=>{};class MultipartParser{constructor(e){this.index=0,this.flags=0,this.onHeaderEnd=noop,this.onHeaderField=noop,this.onHeadersEnd=noop,this.onHeaderValue=noop,this.onPartBegin=noop,this.onPartData=noop,this.onPartEnd=noop,this.boundaryChars={},e="\r\n--"+e;const t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n),this.boundaryChars[t[n]]=!0;this.boundary=t,this.lookbehind=new Uint8Array(this.boundary.length+8),this.state=o.START_BOUNDARY}write(e){let t=0;const n=e.length;let a=this.index,{lookbehind:r,boundary:i,boundaryChars:s,index:A,state:h,flags:l}=this;const D=this.boundary.length,c=D-1,f=e.length;let T,_;const mark=e=>{this[e+"Mark"]=t},clear=e=>{delete this[e+"Mark"]},callback=(e,t,n,a)=>{void 0!==t&&t===n||this[e](a&&a.subarray(t,n))},dataCallback=(n,a)=>{const r=n+"Mark";r in this&&(a?(callback(n,this[r],t,e),delete this[r]):(callback(n,this[r],e.length,e),this[r]=0))};for(t=0;t<n;t++)switch(T=e[t],h){case o.START_BOUNDARY:if(A===i.length-2){if(45===T)l|=E;else if(13!==T)return;A++;break}if(A-1==i.length-2){if(l&E&&45===T)h=o.END,l=0;else{if(l&E||10!==T)return;A=0,callback("onPartBegin"),h=o.HEADER_FIELD_START}break}T!==i[A+2]&&(A=-2),T===i[A+2]&&A++;break;case o.HEADER_FIELD_START:h=o.HEADER_FIELD,mark("onHeaderField"),A=0;case o.HEADER_FIELD:if(13===T){clear("onHeaderField"),h=o.HEADERS_ALMOST_DONE;break}if(A++,45===T)break;if(58===T){if(1===A)return;dataCallback("onHeaderField",!0),h=o.HEADER_VALUE_START;break}if(_=lower(T),_<97||_>122)return;break;case o.HEADER_VALUE_START:if(32===T)break;mark("onHeaderValue"),h=o.HEADER_VALUE;case o.HEADER_VALUE:13===T&&(dataCallback("onHeaderValue",!0),callback("onHeaderEnd"),h=o.HEADER_VALUE_ALMOST_DONE);break;case o.HEADER_VALUE_ALMOST_DONE:if(10!==T)return;h=o.HEADER_FIELD_START;break;case o.HEADERS_ALMOST_DONE:if(10!==T)return;callback("onHeadersEnd"),h=o.PART_DATA_START;break;case o.PART_DATA_START:h=o.PART_DATA,mark("onPartData");case o.PART_DATA:if(a=A,0===A){for(t+=c;t<f&&!(e[t]in s);)t+=D;t-=c,T=e[t]}if(A<i.length)i[A]===T?(0===A&&dataCallback("onPartData",!0),A++):A=0;else if(A===i.length)A++,13===T?l|=d:45===T?l|=E:A=0;else if(A-1===i.length)if(l&d){if(A=0,10===T){l&=~d,callback("onPartEnd"),callback("onPartBegin"),h=o.HEADER_FIELD_START;break}}else l&E&&45===T?(callback("onPartEnd"),h=o.END,l=0):A=0;if(A>0)r[A-1]=T;else if(a>0){const e=new Uint8Array(r.buffer,r.byteOffset,r.byteLength);callback("onPartData",0,a,e),a=0,mark("onPartData"),t--}break;case o.END:break;default:throw new Error(`Unexpected state entered: ${h}`)}dataCallback("onHeaderField"),dataCallback("onHeaderValue"),dataCallback("onPartData"),this.index=A,this.state=h,this.flags=l}end(){if(this.state===o.HEADER_FIELD_START&&0===this.index||this.state===o.PART_DATA&&this.index===this.boundary.length)this.onPartEnd();else if(this.state!==o.END)throw new Error("MultipartParser.end(): stream ended unexpectedly")}}async function toFormData(e,t){if(!/multipart/i.test(t))throw new TypeError("Failed to fetch");const n=t.match(/boundary=(?:"([^"]+)"|([^;]+))/i);if(!n)throw new TypeError("no or bad content-type header, no multipart boundary");const i=new MultipartParser(n[1]||n[2]);let o,s,d,E,A,h;const l=[],D=new r.fS,onPartData=e=>{d+=c.decode(e,{stream:!0})},appendToFile=e=>{l.push(e)},appendFileToFormData=()=>{const e=new a.ZH(l,h,{type:A});D.append(E,e)},appendEntryToFormData=()=>{D.append(E,d)},c=new TextDecoder("utf-8");c.decode(),i.onPartBegin=function(){i.onPartData=onPartData,i.onPartEnd=appendEntryToFormData,o="",s="",d="",E="",A="",h=null,l.length=0},i.onHeaderField=function(e){o+=c.decode(e,{stream:!0})},i.onHeaderValue=function(e){s+=c.decode(e,{stream:!0})},i.onHeaderEnd=function(){if(s+=c.decode(),o=o.toLowerCase(),"content-disposition"===o){const e=s.match(/\bname=("([^"]*)"|([^()<>@,;:\\"/[\]?={}\s\t]+))/i);e&&(E=e[2]||e[3]||""),h=function _fileName(e){const t=e.match(/\bfilename=("(.*?)"|([^()<>@,;:\\"/[\]?={}\s\t]+))($|;\s)/i);if(!t)return;const n=t[2]||t[3]||"";let a=n.slice(n.lastIndexOf("\\")+1);return a=a.replace(/%22/g,'"'),a=a.replace(/&#(\d{4});/g,((e,t)=>String.fromCharCode(t))),a}(s),h&&(i.onPartData=appendToFile,i.onPartEnd=appendFileToFormData)}else"content-type"===o&&(A=s);s="",o=""};for await(const t of e)i.write(t);return i.end(),D}}};