@entrydesk/cli 1.29.0 → 1.30.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/dist/{agents-HRFKKSCB.js → agents-JG6OXKYV.js} +1 -1
- package/dist/{billing-LXGGM4BO.js → billing-MGDBCV6I.js} +1 -1
- package/dist/{budget-3KJ75AIF.js → budget-YYGSDB4J.js} +1 -1
- package/dist/{chunk-YAWZE3PA.js → chunk-NC63CPWW.js} +60 -33
- package/dist/chunk-RJGB52EF.js +4 -0
- package/dist/{config-53QOLH2T.js → config-PBKYHI2B.js} +1 -1
- package/dist/{config-help-2YHNIPHU.js → config-help-RTQDCM2A.js} +1 -1
- package/dist/{connectors-YUVHSMJD.js → connectors-EEPEIQ76.js} +1 -1
- package/dist/index.js +1 -1
- package/dist/{login-BKSNJT4R.js → login-HL5KEHEN.js} +1 -1
- package/dist/{logout-U64RQTQO.js → logout-QI7X4M4E.js} +1 -1
- package/dist/{marketplace-4NZ4R2RK.js → marketplace-5QZCY7QH.js} +1 -1
- package/dist/mcp-5764U6QO.js +4 -0
- package/dist/{meeting-NAS2QHFI.js → meeting-5RUQYMWF.js} +1 -1
- package/dist/{models-E3O6GOH5.js → models-PFIG6ACY.js} +1 -1
- package/dist/{notifications-CSXLCFK2.js → notifications-ZCJVVQIC.js} +1 -1
- package/dist/{profile-4GVYKBJP.js → profile-RIAXCLXG.js} +1 -1
- package/dist/{recordings-GJIO55FV.js → recordings-FMD3YL7B.js} +1 -1
- package/dist/{schedules-7CGTNN5S.js → schedules-JFVHBBM3.js} +1 -1
- package/dist/{skills-OOY3DP3O.js → skills-L4AGJVTQ.js} +1 -1
- package/dist/{status-KK6P75DT.js → status-DBKKDZAF.js} +1 -1
- package/dist/task-PBX6HRS3.js +194 -0
- package/dist/{tasks-SJWOHL6F.js → tasks-7SK2EZZS.js} +1 -1
- package/dist/{tool-TW7BI2LH.js → tool-YOUXWQ76.js} +5 -5
- package/dist/{update-B3LT5ALF.js → update-3SS5DWV3.js} +1 -1
- package/dist/{usage-IQW77ZHI.js → usage-6PXKAMOY.js} +1 -1
- package/dist/{version-TG5WFL3B.js → version-RYL2AKE2.js} +1 -1
- package/dist/{workflow-J6RX65V7.js → workflow-6MU3A6LB.js} +1 -1
- package/dist/{workspaces-KDZIJPII.js → workspaces-EQSJKVVV.js} +1 -1
- package/package.json +7 -4
- package/dist/chunk-GN6HSCLY.js +0 -4
- package/dist/chunk-NOSHH4TO.js +0 -8
- package/dist/mcp-EON5KZPT.js +0 -4
- package/dist/task-ET6X7N52.js +0 -211
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{g as I,s as A,t as O,v}from"./chunk-
|
|
2
|
+
import{g as I,s as A,t as O,v}from"./chunk-RJGB52EF.js";import"./chunk-ZIAOI7B2.js";var h="\x1B[2m",c="\x1B[0m",p="\x1B[36m",N="\x1B[33m",R="\x1B[32m",b="stream-json";function f(t,n){let o=n===void 0?{event:t}:{event:t,data:n};process.stdout.write(`${JSON.stringify(o)}
|
|
3
3
|
`)}function w(t){let n=new Date(t),e=new Date().getTime()-n.getTime(),r=Math.floor(e/(1e3*60*60*24));return r===0?n.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit"}):r===1?"Yesterday":r<7?`${r} days ago`:n.toLocaleDateString("en-US",{month:"short",day:"numeric"})}var M="\x1B[1m";function j(t){return t.replace(/<mark>/g,M).replace(/<\/mark>/g,c).replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'").replace(/&/g,"&")}function $(t,n){if(n)return t;let o=t.split(`
|
|
4
4
|
`);if(o.length<=15)return t;let e=o.slice(0,6),r=o.slice(-4),i=o.length-10;return[...e,`... (${i} lines omitted, use --full-output to see all) ...`,...r].join(`
|
|
5
5
|
`)}function x(t){if(!t||typeof t!="object")return t;if(Array.isArray(t))return t.map(x);let n={};for(let[o,e]of Object.entries(t))typeof e=="string"&&e.length>200?n[o]=e.slice(0,150)+"... (truncated)":typeof e=="object"&&e!==null?n[o]=x(e):n[o]=e;return n}function J(t){if(!t||typeof t!="object")return String(t);try{return JSON.stringify(t,null,2)}catch{return String(t)}}function E(t,n){if(!t)return"(no result)";if(typeof t!="object")return $(String(t),n);let o=n?t:x(t);if("structuredContent"in o&&o.structuredContent){let e=o.structuredContent,r=[];if(e.stdout&&typeof e.stdout=="string"&&e.stdout.trim()&&r.push(e.stdout.trim()),e.stderr&&typeof e.stderr=="string"&&e.stderr.trim()&&r.push(`${N}[stderr]${c} ${e.stderr.trim()}`),e.urls&&Array.isArray(e.urls)){let i=e.urls;for(let s of i)s.path&&s.url&&r.push(`${s.path}: ${s.url}`)}return r.length===0&&r.push(JSON.stringify(e,null,2)),$(r.join(`
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{c as S,t as _}from"./chunk-
|
|
2
|
+
import{c as S,t as _}from"./chunk-RJGB52EF.js";import"./chunk-ZIAOI7B2.js";import R from"fs";import{Client as x,StreamableHTTPClientTransport as v}from"@modelcontextprotocol/client";async function A(t={}){let e=t.apiUrl,n=t.accessToken,o=t.workspaceId;if(!n||!o){let l=await _();n=n||l.accessToken,o=o||l.workspaceId}e||(e=S().apiUrl);let i=new x({name:"entrydesk-cli",version:"1.0.0"}),s=new URL(`${e}/v1/workspaces/${o}/mcp`),r=new v(s,{requestInit:{headers:{Authorization:`Bearer ${n}`}}});return await i.connect(r),i}async function T(){return A()}import h from"fs/promises";import D from"os";import d from"path";var y=!process.env.NO_COLOR&&!!process.stdout.isTTY,p={green:y?"\x1B[32m":"",yellow:y?"\x1B[33m":"",reset:y?"\x1B[0m":""},P=10*1024,O=8*1024,N=2*1024,b=100,M=100;function U(){return d.join(D.homedir(),".entrydesk","tool-results")}function B(t){let e=t.trim().replace(/[/\\:*?"<>|\s]/g,"_").replace(/_+/g,"_").replace(/^[._]+|[._]+$/g,"").slice(0,b);return!e||e==="."||e===".."?"unnamed_tool":e}function F(t){try{return JSON.stringify(t,(e,n)=>typeof n=="bigint"?`${n}n`:typeof n=="function"?"[Function]":typeof n=="symbol"?n.toString():n,2)}catch{return String(t)}}function J(t){let e=new Date,n=[e.getFullYear(),String(e.getMonth()+1).padStart(2,"0"),String(e.getDate()).padStart(2,"0")].join("-")+"_"+[String(e.getHours()).padStart(2,"0"),String(e.getMinutes()).padStart(2,"0"),String(e.getSeconds()).padStart(2,"0")].join("-"),o=B(t);return`${n}_${o}.json`}async function I(t,e){try{return await h.writeFile(t,e,{encoding:"utf8",flag:"wx"}),!0}catch(n){if(n instanceof Error&&"code"in n&&n.code==="EEXIST")return!1;throw n}}async function k(t,e){try{let n=U();await h.mkdir(n,{recursive:!0});let o=J(t),i=d.extname(o),s=o.slice(0,-i.length),r=F(e),l=d.join(n,o);if(await I(l,r))return l;for(let u=1;u<=M;u++){let w=d.join(n,`${s}-${u}${i}`);if(await I(w,r))return w}let a=Math.random().toString(36).slice(2,10),c=d.join(n,`${s}-${a}${i}`);return await h.writeFile(c,r,{encoding:"utf8",flag:"wx"}),c}catch(n){let o=n instanceof Error?n.message:"unknown error";return console.error(`${p.yellow}Warning: Could not save result to file: ${o}${p.reset}`),null}}function $(t,e){let n=Buffer.byteLength(t,"utf8");if(n<=P)return t;let o=t.slice(0,O),i=t.slice(-N),r=((n-O-N)/1024).toFixed(1),l=(n/1024).toFixed(1),a=` ... (skipped ${r}KB of ${l}KB) ...`;return e&&(a+=`
|
|
3
3
|
Tip: jq -r '.structuredContent.field' <file> | grep/head/tail`),`${o}
|
|
4
4
|
|
|
5
|
-
${
|
|
5
|
+
${a}
|
|
6
6
|
|
|
7
|
-
${i}`}function
|
|
7
|
+
${i}`}function C(t){console.log(`${p.green}Tool execution result saved to: ${t}${p.reset}`),console.log()}function E(){console.log(`${p.green}Tool execution result:${p.reset}`)}function H(t){return t.split("__")[0]??t}function f(t,e,n){console.error(n?JSON.stringify({error:{code:t,message:e}}):`Error [${t}]: ${e}`),process.exit(1)}function g(t,e,n="CONNECTION_FAILED"){let o=t instanceof Error?t.message:"Unknown error";o.includes("Not logged in")||o.includes("not-logged-in")?f("AUTH_MISSING",o,e):f(n,o,e)}async function Y(){return process.stdin.isTTY?null:new Promise(t=>{let e=[],n=!1,o=!1,i,s,r,l,a=()=>{clearTimeout(i),process.stdin.removeListener("data",s),process.stdin.removeListener("end",r),process.stdin.removeListener("error",l)},c=u=>{o||(o=!0,a(),t(u))};s=u=>{n=!0,clearTimeout(i),e.push(u)},r=()=>{e.length===0?c(null):c(Buffer.concat(e).toString("utf-8").trim())},l=()=>{c(null)},i=setTimeout(()=>{n||c(null)},100),process.stdin.on("data",s),process.stdin.on("end",r),process.stdin.on("error",l),process.stdin.resume()})}var m=class extends Error{constructor(e){super(e),this.name="InputError"}};async function V(t,e){if(t)return t;if(e)try{return R.readFileSync(e,"utf-8").trim()}catch(o){let i=o instanceof Error?o.message:"Failed to read input file";throw new m(`Failed to read input file: ${i}`)}let n=await Y();if(n)return n;throw new m("Input JSON is required. Use --input, --input-file, or pipe via stdin")}function q(t){let e=[`Tool: ${t.name}`];return t.description&&e.push(` Description: ${t.description}`),e.join(`
|
|
8
8
|
`)}function X(t){let e=[`Tool: ${t.name}`];return t.description&&(e.push("Description:"),e.push(` ${t.description}`)),e.push("Input Schema:"),e.push(JSON.stringify(t.inputSchema,null,2)),e.join(`
|
|
9
9
|
`)}async function z(t,e){let n=await T().catch(o=>{g(o,t)});try{let i=(await n.listTools()).tools;if(e){let s=e.toLowerCase();i=i.filter(r=>H(r.name).toLowerCase().startsWith(s))}if(t)console.log(JSON.stringify(i,null,2));else{let s=e?` (prefix: ${e})`:"";console.log(`Available Tools (${i.length})${s}:
|
|
10
|
-
`);for(let r of i)console.log(q(r)),console.log()}}catch(o){g(o,t)}finally{await n.close().catch(()=>{})}}async function G(t,e){let n=await T().catch(o=>{g(o,e)});try{let i=(await n.listTools()).tools.find(s=>s.name===t);i||f("TOOL_NOT_FOUND",`Tool not found: ${t}`,e),console.log(e?JSON.stringify(i,null,2):X(i))}catch(o){g(o,e)}finally{await n.close().catch(()=>{})}}async function K(t,e,n){let o;try{o=JSON.parse(e)}catch(r){let l=r instanceof Error?`Invalid JSON input: ${r.message}`:"Invalid JSON input";f("INVALID_INPUT",l,n)}let i=await T().catch(r=>{g(r,n,"TOOL_CALL_FAILED")}),s=!1;try{let r=await i.callTool({name:t,arguments:o});if(n)console.log(JSON.stringify(r,null,2));else{let l=await
|
|
10
|
+
`);for(let r of i)console.log(q(r)),console.log()}}catch(o){g(o,t)}finally{await n.close().catch(()=>{})}}async function G(t,e){let n=await T().catch(o=>{g(o,e)});try{let i=(await n.listTools()).tools.find(s=>s.name===t);i||f("TOOL_NOT_FOUND",`Tool not found: ${t}`,e),console.log(e?JSON.stringify(i,null,2):X(i))}catch(o){g(o,e)}finally{await n.close().catch(()=>{})}}async function K(t,e,n){let o;try{o=JSON.parse(e)}catch(r){let l=r instanceof Error?`Invalid JSON input: ${r.message}`:"Invalid JSON input";f("INVALID_INPUT",l,n)}let i=await T().catch(r=>{g(r,n,"TOOL_CALL_FAILED")}),s=!1;try{let r=await i.callTool({name:t,arguments:o});if(n)console.log(JSON.stringify(r,null,2));else{let l=await k(t,r);l&&C(l),E();for(let a of r.content)a.type==="text"?console.log(a.text):a.type==="image"?console.log(`[Image: ${a.mimeType}]`):a.type==="resource"?console.log(`[Resource: ${a.resource.uri}]`):console.log(JSON.stringify(a,null,2));if(r.structuredContent){let a=JSON.stringify(r.structuredContent,null,2),c=$(a,l);console.log(c)}}r.isError&&(s=!0)}catch(r){g(r,n,"TOOL_CALL_FAILED")}finally{await i.close().catch(()=>{})}s&&process.exit(1)}function L(){console.log(`Usage: entrydesk tool <action> [options]
|
|
11
11
|
|
|
12
12
|
Actions:
|
|
13
13
|
list List all available tools
|
|
@@ -32,4 +32,4 @@ Examples:
|
|
|
32
32
|
entrydesk tool call agent__search_agents --input '{"limit": 5}'
|
|
33
33
|
entrydesk tool call agent__search_agents --input-file input.json
|
|
34
34
|
echo '{"limit": 5}' | entrydesk tool call agent__search_agents
|
|
35
|
-
`)}async function
|
|
35
|
+
`)}async function lt(t){let e=t.json??!1;if(t.help){L();return}switch(t.action){case"list":await z(e,t.prefix);break;case"get":t.name||f("INVALID_INPUT","Tool name is required",e),await G(t.name,e);break;case"call":{t.name||f("INVALID_INPUT","Tool name is required",e);let n;try{n=await V(t.input,t.inputFile)}catch(o){throw o instanceof m&&f("INVALID_INPUT",o.message,e),o}await K(t.name,n,e);break}default:L();break}}export{m as InputError,V as getInputJson,L as printToolUsage,Y as readStdin,lt as runTool};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{u as l}from"./chunk-
|
|
2
|
+
import{u as l}from"./chunk-RJGB52EF.js";import"./chunk-ZIAOI7B2.js";import{spawn as f}from"child_process";var a="@entrydesk/cli";function g(){return"1.30.0"}function d(n){let e=/^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/u.exec(n.trim());return e?{nums:[Number(e[1]),Number(e[2]),Number(e[3])],prerelease:e[4]??null}:null}function h(n,e){if(n===e)return 0;if(n===null)return 1;if(e===null)return-1;let t=n.split("."),i=e.split("."),r=Math.min(t.length,i.length);for(let s=0;s<r;s++){let u=t[s],o=i[s];if(u!==o){let c=/^\d+$/u.test(u),p=/^\d+$/u.test(o);return c&&p?Number(u)<Number(o)?-1:1:c?-1:p?1:u<o?-1:1}}return t.length===i.length?0:t.length<i.length?-1:1}function y(n,e){let t=d(n),i=d(e);if(!t||!i)return t?1:i?-1:0;for(let r=0;r<3;r++)if(t.nums[r]!==i.nums[r])return t.nums[r]<i.nums[r]?-1:1;return h(t.prerelease,i.prerelease)}function $(){return process.platform==="win32"?"npm.cmd":"npm"}function m(n,{inheritOutput:e}){return new Promise((t,i)=>{let r=f($(),n,{stdio:e?["ignore","inherit","inherit"]:["ignore","pipe","pipe"]}),s="",u="";r.stdout?.on("data",o=>{s+=String(o)}),r.stderr?.on("data",o=>{u+=String(o)}),r.once("error",i),r.once("close",o=>{t({exitCode:o??1,stdout:s,stderr:u})})})}async function w(){let n;try{n=await m(["view",a,"version"],{inheritOutput:!1})}catch(t){throw new l("Failed to run npm \u2014 is npm installed and on your PATH?",1,t instanceof Error?t:void 0)}let e=n.stdout.trim();if(n.exitCode!==0||!e)throw new l(`Failed to look up the latest ${a} version from the npm registry.${n.stderr?`
|
|
3
3
|
${n.stderr.trim()}`:""}`);if(!d(e))throw new l(`Unexpected version from the npm registry: ${JSON.stringify(e)}`);return e}async function _(n){let e=g(),t=await w(),i=y(e,t),r=i>=0;if(n.check||r){n.json?console.log(JSON.stringify({current:e,latest:t,upToDate:r,updated:!1})):i>0?console.log(`entrydesk ${e} is newer than the latest published version (${t}). Nothing to do.`):console.log(r?`entrydesk ${e} is already the latest version.`:`Update available: ${e} \u2192 ${t}. Run \`entrydesk update\` to install.`);return}n.json||console.log(`Updating entrydesk ${e} \u2192 ${t} ...`);let s=await m(["install","-g",`${a}@${t}`],{inheritOutput:!n.json});if(s.exitCode!==0){let u=s.stderr?`
|
|
4
4
|
${s.stderr.trim()}`:"";throw new l(`npm install failed (exit code ${s.exitCode}). You can update manually with \`npm install -g ${a}@latest\`.`+u,s.exitCode)}n.json?console.log(JSON.stringify({current:e,latest:t,upToDate:r,updated:!0})):console.log(`entrydesk updated to ${t}.`)}export{_ as runUpdate};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{g as d,t as y,v as U}from"./chunk-
|
|
2
|
+
import{g as d,t as y,v as U}from"./chunk-RJGB52EF.js";import"./chunk-ZIAOI7B2.js";import{writeFileSync as S}from"fs";function $(){console.log(`
|
|
3
3
|
Usage: entrydesk usage [balance|me|consumptions|export] [options]
|
|
4
4
|
|
|
5
5
|
Commands:
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import"./chunk-ZIAOI7B2.js";function n(){console.log("entrydesk 1.
|
|
2
|
+
import"./chunk-ZIAOI7B2.js";function n(){console.log("entrydesk 1.30.0")}export{n as printVersion};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{
|
|
2
|
+
import{g as u}from"./chunk-NC63CPWW.js";import{g as p,t as g,v as k}from"./chunk-RJGB52EF.js";import"./chunk-ZIAOI7B2.js";import{readFileSync as I}from"fs";var m=262144,R=new Set(["completed","failed","cancelled"]);function f(){console.log(`
|
|
3
3
|
Usage: entrydesk workflow [list|get|create|update|run|runs|run-get|share] [options]
|
|
4
4
|
|
|
5
5
|
Commands:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{f as a,g as w,s as k}from"./chunk-
|
|
2
|
+
import{f as a,g as w,s as k}from"./chunk-RJGB52EF.js";import"./chunk-ZIAOI7B2.js";function l(){console.log(`
|
|
3
3
|
Usage: entrydesk workspaces [list|switch|use] [options]
|
|
4
4
|
|
|
5
5
|
Commands:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@entrydesk/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.30.0",
|
|
4
4
|
"description": "EntryDesk CLI - Interact with EntryDesk from your terminal",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
"README.md"
|
|
12
12
|
],
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@modelcontextprotocol/
|
|
14
|
+
"@modelcontextprotocol/client": "^2.0.0",
|
|
15
|
+
"@modelcontextprotocol/node": "^2.0.0",
|
|
16
|
+
"@modelcontextprotocol/server": "^2.0.0",
|
|
15
17
|
"adm-zip": "^0.6.0",
|
|
16
18
|
"archiver": "^7.0.1",
|
|
17
19
|
"ink": "^7.1.1",
|
|
@@ -35,9 +37,10 @@
|
|
|
35
37
|
"typescript": "^7.0.2",
|
|
36
38
|
"vitest": "^4.1.6",
|
|
37
39
|
"@entrydesk/client-tools": "^0.0.0",
|
|
38
|
-
"@
|
|
40
|
+
"@entrydesk/shared": "^0.0.0",
|
|
39
41
|
"@gntc/utils": "^0.0.0",
|
|
40
|
-
"@
|
|
42
|
+
"@gntc/ci": "^0.0.0",
|
|
43
|
+
"@gntc/vitest": "^0.0.0"
|
|
41
44
|
},
|
|
42
45
|
"optionalDependencies": {
|
|
43
46
|
"keytar": "^7.9.0"
|
package/dist/chunk-GN6HSCLY.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import m from"fs";import et from"os";import E from"path";import{HTTPError as Xe,TimeoutError as Ze}from"ky";import M from"fs";function me(s){let e=a.getEffectiveProfileName(s);return a.getProfileConfigFile(e)}function g(s){let e=me(s);try{if(!M.existsSync(e))return{};let t=M.readFileSync(e,"utf-8");return JSON.parse(t)}catch{return{}}}function w(s,e){let t=a.getEffectiveProfileName(e);a.ensureProfileDir(t);let r=a.getProfileConfigFile(t);M.writeFileSync(r,JSON.stringify(s,null,2),{mode:384});try{M.chmodSync(r,384)}catch{}}var O={getApiUrl(s){return g(s).apiUrl??null},setApiUrl(s,e){let t=g(e);t.apiUrl=s,w(t,e)},clearApiUrl(s){let e=g(s);delete e.apiUrl,w(e,s)},getHubUrl(s){return g(s).hubUrl??null},setHubUrl(s,e){let t=g(e);t.hubUrl=s,w(t,e)},getAll(s){return g(s)},setAll(s,e){w(s,e)},set(s,e,t){let r=g(t);r[s]=e,w(r,t)},get(s,e){return g(e)[s]},unset(s,e){let t=g(e);delete t[s],w(t,e)},getDefaultModel(s){return g(s).model?.default??null},setDefaultModel(s,e){let t=g(e);t.model={...t.model,default:s},w(t,e)},getDefaultConnectorIds(s){return g(s).connectors?.defaults??null},setDefaultConnectorIds(s,e){let t=g(e);t.connectors={...t.connectors,defaults:s},w(t,e)},getLocalTools(s){return g(s).localTools??null},setLocalTools(s,e){let t=g(e);t.localTools={...t.localTools,...s},w(t,e)}};var we="https://api.entrydesk.com",ke="https://app.entrydesk.com",ve=3100,Re=300*1e3;function L(s){return{apiUrl:process.env.ENTRYDESK_API_URL||O.getApiUrl(s)||we,hubUrl:process.env.ENTRYDESK_HUB_URL||O.getHubUrl(s)||ke,mcp:{httpPort:ve},auth:{loginTimeout:Re,ignoreSslErrors:process.env.ENTRYDESK_IGNORE_SSL_ERRORS==="true"||!1}}}function S(s){return L(s).apiUrl}function se(s){return L(s).hubUrl}function U(){return L().auth}import{HTTPError as Ye}from"ky";import be,{TimeoutError as xe,isHTTPError as oe}from"ky";import b from"crypto";import p from"fs";import Pe from"path";var Ae="ENTRYDESK_FORCE_FILE_STORAGE",$="EntryDesk CLI",Se="__entrydesk_keychain_test__",$e="profile:",Ce=".credentials.key",ne={keychain:!1,permissions:!1,corruptFile:!1,windowsFile:!1};function v(s,e){ne[s]||(ne[s]=!0,console.error(e))}function Te(){return process.env.ENTRYDESK_DEBUG?.toLowerCase()==="true"}function ie(s){if(!s||typeof s!="object")return!1;let e=s;return!(!("accessToken"in e||"refreshToken"in e||"email"in e||"workspaceId"in e)||"accessToken"in e&&typeof e.accessToken!="string"||"refreshToken"in e&&typeof e.refreshToken!="string"||"email"in e&&typeof e.email!="string"||"workspaceId"in e&&typeof e.workspaceId!="string")}function Ee(s){if(!s||typeof s!="object")return!1;let e=s;return typeof e.getPassword=="function"&&typeof e.setPassword=="function"&&typeof e.deletePassword=="function"}function F(s){return a.getProfileCredentialsFile(s)}var N=class{getKeyFilePath(e){return Pe.join(a.getProfileDir(e),Ce)}loadEncryptionKey(e){let t=this.getKeyFilePath(e);try{if(!p.existsSync(t))return null;let r=p.readFileSync(t);return r.length!==32?null:(this.ensureSecureFilePermissions(t),r)}catch{return null}}createEncryptionKey(e){a.ensureProfileDir(e);let t=this.getKeyFilePath(e),r=b.randomBytes(32);return p.writeFileSync(t,r,{mode:384}),this.ensureSecureFilePermissions(t),r}getOrCreateEncryptionKey(e){let t=this.loadEncryptionKey(e);return t||this.createEncryptionKey(e)}encrypt(e,t){let r=b.randomBytes(16),n=b.createCipheriv("aes-256-gcm",t,r),i=n.update(e,"utf8","hex");i+=n.final("hex");let o=n.getAuthTag();return`${r.toString("hex")}:${o.toString("hex")}:${i}`}decrypt(e,t){let r=e.split(":");if(r.length!==3)throw new Error("Invalid encrypted data format");let n=Buffer.from(r[0],"hex"),i=Buffer.from(r[1],"hex"),o=r[2],d=b.createDecipheriv("aes-256-gcm",t,n,{authTagLength:16});d.setAuthTag(i);let u=d.update(o,"hex","utf8");return u+=d.final("utf8"),u}tryDecrypt(e,t){try{return this.decrypt(e,t)}catch{return null}}tryParseCredentials(e){try{let t=JSON.parse(e);return ie(t)?t:null}catch{return null}}ensureSecureFilePermissions(e){if(process.platform!=="win32"){try{p.chmodSync(e,384)}catch{v("permissions","Warning: Failed to set secure permissions on credentials file.");return}try{(p.statSync(e).mode&511)!==384&&v("permissions","Warning: Credentials file permissions are too permissive.")}catch{v("permissions","Warning: Failed to verify credentials file permissions.")}}}async getCredentials(e){let t=F(e);try{if(!p.existsSync(t))return null;let r=p.readFileSync(t,"utf-8").trim();if(!r)return null;let n=this.loadEncryptionKey(e),i=n?this.tryDecrypt(r,n):null;if(i){let o=this.tryParseCredentials(i);if(o)return o}return v("corruptFile","Warning: Credentials file is unreadable. Please run `entrydesk login` again."),null}catch{return null}}async setCredentials(e,t){a.ensureProfileDir(e);let r=F(e),n=this.getOrCreateEncryptionKey(e),i=this.encrypt(JSON.stringify(t),n);p.writeFileSync(r,i,{mode:384}),this.ensureSecureFilePermissions(r)}async deleteCredentials(e){let t=F(e);try{p.existsSync(t)&&p.unlinkSync(t)}catch{}}},W=class{keytarModule=null;keytarLoadAttempted=!1;keychainAvailable=null;async getKeytar(){if(this.keytarLoadAttempted)return this.keytarModule;this.keytarLoadAttempted=!0;try{let t=await import("keytar"),r=t&&typeof t=="object"&&"default"in t?t.default:t;this.keytarModule=Ee(r)?r:null}catch{this.keytarModule=null}return this.keytarModule}getAccount(e){return`${$e}${e}`}async checkKeychainAvailability(){if(this.keychainAvailable!==null)return this.keychainAvailable;try{let e=await this.getKeytar();if(!e)return this.keychainAvailable=!1,!1;let t=`${Se}${b.randomBytes(8).toString("hex")}`,r="test";await e.setPassword($,t,r);let n=await e.getPassword($,t),i=await e.deletePassword($,t);return this.keychainAvailable=!!(i&&n===r),this.keychainAvailable}catch{return this.keychainAvailable=!1,!1}}async isAvailable(){return this.checkKeychainAvailability()}async getCredentials(e){if(!await this.checkKeychainAvailability())throw new Error("Keychain is not available");let t=await this.getKeytar();if(!t)throw new Error("Keytar module not available");let r=await t.getPassword($,this.getAccount(e));if(!r)return null;let n=this.tryParseKeychainPayload(r);return n||v("corruptFile",`Warning: Keychain entry for profile "${e}" is unreadable.`),n}async setCredentials(e,t){if(!await this.checkKeychainAvailability())throw new Error("Keychain is not available");let r=await this.getKeytar();if(!r)throw new Error("Keytar module not available");let n=JSON.stringify(t);await r.setPassword($,this.getAccount(e),n)}async deleteCredentials(e){if(!await this.checkKeychainAvailability())throw new Error("Keychain is not available");let t=await this.getKeytar();if(!t)throw new Error("Keytar module not available");await t.deletePassword($,this.getAccount(e))}tryParseKeychainPayload(e){try{let t=JSON.parse(e);return ie(t)?t:null}catch{return null}}},G=class{keychainStorage=null;fileStorage=new N;keychainAvailable=null;initPromise=null;shouldForceFileStorage(){return process.env[Ae]?.toLowerCase()==="true"}async initializeStorage(){if(this.shouldForceFileStorage()){this.keychainAvailable=!1,this.keychainStorage=null;return}try{let e=new W,t=await e.isAvailable();this.keychainAvailable=t,this.keychainStorage=t?e:null}catch{this.keychainAvailable=!1,this.keychainStorage=null}!this.keychainAvailable&&!this.shouldForceFileStorage()&&(Te()&&v("keychain","Keychain unavailable. Falling back to file-based credentials."),process.platform==="win32"&&v("windowsFile","Warning: File-based credentials on Windows may be readable by other users."))}async ensureInitialized(){if(this.shouldForceFileStorage()){this.keychainAvailable=!1,this.keychainStorage=null;return}this.keychainAvailable===null&&(this.initPromise??=this.initializeStorage(),await this.initPromise)}disableKeychain(){this.shouldForceFileStorage()||v("keychain","Keychain error encountered. Falling back to file-based credentials."),this.keychainAvailable=!1,this.keychainStorage=null}async getKeychainStorage(){return await this.ensureInitialized(),this.shouldForceFileStorage()?null:this.keychainAvailable?this.keychainStorage:null}async getCredentials(e){let t=await this.getKeychainStorage();if(!t)return this.fileStorage.getCredentials(e);try{let n=await t.getCredentials(e);if(n)return n}catch{return this.disableKeychain(),this.fileStorage.getCredentials(e)}let r=await this.fileStorage.getCredentials(e);if(r)try{await t.setCredentials(e,r),await this.fileStorage.deleteCredentials(e)}catch{}return r}async setCredentials(e,t){let r=await this.getKeychainStorage();if(!r){await this.fileStorage.setCredentials(e,t);return}try{await r.setCredentials(e,t),await this.fileStorage.deleteCredentials(e)}catch{this.disableKeychain(),await this.fileStorage.setCredentials(e,t)}}async deleteCredentials(e){let t=await this.getKeychainStorage();if(t)try{await t.deleteCredentials(e)}catch{this.disableKeychain()}await this.fileStorage.deleteCredentials(e)}},l=new G,h={async saveAccessToken(s,e){let t=a.getEffectiveProfileName(e),r=await l.getCredentials(t)??{};r.accessToken=s,await l.setCredentials(t,r)},async getAccessToken(s){let e=a.getEffectiveProfileName(s);return(await l.getCredentials(e))?.accessToken??null},async saveRefreshToken(s,e){let t=a.getEffectiveProfileName(e),r=await l.getCredentials(t)??{};r.refreshToken=s,await l.setCredentials(t,r)},async getRefreshToken(s){let e=a.getEffectiveProfileName(s);return(await l.getCredentials(e))?.refreshToken??null},async saveEmail(s,e){let t=a.getEffectiveProfileName(e),r=await l.getCredentials(t)??{};r.email=s,await l.setCredentials(t,r)},async getEmail(s){let e=a.getEffectiveProfileName(s);return(await l.getCredentials(e))?.email??null},async saveWorkspaceId(s,e){let t=a.getEffectiveProfileName(e),r=await l.getCredentials(t)??{};r.workspaceId=s,await l.setCredentials(t,r)},async getWorkspaceId(s){let e=a.getEffectiveProfileName(s);return(await l.getCredentials(e))?.workspaceId??null},async saveAll(s,e){let t=a.getEffectiveProfileName(e);await l.setCredentials(t,s)},async getAll(s){let e=a.getEffectiveProfileName(s);return l.getCredentials(e)},async clear(s){let e=a.getEffectiveProfileName(s);await l.deleteCredentials(e)},async moveProfileCredentials(s,e){let t=await l.getCredentials(s);t&&(await l.setCredentials(e,t),await l.deleteCredentials(s))},async deleteProfileCredentials(s){await l.deleteCredentials(s)},async isLoggedIn(s){let e=a.getEffectiveProfileName(s);return(await l.getCredentials(e))?.accessToken!=null}};var K=class s{client;baseUrl;runtimeConfigCache;constructor(e,t){this.baseUrl=e||S(t),U().ignoreSslErrors&&(process.env.NODE_TLS_REJECT_UNAUTHORIZED="0",process.env.DEBUG&&console.log("[DEBUG] ApiClient: SSL certificate validation disabled")),this.client=be.create({baseUrl:this.baseUrl.replace(/\/?$/,"/"),timeout:3e4,retry:{limit:3,methods:["get","put","head","delete","options","trace"],statusCodes:[408,413,429,500,502,503,504]},hooks:{beforeError:[({error:n})=>(oe(n)&&(n.request.headers.delete("authorization"),n.request.headers.delete("Authorization")),n)]}})}getBaseUrl(){return this.baseUrl}async refreshOAuthToken(e){return this.client.post("v1/oauth/token",{json:{grant_type:"refresh_token",refresh_token:e.refreshToken,client_id:e.clientId}}).json()}async revokeOAuthToken(e){await this.client.post("v1/oauth/revoke",{json:{token:e.token,token_type_hint:"refresh_token",client_id:e.clientId}})}async getWorkspaces(e){try{return process.env.DEBUG&&console.log(`[DEBUG] Calling getWorkspaces API: ${this.baseUrl}/v1/workspaces`),await this.client.get("v1/workspaces",{headers:{Authorization:`Bearer ${e}`}}).json()}catch(t){throw process.env.DEBUG&&(console.error("[DEBUG] getWorkspaces error:",t),t instanceof Error&&"cause"in t&&console.error("[DEBUG] Error cause:",t.cause)),t}}async getAgents(e,t,r){let n={limit:r?.limit??100};return r?.nextKey&&(n.nextKey=r.nextKey),r?.search&&(n.search=r.search),await this.client.get(`v1/workspaces/${t}/availableAgents`,{headers:{Authorization:`Bearer ${e}`},searchParams:n}).json()}async createAgent(e,t,r){return await this.client.post(`v1/workspaces/${t}/agents`,{headers:{Authorization:`Bearer ${e}`},json:r}).json()}async updateAgent(e,t,r,n){await this.client.put(`v1/workspaces/${t}/agents/${r}`,{headers:{Authorization:`Bearer ${e}`},json:n})}async deleteAgent(e,t,r){await this.client.delete(`v1/workspaces/${t}/agents/${r}`,{headers:{Authorization:`Bearer ${e}`}})}async getMyAgents(e,t,r){let n={limit:r?.limit??100};return r?.nextKey&&(n.nextKey=r.nextKey),r?.search&&(n.search=r.search),await this.client.get(`v1/workspaces/${t}/myAgents`,{headers:{Authorization:`Bearer ${e}`},searchParams:n}).json()}async publishAgent(e,t,r){await this.client.post(`v1/workspaces/${t}/agents/${r}/publish`,{headers:{Authorization:`Bearer ${e}`}})}async getAgentGrants(e,t,r){return await this.client.get(`v1/workspaces/${t}/agents/${r}/grants`,{headers:{Authorization:`Bearer ${e}`}}).json()}async upsertAgentGrant(e,t,r,n,i){return await this.client.put(`v1/workspaces/${t}/agents/${r}/grants/${n}`,{headers:{Authorization:`Bearer ${e}`},json:{role:i}}).json()}async removeAgentGrant(e,t,r,n){await this.client.delete(`v1/workspaces/${t}/agents/${r}/grants/${n}`,{headers:{Authorization:`Bearer ${e}`}})}async getMeetings(e,t,r){let n={limit:r?.limit??20};return r?.nextKey&&(n.nextKey=r.nextKey),r?.search&&(n.search=r.search),r?.filter&&(n.filter=r.filter),r?.sortBy&&(n.sortBy=r.sortBy),await this.client.get(`v1/workspaces/${t}/meetings`,{headers:{Authorization:`Bearer ${e}`},searchParams:n}).json()}async getMeeting(e,t,r){return await this.client.get(`v1/workspaces/${t}/meetings/${r}`,{headers:{Authorization:`Bearer ${e}`}}).json()}async createMeeting(e,t,r){return await this.client.post(`v1/workspaces/${t}/meetings`,{headers:{Authorization:`Bearer ${e}`},json:r}).json()}async updateMeeting(e,t,r,n){return await this.client.patch(`v1/workspaces/${t}/meetings/${r}`,{headers:{Authorization:`Bearer ${e}`},json:n}).json()}async deleteMeeting(e,t,r){await this.client.delete(`v1/workspaces/${t}/meetings/${r}`,{headers:{Authorization:`Bearer ${e}`}})}async getMeetingPreviousBrief(e,t,r){return await this.client.get(`v1/workspaces/${t}/meetings/${r}/previous`,{headers:{Authorization:`Bearer ${e}`}}).json()}async getRecording(e,t,r){return await this.client.get(`v1/workspaces/${t}/recordings/${r}`,{headers:{Authorization:`Bearer ${e}`}}).json()}async getMeetingShares(e,t,r){return await this.client.get(`v1/workspaces/${t}/meetings/${r}/shares`,{headers:{Authorization:`Bearer ${e}`}}).json()}async upsertMeetingUserGrant(e,t,r,n,i){return await this.client.put(`v1/workspaces/${t}/meetings/${r}/shares/users/${n}`,{headers:{Authorization:`Bearer ${e}`},json:{role:i}}).json()}async removeMeetingUserGrant(e,t,r,n){await this.client.delete(`v1/workspaces/${t}/meetings/${r}/shares/users/${n}`,{headers:{Authorization:`Bearer ${e}`}})}async upsertMeetingTeamGrant(e,t,r,n,i){return await this.client.put(`v1/workspaces/${t}/meetings/${r}/shares/teams/${n}`,{headers:{Authorization:`Bearer ${e}`},json:{role:i}}).json()}async removeMeetingTeamGrant(e,t,r,n){await this.client.delete(`v1/workspaces/${t}/meetings/${r}/shares/teams/${n}`,{headers:{Authorization:`Bearer ${e}`}})}async getWorkflows(e,t,r){let n={limit:r?.limit??20};return r?.nextKey&&(n.nextKey=r.nextKey),r?.search&&(n.search=r.search),await this.client.get(`v1/workspaces/${t}/workflows`,{headers:{Authorization:`Bearer ${e}`},searchParams:n}).json()}async getWorkflow(e,t,r){return await this.client.get(`v1/workspaces/${t}/workflows/${r}`,{headers:{Authorization:`Bearer ${e}`}}).json()}async createWorkflow(e,t,r){return await this.client.post(`v1/workspaces/${t}/workflows`,{headers:{Authorization:`Bearer ${e}`},json:r}).json()}async updateWorkflow(e,t,r,n){await this.client.put(`v1/workspaces/${t}/workflows/${r}`,{headers:{Authorization:`Bearer ${e}`},json:n})}async triggerWorkflowRun(e,t,r,n){return await this.client.post(`v1/workspaces/${t}/workflows/${r}/runs`,{headers:{Authorization:`Bearer ${e}`},json:n===void 0?{}:{args:n}}).json()}async getWorkflowRuns(e,t,r,n){let i={limit:n?.limit??20};return n?.nextKey&&(i.nextKey=n.nextKey),await this.client.get(`v1/workspaces/${t}/workflows/${r}/runs`,{headers:{Authorization:`Bearer ${e}`},searchParams:i}).json()}async getWorkflowRun(e,t,r,n){return await this.client.get(`v1/workspaces/${t}/workflows/${r}/runs/${n}`,{headers:{Authorization:`Bearer ${e}`}}).json()}async getWorkflowGrants(e,t,r){return await this.client.get(`v1/workspaces/${t}/workflows/${r}/grants`,{headers:{Authorization:`Bearer ${e}`}}).json()}async upsertWorkflowGrant(e,t,r,n,i){return await this.client.put(`v1/workspaces/${t}/workflows/${r}/grants/${n}`,{headers:{Authorization:`Bearer ${e}`},json:{role:i}}).json()}async removeWorkflowGrant(e,t,r,n){await this.client.delete(`v1/workspaces/${t}/workflows/${r}/grants/${n}`,{headers:{Authorization:`Bearer ${e}`}})}async getNotifications(e,t,r){let n={limit:r?.limit??20};return r?.tab&&(n.tab=r.tab),r?.eventType&&(n.eventType=r.eventType),r?.cursor&&(n.cursor=r.cursor),await this.client.get(`v1/workspaces/${t}/notifications`,{headers:{Authorization:`Bearer ${e}`},searchParams:n}).json()}async getNotificationUnreadCount(e,t){return await this.client.get(`v1/workspaces/${t}/notifications/unreadCount`,{headers:{Authorization:`Bearer ${e}`}}).json()}async markNotificationRead(e,t,r){await this.client.post(`v1/workspaces/${t}/notifications/${r}/read`,{headers:{Authorization:`Bearer ${e}`}})}async markAllNotificationsRead(e,t){await this.client.post(`v1/workspaces/${t}/notifications/readAll`,{headers:{Authorization:`Bearer ${e}`}})}async getRuntimeConfig(){if(this.runtimeConfigCache)return this.runtimeConfigCache;let e=await this.client.get("v1/runtimeConfig").json();return this.runtimeConfigCache=e,e}async getModels(e,t){return await this.client.get(`v1/workspaces/${t}/models`,{headers:{Authorization:`Bearer ${e}`}}).json()}async getModelTiers(e,t){return await this.client.get(`v1/workspaces/${t}/modelTiers`,{headers:{Authorization:`Bearer ${e}`}}).json()}async listSelectableModels(e,t){let{deploymentMode:r}=await this.getRuntimeConfig(),{models:n}=r==="saas"?await this.getModelTiers(e,t):await this.getModels(e,t);return{models:n.filter(i=>i.enabled!==!1)}}async getConnectors(e,t,r){let n={limit:r?.limit??100,connectionStatus:r?.connectionStatus??"connected"};return r?.search&&(n.search=r.search),r?.nextKey&&(n.nextKey=r.nextKey),await this.client.get(`v1/workspaces/${t}/availableConnectors`,{headers:{Authorization:`Bearer ${e}`},searchParams:n}).json()}async getConnectorTools(e,t,r){return this.client.get(`v1/workspaces/${t}/connectors/${r}/tools`,{headers:{Authorization:`Bearer ${e}`}}).json()}async connectConnectorToken(e,t,r,n){await this.client.put(`v1/workspaces/${t}/connectors/${r}/token`,{headers:{Authorization:`Bearer ${e}`},json:n})}async getConnectorAuthUrl(e,t,r){return this.client.post(`v1/workspaces/${t}/connectors/${r}/authUrl`,{headers:{Authorization:`Bearer ${e}`},json:{}}).json()}async disconnectConnector(e,t,r){await this.client.delete(`v1/workspaces/${t}/connectors/${r}/token`,{headers:{Authorization:`Bearer ${e}`}})}async getTasks(e,t,r=20){return await this.client.get(`v1/workspaces/${t}/tasks`,{headers:{Authorization:`Bearer ${e}`},searchParams:{limit:r}}).json()}async searchTasks(e,t,r,n){let i={q:r,limit:n?.limit??20};return n?.nextKey&&(i.nextKey=n.nextKey),await this.client.get(`v1/workspaces/${t}/tasks/search`,{headers:{Authorization:`Bearer ${e}`},searchParams:i}).json()}async getMessages(e,t,r,n=50){return await this.client.get(`v1/workspaces/${t}/tasks/${r}/messages`,{headers:{Authorization:`Bearer ${e}`},searchParams:{limit:n}}).json()}async getAgent(e,t,r){return await this.client.get(`v1/workspaces/${t}/agents/${r}`,{headers:{Authorization:`Bearer ${e}`}}).json()}async listAvailableSkills(e,t,r){return await this.client.get(`v1/workspaces/${t}/availableSkills`,{headers:{Authorization:`Bearer ${e}`},searchParams:{createdBy:r?.createdBy,nextKey:r?.nextKey,limit:r?.limit??20}}).json()}async uploadSkill(e,t,r){return await this.client.post(`v1/workspaces/${t}/skills`,{headers:{Authorization:`Bearer ${e}`},body:r}).json()}async deleteSkill(e,t,r){await this.client.delete(`v1/workspaces/${t}/skills/${r}`,{headers:{Authorization:`Bearer ${e}`}})}async updateSkillPreference(e,t,r,n){return await this.client.patch(`v1/workspaces/${t}/skills/${r}/preference`,{headers:{Authorization:`Bearer ${e}`},json:{isEnabled:n}}).json()}async getSkillVersions(e,t,r){return await this.client.get(`v1/workspaces/${t}/skills/${r}/versions`,{headers:{Authorization:`Bearer ${e}`}}).json()}async getSkillGrants(e,t,r){return await this.client.get(`v1/workspaces/${t}/skills/${r}/grants`,{headers:{Authorization:`Bearer ${e}`}}).json()}async upsertSkillGrant(e,t,r,n,i){return await this.client.put(`v1/workspaces/${t}/skills/${r}/grants/${n}`,{headers:{Authorization:`Bearer ${e}`},json:{role:i}}).json()}async removeSkillGrant(e,t,r,n){await this.client.delete(`v1/workspaces/${t}/skills/${r}/grants/${n}`,{headers:{Authorization:`Bearer ${e}`}})}async downloadSkillCurrent(e,t,r){return await this.client.get(`v1/workspaces/${t}/skills/${r}/download`,{headers:{Authorization:`Bearer ${e}`}}).json()}async task(e,t,r){try{let n=await this.client.post(`v1/workspaces/${t}/tasks`,{headers:{Authorization:`Bearer ${e}`},json:r,timeout:6e4,throwHttpErrors:!1});if(!n.ok){let o=await n.text();throw new Error(`Task API failed (${n.status}): ${o}`)}let i=await n.json();return i.noop||!i.streamId?new Response(`data: [DONE]
|
|
3
|
-
|
|
4
|
-
`,{headers:{"Content-Type":"text/event-stream"}}):await this.taskStream(e,t,i.taskId)}catch(n){throw n instanceof xe?new TypeError("Request timed out. Please check your connection and try again.",{cause:n}):n}}async taskStream(e,t,r){let n=await this.client.get(`v1/workspaces/${t}/tasks/${r}/stream`,{headers:{Authorization:`Bearer ${e}`,Accept:"text/event-stream"},timeout:!1,throwHttpErrors:!1});if(!n.ok){let i=await n.text();throw new Error(`Task stream failed (${n.status}): ${i}`)}return n}async getBudget(e,t){return await this.client.get(`v1/workspaces/${t}/budget`,{headers:{Authorization:`Bearer ${e}`}}).json()}async updateBudget(e,t,r){await this.client.put(`v1/workspaces/${t}/budget`,{headers:{Authorization:`Bearer ${e}`},json:{budget:r}})}async getMonthlyUsages(e,t,r){return await this.client.get(`v1/workspaces/${t}/monthlyUsages`,{headers:{Authorization:`Bearer ${e}`},searchParams:{nextKey:r?.nextKey,limit:r?.limit??20}}).json()}async getBillingOverview(e,t){return await this.client.get(`v1/workspaces/${t}/billing/overview`,{headers:{Authorization:`Bearer ${e}`}}).json()}async getBillingInvoices(e,t,r){let n={limit:r?.limit??20};return r?.nextKey&&(n.nextKey=r.nextKey),await this.client.get(`v1/workspaces/${t}/billing/invoices`,{headers:{Authorization:`Bearer ${e}`},searchParams:n}).json()}async getUsageOverview(e,t){return await this.client.get(`v1/workspaces/${t}/usage/overview`,{headers:{Authorization:`Bearer ${e}`}}).json()}async getUsageMe(e,t){return await this.client.get(`v1/workspaces/${t}/usage/me`,{headers:{Authorization:`Bearer ${e}`}}).json()}async getUsageConsumptions(e,t,r){let n={limit:r?.limit??20,offset:r?.offset??0};return r?.periodStart&&(n.periodStart=r.periodStart),await this.client.get(`v1/workspaces/${t}/usage/consumptions`,{headers:{Authorization:`Bearer ${e}`},searchParams:n}).json()}async exportUsageCsv(e,t,r){let n={};return r&&(n.periodStart=r),await this.client.get(`v1/workspaces/${t}/usage/export`,{headers:{Authorization:`Bearer ${e}`},searchParams:n}).text()}async createTaskShare(e,t,r,n="public"){try{return await this.client.post(`v1/workspaces/${t}/tasks/${r}/shares`,{headers:{Authorization:`Bearer ${e}`},json:{visibility:n}}).json()}catch(i){if(oe(i)&&i.response.status===403){let o=await i.response.json().catch(()=>null);if(o?.code==="sharing_disabled")throw new Error("Sharing is turned off for this workspace by an admin.",{cause:i});if(o?.code==="share_visibility_not_allowed")throw new Error("Public sharing is turned off for this workspace by an admin.",{cause:i})}throw i}}async getSharedTask(e,t){let r={};return t&&(r.Authorization=`Bearer ${t}`),await this.client.get(`v1/shares/${e}`,{headers:r}).json()}async getSharedMessages(e,t=50,r){let n={};return r&&(n.Authorization=`Bearer ${r}`),await this.client.get(`v1/shares/${e}/messages`,{headers:n,searchParams:{limit:t}}).json()}async deleteTask(e,t,r){await this.client.delete(`v1/workspaces/${t}/tasks/${r}`,{headers:{Authorization:`Bearer ${e}`}})}async getModelProviders(e,t){return await this.client.get(`v1/workspaces/${t}/modelProviders`,{headers:{Authorization:`Bearer ${e}`}}).json()}async uploadFile(e,t,r,n){let i=new FormData,o=new Blob([r.buffer],{type:r.mimeType});return i.append("file",o,r.filename),i.append("modelProviderId",n),await this.client.post(`v1/workspaces/${t}/files`,{headers:{Authorization:`Bearer ${e}`},body:i,timeout:12e4}).json()}async getCalendarAccounts(e,t){return await this.client.get(`v1/workspaces/${t}/calendar/accounts`,{headers:{Authorization:`Bearer ${e}`}}).json()}async getSchedules(e,t,r){let n={limit:r?.limit??20};return r?.nextKey&&(n.nextKey=r.nextKey),r?.search&&(n.search=r.search),await this.client.get(`v1/workspaces/${t}/schedules`,{headers:{Authorization:`Bearer ${e}`},searchParams:n}).json()}async getSchedule(e,t,r){return await this.client.get(`v1/workspaces/${t}/schedules/${r}`,{headers:{Authorization:`Bearer ${e}`}}).json()}async createSchedule(e,t,r){return await this.client.post(`v1/workspaces/${t}/schedules`,{headers:{Authorization:`Bearer ${e}`},json:r}).json()}async updateSchedule(e,t,r,n){await this.client.put(`v1/workspaces/${t}/schedules/${r}`,{headers:{Authorization:`Bearer ${e}`},json:n})}async deleteSchedule(e,t,r){await this.client.delete(`v1/workspaces/${t}/schedules/${r}`,{headers:{Authorization:`Bearer ${e}`}})}async activateSchedule(e,t,r){await this.client.post(`v1/workspaces/${t}/schedules/${r}/activate`,{headers:{Authorization:`Bearer ${e}`}})}async deactivateSchedule(e,t,r){await this.client.post(`v1/workspaces/${t}/schedules/${r}/deactivate`,{headers:{Authorization:`Bearer ${e}`}})}async runScheduleNow(e,t,r){return await this.client.post(`v1/workspaces/${t}/schedules/${r}/run`,{headers:{Authorization:`Bearer ${e}`}}).json()}async getScheduleRuns(e,t,r,n){let i={limit:n?.limit??20};return n?.nextKey&&(i.nextKey=n.nextKey),await this.client.get(`v1/workspaces/${t}/schedules/${r}/runs`,{headers:{Authorization:`Bearer ${e}`},searchParams:i}).json()}async listRecordings(e,t,r){let n={limit:r?.limit??20};return r?.nextKey&&(n.nextKey=r.nextKey),r?.search&&(n.search=r.search),this.client.get(`v1/workspaces/${t}/recordings`,{headers:{Authorization:`Bearer ${e}`},searchParams:n}).json()}async importRecordingMedia(e,t,r){return this.client.post(`v1/workspaces/${t}/recordings/import/media`,{headers:{Authorization:`Bearer ${e}`},json:r}).json()}async previewRecordingMedia(e,t,r){let n={url:r};return this.client.get(`v1/workspaces/${t}/recordings/preview/media`,{headers:{Authorization:`Bearer ${e}`},searchParams:n}).json()}async getRecordingAudioUrl(e,t,r){return this.client.get(`v1/workspaces/${t}/recordings/${r}/audioUrl`,{headers:{Authorization:`Bearer ${e}`}}).json()}async retryRecording(e,t,r){return this.client.post(`v1/workspaces/${t}/recordings/${r}/retry`,{headers:{Authorization:`Bearer ${e}`}}).json()}async deleteRecording(e,t,r){await this.client.delete(`v1/workspaces/${t}/recordings/${r}`,{headers:{Authorization:`Bearer ${e}`}})}async searchMarketplace(e){let t={};return e?.type&&(t.type=e.type),e?.tag&&(t.tag=e.tag),e?.limit&&(t.limit=e.limit),e?.cursor&&(t.cursor=e.cursor),this.client.get("v1/marketplace/resources",{searchParams:t}).json()}async getMarketplaceAgent(e){return this.client.get(`v1/marketplace/agents/${encodeURIComponent(e)}`).json()}async getMarketplaceSkill(e){return this.client.get(`v1/marketplace/skills/${encodeURIComponent(e)}`).json()}async listMarketplaceRoles(){return this.client.get("v1/marketplace/roles").json()}async installMarketplaceResource(e,t,r,n){return this.client.post(`v1/workspaces/${t}/marketplace/${r}s/${encodeURIComponent(n)}/install`,{headers:{Authorization:`Bearer ${e}`},json:{}}).json()}static async getAuthenticatedClient(e){let t=await h.getAll(e);return t?{client:new s(void 0,e),accessToken:t.accessToken,workspaceId:t.workspaceId??null}:null}};function H(){return process.env.ENTRYDESK_SANDBOX==="true"}function I(){if(!H())return null;let s=process.env.ENTRYDESK_SANDBOX_ACCESS_TOKEN?.trim(),e=process.env.ENTRYDESK_SANDBOX_WORKSPACE_ID?.trim();if(!s||!e){let t=[];throw s||t.push("ENTRYDESK_SANDBOX_ACCESS_TOKEN"),e||t.push("ENTRYDESK_SANDBOX_WORKSPACE_ID"),new Error(`Sandbox mode enabled but missing credentials: ${t.join(", ")}`)}return{accessToken:s,workspaceId:e}}function ae(){return!!process.env.ENTRYDESK_TOKEN?.trim()}function Y(){let s=process.env.ENTRYDESK_TOKEN?.trim();if(!s)return null;let e=process.env.ENTRYDESK_WORKSPACE_ID?.trim();if(!e)throw new Error("ENTRYDESK_TOKEN is set but ENTRYDESK_WORKSPACE_ID is missing. Both are required for PAT authentication.");return{accessToken:s,workspaceId:e}}var V="sandbox environment (ENTRYDESK_SANDBOX)",Be="personal access token (ENTRYDESK_TOKEN)";function vt(){let s=I();if(s)return{authSource:"sandbox-env",label:V,workspaceId:s.workspaceId};let e=Y();return e?{authSource:"pat-env",label:Be,workspaceId:e.workspaceId}:null}import{execFile as Me}from"child_process";import{setTimeout as Ue}from"timers/promises";import{decodeJwt as Ke}from"jose";import Ie,{HTTPError as ce,isHTTPError as De}from"ky";function C(s){if(s===null||typeof s!="object")return{error:""};let e=s;return{code:typeof e.code=="string"?e.code:void 0,error:typeof e.error=="string"?e.error:""}}var _e=/^[a-z0-9_.-]{1,64}$/iu;function q(s){let e=C(s).code;return e&&_e.test(e)?e:void 0}function J(s){return[...s].filter(e=>{let t=e.codePointAt(0)??0,r=t<=31,n=t===127,i=t>=128&&t<=159;return!r&&!n&&!i}).join("")}var x="entrydesk-cli",je="offline_access workspaces:read tasks:read tasks:write tasks:delete agents:read agents:write connectors:read connectors:write tools:read tools:execute skills:read skills:write meetings:read meetings:write workflows:read workflows:write notifications:read notifications:write publishes:read publishes:write calendar:read calendar:write schedules:read schedules:write user:read user:write";function ze(s,e){let t=new Set(e.split(/[\s,]+/).filter(Boolean)),r=s.split(" ").filter(Boolean);return{rejected:r.filter(n=>t.has(n)),remaining:r.filter(n=>!t.has(n))}}async function Oe(s,e,t){try{return await s.post("v1/oauth/device/code",{json:{client_id:x,scope:e}}).json()}catch(r){if(!(r instanceof ce))throw r;let{code:n,error:i}=C(r.data);if(n==="invalid_scope"){let{rejected:o,remaining:d}=ze(e,i);if(o.length>0&&d.length>0)return t?.onWarning?.(`This server doesn't support these scopes: ${o.join(", ")}. Continuing without them \u2014 commands that need them may be unavailable.`),s.post("v1/oauth/device/code",{json:{client_id:x,scope:d.join(" ")}}).json()}throw new Error(i?`Failed to request device code: ${i}`:"Failed to request device code",{cause:r})}}var Le=new Set(["localhost","0.0.0.0","::","::1"]);function Fe(s){let e=s.replace(/^\[|\]$/gu,"").replace(/\.$/u,"").toLowerCase(),t=e.replace(/^::ffff:/u,"");return Le.has(e)||/^127(?:\.\d{1,3}){3}$/u.test(t)||e.startsWith("::ffff:7f")}var Ne=/^[A-Za-z0-9\-._~/]*$/u,We=/^[A-Za-z0-9-]{1,64}$/u;function Ge(s,e,t){let r=null;if(s)try{let n=new URL(s);(n.protocol==="https:"||n.protocol==="http:")&&n.username===""&&n.password===""&&n.hostname!==""&&!Fe(n.hostname)&&Ne.test(n.pathname)&&(r=new URL(n.pathname,n.origin))}catch{}return r??=new URL("/oauth/device",e),We.test(t)&&r.searchParams.set("user_code",t),r.toString()}function He(s){return new Promise((e,t)=>{let r=process.platform,n,i;switch(r){case"darwin":n="open",i=[s];break;case"win32":n="cmd",i=["/c","start","",s];break;default:n="xdg-open",i=[s];break}Me(n,i,o=>{o?t(new Error(`Failed to open browser. Please manually visit: ${s}`,{cause:o})):e()})})}async function bt(s){let e=S(),t=se(),r=U(),n=process.env.NODE_TLS_REJECT_UNAUTHORIZED;r.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=Ie.create({baseUrl:e.replace(/\/?$/,"/"),timeout:3e4,hooks:{beforeError:[({error:c})=>(De(c)&&(c.request.headers.delete("authorization"),c.request.headers.delete("Authorization")),c)]}}),o;try{o=await Oe(i,je,s)}catch(c){let k=c instanceof Error?c:new Error("Failed to request device code");throw s?.onError?.(k),k}let{device_code:d,user_code:u,expires_in:pe,interval:he}=o,te=Ge(o.verification_uri,t,u);s?.onDeviceCodeReceived?.(u,te),s?.onBrowserOpening?.();try{await He(te)}catch(c){process.env.DEBUG&&console.error("[DEBUG] Failed to open browser:",c)}s?.onWaitingForAuthorization?.();let re=Math.max(he,5)*1e3,fe=Date.now()+pe*1e3;for(;Date.now()<fe;){await Ue(re);try{let c=await i.post("v1/oauth/token",{json:{grant_type:"urn:ietf:params:oauth:grant-type:device_code",device_code:d,client_id:x}}).json();s?.onAuthorized?.();let k={};try{k=Ke(c.access_token)}catch{}return{accessToken:c.access_token,refreshToken:c.refresh_token??void 0,email:k.email||"",scopes:c.scope.split(" ").filter(j=>j.length>0)}}catch(c){if(c instanceof ce){let{code:j,error:ye}=C(c.data),z=j||ye;if(!z)continue;switch(z){case"authorization_pending":continue;case"slow_down":re+=5e3;continue;case"access_denied":throw new Error("Authorization denied by user",{cause:c});case"expired_token":throw new Error("Device code expired. Please try again.",{cause:c});default:throw new Error(`Authorization failed: ${z||"Unknown error"}`,{cause:c})}}let k=c instanceof Error?c:new Error("Unknown error during authorization");throw s?.onError?.(k),k}}throw new Error("Device code expired. Please try again.")}finally{n===void 0?delete process.env.NODE_TLS_REJECT_UNAUTHORIZED:process.env.NODE_TLS_REJECT_UNAUTHORIZED=n}}function Ve(s){if(s instanceof Ye){let e=s.response.status;return e===400||e===401}return!1}var f=class extends Error{code;constructor(e,t){super(t),this.name="AuthError",this.code=e}};function qe(s){try{let e=s.split(".");if(e.length<2)return null;let t=e[1].replace(/-/g,"+").replace(/_/g,"/"),r=(4-t.length%4)%4,n=t.padEnd(t.length+r,"="),i=Buffer.from(n,"base64").toString("utf8");return JSON.parse(i)}catch{return null}}function Je(s,e=300){let r=qe(s)?.exp;if(typeof r!="number")return!1;let n=Math.floor(Date.now()/1e3);return r-n<=e}async function le(s){let e=s.accessToken;if(!Je(e))return e;if(!s.refreshToken)throw await h.clear(),new f("session-expired","Session expired. Please run `entrydesk login` again.");let t=s.refreshToken;try{let n=await new K().refreshOAuthToken({refreshToken:t,clientId:x}),i=await h.getAll();return i?.accessToken&&i.refreshToken&&i.refreshToken!==t?i.accessToken:(await h.saveAll({...i??s,accessToken:n.access_token,refreshToken:n.refresh_token??i?.refreshToken??t}),n.access_token)}catch(r){if(!Ve(r))throw new f("refresh-failed","Could not refresh your session (auth server unreachable). Please try again.");let n=await h.getAll();if(n?.accessToken&&n.refreshToken&&n.refreshToken!==t)return n.accessToken;throw await h.clear(),new f("session-expired","Session expired. Please run `entrydesk login` again.")}}async function It(){let s=I();if(s)return s.accessToken;let e=await h.getAll();if(!e?.accessToken)throw new f("not-logged-in","Not logged in. Run `entrydesk login` first.");return le(e)}async function Dt(){let s=I();if(s)return{accessToken:s.accessToken,workspaceId:s.workspaceId};let e=Y();if(e)return e;let t=await h.getAll();if(!t?.accessToken)throw new f("not-logged-in","Not logged in. Run `entrydesk login` first.");if(!t.workspaceId)throw new f("no-workspace","No workspace selected. Run `entrydesk workspaces` first.");return{accessToken:await le(t),workspaceId:t.workspaceId}}function Qe(s){let e="";try{e=` by ${S()}`}catch{}let t=q(s.data),r=t?` (server code: ${t})`:"",n;if(t==="missing_token"||t==="bearer_not_supported"){let i='The API did not accept your Authorization header (stripped or refused en route) \u2014 the URL likely points at a browser-facing proxy path (such as a Hub "/api" URL). ';n=process.env.ENTRYDESK_API_URL?i+"It comes from the ENTRYDESK_API_URL environment variable, which overrides profile config \u2014 update or unset ENTRYDESK_API_URL.":i+"Set apiUrl to the API server URL with `entrydesk config set apiUrl <url>`."}else H()?n=`Requests are authenticated via ${V} \u2014 ask the sandbox owner to issue fresh credentials.`:ae()?n="ENTRYDESK_TOKEN is set and takes priority over `entrydesk login` credentials for workspace commands \u2014 unset it or replace it with a valid token; if this command does not use it, run `entrydesk login`.":n="Your session may have expired \u2014 run `entrydesk login`. If this is not the environment you expect, check `entrydesk config get apiUrl`.";return`Not authorized (401)${e}${r}. ${n}`}var y=class extends Error{constructor(t,r=1,n){super(t);this.exitCode=r;this.cause=n;this.name="CLIError"}exitCode;cause};function Wt(s){let e=!!process.env.DEBUG;if(s instanceof y&&(console.error(`Error: ${s.message}`),s.cause&&(console.error(`Cause: ${s.cause.message}`),e&&s.cause.stack&&console.error(s.cause.stack)),process.exit(s.exitCode)),s instanceof f&&(console.error(s.message),e&&s.stack&&console.error(s.stack),process.exit(1)),s instanceof Ze&&(console.error("Request timed out. Please check your connection and try again."),e&&s.stack&&console.error(s.stack),process.exit(1)),s instanceof Xe){let t=s.response.status;if(t===401)console.error(Qe(s));else if(t===403)console.error("Forbidden (403). Your account or token lacks permission for this action. If your token predates a recently added feature, run `entrydesk login` to refresh its scopes; otherwise you may lack permission in this workspace.");else{let r=C(s.data),n=q(s.data),i=n?` (server code: ${n})`:"",o=J(r.error),d=J(s.response.statusText);console.error(`Request failed (${t}): ${o||d}${i}`)}e&&s.stack&&console.error(s.stack),process.exit(1)}s instanceof Error&&(console.error(`Unexpected error: ${s.message}`),e&&s.stack&&console.error(s.stack),process.exit(1)),console.error("An unknown error occurred"),process.exit(1)}var P="default",tt=/^[A-Za-z0-9_-]+$/,X=null;function Q(){return E.join(et.homedir(),".entrydesk")}function de(){return E.join(Q(),"profiles")}function ue(){return E.join(Q(),"profiles.json")}function D(s){return E.join(de(),s)}function ee(s){if(m.existsSync(s))try{m.chmodSync(s,448)}catch{}else m.mkdirSync(s,{mode:448,recursive:!0})}function rt(){ee(Q())}function Z(){ee(de())}function st(){let s=ue();try{if(!m.existsSync(s))return null;let e=m.readFileSync(s,"utf-8");return JSON.parse(e)}catch{return null}}function T(s){rt();let e=ue();m.writeFileSync(e,JSON.stringify(s,null,2),{mode:384});try{m.chmodSync(e,384)}catch{}}function nt(s){let e=s.profiles?.length?[...new Set(s.profiles)]:[],t=s.currentProfile&&e.includes(s.currentProfile)?s.currentProfile:e[0]||P;return e.length===0&&e.push(P),e.includes(t)||e.unshift(t),{currentProfile:t,profiles:e}}function _(s){Z(),ee(D(s))}function R(){let s=st();if(!s){let t={currentProfile:P,profiles:[P]};return T(t),Z(),_(P),t}let e=nt(s);return(e.currentProfile!==s.currentProfile||e.profiles.length!==s.profiles.length)&&T(e),Z(),e}function A(s){if(!s)throw new y("Profile name is required.");if(!tt.test(s))throw new y("Invalid profile name. Use letters, numbers, dash, or underscore.")}function B(s,e){if(!s.profiles.includes(e))throw new y(`Profile not found: ${e}`)}function ge(s,e){if(s.profiles.includes(e))throw new y(`Profile already exists: ${e}`)}var a={DEFAULT_PROFILE:P,setOverrideProfile(s){X=s},getOverrideProfile(){return X},getProfileDir(s){return D(s)},getProfileConfigFile(s){return E.join(a.getProfileDir(s),"config.json")},getProfileCredentialsFile(s){return E.join(a.getProfileDir(s),"credentials.json")},getProfileNames(){return[...R().profiles]},getProfileCount(){return a.getProfileNames().length},getCurrentProfileName(){return R().currentProfile},getEffectiveProfileName(s){let e=R(),t=s||X||e.currentProfile;return A(t),B(e,t),t},ensureProfileExists(s){let e=R();A(s),B(e,s)},createProfile(s){A(s);let e=R();ge(e,s);let t={currentProfile:e.currentProfile,profiles:[...e.profiles,s]};T(t),_(s)},deleteProfile(s){A(s);let e=R();if(B(e,s),e.profiles.length===1)throw new y("Cannot delete the last profile.");let t=e.profiles.filter(i=>i!==s),r=e.currentProfile;r===s&&(r=t.includes(P)?P:t[0]),T({currentProfile:r,profiles:t});try{m.rmSync(a.getProfileDir(s),{recursive:!0,force:!0})}catch{}return{currentProfile:r}},renameProfile(s,e){A(s),A(e);let t=R();B(t,s),ge(t,e);let r=D(s),n=D(e);if(m.existsSync(r))try{m.renameSync(r,n)}catch(u){throw new y("Failed to rename profile directory.",1,u)}else _(e);let i=t.profiles.map(u=>u===s?e:u),o=t.currentProfile===s?e:t.currentProfile;return T({currentProfile:o,profiles:i}),{currentProfile:o}},setCurrentProfile(s){A(s);let e=R();B(e,s);let t={currentProfile:s,profiles:e.profiles};T(t),_(s)},ensureProfileDir:_};export{a,O as b,L as c,S as d,se as e,h as f,K as g,I as h,ae as i,Y as j,V as k,vt as l,J as m,x as n,bt as o,f as p,Je as q,le as r,It as s,Dt as t,y as u,Wt as v};
|
package/dist/chunk-NOSHH4TO.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
function A(e){return e!=null}function m(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(f){return Object.getOwnPropertyDescriptor(e,f).enumerable})),r.push.apply(r,o)}return r}function d(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?m(Object(r),!0).forEach(function(o){b(e,o,r[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):m(Object(r)).forEach(function(o){Object.defineProperty(e,o,Object.getOwnPropertyDescriptor(r,o))})}return e}function b(e,t,r){return t=O(t),t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function O(e){var t=w(e,"string");return typeof t=="symbol"?t:String(t)}function w(e,t){if(typeof e!="object"||e===null)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var o=r.call(e,t||"default");if(typeof o!="object")return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}var v=x({});function x(e){return t.withOptions=r=>x(d(d({},e),r)),t;function t(r,...o){let f=typeof r=="string"?[r]:r.raw,{alignValues:g=!1,escapeSpecialCharacters:l=Array.isArray(r),trimWhitespace:h=!0}=e,c="";for(let i=0;i<f.length;i++){let n=f[i];if(l&&(n=n.replace(/\\\n[ \t]*/g,"").replace(/\\`/g,"`").replace(/\\\$/g,"$").replace(/\\\{/g,"{")),c+=n,i<o.length){let p=g?P(o[i],c):o[i];c+=p}}let s=c.split(`
|
|
3
|
-
`),a=null;for(let i of s){let n=i.match(/^(\s+)\S+/);if(n){let p=n[1].length;a?a=Math.min(a,p):a=p}}if(a!==null){let i=a;c=s.map(n=>n[0]===" "||n[0]===" "?n.slice(i):n).join(`
|
|
4
|
-
`)}return h&&(c=c.trim()),l&&(c=c.replace(/\\n/g,`
|
|
5
|
-
`).replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\v/g,"\v").replace(/\\b/g,"\b").replace(/\\f/g,"\f").replace(/\\0/g,"\0").replace(/\\x([\da-fA-F]{2})/g,(i,n)=>String.fromCharCode(parseInt(n,16))).replace(/\\u\{([\da-fA-F]{1,6})\}/g,(i,n)=>String.fromCodePoint(parseInt(n,16))).replace(/\\u([\da-fA-F]{4})/g,(i,n)=>String.fromCharCode(parseInt(n,16)))),typeof Bun<"u"&&(c=c.replace(/\\u(?:\{([\da-fA-F]{1,6})\}|([\da-fA-F]{4}))/g,(i,n,p)=>{var u;let y=(u=n??p)!==null&&u!==void 0?u:"";return String.fromCodePoint(parseInt(y,16))})),c}}function P(e,t){if(typeof e!="string"||!e.includes(`
|
|
6
|
-
`))return e;let o=t.slice(t.lastIndexOf(`
|
|
7
|
-
`)+1).match(/^(\s+)/);if(o){let f=o[1];return e.replace(/\n/g,`
|
|
8
|
-
${f}`)}return e}var R=new TextEncoder,G=new TextDecoder("utf-8",{fatal:!1});export{A as a};
|
package/dist/mcp-EON5KZPT.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import{c as m,f as u,q as y,r as f,t as w}from"./chunk-GN6HSCLY.js";import"./chunk-ZIAOI7B2.js";import h from"http";import{stderr as T}from"process";import{Client as k}from"@modelcontextprotocol/sdk/client/index.js";import{StreamableHTTPClientTransport as v}from"@modelcontextprotocol/sdk/client/streamableHttp.js";import{Server as C}from"@modelcontextprotocol/sdk/server/index.js";import{StdioServerTransport as P}from"@modelcontextprotocol/sdk/server/stdio.js";import{StreamableHTTPServerTransport as A}from"@modelcontextprotocol/sdk/server/streamableHttp.js";import{CallToolRequestSchema as O,ListToolsRequestSchema as E}from"@modelcontextprotocol/sdk/types.js";function a(c){T.write(`${c}
|
|
3
|
-
`)}async function g(c,e,o){let r=new k({name:"entrydesk-cli-proxy",version:"1.0.0"}),i=new URL(`${c}/v1/workspaces/${o}/mcp`),t=new v(i,{requestInit:{headers:{Authorization:`Bearer ${e}`}}});return await r.connect(t),r}function S(c){let e=new C({name:"entrydesk-cli",version:"1.0.0"},{capabilities:{tools:{}}});return e.setRequestHandler(E,async()=>({tools:(await(await c()).listTools()).tools})),e.setRequestHandler(O,async o=>{let{name:r,arguments:i}=o.params,n=await(await c()).callTool({name:r,arguments:i}),l=Array.isArray(n.content)?[...n.content]:[];return n.structuredContent&&l.push({type:"text",text:JSON.stringify(n.structuredContent,null,2)}),{content:l,structuredContent:n.structuredContent,isError:n.isError}}),e}async function H(c,e,o){let r=h.createServer(async(i,t)=>{if(i.method==="OPTIONS"){t.setHeader("Access-Control-Allow-Origin","*"),t.setHeader("Access-Control-Allow-Methods","GET, POST, DELETE, OPTIONS"),t.setHeader("Access-Control-Allow-Headers","Content-Type, Accept"),t.writeHead(204),t.end();return}if(i.url!=="/mcp"){t.writeHead(404,{"Content-Type":"application/json"}),t.end(JSON.stringify({error:"Not found"}));return}let n=S(c),l=new A({sessionIdGenerator:void 0});if(t.setHeader("Access-Control-Allow-Origin","*"),t.on("close",()=>{l.close(),n.close()}),await n.connect(l),i.method==="POST"){let p="";i.on("data",s=>{p+=s.toString()}),i.on("end",async()=>{try{let s=JSON.parse(p);await l.handleRequest(i,t,s)}catch{t.writeHead(400,{"Content-Type":"application/json"}),t.end(JSON.stringify({error:"Invalid JSON"}))}})}else await l.handleRequest(i,t)});r.listen(o,()=>{a(`EntryDesk MCP server running at http://localhost:${o}/mcp`),a("Press Ctrl+C to stop")}),process.on("SIGINT",async()=>{a(`
|
|
4
|
-
Shutting down...`),r.close(),await e(),process.exit(0)}),process.on("SIGTERM",async()=>{r.close(),await e(),process.exit(0)})}async function x(c,e){let o=S(c),r=new P;r.onclose=async()=>{await e()},await o.connect(r)}var I={mode:"stdio"};async function B(c=I){process.on("unhandledRejection",e=>{console.error("[entrydesk-mcp] Unhandled rejection:",e)}),process.on("uncaughtException",e=>{console.error("[entrydesk-mcp] Uncaught exception:",e)});try{a("[entrydesk-mcp] Starting MCP server...");let e,o;try{let s=await w();e=s.accessToken,o=s.workspaceId}catch(s){let d=s instanceof Error?s.message:"Authentication failed";console.error(d),process.exit(1)}let{apiUrl:r,mcp:i}=m();a(`[entrydesk-mcp] Connecting to ${r}...`),a(`[entrydesk-mcp] Workspace: ${o}`);let t=await g(r,e,o);a("[entrydesk-mcp] Connected to EntryDesk API");let n=null,l=async()=>y(e)?n||(n=(async()=>{a("[entrydesk-mcp] Token expiring soon, refreshing...");let s=await u.getAll();if(!s?.accessToken)throw new Error("Not logged in. Please run `entrydesk login` again.");let d=await f(s);if(d!==e){e=d;try{await t.close()}catch{}t=await g(r,e,o),a("[entrydesk-mcp] Token refreshed, reconnected")}return t})().finally(()=>{n=null}),n):t,p=async()=>{try{await t.close()}catch{}};if(c.mode==="http"){let s=c.port??i.httpPort;await H(l,p,s)}else a("[entrydesk-mcp] Starting stdio server..."),await x(l,p),a("[entrydesk-mcp] Stdio server started")}catch(e){console.error("[entrydesk-mcp] Fatal error:",e),process.exit(1)}}export{B as startMcpServer};
|