@gloom-sh/terminal 0.20.10 → 0.20.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/patches/@opentui%2Fcore@0.3.2.patch +16 -0
- package/src/api-client/awards.ts +16 -0
- package/src/api-client/central-bank-rates.ts +5 -0
- package/src/api-client/data.ts +55 -2
- package/src/api-client/index.ts +18 -1
- package/src/api-client/request.ts +86 -3
- package/src/api-client/socket-connection.ts +366 -0
- package/src/api-client/socket-features.ts +75 -0
- package/src/api-client/socket-frames.ts +161 -0
- package/src/api-client/socket-listeners.ts +207 -0
- package/src/api-client/socket-quotes.ts +332 -0
- package/src/api-client/socket.ts +168 -983
- package/src/api-client/supply-chain-graph.ts +4 -2
- package/src/api-client/supply-chain.ts +8 -0
- package/src/api-client/types/econ.ts +10 -7
- package/src/api-client/types/filings-and-calls.ts +8 -0
- package/src/app/global-shortcuts.ts +2 -1
- package/src/app/keybindings/actions.ts +19 -0
- package/src/app/pane-runtime/index.tsx +18 -3
- package/src/app/pane-runtime/layout-placement.ts +63 -0
- package/src/app/pane-runtime/ticker-open-runtime.ts +10 -2
- package/src/brokers/signed-in/adapter.ts +19 -5
- package/src/brokers/signed-in/client.ts +13 -1
- package/src/brokers/signed-in/sign-in-dialog.tsx +33 -9
- package/src/capabilities/chart-series.ts +4 -1
- package/src/cli/board-coins.ts +10 -1
- package/src/cli/commands/crypto-hints.ts +3 -2
- package/src/cli/commands/fred-series.ts +0 -54
- package/src/cli/commands/market.ts +209 -31
- package/src/cli/commands/overview.ts +47 -14
- package/src/cli/commands/search.ts +37 -8
- package/src/cli/commands/ticker.ts +15 -4
- package/src/cli/desktop-pane-shot.ts +27 -2
- package/src/cli/fx-quote-rate.ts +1 -1
- package/src/cli/glossary.ts +14 -5
- package/src/cli/history-catalog-series.ts +85 -0
- package/src/cli/index.ts +1 -1
- package/src/cli/list-progress.ts +45 -0
- package/src/cli/listing-arg.ts +71 -7
- package/src/cli/name-entries.ts +8 -4
- package/src/cli/not-a-ticker.ts +2 -2
- package/src/cli/pane-functions/freshness.ts +50 -3
- package/src/cli/pane-functions/index.ts +7 -4
- package/src/cli/pane-functions/market-session.ts +66 -14
- package/src/cli/pane-functions/options.ts +5 -0
- package/src/cli/pane-functions/resolver.ts +9 -2
- package/src/cli/pane-functions/screenshot-assessment.ts +28 -3
- package/src/cli/pane-functions/screenshot-types.ts +6 -0
- package/src/cli/quote-answer.ts +49 -10
- package/src/cli/quote-list-reads.ts +87 -0
- package/src/cli/report-tables.ts +70 -13
- package/src/cli/result.ts +24 -2
- package/src/cli/symbol-list.ts +31 -4
- package/src/cli/terminal-code-hints.ts +83 -0
- package/src/cli/ticker-resolution.ts +2 -1
- package/src/cli/treasury-yields.ts +5 -0
- package/src/components/chart/native/kitty/manager.ts +2 -0
- package/src/components/chart/native/surface/manager.ts +211 -11
- package/src/components/command-bar/action-runtime.ts +2 -0
- package/src/components/command-bar/panel/index.tsx +2 -13
- package/src/components/command-bar/panel/layout.ts +1 -7
- package/src/components/command-bar/panel/runtime.ts +0 -1
- package/src/components/command-bar/panel/types.ts +0 -2
- package/src/components/command-bar/routing/launch-request.ts +2 -1
- package/src/components/command-bar/routing/navigation-state.ts +4 -2
- package/src/components/command-bar/workflow/types.ts +6 -0
- package/src/components/data-table/column-menu.tsx +89 -0
- package/src/components/data-table/sort-menu.tsx +9 -2
- package/src/components/data-table/view.tsx +33 -6
- package/src/components/form-modal/content.tsx +10 -0
- package/src/components/index.ts +1 -1
- package/src/components/layout/detached-pane-shell.tsx +3 -0
- package/src/components/layout/double-escape-close.ts +34 -3
- package/src/components/layout/floating-pane.tsx +10 -4
- package/src/components/layout/pane/cycle-order.ts +66 -2
- package/src/components/layout/pane/footer/index.tsx +25 -11
- package/src/components/layout/pane/footer/model.ts +62 -20
- package/src/components/layout/pane/header.tsx +140 -31
- package/src/components/layout/pane/sidebar.tsx +138 -20
- package/src/components/layout/pane/status-footer.ts +3 -1
- package/src/components/layout/shell/active-drag.ts +18 -13
- package/src/components/layout/shell/drag/magnets.ts +34 -18
- package/src/components/layout/shell/drag/runtime.ts +5 -0
- package/src/components/layout/shell/index.tsx +25 -0
- package/src/components/layout/shell/menu.ts +9 -0
- package/src/components/layout/shell/pane/actions.ts +36 -0
- package/src/components/layout/shell/pane/management-shortcuts.ts +27 -3
- package/src/components/layout/shell/pane-occlusion.ts +40 -0
- package/src/components/layout/shell/shortcuts.ts +17 -1
- package/src/components/layout/shell/terminal-pointer-runtime.ts +39 -6
- package/src/components/layout/shell/window-mode/index.ts +5 -16
- package/src/components/layout/shell/window-mode/overlays.tsx +3 -1
- package/src/components/market-board/index.tsx +14 -5
- package/src/components/metric-treemap/index.tsx +3 -1
- package/src/components/ticker/list-table-view.tsx +5 -0
- package/src/components/ui/button.tsx +48 -4
- package/src/components/ui/data-table/column-order.ts +180 -0
- package/src/components/ui/data-table/index.tsx +12 -1
- package/src/components/ui/data-table/opentui/index.tsx +291 -32
- package/src/components/ui/data-table/opentui/model.ts +43 -4
- package/src/components/ui/data-table/types.ts +56 -0
- package/src/components/ui/data-table/use-column-order.ts +135 -0
- package/src/components/ui/index.ts +1 -1
- package/src/components/ui/inline-quick-add.tsx +19 -3
- package/src/components/ui/list-view.tsx +11 -5
- package/src/components/ui/query-bar.tsx +16 -1
- package/src/components/ui/selection-fill.ts +39 -0
- package/src/components/ui/table-layout.ts +120 -0
- package/src/core/state/app/layout-reducer.ts +2 -1
- package/src/core/state/app/pane-choices.ts +68 -0
- package/src/core/state/app/state.ts +14 -6
- package/src/core/state/app/types.ts +8 -0
- package/src/docs/snapshot.json +3 -2
- package/src/i18n/es.ts +2 -0
- package/src/i18n/ja.ts +2 -0
- package/src/i18n/ko.ts +2 -0
- package/src/i18n/zh-cn.ts +2 -0
- package/src/i18n/zh-tw.ts +2 -0
- package/src/layout/pane-manager/dock-tree.ts +19 -0
- package/src/layout/pane-manager/index.ts +3 -0
- package/src/market-data/coordinator/index.ts +4 -3
- package/src/market-data/coordinator/quotes.ts +12 -4
- package/src/market-data/market/freshness.ts +33 -0
- package/src/market-data/market/status.ts +5 -1
- package/src/market-data/quotes/contributions.ts +10 -0
- package/src/market-data/quotes/freshness.ts +31 -0
- package/src/market-data/quotes/live-valuation.ts +32 -5
- package/src/market-data/quotes/regular-session-valuation.ts +1 -1
- package/src/market-data/quotes/resolution.ts +4 -0
- package/src/market-data/quotes/time.ts +0 -14
- package/src/plugins/builtin/account-management/index.tsx +1 -0
- package/src/plugins/builtin/awards/detail.tsx +12 -4
- package/src/plugins/builtin/awards/headless.ts +29 -8
- package/src/plugins/builtin/awards/model.ts +36 -2
- package/src/plugins/builtin/awards/pane.tsx +7 -4
- package/src/plugins/builtin/broker-manager/detail.tsx +5 -3
- package/src/plugins/builtin/broker-manager/index.tsx +7 -6
- package/src/plugins/builtin/broker-manager/model.ts +15 -6
- package/src/plugins/builtin/broker-manager/pane-actions.tsx +11 -4
- package/src/plugins/builtin/broker-manager/sign-in-end.ts +50 -19
- package/src/plugins/builtin/broker-manager/table.ts +10 -4
- package/src/plugins/builtin/broker-trading/index.tsx +1 -1
- package/src/plugins/builtin/central-bank-rates/headless.ts +6 -6
- package/src/plugins/builtin/central-bank-rates/index.tsx +1 -1
- package/src/plugins/builtin/central-bank-rates/model.ts +21 -3
- package/src/plugins/builtin/central-bank-rates/pane.tsx +15 -5
- package/src/plugins/builtin/chart-composer/headless.ts +5 -1
- package/src/plugins/builtin/chart-composer/pane.tsx +1 -0
- package/src/plugins/builtin/chat/content/handle-prompt.tsx +4 -0
- package/src/plugins/builtin/chat/controller/realtime.ts +17 -1
- package/src/plugins/builtin/chat/message/terminal.tsx +4 -1
- package/src/plugins/builtin/chat/sidebar.tsx +35 -19
- package/src/plugins/builtin/cloud/askg/pane.tsx +4 -0
- package/src/plugins/builtin/cloud/askg/tool-timeline.tsx +2 -0
- package/src/plugins/builtin/cloud/plugin.tsx +1 -0
- package/src/plugins/builtin/cloud/team/module.tsx +1 -0
- package/src/plugins/builtin/cloud/thesis/detail.tsx +9 -4
- package/src/plugins/builtin/commodity-balances/pane.tsx +13 -5
- package/src/plugins/builtin/company-kpis/model.ts +3 -3
- package/src/plugins/builtin/connections/index.ts +1 -0
- package/src/plugins/builtin/credit-boards/cdx-pane.tsx +9 -5
- package/src/plugins/builtin/credit-boards/client.ts +5 -0
- package/src/plugins/builtin/credit-boards/headless.ts +1 -6
- package/src/plugins/builtin/credit-boards/model.ts +0 -6
- package/src/plugins/builtin/credit-boards/series.ts +19 -8
- package/src/plugins/builtin/credit-boards/sovr-pane.tsx +9 -5
- package/src/plugins/builtin/crypto-etf-flows/headless.ts +23 -13
- package/src/plugins/builtin/crypto-etf-flows/pane.tsx +8 -3
- package/src/plugins/builtin/debt-maturities/headless.ts +16 -7
- package/src/plugins/builtin/debt-maturities/model.ts +9 -15
- package/src/plugins/builtin/debt-maturities/pane.tsx +9 -10
- package/src/plugins/builtin/earnings/board-model.ts +33 -4
- package/src/plugins/builtin/earnings/board.tsx +15 -3
- package/src/plugins/builtin/earnings/calendar.tsx +10 -6
- package/src/plugins/builtin/earnings/client.ts +0 -9
- package/src/plugins/builtin/earnings/headless.ts +10 -7
- package/src/plugins/builtin/earnings/history.tsx +21 -14
- package/src/plugins/builtin/earnings-calls/data.ts +24 -4
- package/src/plugins/builtin/earnings-calls/format.ts +23 -5
- package/src/plugins/builtin/earnings-calls/headless.ts +23 -3
- package/src/plugins/builtin/earnings-calls/index.tsx +1 -0
- package/src/plugins/builtin/earnings-calls/model.ts +11 -1
- package/src/plugins/builtin/earnings-calls/pane.tsx +2 -5
- package/src/plugins/builtin/econ/calendar-model.ts +27 -0
- package/src/plugins/builtin/econ/fred-catalog.ts +3 -0
- package/src/plugins/builtin/econ/index.tsx +9 -2
- package/src/plugins/builtin/econ-statistics/headless.ts +3 -1
- package/src/plugins/builtin/econ-statistics/index.tsx +1 -1
- package/src/plugins/builtin/equity-screener/live.ts +74 -18
- package/src/plugins/builtin/equity-screener/model.ts +19 -4
- package/src/plugins/builtin/equity-screener/pane.tsx +19 -14
- package/src/plugins/builtin/equity-screener/refresh-anchor.ts +45 -0
- package/src/plugins/builtin/equity-screener/results.ts +22 -2
- package/src/plugins/builtin/equity-screener/screen-check.ts +9 -3
- package/src/plugins/builtin/fear-greed/headless.ts +16 -13
- package/src/plugins/builtin/fear-greed/pane.tsx +12 -4
- package/src/plugins/builtin/filing-events/index.tsx +1 -0
- package/src/plugins/builtin/futures/index.tsx +15 -1
- package/src/plugins/builtin/futures/table.tsx +1 -1
- package/src/plugins/builtin/fx-matrix/index.tsx +32 -19
- package/src/plugins/builtin/holders/pane.tsx +30 -20
- package/src/plugins/builtin/insider/table.tsx +10 -7
- package/src/plugins/builtin/insider/tickers.tsx +1 -1
- package/src/plugins/builtin/iv-history/events.ts +5 -0
- package/src/plugins/builtin/iv-history/headless.ts +15 -9
- package/src/plugins/builtin/jobs/index.tsx +1 -0
- package/src/plugins/builtin/kelly-sizer/sections.tsx +2 -0
- package/src/plugins/builtin/macro-day/headless.ts +15 -6
- package/src/plugins/builtin/macro-day/model.ts +1 -1
- package/src/plugins/builtin/macro-day/releases.ts +25 -16
- package/src/plugins/builtin/market-movers/index.tsx +20 -8
- package/src/plugins/builtin/market-movers/model.ts +5 -0
- package/src/plugins/builtin/market-movers/session-body.tsx +2 -1
- package/src/plugins/builtin/money-markets/headless.ts +12 -2
- package/src/plugins/builtin/money-markets/pane.tsx +10 -1
- package/src/plugins/builtin/options/view.tsx +3 -0
- package/src/plugins/builtin/options-positioning/pane.tsx +1 -1
- package/src/plugins/builtin/options-scenario/pane.tsx +2 -1
- package/src/plugins/builtin/perps/cascade-tabs.tsx +2 -1
- package/src/plugins/builtin/portfolio-list/cli/bulk-symbols.ts +4 -31
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +19 -1
- package/src/plugins/builtin/portfolio-list/quick-add/index.tsx +22 -8
- package/src/plugins/builtin/portfolio-list/summary/index.tsx +6 -8
- package/src/plugins/builtin/portfolio-list/table.tsx +15 -1
- package/src/plugins/builtin/rate-path/pane.tsx +2 -0
- package/src/plugins/builtin/realized-vol/headless.ts +28 -2
- package/src/plugins/builtin/revenue-breakdown/pane.tsx +2 -0
- package/src/plugins/builtin/reverse-dcf/pane.tsx +2 -1
- package/src/plugins/builtin/risk-factors/index.tsx +1 -0
- package/src/plugins/builtin/seasonality/pane.tsx +2 -1
- package/src/plugins/builtin/shared/source-footer.ts +70 -0
- package/src/plugins/builtin/short-interest/publications-pane.tsx +5 -1
- package/src/plugins/builtin/short-volume/pane.tsx +5 -1
- package/src/plugins/builtin/social-mentions/outliers.tsx +10 -1
- package/src/plugins/builtin/social-mentions/pane.tsx +7 -0
- package/src/plugins/builtin/supply-chain/client.ts +3 -1
- package/src/plugins/builtin/supply-chain/flow.tsx +25 -8
- package/src/plugins/builtin/supply-chain/graph-client.ts +1 -1
- package/src/plugins/builtin/supply-chain/graph-evidence.ts +1 -1
- package/src/plugins/builtin/supply-chain/graph-model.ts +12 -1
- package/src/plugins/builtin/supply-chain/graph-pane.tsx +9 -8
- package/src/plugins/builtin/supply-chain/graph.tsx +12 -6
- package/src/plugins/builtin/supply-chain/headless.ts +13 -7
- package/src/plugins/builtin/supply-chain/model.ts +68 -11
- package/src/plugins/builtin/supply-chain/pane.tsx +9 -6
- package/src/plugins/builtin/supply-chain/row-evidence.tsx +5 -5
- package/src/plugins/builtin/thirteenf/pane.tsx +2 -0
- package/src/plugins/builtin/ticker-detail/financials/model.ts +28 -6
- package/src/plugins/builtin/ticker-detail/financials/ratio-table.tsx +26 -9
- package/src/plugins/builtin/ticker-detail/financials/tab.tsx +58 -35
- package/src/plugins/builtin/ticker-detail/overview/components.tsx +14 -1
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +2 -0
- package/src/plugins/builtin/ticker-detail/pane.tsx +48 -24
- package/src/plugins/builtin/ticker-detail/quote-footer.ts +5 -0
- package/src/plugins/builtin/ticker-detail/quote-monitor/card.tsx +6 -3
- package/src/plugins/builtin/treasury-auctions/after.ts +50 -23
- package/src/plugins/builtin/treasury-auctions/cache.ts +23 -5
- package/src/plugins/builtin/treasury-auctions/headless.ts +226 -37
- package/src/plugins/builtin/treasury-auctions/hk-headless.ts +11 -5
- package/src/plugins/builtin/treasury-auctions/hk-view.tsx +27 -25
- package/src/plugins/builtin/treasury-auctions/hk.ts +60 -8
- package/src/plugins/builtin/treasury-auctions/index.tsx +3 -0
- package/src/plugins/builtin/treasury-auctions/keys.ts +27 -0
- package/src/plugins/builtin/treasury-auctions/like.ts +137 -0
- package/src/plugins/builtin/treasury-auctions/model.ts +100 -22
- package/src/plugins/builtin/treasury-auctions/pane.tsx +39 -11
- package/src/plugins/builtin/vol-surface/heat-grid.tsx +6 -3
- package/src/plugins/builtin/vol-surface/pane.tsx +7 -3
- package/src/plugins/builtin/world-indices/index.tsx +5 -1
- package/src/plugins/builtin/yield-curve/index.tsx +2 -1
- package/src/plugins/runtime/index.tsx +1 -0
- package/src/plugins/runtime/state.ts +20 -0
- package/src/portfolio/column-values.ts +8 -2
- package/src/public/__snapshots__/public-api.test.ts.snap +5 -0
- package/src/public/react.ts +7 -0
- package/src/react/auto-refresh.ts +29 -0
- package/src/renderers/browser/deeplink-bridge.ts +24 -3
- package/src/renderers/dom/data-table/column-drag.ts +147 -0
- package/src/renderers/dom/data-table/index.tsx +22 -0
- package/src/renderers/dom/data-table/row.tsx +27 -5
- package/src/renderers/dom/desktop/query-bar.tsx +229 -60
- package/src/renderers/dom/host/overflow-fade-px.ts +2 -0
- package/src/renderers/dom/host/overflow-fade.ts +1 -2
- package/src/renderers/dom/styles.css +47 -5
- package/src/renderers/electrobun/view/cli-pane-shot-entry.tsx +2 -1
- package/src/renderers/opentui/chart-surface.tsx +1 -0
- package/src/renderers/opentui/frame-hits.ts +33 -0
- package/src/renderers/opentui/host.tsx +2 -0
- package/src/renderers/opentui/native-surface.ts +14 -21
- package/src/renderers/opentui/test-utils.tsx +3 -0
- package/src/series/types.ts +2 -0
- package/src/sources/gloomberb-cloud/fred-attribution.ts +86 -0
- package/src/sources/gloomberb-cloud/index.ts +25 -1
- package/src/sources/gloomberb-cloud/normalizers.ts +22 -3
- package/src/sources/provider-errors.ts +64 -1
- package/src/sources/provider-router/batches.ts +19 -0
- package/src/sources/provider-router/index.ts +7 -1
- package/src/state/app/context/index.tsx +46 -1
- package/src/state/pane-unsent-work.ts +47 -0
- package/src/test-support/app-store.ts +24 -1
- package/src/test-support/shell-pane-keys.tsx +5 -0
- package/src/test-support/telemetry-guard.ts +83 -0
- package/src/test-support/test-env.ts +12 -0
- package/src/theme/colors.ts +17 -1
- package/src/theme/ui-tokens.ts +50 -1
- package/src/tickers/listing-venues.ts +11 -1
- package/src/tickers/search/japanese-names.json +1 -0
- package/src/tickers/search/japanese-names.ts +152 -0
- package/src/tickers/terminal-codes.ts +55 -6
- package/src/time-series/base-series.ts +3 -0
- package/src/time-series/live-quotes.ts +3 -9
- package/src/types/data-provider.ts +6 -0
- package/src/types/financials.ts +11 -0
- package/src/types/plugin-contributions.ts +7 -0
- package/src/types/plugin-panes.ts +7 -0
- package/src/ui/host.tsx +24 -0
- package/src/ui/pointer-drag.ts +11 -2
- package/src/utils/double-escape-close.ts +42 -0
- package/src/utils/fundamentals.ts +14 -3
- package/src/utils/fx-status.ts +30 -7
- package/src/utils/network-failure.ts +23 -0
- package/src/utils/share-multiples.cases.json +780 -2
- package/src/utils/share-multiples.ts +154 -24
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Renderable, RGBA, type CliRenderer } from "@opentui/core";
|
|
2
|
+
import type { NativeFrameHits } from "../../ui/host";
|
|
3
|
+
|
|
4
|
+
function filled(color: unknown): boolean {
|
|
5
|
+
return color instanceof RGBA && color.a > 0;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The terminal's hit grid as the image layer reads it: every renderable the
|
|
10
|
+
* frame drew claims its cells, the one drawn last on top, so it says what
|
|
11
|
+
* covers a kitty image whichever pane, menu, toast or bar drew it.
|
|
12
|
+
*/
|
|
13
|
+
export function createFrameHits(renderer: CliRenderer): NativeFrameHits {
|
|
14
|
+
return {
|
|
15
|
+
at(x, y) {
|
|
16
|
+
if (renderer.isDestroyed) return null;
|
|
17
|
+
return Renderable.renderablesByNumber.get(renderer.hitTest(x, y)) ?? null;
|
|
18
|
+
},
|
|
19
|
+
paints(renderable) {
|
|
20
|
+
const node = renderable as { backgroundColor?: unknown; bg?: unknown };
|
|
21
|
+
return filled(node.backgroundColor) || filled(node.bg);
|
|
22
|
+
},
|
|
23
|
+
attached(renderable) {
|
|
24
|
+
let node = renderable as { parent?: unknown; isDestroyed?: boolean } | null;
|
|
25
|
+
if (!node || node.isDestroyed) return false;
|
|
26
|
+
for (let depth = 0; node && depth < 512; depth += 1) {
|
|
27
|
+
if (node === renderer.root) return true;
|
|
28
|
+
node = (node.parent ?? null) as typeof node;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -13,6 +13,7 @@ import { installInteractionPerformanceRecorder } from "./interaction-performance
|
|
|
13
13
|
import { provideKittyServices } from "./kitty-services";
|
|
14
14
|
import { setTerminalReportsControlKeys } from "../../app/keybindings/terminal-keys";
|
|
15
15
|
import { captureRendererFrame } from "./frame-capture";
|
|
16
|
+
import { createFrameHits } from "./frame-hits";
|
|
16
17
|
import {
|
|
17
18
|
createTimerFrameDriver,
|
|
18
19
|
installMarketDataFrameDriver,
|
|
@@ -245,6 +246,7 @@ export async function createOpenTuiHost(): Promise<OpenTuiHost> {
|
|
|
245
246
|
removePostProcessFn: (processFn) => renderer.removePostProcessFn(processFn as any),
|
|
246
247
|
copyToClipboardOSC52: (text) => renderer.copyToClipboardOSC52(text),
|
|
247
248
|
captureFrame: () => captureRendererFrame(renderer),
|
|
249
|
+
frameHits: createFrameHits(renderer),
|
|
248
250
|
async capturePaneImage(rect) {
|
|
249
251
|
if (renderer.isDestroyed) throw new Error("The terminal has closed.");
|
|
250
252
|
// Loaded on first use: the glyph atlas is only needed for a picture.
|
|
@@ -6,7 +6,12 @@ import {
|
|
|
6
6
|
type CellRect,
|
|
7
7
|
type NativeChartBitmap,
|
|
8
8
|
} from "../../components/chart/native/chart-rasterizer";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
getNativeSurfaceManager,
|
|
11
|
+
insetCellRect,
|
|
12
|
+
type CellInsets,
|
|
13
|
+
type NativeSurfaceAnchor,
|
|
14
|
+
} from "../../components/chart/native/surface/manager";
|
|
10
15
|
import {
|
|
11
16
|
getRenderableCellRect,
|
|
12
17
|
resolveNativeSurfaceVisibleRect,
|
|
@@ -32,38 +37,24 @@ export interface NativeSurfaceTarget {
|
|
|
32
37
|
pixelHeight: number;
|
|
33
38
|
/** The source key plus the pixel size, so a resize uploads a fresh bitmap. */
|
|
34
39
|
bitmapKey: string;
|
|
40
|
+
/** The box drawn over, which the image layer measures again after every frame. */
|
|
41
|
+
anchor: NativeSurfaceAnchor;
|
|
35
42
|
}
|
|
36
43
|
|
|
37
|
-
export
|
|
38
|
-
top: number;
|
|
39
|
-
right: number;
|
|
40
|
-
bottom: number;
|
|
41
|
-
left: number;
|
|
42
|
-
}
|
|
44
|
+
export type { CellInsets };
|
|
43
45
|
|
|
44
46
|
function sameTarget(left: NativeSurfaceTarget | null, right: NativeSurfaceTarget | null): boolean {
|
|
45
47
|
if (left === right) return true;
|
|
46
48
|
if (!left || !right) return false;
|
|
47
49
|
return left.bitmapKey === right.bitmapKey
|
|
50
|
+
&& left.anchor.renderable === right.anchor.renderable
|
|
51
|
+
&& left.anchor.insets === right.anchor.insets
|
|
48
52
|
&& left.pixelWidth === right.pixelWidth
|
|
49
53
|
&& left.pixelHeight === right.pixelHeight
|
|
50
54
|
&& sameCellRect(left.rect, right.rect)
|
|
51
55
|
&& sameCellRect(left.visibleRect, right.visibleRect);
|
|
52
56
|
}
|
|
53
57
|
|
|
54
|
-
function insetRect(rect: CellRect, insets: CellInsets | undefined): CellRect | null {
|
|
55
|
-
if (!insets) return rect;
|
|
56
|
-
const width = rect.width - insets.left - insets.right;
|
|
57
|
-
const height = rect.height - insets.top - insets.bottom;
|
|
58
|
-
if (width <= 0 || height <= 0) return null;
|
|
59
|
-
return {
|
|
60
|
-
x: rect.x + insets.left,
|
|
61
|
-
y: rect.y + insets.top,
|
|
62
|
-
width,
|
|
63
|
-
height,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
58
|
/**
|
|
68
59
|
* Where a terminal image surface should draw, re-measured on every lifecycle
|
|
69
60
|
* pass so it follows layout, scrolling and clipping.
|
|
@@ -96,7 +87,7 @@ export function useNativeSurfaceTarget(
|
|
|
96
87
|
let mountTimer: Timer | null = null;
|
|
97
88
|
const previousLifecyclePass = renderable.onLifecyclePass;
|
|
98
89
|
const syncTarget = () => {
|
|
99
|
-
const rect =
|
|
90
|
+
const rect = insetCellRect(getRenderableCellRect(renderable), insets);
|
|
100
91
|
if (!rect || !renderer.resolution || renderer.terminalWidth <= 0 || renderer.terminalHeight <= 0) {
|
|
101
92
|
setTarget((current) => (current === null ? current : null));
|
|
102
93
|
return;
|
|
@@ -110,6 +101,7 @@ export function useNativeSurfaceTarget(
|
|
|
110
101
|
pixelWidth: size.pixelWidth,
|
|
111
102
|
pixelHeight: size.pixelHeight,
|
|
112
103
|
bitmapKey: `${sourceKey}:${size.pixelWidth}x${size.pixelHeight}`,
|
|
104
|
+
anchor: { renderable, insets },
|
|
113
105
|
};
|
|
114
106
|
setTarget((current) => (sameTarget(current, nextTarget) ? current : nextTarget));
|
|
115
107
|
};
|
|
@@ -170,6 +162,7 @@ export function useNativeSurface(
|
|
|
170
162
|
visibleRect: target.visibleRect,
|
|
171
163
|
bitmap,
|
|
172
164
|
bitmapKey: target.bitmapKey,
|
|
165
|
+
anchor: target.anchor,
|
|
173
166
|
});
|
|
174
167
|
renderer.requestRender();
|
|
175
168
|
}, [bitmap, nativeSurfaceManager, paneId, renderer, surfaceId, target]);
|
|
@@ -9,6 +9,7 @@ import { AppDialogBridge } from "../../app/dialog-bridge";
|
|
|
9
9
|
import { OpenTuiDialogHostProvider } from "./dialog-host";
|
|
10
10
|
import { OpenTuiInputHostProvider } from "./input-host";
|
|
11
11
|
import { provideKittyServices } from "./kitty-services";
|
|
12
|
+
import { createFrameHits } from "./frame-hits";
|
|
12
13
|
import { captureRendererFrame } from "./frame-capture";
|
|
13
14
|
import { openTuiToastHost } from "./toast-host";
|
|
14
15
|
import { openTuiUiHost } from "./ui-host";
|
|
@@ -90,6 +91,8 @@ function createTestNativeRendererHost(renderer: any): NativeRendererHost {
|
|
|
90
91
|
}
|
|
91
92
|
// What a feedback report and Ask Gloom read from the screen, as the app's host gives it.
|
|
92
93
|
if (typeof renderer.captureFrame !== "function") renderer.captureFrame = () => captureRendererFrame(renderer);
|
|
94
|
+
// What covers a kitty image, as the app's host reads it.
|
|
95
|
+
if (!renderer.frameHits) renderer.frameHits = createFrameHits(renderer);
|
|
93
96
|
return provideKittyServices(renderer as NativeRendererHost);
|
|
94
97
|
}
|
|
95
98
|
|
package/src/series/types.ts
CHANGED
|
@@ -86,6 +86,8 @@ export interface SeriesLoadRequest {
|
|
|
86
86
|
export interface SeriesAttribution {
|
|
87
87
|
source: string;
|
|
88
88
|
publisher?: string;
|
|
89
|
+
/** When its newest observation was published, an ISO instant, when the source says. */
|
|
90
|
+
publishedAt?: string;
|
|
89
91
|
}
|
|
90
92
|
|
|
91
93
|
export interface SeriesLoadResult {
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { parseReportTime } from "../../utils/utc-time";
|
|
2
|
+
import { seriesNotOnFred, type FredSeriesData } from "./fred-series";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* When FRED last updated a series, its `last_updated` (`2026-10-09 08:08:04-05`),
|
|
6
|
+
* as an ISO instant in UTC: the publication time an export cites. Only when
|
|
7
|
+
* that update covers the newest observation shown (`observationEnd` reaches
|
|
8
|
+
* it): metadata from before it says nothing about when it was published.
|
|
9
|
+
* Null when it does not, or when FRED's metadata does not say.
|
|
10
|
+
*/
|
|
11
|
+
export function fredPublicationTime(
|
|
12
|
+
info: { lastUpdated?: string | null; observationEnd?: string | null } | null | undefined,
|
|
13
|
+
newestDate: string | null | undefined,
|
|
14
|
+
): string | null {
|
|
15
|
+
if (newestDate && !(info?.observationEnd && info.observationEnd >= newestDate)) return null;
|
|
16
|
+
const iso = (info?.lastUpdated ?? "").trim().replace(/^(\d{4}-\d{2}-\d{2}) /, "$1T").replace(/([+-]\d{2})$/, "$1:00");
|
|
17
|
+
const time = parseReportTime(iso);
|
|
18
|
+
return time && !time.dateOnly ? new Date(time.time).toISOString() : null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Where a FRED report's figures come from, as its source line names them. */
|
|
22
|
+
export interface FredProvenance {
|
|
23
|
+
source: string;
|
|
24
|
+
publisher?: string;
|
|
25
|
+
publishedAt?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Where the newest of these observations comes from: FRED, unless Gloom
|
|
30
|
+
* Cloud carried a value FRED does not list yet and named its publisher. Then
|
|
31
|
+
* the source line names that publisher and when it published, so a reader
|
|
32
|
+
* looking for the figure in FRED's own data knows it is not there yet:
|
|
33
|
+
* `U.S. Treasury via FRED, published 2026-10-09`. Null for FRED's own.
|
|
34
|
+
*/
|
|
35
|
+
export function fredProvenance(
|
|
36
|
+
observations: ReadonlyArray<{ date: string; publisher?: string; publishedAt?: string }>,
|
|
37
|
+
seriesId?: string,
|
|
38
|
+
): FredProvenance | null {
|
|
39
|
+
const ahead = observations.filter((observation) => observation.publisher?.trim());
|
|
40
|
+
if (ahead.length === 0) return null;
|
|
41
|
+
const publishers = [...new Set(ahead.map((observation) => observation.publisher!.trim()))];
|
|
42
|
+
const times = ahead.flatMap((observation) => {
|
|
43
|
+
const time = parseReportTime(observation.publishedAt);
|
|
44
|
+
return time ? [new Date(time.time).toISOString()] : [];
|
|
45
|
+
}).sort();
|
|
46
|
+
const publishedAt = times.at(-1);
|
|
47
|
+
const publisher = publishers.join(" and ");
|
|
48
|
+
return {
|
|
49
|
+
// A series FRED does not carry names whose publication it is read from instead (TurkStat via the CBRT).
|
|
50
|
+
source: `${publisher} via ${(seriesId ? seriesNotOnFred(seriesId)?.via : null) ?? "FRED"}${publishedAt ? `, published ${publishedAt.slice(0, 10)}` : ""}`,
|
|
51
|
+
publisher,
|
|
52
|
+
...(publishedAt ? { publishedAt } : {}),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Who a series FRED does not carry comes from, for a source line whose rows do not name it: `TurkStat via the CBRT`. */
|
|
57
|
+
export function notOnFredSource(seriesId: string): string | null {
|
|
58
|
+
const elsewhere = seriesNotOnFred(seriesId);
|
|
59
|
+
return elsewhere ? `${elsewhere.publisher} via ${elsewhere.via}` : null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Who publishes a served series and when its newest observation was
|
|
64
|
+
* published, as `fred` cites it and every chart, catalog row and export of
|
|
65
|
+
* the series must too: its newest value's own publisher when Gloom Cloud
|
|
66
|
+
* carried one FRED does not list yet (`TurkStat via the CBRT, published
|
|
67
|
+
* 2026-11-03`), else FRED, naming the publisher FRED's metadata gives and
|
|
68
|
+
* when FRED last updated the series.
|
|
69
|
+
*/
|
|
70
|
+
export function fredSeriesAttribution(
|
|
71
|
+
seriesId: string,
|
|
72
|
+
data: Pick<FredSeriesData, "observations" | "info">,
|
|
73
|
+
): FredProvenance {
|
|
74
|
+
const newestDate = data.observations.reduce<string | null>((newest, observation) => (
|
|
75
|
+
observation.value != null && (!newest || observation.date > newest) ? observation.date : newest
|
|
76
|
+
), null);
|
|
77
|
+
const ahead = fredProvenance(data.observations.filter((observation) => observation.date === newestDate), seriesId);
|
|
78
|
+
if (ahead) return ahead;
|
|
79
|
+
const publisher = data.info?.source?.trim();
|
|
80
|
+
const publishedAt = fredPublicationTime(data.info, newestDate);
|
|
81
|
+
return {
|
|
82
|
+
source: notOnFredSource(seriesId) ?? "FRED",
|
|
83
|
+
...(publisher ? { publisher } : {}),
|
|
84
|
+
...(publishedAt ? { publishedAt } : {}),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -49,7 +49,7 @@ import { resolveCurrencyUnit } from "../../utils/currency-units";
|
|
|
49
49
|
import { exchangeLineCoinListing, isRoundTheClockCoin, withExchangeLinesAsCoinListings } from "../../utils/crypto-pair";
|
|
50
50
|
import { canonicalExchange, canonicalTickerKey, parsePublicTickerKey } from "../../utils/exchanges";
|
|
51
51
|
import { normalizePriceHistory, priceHistoryIntervalMs, reachesLatestSettledSession } from "../../utils/price-history";
|
|
52
|
-
import { createProviderMiss, ProviderBusyError, providerMissReason, StaleHistoryError } from "../provider-errors";
|
|
52
|
+
import { createProviderMiss, isRateLimited, ProviderBusyError, providerMissReason, StaleHistoryError } from "../provider-errors";
|
|
53
53
|
import { parseListingDelisting } from "../../market-data/quotes/delisting";
|
|
54
54
|
import { isRetryableApiError, markAskedTwice, sourceDidNotAnswer, wasAskedTwice } from "../../api-client/errors";
|
|
55
55
|
import { assertSecRegistrantMatches } from "../sec-registrant";
|
|
@@ -94,8 +94,13 @@ import { cleanListingName } from "../../tickers/company-name";
|
|
|
94
94
|
import { settleWithin } from "../../utils/async-deadline";
|
|
95
95
|
import { cloudSearchBatch, cloudTickerChangesBatch } from "./batched-lookups";
|
|
96
96
|
import { cappedAnswerStart, firstBarDate, reachesWindowStart, withOlderBars } from "./dated-chunks";
|
|
97
|
+
import { chunked, mapWithConcurrency } from "../../utils/concurrency";
|
|
97
98
|
|
|
98
99
|
const providerId = GLOOMBERB_CLOUD_PROVIDER_ID;
|
|
100
|
+
/** Listings in one quote batch request: the most the service reads in a signed-out batch. */
|
|
101
|
+
const QUOTE_BATCH_SIZE = 100;
|
|
102
|
+
/** Quote batch requests of one long list in flight at once. */
|
|
103
|
+
const QUOTE_BATCHES_IN_FLIGHT = 3;
|
|
99
104
|
/** How long a search that is not typed waits for perpetual markets. */
|
|
100
105
|
const PERPETUAL_SEARCH_WAIT_MS = 2_000;
|
|
101
106
|
/** How long a batched search waits for the board it answers every query's perpetual markets from. */
|
|
@@ -655,6 +660,25 @@ export class GloomberbCloudProvider implements AssetDataProvider {
|
|
|
655
660
|
const { valid, invalid } = cloudBatchTargets(targets);
|
|
656
661
|
const rejected = invalid.map((entry) => ({ ...entry, quote: null }));
|
|
657
662
|
if (!valid.length) return rejected;
|
|
663
|
+
// A request per hundred listings, a few in flight: the service reads a signed-out batch of a hundred at most and
|
|
664
|
+
// refuses a longer one whole, which left a pasted list of 300 to be asked one listing at a time.
|
|
665
|
+
// A request refused for the service's request limit leaves its listings, and those of the requests not sent yet,
|
|
666
|
+
// with that refusal: the others keep their answers.
|
|
667
|
+
if (valid.length > QUOTE_BATCH_SIZE) {
|
|
668
|
+
let refusal: unknown = null;
|
|
669
|
+
const chunks = await mapWithConcurrency(chunked(valid.map((entry) => entry.target), QUOTE_BATCH_SIZE), QUOTE_BATCHES_IN_FLIGHT,
|
|
670
|
+
async (chunk): Promise<QuoteBatchResult[]> => {
|
|
671
|
+
if (refusal) return chunk.map((target) => ({ target, quote: null, error: refusal }));
|
|
672
|
+
try {
|
|
673
|
+
return await this.getQuotesBatch(chunk, options);
|
|
674
|
+
} catch (error) {
|
|
675
|
+
if (!isRateLimited(error)) throw error;
|
|
676
|
+
refusal = error;
|
|
677
|
+
return chunk.map((target) => ({ target, quote: null, error }));
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
return [...rejected, ...chunks.flat()];
|
|
681
|
+
}
|
|
658
682
|
const submitted = valid.map((entry) => entry.target);
|
|
659
683
|
return withCloudFallback(async () => {
|
|
660
684
|
const response = await apiClient.getCloudQuotesBatch(
|
|
@@ -33,6 +33,8 @@ import { isBankOrInsurerIndustry, withStatementEbitda } from "../../utils/ebitda
|
|
|
33
33
|
import { parseListingDelisting } from "../../market-data/quotes/delisting";
|
|
34
34
|
import { readIntradayBar, readStaleReason } from "../../market-data/quotes/intraday-bar";
|
|
35
35
|
import { readSessionSplit } from "../../market-data/quotes/session-split";
|
|
36
|
+
import { isIndexLevel } from "../../market-data/market/index-level";
|
|
37
|
+
import { isYieldIndexSymbol } from "../../tickers/index-roots";
|
|
36
38
|
|
|
37
39
|
export const GLOOMBERB_CLOUD_PROVIDER_ID = "gloomberb-cloud" as const;
|
|
38
40
|
|
|
@@ -109,6 +111,13 @@ export function mapQuote(
|
|
|
109
111
|
const priceBasis = quote.priceBasis === "nav"
|
|
110
112
|
? "per-unit"
|
|
111
113
|
: futuresBasis ?? quote.priceBasis;
|
|
114
|
+
// An index's 0 open or day range is none (^BVSP before B3 opens served Open 0.00, Day Range 0.00 - 0.00): no level
|
|
115
|
+
// is 0. A Treasury yield index's is (^IRX read 0.00 in 2020), and its levels stand.
|
|
116
|
+
const index = isIndexLevel(quote.instrumentType) && !isYieldIndexSymbol(quote.symbol ?? "");
|
|
117
|
+
const sessionPrice = (value: number | undefined) => {
|
|
118
|
+
const price = normalizePriceValueByDivisor(value, divisor);
|
|
119
|
+
return index && price != null && price <= 0 ? undefined : price;
|
|
120
|
+
};
|
|
112
121
|
return withoutUndefinedFields(reconcileQuoteDayRange({
|
|
113
122
|
...quote,
|
|
114
123
|
retrievedAt: serviceRetrievedAt(quote.retrievedAt),
|
|
@@ -132,11 +141,15 @@ export function mapQuote(
|
|
|
132
141
|
: undefined,
|
|
133
142
|
high52w: normalizePriceValueByDivisor(quote.high52w, divisor),
|
|
134
143
|
low52w: normalizePriceValueByDivisor(quote.low52w, divisor),
|
|
144
|
+
// The service read the 52-week range from its stored daily bars, its source's being unusable.
|
|
145
|
+
yearRangeBasis: quote.yearRangeBasis === "daily-bars" ? "daily-bars" : undefined,
|
|
146
|
+
// No live quote: the close of the latest daily bar of this session.
|
|
147
|
+
dailyClose: readDailyClose(quote.dailyClose),
|
|
135
148
|
bid: normalizePriceValueByDivisor(quote.bid, divisor),
|
|
136
149
|
ask: normalizePriceValueByDivisor(quote.ask, divisor),
|
|
137
|
-
open:
|
|
138
|
-
high:
|
|
139
|
-
low:
|
|
150
|
+
open: sessionPrice(quote.open),
|
|
151
|
+
high: sessionPrice(quote.high),
|
|
152
|
+
low: sessionPrice(quote.low),
|
|
140
153
|
mark: normalizePriceValueByDivisor(quote.mark, divisor),
|
|
141
154
|
lastTradePrice: normalizePriceValueByDivisor(quote.lastTradePrice, divisor),
|
|
142
155
|
preMarketPrice: normalizePriceValueByDivisor(quote.preMarketPrice, divisor),
|
|
@@ -195,6 +208,12 @@ export function mapQuote(
|
|
|
195
208
|
}));
|
|
196
209
|
}
|
|
197
210
|
|
|
211
|
+
/** A daily close's session, an exchange-local `YYYY-MM-DD`; anything else is no daily close. */
|
|
212
|
+
function readDailyClose(value: unknown): Quote["dailyClose"] {
|
|
213
|
+
const session = value && typeof value === "object" ? (value as { session?: unknown }).session : undefined;
|
|
214
|
+
return typeof session === "string" && /^\d{4}-\d{2}-\d{2}$/.test(session) ? { session } : undefined;
|
|
215
|
+
}
|
|
216
|
+
|
|
198
217
|
/**
|
|
199
218
|
* JSON has no undefined, so a field the server left out must stay absent here
|
|
200
219
|
* too; the desktop window only ever sees the JSON form. Whether an omitted
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DataServiceUnreachableError, isNetworkFailure } from "../utils/network-failure";
|
|
2
|
-
import { wasAskedTwice } from "../api-client/errors";
|
|
2
|
+
import { ApiRequestError, wasAskedTwice } from "../api-client/errors";
|
|
3
3
|
|
|
4
4
|
// Registered, so a miss raised by another copy of this module (a plugin that
|
|
5
5
|
// resolved `gloomberb/market-data` from the source tree) is still recognized.
|
|
@@ -163,9 +163,22 @@ export function noProviderError(message: string, note: ProviderMissNote | undefi
|
|
|
163
163
|
return note!.failure instanceof DataServiceUnreachableError ? note!.failure : new DataServiceUnreachableError(note!.failure);
|
|
164
164
|
}
|
|
165
165
|
if (wasAskedTwice(note?.failure)) return new NoProviderError(serviceDidNotAnswerMessage(symbol), note!.failure);
|
|
166
|
+
if (note?.failure instanceof ApiRequestError && note.failure.status === 429) {
|
|
167
|
+
return new NoProviderError(rateLimitedMessage(symbol, note.failure.retryAfterMs), note.failure);
|
|
168
|
+
}
|
|
166
169
|
return new NoProviderError(message, note?.failure);
|
|
167
170
|
}
|
|
168
171
|
|
|
172
|
+
/**
|
|
173
|
+
* What a read says when Gloom's data service refused it for its request limit
|
|
174
|
+
* (429): not that the listing has no data, and when to ask again. "for SYMBOL"
|
|
175
|
+
* closes the first sentence, as `serviceDidNotAnswerMessage` words it.
|
|
176
|
+
*/
|
|
177
|
+
export function rateLimitedMessage(symbol?: string, retryAfterMs?: number): string {
|
|
178
|
+
const wait = retryAfterMs && retryAfterMs > 0 ? `in ${Math.ceil(retryAfterMs / 1000)} s` : "in a minute";
|
|
179
|
+
return `Gloom's data service is at its request limit${symbol ? ` for ${symbol}` : ""}. Try again ${wait}.`;
|
|
180
|
+
}
|
|
181
|
+
|
|
169
182
|
/**
|
|
170
183
|
* The router's answer that no source served a read because one failed (a
|
|
171
184
|
* timeout, a rate limit, a refused session), not because none has it: asked
|
|
@@ -212,3 +225,53 @@ export function shouldLogProviderError(error: unknown): boolean {
|
|
|
212
225
|
const message = error instanceof Error ? error.message : String(error);
|
|
213
226
|
return !EXPECTED_PROVIDER_MISS.test(message);
|
|
214
227
|
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* The data service's refusal of a read for its request limit (429), however
|
|
231
|
+
* it reached the caller: as itself, as the failure behind the router's "No
|
|
232
|
+
* quote provider available", or as the cause of a busy search. Null for any
|
|
233
|
+
* other failure.
|
|
234
|
+
*/
|
|
235
|
+
function rateLimitRefusal(error: unknown, depth = 0): ApiRequestError | null {
|
|
236
|
+
if (!error || typeof error !== "object" || depth > 4) return null;
|
|
237
|
+
if (error instanceof ApiRequestError) return error.status === 429 ? error : null;
|
|
238
|
+
if (error instanceof NoProviderError) return rateLimitRefusal(error.failure, depth + 1);
|
|
239
|
+
return rateLimitRefusal((error as { cause?: unknown }).cause, depth + 1);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Whether a read was refused for the data service's request limit, including
|
|
244
|
+
* one whose message alone crossed a bridge ("... at its request limit for
|
|
245
|
+
* AAPL. Try again in 40 s."). Never asked again: asking is more of what it
|
|
246
|
+
* refused, so the row keeps when to try.
|
|
247
|
+
*/
|
|
248
|
+
export function isRateLimited(error: unknown): boolean {
|
|
249
|
+
if (error == null) return false;
|
|
250
|
+
if (rateLimitRefusal(error)) return true;
|
|
251
|
+
const message = (error instanceof Error ? error.message : String(error)).trim();
|
|
252
|
+
return message.startsWith(rateLimitedMessage().split(".")[0]!);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* A read refused for the request limit, worded as a single read of `symbol`
|
|
257
|
+
* says it: "Gloom's data service is at its request limit for AAPL. Try again
|
|
258
|
+
* in 40 s.". The error itself when it says so already.
|
|
259
|
+
*/
|
|
260
|
+
export function rateLimitedError(error: unknown, symbol: string): unknown {
|
|
261
|
+
const refusal = rateLimitRefusal(error);
|
|
262
|
+
return refusal ? new NoProviderError(rateLimitedMessage(symbol, refusal.retryAfterMs), refusal) : error;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Whether a failure says nothing of what was asked, so asked again in a
|
|
267
|
+
* moment it may be answered: no connection, no answer from the data service,
|
|
268
|
+
* or a busy moment. A source's own answer (Not a ticker, a delisting) is not
|
|
269
|
+
* one, and neither is the request limit (`isRateLimited`), which is never
|
|
270
|
+
* asked again.
|
|
271
|
+
*/
|
|
272
|
+
export function isTransientServiceFailure(error: unknown): boolean {
|
|
273
|
+
if (error == null || isRateLimited(error)) return false;
|
|
274
|
+
if (isNetworkFailure(error) || isProviderBusy(error)) return true;
|
|
275
|
+
const message = (error instanceof Error ? error.message : String(error)).trim();
|
|
276
|
+
return message.startsWith(serviceDidNotAnswerMessage().split(".")[0]!);
|
|
277
|
+
}
|
|
@@ -27,6 +27,8 @@ import {
|
|
|
27
27
|
type CachedFinancialsSelection,
|
|
28
28
|
} from "./financials";
|
|
29
29
|
import type { ProviderRouterCoreDeps } from "./route-types";
|
|
30
|
+
import { isRateLimited, rateLimitedError } from "../provider-errors";
|
|
31
|
+
import { quoteServedFromSavedCopy } from "../../data/saved-copies";
|
|
30
32
|
import { isNetworkFailure } from "../../utils/network-failure";
|
|
31
33
|
import { withRetrievedAt } from "./retrieved-at";
|
|
32
34
|
|
|
@@ -62,6 +64,8 @@ export class ProviderRouterBatchRoutes {
|
|
|
62
64
|
const results = new Array<QuoteBatchResult | null>(targets.length).fill(null);
|
|
63
65
|
// A dated price the batch answered that is not current: shown, flagged stale, when asking alone brings none.
|
|
64
66
|
const lastKnown = new Array<Quote | null>(targets.length).fill(null);
|
|
67
|
+
// The data service's copy each listing has saved here, which answers for it when the service refuses the batch.
|
|
68
|
+
const saved = new Array<{ value: Quote; fetchedAt: number } | null>(targets.length).fill(null);
|
|
65
69
|
const misses: Array<{ index: number; target: QuoteSubscriptionTarget }> = [];
|
|
66
70
|
|
|
67
71
|
targets.forEach((target, index) => {
|
|
@@ -88,6 +92,7 @@ export class ProviderRouterBatchRoutes {
|
|
|
88
92
|
return;
|
|
89
93
|
}
|
|
90
94
|
// Revalidated, a fresh copy is still what the quote route answers when no source does.
|
|
95
|
+
if (cached && !brokerSourceKeys.includes(cached.sourceKey)) saved[index] = cached;
|
|
91
96
|
misses.push({ index, target });
|
|
92
97
|
});
|
|
93
98
|
|
|
@@ -95,6 +100,8 @@ export class ProviderRouterBatchRoutes {
|
|
|
95
100
|
const providerMisses = misses.filter(({ target }) => !this.deps.hasBrokerContext(target.context));
|
|
96
101
|
const providerIndexes = new Map<string, Array<{ index: number; target: QuoteSubscriptionTarget }>>();
|
|
97
102
|
let batchFailure: unknown = null;
|
|
103
|
+
// Listings the service refused for its request limit, by batch key, with the refusal.
|
|
104
|
+
const limited = new Map<string, unknown>();
|
|
98
105
|
if (batchProvider && providerMisses.length > 0) {
|
|
99
106
|
for (const entry of providerMisses) {
|
|
100
107
|
const key = this.quoteBatchKey(entry.target);
|
|
@@ -111,6 +118,7 @@ export class ProviderRouterBatchRoutes {
|
|
|
111
118
|
for (const answered of batchResults) {
|
|
112
119
|
const item = { ...answered, quote: withRetrievedAt(answered.quote, answeredAt) };
|
|
113
120
|
const key = this.quoteBatchKey(item.target);
|
|
121
|
+
if (!item.quote && isRateLimited(item.error)) limited.set(key, item.error);
|
|
114
122
|
if (!isProviderQuoteUsableForCurrentSession(item.quote, item.target.exchange, item.target.symbol, { recentAnswer: true })) {
|
|
115
123
|
const fallback = lastKnownProviderQuote(item.quote, item.target.exchange, item.target.symbol);
|
|
116
124
|
if (fallback) for (const entry of providerIndexes.get(key) ?? []) lastKnown[entry.index] = fallback;
|
|
@@ -126,6 +134,17 @@ export class ProviderRouterBatchRoutes {
|
|
|
126
134
|
}
|
|
127
135
|
}
|
|
128
136
|
|
|
137
|
+
// Refused for the request limit, a listing is never asked again alone: that is a request each, more of what was
|
|
138
|
+
// refused. Its saved copy answers, as a single read's would, else the row says when to try again.
|
|
139
|
+
for (const { index, target } of providerMisses) {
|
|
140
|
+
const refusal = isRateLimited(batchFailure) ? batchFailure : limited.get(this.quoteBatchKey(target));
|
|
141
|
+
if (results[index] || refusal === undefined) continue;
|
|
142
|
+
const copy = saved[index];
|
|
143
|
+
results[index] = copy ? { target, quote: quoteServedFromSavedCopy(withRetrievedAt(copy.value, copy.fetchedAt), copy.fetchedAt) }
|
|
144
|
+
: lastKnown[index] ? { target, quote: lastKnown[index] }
|
|
145
|
+
: { target, quote: null, error: rateLimitedError(refusal, target.symbol) };
|
|
146
|
+
}
|
|
147
|
+
|
|
129
148
|
// The batch never reached the data service: a copy saved a moment ago is still a saved copy, not the
|
|
130
149
|
// service's answer, so each is asked for as a refresh, which fails at once and says it answers from that copy.
|
|
131
150
|
const unreached = isNetworkFailure(batchFailure) ? new Set(providerMisses.map(({ index }) => index)) : null;
|
|
@@ -33,6 +33,8 @@ import { assertTimeRange, type TimeRange } from "../../time-series/range";
|
|
|
33
33
|
import type { ChartResolutionSupport, ManualChartResolution } from "../../time-series/resolution";
|
|
34
34
|
import { debugLog } from "../../utils/debug-log";
|
|
35
35
|
import { errorMessage } from "../../utils/errors";
|
|
36
|
+
import { isProviderBusy, isRateLimited, isSourceFailure } from "../provider-errors";
|
|
37
|
+
import { isNetworkFailure } from "../../utils/network-failure";
|
|
36
38
|
import { isPastPreCloseRefetch } from "../../utils/exchange-rate-snapshot";
|
|
37
39
|
import { ProviderRouterBatchRoutes } from "./batches";
|
|
38
40
|
import { createSignedInRealtimeCloudAccess, type RealtimeCloudAccess } from "./realtime-access";
|
|
@@ -259,7 +261,11 @@ export class AssetDataRouter implements DataProvider {
|
|
|
259
261
|
// Error into {} and its reason into "[object Object]" on the board.
|
|
260
262
|
return targets.map((target) => {
|
|
261
263
|
const result = restored.get(target) ?? { target, quote: null };
|
|
262
|
-
|
|
264
|
+
if (result.error == null) return result;
|
|
265
|
+
// The request limit is no moment's failure: asked again it is more of what was refused (`isRateLimited`).
|
|
266
|
+
const transient = !isRateLimited(result.error)
|
|
267
|
+
&& (isSourceFailure(result.error) || isNetworkFailure(result.error) || isProviderBusy(result.error));
|
|
268
|
+
return { ...result, error: errorMessage(result.error), ...transient ? { transient } : {} };
|
|
263
269
|
});
|
|
264
270
|
}
|
|
265
271
|
|
|
@@ -26,6 +26,7 @@ import { setPaneSetting, setPaneSettings, updatePaneInstance } from "../../../pa
|
|
|
26
26
|
import { useTickerFinancials } from "../../../market-data/hooks";
|
|
27
27
|
import { hasAmbiguousTickerContracts, resolveInstrumentForPane, resolveListingForPane, tickerForInstrument } from "../../../core/state/app/instrument";
|
|
28
28
|
import { materializeDetachedLayouts } from "../../../core/state/app/layout";
|
|
29
|
+
import { isPaneChoice, withAllPaneChoices } from "../../../core/state/app/pane-choices";
|
|
29
30
|
import {
|
|
30
31
|
APP_SESSION_ID,
|
|
31
32
|
APP_SESSION_SCHEMA_VERSION,
|
|
@@ -339,6 +340,21 @@ export function usePaneStateValue<T>(key: string, fallback: T, paneId?: string):
|
|
|
339
340
|
return [value, setValue];
|
|
340
341
|
}
|
|
341
342
|
|
|
343
|
+
/**
|
|
344
|
+
* Whether this pane's `key` was chosen in this session rather than restored
|
|
345
|
+
* with the workspace, and the call for a pick that may leave the value as it
|
|
346
|
+
* is (see `pane-choices.ts`). Any write of the key already counts.
|
|
347
|
+
*/
|
|
348
|
+
export function usePaneChoice(key: string, paneId?: string): [chosen: boolean, choose: () => void] {
|
|
349
|
+
const dispatch = useAppDispatch();
|
|
350
|
+
const scopedPaneId = useScopedPaneId(paneId);
|
|
351
|
+
const chosen = useAppSelector((state) => isPaneChoice(state, scopedPaneId, key));
|
|
352
|
+
const choose = useCallback(() => {
|
|
353
|
+
dispatch({ type: "CHOOSE_PANE_STATE", paneId: scopedPaneId, key });
|
|
354
|
+
}, [dispatch, key, scopedPaneId]);
|
|
355
|
+
return [chosen, choose];
|
|
356
|
+
}
|
|
357
|
+
|
|
342
358
|
export function usePaneSettingValue<T>(
|
|
343
359
|
key: string,
|
|
344
360
|
fallback: T,
|
|
@@ -376,6 +392,28 @@ export function useUpdatePaneSettings(paneId?: string) {
|
|
|
376
392
|
}, [scopedPaneId, updateLayout]);
|
|
377
393
|
}
|
|
378
394
|
|
|
395
|
+
/**
|
|
396
|
+
* Rewrites one setting of a pane that may be absent (a table drawn outside a
|
|
397
|
+
* pane): `update` gets its value and returns the next one, `undefined` to
|
|
398
|
+
* remove it, or the same value to leave the layout alone.
|
|
399
|
+
*/
|
|
400
|
+
export function useOptionalPaneSettingUpdater(paneId: string | null, key: string) {
|
|
401
|
+
const updateLayout = useUpdatePaneLayout();
|
|
402
|
+
return useCallback((update: (value: unknown) => unknown) => {
|
|
403
|
+
if (!paneId) return;
|
|
404
|
+
updateLayout((layout) => {
|
|
405
|
+
const pane = findPaneInstance(layout, paneId);
|
|
406
|
+
if (!pane) return layout;
|
|
407
|
+
const current = pane.settings?.[key];
|
|
408
|
+
const next = update(current);
|
|
409
|
+
if (Object.is(next, current)) return layout;
|
|
410
|
+
if (next !== undefined) return setPaneSetting(layout, paneId, key, next);
|
|
411
|
+
const { [key]: _removed, ...rest } = pane.settings ?? {};
|
|
412
|
+
return setPaneSettings(layout, paneId, Object.keys(rest).length > 0 ? rest : undefined);
|
|
413
|
+
});
|
|
414
|
+
}, [key, paneId, updateLayout]);
|
|
415
|
+
}
|
|
416
|
+
|
|
379
417
|
function useScopedPaneId(paneId?: string): string {
|
|
380
418
|
const contextId = useOptionalPaneInstanceId();
|
|
381
419
|
const id = paneId ?? contextId;
|
|
@@ -423,6 +461,7 @@ export function AppProvider({
|
|
|
423
461
|
desktopBridge,
|
|
424
462
|
desktopSnapshot = null,
|
|
425
463
|
initialThemePreview = null,
|
|
464
|
+
paneStateChosen = false,
|
|
426
465
|
}: {
|
|
427
466
|
config: AppConfig;
|
|
428
467
|
children: ReactNode;
|
|
@@ -431,6 +470,11 @@ export function AppProvider({
|
|
|
431
470
|
desktopBridge?: DesktopWindowBridge;
|
|
432
471
|
desktopSnapshot?: DesktopSharedStateSnapshot | null;
|
|
433
472
|
initialThemePreview?: DesktopThemePreviewState | null;
|
|
473
|
+
/**
|
|
474
|
+
* The pane state it starts with was asked for now (a pane function's
|
|
475
|
+
* capture), not restored with a workspace: see `pane-choices.ts`.
|
|
476
|
+
*/
|
|
477
|
+
paneStateChosen?: boolean;
|
|
434
478
|
}) {
|
|
435
479
|
const [state, rawDispatch] = useReducer(
|
|
436
480
|
appReducer,
|
|
@@ -448,9 +492,10 @@ export function AppProvider({
|
|
|
448
492
|
initialThemePreview: initialDesktopThemePreview,
|
|
449
493
|
} = initialState;
|
|
450
494
|
const baseState = createInitialState(initialConfig, initialSessionSnapshot);
|
|
451
|
-
const
|
|
495
|
+
const hydratedState = initialDesktopSnapshot
|
|
452
496
|
? appReducer(baseState, { type: "HYDRATE_DESKTOP_SNAPSHOT", snapshot: initialDesktopSnapshot })
|
|
453
497
|
: baseState;
|
|
498
|
+
const nextState = paneStateChosen ? withAllPaneChoices(hydratedState) : hydratedState;
|
|
454
499
|
return initialDesktopThemePreview
|
|
455
500
|
? appReducer(nextState, { type: "PREVIEW_THEME", theme: initialDesktopThemePreview.theme })
|
|
456
501
|
: nextState;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { useOptionalPaneInstanceId } from "./app/context";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Panes holding something an Esc must not throw away: a draft not sent, an
|
|
6
|
+
* answer still coming in. Esc, one press or two, never closes such a pane; a
|
|
7
|
+
* deliberate close (Ctrl+W, the close button, the pane menu) still does.
|
|
8
|
+
*
|
|
9
|
+
* A pane whose draft outlives it (saved with the chat channel, a note saved
|
|
10
|
+
* when editing ends) has nothing to report. Neither has a form that takes its
|
|
11
|
+
* own Esc as Cancel: that Esc never reaches the close.
|
|
12
|
+
*/
|
|
13
|
+
const holders = new Map<string, Set<symbol>>();
|
|
14
|
+
|
|
15
|
+
export function paneHoldsUnsentWork(paneId: string | null | undefined): boolean {
|
|
16
|
+
return !!paneId && (holders.get(paneId)?.size ?? 0) > 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Marks a pane as holding unsent work until the returned release is called. */
|
|
20
|
+
export function holdPaneUnsentWork(paneId: string): () => void {
|
|
21
|
+
const token = Symbol(paneId);
|
|
22
|
+
let entry = holders.get(paneId);
|
|
23
|
+
if (!entry) {
|
|
24
|
+
entry = new Set();
|
|
25
|
+
holders.set(paneId, entry);
|
|
26
|
+
}
|
|
27
|
+
const held = entry;
|
|
28
|
+
held.add(token);
|
|
29
|
+
return () => {
|
|
30
|
+
held.delete(token);
|
|
31
|
+
if (held.size === 0 && holders.get(paneId) === held) holders.delete(paneId);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Reports that the pane holds work an Esc must not throw away while `holds`
|
|
37
|
+
* is true: a composer with text in it, an answer still streaming. The pane is
|
|
38
|
+
* the one in context, or `paneId` where the caller names it.
|
|
39
|
+
*/
|
|
40
|
+
export function usePaneUnsentWork(holds: boolean, paneId?: string): void {
|
|
41
|
+
const contextPaneId = useOptionalPaneInstanceId();
|
|
42
|
+
const target = paneId ?? contextPaneId;
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (!holds || !target) return undefined;
|
|
45
|
+
return holdPaneUnsentWork(target);
|
|
46
|
+
}, [holds, target]);
|
|
47
|
+
}
|