@tracecode/harness 0.16.4 → 0.16.6

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 (50) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +6 -4
  3. package/dist/{browser-runtime-provider-OGJQLGXU.js → browser-runtime-provider-KPQBQ4EG.js} +5 -5
  4. package/dist/{chunk-AAKNIYV6.js → chunk-46XZQOHV.js} +3 -3
  5. package/dist/{chunk-6LE4KEMZ.js → chunk-4PN5YD6J.js} +489 -3
  6. package/dist/{chunk-DTLDQQHA.js → chunk-5KH5ABPQ.js} +72 -1
  7. package/dist/{chunk-5RT5IT4I.js → chunk-B2EM2SZ2.js} +15 -31
  8. package/dist/{chunk-M7SNEZDR.js → chunk-EPBHRROK.js} +3 -3
  9. package/dist/{chunk-Y72C46GE.js → chunk-GXTDL2ML.js} +20 -11
  10. package/dist/{chunk-RCOPAMVR.js → chunk-J2KGF5PU.js} +56 -36
  11. package/dist/core.cjs +19 -10
  12. package/dist/core.js +1 -1
  13. package/dist/cpp-worker-client-UWGDH6HR.js +12 -0
  14. package/dist/{csharp-worker-client-ARGMOB3M.js → csharp-worker-client-4QP2ZBSA.js} +4 -4
  15. package/dist/internal/browser.cjs +72 -0
  16. package/dist/internal/browser.d.cts +19 -1
  17. package/dist/internal/browser.d.ts +19 -1
  18. package/dist/internal/browser.js +3 -1
  19. package/dist/internal/tracekernel-workspace.cjs +19 -10
  20. package/dist/internal/tracekernel-workspace.js +1 -1
  21. package/dist/{java-project-JB5TUIFU.js → java-project-AEQEVBDA.js} +2 -2
  22. package/dist/judge.cjs +885 -89
  23. package/dist/judge.d.cts +6 -0
  24. package/dist/judge.d.ts +6 -0
  25. package/dist/judge.js +237 -23
  26. package/dist/{project-browser-3S2FWEAP.js → project-browser-HFNQEALT.js} +2 -2
  27. package/dist/{project-browser-QN7YOJQQ.js → project-browser-L3A2G2MA.js} +2 -2
  28. package/dist/{project-browser-S4KLCZV7.js → project-browser-OVE7V464.js} +2 -2
  29. package/dist/{project-browser-WDUWUGLZ.js → project-browser-P2H222D7.js} +2 -2
  30. package/dist/{project-browser-HCQCXAYC.js → project-browser-WCSIJY6I.js} +2 -2
  31. package/dist/{python-worker-client-EX6Q2W4L.js → python-worker-client-UCOMTSMU.js} +4 -4
  32. package/dist/tracekernel.cjs +650 -68
  33. package/dist/tracekernel.js +4 -4
  34. package/package.json +14 -5
  35. package/runtime-assets.lock.json +77 -70
  36. package/workers/cpp/cpp-worker.js +53 -43
  37. package/workers/csharp/csharp-worker.js +150 -1
  38. package/workers/javascript/javascript-project-worker.js +18 -9
  39. package/workers/python/python-worker.js +121 -1
  40. package/workers/vendor/csharp/_framework/TraceCode.CSharpHost.wasm +0 -0
  41. package/workers/vendor/csharp/_framework/TraceCode.CSharpJudgeRuntime.wasm +0 -0
  42. package/workers/vendor/csharp/_framework/TraceCode.TraceClrWire.wasm +0 -0
  43. package/workers/vendor/csharp/_framework/dotnet.boot.js +11 -6
  44. package/workers/vendor/csharp/_framework/dotnet.native.wasm +0 -0
  45. package/workers/vendor/csharp/_framework/supportFiles/TraceCode.CSharpHost.dll +0 -0
  46. package/workers/vendor/csharp/_framework/supportFiles/TraceCode.CSharpJudgeRuntime.dll +0 -0
  47. package/workers/vendor/csharp-runner/_framework/assemblies-02.pack +0 -0
  48. package/workers/vendor/csharp-runner/_framework/assemblies-03.pack +0 -0
  49. package/workers/vendor/csharp-runner/_framework/dotnet.boot.js +65 -65
  50. package/dist/cpp-worker-client-HV7RO2P5.js +0 -12
@@ -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": {
@@ -13521,7 +13521,7 @@ var init_package = __esm({
13521
13521
  "package.json"() {
13522
13522
  package_default = {
13523
13523
  name: "@tracecode/harness",
13524
- version: "0.16.4",
13524
+ version: "0.16.6",
13525
13525
  license: "AGPL-3.0-only",
13526
13526
  homepage: "https://tracecode.app",
13527
13527
  repository: {
@@ -13589,6 +13589,15 @@ var init_package = __esm({
13589
13589
  "build:browser-host": "pnpm exec tsup --config tsup.browser-host.config.ts",
13590
13590
  "build:tracekernel": "pnpm exec tsup --config tsup.tracekernel.config.ts",
13591
13591
  "generate:runtime-info": "pnpm exec tsx --tsconfig tsconfig.base.json scripts/generate-runtime-language-info.ts",
13592
+ "generate:traceclr-profile": "node scripts/generate-traceclr-algorithm-profile.mjs",
13593
+ "audit:traceclr-corpus": "node scripts/audit-traceclr-corpus.mjs",
13594
+ "build:traceclr-product-corpus": "node scripts/create-traceclr-product-corpus.mjs",
13595
+ "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",
13596
+ "check:traceclr-product-profile": "node scripts/generate-traceclr-algorithm-profile.mjs --check && pnpm check:traceclr-profile",
13597
+ "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",
13598
+ "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",
13599
+ "bench:traceclr-tiers": "pnpm build:traceclr-wire-probe && pnpm materialize:csharp-role-assets && node --import tsx scripts/benchmark-traceclr-runtime-tiers.ts",
13600
+ "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",
13592
13601
  "generate:runtime-open-source-info": "pnpm exec tsx --tsconfig tsconfig.base.json scripts/generate-runtime-open-source-info.ts",
13593
13602
  "generate:python-harness": "pnpm exec tsx --tsconfig tsconfig.base.json scripts/generate-python-harness-artifacts.ts",
13594
13603
  "generate:runtime-assets-lock": "node --import tsx scripts/generate-runtime-assets-lock.mjs",
@@ -13652,10 +13661,10 @@ var init_package = __esm({
13652
13661
  "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",
13653
13662
  "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",
13654
13663
  "test:tracejvm-semantic-trace": "node --import tsx tests/test-tracejvm-semantic-trace-matrix.ts",
13655
- "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",
13664
+ "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",
13656
13665
  "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",
13657
13666
  "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",
13658
- "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",
13667
+ "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",
13659
13668
  "test:cpp-runtime": "pnpm exec tsx --tsconfig tsconfig.base.json tests/test-cpp-runtime.ts",
13660
13669
  "test:cpp-conformance": "pnpm exec tsx --tsconfig tsconfig.base.json tests/test-cpp-conformance.ts",
13661
13670
  "test:cpp-script-lambda-trace": "pnpm exec tsx --tsconfig tsconfig.base.json tests/test-cpp-script-lambda-trace.ts",
@@ -13791,7 +13800,7 @@ var init_runtime_language_info_data = __esm({
13791
13800
  "versionLabel": "Python 3.13.2",
13792
13801
  "executionPlatform": {
13793
13802
  "name": "TraceKernel",
13794
- "version": "0.16.4"
13803
+ "version": "0.16.6"
13795
13804
  },
13796
13805
  "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.",
13797
13806
  "runtime": {
@@ -13818,7 +13827,7 @@ var init_runtime_language_info_data = __esm({
13818
13827
  "versionLabel": "JavaScript (ECMAScript 2023)",
13819
13828
  "executionPlatform": {
13820
13829
  "name": "TraceKernel",
13821
- "version": "0.16.4"
13830
+ "version": "0.16.6"
13822
13831
  },
13823
13832
  "runtime": {
13824
13833
  "name": "TraceKernel JavaScript runtime",
@@ -13910,7 +13919,7 @@ Binary Search Tree, Trie, and Graph are bundled too, but are not exposed globall
13910
13919
  "versionLabel": "TypeScript 5.9.3",
13911
13920
  "executionPlatform": {
13912
13921
  "name": "TraceKernel",
13913
- "version": "0.16.4"
13922
+ "version": "0.16.6"
13914
13923
  },
13915
13924
  "description": `TypeScript 5.9.3 is compiled with the TypeScript compiler and executed by TraceKernel's JavaScript runtime.
13916
13925
 
@@ -14010,7 +14019,7 @@ The compiled output runs on the same TraceKernel execution lane as JavaScript su
14010
14019
  "versionLabel": "Java 23",
14011
14020
  "executionPlatform": {
14012
14021
  "name": "TraceKernel",
14013
- "version": "0.16.4"
14022
+ "version": "0.16.6"
14014
14023
  },
14015
14024
  "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.",
14016
14025
  "runtime": {
@@ -14047,7 +14056,7 @@ The compiled output runs on the same TraceKernel execution lane as JavaScript su
14047
14056
  "versionLabel": "C# 14",
14048
14057
  "executionPlatform": {
14049
14058
  "name": "TraceKernel",
14050
- "version": "0.16.4"
14059
+ "version": "0.16.6"
14051
14060
  },
14052
14061
  "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.",
14053
14062
  "runtime": {
@@ -14076,7 +14085,7 @@ The compiled output runs on the same TraceKernel execution lane as JavaScript su
14076
14085
  "versionLabel": "C++23",
14077
14086
  "executionPlatform": {
14078
14087
  "name": "TraceKernel",
14079
- "version": "0.16.4"
14088
+ "version": "0.16.6"
14080
14089
  },
14081
14090
  "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.",
14082
14091
  "runtime": {
@@ -14241,7 +14250,7 @@ var init_runtime_open_source_info_data = __esm({
14241
14250
  {
14242
14251
  "kind": "modifications",
14243
14252
  "label": "Runtime modifications",
14244
- "url": "https://github.com/tracecodeapp/harness/tree/v0.16.4/workers/python/pyodide-0.29.3"
14253
+ "url": "https://github.com/tracecodeapp/harness/tree/v0.16.6/workers/python/pyodide-0.29.3"
14245
14254
  }
14246
14255
  ]
14247
14256
  }
@@ -102564,6 +102573,81 @@ var init_browser_client_env = __esm({
102564
102573
  }
102565
102574
  });
102566
102575
 
102576
+ // packages/runtime-browser/src/background-work-scheduler.ts
102577
+ function createPromotableBrowserBackgroundTask(work) {
102578
+ let permanentlyCancelled = false;
102579
+ let task = null;
102580
+ let idleHandle = null;
102581
+ let backgroundController = null;
102582
+ let resolveCompletion;
102583
+ let rejectCompletion;
102584
+ const completion = new Promise((resolve, reject) => {
102585
+ resolveCompletion = resolve;
102586
+ rejectCompletion = reject;
102587
+ });
102588
+ void completion.catch(() => void 0);
102589
+ const start = () => {
102590
+ if (permanentlyCancelled) return Promise.resolve();
102591
+ if (!task) {
102592
+ task = Promise.resolve().then(work);
102593
+ task.then(resolveCompletion, rejectCompletion);
102594
+ void task.catch(() => void 0);
102595
+ }
102596
+ return task;
102597
+ };
102598
+ const cancelPendingCallback = () => {
102599
+ if (idleHandle !== null && typeof globalThis.cancelIdleCallback === "function") {
102600
+ globalThis.cancelIdleCallback(idleHandle);
102601
+ idleHandle = null;
102602
+ }
102603
+ backgroundController?.abort();
102604
+ backgroundController = null;
102605
+ };
102606
+ if (typeof globalThis.requestIdleCallback === "function") {
102607
+ idleHandle = globalThis.requestIdleCallback(() => {
102608
+ idleHandle = null;
102609
+ void start();
102610
+ });
102611
+ } else {
102612
+ const scheduler = globalThis.scheduler;
102613
+ if (scheduler?.postTask) {
102614
+ backgroundController = new AbortController();
102615
+ void scheduler.postTask(
102616
+ () => {
102617
+ backgroundController = null;
102618
+ return start();
102619
+ },
102620
+ {
102621
+ priority: "background",
102622
+ signal: backgroundController.signal
102623
+ }
102624
+ ).catch(() => void 0);
102625
+ }
102626
+ }
102627
+ return {
102628
+ promote: () => {
102629
+ cancelPendingCallback();
102630
+ return start();
102631
+ },
102632
+ wait: () => completion,
102633
+ cancel: () => {
102634
+ if (permanentlyCancelled) return;
102635
+ permanentlyCancelled = true;
102636
+ cancelPendingCallback();
102637
+ if (!task) {
102638
+ rejectCompletion(
102639
+ new DOMException("Browser background work was cancelled.", "AbortError")
102640
+ );
102641
+ }
102642
+ }
102643
+ };
102644
+ }
102645
+ var init_background_work_scheduler = __esm({
102646
+ "packages/runtime-browser/src/background-work-scheduler.ts"() {
102647
+ "use strict";
102648
+ }
102649
+ });
102650
+
102567
102651
  // packages/runtime-browser/src/host-artifact-cache.ts
102568
102652
  function handleHostArtifactCacheRequest(options) {
102569
102653
  const { cache, message, worker, validateProtocolToken } = options;
@@ -104618,6 +104702,7 @@ var init_internal = __esm({
104618
104702
  "packages/runtime-browser/src/internal.ts"() {
104619
104703
  "use strict";
104620
104704
  init_browser_client_env();
104705
+ init_background_work_scheduler();
104621
104706
  init_execution_host();
104622
104707
  init_host_artifact_cache();
104623
104708
  init_kernel_http_async();
@@ -114811,9 +114896,9 @@ function createBrowserFsPromisesApi(requestState, filesystemState, fsApi) {
114811
114896
  const options = typeof bufferOrOptions === "object" && bufferOrOptions !== null && !ArrayBuffer.isView(bufferOrOptions) ? bufferOrOptions : void 0;
114812
114897
  const buffer = options?.buffer ?? (ArrayBuffer.isView(bufferOrOptions) ? bufferOrOptions : BrowserBuffer.alloc(16 * 1024));
114813
114898
  const readOffset = options?.offset ?? offset;
114814
- const readLength = options?.length ?? length3 ?? buffer.byteLength - readOffset;
114899
+ const readLength2 = options?.length ?? length3 ?? buffer.byteLength - readOffset;
114815
114900
  const readPosition = options !== void 0 ? options.position : position;
114816
- const bytesRead = fsApi.readSync(fd5, buffer, readOffset, readLength, readPosition);
114901
+ const bytesRead = fsApi.readSync(fd5, buffer, readOffset, readLength2, readPosition);
114817
114902
  return { bytesRead, buffer };
114818
114903
  },
114819
114904
  readFile: async (encoding) => readFileFromHandle(encoding),
@@ -120890,6 +120975,466 @@ var init_project_browser4 = __esm({
120890
120975
  }
120891
120976
  });
120892
120977
 
120978
+ // packages/runtime-csharp/src/traceclr-wire.ts
120979
+ function parseWireType(text, depth = 0) {
120980
+ if (depth > TRACECLR_WIRE_LIMITS.maxDepth) throw new RangeError("TraceCLR wire type is too deeply nested.");
120981
+ if (text === "list-node<int32>") return { kind: "list-node" };
120982
+ if (text === "tree-node<int32>") return { kind: "tree-node" };
120983
+ for (const name of ["array", "list", "set"]) {
120984
+ const prefix = `${name}<`;
120985
+ if (text.startsWith(prefix) && text.endsWith(">")) {
120986
+ return { kind: "container", name, element: parseWireType(text.slice(prefix.length, -1), depth + 1) };
120987
+ }
120988
+ }
120989
+ const scalars = /* @__PURE__ */ new Set([
120990
+ "void",
120991
+ "null",
120992
+ "bool",
120993
+ "char",
120994
+ "uint8",
120995
+ "int8",
120996
+ "int16",
120997
+ "uint16",
120998
+ "int32",
120999
+ "uint32",
121000
+ "int64",
121001
+ "uint64",
121002
+ "float32",
121003
+ "float64",
121004
+ "string"
121005
+ ]);
121006
+ if (!scalars.has(text)) throw new TypeError(`Unsupported TraceCLR wire type: ${text}`);
121007
+ return { kind: "scalar", name: text };
121008
+ }
121009
+ function integer(value, minimum, maximum, label) {
121010
+ if (typeof value !== "number" || !Number.isInteger(value) || value < minimum || value > maximum) {
121011
+ throw new TypeError(`${label} must be an integer between ${minimum} and ${maximum}.`);
121012
+ }
121013
+ return value;
121014
+ }
121015
+ function integer64(value, signed) {
121016
+ let converted = null;
121017
+ if (typeof value === "bigint") {
121018
+ converted = value;
121019
+ } else if (typeof value === "number" && Number.isInteger(value)) {
121020
+ const jsonDecimal = JSON.stringify(value);
121021
+ if (jsonDecimal !== void 0) converted = BigInt(jsonDecimal);
121022
+ }
121023
+ const minimum = signed ? -(1n << 63n) : 0n;
121024
+ const maximum = signed ? (1n << 63n) - 1n : (1n << 64n) - 1n;
121025
+ if (converted === null || converted < minimum || converted > maximum) {
121026
+ throw new TypeError(`${signed ? "int64" : "uint64"} must be a bigint or integer number in range.`);
121027
+ }
121028
+ return converted;
121029
+ }
121030
+ function floatingPoint(value, label) {
121031
+ if (typeof value === "number") return Object.is(value, -0) ? 0 : value;
121032
+ if (value === "NaN") return Number.NaN;
121033
+ if (value === "Infinity") return Number.POSITIVE_INFINITY;
121034
+ if (value === "-Infinity") return Number.NEGATIVE_INFINITY;
121035
+ throw new TypeError(`${label} must be numeric or a named floating-point literal.`);
121036
+ }
121037
+ function collection(value, set6) {
121038
+ const items = set6 && value instanceof Set ? [...value] : value;
121039
+ if (!Array.isArray(items)) throw new TypeError("TraceCLR collection values must be arrays or Sets.");
121040
+ if (items.length > TRACECLR_WIRE_LIMITS.maxCollectionItems) {
121041
+ throw new RangeError(`TraceCLR collection exceeds ${TRACECLR_WIRE_LIMITS.maxCollectionItems} items.`);
121042
+ }
121043
+ return items;
121044
+ }
121045
+ function writeValue(writer, type, value, depth) {
121046
+ if (depth > TRACECLR_WIRE_LIMITS.maxDepth) throw new RangeError("TraceCLR value is too deeply nested.");
121047
+ if (type.kind === "container") {
121048
+ if (value === null) {
121049
+ writer.int32(-1);
121050
+ return;
121051
+ }
121052
+ const values3 = collection(value, type.name === "set");
121053
+ writer.int32(values3.length);
121054
+ for (const item of values3) writeValue(writer, type.element, item, depth + 1);
121055
+ return;
121056
+ }
121057
+ if (type.kind === "list-node") {
121058
+ if (value === null) {
121059
+ writer.int32(-1);
121060
+ return;
121061
+ }
121062
+ const values3 = Array.isArray(value) ? value : [];
121063
+ if (!Array.isArray(value)) {
121064
+ const seen = /* @__PURE__ */ new Set();
121065
+ let node = value;
121066
+ while (node !== null) {
121067
+ if (typeof node !== "object" || seen.has(node)) throw new TypeError("TraceCLR ListNode must be acyclic.");
121068
+ seen.add(node);
121069
+ values3.push(node.val ?? node.value);
121070
+ node = node.next ?? null;
121071
+ if (values3.length > TRACECLR_WIRE_LIMITS.maxCollectionItems) throw new RangeError("TraceCLR ListNode is too long.");
121072
+ }
121073
+ }
121074
+ writer.int32(values3.length);
121075
+ for (const item of values3) writer.int32(integer(item, -2147483648, 2147483647, "ListNode value"));
121076
+ return;
121077
+ }
121078
+ if (type.kind === "tree-node") {
121079
+ if (value === null) {
121080
+ writer.int32(-1);
121081
+ return;
121082
+ }
121083
+ let rawValues;
121084
+ if (Array.isArray(value)) {
121085
+ rawValues = value;
121086
+ } else if (typeof value === "object") {
121087
+ const values4 = [];
121088
+ const nodes = [value];
121089
+ for (let index = 0; index < nodes.length; index++) {
121090
+ const node = nodes[index];
121091
+ if (node === null) {
121092
+ values4.push(null);
121093
+ continue;
121094
+ }
121095
+ if (typeof node !== "object") throw new TypeError("TraceCLR TreeNode nodes must be objects or null.");
121096
+ const typed = node;
121097
+ values4.push(typed.val ?? typed.value);
121098
+ nodes.push(typed.left ?? null, typed.right ?? null);
121099
+ if (nodes.length > TRACECLR_WIRE_LIMITS.maxCollectionItems) throw new RangeError("TraceCLR TreeNode is too large.");
121100
+ }
121101
+ while (values4.at(-1) === null) values4.pop();
121102
+ rawValues = values4;
121103
+ } else {
121104
+ throw new TypeError("TraceCLR TreeNode inputs must be level-order arrays or node objects.");
121105
+ }
121106
+ const values3 = collection(rawValues, false);
121107
+ writer.int32(values3.length);
121108
+ for (const item of values3) {
121109
+ writer.uint8(item === null ? 0 : 1);
121110
+ if (item !== null) writer.int32(integer(item, -2147483648, 2147483647, "TreeNode value"));
121111
+ }
121112
+ return;
121113
+ }
121114
+ switch (type.name) {
121115
+ case "void":
121116
+ return;
121117
+ case "null":
121118
+ if (value !== null) throw new TypeError("TraceCLR null result must be null.");
121119
+ writer.uint8(0);
121120
+ return;
121121
+ case "bool":
121122
+ if (typeof value !== "boolean") throw new TypeError("bool must be boolean.");
121123
+ writer.uint8(value ? 1 : 0);
121124
+ return;
121125
+ case "char": {
121126
+ if (typeof value !== "string" || value.length !== 1) throw new TypeError("char must be one UTF-16 code unit.");
121127
+ writer.uint16(value.charCodeAt(0));
121128
+ return;
121129
+ }
121130
+ case "uint8":
121131
+ writer.uint8(integer(value, 0, 255, "uint8"));
121132
+ return;
121133
+ case "int8":
121134
+ writer.int8(integer(value, -128, 127, "int8"));
121135
+ return;
121136
+ case "int16":
121137
+ writer.int16(integer(value, -32768, 32767, "int16"));
121138
+ return;
121139
+ case "uint16":
121140
+ writer.uint16(integer(value, 0, 65535, "uint16"));
121141
+ return;
121142
+ case "int32":
121143
+ writer.int32(integer(value, -2147483648, 2147483647, "int32"));
121144
+ return;
121145
+ case "uint32":
121146
+ writer.uint32(integer(value, 0, 4294967295, "uint32"));
121147
+ return;
121148
+ case "int64":
121149
+ writer.int64(integer64(value, true));
121150
+ return;
121151
+ case "uint64":
121152
+ writer.uint64(integer64(value, false));
121153
+ return;
121154
+ case "float32":
121155
+ writer.float32(floatingPoint(value, "float32"));
121156
+ return;
121157
+ case "float64":
121158
+ writer.float64(floatingPoint(value, "float64"));
121159
+ return;
121160
+ case "string": {
121161
+ if (value === null) {
121162
+ writer.int32(-1);
121163
+ return;
121164
+ }
121165
+ if (typeof value !== "string") throw new TypeError("string must be a string or null.");
121166
+ const bytes = new TextEncoder().encode(value);
121167
+ writer.int32(bytes.byteLength);
121168
+ writer.bytes(bytes);
121169
+ return;
121170
+ }
121171
+ }
121172
+ }
121173
+ function normalizePortableResult(type, value) {
121174
+ if (value === null || value === void 0) return value;
121175
+ if (type.kind === "container") {
121176
+ const values3 = type.name === "set" && value instanceof Set ? [...value] : value;
121177
+ if (!Array.isArray(values3)) {
121178
+ throw new TypeError(`TraceCLR ${type.name} result did not decode to a collection.`);
121179
+ }
121180
+ return values3.map((item) => normalizePortableResult(type.element, item));
121181
+ }
121182
+ if (type.kind === "scalar" && (type.name === "int64" || type.name === "uint64")) {
121183
+ if (typeof value !== "bigint") {
121184
+ throw new TypeError(`TraceCLR ${type.name} result did not decode to a bigint.`);
121185
+ }
121186
+ return Number(value);
121187
+ }
121188
+ if (type.kind === "scalar" && (type.name === "float32" || type.name === "float64")) {
121189
+ if (typeof value !== "number") {
121190
+ throw new TypeError(`TraceCLR ${type.name} result did not decode to a number.`);
121191
+ }
121192
+ if (Number.isNaN(value)) return "NaN";
121193
+ if (value === Number.POSITIVE_INFINITY) return "Infinity";
121194
+ if (value === Number.NEGATIVE_INFINITY) return "-Infinity";
121195
+ }
121196
+ return value;
121197
+ }
121198
+ function readLength(reader) {
121199
+ const length3 = reader.int32();
121200
+ if (length3 === -1) return null;
121201
+ if (length3 < 0 || length3 > TRACECLR_WIRE_LIMITS.maxCollectionItems) {
121202
+ throw new RangeError(`Invalid TraceCLR collection length: ${length3}.`);
121203
+ }
121204
+ return length3;
121205
+ }
121206
+ function readByteLength(reader) {
121207
+ const length3 = reader.int32();
121208
+ if (length3 === -1) return null;
121209
+ if (length3 < 0 || length3 > TRACECLR_WIRE_LIMITS.maxBytes) {
121210
+ throw new RangeError(`Invalid TraceCLR byte length: ${length3}.`);
121211
+ }
121212
+ return length3;
121213
+ }
121214
+ function readValue(reader, type, depth) {
121215
+ if (depth > TRACECLR_WIRE_LIMITS.maxDepth) throw new RangeError("TraceCLR value is too deeply nested.");
121216
+ if (type.kind === "container") {
121217
+ const length3 = readLength(reader);
121218
+ if (length3 === null) return null;
121219
+ const values3 = Array.from({ length: length3 }, () => readValue(reader, type.element, depth + 1));
121220
+ return type.name === "set" ? new Set(values3) : values3;
121221
+ }
121222
+ if (type.kind === "list-node") {
121223
+ const length3 = readLength(reader);
121224
+ return length3 === null ? null : Array.from({ length: length3 }, () => reader.int32());
121225
+ }
121226
+ if (type.kind === "tree-node") {
121227
+ const length3 = readLength(reader);
121228
+ if (length3 === null) return null;
121229
+ const values3 = Array.from({ length: length3 }, () => reader.uint8() === 0 ? null : reader.int32());
121230
+ while (values3.at(-1) === null) values3.pop();
121231
+ return values3;
121232
+ }
121233
+ switch (type.name) {
121234
+ case "void":
121235
+ return void 0;
121236
+ case "null":
121237
+ if (reader.uint8() !== 0) throw new RangeError("Invalid TraceCLR null marker.");
121238
+ return null;
121239
+ case "bool": {
121240
+ const value = reader.uint8();
121241
+ if (value > 1) throw new RangeError("Invalid TraceCLR bool.");
121242
+ return value === 1;
121243
+ }
121244
+ case "char":
121245
+ return String.fromCharCode(reader.uint16());
121246
+ case "uint8":
121247
+ return reader.uint8();
121248
+ case "int8":
121249
+ return reader.int8();
121250
+ case "int16":
121251
+ return reader.int16();
121252
+ case "uint16":
121253
+ return reader.uint16();
121254
+ case "int32":
121255
+ return reader.int32();
121256
+ case "uint32":
121257
+ return reader.uint32();
121258
+ case "int64":
121259
+ return reader.int64();
121260
+ case "uint64":
121261
+ return reader.uint64();
121262
+ case "float32":
121263
+ return reader.float32();
121264
+ case "float64":
121265
+ return reader.float64();
121266
+ case "string": {
121267
+ const length3 = readByteLength(reader);
121268
+ return length3 === null ? null : new TextDecoder("utf-8", { fatal: true }).decode(reader.bytes(length3));
121269
+ }
121270
+ }
121271
+ }
121272
+ function begin(writer) {
121273
+ writer.uint32(WIRE_MAGIC);
121274
+ }
121275
+ function verify(reader) {
121276
+ if (reader.uint32() !== WIRE_MAGIC) throw new RangeError("TraceCLR wire magic/version mismatch.");
121277
+ }
121278
+ function encodeTraceClrWireInputs(contract, inputs) {
121279
+ const writer = new WireWriter();
121280
+ begin(writer);
121281
+ writer.uint16(contract.parameters.length);
121282
+ const positionalInputs = Object.values(inputs);
121283
+ for (const [index, parameter] of contract.parameters.entries()) {
121284
+ const value = Object.prototype.hasOwnProperty.call(inputs, parameter.name) ? inputs[parameter.name] : positionalInputs[index];
121285
+ if (value === void 0 && !Object.prototype.hasOwnProperty.call(inputs, parameter.name) && index >= positionalInputs.length) {
121286
+ throw new TypeError(`Missing TraceCLR input: ${parameter.name}`);
121287
+ }
121288
+ writeValue(writer, parseWireType(parameter.type.wireType), value, 0);
121289
+ }
121290
+ return writer.finish();
121291
+ }
121292
+ function decodeTraceClrWireResult(contract, bytes) {
121293
+ const reader = new WireReader(bytes);
121294
+ verify(reader);
121295
+ const type = parseWireType(contract.returnType.wireType);
121296
+ const value = readValue(reader, type, 0);
121297
+ reader.done();
121298
+ return normalizePortableResult(type, value);
121299
+ }
121300
+ var WIRE_MAGIC, TRACECLR_WIRE_LIMITS, WireWriter, WireReader;
121301
+ var init_traceclr_wire = __esm({
121302
+ "packages/runtime-csharp/src/traceclr-wire.ts"() {
121303
+ "use strict";
121304
+ WIRE_MAGIC = 827802452;
121305
+ TRACECLR_WIRE_LIMITS = Object.freeze({
121306
+ maxBytes: 16 * 1024 * 1024,
121307
+ maxCollectionItems: 1e6,
121308
+ maxDepth: 128
121309
+ });
121310
+ WireWriter = class {
121311
+ buffer = new ArrayBuffer(256);
121312
+ view = new DataView(this.buffer);
121313
+ length = 0;
121314
+ reserve(bytes) {
121315
+ const next3 = this.length + bytes;
121316
+ if (!Number.isSafeInteger(bytes) || bytes < 0 || next3 > TRACECLR_WIRE_LIMITS.maxBytes) {
121317
+ throw new RangeError(`TraceCLR wire payload exceeds ${TRACECLR_WIRE_LIMITS.maxBytes} bytes.`);
121318
+ }
121319
+ if (next3 > this.buffer.byteLength) {
121320
+ let capacity3 = this.buffer.byteLength;
121321
+ while (capacity3 < next3) capacity3 = Math.min(TRACECLR_WIRE_LIMITS.maxBytes, capacity3 * 2);
121322
+ const replacement = new ArrayBuffer(capacity3);
121323
+ new Uint8Array(replacement).set(new Uint8Array(this.buffer, 0, this.length));
121324
+ this.buffer = replacement;
121325
+ this.view = new DataView(replacement);
121326
+ }
121327
+ const offset = this.length;
121328
+ this.length = next3;
121329
+ return offset;
121330
+ }
121331
+ uint8(value) {
121332
+ const offset = this.reserve(1);
121333
+ this.view.setUint8(offset, value);
121334
+ }
121335
+ int8(value) {
121336
+ const offset = this.reserve(1);
121337
+ this.view.setInt8(offset, value);
121338
+ }
121339
+ int16(value) {
121340
+ const offset = this.reserve(2);
121341
+ this.view.setInt16(offset, value, true);
121342
+ }
121343
+ uint16(value) {
121344
+ const offset = this.reserve(2);
121345
+ this.view.setUint16(offset, value, true);
121346
+ }
121347
+ int32(value) {
121348
+ const offset = this.reserve(4);
121349
+ this.view.setInt32(offset, value, true);
121350
+ }
121351
+ uint32(value) {
121352
+ const offset = this.reserve(4);
121353
+ this.view.setUint32(offset, value, true);
121354
+ }
121355
+ int64(value) {
121356
+ const offset = this.reserve(8);
121357
+ this.view.setBigInt64(offset, value, true);
121358
+ }
121359
+ uint64(value) {
121360
+ const offset = this.reserve(8);
121361
+ this.view.setBigUint64(offset, value, true);
121362
+ }
121363
+ float32(value) {
121364
+ const offset = this.reserve(4);
121365
+ this.view.setFloat32(offset, value, true);
121366
+ }
121367
+ float64(value) {
121368
+ const offset = this.reserve(8);
121369
+ this.view.setFloat64(offset, value, true);
121370
+ }
121371
+ bytes(value) {
121372
+ const offset = this.reserve(value.byteLength);
121373
+ new Uint8Array(this.buffer, offset, value.byteLength).set(value);
121374
+ }
121375
+ finish() {
121376
+ return new Uint8Array(this.buffer.slice(0, this.length));
121377
+ }
121378
+ };
121379
+ WireReader = class {
121380
+ view;
121381
+ offset = 0;
121382
+ constructor(bytes) {
121383
+ if (bytes.byteLength > TRACECLR_WIRE_LIMITS.maxBytes) {
121384
+ throw new RangeError(`TraceCLR wire payload exceeds ${TRACECLR_WIRE_LIMITS.maxBytes} bytes.`);
121385
+ }
121386
+ this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
121387
+ }
121388
+ take(bytes) {
121389
+ if (this.offset + bytes > this.view.byteLength) {
121390
+ throw new RangeError("TraceCLR wire payload ended unexpectedly.");
121391
+ }
121392
+ const offset = this.offset;
121393
+ this.offset += bytes;
121394
+ return offset;
121395
+ }
121396
+ uint8() {
121397
+ return this.view.getUint8(this.take(1));
121398
+ }
121399
+ int8() {
121400
+ return this.view.getInt8(this.take(1));
121401
+ }
121402
+ int16() {
121403
+ return this.view.getInt16(this.take(2), true);
121404
+ }
121405
+ uint16() {
121406
+ return this.view.getUint16(this.take(2), true);
121407
+ }
121408
+ int32() {
121409
+ return this.view.getInt32(this.take(4), true);
121410
+ }
121411
+ uint32() {
121412
+ return this.view.getUint32(this.take(4), true);
121413
+ }
121414
+ int64() {
121415
+ return this.view.getBigInt64(this.take(8), true);
121416
+ }
121417
+ uint64() {
121418
+ return this.view.getBigUint64(this.take(8), true);
121419
+ }
121420
+ float32() {
121421
+ return this.view.getFloat32(this.take(4), true);
121422
+ }
121423
+ float64() {
121424
+ return this.view.getFloat64(this.take(8), true);
121425
+ }
121426
+ bytes(length3) {
121427
+ return new Uint8Array(this.view.buffer, this.view.byteOffset + this.take(length3), length3);
121428
+ }
121429
+ done() {
121430
+ if (this.offset !== this.view.byteLength) {
121431
+ throw new RangeError(`TraceCLR wire payload has ${this.view.byteLength - this.offset} trailing bytes.`);
121432
+ }
121433
+ }
121434
+ };
121435
+ }
121436
+ });
121437
+
120893
121438
  // packages/runtime-csharp/src/csharp-worker-client.ts
120894
121439
  var csharp_worker_client_exports = {};
120895
121440
  __export(csharp_worker_client_exports, {
@@ -120918,6 +121463,7 @@ var init_csharp_worker_client = __esm({
120918
121463
  init_internal();
120919
121464
  init_internal();
120920
121465
  init_internal();
121466
+ init_traceclr_wire();
120921
121467
  EXECUTION_TIMEOUT_MS2 = 2e4;
120922
121468
  TRACING_TIMEOUT_MS2 = 2e4;
120923
121469
  INIT_TIMEOUT_MS2 = 45e3;
@@ -121284,12 +121830,17 @@ var init_csharp_worker_client = __esm({
121284
121830
  async executePreparedCode(prepared, call) {
121285
121831
  return this.runPreparedExecutionGeneration(call.signal, async () => {
121286
121832
  const wallClockMs = call.limits?.wallClockMs ?? this.executionTimeoutMs;
121833
+ const inputBytes = prepared.preparedRunnerTier === "algorithm-fast" ? encodeTraceClrWireInputs(
121834
+ prepared.traceClrWireContract,
121835
+ call.inputs
121836
+ ) : void 0;
121287
121837
  const program = this.preparedReadyEffect().pipe(
121288
121838
  andThen4(
121289
121839
  this.core.withExecutionDeadline(
121290
121840
  this.sendCommandEffect("execute-prepared-code", {
121291
121841
  prepared,
121292
121842
  inputs: call.inputs,
121843
+ ...inputBytes ? { inputBytes } : {},
121293
121844
  assetBaseUrl: this.options.assetBaseUrl,
121294
121845
  timeoutMs: Math.max(100, wallClockMs - 1e3),
121295
121846
  ...this.workerOptionsPayload()
@@ -121299,6 +121850,17 @@ var init_csharp_worker_client = __esm({
121299
121850
  )
121300
121851
  );
121301
121852
  const result = await this.core.runClientEffect(program, call.signal);
121853
+ if (prepared.preparedRunnerTier === "algorithm-fast" && result.success) {
121854
+ if (!(result.outputBytes instanceof Uint8Array)) {
121855
+ throw new TypeError(
121856
+ "The algorithm-fast C# runner returned no binary output payload."
121857
+ );
121858
+ }
121859
+ result.output = decodeTraceClrWireResult(
121860
+ prepared.traceClrWireContract,
121861
+ result.outputBytes
121862
+ );
121863
+ }
121302
121864
  return this.toCodeExecutionResult(result);
121303
121865
  });
121304
121866
  }
@@ -121310,6 +121872,10 @@ var init_csharp_worker_client = __esm({
121310
121872
  }
121311
121873
  return this.runPreparedExecutionGeneration(call.signal, async () => {
121312
121874
  const wallClockMs = call.limits?.wallClockMs ?? this.resolveTracingTimeoutMs(prepared.functionName, prepared.executionStyle);
121875
+ const inputBytes = prepared.preparedRunnerTier === "algorithm-fast" ? encodeTraceClrWireInputs(
121876
+ prepared.traceClrWireContract,
121877
+ call.inputs
121878
+ ) : void 0;
121313
121879
  let result;
121314
121880
  const program = this.preparedReadyEffect().pipe(
121315
121881
  andThen4(
@@ -121317,6 +121883,7 @@ var init_csharp_worker_client = __esm({
121317
121883
  this.sendCommandEffect("execute-prepared-trace", {
121318
121884
  prepared,
121319
121885
  inputs: call.inputs,
121886
+ ...inputBytes ? { inputBytes } : {},
121320
121887
  ...call.recordTrace === void 0 ? {} : { tracingEnabled: call.recordTrace },
121321
121888
  assetBaseUrl: this.options.assetBaseUrl,
121322
121889
  timeoutMs: Math.max(100, wallClockMs - 1e3),
@@ -121332,6 +121899,17 @@ var init_csharp_worker_client = __esm({
121332
121899
  } catch (error) {
121333
121900
  return this.traceClientFailure(error, wallClockMs);
121334
121901
  }
121902
+ if (prepared.preparedRunnerTier === "algorithm-fast" && result.success) {
121903
+ if (!(result.outputBytes instanceof Uint8Array)) {
121904
+ throw new TypeError(
121905
+ "The algorithm-fast C# trace runner returned no binary output payload."
121906
+ );
121907
+ }
121908
+ result.output = decodeTraceClrWireResult(
121909
+ prepared.traceClrWireContract,
121910
+ result.outputBytes
121911
+ );
121912
+ }
121335
121913
  return this.toTraceExecutionResult(
121336
121914
  result,
121337
121915
  prepared.traceOptions,
@@ -122910,6 +123488,7 @@ function createCppPreparedExecutionProvider(options) {
122910
123488
  let terminated = false;
122911
123489
  const ownedClients = /* @__PURE__ */ new Set();
122912
123490
  const activePrograms = /* @__PURE__ */ new Set();
123491
+ let scheduledCompilerPrewarm = null;
122913
123492
  const createClient = () => {
122914
123493
  const client = options.createWorkerClient();
122915
123494
  ownedClients.add(client);
@@ -122937,6 +123516,21 @@ function createCppPreparedExecutionProvider(options) {
122937
123516
  standbyClient = null;
122938
123517
  return client;
122939
123518
  };
123519
+ const cancelScheduledCompilerPrewarm = () => {
123520
+ scheduledCompilerPrewarm?.cancel();
123521
+ scheduledCompilerPrewarm = null;
123522
+ };
123523
+ const scheduleCompilerPrewarm = () => {
123524
+ if (terminated || scheduledCompilerPrewarm || !options.prewarmCompiler || !options.scheduleCompilerPrewarm) {
123525
+ return;
123526
+ }
123527
+ const expectedGeneration = generation;
123528
+ scheduledCompilerPrewarm = options.scheduleCompilerPrewarm(async () => {
123529
+ assertGeneration(expectedGeneration);
123530
+ await options.prewarmCompiler?.();
123531
+ assertGeneration(expectedGeneration);
123532
+ });
123533
+ };
122940
123534
  return {
122941
123535
  async init() {
122942
123536
  assertActive();
@@ -122955,6 +123549,7 @@ function createCppPreparedExecutionProvider(options) {
122955
123549
  const result = await client.init();
122956
123550
  assertGeneration(expectedGeneration);
122957
123551
  standbyClient = client;
123552
+ scheduleCompilerPrewarm();
122958
123553
  return {
122959
123554
  success: result.success,
122960
123555
  loadTimeMs: result.loadTimeMs
@@ -122966,6 +123561,12 @@ function createCppPreparedExecutionProvider(options) {
122966
123561
  },
122967
123562
  async prepareProgram(call) {
122968
123563
  const expectedGeneration = generation;
123564
+ const compilerPrewarm = scheduledCompilerPrewarm;
123565
+ scheduledCompilerPrewarm = null;
123566
+ if (compilerPrewarm) {
123567
+ await compilerPrewarm.promote().catch(() => void 0);
123568
+ assertGeneration(expectedGeneration);
123569
+ }
122969
123570
  const client = acquireClient();
122970
123571
  try {
122971
123572
  await client.init();
@@ -123096,6 +123697,7 @@ function createCppPreparedExecutionProvider(options) {
123096
123697
  },
123097
123698
  reset() {
123098
123699
  assertActive();
123700
+ cancelScheduledCompilerPrewarm();
123099
123701
  generation += 1;
123100
123702
  for (const forceDispose of [...activePrograms]) forceDispose();
123101
123703
  for (const client of [...ownedClients]) retireClient(client);
@@ -123103,6 +123705,7 @@ function createCppPreparedExecutionProvider(options) {
123103
123705
  },
123104
123706
  terminate() {
123105
123707
  if (terminated) return;
123708
+ cancelScheduledCompilerPrewarm();
123106
123709
  generation += 1;
123107
123710
  terminated = true;
123108
123711
  for (const forceDispose of [...activePrograms]) forceDispose();
@@ -123202,8 +123805,30 @@ var init_tracecc_compiler_service = __esm({
123202
123805
  requestTimeoutMs;
123203
123806
  artifactCache = /* @__PURE__ */ new Map();
123204
123807
  artifactCacheBytes = 0;
123808
+ /**
123809
+ * Fetch and verify the immutable compiler inputs inside the trusted compiler
123810
+ * Worker without compiling or instantiating TraceCC. A foreground compile
123811
+ * joins the Worker's immutable byte cache.
123812
+ */
123813
+ async prewarmAssets(shard = "narrow") {
123814
+ await this.ensureWorker();
123815
+ const selected = this.options.shards[shard];
123816
+ const result = await this.send("prewarm-trusted-tracecc-assets", {
123817
+ ...this.traceccAssets(
123818
+ selected,
123819
+ `/tracecc-assets/${shard}.pch`,
123820
+ `/tracecc-assets/${shard}.o`
123821
+ ),
123822
+ source: "tracecc-prewarm-assets-v1"
123823
+ });
123824
+ if (result.success !== true) {
123825
+ throw new Error(
123826
+ typeof result.error === "string" ? result.error : "TraceCC compiler asset prewarm failed."
123827
+ );
123828
+ }
123829
+ }
123205
123830
  async warmup(shard = "narrow") {
123206
- await this.options.assetPreflight?.(shard);
123831
+ await this.prewarmAssets(shard);
123207
123832
  await this.ensureWorker();
123208
123833
  const selected = this.options.shards[shard];
123209
123834
  const pchPath = `/tracecc-assets/${shard}.pch`;
@@ -123270,7 +123895,6 @@ var init_tracecc_compiler_service = __esm({
123270
123895
  ""
123271
123896
  );
123272
123897
  const shard = traceccShardForDriver(strippedSource);
123273
- await this.options.assetPreflight?.(shard);
123274
123898
  if (signal?.aborted || generation !== this.generation) {
123275
123899
  throw Object.assign(
123276
123900
  new Error("TraceCC compilation was cancelled."),
@@ -123448,7 +124072,6 @@ var init_tracecc_compiler_service = __esm({
123448
124072
  error: "TraceCC trusted Project compilation only accepts compile requests."
123449
124073
  };
123450
124074
  }
123451
- await this.options.commonAssetPreflight?.();
123452
124075
  if (signal?.aborted || generation !== this.generation) {
123453
124076
  throw Object.assign(
123454
124077
  new Error("TraceCC Project compilation was cancelled."),
@@ -123654,36 +124277,18 @@ function createTraceCCBrowserCompilerService(compiler, context2) {
123654
124277
  ...DEFAULT_TRACECC_RESOURCE_NAMES,
123655
124278
  ...compiler.resourceNames ?? {}
123656
124279
  };
123657
- const commonCompilerAssetNames = [
123658
- "runtimeHeader",
123659
- "compilerWasm",
123660
- "linkerWasm",
123661
- "sysroot"
123662
- ];
123663
- const commonAssetPreflight = () => context2.preflight(commonCompilerAssetNames);
123664
124280
  const compilerIntegrity = context2.assets.cppCompilerIntegrity;
123665
124281
  if (!compilerIntegrity) {
123666
124282
  throw new Error(
123667
124283
  "TraceCC requires exact compiler integrity entries from a C++ runtime manifest."
123668
124284
  );
123669
124285
  }
123670
- const shardAssetPreflight = (shard) => {
123671
- const prefix = shard === "map" ? "map" : shard;
123672
- return context2.preflight([
123673
- ...commonCompilerAssetNames,
123674
- `compilerResources.${resourceNames[`${prefix}Pch`]}`,
123675
- `compilerResources.${resourceNames[`${prefix}PchSource`]}`,
123676
- `compilerResources.${resourceNames[`${prefix}RuntimeObject`]}`
123677
- ]);
123678
- };
123679
124286
  return new TraceCCCompilerService({
123680
124287
  workerUrl: context2.assets.cppWorker,
123681
124288
  compilerUrl: context2.assets.cppCompilerWasm,
123682
124289
  resourcesUrl: context2.assets.cppSysroot,
123683
124290
  runtimeHeaderUrl: context2.assets.cppRuntimeHeader,
123684
124291
  compilerIntegrity,
123685
- commonAssetPreflight,
123686
- assetPreflight: shardAssetPreflight,
123687
124292
  shards: {
123688
124293
  narrow: traceccShardAssets(
123689
124294
  traceccResources,
@@ -123712,18 +124317,9 @@ function createCppBrowserRuntimeProvider(options = {}) {
123712
124317
  create(context2) {
123713
124318
  const workerFactory = context2.workerFactoryFor("cpp");
123714
124319
  const compiler = options.compiler ?? {};
123715
- const commonCompilerAssetNames = [
123716
- "runtimeHeader",
123717
- "compilerWasm",
123718
- "linkerWasm",
123719
- "sysroot"
123720
- ];
123721
- const runtimeAssetPreflight = context2.preflight("cpp", commonCompilerAssetNames);
123722
124320
  const workerOptions = {
123723
124321
  workerUrl: context2.assets.cppWorker,
123724
124322
  ...workerFactory ? { workerFactory } : {},
123725
- assetPreflight: context2.preflight("cpp", ["worker"]),
123726
- runtimeAssetPreflight,
123727
124323
  compilerWasmUrl: context2.assets.cppCompilerWasm,
123728
124324
  linkerWasmUrl: context2.assets.cppLinkerWasm,
123729
124325
  sysrootUrl: context2.assets.cppSysroot,
@@ -123739,8 +124335,7 @@ function createCppBrowserRuntimeProvider(options = {}) {
123739
124335
  };
123740
124336
  const compilerService = createTraceCCBrowserCompilerService(compiler, {
123741
124337
  assets: context2.assets,
123742
- ...workerFactory ? { workerFactory } : {},
123743
- preflight: (assetNames) => context2.preflight("cpp", assetNames)()
124338
+ ...workerFactory ? { workerFactory } : {}
123744
124339
  });
123745
124340
  const createWorkerClient = () => new CppWorkerClient({
123746
124341
  ...workerOptions,
@@ -123748,7 +124343,9 @@ function createCppBrowserRuntimeProvider(options = {}) {
123748
124343
  });
123749
124344
  const preparedProvider = createCppPreparedExecutionProvider({
123750
124345
  createWorkerClient,
123751
- warmCompilerOnInit: true
124346
+ warmCompilerOnInit: false,
124347
+ prewarmCompiler: () => compilerService.prewarmAssets(),
124348
+ scheduleCompilerPrewarm: createPromotableBrowserBackgroundTask
123752
124349
  });
123753
124350
  const preparedProviders = /* @__PURE__ */ new Map([["cpp", preparedProvider]]);
123754
124351
  const terminateCompiler = () => {
@@ -123772,6 +124369,7 @@ var DEFAULT_TRACECC_RESOURCE_NAMES;
123772
124369
  var init_browser_runtime_provider = __esm({
123773
124370
  "packages/runtime-cpp/src/browser-runtime-provider.ts"() {
123774
124371
  "use strict";
124372
+ init_internal();
123775
124373
  init_cpp_prepared_provider();
123776
124374
  init_cpp_worker_client();
123777
124375
  init_tracecc_compiler_service();
@@ -219567,22 +220165,13 @@ async function createBrowserProjectWorkspace(options = {}) {
219567
220165
  } : {}
219568
220166
  };
219569
220167
  const cppCompilerWorkerFactory = executionHost && isExecutionHosted("cpp") ? executionHost.workerFactory : void 0;
219570
- const cppRuntimeAssetPreflight = () => runtimeAssetPreflight.preflight("cpp", [
219571
- "runtimeHeader",
219572
- "compilerWasm",
219573
- "linkerWasm",
219574
- "sysroot"
219575
- ]);
219576
220168
  const traceccCompilerService = cppProvider && !injectedCppProvider ? cppProvider[2].createTraceCCBrowserCompilerService({}, {
219577
220169
  assets,
219578
- ...cppCompilerWorkerFactory ? { workerFactory: cppCompilerWorkerFactory } : {},
219579
- preflight: (assetNames) => runtimeAssetPreflight.preflight("cpp", assetNames)
220170
+ ...cppCompilerWorkerFactory ? { workerFactory: cppCompilerWorkerFactory } : {}
219580
220171
  }) : void 0;
219581
220172
  const cppWorkerOptions = {
219582
220173
  workerUrl: assets.cppWorker,
219583
220174
  ...cppCompilerWorkerFactory ? { workerFactory: cppCompilerWorkerFactory } : {},
219584
- assetPreflight: () => runtimeAssetPreflight.preflight("cpp", ["worker"]),
219585
- runtimeAssetPreflight: cppRuntimeAssetPreflight,
219586
220175
  compilerWasmUrl: assets.cppCompilerWasm,
219587
220176
  linkerWasmUrl: assets.cppLinkerWasm,
219588
220177
  sysrootUrl: assets.cppSysroot,
@@ -219786,14 +220375,7 @@ function preflightAssets(language, surface, csharpPreparedAuthority) {
219786
220375
  "runnerDependencies"
219787
220376
  ];
219788
220377
  case "cpp":
219789
- return [
219790
- "worker",
219791
- "runtimeHeader",
219792
- "compilerWasm",
219793
- "linkerWasm",
219794
- "sysroot",
219795
- "compilerResources"
219796
- ];
220378
+ return [];
219797
220379
  }
219798
220380
  }
219799
220381
  function detectEngine(userAgent = globalThis.navigator?.userAgent ?? "") {