@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.cjs
CHANGED
|
@@ -5249,6 +5249,58 @@ function nextCursor(page) {
|
|
|
5249
5249
|
throw invalid3();
|
|
5250
5250
|
return info.hasNextPage ? info.endCursor : null;
|
|
5251
5251
|
}
|
|
5252
|
+
var RETURN_QUERY = `query ToolkitThesisReturn($id: ID!, $detail: Boolean!) {
|
|
5253
|
+
node(id: $id) { ... on Playbook { latestRelease { thesisPublication {
|
|
5254
|
+
returnTracking
|
|
5255
|
+
thesisReturn(detail: $detail) {
|
|
5256
|
+
live value firstFillAtMs pricedAtMs stale computedAtMs
|
|
5257
|
+
updates { authorVersionId publishedAtMs startValue updateReturn
|
|
5258
|
+
positions { entityId symbol direction startPrice startAtMs endPrice endAtMs end positionReturn currency } }
|
|
5259
|
+
}
|
|
5260
|
+
} } } }
|
|
5261
|
+
}`;
|
|
5262
|
+
async function thesisReturn(client, id, params = {}) {
|
|
5263
|
+
if (!isPositiveInt64(id))
|
|
5264
|
+
throw argument("id must be an internal positive int64 Playbook ID");
|
|
5265
|
+
if (params.detail !== void 0 && typeof params.detail !== "boolean")
|
|
5266
|
+
throw argument("detail must be a boolean");
|
|
5267
|
+
client._requireAuth();
|
|
5268
|
+
const data = await graphql(client, RETURN_QUERY, {
|
|
5269
|
+
id: `Playbook:${id}`,
|
|
5270
|
+
detail: params.detail ?? false
|
|
5271
|
+
});
|
|
5272
|
+
if (data.node === null) throw notFound();
|
|
5273
|
+
if (!record2(data.node)) throw invalid3();
|
|
5274
|
+
const release = data.node.latestRelease;
|
|
5275
|
+
if (release === null || release === void 0)
|
|
5276
|
+
return { playbookId: id, returnTracking: null, thesisReturn: null };
|
|
5277
|
+
if (!record2(release)) throw invalid3();
|
|
5278
|
+
const publication = release.thesisPublication;
|
|
5279
|
+
if (publication === null)
|
|
5280
|
+
return { playbookId: id, returnTracking: null, thesisReturn: null };
|
|
5281
|
+
if (!record2(publication)) throw invalid3();
|
|
5282
|
+
const tracking = publication.returnTracking;
|
|
5283
|
+
if (tracking !== null && !["UNSET", "ON", "OFF"].includes(tracking))
|
|
5284
|
+
throw invalid3();
|
|
5285
|
+
const value = publication.thesisReturn;
|
|
5286
|
+
if (value !== null && !validThesisReturn(value)) throw invalid3();
|
|
5287
|
+
return {
|
|
5288
|
+
playbookId: id,
|
|
5289
|
+
returnTracking: tracking,
|
|
5290
|
+
thesisReturn: value
|
|
5291
|
+
};
|
|
5292
|
+
}
|
|
5293
|
+
function validThesisReturn(value) {
|
|
5294
|
+
if (!record2(value) || typeof value.live !== "boolean" || typeof value.value !== "number" || typeof value.stale !== "boolean" || typeof value.computedAtMs !== "number" || !Array.isArray(value.updates))
|
|
5295
|
+
return false;
|
|
5296
|
+
return value.updates.every(
|
|
5297
|
+
(update) => record2(update) && nonempty(update.authorVersionId) && typeof update.publishedAtMs === "number" && typeof update.startValue === "number" && Array.isArray(update.positions) && update.positions.every(
|
|
5298
|
+
(position) => record2(position) && nonempty(position.symbol) && ["BULLISH", "BEARISH"].includes(position.direction) && ["PENDING", "NEXT_UPDATE", "LATEST"].includes(
|
|
5299
|
+
position.end
|
|
5300
|
+
) && typeof position.positionReturn === "number"
|
|
5301
|
+
)
|
|
5302
|
+
);
|
|
5303
|
+
}
|
|
5252
5304
|
async function graphql(client, document, variables) {
|
|
5253
5305
|
const response = await client._request("POST", "/query", {
|
|
5254
5306
|
body: { query: document, variables }
|
|
@@ -5334,17 +5386,29 @@ var ThesesResource = class {
|
|
|
5334
5386
|
related(id, params = {}) {
|
|
5335
5387
|
return relatedTheses(this.client, id, params);
|
|
5336
5388
|
}
|
|
5337
|
-
async assetCandidates(text) {
|
|
5389
|
+
async assetCandidates(text, params = {}) {
|
|
5338
5390
|
this.client._requireAuth();
|
|
5339
5391
|
const source = requireBody(text);
|
|
5392
|
+
const input = {
|
|
5393
|
+
text: source,
|
|
5394
|
+
selectedEntityIds: requireIDs(params.entityIds ?? [], "entityIds")
|
|
5395
|
+
};
|
|
5396
|
+
if (params.thesisId !== void 0)
|
|
5397
|
+
input.thesisId = requireID(params.thesisId, "thesisId");
|
|
5398
|
+
if (params.discover !== void 0) {
|
|
5399
|
+
if (typeof params.discover !== "boolean")
|
|
5400
|
+
throw invalidArgument("discover must be a boolean");
|
|
5401
|
+
input.discover = params.discover;
|
|
5402
|
+
}
|
|
5340
5403
|
const response = await this.client._request("POST", "/query", {
|
|
5341
5404
|
body: {
|
|
5342
5405
|
query: `query ThesisAssetCandidates($input: ThesisAssetCandidatesInput!) {
|
|
5343
5406
|
viewer { thesisAssetCandidates(input: $input) {
|
|
5344
5407
|
mentions { quote ticker resolution stance candidates { entityId ticker name kind } }
|
|
5408
|
+
returnPreview { tracking askSwitch directions { entityId direction } keptEntityIds lastLegRemoved }
|
|
5345
5409
|
} }
|
|
5346
5410
|
}`,
|
|
5347
|
-
variables: { input
|
|
5411
|
+
variables: { input }
|
|
5348
5412
|
}
|
|
5349
5413
|
});
|
|
5350
5414
|
if (Array.isArray(response?.errors) && response.errors.length > 0) {
|
|
@@ -5382,7 +5446,11 @@ var ThesesResource = class {
|
|
|
5382
5446
|
});
|
|
5383
5447
|
return { ...item, candidates };
|
|
5384
5448
|
});
|
|
5385
|
-
return { mentions };
|
|
5449
|
+
return { mentions, returnPreview: returnPreview(result.returnPreview) };
|
|
5450
|
+
}
|
|
5451
|
+
/** The Thesis return of a Playbook's current publication; detail revalues it. */
|
|
5452
|
+
thesisReturn(id, params = {}) {
|
|
5453
|
+
return thesisReturn(this.client, id, params);
|
|
5386
5454
|
}
|
|
5387
5455
|
async create(params) {
|
|
5388
5456
|
this.client._requireAuth();
|
|
@@ -5444,30 +5512,6 @@ var ThesesResource = class {
|
|
|
5444
5512
|
throw invalidResponse4("Update list must match requested Thesis");
|
|
5445
5513
|
return { versions, next_cursor: response.next_cursor };
|
|
5446
5514
|
}
|
|
5447
|
-
/** Deletes only the selected Update; never falls back to whole-Thesis deletion. */
|
|
5448
|
-
async deleteUpdate(id, authorVersionID, expectedAuthorVersionID) {
|
|
5449
|
-
this.client._requireAuth();
|
|
5450
|
-
const thesisID = requireID(id, "id");
|
|
5451
|
-
const versionID = requireID(authorVersionID, "author_version_id");
|
|
5452
|
-
const expected = requireID(
|
|
5453
|
-
expectedAuthorVersionID,
|
|
5454
|
-
"expected_author_version_id"
|
|
5455
|
-
);
|
|
5456
|
-
const response = thesisResponse(
|
|
5457
|
-
await this.client._request(
|
|
5458
|
-
"DELETE",
|
|
5459
|
-
`/api/v1/theses/${thesisID}/versions/${versionID}`,
|
|
5460
|
-
{
|
|
5461
|
-
query: { expected_author_version_id: expected }
|
|
5462
|
-
}
|
|
5463
|
-
)
|
|
5464
|
-
);
|
|
5465
|
-
if (response.thesis.id !== thesisID)
|
|
5466
|
-
throw invalidResponse4(
|
|
5467
|
-
"delete Update response must match requested Thesis"
|
|
5468
|
-
);
|
|
5469
|
-
return response;
|
|
5470
|
-
}
|
|
5471
5515
|
async signals(id, params = {}) {
|
|
5472
5516
|
this.client._requireAuth();
|
|
5473
5517
|
const first = params.first ?? 20;
|
|
@@ -5643,35 +5687,6 @@ var ThesesResource = class {
|
|
|
5643
5687
|
}
|
|
5644
5688
|
return response;
|
|
5645
5689
|
}
|
|
5646
|
-
async close(id, params) {
|
|
5647
|
-
this.client._requireAuth();
|
|
5648
|
-
const body = {
|
|
5649
|
-
expected_author_version_id: requireID(
|
|
5650
|
-
params.expected_author_version_id,
|
|
5651
|
-
"expected_author_version_id"
|
|
5652
|
-
)
|
|
5653
|
-
};
|
|
5654
|
-
if (params.note !== void 0) body.note = requireText2(params.note, "note");
|
|
5655
|
-
return thesisResponse(
|
|
5656
|
-
await this.client._request(
|
|
5657
|
-
"POST",
|
|
5658
|
-
`/api/v1/theses/${requireID(id, "id")}/close`,
|
|
5659
|
-
{ body }
|
|
5660
|
-
)
|
|
5661
|
-
);
|
|
5662
|
-
}
|
|
5663
|
-
async delete(id) {
|
|
5664
|
-
this.client._requireAuth();
|
|
5665
|
-
const response = await this.client._request(
|
|
5666
|
-
"DELETE",
|
|
5667
|
-
`/api/v1/theses/${requireID(id, "id")}`
|
|
5668
|
-
);
|
|
5669
|
-
if (response === void 0) return {};
|
|
5670
|
-
if (!isRecord2(response) || Object.keys(response).length !== 0) {
|
|
5671
|
-
throw invalidResponse4("delete response must be {}");
|
|
5672
|
-
}
|
|
5673
|
-
return {};
|
|
5674
|
-
}
|
|
5675
5690
|
async rewrite(params) {
|
|
5676
5691
|
this.client._requireAuth();
|
|
5677
5692
|
const body = requireBody(params.body);
|
|
@@ -5714,6 +5729,8 @@ function createBody(params) {
|
|
|
5714
5729
|
}
|
|
5715
5730
|
if (params.tickers !== void 0)
|
|
5716
5731
|
body.tickers = requireTickers(params.tickers);
|
|
5732
|
+
if (params.track_return !== void 0)
|
|
5733
|
+
body.track_return = requireTrackReturn(params.track_return);
|
|
5717
5734
|
if (params.entity_stances !== void 0) {
|
|
5718
5735
|
body.entity_stances = requireEntityStances(
|
|
5719
5736
|
params.entity_stances,
|
|
@@ -5722,6 +5739,52 @@ function createBody(params) {
|
|
|
5722
5739
|
}
|
|
5723
5740
|
return body;
|
|
5724
5741
|
}
|
|
5742
|
+
var ENTITY_STANCES = [
|
|
5743
|
+
"unknown",
|
|
5744
|
+
"bullish",
|
|
5745
|
+
"bearish",
|
|
5746
|
+
"none"
|
|
5747
|
+
];
|
|
5748
|
+
var THESIS_DIRECTIONS = [
|
|
5749
|
+
"UNKNOWN",
|
|
5750
|
+
"BULLISH",
|
|
5751
|
+
"BEARISH",
|
|
5752
|
+
"NONE"
|
|
5753
|
+
];
|
|
5754
|
+
var RETURN_TRACKING = ["UNSET", "ON", "OFF"];
|
|
5755
|
+
function requireTrackReturn(value) {
|
|
5756
|
+
if (typeof value !== "boolean")
|
|
5757
|
+
throw invalidArgument("track_return must be a boolean");
|
|
5758
|
+
return value;
|
|
5759
|
+
}
|
|
5760
|
+
function selectedDirections(value, field) {
|
|
5761
|
+
if (!Array.isArray(value)) throw invalidResponse4(`${field} must be an array`);
|
|
5762
|
+
return value.map((item, index) => {
|
|
5763
|
+
if (!isRecord2(item) || !THESIS_DIRECTIONS.includes(item.direction))
|
|
5764
|
+
throw invalidResponse4(`${field}[${index}] is invalid`);
|
|
5765
|
+
return {
|
|
5766
|
+
entityId: responseID(item.entityId, `${field}[${index}].entityId`),
|
|
5767
|
+
direction: item.direction
|
|
5768
|
+
};
|
|
5769
|
+
});
|
|
5770
|
+
}
|
|
5771
|
+
function returnPreview(value) {
|
|
5772
|
+
if (value === null || value === void 0) return null;
|
|
5773
|
+
if (!isRecord2(value) || !RETURN_TRACKING.includes(value.tracking) || typeof value.askSwitch !== "boolean" || typeof value.lastLegRemoved !== "boolean" || !Array.isArray(value.keptEntityIds))
|
|
5774
|
+
throw invalidResponse4("returnPreview is invalid");
|
|
5775
|
+
return {
|
|
5776
|
+
tracking: value.tracking,
|
|
5777
|
+
askSwitch: value.askSwitch,
|
|
5778
|
+
directions: selectedDirections(
|
|
5779
|
+
value.directions,
|
|
5780
|
+
"returnPreview.directions"
|
|
5781
|
+
),
|
|
5782
|
+
keptEntityIds: value.keptEntityIds.map(
|
|
5783
|
+
(id, index) => responseID(id, `returnPreview.keptEntityIds[${index}]`)
|
|
5784
|
+
),
|
|
5785
|
+
lastLegRemoved: value.lastLegRemoved
|
|
5786
|
+
};
|
|
5787
|
+
}
|
|
5725
5788
|
function requireEntityStances(value, entityIDs) {
|
|
5726
5789
|
if (!Array.isArray(value) || value.length > MAX_ENTITY_IDS)
|
|
5727
5790
|
throw invalidArgument("entity_stances must contain at most 100 values");
|
|
@@ -5739,7 +5802,7 @@ function requireEntityStances(value, entityIDs) {
|
|
|
5739
5802
|
"entity stance must reference one unique entity_id"
|
|
5740
5803
|
);
|
|
5741
5804
|
seen.add(entityID);
|
|
5742
|
-
if (!
|
|
5805
|
+
if (!ENTITY_STANCES.includes(item.stance))
|
|
5743
5806
|
throw invalidArgument(`entity_stances[${index}].stance is invalid`);
|
|
5744
5807
|
return { entity_id: entityID, stance: item.stance };
|
|
5745
5808
|
});
|
|
@@ -5754,8 +5817,7 @@ function updateBody(params) {
|
|
|
5754
5817
|
body: requireBody(params.body),
|
|
5755
5818
|
title: requireTitle(params.title ?? ""),
|
|
5756
5819
|
entity_ids: requireIDs(params.entity_ids ?? [], "entity_ids"),
|
|
5757
|
-
visibility: requireVisibility(params.visibility)
|
|
5758
|
-
editorial: params.editorial ?? false
|
|
5820
|
+
visibility: requireVisibility(params.visibility)
|
|
5759
5821
|
};
|
|
5760
5822
|
if (params.medias !== void 0) {
|
|
5761
5823
|
if (!Array.isArray(params.medias) || params.medias.length > 20)
|
|
@@ -5770,6 +5832,8 @@ function updateBody(params) {
|
|
|
5770
5832
|
body.archived = params.archived;
|
|
5771
5833
|
}
|
|
5772
5834
|
if (params.note !== void 0) body.note = requireText2(params.note, "note");
|
|
5835
|
+
if (params.track_return !== void 0)
|
|
5836
|
+
body.track_return = requireTrackReturn(params.track_return);
|
|
5773
5837
|
if (params.entity_stances !== void 0) {
|
|
5774
5838
|
body.entity_stances = requireEntityStances(
|
|
5775
5839
|
params.entity_stances,
|
|
@@ -5832,9 +5896,20 @@ function thesisResponse(response) {
|
|
|
5832
5896
|
const entityID = responseID(item.entity_id, "entity_stances.entity_id");
|
|
5833
5897
|
if (!value.entity_ids.includes(entityID))
|
|
5834
5898
|
throw invalidResponse4("entity stance must reference a thesis entity");
|
|
5835
|
-
if (!
|
|
5899
|
+
if (!ENTITY_STANCES.includes(item.stance))
|
|
5836
5900
|
throw invalidResponse4("thesis.entity_stances contains invalid stance");
|
|
5837
|
-
|
|
5901
|
+
const stance = {
|
|
5902
|
+
entity_id: entityID,
|
|
5903
|
+
stance: item.stance
|
|
5904
|
+
};
|
|
5905
|
+
if (item.direction !== void 0) {
|
|
5906
|
+
if (!ENTITY_STANCES.includes(item.direction))
|
|
5907
|
+
throw invalidResponse4(
|
|
5908
|
+
"thesis.entity_stances contains invalid direction"
|
|
5909
|
+
);
|
|
5910
|
+
stance.direction = item.direction;
|
|
5911
|
+
}
|
|
5912
|
+
return stance;
|
|
5838
5913
|
});
|
|
5839
5914
|
}
|
|
5840
5915
|
return { thesis: value };
|
|
@@ -6685,7 +6760,8 @@ var AlvaClient = class {
|
|
|
6685
6760
|
throw new AlvaError(
|
|
6686
6761
|
data.error.code ?? "UNKNOWN",
|
|
6687
6762
|
data.error.message ?? `HTTP ${response.status}`,
|
|
6688
|
-
response.status
|
|
6763
|
+
response.status,
|
|
6764
|
+
data.details
|
|
6689
6765
|
);
|
|
6690
6766
|
}
|
|
6691
6767
|
} catch (e) {
|
|
@@ -6815,14 +6891,16 @@ var stripPbsvFromUrl = (targetWindow) => {
|
|
|
6815
6891
|
};
|
|
6816
6892
|
var parseBootParams = (targetWindow) => {
|
|
6817
6893
|
const params = new URLSearchParams(targetWindow.location.search);
|
|
6818
|
-
|
|
6894
|
+
const boot = targetWindow;
|
|
6895
|
+
cachedToken = boot.__ALVA_PBSV_BOOTSTRAP__ || null;
|
|
6896
|
+
delete boot.__ALVA_PBSV_BOOTSTRAP__;
|
|
6897
|
+
if (params.has("_pbsv")) stripPbsvFromUrl(targetWindow);
|
|
6819
6898
|
expectedParentOrigin = params.get("parent_origin");
|
|
6820
6899
|
apiOrigin = (params.get("api_origin") || DEFAULT_API_ORIGIN).replace(
|
|
6821
6900
|
/\/$/,
|
|
6822
6901
|
""
|
|
6823
6902
|
);
|
|
6824
6903
|
playbookIdFromBoot = playbookIdFromToken(cachedToken);
|
|
6825
|
-
if (cachedToken) stripPbsvFromUrl(targetWindow);
|
|
6826
6904
|
};
|
|
6827
6905
|
var safeJson = async (response) => {
|
|
6828
6906
|
try {
|
|
@@ -7148,7 +7226,7 @@ var installPlaybookRuntime = (targetWindow) => {
|
|
|
7148
7226
|
};
|
|
7149
7227
|
|
|
7150
7228
|
// src/index.ts
|
|
7151
|
-
var VERSION = true ? "0.
|
|
7229
|
+
var VERSION = true ? "0.36.0-beta.0" : "dev";
|
|
7152
7230
|
// Annotate the CommonJS export names for ESM import in node:
|
|
7153
7231
|
0 && (module.exports = {
|
|
7154
7232
|
AlertsResource,
|