@alva-ai/toolkit 0.25.2-beta.0 → 0.27.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.
@@ -1681,8 +1681,8 @@ declare class NotificationsResource {
1681
1681
  constructor(client: AlvaClient);
1682
1682
  /**
1683
1683
  * List the caller's notification history for one feed
1684
- * `(username, name)`. Authorization is alfs read on
1685
- * `/alva/home/<username>/feeds/<name>`.
1684
+ * `(username, name)`. Authorization uses the backend's canonical Feed read
1685
+ * decision (owner, public, bundled paid access, Plan, or Access Group).
1686
1686
  */
1687
1687
  listFeed(params: NotificationListParams): Promise<FeedNotificationListResponse>;
1688
1688
  }
@@ -2106,6 +2106,43 @@ declare class SchedulesResource {
2106
2106
  private graphql;
2107
2107
  }
2108
2108
 
2109
+ interface TradingPairCandidate {
2110
+ /** Underlying ticker returned by the market catalog. */
2111
+ symbol: string;
2112
+ /** Complete canonical identity used by OHLCV, Altra, and orders. */
2113
+ tradingPair: string;
2114
+ market: string;
2115
+ instrumentType: string;
2116
+ underlyingType?: string;
2117
+ quote: string;
2118
+ type?: string;
2119
+ description?: string;
2120
+ feeRate?: number;
2121
+ symbolIconUrl?: string;
2122
+ }
2123
+ interface TradingPairSearchParams {
2124
+ symbol: string;
2125
+ market?: string;
2126
+ instrumentType?: string;
2127
+ underlyingType?: string;
2128
+ quote?: string;
2129
+ limit?: number;
2130
+ }
2131
+ interface TradingPairSearchResponse {
2132
+ query: string;
2133
+ candidates: TradingPairCandidate[];
2134
+ truncated?: boolean;
2135
+ }
2136
+ type TradingPairResolveFilters = Omit<TradingPairSearchParams, 'symbol' | 'limit'>;
2137
+ declare class TradingPairsResource {
2138
+ private client;
2139
+ constructor(client: AlvaClient);
2140
+ search(params: TradingPairSearchParams): Promise<TradingPairSearchResponse>;
2141
+ resolve(params: ({
2142
+ pair: string;
2143
+ } & TradingPairResolveFilters) | Omit<TradingPairSearchParams, 'limit'>): Promise<TradingPairCandidate>;
2144
+ }
2145
+
2109
2146
  interface RequestOptions {
2110
2147
  query?: Record<string, unknown>;
2111
2148
  body?: unknown;
@@ -2172,6 +2209,7 @@ declare class AlvaClient {
2172
2209
  private _credits?;
2173
2210
  private _markets?;
2174
2211
  private _schedules?;
2212
+ private _tradingPairs?;
2175
2213
  constructor(config: AlvaClientConfig);
2176
2214
  get fs(): FsResource;
2177
2215
  get run(): RunResource;
@@ -2201,6 +2239,7 @@ declare class AlvaClient {
2201
2239
  get functions(): FunctionsResource;
2202
2240
  get credits(): CreditsResource;
2203
2241
  get markets(): MarketsResource;
2242
+ get tradingPairs(): TradingPairsResource;
2204
2243
  get schedules(): SchedulesResource;
2205
2244
  _requireAuth(): void;
2206
2245
  _request(method: string, path: string, options?: RequestOptions): Promise<unknown>;
package/dist/dispatch.js CHANGED
@@ -6088,6 +6088,28 @@ var EMBEDDED_COMMAND_DEFINITIONS = [
6088
6088
  route("markets earnings", "markets earnings", {
6089
6089
  values: ["ticker", "event", "fiscal-year", "fiscal-quarter"]
6090
6090
  }),
6091
+ route("trading-pairs search", "trading-pairs search", {
6092
+ values: [
6093
+ "symbol",
6094
+ "market",
6095
+ "instrument-type",
6096
+ "underlying-type",
6097
+ "quote",
6098
+ "limit"
6099
+ ],
6100
+ booleans: ["json"]
6101
+ }),
6102
+ route("trading-pairs resolve", "trading-pairs resolve", {
6103
+ values: [
6104
+ "pair",
6105
+ "symbol",
6106
+ "market",
6107
+ "instrument-type",
6108
+ "underlying-type",
6109
+ "quote"
6110
+ ],
6111
+ booleans: ["json"]
6112
+ }),
6091
6113
  action(
6092
6114
  "automation create",
6093
6115
  {
@@ -6363,6 +6385,7 @@ Commands:
6363
6385
  data-skills Discover structured Arrays data endpoints
6364
6386
  skillhub Discover curated methodology blueprints
6365
6387
  markets Read market narrative and earnings context
6388
+ trading-pairs Discover and strictly verify canonical trading pairs
6366
6389
  automation Create and operate scheduled automations
6367
6390
  playbooks Discover, build, release, and manage Playbooks
6368
6391
  alert Manage personal automation alert bindings
@@ -6403,6 +6426,42 @@ Subcommands:
6403
6426
  Subcommands:
6404
6427
  narrative
6405
6428
  earnings`,
6429
+ "trading-pairs": `Usage: alva trading-pairs <subcommand>
6430
+
6431
+ Subcommands:
6432
+ search Discover matching candidates; multiple results are normal
6433
+ resolve Require exactly one canonical tradingPair
6434
+
6435
+ Run 'alva trading-pairs search --help' and
6436
+ 'alva trading-pairs resolve --help' for flags and examples.`,
6437
+ "trading-pairs search": `Usage: alva trading-pairs search [options]
6438
+
6439
+ Return all matching candidates. Multiple results are normal; this command
6440
+ does not select a venue or construct a tradingPair.
6441
+
6442
+ Flags:
6443
+ --symbol <ticker> Ticker/query (required)
6444
+ --market <market> Optional market filter
6445
+ --instrument-type <type> Optional spot/perp/option filter
6446
+ --underlying-type <type> Optional stock/crypto filter
6447
+ --quote <currency> Optional quote filter
6448
+ --limit <n> Optional result limit
6449
+ --json Return machine-readable JSON`,
6450
+ "trading-pairs resolve": `Usage: alva trading-pairs resolve [options]
6451
+
6452
+ Require exactly one canonical tradingPair. Pass either a complete --pair or a
6453
+ --symbol with enough filters to make the result unique.
6454
+
6455
+ Flags:
6456
+ --pair <trading-pair> Verify one complete pair
6457
+ --symbol <ticker> Discover then require one match
6458
+ --market <market> Market filter
6459
+ --instrument-type <type> Spot/perp/option filter
6460
+ --underlying-type <type> Stock/crypto filter
6461
+ --quote <currency> Quote filter
6462
+ --json Return machine-readable JSON
6463
+
6464
+ Zero or multiple distinct pairs fail. Never use the first result.`,
6406
6465
  automation: `Usage: alva automation <subcommand>
6407
6466
 
6408
6467
  Subcommands:
@@ -6588,6 +6647,28 @@ function closestFlag(input, available) {
6588
6647
  const threshold = input.length <= 4 ? 1 : 2;
6589
6648
  return distance <= threshold ? closest : void 0;
6590
6649
  }
6650
+ var TOP_LEVEL_COMMAND_SUGGESTIONS = {
6651
+ market: "markets",
6652
+ data: "data-skills",
6653
+ feeds: "automation"
6654
+ };
6655
+ function closestCommand(input, available) {
6656
+ const terminology = TOP_LEVEL_COMMAND_SUGGESTIONS[input];
6657
+ if (terminology !== void 0 && available.has(terminology)) {
6658
+ return terminology;
6659
+ }
6660
+ let closest;
6661
+ let distance = Number.POSITIVE_INFINITY;
6662
+ for (const candidate of available.keys()) {
6663
+ const candidateDistance = editDistance(input, candidate);
6664
+ if (candidateDistance < distance) {
6665
+ closest = candidate;
6666
+ distance = candidateDistance;
6667
+ }
6668
+ }
6669
+ const threshold = input.length <= 4 ? 1 : 2;
6670
+ return distance <= threshold ? closest : void 0;
6671
+ }
6591
6672
  function mergeFlags(definition, globalFlags) {
6592
6673
  return { ...globalFlags, ...definition.flags };
6593
6674
  }
@@ -6605,7 +6686,9 @@ function resolveCommand(args, tree) {
6605
6686
  }
6606
6687
  if (node.definition !== void 0 && node.children.size === 0) break;
6607
6688
  if (consumed === 0) {
6608
- throw new CliUsageError(`Unknown command: '${input}'`);
6689
+ const suggestion = closestCommand(input, node.children);
6690
+ const recovery = suggestion === void 0 ? " Run 'alva --help' to list command families." : ` Did you mean '${suggestion}'?`;
6691
+ throw new CliUsageError(`Unknown command: '${input}'.${recovery}`);
6609
6692
  }
6610
6693
  const group2 = args[0];
6611
6694
  const command2 = args.slice(0, consumed).join(" ");
@@ -6816,7 +6899,8 @@ var COMMAND_DEFINITIONS = [
6816
6899
  "args",
6817
6900
  "max-heap-size-mb",
6818
6901
  "timeout-ms"
6819
- ]
6902
+ ],
6903
+ booleans: ["args-stdin"]
6820
6904
  }),
6821
6905
  command("deploy create", {
6822
6906
  values: [
@@ -7162,6 +7246,28 @@ var COMMAND_DEFINITIONS = [
7162
7246
  command("markets earnings", {
7163
7247
  values: ["ticker", "event", "fiscal-year", "fiscal-quarter"]
7164
7248
  }),
7249
+ command("trading-pairs search", {
7250
+ values: [
7251
+ "symbol",
7252
+ "market",
7253
+ "instrument-type",
7254
+ "underlying-type",
7255
+ "quote",
7256
+ "limit"
7257
+ ],
7258
+ booleans: ["json"]
7259
+ }),
7260
+ command("trading-pairs resolve", {
7261
+ values: [
7262
+ "pair",
7263
+ "symbol",
7264
+ "market",
7265
+ "instrument-type",
7266
+ "underlying-type",
7267
+ "quote"
7268
+ ],
7269
+ booleans: ["json"]
7270
+ }),
7165
7271
  command("trading accounts"),
7166
7272
  command("trading portfolio", { values: ["account-id"] }),
7167
7273
  command("trading orders", {
@@ -10935,8 +11041,41 @@ function validateSerializedArgs(raw) {
10935
11041
  validateJSONNumberTokens(raw);
10936
11042
  }
10937
11043
 
11044
+ // src/cli/tradingPairsFormat.ts
11045
+ function candidateLine(candidate) {
11046
+ const metadata = [
11047
+ `market=${candidate.market}`,
11048
+ `instrument=${candidate.instrumentType}`,
11049
+ candidate.underlyingType === void 0 ? void 0 : `underlying=${candidate.underlyingType}`,
11050
+ `quote=${candidate.quote}`
11051
+ ].filter((value) => value !== void 0);
11052
+ return `${candidate.tradingPair} (${metadata.join(" ")})`;
11053
+ }
11054
+ function formatTradingPairSearch(result) {
11055
+ if (result.candidates.length === 0) {
11056
+ return `No trading pairs found for "${result.query}".`;
11057
+ }
11058
+ const lines = result.candidates.map(candidateLine);
11059
+ if (result.truncated === true) {
11060
+ lines.push(
11061
+ `... results truncated at ${result.candidates.length} candidates`
11062
+ );
11063
+ }
11064
+ return lines.join("\n");
11065
+ }
11066
+ function formatTradingPairResolved(result) {
11067
+ return [
11068
+ result.tradingPair,
11069
+ `symbol=${result.symbol}`,
11070
+ `market=${result.market}`,
11071
+ `instrument=${result.instrumentType}`,
11072
+ ...result.underlyingType === void 0 ? [] : [`underlying=${result.underlyingType}`],
11073
+ `quote=${result.quote}`
11074
+ ].join("\n");
11075
+ }
11076
+
10938
11077
  // src/cli/dispatch.ts
10939
- var CLI_VERSION = true ? "0.25.2-beta.0" : "dev";
11078
+ var CLI_VERSION = true ? "0.27.0" : "dev";
10940
11079
  var DEFAULT_RUN_TIMEOUT_MS = 6e5;
10941
11080
  var RUN_TIMEOUT_ENV = "ALVA_RUN_TIMEOUT_MS";
10942
11081
  var GLOBAL_VALUE_FLAGS = Object.entries(GLOBAL_FLAG_DEFINITIONS).filter(([, kind]) => kind === "value").map(([name]) => `--${name}`);
@@ -11166,6 +11305,7 @@ Options:
11166
11305
  --entry-path <path> Path to a script file on ALFS (home-relative)
11167
11306
  --working-dir <dir> Working directory for require() (inline code only)
11168
11307
  --args <json> JSON object passed to require("env").args
11308
+ --args-stdin Read the JSON object from stdin (mutually exclusive with --args)
11169
11309
  --max-heap-size-mb <mb> Override the V8 heap limit in MB (1-2048, default 256)
11170
11310
  --timeout-ms <ms> Client HTTP timeout for /api/v1/run (default: ${DEFAULT_RUN_TIMEOUT_MS}; env: ${RUN_TIMEOUT_ENV})
11171
11311
 
@@ -11199,6 +11339,7 @@ Examples:
11199
11339
  alva run --entry-path "~/feeds/my-feed/v1/src/index.js"
11200
11340
  alva run --entry-path "~/tasks/analyze/src/index.js" --args '{"symbol":"NVDA","limit":50}'
11201
11341
  alva run --local-file ./my-script.js --args '{"symbol":"BTC"}'
11342
+ printf '%s' '{"symbol":"BTC"}' | alva run --local-file ./my-script.js --args-stdin
11202
11343
  alva run --entry-path "~/tasks/heavy/src/index.js" --max-heap-size-mb 1024
11203
11344
  alva run --entry-path "~/feeds/slow/v1/src/index.js" --timeout-ms 900000`,
11204
11345
  deploy: `Usage: alva deploy <subcommand> [options]
@@ -12087,6 +12228,34 @@ Examples:
12087
12228
  alva markets earnings --ticker AAPL
12088
12229
  alva markets earnings --ticker AAPL --event next-confirmed
12089
12230
  alva markets earnings --ticker AAPL --fiscal-year 2026 --fiscal-quarter Q3`,
12231
+ "trading-pairs": `Usage: alva trading-pairs <subcommand> [options]
12232
+
12233
+ Discover canonical trading-pair identities before backtesting or trading.
12234
+ The returned tradingPair is the exact value to use in OHLCV, Altra targets,
12235
+ positions, and orders. This command never constructs aliases or picks the
12236
+ first result.
12237
+
12238
+ Subcommands:
12239
+ search Return all matching candidates; multiple results are normal
12240
+ resolve Require exactly one matching canonical tradingPair
12241
+
12242
+ Search and resolve flags:
12243
+ --symbol <ticker> Underlying ticker/query (for example RKLB)
12244
+ --market <market> Venue/market filter (for example US, BINANCE)
12245
+ --instrument-type <type> spot, perp, option, ...
12246
+ --underlying-type <type> stock, crypto, ...
12247
+ --quote <currency> USD, USDT, USDC, ...
12248
+ --json Return the machine-readable result
12249
+
12250
+ Search-only flags:
12251
+ --limit <n> Limit returned candidates; truncation is reported
12252
+
12253
+ Resolve forms:
12254
+ alva trading-pairs resolve --pair US_SPOT_RKLB_USD --json
12255
+ alva trading-pairs resolve --symbol RKLB --market US --instrument-type spot --quote USD --json
12256
+
12257
+ Resolve fails when zero or multiple distinct pairs remain. Existing holdings
12258
+ must keep their stored full tradingPair instead of being resolved again.`,
12090
12259
  trading: `Usage: alva trading <subcommand> [options]
12091
12260
 
12092
12261
  Manage trading accounts, portfolios, orders, subscriptions, and risk rules.
@@ -12172,13 +12341,13 @@ function boolFlag(val) {
12172
12341
  if (val === "false") return false;
12173
12342
  return void 0;
12174
12343
  }
12175
- function serializedJSONFlag(value, command2) {
12344
+ function serializedJSONFlag(value, command2, flag = "--args") {
12176
12345
  if (value === void 0) return void 0;
12177
12346
  try {
12178
12347
  validateSerializedArgs(value);
12179
12348
  } catch (error) {
12180
12349
  throw new CliUsageError(
12181
- `--args must contain valid JSON for '${command2}': ${error instanceof Error ? error.message : String(error)}`,
12350
+ `${flag} must contain valid JSON for '${command2}': ${error instanceof Error ? error.message : String(error)}`,
12182
12351
  command2.split(" ")[0]
12183
12352
  );
12184
12353
  }
@@ -13020,7 +13189,30 @@ async function executeParsedCommand(client, parsedCommand, meta, deps) {
13020
13189
  ),
13021
13190
  timeout_ms
13022
13191
  };
13023
- const serializedArgs = serializedJSONFlag(flags["args"], "run");
13192
+ const argsFromStdin = boolFlag(flags["args-stdin"]) === true;
13193
+ if (argsFromStdin && flags["args"] !== void 0) {
13194
+ throw new CliUsageError(
13195
+ "--args and --args-stdin are mutually exclusive",
13196
+ "run"
13197
+ );
13198
+ }
13199
+ let serializedArgs = serializedJSONFlag(flags["args"], "run");
13200
+ if (argsFromStdin) {
13201
+ if (!deps?.readStdin) {
13202
+ throw new CliUsageError(
13203
+ "--args-stdin requires a Node.js runtime adapter",
13204
+ "run"
13205
+ );
13206
+ }
13207
+ const stdin = await deps.readStdin();
13208
+ serializedArgs = serializedJSONFlag(stdin, "run", "--args-stdin");
13209
+ if (serializedArgs === void 0) {
13210
+ throw new CliUsageError(
13211
+ "--args-stdin requires JSON input from stdin",
13212
+ "run"
13213
+ );
13214
+ }
13215
+ }
13024
13216
  return serializedArgs === void 0 ? client.run.execute(params) : client.run._executeSerializedArgs(params, serializedArgs);
13025
13217
  }
13026
13218
  case "deploy": {
@@ -14346,6 +14538,61 @@ async function executeParsedCommand(client, parsedCommand, meta, deps) {
14346
14538
  );
14347
14539
  }
14348
14540
  }
14541
+ case "trading-pairs": {
14542
+ if (!subcommand) {
14543
+ throw new CliUsageError(
14544
+ "Missing subcommand for trading-pairs",
14545
+ "trading-pairs"
14546
+ );
14547
+ }
14548
+ const asJson = boolFlag(flags["json"]) ?? false;
14549
+ const filters = {
14550
+ market: flags["market"],
14551
+ instrumentType: flags["instrument-type"],
14552
+ underlyingType: flags["underlying-type"],
14553
+ quote: flags["quote"]
14554
+ };
14555
+ switch (subcommand) {
14556
+ case "search": {
14557
+ const limit = flags["limit"] === void 0 ? void 0 : requirePositiveIntegerFlag(
14558
+ flags,
14559
+ "limit",
14560
+ "trading-pairs search"
14561
+ );
14562
+ const result = await client.tradingPairs.search({
14563
+ symbol: requireFlag(flags, "symbol", "trading-pairs search"),
14564
+ ...filters,
14565
+ limit
14566
+ });
14567
+ return asJson ? result : formatTradingPairSearch(result);
14568
+ }
14569
+ case "resolve": {
14570
+ const pair = flags["pair"];
14571
+ const symbol = flags["symbol"];
14572
+ if (pair !== void 0 && symbol !== void 0) {
14573
+ throw new CliUsageError(
14574
+ "'trading-pairs resolve' accepts either --pair or --symbol, not both",
14575
+ "trading-pairs"
14576
+ );
14577
+ }
14578
+ if (pair === void 0 && symbol === void 0) {
14579
+ throw new CliUsageError(
14580
+ "'trading-pairs resolve' requires --pair or --symbol",
14581
+ "trading-pairs"
14582
+ );
14583
+ }
14584
+ const result = await client.tradingPairs.resolve(
14585
+ pair !== void 0 ? { pair, ...filters } : { symbol, ...filters }
14586
+ );
14587
+ return asJson ? result : formatTradingPairResolved(result);
14588
+ }
14589
+ default:
14590
+ throw new CliUsageError(
14591
+ `Unknown subcommand: trading-pairs ${subcommand}`,
14592
+ "trading-pairs"
14593
+ );
14594
+ }
14595
+ }
14349
14596
  case "trading": {
14350
14597
  if (!subcommand)
14351
14598
  throw new CliUsageError("Missing subcommand for trading", "trading");