@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.d.cts
CHANGED
|
@@ -2106,6 +2106,25 @@ interface ThesisPositionReturn {
|
|
|
2106
2106
|
end: 'PENDING' | 'NEXT_UPDATE' | 'LATEST';
|
|
2107
2107
|
positionReturn: number;
|
|
2108
2108
|
currency: string;
|
|
2109
|
+
/** The Update's target share of this position; equal shares when it states none. */
|
|
2110
|
+
weight: number;
|
|
2111
|
+
}
|
|
2112
|
+
/** One long or short of a target portfolio. */
|
|
2113
|
+
interface ThesisHolding {
|
|
2114
|
+
entityId: string;
|
|
2115
|
+
symbol: string;
|
|
2116
|
+
direction: 'BULLISH' | 'BEARISH';
|
|
2117
|
+
/** Target share as a fraction; equal shares when the Update states none. */
|
|
2118
|
+
weight: number;
|
|
2119
|
+
}
|
|
2120
|
+
/**
|
|
2121
|
+
* The current target portfolio: the shares the latest Update set, not drifted
|
|
2122
|
+
* with prices. Holdings and cash sum to 1; cash is 1 with no direction or
|
|
2123
|
+
* while archived.
|
|
2124
|
+
*/
|
|
2125
|
+
interface ThesisAllocation {
|
|
2126
|
+
holdings: ThesisHolding[];
|
|
2127
|
+
cash: number;
|
|
2109
2128
|
}
|
|
2110
2129
|
/** One Update on the return chart. */
|
|
2111
2130
|
interface ThesisUpdateReturn {
|
|
@@ -2124,6 +2143,8 @@ interface ThesisReturnValue {
|
|
|
2124
2143
|
stale: boolean;
|
|
2125
2144
|
computedAtMs: number;
|
|
2126
2145
|
updates: ThesisUpdateReturn[];
|
|
2146
|
+
/** The current target portfolio, with detail; null on card reads. */
|
|
2147
|
+
allocation: ThesisAllocation | null;
|
|
2127
2148
|
}
|
|
2128
2149
|
interface ThesisReturnResult {
|
|
2129
2150
|
playbookId: string;
|
|
@@ -2159,6 +2180,14 @@ interface ThesisEntityStance {
|
|
|
2159
2180
|
stance: ThesisAssetStance;
|
|
2160
2181
|
/** Full direction in responses; stance reports none as unknown there. */
|
|
2161
2182
|
direction?: ThesisAssetStance;
|
|
2183
|
+
/**
|
|
2184
|
+
* The Update's share of this long or short as a fraction (0.4 is 40%), with
|
|
2185
|
+
* at most four decimals. On create and update give one to every bullish or
|
|
2186
|
+
* bearish entity, and the rest is cash, or to none, and the shares follow
|
|
2187
|
+
* the default rules and what the body says. Responses carry it only on an
|
|
2188
|
+
* Update published with weights.
|
|
2189
|
+
*/
|
|
2190
|
+
weight?: number;
|
|
2162
2191
|
}
|
|
2163
2192
|
/** GraphQL direction, including NONE. */
|
|
2164
2193
|
type ThesisDirection = 'UNKNOWN' | 'BULLISH' | 'BEARISH' | 'NONE';
|
|
@@ -2312,6 +2341,25 @@ interface CreateThesisParams {
|
|
|
2312
2341
|
visibility?: 'public' | 'private';
|
|
2313
2342
|
/** Thesis return switch; omitted keeps the default (on). */
|
|
2314
2343
|
track_return?: boolean;
|
|
2344
|
+
/** Which Signals the Thesis shows; omitted shows every Signal. */
|
|
2345
|
+
signal_preferences?: ThesisSignalPreferences;
|
|
2346
|
+
}
|
|
2347
|
+
/** What a Thesis Signal is about. */
|
|
2348
|
+
type ThesisSignalKind = 'fundamentals' | 'macro' | 'technicals' | 'commentary';
|
|
2349
|
+
/** The least important Signals a Thesis shows; notable means notable and major. */
|
|
2350
|
+
type ThesisSignalMinImportance = 'all' | 'notable' | 'major';
|
|
2351
|
+
/**
|
|
2352
|
+
* Which Signals a Thesis shows to every reader, chosen by its author. Signals
|
|
2353
|
+
* without a label always show.
|
|
2354
|
+
*/
|
|
2355
|
+
interface ThesisSignalPreferences {
|
|
2356
|
+
kinds: ThesisSignalKind[];
|
|
2357
|
+
min_importance: ThesisSignalMinImportance;
|
|
2358
|
+
}
|
|
2359
|
+
interface ThesisSignalPreferencesResponse {
|
|
2360
|
+
/** The Thesis read or written; null for the caller's last choice. */
|
|
2361
|
+
thesis_id: ThesisID | null;
|
|
2362
|
+
preferences: ThesisSignalPreferences;
|
|
2315
2363
|
}
|
|
2316
2364
|
interface UpdateThesisParams {
|
|
2317
2365
|
/** Full media replacement; pass current medias for a text-only update. */
|
|
@@ -2399,6 +2447,17 @@ declare class ThesesResource {
|
|
|
2399
2447
|
*/
|
|
2400
2448
|
setArchived(id: ThesisID, params: SetThesisArchivedParams): Promise<ThesisResponse>;
|
|
2401
2449
|
setStarred(id: ThesisID, isStarred: boolean): Promise<ThesisStarredResponse>;
|
|
2450
|
+
/**
|
|
2451
|
+
* Reads which Signals one of the caller's Theses shows: its setting, or every
|
|
2452
|
+
* kind and `all` when it has none. Without an id, reads the setting the caller
|
|
2453
|
+
* last saved, which prefills a new Thesis. Only the Thesis's author can read it.
|
|
2454
|
+
*/
|
|
2455
|
+
getSignalPreferences(id?: ThesisID): Promise<ThesisSignalPreferencesResponse>;
|
|
2456
|
+
/**
|
|
2457
|
+
* Replaces which Signals one of the caller's Theses shows, for every reader,
|
|
2458
|
+
* and records it as the caller's last choice. Author only.
|
|
2459
|
+
*/
|
|
2460
|
+
setSignalPreferences(id: ThesisID, preferences: ThesisSignalPreferences): Promise<ThesisSignalPreferencesResponse>;
|
|
2402
2461
|
setSignalEnabled(id: ThesisID, enabled: boolean): Promise<ThesisSignalEnabledResponse>;
|
|
2403
2462
|
setVisibility(id: ThesisID, params: SetThesisVisibilityParams): Promise<ThesisResponse>;
|
|
2404
2463
|
rewrite(params: RewriteThesisParams): Promise<RewriteThesisResponse>;
|
|
@@ -2512,12 +2571,10 @@ interface FollowingThesesParams {
|
|
|
2512
2571
|
first?: number;
|
|
2513
2572
|
}
|
|
2514
2573
|
/** The author of a Thesis in the following feed. */
|
|
2574
|
+
/** The followed user who wrote a Thesis Update. Persons cannot be followed. */
|
|
2515
2575
|
interface FollowingThesisAuthor {
|
|
2516
|
-
kind: 'user'
|
|
2517
|
-
|
|
2518
|
-
username?: string;
|
|
2519
|
-
/** Set for a person. */
|
|
2520
|
-
slug?: string;
|
|
2576
|
+
kind: 'user';
|
|
2577
|
+
username: string;
|
|
2521
2578
|
display_name: string;
|
|
2522
2579
|
}
|
|
2523
2580
|
interface FollowingThesisItem {
|
package/dist/index.d.ts
CHANGED
|
@@ -2106,6 +2106,25 @@ interface ThesisPositionReturn {
|
|
|
2106
2106
|
end: 'PENDING' | 'NEXT_UPDATE' | 'LATEST';
|
|
2107
2107
|
positionReturn: number;
|
|
2108
2108
|
currency: string;
|
|
2109
|
+
/** The Update's target share of this position; equal shares when it states none. */
|
|
2110
|
+
weight: number;
|
|
2111
|
+
}
|
|
2112
|
+
/** One long or short of a target portfolio. */
|
|
2113
|
+
interface ThesisHolding {
|
|
2114
|
+
entityId: string;
|
|
2115
|
+
symbol: string;
|
|
2116
|
+
direction: 'BULLISH' | 'BEARISH';
|
|
2117
|
+
/** Target share as a fraction; equal shares when the Update states none. */
|
|
2118
|
+
weight: number;
|
|
2119
|
+
}
|
|
2120
|
+
/**
|
|
2121
|
+
* The current target portfolio: the shares the latest Update set, not drifted
|
|
2122
|
+
* with prices. Holdings and cash sum to 1; cash is 1 with no direction or
|
|
2123
|
+
* while archived.
|
|
2124
|
+
*/
|
|
2125
|
+
interface ThesisAllocation {
|
|
2126
|
+
holdings: ThesisHolding[];
|
|
2127
|
+
cash: number;
|
|
2109
2128
|
}
|
|
2110
2129
|
/** One Update on the return chart. */
|
|
2111
2130
|
interface ThesisUpdateReturn {
|
|
@@ -2124,6 +2143,8 @@ interface ThesisReturnValue {
|
|
|
2124
2143
|
stale: boolean;
|
|
2125
2144
|
computedAtMs: number;
|
|
2126
2145
|
updates: ThesisUpdateReturn[];
|
|
2146
|
+
/** The current target portfolio, with detail; null on card reads. */
|
|
2147
|
+
allocation: ThesisAllocation | null;
|
|
2127
2148
|
}
|
|
2128
2149
|
interface ThesisReturnResult {
|
|
2129
2150
|
playbookId: string;
|
|
@@ -2159,6 +2180,14 @@ interface ThesisEntityStance {
|
|
|
2159
2180
|
stance: ThesisAssetStance;
|
|
2160
2181
|
/** Full direction in responses; stance reports none as unknown there. */
|
|
2161
2182
|
direction?: ThesisAssetStance;
|
|
2183
|
+
/**
|
|
2184
|
+
* The Update's share of this long or short as a fraction (0.4 is 40%), with
|
|
2185
|
+
* at most four decimals. On create and update give one to every bullish or
|
|
2186
|
+
* bearish entity, and the rest is cash, or to none, and the shares follow
|
|
2187
|
+
* the default rules and what the body says. Responses carry it only on an
|
|
2188
|
+
* Update published with weights.
|
|
2189
|
+
*/
|
|
2190
|
+
weight?: number;
|
|
2162
2191
|
}
|
|
2163
2192
|
/** GraphQL direction, including NONE. */
|
|
2164
2193
|
type ThesisDirection = 'UNKNOWN' | 'BULLISH' | 'BEARISH' | 'NONE';
|
|
@@ -2312,6 +2341,25 @@ interface CreateThesisParams {
|
|
|
2312
2341
|
visibility?: 'public' | 'private';
|
|
2313
2342
|
/** Thesis return switch; omitted keeps the default (on). */
|
|
2314
2343
|
track_return?: boolean;
|
|
2344
|
+
/** Which Signals the Thesis shows; omitted shows every Signal. */
|
|
2345
|
+
signal_preferences?: ThesisSignalPreferences;
|
|
2346
|
+
}
|
|
2347
|
+
/** What a Thesis Signal is about. */
|
|
2348
|
+
type ThesisSignalKind = 'fundamentals' | 'macro' | 'technicals' | 'commentary';
|
|
2349
|
+
/** The least important Signals a Thesis shows; notable means notable and major. */
|
|
2350
|
+
type ThesisSignalMinImportance = 'all' | 'notable' | 'major';
|
|
2351
|
+
/**
|
|
2352
|
+
* Which Signals a Thesis shows to every reader, chosen by its author. Signals
|
|
2353
|
+
* without a label always show.
|
|
2354
|
+
*/
|
|
2355
|
+
interface ThesisSignalPreferences {
|
|
2356
|
+
kinds: ThesisSignalKind[];
|
|
2357
|
+
min_importance: ThesisSignalMinImportance;
|
|
2358
|
+
}
|
|
2359
|
+
interface ThesisSignalPreferencesResponse {
|
|
2360
|
+
/** The Thesis read or written; null for the caller's last choice. */
|
|
2361
|
+
thesis_id: ThesisID | null;
|
|
2362
|
+
preferences: ThesisSignalPreferences;
|
|
2315
2363
|
}
|
|
2316
2364
|
interface UpdateThesisParams {
|
|
2317
2365
|
/** Full media replacement; pass current medias for a text-only update. */
|
|
@@ -2399,6 +2447,17 @@ declare class ThesesResource {
|
|
|
2399
2447
|
*/
|
|
2400
2448
|
setArchived(id: ThesisID, params: SetThesisArchivedParams): Promise<ThesisResponse>;
|
|
2401
2449
|
setStarred(id: ThesisID, isStarred: boolean): Promise<ThesisStarredResponse>;
|
|
2450
|
+
/**
|
|
2451
|
+
* Reads which Signals one of the caller's Theses shows: its setting, or every
|
|
2452
|
+
* kind and `all` when it has none. Without an id, reads the setting the caller
|
|
2453
|
+
* last saved, which prefills a new Thesis. Only the Thesis's author can read it.
|
|
2454
|
+
*/
|
|
2455
|
+
getSignalPreferences(id?: ThesisID): Promise<ThesisSignalPreferencesResponse>;
|
|
2456
|
+
/**
|
|
2457
|
+
* Replaces which Signals one of the caller's Theses shows, for every reader,
|
|
2458
|
+
* and records it as the caller's last choice. Author only.
|
|
2459
|
+
*/
|
|
2460
|
+
setSignalPreferences(id: ThesisID, preferences: ThesisSignalPreferences): Promise<ThesisSignalPreferencesResponse>;
|
|
2402
2461
|
setSignalEnabled(id: ThesisID, enabled: boolean): Promise<ThesisSignalEnabledResponse>;
|
|
2403
2462
|
setVisibility(id: ThesisID, params: SetThesisVisibilityParams): Promise<ThesisResponse>;
|
|
2404
2463
|
rewrite(params: RewriteThesisParams): Promise<RewriteThesisResponse>;
|
|
@@ -2512,12 +2571,10 @@ interface FollowingThesesParams {
|
|
|
2512
2571
|
first?: number;
|
|
2513
2572
|
}
|
|
2514
2573
|
/** The author of a Thesis in the following feed. */
|
|
2574
|
+
/** The followed user who wrote a Thesis Update. Persons cannot be followed. */
|
|
2515
2575
|
interface FollowingThesisAuthor {
|
|
2516
|
-
kind: 'user'
|
|
2517
|
-
|
|
2518
|
-
username?: string;
|
|
2519
|
-
/** Set for a person. */
|
|
2520
|
-
slug?: string;
|
|
2576
|
+
kind: 'user';
|
|
2577
|
+
username: string;
|
|
2521
2578
|
display_name: string;
|
|
2522
2579
|
}
|
|
2523
2580
|
interface FollowingThesisItem {
|
package/dist/index.js
CHANGED
|
@@ -3015,7 +3015,8 @@ var RETURN_QUERY = `query ToolkitThesisReturn($id: ID!, $detail: Boolean!) {
|
|
|
3015
3015
|
thesisReturn(detail: $detail) {
|
|
3016
3016
|
live value firstFillAtMs pricedAtMs stale computedAtMs
|
|
3017
3017
|
updates { authorVersionId publishedAtMs startValue updateReturn
|
|
3018
|
-
positions { entityId symbol direction startPrice startAtMs endPrice endAtMs end positionReturn currency } }
|
|
3018
|
+
positions { entityId symbol direction startPrice startAtMs endPrice endAtMs end positionReturn currency weight } }
|
|
3019
|
+
allocation { holdings { entityId symbol direction weight } cash }
|
|
3019
3020
|
}
|
|
3020
3021
|
} } } }
|
|
3021
3022
|
}`;
|
|
@@ -3084,16 +3085,21 @@ async function thesisWatchpoints(client, id) {
|
|
|
3084
3085
|
return { playbookId: id, watchpoints };
|
|
3085
3086
|
}
|
|
3086
3087
|
function validThesisReturn(value) {
|
|
3087
|
-
if (!record2(value) || typeof value.live !== "boolean" || typeof value.value !== "number" || typeof value.stale !== "boolean" || typeof value.computedAtMs !== "number" || !Array.isArray(value.updates))
|
|
3088
|
+
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))
|
|
3088
3089
|
return false;
|
|
3089
3090
|
return value.updates.every(
|
|
3090
3091
|
(update) => record2(update) && nonempty(update.authorVersionId) && typeof update.publishedAtMs === "number" && typeof update.startValue === "number" && Array.isArray(update.positions) && update.positions.every(
|
|
3091
3092
|
(position) => record2(position) && nonempty(position.symbol) && ["BULLISH", "BEARISH"].includes(position.direction) && ["PENDING", "NEXT_UPDATE", "LATEST"].includes(
|
|
3092
3093
|
position.end
|
|
3093
|
-
) && typeof position.positionReturn === "number"
|
|
3094
|
+
) && typeof position.positionReturn === "number" && typeof position.weight === "number"
|
|
3094
3095
|
)
|
|
3095
3096
|
);
|
|
3096
3097
|
}
|
|
3098
|
+
function validAllocation(value) {
|
|
3099
|
+
return record2(value) && typeof value.cash === "number" && Array.isArray(value.holdings) && value.holdings.every(
|
|
3100
|
+
(holding) => record2(holding) && nonempty(holding.entityId) && nonempty(holding.symbol) && ["BULLISH", "BEARISH"].includes(holding.direction) && typeof holding.weight === "number"
|
|
3101
|
+
);
|
|
3102
|
+
}
|
|
3097
3103
|
async function graphql(client, document, variables) {
|
|
3098
3104
|
const response = await client._request("POST", "/query", {
|
|
3099
3105
|
body: { query: document, variables }
|
|
@@ -3150,6 +3156,13 @@ function notFound() {
|
|
|
3150
3156
|
}
|
|
3151
3157
|
|
|
3152
3158
|
// src/resources/theses.ts
|
|
3159
|
+
var THESIS_SIGNAL_KINDS = [
|
|
3160
|
+
"fundamentals",
|
|
3161
|
+
"macro",
|
|
3162
|
+
"technicals",
|
|
3163
|
+
"commentary"
|
|
3164
|
+
];
|
|
3165
|
+
var THESIS_SIGNAL_MIN_IMPORTANCES = ["all", "notable", "major"];
|
|
3153
3166
|
var SET_THESIS_STARRED = `mutation SetThesisStarred($input: SetThesisStarredInput!) {
|
|
3154
3167
|
setThesisStarred(input: $input) {
|
|
3155
3168
|
thesisId
|
|
@@ -3255,9 +3268,11 @@ var ThesesResource = class {
|
|
|
3255
3268
|
async create(params) {
|
|
3256
3269
|
this.client._requireAuth();
|
|
3257
3270
|
const body = createBody(params);
|
|
3258
|
-
|
|
3271
|
+
const response = thesisResponse(
|
|
3259
3272
|
await this.client._request("POST", "/api/v1/theses", { body })
|
|
3260
3273
|
);
|
|
3274
|
+
requireKeptWeights(body.entity_stances, response.thesis.entity_stances);
|
|
3275
|
+
return response;
|
|
3261
3276
|
}
|
|
3262
3277
|
async get(id) {
|
|
3263
3278
|
this.client._requireAuth();
|
|
@@ -3346,6 +3361,7 @@ var ThesesResource = class {
|
|
|
3346
3361
|
if (response.thesis.id !== thesisID) {
|
|
3347
3362
|
throw invalidResponse3("update response must match the requested thesis");
|
|
3348
3363
|
}
|
|
3364
|
+
requireKeptWeights(body.entity_stances, response.thesis.entity_stances);
|
|
3349
3365
|
return response;
|
|
3350
3366
|
}
|
|
3351
3367
|
/**
|
|
@@ -3380,7 +3396,11 @@ var ThesesResource = class {
|
|
|
3380
3396
|
body: current.thesis.body,
|
|
3381
3397
|
title: current.thesis.title,
|
|
3382
3398
|
entity_ids: current.thesis.entity_ids,
|
|
3383
|
-
|
|
3399
|
+
// Directions only: archiving keeps the current Update and unarchiving
|
|
3400
|
+
// keeps its shares without restating them.
|
|
3401
|
+
entity_stances: current.thesis.entity_stances?.map(
|
|
3402
|
+
({ entity_id, stance }) => ({ entity_id, stance })
|
|
3403
|
+
),
|
|
3384
3404
|
visibility: current.thesis.visibility,
|
|
3385
3405
|
archived: params.archived,
|
|
3386
3406
|
medias: current.thesis.medias,
|
|
@@ -3427,6 +3447,45 @@ var ThesesResource = class {
|
|
|
3427
3447
|
is_starred: returnedStarred
|
|
3428
3448
|
};
|
|
3429
3449
|
}
|
|
3450
|
+
/**
|
|
3451
|
+
* Reads which Signals one of the caller's Theses shows: its setting, or every
|
|
3452
|
+
* kind and `all` when it has none. Without an id, reads the setting the caller
|
|
3453
|
+
* last saved, which prefills a new Thesis. Only the Thesis's author can read it.
|
|
3454
|
+
*/
|
|
3455
|
+
async getSignalPreferences(id) {
|
|
3456
|
+
this.client._requireAuth();
|
|
3457
|
+
if (id === void 0) {
|
|
3458
|
+
return signalPreferencesResponse(
|
|
3459
|
+
await this.client._request("GET", "/api/v1/theses/signal-preferences"),
|
|
3460
|
+
null
|
|
3461
|
+
);
|
|
3462
|
+
}
|
|
3463
|
+
const thesisID = requireID(id, "id");
|
|
3464
|
+
return signalPreferencesResponse(
|
|
3465
|
+
await this.client._request(
|
|
3466
|
+
"GET",
|
|
3467
|
+
`/api/v1/theses/${thesisID}/signal-preferences`
|
|
3468
|
+
),
|
|
3469
|
+
thesisID
|
|
3470
|
+
);
|
|
3471
|
+
}
|
|
3472
|
+
/**
|
|
3473
|
+
* Replaces which Signals one of the caller's Theses shows, for every reader,
|
|
3474
|
+
* and records it as the caller's last choice. Author only.
|
|
3475
|
+
*/
|
|
3476
|
+
async setSignalPreferences(id, preferences) {
|
|
3477
|
+
this.client._requireAuth();
|
|
3478
|
+
const thesisID = requireID(id, "id");
|
|
3479
|
+
const input = requireSignalPreferences(preferences);
|
|
3480
|
+
return signalPreferencesResponse(
|
|
3481
|
+
await this.client._request(
|
|
3482
|
+
"PUT",
|
|
3483
|
+
`/api/v1/theses/${thesisID}/signal-preferences`,
|
|
3484
|
+
{ body: { signal_preferences: input } }
|
|
3485
|
+
),
|
|
3486
|
+
thesisID
|
|
3487
|
+
);
|
|
3488
|
+
}
|
|
3430
3489
|
async setSignalEnabled(id, enabled) {
|
|
3431
3490
|
this.client._requireAuth();
|
|
3432
3491
|
const thesisID = requireID(id, "id");
|
|
@@ -3533,6 +3592,10 @@ function createBody(params) {
|
|
|
3533
3592
|
body.tickers = requireTickers(params.tickers);
|
|
3534
3593
|
if (params.track_return !== void 0)
|
|
3535
3594
|
body.track_return = requireTrackReturn(params.track_return);
|
|
3595
|
+
if (params.signal_preferences !== void 0)
|
|
3596
|
+
body.signal_preferences = requireSignalPreferences(
|
|
3597
|
+
params.signal_preferences
|
|
3598
|
+
);
|
|
3536
3599
|
if (params.entity_stances !== void 0) {
|
|
3537
3600
|
body.entity_stances = requireEntityStances(
|
|
3538
3601
|
params.entity_stances,
|
|
@@ -3541,6 +3604,43 @@ function createBody(params) {
|
|
|
3541
3604
|
}
|
|
3542
3605
|
return body;
|
|
3543
3606
|
}
|
|
3607
|
+
function requireSignalPreferences(value) {
|
|
3608
|
+
if (!isRecord(value) || !Array.isArray(value.kinds))
|
|
3609
|
+
throw invalidArgument(
|
|
3610
|
+
"signal_preferences must have kinds and min_importance"
|
|
3611
|
+
);
|
|
3612
|
+
const kinds = [...new Set(value.kinds)];
|
|
3613
|
+
if (kinds.length === 0 || !kinds.every(
|
|
3614
|
+
(kind) => THESIS_SIGNAL_KINDS.includes(kind)
|
|
3615
|
+
))
|
|
3616
|
+
throw invalidArgument(
|
|
3617
|
+
`signal kinds must be one or more of ${THESIS_SIGNAL_KINDS.join(", ")}`
|
|
3618
|
+
);
|
|
3619
|
+
if (!THESIS_SIGNAL_MIN_IMPORTANCES.includes(
|
|
3620
|
+
value.min_importance
|
|
3621
|
+
))
|
|
3622
|
+
throw invalidArgument(
|
|
3623
|
+
`min_importance must be ${THESIS_SIGNAL_MIN_IMPORTANCES.join(", ")}`
|
|
3624
|
+
);
|
|
3625
|
+
return {
|
|
3626
|
+
kinds,
|
|
3627
|
+
min_importance: value.min_importance
|
|
3628
|
+
};
|
|
3629
|
+
}
|
|
3630
|
+
function signalPreferencesResponse(value, thesisID) {
|
|
3631
|
+
if (!isRecord(value) || value.thesis_id !== thesisID)
|
|
3632
|
+
throw invalidResponse3(
|
|
3633
|
+
"Signal setting response must name the requested thesis"
|
|
3634
|
+
);
|
|
3635
|
+
try {
|
|
3636
|
+
return {
|
|
3637
|
+
thesis_id: thesisID,
|
|
3638
|
+
preferences: requireSignalPreferences(value.signal_preferences)
|
|
3639
|
+
};
|
|
3640
|
+
} catch {
|
|
3641
|
+
throw invalidResponse3("response contains an unknown Signal setting");
|
|
3642
|
+
}
|
|
3643
|
+
}
|
|
3544
3644
|
var ENTITY_STANCES = [
|
|
3545
3645
|
"unknown",
|
|
3546
3646
|
"bullish",
|
|
@@ -3606,9 +3706,44 @@ function requireEntityStances(value, entityIDs) {
|
|
|
3606
3706
|
seen.add(entityID);
|
|
3607
3707
|
if (!ENTITY_STANCES.includes(item.stance))
|
|
3608
3708
|
throw invalidArgument(`entity_stances[${index}].stance is invalid`);
|
|
3609
|
-
|
|
3709
|
+
const stance = {
|
|
3710
|
+
entity_id: entityID,
|
|
3711
|
+
stance: item.stance
|
|
3712
|
+
};
|
|
3713
|
+
if (item.weight !== void 0) {
|
|
3714
|
+
if (!validWeight(item.weight))
|
|
3715
|
+
throw invalidArgument(
|
|
3716
|
+
`entity_stances[${index}].weight must be a fraction in (0, 1] with at most four decimals`
|
|
3717
|
+
);
|
|
3718
|
+
if (stance.stance !== "bullish" && stance.stance !== "bearish")
|
|
3719
|
+
throw invalidArgument(
|
|
3720
|
+
`entity_stances[${index}].weight needs a bullish or bearish stance`
|
|
3721
|
+
);
|
|
3722
|
+
stance.weight = item.weight;
|
|
3723
|
+
}
|
|
3724
|
+
return stance;
|
|
3610
3725
|
});
|
|
3611
3726
|
}
|
|
3727
|
+
function validWeight(value) {
|
|
3728
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return false;
|
|
3729
|
+
const bps = Math.round(value * 1e4);
|
|
3730
|
+
return bps >= 1 && bps <= 1e4 && Math.abs(value * 1e4 - bps) <= 1e-6;
|
|
3731
|
+
}
|
|
3732
|
+
function requireKeptWeights(sent, returned) {
|
|
3733
|
+
if (!Array.isArray(sent)) return;
|
|
3734
|
+
const weights = /* @__PURE__ */ new Map();
|
|
3735
|
+
for (const item of returned ?? []) {
|
|
3736
|
+
if (item.weight !== void 0) weights.set(item.entity_id, item.weight);
|
|
3737
|
+
}
|
|
3738
|
+
for (const item of sent) {
|
|
3739
|
+
if (item.weight === void 0) continue;
|
|
3740
|
+
const kept = weights.get(item.entity_id);
|
|
3741
|
+
if (kept === void 0 || Math.abs(kept - item.weight) > 1e-9)
|
|
3742
|
+
throw invalidResponse3(
|
|
3743
|
+
"the Update was published without the weights sent: the server predates weights"
|
|
3744
|
+
);
|
|
3745
|
+
}
|
|
3746
|
+
}
|
|
3612
3747
|
function updateBody(params) {
|
|
3613
3748
|
const body = {
|
|
3614
3749
|
request_id: requireRequestID(params.request_id),
|
|
@@ -3716,6 +3851,13 @@ function thesisResponse(response) {
|
|
|
3716
3851
|
);
|
|
3717
3852
|
stance.direction = item.direction;
|
|
3718
3853
|
}
|
|
3854
|
+
if (item.weight !== void 0) {
|
|
3855
|
+
if (!validWeight(item.weight))
|
|
3856
|
+
throw invalidResponse3(
|
|
3857
|
+
"thesis.entity_stances contains invalid weight"
|
|
3858
|
+
);
|
|
3859
|
+
stance.weight = item.weight;
|
|
3860
|
+
}
|
|
3719
3861
|
return stance;
|
|
3720
3862
|
});
|
|
3721
3863
|
}
|
|
@@ -4580,13 +4722,12 @@ function followingThesesPage(value) {
|
|
|
4580
4722
|
}
|
|
4581
4723
|
function followingThesisAuthor(value) {
|
|
4582
4724
|
if (value === null) return null;
|
|
4583
|
-
if (!record3(value) || value.kind !== "user"
|
|
4725
|
+
if (!record3(value) || value.kind !== "user" || typeof value.username !== "string" || typeof value.display_name !== "string") {
|
|
4584
4726
|
throw invalidFollowingTheses("invalid following theses author");
|
|
4585
4727
|
}
|
|
4586
4728
|
return {
|
|
4587
4729
|
kind: value.kind,
|
|
4588
|
-
|
|
4589
|
-
...value.slug === void 0 ? {} : { slug: value.slug },
|
|
4730
|
+
username: value.username,
|
|
4590
4731
|
display_name: value.display_name
|
|
4591
4732
|
};
|
|
4592
4733
|
}
|
|
@@ -7262,7 +7403,7 @@ var installPlaybookRuntime = (targetWindow) => {
|
|
|
7262
7403
|
};
|
|
7263
7404
|
|
|
7264
7405
|
// src/index.ts
|
|
7265
|
-
var VERSION = true ? "0.38.0-beta.
|
|
7406
|
+
var VERSION = true ? "0.38.0-beta.1" : "dev";
|
|
7266
7407
|
export {
|
|
7267
7408
|
AlertsResource,
|
|
7268
7409
|
AlvaClient,
|