@tracecode/harness 0.16.3 → 0.16.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +6 -4
  3. package/dist/{browser-runtime-provider-C53ZJH3D.js → browser-runtime-provider-POTAJULA.js} +5 -5
  4. package/dist/{chunk-DTLDQQHA.js → chunk-5KH5ABPQ.js} +72 -1
  5. package/dist/{chunk-YID2AAYD.js → chunk-GX4SGR3L.js} +64 -36
  6. package/dist/{chunk-DI7WIHES.js → chunk-I2JLGVMT.js} +3 -3
  7. package/dist/{chunk-53ROKKGU.js → chunk-JPDVJCVS.js} +3 -3
  8. package/dist/{chunk-BXUGUGWL.js → chunk-NHGF353L.js} +20 -11
  9. package/dist/{chunk-TXDHVV6B.js → chunk-OXFBZTWZ.js} +15 -31
  10. package/dist/{chunk-6SWX35P2.js → chunk-P5FQOYM4.js} +489 -3
  11. package/dist/cli.js +0 -0
  12. package/dist/core.cjs +19 -10
  13. package/dist/core.js +1 -1
  14. package/dist/cpp-worker-client-SKBOLX5Q.js +12 -0
  15. package/dist/{csharp-worker-client-S4U6MCVF.js → csharp-worker-client-GAUCDYVS.js} +4 -4
  16. package/dist/internal/browser.cjs +72 -0
  17. package/dist/internal/browser.d.cts +19 -1
  18. package/dist/internal/browser.d.ts +19 -1
  19. package/dist/internal/browser.js +3 -1
  20. package/dist/internal/tracekernel-workspace.cjs +19 -10
  21. package/dist/internal/tracekernel-workspace.js +1 -1
  22. package/dist/{java-project-GK6MHT3I.js → java-project-ASCLR77F.js} +2 -2
  23. package/dist/judge.cjs +892 -89
  24. package/dist/judge.d.cts +4 -0
  25. package/dist/judge.d.ts +4 -0
  26. package/dist/judge.js +236 -23
  27. package/dist/{project-browser-B5T7WJWP.js → project-browser-7MVLDAHN.js} +2 -2
  28. package/dist/{project-browser-3I5FVB5N.js → project-browser-DKMZFGCJ.js} +2 -2
  29. package/dist/{project-browser-ADXGG5RZ.js → project-browser-VSLHVOH4.js} +2 -2
  30. package/dist/{project-browser-TDL4LMJJ.js → project-browser-XKQ2MNK3.js} +2 -2
  31. package/dist/{project-browser-JXJ74RDZ.js → project-browser-YUBOA2Q4.js} +2 -2
  32. package/dist/{python-worker-client-2RF6IYIN.js → python-worker-client-R7K7HDO7.js} +4 -4
  33. package/dist/tracekernel.cjs +658 -68
  34. package/dist/tracekernel.js +4 -4
  35. package/package.json +43 -46
  36. package/runtime-assets.lock.json +77 -70
  37. package/workers/cpp/cpp-worker.js +53 -43
  38. package/workers/csharp/csharp-worker.js +150 -1
  39. package/workers/javascript/javascript-project-worker.js +18 -9
  40. package/workers/python/python-worker.js +121 -1
  41. package/workers/vendor/csharp/_framework/TraceCode.CSharpHost.wasm +0 -0
  42. package/workers/vendor/csharp/_framework/TraceCode.CSharpJudgeRuntime.wasm +0 -0
  43. package/workers/vendor/csharp/_framework/TraceCode.TraceClrWire.wasm +0 -0
  44. package/workers/vendor/csharp/_framework/dotnet.boot.js +11 -6
  45. package/workers/vendor/csharp/_framework/dotnet.native.wasm +0 -0
  46. package/workers/vendor/csharp/_framework/supportFiles/TraceCode.CSharpHost.dll +0 -0
  47. package/workers/vendor/csharp/_framework/supportFiles/TraceCode.CSharpJudgeRuntime.dll +0 -0
  48. package/workers/vendor/csharp-runner/_framework/assemblies-02.pack +0 -0
  49. package/workers/vendor/csharp-runner/_framework/assemblies-03.pack +0 -0
  50. package/workers/vendor/csharp-runner/_framework/dotnet.boot.js +65 -65
  51. package/dist/cpp-worker-client-FLJ2YLSW.js +0 -12
package/dist/judge.cjs CHANGED
@@ -1132,7 +1132,7 @@ var init_Array = __esm({
1132
1132
  }
1133
1133
  return out;
1134
1134
  });
1135
- fromIterable = (collection) => Array.isArray(collection) ? collection : Array.from(collection);
1135
+ fromIterable = (collection2) => Array.isArray(collection2) ? collection2 : Array.from(collection2);
1136
1136
  ensure = (self2) => Array.isArray(self2) ? self2 : [self2];
1137
1137
  prepend = /* @__PURE__ */ dual(2, (self2, head4) => [head4, ...self2]);
1138
1138
  append = /* @__PURE__ */ dual(2, (self2, last3) => [...self2, last3]);
@@ -9877,17 +9877,17 @@ var init_redBlackTree = __esm({
9877
9877
  });
9878
9878
  keysForward = (self2) => keys3(self2, Direction.Forward);
9879
9879
  keys3 = (self2, direction) => {
9880
- const begin = self2[Symbol.iterator]();
9880
+ const begin2 = self2[Symbol.iterator]();
9881
9881
  let count = 0;
9882
9882
  return {
9883
9883
  [Symbol.iterator]: () => keys3(self2, direction),
9884
9884
  next: () => {
9885
9885
  count++;
9886
- const entry = begin.key;
9886
+ const entry = begin2.key;
9887
9887
  if (direction === Direction.Forward) {
9888
- begin.moveNext();
9888
+ begin2.moveNext();
9889
9889
  } else {
9890
- begin.movePrev();
9890
+ begin2.movePrev();
9891
9891
  }
9892
9892
  switch (entry._tag) {
9893
9893
  case "None": {
@@ -13074,7 +13074,7 @@ var init_runtime_language_info_data = __esm({
13074
13074
  "versionLabel": "Python 3.13.2",
13075
13075
  "executionPlatform": {
13076
13076
  "name": "TraceKernel",
13077
- "version": "0.16.3"
13077
+ "version": "0.16.5"
13078
13078
  },
13079
13079
  "description": "Python 3.13.2 runs in TraceKernel's isolated Python runtime.\n\nCommon algorithm helpers are imported automatically, including array, bisect, collections, functools, heapq, itertools. Other standard-library modules can be imported normally.\n\nOptional third-party packages are consumer-owned runtime assets and are available only when declared by the TraceKernel runtime manifest.",
13080
13080
  "runtime": {
@@ -13101,7 +13101,7 @@ var init_runtime_language_info_data = __esm({
13101
13101
  "versionLabel": "JavaScript (ECMAScript 2023)",
13102
13102
  "executionPlatform": {
13103
13103
  "name": "TraceKernel",
13104
- "version": "0.16.3"
13104
+ "version": "0.16.5"
13105
13105
  },
13106
13106
  "runtime": {
13107
13107
  "name": "TraceKernel JavaScript runtime",
@@ -13193,7 +13193,7 @@ Binary Search Tree, Trie, and Graph are bundled too, but are not exposed globall
13193
13193
  "versionLabel": "TypeScript 5.9.3",
13194
13194
  "executionPlatform": {
13195
13195
  "name": "TraceKernel",
13196
- "version": "0.16.3"
13196
+ "version": "0.16.5"
13197
13197
  },
13198
13198
  "description": `TypeScript 5.9.3 is compiled with the TypeScript compiler and executed by TraceKernel's JavaScript runtime.
13199
13199
 
@@ -13293,7 +13293,7 @@ The compiled output runs on the same TraceKernel execution lane as JavaScript su
13293
13293
  "versionLabel": "Java 23",
13294
13294
  "executionPlatform": {
13295
13295
  "name": "TraceKernel",
13296
- "version": "0.16.3"
13296
+ "version": "0.16.5"
13297
13297
  },
13298
13298
  "description": "Java 23 is compiled with javac 23 and executed by the Java runtime on TraceKernel.\n\nCommon imports are added automatically: java.util.*, java.io.*, java.math.*, java.util.stream.*, javafx.util.Pair.",
13299
13299
  "runtime": {
@@ -13330,7 +13330,7 @@ The compiled output runs on the same TraceKernel execution lane as JavaScript su
13330
13330
  "versionLabel": "C# 14",
13331
13331
  "executionPlatform": {
13332
13332
  "name": "TraceKernel",
13333
- "version": "0.16.3"
13333
+ "version": "0.16.5"
13334
13334
  },
13335
13335
  "description": "C# 14 source is compiled and executed by TraceKernel's isolated C# runtime.\n\nCommon namespaces are imported automatically: System, System.Collections, System.Collections.Generic, System.IO, System.Linq, System.Numerics, System.Text, System.Text.RegularExpressions.",
13336
13336
  "runtime": {
@@ -13359,7 +13359,7 @@ The compiled output runs on the same TraceKernel execution lane as JavaScript su
13359
13359
  "versionLabel": "C++23",
13360
13360
  "executionPlatform": {
13361
13361
  "name": "TraceKernel",
13362
- "version": "0.16.3"
13362
+ "version": "0.16.5"
13363
13363
  },
13364
13364
  "description": "C++ source is compiled using the C++23 standard.\n\nSubmissions compile to WebAssembly and run in TraceKernel's WASI execution lane. The compiler currently uses -O0 and -fno-exceptions, with a fixed program stack size.\n\nCommon standard library headers are included automatically, including <algorithm>, <array>, <bitset>, <climits>, <cmath>, <cstdint>, <functional>, <limits>, <numeric>, <sstream>, <tuple>, <vector>, <unordered_map>, <unordered_set> and more.",
13365
13365
  "runtime": {
@@ -13524,7 +13524,7 @@ var init_runtime_open_source_info_data = __esm({
13524
13524
  {
13525
13525
  "kind": "modifications",
13526
13526
  "label": "Runtime modifications",
13527
- "url": "https://github.com/tracecodeapp/harness/tree/v0.16.3/workers/python/pyodide-0.29.3"
13527
+ "url": "https://github.com/tracecodeapp/harness/tree/v0.16.5/workers/python/pyodide-0.29.3"
13528
13528
  }
13529
13529
  ]
13530
13530
  }
@@ -15043,6 +15043,81 @@ var init_runtime_profiles = __esm({
15043
15043
  }
15044
15044
  });
15045
15045
 
15046
+ // packages/runtime-browser/src/background-work-scheduler.ts
15047
+ function createPromotableBrowserBackgroundTask(work) {
15048
+ let permanentlyCancelled = false;
15049
+ let task = null;
15050
+ let idleHandle = null;
15051
+ let backgroundController = null;
15052
+ let resolveCompletion;
15053
+ let rejectCompletion;
15054
+ const completion = new Promise((resolve, reject) => {
15055
+ resolveCompletion = resolve;
15056
+ rejectCompletion = reject;
15057
+ });
15058
+ void completion.catch(() => void 0);
15059
+ const start = () => {
15060
+ if (permanentlyCancelled) return Promise.resolve();
15061
+ if (!task) {
15062
+ task = Promise.resolve().then(work);
15063
+ task.then(resolveCompletion, rejectCompletion);
15064
+ void task.catch(() => void 0);
15065
+ }
15066
+ return task;
15067
+ };
15068
+ const cancelPendingCallback = () => {
15069
+ if (idleHandle !== null && typeof globalThis.cancelIdleCallback === "function") {
15070
+ globalThis.cancelIdleCallback(idleHandle);
15071
+ idleHandle = null;
15072
+ }
15073
+ backgroundController?.abort();
15074
+ backgroundController = null;
15075
+ };
15076
+ if (typeof globalThis.requestIdleCallback === "function") {
15077
+ idleHandle = globalThis.requestIdleCallback(() => {
15078
+ idleHandle = null;
15079
+ void start();
15080
+ });
15081
+ } else {
15082
+ const scheduler = globalThis.scheduler;
15083
+ if (scheduler?.postTask) {
15084
+ backgroundController = new AbortController();
15085
+ void scheduler.postTask(
15086
+ () => {
15087
+ backgroundController = null;
15088
+ return start();
15089
+ },
15090
+ {
15091
+ priority: "background",
15092
+ signal: backgroundController.signal
15093
+ }
15094
+ ).catch(() => void 0);
15095
+ }
15096
+ }
15097
+ return {
15098
+ promote: () => {
15099
+ cancelPendingCallback();
15100
+ return start();
15101
+ },
15102
+ wait: () => completion,
15103
+ cancel: () => {
15104
+ if (permanentlyCancelled) return;
15105
+ permanentlyCancelled = true;
15106
+ cancelPendingCallback();
15107
+ if (!task) {
15108
+ rejectCompletion(
15109
+ new DOMException("Browser background work was cancelled.", "AbortError")
15110
+ );
15111
+ }
15112
+ }
15113
+ };
15114
+ }
15115
+ var init_background_work_scheduler = __esm({
15116
+ "packages/runtime-browser/src/background-work-scheduler.ts"() {
15117
+ "use strict";
15118
+ }
15119
+ });
15120
+
15046
15121
  // packages/runtime-browser/src/runtime-capability-guards.ts
15047
15122
  function isScriptRequest(functionName) {
15048
15123
  if (functionName == null) return true;
@@ -15138,7 +15213,7 @@ var init_package = __esm({
15138
15213
  "package.json"() {
15139
15214
  package_default = {
15140
15215
  name: "@tracecode/harness",
15141
- version: "0.16.3",
15216
+ version: "0.16.5",
15142
15217
  license: "AGPL-3.0-only",
15143
15218
  homepage: "https://tracecode.app",
15144
15219
  repository: {
@@ -15206,6 +15281,15 @@ var init_package = __esm({
15206
15281
  "build:browser-host": "pnpm exec tsup --config tsup.browser-host.config.ts",
15207
15282
  "build:tracekernel": "pnpm exec tsup --config tsup.tracekernel.config.ts",
15208
15283
  "generate:runtime-info": "pnpm exec tsx --tsconfig tsconfig.base.json scripts/generate-runtime-language-info.ts",
15284
+ "generate:traceclr-profile": "node scripts/generate-traceclr-algorithm-profile.mjs",
15285
+ "audit:traceclr-corpus": "node scripts/audit-traceclr-corpus.mjs",
15286
+ "build:traceclr-product-corpus": "node scripts/create-traceclr-product-corpus.mjs",
15287
+ "check:traceclr-profile": "node --test tests/test-traceclr-algorithm-profile.mjs tests/test-traceclr-profile-policy.mjs && node --import tsx tests/test-traceclr-wire-codec.ts",
15288
+ "check:traceclr-product-profile": "node scripts/generate-traceclr-algorithm-profile.mjs --check && pnpm check:traceclr-profile",
15289
+ "build:traceclr-wire-probe": "dotnet build tools/TraceCode.TraceClrWireProbe/TraceCode.TraceClrWireProbe.csproj -c Release && dotnet build tools/TraceCode.TraceClrHostileProbe/TraceCode.TraceClrHostileProbe.csproj -c Release && dotnet publish packages/runtime-csharp/dotnet/TraceCode.CSharpAlgorithmRunner/TraceCode.CSharpAlgorithmRunner.csproj -c Release",
15290
+ "test:traceclr-wire-browser": "pnpm build:traceclr-wire-probe && TRACECODE_TRACECLR_BROWSER_ENGINE=chromium node --import tsx tests/test-traceclr-wire-runner-browser.ts && TRACECODE_TRACECLR_BROWSER_ENGINE=firefox node --import tsx tests/test-traceclr-wire-runner-browser.ts && TRACECODE_TRACECLR_BROWSER_ENGINE=webkit node --import tsx tests/test-traceclr-wire-runner-browser.ts",
15291
+ "bench:traceclr-tiers": "pnpm build:traceclr-wire-probe && pnpm materialize:csharp-role-assets && node --import tsx scripts/benchmark-traceclr-runtime-tiers.ts",
15292
+ "bench:traceclr-tiers:matrix": "pnpm build:traceclr-wire-probe && pnpm materialize:csharp-role-assets && for engine in chromium firefox webkit; do TRACECODE_TRACECLR_BROWSER_ENGINE=$engine node --import tsx scripts/benchmark-traceclr-runtime-tiers.ts || exit; done",
15209
15293
  "generate:runtime-open-source-info": "pnpm exec tsx --tsconfig tsconfig.base.json scripts/generate-runtime-open-source-info.ts",
15210
15294
  "generate:python-harness": "pnpm exec tsx --tsconfig tsconfig.base.json scripts/generate-python-harness-artifacts.ts",
15211
15295
  "generate:runtime-assets-lock": "node --import tsx scripts/generate-runtime-assets-lock.mjs",
@@ -15269,10 +15353,10 @@ var init_package = __esm({
15269
15353
  "test:java-runtime": "pnpm exec tsx --tsconfig tsconfig.base.json tests/test-java-runtime.ts && pnpm exec tsx --tsconfig tsconfig.base.json tests/test-java-project-filesystem.ts && node --import tsx --test tests/test-java-jar-manifest.ts && pnpm exec tsx --tsconfig tsconfig.base.json tests/test-java-project-provider.ts && TSX_TSCONFIG_PATH=tsconfig.base.json node --import tsx --test tests/test-java-prepared-provider.ts",
15270
15354
  "test:java-prepared-provider": "TSX_TSCONFIG_PATH=tsconfig.base.json node --import tsx --test tests/test-java-prepared-provider.ts && pnpm exec tsx --tsconfig tsconfig.base.json tests/test-java-prepared-provider-browser.ts",
15271
15355
  "test:tracejvm-semantic-trace": "node --import tsx tests/test-tracejvm-semantic-trace-matrix.ts",
15272
- "test:csharp-runtime": "pnpm exec tsx --tsconfig tsconfig.base.json scripts/validate-csharp-runtime-role-assets.ts && TSX_TSCONFIG_PATH=tsconfig.base.json node --import tsx --test tests/test-csharp-role-artifacts.ts tests/test-csharp-managed-assembly-packs.ts && pnpm exec tsx --tsconfig tsconfig.base.json tests/test-csharp-runtime.ts && TSX_TSCONFIG_PATH=tsconfig.base.json node --import tsx --test tests/test-csharp-prepared-provider.ts && pnpm exec tsx --tsconfig tsconfig.base.json tests/test-csharp-project-fs-parity.ts",
15356
+ "test:csharp-runtime": "pnpm check:traceclr-profile && pnpm exec tsx --tsconfig tsconfig.base.json scripts/validate-csharp-runtime-role-assets.ts && TSX_TSCONFIG_PATH=tsconfig.base.json node --import tsx --test tests/test-csharp-role-artifacts.ts tests/test-csharp-managed-assembly-packs.ts && pnpm exec tsx --tsconfig tsconfig.base.json tests/test-csharp-runtime.ts && TSX_TSCONFIG_PATH=tsconfig.base.json node --import tsx --test tests/test-csharp-prepared-provider.ts && pnpm exec tsx --tsconfig tsconfig.base.json tests/test-csharp-project-fs-parity.ts",
15273
15357
  "test:csharp-role-assets": "pnpm materialize:csharp-role-assets && TSX_TSCONFIG_PATH=tsconfig.base.json node --import tsx --test tests/test-csharp-role-artifacts.ts tests/test-csharp-managed-assembly-packs.ts && pnpm exec tsx --tsconfig tsconfig.base.json scripts/validate-csharp-runtime-role-assets.ts",
15274
15358
  "test:csharp-worker-browser": "pnpm materialize:csharp-role-assets && pnpm exec tsx --tsconfig tsconfig.base.json tests/test-csharp-worker-client-http.ts && pnpm exec tsx --tsconfig tsconfig.base.json tests/test-csharp-worker-browser.ts && pnpm exec tsx --tsconfig tsconfig.base.json tests/test-csharp-worker-lifecycle-browser.ts && pnpm exec tsx --tsconfig tsconfig.base.json tests/test-csharp-prepared-boundary-browser.ts",
15275
- "test:csharp-worker-browser-matrix": "pnpm materialize:csharp-role-assets && TRACECODE_CSHARP_BROWSER_SMOKE=1 TRACECODE_CSHARP_BROWSER_ENGINE=chromium pnpm exec tsx --tsconfig tsconfig.base.json tests/test-csharp-worker-browser.ts && TRACECODE_CSHARP_BROWSER_SMOKE=1 TRACECODE_CSHARP_BROWSER_ENGINE=firefox pnpm exec tsx --tsconfig tsconfig.base.json tests/test-csharp-worker-browser.ts && TRACECODE_CSHARP_BROWSER_SMOKE=1 TRACECODE_CSHARP_BROWSER_ENGINE=webkit pnpm exec tsx --tsconfig tsconfig.base.json tests/test-csharp-worker-browser.ts",
15359
+ "test:csharp-worker-browser-matrix": "pnpm materialize:csharp-role-assets && for engine in chromium firefox webkit; do TSX_TSCONFIG_PATH=tsconfig.base.json TRACECODE_CSHARP_BROWSER_SMOKE=1 TRACECODE_CSHARP_BROWSER_ENGINE=$engine node --import tsx tests/test-csharp-worker-browser.ts && TSX_TSCONFIG_PATH=tsconfig.base.json TRACECODE_CSHARP_BROWSER_ENGINE=$engine node --import tsx tests/test-csharp-prepared-boundary-browser.ts || exit; done",
15276
15360
  "test:cpp-runtime": "pnpm exec tsx --tsconfig tsconfig.base.json tests/test-cpp-runtime.ts",
15277
15361
  "test:cpp-conformance": "pnpm exec tsx --tsconfig tsconfig.base.json tests/test-cpp-conformance.ts",
15278
15362
  "test:cpp-script-lambda-trace": "pnpm exec tsx --tsconfig tsconfig.base.json tests/test-cpp-script-lambda-trace.ts",
@@ -19839,6 +19923,7 @@ var init_internal = __esm({
19839
19923
  "packages/runtime-browser/src/internal.ts"() {
19840
19924
  "use strict";
19841
19925
  init_browser_client_env();
19926
+ init_background_work_scheduler();
19842
19927
  init_execution_host();
19843
19928
  init_host_artifact_cache();
19844
19929
  init_kernel_http_async();
@@ -29277,6 +29362,466 @@ var init_tracejvm_runtime_assets = __esm({
29277
29362
  }
29278
29363
  });
29279
29364
 
29365
+ // packages/runtime-csharp/src/traceclr-wire.ts
29366
+ function parseWireType(text, depth = 0) {
29367
+ if (depth > TRACECLR_WIRE_LIMITS.maxDepth) throw new RangeError("TraceCLR wire type is too deeply nested.");
29368
+ if (text === "list-node<int32>") return { kind: "list-node" };
29369
+ if (text === "tree-node<int32>") return { kind: "tree-node" };
29370
+ for (const name of ["array", "list", "set"]) {
29371
+ const prefix = `${name}<`;
29372
+ if (text.startsWith(prefix) && text.endsWith(">")) {
29373
+ return { kind: "container", name, element: parseWireType(text.slice(prefix.length, -1), depth + 1) };
29374
+ }
29375
+ }
29376
+ const scalars = /* @__PURE__ */ new Set([
29377
+ "void",
29378
+ "null",
29379
+ "bool",
29380
+ "char",
29381
+ "uint8",
29382
+ "int8",
29383
+ "int16",
29384
+ "uint16",
29385
+ "int32",
29386
+ "uint32",
29387
+ "int64",
29388
+ "uint64",
29389
+ "float32",
29390
+ "float64",
29391
+ "string"
29392
+ ]);
29393
+ if (!scalars.has(text)) throw new TypeError(`Unsupported TraceCLR wire type: ${text}`);
29394
+ return { kind: "scalar", name: text };
29395
+ }
29396
+ function integer(value, minimum, maximum, label) {
29397
+ if (typeof value !== "number" || !Number.isInteger(value) || value < minimum || value > maximum) {
29398
+ throw new TypeError(`${label} must be an integer between ${minimum} and ${maximum}.`);
29399
+ }
29400
+ return value;
29401
+ }
29402
+ function integer64(value, signed) {
29403
+ let converted = null;
29404
+ if (typeof value === "bigint") {
29405
+ converted = value;
29406
+ } else if (typeof value === "number" && Number.isInteger(value)) {
29407
+ const jsonDecimal = JSON.stringify(value);
29408
+ if (jsonDecimal !== void 0) converted = BigInt(jsonDecimal);
29409
+ }
29410
+ const minimum = signed ? -(1n << 63n) : 0n;
29411
+ const maximum = signed ? (1n << 63n) - 1n : (1n << 64n) - 1n;
29412
+ if (converted === null || converted < minimum || converted > maximum) {
29413
+ throw new TypeError(`${signed ? "int64" : "uint64"} must be a bigint or integer number in range.`);
29414
+ }
29415
+ return converted;
29416
+ }
29417
+ function floatingPoint(value, label) {
29418
+ if (typeof value === "number") return Object.is(value, -0) ? 0 : value;
29419
+ if (value === "NaN") return Number.NaN;
29420
+ if (value === "Infinity") return Number.POSITIVE_INFINITY;
29421
+ if (value === "-Infinity") return Number.NEGATIVE_INFINITY;
29422
+ throw new TypeError(`${label} must be numeric or a named floating-point literal.`);
29423
+ }
29424
+ function collection(value, set6) {
29425
+ const items = set6 && value instanceof Set ? [...value] : value;
29426
+ if (!Array.isArray(items)) throw new TypeError("TraceCLR collection values must be arrays or Sets.");
29427
+ if (items.length > TRACECLR_WIRE_LIMITS.maxCollectionItems) {
29428
+ throw new RangeError(`TraceCLR collection exceeds ${TRACECLR_WIRE_LIMITS.maxCollectionItems} items.`);
29429
+ }
29430
+ return items;
29431
+ }
29432
+ function writeValue(writer, type, value, depth) {
29433
+ if (depth > TRACECLR_WIRE_LIMITS.maxDepth) throw new RangeError("TraceCLR value is too deeply nested.");
29434
+ if (type.kind === "container") {
29435
+ if (value === null) {
29436
+ writer.int32(-1);
29437
+ return;
29438
+ }
29439
+ const values3 = collection(value, type.name === "set");
29440
+ writer.int32(values3.length);
29441
+ for (const item of values3) writeValue(writer, type.element, item, depth + 1);
29442
+ return;
29443
+ }
29444
+ if (type.kind === "list-node") {
29445
+ if (value === null) {
29446
+ writer.int32(-1);
29447
+ return;
29448
+ }
29449
+ const values3 = Array.isArray(value) ? value : [];
29450
+ if (!Array.isArray(value)) {
29451
+ const seen = /* @__PURE__ */ new Set();
29452
+ let node = value;
29453
+ while (node !== null) {
29454
+ if (typeof node !== "object" || seen.has(node)) throw new TypeError("TraceCLR ListNode must be acyclic.");
29455
+ seen.add(node);
29456
+ values3.push(node.val ?? node.value);
29457
+ node = node.next ?? null;
29458
+ if (values3.length > TRACECLR_WIRE_LIMITS.maxCollectionItems) throw new RangeError("TraceCLR ListNode is too long.");
29459
+ }
29460
+ }
29461
+ writer.int32(values3.length);
29462
+ for (const item of values3) writer.int32(integer(item, -2147483648, 2147483647, "ListNode value"));
29463
+ return;
29464
+ }
29465
+ if (type.kind === "tree-node") {
29466
+ if (value === null) {
29467
+ writer.int32(-1);
29468
+ return;
29469
+ }
29470
+ let rawValues;
29471
+ if (Array.isArray(value)) {
29472
+ rawValues = value;
29473
+ } else if (typeof value === "object") {
29474
+ const values4 = [];
29475
+ const nodes = [value];
29476
+ for (let index = 0; index < nodes.length; index++) {
29477
+ const node = nodes[index];
29478
+ if (node === null) {
29479
+ values4.push(null);
29480
+ continue;
29481
+ }
29482
+ if (typeof node !== "object") throw new TypeError("TraceCLR TreeNode nodes must be objects or null.");
29483
+ const typed = node;
29484
+ values4.push(typed.val ?? typed.value);
29485
+ nodes.push(typed.left ?? null, typed.right ?? null);
29486
+ if (nodes.length > TRACECLR_WIRE_LIMITS.maxCollectionItems) throw new RangeError("TraceCLR TreeNode is too large.");
29487
+ }
29488
+ while (values4.at(-1) === null) values4.pop();
29489
+ rawValues = values4;
29490
+ } else {
29491
+ throw new TypeError("TraceCLR TreeNode inputs must be level-order arrays or node objects.");
29492
+ }
29493
+ const values3 = collection(rawValues, false);
29494
+ writer.int32(values3.length);
29495
+ for (const item of values3) {
29496
+ writer.uint8(item === null ? 0 : 1);
29497
+ if (item !== null) writer.int32(integer(item, -2147483648, 2147483647, "TreeNode value"));
29498
+ }
29499
+ return;
29500
+ }
29501
+ switch (type.name) {
29502
+ case "void":
29503
+ return;
29504
+ case "null":
29505
+ if (value !== null) throw new TypeError("TraceCLR null result must be null.");
29506
+ writer.uint8(0);
29507
+ return;
29508
+ case "bool":
29509
+ if (typeof value !== "boolean") throw new TypeError("bool must be boolean.");
29510
+ writer.uint8(value ? 1 : 0);
29511
+ return;
29512
+ case "char": {
29513
+ if (typeof value !== "string" || value.length !== 1) throw new TypeError("char must be one UTF-16 code unit.");
29514
+ writer.uint16(value.charCodeAt(0));
29515
+ return;
29516
+ }
29517
+ case "uint8":
29518
+ writer.uint8(integer(value, 0, 255, "uint8"));
29519
+ return;
29520
+ case "int8":
29521
+ writer.int8(integer(value, -128, 127, "int8"));
29522
+ return;
29523
+ case "int16":
29524
+ writer.int16(integer(value, -32768, 32767, "int16"));
29525
+ return;
29526
+ case "uint16":
29527
+ writer.uint16(integer(value, 0, 65535, "uint16"));
29528
+ return;
29529
+ case "int32":
29530
+ writer.int32(integer(value, -2147483648, 2147483647, "int32"));
29531
+ return;
29532
+ case "uint32":
29533
+ writer.uint32(integer(value, 0, 4294967295, "uint32"));
29534
+ return;
29535
+ case "int64":
29536
+ writer.int64(integer64(value, true));
29537
+ return;
29538
+ case "uint64":
29539
+ writer.uint64(integer64(value, false));
29540
+ return;
29541
+ case "float32":
29542
+ writer.float32(floatingPoint(value, "float32"));
29543
+ return;
29544
+ case "float64":
29545
+ writer.float64(floatingPoint(value, "float64"));
29546
+ return;
29547
+ case "string": {
29548
+ if (value === null) {
29549
+ writer.int32(-1);
29550
+ return;
29551
+ }
29552
+ if (typeof value !== "string") throw new TypeError("string must be a string or null.");
29553
+ const bytes2 = new TextEncoder().encode(value);
29554
+ writer.int32(bytes2.byteLength);
29555
+ writer.bytes(bytes2);
29556
+ return;
29557
+ }
29558
+ }
29559
+ }
29560
+ function normalizePortableResult(type, value) {
29561
+ if (value === null || value === void 0) return value;
29562
+ if (type.kind === "container") {
29563
+ const values3 = type.name === "set" && value instanceof Set ? [...value] : value;
29564
+ if (!Array.isArray(values3)) {
29565
+ throw new TypeError(`TraceCLR ${type.name} result did not decode to a collection.`);
29566
+ }
29567
+ return values3.map((item) => normalizePortableResult(type.element, item));
29568
+ }
29569
+ if (type.kind === "scalar" && (type.name === "int64" || type.name === "uint64")) {
29570
+ if (typeof value !== "bigint") {
29571
+ throw new TypeError(`TraceCLR ${type.name} result did not decode to a bigint.`);
29572
+ }
29573
+ return Number(value);
29574
+ }
29575
+ if (type.kind === "scalar" && (type.name === "float32" || type.name === "float64")) {
29576
+ if (typeof value !== "number") {
29577
+ throw new TypeError(`TraceCLR ${type.name} result did not decode to a number.`);
29578
+ }
29579
+ if (Number.isNaN(value)) return "NaN";
29580
+ if (value === Number.POSITIVE_INFINITY) return "Infinity";
29581
+ if (value === Number.NEGATIVE_INFINITY) return "-Infinity";
29582
+ }
29583
+ return value;
29584
+ }
29585
+ function readLength(reader) {
29586
+ const length3 = reader.int32();
29587
+ if (length3 === -1) return null;
29588
+ if (length3 < 0 || length3 > TRACECLR_WIRE_LIMITS.maxCollectionItems) {
29589
+ throw new RangeError(`Invalid TraceCLR collection length: ${length3}.`);
29590
+ }
29591
+ return length3;
29592
+ }
29593
+ function readByteLength(reader) {
29594
+ const length3 = reader.int32();
29595
+ if (length3 === -1) return null;
29596
+ if (length3 < 0 || length3 > TRACECLR_WIRE_LIMITS.maxBytes) {
29597
+ throw new RangeError(`Invalid TraceCLR byte length: ${length3}.`);
29598
+ }
29599
+ return length3;
29600
+ }
29601
+ function readValue(reader, type, depth) {
29602
+ if (depth > TRACECLR_WIRE_LIMITS.maxDepth) throw new RangeError("TraceCLR value is too deeply nested.");
29603
+ if (type.kind === "container") {
29604
+ const length3 = readLength(reader);
29605
+ if (length3 === null) return null;
29606
+ const values3 = Array.from({ length: length3 }, () => readValue(reader, type.element, depth + 1));
29607
+ return type.name === "set" ? new Set(values3) : values3;
29608
+ }
29609
+ if (type.kind === "list-node") {
29610
+ const length3 = readLength(reader);
29611
+ return length3 === null ? null : Array.from({ length: length3 }, () => reader.int32());
29612
+ }
29613
+ if (type.kind === "tree-node") {
29614
+ const length3 = readLength(reader);
29615
+ if (length3 === null) return null;
29616
+ const values3 = Array.from({ length: length3 }, () => reader.uint8() === 0 ? null : reader.int32());
29617
+ while (values3.at(-1) === null) values3.pop();
29618
+ return values3;
29619
+ }
29620
+ switch (type.name) {
29621
+ case "void":
29622
+ return void 0;
29623
+ case "null":
29624
+ if (reader.uint8() !== 0) throw new RangeError("Invalid TraceCLR null marker.");
29625
+ return null;
29626
+ case "bool": {
29627
+ const value = reader.uint8();
29628
+ if (value > 1) throw new RangeError("Invalid TraceCLR bool.");
29629
+ return value === 1;
29630
+ }
29631
+ case "char":
29632
+ return String.fromCharCode(reader.uint16());
29633
+ case "uint8":
29634
+ return reader.uint8();
29635
+ case "int8":
29636
+ return reader.int8();
29637
+ case "int16":
29638
+ return reader.int16();
29639
+ case "uint16":
29640
+ return reader.uint16();
29641
+ case "int32":
29642
+ return reader.int32();
29643
+ case "uint32":
29644
+ return reader.uint32();
29645
+ case "int64":
29646
+ return reader.int64();
29647
+ case "uint64":
29648
+ return reader.uint64();
29649
+ case "float32":
29650
+ return reader.float32();
29651
+ case "float64":
29652
+ return reader.float64();
29653
+ case "string": {
29654
+ const length3 = readByteLength(reader);
29655
+ return length3 === null ? null : new TextDecoder("utf-8", { fatal: true }).decode(reader.bytes(length3));
29656
+ }
29657
+ }
29658
+ }
29659
+ function begin(writer) {
29660
+ writer.uint32(WIRE_MAGIC);
29661
+ }
29662
+ function verify(reader) {
29663
+ if (reader.uint32() !== WIRE_MAGIC) throw new RangeError("TraceCLR wire magic/version mismatch.");
29664
+ }
29665
+ function encodeTraceClrWireInputs(contract, inputs) {
29666
+ const writer = new WireWriter();
29667
+ begin(writer);
29668
+ writer.uint16(contract.parameters.length);
29669
+ const positionalInputs = Object.values(inputs);
29670
+ for (const [index, parameter] of contract.parameters.entries()) {
29671
+ const value = Object.prototype.hasOwnProperty.call(inputs, parameter.name) ? inputs[parameter.name] : positionalInputs[index];
29672
+ if (value === void 0 && !Object.prototype.hasOwnProperty.call(inputs, parameter.name) && index >= positionalInputs.length) {
29673
+ throw new TypeError(`Missing TraceCLR input: ${parameter.name}`);
29674
+ }
29675
+ writeValue(writer, parseWireType(parameter.type.wireType), value, 0);
29676
+ }
29677
+ return writer.finish();
29678
+ }
29679
+ function decodeTraceClrWireResult(contract, bytes2) {
29680
+ const reader = new WireReader(bytes2);
29681
+ verify(reader);
29682
+ const type = parseWireType(contract.returnType.wireType);
29683
+ const value = readValue(reader, type, 0);
29684
+ reader.done();
29685
+ return normalizePortableResult(type, value);
29686
+ }
29687
+ var WIRE_MAGIC, TRACECLR_WIRE_LIMITS, WireWriter, WireReader;
29688
+ var init_traceclr_wire = __esm({
29689
+ "packages/runtime-csharp/src/traceclr-wire.ts"() {
29690
+ "use strict";
29691
+ WIRE_MAGIC = 827802452;
29692
+ TRACECLR_WIRE_LIMITS = Object.freeze({
29693
+ maxBytes: 16 * 1024 * 1024,
29694
+ maxCollectionItems: 1e6,
29695
+ maxDepth: 128
29696
+ });
29697
+ WireWriter = class {
29698
+ buffer = new ArrayBuffer(256);
29699
+ view = new DataView(this.buffer);
29700
+ length = 0;
29701
+ reserve(bytes2) {
29702
+ const next2 = this.length + bytes2;
29703
+ if (!Number.isSafeInteger(bytes2) || bytes2 < 0 || next2 > TRACECLR_WIRE_LIMITS.maxBytes) {
29704
+ throw new RangeError(`TraceCLR wire payload exceeds ${TRACECLR_WIRE_LIMITS.maxBytes} bytes.`);
29705
+ }
29706
+ if (next2 > this.buffer.byteLength) {
29707
+ let capacity3 = this.buffer.byteLength;
29708
+ while (capacity3 < next2) capacity3 = Math.min(TRACECLR_WIRE_LIMITS.maxBytes, capacity3 * 2);
29709
+ const replacement = new ArrayBuffer(capacity3);
29710
+ new Uint8Array(replacement).set(new Uint8Array(this.buffer, 0, this.length));
29711
+ this.buffer = replacement;
29712
+ this.view = new DataView(replacement);
29713
+ }
29714
+ const offset = this.length;
29715
+ this.length = next2;
29716
+ return offset;
29717
+ }
29718
+ uint8(value) {
29719
+ const offset = this.reserve(1);
29720
+ this.view.setUint8(offset, value);
29721
+ }
29722
+ int8(value) {
29723
+ const offset = this.reserve(1);
29724
+ this.view.setInt8(offset, value);
29725
+ }
29726
+ int16(value) {
29727
+ const offset = this.reserve(2);
29728
+ this.view.setInt16(offset, value, true);
29729
+ }
29730
+ uint16(value) {
29731
+ const offset = this.reserve(2);
29732
+ this.view.setUint16(offset, value, true);
29733
+ }
29734
+ int32(value) {
29735
+ const offset = this.reserve(4);
29736
+ this.view.setInt32(offset, value, true);
29737
+ }
29738
+ uint32(value) {
29739
+ const offset = this.reserve(4);
29740
+ this.view.setUint32(offset, value, true);
29741
+ }
29742
+ int64(value) {
29743
+ const offset = this.reserve(8);
29744
+ this.view.setBigInt64(offset, value, true);
29745
+ }
29746
+ uint64(value) {
29747
+ const offset = this.reserve(8);
29748
+ this.view.setBigUint64(offset, value, true);
29749
+ }
29750
+ float32(value) {
29751
+ const offset = this.reserve(4);
29752
+ this.view.setFloat32(offset, value, true);
29753
+ }
29754
+ float64(value) {
29755
+ const offset = this.reserve(8);
29756
+ this.view.setFloat64(offset, value, true);
29757
+ }
29758
+ bytes(value) {
29759
+ const offset = this.reserve(value.byteLength);
29760
+ new Uint8Array(this.buffer, offset, value.byteLength).set(value);
29761
+ }
29762
+ finish() {
29763
+ return new Uint8Array(this.buffer.slice(0, this.length));
29764
+ }
29765
+ };
29766
+ WireReader = class {
29767
+ view;
29768
+ offset = 0;
29769
+ constructor(bytes2) {
29770
+ if (bytes2.byteLength > TRACECLR_WIRE_LIMITS.maxBytes) {
29771
+ throw new RangeError(`TraceCLR wire payload exceeds ${TRACECLR_WIRE_LIMITS.maxBytes} bytes.`);
29772
+ }
29773
+ this.view = new DataView(bytes2.buffer, bytes2.byteOffset, bytes2.byteLength);
29774
+ }
29775
+ take(bytes2) {
29776
+ if (this.offset + bytes2 > this.view.byteLength) {
29777
+ throw new RangeError("TraceCLR wire payload ended unexpectedly.");
29778
+ }
29779
+ const offset = this.offset;
29780
+ this.offset += bytes2;
29781
+ return offset;
29782
+ }
29783
+ uint8() {
29784
+ return this.view.getUint8(this.take(1));
29785
+ }
29786
+ int8() {
29787
+ return this.view.getInt8(this.take(1));
29788
+ }
29789
+ int16() {
29790
+ return this.view.getInt16(this.take(2), true);
29791
+ }
29792
+ uint16() {
29793
+ return this.view.getUint16(this.take(2), true);
29794
+ }
29795
+ int32() {
29796
+ return this.view.getInt32(this.take(4), true);
29797
+ }
29798
+ uint32() {
29799
+ return this.view.getUint32(this.take(4), true);
29800
+ }
29801
+ int64() {
29802
+ return this.view.getBigInt64(this.take(8), true);
29803
+ }
29804
+ uint64() {
29805
+ return this.view.getBigUint64(this.take(8), true);
29806
+ }
29807
+ float32() {
29808
+ return this.view.getFloat32(this.take(4), true);
29809
+ }
29810
+ float64() {
29811
+ return this.view.getFloat64(this.take(8), true);
29812
+ }
29813
+ bytes(length3) {
29814
+ return new Uint8Array(this.view.buffer, this.view.byteOffset + this.take(length3), length3);
29815
+ }
29816
+ done() {
29817
+ if (this.offset !== this.view.byteLength) {
29818
+ throw new RangeError(`TraceCLR wire payload has ${this.view.byteLength - this.offset} trailing bytes.`);
29819
+ }
29820
+ }
29821
+ };
29822
+ }
29823
+ });
29824
+
29280
29825
  // packages/runtime-csharp/src/csharp-worker-client.ts
29281
29826
  var csharp_worker_client_exports = {};
29282
29827
  __export(csharp_worker_client_exports, {
@@ -29305,6 +29850,7 @@ var init_csharp_worker_client = __esm({
29305
29850
  init_internal();
29306
29851
  init_internal();
29307
29852
  init_internal();
29853
+ init_traceclr_wire();
29308
29854
  EXECUTION_TIMEOUT_MS4 = 2e4;
29309
29855
  TRACING_TIMEOUT_MS4 = 2e4;
29310
29856
  INIT_TIMEOUT_MS4 = 45e3;
@@ -29671,12 +30217,17 @@ var init_csharp_worker_client = __esm({
29671
30217
  async executePreparedCode(prepared, call) {
29672
30218
  return this.runPreparedExecutionGeneration(call.signal, async () => {
29673
30219
  const wallClockMs = call.limits?.wallClockMs ?? this.executionTimeoutMs;
30220
+ const inputBytes = prepared.preparedRunnerTier === "algorithm-fast" ? encodeTraceClrWireInputs(
30221
+ prepared.traceClrWireContract,
30222
+ call.inputs
30223
+ ) : void 0;
29674
30224
  const program = this.preparedReadyEffect().pipe(
29675
30225
  andThen4(
29676
30226
  this.core.withExecutionDeadline(
29677
30227
  this.sendCommandEffect("execute-prepared-code", {
29678
30228
  prepared,
29679
30229
  inputs: call.inputs,
30230
+ ...inputBytes ? { inputBytes } : {},
29680
30231
  assetBaseUrl: this.options.assetBaseUrl,
29681
30232
  timeoutMs: Math.max(100, wallClockMs - 1e3),
29682
30233
  ...this.workerOptionsPayload()
@@ -29686,6 +30237,17 @@ var init_csharp_worker_client = __esm({
29686
30237
  )
29687
30238
  );
29688
30239
  const result = await this.core.runClientEffect(program, call.signal);
30240
+ if (prepared.preparedRunnerTier === "algorithm-fast" && result.success) {
30241
+ if (!(result.outputBytes instanceof Uint8Array)) {
30242
+ throw new TypeError(
30243
+ "The algorithm-fast C# runner returned no binary output payload."
30244
+ );
30245
+ }
30246
+ result.output = decodeTraceClrWireResult(
30247
+ prepared.traceClrWireContract,
30248
+ result.outputBytes
30249
+ );
30250
+ }
29689
30251
  return this.toCodeExecutionResult(result);
29690
30252
  });
29691
30253
  }
@@ -29697,6 +30259,10 @@ var init_csharp_worker_client = __esm({
29697
30259
  }
29698
30260
  return this.runPreparedExecutionGeneration(call.signal, async () => {
29699
30261
  const wallClockMs = call.limits?.wallClockMs ?? this.resolveTracingTimeoutMs(prepared.functionName, prepared.executionStyle);
30262
+ const inputBytes = prepared.preparedRunnerTier === "algorithm-fast" ? encodeTraceClrWireInputs(
30263
+ prepared.traceClrWireContract,
30264
+ call.inputs
30265
+ ) : void 0;
29700
30266
  let result;
29701
30267
  const program = this.preparedReadyEffect().pipe(
29702
30268
  andThen4(
@@ -29704,6 +30270,7 @@ var init_csharp_worker_client = __esm({
29704
30270
  this.sendCommandEffect("execute-prepared-trace", {
29705
30271
  prepared,
29706
30272
  inputs: call.inputs,
30273
+ ...inputBytes ? { inputBytes } : {},
29707
30274
  ...call.recordTrace === void 0 ? {} : { tracingEnabled: call.recordTrace },
29708
30275
  assetBaseUrl: this.options.assetBaseUrl,
29709
30276
  timeoutMs: Math.max(100, wallClockMs - 1e3),
@@ -29719,6 +30286,17 @@ var init_csharp_worker_client = __esm({
29719
30286
  } catch (error) {
29720
30287
  return this.traceClientFailure(error, wallClockMs);
29721
30288
  }
30289
+ if (prepared.preparedRunnerTier === "algorithm-fast" && result.success) {
30290
+ if (!(result.outputBytes instanceof Uint8Array)) {
30291
+ throw new TypeError(
30292
+ "The algorithm-fast C# trace runner returned no binary output payload."
30293
+ );
30294
+ }
30295
+ result.output = decodeTraceClrWireResult(
30296
+ prepared.traceClrWireContract,
30297
+ result.outputBytes
30298
+ );
30299
+ }
29722
30300
  return this.toTraceExecutionResult(
29723
30301
  result,
29724
30302
  prepared.traceOptions,
@@ -29908,6 +30486,7 @@ function createCppPreparedExecutionProvider(options) {
29908
30486
  let terminated = false;
29909
30487
  const ownedClients = /* @__PURE__ */ new Set();
29910
30488
  const activePrograms = /* @__PURE__ */ new Set();
30489
+ let scheduledCompilerPrewarm = null;
29911
30490
  const createClient = () => {
29912
30491
  const client = options.createWorkerClient();
29913
30492
  ownedClients.add(client);
@@ -29935,6 +30514,21 @@ function createCppPreparedExecutionProvider(options) {
29935
30514
  standbyClient = null;
29936
30515
  return client;
29937
30516
  };
30517
+ const cancelScheduledCompilerPrewarm = () => {
30518
+ scheduledCompilerPrewarm?.cancel();
30519
+ scheduledCompilerPrewarm = null;
30520
+ };
30521
+ const scheduleCompilerPrewarm = () => {
30522
+ if (terminated || scheduledCompilerPrewarm || !options.prewarmCompiler || !options.scheduleCompilerPrewarm) {
30523
+ return;
30524
+ }
30525
+ const expectedGeneration = generation;
30526
+ scheduledCompilerPrewarm = options.scheduleCompilerPrewarm(async () => {
30527
+ assertGeneration(expectedGeneration);
30528
+ await options.prewarmCompiler?.();
30529
+ assertGeneration(expectedGeneration);
30530
+ });
30531
+ };
29938
30532
  return {
29939
30533
  async init() {
29940
30534
  assertActive();
@@ -29953,6 +30547,7 @@ function createCppPreparedExecutionProvider(options) {
29953
30547
  const result = await client.init();
29954
30548
  assertGeneration(expectedGeneration);
29955
30549
  standbyClient = client;
30550
+ scheduleCompilerPrewarm();
29956
30551
  return {
29957
30552
  success: result.success,
29958
30553
  loadTimeMs: result.loadTimeMs
@@ -29964,6 +30559,12 @@ function createCppPreparedExecutionProvider(options) {
29964
30559
  },
29965
30560
  async prepareProgram(call) {
29966
30561
  const expectedGeneration = generation;
30562
+ const compilerPrewarm = scheduledCompilerPrewarm;
30563
+ scheduledCompilerPrewarm = null;
30564
+ if (compilerPrewarm) {
30565
+ await compilerPrewarm.promote().catch(() => void 0);
30566
+ assertGeneration(expectedGeneration);
30567
+ }
29967
30568
  const client = acquireClient();
29968
30569
  try {
29969
30570
  await client.init();
@@ -30094,6 +30695,7 @@ function createCppPreparedExecutionProvider(options) {
30094
30695
  },
30095
30696
  reset() {
30096
30697
  assertActive();
30698
+ cancelScheduledCompilerPrewarm();
30097
30699
  generation += 1;
30098
30700
  for (const forceDispose of [...activePrograms]) forceDispose();
30099
30701
  for (const client of [...ownedClients]) retireClient(client);
@@ -30101,6 +30703,7 @@ function createCppPreparedExecutionProvider(options) {
30101
30703
  },
30102
30704
  terminate() {
30103
30705
  if (terminated) return;
30706
+ cancelScheduledCompilerPrewarm();
30104
30707
  generation += 1;
30105
30708
  terminated = true;
30106
30709
  for (const forceDispose of [...activePrograms]) forceDispose();
@@ -31553,8 +32156,30 @@ var init_tracecc_compiler_service = __esm({
31553
32156
  requestTimeoutMs;
31554
32157
  artifactCache = /* @__PURE__ */ new Map();
31555
32158
  artifactCacheBytes = 0;
32159
+ /**
32160
+ * Fetch and verify the immutable compiler inputs inside the trusted compiler
32161
+ * Worker without compiling or instantiating TraceCC. A foreground compile
32162
+ * joins the Worker's immutable byte cache.
32163
+ */
32164
+ async prewarmAssets(shard = "narrow") {
32165
+ await this.ensureWorker();
32166
+ const selected = this.options.shards[shard];
32167
+ const result = await this.send("prewarm-trusted-tracecc-assets", {
32168
+ ...this.traceccAssets(
32169
+ selected,
32170
+ `/tracecc-assets/${shard}.pch`,
32171
+ `/tracecc-assets/${shard}.o`
32172
+ ),
32173
+ source: "tracecc-prewarm-assets-v1"
32174
+ });
32175
+ if (result.success !== true) {
32176
+ throw new Error(
32177
+ typeof result.error === "string" ? result.error : "TraceCC compiler asset prewarm failed."
32178
+ );
32179
+ }
32180
+ }
31556
32181
  async warmup(shard = "narrow") {
31557
- await this.options.assetPreflight?.(shard);
32182
+ await this.prewarmAssets(shard);
31558
32183
  await this.ensureWorker();
31559
32184
  const selected = this.options.shards[shard];
31560
32185
  const pchPath = `/tracecc-assets/${shard}.pch`;
@@ -31621,7 +32246,6 @@ var init_tracecc_compiler_service = __esm({
31621
32246
  ""
31622
32247
  );
31623
32248
  const shard = traceccShardForDriver(strippedSource);
31624
- await this.options.assetPreflight?.(shard);
31625
32249
  if (signal?.aborted || generation !== this.generation) {
31626
32250
  throw Object.assign(
31627
32251
  new Error("TraceCC compilation was cancelled."),
@@ -31799,7 +32423,6 @@ var init_tracecc_compiler_service = __esm({
31799
32423
  error: "TraceCC trusted Project compilation only accepts compile requests."
31800
32424
  };
31801
32425
  }
31802
- await this.options.commonAssetPreflight?.();
31803
32426
  if (signal?.aborted || generation !== this.generation) {
31804
32427
  throw Object.assign(
31805
32428
  new Error("TraceCC Project compilation was cancelled."),
@@ -31870,6 +32493,14 @@ var init_tracecc_compiler_service = __esm({
31870
32493
  }, this.requestTimeoutMs);
31871
32494
  worker.onmessage = (event) => {
31872
32495
  const message = event.data;
32496
+ if (message.type === "idle-timeout") {
32497
+ if (generation === this.generation) {
32498
+ this.reset(
32499
+ new Error("TraceCC compiler Worker closed after idle timeout.")
32500
+ );
32501
+ }
32502
+ return;
32503
+ }
31873
32504
  if (message.type === "worker-ready") {
31874
32505
  globalThis.clearTimeout(readyTimeout);
31875
32506
  resolve();
@@ -31997,36 +32628,18 @@ function createTraceCCBrowserCompilerService(compiler, context2) {
31997
32628
  ...DEFAULT_TRACECC_RESOURCE_NAMES,
31998
32629
  ...compiler.resourceNames ?? {}
31999
32630
  };
32000
- const commonCompilerAssetNames = [
32001
- "runtimeHeader",
32002
- "compilerWasm",
32003
- "linkerWasm",
32004
- "sysroot"
32005
- ];
32006
- const commonAssetPreflight = () => context2.preflight(commonCompilerAssetNames);
32007
32631
  const compilerIntegrity = context2.assets.cppCompilerIntegrity;
32008
32632
  if (!compilerIntegrity) {
32009
32633
  throw new Error(
32010
32634
  "TraceCC requires exact compiler integrity entries from a C++ runtime manifest."
32011
32635
  );
32012
32636
  }
32013
- const shardAssetPreflight = (shard) => {
32014
- const prefix = shard === "map" ? "map" : shard;
32015
- return context2.preflight([
32016
- ...commonCompilerAssetNames,
32017
- `compilerResources.${resourceNames[`${prefix}Pch`]}`,
32018
- `compilerResources.${resourceNames[`${prefix}PchSource`]}`,
32019
- `compilerResources.${resourceNames[`${prefix}RuntimeObject`]}`
32020
- ]);
32021
- };
32022
32637
  return new TraceCCCompilerService({
32023
32638
  workerUrl: context2.assets.cppWorker,
32024
32639
  compilerUrl: context2.assets.cppCompilerWasm,
32025
32640
  resourcesUrl: context2.assets.cppSysroot,
32026
32641
  runtimeHeaderUrl: context2.assets.cppRuntimeHeader,
32027
32642
  compilerIntegrity,
32028
- commonAssetPreflight,
32029
- assetPreflight: shardAssetPreflight,
32030
32643
  shards: {
32031
32644
  narrow: traceccShardAssets(
32032
32645
  traceccResources,
@@ -32055,18 +32668,9 @@ function createCppBrowserRuntimeProvider(options = {}) {
32055
32668
  create(context2) {
32056
32669
  const workerFactory = context2.workerFactoryFor("cpp");
32057
32670
  const compiler = options.compiler ?? {};
32058
- const commonCompilerAssetNames = [
32059
- "runtimeHeader",
32060
- "compilerWasm",
32061
- "linkerWasm",
32062
- "sysroot"
32063
- ];
32064
- const runtimeAssetPreflight = context2.preflight("cpp", commonCompilerAssetNames);
32065
32671
  const workerOptions = {
32066
32672
  workerUrl: context2.assets.cppWorker,
32067
32673
  ...workerFactory ? { workerFactory } : {},
32068
- assetPreflight: context2.preflight("cpp", ["worker"]),
32069
- runtimeAssetPreflight,
32070
32674
  compilerWasmUrl: context2.assets.cppCompilerWasm,
32071
32675
  linkerWasmUrl: context2.assets.cppLinkerWasm,
32072
32676
  sysrootUrl: context2.assets.cppSysroot,
@@ -32082,8 +32686,7 @@ function createCppBrowserRuntimeProvider(options = {}) {
32082
32686
  };
32083
32687
  const compilerService = createTraceCCBrowserCompilerService(compiler, {
32084
32688
  assets: context2.assets,
32085
- ...workerFactory ? { workerFactory } : {},
32086
- preflight: (assetNames) => context2.preflight("cpp", assetNames)()
32689
+ ...workerFactory ? { workerFactory } : {}
32087
32690
  });
32088
32691
  const createWorkerClient = () => new CppWorkerClient({
32089
32692
  ...workerOptions,
@@ -32091,7 +32694,9 @@ function createCppBrowserRuntimeProvider(options = {}) {
32091
32694
  });
32092
32695
  const preparedProvider = createCppPreparedExecutionProvider({
32093
32696
  createWorkerClient,
32094
- warmCompilerOnInit: true
32697
+ warmCompilerOnInit: false,
32698
+ prewarmCompiler: () => compilerService.prewarmAssets(),
32699
+ scheduleCompilerPrewarm: createPromotableBrowserBackgroundTask
32095
32700
  });
32096
32701
  const preparedProviders = /* @__PURE__ */ new Map([["cpp", preparedProvider]]);
32097
32702
  const terminateCompiler = () => {
@@ -32115,6 +32720,7 @@ var DEFAULT_TRACECC_RESOURCE_NAMES;
32115
32720
  var init_browser_runtime_provider = __esm({
32116
32721
  "packages/runtime-cpp/src/browser-runtime-provider.ts"() {
32117
32722
  "use strict";
32723
+ init_internal();
32118
32724
  init_cpp_prepared_provider();
32119
32725
  init_cpp_worker_client();
32120
32726
  init_tracecc_compiler_service();
@@ -117855,9 +118461,9 @@ function createBrowserFsPromisesApi(requestState, filesystemState, fsApi) {
117855
118461
  const options = typeof bufferOrOptions === "object" && bufferOrOptions !== null && !ArrayBuffer.isView(bufferOrOptions) ? bufferOrOptions : void 0;
117856
118462
  const buffer = options?.buffer ?? (ArrayBuffer.isView(bufferOrOptions) ? bufferOrOptions : BrowserBuffer.alloc(16 * 1024));
117857
118463
  const readOffset = options?.offset ?? offset;
117858
- const readLength = options?.length ?? length3 ?? buffer.byteLength - readOffset;
118464
+ const readLength2 = options?.length ?? length3 ?? buffer.byteLength - readOffset;
117859
118465
  const readPosition = options !== void 0 ? options.position : position;
117860
- const bytesRead = fsApi.readSync(fd3, buffer, readOffset, readLength, readPosition);
118466
+ const bytesRead = fsApi.readSync(fd3, buffer, readOffset, readLength2, readPosition);
117861
118467
  return { bytesRead, buffer };
117862
118468
  },
117863
118469
  readFile: async (encoding) => readFileFromHandle(encoding),
@@ -125115,14 +125721,7 @@ function preflightAssets(language, surface, csharpPreparedAuthority) {
125115
125721
  "runnerDependencies"
125116
125722
  ];
125117
125723
  case "cpp":
125118
- return [
125119
- "worker",
125120
- "runtimeHeader",
125121
- "compilerWasm",
125122
- "linkerWasm",
125123
- "sysroot",
125124
- "compilerResources"
125125
- ];
125724
+ return [];
125126
125725
  }
125127
125726
  }
125128
125727
  function detectEngine(userAgent = globalThis.navigator?.userAgent ?? "") {
@@ -125790,6 +126389,7 @@ function withPreparedProgramReuse(delegate, options = {}) {
125790
126389
  }
125791
126390
 
125792
126391
  // packages/runtime-browser/src/browser-runtime-host.ts
126392
+ init_background_work_scheduler();
125793
126393
  function resolveHostContext(options) {
125794
126394
  return resolveBrowserRuntimeLifecycleContext(options, {
125795
126395
  optionsName: "CreateBrowserRuntimeHostOptions",
@@ -125881,6 +126481,8 @@ var BrowserRuntimeHostImplementation = class {
125881
126481
  environment;
125882
126482
  supportedLanguages;
125883
126483
  #preparedProviders = /* @__PURE__ */ new Map();
126484
+ #providerInitializers = /* @__PURE__ */ new Map();
126485
+ #warmEntries = /* @__PURE__ */ new Map();
125884
126486
  #leases = [];
125885
126487
  #leaseByLanguage = /* @__PURE__ */ new Map();
125886
126488
  #readinessByLanguage = /* @__PURE__ */ new Map();
@@ -125922,16 +126524,25 @@ var BrowserRuntimeHostImplementation = class {
125922
126524
  language,
125923
126525
  preparedProvider
125924
126526
  );
126527
+ const safeProvider = safePreparedProvider(
126528
+ language,
126529
+ preparedProvider,
126530
+ () => this.#assertActive(),
126531
+ () => this.#ensureLanguageReady(language)
126532
+ );
126533
+ this.#providerInitializers.set(
126534
+ language,
126535
+ () => safeProvider.init()
126536
+ );
125925
126537
  this.#preparedProviders.set(
125926
126538
  language,
125927
- withPreparedProgramReuse(
125928
- safePreparedProvider(
125929
- language,
125930
- preparedProvider,
125931
- () => this.#assertActive(),
125932
- () => this.#ensureLanguageReady(language)
125933
- )
125934
- )
126539
+ withPreparedProgramReuse({
126540
+ init: () => this.#promoteLanguageWarm(language),
126541
+ prepareProgram: async (call) => {
126542
+ await this.#promoteLanguageWarm(language);
126543
+ return safeProvider.prepareProgram(call);
126544
+ }
126545
+ })
125935
126546
  );
125936
126547
  this.#leaseByLanguage.set(language, lease);
125937
126548
  }
@@ -125978,6 +126589,41 @@ var BrowserRuntimeHostImplementation = class {
125978
126589
  throw new Error("Browser runtime host has been disposed.");
125979
126590
  }
125980
126591
  }
126592
+ #warmEntry(language) {
126593
+ const existing = this.#warmEntries.get(language);
126594
+ if (existing) return existing;
126595
+ const initialize = this.#providerInitializers.get(language);
126596
+ if (!initialize) {
126597
+ throw new Error(
126598
+ `Prepared runtime for language "${language}" is not registered.`
126599
+ );
126600
+ }
126601
+ let warmResult;
126602
+ const task = createPromotableBrowserBackgroundTask(async () => {
126603
+ warmResult = await initialize();
126604
+ });
126605
+ const result = task.wait().then(() => {
126606
+ if (!warmResult) {
126607
+ throw new Error(
126608
+ `Browser runtime for ${JSON.stringify(language)} completed warmup without a result.`
126609
+ );
126610
+ }
126611
+ return warmResult;
126612
+ });
126613
+ const entry = { task, result };
126614
+ this.#warmEntries.set(language, entry);
126615
+ void result.catch(() => {
126616
+ if (this.#warmEntries.get(language) === entry) {
126617
+ this.#warmEntries.delete(language);
126618
+ }
126619
+ });
126620
+ return entry;
126621
+ }
126622
+ async #promoteLanguageWarm(language) {
126623
+ const entry = this.#warmEntry(language);
126624
+ await entry.task.promote();
126625
+ return entry.result;
126626
+ }
125981
126627
  isLanguageSupported(language) {
125982
126628
  return this.supportedLanguages.includes(language);
125983
126629
  }
@@ -126045,6 +126691,17 @@ var BrowserRuntimeHostImplementation = class {
126045
126691
  runtimes: Object.freeze(runtimes)
126046
126692
  });
126047
126693
  }
126694
+ prewarmLanguage(language) {
126695
+ this.#assertActive();
126696
+ if (!this.supportedLanguages.includes(language)) {
126697
+ return Promise.reject(
126698
+ new Error(
126699
+ `Runtime for language "${language}" is not selected in this browser environment.`
126700
+ )
126701
+ );
126702
+ }
126703
+ return this.#warmEntry(language).result;
126704
+ }
126048
126705
  warmLanguage(language) {
126049
126706
  this.#assertActive();
126050
126707
  if (!this.supportedLanguages.includes(language)) {
@@ -126054,16 +126711,20 @@ var BrowserRuntimeHostImplementation = class {
126054
126711
  )
126055
126712
  );
126056
126713
  }
126057
- return this.#preparedProviders.get(language).init();
126714
+ return this.#promoteLanguageWarm(language);
126058
126715
  }
126059
126716
  disposeLanguage(language) {
126060
126717
  if (this.#disposed || !this.supportedLanguages.includes(language)) return;
126718
+ this.#warmEntries.get(language)?.task.cancel();
126719
+ this.#warmEntries.delete(language);
126061
126720
  this.#preparedProviders.get(language)?.flushPreparedProgramCache();
126062
126721
  this.#leaseByLanguage.get(language)?.disposeLanguage(language);
126063
126722
  }
126064
126723
  dispose() {
126065
126724
  if (this.#disposed) return;
126066
126725
  this.#disposed = true;
126726
+ for (const entry of this.#warmEntries.values()) entry.task.cancel();
126727
+ this.#warmEntries.clear();
126067
126728
  this.#readinessByLanguage.clear();
126068
126729
  for (const provider of this.#preparedProviders.values()) {
126069
126730
  provider.flushPreparedProgramCache();
@@ -126903,6 +127564,7 @@ init_execution_host();
126903
127564
  init_runtime_language_info();
126904
127565
 
126905
127566
  // packages/runtime-python/src/python-runtime-image.ts
127567
+ init_internal();
126906
127568
  function fetchOptions(descriptor3, signal) {
126907
127569
  return {
126908
127570
  cache: "force-cache",
@@ -126943,8 +127605,114 @@ function createPythonRuntimeImageFactory(options) {
126943
127605
  let disposed = false;
126944
127606
  let imagePromise = null;
126945
127607
  let activeBuildController = null;
127608
+ let activeBootstrapWorker = null;
127609
+ let activeBootstrapCancellation = null;
127610
+ const buildInWorker = () => new Promise((resolve, reject) => {
127611
+ if (!options.workerUrl) {
127612
+ reject(new Error("Python runtime-image bootstrap requires a worker URL."));
127613
+ return;
127614
+ }
127615
+ const workerFormat = options.workerFormat ?? "classic";
127616
+ let workerUrl = appendWorkerUrlQueryParameter(
127617
+ options.workerUrl,
127618
+ "tracecodePythonRole",
127619
+ "runtime-image"
127620
+ );
127621
+ if (workerFormat === "module") {
127622
+ workerUrl = appendWorkerUrlQueryParameter(
127623
+ workerUrl,
127624
+ "tracecodePythonWorkerFormat",
127625
+ "module"
127626
+ );
127627
+ }
127628
+ const worker = options.workerFactory ? options.workerFactory(
127629
+ workerUrl,
127630
+ workerFormat === "module" ? { type: "module" } : void 0
127631
+ ) : new Worker(
127632
+ workerUrl,
127633
+ workerFormat === "module" ? { type: "module" } : void 0
127634
+ );
127635
+ activeBootstrapWorker = worker;
127636
+ const id3 = "python-runtime-image";
127637
+ const protocolToken = createWorkerProtocolToken();
127638
+ let requested = false;
127639
+ let settled = false;
127640
+ const finish = (operation) => {
127641
+ if (settled) return;
127642
+ settled = true;
127643
+ globalThis.clearTimeout(timeoutId);
127644
+ worker.terminate();
127645
+ if (activeBootstrapWorker === worker) activeBootstrapWorker = null;
127646
+ activeBootstrapCancellation = null;
127647
+ operation();
127648
+ };
127649
+ const timeoutId = globalThis.setTimeout(() => {
127650
+ finish(() => reject(
127651
+ new Error(
127652
+ `Python runtime image acquisition timed out after ${timeoutMs}ms.`
127653
+ )
127654
+ ));
127655
+ }, timeoutMs);
127656
+ activeBootstrapCancellation = () => {
127657
+ finish(() => reject(
127658
+ new Error("Python runtime image factory was disposed while loading.")
127659
+ ));
127660
+ };
127661
+ worker.onerror = (event) => {
127662
+ finish(() => reject(
127663
+ new Error(
127664
+ event.message || "Python runtime-image bootstrap Worker crashed."
127665
+ )
127666
+ ));
127667
+ };
127668
+ worker.onmessage = (event) => {
127669
+ const message = event.data;
127670
+ if (message?.type === "worker-ready" && !requested) {
127671
+ requested = true;
127672
+ worker.postMessage({
127673
+ id: id3,
127674
+ type: "build-runtime-image",
127675
+ protocolToken,
127676
+ payload: {
127677
+ source: "tracecode-python-runtime-image-v1",
127678
+ descriptor: options.descriptor
127679
+ }
127680
+ });
127681
+ return;
127682
+ }
127683
+ if (message?.id !== id3 || message.protocolToken !== protocolToken) {
127684
+ return;
127685
+ }
127686
+ if (message.type === "error") {
127687
+ finish(() => reject(
127688
+ new Error(
127689
+ message.payload?.error || "Python runtime-image bootstrap failed."
127690
+ )
127691
+ ));
127692
+ return;
127693
+ }
127694
+ if (message.type !== "runtime-image-result") return;
127695
+ const image = message.payload?.runtimeImage;
127696
+ if (image?.protocolVersion !== PYTHON_RUNTIME_IMAGE_PROTOCOL_VERSION || !(image.compiledModule instanceof WebAssembly.Module) || !(image.snapshot instanceof Uint8Array) || image.snapshot.byteLength === 0 || typeof image.pythonHashSeed !== "string" || image.pythonHashSeed.length === 0) {
127697
+ finish(() => reject(
127698
+ new Error("Python runtime-image bootstrap returned an invalid image.")
127699
+ ));
127700
+ return;
127701
+ }
127702
+ finish(() => resolve(Object.freeze(image)));
127703
+ };
127704
+ });
126946
127705
  const build = async () => {
126947
127706
  if (disposed) throw new Error("Python runtime image factory is disposed.");
127707
+ if (options.workerUrl) {
127708
+ const image = await buildInWorker();
127709
+ if (disposed) {
127710
+ throw new Error(
127711
+ "Python runtime image factory was disposed while loading."
127712
+ );
127713
+ }
127714
+ return image;
127715
+ }
126948
127716
  const controller = new AbortController();
126949
127717
  activeBuildController = controller;
126950
127718
  let timeoutId;
@@ -127062,6 +127830,10 @@ function createPythonRuntimeImageFactory(options) {
127062
127830
  disposed = true;
127063
127831
  activeBuildController?.abort();
127064
127832
  activeBuildController = null;
127833
+ activeBootstrapCancellation?.();
127834
+ activeBootstrapCancellation = null;
127835
+ activeBootstrapWorker?.terminate();
127836
+ activeBootstrapWorker = null;
127065
127837
  imagePromise = null;
127066
127838
  }
127067
127839
  });
@@ -127188,9 +127960,15 @@ function createPythonBrowserRuntimeProvider(options = {}) {
127188
127960
  );
127189
127961
  }
127190
127962
  const createRuntimeImageFactory = () => createPythonRuntimeImageFactory({
127191
- descriptor: runtimeImageDescriptor
127963
+ descriptor: runtimeImageDescriptor,
127964
+ workerUrl: context2.assets.pythonWorker,
127965
+ ...workerFactory ? { workerFactory } : {},
127966
+ ...pythonManifest?.workerFormat ? { workerFormat: pythonManifest.workerFormat } : {}
127192
127967
  });
127193
127968
  let runtimeImageFactory = createRuntimeImageFactory();
127969
+ const runtimeImageWorkerPreflight = context2.preflight("python", [
127970
+ "worker"
127971
+ ]);
127194
127972
  const workerOptions = () => ({
127195
127973
  workerUrl: context2.assets.pythonWorker,
127196
127974
  ...workerFactory ? { workerFactory } : {},
@@ -127231,6 +128009,7 @@ function createPythonBrowserRuntimeProvider(options = {}) {
127231
128009
  const lease = {
127232
128010
  preparedProviders,
127233
128011
  preflightLanguage: async () => {
128012
+ await runtimeImageWorkerPreflight();
127234
128013
  await runtimeImageFactory.acquire();
127235
128014
  },
127236
128015
  disposeLanguage: () => {
@@ -129576,9 +130355,9 @@ var CSharpRuntimeClient = class {
129576
130355
  get preparedCompiler() {
129577
130356
  return this.preparedAuthority?.compiler ?? this.workerClient;
129578
130357
  }
129579
- async withPreparedRunner(execute) {
130358
+ async withPreparedRunner(tier, execute) {
129580
130359
  if (!this.preparedAuthority) return execute(this.workerClient);
129581
- const runner = this.preparedAuthority.createRunner();
130360
+ const runner = this.preparedAuthority.createRunner(tier);
129582
130361
  try {
129583
130362
  return await execute(runner);
129584
130363
  } finally {
@@ -129586,7 +130365,7 @@ var CSharpRuntimeClient = class {
129586
130365
  this.preparedAuthority.releaseRunner(runner);
129587
130366
  }
129588
130367
  }
129589
- async withFreshPreparedRunners(inputBatch, execute, signal) {
130368
+ async withFreshPreparedRunners(tier, inputBatch, execute, signal) {
129590
130369
  const concurrency = Math.min(
129591
130370
  inputBatch.length,
129592
130371
  this.preparedAuthority?.batchConcurrency ?? 1
@@ -129608,6 +130387,7 @@ var CSharpRuntimeClient = class {
129608
130387
  const inputs = inputBatch[index];
129609
130388
  try {
129610
130389
  results[index] = await this.withPreparedRunner(
130390
+ tier,
129611
130391
  (runner) => execute(runner, inputs, index)
129612
130392
  );
129613
130393
  } catch (reason) {
@@ -129711,6 +130491,17 @@ var CSharpRuntimeClient = class {
129711
130491
  timings: result.timings
129712
130492
  };
129713
130493
  }
130494
+ const preparedRunnerTier = result.preparedRunnerTier;
130495
+ const preparedRunnerReason = result.preparedRunnerReason;
130496
+ if (preparedRunnerTier !== "algorithm-fast" && preparedRunnerTier !== "compatibility" || typeof preparedRunnerReason !== "string" || !preparedRunnerReason || preparedRunnerTier === "algorithm-fast" && !result.traceClrWireContract) {
130497
+ return {
130498
+ kind: "failed",
130499
+ error: "C# preparation completed without a valid runner-tier descriptor.",
130500
+ diagnosticStage: "compile",
130501
+ consoleOutput: result.consoleOutput ?? [],
130502
+ timings: result.timings
130503
+ };
130504
+ }
129714
130505
  let artifact = Object.freeze({
129715
130506
  mode: call.mode,
129716
130507
  code: call.code,
@@ -129719,7 +130510,24 @@ var CSharpRuntimeClient = class {
129719
130510
  ...call.traceOptions ? { traceOptions: Object.freeze({ ...call.traceOptions }) } : {},
129720
130511
  compiledArtifactKey: result.compiledArtifactKey,
129721
130512
  compiledArtifactBase64: result.compiledArtifactBase64,
129722
- compiledArtifactSha256: result.compiledArtifactSha256
130513
+ compiledArtifactSha256: result.compiledArtifactSha256,
130514
+ preparedRunnerTier,
130515
+ preparedRunnerReason,
130516
+ ...result.traceClrWireContract ? {
130517
+ traceClrWireContract: Object.freeze({
130518
+ parameters: Object.freeze(
130519
+ result.traceClrWireContract.parameters.map(
130520
+ (parameter) => Object.freeze({
130521
+ name: parameter.name,
130522
+ type: Object.freeze({ ...parameter.type })
130523
+ })
130524
+ )
130525
+ ),
130526
+ returnType: Object.freeze({
130527
+ ...result.traceClrWireContract.returnType
130528
+ })
130529
+ })
130530
+ } : {}
129723
130531
  });
129724
130532
  let disposed = false;
129725
130533
  let disposePromise;
@@ -129789,6 +130597,7 @@ var CSharpRuntimeClient = class {
129789
130597
  executeIsolated: (preparedCall) => executeOwned(
129790
130598
  preparedCall,
129791
130599
  (preparedArtifact, forwardedCall) => this.withPreparedRunner(
130600
+ preparedArtifact.preparedRunnerTier,
129792
130601
  (runner) => runner.executePreparedTrace(
129793
130602
  preparedArtifact,
129794
130603
  forwardedCall
@@ -129806,6 +130615,7 @@ var CSharpRuntimeClient = class {
129806
130615
  return executeOwned(
129807
130616
  preparedCall,
129808
130617
  (preparedArtifact, forwardedCall) => this.withFreshPreparedRunners(
130618
+ preparedArtifact.preparedRunnerTier,
129809
130619
  forwardedCall.inputBatch,
129810
130620
  (runner, inputs, index) => runner.executePreparedTrace(
129811
130621
  preparedArtifact,
@@ -129829,12 +130639,14 @@ var CSharpRuntimeClient = class {
129829
130639
  executeIsolated: (preparedCall) => executeOwned(
129830
130640
  preparedCall,
129831
130641
  (preparedArtifact, forwardedCall) => this.withPreparedRunner(
130642
+ preparedArtifact.preparedRunnerTier,
129832
130643
  (runner) => runner.executePreparedCode(preparedArtifact, forwardedCall)
129833
130644
  )
129834
130645
  ),
129835
130646
  executeBatchIsolated: (preparedCall) => executeOwned(
129836
130647
  preparedCall,
129837
130648
  (preparedArtifact, forwardedCall) => this.withFreshPreparedRunners(
130649
+ preparedArtifact.preparedRunnerTier,
129838
130650
  forwardedCall.inputBatch,
129839
130651
  (runner, inputs) => runner.executePreparedCode(preparedArtifact, {
129840
130652
  inputs,
@@ -129911,8 +130723,8 @@ function createCSharpBrowserRuntimeProvider(options = {}) {
129911
130723
  const firefoxPreparedIdleTimeoutMs = isFirefoxBrowser() ? FIREFOX_PREPARED_WORKER_IDLE_TIMEOUT_MS : void 0;
129912
130724
  const compilerIdleTimeoutMs = options.compilerIdleTimeoutMs ?? firefoxPreparedIdleTimeoutMs;
129913
130725
  const runnerIdleTimeoutMs = options.runnerIdleTimeoutMs ?? options.workerIdleTimeoutMs ?? firefoxPreparedIdleTimeoutMs;
129914
- const dependencyUrls = (collection) => {
129915
- const descriptors = context2.manifestAssetCollection("csharp", collection);
130726
+ const dependencyUrls = (collection2) => {
130727
+ const descriptors = context2.manifestAssetCollection("csharp", collection2);
129916
130728
  return descriptors ? Object.fromEntries(
129917
130729
  Object.entries(descriptors).map(([name, descriptor3]) => [
129918
130730
  name,
@@ -130074,7 +130886,6 @@ function createCSharpBrowserRuntimeProvider(options = {}) {
130074
130886
  standbyWarmup = warmup;
130075
130887
  return warmup;
130076
130888
  };
130077
- void ensureStandbyRunner().catch(() => void 0);
130078
130889
  const preparedAuthority = preparedAuthorityEnabled ? {
130079
130890
  compiler,
130080
130891
  batchConcurrency: preparedBatchConcurrency,
@@ -130089,7 +130900,7 @@ function createCSharpBrowserRuntimeProvider(options = {}) {
130089
130900
  loadTimeMs: performance.now() - startedAt
130090
130901
  };
130091
130902
  },
130092
- createRunner() {
130903
+ createRunner(_tier) {
130093
130904
  if (disposed) {
130094
130905
  throw new Error("C# browser runtime provider has been disposed.");
130095
130906
  }
@@ -137679,15 +138490,15 @@ function evaluateExpression(expression, context2, scope2) {
137679
138490
  }
137680
138491
  case "every":
137681
138492
  case "some": {
137682
- const collection = resolveValue(expression.collection, context2, scope2);
137683
- if (!Array.isArray(collection)) {
138493
+ const collection2 = resolveValue(expression.collection, context2, scope2);
138494
+ if (!Array.isArray(collection2)) {
137684
138495
  return Object.freeze({
137685
138496
  expression,
137686
138497
  result: "unknown",
137687
138498
  reason: "The quantified collection is missing or is not an array."
137688
138499
  });
137689
138500
  }
137690
- const children2 = collection.map(
138501
+ const children2 = collection2.map(
137691
138502
  (item) => evaluateExpression(
137692
138503
  expression.condition,
137693
138504
  context2,
@@ -141119,22 +141930,13 @@ async function createBrowserProjectWorkspace(options = {}) {
141119
141930
  } : {}
141120
141931
  };
141121
141932
  const cppCompilerWorkerFactory = executionHost && isExecutionHosted("cpp") ? executionHost.workerFactory : void 0;
141122
- const cppRuntimeAssetPreflight = () => runtimeAssetPreflight.preflight("cpp", [
141123
- "runtimeHeader",
141124
- "compilerWasm",
141125
- "linkerWasm",
141126
- "sysroot"
141127
- ]);
141128
141933
  const traceccCompilerService = cppProvider && !injectedCppProvider ? cppProvider[2].createTraceCCBrowserCompilerService({}, {
141129
141934
  assets,
141130
- ...cppCompilerWorkerFactory ? { workerFactory: cppCompilerWorkerFactory } : {},
141131
- preflight: (assetNames) => runtimeAssetPreflight.preflight("cpp", assetNames)
141935
+ ...cppCompilerWorkerFactory ? { workerFactory: cppCompilerWorkerFactory } : {}
141132
141936
  }) : void 0;
141133
141937
  const cppWorkerOptions = {
141134
141938
  workerUrl: assets.cppWorker,
141135
141939
  ...cppCompilerWorkerFactory ? { workerFactory: cppCompilerWorkerFactory } : {},
141136
- assetPreflight: () => runtimeAssetPreflight.preflight("cpp", ["worker"]),
141137
- runtimeAssetPreflight: cppRuntimeAssetPreflight,
141138
141940
  compilerWasmUrl: assets.cppCompilerWasm,
141139
141941
  linkerWasmUrl: assets.cppLinkerWasm,
141140
141942
  sysrootUrl: assets.cppSysroot,
@@ -142549,6 +143351,7 @@ function createBrowserJudgeHostFromRuntimeHost(host, options = {}) {
142549
143351
  isLanguageSupported: host.isLanguageSupported.bind(host),
142550
143352
  preflightLanguage: host.preflightLanguage.bind(host),
142551
143353
  preflight: host.preflight.bind(host),
143354
+ prewarmLanguage: host.prewarmLanguage.bind(host),
142552
143355
  warmLanguage: host.warmLanguage.bind(host),
142553
143356
  disposeLanguage: host.disposeLanguage.bind(host),
142554
143357
  createJudge: (judgeOptions) => createBrowserRuntimeJudge({