@alva-ai/toolkit 0.34.0-beta.0 → 0.35.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);
@@ -4661,19 +5288,19 @@ var ThesesResource = class {
4661
5288
  const viewer = isRecord2(data) ? data.viewer : void 0;
4662
5289
  const result = isRecord2(viewer) ? viewer.thesisAssetCandidates : void 0;
4663
5290
  if (!isRecord2(result) || !Array.isArray(result.mentions)) {
4664
- throw invalidResponse3("asset candidates response must contain mentions");
5291
+ throw invalidResponse4("asset candidates response must contain mentions");
4665
5292
  }
4666
5293
  const mentions = result.mentions.map((item, index) => {
4667
5294
  if (!isRecord2(item) || typeof item.quote !== "string" || typeof item.ticker !== "string" || !["RESOLVED", "AMBIGUOUS", "UNRESOLVED"].includes(
4668
5295
  item.resolution
4669
5296
  ) || !["UNKNOWN", "BULLISH", "BEARISH"].includes(item.stance) || !Array.isArray(item.candidates)) {
4670
- throw invalidResponse3(`asset mention ${index} is invalid`);
5297
+ throw invalidResponse4(`asset mention ${index} is invalid`);
4671
5298
  }
4672
5299
  const candidates = item.candidates.map((candidate) => {
4673
5300
  if (!isRecord2(candidate) || typeof candidate.ticker !== "string" || typeof candidate.name !== "string" || !["STOCK", "ETF", "CRYPTO", "INDEX"].includes(
4674
5301
  candidate.kind
4675
5302
  )) {
4676
- throw invalidResponse3(`asset mention ${index} has invalid candidate`);
5303
+ throw invalidResponse4(`asset mention ${index} has invalid candidate`);
4677
5304
  }
4678
5305
  return {
4679
5306
  entityId: responseID(
@@ -4703,7 +5330,7 @@ var ThesesResource = class {
4703
5330
  await this.client._request("GET", `/api/v1/theses/${thesisID}`)
4704
5331
  );
4705
5332
  if (response.thesis.id !== thesisID) {
4706
- throw invalidResponse3("get response must match the requested thesis");
5333
+ throw invalidResponse4("get response must match the requested thesis");
4707
5334
  }
4708
5335
  return response;
4709
5336
  }
@@ -4718,7 +5345,7 @@ var ThesesResource = class {
4718
5345
  )
4719
5346
  );
4720
5347
  if (response.thesis.id !== thesisID || response.thesis.author_version_id !== versionID) {
4721
- throw invalidResponse3(
5348
+ throw invalidResponse4(
4722
5349
  "version response must match the requested thesis and author version"
4723
5350
  );
4724
5351
  }
@@ -4741,12 +5368,12 @@ var ThesesResource = class {
4741
5368
  }
4742
5369
  );
4743
5370
  if (!isRecord2(response) || !Array.isArray(response.versions) || typeof response.next_cursor !== "string")
4744
- throw invalidResponse3("invalid Update list");
5371
+ throw invalidResponse4("invalid Update list");
4745
5372
  const versions = response.versions.map(
4746
5373
  (value) => thesisResponse({ thesis: value }).thesis
4747
5374
  );
4748
5375
  if (versions.some((version) => version.id !== thesisID))
4749
- throw invalidResponse3("Update list must match requested Thesis");
5376
+ throw invalidResponse4("Update list must match requested Thesis");
4750
5377
  return { versions, next_cursor: response.next_cursor };
4751
5378
  }
4752
5379
  /** Deletes only the selected Update; never falls back to whole-Thesis deletion. */
@@ -4768,7 +5395,7 @@ var ThesesResource = class {
4768
5395
  )
4769
5396
  );
4770
5397
  if (response.thesis.id !== thesisID)
4771
- throw invalidResponse3(
5398
+ throw invalidResponse4(
4772
5399
  "delete Update response must match requested Thesis"
4773
5400
  );
4774
5401
  return response;
@@ -4807,7 +5434,7 @@ var ThesesResource = class {
4807
5434
  })
4808
5435
  );
4809
5436
  if (response.thesis.id !== thesisID) {
4810
- throw invalidResponse3("update response must match the requested thesis");
5437
+ throw invalidResponse4("update response must match the requested thesis");
4811
5438
  }
4812
5439
  return response;
4813
5440
  }
@@ -4829,7 +5456,7 @@ var ThesesResource = class {
4829
5456
  current.thesis.entity_ids,
4830
5457
  current.thesis.entity_stances
4831
5458
  )) {
4832
- throw invalidResponse3(
5459
+ throw invalidResponse4(
4833
5460
  "archive requires one entity_stance for every Thesis entity"
4834
5461
  );
4835
5462
  }
@@ -4846,7 +5473,7 @@ var ThesesResource = class {
4846
5473
  note: params.note
4847
5474
  });
4848
5475
  if (response.thesis.id !== thesisID || response.thesis.archived !== params.archived) {
4849
- throw invalidResponse3("archive response must match the requested state");
5476
+ throw invalidResponse4("archive response must match the requested state");
4850
5477
  }
4851
5478
  return response;
4852
5479
  }
@@ -4861,15 +5488,15 @@ var ThesesResource = class {
4861
5488
  });
4862
5489
  const result = data.setThesisStarred;
4863
5490
  if (!isRecord2(result) || !isRecord2(result.stats) || !isRecord2(result.viewerState)) {
4864
- throw invalidResponse3("star response must contain stats and viewerState");
5491
+ throw invalidResponse4("star response must contain stats and viewerState");
4865
5492
  }
4866
5493
  const returnedID = responseID(result.thesisId, "thesisId");
4867
5494
  if (returnedID !== thesisID) {
4868
- throw invalidResponse3("star response must match the requested thesis");
5495
+ throw invalidResponse4("star response must match the requested thesis");
4869
5496
  }
4870
5497
  const starCount = result.stats.starCount;
4871
5498
  if (typeof starCount !== "number" || !Number.isInteger(starCount) || starCount < 0) {
4872
- throw invalidResponse3(
5499
+ throw invalidResponse4(
4873
5500
  "star response must contain a nonnegative star count"
4874
5501
  );
4875
5502
  }
@@ -4878,7 +5505,7 @@ var ThesesResource = class {
4878
5505
  "viewerState.isStarred"
4879
5506
  );
4880
5507
  if (returnedStarred !== isStarred) {
4881
- throw invalidResponse3("star response did not apply the requested state");
5508
+ throw invalidResponse4("star response did not apply the requested state");
4882
5509
  }
4883
5510
  return {
4884
5511
  thesis_id: returnedID,
@@ -4897,7 +5524,7 @@ var ThesesResource = class {
4897
5524
  });
4898
5525
  const result = data.setThesisSignalEnabled;
4899
5526
  if (!isRecord2(result) || !isRecord2(result.publication)) {
4900
- throw invalidResponse3("Signal response must contain publication");
5527
+ throw invalidResponse4("Signal response must contain publication");
4901
5528
  }
4902
5529
  const publication = result.publication;
4903
5530
  const returnedID = responseID(
@@ -4905,14 +5532,14 @@ var ThesesResource = class {
4905
5532
  "publication.playbookId"
4906
5533
  );
4907
5534
  if (returnedID !== thesisID) {
4908
- throw invalidResponse3("Signal response must match the requested thesis");
5535
+ throw invalidResponse4("Signal response must match the requested thesis");
4909
5536
  }
4910
5537
  const researchPaused = responseBoolean(
4911
5538
  publication.researchPaused,
4912
5539
  "publication.researchPaused"
4913
5540
  );
4914
5541
  if (researchPaused === enabled) {
4915
- throw invalidResponse3(
5542
+ throw invalidResponse4(
4916
5543
  "Signal response did not apply the requested state"
4917
5544
  );
4918
5545
  }
@@ -4942,7 +5569,7 @@ var ThesesResource = class {
4942
5569
  )
4943
5570
  );
4944
5571
  if (response.thesis.id !== thesisID || response.thesis.visibility !== visibility) {
4945
- throw invalidResponse3(
5572
+ throw invalidResponse4(
4946
5573
  "visibility response must match the requested thesis and visibility"
4947
5574
  );
4948
5575
  }
@@ -4973,7 +5600,7 @@ var ThesesResource = class {
4973
5600
  );
4974
5601
  if (response === void 0) return {};
4975
5602
  if (!isRecord2(response) || Object.keys(response).length !== 0) {
4976
- throw invalidResponse3("delete response must be {}");
5603
+ throw invalidResponse4("delete response must be {}");
4977
5604
  }
4978
5605
  return {};
4979
5606
  }
@@ -4989,7 +5616,7 @@ var ThesesResource = class {
4989
5616
  }
4990
5617
  );
4991
5618
  if (!isRecord2(response) || typeof response.body !== "string") {
4992
- throw invalidResponse3("rewrite response must contain a string body");
5619
+ throw invalidResponse4("rewrite response must contain a string body");
4993
5620
  }
4994
5621
  return { body: responseBody(response.body) };
4995
5622
  }
@@ -5085,7 +5712,7 @@ function updateBody(params) {
5085
5712
  }
5086
5713
  function thesisResponse(response) {
5087
5714
  if (!isRecord2(response) || !isRecord2(response.thesis)) {
5088
- throw invalidResponse3("response must contain thesis");
5715
+ throw invalidResponse4("response must contain thesis");
5089
5716
  }
5090
5717
  const thesis = response.thesis;
5091
5718
  const value = {
@@ -5110,10 +5737,10 @@ function thesisResponse(response) {
5110
5737
  };
5111
5738
  if (thesis.medias !== void 0) {
5112
5739
  if (!Array.isArray(thesis.medias) || thesis.medias.length > 20)
5113
- throw invalidResponse3("thesis.medias must contain at most 20 items");
5740
+ throw invalidResponse4("thesis.medias must contain at most 20 items");
5114
5741
  value.medias = thesis.medias.map((item) => {
5115
5742
  if (!validMedia(item))
5116
- throw invalidResponse3("thesis.medias contains invalid media");
5743
+ throw invalidResponse4("thesis.medias contains invalid media");
5117
5744
  return {
5118
5745
  type: item.type,
5119
5746
  cover_url: item.cover_url,
@@ -5130,15 +5757,15 @@ function thesisResponse(response) {
5130
5757
  value.note = responseText(thesis.note, "thesis.note");
5131
5758
  if (thesis.entity_stances !== void 0) {
5132
5759
  if (!Array.isArray(thesis.entity_stances))
5133
- throw invalidResponse3("thesis.entity_stances must be an array");
5760
+ throw invalidResponse4("thesis.entity_stances must be an array");
5134
5761
  value.entity_stances = thesis.entity_stances.map((item) => {
5135
5762
  if (!isRecord2(item))
5136
- throw invalidResponse3("thesis.entity_stances contains invalid entry");
5763
+ throw invalidResponse4("thesis.entity_stances contains invalid entry");
5137
5764
  const entityID = responseID(item.entity_id, "entity_stances.entity_id");
5138
5765
  if (!value.entity_ids.includes(entityID))
5139
- throw invalidResponse3("entity stance must reference a thesis entity");
5766
+ throw invalidResponse4("entity stance must reference a thesis entity");
5140
5767
  if (!["unknown", "bullish", "bearish"].includes(item.stance))
5141
- throw invalidResponse3("thesis.entity_stances contains invalid stance");
5768
+ throw invalidResponse4("thesis.entity_stances contains invalid stance");
5142
5769
  return { entity_id: entityID, stance: item.stance };
5143
5770
  });
5144
5771
  }
@@ -5147,7 +5774,7 @@ function thesisResponse(response) {
5147
5774
  function thesisGetResponse(response) {
5148
5775
  const base = thesisResponse(response);
5149
5776
  if (!isRecord2(response) || !isRecord2(response.author)) {
5150
- throw invalidResponse3("response must contain author");
5777
+ throw invalidResponse4("response must contain author");
5151
5778
  }
5152
5779
  const authorRecord = response.author;
5153
5780
  const author = {
@@ -5161,14 +5788,14 @@ function thesisGetResponse(response) {
5161
5788
  username: responseText(authorRecord.username, "author.username")
5162
5789
  };
5163
5790
  if (!Array.isArray(response.entities)) {
5164
- throw invalidResponse3("response must contain entities");
5791
+ throw invalidResponse4("response must contain entities");
5165
5792
  }
5166
5793
  if (response.entities.length !== base.thesis.entity_ids.length) {
5167
- throw invalidResponse3("entities must match thesis.entity_ids");
5794
+ throw invalidResponse4("entities must match thesis.entity_ids");
5168
5795
  }
5169
5796
  const entities = response.entities.map((item, index) => {
5170
5797
  if (!isRecord2(item))
5171
- throw invalidResponse3(`entities[${index}] must be an object`);
5798
+ throw invalidResponse4(`entities[${index}] must be an object`);
5172
5799
  const entity = {
5173
5800
  id: responseID(item.id, `entities[${index}].id`),
5174
5801
  ticker: responseText(item.ticker, `entities[${index}].ticker`),
@@ -5177,7 +5804,7 @@ function thesisGetResponse(response) {
5177
5804
  kind: responseText(item.kind, `entities[${index}].kind`)
5178
5805
  };
5179
5806
  if (entity.id !== base.thesis.entity_ids[index]) {
5180
- throw invalidResponse3("entities must preserve thesis.entity_ids order");
5807
+ throw invalidResponse4("entities must preserve thesis.entity_ids order");
5181
5808
  }
5182
5809
  return entity;
5183
5810
  });
@@ -5185,7 +5812,7 @@ function thesisGetResponse(response) {
5185
5812
  }
5186
5813
  function thesisSignalsResponse(response, thesisID, first) {
5187
5814
  if (!isRecord2(response) || !isRecord2(response.research) || !Array.isArray(response.entries) || response.entries.length > first) {
5188
- throw invalidResponse3("invalid Signal history response");
5815
+ throw invalidResponse4("invalid Signal history response");
5189
5816
  }
5190
5817
  const research = response.research;
5191
5818
  const status = {
@@ -5211,13 +5838,13 @@ function thesisSignalsResponse(response, thesisID, first) {
5211
5838
  );
5212
5839
  const entries = response.entries.map((raw) => {
5213
5840
  if (!isRecord2(raw) || !isRecord2(raw.signal) || !isRecord2(raw.signal.source)) {
5214
- throw invalidResponse3("entry must include a Signal and source");
5841
+ throw invalidResponse4("entry must include a Signal and source");
5215
5842
  }
5216
5843
  const signal = raw.signal;
5217
5844
  const source = signal.source;
5218
5845
  const signalID = responseID(signal.thesis_id, "signal.thesis_id");
5219
5846
  if (signalID !== thesisID)
5220
- throw invalidResponse3("Signal belongs to another Thesis");
5847
+ throw invalidResponse4("Signal belongs to another Thesis");
5221
5848
  const cursor = responseNonemptyText(raw.cursor, "entry.cursor");
5222
5849
  const mappedSource = {
5223
5850
  title: responseText(source.title, "source.title")
@@ -5250,7 +5877,7 @@ function thesisSignalsResponse(response, thesisID, first) {
5250
5877
  };
5251
5878
  if (signal.evidence_excerpt !== void 0) {
5252
5879
  if (!isRecord2(signal.evidence_excerpt))
5253
- throw invalidResponse3("invalid evidence excerpt");
5880
+ throw invalidResponse4("invalid evidence excerpt");
5254
5881
  mappedSignal.evidence_excerpt = {
5255
5882
  text: responseNonemptyText(
5256
5883
  signal.evidence_excerpt.text,
@@ -5274,19 +5901,19 @@ function thesisSignalsResponse(response, thesisID, first) {
5274
5901
  });
5275
5902
  const nextCursor2 = responseText(response.next_cursor, "next_cursor");
5276
5903
  if (nextCursor2 && nextCursor2 !== entries[entries.length - 1]?.cursor) {
5277
- throw invalidResponse3("next_cursor must match the final entry");
5904
+ throw invalidResponse4("next_cursor must match the final entry");
5278
5905
  }
5279
5906
  return { research: status, entries, next_cursor: nextCursor2 };
5280
5907
  }
5281
5908
  function responseNonnegativeInteger(value, field) {
5282
5909
  if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
5283
- throw invalidResponse3(field + " must be a nonnegative safe integer");
5910
+ throw invalidResponse4(field + " must be a nonnegative safe integer");
5284
5911
  }
5285
5912
  return value;
5286
5913
  }
5287
5914
  function responseNonemptyText(value, field) {
5288
5915
  const valueText = responseText(value, field);
5289
- if (!valueText.trim()) throw invalidResponse3(field + " must be nonempty");
5916
+ if (!valueText.trim()) throw invalidResponse4(field + " must be nonempty");
5290
5917
  return valueText;
5291
5918
  }
5292
5919
  function requireRequestID(value) {
@@ -5377,20 +6004,20 @@ function requireText2(value, field) {
5377
6004
  }
5378
6005
  function responseID(value, field) {
5379
6006
  if (typeof value === "number") {
5380
- throw invalidResponse3(
6007
+ throw invalidResponse4(
5381
6008
  `${field} must be a decimal string; numeric IDs are unsafe`
5382
6009
  );
5383
6010
  }
5384
6011
  try {
5385
6012
  return requireID(value, field);
5386
6013
  } catch {
5387
- throw invalidResponse3(`${field} must be a positive int64 decimal string`);
6014
+ throw invalidResponse4(`${field} must be a positive int64 decimal string`);
5388
6015
  }
5389
6016
  }
5390
6017
  function responseIDs(value, field) {
5391
- if (!Array.isArray(value)) throw invalidResponse3(`${field} must be an array`);
6018
+ if (!Array.isArray(value)) throw invalidResponse4(`${field} must be an array`);
5392
6019
  if (value.length > MAX_ENTITY_IDS) {
5393
- throw invalidResponse3(
6020
+ throw invalidResponse4(
5394
6021
  `${field} must contain at most ${MAX_ENTITY_IDS} IDs`
5395
6022
  );
5396
6023
  }
@@ -5400,33 +6027,33 @@ function responseText(value, field) {
5400
6027
  try {
5401
6028
  return requireText2(value, field);
5402
6029
  } catch {
5403
- throw invalidResponse3(`${field} must be valid text`);
6030
+ throw invalidResponse4(`${field} must be valid text`);
5404
6031
  }
5405
6032
  }
5406
6033
  function responseClosingNote(value) {
5407
6034
  try {
5408
6035
  return requireText2(value, "note");
5409
6036
  } catch {
5410
- throw invalidResponse3("thesis.closing_note must be valid text");
6037
+ throw invalidResponse4("thesis.closing_note must be valid text");
5411
6038
  }
5412
6039
  }
5413
6040
  function responseBoolean(value, field) {
5414
6041
  if (typeof value !== "boolean")
5415
- throw invalidResponse3(`${field} must be boolean`);
6042
+ throw invalidResponse4(`${field} must be boolean`);
5416
6043
  return value;
5417
6044
  }
5418
6045
  function responseVisibility(value) {
5419
6046
  try {
5420
6047
  return requireVisibility(value);
5421
6048
  } catch {
5422
- throw invalidResponse3("thesis.visibility must be public, private or paid");
6049
+ throw invalidResponse4("thesis.visibility must be public, private or paid");
5423
6050
  }
5424
6051
  }
5425
6052
  function responseBody(value) {
5426
6053
  try {
5427
6054
  return requireBody(value);
5428
6055
  } catch {
5429
- throw invalidResponse3(
6056
+ throw invalidResponse4(
5430
6057
  "response body must be nonblank valid text at most 65536 UTF-8 bytes"
5431
6058
  );
5432
6059
  }
@@ -5435,7 +6062,7 @@ function responseTitle(value) {
5435
6062
  try {
5436
6063
  return requireTitle(value);
5437
6064
  } catch {
5438
- throw invalidResponse3(
6065
+ throw invalidResponse4(
5439
6066
  "response title must be valid text at most 500 UTF-8 bytes"
5440
6067
  );
5441
6068
  }
@@ -5455,7 +6082,7 @@ function completeEntityStances(entityIDs, stances) {
5455
6082
  function invalidArgument(message) {
5456
6083
  return new AlvaError("INVALID_ARGUMENT", message, 400);
5457
6084
  }
5458
- function invalidResponse3(message) {
6085
+ function invalidResponse4(message) {
5459
6086
  return new AlvaError("INVALID_RESPONSE", message, 502);
5460
6087
  }
5461
6088
  function validMedia(item) {
@@ -5476,10 +6103,10 @@ async function thesisGraphql(client, query, variables) {
5476
6103
  body: { query, variables }
5477
6104
  });
5478
6105
  if (!isRecord2(response))
5479
- throw invalidResponse3("GraphQL response must be an object");
6106
+ throw invalidResponse4("GraphQL response must be an object");
5480
6107
  if (response.errors !== void 0) {
5481
6108
  if (!Array.isArray(response.errors))
5482
- throw invalidResponse3("GraphQL errors must be an array");
6109
+ throw invalidResponse4("GraphQL errors must be an array");
5483
6110
  if (response.errors.length > 0) {
5484
6111
  const messages = response.errors.flatMap(
5485
6112
  (error) => isRecord2(error) && typeof error.message === "string" ? [error.message] : []
@@ -5501,7 +6128,7 @@ async function thesisGraphql(client, query, variables) {
5501
6128
  }
5502
6129
  }
5503
6130
  if (!isRecord2(response.data))
5504
- throw invalidResponse3("GraphQL response must contain data");
6131
+ throw invalidResponse4("GraphQL response must contain data");
5505
6132
  return response.data;
5506
6133
  }
5507
6134
 
@@ -5511,7 +6138,7 @@ var CREATE_COMPANY_NEWS = `mutation CreateCompanyNews($input: CompanyNewsFeedInp
5511
6138
  createFeed(input: $input) { id producer { id } }
5512
6139
  }
5513
6140
  }`;
5514
- var GRAPHQL_STATUS_BY_CODE4 = {
6141
+ var GRAPHQL_STATUS_BY_CODE5 = {
5515
6142
  INVALID_ARGUMENT: 400,
5516
6143
  UNAUTHENTICATED: 401,
5517
6144
  PERMISSION_DENIED: 403,
@@ -5580,7 +6207,7 @@ var CompanyNewsResource = class {
5580
6207
  throw new AlvaError(
5581
6208
  code,
5582
6209
  graph.errors.map((error) => error?.message).filter(Boolean).join("; ") || "Company News creation failed",
5583
- GRAPHQL_STATUS_BY_CODE4[code] ?? 502,
6210
+ GRAPHQL_STATUS_BY_CODE5[code] ?? 502,
5584
6211
  { errors: graph.errors }
5585
6212
  );
5586
6213
  }
@@ -5706,6 +6333,7 @@ var AlvaClient = class {
5706
6333
  _notifications;
5707
6334
  _notificationPreferences;
5708
6335
  _subscriptions;
6336
+ _follows;
5709
6337
  _alerts;
5710
6338
  _channelGroupSubscriptions;
5711
6339
  _feedback;
@@ -5797,6 +6425,9 @@ var AlvaClient = class {
5797
6425
  get subscriptions() {
5798
6426
  return this._subscriptions ??= new SubscriptionsResource(this);
5799
6427
  }
6428
+ get follows() {
6429
+ return this._follows ??= new FollowsResource(this);
6430
+ }
5800
6431
  get alerts() {
5801
6432
  return this._alerts ??= new AlertsResource(this);
5802
6433
  }
@@ -6449,7 +7080,7 @@ var installPlaybookRuntime = (targetWindow) => {
6449
7080
  };
6450
7081
 
6451
7082
  // src/index.ts
6452
- var VERSION = true ? "0.34.0-beta.0" : "dev";
7083
+ var VERSION = true ? "0.35.0" : "dev";
6453
7084
  export {
6454
7085
  AlertsResource,
6455
7086
  AlvaClient,
@@ -6458,6 +7089,7 @@ export {
6458
7089
  AutomationResource,
6459
7090
  CliUsageError,
6460
7091
  CompanyNewsResource,
7092
+ FollowsResource,
6461
7093
  ForYouResource,
6462
7094
  MarketsResource,
6463
7095
  PBSV_UPDATE_MESSAGE,