@alva-ai/toolkit 0.28.1-beta.1 → 0.31.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 +14 -3
- package/dist/browser.global.js +63 -24
- package/dist/browser.global.js.map +1 -1
- package/dist/cli.d.ts +183 -1
- package/dist/cli.js +557 -45
- package/dist/cli.js.map +1 -1
- package/dist/dispatch.d.ts +183 -1
- package/dist/dispatch.js +211 -21
- package/dist/dispatch.js.map +1 -1
- package/dist/index.cjs +443 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +184 -2
- package/dist/index.d.ts +184 -2
- package/dist/index.js +443 -32
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -568,7 +568,8 @@ var ReleaseResource = class {
|
|
|
568
568
|
version: params.version,
|
|
569
569
|
feeds: params.feeds,
|
|
570
570
|
changelog: params.changelog,
|
|
571
|
-
readme_url: params.readme_url
|
|
571
|
+
readme_url: params.readme_url,
|
|
572
|
+
confirm_bundled_feed_exposure: params.confirm_bundled_feed_exposure
|
|
572
573
|
}
|
|
573
574
|
});
|
|
574
575
|
}
|
|
@@ -753,6 +754,166 @@ function connection(value) {
|
|
|
753
754
|
return invalidResponse();
|
|
754
755
|
return value;
|
|
755
756
|
}
|
|
757
|
+
var THESIS_RECOMMENDATION_QUERY = `
|
|
758
|
+
query ToolkitForYouTheses($input: ThesisRecommendationInput) {
|
|
759
|
+
viewer {
|
|
760
|
+
thesisRecommendations(input: $input) {
|
|
761
|
+
listId pageCursor nextCursor exhausted scanLimited
|
|
762
|
+
pageInfo { startCursor endCursor hasNextPage hasPreviousPage }
|
|
763
|
+
edges {
|
|
764
|
+
cursor
|
|
765
|
+
node {
|
|
766
|
+
itemKey
|
|
767
|
+
publication {
|
|
768
|
+
thesisId playbookId authorVersionId materialVersionId itemKey
|
|
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
|
+
}
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
`.trim();
|
|
793
|
+
function validateForYouThesesParams(params) {
|
|
794
|
+
if (!record(params)) throw new Error("Thesis parameters must be an object");
|
|
795
|
+
const first = params.first === void 0 ? 10 : params.first;
|
|
796
|
+
if (typeof first !== "number" || !Number.isInteger(first) || first < 1 || first > 10) {
|
|
797
|
+
throw new Error("first must be an integer between 1 and 10");
|
|
798
|
+
}
|
|
799
|
+
if (params.after !== void 0 && (typeof params.after !== "string" || !params.after.trim())) {
|
|
800
|
+
throw new Error("after must be a non-empty cursor");
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
function graphqlViewerField(response, field) {
|
|
804
|
+
if (!record(response)) {
|
|
805
|
+
throw new AlvaError(
|
|
806
|
+
"GRAPHQL_INVALID_RESPONSE",
|
|
807
|
+
`GraphQL returned an invalid viewer.${field} response`,
|
|
808
|
+
502
|
|
809
|
+
);
|
|
810
|
+
}
|
|
811
|
+
if (response.errors !== void 0) {
|
|
812
|
+
if (!Array.isArray(response.errors)) {
|
|
813
|
+
throw new AlvaError(
|
|
814
|
+
"GRAPHQL_INVALID_RESPONSE",
|
|
815
|
+
`GraphQL returned an invalid viewer.${field} response`,
|
|
816
|
+
502
|
|
817
|
+
);
|
|
818
|
+
}
|
|
819
|
+
if (response.errors.length > 0) {
|
|
820
|
+
const messages = response.errors.flatMap(
|
|
821
|
+
(error) => record(error) && typeof error.message === "string" ? [error.message] : []
|
|
822
|
+
);
|
|
823
|
+
throw new AlvaError(
|
|
824
|
+
"GRAPHQL_ERROR",
|
|
825
|
+
messages.join("; ") || "GraphQL request failed",
|
|
826
|
+
400,
|
|
827
|
+
{ errors: response.errors }
|
|
828
|
+
);
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
if (!record(response.data) || !record(response.data.viewer) || response.data.viewer[field] == null) {
|
|
832
|
+
throw new AlvaError(
|
|
833
|
+
"GRAPHQL_EMPTY_RESPONSE",
|
|
834
|
+
`GraphQL response did not include viewer.${field}`,
|
|
835
|
+
502
|
|
836
|
+
);
|
|
837
|
+
}
|
|
838
|
+
return response.data.viewer[field];
|
|
839
|
+
}
|
|
840
|
+
function invalidPage() {
|
|
841
|
+
throw new AlvaError(
|
|
842
|
+
"GRAPHQL_INVALID_RESPONSE",
|
|
843
|
+
"GraphQL returned an invalid Thesis recommendation page",
|
|
844
|
+
502
|
|
845
|
+
);
|
|
846
|
+
}
|
|
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
|
+
function recommendationPage(value) {
|
|
901
|
+
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
|
+
return invalidPage();
|
|
903
|
+
}
|
|
904
|
+
const page = value.pageInfo;
|
|
905
|
+
if (typeof page.startCursor !== "string" || typeof page.endCursor !== "string" || typeof page.hasNextPage !== "boolean" || typeof page.hasPreviousPage !== "boolean" || page.hasNextPage !== (value.nextCursor !== null)) {
|
|
906
|
+
return invalidPage();
|
|
907
|
+
}
|
|
908
|
+
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() || !publication(edge.node.publication)) {
|
|
910
|
+
return invalidPage();
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
const first = value.edges[0];
|
|
914
|
+
if (page.startCursor !== (first?.cursor ?? "")) return invalidPage();
|
|
915
|
+
return value;
|
|
916
|
+
}
|
|
756
917
|
var ForYouResource = class {
|
|
757
918
|
constructor(client) {
|
|
758
919
|
this.client = client;
|
|
@@ -775,29 +936,29 @@ var ForYouResource = class {
|
|
|
775
936
|
}
|
|
776
937
|
}
|
|
777
938
|
});
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
939
|
+
return connection(graphqlViewerField(response, "forYou"));
|
|
940
|
+
}
|
|
941
|
+
/**
|
|
942
|
+
* One ranked page of Thesis recommendations -- the stream the Feed App reads,
|
|
943
|
+
* which is not the chronological `list` stream. Page to `exhausted` and filter
|
|
944
|
+
* on `publication.publishedAtMs` yourself; the order is slot-mixed, so a time
|
|
945
|
+
* bound is never a reason to stop paging. Publications the viewer already saw
|
|
946
|
+
* are withheld by an upstream cooldown, so a window read is "recommended and
|
|
947
|
+
* recent", not every publication in the window.
|
|
948
|
+
*/
|
|
949
|
+
async theses(params = {}) {
|
|
950
|
+
validateForYouThesesParams(params);
|
|
951
|
+
this.client._requireAuth();
|
|
952
|
+
const response = await this.client._request("POST", "/query", {
|
|
953
|
+
body: {
|
|
954
|
+
query: THESIS_RECOMMENDATION_QUERY,
|
|
955
|
+
variables: {
|
|
956
|
+
input: { first: params.first ?? 10, after: params.after }
|
|
957
|
+
}
|
|
791
958
|
}
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
"GRAPHQL_EMPTY_RESPONSE",
|
|
796
|
-
"GraphQL response did not include viewer.forYou",
|
|
797
|
-
502
|
|
798
|
-
);
|
|
799
|
-
}
|
|
800
|
-
return connection(response.data.viewer.forYou);
|
|
959
|
+
});
|
|
960
|
+
const field = graphqlViewerField(response, "thesisRecommendations");
|
|
961
|
+
return recommendationPage(field);
|
|
801
962
|
}
|
|
802
963
|
};
|
|
803
964
|
|
|
@@ -3711,9 +3872,7 @@ function requireDeliveryId(value, label = "delivery id") {
|
|
|
3711
3872
|
throw invalid2(`${label} must be a positive integer`);
|
|
3712
3873
|
return value;
|
|
3713
3874
|
}
|
|
3714
|
-
function
|
|
3715
|
-
if (values.length === 0)
|
|
3716
|
-
throw invalid2("at least one delivery id is required");
|
|
3875
|
+
function normalizeDeliveryIds(values) {
|
|
3717
3876
|
const unique = /* @__PURE__ */ new Set();
|
|
3718
3877
|
for (const value of values) {
|
|
3719
3878
|
requireDeliveryId(value);
|
|
@@ -3722,6 +3881,11 @@ function requireDeliveryIds(values) {
|
|
|
3722
3881
|
}
|
|
3723
3882
|
return [...unique];
|
|
3724
3883
|
}
|
|
3884
|
+
function requireDeliveryIds(values) {
|
|
3885
|
+
if (values.length === 0)
|
|
3886
|
+
throw invalid2("at least one delivery id is required");
|
|
3887
|
+
return normalizeDeliveryIds(values);
|
|
3888
|
+
}
|
|
3725
3889
|
function requireDecision(value) {
|
|
3726
3890
|
if (!DECISIONS.has(value))
|
|
3727
3891
|
throw invalid2("decision must be one of immediate, digest, suppress");
|
|
@@ -3804,7 +3968,10 @@ var StewardResource = class {
|
|
|
3804
3968
|
inboxPath: requireInboxPath(params),
|
|
3805
3969
|
requestId: requireRequestId(params.requestId),
|
|
3806
3970
|
body: params.body,
|
|
3807
|
-
|
|
3971
|
+
// A For-You-only Brief covers no ledger delivery, so an empty (or
|
|
3972
|
+
// omitted) set is valid here; the backend accepts it. `briefed` still
|
|
3973
|
+
// requires ids.
|
|
3974
|
+
deliveryIds: normalizeDeliveryIds(params.deliveryIds ?? [])
|
|
3808
3975
|
}
|
|
3809
3976
|
});
|
|
3810
3977
|
const message = data.postStewardMessage?.message;
|
|
@@ -4078,6 +4245,56 @@ var ThesesResource = class {
|
|
|
4078
4245
|
this.client = client;
|
|
4079
4246
|
}
|
|
4080
4247
|
client;
|
|
4248
|
+
async assetCandidates(text) {
|
|
4249
|
+
this.client._requireAuth();
|
|
4250
|
+
const source = requireBody(text);
|
|
4251
|
+
const response = await this.client._request("POST", "/query", {
|
|
4252
|
+
body: {
|
|
4253
|
+
query: `query ThesisAssetCandidates($input: ThesisAssetCandidatesInput!) {
|
|
4254
|
+
viewer { thesisAssetCandidates(input: $input) {
|
|
4255
|
+
mentions { quote ticker resolution stance candidates { entityId ticker name kind } }
|
|
4256
|
+
} }
|
|
4257
|
+
}`,
|
|
4258
|
+
variables: { input: { text: source } }
|
|
4259
|
+
}
|
|
4260
|
+
});
|
|
4261
|
+
if (Array.isArray(response?.errors) && response.errors.length > 0) {
|
|
4262
|
+
throw new AlvaError("GRAPHQL_ERROR", "Asset extraction failed", 400, {
|
|
4263
|
+
errors: response.errors
|
|
4264
|
+
});
|
|
4265
|
+
}
|
|
4266
|
+
const data = response?.data;
|
|
4267
|
+
const viewer = isRecord2(data) ? data.viewer : void 0;
|
|
4268
|
+
const result = isRecord2(viewer) ? viewer.thesisAssetCandidates : void 0;
|
|
4269
|
+
if (!isRecord2(result) || !Array.isArray(result.mentions)) {
|
|
4270
|
+
throw invalidResponse2("asset candidates response must contain mentions");
|
|
4271
|
+
}
|
|
4272
|
+
const mentions = result.mentions.map((item, index) => {
|
|
4273
|
+
if (!isRecord2(item) || typeof item.quote !== "string" || typeof item.ticker !== "string" || !["RESOLVED", "AMBIGUOUS", "UNRESOLVED"].includes(
|
|
4274
|
+
item.resolution
|
|
4275
|
+
) || !["UNKNOWN", "BULLISH", "BEARISH"].includes(item.stance) || !Array.isArray(item.candidates)) {
|
|
4276
|
+
throw invalidResponse2(`asset mention ${index} is invalid`);
|
|
4277
|
+
}
|
|
4278
|
+
const candidates = item.candidates.map((candidate) => {
|
|
4279
|
+
if (!isRecord2(candidate) || typeof candidate.ticker !== "string" || typeof candidate.name !== "string" || !["STOCK", "ETF", "CRYPTO", "INDEX"].includes(
|
|
4280
|
+
candidate.kind
|
|
4281
|
+
)) {
|
|
4282
|
+
throw invalidResponse2(`asset mention ${index} has invalid candidate`);
|
|
4283
|
+
}
|
|
4284
|
+
return {
|
|
4285
|
+
entityId: responseID(
|
|
4286
|
+
candidate.entityId,
|
|
4287
|
+
`asset mention ${index} candidate.entityId`
|
|
4288
|
+
),
|
|
4289
|
+
ticker: candidate.ticker,
|
|
4290
|
+
name: candidate.name,
|
|
4291
|
+
kind: candidate.kind
|
|
4292
|
+
};
|
|
4293
|
+
});
|
|
4294
|
+
return { ...item, candidates };
|
|
4295
|
+
});
|
|
4296
|
+
return { mentions };
|
|
4297
|
+
}
|
|
4081
4298
|
async create(params) {
|
|
4082
4299
|
this.client._requireAuth();
|
|
4083
4300
|
const body = createBody(params);
|
|
@@ -4091,6 +4308,47 @@ var ThesesResource = class {
|
|
|
4091
4308
|
await this.client._request("GET", `/api/v1/theses/${requireID(id, "id")}`)
|
|
4092
4309
|
);
|
|
4093
4310
|
}
|
|
4311
|
+
async getVersion(id, authorVersionID) {
|
|
4312
|
+
this.client._requireAuth();
|
|
4313
|
+
const thesisID = requireID(id, "id");
|
|
4314
|
+
const versionID = requireID(authorVersionID, "author_version_id");
|
|
4315
|
+
const response = thesisResponse(
|
|
4316
|
+
await this.client._request(
|
|
4317
|
+
"GET",
|
|
4318
|
+
`/api/v1/theses/${thesisID}/versions/${versionID}`
|
|
4319
|
+
)
|
|
4320
|
+
);
|
|
4321
|
+
if (response.thesis.id !== thesisID || response.thesis.author_version_id !== versionID) {
|
|
4322
|
+
throw invalidResponse2(
|
|
4323
|
+
"version response must match the requested thesis and author version"
|
|
4324
|
+
);
|
|
4325
|
+
}
|
|
4326
|
+
return response;
|
|
4327
|
+
}
|
|
4328
|
+
async signals(id, params = {}) {
|
|
4329
|
+
this.client._requireAuth();
|
|
4330
|
+
const first = params.first ?? 20;
|
|
4331
|
+
if (!Number.isInteger(first) || first < 1 || first > 50) {
|
|
4332
|
+
throw invalidArgument("first must be an integer between 1 and 50");
|
|
4333
|
+
}
|
|
4334
|
+
if (params.cursor !== void 0 && typeof params.cursor !== "string") {
|
|
4335
|
+
throw invalidArgument("cursor must be a string");
|
|
4336
|
+
}
|
|
4337
|
+
return thesisSignalsResponse(
|
|
4338
|
+
await this.client._request(
|
|
4339
|
+
"GET",
|
|
4340
|
+
`/api/v1/theses/${requireID(id, "id")}/signals`,
|
|
4341
|
+
{
|
|
4342
|
+
query: {
|
|
4343
|
+
first,
|
|
4344
|
+
...params.cursor === void 0 ? {} : { cursor: params.cursor }
|
|
4345
|
+
}
|
|
4346
|
+
}
|
|
4347
|
+
),
|
|
4348
|
+
id,
|
|
4349
|
+
first
|
|
4350
|
+
);
|
|
4351
|
+
}
|
|
4094
4352
|
async update(id, params) {
|
|
4095
4353
|
this.client._requireAuth();
|
|
4096
4354
|
const body = updateBody(params);
|
|
@@ -4181,8 +4439,36 @@ function createBody(params) {
|
|
|
4181
4439
|
};
|
|
4182
4440
|
if (params.tickers !== void 0)
|
|
4183
4441
|
body.tickers = requireTickers(params.tickers);
|
|
4442
|
+
if (params.entity_stances !== void 0) {
|
|
4443
|
+
body.entity_stances = requireEntityStances(
|
|
4444
|
+
params.entity_stances,
|
|
4445
|
+
body.entity_ids
|
|
4446
|
+
);
|
|
4447
|
+
}
|
|
4184
4448
|
return body;
|
|
4185
4449
|
}
|
|
4450
|
+
function requireEntityStances(value, entityIDs) {
|
|
4451
|
+
if (!Array.isArray(value) || value.length > MAX_ENTITY_IDS)
|
|
4452
|
+
throw invalidArgument("entity_stances must contain at most 100 values");
|
|
4453
|
+
const allowed = new Set(entityIDs);
|
|
4454
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4455
|
+
return value.map((item, index) => {
|
|
4456
|
+
if (!isRecord2(item))
|
|
4457
|
+
throw invalidArgument(`entity_stances[${index}] must be an object`);
|
|
4458
|
+
const entityID = requireID(
|
|
4459
|
+
item.entity_id,
|
|
4460
|
+
`entity_stances[${index}].entity_id`
|
|
4461
|
+
);
|
|
4462
|
+
if (!allowed.has(entityID) || seen.has(entityID))
|
|
4463
|
+
throw invalidArgument(
|
|
4464
|
+
"entity stance must reference one unique entity_id"
|
|
4465
|
+
);
|
|
4466
|
+
seen.add(entityID);
|
|
4467
|
+
if (!["unknown", "bullish", "bearish"].includes(item.stance))
|
|
4468
|
+
throw invalidArgument(`entity_stances[${index}].stance is invalid`);
|
|
4469
|
+
return { entity_id: entityID, stance: item.stance };
|
|
4470
|
+
});
|
|
4471
|
+
}
|
|
4186
4472
|
function updateBody(params) {
|
|
4187
4473
|
return {
|
|
4188
4474
|
request_id: requireRequestID(params.request_id),
|
|
@@ -4221,6 +4507,20 @@ function thesisResponse(response) {
|
|
|
4221
4507
|
author_kind: responseText(thesis.author_kind, "thesis.author_kind"),
|
|
4222
4508
|
author_ref: responseText(thesis.author_ref, "thesis.author_ref")
|
|
4223
4509
|
};
|
|
4510
|
+
if (thesis.entity_stances !== void 0) {
|
|
4511
|
+
if (!Array.isArray(thesis.entity_stances))
|
|
4512
|
+
throw invalidResponse2("thesis.entity_stances must be an array");
|
|
4513
|
+
value.entity_stances = thesis.entity_stances.map((item) => {
|
|
4514
|
+
if (!isRecord2(item))
|
|
4515
|
+
throw invalidResponse2("thesis.entity_stances contains invalid entry");
|
|
4516
|
+
const entityID = responseID(item.entity_id, "entity_stances.entity_id");
|
|
4517
|
+
if (!value.entity_ids.includes(entityID))
|
|
4518
|
+
throw invalidResponse2("entity stance must reference a thesis entity");
|
|
4519
|
+
if (!["unknown", "bullish", "bearish"].includes(item.stance))
|
|
4520
|
+
throw invalidResponse2("thesis.entity_stances contains invalid stance");
|
|
4521
|
+
return { entity_id: entityID, stance: item.stance };
|
|
4522
|
+
});
|
|
4523
|
+
}
|
|
4224
4524
|
return { thesis: value };
|
|
4225
4525
|
}
|
|
4226
4526
|
function thesisGetResponse(response) {
|
|
@@ -4262,6 +4562,112 @@ function thesisGetResponse(response) {
|
|
|
4262
4562
|
});
|
|
4263
4563
|
return { thesis: base.thesis, author, entities };
|
|
4264
4564
|
}
|
|
4565
|
+
function thesisSignalsResponse(response, thesisID, first) {
|
|
4566
|
+
if (!isRecord2(response) || !isRecord2(response.research) || !Array.isArray(response.entries) || response.entries.length > first) {
|
|
4567
|
+
throw invalidResponse2("invalid Signal history response");
|
|
4568
|
+
}
|
|
4569
|
+
const research = response.research;
|
|
4570
|
+
const status = {
|
|
4571
|
+
state: responseText(research.state, "research.state"),
|
|
4572
|
+
pending_work: responseNonnegativeInteger(
|
|
4573
|
+
research.pending_work,
|
|
4574
|
+
"research.pending_work"
|
|
4575
|
+
),
|
|
4576
|
+
read_complete: responseBoolean(
|
|
4577
|
+
research.read_complete,
|
|
4578
|
+
"research.read_complete"
|
|
4579
|
+
)
|
|
4580
|
+
};
|
|
4581
|
+
if (research.last_attempt_ms !== void 0)
|
|
4582
|
+
status.last_attempt_ms = responseNonnegativeInteger(
|
|
4583
|
+
research.last_attempt_ms,
|
|
4584
|
+
"research.last_attempt_ms"
|
|
4585
|
+
);
|
|
4586
|
+
if (research.last_completed_ms !== void 0)
|
|
4587
|
+
status.last_completed_ms = responseNonnegativeInteger(
|
|
4588
|
+
research.last_completed_ms,
|
|
4589
|
+
"research.last_completed_ms"
|
|
4590
|
+
);
|
|
4591
|
+
const entries = response.entries.map((raw) => {
|
|
4592
|
+
if (!isRecord2(raw) || !isRecord2(raw.signal) || !isRecord2(raw.signal.source)) {
|
|
4593
|
+
throw invalidResponse2("entry must include a Signal and source");
|
|
4594
|
+
}
|
|
4595
|
+
const signal = raw.signal;
|
|
4596
|
+
const source = signal.source;
|
|
4597
|
+
const signalID = responseID(signal.thesis_id, "signal.thesis_id");
|
|
4598
|
+
if (signalID !== thesisID)
|
|
4599
|
+
throw invalidResponse2("Signal belongs to another Thesis");
|
|
4600
|
+
const cursor = responseNonemptyText(raw.cursor, "entry.cursor");
|
|
4601
|
+
const mappedSource = {
|
|
4602
|
+
title: responseText(source.title, "source.title")
|
|
4603
|
+
};
|
|
4604
|
+
if (source.url !== void 0)
|
|
4605
|
+
mappedSource.url = responseText(source.url, "source.url");
|
|
4606
|
+
if (source.published_at_ms !== void 0)
|
|
4607
|
+
mappedSource.published_at_ms = responseNonnegativeInteger(
|
|
4608
|
+
source.published_at_ms,
|
|
4609
|
+
"source.published_at_ms"
|
|
4610
|
+
);
|
|
4611
|
+
const mappedSignal = {
|
|
4612
|
+
id: responseID(signal.id, "signal.id"),
|
|
4613
|
+
thesis_id: signalID,
|
|
4614
|
+
author_version_id: responseID(
|
|
4615
|
+
signal.author_version_id,
|
|
4616
|
+
"signal.author_version_id"
|
|
4617
|
+
),
|
|
4618
|
+
statement_snapshot: responseNonemptyText(
|
|
4619
|
+
signal.statement_snapshot,
|
|
4620
|
+
"signal.statement_snapshot"
|
|
4621
|
+
),
|
|
4622
|
+
stance: responseText(signal.stance, "signal.stance"),
|
|
4623
|
+
explanation: responseText(signal.explanation, "signal.explanation"),
|
|
4624
|
+
information_kind: responseText(
|
|
4625
|
+
signal.information_kind,
|
|
4626
|
+
"signal.information_kind"
|
|
4627
|
+
),
|
|
4628
|
+
source: mappedSource
|
|
4629
|
+
};
|
|
4630
|
+
if (signal.evidence_excerpt !== void 0) {
|
|
4631
|
+
if (!isRecord2(signal.evidence_excerpt))
|
|
4632
|
+
throw invalidResponse2("invalid evidence excerpt");
|
|
4633
|
+
mappedSignal.evidence_excerpt = {
|
|
4634
|
+
text: responseNonemptyText(
|
|
4635
|
+
signal.evidence_excerpt.text,
|
|
4636
|
+
"evidence_excerpt.text"
|
|
4637
|
+
),
|
|
4638
|
+
omitted_before: responseBoolean(
|
|
4639
|
+
signal.evidence_excerpt.omitted_before,
|
|
4640
|
+
"evidence_excerpt.omitted_before"
|
|
4641
|
+
),
|
|
4642
|
+
omitted_after: responseBoolean(
|
|
4643
|
+
signal.evidence_excerpt.omitted_after,
|
|
4644
|
+
"evidence_excerpt.omitted_after"
|
|
4645
|
+
)
|
|
4646
|
+
};
|
|
4647
|
+
}
|
|
4648
|
+
return {
|
|
4649
|
+
feed_entry_id: responseID(raw.feed_entry_id, "feed_entry_id"),
|
|
4650
|
+
cursor,
|
|
4651
|
+
signal: mappedSignal
|
|
4652
|
+
};
|
|
4653
|
+
});
|
|
4654
|
+
const nextCursor = responseText(response.next_cursor, "next_cursor");
|
|
4655
|
+
if (nextCursor && nextCursor !== entries[entries.length - 1]?.cursor) {
|
|
4656
|
+
throw invalidResponse2("next_cursor must match the final entry");
|
|
4657
|
+
}
|
|
4658
|
+
return { research: status, entries, next_cursor: nextCursor };
|
|
4659
|
+
}
|
|
4660
|
+
function responseNonnegativeInteger(value, field) {
|
|
4661
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
|
|
4662
|
+
throw invalidResponse2(field + " must be a nonnegative safe integer");
|
|
4663
|
+
}
|
|
4664
|
+
return value;
|
|
4665
|
+
}
|
|
4666
|
+
function responseNonemptyText(value, field) {
|
|
4667
|
+
const valueText = responseText(value, field);
|
|
4668
|
+
if (!valueText.trim()) throw invalidResponse2(field + " must be nonempty");
|
|
4669
|
+
return valueText;
|
|
4670
|
+
}
|
|
4265
4671
|
function requireRequestID(value) {
|
|
4266
4672
|
if (!UUID.test(value) || /^0{8}-0{4}-0{4}-0{4}-0{12}$/i.test(value)) {
|
|
4267
4673
|
throw invalidArgument("request_id must be a non-zero RFC 4122 UUID");
|
|
@@ -4278,10 +4684,13 @@ function requireID(value, field) {
|
|
|
4278
4684
|
}
|
|
4279
4685
|
return value;
|
|
4280
4686
|
}
|
|
4687
|
+
var MAX_ENTITY_IDS = 100;
|
|
4281
4688
|
function requireIDs(value, field) {
|
|
4282
4689
|
if (!Array.isArray(value)) throw invalidArgument(`${field} must be an array`);
|
|
4283
|
-
if (value.length >
|
|
4284
|
-
throw invalidArgument(
|
|
4690
|
+
if (value.length > MAX_ENTITY_IDS) {
|
|
4691
|
+
throw invalidArgument(
|
|
4692
|
+
`${field} must contain at most ${MAX_ENTITY_IDS} IDs`
|
|
4693
|
+
);
|
|
4285
4694
|
}
|
|
4286
4695
|
return value.map((item, index) => requireID(item, `${field}[${index}]`));
|
|
4287
4696
|
}
|
|
@@ -4352,8 +4761,10 @@ function responseID(value, field) {
|
|
|
4352
4761
|
}
|
|
4353
4762
|
function responseIDs(value, field) {
|
|
4354
4763
|
if (!Array.isArray(value)) throw invalidResponse2(`${field} must be an array`);
|
|
4355
|
-
if (value.length >
|
|
4356
|
-
throw invalidResponse2(
|
|
4764
|
+
if (value.length > MAX_ENTITY_IDS) {
|
|
4765
|
+
throw invalidResponse2(
|
|
4766
|
+
`${field} must contain at most ${MAX_ENTITY_IDS} IDs`
|
|
4767
|
+
);
|
|
4357
4768
|
}
|
|
4358
4769
|
return value.map((item, index) => responseID(item, `${field}[${index}]`));
|
|
4359
4770
|
}
|
|
@@ -5252,7 +5663,7 @@ var installPlaybookRuntime = (targetWindow) => {
|
|
|
5252
5663
|
};
|
|
5253
5664
|
|
|
5254
5665
|
// src/index.ts
|
|
5255
|
-
var VERSION = true ? "0.
|
|
5666
|
+
var VERSION = true ? "0.31.0" : "dev";
|
|
5256
5667
|
export {
|
|
5257
5668
|
AlertsResource,
|
|
5258
5669
|
AlvaClient,
|