@alva-ai/toolkit 0.38.0-beta.0 → 0.38.0-beta.2

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.
@@ -2106,6 +2106,25 @@ interface ThesisPositionReturn {
2106
2106
  end: 'PENDING' | 'NEXT_UPDATE' | 'LATEST';
2107
2107
  positionReturn: number;
2108
2108
  currency: string;
2109
+ /** The Update's target share of this position; equal shares when it states none. */
2110
+ weight: number;
2111
+ }
2112
+ /** One long or short of a target portfolio. */
2113
+ interface ThesisHolding {
2114
+ entityId: string;
2115
+ symbol: string;
2116
+ direction: 'BULLISH' | 'BEARISH';
2117
+ /** Target share as a fraction; equal shares when the Update states none. */
2118
+ weight: number;
2119
+ }
2120
+ /**
2121
+ * The current target portfolio: the shares the latest Update set, not drifted
2122
+ * with prices. Holdings and cash sum to 1; cash is 1 with no direction or
2123
+ * while archived.
2124
+ */
2125
+ interface ThesisAllocation {
2126
+ holdings: ThesisHolding[];
2127
+ cash: number;
2109
2128
  }
2110
2129
  /** One Update on the return chart. */
2111
2130
  interface ThesisUpdateReturn {
@@ -2124,6 +2143,8 @@ interface ThesisReturnValue {
2124
2143
  stale: boolean;
2125
2144
  computedAtMs: number;
2126
2145
  updates: ThesisUpdateReturn[];
2146
+ /** The current target portfolio, with detail; null on card reads. */
2147
+ allocation: ThesisAllocation | null;
2127
2148
  }
2128
2149
  interface ThesisReturnResult {
2129
2150
  playbookId: string;
@@ -2159,6 +2180,14 @@ interface ThesisEntityStance {
2159
2180
  stance: ThesisAssetStance;
2160
2181
  /** Full direction in responses; stance reports none as unknown there. */
2161
2182
  direction?: ThesisAssetStance;
2183
+ /**
2184
+ * The Update's share of this long or short as a fraction (0.4 is 40%), with
2185
+ * at most four decimals. On create and update give one to every bullish or
2186
+ * bearish entity, and the rest is cash, or to none, and the shares follow
2187
+ * the default rules and what the body says. Responses carry it only on an
2188
+ * Update published with weights.
2189
+ */
2190
+ weight?: number;
2162
2191
  }
2163
2192
  /** GraphQL direction, including NONE. */
2164
2193
  type ThesisDirection = 'UNKNOWN' | 'BULLISH' | 'BEARISH' | 'NONE';
@@ -2236,6 +2265,10 @@ interface Thesis {
2236
2265
  interface ThesisResponse {
2237
2266
  thesis: Thesis;
2238
2267
  }
2268
+ /** A created Thesis and its clickable web url, e.g. `https://alva.ai/thesis/123`. */
2269
+ interface ThesisCreateResponse extends ThesisResponse {
2270
+ url: string;
2271
+ }
2239
2272
  interface ThesisAuthor {
2240
2273
  id: ThesisID;
2241
2274
  kind: string;
@@ -2312,6 +2345,25 @@ interface CreateThesisParams {
2312
2345
  visibility?: 'public' | 'private';
2313
2346
  /** Thesis return switch; omitted keeps the default (on). */
2314
2347
  track_return?: boolean;
2348
+ /** Which Signals the Thesis shows; omitted shows every Signal. */
2349
+ signal_preferences?: ThesisSignalPreferences;
2350
+ }
2351
+ /** What a Thesis Signal is about. */
2352
+ type ThesisSignalKind = 'fundamentals' | 'macro' | 'technicals' | 'commentary';
2353
+ /** The least important Signals a Thesis shows; notable means notable and major. */
2354
+ type ThesisSignalMinImportance = 'all' | 'notable' | 'major';
2355
+ /**
2356
+ * Which Signals a Thesis shows to every reader, chosen by its author. Signals
2357
+ * without a label always show.
2358
+ */
2359
+ interface ThesisSignalPreferences {
2360
+ kinds: ThesisSignalKind[];
2361
+ min_importance: ThesisSignalMinImportance;
2362
+ }
2363
+ interface ThesisSignalPreferencesResponse {
2364
+ /** The Thesis read or written; null for the caller's last choice. */
2365
+ thesis_id: ThesisID | null;
2366
+ preferences: ThesisSignalPreferences;
2315
2367
  }
2316
2368
  interface UpdateThesisParams {
2317
2369
  /** Full media replacement; pass current medias for a text-only update. */
@@ -2379,7 +2431,7 @@ declare class ThesesResource {
2379
2431
  * things the Thesis depends on, or that would show it right or wrong.
2380
2432
  */
2381
2433
  watchpoints(id: ThesisID): Promise<ThesisWatchpointsResult>;
2382
- create(params: CreateThesisParams): Promise<ThesisResponse>;
2434
+ create(params: CreateThesisParams): Promise<ThesisCreateResponse>;
2383
2435
  get(id: ThesisID): Promise<ThesisGetResponse>;
2384
2436
  getVersion(id: ThesisID, authorVersionID: ThesisID): Promise<ThesisResponse>;
2385
2437
  /** Lists reader-visible Updates, with editorial revisions folded together. */
@@ -2399,6 +2451,17 @@ declare class ThesesResource {
2399
2451
  */
2400
2452
  setArchived(id: ThesisID, params: SetThesisArchivedParams): Promise<ThesisResponse>;
2401
2453
  setStarred(id: ThesisID, isStarred: boolean): Promise<ThesisStarredResponse>;
2454
+ /**
2455
+ * Reads which Signals one of the caller's Theses shows: its setting, or every
2456
+ * kind and `all` when it has none. Without an id, reads the setting the caller
2457
+ * last saved, which prefills a new Thesis. Only the Thesis's author can read it.
2458
+ */
2459
+ getSignalPreferences(id?: ThesisID): Promise<ThesisSignalPreferencesResponse>;
2460
+ /**
2461
+ * Replaces which Signals one of the caller's Theses shows, for every reader,
2462
+ * and records it as the caller's last choice. Author only.
2463
+ */
2464
+ setSignalPreferences(id: ThesisID, preferences: ThesisSignalPreferences): Promise<ThesisSignalPreferencesResponse>;
2402
2465
  setSignalEnabled(id: ThesisID, enabled: boolean): Promise<ThesisSignalEnabledResponse>;
2403
2466
  setVisibility(id: ThesisID, params: SetThesisVisibilityParams): Promise<ThesisResponse>;
2404
2467
  rewrite(params: RewriteThesisParams): Promise<RewriteThesisResponse>;
@@ -2512,12 +2575,10 @@ interface FollowingThesesParams {
2512
2575
  first?: number;
2513
2576
  }
2514
2577
  /** The author of a Thesis in the following feed. */
2578
+ /** The followed user who wrote a Thesis Update. Persons cannot be followed. */
2515
2579
  interface FollowingThesisAuthor {
2516
- kind: 'user' | 'person';
2517
- /** Set for a user. */
2518
- username?: string;
2519
- /** Set for a person. */
2520
- slug?: string;
2580
+ kind: 'user';
2581
+ username: string;
2521
2582
  display_name: string;
2522
2583
  }
2523
2584
  interface FollowingThesisItem {
package/dist/dispatch.js CHANGED
@@ -6065,7 +6065,9 @@ var EMBEDDED_COMMAND_DEFINITIONS = [
6065
6065
  "entity-stances",
6066
6066
  "tickers",
6067
6067
  "visibility",
6068
- "track-return"
6068
+ "track-return",
6069
+ "signal-kinds",
6070
+ "signal-min-importance"
6069
6071
  ]
6070
6072
  }),
6071
6073
  route("thesis asset-candidates", "thesis asset-candidates", {
@@ -6113,6 +6115,12 @@ var EMBEDDED_COMMAND_DEFINITIONS = [
6113
6115
  route("thesis set-signal-enabled", "thesis set-signal-enabled", {
6114
6116
  values: ["id", "enabled"]
6115
6117
  }),
6118
+ route("thesis signal-preferences get", "thesis signal-preferences get", {
6119
+ values: ["id"]
6120
+ }),
6121
+ route("thesis signal-preferences set", "thesis signal-preferences set", {
6122
+ values: ["id", "kinds", "min-importance"]
6123
+ }),
6116
6124
  route("thesis update", "thesis update", {
6117
6125
  values: [
6118
6126
  "id",
@@ -6673,7 +6681,7 @@ Examples:
6673
6681
  alva for-you theses --cursor '<nextCursor>'`,
6674
6682
  thesis: `Usage: alva thesis <subcommand> [options]
6675
6683
 
6676
- Subcommands: list, related, asset-candidates, create, get, version get, signals, watchpoints, set-visibility, archive, star, unstar, set-signal-enabled, update, rewrite.
6684
+ Subcommands: list, related, asset-candidates, create, get, version get, signals, watchpoints, return, set-visibility, archive, star, unstar, set-signal-enabled, signal-preferences get|set, update, rewrite.
6677
6685
 
6678
6686
  list --person <slug> | --person-name <name> | --user <username>
6679
6687
  | --ticker <ticker> | --entity-id <id>
@@ -6694,13 +6702,26 @@ directions without publishing. For known tickers, add --entity-ids <id,id>
6694
6702
  --no-discovery (and --thesis-id <id> for an Update): it skips ticker discovery
6695
6703
  and returns returnPreview, the directions publishing would store, whether to ask
6696
6704
  the Thesis return switch (askSwitch) and whether the draft would be rejected
6697
- (lastLegRemoved). Publish with create/update --entity-ids <id,id> and
6705
+ (lastLegRemoved). UNRESOLVED or UNKNOWN is an answer, not an error: the text
6706
+ names no catalog asset or no clear direction. Publish with create/update --entity-ids <id,id> and
6698
6707
  --entity-stances <json> equal to returnPreview.directions, lowercased:
6699
6708
  --entity-stances '[{"entity_id":"745337","stance":"bearish"}]'. Valid stances:
6700
- unknown, bullish, bearish, none. --track-return false turns the Thesis return
6709
+ unknown, bullish, bearish, none. An optional "weight" (a fraction, 0.4 is 40%,
6710
+ at most four decimals) sets that long or short's share and the rest is cash:
6711
+ give one to every bullish or bearish entity or to none; without weights the
6712
+ shares follow the default rules and what the body says, and get shows weight
6713
+ only on an Update published with weights. --track-return false turns the Thesis return
6701
6714
  off for good; it is accepted only while the switch is UNSET.
6715
+ create --signal-kinds <kind,kind> --signal-min-importance all|notable|major
6716
+ limits which Signals the new Thesis shows (omit both: every Signal). Kinds:
6717
+ fundamentals, macro, technicals, commentary.
6718
+ signal-preferences get [--id <id>] reads which Signals your Thesis shows
6719
+ (without --id: your last saved setting); signal-preferences set --id <id>
6720
+ [--kinds <kind,kind>] [--min-importance all|notable|major] changes only what is
6721
+ given, for every reader of that Thesis. Author only.
6702
6722
  return --id <id> [--detail] reads the Thesis return (fractions; --detail adds
6703
- each Update's positions).
6723
+ each Update's positions with their weight and the allocation: the current
6724
+ target shares and cash, not drifted with prices).
6704
6725
  watchpoints --id <thesis-id> lists every watchpoint of the Thesis (the same id
6705
6726
  as get and signals). A watchpoint is one thing the Thesis depends on, or that
6706
6727
  would show it right or wrong; Alva's Signal research checks each new source
@@ -6716,7 +6737,9 @@ author's only through an Update the author asks for.
6716
6737
  Embedded thesis commands accept literal --body text only; file and stdin body
6717
6738
  transports are intentionally unavailable because this runtime has no verified
6718
6739
  local filesystem or stdin adapter. Rewrite accepts --mode reformat|shorten|enrich;
6719
- only omission defaults to canonical reformat, which is sent to the API. Create defaults --visibility to public.
6740
+ only omission defaults to canonical reformat, which is sent to the API. Create
6741
+ and update require --visibility public|private explicitly; create returns the
6742
+ Thesis's web url.
6720
6743
  Set-visibility changes current access without publishing a new author version.
6721
6744
  It requires --id and --visibility public|private and never uses a request ID.
6722
6745
  Archive preserves the current Thesis fields and uses the current author version
@@ -7331,7 +7354,27 @@ function argument(message) {
7331
7354
  return new AlvaError("INVALID_ARGUMENT", message, 400);
7332
7355
  }
7333
7356
 
7357
+ // src/resources/webOrigin.ts
7358
+ function webOriginFromApiBase(apiBaseUrl) {
7359
+ try {
7360
+ const host = new URL(apiBaseUrl).hostname;
7361
+ const match = /^api-llm\.([a-z0-9-]+)\.alva\.ai$/i.exec(host);
7362
+ if (match) {
7363
+ const env = match[1].toLowerCase();
7364
+ return env === "prd" ? "https://alva.ai" : `https://${env}.alva.ai`;
7365
+ }
7366
+ } catch {
7367
+ }
7368
+ return "https://alva.ai";
7369
+ }
7370
+
7334
7371
  // src/resources/theses.ts
7372
+ var THESIS_SIGNAL_KINDS = [
7373
+ "fundamentals",
7374
+ "macro",
7375
+ "technicals",
7376
+ "commentary"
7377
+ ];
7335
7378
  var encoder = new TextEncoder();
7336
7379
 
7337
7380
  // src/resources/follows.ts
@@ -7852,7 +7895,9 @@ var COMMAND_DEFINITIONS = [
7852
7895
  "entity-stances",
7853
7896
  "tickers",
7854
7897
  "visibility",
7855
- "track-return"
7898
+ "track-return",
7899
+ "signal-kinds",
7900
+ "signal-min-importance"
7856
7901
  ],
7857
7902
  booleans: ["body-stdin"]
7858
7903
  }),
@@ -7886,6 +7931,10 @@ var COMMAND_DEFINITIONS = [
7886
7931
  command("thesis star", { values: ["id"] }),
7887
7932
  command("thesis unstar", { values: ["id"] }),
7888
7933
  command("thesis set-signal-enabled", { values: ["id", "enabled"] }),
7934
+ command("thesis signal-preferences get", { values: ["id"] }),
7935
+ command("thesis signal-preferences set", {
7936
+ values: ["id", "kinds", "min-importance"]
7937
+ }),
7889
7938
  command("thesis update", {
7890
7939
  values: [
7891
7940
  "id",
@@ -8404,18 +8453,6 @@ var PLAYBOOK_VISIBILITIES = [
8404
8453
  "paid"
8405
8454
  ];
8406
8455
  var OWNED_PLAYBOOK_FILTERS = ["draft", "running", "paused"];
8407
- function webOriginFromApiBase(apiBaseUrl) {
8408
- try {
8409
- const host = new URL(apiBaseUrl).hostname;
8410
- const match = /^api-llm\.([a-z0-9-]+)\.alva\.ai$/i.exec(host);
8411
- if (match) {
8412
- const env = match[1].toLowerCase();
8413
- return env === "prd" ? "https://alva.ai" : `https://${env}.alva.ai`;
8414
- }
8415
- } catch {
8416
- }
8417
- return "https://alva.ai";
8418
- }
8419
8456
 
8420
8457
  // src/cli/playbooksFormat.ts
8421
8458
  var MAX_DESC = 200;
@@ -12045,7 +12082,7 @@ function formatTradingPairResolved(result) {
12045
12082
  }
12046
12083
 
12047
12084
  // src/cli/dispatch.ts
12048
- var CLI_VERSION = true ? "0.38.0-beta.0" : "dev";
12085
+ var CLI_VERSION = true ? "0.38.0-beta.2" : "dev";
12049
12086
  var DEFAULT_RUN_TIMEOUT_MS = 6e5;
12050
12087
  var RUN_TIMEOUT_ENV = "ALVA_RUN_TIMEOUT_MS";
12051
12088
  var GLOBAL_VALUE_FLAGS = Object.entries(GLOBAL_FLAG_DEFINITIONS).filter(([, kind]) => kind === "value").map(([name]) => `--${name}`);
@@ -13474,6 +13511,7 @@ Create and update never rewrite text automatically.
13474
13511
 
13475
13512
  Subcommands:
13476
13513
  create Create a thesis
13514
+ asset-candidates Read catalog IDs and the directions publishing would store, without publishing
13477
13515
  list Read theses by author or market entity
13478
13516
  related Read related current publications
13479
13517
  get Get one thesis
@@ -13481,11 +13519,13 @@ Subcommands:
13481
13519
  version list List visible Updates with editorial revisions folded together
13482
13520
  signals Read published Signal history
13483
13521
  watchpoints List a Thesis's current watchpoints
13522
+ return Read the Thesis return
13484
13523
  set-visibility Change current access without publishing a version
13485
13524
  archive Archive the current author version
13486
13525
  star Add the Thesis to your bookmarks
13487
13526
  unstar Remove the Thesis from your bookmarks
13488
13527
  set-signal-enabled Enable or disable managed Signal research
13528
+ signal-preferences get|set Read or change which Signals your Thesis shows
13489
13529
  update Publish a new Update replacing body, title, entities, visibility (all sent in full);
13490
13530
  with --archived false it also unarchives the Thesis
13491
13531
  rewrite Explicitly request a candidate body rewrite; never called by another command
@@ -13498,11 +13538,14 @@ Body input (create, update, rewrite): choose exactly one:
13498
13538
  Create and update require --request-id: a caller-supplied non-zero UUID. The
13499
13539
  toolkit does not generate or retry request IDs. If a response is ambiguous
13500
13540
  after a write, reuse the same request ID only after resolving that ambiguity with
13501
- the backend; do not send a fresh ID. Create defaults --visibility to public.
13502
- Update requires --visibility explicitly so it cannot inadvertently publish.
13541
+ the backend; do not send a fresh ID. Create and update require --visibility
13542
+ explicitly so neither can publish by accident. Create returns the Thesis's web
13543
+ url.
13503
13544
 
13504
13545
  Other flags:
13505
- create --request-id <uuid> --body ... [--images <json-array-of-https-urls>] [--title <text>] [--tickers <ticker,ticker>] [--entity-ids <id,id>] [--entity-stances <json>] [--visibility <value>] [--track-return true|false]
13546
+ create --request-id <uuid> --body ... [--images <json-array-of-https-urls>] [--title <text>] [--tickers <ticker,ticker>] [--entity-ids <id,id>] [--entity-stances <json>] --visibility public|private [--track-return true|false] [--signal-kinds <kind,kind>] [--signal-min-importance all|notable|major]
13547
+ Signals: omit both to show every Signal. Kinds: fundamentals, macro,
13548
+ technicals, commentary; with only one flag the other keeps its default.
13506
13549
  Images: public creation only, at most 20 in display order. Upload selected files
13507
13550
  with the existing host upload tool after publication confirmation. Private
13508
13551
  images and local/ALFS paths are not supported; this flag does not upload.
@@ -13524,6 +13567,8 @@ Other flags:
13524
13567
  --no-discovery only classifies --entity-ids (no ticker discovery) and
13525
13568
  returns returnPreview: the directions publishing would store, the return
13526
13569
  switch (askSwitch) and lastLegRemoved. --thesis-id seeds an Update.
13570
+ A mention resolved UNRESOLVED or a direction UNKNOWN is an answer, not
13571
+ an error: the text names no catalog asset or no clear direction.
13527
13572
  return --id <id> [--detail] the Thesis return; --detail adds each Update's positions
13528
13573
  get --id <signed-int64-decimal>
13529
13574
  version get --id <signed-int64-decimal> --author-version-id <signed-int64-decimal>
@@ -13543,6 +13588,13 @@ Other flags:
13543
13588
  archive --id <id> --request-id <uuid> [--note <text>]
13544
13589
  star|unstar --id <id>
13545
13590
  set-signal-enabled --id <id> --enabled true|false
13591
+ signal-preferences get [--id <id>]
13592
+ Which Signals your Thesis shows to every reader: {thesis_id, preferences:
13593
+ {kinds, min_importance}}. Without --id: the setting you last saved, which
13594
+ prefills a new Thesis. Only the author can read or set it.
13595
+ signal-preferences set --id <id> [--kinds <kind,kind>] [--min-importance all|notable|major]
13596
+ Changes only what is given. Applies to every reader, the Thesis's
13597
+ deliveries and, from its next daily run, its Overview.
13546
13598
 
13547
13599
  Maintenance behavior:
13548
13600
  archive reads the current Thesis first, preserves its body, title,
@@ -13582,7 +13634,7 @@ valid Unicode, and at most 65536 UTF-8 bytes; title is optional and at most
13582
13634
  500 UTF-8 bytes. Text is passed without trimming or newline conversion.
13583
13635
 
13584
13636
  Examples:
13585
- alva thesis create --request-id 123e4567-e89b-42d3-a456-426614174000 --body $'line one\\r\\nline two'
13637
+ alva thesis create --request-id 123e4567-e89b-42d3-a456-426614174000 --body $'line one\\r\\nline two' --visibility private
13586
13638
  alva thesis set-visibility --id 9223372036854775807 --visibility private
13587
13639
  alva thesis update --id 9223372036854775807 --request-id 123e4567-e89b-42d3-a456-426614174000 --expected-author-version-id 9223372036854775806 --body-file ./thesis.md --visibility private
13588
13640
  printf '%s' 'Draft body' | alva thesis rewrite --body-stdin --mode shorten`
@@ -14438,6 +14490,22 @@ function thesisImages(flags) {
14438
14490
  "thesis"
14439
14491
  );
14440
14492
  }
14493
+ function thesisSignalKindList(raw, flag) {
14494
+ const kinds = raw.split(",").map((kind) => kind.trim());
14495
+ if (kinds.some((kind) => kind === "")) {
14496
+ throw new CliUsageError(`${flag} must not contain empty kinds`, "thesis");
14497
+ }
14498
+ return kinds;
14499
+ }
14500
+ function thesisCreateSignalPreferences(flags) {
14501
+ const kinds = flags["signal-kinds"];
14502
+ const minImportance = flags["signal-min-importance"];
14503
+ if (kinds === void 0 && minImportance === void 0) return void 0;
14504
+ return {
14505
+ kinds: kinds === void 0 ? [...THESIS_SIGNAL_KINDS] : thesisSignalKindList(kinds, "--signal-kinds"),
14506
+ min_importance: minImportance ?? "all"
14507
+ };
14508
+ }
14441
14509
  function thesisTrackReturn(flags, command2) {
14442
14510
  const raw = flags["track-return"];
14443
14511
  if (raw === void 0) return void 0;
@@ -15111,8 +15179,11 @@ async function executeParsedCommand(client, parsedCommand, meta, deps) {
15111
15179
  entity_ids: thesisEntityIDs(flags),
15112
15180
  entity_stances: thesisEntityStances(flags),
15113
15181
  tickers: thesisTickers(flags),
15114
- visibility: flags.visibility === void 0 ? "public" : thesisCreateVisibility(flags.visibility),
15115
- track_return: thesisTrackReturn(flags, "thesis create")
15182
+ visibility: thesisCreateVisibility(
15183
+ requireFlag(flags, "visibility", "thesis create")
15184
+ ),
15185
+ track_return: thesisTrackReturn(flags, "thesis create"),
15186
+ signal_preferences: thesisCreateSignalPreferences(flags)
15116
15187
  });
15117
15188
  case "asset-candidates":
15118
15189
  return client.theses.assetCandidates(
@@ -15217,6 +15288,23 @@ async function executeParsedCommand(client, parsedCommand, meta, deps) {
15217
15288
  requireFlag(flags, "id", "thesis unstar"),
15218
15289
  false
15219
15290
  );
15291
+ case "signal-preferences": {
15292
+ if (parsedCommand.path[2] === "get") {
15293
+ return client.theses.getSignalPreferences(flags.id);
15294
+ }
15295
+ const id = requireFlag(flags, "id", "thesis signal-preferences set");
15296
+ if (flags.kinds === void 0 && flags["min-importance"] === void 0) {
15297
+ throw new CliUsageError(
15298
+ "thesis signal-preferences set needs --kinds or --min-importance",
15299
+ "thesis"
15300
+ );
15301
+ }
15302
+ const current = await client.theses.getSignalPreferences(id);
15303
+ return client.theses.setSignalPreferences(id, {
15304
+ kinds: flags.kinds === void 0 ? current.preferences.kinds : thesisSignalKindList(flags.kinds, "--kinds"),
15305
+ min_importance: flags["min-importance"] === void 0 ? current.preferences.min_importance : flags["min-importance"]
15306
+ });
15307
+ }
15220
15308
  case "set-signal-enabled":
15221
15309
  return client.theses.setSignalEnabled(
15222
15310
  requireFlag(flags, "id", "thesis set-signal-enabled"),