@orangecharts/wrun-chart-host 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -0
- package/dist/constants/governed-exchanges.constants.d.ts +11 -0
- package/dist/constants/governed-exchanges.constants.js +11 -0
- package/dist/constants/indicator-sets.constants.d.ts +8 -0
- package/dist/constants/indicator-sets.constants.js +8 -0
- package/dist/constants/interval.constants.d.ts +34 -0
- package/dist/constants/interval.constants.js +121 -0
- package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.d.ts +28 -0
- package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.js +65 -0
- package/dist/constants/tpo-color-schemes.constants.d.ts +30 -0
- package/dist/constants/tpo-color-schemes.constants.js +32 -0
- package/dist/host-env.d.ts +102 -0
- package/dist/host-env.js +26 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.js +96 -0
- package/dist/indicators/controls/tpo-letter.util.d.ts +2 -0
- package/dist/indicators/controls/tpo-letter.util.js +13 -0
- package/dist/indicators/controls/tpo-session.util.d.ts +99 -0
- package/dist/indicators/controls/tpo-session.util.js +389 -0
- package/dist/interfaces/kscript-diagnostics.interface.d.ts +64 -0
- package/dist/interfaces/kscript-diagnostics.interface.js +1 -0
- package/dist/interfaces/om-panel-data.interface.d.ts +103 -0
- package/dist/interfaces/om-panel-data.interface.js +7 -0
- package/dist/interfaces/wrun-runtime.interface.d.ts +2659 -0
- package/dist/interfaces/wrun-runtime.interface.js +55 -0
- package/dist/utility/chart/calendar-interval.util.d.ts +24 -0
- package/dist/utility/chart/calendar-interval.util.js +81 -0
- package/dist/utility/chart/candle-bar-end.util.d.ts +15 -0
- package/dist/utility/chart/candle-bar-end.util.js +23 -0
- package/dist/utility/chart/cme-realtime.util.d.ts +24 -0
- package/dist/utility/chart/cme-realtime.util.js +53 -0
- package/dist/utility/chart/interval-ladder.util.d.ts +27 -0
- package/dist/utility/chart/interval-ladder.util.js +92 -0
- package/dist/utility/chart/kscript-drawing-prep.util.d.ts +40 -0
- package/dist/utility/chart/kscript-drawing-prep.util.js +184 -0
- package/dist/utility/chart/kscript-drawing-safe-area.util.d.ts +95 -0
- package/dist/utility/chart/kscript-drawing-safe-area.util.js +805 -0
- package/dist/utility/chart/kscript-legend-entries.util.d.ts +166 -0
- package/dist/utility/chart/kscript-legend-entries.util.js +538 -0
- package/dist/utility/chart/kscript-output-role.util.d.ts +32 -0
- package/dist/utility/chart/kscript-output-role.util.js +215 -0
- package/dist/utility/chart/kscript-provenance-keys.util.d.ts +22 -0
- package/dist/utility/chart/kscript-provenance-keys.util.js +56 -0
- package/dist/utility/chart/kscript-run-result-normalize.util.d.ts +53 -0
- package/dist/utility/chart/kscript-run-result-normalize.util.js +476 -0
- package/dist/utility/chart/kscript-run-result-shape.util.d.ts +14 -0
- package/dist/utility/chart/kscript-run-result-shape.util.js +66 -0
- package/dist/utility/chart/kscript-titancharts-container.util.d.ts +29 -0
- package/dist/utility/chart/kscript-titancharts-container.util.js +151 -0
- package/dist/utility/chart/kscript-viewport-overlays.util.d.ts +83 -0
- package/dist/utility/chart/kscript-viewport-overlays.util.js +443 -0
- package/dist/utility/chart/om-panel-push-style.util.d.ts +78 -0
- package/dist/utility/chart/om-panel-push-style.util.js +301 -0
- package/dist/utility/chart/om-panel.util.d.ts +166 -0
- package/dist/utility/chart/om-panel.util.js +815 -0
- package/dist/utility/chart/om-series.util.d.ts +42 -0
- package/dist/utility/chart/om-series.util.js +330 -0
- package/dist/utility/chart/om-target.util.d.ts +11 -0
- package/dist/utility/chart/om-target.util.js +24 -0
- package/dist/utility/chart/om-widget.util.d.ts +148 -0
- package/dist/utility/chart/om-widget.util.js +413 -0
- package/dist/utility/chart/overlay-output-budget.util.d.ts +16 -0
- package/dist/utility/chart/overlay-output-budget.util.js +109 -0
- package/dist/utility/chart/overlay-paint-flags.util.d.ts +24 -0
- package/dist/utility/chart/overlay-paint-flags.util.js +55 -0
- package/dist/utility/chart/profile-row-height.util.d.ts +21 -0
- package/dist/utility/chart/profile-row-height.util.js +110 -0
- package/dist/utility/chart/session-interval.util.d.ts +1 -0
- package/dist/utility/chart/session-interval.util.js +35 -0
- package/dist/utility/chart/technical-script-legend-value.util.d.ts +18 -0
- package/dist/utility/chart/technical-script-legend-value.util.js +53 -0
- package/dist/utility/chart/trading-day.util.d.ts +70 -0
- package/dist/utility/chart/trading-day.util.js +238 -0
- package/dist/utility/chart/wrun-legend-name.util.d.ts +25 -0
- package/dist/utility/chart/wrun-legend-name.util.js +87 -0
- package/dist/utility/chart/wrun-run-result.util.d.ts +977 -0
- package/dist/utility/chart/wrun-run-result.util.js +5179 -0
- package/dist/utility/chart/wrun-visibility-chart.util.d.ts +25 -0
- package/dist/utility/chart/wrun-visibility-chart.util.js +22 -0
- package/dist/utility/indicators/heatmap-sensitivity.util.d.ts +62 -0
- package/dist/utility/indicators/heatmap-sensitivity.util.js +82 -0
- package/dist/utility/number-format.util.d.ts +68 -0
- package/dist/utility/number-format.util.js +188 -0
- package/dist/utility/v2/opra-governed.util.d.ts +1 -0
- package/dist/utility/v2/opra-governed.util.js +13 -0
- package/dist/utility/wrun/wrun-auto-row.util.d.ts +54 -0
- package/dist/utility/wrun/wrun-auto-row.util.js +96 -0
- package/dist/utility/wrun/wrun-batched-marks.util.d.ts +341 -0
- package/dist/utility/wrun/wrun-batched-marks.util.js +938 -0
- package/dist/utility/wrun/wrun-batched-readout.util.d.ts +75 -0
- package/dist/utility/wrun/wrun-batched-readout.util.js +171 -0
- package/dist/utility/wrun/wrun-box-segment.util.d.ts +185 -0
- package/dist/utility/wrun/wrun-box-segment.util.js +570 -0
- package/dist/utility/wrun/wrun-build-memo.util.d.ts +133 -0
- package/dist/utility/wrun/wrun-build-memo.util.js +301 -0
- package/dist/utility/wrun/wrun-builtin-twin-ports.util.d.ts +25 -0
- package/dist/utility/wrun/wrun-builtin-twin-ports.util.js +75 -0
- package/dist/utility/wrun/wrun-builtin-twin.util.d.ts +9 -0
- package/dist/utility/wrun/wrun-builtin-twin.util.js +40 -0
- package/dist/utility/wrun/wrun-canvas-cache.util.d.ts +28 -0
- package/dist/utility/wrun/wrun-canvas-cache.util.js +56 -0
- package/dist/utility/wrun/wrun-canvas-readout.util.d.ts +69 -0
- package/dist/utility/wrun/wrun-canvas-readout.util.js +53 -0
- package/dist/utility/wrun/wrun-canvases.util.d.ts +295 -0
- package/dist/utility/wrun/wrun-canvases.util.js +1432 -0
- package/dist/utility/wrun/wrun-cap-notice.util.d.ts +77 -0
- package/dist/utility/wrun/wrun-cap-notice.util.js +296 -0
- package/dist/utility/wrun/wrun-card-style.util.d.ts +154 -0
- package/dist/utility/wrun/wrun-card-style.util.js +539 -0
- package/dist/utility/wrun/wrun-chart-context.util.d.ts +89 -0
- package/dist/utility/wrun/wrun-chart-context.util.js +213 -0
- package/dist/utility/wrun/wrun-chart-names.util.d.ts +23 -0
- package/dist/utility/wrun/wrun-chart-names.util.js +33 -0
- package/dist/utility/wrun/wrun-chart-time.util.d.ts +12 -0
- package/dist/utility/wrun/wrun-chart-time.util.js +23 -0
- package/dist/utility/wrun/wrun-child-overlay-id.util.d.ts +13 -0
- package/dist/utility/wrun/wrun-child-overlay-id.util.js +44 -0
- package/dist/utility/wrun/wrun-color-facts.util.d.ts +40 -0
- package/dist/utility/wrun/wrun-color-facts.util.js +88 -0
- package/dist/utility/wrun/wrun-color-settings.lazy.d.ts +26 -0
- package/dist/utility/wrun/wrun-color-settings.lazy.js +9 -0
- package/dist/utility/wrun/wrun-color-settings.util.d.ts +351 -0
- package/dist/utility/wrun/wrun-color-settings.util.js +1363 -0
- package/dist/utility/wrun/wrun-footprint-modes.util.d.ts +23 -0
- package/dist/utility/wrun/wrun-footprint-modes.util.js +24 -0
- package/dist/utility/wrun/wrun-frames.d.ts +217 -0
- package/dist/utility/wrun/wrun-frames.js +1021 -0
- package/dist/utility/wrun/wrun-handles.util.d.ts +792 -0
- package/dist/utility/wrun/wrun-handles.util.js +2050 -0
- package/dist/utility/wrun/wrun-heatmap-cell-budget.util.d.ts +156 -0
- package/dist/utility/wrun/wrun-heatmap-cell-budget.util.js +342 -0
- package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +218 -0
- package/dist/utility/wrun/wrun-hosted-wire-caps.js +667 -0
- package/dist/utility/wrun/wrun-hosted-wire.util.d.ts +40 -0
- package/dist/utility/wrun/wrun-hosted-wire.util.js +27 -0
- package/dist/utility/wrun/wrun-hover.util.d.ts +182 -0
- package/dist/utility/wrun/wrun-hover.util.js +534 -0
- package/dist/utility/wrun/wrun-hud-looks.util.d.ts +246 -0
- package/dist/utility/wrun/wrun-hud-looks.util.js +587 -0
- package/dist/utility/wrun/wrun-integration-budget.util.d.ts +47 -0
- package/dist/utility/wrun/wrun-integration-budget.util.js +122 -0
- package/dist/utility/wrun/wrun-latest-snapshot.d.ts +19 -0
- package/dist/utility/wrun/wrun-latest-snapshot.js +7 -0
- package/dist/utility/wrun/wrun-levels-child.util.d.ts +131 -0
- package/dist/utility/wrun/wrun-levels-child.util.js +514 -0
- package/dist/utility/wrun/wrun-lifecycle.contract.d.ts +75 -0
- package/dist/utility/wrun/wrun-lifecycle.contract.js +9 -0
- package/dist/utility/wrun/wrun-market-facts.util.d.ts +116 -0
- package/dist/utility/wrun/wrun-market-facts.util.js +238 -0
- package/dist/utility/wrun/wrun-output-style.util.d.ts +344 -0
- package/dist/utility/wrun/wrun-output-style.util.js +1239 -0
- package/dist/utility/wrun/wrun-overlay-identity.util.d.ts +84 -0
- package/dist/utility/wrun/wrun-overlay-identity.util.js +142 -0
- package/dist/utility/wrun/wrun-overlay-result.util.d.ts +120 -0
- package/dist/utility/wrun/wrun-overlay-result.util.js +219 -0
- package/dist/utility/wrun/wrun-pack.util.d.ts +70 -0
- package/dist/utility/wrun/wrun-pack.util.js +301 -0
- package/dist/utility/wrun/wrun-pane-format.util.d.ts +180 -0
- package/dist/utility/wrun/wrun-pane-format.util.js +299 -0
- package/dist/utility/wrun/wrun-panel-style.lazy.d.ts +25 -0
- package/dist/utility/wrun/wrun-panel-style.lazy.js +15 -0
- package/dist/utility/wrun/wrun-panel-style.util.d.ts +174 -0
- package/dist/utility/wrun/wrun-panel-style.util.js +726 -0
- package/dist/utility/wrun/wrun-param-values.util.d.ts +69 -0
- package/dist/utility/wrun/wrun-param-values.util.js +230 -0
- package/dist/utility/wrun/wrun-refusal.util.d.ts +263 -0
- package/dist/utility/wrun/wrun-refusal.util.js +1259 -0
- package/dist/utility/wrun/wrun-registry-errors.util.d.ts +199 -0
- package/dist/utility/wrun/wrun-registry-errors.util.js +257 -0
- package/dist/utility/wrun/wrun-render-select.util.d.ts +336 -0
- package/dist/utility/wrun/wrun-render-select.util.js +1157 -0
- package/dist/utility/wrun/wrun-script-inputs.util.d.ts +434 -0
- package/dist/utility/wrun/wrun-script-inputs.util.js +1971 -0
- package/dist/utility/wrun/wrun-setting-words.lazy.d.ts +20 -0
- package/dist/utility/wrun/wrun-setting-words.lazy.js +9 -0
- package/dist/utility/wrun/wrun-setting-words.util.d.ts +79 -0
- package/dist/utility/wrun/wrun-setting-words.util.js +176 -0
- package/dist/utility/wrun/wrun-socket-row-store.d.ts +98 -0
- package/dist/utility/wrun/wrun-socket-row-store.js +417 -0
- package/dist/utility/wrun/wrun-style-flags.util.d.ts +18 -0
- package/dist/utility/wrun/wrun-style-flags.util.js +21 -0
- package/dist/utility/wrun/wrun-style-words.util.d.ts +148 -0
- package/dist/utility/wrun/wrun-style-words.util.js +439 -0
- package/dist/utility/wrun/wrun-table-look.util.d.ts +125 -0
- package/dist/utility/wrun/wrun-table-look.util.js +225 -0
- package/dist/utility/wrun/wrun-text-look.util.d.ts +51 -0
- package/dist/utility/wrun/wrun-text-look.util.js +227 -0
- package/dist/utility/wrun/wrun-text-params.util.d.ts +106 -0
- package/dist/utility/wrun/wrun-text-params.util.js +171 -0
- package/dist/utility/wrun/wrun-tpo-rows.util.d.ts +71 -0
- package/dist/utility/wrun/wrun-tpo-rows.util.js +438 -0
- package/dist/utility/wrun/wrun-twin-compute-inputs.util.d.ts +14 -0
- package/dist/utility/wrun/wrun-twin-compute-inputs.util.js +58 -0
- package/dist/utility/wrun/wrun-visibility-table.d.ts +437 -0
- package/dist/utility/wrun/wrun-visibility-table.js +237 -0
- package/dist/utility/wrun/wrun-volume-profile.util.d.ts +37 -0
- package/dist/utility/wrun/wrun-volume-profile.util.js +278 -0
- package/package.json +38 -0
|
@@ -0,0 +1,1259 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ONE refusal record of a browser-run Indicator: why it cannot draw on a market (or draws with
|
|
3
|
+
* a gap), named by the Indicator, with exactly one checked way out (OUT). Throw sites raise a seed
|
|
4
|
+
* (class, variant, params, market) on the error they already throw; `wrunRefusalFor` completes it
|
|
5
|
+
* into the record against the chart's facts; only the surfaces turn it into words, every one of
|
|
6
|
+
* them through `wrunRefusalTexts` (the legend chip and card, the folded summary, the toast, the
|
|
7
|
+
* editor console, the works-on list). Plan: WRUN-REFUSALS-PLAN.md, contracts C1, C2 and C4.
|
|
8
|
+
*
|
|
9
|
+
* Pure and worker-safe on purpose: types, constants and the typed lane errors only (no store, no
|
|
10
|
+
* i18n, no DOM), so the worker-reachable runtime diagnostics render the same words with their
|
|
11
|
+
* injected `translate`.
|
|
12
|
+
*
|
|
13
|
+
* - The record is canonical: `serializeWrunRefusal` writes a fixed key order with the params
|
|
14
|
+
* sorted by key, so equal records give equal strings (the legend's change-only comparator is
|
|
15
|
+
* strict per primitive, and the record rides `errorMessage.refusal` as that string).
|
|
16
|
+
* - Classification: an attached seed wins (the raiser knows the cause); an unseeded throw falls back
|
|
17
|
+
* to the stable codes the raisers already print (`wrun_cell_block_too_large`,
|
|
18
|
+
* `wrun_options_chain_*`, `wrun_pin_venue_refused`, `wrun_pin_venue_unknown`) and the facts printed beside them (the TPO
|
|
19
|
+
* letter check's pinned words included: letters the chart's own bars cannot place are
|
|
20
|
+
* `interval-unserved` `at-most`, the chart's interval must be the letter's or finer), then to
|
|
21
|
+
* the typed errors (no bars, deadline, source data unavailable), else `run-failed`: `code` when the
|
|
22
|
+
* words are the engine's trap or the host's write and memory rules, else `generic`. A run-failed
|
|
23
|
+
* record is deterministic (no Retry) unless its cause is one a second run can get past.
|
|
24
|
+
* - A cloud run's refusal reads by its code alone (WRUN-PARITY-PLAN row 21, lane parity U16): the
|
|
25
|
+
* code the error frame's `details.wrunRefusal` names (wrun-hosted-wire-caps `wrunFrameRefusalOf`),
|
|
26
|
+
* or a whole-run refusal of the socket row source, maps onto this table through
|
|
27
|
+
* `wrunCloudRefusalSeed`, never a pattern over the cloud's sentence. The cloud's no-candles answer
|
|
28
|
+
* is the browser lane's no-bars record, `waiting` (row 37: one class for both lanes).
|
|
29
|
+
* - `details` keeps the raiser's technical text for Copy details; a run-failed `generic` or `code`
|
|
30
|
+
* record also shows its first line under the sentence (`wrunRefusalDetailOf`), since its sentence
|
|
31
|
+
* cannot name the cause.
|
|
32
|
+
*/
|
|
33
|
+
import { Intervals } from '../../constants/interval.constants.js';
|
|
34
|
+
import { isCalendarIntervalLabel } from '../chart/calendar-interval.util.js';
|
|
35
|
+
import { WRUN_KIT_REFUSAL_STAGES, WRUN_NO_CANDLES_CODE, wrunFrameRefusalOf, wrunKitRefusalStageOf, wrunServerAnswerOfText, } from './wrun-hosted-wire-caps.js';
|
|
36
|
+
import { WrunDeadlineError, WrunNoBarsError, WrunQuarantinedError, WrunSourceDataUnavailableError, WrunWorkerPoisonError, } from './wrun-registry-errors.util.js';
|
|
37
|
+
/** Every class, in the C2 precedence order (paused before note decides first). */
|
|
38
|
+
export const WRUN_REFUSAL_CLASSES = Object.freeze([
|
|
39
|
+
'cme-wall',
|
|
40
|
+
'slots',
|
|
41
|
+
'not-added',
|
|
42
|
+
'pin-refused',
|
|
43
|
+
'no-options',
|
|
44
|
+
'coin-outside-feed',
|
|
45
|
+
'interval-unserved',
|
|
46
|
+
'feed-missing',
|
|
47
|
+
'too-big',
|
|
48
|
+
'live-stopped',
|
|
49
|
+
'legs-empty',
|
|
50
|
+
'service-no-answer',
|
|
51
|
+
'not-reached',
|
|
52
|
+
'run-failed',
|
|
53
|
+
'index-unserved',
|
|
54
|
+
'nothing-ready',
|
|
55
|
+
'waiting',
|
|
56
|
+
]);
|
|
57
|
+
const CLASS_RANK = new Map(WRUN_REFUSAL_CLASSES.map((cls, rank) => [cls, rank]));
|
|
58
|
+
/**
|
|
59
|
+
* The label of an odds leg's market when its input has no description ("the event market").
|
|
60
|
+
* wrun-overlay-run.util reads it into a refusal's market label and `markets` param when the leg
|
|
61
|
+
* refuses, which can happen during a boot restore, and that module loads lazily (outside the
|
|
62
|
+
* pre-candle closure). The full literal key lives here, in the closure, so the boot scanner keeps
|
|
63
|
+
* it in the boot locale bundle and the refusal never stores the untranslated key.
|
|
64
|
+
*/
|
|
65
|
+
export const WRUN_REFUSAL_EVENT_MARKET_KEY = 'wrun.refusal.market.event';
|
|
66
|
+
/**
|
|
67
|
+
* The words of every row-builder class and registered poll lane (C4 `feed`): a `feed` param holds
|
|
68
|
+
* a builtin class (`trade_volume_by_size`) or a lane key (`bitfinex_margin_rate`; a class served
|
|
69
|
+
* by several lanes is named by the lane its input reads). Full literal keys, so the boot scanner
|
|
70
|
+
* harvests them. The spec fails when a builtin class or a registered lane has no row here.
|
|
71
|
+
*/
|
|
72
|
+
export const WRUN_REFUSAL_FEED_KEYS = Object.freeze({
|
|
73
|
+
ohlcv: 'wrun.refusal.feed.ohlcv',
|
|
74
|
+
candles: 'wrun.refusal.feed.candles',
|
|
75
|
+
intrabar: 'wrun.refusal.feed.intrabar',
|
|
76
|
+
odds: 'wrun.refusal.feed.odds',
|
|
77
|
+
time: 'wrun.refusal.feed.time',
|
|
78
|
+
trade_volume_by_size: 'wrun.refusal.feed.tradeVolumeBySize',
|
|
79
|
+
tape: 'wrun.refusal.feed.tape',
|
|
80
|
+
book: 'wrun.refusal.feed.book',
|
|
81
|
+
trades: 'wrun.refusal.feed.trades',
|
|
82
|
+
oi: 'wrun.refusal.feed.oi',
|
|
83
|
+
volume_profile: 'wrun.refusal.feed.volumeProfile',
|
|
84
|
+
liquidations: 'wrun.refusal.feed.liquidations',
|
|
85
|
+
funding: 'wrun.refusal.feed.funding',
|
|
86
|
+
implied_volatility: 'wrun.refusal.feed.impliedVolatility',
|
|
87
|
+
skew: 'wrun.refusal.feed.skew',
|
|
88
|
+
options_chain: 'wrun.refusal.feed.optionsChain',
|
|
89
|
+
etf_flow: 'wrun.refusal.feed.etfFlow',
|
|
90
|
+
bitfinex_funding_size: 'wrun.refusal.feed.bitfinexFundingSize',
|
|
91
|
+
bitfinex_credit_size: 'wrun.refusal.feed.bitfinexCreditSize',
|
|
92
|
+
bitfinex_active_credit_size: 'wrun.refusal.feed.bitfinexActiveCreditSize',
|
|
93
|
+
bitfinex_margin_rate: 'wrun.refusal.feed.bitfinexMarginRate',
|
|
94
|
+
economic: 'wrun.refusal.feed.economic',
|
|
95
|
+
etf_holdings: 'wrun.refusal.feed.etfHoldings',
|
|
96
|
+
etf_premium: 'wrun.refusal.feed.etfPremium',
|
|
97
|
+
ethena_positions: 'wrun.refusal.feed.ethenaPositions',
|
|
98
|
+
long_short_ratio: 'wrun.refusal.feed.longShortRatio',
|
|
99
|
+
options_oi: 'wrun.refusal.feed.optionsOi',
|
|
100
|
+
options_volume: 'wrun.refusal.feed.optionsVolume',
|
|
101
|
+
token_supply: 'wrun.refusal.feed.tokenSupply',
|
|
102
|
+
treasury_balance: 'wrun.refusal.feed.treasuryBalance',
|
|
103
|
+
volatility_index: 'wrun.refusal.feed.volatilityIndex',
|
|
104
|
+
series: 'wrun.refusal.feed.series',
|
|
105
|
+
});
|
|
106
|
+
/** The full literal key of a feed's words, or undefined for a word that names no feed. */
|
|
107
|
+
export function wrunRefusalFeedKey(feed) {
|
|
108
|
+
return typeof feed === 'string' && Object.prototype.hasOwnProperty.call(WRUN_REFUSAL_FEED_KEYS, feed)
|
|
109
|
+
? WRUN_REFUSAL_FEED_KEYS[feed]
|
|
110
|
+
: undefined;
|
|
111
|
+
}
|
|
112
|
+
const row = (sentence, chip, params, extra) => ({ sentence, chip, params, ...extra });
|
|
113
|
+
/** The C2 table. Keys are full literals (the boot scanner harvests them). */
|
|
114
|
+
const VARIANTS = {
|
|
115
|
+
'legs-empty': {
|
|
116
|
+
drew: row('wrun.refusal.sentence.legsEmpty', 'wrun.refusal.chip.marketsEmpty', ['markets', 'count'], {
|
|
117
|
+
plural: 'count',
|
|
118
|
+
severity: 'note',
|
|
119
|
+
}),
|
|
120
|
+
refused: row('wrun.refusal.sentence.legsRefused', 'wrun.refusal.chip.marketsEmpty', ['markets', 'count', 'name'], {
|
|
121
|
+
plural: 'count',
|
|
122
|
+
severity: 'paused',
|
|
123
|
+
}),
|
|
124
|
+
},
|
|
125
|
+
'feed-missing': {
|
|
126
|
+
'crypto-only': row('wrun.refusal.sentence.feedFromCrypto', 'wrun.refusal.chip.feedMissing', ['feed', 'market']),
|
|
127
|
+
'market-paused': row('wrun.refusal.sentence.feedMissing', 'wrun.refusal.chip.feedMissing', ['feed', 'market'], {
|
|
128
|
+
severity: 'paused',
|
|
129
|
+
}),
|
|
130
|
+
'market-note': row('wrun.refusal.sentence.feedMissingNote', 'wrun.refusal.chip.feedMissing', ['feed', 'market'], {
|
|
131
|
+
severity: 'note',
|
|
132
|
+
}),
|
|
133
|
+
},
|
|
134
|
+
'no-options': {
|
|
135
|
+
venue: row('wrun.refusal.sentence.noOptionsVenue', 'wrun.refusal.chip.noOptions', ['venue', 'coin'], {
|
|
136
|
+
severity: 'paused',
|
|
137
|
+
}),
|
|
138
|
+
chain: row('wrun.refusal.sentence.noOptionsChain', 'wrun.refusal.chip.noOptions', ['market', 'coin'], {
|
|
139
|
+
severity: 'paused',
|
|
140
|
+
}),
|
|
141
|
+
'flag-off': row('wrun.refusal.sentence.noOptionsFlag', 'wrun.refusal.chip.noOptions', ['venue', 'coin'], {
|
|
142
|
+
severity: 'paused',
|
|
143
|
+
}),
|
|
144
|
+
'cme-venue': row('wrun.refusal.sentence.noOptionsCme', 'wrun.refusal.chip.noOptions', ['name', 'coin'], {
|
|
145
|
+
severity: 'paused',
|
|
146
|
+
}),
|
|
147
|
+
unresolved: row('wrun.refusal.sentence.noOptionsUnresolved', 'wrun.refusal.chip.noOptions', ['market', 'coin'], {
|
|
148
|
+
severity: 'paused',
|
|
149
|
+
}),
|
|
150
|
+
},
|
|
151
|
+
'coin-outside-feed': {
|
|
152
|
+
default: row('wrun.refusal.sentence.coinOutsideFeed', 'wrun.refusal.chip.coinOutsideFeed', ['feed', 'coins', 'coin'], {
|
|
153
|
+
severity: 'paused',
|
|
154
|
+
}),
|
|
155
|
+
},
|
|
156
|
+
'interval-unserved': {
|
|
157
|
+
fine: row('wrun.refusal.sentence.intervalUnserved', 'wrun.refusal.chip.intervalUnserved', ['feed', 'interval', 'chartInterval'], { severity: 'paused' }),
|
|
158
|
+
coarse: row('wrun.refusal.sentence.intervalTooCoarse', 'wrun.refusal.chip.intervalTooCoarse', ['feed', 'interval', 'chartInterval'], { severity: 'paused' }),
|
|
159
|
+
// The Indicator itself needs a chart this fine (TPO letters a coarser bar cannot place): it
|
|
160
|
+
// names no feed, the Indicator's name is the subject.
|
|
161
|
+
'at-most': row('wrun.refusal.sentence.intervalAtMost', 'wrun.refusal.chip.intervalAtMost', ['interval', 'chartInterval'], { severity: 'paused' }),
|
|
162
|
+
// A published feed read at its own cadence only (exact_interval): no coarser or finer chart
|
|
163
|
+
// serves it, so the sentence names the one interval that does (P3 C10).
|
|
164
|
+
exact: row('feeds.refusal.exactOnly', 'feeds.refusal.exactOnlyChip', ['feed', 'interval', 'chartInterval'], {
|
|
165
|
+
severity: 'paused',
|
|
166
|
+
}),
|
|
167
|
+
},
|
|
168
|
+
'service-no-answer': {
|
|
169
|
+
lane: row('wrun.refusal.sentence.noAnswer', 'wrun.refusal.chip.noAnswer', ['feed', 'market']),
|
|
170
|
+
global: row('wrun.refusal.sentence.noAnswerGlobal', 'wrun.refusal.chip.noAnswer', ['feed']),
|
|
171
|
+
'cme-directory': row('wrun.refusal.sentence.noAnswerCme', 'wrun.refusal.chip.noAnswer', ['market']),
|
|
172
|
+
// The US option chain directory a stock or ETF chart's OPRA chain resolves through did not answer.
|
|
173
|
+
'opra-directory': row('wrun.refusal.sentence.noAnswerOpra', 'wrun.refusal.chip.noAnswer', ['market']),
|
|
174
|
+
// The cloud's upstream market-data read failed (the error envelope's DATA_UNAVAILABLE, read off a socket frame by
|
|
175
|
+
// wrunSocketAskFailure): no feed to name, so the envelope's own words and chip, the ones a protected script shows.
|
|
176
|
+
'market-data': row('kscript.errors.DATA_UNAVAILABLE', 'kscript.legend.labels.DATA_UNAVAILABLE', []),
|
|
177
|
+
},
|
|
178
|
+
waiting: {
|
|
179
|
+
default: row('wrun.refusal.sentence.waiting', 'wrun.refusal.chip.waiting', [], { severity: 'note' }),
|
|
180
|
+
},
|
|
181
|
+
'cme-wall': {
|
|
182
|
+
default: row('wrun.refusal.sentence.cmeWall', 'wrun.refusal.chip.cmeWall', [], { severity: 'paused' }),
|
|
183
|
+
// The same wall on US options data (OPRA): a package that is not one of OpenMarket's own reads no OPRA chain
|
|
184
|
+
// (product decision 2026-10-14), whatever chart it runs on.
|
|
185
|
+
opra: row('wrun.refusal.sentence.opraWall', 'wrun.refusal.chip.opraWall', [], { severity: 'paused' }),
|
|
186
|
+
},
|
|
187
|
+
'pin-refused': {
|
|
188
|
+
default: row('wrun.refusal.sentence.pinRefused', 'wrun.refusal.chip.pinRefused', ['pin'], { severity: 'paused' }),
|
|
189
|
+
},
|
|
190
|
+
'index-unserved': {
|
|
191
|
+
default: row('wrun.refusal.sentence.indexUnserved', 'wrun.refusal.chip.indexUnserved', ['symbol'], {
|
|
192
|
+
severity: 'note',
|
|
193
|
+
}),
|
|
194
|
+
},
|
|
195
|
+
'too-big': {
|
|
196
|
+
chain: row('wrun.refusal.sentence.tooBigChain', 'wrun.refusal.chip.tooBig', ['cells', 'max']),
|
|
197
|
+
block: row('wrun.refusal.sentence.tooBigBlock', 'wrun.refusal.chip.tooBig', ['feed', 'cells', 'max']),
|
|
198
|
+
// The chart's row budget (applyWrunIntegrationBudget): the run's lines over the loaded candles
|
|
199
|
+
// outgrow what one Indicator may put on the chart; the numbers say what to change.
|
|
200
|
+
rows: row('wrun.refusal.sentence.tooBigRows', 'wrun.refusal.chip.tooBig', ['series', 'bars', 'max']),
|
|
201
|
+
},
|
|
202
|
+
// The live session's own stop (the merged tick result over the row budget): the last picture stays.
|
|
203
|
+
'live-stopped': {
|
|
204
|
+
default: row('wrun.refusal.sentence.liveStopped', 'wrun.refusal.chip.liveStopped', [], { severity: 'note' }),
|
|
205
|
+
},
|
|
206
|
+
'not-reached': {
|
|
207
|
+
run: row('wrun.refusal.sentence.notReached', 'wrun.refusal.chip.notReached', [], { severity: 'paused' }),
|
|
208
|
+
mount: row('wrun.refusal.sentence.notReached', 'wrun.refusal.chip.notReached', [], { severity: 'paused' }),
|
|
209
|
+
'first-run': row('wrun.refusal.sentence.notReached', 'wrun.refusal.chip.notReached', [], { severity: 'paused' }),
|
|
210
|
+
// A bystander of another indicator's sandbox death (its run timed out with a known owner, or
|
|
211
|
+
// the sandbox ended some other way).
|
|
212
|
+
held: row('wrun.refusal.sentence.notReachedHeld', 'wrun.refusal.chip.notReached', ['holder', 'seconds', 'name'], {
|
|
213
|
+
severity: 'paused',
|
|
214
|
+
}),
|
|
215
|
+
ended: row('wrun.refusal.sentence.notReachedEnded', 'wrun.refusal.chip.notReached', ['name'], {
|
|
216
|
+
severity: 'paused',
|
|
217
|
+
}),
|
|
218
|
+
},
|
|
219
|
+
'nothing-ready': {
|
|
220
|
+
default: row('wrun.refusal.sentence.nothingReady', 'wrun.refusal.chip.nothingReady', [], { severity: 'note' }),
|
|
221
|
+
},
|
|
222
|
+
// The slot refusal's card is Make room; its chip (console rows, a legend that ever carries one)
|
|
223
|
+
// says the add did not happen.
|
|
224
|
+
slots: {
|
|
225
|
+
'some-free': row('dialogs.makeRoom.plusEyebrowSomeFree', 'wrun.refusal.chip.notAdded', ['name', 'n', 'free'], {
|
|
226
|
+
plural: 'n',
|
|
227
|
+
severity: 'paused',
|
|
228
|
+
}),
|
|
229
|
+
'all-in-use': row('dialogs.makeRoom.plusEyebrowAllInUse', 'wrun.refusal.chip.notAdded', ['name', 'n', 'limit'], {
|
|
230
|
+
plural: 'n',
|
|
231
|
+
severity: 'paused',
|
|
232
|
+
}),
|
|
233
|
+
},
|
|
234
|
+
'not-added': {
|
|
235
|
+
gate: row('wrun.refusal.sentence.notAdded', 'wrun.refusal.chip.notAdded', ['name'], { severity: 'paused' }),
|
|
236
|
+
'window-replay': row('chart.window.replayFirst', 'wrun.refusal.chip.notAdded', [], { severity: 'paused' }),
|
|
237
|
+
'window-layout-full': row('chart.window.layoutFull', 'wrun.refusal.chip.notAdded', [], { severity: 'paused' }),
|
|
238
|
+
'window-open-failed': row('chart.window.openFailed', 'wrun.refusal.chip.notAdded', [], { severity: 'paused' }),
|
|
239
|
+
'window-slot-held': row('chart.window.slotHeld', 'wrun.refusal.chip.notAdded', [], { severity: 'paused' }),
|
|
240
|
+
'window-budget': row('dialogs.makeRoom.titleRun', 'wrun.refusal.chip.notAdded', ['name'], { severity: 'paused' }),
|
|
241
|
+
},
|
|
242
|
+
'run-failed': {
|
|
243
|
+
generic: row('wrun.refusal.sentence.runFailed', 'wrun.refusal.chip.runFailed', [], { severity: 'paused' }),
|
|
244
|
+
compile: row('wrun.refusal.sentence.compileBlocked', 'wrun.refusal.chip.runFailed', ['line'], {
|
|
245
|
+
severity: 'paused',
|
|
246
|
+
}),
|
|
247
|
+
// The engine's trap or the host's write and memory rules: the Indicator's own code stopped.
|
|
248
|
+
code: row('wrun.refusal.sentence.codeError', 'wrun.refusal.chip.runFailed', [], { severity: 'paused' }),
|
|
249
|
+
// A pin on a venue word the chart's lanes cannot ask (wrun_pin_venue_unknown), refused before any
|
|
250
|
+
// fetch: the sheet contract's sentence, the venue named.
|
|
251
|
+
'pin-venue-unknown': row('wrun.refusal.sentence.pinVenueUnknown', 'wrun.refusal.chip.runFailed', ['venue'], {
|
|
252
|
+
severity: 'paused',
|
|
253
|
+
}),
|
|
254
|
+
// A cloud run's refusals, read from the code the cloud answered (`wrunCloudRefusalSeed`). Their
|
|
255
|
+
// records carry no name or market a host can always give, so their sentences name neither.
|
|
256
|
+
// `refused`: a code no class reads, the generic words with the code.
|
|
257
|
+
refused: row('wrun.refusal.sentence.cantRunHere', 'kscript.legend.labels.VENUE_BLOCKED', ['code'], {
|
|
258
|
+
severity: 'paused',
|
|
259
|
+
}),
|
|
260
|
+
// A presentation family the cloud left out of a reply that drew.
|
|
261
|
+
'left-out': row('wrun.refusal.sentence.partLeftOut', 'kscript.legend.labels.FE_RANGE_SKIPPED', ['code', 'family'], {
|
|
262
|
+
severity: 'note',
|
|
263
|
+
}),
|
|
264
|
+
settings: row('wrun.refusal.sentence.settingsCantRun', 'kscript.legend.labels.VENUE_BLOCKED', ['code'], {
|
|
265
|
+
severity: 'paused',
|
|
266
|
+
}),
|
|
267
|
+
window: row('wrun.refusal.sentence.windowTooLarge', 'kscript.legend.labels.VENUE_BLOCKED', ['code', 'leg'], {
|
|
268
|
+
severity: 'paused',
|
|
269
|
+
}),
|
|
270
|
+
intrabar: row('wrun.refusal.sentence.intrabarTooFine', 'kscript.legend.labels.VENUE_BLOCKED', ['code'], {
|
|
271
|
+
severity: 'paused',
|
|
272
|
+
}),
|
|
273
|
+
'tab-full': row('wrun.refusal.sentence.tabFull', 'wrun.refusal.chip.tabFull', ['cap', 'code'], {
|
|
274
|
+
severity: 'paused',
|
|
275
|
+
}),
|
|
276
|
+
// A cloud reply without the hosted wire (a server on the legacy pre-styled path answering a cloud
|
|
277
|
+
// record): the chart reads no flat reply for a wrun record, so the run is refused and the way out
|
|
278
|
+
// reloads the app. The one retract kept until the backend floor deletes the legacy path.
|
|
279
|
+
'legacy-result': row('kscript.hostedWrun.unreadable', 'wrun.refusal.chip.runFailed', [], { severity: 'paused' }),
|
|
280
|
+
// The server superseded the overlay's LIVE session from elsewhere (another chart or tab created the same
|
|
281
|
+
// instance id): nothing of this run failed, and a Retry runs it here again (never on its own: the other
|
|
282
|
+
// chart's session would go the same way). A note, never the paused words (WRUN-REPORTS-CLASSES C1).
|
|
283
|
+
'session-lost': row('wrun.refusal.sentence.sessionLost', 'wrun.refusal.chip.sessionLost', [], {
|
|
284
|
+
severity: 'note',
|
|
285
|
+
}),
|
|
286
|
+
},
|
|
287
|
+
};
|
|
288
|
+
/** The variants of a class, in C2 order (the spec walks every one). */
|
|
289
|
+
export function wrunRefusalVariants(cls) {
|
|
290
|
+
return Object.keys(VARIANTS[cls] ?? {});
|
|
291
|
+
}
|
|
292
|
+
function variantSpec(cls, variant) {
|
|
293
|
+
const ofClass = VARIANTS[cls];
|
|
294
|
+
return ofClass && Object.prototype.hasOwnProperty.call(ofClass, variant) ? ofClass[variant] : undefined;
|
|
295
|
+
}
|
|
296
|
+
const RUN_FAILED_GENERIC = VARIANTS['run-failed'].generic;
|
|
297
|
+
/** The spec a record renders by: its own, or the generic run-failed words when its variant is
|
|
298
|
+
* unknown or names a feed that has no words (a technical word never reaches a sentence). */
|
|
299
|
+
function renderSpec(r) {
|
|
300
|
+
const spec = variantSpec(r.cls, r.variant);
|
|
301
|
+
if (!spec)
|
|
302
|
+
return RUN_FAILED_GENERIC;
|
|
303
|
+
if (spec.params.includes('feed') && wrunRefusalFeedKey(r.params.feed) === undefined)
|
|
304
|
+
return RUN_FAILED_GENERIC;
|
|
305
|
+
return spec;
|
|
306
|
+
}
|
|
307
|
+
// ---------------------------------------------------------------------------
|
|
308
|
+
// Validation and the canonical form
|
|
309
|
+
// ---------------------------------------------------------------------------
|
|
310
|
+
const CLASS_SET = new Set(WRUN_REFUSAL_CLASSES);
|
|
311
|
+
function isClass(value) {
|
|
312
|
+
return typeof value === 'string' && CLASS_SET.has(value);
|
|
313
|
+
}
|
|
314
|
+
function isRecordObject(value) {
|
|
315
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
316
|
+
}
|
|
317
|
+
function nonEmpty(value) {
|
|
318
|
+
return typeof value === 'string' && value.length > 0;
|
|
319
|
+
}
|
|
320
|
+
/** A well-formed OUT in canonical key order, or undefined. */
|
|
321
|
+
function canonicalOut(value) {
|
|
322
|
+
if (!isRecordObject(value))
|
|
323
|
+
return undefined;
|
|
324
|
+
switch (value.kind) {
|
|
325
|
+
case 'switch-market':
|
|
326
|
+
return nonEmpty(value.exchange) && nonEmpty(value.symbol) && nonEmpty(value.label)
|
|
327
|
+
? { kind: 'switch-market', exchange: value.exchange, symbol: value.symbol, label: value.label }
|
|
328
|
+
: undefined;
|
|
329
|
+
case 'try-interval':
|
|
330
|
+
return nonEmpty(value.interval) ? { kind: 'try-interval', interval: value.interval } : undefined;
|
|
331
|
+
case 'go-to-line':
|
|
332
|
+
return typeof value.line === 'number' && Number.isInteger(value.line) && value.line > 0
|
|
333
|
+
? { kind: 'go-to-line', line: value.line }
|
|
334
|
+
: undefined;
|
|
335
|
+
case 'works-on':
|
|
336
|
+
case 'open-settings':
|
|
337
|
+
case 'retry':
|
|
338
|
+
case 'resume-live':
|
|
339
|
+
case 'free-slots':
|
|
340
|
+
case 'open-editor':
|
|
341
|
+
case 'run-on-chart':
|
|
342
|
+
case 'report':
|
|
343
|
+
case 'reload':
|
|
344
|
+
return { kind: value.kind };
|
|
345
|
+
default:
|
|
346
|
+
return undefined;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
function canonicalMarket(value) {
|
|
350
|
+
if (!isRecordObject(value))
|
|
351
|
+
return undefined;
|
|
352
|
+
if (typeof value.exchange !== 'string' || typeof value.symbol !== 'string' || typeof value.label !== 'string') {
|
|
353
|
+
return undefined;
|
|
354
|
+
}
|
|
355
|
+
if (value.coin !== undefined && typeof value.coin !== 'string')
|
|
356
|
+
return undefined;
|
|
357
|
+
return {
|
|
358
|
+
exchange: value.exchange,
|
|
359
|
+
symbol: value.symbol,
|
|
360
|
+
...(typeof value.coin === 'string' ? { coin: value.coin } : {}),
|
|
361
|
+
label: value.label,
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
/** The params sorted by key; a value that is not a string or a finite number fails. */
|
|
365
|
+
function canonicalParams(value) {
|
|
366
|
+
if (!isRecordObject(value))
|
|
367
|
+
return undefined;
|
|
368
|
+
const out = {};
|
|
369
|
+
for (const key of Object.keys(value).sort()) {
|
|
370
|
+
const v = value[key];
|
|
371
|
+
if (typeof v === 'string' || (typeof v === 'number' && Number.isFinite(v)))
|
|
372
|
+
out[key] = v;
|
|
373
|
+
else
|
|
374
|
+
return undefined;
|
|
375
|
+
}
|
|
376
|
+
return out;
|
|
377
|
+
}
|
|
378
|
+
/** A record's telemetry in canonical key order, each field only when it is well formed. */
|
|
379
|
+
function canonicalTelemetry(value) {
|
|
380
|
+
return {
|
|
381
|
+
...(nonEmpty(value.clientRequestId) ? { clientRequestId: value.clientRequestId } : {}),
|
|
382
|
+
...(nonEmpty(value.attemptId) ? { attemptId: value.attemptId } : {}),
|
|
383
|
+
...(value.foreignSupersede === true ? { foreignSupersede: true } : {}),
|
|
384
|
+
...(value.unknownCode === true ? { unknownCode: true } : {}),
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
/** Equal records give equal strings: a fixed key order, the params sorted by key, the telemetry last. */
|
|
388
|
+
export function serializeWrunRefusal(r) {
|
|
389
|
+
const market = canonicalMarket(r.market);
|
|
390
|
+
return JSON.stringify({
|
|
391
|
+
v: 1,
|
|
392
|
+
cls: r.cls,
|
|
393
|
+
variant: r.variant,
|
|
394
|
+
indicatorName: r.indicatorName,
|
|
395
|
+
...(market ? { market } : {}),
|
|
396
|
+
params: canonicalParams(r.params) ?? {},
|
|
397
|
+
severity: r.severity,
|
|
398
|
+
out: canonicalOut(r.out) ?? { kind: 'retry' },
|
|
399
|
+
details: r.details,
|
|
400
|
+
...canonicalTelemetry(r),
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
/** The record a value holds (its canonical string, or the object itself), or null for anything
|
|
404
|
+
* that is not a well-formed `v: 1` record. */
|
|
405
|
+
export function parseWrunRefusal(value) {
|
|
406
|
+
let candidate = value;
|
|
407
|
+
if (typeof value === 'string') {
|
|
408
|
+
try {
|
|
409
|
+
candidate = JSON.parse(value);
|
|
410
|
+
}
|
|
411
|
+
catch {
|
|
412
|
+
return null;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
if (!isRecordObject(candidate) || candidate.v !== 1)
|
|
416
|
+
return null;
|
|
417
|
+
if (!isClass(candidate.cls) || typeof candidate.variant !== 'string')
|
|
418
|
+
return null;
|
|
419
|
+
if (typeof candidate.indicatorName !== 'string' || typeof candidate.details !== 'string')
|
|
420
|
+
return null;
|
|
421
|
+
if (candidate.severity !== 'note' && candidate.severity !== 'paused')
|
|
422
|
+
return null;
|
|
423
|
+
const params = canonicalParams(candidate.params);
|
|
424
|
+
const out = canonicalOut(candidate.out);
|
|
425
|
+
if (!params || !out)
|
|
426
|
+
return null;
|
|
427
|
+
let market;
|
|
428
|
+
if (candidate.market !== undefined) {
|
|
429
|
+
market = canonicalMarket(candidate.market);
|
|
430
|
+
if (!market)
|
|
431
|
+
return null;
|
|
432
|
+
}
|
|
433
|
+
return {
|
|
434
|
+
v: 1,
|
|
435
|
+
cls: candidate.cls,
|
|
436
|
+
variant: candidate.variant,
|
|
437
|
+
indicatorName: candidate.indicatorName,
|
|
438
|
+
...(market ? { market } : {}),
|
|
439
|
+
params,
|
|
440
|
+
severity: candidate.severity,
|
|
441
|
+
out,
|
|
442
|
+
details: candidate.details,
|
|
443
|
+
...canonicalTelemetry(candidate),
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
/** C2 precedence: paused before note, then the class order, then the canonical string (a total
|
|
447
|
+
* order, so the top refusal of a set never depends on arrival order). */
|
|
448
|
+
export function compareWrunRefusals(a, b) {
|
|
449
|
+
const severity = (a.severity === 'paused' ? 0 : 1) - (b.severity === 'paused' ? 0 : 1);
|
|
450
|
+
if (severity !== 0)
|
|
451
|
+
return severity;
|
|
452
|
+
const rank = (CLASS_RANK.get(a.cls) ?? CLASS_RANK.size) - (CLASS_RANK.get(b.cls) ?? CLASS_RANK.size);
|
|
453
|
+
if (rank !== 0)
|
|
454
|
+
return rank;
|
|
455
|
+
const sa = serializeWrunRefusal(a);
|
|
456
|
+
const sb = serializeWrunRefusal(b);
|
|
457
|
+
return sa < sb ? -1 : sa > sb ? 1 : 0;
|
|
458
|
+
}
|
|
459
|
+
// ---------------------------------------------------------------------------
|
|
460
|
+
// Seeds and records on errors
|
|
461
|
+
// ---------------------------------------------------------------------------
|
|
462
|
+
const SEED_KEY = 'wrunRefusalSeed';
|
|
463
|
+
const RECORD_KEY = 'wrunRefusal';
|
|
464
|
+
function defineHidden(target, key, value) {
|
|
465
|
+
Object.defineProperty(target, key, { value, configurable: true, writable: true, enumerable: false });
|
|
466
|
+
}
|
|
467
|
+
function validSeed(value) {
|
|
468
|
+
return isRecordObject(value) && isClass(value.cls) ? value : undefined;
|
|
469
|
+
}
|
|
470
|
+
/** Attach the raiser's seed to the error it throws. The nearest raiser wins: a seed already on the
|
|
471
|
+
* error stays. A non-object throwable is returned as it is. */
|
|
472
|
+
export function attachWrunRefusal(error, seed) {
|
|
473
|
+
if (error && typeof error === 'object' && !(SEED_KEY in error))
|
|
474
|
+
defineHidden(error, SEED_KEY, seed);
|
|
475
|
+
return error;
|
|
476
|
+
}
|
|
477
|
+
/** The seed a raiser attached, or undefined. */
|
|
478
|
+
export function wrunRefusalSeedOf(error) {
|
|
479
|
+
if (!error || typeof error !== 'object')
|
|
480
|
+
return undefined;
|
|
481
|
+
return validSeed(error[SEED_KEY]);
|
|
482
|
+
}
|
|
483
|
+
/** Annotate the completed record on the error (the decision of the outermost site that made it:
|
|
484
|
+
* a later annotation replaces an earlier one), so a caller downstream (the loader's catch, the
|
|
485
|
+
* editor console) reads the same record instead of deciding again. */
|
|
486
|
+
export function annotateWrunErrorRefusal(error, r) {
|
|
487
|
+
if (error && typeof error === 'object')
|
|
488
|
+
defineHidden(error, RECORD_KEY, r);
|
|
489
|
+
return error;
|
|
490
|
+
}
|
|
491
|
+
/** The completed record an error carries, or undefined. */
|
|
492
|
+
export function wrunRefusalOf(error) {
|
|
493
|
+
if (!error || typeof error !== 'object')
|
|
494
|
+
return undefined;
|
|
495
|
+
return parseWrunRefusal(error[RECORD_KEY]) ?? undefined;
|
|
496
|
+
}
|
|
497
|
+
const TELEMETRY_KEY = 'wrunRefusalTelemetry';
|
|
498
|
+
/** Stamp what the raiser knows of the answer on the error it throws (the cloud lane's transport: the ask's socket
|
|
499
|
+
* stamp, the run attempt, a foreign supersede); the record `wrunRefusalFor` completes carries it. Merged over an
|
|
500
|
+
* earlier stamp. A non-object throwable is returned as it is. */
|
|
501
|
+
export function stampWrunRefusalTelemetry(error, telemetry) {
|
|
502
|
+
if (!error || typeof error !== 'object')
|
|
503
|
+
return error;
|
|
504
|
+
const held = error[TELEMETRY_KEY];
|
|
505
|
+
defineHidden(error, TELEMETRY_KEY, canonicalTelemetry({ ...(isRecordObject(held) ? held : {}), ...telemetry }));
|
|
506
|
+
return error;
|
|
507
|
+
}
|
|
508
|
+
/** The telemetry a raiser stamped on an error (stampWrunRefusalTelemetry), or none. */
|
|
509
|
+
export function wrunRefusalTelemetryOf(error) {
|
|
510
|
+
if (!error || typeof error !== 'object')
|
|
511
|
+
return {};
|
|
512
|
+
const held = error[TELEMETRY_KEY];
|
|
513
|
+
return isRecordObject(held) ? canonicalTelemetry(held) : {};
|
|
514
|
+
}
|
|
515
|
+
// ---------------------------------------------------------------------------
|
|
516
|
+
// The editable rule
|
|
517
|
+
// ---------------------------------------------------------------------------
|
|
518
|
+
function refObject(value) {
|
|
519
|
+
return isRecordObject(value) ? value : undefined;
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Whether the overlay's source can be opened in the editor (the OUT ladders read it, so Open in
|
|
523
|
+
* editor never appears for an opaque package):
|
|
524
|
+
* - a live editor tab whose `scriptId ?? id` is `settings.editorRunKey` (`hasEditorTab` answers);
|
|
525
|
+
* - a saved draft: `settings.wrunDraftRef.scriptDocId`;
|
|
526
|
+
* - a registry package the fork loader can open (`wrun-registry-fork.util.ts`): a browser lane
|
|
527
|
+
* ref (`wrunRegistryRef.package`), never a hosted record (`wrunRef`, the Cloud target), never a
|
|
528
|
+
* ref that names a closed source mode (`sourceMode` other than "open") or several files. The
|
|
529
|
+
* persisted ref carries no source mode today, so a compiled-only version answers true here and
|
|
530
|
+
* its Open in editor ends `unavailable` when the fork refuses.
|
|
531
|
+
*/
|
|
532
|
+
export function wrunOverlayEditable(settings, hasEditorTab) {
|
|
533
|
+
if (!settings)
|
|
534
|
+
return false;
|
|
535
|
+
const runKey = settings.editorRunKey;
|
|
536
|
+
if (nonEmpty(runKey) && runKey.trim() !== '' && hasEditorTab(runKey))
|
|
537
|
+
return true;
|
|
538
|
+
if (nonEmpty(refObject(settings.wrunDraftRef)?.scriptDocId))
|
|
539
|
+
return true;
|
|
540
|
+
const registryRef = refObject(settings.wrunRegistryRef);
|
|
541
|
+
if (!nonEmpty(registryRef?.package))
|
|
542
|
+
return false;
|
|
543
|
+
if (nonEmpty(refObject(settings.wrunRef)?.package) || settings.wrunRunTarget === 'cloud')
|
|
544
|
+
return false;
|
|
545
|
+
// A version whose source mode is unknown (a ref saved before the loader stamped it, not yet
|
|
546
|
+
// restored) is not offered Open in editor: the fork might refuse, and a way out must lead
|
|
547
|
+
// somewhere. The loader stamps the mode at mount and on restore.
|
|
548
|
+
if (registryRef.sourceMode !== 'open')
|
|
549
|
+
return false;
|
|
550
|
+
if (registryRef.multiFile === true)
|
|
551
|
+
return false;
|
|
552
|
+
return true;
|
|
553
|
+
}
|
|
554
|
+
// ---------------------------------------------------------------------------
|
|
555
|
+
// Classification
|
|
556
|
+
// ---------------------------------------------------------------------------
|
|
557
|
+
/** The options-chain venues' names, for the codes' fallback (the run lane's own spelling). */
|
|
558
|
+
const OPTIONS_VENUE_NAMES = Object.freeze({
|
|
559
|
+
deribit: 'Deribit',
|
|
560
|
+
binance: 'Binance Options',
|
|
561
|
+
okx: 'OKX Options',
|
|
562
|
+
bybit: 'Bybit',
|
|
563
|
+
bullish: 'Bullish',
|
|
564
|
+
derive: 'Derive',
|
|
565
|
+
});
|
|
566
|
+
/** The picker's standard intervals, finest first: a coarse refusal's default OUT is the coarsest
|
|
567
|
+
* of them strictly finer than the bound the lane named. */
|
|
568
|
+
const STANDARD_INTERVALS = ['1m', '5m', '15m', '30m', '1h', '4h', '1d', '1w'];
|
|
569
|
+
function intervalMs(word) {
|
|
570
|
+
if (typeof word !== 'string')
|
|
571
|
+
return undefined;
|
|
572
|
+
const ms = Intervals.map_unit[word];
|
|
573
|
+
return typeof ms === 'number' && Number.isFinite(ms) && ms > 0 ? ms : undefined;
|
|
574
|
+
}
|
|
575
|
+
function coarsestFinerThan(bound) {
|
|
576
|
+
const boundMs = intervalMs(bound);
|
|
577
|
+
if (boundMs === undefined)
|
|
578
|
+
return undefined;
|
|
579
|
+
let best;
|
|
580
|
+
for (const word of STANDARD_INTERVALS) {
|
|
581
|
+
const ms = intervalMs(word);
|
|
582
|
+
if (ms !== undefined && ms < boundMs)
|
|
583
|
+
best = word;
|
|
584
|
+
}
|
|
585
|
+
return best;
|
|
586
|
+
}
|
|
587
|
+
function messageOf(error) {
|
|
588
|
+
if (error instanceof Error)
|
|
589
|
+
return error.message;
|
|
590
|
+
if (typeof error === 'string')
|
|
591
|
+
return error;
|
|
592
|
+
if (isRecordObject(error) && typeof error.message === 'string')
|
|
593
|
+
return error.message;
|
|
594
|
+
return '';
|
|
595
|
+
}
|
|
596
|
+
function chartMarketOf(ctx) {
|
|
597
|
+
const chart = ctx.chart;
|
|
598
|
+
if (!chart)
|
|
599
|
+
return undefined;
|
|
600
|
+
return {
|
|
601
|
+
exchange: chart.exchange,
|
|
602
|
+
symbol: chart.symbol,
|
|
603
|
+
...(typeof chart.coin === 'string' && chart.coin !== '' ? { coin: chart.coin } : {}),
|
|
604
|
+
label: chart.symbol,
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
function numberMatch(message, re) {
|
|
608
|
+
const match = re.exec(message);
|
|
609
|
+
if (!match)
|
|
610
|
+
return undefined;
|
|
611
|
+
const n = Number(match[1]);
|
|
612
|
+
return Number.isFinite(n) ? n : undefined;
|
|
613
|
+
}
|
|
614
|
+
/** The seed a stable code in the message names, or undefined. */
|
|
615
|
+
function seedFromCodes(message, ctx) {
|
|
616
|
+
if (message.includes('wrun_cell_block_too_large')) {
|
|
617
|
+
const inputIndex = numberMatch(message, /\binput (\d+)\b/);
|
|
618
|
+
const cells = numberMatch(message, /\bhas (\d+) cells\b/) ?? 0;
|
|
619
|
+
const max = numberMatch(message, /\bmax_cells is (\d+)\b/) ?? 0;
|
|
620
|
+
const sourceClass = inputIndex === undefined ? undefined : ctx.inputClassAt?.(inputIndex);
|
|
621
|
+
if (sourceClass === 'options_chain')
|
|
622
|
+
return { cls: 'too-big', variant: 'chain', params: { cells, max } };
|
|
623
|
+
return { cls: 'too-big', variant: 'block', params: { feed: sourceClass ?? '', cells, max } };
|
|
624
|
+
}
|
|
625
|
+
const optionsCode = /\b(wrun_options_chain_[a-z_]+)\b/.exec(message)?.[1];
|
|
626
|
+
if (optionsCode !== undefined) {
|
|
627
|
+
const coin = /\bcoin '([^']+)'/.exec(message)?.[1] ?? ctx.chart?.coin ?? '';
|
|
628
|
+
const provablyNotCme = ctx.chart !== undefined && ctx.chart.cme === false;
|
|
629
|
+
switch (optionsCode) {
|
|
630
|
+
case 'wrun_options_chain_unavailable':
|
|
631
|
+
return { cls: 'no-options', variant: ctx.chart?.cme ? 'unresolved' : 'chain', params: { coin } };
|
|
632
|
+
case 'wrun_options_chain_venue_unavailable': {
|
|
633
|
+
const word = /\bwith venue "([^"]+)"/.exec(message)?.[1] ?? '';
|
|
634
|
+
if (word === 'cme') {
|
|
635
|
+
return { cls: 'no-options', variant: provablyNotCme ? 'cme-venue' : 'unresolved', params: { coin } };
|
|
636
|
+
}
|
|
637
|
+
const venue = OPTIONS_VENUE_NAMES[word];
|
|
638
|
+
if (venue === undefined)
|
|
639
|
+
return { cls: 'no-options', variant: 'unresolved', params: { coin } };
|
|
640
|
+
const flagOff = word !== 'deribit' && message.includes('crypto-options flag is off');
|
|
641
|
+
return { cls: 'no-options', variant: flagOff ? 'flag-off' : 'venue', params: { venue, coin } };
|
|
642
|
+
}
|
|
643
|
+
default:
|
|
644
|
+
// A bad venue word, two venues in one sheet, a bad expiries word: the author's to fix.
|
|
645
|
+
return { cls: 'run-failed', variant: 'generic' };
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
if (message.includes('wrun_pin_venue_refused')) {
|
|
649
|
+
const pin = /\bwrun_pin_venue_refused: (\S+) is CME\b/.exec(message)?.[1] ??
|
|
650
|
+
/\bpins exchange (\S+?):/.exec(message)?.[1] ??
|
|
651
|
+
'CME';
|
|
652
|
+
return { cls: 'pin-refused', params: { pin } };
|
|
653
|
+
}
|
|
654
|
+
// A host's own refusal of a venue word (the cloud's planner, om's sheet check): the same record
|
|
655
|
+
// the run pass seeds.
|
|
656
|
+
const unknownVenue = /\bwrun_pin_venue_unknown: venue '([^']*)'/.exec(message);
|
|
657
|
+
if (unknownVenue !== null) {
|
|
658
|
+
return { cls: 'run-failed', variant: 'pin-venue-unknown', params: { venue: unknownVenue[1] } };
|
|
659
|
+
}
|
|
660
|
+
const tpo = TPO_LETTER_MISMATCH_RE.exec(message);
|
|
661
|
+
if (tpo !== null)
|
|
662
|
+
return tpoLetterSeed(Number(tpo[1]), tpo[2], ctx);
|
|
663
|
+
return undefined;
|
|
664
|
+
}
|
|
665
|
+
// ---------------------------------------------------------------------------
|
|
666
|
+
// The cloud's refusals, by code (WRUN-PARITY-PLAN row 21, lane parity U16)
|
|
667
|
+
// ---------------------------------------------------------------------------
|
|
668
|
+
/** The kit's refusal stages live in the import-free leaf the answer table reads (the socket worker reads it too). */
|
|
669
|
+
export { WRUN_KIT_REFUSAL_STAGES, wrunKitRefusalStageOf };
|
|
670
|
+
/** The whole-run refusal code of a cloud reply the chart reads no rows from: a reply without the
|
|
671
|
+
* hosted wire (a server on the legacy pre-styled path; the socket row source refuses it). */
|
|
672
|
+
export const WRUN_LEGACY_RESULT_CODE = 'wrun_legacy_result';
|
|
673
|
+
/** The whole-run refusal code of a create the server superseded while it was the overlay's live attempt (no newer
|
|
674
|
+
* attempt of this chart replaced it: another chart or tab created the same instance id). The socket row source
|
|
675
|
+
* answers it; its record is `session-lost` (WRUN-REPORTS-CLASSES C1). */
|
|
676
|
+
export const WRUN_SESSION_LOST_CODE = 'wrun_session_lost';
|
|
677
|
+
/** The `session-lost` record's seed: a note whose way out is Retry. Never retried on its own: the heal reads the
|
|
678
|
+
* socket row source's refusal as one the same ask repeats, and another chart's session would go the same way. */
|
|
679
|
+
export function wrunSessionLostSeed() {
|
|
680
|
+
return { cls: 'run-failed', variant: 'session-lost', out: { kind: 'retry' } };
|
|
681
|
+
}
|
|
682
|
+
/** The codes whose way out is the settings: a value a declaration refuses, a param the package no
|
|
683
|
+
* longer declares, a paint the settings ask that no host draws. */
|
|
684
|
+
const SETTINGS_REFUSAL_CODES = new Set([
|
|
685
|
+
'wrun_params_invalid',
|
|
686
|
+
'wrun_tape_min_size_invalid',
|
|
687
|
+
'wrun_param_unknown',
|
|
688
|
+
'wrun_settings_paint_unsupported',
|
|
689
|
+
]);
|
|
690
|
+
/** The connection's caps: the tab's other Indicators hold them, and the room returns when one of them
|
|
691
|
+
* is removed, so the way out is Retry (`free-slots` is an add door no mounted overlay runs). */
|
|
692
|
+
const TAB_FULL_REFUSAL_CODES = new Set([
|
|
693
|
+
'wrun_foreign_sources_over_cap',
|
|
694
|
+
'wrun_instances_over_cap',
|
|
695
|
+
]);
|
|
696
|
+
/** The tape lane's interval refusal in the browser lane's own record (wrun-overlay-run.util
|
|
697
|
+
* `assertWrunTapeServedOnInterval`): a calendar chart is coarser than the tape serves, any other
|
|
698
|
+
* (one second) finer. */
|
|
699
|
+
function tapeIntervalSeed(chartInterval) {
|
|
700
|
+
return isCalendarIntervalLabel(chartInterval)
|
|
701
|
+
? { cls: 'interval-unserved', variant: 'coarse', params: { feed: 'tape', interval: '1M', chartInterval } }
|
|
702
|
+
: { cls: 'interval-unserved', variant: 'fine', params: { feed: 'tape', interval: '1m', chartInterval } };
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* The record seed of a refusal the cloud answered, by its code and the facts its frame carried
|
|
706
|
+
* (wrun-hosted-wire-caps `WrunFrameRefusal`), never its sentence: the no-candles answer is the browser
|
|
707
|
+
* lane's no-bars record (`waiting`, row 37); a reply without the hosted wire refuses with the reload
|
|
708
|
+
* way out; a code the settings answer opens them; the leg, window and tape refusals and the tab's caps
|
|
709
|
+
* say the browser lane's own words; the options chain and the pin codes read as the browser lane's own
|
|
710
|
+
* table reads them, with the chart's coin; anything else says the generic words with its code. Every
|
|
711
|
+
* seed but `waiting` and the reload carries the code, so the record names what the cloud said.
|
|
712
|
+
*/
|
|
713
|
+
export function wrunCloudRefusalSeed(code, facts = {}, ctx) {
|
|
714
|
+
if (code === WRUN_NO_CANDLES_CODE)
|
|
715
|
+
return { cls: 'waiting' };
|
|
716
|
+
if (code === WRUN_LEGACY_RESULT_CODE)
|
|
717
|
+
return { cls: 'run-failed', variant: 'legacy-result', out: { kind: 'reload' } };
|
|
718
|
+
if (code === WRUN_SESSION_LOST_CODE)
|
|
719
|
+
return wrunSessionLostSeed();
|
|
720
|
+
if (SETTINGS_REFUSAL_CODES.has(code)) {
|
|
721
|
+
return { cls: 'run-failed', variant: 'settings', params: { code }, out: { kind: 'open-settings' } };
|
|
722
|
+
}
|
|
723
|
+
if (code === 'wrun_intrabar_leg_not_finer')
|
|
724
|
+
return { cls: 'run-failed', variant: 'intrabar', params: { code } };
|
|
725
|
+
if (code === 'wrun_window_too_large' && facts.value) {
|
|
726
|
+
return { cls: 'run-failed', variant: 'window', params: { code, leg: facts.value } };
|
|
727
|
+
}
|
|
728
|
+
const chart = ctx?.chart;
|
|
729
|
+
// No chart in hand (the error envelope): the frame's value names the chart's interval or coin.
|
|
730
|
+
const value = chart ? undefined : facts.value;
|
|
731
|
+
const chartInterval = chart?.interval ?? value;
|
|
732
|
+
if (code === 'wrun_tape_interval_unsupported' && chartInterval)
|
|
733
|
+
return tapeIntervalSeed(chartInterval);
|
|
734
|
+
if (TAB_FULL_REFUSAL_CODES.has(code)) {
|
|
735
|
+
const params = { code };
|
|
736
|
+
if (facts.limit !== undefined && Number.isFinite(facts.limit))
|
|
737
|
+
params.cap = facts.limit;
|
|
738
|
+
return { cls: 'run-failed', variant: 'tab-full', params, out: { kind: 'retry' } };
|
|
739
|
+
}
|
|
740
|
+
// The options chain codes read with the chart's coin (else the frame's, its market too), the venue a venue
|
|
741
|
+
// refusal names by its word; without the facts their words need, the generic words with the code.
|
|
742
|
+
const coin = chart?.coin ?? (code === 'wrun_options_chain_unavailable' ? value : undefined) ?? '';
|
|
743
|
+
if (code === 'wrun_options_chain_unavailable' && coin !== '') {
|
|
744
|
+
return {
|
|
745
|
+
cls: 'no-options',
|
|
746
|
+
variant: chart?.cme ? 'unresolved' : 'chain',
|
|
747
|
+
params: chart ? { coin } : { coin, market: coin },
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
const venue = facts.value !== undefined ? OPTIONS_VENUE_NAMES[facts.value] : undefined;
|
|
751
|
+
if (code === 'wrun_options_chain_venue_unavailable' && coin !== '' && venue !== undefined) {
|
|
752
|
+
return { cls: 'no-options', variant: 'venue', params: { venue, coin } };
|
|
753
|
+
}
|
|
754
|
+
// A pin on CME data names the venue the frame names, else CME (the browser lane's own default).
|
|
755
|
+
if (code === 'wrun_pin_venue_refused')
|
|
756
|
+
return { cls: 'pin-refused', params: { pin: facts.value ?? 'CME' } };
|
|
757
|
+
if (code === 'wrun_pin_venue_unknown' && facts.value) {
|
|
758
|
+
return { cls: 'run-failed', variant: 'pin-venue-unknown', params: { venue: facts.value } };
|
|
759
|
+
}
|
|
760
|
+
return { cls: 'run-failed', variant: 'refused', params: { code } };
|
|
761
|
+
}
|
|
762
|
+
/** The record seed of a presentation family a source left out of a batch that drew (a note: the rest
|
|
763
|
+
* drew), with the code the source answered for it. */
|
|
764
|
+
export function wrunLeftOutRefusalSeed(family, code) {
|
|
765
|
+
return { cls: 'run-failed', variant: 'left-out', params: { code, family } };
|
|
766
|
+
}
|
|
767
|
+
/** A whole-run refusal of the socket row source (its `WrunSocketRefusalError`, kept out of this
|
|
768
|
+
* module's graph: read by its name), as the code and facts it carries. */
|
|
769
|
+
function socketRefusalOf(error) {
|
|
770
|
+
if (!(error instanceof Error) || error.name !== 'WrunSocketRefusalError')
|
|
771
|
+
return undefined;
|
|
772
|
+
const { code, facts } = error;
|
|
773
|
+
if (typeof code !== 'string' || code === '')
|
|
774
|
+
return undefined;
|
|
775
|
+
return { ...(isRecordObject(facts) ? facts : {}), code };
|
|
776
|
+
}
|
|
777
|
+
/** The cloud refusal an error carries: a socket row source's whole-run refusal, else the code a cloud
|
|
778
|
+
* error frame's text names (its relayed details, or an older server's leading code), else, for a frame
|
|
779
|
+
* that names no refusal, its own code when the answer table remembers it (an eligibility frame) or has
|
|
780
|
+
* no row for it: the error envelope's record reads the same, never the generic words. */
|
|
781
|
+
function cloudRefusalOfError(error, message, answer) {
|
|
782
|
+
const coded = socketRefusalOf(error) ?? wrunFrameRefusalOf(message);
|
|
783
|
+
if (coded !== undefined)
|
|
784
|
+
return coded;
|
|
785
|
+
if (answer?.frameCode !== undefined && (answer.memory !== undefined || answer.unknownCode === true)) {
|
|
786
|
+
return { code: answer.frameCode };
|
|
787
|
+
}
|
|
788
|
+
return undefined;
|
|
789
|
+
}
|
|
790
|
+
/** The TPO letter check's words (wrun-tpo-rows.util `wrunTpoLetterMismatch`, pinned by its specs):
|
|
791
|
+
* the letter's minutes and the span label of the bars it was asked to place. */
|
|
792
|
+
const TPO_LETTER_MISMATCH_RE = /\b(\d+)-minute letters need bars of \d+ minutes or a whole divisor; the bars here are (\S+) \(/;
|
|
793
|
+
/** The coarsest picker interval that divides `spanMs` (`strictlyFiner`: and is not the span itself). */
|
|
794
|
+
function coarsestStandardDividing(spanMs, strictlyFiner) {
|
|
795
|
+
let best;
|
|
796
|
+
for (const word of STANDARD_INTERVALS) {
|
|
797
|
+
const ms = intervalMs(word);
|
|
798
|
+
if (ms !== undefined && ms <= spanMs && spanMs % ms === 0 && !(strictlyFiner && ms === spanMs))
|
|
799
|
+
best = word;
|
|
800
|
+
}
|
|
801
|
+
return best;
|
|
802
|
+
}
|
|
803
|
+
/** The coarsest picker interval whose bars place a letter of `letterMinutes` (a whole divisor). */
|
|
804
|
+
function standardIntervalDividing(letterMinutes) {
|
|
805
|
+
return coarsestStandardDividing(letterMinutes * 60_000, false);
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* The seed of an input interval pin finer than the chart's (`planWrunPinnedWires`): a pinned leg is a
|
|
809
|
+
* whole number of chart bars, so the chart must be the pin's interval or a divisor of it, strictly
|
|
810
|
+
* finer for an input that views the pin (confirmed, forming, offset: the chart's own interval has
|
|
811
|
+
* nothing to view). `at-most` with the coarsest picker interval that serves it as the way out; none
|
|
812
|
+
* (a pin finer than every picker interval): the run-failed words.
|
|
813
|
+
*/
|
|
814
|
+
export function wrunPinFinerSeed(pinMs, strictlyFiner) {
|
|
815
|
+
const interval = Number.isFinite(pinMs) && pinMs > 0 ? coarsestStandardDividing(pinMs, strictlyFiner) : undefined;
|
|
816
|
+
return interval === undefined
|
|
817
|
+
? { cls: 'run-failed', variant: 'generic' }
|
|
818
|
+
: { cls: 'interval-unserved', variant: 'at-most', params: { interval } };
|
|
819
|
+
}
|
|
820
|
+
/** The seed of a TPO letter refusal: the chart's own bars (their span is the chart's interval) are
|
|
821
|
+
* too coarse for the letter, so the chart must be the letter's interval or finer (`at-most`, its
|
|
822
|
+
* way out the coarsest picker interval that places it); bars of another span (an intrabar input
|
|
823
|
+
* the author declared) are the author's to fix. */
|
|
824
|
+
function tpoLetterSeed(letterMinutes, bars, ctx) {
|
|
825
|
+
const interval = Number.isFinite(letterMinutes) && letterMinutes > 0 ? standardIntervalDividing(letterMinutes) : undefined;
|
|
826
|
+
const chartInterval = ctx.chart?.interval;
|
|
827
|
+
const barsMs = intervalMs(bars);
|
|
828
|
+
const chartMs = intervalMs(chartInterval);
|
|
829
|
+
const chartBars = chartInterval !== undefined &&
|
|
830
|
+
(barsMs !== undefined && chartMs !== undefined ? barsMs === chartMs : bars === chartInterval);
|
|
831
|
+
if (interval === undefined || !chartBars)
|
|
832
|
+
return { cls: 'run-failed', variant: 'generic' };
|
|
833
|
+
return { cls: 'interval-unserved', variant: 'at-most', params: { interval, chartInterval: bars } };
|
|
834
|
+
}
|
|
835
|
+
/** Leg classes: an unseeded refusal of theirs names a pinned market the message alone does not
|
|
836
|
+
* give, so it keeps the generic words rather than name the chart's market wrongly. */
|
|
837
|
+
const LEG_CLASSES = new Set(['ohlcv', 'candles', 'intrabar', 'odds', 'time']);
|
|
838
|
+
/** The lane word of an unseeded "data is unavailable" refusal (`the <lane> source lane`), when it
|
|
839
|
+
* names a feed of the chart's own market. */
|
|
840
|
+
function laneFeedOf(message) {
|
|
841
|
+
const lane = /\bthe ([a-z][a-z0-9_]*) source lane\b/.exec(message)?.[1];
|
|
842
|
+
if (lane === undefined || LEG_CLASSES.has(lane))
|
|
843
|
+
return undefined;
|
|
844
|
+
return wrunRefusalFeedKey(lane) !== undefined ? lane : undefined;
|
|
845
|
+
}
|
|
846
|
+
function seedOfError(error, ctx) {
|
|
847
|
+
const attached = wrunRefusalSeedOf(error);
|
|
848
|
+
if (attached)
|
|
849
|
+
return attached;
|
|
850
|
+
const plain = validSeed(error);
|
|
851
|
+
if (plain && !(error instanceof Error))
|
|
852
|
+
return plain;
|
|
853
|
+
const message = messageOf(error);
|
|
854
|
+
// A server answer reads through the one answer table (wrun-hosted-wire-caps `wrunServerAnswerOfText`).
|
|
855
|
+
const answer = wrunServerAnswerOfText(message);
|
|
856
|
+
// An answer to a superseded create reaches a record only as the live attempt's own (the socket worker settles
|
|
857
|
+
// a replaced attempt's caller, never throws it): another chart or tab took the session. Retry, a note.
|
|
858
|
+
if (answer?.verdict === 'stale')
|
|
859
|
+
return wrunSessionLostSeed();
|
|
860
|
+
// A cloud refusal reads by its code (row 21), before any read of the words; one the table says may pass on
|
|
861
|
+
// the next ask keeps Retry as its way out.
|
|
862
|
+
const cloud = cloudRefusalOfError(error, message, answer);
|
|
863
|
+
if (cloud) {
|
|
864
|
+
const seed = wrunCloudRefusalSeed(cloud.code, cloud, ctx);
|
|
865
|
+
return answer?.verdict === 'retry' ? { ...seed, out: { kind: 'retry' } } : seed;
|
|
866
|
+
}
|
|
867
|
+
const coded = seedFromCodes(message, ctx);
|
|
868
|
+
if (coded)
|
|
869
|
+
return coded;
|
|
870
|
+
if (error instanceof WrunNoBarsError)
|
|
871
|
+
return { cls: 'waiting' };
|
|
872
|
+
if (error instanceof WrunDeadlineError)
|
|
873
|
+
return { cls: 'not-reached', variant: 'run' };
|
|
874
|
+
if (error instanceof WrunSourceDataUnavailableError) {
|
|
875
|
+
const feed = laneFeedOf(message);
|
|
876
|
+
return { cls: 'service-no-answer', variant: 'lane', params: feed ? { feed } : {} };
|
|
877
|
+
}
|
|
878
|
+
// An answer a second ask may pass (`[INTERNAL]`, an uncoded lane failure, the rate limit) keeps the transient
|
|
879
|
+
// run's Retry (the generic words, the frame's first line under them): the server's own word, never the
|
|
880
|
+
// deterministic dead end.
|
|
881
|
+
if (answer?.verdict === 'retry')
|
|
882
|
+
return { cls: 'run-failed', variant: 'generic', out: { kind: 'retry' } };
|
|
883
|
+
return runFailedSeedOf(error, message);
|
|
884
|
+
}
|
|
885
|
+
/** A wasm trap in each engine's own words (V8, SpiderMonkey, JavaScriptCore), matched on the whole
|
|
886
|
+
* first line (a stringified error leads with its name): the Indicator's code stopped. `unreachable`
|
|
887
|
+
* never reaches here: the run seam makes it a trap row (WRUN_UNREACHABLE_TRAP). */
|
|
888
|
+
const ENGINE_TRAP_WORDS = [
|
|
889
|
+
'(?:integer )?divide by zero',
|
|
890
|
+
'division by zero',
|
|
891
|
+
'remainder by zero',
|
|
892
|
+
'integer overflow',
|
|
893
|
+
'float unrepresentable in integer range',
|
|
894
|
+
'invalid conversion to integer',
|
|
895
|
+
'out of bounds trunc operation',
|
|
896
|
+
'memory access out of bounds',
|
|
897
|
+
'out of bounds memory access',
|
|
898
|
+
'index out of bounds',
|
|
899
|
+
'table index is out of bounds',
|
|
900
|
+
'out of bounds table access',
|
|
901
|
+
'null function or function signature mismatch',
|
|
902
|
+
'indirect call to null',
|
|
903
|
+
'indirect call signature mismatch',
|
|
904
|
+
'out of bounds call_indirect',
|
|
905
|
+
'call_indirect to a null table entry',
|
|
906
|
+
'call_indirect to a signature that does not match',
|
|
907
|
+
'illegal cast',
|
|
908
|
+
'maximum call stack size exceeded',
|
|
909
|
+
'too much recursion',
|
|
910
|
+
];
|
|
911
|
+
const ENGINE_TRAP_RE = new RegExp(`^(?:(?:RuntimeError|RangeError|InternalError): )?(?:${ENGINE_TRAP_WORDS.join('|')})\\.?$`, 'i');
|
|
912
|
+
/** The ABI host's write and memory rules the module broke (workers/wrun/wrun-abi-host.ts; the Run's
|
|
913
|
+
* analytics codes them in run-failure-props.util ROWLESS_REJECTIONS from the same words). */
|
|
914
|
+
const HOST_RULE_RE = /\bWRUN (?:(?:string|frame) slot \d+ write of \d+ bytes|(?:string|string and frame|frame and string) writes for (?:one row|this run) total \d+ bytes|output \d+ is -?Infinity;|memory \d+ bytes exceeds limit)/;
|
|
915
|
+
/** A dropped connection under the run: a fetch or a lazy chunk that did not arrive. */
|
|
916
|
+
const NETWORK_FAILURE_RE = /\b(?:Failed to fetch|NetworkError|Load failed|network error|dynamically imported module|Importing a module script failed|ChunkLoadError)\b/i;
|
|
917
|
+
/** The failures a second run can get past: the shared sandbox died under the run (its holder's own
|
|
918
|
+
* timeout is the run deadline's record) or dropped its live session, a package quarantined on its
|
|
919
|
+
* first timeout (the heal waits that one out too), a dropped connection. Every other cause is a
|
|
920
|
+
* function of the code, the data and the settings: the planner and the sandbox fail the same way. */
|
|
921
|
+
function isTransientRunFailure(error, message) {
|
|
922
|
+
if (error instanceof WrunWorkerPoisonError)
|
|
923
|
+
return true;
|
|
924
|
+
if (error instanceof Error && error.name === 'WrunLiveSessionLostError')
|
|
925
|
+
return true;
|
|
926
|
+
if (error instanceof WrunQuarantinedError)
|
|
927
|
+
return error.reason === 'timeout' && error.strikes === 1;
|
|
928
|
+
return NETWORK_FAILURE_RE.test(message);
|
|
929
|
+
}
|
|
930
|
+
/** The first non-empty line of a text, trimmed with its runs of spaces collapsed. */
|
|
931
|
+
function firstLineOf(text) {
|
|
932
|
+
const line = text.split('\n').find((part) => part.trim() !== '') ?? '';
|
|
933
|
+
return line.trim().replace(/\s+/g, ' ');
|
|
934
|
+
}
|
|
935
|
+
/** A run that failed for none of the named reasons: Retry for a transient cause, the code's words for
|
|
936
|
+
* the engine's trap and the host's rules, else the generic words (both deterministic). */
|
|
937
|
+
function runFailedSeedOf(error, message) {
|
|
938
|
+
if (isTransientRunFailure(error, message))
|
|
939
|
+
return { cls: 'run-failed', variant: 'generic', out: { kind: 'retry' } };
|
|
940
|
+
if (ENGINE_TRAP_RE.test(firstLineOf(message)) || HOST_RULE_RE.test(message)) {
|
|
941
|
+
return { cls: 'run-failed', variant: 'code' };
|
|
942
|
+
}
|
|
943
|
+
return { cls: 'run-failed', variant: 'generic' };
|
|
944
|
+
}
|
|
945
|
+
/** The default variant of a class when the seed names none (or names one the facts disprove). */
|
|
946
|
+
function variantFor(seed, ctx) {
|
|
947
|
+
const declared = seed.variant;
|
|
948
|
+
switch (seed.cls) {
|
|
949
|
+
case 'legs-empty':
|
|
950
|
+
if (declared === 'drew' || declared === 'refused')
|
|
951
|
+
return declared;
|
|
952
|
+
return seed.severity === 'paused' ? 'refused' : 'drew';
|
|
953
|
+
case 'feed-missing': {
|
|
954
|
+
const cryptoChart = ctx.chart === undefined || ctx.chart.cryptoVenue;
|
|
955
|
+
// Copy follows facts: "it comes from crypto markets" only off crypto venues.
|
|
956
|
+
if (declared === 'crypto-only' && !cryptoChart)
|
|
957
|
+
return declared;
|
|
958
|
+
if (declared === 'market-paused' || declared === 'market-note')
|
|
959
|
+
return declared;
|
|
960
|
+
if (declared === undefined && !cryptoChart)
|
|
961
|
+
return 'crypto-only';
|
|
962
|
+
return seed.severity === 'note' ? 'market-note' : 'market-paused';
|
|
963
|
+
}
|
|
964
|
+
case 'no-options': {
|
|
965
|
+
const provablyNotCme = ctx.chart !== undefined && ctx.chart.cme === false;
|
|
966
|
+
if (declared === 'cme-venue')
|
|
967
|
+
return provablyNotCme ? 'cme-venue' : 'unresolved';
|
|
968
|
+
if (declared !== undefined && variantSpec('no-options', declared))
|
|
969
|
+
return declared;
|
|
970
|
+
return ctx.chart?.cme ? 'unresolved' : 'chain';
|
|
971
|
+
}
|
|
972
|
+
case 'interval-unserved':
|
|
973
|
+
return declared === 'coarse' || declared === 'at-most' || declared === 'exact' ? declared : 'fine';
|
|
974
|
+
case 'service-no-answer':
|
|
975
|
+
if (declared !== undefined && variantSpec('service-no-answer', declared))
|
|
976
|
+
return declared;
|
|
977
|
+
return seed.params?.market !== undefined || seed.market !== undefined || ctx.chart ? 'lane' : 'global';
|
|
978
|
+
case 'cme-wall':
|
|
979
|
+
return declared !== undefined && variantSpec('cme-wall', declared) ? declared : 'default';
|
|
980
|
+
case 'too-big':
|
|
981
|
+
return declared === 'chain' || declared === 'rows' ? declared : 'block';
|
|
982
|
+
case 'not-reached':
|
|
983
|
+
return declared !== undefined && variantSpec('not-reached', declared) ? declared : 'run';
|
|
984
|
+
case 'slots':
|
|
985
|
+
return declared === 'all-in-use' ? 'all-in-use' : 'some-free';
|
|
986
|
+
case 'not-added':
|
|
987
|
+
return declared !== undefined && variantSpec('not-added', declared) ? declared : 'gate';
|
|
988
|
+
case 'run-failed':
|
|
989
|
+
return declared !== undefined && variantSpec('run-failed', declared) ? declared : 'generic';
|
|
990
|
+
default:
|
|
991
|
+
return 'default';
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
function finiteNumber(value, fallback) {
|
|
995
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : fallback;
|
|
996
|
+
}
|
|
997
|
+
/** Exactly the variant's params: the seed's, else the defaults the record and the chart give. */
|
|
998
|
+
function paramsFor(spec, seed, ctx, market) {
|
|
999
|
+
const given = seed.params ?? {};
|
|
1000
|
+
const out = {};
|
|
1001
|
+
for (const name of spec.params) {
|
|
1002
|
+
const value = given[name];
|
|
1003
|
+
if (typeof value === 'string' || (typeof value === 'number' && Number.isFinite(value))) {
|
|
1004
|
+
out[name] = value;
|
|
1005
|
+
continue;
|
|
1006
|
+
}
|
|
1007
|
+
switch (name) {
|
|
1008
|
+
case 'name':
|
|
1009
|
+
out.name = ctx.indicatorName;
|
|
1010
|
+
break;
|
|
1011
|
+
case 'market':
|
|
1012
|
+
case 'markets':
|
|
1013
|
+
out[name] = market?.label ?? '';
|
|
1014
|
+
break;
|
|
1015
|
+
case 'coin':
|
|
1016
|
+
out.coin = market?.coin ?? ctx.chart?.coin ?? '';
|
|
1017
|
+
break;
|
|
1018
|
+
case 'symbol':
|
|
1019
|
+
out.symbol = market?.symbol ?? '';
|
|
1020
|
+
break;
|
|
1021
|
+
case 'chartInterval':
|
|
1022
|
+
out.chartInterval = ctx.chart?.interval ?? '';
|
|
1023
|
+
break;
|
|
1024
|
+
case 'count':
|
|
1025
|
+
out.count = 1;
|
|
1026
|
+
break;
|
|
1027
|
+
case 'n':
|
|
1028
|
+
case 'free':
|
|
1029
|
+
case 'limit':
|
|
1030
|
+
case 'cells':
|
|
1031
|
+
case 'max':
|
|
1032
|
+
case 'line':
|
|
1033
|
+
case 'seconds':
|
|
1034
|
+
out[name] = 0;
|
|
1035
|
+
break;
|
|
1036
|
+
default:
|
|
1037
|
+
out[name] = '';
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
return out;
|
|
1041
|
+
}
|
|
1042
|
+
function switchOrWorksOn(ctx) {
|
|
1043
|
+
return canonicalOut(ctx.switchTarget) ?? { kind: 'works-on' };
|
|
1044
|
+
}
|
|
1045
|
+
/** The C2 OUT ladder of a (class, variant), reading the context's flags. */
|
|
1046
|
+
function defaultOut(cls, variant, ctx, params) {
|
|
1047
|
+
switch (cls) {
|
|
1048
|
+
case 'legs-empty':
|
|
1049
|
+
case 'service-no-answer':
|
|
1050
|
+
case 'waiting':
|
|
1051
|
+
case 'not-reached':
|
|
1052
|
+
return { kind: 'retry' };
|
|
1053
|
+
case 'feed-missing':
|
|
1054
|
+
case 'coin-outside-feed':
|
|
1055
|
+
case 'cme-wall':
|
|
1056
|
+
return switchOrWorksOn(ctx);
|
|
1057
|
+
case 'no-options':
|
|
1058
|
+
if (variant === 'unresolved')
|
|
1059
|
+
return { kind: 'retry' };
|
|
1060
|
+
if (variant === 'flag-off' || variant === 'cme-venue') {
|
|
1061
|
+
return ctx.editable ? { kind: 'open-editor' } : { kind: 'works-on' };
|
|
1062
|
+
}
|
|
1063
|
+
return { kind: 'works-on' };
|
|
1064
|
+
case 'interval-unserved': {
|
|
1065
|
+
const interval = variant === 'coarse' ? coarsestFinerThan(params.interval) : params.interval;
|
|
1066
|
+
return nonEmpty(interval) ? { kind: 'try-interval', interval } : { kind: 'works-on' };
|
|
1067
|
+
}
|
|
1068
|
+
case 'pin-refused':
|
|
1069
|
+
if (ctx.editable)
|
|
1070
|
+
return { kind: 'open-editor' };
|
|
1071
|
+
return ctx.hasSettings ? { kind: 'open-settings' } : { kind: 'works-on' };
|
|
1072
|
+
case 'index-unserved':
|
|
1073
|
+
if (ctx.editable)
|
|
1074
|
+
return { kind: 'open-editor' };
|
|
1075
|
+
return ctx.hasSettings ? { kind: 'open-settings' } : { kind: 'retry' };
|
|
1076
|
+
case 'too-big':
|
|
1077
|
+
return ctx.editable ? { kind: 'open-editor' } : { kind: 'works-on' };
|
|
1078
|
+
case 'live-stopped':
|
|
1079
|
+
return { kind: 'resume-live' };
|
|
1080
|
+
case 'nothing-ready':
|
|
1081
|
+
return ctx.hasSettings ? { kind: 'open-settings' } : { kind: 'retry' };
|
|
1082
|
+
case 'slots':
|
|
1083
|
+
return { kind: 'free-slots' };
|
|
1084
|
+
case 'not-added':
|
|
1085
|
+
if (variant === 'window-replay' || variant === 'window-layout-full' || variant === 'window-slot-held') {
|
|
1086
|
+
return { kind: 'run-on-chart' };
|
|
1087
|
+
}
|
|
1088
|
+
return variant === 'window-budget' ? { kind: 'free-slots' } : { kind: 'retry' };
|
|
1089
|
+
case 'run-failed':
|
|
1090
|
+
if (variant === 'compile') {
|
|
1091
|
+
const line = finiteNumber(params.line, 0);
|
|
1092
|
+
return line > 0 ? { kind: 'go-to-line', line } : { kind: 'retry' };
|
|
1093
|
+
}
|
|
1094
|
+
// The same code, data and settings fail the same way (a transient cause seeds its own Retry):
|
|
1095
|
+
// the source when it opens, else the report.
|
|
1096
|
+
return ctx.editable ? { kind: 'open-editor' } : { kind: 'report' };
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
/** A seed's own OUT, held to the flags: Open in editor only for an openable source, Open the
|
|
1100
|
+
* settings only when there are settings; otherwise the class ladder decides. */
|
|
1101
|
+
function outFor(seed, cls, variant, ctx, params) {
|
|
1102
|
+
const declared = canonicalOut(seed.out);
|
|
1103
|
+
if (declared &&
|
|
1104
|
+
!(declared.kind === 'open-editor' && !ctx.editable) &&
|
|
1105
|
+
!(declared.kind === 'open-settings' && !ctx.hasSettings)) {
|
|
1106
|
+
return declared;
|
|
1107
|
+
}
|
|
1108
|
+
return defaultOut(cls, variant, ctx, params);
|
|
1109
|
+
}
|
|
1110
|
+
/** The class's severity when neither the variant nor the seed fixes it. */
|
|
1111
|
+
function defaultSeverity(cls) {
|
|
1112
|
+
return cls === 'waiting' || cls === 'index-unserved' || cls === 'nothing-ready' || cls === 'live-stopped'
|
|
1113
|
+
? 'note'
|
|
1114
|
+
: 'paused';
|
|
1115
|
+
}
|
|
1116
|
+
function buildRecord(seed, ctx, details, telemetry = {}) {
|
|
1117
|
+
const cls = seed.cls;
|
|
1118
|
+
const variant = variantFor(seed, ctx);
|
|
1119
|
+
const spec = variantSpec(cls, variant) ?? RUN_FAILED_GENERIC;
|
|
1120
|
+
const market = canonicalMarket(seed.market) ?? chartMarketOf(ctx);
|
|
1121
|
+
const params = paramsFor(spec, seed, ctx, market);
|
|
1122
|
+
const severity = spec.severity ?? seed.severity ?? defaultSeverity(cls);
|
|
1123
|
+
const out = outFor(seed, cls, variant, ctx, params);
|
|
1124
|
+
const record = {
|
|
1125
|
+
v: 1,
|
|
1126
|
+
cls,
|
|
1127
|
+
variant,
|
|
1128
|
+
indicatorName: ctx.indicatorName,
|
|
1129
|
+
...(market ? { market } : {}),
|
|
1130
|
+
params,
|
|
1131
|
+
severity,
|
|
1132
|
+
out,
|
|
1133
|
+
details,
|
|
1134
|
+
...telemetry,
|
|
1135
|
+
};
|
|
1136
|
+
// A feed with no words cannot be named: the generic words, the class's way out kept.
|
|
1137
|
+
if (spec.params.includes('feed') && wrunRefusalFeedKey(params.feed) === undefined) {
|
|
1138
|
+
return { ...record, cls: 'run-failed', variant: 'generic', params: {} };
|
|
1139
|
+
}
|
|
1140
|
+
return parseWrunRefusal(record) ?? record;
|
|
1141
|
+
}
|
|
1142
|
+
/** The seed `wrunRefusalFor` reads off a rejection (a cloud refusal by its code included). Never throws. */
|
|
1143
|
+
export function wrunRefusalSeedFor(error, ctx) {
|
|
1144
|
+
try {
|
|
1145
|
+
return seedOfError(error, ctx);
|
|
1146
|
+
}
|
|
1147
|
+
catch {
|
|
1148
|
+
return { cls: 'run-failed', variant: 'generic' };
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
/**
|
|
1152
|
+
* The completed record for a rejection (or a bare seed), against the chart's facts. Never throws.
|
|
1153
|
+
* Order: a record already annotated on the error; an attached (or bare) seed; a cloud refusal by its
|
|
1154
|
+
* code (`wrunCloudRefusalSeed`: a socket row source's whole-run refusal, or the code a cloud error
|
|
1155
|
+
* frame names; the cloud's no-candles answer -> waiting); the stable codes the browser lane prints
|
|
1156
|
+
* (`wrun_cell_block_too_large`, picking chain or block by the input's class; `wrun_options_chain_*`;
|
|
1157
|
+
* `wrun_pin_venue_refused`; the TPO letter check's words -> interval-unserved `at-most` on the
|
|
1158
|
+
* chart's own bars); `WrunNoBarsError` -> waiting; `WrunDeadlineError` -> not-reached;
|
|
1159
|
+
* an unseeded `WrunSourceDataUnavailableError` -> service-no-answer; else run-failed. A server answer
|
|
1160
|
+
* reads through the one answer table first (wrun-hosted-wire-caps): a superseded create's answer is the
|
|
1161
|
+
* `session-lost` note, one a second ask may pass keeps Retry. The record carries the raiser's telemetry
|
|
1162
|
+
* (stampWrunRefusalTelemetry) and `unknownCode` for a code the table has no row for.
|
|
1163
|
+
*/
|
|
1164
|
+
export function wrunRefusalFor(errorOrSeed, ctx) {
|
|
1165
|
+
let details = '';
|
|
1166
|
+
try {
|
|
1167
|
+
details = messageOf(errorOrSeed);
|
|
1168
|
+
const annotated = wrunRefusalOf(errorOrSeed);
|
|
1169
|
+
if (annotated)
|
|
1170
|
+
return annotated;
|
|
1171
|
+
const telemetry = wrunRefusalTelemetryOf(errorOrSeed);
|
|
1172
|
+
if (wrunServerAnswerOfText(details)?.unknownCode === true)
|
|
1173
|
+
telemetry.unknownCode = true;
|
|
1174
|
+
return buildRecord(seedOfError(errorOrSeed, ctx), ctx, details, telemetry);
|
|
1175
|
+
}
|
|
1176
|
+
catch {
|
|
1177
|
+
return {
|
|
1178
|
+
v: 1,
|
|
1179
|
+
cls: 'run-failed',
|
|
1180
|
+
variant: 'generic',
|
|
1181
|
+
indicatorName: typeof ctx?.indicatorName === 'string' ? ctx.indicatorName : '',
|
|
1182
|
+
params: {},
|
|
1183
|
+
severity: 'paused',
|
|
1184
|
+
out: { kind: 'retry' },
|
|
1185
|
+
details,
|
|
1186
|
+
};
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
function outLabelOf(out, t) {
|
|
1190
|
+
switch (out.kind) {
|
|
1191
|
+
case 'switch-market':
|
|
1192
|
+
return t('wrun.refusal.out.switchMarket', { market: out.label });
|
|
1193
|
+
case 'works-on':
|
|
1194
|
+
return t('wrun.refusal.out.worksOn');
|
|
1195
|
+
case 'try-interval':
|
|
1196
|
+
return t('wrun.refusal.out.tryInterval', { interval: out.interval });
|
|
1197
|
+
case 'open-settings':
|
|
1198
|
+
return t('wrun.refusal.out.openSettings');
|
|
1199
|
+
case 'retry':
|
|
1200
|
+
return t('indicatorStatus.card.retry');
|
|
1201
|
+
case 'resume-live':
|
|
1202
|
+
return t('wrun.refusal.out.resumeLive');
|
|
1203
|
+
case 'free-slots':
|
|
1204
|
+
return t('wrun.refusal.out.makeRoom');
|
|
1205
|
+
case 'go-to-line':
|
|
1206
|
+
return t('wrun.refusal.out.goToLine', { line: out.line });
|
|
1207
|
+
case 'open-editor':
|
|
1208
|
+
return t('kscript.legend.card.openInEditor');
|
|
1209
|
+
case 'run-on-chart':
|
|
1210
|
+
return t('wrun.refusal.out.runOnChart');
|
|
1211
|
+
case 'report':
|
|
1212
|
+
return t('wrunReport.legend.report');
|
|
1213
|
+
case 'reload':
|
|
1214
|
+
return t('dialogs.loadingTimeout.reloadApp');
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
/** The longest detail line a surface shows. */
|
|
1218
|
+
export const WRUN_REFUSAL_DETAIL_MAX = 160;
|
|
1219
|
+
/** The run-failed variants whose sentence cannot name the cause: their detail line says it. */
|
|
1220
|
+
const DETAIL_VARIANTS = new Set(['generic', 'code']);
|
|
1221
|
+
/**
|
|
1222
|
+
* The line a run-failed `generic` or `code` record shows under its sentence: the first line of the
|
|
1223
|
+
* raiser's text, trimmed, at most `WRUN_REFUSAL_DETAIL_MAX` characters. '' for every other record
|
|
1224
|
+
* (its sentence names the cause) and for a record without text.
|
|
1225
|
+
*/
|
|
1226
|
+
export function wrunRefusalDetailOf(r) {
|
|
1227
|
+
if (r.cls !== 'run-failed' || !DETAIL_VARIANTS.has(r.variant))
|
|
1228
|
+
return '';
|
|
1229
|
+
const line = firstLineOf(r.details);
|
|
1230
|
+
return line.length > WRUN_REFUSAL_DETAIL_MAX ? `${line.slice(0, WRUN_REFUSAL_DETAIL_MAX - 1).trimEnd()}\u2026` : line;
|
|
1231
|
+
}
|
|
1232
|
+
/**
|
|
1233
|
+
* The ONE text path: chip, sentence, OUT label and severity word of a record, in the injected
|
|
1234
|
+
* translate's locale, and its detail line (`wrunRefusalDetailOf`, the raiser's own words, never
|
|
1235
|
+
* translated). `name` and `market` render from the record when the variant does not carry
|
|
1236
|
+
* them as params; a `feed` param renders as its `wrun.refusal.feed.*` words; plural keys pass the
|
|
1237
|
+
* record's `count` / `n` as the plural choice. A note has no severity word.
|
|
1238
|
+
*/
|
|
1239
|
+
export function wrunRefusalTexts(r, t) {
|
|
1240
|
+
const spec = renderSpec(r);
|
|
1241
|
+
const named = {
|
|
1242
|
+
name: r.indicatorName,
|
|
1243
|
+
market: r.market?.label ?? '',
|
|
1244
|
+
...(spec === RUN_FAILED_GENERIC ? {} : r.params),
|
|
1245
|
+
};
|
|
1246
|
+
const feedKey = wrunRefusalFeedKey(named.feed);
|
|
1247
|
+
if (feedKey !== undefined)
|
|
1248
|
+
named.feed = t(feedKey);
|
|
1249
|
+
const choice = spec.plural === undefined ? undefined : r.params[spec.plural];
|
|
1250
|
+
const plural = typeof choice === 'number' && Number.isFinite(choice) ? choice : undefined;
|
|
1251
|
+
const render = (key) => (plural === undefined ? t(key, named) : t(key, named, plural));
|
|
1252
|
+
return {
|
|
1253
|
+
chip: render(spec.chip),
|
|
1254
|
+
sentence: render(spec.sentence),
|
|
1255
|
+
outLabel: outLabelOf(r.out, t),
|
|
1256
|
+
severityWord: r.severity === 'paused' ? t('wrun.refusal.severity.paused') : '',
|
|
1257
|
+
detail: wrunRefusalDetailOf(r),
|
|
1258
|
+
};
|
|
1259
|
+
}
|