@kizenapps/cli 1.6.0-7e7fe95 → 1.6.1-4ca2bd3
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/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -165,7 +165,7 @@ sys.stdout.write('\\n__KIZEN_RESULT_START__\\n')
|
|
|
165
165
|
sys.stdout.write(json.dumps(result, ensure_ascii=False))
|
|
166
166
|
sys.stdout.write('\\n__KIZEN_RESULT_END__\\n')
|
|
167
167
|
sys.stdout.flush()
|
|
168
|
-
`.trim(),Un=3e4,vt=De(process.cwd(),".kizenapp","venv"),Vn=["awslambdaric","bcrypt","fpdf2","lxml","msgpack","numpy","paramiko","pyjwt","pypdf","pytz","requests","tzdata"],Ke=null;function Jn(e){let t=/^python-(\d+\.\d+)$/.exec(e);return t?.[1]?`python${t[1]}`:"python3"}function er(e,t,o){return new Promise((n,r)=>{let s=tr(e,t,{stdio:["ignore","pipe","pipe"]}),g=(C,x)=>{let y=[],v="";return C.on("data",h=>{v+=h.toString("utf-8");let l=v.indexOf(`
|
|
168
|
+
`.trim(),Un=3e4,vt=De(process.cwd(),".kizenapp","venv"),Vn=["awslambdaric","bcrypt","fpdf2","lxml","msgpack","numpy","oracledb","paramiko","psycopg","pyjwt","pymysql","pypdf","pytz","requests","sqlalchemy","tzdata"],Ke=null;function Jn(e){let t=/^python-(\d+\.\d+)$/.exec(e);return t?.[1]?`python${t[1]}`:"python3"}function er(e,t,o){return new Promise((n,r)=>{let s=tr(e,t,{stdio:["ignore","pipe","pipe"]}),g=(C,x)=>{let y=[],v="";return C.on("data",h=>{v+=h.toString("utf-8");let l=v.indexOf(`
|
|
169
169
|
`);for(;l>=0;){let b=v.slice(0,l).replace(/\r$/,"");v=v.slice(l+1),y.push(b),o?.(b,x),l=v.indexOf(`
|
|
170
170
|
`)}}),C.on("end",()=>{if(v.length>0){let h=v.replace(/\r$/,"");y.push(h),o?.(h,x)}}),y},d=g(s.stderr,"stderr");g(s.stdout,"stdout"),s.on("error",r),s.on("close",C=>{if(C===0)n();else{let x=d.slice(-10).join(`
|
|
171
171
|
`).trim(),y=x.length>0?`: ${x}`:"";r(new Error(`${e} exited with code ${String(C)}${y}`))}})})}var wt=new Set;function Xe(e){for(let t of wt)t(e)}function Wn(e,t){return t&&wt.add(t),Ke||(Ke=(async()=>{let o=De(vt,"bin","python");try{await Mn(o)}catch{let n=Jn(e);await er(n,["-m","venv",vt])}Xe({kind:"start"});try{await er(o,["-m","pip","install","--disable-pip-version-check",...Vn],(n,r)=>{Xe({kind:"log",line:n,stream:r})}),Xe({kind:"complete"})}catch(n){let r=n instanceof Error?n.message:String(n);throw Xe({kind:"error",message:r}),Ke=null,await rr(vt,{recursive:!0,force:!0}).catch(()=>{}),n}finally{wt.clear()}return o})()),Ke}function Gn(e){let t="__KIZEN_RESULT_START__",o="__KIZEN_RESULT_END__",n=e.indexOf(t),r=e.indexOf(o);if(n===-1||r===-1)return{userStdout:e,result:null};let s=e.slice(0,n).trimEnd(),g=e.slice(n+t.length,r).trim();try{let d=JSON.parse(g);return{userStdout:s,result:d}}catch{return{userStdout:e,result:null}}}async function nr(e){let t=e.timeout??Un,o=await Wn(e.scriptRuntime,e.onInstallProgress),n=Date.now(),r;try{r=await zn(De(Hn(),"kizen-step-"));let s=De(r,"wrapper.py"),g=De(r,"script.py");await Promise.all([Qt(s,qn,"utf-8"),Qt(g,e.script,"utf-8")]);let d={...process.env,__KIZEN_INPUTS__:JSON.stringify(e.inputs),__KIZEN_SECRETS__:JSON.stringify(e.secrets),__KIZEN_SCRIPT_PATH__:g},{exitCode:C,stdout:x,stderr:y}=await new Promise(P=>{let D=[],S=[],m=!1,p=tr(o,[s],{env:d,cwd:r,stdio:["ignore","pipe","pipe"]}),_=setTimeout(()=>{p.kill("SIGKILL")},t);p.stdout.on("data",i=>{D.push(i)}),p.stderr.on("data",i=>{S.push(i)});let a=i=>{m||(m=!0,clearTimeout(_),P({exitCode:i??1,stdout:Buffer.concat(D).toString("utf-8"),stderr:Buffer.concat(S).toString("utf-8")}))};p.on("close",a),p.on("error",i=>{m||(m=!0,clearTimeout(_),P({exitCode:1,stdout:"",stderr:i.message}))})}),v=Date.now()-n,{userStdout:h,result:l}=Gn(x);if(l){let P={success:l.success,outputValues:l.outputValues,logs:l.logs,stdout:h,stderr:y,exitCode:C,durationMs:v};return l.error!==null&&(P.error=l.error),l.httpRequests&&(P.httpRequests=l.httpRequests),P}let b={success:!1,outputValues:{},logs:[],stdout:h,stderr:y,exitCode:C,durationMs:v};return C!==0&&(b.error=`Process exited with code ${String(C)}`),b}finally{r&&rr(r,{recursive:!0,force:!0})}}var or=new Set([".ts",".tsx",".js",".jsx",".mjs",".cjs",".json",".md",".mdx",".yml",".yaml",".toml",".css",".scss",".html",".htm",".xml",".svg",".txt",".sh",".py",".env",".gitignore",".prettierrc",".eslintrc"]);function Ct(e){if(e.kind==="info")return e.message;let t=e.fromCache?" [cache]":"",o=e.upstreamStatus!==void 0?` (upstream ${String(e.upstreamStatus)})`:"";return`${e.method} ${e.url} \u2192 ${String(e.status)}${o}${t}`}var no=2*1024*1024,oo=new Set([".DS_Store",".gitignore"]);function io(e){if(e===void 0||e==="")return!1;let t=e.startsWith("[")?e.slice(0,e.indexOf("]")+1):e.split(":")[0]??"";return t==="localhost"||t==="127.0.0.1"||t==="[::1]"}var so=["kizen.com","kizen.dev"];function ao(e){let t;try{t=new URL(e)}catch{return!1}if(t.protocol!=="https:")return!1;let o=t.hostname.toLowerCase();return so.some(n=>o===n||o.endsWith("."+n))}function lo(e){if(e===void 0||e==="")return!1;try{let{hostname:t}=new URL(e);return t==="localhost"||t==="127.0.0.1"||t==="::1"}catch{return!1}}async function lr(e,t){if(t.includes("\0"))return null;let o=t.replace(/^\/+/,""),n=to(e,o);if(n!==e&&!n.startsWith(e+St))return null;try{let r=await Qn(n);return r!==e&&!r.startsWith(e+St)?null:r}catch{return null}}function cr(e,t){let o=t===e?"":t.slice(e.length+1);return o===""?!1:o.split(St).some(r=>ze.has(r))}function ur(){let e=ro(import.meta.url);return Re(eo(e),"viewer")}function dr(e,t,o){if(e.includes("/external-integrations/proxy")&&t["content-type"]?.includes("application/json"))try{let n=JSON.parse(o.toString("utf8"));return typeof n.status_code=="number"?n.status_code:void 0}catch{return}}async function _t(e){try{return await Xn(e),!0}catch{return!1}}function pr(e,t,o,n,r,s,g,d,C,x){let y=Yt({onChange:d}),v=Kn(x);return(h,l)=>{(async()=>{let b=h.url??"/";try{if(!io(h.headers.host)){l.writeHead(403,{"Content-Type":"application/json; charset=utf-8"}),l.end(JSON.stringify({error:"Forbidden"}));return}if((h.method==="POST"||h.method==="PATCH"||h.method==="DELETE")&&!lo(h.headers.origin)){l.writeHead(403,{"Content-Type":"application/json; charset=utf-8"}),l.end(JSON.stringify({error:"Forbidden"}));return}if(t(`Received request: ${b}`),b==="/api/credentials"){l.writeHead(200,{"Content-Type":"application/json; charset=utf-8"}),l.end(JSON.stringify({credentials:n.current??null,activeProfile:r.current??null}));return}if(b==="/api/credential-profiles"&&h.method==="GET"){let a=await Ie();l.writeHead(200,{"Content-Type":"application/json; charset=utf-8"}),l.end(JSON.stringify({profiles:a,active:r.current}));return}if(b==="/api/credentials/switch"&&h.method==="POST"){let a=[];for await(let f of h)a.push(f);let c=JSON.parse(Buffer.concat(a).toString("utf-8")||"{}").profile,u=c===void 0||c===""?await Y():await Ce(c);if(u!==null){n.current=u,r.current=c??void 0;let f=r.current;await ge(s,{credentialMode:"global",...f!==void 0&&{activeCredentialProfile:f}}),g({type:"credentials-updated",credentials:u,activeProfile:r.current??null})}l.writeHead(200,{"Content-Type":"application/json; charset=utf-8"}),l.end(JSON.stringify({ok:u!==null}));return}if(b==="/api/bundle"){let a=Re(process.cwd(),".kizenapp","bundle.json");try{let i=await Zn(a,"utf-8");l.writeHead(200,{"Content-Type":"application/json; charset=utf-8"}),l.end(i)}catch{l.writeHead(200,{"Content-Type":"application/json; charset=utf-8"}),l.end("{}")}return}if(b==="/api/last-path"&&h.method==="POST"){let a=[];for await(let c of h)a.push(c);let i=JSON.parse(Buffer.concat(a).toString("utf-8")||"{}");if(typeof i.path=="string"){C.current=i.path;let c=await Ne(s);await ge(s,{...c,lastPath:i.path})}l.writeHead(200,{"Content-Type":"application/json; charset=utf-8"}),l.end('{"ok":true}');return}if(b==="/api/execute-step"&&h.method==="POST"){let a=[];for await(let f of h)a.push(f);let i=JSON.parse(Buffer.concat(a).toString("utf-8")||"{}");if(typeof i.script!="string"){l.writeHead(400,{"Content-Type":"application/json; charset=utf-8"}),l.end(JSON.stringify({error:"Missing required field: script"}));return}let c={script:i.script,scriptRuntime:i.scriptRuntime??"python-3.9",inputs:i.inputs??{},secrets:i.secrets??{},onInstallProgress:f=>{f.kind==="start"?g({type:"venv-install-start"}):f.kind==="log"?g({type:"venv-install-log",line:f.line,stream:f.stream}):f.kind==="complete"?g({type:"venv-install-complete"}):g({type:"venv-install-error",message:f.message})}};typeof i.timeout=="number"&&i.timeout>0&&(c.timeout=Math.min(i.timeout,300*1e3));let u=await nr(c);l.writeHead(200,{"Content-Type":"application/json; charset=utf-8"}),l.end(JSON.stringify(u));return}if(b==="/api/proxy-cache/clear"){y.clear(),o({kind:"info",message:"Proxy cache cleared"}),l.writeHead(200,{"Content-Type":"application/json; charset=utf-8"}),l.end('{"ok":true}');return}if(b.startsWith("/api/proxy")){let a=h.headers["x-proxy-target"];if(typeof a!="string"){l.writeHead(400),l.end("Missing x-proxy-target header");return}if(!ao(a)){l.writeHead(400),l.end("Invalid proxy target");return}let i=b.slice(10)||"/",c=`${a}${i}`,u=h.method??"GET",f=[];for await(let _e of h)f.push(_e);let{host:j,"x-proxy-target":E,...R}=h.headers;if(u==="GET"){let _e=`GET::${c}`,{response:ee,fromCache:nt}=await y.get(_e,()=>fetch(c,{method:"GET",headers:R}));o({kind:"request",method:"GET",status:ee.status,upstreamStatus:dr(i,ee.headers,ee.body),fromCache:nt,url:i}),l.writeHead(ee.status,ee.headers),l.end(ee.body);return}let A=f.length>0?Buffer.concat(f):void 0,H=A&&A.length>0?A:void 0,W=await fetch(c,{method:u,headers:R,...H!==void 0&&{body:H}}),Q=ht(Object.fromEntries(W.headers)),ae=await xt(W,yt);o({kind:"request",method:u,status:W.status,upstreamStatus:dr(i,Q,ae),fromCache:!1,url:i}),l.writeHead(W.status,Q),l.end(ae);return}if(b.startsWith("/api/source/tree")&&h.method==="GET"){let i=new URL(b,"http://localhost").searchParams.get("path")??"",c=await lr(v,i);if(c===null){l.writeHead(403,{"Content-Type":"application/json; charset=utf-8"}),l.end(JSON.stringify({error:"Invalid path"}));return}if(cr(v,c)){l.writeHead(403,{"Content-Type":"application/json; charset=utf-8"}),l.end(JSON.stringify({error:"Path is excluded"}));return}try{let u=await Yn(c,{withFileTypes:!0}),f=await Promise.all(u.filter(E=>E.isDirectory()?!ze.has(E.name):E.isFile()?!oo.has(E.name):!1).map(async E=>{let R=E.isDirectory()?"dir":"file",A={name:E.name,kind:R};if(R==="file")try{let H=await sr(Re(c,E.name));A.size=H.size}catch{}return A}));f.sort((E,R)=>E.kind!==R.kind?E.kind==="dir"?-1:1:E.name.localeCompare(R.name));let j=c===v?"":c.slice(v.length+1);l.writeHead(200,{"Content-Type":"application/json; charset=utf-8"}),l.end(JSON.stringify({path:j,entries:f}))}catch(u){let f=u instanceof Error?u.message:String(u);t(`source/tree failed (${i}): ${f}`),l.writeHead(404,{"Content-Type":"application/json; charset=utf-8"}),l.end(JSON.stringify({error:"Not found"}))}return}if(b.startsWith("/api/source/file")&&h.method==="GET"){let i=new URL(b,"http://localhost").searchParams.get("path")??"";if(i===""){l.writeHead(400,{"Content-Type":"application/json; charset=utf-8"}),l.end(JSON.stringify({error:"Missing path"}));return}let c=await lr(v,i);if(c===null){l.writeHead(403,{"Content-Type":"application/json; charset=utf-8"}),l.end(JSON.stringify({error:"Invalid path"}));return}if(cr(v,c)){l.writeHead(403,{"Content-Type":"application/json; charset=utf-8"}),l.end(JSON.stringify({error:"Path is excluded"}));return}try{let u=await sr(c);if(!u.isFile()){l.writeHead(400,{"Content-Type":"application/json; charset=utf-8"}),l.end(JSON.stringify({error:"Not a file"}));return}if(u.size>no){l.writeHead(413,{"Content-Type":"application/json; charset=utf-8"}),l.end(JSON.stringify({error:"File too large",size:u.size}));return}let f=ar(c).toLowerCase(),j=bt[f],E=or.has(f),R=j??(E?"text/plain; charset=utf-8":"application/octet-stream");l.writeHead(200,{"Content-Type":R,"Content-Length":String(u.size)}),ir(c).pipe(l)}catch(u){let f=u instanceof Error?u.message:String(u);t(`source/file failed (${i}): ${f}`),l.writeHead(404,{"Content-Type":"application/json; charset=utf-8"}),l.end(JSON.stringify({error:"Not found"}))}return}let S=Re(e,b==="/"?"/index.html":b),m=await _t(S)?S:Re(e,"index.html"),p=ar(m),_=bt[p]??"application/octet-stream";l.writeHead(200,{"Content-Type":_}),ir(m).pipe(l)}catch(P){if(b.startsWith("/api/proxy")){let D=b.slice(10)||"/",S=h.method??"GET";P instanceof Be?o({kind:"info",message:`${S} ${D} \u2192 502 (response exceeded ${String(P.limit)} bytes)`}):o({kind:"request",method:S,status:502,fromCache:!1,url:D})}else o({kind:"info",message:`Error handling ${b}: ${P instanceof Error?P.message:String(P)}`});l.headersSent||(l.writeHead(502),l.end("Bad Gateway"))}})()}}import{launch as co}from"chrome-launcher";import{createRequire as uo}from"module";import{mkdirSync as po}from"fs";import{readFile as fo}from"fs/promises";import{dirname as mo,join as go}from"path";import{fileURLToPath as ho}from"url";var fr=uo(import.meta.url)("chrome-remote-interface"),yo=new Set(["content-security-policy","content-security-policy-report-only","x-frame-options"]),gr=["kizen.dev","kizen.com"];function mr(e){try{let{hostname:t}=new URL(e);return gr.some(o=>t===o||t.endsWith("."+o))}catch{return!1}}async function xo(e){try{let t=go(mo(ho(import.meta.url)),"viewer","icon.png"),o=await fo(t);await e.Browser.setDockTile({image:o.toString("base64")})}catch{}}async function hr(e){po(e.userDataDir,{recursive:!0});let t=`http://localhost:${String(e.port)}`,o=await co({startingUrl:t,chromeFlags:[`--app=${t}`,"--no-first-run","--no-default-browser-check","--disable-extensions","--disable-features=DeviceBoundSessions"],userDataDir:e.userDataDir,handleSIGINT:!1,logLevel:"silent"}),n=o.port,r=null,s=null,g=null,d=null,C=0,x=!1,y=p=>{e.debugLog?.(p)},v=p=>{e.verbose&&e.debugLog?.(p)},h=()=>{s!==null&&(clearInterval(s),s=null)},l=p=>p==="chrome://new-tab-page/"||p==="chrome://newtab/",b=async p=>{h(),g=null,await xo(p),await p.Fetch.enable({patterns:gr.flatMap(a=>[{urlPattern:`*://${a}/*`,requestStage:"Response"},{urlPattern:`*://*.${a}/*`,requestStage:"Response"}])}),p.on("Fetch.requestPaused",a=>{(async()=>{let i=a,{requestId:c,request:u,responseHeaders:f,responseStatusCode:j}=i,E=u.url;v(`Fetch ${String(j??"?")} ${E}`);let R=[],A=!1;for(let H of f??[])if(!yo.has(H.name.toLowerCase()))if(H.name.toLowerCase()==="set-cookie"&&mr(E)){let W=H.value.split(`
|