@crewx/app 0.1.0-rc.130 → 0.1.0-rc.132

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,7 +1,7 @@
1
- import{existsSync as x,mkdirSync as z,mkdtempSync as Q,readFileSync as R,realpathSync as W,rmSync as C,watch as Z,writeFileSync as O}from"node:fs";import{createRequire as F}from"node:module";import{tmpdir as ee}from"node:os";import{basename as te,dirname as _,isAbsolute as re,join as c,relative as h,resolve as N,sep as U}from"node:path";import{fileURLToPath as ne,pathToFileURL as T}from"node:url";import{CREWX_META_NAMESPACE as S,convertV2ToManifest as J}from"./manifest.mjs";const D=_(ne(import.meta.url));const oe=F(import.meta.url);const se=c("packages","built-in","app","build-app");const L=N(D,"..","..","..","..");const $=c(L,"packages","sdk","src","app","index.ts");const V=_($);const E="server.ts";const k="dist/server.mjs";const q="dist/entry.mjs";const I="dist/main.mjs";const K="dist/tools.json";const ae=1;const y="manifest.json";const ie=100;const ce=[`import App from './${E}';`,`export * from './${E}';`,"export default App;","export { AppError, CrewXApp, Tool, executeAppRequest, generateManifest, getToolDeclarations, runSkillApp } from '@crewx/sdk/app';",""].join("\n");const le="export { runAppEntry } from '@crewx/sdk/app';\n";const fe=["import { runAppEntry } from '@crewx/sdk/app';","await runAppEntry(() => import('./server.mjs'));",""].join("\n");const ue=[`import App from './${E}';`,"export default App;","export { generateToolDeclarations } from '@crewx/sdk/app';",""].join("\n");const de="export { SKILL_BACKEND_ENV_NAMES, isSkillBackendEnv } from '@crewx/sdk/app';\n";const pe="dist/.env-rule.mjs";const me="import { createRequire as __crewxCreateRequire } from 'node:module'; const require = __crewxCreateRequire(import.meta.url);";const we={compilerOptions:{target:"ES2022",module:"ESNext",moduleResolution:"Bundler",experimentalDecorators:false,emitDecoratorMetadata:false,useDefineForClassFields:true,lib:["ES2022","esnext.decorators"],allowJs:true,checkJs:false}};function he(e,r,n,o){let s=e.generateManifest(e.default,r);if(o!==void 0&&Array.isArray(s.actions)){s={...s,actions:s.actions.map(a=>({...a,backend:{...a.backend,env:[...o]}}))}}let t;if(n===void 0){t=J(s)}else{try{t=JSON.parse(n)}catch(i){throw new Error(`${y} is not valid JSON: ${i instanceof Error?i.message:String(i)}`)}const a=t?._meta?.[S];if(a===null||typeof a!=="object"||Array.isArray(a)){throw new Error(`${y} must have an object at _meta["${S}"]`)}a.actions=s.actions}return{fileName:y,text:`${JSON.stringify(t,null,2)}
2
- `}}function xe(e,r){const n=e.generateToolDeclarations(e.default);let o;if(r===void 0){o=J({...e.default.definition})}else{try{o=JSON.parse(r)}catch(t){throw new Error(`${y} is not valid JSON: ${t instanceof Error?t.message:String(t)}`)}const s=o?._meta?.[S];if(s===null||typeof s!=="object"||Array.isArray(s)){throw new Error(`${y} must have an object at _meta["${S}"]`)}delete s.actions}return{fileName:y,text:`${JSON.stringify(o,null,2)}
3
- `,toolsFileName:K,toolsText:`${JSON.stringify({schemaVersion:ae,actions:n},null,2)}
4
- `}}function Ee(e,r=process.cwd()){let n;let o=false;let s=false;const t=a=>{if(n!==void 0)throw new Error("Give the app folder only once");n=N(r,a)};for(const a of e){if(a==="--check")o=true;else if(a==="--watch")s=true;else if(a.startsWith("--app-dir="))t(a.slice("--app-dir=".length));else if(a.startsWith("-"))throw new Error(`Unknown argument: ${a}`);else t(a)}if(o&&s)throw new Error("--check and --watch cannot be combined");return{appDirectory:n??r,check:o,watch:s}}function ye(e){const r=c(e,"package.json");if(!x(r))throw new Error(`${r} not found; run the build from an app folder or give the app folder`);const n=JSON.parse(R(r,"utf8"));const o=n.crewx?.app??{};if(Ae(n)){if(o.env!==void 0){throw new Error("crewx.app.env is only for an App with a bin or crewx.app.command; a server.ts-only App always gets its instance and thread as this.context")}const i=o.external??[];if(!Array.isArray(i)||!i.every(d=>typeof d==="string")){throw new Error("crewx.app.external must be an array of globs")}return{external:i}}const s=o.command??ve(n);if(!Array.isArray(s)||s.length===0||!s.every(i=>typeof i==="string"&&i!=="")){throw new Error("crewx.app.command must be a non-empty array of strings")}const t=o.external??[];if(!Array.isArray(t)||!t.every(i=>typeof i==="string")){throw new Error("crewx.app.external must be an array of globs")}const a=o.env;if(a!==void 0&&(!Array.isArray(a)||!a.every(i=>typeof i==="string"))){throw new Error("crewx.app.env must be an array of environment variable names")}return{command:s,external:t,...a===void 0?{}:{env:a}}}function Ae(e){return e.bin===void 0&&e.crewx?.app?.command===void 0}async function ge(e,r,n){let o;try{o=await b(e,r,n,{contents:de,sourcefile:"crewx-app-env-rule.ts",outfile:pe})}catch(t){if(t.errors?.some(({text:a})=>/No matching export/u.test(a))){throw new Error("crewx.app.env needs a newer @crewx/sdk: reinstall the CrewX CLI")}throw t}const s=Q(c(ee(),"crewx-app-env-"));try{const t=c(s,"rule.mjs");O(t,o.text,"utf8");const a=await import(T(t).href);if(!a.isSkillBackendEnv(n.env)){throw new Error(`crewx.app.env must be a non-empty list of distinct names from ${a.SKILL_BACKEND_ENV_NAMES.join(", ")}`)}}finally{C(s,{recursive:true,force:true})}}function ve(e){const r=e.bin;const n=typeof r==="string"?[String(e.name??"").replace(/^@[^/]+\//u,"")]:Object.keys(r??{});if(n.length!==1||n[0]===""){throw new Error('cannot derive the skill command: give package.json exactly one "bin" name, or set crewx.app.command')}return[n[0],"app"]}function Se(e){let r="^";for(let n=0;n<e.length;n+=1){const o=e[n];if(o==="*"&&e[n+1]==="*"){r+=".*";n+=1}else if(o==="*"){r+="[^/]*"}else if(o==="?"){r+="[^/]"}else{r+=o.replace(/[\\^$+{}()[\].|]/g,"\\$&")}}return new RegExp(`${r}$`)}function be(e,r){const n=h(e,r);return n!==""&&!n.startsWith("..")&&!re(n)}function P(e){if(D!==c(L,se))return false;if(!x($))return false;return be(W(L),W(e))}async function Re(e){try{const r=F(c(e,"package.json")).resolve("esbuild");return await import(T(r).href)}catch{}try{return await import("esbuild")}catch{throw new Error("cannot load esbuild: it comes with @crewx/app, so reinstall the CrewX CLI")}}const M="crewx-sdk";const _e="app/index.js";function X(){try{return oe.resolve("@crewx/sdk/app")}catch{return void 0}}function Ne(e,r){const n=r.external.map(Se);const o=P(e);return[{name:"crewx-sdk-app",setup(s){s.onResolve({filter:/^@crewx\/sdk\/app$/},()=>{if(o)return{path:$};const t=X();if(t===void 0){return{errors:[{text:"cannot resolve @crewx/sdk/app: it comes with the CrewX CLI, so reinstall the CLI"}]}}return{path:_e,namespace:M,pluginData:{file:t}}});s.onLoad({filter:/.*/,namespace:M},({pluginData:t})=>({contents:R(t.file,"utf8"),loader:"js",resolveDir:_(t.file)}))}},{name:"crewx-app-external-files",setup(s){if(n.length===0)return;s.onResolve({filter:/^\.\.?\//},({path:t,resolveDir:a})=>{const i=N(a,t);const d=h(e,i).split(U).join("/");if(d.startsWith("..")||!n.some(l=>l.test(d)))return void 0;const p=h(c(e,"dist"),i).split(U).join("/");return{path:p.startsWith(".")?p:`./${p}`,external:true}})}}]}const $e={name:"crewx-app-server-import",setup(e){e.onResolve({filter:/^\.\/server\.mjs$/},({path:r})=>({path:r,external:true}))}};async function b(e,r,n,{contents:o,sourcefile:s,outfile:t,metafile:a=false,plugins:i=[]}){const d=await e.build({...P(r)?{}:{banner:{js:me}},absWorkingDir:r,stdin:{contents:o,resolveDir:r,sourcefile:s,loader:"ts"},outfile:t,bundle:true,write:false,metafile:a,format:"esm",platform:"node",target:"node22",packages:"external",plugins:[...Ne(r,n),...i],tsconfigRaw:we,logLevel:"silent"}).catch(f=>{if(f.errors?.some(({text:w})=>/No matching export in ".*server\.ts" for import "default"/u.test(w))){throw new Error(`${E} must default-export a CrewXApp subclass with a static definition`)}throw f});const p=c(r,t);const l=d.outputFiles.find(f=>f.path===p)?.text;if(l===void 0)throw new Error(`esbuild did not produce ${t}`);if(/@crewx\/sdk(?:['"/])/u.test(l.replace(/^\s*\/\/.*$/gmu,""))){throw new Error(`${t} still imports @crewx/sdk; server.ts may import only @crewx/sdk/app`)}return{text:l,inputs:d.metafile?Object.keys(d.metafile.inputs):[]}}async function Y({appDirectory:e,check:r=false,log:n=()=>{}}){if(!x(c(e,E)))throw new Error(`${c(e,E)} not found`);const o=ye(e);const s=o.command===void 0;const t=await Re(e);if(o.env!==void 0)await ge(t,e,o);const a=c(e,"dist");const i=x(a);const d=c(a,`.server-build-${process.pid}.mjs`);try{const p=await b(t,e,o,{contents:ce,sourcefile:"crewx-app-server.ts",outfile:k,metafile:true});const l=s?await b(t,e,o,{contents:fe,sourcefile:"crewx-app-main.ts",outfile:I,plugins:[$e]}):await b(t,e,o,{contents:le,sourcefile:"crewx-app-entry.ts",outfile:q});const f=s?await ke(t,e,o):p;z(a,{recursive:true});O(d,f.text,"utf8");const w=await import(`${T(d).href}?build=${Date.now()}`);if(typeof w.default!=="function"||w.default.definition===void 0){throw new Error(`${E} must default-export a CrewXApp subclass with a static definition`)}const g=c(e,y);const A=x(g)?R(g,"utf8"):void 0;const m=s?xe(w,A):he(w,o.command,A,o.env);const j=[{path:c(e,k),text:p.text},{path:c(e,s?I:q),text:l.text},...s?[{path:c(e,m.toolsFileName),text:m.toolsText}]:[],{path:c(e,m.fileName),text:m.text}];const B=j.filter(({path:u,text:v})=>!x(u)||R(u,"utf8")!==v);const H=B.map(({path:u})=>h(process.cwd(),u));if(!r){for(const{path:v,text:G}of j)O(v,G,"utf8");const u=v=>h(process.cwd(),c(e,v));n(s?`Built ${u(k)} and ${u(I)}, wrote ${u(K)} and regenerated ${u(m.fileName)}.`:`Built ${h(process.cwd(),c(e,k))} and regenerated ${h(process.cwd(),c(e,m.fileName))}.`)}return{stale:r?H:[],staleFiles:r?B.map(({path:u})=>h(e,u)):[],files:j.map(({path:u})=>h(e,u)),actions:s?Pe(m.toolsText):je(m.text),mode:s?"tool":"bridge",sdkEntry:P(e)?$:X(),inputs:p.inputs.filter(u=>!u.startsWith(`${M}:`)).map(u=>N(e,u))}}finally{C(d,{force:true});if(!i&&r)C(a,{recursive:true,force:true})}}async function ke(e,r,n){try{return await b(e,r,n,{contents:ue,sourcefile:"crewx-app-declarations.ts",outfile:"dist/.declarations-build.mjs"})}catch(o){if(o.errors?.some(({text:s})=>/No matching export/u.test(s)&&/generateToolDeclarations/u.test(s))){throw new Error("a server.ts-only App (no bin, no crewx.app.command) needs a newer @crewx/sdk: reinstall the CrewX CLI")}throw o}}function Pe(e){const r=JSON.parse(e)?.actions;return Array.isArray(r)?r.map(n=>n?.actionId).filter(n=>typeof n==="string"):[]}function je(e){const r=JSON.parse(e)?._meta?.[S]?.actions;return Array.isArray(r)?r.map(n=>n?.actionId).filter(n=>typeof n==="string"):[]}async function Ce(e,r,{signal:n}={}){const o=new Map;let s=false;let t=false;let a;let i=new Set;const d=async()=>{if(s){t=true;return}s=true;try{const l=await Y({appDirectory:e,log:r});i=new Set(l.inputs)}catch(l){r(`Build failed: ${l instanceof Error?l.message:String(l)}`)}finally{s=false;if(!n?.aborted)p();if(t&&!n?.aborted){t=false;void d()}}};const p=()=>{const l=new Set([e,...[...i].map(f=>_(f))]);if(P(e))l.add(V);for(const[f,w]of o){if(!l.has(f)){w.close();o.delete(f)}}for(const f of l){if(o.has(f)||!x(f))continue;o.set(f,Z(f,(w,g)=>{if(g===null)return;const A=c(f,g.toString());const m=i.has(A)||A===c(e,"package.json")||f===V&&/\.tsx?$/u.test(A);if(!m)return;clearTimeout(a);a=setTimeout(()=>void d(),ie)}))}};await d();r("Watching for changes. Press Ctrl+C to stop.");await new Promise(l=>{if(n===void 0)return;if(n.aborted)l();else n.addEventListener("abort",l,{once:true})});clearTimeout(a);for(const l of o.values())l.close();o.clear()}async function We(e,{cwd:r=process.cwd(),stdout:n=process.stdout,stderr:o=process.stderr}={}){const s=t=>n.write(`${t}
5
- `);try{const t=Ee(e,r);if(t.watch){await Ce(t.appDirectory,s);return 0}const{stale:a}=await Y({appDirectory:t.appDirectory,check:t.check,log:s});if(!t.check)return 0;if(a.length>0){o.write(`Stale generated files: ${a.join(", ")}
6
- `);return 1}s(`${te(t.appDirectory)} App build artifacts are in sync.`);return 0}catch(t){o.write(`${t instanceof Error?t.message:String(t)}
7
- `);return 1}}export{$ as SDK_APP_SOURCE_ENTRY,Y as buildApp,Ee as parseArguments,ye as readAppConfig,he as renderActionDeclarations,xe as renderToolDeclarations,We as runScript,P as usesSdkSource,Ce as watchApp};
1
+ import{randomUUID as Z}from"node:crypto";import{existsSync as E,mkdirSync as ee,mkdtempSync as te,readFileSync as _,realpathSync as U,rmSync as O,watch as re,writeFileSync as j}from"node:fs";import{createRequire as B}from"node:module";import{tmpdir as ne}from"node:os";import{basename as oe,dirname as b,isAbsolute as se,join as c,relative as h,resolve as N,sep as W}from"node:path";import{fileURLToPath as ae,pathToFileURL as F}from"node:url";import{CREWX_META_NAMESPACE as S,convertV2ToManifest as D}from"./manifest.mjs";const J=b(ae(import.meta.url));const V=B(import.meta.url);const ie=c("packages","built-in","app","build-app");const T=N(J,"..","..","..","..");const k=c(T,"packages","sdk","src","app","index.ts");const q=b(k);const x="server.ts";const $="dist/server.mjs";const K="dist/entry.mjs";const I="dist/main.mjs";const X="dist/tools.json";const ce=1;const y="manifest.json";const le=100;async function Y(e){try{return V(e)}catch(t){if(t?.code!=="ERR_REQUIRE_ASYNC_MODULE")throw t;return import(F(e).href)}}const fe=[`import App from './${x}';`,`export * from './${x}';`,"export default App;","export { AppError, CrewXApp, Tool, executeAppRequest, generateManifest, getToolDeclarations, runSkillApp } from '@crewx/sdk/app';",""].join("\n");const ue="export { runAppEntry } from '@crewx/sdk/app';\n";const de=["import { runAppEntry } from '@crewx/sdk/app';","await runAppEntry(() => import('./server.mjs'));",""].join("\n");const pe=[`import App from './${x}';`,"export default App;","export { generateToolDeclarations } from '@crewx/sdk/app';",""].join("\n");const me="export { SKILL_BACKEND_ENV_NAMES, isSkillBackendEnv } from '@crewx/sdk/app';\n";const we="dist/.env-rule.mjs";const he="import { createRequire as __crewxCreateRequire } from 'node:module'; const require = __crewxCreateRequire(import.meta.url);";const Ee={compilerOptions:{target:"ES2022",module:"ESNext",moduleResolution:"Bundler",experimentalDecorators:false,emitDecoratorMetadata:false,useDefineForClassFields:true,lib:["ES2022","esnext.decorators"],allowJs:true,checkJs:false}};function xe(e,t,n,o){let s=e.generateManifest(e.default,t);if(o!==void 0&&Array.isArray(s.actions)){s={...s,actions:s.actions.map(a=>({...a,backend:{...a.backend,env:[...o]}}))}}let r;if(n===void 0){r=D(s)}else{try{r=JSON.parse(n)}catch(i){throw new Error(`${y} is not valid JSON: ${i instanceof Error?i.message:String(i)}`)}const a=r?._meta?.[S];if(a===null||typeof a!=="object"||Array.isArray(a)){throw new Error(`${y} must have an object at _meta["${S}"]`)}a.actions=s.actions}return{fileName:y,text:`${JSON.stringify(r,null,2)}
2
+ `}}function ye(e,t){const n=e.generateToolDeclarations(e.default);let o;if(t===void 0){o=D({...e.default.definition})}else{try{o=JSON.parse(t)}catch(r){throw new Error(`${y} is not valid JSON: ${r instanceof Error?r.message:String(r)}`)}const s=o?._meta?.[S];if(s===null||typeof s!=="object"||Array.isArray(s)){throw new Error(`${y} must have an object at _meta["${S}"]`)}delete s.actions}return{fileName:y,text:`${JSON.stringify(o,null,2)}
3
+ `,toolsFileName:X,toolsText:`${JSON.stringify({schemaVersion:ce,actions:n},null,2)}
4
+ `}}function Ae(e,t=process.cwd()){let n;let o=false;let s=false;const r=a=>{if(n!==void 0)throw new Error("Give the app folder only once");n=N(t,a)};for(const a of e){if(a==="--check")o=true;else if(a==="--watch")s=true;else if(a.startsWith("--app-dir="))r(a.slice("--app-dir=".length));else if(a.startsWith("-"))throw new Error(`Unknown argument: ${a}`);else r(a)}if(o&&s)throw new Error("--check and --watch cannot be combined");return{appDirectory:n??t,check:o,watch:s}}function ge(e){const t=c(e,"package.json");if(!E(t))throw new Error(`${t} not found; run the build from an app folder or give the app folder`);const n=JSON.parse(_(t,"utf8"));const o=n.crewx?.app??{};if(ve(n)){if(o.env!==void 0){throw new Error("crewx.app.env is only for an App with a bin or crewx.app.command; a server.ts-only App always gets its instance and thread as this.context")}const i=o.external??[];if(!Array.isArray(i)||!i.every(d=>typeof d==="string")){throw new Error("crewx.app.external must be an array of globs")}return{external:i}}const s=o.command??Re(n);if(!Array.isArray(s)||s.length===0||!s.every(i=>typeof i==="string"&&i!=="")){throw new Error("crewx.app.command must be a non-empty array of strings")}const r=o.external??[];if(!Array.isArray(r)||!r.every(i=>typeof i==="string")){throw new Error("crewx.app.external must be an array of globs")}const a=o.env;if(a!==void 0&&(!Array.isArray(a)||!a.every(i=>typeof i==="string"))){throw new Error("crewx.app.env must be an array of environment variable names")}return{command:s,external:r,...a===void 0?{}:{env:a}}}function ve(e){return e.bin===void 0&&e.crewx?.app?.command===void 0}async function Se(e,t,n){let o;try{o=await R(e,t,n,{contents:me,sourcefile:"crewx-app-env-rule.ts",outfile:we})}catch(r){if(r.errors?.some(({text:a})=>/No matching export/u.test(a))){throw new Error("crewx.app.env needs a newer @crewx/sdk: reinstall the CrewX CLI")}throw r}const s=te(c(ne(),"crewx-app-env-"));try{const r=c(s,"rule.mjs");j(r,o.text,"utf8");const a=await Y(r);if(!a.isSkillBackendEnv(n.env)){throw new Error(`crewx.app.env must be a non-empty list of distinct names from ${a.SKILL_BACKEND_ENV_NAMES.join(", ")}`)}}finally{O(s,{recursive:true,force:true})}}function Re(e){const t=e.bin;const n=typeof t==="string"?[String(e.name??"").replace(/^@[^/]+\//u,"")]:Object.keys(t??{});if(n.length!==1||n[0]===""){throw new Error('cannot derive the skill command: give package.json exactly one "bin" name, or set crewx.app.command')}return[n[0],"app"]}function _e(e){let t="^";for(let n=0;n<e.length;n+=1){const o=e[n];if(o==="*"&&e[n+1]==="*"){t+=".*";n+=1}else if(o==="*"){t+="[^/]*"}else if(o==="?"){t+="[^/]"}else{t+=o.replace(/[\\^$+{}()[\].|]/g,"\\$&")}}return new RegExp(`${t}$`)}function be(e,t){const n=h(e,t);return n!==""&&!n.startsWith("..")&&!se(n)}function P(e){if(J!==c(T,ie))return false;if(!E(k))return false;return be(U(T),U(e))}async function Ne(e){try{const t=B(c(e,"package.json")).resolve("esbuild");return await import(F(t).href)}catch{}try{return await import("esbuild")}catch{throw new Error("cannot load esbuild: it comes with @crewx/app, so reinstall the CrewX CLI")}}const L="crewx-sdk";const ke="app/index.js";function G(){try{return V.resolve("@crewx/sdk/app")}catch{return void 0}}function $e(e,t){const n=t.external.map(_e);const o=P(e);return[{name:"crewx-sdk-app",setup(s){s.onResolve({filter:/^@crewx\/sdk\/app$/},()=>{if(o)return{path:k};const r=G();if(r===void 0){return{errors:[{text:"cannot resolve @crewx/sdk/app: it comes with the CrewX CLI, so reinstall the CLI"}]}}return{path:ke,namespace:L,pluginData:{file:r}}});s.onLoad({filter:/.*/,namespace:L},({pluginData:r})=>({contents:_(r.file,"utf8"),loader:"js",resolveDir:b(r.file)}))}},{name:"crewx-app-external-files",setup(s){if(n.length===0)return;s.onResolve({filter:/^\.\.?\//},({path:r,resolveDir:a})=>{const i=N(a,r);const d=h(e,i).split(W).join("/");if(d.startsWith("..")||!n.some(l=>l.test(d)))return void 0;const p=h(c(e,"dist"),i).split(W).join("/");return{path:p.startsWith(".")?p:`./${p}`,external:true}})}}]}const Pe={name:"crewx-app-server-import",setup(e){e.onResolve({filter:/^\.\/server\.mjs$/},({path:t})=>({path:t,external:true}))}};async function R(e,t,n,{contents:o,sourcefile:s,outfile:r,metafile:a=false,plugins:i=[]}){const d=await e.build({...P(t)?{}:{banner:{js:he}},absWorkingDir:t,stdin:{contents:o,resolveDir:t,sourcefile:s,loader:"ts"},outfile:r,bundle:true,write:false,metafile:a,format:"esm",platform:"node",target:"node22",packages:"external",plugins:[...$e(t,n),...i],tsconfigRaw:Ee,logLevel:"silent"}).catch(f=>{if(f.errors?.some(({text:w})=>/No matching export in ".*server\.ts" for import "default"/u.test(w))){throw new Error(`${x} must default-export a CrewXApp subclass with a static definition`)}throw f});const p=c(t,r);const l=d.outputFiles.find(f=>f.path===p)?.text;if(l===void 0)throw new Error(`esbuild did not produce ${r}`);if(/@crewx\/sdk(?:['"/])/u.test(l.replace(/^\s*\/\/.*$/gmu,""))){throw new Error(`${r} still imports @crewx/sdk; server.ts may import only @crewx/sdk/app`)}return{text:l,inputs:d.metafile?Object.keys(d.metafile.inputs):[]}}async function H({appDirectory:e,check:t=false,log:n=()=>{}}){if(!E(c(e,x)))throw new Error(`${c(e,x)} not found`);const o=ge(e);const s=o.command===void 0;const r=await Ne(e);if(o.env!==void 0)await Se(r,e,o);const a=c(e,"dist");const i=E(a);const d=c(a,`.server-build-${process.pid}-${Z()}.mjs`);try{const p=await R(r,e,o,{contents:fe,sourcefile:"crewx-app-server.ts",outfile:$,metafile:true});const l=s?await R(r,e,o,{contents:de,sourcefile:"crewx-app-main.ts",outfile:I,plugins:[Pe]}):await R(r,e,o,{contents:ue,sourcefile:"crewx-app-entry.ts",outfile:K});const f=s?await Ce(r,e,o):p;ee(a,{recursive:true});j(d,f.text,"utf8");const w=await Y(d);if(typeof w.default!=="function"||w.default.definition===void 0){throw new Error(`${x} must default-export a CrewXApp subclass with a static definition`)}const g=c(e,y);const A=E(g)?_(g,"utf8"):void 0;const m=s?ye(w,A):xe(w,o.command,A,o.env);const C=[{path:c(e,$),text:p.text},{path:c(e,s?I:K),text:l.text},...s?[{path:c(e,m.toolsFileName),text:m.toolsText}]:[],{path:c(e,m.fileName),text:m.text}];const M=C.filter(({path:u,text:v})=>!E(u)||_(u,"utf8")!==v);const Q=M.map(({path:u})=>h(process.cwd(),u));if(!t){for(const{path:v,text:z}of C)j(v,z,"utf8");const u=v=>h(process.cwd(),c(e,v));n(s?`Built ${u($)} and ${u(I)}, wrote ${u(X)} and regenerated ${u(m.fileName)}.`:`Built ${h(process.cwd(),c(e,$))} and regenerated ${h(process.cwd(),c(e,m.fileName))}.`)}return{stale:t?Q:[],staleFiles:t?M.map(({path:u})=>h(e,u)):[],files:C.map(({path:u})=>h(e,u)),actions:s?Oe(m.toolsText):je(m.text),mode:s?"tool":"bridge",sdkEntry:P(e)?k:G(),inputs:p.inputs.filter(u=>!u.startsWith(`${L}:`)).map(u=>N(e,u))}}finally{O(d,{force:true});if(!i&&t)O(a,{recursive:true,force:true})}}async function Ce(e,t,n){try{return await R(e,t,n,{contents:pe,sourcefile:"crewx-app-declarations.ts",outfile:"dist/.declarations-build.mjs"})}catch(o){if(o.errors?.some(({text:s})=>/No matching export/u.test(s)&&/generateToolDeclarations/u.test(s))){throw new Error("a server.ts-only App (no bin, no crewx.app.command) needs a newer @crewx/sdk: reinstall the CrewX CLI")}throw o}}function Oe(e){const t=JSON.parse(e)?.actions;return Array.isArray(t)?t.map(n=>n?.actionId).filter(n=>typeof n==="string"):[]}function je(e){const t=JSON.parse(e)?._meta?.[S]?.actions;return Array.isArray(t)?t.map(n=>n?.actionId).filter(n=>typeof n==="string"):[]}async function Te(e,t,{signal:n}={}){const o=new Map;let s=false;let r=false;let a;let i=new Set;const d=async()=>{if(s){r=true;return}s=true;try{const l=await H({appDirectory:e,log:t});i=new Set(l.inputs)}catch(l){t(`Build failed: ${l instanceof Error?l.message:String(l)}`)}finally{s=false;if(!n?.aborted)p();if(r&&!n?.aborted){r=false;void d()}}};const p=()=>{const l=new Set([e,...[...i].map(f=>b(f))]);if(P(e))l.add(q);for(const[f,w]of o){if(!l.has(f)){w.close();o.delete(f)}}for(const f of l){if(o.has(f)||!E(f))continue;o.set(f,re(f,(w,g)=>{if(g===null)return;const A=c(f,g.toString());const m=i.has(A)||A===c(e,"package.json")||f===q&&/\.tsx?$/u.test(A);if(!m)return;clearTimeout(a);a=setTimeout(()=>void d(),le)}))}};await d();t("Watching for changes. Press Ctrl+C to stop.");await new Promise(l=>{if(n===void 0)return;if(n.aborted)l();else n.addEventListener("abort",l,{once:true})});clearTimeout(a);for(const l of o.values())l.close();o.clear()}async function De(e,{cwd:t=process.cwd(),stdout:n=process.stdout,stderr:o=process.stderr}={}){const s=r=>n.write(`${r}
5
+ `);try{const r=Ae(e,t);if(r.watch){await Te(r.appDirectory,s);return 0}const{stale:a}=await H({appDirectory:r.appDirectory,check:r.check,log:s});if(!r.check)return 0;if(a.length>0){o.write(`Stale generated files: ${a.join(", ")}
6
+ `);return 1}s(`${oe(r.appDirectory)} App build artifacts are in sync.`);return 0}catch(r){o.write(`${r instanceof Error?r.message:String(r)}
7
+ `);return 1}}export{k as SDK_APP_SOURCE_ENTRY,H as buildApp,Ae as parseArguments,ge as readAppConfig,xe as renderActionDeclarations,ye as renderToolDeclarations,De as runScript,P as usesSdkSource,Te as watchApp};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crewx/app",
3
- "version": "0.1.0-rc.130",
3
+ "version": "0.1.0-rc.132",
4
4
  "description": "Task-scoped CLI access to CrewX Apps",
5
5
  "type": "commonjs",
6
6
  "main": "dist/src/engine.js",
@@ -28,7 +28,7 @@
28
28
  ],
29
29
  "dependencies": {
30
30
  "esbuild": "0.27.7",
31
- "@crewx/sdk": "0.9.0-rc.247"
31
+ "@crewx/sdk": "0.9.0-rc.249"
32
32
  },
33
33
  "keywords": [
34
34
  "crewx",