@gloom-sh/terminal 0.19.5 → 0.20.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.
Files changed (318) hide show
  1. package/LICENSE +0 -4
  2. package/package.json +6 -5
  3. package/patches/@opentui%2Fcore@0.3.2.patch +86 -25
  4. package/patches/electrobun-devkit@2.0.5.patch +148 -0
  5. package/src/api-client/bond-trades.ts +59 -0
  6. package/src/api-client/data.ts +21 -0
  7. package/src/api-client/equity-screener.ts +23 -0
  8. package/src/api-client/index.ts +2 -0
  9. package/src/api-client/types/account.ts +86 -0
  10. package/src/api-client/types/assist.ts +32 -0
  11. package/src/api-client/types/auth.ts +63 -0
  12. package/src/api-client/types/billing.ts +54 -0
  13. package/src/api-client/types/chat.ts +180 -0
  14. package/src/api-client/types/congress.ts +107 -0
  15. package/src/api-client/types/credit.ts +110 -0
  16. package/src/api-client/types/econ.ts +158 -0
  17. package/src/api-client/types/equity-diagnostic.ts +73 -0
  18. package/src/api-client/types/filings-and-calls.ts +350 -0
  19. package/src/api-client/types/index.ts +25 -0
  20. package/src/api-client/types/jobs.ts +147 -0
  21. package/src/api-client/types/market.ts +122 -0
  22. package/src/api-client/types/news.ts +91 -0
  23. package/src/api-client/types/notes-and-theses.ts +172 -0
  24. package/src/api-client/types/quotes.ts +28 -0
  25. package/src/api-client/types/scanners.ts +125 -0
  26. package/src/api-client/types/screener.ts +65 -0
  27. package/src/api-client/types/search.ts +107 -0
  28. package/src/api-client/types/sync.ts +14 -0
  29. package/src/api-client/types/team-collections.ts +43 -0
  30. package/src/api-client/types/team-views.ts +32 -0
  31. package/src/api-client/types/teams.ts +135 -0
  32. package/src/api-client/types/ticker-data.ts +57 -0
  33. package/src/api-client/types/tweets.ts +59 -0
  34. package/src/api-client/types/world-venues.ts +23 -0
  35. package/src/app/pane-runtime/index.tsx +2 -0
  36. package/src/app/pane-runtime/plugin-bindings.ts +10 -1
  37. package/src/app/runtime/desktop-deeplink.ts +41 -6
  38. package/src/app/star-prompt/status-line.tsx +1 -1
  39. package/src/app.tsx +64 -23
  40. package/src/architecture/ui-tokens-allowlist.json +0 -8
  41. package/src/cli/commands/market.ts +149 -10
  42. package/src/cli/commands/search.ts +21 -3
  43. package/src/cli/commands/ticker.ts +90 -36
  44. package/src/cli/desktop-pane-shot-browser.ts +69 -3
  45. package/src/cli/glossary.ts +3 -3
  46. package/src/cli/known-gaps.ts +8 -0
  47. package/src/cli/listing-arg.ts +12 -0
  48. package/src/cli/pane-functions/capabilities.ts +2 -0
  49. package/src/cli/pane-functions/catalog.ts +25 -5
  50. package/src/cli/pane-functions/function-help.ts +8 -5
  51. package/src/cli/pane-functions/headless.ts +4 -3
  52. package/src/cli/pane-functions/resolver.ts +75 -2
  53. package/src/cli/quote-answer.ts +9 -0
  54. package/src/cli/symbol-list.ts +54 -2
  55. package/src/cli/symbol-rows.ts +14 -2
  56. package/src/cli/ticker-resolution.ts +89 -20
  57. package/src/components/chart/composite/axis-overlays.tsx +60 -27
  58. package/src/components/chart/composite/composite-chart.tsx +118 -63
  59. package/src/components/chart/composite/cursor-source.ts +111 -0
  60. package/src/components/chart/composite/format.ts +168 -6
  61. package/src/components/chart/composite/legend.tsx +8 -4
  62. package/src/components/chart/composite/panel-labels.ts +20 -1
  63. package/src/components/chart/composite/panel-surface.tsx +201 -92
  64. package/src/components/chart/composite/price-axis-labels.tsx +92 -46
  65. package/src/components/chart/composite/price-series.ts +31 -8
  66. package/src/components/chart/composite/scene.ts +154 -59
  67. package/src/components/chart/composite/series-axis-tags.tsx +4 -2
  68. package/src/components/chart/composite/time-axis.ts +13 -5
  69. package/src/components/chart/composite/time-scale.ts +211 -56
  70. package/src/components/chart/composite/types.ts +11 -1
  71. package/src/components/chart/composite/use-composite-chart-keyboard.ts +43 -14
  72. package/src/components/chart/curve/curve-surface.tsx +5 -2
  73. package/src/components/chart/curve/model.ts +4 -1
  74. package/src/components/chart/native/use-bitmap-metrics.ts +81 -0
  75. package/src/components/chart/static/series.ts +3 -0
  76. package/src/components/command-bar/commands/collection-list.ts +81 -0
  77. package/src/components/command-bar/commands/direct/index.ts +6 -0
  78. package/src/components/command-bar/commands/registry.ts +8 -0
  79. package/src/components/command-bar/layout-items/current-layout.ts +22 -1
  80. package/src/components/command-bar/layout-items/focused-pane.ts +22 -1
  81. package/src/components/command-bar/pane-templates/items.ts +19 -3
  82. package/src/components/command-bar/pane-templates/workflow.ts +5 -0
  83. package/src/components/command-bar/routes/root/results.ts +23 -3
  84. package/src/components/command-bar/routes/root/selection.ts +4 -2
  85. package/src/components/command-bar/routes/root/shortcut-feedback.ts +1 -1
  86. package/src/components/command-bar/routes/root/shortcut-items.ts +3 -4
  87. package/src/components/command-bar/routes/root/shortcuts.ts +58 -14
  88. package/src/components/command-bar/routes/root/ticker-first.ts +32 -0
  89. package/src/components/command-bar/surface/environment.ts +2 -0
  90. package/src/components/command-bar/view-model.ts +7 -0
  91. package/src/components/command-bar/workflow/ops.ts +2 -1
  92. package/src/components/command-bar/workflow/tickers.ts +20 -0
  93. package/src/components/data-table/export.ts +4 -1
  94. package/src/components/layout/detached-pane-shell.tsx +10 -37
  95. package/src/components/layout/double-escape-close.ts +90 -0
  96. package/src/components/layout/header.tsx +3 -2
  97. package/src/components/layout/market-summary.ts +6 -3
  98. package/src/components/layout/pane/footer/index.tsx +2 -6
  99. package/src/components/layout/pane/footer/model.ts +6 -12
  100. package/src/components/layout/shell/active-drag.ts +53 -11
  101. package/src/components/layout/shell/drag/magnets.ts +128 -19
  102. package/src/components/layout/shell/menu.ts +15 -1
  103. package/src/components/layout/shell/pane/actions.ts +10 -2
  104. package/src/components/layout/shell/pane/management-shortcuts.ts +13 -51
  105. package/src/components/layout/shell/ticker-link-menu.ts +12 -3
  106. package/src/components/layout/status-bar.tsx +24 -78
  107. package/src/components/layout/status-widget-space.ts +5 -5
  108. package/src/components/onboarding/onboarding-keyboard.ts +5 -1
  109. package/src/components/onboarding/onboarding-wizard.tsx +15 -4
  110. package/src/components/onboarding/portfolio-step/positions-panel.tsx +9 -6
  111. package/src/components/onboarding/use-onboarding-progress.ts +20 -1
  112. package/src/components/price-sparkline/view.tsx +14 -6
  113. package/src/components/ticker/badge/index.tsx +8 -4
  114. package/src/components/ticker/badge/list.tsx +23 -7
  115. package/src/components/ui/column-grid.tsx +8 -2
  116. package/src/components/ui/data-table/index.tsx +5 -1
  117. package/src/components/ui/data-table/opentui/model.ts +4 -1
  118. package/src/components/ui/data-table/render-cell.ts +19 -0
  119. package/src/components/ui/delayed-mark.tsx +59 -7
  120. package/src/components/ui/icon.tsx +1 -8
  121. package/src/components/ui/menu.tsx +6 -1
  122. package/src/components/ui/tabs.tsx +5 -2
  123. package/src/core/state/app/layout.ts +18 -3
  124. package/src/core/state/app/state.ts +2 -0
  125. package/src/core/state/app/types.ts +5 -0
  126. package/src/data/config/layout.ts +3 -0
  127. package/src/data/config/store/normalize.ts +39 -4
  128. package/src/i18n/es.ts +13 -3
  129. package/src/i18n/ja.ts +13 -3
  130. package/src/i18n/ko.ts +13 -3
  131. package/src/i18n/zh-cn.ts +13 -3
  132. package/src/i18n/zh-tw.ts +13 -3
  133. package/src/layout/pane-manager/floating-placement.ts +7 -4
  134. package/src/layout/pane-manager/floating.ts +5 -2
  135. package/src/market-data/bond-funds.ts +19 -0
  136. package/src/market-data/futures-contract.ts +14 -3
  137. package/src/market-data/market/freshness.ts +18 -0
  138. package/src/market-data/market/status.ts +15 -2
  139. package/src/plugins/builtin/bond-calculator/headless.ts +2 -1
  140. package/src/plugins/builtin/bond-calculator/index.tsx +1 -1
  141. package/src/plugins/builtin/bond-calculator/model.ts +14 -5
  142. package/src/plugins/builtin/bond-calculator/pane.tsx +1 -1
  143. package/src/plugins/builtin/buildout/cells.tsx +25 -45
  144. package/src/plugins/builtin/buildout/detail/company.tsx +3 -3
  145. package/src/plugins/builtin/buildout/detail/index.tsx +1 -1
  146. package/src/plugins/builtin/buildout/detail/intel.tsx +4 -7
  147. package/src/plugins/builtin/buildout/detail/site.tsx +4 -4
  148. package/src/plugins/builtin/buildout/detail/ui.tsx +39 -38
  149. package/src/plugins/builtin/buildout/format.ts +23 -1
  150. package/src/plugins/builtin/buildout/model/types.ts +1 -0
  151. package/src/plugins/builtin/buildout/pane/index.tsx +2 -8
  152. package/src/plugins/builtin/buildout/table-model.ts +12 -4
  153. package/src/plugins/builtin/cds/headless.ts +1 -0
  154. package/src/plugins/builtin/cds/index.tsx +1 -1
  155. package/src/plugins/builtin/chat/content/composer.tsx +21 -27
  156. package/src/plugins/builtin/chat/content/index.tsx +31 -3
  157. package/src/plugins/builtin/chat/content/shortcuts.ts +4 -2
  158. package/src/plugins/builtin/chat/content/snapshot.ts +0 -3
  159. package/src/plugins/builtin/cloud/auth-actions.tsx +51 -23
  160. package/src/plugins/builtin/cloud/plugin.tsx +2 -0
  161. package/src/plugins/builtin/cloud/trial-offer-status-widget.tsx +3 -3
  162. package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +44 -12
  163. package/src/plugins/builtin/congress-trades/model.ts +2 -1
  164. package/src/plugins/builtin/congress-trades/pane.tsx +3 -0
  165. package/src/plugins/builtin/correlation/headless.ts +3 -2
  166. package/src/plugins/builtin/crypto-board/pane.tsx +5 -4
  167. package/src/plugins/builtin/custom-view/index.tsx +1 -1
  168. package/src/plugins/builtin/custom-view/loader.ts +85 -8
  169. package/src/plugins/builtin/custom-view/view-spec.ts +28 -0
  170. package/src/plugins/builtin/debt-maturities/headless.ts +11 -2
  171. package/src/plugins/builtin/debt-maturities/model.ts +66 -0
  172. package/src/plugins/builtin/debt-maturities/pane.tsx +23 -4
  173. package/src/plugins/builtin/earnings-ripple/pane.tsx +1 -1
  174. package/src/plugins/builtin/econ/calendar-model.ts +28 -6
  175. package/src/plugins/builtin/equity-screener/client.ts +1 -1
  176. package/src/plugins/builtin/equity-screener/criterion-editor.tsx +16 -19
  177. package/src/plugins/builtin/equity-screener/headless.ts +37 -3
  178. package/src/plugins/builtin/equity-screener/ideas.ts +67 -3
  179. package/src/plugins/builtin/equity-screener/model.ts +238 -27
  180. package/src/plugins/builtin/equity-screener/pane.tsx +88 -18
  181. package/src/plugins/builtin/equity-screener/screen-check.ts +7 -4
  182. package/src/plugins/builtin/equity-screener/watchlist.ts +33 -0
  183. package/src/plugins/builtin/executives/format.ts +5 -4
  184. package/src/plugins/builtin/executives/pane.tsx +1 -1
  185. package/src/plugins/builtin/futures-curve/client.ts +19 -0
  186. package/src/plugins/builtin/futures-curve/headless.ts +52 -13
  187. package/src/plugins/builtin/futures-curve/index.tsx +1 -1
  188. package/src/plugins/builtin/futures-curve/model.ts +77 -6
  189. package/src/plugins/builtin/futures-curve/pane.tsx +19 -3
  190. package/src/plugins/builtin/help/index.tsx +55 -1
  191. package/src/plugins/builtin/insider/model.ts +30 -2
  192. package/src/plugins/builtin/jobs/model.ts +2 -2
  193. package/src/plugins/builtin/macro-day/client.ts +41 -0
  194. package/src/plugins/builtin/macro-day/headless.ts +19 -9
  195. package/src/plugins/builtin/macro-day/model.ts +3 -1
  196. package/src/plugins/builtin/market-movers/index.tsx +4 -3
  197. package/src/plugins/builtin/mna/distress/headless.ts +1 -0
  198. package/src/plugins/builtin/mna/model.ts +2 -2
  199. package/src/plugins/builtin/notes/files.ts +2 -0
  200. package/src/plugins/builtin/notes/owner.tsx +20 -1
  201. package/src/plugins/builtin/notes/quick-notes-pane.tsx +22 -4
  202. package/src/plugins/builtin/notes/store.ts +6 -1
  203. package/src/plugins/builtin/perps/pane.tsx +3 -1
  204. package/src/plugins/builtin/portfolio-list/cli/bulk-symbols.ts +17 -0
  205. package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +2 -1
  206. package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +2 -1
  207. package/src/plugins/builtin/portfolio-list/header.tsx +1 -1
  208. package/src/plugins/builtin/rate-path/headless.ts +24 -10
  209. package/src/plugins/builtin/research/corporate-actions-pane.tsx +29 -25
  210. package/src/plugins/builtin/research/event-model.ts +10 -3
  211. package/src/plugins/builtin/research/events-headless.ts +20 -2
  212. package/src/plugins/builtin/sec/fund-facts.ts +17 -1
  213. package/src/plugins/builtin/sec/index.tsx +1 -1
  214. package/src/plugins/builtin/series-inventory.ts +1 -0
  215. package/src/plugins/builtin/shared/earnings-report.ts +7 -2
  216. package/src/plugins/builtin/shared/members-menu.tsx +103 -38
  217. package/src/plugins/builtin/shared/use-quote-board.ts +85 -46
  218. package/src/plugins/builtin/short-interest/headless.ts +1 -1
  219. package/src/plugins/builtin/short-interest/model.ts +15 -6
  220. package/src/plugins/builtin/short-interest/publications-model.ts +22 -1
  221. package/src/plugins/builtin/short-interest/publications-pane.tsx +13 -4
  222. package/src/plugins/builtin/short-interest/types.ts +2 -0
  223. package/src/plugins/builtin/short-interest/watch-model.ts +1 -1
  224. package/src/plugins/builtin/thirteenf/overlap-pane.tsx +3 -0
  225. package/src/plugins/builtin/thirteenf/pane.tsx +3 -0
  226. package/src/plugins/builtin/ticker-detail/overview/model.ts +5 -3
  227. package/src/plugins/builtin/ticker-detail/overview-tab.tsx +4 -4
  228. package/src/plugins/builtin/time-sales/pane.tsx +3 -2
  229. package/src/plugins/builtin/trace-bonds/client.ts +7 -4
  230. package/src/plugins/builtin/trace-bonds/detail.tsx +198 -0
  231. package/src/plugins/builtin/trace-bonds/headless.ts +62 -4
  232. package/src/plugins/builtin/trace-bonds/history.ts +155 -0
  233. package/src/plugins/builtin/trace-bonds/index.tsx +1 -1
  234. package/src/plugins/builtin/trace-bonds/pane.tsx +64 -5
  235. package/src/plugins/builtin/volatility/client.ts +6 -1
  236. package/src/plugins/builtin/volatility/headless.ts +0 -1
  237. package/src/plugins/builtin/yield-curve/curves.ts +15 -0
  238. package/src/plugins/builtin/yield-curve/headless.ts +6 -1
  239. package/src/plugins/builtin/yield-curve/index.tsx +5 -8
  240. package/src/plugins/host-modules.ts +22 -3
  241. package/src/plugins/host-smoke.ts +6 -3
  242. package/src/plugins/installer.ts +16 -3
  243. package/src/plugins/plugin-names.ts +11 -2
  244. package/src/portfolio/collection-name.ts +19 -0
  245. package/src/remote/controller.ts +9 -2
  246. package/src/remote/schema.ts +2 -1
  247. package/src/renderers/browser/http-proxy-transport.ts +78 -8
  248. package/src/renderers/cloudflare/http-proxy.ts +73 -3
  249. package/src/renderers/cloudflare/proxy-session.ts +47 -24
  250. package/src/renderers/cloudflare/worker.ts +44 -4
  251. package/src/renderers/desktop/geometry.ts +279 -0
  252. package/src/renderers/desktop/screen-setup.ts +246 -0
  253. package/src/renderers/desktop/sequential-window-host.ts +179 -0
  254. package/src/renderers/desktop/test-utils.ts +71 -0
  255. package/src/renderers/desktop/window-controller.ts +433 -0
  256. package/src/renderers/desktop/window-host.ts +70 -0
  257. package/src/renderers/desktop/window-layouts.ts +630 -0
  258. package/src/renderers/dom/data-frames.ts +15 -4
  259. package/src/renderers/dom/desktop/icons.tsx +0 -2
  260. package/src/renderers/dom/styles.css +0 -3
  261. package/src/renderers/electrobun/bun/application-menu/click.ts +1 -0
  262. package/src/renderers/electrobun/bun/application-menu/index.ts +4 -1
  263. package/src/renderers/electrobun/bun/desktop/backend-requests.ts +19 -8
  264. package/src/renderers/electrobun/bun/desktop/backend.ts +320 -19
  265. package/src/renderers/electrobun/bun/desktop/detached-windows.ts +83 -61
  266. package/src/renderers/electrobun/bun/desktop/host-requests.ts +4 -14
  267. package/src/renderers/electrobun/bun/desktop/initialization.ts +30 -11
  268. package/src/renderers/electrobun/bun/desktop/install-records.ts +59 -0
  269. package/src/renderers/electrobun/bun/desktop/installer-folder.ts +208 -592
  270. package/src/renderers/electrobun/bun/desktop/macos-objc.ts +14 -0
  271. package/src/renderers/electrobun/bun/desktop/screen-setup-file.ts +55 -0
  272. package/src/renderers/electrobun/bun/desktop/state-broadcaster.ts +44 -8
  273. package/src/renderers/electrobun/bun/desktop/update.ts +1 -1
  274. package/src/renderers/electrobun/bun/desktop/workspace/index.ts +298 -97
  275. package/src/renderers/electrobun/bun/desktop/workspace/requests.ts +44 -6
  276. package/src/renderers/electrobun/bun/index.ts +22 -109
  277. package/src/renderers/electrobun/bun/window/create.ts +23 -3
  278. package/src/renderers/electrobun/bun/window/electrobun-window-host.ts +306 -0
  279. package/src/renderers/electrobun/bun/window/events.ts +4 -4
  280. package/src/renderers/electrobun/bun/window/focus.ts +0 -25
  281. package/src/renderers/electrobun/bun/window/frame.ts +2 -1
  282. package/src/renderers/electrobun/bun/window/native-min-size.ts +322 -0
  283. package/src/renderers/electrobun/bun/window/remembered-frame.ts +4 -82
  284. package/src/renderers/electrobun/shared/protocol.ts +44 -2
  285. package/src/renderers/electrobun/view/backend-rpc.ts +16 -1
  286. package/src/renderers/electrobun/view/desktop/window/bridge.ts +63 -3
  287. package/src/renderers/electrobun/view/main.tsx +13 -7
  288. package/src/series/fred-argument.ts +17 -0
  289. package/src/sources/gloomberb-cloud/index.ts +5 -7
  290. package/src/sources/provider-router/batches.ts +18 -3
  291. package/src/sources/provider-router/financial-routes.ts +7 -1
  292. package/src/sources/provider-router/financials.ts +18 -4
  293. package/src/state/app/context/index.tsx +16 -2
  294. package/src/state/desktop-windows.ts +63 -0
  295. package/src/sync/other-window-tabs.ts +62 -0
  296. package/src/tickers/company-name-listing.ts +23 -3
  297. package/src/tickers/listing-fate.ts +147 -1
  298. package/src/tickers/terminal-codes.ts +5 -0
  299. package/src/time-series/types.ts +6 -0
  300. package/src/types/config.ts +10 -1
  301. package/src/types/data-provider.ts +14 -0
  302. package/src/types/desktop-window.ts +71 -2
  303. package/src/types/financials.ts +19 -3
  304. package/src/types/headless.ts +21 -0
  305. package/src/types/plugin.ts +6 -0
  306. package/src/ui/index.tsx +14 -13
  307. package/src/ui/same-props.ts +58 -0
  308. package/src/utils/cli-output.ts +33 -4
  309. package/src/utils/double-escape-close.ts +38 -16
  310. package/src/utils/format.ts +30 -5
  311. package/src/utils/futures-generic.ts +12 -0
  312. package/src/utils/http-proxy-upstream.ts +6 -2
  313. package/src/utils/plugin-proxy-hosts.json +0 -4
  314. package/src/utils/plugin-proxy-hosts.ts +22 -0
  315. package/src/utils/price-earnings.ts +18 -0
  316. package/src/utils/sec-filings.ts +7 -1
  317. package/patches/electrobun@1.18.1.patch +0 -633
  318. package/src/api-client/types.ts +0 -2441
@@ -1,6 +1,6 @@
1
- import { useCallback, useEffect, useMemo } from "react";
1
+ import { useCallback, useEffect, useMemo, useRef } from "react";
2
2
  import {
3
- DataTableView,
3
+ DataTableStackView,
4
4
  loadingText,
5
5
  Notice,
6
6
  QueryBar,
@@ -13,6 +13,8 @@ import {
13
13
  type DataTableRootKeyContext,
14
14
  } from "../../../components";
15
15
  import { usePaneRefreshKey } from "../../../components/data-table/table-pane";
16
+ import { apiClient } from "../../../api-client";
17
+ import { usePlanAccess } from "../../../api-client/plan-access";
16
18
  import { useAsyncResource } from "../../../react/async-resource";
17
19
  import { useAutoRefresh } from "../../../react/auto-refresh";
18
20
  import { usePaneInstance } from "../../../state/app/context";
@@ -31,6 +33,8 @@ import {
31
33
  quotedCompanyName,
32
34
  type CorporateBond,
33
35
  } from "./client";
36
+ import { BondHistoryDetail } from "./detail";
37
+ import { loadStoredBond, PRO_HISTORY_TEXT } from "./history";
34
38
  import {
35
39
  DEFAULT_BOND_SORT,
36
40
  TRACE_BONDS_PANE_ID,
@@ -55,6 +59,12 @@ function dash(value: string | null): string {
55
59
  return value ?? "—";
56
60
  }
57
61
 
62
+ /** What a bond's detail is called: its issuer, coupon and maturity, as a bond is named. */
63
+ function bondTitle(bond: CorporateBond): string {
64
+ return [bond.issuerName, bond.couponRate == null ? null : formatBondDecimal(bond.couponRate, 3), bond.maturityDate]
65
+ .filter(Boolean).join(" ");
66
+ }
67
+
58
68
  export function TraceBondsPane({ focused, width, height }: PaneProps) {
59
69
  const presetIssuer = usePaneInstance()?.params?.issuer ?? "";
60
70
  const [query, setQuery] = usePluginPaneState("issuer", presetIssuer);
@@ -73,7 +83,6 @@ export function TraceBondsPane({ focused, width, height }: PaneProps) {
73
83
  const { active: searchActive, focus: focusSearch, searchProps } = useQueryBarSearch();
74
84
 
75
85
  useAutoRefresh(updatedAt, load);
76
- usePaneRefreshKey(() => void reload(), { focused, enabled: !searchActive });
77
86
 
78
87
  // One issuer's tape says its name once, in what was asked, not on every row.
79
88
  const sharedIssuer = useMemo(() => sharesOneIssuer(bonds), [bonds]);
@@ -99,6 +108,38 @@ export function TraceBondsPane({ focused, width, height }: PaneProps) {
99
108
  if (!selectedId || !rows.some((row) => row.id === selectedId)) setSelectedId(rows[0]!.id);
100
109
  }, [answered, rows, selectedId, setSelectedId]);
101
110
 
111
+ // A bond opens on its kept prints: Enter on a row, and with Gloom Pro a CUSIP looked up opens on its own once.
112
+ const [detailOpen, setDetailOpen] = usePluginPaneState("detailOpen", false);
113
+ const selectedBond = rows.find((row) => row.id === selectedId) ?? null;
114
+ const access = usePlanAccess();
115
+ const pro = access.hasProAccess;
116
+ const openedFor = useRef<string | null>(null);
117
+ const asked = answered ? data.query : null;
118
+ useEffect(() => {
119
+ if (!pro || asked?.kind !== "cusip" || rows.length !== 1 || openedFor.current === asked.cusip) return;
120
+ openedFor.current = asked.cusip;
121
+ setDetailOpen(true);
122
+ }, [asked, pro, rows.length, setDetailOpen]);
123
+ // A ticker looked up keeps its company's bonds from now on, as `fn TRACE` does; nothing waits on it.
124
+ useEffect(() => {
125
+ if (!pro || asked?.kind !== "issuer" || !asked.ticker) return;
126
+ const controller = new AbortController();
127
+ void apiClient.getCloudStoredIssuerBonds(asked.ticker, { signal: controller.signal }).catch(() => {
128
+ // Intentional ignore: keeping the company's bonds is a side effect; the tape shows without it.
129
+ });
130
+ return () => controller.abort();
131
+ }, [asked, pro]);
132
+ const detailCusip = detailOpen && selectedBond?.cusip ? selectedBond.cusip : null;
133
+ const historyRequest = useCallback(() => loadStoredBond(detailCusip!, apiClient), [detailCusip]);
134
+ const history = useAsyncResource(detailCusip && pro ? historyRequest : null);
135
+ // Without Pro, refused or failed: the detail says why in place of the prints.
136
+ const historyRefusal = !pro ? PRO_HISTORY_TEXT
137
+ : history.data?.refusal ?? (history.error && !history.data ? unavailableText("Kept price history") : null);
138
+ usePaneRefreshKey(() => {
139
+ void reload();
140
+ if (detailCusip && pro) history.load();
141
+ }, { focused, enabled: !searchActive });
142
+
102
143
  const onHeaderClick = useCallback((columnId: string) => {
103
144
  if (!isBondColumnId(columnId)) return;
104
145
  setSort((current) => nextHeaderSort(shownBondSort(current, sharedIssuer), columnId, {
@@ -154,7 +195,7 @@ export function TraceBondsPane({ focused, width, height }: PaneProps) {
154
195
  // A failure or a load for another query is the table's own message; the footer keeps the answered query's status.
155
196
  usePaneStatusFooter({
156
197
  registrationId: TRACE_BONDS_PANE_ID,
157
- loading: loading && answered,
198
+ loading: (loading && answered) || (!!detailCusip && history.loading && !history.data),
158
199
  error: answered ? error : null,
159
200
  info: footerInfo,
160
201
  });
@@ -165,8 +206,26 @@ export function TraceBondsPane({ focused, width, height }: PaneProps) {
165
206
  });
166
207
 
167
208
  return (
168
- <DataTableView
209
+ <DataTableStackView
169
210
  focused={focused && !searchActive}
211
+ detailOpen={detailOpen && !!selectedBond}
212
+ onBack={() => setDetailOpen(false)}
213
+ detailTitle={selectedBond ? bondTitle(selectedBond) : undefined}
214
+ detailContent={selectedBond ? (
215
+ <BondHistoryDetail
216
+ bond={selectedBond}
217
+ history={history.data?.history ?? null}
218
+ loading={!!detailCusip && pro && history.loading && !history.data}
219
+ refusal={historyRefusal}
220
+ focused={focused && detailOpen}
221
+ width={width}
222
+ height={Math.max(0, height - 1)}
223
+ />
224
+ ) : null}
225
+ onActivate={(row) => {
226
+ setSelectedId(row.id);
227
+ setDetailOpen(true);
228
+ }}
170
229
  rootWidth={width}
171
230
  rootHeight={height}
172
231
  rootBefore={(
@@ -16,7 +16,12 @@ import { abortable, abortError } from "../../../utils/async-deadline";
16
16
  import { errorMessage } from "../../../utils/errors";
17
17
  import { savedCopyAt } from "../../../data/saved-copies";
18
18
 
19
- const VOLATILITY_LOAD_CONCURRENCY = 4;
19
+ /**
20
+ * Source reads in flight at once: the board's 23 closes and series in three
21
+ * rounds, not six. Each round is a request's wait, which a shot of the board
22
+ * and `fn VIX` sit through in turn.
23
+ */
24
+ const VOLATILITY_LOAD_CONCURRENCY = 8;
20
25
  const VOLATILITY_HISTORY_LIMIT = 400;
21
26
  export interface VolatilityLoadResult {
22
27
  data: VolatilityData;
@@ -56,7 +56,6 @@ export function createVolatilityHeadless(dependencies: VolatilityHeadlessDepende
56
56
  discovery: { screenshotReadiness: "live-dom", limitations: [
57
57
  "Daily histories may contain isolated index observations; sparse coverage has no daily change or annual percentile.",
58
58
  "Thin histories do not support daily changes or one-year percentiles.",
59
- "The existing sources do not supply a VIX futures curve.",
60
59
  ] },
61
60
  async load(args, context) {
62
61
  const result = await dependencies.load(args, context);
@@ -6,6 +6,8 @@ import type { CurveBasis } from "./forward";
6
6
  import { yieldSpreads, type YieldLookbackCurves } from "./chart";
7
7
  import { completeYieldCurve, loadHistoricalYieldCurve, yieldCurveDate } from "./history";
8
8
  import { DATE_OPTION_FORMATS, dateOptionHint, readCalendarDate } from "../../../utils/calendar-date";
9
+ import { formatBasisPoints } from "../../../utils/basis-points";
10
+ import { formatPercentileRank } from "../../../utils/format";
9
11
  import { isYieldObservationDate, loadYieldCurve, type YieldPoint } from "./treasury-data";
10
12
 
11
13
  export type CurveId = CloudCurveId;
@@ -166,6 +168,19 @@ export function curveSpreadFigures(data: CurveData | null, lookbacks: YieldLookb
166
168
  .map(({ id, spread, change1d }) => ({ id, value: spread, change1d, percentile1y: null }));
167
169
  }
168
170
 
171
+ /**
172
+ * A spread as GC reads it, the pane's figure and the report's row alike: its
173
+ * level ("+38bp"), and under it the day's move and where it sits in the last
174
+ * year ("+1bp 1D · 20 pctl 1Y"), the rank left out when the source has none.
175
+ */
176
+ export function curveSpreadText(figure: CurveSpreadFigure): { value: string; detail: string } {
177
+ return {
178
+ value: figure.value == null ? "--" : formatBasisPoints(figure.value),
179
+ detail: [`${figure.change1d == null ? "--" : formatBasisPoints(figure.change1d)} 1D`,
180
+ ...(figure.percentile1y == null ? [] : [formatPercentileRank(figure.percentile1y, "1Y")])].join(" · "),
181
+ };
182
+ }
183
+
169
184
  /**
170
185
  * A curve on the requested date (its last session on or before it) or its
171
186
  * latest. Treasuries fall back to FRED when the stored curve cannot be read,
@@ -3,7 +3,7 @@ import type {
3
3
  HeadlessPaneDefinition,
4
4
  } from "../../../types/plugin";
5
5
  import {
6
- compareDate, curveCutoff, curveIdOf, curveOption, curveSpreadFigures, curveTenorMove, loadComparePoints,
6
+ compareDate, curveCutoff, curveIdOf, curveOption, curveSpreadFigures, curveSpreadText, curveTenorMove, loadComparePoints,
7
7
  parseCompareInput, parseCurveArgument, unknownCurveMessage, type CurveData, type CurveId,
8
8
  } from "./curves";
9
9
  import { yieldTenorRows, type YieldLookbackCurves } from "./chart";
@@ -241,6 +241,11 @@ export function createYieldCurveHeadless(
241
241
  ...(requestedDate ? { basis: "historical curve" } : { basis: "daily curve", cadence: "daily" }) },
242
242
  ...(comparePoints ? { columns: compareColumns(compareAsOf) } : ranked ? { columns: RANKED_COLUMNS } : {}),
243
243
  ...(ranked ? { notes: [RANK_NOTE] } : {}),
244
+ // The spreads the pane shows over its table, each with its day move and where it sits in the last year.
245
+ ...(spreads.length ? { textSections: [{ title: "Spreads", entries: spreads.map((figure) => {
246
+ const text = curveSpreadText(figure);
247
+ return { key: figure.id, label: figure.id, value: bp(figure.value), formatted: `${text.value} ${text.detail}` };
248
+ }) }] } : {}),
244
249
  rows: rows.map((point) => {
245
250
  const compare = compareAt(point.maturity);
246
251
  const change = tenorRows.get(point.maturity)?.change1d ?? null;
@@ -20,7 +20,6 @@ import { GOVERNMENT_BOND_SERIES, TREASURY_SERIES } from "./series";
20
20
  import { useAutoRefresh } from "../../../react/auto-refresh";
21
21
  import { usePaneStatusFooter } from "../../../components/layout/pane/status-footer";
22
22
  import { savedCopyFooterSegment, type PaneFooterSegment } from "../../../components/layout/pane/footer";
23
- import { formatPercentileRank } from "../../../utils/format";
24
23
  import { SERIES_COLORS } from "../../../theme/series-colors";
25
24
  import type { CurveSeries } from "../../../components/chart/curve";
26
25
  import { yieldCurveHeadless } from "./headless";
@@ -29,7 +28,7 @@ import {
29
28
  type YieldTenorRow,
30
29
  } from "./chart";
31
30
  import {
32
- compareDate, curveCutoff, curveIdOf, CURVE_OPTIONS, curveSpreadFigures, curveTenorMove, loadComparePoints,
31
+ compareDate, curveCutoff, curveIdOf, CURVE_OPTIONS, curveSpreadFigures, curveSpreadText, curveTenorMove, loadComparePoints,
33
32
  parseCompareInput, parseCurveArgument, type CurveId,
34
33
  } from "./curves";
35
34
  import { formatMoveRank, MOVE_HORIZONS } from "../shared/move-rank";
@@ -291,11 +290,9 @@ function CurveTab({ curve, onCurveChange, focused, width, height }: {
291
290
  // last year; an inverted one is the warning the curve's shape gives. Then the
292
291
  // selected tenor's 1D and 1W moves, ranked by size against its whole history.
293
292
  const figures = useMemo<StatItem[]>(() => [
294
- ...curveSpreadFigures(current, lookbackCurves).map(({ id, value, change1d, percentile1y }): StatItem => ({
295
- id, label: id, value: value == null ? "--" : formatYieldChange(value),
296
- detail: [`${change1d == null ? "--" : formatYieldChange(change1d)} 1D`,
297
- ...(percentile1y == null ? [] : [formatPercentileRank(percentile1y, "1Y")])].join(" · "),
298
- tone: value != null && Math.round(value * 100) < 0 ? "warning" : undefined,
293
+ ...curveSpreadFigures(current, lookbackCurves).map((figure): StatItem => ({
294
+ id: figure.id, label: figure.id, ...curveSpreadText(figure),
295
+ tone: figure.value != null && Math.round(figure.value * 100) < 0 ? "warning" : undefined,
299
296
  })),
300
297
  ...(selectedId ? MOVE_HORIZONS : []).flatMap((horizon): StatItem[] => {
301
298
  const move = curveTenorMove(current, selectedId!, horizon);
@@ -507,7 +504,7 @@ export const yieldCurveModule: PluginModule = {
507
504
  label: "Yield Curve",
508
505
  description: "Government bond curves, a world grid, and USD SOFR swap rates, swap spreads and tenor history.",
509
506
  keywords: ["yield", "curve", "treasury", "bonds", "rates", "gc", "interest", "tips", "breakeven", "bund", "gilt", "jgb",
510
- "sovereign", "world", "forward", "swaps", "sofr", "ois", "swap spread"],
507
+ "sovereign", "world", "forward", "swaps", "sofr", "ois", "swap spread", "2s10s", "steepener", "flattener"],
511
508
  shortcut: { prefix: "GC", argPlaceholder: "[curve] [date]", argKind: "text", argOptional: true },
512
509
  headless: yieldCurveHeadless,
513
510
  createInstance: (_context, options) => {
@@ -23,6 +23,25 @@ interface HostModule {
23
23
  native?: true;
24
24
  }
25
25
 
26
+ /**
27
+ * A CommonJS package's exports as an ES module's: each property of its
28
+ * `module.exports` a named export, beside `default`.
29
+ *
30
+ * The terminal binary and the desktop app's terminal are bundled with
31
+ * `--splitting` (scripts/build.ts, scripts/install-electrobun-tui-shim.ts),
32
+ * and once any module default-imports React, as the OpenTUI renderer does,
33
+ * Bun answers `import("react")` with a chunk that exports `module.exports`
34
+ * as `default` and nothing else. Served like that, a plugin's
35
+ * `import React from "react"` linked and its `import { useEffect } from
36
+ * "react"` did not, and nearly every plugin failed to load there.
37
+ */
38
+ async function importCommonJs(load: HostModuleImporter): Promise<object> {
39
+ const namespace = (await load()) as Record<string, unknown>;
40
+ const moduleExports = namespace.default;
41
+ if (moduleExports === null || typeof moduleExports !== "object") return namespace;
42
+ return { ...moduleExports, ...namespace };
43
+ }
44
+
26
45
  /**
27
46
  * Every specifier a plugin may import that must resolve to the host's copy.
28
47
  * Anything else is a plugin's own dependency and gets bundled normally.
@@ -37,9 +56,9 @@ interface HostModule {
37
56
  * desktop and break in the TUI.
38
57
  */
39
58
  const HOST_MODULES: Readonly<Record<string, HostModule>> = {
40
- "react": { load: () => import("react") },
41
- "react/jsx-runtime": { load: () => import("react/jsx-runtime") },
42
- "react/jsx-dev-runtime": { load: () => import("react/jsx-dev-runtime") },
59
+ "react": { load: () => importCommonJs(() => import("react")) },
60
+ "react/jsx-runtime": { load: () => importCommonJs(() => import("react/jsx-runtime")) },
61
+ "react/jsx-dev-runtime": { load: () => importCommonJs(() => import("react/jsx-dev-runtime")) },
43
62
  "gloomberb/types/plugin": { load: () => import("../types/plugin") },
44
63
  "gloomberb/types/persistence": { load: () => import("../types/persistence") },
45
64
  // Type modules also export runtime values (`TICKER_RESEARCH_PANE_ID`,
@@ -7,13 +7,15 @@ import { loadExternalPlugin } from "./loader";
7
7
  /**
8
8
  * The plugin the smoke writes: one import from each kind of module a real
9
9
  * plugin uses. `react` and the JSX runtime have to be the host's own
10
- * instance, `gloomberb/ui` is shared state, `gloomberb/types/config` is a
10
+ * instance, imported by name as registry plugins do: a host that served
11
+ * React's default export alone passed a default import and failed every
12
+ * plugin. `gloomberb/ui` is shared state, `gloomberb/types/config` is a
11
13
  * value from a module that used to be bundled from the package directory,
12
14
  * and `smoke-dep` stands in for a dependency `bun install` put in the
13
15
  * plugin's own `node_modules`.
14
16
  */
15
17
  const SMOKE_PLUGIN_SOURCE = `
16
- import React from "react";
18
+ import React, { memo, useCallback, useEffect, useState, useSyncExternalStore } from "react";
17
19
  import { Box, Text } from "gloomberb/ui";
18
20
  import { formatNumber } from "gloomberb/utils";
19
21
  import { TICKER_RESEARCH_PANE_ID } from "gloomberb/types/config";
@@ -31,7 +33,8 @@ export default {
31
33
  const element = <Probe />;
32
34
  const tree = Probe();
33
35
  return {
34
- react: typeof React.createElement === "function" && typeof React.useState === "function",
36
+ react: typeof React.createElement === "function"
37
+ && [memo, useCallback, useEffect, useState, useSyncExternalStore].every((value) => typeof value === "function"),
35
38
  jsx: typeof element.type === "function" && tree != null && typeof tree === "object" && "type" in tree,
36
39
  paneId: TICKER_RESEARCH_PANE_ID,
37
40
  platform,
@@ -45,6 +45,18 @@ function ensurePluginsDir() {
45
45
 
46
46
  const GITHUB_SEGMENT_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*(?![\s\S])/;
47
47
  const COMMIT_PATTERN = /^[0-9a-f]{7,40}$/i;
48
+ /**
49
+ * A tag or branch name as git spells one: never starting with a dash, which
50
+ * git would read as an option, and without `..`, `//`, `@{`, a trailing slash
51
+ * or dot, or `.lock` at the end.
52
+ */
53
+ const PIN_REF_PATTERN = /^(?!.*\.\.)(?!.*\/\/)(?!.*@\{)(?!.*\.lock$)(?!.*[./]$)[A-Za-z0-9][A-Za-z0-9._/@+-]*$/;
54
+
55
+ /** The registry pin's tag or branch, refused unless it is plainly one. */
56
+ export function validatePinRef(ref: string): string {
57
+ if (ref.length > 200 || !PIN_REF_PATTERN.test(ref)) throw new Error(`Invalid ref in registry pin: ${JSON.stringify(ref)}.`);
58
+ return ref;
59
+ }
48
60
 
49
61
  export function validatePluginDirectoryName(name: string): string {
50
62
  if (!GITHUB_SEGMENT_PATTERN.test(name)) {
@@ -203,8 +215,9 @@ function pinMatches(commit: string | null, expected: string | undefined): boolea
203
215
  async function fetchPin(targetDir: string, pin: PluginPin, quiet: boolean): Promise<string> {
204
216
  const wanted = pin.ref ?? pin.commit;
205
217
  if (!wanted) throw new Error("The registry pin names no ref or commit.");
218
+ if (pin.ref) validatePinRef(pin.ref);
206
219
  if (pin.commit && !COMMIT_PATTERN.test(pin.commit)) throw new Error(`Invalid commit in registry pin: ${pin.commit}`);
207
- await git(["fetch", "--depth", "1", "origin", wanted], targetDir, quiet, `Could not fetch ${wanted}`);
220
+ await git(["fetch", "--depth", "1", "origin", "--", wanted], targetDir, quiet, `Could not fetch ${wanted}`);
208
221
  const commit = await git(["rev-parse", "FETCH_HEAD^{commit}"], targetDir, quiet, `Could not read ${wanted}`);
209
222
  if (!pinMatches(commit, pin.commit)) {
210
223
  throw new Error(`${pin.ref ?? "The pinned ref"} now points at ${commit.slice(0, 7)}, the registry reviewed ${pin.commit!.slice(0, 7)}.`);
@@ -348,8 +361,8 @@ export async function installPlugin(ref: string, options: PluginInstallOptions =
348
361
  const pin = options.pin ?? {};
349
362
  try {
350
363
  const cloneArgs = ["clone", "--depth", "1"];
351
- if (pin.ref) cloneArgs.push("--branch", pin.ref);
352
- cloneArgs.push(url, targetDir);
364
+ if (pin.ref) cloneArgs.push(`--branch=${validatePinRef(pin.ref)}`);
365
+ cloneArgs.push("--", url, targetDir);
353
366
  await git(cloneArgs, PLUGINS_DIR, quiet, `Failed to clone ${url}`);
354
367
  if (pin.ref) {
355
368
  const commit = readPluginCommit(targetDir);
@@ -11,20 +11,29 @@
11
11
  */
12
12
  const PLUGIN_NAME_PREFIXES = ["gloom-", "gloomberb-"] as const;
13
13
 
14
+ /**
15
+ * A plugin package name is one folder name: a prefix, then letters, digits,
16
+ * dots, dashes and underscores. A name read from a plugin's manifest is
17
+ * joined to the plugins folder, so a slash or a backslash would reach past it.
18
+ */
19
+ const PLUGIN_PACKAGE_NAME = /^(?:gloom|gloomberb)-[A-Za-z0-9][A-Za-z0-9._-]*$/;
20
+
14
21
  /** True for a name that belongs to a plugin package under either product name. */
15
22
  export function isPluginPackageName(name: string): boolean {
16
- return PLUGIN_NAME_PREFIXES.some((prefix) => name.startsWith(prefix));
23
+ return PLUGIN_PACKAGE_NAME.test(name);
17
24
  }
18
25
 
19
26
  /**
20
27
  * The directory names a plugin could be installed under, the given name first.
21
28
  *
22
29
  * A name with neither prefix is returned alone, so this is safe to call on any
23
- * dependency name.
30
+ * dependency name. A name with a prefix that is not a plugin package name has
31
+ * no folder to look in.
24
32
  */
25
33
  export function pluginDirectoryNames(name: string): string[] {
26
34
  for (const prefix of PLUGIN_NAME_PREFIXES) {
27
35
  if (!name.startsWith(prefix)) continue;
36
+ if (!isPluginPackageName(name)) return [];
28
37
  const other = PLUGIN_NAME_PREFIXES.find((candidate) => candidate !== prefix);
29
38
  return [name, `${other}${name.slice(prefix.length)}`];
30
39
  }
@@ -25,6 +25,25 @@ export function findNamedCollection<T extends { id: string; name: string }>(
25
25
  )) ?? null;
26
26
  }
27
27
 
28
+ /**
29
+ * What a list argument that names a watchlist reads (`SIW HY3`): its symbols,
30
+ * at most a function's `maximum`, and a note saying the name was read as the
31
+ * watchlist, which matters when it is a ticker too (`AI`): `Read AI as
32
+ * watchlist AI (12 symbols).` or `Read HY3 as watchlist HY3 (70 symbols); the
33
+ * first 60 are read.` Every function's list argument, in `fn` and in the
34
+ * command bar, reads a watchlist's name here.
35
+ */
36
+ export function readWatchlistArgument(
37
+ typed: string,
38
+ watchlist: { name: string },
39
+ members: readonly string[],
40
+ maximum: number | undefined,
41
+ ): { symbols: string[]; note: string } {
42
+ const read = `Read ${typed.trim()} as watchlist ${watchlist.name} (${members.length} symbol${members.length === 1 ? "" : "s"})`;
43
+ if (maximum == null || members.length <= maximum) return { symbols: [...members], note: `${read}.` };
44
+ return { symbols: members.slice(0, maximum), note: `${read}; the first ${maximum} are read.` };
45
+ }
46
+
28
47
  /**
29
48
  * The command bar's row for a function typed with a portfolio or watchlist
30
49
  * nothing has (`PF Nope`, `PORT Nope`), or null when one of `collections` has
@@ -17,6 +17,7 @@ import {
17
17
  customViewInstanceSettings,
18
18
  parseViewSpecOr,
19
19
  trialLoadViewSource,
20
+ UnknownViewKeysError,
20
21
  type ViewSpec,
21
22
  } from "../plugins/builtin/custom-view";
22
23
  import { findPaneInstance, getPlacedPaneInstanceIds, type PaneInstanceConfig, resolvePaneInstance } from "../types/config";
@@ -409,13 +410,18 @@ export function createAppRemoteController({
409
410
  /**
410
411
  * A view's source loads once before the view is kept, so a function that
411
412
  * does not exist or cannot read answers with its own error instead of
412
- * leaving a pane that never fills. What the load noted comes back as warnings.
413
+ * leaving a pane that never fills, and a column, filter or sort on a key its
414
+ * rows never carry is answered with the keys they do carry. What the load
415
+ * noted comes back as warnings.
413
416
  */
414
417
  const checkViewSource = async (spec: ViewSpec, action: "create" | "update", signal?: AbortSignal): Promise<string[]> => {
415
418
  try {
416
419
  return await trialLoadViewSource(spec, getState().config, { registry: pluginRegistry, signal });
417
420
  } catch (error) {
418
421
  const reason = error instanceof Error ? error.message : String(error);
422
+ if (error instanceof UnknownViewKeysError) {
423
+ throw new Error(`${action === "create" ? "No view was created" : "The view was left as it was"}. ${reason}`);
424
+ }
419
425
  throw new Error(`The view's source did not load, so ${action === "create" ? "no view was created" : "the view was left as it was"}. ${reason}`);
420
426
  }
421
427
  };
@@ -497,7 +503,8 @@ export function createAppRemoteController({
497
503
  const name = optionalString(input, "name");
498
504
  if (name) layout = updatePaneInstance(layout, instanceId, (entry: PaneInstanceConfig) => ({ ...entry, title: name }));
499
505
  pluginRegistry.updateLayout(layout);
500
- return getAfterMutationSummary({ affectedPaneIds: [instanceId], ...(loadWarnings.length ? { warnings: loadWarnings } : {}) });
506
+ const warnings = [...parsed.result.warnings.map((entry) => entry.message), ...loadWarnings];
507
+ return getAfterMutationSummary({ affectedPaneIds: [instanceId], ...(warnings.length ? { warnings } : {}) });
501
508
  }
502
509
  case "pane.setState":
503
510
  dispatch({
@@ -169,7 +169,8 @@ export const REMOTE_OPERATIONS: RemoteOperationSchema[] = [
169
169
  + "spec = { source: { pane: <function code>, argument?: <one string>, options?: { <flag>: <value> } }, projection: { columns?: [{ key, label?, transform? }], filters?: [{ key, op, value }], sort?: { by, direction }, limit? }, presentation?: { title?, symbolKey? } }. "
170
170
  + "pane is a function code (app://pane-templates says what each does), never an invented name; an unknown one is answered with the closest codes and the valid ones. "
171
171
  + "argument is always one string, several tickers separated by spaces: \"CME AAPL\". "
172
- + "options sets the function's own flags; a wrong flag or value is answered with the ones it takes.",
172
+ + "options sets the function's own flags; a wrong flag or value is answered with the ones it takes. "
173
+ + "Column, filter and sort keys are keys the source's rows carry; one they do not is answered with the keys they do, and no pane opens.",
173
174
  "{ name?: string, spec: object }",
174
175
  "local-write",
175
176
  objectSchema({ name: stringSchema, spec: openObjectSchema }, ["spec"]),
@@ -6,6 +6,70 @@ import {
6
6
  import type { HttpFetchTransport } from "../../utils/http-transport";
7
7
  import { HTTP_PROXY_PATH, isProxiedHost, PROXY_ALLOWED_HOSTS } from "../../utils/plugin-proxy-hosts";
8
8
 
9
+ /** Thrown when the worker refuses or cannot complete a proxied request. */
10
+ class ProxyRefusedError extends Error {
11
+ constructor(message: string, readonly status: number) {
12
+ super(message);
13
+ this.name = "ProxyRefusedError";
14
+ }
15
+ }
16
+
17
+ const UNREACHABLE = "The data source could not be reached. Check your connection and try again.";
18
+ const UNREADABLE = "The data source's answer could not be read. Try again shortly.";
19
+ /** Longer than any sentence the worker writes; anything past it is not one of them. */
20
+ const MAX_REFUSAL_LENGTH = 160;
21
+
22
+ /**
23
+ * The sentence a pane shows for a refusal. The worker answers with
24
+ * `{ error }` in plain words; anything else (an edge error page, a body cut
25
+ * short, a message that is not one short line) gets a sentence for its
26
+ * status, never the raw body.
27
+ */
28
+ async function refusalMessage(response: Response): Promise<string> {
29
+ const body = await response.json().catch(() => null) as { error?: unknown } | null;
30
+ const error = typeof body?.error === "string" ? body.error.trim() : "";
31
+ if (error && error.length <= MAX_REFUSAL_LENGTH && !/[{}<>\n]/.test(error)) return error;
32
+ if (response.status === 429) return "Too many requests right now. Try again in a minute.";
33
+ if (response.status >= 500) return "The data source could not be reached. Try again shortly.";
34
+ return "This request could not be completed.";
35
+ }
36
+
37
+ function isEnvelope(value: unknown): value is HttpProxyResponseEnvelope {
38
+ if (!value || typeof value !== "object") return false;
39
+ const { status, headers, body } = value as Partial<HttpProxyResponseEnvelope>;
40
+ return typeof status === "number" && !!headers && typeof headers === "object" && typeof body === "string";
41
+ }
42
+
43
+ /**
44
+ * A request that never got an answer fails with the browser's own words
45
+ * ("Failed to fetch", "Load failed"), which a pane would print as they are.
46
+ * It becomes a sentence instead, keeping the original as `cause` for code
47
+ * that classifies network failures. A caller's abort or timeout stays as it
48
+ * was, since callers check for those by name.
49
+ */
50
+ async function answered(request: () => Promise<Response>, signal: AbortSignal | null | undefined): Promise<Response> {
51
+ try {
52
+ return await request();
53
+ } catch (error) {
54
+ const name = (error as { name?: unknown } | null)?.name;
55
+ if (signal?.aborted || name === "AbortError" || name === "TimeoutError") throw error;
56
+ throw new Error(UNREACHABLE, { cause: error });
57
+ }
58
+ }
59
+
60
+ /**
61
+ * A browser owns `User-Agent`. Chrome drops one set by script, but Firefox
62
+ * sends it, which turns a simple cross-origin GET into a preflight that some
63
+ * of the hosts called directly do not allow. Every browser leaves it out.
64
+ */
65
+ function withoutUserAgent(init: RequestInit | undefined): RequestInit | undefined {
66
+ if (!init?.headers) return init;
67
+ const headers = new Headers(init.headers);
68
+ if (!headers.has("user-agent")) return init;
69
+ headers.delete("user-agent");
70
+ return { ...init, headers };
71
+ }
72
+
9
73
  function needsProxy(url: string, hosts: readonly string[]): boolean {
10
74
  try {
11
75
  const target = new URL(url, typeof location === "undefined" ? undefined : location.href);
@@ -36,20 +100,26 @@ export function createBrowserHttpProxyTransport(
36
100
  hosts: readonly string[] = PROXY_ALLOWED_HOSTS,
37
101
  ): HttpFetchTransport {
38
102
  return async function proxiedFetch(url: string, init?: RequestInit): Promise<Response> {
39
- if (!needsProxy(url, hosts)) return send(url, init);
103
+ if (!needsProxy(url, hosts)) return answered(() => send(url, withoutUserAgent(init)), init?.signal);
40
104
 
41
- const proxied = await send(HTTP_PROXY_PATH, {
105
+ const envelope = await toRequestEnvelope(url, init);
106
+ const proxied = await answered(() => send(HTTP_PROXY_PATH, {
42
107
  method: "POST",
43
108
  headers: { "content-type": "application/json" },
44
109
  credentials: "include",
45
110
  signal: init?.signal ?? null,
46
- body: JSON.stringify(await toRequestEnvelope(url, init)),
47
- });
111
+ body: JSON.stringify(envelope),
112
+ }), init?.signal);
48
113
 
49
- if (!proxied.ok) {
50
- const detail = await proxied.text().catch(() => "");
51
- throw new Error(`Plugin request was refused (${proxied.status}). ${detail}`.trim());
114
+ if (!proxied.ok) throw new ProxyRefusedError(await refusalMessage(proxied), proxied.status);
115
+ // A 200 that is not an envelope (an HTML page from a route that is not
116
+ // the worker's) would otherwise surface as a JSON SyntaxError quoting it.
117
+ const answer = await proxied.json().catch(() => null);
118
+ if (!isEnvelope(answer)) throw new ProxyRefusedError(UNREADABLE, proxied.status);
119
+ try {
120
+ return createProxyResponse(answer);
121
+ } catch {
122
+ throw new ProxyRefusedError(UNREADABLE, proxied.status);
52
123
  }
53
- return createProxyResponse(await proxied.json() as HttpProxyResponseEnvelope);
54
124
  };
55
125
  }