@entrydesk/cli 1.26.0 → 1.27.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-BPEYRMJS.js → agents-ZOLKUK3V.js} +1 -1
- package/dist/{billing-ZIIVREJT.js → billing-EXNUZ27V.js} +1 -1
- package/dist/{budget-GOLUDBCL.js → budget-GP7TPIHT.js} +1 -1
- package/dist/chunk-B5EWO4CJ.js +91 -0
- package/dist/chunk-EH2LVJZD.js +4 -0
- package/dist/{chunk-HDVXCFOU.js → chunk-JMRVTRPY.js} +1 -1
- package/dist/chunk-KBW7PPBV.js +2 -0
- package/dist/chunk-SVE74GZ2.js +8 -0
- package/dist/{config-4IUXVJTP.js → config-OKYEHGIF.js} +1 -1
- package/dist/{config-help-VOALBZOV.js → config-help-IKI7XAH3.js} +1 -1
- package/dist/{connectors-CSQK22LM.js → connectors-RWQYKGOG.js} +1 -1
- package/dist/{help-4WGGQ6JC.js → help-TFK3BT5B.js} +1 -1
- package/dist/index.js +1 -1
- package/dist/login-DQELHKE3.js +2 -0
- package/dist/{logout-ADWPA2FG.js → logout-V2NLWFNM.js} +1 -1
- package/dist/{marketplace-SQVRI7DY.js → marketplace-XQPPKUMQ.js} +1 -1
- package/dist/{mcp-VDO3M3ZZ.js → mcp-HPPSJT7W.js} +1 -1
- package/dist/{meeting-TW3VZXAR.js → meeting-7SGZAPPL.js} +1 -1
- package/dist/{models-B3KI6HNA.js → models-6W5QSXEO.js} +1 -1
- package/dist/{notifications-W4JZNPP5.js → notifications-OLXBWR6Q.js} +1 -1
- package/dist/{profile-AHVLOC6L.js → profile-QQXHY3ZS.js} +1 -1
- package/dist/{recordings-LYXVL3QK.js → recordings-OI24HIML.js} +9 -9
- package/dist/{schedules-EBOKWL2V.js → schedules-VT37LVQS.js} +1 -1
- package/dist/{skills-KZ3IZP5O.js → skills-JYDSRE6Y.js} +1 -1
- package/dist/status-HY3ZS7SA.js +2 -0
- package/dist/{task-RMAWXZYH.js → task-A4RVTJS5.js} +45 -45
- package/dist/{tasks-IN2ZYMSB.js → tasks-VSKYJMRE.js} +1 -1
- package/dist/{token-FCXXKQBB.js → token-ET5ACXYV.js} +1 -1
- package/dist/token-util-4YZZOFTH.js +2 -0
- package/dist/{tool-MJKJCMYH.js → tool-MJBJPNVQ.js} +1 -1
- package/dist/{update-5CGQNKNF.js → update-YHLJYPBF.js} +1 -1
- package/dist/{usage-46QSLRS2.js → usage-QMI573O7.js} +1 -1
- package/dist/version-4CHSBNSW.js +2 -0
- package/dist/{workflow-BR4CFCAK.js → workflow-QILMEKPR.js} +1 -1
- package/dist/{workspaces-IAN5MGM7.js → workspaces-BTA5XP43.js} +1 -1
- package/package.json +7 -8
- package/dist/chunk-DR3LDSMV.js +0 -4
- package/dist/chunk-EFMVEUKG.js +0 -97
- package/dist/chunk-KURQCTT3.js +0 -2
- package/dist/config-IAKKALFC.js +0 -2
- package/dist/login-EB3L2V2J.js +0 -2
- package/dist/status-L6BVD6XO.js +0 -2
- package/dist/token-util-OEHRI4SO.js +0 -2
- package/dist/version-CE6LTBHK.js +0 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{
|
|
2
|
+
import{g as I,r as A,s as O,u as v}from"./chunk-EH2LVJZD.js";import"./chunk-KBW7PPBV.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 r=n===void 0?{event:t}:{event:t,data:n};process.stdout.write(`${JSON.stringify(r)}
|
|
3
3
|
`)}function S(t){let n=new Date(t),e=new Date().getTime()-n.getTime(),o=Math.floor(e/(1e3*60*60*24));return o===0?n.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit"}):o===1?"Yesterday":o<7?`${o} 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 w(t,n){if(n)return t;let r=t.split(`
|
|
4
4
|
`);if(r.length<=15)return t;let e=r.slice(0,6),o=r.slice(-4),i=r.length-10;return[...e,`... (${i} lines omitted, use --full-output to see all) ...`,...o].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[r,e]of Object.entries(t))typeof e=="string"&&e.length>200?n[r]=e.slice(0,150)+"... (truncated)":typeof e=="object"&&e!==null?n[r]=x(e):n[r]=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 w(String(t),n);let r=n?t:x(t);if("structuredContent"in r&&r.structuredContent){let e=r.structuredContent,o=[];if(e.stdout&&typeof e.stdout=="string"&&e.stdout.trim()&&o.push(e.stdout.trim()),e.stderr&&typeof e.stderr=="string"&&e.stderr.trim()&&o.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&&o.push(`${s.path}: ${s.url}`)}return o.length===0&&o.push(JSON.stringify(e,null,2)),w(o.join(`
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as _,b as k}from"./chunk-
|
|
2
|
+
import{a as _,b as k}from"./chunk-JMRVTRPY.js";import{b as s}from"./chunk-KBW7PPBV.js";var T=s((w,f)=>{var i=Object.defineProperty,l=Object.getOwnPropertyDescriptor,u=Object.getOwnPropertyNames,d=Object.prototype.hasOwnProperty,O=(t,e)=>{for(var o in e)i(t,o,{get:e[o],enumerable:!0})},j=(t,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of u(e))!d.call(t,r)&&r!==o&&i(t,r,{get:()=>e[r],enumerable:!(n=l(e,r))||n.enumerable});return t},v=t=>j(i({},"__esModule",{value:!0}),t),p={};O(p,{refreshToken:()=>y});f.exports=v(p);var c=_(),a=k();async function y(t){let e=t?.project,o=t?.team;if(!e&&!o){let r=(0,a.findProjectInfo)();e=r.projectId,o=r.teamId}else if(!e||!o){let r=(0,a.findProjectInfo)();e=e??r.projectId,o=o??r.teamId}if(!e)throw new c.VercelOidcTokenError("Failed to refresh OIDC token: No project specified. Try re-linking your project with `vc link`");let n=(0,a.loadToken)(e);if(!n||(0,a.isExpired)((0,a.getTokenPayload)(n.token),t?.expirationBufferMs)){let r=await(0,a.getVercelToken)({expirationBufferMs:t?.expirationBufferMs});if(n=await(0,a.getVercelOidcToken)(r,e,o),!n)throw new c.VercelOidcTokenError("Failed to refresh OIDC token");(0,a.saveToken)(n,e)}process.env.VERCEL_OIDC_TOKEN=n.token}});export default T();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{c as S,
|
|
2
|
+
import{c as S,s as _}from"./chunk-EH2LVJZD.js";import"./chunk-KBW7PPBV.js";import R from"fs";import{Client as x}from"@modelcontextprotocol/sdk/client/index.js";import{StreamableHTTPClientTransport as v}from"@modelcontextprotocol/sdk/client/streamableHttp.js";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,I=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 N(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 C(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 N(l,r))return l;for(let c=1;c<=M;c++){let w=d.join(n,`${s}-${c}${i}`);if(await N(w,r))return w}let u=Math.random().toString(36).slice(2,10),a=d.join(n,`${s}-${u}${i}`);return await h.writeFile(a,r,{encoding:"utf8",flag:"wx"}),a}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 k(t,e){let n=Buffer.byteLength(t,"utf8");if(n<=P)return t;let o=t.slice(0,O),i=t.slice(-I),r=((n-O-I)/1024).toFixed(1),l=(n/1024).toFixed(1),u=` ... (skipped ${r}KB of ${l}KB) ...`;return e&&(u+=`
|
|
3
3
|
Tip: jq -r '.structuredContent.field' <file> | grep/head/tail`),`${o}
|
|
4
4
|
|
|
5
5
|
${u}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{
|
|
2
|
+
import{t as l}from"./chunk-EH2LVJZD.js";import"./chunk-KBW7PPBV.js";import{spawn as f}from"child_process";var a="@entrydesk/cli";function g(){return"1.27.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{
|
|
2
|
+
import{g as d,s as y,u as U}from"./chunk-EH2LVJZD.js";import"./chunk-KBW7PPBV.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,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{c as u}from"./chunk-
|
|
2
|
+
import{c as u}from"./chunk-B5EWO4CJ.js";import"./chunk-SVE74GZ2.js";import{g as p,s as g,u as k}from"./chunk-EH2LVJZD.js";import"./chunk-KBW7PPBV.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{
|
|
2
|
+
import{f as a,g as w,r as k}from"./chunk-EH2LVJZD.js";import"./chunk-KBW7PPBV.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.27.0",
|
|
4
4
|
"description": "EntryDesk CLI - Interact with EntryDesk from your terminal",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -12,33 +12,32 @@
|
|
|
12
12
|
],
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@modelcontextprotocol/sdk": "1.29.0",
|
|
15
|
-
"adm-zip": "^0.
|
|
15
|
+
"adm-zip": "^0.6.0",
|
|
16
16
|
"archiver": "^7.0.1",
|
|
17
17
|
"glob": "^13.0.1",
|
|
18
18
|
"ink": "^6.5.1",
|
|
19
19
|
"ink-spinner": "^5.0.0",
|
|
20
20
|
"jose": "^6.2.3",
|
|
21
21
|
"ky": "^2.0.2",
|
|
22
|
-
"react": "^19.2.
|
|
22
|
+
"react": "^19.2.8",
|
|
23
23
|
"uuid": "^14.0.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@lydell/node-pty": "^1.1.0",
|
|
27
27
|
"@testing-library/react": "^16.3.2",
|
|
28
|
-
"@types/adm-zip": "^0.5.8",
|
|
29
28
|
"@types/archiver": "^7.0.0",
|
|
30
29
|
"@types/node": "^24.12.4",
|
|
31
|
-
"@types/react": "^19.2.
|
|
30
|
+
"@types/react": "^19.2.17",
|
|
32
31
|
"@vitest/coverage-v8": "^4.1.6",
|
|
33
32
|
"happy-dom": "^20.8.9",
|
|
34
|
-
"oxlint": "^1.
|
|
33
|
+
"oxlint": "^1.74.0",
|
|
35
34
|
"strip-ansi": "^7.1.2",
|
|
36
35
|
"tsup": "^8.5.0",
|
|
37
36
|
"typescript": "^7.0.2",
|
|
38
37
|
"vitest": "^4.1.6",
|
|
39
|
-
"@gntc/ci": "^0.0.0",
|
|
40
38
|
"@entrydesk/shared": "^0.0.0",
|
|
41
|
-
"@gntc/utils": "^0.0.0"
|
|
39
|
+
"@gntc/utils": "^0.0.0",
|
|
40
|
+
"@gntc/ci": "^0.0.0"
|
|
42
41
|
},
|
|
43
42
|
"optionalDependencies": {
|
|
44
43
|
"keytar": "^7.9.0"
|
package/dist/chunk-DR3LDSMV.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import _ from"fs";import m from"fs";import ze from"os";import C from"path";import{HTTPError as _e,TimeoutError as je}from"ky";import{HTTPError as Me}from"ky";import ve,{TimeoutError as Re,isHTTPError as re}from"ky";import b from"crypto";import p from"fs";import pe from"path";var he="ENTRYDESK_FORCE_FILE_STORAGE",S="EntryDesk CLI",fe="__entrydesk_keychain_test__",ye="profile:",me=".credentials.key",ee={keychain:!1,permissions:!1,corruptFile:!1,windowsFile:!1};function v(s,e){ee[s]||(ee[s]=!0,console.error(e))}function we(){return process.env.ENTRYDESK_DEBUG?.toLowerCase()==="true"}function te(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 ke(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 D(s){return a.getProfileCredentialsFile(s)}var F=class{getKeyFilePath(e){return pe.join(a.getProfileDir(e),me)}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 te(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=D(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=D(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=D(e);try{p.existsSync(t)&&p.unlinkSync(t)}catch{}}},O=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=ke(r)?r:null}catch{this.keytarModule=null}return this.keytarModule}getAccount(e){return`${ye}${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=`${fe}${b.randomBytes(8).toString("hex")}`,r="test";await e.setPassword(S,t,r);let n=await e.getPassword(S,t),i=await e.deletePassword(S,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(S,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(S,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(S,this.getAccount(e))}tryParseKeychainPayload(e){try{let t=JSON.parse(e);return te(t)?t:null}catch{return null}}},N=class{keychainStorage=null;fileStorage=new F;keychainAvailable=null;initPromise=null;shouldForceFileStorage(){return process.env[he]?.toLowerCase()==="true"}async initializeStorage(){if(this.shouldForceFileStorage()){this.keychainAvailable=!1,this.keychainStorage=null;return}try{let e=new O,t=await e.isAvailable();this.keychainAvailable=t,this.keychainStorage=t?e:null}catch{this.keychainAvailable=!1,this.keychainStorage=null}!this.keychainAvailable&&!this.shouldForceFileStorage()&&(we()&&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 N,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 isLoggedIn(s){let e=a.getEffectiveProfileName(s);return(await l.getCredentials(e))?.accessToken!=null}};var B=class s{client;baseUrl;runtimeConfigCache;constructor(e,t){this.baseUrl=e||M(t),K().ignoreSslErrors&&(process.env.NODE_TLS_REJECT_UNAUTHORIZED="0",process.env.DEBUG&&console.log("[DEBUG] ApiClient: SSL certificate validation disabled")),this.client=ve.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})=>(re(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 Re?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(re(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 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 Pe(){return process.env.ENTRYDESK_SANDBOX==="true"}function I(){if(!Pe())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 L(){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}}function nt(){let s=I();if(s)return{authSource:"sandbox-env",label:"sandbox environment (ENTRYDESK_SANDBOX)",workspaceId:s.workspaceId};let e=L();return e?{authSource:"pat-env",label:"personal access token (ENTRYDESK_TOKEN)",workspaceId:e.workspaceId}:null}import{execFile as Ae}from"child_process";import{setTimeout as Se}from"timers/promises";import{decodeJwt as $e}from"jose";import Ce,{HTTPError as ne,isHTTPError as be}from"ky";function G(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 T="entrydesk-cli",Te="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 Ee(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 xe(s,e,t){try{return await s.post("v1/oauth/device/code",{json:{client_id:T,scope:e}}).json()}catch(r){if(!(r instanceof ne))throw r;let{code:n,error:i}=G(r.data);if(n==="invalid_scope"){let{rejected:o,remaining:d}=Ee(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:T,scope:d.join(" ")}}).json()}throw new Error(i?`Failed to request device code: ${i}`:"Failed to request device code",{cause:r})}}function Be(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}Ae(n,i,o=>{o?t(new Error(`Failed to open browser. Please manually visit: ${s}`,{cause:o})):e()})})}async function pt(s){let e=M(),t=se(),r=K(),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=Ce.create({baseUrl:e.replace(/\/?$/,"/"),timeout:3e4,hooks:{beforeError:[({error:c})=>(be(c)&&(c.request.headers.delete("authorization"),c.request.headers.delete("Authorization")),c)]}}),o;try{o=await xe(i,Te,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:le,interval:ge}=o,X=new URL("/oauth/device",t);X.searchParams.set("user_code",u);let Z=X.toString();s?.onDeviceCodeReceived?.(u,Z),s?.onBrowserOpening?.();try{await Be(Z)}catch(c){process.env.DEBUG&&console.error("[DEBUG] Failed to open browser:",c)}s?.onWaitingForAuthorization?.();let Q=Math.max(ge,5)*1e3,de=Date.now()+le*1e3;for(;Date.now()<de;){await Se(Q);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:T}}).json();s?.onAuthorized?.();let k={};try{k=$e(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 ne){let{code:j,error:ue}=G(c.data),z=j||ue;if(!z)continue;switch(z){case"authorization_pending":continue;case"slow_down":Q+=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 Ke(s){if(s instanceof Me){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 Ie(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 Ue(s,e=300){let r=Ie(s)?.exp;if(typeof r!="number")return!1;let n=Math.floor(Date.now()/1e3);return r-n<=e}async function ie(s){let e=s.accessToken;if(!Ue(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 B().refreshOAuthToken({refreshToken:t,clientId:T}),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(!Ke(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 vt(){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 ie(e)}async function Rt(){let s=I();if(s)return{accessToken:s.accessToken,workspaceId:s.workspaceId};let e=L();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 ie(t),workspaceId:t.workspaceId}}var y=class extends Error{constructor(t,r=1,n){super(t);this.exitCode=r;this.cause=n;this.name="CLIError"}exitCode;cause};function $t(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 je&&(console.error("Request timed out. Please check your connection and try again."),e&&s.stack&&console.error(s.stack),process.exit(1)),s instanceof _e){let t=s.response.status;console.error(t===401?"Not authorized (401). Your session may have expired \u2014 run `entrydesk login`.":t===403?"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.":`Request failed (${t}): ${s.response.statusText}`),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",De=/^[A-Za-z0-9_-]+$/,W=null;function Y(){return C.join(ze.homedir(),".entrydesk")}function ae(){return C.join(Y(),"profiles")}function ce(){return C.join(Y(),"profiles.json")}function U(s){return C.join(ae(),s)}function V(s){if(m.existsSync(s))try{m.chmodSync(s,448)}catch{}else m.mkdirSync(s,{mode:448,recursive:!0})}function Fe(){V(Y())}function H(){V(ae())}function Oe(){let s=ce();try{if(!m.existsSync(s))return null;let e=m.readFileSync(s,"utf-8");return JSON.parse(e)}catch{return null}}function $(s){Fe();let e=ce();m.writeFileSync(e,JSON.stringify(s,null,2),{mode:384});try{m.chmodSync(e,384)}catch{}}function Ne(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 x(s){H(),V(U(s))}function R(){let s=Oe();if(!s){let t={currentProfile:P,profiles:[P]};return $(t),H(),x(P),t}let e=Ne(s);return(e.currentProfile!==s.currentProfile||e.profiles.length!==s.profiles.length)&&$(e),H(),e}function A(s){if(!s)throw new y("Profile name is required.");if(!De.test(s))throw new y("Invalid profile name. Use letters, numbers, dash, or underscore.")}function E(s,e){if(!s.profiles.includes(e))throw new y(`Profile not found: ${e}`)}function oe(s,e){if(s.profiles.includes(e))throw new y(`Profile already exists: ${e}`)}var a={DEFAULT_PROFILE:P,setOverrideProfile(s){W=s},getOverrideProfile(){return W},getProfileDir(s){return U(s)},getProfileConfigFile(s){return C.join(a.getProfileDir(s),"config.json")},getProfileCredentialsFile(s){return C.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||W||e.currentProfile;return A(t),E(e,t),t},ensureProfileExists(s){let e=R();A(s),E(e,s)},createProfile(s){A(s);let e=R();oe(e,s);let t={currentProfile:e.currentProfile,profiles:[...e.profiles,s]};$(t),x(s)},deleteProfile(s){A(s);let e=R();if(E(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]),$({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();E(t,s),oe(t,e);let r=U(s),n=U(e);if(m.existsSync(r))try{m.renameSync(r,n)}catch(u){throw new y("Failed to rename profile directory.",1,u)}else x(e);let i=t.profiles.map(u=>u===s?e:u),o=t.currentProfile===s?e:t.currentProfile;return $({currentProfile:o,profiles:i}),{currentProfile:o}},setCurrentProfile(s){A(s);let e=R();E(e,s);let t={currentProfile:s,profiles:e.profiles};$(t),x(s)},ensureProfileDir:x};function Le(s){let e=a.getEffectiveProfileName(s);return a.getProfileConfigFile(e)}function g(s){let e=Le(s);try{if(!_.existsSync(e))return{};let t=_.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);_.writeFileSync(r,JSON.stringify(s,null,2),{mode:384});try{_.chmodSync(r,384)}catch{}}var J={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 Ge="https://api.entrydesk.com",We="https://app.entrydesk.com",He=3100,Ye=300*1e3;function q(s){return{apiUrl:J.getApiUrl(s)||process.env.ENTRYDESK_API_URL||Ge,hubUrl:J.getHubUrl(s)||process.env.ENTRYDESK_HUB_URL||We,mcp:{httpPort:He},auth:{loginTimeout:Ye,ignoreSslErrors:process.env.ENTRYDESK_IGNORE_SSL_ERRORS==="true"||!1}}}function M(s){return q(s).apiUrl}function se(s){return q(s).hubUrl}function K(){return q().auth}export{a,J as b,q as c,M as d,se as e,K as f,h as g,B as h,L as i,nt as j,T as k,pt as l,f as m,Ue as n,ie as o,vt as p,Rt as q,y as r,$t as s};
|