rapidkit 0.21.2 → 0.22.0
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/README.md +75 -11
- package/dist/chunk-74G6C57B.js +24 -0
- package/dist/index.js +3435 -197
- package/dist/package.json +1 -1
- package/dist/pythonRapidkitExec-YIFUZLND.js +1 -0
- package/package.json +1 -1
- package/dist/chunk-D2ZRDZOE.js +0 -17
- package/dist/pythonRapidkitExec-GFCAVUOY.js +0 -1
package/dist/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{j as __test__,b as checkRapidkitCoreAvailable,h as getCachedCoreTopLevelCommands,g as getCoreTopLevelCommands,i as getModulesCatalog,c as resolveRapidkitPython,d as runCoreRapidkit,f as runCoreRapidkitCapture,e as runCoreRapidkitStreamed}from'./chunk-74G6C57B.js';
|
package/package.json
CHANGED
package/dist/chunk-D2ZRDZOE.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import z from'crypto';import T from'os';import c from'path';import*as d from'fs-extra';import {execa}from'execa';var W=["version","project","create","init","dev","start","build","test","lint","format","add","list","info","upgrade","diff","doctor","license","commands","reconcile","rollback","uninstall","checkpoint","optimize","snapshot","frameworks","modules","merge"],x=new Set(W);var y=class extends Error{code;constructor(n,t){super(t),this.code=n;}};function $(e){if(e instanceof y)switch(e.code){case "PYTHON_NOT_FOUND":return "RapidKit (npm) could not find Python (python3/python) on your PATH.\nInstall Python 3.10+ and ensure `python3` is available, then retry.\nTip: if you are inside a RapidKit project, use the local ./rapidkit launcher.";case "BRIDGE_VENV_CREATE_FAILED":return `RapidKit (npm) failed to create its bridge virtual environment.
|
|
2
|
-
Ensure Python venv support is installed (e.g., python3-venv).
|
|
3
|
-
Details: ${e.message}`;case "BRIDGE_PIP_BOOTSTRAP_FAILED":return `RapidKit (npm) could not bootstrap pip inside the bridge virtual environment.
|
|
4
|
-
Install python3-venv/python3-pip and retry.
|
|
5
|
-
Details: ${e.message}`;case "BRIDGE_PIP_UPGRADE_FAILED":return `RapidKit (npm) could not upgrade pip in the bridge virtual environment.
|
|
6
|
-
Check your network/proxy or disable RAPIDKIT_BRIDGE_UPGRADE_PIP.
|
|
7
|
-
Details: ${e.message}`;case "BRIDGE_PIP_INSTALL_FAILED":return `RapidKit (npm) could not install rapidkit-core in the bridge virtual environment.
|
|
8
|
-
Check your network/proxy, or install manually with: pipx install rapidkit-core.
|
|
9
|
-
Details: ${e.message}`;default:return `RapidKit (npm) bridge error: ${e.message}`}return `RapidKit (npm) failed to run the Python core engine: ${e instanceof Error?e.message:String(e)}`}function k(){let e=process.env.RAPIDKIT_CORE_PYTHON_PACKAGE;return e&&e.trim()?e.trim():"rapidkit-core"}function X(){let e=k(),n=process.env.RAPIDKIT_CORE_PYTHON_PACKAGE_ID,t=n&&n.trim()?`${e}|${n.trim()}`:e;return z.createHash("sha256").update(t).digest("hex").slice(0,12)}function E(){let e=process.env.XDG_CACHE_HOME;return e&&e.trim()?e:c.join(T.homedir(),".cache")}function q(){return c.join(E(),"rapidkit","npm-bridge","venv")}function M(){let e=X();return c.join(E(),"rapidkit","npm-bridge",`venv-${e}`)}function S(e){return process.platform==="win32"?c.join(e,"Scripts","python.exe"):c.join(e,"bin","python")}function D(e){return process.platform==="win32"?c.join(e,"Scripts","rapidkit.exe"):c.join(e,"bin","rapidkit")}function Q(e){return /[<>=!~]=|@|\.whl$|\.tar\.gz$|\.zip$|git\+|https?:\/\//.test(e)}function Z(e){return c.dirname(c.dirname(e))}function B(){return c.join(E(),"rapidkit","npm-bridge","core-commands.json")}async function F(e){let n=!!process.env.RAPIDKIT_DEBUG,t=r=>{n&&process.stderr.write(`[DEBUG] tryRapidkit(${e}): ${r}
|
|
10
|
-
`);};try{t("probing interpreter-specific rapidkit script");let o=((await execa(e,["-c","import sysconfig, os; print(os.path.join(sysconfig.get_path('scripts'), 'rapidkit'))"],{reject:false,stdio:"pipe",timeout:2e3})).stdout??"").toString().trim();if(t(`script path: ${o}`),o)try{if(await d.pathExists(o)){t(`found script at ${o}; invoking --version --json`);let i=await execa(o,["--version","--json"],{reject:false,stdio:"pipe",timeout:4e3});if(t(`script exitCode=${i.exitCode}`),i.exitCode===0){let a=(i.stdout??"").toString().trim();try{let s=JSON.parse(a),u=!!s&&typeof s=="object"&&s!==null&&"version"in s;if(t(`script JSON parse ok=${u}`),u)return true}catch{t("script output not valid JSON");}}}}catch(i){t(`interpreter-specific script probe failed: ${String(i)}`);}}catch(r){t(`interpreter-specific script probe error: ${String(r)}`);}try{t('probing importlib.find_spec("rapidkit")');let r=await execa(e,["-c","import importlib.util; print(1 if importlib.util.find_spec('rapidkit') else 0)"],{reject:false,stdio:"pipe",timeout:2e3});if(t(`import probe exitCode=${r.exitCode} stdout=${(r.stdout??"").toString().trim()}`),r.exitCode===0&&(r.stdout??"").toString().trim()==="1")return true}catch(r){t(`import probe error: ${String(r)}`);}try{t("probing python -m rapidkit");let r=await execa(e,["-m","rapidkit","--version","--json"],{reject:false,stdio:"pipe",timeout:8e3});if(t(`-m probe exitCode=${r.exitCode}`),r.exitCode===0)return true}catch(r){t(`-m probe error: ${String(r)}`);}try{t("probing PATH for rapidkit executables");let r=(process.env.PATH??"").split(c.delimiter).filter(Boolean);for(let o of r){let i=c.join(o,process.platform==="win32"?"rapidkit.exe":"rapidkit");try{if(await d.pathExists(i)){t(`found candidate on PATH: ${i}; invoking --version --json`);let a=await execa(i,["--version","--json"],{reject:false,stdio:"pipe",timeout:4e3});if(t(`candidate exitCode=${a.exitCode}`),a.exitCode===0){let s=(a.stdout??"").toString().trim();try{let u=JSON.parse(s);if(u&&typeof u=="object"&&u!==null&&"version"in u)return true}catch{t("candidate output not valid JSON, skipping");}}}}catch(a){t(`error probing candidate ${i}: ${String(a)}`);}}return t("no valid rapidkit found on PATH"),false}catch(r){return t(`PATH probe error: ${String(r)}`),false}}async function R(e){let n=(e??"").toString().trim();if(!n)return false;try{let t=JSON.parse(n);return !!t&&typeof t=="object"&&t!==null&&"version"in t}catch{return false}}async function tt(e){let n=process.platform==="win32",t=n?c.join(".venv","Scripts","rapidkit.exe"):c.join(".venv","bin","rapidkit"),r=n?c.join(".venv","Scripts","python.exe"):c.join(".venv","bin","python"),o=e;for(let i=0;i<25;i+=1){let a=c.join(o,t);if(await d.pathExists(a)){let f=await execa(a,["--version","--json"],{reject:false,stdio:"pipe",timeout:1500,cwd:o});if(f.exitCode===0&&await R(f.stdout))return {cmd:a,baseArgs:[]}}let s=c.join(o,r);if(await d.pathExists(s)){let f=await execa(s,["-m","rapidkit","--version","--json"],{reject:false,stdio:"pipe",timeout:1500,cwd:o});if(f.exitCode===0&&await R(f.stdout))return {cmd:s,baseArgs:["-m","rapidkit"]}}let u=c.dirname(o);if(u===o)break;o=u;}return null}async function et(e){try{let n=c.join(e,".python-version");if(await d.pathExists(n)){let r=(await d.readFile(n,"utf-8")).trim();if(r)return r}}catch{}try{let n=c.join(e,".rapidkit-workspace");if(await d.pathExists(n)){let t=await d.readFile(n,"utf-8"),r=JSON.parse(t);if(r.pythonVersion)return r.pythonVersion}}catch{}return null}async function G(e){if(e&&e.trim())try{let i=await tt(e);if(i){let a=c.dirname(i.cmd).includes(".venv")?c.dirname(c.dirname(c.dirname(i.cmd))):c.dirname(i.cmd),s=await et(a);return s&&(process.env.PYENV_VERSION=s),i}}catch{}let n=await rt();if(n.kind==="venv"){let i=Z(n.pythonPath),a=D(i);return await d.pathExists(a)?{cmd:a,baseArgs:[]}:{cmd:n.pythonPath,baseArgs:["-m","rapidkit"]}}try{if((await execa(n.cmd,["-m","rapidkit","--version","--json"],{reject:false,stdio:"pipe",timeout:4e3})).exitCode===0)return {cmd:n.cmd,baseArgs:["-m","rapidkit"]}}catch{}try{let a=((await execa(n.cmd,["-c","import sysconfig, os; print(os.path.join(sysconfig.get_path('scripts'), 'rapidkit'))"],{reject:false,stdio:"pipe",timeout:2e3})).stdout??"").toString().trim();if(a&&await d.pathExists(a))try{let s=await execa(a,["--version","--json"],{reject:false,stdio:"pipe",timeout:4e3});if(s.exitCode===0&&await R(s.stdout))return {cmd:a,baseArgs:[]}}catch{}}catch{}let t=M(),r=await _(n.cmd),o=D(t);return await d.pathExists(o)?{cmd:o,baseArgs:[]}:{cmd:r,baseArgs:["-m","rapidkit"]}}async function b(){for(let e of ["python3","python"])try{return await execa(e,["--version"],{reject:false,stdio:"pipe",timeout:2e3}),e}catch{}return null}async function nt(){let e=!!process.env.RAPIDKIT_DEBUG,n=t=>{e&&process.stderr.write(`[DEBUG] checkRapidkitCore: ${t}
|
|
11
|
-
`);};for(let t of ["python3","python","python3.10","python3.11","python3.12"])try{n(`Method 1: trying ${t} import`);let r=await execa(t,["-c","import rapidkit_core; print(1)"],{reject:false,stdio:"pipe",timeout:3e3});if(r.exitCode===0&&r.stdout?.trim()==="1")return n(`\u2713 Found via ${t} import`),true}catch{continue}for(let t of ["python3","python"])try{n(`Method 2: trying ${t} -m pip show`);let r=await execa(t,["-m","pip","show","rapidkit-core"],{reject:false,stdio:"pipe",timeout:3e3});if(r.exitCode===0&&r.stdout?.includes("Name: rapidkit-core"))return n(`\u2713 Found via ${t} -m pip show`),true}catch{continue}for(let t of ["pip","pip3"])try{n(`Method 3: trying ${t} show`);let r=await execa(t,["show","rapidkit-core"],{reject:false,stdio:"pipe",timeout:3e3});if(r.exitCode===0&&r.stdout?.includes("Name: rapidkit-core"))return n(`\u2713 Found via ${t} show`),true}catch{continue}try{n("Method 4: checking pyenv versions");let t=await execa("pyenv",["versions","--bare"],{reject:false,stdio:"pipe",timeout:3e3});if(t.exitCode===0&&t.stdout){let r=t.stdout.split(`
|
|
12
|
-
`).filter(o=>o.trim());n(`Found pyenv versions: ${r.join(", ")}`);for(let o of r){let i=process.env.PYENV_ROOT||c.join(T.homedir(),".pyenv"),a=c.join(i,"versions",o.trim(),"bin","pip");try{let s=await execa(a,["show","rapidkit-core"],{reject:false,stdio:"pipe",timeout:3e3});if(s.exitCode===0&&s.stdout?.includes("Name: rapidkit-core"))return n(`\u2713 Found in pyenv ${o}`),true}catch{try{let s=await execa("bash",["-c",`PYENV_VERSION=${o.trim()} pyenv exec pip show rapidkit-core`],{reject:false,stdio:"pipe",timeout:3e3});if(s.exitCode===0&&s.stdout?.includes("Name: rapidkit-core"))return n(`\u2713 Found in pyenv ${o} via PYENV_VERSION`),true}catch{continue}}}}}catch{n("pyenv not available");}for(let t of ["python3","python"])try{n(`Method 5: checking ${t} user site`);let r=await execa(t,["-m","site","--user-site"],{reject:false,stdio:"pipe",timeout:3e3});if(r.exitCode===0&&r.stdout){let o=r.stdout.trim(),i=c.join(o,"rapidkit_core");if(await d.pathExists(i))return n("\u2713 Found in user site-packages"),true}}catch{continue}try{n("Method 6: checking pipx");let t=await execa("pipx",["list"],{reject:false,stdio:"pipe",timeout:3e3});if(t.exitCode===0&&t.stdout?.includes("rapidkit-core"))return n("\u2713 Found via pipx"),true}catch{n("pipx not available");}try{if(n("Method 7: checking poetry"),(await execa("poetry",["show","rapidkit-core"],{reject:false,stdio:"pipe",timeout:3e3})).exitCode===0)return n("\u2713 Found via poetry"),true}catch{n("poetry check failed");}try{n("Method 8: checking conda");let t=await execa("conda",["list","rapidkit-core"],{reject:false,stdio:"pipe",timeout:3e3});if(t.exitCode===0&&t.stdout?.includes("rapidkit-core"))return n("\u2713 Found via conda"),true}catch{n("conda not available");}return n("\u2717 Not found in any environment"),false}async function _(e){let n=M(),t=q(),r=k(),o=[n];!Q(r)&&!await d.pathExists(n)&&await d.pathExists(t)&&o.push(t);for(let m of o){let h=S(m);if(await d.pathExists(h))try{let l=await execa(h,["-c","import importlib.util; print(1 if importlib.util.find_spec('rapidkit') else 0)"],{reject:false,stdio:"pipe",timeout:2e3});if(l.exitCode===0&&(l.stdout??"").toString().trim()==="1")return h;await d.remove(m);}catch{await d.remove(m);}}let i=n,a={...process.env,PIP_DISABLE_PIP_VERSION_CHECK:"1",PIP_NO_PYTHON_VERSION_WARNING:"1"},s=Math.max(0,Number(process.env.RAPIDKIT_BRIDGE_PIP_RETRY??"2")),u=Math.max(200,Number(process.env.RAPIDKIT_BRIDGE_PIP_RETRY_DELAY_MS??"800")),f=Math.max(1e4,Number(process.env.RAPIDKIT_BRIDGE_PIP_TIMEOUT_MS??"120000")),J=m=>new Promise(h=>setTimeout(h,m)),A=async(m,h,l)=>{let g=await execa(m,h,{reject:false,stdio:["ignore","pipe","inherit"],env:a,timeout:l});if(g.exitCode===0)return;let P=(g.stdout??"").toString(),C=(g.stderr??"").toString(),v=[P,C].filter(Boolean).join(`
|
|
13
|
-
`),H=v?`${m} ${h.join(" ")}
|
|
14
|
-
${v}`:`${m} ${h.join(" ")}`;throw new Error(H)},I=async(m,h,l)=>{let g=0;for(;;)try{await A(m,h,l);return}catch(P){if(g>=s)throw P;let C=Math.floor(Math.random()*200),v=u*Math.pow(2,g)+C;g+=1,await J(v);}};try{await d.ensureDir(c.dirname(i));try{await A(e,["-m","venv",i],6e4);}catch(l){let g=l instanceof Error?l.message:String(l);throw new y("BRIDGE_VENV_CREATE_FAILED",g)}let m=S(i);if((await execa(m,["-m","pip","--version"],{reject:false,stdio:"pipe",timeout:2e3})).exitCode!==0&&(await execa(m,["-m","ensurepip","--default-pip"],{reject:false,stdio:["ignore","pipe","inherit"],env:a,timeout:6e4})).exitCode!==0)throw new y("BRIDGE_PIP_BOOTSTRAP_FAILED","ensurepip failed; install python3-venv/python3-pip and retry.");if(process.env.RAPIDKIT_BRIDGE_UPGRADE_PIP==="1")try{await I(m,["-m","pip","install","-U","pip"],f);}catch(l){let g=l instanceof Error?l.message:String(l);throw new y("BRIDGE_PIP_UPGRADE_FAILED",g)}try{await I(m,["-m","pip","install","-U",k()],f);}catch(l){let g=l instanceof Error?l.message:String(l);throw new y("BRIDGE_PIP_INSTALL_FAILED",g)}return m}catch(m){if(m instanceof y)throw m;let h=m instanceof Error?m.message:String(m);throw new y("BRIDGE_VENV_BOOTSTRAP_FAILED",h)}}async function rt(){if(process.env.RAPIDKIT_BRIDGE_FORCE_VENV==="1"){let t=await b();if(!t)throw new y("PYTHON_NOT_FOUND","No Python interpreter found (python3/python).");return {kind:"venv",pythonPath:await _(t)}}for(let t of ["python3","python"])if(await F(t))return {kind:"system",cmd:t};let e=await b();if(!e)throw new y("PYTHON_NOT_FOUND","No Python interpreter found (python3/python).");return {kind:"venv",pythonPath:await _(e)}}async function ft(e,n){try{let t=await G(n?.cwd),r=t.cmd,o=[...t.baseArgs,...e],i=await execa(r,o,{cwd:n?.cwd,env:{...process.env,...n?.env},reject:false,stdio:"inherit"});return typeof i.exitCode=="number"?i.exitCode:1}catch(t){return process.stderr.write(`${$(t)}
|
|
15
|
-
`),1}}async function w(e,n){try{let t=await G(n?.cwd),r=t.cmd,o=[...t.baseArgs,...e],i=await execa(r,o,{cwd:n?.cwd,env:{...process.env,...n?.env},reject:false,stdio:"pipe"});return {exitCode:typeof i.exitCode=="number"?i.exitCode:1,stdout:(i.stdout??"").toString(),stderr:(i.stderr??"").toString()}}catch(t){return {exitCode:1,stdout:"",stderr:`${$(t)}
|
|
16
|
-
`}}}function V(e){let n=new Set,t=e.split(`
|
|
17
|
-
`),r=false;for(let o of t){let i=o.replace(/\r$/,"");if(!r){/^\s*Commands:\s*$/i.test(i)&&(r=true);let u=i.match(/^\s*rapidkit\s+([a-z0-9_-]+)\b/i);if(u){let f=u[1].trim();f&&!f.startsWith("-")&&n.add(f);}continue}if(!i.trim())break;if(/^\s*(Options|Arguments|Usage|Commands)\s*:/i.test(i))continue;let a=i.match(/^\s*([a-z0-9][a-z0-9_-]*)\b/i);if(!a)continue;let s=a[1].trim();s&&!s.startsWith("-")&&n.add(s);}return n}async function L(){let e=B();if(!await d.pathExists(e))return null;try{let n=await d.readJson(e);if(n&&n.schema_version===1&&Array.isArray(n.commands))return n}catch{}return null}async function j(e){let n=B();await d.ensureDir(c.dirname(n)),await d.writeJson(n,e,{spaces:2});}async function it(){let e=await w(["version","--json"],{cwd:process.cwd()});if(e.exitCode===0)try{let t=JSON.parse(e.stdout)?.version;return typeof t=="string"?t:void 0}catch{return}}async function ot(){let e=await w(["commands","--json"],{cwd:process.cwd()});if(e.exitCode!==0)return null;try{let n=JSON.parse(e.stdout);if(n?.schema_version!==1||!Array.isArray(n.commands))return null;let t=n.commands.filter(r=>typeof r=="string");return t.length?t:null}catch{return null}}async function ht(){let n=Date.now(),t=await L(),r=await it(),o=!!t?.commands?.length;if(o&&n-t.fetched_at<864e5&&(!r||!t.rapidkit_version||t.rapidkit_version===r))return new Set(t.commands);let i=await ot();if(i?.length){let f=Array.from(new Set(i)).sort();return await j({schema_version:1,fetched_at:n,rapidkit_version:r,commands:f}),new Set(f)}let a=await w(["--help"],{cwd:process.cwd()});if(a.exitCode!==0)return o&&t?.commands?new Set(t.commands):new Set(x);let s=V(a.stdout);if(s.size===0)return new Set(x);let u=Array.from(s).sort();return await j({schema_version:1,fetched_at:n,rapidkit_version:r,commands:u}),s}async function gt(){let n=Date.now(),t=await L();return !t||n-t.fetched_at>=864e5||!t.commands?.length?null:new Set(t.commands)}function K(){return c.join(E(),"rapidkit","npm-bridge","modules-catalog.json")}async function st(){let e=K();if(!await d.pathExists(e))return null;try{let n=await d.readJson(e);if(n&&n.schema_version===1&&Array.isArray(n.modules))return n}catch{}return null}async function O(e){let n=K();await d.ensureDir(c.dirname(n)),await d.writeJson(n,e,{spaces:2});}function N(e){try{return JSON.parse(e)}catch{return null}}async function yt(e={}){let n=typeof e.ttlMs=="number"?e.ttlMs:18e5,t=Date.now(),r=await st();if(r?.fetched_at&&t-r.fetched_at<n)return r;let o=["modules","list","--json-schema","1"];e.category&&o.push("--category",e.category),e.tag&&o.push("--tag",e.tag),e.detailed&&o.push("--detailed");let i=await w(o,{cwd:e.cwd,env:e.env});if(i.exitCode===0){let s=N(i.stdout);if(s&&s.schema_version===1&&Array.isArray(s.modules)){let u={...s,fetched_at:t};return await O(u),u}}let a=await w(["modules","list","--json"],{cwd:e.cwd,env:e.env});if(a.exitCode===0){let s=N(a.stdout);if(Array.isArray(s)){let u={schema_version:1,generated_at:new Date().toISOString(),filters:{category:e.category??null,tag:e.tag??null,detailed:!!e.detailed},stats:{total:s.length,returned:s.length,invalid:0},modules:s,source:"legacy-json",fetched_at:t};return await O(u),u}}return r||null}var wt={pickSystemPython:b,ensureBridgeVenv:_,parseCoreCommandsFromHelp:V,tryRapidkit:F,checkRapidkitCoreAvailable:nt};export{x as a,nt as b,rt as c,ft as d,w as e,ht as f,gt as g,yt as h,wt as i};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export{i as __test__,b as checkRapidkitCoreAvailable,g as getCachedCoreTopLevelCommands,f as getCoreTopLevelCommands,h as getModulesCatalog,c as resolveRapidkitPython,d as runCoreRapidkit,e as runCoreRapidkitCapture}from'./chunk-D2ZRDZOE.js';
|