@alva-ai/toolkit 0.17.1-beta.0 → 0.17.1-beta.1

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.d.ts CHANGED
@@ -11,6 +11,8 @@ interface AlvaClientConfig {
11
11
  signal?: AbortSignal;
12
12
  /** Alva chat session owning produced artifacts; sent as X-Alva-Origin-Session-Id. */
13
13
  originSessionId?: string;
14
+ /** Session profile kind used to gate attached-context CLI commands. */
15
+ originSessionKind?: string;
14
16
  }
15
17
  interface UserProfile {
16
18
  id: string;
@@ -1632,8 +1634,8 @@ declare class AlertsResource {
1632
1634
  * Group push subscriptions for an external channel session.
1633
1635
  *
1634
1636
  * These APIs subscribe the Telegram/Discord group attached to `session_id`
1635
- * to public feed push events. Mutations are idempotent no-ops unless
1636
- * the authenticated caller is that group's Alva admin.
1637
+ * to feed push events the group admin may read. Mutations are idempotent no-ops
1638
+ * unless the authenticated caller is that group's Alva admin.
1637
1639
  */
1638
1640
  declare class ChannelGroupSubscriptionsResource {
1639
1641
  private client;
@@ -1797,6 +1799,8 @@ declare class AlvaClient {
1797
1799
  * from `gaSessionId` (browser analytics).
1798
1800
  */
1799
1801
  readonly originSessionId?: string;
1802
+ /** Session profile kind associated with originSessionId. */
1803
+ readonly originSessionKind?: string;
1800
1804
  private _fs?;
1801
1805
  private _run?;
1802
1806
  private _deploy?;
package/dist/cli.js CHANGED
@@ -12474,6 +12474,8 @@ var AlvaClient = class {
12474
12474
  * from `gaSessionId` (browser analytics).
12475
12475
  */
12476
12476
  originSessionId;
12477
+ /** Session profile kind associated with originSessionId. */
12478
+ originSessionKind;
12477
12479
  _fs;
12478
12480
  _run;
12479
12481
  _deploy;
@@ -12512,6 +12514,7 @@ var AlvaClient = class {
12512
12514
  this.utmParams = config.utmParams;
12513
12515
  this.signal = config.signal;
12514
12516
  this.originSessionId = config.originSessionId;
12517
+ this.originSessionKind = config.originSessionKind;
12515
12518
  }
12516
12519
  get fs() {
12517
12520
  return this._fs ??= new FsResource(this);
@@ -12854,6 +12857,7 @@ function loadConfig(deps) {
12854
12857
  const gaSessionIdEnv = env.ALVA_GA_SESSION_ID;
12855
12858
  const utmParamsEnv = env.ALVA_UTM_PARAMS;
12856
12859
  const originSessionIdEnv = env.ALVA_SESSION_ID;
12860
+ const originSessionKindEnv = env.ALVA_SESSION_KIND;
12857
12861
  let fileProfile = {};
12858
12862
  const path = configPath({ env, homedir: homedir3 });
12859
12863
  try {
@@ -12878,7 +12882,8 @@ function loadConfig(deps) {
12878
12882
  gaClientId: gaClientIdEnv,
12879
12883
  gaSessionId: gaSessionIdEnv,
12880
12884
  utmParams: utmParamsEnv,
12881
- originSessionId: originSessionIdEnv
12885
+ originSessionId: originSessionIdEnv,
12886
+ originSessionKind: originSessionKindEnv
12882
12887
  };
12883
12888
  }
12884
12889
 
@@ -13643,6 +13648,19 @@ function formatAlertList(result) {
13643
13648
  }
13644
13649
  return lines.join("\n");
13645
13650
  }
13651
+ function formatGroupAlertList(result) {
13652
+ const alerts = result.subscriptions ?? [];
13653
+ if (alerts.length === 0) return "(no group alerts)\n";
13654
+ const lines = [`${alerts.length} group alert(s):`, ""];
13655
+ for (const alert of alerts) {
13656
+ const targetID = alert.target?.id;
13657
+ const status = alert.enabled ? "enabled" : "disabled";
13658
+ lines.push(`\u2022 automation ${targetID ?? "(unknown)"} [${status}]`);
13659
+ lines.push(` event: ${alert.event_type}`);
13660
+ lines.push("");
13661
+ }
13662
+ return lines.join("\n");
13663
+ }
13646
13664
  function alertTitle(alert) {
13647
13665
  if (alert.feed_name) return alert.feed_name;
13648
13666
  return alert.target?.id ? `target ${alert.target.id}` : "(unknown target)";
@@ -13653,7 +13671,7 @@ import * as fs2 from "fs";
13653
13671
  import * as os2 from "os";
13654
13672
  import * as fsPromises2 from "fs/promises";
13655
13673
  import { Agent, setGlobalDispatcher } from "undici";
13656
- var CLI_VERSION = true ? "0.17.1-beta.0" : "dev";
13674
+ var CLI_VERSION = true ? "0.17.1-beta.1" : "dev";
13657
13675
  var DEFAULT_RUN_TIMEOUT_MS = 6e5;
13658
13676
  var RUN_TIMEOUT_ENV = "ALVA_RUN_TIMEOUT_MS";
13659
13677
  var configuredRunFetchTimeoutMs;
@@ -13702,7 +13720,7 @@ Commands:
13702
13720
  notification-preferences Notification preferences (list, enable-session-completed, disable-session-completed)
13703
13721
  feedback Submit user-confirmed Alva platform feedback (submit)
13704
13722
  subscriptions Playbook follows and feed alert subscriptions
13705
- channel Channel group operations (group-subscriptions context, list, subscribe, unsubscribe)
13723
+ channel Deprecated group-alert compatibility commands
13706
13724
  remix Save playbook remix lineage
13707
13725
  portfolio Connected-account portfolio (accounts, summary, activities)
13708
13726
  trading Trading operations (accounts, portfolio, orders, subscriptions, equity-history, risk-rules, subscribe, unsubscribe, execute, update-risk-rules)
@@ -14137,12 +14155,15 @@ Examples:
14137
14155
 
14138
14156
  Manage alerts. Alert subscriptions target automations (feeds) only. Playbook
14139
14157
  follows are independent; delivery history and global preferences live here too.
14158
+ Personal alerts may be routed to different Alva delivery channels. Group alerts
14159
+ are managed explicitly through "alert group" and target the current group.
14140
14160
 
14141
14161
  Subcommands:
14142
14162
  list List the caller's active alerts
14143
14163
  follows List the playbooks the caller follows
14144
14164
  enable Enable alerts by automation name or ids
14145
14165
  disable Disable alerts by automation name or ids
14166
+ group Manage alerts delivered to the current external group
14146
14167
  history List alert delivery history for an automation
14147
14168
  preferences List global alert preferences
14148
14169
  enable-session-completed
@@ -14155,6 +14176,14 @@ Enable/disable-by-id flags:
14155
14176
  --automation-ids <a,b> Comma-separated automation target ids
14156
14177
  --channel-id <id> Delivery channel for batch enable (optional)
14157
14178
 
14179
+ Group subcommands:
14180
+ alva alert group list
14181
+ alva alert group enable --automation-ids <id>
14182
+ alva alert group disable --automation-ids <id>
14183
+
14184
+ Group commands must run inside the attached channel-group sandbox. The current
14185
+ group is inferred automatically; there is no session-id argument.
14186
+
14158
14187
  List flags:
14159
14188
  --first <n> Optional page size
14160
14189
  --cursor <token> Optional cursor from previous response
@@ -14176,6 +14205,7 @@ Examples:
14176
14205
  alva alert disable --automation alice/btc-ema
14177
14206
  alva alert enable --automation-ids 13292,13293
14178
14207
  alva alert disable --automation-ids 13292
14208
+ alva alert group enable --automation-ids 13292
14179
14209
  alva alert history --automation alice/btc-ema --status sent
14180
14210
  alva alert preferences`,
14181
14211
  feed: `Usage: alva feed <subcommand> [options]
@@ -14674,29 +14704,32 @@ Examples:
14674
14704
  alva subscriptions follows`,
14675
14705
  channel: `Usage: alva channel group-subscriptions <subcommand> [options]
14676
14706
 
14677
- Manage push notifications delivered into the external group chat attached
14678
- to a channel session. The group can subscribe to public feeds.
14707
+ Deprecated compatibility surface. Normal alva alert list/enable/disable
14708
+ commands remain personal-channel operations. Use alva alert group
14709
+ list/enable/disable for the current external group. This alias remains available
14710
+ for existing scripts.
14711
+
14712
+ Manage alerts delivered into the external group chat attached to a channel
14713
+ session. The group can subscribe to feeds the group admin may read.
14679
14714
  Subscribe/unsubscribe are idempotent no-ops unless the authenticated caller
14680
14715
  is that group's Alva admin.
14681
14716
 
14682
14717
  Subcommands:
14683
14718
  context Show group admin status and current subscriptions
14684
14719
  list List active subscriptions for the group
14685
- subscribe Subscribe the group to a public feed
14720
+ subscribe Subscribe the group to a feed the admin may read
14686
14721
  unsubscribe Unsubscribe the group from a feed
14687
14722
 
14688
- Common flags:
14689
- --session-id <id> Channel session id for the group (required)
14690
-
14691
14723
  Subscribe/unsubscribe flags:
14692
- --target-type <type> feed (required)
14693
- --target-id <id> Numeric feed_id (required)
14724
+ --feed-id <id> Numeric feed_id (required)
14694
14725
 
14695
14726
  Examples:
14696
- alva channel group-subscriptions context --session-id 123
14697
- alva channel group-subscriptions list --session-id 123
14698
- alva channel group-subscriptions subscribe --session-id 123 --target-type feed --target-id 8169
14699
- alva channel group-subscriptions unsubscribe --session-id 123 --target-type feed --target-id 8169`,
14727
+ alva channel group-subscriptions context
14728
+ alva channel group-subscriptions list
14729
+ alva channel group-subscriptions subscribe --feed-id 8169
14730
+ alva channel group-subscriptions unsubscribe --feed-id 8169
14731
+
14732
+ These commands use the current sandbox session from ALVA_SESSION_ID.`,
14700
14733
  remix: `Usage: alva remix --child-username <u> --child-name <n> --parents <json>
14701
14734
 
14702
14735
  Record remix lineage when creating a playbook based on existing playbooks.
@@ -15066,13 +15099,89 @@ function configureRunFetchTimeout(timeoutMs, deps) {
15066
15099
  configuredRunFetchTimeoutMs = timeoutMs;
15067
15100
  }
15068
15101
  function requireGroupSubscriptionTargetType(flags, command) {
15069
- const val = requireFlag(flags, "target-type", command).trim().toLowerCase();
15102
+ const val = flags["target-type"]?.trim().toLowerCase() ?? "feed";
15070
15103
  if (val === "feed") return val;
15071
15104
  throw new CliUsageError(
15072
15105
  `--target-type must be feed for '${command}', got '${val}'`,
15073
15106
  command.split(" ")[0]
15074
15107
  );
15075
15108
  }
15109
+ function requireGroupSubscriptionSessionID(client, flags, command) {
15110
+ const val = flags["session-id"] ?? client.originSessionId;
15111
+ if (val === void 0) {
15112
+ throw new CliUsageError(
15113
+ `current group session is unavailable for '${command}'; run inside an Alva sandbox with ALVA_SESSION_ID`,
15114
+ "channel"
15115
+ );
15116
+ }
15117
+ if (!/^[1-9]\d*$/.test(val)) {
15118
+ throw new CliUsageError(
15119
+ `current group session must be a positive integer for '${command}', got '${val}'`,
15120
+ "channel"
15121
+ );
15122
+ }
15123
+ return val;
15124
+ }
15125
+ function requireGroupSubscriptionFeedID(flags, command) {
15126
+ const val = flags["feed-id"] ?? flags["target-id"];
15127
+ if (val === void 0) {
15128
+ throw new CliUsageError(
15129
+ `--feed-id is required for '${command}'`,
15130
+ "channel"
15131
+ );
15132
+ }
15133
+ if (!/^[1-9]\d*$/.test(val)) {
15134
+ throw new CliUsageError(
15135
+ `--feed-id must be a positive integer for '${command}', got '${val}'`,
15136
+ "channel"
15137
+ );
15138
+ }
15139
+ return val;
15140
+ }
15141
+ function requireCurrentGroupAlertSessionID(client, command) {
15142
+ if (client.originSessionKind !== "channel_group") {
15143
+ throw new CliUsageError(
15144
+ `'${command}' is only available inside a channel-group sandbox`,
15145
+ "alert"
15146
+ );
15147
+ }
15148
+ const sessionID = client.originSessionId;
15149
+ if (sessionID === void 0) {
15150
+ throw new CliUsageError(
15151
+ `current group session is unavailable for '${command}'`,
15152
+ "alert"
15153
+ );
15154
+ }
15155
+ if (!/^[1-9]\d*$/.test(sessionID)) {
15156
+ throw new CliUsageError(
15157
+ `current group session must be a positive integer for '${command}', got '${sessionID}'`,
15158
+ "alert"
15159
+ );
15160
+ }
15161
+ return sessionID;
15162
+ }
15163
+ function requireSingleGroupAlertFeedID(flags, command) {
15164
+ if (flags.automation !== void 0) {
15165
+ throw new CliUsageError(
15166
+ `Group alerts require --automation-ids for '${command}'`,
15167
+ "alert"
15168
+ );
15169
+ }
15170
+ if (flags["channel-id"] !== void 0) {
15171
+ throw new CliUsageError(
15172
+ `--channel-id selects a personal Alva channel; omit it for '${command}'`,
15173
+ "alert"
15174
+ );
15175
+ }
15176
+ const ids = csvList(flags["automation-ids"]) ?? [];
15177
+ if (ids.length !== 1 || !/^[1-9]\d*$/.test(ids[0])) {
15178
+ throw new CliUsageError(
15179
+ `Group alerts require exactly one positive --automation-ids value for '${command}'`,
15180
+ "alert"
15181
+ );
15182
+ }
15183
+ return ids[0];
15184
+ }
15076
15185
  function num(val) {
15077
15186
  if (val === void 0) return void 0;
15078
15187
  const n = Number(val);
@@ -15419,22 +15528,38 @@ async function readAllStdin() {
15419
15528
  }
15420
15529
  return Buffer.concat(chunks).toString("utf8");
15421
15530
  }
15531
+ function brokerStdinNeedsIntentId(stdin) {
15532
+ let value;
15533
+ try {
15534
+ value = JSON.parse(stdin);
15535
+ } catch {
15536
+ return false;
15537
+ }
15538
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
15539
+ return false;
15540
+ }
15541
+ const input = value;
15542
+ const owns = (key) => Object.prototype.hasOwnProperty.call(input, key);
15543
+ if (owns("intentId") || owns("clientOrderId")) return false;
15544
+ if (!owns("dryRun")) return true;
15545
+ return input.dryRun === false;
15546
+ }
15422
15547
  async function handleBroker(client, brokerArgv, deps) {
15423
15548
  let argv = brokerArgv;
15424
15549
  const isOrderPlace = brokerArgv[0] === "order" && brokerArgv[1] === "place";
15425
15550
  const hasFlag = (name) => brokerArgv.some((a) => a === name || a.startsWith(`${name}=`));
15426
15551
  const hasHandle = hasFlag("--intent-id") || hasFlag("--client-order-id");
15427
15552
  const isDryRun = hasFlag("--dry-run");
15428
- if (isOrderPlace && !hasHandle && !isDryRun) {
15553
+ let stdin;
15554
+ if (hasFlag("--stdin")) {
15555
+ stdin = await readAllStdin();
15556
+ }
15557
+ if (isOrderPlace && !hasHandle && !isDryRun && (stdin === void 0 || brokerStdinNeedsIntentId(stdin))) {
15429
15558
  const intentId = crypto3.randomUUID();
15430
15559
  process.stderr.write(`alva broker: intent-id ${intentId}
15431
15560
  `);
15432
15561
  argv = [...brokerArgv, "--intent-id", intentId];
15433
15562
  }
15434
- let stdin;
15435
- if (hasFlag("--stdin")) {
15436
- stdin = await readAllStdin();
15437
- }
15438
15563
  let envelope;
15439
15564
  let exit = 2;
15440
15565
  try {
@@ -16636,6 +16761,45 @@ async function dispatch(client, args, meta, deps) {
16636
16761
  requireAutomationAlertTarget(flags, "alert disable")
16637
16762
  );
16638
16763
  }
16764
+ case "group": {
16765
+ const leaf = args[2];
16766
+ if (!leaf || leaf === "--help" || leaf === "-h") {
16767
+ return { _help: true, text: COMMAND_HELP.alert };
16768
+ }
16769
+ const command = `alert group ${leaf}`;
16770
+ if (flags["session-id"] !== void 0) {
16771
+ throw new CliUsageError(
16772
+ `'${command}' uses the attached group and does not accept --session-id`,
16773
+ "alert"
16774
+ );
16775
+ }
16776
+ const sessionID = requireCurrentGroupAlertSessionID(client, command);
16777
+ switch (leaf) {
16778
+ case "list": {
16779
+ const result = await client.channelGroupSubscriptions.list({
16780
+ session_id: sessionID
16781
+ });
16782
+ return boolFlag(flags["json"]) ? result : formatGroupAlertList(result);
16783
+ }
16784
+ case "enable":
16785
+ return client.channelGroupSubscriptions.subscribe({
16786
+ session_id: sessionID,
16787
+ target_type: "feed",
16788
+ target_id: requireSingleGroupAlertFeedID(flags, command)
16789
+ });
16790
+ case "disable":
16791
+ return client.channelGroupSubscriptions.unsubscribe({
16792
+ session_id: sessionID,
16793
+ target_type: "feed",
16794
+ target_id: requireSingleGroupAlertFeedID(flags, command)
16795
+ });
16796
+ default:
16797
+ throw new CliUsageError(
16798
+ `Unknown subcommand: alert group ${leaf}`,
16799
+ "alert"
16800
+ );
16801
+ }
16802
+ }
16639
16803
  case "history": {
16640
16804
  rejectPlaybookAlertTarget(flags, "alert history");
16641
16805
  const target = requireAutomationAlertTarget(flags, "alert history");
@@ -16688,51 +16852,49 @@ async function dispatch(client, args, meta, deps) {
16688
16852
  switch (leaf) {
16689
16853
  case "context":
16690
16854
  return client.channelGroupSubscriptions.context({
16691
- session_id: requirePositiveIntegerStringFlag(
16855
+ session_id: requireGroupSubscriptionSessionID(
16856
+ client,
16692
16857
  channelFlags,
16693
- "session-id",
16694
16858
  commandName
16695
16859
  )
16696
16860
  });
16697
16861
  case "list":
16698
16862
  return client.channelGroupSubscriptions.list({
16699
- session_id: requirePositiveIntegerStringFlag(
16863
+ session_id: requireGroupSubscriptionSessionID(
16864
+ client,
16700
16865
  channelFlags,
16701
- "session-id",
16702
16866
  commandName
16703
16867
  )
16704
16868
  });
16705
16869
  case "subscribe":
16706
16870
  return client.channelGroupSubscriptions.subscribe({
16707
- session_id: requirePositiveIntegerStringFlag(
16871
+ session_id: requireGroupSubscriptionSessionID(
16872
+ client,
16708
16873
  channelFlags,
16709
- "session-id",
16710
16874
  commandName
16711
16875
  ),
16712
16876
  target_type: requireGroupSubscriptionTargetType(
16713
16877
  channelFlags,
16714
16878
  commandName
16715
16879
  ),
16716
- target_id: requirePositiveIntegerStringFlag(
16880
+ target_id: requireGroupSubscriptionFeedID(
16717
16881
  channelFlags,
16718
- "target-id",
16719
16882
  commandName
16720
16883
  )
16721
16884
  });
16722
16885
  case "unsubscribe":
16723
16886
  return client.channelGroupSubscriptions.unsubscribe({
16724
- session_id: requirePositiveIntegerStringFlag(
16887
+ session_id: requireGroupSubscriptionSessionID(
16888
+ client,
16725
16889
  channelFlags,
16726
- "session-id",
16727
16890
  commandName
16728
16891
  ),
16729
16892
  target_type: requireGroupSubscriptionTargetType(
16730
16893
  channelFlags,
16731
16894
  commandName
16732
16895
  ),
16733
- target_id: requirePositiveIntegerStringFlag(
16896
+ target_id: requireGroupSubscriptionFeedID(
16734
16897
  channelFlags,
16735
- "target-id",
16736
16898
  commandName
16737
16899
  )
16738
16900
  });
@@ -17091,7 +17253,8 @@ async function main() {
17091
17253
  gaClientId: config.gaClientId,
17092
17254
  gaSessionId: config.gaSessionId,
17093
17255
  utmParams: config.utmParams,
17094
- originSessionId: config.originSessionId
17256
+ originSessionId: config.originSessionId,
17257
+ originSessionKind: config.originSessionKind
17095
17258
  });
17096
17259
  const cleanArgs = stripGlobalFlags(rawArgs);
17097
17260
  const result = await dispatch(client, cleanArgs, {