@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/README.md +61 -1
- package/dist/browser.global.js +76 -44
- package/dist/browser.global.js.map +1 -1
- package/dist/cli.d.ts +174 -66
- package/dist/cli.js +580 -94
- package/dist/cli.js.map +1 -1
- package/dist/dispatch.d.ts +174 -66
- package/dist/dispatch.js +328 -37
- package/dist/dispatch.js.map +1 -1
- package/dist/index.cjs +443 -84
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +175 -67
- package/dist/index.d.ts +175 -67
- package/dist/index.js +442 -84
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -674,6 +674,89 @@ function requireFeedID(id) {
|
|
|
674
674
|
return id;
|
|
675
675
|
}
|
|
676
676
|
|
|
677
|
+
// src/resources/thesisPublication.ts
|
|
678
|
+
function record(value) {
|
|
679
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
680
|
+
}
|
|
681
|
+
function isPositiveInt64(value) {
|
|
682
|
+
return typeof value === "string" && /^[1-9]\d{0,18}$/.test(value) && BigInt(value) <= 9223372036854775807n;
|
|
683
|
+
}
|
|
684
|
+
var THESIS_PUBLICATION_FIELDS = `
|
|
685
|
+
thesisId playbookId authorVersionId materialVersionId itemKey
|
|
686
|
+
title body publishedAtMs changeKind visibility
|
|
687
|
+
closed archived note closingNote researchPaused
|
|
688
|
+
entityIds categoryIds
|
|
689
|
+
entityStances { entityId stance }
|
|
690
|
+
entities { id ticker name }
|
|
691
|
+
publisher {
|
|
692
|
+
__typename id displayName avatarUrl bio followersCount
|
|
693
|
+
viewerState { following }
|
|
694
|
+
... on Person { slug }
|
|
695
|
+
... on PublicUser { username }
|
|
696
|
+
}
|
|
697
|
+
medias { type coverUrl url }
|
|
698
|
+
signalFeed { id }
|
|
699
|
+
snapshotRelease {
|
|
700
|
+
versionId materialVersionId publishedAtMs changeKind
|
|
701
|
+
sourceRefs {
|
|
702
|
+
title sourceKind sourceContentId publicUrl sourceTimeMs locator
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
`;
|
|
706
|
+
function positiveInt64List(value) {
|
|
707
|
+
return Array.isArray(value) && value.every(isPositiveInt64);
|
|
708
|
+
}
|
|
709
|
+
function stanceList(value) {
|
|
710
|
+
return Array.isArray(value) && value.every(
|
|
711
|
+
(item) => record(item) && isPositiveInt64(item.entityId) && typeof item.stance === "string" && item.stance.trim() !== ""
|
|
712
|
+
);
|
|
713
|
+
}
|
|
714
|
+
function entityList(value) {
|
|
715
|
+
return Array.isArray(value) && value.every(
|
|
716
|
+
(item) => record(item) && typeof item.id === "string" && item.id.trim() !== "" && typeof item.ticker === "string" && typeof item.name === "string"
|
|
717
|
+
);
|
|
718
|
+
}
|
|
719
|
+
function mediaList(value) {
|
|
720
|
+
return Array.isArray(value) && value.every(
|
|
721
|
+
(item) => record(item) && typeof item.type === "string" && item.type.trim() !== "" && typeof item.coverUrl === "string" && (item.url === null || typeof item.url === "string")
|
|
722
|
+
);
|
|
723
|
+
}
|
|
724
|
+
function sourceRefList(value) {
|
|
725
|
+
return Array.isArray(value) && value.every(
|
|
726
|
+
(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"
|
|
727
|
+
);
|
|
728
|
+
}
|
|
729
|
+
function nullableMs(value) {
|
|
730
|
+
return value === null || typeof value === "number" && Number.isFinite(value);
|
|
731
|
+
}
|
|
732
|
+
function snapshot(value) {
|
|
733
|
+
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);
|
|
734
|
+
}
|
|
735
|
+
function publisher(value) {
|
|
736
|
+
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");
|
|
737
|
+
}
|
|
738
|
+
function isThesisPublication(value) {
|
|
739
|
+
if (!record(value)) return false;
|
|
740
|
+
for (const field of [
|
|
741
|
+
"thesisId",
|
|
742
|
+
"playbookId",
|
|
743
|
+
"authorVersionId",
|
|
744
|
+
"materialVersionId"
|
|
745
|
+
]) {
|
|
746
|
+
if (!isPositiveInt64(value[field])) return false;
|
|
747
|
+
}
|
|
748
|
+
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") {
|
|
749
|
+
return false;
|
|
750
|
+
}
|
|
751
|
+
for (const field of ["closed", "archived", "researchPaused"]) {
|
|
752
|
+
if (typeof value[field] !== "boolean") return false;
|
|
753
|
+
}
|
|
754
|
+
if (!positiveInt64List(value.entityIds) || !positiveInt64List(value.categoryIds) || !stanceList(value.entityStances) || !entityList(value.entities) || !mediaList(value.medias) || !publisher(value.publisher) || !snapshot(value.snapshotRelease)) {
|
|
755
|
+
return false;
|
|
756
|
+
}
|
|
757
|
+
return value.signalFeed === null || record(value.signalFeed) && isPositiveInt64(value.signalFeed.id);
|
|
758
|
+
}
|
|
759
|
+
|
|
677
760
|
// src/resources/forYou.ts
|
|
678
761
|
var FOR_YOU_QUERY = `
|
|
679
762
|
query ToolkitForYou($input: FeedEntryConnectionInput) {
|
|
@@ -703,9 +786,6 @@ query ToolkitForYou($input: FeedEntryConnectionInput) {
|
|
|
703
786
|
}
|
|
704
787
|
}
|
|
705
788
|
`.trim();
|
|
706
|
-
function record(value) {
|
|
707
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
708
|
-
}
|
|
709
789
|
function validateForYouListParams(params) {
|
|
710
790
|
if (!record(params)) throw new Error("For You parameters must be an object");
|
|
711
791
|
const first = params.first === void 0 ? 20 : params.first;
|
|
@@ -722,9 +802,6 @@ function validateForYouListParams(params) {
|
|
|
722
802
|
throw new Error("feedId must be a positive decimal int64 string");
|
|
723
803
|
}
|
|
724
804
|
}
|
|
725
|
-
function isPositiveInt64(value) {
|
|
726
|
-
return typeof value === "string" && /^[1-9]\d{0,18}$/.test(value) && BigInt(value) <= 9223372036854775807n;
|
|
727
|
-
}
|
|
728
805
|
function invalidResponse() {
|
|
729
806
|
throw new AlvaError(
|
|
730
807
|
"GRAPHQL_INVALID_RESPONSE",
|
|
@@ -765,24 +842,7 @@ query ToolkitForYouTheses($input: ThesisRecommendationInput) {
|
|
|
765
842
|
node {
|
|
766
843
|
itemKey
|
|
767
844
|
publication {
|
|
768
|
-
|
|
769
|
-
title body publishedAtMs changeKind visibility
|
|
770
|
-
closed archived note closingNote researchPaused
|
|
771
|
-
entityIds categoryIds
|
|
772
|
-
entityStances { entityId stance }
|
|
773
|
-
entities { id ticker name }
|
|
774
|
-
publisher {
|
|
775
|
-
id displayName avatarUrl bio followersCount
|
|
776
|
-
viewerState { following }
|
|
777
|
-
}
|
|
778
|
-
medias { type coverUrl url }
|
|
779
|
-
signalFeed { id }
|
|
780
|
-
snapshotRelease {
|
|
781
|
-
versionId materialVersionId publishedAtMs changeKind
|
|
782
|
-
sourceRefs {
|
|
783
|
-
title sourceKind sourceContentId publicUrl sourceTimeMs locator
|
|
784
|
-
}
|
|
785
|
-
}
|
|
845
|
+
${THESIS_PUBLICATION_FIELDS}
|
|
786
846
|
}
|
|
787
847
|
}
|
|
788
848
|
}
|
|
@@ -844,59 +904,6 @@ function invalidPage() {
|
|
|
844
904
|
502
|
|
845
905
|
);
|
|
846
906
|
}
|
|
847
|
-
function positiveInt64List(value) {
|
|
848
|
-
return Array.isArray(value) && value.every(isPositiveInt64);
|
|
849
|
-
}
|
|
850
|
-
function stanceList(value) {
|
|
851
|
-
return Array.isArray(value) && value.every(
|
|
852
|
-
(item) => record(item) && isPositiveInt64(item.entityId) && typeof item.stance === "string" && item.stance.trim() !== ""
|
|
853
|
-
);
|
|
854
|
-
}
|
|
855
|
-
function entityList(value) {
|
|
856
|
-
return Array.isArray(value) && value.every(
|
|
857
|
-
(item) => record(item) && typeof item.id === "string" && item.id.trim() !== "" && typeof item.ticker === "string" && typeof item.name === "string"
|
|
858
|
-
);
|
|
859
|
-
}
|
|
860
|
-
function mediaList(value) {
|
|
861
|
-
return Array.isArray(value) && value.every(
|
|
862
|
-
(item) => record(item) && typeof item.type === "string" && item.type.trim() !== "" && typeof item.coverUrl === "string" && (item.url === null || typeof item.url === "string")
|
|
863
|
-
);
|
|
864
|
-
}
|
|
865
|
-
function sourceRefList(value) {
|
|
866
|
-
return Array.isArray(value) && value.every(
|
|
867
|
-
(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"
|
|
868
|
-
);
|
|
869
|
-
}
|
|
870
|
-
function nullableMs(value) {
|
|
871
|
-
return value === null || typeof value === "number" && Number.isFinite(value);
|
|
872
|
-
}
|
|
873
|
-
function snapshot(value) {
|
|
874
|
-
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);
|
|
875
|
-
}
|
|
876
|
-
function publisher(value) {
|
|
877
|
-
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");
|
|
878
|
-
}
|
|
879
|
-
function publication(value) {
|
|
880
|
-
if (!record(value)) return false;
|
|
881
|
-
for (const field of [
|
|
882
|
-
"thesisId",
|
|
883
|
-
"playbookId",
|
|
884
|
-
"authorVersionId",
|
|
885
|
-
"materialVersionId"
|
|
886
|
-
]) {
|
|
887
|
-
if (!isPositiveInt64(value[field])) return false;
|
|
888
|
-
}
|
|
889
|
-
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") {
|
|
890
|
-
return false;
|
|
891
|
-
}
|
|
892
|
-
for (const field of ["closed", "archived", "researchPaused"]) {
|
|
893
|
-
if (typeof value[field] !== "boolean") return false;
|
|
894
|
-
}
|
|
895
|
-
if (!positiveInt64List(value.entityIds) || !positiveInt64List(value.categoryIds) || !stanceList(value.entityStances) || !entityList(value.entities) || !mediaList(value.medias) || !publisher(value.publisher) || !snapshot(value.snapshotRelease)) {
|
|
896
|
-
return false;
|
|
897
|
-
}
|
|
898
|
-
return value.signalFeed === null || record(value.signalFeed) && isPositiveInt64(value.signalFeed.id);
|
|
899
|
-
}
|
|
900
907
|
function recommendationPage(value) {
|
|
901
908
|
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") {
|
|
902
909
|
return invalidPage();
|
|
@@ -906,7 +913,7 @@ function recommendationPage(value) {
|
|
|
906
913
|
return invalidPage();
|
|
907
914
|
}
|
|
908
915
|
for (const edge of value.edges) {
|
|
909
|
-
if (!record(edge) || typeof edge.cursor !== "string" || !edge.cursor.trim() || !record(edge.node) || typeof edge.node.itemKey !== "string" || !edge.node.itemKey.trim() || !
|
|
916
|
+
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)) {
|
|
910
917
|
return invalidPage();
|
|
911
918
|
}
|
|
912
919
|
}
|
|
@@ -4007,10 +4014,10 @@ var StewardResource = class {
|
|
|
4007
4014
|
if (!Number.isSafeInteger(windowSinceMs) || !Number.isSafeInteger(windowUntilMs) || windowSinceMs <= 0 || windowUntilMs <= windowSinceMs)
|
|
4008
4015
|
throw emptyResponse();
|
|
4009
4016
|
const items = page.edges.map((edge) => edge.node);
|
|
4010
|
-
const
|
|
4017
|
+
const nextCursor2 = page.pageInfo?.hasNextPage === true && page.pageInfo.endCursor ? page.pageInfo.endCursor : null;
|
|
4011
4018
|
return {
|
|
4012
4019
|
items,
|
|
4013
|
-
nextCursor,
|
|
4020
|
+
nextCursor: nextCursor2,
|
|
4014
4021
|
windowSinceMs,
|
|
4015
4022
|
windowUntilMs
|
|
4016
4023
|
};
|
|
@@ -4235,6 +4242,249 @@ var TradingPairsResource = class {
|
|
|
4235
4242
|
}
|
|
4236
4243
|
};
|
|
4237
4244
|
|
|
4245
|
+
// src/resources/thesisReads.ts
|
|
4246
|
+
var PAGE = "pageInfo { endCursor hasNextPage }";
|
|
4247
|
+
var PERSON = "__typename id slug displayName bio";
|
|
4248
|
+
var USER = "__typename id username displayName bio";
|
|
4249
|
+
var ENTITY = "__typename id ticker name kind assetClass venue { id name }";
|
|
4250
|
+
var AUTHOR_THESES = `theses(input: $input) {
|
|
4251
|
+
edges { cursor node { id latestRelease { thesisPublication { ${THESIS_PUBLICATION_FIELDS} } } } }
|
|
4252
|
+
${PAGE}
|
|
4253
|
+
}`;
|
|
4254
|
+
var PERSON_QUERY = `query ToolkitPersonTheses($slug: String!, $input: ProfileThesisConnectionInput) {
|
|
4255
|
+
scope: person(slug: $slug) { ${PERSON} ${AUTHOR_THESES} }
|
|
4256
|
+
}`;
|
|
4257
|
+
var USER_QUERY = `query ToolkitUserTheses($username: String!, $input: ProfileThesisConnectionInput) {
|
|
4258
|
+
scope: publicUser(username: $username) { ${USER} ${AUTHOR_THESES} }
|
|
4259
|
+
}`;
|
|
4260
|
+
var ENTITY_QUERY = `query ToolkitEntityTheses($id: ID!, $input: EntityThesisConnectionInput) {
|
|
4261
|
+
market { scope: entity(input: { id: $id }) { ${ENTITY}
|
|
4262
|
+
theses(input: $input) { edges { cursor node { ${THESIS_PUBLICATION_FIELDS} } } ${PAGE} }
|
|
4263
|
+
} }
|
|
4264
|
+
}`;
|
|
4265
|
+
var PEOPLE_QUERY = `query ToolkitThesisPeople($query: String!) {
|
|
4266
|
+
search: people(input: { query: $query, first: 50 }) {
|
|
4267
|
+
edges { node { ${PERSON} } } pageInfo { hasNextPage }
|
|
4268
|
+
}
|
|
4269
|
+
}`;
|
|
4270
|
+
var ENTITIES_QUERY = `query ToolkitThesisEntities($query: String!) {
|
|
4271
|
+
market { search: entities(input: { query: $query, first: 50, byPrefix: false }) {
|
|
4272
|
+
edges { node { ${ENTITY} } } pageInfo { hasNextPage }
|
|
4273
|
+
} }
|
|
4274
|
+
}`;
|
|
4275
|
+
var RELATED_QUERY = `query ToolkitRelatedTheses($id: ID!, $input: RelatedThesisInput) {
|
|
4276
|
+
node(id: $id) { ... on Playbook { relatedTheses(input: $input) {
|
|
4277
|
+
state nextCursor
|
|
4278
|
+
edges { cursor node { itemKey score publication { ${THESIS_PUBLICATION_FIELDS} } } }
|
|
4279
|
+
} } }
|
|
4280
|
+
}`;
|
|
4281
|
+
var SELECTORS = [
|
|
4282
|
+
"person",
|
|
4283
|
+
"personName",
|
|
4284
|
+
"user",
|
|
4285
|
+
"ticker",
|
|
4286
|
+
"entityId"
|
|
4287
|
+
];
|
|
4288
|
+
function validateThesisPageParams(params) {
|
|
4289
|
+
if (!record(params)) throw argument("Thesis parameters must be an object");
|
|
4290
|
+
const first = params.first === void 0 ? 10 : params.first;
|
|
4291
|
+
if (typeof first !== "number" || !Number.isInteger(first) || first < 1 || first > 50) {
|
|
4292
|
+
throw argument("first must be an integer between 1 and 50");
|
|
4293
|
+
}
|
|
4294
|
+
if (params.cursor !== void 0 && !nonempty(params.cursor)) {
|
|
4295
|
+
throw argument("cursor must be non-empty");
|
|
4296
|
+
}
|
|
4297
|
+
}
|
|
4298
|
+
function validateListThesesParams(params) {
|
|
4299
|
+
validateThesisPageParams(params);
|
|
4300
|
+
const chosen = SELECTORS.filter((key) => params[key] !== void 0);
|
|
4301
|
+
if (chosen.length !== 1) {
|
|
4302
|
+
throw argument(
|
|
4303
|
+
"Choose exactly one of person, personName, user, ticker or entityId"
|
|
4304
|
+
);
|
|
4305
|
+
}
|
|
4306
|
+
if (!nonempty(params[chosen[0]]))
|
|
4307
|
+
throw argument(`${chosen[0]} must be non-empty`);
|
|
4308
|
+
if (params.entityId !== void 0 && !isPositiveInt64(params.entityId)) {
|
|
4309
|
+
throw argument("entityId must be a positive int64 string");
|
|
4310
|
+
}
|
|
4311
|
+
if (params.status !== void 0 && params.status !== "ACTIVE" && params.status !== "ARCHIVED") {
|
|
4312
|
+
throw argument("status must be ACTIVE or ARCHIVED");
|
|
4313
|
+
}
|
|
4314
|
+
if (params.status !== void 0 && (params.ticker !== void 0 || params.entityId !== void 0)) {
|
|
4315
|
+
throw argument("status applies only to author lists");
|
|
4316
|
+
}
|
|
4317
|
+
}
|
|
4318
|
+
async function listTheses(client, params) {
|
|
4319
|
+
validateListThesesParams(params);
|
|
4320
|
+
client._requireAuth();
|
|
4321
|
+
const input = { first: params.first ?? 10, after: params.cursor };
|
|
4322
|
+
const entityId = params.ticker === void 0 ? params.entityId : (await resolveUnique(client, ENTITIES_QUERY, params.ticker, "Entity")).id;
|
|
4323
|
+
if (entityId !== void 0) {
|
|
4324
|
+
const data2 = await graphql(client, ENTITY_QUERY, { id: entityId, input });
|
|
4325
|
+
if (!record(data2.market)) throw invalid3();
|
|
4326
|
+
return thesisPage(
|
|
4327
|
+
data2.market.scope,
|
|
4328
|
+
(node) => isThesisPublication(node) ? { playbookId: node.playbookId, publication: node } : void 0
|
|
4329
|
+
);
|
|
4330
|
+
}
|
|
4331
|
+
const profileInput = { ...input, status: params.status };
|
|
4332
|
+
const slug = params.personName === void 0 ? params.person : (await resolveUnique(client, PEOPLE_QUERY, params.personName, "Person")).slug;
|
|
4333
|
+
const data = slug === void 0 ? await graphql(client, USER_QUERY, {
|
|
4334
|
+
username: params.user,
|
|
4335
|
+
input: profileInput
|
|
4336
|
+
}) : await graphql(client, PERSON_QUERY, { slug, input: profileInput });
|
|
4337
|
+
return thesisPage(data.scope, (node) => {
|
|
4338
|
+
if (!isPositiveInt64(node.id)) return void 0;
|
|
4339
|
+
const release = node.latestRelease;
|
|
4340
|
+
if (release === null) return { playbookId: node.id, publication: null };
|
|
4341
|
+
if (!record(release)) return void 0;
|
|
4342
|
+
const publication = release.thesisPublication;
|
|
4343
|
+
if (publication !== null && !isThesisPublication(publication))
|
|
4344
|
+
return void 0;
|
|
4345
|
+
return { playbookId: node.id, publication };
|
|
4346
|
+
});
|
|
4347
|
+
}
|
|
4348
|
+
async function relatedTheses(client, id, params = {}) {
|
|
4349
|
+
validateThesisPageParams(params);
|
|
4350
|
+
if (!isPositiveInt64(id))
|
|
4351
|
+
throw argument("id must be an internal positive int64 Playbook ID");
|
|
4352
|
+
client._requireAuth();
|
|
4353
|
+
const data = await graphql(client, RELATED_QUERY, {
|
|
4354
|
+
id: `Playbook:${id}`,
|
|
4355
|
+
input: { first: params.first ?? 10, after: params.cursor }
|
|
4356
|
+
});
|
|
4357
|
+
if (data.node === null) throw notFound();
|
|
4358
|
+
if (!record(data.node)) throw invalid3();
|
|
4359
|
+
const value = data.node.relatedTheses;
|
|
4360
|
+
if (!record(value) || !["GENERATING", "READY", "FAILED"].includes(value.state) || value.nextCursor !== null && !nonempty(value.nextCursor))
|
|
4361
|
+
throw invalid3();
|
|
4362
|
+
for (const edge of edges(value)) {
|
|
4363
|
+
if (!nonempty(edge.node.itemKey) || typeof edge.node.score !== "number" || !isThesisPublication(edge.node.publication))
|
|
4364
|
+
throw invalid3();
|
|
4365
|
+
}
|
|
4366
|
+
return {
|
|
4367
|
+
state: value.state,
|
|
4368
|
+
edges: value.edges,
|
|
4369
|
+
nextCursor: value.nextCursor
|
|
4370
|
+
};
|
|
4371
|
+
}
|
|
4372
|
+
function thesisPage(value, readNode) {
|
|
4373
|
+
if (value === null) throw notFound();
|
|
4374
|
+
const scope = readScope(value);
|
|
4375
|
+
if (!record(value) || !record(value.theses)) throw invalid3();
|
|
4376
|
+
const page = value.theses;
|
|
4377
|
+
const items = edges(page).map((edge) => {
|
|
4378
|
+
const node = readNode(edge.node);
|
|
4379
|
+
if (node === void 0) throw invalid3();
|
|
4380
|
+
return { cursor: edge.cursor, node };
|
|
4381
|
+
});
|
|
4382
|
+
return { scope, edges: items, nextCursor: nextCursor(page) };
|
|
4383
|
+
}
|
|
4384
|
+
async function resolveUnique(client, document, text, kind) {
|
|
4385
|
+
const data = await graphql(client, document, { query: text });
|
|
4386
|
+
const search = record(data.market) ? data.market.search : data.search;
|
|
4387
|
+
if (!record(search) || !Array.isArray(search.edges) || !record(search.pageInfo))
|
|
4388
|
+
throw invalid3();
|
|
4389
|
+
const candidates = search.edges.map(
|
|
4390
|
+
(edge) => readScope(record(edge) ? edge.node : void 0)
|
|
4391
|
+
);
|
|
4392
|
+
if (!candidates.every((c) => c.__typename === kind))
|
|
4393
|
+
throw invalid3();
|
|
4394
|
+
const more = search.pageInfo.hasNextPage === true;
|
|
4395
|
+
if (candidates.length === 1 && !more) return candidates[0];
|
|
4396
|
+
if (candidates.length === 0 && !more) throw notFound();
|
|
4397
|
+
throw new AlvaError(
|
|
4398
|
+
"AMBIGUOUS_IDENTITY",
|
|
4399
|
+
// ALPI Dispatch currently forwards only Error.message, not details.
|
|
4400
|
+
// Keep candidate identities available through that existing boundary too.
|
|
4401
|
+
`Choose an exact identity before reading theses. Candidates: ${JSON.stringify(candidates)}${more ? " More matches exist; refine the name or ticker." : ""}`,
|
|
4402
|
+
400,
|
|
4403
|
+
{ candidates, more }
|
|
4404
|
+
);
|
|
4405
|
+
}
|
|
4406
|
+
function readScope(value) {
|
|
4407
|
+
if (!record(value) || !nonempty(value.id)) throw invalid3();
|
|
4408
|
+
if (value.__typename === "Entity") {
|
|
4409
|
+
if (!["ticker", "name", "kind", "assetClass"].every(
|
|
4410
|
+
(key) => typeof value[key] === "string"
|
|
4411
|
+
) || value.venue !== null && (!record(value.venue) || !nonempty(value.venue.id) || typeof value.venue.name !== "string"))
|
|
4412
|
+
throw invalid3();
|
|
4413
|
+
} else if (typeof value.displayName !== "string" || typeof value.bio !== "string" || !(value.__typename === "Person" && nonempty(value.slug) || value.__typename === "PublicUser" && nonempty(value.username))) {
|
|
4414
|
+
throw invalid3();
|
|
4415
|
+
}
|
|
4416
|
+
const scope = { ...value };
|
|
4417
|
+
delete scope.theses;
|
|
4418
|
+
return scope;
|
|
4419
|
+
}
|
|
4420
|
+
function edges(value) {
|
|
4421
|
+
if (!Array.isArray(value.edges) || !value.edges.every(
|
|
4422
|
+
(edge) => record(edge) && nonempty(edge.cursor) && record(edge.node)
|
|
4423
|
+
))
|
|
4424
|
+
throw invalid3();
|
|
4425
|
+
return value.edges;
|
|
4426
|
+
}
|
|
4427
|
+
function nextCursor(page) {
|
|
4428
|
+
const info = page.pageInfo;
|
|
4429
|
+
if (!record(info) || typeof info.hasNextPage !== "boolean" || info.hasNextPage && !nonempty(info.endCursor))
|
|
4430
|
+
throw invalid3();
|
|
4431
|
+
return info.hasNextPage ? info.endCursor : null;
|
|
4432
|
+
}
|
|
4433
|
+
async function graphql(client, document, variables) {
|
|
4434
|
+
const response = await client._request("POST", "/query", {
|
|
4435
|
+
body: { query: document, variables }
|
|
4436
|
+
});
|
|
4437
|
+
if (!record(response)) throw invalid3();
|
|
4438
|
+
if (response.errors !== void 0) {
|
|
4439
|
+
if (!Array.isArray(response.errors)) throw invalid3();
|
|
4440
|
+
if (response.errors.length) {
|
|
4441
|
+
const messages = response.errors.flatMap(
|
|
4442
|
+
(error) => record(error) && typeof error.message === "string" ? [error.message] : []
|
|
4443
|
+
);
|
|
4444
|
+
const codes = new Set(
|
|
4445
|
+
response.errors.map(
|
|
4446
|
+
(error) => record(error) && record(error.extensions) ? error.extensions.code : void 0
|
|
4447
|
+
)
|
|
4448
|
+
);
|
|
4449
|
+
const [code] = codes;
|
|
4450
|
+
const status = codes.size === 1 && typeof code === "string" ? CANONICAL_STATUS.get(code) : void 0;
|
|
4451
|
+
throw new AlvaError(
|
|
4452
|
+
status === void 0 ? "GRAPHQL_ERROR" : String(code),
|
|
4453
|
+
messages.join("; ") || "GraphQL request failed",
|
|
4454
|
+
status ?? 400,
|
|
4455
|
+
{ errors: response.errors }
|
|
4456
|
+
);
|
|
4457
|
+
}
|
|
4458
|
+
}
|
|
4459
|
+
if (!record(response.data)) throw invalid3();
|
|
4460
|
+
return response.data;
|
|
4461
|
+
}
|
|
4462
|
+
var CANONICAL_STATUS = /* @__PURE__ */ new Map([
|
|
4463
|
+
["NOT_FOUND", 404],
|
|
4464
|
+
["PERMISSION_DENIED", 403],
|
|
4465
|
+
["UNAUTHENTICATED", 401]
|
|
4466
|
+
]);
|
|
4467
|
+
function nonempty(value) {
|
|
4468
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
4469
|
+
}
|
|
4470
|
+
function argument(message) {
|
|
4471
|
+
return new AlvaError("INVALID_ARGUMENT", message, 400);
|
|
4472
|
+
}
|
|
4473
|
+
function invalid3() {
|
|
4474
|
+
return new AlvaError(
|
|
4475
|
+
"GRAPHQL_INVALID_RESPONSE",
|
|
4476
|
+
"Invalid Thesis read response",
|
|
4477
|
+
502
|
|
4478
|
+
);
|
|
4479
|
+
}
|
|
4480
|
+
function notFound() {
|
|
4481
|
+
return new AlvaError(
|
|
4482
|
+
"NOT_FOUND",
|
|
4483
|
+
"No visible matching identity or Thesis found",
|
|
4484
|
+
404
|
|
4485
|
+
);
|
|
4486
|
+
}
|
|
4487
|
+
|
|
4238
4488
|
// src/resources/theses.ts
|
|
4239
4489
|
var MAX_SIGNED_INT64 = 9223372036854775807n;
|
|
4240
4490
|
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
@@ -4245,6 +4495,14 @@ var ThesesResource = class {
|
|
|
4245
4495
|
this.client = client;
|
|
4246
4496
|
}
|
|
4247
4497
|
client;
|
|
4498
|
+
/** One visible page; no automatic pagination or content truncation. */
|
|
4499
|
+
list(params) {
|
|
4500
|
+
return listTheses(this.client, params);
|
|
4501
|
+
}
|
|
4502
|
+
/** Related publications always use the current source version. */
|
|
4503
|
+
related(id, params = {}) {
|
|
4504
|
+
return relatedTheses(this.client, id, params);
|
|
4505
|
+
}
|
|
4248
4506
|
async assetCandidates(text) {
|
|
4249
4507
|
this.client._requireAuth();
|
|
4250
4508
|
const source = requireBody(text);
|
|
@@ -4651,11 +4909,11 @@ function thesisSignalsResponse(response, thesisID, first) {
|
|
|
4651
4909
|
signal: mappedSignal
|
|
4652
4910
|
};
|
|
4653
4911
|
});
|
|
4654
|
-
const
|
|
4655
|
-
if (
|
|
4912
|
+
const nextCursor2 = responseText(response.next_cursor, "next_cursor");
|
|
4913
|
+
if (nextCursor2 && nextCursor2 !== entries[entries.length - 1]?.cursor) {
|
|
4656
4914
|
throw invalidResponse2("next_cursor must match the final entry");
|
|
4657
4915
|
}
|
|
4658
|
-
return { research: status, entries, next_cursor:
|
|
4916
|
+
return { research: status, entries, next_cursor: nextCursor2 };
|
|
4659
4917
|
}
|
|
4660
4918
|
function responseNonnegativeInteger(value, field) {
|
|
4661
4919
|
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
|
|
@@ -4822,6 +5080,101 @@ function invalidResponse2(message) {
|
|
|
4822
5080
|
return new AlvaError("INVALID_RESPONSE", message, 502);
|
|
4823
5081
|
}
|
|
4824
5082
|
|
|
5083
|
+
// src/resources/companyNews.ts
|
|
5084
|
+
var CREATE_COMPANY_NEWS = `mutation CreateCompanyNews($input: CompanyNewsFeedInput!) {
|
|
5085
|
+
companyNews {
|
|
5086
|
+
createFeed(input: $input) { id producer { id } }
|
|
5087
|
+
}
|
|
5088
|
+
}`;
|
|
5089
|
+
var GRAPHQL_STATUS_BY_CODE3 = {
|
|
5090
|
+
INVALID_ARGUMENT: 400,
|
|
5091
|
+
UNAUTHENTICATED: 401,
|
|
5092
|
+
PERMISSION_DENIED: 403,
|
|
5093
|
+
NOT_FOUND: 404,
|
|
5094
|
+
ALREADY_EXISTS: 409,
|
|
5095
|
+
ABORTED: 409,
|
|
5096
|
+
FAILED_PRECONDITION: 412,
|
|
5097
|
+
RESOURCE_EXHAUSTED: 429,
|
|
5098
|
+
INTERNAL: 500,
|
|
5099
|
+
UNKNOWN: 500,
|
|
5100
|
+
DATA_LOSS: 500,
|
|
5101
|
+
UNAVAILABLE: 503,
|
|
5102
|
+
DEADLINE_EXCEEDED: 504
|
|
5103
|
+
};
|
|
5104
|
+
function validateCompanyNewsCreateParams(params) {
|
|
5105
|
+
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") {
|
|
5106
|
+
throw new AlvaError(
|
|
5107
|
+
"INVALID_ARGUMENT",
|
|
5108
|
+
"name must be 1-64 alphanumeric/hyphen characters and distinct from news-lane",
|
|
5109
|
+
400
|
|
5110
|
+
);
|
|
5111
|
+
}
|
|
5112
|
+
if (!Array.isArray(params.tickers) || params.tickers.length < 1 || params.tickers.length > 1e3 || params.tickers.some(
|
|
5113
|
+
(ticker) => typeof ticker !== "string" || ticker.trim() !== ticker || !/^[A-Z0-9][A-Z0-9.-]{0,19}$/.test(ticker)
|
|
5114
|
+
) || new Set(params.tickers).size !== params.tickers.length) {
|
|
5115
|
+
throw new AlvaError(
|
|
5116
|
+
"INVALID_ARGUMENT",
|
|
5117
|
+
"tickers must contain 1-1000 unique uppercase symbols",
|
|
5118
|
+
400
|
|
5119
|
+
);
|
|
5120
|
+
}
|
|
5121
|
+
for (const [name, maximum] of [
|
|
5122
|
+
["initial_lookback_hours", 168],
|
|
5123
|
+
["page_size", 100]
|
|
5124
|
+
]) {
|
|
5125
|
+
const value = params[name];
|
|
5126
|
+
if (value !== void 0 && (!Number.isInteger(value) || value < 0 || value > maximum)) {
|
|
5127
|
+
throw new AlvaError(
|
|
5128
|
+
"INVALID_ARGUMENT",
|
|
5129
|
+
`${name} must be an integer from 0 to ${maximum} (0 selects the default)`,
|
|
5130
|
+
400
|
|
5131
|
+
);
|
|
5132
|
+
}
|
|
5133
|
+
}
|
|
5134
|
+
}
|
|
5135
|
+
var CompanyNewsResource = class {
|
|
5136
|
+
constructor(client) {
|
|
5137
|
+
this.client = client;
|
|
5138
|
+
}
|
|
5139
|
+
client;
|
|
5140
|
+
async create(params) {
|
|
5141
|
+
this.client._requireAuth();
|
|
5142
|
+
validateCompanyNewsCreateParams(params);
|
|
5143
|
+
const body = {
|
|
5144
|
+
name: params.name,
|
|
5145
|
+
tickers: params.tickers,
|
|
5146
|
+
...params.initial_lookback_hours === void 0 ? {} : { initialLookbackHours: params.initial_lookback_hours },
|
|
5147
|
+
...params.page_size === void 0 ? {} : { pageSize: params.page_size }
|
|
5148
|
+
};
|
|
5149
|
+
const graph = await this.client._request("POST", "/query", {
|
|
5150
|
+
body: { query: CREATE_COMPANY_NEWS, variables: { input: body } }
|
|
5151
|
+
});
|
|
5152
|
+
if (Array.isArray(graph?.errors) && graph.errors.length > 0) {
|
|
5153
|
+
const codes = graph.errors.map((error) => error?.extensions?.code);
|
|
5154
|
+
const code = typeof codes[0] === "string" && codes.every((value) => value === codes[0]) ? codes[0] : "GRAPHQL_ERROR";
|
|
5155
|
+
throw new AlvaError(
|
|
5156
|
+
code,
|
|
5157
|
+
graph.errors.map((error) => error?.message).filter(Boolean).join("; ") || "Company News creation failed",
|
|
5158
|
+
GRAPHQL_STATUS_BY_CODE3[code] ?? 502,
|
|
5159
|
+
{ errors: graph.errors }
|
|
5160
|
+
);
|
|
5161
|
+
}
|
|
5162
|
+
const feed = graph?.data?.companyNews?.createFeed;
|
|
5163
|
+
const response = { feed_id: feed?.id, cronjob_id: feed?.producer?.id };
|
|
5164
|
+
if (typeof response !== "object" || response === null || !("feed_id" in response) || !validID(response.feed_id) || !("cronjob_id" in response) || !validID(response.cronjob_id)) {
|
|
5165
|
+
throw new AlvaError(
|
|
5166
|
+
"INVALID_RESPONSE",
|
|
5167
|
+
"company news response must contain decimal int64 feed_id and cronjob_id strings",
|
|
5168
|
+
502
|
|
5169
|
+
);
|
|
5170
|
+
}
|
|
5171
|
+
return { feed_id: response.feed_id, cronjob_id: response.cronjob_id };
|
|
5172
|
+
}
|
|
5173
|
+
};
|
|
5174
|
+
function validID(value) {
|
|
5175
|
+
return typeof value === "string" && value.trim() === value && /^[1-9]\d{0,18}$/.test(value) && BigInt(value) <= 9223372036854775807n;
|
|
5176
|
+
}
|
|
5177
|
+
|
|
4825
5178
|
// src/client.ts
|
|
4826
5179
|
var DEFAULT_BASE_URL = "https://api-llm.prd.alva.ai";
|
|
4827
5180
|
var DEFAULT_ARRAYS_BASE_URL = "https://data-tools.prd.space.id";
|
|
@@ -4937,6 +5290,7 @@ var AlvaClient = class {
|
|
|
4937
5290
|
_steward;
|
|
4938
5291
|
_tradingPairs;
|
|
4939
5292
|
_theses;
|
|
5293
|
+
_companyNews;
|
|
4940
5294
|
constructor(config) {
|
|
4941
5295
|
this.baseUrl = config.baseUrl ?? DEFAULT_BASE_URL;
|
|
4942
5296
|
this.arraysBaseUrl = config.arraysBaseUrl ?? DEFAULT_ARRAYS_BASE_URL;
|
|
@@ -5047,6 +5401,9 @@ var AlvaClient = class {
|
|
|
5047
5401
|
get theses() {
|
|
5048
5402
|
return this._theses ??= new ThesesResource(this);
|
|
5049
5403
|
}
|
|
5404
|
+
get companyNews() {
|
|
5405
|
+
return this._companyNews ??= new CompanyNewsResource(this);
|
|
5406
|
+
}
|
|
5050
5407
|
_requireAuth() {
|
|
5051
5408
|
if (!this.pbsvToken && !this.viewer_token && !this.apiKey) {
|
|
5052
5409
|
throw new AlvaError(
|
|
@@ -5663,7 +6020,7 @@ var installPlaybookRuntime = (targetWindow) => {
|
|
|
5663
6020
|
};
|
|
5664
6021
|
|
|
5665
6022
|
// src/index.ts
|
|
5666
|
-
var VERSION = true ? "0.32.0
|
|
6023
|
+
var VERSION = true ? "0.32.0" : "dev";
|
|
5667
6024
|
export {
|
|
5668
6025
|
AlertsResource,
|
|
5669
6026
|
AlvaClient,
|
|
@@ -5671,6 +6028,7 @@ export {
|
|
|
5671
6028
|
AutomationAlertDeliveryResource,
|
|
5672
6029
|
AutomationResource,
|
|
5673
6030
|
CliUsageError,
|
|
6031
|
+
CompanyNewsResource,
|
|
5674
6032
|
ForYouResource,
|
|
5675
6033
|
MarketsResource,
|
|
5676
6034
|
PBSV_UPDATE_MESSAGE,
|