@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,667 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The hosted wire's names, import-free: the wire capabilities every hosted wrun createScript
|
|
3
|
+
* advertises (one constant list, lane parity C4), the settings key that carries them from the main
|
|
4
|
+
* thread to the kScript socket worker, the run-level key a hosted-wire reply carries, the server
|
|
5
|
+
* capabilities the socket's `hello` frame advertises the other way, and the refusal an error frame
|
|
6
|
+
* names (its `details.wrunRefusal`, relayed across the worker boundary: "Refusals off an error
|
|
7
|
+
* frame" below). The socket worker and the boot graph read these and must never
|
|
8
|
+
* load the shared host (the kit's host entry, which only the seam `wrun-shared-host.ts` imports),
|
|
9
|
+
* so this file keeps its own literal copies of the package's names and imports nothing.
|
|
10
|
+
* `wrun-hosted-wire-caps.spec.ts` pins each literal, and the verdicts of `hasWrunHostedWire`,
|
|
11
|
+
* equal to the package's; `wrun-shared-host.boundary.spec.ts` keeps this file free of imports. See
|
|
12
|
+
* docs/features/kscript/wrun/wrun-browser-editor.md ("The host entry").
|
|
13
|
+
*/
|
|
14
|
+
/** The client capability for the hosted wire: every result and live frame of the instance carries
|
|
15
|
+
* one `wrunHost` key (the package's `WRUN_HOST_WIRE_CAP`). */
|
|
16
|
+
export const WRUN_HOST_WIRE_CAP = 'wrun-host-v1';
|
|
17
|
+
/** The client capability for displaced outputs (the package's `WRUN_DISPLACEMENT_WIRE_CAP`). The
|
|
18
|
+
* chart advertises it only beside `WRUN_HOST_WIRE_CAP`. */
|
|
19
|
+
export const WRUN_DISPLACEMENT_WIRE_CAP = 'wrun-displacement-v1';
|
|
20
|
+
/** The client capability for the batched sections (marks, spans, rays; the package's
|
|
21
|
+
* `WRUN_BATCHED_WIRE_CAP`, lane parity row 55): the cloud keeps the sections in the hosted wire's
|
|
22
|
+
* sheet and their data-only outputs in its rows, which the pass draws by index as it draws a
|
|
23
|
+
* browser run's. A server that does not deliver them (its hello lists no `wrun-batched-v1`)
|
|
24
|
+
* ignores the name and keeps refusing the family on the wire (`wrunHost.refusals`), which the pass
|
|
25
|
+
* already reads as a left-out row. The chart advertises it only beside `WRUN_HOST_WIRE_CAP`. */
|
|
26
|
+
export const WRUN_BATCHED_WIRE_CAP = 'wrun-batched-v1';
|
|
27
|
+
/** The client capability for the timed spans and rays (stride 5; the package's
|
|
28
|
+
* `WRUN_BATCHED_V2_WIRE_CAP`): a delivery gate like `WRUN_BATCHED_WIRE_CAP`. A server that
|
|
29
|
+
* delivers them lists `wrun-batched-v2` in its hello; without the cap the cloud refuses the timed
|
|
30
|
+
* family by name on the wire, and an older server refuses it at plan. The chart advertises it only
|
|
31
|
+
* beside `WRUN_HOST_WIRE_CAP`. */
|
|
32
|
+
export const WRUN_BATCHED_V2_WIRE_CAP = 'wrun-batched-v2';
|
|
33
|
+
/** The wire caps every hosted wrun run advertises beside `canonical-live-v1` (lane parity C4: the
|
|
34
|
+
* hosted wire is the one reply shape, no flag reads it), in the one fixed order: the hosted wire,
|
|
35
|
+
* then the displacement and the two batched sections caps beside it. The hosted createScript (the
|
|
36
|
+
* technical-script payload), Run once in Cloud and the Protected publish preflight's profile table
|
|
37
|
+
* all send or judge this list. */
|
|
38
|
+
export const WRUN_HOSTED_WIRE_CAPS = Object.freeze([
|
|
39
|
+
WRUN_HOST_WIRE_CAP,
|
|
40
|
+
WRUN_DISPLACEMENT_WIRE_CAP,
|
|
41
|
+
WRUN_BATCHED_WIRE_CAP,
|
|
42
|
+
WRUN_BATCHED_V2_WIRE_CAP,
|
|
43
|
+
]);
|
|
44
|
+
/** The settings key that carries the advertised caps from the main thread's request payload to
|
|
45
|
+
* the socket worker, which lifts it into `wireCaps` and strips it: it never rides the wire. */
|
|
46
|
+
export const WRUN_WIRE_CAPS_KEY = 'wrunWireCaps';
|
|
47
|
+
/** The run-level key a hosted-wire reply carries (the package's `WRUN_HOSTED_WIRE_KEY`). */
|
|
48
|
+
export const WRUN_HOSTED_WIRE_KEY = 'wrunHost';
|
|
49
|
+
/** The server capability (kscript-backend's `hello`, the first frame on every kScript socket, lists
|
|
50
|
+
* its caps under `serverCaps`) that admits a market picker's `EXCHANGE:SYMBOL` text in a hosted
|
|
51
|
+
* createScript's param map: the shared view resolves the pick from the text like the browser
|
|
52
|
+
* sheet does. A server that did not advertise it reads the param through Number() and refuses the
|
|
53
|
+
* text, so the map sends 0 to it (wrunHostedParamsOf). The server lists any later cap beside it. */
|
|
54
|
+
export const WRUN_SYMBOL_TEXT_SERVER_CAP = 'wrun-symbol-text-v1';
|
|
55
|
+
/** The server capability that admits the settings record (lane parity C4, its 10-12 rollout
|
|
56
|
+
* amendment): a hosted createScript sends the overlay's flat setting values over the sheet's params
|
|
57
|
+
* (`settings`, wrunHostedSettingsRecord) and the packed host fills (`hostFill`) instead of the
|
|
58
|
+
* numeric param map, the cloud resolves them through the SDK as the browser does, and a compute
|
|
59
|
+
* edit or a theme change rides `changeSettings` (C5) instead of a recreate. A socket whose hello did
|
|
60
|
+
* not name it gets the numeric map and today's recreate, so the chart and kscript-backend deploy in
|
|
61
|
+
* either order. */
|
|
62
|
+
export const WRUN_SETTINGS_SERVER_CAP = 'wrun-settings-v1';
|
|
63
|
+
/** The caps a hello's `serverCaps` holds: its non-empty strings, once each, in order; none for a
|
|
64
|
+
* value that is not an array. An unknown name is kept: a reader asks for the one cap it knows. */
|
|
65
|
+
export function readWrunServerCaps(value) {
|
|
66
|
+
if (!Array.isArray(value))
|
|
67
|
+
return [];
|
|
68
|
+
const caps = [];
|
|
69
|
+
for (const cap of value) {
|
|
70
|
+
if (typeof cap === 'string' && cap !== '' && !caps.includes(cap))
|
|
71
|
+
caps.push(cap);
|
|
72
|
+
}
|
|
73
|
+
return caps;
|
|
74
|
+
}
|
|
75
|
+
/** True when a socket's server caps admit a market picker's text in the hosted param map; none
|
|
76
|
+
* (a server that sent no hello, or a socket whose hello has not landed) admit nothing. */
|
|
77
|
+
export function wrunServerAdmitsSymbolText(serverCaps) {
|
|
78
|
+
return serverCaps?.includes(WRUN_SYMBOL_TEXT_SERVER_CAP) === true;
|
|
79
|
+
}
|
|
80
|
+
/** True when a socket's server caps admit the settings record and `changeSettings` for a hosted
|
|
81
|
+
* session (WRUN_SETTINGS_SERVER_CAP); none admit nothing. */
|
|
82
|
+
export function wrunServerAdmitsSettings(serverCaps) {
|
|
83
|
+
return serverCaps?.includes(WRUN_SETTINGS_SERVER_CAP) === true;
|
|
84
|
+
}
|
|
85
|
+
/** The known caps a carrier value holds, in the fixed order (WRUN_HOSTED_WIRE_CAPS). A value that is
|
|
86
|
+
* not an array reads as none; an unknown name or a repeat is dropped; the displacement and batched
|
|
87
|
+
* caps without the hosted wire cap are dropped too: they never ride alone. */
|
|
88
|
+
export function readWrunWireCaps(value) {
|
|
89
|
+
if (!Array.isArray(value) || !value.includes(WRUN_HOST_WIRE_CAP))
|
|
90
|
+
return [];
|
|
91
|
+
return WRUN_HOSTED_WIRE_CAPS.filter((cap) => value.includes(cap));
|
|
92
|
+
}
|
|
93
|
+
/** A carrier value as session identity: its known caps joined by a comma ('' for none). Two
|
|
94
|
+
* settings whose identities differ ask for different hosted sessions. */
|
|
95
|
+
export function wrunWireCapsIdentity(value) {
|
|
96
|
+
return readWrunWireCaps(value).join(',');
|
|
97
|
+
}
|
|
98
|
+
/** True for a record whose own `wrunHost` is a record with `v === 1`: the package's
|
|
99
|
+
* `hasWrunHostedWire`, verdict for verdict, without loading the package. */
|
|
100
|
+
export function hasWrunHostedWire(output) {
|
|
101
|
+
if (!isRecord(output) || !Object.hasOwn(output, WRUN_HOSTED_WIRE_KEY))
|
|
102
|
+
return false;
|
|
103
|
+
const value = output[WRUN_HOSTED_WIRE_KEY];
|
|
104
|
+
return isRecord(value) && value.v === 1;
|
|
105
|
+
}
|
|
106
|
+
function isRecord(value) {
|
|
107
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
108
|
+
}
|
|
109
|
+
/** The chart's name for the one answer kscript-backend still words without a code: its own fetch of
|
|
110
|
+
* the chart's market returned no candles in the asked window (wrun-lane.ts `transientDataFailure`,
|
|
111
|
+
* answered INTERNAL, so it keeps its retry). Read as a code here, the one sentence this leaf knows, so
|
|
112
|
+
* every reader past it reads codes only (row 37: the same `waiting` record as the browser lane's no
|
|
113
|
+
* bars). Retired once the backend codes the answer. */
|
|
114
|
+
export const WRUN_NO_CANDLES_CODE = 'wrun_no_candles';
|
|
115
|
+
/** The kit's code spelling: no reader accepts any other word as a code. */
|
|
116
|
+
const REFUSAL_CODE = /^wrun_[a-z0-9_]+$/;
|
|
117
|
+
/** The trailer's opening; the JSON of the details follows, then the closing parenthesis. */
|
|
118
|
+
const REFUSAL_TRAILER_OPEN = ' (wrun-refusal: ';
|
|
119
|
+
/** A wrun error frame as the socket worker rethrows it (`[<frame code>] WRUN <package>@<version>:
|
|
120
|
+
* <sentence>`): `$1` the frame's own code, `$2` the sentence and whatever trails it. */
|
|
121
|
+
const WRUN_FRAME = /\[([A-Z][A-Z_]*)\] WRUN \S+@[^\s@:]+: ([\s\S]*)$/;
|
|
122
|
+
/** The kit's code a sentence leads with (`wrunRefusalMessage` writes `<code>: <sentence>`). */
|
|
123
|
+
const LEADING_CODE = /^(wrun_[a-z0-9_]+):/;
|
|
124
|
+
/** The no-candles answer's words (see WRUN_NO_CANDLES_CODE): its head and the clause after the
|
|
125
|
+
* market token (a memecoin symbol carries `/` and `:`, so the token is never parsed). */
|
|
126
|
+
const NO_CANDLES_HEAD = 'no candles for ';
|
|
127
|
+
const NO_CANDLES_TAIL = " (the chart's market) in the requested range";
|
|
128
|
+
/** The details' known keys and their types; any other key never crosses. */
|
|
129
|
+
const FRAME_REFUSAL_STRINGS = ['where', 'input', 'family', 'value'];
|
|
130
|
+
const FRAME_REFUSAL_NUMBERS = ['count', 'limit'];
|
|
131
|
+
/** A value read as a frame refusal: a record with a coded `code`, its known keys kept by type. */
|
|
132
|
+
function frameRefusalOf(value) {
|
|
133
|
+
if (!isRecord(value) || typeof value.code !== 'string' || !REFUSAL_CODE.test(value.code))
|
|
134
|
+
return undefined;
|
|
135
|
+
const refusal = { code: value.code };
|
|
136
|
+
for (const key of FRAME_REFUSAL_STRINGS) {
|
|
137
|
+
const field = value[key];
|
|
138
|
+
if (typeof field === 'string' && field !== '')
|
|
139
|
+
refusal[key] = field;
|
|
140
|
+
}
|
|
141
|
+
for (const key of FRAME_REFUSAL_NUMBERS) {
|
|
142
|
+
const field = value[key];
|
|
143
|
+
if (typeof field === 'number' && Number.isFinite(field))
|
|
144
|
+
refusal[key] = field;
|
|
145
|
+
}
|
|
146
|
+
return refusal;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The trailer the kScript socket worker appends to an error frame's rethrown message when the frame's
|
|
150
|
+
* `details.wrunRefusal` names a coded refusal: ` (wrun-refusal: {"code":...})`, the details' known keys
|
|
151
|
+
* as JSON (wrunFrameRefusalOf reads it back); '' for any other frame.
|
|
152
|
+
*/
|
|
153
|
+
export function wrunRefusalTrailer(details) {
|
|
154
|
+
const refusal = isRecord(details) ? frameRefusalOf(details.wrunRefusal) : undefined;
|
|
155
|
+
return refusal === undefined ? '' : `${REFUSAL_TRAILER_OPEN}${JSON.stringify(refusal)})`;
|
|
156
|
+
}
|
|
157
|
+
/** The trailer's refusal, when the text ends with one. */
|
|
158
|
+
function trailerRefusalOf(text) {
|
|
159
|
+
const at = text.lastIndexOf(REFUSAL_TRAILER_OPEN);
|
|
160
|
+
if (at < 0 || !text.endsWith(')'))
|
|
161
|
+
return undefined;
|
|
162
|
+
try {
|
|
163
|
+
return frameRefusalOf(JSON.parse(text.slice(at + REFUSAL_TRAILER_OPEN.length, -1)));
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/** The own code of a wrun error frame (`[BAD_REQUEST]`, `[SOURCE_UNSUPPORTED]`, `[INTERNAL]`), or
|
|
170
|
+
* undefined for a text that is no wrun frame (a frame that names no package, the connection's
|
|
171
|
+
* instance cap among them, is none). */
|
|
172
|
+
export function wrunErrorFrameCodeOf(text) {
|
|
173
|
+
return WRUN_FRAME.exec(text)?.[1];
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* The refusal an error text names: the details the socket worker relayed (wrunRefusalTrailer); else,
|
|
177
|
+
* on a wrun frame of an older server, the kit's code its sentence leads with; else the no-candles
|
|
178
|
+
* answer by its name (WRUN_NO_CANDLES_CODE). Undefined for anything else: a frame without a code
|
|
179
|
+
* keeps its frame code alone (wrunErrorFrameCodeOf).
|
|
180
|
+
*/
|
|
181
|
+
export function wrunFrameRefusalOf(text) {
|
|
182
|
+
const relayed = trailerRefusalOf(text);
|
|
183
|
+
if (relayed !== undefined)
|
|
184
|
+
return relayed;
|
|
185
|
+
const sentence = WRUN_FRAME.exec(text)?.[2];
|
|
186
|
+
if (sentence === undefined)
|
|
187
|
+
return undefined;
|
|
188
|
+
const leading = LEADING_CODE.exec(sentence)?.[1];
|
|
189
|
+
if (leading !== undefined)
|
|
190
|
+
return { code: leading };
|
|
191
|
+
return sentence.startsWith(NO_CANDLES_HEAD) && sentence.includes(NO_CANDLES_TAIL)
|
|
192
|
+
? { code: WRUN_NO_CANDLES_CODE }
|
|
193
|
+
: undefined;
|
|
194
|
+
}
|
|
195
|
+
/** The connection's caps (the socket's other Indicators hold the room, which returns when one leaves) and the
|
|
196
|
+
* no-candles answer (an empty history answer can be a transient truncation): retried, whatever the frame code. */
|
|
197
|
+
const RETRIED_REFUSALS = new Set([
|
|
198
|
+
'wrun_foreign_sources_over_cap',
|
|
199
|
+
'wrun_instances_over_cap',
|
|
200
|
+
WRUN_NO_CANDLES_CODE,
|
|
201
|
+
]);
|
|
202
|
+
/** Refusals sized by the asked window: a smaller window may pass. */
|
|
203
|
+
const WINDOW_SIZED_REFUSALS = new Set(['wrun_window_too_large', 'wrun_pinned_cells_over_cap']);
|
|
204
|
+
/** Refusals of a fixed property of the request (its sheet, its settings, the package's own fan-out, the
|
|
205
|
+
* cloud profile's own refusal of a declared input source class or family, which a create answers
|
|
206
|
+
* BAD_REQUEST: EJpGr1ba 2026-10-13): the same request buys the same answer. */
|
|
207
|
+
const IDENTITY_REFUSALS = new Set([
|
|
208
|
+
'wrun_intrabar_leg_not_finer',
|
|
209
|
+
'wrun_params_invalid',
|
|
210
|
+
'wrun_settings_paint_unsupported',
|
|
211
|
+
'wrun_param_unknown',
|
|
212
|
+
'wrun_secondary_keys_over_cap',
|
|
213
|
+
'wrun_source_unsupported',
|
|
214
|
+
'wrun_family_unsupported',
|
|
215
|
+
]);
|
|
216
|
+
/** The lane's own refusal codes the kit's table does not hold (kscript-backend wrun-lane.ts, wrun-plan.ts): known,
|
|
217
|
+
* so none of them reads as an unknown code. `wrun_book_unavailable` is raised at align (it turns on the data). */
|
|
218
|
+
const LANE_REFUSALS = new Set([
|
|
219
|
+
...RETRIED_REFUSALS,
|
|
220
|
+
...WINDOW_SIZED_REFUSALS,
|
|
221
|
+
...IDENTITY_REFUSALS,
|
|
222
|
+
'wrun_book_unavailable',
|
|
223
|
+
'wrun_rebind_busy',
|
|
224
|
+
]);
|
|
225
|
+
/** The hosted-support decision codes a create is refused with (the contracts' WrunSupportCode list): shown. */
|
|
226
|
+
const SHOWN_ELIGIBILITY_CODES = new Set([
|
|
227
|
+
'EXECUTION_NOT_HOSTED',
|
|
228
|
+
'ABI_UNSUPPORTED',
|
|
229
|
+
'OUTPUT_UNSUPPORTED',
|
|
230
|
+
'PARAM_UNSUPPORTED',
|
|
231
|
+
'METADATA_UNSUPPORTED',
|
|
232
|
+
'CONTEXT_UNSUPPORTED',
|
|
233
|
+
'WIRE_CAP_REQUIRED',
|
|
234
|
+
'SUPPORT_LIMIT_EXCEEDED',
|
|
235
|
+
'SUPPORT_REFUSED',
|
|
236
|
+
]);
|
|
237
|
+
/** The support protocol's own refusals (an Enterprise support request the server cannot admit): fatal. */
|
|
238
|
+
const SUPPORT_PROTOCOL_CODES = new Set([
|
|
239
|
+
'SUPPORT_PROFILE_MISMATCH',
|
|
240
|
+
'SUPPORT_REQUEST_INVALID',
|
|
241
|
+
'SUPPORT_BINDING_MISSING',
|
|
242
|
+
'SUPPORT_BINDING_MISMATCH',
|
|
243
|
+
]);
|
|
244
|
+
/** Run once in Cloud's refusals (a `wrunTestRun` answer, read by its reason, never on the request path). */
|
|
245
|
+
const TEST_RUN_REFUSALS = new Set([
|
|
246
|
+
'wrun-test-run-bad-window',
|
|
247
|
+
'wrun-test-run-disabled',
|
|
248
|
+
'wrun-test-run-invalid-module',
|
|
249
|
+
'wrun-test-run-limit',
|
|
250
|
+
'wrun-test-run-too-large',
|
|
251
|
+
'wrun-test-run-unsupported',
|
|
252
|
+
]);
|
|
253
|
+
/** The kit stages that read no data: a second try of the same ask buys the same answer. */
|
|
254
|
+
const FIXED_KIT_STAGES = new Set(['validate', 'plan', 'shape']);
|
|
255
|
+
const codes = (...names) => new Set(names);
|
|
256
|
+
/**
|
|
257
|
+
* The table, first match wins, one row per answer of kscript-backend's catalog. The order keeps the precedence
|
|
258
|
+
* the readers kept before it existed: a superseded create first; the answers off the request path by their
|
|
259
|
+
* reason; the retried refusals on any frame; `INTERNAL` and `FORBIDDEN` over any refusal they carry; the
|
|
260
|
+
* remembered refusals; an eligibility frame over the kit's stage of a refusal it carries; the kit's stages; then
|
|
261
|
+
* the uncoded frames by code and sentence, and the fallback.
|
|
262
|
+
*/
|
|
263
|
+
const WRUN_SERVER_ANSWER_ROWS = [
|
|
264
|
+
// A create the server superseded: the reason a newer server names, else the sentence it answers with.
|
|
265
|
+
{ id: 'superseded', verdict: 'stale', reason: 'superseded' },
|
|
266
|
+
{
|
|
267
|
+
id: 'superseded-run',
|
|
268
|
+
verdict: 'stale',
|
|
269
|
+
codes: codes('BAD_REQUEST'),
|
|
270
|
+
message: /^WRUN \S+@[^\s@:]+: create was superseded$/,
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
id: 'superseded-preflight',
|
|
274
|
+
verdict: 'stale',
|
|
275
|
+
codes: codes('BAD_REQUEST'),
|
|
276
|
+
message: /^Script create was superseded\.$/,
|
|
277
|
+
},
|
|
278
|
+
// Answers off the request path, by their reason: the Enterprise source withdrawal, Run once in Cloud.
|
|
279
|
+
{ id: 'source-withdrawn', verdict: 'show', reason: 'source-access-withdrawn' },
|
|
280
|
+
{ id: 'test-run-busy', verdict: 'retry', reason: 'wrun-test-run-busy' },
|
|
281
|
+
{ id: 'test-run', verdict: 'show', reason: TEST_RUN_REFUSALS },
|
|
282
|
+
{ id: 'no-candles', verdict: 'retry', refusal: codes(WRUN_NO_CANDLES_CODE) },
|
|
283
|
+
{ id: 'tab-full', verdict: 'retry', refusal: codes('wrun_foreign_sources_over_cap', 'wrun_instances_over_cap') },
|
|
284
|
+
{ id: 'rebind-busy', verdict: 'retry', refusal: codes('wrun_rebind_busy') },
|
|
285
|
+
{ id: 'internal', verdict: 'retry', codes: codes('INTERNAL') },
|
|
286
|
+
// The run gate's capability deny (the sweep's and a create's): the fetch's one forced re-mint retries it.
|
|
287
|
+
{ id: 'capability-denied', verdict: 'retry', codes: codes('FORBIDDEN'), reason: 'capability-invalid' },
|
|
288
|
+
{
|
|
289
|
+
id: 'capability-denied-words',
|
|
290
|
+
verdict: 'retry',
|
|
291
|
+
codes: codes('FORBIDDEN'),
|
|
292
|
+
message: /^Forbidden: capability invalid, expired, or insufficient for this script\.$/,
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
id: 'enterprise-principal',
|
|
296
|
+
verdict: 'fatal',
|
|
297
|
+
codes: codes('FORBIDDEN'),
|
|
298
|
+
message: /^The WRun support protocol requires a verified Enterprise principal\.$/,
|
|
299
|
+
},
|
|
300
|
+
// Any other FORBIDDEN (market data the account may not read, a refusal under it): shown, never remembered.
|
|
301
|
+
{ id: 'forbidden', verdict: 'show', codes: codes('FORBIDDEN') },
|
|
302
|
+
{ id: 'window-sized', verdict: 'show', refusal: WINDOW_SIZED_REFUSALS, memory: 'window' },
|
|
303
|
+
{ id: 'identity', verdict: 'show', refusal: IDENTITY_REFUSALS, memory: 'identity' },
|
|
304
|
+
{ id: 'source-unsupported', verdict: 'show', codes: codes('SOURCE_UNSUPPORTED'), memory: 'identity' },
|
|
305
|
+
{ id: 'eligibility', verdict: 'show', codes: SHOWN_ELIGIBILITY_CODES },
|
|
306
|
+
{ id: 'support-protocol', verdict: 'fatal', codes: SUPPORT_PROTOCOL_CODES },
|
|
307
|
+
{ id: 'coded', verdict: 'show', refusal: 'known' },
|
|
308
|
+
{ id: 'coded-unknown', verdict: 'show', refusal: 'any', unknownCode: true },
|
|
309
|
+
// Uncoded frames, by code and sentence. A request the server cannot read is fatal.
|
|
310
|
+
{
|
|
311
|
+
id: 'malformed-request',
|
|
312
|
+
verdict: 'fatal',
|
|
313
|
+
codes: codes('BAD_REQUEST'),
|
|
314
|
+
message: /^(?:Bad request: missing or invalid fields in the payload|Invalid WRun support request|Invalid script ID format|Invalid timestamps)\.$/,
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
id: 'latest-too-large',
|
|
318
|
+
verdict: 'fatal',
|
|
319
|
+
codes: codes('BAD_REQUEST'),
|
|
320
|
+
message: /(?:^|: )wrun_latest_envelope_too_large$/,
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
id: 'bad-request-transient',
|
|
324
|
+
verdict: 'retry',
|
|
325
|
+
codes: codes('BAD_REQUEST'),
|
|
326
|
+
message: /^(?:Rate limit exceeded\. Try again later\.|Script session not found\. Please create the script first!|createScript already in progress; retry shortly\.)$/,
|
|
327
|
+
},
|
|
328
|
+
{ id: 'latest-busy', verdict: 'retry', codes: codes('BAD_REQUEST'), message: /(?:^|: )wrun_latest_context_busy$/ },
|
|
329
|
+
// Every other BAD_REQUEST is a refusal shown as it came: the venue wall, the interval refusal, the instance cap,
|
|
330
|
+
// a backend without wrun, a lane failure of the run named by its words.
|
|
331
|
+
{ id: 'bad-request', verdict: 'show', codes: codes('BAD_REQUEST') },
|
|
332
|
+
{ id: 'token-expired', verdict: 'retry', codes: codes('UNAUTHORIZED'), message: /^Invalid or expired token\.$/ },
|
|
333
|
+
{ id: 'unauthorized', verdict: 'show', codes: codes('UNAUTHORIZED') },
|
|
334
|
+
{ id: 'script-timeout', verdict: 'show', codes: codes('SCRIPT_TIMEOUT') },
|
|
335
|
+
{ id: 'protocol', verdict: 'fatal', codes: codes('NOT_FOUND', 'TIME_RANGE_INVALID', 'UNKNOWN_MESSAGE') },
|
|
336
|
+
];
|
|
337
|
+
/** The answer for a frame code no row knows: a refusal shown with its code. */
|
|
338
|
+
const UNKNOWN_CODE_ROW = { id: 'unknown-code', verdict: 'show', unknownCode: true };
|
|
339
|
+
function textOf(value) {
|
|
340
|
+
return typeof value === 'string' && value !== '' ? value : undefined;
|
|
341
|
+
}
|
|
342
|
+
function refusalMatches(match, code) {
|
|
343
|
+
if (match === 'any')
|
|
344
|
+
return true;
|
|
345
|
+
if (match === 'known')
|
|
346
|
+
return wrunKitRefusalStageOf(code) !== undefined || LANE_REFUSALS.has(code);
|
|
347
|
+
return match.has(code);
|
|
348
|
+
}
|
|
349
|
+
function rowMatches(row, frameCode, reason, message, refusal) {
|
|
350
|
+
if (row.codes !== undefined && (frameCode === undefined || !row.codes.has(frameCode)))
|
|
351
|
+
return false;
|
|
352
|
+
if (row.reason !== undefined) {
|
|
353
|
+
if (reason === undefined)
|
|
354
|
+
return false;
|
|
355
|
+
if (typeof row.reason === 'string' ? reason !== row.reason : !row.reason.has(reason))
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
358
|
+
if (row.message !== undefined && !row.message.test(message))
|
|
359
|
+
return false;
|
|
360
|
+
if (row.refusal !== undefined && (refusal === undefined || !refusalMatches(row.refusal, refusal.code)))
|
|
361
|
+
return false;
|
|
362
|
+
return true;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* The verdict of one error frame (see the table above): undefined for a value that names neither a frame code
|
|
366
|
+
* nor a coded refusal (no server answer at all). A frame code no row knows answers `show` with `unknownCode`.
|
|
367
|
+
*/
|
|
368
|
+
export function wrunServerAnswerVerdict(frame) {
|
|
369
|
+
const frameCode = textOf(frame.code);
|
|
370
|
+
const details = isRecord(frame.details) ? frame.details : undefined;
|
|
371
|
+
const reason = textOf(details?.reason) ?? textOf(frame.reason);
|
|
372
|
+
const message = textOf(frame.message) ?? '';
|
|
373
|
+
const relayed = frameRefusalOf(details?.wrunRefusal);
|
|
374
|
+
const refusal = relayed ?? (frameCode !== undefined ? sentenceRefusalOf(message) : undefined);
|
|
375
|
+
if (frameCode === undefined && refusal === undefined && reason === undefined)
|
|
376
|
+
return undefined;
|
|
377
|
+
const row = WRUN_SERVER_ANSWER_ROWS.find((candidate) => rowMatches(candidate, frameCode, reason, message, refusal)) ??
|
|
378
|
+
UNKNOWN_CODE_ROW;
|
|
379
|
+
const answer = { verdict: row.verdict, row: row.id };
|
|
380
|
+
if (frameCode !== undefined)
|
|
381
|
+
answer.frameCode = frameCode;
|
|
382
|
+
if (refusal !== undefined)
|
|
383
|
+
answer.refusal = refusal;
|
|
384
|
+
const said = reason ?? (row.verdict === 'stale' ? 'superseded' : undefined);
|
|
385
|
+
if (said !== undefined)
|
|
386
|
+
answer.reason = said;
|
|
387
|
+
if (row.memory !== undefined)
|
|
388
|
+
answer.memory = row.memory;
|
|
389
|
+
const stage = refusal !== undefined ? wrunKitRefusalStageOf(refusal.code) : undefined;
|
|
390
|
+
if (row.memory !== undefined || (stage !== undefined && FIXED_KIT_STAGES.has(stage)))
|
|
391
|
+
answer.repeats = true;
|
|
392
|
+
if (row.unknownCode === true)
|
|
393
|
+
answer.unknownCode = true;
|
|
394
|
+
return answer;
|
|
395
|
+
}
|
|
396
|
+
/** The refusal a sentence names on its own: the kit's leading code, else the no-candles answer. */
|
|
397
|
+
function sentenceRefusalOf(message) {
|
|
398
|
+
const sentence = WRUN_FRAME_SENTENCE.exec(message)?.[1];
|
|
399
|
+
if (sentence === undefined)
|
|
400
|
+
return undefined;
|
|
401
|
+
const leading = LEADING_CODE.exec(sentence)?.[1];
|
|
402
|
+
if (leading !== undefined)
|
|
403
|
+
return { code: leading };
|
|
404
|
+
return sentence.startsWith(NO_CANDLES_HEAD) && sentence.includes(NO_CANDLES_TAIL)
|
|
405
|
+
? { code: WRUN_NO_CANDLES_CODE }
|
|
406
|
+
: undefined;
|
|
407
|
+
}
|
|
408
|
+
/** A wrun frame's sentence as the server wrote it: `$1` past `WRUN <package>@<version>: `. */
|
|
409
|
+
const WRUN_FRAME_SENTENCE = /^WRUN \S+@[^\s@:]+: ([\s\S]*)$/;
|
|
410
|
+
/** A rethrown error text's frame code: the socket worker writes `KScript error: [<code>] <sentence>` (a result
|
|
411
|
+
* carrying an error, `KScript result error: ...`), so only a code behind that head is one (a browser run's own
|
|
412
|
+
* words never read as a server answer); `$2` is the rest. */
|
|
413
|
+
const RETHROWN_FRAME = /^KScript (?:result )?error: \[([A-Z][A-Z0-9_]*)\] ([\s\S]*)$/;
|
|
414
|
+
/** The interval refusal's trailer (kscript-interval-refusal.util), named or not. */
|
|
415
|
+
const INTERVAL_TRAILER = / \(interval-unsupported(?:: [0-9A-Za-z]{1,16})?\)$/;
|
|
416
|
+
/**
|
|
417
|
+
* The verdict of an error text past the socket worker (only text crosses the worker boundary): the frame code at
|
|
418
|
+
* its head (or a wrun frame's anywhere in it), its sentence less the trailers the worker appended, the refusal
|
|
419
|
+
* the wrun trailer relays and the interval refusal's reason. Undefined for a text that is no server answer.
|
|
420
|
+
*/
|
|
421
|
+
export function wrunServerAnswerOfText(text) {
|
|
422
|
+
const relayed = trailerRefusalOf(text);
|
|
423
|
+
let body = relayed !== undefined ? text.slice(0, text.lastIndexOf(REFUSAL_TRAILER_OPEN)) : text;
|
|
424
|
+
const interval = INTERVAL_TRAILER.test(body);
|
|
425
|
+
if (interval)
|
|
426
|
+
body = body.replace(INTERVAL_TRAILER, '');
|
|
427
|
+
const head = RETHROWN_FRAME.exec(body);
|
|
428
|
+
const wrun = head === null ? WRUN_FRAME.exec(body) : null;
|
|
429
|
+
const frameCode = head?.[1] ?? wrun?.[1];
|
|
430
|
+
// A wrun frame inside a longer text: its sentence starts past `[<code>] `.
|
|
431
|
+
const message = head?.[2] ?? (wrun !== null ? body.slice(wrun.index + wrun[1].length + 3) : '');
|
|
432
|
+
return wrunServerAnswerVerdict({
|
|
433
|
+
code: frameCode,
|
|
434
|
+
message,
|
|
435
|
+
details: relayed !== undefined ? { wrunRefusal: relayed } : undefined,
|
|
436
|
+
reason: interval ? 'interval-unsupported' : undefined,
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* How a refused wrun ask is remembered (the protected worker control's create memory, the socket
|
|
441
|
+
* worker's settings memory, the socket row source's whole-run refusal): the answer table's `memory`
|
|
442
|
+
* (wrunServerAnswerVerdict) of a wrun frame: `window` for a refusal sized by the asked window, `identity`
|
|
443
|
+
* for one of a fixed property of the request or any eligibility frame (`[SOURCE_UNSUPPORTED]` and its
|
|
444
|
+
* siblings), null for everything else (a transient frame code, `[INTERNAL]` or `[FORBIDDEN]`, a retried
|
|
445
|
+
* refusal, a text that is no wrun frame).
|
|
446
|
+
*/
|
|
447
|
+
export function wrunFrameRefusalMemory(text) {
|
|
448
|
+
if (wrunErrorFrameCodeOf(text) === undefined)
|
|
449
|
+
return null;
|
|
450
|
+
return wrunServerAnswerOfText(text)?.memory ?? null;
|
|
451
|
+
}
|
|
452
|
+
// ── The kit's refusal stages ─────────────────────────────────────────────────────────────────────
|
|
453
|
+
/**
|
|
454
|
+
* The stage the kit's shared host raises each refusal it names at (`WRUN_HOST_REFUSALS[code].where`,
|
|
455
|
+
* packages/sdk/src/wrun-host/refusals.ts, shipped in `@orangecharts/indicator-kit/host`), in the kit's
|
|
456
|
+
* own order: validate reads the sheet, plan the sheet against the chart and the host, shape the
|
|
457
|
+
* module's own output; pack reads the fetched rows' cell blocks and align the fetched series, so their
|
|
458
|
+
* refusals turn on the window's data. Mirrored because host.js stays out of the boot graph
|
|
459
|
+
* (wrun-shared-host.ts) and the answer table above answers synchronously, in the socket worker too (this
|
|
460
|
+
* leaf imports nothing; wrun-refusal.util re-exports it); tests/utility/wrun/wrun-refusal.cloud.spec.ts
|
|
461
|
+
* holds it to the installed kit's table code by code, so a kit bump that adds or moves a code fails there
|
|
462
|
+
* by name.
|
|
463
|
+
*/
|
|
464
|
+
export const WRUN_KIT_REFUSAL_STAGES = {
|
|
465
|
+
validate: [
|
|
466
|
+
'wrun_abi_unsupported',
|
|
467
|
+
// kit 0.65.0: a pin on a venue word no lane can ask (the chart's main bumped the kit 10-12).
|
|
468
|
+
'wrun_pin_venue_unknown',
|
|
469
|
+
'wrun_sheet_over_cap',
|
|
470
|
+
'wrun_abi_channel_missing',
|
|
471
|
+
'wrun_intrabar_interval_required',
|
|
472
|
+
'wrun_intrabar_primary',
|
|
473
|
+
'wrun_candles_interval_required',
|
|
474
|
+
'wrun_candles_primary',
|
|
475
|
+
'wrun_options_chain_venue',
|
|
476
|
+
'wrun_options_chain_expiries',
|
|
477
|
+
'wrun_options_chain_market_pinned',
|
|
478
|
+
'wrun_offset_needs_view',
|
|
479
|
+
'wrun_offset_count_required',
|
|
480
|
+
'wrun_bars_needs_leg',
|
|
481
|
+
// kit 0.74.0: `chart_interval_below` on a source other than candles, on the primary input, or beside
|
|
482
|
+
// view "forming" (scaffold 74, WRUN-LANE-INTERVAL-GATE).
|
|
483
|
+
'wrun_chart_interval_below_needs_candles',
|
|
484
|
+
'wrun_chart_interval_below_primary',
|
|
485
|
+
'wrun_chart_interval_below_forming',
|
|
486
|
+
'wrun_pin_venue_refused',
|
|
487
|
+
'wrun_pin_symbol_literal',
|
|
488
|
+
'wrun_tape_history_unavailable',
|
|
489
|
+
'wrun_strategy_feed_not_ohlcv',
|
|
490
|
+
'wrun_strategy_slippage_model_unsupported',
|
|
491
|
+
'wrun_strategy_reserved_output',
|
|
492
|
+
'wrun_tape_min_size_invalid',
|
|
493
|
+
],
|
|
494
|
+
plan: [
|
|
495
|
+
'wrun_options_coin_unknown',
|
|
496
|
+
'wrun_source_unsupported',
|
|
497
|
+
'wrun_field_unsupported',
|
|
498
|
+
'wrun_tenor_unsupported',
|
|
499
|
+
'wrun_view_unsupported',
|
|
500
|
+
'wrun_family_unsupported',
|
|
501
|
+
'wrun_displacement_needs_cap',
|
|
502
|
+
'wrun_options_chain_venue_unavailable',
|
|
503
|
+
'wrun_options_chain_unavailable',
|
|
504
|
+
'wrun_options_chain_one_venue',
|
|
505
|
+
'wrun_lane_input_refused',
|
|
506
|
+
'wrun_permission_denied',
|
|
507
|
+
// kit 0.78.1: a coin leg the host cannot serve, or whose coin resolves to no market (kit 0.77.0's coin legs).
|
|
508
|
+
'wrun_coin_leg_unsupported',
|
|
509
|
+
'wrun_coin_leg_unresolved',
|
|
510
|
+
'wrun_pin_unsupported',
|
|
511
|
+
'wrun_custom_interval_unsupported',
|
|
512
|
+
'wrun_intrabar_leg_off_grid',
|
|
513
|
+
'wrun_intrabar_ratio_over_cap',
|
|
514
|
+
'wrun_intrabar_unsupported',
|
|
515
|
+
'wrun_candles_bars_over_cap',
|
|
516
|
+
'wrun_candles_ratio_over_cap',
|
|
517
|
+
'wrun_trade_volume_by_size_unsupported',
|
|
518
|
+
'wrun_view_leg_off_grid',
|
|
519
|
+
'wrun_view_leg_equal',
|
|
520
|
+
'wrun_time_facts_unsupported',
|
|
521
|
+
'wrun_etf_flow_unsupported',
|
|
522
|
+
'wrun_volatility_index_unsupported',
|
|
523
|
+
'wrun_long_short_ratio_unsupported',
|
|
524
|
+
'wrun_options_oi_unsupported',
|
|
525
|
+
'wrun_options_volume_unsupported',
|
|
526
|
+
'wrun_ethena_positions_unsupported',
|
|
527
|
+
'wrun_etf_holdings_unsupported',
|
|
528
|
+
'wrun_etf_premium_unsupported',
|
|
529
|
+
'wrun_economic_unsupported',
|
|
530
|
+
'wrun_treasury_balance_unsupported',
|
|
531
|
+
'wrun_bitfinex_funding_unsupported',
|
|
532
|
+
'wrun_strategy_costs_in_sheet',
|
|
533
|
+
'wrun_window_bars_invalid',
|
|
534
|
+
'wrun_cells_unavailable',
|
|
535
|
+
'wrun_tape_unavailable',
|
|
536
|
+
'wrun_tape_interval_unsupported',
|
|
537
|
+
'wrun_metric_source_missing_policy',
|
|
538
|
+
'wrun_series_source_primary',
|
|
539
|
+
'wrun_series_source_densification',
|
|
540
|
+
'wrun_metric_pin_coarser_than_primary',
|
|
541
|
+
'wrun_forming_primary_not_own_candles',
|
|
542
|
+
'wrun_package_lock_invalid',
|
|
543
|
+
'wrun_package_lock_missing',
|
|
544
|
+
'wrun_package_not_installed',
|
|
545
|
+
'wrun_package_lock_mismatch',
|
|
546
|
+
'wrun_composition_cycle',
|
|
547
|
+
'wrun_composition_depth',
|
|
548
|
+
'wrun_options_chain_unsupported',
|
|
549
|
+
'wrun_volume_profile_ticks_unsupported',
|
|
550
|
+
'wrun_celled_metric_unsupported',
|
|
551
|
+
'wrun_series_source_missing',
|
|
552
|
+
'wrun_series_source_invalid',
|
|
553
|
+
'wrun_params_invalid',
|
|
554
|
+
'wrun_source_bindings_invalid',
|
|
555
|
+
'wrun_output_displaced',
|
|
556
|
+
// kit 0.78.1: a pin that names no market the host serves, even respelled (resolveWrunPinMarket).
|
|
557
|
+
'wrun_pin_unresolvable',
|
|
558
|
+
],
|
|
559
|
+
shape: [
|
|
560
|
+
'wrun_draw_kind_limit',
|
|
561
|
+
'wrun_draw_total_limit',
|
|
562
|
+
'wrun_draw_polyline_too_large',
|
|
563
|
+
'wrun_draw_calls_per_row',
|
|
564
|
+
'wrun_render_result_too_large',
|
|
565
|
+
'wrun_draw_kind_mismatch',
|
|
566
|
+
'wrun_draw_handle_missing',
|
|
567
|
+
'wrun_draw_label_slot_absent',
|
|
568
|
+
'wrun_draw_non_finite',
|
|
569
|
+
'wrun_draw_phase',
|
|
570
|
+
'wrun_draw_id_negative',
|
|
571
|
+
'wrun_draw_kind_undeclared',
|
|
572
|
+
'wrun_draw_prop_unknown',
|
|
573
|
+
'wrun_draw_prop_unsupported',
|
|
574
|
+
'wrun_draw_style_out_of_range',
|
|
575
|
+
'wrun_draw_polyline_empty',
|
|
576
|
+
'wrun_draw_polyline_out_of_bounds',
|
|
577
|
+
'wrun_draw_label_slot_undeclared',
|
|
578
|
+
'wrun_draw_polyline_budget',
|
|
579
|
+
'wrun_strategy_id_limit',
|
|
580
|
+
'wrun_strategy_id_too_long',
|
|
581
|
+
'wrun_strategy_id_invalid_utf8',
|
|
582
|
+
'wrun_strategy_calls_per_row',
|
|
583
|
+
'wrun_strategy_trade_limit',
|
|
584
|
+
'wrun_strategy_non_finite',
|
|
585
|
+
'wrun_strategy_bad_direction',
|
|
586
|
+
'wrun_strategy_not_declared',
|
|
587
|
+
'wrun_strategy_phase',
|
|
588
|
+
'wrun_strategy_id_out_of_bounds',
|
|
589
|
+
'wrun_text_param_phase',
|
|
590
|
+
'wrun_text_param_memory',
|
|
591
|
+
'wrun_bar_count_phase',
|
|
592
|
+
'wrun_frame_invalid',
|
|
593
|
+
'wrun_frame_phase',
|
|
594
|
+
'wrun_frame_undeclared',
|
|
595
|
+
'wrun_frame_length',
|
|
596
|
+
'wrun_frame_too_large',
|
|
597
|
+
'wrun_frame_run_too_large',
|
|
598
|
+
'wrun_frame_memory',
|
|
599
|
+
'wrun_frame_utf8',
|
|
600
|
+
],
|
|
601
|
+
pack: [
|
|
602
|
+
'wrun_cell_block_invalid',
|
|
603
|
+
// kit 0.71.0: a run's rows x outputs past WRUN_MAX_RUN_CELLS, refused before the buffer (wrun-run-cells.util).
|
|
604
|
+
'wrun_run_cells_too_large',
|
|
605
|
+
'wrun_cell_block_too_large',
|
|
606
|
+
],
|
|
607
|
+
align: [
|
|
608
|
+
'wrun_densify_empty_fetch',
|
|
609
|
+
'wrun_densify_mixed_phase',
|
|
610
|
+
'wrun_liquidation_side_unmatched',
|
|
611
|
+
'wrun_bound_series_empty',
|
|
612
|
+
'wrun_cell_data_malformed',
|
|
613
|
+
],
|
|
614
|
+
};
|
|
615
|
+
const KIT_REFUSAL_STAGE_OF = new Map(Object.keys(WRUN_KIT_REFUSAL_STAGES).flatMap((stage) => WRUN_KIT_REFUSAL_STAGES[stage].map((code) => [code, stage])));
|
|
616
|
+
/** The kit stage a refusal code is raised at, or undefined for a code the kit's table does not hold
|
|
617
|
+
* (the lane's own caps, a code a newer kit added). */
|
|
618
|
+
export function wrunKitRefusalStageOf(code) {
|
|
619
|
+
return KIT_REFUSAL_STAGE_OF.get(code);
|
|
620
|
+
}
|
|
621
|
+
/** The marker field of a stale answer (the attempt was replaced or retired). */
|
|
622
|
+
export const WRUN_STALE_ANSWER_KEY = 'wrunStaleAnswer';
|
|
623
|
+
/** The marker field of a foreign supersede (the server superseded the overlay's live attempt from elsewhere). */
|
|
624
|
+
export const WRUN_FOREIGN_SUPERSEDE_KEY = 'wrunForeignSupersede';
|
|
625
|
+
const STALE_NOTE_KEYS = ['clientRequestId', 'code', 'reason', 'message'];
|
|
626
|
+
function staleNoteOf(value) {
|
|
627
|
+
if (!isRecord(value))
|
|
628
|
+
return undefined;
|
|
629
|
+
const note = {};
|
|
630
|
+
for (const key of STALE_NOTE_KEYS) {
|
|
631
|
+
const field = textOf(value[key]);
|
|
632
|
+
if (field !== undefined)
|
|
633
|
+
note[key] = field;
|
|
634
|
+
}
|
|
635
|
+
return note;
|
|
636
|
+
}
|
|
637
|
+
/** The stale answer a worker reply's output carries, when the worker settled one (WRUN_STALE_ANSWER_KEY). */
|
|
638
|
+
export function wrunStaleAnswerOf(output) {
|
|
639
|
+
return isRecord(output) ? staleNoteOf(output[WRUN_STALE_ANSWER_KEY]) : undefined;
|
|
640
|
+
}
|
|
641
|
+
/** The foreign supersede a worker reply's output carries, when the worker settled one (WRUN_FOREIGN_SUPERSEDE_KEY). */
|
|
642
|
+
export function wrunForeignSupersedeOf(output) {
|
|
643
|
+
return isRecord(output) ? staleNoteOf(output[WRUN_FOREIGN_SUPERSEDE_KEY]) : undefined;
|
|
644
|
+
}
|
|
645
|
+
const staleAnswerListeners = new Set();
|
|
646
|
+
/**
|
|
647
|
+
* The stale-settle hook: the cloud lane's transport calls it for every answer the socket worker settled as stale
|
|
648
|
+
* (WRUN_STALE_ANSWER_KEY), so the monitoring joins the chart's settles to the server's refusal lines by
|
|
649
|
+
* `clientRequestId`. A listener that throws never reaches the caller.
|
|
650
|
+
*/
|
|
651
|
+
export function onWrunAnswerStale(note) {
|
|
652
|
+
for (const listener of [...staleAnswerListeners]) {
|
|
653
|
+
try {
|
|
654
|
+
listener(note);
|
|
655
|
+
}
|
|
656
|
+
catch {
|
|
657
|
+
// Monitoring is advisory: a failing listener never fails the ask.
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
/** Subscribe to the stale-settle hook (onWrunAnswerStale); returns the unsubscribe. */
|
|
662
|
+
export function subscribeWrunAnswerStale(listener) {
|
|
663
|
+
staleAnswerListeners.add(listener);
|
|
664
|
+
return () => {
|
|
665
|
+
staleAnswerListeners.delete(listener);
|
|
666
|
+
};
|
|
667
|
+
}
|