hypha-cli 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/apps-CpJkx863.mjs +512 -0
- package/dist/apps-D659xu7q.mjs +424 -0
- package/dist/artifacts-C0yhSTgw.mjs +629 -0
- package/dist/artifacts-DdgZRh8t.mjs +764 -0
- package/dist/cli.mjs +28 -6
- package/dist/workspace-BwLwj61H.mjs +206 -0
- package/dist/workspace-DCueGyht.mjs +127 -0
- package/dist/workspace-DDljPOfV.mjs +286 -0
- package/dist/workspace-DMqqSmvB.mjs +283 -0
- package/dist/{workspace-D63jR8RA.mjs → workspace-RZLvWJpe.mjs} +3 -2
- package/dist/workspace-XO_tEtii.mjs +284 -0
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -21,11 +21,18 @@ function printHelp() {
|
|
|
21
21
|
|
|
22
22
|
Usage: hypha [--server URL] [--workspace WS] <command> [options]
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
Connection:
|
|
25
25
|
login [server-url] Login to Hypha server (opens browser)
|
|
26
|
+
info [--json] Show connection info
|
|
26
27
|
token [options] Generate a workspace token
|
|
28
|
+
|
|
29
|
+
Workspace management:
|
|
27
30
|
services [options] List services in workspace
|
|
28
|
-
|
|
31
|
+
clients [workspace] [--json] List connected clients
|
|
32
|
+
ping <client-id> Ping a client (check if alive)
|
|
33
|
+
kick <client-id> [workspace] Disconnect and remove a client (admin)
|
|
34
|
+
cleanup [workspace] Remove dead/stale clients (admin)
|
|
35
|
+
workspace-info [ws] [--json] Show detailed workspace info (admin)
|
|
29
36
|
|
|
30
37
|
Apps (manage server app definitions and instances):
|
|
31
38
|
apps list [--json] List installed app definitions
|
|
@@ -70,17 +77,32 @@ async function main() {
|
|
|
70
77
|
}
|
|
71
78
|
const commandArgs = args.slice(1);
|
|
72
79
|
if (subcommand === "login") {
|
|
73
|
-
const { loginCommand } = await import('./workspace-
|
|
80
|
+
const { loginCommand } = await import('./workspace-DDljPOfV.mjs');
|
|
74
81
|
await loginCommand(commandArgs);
|
|
75
82
|
} else if (subcommand === "token") {
|
|
76
|
-
const { tokenCommand } = await import('./workspace-
|
|
83
|
+
const { tokenCommand } = await import('./workspace-DDljPOfV.mjs');
|
|
77
84
|
await tokenCommand(commandArgs);
|
|
78
85
|
} else if (subcommand === "services") {
|
|
79
|
-
const { servicesCommand } = await import('./workspace-
|
|
86
|
+
const { servicesCommand } = await import('./workspace-DDljPOfV.mjs');
|
|
80
87
|
await servicesCommand(commandArgs);
|
|
81
88
|
} else if (subcommand === "info") {
|
|
82
|
-
const { infoCommand } = await import('./workspace-
|
|
89
|
+
const { infoCommand } = await import('./workspace-DDljPOfV.mjs');
|
|
83
90
|
await infoCommand(commandArgs);
|
|
91
|
+
} else if (subcommand === "clients") {
|
|
92
|
+
const { clientsCommand } = await import('./workspace-DDljPOfV.mjs');
|
|
93
|
+
await clientsCommand(commandArgs);
|
|
94
|
+
} else if (subcommand === "ping") {
|
|
95
|
+
const { pingCommand } = await import('./workspace-DDljPOfV.mjs');
|
|
96
|
+
await pingCommand(commandArgs);
|
|
97
|
+
} else if (subcommand === "kick") {
|
|
98
|
+
const { kickCommand } = await import('./workspace-DDljPOfV.mjs');
|
|
99
|
+
await kickCommand(commandArgs);
|
|
100
|
+
} else if (subcommand === "cleanup") {
|
|
101
|
+
const { cleanupCommand } = await import('./workspace-DDljPOfV.mjs');
|
|
102
|
+
await cleanupCommand(commandArgs);
|
|
103
|
+
} else if (subcommand === "workspace-info") {
|
|
104
|
+
const { workspaceInfoCommand } = await import('./workspace-DDljPOfV.mjs');
|
|
105
|
+
await workspaceInfoCommand(commandArgs);
|
|
84
106
|
} else if (subcommand === "apps") {
|
|
85
107
|
const { handleAppsCommand } = await import('./apps-DqDtK6XB.mjs');
|
|
86
108
|
await handleAppsCommand(commandArgs);
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { e as hasFlag, l as loginToHypha, c as connectToHypha, g as getFlagInt, i as getFlag, f as formatJson, a as formatTable, r as resolveServerUrl } from './helpers-DWQC3Lr8.mjs';
|
|
2
|
+
import 'fs';
|
|
3
|
+
import 'path';
|
|
4
|
+
import 'os';
|
|
5
|
+
|
|
6
|
+
async function loginCommand(args) {
|
|
7
|
+
if (hasFlag(args, "--help", "-h")) {
|
|
8
|
+
console.log(`Usage: hypha login [server-url]
|
|
9
|
+
|
|
10
|
+
Login to a Hypha server via browser-based OAuth.
|
|
11
|
+
Credentials are saved to ~/.hypha/.env.
|
|
12
|
+
|
|
13
|
+
Default server: https://hypha.aicell.io`);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const serverUrl = args[0] && !args[0].startsWith("-") ? args[0] : void 0;
|
|
17
|
+
await loginToHypha(serverUrl);
|
|
18
|
+
}
|
|
19
|
+
async function tokenCommand(args) {
|
|
20
|
+
if (hasFlag(args, "--help", "-h")) {
|
|
21
|
+
console.log(`Usage: hypha token [options]
|
|
22
|
+
|
|
23
|
+
Generate a workspace token.
|
|
24
|
+
|
|
25
|
+
Options:
|
|
26
|
+
--expires-in <seconds> Token expiration (default: 3600)
|
|
27
|
+
--permission <perm> Permission level: read, read_write, admin (default: read_write)
|
|
28
|
+
--workspace <ws> Target workspace (default: current)
|
|
29
|
+
--json Output as JSON`);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const server = await connectToHypha();
|
|
33
|
+
try {
|
|
34
|
+
const expiresIn = getFlagInt(args, "--expires-in") || 3600;
|
|
35
|
+
const permission = getFlag(args, "--permission") || "read_write";
|
|
36
|
+
const workspace = getFlag(args, "--workspace") || server.config.workspace;
|
|
37
|
+
const json = hasFlag(args, "--json");
|
|
38
|
+
const token = await server.generateToken({
|
|
39
|
+
expires_in: expiresIn,
|
|
40
|
+
permission,
|
|
41
|
+
workspace
|
|
42
|
+
});
|
|
43
|
+
if (json) {
|
|
44
|
+
console.log(formatJson({
|
|
45
|
+
token,
|
|
46
|
+
workspace,
|
|
47
|
+
permission,
|
|
48
|
+
expires_in: expiresIn
|
|
49
|
+
}));
|
|
50
|
+
} else {
|
|
51
|
+
console.log(token);
|
|
52
|
+
}
|
|
53
|
+
} finally {
|
|
54
|
+
await server.disconnect();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async function servicesCommand(args) {
|
|
58
|
+
if (hasFlag(args, "--help", "-h")) {
|
|
59
|
+
console.log(`Usage: hypha services [options]
|
|
60
|
+
|
|
61
|
+
List services in the current workspace.
|
|
62
|
+
|
|
63
|
+
Options:
|
|
64
|
+
--type <type> Filter by service type
|
|
65
|
+
--include-unlisted Include unlisted services
|
|
66
|
+
--json Output as JSON`);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const server = await connectToHypha();
|
|
70
|
+
try {
|
|
71
|
+
const type = getFlag(args, "--type");
|
|
72
|
+
const includeUnlisted = hasFlag(args, "--include-unlisted");
|
|
73
|
+
const json = hasFlag(args, "--json");
|
|
74
|
+
const query = { _rkwargs: true };
|
|
75
|
+
if (type) query.type = type;
|
|
76
|
+
if (includeUnlisted) query.include_unlisted = true;
|
|
77
|
+
const services = await server.listServices(query);
|
|
78
|
+
if (json) {
|
|
79
|
+
console.log(formatJson(services));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (!services || services.length === 0) {
|
|
83
|
+
console.log("No services found.");
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const rows = [["ID", "NAME", "TYPE", "DESCRIPTION"]];
|
|
87
|
+
for (const svc of services) {
|
|
88
|
+
rows.push([
|
|
89
|
+
svc.id || "",
|
|
90
|
+
svc.name || "",
|
|
91
|
+
svc.type || "",
|
|
92
|
+
(svc.description || "").slice(0, 60)
|
|
93
|
+
]);
|
|
94
|
+
}
|
|
95
|
+
console.log(formatTable(rows));
|
|
96
|
+
} finally {
|
|
97
|
+
await server.disconnect();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async function clientsCommand(args) {
|
|
101
|
+
if (hasFlag(args, "--help", "-h")) {
|
|
102
|
+
console.log(`Usage: hypha clients [options]
|
|
103
|
+
|
|
104
|
+
List connected clients in the workspace.
|
|
105
|
+
|
|
106
|
+
Options:
|
|
107
|
+
--json Output as JSON`);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const server = await connectToHypha();
|
|
111
|
+
try {
|
|
112
|
+
const json = hasFlag(args, "--json");
|
|
113
|
+
const wm = await server.getService("public/*:workspace-manager");
|
|
114
|
+
const clients = await wm.listClients({ workspace: server.config.workspace, _rkwargs: true });
|
|
115
|
+
if (json) {
|
|
116
|
+
console.log(formatJson(clients));
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
console.log(`${clients.length} client(s) in workspace ${server.config.workspace}`);
|
|
120
|
+
if (clients.length === 0) return;
|
|
121
|
+
const byToken = {};
|
|
122
|
+
for (const c of clients) {
|
|
123
|
+
const id = typeof c === "string" ? c : c.id || c;
|
|
124
|
+
const key = String(id).split("/").pop()?.split(":")[0] || String(id);
|
|
125
|
+
if (!byToken[key]) byToken[key] = [];
|
|
126
|
+
byToken[key].push(String(id));
|
|
127
|
+
}
|
|
128
|
+
for (const c of clients.slice(0, 30)) {
|
|
129
|
+
const id = typeof c === "string" ? c : c.id || c;
|
|
130
|
+
console.log(` ${id}`);
|
|
131
|
+
}
|
|
132
|
+
if (clients.length > 30) {
|
|
133
|
+
console.log(` ... and ${clients.length - 30} more`);
|
|
134
|
+
}
|
|
135
|
+
} finally {
|
|
136
|
+
await server.disconnect();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
async function cleanupCommand(args) {
|
|
140
|
+
if (hasFlag(args, "--help", "-h")) {
|
|
141
|
+
console.log(`Usage: hypha cleanup [options]
|
|
142
|
+
|
|
143
|
+
Ping all clients in the workspace and remove dead/stale ones.
|
|
144
|
+
Requires admin permission.
|
|
145
|
+
|
|
146
|
+
Options:
|
|
147
|
+
--timeout <seconds> Ping timeout per client (default: 2)
|
|
148
|
+
--json Output as JSON`);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const server = await connectToHypha();
|
|
152
|
+
try {
|
|
153
|
+
const timeout = getFlagInt(args, "--timeout") || 2;
|
|
154
|
+
const json = hasFlag(args, "--json");
|
|
155
|
+
const ws = server.config.workspace;
|
|
156
|
+
const wm = await server.getService("public/*:workspace-manager");
|
|
157
|
+
const clients = await wm.listClients({ workspace: ws, _rkwargs: true });
|
|
158
|
+
console.log(`Workspace ${ws}: ${clients.length} client(s)`);
|
|
159
|
+
console.log(`Pinging all clients (timeout=${timeout}s)... this may take a while.`);
|
|
160
|
+
const result = await wm.cleanup({ workspace: ws, timeout, _rkwargs: true });
|
|
161
|
+
const removed = result?.removed_clients || result?.removedClients || [];
|
|
162
|
+
if (json) {
|
|
163
|
+
console.log(formatJson(result));
|
|
164
|
+
} else {
|
|
165
|
+
console.log(`Removed ${removed.length} dead client(s).`);
|
|
166
|
+
if (removed.length > 0 && removed.length <= 20) {
|
|
167
|
+
for (const c of removed) {
|
|
168
|
+
console.log(` - ${c}`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (result?.removed_workspace || result?.removedWorkspace) {
|
|
172
|
+
console.log(`Workspace ${ws} was removed (no live clients remaining).`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
} finally {
|
|
176
|
+
await server.disconnect();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async function infoCommand(args) {
|
|
180
|
+
if (hasFlag(args, "--help", "-h")) {
|
|
181
|
+
console.log(`Usage: hypha info [--json]
|
|
182
|
+
|
|
183
|
+
Show workspace information.`);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
const server = await connectToHypha();
|
|
187
|
+
try {
|
|
188
|
+
const json = hasFlag(args, "--json");
|
|
189
|
+
const info = {
|
|
190
|
+
server_url: server.config.public_base_url || resolveServerUrl(),
|
|
191
|
+
workspace: server.config.workspace,
|
|
192
|
+
client_id: server.config.client_id
|
|
193
|
+
};
|
|
194
|
+
if (json) {
|
|
195
|
+
console.log(formatJson(info));
|
|
196
|
+
} else {
|
|
197
|
+
console.log(`Server: ${info.server_url}`);
|
|
198
|
+
console.log(`Workspace: ${info.workspace}`);
|
|
199
|
+
console.log(`Client ID: ${info.client_id}`);
|
|
200
|
+
}
|
|
201
|
+
} finally {
|
|
202
|
+
await server.disconnect();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export { cleanupCommand, clientsCommand, infoCommand, loginCommand, servicesCommand, tokenCommand };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { e as hasFlag, l as loginToHypha, c as connectToHypha, g as getFlagInt, i as getFlag, f as formatJson, a as formatTable, r as resolveServerUrl } from './helpers-DWQC3Lr8.mjs';
|
|
2
|
+
import 'fs';
|
|
3
|
+
import 'path';
|
|
4
|
+
import 'os';
|
|
5
|
+
|
|
6
|
+
async function loginCommand(args) {
|
|
7
|
+
if (hasFlag(args, "--help", "-h")) {
|
|
8
|
+
console.log(`Usage: hypha login [server-url]
|
|
9
|
+
|
|
10
|
+
Login to a Hypha server via browser-based OAuth.
|
|
11
|
+
Credentials are saved to ~/.hypha/.env.
|
|
12
|
+
|
|
13
|
+
Default server: https://hypha.aicell.io`);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const serverUrl = args[0] && !args[0].startsWith("-") ? args[0] : void 0;
|
|
17
|
+
await loginToHypha(serverUrl);
|
|
18
|
+
}
|
|
19
|
+
async function tokenCommand(args) {
|
|
20
|
+
if (hasFlag(args, "--help", "-h")) {
|
|
21
|
+
console.log(`Usage: hypha token [options]
|
|
22
|
+
|
|
23
|
+
Generate a workspace token.
|
|
24
|
+
|
|
25
|
+
Options:
|
|
26
|
+
--expires-in <seconds> Token expiration (default: 3600)
|
|
27
|
+
--permission <perm> Permission level: read, read_write, admin (default: read_write)
|
|
28
|
+
--workspace <ws> Target workspace (default: current)
|
|
29
|
+
--json Output as JSON`);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const server = await connectToHypha();
|
|
33
|
+
try {
|
|
34
|
+
const expiresIn = getFlagInt(args, "--expires-in") || 3600;
|
|
35
|
+
const permission = getFlag(args, "--permission") || "read_write";
|
|
36
|
+
const workspace = getFlag(args, "--workspace") || server.config.workspace;
|
|
37
|
+
const json = hasFlag(args, "--json");
|
|
38
|
+
const token = await server.generateToken({
|
|
39
|
+
expires_in: expiresIn,
|
|
40
|
+
permission,
|
|
41
|
+
workspace
|
|
42
|
+
});
|
|
43
|
+
if (json) {
|
|
44
|
+
console.log(formatJson({
|
|
45
|
+
token,
|
|
46
|
+
workspace,
|
|
47
|
+
permission,
|
|
48
|
+
expires_in: expiresIn
|
|
49
|
+
}));
|
|
50
|
+
} else {
|
|
51
|
+
console.log(token);
|
|
52
|
+
}
|
|
53
|
+
} finally {
|
|
54
|
+
await server.disconnect();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async function servicesCommand(args) {
|
|
58
|
+
if (hasFlag(args, "--help", "-h")) {
|
|
59
|
+
console.log(`Usage: hypha services [options]
|
|
60
|
+
|
|
61
|
+
List services in the current workspace.
|
|
62
|
+
|
|
63
|
+
Options:
|
|
64
|
+
--type <type> Filter by service type
|
|
65
|
+
--include-unlisted Include unlisted services
|
|
66
|
+
--json Output as JSON`);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const server = await connectToHypha();
|
|
70
|
+
try {
|
|
71
|
+
const type = getFlag(args, "--type");
|
|
72
|
+
const includeUnlisted = hasFlag(args, "--include-unlisted");
|
|
73
|
+
const json = hasFlag(args, "--json");
|
|
74
|
+
const query = { _rkwargs: true };
|
|
75
|
+
if (type) query.type = type;
|
|
76
|
+
if (includeUnlisted) query.include_unlisted = true;
|
|
77
|
+
const services = await server.listServices(query);
|
|
78
|
+
if (json) {
|
|
79
|
+
console.log(formatJson(services));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (!services || services.length === 0) {
|
|
83
|
+
console.log("No services found.");
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const rows = [["ID", "NAME", "TYPE", "DESCRIPTION"]];
|
|
87
|
+
for (const svc of services) {
|
|
88
|
+
rows.push([
|
|
89
|
+
svc.id || "",
|
|
90
|
+
svc.name || "",
|
|
91
|
+
svc.type || "",
|
|
92
|
+
(svc.description || "").slice(0, 60)
|
|
93
|
+
]);
|
|
94
|
+
}
|
|
95
|
+
console.log(formatTable(rows));
|
|
96
|
+
} finally {
|
|
97
|
+
await server.disconnect();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async function infoCommand(args) {
|
|
101
|
+
if (hasFlag(args, "--help", "-h")) {
|
|
102
|
+
console.log(`Usage: hypha info [--json]
|
|
103
|
+
|
|
104
|
+
Show workspace information.`);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const server = await connectToHypha();
|
|
108
|
+
try {
|
|
109
|
+
const json = hasFlag(args, "--json");
|
|
110
|
+
const info = {
|
|
111
|
+
server_url: server.config.public_base_url || resolveServerUrl(),
|
|
112
|
+
workspace: server.config.workspace,
|
|
113
|
+
client_id: server.config.client_id
|
|
114
|
+
};
|
|
115
|
+
if (json) {
|
|
116
|
+
console.log(formatJson(info));
|
|
117
|
+
} else {
|
|
118
|
+
console.log(`Server: ${info.server_url}`);
|
|
119
|
+
console.log(`Workspace: ${info.workspace}`);
|
|
120
|
+
console.log(`Client ID: ${info.client_id}`);
|
|
121
|
+
}
|
|
122
|
+
} finally {
|
|
123
|
+
await server.disconnect();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export { infoCommand, loginCommand, servicesCommand, tokenCommand };
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { e as hasFlag, l as loginToHypha, c as connectToHypha, g as getFlagInt, i as getFlag, f as formatJson, a as formatTable, r as resolveServerUrl } from './helpers-DWQC3Lr8.mjs';
|
|
2
|
+
import 'fs';
|
|
3
|
+
import 'path';
|
|
4
|
+
import 'os';
|
|
5
|
+
|
|
6
|
+
async function loginCommand(args) {
|
|
7
|
+
if (hasFlag(args, "--help", "-h")) {
|
|
8
|
+
console.log(`Usage: hypha login [server-url]
|
|
9
|
+
|
|
10
|
+
Login to a Hypha server via browser-based OAuth.
|
|
11
|
+
Credentials are saved to ~/.hypha/.env.
|
|
12
|
+
|
|
13
|
+
Default server: https://hypha.aicell.io`);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const serverUrl = args[0] && !args[0].startsWith("-") ? args[0] : void 0;
|
|
17
|
+
await loginToHypha(serverUrl);
|
|
18
|
+
}
|
|
19
|
+
async function tokenCommand(args) {
|
|
20
|
+
if (hasFlag(args, "--help", "-h")) {
|
|
21
|
+
console.log(`Usage: hypha token [options]
|
|
22
|
+
|
|
23
|
+
Generate a workspace token.
|
|
24
|
+
|
|
25
|
+
Options:
|
|
26
|
+
--expires-in <seconds> Token expiration (default: 3600)
|
|
27
|
+
--permission <perm> Permission level: read, read_write, admin (default: read_write)
|
|
28
|
+
--workspace <ws> Target workspace (default: current)
|
|
29
|
+
--json Output as JSON`);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const server = await connectToHypha();
|
|
33
|
+
try {
|
|
34
|
+
const expiresIn = getFlagInt(args, "--expires-in") || 3600;
|
|
35
|
+
const permission = getFlag(args, "--permission") || "read_write";
|
|
36
|
+
const workspace = getFlag(args, "--workspace") || server.config.workspace;
|
|
37
|
+
const json = hasFlag(args, "--json");
|
|
38
|
+
const token = await server.generateToken({
|
|
39
|
+
expires_in: expiresIn,
|
|
40
|
+
permission,
|
|
41
|
+
workspace
|
|
42
|
+
});
|
|
43
|
+
if (json) {
|
|
44
|
+
console.log(formatJson({
|
|
45
|
+
token,
|
|
46
|
+
workspace,
|
|
47
|
+
permission,
|
|
48
|
+
expires_in: expiresIn
|
|
49
|
+
}));
|
|
50
|
+
} else {
|
|
51
|
+
console.log(token);
|
|
52
|
+
}
|
|
53
|
+
} finally {
|
|
54
|
+
await server.disconnect();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async function servicesCommand(args) {
|
|
58
|
+
if (hasFlag(args, "--help", "-h")) {
|
|
59
|
+
console.log(`Usage: hypha services [options]
|
|
60
|
+
|
|
61
|
+
List services in the current workspace.
|
|
62
|
+
|
|
63
|
+
Options:
|
|
64
|
+
--type <type> Filter by service type
|
|
65
|
+
--include-unlisted Include unlisted services
|
|
66
|
+
--json Output as JSON`);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const server = await connectToHypha();
|
|
70
|
+
try {
|
|
71
|
+
const type = getFlag(args, "--type");
|
|
72
|
+
const includeUnlisted = hasFlag(args, "--include-unlisted");
|
|
73
|
+
const json = hasFlag(args, "--json");
|
|
74
|
+
const query = { _rkwargs: true };
|
|
75
|
+
if (type) query.type = type;
|
|
76
|
+
if (includeUnlisted) query.include_unlisted = true;
|
|
77
|
+
const services = await server.listServices(query);
|
|
78
|
+
if (json) {
|
|
79
|
+
console.log(formatJson(services));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (!services || services.length === 0) {
|
|
83
|
+
console.log("No services found.");
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const rows = [["ID", "NAME", "TYPE", "DESCRIPTION"]];
|
|
87
|
+
for (const svc of services) {
|
|
88
|
+
rows.push([
|
|
89
|
+
svc.id || "",
|
|
90
|
+
svc.name || "",
|
|
91
|
+
svc.type || "",
|
|
92
|
+
(svc.description || "").slice(0, 60)
|
|
93
|
+
]);
|
|
94
|
+
}
|
|
95
|
+
console.log(formatTable(rows));
|
|
96
|
+
} finally {
|
|
97
|
+
await server.disconnect();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async function clientsCommand(args) {
|
|
101
|
+
if (hasFlag(args, "--help", "-h")) {
|
|
102
|
+
console.log(`Usage: hypha clients [workspace] [options]
|
|
103
|
+
|
|
104
|
+
List connected clients in a workspace. Defaults to the connected workspace.
|
|
105
|
+
Pass a workspace name as positional arg to target a different workspace (requires admin).
|
|
106
|
+
|
|
107
|
+
Options:
|
|
108
|
+
--json Output as JSON`);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const server = await connectToHypha();
|
|
112
|
+
try {
|
|
113
|
+
const json = hasFlag(args, "--json");
|
|
114
|
+
const targetWs = args[0] && !args[0].startsWith("-") ? args[0] : server.config.workspace;
|
|
115
|
+
const clients = await server.listClients({ workspace: targetWs, _rkwargs: true });
|
|
116
|
+
if (json) {
|
|
117
|
+
console.log(formatJson(clients));
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
console.log(`${clients.length} client(s) in workspace ${targetWs}`);
|
|
121
|
+
if (clients.length === 0) return;
|
|
122
|
+
for (const c of clients.slice(0, 50)) {
|
|
123
|
+
const id = typeof c === "string" ? c : c.id || String(c);
|
|
124
|
+
const email = typeof c === "object" ? c.user?.email || "" : "";
|
|
125
|
+
console.log(` ${id}${email ? " (" + email + ")" : ""}`);
|
|
126
|
+
}
|
|
127
|
+
if (clients.length > 50) {
|
|
128
|
+
console.log(` ... and ${clients.length - 50} more`);
|
|
129
|
+
}
|
|
130
|
+
} finally {
|
|
131
|
+
await server.disconnect();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async function pingCommand(args) {
|
|
135
|
+
if (hasFlag(args, "--help", "-h")) {
|
|
136
|
+
console.log(`Usage: hypha ping <client-id> [options]
|
|
137
|
+
|
|
138
|
+
Ping a specific client to check if it's alive.
|
|
139
|
+
|
|
140
|
+
Options:
|
|
141
|
+
--timeout <seconds> Ping timeout (default: 5)`);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const clientId = args[0] && !args[0].startsWith("-") ? args[0] : void 0;
|
|
145
|
+
if (!clientId) {
|
|
146
|
+
console.error("Usage: hypha ping <client-id>");
|
|
147
|
+
process.exit(1);
|
|
148
|
+
}
|
|
149
|
+
const server = await connectToHypha();
|
|
150
|
+
try {
|
|
151
|
+
const timeout = getFlagInt(args, "--timeout") || 5;
|
|
152
|
+
try {
|
|
153
|
+
const result = await server.ping({ client_id: clientId, timeout, _rkwargs: true });
|
|
154
|
+
console.log(`${clientId}: ${result}`);
|
|
155
|
+
} catch (e) {
|
|
156
|
+
console.log(`${clientId}: dead (${e.message || e})`);
|
|
157
|
+
}
|
|
158
|
+
} finally {
|
|
159
|
+
await server.disconnect();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
async function kickCommand(args) {
|
|
163
|
+
if (hasFlag(args, "--help", "-h")) {
|
|
164
|
+
console.log(`Usage: hypha kick <client-id> [workspace]
|
|
165
|
+
|
|
166
|
+
Disconnect a client and remove all its services. Requires admin.
|
|
167
|
+
If workspace is not specified, uses the connected workspace.
|
|
168
|
+
|
|
169
|
+
Note: delete_client is not in the default workspace interface.
|
|
170
|
+
This command uses the workspace-manager service directly.`);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const clientId = args[0] && !args[0].startsWith("-") ? args[0] : void 0;
|
|
174
|
+
if (!clientId) {
|
|
175
|
+
console.error("Usage: hypha kick <client-id> [workspace]");
|
|
176
|
+
process.exit(1);
|
|
177
|
+
}
|
|
178
|
+
const server = await connectToHypha();
|
|
179
|
+
try {
|
|
180
|
+
const targetWs = args[1] && !args[1].startsWith("-") ? args[1] : server.config.workspace;
|
|
181
|
+
const svc = await server.getService(`${server.config.workspace}/*:default`);
|
|
182
|
+
if (svc.deleteClient) {
|
|
183
|
+
await svc.deleteClient({ client_id: clientId, workspace: targetWs, _rkwargs: true });
|
|
184
|
+
} else {
|
|
185
|
+
console.error("delete_client is not available. Use `hypha cleanup` instead.");
|
|
186
|
+
process.exit(1);
|
|
187
|
+
}
|
|
188
|
+
console.log(`Kicked client ${clientId} from ${targetWs}`);
|
|
189
|
+
} finally {
|
|
190
|
+
await server.disconnect();
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
async function cleanupCommand(args) {
|
|
194
|
+
if (hasFlag(args, "--help", "-h")) {
|
|
195
|
+
console.log(`Usage: hypha cleanup [workspace] [options]
|
|
196
|
+
|
|
197
|
+
Ping all clients in a workspace and remove dead/stale ones.
|
|
198
|
+
Requires admin permission.
|
|
199
|
+
Defaults to the connected workspace. Pass workspace name as positional arg.
|
|
200
|
+
|
|
201
|
+
Options:
|
|
202
|
+
--timeout <seconds> Ping timeout per client (default: 2)
|
|
203
|
+
--json Output as JSON`);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const server = await connectToHypha();
|
|
207
|
+
try {
|
|
208
|
+
const timeout = getFlagInt(args, "--timeout") || 2;
|
|
209
|
+
const json = hasFlag(args, "--json");
|
|
210
|
+
const targetWs = args[0] && !args[0].startsWith("-") ? args[0] : server.config.workspace;
|
|
211
|
+
const clients = await server.listClients({ workspace: targetWs, _rkwargs: true });
|
|
212
|
+
console.log(`Workspace ${targetWs}: ${clients.length} client(s)`);
|
|
213
|
+
console.log(`Pinging all clients (timeout=${timeout}s)... this may take a while.`);
|
|
214
|
+
const result = await server.cleanup({ workspace: targetWs, timeout, _rkwargs: true });
|
|
215
|
+
const removed = result?.removed_clients || result?.removedClients || [];
|
|
216
|
+
if (json) {
|
|
217
|
+
console.log(formatJson(result));
|
|
218
|
+
} else {
|
|
219
|
+
console.log(`Removed ${removed.length} dead client(s).`);
|
|
220
|
+
if (removed.length > 0 && removed.length <= 30) {
|
|
221
|
+
for (const c of removed) {
|
|
222
|
+
console.log(` - ${c}`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (result?.removed_workspace || result?.removedWorkspace) {
|
|
226
|
+
console.log(`Workspace ${targetWs} was removed (no live clients remaining).`);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
} finally {
|
|
230
|
+
await server.disconnect();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
async function workspaceInfoCommand(args) {
|
|
234
|
+
if (hasFlag(args, "--help", "-h")) {
|
|
235
|
+
console.log(`Usage: hypha workspace-info [workspace] [--json]
|
|
236
|
+
|
|
237
|
+
Show detailed workspace information (admin).`);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const server = await connectToHypha();
|
|
241
|
+
try {
|
|
242
|
+
const json = hasFlag(args, "--json");
|
|
243
|
+
const targetWs = args[0] && !args[0].startsWith("-") ? args[0] : server.config.workspace;
|
|
244
|
+
const wsInfo = await server.getWorkspaceInfo({ workspace: targetWs, _rkwargs: true });
|
|
245
|
+
if (json) {
|
|
246
|
+
console.log(formatJson(wsInfo));
|
|
247
|
+
} else {
|
|
248
|
+
console.log(`Workspace: ${wsInfo.id || wsInfo.name || targetWs}`);
|
|
249
|
+
for (const [k, v] of Object.entries(wsInfo)) {
|
|
250
|
+
if (k === "id" || k === "name") continue;
|
|
251
|
+
const val = typeof v === "object" ? JSON.stringify(v) : String(v);
|
|
252
|
+
console.log(` ${k}: ${val.slice(0, 120)}`);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
} finally {
|
|
256
|
+
await server.disconnect();
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
async function infoCommand(args) {
|
|
260
|
+
if (hasFlag(args, "--help", "-h")) {
|
|
261
|
+
console.log(`Usage: hypha info [--json]
|
|
262
|
+
|
|
263
|
+
Show connection information.`);
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
const server = await connectToHypha();
|
|
267
|
+
try {
|
|
268
|
+
const json = hasFlag(args, "--json");
|
|
269
|
+
const info = {
|
|
270
|
+
server_url: server.config.public_base_url || resolveServerUrl(),
|
|
271
|
+
workspace: server.config.workspace,
|
|
272
|
+
client_id: server.config.client_id
|
|
273
|
+
};
|
|
274
|
+
if (json) {
|
|
275
|
+
console.log(formatJson(info));
|
|
276
|
+
} else {
|
|
277
|
+
console.log(`Server: ${info.server_url}`);
|
|
278
|
+
console.log(`Workspace: ${info.workspace}`);
|
|
279
|
+
console.log(`Client ID: ${info.client_id}`);
|
|
280
|
+
}
|
|
281
|
+
} finally {
|
|
282
|
+
await server.disconnect();
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export { cleanupCommand, clientsCommand, infoCommand, kickCommand, loginCommand, pingCommand, servicesCommand, tokenCommand, workspaceInfoCommand };
|