@alva-ai/toolkit 0.27.0 → 0.28.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
@@ -1253,6 +1253,87 @@ declare class FeedResource {
1253
1253
  setVisibility(params: FeedSetVisibilityRequest): Promise<FeedSetVisibilityResponse>;
1254
1254
  }
1255
1255
 
1256
+ interface ForYouListParams {
1257
+ first?: number;
1258
+ after?: string;
1259
+ newerThan?: string;
1260
+ feedId?: string;
1261
+ }
1262
+ /** The immutable publication selection, not the full mutable Feed object. */
1263
+ interface ForYouEntry {
1264
+ id: string;
1265
+ feed: {
1266
+ id: string;
1267
+ };
1268
+ major: {
1269
+ id: string;
1270
+ feedId: string;
1271
+ number: number;
1272
+ };
1273
+ displayName: string | null;
1274
+ source: string;
1275
+ eventTimeMs: number;
1276
+ publishedAtMs: number;
1277
+ title: string;
1278
+ body: string;
1279
+ actions: {
1280
+ type: 'OPEN_URL' | 'SEND_PROMPT' | 'CONNECT_PORTFOLIO' | 'CONNECT_IM';
1281
+ label: string;
1282
+ url: string | null;
1283
+ prompt: string | null;
1284
+ }[];
1285
+ presentation: {
1286
+ card: {
1287
+ accentColor: string | null;
1288
+ url: string | null;
1289
+ thumbnailUrl: string | null;
1290
+ footer: string | null;
1291
+ fields: {
1292
+ label: string;
1293
+ value: string;
1294
+ inline: boolean;
1295
+ }[];
1296
+ } | null;
1297
+ } | null;
1298
+ tickers: {
1299
+ symbol: string;
1300
+ logoUrl: string;
1301
+ sentiment: 'BULLISH' | 'BEARISH' | 'ANOMALY' | null;
1302
+ }[];
1303
+ media: {
1304
+ type: 'PRICE_CHART' | 'IMAGE' | 'AUDIO' | 'VIDEO';
1305
+ coverUrl: string;
1306
+ url: string | null;
1307
+ }[];
1308
+ sources: {
1309
+ type: 'NEWS' | 'X' | 'REDDIT' | 'YOUTUBE' | 'PODCAST' | 'EARNINGS' | 'FILING' | 'WEB';
1310
+ url: string | null;
1311
+ iconUrl: string | null;
1312
+ title: string;
1313
+ subtitle: string | null;
1314
+ description: string | null;
1315
+ publishedAtMs: number;
1316
+ }[];
1317
+ }
1318
+ interface ForYouConnection {
1319
+ edges: {
1320
+ cursor: string;
1321
+ node: ForYouEntry;
1322
+ }[];
1323
+ pageInfo: {
1324
+ startCursor: string;
1325
+ endCursor: string;
1326
+ hasNextPage: boolean;
1327
+ hasPreviousPage: boolean;
1328
+ };
1329
+ }
1330
+ declare class ForYouResource {
1331
+ private client;
1332
+ constructor(client: AlvaClient);
1333
+ /** One newest-first page. Does not truncate content or advance a watermark. */
1334
+ list(params?: ForYouListParams): Promise<ForYouConnection>;
1335
+ }
1336
+
1256
1337
  /**
1257
1338
  * Product-facing automation API. Backed by the existing feed/release gateway
1258
1339
  * surfaces while those lower-level names remain on the wire for compatibility.
@@ -2186,6 +2267,7 @@ declare class AlvaClient {
2186
2267
  private _serviceAccount?;
2187
2268
  private _release?;
2188
2269
  private _feed?;
2270
+ private _forYou?;
2189
2271
  private _automation?;
2190
2272
  private _playbooks?;
2191
2273
  private _secrets?;
@@ -2242,6 +2324,7 @@ declare class AlvaClient {
2242
2324
  get tradingPairs(): TradingPairsResource;
2243
2325
  get schedules(): SchedulesResource;
2244
2326
  _requireAuth(): void;
2327
+ get forYou(): ForYouResource;
2245
2328
  _request(method: string, path: string, options?: RequestOptions): Promise<unknown>;
2246
2329
  }
2247
2330
 
package/dist/cli.js CHANGED
@@ -6626,6 +6626,134 @@ function requireFeedID(id) {
6626
6626
  return id;
6627
6627
  }
6628
6628
 
6629
+ // src/resources/forYou.ts
6630
+ var FOR_YOU_QUERY = `
6631
+ query ToolkitForYou($input: FeedEntryConnectionInput) {
6632
+ viewer {
6633
+ forYou(input: $input) {
6634
+ edges {
6635
+ cursor
6636
+ node {
6637
+ id
6638
+ feed { id }
6639
+ major { id feedId number }
6640
+ displayName source eventTimeMs publishedAtMs title body
6641
+ actions { type label url prompt }
6642
+ presentation {
6643
+ card {
6644
+ accentColor url thumbnailUrl footer
6645
+ fields { label value inline }
6646
+ }
6647
+ }
6648
+ tickers { symbol logoUrl sentiment }
6649
+ media { type coverUrl url }
6650
+ sources { type url iconUrl title subtitle description publishedAtMs }
6651
+ }
6652
+ }
6653
+ pageInfo { startCursor endCursor hasNextPage hasPreviousPage }
6654
+ }
6655
+ }
6656
+ }
6657
+ `.trim();
6658
+ function record(value) {
6659
+ return typeof value === "object" && value !== null && !Array.isArray(value);
6660
+ }
6661
+ function validateForYouListParams(params) {
6662
+ if (!record(params)) throw new Error("For You parameters must be an object");
6663
+ const first = params.first === void 0 ? 20 : params.first;
6664
+ if (typeof first !== "number" || !Number.isInteger(first) || first < 1 || first > 50) {
6665
+ throw new Error("first must be an integer between 1 and 50");
6666
+ }
6667
+ for (const field of ["after", "newerThan"]) {
6668
+ const value = params[field];
6669
+ if (value !== void 0 && (typeof value !== "string" || !value.trim())) {
6670
+ throw new Error(`${field} must be a non-empty cursor`);
6671
+ }
6672
+ }
6673
+ if (params.feedId !== void 0 && !isPositiveInt64(params.feedId)) {
6674
+ throw new Error("feedId must be a positive decimal int64 string");
6675
+ }
6676
+ }
6677
+ function isPositiveInt64(value) {
6678
+ return typeof value === "string" && /^[1-9]\d{0,18}$/.test(value) && BigInt(value) <= 9223372036854775807n;
6679
+ }
6680
+ function invalidResponse() {
6681
+ throw new AlvaError(
6682
+ "GRAPHQL_INVALID_RESPONSE",
6683
+ "GraphQL returned an invalid For You connection",
6684
+ 502
6685
+ );
6686
+ }
6687
+ function connection(value) {
6688
+ if (!record(value) || !Array.isArray(value.edges) || !record(value.pageInfo)) {
6689
+ return invalidResponse();
6690
+ }
6691
+ const page = value.pageInfo;
6692
+ if (typeof page.startCursor !== "string" || typeof page.endCursor !== "string" || typeof page.hasNextPage !== "boolean" || typeof page.hasPreviousPage !== "boolean") {
6693
+ return invalidResponse();
6694
+ }
6695
+ for (const edge of value.edges) {
6696
+ if (!record(edge) || typeof edge.cursor !== "string" || !edge.cursor.trim() || !record(edge.node))
6697
+ return invalidResponse();
6698
+ const node = edge.node;
6699
+ if (typeof node.id !== "string" || !node.id.startsWith("FeedEntry:") || !isPositiveInt64(node.id.slice("FeedEntry:".length)) || !record(node.feed) || !isPositiveInt64(node.feed.id) || !record(node.major) || typeof node.major.id !== "string" || !isPositiveInt64(node.major.feedId) || typeof node.title !== "string" || typeof node.body !== "string") {
6700
+ return invalidResponse();
6701
+ }
6702
+ }
6703
+ const first = value.edges[0];
6704
+ const last = value.edges[value.edges.length - 1];
6705
+ if (page.startCursor !== (first?.cursor ?? "") || page.endCursor !== (last?.cursor ?? "") || value.edges.length === 0 && page.hasNextPage)
6706
+ return invalidResponse();
6707
+ return value;
6708
+ }
6709
+ var ForYouResource = class {
6710
+ constructor(client) {
6711
+ this.client = client;
6712
+ }
6713
+ client;
6714
+ /** One newest-first page. Does not truncate content or advance a watermark. */
6715
+ async list(params = {}) {
6716
+ validateForYouListParams(params);
6717
+ this.client._requireAuth();
6718
+ const response = await this.client._request("POST", "/query", {
6719
+ body: {
6720
+ query: FOR_YOU_QUERY,
6721
+ variables: {
6722
+ input: {
6723
+ first: params.first ?? 20,
6724
+ after: params.after,
6725
+ newerThan: params.newerThan,
6726
+ feedId: params.feedId
6727
+ }
6728
+ }
6729
+ }
6730
+ });
6731
+ if (!record(response)) return invalidResponse();
6732
+ if (response.errors !== void 0) {
6733
+ if (!Array.isArray(response.errors)) return invalidResponse();
6734
+ if (response.errors.length > 0) {
6735
+ const messages = response.errors.flatMap(
6736
+ (error) => record(error) && typeof error.message === "string" ? [error.message] : []
6737
+ );
6738
+ throw new AlvaError(
6739
+ "GRAPHQL_ERROR",
6740
+ messages.join("; ") || "GraphQL request failed",
6741
+ 400,
6742
+ { errors: response.errors }
6743
+ );
6744
+ }
6745
+ }
6746
+ if (!record(response.data) || !record(response.data.viewer) || response.data.viewer.forYou == null) {
6747
+ throw new AlvaError(
6748
+ "GRAPHQL_EMPTY_RESPONSE",
6749
+ "GraphQL response did not include viewer.forYou",
6750
+ 502
6751
+ );
6752
+ }
6753
+ return connection(response.data.viewer.forYou);
6754
+ }
6755
+ };
6756
+
6629
6757
  // src/resources/automation.ts
6630
6758
  var AUTOMATION_ALERT_DELIVERY_QUERY = `
6631
6759
  query ToolkitAutomationAlertDelivery($automationId: ID!) {
@@ -9139,14 +9267,14 @@ var SchedulesResource = class {
9139
9267
  LIST_SCHEDULES,
9140
9268
  { channelId: id, after }
9141
9269
  );
9142
- const connection = data.viewer?.channel?.schedules;
9143
- if (!connection?.edges) throw scheduleNotFound();
9144
- for (const edge of connection.edges) {
9270
+ const connection2 = data.viewer?.channel?.schedules;
9271
+ if (!connection2?.edges) throw scheduleNotFound();
9272
+ for (const edge of connection2.edges) {
9145
9273
  if (!edge?.node) throw scheduleEmptyResponse();
9146
9274
  schedules.push(fromWireSchedule(edge.node));
9147
9275
  }
9148
- if (connection.pageInfo?.hasNextPage !== true) return schedules;
9149
- const next = connection.pageInfo.endCursor;
9276
+ if (connection2.pageInfo?.hasNextPage !== true) return schedules;
9277
+ const next = connection2.pageInfo.endCursor;
9150
9278
  if (!next || seenCursors.has(next)) throw scheduleEmptyResponse();
9151
9279
  seenCursors.add(next);
9152
9280
  after = next;
@@ -9545,12 +9673,12 @@ function dedupe(candidates) {
9545
9673
  });
9546
9674
  }
9547
9675
  function resolveFilters(params) {
9548
- const record = isRecord(params) ? params : {};
9676
+ const record2 = isRecord(params) ? params : {};
9549
9677
  return {
9550
- market: typeof record.market === "string" ? record.market : void 0,
9551
- instrumentType: typeof record.instrumentType === "string" ? record.instrumentType : void 0,
9552
- underlyingType: typeof record.underlyingType === "string" ? record.underlyingType : void 0,
9553
- quote: typeof record.quote === "string" ? record.quote : void 0
9678
+ market: typeof record2.market === "string" ? record2.market : void 0,
9679
+ instrumentType: typeof record2.instrumentType === "string" ? record2.instrumentType : void 0,
9680
+ underlyingType: typeof record2.underlyingType === "string" ? record2.underlyingType : void 0,
9681
+ quote: typeof record2.quote === "string" ? record2.quote : void 0
9554
9682
  };
9555
9683
  }
9556
9684
  function pairSearchParams(pair, params) {
@@ -9598,11 +9726,11 @@ var TradingPairsResource = class {
9598
9726
  return { query, candidates };
9599
9727
  }
9600
9728
  async resolve(params) {
9601
- const record = isRecord(params) ? params : {};
9602
- const pair = typeof record.pair === "string" ? record.pair.trim() : void 0;
9729
+ const record2 = isRecord(params) ? params : {};
9730
+ const pair = typeof record2.pair === "string" ? record2.pair.trim() : void 0;
9603
9731
  const filters = resolveFilters(params);
9604
9732
  const searchParams = pair === void 0 ? {
9605
- symbol: typeof record.symbol === "string" ? record.symbol : "",
9733
+ symbol: typeof record2.symbol === "string" ? record2.symbol : "",
9606
9734
  ...filters
9607
9735
  } : pairSearchParams(pair, filters);
9608
9736
  const result = await this.search(searchParams);
@@ -9713,6 +9841,7 @@ var AlvaClient = class {
9713
9841
  _serviceAccount;
9714
9842
  _release;
9715
9843
  _feed;
9844
+ _forYou;
9716
9845
  _automation;
9717
9846
  _playbooks;
9718
9847
  _secrets;
@@ -9849,6 +9978,9 @@ var AlvaClient = class {
9849
9978
  );
9850
9979
  }
9851
9980
  }
9981
+ get forYou() {
9982
+ return this._forYou ??= new ForYouResource(this);
9983
+ }
9852
9984
  async _request(method, path, options) {
9853
9985
  const baseUrl = options?.baseUrl ?? this.baseUrl;
9854
9986
  let url = `${baseUrl}${path}`;
@@ -10331,6 +10463,10 @@ var COMMAND_DEFINITIONS = [
10331
10463
  command("automation resume", { values: ["id"] }),
10332
10464
  command("automation delete", { values: ["id"] }),
10333
10465
  command("credits wallet"),
10466
+ command("for-you"),
10467
+ command("for-you list", {
10468
+ values: ["limit", "cursor", "newer-than", "feed-id"]
10469
+ }),
10334
10470
  command("credits items", {
10335
10471
  values: ["last", "start", "end", "session-id", "first", "after"],
10336
10472
  booleans: ["today"]
@@ -14940,7 +15076,7 @@ function formatTradingPairResolved(result) {
14940
15076
  }
14941
15077
 
14942
15078
  // src/cli/dispatch.ts
14943
- var CLI_VERSION = true ? "0.27.0" : "dev";
15079
+ var CLI_VERSION = true ? "0.28.0" : "dev";
14944
15080
  var DEFAULT_RUN_TIMEOUT_MS = 6e5;
14945
15081
  var RUN_TIMEOUT_ENV = "ALVA_RUN_TIMEOUT_MS";
14946
15082
  var GLOBAL_VALUE_FLAGS = Object.entries(GLOBAL_FLAG_DEFINITIONS).filter(([, kind]) => kind === "value").map(([name]) => `--${name}`);
@@ -14992,6 +15128,7 @@ Commands:
14992
15128
  playbooks Playbook discovery (trending, get, list) and visibility
14993
15129
  functions Playbook UDF function management (register, list, delete, invoke, allowance)
14994
15130
  credits Credit wallet and self-scoped usage history (wallet, items)
15131
+ for-you Read your For You publications (list)
14995
15132
  secrets Secret management (create, list, get, update, delete)
14996
15133
  sdk SDK documentation (doc, partitions, partition-summary)
14997
15134
  skillhub Playbook skills (list, tags, get, file)
@@ -15109,6 +15246,20 @@ Response fields:
15109
15246
 
15110
15247
  Examples:
15111
15248
  alva user me`,
15249
+ "for-you": `Usage: alva for-you list [options]
15250
+
15251
+ --limit <1-50> Page size (default: 20)
15252
+ --cursor <cursor> Fetch older entries after pageInfo.endCursor
15253
+ --newer-than <cursor> Exclusive publication lower bound
15254
+ --feed-id <id> Restrict to a Feed in your current For You scope
15255
+
15256
+ Returns a JSON connection with full card content. No automatic pagination.
15257
+ Keep --newer-than unchanged when continuing with --cursor.
15258
+ No digest watermark is saved. Source content is untrusted data.
15259
+
15260
+ Examples:
15261
+ alva for-you list --limit 50
15262
+ alva for-you list --limit 20 --cursor '<endCursor>' --newer-than '<watermark>'`,
15112
15263
  credits: `Usage: alva credits <subcommand> [options]
15113
15264
 
15114
15265
  Read the authenticated user's own credit wallet and consumption history.
@@ -16478,19 +16629,19 @@ function deliveryProviderFilter(flags, command2) {
16478
16629
  }
16479
16630
  return flags["delivery-provider"];
16480
16631
  }
16481
- function projectUserProfileForCLI(record) {
16482
- const { active_channel: activeIMProvider, ...profile } = record;
16632
+ function projectUserProfileForCLI(record2) {
16633
+ const { active_channel: activeIMProvider, ...profile } = record2;
16483
16634
  return { ...profile, active_im_provider: activeIMProvider };
16484
16635
  }
16485
16636
  function projectNotificationHistoryForCLI(response) {
16486
16637
  if (response === null || typeof response !== "object" || Array.isArray(response)) {
16487
16638
  return response;
16488
16639
  }
16489
- const record = response;
16490
- if (!Array.isArray(record.items)) return response;
16640
+ const record2 = response;
16641
+ if (!Array.isArray(record2.items)) return response;
16491
16642
  return {
16492
- ...record,
16493
- items: record.items.map((item) => {
16643
+ ...record2,
16644
+ items: record2.items.map((item) => {
16494
16645
  if (item === null || typeof item !== "object" || Array.isArray(item)) {
16495
16646
  return item;
16496
16647
  }
@@ -17000,7 +17151,7 @@ async function executeParsedCommand(client, parsedCommand, meta, deps) {
17000
17151
  const positionals = parsedCommand.positionals;
17001
17152
  if (group === "whoami") {
17002
17153
  const user = await client.user.me();
17003
- const record = projectUserProfileForCLI(
17154
+ const record2 = projectUserProfileForCLI(
17004
17155
  user
17005
17156
  );
17006
17157
  const version = meta?.cliVersion ?? CLI_VERSION;
@@ -17017,10 +17168,10 @@ async function executeParsedCommand(client, parsedCommand, meta, deps) {
17017
17168
  metaBlock.arrays_jwt = arraysJwtStatus;
17018
17169
  }
17019
17170
  const result = {
17020
- ...record,
17171
+ ...record2,
17021
17172
  _meta: metaBlock
17022
17173
  };
17023
- const minVersion = record.toolkit_min_version;
17174
+ const minVersion = record2.toolkit_min_version;
17024
17175
  if (typeof minVersion === "string" && version && version !== "dev" && isVersionOlderThan(version, minVersion)) {
17025
17176
  result._warning = `Warning: your toolkit version (${version}) is older than the minimum recommended version (${minVersion}). Please upgrade: npm install -g @alva-ai/toolkit`;
17026
17177
  }
@@ -17513,6 +17664,32 @@ async function executeParsedCommand(client, parsedCommand, meta, deps) {
17513
17664
  );
17514
17665
  }
17515
17666
  }
17667
+ case "for-you": {
17668
+ if (subcommand !== "list") {
17669
+ throw new CliUsageError("Expected for-you list", "for-you");
17670
+ }
17671
+ const params = {
17672
+ first: optionalBoundedIntegerFlag(
17673
+ flags,
17674
+ "limit",
17675
+ "for-you list",
17676
+ 1,
17677
+ 50
17678
+ ),
17679
+ after: flags.cursor,
17680
+ newerThan: flags["newer-than"],
17681
+ feedId: flags["feed-id"]
17682
+ };
17683
+ try {
17684
+ validateForYouListParams(params);
17685
+ } catch (error) {
17686
+ throw new CliUsageError(
17687
+ error instanceof Error ? error.message : String(error),
17688
+ "for-you"
17689
+ );
17690
+ }
17691
+ return client.forYou.list(params);
17692
+ }
17516
17693
  case "credits": {
17517
17694
  if (!subcommand)
17518
17695
  throw new CliUsageError("Missing subcommand for credits", "credits");