@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 +1 -1
- package/dist/esm/plugins/index.js +25 -25
- package/dist/esm/repository/index.js +40 -40
- package/dist/index.js +1 -1
- package/dist/plugins/index.js +25 -25
- package/dist/repository/index.js +39 -39
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
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(as(e.content))??n(s.output_for_prompt);return c!==void 0?c:i(o)}if(e.content!==null&&e.content!==void 0)return as(e.content)??i(e.content);if(e.result!==null&&e.result!==void 0)return as(e.result)??i(e.result)}function LE(e){let t=Ra(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?ME(n):"Grok CLI reported an error."}function ME(e){return (e.replace(ZM,"").split(/\r?\n/).map(n=>n.trim()).filter(Boolean)[0]??e.trim()).slice(0,500)}function NE(e){return QM.test(e)}function nU(e){let t=Ra(e.modelUsage);return t?Object.keys(t)[0]??null:null}function rU(e){let t=Ra(e.usage);if(!t)return null;let n=ds(t.cache_read_input_tokens);return {inputTokens:ds(t.input_tokens)+n,cachedInputTokens:n,outputTokens:ds(t.output_tokens),costUsd:ds(e.total_cost_usd)}}function iU(e){let t=0,n=0,r=0,i=false,o=new Set;for(let s of e.split(`
|
|
20
20
|
`).flatMap(gc)){if(s.type!=="usage")continue;let a=Ra(s.usage);if(!a)continue;let d=hn(s.signature);if(d&&d.length>0){let l=`signature:${d}`;if(o.has(l))continue;o.add(l);}let c=ds(a.cache_read_input_tokens);t+=ds(a.input_tokens)+c,n+=c,r+=ds(a.output_tokens),i=true;}return i?{inputTokens:t,cachedInputTokens:n,outputTokens:r,costUsd:0}:null}function oU(e,t){if(!Array.isArray(t.entries)||t.entries.length===0)return [];let n=[];for(let o of t.entries.slice(0,PE)){if(!wa(o))continue;let s=hn(o.content)?.trim();if(!s)continue;let a=hn(o.status)?.trim(),d=hn(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>PE&&n.push(xE);let r=n.join(`
|
|
21
|
-
`),i=r.length>OE?`${r.slice(0,OE-1)}${xE}`:r;return [{timestamp:e,type:"info",content:i}]}function sU(e,t){let n=hn(t.type);if(n==="thought"){let r=hn(t.data);return r===void 0?[]:[{timestamp:e,type:"thinking",content:r}]}if(n==="text"){let r=hn(t.data);return r===void 0?[]:[{timestamp:e,type:"text",content:r}]}if(n==="plan")return oU(e,t);if(n==="tool_call"){let r=hn(t.toolCallId),i=hn(t.toolName)??hn(t.title),o=t.rawInput===void 0?void 0:DE(t.rawInput);return [{timestamp:e,type:"tool_use",toolUseId:r,toolName:i,toolInput:o}]}if(n==="tool_call_update"){let r=hn(t.status);if(r!=="completed"&&r!=="failed"&&r!=="error")return [];let i=tU(t),o=r!=="completed"||t.isError===true;return [{timestamp:e,type:"tool_result",toolUseId:hn(t.toolCallId),toolName:hn(t.toolName)??hn(t.title),...i!==void 0?Ln(i,o):{isError:o}}]}if(n==="error"){let r=LE(t);return [{timestamp:e,type:"error",content:r,errorMessage:r}]}return []}var dp,YM,QM,ZM,PE,OE,xE;exports.grokAdapter=void 0;var vh=U(()=>{h();Ti();Gu();xn();Yi();uc();Zi();dp="cli/grok",YM=new Set(["available_commands","usage","end"]),QM=/(?:rate[\s_-]*limit|quota|usage[\s_-]*limit|too many requests|limit(?:ed|ing)?\s+(?:exceeded|reached))/i,ZM=/\u001b\[[0-?]*[ -/]*[@-~]/g,PE=20,OE=4e3,xE="\u2026";exports.grokAdapter={command:"grok",createSessionId:()=>VI.randomUUID(),meta:{displayName:"Grok",capabilities:{resume:true}},buildArgs(e,t){let{model:n,effort:r}=Qi(t.model),i=t.effort??r,o=t.resumeSessionId?["--resume",t.resumeSessionId]:t.providerSessionId?["--session-id",t.providerSessionId]:[],s=n?["--model",n]:[],a=n?lr("grok").some(
|
|
21
|
+
`),i=r.length>OE?`${r.slice(0,OE-1)}${xE}`:r;return [{timestamp:e,type:"info",content:i}]}function sU(e,t){let n=hn(t.type);if(n==="thought"){let r=hn(t.data);return r===void 0?[]:[{timestamp:e,type:"thinking",content:r}]}if(n==="text"){let r=hn(t.data);return r===void 0?[]:[{timestamp:e,type:"text",content:r}]}if(n==="plan")return oU(e,t);if(n==="tool_call"){let r=hn(t.toolCallId),i=hn(t.toolName)??hn(t.title),o=t.rawInput===void 0?void 0:DE(t.rawInput);return [{timestamp:e,type:"tool_use",toolUseId:r,toolName:i,toolInput:o}]}if(n==="tool_call_update"){let r=hn(t.status);if(r!=="completed"&&r!=="failed"&&r!=="error")return [];let i=tU(t),o=r!=="completed"||t.isError===true;return [{timestamp:e,type:"tool_result",toolUseId:hn(t.toolCallId),toolName:hn(t.toolName)??hn(t.title),...i!==void 0?Ln(i,o):{isError:o}}]}if(n==="error"){let r=LE(t);return [{timestamp:e,type:"error",content:r,errorMessage:r}]}return []}var dp,YM,QM,ZM,PE,OE,xE;exports.grokAdapter=void 0;var vh=U(()=>{h();Ti();Gu();xn();Yi();uc();Zi();dp="cli/grok",YM=new Set(["available_commands","usage","end"]),QM=/(?:rate[\s_-]*limit|quota|usage[\s_-]*limit|too many requests|limit(?:ed|ing)?\s+(?:exceeded|reached))/i,ZM=/\u001b\[[0-?]*[ -/]*[@-~]/g,PE=20,OE=4e3,xE="\u2026";exports.grokAdapter={command:"grok",createSessionId:()=>VI.randomUUID(),meta:{displayName:"Grok",capabilities:{resume:true}},buildArgs(e,t){let{model:n,effort:r}=Qi(t.model),i=t.effort??r,o=t.resumeSessionId?["--resume",t.resumeSessionId]:t.providerSessionId?["--session-id",t.providerSessionId]:[],s=n?["--model",n]:[],a=n?lr("grok").some(k=>k.id===n):false,d=n&&a?pr("grok",n):[],c=!i||d.length===0||d.includes(i)?i:void 0,l=cE(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")?[]:sE(t.mode),A=p("--always-approve")?[]:aE(m),I=p("--sandbox")?[]:dE(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(gc))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 gc(e))if(t.type==="error"){let n=LE(t);return NE(DE(t))?new exports.RateLimitError(n,dp):new exports.ProviderError(n,dp)}return null},interpretExit(e,t){if(e===0)return null;let n=ME(t)||`Grok CLI exited with code ${e}.`;return NE(t)?new exports.RateLimitError(n,dp):new exports.ProviderError(n,dp)},parseResultMeta(e){let n=e.split(`
|
|
23
23
|
`).flatMap(gc).find(r=>r.type==="end");return n?{usage:rU(n),model:nU(n)}:{usage:iU(e),model:null}},parseEvent(e,t){let n=t??new Date().toISOString();return gc(e).flatMap(r=>sU(mn(r,n),r))},suppressOutputLine(e){let t=e.trim();if(!t.startsWith("{")||!t.endsWith("}"))return false;try{let n=JSON.parse(t);return wa(n)&&typeof n.type=="string"?YM.has(n.type):!1}catch{return false}}};});function Ch(e,t,n){return UE(e,t,n)}function Ph(e){let t=new Map;return {parse:(n,r,i)=>UE(n,r,e,{rowIndex:i,state:t})}}function UE(e,t,n,r){if(n){let i=exports.BUILTIN_ADAPTERS[n];if(i?.parseEvent)return i.parseEvent(t,e,r);let o=aU[n];if(o?.parseEvent)return o.parseEvent(t,e)}for(let i of Object.values(exports.BUILTIN_ADAPTERS)){let o=i.parseEvent?.(t,e,r)??[];if(o.length>0)return o}return []}exports.BUILTIN_ADAPTERS=void 0;var aU,to=U(()=>{h();Th();kh();Eh();wh();bh();CE();vh();Th();kh();Eh();wh();bh();vh();Ia();exports.BUILTIN_ADAPTERS={codex:exports.codexAdapter,claude:exports.claudeAdapter,opencode:exports.opencodeAdapter,antigravity:Sh,copilot:exports.copilotAdapter,grok:exports.grokAdapter},aU={gemini:vE};});var cs,Oh=U(()=>{h();cs=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 HE(e,t){if(e===void 0||e==="")return t;let n=parseInt(e,10);return Number.isNaN(n)?t:n}function xh(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 BE(e=process.env){return {queryMs:HE(e.CREWX_TIMEOUT_QUERY,288e5),executeMs:HE(e.CREWX_TIMEOUT_EXECUTE,288e5),idleMs:xh(e)??6e5}}var lp=U(()=>{h();});function Dh(e){return e instanceof Error?e:e===void 0?void 0:new Error(String(e))}function FE(e){return typeof e=="object"&&e!==null&&"code"in e?String(e.code):void 0}function Lh(e){return Number.isSafeInteger(e)&&e>0}function lU(e,t){try{let n=child_process.spawnSync(e,t,{encoding:"utf8",timeout:Nh,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:Dh(n)}}}function uU(e,t){return new Promise(n=>{let r;try{r=child_process.spawn(e,t,{windowsHide:!0});}catch(c){n({status:null,stdout:"",stderr:"",error:Dh(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 ${Nh}ms`)});},Nh);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 qE(e,t,n){return n.runCommandAsync?n.runCommandAsync(e,t):n.runCommand?n.runCommand(e,t):uU(e,t)}function pU(e){return new Promise(t=>{setTimeout(t,Math.max(0,e));})}function fU(){return new Promise(e=>{setImmediate(e);})}function no(e,t=process.kill){try{return t(e,0),"alive"}catch(n){return FE(n)==="ESRCH"?"not_found":FE(n)==="EPERM"?"alive":"unknown"}}function gU(e,t){if(!Lh(e))return {status:"unknown"};let n=t.platform??process.platform,r=t.runCommand??lU,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 mU(e,t){let n=no(-e,t),r=no(e,t);return n==="alive"||r==="alive"?"alive":n==="unknown"||r==="unknown"?"unknown":"not_found"}async function zE(e,t,n,r){let i=Math.max(0,n),o=Math.max(1,r.pollIntervalMs??exports.UNIX_PROCESS_POLL_INTERVAL_MS),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 fU();;){let l=mU(e,t);if(l==="not_found")return l;let u=s-Date.now();if(d||u<=0)return l;await Promise.race([c,pU(Math.min(o,u))]);}}finally{a!==void 0&&clearTimeout(a);}}async function jE(e,t,n,r,i){let o=await zE(e,t,i.hardConfirmMs??exports.UNIX_SIGKILL_CONFIRM_MS,{...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 hU(e,t,n={}){let r=gU(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 up(e,t,n={}){if(!Lh(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 qE(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 qr(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(!Lh(e))return i("Invalid process ID");let o=t.kill??process.kill,s=no(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 qE("taskkill",["/PID",String(e),"/T","/F"],t);}catch(m){p={status:null,stdout:"",stderr:"",error:Dh(m)};}let f=no(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 jE(e,o,a,r,t);if(await zE(e,o,t.graceMs??exports.UNIX_SIGTERM_GRACE_MS,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 jE(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 Nh,mc;exports.UNIX_SIGTERM_GRACE_MS=void 0;exports.UNIX_PROCESS_POLL_INTERVAL_MS=void 0;exports.UNIX_SIGKILL_CONFIRM_MS=void 0;var ls=U(()=>{h();Nh=3e3,mc="SIGINT",exports.UNIX_SIGTERM_GRACE_MS=2e3,exports.UNIX_PROCESS_POLL_INTERVAL_MS=25,exports.UNIX_SIGKILL_CONFIRM_MS=100;});function AU(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(`
|