@alva-ai/toolkit 0.34.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/dist/index.js CHANGED
@@ -2821,6 +2821,458 @@ var SubscriptionsResource = class {
2821
2821
  }
2822
2822
  };
2823
2823
 
2824
+ // src/resources/follows.ts
2825
+ var MAX_TICKERS = 50;
2826
+ var MAX_TICKER_LENGTH = 40;
2827
+ var MAX_WATCHLIST_FIRST = 100;
2828
+ var MAX_PROFILE_FIRST = 50;
2829
+ var MAX_PROFILE_QUERY_LENGTH = 200;
2830
+ var LOOKUP_CONCURRENCY = 5;
2831
+ var TICKER_KINDS = ["STOCK", "ETF", "CRYPTO"];
2832
+ var PROFILE_KINDS = ["USER", "PERSON"];
2833
+ var UNRESOLVED_LOOKUP_CODES = /* @__PURE__ */ new Set(["NOT_FOUND", "FAILED_PRECONDITION"]);
2834
+ var GRAPHQL_STATUS_BY_CODE2 = {
2835
+ INVALID_ARGUMENT: 400,
2836
+ UNAUTHENTICATED: 401,
2837
+ PERMISSION_DENIED: 403,
2838
+ NOT_FOUND: 404,
2839
+ ALREADY_EXISTS: 409,
2840
+ ABORTED: 409,
2841
+ FAILED_PRECONDITION: 412,
2842
+ RESOURCE_EXHAUSTED: 429,
2843
+ INTERNAL: 500,
2844
+ UNKNOWN: 500,
2845
+ DATA_LOSS: 500,
2846
+ UNAVAILABLE: 503,
2847
+ DEADLINE_EXCEEDED: 504
2848
+ };
2849
+ var TICKER_FIELDS = "id ticker name kind";
2850
+ var PROFILE_FIELDS = "__typename id displayName followersCount viewerState { following } ... on PublicUser { username } ... on Person { slug xHandle }";
2851
+ function record3(value) {
2852
+ return typeof value === "object" && value !== null && !Array.isArray(value);
2853
+ }
2854
+ function invalidResponse3(field) {
2855
+ throw new AlvaError(
2856
+ "GRAPHQL_INVALID_RESPONSE",
2857
+ `GraphQL returned an invalid ${field} response`,
2858
+ 502
2859
+ );
2860
+ }
2861
+ function graphQLFailure(response) {
2862
+ if (!record3(response) || response.errors === void 0) return void 0;
2863
+ if (!Array.isArray(response.errors)) return invalidResponse3("GraphQL");
2864
+ if (response.errors.length === 0) return void 0;
2865
+ const errors = response.errors;
2866
+ const messages = errors.flatMap(
2867
+ (error) => record3(error) && typeof error.message === "string" ? [error.message] : []
2868
+ );
2869
+ const codes = errors.map(
2870
+ (error) => record3(error) && record3(error.extensions) ? error.extensions.code : void 0
2871
+ );
2872
+ const code = typeof codes[0] === "string" && Object.hasOwn(GRAPHQL_STATUS_BY_CODE2, codes[0]) && codes.every((value) => value === codes[0]) ? codes[0] : "GRAPHQL_ERROR";
2873
+ return { code, message: messages.join("; ") || "Request failed", errors };
2874
+ }
2875
+ function throwFailure(failure) {
2876
+ throw new AlvaError(
2877
+ failure.code,
2878
+ failure.message,
2879
+ GRAPHQL_STATUS_BY_CODE2[failure.code] ?? 502,
2880
+ { errors: failure.errors }
2881
+ );
2882
+ }
2883
+ function responseData(response, field) {
2884
+ const failure = graphQLFailure(response);
2885
+ if (failure) throwFailure(failure);
2886
+ if (!record3(response) || !record3(response.data))
2887
+ return invalidResponse3(field);
2888
+ return response.data;
2889
+ }
2890
+ function viewerField2(response, field) {
2891
+ const data = responseData(response, field);
2892
+ if (!record3(data.viewer)) return invalidResponse3(field);
2893
+ return data.viewer[field];
2894
+ }
2895
+ function requireString(value, field) {
2896
+ if (typeof value !== "string" || !value) return invalidResponse3(field);
2897
+ return value;
2898
+ }
2899
+ function pageInfo(value, field) {
2900
+ if (!record3(value) || typeof value.hasNextPage !== "boolean" || value.endCursor !== null && value.endCursor !== void 0 && typeof value.endCursor !== "string" || value.hasNextPage && !value.endCursor) {
2901
+ return invalidResponse3(field);
2902
+ }
2903
+ return {
2904
+ endCursor: typeof value.endCursor === "string" ? value.endCursor : "",
2905
+ hasNextPage: value.hasNextPage
2906
+ };
2907
+ }
2908
+ function normalizeProfile(value, field) {
2909
+ if (!record3(value) || !record3(value.viewerState))
2910
+ return invalidResponse3(field);
2911
+ const following = value.viewerState.following;
2912
+ if (typeof value.followersCount !== "number" || typeof value.displayName !== "string" || following !== null && typeof following !== "boolean") {
2913
+ return invalidResponse3(field);
2914
+ }
2915
+ const base = {
2916
+ id: requireString(value.id, field),
2917
+ displayName: value.displayName,
2918
+ followersCount: value.followersCount,
2919
+ following: following ?? null
2920
+ };
2921
+ if (value.__typename === "PublicUser") {
2922
+ return {
2923
+ kind: "USER",
2924
+ ...base,
2925
+ username: requireString(value.username, field)
2926
+ };
2927
+ }
2928
+ if (value.__typename === "Person") {
2929
+ if (value.xHandle !== null && value.xHandle !== void 0 && typeof value.xHandle !== "string") {
2930
+ return invalidResponse3(field);
2931
+ }
2932
+ return {
2933
+ kind: "PERSON",
2934
+ ...base,
2935
+ slug: requireString(value.slug, field),
2936
+ xHandle: value.xHandle ?? null
2937
+ };
2938
+ }
2939
+ return invalidResponse3(field);
2940
+ }
2941
+ function boundedFirst(value, max, name = "first") {
2942
+ if (value === void 0) return void 0;
2943
+ if (!Number.isInteger(value) || value < 1 || value > max) {
2944
+ throw new Error(`${name} must be an integer between 1 and ${max}`);
2945
+ }
2946
+ return value;
2947
+ }
2948
+ function optionalCursor(value) {
2949
+ if (value === void 0) return void 0;
2950
+ if (typeof value !== "string" || !value.trim() || value.length > 4096) {
2951
+ throw new Error(
2952
+ "after must be a non-empty cursor of at most 4096 characters"
2953
+ );
2954
+ }
2955
+ return value;
2956
+ }
2957
+ function profileKind(value, required) {
2958
+ if (value === void 0 && !required) return void 0;
2959
+ if (typeof value !== "string" || !PROFILE_KINDS.includes(value)) {
2960
+ throw new Error("kind must be USER or PERSON");
2961
+ }
2962
+ return value;
2963
+ }
2964
+ function tickerKind(value) {
2965
+ if (value === void 0) return void 0;
2966
+ if (typeof value !== "string" || !TICKER_KINDS.includes(value)) {
2967
+ throw new Error("kind must be STOCK, ETF, or CRYPTO");
2968
+ }
2969
+ return value;
2970
+ }
2971
+ function normalizeWatchlistTickersParams(params) {
2972
+ if (!record3(params) || !Array.isArray(params.tickers)) {
2973
+ throw new Error("tickers must be a list of ticker symbols");
2974
+ }
2975
+ const defaultKind = tickerKind(params.kind);
2976
+ const tickers = [];
2977
+ for (const raw of params.tickers) {
2978
+ const spec = typeof raw === "string" ? { ticker: raw } : raw;
2979
+ if (!record3(spec) || typeof spec.ticker !== "string") {
2980
+ throw new Error("tickers must be symbols or {ticker, kind} specs");
2981
+ }
2982
+ const ticker = spec.ticker.trim().toUpperCase();
2983
+ if (!ticker || /\s/.test(ticker) || ticker.length > MAX_TICKER_LENGTH) {
2984
+ throw new Error(
2985
+ `ticker '${spec.ticker}' must be a non-empty symbol of at most ${MAX_TICKER_LENGTH} characters`
2986
+ );
2987
+ }
2988
+ const kind = tickerKind(spec.kind) ?? defaultKind;
2989
+ if (!tickers.some((t) => t.ticker === ticker && t.kind === kind)) {
2990
+ tickers.push(kind === void 0 ? { ticker } : { ticker, kind });
2991
+ }
2992
+ }
2993
+ if (tickers.length === 0 || tickers.length > MAX_TICKERS) {
2994
+ throw new Error(
2995
+ `tickers must contain between 1 and ${MAX_TICKERS} symbols`
2996
+ );
2997
+ }
2998
+ return { tickers };
2999
+ }
3000
+ function validateProfileRef(params) {
3001
+ if (!record3(params)) throw new Error("profile reference must be an object");
3002
+ const kind = profileKind(params.kind, true);
3003
+ if (typeof params.id !== "string" || !/^[1-9]\d{0,18}$/.test(params.id)) {
3004
+ throw new Error("id must be a positive decimal profile id");
3005
+ }
3006
+ return { kind, id: params.id };
3007
+ }
3008
+ function validateSearchProfilesParams(params) {
3009
+ if (!record3(params) || typeof params.query !== "string") {
3010
+ throw new Error("query is required");
3011
+ }
3012
+ const query = params.query.trim();
3013
+ if (!query || query.length > MAX_PROFILE_QUERY_LENGTH) {
3014
+ throw new Error(
3015
+ `query must be non-empty and at most ${MAX_PROFILE_QUERY_LENGTH} characters`
3016
+ );
3017
+ }
3018
+ return {
3019
+ query,
3020
+ kind: profileKind(params.kind, false),
3021
+ first: boundedFirst(params.first, MAX_PROFILE_FIRST)
3022
+ };
3023
+ }
3024
+ function unresolvedTicker(input, kind, code, message) {
3025
+ if (kind === void 0) {
3026
+ return { ok: false, unresolved: { input, code, message } };
3027
+ }
3028
+ return {
3029
+ ok: false,
3030
+ unresolved: {
3031
+ input,
3032
+ kind,
3033
+ code,
3034
+ message: code === "NOT_FOUND" ? `no ${kind} entity found for ticker ${input}; it may exist as another kind (retry with a different :kind suffix or none)` : message
3035
+ }
3036
+ };
3037
+ }
3038
+ var FollowsResource = class {
3039
+ constructor(client) {
3040
+ this.client = client;
3041
+ }
3042
+ client;
3043
+ /** Add tickers to the watchlist by exact symbol in one atomic batch. */
3044
+ async addToWatchlist(params) {
3045
+ const { changed, unchanged, unresolved } = await this.changeWatchlist(
3046
+ params,
3047
+ "add"
3048
+ );
3049
+ return { added: changed, unchanged, unresolved };
3050
+ }
3051
+ /** Remove tickers from the watchlist by exact symbol in one atomic batch. */
3052
+ async removeFromWatchlist(params) {
3053
+ const { changed, unchanged, unresolved } = await this.changeWatchlist(
3054
+ params,
3055
+ "remove"
3056
+ );
3057
+ return { removed: changed, unchanged, unresolved };
3058
+ }
3059
+ /** One page of the watchlist, most recently added first. */
3060
+ async watchlist(params = {}) {
3061
+ const first = boundedFirst(params.first, MAX_WATCHLIST_FIRST);
3062
+ const after = optionalCursor(params.after);
3063
+ this.client._requireAuth();
3064
+ const response = await this.client._request("POST", "/query", {
3065
+ body: {
3066
+ query: `query ToolkitWatchlist($input: MarketWatchlistConnectionInput) { viewer { marketWatchlist(input: $input) { totalCount edges { cursor followedAtMs node { ${TICKER_FIELDS} } } pageInfo { endCursor hasNextPage } } } }`,
3067
+ variables: { input: { first: first ?? 20, after } }
3068
+ }
3069
+ });
3070
+ const field = "viewer.marketWatchlist";
3071
+ const value = viewerField2(response, "marketWatchlist");
3072
+ if (!record3(value) || typeof value.totalCount !== "number" || !Array.isArray(value.edges)) {
3073
+ return invalidResponse3(field);
3074
+ }
3075
+ const tickers = value.edges.map((edge) => {
3076
+ if (!record3(edge) || !record3(edge.node) || typeof edge.followedAtMs !== "number") {
3077
+ return invalidResponse3(field);
3078
+ }
3079
+ return {
3080
+ entityId: requireString(edge.node.id, field),
3081
+ ticker: requireString(edge.node.ticker, field),
3082
+ name: typeof edge.node.name === "string" ? edge.node.name : "",
3083
+ kind: requireString(edge.node.kind, field),
3084
+ addedAtMs: edge.followedAtMs
3085
+ };
3086
+ });
3087
+ return {
3088
+ totalCount: value.totalCount,
3089
+ tickers,
3090
+ pageInfo: pageInfo(value.pageInfo, field)
3091
+ };
3092
+ }
3093
+ /** Search public profiles (Alva users and curated people). */
3094
+ async searchProfiles(params) {
3095
+ const { query, kind, first } = validateSearchProfilesParams(params);
3096
+ this.client._requireAuth();
3097
+ const response = await this.client._request("POST", "/query", {
3098
+ body: {
3099
+ query: `query ToolkitSearchProfiles($input: PublicProfileConnectionInput) { profiles(input: $input) { edges { node { ${PROFILE_FIELDS} } } pageInfo { endCursor hasNextPage } } }`,
3100
+ variables: { input: { query, kind, first: first ?? 10 } }
3101
+ }
3102
+ });
3103
+ return this.profilesPage(
3104
+ responseData(response, "profiles").profiles,
3105
+ "profiles"
3106
+ );
3107
+ }
3108
+ /** One page of profiles the caller follows. */
3109
+ async profiles(params = {}) {
3110
+ const kind = profileKind(params.kind, false);
3111
+ const first = boundedFirst(params.first, MAX_PROFILE_FIRST);
3112
+ const after = optionalCursor(params.after);
3113
+ this.client._requireAuth();
3114
+ const response = await this.client._request("POST", "/query", {
3115
+ body: {
3116
+ query: `query ToolkitFollowedProfiles($input: FollowingProfileConnectionInput) { viewer { followingProfiles(input: $input) { edges { node { ${PROFILE_FIELDS} } } pageInfo { endCursor hasNextPage } } } }`,
3117
+ variables: { input: { kind, first: first ?? 20, after } }
3118
+ }
3119
+ });
3120
+ return this.profilesPage(
3121
+ viewerField2(response, "followingProfiles"),
3122
+ "viewer.followingProfiles"
3123
+ );
3124
+ }
3125
+ /** Follow one profile. Idempotent. */
3126
+ async followProfile(params) {
3127
+ return this.changeProfile(params, "followProfile");
3128
+ }
3129
+ /** Unfollow one profile. Idempotent. */
3130
+ async unfollowProfile(params) {
3131
+ return this.changeProfile(params, "unfollowProfile");
3132
+ }
3133
+ profilesPage(value, field) {
3134
+ if (!record3(value) || !Array.isArray(value.edges)) {
3135
+ return invalidResponse3(field);
3136
+ }
3137
+ return {
3138
+ profiles: value.edges.map(
3139
+ (edge) => record3(edge) ? normalizeProfile(edge.node, field) : invalidResponse3(field)
3140
+ ),
3141
+ pageInfo: pageInfo(value.pageInfo, field)
3142
+ };
3143
+ }
3144
+ async changeProfile(params, mutation) {
3145
+ const input = validateProfileRef(params);
3146
+ this.client._requireAuth();
3147
+ const response = await this.client._request("POST", "/query", {
3148
+ body: {
3149
+ query: `mutation ToolkitChangeProfileFollow($input: PublicProfileRefInput!) { ${mutation}(input: $input) { following target { ${PROFILE_FIELDS} } } }`,
3150
+ variables: { input }
3151
+ }
3152
+ });
3153
+ const value = responseData(response, mutation)[mutation];
3154
+ if (!record3(value) || typeof value.following !== "boolean") {
3155
+ return invalidResponse3(mutation);
3156
+ }
3157
+ return {
3158
+ following: value.following,
3159
+ profile: value.target === null || value.target === void 0 ? null : normalizeProfile(value.target, mutation)
3160
+ };
3161
+ }
3162
+ async changeWatchlist(params, direction) {
3163
+ const { tickers } = normalizeWatchlistTickersParams(params);
3164
+ this.client._requireAuth();
3165
+ const lookups = await this.lookupTickers(tickers);
3166
+ const changed = [];
3167
+ const unchanged = [];
3168
+ const unresolved = [];
3169
+ const groupByEntity = /* @__PURE__ */ new Map();
3170
+ const writeIds = [];
3171
+ for (const lookup of lookups) {
3172
+ if (!lookup.ok) {
3173
+ unresolved.push(lookup.unresolved);
3174
+ continue;
3175
+ }
3176
+ const seenGroup = groupByEntity.get(lookup.ticker.entityId);
3177
+ if (seenGroup) {
3178
+ seenGroup.push(lookup.ticker);
3179
+ continue;
3180
+ }
3181
+ const needsChange = direction === "add" ? !lookup.inWatchlist : lookup.inWatchlist;
3182
+ const group = needsChange ? changed : unchanged;
3183
+ group.push(lookup.ticker);
3184
+ groupByEntity.set(lookup.ticker.entityId, group);
3185
+ if (needsChange || direction === "remove") {
3186
+ writeIds.push(lookup.ticker.entityId);
3187
+ }
3188
+ }
3189
+ if (writeIds.length > 0) {
3190
+ const mutation = direction === "add" ? "followTickers" : "unfollowTickers";
3191
+ const input = direction === "add" ? "FollowTickersInput" : "UnfollowTickersInput";
3192
+ const response = await this.client._request("POST", "/query", {
3193
+ body: {
3194
+ query: `mutation ToolkitChangeWatchlist($input: ${input}!) { ${mutation}(input: $input) { entities { id } } }`,
3195
+ variables: { input: { entityIds: writeIds } }
3196
+ }
3197
+ });
3198
+ const value = responseData(response, mutation)[mutation];
3199
+ if (!record3(value) || !Array.isArray(value.entities)) {
3200
+ return invalidResponse3(mutation);
3201
+ }
3202
+ }
3203
+ return { changed, unchanged, unresolved };
3204
+ }
3205
+ async lookupTickers(tickers) {
3206
+ const results = new Array(tickers.length);
3207
+ let next = 0;
3208
+ const worker = async () => {
3209
+ while (next < tickers.length) {
3210
+ const index = next++;
3211
+ const { ticker, kind } = tickers[index];
3212
+ results[index] = await this.lookupTicker(ticker, kind);
3213
+ }
3214
+ };
3215
+ await Promise.all(
3216
+ Array.from(
3217
+ { length: Math.min(LOOKUP_CONCURRENCY, tickers.length) },
3218
+ worker
3219
+ )
3220
+ );
3221
+ return results;
3222
+ }
3223
+ async lookupTicker(input, kind) {
3224
+ const response = await this.client._request("POST", "/query", {
3225
+ body: {
3226
+ query: `query ToolkitTickerLookup($input: MarketEntityLookupInput!) { market { entity(input: $input) { ${TICKER_FIELDS} viewerState { isFollowed } } } }`,
3227
+ variables: { input: { ticker: input, kind } }
3228
+ }
3229
+ });
3230
+ const failure = graphQLFailure(response);
3231
+ if (failure) {
3232
+ if (UNRESOLVED_LOOKUP_CODES.has(failure.code)) {
3233
+ return unresolvedTicker(input, kind, failure.code, failure.message);
3234
+ }
3235
+ throwFailure(failure);
3236
+ }
3237
+ const field = "market.entity";
3238
+ if (!record3(response) || !record3(response.data) || !record3(response.data.market)) {
3239
+ return invalidResponse3(field);
3240
+ }
3241
+ const entity = response.data.market.entity;
3242
+ if (entity === null || entity === void 0) {
3243
+ return unresolvedTicker(
3244
+ input,
3245
+ kind,
3246
+ "NOT_FOUND",
3247
+ `no entity found for ticker: ${input}`
3248
+ );
3249
+ }
3250
+ if (!record3(entity)) return invalidResponse3(field);
3251
+ const viewerState = entity.viewerState;
3252
+ if (viewerState === null || viewerState === void 0) {
3253
+ throw new AlvaError(
3254
+ "PERMISSION_DENIED",
3255
+ "This credential cannot read the user's watchlist",
3256
+ 403
3257
+ );
3258
+ }
3259
+ if (!record3(viewerState) || typeof viewerState.isFollowed !== "boolean") {
3260
+ return invalidResponse3(field);
3261
+ }
3262
+ return {
3263
+ ok: true,
3264
+ inWatchlist: viewerState.isFollowed,
3265
+ ticker: {
3266
+ input,
3267
+ entityId: requireString(entity.id, field),
3268
+ ticker: requireString(entity.ticker, field),
3269
+ name: typeof entity.name === "string" ? entity.name : "",
3270
+ kind: requireString(entity.kind, field)
3271
+ }
3272
+ };
3273
+ }
3274
+ };
3275
+
2824
3276
  // src/resources/alerts.ts
2825
3277
  var AlertsResource = class {
2826
3278
  constructor(client) {
@@ -3492,7 +3944,8 @@ var MarketsResource = class {
3492
3944
  }
3493
3945
  selectPeriod(catalog, event, ticker) {
3494
3946
  if (event === "latest-completed") {
3495
- if (catalog.defaultPeriod) return catalog.defaultPeriod;
3947
+ const completed = catalog.periods.filter((period) => period.status === "COMPLETED").sort((a, b) => b.earningsDate.localeCompare(a.earningsDate));
3948
+ if (completed.length > 0) return completed[0];
3496
3949
  } else {
3497
3950
  const upcoming = catalog.periods.filter((period) => period.status === "UPCOMING").sort((a, b) => a.earningsDate.localeCompare(b.earningsDate));
3498
3951
  if (upcoming.length > 0) return upcoming[0];
@@ -3588,7 +4041,7 @@ var SCHEDULE_NAME = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
3588
4041
  var RFC3339 = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(Z|[+-](\d{2}):(\d{2}))$/i;
3589
4042
  var RFC3339_FRACTIONAL = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d{1,9})?(Z|[+-](\d{2}):(\d{2}))$/i;
3590
4043
  var ISO_DURATION = /^P(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?)?$/;
3591
- var GRAPHQL_STATUS_BY_CODE2 = {
4044
+ var GRAPHQL_STATUS_BY_CODE3 = {
3592
4045
  INVALID_ARGUMENT: 400,
3593
4046
  UNAUTHENTICATED: 401,
3594
4047
  PERMISSION_DENIED: 403,
@@ -3690,7 +4143,7 @@ var SchedulesResource = class {
3690
4143
  const codes = response.errors.map((error) => error.extensions?.code);
3691
4144
  const distinctCodes = new Set(codes);
3692
4145
  const canonicalCode = distinctCodes.size === 1 && typeof codes[0] === "string" ? codes[0] : void 0;
3693
- const canonicalStatus = canonicalCode ? GRAPHQL_STATUS_BY_CODE2[canonicalCode] : void 0;
4146
+ const canonicalStatus = canonicalCode ? GRAPHQL_STATUS_BY_CODE3[canonicalCode] : void 0;
3694
4147
  const errorCode = canonicalCode !== void 0 && canonicalStatus !== void 0 ? canonicalCode : "GRAPHQL_ERROR";
3695
4148
  throw new AlvaError(
3696
4149
  errorCode,
@@ -3939,7 +4392,7 @@ function scheduleEmptyResponse() {
3939
4392
  }
3940
4393
 
3941
4394
  // src/resources/steward.ts
3942
- var GRAPHQL_STATUS_BY_CODE3 = {
4395
+ var GRAPHQL_STATUS_BY_CODE4 = {
3943
4396
  INVALID_ARGUMENT: 400,
3944
4397
  UNAUTHENTICATED: 401,
3945
4398
  PERMISSION_DENIED: 403,
@@ -3984,12 +4437,47 @@ var BRIEFED = `
3984
4437
  mutation ToolkitStewardBriefed($input: CompleteStewardBriefInput!) {
3985
4438
  completeStewardBrief(input: $input) { ok }
3986
4439
  }`.trim();
4440
+ var DIGEST_RUN_FIELDS = `
4441
+ digestRunId state scheduleId scheduleVersion occurrenceIndex
4442
+ windowSinceMs windowUntilMs scanCompletedAtMs bodySha256 coverageSha256
4443
+ channelMessageId attempts lastError startedAtMs completedAtMs sendUncertainAtMs
4444
+ `.trim();
4445
+ var DIGEST_RUN = `
4446
+ query ToolkitStewardDigestRun($inboxPath: String!, $digestRunId: String!) {
4447
+ viewer { stewardDigestRun(inboxPath: $inboxPath, digestRunId: $digestRunId) { ${DIGEST_RUN_FIELDS} } }
4448
+ }`.trim();
4449
+ var DIGEST_RUN_PENDING = `
4450
+ query ToolkitStewardDigestRunPending($inboxPath: String!, $digestRunId: String!, $input: StewardDigestRunPendingInput) {
4451
+ viewer {
4452
+ stewardDigestRunPending(inboxPath: $inboxPath, digestRunId: $digestRunId, input: $input) {
4453
+ edges {
4454
+ node { deliveryId feedEntryId source { kind id } decisionReason consumedAtMs alertSnapshot }
4455
+ }
4456
+ pageInfo { hasNextPage endCursor }
4457
+ }
4458
+ }
4459
+ }`.trim();
4460
+ var PUBLISH_DAILY_BRIEF = `
4461
+ mutation ToolkitStewardPublishDailyBrief($input: PublishStewardDailyBriefInput!) {
4462
+ publishStewardDailyBrief(input: $input) { run { ${DIGEST_RUN_FIELDS} } }
4463
+ }`.trim();
3987
4464
  var DECISIONS = /* @__PURE__ */ new Set([
3988
4465
  "immediate",
3989
4466
  "digest",
3990
4467
  "suppress"
3991
4468
  ]);
3992
4469
  var DELIVERY_ID = /^[1-9][0-9]{0,18}$/;
4470
+ var MAX_LEGACY_BRIEFED_IDS = 100;
4471
+ var MAX_DIGEST_RUN_COVERAGE = 1e4;
4472
+ var DIGEST_RUN_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
4473
+ var PENDING_ATTEMPTS = 3;
4474
+ var TRANSIENT_PENDING_CODES = /* @__PURE__ */ new Set([
4475
+ "NETWORK_ERROR",
4476
+ "NETWORK_TIMEOUT",
4477
+ "UNAVAILABLE",
4478
+ "DEADLINE_EXCEEDED"
4479
+ ]);
4480
+ var TRANSIENT_HTTP_STATUSES = /* @__PURE__ */ new Set([502, 503, 504]);
3993
4481
  function invalid2(message) {
3994
4482
  return new AlvaError("INVALID_ARGUMENT", message, 400);
3995
4483
  }
@@ -4048,6 +4536,13 @@ function requireRequestId(value) {
4048
4536
  throw invalid2("request id must be a UUID");
4049
4537
  return value;
4050
4538
  }
4539
+ function requireDigestRunId(value) {
4540
+ if (!DIGEST_RUN_ID.test(value)) throw invalid2("digest run id must be a UUID");
4541
+ return value.toLowerCase();
4542
+ }
4543
+ function isTransientStewardError(error) {
4544
+ return error instanceof AlvaError && (TRANSIENT_PENDING_CODES.has(error.code) || TRANSIENT_HTTP_STATUSES.has(error.status));
4545
+ }
4051
4546
  function emptyResponse() {
4052
4547
  return new AlvaError("EMPTY_RESPONSE", "steward response was empty", 502);
4053
4548
  }
@@ -4110,6 +4605,56 @@ var StewardResource = class {
4110
4605
  return message;
4111
4606
  }
4112
4607
  async pending(params) {
4608
+ if (params.after !== void 0) return this.pendingPage(params);
4609
+ const items = [];
4610
+ const deliveryIds = /* @__PURE__ */ new Set();
4611
+ const cursors = /* @__PURE__ */ new Set();
4612
+ let after;
4613
+ let windowSinceMs;
4614
+ let windowUntilMs;
4615
+ do {
4616
+ const page = await this.pendingPageWithRetry({
4617
+ ...params,
4618
+ after,
4619
+ sinceMs: after === void 0 ? params.sinceMs : void 0,
4620
+ untilMs: after === void 0 ? params.untilMs : void 0
4621
+ });
4622
+ if (windowSinceMs === void 0) {
4623
+ windowSinceMs = page.windowSinceMs;
4624
+ windowUntilMs = page.windowUntilMs;
4625
+ } else if (page.windowSinceMs !== windowSinceMs || page.windowUntilMs !== windowUntilMs) {
4626
+ throw new AlvaError(
4627
+ "ABORTED",
4628
+ "steward pending window changed during pagination",
4629
+ 409
4630
+ );
4631
+ }
4632
+ for (const item of page.items) {
4633
+ if (deliveryIds.has(item.deliveryId)) continue;
4634
+ deliveryIds.add(item.deliveryId);
4635
+ items.push(item);
4636
+ }
4637
+ after = page.nextCursor ?? void 0;
4638
+ if (after !== void 0) {
4639
+ if (cursors.has(after)) {
4640
+ throw new AlvaError(
4641
+ "INTERNAL",
4642
+ "steward pending pagination loop detected",
4643
+ 500
4644
+ );
4645
+ }
4646
+ cursors.add(after);
4647
+ }
4648
+ } while (after !== void 0);
4649
+ if (windowSinceMs === void 0 || windowUntilMs === void 0)
4650
+ throw emptyResponse();
4651
+ return {
4652
+ items,
4653
+ windowSinceMs,
4654
+ windowUntilMs
4655
+ };
4656
+ }
4657
+ async pendingPage(params) {
4113
4658
  this.client._requireAuth();
4114
4659
  const first = params.first ?? 50;
4115
4660
  if (!Number.isInteger(first) || first < 1 || first > 100)
@@ -4138,7 +4683,14 @@ var StewardResource = class {
4138
4683
  if (!Number.isSafeInteger(windowSinceMs) || !Number.isSafeInteger(windowUntilMs) || windowSinceMs <= 0 || windowUntilMs <= windowSinceMs)
4139
4684
  throw emptyResponse();
4140
4685
  const items = page.edges.map((edge) => edge.node);
4141
- const nextCursor2 = page.pageInfo?.hasNextPage === true && page.pageInfo.endCursor ? page.pageInfo.endCursor : null;
4686
+ const pageInfo2 = page.pageInfo;
4687
+ if (!pageInfo2 || typeof pageInfo2.hasNextPage !== "boolean")
4688
+ throw emptyResponse();
4689
+ const endCursor = pageInfo2.endCursor;
4690
+ if (endCursor !== void 0 && endCursor !== null && typeof endCursor !== "string")
4691
+ throw emptyResponse();
4692
+ if (pageInfo2.hasNextPage && !endCursor) throw emptyResponse();
4693
+ const nextCursor2 = pageInfo2.hasNextPage ? endCursor : null;
4142
4694
  return {
4143
4695
  items,
4144
4696
  nextCursor: nextCursor2,
@@ -4146,20 +4698,95 @@ var StewardResource = class {
4146
4698
  windowUntilMs
4147
4699
  };
4148
4700
  }
4701
+ async pendingPageWithRetry(params) {
4702
+ for (let attempt = 1; attempt < PENDING_ATTEMPTS; attempt += 1) {
4703
+ try {
4704
+ return await this.pendingPage(params);
4705
+ } catch (error) {
4706
+ if (!isTransientStewardError(error)) throw error;
4707
+ }
4708
+ }
4709
+ return this.pendingPage(params);
4710
+ }
4149
4711
  async briefed(params) {
4150
4712
  this.client._requireAuth();
4151
4713
  const digestRunId = params.digestRunId?.trim();
4152
4714
  if (!digestRunId) throw invalid2("a digest run id is required");
4715
+ const inboxPath = requireInboxPath(params);
4716
+ const deliveryIds = requireDeliveryIds(params.deliveryIds);
4717
+ if (deliveryIds.length > MAX_LEGACY_BRIEFED_IDS)
4718
+ throw invalid2("legacy briefed accepts at most 100 delivery ids");
4153
4719
  const data = await this.graphql(BRIEFED, {
4154
4720
  input: {
4155
- inboxPath: requireInboxPath(params),
4156
- deliveryIds: requireDeliveryIds(params.deliveryIds),
4721
+ inboxPath,
4722
+ deliveryIds,
4157
4723
  digestRunId
4158
4724
  }
4159
4725
  });
4160
4726
  if (data.completeStewardBrief?.ok !== true) throw emptyResponse();
4161
4727
  return { ok: true };
4162
4728
  }
4729
+ async digestRun(params) {
4730
+ this.client._requireAuth();
4731
+ const data = await this.graphql(DIGEST_RUN, {
4732
+ inboxPath: requireInboxPath(params),
4733
+ digestRunId: requireDigestRunId(params.digestRunId)
4734
+ });
4735
+ const run = data.viewer?.stewardDigestRun;
4736
+ if (!run) throw emptyResponse();
4737
+ return run;
4738
+ }
4739
+ async digestRunPending(params) {
4740
+ this.client._requireAuth();
4741
+ const inboxPath = requireInboxPath(params);
4742
+ const digestRunId = requireDigestRunId(params.digestRunId);
4743
+ const items = [];
4744
+ const seenCursors = /* @__PURE__ */ new Set();
4745
+ let after;
4746
+ for (; ; ) {
4747
+ const data = await this.graphql(DIGEST_RUN_PENDING, {
4748
+ inboxPath,
4749
+ digestRunId,
4750
+ input: { first: 100, ...after === void 0 ? {} : { after } }
4751
+ });
4752
+ const connection2 = data.viewer?.stewardDigestRunPending;
4753
+ if (!connection2 || !Array.isArray(connection2.edges))
4754
+ throw emptyResponse();
4755
+ const pageInfo2 = connection2.pageInfo;
4756
+ if (!pageInfo2 || typeof pageInfo2.hasNextPage !== "boolean")
4757
+ throw emptyResponse();
4758
+ for (const edge of connection2.edges) {
4759
+ if (!edge?.node) throw emptyResponse();
4760
+ items.push(edge.node);
4761
+ }
4762
+ if (!pageInfo2.hasNextPage) break;
4763
+ const next = pageInfo2.endCursor;
4764
+ if (typeof next !== "string" || next === "" || seenCursors.has(next))
4765
+ throw emptyResponse();
4766
+ seenCursors.add(next);
4767
+ after = next;
4768
+ }
4769
+ return items;
4770
+ }
4771
+ async sendDigestRun(params) {
4772
+ this.client._requireAuth();
4773
+ const deliveryIds = normalizeDeliveryIds(params.deliveryIds ?? []);
4774
+ if (deliveryIds.length > MAX_DIGEST_RUN_COVERAGE)
4775
+ throw invalid2("durable Daily Brief accepts at most 10000 delivery ids");
4776
+ if (params.body !== void 0 && params.body.trim() === "")
4777
+ throw invalid2("a message body must be non-blank when provided");
4778
+ const data = await this.graphql(PUBLISH_DAILY_BRIEF, {
4779
+ input: {
4780
+ inboxPath: requireInboxPath(params),
4781
+ digestRunId: requireDigestRunId(params.digestRunId),
4782
+ deliveryIds,
4783
+ ...params.body === void 0 ? {} : { body: params.body }
4784
+ }
4785
+ });
4786
+ const run = data.publishStewardDailyBrief?.run;
4787
+ if (!run) throw emptyResponse();
4788
+ return run;
4789
+ }
4163
4790
  async graphql(query, variables) {
4164
4791
  const response = await this.client._request("POST", "/query", {
4165
4792
  body: { query, variables }
@@ -4168,7 +4795,7 @@ var StewardResource = class {
4168
4795
  if (response.errors?.length) {
4169
4796
  const codes = response.errors.map((error) => error.extensions?.code);
4170
4797
  const canonicalCode = new Set(codes).size === 1 && typeof codes[0] === "string" ? codes[0] : void 0;
4171
- const canonicalStatus = canonicalCode ? GRAPHQL_STATUS_BY_CODE3[canonicalCode] : void 0;
4798
+ const canonicalStatus = canonicalCode ? GRAPHQL_STATUS_BY_CODE4[canonicalCode] : void 0;
4172
4799
  throw new AlvaError(
4173
4800
  canonicalCode !== void 0 && canonicalStatus !== void 0 ? canonicalCode : "GRAPHQL_ERROR",
4174
4801
  response.errors.map((error) => error.message).filter((message) => typeof message === "string").join("; ") || "GraphQL request failed",
@@ -4284,12 +4911,12 @@ function dedupe(candidates) {
4284
4911
  });
4285
4912
  }
4286
4913
  function resolveFilters(params) {
4287
- const record3 = isRecord(params) ? params : {};
4914
+ const record4 = isRecord(params) ? params : {};
4288
4915
  return {
4289
- market: typeof record3.market === "string" ? record3.market : void 0,
4290
- instrumentType: typeof record3.instrumentType === "string" ? record3.instrumentType : void 0,
4291
- underlyingType: typeof record3.underlyingType === "string" ? record3.underlyingType : void 0,
4292
- quote: typeof record3.quote === "string" ? record3.quote : void 0
4916
+ market: typeof record4.market === "string" ? record4.market : void 0,
4917
+ instrumentType: typeof record4.instrumentType === "string" ? record4.instrumentType : void 0,
4918
+ underlyingType: typeof record4.underlyingType === "string" ? record4.underlyingType : void 0,
4919
+ quote: typeof record4.quote === "string" ? record4.quote : void 0
4293
4920
  };
4294
4921
  }
4295
4922
  function pairSearchParams(pair, params) {
@@ -4337,11 +4964,11 @@ var TradingPairsResource = class {
4337
4964
  return { query, candidates };
4338
4965
  }
4339
4966
  async resolve(params) {
4340
- const record3 = isRecord(params) ? params : {};
4341
- const pair = typeof record3.pair === "string" ? record3.pair.trim() : void 0;
4967
+ const record4 = isRecord(params) ? params : {};
4968
+ const pair = typeof record4.pair === "string" ? record4.pair.trim() : void 0;
4342
4969
  const filters = resolveFilters(params);
4343
4970
  const searchParams = pair === void 0 ? {
4344
- symbol: typeof record3.symbol === "string" ? record3.symbol : "",
4971
+ symbol: typeof record4.symbol === "string" ? record4.symbol : "",
4345
4972
  ...filters
4346
4973
  } : pairSearchParams(pair, filters);
4347
4974
  const result = await this.search(searchParams);
@@ -4554,6 +5181,58 @@ function nextCursor(page) {
4554
5181
  throw invalid3();
4555
5182
  return info.hasNextPage ? info.endCursor : null;
4556
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
+ }
4557
5236
  async function graphql(client, document, variables) {
4558
5237
  const response = await client._request("POST", "/query", {
4559
5238
  body: { query: document, variables }
@@ -4639,17 +5318,29 @@ var ThesesResource = class {
4639
5318
  related(id, params = {}) {
4640
5319
  return relatedTheses(this.client, id, params);
4641
5320
  }
4642
- async assetCandidates(text) {
5321
+ async assetCandidates(text, params = {}) {
4643
5322
  this.client._requireAuth();
4644
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
+ }
4645
5335
  const response = await this.client._request("POST", "/query", {
4646
5336
  body: {
4647
5337
  query: `query ThesisAssetCandidates($input: ThesisAssetCandidatesInput!) {
4648
5338
  viewer { thesisAssetCandidates(input: $input) {
4649
5339
  mentions { quote ticker resolution stance candidates { entityId ticker name kind } }
5340
+ returnPreview { tracking askSwitch directions { entityId direction } keptEntityIds lastLegRemoved }
4650
5341
  } }
4651
5342
  }`,
4652
- variables: { input: { text: source } }
5343
+ variables: { input }
4653
5344
  }
4654
5345
  });
4655
5346
  if (Array.isArray(response?.errors) && response.errors.length > 0) {
@@ -4661,19 +5352,19 @@ var ThesesResource = class {
4661
5352
  const viewer = isRecord2(data) ? data.viewer : void 0;
4662
5353
  const result = isRecord2(viewer) ? viewer.thesisAssetCandidates : void 0;
4663
5354
  if (!isRecord2(result) || !Array.isArray(result.mentions)) {
4664
- throw invalidResponse3("asset candidates response must contain mentions");
5355
+ throw invalidResponse4("asset candidates response must contain mentions");
4665
5356
  }
4666
5357
  const mentions = result.mentions.map((item, index) => {
4667
5358
  if (!isRecord2(item) || typeof item.quote !== "string" || typeof item.ticker !== "string" || !["RESOLVED", "AMBIGUOUS", "UNRESOLVED"].includes(
4668
5359
  item.resolution
4669
5360
  ) || !["UNKNOWN", "BULLISH", "BEARISH"].includes(item.stance) || !Array.isArray(item.candidates)) {
4670
- throw invalidResponse3(`asset mention ${index} is invalid`);
5361
+ throw invalidResponse4(`asset mention ${index} is invalid`);
4671
5362
  }
4672
5363
  const candidates = item.candidates.map((candidate) => {
4673
5364
  if (!isRecord2(candidate) || typeof candidate.ticker !== "string" || typeof candidate.name !== "string" || !["STOCK", "ETF", "CRYPTO", "INDEX"].includes(
4674
5365
  candidate.kind
4675
5366
  )) {
4676
- throw invalidResponse3(`asset mention ${index} has invalid candidate`);
5367
+ throw invalidResponse4(`asset mention ${index} has invalid candidate`);
4677
5368
  }
4678
5369
  return {
4679
5370
  entityId: responseID(
@@ -4687,7 +5378,11 @@ var ThesesResource = class {
4687
5378
  });
4688
5379
  return { ...item, candidates };
4689
5380
  });
4690
- 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);
4691
5386
  }
4692
5387
  async create(params) {
4693
5388
  this.client._requireAuth();
@@ -4703,7 +5398,7 @@ var ThesesResource = class {
4703
5398
  await this.client._request("GET", `/api/v1/theses/${thesisID}`)
4704
5399
  );
4705
5400
  if (response.thesis.id !== thesisID) {
4706
- throw invalidResponse3("get response must match the requested thesis");
5401
+ throw invalidResponse4("get response must match the requested thesis");
4707
5402
  }
4708
5403
  return response;
4709
5404
  }
@@ -4718,7 +5413,7 @@ var ThesesResource = class {
4718
5413
  )
4719
5414
  );
4720
5415
  if (response.thesis.id !== thesisID || response.thesis.author_version_id !== versionID) {
4721
- throw invalidResponse3(
5416
+ throw invalidResponse4(
4722
5417
  "version response must match the requested thesis and author version"
4723
5418
  );
4724
5419
  }
@@ -4741,38 +5436,14 @@ var ThesesResource = class {
4741
5436
  }
4742
5437
  );
4743
5438
  if (!isRecord2(response) || !Array.isArray(response.versions) || typeof response.next_cursor !== "string")
4744
- throw invalidResponse3("invalid Update list");
5439
+ throw invalidResponse4("invalid Update list");
4745
5440
  const versions = response.versions.map(
4746
5441
  (value) => thesisResponse({ thesis: value }).thesis
4747
5442
  );
4748
5443
  if (versions.some((version) => version.id !== thesisID))
4749
- throw invalidResponse3("Update list must match requested Thesis");
5444
+ throw invalidResponse4("Update list must match requested Thesis");
4750
5445
  return { versions, next_cursor: response.next_cursor };
4751
5446
  }
4752
- /** Deletes only the selected Update; never falls back to whole-Thesis deletion. */
4753
- async deleteUpdate(id, authorVersionID, expectedAuthorVersionID) {
4754
- this.client._requireAuth();
4755
- const thesisID = requireID(id, "id");
4756
- const versionID = requireID(authorVersionID, "author_version_id");
4757
- const expected = requireID(
4758
- expectedAuthorVersionID,
4759
- "expected_author_version_id"
4760
- );
4761
- const response = thesisResponse(
4762
- await this.client._request(
4763
- "DELETE",
4764
- `/api/v1/theses/${thesisID}/versions/${versionID}`,
4765
- {
4766
- query: { expected_author_version_id: expected }
4767
- }
4768
- )
4769
- );
4770
- if (response.thesis.id !== thesisID)
4771
- throw invalidResponse3(
4772
- "delete Update response must match requested Thesis"
4773
- );
4774
- return response;
4775
- }
4776
5447
  async signals(id, params = {}) {
4777
5448
  this.client._requireAuth();
4778
5449
  const first = params.first ?? 20;
@@ -4807,7 +5478,7 @@ var ThesesResource = class {
4807
5478
  })
4808
5479
  );
4809
5480
  if (response.thesis.id !== thesisID) {
4810
- throw invalidResponse3("update response must match the requested thesis");
5481
+ throw invalidResponse4("update response must match the requested thesis");
4811
5482
  }
4812
5483
  return response;
4813
5484
  }
@@ -4829,7 +5500,7 @@ var ThesesResource = class {
4829
5500
  current.thesis.entity_ids,
4830
5501
  current.thesis.entity_stances
4831
5502
  )) {
4832
- throw invalidResponse3(
5503
+ throw invalidResponse4(
4833
5504
  "archive requires one entity_stance for every Thesis entity"
4834
5505
  );
4835
5506
  }
@@ -4846,7 +5517,7 @@ var ThesesResource = class {
4846
5517
  note: params.note
4847
5518
  });
4848
5519
  if (response.thesis.id !== thesisID || response.thesis.archived !== params.archived) {
4849
- throw invalidResponse3("archive response must match the requested state");
5520
+ throw invalidResponse4("archive response must match the requested state");
4850
5521
  }
4851
5522
  return response;
4852
5523
  }
@@ -4861,15 +5532,15 @@ var ThesesResource = class {
4861
5532
  });
4862
5533
  const result = data.setThesisStarred;
4863
5534
  if (!isRecord2(result) || !isRecord2(result.stats) || !isRecord2(result.viewerState)) {
4864
- throw invalidResponse3("star response must contain stats and viewerState");
5535
+ throw invalidResponse4("star response must contain stats and viewerState");
4865
5536
  }
4866
5537
  const returnedID = responseID(result.thesisId, "thesisId");
4867
5538
  if (returnedID !== thesisID) {
4868
- throw invalidResponse3("star response must match the requested thesis");
5539
+ throw invalidResponse4("star response must match the requested thesis");
4869
5540
  }
4870
5541
  const starCount = result.stats.starCount;
4871
5542
  if (typeof starCount !== "number" || !Number.isInteger(starCount) || starCount < 0) {
4872
- throw invalidResponse3(
5543
+ throw invalidResponse4(
4873
5544
  "star response must contain a nonnegative star count"
4874
5545
  );
4875
5546
  }
@@ -4878,7 +5549,7 @@ var ThesesResource = class {
4878
5549
  "viewerState.isStarred"
4879
5550
  );
4880
5551
  if (returnedStarred !== isStarred) {
4881
- throw invalidResponse3("star response did not apply the requested state");
5552
+ throw invalidResponse4("star response did not apply the requested state");
4882
5553
  }
4883
5554
  return {
4884
5555
  thesis_id: returnedID,
@@ -4897,7 +5568,7 @@ var ThesesResource = class {
4897
5568
  });
4898
5569
  const result = data.setThesisSignalEnabled;
4899
5570
  if (!isRecord2(result) || !isRecord2(result.publication)) {
4900
- throw invalidResponse3("Signal response must contain publication");
5571
+ throw invalidResponse4("Signal response must contain publication");
4901
5572
  }
4902
5573
  const publication = result.publication;
4903
5574
  const returnedID = responseID(
@@ -4905,14 +5576,14 @@ var ThesesResource = class {
4905
5576
  "publication.playbookId"
4906
5577
  );
4907
5578
  if (returnedID !== thesisID) {
4908
- throw invalidResponse3("Signal response must match the requested thesis");
5579
+ throw invalidResponse4("Signal response must match the requested thesis");
4909
5580
  }
4910
5581
  const researchPaused = responseBoolean(
4911
5582
  publication.researchPaused,
4912
5583
  "publication.researchPaused"
4913
5584
  );
4914
5585
  if (researchPaused === enabled) {
4915
- throw invalidResponse3(
5586
+ throw invalidResponse4(
4916
5587
  "Signal response did not apply the requested state"
4917
5588
  );
4918
5589
  }
@@ -4942,41 +5613,12 @@ var ThesesResource = class {
4942
5613
  )
4943
5614
  );
4944
5615
  if (response.thesis.id !== thesisID || response.thesis.visibility !== visibility) {
4945
- throw invalidResponse3(
5616
+ throw invalidResponse4(
4946
5617
  "visibility response must match the requested thesis and visibility"
4947
5618
  );
4948
5619
  }
4949
5620
  return response;
4950
5621
  }
4951
- async close(id, params) {
4952
- this.client._requireAuth();
4953
- const body = {
4954
- expected_author_version_id: requireID(
4955
- params.expected_author_version_id,
4956
- "expected_author_version_id"
4957
- )
4958
- };
4959
- if (params.note !== void 0) body.note = requireText2(params.note, "note");
4960
- return thesisResponse(
4961
- await this.client._request(
4962
- "POST",
4963
- `/api/v1/theses/${requireID(id, "id")}/close`,
4964
- { body }
4965
- )
4966
- );
4967
- }
4968
- async delete(id) {
4969
- this.client._requireAuth();
4970
- const response = await this.client._request(
4971
- "DELETE",
4972
- `/api/v1/theses/${requireID(id, "id")}`
4973
- );
4974
- if (response === void 0) return {};
4975
- if (!isRecord2(response) || Object.keys(response).length !== 0) {
4976
- throw invalidResponse3("delete response must be {}");
4977
- }
4978
- return {};
4979
- }
4980
5622
  async rewrite(params) {
4981
5623
  this.client._requireAuth();
4982
5624
  const body = requireBody(params.body);
@@ -4989,7 +5631,7 @@ var ThesesResource = class {
4989
5631
  }
4990
5632
  );
4991
5633
  if (!isRecord2(response) || typeof response.body !== "string") {
4992
- throw invalidResponse3("rewrite response must contain a string body");
5634
+ throw invalidResponse4("rewrite response must contain a string body");
4993
5635
  }
4994
5636
  return { body: responseBody(response.body) };
4995
5637
  }
@@ -5019,6 +5661,8 @@ function createBody(params) {
5019
5661
  }
5020
5662
  if (params.tickers !== void 0)
5021
5663
  body.tickers = requireTickers(params.tickers);
5664
+ if (params.track_return !== void 0)
5665
+ body.track_return = requireTrackReturn(params.track_return);
5022
5666
  if (params.entity_stances !== void 0) {
5023
5667
  body.entity_stances = requireEntityStances(
5024
5668
  params.entity_stances,
@@ -5027,6 +5671,52 @@ function createBody(params) {
5027
5671
  }
5028
5672
  return body;
5029
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
+ }
5030
5720
  function requireEntityStances(value, entityIDs) {
5031
5721
  if (!Array.isArray(value) || value.length > MAX_ENTITY_IDS)
5032
5722
  throw invalidArgument("entity_stances must contain at most 100 values");
@@ -5044,7 +5734,7 @@ function requireEntityStances(value, entityIDs) {
5044
5734
  "entity stance must reference one unique entity_id"
5045
5735
  );
5046
5736
  seen.add(entityID);
5047
- if (!["unknown", "bullish", "bearish"].includes(item.stance))
5737
+ if (!ENTITY_STANCES.includes(item.stance))
5048
5738
  throw invalidArgument(`entity_stances[${index}].stance is invalid`);
5049
5739
  return { entity_id: entityID, stance: item.stance };
5050
5740
  });
@@ -5059,8 +5749,7 @@ function updateBody(params) {
5059
5749
  body: requireBody(params.body),
5060
5750
  title: requireTitle(params.title ?? ""),
5061
5751
  entity_ids: requireIDs(params.entity_ids ?? [], "entity_ids"),
5062
- visibility: requireVisibility(params.visibility),
5063
- editorial: params.editorial ?? false
5752
+ visibility: requireVisibility(params.visibility)
5064
5753
  };
5065
5754
  if (params.medias !== void 0) {
5066
5755
  if (!Array.isArray(params.medias) || params.medias.length > 20)
@@ -5075,6 +5764,8 @@ function updateBody(params) {
5075
5764
  body.archived = params.archived;
5076
5765
  }
5077
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);
5078
5769
  if (params.entity_stances !== void 0) {
5079
5770
  body.entity_stances = requireEntityStances(
5080
5771
  params.entity_stances,
@@ -5085,7 +5776,7 @@ function updateBody(params) {
5085
5776
  }
5086
5777
  function thesisResponse(response) {
5087
5778
  if (!isRecord2(response) || !isRecord2(response.thesis)) {
5088
- throw invalidResponse3("response must contain thesis");
5779
+ throw invalidResponse4("response must contain thesis");
5089
5780
  }
5090
5781
  const thesis = response.thesis;
5091
5782
  const value = {
@@ -5110,10 +5801,10 @@ function thesisResponse(response) {
5110
5801
  };
5111
5802
  if (thesis.medias !== void 0) {
5112
5803
  if (!Array.isArray(thesis.medias) || thesis.medias.length > 20)
5113
- throw invalidResponse3("thesis.medias must contain at most 20 items");
5804
+ throw invalidResponse4("thesis.medias must contain at most 20 items");
5114
5805
  value.medias = thesis.medias.map((item) => {
5115
5806
  if (!validMedia(item))
5116
- throw invalidResponse3("thesis.medias contains invalid media");
5807
+ throw invalidResponse4("thesis.medias contains invalid media");
5117
5808
  return {
5118
5809
  type: item.type,
5119
5810
  cover_url: item.cover_url,
@@ -5130,16 +5821,27 @@ function thesisResponse(response) {
5130
5821
  value.note = responseText(thesis.note, "thesis.note");
5131
5822
  if (thesis.entity_stances !== void 0) {
5132
5823
  if (!Array.isArray(thesis.entity_stances))
5133
- throw invalidResponse3("thesis.entity_stances must be an array");
5824
+ throw invalidResponse4("thesis.entity_stances must be an array");
5134
5825
  value.entity_stances = thesis.entity_stances.map((item) => {
5135
5826
  if (!isRecord2(item))
5136
- throw invalidResponse3("thesis.entity_stances contains invalid entry");
5827
+ throw invalidResponse4("thesis.entity_stances contains invalid entry");
5137
5828
  const entityID = responseID(item.entity_id, "entity_stances.entity_id");
5138
5829
  if (!value.entity_ids.includes(entityID))
5139
- throw invalidResponse3("entity stance must reference a thesis entity");
5140
- if (!["unknown", "bullish", "bearish"].includes(item.stance))
5141
- throw invalidResponse3("thesis.entity_stances contains invalid stance");
5142
- return { entity_id: entityID, stance: item.stance };
5830
+ throw invalidResponse4("entity stance must reference a thesis entity");
5831
+ if (!ENTITY_STANCES.includes(item.stance))
5832
+ throw invalidResponse4("thesis.entity_stances contains invalid stance");
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;
5143
5845
  });
5144
5846
  }
5145
5847
  return { thesis: value };
@@ -5147,7 +5849,7 @@ function thesisResponse(response) {
5147
5849
  function thesisGetResponse(response) {
5148
5850
  const base = thesisResponse(response);
5149
5851
  if (!isRecord2(response) || !isRecord2(response.author)) {
5150
- throw invalidResponse3("response must contain author");
5852
+ throw invalidResponse4("response must contain author");
5151
5853
  }
5152
5854
  const authorRecord = response.author;
5153
5855
  const author = {
@@ -5161,14 +5863,14 @@ function thesisGetResponse(response) {
5161
5863
  username: responseText(authorRecord.username, "author.username")
5162
5864
  };
5163
5865
  if (!Array.isArray(response.entities)) {
5164
- throw invalidResponse3("response must contain entities");
5866
+ throw invalidResponse4("response must contain entities");
5165
5867
  }
5166
5868
  if (response.entities.length !== base.thesis.entity_ids.length) {
5167
- throw invalidResponse3("entities must match thesis.entity_ids");
5869
+ throw invalidResponse4("entities must match thesis.entity_ids");
5168
5870
  }
5169
5871
  const entities = response.entities.map((item, index) => {
5170
5872
  if (!isRecord2(item))
5171
- throw invalidResponse3(`entities[${index}] must be an object`);
5873
+ throw invalidResponse4(`entities[${index}] must be an object`);
5172
5874
  const entity = {
5173
5875
  id: responseID(item.id, `entities[${index}].id`),
5174
5876
  ticker: responseText(item.ticker, `entities[${index}].ticker`),
@@ -5177,7 +5879,7 @@ function thesisGetResponse(response) {
5177
5879
  kind: responseText(item.kind, `entities[${index}].kind`)
5178
5880
  };
5179
5881
  if (entity.id !== base.thesis.entity_ids[index]) {
5180
- throw invalidResponse3("entities must preserve thesis.entity_ids order");
5882
+ throw invalidResponse4("entities must preserve thesis.entity_ids order");
5181
5883
  }
5182
5884
  return entity;
5183
5885
  });
@@ -5185,7 +5887,7 @@ function thesisGetResponse(response) {
5185
5887
  }
5186
5888
  function thesisSignalsResponse(response, thesisID, first) {
5187
5889
  if (!isRecord2(response) || !isRecord2(response.research) || !Array.isArray(response.entries) || response.entries.length > first) {
5188
- throw invalidResponse3("invalid Signal history response");
5890
+ throw invalidResponse4("invalid Signal history response");
5189
5891
  }
5190
5892
  const research = response.research;
5191
5893
  const status = {
@@ -5211,13 +5913,13 @@ function thesisSignalsResponse(response, thesisID, first) {
5211
5913
  );
5212
5914
  const entries = response.entries.map((raw) => {
5213
5915
  if (!isRecord2(raw) || !isRecord2(raw.signal) || !isRecord2(raw.signal.source)) {
5214
- throw invalidResponse3("entry must include a Signal and source");
5916
+ throw invalidResponse4("entry must include a Signal and source");
5215
5917
  }
5216
5918
  const signal = raw.signal;
5217
5919
  const source = signal.source;
5218
5920
  const signalID = responseID(signal.thesis_id, "signal.thesis_id");
5219
5921
  if (signalID !== thesisID)
5220
- throw invalidResponse3("Signal belongs to another Thesis");
5922
+ throw invalidResponse4("Signal belongs to another Thesis");
5221
5923
  const cursor = responseNonemptyText(raw.cursor, "entry.cursor");
5222
5924
  const mappedSource = {
5223
5925
  title: responseText(source.title, "source.title")
@@ -5250,7 +5952,7 @@ function thesisSignalsResponse(response, thesisID, first) {
5250
5952
  };
5251
5953
  if (signal.evidence_excerpt !== void 0) {
5252
5954
  if (!isRecord2(signal.evidence_excerpt))
5253
- throw invalidResponse3("invalid evidence excerpt");
5955
+ throw invalidResponse4("invalid evidence excerpt");
5254
5956
  mappedSignal.evidence_excerpt = {
5255
5957
  text: responseNonemptyText(
5256
5958
  signal.evidence_excerpt.text,
@@ -5274,19 +5976,19 @@ function thesisSignalsResponse(response, thesisID, first) {
5274
5976
  });
5275
5977
  const nextCursor2 = responseText(response.next_cursor, "next_cursor");
5276
5978
  if (nextCursor2 && nextCursor2 !== entries[entries.length - 1]?.cursor) {
5277
- throw invalidResponse3("next_cursor must match the final entry");
5979
+ throw invalidResponse4("next_cursor must match the final entry");
5278
5980
  }
5279
5981
  return { research: status, entries, next_cursor: nextCursor2 };
5280
5982
  }
5281
5983
  function responseNonnegativeInteger(value, field) {
5282
5984
  if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
5283
- throw invalidResponse3(field + " must be a nonnegative safe integer");
5985
+ throw invalidResponse4(field + " must be a nonnegative safe integer");
5284
5986
  }
5285
5987
  return value;
5286
5988
  }
5287
5989
  function responseNonemptyText(value, field) {
5288
5990
  const valueText = responseText(value, field);
5289
- if (!valueText.trim()) throw invalidResponse3(field + " must be nonempty");
5991
+ if (!valueText.trim()) throw invalidResponse4(field + " must be nonempty");
5290
5992
  return valueText;
5291
5993
  }
5292
5994
  function requireRequestID(value) {
@@ -5377,20 +6079,20 @@ function requireText2(value, field) {
5377
6079
  }
5378
6080
  function responseID(value, field) {
5379
6081
  if (typeof value === "number") {
5380
- throw invalidResponse3(
6082
+ throw invalidResponse4(
5381
6083
  `${field} must be a decimal string; numeric IDs are unsafe`
5382
6084
  );
5383
6085
  }
5384
6086
  try {
5385
6087
  return requireID(value, field);
5386
6088
  } catch {
5387
- throw invalidResponse3(`${field} must be a positive int64 decimal string`);
6089
+ throw invalidResponse4(`${field} must be a positive int64 decimal string`);
5388
6090
  }
5389
6091
  }
5390
6092
  function responseIDs(value, field) {
5391
- if (!Array.isArray(value)) throw invalidResponse3(`${field} must be an array`);
6093
+ if (!Array.isArray(value)) throw invalidResponse4(`${field} must be an array`);
5392
6094
  if (value.length > MAX_ENTITY_IDS) {
5393
- throw invalidResponse3(
6095
+ throw invalidResponse4(
5394
6096
  `${field} must contain at most ${MAX_ENTITY_IDS} IDs`
5395
6097
  );
5396
6098
  }
@@ -5400,33 +6102,33 @@ function responseText(value, field) {
5400
6102
  try {
5401
6103
  return requireText2(value, field);
5402
6104
  } catch {
5403
- throw invalidResponse3(`${field} must be valid text`);
6105
+ throw invalidResponse4(`${field} must be valid text`);
5404
6106
  }
5405
6107
  }
5406
6108
  function responseClosingNote(value) {
5407
6109
  try {
5408
6110
  return requireText2(value, "note");
5409
6111
  } catch {
5410
- throw invalidResponse3("thesis.closing_note must be valid text");
6112
+ throw invalidResponse4("thesis.closing_note must be valid text");
5411
6113
  }
5412
6114
  }
5413
6115
  function responseBoolean(value, field) {
5414
6116
  if (typeof value !== "boolean")
5415
- throw invalidResponse3(`${field} must be boolean`);
6117
+ throw invalidResponse4(`${field} must be boolean`);
5416
6118
  return value;
5417
6119
  }
5418
6120
  function responseVisibility(value) {
5419
6121
  try {
5420
6122
  return requireVisibility(value);
5421
6123
  } catch {
5422
- throw invalidResponse3("thesis.visibility must be public, private or paid");
6124
+ throw invalidResponse4("thesis.visibility must be public, private or paid");
5423
6125
  }
5424
6126
  }
5425
6127
  function responseBody(value) {
5426
6128
  try {
5427
6129
  return requireBody(value);
5428
6130
  } catch {
5429
- throw invalidResponse3(
6131
+ throw invalidResponse4(
5430
6132
  "response body must be nonblank valid text at most 65536 UTF-8 bytes"
5431
6133
  );
5432
6134
  }
@@ -5435,7 +6137,7 @@ function responseTitle(value) {
5435
6137
  try {
5436
6138
  return requireTitle(value);
5437
6139
  } catch {
5438
- throw invalidResponse3(
6140
+ throw invalidResponse4(
5439
6141
  "response title must be valid text at most 500 UTF-8 bytes"
5440
6142
  );
5441
6143
  }
@@ -5455,7 +6157,7 @@ function completeEntityStances(entityIDs, stances) {
5455
6157
  function invalidArgument(message) {
5456
6158
  return new AlvaError("INVALID_ARGUMENT", message, 400);
5457
6159
  }
5458
- function invalidResponse3(message) {
6160
+ function invalidResponse4(message) {
5459
6161
  return new AlvaError("INVALID_RESPONSE", message, 502);
5460
6162
  }
5461
6163
  function validMedia(item) {
@@ -5476,10 +6178,10 @@ async function thesisGraphql(client, query, variables) {
5476
6178
  body: { query, variables }
5477
6179
  });
5478
6180
  if (!isRecord2(response))
5479
- throw invalidResponse3("GraphQL response must be an object");
6181
+ throw invalidResponse4("GraphQL response must be an object");
5480
6182
  if (response.errors !== void 0) {
5481
6183
  if (!Array.isArray(response.errors))
5482
- throw invalidResponse3("GraphQL errors must be an array");
6184
+ throw invalidResponse4("GraphQL errors must be an array");
5483
6185
  if (response.errors.length > 0) {
5484
6186
  const messages = response.errors.flatMap(
5485
6187
  (error) => isRecord2(error) && typeof error.message === "string" ? [error.message] : []
@@ -5501,7 +6203,7 @@ async function thesisGraphql(client, query, variables) {
5501
6203
  }
5502
6204
  }
5503
6205
  if (!isRecord2(response.data))
5504
- throw invalidResponse3("GraphQL response must contain data");
6206
+ throw invalidResponse4("GraphQL response must contain data");
5505
6207
  return response.data;
5506
6208
  }
5507
6209
 
@@ -5511,7 +6213,7 @@ var CREATE_COMPANY_NEWS = `mutation CreateCompanyNews($input: CompanyNewsFeedInp
5511
6213
  createFeed(input: $input) { id producer { id } }
5512
6214
  }
5513
6215
  }`;
5514
- var GRAPHQL_STATUS_BY_CODE4 = {
6216
+ var GRAPHQL_STATUS_BY_CODE5 = {
5515
6217
  INVALID_ARGUMENT: 400,
5516
6218
  UNAUTHENTICATED: 401,
5517
6219
  PERMISSION_DENIED: 403,
@@ -5580,7 +6282,7 @@ var CompanyNewsResource = class {
5580
6282
  throw new AlvaError(
5581
6283
  code,
5582
6284
  graph.errors.map((error) => error?.message).filter(Boolean).join("; ") || "Company News creation failed",
5583
- GRAPHQL_STATUS_BY_CODE4[code] ?? 502,
6285
+ GRAPHQL_STATUS_BY_CODE5[code] ?? 502,
5584
6286
  { errors: graph.errors }
5585
6287
  );
5586
6288
  }
@@ -5706,6 +6408,7 @@ var AlvaClient = class {
5706
6408
  _notifications;
5707
6409
  _notificationPreferences;
5708
6410
  _subscriptions;
6411
+ _follows;
5709
6412
  _alerts;
5710
6413
  _channelGroupSubscriptions;
5711
6414
  _feedback;
@@ -5797,6 +6500,9 @@ var AlvaClient = class {
5797
6500
  get subscriptions() {
5798
6501
  return this._subscriptions ??= new SubscriptionsResource(this);
5799
6502
  }
6503
+ get follows() {
6504
+ return this._follows ??= new FollowsResource(this);
6505
+ }
5800
6506
  get alerts() {
5801
6507
  return this._alerts ??= new AlertsResource(this);
5802
6508
  }
@@ -5986,7 +6692,8 @@ var AlvaClient = class {
5986
6692
  throw new AlvaError(
5987
6693
  data.error.code ?? "UNKNOWN",
5988
6694
  data.error.message ?? `HTTP ${response.status}`,
5989
- response.status
6695
+ response.status,
6696
+ data.details
5990
6697
  );
5991
6698
  }
5992
6699
  } catch (e) {
@@ -6116,14 +6823,16 @@ var stripPbsvFromUrl = (targetWindow) => {
6116
6823
  };
6117
6824
  var parseBootParams = (targetWindow) => {
6118
6825
  const params = new URLSearchParams(targetWindow.location.search);
6119
- cachedToken = params.get("_pbsv");
6826
+ const boot = targetWindow;
6827
+ cachedToken = boot.__ALVA_PBSV_BOOTSTRAP__ || null;
6828
+ delete boot.__ALVA_PBSV_BOOTSTRAP__;
6829
+ if (params.has("_pbsv")) stripPbsvFromUrl(targetWindow);
6120
6830
  expectedParentOrigin = params.get("parent_origin");
6121
6831
  apiOrigin = (params.get("api_origin") || DEFAULT_API_ORIGIN).replace(
6122
6832
  /\/$/,
6123
6833
  ""
6124
6834
  );
6125
6835
  playbookIdFromBoot = playbookIdFromToken(cachedToken);
6126
- if (cachedToken) stripPbsvFromUrl(targetWindow);
6127
6836
  };
6128
6837
  var safeJson = async (response) => {
6129
6838
  try {
@@ -6449,7 +7158,7 @@ var installPlaybookRuntime = (targetWindow) => {
6449
7158
  };
6450
7159
 
6451
7160
  // src/index.ts
6452
- var VERSION = true ? "0.34.0" : "dev";
7161
+ var VERSION = true ? "0.36.0-beta.0" : "dev";
6453
7162
  export {
6454
7163
  AlertsResource,
6455
7164
  AlvaClient,
@@ -6458,6 +7167,7 @@ export {
6458
7167
  AutomationResource,
6459
7168
  CliUsageError,
6460
7169
  CompanyNewsResource,
7170
+ FollowsResource,
6461
7171
  ForYouResource,
6462
7172
  MarketsResource,
6463
7173
  PBSV_UPDATE_MESSAGE,