gloomberb 0.20.3 → 0.20.5

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.
Files changed (348) hide show
  1. package/README.md +2 -0
  2. package/bin/gloom +9 -0
  3. package/bin/without-bun.cjs +98 -0
  4. package/package.json +3 -1
  5. package/src/account/auth-dialog.tsx +17 -0
  6. package/src/api-client/data.ts +144 -35
  7. package/src/api-client/fx-interventions.ts +64 -0
  8. package/src/api-client/index.ts +1 -0
  9. package/src/api-client/release-summaries.ts +21 -0
  10. package/src/api-client/types/econ.ts +12 -0
  11. package/src/api-client/yield-curves.ts +1 -1
  12. package/src/app/global-shortcuts.ts +4 -1
  13. package/src/app/keybindings/actions.ts +8 -2
  14. package/src/app/keybindings/config.ts +2 -1
  15. package/src/app/keybindings/index.ts +1 -0
  16. package/src/app/keybindings/labels.ts +6 -1
  17. package/src/app/keybindings/resolve.ts +23 -4
  18. package/src/app/keybindings/terminal-keys.ts +35 -0
  19. package/src/app/pane-runtime/index.tsx +2 -2
  20. package/src/app/pane-runtime/ticker-open-runtime.ts +274 -67
  21. package/src/architecture/ui-literals-allowlist.json +1 -1
  22. package/src/capabilities/chart-series.ts +27 -1
  23. package/src/cli/commands/keybindings.ts +5 -5
  24. package/src/cli/commands/market.ts +154 -21
  25. package/src/cli/commands/news-search.ts +60 -10
  26. package/src/cli/commands/overview.ts +16 -1
  27. package/src/cli/commands/plugins.ts +27 -5
  28. package/src/cli/commands/remote.ts +16 -17
  29. package/src/cli/commands/system.ts +20 -4
  30. package/src/cli/commands/ticker.ts +60 -19
  31. package/src/cli/fx-forward.ts +25 -7
  32. package/src/cli/glossary.ts +19 -5
  33. package/src/cli/history-rows.ts +5 -3
  34. package/src/cli/index.ts +8 -8
  35. package/src/cli/known-gaps.ts +27 -1
  36. package/src/cli/listing-arg.ts +11 -1
  37. package/src/cli/name-entries.ts +5 -1
  38. package/src/cli/not-a-ticker.ts +4 -0
  39. package/src/cli/pane-functions/function-help.ts +5 -5
  40. package/src/cli/report-tables.ts +18 -6
  41. package/src/cli/result.ts +15 -7
  42. package/src/cli/types.ts +2 -0
  43. package/src/components/chart/composite/axis-overlays.tsx +22 -0
  44. package/src/components/chart/composite/composite-chart.tsx +54 -13
  45. package/src/components/chart/composite/event-captions.ts +109 -0
  46. package/src/components/chart/composite/event-guides.ts +74 -0
  47. package/src/components/chart/composite/rasterizer.ts +2 -0
  48. package/src/components/chart/composite/text-renderer.ts +2 -0
  49. package/src/components/chart/composite/types.ts +31 -0
  50. package/src/components/command-bar/layout-items/focused-pane.ts +5 -5
  51. package/src/components/command-bar/pane-settings.ts +2 -2
  52. package/src/components/command-bar/routes/root/provider-search.ts +5 -4
  53. package/src/components/command-bar/routes/root/results.ts +6 -2
  54. package/src/components/command-bar/routes/ticker-search/results.ts +51 -0
  55. package/src/components/command-bar/routes/ticker-search/route.ts +3 -2
  56. package/src/components/input-search-bar.tsx +9 -2
  57. package/src/components/layout/detached-pane-shell.tsx +1 -1
  58. package/src/components/layout/floating-pane.tsx +5 -1
  59. package/src/components/layout/pane/footer/index.tsx +21 -14
  60. package/src/components/layout/pane/footer/model.ts +6 -0
  61. package/src/components/layout/pane/header.tsx +2 -0
  62. package/src/components/layout/shell/action-menu-overlay.tsx +10 -5
  63. package/src/components/layout/shell/active-drag.ts +149 -105
  64. package/src/components/layout/shell/drag/drop-zones.ts +162 -0
  65. package/src/components/layout/shell/drag/index.ts +47 -218
  66. package/src/components/layout/shell/drag/live.ts +10 -3
  67. package/src/components/layout/shell/drag/overlays.tsx +182 -5
  68. package/src/components/layout/shell/drag/runtime.ts +29 -6
  69. package/src/components/layout/shell/drag/shared-edges.ts +156 -0
  70. package/src/components/layout/shell/index.tsx +11 -6
  71. package/src/components/layout/shell/menu.ts +11 -2
  72. package/src/components/layout/shell/native/pointer-runtime.ts +25 -0
  73. package/src/components/layout/shell/native/window-state.ts +2 -2
  74. package/src/components/layout/shell/pane/capture.ts +4 -1
  75. package/src/components/layout/shell/pane/layers.tsx +71 -7
  76. package/src/components/layout/shell/terminal-pointer-runtime.ts +18 -9
  77. package/src/components/layout/shell/window-mode/index.ts +8 -10
  78. package/src/components/layout/status-bar.tsx +6 -1
  79. package/src/components/layout/window-edit/mode.ts +39 -7
  80. package/src/components/layout/window-edit/presentation.ts +1 -1
  81. package/src/components/onboarding/first-run-workspace.ts +44 -2
  82. package/src/components/onboarding/onboarding-frame.tsx +11 -2
  83. package/src/components/onboarding/onboarding-keyboard.ts +20 -0
  84. package/src/components/onboarding/onboarding-wizard.tsx +16 -11
  85. package/src/components/onboarding/portfolio-step/positions-panel.tsx +62 -1
  86. package/src/components/onboarding/use-onboarding-progress.ts +12 -4
  87. package/src/components/pane-settings-dialog/desktop.tsx +2 -2
  88. package/src/components/pane-settings-dialog/tui.tsx +2 -2
  89. package/src/components/pane-settings-dialog/value.ts +6 -0
  90. package/src/components/pane-settings-dialog.tsx +3 -3
  91. package/src/components/reader/detail-reader.tsx +4 -0
  92. package/src/components/ui/button.tsx +2 -0
  93. package/src/components/ui/choice-dialog.tsx +1 -0
  94. package/src/components/ui/data-table/index.tsx +4 -3
  95. package/src/components/ui/index.ts +1 -1
  96. package/src/components/ui/list-view.tsx +7 -12
  97. package/src/components/ui/loading.tsx +10 -3
  98. package/src/components/ui/menu.tsx +6 -2
  99. package/src/components/ui/page-stack-view.tsx +3 -0
  100. package/src/components/ui/pane-link-chip.tsx +269 -54
  101. package/src/components/ui/query-bar.tsx +2 -1
  102. package/src/components/ui/quote.ts +14 -1
  103. package/src/components/ui/tabs.tsx +97 -19
  104. package/src/core/state/app/layout-reducer.ts +7 -0
  105. package/src/core/state/app/layout.ts +44 -7
  106. package/src/core/state/app/state.ts +1 -1
  107. package/src/core/state/app/types.ts +22 -2
  108. package/src/data/config/layout.ts +5 -2
  109. package/src/docs/snapshot.json +54 -13
  110. package/src/i18n/es.ts +9 -8
  111. package/src/i18n/ja.ts +9 -8
  112. package/src/i18n/ko.ts +9 -8
  113. package/src/i18n/zh-cn.ts +9 -8
  114. package/src/i18n/zh-tw.ts +9 -8
  115. package/src/layout/pane-manager/floating-actions.ts +17 -0
  116. package/src/layout/pane-manager/floating-stack.ts +187 -0
  117. package/src/layout/pane-manager/floating.ts +4 -2
  118. package/src/layout/pane-manager/gridlock.ts +5 -1
  119. package/src/layout/pane-manager/index.ts +11 -0
  120. package/src/layout/pane-manager/layout-state.ts +10 -3
  121. package/src/market-data/depositary-pair.ts +5 -3
  122. package/src/market-data/futures-board.ts +46 -1
  123. package/src/market-data/futures-contract.ts +12 -3
  124. package/src/market-data/fx-interventions.ts +270 -0
  125. package/src/market-data/market/dated-previous-close.ts +94 -15
  126. package/src/market-data/market/status.ts +17 -1
  127. package/src/news/news-model.ts +44 -2
  128. package/src/plugins/builtin/alerts/cli.ts +4 -4
  129. package/src/plugins/builtin/alerts/format.ts +1 -2
  130. package/src/plugins/builtin/alerts/headless.ts +1 -2
  131. package/src/plugins/builtin/alerts/move-checks.ts +12 -6
  132. package/src/plugins/builtin/alerts/move.ts +30 -9
  133. package/src/plugins/builtin/alerts/pane.tsx +0 -2
  134. package/src/plugins/builtin/alerts/storage.ts +4 -2
  135. package/src/plugins/builtin/alerts/types.ts +12 -0
  136. package/src/plugins/builtin/analytics/risk-client.ts +10 -4
  137. package/src/plugins/builtin/analytics/risk-episodes.ts +5 -4
  138. package/src/plugins/builtin/analytics/risk-headless.ts +4 -2
  139. package/src/plugins/builtin/analytics/risk-sectors.ts +91 -0
  140. package/src/plugins/builtin/awards/index.tsx +1 -1
  141. package/src/plugins/builtin/buildout/index.tsx +1 -0
  142. package/src/plugins/builtin/catalysts/index.tsx +2 -2
  143. package/src/plugins/builtin/cds/headless.ts +4 -0
  144. package/src/plugins/builtin/changelog/index.tsx +292 -101
  145. package/src/plugins/builtin/changelog/versions.ts +293 -0
  146. package/src/plugins/builtin/chart-composer/headless.ts +2 -1
  147. package/src/plugins/builtin/chart-composer/index.tsx +1 -0
  148. package/src/plugins/builtin/chart-composer/intervention-events.ts +105 -0
  149. package/src/plugins/builtin/chart-composer/pane.tsx +21 -7
  150. package/src/plugins/builtin/chat/content/composer.tsx +5 -4
  151. package/src/plugins/builtin/chat/content/index.tsx +12 -2
  152. package/src/plugins/builtin/chat/content/layout-metrics.ts +3 -3
  153. package/src/plugins/builtin/chat/content/open-targets.ts +3 -3
  154. package/src/plugins/builtin/chat/layout.ts +5 -2
  155. package/src/plugins/builtin/chat/message/pane-chip.tsx +61 -40
  156. package/src/plugins/builtin/chat/message/render-state.ts +2 -5
  157. package/src/plugins/builtin/chat/message/terminal.tsx +13 -15
  158. package/src/plugins/builtin/chat/pane-links/previews.ts +51 -5
  159. package/src/plugins/builtin/chat/pane-links/share-card.ts +36 -0
  160. package/src/plugins/builtin/cloud/askg/attached-pane.tsx +10 -5
  161. package/src/plugins/builtin/cloud/askg/controller.ts +141 -5
  162. package/src/plugins/builtin/cloud/askg/executor.ts +113 -4
  163. package/src/plugins/builtin/cloud/askg/manifest.ts +28 -13
  164. package/src/plugins/builtin/cloud/askg/model.ts +14 -4
  165. package/src/plugins/builtin/cloud/askg/pane.tsx +70 -46
  166. package/src/plugins/builtin/cloud/askg/tool-display.ts +1 -0
  167. package/src/plugins/builtin/cloud/askg/turn-parts.tsx +70 -0
  168. package/src/plugins/builtin/cloud/terminal-relay/engine.ts +50 -130
  169. package/src/plugins/builtin/cloud/terminal-relay/policy.ts +327 -7
  170. package/src/plugins/builtin/cloud/terminal-relay/prompts.tsx +2 -1
  171. package/src/plugins/builtin/cloud/terminal-relay/redact.ts +52 -9
  172. package/src/plugins/builtin/commodities-energy/index.tsx +1 -3
  173. package/src/plugins/builtin/commodities-energy/view-state.ts +3 -0
  174. package/src/plugins/builtin/commodity-balances/index.tsx +1 -0
  175. package/src/plugins/builtin/company-attention/index.tsx +1 -1
  176. package/src/plugins/builtin/company-kpis/headless.ts +3 -1
  177. package/src/plugins/builtin/company-kpis/index.tsx +2 -2
  178. package/src/plugins/builtin/cot/headless.ts +14 -2
  179. package/src/plugins/builtin/cot/index.tsx +1 -1
  180. package/src/plugins/builtin/cpi/index.tsx +1 -1
  181. package/src/plugins/builtin/crypto-board/index.tsx +1 -0
  182. package/src/plugins/builtin/dividend-yield/index.tsx +1 -0
  183. package/src/plugins/builtin/doe/index.tsx +1 -1
  184. package/src/plugins/builtin/earnings/index.tsx +2 -2
  185. package/src/plugins/builtin/earnings-calls/headless.ts +5 -1
  186. package/src/plugins/builtin/earnings-calls/index.tsx +1 -0
  187. package/src/plugins/builtin/econ/calendar-model.ts +74 -1
  188. package/src/plugins/builtin/econ/fred-catalog.ts +3 -1
  189. package/src/plugins/builtin/econ/index.tsx +1 -0
  190. package/src/plugins/builtin/econ-statistics/index.tsx +1 -0
  191. package/src/plugins/builtin/econ-statistics/pane.tsx +6 -0
  192. package/src/plugins/builtin/estimate-revisions/index.tsx +1 -0
  193. package/src/plugins/builtin/executives/index.tsx +1 -0
  194. package/src/plugins/builtin/filing-events/index.tsx +1 -0
  195. package/src/plugins/builtin/fixed-income/index.tsx +1 -0
  196. package/src/plugins/builtin/futures/index.tsx +25 -4
  197. package/src/plugins/builtin/futures/model.ts +28 -32
  198. package/src/plugins/builtin/futures/series.ts +4 -3
  199. package/src/plugins/builtin/futures/table.tsx +16 -9
  200. package/src/plugins/builtin/futures/use-board-terms.ts +3 -3
  201. package/src/plugins/builtin/futures-curve/headless.ts +3 -3
  202. package/src/plugins/builtin/futures-curve/index.tsx +1 -1
  203. package/src/plugins/builtin/futures-curve/model.ts +18 -0
  204. package/src/plugins/builtin/gpu/index.tsx +1 -1
  205. package/src/plugins/builtin/help/functions-table.tsx +1 -1
  206. package/src/plugins/builtin/help/index.tsx +14 -4
  207. package/src/plugins/builtin/help/keybindings-editor.tsx +19 -5
  208. package/src/plugins/builtin/holders/index.tsx +1 -0
  209. package/src/plugins/builtin/holders/report-header.ts +2 -2
  210. package/src/plugins/builtin/insider/index.tsx +1 -0
  211. package/src/plugins/builtin/iv-history/index.tsx +1 -1
  212. package/src/plugins/builtin/jobs/index.tsx +1 -0
  213. package/src/plugins/builtin/layout-manager/index.tsx +8 -8
  214. package/src/plugins/builtin/macro-day/headless.ts +27 -8
  215. package/src/plugins/builtin/macro-day/index.tsx +1 -1
  216. package/src/plugins/builtin/macro-day/model.ts +19 -3
  217. package/src/plugins/builtin/macro-day/pane.tsx +14 -9
  218. package/src/plugins/builtin/macro-day/releases.ts +25 -7
  219. package/src/plugins/builtin/market-valuation/index.tsx +1 -0
  220. package/src/plugins/builtin/market-valuation/pane.tsx +8 -0
  221. package/src/plugins/builtin/members/index.tsx +1 -1
  222. package/src/plugins/builtin/mna/index.tsx +1 -0
  223. package/src/plugins/builtin/news/headless.ts +2 -2
  224. package/src/plugins/builtin/news/index.tsx +4 -3
  225. package/src/plugins/builtin/news/wire/index.tsx +5 -1
  226. package/src/plugins/builtin/news/wire/news/detail-view.tsx +4 -0
  227. package/src/plugins/builtin/news/wire/news/list-search.ts +5 -2
  228. package/src/plugins/builtin/options/index.tsx +1 -0
  229. package/src/plugins/builtin/options-positioning/index.tsx +1 -0
  230. package/src/plugins/builtin/pe-band/index.tsx +1 -1
  231. package/src/plugins/builtin/perps/markets-section.tsx +5 -2
  232. package/src/plugins/builtin/plugin-marketplace/pane.tsx +11 -11
  233. package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +25 -0
  234. package/src/plugins/builtin/portfolio-list/headless.ts +15 -6
  235. package/src/plugins/builtin/portfolio-list/summary/index.tsx +3 -1
  236. package/src/plugins/builtin/power/index.tsx +1 -1
  237. package/src/plugins/builtin/realized-vol/index.tsx +1 -1
  238. package/src/plugins/builtin/research/event-model.ts +9 -1
  239. package/src/plugins/builtin/research/event-sources.ts +22 -0
  240. package/src/plugins/builtin/research/headless.ts +11 -5
  241. package/src/plugins/builtin/research/index.tsx +4 -0
  242. package/src/plugins/builtin/research-search/index.tsx +1 -0
  243. package/src/plugins/builtin/research-search/pane.tsx +8 -0
  244. package/src/plugins/builtin/revenue-breakdown/index.tsx +1 -0
  245. package/src/plugins/builtin/reverse-dcf/index.tsx +1 -1
  246. package/src/plugins/builtin/risk-factors/index.tsx +1 -0
  247. package/src/plugins/builtin/scanner/headless.ts +52 -13
  248. package/src/plugins/builtin/seasonality/index.tsx +1 -1
  249. package/src/plugins/builtin/sec/index.tsx +1 -0
  250. package/src/plugins/builtin/series-inventory.ts +1 -1
  251. package/src/plugins/builtin/shared/cloud-upgrade.ts +27 -3
  252. package/src/plugins/builtin/shared/scanner-capture.ts +11 -3
  253. package/src/plugins/builtin/shared/series-list-detail.tsx +5 -0
  254. package/src/plugins/builtin/short-interest/index.tsx +1 -0
  255. package/src/plugins/builtin/social-mentions/index.tsx +1 -1
  256. package/src/plugins/builtin/supply-chain/index.tsx +1 -0
  257. package/src/plugins/builtin/thirteenf/data.ts +43 -10
  258. package/src/plugins/builtin/thirteenf/headless.ts +55 -11
  259. package/src/plugins/builtin/thirteenf/model.ts +25 -9
  260. package/src/plugins/builtin/thirteenf/report-notes.ts +27 -6
  261. package/src/plugins/builtin/thirteenf/types.ts +2 -0
  262. package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +1 -1
  263. package/src/plugins/builtin/ticker-detail/financials/model.ts +12 -0
  264. package/src/plugins/builtin/ticker-detail/financials/ratio-table.tsx +3 -3
  265. package/src/plugins/builtin/ticker-detail/financials/tab.tsx +5 -5
  266. package/src/plugins/builtin/ticker-detail/headless.ts +18 -13
  267. package/src/plugins/builtin/ticker-detail/index.tsx +4 -0
  268. package/src/plugins/builtin/ticker-detail/overview/components.tsx +54 -5
  269. package/src/plugins/builtin/ticker-detail/overview/model.ts +6 -4
  270. package/src/plugins/builtin/ticker-detail/overview-tab.tsx +34 -17
  271. package/src/plugins/builtin/ticker-detail/pane.tsx +7 -2
  272. package/src/plugins/builtin/time-sales/client.ts +9 -11
  273. package/src/plugins/builtin/time-sales/index.tsx +1 -1
  274. package/src/plugins/builtin/treasury-auctions/after.ts +267 -0
  275. package/src/plugins/builtin/treasury-auctions/cache.ts +18 -3
  276. package/src/plugins/builtin/treasury-auctions/client.ts +33 -2
  277. package/src/plugins/builtin/treasury-auctions/headless.ts +109 -19
  278. package/src/plugins/builtin/treasury-auctions/index.tsx +14 -4
  279. package/src/plugins/builtin/treasury-auctions/model.ts +256 -28
  280. package/src/plugins/builtin/treasury-auctions/pane.tsx +139 -28
  281. package/src/plugins/builtin/treasury-auctions/treasury-direct.ts +5 -2
  282. package/src/plugins/builtin/treasury-auctions/types.ts +7 -1
  283. package/src/plugins/builtin/vol-surface/index.tsx +1 -1
  284. package/src/plugins/builtin/world-venue-map/index.ts +1 -0
  285. package/src/plugins/builtin/yield-curve/curves.ts +10 -4
  286. package/src/plugins/builtin/yield-curve/headless.ts +6 -2
  287. package/src/plugins/builtin/yield-curve/index.tsx +3 -3
  288. package/src/plugins/builtin/yield-curve/series.ts +10 -0
  289. package/src/plugins/builtin/yield-curve/world.ts +3 -1
  290. package/src/plugins/installer.ts +45 -0
  291. package/src/portfolio/column-values.ts +2 -1
  292. package/src/public/__snapshots__/public-api.test.ts.snap +4 -0
  293. package/src/public/remote.ts +7 -1
  294. package/src/remote/client.ts +191 -11
  295. package/src/remote/controller-utils.ts +13 -1
  296. package/src/remote/controller.ts +88 -26
  297. package/src/remote/endpoint.ts +24 -0
  298. package/src/remote/form.ts +59 -4
  299. package/src/remote/resources.ts +56 -19
  300. package/src/remote/schema.ts +22 -9
  301. package/src/remote/secrets.ts +12 -0
  302. package/src/remote/semantic-helpers.ts +29 -1
  303. package/src/remote/semantic-tree.tsx +44 -15
  304. package/src/remote/server.ts +2 -1
  305. package/src/remote/surface.tsx +192 -0
  306. package/src/remote/types.ts +5 -0
  307. package/src/renderers/cloudflare/worker.ts +16 -1
  308. package/src/renderers/dom/styles.css +40 -6
  309. package/src/renderers/opentui/host.tsx +6 -0
  310. package/src/renderers/share/layout-view.tsx +1 -1
  311. package/src/series/standalone.ts +2 -2
  312. package/src/shares/api.ts +21 -4
  313. package/src/shares/item.ts +73 -0
  314. package/src/shares/pane-item.ts +205 -0
  315. package/src/shares/pane.ts +4 -0
  316. package/src/shares/payload.ts +9 -5
  317. package/src/sources/gloomberb-cloud/news.ts +37 -12
  318. package/src/state/opening-ticker-panes.ts +47 -0
  319. package/src/test-support/cli-context.ts +2 -0
  320. package/src/test-support/preload.ts +4 -1
  321. package/src/tickers/instrument-kind.ts +23 -3
  322. package/src/tickers/renamed-listings.ts +105 -0
  323. package/src/tickers/search/index.ts +103 -16
  324. package/src/time-series/resolve.ts +2 -2
  325. package/src/types/config.ts +5 -0
  326. package/src/types/context-menu.ts +2 -0
  327. package/src/types/financials.ts +1 -0
  328. package/src/types/plugin-commands.ts +140 -0
  329. package/src/types/plugin-context.ts +125 -0
  330. package/src/types/plugin-contributions.ts +55 -0
  331. package/src/types/plugin-definition.ts +234 -0
  332. package/src/types/plugin-notifications.ts +38 -0
  333. package/src/types/plugin-pane-settings.ts +116 -0
  334. package/src/types/plugin-pane-templates.ts +160 -0
  335. package/src/types/plugin-panes.ts +243 -0
  336. package/src/types/plugin-reports.ts +35 -0
  337. package/src/types/plugin-shared.ts +14 -0
  338. package/src/types/plugin-state.ts +71 -0
  339. package/src/types/plugin.ts +14 -1169
  340. package/src/ui/index.tsx +14 -3
  341. package/src/updater/github-releases.ts +23 -0
  342. package/src/utils/central-banks.ts +86 -1
  343. package/src/utils/cli-output.ts +22 -9
  344. package/src/utils/datetime-format.ts +12 -3
  345. package/src/utils/depositary-receipt.ts +28 -3
  346. package/src/utils/fundamentals.ts +14 -0
  347. package/src/utils/max-drawdown.ts +97 -16
  348. package/src/utils/untrusted-text.ts +29 -0
package/src/shares/api.ts CHANGED
@@ -58,17 +58,28 @@ async function readJson(response: Response): Promise<unknown> {
58
58
  try { return await response.json(); } catch { throw new Error("The share service returned an invalid response."); }
59
59
  }
60
60
 
61
+ /**
62
+ * A service from before shares kept an item refuses one it does not know with
63
+ * a 400: the share is made again without it, as that service would keep it.
64
+ */
65
+ function withoutItem(payload: SharePayload): SharePayload | null {
66
+ return payload.kind === "pane" && payload.item ? { kind: "pane", data: payload.data } : null;
67
+ }
68
+
61
69
  export async function createShare(payload: SharePayload, fetchImpl?: ShareFetch): Promise<CreatedShare> {
62
70
  const validated = parseSharePayload(payload);
63
71
  if (!validated) throw new Error("Invalid share payload.");
64
72
  let body: unknown;
65
73
  if (fetchImpl) {
66
- const response = await fetchImpl(`${SHARE_API_ORIGIN}/shares`, {
74
+ const post = (share: SharePayload) => fetchImpl(`${SHARE_API_ORIGIN}/shares`, {
67
75
  method: "POST",
68
76
  credentials: "include",
69
77
  headers: { "Content-Type": "application/json" },
70
- body: JSON.stringify(validated),
78
+ body: JSON.stringify(share),
71
79
  });
80
+ let response = await post(validated);
81
+ const plain = response.status === 400 ? withoutItem(validated) : null;
82
+ if (plain) response = await post(plain);
72
83
  if (!response.ok) {
73
84
  if (response.status === 401) throw new Error("Sign in to Gloom Cloud to share.");
74
85
  if (response.status === 403) throw new Error("Verify your Gloom Cloud email to share.");
@@ -80,7 +91,13 @@ export async function createShare(payload: SharePayload, fetchImpl?: ShareFetch)
80
91
  // client when an interactive app creates a share, not on every public view.
81
92
  const { apiClient } = await import("../api-client").catch((error: unknown) => { throw shareFailed(error); });
82
93
  try {
83
- body = await apiClient.createTerminalShare(validated);
94
+ try {
95
+ body = await apiClient.createTerminalShare(validated);
96
+ } catch (error) {
97
+ const plain = error instanceof ApiRequestError && error.status === 400 ? withoutItem(validated) : null;
98
+ if (!plain) throw error;
99
+ body = await apiClient.createTerminalShare(plain);
100
+ }
84
101
  } catch (error) {
85
102
  if (error instanceof ApiRequestError && error.status === 401) throw new Error("Sign in to Gloom Cloud to share.");
86
103
  if (error instanceof ApiRequestError && error.status === 403) throw new Error("Verify your Gloom Cloud email to share.");
@@ -112,7 +129,7 @@ export async function getShare(
112
129
  const body = await readJson(response);
113
130
  if (!body || typeof body !== "object") return null;
114
131
  const object = body as Record<string, unknown>;
115
- const payload = parseSharePayload({ kind: object.kind, data: object.data });
132
+ const payload = parseSharePayload({ kind: object.kind, data: object.data, item: object.item });
116
133
  if (!payload || !validDate(object.createdAt) || !validDate(object.expiresAt)) return null;
117
134
  return {
118
135
  ...payload,
@@ -0,0 +1,73 @@
1
+ import { markdownPlainText } from "../utils/markdown";
2
+ import { isRecord } from "../utils/guards";
3
+ import { plainUntrustedLine } from "../utils/untrusted-text";
4
+
5
+ /**
6
+ * What a shared pane was on when it was shared: the story it had open, the
7
+ * result it had picked, the ticker it shows. It goes with the share, beside
8
+ * the pane's settings, so a chat card, a link preview in another app and the
9
+ * chat's bots can say what the link is about without opening it. A pane on
10
+ * nothing in particular shares none.
11
+ */
12
+ export interface ShareItem {
13
+ /** The pane it opens, by name: a reader without that pane (a link preview, a bot) still says which. */
14
+ pane: string;
15
+ title: string;
16
+ /** A sentence or two of what it says: a story's summary, a result's snippet. */
17
+ excerpt?: string;
18
+ }
19
+
20
+ const SHARE_ITEM_LIMITS = { pane: 80, title: 200, excerpt: 300 } as const;
21
+ /** About two lines of a chat card and what link previews show of a description. */
22
+ const EXCERPT_LENGTH = 240;
23
+
24
+ /** One line of plain text, as the share service keeps it and every reader draws it (untrusted-text.ts). */
25
+ const oneLine = plainUntrustedLine;
26
+
27
+ /** `text` cut to `max` characters at a word, with an ellipsis when it was cut. */
28
+ function clip(text: string, max: number): string {
29
+ if (text.length <= max) return text;
30
+ const cut = text.slice(0, max - 1);
31
+ const space = cut.lastIndexOf(" ");
32
+ return `${(space > max * 0.6 ? cut.slice(0, space) : cut).replace(/[\s,;:.-]+$/, "")}…`;
33
+ }
34
+
35
+ /** The opening of a text as one line: its first paragraph, cut to about two lines. */
36
+ export function shareItemExcerpt(text: string | null | undefined, { markdown = false, max = EXCERPT_LENGTH } = {}): string | undefined {
37
+ if (!text) return undefined;
38
+ const plain = markdown ? markdownPlainText(text, { links: true }) : text;
39
+ const paragraph = plain.split(/\n\s*\n/).map(oneLine).find(Boolean);
40
+ return paragraph ? clip(paragraph, Math.min(max, SHARE_ITEM_LIMITS.excerpt)) : undefined;
41
+ }
42
+
43
+ /** The item as it is kept: one line each, within the limits, or null without a title. */
44
+ export function shareItem(pane: string, part: { title?: string | null; excerpt?: string | null } | null | undefined): ShareItem | null {
45
+ const title = part?.title ? clip(oneLine(part.title), SHARE_ITEM_LIMITS.title) : "";
46
+ const name = clip(oneLine(pane), SHARE_ITEM_LIMITS.pane);
47
+ if (!title || !name) return null;
48
+ const excerpt = part?.excerpt ? clip(oneLine(part.excerpt), SHARE_ITEM_LIMITS.excerpt) : "";
49
+ return { pane: name, title, ...(excerpt && excerpt !== title ? { excerpt } : {}) };
50
+ }
51
+
52
+ /** `value` as one line of plain text within `max`, or null when it is not text, says nothing, or is over. */
53
+ function boundedText(value: unknown, max: number): string | null {
54
+ if (typeof value !== "string") return null;
55
+ const text = oneLine(value);
56
+ return text && text.length <= max ? text : null;
57
+ }
58
+
59
+ /**
60
+ * An item read back from a share, or null for anything else. Another person's
61
+ * app wrote it, so its text is made plain again here, whatever the service
62
+ * kept: no escape sequence, control, bidi or zero-width character reaches a
63
+ * card.
64
+ */
65
+ export function parseShareItem(value: unknown): ShareItem | null {
66
+ if (!isRecord(value) || !Object.keys(value).every((key) => key === "pane" || key === "title" || key === "excerpt")) return null;
67
+ const pane = boundedText(value.pane, SHARE_ITEM_LIMITS.pane);
68
+ const title = boundedText(value.title, SHARE_ITEM_LIMITS.title);
69
+ if (!pane || !title) return null;
70
+ if (value.excerpt === undefined) return { pane, title };
71
+ const excerpt = boundedText(value.excerpt, SHARE_ITEM_LIMITS.excerpt);
72
+ return excerpt ? { pane, title, excerpt } : null;
73
+ }
@@ -0,0 +1,205 @@
1
+ import { useEffect, useRef } from "react";
2
+ import { usePaneFooterScopeActive } from "../components/layout/pane/footer/registration";
3
+ import type { ResolvedPane } from "../layout/pane-manager";
4
+ import { listExternalPlugins } from "../plugins/external-runtime";
5
+ import type { PluginRegistry } from "../plugins/registry";
6
+ import { resolveTickerForPane, useOptionalPaneInstanceId, type AppState } from "../state/app/context";
7
+ import type { PaneTemplateDef } from "../types/plugin";
8
+ import { logFailure } from "../utils/log-failure";
9
+ import { shareItem, type ShareItem } from "./item";
10
+
11
+ /** What a pane, or a part of the kit it is drawn with, says it is on. */
12
+ export interface PaneShareItemPart {
13
+ title?: string | null;
14
+ excerpt?: string | null;
15
+ }
16
+
17
+ type PaneShareItemInput = PaneShareItemPart | null | (() => PaneShareItemPart | null);
18
+
19
+ interface Entry {
20
+ read(): PaneShareItemPart | null;
21
+ /** Said by the kit (a stack's open detail, a reader's text), which a pane's own word outranks. */
22
+ kit: boolean;
23
+ order: number;
24
+ }
25
+
26
+ const entries = new Map<string, Set<Entry>>();
27
+ let nextOrder = 0;
28
+
29
+ /**
30
+ * Says what the pane is on now, for Share to keep with its link: the story
31
+ * it has open, the result it has picked. Pass null when it is on nothing in
32
+ * particular, and a function for an item that takes work to put together:
33
+ * it is read only when a link is made. A tab that is not shown says nothing. `kit` marks the shared components'
34
+ * own guesses (a stack's detail title, a reader's opening), which a pane's
35
+ * own item outranks; they combine, so a stack's title takes its reader's
36
+ * opening as its excerpt. Any pane may say; a link reads it only from a pane
37
+ * that opts in with `shareItem.open` (paneShareItemFor).
38
+ */
39
+ export function usePaneShareItem(item: PaneShareItemInput, options: { paneId?: string; kit?: boolean } = {}): void {
40
+ const contextPaneId = useOptionalPaneInstanceId();
41
+ const paneId = options.paneId ?? contextPaneId;
42
+ const shown = usePaneFooterScopeActive();
43
+ const latest = useRef(item);
44
+ latest.current = item;
45
+ const kit = options.kit === true;
46
+ useEffect(() => {
47
+ if (!paneId || !shown) return;
48
+ const entry: Entry = {
49
+ read: () => {
50
+ const current = latest.current;
51
+ return typeof current === "function" ? current() : current;
52
+ },
53
+ kit,
54
+ order: ++nextOrder,
55
+ };
56
+ let set = entries.get(paneId);
57
+ if (!set) entries.set(paneId, set = new Set());
58
+ set.add(entry);
59
+ return () => {
60
+ set.delete(entry);
61
+ if (set.size === 0 && entries.get(paneId) === set) entries.delete(paneId);
62
+ };
63
+ }, [kit, paneId, shown]);
64
+ }
65
+
66
+ function readEntry(entry: Entry): PaneShareItemPart | null {
67
+ try {
68
+ return entry.read();
69
+ } catch (error) {
70
+ logFailure("shares.pane-item", "Reading what a pane is on failed")(error);
71
+ return null;
72
+ }
73
+ }
74
+
75
+ /**
76
+ * What the pane says it is on: the pane's own item first, then the kit's,
77
+ * the one shown last first within each. A title without an excerpt takes the
78
+ * kit's excerpt (a stack's title, its reader's opening).
79
+ */
80
+ function declaredPaneShareItem(paneId: string): PaneShareItemPart | null {
81
+ const said = [...entries.get(paneId) ?? []]
82
+ .sort((a, b) => Number(a.kit) - Number(b.kit) || b.order - a.order)
83
+ .map((entry) => ({ entry, part: readEntry(entry) }))
84
+ .filter((said): said is { entry: Entry; part: PaneShareItemPart } => !!said.part);
85
+ const titled = said.find(({ part }) => part.title?.trim());
86
+ if (!titled) return null;
87
+ const excerpt = titled.part.excerpt?.trim()
88
+ || said.find(({ entry, part }) => entry.kit && entry !== titled.entry && part.excerpt?.trim())?.part.excerpt;
89
+ return { title: titled.part.title, excerpt: excerpt || null };
90
+ }
91
+
92
+ export interface PaneShareItemSource {
93
+ /** The pane's instance id, when what it says it is on may name the item (`shareItem.open`); null when not. */
94
+ paneId: string | null;
95
+ /** The pane's name. */
96
+ paneName: string;
97
+ /** The one ticker the pane shows, with what is known of it; not a list's cursor. */
98
+ ticker?: { symbol: string; name?: string; exchange?: string; sector?: string; industry?: string } | null;
99
+ /** The argument the pane's function was opened with (`NI CRYPTO`), as its option names it. */
100
+ argument?: { label: string; description?: string } | null;
101
+ }
102
+
103
+ /**
104
+ * The item a share keeps: what the pane says it is on, else the ticker it
105
+ * shows, else the argument its function was opened with; null when it is on
106
+ * none of these.
107
+ */
108
+ export function resolvePaneShareItem(source: PaneShareItemSource): ShareItem | null {
109
+ const declared = source.paneId ? shareItem(source.paneName, declaredPaneShareItem(source.paneId)) : null;
110
+ if (declared) return declared;
111
+ const ticker = source.ticker;
112
+ if (ticker?.symbol) {
113
+ const symbol = ticker.symbol.split(":")[0] || ticker.symbol;
114
+ const name = ticker.name?.trim();
115
+ return shareItem(source.paneName, {
116
+ title: name && name !== symbol ? `${name} (${symbol})` : ticker.symbol,
117
+ excerpt: [ticker.exchange, ticker.sector, ticker.industry].filter(Boolean).join(" · "),
118
+ });
119
+ }
120
+ if (source.argument) return shareItem(source.paneName, { title: source.argument.label, excerpt: source.argument.description });
121
+ return null;
122
+ }
123
+
124
+ /**
125
+ * The argument a pane's function was opened with, read from its title as the
126
+ * function wrote it (`NI CRYPTO`), named as the function's options name it.
127
+ * Only an option the function lists: words typed after it (a search, a note)
128
+ * are the person's own, and a ticker is not one (the pane's ticker says more).
129
+ */
130
+ function functionArgument(
131
+ templates: ReadonlyMap<string, PaneTemplateDef>,
132
+ paneType: string,
133
+ title: string | undefined,
134
+ ): PaneShareItemSource["argument"] {
135
+ const [code = "", ...words] = (title ?? "").trim().split(/\s+/);
136
+ const argument = words.join(" ");
137
+ if (!argument) return null;
138
+ const opens = (prefix: string) => prefix.toUpperCase() === code.toUpperCase();
139
+ const template = [...templates.values()].find((candidate) => candidate.paneId === paneType
140
+ && !!candidate.shortcut
141
+ && (opens(candidate.shortcut.prefix) || (candidate.shortcut.aliases ?? []).some(opens)));
142
+ const options = template?.shortcut?.argKind === "ticker" ? undefined : template?.shortcut?.argOptions;
143
+ if (!template || !options) return null;
144
+ try {
145
+ const label = options().find((option) => option.value.toUpperCase() === argument.toUpperCase())?.label;
146
+ return label ? { label, description: template.description } : null;
147
+ } catch (error) {
148
+ logFailure("shares.pane-item", "Reading a function's argument options failed")(error);
149
+ return null;
150
+ }
151
+ }
152
+
153
+ /** Fields the pane keeps on the device when shared, so nothing it shows may stand in for them. */
154
+ function keepsFieldsPrivate(pane: Pick<ResolvedPane, "def">): boolean {
155
+ const kept = pane.def.portableShare?.private;
156
+ return !!kept && Object.values(kept).some((fields) => fields === true || (Array.isArray(fields) && fields.length > 0));
157
+ }
158
+
159
+ /** Whether a plugin loaded from outside the app (a registry or local plugin) owns the pane. */
160
+ function fromExternalPlugin(registry: Pick<PluginRegistry, "getPanePluginId">, paneType: string): boolean {
161
+ const owner = registry.getPanePluginId(paneType);
162
+ return !!owner && listExternalPlugins().some((entry) => entry.plugin.id === owner);
163
+ }
164
+
165
+ /** Whether the pane shows one ticker now: a chart of one security, not a comparison or a list. */
166
+ function showsOneTicker(pane: Pick<ResolvedPane, "instance" | "def">): boolean {
167
+ const { def, instance } = pane;
168
+ if (def.tickerSource) return false;
169
+ return typeof def.tickerFollower === "function" ? def.tickerFollower(instance) : def.tickerFollower === true;
170
+ }
171
+
172
+ /**
173
+ * The item a public link to the pane keeps, or null. Only from what the pane
174
+ * opts into (`PaneDef.shareItem`): an alert, a form's title or a search typed
175
+ * in a pane that says nothing never reaches a link, nor anything from a
176
+ * plugin loaded from outside the app. A pane that shows the person's own data,
177
+ * or keeps fields of its own off a share, keeps none either: what it is on
178
+ * would say what its settings leave out.
179
+ */
180
+ export function paneShareItemFor({ pane, state, registry, personal }: {
181
+ pane: Pick<ResolvedPane, "instance" | "def">;
182
+ state: Pick<AppState, "tickers"> & Parameters<typeof resolveTickerForPane>[0];
183
+ registry: Pick<PluginRegistry, "paneTemplates" | "getPanePluginId">;
184
+ /** Whether the pane shows the person's own data now (personal-pane.ts). */
185
+ personal: boolean;
186
+ }): ShareItem | null {
187
+ const { instance, def } = pane;
188
+ const allowed = def.shareItem;
189
+ if (!allowed || personal || keepsFieldsPrivate(pane) || fromExternalPlugin(registry, instance.paneId)) return null;
190
+ // The one ticker it shows; a list's cursor is where the list is, not something picked to share.
191
+ const symbol = allowed.ticker && showsOneTicker(pane) ? resolveTickerForPane(state, instance.instanceId) : null;
192
+ const metadata = symbol ? state.tickers.get(symbol)?.metadata : undefined;
193
+ return resolvePaneShareItem({
194
+ paneId: allowed.open ? instance.instanceId : null,
195
+ paneName: def.name,
196
+ ticker: symbol ? {
197
+ symbol,
198
+ name: metadata?.name,
199
+ exchange: metadata?.exchange,
200
+ sector: metadata?.sector,
201
+ industry: metadata?.industry,
202
+ } : null,
203
+ argument: allowed.argument ? functionArgument(registry.paneTemplates, instance.paneId, instance.title) : null,
204
+ });
205
+ }
@@ -6,6 +6,7 @@ import type { PluginRegistry } from "../plugins/registry";
6
6
  import type { PaneInstanceConfig } from "../types/config";
7
7
  import type { PaneDef, PaneTemplateDef } from "../types/plugin";
8
8
  import type { TickerRecord } from "../types/ticker";
9
+ import type { ShareItem } from "./item";
9
10
  import { parseSharePayload, type PaneShareData, type SharePayload } from "./payload";
10
11
 
11
12
  export function buildPaneSharePayload(
@@ -15,6 +16,8 @@ export function buildPaneSharePayload(
15
16
  resolvedTicker?: string | null,
16
17
  tickers?: ReadonlyMap<string, TickerRecord>,
17
18
  pinnedTime?: number | null,
19
+ /** What the pane is on (pane-item.ts), kept beside its settings. */
20
+ item?: ShareItem | null,
18
21
  ): Extract<SharePayload, { kind: "pane" }> | null {
19
22
  const def = pluginRegistry.panes.get(pane.paneId);
20
23
  if (!def) return null;
@@ -37,6 +40,7 @@ export function buildPaneSharePayload(
37
40
  ...(description ? { description } : {}),
38
41
  layout,
39
42
  },
43
+ ...(item ? { item } : {}),
40
44
  });
41
45
  return payload?.kind === "pane" ? payload : null;
42
46
  } catch (error) {
@@ -4,6 +4,7 @@ import {
4
4
  } from "./portable-layout";
5
5
  import { safeExternalUrl } from "../utils/external-url";
6
6
  import { isRecord } from "../utils/guards";
7
+ import { parseShareItem, type ShareItem } from "./item";
7
8
 
8
9
  const MAX_SHARE_BYTES = 128 * 1024;
9
10
  const MAX_TITLE_LENGTH = 200;
@@ -69,7 +70,8 @@ export type SharePayload =
69
70
  | { kind: "table"; data: TableShareData }
70
71
  | { kind: "chart"; data: ChartShareData }
71
72
  | { kind: "article"; data: ArticleShareData }
72
- | { kind: "pane"; data: PaneShareData };
73
+ /** `item` sits beside `data`, which apps before it read strictly and would refuse with it inside. */
74
+ | { kind: "pane"; data: PaneShareData; item?: ShareItem };
73
75
 
74
76
  function shortString(value: unknown, max = MAX_TITLE_LENGTH): value is string {
75
77
  return typeof value === "string" && value.length > 0 && value.length <= max;
@@ -195,12 +197,14 @@ export function parseSharePayload(value: unknown): SharePayload | null {
195
197
  let json: string;
196
198
  try { json = JSON.stringify(value); } catch { /* Intentional ignore: Circular or unserializable input is not a valid share payload. */ return null; }
197
199
  if (new TextEncoder().encode(json).byteLength > MAX_SHARE_BYTES) return null;
198
- if (value.kind === "table" && isTableData(value.data)) return value as unknown as SharePayload;
199
- if (value.kind === "chart" && isChartData(value.data)) return value as unknown as SharePayload;
200
- if (value.kind === "article" && isArticleData(value.data)) return value as unknown as SharePayload;
200
+ if (value.kind === "table" && isTableData(value.data)) return { kind: "table", data: value.data };
201
+ if (value.kind === "chart" && isChartData(value.data)) return { kind: "chart", data: value.data };
202
+ if (value.kind === "article" && isArticleData(value.data)) return { kind: "article", data: value.data };
201
203
  if (value.kind === "pane") {
202
204
  const data = parsePaneData(value.data);
203
- if (data) return { kind: "pane", data };
205
+ // An item this app cannot read leaves the pane as it was shared, without one.
206
+ const item = parseShareItem(value.item);
207
+ if (data) return { kind: "pane", data, ...(item ? { item } : {}) };
204
208
  }
205
209
  return null;
206
210
  }
@@ -12,6 +12,8 @@ import type {
12
12
  import type { CloudNewsParams } from "../../api-client/paths";
13
13
  import { parsePublicTickerKey, publicExchange } from "../../utils/exchanges";
14
14
  import { coinSearchName } from "../../utils/crypto-pair";
15
+ import { commoditySearchName } from "../../market-data/commodity-names";
16
+ import { futuresBoardContractForTicker } from "../../market-data/futures-board";
15
17
  import { logFailure } from "../../utils/log-failure";
16
18
  import { getListingSymbol, tickerHasListingSuffix } from "../listing-symbols";
17
19
 
@@ -195,12 +197,35 @@ export function cloudNewsAccess(
195
197
  type CloudNewsClient = Pick<typeof apiClient, "getCloudNews" | "searchCloudNews">
196
198
  & Partial<Pick<typeof apiClient, "hasSessionCredential">>;
197
199
 
200
+ /** The NI code of the metal markets: prices, futures, bullion and the trusts that hold it, not a miner's releases. */
201
+ export const METALS_NEWS_TOPIC = "metals";
202
+ /** The topic the service tags oil, gas and power market stories with. */
203
+ export const ENERGY_NEWS_TOPIC = "energy";
204
+
205
+ /**
206
+ * What a ticker no story is filed under is searched by: a coin pair's coin
207
+ * ("bitcoin" for BTC-USD), or a futures board symbol's commodity ("cocoa" for
208
+ * CC=F), as `news` searches them. A metal's future (GC=F, SI=F, HG=F, PL=F,
209
+ * PA=F, ALI=F) searches the metals stories only, as `news GC=F` does: the
210
+ * stories that merely name gold are mostly miners' releases. Null for
211
+ * anything else, and for a future with no commodity name (ES=F, ZN=F).
212
+ */
213
+ function newsFallbackSearch(query: Pick<NewsQuery, "ticker" | "exchange" | "listingName">): { text: string; topics?: string[] } | null {
214
+ const coin = coinSearchName(query.ticker, query.exchange, query.listingName);
215
+ if (coin) return { text: coin };
216
+ const future = query.ticker ? futuresBoardContractForTicker(parsePublicTickerKey(query.ticker).symbol) : null;
217
+ const text = future ? commoditySearchName(future) : null;
218
+ if (!future || !text) return null;
219
+ return future.sector === "metals" ? { text, topics: [METALS_NEWS_TOPIC] } : { text };
220
+ }
221
+
198
222
  /**
199
223
  * A news query's first page from Gloom Cloud. Stories are filed under company
200
- * tickers, and a coin pair (BTC-USD) rarely has any filed under it, so its
201
- * empty feed falls back to the stories that mention the coin ("bitcoin"),
202
- * marked with what was searched. A later page, a failed search or a coin with
203
- * no name to search keeps the empty answer.
224
+ * tickers, and a coin pair (BTC-USD) or a future (CC=F) rarely has any filed
225
+ * under it, so its empty feed falls back to the stories that mention the coin
226
+ * or the commodity ("bitcoin", "cocoa"), marked with what was searched. A
227
+ * later page, a failed search or a ticker with no name to search keeps the
228
+ * empty answer.
204
229
  */
205
230
  export async function readCloudNews(client: CloudNewsClient, query: NewsQuery): Promise<CloudNewsRead> {
206
231
  // Asked in the tick the request goes out in, which is when its headers take the session.
@@ -208,16 +233,16 @@ export async function readCloudNews(client: CloudNewsClient, query: NewsQuery):
208
233
  const response = await client.getCloudNews(cloudNewsParams(query));
209
234
  const read: CloudNewsRead = { ...response, access: cloudNewsAccess(response, sentSession) };
210
235
  if (response.items.length > 0 || query.cursor || normalizeNewsFeed(query) !== "ticker") return read;
211
- const text = coinSearchName(query.ticker, query.exchange, query.listingName);
212
- if (!text) return read;
213
- const found = await client.searchCloudNews(text, query.limit)
214
- .catch(logFailure("sources.gloomberb-cloud.news", "Search a coin's stories failed", null));
236
+ const search = newsFallbackSearch(query);
237
+ if (!search) return read;
238
+ const found = await client.searchCloudNews(search.text, query.limit, search.topics)
239
+ .catch(logFailure("sources.gloomberb-cloud.news", "Search the stories that mention a ticker's coin or commodity failed", null));
215
240
  return found && found.items.length > 0
216
- ? { items: found.items, nextCursor: null, searchedFor: text, access: cloudNewsAccess(found, sentSession) }
241
+ ? { items: found.items, nextCursor: null, searchedFor: search.text, access: cloudNewsAccess(found, sentSession) }
217
242
  : read;
218
243
  }
219
244
 
220
- /** A read's stories as articles, each marked with the text a coin's fallback searched for. */
245
+ /** A read's stories as articles, each marked with the text a coin's or a future's fallback searched for. */
221
246
  export function cloudNewsReadArticles(read: CloudNewsRead, ticker?: string): NewsArticle[] {
222
247
  return read.items.map((item) => {
223
248
  const article = mapCloudNewsArticle(item, read.searchedFor ? undefined : ticker);
@@ -225,7 +250,7 @@ export function cloudNewsReadArticles(read: CloudNewsRead, ticker?: string): New
225
250
  });
226
251
  }
227
252
 
228
- /** What a pane or report says above the stories a coin's fallback found: "No stories are filed under BTC-USD; these mention bitcoin." */
229
- export function coinNewsFallbackNotice(ticker: string, searchedFor: string): string {
253
+ /** What a pane or report says above the stories a fallback found: "No stories are filed under CC=F; these mention cocoa." */
254
+ export function newsFallbackNotice(ticker: string, searchedFor: string): string {
230
255
  return `No stories are filed under ${ticker}; these mention ${searchedFor}.`;
231
256
  }
@@ -0,0 +1,47 @@
1
+ import { useSyncExternalStore } from "react";
2
+
3
+ /**
4
+ * Panes placed before their ticker is found. Opening a ticker the app does
5
+ * not hold yet looks it up over the network (search, then its quote), which
6
+ * can take seconds; the pane shows at once and the lookup settles it. Until
7
+ * then the pane has a symbol and no ticker record, and says it is loading
8
+ * rather than that no ticker is selected.
9
+ */
10
+ const opening = new Set<string>();
11
+ const listeners = new Set<() => void>();
12
+
13
+ function changed(): void {
14
+ for (const listener of listeners) listener();
15
+ }
16
+
17
+ /** Marks a pane as opening; the returned stop clears it, once. */
18
+ export function markTickerPaneOpening(instanceId: string): () => void {
19
+ opening.add(instanceId);
20
+ changed();
21
+ let stopped = false;
22
+ return () => {
23
+ if (stopped) return;
24
+ stopped = true;
25
+ if (opening.delete(instanceId)) changed();
26
+ };
27
+ }
28
+
29
+ export function isTickerPaneOpening(instanceId: string | null | undefined): boolean {
30
+ return !!instanceId && opening.has(instanceId);
31
+ }
32
+
33
+ function subscribe(listener: () => void): () => void {
34
+ listeners.add(listener);
35
+ return () => {
36
+ listeners.delete(listener);
37
+ };
38
+ }
39
+
40
+ /** Whether the pane's ticker is still being looked up. */
41
+ export function useTickerPaneOpening(instanceId: string | null | undefined): boolean {
42
+ return useSyncExternalStore(subscribe, () => isTickerPaneOpening(instanceId), () => false);
43
+ }
44
+
45
+ export function resetOpeningTickerPanesForTests(): void {
46
+ opening.clear();
47
+ }
@@ -23,6 +23,8 @@ export function createTestCliContext(
23
23
  persistence: { close: () => { closed += 1; } },
24
24
  // Commands look up the saved listing of every symbol they are given.
25
25
  store: { loadTicker: async () => null, loadAllTickers: async () => [] },
26
+ // A yen pair's notes read Japan's intervention record from Gloom Cloud; a test has none unless it brings one.
27
+ fxInterventions: async () => null,
26
28
  ...market,
27
29
  });
28
30
  const context = {
@@ -1,6 +1,7 @@
1
1
  import { beforeEach } from "bun:test";
2
2
  import { resetSeenPaneNoticesForTest } from "../components/pane-notice-seen";
3
3
  import { resetListingIndexForTests } from "../tickers/search/listing-index";
4
+ import { resetOpeningTickerPanesForTests } from "../state/opening-ticker-panes";
4
5
  import { resetCrashReporterForTests } from "../telemetry/crash-reports";
5
6
  import { setCliAsciiLocaleOverride, setCliColorEnabledOverride, setCliPlainOverride, setCliWidthOverride } from "../utils/cli-output";
6
7
 
@@ -19,12 +20,14 @@ import { setCliAsciiLocaleOverride, setCliColorEnabledOverride, setCliPlainOverr
19
20
  * Data warnings the user has opened are remembered the same way, and would
20
21
  * leave a later test's footer icon muted instead of warning yellow. So are the
21
22
  * listings search answered, which would name a later test's symbol before its
22
- * own search does.
23
+ * own search does, and so are panes still waiting on a ticker lookup, which
24
+ * would show a later test's pane as loading.
23
25
  */
24
26
  beforeEach(() => {
25
27
  resetCrashReporterForTests();
26
28
  resetSeenPaneNoticesForTest();
27
29
  resetListingIndexForTests();
30
+ resetOpeningTickerPanesForTests();
28
31
  setCliAsciiLocaleOverride(null);
29
32
  setCliColorEnabledOverride(null);
30
33
  setCliPlainOverride(null);
@@ -149,8 +149,26 @@ export function isCryptoVenuePerpetual(type: string | null | undefined, name: st
149
149
  }
150
150
 
151
151
  /**
152
- * A listing's type, in plain words where the provider's type misleads (a
153
- * perpetual typed as a coin). `detail` says what it is not, for a report line.
152
+ * A quote type's code in the words the other types are written in ("Common
153
+ * Stock", "Depositary Receipt"), so one search lists one vocabulary. A generic
154
+ * EQUITY is any share, a receipt's too, so it reads as Stock, never Common
155
+ * Stock. A broker's own codes (STK, CASH) stay as the broker files them.
156
+ */
157
+ const TYPE_CODE_WORDS: Record<string, string> = {
158
+ EQUITY: "Stock",
159
+ CRYPTOCURRENCY: "Cryptocurrency",
160
+ INDEX: "Index",
161
+ FUTURE: "Future",
162
+ MUTUALFUND: "Mutual Fund",
163
+ MONEYMARKET: "Money Market Fund",
164
+ CURRENCY: "Currency",
165
+ OPTION: "Option",
166
+ };
167
+
168
+ /**
169
+ * A listing's type, in plain words: a provider's type code as the words the
170
+ * others use, and where the type misleads (a perpetual typed as a coin), what
171
+ * it is. `detail` says what it is not, for a report line.
154
172
  */
155
173
  export function instrumentTypeLabel(
156
174
  type: string | null | undefined,
@@ -161,5 +179,7 @@ export function instrumentTypeLabel(
161
179
  return options.detail ? "Perpetual futures price (24/7 on crypto venues; not the listed future, not spot)" : "Perpetual futures price";
162
180
  }
163
181
  if (classifyInstrumentType(type) === "perpetual") return "Perpetual futures";
164
- return type?.trim() || undefined;
182
+ const written = type?.trim();
183
+ // Only a code: a type written in words ("Equity Fund") stays as written.
184
+ return (written && written === written.toUpperCase() ? TYPE_CODE_WORDS[written] : undefined) ?? (written || undefined);
165
185
  }