@entrydesk/cli 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,168 @@
1
+ # EntryDesk CLI
2
+
3
+ Command-line client for EntryDesk. Includes interactive chat, tool output
4
+ rendering, and scripting-friendly JSON output.
5
+
6
+ ## Installation
7
+
8
+ ```bash
9
+ # Install the CLI
10
+ npm install -g @entrydesk/cli
11
+
12
+ # Install Playwright globally (required for browser-based login)
13
+ npm install -g playwright
14
+
15
+ # Install Chromium browser and system dependencies
16
+ npx playwright install chromium --with-deps
17
+ ```
18
+
19
+ The Playwright browser is required for the browser-based OAuth login flow (`entrydesk login`).
20
+
21
+ ## Quick Start
22
+
23
+ Build and run from the repo:
24
+
25
+ ```bash
26
+ pnpm --filter @entrydesk/cli build
27
+ pnpm --filter @entrydesk/cli start -- chat -i
28
+ ```
29
+
30
+ Interactive chat is also the default when no command is provided:
31
+
32
+ ```bash
33
+ entrydesk
34
+ ```
35
+
36
+ ## Authentication
37
+
38
+ ```bash
39
+ entrydesk login
40
+ entrydesk login --google
41
+ entrydesk login --email <email> --password <password>
42
+ entrydesk status
43
+ entrydesk logout
44
+ ```
45
+
46
+ ### Credential Storage
47
+
48
+ By default, EntryDesk CLI stores credentials in the OS keychain when available.
49
+ If the keychain is unavailable, it falls back to an encrypted file at
50
+ `~/.entrydesk/profiles/<profile>/credentials.json`.
51
+
52
+ To force file storage (for example, in CI), set
53
+ `ENTRYDESK_FORCE_FILE_STORAGE=true`.
54
+
55
+ Login requires HTTPS by default. For local development against an HTTP API,
56
+ set `ENTRYDESK_ALLOW_INSECURE_LOGIN=true`.
57
+
58
+ ## Chat
59
+
60
+ ```bash
61
+ entrydesk chat -m "Hello" --model <model>
62
+ entrydesk chat -a <agent>
63
+ entrydesk chat -c 1 -m "Follow up"
64
+ entrydesk chat -i
65
+ entrydesk chat -i --web-search # Enable web search
66
+ entrydesk chat -i --no-sandbox # Disable sandbox
67
+ entrydesk chat -i --connectors id1,id2 # Use specific connectors
68
+ ```
69
+
70
+ Piping input and output:
71
+
72
+ ```bash
73
+ echo "Hello" | entrydesk chat --model <model>
74
+ entrydesk chat -m "Hi" --model <model> --plain
75
+ entrydesk chat -m "Hi" --model <model> --output stream-json
76
+ ```
77
+
78
+ ## Browse Resources
79
+
80
+ ```bash
81
+ entrydesk workspaces
82
+ entrydesk workspaces switch <workspaceId> # Switch to a workspace
83
+ entrydesk models
84
+ entrydesk agents
85
+ entrydesk connectors
86
+ entrydesk skills
87
+ entrydesk chats
88
+ entrydesk chats 1
89
+ ```
90
+
91
+ ## MCP Server
92
+
93
+ ```bash
94
+ entrydesk mcp
95
+ entrydesk mcp --http --port 3100
96
+ ```
97
+
98
+ ## Skills Management
99
+
100
+ ```bash
101
+ entrydesk skills # List all available skills
102
+ entrydesk skills --me # List only skills created by you
103
+ entrydesk skills upload my-skill.zip # Upload a skill zip file
104
+ entrydesk skills upload ./my-skill # Upload a skill folder (auto-zipped)
105
+ entrydesk skills delete skill-123 # Delete a skill you own
106
+ entrydesk skills --json # Output in JSON format
107
+ ```
108
+
109
+ ## Budget Management
110
+
111
+ ```bash
112
+ entrydesk budget # Show current workspace budget
113
+ entrydesk budget get # Get workspace budget
114
+ entrydesk budget set 100.00 # Set workspace budget to $100
115
+ entrydesk budget clear # Remove workspace budget
116
+ entrydesk budget --json # Output in JSON format
117
+ ```
118
+
119
+ ## Usage Statistics
120
+
121
+ ```bash
122
+ entrydesk usage # Show usage by all users, sorted by cost
123
+ entrydesk usage --limit 10 # Show top 10 users
124
+ entrydesk usage --sort-by operations # Sort by operation count
125
+ entrydesk usage --json # Output in JSON format
126
+ ```
127
+
128
+ ## Agents Management
129
+
130
+ ```bash
131
+ entrydesk agents # List available agents
132
+ entrydesk agents --json # Output in JSON format
133
+ entrydesk agents create --name "My Agent" --description "..." --system-prompt "..." --model-id <modelId>
134
+ entrydesk agents update <agentId> --name "New Name" --description "..." --system-prompt "..." --model-id <modelId>
135
+ entrydesk agents delete <agentId>
136
+ ```
137
+
138
+ ## Configuration
139
+
140
+ ```bash
141
+ entrydesk config
142
+ entrydesk config set apiUrl http://localhost:3200
143
+ entrydesk config set hubUrl http://localhost:3000
144
+ entrydesk config unset apiUrl
145
+ ```
146
+
147
+ ## Profiles
148
+
149
+ ```bash
150
+ entrydesk profile # List profiles
151
+ entrydesk profile create staging # Create a profile
152
+ entrydesk profile use staging # Switch active profile
153
+ entrydesk profile show staging # Show profile details
154
+ entrydesk profile clone default staging # Clone config defaults (no credentials)
155
+ entrydesk profile delete staging
156
+
157
+ # Run a single command against a specific profile without switching
158
+ entrydesk status --profile staging
159
+ entrydesk chat -i --profile staging
160
+ ```
161
+
162
+ ## Development
163
+
164
+ ```bash
165
+ pnpm --filter @entrydesk/cli dev
166
+ pnpm --filter @entrydesk/cli lint
167
+ pnpm --filter @entrydesk/cli typecheck
168
+ ```
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import R from"crypto";import f from"fs";import ue from"path";import u from"fs";import ae from"os";import S from"path";import{HTTPError as ie,TimeoutError as oe}from"ky";import te,{TimeoutError as re}from"ky";import E from"fs";function V(r){let e=o.getEffectiveProfileName(r);return o.getProfileConfigFile(e)}function a(r){let e=V(r);try{if(!E.existsSync(e))return{};let t=E.readFileSync(e,"utf-8");return JSON.parse(t)}catch{return{}}}function d(r,e){let t=o.getEffectiveProfileName(e);o.ensureProfileDir(t);let s=o.getProfileConfigFile(t);E.writeFileSync(s,JSON.stringify(r,null,2),{mode:384});try{E.chmodSync(s,384)}catch{}}var F={getApiUrl(r){return a(r).apiUrl??null},setApiUrl(r,e){let t=a(e);t.apiUrl=r,d(t,e)},clearApiUrl(r){let e=a(r);delete e.apiUrl,d(e,r)},getHubUrl(r){return a(r).hubUrl??null},setHubUrl(r,e){let t=a(e);t.hubUrl=r,d(t,e)},getAll(r){return a(r)},setAll(r,e){d(r,e)},set(r,e,t){let s=a(t);s[r]=e,d(s,t)},get(r,e){return a(e)[r]},unset(r,e){let t=a(e);delete t[r],d(t,e)},getDefaultModel(r){return a(r).model?.default??null},setDefaultModel(r,e){let t=a(e);t.model={...t.model,default:r},d(t,e)},getDefaultConnectorIds(r){return a(r).connectors?.defaults??null},setDefaultConnectorIds(r,e){let t=a(e);t.connectors={...t.connectors,defaults:r},d(t,e)},getCapabilities(r){return a(r).capabilities??null},setCapabilities(r,e){let t=a(e);t.capabilities={...t.capabilities,...r},d(t,e)},getLocalTools(r){return a(r).localTools??null},setLocalTools(r,e){let t=a(e);t.localTools={...t.localTools,...r},d(t,e)}};var X="https://entrydesk-api.dcard.io",Z="https://entrydesk.dcard.io",Q=3100,ee=300*1e3;function T(r){return{apiUrl:F.getApiUrl(r)||process.env.ENTRYDESK_API_URL||X,hubUrl:F.getHubUrl(r)||process.env.ENTRYDESK_HUB_URL||Z,mcp:{httpPort:Q},auth:{loginTimeout:ee,ignoreSslErrors:process.env.ENTRYDESK_IGNORE_SSL_ERRORS==="true"||!1}}}function z(r){return T(r).apiUrl}function Se(r){return T(r).hubUrl}function Ce(){return T().mcp}function O(){return T().auth}var N="ENTRYDESK_ALLOW_INSECURE_LOGIN",$=class r{client;baseUrl;constructor(e,t){this.baseUrl=e||z(t),O().ignoreSslErrors&&(process.env.NODE_TLS_REJECT_UNAUTHORIZED="0",process.env.DEBUG&&console.log("[DEBUG] ApiClient: SSL certificate validation disabled")),this.client=te.create({prefixUrl:this.baseUrl,timeout:3e4,retry:{limit:3,methods:["get","put","head","delete","options","trace"],statusCodes:[408,413,429,500,502,503,504]},hooks:{beforeError:[n=>(n.request?.headers&&(n.request.headers.delete("authorization"),n.request.headers.delete("Authorization")),n)]}})}getBaseUrl(){return this.baseUrl}shouldAllowInsecureLogin(){return process.env[N]?.toLowerCase()==="true"}assertSecureLogin(){let e;try{e=new URL(this.baseUrl)}catch(t){let s=t instanceof Error?t:void 0;throw new c("Invalid API URL; cannot perform login.",1,s)}if(e.protocol!=="https:"&&!this.shouldAllowInsecureLogin())throw new c(`Login requires HTTPS. Set apiUrl to https:// or set ${N}=true for local development.`)}async login(e,t){return this.assertSecureLogin(),await this.client.post("v1/auth/credentials/token",{json:{email:e,password:t}}).json()}async refreshToken(e){return await this.client.post("v1/auth/token/refresh",{json:{refreshToken:e}}).json()}async revokeToken(e){await this.client.post("v1/auth/token/revoke",{json:{refreshToken:e}})}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){return await this.client.get(`v1/workspaces/${t}/availableAgents`,{headers:{Authorization:`Bearer ${e}`},searchParams:{limit:100}}).json()}async createAgent(e,t,s){return await this.client.post(`v1/workspaces/${t}/agents`,{headers:{Authorization:`Bearer ${e}`},json:s}).json()}async updateAgent(e,t,s,n){await this.client.put(`v1/workspaces/${t}/agents/${s}`,{headers:{Authorization:`Bearer ${e}`},json:n})}async deleteAgent(e,t,s){await this.client.delete(`v1/workspaces/${t}/agents/${s}`,{headers:{Authorization:`Bearer ${e}`}})}async getModels(e,t){return await this.client.get(`v1/workspaces/${t}/models`,{headers:{Authorization:`Bearer ${e}`}}).json()}async getConnectors(e,t){return await this.client.get(`v1/workspaces/${t}/availableConnectors`,{headers:{Authorization:`Bearer ${e}`},searchParams:{limit:100,connectionStatus:"connected"}}).json()}async getChats(e,t,s=20){return await this.client.get(`v1/workspaces/${t}/chats`,{headers:{Authorization:`Bearer ${e}`},searchParams:{limit:s}}).json()}async getMessages(e,t,s,n=50){return await this.client.get(`v1/workspaces/${t}/chats/${s}/messages`,{headers:{Authorization:`Bearer ${e}`},searchParams:{limit:n}}).json()}async getAgent(e,t,s){return await this.client.get(`v1/workspaces/${t}/agents/${s}`,{headers:{Authorization:`Bearer ${e}`}}).json()}async listAvailableSkills(e,t,s){return await this.client.get(`v1/workspaces/${t}/availableSkills`,{headers:{Authorization:`Bearer ${e}`},searchParams:{createdBy:s?.createdBy,nextKey:s?.nextKey,limit:s?.limit??20}}).json()}async uploadSkill(e,t,s){return await this.client.post(`v1/workspaces/${t}/skills`,{headers:{Authorization:`Bearer ${e}`},body:s}).json()}async deleteSkill(e,t,s){await this.client.delete(`v1/workspaces/${t}/skills/${s}`,{headers:{Authorization:`Bearer ${e}`}})}async chat(e,t,s){try{let n=await this.client.post(`v1/workspaces/${t}/chats`,{headers:{Authorization:`Bearer ${e}`},json:s,timeout:6e4,throwHttpErrors:!1});if(!n.ok){let i=await n.text();throw new Error(`Chat API failed (${n.status}): ${i}`)}return n}catch(n){throw n instanceof re?new Error("Request timed out. Please check your connection and try again.",{cause:n}):n}}async getBudget(e,t){return await this.client.get(`v1/workspaces/${t}/budget`,{headers:{Authorization:`Bearer ${e}`}}).json()}async updateBudget(e,t,s){return await this.client.put(`v1/workspaces/${t}/budget`,{headers:{Authorization:`Bearer ${e}`},json:{budget:s}}).json()}async getMonthlyUsages(e,t,s){return await this.client.get(`v1/workspaces/${t}/monthlyUsages`,{headers:{Authorization:`Bearer ${e}`},searchParams:{nextKey:s?.nextKey,limit:s?.limit??20}}).json()}async createChatShare(e,t,s,n="public"){return await this.client.post(`v1/workspaces/${t}/chats/${s}/shares`,{headers:{Authorization:`Bearer ${e}`},json:{visibility:n}}).json()}async getSharedChat(e,t){let s={};return t&&(s.Authorization=`Bearer ${t}`),await this.client.get(`v1/shares/${e}`,{headers:s}).json()}async getSharedMessages(e,t=50,s){let n={};return s&&(n.Authorization=`Bearer ${s}`),await this.client.get(`v1/shares/${e}/messages`,{headers:n,searchParams:{limit:t}}).json()}async deleteChat(e,t,s){await this.client.delete(`v1/workspaces/${t}/chats/${s}`,{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,s,n){let i=new FormData,g=new Blob([s.buffer],{type:s.mimeType});return i.append("file",g,s.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,s){let n={limit:s?.limit??20};return s?.nextKey&&(n.nextKey=s.nextKey),s?.search&&(n.search=s.search),await this.client.get(`v1/workspaces/${t}/schedules`,{headers:{Authorization:`Bearer ${e}`},searchParams:n}).json()}async getSchedule(e,t,s){return await this.client.get(`v1/workspaces/${t}/schedules/${s}`,{headers:{Authorization:`Bearer ${e}`}}).json()}async createSchedule(e,t,s){return await this.client.post(`v1/workspaces/${t}/schedules`,{headers:{Authorization:`Bearer ${e}`},json:s}).json()}async updateSchedule(e,t,s,n){await this.client.put(`v1/workspaces/${t}/schedules/${s}`,{headers:{Authorization:`Bearer ${e}`},json:n})}async deleteSchedule(e,t,s){await this.client.delete(`v1/workspaces/${t}/schedules/${s}`,{headers:{Authorization:`Bearer ${e}`}})}static async getAuthenticatedClient(e){let t=await h.getAll(e);return t?{client:new r(void 0,e),accessToken:t.accessToken,workspaceId:t.workspaceId??null}:null}};var p=class extends Error{code;constructor(e,t){super(t),this.code=e}};function se(r){try{let e=r.split(".");if(e.length<2)return null;let t=e[1].replace(/-/g,"+").replace(/_/g,"/"),s=(4-t.length%4)%4,n=t.padEnd(t.length+s,"="),i=Buffer.from(n,"base64").toString("utf8");return JSON.parse(i)}catch{return null}}function ne(r,e=300){let t=se(r);if(!t?.exp)return!1;let s=Math.floor(Date.now()/1e3);return t.exp-s<=e}async function W(r){let e=r.accessToken;if(!ne(e))return e;if(!r.refreshToken)throw await h.clear(),new p("session-expired","Session expired. Please run `entrydesk login` again.");try{let t=new $,{token:s}=await t.refreshToken(r.refreshToken);return await h.saveAccessToken(s),s}catch{throw await h.clear(),new p("session-expired","Session expired. Please run `entrydesk login` again.")}}async function Fe(){let r=await h.getAll();if(!r?.accessToken)throw new p("not-logged-in","Not logged in. Run `entrydesk login` first.");return W(r)}async function Ke(){let r=await h.getAll();if(!r?.accessToken)throw new p("not-logged-in","Not logged in. Run `entrydesk login` first.");if(!r.workspaceId)throw new p("no-workspace","No workspace selected. Run `entrydesk workspaces` first.");return{accessToken:await W(r),workspaceId:r.workspaceId}}var c=class extends Error{constructor(t,s=1,n){super(t);this.exitCode=s;this.cause=n;this.name="CLIError"}};function De(r){let e=!!process.env.DEBUG;r instanceof c&&(console.error(`Error: ${r.message}`),r.cause&&(console.error(`Cause: ${r.cause.message}`),e&&r.cause.stack&&console.error(r.cause.stack)),process.exit(r.exitCode)),r instanceof p&&(console.error(r.message),e&&r.stack&&console.error(r.stack),process.exit(1)),r instanceof oe&&(console.error("Request timed out. Please check your connection and try again."),e&&r.stack&&console.error(r.stack),process.exit(1)),r instanceof ie&&(console.error(`Request failed (${r.response.status}): ${r.response.statusText}`),e&&r.stack&&console.error(r.stack),process.exit(1)),r instanceof Error&&(console.error(`Unexpected error: ${r.message}`),e&&r.stack&&console.error(r.stack),process.exit(1)),console.error("An unknown error occurred"),process.exit(1)}var m="default",le=/^[A-Za-z0-9_-]+$/,K=null;function B(){return S.join(ae.homedir(),".entrydesk")}function H(){return S.join(B(),"profiles")}function J(){return S.join(B(),"profiles.json")}function U(r){return S.join(H(),r)}function M(r){if(!u.existsSync(r))u.mkdirSync(r,{mode:448,recursive:!0});else try{u.chmodSync(r,448)}catch{}}function ce(){M(B())}function I(){M(H())}function ge(){let r=J();try{if(!u.existsSync(r))return null;let e=u.readFileSync(r,"utf-8");return JSON.parse(e)}catch{return null}}function k(r){ce();let e=J();u.writeFileSync(e,JSON.stringify(r,null,2),{mode:384});try{u.chmodSync(e,384)}catch{}}function de(r){let e=r.profiles?.length?Array.from(new Set(r.profiles)):[],t=r.currentProfile&&e.includes(r.currentProfile)?r.currentProfile:e[0]||m;return e.length===0&&e.push(m),e.includes(t)||e.unshift(t),{currentProfile:t,profiles:e}}function y(){let r=ge();if(!r){let t={currentProfile:m,profiles:[m]};return k(t),I(),x(m),t}let e=de(r);return(e.currentProfile!==r.currentProfile||e.profiles.length!==r.profiles.length)&&k(e),I(),e}function P(r){if(!r)throw new c("Profile name is required.");if(!le.test(r))throw new c("Invalid profile name. Use letters, numbers, dash, or underscore.")}function b(r,e){if(!r.profiles.includes(e))throw new c(`Profile not found: ${e}`)}function G(r,e){if(r.profiles.includes(e))throw new c(`Profile already exists: ${e}`)}function x(r){I(),M(U(r))}var o={DEFAULT_PROFILE:m,setOverrideProfile(r){K=r},getOverrideProfile(){return K},getProfileDir(r){return U(r)},getProfileConfigFile(r){return S.join(o.getProfileDir(r),"config.json")},getProfileCredentialsFile(r){return S.join(o.getProfileDir(r),"credentials.json")},getProfileNames(){return[...y().profiles]},getProfileCount(){return o.getProfileNames().length},getCurrentProfileName(){return y().currentProfile},getEffectiveProfileName(r){let e=y(),t=r||K||e.currentProfile;return P(t),b(e,t),t},ensureProfileExists(r){let e=y();P(r),b(e,r)},createProfile(r){P(r);let e=y();G(e,r);let t={currentProfile:e.currentProfile,profiles:[...e.profiles,r]};k(t),x(r)},deleteProfile(r){P(r);let e=y();if(b(e,r),e.profiles.length===1)throw new c("Cannot delete the last profile.");let t=e.profiles.filter(i=>i!==r),s=e.currentProfile;s===r&&(s=t.includes(m)?m:t[0]),k({currentProfile:s,profiles:t});try{u.rmSync(o.getProfileDir(r),{recursive:!0,force:!0})}catch{}return{currentProfile:s}},renameProfile(r,e){P(r),P(e);let t=y();b(t,r),G(t,e);let s=U(r),n=U(e);if(u.existsSync(s))try{u.renameSync(s,n)}catch(v){throw new c("Failed to rename profile directory.",1,v)}else x(e);let i=t.profiles.map(v=>v===r?e:v),g=t.currentProfile===r?e:t.currentProfile;return k({currentProfile:g,profiles:i}),{currentProfile:g}},setCurrentProfile(r){P(r);let e=y();b(e,r);let t={currentProfile:r,profiles:e.profiles};k(t),x(r)},ensureProfileDir:x};var fe="ENTRYDESK_FORCE_FILE_STORAGE",C="EntryDesk CLI",pe="__entrydesk_keychain_test__",he="profile:",ye=".credentials.key",Y={keychain:!1,permissions:!1,corruptFile:!1,windowsFile:!1};function w(r,e){Y[r]||(Y[r]=!0,console.error(e))}function q(r){if(!r||typeof r!="object")return!1;let e=r;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 me(r){if(!r||typeof r!="object")return!1;let e=r;return typeof e.getPassword=="function"&&typeof e.setPassword=="function"&&typeof e.deletePassword=="function"}function D(r){return o.getProfileCredentialsFile(r)}var L=class{getKeyFilePath(e){return ue.join(o.getProfileDir(e),ye)}loadEncryptionKey(e){let t=this.getKeyFilePath(e);try{if(!f.existsSync(t))return null;let s=f.readFileSync(t);return s.length!==32?null:(this.ensureSecureFilePermissions(t),s)}catch{return null}}createEncryptionKey(e){o.ensureProfileDir(e);let t=this.getKeyFilePath(e),s=R.randomBytes(32);return f.writeFileSync(t,s,{mode:384}),this.ensureSecureFilePermissions(t),s}getOrCreateEncryptionKey(e){let t=this.loadEncryptionKey(e);return t||this.createEncryptionKey(e)}encrypt(e,t){let s=R.randomBytes(16),n=R.createCipheriv("aes-256-gcm",t,s),i=n.update(e,"utf8","hex");i+=n.final("hex");let g=n.getAuthTag();return`${s.toString("hex")}:${g.toString("hex")}:${i}`}decrypt(e,t){let s=e.split(":");if(s.length!==3)throw new Error("Invalid encrypted data format");let n=Buffer.from(s[0],"hex"),i=Buffer.from(s[1],"hex"),g=s[2],A=R.createDecipheriv("aes-256-gcm",t,n,{authTagLength:16});A.setAuthTag(i);let v=A.update(g,"hex","utf8");return v+=A.final("utf8"),v}tryDecrypt(e,t){try{return this.decrypt(e,t)}catch{return null}}tryParseCredentials(e){try{let t=JSON.parse(e);return q(t)?t:null}catch{return null}}ensureSecureFilePermissions(e){if(process.platform!=="win32"){try{f.chmodSync(e,384)}catch{w("permissions","Warning: Failed to set secure permissions on credentials file.");return}try{(f.statSync(e).mode&511)!==384&&w("permissions","Warning: Credentials file permissions are too permissive.")}catch{w("permissions","Warning: Failed to verify credentials file permissions.")}}}async getCredentials(e){let t=D(e);try{if(!f.existsSync(t))return null;let s=f.readFileSync(t,"utf-8").trim();if(!s)return null;let n=this.loadEncryptionKey(e),i=n?this.tryDecrypt(s,n):null;if(i){let g=this.tryParseCredentials(i);if(g)return g}return w("corruptFile","Warning: Credentials file is unreadable. Please run `entrydesk login` again."),null}catch{return null}}async setCredentials(e,t){o.ensureProfileDir(e);let s=D(e),n=this.getOrCreateEncryptionKey(e),i=this.encrypt(JSON.stringify(t),n);f.writeFileSync(s,i,{mode:384}),this.ensureSecureFilePermissions(s)}async deleteCredentials(e){let t=D(e);try{f.existsSync(t)&&f.unlinkSync(t)}catch{}}},_=class{keytarModule=null;keytarLoadAttempted=!1;keychainAvailable=null;async getKeytar(){if(this.keytarLoadAttempted)return this.keytarModule;this.keytarLoadAttempted=!0;try{let t=await import("keytar"),s=t&&typeof t=="object"&&"default"in t?t.default:t;this.keytarModule=me(s)?s:null}catch{this.keytarModule=null}return this.keytarModule}getAccount(e){return`${he}${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=`${pe}${R.randomBytes(8).toString("hex")}`,s="test";await e.setPassword(C,t,s);let n=await e.getPassword(C,t),i=await e.deletePassword(C,t);return this.keychainAvailable=!!(i&&n===s),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 s=await t.getPassword(C,this.getAccount(e));if(!s)return null;let n=this.tryParseKeychainPayload(s);return n||w("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 s=await this.getKeytar();if(!s)throw new Error("Keytar module not available");let n=JSON.stringify(t);await s.setPassword(C,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(C,this.getAccount(e))}tryParseKeychainPayload(e){try{let t=JSON.parse(e);return q(t)?t:null}catch{return null}}},j=class{keychainStorage=null;fileStorage=new L;keychainAvailable=null;initPromise=null;shouldForceFileStorage(){return process.env[fe]?.toLowerCase()==="true"}async initializeStorage(){if(this.shouldForceFileStorage()){this.keychainAvailable=!1,this.keychainStorage=null;return}try{let e=new _,t=await e.isAvailable();this.keychainAvailable=t,this.keychainStorage=t?e:null}catch{this.keychainAvailable=!1,this.keychainStorage=null}!this.keychainAvailable&&!this.shouldForceFileStorage()&&(w("keychain","Keychain unavailable. Falling back to file-based credentials."),process.platform==="win32"&&w("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.initPromise=this.initializeStorage()),await this.initPromise)}disableKeychain(){this.shouldForceFileStorage()||w("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 s=await this.fileStorage.getCredentials(e);if(s)try{await t.setCredentials(e,s),await this.fileStorage.deleteCredentials(e)}catch{}return s}async setCredentials(e,t){let s=await this.getKeychainStorage();if(!s){await this.fileStorage.setCredentials(e,t);return}try{await s.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 j,h={async saveAccessToken(r,e){let t=o.getEffectiveProfileName(e),s=await l.getCredentials(t)||{};s.accessToken=r,await l.setCredentials(t,s)},async getAccessToken(r){let e=o.getEffectiveProfileName(r);return(await l.getCredentials(e))?.accessToken??null},async saveRefreshToken(r,e){let t=o.getEffectiveProfileName(e),s=await l.getCredentials(t)||{};s.refreshToken=r,await l.setCredentials(t,s)},async getRefreshToken(r){let e=o.getEffectiveProfileName(r);return(await l.getCredentials(e))?.refreshToken??null},async saveEmail(r,e){let t=o.getEffectiveProfileName(e),s=await l.getCredentials(t)||{};s.email=r,await l.setCredentials(t,s)},async getEmail(r){let e=o.getEffectiveProfileName(r);return(await l.getCredentials(e))?.email??null},async saveWorkspaceId(r,e){let t=o.getEffectiveProfileName(e),s=await l.getCredentials(t)||{};s.workspaceId=r,await l.setCredentials(t,s)},async getWorkspaceId(r){let e=o.getEffectiveProfileName(r);return(await l.getCredentials(e))?.workspaceId??null},async saveAll(r,e){let t=o.getEffectiveProfileName(e);await l.setCredentials(t,r)},async getAll(r){let e=o.getEffectiveProfileName(r);return l.getCredentials(e)},async clear(r){let e=o.getEffectiveProfileName(r);await l.deleteCredentials(e)},async isLoggedIn(r){let e=o.getEffectiveProfileName(r);return(await l.getCredentials(e))?.accessToken!=null}};export{h as a,p as b,Fe as c,Ke as d,c as e,De as f,o as g,F as h,T as i,z as j,Se as k,Ce as l,O as m,$ as n};
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import{i as a,j as b,k as c,l as d,m as e}from"./chunk-J6ER4MMT.js";export{b as getApiUrl,e as getAuthConfig,a as getConfig,c as getHubUrl,d as getMcpConfig};
package/dist/index.js ADDED
@@ -0,0 +1,501 @@
1
+ #!/usr/bin/env node
2
+ import{a as $e,b as Ze,c as dt,d as ye,e as Et,f as be,g as H,h as ne,i as Qe,n as B}from"./chunk-J6ER4MMT.js";import{render as gi}from"ink";function bo(){console.log(`
3
+ Usage: entrydesk agents [list|create|update|delete] [options]
4
+
5
+ Commands:
6
+ list List available agents (default)
7
+ create Create a new agent
8
+ update <agentId> Update an agent you own
9
+ delete <agentId> Delete an agent you own
10
+
11
+ Create/Update Options:
12
+ --name <name>
13
+ --description <text>
14
+ --system-prompt <text>
15
+ --model-id <modelId>
16
+ --connector-ids id1,id2
17
+ --capabilities sandbox,web_search,image_generation,chart
18
+ --conversation-starters s1,s2,s3
19
+ --tools prefix__tool1,prefix__tool2
20
+ --icon-id <iconId>
21
+
22
+ Flags:
23
+ --json Output JSON
24
+ `)}function Ns(e){if(!e)return[];let t=new Map([["sandbox","sandbox"],["web","web_search"],["web-search","web_search"],["web_search","web_search"],["image","image_generation"],["image-gen","image_generation"],["image_generation","image_generation"],["chart","chart"]]);return e.map(n=>t.get(n)??n)}function Xo(e){return(!e.name||!e.description||!e.systemPrompt||!e.modelId)&&(console.error("Missing required fields for agent create/update."),bo(),process.exit(1)),{name:e.name,description:e.description,systemPrompt:e.systemPrompt,modelId:e.modelId,connectorIds:e.connectorIds??[],capabilities:Ns(e.capabilities),conversationStarters:e.conversationStarters??[],tools:e.tools,iconId:e.iconId}}async function Zo(e){try{if(e.help){bo();return}let t=await ye(),{accessToken:n,workspaceId:s}=t,o=e.action||"list",r=new B;if(o==="create"){let a=Xo(e),l=await r.createAgent(n,s,a);if(e.json){console.log(JSON.stringify(l));return}console.log(`Created agent: ${l.name}`),console.log(` ID: ${l.id}`);return}if(o==="update"){let a=e.agentId;if(!a)throw new Error("Missing agentId for update command");let l=Xo(e);await r.updateAgent(n,s,a,l),console.log(`Updated agent: ${a}`);return}if(o==="delete"){let a=e.agentId;if(!a)throw new Error("Missing agentId for delete command");await r.deleteAgent(n,s,a),console.log(`Deleted agent: ${a}`);return}o!=="list"&&(console.error(`Unknown agents command: ${o}`),bo(),process.exit(1));let{agents:i}=await r.getAgents(n,s);if(e.json){console.log(JSON.stringify(i));return}if(i.length===0){console.log("No agents found in this workspace.");return}console.log(`Available Agents (${i.length}):
25
+ `);for(let a of i)console.log(` ${a.name} (${a.visibility})`),a.description&&console.log(` ${a.description.slice(0,80)}`),console.log(` ID: ${a.id}`),console.log("")}catch(t){be(t)}}function _s(){console.log(`
26
+ Usage: entrydesk budget [get|set|clear] [options]
27
+
28
+ Commands:
29
+ get Show current workspace budget (default)
30
+ set <amount> Set workspace budget (e.g., 100.00)
31
+ clear Remove workspace budget
32
+
33
+ Flags:
34
+ --json Output JSON
35
+ `)}async function Qo(e){try{if(e.help){_s();return}let t=await ye(),{accessToken:n,workspaceId:s}=t,o=e.action||"get",r=new B;if(o==="set"){let a=e.configKey;if(!a)throw new Error("Missing budget amount for set command");let l=parseFloat(a);if(isNaN(l)||l<0)throw new Error("Budget must be a positive number");let d=await r.updateBudget(n,s,a);if(e.json){console.log(JSON.stringify(d));return}console.log(`Budget updated: $${a}`);return}if(o==="clear"){let a=await r.updateBudget(n,s,null);if(e.json){console.log(JSON.stringify(a));return}console.log("Budget cleared.");return}if(o!=="get")throw new Error(`Unknown budget command: ${o}`);let i=await r.getBudget(n,s);if(e.json){console.log(JSON.stringify(i));return}if(i.budget===null){console.log("No budget set for this workspace.");return}console.log(`Current workspace budget: $${i.budget}`)}catch(t){be(t)}}import{render as Nr}from"ink";import{v4 as uo}from"uuid";import{exec as Ds}from"child_process";import Ls from"fs";import et from"fs/promises";import en from"os";import xo from"path";import{promisify as Rs}from"util";import{glob as Os}from"glob";var Us=Rs(Ds),js=`## Filesystem Tool Instructions
36
+
37
+ You have access to filesystem tools that allow you to interact with the user's local filesystem.
38
+
39
+ ### Available Operations
40
+
41
+ - **Read File**: Read the contents of a file
42
+ - **Read Multiple Files**: Read multiple files at once (max 10)
43
+ - **Write File**: Create or overwrite a file
44
+ - **Create Directory**: Create a new directory (including parent directories)
45
+ - **List Directory**: List files and subdirectories
46
+ - **Search Files**: Search for files matching a glob pattern
47
+ - **Get File Info**: Get metadata about a file or directory
48
+ - **Move File**: Move or rename a file or directory
49
+ - **Execute Command**: Run shell commands on the user's machine
50
+
51
+ ### Important Notes
52
+
53
+ - Always use absolute paths when possible
54
+ - Be mindful of file permissions and access restrictions
55
+ - Large files will be truncated in responses
56
+ - Search results are limited to prevent overwhelming responses
57
+ - Execute Command has a default timeout of 30 seconds (max 5 minutes)
58
+ - The current working directory is: ${process.cwd()}
59
+ - The user's home directory is: ${en.homedir()}
60
+ `,Bs=[{name:"filesystem__read_file",description:"Read the contents of a file from the local filesystem.",inputSchema:{type:"object",properties:{path:{type:"string",description:"The absolute path to the file to read."}},required:["path"]}},{name:"filesystem__read_multiple_files",description:"Read multiple files at once (max 10 files).",inputSchema:{type:"object",properties:{paths:{type:"array",items:{type:"string"},description:"Array of absolute file paths to read."}},required:["paths"]}},{name:"filesystem__write_file",description:"Create or overwrite a file with the given content.",inputSchema:{type:"object",properties:{path:{type:"string",description:"The absolute path to the file to write."},content:{type:"string",description:"The content to write to the file."}},required:["path","content"]}},{name:"filesystem__create_directory",description:"Create a new directory (including parent directories if needed).",inputSchema:{type:"object",properties:{path:{type:"string",description:"The absolute path of the directory to create."}},required:["path"]}},{name:"filesystem__list_directory",description:"List files and subdirectories in a directory.",inputSchema:{type:"object",properties:{path:{type:"string",description:"The absolute path of the directory to list."}},required:["path"]}},{name:"filesystem__search_files",description:"Search for files matching a glob pattern.",inputSchema:{type:"object",properties:{pattern:{type:"string",description:'Glob pattern to match files (e.g., "**/*.ts").'},cwd:{type:"string",description:"Base directory to search in (optional)."}},required:["pattern"]}},{name:"filesystem__get_file_info",description:"Get metadata about a file or directory.",inputSchema:{type:"object",properties:{path:{type:"string",description:"The absolute path to get info for."}},required:["path"]}},{name:"filesystem__move_file",description:"Move or rename a file or directory.",inputSchema:{type:"object",properties:{source:{type:"string",description:"The source path."},destination:{type:"string",description:"The destination path."}},required:["source","destination"]}},{name:"filesystem__execute_command",description:"Execute a shell command on the local machine.",inputSchema:{type:"object",properties:{command:{type:"string",description:"The command to execute."},cwd:{type:"string",description:"Working directory for the command (optional)."},timeout:{type:"number",description:"Timeout in milliseconds (default: 30000, max: 300000)."}},required:["command"]}}];function tn(){return{name:"filesystem",systemPrompt:js,tools:Bs}}function Ve(e){return e.startsWith("~/")?xo.join(en.homedir(),e.slice(2)):e}function zt(e,t=1e5){return e.length<=t?e:e.slice(0,t)+`
61
+
62
+ ... (truncated, ${e.length-t} more characters)`}async function on(e,t){try{switch(e){case"filesystem__read_file":{let n=Ve(t.path),s=await et.readFile(n,"utf-8");return{success:!0,result:zt(s)}}case"filesystem__read_multiple_files":{let n=t.paths.slice(0,10),s={};for(let o of n){let r=Ve(o);try{let i=await et.readFile(r,"utf-8");s[o]=zt(i,5e4)}catch(i){s[o]={error:i instanceof Error?i.message:String(i)}}}return{success:!0,result:s}}case"filesystem__write_file":{let n=Ve(t.path),s=t.content;return await et.mkdir(xo.dirname(n),{recursive:!0}),await et.writeFile(n,s,"utf-8"),{success:!0,result:{written:n}}}case"filesystem__create_directory":{let n=Ve(t.path);return await et.mkdir(n,{recursive:!0}),{success:!0,result:{created:n}}}case"filesystem__list_directory":{let n=Ve(t.path);return{success:!0,result:(await et.readdir(n,{withFileTypes:!0})).map(r=>({name:r.name,type:r.isDirectory()?"directory":r.isFile()?"file":r.isSymbolicLink()?"symlink":"other"}))}}case"filesystem__search_files":{let n=t.pattern,s=t.cwd?Ve(t.cwd):process.cwd(),o=await Os(n,{cwd:s,nodir:!0,maxDepth:10});return{success:!0,result:{files:o.slice(0,100),total:o.length,truncated:o.length>100}}}case"filesystem__get_file_info":{let n=Ve(t.path),s=await et.stat(n);return{success:!0,result:{path:n,type:s.isDirectory()?"directory":s.isFile()?"file":"other",size:s.size,created:s.birthtime.toISOString(),modified:s.mtime.toISOString(),accessed:s.atime.toISOString(),mode:s.mode.toString(8)}}}case"filesystem__move_file":{let n=Ve(t.source),s=Ve(t.destination);return await et.mkdir(xo.dirname(s),{recursive:!0}),await et.rename(n,s),{success:!0,result:{moved:{from:n,to:s}}}}case"filesystem__execute_command":{let n=t.command,s=t.cwd?Ve(t.cwd):process.cwd(),o=Math.min(t.timeout||3e4,3e5);if(!Ls.existsSync(s))return{success:!1,error:`Working directory does not exist: ${s}`};let{stdout:r,stderr:i}=await Us(n,{cwd:s,timeout:o,maxBuffer:10*1024*1024});return{success:!0,result:{stdout:zt(r,5e4),stderr:zt(i,5e4)}}}default:return{success:!1,error:`Unknown tool: ${e}`}}}catch(n){return{success:!1,error:n instanceof Error?n.message:String(n)}}}function Co(e){return e.startsWith("filesystem__")}function nn(){return[tn()]}function Yt(){return nn().flatMap(e=>e.tools)}function Xt(){return nn().map(e=>e.systemPrompt).filter(Boolean).join(`
63
+
64
+ `)}function tt(e){return Co(e)}async function Zt(e,t){return Co(e)?on(e,t):{success:!1,error:`Unknown client tool: ${e}`}}import{Box as Pe,Text as K,useInput as jo}from"ink";import Bo from"ink-spinner";import{useCallback as Fo,useEffect as co,useRef as Yn,useState as $r}from"react";import{Box as Qt,Text as Nt}from"ink";import{jsx as eo,jsxs as _t}from"react/jsx-runtime";function sn(e,t){return e.length<=t?e:t<=3?".".repeat(t):e.slice(0,t-3)+"..."}function rn({items:e,activeIndex:t,selectedIds:n,multiSelect:s=!1,visible:o,title:r,pageSize:i=10}){if(!o||e.length===0)return null;let a=process.stdout.columns??80,l=s?4:0,d=Math.max(20,a-2-2-l),v=Math.max(1,i),b=Math.floor(t/v)*v,x=Math.min(e.length,b+v),C=e.slice(b,x);return _t(Qt,{flexDirection:"column",marginBottom:1,children:[eo(Nt,{bold:!0,color:"cyan",children:r}),eo(Qt,{borderStyle:"single",borderColor:"gray",flexDirection:"column",children:C.map((m,h)=>{let R=b+h===t,V=n?.has(m.id),Z=sn(m.name,d),ae=m.description?sn(m.description,Math.max(0,d-l)):"",Y=s?" ".repeat(l):"";return _t(Qt,{paddingX:1,flexDirection:"column",children:[_t(Qt,{children:[s&&eo(Nt,{color:V?"green":"gray",children:V?"[\u2713] ":"[ ] "}),eo(Nt,{backgroundColor:R?"cyan":void 0,color:R?"black":V?"green":"white",bold:!0,children:Z})]}),ae&&_t(Nt,{dimColor:!0,children:[Y,"\xB7 ",ae]})]},m.id)})}),_t(Nt,{dimColor:!0,children:[s?"\u2191\u2193 Navigate \xB7 Space Toggle \xB7 a All \xB7 n None \xB7 Enter Confirm \xB7 Esc Cancel":"\u2191\u2193 Navigate \xB7 Enter Select \xB7 Esc Cancel",e.length>v?` \xB7 Showing ${b+1}-${x} of ${e.length}`:""]})]})}import{Box as $o,Text as Dt}from"ink";import{jsx as Lt,jsxs as So}from"react/jsx-runtime";function an({suggestions:e,activeIndex:t,visible:n}){return!n||e.length===0?null:So($o,{flexDirection:"column",marginBottom:1,children:[Lt($o,{borderStyle:"single",borderColor:"gray",flexDirection:"column",children:e.map((s,o)=>{let r=o===t,i=s.aliases.length>0?` (${s.aliases.join(", ")})`:"";return So($o,{paddingX:1,children:[So(Dt,{backgroundColor:r?"cyan":void 0,color:r?"black":"cyan",bold:r,children:["/",s.name]}),Lt(Dt,{dimColor:!0,children:i}),Lt(Dt,{children:" - "}),Lt(Dt,{color:r?"white":"gray",children:s.description})]},s.name)})}),Lt(Dt,{dimColor:!0,children:"\u2191\u2193 Navigate \xB7 Tab/Enter Select \xB7 Esc Cancel"})]})}import{Box as Fs,Text as ln,useInput as Ws,useStdout as Ms}from"ink";import{useCallback as cn,useEffect as un,useMemo as To,useRef as dn,useState as fn}from"react";import{jsx as Po}from"react/jsx-runtime";function to(e,t){return e<0?0:e>t?t:e}function vo(e){return Array.from(e)}function oo(e){return/\s/.test(e)}function Io(e,t){let n=t;for(;n>0&&oo(e[n-1]??"");)n-=1;for(;n>0&&!oo(e[n-1]??"");)n-=1;return n}function pn(e,t){let n=t;for(;n<e.length&&oo(e[n]??"");)n+=1;for(;n<e.length&&!oo(e[n]??"");)n+=1;return n}function Js(e){let t=[],n=[],s=[],o=0;n.push(0),e.forEach((i,a)=>{if(i===`
65
+ `){t.push(s),s=[],o=a+1,n.push(o);return}s.push(i)}),t.push(s);let r=t.map(i=>i.length);return{lines:t,lineStarts:n,lineLengths:r}}function mn(e,t,n){for(let o=0;o<t.length;o+=1){let r=t[o]??0,i=n[o]??0,a=r+i;if(e<=a)return{row:o,col:e-r}}let s=Math.max(0,t.length-1);return{row:s,col:n[s]??0}}var Gs=2;function gn({value:e,onChange:t,onSubmit:n,onPaste:s,focus:o=!0,leadingOffset:r=0,multiline:i=!1}){let[a,l]=fn(()=>vo(e).length),d=dn(null),[v,b]=fn(0),x=dn(null),{stdout:C}=Ms(),m=To(()=>vo(e),[e]),{lines:h,lineStarts:S,lineLengths:R}=To(()=>Js(m),[m]),{row:V,col:Z}=To(()=>mn(a,S,R),[a,S,R]),ae=Math.max(1,(C?.columns??80)-r);un(()=>{d.current!==e?(l(m.length),x.current=null):l(j=>to(j,m.length)),d.current=e},[e,m.length]),un(()=>{b(j=>{let P=j;Z<P?P=Z:Z>=P+ae&&(P=Z-ae+1);let N=R[V]??0,O=Z===N?N+1:N,W=Math.max(0,O-ae);return P>W&&(P=W),P<0&&(P=0),P})},[ae,Z,V,R]);let Y=cn((j,P)=>{d.current=j,t(j),l(P),x.current=null},[t]),Se=cn(async(j,P)=>{if(!o)return;let{row:N,col:O}=mn(a,S,R),W=h[N]??[],_=R[N]??0,ge=h.length>1;if(i&&(P.meta&&P.return||P.ctrl&&j==="j"||P.shift&&P.return)){let D=[...m.slice(0,a),`
66
+ `,...m.slice(a)].join("");Y(D,a+1);return}if(P.return){n(e);return}if(P.leftArrow){P.ctrl||P.meta?(O===0&&N>0?l(S[N]-1):l(S[N]+Io(W,O)),x.current=null):(O===0&&N>0?l(S[N]-1):l(D=>to(D-1,m.length)),x.current=null);return}if(P.rightArrow){P.ctrl||P.meta?(O>=_&&N<h.length-1?l(S[N+1]):l(S[N]+pn(W,O)),x.current=null):(O>=_&&N<h.length-1?l(S[N+1]):l(D=>to(D+1,m.length)),x.current=null);return}if(i&&ge&&P.upArrow){let D=x.current??O,p=Math.max(0,N-1),ie=Math.min(D,R[p]??0);l((S[p]??0)+ie),x.current=D;return}if(i&&ge&&P.downArrow){let D=x.current??O,p=Math.min(h.length-1,N+1),ie=Math.min(D,R[p]??0);l((S[p]??0)+ie),x.current=D;return}if(P.ctrl){if(j==="a"){l(S[N]??0),x.current=null;return}if(j==="e"){l((S[N]??0)+_),x.current=null;return}if(j==="u"){if(O>0){let D=S[N]??0,p=[...m.slice(0,D),...m.slice(a)].join("");Y(p,D)}return}if(j==="k"){if(O<_){let D=(S[N]??0)+_,p=[...m.slice(0,a),...m.slice(D)].join("");Y(p,a)}return}if(j==="w"){if(O===0&&N>0){let p=[...m.slice(0,a-1),...m.slice(a)].join("");Y(p,a-1);return}let D=Io(W,O);if(D!==O){let p=(S[N]??0)+D,ie=[...m.slice(0,p),...m.slice(a)].join("");Y(ie,p)}return}if(j==="d"){if(a<m.length){let D=[...m.slice(0,a),...m.slice(a+1)].join("");Y(D,a)}return}return}if(P.meta){j==="b"?(O===0&&N>0?l(S[N]-1):l(S[N]+Io(W,O)),x.current=null):j==="f"&&(O>=_&&N<h.length-1?l(S[N+1]):l(S[N]+pn(W,O)),x.current=null);return}if(P.backspace||P.delete){if(a<=0)return;let D=[...m.slice(0,a-1),...m.slice(a)].join("");Y(D,a-1);return}if(!(P.tab||P.escape)&&j.length>0){let D=i?j.replace(/\r\n/g,`
67
+ `).replace(/\r/g,`
68
+ `):j.replace(/\r?\n/g,"");if(!D||(D=D.replace(/^\x1b?\[200~/,"").replace(/\x1b?\[201~$/,""),!D))return;if((D.length>=Gs||D.includes(`
69
+ `))&&s){let q=!1,A={text:D,preventDefault:()=>{q=!0}};if(await Promise.resolve(s(A)),q)return}let ie=vo(D),ke=[...m.slice(0,a),...ie,...m.slice(a)].join("");Y(ke,a+ie.length)}},[m,a,o,R,S,h,i,s,n,Y,e]);return Ws(Se,{isActive:o}),Po(Fs,{flexDirection:"column",children:h.map((j,P)=>{let N=P===V,W=(N&&Z===j.length?[...j," "]:j).slice(v,v+ae),_=W.join("");if(!N)return Po(ln,{children:_||" "},P);let ge=to(Z-v,Math.max(0,W.length-1)),D=W.slice(0,ge).join(""),p=W[ge]??" ",ie=W.slice(ge+1).join(""),A=`${D}\x1B[7m${p}\x1B[27m${ie}`;return Po(ln,{children:A},P)})})}import{Box as Ke,Text as ft}from"ink";import _o from"react";import{Text as Be}from"ink";import Hs from"react";import{Fragment as qs,jsx as Me,jsxs as wn}from"react/jsx-runtime";var Ao=2,Eo=1,No=2,Vs=1,hn=3,yn=4,Ks=({text:e,defaultColor:t,linkColor:n,codeColor:s})=>{let o=t;if(!/[*_~`<[https?:]/.test(e))return Me(Be,{color:o,children:e});let r=[],i=0,a=/(\*\*.*?\*\*|\*.*?\*|_.*?_|~~.*?~~|\[.*?\]\(.*?\)|`+.+?`+|<u>.*?<\/u>|https?:\/\/\S+)/g,l;for(;(l=a.exec(e))!==null;){l.index>i&&r.push(Me(Be,{color:o,children:e.slice(i,l.index)},`t-${i}`));let d=l[0],v=null,b=`m-${l.index}`;try{if(d.startsWith("**")&&d.endsWith("**")&&d.length>Ao*2)v=Me(Be,{bold:!0,color:o,children:d.slice(Ao,-Ao)},b);else if(d.length>Eo*2&&(d.startsWith("*")&&d.endsWith("*")||d.startsWith("_")&&d.endsWith("_"))&&!/\w/.test(e.substring(l.index-1,l.index))&&!/\w/.test(e.substring(a.lastIndex,a.lastIndex+1))&&!/\S[./\\]/.test(e.substring(l.index-2,l.index))&&!/[./\\]\S/.test(e.substring(a.lastIndex,a.lastIndex+2)))v=Me(Be,{italic:!0,color:o,children:d.slice(Eo,-Eo)},b);else if(d.startsWith("~~")&&d.endsWith("~~")&&d.length>No*2)v=Me(Be,{strikethrough:!0,color:o,children:d.slice(No,-No)},b);else if(d.startsWith("`")&&d.endsWith("`")&&d.length>Vs){let x=d.match(/^(`+)(.+?)\1$/s);x&&x[2]&&(v=Me(Be,{color:s,children:x[2]},b))}else if(d.startsWith("[")&&d.includes("](")&&d.endsWith(")")){let x=d.match(/\[(.*?)\]\((.*?)\)/);if(x){let C=x[1],m=x[2];v=wn(Be,{color:o,children:[C,wn(Be,{color:n,children:[" (",m,")"]})]},b)}}else d.startsWith("<u>")&&d.endsWith("</u>")&&d.length>hn+yn-1?v=Me(Be,{underline:!0,color:o,children:d.slice(hn,-yn)},b):d.match(/^https?:\/\//)&&(v=Me(Be,{color:n,children:d},b))}catch{v=null}r.push(v??Me(Be,{color:o,children:d},b)),i=a.lastIndex}return i<e.length&&r.push(Me(Be,{color:o,children:e.slice(i)},`t-${i}`)),Me(qs,{children:r.filter(d=>d!==null)})},Rt=Hs.memo(Ks);import{Fragment as tr,jsx as we,jsxs as Cn}from"react/jsx-runtime";var zs=1,xn=1,Ys=1,Xs=1,Zs=({text:e,renderMarkdown:t=!0})=>{if(!e)return null;if(!t)return we(Ke,{paddingLeft:xn,flexDirection:"column",children:we(ft,{wrap:"wrap",children:e})});let n=e.split(/\r?\n/),s=/^ *(#{1,4}) +(.*)/,o=/^ *(`{3,}|~{3,}) *(\w*?) *$/,r=/^([ \t]*)([-*+]) +(.*)/,i=/^([ \t]*)(\d+)\. +(.*)/,a=/^ *([-*_] *){3,} *$/,l=/^ *> ?(.*)/,d=[],v=!1,b=!0,x=[],C="";function m(h){h&&(d.push(h),b=!1)}return n.forEach((h,S)=>{let R=`line-${S}`;if(v){let P=h.match(o);P&&P[1].startsWith(C[0])&&P[1].length>=C.length?(m(we(kn,{content:x},R)),v=!1,x=[],C=""):x.push(h);return}let V=h.match(o),Z=h.match(s),ae=h.match(r),Y=h.match(i),Se=h.match(a),j=h.match(l);if(V)v=!0,C=V[1];else if(Se)m(we(Ke,{children:we(ft,{dimColor:!0,children:"---"})},R));else if(Z){let P=Z[1].length,N=Z[2],O=P<=2?"cyan":"blue";m(we(Ke,{children:we(ft,{color:O,...(P===4?"italic":"bold")==="italic"?{italic:!0}:{bold:!0},children:we(Rt,{text:N,defaultColor:O,linkColor:"cyan",codeColor:"yellow"})})},R))}else if(j){let P=j[1];m(we(Ke,{paddingLeft:1,children:Cn(ft,{dimColor:!0,children:["> ",we(Rt,{text:P,defaultColor:"gray",linkColor:"cyan",codeColor:"yellow"})]})},R))}else if(ae){let P=ae[1],N=ae[2],O=ae[3];m(we(bn,{itemText:O,type:"ul",marker:N,leadingWhitespace:P},R))}else if(Y){let P=Y[1],N=Y[2],O=Y[3];m(we(bn,{itemText:O,type:"ol",marker:N,leadingWhitespace:P},R))}else h.trim().length===0?b||(d.push(we(Ke,{height:zs},`spacer-${S}`)),b=!0):m(we(Ke,{children:we(ft,{wrap:"wrap",children:we(Rt,{text:h,defaultColor:void 0,linkColor:"cyan",codeColor:"yellow"})})},R))}),v&&m(we(kn,{content:x},"line-eof")),we(tr,{children:d})},Qs=({content:e})=>{let t=e.join(`
70
+ `);return we(Ke,{paddingLeft:xn,flexDirection:"column",children:we(ft,{color:"yellow",children:t})})},kn=_o.memo(Qs),er=({itemText:e,type:t,marker:n,leadingWhitespace:s=""})=>{let o=t==="ol"?`${n}. `:`${n} `,r=o.length,i=s.length;return Cn(Ke,{paddingLeft:i+Ys,flexDirection:"row",children:[we(Ke,{width:r,children:we(ft,{children:o})}),we(Ke,{flexGrow:Xs,children:we(ft,{wrap:"wrap",children:we(Rt,{text:e,defaultColor:void 0,linkColor:"cyan",codeColor:"yellow"})})})]})},bn=_o.memo(er),Do=_o.memo(Zs);import{execFile as or}from"child_process";import nr from"fs";import $t from"fs/promises";import $n from"os";import so from"path";import{promisify as sr}from"util";var no=sr(or);async function rr(){let e=so.join($n.tmpdir(),`entrydesk-clipboard-${Date.now()}.png`);try{let t=`
71
+ set imageData to the clipboard as "PNGf"
72
+ set fileRef to open for access POSIX file "${e}" with write permission
73
+ set eof fileRef to 0
74
+ write imageData to fileRef
75
+ close access fileRef
76
+ `;return await no("osascript",["-e",t]),(await $t.stat(e)).size===0?void 0:{buffer:await $t.readFile(e),mime:"image/png"}}catch{return}finally{try{nr.existsSync(e)&&await $t.unlink(e)}catch{}}}async function ir(){try{let e=`
77
+ Add-Type -AssemblyName System.Windows.Forms
78
+ $img = [System.Windows.Forms.Clipboard]::GetImage()
79
+ if ($img) {
80
+ $ms = New-Object System.IO.MemoryStream
81
+ $img.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png)
82
+ [System.Convert]::ToBase64String($ms.ToArray())
83
+ }
84
+ `,{stdout:t}=await no("powershell.exe",["-command",e]),n=t.trim();if(!n)return;let s=Buffer.from(n,"base64");return s.length===0?void 0:{buffer:s,mime:"image/png"}}catch{return}}async function ar(){try{let{stdout:e}=await no("wl-paste",["-t","image/png"],{encoding:"buffer",maxBuffer:52428800});if(e&&e.length>0)return{buffer:e,mime:"image/png"}}catch{}try{let{stdout:e}=await no("xclip",["-selection","clipboard","-t","image/png","-o"],{encoding:"buffer",maxBuffer:52428800});if(e&&e.length>0)return{buffer:e,mime:"image/png"}}catch{}}async function Sn(){let e=$n.platform();if(e==="darwin")return rr();if(e==="win32")return ir();if(e==="linux")return ar()}var lr=new Set([".png",".jpg",".jpeg",".gif",".webp",".bmp",".ico",".heic",".heif",".pdf",".txt",".md",".rtf",".csv",".doc",".docx",".xls",".xlsx",".ppt",".pptx",".key",".pages",".numbers",".odt",".ods",".odp",".json",".xml",".yaml",".yml"]);function Tn(e){let t=so.extname(e).toLowerCase();return lr.has(t)}function cr(e){let t=so.extname(e).toLowerCase();return{".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".bmp":"image/bmp",".ico":"image/x-icon",".heic":"image/heic",".heif":"image/heif",".txt":"text/plain",".md":"text/markdown",".pdf":"application/pdf",".csv":"text/csv",".rtf":"application/rtf",".doc":"application/msword",".docx":"application/vnd.openxmlformats-officedocument.wordprocessingml.document",".xls":"application/vnd.ms-excel",".xlsx":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",".ppt":"application/vnd.ms-powerpoint",".pptx":"application/vnd.openxmlformats-officedocument.presentationml.presentation",".key":"application/vnd.apple.keynote",".pages":"application/vnd.apple.pages",".numbers":"application/vnd.apple.numbers",".odt":"application/vnd.oasis.opendocument.text",".ods":"application/vnd.oasis.opendocument.spreadsheet",".odp":"application/vnd.oasis.opendocument.presentation",".json":"application/json",".xml":"application/xml",".yaml":"text/yaml",".yml":"text/yaml"}[t]||"application/octet-stream"}function ro(e){let t=e.trim();return t.startsWith("file://")&&(t=decodeURIComponent(t.slice(7))),(t.startsWith("'")&&t.endsWith("'")||t.startsWith('"')&&t.endsWith('"'))&&(t=t.slice(1,-1)),t=t.replace(/\\(.)/g,"$1"),t}async function vn(e){let t=ro(e);if(/^https?:\/\//.test(t))return!1;try{return await $t.access(t),!0}catch{return!1}}async function In(e){let t=ro(e);try{if(!(await $t.stat(t)).isFile())return;let s=await $t.readFile(t),o=cr(t),r=so.basename(t);return{buffer:s,mimeType:o,filename:r}}catch{return}}var Fe="\x1B[2m",re="\x1B[0m",Ie="\x1B[36m",St="\x1B[32m",Pn="\x1B[31m",gt="\x1B[38;2;59;91;204m",Lo="\x1B[38;2;126;200;248m",Ro="\x1B[38;2;244;196;78m";import{useState as ot}from"react";import{v4 as An}from"uuid";function En(e,t){let[n,s]=ot({status:"loading"}),[o,r]=ot([]),[i,a]=ot(""),[l,d]=ot(()=>e||An()),[v,b]=ot(t),[x,C]=ot(!!e),[m,h]=ot(null),[S,R]=ot(""),[V,Z]=ot(!1),ae=Se=>{r(j=>[...j,{role:"system",content:Se}])};return{state:n,setState:s,messages:o,setMessages:r,input:i,setInput:a,chatId:l,setChatId:d,currentChatTitle:v,setCurrentChatTitle:b,hasPersistedChat:x,setHasPersistedChat:C,credentials:m,setCredentials:h,currentResponse:S,setCurrentResponse:R,fullOutput:V,setFullOutput:Z,addSystemMessage:ae,startNewChat:Se=>{let j=An();d(j),b(void 0),C(!1),r([]),Se&&ae(Se)}}}import{useEffect as ur,useState as Nn}from"react";function _n(e){let[t,n]=Nn(null),[s,o]=Nn(!0);return ur(()=>{let r=!1;async function i(){try{let a=await ye();if(r)return;n({accessToken:a.accessToken,workspaceId:a.workspaceId}),o(!1)}catch(a){if(r)return;if(a instanceof Ze){if(a.code==="not-logged-in"){e({status:"not-logged-in"}),o(!1);return}if(a.code==="no-workspace"){e({status:"no-workspace"}),o(!1);return}}let l=a instanceof Error?a.message:"Failed to authenticate";e({status:"error",message:l}),o(!1)}}return i(),()=>{r=!0}},[e]),{credentials:t,loading:s}}import{useEffect as dr,useState as Ot}from"react";function Dn(e){let[t,n]=Ot([]),[s,o]=Ot([]),[r,i]=Ot([]),[a,l]=Ot([]),[d,v]=Ot(!1);return dr(()=>{if(!e)return;let b=!1;v(!0);async function x(){if(e)try{let C=new B,[m,h,S,R]=await Promise.all([C.getConnectors(e.accessToken,e.workspaceId),C.getModels(e.accessToken,e.workspaceId),C.getAgents(e.accessToken,e.workspaceId),C.getModelProviders(e.accessToken,e.workspaceId)]);if(b)return;n(m.connectors),o(h.models),i(S.agents),l(R.providers??[])}catch{}finally{b||v(!1)}}return x(),()=>{b=!0}},[e]),{availableConnectors:t,availableModels:s,availableAgents:r,modelProviders:a,loading:d}}import lo from"fs";import Rn from"path";import{useCallback as fr}from"react";import{v4 as pr}from"uuid";function Ln(e,t){if(!e)return"(no result)";if(typeof e!="object"){let o=String(e);return t||o.length<=200?o:o.slice(0,200)+"..."}let n=e;if("structuredContent"in n&&n.structuredContent){let o=n.structuredContent;if(o.stdout&&typeof o.stdout=="string"){let r=o.stdout.trim();return t||r.length<=200?r:r.slice(0,200)+"..."}}if("content"in n&&Array.isArray(n.content)){let o=n.content.filter(r=>r.type==="text"&&r.text).map(r=>r.text).join(`
85
+ `);return o?t||o.length<=200?o:o.slice(0,200)+"...":"(result)"}let s=JSON.stringify(e,null,t?2:void 0);return t||s.length<=200?s:s.slice(0,200)+"..."}function ht(e,t=!1){let n=[];for(let s of e)if(s.type==="text"&&s.text)n.push(s.text);else if(s.type==="reasoning"&&s.text)t?n.push(`${Fe}[Thinking]
86
+ ${s.text}${re}`):n.push(`${Fe}[Thinking...]${re}`);else if(s.type==="tool-call"&&s.toolName){let o=[];if(o.push(`${Ie}\u250C\u2500 Tool: ${s.toolName}${re}`),s.args){let r=JSON.stringify(s.args,null,t?2:void 0),i=t||r.length<=100?r:r.slice(0,100)+"...";o.push(`${Fe}\u2502 Args: ${i}${re}`)}s.result!==void 0?(o.push(`${St}\u2502 Result: ${Ln(s.result,t)}${re}`),o.push(`${Ie}\u2514\u2500 completed${re}`)):o.push(`${Ie}\u2514\u2500${re}`),n.push(o.join(`
87
+ `))}else if(s.type.startsWith("tool-")&&s.type!=="tool-call"){let o=s.title||s.type.slice(5).replace(/__/g," "),r=[];if(r.push(`${Ie}\u250C\u2500 Tool: ${o}${re}`),s.input){let i=JSON.stringify(s.input,null,t?2:void 0),a=t||i.length<=100?i:i.slice(0,100)+"...";r.push(`${Fe}\u2502 Input: ${a}${re}`)}s.output!==void 0&&s.state==="output-available"?(r.push(`${St}\u2502 Output: ${Ln(s.output,t)}${re}`),r.push(`${Ie}\u2514\u2500 completed${re}`)):s.state==="error"?r.push(`${Ie}\u2514\u2500 failed${re}`):r.push(`${Ie}\u2514\u2500${re}`),n.push(r.join(`
88
+ `))}return n.join(`
89
+
90
+ `).trim()}var io=class{pendingToolCalls=new Map;hasPending(){return this.pendingToolCalls.size>0}hasExecuting(){for(let t of this.pendingToolCalls.values())if(t.status==="executing")return!0;return!1}clear(t){this.pendingToolCalls.delete(t)}buildToolDisplay(){if(this.pendingToolCalls.size===0)return"";let t=[];for(let[,n]of this.pendingToolCalls){let s=n.toolName.replace(/__/g," "),o=`
91
+
92
+ ${Ie}\u250C\u2500 Tool: ${s}${re}`;if(n.args){let r=n.args.length>100?n.args.slice(0,100)+"...":n.args;o+=`
93
+ ${Fe}\u2502 Input: ${r}${re}`}if(n.output){let r=n.output.length>150?n.output.slice(0,150)+"...":n.output;o+=`
94
+ ${St}\u2502 Output: ${r}${re}`}else if(n.status==="executing"){let r=n.startedAt??Date.now(),i=Math.floor((Date.now()-r)/1e3);o+=`
95
+ ${Ie}\u2502${re} (executing... ${i}s)`}else n.status==="preparing"&&(o+=`
96
+ ${Ie}\u2502${re} (preparing...)`);t.push(o)}return t.join("")}flushPending(t){if(this.pendingToolCalls.size===0)return t;for(let[n,s]of this.pendingToolCalls){let o=s.toolName.replace(/__/g," "),r=typeof s.args=="string"&&s.args.length>100?s.args.slice(0,100)+"...":s.args||"";t+=`
97
+
98
+ ${Ie}\u250C\u2500 Tool: ${o}${re}`,r&&(t+=`
99
+ ${Fe}\u2502 Input: ${r}${re}`),t+=`
100
+ ${Ie}\u2514\u2500 completed${re}
101
+ `,this.pendingToolCalls.delete(n)}return t}handleToolInputStart(t){return t.toolCallId&&t.toolName?(this.pendingToolCalls.set(t.toolCallId,{toolName:t.toolName,args:"",status:"preparing"}),this.buildToolDisplay()):null}handleToolInputDelta(t){if(t.toolCallId&&t.inputTextDelta){let n=this.pendingToolCalls.get(t.toolCallId);if(n)return n.args=(n.args||"")+t.inputTextDelta,n.status="executing",n.startedAt??=Date.now(),this.buildToolDisplay()}return null}handleToolOutputStart(t){if(t.toolCallId){let n=this.pendingToolCalls.get(t.toolCallId);if(n)return n.output="",n.status="output",this.buildToolDisplay()}return null}handleToolOutputDelta(t){if(t.toolCallId&&t.outputTextDelta){let n=this.pendingToolCalls.get(t.toolCallId);if(n)return n.output=(n.output||"")+t.outputTextDelta,this.buildToolDisplay()}return null}handleToolOutputEnd(t,n){if(!t.toolCallId)return null;let s=this.pendingToolCalls.get(t.toolCallId);if(!s)return null;let o=s.toolName.replace(/__/g," "),r=typeof s.args=="string"&&s.args.length>100?s.args.slice(0,100)+"...":s.args||"",i=(s.output||"").length>200?(s.output||"").slice(0,200)+"...":s.output||"";return n+=`
102
+
103
+ ${Ie}\u250C\u2500 Tool: ${o}${re}`,r&&(n+=`
104
+ ${Fe}\u2502 Input: ${r}${re}`),n+=`
105
+ ${St}\u2502 Output: ${i}${re}`,n+=`
106
+ ${Ie}\u2514\u2500 completed${re}
107
+ `,this.pendingToolCalls.delete(t.toolCallId),{fullResponse:n,toolDisplay:this.buildToolDisplay()}}handleToolError(t,n){if(!t.toolCallId)return null;let o=(this.pendingToolCalls.get(t.toolCallId)?.toolName||t.toolName||"Tool").replace(/__/g," "),r=t.errorText||"Unknown error",i=r.length>200?r.slice(0,200)+"...":r;return n+=`
108
+
109
+ ${Ie}\u250C\u2500 Tool: ${o}${re}`,n+=`
110
+ ${Pn}\u2502 Error: ${i}${re}`,n+=`
111
+ ${Ie}\u2514\u2500 failed${re}
112
+ `,this.pendingToolCalls.delete(t.toolCallId),{fullResponse:n,toolDisplay:this.buildToolDisplay()}}};var Oo=Rn.join(process.env.HOME||"/tmp",".entrydesk","stream-debug.log");function le(e,t){let s=`[${new Date().toISOString()}] ${e}`;t!==void 0&&(s+=`
113
+ DATA: ${JSON.stringify(t,null,2)}`),s+=`
114
+ `;try{lo.appendFileSync(Oo,s)}catch{}}function mr(){try{let e=Rn.dirname(Oo);lo.existsSync(e)||lo.mkdirSync(e,{recursive:!0}),lo.writeFileSync(Oo,`=== Debug session started at ${new Date().toISOString()} ===
115
+ `)}catch{}}function ao(e){if(!e)return{};if(typeof e=="string")try{return JSON.parse(e)}catch{return{}}return typeof e=="object"?e:{}}function On({chatId:e,credentials:t,currentAgentId:n,currentModel:s,activeConnectorIds:o,sandbox:r,webSearch:i,imageGeneration:a,chart:l,localTools:d,fullOutput:v,setMessages:b,setState:x,setCurrentResponse:C,setCredentials:m,setHasPersistedChat:h,getFileIds:S,clearFiles:R}){let V=d?Yt():void 0,Z=d?Xt():void 0;return{sendMessage:fr(async(Y,Se,j)=>{mr(),le("=== sendMessage called ===",{text:Y,localTools:d,clientToolsCount:V?.length});let P=Se||t?.accessToken,N=j||t?.workspaceId;if(!P||!N)try{let _=await ye();P=_.accessToken,N=_.workspaceId,m(_)}catch(_){if(_ instanceof Ze){if(_.code==="not-logged-in"){x({status:"not-logged-in"});return}if(_.code==="no-workspace"){x({status:"no-workspace"});return}}let ge=_ instanceof Error?_.message:"Authentication failed";x({status:"error",message:ge});return}else try{let _=await dt();_!==P&&(P=_,m({accessToken:_,workspaceId:N}))}catch(_){if(_ instanceof Ze&&_.code==="not-logged-in"){x({status:"not-logged-in"});return}let ge=_ instanceof Error?_.message:"Authentication failed";x({status:"error",message:ge});return}b(_=>[..._,{role:"user",content:Y}]),x({status:"sending"}),C("");let O=null,W=null;try{let _=new B,ge=S?.()??[],D={id:e,message:{id:pr(),createdAt:new Date,role:"user",parts:[{type:"text",text:Y}]}};ge.length>0&&(D.fileIds=ge),n?D.agentId=n:(s&&(D.model=s),D.connectorIds=o??[],D.enableSandbox=r,D.enableWebSearch=i,D.enableImageGeneration=a,D.enableChart=l),V&&(D.clientTools=V),Z&&(D.clientToolSystemPrompt=Z);let p=await _.chat(P,N,D);if(!p.ok){let F=await p.text();throw new Error(`API error ${p.status}: ${F}`)}if(!p.body)throw new Error("No response body from server");O=p.body.getReader();let ie=new TextDecoder,ke="",q="",A="",te="",ee="",pe="",ce="",M=new io,Q=[],z=[],fe=[],Te=()=>{let F=M.hasExecuting();F&&!W?W=setInterval(()=>{if(!M.hasExecuting()){W&&(clearInterval(W),W=null);return}C(q+M.buildToolDisplay())},1e3):!F&&W&&(clearInterval(W),W=null)};for(;;){let{done:F,value:se}=await O.read();if(F)break;ke+=ie.decode(se,{stream:!0});let L=ke.split(`
116
+ `);ke=L.pop()||"";for(let f of L)if(f.trim()!=="data: [DONE]"&&f.startsWith("data: "))try{let w=JSON.parse(f.slice(6));switch(le(`SSE event received: ${w.type}`,w),w.type){case"reasoning-start":te=w.id||"0",A="";break;case"reasoning-delta":w.delta&&(A+=w.delta,C(`${Fe}[Thinking...]${re}
117
+ ${A}`)),w.providerMetadata?.anthropic?.signature&&(ee=w.providerMetadata.anthropic.signature);break;case"reasoning-end":if(A){let T={type:"reasoning",id:te,text:A,state:"done"};ee&&(T.providerMetadata={anthropic:{signature:ee}}),z.push(T),le("Added reasoning to messageParts",{reasoningLength:A.length,hasSignature:!!ee,messagePartsCount:z.length})}A="",ee="",C("");break;case"text-delta":w.delta&&(M.hasPending()&&(q=M.flushPending(q)),q+=w.delta,pe+=w.delta,C(q));break;case"tool-input-start":{let T=M.handleToolInputStart(w);T&&C(q+T),Te();break}case"tool-input-delta":{let T=M.handleToolInputDelta(w);T&&C(q+T),Te();break}case"tool-call":case"tool-input-available":{if(le(`=== Tool event: ${w.type} ===`,{toolCallId:w.toolCallId,toolName:w.toolName,localTools:d,isClientToolResult:w.toolName?tt(w.toolName):"no toolName",args:w.args,input:w.input}),w.toolCallId&&w.toolName){let T=ao(w.args??w.input);z.push({type:w.type,toolCallId:w.toolCallId,toolName:w.toolName,args:T}),le("Added tool to messageParts",{messagePartsCount:z.length})}if(d&&w.toolCallId&&w.toolName&&tt(w.toolName)){let T=ao(w.args??w.input);Q.push({toolCallId:w.toolCallId,toolName:w.toolName,args:T}),le("Added to pendingClientTools",{pendingCount:Q.length,pendingClientTools:Q}),C(q+M.buildToolDisplay()+`
118
+ [Executing ${w.toolName} locally...]`)}else le("NOT added to pendingClientTools - conditions not met",{localTools:d,hasToolCallId:!!w.toolCallId,hasToolName:!!w.toolName,isClientTool:w.toolName?tt(w.toolName):!1});break}case"tool-output-start":{let T=M.handleToolOutputStart(w);T&&C(q+T),Te();break}case"tool-output-delta":{let T=M.handleToolOutputDelta(w);T&&C(q+T),Te();break}case"tool-output-end":{let T=M.handleToolOutputEnd(w,q);T&&(q=T.fullResponse,C(q+T.toolDisplay)),Te();break}case"tool-input-error":case"tool-output-error":{let T=M.handleToolError(w,q);T&&(q=T.fullResponse,C(q+T.toolDisplay)),Te();break}case"start":w.messageId&&(ce=w.messageId,le("Captured messageId from start event",{messageId:ce}));break;case"start-step":case"text-start":case"text-end":case"finish-step":case"message-metadata":case"finish":break;case"error":w.errorText&&console.error("Stream error:",w.errorText);break}}catch{}}if(pe){let F=z.findIndex(L=>L.type!=="reasoning"),se=F===-1?z.length:F;z.splice(se,0,{type:"text",text:pe}),le("Added accumulated text to messageParts",{textLength:pe.length,insertIndex:se})}for(le("=== Initial stream ended ===",{pendingClientToolsCount:Q.length,pendingClientTools:Q,messagePartsCount:z.length,messageParts:z.map(F=>({type:F.type,toolCallId:F.toolCallId,toolName:F.toolName}))});Q.length>0;){le("=== Starting pending tools execution loop ===",{pendingCount:Q.length});let F=[];for(let f of Q){le(`Executing tool: ${f.toolName}`,{toolCallId:f.toolCallId,args:f.args}),M.handleToolInputStart({toolCallId:f.toolCallId,toolName:f.toolName}),M.handleToolInputDelta({toolCallId:f.toolCallId,inputTextDelta:JSON.stringify(f.args)}),C(q+M.buildToolDisplay()),Te();let w=await Zt(f.toolName,f.args);le(`Tool execution result: ${f.toolName}`,{success:w.success,resultPreview:w.success?JSON.stringify(w.result).slice(0,200):w.error});let T=w.success?JSON.stringify(w.result):w.error||"Unknown error";if(F.push({toolCallId:f.toolCallId,toolName:f.toolName,content:[{type:"text",text:T}],isError:!w.success}),w.success){M.handleToolOutputStart({toolCallId:f.toolCallId}),M.handleToolOutputDelta({toolCallId:f.toolCallId,outputTextDelta:JSON.stringify(w.result).slice(0,200)});let oe=M.handleToolOutputEnd({toolCallId:f.toolCallId},q);oe&&(q=oe.fullResponse)}else{let oe=M.handleToolError({toolCallId:f.toolCallId,errorText:w.error},q);oe&&(q=oe.fullResponse)}C(q+M.buildToolDisplay()),Te()}Q.length=0;for(let f of F){let w=z.find(T=>(T.type==="tool-input-available"||T.type==="tool-call")&&T.toolCallId===f.toolCallId);if(w){let T=[];for(let U of f.content)U.type==="text"?T.push(U.text):U.type==="image"?T.push("[Image]"):U.type==="audio"?T.push("[Audio]"):(U.type==="resource"||U.type==="resource_link")&&T.push("[Resource]");let oe=T.join(`
119
+ `);fe.push({type:`tool-${w.toolName}`,toolName:w.toolName,toolCallId:w.toolCallId,input:w.args,output:oe,isError:f.isError})}}if(le("=== Sending clientToolResults for continuation ===",{toolResultsCount:F.length,toolResults:F.map(f=>({toolCallId:f.toolCallId,toolName:f.toolName,isError:f.isError}))}),O)try{O.releaseLock()}catch{}let se={id:e,clientToolResults:F};n?se.agentId=n:(s&&(se.model=s),se.connectorIds=o??[],se.enableSandbox=r,se.enableWebSearch=i,se.enableImageGeneration=a,se.enableChart=l),V&&(se.clientTools=V),Z&&(se.clientToolSystemPrompt=Z),le("=== Sending continuation request ===",{chatId:e,hasAgentId:!!se.agentId,hasModel:!!se.model,clientToolResultsCount:F.length});let L=await _.chat(P,N,se);if(le("=== Continuation response received ===",{ok:L.ok,status:L.status}),!L.ok){let f=await L.text();throw new Error(`Continuation failed: ${L.status}: ${f}`)}if(!L.body)break;for(le("=== Processing continuation stream ==="),O=L.body.getReader(),z.length=0,pe="",A="",te="",ee="";;){let{done:f,value:w}=await O.read();if(f){le("=== Continuation stream done ===");break}ke+=ie.decode(w,{stream:!0});let T=ke.split(`
120
+ `);ke=T.pop()||"";for(let oe of T)if(oe.trim()!=="data: [DONE]"&&oe.startsWith("data: "))try{let U=JSON.parse(oe.slice(6));switch(le(`Continuation SSE: ${U.type}`,U),U.type){case"reasoning-start":te=U.id||"0",A="";break;case"reasoning-delta":U.delta&&(A+=U.delta,C(`${Fe}[Thinking...]${re}
121
+ ${A}`)),U.providerMetadata?.anthropic?.signature&&(ee=U.providerMetadata.anthropic.signature);break;case"reasoning-end":if(A){let Ce={type:"reasoning",id:te,text:A,state:"done"};ee&&(Ce.providerMetadata={anthropic:{signature:ee}}),z.push(Ce),le("Continuation: Added reasoning to messageParts",{reasoningLength:A.length,hasSignature:!!ee,messagePartsCount:z.length})}A="",ee="",C(q);break;case"text-delta":U.delta&&(q+=U.delta,pe+=U.delta,C(q));break;case"tool-call":case"tool-input-available":if(U.toolCallId&&U.toolName){let Ce=ao(U.args??U.input);z.push({type:U.type,toolCallId:U.toolCallId,toolName:U.toolName,args:Ce})}if(d&&U.toolCallId&&U.toolName&&tt(U.toolName)){let Ce=ao(U.args??U.input);Q.push({toolCallId:U.toolCallId,toolName:U.toolName,args:Ce}),le("Continuation: Added to pendingClientTools",{pendingCount:Q.length})}break;case"finish":le("Continuation finish event",U);break}}catch{}}if(pe){let f=z.findIndex(T=>T.type!=="reasoning"),w=f===-1?z.length:f;z.splice(w,0,{type:"text",text:pe})}le("=== Continuation stream processing complete ===",{pendingClientToolsCount:Q.length,messagePartsCount:z.length,fullResponseLength:q.length})}if(d&&V&&V.length>0){let F=[];for(let L of fe)F.push({type:String(L.type),title:String(L.toolName).replace(/__/g," "),input:L.input,output:L.output,state:L.isError?"error":"output-available"});for(let L of z)L.type==="text"&&L.text&&F.push({type:"text",text:L.text});let se=ht(F,v);le("=== Using formatted parts for local tools ===",{executedToolsCount:fe.length,textPartsCount:z.filter(L=>L.type==="text").length,contentLength:se.length}),b(L=>[...L,{role:"assistant",content:se,parts:F}])}else{le("=== Fetching message from API ===",{fullResponseLength:q.length,fullResponsePreview:q.slice(0,200)});try{let{messages:F}=await _.getMessages(P,N,e,10);le("=== API messages received ===",{count:F.length,roles:F.map(L=>L.role)});let se=F.find(L=>L.role==="assistant");if(se){let L=se.parts,f=ht(L,v);le("=== Setting message from API ===",{partsCount:L.length,partTypes:L.map(w=>w.type),contentLength:f.length,contentPreview:f.slice(0,200)}),b(w=>[...w,{role:"assistant",content:f,parts:L}])}else le("=== No assistant message found, using fallback ==="),b(L=>[...L,{role:"assistant",content:q}])}catch(F){le("=== API fetch failed, using fallback ===",{error:F instanceof Error?F.message:String(F)}),b(se=>[...se,{role:"assistant",content:q}])}}le("=== Message handling complete ==="),C(""),x({status:"ready"}),h(!0),ge.length>0&&R?.()}catch(_){le("=== ERROR ===",{message:_ instanceof Error?_.message:String(_),stack:_ instanceof Error?_.stack:void 0});let ge=_ instanceof Error?_.message:"Failed to send message";x({status:"error",message:ge})}finally{if(W&&(clearInterval(W),W=null),O)try{O.releaseLock()}catch{}}},[t,e,n,s,o,r,i,a,l,d,V,Z,v,b,x,C,m,h,S,R])}}import{useState as Ut}from"react";var Un={sandbox:{id:"sandbox",apiKey:"sandbox",name:"Sandbox",description:"Code execution",type:"server"},webSearch:{id:"webSearch",apiKey:"web_search",name:"Web Search",description:"Search the web",type:"server"},imageGeneration:{id:"imageGeneration",apiKey:"image_generation",name:"Image Generation",description:"Generate images",type:"server"},chart:{id:"chart",apiKey:"chart",name:"Chart",description:"Create charts",type:"server"},fileSystem:{id:"fileSystem",apiKey:"file_system",name:"FileSystem",description:"Local file operations",type:"client"}},jn=new Map(Object.values(Un).map(e=>[e.apiKey,e.name]));function Bn(){return Object.values(Un)}function Fn(e,t,n,s,o){let[r,i]=Ut(e),[a,l]=Ut(t),[d,v]=Ut(n),[b,x]=Ut(s),[C,m]=Ut(o);return{sandbox:r,setSandbox:i,webSearch:a,setWebSearch:l,imageGeneration:d,setImageGeneration:v,chart:b,setChart:x,fileSystem:C,setFileSystem:m,capabilityLabelMap:jn}}import{useEffect as gr,useState as hr}from"react";function Wn(e,t){let[n,s]=hr(null);return gr(()=>{let o=!1;async function r(){if(!e||!t){s(null);return}try{let a=await new B().getAgent(t.accessToken,t.workspaceId,e);o||s(a)}catch{o||s(null)}}return r(),()=>{o=!0}},[e,t]),{currentAgentDetails:n}}import{useState as Uo}from"react";function Mn(e,t,n){let[s,o]=Uo(e),[r,i]=Uo(t),[a,l]=Uo(n);return{currentModel:s,setCurrentModel:o,currentAgentId:r,setCurrentAgentId:i,activeConnectorIds:a,setActiveConnectorIds:l}}import{useApp as wr,useInput as kr}from"ink";import{useCallback as nt,useRef as br,useState as Le}from"react";import{spawn as yr}from"child_process";function Jn(e){return new Promise((t,n)=>{let s,o;process.platform==="darwin"?(s="open",o=[e]):process.platform==="win32"?(s="cmd",o=["/c","start","",e]):(s="xdg-open",o=[e]);let r=yr(s,o,{stdio:"ignore",detached:!0});r.once("error",i=>{n(i)}),r.once("spawn",()=>{r.unref(),t()})})}var Gn=[{name:"help",aliases:["h","?"],description:"Show available commands"},{name:"clear",aliases:["cls","new"],description:"Start a new chat"},{name:"model",aliases:["m"],description:"Show/switch model",hasArgs:!0},{name:"agent",aliases:["a"],description:"Show/switch agent",hasArgs:!0},{name:"skills",aliases:["sk"],description:"List skills",hasArgs:!0},{name:"schedules",aliases:["sch"],description:"List schedules",hasArgs:!0},{name:"connectors",aliases:["conn"],description:"Select connectors"},{name:"capabilities",aliases:["cap"],description:"Select capabilities"},{name:"chats",aliases:["c"],description:"Switch to another chat"},{name:"workspace",aliases:["ws"],description:"List/switch workspace",hasArgs:!0},{name:"budget",aliases:["bg"],description:"View/set workspace budget",hasArgs:!0},{name:"usage",aliases:["u"],description:"View current month usage"},{name:"status",aliases:["s"],description:"Show session status"},{name:"profile",aliases:["p"],description:"Manage profiles",hasArgs:!0},{name:"open-in-browser",aliases:[],description:"Open current chat in browser"},{name:"share",aliases:[],description:"Get share link for current chat"},{name:"delete",aliases:["del"],description:"Delete current chat"},{name:"quit",aliases:["exit","q"],description:"Exit chat"}];function Hn(e){if(!e.startsWith("/"))return[];let t=e.slice(1).toLowerCase();return t?Gn.filter(n=>n.name.startsWith(t)||n.aliases.some(s=>s.startsWith(t))):Gn}function Vn(e){let t=e.trim();if(!t.startsWith("/"))return null;let n=t.slice(1).split(/\s+/),s=n[0]?.toLowerCase(),o=n.slice(1).join(" ");switch(s){case"help":case"h":case"?":return{type:"help"};case"clear":case"cls":case"new":return{type:"clear"};case"model":case"m":return{type:"model",value:o||void 0};case"agent":case"a":return{type:"agent",value:o||void 0};case"skills":case"sk":return{type:"skills",value:o||void 0};case"schedules":case"sch":return{type:"schedules",value:o||void 0};case"connectors":case"conn":return{type:"connectors"};case"capabilities":case"cap":return{type:"capabilities"};case"chats":case"c":return{type:"chats"};case"workspace":case"ws":return{type:"workspace",value:o||void 0};case"budget":case"bg":return{type:"budget",value:o||void 0};case"usage":case"u":return{type:"usage"};case"status":case"s":return{type:"status"};case"profile":case"p":return{type:"profile",value:o||void 0};case"open-in-browser":return{type:"open-in-browser"};case"share":return{type:"share"};case"delete":case"del":return{type:"delete"};case"quit":case"exit":case"q":return{type:"quit"};default:return{type:"unknown",input:t}}}var Kn=`Available commands:
122
+ /help, /h, /? Show this help message
123
+ /clear, /cls, /new Start a new chat
124
+ /model [name], /m Show current model or switch to [name]
125
+ /agent [name], /a Show current agent or switch to [name]
126
+ /skills [name], /sk List skills or show details for [name]
127
+ /schedules [id], /sch List schedules or show details for [id]
128
+ /connectors, /conn Select active connectors
129
+ /capabilities, /cap Select capabilities (sandbox, web, etc.)
130
+ /chats, /c Switch to another chat
131
+ /workspace [id], /ws List or switch workspace
132
+ /budget [amount], /bg View or set workspace budget
133
+ /usage, /u View current month usage (top 10 by cost)
134
+ /status, /s Show current session status
135
+ /profile [args], /p Manage profiles (list/show/use/create/delete/rename/clone)
136
+ /open-in-browser Open current chat in browser
137
+ /share Get share link for current chat
138
+ /delete, /del Delete current chat
139
+ /quit, /exit, /q Exit interactive mode
140
+
141
+ Note: For detailed usage with sorting/limits, use: entrydesk usage --help
142
+
143
+ Keyboard shortcuts:
144
+ Ctrl+O Toggle full output mode
145
+ Ctrl+C Exit`;function qn({input:e,setInput:t,chatId:n,setChatId:s,currentChatTitle:o,setCurrentChatTitle:r,currentModel:i,setCurrentModel:a,currentAgentId:l,setCurrentAgentId:d,currentAgentDetails:v,setCurrentAgentDetails:b,activeConnectorIds:x,setActiveConnectorIds:C,sandbox:m,setSandbox:h,webSearch:S,setWebSearch:R,imageGeneration:V,setImageGeneration:Z,chart:ae,setChart:Y,fileSystem:Se,setFileSystem:j,availableModels:P,availableAgents:N,availableConnectors:O,messages:W,hasPersistedChat:_,setHasPersistedChat:ge,setMessages:D,addSystemMessage:p,startNewChat:ie,sendMessage:ke,setFullOutput:q,credentials:A,setCredentials:te,setState:ee,defaultCapabilities:pe,capabilityLabelMap:ce,hasUploadingFiles:M=!1}){let{exit:Q}=wr(),[z,fe]=Le([]),[Te,F]=Le(0),[se,L]=Le(!1),[f,w]=Le(null),[T,oe]=Le([]),[U,Ce]=Le(0),[rt,it]=Le(new Set),[Oe,at]=Le(new Set),[yo,Gt]=Le([]),[We,yt]=Le([]),[ze,Ht]=Le([]),[lt,wo]=Le([]),[He,Ye]=Le(null),[Vt,wt]=Le(""),mt=br(!1),[ct,kt]=Le(!1),bt=nt(async()=>{if(!A)return[];let I=new B,y=[],c;do{let u=await I.listAvailableSkills(A.accessToken,A.workspaceId,{limit:100,nextKey:c});y.push(...u.skills),c=u.nextKey}while(c);return yt(y),y},[A]),xt=nt(async()=>{if(!A)return[];let I=new B,y=[],c;do{let u=await I.getSchedules(A.accessToken,A.workspaceId,{limit:100,nextKey:c});y.push(...u.schedules),c=u.nextKey}while(c);return Ht(y),y},[A]),_e=nt(async I=>{if(I==="model"){if(P.length===0){p("No models available.");return}let y=P.map(u=>({id:u.id,name:u.name,description:u.description}));oe(y);let c=i?y.findIndex(u=>u.id===i):-1;Ce(c>=0?c:0),w("model")}else if(I==="agent"){if(N.length===0){p("No agents available.");return}let y=N.map(u=>({id:u.id,name:u.name,description:u.description}));oe(y);let c=l?y.findIndex(u=>u.id===l):-1;Ce(c>=0?c:0),w("agent")}else if(I==="skills"){let y=We;if(y.length===0)try{y=await bt()}catch{p("Failed to load skills.");return}if(y.length===0){p("No skills available.");return}let c=y.map(u=>({id:u.id,name:u.name,description:u.description}));oe(c),Ce(0),w("skills")}else if(I==="schedules"){let y=ze;if(y.length===0)try{y=await xt()}catch{p("Failed to load schedules.");return}if(y.length===0){p("No schedules found.");return}let c=y.map(u=>({id:u.id,name:u.name,description:`${u.agent.name} - ${u.isActive?"Active":"Paused"}`}));oe(c),Ce(0),w("schedules")}else if(I==="connectors"){if(O.length===0){p("No connectors available.");return}let y=O.map(c=>({id:c.id,name:c.name}));oe(y),Ce(0),it(new Set(x||[])),w("connectors")}else if(I==="capabilities"){let y=Bn().map(u=>({id:u.id,name:u.name,description:u.description}));oe(y),Ce(0);let c=new Set;m&&c.add("sandbox"),S&&c.add("webSearch"),V&&c.add("imageGeneration"),ae&&c.add("chart"),Se&&c.add("fileSystem"),at(c),w("capabilities")}else if(I==="chats"){if(!A){p("Not authenticated.");return}try{let y=new B,{chats:c}=await y.getChats(A.accessToken,A.workspaceId,20);if(c.length===0){p("No chats available.");return}Gt(c);let u=c.map($=>({id:$.id,name:$.title||"Untitled",description:new Date($.createdAt).toLocaleDateString()}));oe(u);let g=u.findIndex($=>$.id===n);Ce(g>=0?g:0),w("chats")}catch{p("Failed to load chats.")}}else if(I==="profile"){let y=H.getProfileNames(),c=H.getCurrentProfileName(),u=y.map($=>({id:$,name:$,description:$===c?"(current)":void 0}));oe(u);let g=u.findIndex($=>$.id===c);Ce(g>=0?g:0),w("profile")}L(!1),fe([])},[P,N,We,ze,O,x,i,l,bt,xt,m,S,V,ae,Se,A,n,p]),he=nt(I=>{let y=ne.getAll(I);a(y.model?.default),d(void 0),b(null);let c=y.connectors?.defaults;C(c&&c.length>0?c:void 0);let u=y.capabilities;h(u?.sandbox??pe.sandbox),R(u?.webSearch??pe.webSearch),Z(u?.imageGeneration??pe.imageGeneration),Y(u?.chart??pe.chart);let g=y.localTools;j(g?.fileSystem??pe.fileSystem)},[a,d,b,C,h,R,Z,Y,j,pe]),Xe=nt(async()=>{try{let I=await ye();te({accessToken:I.accessToken,workspaceId:I.workspaceId}),ee({status:"ready"})}catch(I){if(te(null),I instanceof Ze){if(I.code==="not-logged-in"){ee({status:"not-logged-in"});return}if(I.code==="no-workspace"){ee({status:"no-workspace"});return}}let y=I instanceof Error?I.message:"Failed to authenticate";ee({status:"error",message:y})}},[te,ee]),Ct=nt(async I=>{switch(I.type){case"help":return p(Kn),!0;case"clear":return ie("Started a new chat."),!0;case"model":{if(I.value){let y=I.value.toLowerCase(),c=P.find(u=>u.id.toLowerCase()===y||u.name.toLowerCase().includes(y));if(c)l?ie(`Switched to model: ${c.name} (new chat)`):p(`Switched to model: ${c.name}`),a(c.id),d(void 0),b(null),ne.setDefaultModel(c.id);else{let u=P.map(g=>g.name).join(", ");p(`Model "${I.value}" not found.
146
+ Available: ${u||"none"}`)}}else{let y=P.find(c=>c.id===i)?.name||i;p(i?`Current model: ${y}`:"No model selected. Using agent mode.")}return!0}case"agent":{if(!I.value)return N.length===0?(p("No agents available."),!0):(_e("agent"),!0);let y=I.value.toLowerCase(),c=N.find(u=>u.id.toLowerCase()===y||u.name.toLowerCase().includes(y));if(c)c.id!==l?ie(`Switched to agent: ${c.name} (new chat)`):p(`Switched to agent: ${c.name}`),d(c.id),a(void 0);else{let u=N.map(g=>g.name).join(", ");p(`Agent "${I.value}" not found.
147
+ Available: ${u||"none"}`)}return!0}case"skills":{if(!I.value)return _e("skills"),!0;let y=I.value.toLowerCase();return(We.length?Promise.resolve(We):bt().catch(()=>[])).then(u=>{let g=u.find($=>$.id.toLowerCase()===y||$.name.toLowerCase().includes(y));p(g?`Skill: ${g.name}
148
+ ${g.description}
149
+ Provider: ${g.provider}
150
+ Author: ${g.author.name}
151
+ ID: ${g.id}`:`Skill "${I.value}" not found.`)}),!0}case"schedules":{if(!I.value)return _e("schedules"),!0;let y=I.value.toLowerCase();return(ze.length?Promise.resolve(ze):xt().catch(()=>[])).then(u=>{let g=u.find($=>$.id.toLowerCase()===y||$.name.toLowerCase().includes(y));if(g){let $=E=>{if(E.type==="no-repeat")return"No repeat";let{interval:J}=E;switch(J.unit){case"minutes":return`Every ${J.every} min`;case"hours":return`Every ${J.every} hr`;case"days":return`Every ${J.every} day at ${String(J.time.hour).padStart(2,"0")}:${String(J.time.minute).padStart(2,"0")}`;case"weeks":return`Every ${J.every} week`;case"months":return`Every ${J.every} month`;default:return"Unknown"}},k=g.nextRunAt?new Date(g.nextRunAt).toLocaleString():"-";p(`Schedule: ${g.name}
152
+ Agent: ${g.agent.name}
153
+ Status: ${g.isActive?"Active":"Paused"}
154
+ Repeat: ${$(g.config)}
155
+ Next Run: ${k}
156
+ ID: ${g.id}`)}else p(`Schedule "${I.value}" not found.`)}),!0}case"connectors":{if(l){let c=v?.connectors||[];if(c.length===0)p("No agent connectors.");else{let u=c.map(g=>` - ${g.name}`).join(`
157
+ `);p(`Agent connectors:
158
+ ${u}`)}return!0}let y=O.filter(c=>x?.includes(c.id));if(y.length===0)p("No active connectors.");else{let c=y.map(u=>` - ${u.name}`).join(`
159
+ `);p(`Active connectors:
160
+ ${c}`)}return!0}case"capabilities":{if(l){let u=(v?.capabilities||[]).map(g=>ce.get(g)??g);return p(u.length>0?`Agent capabilities:
161
+ ${u.map(g=>` - ${g}`).join(`
162
+ `)}`:"No agent capabilities."),!0}let y=[];return m&&y.push("Sandbox"),S&&y.push("Web Search"),V&&y.push("Image Generation"),ae&&y.push("Chart"),Se&&y.push("FileSystem"),p(y.length>0?`Active capabilities:
163
+ ${y.map(c=>` - ${c}`).join(`
164
+ `)}`:"No capabilities enabled."),!0}case"chats":return p(o?`Current chat: ${o}`:`Current chat: ${n.slice(0,8)}...`),!0;case"workspace":{if(!A)return p("Not authenticated."),!0;let y=new B;if(!I.value){try{let{workspaces:u}=await y.getWorkspaces(A.accessToken);if(u.length===0)p("No workspaces found.");else{let g=u.map($=>` ${$.id===A.workspaceId?"* ":" "}${$.name}
165
+ ID: ${$.id}`);p(`Workspaces:
166
+ ${g.join(`
167
+ `)}`)}}catch(u){p(`Failed to load workspaces: ${u instanceof Error?u.message:"Unknown error"}`)}return!0}let c=I.value;try{let{workspaces:u}=await y.getWorkspaces(A.accessToken),g=u.find(k=>k.id===c);if(!g)return p(`Workspace not found: ${c}`),!0;let{TokenStorage:$}=await import("./token-storage-JKKVPVG3.js");await $.saveWorkspaceId(c),p(`Switched to workspace: ${g.name}`),p("Please restart the chat to apply changes.")}catch(u){p(`Failed to switch workspace: ${u instanceof Error?u.message:"Unknown error"}`)}return!0}case"budget":{if(!A)return p("Not authenticated."),!0;let y=new B;if(!I.value){try{let g=await y.getBudget(A.accessToken,A.workspaceId);g.budget===null?p("No budget set for this workspace."):p(`Current budget: $${g.budget}`)}catch(g){p(`Failed to get budget: ${g instanceof Error?g.message:"Unknown error"}`)}return!0}let c=I.value.toLowerCase();if(c==="clear"||c==="null"){try{await y.updateBudget(A.accessToken,A.workspaceId,null),p("Budget cleared.")}catch(g){p(`Failed to clear budget: ${g instanceof Error?g.message:"Unknown error"}`)}return!0}let u=parseFloat(c);if(isNaN(u)||u<0)return p("Invalid budget amount. Must be a positive number."),!0;try{await y.updateBudget(A.accessToken,A.workspaceId,c),p(`Budget set to: $${c}`)}catch(g){p(`Failed to set budget: ${g instanceof Error?g.message:"Unknown error"}`)}return!0}case"usage":{if(!A)return p("Not authenticated."),!0;let y=new B;try{let c=[],u,g=0,$=10;do{let ve=await y.getMonthlyUsages(A.accessToken,A.workspaceId,{nextKey:u,limit:20});if(c.push(...ve.monthlyUsages),u=ve.nextKey,g++,g>=$){p(`Warning: Showing first ${c.length} entries (pagination limit reached)`);break}}while(u);if(c.length===0)return p("No usage data found for this workspace."),!0;let k=0,E=0;for(let ve of c)k+=parseFloat(ve.totalCost),E+=ve.operationCount;let J=[...c].toSorted((ve,ut)=>parseFloat(ut.totalCost)-parseFloat(ve.totalCost)),G=10,ue=J.slice(0,G),Ue=[`Total Cost: $${k.toFixed(2)}`,`Total Operations: ${E.toLocaleString()}`,`Users: ${c.length}`,"",`Top ${ue.length} Users by Cost:`,...ue.map(ve=>` ${ve.user.name}: $${parseFloat(ve.totalCost).toFixed(2)} (${ve.operationCount.toLocaleString()} ops)`)];c.length>G&&(Ue.push("",`... and ${c.length-G} more users`),Ue.push("Use CLI command for full list: entrydesk usage --limit <n> --sort-by <cost|operations>")),p(Ue.join(`
168
+ `))}catch(c){p(`Failed to get usage: ${c instanceof Error?c.message:"Unknown error"}`)}return!0}case"status":{let y=H.getCurrentProfileName(),c=i?P.find(k=>k.id===i)?.name||i:null,u=l?N.find(k=>k.id===l)?.name||l:null,g=x?O.filter(k=>x.includes(k.id)).map(k=>k.name):[],$=[];return m&&$.push("Sandbox"),S&&$.push("Web Search"),V&&$.push("Image Gen"),ae&&$.push("Chart"),Se&&$.push("FileSystem"),$e.getEmail().then(k=>{let E=[`Profile: ${y}${y!=="default"?" (non-default)":""}`,k?`Logged in as: ${k}`:"Not logged in",A?.workspaceId?`Workspace: ${A.workspaceId}`:null,_?`Chat ID: ${n}`:null,c?`Model: ${c}`:null,u?`Agent: ${u}`:null,`Connectors: ${g.length>0?g.join(", "):"none"}`,`Capabilities: ${$.length>0?$.join(", "):"none"}`].filter(Boolean);p(E.join(`
169
+ `))}).catch(()=>{let k=[`Profile: ${y}`,"Not logged in",_?`Chat ID: ${n}`:null,c?`Model: ${c}`:null,u?`Agent: ${u}`:null,`Connectors: ${g.length>0?g.join(", "):"none"}`,`Capabilities: ${$.length>0?$.join(", "):"none"}`].filter(Boolean);p(k.join(`
170
+ `))}),!0}case"profile":{let y=I.value?I.value.split(/\s+/).filter(Boolean):[];if(y.length===0)return _e("profile"),!0;let c=y[0]?.toLowerCase()||"list",u=y[1],g=y[2],$=H.getProfileNames(),k=H.getCurrentProfileName(),E=H.getOverrideProfile(),J=(G,ue=!1)=>{if(G)return G;if(ue&&$.length===1)return $[0];throw new Error("Profile name is required when multiple profiles exist.")};try{if(c==="list"){let G=[`Profiles (${$.length}):`];for(let ue of $){let Ue=ue===k?" (current)":"";G.push(` ${ue}${Ue}`)}return p(G.join(`
171
+ `)),!0}if(c==="current")return p(`Current profile: ${k}`),!0;if(c==="show"){let G=J(u,!0),ue=ne.getAll(G),Ue=await $e.getAll(G),ve=!!Ue?.accessToken,ut=ue.capabilities?Object.entries(ue.capabilities).filter(([,ko])=>ko).map(([ko])=>ko):[],As=ue.connectors?.defaults&&ue.connectors.defaults.length>0?ue.connectors.defaults.join(", "):"unset",Es=[`Profile: ${G}${G===k?" (current)":""}`,`API URL: ${ue.apiUrl??"default"}`,`Hub URL: ${ue.hubUrl??"default"}`,`Model: ${ue.model?.default??"unset"}`,`Connectors: ${As}`,`Capabilities: ${ut.length>0?ut.join(", "):"none"}`,ve?`Logged in as: ${Ue?.email??"unknown"}`:"Not logged in",ve&&Ue?.workspaceId?`Workspace ID: ${Ue.workspaceId}`:null].filter(Boolean);return p(Es.join(`
172
+ `)),!0}if(c==="create"){let G=u||H.DEFAULT_PROFILE;return H.createProfile(G),p(`Profile created: ${G}`),!0}if(c==="use"||c==="switch"){let G=J(u,!0);return H.setOverrideProfile(G),H.setCurrentProfile(G),he(G),await Xe(),ie(`Switched to profile: ${G} (new chat)`),!0}if(c==="delete"||c==="remove"||c==="rm"){let G=J(u,!0),ue=G===k,Ue=H.deleteProfile(G),ve=`Profile deleted: ${G}`;if(ue)H.setOverrideProfile(Ue.currentProfile),he(Ue.currentProfile),await Xe(),ie(`${ve}
173
+ Switched to profile: ${Ue.currentProfile} (new chat)`);else if(E===G){let ut=H.getCurrentProfileName();H.setOverrideProfile(ut),he(ut),await Xe(),ie(`${ve}
174
+ Switched to profile: ${ut} (new chat)`)}else p(ve);return!0}if(c==="rename"||c==="move"||c==="mv"){let G=J(u,!0);if(!g)throw new Error("New profile name is required.");let ue=H.renameProfile(G,g);return p(`Profile renamed: ${G} -> ${g}`),E===G?(H.setOverrideProfile(g),he(g)):ue.currentProfile===g&&he(g),!0}if(c==="clone"||c==="copy"){let G=J(u,!0);if(!g)throw new Error("Target profile name is required.");let ue=ne.getAll(G);return H.createProfile(g),ne.setAll(ue,g),await $e.clear(g),p(`Profile cloned: ${G} -> ${g}`),!0}p(`Unknown profile command: ${c}`)}catch(G){let ue=G instanceof Error?G.message:"Unknown error";p(`Profile error: ${ue}`)}return!0}case"open-in-browser":{let y=Qe().hubUrl.replace(/\/$/,""),u=_||W.some(k=>k.role!=="system")?`/chat/${n}`:"/chat/new",g=l?`?agentId=${encodeURIComponent(l)}`:"",$=`${y}${u}${g}`;try{await Jn($),p(`Opened in browser: ${$}`)}catch(k){p(`Failed to open browser: ${k instanceof Error?k.message:"Unknown error"}
175
+ URL: ${$}`)}return!0}case"share":{if(!A)return p("Not authenticated."),!0;if(!(_||W.some(c=>c.role!=="system")))return p("No conversation to share. Start a chat first."),!0;try{let u=await new B().createChatShare(A.accessToken,A.workspaceId,n,"public"),$=`${Qe().hubUrl.replace(/\/$/,"")}/share/${u.id}`;p(`Share link: ${$}`)}catch(c){p(`Failed to create share link: ${c instanceof Error?c.message:"Unknown error"}`)}return!0}case"delete":return A?_?(kt(!0),p("Delete this chat? (y/N)"),!0):(p("No chat to delete."),!0):(p("Not authenticated."),!0);case"quit":return Q(),!0;case"unknown":return p(`Unknown command: ${I.input}
176
+ Type /help for available commands.`),!0;default:return!1}},[p,P,N,O,We,ze,i,l,x,m,S,V,ae,Se,n,o,Q,_e,ie,ce,v,_,W,bt,xt,D,a,d,b,a,he,Xe]),Kt=nt(I=>{if(mt.current=!1,ct){(I===""||I.startsWith("/"))&&(t(I),I.startsWith("/")&&kt(!1));return}if(t(I),wt(I),He!==null&&Ye(null),f&&(w(null),oe([])),I.startsWith("/")&&!I.includes(" ")){let y=Hn(I);fe(y),F(0),L(y.length>0)}else L(!1),fe([])},[f,He,ct,t]),At=nt((I,y=!1)=>{if(I>=0&&I<z.length){let c=z[I];L(!1),fe([]),c.name==="model"?(t("/model "),_e("model")):c.name==="agent"?(t("/agent "),_e("agent")):c.name==="skills"?(t("/skills "),_e("skills")):c.name==="schedules"?(t("/schedules "),_e("schedules")):c.name==="connectors"?(t("/connectors "),_e("connectors")):c.name==="capabilities"?(t("/capabilities "),_e("capabilities")):c.name==="chats"?(t("/chats "),_e("chats")):c.name==="profile"?(t("/profile "),_e("profile")):y?(t(""),Ct({type:c.name})):t(`/${c.name}`)}},[z,_e,t,Ct]),qt=nt(async I=>{mt.current=!1;let y=I.trim();if(!y||ct)return;if(f==="model"&&T.length>0){let u=T[U];u&&(l?ie(`Switched to model: ${u.name} (new chat)`):p(`Switched to model: ${u.name}`),a(u.id),d(void 0),b(null)),w(null),oe([]),t("");return}if(f==="agent"&&T.length>0){let u=T[U];u&&(u.id!==l?ie(`Switched to agent: ${u.name} (new chat)`):p(`Switched to agent: ${u.name}`),d(u.id),a(void 0)),w(null),oe([]),t("");return}if(f==="skills"&&T.length>0){let u=T[U];if(u){let g=We.find($=>$.id===u.id);g&&p(`Skill: ${g.name}
177
+ ${g.description}
178
+ Provider: ${g.provider}
179
+ Author: ${g.author.name}
180
+ ID: ${g.id}`)}w(null),oe([]),t("");return}if(f==="schedules"&&T.length>0){let u=T[U];if(u){let g=ze.find($=>$.id===u.id);if(g){let $=E=>{if(E.type==="no-repeat")return"No repeat";let{interval:J}=E;switch(J.unit){case"minutes":return`Every ${J.every} min`;case"hours":return`Every ${J.every} hr`;case"days":return`Every ${J.every} day at ${String(J.time.hour).padStart(2,"0")}:${String(J.time.minute).padStart(2,"0")}`;case"weeks":return`Every ${J.every} week`;case"months":return`Every ${J.every} month`;default:return"Unknown"}},k=g.nextRunAt?new Date(g.nextRunAt).toLocaleString():"-";p(`Schedule: ${g.name}
181
+ Agent: ${g.agent.name}
182
+ Status: ${g.isActive?"Active":"Paused"}
183
+ Repeat: ${$(g.config)}
184
+ Next Run: ${k}
185
+ ID: ${g.id}`)}}w(null),oe([]),t("");return}if(f==="connectors"){let u=Array.from(rt);C(u.length>0?u:void 0),ne.setDefaultConnectorIds(u);let g=O.filter($=>rt.has($.id)).map($=>$.name);p(g.length>0?`Active connectors: ${g.join(", ")}`:"All connectors disabled."),w(null),oe([]),t("");return}if(f==="capabilities"){let u=Oe.has("sandbox"),g=Oe.has("webSearch"),$=Oe.has("imageGeneration"),k=Oe.has("chart"),E=Oe.has("fileSystem");h(u),R(g),Z($),Y(k),j(E),ne.setCapabilities({sandbox:u,webSearch:g,imageGeneration:$,chart:k}),ne.setLocalTools({fileSystem:E});let J=[];u&&J.push("Sandbox"),g&&J.push("Web Search"),$&&J.push("Image Generation"),k&&J.push("Chart"),E&&J.push("FileSystem"),p(J.length>0?`Active capabilities: ${J.join(", ")}`:"All capabilities disabled."),w(null),oe([]),t("");return}if(f==="profile"&&T.length>0){let u=T[U];if(u){let g=H.getCurrentProfileName();u.id!==g?(H.setOverrideProfile(u.id),H.setCurrentProfile(u.id),he(u.id),Xe(),ie(`Switched to profile: ${u.name}`)):p(`Already using profile: ${u.name}`)}w(null),oe([]),t("");return}if(se&&z.length>0){At(Te,!0);return}Ye(null),wt(""),wo(u=>u.length>0&&u[u.length-1]===y?u:[...u,y]);let c=Vn(y);if(c){await Ct(c),t(""),L(!1);return}if(M){p("Please wait for file uploads to complete.");return}t(""),L(!1),ke(y)},[ke,Ct,se,z,Te,At,f,T,U,rt,Oe,O,We,ze,p,t,l,ie,a,d,b,C,h,R,Z,Y,j,M,he,Xe,ct,A,_,n]);return kr((I,y)=>{if(y.ctrl&&I==="c"){if(e.length>0){Kt(""),mt.current=!0,p("Press Ctrl+C again to exit.");return}if(mt.current){Q();return}Q();return}if(y.ctrl&&I==="o"){q(c=>!c);return}if(ct){if(y.escape||y.return||I==="n"||I==="N"){kt(!1),t(""),p("Chat deletion cancelled.");return}if(I==="y"||I==="Y"){kt(!1),t(""),A&&_&&new B().deleteChat(A.accessToken,A.workspaceId,n).then(()=>{ie("Chat deleted. Started a new chat.")}).catch(u=>{p(`Failed to delete chat: ${u.message||"Unknown error"}`)});return}return}if(f&&T.length>0){if(y.upArrow){Ce(c=>c<=0?T.length-1:c-1);return}if(y.downArrow){Ce(c=>c>=T.length-1?0:c+1);return}if(y.escape){w(null),oe([]),t("");return}if(y.return){if(f==="model"){let c=T[U];c&&(l?ie(`Switched to model: ${c.name} (new chat)`):p(`Switched to model: ${c.name}`),a(c.id),d(void 0),b(null),ne.setDefaultModel(c.id))}else if(f==="agent"){let c=T[U];c&&(c.id!==l?ie(`Switched to agent: ${c.name} (new chat)`):p(`Switched to agent: ${c.name}`),d(c.id),a(void 0))}else if(f==="skills"){let c=T[U];if(c){let u=We.find(g=>g.id===c.id);u&&p(`Skill: ${u.name}
186
+ ${u.description}
187
+ Provider: ${u.provider}
188
+ Author: ${u.author.name}
189
+ ID: ${u.id}`)}}else if(f==="schedules"){let c=T[U];if(c){let u=ze.find(g=>g.id===c.id);if(u){let g=k=>{if(k.type==="no-repeat")return"No repeat";let{interval:E}=k;switch(E.unit){case"minutes":return`Every ${E.every} min`;case"hours":return`Every ${E.every} hr`;case"days":return`Every ${E.every} day at ${String(E.time.hour).padStart(2,"0")}:${String(E.time.minute).padStart(2,"0")}`;case"weeks":return`Every ${E.every} week`;case"months":return`Every ${E.every} month`;default:return"Unknown"}},$=u.nextRunAt?new Date(u.nextRunAt).toLocaleString():"-";p(`Schedule: ${u.name}
190
+ Agent: ${u.agent.name}
191
+ Status: ${u.isActive?"Active":"Paused"}
192
+ Repeat: ${g(u.config)}
193
+ Next Run: ${$}
194
+ ID: ${u.id}`)}}}else if(f==="connectors"){let c=Array.from(rt);C(c.length>0?c:void 0),ne.setDefaultConnectorIds(c);let u=O.filter(g=>rt.has(g.id)).map(g=>g.name);p(u.length>0?`Active connectors: ${u.join(", ")}`:"All connectors disabled.")}else if(f==="capabilities"){let c=Oe.has("sandbox"),u=Oe.has("webSearch"),g=Oe.has("imageGeneration"),$=Oe.has("chart"),k=Oe.has("fileSystem");h(c),R(u),Z(g),Y($),j(k),ne.setCapabilities({sandbox:c,webSearch:u,imageGeneration:g,chart:$}),ne.setLocalTools({fileSystem:k});let E=[];c&&E.push("Sandbox"),u&&E.push("Web Search"),g&&E.push("Image Generation"),$&&E.push("Chart"),k&&E.push("FileSystem"),p(E.length>0?`Active capabilities: ${E.join(", ")}`:"All capabilities disabled.")}else if(f==="chats"){let c=T[U];if(c){let u=yo.find(g=>g.id===c.id);u&&A&&(s(u.id),r(u.title||void 0),ge(!0),new B().getMessages(A.accessToken,A.workspaceId,u.id,20).then(({messages:$})=>{let k=$.filter(E=>E.role==="user"||E.role==="assistant").map(E=>({role:E.role,content:ht(E.parts,!1),parts:E.parts})).filter(E=>E.content).toReversed();D(k),p(`Switched to: ${u.title||"Untitled"}`)}).catch(()=>{p("Failed to load chat messages.")}))}}else if(f==="profile"){let c=T[U];if(c){let u=H.getCurrentProfileName();c.id!==u?(H.setOverrideProfile(c.id),H.setCurrentProfile(c.id),he(c.id),Xe(),ie(`Switched to profile: ${c.name}`)):p(`Already using profile: ${c.name}`)}}w(null),oe([]),t("");return}if(I===" "&&(f==="connectors"||f==="capabilities")){let c=T[U];c&&(f==="connectors"?it:at)(g=>{let $=new Set(g);return $.has(c.id)?$.delete(c.id):$.add(c.id),$});return}if(I==="a"&&(f==="connectors"||f==="capabilities")){(f==="connectors"?it:at)(new Set(T.map(u=>u.id)));return}if(I==="n"&&(f==="connectors"||f==="capabilities")){(f==="connectors"?it:at)(new Set);return}return}if(se&&z.length>0){if(y.upArrow){F(c=>c<=0?z.length-1:c-1);return}if(y.downArrow){F(c=>c>=z.length-1?0:c+1);return}if(y.escape){L(!1),fe([]);return}if(y.tab){At(Te);return}}if(y.upArrow){if(e.includes(`
195
+ `)||lt.length===0)return;if(He===null){wt(e);let u=lt.length-1;Ye(u),t(lt[u]);return}let c=Math.max(0,He-1);Ye(c),t(lt[c]);return}if(y.downArrow){if(e.includes(`
196
+ `)||He===null)return;if(He>=lt.length-1){Ye(null),t(Vt);return}let c=He+1;Ye(c),t(lt[c])}}),{suggestions:z,suggestionIndex:Te,showSuggestions:se,argMode:f,argItems:T,argIndex:U,selectedConnectorIds:rt,selectedCapabilities:Oe,deleteConfirmMode:ct,handleInputChange:Kt,handleSubmit:qt}}import{useCallback as jt,useRef as xr,useState as Cr}from"react";function zn({credentials:e,currentModel:t,modelProviders:n,onUploadSuccess:s,onUploadError:o}){let[r,i]=Cr([]),a=xr(0),l=jt(h=>{if(!(!Array.isArray(n)||n.length===0)){for(let S of n)if(S.models.some(V=>V.id===h))return S.id;return n[0]?.id}},[n]),d=jt(async h=>{if(!e){o?.(h.filename,"Not logged in");return}if(!Array.isArray(n)||n.length===0){o?.(h.filename,"Model providers not loaded yet. Please wait and try again.");return}let S=t?l(t):n[0]?.id;if(!S){o?.(h.filename,"No model provider available");return}let R=`file-${++a.current}`;i(V=>[...V,{id:R,filename:h.filename,mimeType:h.mimeType,status:"uploading"}]);try{let Z=await new B().uploadFile(e.accessToken,e.workspaceId,h,S);i(ae=>ae.map(Y=>Y.id===R?{...Y,status:"uploaded",fileId:Z.id}:Y)),s?.(h.filename)}catch(V){let Z=V instanceof Error?V.message:"Upload failed";i(ae=>ae.map(Y=>Y.id===R?{...Y,status:"error",error:Z}:Y)),o?.(h.filename,Z)}},[e,t,l,n,s,o]),v=jt(h=>{i(S=>S.filter(R=>R.id!==h))},[]),b=jt(()=>{i([])},[]),x=jt(()=>r.filter(h=>h.status==="uploaded"&&h.fileId).map(h=>h.fileId),[r]),C=r.some(h=>h.status==="uploading"),m=r.length>0;return{pendingFiles:r,addFile:d,removeFile:v,clearFiles:b,getUploadedFileIds:x,hasUploadingFiles:C,hasFiles:m}}import{jsx as X,jsxs as de}from"react/jsx-runtime";var Sr=[" ______ _ ____ _","| ____| | | | _ \\ | |","| |__ _ __ | |_ _ __ _ _ | | | | ___ ___| | __","| __| | '_ \\| __| '__| | | || | | |/ _ \\/ __| |/ /","| |____| | | | |_| | | |_| || |_| | __/\\__ \\ <","|______|_| |_|\\__|_| \\__, ||____/ \\___||___/_|\\_\\"," __/ |"," |___/"],Tr=[Ro,Ro,Lo,Lo,gt,gt,gt,gt],Xn=Sr.map((e,t)=>`${Tr[t]??gt}${e}${re}`).join(`
197
+ `),vr=`${gt}EntryDesk${re}`,Ir=500;function Pr(e){let t="",n=0;for(;n<e.length;){if(e.charCodeAt(n)===27&&e[n+1]==="["){for(n+=2;n<e.length;){let s=e.charCodeAt(n);if(s>=64&&s<=126){n+=1;break}n+=1}continue}t+=e[n],n+=1}return t}function Ar(e){let t=Pr(e);return Math.max(...t.split(`
198
+ `).map(n=>n.length))}function Er(e){let t=Ar(Xn);return e>=t?Xn:vr}function Zn({agentId:e,model:t,message:n,chatId:s,chatTitle:o,connectorIds:r,enableSandbox:i=!0,enableWebSearch:a=!1,enableImageGeneration:l=!1,enableChart:d=!1,enableFileSystem:v=!0}){let b=process.stdout.columns??80,x=Er(b),C=Yn(null),m=En(s,o),{state:h,setState:S,messages:R,setMessages:V,input:Z,setInput:ae,chatId:Y,setChatId:Se,currentChatTitle:j,setCurrentChatTitle:P,hasPersistedChat:N,setHasPersistedChat:O,credentials:W,setCredentials:_,currentResponse:ge,setCurrentResponse:D,fullOutput:p,setFullOutput:ie,addSystemMessage:ke,startNewChat:q}=m,{credentials:A}=_n(S);co(()=>{A&&!W&&_(A)},[A,W,_]);let{availableConnectors:te,availableModels:ee,availableAgents:pe,modelProviders:ce,loading:M}=Dn(W),{currentModel:Q,setCurrentModel:z,currentAgentId:fe,setCurrentAgentId:Te,activeConnectorIds:F,setActiveConnectorIds:se}=Mn(t,e,r),L=Yn(!1);co(()=>{if(!L.current){if(L.current=!0,!t&&!e){let k=ne.getDefaultModel();k&&z(k)}if(!r&&!e){let k=ne.getDefaultConnectorIds();k&&se(k.length>0?k:void 0)}}},[t,e,r,z,se]);let{currentAgentDetails:f}=Wn(fe,W),{sandbox:w,setSandbox:T,webSearch:oe,setWebSearch:U,imageGeneration:Ce,setImageGeneration:rt,chart:it,setChart:Oe,fileSystem:at,setFileSystem:yo,capabilityLabelMap:Gt}=Fn(i,a,l,d,v),{pendingFiles:We,addFile:yt,removeFile:ze,clearFiles:Ht,getUploadedFileIds:lt,hasUploadingFiles:wo,hasFiles:He}=zn({credentials:W,currentModel:Q,modelProviders:ce,onUploadSuccess:k=>{ke(`\u2713 Attached: ${k}`)},onUploadError:(k,E)=>{ke(`\u2717 Failed to upload ${k}: ${E}`)}}),{sendMessage:Ye}=On({chatId:Y,credentials:W,currentAgentId:fe,currentModel:Q,activeConnectorIds:F,sandbox:w,webSearch:oe,imageGeneration:Ce,chart:it,localTools:at,fullOutput:p,setMessages:V,setState:S,setCurrentResponse:D,setCredentials:_,setHasPersistedChat:O,getFileIds:lt,clearFiles:Ht}),Vt=Fo(k=>{q(k),D("")},[q]),[wt,mt]=$r(!1),ct=Fo(async k=>{let E=k.text.trim(),J=ro(E);if(/^https?:\/\//.test(J))return;if(await vn(E)&&Tn(J)){let ue=await In(E);ue&&(k.preventDefault(),await yt(ue))}},[yt]),kt=Fo(async()=>{if(!(wt||h.status!=="ready")){if(M||ce.length===0){ke("Please wait for resources to load before pasting images.");return}ke("Reading clipboard..."),mt(!0);try{let k=await Sn();if(k){let E=`clipboard-${Date.now()}.png`;ke(`Uploading: ${E} (${Math.round(k.buffer.length/1024)}KB)`),await yt({buffer:k.buffer,filename:E,mimeType:k.mime})}else ke("No image found in clipboard. Copy an image first.")}catch(k){let E=k instanceof Error?k.message:"Failed to read clipboard";ke(`Clipboard error: ${E}`)}finally{mt(!1)}}},[yt,ke,wt,h.status,M,ce.length]),{suggestions:bt,suggestionIndex:xt,showSuggestions:_e,argMode:he,argItems:Xe,argIndex:Ct,selectedConnectorIds:Kt,selectedCapabilities:At,deleteConfirmMode:qt,handleInputChange:I,handleSubmit:y}=qn({input:Z,setInput:ae,chatId:Y,setChatId:Se,currentChatTitle:j,setCurrentChatTitle:P,currentModel:Q,setCurrentModel:z,currentAgentId:fe,setCurrentAgentId:Te,currentAgentDetails:f,setCurrentAgentDetails:()=>{},activeConnectorIds:F,setActiveConnectorIds:se,sandbox:w,setSandbox:T,webSearch:oe,setWebSearch:U,imageGeneration:Ce,setImageGeneration:rt,chart:it,setChart:Oe,fileSystem:at,setFileSystem:yo,availableModels:ee,availableAgents:pe,availableConnectors:te,messages:R,hasPersistedChat:N,setHasPersistedChat:O,setMessages:V,addSystemMessage:ke,startNewChat:Vt,sendMessage:Ye,setFullOutput:ie,credentials:W,setCredentials:_,setState:S,defaultCapabilities:{sandbox:i,webSearch:a,imageGeneration:l,chart:d,fileSystem:v},capabilityLabelMap:Gt,hasUploadingFiles:wo});if(jo((k,E)=>{(E.ctrl||E.meta)&&k==="v"&&kt()},{isActive:h.status==="ready"&&!he}),jo((k,E)=>{if(!E.escape)return;let J=Date.now(),G=C.current;C.current=J,!(!G||J-G>Ir)&&(he||_e||(C.current=null,He&&Ht(),Z.length>0&&I("")))},{isActive:h.status==="ready"}),jo((k,E)=>{E.return&&(Vt("Started a new chat."),S({status:"ready"}))},{isActive:h.status==="error"}),co(()=>{if(W&&!M&&h.status==="loading")if(!Q&&!fe){let k=ne.getDefaultModel(),E=k&&ee.some(G=>G.id===k),J=E?k:ee[0]?.id;J?(E||ne.setDefaultModel(J),z(J),S({status:"ready"})):pe.length===0?S({status:"no-model"}):S({status:"ready"})}else S({status:"ready"})},[W,M,Q,fe,ee,pe,h.status,z,S]),co(()=>{n&&W&&h.status==="ready"&&Ye(n)},[W,n]),h.status==="loading")return de(Pe,{flexDirection:"column",children:[X(K,{children:x}),de(Pe,{children:[X(K,{color:"cyan",children:X(Bo,{type:"dots"})}),X(K,{children:" Initializing chat..."})]})]});if(h.status==="not-logged-in")return de(Pe,{flexDirection:"column",children:[X(K,{children:x}),X(K,{color:"yellow",children:"Not logged in"}),X(K,{dimColor:!0,children:"Run `entrydesk login` to authenticate first."})]});if(h.status==="no-workspace")return de(Pe,{flexDirection:"column",children:[X(K,{children:x}),X(K,{color:"yellow",children:"No workspace selected"}),X(K,{dimColor:!0,children:"Run `entrydesk workspaces` to select a workspace first."})]});if(h.status==="no-model")return de(Pe,{flexDirection:"column",children:[X(K,{children:x}),X(K,{color:"yellow",children:"No model or agent specified"}),s&&X(K,{dimColor:!0,children:"Could not determine the model used in this chat."}),X(K,{dimColor:!0,children:"Please specify a model with --model or use an agent with -a."}),X(K,{dimColor:!0,children:"Example: entrydesk chat -c 1 -i --model gemini-2.5-flash-lite"})]});if(h.status==="error")return de(Pe,{flexDirection:"column",children:[X(K,{children:x}),de(K,{color:"red",children:["Error: ",h.message]}),X(K,{dimColor:!0,children:"Press Enter to start a new chat, or Ctrl+C to exit"})]});let c=fe?f?f.connectors&&f.connectors.length>0?f.connectors.map(k=>k.name).join(", "):"none":"loading...":F&&F.length>0?te.filter(k=>F.includes(k.id)).map(k=>k.name).join(", ")||`${F.length} connector(s)`:"none",u=[];if(fe)if(f?.capabilities)for(let k of f.capabilities)u.push(Gt.get(k)??k);else u.push("loading...");else w&&u.push("Sandbox"),oe&&u.push("Web"),Ce&&u.push("Image"),it&&u.push("Chart");at&&u.push("FileSystem");let g=H.getCurrentProfileName(),$=g!=="default";return de(Pe,{flexDirection:"column",children:[de(Pe,{marginBottom:1,flexDirection:"column",children:[X(K,{children:x}),de(Pe,{children:[X(K,{bold:!0,color:"cyan",children:j?`Continuing: ${j}`:"EntryDesk CLI"}),de(K,{dimColor:!0,children:[" v","1.3.2"]}),$&&de(K,{color:"magenta",children:[" [",g,"]"]}),X(K,{dimColor:!0,children:" (type /help for commands)"})]})]}),R.map((k,E)=>{let J=k.parts&&p?ht(k.parts,!0):k.content,G=k.role==="user"?"green":k.role==="system"?"yellow":"blue",ue=k.role==="user"?"You":k.role==="system"?"System":"Assistant";return de(Pe,{flexDirection:"column",marginBottom:1,children:[de(K,{bold:!0,color:G,children:[ue,":"]}),X(Do,{text:J})]},E)}),ge&&de(Pe,{flexDirection:"column",marginBottom:1,children:[X(K,{bold:!0,color:"blue",children:"Assistant:"}),X(Do,{text:ge})]}),h.status==="ready"&&X(an,{suggestions:bt,activeIndex:xt,visible:_e}),h.status==="ready"&&he&&X(rn,{items:Xe,activeIndex:Ct,pageSize:he==="agent"||he==="skills"||he==="model"?5:10,selectedIds:he==="connectors"?Kt:he==="capabilities"?At:void 0,multiSelect:he==="connectors"||he==="capabilities",visible:!0,title:he==="model"?"Select model:":he==="agent"?"Select agent:":he==="skills"?"Select skill:":he==="connectors"?"Select connectors:":he==="capabilities"?"Select capabilities:":"Select chat:"}),h.status==="sending"&&!ge?de(Pe,{children:[X(K,{color:"cyan",children:X(Bo,{type:"dots"})}),X(K,{children:" Thinking..."})]}):h.status==="ready"&&!he?de(Pe,{flexDirection:"column",children:[qt&&X(Pe,{marginBottom:1,children:X(K,{color:"yellow",children:"\u26A0\uFE0F Delete this chat? (y/N) "})}),He&&!qt&&de(Pe,{marginBottom:1,flexDirection:"row",gap:1,children:[X(K,{dimColor:!0,children:"Attachments:"}),We.map((k,E)=>de(K,{children:[k.status==="uploading"?de(K,{color:"yellow",children:[X(Bo,{type:"dots"})," ",k.filename]}):k.status==="error"?de(K,{color:"red",children:["\u2717 ",k.filename]}):de(K,{color:"green",children:["\u2713 ",k.filename]}),E<We.length-1&&X(K,{children:", "})]},k.id))]}),de(Pe,{children:[X(K,{color:"green",children:"> "}),X(gn,{value:Z,onChange:I,onSubmit:y,onPaste:ct,leadingOffset:2,multiline:!0})]})]}):null,de(Pe,{marginTop:1,flexDirection:"column",children:[de(Pe,{gap:2,children:[de(K,{children:[X(K,{dimColor:!0,children:"Model: "}),X(K,{color:"magenta",children:fe?f?.model?.name||"loading...":ee.find(k=>k.id===Q)?.name||Q||"none"})]}),de(K,{children:[X(K,{dimColor:!0,children:"Connectors: "}),X(K,{color:"cyan",children:c})]}),de(K,{children:[X(K,{dimColor:!0,children:"Capabilities: "}),X(K,{color:"green",children:u.length>0?u.join(", "):"none"})]})]}),de(K,{dimColor:!0,children:["Esc Esc: Clear input & attachments | Ctrl+V: Paste image | Ctrl+O: Toggle full output ",p?"(ON)":"(OFF)"," | Ctrl+C: Exit"]})]})]})}import{jsx as Rr}from"react/jsx-runtime";async function _r(){let e=[];for await(let t of process.stdin)e.push(t);return Buffer.concat(e).toString("utf8").trim()}async function Dr(e,t,n,s){if(s<1)return console.error("Chat number must be 1 or greater"),null;let{chats:o}=await e.getChats(t,n,20);if(o.length===0)return console.error("No chats found. Start a new chat first."),null;if(s>o.length)return console.error(`Chat number ${s} not found. You have ${o.length} recent chats.`),console.error("Use `entrydesk chats` to see available chats."),null;let r=o[s-1],i;if(!r.agentId){let{messages:a}=await e.getMessages(t,n,r.id,10);i=a.find(d=>d.role==="assistant"&&d.modelId)?.modelId}return{chat:r,modelId:i}}var Tt="\x1B[2m",Re="\x1B[0m",Wo="\x1B[36m",os="\x1B[33m",fo="\x1B[32m",Qn="stream-json";function es(e,t,n,s){e&&t&&(console.error(`Error: Cannot use both ${n} and ${s}`),process.exit(1))}function po(e,t){let n=t===void 0?{event:e}:{event:e,data:t};process.stdout.write(`${JSON.stringify(n)}
199
+ `)}function mo(e,t){if(t)return e;let n=e.split(`
200
+ `);if(n.length<=20)return e;let s=n.slice(0,5),o=n.slice(-5),r=n.length-10;return[...s,`${Tt}... (${r} lines omitted, use --full-output to see all) ...${Re}`,...o].join(`
201
+ `)}function Lr(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}function ts(e,t){if(!e)return"(no result)";if(typeof e!="object")return mo(String(e),t);let n=e;if("structuredContent"in n&&n.structuredContent){let s=n.structuredContent,o=[];if(s.stdout&&typeof s.stdout=="string"&&s.stdout.trim()&&o.push(s.stdout.trim()),s.stderr&&typeof s.stderr=="string"&&s.stderr.trim()&&o.push(`${os}[stderr]${Re} ${s.stderr.trim()}`),s.urls&&Array.isArray(s.urls)){let r=s.urls;for(let i of r)i.path&&i.url&&o.push(`${i.path}: ${i.url}`)}return o.length===0&&o.push(JSON.stringify(s,null,2)),mo(o.join(`
202
+ `),t)}if("content"in n&&Array.isArray(n.content)){let o=n.content.filter(r=>r.type==="text"&&r.text).map(r=>r.text).join(`
203
+ `);return mo(o||JSON.stringify(e,null,2),t)}return mo(JSON.stringify(e,null,2),t)}async function ns(e){let t,n;try{let te=await ye();t=te.accessToken,n=te.workspaceId}catch(te){be(te)}let s=e.output===Qn;e.output&&!s&&(console.error(`Invalid --output value. Supported: ${Qn}`),process.exit(1));let o=!s&&(e.plain||!process.stdout.isTTY),r=ne.getDefaultModel(),i=e.message;!i&&!process.stdin.isTTY&&(i=await _r());let a=new B;async function l(){if(!r)try{let{models:te}=await a.getModels(t,n),ee=te[0]?.id;if(!ee)return;ne.setDefaultModel(ee),r=ee}catch{}}let d,v,b,x;if(e.continue){let te=await Dr(a,t,n,e.continue);te||process.exit(1),d=te.chat.id,v=te.chat.title??void 0,b=te.chat.agentId??void 0,x=te.modelId;let ee=e.agentId||e.model||b||x||r;!ee&&!e.interactive&&(await l(),ee=e.agentId||e.model||b||x||r),!ee&&!e.interactive&&(o||console.log(`Continuing chat: ${te.chat.title||"Untitled"}`),console.error(`
204
+ Could not determine model for this chat. Please specify --model or -a.`),console.error('Example: entrydesk chat -c 1 -m "message" --model gemini-2.5-flash-lite'),process.exit(1)),!o&&!e.interactive&&console.log(`Continuing chat: ${te.chat.title||"Untitled"}
205
+ `)}let C=e.agentId||b,m=e.model||x||r||void 0;!C&&!m&&(await l(),m=e.model||x||r||void 0),es(e.sandbox,e.noSandbox,"--sandbox","--no-sandbox"),es(e.fileSystem,e.noFileSystem,"--file-system","--no-file-system");let h=ne.getCapabilities(),S=e.noSandbox?!1:e.sandbox?!0:h?.sandbox??!0,R=e.webSearch??h?.webSearch??!1,V=e.imageGen??h?.imageGeneration??!1,Z=e.chart??h?.chart??!1,ae=ne.getDefaultConnectorIds(),Y=e.connectors??ae??void 0,Se=ne.getLocalTools(),j=e.noFileSystem?!1:e.fileSystem?!0:Se?.fileSystem??!0;if(e.interactive){Nr(Rr(Zn,{agentId:C,model:m,message:e.message,chatId:d,chatTitle:v??void 0,connectorIds:Y,enableSandbox:S,enableWebSearch:R,enableImageGeneration:V,enableChart:Z,enableFileSystem:j}),{exitOnCtrlC:!1});return}let P=!e.continue&&!m&&!C;(!i||P)&&(console.error("Usage: entrydesk chat -m <message> --model <model>"),console.error(" entrydesk chat -m <message> -a <agent>"),console.error(" entrydesk chat -c <number> -m <message>"),console.error(' echo "message" | entrydesk chat --model <model>'),console.error(" entrydesk chat -i (interactive mode)"),console.error(""),console.error("Options:"),console.error(" -m, --message Message to send (or pipe via stdin)"),console.error(" --model Model ID to use (required if no agent and no default)"),console.error(" -a, --agent Agent ID to use (required if no model)"),console.error(" -c, --continue Continue recent chat by number (1 = most recent)"),console.error(" -i Interactive mode"),console.error(" --plain Plain text output (no colors/formatting)"),console.error(" --output stream-json Stream JSON events (for scripting)"),console.error(" --full-output Show full tool results without truncation"),console.error(""),console.error("List available models: entrydesk models"),console.error("List available agents: entrydesk agents"),console.error("List recent chats: entrydesk chats"),process.exit(1));let N=e.fullOutput??!1,O=d||uo(),W=j?Yt():void 0,_=j?Xt():void 0,ge=[],D=uo(),p=(te,ee,pe)=>{let ce={id:O};return te&&(ce.message={id:te.id,createdAt:new Date,role:"user",parts:[{type:"text",text:te.text}]}),C?ce.agentId=C:(m&&(ce.model=m),ce.connectorIds=Y??[],ce.enableSandbox=S,ce.enableWebSearch=R,ce.enableImageGeneration=V,ce.enableChart=Z),W&&(ce.clientTools=W),_&&(ce.clientToolSystemPrompt=_),ee&&ee.length>0&&(ce.clientToolResults=ee),pe&&pe.length>0&&(ce.previousMessages=pe),ce},ie=async te=>{if(!te.body)throw new Error("No response body");let ee=te.body.getReader(),pe=new TextDecoder,ce="",M=new Map,Q=[],z=[];for(;;){let{done:fe,value:Te}=await ee.read();if(fe)break;ce+=pe.decode(Te,{stream:!0});let F=ce.split(`
206
+ `);ce=F.pop()||"";for(let se of F){let L=se.trimEnd();if(L==="data: [DONE]"){s&&po("done");continue}if(L.startsWith("data: "))try{let f=JSON.parse(L.slice(6));if(f.type&&z.push(f),s){f.type==="text-delta"&&f.delta!==void 0?po("text-delta",f.delta):f.type==="reasoning-delta"&&f.delta!==void 0?po("reasoning-delta",f.delta):po(f.type||"event",f);continue}if(o){if(f.type==="text-delta"&&f.delta&&process.stdout.write(f.delta),j&&(f.type==="tool-input-available"||f.type==="tool-call")&&f.toolCallId&&f.toolName&&tt(f.toolName)){let w=f.args||f.input||{};Q.push({toolCallId:f.toolCallId,toolName:f.toolName,args:w})}continue}switch(f.type){case"reasoning-delta":f.delta&&process.stdout.write(`${Tt}${f.delta}${Re}`);break;case"reasoning-end":process.stdout.write(`
207
+
208
+ `);break;case"text-delta":f.delta&&process.stdout.write(f.delta);break;case"tool-call-streaming-start":case"tool-input-start":if(f.toolCallId&&f.toolName){M.set(f.toolCallId,{toolName:f.toolName});let T=j&&tt(f.toolName)?`${fo}[LOCAL]${Re} `:"";console.log(`
209
+ ${Wo}\u250C\u2500 ${T}Tool Call: ${f.toolName}${Re}`)}break;case"tool-call":case"tool-input-available":if(f.toolCallId&&f.toolName){let w=f.args||f.input||{},T=Lr(w);console.log(`${os}\u2502 Arguments:${Re}`);for(let oe of T.split(`
210
+ `))console.log(`${Tt}\u2502 ${oe}${Re}`);j&&tt(f.toolName)&&(M.set(f.toolCallId,{toolName:f.toolName,args:w}),Q.push({toolCallId:f.toolCallId,toolName:f.toolName,args:w}))}break;case"tool-result":if(f.toolCallId){let w=M.get(f.toolCallId),T=ts(f.result,N);console.log(`${fo}\u2502 Result:${Re}`);for(let oe of T.split(`
211
+ `))console.log(`${Tt}\u2502 ${oe}${Re}`);console.log(`${Wo}\u2514\u2500 ${w?.toolName||"Tool"} completed${Re}
212
+ `),M.delete(f.toolCallId)}break;case"error":f.errorText&&console.error(`${Tt}Error: ${f.errorText}${Re}`);break}}catch{}}}return{pendingClientTools:Q,messageParts:z}},ke=p({id:uo(),text:i}),q=await a.chat(t,n,ke),A=await ie(q);for(ge=A.messageParts;A.pendingClientTools.length>0;){let te=[];for(let M of A.pendingClientTools){!o&&!s&&console.log(`${fo}\u2502 Executing locally...${Re}`);let Q=await Zt(M.toolName,M.args),z=Q.success?JSON.stringify(Q.result):Q.error||"Unknown error";if(te.push({toolCallId:M.toolCallId,toolName:M.toolName,content:[{type:"text",text:z}],isError:!Q.success}),!o&&!s){let fe=ts(Q.success?Q.result:{error:Q.error},N);console.log(`${fo}\u2502 Result:${Re}`);for(let Te of fe.split(`
213
+ `))console.log(`${Tt}\u2502 ${Te}${Re}`);console.log(`${Wo}\u2514\u2500 ${M.toolName} completed${Re}
214
+ `)}}let ee=ge.map(M=>{if(M.type==="tool-call"){let Q=te.find(fe=>fe.toolCallId===M.toolCallId),z=Q?.content.filter(fe=>fe.type==="text").map(fe=>fe.text).join(`
215
+ `);return{type:"tool-invocation",toolCallId:M.toolCallId,toolName:M.toolName,args:M.args,state:Q?.isError?"output-error":"output-available",output:z}}return M}),pe=[{id:D,role:"assistant",parts:ee}];D=uo();let ce=p(void 0,te,pe);q=await a.chat(t,n,ce),A=await ie(q),ge=A.messageParts}s||console.log("")}var Bt="\x1B[2m",Ae="\x1B[0m",pt="\x1B[36m",Jo="\x1B[33m",ss="\x1B[32m",rs="stream-json";function qe(e,t){let n=t===void 0?{event:e}:{event:e,data:t};process.stdout.write(`${JSON.stringify(n)}
216
+ `)}function Mo(e){let t=new Date(e),s=new Date().getTime()-t.getTime(),o=Math.floor(s/(1e3*60*60*24));return o===0?t.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit"}):o===1?"Yesterday":o<7?`${o} days ago`:t.toLocaleDateString("en-US",{month:"short",day:"numeric"})}function go(e,t){if(t)return e;let n=e.split(`
217
+ `);if(n.length<=15)return e;let s=n.slice(0,6),o=n.slice(-4),r=n.length-10;return[...s,`... (${r} lines omitted, use --full-output to see all) ...`,...o].join(`
218
+ `)}function Go(e){if(!e||typeof e!="object")return e;if(Array.isArray(e))return e.map(Go);let t={};for(let[n,s]of Object.entries(e))typeof s=="string"&&s.length>200?t[n]=s.slice(0,150)+"... (truncated)":typeof s=="object"&&s!==null?t[n]=Go(s):t[n]=s;return t}function is(e){if(!e||typeof e!="object")return String(e);try{return JSON.stringify(e,null,2)}catch{return String(e)}}function as(e,t){if(!e)return"(no result)";if(typeof e!="object")return go(String(e),t);let n=t?e:Go(e);if("structuredContent"in n&&n.structuredContent){let s=n.structuredContent,o=[];if(s.stdout&&typeof s.stdout=="string"&&s.stdout.trim()&&o.push(s.stdout.trim()),s.stderr&&typeof s.stderr=="string"&&s.stderr.trim()&&o.push(`${Jo}[stderr]${Ae} ${s.stderr.trim()}`),s.urls&&Array.isArray(s.urls)){let r=s.urls;for(let i of r)i.path&&i.url&&o.push(`${i.path}: ${i.url}`)}return o.length===0&&o.push(JSON.stringify(s,null,2)),go(o.join(`
219
+ `),t)}if("content"in n&&Array.isArray(n.content)){let o=n.content.filter(r=>r.type==="text"&&r.text).map(r=>r.text).join(`
220
+ `);return go(o||JSON.stringify(e,null,2),t)}return go(JSON.stringify(e,null,2),t)}function Or(e){if(typeof e.title=="string")return e.title;if(typeof e.toolName=="string")return e.toolName;let t=e.type;return t.startsWith("tool-")?t.slice(5).replace(/__/g," ").replace(/_/g," "):t}function ls(e,t){let n=[];for(let s of e)if(s.type==="reasoning"&&s.text)n.push(`${Bt}${s.text}${Ae}`);else if(s.type==="text"&&s.text)n.push(s.text);else if(s.type==="tool-call"&&s.toolName){let o=[];if(o.push(`${pt}\u250C\u2500 Tool Call: ${s.toolName}${Ae}`),s.args){o.push(`${Jo}\u2502 Arguments:${Ae}`);let r=is(s.args);for(let i of r.split(`
221
+ `))o.push(`${Bt}\u2502 ${i}${Ae}`)}if(s.result!==void 0){o.push(`${ss}\u2502 Result:${Ae}`);let r=as(s.result,t);for(let i of r.split(`
222
+ `))o.push(`${Bt}\u2502 ${i}${Ae}`);o.push(`${pt}\u2514\u2500 ${s.toolName} completed${Ae}`)}else s.state==="call"?o.push(`${pt}\u2514\u2500 (awaiting result)${Ae}`):o.push(`${pt}\u2514\u2500${Ae}`);n.push(o.join(`
223
+ `))}else if(s.type.startsWith("tool-")&&s.type!=="tool-call"){let o=Or(s),r=[];if(r.push(`${pt}\u250C\u2500 Tool: ${o}${Ae}`),s.input){r.push(`${Jo}\u2502 Input:${Ae}`);let i=is(s.input);for(let a of i.split(`
224
+ `))r.push(`${Bt}\u2502 ${a}${Ae}`)}if(s.output!==void 0&&s.state==="output-available"){r.push(`${ss}\u2502 Output:${Ae}`);let i=as(s.output,t);for(let a of i.split(`
225
+ `))r.push(`${Bt}\u2502 ${a}${Ae}`);r.push(`${pt}\u2514\u2500 completed${Ae}`)}else s.state==="call"||s.state==="partial-call"?r.push(`${pt}\u2514\u2500 (in progress)${Ae}`):r.push(`${pt}\u2514\u2500${Ae}`);n.push(r.join(`
226
+ `))}return n.join(`
227
+
228
+ `).trim()}async function cs(e){let t=e.output===rs;e.output&&!t&&(console.error(`Invalid --output value. Supported: ${rs}`),process.exit(1));let n=new B;if(e.shareId){let i;try{i=await dt()}catch{}try{let a=await n.getSharedChat(e.shareId,i),{messages:l}=await n.getSharedMessages(e.shareId,50,i);if(e.json){console.log(JSON.stringify({chat:a,messages:l}));return}if(t){if(qe("chat",a),l.length===0)qe("info","No messages in this shared chat.");else for(let b of l.toReversed())qe("message",b);qe("done");return}if(console.log(`Shared Chat: ${a.title||"Untitled"}`),console.log(`Visibility: ${a.visibility}`),a.agent&&console.log(`Agent: ${a.agent.name}`),console.log(`${l.length} messages
229
+ `),l.length===0){console.log("No messages in this shared chat.");return}let d=l.toReversed(),v=e.fullOutput??!1;for(let b of d){let x=ls(b.parts,v);if(!x)continue;let C=b.role==="user"?"You":"Assistant";console.log(`[${C}] ${Mo(b.createdAt)}`),console.log(x),console.log("")}return}catch(a){if(a instanceof Error){let l=a.message.toLowerCase();l.includes("401")||l.includes("unauthorized")?console.error("Access denied. This shared chat requires authentication or is not accessible to you."):l.includes("404")||l.includes("not found")?console.error("Shared chat not found. The share ID may be invalid or the chat was deleted."):console.error(`Failed to fetch shared chat: ${a.message}`)}else console.error("Failed to fetch shared chat");process.exit(1)}}let s,o;try{let i=await ye();s=i.accessToken,o=i.workspaceId}catch(i){be(i)}if(e.chatId){let i=e.chatId,a=!1,l=null,d=parseInt(e.chatId,10);if(!isNaN(d)&&d>=0&&/^\d+$/.test(e.chatId)){let m=d===0?1:d,{chats:h}=await n.getChats(s,o,20);m>h.length&&(console.error(`Chat number ${m} not found. You have ${h.length} recent chats.`),process.exit(1));let S=h[m-1];i=S.id,a=!0,l=S,t||console.log(`Chat: ${S.title||"Untitled"}
230
+ `)}let{messages:b}=await n.getMessages(s,o,i,50);if(e.json){console.log(JSON.stringify(b));return}if(t){if(l&&qe("chat",l),b.length===0)qe("info","No messages in this chat.");else for(let m of b.toReversed())qe("message",m);qe("done");return}if(b.length===0){console.log("No messages in this chat.");return}let x=b.toReversed(),C=e.fullOutput??!1;a||console.log(`Chat: ${e.chatId.slice(0,8)}...`),console.log(`${b.length} messages
231
+ `);for(let m of x){let h=ls(m.parts,C);if(!h)continue;let S=m.role==="user"?"You":"Assistant";console.log(`[${S}] ${Mo(m.createdAt)}`),console.log(h),console.log("")}return}let{chats:r}=await n.getChats(s,o,20);if(t){for(let i of r)qe("chat",i);qe("done");return}if(e.json){console.log(JSON.stringify(r));return}if(r.length===0){console.log("No chats found.");return}console.log(`Recent Chats (${r.length}):
232
+ `),r.forEach((i,a)=>{let l=(a+1).toString().padStart(2," ");console.log(` ${l}. ${Mo(i.createdAt).padEnd(12)} ${i.title||"Untitled"}`)}),console.log(""),console.log("Use `entrydesk chats 1` to view the most recent chat"),console.log('Use `entrydesk chat -c 1 -m "message"` to continue it')}import{Box as Ur,Text as Ee}from"ink";import{jsx as je,jsxs as vt}from"react/jsx-runtime";var It=["apiUrl","hubUrl"];function Ho(e){return It.includes(e)}async function us(e){let t=e.action||"list",n=e.configKey,s=e.value,o=H.getEffectiveProfileName();if(t==="list"){let r=ne.getAll(),i=Object.entries(r);if(e.json){console.log(JSON.stringify(r));return}if(console.log(`Profile: ${o}`),i.length===0){console.log("No configuration set."),console.log(`Available keys: ${It.join(", ")}`);return}console.log(`Configuration:
233
+ `);for(let[a,l]of i)console.log(` ${a}=${l}`);console.log(`
234
+ Available keys: ${It.join(", ")}`);return}if(t==="get"){n||(console.error("Error: key is required for get action"),process.exit(1)),Ho(n)||(console.error(`Error: Invalid key '${n}'. Valid keys: ${It.join(", ")}`),process.exit(1));let r=ne.get(n);e.json?console.log(JSON.stringify({[n]:r??null})):console.log(r||"Not set");return}if(t==="set"){n||(console.error("Error: key is required for set action"),process.exit(1)),Ho(n)||(console.error(`Error: Invalid key '${n}'. Valid keys: ${It.join(", ")}`),process.exit(1)),s||(console.error("Error: value is required for set action"),process.exit(1)),ne.set(n,s),console.log(`Set ${n}=${s}`);return}if(t==="unset"){n||(console.error("Error: key is required for unset action"),process.exit(1)),Ho(n)||(console.error(`Error: Invalid key '${n}'. Valid keys: ${It.join(", ")}`),process.exit(1)),ne.unset(n),console.log(`Unset ${n}`);return}console.error(`Unknown action: ${t}`),process.exit(1)}function ds(){let e=Qe();return vt(Ur,{flexDirection:"column",children:[je(Ee,{bold:!0,children:"entrydesk config"}),je(Ee,{children:" "}),je(Ee,{children:"Manage CLI configuration"}),je(Ee,{children:" "}),je(Ee,{bold:!0,children:"Usage:"}),je(Ee,{children:" entrydesk config List all configuration"}),vt(Ee,{children:[" entrydesk config get ","<key>"," Get a configuration value"]}),vt(Ee,{children:[" ","entrydesk config set ","<key>"," ","<value>"," Set a configuration value"]}),vt(Ee,{children:[" ","entrydesk config unset ","<key>"," Remove a configuration value"]}),je(Ee,{children:" "}),je(Ee,{bold:!0,children:"Available keys:"}),vt(Ee,{children:[" apiUrl API server URL (default: ",e.apiUrl,")"]}),vt(Ee,{children:[" hubUrl Hub server URL (default: ",e.hubUrl,")"]}),je(Ee,{children:" "}),je(Ee,{bold:!0,children:"Examples:"}),je(Ee,{children:" entrydesk config set apiUrl http://localhost:3200"}),je(Ee,{children:" entrydesk config get apiUrl"}),je(Ee,{children:" entrydesk config unset apiUrl"})]})}async function fs(e){try{let t,n;try{let r=await ye();t=r.accessToken,n=r.workspaceId}catch(r){let i=r instanceof Error?r.message:"Authentication failed";console.error(i),process.exit(1)}let s=new B,{connectors:o}=await s.getConnectors(t,n);if(e.json){console.log(JSON.stringify(o));return}if(o.length===0){console.log("No connectors found in this workspace.");return}console.log(`Connected Connectors (${o.length}):
235
+ `);for(let r of o){let i=r.connected?"connected":"disconnected";console.log(` ${r.name} (${i})`),console.log(` Provider: ${r.provider}`),console.log(` ID: ${r.id}`),console.log("")}}catch(t){be(t)}}function ho(){console.log(`
236
+ EntryDesk CLI - Interact with EntryDesk from your terminal
237
+
238
+ Usage: entrydesk <command> [options]
239
+
240
+ Commands:
241
+ login Authenticate with EntryDesk
242
+ logout Sign out and clear credentials
243
+ status Show current authentication status
244
+ workspaces List or switch workspaces
245
+ models List available models
246
+ agents List available agents
247
+ skills List or upload skills
248
+ schedules List or manage scheduled tasks
249
+ connectors List connected connectors
250
+ profile Manage profiles
251
+ chats List recent chats or view messages
252
+ chat Send a message or start interactive chat
253
+ budget View or manage workspace budget
254
+ usage View current month usage statistics
255
+ mcp Start MCP server (stdio or HTTP)
256
+ config Manage CLI configuration
257
+ help Show this help message
258
+ version Show version number
259
+
260
+ Global Options:
261
+ --json Output in JSON format (for scripting)
262
+ -i Interactive mode (for login, chat)
263
+ --profile Use a specific profile for this command
264
+
265
+ Login:
266
+ entrydesk login # Open browser login
267
+ entrydesk login --email <email> --password <password>
268
+ entrydesk login --google # Google OAuth (opens browser)
269
+ entrydesk login -i # Interactive mode
270
+
271
+ Chat:
272
+ entrydesk chat -m "Hello" --model <model> # Send with model
273
+ entrydesk chat -m "Hello" -a <agent> # Send with agent
274
+ entrydesk chat -c 1 -m "Follow up" # Continue recent chat
275
+ entrydesk chat -i # Interactive mode
276
+ echo "Hello" | entrydesk chat --model <m> # Pipe input from stdin
277
+ entrydesk chat -m "Hi" --model <m> --plain # Plain text output
278
+ entrydesk chat -m "Hi" --model <m> --output stream-json # Stream JSON
279
+ entrydesk chat -i --web-search # Enable web search
280
+ entrydesk chat -i --no-sandbox # Disable sandbox
281
+ entrydesk chat -i --no-file-system # Disable local file operations
282
+ entrydesk chat -i --connectors id1,id2 # Use specific connectors
283
+
284
+ MCP Server:
285
+ entrydesk mcp # Start stdio server
286
+ entrydesk mcp --http --port 3100 # Start HTTP server
287
+
288
+ Workspaces:
289
+ entrydesk workspaces # List all workspaces
290
+ entrydesk workspaces switch <id> # Switch to a workspace
291
+ entrydesk workspaces use <id> # Alias for switch
292
+
293
+ Budget:
294
+ entrydesk budget # Show current budget
295
+ entrydesk budget get # Show current budget
296
+ entrydesk budget set 100.00 # Set budget to $100.00
297
+ entrydesk budget clear # Remove budget
298
+
299
+ Usage:
300
+ entrydesk usage # Show current month usage (top users by cost)
301
+ entrydesk usage --limit 20 # Show top 20 users
302
+ entrydesk usage --sort-by operations # Sort by operations instead of cost
303
+ entrydesk usage --limit 10 --sort-by cost # Top 10 by cost
304
+ entrydesk usage --json # Get usage as JSON
305
+
306
+ Chats:
307
+ entrydesk chats # List recent chats
308
+ entrydesk chats 1 # View chat #1 messages
309
+ entrydesk chats <uuid> # View chat by ID
310
+ entrydesk chats --share <shareId> # View shared chat by share ID
311
+ entrydesk chats -s <shareId> # Short form for --share
312
+ entrydesk chats --share <id> --json # Get shared chat as JSON
313
+
314
+ Examples:
315
+ $ entrydesk login
316
+ $ entrydesk status
317
+ $ entrydesk workspaces # List workspaces
318
+ $ entrydesk workspaces switch <workspaceId> # Switch workspace
319
+ $ entrydesk budget # View budget
320
+ $ entrydesk budget set 100.00 # Set budget
321
+ $ entrydesk budget clear # Clear budget
322
+ $ entrydesk usage # View usage (all users, sorted by cost)
323
+ $ entrydesk usage --limit 10 # Show top 10 users
324
+ $ entrydesk usage --sort-by operations # Sort by operation count
325
+ $ entrydesk models --json
326
+ $ entrydesk agents --json
327
+ $ entrydesk agents create --name "My Agent" --description "..." --system-prompt "..." --model-id <modelId>
328
+ $ entrydesk agents update <agentId> --name "New Name" --description "..." --system-prompt "..." --model-id <modelId>
329
+ $ entrydesk agents delete <agentId>
330
+ $ entrydesk skills
331
+ $ entrydesk skills upload ./my-skill.zip
332
+ $ entrydesk skills upload ./my-skill-folder
333
+ $ entrydesk chat -m "Hello" --model gemini-2.5-flash-lite
334
+ $ entrydesk chats # List recent chats
335
+ $ entrydesk chats 1 # View chat #1 messages
336
+ $ entrydesk chat -c 1 -m "Tell me more" # Continue chat #1
337
+ $ entrydesk chats 0 --output stream-json # Stream recent chat as JSON
338
+ $ entrydesk chats --share <shareId> # View shared chat
339
+
340
+ Piping:
341
+ $ echo "Explain this code" | entrydesk chat --model gemini-2.5-flash-lite
342
+ $ cat file.txt | entrydesk chat -c 1 # Pipe file content
343
+ $ entrydesk chat -m "Hi" --model <m> > out.txt # Save to file
344
+
345
+ Usage Examples:
346
+ $ entrydesk usage # Show all users, sorted by cost
347
+ $ entrydesk usage --limit 10 # Show top 10 users
348
+ $ entrydesk usage --sort-by operations # Sort by operation count
349
+
350
+ Configuration:
351
+ entrydesk config # Show current config
352
+ entrydesk config set <key> <value> # Set a config value
353
+ entrydesk config unset <key> # Remove a config value
354
+
355
+ Profiles:
356
+ entrydesk profile # List profiles
357
+ entrydesk profile create <name> # Create a profile
358
+ entrydesk profile use <name> # Switch active profile
359
+ entrydesk profile delete <name> # Delete a profile
360
+ entrydesk profile rename <from> <to> # Rename a profile
361
+ entrydesk profile clone <from> <to> # Clone config defaults (no credentials)
362
+
363
+ Skills:
364
+ entrydesk skills # List skills
365
+ entrydesk skills list --me # List my skills
366
+ entrydesk skills upload <file.zip> # Upload a skill zip
367
+ entrydesk skills upload <folder> # Upload a skill folder
368
+ entrydesk skills upload <file.zip> --force
369
+ entrydesk skills delete <skillId>
370
+
371
+ Agents:
372
+ entrydesk agents # List agents
373
+ entrydesk agents create --name "My Agent" --description "..." --system-prompt "..." --model-id <modelId>
374
+ entrydesk agents update <agentId> --name "New Name" --description "..." --system-prompt "..." --model-id <modelId>
375
+ entrydesk agents delete <agentId>
376
+
377
+ Schedules:
378
+ entrydesk schedules # List schedules
379
+ entrydesk schedules get <id> # Show schedule details
380
+ entrydesk schedules create \\
381
+ --name "Daily Report" \\
382
+ --agent-id <agentId> \\
383
+ --prompt "Generate report" \\
384
+ --starts-at "2025-01-01T09:00:00Z" \\
385
+ --repeat-type days --every 1 --time 09:00 \\
386
+ --utc-offset "+08:00"
387
+ entrydesk schedules delete <id> # Delete a schedule
388
+
389
+ Available keys: apiUrl, hubUrl
390
+
391
+ Local Development:
392
+ $ entrydesk config set apiUrl http://localhost:3200
393
+ $ entrydesk config set hubUrl http://localhost:3000
394
+
395
+ For more information, visit https://entrydesk.com/docs/cli
396
+ `)}import{render as Vr}from"ink";import{randomUUID as jr}from"crypto";import{chromium as Br}from"playwright";function Fr(e){return e==="localhost"||e==="127.0.0.1"||e==="::1"||e==="0.0.0.0"}function Wr(e){let t;try{t=new URL(e)}catch{throw new Error("Invalid hub URL. Please check ENTRYDESK_HUB_URL.")}if(t.protocol!=="https:"&&t.protocol!=="http:")throw new Error("Hub URL must use http or https.");if(t.username||t.password)throw new Error("Hub URL must not include credentials.");if(!t.hostname)throw new Error("Hub URL must include a hostname.");if(t.protocol==="http:"&&!Fr(t.hostname))throw new Error("Hub URL must use https unless running on localhost.");return t}function Mr(e){try{let t=e.split(".");if(t.length<2)return null;let n=t[1].replace(/-/g,"+").replace(/_/g,"/"),s=(4-n.length%4)%4,o=n.padEnd(n.length+s,"="),r=Buffer.from(o,"base64").toString("utf8");return JSON.parse(r).exp??null}catch{return null}}async function Vo(e){let{hubUrl:t,auth:n}=Qe(),s=Wr(t),o=new URL("/login",s),r=jr();o.searchParams.set("cli","true"),o.searchParams.set("state",r);let i;try{i=await Br.launch({headless:!1,args:["--disable-blink-features=AutomationControlled"]})}catch(a){throw a instanceof Error&&a.message.includes("Executable")?new Error(`Chromium browser is not installed. Please run:
397
+ npm install -g playwright
398
+ npx playwright install chromium --with-deps`,{cause:a}):a}try{let l=await(await i.newContext({viewport:{width:1280,height:800},ignoreHTTPSErrors:n.ignoreSslErrors})).newPage();process.env.DEBUG&&l.on("console",m=>{console.log(`[Browser Console] ${m.type()}: ${m.text()}`)}),e?.onBrowserOpen?.(),await l.goto(o.toString(),{waitUntil:"networkidle"}),e?.onWaitingForLogin?.();let d=s.host;await l.waitForURL(m=>{let h=new URL(m);if(h.host!==d)return!1;let S=h.pathname;if(S==="/login"||S.startsWith("/auth/"))return!1;let R=h.searchParams.get("state");return!(R&&R!==r)},{timeout:n.loginTimeout});let v=new URL("/api/auth/session",s).toString();process.env.DEBUG&&(console.log(`[DEBUG] Fetching session from: ${v}`),console.log(`[DEBUG] Current page URL: ${l.url()}`),console.log(`[DEBUG] SSL ignore enabled: ${n.ignoreSslErrors}`));let b=await l.evaluate(async m=>{try{let h=await fetch(m);if(!h.ok)throw new Error(`Failed to fetch session: ${h.status} ${h.statusText}`);return h.json()}catch(h){throw console.error("[Browser Context] Fetch error:",h),h}},v);if(!b?.accessToken)throw new Error("Failed to get access token from session");let x=Mr(b.accessToken);if(x&&x*1e3<=Date.now())throw new Error("Access token is expired. Please log in again.");let C=b.user?.email||"";return e?.onLoginSuccess?.(C||"unknown"),{accessToken:b.accessToken,email:C,workspaceId:b.currentWorkspaceId}}catch(a){let l;throw a instanceof Error?(l=a,l.message.includes("fetch failed")&&(l=new Error(`Network request failed. This might be due to SSL certificate issues. Current SSL ignore setting: ${n.ignoreSslErrors}. Original error: ${l.message}`))):l=new Error("Browser authentication failed."),e?.onError?.(l),l}finally{await i.close()}}import{Box as Ne,Text as De,useApp as Jr,useInput as Gr}from"ink";import Hr from"ink-spinner";import ps from"ink-text-input";import{useState as Ft}from"react";import{jsx as me,jsxs as Je}from"react/jsx-runtime";function ms(){let{exit:e}=Jr(),[t,n]=Ft("email"),[s,o]=Ft(""),[r,i]=Ft(""),[a,l]=Ft(null),[d,v]=Ft(null);return Gr((C,m)=>{m.escape&&e()}),Je(Ne,{flexDirection:"column",padding:1,children:[me(Ne,{marginBottom:1,children:me(De,{bold:!0,color:"cyan",children:"EntryDesk Login"})}),t==="email"&&Je(Ne,{flexDirection:"column",children:[Je(Ne,{children:[me(De,{children:"Email: "}),me(ps,{value:s,onChange:o,onSubmit:C=>{if(!C.includes("@")){l("Please enter a valid email address");return}o(C),l(null),n("password")},placeholder:"user@example.com"})]}),a&&me(Ne,{marginTop:1,children:me(De,{color:"red",children:a})}),me(Ne,{marginTop:1,children:me(De,{dimColor:!0,children:"Press Enter to continue, Esc to cancel"})})]}),t==="password"&&Je(Ne,{flexDirection:"column",children:[Je(Ne,{children:[me(De,{children:"Email: "}),me(De,{color:"green",children:s})]}),Je(Ne,{children:[me(De,{children:"Password: "}),me(ps,{value:r,onChange:i,onSubmit:async C=>{i(C),n("loading"),l(null);try{let m=new B,{token:h,refreshToken:S}=await m.login(s,C),{workspaces:R}=await m.getWorkspaces(h),V=R[0];await $e.saveAll({accessToken:h,refreshToken:S,email:s,workspaceId:V?.id}),v(V?.name??null),n("success"),setTimeout(()=>{e()},1500)}catch(m){n("error"),m instanceof Error?m.message.includes("403")||m.message.includes("Invalid")?l("Invalid email or password"):l(m.message):l("Login failed. Please try again.")}},mask:"*",placeholder:"Enter password"})]}),me(Ne,{marginTop:1,children:me(De,{dimColor:!0,children:"Press Enter to login, Esc to cancel"})})]}),t==="loading"&&Je(Ne,{children:[me(De,{color:"cyan",children:me(Hr,{type:"dots"})}),me(De,{children:" Logging in..."})]}),t==="success"&&Je(Ne,{flexDirection:"column",children:[Je(Ne,{children:[me(De,{color:"green",children:"\u2713"}),me(De,{children:" Logged in as "}),me(De,{bold:!0,children:s})]}),d&&me(Ne,{children:Je(De,{dimColor:!0,children:["Workspace: ",d]})})]}),t==="error"&&Je(Ne,{flexDirection:"column",children:[me(Ne,{children:me(De,{color:"red",children:"\u2717 Login failed"})}),a&&me(Ne,{children:me(De,{color:"red",children:a})}),me(Ne,{marginTop:1,children:me(De,{dimColor:!0,children:"Run `entrydesk login` to try again"})})]})]})}import{jsx as Kr}from"react/jsx-runtime";async function gs(e){if(!!(e.email||e.password)){(!e.email||!e.password)&&(console.error("Usage: entrydesk login --email <email> --password <password>"),console.error(" entrydesk login"),console.error(" entrydesk login --google"),console.error(" entrydesk login -i (interactive mode)"),process.exit(1));let a=new B,{token:l,refreshToken:d}=await a.login(e.email,e.password),{workspaces:v}=await a.getWorkspaces(l),b=v[0];await $e.saveAll({accessToken:l,refreshToken:d,email:e.email,workspaceId:b?.id}),e.json?console.log(JSON.stringify({email:e.email,workspaceId:b?.id,workspaceName:b?.name})):(console.log(`Logged in as ${e.email}`),b&&console.log(`Workspace: ${b.name}`));return}if(e.google){console.log("Opening browser for Google OAuth...");let a=await Vo(),l=new B,{workspaces:d}=await l.getWorkspaces(a.accessToken),v=d[0],b=a.workspaceId||v?.id;await $e.saveAll({accessToken:a.accessToken,refreshToken:"",email:a.email,workspaceId:b}),e.json?console.log(JSON.stringify({email:a.email,workspaceId:b,workspaceName:v?.name})):(console.log(`Logged in as ${a.email}`),v&&console.log(`Workspace: ${v.name}`));return}if(e.interactive){Vr(Kr(ms,{}));return}if(console.log("Opening browser for login..."),process.env.DEBUG){let{getApiUrl:a,getHubUrl:l}=await import("./config-LX73PV6D.js");console.log(`[DEBUG] Hub URL: ${l()}`),console.log(`[DEBUG] API URL: ${a()}`)}let n=await Vo(),s=new B,{workspaces:o}=await s.getWorkspaces(n.accessToken),r=o[0],i=n.workspaceId||r?.id;await $e.saveAll({accessToken:n.accessToken,refreshToken:"",email:n.email,workspaceId:i}),e.json?console.log(JSON.stringify({email:n.email,workspaceId:i,workspaceName:r?.name})):(console.log(`Logged in as ${n.email}`),r&&console.log(`Workspace: ${r.name}`))}async function hs(e){try{let t=await $e.getAll();if(!t){console.log("Not logged in");return}try{await new B().revokeToken(t.refreshToken)}catch{}await $e.clear(),console.log("Logged out successfully")}catch(t){be(t)}}import qr from"http";import{Client as zr}from"@modelcontextprotocol/sdk/client/index.js";import{StreamableHTTPClientTransport as Yr}from"@modelcontextprotocol/sdk/client/streamableHttp.js";import{Server as Xr}from"@modelcontextprotocol/sdk/server/index.js";import{StdioServerTransport as Zr}from"@modelcontextprotocol/sdk/server/stdio.js";import{StreamableHTTPServerTransport as Qr}from"@modelcontextprotocol/sdk/server/streamableHttp.js";import{CallToolRequestSchema as ei,ListToolsRequestSchema as ti}from"@modelcontextprotocol/sdk/types.js";async function oi(e,t,n){let s=new zr({name:"entrydesk-cli-proxy",version:"1.0.0"}),o=new URL(`${e}/v1/workspaces/${n}/mcp`),r=new Yr(o,{requestInit:{headers:{Authorization:`Bearer ${t}`}}});return await s.connect(r),s}function ys(e){let t=new Xr({name:"entrydesk-cli",version:"1.0.0"},{capabilities:{tools:{}}});return t.setRequestHandler(ti,async()=>({tools:(await e.listTools()).tools})),t.setRequestHandler(ei,async n=>{let{name:s,arguments:o}=n.params,r=await e.callTool({name:s,arguments:o});return{content:r.content,isError:r.isError}}),t}async function ni(e,t){let n=qr.createServer(async(s,o)=>{if(s.method==="OPTIONS"){o.setHeader("Access-Control-Allow-Origin","*"),o.setHeader("Access-Control-Allow-Methods","GET, POST, DELETE, OPTIONS"),o.setHeader("Access-Control-Allow-Headers","Content-Type, Accept"),o.writeHead(204),o.end();return}if(s.url!=="/mcp"){o.writeHead(404,{"Content-Type":"application/json"}),o.end(JSON.stringify({error:"Not found"}));return}let r=ys(e),i=new Qr({sessionIdGenerator:void 0});if(o.setHeader("Access-Control-Allow-Origin","*"),o.on("close",()=>{i.close(),r.close()}),await r.connect(i),s.method==="POST"){let a="";s.on("data",l=>{a+=l.toString()}),s.on("end",async()=>{try{let l=JSON.parse(a);await i.handleRequest(s,o,l)}catch{o.writeHead(400,{"Content-Type":"application/json"}),o.end(JSON.stringify({error:"Invalid JSON"}))}})}else await i.handleRequest(s,o)});n.listen(t,()=>{console.error(`EntryDesk MCP server running at http://localhost:${t}/mcp`),console.error("Press Ctrl+C to stop")}),process.on("SIGINT",async()=>{console.error(`
399
+ Shutting down...`),n.close(),await e.close(),process.exit(0)}),process.on("SIGTERM",async()=>{n.close(),await e.close(),process.exit(0)})}async function si(e){let t=ys(e),n=new Zr;n.onclose=async()=>{await e.close()},await t.connect(n)}async function ws(e={mode:"stdio"}){process.on("unhandledRejection",t=>{console.error("[entrydesk-mcp] Unhandled rejection:",t)}),process.on("uncaughtException",t=>{console.error("[entrydesk-mcp] Uncaught exception:",t)});try{console.error("[entrydesk-mcp] Starting MCP server...");let t,n;try{let i=await ye();t=i.accessToken,n=i.workspaceId}catch(i){let a=i instanceof Error?i.message:"Authentication failed";console.error(a),process.exit(1)}let{apiUrl:s,mcp:o}=Qe();console.error(`[entrydesk-mcp] Connecting to ${s}...`),console.error(`[entrydesk-mcp] Workspace: ${n}`);let r=await oi(s,t,n);if(console.error("[entrydesk-mcp] Connected to EntryDesk API"),e.mode==="http"){let i=e.port||o.httpPort;await ni(r,i)}else console.error("[entrydesk-mcp] Starting stdio server..."),await si(r),console.error("[entrydesk-mcp] Stdio server started")}catch(t){console.error("[entrydesk-mcp] Fatal error:",t),process.exit(1)}}async function ks(e){try{let t,n;try{let r=await ye();t=r.accessToken,n=r.workspaceId}catch(r){let i=r instanceof Error?r.message:"Authentication failed";console.error(i),process.exit(1)}let s=new B,{models:o}=await s.getModels(t,n);if(e.json){console.log(JSON.stringify(o));return}if(o.length===0){console.log("No models available in this workspace.");return}console.log(`Available Models (${o.length}):
400
+ `);for(let r of o)console.log(` ${r.name}`),r.description&&console.log(` ${r.description.slice(0,80)}`),console.log(` ID: ${r.id}`),console.log("")}catch(t){be(t)}}function ri(){console.log(`
401
+ Usage: entrydesk profile [list|show|current|create|use|delete|rename|clone] [args]
402
+
403
+ Commands:
404
+ list List profiles (default)
405
+ show <name> Show profile details
406
+ current Show active profile
407
+ create <name> Create a profile (default name: default)
408
+ use <name> Switch active profile
409
+ delete <name> Delete a profile
410
+ rename <from> <to> Rename a profile
411
+ clone <from> <to> Clone config defaults (no credentials)
412
+
413
+ Flags:
414
+ --json Output JSON
415
+ `)}function Wt(e,t){if(e)return e;if(t&&H.getProfileCount()===1)return H.getProfileNames()[0];throw new Et("Profile name is required when multiple profiles exist.")}function ii(e){if(!e)return"none";let t=[];return e.sandbox&&t.push("sandbox"),e.webSearch&&t.push("webSearch"),e.imageGeneration&&t.push("imageGeneration"),e.chart&&t.push("chart"),t.length>0?t.join(", "):"none"}async function bs(e){try{let t=e.action||"list",n=H.getCurrentProfileName(),s=e.name??e.profile,o=e.value;if(e.help||t==="help"){ri();return}if(t==="list"){let r=H.getProfileNames();if(e.json){console.log(JSON.stringify({currentProfile:n,profiles:r.map(i=>({name:i,isCurrent:i===n}))}));return}console.log(`Profiles (${r.length}):`);for(let i of r)console.log(` ${i}${i===n?" (current)":""}`);return}if(t==="current"){if(e.json){console.log(JSON.stringify({name:n,isCurrent:!0}));return}console.log(`Current profile: ${n}`);return}if(t==="show"){let r=Wt(s,!0),i=ne.getAll(r),a=await $e.getAll(r),l=!!a?.accessToken;if(e.json){console.log(JSON.stringify({name:r,isCurrent:r===n,config:i,auth:l?{loggedIn:!0,email:a?.email??null,workspaceId:a?.workspaceId??null}:{loggedIn:!1}}));return}console.log(`Profile: ${r}${r===n?" (current)":""}`),console.log(` API URL: ${i.apiUrl??"default"}`),console.log(` Hub URL: ${i.hubUrl??"default"}`),console.log(` Model: ${i.model?.default??"unset"}`);let d=i.connectors?.defaults&&i.connectors.defaults.length>0?i.connectors.defaults.join(", "):"unset";console.log(` Connectors: ${d}`),console.log(` Capabilities: ${ii(i.capabilities)}`),console.log(l?` Logged in as: ${a?.email??"unknown"}`:" Not logged in"),l&&a?.workspaceId&&console.log(` Workspace ID: ${a.workspaceId}`);return}if(t==="create"){let r=s||H.DEFAULT_PROFILE;if(H.createProfile(r),e.json){console.log(JSON.stringify({name:r,created:!0}));return}console.log(`Profile created: ${r}`);return}if(t==="use"||t==="switch"){let r=Wt(s,!0);if(H.setCurrentProfile(r),e.json){console.log(JSON.stringify({name:r,current:!0}));return}console.log(`Switched to profile: ${r}`);return}if(t==="delete"||t==="remove"||t==="rm"){let r=Wt(s,!0),i=H.deleteProfile(r);if(e.json){console.log(JSON.stringify({deleted:r,currentProfile:i.currentProfile}));return}console.log(`Profile deleted: ${r}`),console.log(`Current profile: ${i.currentProfile}`);return}if(t==="rename"||t==="move"||t==="mv"){let r=Wt(s,!0);if(!o)throw new Et("New profile name is required.");let i=H.renameProfile(r,o);if(e.json){console.log(JSON.stringify({renamed:r,name:o,currentProfile:i.currentProfile}));return}console.log(`Profile renamed: ${r} -> ${o}`),console.log(`Current profile: ${i.currentProfile}`);return}if(t==="clone"||t==="copy"){let r=Wt(s,!0);if(!o)throw new Et("Target profile name is required.");let i=ne.getAll(r);if(H.createProfile(o),ne.setAll(i,o),await $e.clear(o),e.json){console.log(JSON.stringify({source:r,name:o,cloned:!0}));return}console.log(`Profile cloned: ${r} -> ${o}`);return}throw new Et(`Unknown profile command: ${t}`)}catch(t){be(t)}}function Mt(){console.log(`
416
+ Usage: entrydesk schedules [list|get|create|delete] [options]
417
+
418
+ Commands:
419
+ list List all schedules (default)
420
+ get <scheduleId> Show schedule details
421
+ create Create a new schedule
422
+ delete <scheduleId> Delete a schedule
423
+
424
+ Create Options:
425
+ --name <name> Schedule name (required)
426
+ --prompt <text> Prompt to send to agent (required)
427
+ --agent-id <id> Agent ID to use (required)
428
+ --starts-at <datetime> Start time in ISO format (required)
429
+ --utc-offset <offset> Timezone offset (e.g., +08:00, default: +00:00)
430
+
431
+ Repeat Config:
432
+ --repeat-type <type> no-repeat, minutes, hours, days, weeks, months
433
+ --every <n> Repeat every N units
434
+ --time <HH:MM> Time of day (for days/weeks/months)
435
+ --days-of-week <0-6> Comma-separated days (0=Sun, for weeks)
436
+ --days-of-month <1-31> Comma-separated days (for months)
437
+ --last-day-of-month Include last day of month
438
+
439
+ Flags:
440
+ --json Output JSON
441
+ `)}function xs(e){if(e.type==="no-repeat")return"No repeat";let{interval:t}=e;switch(t.unit){case"minutes":return`Every ${t.every} minute${t.every>1?"s":""}`;case"hours":return`Every ${t.every} hour${t.every>1?"s":""} at :${String(t.minute).padStart(2,"0")}`;case"days":return`Every ${t.every} day${t.every>1?"s":""} at ${String(t.time.hour).padStart(2,"0")}:${String(t.time.minute).padStart(2,"0")}`;case"weeks":{let n=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],s=t.daysOfWeek.map(o=>n[o]).join(", ");return`Every ${t.every} week${t.every>1?"s":""} on ${s} at ${String(t.time.hour).padStart(2,"0")}:${String(t.time.minute).padStart(2,"0")}`}case"months":{let n=t.lastDayOfMonth?t.daysOfMonth.length>0?`${t.daysOfMonth.join(", ")} and last day`:"last day":t.daysOfMonth.join(", ");return`Every ${t.every} month${t.every>1?"s":""} on day ${n} at ${String(t.time.hour).padStart(2,"0")}:${String(t.time.minute).padStart(2,"0")}`}default:return"Unknown"}}function Jt(e,t){let n=new Date(e),s=t.match(/^([+-])(\d{2}):(\d{2})$/);if(!s)return n.toISOString();let o=s[1]==="+"?1:-1,r=parseInt(s[2],10),i=parseInt(s[3],10),a=o*(r*60+i)*60*1e3;return`${new Date(n.getTime()+a).toISOString().replace("T"," ").slice(0,19)} (${t})`}function ai(e){console.log(`
442
+ Schedule: ${e.name}
443
+ ${"\u2501".repeat(50)}
444
+ ID: ${e.id}
445
+ Agent: ${e.agent.name}
446
+ Status: ${e.isActive?"Active":"Paused"}
447
+ Timezone: ${e.utcOffset}
448
+
449
+ Prompt:
450
+ ${e.prompt.slice(0,200)}${e.prompt.length>200?"...":""}
451
+
452
+ Schedule:
453
+ ${xs(e.config)}
454
+
455
+ Next Run: ${e.nextRunAt?Jt(e.nextRunAt,e.utcOffset):"-"}
456
+ Created: ${Jt(e.createdAt,e.utcOffset)}
457
+ Updated: ${Jt(e.updatedAt,e.utcOffset)}
458
+ `)}function li(e){let t=e.repeatType||"no-repeat";if(t==="no-repeat")return{type:"no-repeat"};let n=e.every||1,s=e.time||"09:00",[o,r]=s.split(":"),i={hour:parseInt(o,10),minute:parseInt(r,10)};switch(t){case"minutes":return{type:"repeat",interval:{unit:"minutes",every:n}};case"hours":return{type:"repeat",interval:{unit:"hours",every:n,minute:i.minute}};case"days":return{type:"repeat",interval:{unit:"days",every:n,time:i}};case"weeks":return{type:"repeat",interval:{unit:"weeks",every:n,daysOfWeek:e.daysOfWeek||[1],time:i}};case"months":return{type:"repeat",interval:{unit:"months",every:n,daysOfMonth:e.daysOfMonth||[1],lastDayOfMonth:e.lastDayOfMonth||!1,time:i}};default:return{type:"no-repeat"}}}async function Cs(e){try{if(e.help){Mt();return}let t=await ye(),{accessToken:n,workspaceId:s}=t,o=e.action||"list",r=new B;if(o==="get"){let l=e.scheduleId;l||(console.error("Missing schedule ID."),Mt(),process.exit(1));let d=await r.getSchedule(n,s,l);if(e.json){console.log(JSON.stringify(d));return}ai(d);return}if(o==="create"){(!e.name||!e.prompt||!e.agentId||!e.startsAt)&&(console.error("Missing required fields for schedule creation."),console.error("Required: --name, --prompt, --agent-id, --starts-at"),Mt(),process.exit(1));let l={name:e.name,prompt:e.prompt,agentId:e.agentId,startsAt:e.startsAt,config:li(e),utcOffset:e.utcOffset||"+00:00"},d=await r.createSchedule(n,s,l);if(e.json){console.log(JSON.stringify(d));return}console.log(`Created schedule: ${d.name}`),console.log(` ID: ${d.id}`),console.log(` Next Run: ${d.nextRunAt?Jt(d.nextRunAt,d.utcOffset):"-"}`);return}if(o==="delete"){let l=e.scheduleId;l||(console.error("Missing schedule ID."),Mt(),process.exit(1)),await r.deleteSchedule(n,s,l),console.log(`Deleted schedule: ${l}`);return}o!=="list"&&(console.error(`Unknown schedules command: ${o}`),Mt(),process.exit(1));let i=[],a;do{let l=await r.getSchedules(n,s,{nextKey:a,limit:100});i.push(...l.schedules),a=l.nextKey}while(a);if(e.json){console.log(JSON.stringify(i));return}if(i.length===0){console.log("No schedules found in this workspace.");return}console.log(`Schedules (${i.length}):
459
+ `);for(let l of i){let d=l.isActive?"\x1B[32mActive\x1B[0m":"\x1B[33mPaused\x1B[0m";console.log(` ${l.name}`),console.log(` Agent: ${l.agent.name}`),console.log(` Repeat: ${xs(l.config)}`),console.log(` Status: ${d}`),console.log(` Next Run: ${l.nextRunAt?Jt(l.nextRunAt,l.utcOffset):"-"}`),console.log(` ID: ${l.id}`),console.log("")}}catch(t){be(t)}}import ci from"fs";import Pt from"fs/promises";import $s from"os";import st from"path";import ui from"archiver";function Ko(){console.log(`
460
+ Usage: entrydesk skills [list|upload|delete] [options]
461
+
462
+ Commands:
463
+ list List available skills (default)
464
+ upload <file.zip> Upload a skill zip file
465
+ upload <folder> Upload a skill folder (auto-zipped)
466
+ delete <skillId> Delete a skill you own
467
+
468
+ Options:
469
+ --me Only list skills created by me
470
+ --force Overwrite an existing skill with the same name
471
+ --json Output JSON (for list/upload)
472
+ `)}function di(e,t){let n=st.relative(e,t);return n===""||!n.startsWith("..")&&!st.isAbsolute(n)}async function fi(e){let t=await Pt.realpath(e),n=[process.cwd(),$s.homedir()];if(!(await Promise.all(n.map(async r=>{try{return await Pt.realpath(r)}catch{return st.resolve(r)}}))).some(r=>di(r,t)))throw new Error("Invalid upload path: must be within the current directory or your home directory.")}async function pi(e){let t=await Pt.mkdtemp(st.join($s.tmpdir(),"entrydesk-skill-")),n=st.join(t,`${st.basename(e)}.zip`);return await new Promise((s,o)=>{let r=ci.createWriteStream(n),i=ui("zip",{zlib:{level:9}});r.on("close",()=>s()),r.on("error",o),i.on("error",o),i.pipe(r),i.directory(e,!1),i.finalize()}),{zipPath:n,cleanupDir:t}}async function Ss(e){let t,n;try{let a=await ye();t=a.accessToken,n=a.workspaceId}catch(a){be(a)}let s=e.action||"list",o=new B;if(s==="upload"){let a=e.configKey;a||(console.error("Missing file path."),Ko(),process.exit(1));let l=st.resolve(a),d;try{d=await Pt.stat(l)}catch{console.error(`File not found: ${l}`),process.exit(1)}let v=l,b=null;try{try{await fi(l)}catch(h){let S=h instanceof Error?h.message:"Invalid upload path.";console.error(S),process.exit(1)}if(d.isDirectory()){let h=await pi(l);v=h.zipPath,b=h.cleanupDir}else d.isFile()||(console.error(`Not a file or directory: ${l}`),process.exit(1));st.extname(v).toLowerCase()!==".zip"&&(console.error("Only .zip files are supported for upload."),process.exit(1));let x=await Pt.readFile(v),C=new FormData;C.append("file",new Blob([x],{type:"application/zip"}),st.basename(v)),e.force&&C.append("force","true");let m;try{m=await o.uploadSkill(t,n,C)}catch(h){if(h instanceof Error&&h.name==="HTTPError"){let S=h;S.response&&S.response.status===409&&(console.error("Upload failed: A skill with this name already exists."),console.error("Use --force to overwrite the existing skill."),process.exit(1))}throw h}if(e.json){console.log(JSON.stringify(m));return}console.log(`Uploaded skill: ${m.name}`),console.log(` ID: ${m.id}`),console.log(` Description: ${m.description}`);return}finally{b&&await Pt.rm(b,{recursive:!0,force:!0})}}if(s==="delete"){let a=e.configKey;a||(console.error("Missing skill ID."),Ko(),process.exit(1)),await o.deleteSkill(t,n,a),console.log(`Deleted skill: ${a}`);return}s!=="list"&&(console.error(`Unknown skills command: ${s}`),Ko(),process.exit(1));let r=[],i;do{let a=await o.listAvailableSkills(t,n,{createdBy:e.createdBy,nextKey:i,limit:100});r.push(...a.skills),i=a.nextKey}while(i);if(e.json){console.log(JSON.stringify(r));return}if(r.length===0){console.log("No skills found in this workspace.");return}console.log(`Available Skills (${r.length}):
473
+ `);for(let a of r)console.log(` ${a.name} (${a.provider})`),console.log(` ${a.description.slice(0,120)}`),console.log(` ID: ${a.id}`),console.log(` Author: ${a.author.name}`),console.log("")}async function Ts(e){try{let t=H.getEffectiveProfileName(),n=await $e.getAll(),s={model:ne.getDefaultModel(),connectors:ne.getDefaultConnectorIds(),capabilities:ne.getCapabilities()};if(!n){e.json?console.log(JSON.stringify({loggedIn:!1,profile:t,defaults:s})):(console.log(`Profile: ${t}`),console.log("Not logged in"),console.log("Run `entrydesk login` to authenticate"));return}let o;if(n.workspaceId)try{let r=new B,i=await dt(),{workspaces:a}=await r.getWorkspaces(i);o=a.find(d=>d.id===n.workspaceId)?.name}catch(r){if(r instanceof Ze){e.json?console.log(JSON.stringify({loggedIn:!1,profile:t,defaults:s})):(console.log(`Profile: ${t}`),console.log("Not logged in"),console.log("Run `entrydesk login` to authenticate"));return}}e.json?console.log(JSON.stringify({loggedIn:!0,profile:t,email:n.email,workspaceId:n.workspaceId,workspaceName:o,defaults:s})):(console.log(`Profile: ${t}`),console.log(`Logged in as ${n.email}`),o&&console.log(`Workspace: ${o}`),n.workspaceId&&console.log(`Workspace ID: ${n.workspaceId}`))}catch(t){be(t)}}function mi(){console.log(`
474
+ Usage: entrydesk usage [options]
475
+
476
+ Options:
477
+ --limit <number> Limit number of users shown (default: all)
478
+ --sort-by cost|operations Sort by cost or operations (default: cost)
479
+ --json Output JSON
480
+
481
+ Examples:
482
+ entrydesk usage # Show all users, sorted by cost
483
+ entrydesk usage --limit 10 # Show top 10 users
484
+ entrydesk usage --sort-by operations # Sort by operation count
485
+ entrydesk usage --json # JSON output
486
+ `)}async function vs(e){if(e.help){mi();return}let t,n;try{let m=await ye();t=m.accessToken,n=m.workspaceId}catch(m){let h=m instanceof Error?m.message:"Authentication failed";console.error(h),process.exit(1)}let s=new B,o=[],r,i=0,a=100;do{let m=await s.getMonthlyUsages(t,n,{nextKey:r,limit:100});if(o.push(...m.monthlyUsages),r=m.nextKey,i++,i>=a){console.error(`Warning: Showing first ${o.length} entries (pagination limit reached)`);break}}while(r);if(e.json){console.log(JSON.stringify(o));return}if(o.length===0){console.log("No usage data found for this workspace.");return}console.log(`Current Month Usage:
487
+ `);let l=0,d=0;for(let m of o)l+=parseFloat(m.totalCost),d+=m.operationCount;console.log(`Total Cost: $${l.toFixed(2)}`),console.log(`Total Operations: ${d.toLocaleString()}`),console.log(`Users: ${o.length}
488
+ `);let v=e.sortBy||"cost",b=[...o].toSorted((m,h)=>v==="cost"?parseFloat(h.totalCost)-parseFloat(m.totalCost):h.operationCount-m.operationCount),x=e.limit&&e.limit>0?e.limit:b.length,C=b.slice(0,x);console.log(`Usage by User (sorted by ${v}, showing ${C.length} of ${o.length}):
489
+ `);for(let m of C){let h=parseFloat(m.totalCost);console.log(` ${m.user.name} (${m.user.email})`),console.log(` Cost: $${h.toFixed(2)}`),console.log(` Operations: ${m.operationCount.toLocaleString()}`),console.log("")}C.length<o.length&&console.log(`... and ${o.length-C.length} more users`)}function qo(){console.log("entrydesk 1.3.2")}function zo(){console.log(`
490
+ Usage: entrydesk workspaces [list|switch|use] [options]
491
+
492
+ Commands:
493
+ list List all workspaces (default)
494
+ switch <workspaceId> Switch to a workspace
495
+ use <workspaceId> Switch to a workspace (alias)
496
+
497
+ Flags:
498
+ --json Output JSON
499
+ `)}async function Is(e){if(e.help){zo();return}let t,s=(await $e.getAll())?.workspaceId;try{t=await dt()}catch(a){let l=a instanceof Error?a.message:"Authentication failed";console.error(l),process.exit(1)}let o=e.action||"list",r=new B;if(o==="switch"||o==="use"){let a=e.configKey;a||(console.error("Missing workspaceId for switch."),zo(),process.exit(1));let{workspaces:l}=await r.getWorkspaces(t),d=l.find(v=>v.id===a);if(!d){console.error(`Workspace not found: ${a}`),console.error(`
500
+ Available workspaces:`);for(let v of l)console.error(` ${v.name}: ${v.id}`);process.exit(1)}if(await $e.saveWorkspaceId(a),e.json){console.log(JSON.stringify({workspaceId:a,workspaceName:d.name}));return}console.log(`Switched to workspace: ${d.name}`),console.log(` ID: ${a}`);return}o!=="list"&&(console.error(`Unknown workspaces command: ${o}`),zo(),process.exit(1));let{workspaces:i}=await r.getWorkspaces(t);if(e.json){console.log(JSON.stringify(i));return}if(i.length===0){console.log("No workspaces found.");return}console.log(`Workspaces (${i.length}):
501
+ `);for(let a of i){let l=a.id===s?" (current)":"";console.log(` ${a.name}${l}`),console.log(` ID: ${a.id}`),console.log("")}}function Ps(e,t,n=!1){let s={},o={};for(let r=n?0:1;r<e.length;r++){let i=e[r];if(i==="--json")s.json=!0;else if(i==="--help"||i==="-h")s.help=!0;else if(i==="--profile")s.profile=e[++r];else switch(t){case"login":i==="--google"||i==="-g"?o.google=!0:i==="-i"||i==="--interactive"?o.interactive=!0:i==="--email"?o.email=e[++r]:i==="--password"&&(o.password=e[++r]);break;case"chat":if(i==="-m"||i==="--message")o.message=e[++r];else if(i==="-a"||i==="--agent")o.agentId=e[++r];else if(i==="--model")o.model=e[++r];else if(i==="--connectors"){let a=e[++r];o.connectors=a?.split(",").map(l=>l.trim())}else i==="-i"||i==="--interactive"?o.interactive=!0:i==="--full-output"?o.fullOutput=!0:i==="-c"||i==="--continue"?o.continue=parseInt(e[++r],10):i==="--plain"?o.plain=!0:i==="--output"?o.output=e[++r]:i==="--sandbox"?o.sandbox=!0:i==="--no-sandbox"?o.noSandbox=!0:i==="--web-search"?o.webSearch=!0:i==="--image-gen"?o.imageGen=!0:i==="--chart"?o.chart=!0:i==="--file-system"?o.fileSystem=!0:i==="--no-file-system"&&(o.noFileSystem=!0);break;case"agents":if(i==="--name")o.name=e[++r];else if(i==="--description")o.description=e[++r];else if(i==="--system-prompt")o.systemPrompt=e[++r];else if(i==="--model-id")o.modelId=e[++r];else if(i==="--connector-ids"){let a=e[++r];o.connectorIds=a?.split(",").map(l=>l.trim()).filter(Boolean)}else if(i==="--capabilities"){let a=e[++r];o.capabilities=a?.split(",").map(l=>l.trim()).filter(Boolean)}else if(i==="--conversation-starters"){let a=e[++r];o.conversationStarters=a?.split(",").map(l=>l.trim()).filter(Boolean)}else if(i==="--tools"){let a=e[++r];o.tools=a?.split(",").map(l=>l.trim()).filter(Boolean)}else i==="--icon-id"?o.iconId=e[++r]:i.startsWith("-")||(o.action?o.agentId=i:o.action=i);break;case"skills":i==="--force"?o.force=!0:i==="--me"||i==="--mine"?o.createdBy="me":i.startsWith("-")||(o.action?o.configKey=i:o.action=i);break;case"schedules":if(i==="--name")o.name=e[++r];else if(i==="--prompt")o.prompt=e[++r];else if(i==="--agent-id")o.agentId=e[++r];else if(i==="--starts-at")o.startsAt=e[++r];else if(i==="--utc-offset")o.utcOffset=e[++r];else if(i==="--repeat-type")o.repeatType=e[++r];else if(i==="--every")o.every=parseInt(e[++r],10);else if(i==="--time")o.time=e[++r];else if(i==="--days-of-week"){let a=e[++r];o.daysOfWeek=a?.split(",").map(l=>parseInt(l.trim(),10)).filter(l=>!isNaN(l))}else if(i==="--days-of-month"){let a=e[++r];o.daysOfMonth=a?.split(",").map(l=>parseInt(l.trim(),10)).filter(l=>!isNaN(l))}else i==="--last-day-of-month"?o.lastDayOfMonth=!0:i.startsWith("-")||(o.action?o.scheduleId=i:o.action=i);break;case"config":!o.action&&!i.startsWith("-")?o.action=i:!o.configKey&&!i.startsWith("-")?o.configKey=i:!o.value&&!i.startsWith("-")&&(o.value=i);break;case"profile":!o.action&&!i.startsWith("-")?o.action=i:!o.name&&!i.startsWith("-")?o.name=i:!o.value&&!i.startsWith("-")&&(o.value=i);break;case"chats":i==="--share"||i==="-s"?o.shareId=e[++r]:i==="--full-output"?o.fullOutput=!0:i==="--output"?o.output=e[++r]:!o.chatId&&!i.startsWith("-")&&(o.chatId=i);break;case"budget":!o.action&&!i.startsWith("-")?o.action=i:!o.configKey&&!i.startsWith("-")&&(o.configKey=i);break;case"usage":if(i==="--limit")o.limit=parseInt(e[++r],10);else if(i==="--sort-by"){let a=e[++r];(a==="cost"||a==="operations")&&(o.sortBy=a)}break;case"mcp":i==="--http"?o.http=!0:(i==="-p"||i==="--port")&&(o.port=parseInt(e[++r],10));break;case"workspaces":!o.action&&!i.startsWith("-")&&(o.action=i);break;default:break}}switch(t){case"login":return{command:"login",...s,...o};case"logout":return{command:"logout",...s,...o};case"status":return{command:"status",...s,...o};case"workspaces":return{command:"workspaces",...s,...o};case"agents":return{command:"agents",...s,...o};case"models":return{command:"models",...s,...o};case"connectors":return{command:"connectors",...s,...o};case"skills":return{command:"skills",...s,...o};case"schedules":return{command:"schedules",...s,...o};case"config":return{command:"config",...s,...o};case"profile":return{command:"profile",...s,...o};case"chat":return{command:"chat",...s,...o};case"chats":return{command:"chats",...s,...o};case"budget":return{command:"budget",...s,...o};case"usage":return{command:"usage",...s,...o};case"mcp":return{command:"mcp",...s,...o};case"version":return{command:"version",...s,...o};default:return{command:"help",...s,...o}}}import{jsx as wi}from"react/jsx-runtime";var Ge=process.argv.slice(2);(Ge[0]==="--help"||Ge[0]==="-h")&&(ho(),process.exit(0));(Ge[0]==="--version"||Ge[0]==="-v")&&(qo(),process.exit(0));var Yo=!Ge[0]||Ge[0].startsWith("-"),hi=Yo?"chat":Ge[0],xe=Ps(Ge,hi,Yo);Yo&&xe.command==="chat"&&(xe.interactive=!0);async function yi(){try{if(xe.command!=="profile"){let e=xe.profile||H.getCurrentProfileName();H.ensureProfileExists(e),H.setOverrideProfile(e)}switch(xe.command){case"login":await gs(xe);break;case"logout":await hs(xe);break;case"status":await Ts(xe);break;case"workspaces":await Is(xe);break;case"agents":await Zo(xe);break;case"models":await ks(xe);break;case"connectors":await fs(xe);break;case"skills":await Ss(xe);break;case"schedules":await Cs(xe);break;case"chats":await cs(xe);break;case"budget":await Qo(xe);break;case"usage":await vs(xe);break;case"config":xe.action==="help"||Ge[1]==="--help"?gi(wi(ds,{})):await us(xe);break;case"profile":await bs(xe);break;case"chat":Ge[1]==="--help"||Ge[1]==="-h"?ho():await ns(xe);break;case"mcp":await ws({mode:xe.http?"http":"stdio",port:xe.port});break;case"version":qo();break;default:ho();break}}catch(e){be(e)}}yi();
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import{a}from"./chunk-J6ER4MMT.js";export{a as TokenStorage};
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@entrydesk/cli",
3
+ "version": "1.3.2",
4
+ "description": "EntryDesk CLI - Interact with EntryDesk from your terminal",
5
+ "type": "module",
6
+ "bin": {
7
+ "entrydesk": "./dist/index.js"
8
+ },
9
+ "files": [
10
+ "dist",
11
+ "README.md"
12
+ ],
13
+ "dependencies": {
14
+ "@modelcontextprotocol/sdk": "1.24.2",
15
+ "archiver": "^7.0.1",
16
+ "glob": "^11.0.0",
17
+ "ink": "^6.5.1",
18
+ "ink-spinner": "^5.0.0",
19
+ "ink-text-input": "^6.0.0",
20
+ "ky": "^1.14.1",
21
+ "playwright": "^1.53.0",
22
+ "react": "^19.2.3",
23
+ "uuid": "^13.0.0",
24
+ "zod": "^3.25.76"
25
+ },
26
+ "devDependencies": {
27
+ "@lydell/node-pty": "^1.1.0",
28
+ "@testing-library/react": "^16.3.1",
29
+ "@types/archiver": "^7.0.0",
30
+ "@types/node": "^24.10.1",
31
+ "@types/react": "^19.2.0",
32
+ "@vitest/coverage-v8": "^4.0.10",
33
+ "happy-dom": "^20.0.11",
34
+ "ink-testing-library": "^4.0.0",
35
+ "memfs": "^4.51.1",
36
+ "strip-ansi": "^7.1.2",
37
+ "tsup": "^8.5.0",
38
+ "typescript": "^5.9.3",
39
+ "vitest": "^4.0.10",
40
+ "@entrydesk/shared": "0.0.0"
41
+ },
42
+ "optionalDependencies": {
43
+ "keytar": "^7.9.0"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "scripts": {
49
+ "build": "tsup",
50
+ "dev": "tsup --watch",
51
+ "lint": "oxlint src/",
52
+ "release": "semantic-release",
53
+ "start": "node dist/index.js",
54
+ "test": "vitest run",
55
+ "test:coverage": "vitest run --coverage",
56
+ "test:integration": "pnpm build && vitest run --root ./integration-tests",
57
+ "test:unit": "vitest run --config vitest.config.ts",
58
+ "test:watch": "vitest",
59
+ "typecheck": "tsc --noEmit"
60
+ }
61
+ }