@alva-ai/toolkit 0.17.1-beta.0 → 0.18.0-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.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.18.0-beta.0" : "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,6 @@ 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)
13706
13723
  remix Save playbook remix lineage
13707
13724
  portfolio Connected-account portfolio (accounts, summary, activities)
13708
13725
  trading Trading operations (accounts, portfolio, orders, subscriptions, equity-history, risk-rules, subscribe, unsubscribe, execute, update-risk-rules)
@@ -14137,12 +14154,15 @@ Examples:
14137
14154
 
14138
14155
  Manage alerts. Alert subscriptions target automations (feeds) only. Playbook
14139
14156
  follows are independent; delivery history and global preferences live here too.
14157
+ Personal alerts may be routed to different Alva delivery channels. Group alerts
14158
+ are managed explicitly through "alert group" and target the current group.
14140
14159
 
14141
14160
  Subcommands:
14142
14161
  list List the caller's active alerts
14143
14162
  follows List the playbooks the caller follows
14144
14163
  enable Enable alerts by automation name or ids
14145
14164
  disable Disable alerts by automation name or ids
14165
+ group Manage alerts delivered to the current external group
14146
14166
  history List alert delivery history for an automation
14147
14167
  preferences List global alert preferences
14148
14168
  enable-session-completed
@@ -14155,6 +14175,14 @@ Enable/disable-by-id flags:
14155
14175
  --automation-ids <a,b> Comma-separated automation target ids
14156
14176
  --channel-id <id> Delivery channel for batch enable (optional)
14157
14177
 
14178
+ Group subcommands:
14179
+ alva alert group list
14180
+ alva alert group enable --automation-ids <id>
14181
+ alva alert group disable --automation-ids <id>
14182
+
14183
+ Group commands must run inside the attached channel-group sandbox. The current
14184
+ group is inferred automatically; there is no session-id argument.
14185
+
14158
14186
  List flags:
14159
14187
  --first <n> Optional page size
14160
14188
  --cursor <token> Optional cursor from previous response
@@ -14176,6 +14204,7 @@ Examples:
14176
14204
  alva alert disable --automation alice/btc-ema
14177
14205
  alva alert enable --automation-ids 13292,13293
14178
14206
  alva alert disable --automation-ids 13292
14207
+ alva alert group enable --automation-ids 13292
14179
14208
  alva alert history --automation alice/btc-ema --status sent
14180
14209
  alva alert preferences`,
14181
14210
  feed: `Usage: alva feed <subcommand> [options]
@@ -14672,31 +14701,6 @@ Examples:
14672
14701
  alva subscriptions unsubscribe --feed-ids 13292,13293
14673
14702
  alva subscriptions list --first 200
14674
14703
  alva subscriptions follows`,
14675
- channel: `Usage: alva channel group-subscriptions <subcommand> [options]
14676
-
14677
- Manage push notifications delivered into the external group chat attached
14678
- to a channel session. The group can subscribe to public feeds.
14679
- Subscribe/unsubscribe are idempotent no-ops unless the authenticated caller
14680
- is that group's Alva admin.
14681
-
14682
- Subcommands:
14683
- context Show group admin status and current subscriptions
14684
- list List active subscriptions for the group
14685
- subscribe Subscribe the group to a public feed
14686
- unsubscribe Unsubscribe the group from a feed
14687
-
14688
- Common flags:
14689
- --session-id <id> Channel session id for the group (required)
14690
-
14691
- Subscribe/unsubscribe flags:
14692
- --target-type <type> feed (required)
14693
- --target-id <id> Numeric feed_id (required)
14694
-
14695
- 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`,
14700
14704
  remix: `Usage: alva remix --child-username <u> --child-name <n> --parents <json>
14701
14705
 
14702
14706
  Record remix lineage when creating a playbook based on existing playbooks.
@@ -15065,13 +15069,49 @@ function configureRunFetchTimeout(timeoutMs, deps) {
15065
15069
  );
15066
15070
  configuredRunFetchTimeoutMs = timeoutMs;
15067
15071
  }
15068
- function requireGroupSubscriptionTargetType(flags, command) {
15069
- const val = requireFlag(flags, "target-type", command).trim().toLowerCase();
15070
- if (val === "feed") return val;
15071
- throw new CliUsageError(
15072
- `--target-type must be feed for '${command}', got '${val}'`,
15073
- command.split(" ")[0]
15074
- );
15072
+ function requireCurrentGroupAlertSessionID(client, command) {
15073
+ if (client.originSessionKind !== "channel_group") {
15074
+ throw new CliUsageError(
15075
+ `'${command}' is only available inside a channel-group sandbox`,
15076
+ "alert"
15077
+ );
15078
+ }
15079
+ const sessionID = client.originSessionId;
15080
+ if (sessionID === void 0) {
15081
+ throw new CliUsageError(
15082
+ `current group session is unavailable for '${command}'`,
15083
+ "alert"
15084
+ );
15085
+ }
15086
+ if (!/^[1-9]\d*$/.test(sessionID)) {
15087
+ throw new CliUsageError(
15088
+ `current group session must be a positive integer for '${command}', got '${sessionID}'`,
15089
+ "alert"
15090
+ );
15091
+ }
15092
+ return sessionID;
15093
+ }
15094
+ function requireSingleGroupAlertFeedID(flags, command) {
15095
+ if (flags.automation !== void 0) {
15096
+ throw new CliUsageError(
15097
+ `Group alerts require --automation-ids for '${command}'`,
15098
+ "alert"
15099
+ );
15100
+ }
15101
+ if (flags["channel-id"] !== void 0) {
15102
+ throw new CliUsageError(
15103
+ `--channel-id selects a personal Alva channel; omit it for '${command}'`,
15104
+ "alert"
15105
+ );
15106
+ }
15107
+ const ids = csvList(flags["automation-ids"]) ?? [];
15108
+ if (ids.length !== 1 || !/^[1-9]\d*$/.test(ids[0])) {
15109
+ throw new CliUsageError(
15110
+ `Group alerts require exactly one positive --automation-ids value for '${command}'`,
15111
+ "alert"
15112
+ );
15113
+ }
15114
+ return ids[0];
15075
15115
  }
15076
15116
  function num(val) {
15077
15117
  if (val === void 0) return void 0;
@@ -15419,22 +15459,38 @@ async function readAllStdin() {
15419
15459
  }
15420
15460
  return Buffer.concat(chunks).toString("utf8");
15421
15461
  }
15462
+ function brokerStdinNeedsIntentId(stdin) {
15463
+ let value;
15464
+ try {
15465
+ value = JSON.parse(stdin);
15466
+ } catch {
15467
+ return false;
15468
+ }
15469
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
15470
+ return false;
15471
+ }
15472
+ const input = value;
15473
+ const owns = (key) => Object.prototype.hasOwnProperty.call(input, key);
15474
+ if (owns("intentId") || owns("clientOrderId")) return false;
15475
+ if (!owns("dryRun")) return true;
15476
+ return input.dryRun === false;
15477
+ }
15422
15478
  async function handleBroker(client, brokerArgv, deps) {
15423
15479
  let argv = brokerArgv;
15424
15480
  const isOrderPlace = brokerArgv[0] === "order" && brokerArgv[1] === "place";
15425
15481
  const hasFlag = (name) => brokerArgv.some((a) => a === name || a.startsWith(`${name}=`));
15426
15482
  const hasHandle = hasFlag("--intent-id") || hasFlag("--client-order-id");
15427
15483
  const isDryRun = hasFlag("--dry-run");
15428
- if (isOrderPlace && !hasHandle && !isDryRun) {
15484
+ let stdin;
15485
+ if (hasFlag("--stdin")) {
15486
+ stdin = await readAllStdin();
15487
+ }
15488
+ if (isOrderPlace && !hasHandle && !isDryRun && (stdin === void 0 || brokerStdinNeedsIntentId(stdin))) {
15429
15489
  const intentId = crypto3.randomUUID();
15430
15490
  process.stderr.write(`alva broker: intent-id ${intentId}
15431
15491
  `);
15432
15492
  argv = [...brokerArgv, "--intent-id", intentId];
15433
15493
  }
15434
- let stdin;
15435
- if (hasFlag("--stdin")) {
15436
- stdin = await readAllStdin();
15437
- }
15438
15494
  let envelope;
15439
15495
  let exit = 2;
15440
15496
  try {
@@ -16636,6 +16692,45 @@ async function dispatch(client, args, meta, deps) {
16636
16692
  requireAutomationAlertTarget(flags, "alert disable")
16637
16693
  );
16638
16694
  }
16695
+ case "group": {
16696
+ const leaf = args[2];
16697
+ if (!leaf || leaf === "--help" || leaf === "-h") {
16698
+ return { _help: true, text: COMMAND_HELP.alert };
16699
+ }
16700
+ const command = `alert group ${leaf}`;
16701
+ if (flags["session-id"] !== void 0) {
16702
+ throw new CliUsageError(
16703
+ `'${command}' uses the attached group and does not accept --session-id`,
16704
+ "alert"
16705
+ );
16706
+ }
16707
+ const sessionID = requireCurrentGroupAlertSessionID(client, command);
16708
+ switch (leaf) {
16709
+ case "list": {
16710
+ const result = await client.channelGroupSubscriptions.list({
16711
+ session_id: sessionID
16712
+ });
16713
+ return boolFlag(flags["json"]) ? result : formatGroupAlertList(result);
16714
+ }
16715
+ case "enable":
16716
+ return client.channelGroupSubscriptions.subscribe({
16717
+ session_id: sessionID,
16718
+ target_type: "feed",
16719
+ target_id: requireSingleGroupAlertFeedID(flags, command)
16720
+ });
16721
+ case "disable":
16722
+ return client.channelGroupSubscriptions.unsubscribe({
16723
+ session_id: sessionID,
16724
+ target_type: "feed",
16725
+ target_id: requireSingleGroupAlertFeedID(flags, command)
16726
+ });
16727
+ default:
16728
+ throw new CliUsageError(
16729
+ `Unknown subcommand: alert group ${leaf}`,
16730
+ "alert"
16731
+ );
16732
+ }
16733
+ }
16639
16734
  case "history": {
16640
16735
  rejectPlaybookAlertTarget(flags, "alert history");
16641
16736
  const target = requireAutomationAlertTarget(flags, "alert history");
@@ -16669,80 +16764,6 @@ async function dispatch(client, args, meta, deps) {
16669
16764
  );
16670
16765
  }
16671
16766
  }
16672
- case "channel": {
16673
- if (!subcommand || subcommand === "--help" || subcommand === "-h") {
16674
- return { _help: true, text: COMMAND_HELP.channel };
16675
- }
16676
- if (subcommand !== "group-subscriptions") {
16677
- throw new CliUsageError(
16678
- `Unknown subcommand: channel ${subcommand}`,
16679
- "channel"
16680
- );
16681
- }
16682
- const leaf = args[2];
16683
- if (!leaf || leaf === "--help" || leaf === "-h") {
16684
- return { _help: true, text: COMMAND_HELP.channel };
16685
- }
16686
- const channelFlags = parseFlags2(args.slice(3));
16687
- const commandName = `channel group-subscriptions ${leaf}`;
16688
- switch (leaf) {
16689
- case "context":
16690
- return client.channelGroupSubscriptions.context({
16691
- session_id: requirePositiveIntegerStringFlag(
16692
- channelFlags,
16693
- "session-id",
16694
- commandName
16695
- )
16696
- });
16697
- case "list":
16698
- return client.channelGroupSubscriptions.list({
16699
- session_id: requirePositiveIntegerStringFlag(
16700
- channelFlags,
16701
- "session-id",
16702
- commandName
16703
- )
16704
- });
16705
- case "subscribe":
16706
- return client.channelGroupSubscriptions.subscribe({
16707
- session_id: requirePositiveIntegerStringFlag(
16708
- channelFlags,
16709
- "session-id",
16710
- commandName
16711
- ),
16712
- target_type: requireGroupSubscriptionTargetType(
16713
- channelFlags,
16714
- commandName
16715
- ),
16716
- target_id: requirePositiveIntegerStringFlag(
16717
- channelFlags,
16718
- "target-id",
16719
- commandName
16720
- )
16721
- });
16722
- case "unsubscribe":
16723
- return client.channelGroupSubscriptions.unsubscribe({
16724
- session_id: requirePositiveIntegerStringFlag(
16725
- channelFlags,
16726
- "session-id",
16727
- commandName
16728
- ),
16729
- target_type: requireGroupSubscriptionTargetType(
16730
- channelFlags,
16731
- commandName
16732
- ),
16733
- target_id: requirePositiveIntegerStringFlag(
16734
- channelFlags,
16735
- "target-id",
16736
- commandName
16737
- )
16738
- });
16739
- default:
16740
- throw new CliUsageError(
16741
- `Unknown subcommand: channel group-subscriptions ${leaf}`,
16742
- "channel"
16743
- );
16744
- }
16745
- }
16746
16767
  case "remix":
16747
16768
  return client.remix.save({
16748
16769
  child: {
@@ -17091,7 +17112,8 @@ async function main() {
17091
17112
  gaClientId: config.gaClientId,
17092
17113
  gaSessionId: config.gaSessionId,
17093
17114
  utmParams: config.utmParams,
17094
- originSessionId: config.originSessionId
17115
+ originSessionId: config.originSessionId,
17116
+ originSessionKind: config.originSessionKind
17095
17117
  });
17096
17118
  const cleanArgs = stripGlobalFlags(rawArgs);
17097
17119
  const result = await dispatch(client, cleanArgs, {