@gloom-sh/terminal 0.20.10 → 0.20.11

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 (103) hide show
  1. package/package.json +1 -1
  2. package/patches/@opentui%2Fcore@0.3.2.patch +16 -0
  3. package/src/api-client/socket-connection.ts +355 -0
  4. package/src/api-client/socket-features.ts +75 -0
  5. package/src/api-client/socket-frames.ts +161 -0
  6. package/src/api-client/socket-listeners.ts +207 -0
  7. package/src/api-client/socket-quotes.ts +332 -0
  8. package/src/api-client/socket.ts +150 -983
  9. package/src/brokers/signed-in/adapter.ts +19 -5
  10. package/src/brokers/signed-in/client.ts +13 -1
  11. package/src/brokers/signed-in/sign-in-dialog.tsx +33 -9
  12. package/src/components/chart/native/kitty/manager.ts +2 -0
  13. package/src/components/chart/native/surface/manager.ts +211 -11
  14. package/src/components/command-bar/panel/index.tsx +2 -13
  15. package/src/components/command-bar/panel/layout.ts +1 -7
  16. package/src/components/command-bar/panel/runtime.ts +0 -1
  17. package/src/components/command-bar/panel/types.ts +0 -2
  18. package/src/components/data-table/column-menu.tsx +89 -0
  19. package/src/components/data-table/sort-menu.tsx +9 -2
  20. package/src/components/data-table/view.tsx +33 -6
  21. package/src/components/form-modal/content.tsx +10 -0
  22. package/src/components/index.ts +1 -1
  23. package/src/components/layout/pane/footer/index.tsx +25 -11
  24. package/src/components/layout/pane/footer/model.ts +62 -20
  25. package/src/components/layout/pane/sidebar.tsx +125 -15
  26. package/src/components/layout/shell/active-drag.ts +18 -13
  27. package/src/components/layout/shell/drag/magnets.ts +34 -18
  28. package/src/components/ticker/list-table-view.tsx +5 -0
  29. package/src/components/ui/data-table/column-order.ts +180 -0
  30. package/src/components/ui/data-table/index.tsx +12 -1
  31. package/src/components/ui/data-table/opentui/index.tsx +267 -23
  32. package/src/components/ui/data-table/opentui/model.ts +43 -4
  33. package/src/components/ui/data-table/types.ts +49 -0
  34. package/src/components/ui/data-table/use-column-order.ts +135 -0
  35. package/src/components/ui/index.ts +1 -1
  36. package/src/components/ui/table-layout.ts +120 -0
  37. package/src/docs/snapshot.json +3 -2
  38. package/src/i18n/es.ts +2 -0
  39. package/src/i18n/ja.ts +2 -0
  40. package/src/i18n/ko.ts +2 -0
  41. package/src/i18n/zh-cn.ts +2 -0
  42. package/src/i18n/zh-tw.ts +2 -0
  43. package/src/market-data/coordinator/index.ts +4 -3
  44. package/src/market-data/coordinator/quotes.ts +12 -4
  45. package/src/market-data/quotes/freshness.ts +12 -0
  46. package/src/market-data/quotes/live-valuation.ts +1 -1
  47. package/src/market-data/quotes/regular-session-valuation.ts +1 -1
  48. package/src/plugins/builtin/broker-manager/detail.tsx +5 -3
  49. package/src/plugins/builtin/broker-manager/index.tsx +6 -6
  50. package/src/plugins/builtin/broker-manager/model.ts +15 -6
  51. package/src/plugins/builtin/broker-manager/pane-actions.tsx +11 -4
  52. package/src/plugins/builtin/broker-manager/sign-in-end.ts +50 -19
  53. package/src/plugins/builtin/broker-manager/table.ts +10 -4
  54. package/src/plugins/builtin/chat/sidebar.tsx +33 -16
  55. package/src/plugins/builtin/cloud/askg/tool-timeline.tsx +2 -0
  56. package/src/plugins/builtin/equity-screener/live.ts +74 -18
  57. package/src/plugins/builtin/equity-screener/model.ts +19 -4
  58. package/src/plugins/builtin/equity-screener/pane.tsx +19 -14
  59. package/src/plugins/builtin/equity-screener/refresh-anchor.ts +45 -0
  60. package/src/plugins/builtin/equity-screener/results.ts +22 -2
  61. package/src/plugins/builtin/equity-screener/screen-check.ts +9 -3
  62. package/src/plugins/builtin/futures/index.tsx +15 -1
  63. package/src/plugins/builtin/futures/table.tsx +1 -1
  64. package/src/plugins/builtin/fx-matrix/index.tsx +2 -0
  65. package/src/plugins/builtin/holders/pane.tsx +30 -20
  66. package/src/plugins/builtin/iv-history/events.ts +5 -0
  67. package/src/plugins/builtin/iv-history/headless.ts +7 -2
  68. package/src/plugins/builtin/kelly-sizer/sections.tsx +2 -0
  69. package/src/plugins/builtin/macro-day/headless.ts +12 -3
  70. package/src/plugins/builtin/options/view.tsx +2 -0
  71. package/src/plugins/builtin/options-scenario/pane.tsx +2 -1
  72. package/src/plugins/builtin/perps/cascade-tabs.tsx +2 -1
  73. package/src/plugins/builtin/portfolio-list/pane/index.tsx +13 -0
  74. package/src/plugins/builtin/portfolio-list/table.tsx +5 -0
  75. package/src/plugins/builtin/rate-path/pane.tsx +2 -0
  76. package/src/plugins/builtin/revenue-breakdown/pane.tsx +2 -0
  77. package/src/plugins/builtin/reverse-dcf/pane.tsx +2 -1
  78. package/src/plugins/builtin/seasonality/pane.tsx +2 -1
  79. package/src/plugins/builtin/thirteenf/pane.tsx +2 -0
  80. package/src/plugins/builtin/ticker-detail/financials/model.ts +28 -6
  81. package/src/plugins/builtin/ticker-detail/financials/ratio-table.tsx +26 -9
  82. package/src/plugins/builtin/ticker-detail/financials/tab.tsx +58 -35
  83. package/src/plugins/builtin/vol-surface/heat-grid.tsx +2 -1
  84. package/src/plugins/builtin/vol-surface/pane.tsx +2 -1
  85. package/src/plugins/builtin/world-indices/index.tsx +5 -1
  86. package/src/plugins/builtin/yield-curve/index.tsx +2 -1
  87. package/src/renderers/dom/data-table/column-drag.ts +147 -0
  88. package/src/renderers/dom/data-table/index.tsx +22 -0
  89. package/src/renderers/dom/data-table/row.tsx +27 -5
  90. package/src/renderers/dom/styles.css +22 -0
  91. package/src/renderers/opentui/chart-surface.tsx +1 -0
  92. package/src/renderers/opentui/frame-hits.ts +33 -0
  93. package/src/renderers/opentui/host.tsx +2 -0
  94. package/src/renderers/opentui/native-surface.ts +14 -21
  95. package/src/renderers/opentui/test-utils.tsx +3 -0
  96. package/src/state/app/context/index.tsx +22 -0
  97. package/src/test-support/app-store.ts +24 -1
  98. package/src/time-series/live-quotes.ts +3 -9
  99. package/src/ui/host.tsx +18 -0
  100. package/src/ui/pointer-drag.ts +11 -2
  101. package/src/utils/fundamentals.ts +14 -3
  102. package/src/utils/share-multiples.cases.json +780 -2
  103. package/src/utils/share-multiples.ts +154 -24
@@ -0,0 +1,135 @@
1
+ import { useCallback, useId, useMemo, useRef } from "react";
2
+ import { findPaneInstance } from "../../../types/config";
3
+ import {
4
+ useAppSelector,
5
+ useOptionalPaneInstanceId,
6
+ useOptionalPaneSettingUpdater,
7
+ } from "../../../state/app/context";
8
+ import { usePaneMenuItems } from "../../layout/pane/footer/registration";
9
+ import {
10
+ COLUMN_ORDER_SETTING,
11
+ defaultColumnOrder,
12
+ moveColumnId,
13
+ orderColumns,
14
+ readColumnOrders,
15
+ rememberColumnOrder,
16
+ rowAnchorColumnCount,
17
+ sameIds,
18
+ } from "./column-order";
19
+ import type { DataTableColumn, DataTableColumnReorder } from "./types";
20
+
21
+ /**
22
+ * A pane's column list to write, or undefined where it is the pane's own default
23
+ * list, so the pane's setting goes and columns later added to its defaults still
24
+ * reach it.
25
+ */
26
+ function listOrDefault(order: string[], defaultOrder: readonly string[] | undefined): string[] | undefined {
27
+ return defaultOrder && sameIds(order, defaultOrder) ? undefined : order;
28
+ }
29
+
30
+ /** Joins a remembered order into one string, so the selector's value only changes when the order does. */
31
+ const ID_SEPARATOR = "\u0000";
32
+
33
+ export interface DataTableColumnOrder<C extends DataTableColumn> {
34
+ /** The columns in the order the reader left them. */
35
+ columns: C[];
36
+ /** Moves a column to an index of `columns`; absent where the order is fixed. */
37
+ onColumnMove?: (columnId: string, toIndex: number) => void;
38
+ anchoredColumns: number;
39
+ /** The reader has changed the order: Reset Columns has something to put back. */
40
+ customized: boolean;
41
+ reset: () => void;
42
+ }
43
+
44
+ /**
45
+ * A table's columns in the order its pane remembers, the move a header drag
46
+ * makes, and Reset Columns. The order is kept in the pane's settings, so it is
47
+ * saved and synced with the layout, per pane; a pane whose settings already
48
+ * order its columns passes them as `control` and the drag rewrites those
49
+ * instead. With `menu`, Reset Columns goes in the pane menu while the order
50
+ * is the reader's own; `DataTableView` lists it with the table's sort instead.
51
+ */
52
+ export function useDataTableColumnOrder<C extends DataTableColumn>(
53
+ columns: readonly C[],
54
+ reorder: false | DataTableColumnReorder | undefined,
55
+ { menu = true }: { menu?: boolean } = {},
56
+ ): DataTableColumnOrder<C> {
57
+ const paneId = useOptionalPaneInstanceId();
58
+ const options = reorder === false ? null : reorder ?? {};
59
+ const control = options?.control;
60
+ const anchored = Math.min(columns.length, options?.anchored ?? rowAnchorColumnCount(columns));
61
+ // Kept under the column that names the row, so a mark before it that comes and goes with the width keeps the order.
62
+ const key = options?.key ?? columns[anchored - 1]?.id ?? columns[0]?.id ?? "";
63
+ const enabled = options !== null && (control !== undefined || paneId !== null) && columns.length - anchored >= 2;
64
+ const savedText = useAppSelector((state) => {
65
+ if (!enabled || control || !paneId) return null;
66
+ const ids = readColumnOrders(findPaneInstance(state.config.layout, paneId)?.settings?.[COLUMN_ORDER_SETTING])[key];
67
+ return ids ? ids.join(ID_SEPARATOR) : null;
68
+ });
69
+ const controlOrder = control?.order;
70
+ const saved = useMemo(
71
+ () => controlOrder ?? (savedText === null ? undefined : savedText.split(ID_SEPARATOR)),
72
+ [controlOrder, savedText],
73
+ );
74
+ const ordered = useMemo(
75
+ () => enabled ? orderColumns(columns, saved, anchored) : columns,
76
+ [anchored, columns, enabled, saved],
77
+ );
78
+ const updateSetting = useOptionalPaneSettingUpdater(paneId, COLUMN_ORDER_SETTING);
79
+ const latest = useRef({ columns, ordered, control, key, anchored });
80
+ latest.current = { columns, ordered, control, key, anchored };
81
+
82
+ const onColumnMove = useCallback((columnId: string, toIndex: number) => {
83
+ const current = latest.current;
84
+ const before = current.ordered.map((column) => column.id);
85
+ const after = moveColumnId(before, columnId, toIndex, current.anchored);
86
+ if (!after) return;
87
+ if (current.control) {
88
+ // Columns the pane adds on its own and does not list (a portfolio's target weights, its CCY column) stay
89
+ // out of the list and are drawn where the pane puts them. So a column dropped between two of them is
90
+ // written beside them in the list, and once they are drawn back in their own place it can land on their
91
+ // other side. Accepted: they follow the pane's rules, not the reader's order.
92
+ const { order, defaultOrder, onChange } = current.control;
93
+ const listed = new Set(order);
94
+ onChange(listOrDefault(rememberColumnOrder(order, before, after).filter((id) => listed.has(id)), defaultOrder));
95
+ return;
96
+ }
97
+ const defaults = current.columns.map((column) => column.id);
98
+ updateSetting((value) => {
99
+ const { [current.key]: previous, ...others } = readColumnOrders(value);
100
+ const next = rememberColumnOrder(previous, before, after);
101
+ // Dragged back to the pane's own order, with no other column's place to keep, it is forgotten.
102
+ const forget = sameIds(after, defaults) && next.every((id) => defaults.includes(id));
103
+ const orders = forget ? others : { ...others, [current.key]: next };
104
+ return Object.keys(orders).length > 0 ? orders : undefined;
105
+ });
106
+ }, [updateSetting]);
107
+
108
+ const reset = useCallback(() => {
109
+ const { control: current, key: tableKey } = latest.current;
110
+ if (!current) {
111
+ // Only this table's order: another table or tab in the pane keeps its own.
112
+ updateSetting((value) => {
113
+ const { [tableKey]: _reset, ...others } = readColumnOrders(value);
114
+ return Object.keys(others).length > 0 ? others : undefined;
115
+ });
116
+ return;
117
+ }
118
+ if (current.defaultOrder) current.onChange(listOrDefault(defaultColumnOrder(current.order, current.defaultOrder), current.defaultOrder));
119
+ }, [updateSetting]);
120
+
121
+ const customized = enabled && (control
122
+ ? !!control.defaultOrder && !sameIds(control.order, defaultColumnOrder(control.order, control.defaultOrder))
123
+ : ordered !== columns);
124
+ usePaneMenuItems(`data-table-columns:${useId()}`, () => menu && customized
125
+ ? [{ id: "reset-columns", label: "Reset Columns", onSelect: reset }]
126
+ : null, [customized, menu, reset]);
127
+
128
+ return {
129
+ columns: ordered as C[],
130
+ onColumnMove: enabled ? onColumnMove : undefined,
131
+ anchoredColumns: anchored,
132
+ customized,
133
+ reset,
134
+ };
135
+ }
@@ -3,7 +3,7 @@ export { ListView } from "./list-view";
3
3
  export type { ListViewItem, ListViewProps, ListRowState } from "./list-view";
4
4
 
5
5
  export { DataTable } from "./data-table";
6
- export type { DataTableCell, DataTableColumn, DataTableProps, DataTableVisibleRange } from "./data-table";
6
+ export type { DataTableCell, DataTableColumn, DataTableColumnReorder, DataTableProps, DataTableVisibleRange } from "./data-table";
7
7
 
8
8
  export { Button, terminalButtonColumns } from "./button";
9
9
  export { Icon, IconButton, ICON_GLYPHS } from "./icon";
@@ -321,6 +321,126 @@ export function hasMeaningfulTableHorizontalOverflow(
321
321
  return viewportWidth > 0 && tableWidth - viewportWidth > columnGap;
322
322
  }
323
323
 
324
+ /**
325
+ * The columns a terminal table drew, by its body's scroll box, while
326
+ * `fitTableColumns` has moved them from the widths the pane set: a sideways
327
+ * step and the column a table opens on go by the edges the reader sees.
328
+ */
329
+ export const drawnTableColumns = new WeakMap<object, readonly TableWidthColumn[]>();
330
+
331
+ /** Cells handed out one at a time, left to right, to the columns still short of their target. */
332
+ function growColumns(widths: number[], targets: readonly number[], indexes: readonly number[], extra: number): number {
333
+ let left = extra;
334
+ while (left > 0) {
335
+ const short = indexes.filter((index) => widths[index]! < targets[index]!);
336
+ if (short.length === 0) break;
337
+ for (const index of short) {
338
+ if (left <= 0) break;
339
+ widths[index]! += 1;
340
+ left -= 1;
341
+ }
342
+ }
343
+ return left;
344
+ }
345
+
346
+ /**
347
+ * The terminal table's columns as wide as the room and what they hold allow,
348
+ * before any column is cut or pushed out of view past the right edge.
349
+ * `contentWidths` is the widest text each column holds now, its header aside,
350
+ * or null where it draws something that cannot be measured (it keeps its set
351
+ * width). A table whose set widths fit (to its trailing gap) and cut nothing
352
+ * is left as set. Otherwise every column first gives up the blank past its
353
+ * text, down to its header and sort mark; a column that cuts its text then
354
+ * takes back what it needs while room is left, and the others take back
355
+ * their blank, a cell at a time. A column that grows (`flexGrow`) takes what
356
+ * is left after that, as it always did.
357
+ *
358
+ * When even that leaves columns past the edge, as many leading columns as fit
359
+ * whole beside the shortest form of the hint that says more follow
360
+ * (`edgeHint.least`) keep the room, or beside the table's padding without a
361
+ * hint. Their cut text takes what it needs first; then the hint's whole form
362
+ * (`edgeHint.whole`), unless a last column, a few cells of it then in view,
363
+ * would show them as cut text instead of the hint; then their blank, up to
364
+ * their set widths. The others wait past the edge at their narrowest.
365
+ *
366
+ * A fit that shows no more than the set widths do (no cut text longer, no
367
+ * column more in view) leaves the table as set.
368
+ */
369
+ export function fitTableColumns<C extends TableWidthColumn>(
370
+ columns: readonly C[],
371
+ contentWidths: readonly (number | null)[],
372
+ viewportWidth: number,
373
+ columnGap = 1,
374
+ horizontalPadding = 1,
375
+ edgeHint: {
376
+ least: number;
377
+ whole: number;
378
+ /** How many leading columns these widths show whole beside the hint, as the table draws it. */
379
+ shownWhole?: (columns: readonly C[]) => number;
380
+ } = { least: 0, whole: 0 },
381
+ ): C[] {
382
+ const set = normalizeTableColumns(columns);
383
+ if (viewportWidth <= 0 || set.length === 0) return set;
384
+ const floors = set.map((column) => (column.label ? Math.min(column.width, displayWidth(column.label) + HEADER_RESERVED_WIDTH) : 1));
385
+ const wants = set.map((column, index) => {
386
+ const content = contentWidths[index];
387
+ return content == null ? column.width : Math.max(floors[index]!, Math.ceil(content));
388
+ });
389
+ const cut = set.flatMap((column, index) => (wants[index]! > column.width ? [index] : []));
390
+ const room = Math.floor(viewportWidth);
391
+ const overflows = hasMeaningfulTableHorizontalOverflow(getTableWidth(set, columnGap, horizontalPadding), room, columnGap);
392
+ if (cut.length === 0 && !overflows) return set;
393
+ const widths = set.map((column, index) => Math.min(column.width, wants[index]!));
394
+ const sized = () => set.map((column, index) => (widths[index] === column.width ? column : { ...column, width: widths[index]! }));
395
+ const setWidths = set.map((column) => column.width);
396
+ const cutGrew = (indexes: readonly number[]) => indexes.some((index) => widths[index]! > setWidths[index]!);
397
+ let extra = room - getTableWidth(sized(), columnGap, horizontalPadding);
398
+ if (extra >= 0) {
399
+ extra = growColumns(widths, wants, cut, extra);
400
+ if (!overflows && !cutGrew(cut)) return set;
401
+ growColumns(widths, setWidths, set.map((_, index) => index), extra);
402
+ return sized();
403
+ }
404
+ // Where the first `count` columns end, without the blank after the last.
405
+ const prefixEnd = (count: number, columns: readonly C[] = sized()) => (
406
+ getTableWidth(columns.slice(0, count), columnGap, horizontalPadding) - columnGap - horizontalPadding
407
+ );
408
+ const least = edgeHint.least > 0 ? edgeHint.least : horizontalPadding;
409
+ // What the first `count` columns keep after them: the hint, or the padding, while columns follow; after the
410
+ // last its padding, unless the set widths already ran into it: the table runs no further past the edge.
411
+ const lastTail = Math.max(0, Math.min(horizontalPadding, room - prefixEnd(set.length, set)));
412
+ const tail = (count: number) => (count < set.length ? least : lastTail);
413
+ let count = 0;
414
+ while (count < set.length && prefixEnd(count + 1) + tail(count + 1) <= room) count += 1;
415
+ if (count === 0) return sized();
416
+ // The columns the set widths show whole, the last one's blank past it cut or not: a fit never shows fewer.
417
+ const shownWhole = edgeHint.shownWhole ?? ((columns: readonly C[]) => {
418
+ let shown = 0;
419
+ while (shown < set.length && prefixEnd(shown + 1, columns) + (shown + 1 < set.length ? least : 0) <= room) shown += 1;
420
+ return shown;
421
+ });
422
+ const setCount = shownWhole(set);
423
+ if (count < setCount) return set;
424
+ const shown = set.slice(0, count).map((_, index) => index);
425
+ extra = room - tail(count) - prefixEnd(count);
426
+ const shownCut = cut.filter((index) => index < count);
427
+ extra = growColumns(widths, wants, shownCut, extra);
428
+ if (count === setCount && !cutGrew(shownCut)) return set;
429
+ if (count < set.length) {
430
+ // Kept for the hint's whole form, a last column after them would have that many cells in view, which text
431
+ // shows cut rather than leave to the hint when they reach its label (hasColumnsPastRightEdge). With more
432
+ // columns past it the hint shows anyway.
433
+ const next = set[count]!;
434
+ const nextInView = edgeHint.whole - columnGap - tableColumnLeadGap(sized(), count, columnGap);
435
+ const nextShowsText = count === set.length - 1 && (next.align ?? "left") !== "right" && nextInView >= displayWidth(next.label ?? "");
436
+ const wholeHint = Math.max(0, edgeHint.whole - least);
437
+ if (edgeHint.least > 0 && wholeHint > 0 && extra >= wholeHint && !nextShowsText) extra -= wholeHint;
438
+ }
439
+ growColumns(widths, setWidths, shown, extra);
440
+ const fitted = sized();
441
+ return cutGrew(shownCut) || shownWhole(fitted) > setCount ? fitted : set;
442
+ }
443
+
324
444
  export function expandTableColumns<C extends TableWidthColumn>(
325
445
  columns: readonly C[],
326
446
  targetWidth: number,
@@ -7382,8 +7382,9 @@
7382
7382
  "They read brokerage accounts, not team portfolios (use `collections.get`).",
7383
7383
  "An IBKR order instruction is not an order: IBKR returns a link where you review and submit it yourself.",
7384
7384
  "IBKR allows one AI connection per user, and Gloom holds it: connecting IBKR in Gloom disconnects it from other AI apps, so reach it through Gloom.",
7385
- "The IBKR sign-in ends seven days after you consent, however often it is used; only signing in again brings it back.",
7386
- "A day before, the Brokers pane shows when it ends, and Gloom emails you once."
7385
+ "The IBKR sign-in ends seven days after you consent, however often it is used; only signing in again brings it back. Signing in before it ends starts a new seven days.",
7386
+ "The Brokers pane shows when it ends. Two days before, Gloom emails you once with a link to renew. IBKR then asks to replace your existing Gloom connection: choose replace.",
7387
+ "Connecting another AI app to the same IBKR account disconnects Gloom. Connect IBKR in Gloom again to get it back."
7387
7388
  ]
7388
7389
  },
7389
7390
  {
package/src/i18n/es.ts CHANGED
@@ -1662,6 +1662,8 @@ export const es: Record<string, string> = {
1662
1662
  "Sign in to Gloom": "Inicia sesión en Gloom",
1663
1663
  "Continue in your browser or scan the code.": "Continúa en tu navegador o escanea el código.",
1664
1664
  "Other AI apps linked to {broker} get disconnected. Connect them to Gloom instead.": "Otras apps de IA vinculadas a {broker} se desconectarán. Conéctalas a Gloom en su lugar.",
1665
+ "{broker} will ask to replace your existing Gloom connection. Choose to replace it.": "{broker} te pedirá reemplazar tu conexión actual con Gloom. Elige reemplazarla.",
1666
+ "{broker} may ask to replace your existing Gloom connection. If it does, choose to replace it.": "{broker} puede pedirte reemplazar tu conexión actual con Gloom. Si lo hace, elige reemplazarla.",
1665
1667
  "Waiting for {broker}...": "Esperando a {broker}...",
1666
1668
  "Contacting Gloom...": "Contactando con Gloom...",
1667
1669
  "Something went wrong.": "Algo salió mal.",
package/src/i18n/ja.ts CHANGED
@@ -1659,6 +1659,8 @@ export const ja: Record<string, string> = {
1659
1659
  "Sign in to Gloom": "Gloom にサインイン",
1660
1660
  "Continue in your browser or scan the code.": "ブラウザーで続けるか、コードをスキャンしてください。",
1661
1661
  "Other AI apps linked to {broker} get disconnected. Connect them to Gloom instead.": "{broker} に連携している他の AI アプリは切断されます。代わりに Gloom に接続してください。",
1662
+ "{broker} will ask to replace your existing Gloom connection. Choose to replace it.": "{broker} から既存の Gloom 接続を置き換えるか確認されます。置き換えを選んでください。",
1663
+ "{broker} may ask to replace your existing Gloom connection. If it does, choose to replace it.": "{broker} から既存の Gloom 接続を置き換えるか確認される場合があります。その場合は置き換えを選んでください。",
1662
1664
  "Waiting for {broker}...": "{broker} を待っています...",
1663
1665
  "Contacting Gloom...": "Gloom に接続中...",
1664
1666
  "Something went wrong.": "問題が発生しました。",
package/src/i18n/ko.ts CHANGED
@@ -1657,6 +1657,8 @@ export const ko: Record<string, string> = {
1657
1657
  "Sign in to Gloom": "Gloom에 로그인",
1658
1658
  "Continue in your browser or scan the code.": "브라우저에서 계속하거나 코드를 스캔하세요.",
1659
1659
  "Other AI apps linked to {broker} get disconnected. Connect them to Gloom instead.": "{broker}에 연결된 다른 AI 앱은 연결이 해제됩니다. 대신 Gloom에 연결하세요.",
1660
+ "{broker} will ask to replace your existing Gloom connection. Choose to replace it.": "{broker}에서 기존 Gloom 연결을 교체할지 묻습니다. 교체를 선택하세요.",
1661
+ "{broker} may ask to replace your existing Gloom connection. If it does, choose to replace it.": "{broker}에서 기존 Gloom 연결을 교체할지 물을 수 있습니다. 그러면 교체를 선택하세요.",
1660
1662
  "Waiting for {broker}...": "{broker} 기다리는 중...",
1661
1663
  "Contacting Gloom...": "Gloom에 연결하는 중...",
1662
1664
  "Something went wrong.": "문제가 발생했습니다.",
package/src/i18n/zh-cn.ts CHANGED
@@ -1659,6 +1659,8 @@ export const zhCN: Record<string, string> = {
1659
1659
  "Sign in to Gloom": "登录 Gloom",
1660
1660
  "Continue in your browser or scan the code.": "在浏览器中继续,或扫描二维码。",
1661
1661
  "Other AI apps linked to {broker} get disconnected. Connect them to Gloom instead.": "已关联 {broker} 的其他 AI 应用会被断开。请改为将它们连接到 Gloom。",
1662
+ "{broker} will ask to replace your existing Gloom connection. Choose to replace it.": "{broker} 会询问是否替换你现有的 Gloom 连接。请选择替换。",
1663
+ "{broker} may ask to replace your existing Gloom connection. If it does, choose to replace it.": "{broker} 可能会询问是否替换你现有的 Gloom 连接。如果询问,请选择替换。",
1662
1664
  "Waiting for {broker}...": "正在等待 {broker}...",
1663
1665
  "Contacting Gloom...": "正在连接 Gloom...",
1664
1666
  "Something went wrong.": "出了点问题。",
package/src/i18n/zh-tw.ts CHANGED
@@ -1659,6 +1659,8 @@ export const zhTW: Record<string, string> = {
1659
1659
  "Sign in to Gloom": "登入 Gloom",
1660
1660
  "Continue in your browser or scan the code.": "在瀏覽器中繼續,或掃描 QR 碼。",
1661
1661
  "Other AI apps linked to {broker} get disconnected. Connect them to Gloom instead.": "已連結 {broker} 的其他 AI 應用程式會被中斷連線。請改為將它們連線到 Gloom。",
1662
+ "{broker} will ask to replace your existing Gloom connection. Choose to replace it.": "{broker} 會詢問是否取代你現有的 Gloom 連線。請選擇取代。",
1663
+ "{broker} may ask to replace your existing Gloom connection. If it does, choose to replace it.": "{broker} 可能會詢問是否取代你現有的 Gloom 連線。如果詢問,請選擇取代。",
1662
1664
  "Waiting for {broker}...": "正在等待 {broker}...",
1663
1665
  "Contacting Gloom...": "正在連線 Gloom...",
1664
1666
  "Something went wrong.": "發生錯誤。",
@@ -93,9 +93,10 @@ import { readsInBatches } from "../batched-reads";
93
93
  /** How long a streamed tick may reuse the quote fields read from the cache. */
94
94
  const STREAM_QUOTE_BASELINE_TTL_MS = 60_000;
95
95
  /**
96
- * A repeat of an unchanged quote only moves its arrival time. Writing that
97
- * would re-render every reader per heartbeat, so it is recorded at most this
98
- * often: often enough that quote ages and the stream watchdog see a live feed.
96
+ * A repeat of an unchanged quote, or one restamped within the same minute,
97
+ * only moves its arrival time and stamp. Writing that would re-render every
98
+ * reader per heartbeat, so it is recorded at most this often: often enough
99
+ * that quote ages and the stream watchdog see a live feed.
99
100
  */
100
101
  const STREAM_RECEIPT_REFRESH_MS = 5_000;
101
102
  /** Keeps a long session of browsing from holding a baseline per visited symbol. */
@@ -7,6 +7,7 @@ import { QueryStore } from "../query-store";
7
7
  import type { QueryEntry } from "../result-types";
8
8
  import { buildQuoteKey, instrumentFromQuoteTarget, toMarketDataContext } from "../selectors";
9
9
  import { measurePerf } from "../../utils/perf-marks";
10
+ import { quoteStampBucket } from "../quotes/freshness";
10
11
  import { withSavedCopyMarkOf } from "../../data/saved-copies";
11
12
  import {
12
13
  failureStatus,
@@ -491,8 +492,13 @@ export class QuoteSubscriptionManager {
491
492
  }
492
493
 
493
494
  /**
494
- * Whether a tick would change nothing but its arrival time. Unavailable
495
- * numbers are NaN on the wire and count as equal to each other; key order and
495
+ * Whether a tick would change nothing but its arrival time, or its stamp
496
+ * within the minute it already has. Most of a busy symbol's ticks restamp a
497
+ * quote whose price, size and book did not move, and a stamp that stays in the
498
+ * same minute changes no chart bar, as-of clock or session edge, so the pane
499
+ * has nothing to redraw (the caller still refreshes the receipt now and then).
500
+ * A stamp that reaches another minute is a change. Unavailable numbers are NaN
501
+ * on the wire and count as equal to each other; key order and
496
502
  * absent-versus-undefined keys do not matter.
497
503
  */
498
504
  export function areStreamQuotesEquivalent(current: Quote | null | undefined, next: Quote): boolean {
@@ -500,12 +506,14 @@ export function areStreamQuotesEquivalent(current: Quote | null | undefined, nex
500
506
  if (current === next) return true;
501
507
  const left = current as unknown as Record<string, unknown>;
502
508
  const right = next as unknown as Record<string, unknown>;
509
+ const sameStampMinute = Object.is(quoteStampBucket(current), quoteStampBucket(next))
510
+ && Number.isFinite(current.lastUpdated);
503
511
  for (const key in left) {
504
- if (key === "receivedAt" || key === "provenance") continue;
512
+ if (key === "receivedAt" || key === "provenance" || (key === "lastUpdated" && sameStampMinute)) continue;
505
513
  if (!Object.is(left[key], right[key])) return false;
506
514
  }
507
515
  for (const key in right) {
508
- if (key === "receivedAt" || key === "provenance") continue;
516
+ if (key === "receivedAt" || key === "provenance" || (key === "lastUpdated" && sameStampMinute)) continue;
509
517
  if (!(key in left) && right[key] !== undefined) return false;
510
518
  }
511
519
  return current.provenance === next.provenance
@@ -33,6 +33,18 @@ export function hasValidQuoteObservationTime(quote: Pick<Quote, "lastUpdated">,
33
33
  && Number.isFinite(new Date(timestamp).getTime()) && Number.isFinite(new Date(now).getTime());
34
34
  }
35
35
 
36
+ /**
37
+ * The size of the stamp window a chart bar, an as-of clock and a session edge
38
+ * all move on: a whole minute. A stamp that stays inside the held one's window
39
+ * changes none of them.
40
+ */
41
+ const QUOTE_STAMP_BUCKET_MS = 60_000;
42
+
43
+ /** The whole minute a quote's stamp falls in; NaN for an unusable stamp. */
44
+ export function quoteStampBucket(quote: Pick<Quote, "lastUpdated">): number {
45
+ return Number.isFinite(quote.lastUpdated) ? Math.floor(quote.lastUpdated / QUOTE_STAMP_BUCKET_MS) : Number.NaN;
46
+ }
47
+
36
48
  /** The source date of a validated daily fund observation, including an old NAV. */
37
49
  export function dailyNavDate(quote: Quote, now = Date.now()): string | null {
38
50
  if (quote.priceObservation !== "nav" || quote.instrumentType !== "MUTUALFUND"
@@ -72,7 +72,7 @@ export function liveTrailingPE(quote: Quote | null | undefined, fundamentals: Fu
72
72
  // Withdrawn as no multiple of the share (utils/share-multiples).
73
73
  if (fundamentals?.notMeaningful?.trailingPE) return NOT_MEANINGFUL;
74
74
  const stored = pricedFundamentals(quote, fundamentals)?.trailingPE;
75
- return priceEarningsOnEarnings(repriceMultiple(stored, priceEarningsEps(fundamentals), quote, fundamentals), fundamentals?.eps);
75
+ return priceEarningsOnEarnings(repriceMultiple(stored, priceEarningsEps(fundamentals, quote?.currency), quote, fundamentals), fundamentals?.eps);
76
76
  }
77
77
 
78
78
  /** Forward P/E over the regular session price; not meaningful when the forward EPS behind it is zero or a loss. */
@@ -188,7 +188,7 @@ export function atRegularSessionPrice<T extends Pick<TickerFinancials, "quote" |
188
188
  if (!fundamentals || fundamentals.stale === true) {
189
189
  return { ...financials, quote: { ...quote, marketCap: scaledAmount(quote.marketCap, capMove(quote.marketCap)) } };
190
190
  }
191
- const trailing = per(fundamentals.trailingPE, priceEarningsEps(fundamentals));
191
+ const trailing = per(fundamentals.trailingPE, priceEarningsEps(fundamentals, quote.currency));
192
192
  const forward = per(fundamentals.forwardPE, fundamentals.forwardEps);
193
193
  const dividend = fundamentals.dividendRate != null && positive(fundamentals.dividendYield)
194
194
  ? fundamentals.dividendRate / fundamentals.dividendYield : undefined;
@@ -317,7 +317,7 @@ export function BrokerDetailContent({
317
317
  // The row's STATUS, and in full what the last action on the profile came to,
318
318
  // which outranks the profile's own status message until it is news no more.
319
319
  // The sign-in's end has a line of its own below.
320
- const status = brokerRowStatus({ ...row, signInEndsAt: null }, activity);
320
+ const status = brokerRowStatus({ ...row, signInEnd: null }, activity);
321
321
  const note = activity.note ?? null;
322
322
  const detailStatusMessage = note?.text ?? (row.message || t("No status message."));
323
323
  const statusMessageColor = note
@@ -340,8 +340,10 @@ export function BrokerDetailContent({
340
340
  <Text fg={statusMessageColor} width={width} wrapText>
341
341
  {detailStatusMessage}
342
342
  </Text>
343
- {row.signInEndsAt !== null && (
344
- <Text fg={colors.warning} width={width} wrapText>{signInEndNote(row.signInEndsAt)}</Text>
343
+ {row.signInEnd !== null && (
344
+ <Text fg={row.signInEnd.soon ? colors.warning : colors.textDim} width={width} wrapText>
345
+ {signInEndNote(row.signInEnd.endsAt)}
346
+ </Text>
345
347
  )}
346
348
  <Text fg={colors.textMuted}>{tf("Last sync {time}", { time: formatRelativeAge(row.lastSyncedAt) })}</Text>
347
349
  {row.instance.localOnly ? <Text fg={colors.textMuted}>{t("Account data stays on this device, out of Gloom Cloud")}</Text> : null}
@@ -37,7 +37,7 @@ import {
37
37
  type BrokerProfileRow,
38
38
  } from "./model";
39
39
  import { useBrokerManagerActions } from "./pane-actions";
40
- import { useSignInEnds } from "./sign-in-end";
40
+ import { useSignInReads } from "./sign-in-end";
41
41
  import {
42
42
  buildBrokerColumns,
43
43
  renderBrokerCell,
@@ -82,10 +82,10 @@ export function BrokersPane({ focused, width, height }: PaneProps) {
82
82
 
83
83
  // Signed-in profiles take their broker's name from the connector list.
84
84
  const signedInBrokers = useSyncExternalStore(subscribeSignedInBrokers, getSignedInBrokers, getSignedInBrokers);
85
- const { ends: signInEnds, reload: reloadSignInEnds } = useSignInEnds(config.brokerInstances);
85
+ const { reads: signInReads, reload: reloadSignInReads } = useSignInReads(config.brokerInstances);
86
86
  const rows = useMemo(
87
- () => buildBrokerProfileRows(config, adapters, brokerAccounts, signInEnds, getBrokerLogo, brokerSyncErrors),
88
- [adapters, brokerAccounts, brokerSyncErrors, config, getBrokerLogo, language, signInEnds, signedInBrokers, statusVersion],
87
+ () => buildBrokerProfileRows(config, adapters, brokerAccounts, signInReads, getBrokerLogo, brokerSyncErrors),
88
+ [adapters, brokerAccounts, brokerSyncErrors, config, getBrokerLogo, language, signInReads, signedInBrokers, statusVersion],
89
89
  );
90
90
  const selectedIndex = Math.max(0, rows.findIndex((row) => row.id === selectedId));
91
91
  const selectedRow = rows[selectedIndex] ?? null;
@@ -115,8 +115,8 @@ export function BrokersPane({ focused, width, height }: PaneProps) {
115
115
  // After a connect or sync, which can renew a sign-in or find it ended.
116
116
  const refreshStatuses = useCallback(() => {
117
117
  setStatusVersion((version) => version + 1);
118
- reloadSignInEnds();
119
- }, [reloadSignInEnds]);
118
+ reloadSignInReads();
119
+ }, [reloadSignInReads]);
120
120
 
121
121
  const {
122
122
  busy,
@@ -4,7 +4,8 @@ import type { AppConfig, BrokerInstanceConfig } from "../../../types/config";
4
4
  import type { BrokerAccount } from "../../../types/trading";
5
5
  import { formatCurrency } from "../../../utils/format";
6
6
  import { t } from "../../../i18n";
7
- import type { SignInEnds } from "./sign-in-end";
7
+ import type { BrokerReplacePrompt } from "../../../brokers/signed-in/client";
8
+ import type { SignInEnd, SignInReads } from "./sign-in-end";
8
9
 
9
10
  export type BrokerDisplayState =
10
11
  | "disabled"
@@ -28,8 +29,14 @@ export interface BrokerProfileRow {
28
29
  accountCount: number;
29
30
  accountSummary: string;
30
31
  accountIds: string[];
31
- /** When the broker ends this profile's sign-in, once Gloom says it is time to connect again. */
32
- signInEndsAt: number | null;
32
+ /** When the broker ends this profile's live sign-in, for a broker that ends it on a clock. */
33
+ signInEnd: SignInEnd | null;
34
+ /**
35
+ * Whether the broker will or may ask to replace the Gloom connection it
36
+ * lists when this profile signs in again, as Gloom says; undefined when
37
+ * Gloom has not said (a server that predates it, or no read yet).
38
+ */
39
+ replacePrompt?: BrokerReplacePrompt | null;
33
40
  /** The broker's logo for the desktop and the web (brokers/logos.ts); null draws its initial. */
34
41
  logo: string | null;
35
42
  instance: BrokerInstanceConfig;
@@ -123,7 +130,7 @@ export function buildBrokerProfileRows(
123
130
  config: AppConfig,
124
131
  adapters: ReadonlyMap<string, BrokerAdapter | null>,
125
132
  brokerAccounts: Record<string, BrokerAccount[]>,
126
- signInEnds: SignInEnds = new Map(),
133
+ signInReads: SignInReads = new Map(),
127
134
  pluginLogo: BrokerPluginLogo = () => null,
128
135
  syncErrors: Readonly<Record<string, string>> = {},
129
136
  ): BrokerProfileRow[] {
@@ -163,9 +170,11 @@ export function buildBrokerProfileRows(
163
170
  accountSummary: summarizeBrokerAccounts(accounts),
164
171
  accountIds: accounts.map((account) => account.accountId),
165
172
  // Say nothing next to a failure or a profile that does not connect.
166
- signInEndsAt: state.state === "error" || state.state === "sign-in" || state.state === "disabled" || state.state === "unavailable"
173
+ signInEnd: state.state === "error" || state.state === "sign-in" || state.state === "disabled" || state.state === "unavailable"
167
174
  ? null
168
- : signInEnds.get(instance.id) ?? null,
175
+ : signInReads.get(instance.id)?.end ?? null,
176
+ // Said for an ended sign-in too: it is the next sign-in the broker asks about.
177
+ replacePrompt: signInReads.get(instance.id)?.replacePrompt,
169
178
  logo: brokerProfileLogo(instance, adapter, pluginLogo),
170
179
  instance,
171
180
  adapter,
@@ -182,12 +182,19 @@ export function useBrokerManagerActions({
182
182
  const { id, label } = selectedRow;
183
183
  startRowAction(id, t("Connecting…"));
184
184
  try {
185
- // A connected broker is connected again only by a new sign-in: this renews it before the broker ends it.
186
- // A row that says when the sign-in ends is renewable before this session's first sync too.
187
- const renew = selectedRow.state === "connected" || selectedRow.signInEndsAt !== null;
185
+ // A connected broker is connected again only by a new sign-in: this renews it before the broker ends it,
186
+ // at any time, for a new full lifetime. A row that says when the sign-in ends is renewable before this
187
+ // session's first sync too.
188
+ const renew = selectedRow.state === "connected" || selectedRow.signInEnd !== null;
189
+ // What the broker will ask about the Gloom connection it lists, as Gloom says: also after the broker ended
190
+ // the sign-in on its clock, and not after another app took the account. A Gloom server that predates it
191
+ // says nothing; then a renewal of a single-connection broker is the one case known to ask.
192
+ const replace = selectedRow.replacePrompt !== undefined
193
+ ? selectedRow.replacePrompt
194
+ : renew && broker.capabilities.singleConnection ? "will" : null;
188
195
  let signedIn: boolean;
189
196
  try {
190
- signedIn = await requestBrokerSignIn(broker, { renew });
197
+ signedIn = await requestBrokerSignIn(broker, { renew, replace });
191
198
  } catch (error) {
192
199
  setRowNote(id, {
193
200
  tone: "error",