agno-cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/bin/agno.js +3616 -0
  2. package/package.json +42 -0
@@ -0,0 +1,3616 @@
1
+ #!/usr/bin/env node
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __esm = (fn, res) => function __init() {
5
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
6
+ };
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+
12
+ // src/lib/errors.ts
13
+ import {
14
+ APIError,
15
+ AuthenticationError,
16
+ BadRequestError,
17
+ InternalServerError,
18
+ NotFoundError,
19
+ RateLimitError,
20
+ RemoteServerUnavailableError,
21
+ UnprocessableEntityError
22
+ } from "@worksofadam/agentos-sdk";
23
+ import chalk from "chalk";
24
+ function isConnectionError(err) {
25
+ if (!(err instanceof Error)) return false;
26
+ const code = err.code;
27
+ if (code === "ECONNREFUSED" || code === "ECONNRESET" || code === "ENOTFOUND") return true;
28
+ if (err.message.includes("fetch failed")) return true;
29
+ return false;
30
+ }
31
+ function isNetworkAPIError(err) {
32
+ return err instanceof APIError && err.status === 0 && err.message.includes("Network error");
33
+ }
34
+ function formatValidationError(message) {
35
+ try {
36
+ const parsed = JSON.parse(message);
37
+ if (parsed && Array.isArray(parsed.detail)) {
38
+ const lines = parsed.detail.map((d) => {
39
+ const field = d.loc?.slice(1).join(".") ?? "unknown";
40
+ return ` - ${field}: ${d.msg ?? "invalid"}`;
41
+ });
42
+ return `Validation error:
43
+ ${lines.join("\n")}`;
44
+ }
45
+ } catch {
46
+ }
47
+ return `Validation error: ${message}`;
48
+ }
49
+ function writeErr(msg) {
50
+ process.stderr.write(`${chalk.red("Error:")} ${msg}
51
+ `);
52
+ }
53
+ function handleError(err, ctx) {
54
+ if (err instanceof AuthenticationError) {
55
+ writeErr("Authentication failed. Check your API key: agno-cli config show");
56
+ process.exitCode = 1;
57
+ } else if (err instanceof NotFoundError) {
58
+ const what = ctx?.resource ?? "Resource";
59
+ writeErr(`${what} not found.`);
60
+ process.exitCode = 1;
61
+ } else if (err instanceof BadRequestError) {
62
+ writeErr(`Invalid request: ${err.message}`);
63
+ process.exitCode = 1;
64
+ } else if (err instanceof UnprocessableEntityError) {
65
+ writeErr(formatValidationError(err.message));
66
+ process.exitCode = 1;
67
+ } else if (err instanceof RateLimitError) {
68
+ writeErr("Rate limited. Wait and retry.");
69
+ process.exitCode = 2;
70
+ } else if (err instanceof InternalServerError) {
71
+ writeErr(`Server error: ${err.message}
72
+ Run \`agno-cli status\` for diagnostics.`);
73
+ process.exitCode = 2;
74
+ } else if (err instanceof RemoteServerUnavailableError) {
75
+ writeErr("Server unavailable. Is AgentOS running?");
76
+ process.exitCode = 2;
77
+ } else if (isConnectionError(err) || isNetworkAPIError(err)) {
78
+ const target = ctx?.url ? ` to ${ctx.url}` : "";
79
+ writeErr(`Cannot connect${target} -- is the server running?`);
80
+ process.exitCode = 2;
81
+ } else if (err instanceof APIError && err.status === 403) {
82
+ const isAdmin = err.message.toLowerCase().includes("admin");
83
+ if (isAdmin) {
84
+ writeErr("This operation requires admin scope. Check your API key permissions.");
85
+ } else {
86
+ writeErr("Access denied. Check your API key permissions.");
87
+ }
88
+ process.exitCode = 1;
89
+ } else if (err instanceof APIError) {
90
+ writeErr(`API error (${err.status}): ${err.message}`);
91
+ process.exitCode = err.status >= 500 ? 2 : 1;
92
+ } else if (err instanceof ConfigError) {
93
+ writeErr(err.message);
94
+ process.exitCode = 1;
95
+ } else {
96
+ writeErr(err instanceof Error ? err.message : String(err));
97
+ process.exitCode = 2;
98
+ }
99
+ process.exit();
100
+ }
101
+ var ConfigError;
102
+ var init_errors = __esm({
103
+ "src/lib/errors.ts"() {
104
+ "use strict";
105
+ ConfigError = class extends Error {
106
+ constructor(message) {
107
+ super(message);
108
+ this.name = "ConfigError";
109
+ }
110
+ };
111
+ }
112
+ });
113
+
114
+ // src/lib/output.ts
115
+ import chalk2 from "chalk";
116
+ import Table from "cli-table3";
117
+ function getOutputFormat(cmd) {
118
+ const globals = cmd.optsWithGlobals();
119
+ if (globals.json !== void 0) return "json";
120
+ if (globals.output === "json") return "json";
121
+ if (globals.output === "table") return "table";
122
+ return process.stdout.isTTY ? "table" : "json";
123
+ }
124
+ function getJsonFields(cmd) {
125
+ const globals = cmd.optsWithGlobals();
126
+ if (typeof globals.json === "string") return globals.json;
127
+ return void 0;
128
+ }
129
+ function selectFields(data, fields) {
130
+ const fieldList = fields.split(",").map((f) => f.trim());
131
+ if (Array.isArray(data)) {
132
+ return data.map((item) => pickFields(item, fieldList));
133
+ }
134
+ return pickFields(data, fieldList);
135
+ }
136
+ function pickFields(obj, fields) {
137
+ const result = {};
138
+ for (const field of fields) {
139
+ if (field in obj) {
140
+ result[field] = obj[field];
141
+ }
142
+ }
143
+ return result;
144
+ }
145
+ function outputList(cmd, data, opts) {
146
+ const format = getOutputFormat(cmd);
147
+ if (format === "json") {
148
+ const fields = getJsonFields(cmd);
149
+ if (fields) {
150
+ const filtered = selectFields(data, fields);
151
+ process.stdout.write(`${JSON.stringify(filtered, null, 2)}
152
+ `);
153
+ return;
154
+ }
155
+ const envelope = { data };
156
+ if (opts.meta) envelope.meta = opts.meta;
157
+ process.stdout.write(`${JSON.stringify(envelope, null, 2)}
158
+ `);
159
+ return;
160
+ }
161
+ if (data.length === 0) {
162
+ process.stderr.write("No items found.\n");
163
+ return;
164
+ }
165
+ const colWidths = calculateColWidths(opts.columns.length);
166
+ const table = new Table({
167
+ head: opts.columns.map((c) => chalk2.bold(c)),
168
+ style: { head: [], border: [] },
169
+ ...colWidths ? { colWidths } : {}
170
+ });
171
+ for (const row of data) {
172
+ table.push(opts.keys.map((key) => String(row[key] ?? "")));
173
+ }
174
+ process.stdout.write(`${table.toString()}
175
+ `);
176
+ }
177
+ function outputDetail(cmd, data, opts) {
178
+ const format = getOutputFormat(cmd);
179
+ if (format === "json") {
180
+ const fields = getJsonFields(cmd);
181
+ if (fields) {
182
+ const filtered = selectFields(data, fields);
183
+ process.stdout.write(`${JSON.stringify(filtered, null, 2)}
184
+ `);
185
+ return;
186
+ }
187
+ process.stdout.write(`${JSON.stringify(data, null, 2)}
188
+ `);
189
+ return;
190
+ }
191
+ const maxLabelLen = Math.max(...opts.labels.map((l) => l.length));
192
+ const lines = [];
193
+ for (let i = 0; i < opts.labels.length; i++) {
194
+ const label = opts.labels[i];
195
+ const key = opts.keys[i];
196
+ if (label !== void 0 && key !== void 0) {
197
+ const padded = `${label}:`.padEnd(maxLabelLen + 2);
198
+ lines.push(`${chalk2.bold(padded)} ${String(data[key] ?? "")}`);
199
+ }
200
+ }
201
+ process.stdout.write(`${lines.join("\n")}
202
+ `);
203
+ }
204
+ function printJson(data) {
205
+ process.stdout.write(`${JSON.stringify(data, null, 2)}
206
+ `);
207
+ }
208
+ function writeError(msg) {
209
+ process.stderr.write(`${chalk2.red("Error:")} ${msg}
210
+ `);
211
+ }
212
+ function writeSuccess(msg) {
213
+ process.stderr.write(`${chalk2.green("Success:")} ${msg}
214
+ `);
215
+ }
216
+ function writeWarning(msg) {
217
+ process.stderr.write(`${chalk2.yellow("Warning:")} ${msg}
218
+ `);
219
+ }
220
+ function maskKey(key) {
221
+ if (!key) return "(not set)";
222
+ return `${key.slice(0, 3)}...${key.slice(-4)}`;
223
+ }
224
+ function handleNoColorFlag(cmd) {
225
+ const globals = cmd.optsWithGlobals();
226
+ if (globals.color === false) {
227
+ process.env.NO_COLOR = "1";
228
+ }
229
+ }
230
+ function calculateColWidths(numCols) {
231
+ const termWidth = process.stdout.columns;
232
+ if (!termWidth) return void 0;
233
+ const available = termWidth - numCols * 3;
234
+ const colWidth = Math.max(10, Math.floor(available / numCols));
235
+ return Array.from({ length: numCols }, () => colWidth);
236
+ }
237
+ var init_output = __esm({
238
+ "src/lib/output.ts"() {
239
+ "use strict";
240
+ }
241
+ });
242
+
243
+ // src/lib/config.ts
244
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
245
+ import { homedir } from "os";
246
+ import { dirname, join } from "path";
247
+ import { parse, parseDocument } from "yaml";
248
+ function getConfigPath() {
249
+ return _configFile;
250
+ }
251
+ function mapContext(raw) {
252
+ return {
253
+ baseUrl: String(raw.base_url ?? "http://localhost:7777"),
254
+ timeout: Number(raw.timeout ?? 60),
255
+ securityKey: raw.security_key == null ? void 0 : String(raw.security_key)
256
+ };
257
+ }
258
+ function unmapContext(ctx) {
259
+ return {
260
+ base_url: ctx.baseUrl,
261
+ timeout: ctx.timeout,
262
+ security_key: ctx.securityKey ?? null
263
+ };
264
+ }
265
+ function configExists() {
266
+ return existsSync(_configFile);
267
+ }
268
+ function loadConfig() {
269
+ if (!existsSync(_configFile)) {
270
+ return JSON.parse(JSON.stringify(DEFAULT_CONFIG));
271
+ }
272
+ try {
273
+ const raw = readFileSync(_configFile, "utf-8");
274
+ const data = parse(raw);
275
+ if (!data) {
276
+ return JSON.parse(JSON.stringify(DEFAULT_CONFIG));
277
+ }
278
+ const rawContexts = data.contexts ?? {};
279
+ const contexts = {};
280
+ for (const [name, rawCtx] of Object.entries(rawContexts)) {
281
+ contexts[name] = mapContext(rawCtx);
282
+ }
283
+ return {
284
+ current_context: String(data.current_context ?? "default"),
285
+ contexts
286
+ };
287
+ } catch (err) {
288
+ throw new ConfigError(
289
+ `Failed to parse config at ${_configFile}: ${err instanceof Error ? err.message : String(err)}`
290
+ );
291
+ }
292
+ }
293
+ function saveConfig(config) {
294
+ const configDir = dirname(_configFile);
295
+ mkdirSync(configDir, { recursive: true, mode: 448 });
296
+ if (existsSync(_configFile)) {
297
+ const raw = readFileSync(_configFile, "utf-8");
298
+ const doc = parseDocument(raw);
299
+ doc.set("current_context", config.current_context);
300
+ for (const [name, ctx] of Object.entries(config.contexts)) {
301
+ const snake = unmapContext(ctx);
302
+ doc.setIn(["contexts", name, "base_url"], snake.base_url);
303
+ doc.setIn(["contexts", name, "timeout"], snake.timeout);
304
+ doc.setIn(["contexts", name, "security_key"], snake.security_key);
305
+ }
306
+ const existingContexts = doc.getIn(["contexts"]);
307
+ if (existingContexts && typeof existingContexts === "object" && "items" in existingContexts) {
308
+ const yamlMap = existingContexts;
309
+ const toDelete = [];
310
+ for (const item of yamlMap.items) {
311
+ if (item.key?.value && !(item.key.value in config.contexts)) {
312
+ toDelete.push(item.key.value);
313
+ }
314
+ }
315
+ for (const name of toDelete) {
316
+ doc.deleteIn(["contexts", name]);
317
+ }
318
+ }
319
+ writeFileSync(_configFile, doc.toString(), { mode: 384 });
320
+ } else {
321
+ const data = {
322
+ current_context: config.current_context,
323
+ contexts: Object.fromEntries(Object.entries(config.contexts).map(([name, ctx]) => [name, unmapContext(ctx)]))
324
+ };
325
+ const doc = parseDocument(JSON.stringify(data));
326
+ writeFileSync(_configFile, doc.toString(), { mode: 384 });
327
+ }
328
+ }
329
+ function resolveContext(overrides) {
330
+ const config = loadConfig();
331
+ const name = overrides.contextName ?? process.env.AGNO_CONTEXT ?? config.current_context;
332
+ const ctx = config.contexts[name];
333
+ if (!ctx) {
334
+ throw new ConfigError(`Context '${name}' not found. Run 'agno-cli config list' to see available contexts.`);
335
+ }
336
+ return {
337
+ baseUrl: overrides.urlOverride ?? process.env.AGNO_BASE_URL ?? ctx.baseUrl,
338
+ securityKey: overrides.keyOverride ?? process.env.AGNO_SECURITY_KEY ?? ctx.securityKey,
339
+ timeout: overrides.timeoutOverride ?? (process.env.AGNO_TIMEOUT ? Number.parseFloat(process.env.AGNO_TIMEOUT) : void 0) ?? ctx.timeout
340
+ };
341
+ }
342
+ var AGNO_CONFIG_DIR, AGNO_CONFIG_FILE, _configFile, DEFAULT_CONFIG;
343
+ var init_config = __esm({
344
+ "src/lib/config.ts"() {
345
+ "use strict";
346
+ init_errors();
347
+ AGNO_CONFIG_DIR = join(homedir(), ".agno");
348
+ AGNO_CONFIG_FILE = join(AGNO_CONFIG_DIR, "config.yaml");
349
+ _configFile = AGNO_CONFIG_FILE;
350
+ DEFAULT_CONFIG = {
351
+ current_context: "default",
352
+ contexts: {
353
+ default: {
354
+ baseUrl: "http://localhost:7777",
355
+ timeout: 60,
356
+ securityKey: void 0
357
+ }
358
+ }
359
+ };
360
+ }
361
+ });
362
+
363
+ // src/commands/config.ts
364
+ var config_exports = {};
365
+ __export(config_exports, {
366
+ configCommand: () => configCommand
367
+ });
368
+ import { Command } from "commander";
369
+ var configCommand;
370
+ var init_config2 = __esm({
371
+ "src/commands/config.ts"() {
372
+ "use strict";
373
+ init_config();
374
+ init_output();
375
+ configCommand = new Command("config").description("Manage endpoint contexts and configuration");
376
+ configCommand.command("init").description("Initialize configuration with a default context").option("--url <url>", "Base URL for the default context", "http://localhost:7777").option("--key <key>", "Security key for the default context").option("--timeout <seconds>", "Timeout in seconds", Number.parseFloat, 60).option("-f, --force", "Overwrite existing config").action((_options, cmd) => {
377
+ const options = cmd.optsWithGlobals();
378
+ if (configExists() && !options.force) {
379
+ writeError(`Config already exists at ${getConfigPath()}. Use --force to overwrite.`);
380
+ process.exitCode = 1;
381
+ return;
382
+ }
383
+ const config = {
384
+ current_context: "default",
385
+ contexts: {
386
+ default: {
387
+ baseUrl: options.url ?? "http://localhost:7777",
388
+ timeout: options.timeout ?? 60,
389
+ securityKey: options.key
390
+ }
391
+ }
392
+ };
393
+ saveConfig(config);
394
+ writeSuccess(`Config initialized at ${getConfigPath()}`);
395
+ });
396
+ configCommand.command("add").argument("<name>", "Context name").description("Add a new context").option("--url <url>", "Base URL of the AgentOS instance (required)").option("--key <key>", "Security key").option("--timeout <seconds>", "Timeout in seconds", Number.parseFloat, 60).action((name, _options, cmd) => {
397
+ const options = cmd.optsWithGlobals();
398
+ if (!options.url) {
399
+ writeError("Missing required option --url <url>");
400
+ process.exitCode = 1;
401
+ return;
402
+ }
403
+ const config = loadConfig();
404
+ if (config.contexts[name]) {
405
+ writeError(`Context '${name}' already exists. Use 'config set' to modify it.`);
406
+ process.exitCode = 1;
407
+ return;
408
+ }
409
+ config.contexts[name] = {
410
+ baseUrl: options.url,
411
+ timeout: options.timeout ?? 60,
412
+ securityKey: options.key
413
+ };
414
+ saveConfig(config);
415
+ writeSuccess(`Context '${name}' added.`);
416
+ });
417
+ configCommand.command("use").argument("<name>", "Context to activate").description("Switch active context").action((name) => {
418
+ const config = loadConfig();
419
+ if (!config.contexts[name]) {
420
+ writeError(`Context '${name}' not found. Run 'agno-cli config list' to see available contexts.`);
421
+ process.exitCode = 1;
422
+ return;
423
+ }
424
+ config.current_context = name;
425
+ saveConfig(config);
426
+ writeSuccess(`Switched to context '${name}'.`);
427
+ });
428
+ configCommand.command("list").description("List all configured contexts").action((_options, cmd) => {
429
+ const config = loadConfig();
430
+ const format = getOutputFormat(cmd);
431
+ if (format === "json") {
432
+ const data2 = Object.entries(config.contexts).map(([name, ctx]) => ({
433
+ name,
434
+ url: ctx.baseUrl,
435
+ timeout: ctx.timeout,
436
+ active: name === config.current_context
437
+ }));
438
+ process.stdout.write(`${JSON.stringify({ data: data2 }, null, 2)}
439
+ `);
440
+ return;
441
+ }
442
+ const data = Object.entries(config.contexts).map(([name, ctx]) => ({
443
+ name: name === config.current_context ? `* ${name}` : ` ${name}`,
444
+ url: ctx.baseUrl,
445
+ timeout: ctx.timeout
446
+ }));
447
+ outputList(cmd, data, {
448
+ columns: ["CONTEXT", "URL", "TIMEOUT"],
449
+ keys: ["name", "url", "timeout"]
450
+ });
451
+ });
452
+ configCommand.command("show").description("Show active context details").action((_options, cmd) => {
453
+ const config = loadConfig();
454
+ const name = config.current_context;
455
+ const ctx = config.contexts[name];
456
+ if (!ctx) {
457
+ writeError(`Active context '${name}' not found in config.`);
458
+ process.exitCode = 1;
459
+ return;
460
+ }
461
+ outputDetail(
462
+ cmd,
463
+ {
464
+ context: name,
465
+ base_url: ctx.baseUrl,
466
+ timeout: ctx.timeout,
467
+ security_key: maskKey(ctx.securityKey)
468
+ },
469
+ {
470
+ labels: ["Context", "Base URL", "Timeout", "Security Key"],
471
+ keys: ["context", "base_url", "timeout", "security_key"]
472
+ }
473
+ );
474
+ });
475
+ configCommand.command("set").argument("<key>", "Config key (base_url, timeout, security_key)").argument("<value>", "New value").description("Set a config value in active context").action((key, value) => {
476
+ const config = loadConfig();
477
+ const ctx = config.contexts[config.current_context];
478
+ if (!ctx) {
479
+ writeError(`Active context '${config.current_context}' not found.`);
480
+ process.exitCode = 1;
481
+ return;
482
+ }
483
+ switch (key) {
484
+ case "base_url":
485
+ ctx.baseUrl = value;
486
+ break;
487
+ case "timeout":
488
+ ctx.timeout = Number.parseFloat(value);
489
+ break;
490
+ case "security_key":
491
+ ctx.securityKey = value;
492
+ break;
493
+ default:
494
+ writeError(`Unknown config key '${key}'. Valid keys: base_url, timeout, security_key`);
495
+ process.exitCode = 1;
496
+ return;
497
+ }
498
+ saveConfig(config);
499
+ writeSuccess(
500
+ `Set ${key} to ${key === "security_key" ? maskKey(value) : value} in context '${config.current_context}'.`
501
+ );
502
+ });
503
+ configCommand.command("remove").argument("<name>", "Context to remove").description("Remove a context").action((name) => {
504
+ const config = loadConfig();
505
+ if (!config.contexts[name]) {
506
+ writeError(`Context '${name}' not found.`);
507
+ process.exitCode = 1;
508
+ return;
509
+ }
510
+ if (name === config.current_context) {
511
+ writeError(
512
+ `Cannot remove active context '${name}'. Switch to another context first with 'agno-cli config use <name>'.`
513
+ );
514
+ process.exitCode = 1;
515
+ return;
516
+ }
517
+ delete config.contexts[name];
518
+ saveConfig(config);
519
+ writeSuccess(`Context '${name}' removed.`);
520
+ });
521
+ }
522
+ });
523
+
524
+ // src/lib/client.ts
525
+ import { AgentOSClient } from "@worksofadam/agentos-sdk";
526
+ function getClient(cmd) {
527
+ if (_client) return _client;
528
+ const globals = cmd.optsWithGlobals();
529
+ const ctx = resolveContext({
530
+ contextName: globals.context,
531
+ urlOverride: globals.url,
532
+ keyOverride: globals.key,
533
+ timeoutOverride: globals.timeout
534
+ });
535
+ _client = new AgentOSClient({
536
+ baseUrl: ctx.baseUrl,
537
+ apiKey: ctx.securityKey,
538
+ timeout: ctx.timeout * 1e3
539
+ // seconds -> milliseconds
540
+ });
541
+ return _client;
542
+ }
543
+ function getBaseUrl(cmd) {
544
+ const globals = cmd.optsWithGlobals();
545
+ const ctx = resolveContext({
546
+ contextName: globals.context,
547
+ urlOverride: globals.url
548
+ });
549
+ return ctx.baseUrl;
550
+ }
551
+ var _client;
552
+ var init_client = __esm({
553
+ "src/lib/client.ts"() {
554
+ "use strict";
555
+ init_config();
556
+ _client = null;
557
+ }
558
+ });
559
+
560
+ // src/commands/status.ts
561
+ var status_exports = {};
562
+ __export(status_exports, {
563
+ statusCommand: () => statusCommand
564
+ });
565
+ import { Command as Command2 } from "commander";
566
+ var statusCommand;
567
+ var init_status = __esm({
568
+ "src/commands/status.ts"() {
569
+ "use strict";
570
+ init_client();
571
+ init_errors();
572
+ init_output();
573
+ statusCommand = new Command2("status").description("Show AgentOS server status and resource counts").action(async (_options, cmd) => {
574
+ try {
575
+ const client = getClient(cmd);
576
+ const config = await client.getConfig();
577
+ const format = getOutputFormat(cmd);
578
+ if (format === "json") {
579
+ printJson(config);
580
+ return;
581
+ }
582
+ const display = {
583
+ os_id: config.os_id ?? "unknown"
584
+ };
585
+ const labels = ["OS ID"];
586
+ const keys = ["os_id"];
587
+ if (config.name) {
588
+ display.name = config.name;
589
+ labels.push("Name");
590
+ keys.push("name");
591
+ }
592
+ if (config.description) {
593
+ display.description = config.description;
594
+ labels.push("Description");
595
+ keys.push("description");
596
+ }
597
+ display.databases = Array.isArray(config.databases) ? config.databases.length : 0;
598
+ display.agents = Array.isArray(config.agents) ? config.agents.length : 0;
599
+ display.teams = Array.isArray(config.teams) ? config.teams.length : 0;
600
+ display.workflows = Array.isArray(config.workflows) ? config.workflows.length : 0;
601
+ labels.push("Databases", "Agents", "Teams", "Workflows");
602
+ keys.push("databases", "agents", "teams", "workflows");
603
+ outputDetail(cmd, display, { labels, keys });
604
+ } catch (err) {
605
+ handleError(err, { url: getBaseUrl(cmd) });
606
+ }
607
+ });
608
+ }
609
+ });
610
+
611
+ // src/lib/paused-runs.ts
612
+ import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, readdirSync, statSync, unlinkSync, writeFileSync as writeFileSync2 } from "fs";
613
+ import { join as join2 } from "path";
614
+ function writePausedRun(state) {
615
+ mkdirSync2(CACHE_DIR, { recursive: true, mode: 448 });
616
+ writeFileSync2(join2(CACHE_DIR, `${state.run_id}.json`), JSON.stringify(state, null, 2), { mode: 384 });
617
+ }
618
+ function readPausedRun(runId) {
619
+ cleanStalePausedRuns();
620
+ const filePath = join2(CACHE_DIR, `${runId}.json`);
621
+ if (!existsSync2(filePath)) return null;
622
+ return JSON.parse(readFileSync2(filePath, "utf-8"));
623
+ }
624
+ function deletePausedRun(runId) {
625
+ const filePath = join2(CACHE_DIR, `${runId}.json`);
626
+ if (!existsSync2(filePath)) return;
627
+ unlinkSync(filePath);
628
+ }
629
+ function cleanStalePausedRuns() {
630
+ if (!existsSync2(CACHE_DIR)) return;
631
+ const files = readdirSync(CACHE_DIR);
632
+ const now = Date.now();
633
+ for (const file of files) {
634
+ const filePath = join2(CACHE_DIR, file);
635
+ const stat = statSync(filePath);
636
+ if (now - stat.mtimeMs > MAX_AGE_MS) {
637
+ unlinkSync(filePath);
638
+ }
639
+ }
640
+ }
641
+ var CACHE_DIR, MAX_AGE_MS;
642
+ var init_paused_runs = __esm({
643
+ "src/lib/paused-runs.ts"() {
644
+ "use strict";
645
+ init_config();
646
+ CACHE_DIR = join2(AGNO_CONFIG_DIR, "paused-runs");
647
+ MAX_AGE_MS = 24 * 60 * 60 * 1e3;
648
+ }
649
+ });
650
+
651
+ // src/lib/stream.ts
652
+ import chalk3 from "chalk";
653
+ function formatContent(content) {
654
+ if (content == null) return "";
655
+ return typeof content === "string" ? content : JSON.stringify(content, null, 2);
656
+ }
657
+ function displayPausedToolInfo(tools, resourceId, runId) {
658
+ process.stderr.write(`
659
+ ${chalk3.yellow.bold("[Run Paused -- Tool requires confirmation]")}
660
+
661
+ `);
662
+ for (const tool of tools) {
663
+ process.stderr.write(` Tool: ${chalk3.cyan(String(tool.tool_name ?? "unknown"))}
664
+ `);
665
+ process.stderr.write(` Args: ${JSON.stringify(tool.tool_args ?? {})}
666
+ `);
667
+ process.stderr.write(` ID: ${String(tool.tool_call_id ?? "unknown")}
668
+
669
+ `);
670
+ }
671
+ process.stderr.write(
672
+ `To confirm: ${chalk3.green(`agno-cli agent continue ${resourceId} ${runId} --confirm --stream`)}
673
+ `
674
+ );
675
+ process.stderr.write(
676
+ `To reject: ${chalk3.red(`agno-cli agent continue ${resourceId} ${runId} --reject --stream`)}
677
+ `
678
+ );
679
+ }
680
+ async function handleStreamRun(cmd, stream, resourceType, options) {
681
+ const format = getOutputFormat(cmd);
682
+ const contentEvent = CONTENT_EVENTS[resourceType];
683
+ const completedEvent = COMPLETED_EVENTS[resourceType];
684
+ const errorEvent = ERROR_EVENTS[resourceType];
685
+ const pausedEvent = PAUSED_EVENTS[resourceType];
686
+ const startedEvent = STARTED_EVENTS[resourceType];
687
+ const onSigint = () => {
688
+ stream.abort();
689
+ };
690
+ process.on("SIGINT", onSigint);
691
+ try {
692
+ if (format === "json") {
693
+ const events = [];
694
+ let jsonSessionId = null;
695
+ for await (const event of stream) {
696
+ events.push(event);
697
+ if (startedEvent && event.event === startedEvent) {
698
+ jsonSessionId = event.session_id ?? null;
699
+ }
700
+ if (pausedEvent && event.event === pausedEvent && options?.resourceId) {
701
+ const tools = event.tools;
702
+ const eventRunId = event.run_id;
703
+ if (tools && tools.length > 0) {
704
+ writePausedRun({
705
+ agent_id: options.resourceId,
706
+ run_id: eventRunId ?? "unknown",
707
+ session_id: jsonSessionId,
708
+ resource_type: resourceType,
709
+ paused_at: (/* @__PURE__ */ new Date()).toISOString(),
710
+ tools
711
+ });
712
+ }
713
+ }
714
+ }
715
+ process.stdout.write(`${JSON.stringify(events, null, 2)}
716
+ `);
717
+ } else {
718
+ let metrics;
719
+ let sessionId = null;
720
+ let runId = null;
721
+ for await (const event of stream) {
722
+ if (event.event === errorEvent) {
723
+ const errorMsg = event.error ?? event.content ?? "Unknown stream error";
724
+ writeError(String(errorMsg));
725
+ process.exitCode = 2;
726
+ } else if (event.event === contentEvent) {
727
+ const content = event.content;
728
+ if (content != null) {
729
+ process.stdout.write(formatContent(content));
730
+ }
731
+ } else if (event.event === completedEvent) {
732
+ metrics = event.metrics;
733
+ } else if (event.event === startedEvent) {
734
+ sessionId = event.session_id ?? null;
735
+ runId = event.run_id ?? null;
736
+ } else if (pausedEvent && event.event === pausedEvent) {
737
+ const tools = event.tools;
738
+ const eventRunId = event.run_id ?? runId;
739
+ if (tools && tools.length > 0 && options?.resourceId) {
740
+ writePausedRun({
741
+ agent_id: options.resourceId,
742
+ run_id: eventRunId ?? "unknown",
743
+ session_id: sessionId,
744
+ resource_type: resourceType,
745
+ paused_at: (/* @__PURE__ */ new Date()).toISOString(),
746
+ tools
747
+ });
748
+ displayPausedToolInfo(tools, options.resourceId, eventRunId ?? "unknown");
749
+ }
750
+ }
751
+ }
752
+ process.stdout.write("\n");
753
+ if (metrics) {
754
+ printMetrics(metrics);
755
+ }
756
+ }
757
+ } finally {
758
+ process.removeListener("SIGINT", onSigint);
759
+ }
760
+ }
761
+ async function handleNonStreamRun(cmd, runFn, options) {
762
+ const format = getOutputFormat(cmd);
763
+ const ora = (await import("ora")).default;
764
+ const spinner = ora({ text: "Running...", stream: process.stderr }).start();
765
+ try {
766
+ const result = await runFn();
767
+ spinner.stop();
768
+ const resultObj = result;
769
+ const statusStr = typeof resultObj?.status === "string" ? resultObj.status.toLowerCase() : "";
770
+ const isPaused = resultObj?.is_paused === true || statusStr === "paused";
771
+ const tools = resultObj?.tools;
772
+ if (isPaused && tools && tools.length > 0 && options?.resourceId && options?.resourceType === "agent") {
773
+ const pausedRunId = resultObj?.run_id ?? "unknown";
774
+ const pausedSessionId = resultObj?.session_id ?? null;
775
+ writePausedRun({
776
+ agent_id: options.resourceId,
777
+ run_id: pausedRunId,
778
+ session_id: pausedSessionId,
779
+ resource_type: options.resourceType,
780
+ paused_at: (/* @__PURE__ */ new Date()).toISOString(),
781
+ tools
782
+ });
783
+ if (format !== "json") {
784
+ displayPausedToolInfo(tools, options.resourceId, pausedRunId);
785
+ }
786
+ }
787
+ if (format === "json") {
788
+ process.stdout.write(`${JSON.stringify(result, null, 2)}
789
+ `);
790
+ } else {
791
+ const content = result?.content;
792
+ if (content != null) {
793
+ process.stdout.write(`${formatContent(content)}
794
+ `);
795
+ }
796
+ const metrics = result?.metrics;
797
+ if (metrics) {
798
+ printMetrics(metrics);
799
+ }
800
+ }
801
+ } catch (err) {
802
+ spinner.stop();
803
+ throw err;
804
+ }
805
+ }
806
+ function printMetrics(metrics) {
807
+ if (!metrics) return;
808
+ const parts = [];
809
+ const inputTokens = metrics.input_tokens;
810
+ const outputTokens = metrics.output_tokens;
811
+ const totalTokens = metrics.total_tokens;
812
+ const duration = metrics.duration;
813
+ if (inputTokens && outputTokens) {
814
+ parts.push(`tokens: ${inputTokens}/${outputTokens}`);
815
+ } else if (totalTokens) {
816
+ parts.push(`tokens: ${totalTokens}`);
817
+ }
818
+ if (duration) {
819
+ parts.push(`time: ${duration.toFixed(2)}s`);
820
+ }
821
+ if (parts.length > 0) {
822
+ process.stderr.write(`${chalk3.dim(`[${parts.join(", ")}]`)}
823
+ `);
824
+ }
825
+ }
826
+ var CONTENT_EVENTS, COMPLETED_EVENTS, ERROR_EVENTS, PAUSED_EVENTS, STARTED_EVENTS;
827
+ var init_stream = __esm({
828
+ "src/lib/stream.ts"() {
829
+ "use strict";
830
+ init_output();
831
+ init_paused_runs();
832
+ CONTENT_EVENTS = {
833
+ agent: "RunContent",
834
+ team: "TeamRunContent",
835
+ workflow: "StepOutput"
836
+ };
837
+ COMPLETED_EVENTS = {
838
+ agent: "RunCompleted",
839
+ team: "TeamRunCompleted",
840
+ workflow: "WorkflowCompleted"
841
+ };
842
+ ERROR_EVENTS = {
843
+ agent: "RunError",
844
+ team: "TeamRunError",
845
+ workflow: "WorkflowCancelled"
846
+ };
847
+ PAUSED_EVENTS = {
848
+ agent: "RunPaused"
849
+ };
850
+ STARTED_EVENTS = {
851
+ agent: "RunStarted",
852
+ team: "TeamRunStarted",
853
+ workflow: "WorkflowStarted"
854
+ };
855
+ }
856
+ });
857
+
858
+ // src/commands/agents.ts
859
+ var agents_exports = {};
860
+ __export(agents_exports, {
861
+ agentCommand: () => agentCommand
862
+ });
863
+ import { Command as Command3 } from "commander";
864
+ function buildConfirmPayload(tools) {
865
+ const confirmed = tools.map((tool) => ({
866
+ ...tool,
867
+ confirmed: true
868
+ }));
869
+ return JSON.stringify(confirmed);
870
+ }
871
+ function buildRejectPayload(tools, note) {
872
+ const rejected = tools.map((tool) => ({
873
+ ...tool,
874
+ confirmed: false,
875
+ confirmation_note: note ?? "Rejected via CLI"
876
+ }));
877
+ return JSON.stringify(rejected);
878
+ }
879
+ var agentCommand;
880
+ var init_agents = __esm({
881
+ "src/commands/agents.ts"() {
882
+ "use strict";
883
+ init_client();
884
+ init_errors();
885
+ init_output();
886
+ init_paused_runs();
887
+ init_stream();
888
+ agentCommand = new Command3("agent").description("Manage agents");
889
+ agentCommand.command("list").description("List all agents").option("--limit <n>", "Results per page", (v) => Number.parseInt(v, 10), 20).option("--page <n>", "Page number", (v) => Number.parseInt(v, 10), 1).action(async (_options, cmd) => {
890
+ try {
891
+ const opts = cmd.optsWithGlobals();
892
+ const client = getClient(cmd);
893
+ const agents = await client.agents.list();
894
+ const limit = opts.limit;
895
+ const page = opts.page;
896
+ const start = (page - 1) * limit;
897
+ const paged = agents.slice(start, start + limit);
898
+ const meta = {
899
+ page,
900
+ limit,
901
+ total_pages: Math.ceil(agents.length / limit),
902
+ total_count: agents.length
903
+ };
904
+ outputList(
905
+ cmd,
906
+ paged.map((a) => ({
907
+ id: a.id ?? "",
908
+ name: a.name ?? "",
909
+ description: a.description ?? ""
910
+ })),
911
+ {
912
+ columns: ["ID", "NAME", "DESCRIPTION"],
913
+ keys: ["id", "name", "description"],
914
+ meta
915
+ }
916
+ );
917
+ } catch (err) {
918
+ handleError(err, { url: getBaseUrl(cmd) });
919
+ }
920
+ });
921
+ agentCommand.command("get").argument("<agent_id>", "Agent ID").description("Get agent details").action(async (agentId, _options, cmd) => {
922
+ try {
923
+ const client = getClient(cmd);
924
+ const agent = await client.agents.get(agentId);
925
+ const format = getOutputFormat(cmd);
926
+ if (format === "json") {
927
+ outputDetail(cmd, agent, { labels: [], keys: [] });
928
+ return;
929
+ }
930
+ const modelDisplay = agent.model?.model ?? agent.model?.name ?? "N/A";
931
+ outputDetail(
932
+ cmd,
933
+ {
934
+ id: agent.id ?? "",
935
+ name: agent.name ?? "",
936
+ description: agent.description ?? "",
937
+ model: modelDisplay
938
+ },
939
+ {
940
+ labels: ["ID", "Name", "Description", "Model"],
941
+ keys: ["id", "name", "description", "model"]
942
+ }
943
+ );
944
+ } catch (err) {
945
+ handleError(err, { resource: "Agent", url: getBaseUrl(cmd) });
946
+ }
947
+ });
948
+ agentCommand.command("run").argument("<agent_id>", "Agent ID").argument("<message>", "Message to send to the agent").description("Run an agent with a message").option("-s, --stream", "Stream the response via SSE").option("--session-id <id>", "Session ID for conversation context").option("--user-id <id>", "User ID for personalization").action(async (agentId, message, options, cmd) => {
949
+ try {
950
+ const client = getClient(cmd);
951
+ if (options.stream) {
952
+ const stream = await client.agents.runStream(agentId, {
953
+ message,
954
+ sessionId: options.sessionId,
955
+ userId: options.userId
956
+ });
957
+ await handleStreamRun(cmd, stream, "agent", { resourceId: agentId });
958
+ } else {
959
+ await handleNonStreamRun(
960
+ cmd,
961
+ () => client.agents.run(agentId, {
962
+ message,
963
+ sessionId: options.sessionId,
964
+ userId: options.userId
965
+ }),
966
+ { resourceType: "agent", resourceId: agentId }
967
+ );
968
+ }
969
+ } catch (err) {
970
+ handleError(err, { resource: "Agent", url: getBaseUrl(cmd) });
971
+ }
972
+ });
973
+ agentCommand.command("continue").argument("<agent_id>", "Agent ID").argument("<run_id>", "Run ID to continue").argument("[tool_results]", "Tool results JSON (optional when using --confirm or --reject)").description("Continue an agent run").option("-s, --stream", "Stream the response via SSE").option("--confirm", "Confirm the paused tool call (auto-reconstruct payload from cache)").option("--reject [note]", "Reject the paused tool call with optional note").option("--session-id <id>", "Session ID").option("--user-id <id>", "User ID").action(async (agentId, runId, toolResults, options, cmd) => {
974
+ try {
975
+ const client = getClient(cmd);
976
+ let tools;
977
+ let sessionId = options.sessionId;
978
+ if (options.confirm) {
979
+ const cached = readPausedRun(runId);
980
+ if (!cached) {
981
+ writeError(`No cached paused state for run ${runId}. Provide tool results JSON directly or re-run the agent with --stream to capture the paused state.`);
982
+ process.exitCode = 1;
983
+ return;
984
+ }
985
+ tools = buildConfirmPayload(cached.tools);
986
+ if (!sessionId && cached.session_id) {
987
+ sessionId = cached.session_id;
988
+ }
989
+ } else if (options.reject !== void 0) {
990
+ const cached = readPausedRun(runId);
991
+ if (!cached) {
992
+ writeError(`No cached paused state for run ${runId}. Provide tool results JSON directly or re-run the agent with --stream to capture the paused state.`);
993
+ process.exitCode = 1;
994
+ return;
995
+ }
996
+ const note = typeof options.reject === "string" ? options.reject : void 0;
997
+ tools = buildRejectPayload(cached.tools, note);
998
+ if (!sessionId && cached.session_id) {
999
+ sessionId = cached.session_id;
1000
+ }
1001
+ } else if (toolResults) {
1002
+ tools = toolResults;
1003
+ } else {
1004
+ writeError("Provide tool results JSON, or use --confirm/--reject for a paused tool call.");
1005
+ process.exitCode = 1;
1006
+ return;
1007
+ }
1008
+ if (options.stream) {
1009
+ const stream = await client.agents.continue(agentId, runId, {
1010
+ tools,
1011
+ sessionId,
1012
+ userId: options.userId,
1013
+ stream: true
1014
+ });
1015
+ await handleStreamRun(cmd, stream, "agent", { resourceId: agentId });
1016
+ } else {
1017
+ const result = await client.agents.continue(agentId, runId, {
1018
+ tools,
1019
+ sessionId,
1020
+ userId: options.userId,
1021
+ stream: false
1022
+ });
1023
+ const format = getOutputFormat(cmd);
1024
+ if (format === "json") {
1025
+ process.stdout.write(`${JSON.stringify(result, null, 2)}
1026
+ `);
1027
+ } else {
1028
+ const content = result.content;
1029
+ if (content) {
1030
+ process.stdout.write(`${typeof content === "string" ? content : JSON.stringify(content, null, 2)}
1031
+ `);
1032
+ }
1033
+ }
1034
+ }
1035
+ if (options.confirm || options.reject !== void 0) {
1036
+ deletePausedRun(runId);
1037
+ }
1038
+ } catch (err) {
1039
+ handleError(err, { resource: "Agent", url: getBaseUrl(cmd) });
1040
+ }
1041
+ });
1042
+ agentCommand.command("cancel").argument("<agent_id>", "Agent ID").argument("<run_id>", "Run ID to cancel").description("Cancel an in-progress agent run").action(async (agentId, runId, _options, cmd) => {
1043
+ try {
1044
+ const client = getClient(cmd);
1045
+ await client.agents.cancel(agentId, runId);
1046
+ writeSuccess(`Cancelled run ${runId} for agent ${agentId}`);
1047
+ } catch (err) {
1048
+ handleError(err, { resource: "Agent", url: getBaseUrl(cmd) });
1049
+ }
1050
+ });
1051
+ }
1052
+ });
1053
+
1054
+ // src/commands/teams.ts
1055
+ var teams_exports = {};
1056
+ __export(teams_exports, {
1057
+ teamCommand: () => teamCommand
1058
+ });
1059
+ import { Command as Command4 } from "commander";
1060
+ var teamCommand;
1061
+ var init_teams = __esm({
1062
+ "src/commands/teams.ts"() {
1063
+ "use strict";
1064
+ init_client();
1065
+ init_errors();
1066
+ init_output();
1067
+ init_stream();
1068
+ teamCommand = new Command4("team").description("Manage teams");
1069
+ teamCommand.command("list").description("List all teams").option("--limit <n>", "Results per page", (v) => Number.parseInt(v, 10), 20).option("--page <n>", "Page number", (v) => Number.parseInt(v, 10), 1).action(async (_options, cmd) => {
1070
+ try {
1071
+ const opts = cmd.optsWithGlobals();
1072
+ const client = getClient(cmd);
1073
+ const teams = await client.teams.list();
1074
+ const limit = opts.limit;
1075
+ const page = opts.page;
1076
+ const start = (page - 1) * limit;
1077
+ const paged = teams.slice(start, start + limit);
1078
+ const meta = {
1079
+ page,
1080
+ limit,
1081
+ total_pages: Math.ceil(teams.length / limit),
1082
+ total_count: teams.length
1083
+ };
1084
+ outputList(
1085
+ cmd,
1086
+ paged.map((t) => ({
1087
+ id: t.id ?? "",
1088
+ name: t.name ?? "",
1089
+ mode: t.mode ?? "",
1090
+ description: t.description ?? ""
1091
+ })),
1092
+ {
1093
+ columns: ["ID", "NAME", "MODE", "DESCRIPTION"],
1094
+ keys: ["id", "name", "mode", "description"],
1095
+ meta
1096
+ }
1097
+ );
1098
+ } catch (err) {
1099
+ handleError(err, { url: getBaseUrl(cmd) });
1100
+ }
1101
+ });
1102
+ teamCommand.command("get").argument("<team_id>", "Team ID").description("Get team details").action(async (teamId, _options, cmd) => {
1103
+ try {
1104
+ const client = getClient(cmd);
1105
+ const team = await client.teams.get(teamId);
1106
+ const format = getOutputFormat(cmd);
1107
+ if (format === "json") {
1108
+ outputDetail(cmd, team, { labels: [], keys: [] });
1109
+ return;
1110
+ }
1111
+ const modelDisplay = team.model?.model ?? team.model?.name ?? "N/A";
1112
+ outputDetail(
1113
+ cmd,
1114
+ {
1115
+ id: team.id ?? "",
1116
+ name: team.name ?? "",
1117
+ mode: team.mode ?? "",
1118
+ description: team.description ?? "",
1119
+ model: modelDisplay
1120
+ },
1121
+ {
1122
+ labels: ["ID", "Name", "Mode", "Description", "Model"],
1123
+ keys: ["id", "name", "mode", "description", "model"]
1124
+ }
1125
+ );
1126
+ } catch (err) {
1127
+ handleError(err, { resource: "Team", url: getBaseUrl(cmd) });
1128
+ }
1129
+ });
1130
+ teamCommand.command("run").argument("<team_id>", "Team ID").argument("<message>", "Message to send to the team").description("Run a team with a message").option("-s, --stream", "Stream the response via SSE").option("--session-id <id>", "Session ID for conversation context").option("--user-id <id>", "User ID for personalization").action(async (teamId, message, options, cmd) => {
1131
+ try {
1132
+ const client = getClient(cmd);
1133
+ if (options.stream) {
1134
+ const stream = await client.teams.runStream(teamId, {
1135
+ message,
1136
+ sessionId: options.sessionId,
1137
+ userId: options.userId
1138
+ });
1139
+ await handleStreamRun(cmd, stream, "team", { resourceId: teamId });
1140
+ } else {
1141
+ await handleNonStreamRun(
1142
+ cmd,
1143
+ () => client.teams.run(teamId, {
1144
+ message,
1145
+ sessionId: options.sessionId,
1146
+ userId: options.userId
1147
+ }),
1148
+ { resourceType: "team", resourceId: teamId }
1149
+ );
1150
+ }
1151
+ } catch (err) {
1152
+ handleError(err, { resource: "Team", url: getBaseUrl(cmd) });
1153
+ }
1154
+ });
1155
+ teamCommand.command("continue").argument("<team_id>", "Team ID").argument("<run_id>", "Run ID to continue").argument("<message>", "Message to continue with").description("Continue a team run").option("-s, --stream", "Stream the response via SSE").option("--session-id <id>", "Session ID").option("--user-id <id>", "User ID").action(async (teamId, runId, message, options, cmd) => {
1156
+ try {
1157
+ const client = getClient(cmd);
1158
+ if (options.stream) {
1159
+ const stream = await client.teams.continue(teamId, runId, {
1160
+ tools: message,
1161
+ sessionId: options.sessionId,
1162
+ userId: options.userId,
1163
+ stream: true
1164
+ });
1165
+ await handleStreamRun(cmd, stream, "team", { resourceId: teamId });
1166
+ } else {
1167
+ const result = await client.teams.continue(teamId, runId, {
1168
+ tools: message,
1169
+ sessionId: options.sessionId,
1170
+ userId: options.userId,
1171
+ stream: false
1172
+ });
1173
+ const format = getOutputFormat(cmd);
1174
+ if (format === "json") {
1175
+ process.stdout.write(`${JSON.stringify(result, null, 2)}
1176
+ `);
1177
+ } else {
1178
+ const content = result.content;
1179
+ if (content) {
1180
+ process.stdout.write(`${typeof content === "string" ? content : JSON.stringify(content, null, 2)}
1181
+ `);
1182
+ }
1183
+ }
1184
+ }
1185
+ } catch (err) {
1186
+ handleError(err, { resource: "Team", url: getBaseUrl(cmd) });
1187
+ }
1188
+ });
1189
+ teamCommand.command("cancel").argument("<team_id>", "Team ID").argument("<run_id>", "Run ID to cancel").description("Cancel an in-progress team run").action(async (teamId, runId, _options, cmd) => {
1190
+ try {
1191
+ const client = getClient(cmd);
1192
+ await client.teams.cancel(teamId, runId);
1193
+ writeSuccess(`Cancelled run ${runId} for team ${teamId}`);
1194
+ } catch (err) {
1195
+ handleError(err, { resource: "Team", url: getBaseUrl(cmd) });
1196
+ }
1197
+ });
1198
+ }
1199
+ });
1200
+
1201
+ // src/commands/workflows.ts
1202
+ var workflows_exports = {};
1203
+ __export(workflows_exports, {
1204
+ workflowCommand: () => workflowCommand
1205
+ });
1206
+ import { Command as Command5 } from "commander";
1207
+ var workflowCommand;
1208
+ var init_workflows = __esm({
1209
+ "src/commands/workflows.ts"() {
1210
+ "use strict";
1211
+ init_client();
1212
+ init_errors();
1213
+ init_output();
1214
+ init_stream();
1215
+ workflowCommand = new Command5("workflow").description("Manage workflows");
1216
+ workflowCommand.command("list").description("List all workflows").option("--limit <n>", "Results per page", (v) => Number.parseInt(v, 10), 20).option("--page <n>", "Page number", (v) => Number.parseInt(v, 10), 1).action(async (_options, cmd) => {
1217
+ try {
1218
+ const opts = cmd.optsWithGlobals();
1219
+ const client = getClient(cmd);
1220
+ const workflows = await client.workflows.list();
1221
+ const limit = opts.limit;
1222
+ const page = opts.page;
1223
+ const start = (page - 1) * limit;
1224
+ const paged = workflows.slice(start, start + limit);
1225
+ const meta = {
1226
+ page,
1227
+ limit,
1228
+ total_pages: Math.ceil(workflows.length / limit),
1229
+ total_count: workflows.length
1230
+ };
1231
+ outputList(
1232
+ cmd,
1233
+ paged.map((w) => ({
1234
+ id: w.id ?? "",
1235
+ name: w.name ?? "",
1236
+ description: w.description ?? ""
1237
+ })),
1238
+ {
1239
+ columns: ["ID", "NAME", "DESCRIPTION"],
1240
+ keys: ["id", "name", "description"],
1241
+ meta
1242
+ }
1243
+ );
1244
+ } catch (err) {
1245
+ handleError(err, { url: getBaseUrl(cmd) });
1246
+ }
1247
+ });
1248
+ workflowCommand.command("get").argument("<workflow_id>", "Workflow ID").description("Get workflow details").action(async (workflowId, _options, cmd) => {
1249
+ try {
1250
+ const client = getClient(cmd);
1251
+ const workflow = await client.workflows.get(workflowId);
1252
+ const format = getOutputFormat(cmd);
1253
+ if (format === "json") {
1254
+ outputDetail(cmd, workflow, { labels: [], keys: [] });
1255
+ return;
1256
+ }
1257
+ outputDetail(
1258
+ cmd,
1259
+ {
1260
+ id: workflow.id ?? "",
1261
+ name: workflow.name ?? "",
1262
+ description: workflow.description ?? "",
1263
+ steps: Array.isArray(workflow.steps) ? workflow.steps.length : 0,
1264
+ workflow_agent: workflow.workflow_agent ? "Yes" : "No"
1265
+ },
1266
+ {
1267
+ labels: ["ID", "Name", "Description", "Steps", "Workflow Agent"],
1268
+ keys: ["id", "name", "description", "steps", "workflow_agent"]
1269
+ }
1270
+ );
1271
+ } catch (err) {
1272
+ handleError(err, { resource: "Workflow", url: getBaseUrl(cmd) });
1273
+ }
1274
+ });
1275
+ workflowCommand.command("run").argument("<workflow_id>", "Workflow ID").argument("<message>", "Message to send to the workflow").description("Run a workflow with a message").option("-s, --stream", "Stream the response via SSE").option("--session-id <id>", "Session ID for conversation context").option("--user-id <id>", "User ID for personalization").action(async (workflowId, message, options, cmd) => {
1276
+ try {
1277
+ const client = getClient(cmd);
1278
+ if (options.stream) {
1279
+ const stream = await client.workflows.runStream(workflowId, {
1280
+ message,
1281
+ sessionId: options.sessionId,
1282
+ userId: options.userId
1283
+ });
1284
+ await handleStreamRun(cmd, stream, "workflow", { resourceId: workflowId });
1285
+ } else {
1286
+ await handleNonStreamRun(
1287
+ cmd,
1288
+ () => client.workflows.run(workflowId, {
1289
+ message,
1290
+ sessionId: options.sessionId,
1291
+ userId: options.userId
1292
+ }),
1293
+ { resourceType: "workflow", resourceId: workflowId }
1294
+ );
1295
+ }
1296
+ } catch (err) {
1297
+ handleError(err, { resource: "Workflow", url: getBaseUrl(cmd) });
1298
+ }
1299
+ });
1300
+ workflowCommand.command("continue").argument("<workflow_id>", "Workflow ID").argument("<run_id>", "Run ID to continue").argument("<message>", "Message to continue with").description("Continue a workflow run").option("-s, --stream", "Stream the response via SSE").option("--session-id <id>", "Session ID").option("--user-id <id>", "User ID").action(async (workflowId, runId, message, options, cmd) => {
1301
+ try {
1302
+ const client = getClient(cmd);
1303
+ if (options.stream) {
1304
+ const stream = await client.workflows.continue(workflowId, runId, {
1305
+ tools: message,
1306
+ sessionId: options.sessionId,
1307
+ userId: options.userId,
1308
+ stream: true
1309
+ });
1310
+ await handleStreamRun(cmd, stream, "workflow", { resourceId: workflowId });
1311
+ } else {
1312
+ const result = await client.workflows.continue(workflowId, runId, {
1313
+ tools: message,
1314
+ sessionId: options.sessionId,
1315
+ userId: options.userId,
1316
+ stream: false
1317
+ });
1318
+ const format = getOutputFormat(cmd);
1319
+ if (format === "json") {
1320
+ process.stdout.write(`${JSON.stringify(result, null, 2)}
1321
+ `);
1322
+ } else {
1323
+ const content = result.content;
1324
+ if (content) {
1325
+ process.stdout.write(`${typeof content === "string" ? content : JSON.stringify(content, null, 2)}
1326
+ `);
1327
+ }
1328
+ }
1329
+ }
1330
+ } catch (err) {
1331
+ handleError(err, { resource: "Workflow", url: getBaseUrl(cmd) });
1332
+ }
1333
+ });
1334
+ workflowCommand.command("cancel").argument("<workflow_id>", "Workflow ID").argument("<run_id>", "Run ID to cancel").description("Cancel an in-progress workflow run").action(async (workflowId, runId, _options, cmd) => {
1335
+ try {
1336
+ const client = getClient(cmd);
1337
+ await client.workflows.cancel(workflowId, runId);
1338
+ writeSuccess(`Cancelled run ${runId} for workflow ${workflowId}`);
1339
+ } catch (err) {
1340
+ handleError(err, { resource: "Workflow", url: getBaseUrl(cmd) });
1341
+ }
1342
+ });
1343
+ }
1344
+ });
1345
+
1346
+ // src/commands/models.ts
1347
+ var models_exports = {};
1348
+ __export(models_exports, {
1349
+ modelCommand: () => modelCommand
1350
+ });
1351
+ import { Command as Command6 } from "commander";
1352
+ var modelCommand;
1353
+ var init_models = __esm({
1354
+ "src/commands/models.ts"() {
1355
+ "use strict";
1356
+ init_client();
1357
+ init_errors();
1358
+ init_output();
1359
+ modelCommand = new Command6("models").description("List available models");
1360
+ modelCommand.command("list").description("List all available models").option("--limit <n>", "Results per page", (v) => Number.parseInt(v, 10), 20).option("--page <n>", "Page number", (v) => Number.parseInt(v, 10), 1).action(async (_options, cmd) => {
1361
+ try {
1362
+ const opts = cmd.optsWithGlobals();
1363
+ const client = getClient(cmd);
1364
+ const models = await client.models.list();
1365
+ const limit = opts.limit;
1366
+ const page = opts.page;
1367
+ const start = (page - 1) * limit;
1368
+ const paged = models.slice(start, start + limit);
1369
+ const meta = {
1370
+ page,
1371
+ limit,
1372
+ total_pages: Math.ceil(models.length / limit),
1373
+ total_count: models.length
1374
+ };
1375
+ outputList(
1376
+ cmd,
1377
+ paged.map((m) => ({
1378
+ id: m.id ?? "",
1379
+ provider: m.provider ?? ""
1380
+ })),
1381
+ {
1382
+ columns: ["ID", "PROVIDER"],
1383
+ keys: ["id", "provider"],
1384
+ meta
1385
+ }
1386
+ );
1387
+ } catch (err) {
1388
+ handleError(err, { url: getBaseUrl(cmd) });
1389
+ }
1390
+ });
1391
+ }
1392
+ });
1393
+
1394
+ // src/commands/metrics.ts
1395
+ var metrics_exports = {};
1396
+ __export(metrics_exports, {
1397
+ metricsCommand: () => metricsCommand
1398
+ });
1399
+ import { Command as Command7 } from "commander";
1400
+ var metricsCommand;
1401
+ var init_metrics = __esm({
1402
+ "src/commands/metrics.ts"() {
1403
+ "use strict";
1404
+ init_client();
1405
+ init_errors();
1406
+ init_output();
1407
+ metricsCommand = new Command7("metrics").description("View and refresh metrics");
1408
+ metricsCommand.command("get").description("Get aggregated metrics").option("--start-date <date>", "Start date (YYYY-MM-DD)").option("--end-date <date>", "End date (YYYY-MM-DD)").option("--db-id <id>", "Database ID").action(async (_options, cmd) => {
1409
+ try {
1410
+ const opts = cmd.optsWithGlobals();
1411
+ const client = getClient(cmd);
1412
+ const response = await client.metrics.get({
1413
+ startingDate: opts.startDate,
1414
+ endingDate: opts.endDate,
1415
+ dbId: opts.dbId
1416
+ });
1417
+ const format = getOutputFormat(cmd);
1418
+ if (format === "json") {
1419
+ printJson(response);
1420
+ return;
1421
+ }
1422
+ const metrics = response.metrics ?? [];
1423
+ outputList(
1424
+ cmd,
1425
+ metrics.map((m) => ({
1426
+ date: m.date ?? "",
1427
+ agent_runs_count: m.agent_runs_count ?? 0,
1428
+ team_runs_count: m.team_runs_count ?? 0,
1429
+ workflow_runs_count: m.workflow_runs_count ?? 0,
1430
+ users_count: m.users_count ?? 0
1431
+ })),
1432
+ {
1433
+ columns: ["DATE", "AGENT_RUNS", "TEAM_RUNS", "WORKFLOW_RUNS", "USERS"],
1434
+ keys: ["date", "agent_runs_count", "team_runs_count", "workflow_runs_count", "users_count"]
1435
+ }
1436
+ );
1437
+ } catch (err) {
1438
+ handleError(err, { url: getBaseUrl(cmd) });
1439
+ }
1440
+ });
1441
+ metricsCommand.command("refresh").description("Trigger metrics refresh").option("--db-id <id>", "Database ID").action(async (_options, cmd) => {
1442
+ try {
1443
+ const opts = cmd.optsWithGlobals();
1444
+ const client = getClient(cmd);
1445
+ await client.metrics.refresh({ dbId: opts.dbId });
1446
+ writeSuccess("Metrics refresh triggered.");
1447
+ } catch (err) {
1448
+ handleError(err, { url: getBaseUrl(cmd) });
1449
+ }
1450
+ });
1451
+ }
1452
+ });
1453
+
1454
+ // src/commands/sessions.ts
1455
+ var sessions_exports = {};
1456
+ __export(sessions_exports, {
1457
+ sessionCommand: () => sessionCommand
1458
+ });
1459
+ import { Command as Command8 } from "commander";
1460
+ var sessionCommand;
1461
+ var init_sessions = __esm({
1462
+ "src/commands/sessions.ts"() {
1463
+ "use strict";
1464
+ init_client();
1465
+ init_errors();
1466
+ init_output();
1467
+ sessionCommand = new Command8("session").description("Manage sessions");
1468
+ sessionCommand.command("list").description("List sessions").option("--type <type>", "Filter by type (agent, team, workflow)").option("--component-id <id>", "Filter by component ID").option("--user-id <id>", "Filter by user ID").option("--limit <n>", "Results per page", (v) => Number.parseInt(v, 10), 20).option("--page <n>", "Page number", (v) => Number.parseInt(v, 10), 1).option("--sort-by <field>", "Sort field").option("--sort-order <order>", "Sort order (asc, desc)").option("--db-id <id>", "Database ID").action(async (_options, cmd) => {
1469
+ try {
1470
+ const opts = cmd.optsWithGlobals();
1471
+ const client = getClient(cmd);
1472
+ const result = await client.sessions.list({
1473
+ type: opts.type,
1474
+ componentId: opts.componentId,
1475
+ userId: opts.userId,
1476
+ page: opts.page,
1477
+ limit: opts.limit,
1478
+ sortBy: opts.sortBy,
1479
+ sortOrder: opts.sortOrder,
1480
+ dbId: opts.dbId
1481
+ });
1482
+ const data = result.data;
1483
+ const meta = result.meta;
1484
+ const format = getOutputFormat(cmd);
1485
+ if (format === "json") {
1486
+ printJson({ data, meta });
1487
+ return;
1488
+ }
1489
+ outputList(
1490
+ cmd,
1491
+ data.map((s) => ({
1492
+ session_id: s.session_id ?? "",
1493
+ name: s.session_name ?? "",
1494
+ type: s.type ?? "",
1495
+ created_at: s.created_at ?? ""
1496
+ })),
1497
+ {
1498
+ columns: ["SESSION_ID", "NAME", "TYPE", "CREATED_AT"],
1499
+ keys: ["session_id", "name", "type", "created_at"],
1500
+ meta
1501
+ }
1502
+ );
1503
+ } catch (err) {
1504
+ handleError(err, { url: getBaseUrl(cmd) });
1505
+ }
1506
+ });
1507
+ sessionCommand.command("get").argument("<session_id>", "Session ID").description("Get session details").option("--db-id <id>", "Database ID").action(async (sessionId, _options, cmd) => {
1508
+ try {
1509
+ const opts = cmd.optsWithGlobals();
1510
+ const client = getClient(cmd);
1511
+ const session = await client.sessions.get(sessionId, { dbId: opts.dbId });
1512
+ const format = getOutputFormat(cmd);
1513
+ if (format === "json") {
1514
+ outputDetail(cmd, session, { labels: [], keys: [] });
1515
+ return;
1516
+ }
1517
+ const s = session;
1518
+ outputDetail(
1519
+ cmd,
1520
+ {
1521
+ session_id: s.session_id ?? "",
1522
+ name: s.session_name ?? "",
1523
+ type: s.type ?? "",
1524
+ state: s.session_state ? JSON.stringify(s.session_state) : "",
1525
+ created_at: s.created_at ?? "",
1526
+ updated_at: s.updated_at ?? ""
1527
+ },
1528
+ {
1529
+ labels: ["Session ID", "Name", "Type", "State", "Created At", "Updated At"],
1530
+ keys: ["session_id", "name", "type", "state", "created_at", "updated_at"]
1531
+ }
1532
+ );
1533
+ } catch (err) {
1534
+ handleError(err, { resource: "Session", url: getBaseUrl(cmd) });
1535
+ }
1536
+ });
1537
+ sessionCommand.command("create").description("Create a new session").requiredOption("--type <type>", "Session type: agent, team, workflow (required)").requiredOption("--component-id <id>", "Component ID (required)").option("--name <name>", "Session name").option("--user-id <id>", "User ID").option("--db-id <id>", "Database ID").action(async (_options, cmd) => {
1538
+ try {
1539
+ const opts = cmd.optsWithGlobals();
1540
+ const client = getClient(cmd);
1541
+ const session = await client.sessions.create({
1542
+ type: opts.type,
1543
+ componentId: opts.componentId,
1544
+ name: opts.name,
1545
+ userId: opts.userId,
1546
+ dbId: opts.dbId
1547
+ });
1548
+ const format = getOutputFormat(cmd);
1549
+ if (format === "json") {
1550
+ printJson(session);
1551
+ return;
1552
+ }
1553
+ const s = session;
1554
+ outputDetail(
1555
+ cmd,
1556
+ {
1557
+ session_id: s.session_id ?? "",
1558
+ name: s.session_name ?? "",
1559
+ type: s.type ?? "",
1560
+ created_at: s.created_at ?? ""
1561
+ },
1562
+ {
1563
+ labels: ["Session ID", "Name", "Type", "Created At"],
1564
+ keys: ["session_id", "name", "type", "created_at"]
1565
+ }
1566
+ );
1567
+ writeSuccess("Session created.");
1568
+ } catch (err) {
1569
+ handleError(err, { url: getBaseUrl(cmd) });
1570
+ }
1571
+ });
1572
+ sessionCommand.command("update").argument("<session_id>", "Session ID").description("Update a session").option("--name <name>", "New session name").option("--state <json>", "Session state as JSON string").option("--metadata <json>", "Metadata as JSON string").option("--summary <text>", "Session summary").option("--db-id <id>", "Database ID").action(async (sessionId, _options, cmd) => {
1573
+ try {
1574
+ const opts = cmd.optsWithGlobals();
1575
+ let parsedState;
1576
+ if (opts.state) {
1577
+ try {
1578
+ parsedState = JSON.parse(opts.state);
1579
+ } catch {
1580
+ writeError("Invalid JSON for --state");
1581
+ process.exitCode = 1;
1582
+ return;
1583
+ }
1584
+ }
1585
+ let parsedMetadata;
1586
+ if (opts.metadata) {
1587
+ try {
1588
+ parsedMetadata = JSON.parse(opts.metadata);
1589
+ } catch {
1590
+ writeError("Invalid JSON for --metadata");
1591
+ process.exitCode = 1;
1592
+ return;
1593
+ }
1594
+ }
1595
+ const client = getClient(cmd);
1596
+ await client.sessions.update(sessionId, {
1597
+ sessionName: opts.name,
1598
+ sessionState: parsedState,
1599
+ metadata: parsedMetadata,
1600
+ summary: opts.summary,
1601
+ dbId: opts.dbId
1602
+ });
1603
+ writeSuccess("Session updated.");
1604
+ } catch (err) {
1605
+ handleError(err, { resource: "Session", url: getBaseUrl(cmd) });
1606
+ }
1607
+ });
1608
+ sessionCommand.command("delete").argument("<session_id>", "Session ID").description("Delete a session").option("--db-id <id>", "Database ID").action(async (sessionId, _options, cmd) => {
1609
+ try {
1610
+ const opts = cmd.optsWithGlobals();
1611
+ const client = getClient(cmd);
1612
+ await client.sessions.delete(sessionId, { dbId: opts.dbId });
1613
+ writeSuccess("Session deleted.");
1614
+ } catch (err) {
1615
+ handleError(err, { resource: "Session", url: getBaseUrl(cmd) });
1616
+ }
1617
+ });
1618
+ sessionCommand.command("delete-all").description("Delete multiple sessions").requiredOption("--ids <ids>", "Comma-separated session IDs (required)").requiredOption("--types <types>", "Comma-separated session types, must match IDs (required)").option("--user-id <id>", "User ID").option("--db-id <id>", "Database ID").action(async (_options, cmd) => {
1619
+ try {
1620
+ const opts = cmd.optsWithGlobals();
1621
+ const sessionIds = opts.ids.split(",").map((s) => s.trim());
1622
+ const sessionTypes = opts.types.split(",").map((s) => s.trim());
1623
+ const client = getClient(cmd);
1624
+ await client.sessions.deleteAll({
1625
+ sessionIds,
1626
+ sessionTypes,
1627
+ userId: opts.userId,
1628
+ dbId: opts.dbId
1629
+ });
1630
+ writeSuccess("Sessions deleted.");
1631
+ } catch (err) {
1632
+ handleError(err, { url: getBaseUrl(cmd) });
1633
+ }
1634
+ });
1635
+ sessionCommand.command("runs").argument("<session_id>", "Session ID").description("List runs for a session").option("--db-id <id>", "Database ID").action(async (sessionId, _options, cmd) => {
1636
+ try {
1637
+ const opts = cmd.optsWithGlobals();
1638
+ const client = getClient(cmd);
1639
+ const runs = await client.sessions.getRuns(sessionId, { dbId: opts.dbId });
1640
+ const format = getOutputFormat(cmd);
1641
+ if (format === "json") {
1642
+ printJson({ data: runs });
1643
+ return;
1644
+ }
1645
+ const data = runs.map((r) => ({
1646
+ run_id: r.run_id ?? "",
1647
+ status: r.status ?? "",
1648
+ created_at: r.created_at ?? ""
1649
+ }));
1650
+ outputList(cmd, data, {
1651
+ columns: ["RUN_ID", "STATUS", "CREATED_AT"],
1652
+ keys: ["run_id", "status", "created_at"]
1653
+ });
1654
+ } catch (err) {
1655
+ handleError(err, { resource: "Session", url: getBaseUrl(cmd) });
1656
+ }
1657
+ });
1658
+ }
1659
+ });
1660
+
1661
+ // src/commands/memories.ts
1662
+ var memories_exports = {};
1663
+ __export(memories_exports, {
1664
+ memoryCommand: () => memoryCommand
1665
+ });
1666
+ import { Command as Command9 } from "commander";
1667
+ var memoryCommand;
1668
+ var init_memories = __esm({
1669
+ "src/commands/memories.ts"() {
1670
+ "use strict";
1671
+ init_client();
1672
+ init_errors();
1673
+ init_output();
1674
+ memoryCommand = new Command9("memory").description("Manage memories");
1675
+ memoryCommand.command("list").description("List memories").option("--user-id <id>", "Filter by user ID").option("--team-id <id>", "Filter by team ID").option("--agent-id <id>", "Filter by agent ID").option("--search <content>", "Search within memory content").option("--topics <topics>", "Comma-separated topics to filter by").option("--limit <n>", "Results per page", (v) => Number.parseInt(v, 10), 20).option("--page <n>", "Page number", (v) => Number.parseInt(v, 10), 1).option("--sort-by <field>", "Sort field").option("--sort-order <order>", "Sort order (asc, desc)").option("--db-id <id>", "Database ID").action(async (_options, cmd) => {
1676
+ try {
1677
+ const opts = cmd.optsWithGlobals();
1678
+ const parsedTopics = opts.topics ? opts.topics.split(",").map((t) => t.trim()) : void 0;
1679
+ const client = getClient(cmd);
1680
+ const result = await client.memories.list({
1681
+ userId: opts.userId,
1682
+ teamId: opts.teamId,
1683
+ agentId: opts.agentId,
1684
+ searchContent: opts.search,
1685
+ topics: parsedTopics,
1686
+ page: opts.page,
1687
+ limit: opts.limit,
1688
+ sortBy: opts.sortBy,
1689
+ sortOrder: opts.sortOrder,
1690
+ dbId: opts.dbId
1691
+ });
1692
+ const data = result.data;
1693
+ const meta = result.meta;
1694
+ const format = getOutputFormat(cmd);
1695
+ if (format === "json") {
1696
+ printJson({ data, meta });
1697
+ return;
1698
+ }
1699
+ outputList(
1700
+ cmd,
1701
+ data.map((m) => ({
1702
+ memory_id: m.memory_id ?? "",
1703
+ memory: m.memory ?? "",
1704
+ topics: Array.isArray(m.topics) ? m.topics.join(", ") : "",
1705
+ user_id: m.user_id ?? ""
1706
+ })),
1707
+ {
1708
+ columns: ["ID", "MEMORY", "TOPICS", "USER_ID"],
1709
+ keys: ["memory_id", "memory", "topics", "user_id"],
1710
+ meta
1711
+ }
1712
+ );
1713
+ } catch (err) {
1714
+ handleError(err, { url: getBaseUrl(cmd) });
1715
+ }
1716
+ });
1717
+ memoryCommand.command("get").argument("<memory_id>", "Memory ID").description("Get memory details").option("--db-id <id>", "Database ID").action(async (memoryId, _options, cmd) => {
1718
+ try {
1719
+ const opts = cmd.optsWithGlobals();
1720
+ const client = getClient(cmd);
1721
+ const memory = await client.memories.get(memoryId, { dbId: opts.dbId });
1722
+ const format = getOutputFormat(cmd);
1723
+ if (format === "json") {
1724
+ outputDetail(cmd, memory, { labels: [], keys: [] });
1725
+ return;
1726
+ }
1727
+ const m = memory;
1728
+ outputDetail(
1729
+ cmd,
1730
+ {
1731
+ memory_id: m.memory_id ?? "",
1732
+ memory: m.memory ?? "",
1733
+ topics: Array.isArray(m.topics) ? m.topics.join(", ") : "",
1734
+ agent_id: m.agent_id ?? "",
1735
+ team_id: m.team_id ?? "",
1736
+ user_id: m.user_id ?? "",
1737
+ updated_at: m.updated_at ?? ""
1738
+ },
1739
+ {
1740
+ labels: ["Memory ID", "Memory", "Topics", "Agent ID", "Team ID", "User ID", "Updated At"],
1741
+ keys: ["memory_id", "memory", "topics", "agent_id", "team_id", "user_id", "updated_at"]
1742
+ }
1743
+ );
1744
+ } catch (err) {
1745
+ handleError(err, { resource: "Memory", url: getBaseUrl(cmd) });
1746
+ }
1747
+ });
1748
+ memoryCommand.command("create").description("Create a new memory").requiredOption("--memory <content>", "Memory content (required)").option("--topics <topics>", "Comma-separated topics").option("--user-id <id>", "User ID").option("--db-id <id>", "Database ID").action(async (_options, cmd) => {
1749
+ try {
1750
+ const opts = cmd.optsWithGlobals();
1751
+ const parsedTopics = opts.topics ? opts.topics.split(",").map((t) => t.trim()) : void 0;
1752
+ const client = getClient(cmd);
1753
+ const memory = await client.memories.create({
1754
+ memory: opts.memory,
1755
+ topics: parsedTopics,
1756
+ userId: opts.userId,
1757
+ dbId: opts.dbId
1758
+ });
1759
+ const format = getOutputFormat(cmd);
1760
+ if (format === "json") {
1761
+ printJson(memory);
1762
+ return;
1763
+ }
1764
+ const m = memory;
1765
+ outputDetail(
1766
+ cmd,
1767
+ {
1768
+ memory_id: m.memory_id ?? "",
1769
+ memory: m.memory ?? "",
1770
+ topics: Array.isArray(m.topics) ? m.topics.join(", ") : "",
1771
+ user_id: m.user_id ?? ""
1772
+ },
1773
+ {
1774
+ labels: ["Memory ID", "Memory", "Topics", "User ID"],
1775
+ keys: ["memory_id", "memory", "topics", "user_id"]
1776
+ }
1777
+ );
1778
+ writeSuccess("Memory created.");
1779
+ } catch (err) {
1780
+ handleError(err, { url: getBaseUrl(cmd) });
1781
+ }
1782
+ });
1783
+ memoryCommand.command("update").argument("<memory_id>", "Memory ID").description("Update a memory").option("--memory <content>", "New memory content").option("--topics <topics>", "Comma-separated topics").option("--db-id <id>", "Database ID").action(async (memoryId, _options, cmd) => {
1784
+ try {
1785
+ const opts = cmd.optsWithGlobals();
1786
+ const parsedTopics = opts.topics ? opts.topics.split(",").map((t) => t.trim()) : void 0;
1787
+ const client = getClient(cmd);
1788
+ await client.memories.update(memoryId, {
1789
+ memory: opts.memory,
1790
+ topics: parsedTopics,
1791
+ dbId: opts.dbId
1792
+ });
1793
+ writeSuccess("Memory updated.");
1794
+ } catch (err) {
1795
+ handleError(err, { resource: "Memory", url: getBaseUrl(cmd) });
1796
+ }
1797
+ });
1798
+ memoryCommand.command("delete").argument("<memory_id>", "Memory ID").description("Delete a memory").option("--db-id <id>", "Database ID").action(async (memoryId, _options, cmd) => {
1799
+ try {
1800
+ const opts = cmd.optsWithGlobals();
1801
+ const client = getClient(cmd);
1802
+ await client.memories.delete(memoryId, { dbId: opts.dbId });
1803
+ writeSuccess("Memory deleted.");
1804
+ } catch (err) {
1805
+ handleError(err, { resource: "Memory", url: getBaseUrl(cmd) });
1806
+ }
1807
+ });
1808
+ memoryCommand.command("delete-all").description("Delete multiple memories").requiredOption("--ids <ids>", "Comma-separated memory IDs (required)").option("--user-id <id>", "User ID").option("--db-id <id>", "Database ID").action(async (_options, cmd) => {
1809
+ try {
1810
+ const opts = cmd.optsWithGlobals();
1811
+ const memoryIds = opts.ids.split(",").map((s) => s.trim());
1812
+ const client = getClient(cmd);
1813
+ await client.memories.deleteAll({
1814
+ memoryIds,
1815
+ userId: opts.userId,
1816
+ dbId: opts.dbId
1817
+ });
1818
+ writeSuccess("Memories deleted.");
1819
+ } catch (err) {
1820
+ handleError(err, { url: getBaseUrl(cmd) });
1821
+ }
1822
+ });
1823
+ memoryCommand.command("topics").description("List memory topics").option("--user-id <id>", "Filter by user ID").option("--db-id <id>", "Database ID").action(async (_options, cmd) => {
1824
+ try {
1825
+ const opts = cmd.optsWithGlobals();
1826
+ const client = getClient(cmd);
1827
+ const result = await client.memories.getTopics({
1828
+ userId: opts.userId,
1829
+ dbId: opts.dbId
1830
+ });
1831
+ const format = getOutputFormat(cmd);
1832
+ if (format === "json") {
1833
+ printJson(result);
1834
+ return;
1835
+ }
1836
+ if (Array.isArray(result)) {
1837
+ outputList(
1838
+ cmd,
1839
+ result.map((t) => ({ topic: String(t) })),
1840
+ {
1841
+ columns: ["TOPIC"],
1842
+ keys: ["topic"]
1843
+ }
1844
+ );
1845
+ } else {
1846
+ printJson(result);
1847
+ }
1848
+ } catch (err) {
1849
+ handleError(err, { url: getBaseUrl(cmd) });
1850
+ }
1851
+ });
1852
+ memoryCommand.command("stats").description("Get memory statistics").option("--user-id <id>", "Filter by user ID").option("--limit <n>", "Results per page", (v) => Number.parseInt(v, 10)).option("--page <n>", "Page number", (v) => Number.parseInt(v, 10)).option("--db-id <id>", "Database ID").action(async (_options, cmd) => {
1853
+ try {
1854
+ const opts = cmd.optsWithGlobals();
1855
+ const client = getClient(cmd);
1856
+ const result = await client.memories.getStats({
1857
+ userId: opts.userId,
1858
+ limit: opts.limit,
1859
+ page: opts.page,
1860
+ dbId: opts.dbId
1861
+ });
1862
+ const format = getOutputFormat(cmd);
1863
+ if (format === "json") {
1864
+ printJson(result);
1865
+ return;
1866
+ }
1867
+ if (Array.isArray(result)) {
1868
+ outputList(
1869
+ cmd,
1870
+ result.map((s) => {
1871
+ const stat = s;
1872
+ return {
1873
+ user_id: stat.user_id ?? "",
1874
+ total_memories: stat.total_memories ?? "",
1875
+ last_updated: stat.last_updated ?? ""
1876
+ };
1877
+ }),
1878
+ {
1879
+ columns: ["USER_ID", "TOTAL_MEMORIES", "LAST_UPDATED"],
1880
+ keys: ["user_id", "total_memories", "last_updated"]
1881
+ }
1882
+ );
1883
+ } else {
1884
+ printJson(result);
1885
+ }
1886
+ } catch (err) {
1887
+ handleError(err, { url: getBaseUrl(cmd) });
1888
+ }
1889
+ });
1890
+ memoryCommand.command("optimize").description("Optimize memories for a user").requiredOption("--user-id <id>", "User ID (required)").option("--model <model>", "Model to use for optimization").option("--apply", "Apply optimizations immediately").option("--db-id <id>", "Database ID").action(async (_options, cmd) => {
1891
+ try {
1892
+ const opts = cmd.optsWithGlobals();
1893
+ const client = getClient(cmd);
1894
+ const result = await client.memories.optimize({
1895
+ userId: opts.userId,
1896
+ model: opts.model,
1897
+ apply: opts.apply,
1898
+ dbId: opts.dbId
1899
+ });
1900
+ const format = getOutputFormat(cmd);
1901
+ if (format === "json") {
1902
+ printJson(result);
1903
+ return;
1904
+ }
1905
+ writeSuccess(`Memory optimization ${opts.apply ? "applied" : "previewed"}.`);
1906
+ printJson(result);
1907
+ } catch (err) {
1908
+ handleError(err, { url: getBaseUrl(cmd) });
1909
+ }
1910
+ });
1911
+ }
1912
+ });
1913
+
1914
+ // src/commands/knowledge.ts
1915
+ var knowledge_exports = {};
1916
+ __export(knowledge_exports, {
1917
+ knowledgeCommand: () => knowledgeCommand
1918
+ });
1919
+ import { existsSync as existsSync3 } from "fs";
1920
+ import { resolve } from "path";
1921
+ import { Command as Command10 } from "commander";
1922
+ var knowledgeCommand;
1923
+ var init_knowledge = __esm({
1924
+ "src/commands/knowledge.ts"() {
1925
+ "use strict";
1926
+ init_client();
1927
+ init_errors();
1928
+ init_output();
1929
+ knowledgeCommand = new Command10("knowledge").description("Manage knowledge base");
1930
+ knowledgeCommand.command("upload").argument("[file_path]", "Local file path to upload").description("Upload content to knowledge base").option("--url <url>", "Upload from URL instead of file").option("--name <name>", "Content name").option("--description <desc>", "Content description").option("--db-id <id>", "Database ID").option("--knowledge-id <id>", "Knowledge base ID").action(async (filePath, _options, cmd) => {
1931
+ try {
1932
+ const opts = cmd.optsWithGlobals();
1933
+ const client = getClient(cmd);
1934
+ if (!filePath && !opts.url) {
1935
+ writeError("Provide a file path or --url");
1936
+ process.exitCode = 1;
1937
+ return;
1938
+ }
1939
+ if (filePath && opts.url) {
1940
+ writeError("Provide either a file path or --url, not both");
1941
+ process.exitCode = 1;
1942
+ return;
1943
+ }
1944
+ const uploadOpts = {
1945
+ name: opts.name,
1946
+ description: opts.description,
1947
+ dbId: opts.dbId,
1948
+ knowledgeId: opts.knowledgeId
1949
+ };
1950
+ if (filePath) {
1951
+ const resolved = resolve(filePath);
1952
+ if (!existsSync3(resolved)) {
1953
+ writeError(`File not found: ${resolved}`);
1954
+ process.exitCode = 1;
1955
+ return;
1956
+ }
1957
+ uploadOpts.file = resolved;
1958
+ } else {
1959
+ uploadOpts.url = opts.url;
1960
+ }
1961
+ const result = await client.knowledge.upload(uploadOpts);
1962
+ const format = getOutputFormat(cmd);
1963
+ if (format === "json") {
1964
+ printJson(result);
1965
+ } else {
1966
+ outputDetail(
1967
+ cmd,
1968
+ {
1969
+ id: result.id ?? "",
1970
+ name: result.name ?? "",
1971
+ status: result.status ?? "",
1972
+ type: result.type ?? ""
1973
+ },
1974
+ {
1975
+ labels: ["ID", "Name", "Status", "Type"],
1976
+ keys: ["id", "name", "status", "type"]
1977
+ }
1978
+ );
1979
+ }
1980
+ process.stderr.write(`Check status: agno-cli knowledge status ${result.id}
1981
+ `);
1982
+ } catch (err) {
1983
+ handleError(err, { resource: "Knowledge base", url: getBaseUrl(cmd) });
1984
+ }
1985
+ });
1986
+ knowledgeCommand.command("list").description("List knowledge content").option("--limit <n>", "Results per page", (v) => Number.parseInt(v, 10), 20).option("--page <n>", "Page number", (v) => Number.parseInt(v, 10), 1).option("--sort-by <field>", "Sort field").option("--sort-order <order>", "Sort order (asc, desc)").option("--db-id <id>", "Database ID").option("--knowledge-id <id>", "Knowledge base ID").action(async (_options, cmd) => {
1987
+ try {
1988
+ const opts = cmd.optsWithGlobals();
1989
+ const client = getClient(cmd);
1990
+ const result = await client.knowledge.list({
1991
+ limit: opts.limit,
1992
+ page: opts.page,
1993
+ sortBy: opts.sortBy,
1994
+ sortOrder: opts.sortOrder,
1995
+ dbId: opts.dbId,
1996
+ knowledgeId: opts.knowledgeId
1997
+ });
1998
+ const r = result;
1999
+ const data = r.data;
2000
+ const meta = r.meta;
2001
+ const format = getOutputFormat(cmd);
2002
+ if (format === "json") {
2003
+ printJson({ data, meta });
2004
+ return;
2005
+ }
2006
+ outputList(
2007
+ cmd,
2008
+ data.map((k) => ({
2009
+ id: k.id ?? "",
2010
+ name: k.name ?? "",
2011
+ status: k.status ?? "",
2012
+ type: k.type ?? ""
2013
+ })),
2014
+ {
2015
+ columns: ["ID", "NAME", "STATUS", "TYPE"],
2016
+ keys: ["id", "name", "status", "type"],
2017
+ meta
2018
+ }
2019
+ );
2020
+ } catch (err) {
2021
+ handleError(err, { url: getBaseUrl(cmd) });
2022
+ }
2023
+ });
2024
+ knowledgeCommand.command("get").argument("<content_id>", "Content ID").description("Get knowledge content details").option("--db-id <id>", "Database ID").option("--knowledge-id <id>", "Knowledge base ID").action(async (contentId, _options, cmd) => {
2025
+ try {
2026
+ const opts = cmd.optsWithGlobals();
2027
+ const client = getClient(cmd);
2028
+ const result = await client.knowledge.get(contentId, { dbId: opts.dbId, knowledgeId: opts.knowledgeId });
2029
+ const format = getOutputFormat(cmd);
2030
+ if (format === "json") {
2031
+ outputDetail(cmd, result, { labels: [], keys: [] });
2032
+ return;
2033
+ }
2034
+ const k = result;
2035
+ const rawContent = String(k.content ?? "");
2036
+ const truncatedContent = rawContent.length > 200 ? `${rawContent.substring(0, 197)}...` : rawContent;
2037
+ outputDetail(
2038
+ cmd,
2039
+ {
2040
+ id: k.id ?? "",
2041
+ name: k.name ?? "",
2042
+ status: k.status ?? "",
2043
+ type: k.type ?? "",
2044
+ content: truncatedContent
2045
+ },
2046
+ {
2047
+ labels: ["ID", "Name", "Status", "Type", "Content"],
2048
+ keys: ["id", "name", "status", "type", "content"]
2049
+ }
2050
+ );
2051
+ } catch (err) {
2052
+ handleError(err, { resource: "Knowledge base", url: getBaseUrl(cmd) });
2053
+ }
2054
+ });
2055
+ knowledgeCommand.command("search").argument("<query>", "Search query").description("Search knowledge base").option("--search-type <type>", "Search type: vector, keyword, hybrid", "vector").option("--max-results <n>", "Maximum results", (v) => Number.parseInt(v, 10)).option("--limit <n>", "Results per page", (v) => Number.parseInt(v, 10), 20).option("--page <n>", "Page number", (v) => Number.parseInt(v, 10), 1).option("--db-id <id>", "Database ID").option("--knowledge-id <id>", "Knowledge base ID").action(async (query, _options, cmd) => {
2056
+ try {
2057
+ const opts = cmd.optsWithGlobals();
2058
+ const client = getClient(cmd);
2059
+ const result = await client.knowledge.search(query, {
2060
+ searchType: opts.searchType,
2061
+ maxResults: opts.maxResults,
2062
+ dbId: opts.dbId,
2063
+ knowledgeId: opts.knowledgeId,
2064
+ page: opts.page,
2065
+ limit: opts.limit
2066
+ });
2067
+ const sr = result;
2068
+ const data = sr.data;
2069
+ const meta = sr.meta;
2070
+ const format = getOutputFormat(cmd);
2071
+ if (format === "json") {
2072
+ printJson({ data, meta });
2073
+ return;
2074
+ }
2075
+ outputList(
2076
+ cmd,
2077
+ data.map((item) => {
2078
+ const rawContent = String(item.content ?? "");
2079
+ return {
2080
+ id: item.id ?? "",
2081
+ content: rawContent.length > 80 ? `${rawContent.substring(0, 77)}...` : rawContent,
2082
+ name: item.name ?? "",
2083
+ score: item.reranking_score ?? ""
2084
+ };
2085
+ }),
2086
+ {
2087
+ columns: ["ID", "CONTENT", "NAME", "SCORE"],
2088
+ keys: ["id", "content", "name", "score"],
2089
+ meta
2090
+ }
2091
+ );
2092
+ } catch (err) {
2093
+ handleError(err, { url: getBaseUrl(cmd) });
2094
+ }
2095
+ });
2096
+ knowledgeCommand.command("status").argument("<content_id>", "Content ID").description("Get knowledge content processing status").option("--db-id <id>", "Database ID").option("--knowledge-id <id>", "Knowledge base ID").action(async (contentId, _options, cmd) => {
2097
+ try {
2098
+ const opts = cmd.optsWithGlobals();
2099
+ const client = getClient(cmd);
2100
+ const result = await client.knowledge.getStatus(contentId, { dbId: opts.dbId, knowledgeId: opts.knowledgeId });
2101
+ const format = getOutputFormat(cmd);
2102
+ if (format === "json") {
2103
+ printJson(result);
2104
+ return;
2105
+ }
2106
+ const s = result;
2107
+ outputDetail(
2108
+ cmd,
2109
+ {
2110
+ content_id: s.content_id ?? "",
2111
+ status: s.status ?? "",
2112
+ progress: s.progress ?? "",
2113
+ error: s.error ?? ""
2114
+ },
2115
+ {
2116
+ labels: ["Content ID", "Status", "Progress", "Error"],
2117
+ keys: ["content_id", "status", "progress", "error"]
2118
+ }
2119
+ );
2120
+ } catch (err) {
2121
+ handleError(err, { resource: "Knowledge base", url: getBaseUrl(cmd) });
2122
+ }
2123
+ });
2124
+ knowledgeCommand.command("delete").argument("<content_id>", "Content ID").description("Delete knowledge content").option("--db-id <id>", "Database ID").option("--knowledge-id <id>", "Knowledge base ID").action(async (contentId, _options, cmd) => {
2125
+ try {
2126
+ const opts = cmd.optsWithGlobals();
2127
+ const client = getClient(cmd);
2128
+ await client.knowledge.delete(contentId, { dbId: opts.dbId, knowledgeId: opts.knowledgeId });
2129
+ writeSuccess("Knowledge content deleted.");
2130
+ } catch (err) {
2131
+ handleError(err, { resource: "Knowledge base", url: getBaseUrl(cmd) });
2132
+ }
2133
+ });
2134
+ knowledgeCommand.command("delete-all").description("Delete all knowledge content").option("--db-id <id>", "Database ID").option("--knowledge-id <id>", "Knowledge base ID").action(async (_options, cmd) => {
2135
+ try {
2136
+ const opts = cmd.optsWithGlobals();
2137
+ const client = getClient(cmd);
2138
+ await client.knowledge.deleteAll({ dbId: opts.dbId, knowledgeId: opts.knowledgeId });
2139
+ writeSuccess("All knowledge content deleted.");
2140
+ } catch (err) {
2141
+ handleError(err, { resource: "Knowledge base", url: getBaseUrl(cmd) });
2142
+ }
2143
+ });
2144
+ knowledgeCommand.command("config").description("Get knowledge base configuration").option("--db-id <id>", "Database ID").option("--knowledge-id <id>", "Knowledge base ID").action(async (_options, cmd) => {
2145
+ try {
2146
+ const opts = cmd.optsWithGlobals();
2147
+ const client = getClient(cmd);
2148
+ const result = await client.knowledge.getConfig({ dbId: opts.dbId, knowledgeId: opts.knowledgeId });
2149
+ const format = getOutputFormat(cmd);
2150
+ if (format === "json") {
2151
+ printJson(result);
2152
+ return;
2153
+ }
2154
+ const c = result;
2155
+ outputDetail(
2156
+ cmd,
2157
+ {
2158
+ readers: c.readers ? JSON.stringify(c.readers) : "",
2159
+ chunkers: c.chunkers ? JSON.stringify(c.chunkers) : "",
2160
+ vector_dbs: c.vector_dbs ? JSON.stringify(c.vector_dbs) : ""
2161
+ },
2162
+ {
2163
+ labels: ["Readers", "Chunkers", "Vector DBs"],
2164
+ keys: ["readers", "chunkers", "vector_dbs"]
2165
+ }
2166
+ );
2167
+ } catch (err) {
2168
+ handleError(err, { resource: "Knowledge base", url: getBaseUrl(cmd) });
2169
+ }
2170
+ });
2171
+ }
2172
+ });
2173
+
2174
+ // src/commands/traces.ts
2175
+ var traces_exports = {};
2176
+ __export(traces_exports, {
2177
+ traceCommand: () => traceCommand
2178
+ });
2179
+ import { Command as Command11 } from "commander";
2180
+ var traceCommand;
2181
+ var init_traces = __esm({
2182
+ "src/commands/traces.ts"() {
2183
+ "use strict";
2184
+ init_client();
2185
+ init_errors();
2186
+ init_output();
2187
+ traceCommand = new Command11("trace").description("Manage traces");
2188
+ traceCommand.command("list").description("List traces").option("--run-id <id>", "Filter by run ID").option("--session-id <id>", "Filter by session ID").option("--user-id <id>", "Filter by user ID").option("--agent-id <id>", "Filter by agent ID").option("--status <status>", "Filter by status").option("--limit <n>", "Results per page", (v) => Number.parseInt(v, 10), 20).option("--page <n>", "Page number", (v) => Number.parseInt(v, 10), 1).option("--db-id <id>", "Database ID").action(async (_options, cmd) => {
2189
+ try {
2190
+ const opts = cmd.optsWithGlobals();
2191
+ const client = getClient(cmd);
2192
+ const result = await client.traces.list({
2193
+ runId: opts.runId,
2194
+ sessionId: opts.sessionId,
2195
+ userId: opts.userId,
2196
+ agentId: opts.agentId,
2197
+ status: opts.status,
2198
+ page: opts.page,
2199
+ limit: opts.limit,
2200
+ dbId: opts.dbId
2201
+ });
2202
+ const data = result.data;
2203
+ const meta = result.meta;
2204
+ const format = getOutputFormat(cmd);
2205
+ if (format === "json") {
2206
+ printJson({ data, meta });
2207
+ return;
2208
+ }
2209
+ outputList(
2210
+ cmd,
2211
+ data.map((t) => ({
2212
+ trace_id: t.trace_id ?? "",
2213
+ name: t.name ?? "",
2214
+ status: t.status ?? "",
2215
+ duration: t.duration ?? "",
2216
+ start_time: t.start_time ?? ""
2217
+ })),
2218
+ {
2219
+ columns: ["TRACE_ID", "NAME", "STATUS", "DURATION", "START_TIME"],
2220
+ keys: ["trace_id", "name", "status", "duration", "start_time"],
2221
+ meta
2222
+ }
2223
+ );
2224
+ } catch (err) {
2225
+ handleError(err, { url: getBaseUrl(cmd) });
2226
+ }
2227
+ });
2228
+ traceCommand.command("get").argument("<trace_id>", "Trace ID").description("Get trace details").option("--db-id <id>", "Database ID").action(async (traceId, _options, cmd) => {
2229
+ try {
2230
+ const opts = cmd.optsWithGlobals();
2231
+ const client = getClient(cmd);
2232
+ const result = await client.traces.get(traceId, { dbId: opts.dbId });
2233
+ const format = getOutputFormat(cmd);
2234
+ if (format === "json") {
2235
+ outputDetail(cmd, result, { labels: [], keys: [] });
2236
+ return;
2237
+ }
2238
+ const t = result;
2239
+ outputDetail(
2240
+ cmd,
2241
+ {
2242
+ trace_id: t.trace_id ?? "",
2243
+ name: t.name ?? "",
2244
+ status: t.status ?? "",
2245
+ duration: t.duration ?? "",
2246
+ start_time: t.start_time ?? "",
2247
+ end_time: t.end_time ?? "",
2248
+ error: t.error ?? ""
2249
+ },
2250
+ {
2251
+ labels: ["Trace ID", "Name", "Status", "Duration", "Start Time", "End Time", "Error"],
2252
+ keys: ["trace_id", "name", "status", "duration", "start_time", "end_time", "error"]
2253
+ }
2254
+ );
2255
+ } catch (err) {
2256
+ handleError(err, { resource: "Trace", url: getBaseUrl(cmd) });
2257
+ }
2258
+ });
2259
+ traceCommand.command("stats").description("Get trace statistics").option("--user-id <id>", "Filter by user ID").option("--agent-id <id>", "Filter by agent ID").option("--team-id <id>", "Filter by team ID").option("--workflow-id <id>", "Filter by workflow ID").option("--start-time <time>", "Start time filter").option("--end-time <time>", "End time filter").option("--limit <n>", "Results per page", (v) => Number.parseInt(v, 10)).option("--page <n>", "Page number", (v) => Number.parseInt(v, 10)).option("--db-id <id>", "Database ID").action(async (_options, cmd) => {
2260
+ try {
2261
+ const opts = cmd.optsWithGlobals();
2262
+ const client = getClient(cmd);
2263
+ const result = await client.traces.getStats({
2264
+ userId: opts.userId,
2265
+ agentId: opts.agentId,
2266
+ teamId: opts.teamId,
2267
+ workflowId: opts.workflowId,
2268
+ startTime: opts.startTime,
2269
+ endTime: opts.endTime,
2270
+ page: opts.page,
2271
+ limit: opts.limit,
2272
+ dbId: opts.dbId
2273
+ });
2274
+ const format = getOutputFormat(cmd);
2275
+ if (format === "json") {
2276
+ printJson(result);
2277
+ return;
2278
+ }
2279
+ const r = result;
2280
+ if (Array.isArray(r.data)) {
2281
+ const data = r.data;
2282
+ outputList(
2283
+ cmd,
2284
+ data.map((s) => ({
2285
+ session_id: s.session_id ?? "",
2286
+ user_id: s.user_id ?? "",
2287
+ agent_id: s.agent_id ?? "",
2288
+ total_traces: s.total_traces ?? 0,
2289
+ first_trace_at: s.first_trace_at ?? "",
2290
+ last_trace_at: s.last_trace_at ?? ""
2291
+ })),
2292
+ {
2293
+ columns: ["SESSION_ID", "USER_ID", "AGENT_ID", "TOTAL_TRACES", "FIRST_TRACE", "LAST_TRACE"],
2294
+ keys: ["session_id", "user_id", "agent_id", "total_traces", "first_trace_at", "last_trace_at"]
2295
+ }
2296
+ );
2297
+ } else {
2298
+ printJson(result);
2299
+ }
2300
+ } catch (err) {
2301
+ handleError(err, { url: getBaseUrl(cmd) });
2302
+ }
2303
+ });
2304
+ traceCommand.command("search").description("Search traces").option("--filter <json>", "Filter as JSON string").option("--group-by <field>", "Group results by: run, session").option("--limit <n>", "Results per page", (v) => Number.parseInt(v, 10), 20).option("--page <n>", "Page number", (v) => Number.parseInt(v, 10), 1).option("--db-id <id>", "Database ID").action(async (_options, cmd) => {
2305
+ try {
2306
+ const opts = cmd.optsWithGlobals();
2307
+ let parsedFilter;
2308
+ if (opts.filter) {
2309
+ try {
2310
+ parsedFilter = JSON.parse(opts.filter);
2311
+ } catch {
2312
+ writeError("Invalid JSON for --filter");
2313
+ process.exitCode = 1;
2314
+ return;
2315
+ }
2316
+ }
2317
+ const client = getClient(cmd);
2318
+ const result = await client.traces.search({
2319
+ filter: parsedFilter,
2320
+ groupBy: opts.groupBy,
2321
+ page: opts.page,
2322
+ limit: opts.limit,
2323
+ dbId: opts.dbId
2324
+ });
2325
+ const format = getOutputFormat(cmd);
2326
+ if (format === "json") {
2327
+ printJson(result);
2328
+ return;
2329
+ }
2330
+ const r = result;
2331
+ if (Array.isArray(r.data)) {
2332
+ const data = r.data;
2333
+ outputList(
2334
+ cmd,
2335
+ data.map((t) => ({
2336
+ trace_id: t.trace_id ?? "",
2337
+ name: t.name ?? "",
2338
+ status: t.status ?? "",
2339
+ duration: t.duration ?? ""
2340
+ })),
2341
+ {
2342
+ columns: ["TRACE_ID", "NAME", "STATUS", "DURATION"],
2343
+ keys: ["trace_id", "name", "status", "duration"]
2344
+ }
2345
+ );
2346
+ } else {
2347
+ printJson(result);
2348
+ }
2349
+ } catch (err) {
2350
+ handleError(err, { url: getBaseUrl(cmd) });
2351
+ }
2352
+ });
2353
+ }
2354
+ });
2355
+
2356
+ // src/commands/evals.ts
2357
+ var evals_exports = {};
2358
+ __export(evals_exports, {
2359
+ evalCommand: () => evalCommand
2360
+ });
2361
+ import { Command as Command12 } from "commander";
2362
+ var evalCommand;
2363
+ var init_evals = __esm({
2364
+ "src/commands/evals.ts"() {
2365
+ "use strict";
2366
+ init_client();
2367
+ init_errors();
2368
+ init_output();
2369
+ evalCommand = new Command12("eval").description("Manage eval runs");
2370
+ evalCommand.command("list").description("List eval runs").option("--agent-id <id>", "Filter by agent ID").option("--team-id <id>", "Filter by team ID").option("--workflow-id <id>", "Filter by workflow ID").option("--model-id <id>", "Filter by model ID").option("--type <type>", "Filter by eval type").option("--limit <n>", "Results per page", (v) => Number.parseInt(v, 10), 20).option("--page <n>", "Page number", (v) => Number.parseInt(v, 10), 1).option("--sort-by <field>", "Sort field").option("--sort-order <order>", "Sort order (asc, desc)").option("--db-id <id>", "Database ID").action(async (_options, cmd) => {
2371
+ try {
2372
+ const opts = cmd.optsWithGlobals();
2373
+ const client = getClient(cmd);
2374
+ const result = await client.evals.list({
2375
+ agentId: opts.agentId,
2376
+ teamId: opts.teamId,
2377
+ workflowId: opts.workflowId,
2378
+ modelId: opts.modelId,
2379
+ type: opts.type,
2380
+ page: opts.page,
2381
+ limit: opts.limit,
2382
+ sortBy: opts.sortBy,
2383
+ sortOrder: opts.sortOrder,
2384
+ dbId: opts.dbId
2385
+ });
2386
+ const data = result.data;
2387
+ const meta = result.meta;
2388
+ const format = getOutputFormat(cmd);
2389
+ if (format === "json") {
2390
+ printJson({ data, meta });
2391
+ return;
2392
+ }
2393
+ outputList(
2394
+ cmd,
2395
+ data.map((e) => ({
2396
+ id: e.id ?? "",
2397
+ name: e.name ?? "",
2398
+ eval_type: e.eval_type ?? "",
2399
+ agent_id: e.agent_id ?? "",
2400
+ created_at: e.created_at ?? ""
2401
+ })),
2402
+ {
2403
+ columns: ["ID", "NAME", "EVAL_TYPE", "AGENT_ID", "CREATED_AT"],
2404
+ keys: ["id", "name", "eval_type", "agent_id", "created_at"],
2405
+ meta
2406
+ }
2407
+ );
2408
+ } catch (err) {
2409
+ handleError(err, { url: getBaseUrl(cmd) });
2410
+ }
2411
+ });
2412
+ evalCommand.command("get").argument("<eval_run_id>", "Eval run ID").description("Get eval run details").option("--db-id <id>", "Database ID").action(async (evalRunId, _options, cmd) => {
2413
+ try {
2414
+ const opts = cmd.optsWithGlobals();
2415
+ const client = getClient(cmd);
2416
+ const result = await client.evals.get(evalRunId, { dbId: opts.dbId });
2417
+ const format = getOutputFormat(cmd);
2418
+ if (format === "json") {
2419
+ outputDetail(cmd, result, { labels: [], keys: [] });
2420
+ return;
2421
+ }
2422
+ const e = result;
2423
+ outputDetail(
2424
+ cmd,
2425
+ {
2426
+ id: e.id ?? "",
2427
+ name: e.name ?? "",
2428
+ eval_type: e.eval_type ?? "",
2429
+ agent_id: e.agent_id ?? "",
2430
+ input: e.input ?? "",
2431
+ output: e.output ?? "",
2432
+ expected_output: e.expected_output ?? "",
2433
+ score: e.score ?? "",
2434
+ created_at: e.created_at ?? ""
2435
+ },
2436
+ {
2437
+ labels: ["ID", "Name", "Eval Type", "Agent ID", "Input", "Output", "Expected Output", "Score", "Created At"],
2438
+ keys: ["id", "name", "eval_type", "agent_id", "input", "output", "expected_output", "score", "created_at"]
2439
+ }
2440
+ );
2441
+ } catch (err) {
2442
+ handleError(err, { resource: "Eval", url: getBaseUrl(cmd) });
2443
+ }
2444
+ });
2445
+ evalCommand.command("delete").description("Delete eval runs").requiredOption("--ids <ids>", "Comma-separated eval run IDs to delete (required)").option("--db-id <id>", "Database ID").action(async (_options, cmd) => {
2446
+ try {
2447
+ const opts = cmd.optsWithGlobals();
2448
+ const parsedIds = opts.ids.split(",").map((id) => id.trim());
2449
+ const client = getClient(cmd);
2450
+ await client.evals.delete({ ids: parsedIds, dbId: opts.dbId });
2451
+ writeSuccess("Eval runs deleted.");
2452
+ } catch (err) {
2453
+ handleError(err, { url: getBaseUrl(cmd) });
2454
+ }
2455
+ });
2456
+ }
2457
+ });
2458
+
2459
+ // src/commands/approvals.ts
2460
+ var approvals_exports = {};
2461
+ __export(approvals_exports, {
2462
+ approvalCommand: () => approvalCommand
2463
+ });
2464
+ import { Command as Command13 } from "commander";
2465
+ var approvalCommand;
2466
+ var init_approvals = __esm({
2467
+ "src/commands/approvals.ts"() {
2468
+ "use strict";
2469
+ init_client();
2470
+ init_errors();
2471
+ init_output();
2472
+ approvalCommand = new Command13("approval").description("Manage approvals");
2473
+ approvalCommand.command("list").description("List approvals").option("--status <status>", "Filter by status (e.g., pending, approved, rejected)").option("--agent-id <id>", "Filter by agent ID").option("--limit <n>", "Results per page", (v) => Number.parseInt(v, 10), 20).option("--page <n>", "Page number", (v) => Number.parseInt(v, 10), 1).action(async (_options, cmd) => {
2474
+ try {
2475
+ const opts = cmd.optsWithGlobals();
2476
+ const client = getClient(cmd);
2477
+ const result = await client.approvals.list({
2478
+ status: opts.status,
2479
+ agentId: opts.agentId,
2480
+ limit: opts.limit,
2481
+ page: opts.page
2482
+ });
2483
+ const r = result;
2484
+ const data = r.data ?? [];
2485
+ const meta = r.meta;
2486
+ const format = getOutputFormat(cmd);
2487
+ if (format === "json") {
2488
+ printJson({ data, meta });
2489
+ return;
2490
+ }
2491
+ outputList(
2492
+ cmd,
2493
+ data.map((a) => ({
2494
+ id: a.id ?? "",
2495
+ status: a.status ?? "",
2496
+ type: a.type ?? "",
2497
+ created_at: a.created_at ?? ""
2498
+ })),
2499
+ {
2500
+ columns: ["ID", "STATUS", "TYPE", "CREATED_AT"],
2501
+ keys: ["id", "status", "type", "created_at"],
2502
+ meta
2503
+ }
2504
+ );
2505
+ } catch (err) {
2506
+ handleError(err, { url: getBaseUrl(cmd) });
2507
+ }
2508
+ });
2509
+ approvalCommand.command("get").argument("<id>", "Approval ID").description("Get approval details").action(async (id, _options, cmd) => {
2510
+ try {
2511
+ const client = getClient(cmd);
2512
+ const result = await client.approvals.get(id);
2513
+ const format = getOutputFormat(cmd);
2514
+ if (format === "json") {
2515
+ outputDetail(cmd, result, { labels: [], keys: [] });
2516
+ return;
2517
+ }
2518
+ const a = result;
2519
+ outputDetail(
2520
+ cmd,
2521
+ {
2522
+ id: a.id ?? "",
2523
+ status: a.status ?? "",
2524
+ type: a.type ?? "",
2525
+ agent_id: a.agent_id ?? "",
2526
+ details: a.details ? JSON.stringify(a.details) : "",
2527
+ created_at: a.created_at ?? ""
2528
+ },
2529
+ {
2530
+ labels: ["ID", "Status", "Type", "Agent ID", "Details", "Created"],
2531
+ keys: ["id", "status", "type", "agent_id", "details", "created_at"]
2532
+ }
2533
+ );
2534
+ } catch (err) {
2535
+ handleError(err, { resource: "Approval", url: getBaseUrl(cmd) });
2536
+ }
2537
+ });
2538
+ approvalCommand.command("resolve").argument("<id>", "Approval ID").description("Resolve an approval").requiredOption("--status <status>", "Resolution status, e.g. approved, rejected (required)").option("--resolved-by <user>", "Who resolved the approval").option("--resolution-data <json>", "Additional resolution data as JSON").action(async (id, _options, cmd) => {
2539
+ try {
2540
+ const opts = cmd.optsWithGlobals();
2541
+ const client = getClient(cmd);
2542
+ let resolutionData;
2543
+ if (opts.resolutionData) {
2544
+ try {
2545
+ resolutionData = JSON.parse(opts.resolutionData);
2546
+ } catch {
2547
+ writeError("Invalid JSON for --resolution-data");
2548
+ process.exitCode = 1;
2549
+ return;
2550
+ }
2551
+ }
2552
+ const result = await client.approvals.resolve(id, {
2553
+ status: opts.status,
2554
+ resolvedBy: opts.resolvedBy,
2555
+ resolutionData
2556
+ });
2557
+ const format = getOutputFormat(cmd);
2558
+ if (format === "json") {
2559
+ printJson(result);
2560
+ return;
2561
+ }
2562
+ const a = result;
2563
+ outputDetail(
2564
+ cmd,
2565
+ {
2566
+ id: a.id ?? "",
2567
+ status: a.status ?? "",
2568
+ resolved_by: a.resolved_by ?? "",
2569
+ resolved_at: a.resolved_at ?? ""
2570
+ },
2571
+ {
2572
+ labels: ["ID", "Status", "Resolved By", "Resolved At"],
2573
+ keys: ["id", "status", "resolved_by", "resolved_at"]
2574
+ }
2575
+ );
2576
+ writeSuccess("Approval resolved.");
2577
+ } catch (err) {
2578
+ handleError(err, { resource: "Approval", url: getBaseUrl(cmd) });
2579
+ }
2580
+ });
2581
+ }
2582
+ });
2583
+
2584
+ // src/commands/auth.ts
2585
+ var auth_exports = {};
2586
+ __export(auth_exports, {
2587
+ authCommand: () => authCommand
2588
+ });
2589
+ import { Command as Command14 } from "commander";
2590
+ var authCommand, keyCommand, connectionCommand;
2591
+ var init_auth = __esm({
2592
+ "src/commands/auth.ts"() {
2593
+ "use strict";
2594
+ init_client();
2595
+ init_errors();
2596
+ init_output();
2597
+ authCommand = new Command14("auth").description("Authentication and connections");
2598
+ authCommand.command("me").description("Show current auth info").action(async (_options, cmd) => {
2599
+ try {
2600
+ const client = getClient(cmd);
2601
+ const result = await client.auth.me();
2602
+ const format = getOutputFormat(cmd);
2603
+ if (format === "json") {
2604
+ printJson(result);
2605
+ return;
2606
+ }
2607
+ const u = result;
2608
+ outputDetail(
2609
+ cmd,
2610
+ {
2611
+ id: u.id ?? "",
2612
+ email: u.email ?? "",
2613
+ role: u.role ?? "",
2614
+ name: u.name ?? ""
2615
+ },
2616
+ {
2617
+ labels: ["ID", "Email", "Role", "Name"],
2618
+ keys: ["id", "email", "role", "name"]
2619
+ }
2620
+ );
2621
+ } catch (err) {
2622
+ handleError(err, { url: getBaseUrl(cmd) });
2623
+ }
2624
+ });
2625
+ keyCommand = new Command14("key").description("Manage API keys");
2626
+ keyCommand.command("list").description("List API keys").action(async (_options, cmd) => {
2627
+ try {
2628
+ const client = getClient(cmd);
2629
+ const result = await client.auth.keys.list();
2630
+ const data = Array.isArray(result) ? result : [];
2631
+ const format = getOutputFormat(cmd);
2632
+ if (format === "json") {
2633
+ printJson(data);
2634
+ return;
2635
+ }
2636
+ outputList(
2637
+ cmd,
2638
+ data.map((k) => ({
2639
+ id: k.id ?? "",
2640
+ name: k.name ?? "",
2641
+ created_at: k.created_at ?? "",
2642
+ expires_at: k.expires_at ?? ""
2643
+ })),
2644
+ {
2645
+ columns: ["ID", "NAME", "CREATED_AT", "EXPIRES_AT"],
2646
+ keys: ["id", "name", "created_at", "expires_at"]
2647
+ }
2648
+ );
2649
+ } catch (err) {
2650
+ handleError(err, { url: getBaseUrl(cmd) });
2651
+ }
2652
+ });
2653
+ keyCommand.command("create").description("Create a new API key").requiredOption("--name <name>", "Key name (required)").option("--scopes <scopes>", "Comma-separated scopes").option("--expires-at <date>", "Expiration date (ISO 8601)").action(async (_options, cmd) => {
2654
+ try {
2655
+ const opts = cmd.optsWithGlobals();
2656
+ const client = getClient(cmd);
2657
+ const result = await client.auth.keys.create({
2658
+ name: opts.name,
2659
+ scopes: opts.scopes ? opts.scopes.split(",") : void 0,
2660
+ expiresAt: opts.expiresAt
2661
+ });
2662
+ const format = getOutputFormat(cmd);
2663
+ const k = result;
2664
+ if (format === "json") {
2665
+ printJson(result);
2666
+ } else {
2667
+ outputDetail(
2668
+ cmd,
2669
+ {
2670
+ id: k.id ?? "",
2671
+ name: k.name ?? "",
2672
+ key: k.key ?? "",
2673
+ created_at: k.created_at ?? ""
2674
+ },
2675
+ {
2676
+ labels: ["ID", "Name", "Key (save this!)", "Created"],
2677
+ keys: ["id", "name", "key", "created_at"]
2678
+ }
2679
+ );
2680
+ writeWarning("This key will not be shown again.");
2681
+ }
2682
+ } catch (err) {
2683
+ handleError(err, { url: getBaseUrl(cmd) });
2684
+ }
2685
+ });
2686
+ keyCommand.command("get").argument("<key_id>", "Key ID").description("Get API key details").action(async (keyId, _options, cmd) => {
2687
+ try {
2688
+ const client = getClient(cmd);
2689
+ const result = await client.auth.keys.get(keyId);
2690
+ const format = getOutputFormat(cmd);
2691
+ if (format === "json") {
2692
+ printJson(result);
2693
+ return;
2694
+ }
2695
+ const k = result;
2696
+ outputDetail(
2697
+ cmd,
2698
+ {
2699
+ id: k.id ?? "",
2700
+ name: k.name ?? "",
2701
+ created_at: k.created_at ?? "",
2702
+ expires_at: k.expires_at ?? ""
2703
+ },
2704
+ {
2705
+ labels: ["ID", "Name", "Created", "Expires"],
2706
+ keys: ["id", "name", "created_at", "expires_at"]
2707
+ }
2708
+ );
2709
+ } catch (err) {
2710
+ handleError(err, { url: getBaseUrl(cmd) });
2711
+ }
2712
+ });
2713
+ keyCommand.command("revoke").argument("<key_id>", "Key ID").description("Revoke an API key").action(async (keyId, _options, cmd) => {
2714
+ try {
2715
+ const client = getClient(cmd);
2716
+ await client.auth.keys.revoke(keyId);
2717
+ writeSuccess(`API key ${keyId} revoked.`);
2718
+ } catch (err) {
2719
+ handleError(err, { url: getBaseUrl(cmd) });
2720
+ }
2721
+ });
2722
+ keyCommand.command("rotate").argument("<key_id>", "Key ID").description("Rotate an API key").action(async (keyId, _options, cmd) => {
2723
+ try {
2724
+ const client = getClient(cmd);
2725
+ const result = await client.auth.keys.rotate(keyId);
2726
+ const format = getOutputFormat(cmd);
2727
+ const k = result;
2728
+ if (format === "json") {
2729
+ printJson(result);
2730
+ } else {
2731
+ outputDetail(
2732
+ cmd,
2733
+ {
2734
+ id: k.id ?? "",
2735
+ name: k.name ?? "",
2736
+ key: k.key ?? "",
2737
+ created_at: k.created_at ?? ""
2738
+ },
2739
+ {
2740
+ labels: ["ID", "Name", "New Key (save this!)", "Created"],
2741
+ keys: ["id", "name", "key", "created_at"]
2742
+ }
2743
+ );
2744
+ writeWarning("This key will not be shown again.");
2745
+ }
2746
+ } catch (err) {
2747
+ handleError(err, { url: getBaseUrl(cmd) });
2748
+ }
2749
+ });
2750
+ authCommand.addCommand(keyCommand);
2751
+ connectionCommand = new Command14("connection").description("Manage connections");
2752
+ connectionCommand.command("list").description("List connections").action(async (_options, cmd) => {
2753
+ try {
2754
+ const client = getClient(cmd);
2755
+ const result = await client.auth.connections.list();
2756
+ const data = Array.isArray(result) ? result : [];
2757
+ const format = getOutputFormat(cmd);
2758
+ if (format === "json") {
2759
+ printJson(data);
2760
+ return;
2761
+ }
2762
+ outputList(
2763
+ cmd,
2764
+ data.map((c) => ({
2765
+ id: c.id ?? "",
2766
+ name: c.name ?? "",
2767
+ host: c.host ?? "",
2768
+ port: c.port ?? "",
2769
+ is_default: c.is_default ?? ""
2770
+ })),
2771
+ {
2772
+ columns: ["ID", "NAME", "HOST", "PORT", "IS_DEFAULT"],
2773
+ keys: ["id", "name", "host", "port", "is_default"]
2774
+ }
2775
+ );
2776
+ } catch (err) {
2777
+ handleError(err, { url: getBaseUrl(cmd) });
2778
+ }
2779
+ });
2780
+ connectionCommand.command("create").description("Create a new connection").requiredOption("--name <name>", "Connection name (required)").requiredOption("--host <host>", "Hostname or IP (required)").requiredOption("--port <port>", "Port number (required)").requiredOption("--user <user>", "Username (required)").requiredOption("--password <password>", "Password (required)").option("--is-default", "Set as default connection").action(async (_options, cmd) => {
2781
+ try {
2782
+ const opts = cmd.optsWithGlobals();
2783
+ const client = getClient(cmd);
2784
+ const result = await client.auth.connections.create({
2785
+ name: opts.name,
2786
+ host: opts.host,
2787
+ port: Number.parseInt(opts.port, 10),
2788
+ user: opts.user,
2789
+ password: opts.password,
2790
+ isDefault: opts.isDefault ?? false
2791
+ });
2792
+ const format = getOutputFormat(cmd);
2793
+ if (format === "json") {
2794
+ printJson(result);
2795
+ return;
2796
+ }
2797
+ const c = result;
2798
+ outputDetail(
2799
+ cmd,
2800
+ {
2801
+ id: c.id ?? "",
2802
+ name: c.name ?? "",
2803
+ host: c.host ?? "",
2804
+ port: c.port ?? "",
2805
+ is_default: c.is_default ?? ""
2806
+ },
2807
+ {
2808
+ labels: ["ID", "Name", "Host", "Port", "Default"],
2809
+ keys: ["id", "name", "host", "port", "is_default"]
2810
+ }
2811
+ );
2812
+ writeSuccess("Connection created.");
2813
+ } catch (err) {
2814
+ handleError(err, { url: getBaseUrl(cmd) });
2815
+ }
2816
+ });
2817
+ connectionCommand.command("get").argument("<conn_id>", "Connection ID").description("Get connection details").action(async (connId, _options, cmd) => {
2818
+ try {
2819
+ const client = getClient(cmd);
2820
+ const result = await client.auth.connections.get(connId);
2821
+ const format = getOutputFormat(cmd);
2822
+ if (format === "json") {
2823
+ printJson(result);
2824
+ return;
2825
+ }
2826
+ const c = result;
2827
+ outputDetail(
2828
+ cmd,
2829
+ {
2830
+ id: c.id ?? "",
2831
+ name: c.name ?? "",
2832
+ host: c.host ?? "",
2833
+ port: c.port ?? "",
2834
+ user: c.user ?? "",
2835
+ is_default: c.is_default ?? ""
2836
+ },
2837
+ {
2838
+ labels: ["ID", "Name", "Host", "Port", "User", "Default"],
2839
+ keys: ["id", "name", "host", "port", "user", "is_default"]
2840
+ }
2841
+ );
2842
+ } catch (err) {
2843
+ handleError(err, { url: getBaseUrl(cmd) });
2844
+ }
2845
+ });
2846
+ connectionCommand.command("update").argument("<conn_id>", "Connection ID").description("Update a connection").option("--name <name>", "Connection name").option("--host <host>", "Hostname or IP").option("--port <port>", "Port number").option("--user <user>", "Username").option("--password <password>", "Password").option("--is-default", "Set as default connection").action(async (connId, _options, cmd) => {
2847
+ try {
2848
+ const opts = cmd.optsWithGlobals();
2849
+ const client = getClient(cmd);
2850
+ const updateOpts = {};
2851
+ if (opts.name) updateOpts.name = opts.name;
2852
+ if (opts.host) updateOpts.host = opts.host;
2853
+ if (opts.port) updateOpts.port = Number.parseInt(opts.port, 10);
2854
+ if (opts.user) updateOpts.user = opts.user;
2855
+ if (opts.password) updateOpts.password = opts.password;
2856
+ if (opts.isDefault !== void 0) updateOpts.isDefault = opts.isDefault;
2857
+ const result = await client.auth.connections.update(connId, updateOpts);
2858
+ const format = getOutputFormat(cmd);
2859
+ if (format === "json") {
2860
+ printJson(result);
2861
+ return;
2862
+ }
2863
+ const c = result;
2864
+ outputDetail(
2865
+ cmd,
2866
+ {
2867
+ id: c.id ?? "",
2868
+ name: c.name ?? "",
2869
+ host: c.host ?? "",
2870
+ port: c.port ?? "",
2871
+ is_default: c.is_default ?? ""
2872
+ },
2873
+ {
2874
+ labels: ["ID", "Name", "Host", "Port", "Default"],
2875
+ keys: ["id", "name", "host", "port", "is_default"]
2876
+ }
2877
+ );
2878
+ writeSuccess("Connection updated.");
2879
+ } catch (err) {
2880
+ handleError(err, { url: getBaseUrl(cmd) });
2881
+ }
2882
+ });
2883
+ connectionCommand.command("delete").argument("<conn_id>", "Connection ID").description("Delete a connection").action(async (connId, _options, cmd) => {
2884
+ try {
2885
+ const client = getClient(cmd);
2886
+ await client.auth.connections.delete(connId);
2887
+ writeSuccess(`Connection ${connId} deleted.`);
2888
+ } catch (err) {
2889
+ handleError(err, { url: getBaseUrl(cmd) });
2890
+ }
2891
+ });
2892
+ connectionCommand.command("test").argument("<conn_id>", "Connection ID").description("Test a connection").action(async (connId, _options, cmd) => {
2893
+ try {
2894
+ const client = getClient(cmd);
2895
+ const result = await client.auth.connections.test(connId);
2896
+ const format = getOutputFormat(cmd);
2897
+ if (format === "json") {
2898
+ printJson(result);
2899
+ return;
2900
+ }
2901
+ const t = result;
2902
+ outputDetail(
2903
+ cmd,
2904
+ {
2905
+ success: t.success ?? "",
2906
+ message: t.message ?? ""
2907
+ },
2908
+ {
2909
+ labels: ["Success", "Message"],
2910
+ keys: ["success", "message"]
2911
+ }
2912
+ );
2913
+ } catch (err) {
2914
+ handleError(err, { url: getBaseUrl(cmd) });
2915
+ }
2916
+ });
2917
+ authCommand.addCommand(connectionCommand);
2918
+ }
2919
+ });
2920
+
2921
+ // src/commands/components.ts
2922
+ var components_exports = {};
2923
+ __export(components_exports, {
2924
+ componentCommand: () => componentCommand
2925
+ });
2926
+ import { Command as Command15 } from "commander";
2927
+ var componentCommand, configSubCommand;
2928
+ var init_components = __esm({
2929
+ "src/commands/components.ts"() {
2930
+ "use strict";
2931
+ init_client();
2932
+ init_errors();
2933
+ init_output();
2934
+ componentCommand = new Command15("component").description("Manage components");
2935
+ componentCommand.command("list").description("List components").option("--type <type>", "Filter by type (agent, team, workflow)").option("--limit <n>", "Results per page", (v) => Number.parseInt(v, 10), 20).option("--page <n>", "Page number", (v) => Number.parseInt(v, 10), 1).action(async (_options, cmd) => {
2936
+ try {
2937
+ const opts = cmd.optsWithGlobals();
2938
+ const client = getClient(cmd);
2939
+ const result = await client.components.list({
2940
+ componentType: opts.type,
2941
+ page: opts.page,
2942
+ limit: opts.limit
2943
+ });
2944
+ const r = result;
2945
+ const data = r.data ?? [];
2946
+ const meta = r.meta;
2947
+ const format = getOutputFormat(cmd);
2948
+ if (format === "json") {
2949
+ printJson({ data, meta });
2950
+ return;
2951
+ }
2952
+ outputList(
2953
+ cmd,
2954
+ data.map((c) => ({
2955
+ id: c.id ?? "",
2956
+ name: c.name ?? "",
2957
+ type: c.component_type ?? "",
2958
+ stage: c.stage ?? ""
2959
+ })),
2960
+ {
2961
+ columns: ["ID", "NAME", "TYPE", "STAGE"],
2962
+ keys: ["id", "name", "type", "stage"],
2963
+ meta
2964
+ }
2965
+ );
2966
+ } catch (err) {
2967
+ handleError(err, { url: getBaseUrl(cmd) });
2968
+ }
2969
+ });
2970
+ componentCommand.command("get").argument("<component_id>", "Component ID").description("Get component details").action(async (componentId, _options, cmd) => {
2971
+ try {
2972
+ const client = getClient(cmd);
2973
+ const result = await client.components.get(componentId);
2974
+ const format = getOutputFormat(cmd);
2975
+ if (format === "json") {
2976
+ outputDetail(cmd, result, { labels: [], keys: [] });
2977
+ return;
2978
+ }
2979
+ const c = result;
2980
+ outputDetail(
2981
+ cmd,
2982
+ {
2983
+ id: c.id ?? "",
2984
+ name: c.name ?? "",
2985
+ component_type: c.component_type ?? "",
2986
+ description: c.description ?? "",
2987
+ stage: c.stage ?? "",
2988
+ created_at: c.created_at ?? ""
2989
+ },
2990
+ {
2991
+ labels: ["ID", "Name", "Type", "Description", "Stage", "Created"],
2992
+ keys: ["id", "name", "component_type", "description", "stage", "created_at"]
2993
+ }
2994
+ );
2995
+ } catch (err) {
2996
+ handleError(err, { resource: "Component", url: getBaseUrl(cmd) });
2997
+ }
2998
+ });
2999
+ componentCommand.command("create").description("Create a component").requiredOption("--name <name>", "Component name (required)").requiredOption("--type <type>", "Component type: agent, team, workflow (required)").option("--description <desc>", "Component description").option("--config <json>", "Configuration as JSON").option("--stage <stage>", "Stage (draft, published)").action(async (_options, cmd) => {
3000
+ try {
3001
+ const opts = cmd.optsWithGlobals();
3002
+ const client = getClient(cmd);
3003
+ let config;
3004
+ if (opts.config) {
3005
+ try {
3006
+ config = JSON.parse(opts.config);
3007
+ } catch {
3008
+ writeError("Invalid JSON for --config");
3009
+ process.exitCode = 1;
3010
+ return;
3011
+ }
3012
+ }
3013
+ const result = await client.components.create({
3014
+ name: opts.name,
3015
+ componentType: opts.type,
3016
+ description: opts.description,
3017
+ config,
3018
+ stage: opts.stage
3019
+ });
3020
+ const format = getOutputFormat(cmd);
3021
+ if (format === "json") {
3022
+ printJson(result);
3023
+ return;
3024
+ }
3025
+ const c = result;
3026
+ outputDetail(
3027
+ cmd,
3028
+ {
3029
+ id: c.id ?? "",
3030
+ name: c.name ?? "",
3031
+ component_type: c.component_type ?? "",
3032
+ stage: c.stage ?? ""
3033
+ },
3034
+ {
3035
+ labels: ["ID", "Name", "Type", "Stage"],
3036
+ keys: ["id", "name", "component_type", "stage"]
3037
+ }
3038
+ );
3039
+ writeSuccess("Component created.");
3040
+ } catch (err) {
3041
+ handleError(err, { url: getBaseUrl(cmd) });
3042
+ }
3043
+ });
3044
+ componentCommand.command("update").argument("<component_id>", "Component ID").description("Update a component").option("--name <name>", "Component name").option("--type <type>", "Component type").option("--description <desc>", "Component description").option("--config <json>", "Configuration as JSON").option("--stage <stage>", "Stage (draft, published)").action(async (componentId, _options, cmd) => {
3045
+ try {
3046
+ const opts = cmd.optsWithGlobals();
3047
+ const client = getClient(cmd);
3048
+ let config;
3049
+ if (opts.config) {
3050
+ try {
3051
+ config = JSON.parse(opts.config);
3052
+ } catch {
3053
+ writeError("Invalid JSON for --config");
3054
+ process.exitCode = 1;
3055
+ return;
3056
+ }
3057
+ }
3058
+ const updateOpts = {};
3059
+ if (opts.name) updateOpts.name = opts.name;
3060
+ if (opts.type) updateOpts.componentType = opts.type;
3061
+ if (opts.description) updateOpts.description = opts.description;
3062
+ if (config) updateOpts.config = config;
3063
+ if (opts.stage) updateOpts.stage = opts.stage;
3064
+ const result = await client.components.update(componentId, updateOpts);
3065
+ const format = getOutputFormat(cmd);
3066
+ if (format === "json") {
3067
+ printJson(result);
3068
+ return;
3069
+ }
3070
+ const c = result;
3071
+ outputDetail(
3072
+ cmd,
3073
+ {
3074
+ id: c.id ?? "",
3075
+ name: c.name ?? "",
3076
+ component_type: c.component_type ?? "",
3077
+ stage: c.stage ?? ""
3078
+ },
3079
+ {
3080
+ labels: ["ID", "Name", "Type", "Stage"],
3081
+ keys: ["id", "name", "component_type", "stage"]
3082
+ }
3083
+ );
3084
+ writeSuccess("Component updated.");
3085
+ } catch (err) {
3086
+ handleError(err, { resource: "Component", url: getBaseUrl(cmd) });
3087
+ }
3088
+ });
3089
+ componentCommand.command("delete").argument("<component_id>", "Component ID").description("Delete a component").action(async (componentId, _options, cmd) => {
3090
+ try {
3091
+ const client = getClient(cmd);
3092
+ await client.components.delete(componentId);
3093
+ writeSuccess(`Component ${componentId} deleted.`);
3094
+ } catch (err) {
3095
+ handleError(err, { resource: "Component", url: getBaseUrl(cmd) });
3096
+ }
3097
+ });
3098
+ configSubCommand = new Command15("config").description("Manage component configurations");
3099
+ configSubCommand.command("list").argument("<component_id>", "Component ID").description("List component configurations").action(async (componentId, _options, cmd) => {
3100
+ try {
3101
+ const client = getClient(cmd);
3102
+ const result = await client.components.listConfigs(componentId);
3103
+ const data = Array.isArray(result) ? result : [];
3104
+ const format = getOutputFormat(cmd);
3105
+ if (format === "json") {
3106
+ printJson(data);
3107
+ return;
3108
+ }
3109
+ outputList(
3110
+ cmd,
3111
+ data.map((c) => ({
3112
+ version: c.version ?? "",
3113
+ status: c.status ?? "",
3114
+ created_at: c.created_at ?? ""
3115
+ })),
3116
+ {
3117
+ columns: ["VERSION", "STATUS", "CREATED_AT"],
3118
+ keys: ["version", "status", "created_at"]
3119
+ }
3120
+ );
3121
+ } catch (err) {
3122
+ handleError(err, { resource: "Component", url: getBaseUrl(cmd) });
3123
+ }
3124
+ });
3125
+ configSubCommand.command("create").argument("<component_id>", "Component ID").description("Create a component configuration").requiredOption("--config <json>", "Configuration as JSON (required)").action(async (componentId, _options, cmd) => {
3126
+ try {
3127
+ const opts = cmd.optsWithGlobals();
3128
+ const client = getClient(cmd);
3129
+ let config;
3130
+ try {
3131
+ config = JSON.parse(opts.config);
3132
+ } catch {
3133
+ writeError("Invalid JSON for --config");
3134
+ process.exitCode = 1;
3135
+ return;
3136
+ }
3137
+ const result = await client.components.createConfig(componentId, { config });
3138
+ const format = getOutputFormat(cmd);
3139
+ if (format === "json") {
3140
+ printJson(result);
3141
+ return;
3142
+ }
3143
+ const c = result;
3144
+ outputDetail(
3145
+ cmd,
3146
+ {
3147
+ version: c.version ?? "",
3148
+ status: c.status ?? "",
3149
+ created_at: c.created_at ?? ""
3150
+ },
3151
+ {
3152
+ labels: ["Version", "Status", "Created"],
3153
+ keys: ["version", "status", "created_at"]
3154
+ }
3155
+ );
3156
+ writeSuccess("Configuration created.");
3157
+ } catch (err) {
3158
+ handleError(err, { resource: "Component", url: getBaseUrl(cmd) });
3159
+ }
3160
+ });
3161
+ configSubCommand.command("update").argument("<component_id>", "Component ID").argument("<version>", "Configuration version number").description("Update a draft component configuration").requiredOption("--config <json>", "Configuration as JSON (required)").action(async (componentId, version, _options, cmd) => {
3162
+ try {
3163
+ const opts = cmd.optsWithGlobals();
3164
+ const client = getClient(cmd);
3165
+ let config;
3166
+ try {
3167
+ config = JSON.parse(opts.config);
3168
+ } catch {
3169
+ writeError("Invalid JSON for --config");
3170
+ process.exitCode = 1;
3171
+ return;
3172
+ }
3173
+ const result = await client.components.updateDraftConfig(componentId, Number.parseInt(version, 10), { config });
3174
+ const format = getOutputFormat(cmd);
3175
+ if (format === "json") {
3176
+ printJson(result);
3177
+ return;
3178
+ }
3179
+ const c = result;
3180
+ outputDetail(
3181
+ cmd,
3182
+ {
3183
+ version: c.version ?? "",
3184
+ status: c.status ?? ""
3185
+ },
3186
+ {
3187
+ labels: ["Version", "Status"],
3188
+ keys: ["version", "status"]
3189
+ }
3190
+ );
3191
+ writeSuccess("Configuration updated.");
3192
+ } catch (err) {
3193
+ handleError(err, { resource: "Component", url: getBaseUrl(cmd) });
3194
+ }
3195
+ });
3196
+ configSubCommand.command("delete").argument("<component_id>", "Component ID").argument("<version>", "Configuration version number").description("Delete a component configuration version").action(async (componentId, version, _options, cmd) => {
3197
+ try {
3198
+ const client = getClient(cmd);
3199
+ await client.components.deleteConfigVersion(componentId, Number.parseInt(version, 10));
3200
+ writeSuccess(`Configuration version ${version} deleted.`);
3201
+ } catch (err) {
3202
+ handleError(err, { url: getBaseUrl(cmd) });
3203
+ }
3204
+ });
3205
+ componentCommand.addCommand(configSubCommand);
3206
+ }
3207
+ });
3208
+
3209
+ // src/commands/schedules.ts
3210
+ var schedules_exports = {};
3211
+ __export(schedules_exports, {
3212
+ scheduleCommand: () => scheduleCommand
3213
+ });
3214
+ import { Command as Command16 } from "commander";
3215
+ var scheduleCommand;
3216
+ var init_schedules = __esm({
3217
+ "src/commands/schedules.ts"() {
3218
+ "use strict";
3219
+ init_client();
3220
+ init_errors();
3221
+ init_output();
3222
+ scheduleCommand = new Command16("schedule").description("Manage schedules");
3223
+ scheduleCommand.command("list").description("List schedules").option("--enabled", "Filter to enabled schedules only").option("--limit <n>", "Results per page", (v) => Number.parseInt(v, 10), 20).option("--page <n>", "Page number", (v) => Number.parseInt(v, 10), 1).action(async (_options, cmd) => {
3224
+ try {
3225
+ const opts = cmd.optsWithGlobals();
3226
+ const client = getClient(cmd);
3227
+ const result = await client.schedules.list({
3228
+ enabled: opts.enabled,
3229
+ limit: opts.limit,
3230
+ page: opts.page
3231
+ });
3232
+ const r = result;
3233
+ const data = r.data ?? [];
3234
+ const meta = r.meta;
3235
+ const format = getOutputFormat(cmd);
3236
+ if (format === "json") {
3237
+ printJson({ data, meta });
3238
+ return;
3239
+ }
3240
+ outputList(
3241
+ cmd,
3242
+ data.map((s) => ({
3243
+ id: s.id ?? "",
3244
+ name: s.name ?? "",
3245
+ cron: s.cron_expr ?? "",
3246
+ enabled: s.enabled ?? "",
3247
+ next_run: s.next_run ?? ""
3248
+ })),
3249
+ {
3250
+ columns: ["ID", "NAME", "CRON", "ENABLED", "NEXT_RUN"],
3251
+ keys: ["id", "name", "cron", "enabled", "next_run"],
3252
+ meta
3253
+ }
3254
+ );
3255
+ } catch (err) {
3256
+ handleError(err, { url: getBaseUrl(cmd) });
3257
+ }
3258
+ });
3259
+ scheduleCommand.command("get").argument("<id>", "Schedule ID").description("Get schedule details").action(async (id, _options, cmd) => {
3260
+ try {
3261
+ const client = getClient(cmd);
3262
+ const result = await client.schedules.get(id);
3263
+ const format = getOutputFormat(cmd);
3264
+ if (format === "json") {
3265
+ outputDetail(cmd, result, { labels: [], keys: [] });
3266
+ return;
3267
+ }
3268
+ const s = result;
3269
+ outputDetail(
3270
+ cmd,
3271
+ {
3272
+ id: s.id ?? "",
3273
+ name: s.name ?? "",
3274
+ cron_expr: s.cron_expr ?? "",
3275
+ endpoint: s.endpoint ?? "",
3276
+ method: s.method ?? "",
3277
+ enabled: s.enabled ?? "",
3278
+ timezone: s.timezone ?? "",
3279
+ next_run: s.next_run ?? "",
3280
+ created_at: s.created_at ?? ""
3281
+ },
3282
+ {
3283
+ labels: ["ID", "Name", "Cron", "Endpoint", "Method", "Enabled", "Timezone", "Next Run", "Created"],
3284
+ keys: ["id", "name", "cron_expr", "endpoint", "method", "enabled", "timezone", "next_run", "created_at"]
3285
+ }
3286
+ );
3287
+ } catch (err) {
3288
+ handleError(err, { resource: "Schedule", url: getBaseUrl(cmd) });
3289
+ }
3290
+ });
3291
+ scheduleCommand.command("create").description("Create a schedule").requiredOption("--name <name>", "Schedule name (required)").requiredOption("--cron <expr>", "Cron expression (required)").requiredOption("--endpoint <url>", "Endpoint URL (required)").requiredOption("--method <method>", "HTTP method: GET, POST, etc. (required)").option("--description <desc>", "Schedule description").option("--payload <json>", "Request payload as JSON").option("--timezone <tz>", "Timezone (default: UTC)").option("--timeout-seconds <n>", "Timeout in seconds", (v) => Number.parseInt(v, 10)).option("--max-retries <n>", "Maximum retries", (v) => Number.parseInt(v, 10)).option("--retry-delay-seconds <n>", "Retry delay in seconds", (v) => Number.parseInt(v, 10)).action(async (_options, cmd) => {
3292
+ try {
3293
+ const opts = cmd.optsWithGlobals();
3294
+ const client = getClient(cmd);
3295
+ let payload;
3296
+ if (opts.payload) {
3297
+ try {
3298
+ payload = JSON.parse(opts.payload);
3299
+ } catch {
3300
+ writeError("Invalid JSON for --payload");
3301
+ process.exitCode = 1;
3302
+ return;
3303
+ }
3304
+ }
3305
+ const result = await client.schedules.create({
3306
+ name: opts.name,
3307
+ cronExpr: opts.cron,
3308
+ endpoint: opts.endpoint,
3309
+ method: opts.method,
3310
+ description: opts.description,
3311
+ payload,
3312
+ timezone: opts.timezone,
3313
+ timeoutSeconds: opts.timeoutSeconds,
3314
+ maxRetries: opts.maxRetries,
3315
+ retryDelaySeconds: opts.retryDelaySeconds
3316
+ });
3317
+ const format = getOutputFormat(cmd);
3318
+ if (format === "json") {
3319
+ printJson(result);
3320
+ return;
3321
+ }
3322
+ const s = result;
3323
+ outputDetail(
3324
+ cmd,
3325
+ {
3326
+ id: s.id ?? "",
3327
+ name: s.name ?? "",
3328
+ cron_expr: s.cron_expr ?? "",
3329
+ enabled: s.enabled ?? ""
3330
+ },
3331
+ {
3332
+ labels: ["ID", "Name", "Cron", "Enabled"],
3333
+ keys: ["id", "name", "cron_expr", "enabled"]
3334
+ }
3335
+ );
3336
+ writeSuccess("Schedule created.");
3337
+ } catch (err) {
3338
+ handleError(err, { url: getBaseUrl(cmd) });
3339
+ }
3340
+ });
3341
+ scheduleCommand.command("update").argument("<id>", "Schedule ID").description("Update a schedule").option("--name <name>", "Schedule name").option("--cron <expr>", "Cron expression").option("--endpoint <url>", "Endpoint URL").option("--method <method>", "HTTP method").option("--description <desc>", "Schedule description").option("--payload <json>", "Request payload as JSON").option("--timezone <tz>", "Timezone").option("--timeout-seconds <n>", "Timeout in seconds", (v) => Number.parseInt(v, 10)).option("--max-retries <n>", "Maximum retries", (v) => Number.parseInt(v, 10)).option("--retry-delay-seconds <n>", "Retry delay in seconds", (v) => Number.parseInt(v, 10)).action(async (id, _options, cmd) => {
3342
+ try {
3343
+ const opts = cmd.optsWithGlobals();
3344
+ const client = getClient(cmd);
3345
+ let payload;
3346
+ if (opts.payload) {
3347
+ try {
3348
+ payload = JSON.parse(opts.payload);
3349
+ } catch {
3350
+ writeError("Invalid JSON for --payload");
3351
+ process.exitCode = 1;
3352
+ return;
3353
+ }
3354
+ }
3355
+ const updateOpts = {};
3356
+ if (opts.name) updateOpts.name = opts.name;
3357
+ if (opts.cron) updateOpts.cronExpr = opts.cron;
3358
+ if (opts.endpoint) updateOpts.endpoint = opts.endpoint;
3359
+ if (opts.method) updateOpts.method = opts.method;
3360
+ if (opts.description) updateOpts.description = opts.description;
3361
+ if (payload) updateOpts.payload = payload;
3362
+ if (opts.timezone) updateOpts.timezone = opts.timezone;
3363
+ if (opts.timeoutSeconds) updateOpts.timeoutSeconds = opts.timeoutSeconds;
3364
+ if (opts.maxRetries) updateOpts.maxRetries = opts.maxRetries;
3365
+ if (opts.retryDelaySeconds) updateOpts.retryDelaySeconds = opts.retryDelaySeconds;
3366
+ const result = await client.schedules.update(id, updateOpts);
3367
+ const format = getOutputFormat(cmd);
3368
+ if (format === "json") {
3369
+ printJson(result);
3370
+ return;
3371
+ }
3372
+ const s = result;
3373
+ outputDetail(
3374
+ cmd,
3375
+ {
3376
+ id: s.id ?? "",
3377
+ name: s.name ?? "",
3378
+ cron_expr: s.cron_expr ?? "",
3379
+ enabled: s.enabled ?? ""
3380
+ },
3381
+ {
3382
+ labels: ["ID", "Name", "Cron", "Enabled"],
3383
+ keys: ["id", "name", "cron_expr", "enabled"]
3384
+ }
3385
+ );
3386
+ writeSuccess("Schedule updated.");
3387
+ } catch (err) {
3388
+ handleError(err, { resource: "Schedule", url: getBaseUrl(cmd) });
3389
+ }
3390
+ });
3391
+ scheduleCommand.command("delete").argument("<id>", "Schedule ID").description("Delete a schedule").action(async (id, _options, cmd) => {
3392
+ try {
3393
+ const client = getClient(cmd);
3394
+ await client.schedules.delete(id);
3395
+ writeSuccess(`Schedule ${id} deleted.`);
3396
+ } catch (err) {
3397
+ handleError(err, { resource: "Schedule", url: getBaseUrl(cmd) });
3398
+ }
3399
+ });
3400
+ scheduleCommand.command("pause").argument("<id>", "Schedule ID").description("Pause a schedule").action(async (id, _options, cmd) => {
3401
+ try {
3402
+ const client = getClient(cmd);
3403
+ await client.schedules.disable(id);
3404
+ writeSuccess("Schedule paused.");
3405
+ } catch (err) {
3406
+ handleError(err, { resource: "Schedule", url: getBaseUrl(cmd) });
3407
+ }
3408
+ });
3409
+ scheduleCommand.command("resume").argument("<id>", "Schedule ID").description("Resume a schedule").action(async (id, _options, cmd) => {
3410
+ try {
3411
+ const client = getClient(cmd);
3412
+ await client.schedules.enable(id);
3413
+ writeSuccess("Schedule resumed.");
3414
+ } catch (err) {
3415
+ handleError(err, { resource: "Schedule", url: getBaseUrl(cmd) });
3416
+ }
3417
+ });
3418
+ scheduleCommand.command("runs").argument("<id>", "Schedule ID").description("List schedule run history").action(async (id, _options, cmd) => {
3419
+ try {
3420
+ const client = getClient(cmd);
3421
+ const result = await client.schedules.listRuns(id);
3422
+ const r = result;
3423
+ const data = r.data ?? (Array.isArray(result) ? result : []);
3424
+ const meta = r.meta;
3425
+ const format = getOutputFormat(cmd);
3426
+ if (format === "json") {
3427
+ printJson(meta ? { data, meta } : data);
3428
+ return;
3429
+ }
3430
+ outputList(
3431
+ cmd,
3432
+ data.map((run) => ({
3433
+ id: run.id ?? "",
3434
+ status: run.status ?? "",
3435
+ started_at: run.started_at ?? "",
3436
+ completed_at: run.completed_at ?? ""
3437
+ })),
3438
+ {
3439
+ columns: ["ID", "STATUS", "STARTED_AT", "COMPLETED_AT"],
3440
+ keys: ["id", "status", "started_at", "completed_at"],
3441
+ meta
3442
+ }
3443
+ );
3444
+ } catch (err) {
3445
+ handleError(err, { resource: "Schedule", url: getBaseUrl(cmd) });
3446
+ }
3447
+ });
3448
+ }
3449
+ });
3450
+
3451
+ // src/commands/database.ts
3452
+ var database_exports = {};
3453
+ __export(database_exports, {
3454
+ databaseCommand: () => databaseCommand
3455
+ });
3456
+ import { Command as Command17 } from "commander";
3457
+ var databaseCommand;
3458
+ var init_database = __esm({
3459
+ "src/commands/database.ts"() {
3460
+ "use strict";
3461
+ init_client();
3462
+ init_errors();
3463
+ init_output();
3464
+ databaseCommand = new Command17("database").description("Manage databases");
3465
+ databaseCommand.command("migrate").argument("<db_id>", "Database ID").description("Run database migrations").option("--target-version <version>", "Target migration version").action(async (dbId, _options, cmd) => {
3466
+ try {
3467
+ const opts = cmd.optsWithGlobals();
3468
+ const client = getClient(cmd);
3469
+ await client.database.migrate(dbId, {
3470
+ targetVersion: opts.targetVersion
3471
+ });
3472
+ writeSuccess("Database migration complete.");
3473
+ } catch (err) {
3474
+ handleError(err, { url: getBaseUrl(cmd) });
3475
+ }
3476
+ });
3477
+ }
3478
+ });
3479
+
3480
+ // src/commands/registry.ts
3481
+ var registry_exports = {};
3482
+ __export(registry_exports, {
3483
+ registryCommand: () => registryCommand
3484
+ });
3485
+ import { Command as Command18 } from "commander";
3486
+ var registryCommand;
3487
+ var init_registry = __esm({
3488
+ "src/commands/registry.ts"() {
3489
+ "use strict";
3490
+ init_client();
3491
+ init_errors();
3492
+ init_output();
3493
+ registryCommand = new Command18("registry").description("Manage registry");
3494
+ registryCommand.command("list").description("List registry items").option("--type <type>", "Filter by resource type").option("--name <name>", "Filter by name").option("--limit <n>", "Results per page", (v) => Number.parseInt(v, 10), 20).option("--page <n>", "Page number", (v) => Number.parseInt(v, 10), 1).action(async (_options, cmd) => {
3495
+ try {
3496
+ const opts = cmd.optsWithGlobals();
3497
+ const client = getClient(cmd);
3498
+ const result = await client.registry.list({
3499
+ resourceType: opts.type,
3500
+ name: opts.name,
3501
+ limit: opts.limit,
3502
+ page: opts.page
3503
+ });
3504
+ const r = result;
3505
+ const data = r.data ?? (Array.isArray(result) ? result : []);
3506
+ const meta = r.meta;
3507
+ const format = getOutputFormat(cmd);
3508
+ if (format === "json") {
3509
+ printJson(meta ? { data, meta } : data);
3510
+ return;
3511
+ }
3512
+ outputList(
3513
+ cmd,
3514
+ data.map((item) => ({
3515
+ id: item.id ?? "",
3516
+ name: item.name ?? "",
3517
+ type: item.resource_type ?? item.type ?? "",
3518
+ version: item.version ?? ""
3519
+ })),
3520
+ {
3521
+ columns: ["ID", "NAME", "TYPE", "VERSION"],
3522
+ keys: ["id", "name", "type", "version"],
3523
+ meta
3524
+ }
3525
+ );
3526
+ } catch (err) {
3527
+ handleError(err, { url: getBaseUrl(cmd) });
3528
+ }
3529
+ });
3530
+ }
3531
+ });
3532
+
3533
+ // src/bin/agno.ts
3534
+ init_errors();
3535
+ init_output();
3536
+ import { Command as Command19, Option } from "commander";
3537
+ process.stdout.on("error", (err) => {
3538
+ if (err.code === "EPIPE") process.exit(0);
3539
+ throw err;
3540
+ });
3541
+ process.stderr.on("error", (err) => {
3542
+ if (err.code === "EPIPE") process.exit(0);
3543
+ throw err;
3544
+ });
3545
+ var VERSION = "0.1.0";
3546
+ var program = new Command19("agno-cli").version(VERSION, "-V, --version").description("CLI for interacting with AgentOS instances").option("-c, --context <name>", "Override active context").option("--url <url>", "Override base URL").option("--key <key>", "Override security key").option("--timeout <seconds>", "Override timeout", Number.parseFloat).option("--no-color", "Disable color output").option("--json [fields]", "Output JSON with optional field selection (e.g., --json id,name)").addOption(new Option("-o, --output <format>", "Output format").choices(["json", "table"]));
3547
+ program.hook("preAction", (thisCommand) => {
3548
+ handleNoColorFlag(thisCommand);
3549
+ const globals = thisCommand.optsWithGlobals();
3550
+ if (globals.output === "table" && globals.json !== void 0) {
3551
+ process.stderr.write("Error: --output table and --json cannot be used together.\n");
3552
+ process.exit(1);
3553
+ }
3554
+ });
3555
+ program.addHelpText(
3556
+ "after",
3557
+ `
3558
+ Examples:
3559
+ $ agno-cli config init --url http://localhost:7777
3560
+ $ agno-cli config show
3561
+ $ agno-cli agent list --output json
3562
+ $ agno-cli agent run my-agent "Hello" --stream
3563
+ `
3564
+ );
3565
+ var { configCommand: configCommand2 } = await Promise.resolve().then(() => (init_config2(), config_exports));
3566
+ program.addCommand(configCommand2);
3567
+ var { statusCommand: statusCommand2 } = await Promise.resolve().then(() => (init_status(), status_exports));
3568
+ program.addCommand(statusCommand2);
3569
+ var { agentCommand: agentCommand2 } = await Promise.resolve().then(() => (init_agents(), agents_exports));
3570
+ program.addCommand(agentCommand2);
3571
+ var { teamCommand: teamCommand2 } = await Promise.resolve().then(() => (init_teams(), teams_exports));
3572
+ program.addCommand(teamCommand2);
3573
+ var { workflowCommand: workflowCommand2 } = await Promise.resolve().then(() => (init_workflows(), workflows_exports));
3574
+ program.addCommand(workflowCommand2);
3575
+ var { modelCommand: modelCommand2 } = await Promise.resolve().then(() => (init_models(), models_exports));
3576
+ program.addCommand(modelCommand2);
3577
+ var { metricsCommand: metricsCommand2 } = await Promise.resolve().then(() => (init_metrics(), metrics_exports));
3578
+ program.addCommand(metricsCommand2);
3579
+ var { sessionCommand: sessionCommand2 } = await Promise.resolve().then(() => (init_sessions(), sessions_exports));
3580
+ program.addCommand(sessionCommand2);
3581
+ var { memoryCommand: memoryCommand2 } = await Promise.resolve().then(() => (init_memories(), memories_exports));
3582
+ program.addCommand(memoryCommand2);
3583
+ var { knowledgeCommand: knowledgeCommand2 } = await Promise.resolve().then(() => (init_knowledge(), knowledge_exports));
3584
+ program.addCommand(knowledgeCommand2);
3585
+ var { traceCommand: traceCommand2 } = await Promise.resolve().then(() => (init_traces(), traces_exports));
3586
+ program.addCommand(traceCommand2);
3587
+ var { evalCommand: evalCommand2 } = await Promise.resolve().then(() => (init_evals(), evals_exports));
3588
+ program.addCommand(evalCommand2);
3589
+ var { approvalCommand: approvalCommand2 } = await Promise.resolve().then(() => (init_approvals(), approvals_exports));
3590
+ program.addCommand(approvalCommand2);
3591
+ var { authCommand: authCommand2 } = await Promise.resolve().then(() => (init_auth(), auth_exports));
3592
+ program.addCommand(authCommand2);
3593
+ var { componentCommand: componentCommand2 } = await Promise.resolve().then(() => (init_components(), components_exports));
3594
+ program.addCommand(componentCommand2);
3595
+ var { scheduleCommand: scheduleCommand2 } = await Promise.resolve().then(() => (init_schedules(), schedules_exports));
3596
+ program.addCommand(scheduleCommand2);
3597
+ var { databaseCommand: databaseCommand2 } = await Promise.resolve().then(() => (init_database(), database_exports));
3598
+ program.addCommand(databaseCommand2);
3599
+ var { registryCommand: registryCommand2 } = await Promise.resolve().then(() => (init_registry(), registry_exports));
3600
+ program.addCommand(registryCommand2);
3601
+ program.action(() => {
3602
+ program.outputHelp();
3603
+ });
3604
+ program.exitOverride();
3605
+ try {
3606
+ await program.parseAsync(process.argv);
3607
+ } catch (err) {
3608
+ if (err instanceof Error && "exitCode" in err) {
3609
+ const cmdErr = err;
3610
+ if (cmdErr.exitCode !== 0) {
3611
+ handleError(err);
3612
+ }
3613
+ } else {
3614
+ handleError(err);
3615
+ }
3616
+ }