@entrydesk/cli 1.8.0 → 1.8.2
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 +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -195,7 +195,7 @@ ID: ${u.id}`)}}}else if(f==="connectors"){let l=Array.from(tt);v(l.length>0?l:vo
|
|
|
195
195
|
`)||st.length===0)return;if(We===null){mt(e);let u=st.length-1;Ve(u),t(st[u]);return}let l=Math.max(0,We-1);Ve(l),t(st[l]);return}if(m.downArrow){if(e.includes(`
|
|
196
196
|
`)||We===null)return;if(We>=st.length-1){Ve(null),t(zt);return}let l=We+1;Ve(l),t(st[l])}}),{suggestions:q,suggestionIndex:$e,showSuggestions:ne,argMode:f,argItems:S,argIndex:U,selectedConnectorIds:tt,selectedCapabilities:De,deleteConfirmMode:rt,handleInputChange:qt,handleSubmit:Yt}}import{useCallback as Ft,useRef as Lr,useState as Rr}from"react";function ts({credentials:e,currentModel:t,modelProviders:n,onUploadSuccess:s,onUploadError:o}){let[i,r]=Rr([]),a=Lr(0),c=Ft(y=>{if(!(!Array.isArray(n)||n.length===0)){for(let k of n)if(k.models.some(F=>F.id===y))return k.id;return n[0]?.id}},[n]),d=Ft(async y=>{if(!e){o?.(y.filename,"Not logged in");return}if(!Array.isArray(n)||n.length===0){o?.(y.filename,"Model providers not loaded yet. Please wait and try again.");return}let k=t?c(t):n[0]?.id;if(!k){o?.(y.filename,"No model provider available");return}let _=`file-${++a.current}`;r(F=>[...F,{id:_,filename:y.filename,mimeType:y.mimeType,status:"uploading"}]);try{let K=await new H().uploadFile(e.accessToken,e.workspaceId,y,k);r(ie=>ie.map(Y=>Y.id===_?{...Y,status:"uploaded",fileId:K.id}:Y)),s?.(y.filename)}catch(F){let K=F instanceof Error?F.message:"Upload failed";r(ie=>ie.map(Y=>Y.id===_?{...Y,status:"error",error:K}:Y)),o?.(y.filename,K)}},[e,t,c,n,s,o]),$=Ft(y=>{r(k=>k.filter(_=>_.id!==y))},[]),C=Ft(()=>{r([])},[]),x=Ft(()=>i.filter(y=>y.status==="uploaded"&&y.fileId).map(y=>y.fileId),[i]),v=i.some(y=>y.status==="uploading"),h=i.length>0;return{pendingFiles:i,addFile:d,removeFile:$,clearFiles:C,getUploadedFileIds:x,hasUploadingFiles:v,hasFiles:h}}import{jsx as X,jsxs as ue}from"react/jsx-runtime";var jr=[" ______ _ ____ _","| ____| | | | _ \\ | |","| |__ _ __ | |_ _ __ _ _ | | | | ___ ___| | __","| __| | '_ \\| __| '__| | | || | | |/ _ \\/ __| |/ /","| |____| | | | |_| | | |_| || |_| | __/\\__ \\ <","|______|_| |_|\\__|_| \\__, ||____/ \\___||___/_|\\_\\"," __/ |"," |___/"],Fr=[jo,jo,Uo,Uo,dt,dt,dt,dt],ns=jr.map((e,t)=>`${Fr[t]??dt}${e}${se}`).join(`
|
|
197
197
|
`),Br=`${dt}EntryDesk${se}`,Wr=500;function Mr(e){let t="",n=0;for(;n<e.length;){if(e.charCodeAt(n)===27&&e[n+1]==="["){for(n+=2;n<e.length;){let s=e.charCodeAt(n);if(s>=64&&s<=126){n+=1;break}n+=1}continue}t+=e[n],n+=1}return t}function Jr(e){let t=Mr(e);return Math.max(...t.split(`
|
|
198
|
-
`).map(n=>n.length))}function Gr(e){let t=Jr(ns);return e>=t?ns:Br}function ss({agentId:e,model:t,message:n,chatId:s,chatTitle:o,connectorIds:i,enableSandbox:r=!0,enableWebSearch:a=!1,enableImageGeneration:c=!1,enableChart:d=!1,enableFileSystem:$=!0}){let C=process.stdout.columns??80,x=Gr(C),v=os(null),h=Rn(s,o),{state:y,setState:k,messages:_,setMessages:F,input:K,setInput:ie,chatId:Y,setChatId:Ce,currentChatTitle:j,setCurrentChatTitle:A,hasPersistedChat:N,setHasPersistedChat:R,credentials:W,setCredentials:E,currentResponse:me,setCurrentResponse:D,fullOutput:p,setFullOutput:re,addSystemMessage:we,startNewChat:z}=h,{credentials:P}=jn(k);uo(()=>{P&&!W&&E(P)},[P,W,E]);let{availableConnectors:ee,availableModels:Q,availableAgents:pe,modelProviders:le,loading:M}=Fn(W),{currentModel:Z,setCurrentModel:q,currentAgentId:de,setCurrentAgentId:$e,activeConnectorIds:B,setActiveConnectorIds:ne}=zn(t,e,i),L=os(!1);uo(()=>{if(!L.current){if(L.current=!0,!t&&!e){let b=oe.getDefaultModel();b&&q(b)}if(!i&&!e){let b=oe.getDefaultConnectorIds();b&&ne(b.length>0?b:void 0)}}},[t,e,i,q,ne]);let{currentAgentDetails:f}=Kn(de,W),{sandbox:w,setSandbox:S,webSearch:te,setWebSearch:U,imageGeneration:xe,setImageGeneration:tt,chart:ot,setChart:De,fileSystem:nt,setFileSystem:bo,capabilityLabelMap:Vt}=Vn(r,a,c,d,$),{pendingFiles:je,addFile:gt,removeFile:He,clearFiles:Kt,getUploadedFileIds:st,hasUploadingFiles:xo,hasFiles:We}=ts({credentials:W,currentModel:Z,modelProviders:le,onUploadSuccess:b=>{we(`\u2713 Attached: ${b}`)},onUploadError:(b,O)=>{we(`\u2717 Failed to upload ${b}: ${O}`)}}),{sendMessage:Ve}=Mn({chatId:Y,credentials:W,currentAgentId:de,currentModel:Z,activeConnectorIds:B,sandbox:w,webSearch:te,imageGeneration:xe,chart:ot,localTools:nt,fullOutput:p,setMessages:F,setState:k,setCurrentResponse:D,setCredentials:E,setHasPersistedChat:R,getFileIds:st,clearFiles:Kt}),zt=Jo(b=>{z(b),D("")},[z]),[mt,ut]=Ur(!1),rt=Jo(async b=>{let O=b.text.trim(),ge=ao(O);if(/^https?:\/\//.test(ge))return;if(await _n(O)&&En(ge)){let ce=await Dn(O);ce&&(b.preventDefault(),await gt(ce))}},[gt]),ht=Jo(async()=>{if(!(mt||y.status!=="ready")){if(M||le.length===0){we("Please wait for resources to load before pasting images.");return}we("Reading clipboard..."),ut(!0);try{let b=await Nn();if(b){let O=`clipboard-${Date.now()}.png`;we(`Uploading: ${O} (${Math.round(b.buffer.length/1024)}KB)`),await gt({buffer:b.buffer,filename:O,mimeType:b.mime})}else we("No image found in clipboard. Copy an image first.")}catch(b){let O=b instanceof Error?b.message:"Failed to read clipboard";we(`Clipboard error: ${O}`)}finally{ut(!1)}}},[gt,we,mt,y.status,M,le.length]),{suggestions:yt,suggestionIndex:wt,showSuggestions:Ne,argMode:he,argItems:Ke,argIndex:kt,selectedConnectorIds:qt,selectedCapabilities:Pt,deleteConfirmMode:Yt,handleInputChange:I,handleSubmit:m}=es({input:K,setInput:ie,chatId:Y,setChatId:Ce,currentChatTitle:j,setCurrentChatTitle:A,currentModel:Z,setCurrentModel:q,currentAgentId:de,setCurrentAgentId:$e,currentAgentDetails:f,setCurrentAgentDetails:()=>{},activeConnectorIds:B,setActiveConnectorIds:ne,sandbox:w,setSandbox:S,webSearch:te,setWebSearch:U,imageGeneration:xe,setImageGeneration:tt,chart:ot,setChart:De,fileSystem:nt,setFileSystem:bo,availableModels:Q,availableAgents:pe,availableConnectors:ee,messages:_,hasPersistedChat:N,setHasPersistedChat:R,setMessages:F,addSystemMessage:we,startNewChat:zt,sendMessage:Ve,setFullOutput:re,credentials:W,setCredentials:E,setState:k,defaultCapabilities:{sandbox:r,webSearch:a,imageGeneration:c,chart:d,fileSystem:$},capabilityLabelMap:Vt,hasUploadingFiles:xo});if(Wo((b,O)=>{(O.ctrl||O.meta)&&b==="v"&&ht()},{isActive:y.status==="ready"&&!he}),Wo((b,O)=>{if(!O.escape)return;let ge=Date.now(),J=v.current;v.current=ge,!(!J||ge-J>Wr)&&(he||Ne||(v.current=null,We&&Kt(),K.length>0&&I("")))},{isActive:y.status==="ready"}),Wo((b,O)=>{O.return&&(zt("Started a new chat."),k({status:"ready"}))},{isActive:y.status==="error"}),uo(()=>{if(W&&!M&&y.status==="loading")if(!Z&&!de){let b=oe.getDefaultModel(),O=b&&Q.some(J=>J.id===b),ge=O?b:Q[0]?.id;ge?(O||oe.setDefaultModel(ge),q(ge),k({status:"ready"})):pe.length===0?k({status:"no-model"}):k({status:"ready"})}else k({status:"ready"})},[W,M,Z,de,Q,pe,y.status,q,k]),uo(()=>{n&&W&&y.status==="ready"&&Ve(n)},[W,n]),y.status==="loading")return ue(Ie,{flexDirection:"column",children:[X(V,{children:x}),ue(Ie,{children:[X(V,{color:"cyan",children:X(Mo,{type:"dots"})}),X(V,{children:" Initializing chat..."})]})]});if(y.status==="not-logged-in")return ue(Ie,{flexDirection:"column",children:[X(V,{children:x}),X(V,{color:"yellow",children:"Not logged in"}),X(V,{dimColor:!0,children:"Run `entrydesk login` to authenticate first."})]});if(y.status==="no-workspace")return ue(Ie,{flexDirection:"column",children:[X(V,{children:x}),X(V,{color:"yellow",children:"No workspace selected"}),X(V,{dimColor:!0,children:"Run `entrydesk workspaces` to select a workspace first."})]});if(y.status==="no-model")return ue(Ie,{flexDirection:"column",children:[X(V,{children:x}),X(V,{color:"yellow",children:"No model or agent specified"}),s&&X(V,{dimColor:!0,children:"Could not determine the model used in this chat."}),X(V,{dimColor:!0,children:"Please specify a model with --model or use an agent with -a."}),X(V,{dimColor:!0,children:"Example: entrydesk chat -c 1 -i --model gemini-2.5-flash-lite"})]});if(y.status==="error")return ue(Ie,{flexDirection:"column",children:[X(V,{children:x}),ue(V,{color:"red",children:["Error: ",y.message]}),X(V,{dimColor:!0,children:"Press Enter to start a new chat, or Ctrl+C to exit"})]});let l=de?f?f.connectors&&f.connectors.length>0?f.connectors.map(b=>b.name).join(", "):"none":"loading...":B&&B.length>0?ee.filter(b=>B.includes(b.id)).map(b=>b.name).join(", ")||`${B.length} connector(s)`:"none",u=[];if(de)if(f?.capabilities)for(let b of f.capabilities)u.push(Vt.get(b)??b);else u.push("loading...");else w&&u.push("Sandbox"),te&&u.push("Web"),xe&&u.push("Image"),ot&&u.push("Chart");nt&&u.push("FileSystem");let g=G.getCurrentProfileName(),T=g!=="default";return ue(Ie,{flexDirection:"column",children:[ue(Ie,{marginBottom:1,flexDirection:"column",children:[X(V,{children:x}),ue(Ie,{children:[X(V,{bold:!0,color:"cyan",children:j?`Continuing: ${j}`:"EntryDesk CLI"}),ue(V,{dimColor:!0,children:[" v","1.8.
|
|
198
|
+
`).map(n=>n.length))}function Gr(e){let t=Jr(ns);return e>=t?ns:Br}function ss({agentId:e,model:t,message:n,chatId:s,chatTitle:o,connectorIds:i,enableSandbox:r=!0,enableWebSearch:a=!1,enableImageGeneration:c=!1,enableChart:d=!1,enableFileSystem:$=!0}){let C=process.stdout.columns??80,x=Gr(C),v=os(null),h=Rn(s,o),{state:y,setState:k,messages:_,setMessages:F,input:K,setInput:ie,chatId:Y,setChatId:Ce,currentChatTitle:j,setCurrentChatTitle:A,hasPersistedChat:N,setHasPersistedChat:R,credentials:W,setCredentials:E,currentResponse:me,setCurrentResponse:D,fullOutput:p,setFullOutput:re,addSystemMessage:we,startNewChat:z}=h,{credentials:P}=jn(k);uo(()=>{P&&!W&&E(P)},[P,W,E]);let{availableConnectors:ee,availableModels:Q,availableAgents:pe,modelProviders:le,loading:M}=Fn(W),{currentModel:Z,setCurrentModel:q,currentAgentId:de,setCurrentAgentId:$e,activeConnectorIds:B,setActiveConnectorIds:ne}=zn(t,e,i),L=os(!1);uo(()=>{if(!L.current){if(L.current=!0,!t&&!e){let b=oe.getDefaultModel();b&&q(b)}if(!i&&!e){let b=oe.getDefaultConnectorIds();b&&ne(b.length>0?b:void 0)}}},[t,e,i,q,ne]);let{currentAgentDetails:f}=Kn(de,W),{sandbox:w,setSandbox:S,webSearch:te,setWebSearch:U,imageGeneration:xe,setImageGeneration:tt,chart:ot,setChart:De,fileSystem:nt,setFileSystem:bo,capabilityLabelMap:Vt}=Vn(r,a,c,d,$),{pendingFiles:je,addFile:gt,removeFile:He,clearFiles:Kt,getUploadedFileIds:st,hasUploadingFiles:xo,hasFiles:We}=ts({credentials:W,currentModel:Z,modelProviders:le,onUploadSuccess:b=>{we(`\u2713 Attached: ${b}`)},onUploadError:(b,O)=>{we(`\u2717 Failed to upload ${b}: ${O}`)}}),{sendMessage:Ve}=Mn({chatId:Y,credentials:W,currentAgentId:de,currentModel:Z,activeConnectorIds:B,sandbox:w,webSearch:te,imageGeneration:xe,chart:ot,localTools:nt,fullOutput:p,setMessages:F,setState:k,setCurrentResponse:D,setCredentials:E,setHasPersistedChat:R,getFileIds:st,clearFiles:Kt}),zt=Jo(b=>{z(b),D("")},[z]),[mt,ut]=Ur(!1),rt=Jo(async b=>{let O=b.text.trim(),ge=ao(O);if(/^https?:\/\//.test(ge))return;if(await _n(O)&&En(ge)){let ce=await Dn(O);ce&&(b.preventDefault(),await gt(ce))}},[gt]),ht=Jo(async()=>{if(!(mt||y.status!=="ready")){if(M||le.length===0){we("Please wait for resources to load before pasting images.");return}we("Reading clipboard..."),ut(!0);try{let b=await Nn();if(b){let O=`clipboard-${Date.now()}.png`;we(`Uploading: ${O} (${Math.round(b.buffer.length/1024)}KB)`),await gt({buffer:b.buffer,filename:O,mimeType:b.mime})}else we("No image found in clipboard. Copy an image first.")}catch(b){let O=b instanceof Error?b.message:"Failed to read clipboard";we(`Clipboard error: ${O}`)}finally{ut(!1)}}},[gt,we,mt,y.status,M,le.length]),{suggestions:yt,suggestionIndex:wt,showSuggestions:Ne,argMode:he,argItems:Ke,argIndex:kt,selectedConnectorIds:qt,selectedCapabilities:Pt,deleteConfirmMode:Yt,handleInputChange:I,handleSubmit:m}=es({input:K,setInput:ie,chatId:Y,setChatId:Ce,currentChatTitle:j,setCurrentChatTitle:A,currentModel:Z,setCurrentModel:q,currentAgentId:de,setCurrentAgentId:$e,currentAgentDetails:f,setCurrentAgentDetails:()=>{},activeConnectorIds:B,setActiveConnectorIds:ne,sandbox:w,setSandbox:S,webSearch:te,setWebSearch:U,imageGeneration:xe,setImageGeneration:tt,chart:ot,setChart:De,fileSystem:nt,setFileSystem:bo,availableModels:Q,availableAgents:pe,availableConnectors:ee,messages:_,hasPersistedChat:N,setHasPersistedChat:R,setMessages:F,addSystemMessage:we,startNewChat:zt,sendMessage:Ve,setFullOutput:re,credentials:W,setCredentials:E,setState:k,defaultCapabilities:{sandbox:r,webSearch:a,imageGeneration:c,chart:d,fileSystem:$},capabilityLabelMap:Vt,hasUploadingFiles:xo});if(Wo((b,O)=>{(O.ctrl||O.meta)&&b==="v"&&ht()},{isActive:y.status==="ready"&&!he}),Wo((b,O)=>{if(!O.escape)return;let ge=Date.now(),J=v.current;v.current=ge,!(!J||ge-J>Wr)&&(he||Ne||(v.current=null,We&&Kt(),K.length>0&&I("")))},{isActive:y.status==="ready"}),Wo((b,O)=>{O.return&&(zt("Started a new chat."),k({status:"ready"}))},{isActive:y.status==="error"}),uo(()=>{if(W&&!M&&y.status==="loading")if(!Z&&!de){let b=oe.getDefaultModel(),O=b&&Q.some(J=>J.id===b),ge=O?b:Q[0]?.id;ge?(O||oe.setDefaultModel(ge),q(ge),k({status:"ready"})):pe.length===0?k({status:"no-model"}):k({status:"ready"})}else k({status:"ready"})},[W,M,Z,de,Q,pe,y.status,q,k]),uo(()=>{n&&W&&y.status==="ready"&&Ve(n)},[W,n]),y.status==="loading")return ue(Ie,{flexDirection:"column",children:[X(V,{children:x}),ue(Ie,{children:[X(V,{color:"cyan",children:X(Mo,{type:"dots"})}),X(V,{children:" Initializing chat..."})]})]});if(y.status==="not-logged-in")return ue(Ie,{flexDirection:"column",children:[X(V,{children:x}),X(V,{color:"yellow",children:"Not logged in"}),X(V,{dimColor:!0,children:"Run `entrydesk login` to authenticate first."})]});if(y.status==="no-workspace")return ue(Ie,{flexDirection:"column",children:[X(V,{children:x}),X(V,{color:"yellow",children:"No workspace selected"}),X(V,{dimColor:!0,children:"Run `entrydesk workspaces` to select a workspace first."})]});if(y.status==="no-model")return ue(Ie,{flexDirection:"column",children:[X(V,{children:x}),X(V,{color:"yellow",children:"No model or agent specified"}),s&&X(V,{dimColor:!0,children:"Could not determine the model used in this chat."}),X(V,{dimColor:!0,children:"Please specify a model with --model or use an agent with -a."}),X(V,{dimColor:!0,children:"Example: entrydesk chat -c 1 -i --model gemini-2.5-flash-lite"})]});if(y.status==="error")return ue(Ie,{flexDirection:"column",children:[X(V,{children:x}),ue(V,{color:"red",children:["Error: ",y.message]}),X(V,{dimColor:!0,children:"Press Enter to start a new chat, or Ctrl+C to exit"})]});let l=de?f?f.connectors&&f.connectors.length>0?f.connectors.map(b=>b.name).join(", "):"none":"loading...":B&&B.length>0?ee.filter(b=>B.includes(b.id)).map(b=>b.name).join(", ")||`${B.length} connector(s)`:"none",u=[];if(de)if(f?.capabilities)for(let b of f.capabilities)u.push(Vt.get(b)??b);else u.push("loading...");else w&&u.push("Sandbox"),te&&u.push("Web"),xe&&u.push("Image"),ot&&u.push("Chart");nt&&u.push("FileSystem");let g=G.getCurrentProfileName(),T=g!=="default";return ue(Ie,{flexDirection:"column",children:[ue(Ie,{marginBottom:1,flexDirection:"column",children:[X(V,{children:x}),ue(Ie,{children:[X(V,{bold:!0,color:"cyan",children:j?`Continuing: ${j}`:"EntryDesk CLI"}),ue(V,{dimColor:!0,children:[" v","1.8.2"]}),T&&ue(V,{color:"magenta",children:[" [",g,"]"]}),X(V,{dimColor:!0,children:" (type /help for commands)"})]})]}),_.map((b,O)=>{let ge=b.parts&&p?ft(b.parts,!0):b.content,J=b.role==="user"?"green":b.role==="system"?"yellow":"blue",ce=b.role==="user"?"You":b.role==="system"?"System":"Assistant";return ue(Ie,{flexDirection:"column",marginBottom:1,children:[ue(V,{bold:!0,color:J,children:[ce,":"]}),X(Ro,{text:ge})]},O)}),me&&ue(Ie,{flexDirection:"column",marginBottom:1,children:[X(V,{bold:!0,color:"blue",children:"Assistant:"}),X(Ro,{text:me})]}),y.status==="ready"&&X(pn,{suggestions:yt,activeIndex:wt,visible:Ne}),y.status==="ready"&&he&&X(fn,{items:Ke,activeIndex:kt,pageSize:he==="agent"||he==="skills"||he==="model"?5:10,selectedIds:he==="connectors"?qt:he==="capabilities"?Pt:void 0,multiSelect:he==="connectors"||he==="capabilities",visible:!0,title:he==="model"?"Select model:":he==="agent"?"Select agent:":he==="skills"?"Select skill:":he==="connectors"?"Select connectors:":he==="capabilities"?"Select capabilities:":"Select chat:"}),y.status==="sending"&&!me?ue(Ie,{children:[X(V,{color:"cyan",children:X(Mo,{type:"dots"})}),X(V,{children:" Thinking..."})]}):y.status==="ready"&&!he?ue(Ie,{flexDirection:"column",children:[Yt&&X(Ie,{marginBottom:1,children:X(V,{color:"yellow",children:"\u26A0\uFE0F Delete this chat? (y/N) "})}),We&&!Yt&&ue(Ie,{marginBottom:1,flexDirection:"row",gap:1,children:[X(V,{dimColor:!0,children:"Attachments:"}),je.map((b,O)=>ue(V,{children:[b.status==="uploading"?ue(V,{color:"yellow",children:[X(Mo,{type:"dots"})," ",b.filename]}):b.status==="error"?ue(V,{color:"red",children:["\u2717 ",b.filename]}):ue(V,{color:"green",children:["\u2713 ",b.filename]}),O<je.length-1&&X(V,{children:", "})]},b.id))]}),ue(Ie,{children:[X(V,{color:"green",children:"> "}),X(xn,{value:K,onChange:I,onSubmit:m,onPaste:rt,leadingOffset:2,multiline:!0})]})]}):null,ue(Ie,{marginTop:1,flexDirection:"column",children:[ue(Ie,{gap:2,children:[ue(V,{children:[X(V,{dimColor:!0,children:"Model: "}),X(V,{color:"magenta",children:de?f?.model?.name||"loading...":Q.find(b=>b.id===Z)?.name||Z||"none"})]}),ue(V,{children:[X(V,{dimColor:!0,children:"Connectors: "}),X(V,{color:"cyan",children:l})]}),ue(V,{children:[X(V,{dimColor:!0,children:"Capabilities: "}),X(V,{color:"green",children:u.length>0?u.join(", "):"none"})]})]}),ue(V,{dimColor:!0,children:["Esc Esc: Clear input & attachments | Ctrl+V: Paste image | Ctrl+O: Toggle full output ",p?"(ON)":"(OFF)"," | Ctrl+C: Exit"]})]})]})}import{jsx as qr}from"react/jsx-runtime";async function Vr(){let e=[];for await(let t of process.stdin)e.push(t);return Buffer.concat(e).toString("utf8").trim()}async function Kr(e,t,n,s){if(s<1)return console.error("Chat number must be 1 or greater"),null;let{chats:o}=await e.getChats(t,n,20);if(o.length===0)return console.error("No chats found. Start a new chat first."),null;if(s>o.length)return console.error(`Chat number ${s} not found. You have ${o.length} recent chats.`),console.error("Use `entrydesk chats` to see available chats."),null;let i=o[s-1],r;if(!i.agentId){let{messages:a}=await e.getMessages(t,n,i.id,10);r=a.find(d=>d.role==="assistant"&&d.modelId)?.modelId}return{chat:i,modelId:r}}var $t="\x1B[2m",_e="\x1B[0m",Go="\x1B[36m",ls="\x1B[33m",po="\x1B[32m",rs="stream-json";function is(e,t,n,s){e&&t&&(console.error(`Error: Cannot use both ${n} and ${s}`),process.exit(1))}function go(e,t){let n=t===void 0?{event:e}:{event:e,data:t};process.stdout.write(`${JSON.stringify(n)}
|
|
199
199
|
`)}function mo(e,t){if(t)return e;let n=e.split(`
|
|
200
200
|
`);if(n.length<=20)return e;let s=n.slice(0,5),o=n.slice(-5),i=n.length-10;return[...s,`${$t}... (${i} lines omitted, use --full-output to see all) ...${_e}`,...o].join(`
|
|
201
201
|
`)}function zr(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}function as(e,t){if(!e)return"(no result)";if(typeof e!="object")return mo(String(e),t);let n=e;if("structuredContent"in n&&n.structuredContent){let s=n.structuredContent,o=[];if(s.stdout&&typeof s.stdout=="string"&&s.stdout.trim()&&o.push(s.stdout.trim()),s.stderr&&typeof s.stderr=="string"&&s.stderr.trim()&&o.push(`${ls}[stderr]${_e} ${s.stderr.trim()}`),s.urls&&Array.isArray(s.urls)){let i=s.urls;for(let r of i)r.path&&r.url&&o.push(`${r.path}: ${r.url}`)}return o.length===0&&o.push(JSON.stringify(s,null,2)),mo(o.join(`
|
|
@@ -397,7 +397,7 @@ Local Development:
|
|
|
397
397
|
$ entrydesk config set hubUrl http://localhost:3000
|
|
398
398
|
|
|
399
399
|
For more information, visit https://entrydesk.com/docs/cli
|
|
400
|
-
`)}import{execFile as Zr}from"child_process";import{
|
|
400
|
+
`)}import{execFile as Zr}from"child_process";import{setTimeout as Qr}from"timers/promises";import{decodeJwt as ei}from"jose";import ti,{HTTPError as oi}from"ky";var ks="entrydesk-cli",ni="offline_access workspaces:read chats:read chats:write chats:delete agents:read agents:write connectors:read connectors:write tools:read tools:execute skills:read skills:write meetings:read meetings:write publishes:read publishes:write calendar:read calendar:write schedules:read schedules:write user:read user:write";function si(e){return new Promise((t,n)=>{let s=process.platform,o,i;switch(s){case"darwin":o="open",i=[e];break;case"win32":o="cmd",i=["/c","start","",e];break;default:o="xdg-open",i=[e];break}Zr(o,i,r=>{r?n(new Error(`Failed to open browser. Please manually visit: ${e}`,{cause:r})):t()})})}async function bs(e){let t=en(),n=tn(),s=on(),o=process.env.NODE_TLS_REJECT_UNAUTHORIZED;s.ignoreSslErrors&&(process.env.NODE_TLS_REJECT_UNAUTHORIZED="0",console.error("WARNING: SSL certificate validation is disabled globally for this process during the login flow. All connections in this process will skip TLS verification. Only use ENTRYDESK_IGNORE_SSL_ERRORS for local development."));try{let i=ti.create({prefixUrl:t,timeout:3e4,hooks:{beforeError:[k=>(k.request?.headers&&(k.request.headers.delete("authorization"),k.request.headers.delete("Authorization")),k)]}}),r;try{r=await i.post("v1/oauth/device/code",{json:{client_id:ks,scope:ni}}).json()}catch(k){let _=k instanceof Error?k:new Error("Failed to request device code");throw e?.onError?.(_),_}let{device_code:a,user_code:c,expires_in:d,interval:$}=r,C=new URL("/oauth/device",n);C.searchParams.set("user_code",c);let x=C.toString();e?.onDeviceCodeReceived?.(c,x),e?.onBrowserOpening?.();try{await si(x)}catch(k){process.env.DEBUG&&console.error("[DEBUG] Failed to open browser:",k)}e?.onWaitingForAuthorization?.();let h=Math.max($,5)*1e3,y=Date.now()+d*1e3;for(;Date.now()<y;){await Qr(h);try{let k=await i.post("v1/oauth/token",{json:{grant_type:"urn:ietf:params:oauth:grant-type:device_code",device_code:a,client_id:ks}}).json();e?.onAuthorized?.();let _={};try{_=ei(k.access_token)}catch{}return{accessToken:k.access_token,refreshToken:k.refresh_token??void 0,email:_.email||"",scopes:k.scope.split(" ").filter(F=>F.length>0)}}catch(k){if(k instanceof oi){let F;try{let K=await k.response.json();F=K.code||K.error}catch{continue}switch(F){case"authorization_pending":continue;case"slow_down":h+=5e3;continue;case"access_denied":throw new Error("Authorization denied by user",{cause:k});case"expired_token":throw new Error("Device code expired. Please try again.",{cause:k});default:throw new Error(`Authorization failed: ${F||"Unknown error"}`,{cause:k})}}let _=k instanceof Error?k:new Error("Unknown error during authorization");throw e?.onError?.(_),_}}throw new Error("Device code expired. Please try again.")}finally{o===void 0?delete process.env.NODE_TLS_REJECT_UNAUTHORIZED:process.env.NODE_TLS_REJECT_UNAUTHORIZED=o}}async function xs(e){if(process.env.DEBUG){let{getApiUrl:i,getHubUrl:r}=await import("./config-NHNGDQX6.js");console.log(`[DEBUG] Hub URL: ${r()}`),console.log(`[DEBUG] API URL: ${i()}`)}let t=await bs({onDeviceCodeReceived:(i,r)=>{e.json||(console.log(""),console.log("To authenticate, please:"),console.log(""),console.log(` 1. Visit: ${r}`),console.log(` 2. Enter code: ${i}`),console.log(""))},onBrowserOpening:()=>{e.json||console.log("Opening browser...")},onWaitingForAuthorization:()=>{e.json||console.log("Waiting for authorization...")},onAuthorized:()=>{e.json||console.log("Authorization successful!")}}),n=new H,{workspaces:s}=await n.getWorkspaces(t.accessToken),o=s[0];await Te.saveAll({accessToken:t.accessToken,refreshToken:t.refreshToken,email:t.email,workspaceId:o?.id}),e.json?console.log(JSON.stringify({email:t.email,workspaceId:o?.id,workspaceName:o?.name})):(console.log(`Logged in as ${t.email}`),o&&console.log(`Workspace: ${o.name}`))}async function Cs(e){try{let t=await Te.getAll();if(!t){console.log("Not logged in");return}try{t.refreshToken&&await new H().revokeToken(t.refreshToken)}catch{}await Te.clear(),console.log("Logged out successfully")}catch(t){ke(t)}}import ri from"http";import{Client as ii}from"@modelcontextprotocol/sdk/client/index.js";import{StreamableHTTPClientTransport as ai}from"@modelcontextprotocol/sdk/client/streamableHttp.js";import{Server as li}from"@modelcontextprotocol/sdk/server/index.js";import{StdioServerTransport as ci}from"@modelcontextprotocol/sdk/server/stdio.js";import{StreamableHTTPServerTransport as ui}from"@modelcontextprotocol/sdk/server/streamableHttp.js";import{CallToolRequestSchema as di,ListToolsRequestSchema as fi}from"@modelcontextprotocol/sdk/types.js";async function pi(e,t,n){let s=new ii({name:"entrydesk-cli-proxy",version:"1.0.0"}),o=new URL(`${e}/v1/workspaces/${n}/mcp`),i=new ai(o,{requestInit:{headers:{Authorization:`Bearer ${t}`}}});return await s.connect(i),s}function $s(e){let t=new li({name:"entrydesk-cli",version:"1.0.0"},{capabilities:{tools:{}}});return t.setRequestHandler(fi,async()=>({tools:(await e.listTools()).tools})),t.setRequestHandler(di,async n=>{let{name:s,arguments:o}=n.params,i=await e.callTool({name:s,arguments:o}),r=Array.isArray(i.content)?[...i.content]:[];return i.structuredContent&&r.push({type:"text",text:JSON.stringify(i.structuredContent,null,2)}),{content:r,structuredContent:i.structuredContent,isError:i.isError}}),t}async function gi(e,t){let n=ri.createServer(async(s,o)=>{if(s.method==="OPTIONS"){o.setHeader("Access-Control-Allow-Origin","*"),o.setHeader("Access-Control-Allow-Methods","GET, POST, DELETE, OPTIONS"),o.setHeader("Access-Control-Allow-Headers","Content-Type, Accept"),o.writeHead(204),o.end();return}if(s.url!=="/mcp"){o.writeHead(404,{"Content-Type":"application/json"}),o.end(JSON.stringify({error:"Not found"}));return}let i=$s(e),r=new ui({sessionIdGenerator:void 0});if(o.setHeader("Access-Control-Allow-Origin","*"),o.on("close",()=>{r.close(),i.close()}),await i.connect(r),s.method==="POST"){let a="";s.on("data",c=>{a+=c.toString()}),s.on("end",async()=>{try{let c=JSON.parse(a);await r.handleRequest(s,o,c)}catch{o.writeHead(400,{"Content-Type":"application/json"}),o.end(JSON.stringify({error:"Invalid JSON"}))}})}else await r.handleRequest(s,o)});n.listen(t,()=>{console.error(`EntryDesk MCP server running at http://localhost:${t}/mcp`),console.error("Press Ctrl+C to stop")}),process.on("SIGINT",async()=>{console.error(`
|
|
401
401
|
Shutting down...`),n.close(),await e.close(),process.exit(0)}),process.on("SIGTERM",async()=>{n.close(),await e.close(),process.exit(0)})}async function mi(e){let t=$s(e),n=new ci;n.onclose=async()=>{await e.close()},await t.connect(n)}async function Ss(e={mode:"stdio"}){process.on("unhandledRejection",t=>{console.error("[entrydesk-mcp] Unhandled rejection:",t)}),process.on("uncaughtException",t=>{console.error("[entrydesk-mcp] Uncaught exception:",t)});try{console.error("[entrydesk-mcp] Starting MCP server...");let t,n;try{let r=await fe();t=r.accessToken,n=r.workspaceId}catch(r){let a=r instanceof Error?r.message:"Authentication failed";console.error(a),process.exit(1)}let{apiUrl:s,mcp:o}=qe();console.error(`[entrydesk-mcp] Connecting to ${s}...`),console.error(`[entrydesk-mcp] Workspace: ${n}`);let i=await pi(s,t,n);if(console.error("[entrydesk-mcp] Connected to EntryDesk API"),e.mode==="http"){let r=e.port||o.httpPort;await gi(i,r)}else console.error("[entrydesk-mcp] Starting stdio server..."),await mi(i),console.error("[entrydesk-mcp] Stdio server started")}catch(t){console.error("[entrydesk-mcp] Fatal error:",t),process.exit(1)}}async function Ts(e){try{let t,n;try{let i=await fe();t=i.accessToken,n=i.workspaceId}catch(i){let r=i instanceof Error?i.message:"Authentication failed";console.error(r),process.exit(1)}let s=new H,{models:o}=await s.getModels(t,n);if(e.json){console.log(JSON.stringify(o));return}if(o.length===0){console.log("No models available in this workspace.");return}console.log(`Available Models (${o.length}):
|
|
402
402
|
`);for(let i of o)console.log(` ${i.name}`),i.description&&console.log(` ${i.description.slice(0,80)}`),console.log(` ID: ${i.id}`),console.log("")}catch(t){ke(t)}}function hi(){console.log(`
|
|
403
403
|
Usage: entrydesk profile [list|show|current|create|use|delete|rename|clone] [args]
|
|
@@ -523,7 +523,7 @@ Examples:
|
|
|
523
523
|
`)}async function Bs(e){if(e.help){Hi();return}let t,n;try{let h=await fe();t=h.accessToken,n=h.workspaceId}catch(h){let y=h instanceof Error?h.message:"Authentication failed";console.error(y),process.exit(1)}let s=new H,o=[],i,r=0,a=100;do{let h=await s.getMonthlyUsages(t,n,{nextKey:i,limit:100});if(o.push(...h.monthlyUsages),i=h.nextKey,r++,r>=a){console.error(`Warning: Showing first ${o.length} entries (pagination limit reached)`);break}}while(i);if(e.json){console.log(JSON.stringify(o));return}if(o.length===0){console.log("No usage data found for this workspace.");return}console.log(`Current Month Usage:
|
|
524
524
|
`);let c=0,d=0;for(let h of o)c+=parseFloat(h.totalCost),d+=h.operationCount;console.log(`Total Cost: $${c.toFixed(2)}`),console.log(`Total Operations: ${d.toLocaleString()}`),console.log(`Users: ${o.length}
|
|
525
525
|
`);let $=e.sortBy||"cost",C=[...o].toSorted((h,y)=>$==="cost"?parseFloat(y.totalCost)-parseFloat(h.totalCost):y.operationCount-h.operationCount),x=e.limit&&e.limit>0?e.limit:C.length,v=C.slice(0,x);console.log(`Usage by User (sorted by ${$}, showing ${v.length} of ${o.length}):
|
|
526
|
-
`);for(let h of v){let y=parseFloat(h.totalCost);console.log(` ${h.user.name} (${h.user.email})`),console.log(` Cost: $${y.toFixed(2)}`),console.log(` Operations: ${h.operationCount.toLocaleString()}`),console.log("")}v.length<o.length&&console.log(`... and ${o.length-v.length} more users`)}function Xo(){console.log("entrydesk 1.8.
|
|
526
|
+
`);for(let h of v){let y=parseFloat(h.totalCost);console.log(` ${h.user.name} (${h.user.email})`),console.log(` Cost: $${y.toFixed(2)}`),console.log(` Operations: ${h.operationCount.toLocaleString()}`),console.log("")}v.length<o.length&&console.log(`... and ${o.length-v.length} more users`)}function Xo(){console.log("entrydesk 1.8.2")}function Zo(){console.log(`
|
|
527
527
|
Usage: entrydesk workspaces [list|switch|use] [options]
|
|
528
528
|
|
|
529
529
|
Commands:
|