hypha-cli 0.1.7 → 0.1.8
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/cli.mjs
CHANGED
|
@@ -70,16 +70,16 @@ async function main() {
|
|
|
70
70
|
}
|
|
71
71
|
const commandArgs = args.slice(1);
|
|
72
72
|
if (subcommand === "login") {
|
|
73
|
-
const { loginCommand } = await import('./workspace-
|
|
73
|
+
const { loginCommand } = await import('./workspace-DCueGyht.mjs');
|
|
74
74
|
await loginCommand(commandArgs);
|
|
75
75
|
} else if (subcommand === "token") {
|
|
76
|
-
const { tokenCommand } = await import('./workspace-
|
|
76
|
+
const { tokenCommand } = await import('./workspace-DCueGyht.mjs');
|
|
77
77
|
await tokenCommand(commandArgs);
|
|
78
78
|
} else if (subcommand === "services") {
|
|
79
|
-
const { servicesCommand } = await import('./workspace-
|
|
79
|
+
const { servicesCommand } = await import('./workspace-DCueGyht.mjs');
|
|
80
80
|
await servicesCommand(commandArgs);
|
|
81
81
|
} else if (subcommand === "info") {
|
|
82
|
-
const { infoCommand } = await import('./workspace-
|
|
82
|
+
const { infoCommand } = await import('./workspace-DCueGyht.mjs');
|
|
83
83
|
await infoCommand(commandArgs);
|
|
84
84
|
} else if (subcommand === "apps") {
|
|
85
85
|
const { handleAppsCommand } = await import('./apps-DqDtK6XB.mjs');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { e as hasFlag, l as loginToHypha, c as connectToHypha, g as getFlagInt, i as getFlag, f as formatJson, a as formatTable } from './helpers-
|
|
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
2
|
import 'fs';
|
|
3
3
|
import 'path';
|
|
4
4
|
import 'os';
|
|
@@ -108,7 +108,7 @@ Show workspace information.`);
|
|
|
108
108
|
try {
|
|
109
109
|
const json = hasFlag(args, "--json");
|
|
110
110
|
const info = {
|
|
111
|
-
server_url: server.config.
|
|
111
|
+
server_url: server.config.public_base_url || resolveServerUrl(),
|
|
112
112
|
workspace: server.config.workspace,
|
|
113
113
|
client_id: server.config.client_id
|
|
114
114
|
};
|
package/package.json
CHANGED
package/dist/apps-rK1_N8nw.mjs
DELETED
|
@@ -1,512 +0,0 @@
|
|
|
1
|
-
import { statSync, readFileSync, readdirSync } from 'fs';
|
|
2
|
-
import { join, extname } from 'path';
|
|
3
|
-
import { e as hasFlag, f as formatJson, a as formatTable, p as positionalArgs, j as relativeTime, c as connectToHypha, k as getAllFlags, i as getFlag, g as getFlagInt } from './helpers-BvfSCkvr.mjs';
|
|
4
|
-
import 'os';
|
|
5
|
-
|
|
6
|
-
const IGNORED_DIRS = /* @__PURE__ */ new Set([
|
|
7
|
-
"__pycache__",
|
|
8
|
-
".git",
|
|
9
|
-
".venv",
|
|
10
|
-
".idea",
|
|
11
|
-
".pytest_cache",
|
|
12
|
-
".mypy_cache",
|
|
13
|
-
"build",
|
|
14
|
-
"dist",
|
|
15
|
-
"__pypackages__",
|
|
16
|
-
"node_modules"
|
|
17
|
-
]);
|
|
18
|
-
const IGNORED_FILES = /* @__PURE__ */ new Set([
|
|
19
|
-
".DS_Store",
|
|
20
|
-
".gitignore",
|
|
21
|
-
".gitattributes",
|
|
22
|
-
".env"
|
|
23
|
-
]);
|
|
24
|
-
const IGNORED_SUFFIXES = [".pyc", ".pyo", ".swp", ".tmp", ".bak"];
|
|
25
|
-
const TEXT_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
26
|
-
".py",
|
|
27
|
-
".js",
|
|
28
|
-
".ts",
|
|
29
|
-
".mjs",
|
|
30
|
-
".cjs",
|
|
31
|
-
".jsx",
|
|
32
|
-
".tsx",
|
|
33
|
-
".html",
|
|
34
|
-
".htm",
|
|
35
|
-
".css",
|
|
36
|
-
".scss",
|
|
37
|
-
".less",
|
|
38
|
-
".json",
|
|
39
|
-
".yaml",
|
|
40
|
-
".yml",
|
|
41
|
-
".toml",
|
|
42
|
-
".ini",
|
|
43
|
-
".cfg",
|
|
44
|
-
".conf",
|
|
45
|
-
".md",
|
|
46
|
-
".txt",
|
|
47
|
-
".rst",
|
|
48
|
-
".csv",
|
|
49
|
-
".tsv",
|
|
50
|
-
".sh",
|
|
51
|
-
".bash",
|
|
52
|
-
".zsh",
|
|
53
|
-
".fish",
|
|
54
|
-
".xml",
|
|
55
|
-
".svg",
|
|
56
|
-
".sql",
|
|
57
|
-
".r",
|
|
58
|
-
".R",
|
|
59
|
-
".jl",
|
|
60
|
-
".c",
|
|
61
|
-
".h",
|
|
62
|
-
".cpp",
|
|
63
|
-
".hpp",
|
|
64
|
-
".java",
|
|
65
|
-
".go",
|
|
66
|
-
".rs",
|
|
67
|
-
".dockerfile",
|
|
68
|
-
".env.example"
|
|
69
|
-
]);
|
|
70
|
-
function isTextFile(name) {
|
|
71
|
-
const ext = extname(name).toLowerCase();
|
|
72
|
-
if (TEXT_EXTENSIONS.has(ext)) return true;
|
|
73
|
-
if (!ext && !name.startsWith(".")) return true;
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
function isIgnored(name, isDir) {
|
|
77
|
-
if (isDir) return IGNORED_DIRS.has(name);
|
|
78
|
-
if (IGNORED_FILES.has(name)) return true;
|
|
79
|
-
return IGNORED_SUFFIXES.some((s) => name.endsWith(s));
|
|
80
|
-
}
|
|
81
|
-
function collectFiles(dir, base = "") {
|
|
82
|
-
const entries = readdirSync(dir, { withFileTypes: true });
|
|
83
|
-
const files = [];
|
|
84
|
-
for (const entry of entries) {
|
|
85
|
-
if (isIgnored(entry.name, entry.isDirectory())) continue;
|
|
86
|
-
const fullPath = join(dir, entry.name);
|
|
87
|
-
const relPath = base ? `${base}/${entry.name}` : entry.name;
|
|
88
|
-
if (entry.isDirectory()) {
|
|
89
|
-
files.push(...collectFiles(fullPath, relPath));
|
|
90
|
-
} else {
|
|
91
|
-
if (isTextFile(entry.name)) {
|
|
92
|
-
files.push({ name: relPath, content: readFileSync(fullPath, "utf-8"), format: "text" });
|
|
93
|
-
} else {
|
|
94
|
-
files.push({ name: relPath, content: readFileSync(fullPath).toString("base64"), format: "base64" });
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return files;
|
|
99
|
-
}
|
|
100
|
-
function parseInstallArgs(args) {
|
|
101
|
-
const source = positionalArgs(args, ["--id", "--manifest", "--files"])[0];
|
|
102
|
-
return {
|
|
103
|
-
source,
|
|
104
|
-
id: getFlag(args, "--id"),
|
|
105
|
-
manifest: getFlag(args, "--manifest"),
|
|
106
|
-
files: getAllFlags(args, "--files"),
|
|
107
|
-
overwrite: hasFlag(args, "--overwrite")
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
function parseStartArgs(args) {
|
|
111
|
-
const pos = positionalArgs(args, ["--timeout"])[0];
|
|
112
|
-
return {
|
|
113
|
-
appId: pos,
|
|
114
|
-
timeout: getFlagInt(args, "--timeout"),
|
|
115
|
-
wait: hasFlag(args, "--wait")
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
function parseStopArgs(args) {
|
|
119
|
-
const pos = positionalArgs(args)[0];
|
|
120
|
-
return {
|
|
121
|
-
id: pos,
|
|
122
|
-
all: hasFlag(args, "--all")
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
function parseLogsArgs(args) {
|
|
126
|
-
const pos = positionalArgs(args, ["--tail", "--type"])[0];
|
|
127
|
-
return {
|
|
128
|
-
instanceId: pos,
|
|
129
|
-
tail: getFlagInt(args, "--tail"),
|
|
130
|
-
type: getFlag(args, "--type")
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
function printAppsHelp() {
|
|
134
|
-
console.log(`hypha apps \u2014 manage server apps
|
|
135
|
-
|
|
136
|
-
Usage: hypha apps <command> [options]
|
|
137
|
-
|
|
138
|
-
Commands:
|
|
139
|
-
list [--json] List installed app definitions (images)
|
|
140
|
-
info <app-id> [--json] Show app details
|
|
141
|
-
install <source> [options] Install an app definition
|
|
142
|
-
uninstall <app-id> Remove an app definition
|
|
143
|
-
start <app-id> [options] Start an app instance
|
|
144
|
-
stop <id> [--all] Stop instance(s)
|
|
145
|
-
ps [--json] List running instances (containers)
|
|
146
|
-
logs <instance-id> [options] View instance logs
|
|
147
|
-
|
|
148
|
-
Aliases: ls \u2192 list, rm \u2192 uninstall
|
|
149
|
-
|
|
150
|
-
Install options:
|
|
151
|
-
--id <app-id> Custom app ID (default: derived from source)
|
|
152
|
-
--manifest <path> Manifest file (JSON/YAML)
|
|
153
|
-
--files <dir> Additional file directory (repeatable)
|
|
154
|
-
--overwrite Overwrite existing app
|
|
155
|
-
|
|
156
|
-
Start options:
|
|
157
|
-
--timeout <seconds> Start timeout (default: 60)
|
|
158
|
-
--wait Wait for service to be ready
|
|
159
|
-
|
|
160
|
-
Logs options:
|
|
161
|
-
--tail <n> Show last N log entries
|
|
162
|
-
--type <stdout|stderr> Filter by log type`);
|
|
163
|
-
}
|
|
164
|
-
async function getServerApps() {
|
|
165
|
-
const server = await connectToHypha();
|
|
166
|
-
const serverApps = await server.getService("public/server-apps");
|
|
167
|
-
return [server, serverApps];
|
|
168
|
-
}
|
|
169
|
-
async function appsList(args) {
|
|
170
|
-
if (hasFlag(args, "--help", "-h")) {
|
|
171
|
-
console.log(`hypha apps list \u2014 list installed app definitions
|
|
172
|
-
|
|
173
|
-
Usage: hypha apps list [--json]
|
|
174
|
-
|
|
175
|
-
Options:
|
|
176
|
-
--json Output as JSON
|
|
177
|
-
|
|
178
|
-
Alias: hypha apps ls`);
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
const json = hasFlag(args, "--json");
|
|
182
|
-
const [server, serverApps] = await getServerApps();
|
|
183
|
-
try {
|
|
184
|
-
const apps = await serverApps.list_apps({ _rkwargs: true });
|
|
185
|
-
if (json) {
|
|
186
|
-
console.log(formatJson(apps));
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
if (!apps || apps.length === 0) {
|
|
190
|
-
console.log("No installed apps.");
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
const rows = [["APP ID", "NAME", "TYPE"]];
|
|
194
|
-
for (const app of apps) {
|
|
195
|
-
const manifest = app.manifest || {};
|
|
196
|
-
rows.push([
|
|
197
|
-
app.id || app.alias || "",
|
|
198
|
-
manifest.name || "",
|
|
199
|
-
manifest.type || app.type || ""
|
|
200
|
-
]);
|
|
201
|
-
}
|
|
202
|
-
console.log(formatTable(rows));
|
|
203
|
-
} finally {
|
|
204
|
-
await server.disconnect();
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
async function appsInfo(args) {
|
|
208
|
-
if (hasFlag(args, "--help", "-h")) {
|
|
209
|
-
console.log(`hypha apps info \u2014 show app details
|
|
210
|
-
|
|
211
|
-
Usage: hypha apps info <app-id> [--json]
|
|
212
|
-
|
|
213
|
-
Options:
|
|
214
|
-
--json Output as JSON`);
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
const pos = positionalArgs(args)[0];
|
|
218
|
-
const json = hasFlag(args, "--json");
|
|
219
|
-
if (!pos) {
|
|
220
|
-
console.error("Usage: hypha apps info <app-id> [--json]");
|
|
221
|
-
process.exit(1);
|
|
222
|
-
}
|
|
223
|
-
const [server, serverApps] = await getServerApps();
|
|
224
|
-
try {
|
|
225
|
-
const info = await serverApps.get_app_info({
|
|
226
|
-
app_id: pos,
|
|
227
|
-
_rkwargs: true
|
|
228
|
-
});
|
|
229
|
-
if (json) {
|
|
230
|
-
console.log(formatJson(info));
|
|
231
|
-
} else {
|
|
232
|
-
const manifest = info.manifest || {};
|
|
233
|
-
console.log(`App ID: ${info.id || info.alias || pos}`);
|
|
234
|
-
console.log(`Name: ${manifest.name || "N/A"}`);
|
|
235
|
-
console.log(`Type: ${manifest.type || info.type || "N/A"}`);
|
|
236
|
-
console.log(`Description: ${manifest.description || "N/A"}`);
|
|
237
|
-
if (info.versions?.length) {
|
|
238
|
-
console.log(`Versions: ${info.versions.map((v) => v.name || v).join(", ")}`);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
} finally {
|
|
242
|
-
await server.disconnect();
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
async function appsInstall(args) {
|
|
246
|
-
if (hasFlag(args, "--help", "-h")) {
|
|
247
|
-
console.log(`hypha apps install \u2014 install an app definition
|
|
248
|
-
|
|
249
|
-
Usage: hypha apps install <source> [options]
|
|
250
|
-
|
|
251
|
-
Arguments:
|
|
252
|
-
<source> URL or local path to app source
|
|
253
|
-
|
|
254
|
-
Options:
|
|
255
|
-
--id <app-id> Custom app ID (default: derived from source)
|
|
256
|
-
--manifest <path> Manifest file (JSON/YAML)
|
|
257
|
-
--files <dir> Additional file directory (repeatable)
|
|
258
|
-
--overwrite Overwrite existing app`);
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
const parsed = parseInstallArgs(args);
|
|
262
|
-
if (!parsed.source) {
|
|
263
|
-
console.error("Usage: hypha apps install <source> [--id <app-id>] [--manifest <path>] [--files <dir>...] [--overwrite]");
|
|
264
|
-
process.exit(1);
|
|
265
|
-
}
|
|
266
|
-
const [server, serverApps] = await getServerApps();
|
|
267
|
-
try {
|
|
268
|
-
const installOpts = {
|
|
269
|
-
_rkwargs: true,
|
|
270
|
-
overwrite: parsed.overwrite
|
|
271
|
-
};
|
|
272
|
-
if (parsed.id) {
|
|
273
|
-
installOpts.app_id = parsed.id;
|
|
274
|
-
}
|
|
275
|
-
if (parsed.source.startsWith("http://") || parsed.source.startsWith("https://")) {
|
|
276
|
-
installOpts.source = parsed.source;
|
|
277
|
-
} else {
|
|
278
|
-
const stat = statSync(parsed.source);
|
|
279
|
-
if (stat.isFile()) {
|
|
280
|
-
installOpts.source = readFileSync(parsed.source, "utf-8");
|
|
281
|
-
} else if (stat.isDirectory()) {
|
|
282
|
-
installOpts.files = collectFiles(parsed.source);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
if (parsed.manifest) {
|
|
286
|
-
const manifestContent = readFileSync(parsed.manifest, "utf-8");
|
|
287
|
-
installOpts.manifest = JSON.parse(manifestContent);
|
|
288
|
-
}
|
|
289
|
-
if (parsed.files.length > 0) {
|
|
290
|
-
const existing = installOpts.files || [];
|
|
291
|
-
for (const fileDir of parsed.files) {
|
|
292
|
-
existing.push(...collectFiles(fileDir));
|
|
293
|
-
}
|
|
294
|
-
installOpts.files = existing;
|
|
295
|
-
}
|
|
296
|
-
const appId = await serverApps.install(installOpts);
|
|
297
|
-
console.log(`Installed: ${appId}`);
|
|
298
|
-
} finally {
|
|
299
|
-
await server.disconnect();
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
async function appsUninstall(args) {
|
|
303
|
-
if (hasFlag(args, "--help", "-h")) {
|
|
304
|
-
console.log(`hypha apps uninstall \u2014 remove an app definition
|
|
305
|
-
|
|
306
|
-
Usage: hypha apps uninstall <app-id>
|
|
307
|
-
|
|
308
|
-
Alias: hypha apps rm`);
|
|
309
|
-
return;
|
|
310
|
-
}
|
|
311
|
-
const appId = positionalArgs(args)[0];
|
|
312
|
-
if (!appId) {
|
|
313
|
-
console.error("Usage: hypha apps uninstall <app-id>");
|
|
314
|
-
process.exit(1);
|
|
315
|
-
}
|
|
316
|
-
const [server, serverApps] = await getServerApps();
|
|
317
|
-
try {
|
|
318
|
-
const artifactManager = await server.getService("artifact-manager");
|
|
319
|
-
await artifactManager.delete({
|
|
320
|
-
artifact_id: appId,
|
|
321
|
-
_rkwargs: true
|
|
322
|
-
});
|
|
323
|
-
console.log(`Uninstalled: ${appId}`);
|
|
324
|
-
} finally {
|
|
325
|
-
await server.disconnect();
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
async function appsStart(args) {
|
|
329
|
-
if (hasFlag(args, "--help", "-h")) {
|
|
330
|
-
console.log(`hypha apps start \u2014 start an app instance
|
|
331
|
-
|
|
332
|
-
Usage: hypha apps start <app-id> [options]
|
|
333
|
-
|
|
334
|
-
Options:
|
|
335
|
-
--timeout <seconds> Start timeout (default: 60)
|
|
336
|
-
--wait Wait for service to be ready`);
|
|
337
|
-
return;
|
|
338
|
-
}
|
|
339
|
-
const parsed = parseStartArgs(args);
|
|
340
|
-
if (!parsed.appId) {
|
|
341
|
-
console.error("Usage: hypha apps start <app-id> [--timeout N] [--wait]");
|
|
342
|
-
process.exit(1);
|
|
343
|
-
}
|
|
344
|
-
const [server, serverApps] = await getServerApps();
|
|
345
|
-
try {
|
|
346
|
-
const startOpts = {
|
|
347
|
-
app_id: parsed.appId,
|
|
348
|
-
_rkwargs: true
|
|
349
|
-
};
|
|
350
|
-
if (parsed.timeout) startOpts.timeout = parsed.timeout;
|
|
351
|
-
if (parsed.wait) startOpts.wait_for_service = "default";
|
|
352
|
-
console.log(`Starting ${parsed.appId}...`);
|
|
353
|
-
const session = await serverApps.start(startOpts);
|
|
354
|
-
console.log(`Instance started:`);
|
|
355
|
-
console.log(` ID: ${session.id}`);
|
|
356
|
-
if (session.app_id) console.log(` App: ${session.app_id}`);
|
|
357
|
-
if (session.workspace) console.log(` WS: ${session.workspace}`);
|
|
358
|
-
} finally {
|
|
359
|
-
await server.disconnect();
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
async function appsStop(args) {
|
|
363
|
-
if (hasFlag(args, "--help", "-h")) {
|
|
364
|
-
console.log(`hypha apps stop \u2014 stop instance(s)
|
|
365
|
-
|
|
366
|
-
Usage: hypha apps stop <id> [--all]
|
|
367
|
-
|
|
368
|
-
Arguments:
|
|
369
|
-
<id> Instance ID to stop, or app ID with --all
|
|
370
|
-
|
|
371
|
-
Options:
|
|
372
|
-
--all Stop all running instances of this app`);
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
const parsed = parseStopArgs(args);
|
|
376
|
-
if (!parsed.id) {
|
|
377
|
-
console.error("Usage: hypha apps stop <id> [--all]");
|
|
378
|
-
console.error(" <id> can be an instance ID or app ID (with --all).");
|
|
379
|
-
process.exit(1);
|
|
380
|
-
}
|
|
381
|
-
const [server, serverApps] = await getServerApps();
|
|
382
|
-
try {
|
|
383
|
-
if (parsed.all) {
|
|
384
|
-
const running = await serverApps.list_running({ _rkwargs: true });
|
|
385
|
-
const matching = running.filter((s) => s.app_id === parsed.id);
|
|
386
|
-
if (matching.length === 0) {
|
|
387
|
-
console.log(`No running instances found for app: ${parsed.id}`);
|
|
388
|
-
return;
|
|
389
|
-
}
|
|
390
|
-
for (const instance of matching) {
|
|
391
|
-
try {
|
|
392
|
-
await serverApps.stop({ session_id: instance.id, _rkwargs: true });
|
|
393
|
-
console.log(`Stopped: ${instance.id}`);
|
|
394
|
-
} catch (err) {
|
|
395
|
-
console.error(`Failed to stop ${instance.id}: ${err.message}`);
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
console.log(`Stopped ${matching.length} instance(s) of ${parsed.id}.`);
|
|
399
|
-
} else {
|
|
400
|
-
await serverApps.stop({ session_id: parsed.id, _rkwargs: true });
|
|
401
|
-
console.log(`Stopped: ${parsed.id}`);
|
|
402
|
-
}
|
|
403
|
-
} finally {
|
|
404
|
-
await server.disconnect();
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
async function appsPs(args) {
|
|
408
|
-
if (hasFlag(args, "--help", "-h")) {
|
|
409
|
-
console.log(`hypha apps ps \u2014 list running instances
|
|
410
|
-
|
|
411
|
-
Usage: hypha apps ps [--json]
|
|
412
|
-
|
|
413
|
-
Shows all currently running app instances (like docker ps).
|
|
414
|
-
|
|
415
|
-
Options:
|
|
416
|
-
--json Output as JSON`);
|
|
417
|
-
return;
|
|
418
|
-
}
|
|
419
|
-
const json = hasFlag(args, "--json");
|
|
420
|
-
const [server, serverApps] = await getServerApps();
|
|
421
|
-
try {
|
|
422
|
-
const running = await serverApps.list_running({ _rkwargs: true });
|
|
423
|
-
if (json) {
|
|
424
|
-
console.log(formatJson(running));
|
|
425
|
-
return;
|
|
426
|
-
}
|
|
427
|
-
if (!running || running.length === 0) {
|
|
428
|
-
console.log("No running instances.");
|
|
429
|
-
return;
|
|
430
|
-
}
|
|
431
|
-
const rows = [["INSTANCE ID", "APP ID", "STATUS", "CREATED"]];
|
|
432
|
-
for (const inst of running) {
|
|
433
|
-
rows.push([
|
|
434
|
-
inst.id || "",
|
|
435
|
-
inst.app_id || "",
|
|
436
|
-
inst.status || "running",
|
|
437
|
-
inst.created_at ? relativeTime(inst.created_at * 1e3) : ""
|
|
438
|
-
]);
|
|
439
|
-
}
|
|
440
|
-
console.log(formatTable(rows));
|
|
441
|
-
} finally {
|
|
442
|
-
await server.disconnect();
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
async function appsLogs(args) {
|
|
446
|
-
if (hasFlag(args, "--help", "-h")) {
|
|
447
|
-
console.log(`hypha apps logs \u2014 view instance logs
|
|
448
|
-
|
|
449
|
-
Usage: hypha apps logs <instance-id> [options]
|
|
450
|
-
|
|
451
|
-
Options:
|
|
452
|
-
--tail <n> Show last N log entries
|
|
453
|
-
--type <stdout|stderr> Filter by log type`);
|
|
454
|
-
return;
|
|
455
|
-
}
|
|
456
|
-
const parsed = parseLogsArgs(args);
|
|
457
|
-
if (!parsed.instanceId) {
|
|
458
|
-
console.error("Usage: hypha apps logs <instance-id> [--tail N] [--type stdout|stderr]");
|
|
459
|
-
process.exit(1);
|
|
460
|
-
}
|
|
461
|
-
const [server, serverApps] = await getServerApps();
|
|
462
|
-
try {
|
|
463
|
-
const logOpts = {
|
|
464
|
-
session_id: parsed.instanceId,
|
|
465
|
-
_rkwargs: true
|
|
466
|
-
};
|
|
467
|
-
if (parsed.type) logOpts.type = parsed.type;
|
|
468
|
-
if (parsed.tail) logOpts.limit = parsed.tail;
|
|
469
|
-
const logs = await serverApps.get_logs(logOpts);
|
|
470
|
-
if (!logs || !logs.items || logs.items.length === 0) {
|
|
471
|
-
console.log("No logs available.");
|
|
472
|
-
return;
|
|
473
|
-
}
|
|
474
|
-
for (const entry of logs.items) {
|
|
475
|
-
const prefix = entry.type === "stderr" ? "[stderr] " : "";
|
|
476
|
-
console.log(`${prefix}${entry.content}`);
|
|
477
|
-
}
|
|
478
|
-
} finally {
|
|
479
|
-
await server.disconnect();
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
async function handleAppsCommand(args) {
|
|
483
|
-
const sub = args[0];
|
|
484
|
-
const commandArgs = args.slice(1);
|
|
485
|
-
if (!sub || sub === "--help" || sub === "-h") {
|
|
486
|
-
printAppsHelp();
|
|
487
|
-
return;
|
|
488
|
-
}
|
|
489
|
-
if (sub === "list" || sub === "ls") {
|
|
490
|
-
await appsList(commandArgs);
|
|
491
|
-
} else if (sub === "info") {
|
|
492
|
-
await appsInfo(commandArgs);
|
|
493
|
-
} else if (sub === "install") {
|
|
494
|
-
await appsInstall(commandArgs);
|
|
495
|
-
} else if (sub === "uninstall" || sub === "rm") {
|
|
496
|
-
await appsUninstall(commandArgs);
|
|
497
|
-
} else if (sub === "start") {
|
|
498
|
-
await appsStart(commandArgs);
|
|
499
|
-
} else if (sub === "stop") {
|
|
500
|
-
await appsStop(commandArgs);
|
|
501
|
-
} else if (sub === "ps") {
|
|
502
|
-
await appsPs(commandArgs);
|
|
503
|
-
} else if (sub === "logs") {
|
|
504
|
-
await appsLogs(commandArgs);
|
|
505
|
-
} else {
|
|
506
|
-
console.error(`Unknown apps command: ${sub}`);
|
|
507
|
-
printAppsHelp();
|
|
508
|
-
process.exit(1);
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
export { handleAppsCommand, parseInstallArgs, parseLogsArgs, parseStartArgs, parseStopArgs };
|