@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.cjs
CHANGED
|
@@ -633,7 +633,8 @@ var ReleaseResource = class {
|
|
|
633
633
|
version: params.version,
|
|
634
634
|
feeds: params.feeds,
|
|
635
635
|
changelog: params.changelog,
|
|
636
|
-
readme_url: params.readme_url
|
|
636
|
+
readme_url: params.readme_url,
|
|
637
|
+
confirm_bundled_feed_exposure: params.confirm_bundled_feed_exposure
|
|
637
638
|
}
|
|
638
639
|
});
|
|
639
640
|
}
|
|
@@ -818,6 +819,166 @@ function connection(value) {
|
|
|
818
819
|
return invalidResponse();
|
|
819
820
|
return value;
|
|
820
821
|
}
|
|
822
|
+
var THESIS_RECOMMENDATION_QUERY = `
|
|
823
|
+
query ToolkitForYouTheses($input: ThesisRecommendationInput) {
|
|
824
|
+
viewer {
|
|
825
|
+
thesisRecommendations(input: $input) {
|
|
826
|
+
listId pageCursor nextCursor exhausted scanLimited
|
|
827
|
+
pageInfo { startCursor endCursor hasNextPage hasPreviousPage }
|
|
828
|
+
edges {
|
|
829
|
+
cursor
|
|
830
|
+
node {
|
|
831
|
+
itemKey
|
|
832
|
+
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
|
+
}
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
`.trim();
|
|
858
|
+
function validateForYouThesesParams(params) {
|
|
859
|
+
if (!record(params)) throw new Error("Thesis parameters must be an object");
|
|
860
|
+
const first = params.first === void 0 ? 10 : params.first;
|
|
861
|
+
if (typeof first !== "number" || !Number.isInteger(first) || first < 1 || first > 10) {
|
|
862
|
+
throw new Error("first must be an integer between 1 and 10");
|
|
863
|
+
}
|
|
864
|
+
if (params.after !== void 0 && (typeof params.after !== "string" || !params.after.trim())) {
|
|
865
|
+
throw new Error("after must be a non-empty cursor");
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
function graphqlViewerField(response, field) {
|
|
869
|
+
if (!record(response)) {
|
|
870
|
+
throw new AlvaError(
|
|
871
|
+
"GRAPHQL_INVALID_RESPONSE",
|
|
872
|
+
`GraphQL returned an invalid viewer.${field} response`,
|
|
873
|
+
502
|
|
874
|
+
);
|
|
875
|
+
}
|
|
876
|
+
if (response.errors !== void 0) {
|
|
877
|
+
if (!Array.isArray(response.errors)) {
|
|
878
|
+
throw new AlvaError(
|
|
879
|
+
"GRAPHQL_INVALID_RESPONSE",
|
|
880
|
+
`GraphQL returned an invalid viewer.${field} response`,
|
|
881
|
+
502
|
|
882
|
+
);
|
|
883
|
+
}
|
|
884
|
+
if (response.errors.length > 0) {
|
|
885
|
+
const messages = response.errors.flatMap(
|
|
886
|
+
(error) => record(error) && typeof error.message === "string" ? [error.message] : []
|
|
887
|
+
);
|
|
888
|
+
throw new AlvaError(
|
|
889
|
+
"GRAPHQL_ERROR",
|
|
890
|
+
messages.join("; ") || "GraphQL request failed",
|
|
891
|
+
400,
|
|
892
|
+
{ errors: response.errors }
|
|
893
|
+
);
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
if (!record(response.data) || !record(response.data.viewer) || response.data.viewer[field] == null) {
|
|
897
|
+
throw new AlvaError(
|
|
898
|
+
"GRAPHQL_EMPTY_RESPONSE",
|
|
899
|
+
`GraphQL response did not include viewer.${field}`,
|
|
900
|
+
502
|
|
901
|
+
);
|
|
902
|
+
}
|
|
903
|
+
return response.data.viewer[field];
|
|
904
|
+
}
|
|
905
|
+
function invalidPage() {
|
|
906
|
+
throw new AlvaError(
|
|
907
|
+
"GRAPHQL_INVALID_RESPONSE",
|
|
908
|
+
"GraphQL returned an invalid Thesis recommendation page",
|
|
909
|
+
502
|
|
910
|
+
);
|
|
911
|
+
}
|
|
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
|
+
function recommendationPage(value) {
|
|
966
|
+
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
|
+
return invalidPage();
|
|
968
|
+
}
|
|
969
|
+
const page = value.pageInfo;
|
|
970
|
+
if (typeof page.startCursor !== "string" || typeof page.endCursor !== "string" || typeof page.hasNextPage !== "boolean" || typeof page.hasPreviousPage !== "boolean" || page.hasNextPage !== (value.nextCursor !== null)) {
|
|
971
|
+
return invalidPage();
|
|
972
|
+
}
|
|
973
|
+
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)) {
|
|
975
|
+
return invalidPage();
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
const first = value.edges[0];
|
|
979
|
+
if (page.startCursor !== (first?.cursor ?? "")) return invalidPage();
|
|
980
|
+
return value;
|
|
981
|
+
}
|
|
821
982
|
var ForYouResource = class {
|
|
822
983
|
constructor(client) {
|
|
823
984
|
this.client = client;
|
|
@@ -840,29 +1001,29 @@ var ForYouResource = class {
|
|
|
840
1001
|
}
|
|
841
1002
|
}
|
|
842
1003
|
});
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
1004
|
+
return connection(graphqlViewerField(response, "forYou"));
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
1007
|
+
* One ranked page of Thesis recommendations -- the stream the Feed App reads,
|
|
1008
|
+
* which is not the chronological `list` stream. Page to `exhausted` and filter
|
|
1009
|
+
* on `publication.publishedAtMs` yourself; the order is slot-mixed, so a time
|
|
1010
|
+
* bound is never a reason to stop paging. Publications the viewer already saw
|
|
1011
|
+
* are withheld by an upstream cooldown, so a window read is "recommended and
|
|
1012
|
+
* recent", not every publication in the window.
|
|
1013
|
+
*/
|
|
1014
|
+
async theses(params = {}) {
|
|
1015
|
+
validateForYouThesesParams(params);
|
|
1016
|
+
this.client._requireAuth();
|
|
1017
|
+
const response = await this.client._request("POST", "/query", {
|
|
1018
|
+
body: {
|
|
1019
|
+
query: THESIS_RECOMMENDATION_QUERY,
|
|
1020
|
+
variables: {
|
|
1021
|
+
input: { first: params.first ?? 10, after: params.after }
|
|
1022
|
+
}
|
|
856
1023
|
}
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
"GRAPHQL_EMPTY_RESPONSE",
|
|
861
|
-
"GraphQL response did not include viewer.forYou",
|
|
862
|
-
502
|
|
863
|
-
);
|
|
864
|
-
}
|
|
865
|
-
return connection(response.data.viewer.forYou);
|
|
1024
|
+
});
|
|
1025
|
+
const field = graphqlViewerField(response, "thesisRecommendations");
|
|
1026
|
+
return recommendationPage(field);
|
|
866
1027
|
}
|
|
867
1028
|
};
|
|
868
1029
|
|
|
@@ -3776,9 +3937,7 @@ function requireDeliveryId(value, label = "delivery id") {
|
|
|
3776
3937
|
throw invalid2(`${label} must be a positive integer`);
|
|
3777
3938
|
return value;
|
|
3778
3939
|
}
|
|
3779
|
-
function
|
|
3780
|
-
if (values.length === 0)
|
|
3781
|
-
throw invalid2("at least one delivery id is required");
|
|
3940
|
+
function normalizeDeliveryIds(values) {
|
|
3782
3941
|
const unique = /* @__PURE__ */ new Set();
|
|
3783
3942
|
for (const value of values) {
|
|
3784
3943
|
requireDeliveryId(value);
|
|
@@ -3787,6 +3946,11 @@ function requireDeliveryIds(values) {
|
|
|
3787
3946
|
}
|
|
3788
3947
|
return [...unique];
|
|
3789
3948
|
}
|
|
3949
|
+
function requireDeliveryIds(values) {
|
|
3950
|
+
if (values.length === 0)
|
|
3951
|
+
throw invalid2("at least one delivery id is required");
|
|
3952
|
+
return normalizeDeliveryIds(values);
|
|
3953
|
+
}
|
|
3790
3954
|
function requireDecision(value) {
|
|
3791
3955
|
if (!DECISIONS.has(value))
|
|
3792
3956
|
throw invalid2("decision must be one of immediate, digest, suppress");
|
|
@@ -3869,7 +4033,10 @@ var StewardResource = class {
|
|
|
3869
4033
|
inboxPath: requireInboxPath(params),
|
|
3870
4034
|
requestId: requireRequestId(params.requestId),
|
|
3871
4035
|
body: params.body,
|
|
3872
|
-
|
|
4036
|
+
// A For-You-only Brief covers no ledger delivery, so an empty (or
|
|
4037
|
+
// omitted) set is valid here; the backend accepts it. `briefed` still
|
|
4038
|
+
// requires ids.
|
|
4039
|
+
deliveryIds: normalizeDeliveryIds(params.deliveryIds ?? [])
|
|
3873
4040
|
}
|
|
3874
4041
|
});
|
|
3875
4042
|
const message = data.postStewardMessage?.message;
|
|
@@ -4143,6 +4310,56 @@ var ThesesResource = class {
|
|
|
4143
4310
|
this.client = client;
|
|
4144
4311
|
}
|
|
4145
4312
|
client;
|
|
4313
|
+
async assetCandidates(text) {
|
|
4314
|
+
this.client._requireAuth();
|
|
4315
|
+
const source = requireBody(text);
|
|
4316
|
+
const response = await this.client._request("POST", "/query", {
|
|
4317
|
+
body: {
|
|
4318
|
+
query: `query ThesisAssetCandidates($input: ThesisAssetCandidatesInput!) {
|
|
4319
|
+
viewer { thesisAssetCandidates(input: $input) {
|
|
4320
|
+
mentions { quote ticker resolution stance candidates { entityId ticker name kind } }
|
|
4321
|
+
} }
|
|
4322
|
+
}`,
|
|
4323
|
+
variables: { input: { text: source } }
|
|
4324
|
+
}
|
|
4325
|
+
});
|
|
4326
|
+
if (Array.isArray(response?.errors) && response.errors.length > 0) {
|
|
4327
|
+
throw new AlvaError("GRAPHQL_ERROR", "Asset extraction failed", 400, {
|
|
4328
|
+
errors: response.errors
|
|
4329
|
+
});
|
|
4330
|
+
}
|
|
4331
|
+
const data = response?.data;
|
|
4332
|
+
const viewer = isRecord2(data) ? data.viewer : void 0;
|
|
4333
|
+
const result = isRecord2(viewer) ? viewer.thesisAssetCandidates : void 0;
|
|
4334
|
+
if (!isRecord2(result) || !Array.isArray(result.mentions)) {
|
|
4335
|
+
throw invalidResponse2("asset candidates response must contain mentions");
|
|
4336
|
+
}
|
|
4337
|
+
const mentions = result.mentions.map((item, index) => {
|
|
4338
|
+
if (!isRecord2(item) || typeof item.quote !== "string" || typeof item.ticker !== "string" || !["RESOLVED", "AMBIGUOUS", "UNRESOLVED"].includes(
|
|
4339
|
+
item.resolution
|
|
4340
|
+
) || !["UNKNOWN", "BULLISH", "BEARISH"].includes(item.stance) || !Array.isArray(item.candidates)) {
|
|
4341
|
+
throw invalidResponse2(`asset mention ${index} is invalid`);
|
|
4342
|
+
}
|
|
4343
|
+
const candidates = item.candidates.map((candidate) => {
|
|
4344
|
+
if (!isRecord2(candidate) || typeof candidate.ticker !== "string" || typeof candidate.name !== "string" || !["STOCK", "ETF", "CRYPTO", "INDEX"].includes(
|
|
4345
|
+
candidate.kind
|
|
4346
|
+
)) {
|
|
4347
|
+
throw invalidResponse2(`asset mention ${index} has invalid candidate`);
|
|
4348
|
+
}
|
|
4349
|
+
return {
|
|
4350
|
+
entityId: responseID(
|
|
4351
|
+
candidate.entityId,
|
|
4352
|
+
`asset mention ${index} candidate.entityId`
|
|
4353
|
+
),
|
|
4354
|
+
ticker: candidate.ticker,
|
|
4355
|
+
name: candidate.name,
|
|
4356
|
+
kind: candidate.kind
|
|
4357
|
+
};
|
|
4358
|
+
});
|
|
4359
|
+
return { ...item, candidates };
|
|
4360
|
+
});
|
|
4361
|
+
return { mentions };
|
|
4362
|
+
}
|
|
4146
4363
|
async create(params) {
|
|
4147
4364
|
this.client._requireAuth();
|
|
4148
4365
|
const body = createBody(params);
|
|
@@ -4156,6 +4373,47 @@ var ThesesResource = class {
|
|
|
4156
4373
|
await this.client._request("GET", `/api/v1/theses/${requireID(id, "id")}`)
|
|
4157
4374
|
);
|
|
4158
4375
|
}
|
|
4376
|
+
async getVersion(id, authorVersionID) {
|
|
4377
|
+
this.client._requireAuth();
|
|
4378
|
+
const thesisID = requireID(id, "id");
|
|
4379
|
+
const versionID = requireID(authorVersionID, "author_version_id");
|
|
4380
|
+
const response = thesisResponse(
|
|
4381
|
+
await this.client._request(
|
|
4382
|
+
"GET",
|
|
4383
|
+
`/api/v1/theses/${thesisID}/versions/${versionID}`
|
|
4384
|
+
)
|
|
4385
|
+
);
|
|
4386
|
+
if (response.thesis.id !== thesisID || response.thesis.author_version_id !== versionID) {
|
|
4387
|
+
throw invalidResponse2(
|
|
4388
|
+
"version response must match the requested thesis and author version"
|
|
4389
|
+
);
|
|
4390
|
+
}
|
|
4391
|
+
return response;
|
|
4392
|
+
}
|
|
4393
|
+
async signals(id, params = {}) {
|
|
4394
|
+
this.client._requireAuth();
|
|
4395
|
+
const first = params.first ?? 20;
|
|
4396
|
+
if (!Number.isInteger(first) || first < 1 || first > 50) {
|
|
4397
|
+
throw invalidArgument("first must be an integer between 1 and 50");
|
|
4398
|
+
}
|
|
4399
|
+
if (params.cursor !== void 0 && typeof params.cursor !== "string") {
|
|
4400
|
+
throw invalidArgument("cursor must be a string");
|
|
4401
|
+
}
|
|
4402
|
+
return thesisSignalsResponse(
|
|
4403
|
+
await this.client._request(
|
|
4404
|
+
"GET",
|
|
4405
|
+
`/api/v1/theses/${requireID(id, "id")}/signals`,
|
|
4406
|
+
{
|
|
4407
|
+
query: {
|
|
4408
|
+
first,
|
|
4409
|
+
...params.cursor === void 0 ? {} : { cursor: params.cursor }
|
|
4410
|
+
}
|
|
4411
|
+
}
|
|
4412
|
+
),
|
|
4413
|
+
id,
|
|
4414
|
+
first
|
|
4415
|
+
);
|
|
4416
|
+
}
|
|
4159
4417
|
async update(id, params) {
|
|
4160
4418
|
this.client._requireAuth();
|
|
4161
4419
|
const body = updateBody(params);
|
|
@@ -4246,8 +4504,36 @@ function createBody(params) {
|
|
|
4246
4504
|
};
|
|
4247
4505
|
if (params.tickers !== void 0)
|
|
4248
4506
|
body.tickers = requireTickers(params.tickers);
|
|
4507
|
+
if (params.entity_stances !== void 0) {
|
|
4508
|
+
body.entity_stances = requireEntityStances(
|
|
4509
|
+
params.entity_stances,
|
|
4510
|
+
body.entity_ids
|
|
4511
|
+
);
|
|
4512
|
+
}
|
|
4249
4513
|
return body;
|
|
4250
4514
|
}
|
|
4515
|
+
function requireEntityStances(value, entityIDs) {
|
|
4516
|
+
if (!Array.isArray(value) || value.length > MAX_ENTITY_IDS)
|
|
4517
|
+
throw invalidArgument("entity_stances must contain at most 100 values");
|
|
4518
|
+
const allowed = new Set(entityIDs);
|
|
4519
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4520
|
+
return value.map((item, index) => {
|
|
4521
|
+
if (!isRecord2(item))
|
|
4522
|
+
throw invalidArgument(`entity_stances[${index}] must be an object`);
|
|
4523
|
+
const entityID = requireID(
|
|
4524
|
+
item.entity_id,
|
|
4525
|
+
`entity_stances[${index}].entity_id`
|
|
4526
|
+
);
|
|
4527
|
+
if (!allowed.has(entityID) || seen.has(entityID))
|
|
4528
|
+
throw invalidArgument(
|
|
4529
|
+
"entity stance must reference one unique entity_id"
|
|
4530
|
+
);
|
|
4531
|
+
seen.add(entityID);
|
|
4532
|
+
if (!["unknown", "bullish", "bearish"].includes(item.stance))
|
|
4533
|
+
throw invalidArgument(`entity_stances[${index}].stance is invalid`);
|
|
4534
|
+
return { entity_id: entityID, stance: item.stance };
|
|
4535
|
+
});
|
|
4536
|
+
}
|
|
4251
4537
|
function updateBody(params) {
|
|
4252
4538
|
return {
|
|
4253
4539
|
request_id: requireRequestID(params.request_id),
|
|
@@ -4286,6 +4572,20 @@ function thesisResponse(response) {
|
|
|
4286
4572
|
author_kind: responseText(thesis.author_kind, "thesis.author_kind"),
|
|
4287
4573
|
author_ref: responseText(thesis.author_ref, "thesis.author_ref")
|
|
4288
4574
|
};
|
|
4575
|
+
if (thesis.entity_stances !== void 0) {
|
|
4576
|
+
if (!Array.isArray(thesis.entity_stances))
|
|
4577
|
+
throw invalidResponse2("thesis.entity_stances must be an array");
|
|
4578
|
+
value.entity_stances = thesis.entity_stances.map((item) => {
|
|
4579
|
+
if (!isRecord2(item))
|
|
4580
|
+
throw invalidResponse2("thesis.entity_stances contains invalid entry");
|
|
4581
|
+
const entityID = responseID(item.entity_id, "entity_stances.entity_id");
|
|
4582
|
+
if (!value.entity_ids.includes(entityID))
|
|
4583
|
+
throw invalidResponse2("entity stance must reference a thesis entity");
|
|
4584
|
+
if (!["unknown", "bullish", "bearish"].includes(item.stance))
|
|
4585
|
+
throw invalidResponse2("thesis.entity_stances contains invalid stance");
|
|
4586
|
+
return { entity_id: entityID, stance: item.stance };
|
|
4587
|
+
});
|
|
4588
|
+
}
|
|
4289
4589
|
return { thesis: value };
|
|
4290
4590
|
}
|
|
4291
4591
|
function thesisGetResponse(response) {
|
|
@@ -4327,6 +4627,112 @@ function thesisGetResponse(response) {
|
|
|
4327
4627
|
});
|
|
4328
4628
|
return { thesis: base.thesis, author, entities };
|
|
4329
4629
|
}
|
|
4630
|
+
function thesisSignalsResponse(response, thesisID, first) {
|
|
4631
|
+
if (!isRecord2(response) || !isRecord2(response.research) || !Array.isArray(response.entries) || response.entries.length > first) {
|
|
4632
|
+
throw invalidResponse2("invalid Signal history response");
|
|
4633
|
+
}
|
|
4634
|
+
const research = response.research;
|
|
4635
|
+
const status = {
|
|
4636
|
+
state: responseText(research.state, "research.state"),
|
|
4637
|
+
pending_work: responseNonnegativeInteger(
|
|
4638
|
+
research.pending_work,
|
|
4639
|
+
"research.pending_work"
|
|
4640
|
+
),
|
|
4641
|
+
read_complete: responseBoolean(
|
|
4642
|
+
research.read_complete,
|
|
4643
|
+
"research.read_complete"
|
|
4644
|
+
)
|
|
4645
|
+
};
|
|
4646
|
+
if (research.last_attempt_ms !== void 0)
|
|
4647
|
+
status.last_attempt_ms = responseNonnegativeInteger(
|
|
4648
|
+
research.last_attempt_ms,
|
|
4649
|
+
"research.last_attempt_ms"
|
|
4650
|
+
);
|
|
4651
|
+
if (research.last_completed_ms !== void 0)
|
|
4652
|
+
status.last_completed_ms = responseNonnegativeInteger(
|
|
4653
|
+
research.last_completed_ms,
|
|
4654
|
+
"research.last_completed_ms"
|
|
4655
|
+
);
|
|
4656
|
+
const entries = response.entries.map((raw) => {
|
|
4657
|
+
if (!isRecord2(raw) || !isRecord2(raw.signal) || !isRecord2(raw.signal.source)) {
|
|
4658
|
+
throw invalidResponse2("entry must include a Signal and source");
|
|
4659
|
+
}
|
|
4660
|
+
const signal = raw.signal;
|
|
4661
|
+
const source = signal.source;
|
|
4662
|
+
const signalID = responseID(signal.thesis_id, "signal.thesis_id");
|
|
4663
|
+
if (signalID !== thesisID)
|
|
4664
|
+
throw invalidResponse2("Signal belongs to another Thesis");
|
|
4665
|
+
const cursor = responseNonemptyText(raw.cursor, "entry.cursor");
|
|
4666
|
+
const mappedSource = {
|
|
4667
|
+
title: responseText(source.title, "source.title")
|
|
4668
|
+
};
|
|
4669
|
+
if (source.url !== void 0)
|
|
4670
|
+
mappedSource.url = responseText(source.url, "source.url");
|
|
4671
|
+
if (source.published_at_ms !== void 0)
|
|
4672
|
+
mappedSource.published_at_ms = responseNonnegativeInteger(
|
|
4673
|
+
source.published_at_ms,
|
|
4674
|
+
"source.published_at_ms"
|
|
4675
|
+
);
|
|
4676
|
+
const mappedSignal = {
|
|
4677
|
+
id: responseID(signal.id, "signal.id"),
|
|
4678
|
+
thesis_id: signalID,
|
|
4679
|
+
author_version_id: responseID(
|
|
4680
|
+
signal.author_version_id,
|
|
4681
|
+
"signal.author_version_id"
|
|
4682
|
+
),
|
|
4683
|
+
statement_snapshot: responseNonemptyText(
|
|
4684
|
+
signal.statement_snapshot,
|
|
4685
|
+
"signal.statement_snapshot"
|
|
4686
|
+
),
|
|
4687
|
+
stance: responseText(signal.stance, "signal.stance"),
|
|
4688
|
+
explanation: responseText(signal.explanation, "signal.explanation"),
|
|
4689
|
+
information_kind: responseText(
|
|
4690
|
+
signal.information_kind,
|
|
4691
|
+
"signal.information_kind"
|
|
4692
|
+
),
|
|
4693
|
+
source: mappedSource
|
|
4694
|
+
};
|
|
4695
|
+
if (signal.evidence_excerpt !== void 0) {
|
|
4696
|
+
if (!isRecord2(signal.evidence_excerpt))
|
|
4697
|
+
throw invalidResponse2("invalid evidence excerpt");
|
|
4698
|
+
mappedSignal.evidence_excerpt = {
|
|
4699
|
+
text: responseNonemptyText(
|
|
4700
|
+
signal.evidence_excerpt.text,
|
|
4701
|
+
"evidence_excerpt.text"
|
|
4702
|
+
),
|
|
4703
|
+
omitted_before: responseBoolean(
|
|
4704
|
+
signal.evidence_excerpt.omitted_before,
|
|
4705
|
+
"evidence_excerpt.omitted_before"
|
|
4706
|
+
),
|
|
4707
|
+
omitted_after: responseBoolean(
|
|
4708
|
+
signal.evidence_excerpt.omitted_after,
|
|
4709
|
+
"evidence_excerpt.omitted_after"
|
|
4710
|
+
)
|
|
4711
|
+
};
|
|
4712
|
+
}
|
|
4713
|
+
return {
|
|
4714
|
+
feed_entry_id: responseID(raw.feed_entry_id, "feed_entry_id"),
|
|
4715
|
+
cursor,
|
|
4716
|
+
signal: mappedSignal
|
|
4717
|
+
};
|
|
4718
|
+
});
|
|
4719
|
+
const nextCursor = responseText(response.next_cursor, "next_cursor");
|
|
4720
|
+
if (nextCursor && nextCursor !== entries[entries.length - 1]?.cursor) {
|
|
4721
|
+
throw invalidResponse2("next_cursor must match the final entry");
|
|
4722
|
+
}
|
|
4723
|
+
return { research: status, entries, next_cursor: nextCursor };
|
|
4724
|
+
}
|
|
4725
|
+
function responseNonnegativeInteger(value, field) {
|
|
4726
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
|
|
4727
|
+
throw invalidResponse2(field + " must be a nonnegative safe integer");
|
|
4728
|
+
}
|
|
4729
|
+
return value;
|
|
4730
|
+
}
|
|
4731
|
+
function responseNonemptyText(value, field) {
|
|
4732
|
+
const valueText = responseText(value, field);
|
|
4733
|
+
if (!valueText.trim()) throw invalidResponse2(field + " must be nonempty");
|
|
4734
|
+
return valueText;
|
|
4735
|
+
}
|
|
4330
4736
|
function requireRequestID(value) {
|
|
4331
4737
|
if (!UUID.test(value) || /^0{8}-0{4}-0{4}-0{4}-0{12}$/i.test(value)) {
|
|
4332
4738
|
throw invalidArgument("request_id must be a non-zero RFC 4122 UUID");
|
|
@@ -4343,10 +4749,13 @@ function requireID(value, field) {
|
|
|
4343
4749
|
}
|
|
4344
4750
|
return value;
|
|
4345
4751
|
}
|
|
4752
|
+
var MAX_ENTITY_IDS = 100;
|
|
4346
4753
|
function requireIDs(value, field) {
|
|
4347
4754
|
if (!Array.isArray(value)) throw invalidArgument(`${field} must be an array`);
|
|
4348
|
-
if (value.length >
|
|
4349
|
-
throw invalidArgument(
|
|
4755
|
+
if (value.length > MAX_ENTITY_IDS) {
|
|
4756
|
+
throw invalidArgument(
|
|
4757
|
+
`${field} must contain at most ${MAX_ENTITY_IDS} IDs`
|
|
4758
|
+
);
|
|
4350
4759
|
}
|
|
4351
4760
|
return value.map((item, index) => requireID(item, `${field}[${index}]`));
|
|
4352
4761
|
}
|
|
@@ -4417,8 +4826,10 @@ function responseID(value, field) {
|
|
|
4417
4826
|
}
|
|
4418
4827
|
function responseIDs(value, field) {
|
|
4419
4828
|
if (!Array.isArray(value)) throw invalidResponse2(`${field} must be an array`);
|
|
4420
|
-
if (value.length >
|
|
4421
|
-
throw invalidResponse2(
|
|
4829
|
+
if (value.length > MAX_ENTITY_IDS) {
|
|
4830
|
+
throw invalidResponse2(
|
|
4831
|
+
`${field} must contain at most ${MAX_ENTITY_IDS} IDs`
|
|
4832
|
+
);
|
|
4422
4833
|
}
|
|
4423
4834
|
return value.map((item, index) => responseID(item, `${field}[${index}]`));
|
|
4424
4835
|
}
|
|
@@ -5317,7 +5728,7 @@ var installPlaybookRuntime = (targetWindow) => {
|
|
|
5317
5728
|
};
|
|
5318
5729
|
|
|
5319
5730
|
// src/index.ts
|
|
5320
|
-
var VERSION = true ? "0.
|
|
5731
|
+
var VERSION = true ? "0.31.0" : "dev";
|
|
5321
5732
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5322
5733
|
0 && (module.exports = {
|
|
5323
5734
|
AlertsResource,
|