@orangecharts/wrun-chart-host 0.5.0 → 0.6.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 +5 -4
- package/dist/constants/feature-flags.constants.js +7 -2
- package/dist/host-env.d.ts +3 -19
- package/dist/host-ports.types.d.ts +1 -14
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/interfaces/wrun-runtime.interface.d.ts +88 -13
- package/dist/interfaces/wrun-runtime.interface.js +17 -3
- package/dist/utility/chart/chart-mount-epoch.util.d.ts +12 -0
- package/dist/utility/chart/chart-mount-epoch.util.js +32 -0
- package/dist/utility/wrun/wrun-bar-count.util.d.ts +17 -6
- package/dist/utility/wrun/wrun-bar-count.util.js +27 -12
- package/dist/utility/wrun/wrun-host.service.d.ts +114 -50
- package/dist/utility/wrun/wrun-host.service.js +351 -151
- package/dist/utility/wrun/wrun-hover.util.d.ts +3 -0
- package/dist/utility/wrun/wrun-hover.util.js +25 -4
- package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +2 -2
- package/dist/utility/wrun/wrun-overlay-run.util.d.ts +2 -2
- package/dist/utility/wrun/wrun-pack.util.d.ts +2 -1
- package/dist/utility/wrun/wrun-prefix-cohort.util.d.ts +1 -1
- package/dist/utility/wrun/wrun-prefix-cohort.util.js +1 -1
- package/dist/utility/wrun/wrun-registry-errors.util.d.ts +5 -3
- package/dist/utility/wrun/wrun-sandbox-row-source.d.ts +2 -2
- package/dist/utility/wrun/wrun-sha256.leaf.d.ts +13 -0
- package/dist/utility/wrun/wrun-sha256.leaf.js +84 -0
- package/dist/workers/wrun/wrun-abi-host.d.ts +15 -2
- package/dist/workers/wrun/wrun-abi-host.js +31 -12
- package/dist/workers/wrun/wrun-engine-handler.d.ts +11 -28
- package/dist/workers/wrun/wrun-engine-handler.js +181 -12
- package/package.json +1 -1
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
import { wrunLegendName } from '../chart/wrun-legend-name.util.js';
|
|
26
26
|
import { WRUN_MAX_BLOCK_HEIGHT_PX, WRUN_MAX_HUD_FONT_SIZE_PX, WRUN_MAX_HUD_RINGS, WRUN_MIN_BLOCK_HEIGHT_PX, WRUN_MIN_HUD_FONT_SIZE_PX, isWrunRowLeader, wrunBlockDraw, } from './wrun-hud-looks.util.js';
|
|
27
27
|
import { formatWrunLegendValue, formatWrunValue, isWrunValueFormat, } from './wrun-pane-format.util.js';
|
|
28
|
-
import { resolveWrunColorWord } from './wrun-style-words.util.js';
|
|
28
|
+
import { isWrunColorWord, parseWrunThemeToken, resolveWrunColorWord, } from './wrun-style-words.util.js';
|
|
29
29
|
/** The sparkline's default window when a block declares no `bars`. */
|
|
30
30
|
export const WRUN_SPARK_DEFAULT_BARS = 32;
|
|
31
31
|
/** The chip separator inside one string slot ("Overbought|Rising"). */
|
|
@@ -96,14 +96,35 @@ function formatPlacedSignedValue(value, name, format, placement, options) {
|
|
|
96
96
|
return '-';
|
|
97
97
|
return `${value < 0 ? '-' : '+'}${formatPlacedValue(Math.abs(value), name, format, placement, options)}`;
|
|
98
98
|
}
|
|
99
|
+
// The colours a block view may paint (HTML sink audit L15): only what a style can read as a colour and nothing
|
|
100
|
+
// else. Any hex (the sheet words are #rrggbb and #rrggbbaa), and a comma rgb()/rgba()/hsl()/hsla() of plain numbers
|
|
101
|
+
// (official sheets carry `rgba(120, 123, 134, 0.7)`). No url(), no var(), no `;`, no word: a sheet comes from a
|
|
102
|
+
// registry tarball with only its id and outputs type-checked, and its colours reach `background` in the HUD tiles.
|
|
103
|
+
const WRUN_PAINT_HEX_RE = /^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
104
|
+
const WRUN_PAINT_NUMBER = String.raw `[-+]?(?:\d+(?:\.\d+)?|\.\d+)`;
|
|
105
|
+
const WRUN_PAINT_FUNCTION_RE = new RegExp(String.raw `^(?:rgba?|hsla?)\(\s*${WRUN_PAINT_NUMBER}(?:deg|%)?\s*,\s*${WRUN_PAINT_NUMBER}%?\s*,\s*${WRUN_PAINT_NUMBER}%?\s*(?:,\s*${WRUN_PAINT_NUMBER}%?\s*)?\)$`, 'i');
|
|
106
|
+
/** `value` as written when a style reads it as a colour and nothing else (a hex, or a numeric rgb()/hsl() form),
|
|
107
|
+
* else undefined. The gate paintColor and every block view sink (WrunBlocks) share. */
|
|
108
|
+
export function wrunPaintColor(value) {
|
|
109
|
+
if (typeof value !== 'string')
|
|
110
|
+
return undefined;
|
|
111
|
+
const color = value.trim();
|
|
112
|
+
return WRUN_PAINT_HEX_RE.test(color) || WRUN_PAINT_FUNCTION_RE.test(color) ? value : undefined;
|
|
113
|
+
}
|
|
99
114
|
/** A colour word painted for the placement's chart: a theme token resolves
|
|
100
|
-
* against the palette (DW13)
|
|
101
|
-
*
|
|
115
|
+
* against the palette (DW13) and paints only when the palette answers with a
|
|
116
|
+
* colour; any other word paints as written when it is a sheet colour word
|
|
117
|
+
* (isWrunColorWord, the HUD card gate: a theme token stays as written without
|
|
118
|
+
* a palette) or a plain colour (wrunPaintColor). Anything else (a url(), a
|
|
119
|
+
* declaration list) paints nothing. */
|
|
102
120
|
function paintColor(word, placement) {
|
|
103
121
|
if (word === undefined)
|
|
104
122
|
return undefined;
|
|
105
123
|
const theme = placement?.colorTheme;
|
|
106
|
-
|
|
124
|
+
if (theme !== undefined && parseWrunThemeToken(word) !== null) {
|
|
125
|
+
return wrunPaintColor(resolveWrunColorWord(word, theme));
|
|
126
|
+
}
|
|
127
|
+
return isWrunColorWord(word) || wrunPaintColor(word) !== undefined ? word : undefined;
|
|
107
128
|
}
|
|
108
129
|
/** An output's display label: the declared `label`, else its name read as
|
|
109
130
|
* words (the legend's own rule, wrunLegendName). */
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
import type { WrunStrategyRunInput } from './wrun-host.service.js';
|
|
78
78
|
import { WrunDeadlineError } from './wrun-registry-errors.util.js';
|
|
79
79
|
import { type WrunRefusalAttemptToken } from './wrun-refusal.util.js';
|
|
80
|
-
import type { WrunIndicatorMetadata, WrunOutputRow } from '../../interfaces/wrun-runtime.interface.js';
|
|
80
|
+
import type { WrunIndicatorMetadata, WrunModuleHandle, WrunOutputRow } from '../../interfaces/wrun-runtime.interface.js';
|
|
81
81
|
import type { WrunCandleGroup, WrunFillPair } from '../chart/wrun-run-result.util.js';
|
|
82
82
|
import type { WrunLaneAcquisition, WrunLiveLane } from './wrun-live-intake.util.js';
|
|
83
83
|
import type { WrunPollLaneInstance } from './sources/wrun-poll-lane.types.js';
|
|
@@ -309,7 +309,7 @@ export interface WrunOverlayLiveContext {
|
|
|
309
309
|
* without a fetch: the compiled module, init()'s argument block and the
|
|
310
310
|
* strategy half minus the bars (rebuilt from the chart's candles). */
|
|
311
311
|
sessionSeed?: {
|
|
312
|
-
module:
|
|
312
|
+
module: WrunModuleHandle;
|
|
313
313
|
initArgs: readonly number[];
|
|
314
314
|
/** wrun-5: the typed text settings' bytes by init slot, beside initArgs. */
|
|
315
315
|
textParams?: Readonly<Record<number, Uint8Array>>;
|
|
@@ -79,7 +79,7 @@ import type { WrunLegCandleClose } from '@orangecharts/indicator-kit/host';
|
|
|
79
79
|
import { type WrunPinnedLeg, type WrunPinnedWire } from './wrun-source-rows.util.js';
|
|
80
80
|
import { type WrunOptionsChainRefusal } from './wrun-options-chain.util.js';
|
|
81
81
|
import { type WrunRunIntervalProjection } from './wrun-run-interval-session.util.js';
|
|
82
|
-
import { type WrunIndicatorMetadata, type WrunOutputRow } from '../../interfaces/wrun-runtime.interface.js';
|
|
82
|
+
import { type WrunIndicatorMetadata, type WrunModuleHandle, type WrunOutputRow } from '../../interfaces/wrun-runtime.interface.js';
|
|
83
83
|
import type { RuntimeDiagnostic } from '../../interfaces/kscript-diagnostics.interface.js';
|
|
84
84
|
import { buildWrunOverlayRunResult, type WrunCanvasHostFill, type WrunOverlayResultOptions } from './wrun-overlay-result.util.js';
|
|
85
85
|
import { wrunIntegratedRowsView } from './wrun-integration-budget.util.js';
|
|
@@ -131,7 +131,7 @@ export interface WrunOverlayRunTarget {
|
|
|
131
131
|
metadata: WrunIndicatorMetadata;
|
|
132
132
|
/** The compiled package the browser lanes run; null for a record whose row source computes the
|
|
133
133
|
* package elsewhere (the socket source: the cloud runs it, contract C7). */
|
|
134
|
-
module:
|
|
134
|
+
module: WrunModuleHandle | null;
|
|
135
135
|
/** Legend/run-result title. */
|
|
136
136
|
title: string;
|
|
137
137
|
position: 'onchart' | 'offchart';
|
|
@@ -49,7 +49,7 @@ export declare function wrunCellTupleWidths(): Readonly<Record<string, number>>;
|
|
|
49
49
|
export declare const WRUN_CELL_BLOCK_TOO_LARGE_CODE = "wrun_cell_block_too_large";
|
|
50
50
|
export declare function wrunAbiVersion(metadata: Pick<WrunIndicatorMetadata, 'abi_version'>): WrunAbiVersion;
|
|
51
51
|
export interface WrunPackRowsResult {
|
|
52
|
-
request: Omit<WrunPackedRunRequest, 'id' | '
|
|
52
|
+
request: Omit<WrunPackedRunRequest, 'id' | 'moduleKey' | 'moduleBytes' | 'mode'>;
|
|
53
53
|
transfer: ArrayBuffer[];
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
@@ -71,4 +71,5 @@ export declare function wrunFramesOf(rows: ReadonlyArray<WrunOutputRow>): (strin
|
|
|
71
71
|
* empty, preserving the ABI distinction. */
|
|
72
72
|
export declare function unpackWrunResponse(response: Extract<WrunWorkerResponse, {
|
|
73
73
|
ok: true;
|
|
74
|
+
outputs: Float64Array;
|
|
74
75
|
}>, ts: ArrayLike<number>, outputCount: number, stringSlotCount: number): WrunOutputRow[];
|
|
@@ -27,7 +27,7 @@ export interface WrunPrefixSafeEntry {
|
|
|
27
27
|
* looked up by that digest alone, never by a name); 'version-outside-audit' when entries name it but none admits this
|
|
28
28
|
* version, build or source (an unknown version passes only a '*' entry, an unknown hash never passes a pinned one, a
|
|
29
29
|
* registry identity never passes a source-pinned one). `wasmSha256` is the sheet's `wasm_sha256`, which the host
|
|
30
|
-
* verifies against the module bytes before it compiles them (wrun-host.service
|
|
30
|
+
* verifies against the module bytes before it compiles them (wrun-host.service loadModule); `sourceDigest` is a
|
|
31
31
|
* draft overlay's `wrunDraftRef.sourceDigest`, the compile pipeline's sha256 of the entry source's UTF-8 text, and
|
|
32
32
|
* null for every other overlay.
|
|
33
33
|
*/
|
|
@@ -237,7 +237,7 @@ const ROSTER = loadRoster(WRUN_PREFIX_SAFE_ROSTER);
|
|
|
237
237
|
* looked up by that digest alone, never by a name); 'version-outside-audit' when entries name it but none admits this
|
|
238
238
|
* version, build or source (an unknown version passes only a '*' entry, an unknown hash never passes a pinned one, a
|
|
239
239
|
* registry identity never passes a source-pinned one). `wasmSha256` is the sheet's `wasm_sha256`, which the host
|
|
240
|
-
* verifies against the module bytes before it compiles them (wrun-host.service
|
|
240
|
+
* verifies against the module bytes before it compiles them (wrun-host.service loadModule); `sourceDigest` is a
|
|
241
241
|
* draft overlay's `wrunDraftRef.sourceDigest`, the compile pipeline's sha256 of the entry source's UTF-8 text, and
|
|
242
242
|
* null for every other overlay.
|
|
243
243
|
*/
|
|
@@ -115,13 +115,15 @@ export declare function isWrunQuarantinedError(error: unknown): error is WrunQua
|
|
|
115
115
|
* arrived without a record, e.g. a host message form that predates it);
|
|
116
116
|
* `quarantineKey` and `sessionKey` name the request the worker was running
|
|
117
117
|
* (its package and, for a live lane, its session, which is the overlay id);
|
|
118
|
-
* `heldMs` is the
|
|
119
|
-
*
|
|
120
|
-
*
|
|
118
|
+
* `heldMs` is the budget a timeout exhausted, so it bounds how long that
|
|
119
|
+
* request held the sandbox, never how long it executed; `at` is the death's
|
|
120
|
+
* epoch ms. */
|
|
121
121
|
export interface WrunHostDeathContext {
|
|
122
122
|
readonly kind: 'timeout' | 'worker-error' | 'unknown';
|
|
123
123
|
readonly quarantineKey?: string;
|
|
124
124
|
readonly sessionKey?: string;
|
|
125
|
+
/** The culprit's phase: `start` (its wait, compile and instantiation, from the post) or `run` (executing). */
|
|
126
|
+
readonly phase?: 'start' | 'run';
|
|
125
127
|
readonly heldMs?: number;
|
|
126
128
|
readonly at: number;
|
|
127
129
|
}
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
* registry and dedupe table.
|
|
33
33
|
*/
|
|
34
34
|
import type { WrunChartHandle } from '../../host-ports.types.js';
|
|
35
|
-
import type { WrunIndicatorMetadata, WrunOutputRow } from '../../interfaces/wrun-runtime.interface.js';
|
|
35
|
+
import type { WrunIndicatorMetadata, WrunModuleHandle, WrunOutputRow } from '../../interfaces/wrun-runtime.interface.js';
|
|
36
36
|
import type { WrunCellRows } from './wrun-canvases.util.js';
|
|
37
37
|
import { type WrunStrategyRunInput } from './wrun-host.service.js';
|
|
38
38
|
import { type WrunInputRow } from './wrun-pack.util.js';
|
|
@@ -101,7 +101,7 @@ export declare function wrunRowBatchCellRows(batch: WrunRowBatch): WrunCellRows
|
|
|
101
101
|
export declare function wrunSandboxRowBatchOf(input: WrunSandboxBatchInput): WrunRowBatch;
|
|
102
102
|
/** The engine worker's request one window resolves to (`WrunBrowserHost.runSeries` / `startLiveSeries`). */
|
|
103
103
|
export interface WrunSandboxRunRequest {
|
|
104
|
-
module:
|
|
104
|
+
module: WrunModuleHandle;
|
|
105
105
|
metadata: WrunIndicatorMetadata;
|
|
106
106
|
rows: readonly WrunInputRow[];
|
|
107
107
|
initArgs: readonly number[];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SHA-256 of a wrun module's bytes, synchronously and with no global: the engine worker's load path
|
|
3
|
+
* (wrun-engine-handler.ts) hashes every module it is handed before it checks the sheet's `wasm_sha256` pin, and mints
|
|
4
|
+
* the module's cache key from the digest. The main thread never hashes a module (wrun-host.service.ts posts the bytes
|
|
5
|
+
* and reads the digest off the worker's reply), so nothing here may reach for `crypto.subtle`: it is missing outside a
|
|
6
|
+
* secure context, it answers only through a promise, and the worker's load has no await to spare before its cache
|
|
7
|
+
* entry exists.
|
|
8
|
+
*
|
|
9
|
+
* Ported from the phone's `wrunSha256Hex` (kiyotaka-frontend-app chart-web/src/wrun/wrun-memory-clamp.ts:242), which
|
|
10
|
+
* phase A moves onto this leaf before its own copy goes. FIPS 180-4 sections 4.2.2 and 5.3.3.
|
|
11
|
+
*/
|
|
12
|
+
/** SHA-256 of `bytes` (the view's own range) as 64 lowercase hex digits, synchronously. */
|
|
13
|
+
export declare function wrunSha256Hex(bytes: Uint8Array): string;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SHA-256 of a wrun module's bytes, synchronously and with no global: the engine worker's load path
|
|
3
|
+
* (wrun-engine-handler.ts) hashes every module it is handed before it checks the sheet's `wasm_sha256` pin, and mints
|
|
4
|
+
* the module's cache key from the digest. The main thread never hashes a module (wrun-host.service.ts posts the bytes
|
|
5
|
+
* and reads the digest off the worker's reply), so nothing here may reach for `crypto.subtle`: it is missing outside a
|
|
6
|
+
* secure context, it answers only through a promise, and the worker's load has no await to spare before its cache
|
|
7
|
+
* entry exists.
|
|
8
|
+
*
|
|
9
|
+
* Ported from the phone's `wrunSha256Hex` (kiyotaka-frontend-app chart-web/src/wrun/wrun-memory-clamp.ts:242), which
|
|
10
|
+
* phase A moves onto this leaf before its own copy goes. FIPS 180-4 sections 4.2.2 and 5.3.3.
|
|
11
|
+
*/
|
|
12
|
+
// The round constants, typed out rather than derived from the prime roots at load: a derived table would hang on each
|
|
13
|
+
// engine's Math.cbrt rounding, and a wrong constant refuses every package.
|
|
14
|
+
const SHA256_K = new Uint32Array([
|
|
15
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98,
|
|
16
|
+
0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
|
|
17
|
+
0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8,
|
|
18
|
+
0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
|
19
|
+
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819,
|
|
20
|
+
0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
|
|
21
|
+
0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7,
|
|
22
|
+
0xc67178f2,
|
|
23
|
+
]);
|
|
24
|
+
const SHA256_INIT = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19];
|
|
25
|
+
// One 64-byte block into `state`. Sums stay exact in doubles (five terms under 2^35), and the Uint32Array stores wrap
|
|
26
|
+
// them mod 2^32, which is the algorithm's own addition.
|
|
27
|
+
function sha256Block(state, w, view, offset) {
|
|
28
|
+
for (let i = 0; i < 16; i += 1)
|
|
29
|
+
w[i] = view.getUint32(offset + i * 4);
|
|
30
|
+
for (let i = 16; i < 64; i += 1) {
|
|
31
|
+
const x = w[i - 15];
|
|
32
|
+
const y = w[i - 2];
|
|
33
|
+
const s0 = ((x >>> 7) | (x << 25)) ^ ((x >>> 18) | (x << 14)) ^ (x >>> 3);
|
|
34
|
+
const s1 = ((y >>> 17) | (y << 15)) ^ ((y >>> 19) | (y << 13)) ^ (y >>> 10);
|
|
35
|
+
w[i] = w[i - 16] + s0 + w[i - 7] + s1;
|
|
36
|
+
}
|
|
37
|
+
let [a, b, c, d, e, f, g, h] = state;
|
|
38
|
+
for (let i = 0; i < 64; i += 1) {
|
|
39
|
+
const s1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((e >>> 25) | (e << 7));
|
|
40
|
+
const t1 = (h + s1 + ((e & f) ^ (~e & g)) + SHA256_K[i] + w[i]) | 0;
|
|
41
|
+
const s0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10));
|
|
42
|
+
const t2 = (s0 + ((a & b) ^ (a & c) ^ (b & c))) | 0;
|
|
43
|
+
h = g;
|
|
44
|
+
g = f;
|
|
45
|
+
f = e;
|
|
46
|
+
e = (d + t1) | 0;
|
|
47
|
+
d = c;
|
|
48
|
+
c = b;
|
|
49
|
+
b = a;
|
|
50
|
+
a = (t1 + t2) | 0;
|
|
51
|
+
}
|
|
52
|
+
state[0] += a;
|
|
53
|
+
state[1] += b;
|
|
54
|
+
state[2] += c;
|
|
55
|
+
state[3] += d;
|
|
56
|
+
state[4] += e;
|
|
57
|
+
state[5] += f;
|
|
58
|
+
state[6] += g;
|
|
59
|
+
state[7] += h;
|
|
60
|
+
}
|
|
61
|
+
/** SHA-256 of `bytes` (the view's own range) as 64 lowercase hex digits, synchronously. */
|
|
62
|
+
export function wrunSha256Hex(bytes) {
|
|
63
|
+
const state = Uint32Array.from(SHA256_INIT);
|
|
64
|
+
const w = new Uint32Array(64);
|
|
65
|
+
const length = bytes.byteLength;
|
|
66
|
+
const fullBlocks = Math.floor(length / 64);
|
|
67
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, length);
|
|
68
|
+
for (let block = 0; block < fullBlocks; block += 1)
|
|
69
|
+
sha256Block(state, w, view, block * 64);
|
|
70
|
+
const rest = length - fullBlocks * 64;
|
|
71
|
+
const tail = new Uint8Array(rest + 9 <= 64 ? 64 : 128);
|
|
72
|
+
tail.set(bytes.subarray(fullBlocks * 64));
|
|
73
|
+
tail[rest] = 0x80;
|
|
74
|
+
const tailView = new DataView(tail.buffer);
|
|
75
|
+
// The message length in bits, big-endian over the last 8 bytes: the high word first (length * 8 / 2^32).
|
|
76
|
+
tailView.setUint32(tail.length - 8, Math.floor(length / 0x20000000));
|
|
77
|
+
tailView.setUint32(tail.length - 4, (length * 8) >>> 0);
|
|
78
|
+
for (let offset = 0; offset < tail.length; offset += 64)
|
|
79
|
+
sha256Block(state, w, tailView, offset);
|
|
80
|
+
let hex = '';
|
|
81
|
+
for (let i = 0; i < 8; i += 1)
|
|
82
|
+
hex += state[i].toString(16).padStart(8, '0');
|
|
83
|
+
return hex;
|
|
84
|
+
}
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
* the string accounting and frame slots across calls, and history is
|
|
85
85
|
* never re-executed per tick.
|
|
86
86
|
*/
|
|
87
|
-
import { WrunLiveOrderError, type WrunAbiVersion, type WrunDrawSkips, type WrunLiveBlockStats, type WrunPackedRowsBlock, type WrunPackedRunOutput, type
|
|
87
|
+
import { WrunLiveOrderError, type WrunAbiVersion, type WrunDrawSkips, type WrunLiveBlockStats, type WrunModuleImport, type WrunPackedRowsBlock, type WrunPackedRunOutput, type WrunResolvedRunRequest } from '../../interfaces/wrun-runtime.interface.js';
|
|
88
88
|
import { type WrunHandleDefaultsByKind, type WrunHandleRecord } from '../../utility/wrun/wrun-handles.util.js';
|
|
89
89
|
import type { StrategyDeclaredConfig, StrategyOutput, WrunStrategyEvents, WrunStrategyReservedOutputs } from '@orangecharts/indicator-kit/host';
|
|
90
90
|
/** The strategy half of a run (contract sections 2 and 5): the engine's
|
|
@@ -146,6 +146,11 @@ export interface WrunAbiSessionConfig {
|
|
|
146
146
|
/** Test hook: observes every forming-bar restore (a same-bar replay and
|
|
147
147
|
* the close-confirm re-evaluation alike). */
|
|
148
148
|
onRestore?: () => void;
|
|
149
|
+
/** Called once the module is instantiated, right before the guest's first
|
|
150
|
+
* call (init()): from here the request executes. The engine worker posts
|
|
151
|
+
* its `running` here, so the client's run deadline never counts an
|
|
152
|
+
* instantiation still pending behind another request's turn. */
|
|
153
|
+
onInstantiated?: () => void;
|
|
149
154
|
}
|
|
150
155
|
/** A wrun-3 session answers the ledger's FULL live set beside every block's
|
|
151
156
|
* rows (wire records in creation order), and the run's skipped draw calls
|
|
@@ -176,9 +181,17 @@ export { WrunLiveOrderError };
|
|
|
176
181
|
export interface WrunAbiSession {
|
|
177
182
|
runRows(block: WrunStrategyRowsBlock, mode: 'historical' | 'live'): WrunAbiSessionOutput;
|
|
178
183
|
}
|
|
184
|
+
/** A compiled module's imports as the shared readers take them (`WrunModuleImport`, in
|
|
185
|
+
* WebAssembly.Module.imports() order), listed once per module and frozen: the engine worker's load answers this list
|
|
186
|
+
* on the module's handle, and every session of the module reads its import checks off the same list (the shared
|
|
187
|
+
* predicates of wrun-bar-count.util among them), so the main thread's handle and the worker's module answer alike. */
|
|
188
|
+
export declare function wrunModuleImportList(module: WebAssembly.Module): readonly WrunModuleImport[];
|
|
179
189
|
export declare function createWrunAbiSession(config: WrunAbiSessionConfig): Promise<WrunAbiSession>;
|
|
180
|
-
|
|
190
|
+
/** One whole request against a fresh instance of the module the engine worker resolved for it (a resolved request:
|
|
191
|
+
* the wire request's module key and bytes already turned into the compiled module, never a wire request). */
|
|
192
|
+
export declare function runWrunPackedRequest(request: WrunResolvedRunRequest & WrunStrategyRunRequestFields, options?: {
|
|
181
193
|
memoryLimitBytes?: number;
|
|
194
|
+
onInstantiated?: () => void;
|
|
182
195
|
}): Promise<WrunAbiSessionOutput>;
|
|
183
196
|
/** An AssemblyScript `string` in the guest's memory: UTF-16LE code units at `ptr`, the byte
|
|
184
197
|
* length as the u32 at `ptr - 4` (the managed object header's rtSize). Null for a null
|
|
@@ -89,15 +89,16 @@ import { abiAtLeast, WrunLiveOrderError, } from '../../interfaces/wrun-runtime.i
|
|
|
89
89
|
import { WRUN3_DRAW_REFUSALS, WrunDrawRefusalError, WrunHandleLedger, } from '../../utility/wrun/wrun-handles.util.js';
|
|
90
90
|
import { WRUN_RENDER_RESULT_LIMIT_BYTES } from '../../utility/wrun/wrun-render-select.util.js';
|
|
91
91
|
import { WRUN5_TEXT_IMPORTS, WRUN5_TEXT_REFUSALS, wrunPlainText } from '../../utility/wrun/wrun-text-params.util.js';
|
|
92
|
-
import { WRUN6_BAR_REFUSALS,
|
|
92
|
+
import { WRUN6_BAR_REFUSALS, wrunImportsBarCount } from '../../utility/wrun/wrun-bar-count.util.js';
|
|
93
93
|
import { WRUN_MEMORY_LIMIT_BYTES } from '../../utility/wrun/wrun-memory-clamp.util.js';
|
|
94
94
|
import { wrunRunCellsRefusal } from '../../utility/wrun/wrun-run-cells.util.js';
|
|
95
95
|
const WRUN_GLOBAL_PREFIX = '__wrun_g';
|
|
96
96
|
/** `strategyBars` stride: open, high, low, close per row. */
|
|
97
97
|
const STRATEGY_BAR_STRIDE = 4;
|
|
98
98
|
const STRATEGY_IMPORT_PREFIX = 'wrun_strategy_';
|
|
99
|
-
/** The memory ceiling: the clamp's own limit, which
|
|
100
|
-
* as its memory maximum (wrun-memory-clamp.util), so the two can
|
|
99
|
+
/** The memory ceiling: the clamp's own limit, which the engine worker's load (wrun-engine-handler.ts
|
|
100
|
+
* compileWrunModuleBytes) also stamps on every module as its memory maximum (wrun-memory-clamp.util), so the two can
|
|
101
|
+
* never drift. */
|
|
101
102
|
const WRUN_DEFAULT_MEMORY_LIMIT_BYTES = WRUN_MEMORY_LIMIT_BYTES;
|
|
102
103
|
const BYTES_PER_CELL = 8;
|
|
103
104
|
const BYTES_PER_POINT = 16;
|
|
@@ -126,11 +127,24 @@ const MAX_ROW_STAMP = 0x3fff_ffff;
|
|
|
126
127
|
* exported here for the worker and the ABI drive specs. */
|
|
127
128
|
export { WrunLiveOrderError };
|
|
128
129
|
const now = () => (typeof performance !== 'undefined' ? performance.now() : Date.now());
|
|
130
|
+
const importListByModule = new WeakMap();
|
|
131
|
+
/** A compiled module's imports as the shared readers take them (`WrunModuleImport`, in
|
|
132
|
+
* WebAssembly.Module.imports() order), listed once per module and frozen: the engine worker's load answers this list
|
|
133
|
+
* on the module's handle, and every session of the module reads its import checks off the same list (the shared
|
|
134
|
+
* predicates of wrun-bar-count.util among them), so the main thread's handle and the worker's module answer alike. */
|
|
135
|
+
export function wrunModuleImportList(module) {
|
|
136
|
+
let list = importListByModule.get(module);
|
|
137
|
+
if (list === undefined) {
|
|
138
|
+
list = Object.freeze(WebAssembly.Module.imports(module).map(({ module: from, name }) => Object.freeze({ module: from, name })));
|
|
139
|
+
importListByModule.set(module, list);
|
|
140
|
+
}
|
|
141
|
+
return list;
|
|
142
|
+
}
|
|
129
143
|
/** A wrun-3 module whose sheet declares no `strategy` section must import
|
|
130
144
|
* no strategy import: refused at instantiation by name, the same rule as a
|
|
131
145
|
* draw call for a kind absent from `handles`, before anything links. */
|
|
132
146
|
function refuseUndeclaredStrategyImports(module) {
|
|
133
|
-
const names =
|
|
147
|
+
const names = wrunModuleImportList(module)
|
|
134
148
|
.filter((entry) => entry.module === 'wrun' && entry.name.startsWith(STRATEGY_IMPORT_PREFIX))
|
|
135
149
|
.map((entry) => entry.name);
|
|
136
150
|
if (names.length === 0)
|
|
@@ -187,7 +201,7 @@ export async function createWrunAbiSession(config) {
|
|
|
187
201
|
throw new Error(`WRUN frames declares ${frameSlotCount} slots; the maximum is ${MAX_FRAME_SLOTS}`);
|
|
188
202
|
}
|
|
189
203
|
if (!abiAtLeast(config.abi, 'wrun-4')) {
|
|
190
|
-
const importsFrame =
|
|
204
|
+
const importsFrame = wrunModuleImportList(config.module).some((entry) => entry.module === 'wrun' && entry.name === 'wrun_output_frame');
|
|
191
205
|
if (importsFrame) {
|
|
192
206
|
throw new Error(`WRUN wrun_output_frame requires abi_version "wrun-4" or later (declared "${config.abi}")`);
|
|
193
207
|
}
|
|
@@ -196,7 +210,7 @@ export async function createWrunAbiSession(config) {
|
|
|
196
210
|
// module compiled from a param.text declaration never links under a host
|
|
197
211
|
// or a sheet that has not reached wrun-5.
|
|
198
212
|
if (!abiAtLeast(config.abi, 'wrun-5')) {
|
|
199
|
-
const textImports =
|
|
213
|
+
const textImports = wrunModuleImportList(config.module)
|
|
200
214
|
.filter((entry) => entry.module === 'wrun' && TEXT_IMPORT_NAMES.has(entry.name))
|
|
201
215
|
.map((entry) => entry.name);
|
|
202
216
|
if (textImports.length > 0) {
|
|
@@ -206,7 +220,7 @@ export async function createWrunAbiSession(config) {
|
|
|
206
220
|
}
|
|
207
221
|
// The row count is wrun-6's (docs/WRUN6_ABI.md): an older ABI refuses the
|
|
208
222
|
// import by name before anything links, the om hosts' way-in hint.
|
|
209
|
-
const importsBarCount =
|
|
223
|
+
const importsBarCount = wrunImportsBarCount(wrunModuleImportList(config.module));
|
|
210
224
|
if (importsBarCount && !abiAtLeast(config.abi, 'wrun-6')) {
|
|
211
225
|
throw new Error(`WRUN wrun_bar_count: the row count requires abi_version "wrun-6" or later ` +
|
|
212
226
|
`(declared "${config.abi}"); a bar.count() call derives it`);
|
|
@@ -663,6 +677,8 @@ export async function createWrunAbiSession(config) {
|
|
|
663
677
|
else if (abiAtLeast(config.abi, 'wrun-3'))
|
|
664
678
|
refuseUndeclaredStrategyImports(config.module);
|
|
665
679
|
const instance = await WebAssembly.instantiate(config.module, importObject);
|
|
680
|
+
// Instantiated: the guest's first call (init) runs next, in this same turn.
|
|
681
|
+
config.onInstantiated?.();
|
|
666
682
|
instanceRef.exports = instance.exports;
|
|
667
683
|
const exports = instance.exports;
|
|
668
684
|
const init = requireFunction(exports.init, 'init');
|
|
@@ -975,6 +991,8 @@ function strategyOutputOf(strategyHost, ledger, rowCount, events) {
|
|
|
975
991
|
strategyReserved: strategyHost.reservedOutputs(rowCount),
|
|
976
992
|
};
|
|
977
993
|
}
|
|
994
|
+
/** One whole request against a fresh instance of the module the engine worker resolved for it (a resolved request:
|
|
995
|
+
* the wire request's module key and bytes already turned into the compiled module, never a wire request). */
|
|
978
996
|
export async function runWrunPackedRequest(request, options = {}) {
|
|
979
997
|
const session = await createWrunAbiSession({
|
|
980
998
|
module: request.module,
|
|
@@ -987,6 +1005,7 @@ export async function runWrunPackedRequest(request, options = {}) {
|
|
|
987
1005
|
handleDefaults: request.handleDefaults,
|
|
988
1006
|
strategy: request.strategy,
|
|
989
1007
|
memoryLimitBytes: options.memoryLimitBytes,
|
|
1008
|
+
onInstantiated: options.onInstantiated,
|
|
990
1009
|
});
|
|
991
1010
|
return session.runRows(request, request.mode);
|
|
992
1011
|
}
|
|
@@ -1084,11 +1103,11 @@ function sliceRow(block, row) {
|
|
|
1084
1103
|
};
|
|
1085
1104
|
}
|
|
1086
1105
|
/** Same-bar live restore semantics: copy linear memory plus the mutable
|
|
1087
|
-
* globals exported under __wrun_g*. The
|
|
1088
|
-
* under that prefix when it compiles the module (
|
|
1089
|
-
*
|
|
1090
|
-
* heap they index; a module must still export its memory if it keeps
|
|
1091
|
-
* there (AssemblyScript does by default). */
|
|
1106
|
+
* globals exported under __wrun_g*. The engine worker exports EVERY mutable
|
|
1107
|
+
* global under that prefix when it compiles the module (wrun-engine-handler
|
|
1108
|
+
* compileWrunModuleBytes), so a compiler's top-level scalars restore beside
|
|
1109
|
+
* the heap they index; a module must still export its memory if it keeps
|
|
1110
|
+
* state there (AssemblyScript does by default). */
|
|
1092
1111
|
function snapshot(exports, runStringBytes) {
|
|
1093
1112
|
const memory = exportedMemory(exports);
|
|
1094
1113
|
const view = memory ? new Uint8Array(memory.buffer) : null;
|
|
@@ -1,37 +1,20 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The wrun sandbox worker's request handler, apart from its realm wiring: the worker's entry
|
|
3
|
-
* (src/workers/wrun-engine.worker.ts) sets the worker's chart-host env first, then binds `self.onmessage` to the
|
|
4
|
-
* handler this factory makes and hands it the realm's `postMessage` as `post`. Every answer leaves through `post`
|
|
5
|
-
* (one argument, or the transfer list as `{ transfer }`), so the handler reads no realm global and keeps no module
|
|
6
|
-
* state: its live sessions live in the factory's closure, one handler per worker realm, and die with the worker.
|
|
7
|
-
*
|
|
8
|
-
* Live forming-bar sessions: a `live-start` request runs like a classic
|
|
9
|
-
* request but KEEPS the instantiated guest under its sessionKey, so later
|
|
10
|
-
* `live-rows` ticks execute only the new/revised rows against the retained
|
|
11
|
-
* state (the ABI's snapshot/restore replays a revised forming bar, memory
|
|
12
|
-
* and ledger alike). Sessions die with the worker; a tick against an
|
|
13
|
-
* unknown key answers `sessionLost` so the main-thread driver rebuilds via
|
|
14
|
-
* a fresh live-start.
|
|
15
|
-
*
|
|
16
|
-
* Session ownership (push-intake contract, plan section 8 fold 3): every
|
|
17
|
-
* `live-start` carries the live context generation as its `epoch`. The
|
|
18
|
-
* worker keeps, per session key, the newest epoch seen and a live-end fence
|
|
19
|
-
* counter. Instantiation is asynchronous, so a start can still be pending
|
|
20
|
-
* when a newer start or a `live-end` (teardown) arrives; when its
|
|
21
|
-
* instantiation settles it installs its session ONLY if its epoch is still
|
|
22
|
-
* the newest and no live-end passed meanwhile (the block is still computed
|
|
23
|
-
* and answered: the caller's full run integrates it, and a later tick on
|
|
24
|
-
* the uninstalled key answers `sessionLost`, whose reseed opens a fresh
|
|
25
|
-
* session under the current generation). A `live-end` bumps the fence and
|
|
26
|
-
* deletes. The session key stays the indicator id.
|
|
27
|
-
*/
|
|
28
1
|
import { type WrunStrategyResponseFields } from './wrun-abi-host.js';
|
|
29
|
-
import type
|
|
2
|
+
import { type WrunAbiVersion, type WrunDrawSkips, type WrunWorkerRequest, type WrunWorkerResponse } from '../../interfaces/wrun-runtime.interface.js';
|
|
30
3
|
/** How the handler answers a request: the realm's `postMessage` (the worker's entry passes
|
|
31
4
|
* `(message, options) => self.postMessage(message, options)`); a transfer list rides `options`. */
|
|
32
5
|
type WrunEnginePost = (message: WrunWorkerResponse & WrunStrategyResponseFields & WrunDrawSkips, options?: StructuredSerializeOptions) => void;
|
|
33
6
|
/** Handles one request; the promise settles once its answer is posted. */
|
|
34
7
|
type WrunEngineHandler = (request: WrunWorkerRequest) => Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* The module the engine worker compiles from a package's original bytes, in the order the main thread compiled them
|
|
10
|
+
* before 0.6.0: the memory clamp (clampWrunModuleMemory: a memory with no maximum gets the 4 MiB limit as its maximum,
|
|
11
|
+
* so the engine refuses a growth past it inside the guest's call; a refusal throws its plain words), then the shared
|
|
12
|
+
* host's `prepareModuleBytes` for the ABI (every mutable global exported under `__wrun_g<index>`, so the live lane's
|
|
13
|
+
* snapshot and restore cover a compiler's top-level scalars beside its memory), then the engine's compile. The
|
|
14
|
+
* module's identity stays its ORIGINAL bytes (the caller hashed them first); only the memory and export sections
|
|
15
|
+
* change. Exported for the ABI drive specs that run a module exactly as the worker compiles it.
|
|
16
|
+
*/
|
|
17
|
+
export declare function compileWrunModuleBytes(bytes: Uint8Array, abi: WrunAbiVersion): Promise<WebAssembly.Module>;
|
|
35
18
|
/** The engine worker's request handler, answering through `post`. The worker's entry makes one, after its env. */
|
|
36
19
|
export declare function createWrunEngineHandler(post: WrunEnginePost): WrunEngineHandler;
|
|
37
20
|
export {};
|