@alva-ai/toolkit 0.35.0 → 0.36.0-beta.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 +5 -4
- package/dist/browser.global.js +59 -49
- package/dist/browser.global.js.map +1 -1
- package/dist/cli.d.ts +83 -11
- package/dist/cli.js +185 -114
- package/dist/cli.js.map +1 -1
- package/dist/dispatch.d.ts +83 -11
- package/dist/dispatch.js +74 -72
- package/dist/dispatch.js.map +1 -1
- package/dist/index.cjs +143 -65
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +84 -12
- package/dist/index.d.ts +84 -12
- package/dist/index.js +143 -65
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5181,6 +5181,58 @@ function nextCursor(page) {
|
|
|
5181
5181
|
throw invalid3();
|
|
5182
5182
|
return info.hasNextPage ? info.endCursor : null;
|
|
5183
5183
|
}
|
|
5184
|
+
var RETURN_QUERY = `query ToolkitThesisReturn($id: ID!, $detail: Boolean!) {
|
|
5185
|
+
node(id: $id) { ... on Playbook { latestRelease { thesisPublication {
|
|
5186
|
+
returnTracking
|
|
5187
|
+
thesisReturn(detail: $detail) {
|
|
5188
|
+
live value firstFillAtMs pricedAtMs stale computedAtMs
|
|
5189
|
+
updates { authorVersionId publishedAtMs startValue updateReturn
|
|
5190
|
+
positions { entityId symbol direction startPrice startAtMs endPrice endAtMs end positionReturn currency } }
|
|
5191
|
+
}
|
|
5192
|
+
} } } }
|
|
5193
|
+
}`;
|
|
5194
|
+
async function thesisReturn(client, id, params = {}) {
|
|
5195
|
+
if (!isPositiveInt64(id))
|
|
5196
|
+
throw argument("id must be an internal positive int64 Playbook ID");
|
|
5197
|
+
if (params.detail !== void 0 && typeof params.detail !== "boolean")
|
|
5198
|
+
throw argument("detail must be a boolean");
|
|
5199
|
+
client._requireAuth();
|
|
5200
|
+
const data = await graphql(client, RETURN_QUERY, {
|
|
5201
|
+
id: `Playbook:${id}`,
|
|
5202
|
+
detail: params.detail ?? false
|
|
5203
|
+
});
|
|
5204
|
+
if (data.node === null) throw notFound();
|
|
5205
|
+
if (!record2(data.node)) throw invalid3();
|
|
5206
|
+
const release = data.node.latestRelease;
|
|
5207
|
+
if (release === null || release === void 0)
|
|
5208
|
+
return { playbookId: id, returnTracking: null, thesisReturn: null };
|
|
5209
|
+
if (!record2(release)) throw invalid3();
|
|
5210
|
+
const publication = release.thesisPublication;
|
|
5211
|
+
if (publication === null)
|
|
5212
|
+
return { playbookId: id, returnTracking: null, thesisReturn: null };
|
|
5213
|
+
if (!record2(publication)) throw invalid3();
|
|
5214
|
+
const tracking = publication.returnTracking;
|
|
5215
|
+
if (tracking !== null && !["UNSET", "ON", "OFF"].includes(tracking))
|
|
5216
|
+
throw invalid3();
|
|
5217
|
+
const value = publication.thesisReturn;
|
|
5218
|
+
if (value !== null && !validThesisReturn(value)) throw invalid3();
|
|
5219
|
+
return {
|
|
5220
|
+
playbookId: id,
|
|
5221
|
+
returnTracking: tracking,
|
|
5222
|
+
thesisReturn: value
|
|
5223
|
+
};
|
|
5224
|
+
}
|
|
5225
|
+
function validThesisReturn(value) {
|
|
5226
|
+
if (!record2(value) || typeof value.live !== "boolean" || typeof value.value !== "number" || typeof value.stale !== "boolean" || typeof value.computedAtMs !== "number" || !Array.isArray(value.updates))
|
|
5227
|
+
return false;
|
|
5228
|
+
return value.updates.every(
|
|
5229
|
+
(update) => record2(update) && nonempty(update.authorVersionId) && typeof update.publishedAtMs === "number" && typeof update.startValue === "number" && Array.isArray(update.positions) && update.positions.every(
|
|
5230
|
+
(position) => record2(position) && nonempty(position.symbol) && ["BULLISH", "BEARISH"].includes(position.direction) && ["PENDING", "NEXT_UPDATE", "LATEST"].includes(
|
|
5231
|
+
position.end
|
|
5232
|
+
) && typeof position.positionReturn === "number"
|
|
5233
|
+
)
|
|
5234
|
+
);
|
|
5235
|
+
}
|
|
5184
5236
|
async function graphql(client, document, variables) {
|
|
5185
5237
|
const response = await client._request("POST", "/query", {
|
|
5186
5238
|
body: { query: document, variables }
|
|
@@ -5266,17 +5318,29 @@ var ThesesResource = class {
|
|
|
5266
5318
|
related(id, params = {}) {
|
|
5267
5319
|
return relatedTheses(this.client, id, params);
|
|
5268
5320
|
}
|
|
5269
|
-
async assetCandidates(text) {
|
|
5321
|
+
async assetCandidates(text, params = {}) {
|
|
5270
5322
|
this.client._requireAuth();
|
|
5271
5323
|
const source = requireBody(text);
|
|
5324
|
+
const input = {
|
|
5325
|
+
text: source,
|
|
5326
|
+
selectedEntityIds: requireIDs(params.entityIds ?? [], "entityIds")
|
|
5327
|
+
};
|
|
5328
|
+
if (params.thesisId !== void 0)
|
|
5329
|
+
input.thesisId = requireID(params.thesisId, "thesisId");
|
|
5330
|
+
if (params.discover !== void 0) {
|
|
5331
|
+
if (typeof params.discover !== "boolean")
|
|
5332
|
+
throw invalidArgument("discover must be a boolean");
|
|
5333
|
+
input.discover = params.discover;
|
|
5334
|
+
}
|
|
5272
5335
|
const response = await this.client._request("POST", "/query", {
|
|
5273
5336
|
body: {
|
|
5274
5337
|
query: `query ThesisAssetCandidates($input: ThesisAssetCandidatesInput!) {
|
|
5275
5338
|
viewer { thesisAssetCandidates(input: $input) {
|
|
5276
5339
|
mentions { quote ticker resolution stance candidates { entityId ticker name kind } }
|
|
5340
|
+
returnPreview { tracking askSwitch directions { entityId direction } keptEntityIds lastLegRemoved }
|
|
5277
5341
|
} }
|
|
5278
5342
|
}`,
|
|
5279
|
-
variables: { input
|
|
5343
|
+
variables: { input }
|
|
5280
5344
|
}
|
|
5281
5345
|
});
|
|
5282
5346
|
if (Array.isArray(response?.errors) && response.errors.length > 0) {
|
|
@@ -5314,7 +5378,11 @@ var ThesesResource = class {
|
|
|
5314
5378
|
});
|
|
5315
5379
|
return { ...item, candidates };
|
|
5316
5380
|
});
|
|
5317
|
-
return { mentions };
|
|
5381
|
+
return { mentions, returnPreview: returnPreview(result.returnPreview) };
|
|
5382
|
+
}
|
|
5383
|
+
/** The Thesis return of a Playbook's current publication; detail revalues it. */
|
|
5384
|
+
thesisReturn(id, params = {}) {
|
|
5385
|
+
return thesisReturn(this.client, id, params);
|
|
5318
5386
|
}
|
|
5319
5387
|
async create(params) {
|
|
5320
5388
|
this.client._requireAuth();
|
|
@@ -5376,30 +5444,6 @@ var ThesesResource = class {
|
|
|
5376
5444
|
throw invalidResponse4("Update list must match requested Thesis");
|
|
5377
5445
|
return { versions, next_cursor: response.next_cursor };
|
|
5378
5446
|
}
|
|
5379
|
-
/** Deletes only the selected Update; never falls back to whole-Thesis deletion. */
|
|
5380
|
-
async deleteUpdate(id, authorVersionID, expectedAuthorVersionID) {
|
|
5381
|
-
this.client._requireAuth();
|
|
5382
|
-
const thesisID = requireID(id, "id");
|
|
5383
|
-
const versionID = requireID(authorVersionID, "author_version_id");
|
|
5384
|
-
const expected = requireID(
|
|
5385
|
-
expectedAuthorVersionID,
|
|
5386
|
-
"expected_author_version_id"
|
|
5387
|
-
);
|
|
5388
|
-
const response = thesisResponse(
|
|
5389
|
-
await this.client._request(
|
|
5390
|
-
"DELETE",
|
|
5391
|
-
`/api/v1/theses/${thesisID}/versions/${versionID}`,
|
|
5392
|
-
{
|
|
5393
|
-
query: { expected_author_version_id: expected }
|
|
5394
|
-
}
|
|
5395
|
-
)
|
|
5396
|
-
);
|
|
5397
|
-
if (response.thesis.id !== thesisID)
|
|
5398
|
-
throw invalidResponse4(
|
|
5399
|
-
"delete Update response must match requested Thesis"
|
|
5400
|
-
);
|
|
5401
|
-
return response;
|
|
5402
|
-
}
|
|
5403
5447
|
async signals(id, params = {}) {
|
|
5404
5448
|
this.client._requireAuth();
|
|
5405
5449
|
const first = params.first ?? 20;
|
|
@@ -5575,35 +5619,6 @@ var ThesesResource = class {
|
|
|
5575
5619
|
}
|
|
5576
5620
|
return response;
|
|
5577
5621
|
}
|
|
5578
|
-
async close(id, params) {
|
|
5579
|
-
this.client._requireAuth();
|
|
5580
|
-
const body = {
|
|
5581
|
-
expected_author_version_id: requireID(
|
|
5582
|
-
params.expected_author_version_id,
|
|
5583
|
-
"expected_author_version_id"
|
|
5584
|
-
)
|
|
5585
|
-
};
|
|
5586
|
-
if (params.note !== void 0) body.note = requireText2(params.note, "note");
|
|
5587
|
-
return thesisResponse(
|
|
5588
|
-
await this.client._request(
|
|
5589
|
-
"POST",
|
|
5590
|
-
`/api/v1/theses/${requireID(id, "id")}/close`,
|
|
5591
|
-
{ body }
|
|
5592
|
-
)
|
|
5593
|
-
);
|
|
5594
|
-
}
|
|
5595
|
-
async delete(id) {
|
|
5596
|
-
this.client._requireAuth();
|
|
5597
|
-
const response = await this.client._request(
|
|
5598
|
-
"DELETE",
|
|
5599
|
-
`/api/v1/theses/${requireID(id, "id")}`
|
|
5600
|
-
);
|
|
5601
|
-
if (response === void 0) return {};
|
|
5602
|
-
if (!isRecord2(response) || Object.keys(response).length !== 0) {
|
|
5603
|
-
throw invalidResponse4("delete response must be {}");
|
|
5604
|
-
}
|
|
5605
|
-
return {};
|
|
5606
|
-
}
|
|
5607
5622
|
async rewrite(params) {
|
|
5608
5623
|
this.client._requireAuth();
|
|
5609
5624
|
const body = requireBody(params.body);
|
|
@@ -5646,6 +5661,8 @@ function createBody(params) {
|
|
|
5646
5661
|
}
|
|
5647
5662
|
if (params.tickers !== void 0)
|
|
5648
5663
|
body.tickers = requireTickers(params.tickers);
|
|
5664
|
+
if (params.track_return !== void 0)
|
|
5665
|
+
body.track_return = requireTrackReturn(params.track_return);
|
|
5649
5666
|
if (params.entity_stances !== void 0) {
|
|
5650
5667
|
body.entity_stances = requireEntityStances(
|
|
5651
5668
|
params.entity_stances,
|
|
@@ -5654,6 +5671,52 @@ function createBody(params) {
|
|
|
5654
5671
|
}
|
|
5655
5672
|
return body;
|
|
5656
5673
|
}
|
|
5674
|
+
var ENTITY_STANCES = [
|
|
5675
|
+
"unknown",
|
|
5676
|
+
"bullish",
|
|
5677
|
+
"bearish",
|
|
5678
|
+
"none"
|
|
5679
|
+
];
|
|
5680
|
+
var THESIS_DIRECTIONS = [
|
|
5681
|
+
"UNKNOWN",
|
|
5682
|
+
"BULLISH",
|
|
5683
|
+
"BEARISH",
|
|
5684
|
+
"NONE"
|
|
5685
|
+
];
|
|
5686
|
+
var RETURN_TRACKING = ["UNSET", "ON", "OFF"];
|
|
5687
|
+
function requireTrackReturn(value) {
|
|
5688
|
+
if (typeof value !== "boolean")
|
|
5689
|
+
throw invalidArgument("track_return must be a boolean");
|
|
5690
|
+
return value;
|
|
5691
|
+
}
|
|
5692
|
+
function selectedDirections(value, field) {
|
|
5693
|
+
if (!Array.isArray(value)) throw invalidResponse4(`${field} must be an array`);
|
|
5694
|
+
return value.map((item, index) => {
|
|
5695
|
+
if (!isRecord2(item) || !THESIS_DIRECTIONS.includes(item.direction))
|
|
5696
|
+
throw invalidResponse4(`${field}[${index}] is invalid`);
|
|
5697
|
+
return {
|
|
5698
|
+
entityId: responseID(item.entityId, `${field}[${index}].entityId`),
|
|
5699
|
+
direction: item.direction
|
|
5700
|
+
};
|
|
5701
|
+
});
|
|
5702
|
+
}
|
|
5703
|
+
function returnPreview(value) {
|
|
5704
|
+
if (value === null || value === void 0) return null;
|
|
5705
|
+
if (!isRecord2(value) || !RETURN_TRACKING.includes(value.tracking) || typeof value.askSwitch !== "boolean" || typeof value.lastLegRemoved !== "boolean" || !Array.isArray(value.keptEntityIds))
|
|
5706
|
+
throw invalidResponse4("returnPreview is invalid");
|
|
5707
|
+
return {
|
|
5708
|
+
tracking: value.tracking,
|
|
5709
|
+
askSwitch: value.askSwitch,
|
|
5710
|
+
directions: selectedDirections(
|
|
5711
|
+
value.directions,
|
|
5712
|
+
"returnPreview.directions"
|
|
5713
|
+
),
|
|
5714
|
+
keptEntityIds: value.keptEntityIds.map(
|
|
5715
|
+
(id, index) => responseID(id, `returnPreview.keptEntityIds[${index}]`)
|
|
5716
|
+
),
|
|
5717
|
+
lastLegRemoved: value.lastLegRemoved
|
|
5718
|
+
};
|
|
5719
|
+
}
|
|
5657
5720
|
function requireEntityStances(value, entityIDs) {
|
|
5658
5721
|
if (!Array.isArray(value) || value.length > MAX_ENTITY_IDS)
|
|
5659
5722
|
throw invalidArgument("entity_stances must contain at most 100 values");
|
|
@@ -5671,7 +5734,7 @@ function requireEntityStances(value, entityIDs) {
|
|
|
5671
5734
|
"entity stance must reference one unique entity_id"
|
|
5672
5735
|
);
|
|
5673
5736
|
seen.add(entityID);
|
|
5674
|
-
if (!
|
|
5737
|
+
if (!ENTITY_STANCES.includes(item.stance))
|
|
5675
5738
|
throw invalidArgument(`entity_stances[${index}].stance is invalid`);
|
|
5676
5739
|
return { entity_id: entityID, stance: item.stance };
|
|
5677
5740
|
});
|
|
@@ -5686,8 +5749,7 @@ function updateBody(params) {
|
|
|
5686
5749
|
body: requireBody(params.body),
|
|
5687
5750
|
title: requireTitle(params.title ?? ""),
|
|
5688
5751
|
entity_ids: requireIDs(params.entity_ids ?? [], "entity_ids"),
|
|
5689
|
-
visibility: requireVisibility(params.visibility)
|
|
5690
|
-
editorial: params.editorial ?? false
|
|
5752
|
+
visibility: requireVisibility(params.visibility)
|
|
5691
5753
|
};
|
|
5692
5754
|
if (params.medias !== void 0) {
|
|
5693
5755
|
if (!Array.isArray(params.medias) || params.medias.length > 20)
|
|
@@ -5702,6 +5764,8 @@ function updateBody(params) {
|
|
|
5702
5764
|
body.archived = params.archived;
|
|
5703
5765
|
}
|
|
5704
5766
|
if (params.note !== void 0) body.note = requireText2(params.note, "note");
|
|
5767
|
+
if (params.track_return !== void 0)
|
|
5768
|
+
body.track_return = requireTrackReturn(params.track_return);
|
|
5705
5769
|
if (params.entity_stances !== void 0) {
|
|
5706
5770
|
body.entity_stances = requireEntityStances(
|
|
5707
5771
|
params.entity_stances,
|
|
@@ -5764,9 +5828,20 @@ function thesisResponse(response) {
|
|
|
5764
5828
|
const entityID = responseID(item.entity_id, "entity_stances.entity_id");
|
|
5765
5829
|
if (!value.entity_ids.includes(entityID))
|
|
5766
5830
|
throw invalidResponse4("entity stance must reference a thesis entity");
|
|
5767
|
-
if (!
|
|
5831
|
+
if (!ENTITY_STANCES.includes(item.stance))
|
|
5768
5832
|
throw invalidResponse4("thesis.entity_stances contains invalid stance");
|
|
5769
|
-
|
|
5833
|
+
const stance = {
|
|
5834
|
+
entity_id: entityID,
|
|
5835
|
+
stance: item.stance
|
|
5836
|
+
};
|
|
5837
|
+
if (item.direction !== void 0) {
|
|
5838
|
+
if (!ENTITY_STANCES.includes(item.direction))
|
|
5839
|
+
throw invalidResponse4(
|
|
5840
|
+
"thesis.entity_stances contains invalid direction"
|
|
5841
|
+
);
|
|
5842
|
+
stance.direction = item.direction;
|
|
5843
|
+
}
|
|
5844
|
+
return stance;
|
|
5770
5845
|
});
|
|
5771
5846
|
}
|
|
5772
5847
|
return { thesis: value };
|
|
@@ -6617,7 +6692,8 @@ var AlvaClient = class {
|
|
|
6617
6692
|
throw new AlvaError(
|
|
6618
6693
|
data.error.code ?? "UNKNOWN",
|
|
6619
6694
|
data.error.message ?? `HTTP ${response.status}`,
|
|
6620
|
-
response.status
|
|
6695
|
+
response.status,
|
|
6696
|
+
data.details
|
|
6621
6697
|
);
|
|
6622
6698
|
}
|
|
6623
6699
|
} catch (e) {
|
|
@@ -6747,14 +6823,16 @@ var stripPbsvFromUrl = (targetWindow) => {
|
|
|
6747
6823
|
};
|
|
6748
6824
|
var parseBootParams = (targetWindow) => {
|
|
6749
6825
|
const params = new URLSearchParams(targetWindow.location.search);
|
|
6750
|
-
|
|
6826
|
+
const boot = targetWindow;
|
|
6827
|
+
cachedToken = boot.__ALVA_PBSV_BOOTSTRAP__ || null;
|
|
6828
|
+
delete boot.__ALVA_PBSV_BOOTSTRAP__;
|
|
6829
|
+
if (params.has("_pbsv")) stripPbsvFromUrl(targetWindow);
|
|
6751
6830
|
expectedParentOrigin = params.get("parent_origin");
|
|
6752
6831
|
apiOrigin = (params.get("api_origin") || DEFAULT_API_ORIGIN).replace(
|
|
6753
6832
|
/\/$/,
|
|
6754
6833
|
""
|
|
6755
6834
|
);
|
|
6756
6835
|
playbookIdFromBoot = playbookIdFromToken(cachedToken);
|
|
6757
|
-
if (cachedToken) stripPbsvFromUrl(targetWindow);
|
|
6758
6836
|
};
|
|
6759
6837
|
var safeJson = async (response) => {
|
|
6760
6838
|
try {
|
|
@@ -7080,7 +7158,7 @@ var installPlaybookRuntime = (targetWindow) => {
|
|
|
7080
7158
|
};
|
|
7081
7159
|
|
|
7082
7160
|
// src/index.ts
|
|
7083
|
-
var VERSION = true ? "0.
|
|
7161
|
+
var VERSION = true ? "0.36.0-beta.0" : "dev";
|
|
7084
7162
|
export {
|
|
7085
7163
|
AlertsResource,
|
|
7086
7164
|
AlvaClient,
|