@alva-ai/toolkit 0.38.0-beta.0 → 0.38.0-beta.1
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 +3 -3
- package/dist/browser.global.js +50 -49
- package/dist/browser.global.js.map +1 -1
- package/dist/cli.d.ts +62 -5
- package/dist/cli.js +204 -13
- package/dist/cli.js.map +1 -1
- package/dist/dispatch.d.ts +62 -5
- package/dist/dispatch.js +84 -8
- package/dist/dispatch.js.map +1 -1
- package/dist/index.cjs +151 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +62 -5
- package/dist/index.d.ts +62 -5
- package/dist/index.js +151 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3083,7 +3083,8 @@ var RETURN_QUERY = `query ToolkitThesisReturn($id: ID!, $detail: Boolean!) {
|
|
|
3083
3083
|
thesisReturn(detail: $detail) {
|
|
3084
3084
|
live value firstFillAtMs pricedAtMs stale computedAtMs
|
|
3085
3085
|
updates { authorVersionId publishedAtMs startValue updateReturn
|
|
3086
|
-
positions { entityId symbol direction startPrice startAtMs endPrice endAtMs end positionReturn currency } }
|
|
3086
|
+
positions { entityId symbol direction startPrice startAtMs endPrice endAtMs end positionReturn currency weight } }
|
|
3087
|
+
allocation { holdings { entityId symbol direction weight } cash }
|
|
3087
3088
|
}
|
|
3088
3089
|
} } } }
|
|
3089
3090
|
}`;
|
|
@@ -3152,16 +3153,21 @@ async function thesisWatchpoints(client, id) {
|
|
|
3152
3153
|
return { playbookId: id, watchpoints };
|
|
3153
3154
|
}
|
|
3154
3155
|
function validThesisReturn(value) {
|
|
3155
|
-
if (!record2(value) || typeof value.live !== "boolean" || typeof value.value !== "number" || typeof value.stale !== "boolean" || typeof value.computedAtMs !== "number" || !Array.isArray(value.updates))
|
|
3156
|
+
if (!record2(value) || typeof value.live !== "boolean" || typeof value.value !== "number" || typeof value.stale !== "boolean" || typeof value.computedAtMs !== "number" || !Array.isArray(value.updates) || value.allocation !== null && !validAllocation(value.allocation))
|
|
3156
3157
|
return false;
|
|
3157
3158
|
return value.updates.every(
|
|
3158
3159
|
(update) => record2(update) && nonempty(update.authorVersionId) && typeof update.publishedAtMs === "number" && typeof update.startValue === "number" && Array.isArray(update.positions) && update.positions.every(
|
|
3159
3160
|
(position) => record2(position) && nonempty(position.symbol) && ["BULLISH", "BEARISH"].includes(position.direction) && ["PENDING", "NEXT_UPDATE", "LATEST"].includes(
|
|
3160
3161
|
position.end
|
|
3161
|
-
) && typeof position.positionReturn === "number"
|
|
3162
|
+
) && typeof position.positionReturn === "number" && typeof position.weight === "number"
|
|
3162
3163
|
)
|
|
3163
3164
|
);
|
|
3164
3165
|
}
|
|
3166
|
+
function validAllocation(value) {
|
|
3167
|
+
return record2(value) && typeof value.cash === "number" && Array.isArray(value.holdings) && value.holdings.every(
|
|
3168
|
+
(holding) => record2(holding) && nonempty(holding.entityId) && nonempty(holding.symbol) && ["BULLISH", "BEARISH"].includes(holding.direction) && typeof holding.weight === "number"
|
|
3169
|
+
);
|
|
3170
|
+
}
|
|
3165
3171
|
async function graphql(client, document, variables) {
|
|
3166
3172
|
const response = await client._request("POST", "/query", {
|
|
3167
3173
|
body: { query: document, variables }
|
|
@@ -3218,6 +3224,13 @@ function notFound() {
|
|
|
3218
3224
|
}
|
|
3219
3225
|
|
|
3220
3226
|
// src/resources/theses.ts
|
|
3227
|
+
var THESIS_SIGNAL_KINDS = [
|
|
3228
|
+
"fundamentals",
|
|
3229
|
+
"macro",
|
|
3230
|
+
"technicals",
|
|
3231
|
+
"commentary"
|
|
3232
|
+
];
|
|
3233
|
+
var THESIS_SIGNAL_MIN_IMPORTANCES = ["all", "notable", "major"];
|
|
3221
3234
|
var SET_THESIS_STARRED = `mutation SetThesisStarred($input: SetThesisStarredInput!) {
|
|
3222
3235
|
setThesisStarred(input: $input) {
|
|
3223
3236
|
thesisId
|
|
@@ -3323,9 +3336,11 @@ var ThesesResource = class {
|
|
|
3323
3336
|
async create(params) {
|
|
3324
3337
|
this.client._requireAuth();
|
|
3325
3338
|
const body = createBody(params);
|
|
3326
|
-
|
|
3339
|
+
const response = thesisResponse(
|
|
3327
3340
|
await this.client._request("POST", "/api/v1/theses", { body })
|
|
3328
3341
|
);
|
|
3342
|
+
requireKeptWeights(body.entity_stances, response.thesis.entity_stances);
|
|
3343
|
+
return response;
|
|
3329
3344
|
}
|
|
3330
3345
|
async get(id) {
|
|
3331
3346
|
this.client._requireAuth();
|
|
@@ -3414,6 +3429,7 @@ var ThesesResource = class {
|
|
|
3414
3429
|
if (response.thesis.id !== thesisID) {
|
|
3415
3430
|
throw invalidResponse3("update response must match the requested thesis");
|
|
3416
3431
|
}
|
|
3432
|
+
requireKeptWeights(body.entity_stances, response.thesis.entity_stances);
|
|
3417
3433
|
return response;
|
|
3418
3434
|
}
|
|
3419
3435
|
/**
|
|
@@ -3448,7 +3464,11 @@ var ThesesResource = class {
|
|
|
3448
3464
|
body: current.thesis.body,
|
|
3449
3465
|
title: current.thesis.title,
|
|
3450
3466
|
entity_ids: current.thesis.entity_ids,
|
|
3451
|
-
|
|
3467
|
+
// Directions only: archiving keeps the current Update and unarchiving
|
|
3468
|
+
// keeps its shares without restating them.
|
|
3469
|
+
entity_stances: current.thesis.entity_stances?.map(
|
|
3470
|
+
({ entity_id, stance }) => ({ entity_id, stance })
|
|
3471
|
+
),
|
|
3452
3472
|
visibility: current.thesis.visibility,
|
|
3453
3473
|
archived: params.archived,
|
|
3454
3474
|
medias: current.thesis.medias,
|
|
@@ -3495,6 +3515,45 @@ var ThesesResource = class {
|
|
|
3495
3515
|
is_starred: returnedStarred
|
|
3496
3516
|
};
|
|
3497
3517
|
}
|
|
3518
|
+
/**
|
|
3519
|
+
* Reads which Signals one of the caller's Theses shows: its setting, or every
|
|
3520
|
+
* kind and `all` when it has none. Without an id, reads the setting the caller
|
|
3521
|
+
* last saved, which prefills a new Thesis. Only the Thesis's author can read it.
|
|
3522
|
+
*/
|
|
3523
|
+
async getSignalPreferences(id) {
|
|
3524
|
+
this.client._requireAuth();
|
|
3525
|
+
if (id === void 0) {
|
|
3526
|
+
return signalPreferencesResponse(
|
|
3527
|
+
await this.client._request("GET", "/api/v1/theses/signal-preferences"),
|
|
3528
|
+
null
|
|
3529
|
+
);
|
|
3530
|
+
}
|
|
3531
|
+
const thesisID = requireID(id, "id");
|
|
3532
|
+
return signalPreferencesResponse(
|
|
3533
|
+
await this.client._request(
|
|
3534
|
+
"GET",
|
|
3535
|
+
`/api/v1/theses/${thesisID}/signal-preferences`
|
|
3536
|
+
),
|
|
3537
|
+
thesisID
|
|
3538
|
+
);
|
|
3539
|
+
}
|
|
3540
|
+
/**
|
|
3541
|
+
* Replaces which Signals one of the caller's Theses shows, for every reader,
|
|
3542
|
+
* and records it as the caller's last choice. Author only.
|
|
3543
|
+
*/
|
|
3544
|
+
async setSignalPreferences(id, preferences) {
|
|
3545
|
+
this.client._requireAuth();
|
|
3546
|
+
const thesisID = requireID(id, "id");
|
|
3547
|
+
const input = requireSignalPreferences(preferences);
|
|
3548
|
+
return signalPreferencesResponse(
|
|
3549
|
+
await this.client._request(
|
|
3550
|
+
"PUT",
|
|
3551
|
+
`/api/v1/theses/${thesisID}/signal-preferences`,
|
|
3552
|
+
{ body: { signal_preferences: input } }
|
|
3553
|
+
),
|
|
3554
|
+
thesisID
|
|
3555
|
+
);
|
|
3556
|
+
}
|
|
3498
3557
|
async setSignalEnabled(id, enabled) {
|
|
3499
3558
|
this.client._requireAuth();
|
|
3500
3559
|
const thesisID = requireID(id, "id");
|
|
@@ -3601,6 +3660,10 @@ function createBody(params) {
|
|
|
3601
3660
|
body.tickers = requireTickers(params.tickers);
|
|
3602
3661
|
if (params.track_return !== void 0)
|
|
3603
3662
|
body.track_return = requireTrackReturn(params.track_return);
|
|
3663
|
+
if (params.signal_preferences !== void 0)
|
|
3664
|
+
body.signal_preferences = requireSignalPreferences(
|
|
3665
|
+
params.signal_preferences
|
|
3666
|
+
);
|
|
3604
3667
|
if (params.entity_stances !== void 0) {
|
|
3605
3668
|
body.entity_stances = requireEntityStances(
|
|
3606
3669
|
params.entity_stances,
|
|
@@ -3609,6 +3672,43 @@ function createBody(params) {
|
|
|
3609
3672
|
}
|
|
3610
3673
|
return body;
|
|
3611
3674
|
}
|
|
3675
|
+
function requireSignalPreferences(value) {
|
|
3676
|
+
if (!isRecord(value) || !Array.isArray(value.kinds))
|
|
3677
|
+
throw invalidArgument(
|
|
3678
|
+
"signal_preferences must have kinds and min_importance"
|
|
3679
|
+
);
|
|
3680
|
+
const kinds = [...new Set(value.kinds)];
|
|
3681
|
+
if (kinds.length === 0 || !kinds.every(
|
|
3682
|
+
(kind) => THESIS_SIGNAL_KINDS.includes(kind)
|
|
3683
|
+
))
|
|
3684
|
+
throw invalidArgument(
|
|
3685
|
+
`signal kinds must be one or more of ${THESIS_SIGNAL_KINDS.join(", ")}`
|
|
3686
|
+
);
|
|
3687
|
+
if (!THESIS_SIGNAL_MIN_IMPORTANCES.includes(
|
|
3688
|
+
value.min_importance
|
|
3689
|
+
))
|
|
3690
|
+
throw invalidArgument(
|
|
3691
|
+
`min_importance must be ${THESIS_SIGNAL_MIN_IMPORTANCES.join(", ")}`
|
|
3692
|
+
);
|
|
3693
|
+
return {
|
|
3694
|
+
kinds,
|
|
3695
|
+
min_importance: value.min_importance
|
|
3696
|
+
};
|
|
3697
|
+
}
|
|
3698
|
+
function signalPreferencesResponse(value, thesisID) {
|
|
3699
|
+
if (!isRecord(value) || value.thesis_id !== thesisID)
|
|
3700
|
+
throw invalidResponse3(
|
|
3701
|
+
"Signal setting response must name the requested thesis"
|
|
3702
|
+
);
|
|
3703
|
+
try {
|
|
3704
|
+
return {
|
|
3705
|
+
thesis_id: thesisID,
|
|
3706
|
+
preferences: requireSignalPreferences(value.signal_preferences)
|
|
3707
|
+
};
|
|
3708
|
+
} catch {
|
|
3709
|
+
throw invalidResponse3("response contains an unknown Signal setting");
|
|
3710
|
+
}
|
|
3711
|
+
}
|
|
3612
3712
|
var ENTITY_STANCES = [
|
|
3613
3713
|
"unknown",
|
|
3614
3714
|
"bullish",
|
|
@@ -3674,9 +3774,44 @@ function requireEntityStances(value, entityIDs) {
|
|
|
3674
3774
|
seen.add(entityID);
|
|
3675
3775
|
if (!ENTITY_STANCES.includes(item.stance))
|
|
3676
3776
|
throw invalidArgument(`entity_stances[${index}].stance is invalid`);
|
|
3677
|
-
|
|
3777
|
+
const stance = {
|
|
3778
|
+
entity_id: entityID,
|
|
3779
|
+
stance: item.stance
|
|
3780
|
+
};
|
|
3781
|
+
if (item.weight !== void 0) {
|
|
3782
|
+
if (!validWeight(item.weight))
|
|
3783
|
+
throw invalidArgument(
|
|
3784
|
+
`entity_stances[${index}].weight must be a fraction in (0, 1] with at most four decimals`
|
|
3785
|
+
);
|
|
3786
|
+
if (stance.stance !== "bullish" && stance.stance !== "bearish")
|
|
3787
|
+
throw invalidArgument(
|
|
3788
|
+
`entity_stances[${index}].weight needs a bullish or bearish stance`
|
|
3789
|
+
);
|
|
3790
|
+
stance.weight = item.weight;
|
|
3791
|
+
}
|
|
3792
|
+
return stance;
|
|
3678
3793
|
});
|
|
3679
3794
|
}
|
|
3795
|
+
function validWeight(value) {
|
|
3796
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return false;
|
|
3797
|
+
const bps = Math.round(value * 1e4);
|
|
3798
|
+
return bps >= 1 && bps <= 1e4 && Math.abs(value * 1e4 - bps) <= 1e-6;
|
|
3799
|
+
}
|
|
3800
|
+
function requireKeptWeights(sent, returned) {
|
|
3801
|
+
if (!Array.isArray(sent)) return;
|
|
3802
|
+
const weights = /* @__PURE__ */ new Map();
|
|
3803
|
+
for (const item of returned ?? []) {
|
|
3804
|
+
if (item.weight !== void 0) weights.set(item.entity_id, item.weight);
|
|
3805
|
+
}
|
|
3806
|
+
for (const item of sent) {
|
|
3807
|
+
if (item.weight === void 0) continue;
|
|
3808
|
+
const kept = weights.get(item.entity_id);
|
|
3809
|
+
if (kept === void 0 || Math.abs(kept - item.weight) > 1e-9)
|
|
3810
|
+
throw invalidResponse3(
|
|
3811
|
+
"the Update was published without the weights sent: the server predates weights"
|
|
3812
|
+
);
|
|
3813
|
+
}
|
|
3814
|
+
}
|
|
3680
3815
|
function updateBody(params) {
|
|
3681
3816
|
const body = {
|
|
3682
3817
|
request_id: requireRequestID(params.request_id),
|
|
@@ -3784,6 +3919,13 @@ function thesisResponse(response) {
|
|
|
3784
3919
|
);
|
|
3785
3920
|
stance.direction = item.direction;
|
|
3786
3921
|
}
|
|
3922
|
+
if (item.weight !== void 0) {
|
|
3923
|
+
if (!validWeight(item.weight))
|
|
3924
|
+
throw invalidResponse3(
|
|
3925
|
+
"thesis.entity_stances contains invalid weight"
|
|
3926
|
+
);
|
|
3927
|
+
stance.weight = item.weight;
|
|
3928
|
+
}
|
|
3787
3929
|
return stance;
|
|
3788
3930
|
});
|
|
3789
3931
|
}
|
|
@@ -4648,13 +4790,12 @@ function followingThesesPage(value) {
|
|
|
4648
4790
|
}
|
|
4649
4791
|
function followingThesisAuthor(value) {
|
|
4650
4792
|
if (value === null) return null;
|
|
4651
|
-
if (!record3(value) || value.kind !== "user"
|
|
4793
|
+
if (!record3(value) || value.kind !== "user" || typeof value.username !== "string" || typeof value.display_name !== "string") {
|
|
4652
4794
|
throw invalidFollowingTheses("invalid following theses author");
|
|
4653
4795
|
}
|
|
4654
4796
|
return {
|
|
4655
4797
|
kind: value.kind,
|
|
4656
|
-
|
|
4657
|
-
...value.slug === void 0 ? {} : { slug: value.slug },
|
|
4798
|
+
username: value.username,
|
|
4658
4799
|
display_name: value.display_name
|
|
4659
4800
|
};
|
|
4660
4801
|
}
|
|
@@ -7330,7 +7471,7 @@ var installPlaybookRuntime = (targetWindow) => {
|
|
|
7330
7471
|
};
|
|
7331
7472
|
|
|
7332
7473
|
// src/index.ts
|
|
7333
|
-
var VERSION = true ? "0.38.0-beta.
|
|
7474
|
+
var VERSION = true ? "0.38.0-beta.1" : "dev";
|
|
7334
7475
|
// Annotate the CommonJS export names for ESM import in node:
|
|
7335
7476
|
0 && (module.exports = {
|
|
7336
7477
|
AlertsResource,
|