@alva-ai/toolkit 0.15.0 → 0.15.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -9480,6 +9480,9 @@ var init_lint2 = __esm({
9480
9480
  }
9481
9481
  });
9482
9482
 
9483
+ // src/cli/index.ts
9484
+ import * as crypto3 from "crypto";
9485
+
9483
9486
  // src/error.ts
9484
9487
  var AlvaError = class extends Error {
9485
9488
  code;
@@ -9879,6 +9882,19 @@ var FeedResource = class {
9879
9882
  this.client = client;
9880
9883
  }
9881
9884
  client;
9885
+ /**
9886
+ * List feeds owned by the caller. Backed by GET /api/v1/feed.
9887
+ */
9888
+ async list(params = {}) {
9889
+ this.client._requireAuth();
9890
+ return this.client._request("GET", "/api/v1/feed", {
9891
+ query: {
9892
+ limit: params.limit,
9893
+ cursor: params.cursor,
9894
+ status: params.status
9895
+ }
9896
+ });
9897
+ }
9882
9898
  /**
9883
9899
  * Stop a feed's producer cronjob. This pauses future scheduled runs while
9884
9900
  * preserving the feed and its existing data.
@@ -9930,6 +9946,46 @@ function requireFeedID(id) {
9930
9946
  return id;
9931
9947
  }
9932
9948
 
9949
+ // src/resources/automation.ts
9950
+ var AutomationResource = class {
9951
+ constructor(client) {
9952
+ this.client = client;
9953
+ }
9954
+ client;
9955
+ list(params = {}) {
9956
+ return this.client.feed.list(params);
9957
+ }
9958
+ /**
9959
+ * Inspect one automation. Backed by GET /api/v1/automation/:id.
9960
+ */
9961
+ async inspect(params) {
9962
+ this.client._requireAuth();
9963
+ const id = requireAutomationID(params.id);
9964
+ return this.client._request(
9965
+ "GET",
9966
+ `/api/v1/automation/${encodeURIComponent(String(id))}`
9967
+ );
9968
+ }
9969
+ stop(params) {
9970
+ return this.client.feed.stop(params);
9971
+ }
9972
+ resume(params) {
9973
+ return this.client.feed.resume(params);
9974
+ }
9975
+ delete(params) {
9976
+ return this.client.feed.delete(params);
9977
+ }
9978
+ publish(params) {
9979
+ return this.client.release.feed(params);
9980
+ }
9981
+ };
9982
+ function requireAutomationID(id) {
9983
+ if (!Number.isInteger(id) || id <= 0) {
9984
+ throw new Error("automation id must be a positive integer");
9985
+ }
9986
+ return id;
9987
+ }
9988
+
9933
9989
  // src/resources/playbooks.ts
9934
9990
  var PLAYBOOK_VISIBILITIES = [
9935
9991
  "public",
@@ -11844,6 +11900,44 @@ var SubscriptionsResource = class {
11844
11900
  }
11845
11901
  };
11846
11902
 
11903
+ // src/resources/alerts.ts
11904
+ var AlertsResource = class {
11905
+ constructor(client) {
11906
+ this.client = client;
11907
+ }
11908
+ client;
11909
+ list(params = {}) {
11910
+ return this.client.subscriptions.list(params);
11911
+ }
11912
+ enableAutomation(params) {
11913
+ return this.client.subscriptions.subscribeFeed(params);
11914
+ }
11915
+ disableAutomation(params) {
11916
+ return this.client.subscriptions.unsubscribeFeed(params);
11917
+ }
11918
+ enablePlaybook(params) {
11919
+ return this.client.subscriptions.subscribePlaybook(params);
11920
+ }
11921
+ disablePlaybook(params) {
11922
+ return this.client.subscriptions.unsubscribePlaybook(params);
11923
+ }
11924
+ disableBatch(params) {
11925
+ return this.client.subscriptions.unsubscribeBatch(params);
11926
+ }
11927
+ historyAutomation(params) {
11928
+ return this.client.notifications.listFeed(params);
11929
+ }
11930
+ historyPlaybook(params) {
11931
+ return this.client.notifications.listPlaybook(params);
11932
+ }
11933
+ preferences() {
11934
+ return this.client.notificationPreferences.list();
11935
+ }
11936
+ updatePreference(params) {
11937
+ return this.client.notificationPreferences.update(params);
11938
+ }
11939
+ };
11940
+
11847
11941
  // src/resources/channelGroupSubscriptions.ts
11848
11942
  var ChannelGroupSubscriptionsResource = class {
11849
11943
  constructor(client) {
@@ -12276,6 +12370,7 @@ var AlvaClient = class {
12276
12370
  _serviceAccount;
12277
12371
  _release;
12278
12372
  _feed;
12373
+ _automation;
12279
12374
  _playbooks;
12280
12375
  _secrets;
12281
12376
  _sdk;
@@ -12291,6 +12386,7 @@ var AlvaClient = class {
12291
12386
  _notifications;
12292
12387
  _notificationPreferences;
12293
12388
  _subscriptions;
12389
+ _alerts;
12294
12390
  _channelGroupSubscriptions;
12295
12391
  _feedback;
12296
12392
  _functions;
@@ -12325,6 +12421,9 @@ var AlvaClient = class {
12325
12421
  get feed() {
12326
12422
  return this._feed ??= new FeedResource(this);
12327
12423
  }
12424
+ get automation() {
12425
+ return this._automation ??= new AutomationResource(this);
12426
+ }
12328
12427
  get playbooks() {
12329
12428
  return this._playbooks ??= new PlaybooksResource(this);
12330
12429
  }
@@ -12370,6 +12469,9 @@ var AlvaClient = class {
12370
12469
  get subscriptions() {
12371
12470
  return this._subscriptions ??= new SubscriptionsResource(this);
12372
12471
  }
12472
+ get alerts() {
12473
+ return this._alerts ??= new AlertsResource(this);
12474
+ }
12373
12475
  get channelGroupSubscriptions() {
12374
12476
  return this._channelGroupSubscriptions ??= new ChannelGroupSubscriptionsResource(this);
12375
12477
  }
@@ -13361,12 +13463,90 @@ function discoveryItemLines(item, webOrigin) {
13361
13463
  return out;
13362
13464
  }
13363
13465
 
13466
+ // src/cli/productFormat.ts
13467
+ function formatAutomationList(result) {
13468
+ const automations = result.feeds ?? [];
13469
+ if (automations.length === 0) return "(no automations)\n";
13470
+ const lines = [`${automations.length} automation(s):`, ""];
13471
+ for (const automation of automations) {
13472
+ const status = automation.status ? ` [${automation.status}]` : "";
13473
+ lines.push(`\u2022 ${automation.name || "(unnamed)"}${status}`);
13474
+ lines.push(` id: ${automation.id}`);
13475
+ if (automation.cron_expression) {
13476
+ lines.push(` schedule: ${automation.cron_expression}`);
13477
+ }
13478
+ lines.push(` runs: ${automation.total_runs ?? 0}`);
13479
+ lines.push(` used by: ${automation.used_by_total ?? 0}`);
13480
+ lines.push("");
13481
+ }
13482
+ if (result.has_more) {
13483
+ lines.push("(more results \u2014 pass --cursor <next_cursor> to page)");
13484
+ if (result.next_cursor) lines.push(`next_cursor: ${result.next_cursor}`);
13485
+ lines.push("");
13486
+ }
13487
+ return lines.join("\n");
13488
+ }
13489
+ function formatAutomationDetail(result) {
13490
+ const status = result.status ? ` [${result.status}]` : "";
13491
+ const lines = [
13492
+ `${result.name || "(unnamed)"}${status}`,
13493
+ ` id: ${result.id}`
13494
+ ];
13495
+ if (result.feed_id && result.feed_id !== result.id) {
13496
+ lines.push(` feed id: ${result.feed_id}`);
13497
+ }
13498
+ if (result.cron_expression) {
13499
+ lines.push(` schedule: ${result.cron_expression}`);
13500
+ }
13501
+ lines.push(` runs: ${result.total_runs ?? 0}`);
13502
+ lines.push(` flow id: ${result.flow_id ?? "(none)"}`);
13503
+ lines.push(` flow config path: ${result.flow_config_path ?? "(none)"}`);
13504
+ return `${lines.join("\n")}
13505
+ `;
13506
+ }
13507
+ function formatAlertList(result) {
13508
+ const alerts = result.items ?? [];
13509
+ if (alerts.length === 0) return "(no alerts)\n";
13510
+ const lines = [`${alerts.length} alert(s):`, ""];
13511
+ for (const alert of alerts) {
13512
+ const targetType = alert.target?.type ?? "UNSPECIFIED";
13513
+ const status = alert.target_status ? ` [${alert.target_status}]` : "";
13514
+ lines.push(`\u2022 ${alertTitle(alert)}${status}`);
13515
+ lines.push(` target: ${targetType} ${alert.target?.id ?? ""}`.trimEnd());
13516
+ if (alert.kind) lines.push(` kind: ${alert.kind}`);
13517
+ if (alert.feed_status)
13518
+ lines.push(` automation status: ${alert.feed_status}`);
13519
+ if (alert.used_by_total !== void 0) {
13520
+ lines.push(` used by: ${alert.used_by_total}`);
13521
+ }
13522
+ if (alert.last_pushed_at_ms) {
13523
+ lines.push(
13524
+ ` last pushed: ${new Date(alert.last_pushed_at_ms).toISOString()}`
13525
+ );
13526
+ }
13527
+ lines.push("");
13528
+ }
13529
+ if (result.next_cursor) {
13530
+ lines.push("(more results \u2014 pass --cursor <next_cursor> to page)");
13531
+ lines.push(`next_cursor: ${result.next_cursor}`);
13532
+ lines.push("");
13533
+ }
13534
+ return lines.join("\n");
13535
+ }
13536
+ function alertTitle(alert) {
13537
+ if (alert.playbook) {
13538
+ return `${alert.playbook.owner_username}/${alert.playbook.name}`;
13539
+ }
13540
+ if (alert.feed_name) return alert.feed_name;
13541
+ return alert.target?.id ? `target ${alert.target.id}` : "(unknown target)";
13542
+ }
13543
+
13364
13544
  // src/cli/index.ts
13365
13545
  import * as fs2 from "fs";
13366
13546
  import * as os2 from "os";
13367
13547
  import * as fsPromises2 from "fs/promises";
13368
13548
  import { Agent, setGlobalDispatcher } from "undici";
13369
- var CLI_VERSION = true ? "0.15.0" : "dev";
13549
+ var CLI_VERSION = true ? "0.15.1-beta.0" : "dev";
13370
13550
  var DEFAULT_RUN_TIMEOUT_MS = 6e5;
13371
13551
  var RUN_TIMEOUT_ENV = "ALVA_RUN_TIMEOUT_MS";
13372
13552
  var configuredRunFetchTimeoutMs;
@@ -13399,7 +13579,9 @@ Commands:
13399
13579
  service-account Restricted run-as identities (create, list, delete, grant, revoke)
13400
13580
  release Feed and playbook releases (feed, playbook-draft, playbook)
13401
13581
  lint Design-system lint (playbook)
13402
- feed Feed lifecycle management (delete)
13582
+ automation Automation management (list, inspect, publish, stop, resume, delete)
13583
+ alert Alert management (list, enable, disable, history, preferences, enable-session-completed, disable-session-completed)
13584
+ feed Legacy automation alias (list, stop, resume, delete)
13403
13585
  playbooks Playbook discovery (trending, get, list) and visibility
13404
13586
  functions Playbook UDF function management (register, list, delete, invoke, allowance)
13405
13587
  credits Credit wallet and self-scoped usage history (wallet, items)
@@ -13411,7 +13593,7 @@ Commands:
13411
13593
  notification-history Notification delivery history (list-playbook, list-feed)
13412
13594
  notification-preferences Notification preferences (list, enable-session-completed, disable-session-completed)
13413
13595
  feedback Submit user-confirmed Alva platform feedback (submit)
13414
- subscriptions Follows + push alerts (subscribe-playbook, unsubscribe-playbook, subscribe-feed, unsubscribe-feed, unsubscribe, list, follows)
13596
+ subscriptions Legacy alert/follow operations (subscribe-playbook, subscribe-feed, list, follows)
13415
13597
  channel Channel group operations (group-subscriptions context, list, subscribe, unsubscribe)
13416
13598
  remix Save playbook remix lineage
13417
13599
  portfolio Connected-account portfolio (accounts, summary, activities)
@@ -13759,19 +13941,108 @@ Examples:
13759
13941
  --cron "0 */4 * * *" --run-as-service-account 90123
13760
13942
  alva service-account revoke --id 90123 --path '~/feeds/x/v1/' --permission read
13761
13943
  alva service-account delete --id 90123`,
13944
+ automation: `Usage: alva automation <subcommand> [options]
13945
+
13946
+ Manage automations. This is the product-facing surface for what older CLI
13947
+ commands called "feeds"; ids are currently the same underlying feed ids.
13948
+
13949
+ Subcommands:
13950
+ list List automations owned by the caller
13951
+ inspect Inspect one automation and show its flow config path when available
13952
+ publish Publish/register an automation after deploying its cronjob
13953
+ stop Stop an automation's producer cronjob
13954
+ resume Resume a stopped automation's producer cronjob
13955
+ delete Soft-delete an automation
13956
+
13957
+ List flags:
13958
+ --limit <n> Max results per page (default 50, max 100 server-side)
13959
+ --cursor <token> Pagination cursor from previous response
13960
+ --status <s> active | paused | all (default: active)
13961
+ --json Print raw JSON instead of a human-readable summary
13962
+
13963
+ Publish flags:
13964
+ --name <name> Automation name, unique per user (required)
13965
+ --version <version> Semantic version, e.g. "1.0.0" (required)
13966
+ --cronjob-id <id> ID of the backing cronjob (required)
13967
+ --view-json <json> View configuration JSON
13968
+ --description <text> Automation description
13969
+ --changelog <text> Per-major changelog summary
13970
+ --agent-type <type> Agent kind that produces this automation, e.g. "alpi"
13971
+
13972
+ Lifecycle flags:
13973
+ --id <automation_id> Numeric automation id (required for inspect/stop/resume/delete)
13974
+
13975
+ Examples:
13976
+ alva automation list
13977
+ alva automation list --status all --limit 20
13978
+ alva automation inspect --id 42
13979
+ alva automation publish --name btc-ema --version 1.0.0 --cronjob-id 42
13980
+ alva automation stop --id 42
13981
+ alva automation resume --id 42
13982
+ alva automation delete --id 42`,
13983
+ alert: `Usage: alva alert <subcommand> [options]
13984
+
13985
+ Manage alerts. Alerts are personal notification opt-ins for automations or
13986
+ playbooks. Delivery history and global alert preferences live here too.
13987
+
13988
+ Subcommands:
13989
+ list List the caller's active alerts
13990
+ enable Enable an alert for an automation or playbook
13991
+ disable Disable alerts by automation/playbook name or id
13992
+ history List alert delivery history for an automation or playbook
13993
+ preferences List global alert preferences
13994
+ enable-session-completed
13995
+ disable-session-completed
13996
+
13997
+ Target flags:
13998
+ --automation <owner/name> Automation target
13999
+ --playbook <owner/name> Playbook target
14000
+
14001
+ Disable-by-id flags:
14002
+ --automation-ids <a,b> Comma-separated automation target ids
14003
+ --playbook-ids <a,b> Comma-separated playbook target ids
14004
+ --feed-ids <a,b> Legacy alias for --automation-ids
14005
+
14006
+ List flags:
14007
+ --first <n> Optional page size
14008
+ --cursor <token> Optional cursor from previous response
14009
+ --json Print raw JSON instead of a human-readable summary
14010
+
14011
+ History flags:
14012
+ --channel <name> Optional delivery channel filter
14013
+ --status <status> Optional status filter (sent, failed, filtered)
14014
+ --since <seconds> Optional Unix seconds lower bound
14015
+
14016
+ Examples:
14017
+ alva alert list
14018
+ alva alert enable --automation alice/btc-ema
14019
+ alva alert disable --automation alice/btc-ema
14020
+ alva alert enable --playbook alice/btc-dashboard
14021
+ alva alert disable --automation-ids 13292
14022
+ alva alert disable --feed-ids 13292
14023
+ alva alert history --automation alice/btc-ema --status sent
14024
+ alva alert preferences`,
13762
14025
  feed: `Usage: alva feed <subcommand> [options]
13763
14026
 
13764
- Feed lifecycle management.
14027
+ Legacy alias for automation lifecycle management. Prefer "alva automation".
13765
14028
 
13766
14029
  Subcommands:
14030
+ list List feeds owned by the caller
13767
14031
  stop Stop a feed's producer cronjob
13768
14032
  resume Resume a stopped feed's producer cronjob
13769
14033
  delete Soft-delete a feed and all its active majors
13770
14034
 
13771
14035
  Flags:
13772
- --id <feed_id> Numeric feed id (required, positive integer)
14036
+ --id <feed_id> Numeric feed id (required for stop/resume/delete)
14037
+
14038
+ List flags:
14039
+ --limit <n> Max results per page (default 50, max 100 server-side)
14040
+ --cursor <token> Pagination cursor from previous response
14041
+ --status <s> active | paused | all (default: active)
13773
14042
 
13774
14043
  Notes:
14044
+ - list returns the raw JSON envelope. Prefer "alva automation list" for
14045
+ human-readable output or "alva automation list --json" for explicit JSON.
13775
14046
  - stop/resume affect future scheduled runs; existing feed data remains.
13776
14047
  - delete cascades to all active feed_majors in the same DB transaction.
13777
14048
  - delete removes producer cronjobs best-effort; the cronjob scavenger
@@ -13779,6 +14050,8 @@ Notes:
13779
14050
  - Auth: caller must own the feed (uid match), enforced by the backend.
13780
14051
 
13781
14052
  Examples:
14053
+ alva feed list
14054
+ alva feed list --status all --limit 20
13782
14055
  alva feed stop --id 42
13783
14056
  alva feed resume --id 42
13784
14057
  alva feed delete --id 42`,
@@ -14654,6 +14927,48 @@ function csvList(val) {
14654
14927
  const values = val.split(",").map((item) => item.trim()).filter(Boolean);
14655
14928
  return values.length > 0 ? values : void 0;
14656
14929
  }
14930
+ function parseOwnerNameTarget(value, flag, command) {
14931
+ const [username, ...rest] = value.split("/");
14932
+ const name = rest.join("/");
14933
+ if (!username || !name || name.includes("/")) {
14934
+ throw new CliUsageError(
14935
+ `--${flag} must be in owner/name form for '${command}', got '${value}'`,
14936
+ command.split(" ")[0]
14937
+ );
14938
+ }
14939
+ return { username, name };
14940
+ }
14941
+ function requireSingleAlertTarget(flags, command) {
14942
+ const automation = flags["automation"];
14943
+ const playbook = flags["playbook"];
14944
+ if ((automation ? 1 : 0) + (playbook ? 1 : 0) !== 1) {
14945
+ throw new CliUsageError(
14946
+ `Provide exactly one of --automation or --playbook for '${command}'`,
14947
+ "alert"
14948
+ );
14949
+ }
14950
+ if (automation) {
14951
+ return {
14952
+ kind: "automation",
14953
+ target: parseOwnerNameTarget(automation, "automation", command)
14954
+ };
14955
+ }
14956
+ return {
14957
+ kind: "playbook",
14958
+ target: parseOwnerNameTarget(playbook, "playbook", command)
14959
+ };
14960
+ }
14961
+ function feedReleaseParams(flags, command) {
14962
+ return {
14963
+ name: requireFlag(flags, "name", command),
14964
+ version: requireFlag(flags, "version", command),
14965
+ cronjob_id: requireNumericFlag(flags, "cronjob-id", command),
14966
+ view_json: jsonParse(flags["view-json"]),
14967
+ description: flags["description"],
14968
+ changelog: flags["changelog"],
14969
+ agent_type: flags["agent-type"]
14970
+ };
14971
+ }
14657
14972
  function trendingPlaybooksSort(val) {
14658
14973
  if (val === void 0) return void 0;
14659
14974
  const normalized = val.trim().toUpperCase();
@@ -14857,6 +15172,54 @@ function writeLocalFileBytes(path, data, command, flag, deps) {
14857
15172
  assertLocalFileAvailable(command, flag, deps);
14858
15173
  fs2.writeFileSync(path, data);
14859
15174
  }
15175
+ async function readAllStdin() {
15176
+ const chunks = [];
15177
+ for await (const chunk of process.stdin) {
15178
+ chunks.push(chunk);
15179
+ }
15180
+ return Buffer.concat(chunks).toString("utf8");
15181
+ }
15182
+ async function handleBroker(client, brokerArgv, deps) {
15183
+ let argv = brokerArgv;
15184
+ const isOrderPlace = brokerArgv[0] === "order" && brokerArgv[1] === "place";
15185
+ const hasFlag = (name) => brokerArgv.some((a) => a === name || a.startsWith(`${name}=`));
15186
+ const hasHandle = hasFlag("--intent-id") || hasFlag("--client-order-id");
15187
+ const isDryRun = hasFlag("--dry-run");
15188
+ if (isOrderPlace && !hasHandle && !isDryRun) {
15189
+ const intentId = crypto3.randomUUID();
15190
+ process.stderr.write(`alva broker: intent-id ${intentId}
15191
+ `);
15192
+ argv = [...brokerArgv, "--intent-id", intentId];
15193
+ }
15194
+ let stdin;
15195
+ if (hasFlag("--stdin")) {
15196
+ stdin = await readAllStdin();
15197
+ }
15198
+ let envelope;
15199
+ let exit = 2;
15200
+ try {
15201
+ const resp = await client._request("POST", "/api/v1/broker/invoke", {
15202
+ body: { argv, stdin }
15203
+ });
15204
+ envelope = resp.envelope;
15205
+ exit = resp.exit ?? 2;
15206
+ } catch (e) {
15207
+ const message = e instanceof Error ? e.message : String(e);
15208
+ envelope = {
15209
+ schemaVersion: 2,
15210
+ status: "error",
15211
+ reason: { code: "network", message }
15212
+ };
15213
+ exit = 2;
15214
+ }
15215
+ if (deps?.mode === "jagent") {
15216
+ return envelope;
15217
+ }
15218
+ await new Promise((resolve) => {
15219
+ process.stdout.write(JSON.stringify(envelope) + "\n", () => resolve());
15220
+ });
15221
+ process.exit(exit);
15222
+ }
14860
15223
  async function dispatch(client, args, meta, deps) {
14861
15224
  const group = args[0];
14862
15225
  if (!group || group === "--help" || group === "-h") {
@@ -14891,6 +15254,9 @@ async function dispatch(client, args, meta, deps) {
14891
15254
  }
14892
15255
  return result;
14893
15256
  }
15257
+ if (group === "broker") {
15258
+ return handleBroker(client, args.slice(1), deps);
15259
+ }
14894
15260
  const subcommand = args[1];
14895
15261
  const flags = parseFlags2(
14896
15262
  args.slice(
@@ -15160,6 +15526,12 @@ async function dispatch(client, args, meta, deps) {
15160
15526
  if (!subcommand)
15161
15527
  throw new CliUsageError("Missing subcommand for feed", "feed");
15162
15528
  switch (subcommand) {
15529
+ case "list":
15530
+ return client.feed.list({
15531
+ limit: num(flags["limit"]),
15532
+ cursor: flags["cursor"],
15533
+ status: flags["status"]
15534
+ });
15163
15535
  case "stop":
15164
15536
  return client.feed.stop({
15165
15537
  id: requireNumericFlag(flags, "id", "feed stop")
@@ -15179,6 +15551,50 @@ async function dispatch(client, args, meta, deps) {
15179
15551
  );
15180
15552
  }
15181
15553
  }
15554
+ case "automation": {
15555
+ if (!subcommand)
15556
+ throw new CliUsageError(
15557
+ "Missing subcommand for automation",
15558
+ "automation"
15559
+ );
15560
+ switch (subcommand) {
15561
+ case "list": {
15562
+ const result = await client.automation.list({
15563
+ limit: num(flags["limit"]),
15564
+ cursor: flags["cursor"],
15565
+ status: flags["status"]
15566
+ });
15567
+ return boolFlag(flags["json"]) ? result : formatAutomationList(result);
15568
+ }
15569
+ case "inspect": {
15570
+ const result = await client.automation.inspect({
15571
+ id: requireNumericFlag(flags, "id", "automation inspect")
15572
+ });
15573
+ return boolFlag(flags["json"]) ? result : formatAutomationDetail(result);
15574
+ }
15575
+ case "publish":
15576
+ return client.automation.publish(
15577
+ feedReleaseParams(flags, "automation publish")
15578
+ );
15579
+ case "stop":
15580
+ return client.automation.stop({
15581
+ id: requireNumericFlag(flags, "id", "automation stop")
15582
+ });
15583
+ case "resume":
15584
+ return client.automation.resume({
15585
+ id: requireNumericFlag(flags, "id", "automation resume")
15586
+ });
15587
+ case "delete":
15588
+ return client.automation.delete({
15589
+ id: requireNumericFlag(flags, "id", "automation delete")
15590
+ });
15591
+ default:
15592
+ throw new CliUsageError(
15593
+ `Unknown subcommand: automation ${subcommand}`,
15594
+ "automation"
15595
+ );
15596
+ }
15597
+ }
15182
15598
  case "credits": {
15183
15599
  if (!subcommand)
15184
15600
  throw new CliUsageError("Missing subcommand for credits", "credits");
@@ -15379,15 +15795,7 @@ async function dispatch(client, args, meta, deps) {
15379
15795
  throw new CliUsageError("Missing subcommand for release", "release");
15380
15796
  switch (subcommand) {
15381
15797
  case "feed":
15382
- return client.release.feed({
15383
- name: requireFlag(flags, "name", "release feed"),
15384
- version: requireFlag(flags, "version", "release feed"),
15385
- cronjob_id: requireNumericFlag(flags, "cronjob-id", "release feed"),
15386
- view_json: jsonParse(flags["view-json"]),
15387
- description: flags["description"],
15388
- changelog: flags["changelog"],
15389
- agent_type: flags["agent-type"]
15390
- });
15798
+ return client.release.feed(feedReleaseParams(flags, "release feed"));
15391
15799
  case "playbook-draft":
15392
15800
  return client.release.playbookDraft({
15393
15801
  name: requireFlag(flags, "name", "release playbook-draft"),
@@ -15826,6 +16234,65 @@ async function dispatch(client, args, meta, deps) {
15826
16234
  );
15827
16235
  }
15828
16236
  }
16237
+ case "alert": {
16238
+ if (!subcommand)
16239
+ throw new CliUsageError("Missing subcommand for alert", "alert");
16240
+ switch (subcommand) {
16241
+ case "list": {
16242
+ const result = await client.alerts.list({
16243
+ first: num(flags["first"]),
16244
+ cursor: flags["cursor"]
16245
+ });
16246
+ return boolFlag(flags["json"]) ? result : formatAlertList(result);
16247
+ }
16248
+ case "enable": {
16249
+ const target = requireSingleAlertTarget(flags, "alert enable");
16250
+ return target.kind === "automation" ? client.alerts.enableAutomation(target.target) : client.alerts.enablePlaybook(target.target);
16251
+ }
16252
+ case "disable": {
16253
+ const automationIds = csvList(flags["automation-ids"]) ?? csvList(flags["feed-ids"]) ?? [];
16254
+ const playbookIds = csvList(flags["playbook-ids"]) ?? [];
16255
+ if (automationIds.length > 0 || playbookIds.length > 0) {
16256
+ return client.alerts.disableBatch({
16257
+ playbookIds,
16258
+ feedIds: automationIds
16259
+ });
16260
+ }
16261
+ const target = requireSingleAlertTarget(flags, "alert disable");
16262
+ return target.kind === "automation" ? client.alerts.disableAutomation(target.target) : client.alerts.disablePlaybook(target.target);
16263
+ }
16264
+ case "history": {
16265
+ const target = requireSingleAlertTarget(flags, "alert history");
16266
+ const params = {
16267
+ username: target.target.username,
16268
+ name: target.target.name,
16269
+ channel: flags["channel"],
16270
+ status: flags["status"],
16271
+ since_time: num(flags["since"]),
16272
+ first: num(flags["first"]),
16273
+ cursor: flags["cursor"]
16274
+ };
16275
+ return target.kind === "automation" ? client.alerts.historyAutomation(params) : client.alerts.historyPlaybook(params);
16276
+ }
16277
+ case "preferences":
16278
+ return client.alerts.preferences();
16279
+ case "enable-session-completed":
16280
+ return client.alerts.updatePreference({
16281
+ key: "session_completed",
16282
+ enabled: true
16283
+ });
16284
+ case "disable-session-completed":
16285
+ return client.alerts.updatePreference({
16286
+ key: "session_completed",
16287
+ enabled: false
16288
+ });
16289
+ default:
16290
+ throw new CliUsageError(
16291
+ `Unknown subcommand: alert ${subcommand}`,
16292
+ "alert"
16293
+ );
16294
+ }
16295
+ }
15829
16296
  case "channel": {
15830
16297
  if (!subcommand || subcommand === "--help" || subcommand === "-h") {
15831
16298
  return { _help: true, text: COMMAND_HELP.channel };