@alva-ai/toolkit 0.32.0-beta.0 → 0.32.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
+ CompanyNewsResource: () => CompanyNewsResource,
29
30
  ForYouResource: () => ForYouResource,
30
31
  MarketsResource: () => MarketsResource,
31
32
  PBSV_UPDATE_MESSAGE: () => PBSV_UPDATE_MESSAGE,
@@ -739,6 +740,89 @@ function requireFeedID(id) {
739
740
  return id;
740
741
  }
741
742
 
743
+ // src/resources/thesisPublication.ts
744
+ function record(value) {
745
+ return typeof value === "object" && value !== null && !Array.isArray(value);
746
+ }
747
+ function isPositiveInt64(value) {
748
+ return typeof value === "string" && /^[1-9]\d{0,18}$/.test(value) && BigInt(value) <= 9223372036854775807n;
749
+ }
750
+ var THESIS_PUBLICATION_FIELDS = `
751
+ thesisId playbookId authorVersionId materialVersionId itemKey
752
+ title body publishedAtMs changeKind visibility
753
+ closed archived note closingNote researchPaused
754
+ entityIds categoryIds
755
+ entityStances { entityId stance }
756
+ entities { id ticker name }
757
+ publisher {
758
+ __typename id displayName avatarUrl bio followersCount
759
+ viewerState { following }
760
+ ... on Person { slug }
761
+ ... on PublicUser { username }
762
+ }
763
+ medias { type coverUrl url }
764
+ signalFeed { id }
765
+ snapshotRelease {
766
+ versionId materialVersionId publishedAtMs changeKind
767
+ sourceRefs {
768
+ title sourceKind sourceContentId publicUrl sourceTimeMs locator
769
+ }
770
+ }
771
+ `;
772
+ function positiveInt64List(value) {
773
+ return Array.isArray(value) && value.every(isPositiveInt64);
774
+ }
775
+ function stanceList(value) {
776
+ return Array.isArray(value) && value.every(
777
+ (item) => record(item) && isPositiveInt64(item.entityId) && typeof item.stance === "string" && item.stance.trim() !== ""
778
+ );
779
+ }
780
+ function entityList(value) {
781
+ return Array.isArray(value) && value.every(
782
+ (item) => record(item) && typeof item.id === "string" && item.id.trim() !== "" && typeof item.ticker === "string" && typeof item.name === "string"
783
+ );
784
+ }
785
+ function mediaList(value) {
786
+ return Array.isArray(value) && value.every(
787
+ (item) => record(item) && typeof item.type === "string" && item.type.trim() !== "" && typeof item.coverUrl === "string" && (item.url === null || typeof item.url === "string")
788
+ );
789
+ }
790
+ function sourceRefList(value) {
791
+ return Array.isArray(value) && value.every(
792
+ (item) => record(item) && (item.title === null || typeof item.title === "string") && typeof item.sourceKind === "string" && typeof item.sourceContentId === "string" && typeof item.publicUrl === "string" && nullableMs(item.sourceTimeMs) && typeof item.locator === "string"
793
+ );
794
+ }
795
+ function nullableMs(value) {
796
+ return value === null || typeof value === "number" && Number.isFinite(value);
797
+ }
798
+ function snapshot(value) {
799
+ return record(value) && isPositiveInt64(value.versionId) && isPositiveInt64(value.materialVersionId) && typeof value.publishedAtMs === "number" && Number.isFinite(value.publishedAtMs) && typeof value.changeKind === "string" && value.changeKind.trim() !== "" && sourceRefList(value.sourceRefs);
800
+ }
801
+ function publisher(value) {
802
+ return record(value) && (value.__typename === "Person" && typeof value.slug === "string" || value.__typename === "PublicUser" && typeof value.username === "string") && typeof value.id === "string" && value.id.trim() !== "" && typeof value.displayName === "string" && typeof value.avatarUrl === "string" && typeof value.bio === "string" && typeof value.followersCount === "number" && Number.isInteger(value.followersCount) && record(value.viewerState) && (value.viewerState.following === null || typeof value.viewerState.following === "boolean");
803
+ }
804
+ function isThesisPublication(value) {
805
+ if (!record(value)) return false;
806
+ for (const field of [
807
+ "thesisId",
808
+ "playbookId",
809
+ "authorVersionId",
810
+ "materialVersionId"
811
+ ]) {
812
+ if (!isPositiveInt64(value[field])) return false;
813
+ }
814
+ if (typeof value.itemKey !== "string" || !value.itemKey.trim() || typeof value.title !== "string" || typeof value.body !== "string" || typeof value.publishedAtMs !== "number" || !Number.isFinite(value.publishedAtMs) || typeof value.changeKind !== "string" || !value.changeKind.trim() || typeof value.visibility !== "string" || typeof value.note !== "string" || typeof value.closingNote !== "string") {
815
+ return false;
816
+ }
817
+ for (const field of ["closed", "archived", "researchPaused"]) {
818
+ if (typeof value[field] !== "boolean") return false;
819
+ }
820
+ if (!positiveInt64List(value.entityIds) || !positiveInt64List(value.categoryIds) || !stanceList(value.entityStances) || !entityList(value.entities) || !mediaList(value.medias) || !publisher(value.publisher) || !snapshot(value.snapshotRelease)) {
821
+ return false;
822
+ }
823
+ return value.signalFeed === null || record(value.signalFeed) && isPositiveInt64(value.signalFeed.id);
824
+ }
825
+
742
826
  // src/resources/forYou.ts
743
827
  var FOR_YOU_QUERY = `
744
828
  query ToolkitForYou($input: FeedEntryConnectionInput) {
@@ -768,9 +852,6 @@ query ToolkitForYou($input: FeedEntryConnectionInput) {
768
852
  }
769
853
  }
770
854
  `.trim();
771
- function record(value) {
772
- return typeof value === "object" && value !== null && !Array.isArray(value);
773
- }
774
855
  function validateForYouListParams(params) {
775
856
  if (!record(params)) throw new Error("For You parameters must be an object");
776
857
  const first = params.first === void 0 ? 20 : params.first;
@@ -787,9 +868,6 @@ function validateForYouListParams(params) {
787
868
  throw new Error("feedId must be a positive decimal int64 string");
788
869
  }
789
870
  }
790
- function isPositiveInt64(value) {
791
- return typeof value === "string" && /^[1-9]\d{0,18}$/.test(value) && BigInt(value) <= 9223372036854775807n;
792
- }
793
871
  function invalidResponse() {
794
872
  throw new AlvaError(
795
873
  "GRAPHQL_INVALID_RESPONSE",
@@ -830,24 +908,7 @@ query ToolkitForYouTheses($input: ThesisRecommendationInput) {
830
908
  node {
831
909
  itemKey
832
910
  publication {
833
- thesisId playbookId authorVersionId materialVersionId itemKey
834
- title body publishedAtMs changeKind visibility
835
- closed archived note closingNote researchPaused
836
- entityIds categoryIds
837
- entityStances { entityId stance }
838
- entities { id ticker name }
839
- publisher {
840
- id displayName avatarUrl bio followersCount
841
- viewerState { following }
842
- }
843
- medias { type coverUrl url }
844
- signalFeed { id }
845
- snapshotRelease {
846
- versionId materialVersionId publishedAtMs changeKind
847
- sourceRefs {
848
- title sourceKind sourceContentId publicUrl sourceTimeMs locator
849
- }
850
- }
911
+ ${THESIS_PUBLICATION_FIELDS}
851
912
  }
852
913
  }
853
914
  }
@@ -909,59 +970,6 @@ function invalidPage() {
909
970
  502
910
971
  );
911
972
  }
912
- function positiveInt64List(value) {
913
- return Array.isArray(value) && value.every(isPositiveInt64);
914
- }
915
- function stanceList(value) {
916
- return Array.isArray(value) && value.every(
917
- (item) => record(item) && isPositiveInt64(item.entityId) && typeof item.stance === "string" && item.stance.trim() !== ""
918
- );
919
- }
920
- function entityList(value) {
921
- return Array.isArray(value) && value.every(
922
- (item) => record(item) && typeof item.id === "string" && item.id.trim() !== "" && typeof item.ticker === "string" && typeof item.name === "string"
923
- );
924
- }
925
- function mediaList(value) {
926
- return Array.isArray(value) && value.every(
927
- (item) => record(item) && typeof item.type === "string" && item.type.trim() !== "" && typeof item.coverUrl === "string" && (item.url === null || typeof item.url === "string")
928
- );
929
- }
930
- function sourceRefList(value) {
931
- return Array.isArray(value) && value.every(
932
- (item) => record(item) && (item.title === null || typeof item.title === "string") && typeof item.sourceKind === "string" && typeof item.sourceContentId === "string" && typeof item.publicUrl === "string" && nullableMs(item.sourceTimeMs) && typeof item.locator === "string"
933
- );
934
- }
935
- function nullableMs(value) {
936
- return value === null || typeof value === "number" && Number.isFinite(value);
937
- }
938
- function snapshot(value) {
939
- return record(value) && isPositiveInt64(value.versionId) && isPositiveInt64(value.materialVersionId) && typeof value.publishedAtMs === "number" && Number.isFinite(value.publishedAtMs) && typeof value.changeKind === "string" && value.changeKind.trim() !== "" && sourceRefList(value.sourceRefs);
940
- }
941
- function publisher(value) {
942
- return record(value) && typeof value.id === "string" && value.id.trim() !== "" && typeof value.displayName === "string" && typeof value.avatarUrl === "string" && typeof value.bio === "string" && typeof value.followersCount === "number" && Number.isInteger(value.followersCount) && record(value.viewerState) && (value.viewerState.following === null || typeof value.viewerState.following === "boolean");
943
- }
944
- function publication(value) {
945
- if (!record(value)) return false;
946
- for (const field of [
947
- "thesisId",
948
- "playbookId",
949
- "authorVersionId",
950
- "materialVersionId"
951
- ]) {
952
- if (!isPositiveInt64(value[field])) return false;
953
- }
954
- if (typeof value.itemKey !== "string" || !value.itemKey.trim() || typeof value.title !== "string" || typeof value.body !== "string" || typeof value.publishedAtMs !== "number" || !Number.isFinite(value.publishedAtMs) || typeof value.changeKind !== "string" || !value.changeKind.trim() || typeof value.visibility !== "string" || typeof value.note !== "string" || typeof value.closingNote !== "string") {
955
- return false;
956
- }
957
- for (const field of ["closed", "archived", "researchPaused"]) {
958
- if (typeof value[field] !== "boolean") return false;
959
- }
960
- if (!positiveInt64List(value.entityIds) || !positiveInt64List(value.categoryIds) || !stanceList(value.entityStances) || !entityList(value.entities) || !mediaList(value.medias) || !publisher(value.publisher) || !snapshot(value.snapshotRelease)) {
961
- return false;
962
- }
963
- return value.signalFeed === null || record(value.signalFeed) && isPositiveInt64(value.signalFeed.id);
964
- }
965
973
  function recommendationPage(value) {
966
974
  if (!record(value) || !Array.isArray(value.edges) || !record(value.pageInfo) || typeof value.listId !== "string" || typeof value.pageCursor !== "string" || typeof value.exhausted !== "boolean" || typeof value.scanLimited !== "boolean" || value.nextCursor !== null && typeof value.nextCursor !== "string") {
967
975
  return invalidPage();
@@ -971,7 +979,7 @@ function recommendationPage(value) {
971
979
  return invalidPage();
972
980
  }
973
981
  for (const edge of value.edges) {
974
- if (!record(edge) || typeof edge.cursor !== "string" || !edge.cursor.trim() || !record(edge.node) || typeof edge.node.itemKey !== "string" || !edge.node.itemKey.trim() || !publication(edge.node.publication)) {
982
+ if (!record(edge) || typeof edge.cursor !== "string" || !edge.cursor.trim() || !record(edge.node) || typeof edge.node.itemKey !== "string" || !edge.node.itemKey.trim() || !isThesisPublication(edge.node.publication)) {
975
983
  return invalidPage();
976
984
  }
977
985
  }
@@ -4072,10 +4080,10 @@ var StewardResource = class {
4072
4080
  if (!Number.isSafeInteger(windowSinceMs) || !Number.isSafeInteger(windowUntilMs) || windowSinceMs <= 0 || windowUntilMs <= windowSinceMs)
4073
4081
  throw emptyResponse();
4074
4082
  const items = page.edges.map((edge) => edge.node);
4075
- const nextCursor = page.pageInfo?.hasNextPage === true && page.pageInfo.endCursor ? page.pageInfo.endCursor : null;
4083
+ const nextCursor2 = page.pageInfo?.hasNextPage === true && page.pageInfo.endCursor ? page.pageInfo.endCursor : null;
4076
4084
  return {
4077
4085
  items,
4078
- nextCursor,
4086
+ nextCursor: nextCursor2,
4079
4087
  windowSinceMs,
4080
4088
  windowUntilMs
4081
4089
  };
@@ -4300,6 +4308,249 @@ var TradingPairsResource = class {
4300
4308
  }
4301
4309
  };
4302
4310
 
4311
+ // src/resources/thesisReads.ts
4312
+ var PAGE = "pageInfo { endCursor hasNextPage }";
4313
+ var PERSON = "__typename id slug displayName bio";
4314
+ var USER = "__typename id username displayName bio";
4315
+ var ENTITY = "__typename id ticker name kind assetClass venue { id name }";
4316
+ var AUTHOR_THESES = `theses(input: $input) {
4317
+ edges { cursor node { id latestRelease { thesisPublication { ${THESIS_PUBLICATION_FIELDS} } } } }
4318
+ ${PAGE}
4319
+ }`;
4320
+ var PERSON_QUERY = `query ToolkitPersonTheses($slug: String!, $input: ProfileThesisConnectionInput) {
4321
+ scope: person(slug: $slug) { ${PERSON} ${AUTHOR_THESES} }
4322
+ }`;
4323
+ var USER_QUERY = `query ToolkitUserTheses($username: String!, $input: ProfileThesisConnectionInput) {
4324
+ scope: publicUser(username: $username) { ${USER} ${AUTHOR_THESES} }
4325
+ }`;
4326
+ var ENTITY_QUERY = `query ToolkitEntityTheses($id: ID!, $input: EntityThesisConnectionInput) {
4327
+ market { scope: entity(input: { id: $id }) { ${ENTITY}
4328
+ theses(input: $input) { edges { cursor node { ${THESIS_PUBLICATION_FIELDS} } } ${PAGE} }
4329
+ } }
4330
+ }`;
4331
+ var PEOPLE_QUERY = `query ToolkitThesisPeople($query: String!) {
4332
+ search: people(input: { query: $query, first: 50 }) {
4333
+ edges { node { ${PERSON} } } pageInfo { hasNextPage }
4334
+ }
4335
+ }`;
4336
+ var ENTITIES_QUERY = `query ToolkitThesisEntities($query: String!) {
4337
+ market { search: entities(input: { query: $query, first: 50, byPrefix: false }) {
4338
+ edges { node { ${ENTITY} } } pageInfo { hasNextPage }
4339
+ } }
4340
+ }`;
4341
+ var RELATED_QUERY = `query ToolkitRelatedTheses($id: ID!, $input: RelatedThesisInput) {
4342
+ node(id: $id) { ... on Playbook { relatedTheses(input: $input) {
4343
+ state nextCursor
4344
+ edges { cursor node { itemKey score publication { ${THESIS_PUBLICATION_FIELDS} } } }
4345
+ } } }
4346
+ }`;
4347
+ var SELECTORS = [
4348
+ "person",
4349
+ "personName",
4350
+ "user",
4351
+ "ticker",
4352
+ "entityId"
4353
+ ];
4354
+ function validateThesisPageParams(params) {
4355
+ if (!record(params)) throw argument("Thesis parameters must be an object");
4356
+ const first = params.first === void 0 ? 10 : params.first;
4357
+ if (typeof first !== "number" || !Number.isInteger(first) || first < 1 || first > 50) {
4358
+ throw argument("first must be an integer between 1 and 50");
4359
+ }
4360
+ if (params.cursor !== void 0 && !nonempty(params.cursor)) {
4361
+ throw argument("cursor must be non-empty");
4362
+ }
4363
+ }
4364
+ function validateListThesesParams(params) {
4365
+ validateThesisPageParams(params);
4366
+ const chosen = SELECTORS.filter((key) => params[key] !== void 0);
4367
+ if (chosen.length !== 1) {
4368
+ throw argument(
4369
+ "Choose exactly one of person, personName, user, ticker or entityId"
4370
+ );
4371
+ }
4372
+ if (!nonempty(params[chosen[0]]))
4373
+ throw argument(`${chosen[0]} must be non-empty`);
4374
+ if (params.entityId !== void 0 && !isPositiveInt64(params.entityId)) {
4375
+ throw argument("entityId must be a positive int64 string");
4376
+ }
4377
+ if (params.status !== void 0 && params.status !== "ACTIVE" && params.status !== "ARCHIVED") {
4378
+ throw argument("status must be ACTIVE or ARCHIVED");
4379
+ }
4380
+ if (params.status !== void 0 && (params.ticker !== void 0 || params.entityId !== void 0)) {
4381
+ throw argument("status applies only to author lists");
4382
+ }
4383
+ }
4384
+ async function listTheses(client, params) {
4385
+ validateListThesesParams(params);
4386
+ client._requireAuth();
4387
+ const input = { first: params.first ?? 10, after: params.cursor };
4388
+ const entityId = params.ticker === void 0 ? params.entityId : (await resolveUnique(client, ENTITIES_QUERY, params.ticker, "Entity")).id;
4389
+ if (entityId !== void 0) {
4390
+ const data2 = await graphql(client, ENTITY_QUERY, { id: entityId, input });
4391
+ if (!record(data2.market)) throw invalid3();
4392
+ return thesisPage(
4393
+ data2.market.scope,
4394
+ (node) => isThesisPublication(node) ? { playbookId: node.playbookId, publication: node } : void 0
4395
+ );
4396
+ }
4397
+ const profileInput = { ...input, status: params.status };
4398
+ const slug = params.personName === void 0 ? params.person : (await resolveUnique(client, PEOPLE_QUERY, params.personName, "Person")).slug;
4399
+ const data = slug === void 0 ? await graphql(client, USER_QUERY, {
4400
+ username: params.user,
4401
+ input: profileInput
4402
+ }) : await graphql(client, PERSON_QUERY, { slug, input: profileInput });
4403
+ return thesisPage(data.scope, (node) => {
4404
+ if (!isPositiveInt64(node.id)) return void 0;
4405
+ const release = node.latestRelease;
4406
+ if (release === null) return { playbookId: node.id, publication: null };
4407
+ if (!record(release)) return void 0;
4408
+ const publication = release.thesisPublication;
4409
+ if (publication !== null && !isThesisPublication(publication))
4410
+ return void 0;
4411
+ return { playbookId: node.id, publication };
4412
+ });
4413
+ }
4414
+ async function relatedTheses(client, id, params = {}) {
4415
+ validateThesisPageParams(params);
4416
+ if (!isPositiveInt64(id))
4417
+ throw argument("id must be an internal positive int64 Playbook ID");
4418
+ client._requireAuth();
4419
+ const data = await graphql(client, RELATED_QUERY, {
4420
+ id: `Playbook:${id}`,
4421
+ input: { first: params.first ?? 10, after: params.cursor }
4422
+ });
4423
+ if (data.node === null) throw notFound();
4424
+ if (!record(data.node)) throw invalid3();
4425
+ const value = data.node.relatedTheses;
4426
+ if (!record(value) || !["GENERATING", "READY", "FAILED"].includes(value.state) || value.nextCursor !== null && !nonempty(value.nextCursor))
4427
+ throw invalid3();
4428
+ for (const edge of edges(value)) {
4429
+ if (!nonempty(edge.node.itemKey) || typeof edge.node.score !== "number" || !isThesisPublication(edge.node.publication))
4430
+ throw invalid3();
4431
+ }
4432
+ return {
4433
+ state: value.state,
4434
+ edges: value.edges,
4435
+ nextCursor: value.nextCursor
4436
+ };
4437
+ }
4438
+ function thesisPage(value, readNode) {
4439
+ if (value === null) throw notFound();
4440
+ const scope = readScope(value);
4441
+ if (!record(value) || !record(value.theses)) throw invalid3();
4442
+ const page = value.theses;
4443
+ const items = edges(page).map((edge) => {
4444
+ const node = readNode(edge.node);
4445
+ if (node === void 0) throw invalid3();
4446
+ return { cursor: edge.cursor, node };
4447
+ });
4448
+ return { scope, edges: items, nextCursor: nextCursor(page) };
4449
+ }
4450
+ async function resolveUnique(client, document, text, kind) {
4451
+ const data = await graphql(client, document, { query: text });
4452
+ const search = record(data.market) ? data.market.search : data.search;
4453
+ if (!record(search) || !Array.isArray(search.edges) || !record(search.pageInfo))
4454
+ throw invalid3();
4455
+ const candidates = search.edges.map(
4456
+ (edge) => readScope(record(edge) ? edge.node : void 0)
4457
+ );
4458
+ if (!candidates.every((c) => c.__typename === kind))
4459
+ throw invalid3();
4460
+ const more = search.pageInfo.hasNextPage === true;
4461
+ if (candidates.length === 1 && !more) return candidates[0];
4462
+ if (candidates.length === 0 && !more) throw notFound();
4463
+ throw new AlvaError(
4464
+ "AMBIGUOUS_IDENTITY",
4465
+ // ALPI Dispatch currently forwards only Error.message, not details.
4466
+ // Keep candidate identities available through that existing boundary too.
4467
+ `Choose an exact identity before reading theses. Candidates: ${JSON.stringify(candidates)}${more ? " More matches exist; refine the name or ticker." : ""}`,
4468
+ 400,
4469
+ { candidates, more }
4470
+ );
4471
+ }
4472
+ function readScope(value) {
4473
+ if (!record(value) || !nonempty(value.id)) throw invalid3();
4474
+ if (value.__typename === "Entity") {
4475
+ if (!["ticker", "name", "kind", "assetClass"].every(
4476
+ (key) => typeof value[key] === "string"
4477
+ ) || value.venue !== null && (!record(value.venue) || !nonempty(value.venue.id) || typeof value.venue.name !== "string"))
4478
+ throw invalid3();
4479
+ } else if (typeof value.displayName !== "string" || typeof value.bio !== "string" || !(value.__typename === "Person" && nonempty(value.slug) || value.__typename === "PublicUser" && nonempty(value.username))) {
4480
+ throw invalid3();
4481
+ }
4482
+ const scope = { ...value };
4483
+ delete scope.theses;
4484
+ return scope;
4485
+ }
4486
+ function edges(value) {
4487
+ if (!Array.isArray(value.edges) || !value.edges.every(
4488
+ (edge) => record(edge) && nonempty(edge.cursor) && record(edge.node)
4489
+ ))
4490
+ throw invalid3();
4491
+ return value.edges;
4492
+ }
4493
+ function nextCursor(page) {
4494
+ const info = page.pageInfo;
4495
+ if (!record(info) || typeof info.hasNextPage !== "boolean" || info.hasNextPage && !nonempty(info.endCursor))
4496
+ throw invalid3();
4497
+ return info.hasNextPage ? info.endCursor : null;
4498
+ }
4499
+ async function graphql(client, document, variables) {
4500
+ const response = await client._request("POST", "/query", {
4501
+ body: { query: document, variables }
4502
+ });
4503
+ if (!record(response)) throw invalid3();
4504
+ if (response.errors !== void 0) {
4505
+ if (!Array.isArray(response.errors)) throw invalid3();
4506
+ if (response.errors.length) {
4507
+ const messages = response.errors.flatMap(
4508
+ (error) => record(error) && typeof error.message === "string" ? [error.message] : []
4509
+ );
4510
+ const codes = new Set(
4511
+ response.errors.map(
4512
+ (error) => record(error) && record(error.extensions) ? error.extensions.code : void 0
4513
+ )
4514
+ );
4515
+ const [code] = codes;
4516
+ const status = codes.size === 1 && typeof code === "string" ? CANONICAL_STATUS.get(code) : void 0;
4517
+ throw new AlvaError(
4518
+ status === void 0 ? "GRAPHQL_ERROR" : String(code),
4519
+ messages.join("; ") || "GraphQL request failed",
4520
+ status ?? 400,
4521
+ { errors: response.errors }
4522
+ );
4523
+ }
4524
+ }
4525
+ if (!record(response.data)) throw invalid3();
4526
+ return response.data;
4527
+ }
4528
+ var CANONICAL_STATUS = /* @__PURE__ */ new Map([
4529
+ ["NOT_FOUND", 404],
4530
+ ["PERMISSION_DENIED", 403],
4531
+ ["UNAUTHENTICATED", 401]
4532
+ ]);
4533
+ function nonempty(value) {
4534
+ return typeof value === "string" && value.trim().length > 0;
4535
+ }
4536
+ function argument(message) {
4537
+ return new AlvaError("INVALID_ARGUMENT", message, 400);
4538
+ }
4539
+ function invalid3() {
4540
+ return new AlvaError(
4541
+ "GRAPHQL_INVALID_RESPONSE",
4542
+ "Invalid Thesis read response",
4543
+ 502
4544
+ );
4545
+ }
4546
+ function notFound() {
4547
+ return new AlvaError(
4548
+ "NOT_FOUND",
4549
+ "No visible matching identity or Thesis found",
4550
+ 404
4551
+ );
4552
+ }
4553
+
4303
4554
  // src/resources/theses.ts
4304
4555
  var MAX_SIGNED_INT64 = 9223372036854775807n;
4305
4556
  var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
@@ -4310,6 +4561,14 @@ var ThesesResource = class {
4310
4561
  this.client = client;
4311
4562
  }
4312
4563
  client;
4564
+ /** One visible page; no automatic pagination or content truncation. */
4565
+ list(params) {
4566
+ return listTheses(this.client, params);
4567
+ }
4568
+ /** Related publications always use the current source version. */
4569
+ related(id, params = {}) {
4570
+ return relatedTheses(this.client, id, params);
4571
+ }
4313
4572
  async assetCandidates(text) {
4314
4573
  this.client._requireAuth();
4315
4574
  const source = requireBody(text);
@@ -4716,11 +4975,11 @@ function thesisSignalsResponse(response, thesisID, first) {
4716
4975
  signal: mappedSignal
4717
4976
  };
4718
4977
  });
4719
- const nextCursor = responseText(response.next_cursor, "next_cursor");
4720
- if (nextCursor && nextCursor !== entries[entries.length - 1]?.cursor) {
4978
+ const nextCursor2 = responseText(response.next_cursor, "next_cursor");
4979
+ if (nextCursor2 && nextCursor2 !== entries[entries.length - 1]?.cursor) {
4721
4980
  throw invalidResponse2("next_cursor must match the final entry");
4722
4981
  }
4723
- return { research: status, entries, next_cursor: nextCursor };
4982
+ return { research: status, entries, next_cursor: nextCursor2 };
4724
4983
  }
4725
4984
  function responseNonnegativeInteger(value, field) {
4726
4985
  if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
@@ -4887,6 +5146,101 @@ function invalidResponse2(message) {
4887
5146
  return new AlvaError("INVALID_RESPONSE", message, 502);
4888
5147
  }
4889
5148
 
5149
+ // src/resources/companyNews.ts
5150
+ var CREATE_COMPANY_NEWS = `mutation CreateCompanyNews($input: CompanyNewsFeedInput!) {
5151
+ companyNews {
5152
+ createFeed(input: $input) { id producer { id } }
5153
+ }
5154
+ }`;
5155
+ var GRAPHQL_STATUS_BY_CODE3 = {
5156
+ INVALID_ARGUMENT: 400,
5157
+ UNAUTHENTICATED: 401,
5158
+ PERMISSION_DENIED: 403,
5159
+ NOT_FOUND: 404,
5160
+ ALREADY_EXISTS: 409,
5161
+ ABORTED: 409,
5162
+ FAILED_PRECONDITION: 412,
5163
+ RESOURCE_EXHAUSTED: 429,
5164
+ INTERNAL: 500,
5165
+ UNKNOWN: 500,
5166
+ DATA_LOSS: 500,
5167
+ UNAVAILABLE: 503,
5168
+ DEADLINE_EXCEEDED: 504
5169
+ };
5170
+ function validateCompanyNewsCreateParams(params) {
5171
+ if (typeof params?.name !== "string" || params.name.trim() !== params.name || !/^[a-zA-Z0-9][a-zA-Z0-9-]{0,63}$/.test(params.name) || params.name === "news-lane") {
5172
+ throw new AlvaError(
5173
+ "INVALID_ARGUMENT",
5174
+ "name must be 1-64 alphanumeric/hyphen characters and distinct from news-lane",
5175
+ 400
5176
+ );
5177
+ }
5178
+ if (!Array.isArray(params.tickers) || params.tickers.length < 1 || params.tickers.length > 1e3 || params.tickers.some(
5179
+ (ticker) => typeof ticker !== "string" || ticker.trim() !== ticker || !/^[A-Z0-9][A-Z0-9.-]{0,19}$/.test(ticker)
5180
+ ) || new Set(params.tickers).size !== params.tickers.length) {
5181
+ throw new AlvaError(
5182
+ "INVALID_ARGUMENT",
5183
+ "tickers must contain 1-1000 unique uppercase symbols",
5184
+ 400
5185
+ );
5186
+ }
5187
+ for (const [name, maximum] of [
5188
+ ["initial_lookback_hours", 168],
5189
+ ["page_size", 100]
5190
+ ]) {
5191
+ const value = params[name];
5192
+ if (value !== void 0 && (!Number.isInteger(value) || value < 0 || value > maximum)) {
5193
+ throw new AlvaError(
5194
+ "INVALID_ARGUMENT",
5195
+ `${name} must be an integer from 0 to ${maximum} (0 selects the default)`,
5196
+ 400
5197
+ );
5198
+ }
5199
+ }
5200
+ }
5201
+ var CompanyNewsResource = class {
5202
+ constructor(client) {
5203
+ this.client = client;
5204
+ }
5205
+ client;
5206
+ async create(params) {
5207
+ this.client._requireAuth();
5208
+ validateCompanyNewsCreateParams(params);
5209
+ const body = {
5210
+ name: params.name,
5211
+ tickers: params.tickers,
5212
+ ...params.initial_lookback_hours === void 0 ? {} : { initialLookbackHours: params.initial_lookback_hours },
5213
+ ...params.page_size === void 0 ? {} : { pageSize: params.page_size }
5214
+ };
5215
+ const graph = await this.client._request("POST", "/query", {
5216
+ body: { query: CREATE_COMPANY_NEWS, variables: { input: body } }
5217
+ });
5218
+ if (Array.isArray(graph?.errors) && graph.errors.length > 0) {
5219
+ const codes = graph.errors.map((error) => error?.extensions?.code);
5220
+ const code = typeof codes[0] === "string" && codes.every((value) => value === codes[0]) ? codes[0] : "GRAPHQL_ERROR";
5221
+ throw new AlvaError(
5222
+ code,
5223
+ graph.errors.map((error) => error?.message).filter(Boolean).join("; ") || "Company News creation failed",
5224
+ GRAPHQL_STATUS_BY_CODE3[code] ?? 502,
5225
+ { errors: graph.errors }
5226
+ );
5227
+ }
5228
+ const feed = graph?.data?.companyNews?.createFeed;
5229
+ const response = { feed_id: feed?.id, cronjob_id: feed?.producer?.id };
5230
+ if (typeof response !== "object" || response === null || !("feed_id" in response) || !validID(response.feed_id) || !("cronjob_id" in response) || !validID(response.cronjob_id)) {
5231
+ throw new AlvaError(
5232
+ "INVALID_RESPONSE",
5233
+ "company news response must contain decimal int64 feed_id and cronjob_id strings",
5234
+ 502
5235
+ );
5236
+ }
5237
+ return { feed_id: response.feed_id, cronjob_id: response.cronjob_id };
5238
+ }
5239
+ };
5240
+ function validID(value) {
5241
+ return typeof value === "string" && value.trim() === value && /^[1-9]\d{0,18}$/.test(value) && BigInt(value) <= 9223372036854775807n;
5242
+ }
5243
+
4890
5244
  // src/client.ts
4891
5245
  var DEFAULT_BASE_URL = "https://api-llm.prd.alva.ai";
4892
5246
  var DEFAULT_ARRAYS_BASE_URL = "https://data-tools.prd.space.id";
@@ -5002,6 +5356,7 @@ var AlvaClient = class {
5002
5356
  _steward;
5003
5357
  _tradingPairs;
5004
5358
  _theses;
5359
+ _companyNews;
5005
5360
  constructor(config) {
5006
5361
  this.baseUrl = config.baseUrl ?? DEFAULT_BASE_URL;
5007
5362
  this.arraysBaseUrl = config.arraysBaseUrl ?? DEFAULT_ARRAYS_BASE_URL;
@@ -5112,6 +5467,9 @@ var AlvaClient = class {
5112
5467
  get theses() {
5113
5468
  return this._theses ??= new ThesesResource(this);
5114
5469
  }
5470
+ get companyNews() {
5471
+ return this._companyNews ??= new CompanyNewsResource(this);
5472
+ }
5115
5473
  _requireAuth() {
5116
5474
  if (!this.pbsvToken && !this.viewer_token && !this.apiKey) {
5117
5475
  throw new AlvaError(
@@ -5728,7 +6086,7 @@ var installPlaybookRuntime = (targetWindow) => {
5728
6086
  };
5729
6087
 
5730
6088
  // src/index.ts
5731
- var VERSION = true ? "0.32.0-beta.0" : "dev";
6089
+ var VERSION = true ? "0.32.0" : "dev";
5732
6090
  // Annotate the CommonJS export names for ESM import in node:
5733
6091
  0 && (module.exports = {
5734
6092
  AlertsResource,
@@ -5737,6 +6095,7 @@ var VERSION = true ? "0.32.0-beta.0" : "dev";
5737
6095
  AutomationAlertDeliveryResource,
5738
6096
  AutomationResource,
5739
6097
  CliUsageError,
6098
+ CompanyNewsResource,
5740
6099
  ForYouResource,
5741
6100
  MarketsResource,
5742
6101
  PBSV_UPDATE_MESSAGE,