@crewx/sdk 0.9.0-rc.141 → 0.9.0-rc.142

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/esm/index.js CHANGED
@@ -18,7 +18,7 @@ import*as We from'path';import We__default,{join,dirname,resolve,relative,sep,is
18
18
  `)||a.endsWith("\r")?"":`
19
19
  `;a=`${a}${l}${d}`;}else a=n(d);if(a)return a;let c=n(s.summary)??n(ds(e.content))??n(s.output_for_prompt);return c!==void 0?c:i(o)}if(e.content!==null&&e.content!==void 0)return ds(e.content)??i(e.content);if(e.result!==null&&e.result!==void 0)return ds(e.result)??i(e.result)}function UE(e){let t=Sa(e.error),n=[e.message,e.errorMessage,t?.message,t?.detail,typeof e.error=="string"?e.error:void 0].find(r=>typeof r=="string"&&r.trim().length>0);return n?HE(n):"Grok CLI reported an error."}function HE(e){return (e.replace(iU,"").split(/\r?\n/).map(n=>n.trim()).filter(Boolean)[0]??e.trim()).slice(0,500)}function LE(e){return rU.test(e)}function aU(e){let t=Sa(e.modelUsage);return t?Object.keys(t)[0]??null:null}function dU(e){let t=Sa(e.usage);if(!t)return null;let n=cs(t.cache_read_input_tokens);return {inputTokens:cs(t.input_tokens)+n,cachedInputTokens:n,outputTokens:cs(t.output_tokens),costUsd:cs(e.total_cost_usd)}}function cU(e){let t=0,n=0,r=0,i=false,o=new Set;for(let s of e.split(`
20
20
  `).flatMap(mc)){if(s.type!=="usage")continue;let a=Sa(s.usage);if(!a)continue;let d=yn(s.signature);if(d&&d.length>0){let l=`signature:${d}`;if(o.has(l))continue;o.add(l);}let c=cs(a.cache_read_input_tokens);t+=cs(a.input_tokens)+c,n+=c,r+=cs(a.output_tokens),i=true;}return i?{inputTokens:t,cachedInputTokens:n,outputTokens:r,costUsd:0}:null}function lU(e,t){if(!Array.isArray(t.entries)||t.entries.length===0)return [];let n=[];for(let o of t.entries.slice(0,xE)){if(!Ra(o))continue;let s=yn(o.content)?.trim();if(!s)continue;let a=yn(o.status)?.trim(),d=yn(o.priority)?.trim(),c=[a?`status=${a}`:void 0,d?`priority=${d}`:void 0].filter(u=>!!u),l=c.length>0?` (${c.join(", ")})`:"";n.push(`- ${s}${l}`);}if(n.length===0)return [];t.entries.length>xE&&n.push(DE);let r=n.join(`
21
- `),i=r.length>NE?`${r.slice(0,NE-1)}${DE}`:r;return [{timestamp:e,type:"info",content:i}]}function uU(e,t){let n=yn(t.type);if(n==="thought"){let r=yn(t.data);return r===void 0?[]:[{timestamp:e,type:"thinking",content:r}]}if(n==="text"){let r=yn(t.data);return r===void 0?[]:[{timestamp:e,type:"text",content:r}]}if(n==="plan")return lU(e,t);if(n==="tool_call"){let r=yn(t.toolCallId),i=yn(t.toolName)??yn(t.title),o=t.rawInput===void 0?void 0:ME(t.rawInput);return [{timestamp:e,type:"tool_use",toolUseId:r,toolName:i,toolInput:o}]}if(n==="tool_call_update"){let r=yn(t.status);if(r!=="completed"&&r!=="failed"&&r!=="error")return [];let i=sU(t),o=r!=="completed"||t.isError===true;return [{timestamp:e,type:"tool_result",toolUseId:yn(t.toolCallId),toolName:yn(t.toolName)??yn(t.title),...i!==void 0?Mn(i,o):{isError:o}}]}if(n==="error"){let r=UE(t);return [{timestamp:e,type:"error",content:r,errorMessage:r}]}return []}var cp,nU,rU,iU,xE,NE,DE,lp,Ch=H(()=>{h();ki();Ku();Nn();Qi();pc();eo();cp="cli/grok",nU=new Set(["available_commands","usage","end"]),rU=/(?:rate[\s_-]*limit|quota|usage[\s_-]*limit|too many requests|limit(?:ed|ing)?\s+(?:exceeded|reached))/i,iU=/\u001b\[[0-?]*[ -/]*[@-~]/g,xE=20,NE=4e3,DE="\u2026";lp={command:"grok",createSessionId:()=>randomUUID(),meta:{displayName:"Grok",capabilities:{resume:true}},buildArgs(e,t){let{model:n,effort:r}=Zi(t.model),i=t.effort??r,o=t.resumeSessionId?["--resume",t.resumeSessionId]:t.providerSessionId?["--session-id",t.providerSessionId]:[],s=n?["--model",n]:[],a=n?ur("grok").some(E=>E.id===n):false,d=n&&a?fr("grok",n):[],c=!i||d.length===0||d.includes(i)?i:void 0,l=uE(c),u=t.additionalArgs??[],p=E=>u.some(k=>k===E||k.startsWith(`${E}=`)),f=t.providerOptions,m=f?.alwaysApprove,y=f?.sandbox,_=p("--permission-mode")?[]:dE(t.mode),A=p("--always-approve")?[]:cE(m),I=p("--sandbox")?[]:lE(y);return {args:["--no-auto-update",...o,"--single",e,"--output-format","streaming-json","--no-alt-screen",...s,...l,..._,...A,...I,...u]}},extractText(e){let t=[],n=false;for(let r of e.split(`
21
+ `),i=r.length>NE?`${r.slice(0,NE-1)}${DE}`:r;return [{timestamp:e,type:"info",content:i}]}function uU(e,t){let n=yn(t.type);if(n==="thought"){let r=yn(t.data);return r===void 0?[]:[{timestamp:e,type:"thinking",content:r}]}if(n==="text"){let r=yn(t.data);return r===void 0?[]:[{timestamp:e,type:"text",content:r}]}if(n==="plan")return lU(e,t);if(n==="tool_call"){let r=yn(t.toolCallId),i=yn(t.toolName)??yn(t.title),o=t.rawInput===void 0?void 0:ME(t.rawInput);return [{timestamp:e,type:"tool_use",toolUseId:r,toolName:i,toolInput:o}]}if(n==="tool_call_update"){let r=yn(t.status);if(r!=="completed"&&r!=="failed"&&r!=="error")return [];let i=sU(t),o=r!=="completed"||t.isError===true;return [{timestamp:e,type:"tool_result",toolUseId:yn(t.toolCallId),toolName:yn(t.toolName)??yn(t.title),...i!==void 0?Mn(i,o):{isError:o}}]}if(n==="error"){let r=UE(t);return [{timestamp:e,type:"error",content:r,errorMessage:r}]}return []}var cp,nU,rU,iU,xE,NE,DE,lp,Ch=H(()=>{h();ki();Ku();Nn();Qi();pc();eo();cp="cli/grok",nU=new Set(["available_commands","usage","end"]),rU=/(?:rate[\s_-]*limit|quota|usage[\s_-]*limit|too many requests|limit(?:ed|ing)?\s+(?:exceeded|reached))/i,iU=/\u001b\[[0-?]*[ -/]*[@-~]/g,xE=20,NE=4e3,DE="\u2026";lp={command:"grok",createSessionId:()=>randomUUID(),meta:{displayName:"Grok",capabilities:{resume:true}},buildArgs(e,t){let{model:n,effort:r}=Zi(t.model),i=t.effort??r,o=t.resumeSessionId?["--resume",t.resumeSessionId]:t.providerSessionId?["--session-id",t.providerSessionId]:[],s=n?["--model",n]:[],a=n?ur("grok").some(k=>k.id===n):false,d=n&&a?fr("grok",n):[],c=!i||d.length===0||d.includes(i)?i:void 0,l=uE(c),u=t.additionalArgs??[],p=k=>u.some(T=>T===k||T.startsWith(`${k}=`)),f=t.providerOptions,m=f?.alwaysApprove,y=f?.sandbox,_=p("--permission-mode")?[]:dE(t.mode),A=p("--always-approve")?[]:cE(m),I=p("--sandbox")?[]:lE(y),E=p("--verbatim")?[]:["--verbatim"];return {args:["--no-auto-update",...o,"--single",e,...E,"--output-format","streaming-json","--no-alt-screen",...s,...l,..._,...A,...I,...u]}},extractText(e){let t=[],n=false;for(let r of e.split(`
22
22
  `).flatMap(mc))typeof r.type=="string"&&(n=true),r.type==="text"&&typeof r.data=="string"&&t.push(r.data);return t.length>0?t.join(""):n?"":e.trim()},extractFailure(e){for(let t of mc(e))if(t.type==="error"){let n=UE(t);return LE(ME(t))?new Xi(n,cp):new W(n,cp)}return null},interpretExit(e,t){if(e===0)return null;let n=HE(t)||`Grok CLI exited with code ${e}.`;return LE(t)?new Xi(n,cp):new W(n,cp)},parseResultMeta(e){let n=e.split(`
23
23
  `).flatMap(mc).find(r=>r.type==="end");return n?{usage:dU(n),model:aU(n)}:{usage:cU(e),model:null}},parseEvent(e,t){let n=t??new Date().toISOString();return mc(e).flatMap(r=>uU(hn(r,n),r))},suppressOutputLine(e){let t=e.trim();if(!t.startsWith("{")||!t.endsWith("}"))return false;try{let n=JSON.parse(t);return Ra(n)&&typeof n.type=="string"?nU.has(n.type):!1}catch{return false}}};});function Ph(e,t,n){return BE(e,t,n)}function Oh(e){let t=new Map;return {parse:(n,r,i)=>BE(n,r,e,{rowIndex:i,state:t})}}function BE(e,t,n,r){if(n){let i=Zn[n];if(i?.parseEvent)return i.parseEvent(t,e,r);let o=pU[n];if(o?.parseEvent)return o.parseEvent(t,e)}for(let i of Object.values(Zn)){let o=i.parseEvent?.(t,e,r)??[];if(o.length>0)return o}return []}var Zn,pU,no=H(()=>{h();kh();Eh();wh();Rh();vh();OE();Ch();kh();Eh();wh();Rh();vh();Ch();Ta();Zn={codex:op,claude:fc,opencode:dp,antigravity:bh,copilot:ip,grok:lp},pU={gemini:PE};});var ls,xh=H(()=>{h();ls=class{timeoutMs;onIdleCb;now;timer=null;lastActivity=0;settled=false;constructor(t){this.timeoutMs=t.timeoutMs,this.onIdleCb=t.onIdle,this.now=t.now??Date.now;}start(){this.settled||(this.lastActivity=this.now(),this.scheduleCheck());}refresh(){this.settled||(this.lastActivity=this.now());}stop(){this.settled||(this.settled=true,this.timer&&(clearTimeout(this.timer),this.timer=null));}scheduleCheck(){if(this.settled)return;let t=this.timeoutMs-(this.now()-this.lastActivity);if(t<=0){this.fireIdle();return}this.timer=setTimeout(()=>this.scheduleCheck(),t),this.timer.unref();}fireIdle(){this.settled||(this.settled=true,this.timer=null,this.onIdleCb());}};});function FE(e,t){if(e===void 0||e==="")return t;let n=parseInt(e,10);return Number.isNaN(n)?t:n}function Nh(e=process.env){let t=e.CREWX_TIMEOUT_IDLE;if(t===void 0||t==="")return;let n=parseInt(t,10);if(!(!Number.isFinite(n)||n<=0))return n}function jE(e=process.env){return {queryMs:FE(e.CREWX_TIMEOUT_QUERY,288e5),executeMs:FE(e.CREWX_TIMEOUT_EXECUTE,288e5),idleMs:Nh(e)??6e5}}var up=H(()=>{h();});function Lh(e){return e instanceof Error?e:e===void 0?void 0:new Error(String(e))}function $E(e){return typeof e=="object"&&e!==null&&"code"in e?String(e.code):void 0}function Mh(e){return Number.isSafeInteger(e)&&e>0}function mU(e,t){try{let n=spawnSync(e,t,{encoding:"utf8",timeout:Dh,windowsHide:!0});return {status:n.status,stdout:typeof n.stdout=="string"?n.stdout:"",stderr:typeof n.stderr=="string"?n.stderr:"",error:n.error}}catch(n){return {status:null,stdout:"",stderr:"",error:Lh(n)}}}function hU(e,t){return new Promise(n=>{let r;try{r=spawn(e,t,{windowsHide:!0});}catch(c){n({status:null,stdout:"",stderr:"",error:Lh(c)});return}let i="",o="",s=false,a,d=setTimeout(()=>{try{r.kill();}catch{}a({status:null,stdout:i,stderr:o,error:new Error(`Command timed out after ${Dh}ms`)});},Dh);a=c=>{s||(s=true,clearTimeout(d),n(c));},r.stdout?.setEncoding("utf8"),r.stderr?.setEncoding("utf8"),r.stdout?.on("data",c=>{i+=String(c);}),r.stderr?.on("data",c=>{o+=String(c);}),r.once("error",c=>{a({status:null,stdout:i,stderr:o,error:c});}),r.once("close",c=>{a({status:c,stdout:i,stderr:o});});})}async function GE(e,t,n){return n.runCommandAsync?n.runCommandAsync(e,t):n.runCommand?n.runCommand(e,t):hU(e,t)}function yU(e){return new Promise(t=>{setTimeout(t,Math.max(0,e));})}function _U(){return new Promise(e=>{setImmediate(e);})}function ro(e,t=process.kill){try{return t(e,0),"alive"}catch(n){return $E(n)==="ESRCH"?"not_found":$E(n)==="EPERM"?"alive":"unknown"}}function AU(e,t){if(!Mh(e))return {status:"unknown"};let n=t.platform??process.platform,r=t.runCommand??mU,i=n==="win32"?"powershell.exe":"ps",o=n==="win32"?["-NoLogo","-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-Command",`$p = Get-CimInstance -ClassName Win32_Process -Filter 'ProcessId = ${e}' -ErrorAction Stop; if ($null -ne $p) { [Console]::Write([string]$p.CommandLine) }`]:["-p",String(e),"-o","command="],s;try{s=r(i,o);}catch{return {status:"unknown"}}if(s.error||s.status!==0)return {status:"unknown"};let a=s.stdout.trim();return a?{status:"found",commandLine:a}:{status:"not_found"}}function IU(e,t){let n=ro(-e,t),r=ro(e,t);return n==="alive"||r==="alive"?"alive":n==="unknown"||r==="unknown"?"unknown":"not_found"}async function KE(e,t,n,r){let i=Math.max(0,n),o=Math.max(1,r.pollIntervalMs??qE),s=Date.now()+i,a,d=i===0,c=r.sleep?Promise.resolve().then(()=>r.sleep(i)).then(()=>{},()=>{}):new Promise(l=>{a=setTimeout(l,i);});c.then(()=>{d=true;});try{for(await _U();;){let l=IU(e,t);if(l==="not_found")return l;let u=s-Date.now();if(d||u<=0)return l;await Promise.race([c,yU(Math.min(o,u))]);}}finally{a!==void 0&&clearTimeout(a);}}async function VE(e,t,n,r,i){let o=await KE(e,t,i.hardConfirmMs??zE,{...i,sleep:void 0});return o==="not_found"?n?{status:"not_found",pid:e,method:r}:{status:"terminated",pid:e,method:r}:o==="alive"?{status:"failed",pid:e,method:r,error:"Process is still running after termination attempt"}:{status:"failed",pid:e,method:r,error:"Unable to verify process termination"}}function TU(e,t,n={}){let r=AU(e,n);if(r.status!=="found")return r.status;let i=n.platform??process.platform,o=i==="win32"?r.commandLine.toLowerCase():r.commandLine;return t.filter(a=>a.trim().length>0).some(a=>{let d=i==="win32"?a.toLowerCase():a;return o.includes(d)})?"owned":"not_owned"}async function pp(e,t,n={}){if(!Mh(e))return "unknown";let r=n.platform??process.platform,i=r==="win32"?"powershell.exe":"ps",o=r==="win32"?["-NoLogo","-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-Command",`$p = Get-CimInstance -ClassName Win32_Process -Filter 'ProcessId = ${e}' -ErrorAction Stop; if ($null -ne $p) { [Console]::Write([string]$p.CommandLine) }`]:["-p",String(e),"-o","command="],s;try{s=await GE(i,o,n);}catch{return "unknown"}if(s.error||s.status!==0)return "unknown";let a=s.stdout.trim();if(!a)return "not_found";let d=r==="win32"?a.toLowerCase():a;return t.filter(l=>l.trim().length>0).some(l=>{let u=r==="win32"?l.toLowerCase():l;return d.includes(u)})?"owned":"not_owned"}async function zr(e,t={}){let n=t.platform??process.platform,r=n==="win32"?"taskkill":"process-group",i=p=>({status:"failed",pid:e,method:r,error:p});if(!Mh(e))return i("Invalid process ID");let o=t.kill??process.kill,s=ro(e,o);if(s==="not_found")return {status:"not_found",pid:e,method:r};if(s!=="alive")return i("Unable to determine whether the process is alive");if(n==="win32"){let p;try{p=await GE("taskkill",["/PID",String(e),"/T","/F"],t);}catch(m){p={status:null,stdout:"",stderr:"",error:Lh(m)};}let f=ro(e,o);return f==="not_found"?p.status===0&&!p.error?{status:"terminated",pid:e,method:r}:{status:"not_found",pid:e,method:r}:i(f==="alive"?"Process is still running after termination attempt":"Unable to verify process termination")}let a,d=t.signal??"SIGKILL";try{o(-e,d);}catch(p){a=p;}if(d==="SIGKILL")return VE(e,o,a,r,t);if(await KE(e,o,t.graceMs??WE,t)==="not_found")return a?{status:"not_found",pid:e,method:r}:{status:"terminated",pid:e,method:r};let l;try{o(-e,"SIGKILL");}catch(p){l=p;}let u=await VE(e,o,l,r,t);return u.status==="terminated"?u:u.status==="not_found"?a?u:{status:"terminated",pid:e,method:r}:i(u.error??"Process termination failed")}var Dh,hc,WE,qE,zE,us=H(()=>{h();Dh=3e3,hc="SIGINT",WE=2e3,qE=25,zE=100;});function wU(e){let t=e.split(`
24
24
  `).filter(d=>d.trim()),n=[],r=[],i=[],o=[],s=[],a=null;for(let d of t)try{let c=JSON.parse(d);if(c.type==="assistant"&&Array.isArray(c.message?.content))for(let l of c.message.content)l.type==="text"&&typeof l.text=="string"&&l.text.trim()&&n.push(l.text.trim());if(c.type==="message"&&c.role==="assistant"&&c.delta===!0&&typeof c.content=="string"&&r.push(c.content),c.type==="assistant.message"&&typeof c.data?.content=="string"){let l=c.data.content;l.trim()&&i.push(l.trim());}if(c.type==="item.completed"&&(c.item?.type==="message"||c.item?.type==="agent_message")&&typeof c.item?.text=="string"){let l=c.item.text;l.trim()&&o.push(l.trim());}if(c.type==="text"&&typeof c.part?.text=="string"){let l=c.part.text;l.trim()&&s.push(l.trim());}c.type==="result"&&typeof c.result=="string"&&(a=c.result);}catch{}return n.length>0?n.join(`