@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/index.cjs CHANGED
@@ -26,6 +26,7 @@ __export(src_exports, {
26
26
  AutomationAlertDeliveryResource: () => AutomationAlertDeliveryResource,
27
27
  AutomationResource: () => AutomationResource,
28
28
  CliUsageError: () => CliUsageError,
29
+ ForYouResource: () => ForYouResource,
29
30
  MarketsResource: () => MarketsResource,
30
31
  PBSV_UPDATE_MESSAGE: () => PBSV_UPDATE_MESSAGE,
31
32
  SUBSCRIBE_MANAGE_MESSAGE: () => SUBSCRIBE_MANAGE_MESSAGE,
@@ -735,6 +736,134 @@ function requireFeedID(id) {
735
736
  return id;
736
737
  }
737
738
 
739
+ // src/resources/forYou.ts
740
+ var FOR_YOU_QUERY = `
741
+ query ToolkitForYou($input: FeedEntryConnectionInput) {
742
+ viewer {
743
+ forYou(input: $input) {
744
+ edges {
745
+ cursor
746
+ node {
747
+ id
748
+ feed { id }
749
+ major { id feedId number }
750
+ displayName source eventTimeMs publishedAtMs title body
751
+ actions { type label url prompt }
752
+ presentation {
753
+ card {
754
+ accentColor url thumbnailUrl footer
755
+ fields { label value inline }
756
+ }
757
+ }
758
+ tickers { symbol logoUrl sentiment }
759
+ media { type coverUrl url }
760
+ sources { type url iconUrl title subtitle description publishedAtMs }
761
+ }
762
+ }
763
+ pageInfo { startCursor endCursor hasNextPage hasPreviousPage }
764
+ }
765
+ }
766
+ }
767
+ `.trim();
768
+ function record(value) {
769
+ return typeof value === "object" && value !== null && !Array.isArray(value);
770
+ }
771
+ function validateForYouListParams(params) {
772
+ if (!record(params)) throw new Error("For You parameters must be an object");
773
+ const first = params.first === void 0 ? 20 : params.first;
774
+ if (typeof first !== "number" || !Number.isInteger(first) || first < 1 || first > 50) {
775
+ throw new Error("first must be an integer between 1 and 50");
776
+ }
777
+ for (const field of ["after", "newerThan"]) {
778
+ const value = params[field];
779
+ if (value !== void 0 && (typeof value !== "string" || !value.trim())) {
780
+ throw new Error(`${field} must be a non-empty cursor`);
781
+ }
782
+ }
783
+ if (params.feedId !== void 0 && !isPositiveInt64(params.feedId)) {
784
+ throw new Error("feedId must be a positive decimal int64 string");
785
+ }
786
+ }
787
+ function isPositiveInt64(value) {
788
+ return typeof value === "string" && /^[1-9]\d{0,18}$/.test(value) && BigInt(value) <= 9223372036854775807n;
789
+ }
790
+ function invalidResponse() {
791
+ throw new AlvaError(
792
+ "GRAPHQL_INVALID_RESPONSE",
793
+ "GraphQL returned an invalid For You connection",
794
+ 502
795
+ );
796
+ }
797
+ function connection(value) {
798
+ if (!record(value) || !Array.isArray(value.edges) || !record(value.pageInfo)) {
799
+ return invalidResponse();
800
+ }
801
+ const page = value.pageInfo;
802
+ if (typeof page.startCursor !== "string" || typeof page.endCursor !== "string" || typeof page.hasNextPage !== "boolean" || typeof page.hasPreviousPage !== "boolean") {
803
+ return invalidResponse();
804
+ }
805
+ for (const edge of value.edges) {
806
+ if (!record(edge) || typeof edge.cursor !== "string" || !edge.cursor.trim() || !record(edge.node))
807
+ return invalidResponse();
808
+ const node = edge.node;
809
+ 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") {
810
+ return invalidResponse();
811
+ }
812
+ }
813
+ const first = value.edges[0];
814
+ const last = value.edges[value.edges.length - 1];
815
+ if (page.startCursor !== (first?.cursor ?? "") || page.endCursor !== (last?.cursor ?? "") || value.edges.length === 0 && page.hasNextPage)
816
+ return invalidResponse();
817
+ return value;
818
+ }
819
+ var ForYouResource = class {
820
+ constructor(client) {
821
+ this.client = client;
822
+ }
823
+ client;
824
+ /** One newest-first page. Does not truncate content or advance a watermark. */
825
+ async list(params = {}) {
826
+ validateForYouListParams(params);
827
+ this.client._requireAuth();
828
+ const response = await this.client._request("POST", "/query", {
829
+ body: {
830
+ query: FOR_YOU_QUERY,
831
+ variables: {
832
+ input: {
833
+ first: params.first ?? 20,
834
+ after: params.after,
835
+ newerThan: params.newerThan,
836
+ feedId: params.feedId
837
+ }
838
+ }
839
+ }
840
+ });
841
+ if (!record(response)) return invalidResponse();
842
+ if (response.errors !== void 0) {
843
+ if (!Array.isArray(response.errors)) return invalidResponse();
844
+ if (response.errors.length > 0) {
845
+ const messages = response.errors.flatMap(
846
+ (error) => record(error) && typeof error.message === "string" ? [error.message] : []
847
+ );
848
+ throw new AlvaError(
849
+ "GRAPHQL_ERROR",
850
+ messages.join("; ") || "GraphQL request failed",
851
+ 400,
852
+ { errors: response.errors }
853
+ );
854
+ }
855
+ }
856
+ if (!record(response.data) || !record(response.data.viewer) || response.data.viewer.forYou == null) {
857
+ throw new AlvaError(
858
+ "GRAPHQL_EMPTY_RESPONSE",
859
+ "GraphQL response did not include viewer.forYou",
860
+ 502
861
+ );
862
+ }
863
+ return connection(response.data.viewer.forYou);
864
+ }
865
+ };
866
+
738
867
  // src/resources/automation.ts
739
868
  var AUTOMATION_ALERT_DELIVERY_QUERY = `
740
869
  query ToolkitAutomationAlertDelivery($automationId: ID!) {
@@ -3247,14 +3376,14 @@ var SchedulesResource = class {
3247
3376
  LIST_SCHEDULES,
3248
3377
  { channelId: id, after }
3249
3378
  );
3250
- const connection = data.viewer?.channel?.schedules;
3251
- if (!connection?.edges) throw scheduleNotFound();
3252
- for (const edge of connection.edges) {
3379
+ const connection2 = data.viewer?.channel?.schedules;
3380
+ if (!connection2?.edges) throw scheduleNotFound();
3381
+ for (const edge of connection2.edges) {
3253
3382
  if (!edge?.node) throw scheduleEmptyResponse();
3254
3383
  schedules.push(fromWireSchedule(edge.node));
3255
3384
  }
3256
- if (connection.pageInfo?.hasNextPage !== true) return schedules;
3257
- const next = connection.pageInfo.endCursor;
3385
+ if (connection2.pageInfo?.hasNextPage !== true) return schedules;
3386
+ const next = connection2.pageInfo.endCursor;
3258
3387
  if (!next || seenCursors.has(next)) throw scheduleEmptyResponse();
3259
3388
  seenCursors.add(next);
3260
3389
  after = next;
@@ -3653,12 +3782,12 @@ function dedupe(candidates) {
3653
3782
  });
3654
3783
  }
3655
3784
  function resolveFilters(params) {
3656
- const record = isRecord(params) ? params : {};
3785
+ const record2 = isRecord(params) ? params : {};
3657
3786
  return {
3658
- market: typeof record.market === "string" ? record.market : void 0,
3659
- instrumentType: typeof record.instrumentType === "string" ? record.instrumentType : void 0,
3660
- underlyingType: typeof record.underlyingType === "string" ? record.underlyingType : void 0,
3661
- quote: typeof record.quote === "string" ? record.quote : void 0
3787
+ market: typeof record2.market === "string" ? record2.market : void 0,
3788
+ instrumentType: typeof record2.instrumentType === "string" ? record2.instrumentType : void 0,
3789
+ underlyingType: typeof record2.underlyingType === "string" ? record2.underlyingType : void 0,
3790
+ quote: typeof record2.quote === "string" ? record2.quote : void 0
3662
3791
  };
3663
3792
  }
3664
3793
  function pairSearchParams(pair, params) {
@@ -3706,11 +3835,11 @@ var TradingPairsResource = class {
3706
3835
  return { query, candidates };
3707
3836
  }
3708
3837
  async resolve(params) {
3709
- const record = isRecord(params) ? params : {};
3710
- const pair = typeof record.pair === "string" ? record.pair.trim() : void 0;
3838
+ const record2 = isRecord(params) ? params : {};
3839
+ const pair = typeof record2.pair === "string" ? record2.pair.trim() : void 0;
3711
3840
  const filters = resolveFilters(params);
3712
3841
  const searchParams = pair === void 0 ? {
3713
- symbol: typeof record.symbol === "string" ? record.symbol : "",
3842
+ symbol: typeof record2.symbol === "string" ? record2.symbol : "",
3714
3843
  ...filters
3715
3844
  } : pairSearchParams(pair, filters);
3716
3845
  const result = await this.search(searchParams);
@@ -3821,6 +3950,7 @@ var AlvaClient = class {
3821
3950
  _serviceAccount;
3822
3951
  _release;
3823
3952
  _feed;
3953
+ _forYou;
3824
3954
  _automation;
3825
3955
  _playbooks;
3826
3956
  _secrets;
@@ -3957,6 +4087,9 @@ var AlvaClient = class {
3957
4087
  );
3958
4088
  }
3959
4089
  }
4090
+ get forYou() {
4091
+ return this._forYou ??= new ForYouResource(this);
4092
+ }
3960
4093
  async _request(method, path, options) {
3961
4094
  const baseUrl = options?.baseUrl ?? this.baseUrl;
3962
4095
  let url = `${baseUrl}${path}`;
@@ -4561,7 +4694,7 @@ var installPlaybookRuntime = (targetWindow) => {
4561
4694
  };
4562
4695
 
4563
4696
  // src/index.ts
4564
- var VERSION = true ? "0.27.0" : "dev";
4697
+ var VERSION = true ? "0.28.0" : "dev";
4565
4698
  // Annotate the CommonJS export names for ESM import in node:
4566
4699
  0 && (module.exports = {
4567
4700
  AlertsResource,
@@ -4570,6 +4703,7 @@ var VERSION = true ? "0.27.0" : "dev";
4570
4703
  AutomationAlertDeliveryResource,
4571
4704
  AutomationResource,
4572
4705
  CliUsageError,
4706
+ ForYouResource,
4573
4707
  MarketsResource,
4574
4708
  PBSV_UPDATE_MESSAGE,
4575
4709
  SUBSCRIBE_MANAGE_MESSAGE,