@alva-ai/toolkit 0.14.1-beta.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;
@@ -9700,7 +9703,8 @@ var DeployResource = class {
9700
9703
  cron_expression: params.cron_expression,
9701
9704
  args: params.args,
9702
9705
  push_notify: params.push_notify,
9703
- max_heap_size_mb: params.max_heap_size_mb
9706
+ max_heap_size_mb: params.max_heap_size_mb,
9707
+ run_as_user_id: params.run_as_user_id
9704
9708
  }
9705
9709
  });
9706
9710
  }
@@ -9780,6 +9784,50 @@ var DeployResource = class {
9780
9784
  }
9781
9785
  };
9782
9786
 
9787
+ // src/resources/serviceAccount.ts
9788
+ var ServiceAccountResource = class {
9789
+ constructor(client) {
9790
+ this.client = client;
9791
+ }
9792
+ client;
9793
+ async create(params) {
9794
+ this.client._requireAuth();
9795
+ return this.client._request("POST", "/api/v1/service-account", {
9796
+ body: { display_name: params.display_name }
9797
+ });
9798
+ }
9799
+ async list() {
9800
+ this.client._requireAuth();
9801
+ return this.client._request(
9802
+ "GET",
9803
+ "/api/v1/service-accounts"
9804
+ );
9805
+ }
9806
+ async delete(params) {
9807
+ this.client._requireAuth();
9808
+ await this.client._request(
9809
+ "DELETE",
9810
+ `/api/v1/service-account/${params.id}`
9811
+ );
9812
+ }
9813
+ async grant(params) {
9814
+ this.client._requireAuth();
9815
+ await this.client._request(
9816
+ "POST",
9817
+ `/api/v1/service-account/${params.id}/grant`,
9818
+ { body: { path: params.path, permission: params.permission } }
9819
+ );
9820
+ }
9821
+ async revoke(params) {
9822
+ this.client._requireAuth();
9823
+ await this.client._request(
9824
+ "POST",
9825
+ `/api/v1/service-account/${params.id}/revoke`,
9826
+ { body: { path: params.path, permission: params.permission } }
9827
+ );
9828
+ }
9829
+ };
9830
+
9783
9831
  // src/resources/release.ts
9784
9832
  var ReleaseResource = class {
9785
9833
  constructor(client) {
@@ -9834,6 +9882,19 @@ var FeedResource = class {
9834
9882
  this.client = client;
9835
9883
  }
9836
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
+ }
9837
9898
  /**
9838
9899
  * Stop a feed's producer cronjob. This pauses future scheduled runs while
9839
9900
  * preserving the feed and its existing data.
@@ -9885,6 +9946,46 @@ function requireFeedID(id) {
9885
9946
  return id;
9886
9947
  }
9887
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
+
9888
9989
  // src/resources/playbooks.ts
9889
9990
  var PLAYBOOK_VISIBILITIES = [
9890
9991
  "public",
@@ -11799,6 +11900,44 @@ var SubscriptionsResource = class {
11799
11900
  }
11800
11901
  };
11801
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
+
11802
11941
  // src/resources/channelGroupSubscriptions.ts
11803
11942
  var ChannelGroupSubscriptionsResource = class {
11804
11943
  constructor(client) {
@@ -11890,7 +12029,8 @@ var FunctionsResource = class {
11890
12029
  function_name: params.function_name,
11891
12030
  entry_script_path: params.entry_script_path,
11892
12031
  params_schema: params.params_schema,
11893
- allow_charges: params.allow_charges
12032
+ allow_charges: params.allow_charges,
12033
+ run_as_user_id: params.run_as_user_id
11894
12034
  }
11895
12035
  });
11896
12036
  }
@@ -12227,8 +12367,10 @@ var AlvaClient = class {
12227
12367
  _fs;
12228
12368
  _run;
12229
12369
  _deploy;
12370
+ _serviceAccount;
12230
12371
  _release;
12231
12372
  _feed;
12373
+ _automation;
12232
12374
  _playbooks;
12233
12375
  _secrets;
12234
12376
  _sdk;
@@ -12244,6 +12386,7 @@ var AlvaClient = class {
12244
12386
  _notifications;
12245
12387
  _notificationPreferences;
12246
12388
  _subscriptions;
12389
+ _alerts;
12247
12390
  _channelGroupSubscriptions;
12248
12391
  _feedback;
12249
12392
  _functions;
@@ -12269,12 +12412,18 @@ var AlvaClient = class {
12269
12412
  get deploy() {
12270
12413
  return this._deploy ??= new DeployResource(this);
12271
12414
  }
12415
+ get serviceAccount() {
12416
+ return this._serviceAccount ??= new ServiceAccountResource(this);
12417
+ }
12272
12418
  get release() {
12273
12419
  return this._release ??= new ReleaseResource(this);
12274
12420
  }
12275
12421
  get feed() {
12276
12422
  return this._feed ??= new FeedResource(this);
12277
12423
  }
12424
+ get automation() {
12425
+ return this._automation ??= new AutomationResource(this);
12426
+ }
12278
12427
  get playbooks() {
12279
12428
  return this._playbooks ??= new PlaybooksResource(this);
12280
12429
  }
@@ -12320,6 +12469,9 @@ var AlvaClient = class {
12320
12469
  get subscriptions() {
12321
12470
  return this._subscriptions ??= new SubscriptionsResource(this);
12322
12471
  }
12472
+ get alerts() {
12473
+ return this._alerts ??= new AlertsResource(this);
12474
+ }
12323
12475
  get channelGroupSubscriptions() {
12324
12476
  return this._channelGroupSubscriptions ??= new ChannelGroupSubscriptionsResource(this);
12325
12477
  }
@@ -13311,12 +13463,90 @@ function discoveryItemLines(item, webOrigin) {
13311
13463
  return out;
13312
13464
  }
13313
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
+
13314
13544
  // src/cli/index.ts
13315
13545
  import * as fs2 from "fs";
13316
13546
  import * as os2 from "os";
13317
13547
  import * as fsPromises2 from "fs/promises";
13318
13548
  import { Agent, setGlobalDispatcher } from "undici";
13319
- var CLI_VERSION = true ? "0.14.1-beta.0" : "dev";
13549
+ var CLI_VERSION = true ? "0.15.1-beta.0" : "dev";
13320
13550
  var DEFAULT_RUN_TIMEOUT_MS = 6e5;
13321
13551
  var RUN_TIMEOUT_ENV = "ALVA_RUN_TIMEOUT_MS";
13322
13552
  var configuredRunFetchTimeoutMs;
@@ -13346,9 +13576,12 @@ Commands:
13346
13576
  fs Filesystem operations (read, write, stat, readdir, mkdir, remove, rename, copy, symlink, readlink, chmod, grant, revoke)
13347
13577
  run Execute code in the Alva runtime
13348
13578
  deploy Cronjob management (create, list, get, update, delete, pause, resume, runs, run-logs)
13579
+ service-account Restricted run-as identities (create, list, delete, grant, revoke)
13349
13580
  release Feed and playbook releases (feed, playbook-draft, playbook)
13350
13581
  lint Design-system lint (playbook)
13351
- 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)
13352
13585
  playbooks Playbook discovery (trending, get, list) and visibility
13353
13586
  functions Playbook UDF function management (register, list, delete, invoke, allowance)
13354
13587
  credits Credit wallet and self-scoped usage history (wallet, items)
@@ -13360,7 +13593,7 @@ Commands:
13360
13593
  notification-history Notification delivery history (list-playbook, list-feed)
13361
13594
  notification-preferences Notification preferences (list, enable-session-completed, disable-session-completed)
13362
13595
  feedback Submit user-confirmed Alva platform feedback (submit)
13363
- 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)
13364
13597
  channel Channel group operations (group-subscriptions context, list, subscribe, unsubscribe)
13365
13598
  remix Save playbook remix lineage
13366
13599
  portfolio Connected-account portfolio (accounts, summary, activities)
@@ -13631,6 +13864,11 @@ Create/Update flags:
13631
13864
  --push-notify Enable Telegram push notifications on completion
13632
13865
  --no-push-notify Disable push notifications
13633
13866
  --max-heap-size-mb <mb> Override per-cronjob V8 heap limit (1-2046, default uses server config)
13867
+ --run-as-service-account <id> Run the cronjob under a service-account identity
13868
+ (id from "alva service-account create"); restricts file
13869
+ access to the SA's grants. Omit on update \u21D2 unchanged (#602)
13870
+ --clear-run-as Clear run_as on update \u2014 run the cronjob as yourself
13871
+ again (mutually exclusive with --run-as-service-account)
13634
13872
 
13635
13873
  List flags:
13636
13874
  --limit <n> Max results per page (default: 20)
@@ -13681,19 +13919,130 @@ Build-time verify (fire once, then poll until your run completes):
13681
13919
  STATUS=$(echo "$ROW" | jq -r .status)
13682
13920
  [ "$STATUS" = completed ] || alva deploy run-logs --id 42 \\
13683
13921
  --run-id "$(echo "$ROW" | jq -r .id)"`,
13922
+ "service-account": `Usage: alva service-account <subcommand> [options]
13923
+
13924
+ Manage restricted run-as identities. A service account executes a UDF or
13925
+ cronjob with only the ALFS paths you grant it; billing/audit stay with you.
13926
+ Set the resulting id as --run-as-service-account on a UDF/cronjob. Opt-in:
13927
+ no run-as = run as owner. See the service-accounts skill reference.
13928
+
13929
+ Subcommands:
13930
+ create Create a service account (--name <label>)
13931
+ list List the service accounts you own
13932
+ delete Delete a service account (--id <id>); referencing jobs fail-close
13933
+ grant Grant an ALFS path (--id <id> --path <path> --permission read|write|import)
13934
+ revoke Revoke an ALFS path (--id <id> --path <path> --permission ...)
13935
+
13936
+ Examples:
13937
+ alva service-account create --name fintwit-bot
13938
+ alva service-account grant --id 90123 --path '~/feeds/x/v1/src/index.js' --permission read
13939
+ alva service-account grant --id 90123 --path '~/feeds/x/v1/' --permission read
13940
+ alva deploy create --name x-update --path '~/feeds/x/v1/src/index.js' \\
13941
+ --cron "0 */4 * * *" --run-as-service-account 90123
13942
+ alva service-account revoke --id 90123 --path '~/feeds/x/v1/' --permission read
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`,
13684
14025
  feed: `Usage: alva feed <subcommand> [options]
13685
14026
 
13686
- Feed lifecycle management.
14027
+ Legacy alias for automation lifecycle management. Prefer "alva automation".
13687
14028
 
13688
14029
  Subcommands:
14030
+ list List feeds owned by the caller
13689
14031
  stop Stop a feed's producer cronjob
13690
14032
  resume Resume a stopped feed's producer cronjob
13691
14033
  delete Soft-delete a feed and all its active majors
13692
14034
 
13693
14035
  Flags:
13694
- --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)
13695
14042
 
13696
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.
13697
14046
  - stop/resume affect future scheduled runs; existing feed data remains.
13698
14047
  - delete cascades to all active feed_majors in the same DB transaction.
13699
14048
  - delete removes producer cronjobs best-effort; the cronjob scavenger
@@ -13701,6 +14050,8 @@ Notes:
13701
14050
  - Auth: caller must own the feed (uid match), enforced by the backend.
13702
14051
 
13703
14052
  Examples:
14053
+ alva feed list
14054
+ alva feed list --status all --limit 20
13704
14055
  alva feed stop --id 42
13705
14056
  alva feed resume --id 42
13706
14057
  alva feed delete --id 42`,
@@ -13786,6 +14137,12 @@ Register flags:
13786
14137
  --params-schema-file <path> Read JSON Schema from a local file
13787
14138
  --allow-charges Allow this function to charge viewer allowance
13788
14139
  --no-allow-charges Explicitly register as no-charge
14140
+ --run-as-service-account <id> Run invocations under a service-account identity
14141
+ (id from "alva service-account create"); scopes file
14142
+ access to the SA's grants. Omit on re-register \u21D2
14143
+ unchanged (#602)
14144
+ --clear-run-as Clear run_as on re-register \u2014 run as the owner again
14145
+ (mutually exclusive with --run-as-service-account)
13789
14146
 
13790
14147
  List flags:
13791
14148
  --playbook-id <id> Numeric playbook id (required)
@@ -14370,6 +14727,7 @@ var BOOLEAN_FLAGS = /* @__PURE__ */ new Set([
14370
14727
  "execute-latest",
14371
14728
  "dry-run",
14372
14729
  "allow-charges",
14730
+ "clear-run-as",
14373
14731
  "json",
14374
14732
  "compress",
14375
14733
  "bypass-lint",
@@ -14473,6 +14831,45 @@ function optionalBoundedIntegerFlag(flags, name, command, min, max) {
14473
14831
  }
14474
14832
  return n;
14475
14833
  }
14834
+ function optionalServiceAccountIdFlag(flags, command) {
14835
+ const raw = flags["run-as-service-account"];
14836
+ if (raw === void 0) return void 0;
14837
+ if (!/^[1-9]\d*$/.test(raw)) {
14838
+ throw new CliUsageError(
14839
+ `--run-as-service-account must be a positive service-account id for '${command}', got '${raw}'`,
14840
+ command.split(" ")[0]
14841
+ );
14842
+ }
14843
+ return raw;
14844
+ }
14845
+ function resolveRunAsFlag(flags, command) {
14846
+ const clear = boolFlag(flags["clear-run-as"]) ?? false;
14847
+ const setID = optionalServiceAccountIdFlag(flags, command);
14848
+ if (clear && setID !== void 0) {
14849
+ throw new CliUsageError(
14850
+ `--clear-run-as and --run-as-service-account are mutually exclusive for '${command}'`,
14851
+ command.split(" ")[0]
14852
+ );
14853
+ }
14854
+ if (clear) return "0";
14855
+ return setID;
14856
+ }
14857
+ function requireServiceAccountIdFlag(flags, command) {
14858
+ const raw = flags["id"];
14859
+ if (raw === void 0 || raw === "") {
14860
+ throw new CliUsageError(
14861
+ `Missing required flag --id for '${command}'`,
14862
+ command.split(" ")[0]
14863
+ );
14864
+ }
14865
+ if (!/^[1-9]\d*$/.test(raw)) {
14866
+ throw new CliUsageError(
14867
+ `--id must be a positive service-account id for '${command}', got '${raw}'`,
14868
+ command.split(" ")[0]
14869
+ );
14870
+ }
14871
+ return raw;
14872
+ }
14476
14873
  function parsePositiveIntegerValue(val, label, command) {
14477
14874
  const n = Number(val);
14478
14875
  if (!/^[1-9]\d*$/.test(val) || !Number.isSafeInteger(n)) {
@@ -14530,6 +14927,48 @@ function csvList(val) {
14530
14927
  const values = val.split(",").map((item) => item.trim()).filter(Boolean);
14531
14928
  return values.length > 0 ? values : void 0;
14532
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
+ }
14533
14972
  function trendingPlaybooksSort(val) {
14534
14973
  if (val === void 0) return void 0;
14535
14974
  const normalized = val.trim().toUpperCase();
@@ -14733,6 +15172,54 @@ function writeLocalFileBytes(path, data, command, flag, deps) {
14733
15172
  assertLocalFileAvailable(command, flag, deps);
14734
15173
  fs2.writeFileSync(path, data);
14735
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
+ }
14736
15223
  async function dispatch(client, args, meta, deps) {
14737
15224
  const group = args[0];
14738
15225
  if (!group || group === "--help" || group === "-h") {
@@ -14767,6 +15254,9 @@ async function dispatch(client, args, meta, deps) {
14767
15254
  }
14768
15255
  return result;
14769
15256
  }
15257
+ if (group === "broker") {
15258
+ return handleBroker(client, args.slice(1), deps);
15259
+ }
14770
15260
  const subcommand = args[1];
14771
15261
  const flags = parseFlags2(
14772
15262
  args.slice(
@@ -14923,6 +15413,10 @@ async function dispatch(client, args, meta, deps) {
14923
15413
  "deploy create",
14924
15414
  1,
14925
15415
  2046
15416
+ ),
15417
+ run_as_user_id: optionalServiceAccountIdFlag(
15418
+ flags,
15419
+ "deploy create"
14926
15420
  )
14927
15421
  });
14928
15422
  case "list":
@@ -14947,7 +15441,8 @@ async function dispatch(client, args, meta, deps) {
14947
15441
  "deploy update",
14948
15442
  1,
14949
15443
  2046
14950
- )
15444
+ ),
15445
+ run_as_user_id: resolveRunAsFlag(flags, "deploy update")
14951
15446
  });
14952
15447
  case "delete":
14953
15448
  return client.deploy.delete({
@@ -14983,10 +15478,60 @@ async function dispatch(client, args, meta, deps) {
14983
15478
  );
14984
15479
  }
14985
15480
  }
15481
+ case "service-account": {
15482
+ if (!subcommand)
15483
+ throw new CliUsageError(
15484
+ "Missing subcommand for service-account",
15485
+ "service-account"
15486
+ );
15487
+ switch (subcommand) {
15488
+ case "create":
15489
+ return client.serviceAccount.create({
15490
+ display_name: requireFlag(flags, "name", "service-account create")
15491
+ });
15492
+ case "list":
15493
+ return client.serviceAccount.list();
15494
+ case "delete":
15495
+ return client.serviceAccount.delete({
15496
+ id: requireServiceAccountIdFlag(flags, "service-account delete")
15497
+ });
15498
+ case "grant":
15499
+ return client.serviceAccount.grant({
15500
+ id: requireServiceAccountIdFlag(flags, "service-account grant"),
15501
+ path: requireFlag(flags, "path", "service-account grant"),
15502
+ permission: requireFlag(
15503
+ flags,
15504
+ "permission",
15505
+ "service-account grant"
15506
+ )
15507
+ });
15508
+ case "revoke":
15509
+ return client.serviceAccount.revoke({
15510
+ id: requireServiceAccountIdFlag(flags, "service-account revoke"),
15511
+ path: requireFlag(flags, "path", "service-account revoke"),
15512
+ permission: requireFlag(
15513
+ flags,
15514
+ "permission",
15515
+ "service-account revoke"
15516
+ )
15517
+ });
15518
+ default:
15519
+ throw new CliUsageError(
15520
+ `Unknown subcommand: service-account ${subcommand}`,
15521
+ "service-account"
15522
+ );
15523
+ }
15524
+ }
14986
15525
  case "feed": {
14987
15526
  if (!subcommand)
14988
15527
  throw new CliUsageError("Missing subcommand for feed", "feed");
14989
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
+ });
14990
15535
  case "stop":
14991
15536
  return client.feed.stop({
14992
15537
  id: requireNumericFlag(flags, "id", "feed stop")
@@ -15006,6 +15551,50 @@ async function dispatch(client, args, meta, deps) {
15006
15551
  );
15007
15552
  }
15008
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
+ }
15009
15598
  case "credits": {
15010
15599
  if (!subcommand)
15011
15600
  throw new CliUsageError("Missing subcommand for credits", "credits");
@@ -15156,7 +15745,8 @@ async function dispatch(client, args, meta, deps) {
15156
15745
  "functions register",
15157
15746
  deps
15158
15747
  ),
15159
- allow_charges: boolFlag(flags["allow-charges"])
15748
+ allow_charges: boolFlag(flags["allow-charges"]),
15749
+ run_as_user_id: resolveRunAsFlag(flags, "functions register")
15160
15750
  });
15161
15751
  case "list":
15162
15752
  return client.functions.list({
@@ -15205,15 +15795,7 @@ async function dispatch(client, args, meta, deps) {
15205
15795
  throw new CliUsageError("Missing subcommand for release", "release");
15206
15796
  switch (subcommand) {
15207
15797
  case "feed":
15208
- return client.release.feed({
15209
- name: requireFlag(flags, "name", "release feed"),
15210
- version: requireFlag(flags, "version", "release feed"),
15211
- cronjob_id: requireNumericFlag(flags, "cronjob-id", "release feed"),
15212
- view_json: jsonParse(flags["view-json"]),
15213
- description: flags["description"],
15214
- changelog: flags["changelog"],
15215
- agent_type: flags["agent-type"]
15216
- });
15798
+ return client.release.feed(feedReleaseParams(flags, "release feed"));
15217
15799
  case "playbook-draft":
15218
15800
  return client.release.playbookDraft({
15219
15801
  name: requireFlag(flags, "name", "release playbook-draft"),
@@ -15652,6 +16234,65 @@ async function dispatch(client, args, meta, deps) {
15652
16234
  );
15653
16235
  }
15654
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
+ }
15655
16296
  case "channel": {
15656
16297
  if (!subcommand || subcommand === "--help" || subcommand === "-h") {
15657
16298
  return { _help: true, text: COMMAND_HELP.channel };