@nice-code/commander 0.108.0 → 0.110.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cli.cjs +523 -277
- package/build/cli.cjs.map +1 -1
- package/build/cli.mjs +523 -277
- package/build/cli.mjs.map +1 -1
- package/build/client/assets/index-dItAKcyH.js +23 -0
- package/build/client/assets/index-dItAKcyH.js.map +1 -0
- package/build/client/index.html +1 -1
- package/build/{main-BHPsC_5Q.cjs → main-CVu9gjbx.cjs} +67 -4
- package/build/main-CVu9gjbx.cjs.map +1 -0
- package/build/{main-1B7viLr8.mjs → main-CWWlV2U5.mjs} +69 -6
- package/build/main-CWWlV2U5.mjs.map +1 -0
- package/package.json +6 -6
- package/build/client/assets/index-RGFhhnpd.js +0 -23
- package/build/client/assets/index-RGFhhnpd.js.map +0 -1
- package/build/main-1B7viLr8.mjs.map +0 -1
- package/build/main-BHPsC_5Q.cjs.map +0 -1
package/build/cli.mjs
CHANGED
|
@@ -1379,6 +1379,7 @@ function wsAcceptorCarrier(options) {
|
|
|
1379
1379
|
carrierLabel: options.carrierLabel ?? "ws",
|
|
1380
1380
|
secure: options.secure,
|
|
1381
1381
|
send: options.send,
|
|
1382
|
+
close: options.close,
|
|
1382
1383
|
upgrade: options.upgrade,
|
|
1383
1384
|
isUpgrade: options.isUpgrade ?? ((request) => request.headers.get("Upgrade") === "websocket"),
|
|
1384
1385
|
attachmentStore: options.attachmentStore
|
|
@@ -2432,16 +2433,16 @@ const err_wire_connect = err_nice.createChildDomain({
|
|
|
2432
2433
|
*/
|
|
2433
2434
|
endpoint_answered_non_protocol: err({ message: ({ stage, expected, url, httpStatus, contentType, receivedKind, bodyPreview }) => {
|
|
2434
2435
|
const received = httpStatus != null ? `an HTTP ${httpStatus}${contentType != null ? ` ${contentType}` : ""} response` : receivedKind != null ? `a "${receivedKind}" frame` : "a response it could not decode";
|
|
2435
|
-
|
|
2436
|
+
const diagnosis = httpStatus != null && httpStatus >= 500 ? "the server answered with an error instead of a nice-wire frame (check the server's logs: a crashed handler or an unavailable upstream answers this way)" : "the endpoint answered but is not speaking the nice-wire protocol (wrong URL, an intercepting proxy/WAF, or a different server)";
|
|
2437
|
+
return `[${stage}] expected ${expected ?? "a nice-wire frame"} but received ${received} — ` + diagnosis + `${url != null ? `. Dialed: ${url}` : ""}${bodyPreview != null ? `. Body: ${JSON.stringify(bodyPreview)}` : ""}.`;
|
|
2436
2438
|
} }),
|
|
2437
2439
|
/**
|
|
2438
|
-
*
|
|
2439
|
-
* or a
|
|
2440
|
-
*
|
|
2441
|
-
*
|
|
2442
|
-
* proxy in front of it).
|
|
2440
|
+
* **No response was received**: DNS/refused/TLS/offline, a socket that errored before it
|
|
2441
|
+
* opened, or a response the platform hid from the caller (a CORS-blocked answer, a refused
|
|
2442
|
+
* WebSocket upgrade, an injected fetch/socket that threw). The sibling of
|
|
2443
|
+
* `endpoint_answered_non_protocol`, which carries the response it did see.
|
|
2443
2444
|
*/
|
|
2444
|
-
endpoint_unreachable: err({ message: ({ url, carrierLabel, reason }) => `Could not reach ${url ?? (carrierLabel != null ? `the "${carrierLabel}" endpoint` : "the endpoint")}: ${reason} —
|
|
2445
|
+
endpoint_unreachable: err({ message: ({ url, carrierLabel, reason }) => `Could not reach ${url ?? (carrierLabel != null ? `the "${carrierLabel}" endpoint` : "the endpoint")}: ${reason} — no response was received (a network, DNS or TLS failure; a response the browser blocked or hid, such as a CORS rejection or a refused WebSocket upgrade; or the fetch/socket implementation threw).` }),
|
|
2445
2446
|
/**
|
|
2446
2447
|
* The peer **is** a nice-code backend and refused the handshake for a reason that carries no
|
|
2447
2448
|
* machine-readable id of its own (an older peer, a dictionary/security mismatch, a custom
|
|
@@ -2484,6 +2485,29 @@ const err_wire_connect = err_nice.createChildDomain({
|
|
|
2484
2485
|
}
|
|
2485
2486
|
});
|
|
2486
2487
|
//#endregion
|
|
2488
|
+
//#region ../nice-wire/src/Connect/sanitizeEndpoint.ts
|
|
2489
|
+
/**
|
|
2490
|
+
* A destination safe to put in diagnostics. Credentials, query parameters, and fragments can carry
|
|
2491
|
+
* secrets (capability tokens, signed leases), so only the scheme, host, port, and path survive.
|
|
2492
|
+
*/
|
|
2493
|
+
function sanitizeEndpoint(raw) {
|
|
2494
|
+
if (raw == null) return void 0;
|
|
2495
|
+
try {
|
|
2496
|
+
const url = new URL(raw);
|
|
2497
|
+
if (url.host !== "") {
|
|
2498
|
+
url.username = "";
|
|
2499
|
+
url.password = "";
|
|
2500
|
+
url.search = "";
|
|
2501
|
+
url.hash = "";
|
|
2502
|
+
return url.toString();
|
|
2503
|
+
}
|
|
2504
|
+
} catch {}
|
|
2505
|
+
const head = raw.split(/[?#]/, 1)[0] ?? "";
|
|
2506
|
+
const authority = /^([a-z][a-z\d+.-]*:)?\/\//i.exec(head);
|
|
2507
|
+
if (authority != null) return authority[0] + head.slice(authority[0].length).replace(/^[^/@]*@/, "");
|
|
2508
|
+
return head.replace(/^[^/]*@/, "");
|
|
2509
|
+
}
|
|
2510
|
+
//#endregion
|
|
2487
2511
|
//#region ../nice-wire/src/Carrier/duplex/ws/ws_util.ts
|
|
2488
2512
|
/**
|
|
2489
2513
|
* Send a text or binary frame over a socket. A binary formatter may hand back a `Uint8Array` whose
|
|
@@ -2578,8 +2602,9 @@ function webSocketByteChannel(ws) {
|
|
|
2578
2602
|
}
|
|
2579
2603
|
/**
|
|
2580
2604
|
* A failed dial, as a structured error the error pipeline (and a consumer's logs) can actually
|
|
2581
|
-
* read. A socket that errors or closes *before* it opened
|
|
2582
|
-
*
|
|
2605
|
+
* read. A socket that errors or closes *before* it opened yields no readable response (the browser
|
|
2606
|
+
* also hides a refused upgrade's status), so it carries the same typed `endpoint_unreachable` id as
|
|
2607
|
+
* the HTTP carrier's `fetch` rejection — that is what
|
|
2583
2608
|
* makes `EWireConnectFailureKind` trustworthy on both carriers rather than HTTP-only (feedback W3).
|
|
2584
2609
|
*/
|
|
2585
2610
|
function dialFailedError(ws) {
|
|
@@ -2587,13 +2612,13 @@ function dialFailedError(ws) {
|
|
|
2587
2612
|
}
|
|
2588
2613
|
function unreachableError(ws, reason) {
|
|
2589
2614
|
return err_wire_connect.fromId("endpoint_unreachable", {
|
|
2590
|
-
url: ws.url != null && ws.url !== "" ? ws.url : void 0,
|
|
2615
|
+
url: ws.url != null && ws.url !== "" ? sanitizeEndpoint(ws.url) : void 0,
|
|
2591
2616
|
carrierLabel: "ws",
|
|
2592
2617
|
reason
|
|
2593
2618
|
});
|
|
2594
2619
|
}
|
|
2595
2620
|
function describeSocket(ws) {
|
|
2596
|
-
return ws.url != null && ws.url !== "" ? ws.url : "(no url)";
|
|
2621
|
+
return (ws.url != null && ws.url !== "" ? sanitizeEndpoint(ws.url) : void 0) ?? "(no url)";
|
|
2597
2622
|
}
|
|
2598
2623
|
/** Accept text + binary frames (ArrayBuffer / Uint8Array / Blob); Blobs are converted to a buffer. */
|
|
2599
2624
|
async function normalizeFrame(data) {
|
|
@@ -2676,23 +2701,6 @@ function describeNonProtocolBody(raw) {
|
|
|
2676
2701
|
return flattened.length > BODY_PREVIEW_LIMIT ? `${flattened.slice(0, BODY_PREVIEW_LIMIT)}…` : flattened;
|
|
2677
2702
|
}
|
|
2678
2703
|
/**
|
|
2679
|
-
* A destination safe to put in diagnostics. Credentials, query parameters, and fragments can
|
|
2680
|
-
* contain secrets, so connection errors retain only the scheme, host, port, and path.
|
|
2681
|
-
*/
|
|
2682
|
-
function sanitizeEndpoint(raw) {
|
|
2683
|
-
if (raw == null) return void 0;
|
|
2684
|
-
try {
|
|
2685
|
-
const url = new URL(raw);
|
|
2686
|
-
url.username = "";
|
|
2687
|
-
url.password = "";
|
|
2688
|
-
url.search = "";
|
|
2689
|
-
url.hash = "";
|
|
2690
|
-
return url.toString();
|
|
2691
|
-
} catch {
|
|
2692
|
-
return raw.split(/[?#]/, 1)[0];
|
|
2693
|
-
}
|
|
2694
|
-
}
|
|
2695
|
-
/**
|
|
2696
2704
|
* Classify a dial failure. Reads typed ids only — the ids are raised at the layer that still holds
|
|
2697
2705
|
* the evidence precisely so this never has to sniff message text.
|
|
2698
2706
|
*/
|
|
@@ -2705,12 +2713,12 @@ function classifyConnectFailure(error) {
|
|
|
2705
2713
|
if (error.hasId("identity_pin_mismatch") || error.hasId("handshake_rejected")) return "handshake_rejected";
|
|
2706
2714
|
return "unknown";
|
|
2707
2715
|
}
|
|
2708
|
-
/** The endpoint a failure names, when it carries one — the URL actually dialed. */
|
|
2716
|
+
/** The endpoint a failure names, when it carries one — the URL actually dialed, sanitized. */
|
|
2709
2717
|
function endpointFromConnectFailure(error) {
|
|
2710
2718
|
if (!err_wire_connect.isExact(error)) return void 0;
|
|
2711
|
-
if (error.hasId("endpoint_answered_non_protocol")) return error.getContext("endpoint_answered_non_protocol").url;
|
|
2712
|
-
if (error.hasId("endpoint_unreachable")) return error.getContext("endpoint_unreachable").url;
|
|
2713
|
-
if (error.hasId("peer_identity_mismatch")) return error.getContext("peer_identity_mismatch").endpoint;
|
|
2719
|
+
if (error.hasId("endpoint_answered_non_protocol")) return sanitizeEndpoint(error.getContext("endpoint_answered_non_protocol").url);
|
|
2720
|
+
if (error.hasId("endpoint_unreachable")) return sanitizeEndpoint(error.getContext("endpoint_unreachable").url);
|
|
2721
|
+
if (error.hasId("peer_identity_mismatch")) return sanitizeEndpoint(error.getContext("peer_identity_mismatch").endpoint);
|
|
2714
2722
|
}
|
|
2715
2723
|
//#endregion
|
|
2716
2724
|
//#region ../nice-wire/src/Connect/ConnectionTransportManager.ts
|
|
@@ -2745,81 +2753,110 @@ var ConnectionTransportManager$1 = class {
|
|
|
2745
2753
|
const candidates = [];
|
|
2746
2754
|
const unavailableTransports = [];
|
|
2747
2755
|
for (const transport of this._transports) {
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
if (
|
|
2756
|
-
|
|
2756
|
+
let cacheKey = null;
|
|
2757
|
+
try {
|
|
2758
|
+
if (!transport.isAvailable(input)) {
|
|
2759
|
+
unavailableTransports.push(transport);
|
|
2760
|
+
continue;
|
|
2761
|
+
}
|
|
2762
|
+
cacheKey = transport.getCacheKey(input);
|
|
2763
|
+
if (cacheKey != null) {
|
|
2764
|
+
const cached = this._cache.get(cacheKey);
|
|
2765
|
+
if (cached != null) {
|
|
2766
|
+
if (cached instanceof Promise) {
|
|
2767
|
+
candidates.push({
|
|
2768
|
+
transport,
|
|
2769
|
+
promise: cached,
|
|
2770
|
+
cacheKey,
|
|
2771
|
+
fresh: false
|
|
2772
|
+
});
|
|
2773
|
+
continue;
|
|
2774
|
+
}
|
|
2757
2775
|
candidates.push({
|
|
2758
2776
|
transport,
|
|
2759
|
-
promise:
|
|
2777
|
+
promise: Promise.resolve({
|
|
2778
|
+
...cached,
|
|
2779
|
+
transport
|
|
2780
|
+
}),
|
|
2781
|
+
cacheKey,
|
|
2782
|
+
fresh: false
|
|
2783
|
+
});
|
|
2784
|
+
break;
|
|
2785
|
+
}
|
|
2786
|
+
}
|
|
2787
|
+
const statusInfo = transport.getTransport(input);
|
|
2788
|
+
if (statusInfo.status === "ready") {
|
|
2789
|
+
const readyData = statusInfo.readyData;
|
|
2790
|
+
if (cacheKey != null) {
|
|
2791
|
+
const key = cacheKey;
|
|
2792
|
+
const entry = {
|
|
2793
|
+
methods: readyData,
|
|
2794
|
+
transport
|
|
2795
|
+
};
|
|
2796
|
+
this._cache.set(key, entry);
|
|
2797
|
+
readyData.addOnDisconnectListener?.(() => {
|
|
2798
|
+
if (this._cache.get(key) === entry) this._cache.delete(key);
|
|
2760
2799
|
});
|
|
2761
|
-
continue;
|
|
2762
2800
|
}
|
|
2763
2801
|
candidates.push({
|
|
2764
2802
|
transport,
|
|
2765
2803
|
promise: Promise.resolve({
|
|
2766
|
-
|
|
2804
|
+
methods: readyData,
|
|
2767
2805
|
transport
|
|
2768
|
-
})
|
|
2806
|
+
}),
|
|
2807
|
+
cacheKey,
|
|
2808
|
+
fresh: true
|
|
2769
2809
|
});
|
|
2770
2810
|
break;
|
|
2771
2811
|
}
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
if (
|
|
2777
|
-
const
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2812
|
+
if (statusInfo.status === "unsupported") {
|
|
2813
|
+
unavailableTransports.push(transport);
|
|
2814
|
+
continue;
|
|
2815
|
+
}
|
|
2816
|
+
if (statusInfo.status === "initializing") {
|
|
2817
|
+
const key = cacheKey;
|
|
2818
|
+
const promise = statusInfo.initializationPromise.then((info) => {
|
|
2819
|
+
if (info.status === "failed") throw info.error;
|
|
2820
|
+
if (info.status === "unsupported") throw this._errors.unsupported([transport.type]);
|
|
2821
|
+
const readyData = info.readyData;
|
|
2822
|
+
const entry = {
|
|
2823
|
+
methods: readyData,
|
|
2824
|
+
transport
|
|
2825
|
+
};
|
|
2826
|
+
if (key != null) if (this._cache.get(key) === promise) {
|
|
2827
|
+
this._cache.set(key, entry);
|
|
2828
|
+
readyData.addOnDisconnectListener?.(() => {
|
|
2829
|
+
if (this._cache.get(key) === entry) this._cache.delete(key);
|
|
2830
|
+
});
|
|
2831
|
+
} else readyData.disconnect?.();
|
|
2832
|
+
return entry;
|
|
2833
|
+
}).catch((e) => {
|
|
2834
|
+
if (key != null && this._cache.get(key) === promise) this._cache.delete(key);
|
|
2835
|
+
throw e;
|
|
2836
|
+
});
|
|
2837
|
+
promise.catch(() => {});
|
|
2838
|
+
if (key != null) this._cache.set(key, promise);
|
|
2839
|
+
candidates.push({
|
|
2840
|
+
transport,
|
|
2841
|
+
promise,
|
|
2842
|
+
cacheKey: key,
|
|
2843
|
+
fresh: true
|
|
2784
2844
|
});
|
|
2785
2845
|
}
|
|
2846
|
+
} catch (e) {
|
|
2847
|
+
if (isDialUnavailable$1(e)) {
|
|
2848
|
+
if (candidates.length === 0) throw e;
|
|
2849
|
+
unavailableTransports.push(transport);
|
|
2850
|
+
continue;
|
|
2851
|
+
}
|
|
2852
|
+
const failed = Promise.reject(e);
|
|
2853
|
+
failed.catch(() => {});
|
|
2786
2854
|
candidates.push({
|
|
2787
2855
|
transport,
|
|
2788
|
-
promise:
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
});
|
|
2793
|
-
break;
|
|
2794
|
-
}
|
|
2795
|
-
if (statusInfo.status === "unsupported") {
|
|
2796
|
-
unavailableTransports.push(transport);
|
|
2797
|
-
continue;
|
|
2798
|
-
}
|
|
2799
|
-
if (statusInfo.status === "initializing") {
|
|
2800
|
-
const promise = statusInfo.initializationPromise.then((info) => {
|
|
2801
|
-
if (info.status === "failed") throw info.error;
|
|
2802
|
-
if (info.status === "unsupported") throw this._errors.unsupported([transport.type]);
|
|
2803
|
-
const readyData = info.readyData;
|
|
2804
|
-
const entry = {
|
|
2805
|
-
methods: readyData,
|
|
2806
|
-
transport
|
|
2807
|
-
};
|
|
2808
|
-
if (cacheKey != null) if (this._cache.get(cacheKey) === promise) {
|
|
2809
|
-
this._cache.set(cacheKey, entry);
|
|
2810
|
-
readyData.addOnDisconnectListener?.(() => {
|
|
2811
|
-
if (this._cache.get(cacheKey) === entry) this._cache.delete(cacheKey);
|
|
2812
|
-
});
|
|
2813
|
-
} else readyData.disconnect?.();
|
|
2814
|
-
return entry;
|
|
2815
|
-
}).catch((e) => {
|
|
2816
|
-
if (cacheKey != null && this._cache.get(cacheKey) === promise) this._cache.delete(cacheKey);
|
|
2817
|
-
throw e;
|
|
2818
|
-
});
|
|
2819
|
-
if (cacheKey != null) this._cache.set(cacheKey, promise);
|
|
2820
|
-
candidates.push({
|
|
2821
|
-
transport,
|
|
2822
|
-
promise
|
|
2856
|
+
promise: failed,
|
|
2857
|
+
cacheKey,
|
|
2858
|
+
fresh: true,
|
|
2859
|
+
callerThrew: true
|
|
2823
2860
|
});
|
|
2824
2861
|
}
|
|
2825
2862
|
}
|
|
@@ -2829,31 +2866,79 @@ var ConnectionTransportManager$1 = class {
|
|
|
2829
2866
|
}
|
|
2830
2867
|
let lastError;
|
|
2831
2868
|
let lastTransport;
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
if (
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
}
|
|
2842
|
-
|
|
2869
|
+
let lastCallerThrew = false;
|
|
2870
|
+
for (const candidate of candidates) {
|
|
2871
|
+
let ready;
|
|
2872
|
+
try {
|
|
2873
|
+
ready = await candidate.promise;
|
|
2874
|
+
} catch (e) {
|
|
2875
|
+
if (isTerminalSelectionError(e)) {
|
|
2876
|
+
this._abandonWarmUps(candidates, candidate);
|
|
2877
|
+
throw this._withDialedEndpoint(e, candidate.transport, input);
|
|
2878
|
+
}
|
|
2879
|
+
lastError = e;
|
|
2880
|
+
lastTransport = candidate.transport;
|
|
2881
|
+
lastCallerThrew = candidate.callerThrew === true;
|
|
2882
|
+
continue;
|
|
2843
2883
|
}
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
lastTransport = candidate.transport;
|
|
2884
|
+
ready.methods.onSelected?.();
|
|
2885
|
+
return ready;
|
|
2847
2886
|
}
|
|
2848
2887
|
if (err_wire_connect.isExact(lastError) && (lastError.hasId("dial_unavailable") || lastError.hasId("identity_pin_mismatch") || lastError.hasId("protocol_version_mismatch") || lastError.hasId("peer_identity_mismatch"))) throw lastError;
|
|
2888
|
+
if (lastCallerThrew && !err_wire_connect.isExact(lastError)) throw lastError;
|
|
2849
2889
|
throw this._errors.initializationFailed(input, {
|
|
2850
2890
|
cause: describeTransportFailure(lastError),
|
|
2851
|
-
endpoint: endpointFromConnectFailure(lastError) ?? lastTransport
|
|
2891
|
+
endpoint: endpointFromConnectFailure(lastError) ?? routeEndpoint(lastTransport, input),
|
|
2852
2892
|
kind: classifyConnectFailure(lastError),
|
|
2853
2893
|
origin: lastError
|
|
2854
2894
|
});
|
|
2855
2895
|
}
|
|
2896
|
+
/**
|
|
2897
|
+
* Close the parallel warm-ups this selection started besides `failed`. Each one's cache slot is
|
|
2898
|
+
* released so a later dispatch re-dials; a warm-up still connecting closes itself when it lands.
|
|
2899
|
+
*/
|
|
2900
|
+
_abandonWarmUps(candidates, failed) {
|
|
2901
|
+
for (const candidate of candidates) {
|
|
2902
|
+
if (candidate === failed || !candidate.fresh) continue;
|
|
2903
|
+
const key = candidate.cacheKey;
|
|
2904
|
+
if (key != null && this._cache.get(key) === candidate.promise) this._cache.delete(key);
|
|
2905
|
+
candidate.promise.then((entry) => {
|
|
2906
|
+
if (key == null) {
|
|
2907
|
+
entry.methods.disconnect?.();
|
|
2908
|
+
return;
|
|
2909
|
+
}
|
|
2910
|
+
const cached = this._cache.get(key);
|
|
2911
|
+
if (cached != null && !(cached instanceof Promise) && cached.methods === entry.methods) {
|
|
2912
|
+
this._cache.delete(key);
|
|
2913
|
+
entry.methods.disconnect?.();
|
|
2914
|
+
}
|
|
2915
|
+
}, () => {});
|
|
2916
|
+
}
|
|
2917
|
+
}
|
|
2918
|
+
/** Attach the sanitized dialed endpoint to a peer-identity mismatch that lacks one. */
|
|
2919
|
+
_withDialedEndpoint(error, transport, input) {
|
|
2920
|
+
if (!err_wire_connect.isExact(error) || !error.hasId("peer_identity_mismatch")) return error;
|
|
2921
|
+
const context = error.getContext("peer_identity_mismatch");
|
|
2922
|
+
if (context.endpoint != null) return error;
|
|
2923
|
+
const endpoint = routeEndpoint(transport, input);
|
|
2924
|
+
if (endpoint == null) return error;
|
|
2925
|
+
return err_wire_connect.fromId("peer_identity_mismatch", {
|
|
2926
|
+
...context,
|
|
2927
|
+
endpoint
|
|
2928
|
+
}).withOriginError(error);
|
|
2929
|
+
}
|
|
2856
2930
|
};
|
|
2931
|
+
const isDialUnavailable$1 = (error) => err_wire_connect.isExact(error) && error.hasId("dial_unavailable");
|
|
2932
|
+
const isTerminalSelectionError = (error) => err_wire_connect.isExact(error) && (error.hasId("peer_identity_mismatch") || error.hasId("protocol_version_mismatch"));
|
|
2933
|
+
/** The transport's sanitized route URL for diagnostics; a throwing route resolver yields none. */
|
|
2934
|
+
function routeEndpoint(transport, input) {
|
|
2935
|
+
if (transport == null) return void 0;
|
|
2936
|
+
try {
|
|
2937
|
+
return sanitizeEndpoint(transport.getRouteInfo(input)?.url);
|
|
2938
|
+
} catch {
|
|
2939
|
+
return;
|
|
2940
|
+
}
|
|
2941
|
+
}
|
|
2857
2942
|
/**
|
|
2858
2943
|
* A short, human-readable reason for a transport failing to connect — surfaced in the
|
|
2859
2944
|
* consumer's initialization-failed message so the caller sees *why* (e.g. a rejected handshake) rather
|
|
@@ -8844,7 +8929,7 @@ function wrongHandshakeFrame(channel, expected, receivedKind) {
|
|
|
8844
8929
|
return err_wire_connect.fromId("endpoint_answered_non_protocol", {
|
|
8845
8930
|
stage: LINK_HANDSHAKE_STAGE,
|
|
8846
8931
|
expected,
|
|
8847
|
-
url: channel.label,
|
|
8932
|
+
url: sanitizeEndpoint(channel.label),
|
|
8848
8933
|
receivedKind: `hs/${receivedKind}`
|
|
8849
8934
|
});
|
|
8850
8935
|
}
|
|
@@ -8894,6 +8979,32 @@ function startHeartbeat(channel, config, tap) {
|
|
|
8894
8979
|
}
|
|
8895
8980
|
};
|
|
8896
8981
|
}
|
|
8982
|
+
function bindMux(mux, remoteIds, pipe, disconnectListeners, tap) {
|
|
8983
|
+
let attached = false;
|
|
8984
|
+
let closed = false;
|
|
8985
|
+
const held = [];
|
|
8986
|
+
disconnectListeners.push(() => {
|
|
8987
|
+
closed = true;
|
|
8988
|
+
held.length = 0;
|
|
8989
|
+
if (attached) mux.detach();
|
|
8990
|
+
});
|
|
8991
|
+
return {
|
|
8992
|
+
mux,
|
|
8993
|
+
dispatch: (frame) => {
|
|
8994
|
+
if (attached) return mux.dispatchIncoming(frame);
|
|
8995
|
+
if (peekProtocolPrefix(frame) == null) return false;
|
|
8996
|
+
if (!closed) held.push(frame);
|
|
8997
|
+
return true;
|
|
8998
|
+
},
|
|
8999
|
+
attach: () => {
|
|
9000
|
+
if (attached || closed) return;
|
|
9001
|
+
attached = true;
|
|
9002
|
+
mux.setRemoteProtocolIds(remoteIds());
|
|
9003
|
+
mux.attach(tap != null ? (bytes) => pipe.send(bytes, mux.protocolIdFor(bytes) ?? "protocol") : (bytes) => pipe.send(bytes));
|
|
9004
|
+
for (const frame of held.splice(0)) mux.dispatchIncoming(frame);
|
|
9005
|
+
}
|
|
9006
|
+
};
|
|
9007
|
+
}
|
|
8897
9008
|
/**
|
|
8898
9009
|
* Wrap a carrier so a **deliberate local** `close()` notifies the session immediately and exactly
|
|
8899
9010
|
* once, rather than waiting for the platform's close event. On a real WebSocket that event lags a
|
|
@@ -8950,6 +9061,7 @@ function establishPlainDuplexSession(ctx) {
|
|
|
8950
9061
|
const mux = ctx.mux;
|
|
8951
9062
|
const heartbeat = ctx.heartbeat != null ? startHeartbeat(channel, ctx.heartbeat, tap) : void 0;
|
|
8952
9063
|
if (heartbeat != null) disconnectListeners.push(heartbeat.stop);
|
|
9064
|
+
const muxBinding = mux == null ? void 0 : bindMux(mux, () => protocolsFromCaps(mux.localCaps()), pipe, disconnectListeners, tap);
|
|
8953
9065
|
channel.attach({
|
|
8954
9066
|
onMessage: (frame) => {
|
|
8955
9067
|
heartbeat?.noteInbound();
|
|
@@ -8961,17 +9073,13 @@ function establishPlainDuplexSession(ctx) {
|
|
|
8961
9073
|
});
|
|
8962
9074
|
return;
|
|
8963
9075
|
}
|
|
8964
|
-
handleIncomingFrame(pipe, frame,
|
|
9076
|
+
handleIncomingFrame(pipe, frame, muxBinding, ctx.lane, port, tap);
|
|
8965
9077
|
},
|
|
8966
9078
|
onClose: () => onChannelClosed(disconnectListeners, ctx.lane),
|
|
8967
9079
|
onError: () => onChannelClosed(disconnectListeners, ctx.lane)
|
|
8968
9080
|
});
|
|
8969
|
-
if (
|
|
8970
|
-
|
|
8971
|
-
mux.attach(tap != null ? (bytes) => pipe.send(bytes, mux.protocolIdFor(bytes) ?? "protocol") : (bytes) => pipe.send(bytes));
|
|
8972
|
-
disconnectListeners.push(() => mux.detach());
|
|
8973
|
-
}
|
|
8974
|
-
return makeSession$1(channel, pipe, disconnectListeners, void 0);
|
|
9081
|
+
if (ctx.deferMuxAttach !== true) muxBinding?.attach();
|
|
9082
|
+
return makeSession$1(channel, pipe, disconnectListeners, void 0, muxBinding);
|
|
8975
9083
|
}
|
|
8976
9084
|
/**
|
|
8977
9085
|
* Secure path: a single message handler feeds the handshake until it completes, then routes lane
|
|
@@ -9005,7 +9113,7 @@ async function establishSecureDuplexSession(ctx) {
|
|
|
9005
9113
|
return;
|
|
9006
9114
|
}
|
|
9007
9115
|
if (active && session.pipe != null && session.port != null) {
|
|
9008
|
-
handleIncomingFrame(session.pipe, frame,
|
|
9116
|
+
handleIncomingFrame(session.pipe, frame, session.muxBinding, ctx.lane, session.port, tap);
|
|
9009
9117
|
return;
|
|
9010
9118
|
}
|
|
9011
9119
|
if (typeof frame === "string") {
|
|
@@ -9035,7 +9143,7 @@ async function establishSecureDuplexSession(ctx) {
|
|
|
9035
9143
|
const timeout = setTimeout(() => reject(nonProtocolFrame != null ? err_wire_connect.fromId("endpoint_answered_non_protocol", {
|
|
9036
9144
|
stage: LINK_HANDSHAKE_STAGE,
|
|
9037
9145
|
expected: "a handshake frame",
|
|
9038
|
-
url: channel.label,
|
|
9146
|
+
url: sanitizeEndpoint(channel.label),
|
|
9039
9147
|
bodyPreview: describeNonProtocolBody(nonProtocolFrame)
|
|
9040
9148
|
}) : /* @__PURE__ */ new Error(`[${LINK_HANDSHAKE_STAGE}] timed out waiting for peer reply`)), HANDSHAKE_TIMEOUT_MS$1);
|
|
9041
9149
|
handshakeWaiters.push((message) => {
|
|
@@ -9044,28 +9152,31 @@ async function establishSecureDuplexSession(ctx) {
|
|
|
9044
9152
|
});
|
|
9045
9153
|
});
|
|
9046
9154
|
};
|
|
9047
|
-
|
|
9048
|
-
|
|
9049
|
-
|
|
9050
|
-
|
|
9051
|
-
|
|
9052
|
-
|
|
9053
|
-
|
|
9054
|
-
|
|
9055
|
-
|
|
9056
|
-
mux
|
|
9057
|
-
|
|
9058
|
-
|
|
9059
|
-
|
|
9060
|
-
|
|
9061
|
-
|
|
9062
|
-
|
|
9063
|
-
|
|
9064
|
-
|
|
9065
|
-
|
|
9066
|
-
|
|
9067
|
-
|
|
9068
|
-
|
|
9155
|
+
try {
|
|
9156
|
+
const { crypto, remoteCaps } = await runClientHandshake({
|
|
9157
|
+
...ctx,
|
|
9158
|
+
channel
|
|
9159
|
+
}, nextHandshakeMessage);
|
|
9160
|
+
const pipe = makePipe(channel, crypto, tap);
|
|
9161
|
+
const port = makeLanePort(channel, pipe);
|
|
9162
|
+
session.pipe = pipe;
|
|
9163
|
+
session.port = port;
|
|
9164
|
+
const muxBinding = mux == null ? void 0 : bindMux(mux, () => protocolsFromCaps(remoteCaps), pipe, disconnectListeners, tap);
|
|
9165
|
+
session.muxBinding = muxBinding;
|
|
9166
|
+
if (ctx.deferMuxAttach !== true) muxBinding?.attach();
|
|
9167
|
+
ctx.lane.onAttach?.(port, { remoteCaps: remoteCaps ?? [] });
|
|
9168
|
+
active = true;
|
|
9169
|
+
for (const frame of pendingFrames) await handleIncomingFrame(pipe, frame, muxBinding, ctx.lane, port, tap);
|
|
9170
|
+
pendingFrames.length = 0;
|
|
9171
|
+
if (ctx.heartbeat != null) {
|
|
9172
|
+
heartbeat = startHeartbeat(channel, ctx.heartbeat, tap);
|
|
9173
|
+
disconnectListeners.push(heartbeat.stop);
|
|
9174
|
+
}
|
|
9175
|
+
return makeSession$1(channel, pipe, disconnectListeners, remoteCaps, muxBinding);
|
|
9176
|
+
} catch (error) {
|
|
9177
|
+
closeQuietly(channel);
|
|
9178
|
+
throw error;
|
|
9179
|
+
}
|
|
9069
9180
|
}
|
|
9070
9181
|
function makePipe(channel, crypto, tap) {
|
|
9071
9182
|
return createFrameCryptoPipe({
|
|
@@ -9088,19 +9199,21 @@ function makeLanePort(channel, pipe) {
|
|
|
9088
9199
|
isOpen: () => channel.isOpen()
|
|
9089
9200
|
};
|
|
9090
9201
|
}
|
|
9091
|
-
function
|
|
9202
|
+
function closeQuietly(channel) {
|
|
9203
|
+
try {
|
|
9204
|
+
channel.close();
|
|
9205
|
+
} catch {}
|
|
9206
|
+
}
|
|
9207
|
+
function makeSession$1(channel, pipe, disconnectListeners, remoteCaps, muxBinding) {
|
|
9092
9208
|
return {
|
|
9093
9209
|
send: (frame) => pipe.send(frame),
|
|
9094
9210
|
isOpen: () => channel.isOpen(),
|
|
9095
|
-
close: () =>
|
|
9096
|
-
try {
|
|
9097
|
-
channel.close();
|
|
9098
|
-
} catch {}
|
|
9099
|
-
},
|
|
9211
|
+
close: () => closeQuietly(channel),
|
|
9100
9212
|
addOnDisconnectListener: (listener) => {
|
|
9101
9213
|
disconnectListeners.push(listener);
|
|
9102
9214
|
},
|
|
9103
|
-
remoteCaps
|
|
9215
|
+
remoteCaps,
|
|
9216
|
+
attachMux: muxBinding == null ? void 0 : () => muxBinding.attach()
|
|
9104
9217
|
};
|
|
9105
9218
|
}
|
|
9106
9219
|
async function runClientHandshake(ctx, nextHandshakeMessage) {
|
|
@@ -9142,15 +9255,15 @@ async function runClientHandshake(ctx, nextHandshakeMessage) {
|
|
|
9142
9255
|
};
|
|
9143
9256
|
}
|
|
9144
9257
|
/** Decrypt → mux dispatch → the lane. Awaited by the pre-ready flush so frame order holds. */
|
|
9145
|
-
async function handleIncomingFrame(pipe, frame,
|
|
9258
|
+
async function handleIncomingFrame(pipe, frame, muxBinding, lane, port, tap) {
|
|
9146
9259
|
const wireBytes = tap != null ? wireFrameByteSize(frame) : 0;
|
|
9147
9260
|
const decoded = await pipe.decryptIncoming(frame);
|
|
9148
9261
|
if (decoded === void 0) return;
|
|
9149
|
-
if (
|
|
9262
|
+
if (muxBinding?.dispatch(decoded)) {
|
|
9150
9263
|
tap?.({
|
|
9151
9264
|
dir: "in",
|
|
9152
9265
|
bytes: wireBytes,
|
|
9153
|
-
lane: mux.protocolIdFor(decoded) ?? "protocol"
|
|
9266
|
+
lane: muxBinding.mux.protocolIdFor(decoded) ?? "protocol"
|
|
9154
9267
|
});
|
|
9155
9268
|
return;
|
|
9156
9269
|
}
|
|
@@ -9579,7 +9692,7 @@ async function exchangeHandshakeFrame(carrier, request, expected) {
|
|
|
9579
9692
|
if (reply == null) throw err_wire_connect.fromId("endpoint_answered_non_protocol", {
|
|
9580
9693
|
stage: HANDSHAKE_STAGE,
|
|
9581
9694
|
expected,
|
|
9582
|
-
url: carrier.label,
|
|
9695
|
+
url: sanitizeEndpoint(carrier.label),
|
|
9583
9696
|
bodyPreview: describeNonProtocolBody(raw)
|
|
9584
9697
|
});
|
|
9585
9698
|
if (reply.k === "err") throw err_wire_connect.fromId("handshake_rejected", {
|
|
@@ -9593,13 +9706,14 @@ function nonProtocolReply(carrier, expected, receivedKind) {
|
|
|
9593
9706
|
return err_wire_connect.fromId("endpoint_answered_non_protocol", {
|
|
9594
9707
|
stage: HANDSHAKE_STAGE,
|
|
9595
9708
|
expected,
|
|
9596
|
-
url: carrier.label,
|
|
9709
|
+
url: sanitizeEndpoint(carrier.label),
|
|
9597
9710
|
receivedKind
|
|
9598
9711
|
});
|
|
9599
9712
|
}
|
|
9600
9713
|
/** Make a peer-bug message self-locating without inventing a typed id for it. */
|
|
9601
9714
|
function at(carrier) {
|
|
9602
|
-
|
|
9715
|
+
const endpoint = sanitizeEndpoint(carrier.label);
|
|
9716
|
+
return endpoint != null ? ` (endpoint: ${endpoint})` : "";
|
|
9603
9717
|
}
|
|
9604
9718
|
function asString(frame) {
|
|
9605
9719
|
if (typeof frame === "string") return frame;
|
|
@@ -9652,6 +9766,7 @@ var AcceptorSecureSession = class {
|
|
|
9652
9766
|
t: "reject",
|
|
9653
9767
|
reason: "server handshake failed; check server logs"
|
|
9654
9768
|
}));
|
|
9769
|
+
this.config.close?.();
|
|
9655
9770
|
} catch {}
|
|
9656
9771
|
});
|
|
9657
9772
|
}
|
|
@@ -9686,12 +9801,15 @@ var AcceptorSecureSession = class {
|
|
|
9686
9801
|
});
|
|
9687
9802
|
if (message.t === "hello") {
|
|
9688
9803
|
this._helloChannels = message.channels;
|
|
9689
|
-
|
|
9804
|
+
const reply = await this._handshake.onHello(message);
|
|
9805
|
+
this.config.send(encodeHandshakeMessage(reply));
|
|
9806
|
+
if (reply.t === "reject") this._refuse();
|
|
9690
9807
|
} else if (message.t === "prove") {
|
|
9691
9808
|
const reply = await this._handshake.onProve(message);
|
|
9692
9809
|
this.config.send(encodeHandshakeMessage(reply));
|
|
9693
9810
|
const result = this._handshake.getResult();
|
|
9694
9811
|
if (reply.t === "accept" && result != null) this._complete(result);
|
|
9812
|
+
else if (reply.t === "reject") this._refuse();
|
|
9695
9813
|
}
|
|
9696
9814
|
return;
|
|
9697
9815
|
}
|
|
@@ -9699,6 +9817,11 @@ var AcceptorSecureSession = class {
|
|
|
9699
9817
|
if (bytes === void 0) return;
|
|
9700
9818
|
this.config.routeAction(bytes, wireBytes);
|
|
9701
9819
|
}
|
|
9820
|
+
/** A refused handshake ends this connection: later frames are ignored and the socket closes. */
|
|
9821
|
+
_refuse() {
|
|
9822
|
+
this._handshakeFailed = true;
|
|
9823
|
+
this.config.close?.();
|
|
9824
|
+
}
|
|
9702
9825
|
_complete(result) {
|
|
9703
9826
|
this._authed = true;
|
|
9704
9827
|
this._handshake = void 0;
|
|
@@ -9779,6 +9902,7 @@ const KEEPALIVE_PONG = "pong";
|
|
|
9779
9902
|
*/
|
|
9780
9903
|
var WireAcceptor = class {
|
|
9781
9904
|
_send;
|
|
9905
|
+
_close;
|
|
9782
9906
|
_tap;
|
|
9783
9907
|
_security;
|
|
9784
9908
|
_lane;
|
|
@@ -9802,6 +9926,7 @@ var WireAcceptor = class {
|
|
|
9802
9926
|
_gateWarned = /* @__PURE__ */ new Set();
|
|
9803
9927
|
constructor(options) {
|
|
9804
9928
|
this._send = options.send;
|
|
9929
|
+
this._close = options.close;
|
|
9805
9930
|
this._tap = options.tap;
|
|
9806
9931
|
this._security = options.security;
|
|
9807
9932
|
this._lane = options.lane;
|
|
@@ -9966,6 +10091,7 @@ var WireAcceptor = class {
|
|
|
9966
10091
|
extraCaps: this._protocolCaps(),
|
|
9967
10092
|
noneAllowed: this._noneAllowed,
|
|
9968
10093
|
send: (frame, tapLane) => this._writeTapped(connection, frame, tapLane ?? "handshake"),
|
|
10094
|
+
close: this._close == null ? void 0 : () => this._close?.(connection),
|
|
9969
10095
|
tap: this._tap,
|
|
9970
10096
|
onAuthenticated: (auth) => this._onAuthenticated(connection, auth),
|
|
9971
10097
|
routePlain: (frame, wireBytes) => this._receivePlain(connection, frame, wireBytes),
|
|
@@ -9978,7 +10104,7 @@ var WireAcceptor = class {
|
|
|
9978
10104
|
/** Bind + persist a connection's authenticated identity once its handshake completes. */
|
|
9979
10105
|
_onAuthenticated(connection, auth) {
|
|
9980
10106
|
if (this._disposed) return;
|
|
9981
|
-
this._bind(connection, auth.client);
|
|
10107
|
+
this._bind(connection, auth.client, auth.securityLevel);
|
|
9982
10108
|
this._levelByConn.set(connection, auth.securityLevel);
|
|
9983
10109
|
this._lane.onAuthenticated?.(connection, auth);
|
|
9984
10110
|
const advertisedIds = protocolsFromCaps(auth.remoteCaps);
|
|
@@ -10002,12 +10128,14 @@ var WireAcceptor = class {
|
|
|
10002
10128
|
/**
|
|
10003
10129
|
* Plain-path identity binding: bind the connection to a self-asserted client coordinate (the
|
|
10004
10130
|
* lane decoded it off an inbound frame) and persist a fresh binding when the identity is new.
|
|
10005
|
-
* Secure mode never calls this — the handshake binds the authenticated coordinate instead.
|
|
10131
|
+
* Secure mode never calls this — the handshake binds the authenticated coordinate instead. While
|
|
10132
|
+
* another live connection holds that coordinate through a handshake, pushes and
|
|
10133
|
+
* `connectionForClient` keep resolving to it; the plain claim takes over only once it drops.
|
|
10006
10134
|
*/
|
|
10007
10135
|
bindPlainConnection(connection, client) {
|
|
10008
10136
|
if (this._disposed) return;
|
|
10009
10137
|
const isNewBinding = this._clientByConn.get(connection)?.stringId !== client.stringId;
|
|
10010
|
-
this._bind(connection, client);
|
|
10138
|
+
this._bind(connection, client, "none");
|
|
10011
10139
|
if (isNewBinding) this._persist(connection, {
|
|
10012
10140
|
v: 1,
|
|
10013
10141
|
client: client.toJsonObject(),
|
|
@@ -10027,11 +10155,12 @@ var WireAcceptor = class {
|
|
|
10027
10155
|
console.warn(`[wire-acceptor] ignored a persisted connection binding of unknown schema version ${JSON.stringify(binding.v)} (expected 1) — treating the connection as fresh (err_nice_wire_connect.binding_version_mismatch).`);
|
|
10028
10156
|
return;
|
|
10029
10157
|
}
|
|
10030
|
-
this._bind(connection, new RuntimeCoordinate(binding.client));
|
|
10031
|
-
this._bindingByConn.set(connection, binding);
|
|
10032
|
-
this._lane.restoreBindingState?.(connection, binding.lane);
|
|
10033
10158
|
const secure = binding.secure;
|
|
10034
10159
|
const security = this._security;
|
|
10160
|
+
const level = secure != null && security != null ? secure.securityLevel : "none";
|
|
10161
|
+
this._bind(connection, new RuntimeCoordinate(binding.client), level);
|
|
10162
|
+
this._bindingByConn.set(connection, binding);
|
|
10163
|
+
this._lane.restoreBindingState?.(connection, binding.lane);
|
|
10035
10164
|
if (secure != null && security != null) {
|
|
10036
10165
|
this._levelByConn.set(connection, secure.securityLevel);
|
|
10037
10166
|
this._sessionFor(connection, security).rehydrate(secure);
|
|
@@ -10043,11 +10172,13 @@ var WireAcceptor = class {
|
|
|
10043
10172
|
this._bindingByConn.set(connection, binding);
|
|
10044
10173
|
this._onConnectionBound?.(connection, binding);
|
|
10045
10174
|
}
|
|
10046
|
-
_bind(connection, client) {
|
|
10175
|
+
_bind(connection, client, level) {
|
|
10047
10176
|
const previous = this._clientByConn.get(connection);
|
|
10048
10177
|
if (previous != null && previous.stringId !== client.stringId && this._connByClient.get(previous.stringId) === connection) this._connByClient.delete(previous.stringId);
|
|
10049
|
-
this._connByClient.set(client.stringId, connection);
|
|
10050
10178
|
this._clientByConn.set(connection, client);
|
|
10179
|
+
const holder = this._connByClient.get(client.stringId);
|
|
10180
|
+
if (level === "none" && holder != null && holder !== connection && this.levelFor(holder) !== "none") return;
|
|
10181
|
+
this._connByClient.set(client.stringId, connection);
|
|
10051
10182
|
}
|
|
10052
10183
|
/** Forget a connection (call on socket close) so stale entries don't misroute later traffic. */
|
|
10053
10184
|
drop(connection) {
|
|
@@ -13770,10 +13901,14 @@ var ChannelConnector = class extends PeerLink {
|
|
|
13770
13901
|
defaultLocalCoordinate: () => ActionRuntime.getDefault().coordinate
|
|
13771
13902
|
});
|
|
13772
13903
|
for (const transport of transports) {
|
|
13904
|
+
const securityLevel = transport._inboundSecurityLevel();
|
|
13773
13905
|
const connection = transport._createConnection({ resolvers: {
|
|
13774
13906
|
onIncomingActionDataJson: (json, reliability) => {
|
|
13775
13907
|
if (reliability?.ack != null) this._applyAck(reliableStreamId(this.peer, json.domain, json.id, reliability.streamKey), reliability.ack);
|
|
13776
|
-
this._emitIncoming(json
|
|
13908
|
+
this._emitIncoming(json, {
|
|
13909
|
+
receiver: this,
|
|
13910
|
+
securityLevel
|
|
13911
|
+
});
|
|
13777
13912
|
},
|
|
13778
13913
|
onControlMessage: (message) => {
|
|
13779
13914
|
const streamId = reliableStreamId(this.peer, message.domain, message.id, message.k);
|
|
@@ -14396,35 +14531,60 @@ var ActionRuntime = class {
|
|
|
14396
14531
|
_addHandlers(handlers, options) {
|
|
14397
14532
|
this._assertActive();
|
|
14398
14533
|
this._assertNoDuplicateLocalExecutors(handlers);
|
|
14399
|
-
|
|
14400
|
-
|
|
14401
|
-
|
|
14402
|
-
|
|
14403
|
-
ownership =
|
|
14404
|
-
|
|
14405
|
-
|
|
14406
|
-
|
|
14407
|
-
|
|
14408
|
-
|
|
14409
|
-
|
|
14410
|
-
|
|
14411
|
-
this._registeredPeerHandlers.push(handler);
|
|
14412
|
-
}
|
|
14413
|
-
for (const key of handlerRouter.getRegisteredKeys()) this.actionRouter.addForKey(key, handler);
|
|
14414
|
-
} catch (error) {
|
|
14415
|
-
ownership.unbind?.();
|
|
14416
|
-
this.actionRouter.removeRouteData(handler);
|
|
14417
|
-
const peerIndex = this._registeredPeerHandlers.indexOf(handler);
|
|
14418
|
-
if (peerIndex >= 0) this._registeredPeerHandlers.splice(peerIndex, 1);
|
|
14419
|
-
throw error;
|
|
14534
|
+
const installed = [];
|
|
14535
|
+
const promoted = [];
|
|
14536
|
+
try {
|
|
14537
|
+
for (const handler of handlers) {
|
|
14538
|
+
let ownership = this._handlerOwnership.get(handler);
|
|
14539
|
+
if (ownership == null) {
|
|
14540
|
+
ownership = this._installHandler(handler);
|
|
14541
|
+
installed.push(handler);
|
|
14542
|
+
}
|
|
14543
|
+
if (options.persistent && !ownership.persistent) {
|
|
14544
|
+
ownership.persistent = true;
|
|
14545
|
+
promoted.push(ownership);
|
|
14420
14546
|
}
|
|
14421
|
-
|
|
14547
|
+
if (options.lease != null) ownership.leases.add(options.lease);
|
|
14548
|
+
}
|
|
14549
|
+
} catch (error) {
|
|
14550
|
+
for (const ownership of promoted) ownership.persistent = false;
|
|
14551
|
+
for (const handler of installed) {
|
|
14552
|
+
const ownership = this._handlerOwnership.get(handler);
|
|
14553
|
+
if (ownership != null) this._uninstallHandler(handler, ownership);
|
|
14422
14554
|
}
|
|
14423
|
-
|
|
14424
|
-
if (options.lease != null) ownership.leases.add(options.lease);
|
|
14555
|
+
throw error;
|
|
14425
14556
|
}
|
|
14426
14557
|
if (options.register) this._registerWithRoutedRoots();
|
|
14427
14558
|
}
|
|
14559
|
+
_installHandler(handler) {
|
|
14560
|
+
const handlerRouter = handler.getActionRouter();
|
|
14561
|
+
const ownership = {
|
|
14562
|
+
persistent: false,
|
|
14563
|
+
leases: /* @__PURE__ */ new Set()
|
|
14564
|
+
};
|
|
14565
|
+
try {
|
|
14566
|
+
this.actionRouter.addDomainsFromOther(handlerRouter);
|
|
14567
|
+
if (handler.handlerType === "peer") {
|
|
14568
|
+
ownership.unbind = handler._setIncomingActionDataListener(this, (json, metadata) => this.resolveIncomingActionPayload(json, metadata));
|
|
14569
|
+
this._registeredPeerHandlers.push(handler);
|
|
14570
|
+
}
|
|
14571
|
+
for (const key of handlerRouter.getRegisteredKeys()) this.actionRouter.addForKey(key, handler);
|
|
14572
|
+
} catch (error) {
|
|
14573
|
+
this._uninstallHandler(handler, ownership);
|
|
14574
|
+
throw error;
|
|
14575
|
+
}
|
|
14576
|
+
this._handlerOwnership.set(handler, ownership);
|
|
14577
|
+
return ownership;
|
|
14578
|
+
}
|
|
14579
|
+
_uninstallHandler(handler, ownership) {
|
|
14580
|
+
ownership.unbind?.();
|
|
14581
|
+
this.actionRouter.removeRouteData(handler);
|
|
14582
|
+
if (handler.handlerType === "peer") {
|
|
14583
|
+
const peerIndex = this._registeredPeerHandlers.indexOf(handler);
|
|
14584
|
+
if (peerIndex >= 0) this._registeredPeerHandlers.splice(peerIndex, 1);
|
|
14585
|
+
}
|
|
14586
|
+
this._handlerOwnership.delete(handler);
|
|
14587
|
+
}
|
|
14428
14588
|
_assertNoDuplicateLocalExecutors(handlers) {
|
|
14429
14589
|
for (const handler of handlers) for (const domain of handler.getActionRouter().getDomains()) this.actionRouter.domainManager.assertCanAddDomain(domain);
|
|
14430
14590
|
const staged = /* @__PURE__ */ new Map();
|
|
@@ -14441,11 +14601,7 @@ var ActionRuntime = class {
|
|
|
14441
14601
|
for (const [handler, ownership] of this._handlerOwnership) {
|
|
14442
14602
|
ownership.leases.delete(lease);
|
|
14443
14603
|
if (ownership.persistent || ownership.leases.size > 0) continue;
|
|
14444
|
-
|
|
14445
|
-
this.actionRouter.removeRouteData(handler);
|
|
14446
|
-
const peerIndex = this._registeredPeerHandlers.indexOf(handler);
|
|
14447
|
-
if (peerIndex >= 0) this._registeredPeerHandlers.splice(peerIndex, 1);
|
|
14448
|
-
this._handlerOwnership.delete(handler);
|
|
14604
|
+
this._uninstallHandler(handler, ownership);
|
|
14449
14605
|
}
|
|
14450
14606
|
}
|
|
14451
14607
|
/**
|
|
@@ -14568,29 +14724,21 @@ var ActionRuntime = class {
|
|
|
14568
14724
|
const originClient = runningAction.context.originClient;
|
|
14569
14725
|
if (originClient.envId === "_unset_" || originClient.isSameFor(this._coordinate).id) return;
|
|
14570
14726
|
const arrival = runningAction.context._getReceiverMetadata();
|
|
14727
|
+
if (arrival != null && !(arrival.receiver instanceof PeerLink)) return;
|
|
14728
|
+
const arrivalLink = arrival?.receiver instanceof PeerLink ? arrival.receiver : void 0;
|
|
14571
14729
|
runningAction.addUpdateListeners([(update) => {
|
|
14572
14730
|
if (update.type === "finished" && update.finishType === "success") {
|
|
14573
14731
|
if (this._disposed) return;
|
|
14574
|
-
const returnHandler =
|
|
14575
|
-
if (returnHandler == null
|
|
14576
|
-
returnHandler.sendReturnPayload(update.response, {
|
|
14732
|
+
const returnHandler = arrivalLink != null ? this._registeredPeerHandlers.includes(arrivalLink) && arrivalLink.canPush ? arrivalLink : void 0 : this.getReturnHandlerForOrigin(originClient);
|
|
14733
|
+
if (returnHandler == null) return;
|
|
14734
|
+
returnHandler.sendReturnPayload(update.response, {
|
|
14735
|
+
targetLocalRuntime: this,
|
|
14736
|
+
arrival
|
|
14737
|
+
}).catch(() => {});
|
|
14577
14738
|
}
|
|
14578
14739
|
}]);
|
|
14579
14740
|
}
|
|
14580
14741
|
};
|
|
14581
|
-
/**
|
|
14582
|
-
* May a result be routed back to the action's *claimed* origin over `returnHandler`?
|
|
14583
|
-
*
|
|
14584
|
-
* - No arrival facts (a locally dispatched action, or an advanced caller supplying its own wire):
|
|
14585
|
-
* unchanged behaviour.
|
|
14586
|
-
* - The frame arrived on this very handler: always — that is answering on the link it came from.
|
|
14587
|
-
* - Otherwise the origin coordinate is only trustworthy when the arrival was authenticated; an
|
|
14588
|
-
* unauthenticated claim must never select a different connection.
|
|
14589
|
-
*/
|
|
14590
|
-
function canReturnToOrigin(arrival, returnHandler) {
|
|
14591
|
-
if (arrival == null || arrival.receiver === returnHandler) return true;
|
|
14592
|
-
return arrival.securityLevel != null && arrival.securityLevel !== "none";
|
|
14593
|
-
}
|
|
14594
14742
|
const runtimeState = {
|
|
14595
14743
|
defaultLocalRuntime: void 0,
|
|
14596
14744
|
assumedRuntimeInfo: void 0
|
|
@@ -14682,12 +14830,12 @@ var ActionLocalHandler = class extends ActionHandler {
|
|
|
14682
14830
|
pushHandlerCuid(runningAction.cuid);
|
|
14683
14831
|
try {
|
|
14684
14832
|
const ran = await niceTryAsync(async () => {
|
|
14685
|
-
const
|
|
14833
|
+
const metadata = state.request.context._getReceiverMetadata();
|
|
14686
14834
|
const context = {
|
|
14687
14835
|
runtime,
|
|
14688
14836
|
origin: state.request.context.originClient,
|
|
14689
|
-
authenticatedOrigin:
|
|
14690
|
-
securityLevel,
|
|
14837
|
+
authenticatedOrigin: metadata?.originAuthenticated === true ? state.request.context.originClient : void 0,
|
|
14838
|
+
securityLevel: metadata?.securityLevel,
|
|
14691
14839
|
reliability: state.request.context.reliability,
|
|
14692
14840
|
run: (request, options) => runtime.run(request, options)
|
|
14693
14841
|
};
|
|
@@ -15246,6 +15394,7 @@ var ChannelAcceptor = class extends PeerLink {
|
|
|
15246
15394
|
const security = options.security;
|
|
15247
15395
|
this.wireAcceptor = new WireAcceptor({
|
|
15248
15396
|
send: options.send,
|
|
15397
|
+
close: options.close,
|
|
15249
15398
|
tap: options.wireTap,
|
|
15250
15399
|
security: security == null ? void 0 : {
|
|
15251
15400
|
securityLevel: security.securityLevel,
|
|
@@ -15536,11 +15685,13 @@ var ChannelAcceptor = class extends PeerLink {
|
|
|
15536
15685
|
_emitIncomingFromReceiver(wire, reliability, arrivalOverride) {
|
|
15537
15686
|
const arrival = arrivalOverride ?? this._receiverMetadataByWire.get(wire);
|
|
15538
15687
|
this._receiverMetadataByWire.delete(wire);
|
|
15688
|
+
const securityLevel = arrival?.securityLevel;
|
|
15539
15689
|
this._emitIncoming(wire, {
|
|
15540
15690
|
receiver: this,
|
|
15541
15691
|
connection: arrival?.connection,
|
|
15542
15692
|
bindingGeneration: arrival?.bindingGeneration,
|
|
15543
|
-
securityLevel
|
|
15693
|
+
securityLevel,
|
|
15694
|
+
originAuthenticated: securityLevel != null && securityLevel !== "none",
|
|
15544
15695
|
reliability
|
|
15545
15696
|
});
|
|
15546
15697
|
}
|
|
@@ -15809,10 +15960,10 @@ var ChannelAcceptor = class extends PeerLink {
|
|
|
15809
15960
|
}
|
|
15810
15961
|
}
|
|
15811
15962
|
async sendReturnPayload(payload, config) {
|
|
15812
|
-
const arrival = payload.context._getReceiverMetadata();
|
|
15813
|
-
const connection = arrival
|
|
15963
|
+
const arrival = config.arrival ?? payload.context._getReceiverMetadata();
|
|
15964
|
+
const connection = arrival == null ? this.wireAcceptor.connectionForClient(payload.context.originClient.stringId) : arrival.receiver === this ? this._liveArrivalConnection(arrival) : void 0;
|
|
15814
15965
|
if (connection == null) return false;
|
|
15815
|
-
const bytes = this._sendPayload(connection, payload, config.targetLocalRuntime.coordinate);
|
|
15966
|
+
const bytes = this._sendPayload(connection, payload, config.targetLocalRuntime.coordinate, arrival?.reliability);
|
|
15816
15967
|
this._reportServed(payload, bytes);
|
|
15817
15968
|
return true;
|
|
15818
15969
|
}
|
|
@@ -15869,11 +16020,11 @@ var ChannelAcceptor = class extends PeerLink {
|
|
|
15869
16020
|
}).withOriginError(cause);
|
|
15870
16021
|
}
|
|
15871
16022
|
/** Encode + send one payload; returns the encoded frame's size so a logger can report it. */
|
|
15872
|
-
_sendPayload(connection, payload, localClient,
|
|
16023
|
+
_sendPayload(connection, payload, localClient, answered) {
|
|
15873
16024
|
const encoding = this._connEncoding.get(connection) ?? "binary";
|
|
15874
|
-
let rel
|
|
15875
|
-
if (
|
|
15876
|
-
const streamKey = payload.context.reliability?.streamKey;
|
|
16025
|
+
let rel;
|
|
16026
|
+
if (payload.type === "result") {
|
|
16027
|
+
const streamKey = (answered ?? payload.context.reliability)?.streamKey;
|
|
15877
16028
|
const streamId = reliableStreamId(payload.context.originClient, payload.domain, payload.id, streamKey);
|
|
15878
16029
|
const receiver = this._persistedReceiver?.hasStream(streamId) ? this._persistedReceiver : this._inbox.hasStream(streamId) ? this._inbox : void 0;
|
|
15879
16030
|
if (receiver != null) {
|
|
@@ -15948,6 +16099,7 @@ function createSecureChannelAcceptor(options) {
|
|
|
15948
16099
|
};
|
|
15949
16100
|
const baseOptions = {
|
|
15950
16101
|
send: options.send,
|
|
16102
|
+
close: options.close,
|
|
15951
16103
|
runtime: options.runtime,
|
|
15952
16104
|
defaultTimeout: options.defaultTimeout,
|
|
15953
16105
|
logger: options.logger,
|
|
@@ -15975,11 +16127,14 @@ function createSecureChannelAcceptor(options) {
|
|
|
15975
16127
|
}
|
|
15976
16128
|
//#endregion
|
|
15977
16129
|
//#region ../nice-action/src/ActionRuntime/Transport/Carrier/Carrier.types.ts
|
|
15978
|
-
/**
|
|
16130
|
+
/**
|
|
16131
|
+
* Convert action routing data into wire's generic carrier dial shape. The routing fields also stay at
|
|
16132
|
+
* the top level, so a carrier source written for the older `open(input: TTransportRouteParams)` shape
|
|
16133
|
+
* still reads `input.action`.
|
|
16134
|
+
*/
|
|
15979
16135
|
function toActionDialParams(input) {
|
|
15980
16136
|
return {
|
|
15981
|
-
|
|
15982
|
-
externalClient: input.externalClient,
|
|
16137
|
+
...input,
|
|
15983
16138
|
dialContext: input
|
|
15984
16139
|
};
|
|
15985
16140
|
}
|
|
@@ -16291,7 +16446,12 @@ function isSessionEnvelope(envelope) {
|
|
|
16291
16446
|
* definition can be shared across multiple handlers — each handler builds its own live
|
|
16292
16447
|
* {@link TransportConnection} via {@link TransportConnection._createConnection}.
|
|
16293
16448
|
*/
|
|
16294
|
-
var Transport = class {
|
|
16449
|
+
var Transport = class {
|
|
16450
|
+
/** @internal The security level frames received over this transport were protected at. */
|
|
16451
|
+
_inboundSecurityLevel() {
|
|
16452
|
+
return "none";
|
|
16453
|
+
}
|
|
16454
|
+
};
|
|
16295
16455
|
//#endregion
|
|
16296
16456
|
//#region ../nice-action/src/ActionRuntime/Transport/SecureSession/establishExchangeSession.ts
|
|
16297
16457
|
/** Plain path (no handshake/token): every action rides a bare `act` envelope, plaintext both ways. */
|
|
@@ -16412,11 +16572,15 @@ var ExchangeConnection = class extends TransportConnection {
|
|
|
16412
16572
|
* can't deliver an unsolicited frame (the runtime never picks it for the return path).
|
|
16413
16573
|
*/
|
|
16414
16574
|
var ExchangeTransport = class ExchangeTransport extends Transport {
|
|
16415
|
-
options;
|
|
16416
16575
|
type = "exchange";
|
|
16576
|
+
options;
|
|
16417
16577
|
constructor(options) {
|
|
16418
16578
|
super();
|
|
16419
|
-
|
|
16579
|
+
if (options.getCacheKey != null && options.getTransportCacheKey != null) throw err_nice_action.fromId("conflicting_connect_options", { detail: "ExchangeTransport: pass only `getCacheKey`; `getTransportCacheKey` is deprecated" });
|
|
16580
|
+
this.options = {
|
|
16581
|
+
...options,
|
|
16582
|
+
getCacheKey: options.getCacheKey ?? options.getTransportCacheKey
|
|
16583
|
+
};
|
|
16420
16584
|
}
|
|
16421
16585
|
static create(options) {
|
|
16422
16586
|
return new ExchangeTransport(options);
|
|
@@ -16650,11 +16814,17 @@ var LinkConnection = class extends TransportConnection {
|
|
|
16650
16814
|
* or an in-memory pipe. Reported with an overridable carrier label in the devtools (defaults to "link").
|
|
16651
16815
|
*/
|
|
16652
16816
|
var LinkTransport = class LinkTransport extends Transport {
|
|
16653
|
-
options;
|
|
16654
16817
|
type = "duplex";
|
|
16818
|
+
options;
|
|
16655
16819
|
constructor(options) {
|
|
16656
16820
|
super();
|
|
16657
|
-
|
|
16821
|
+
if (options.getCacheKey != null && options.getTransportCacheKey != null) throw err_nice_action.fromId("conflicting_connect_options", { detail: "LinkTransport: pass only `getCacheKey`; `getTransportCacheKey` is deprecated" });
|
|
16822
|
+
if (options.heartbeat != null && options.linkKeepalive != null) throw err_nice_action.fromId("conflicting_connect_options", { detail: "LinkTransport: pass only `heartbeat`; `linkKeepalive` is deprecated" });
|
|
16823
|
+
this.options = {
|
|
16824
|
+
...options,
|
|
16825
|
+
getCacheKey: options.getCacheKey ?? options.getTransportCacheKey,
|
|
16826
|
+
heartbeat: options.heartbeat ?? options.linkKeepalive
|
|
16827
|
+
};
|
|
16658
16828
|
}
|
|
16659
16829
|
static create(options) {
|
|
16660
16830
|
return new LinkTransport(options);
|
|
@@ -16677,6 +16847,9 @@ var LinkTransport = class LinkTransport extends Transport {
|
|
|
16677
16847
|
})
|
|
16678
16848
|
}) }, ctx.resolvers);
|
|
16679
16849
|
}
|
|
16850
|
+
_inboundSecurityLevel() {
|
|
16851
|
+
return this.options.security?.securityLevel ?? "none";
|
|
16852
|
+
}
|
|
16680
16853
|
getRouteInfo(input) {
|
|
16681
16854
|
if (this.options.getRouteInfo != null) return this.options.getRouteInfo(input);
|
|
16682
16855
|
return {
|
|
@@ -16829,6 +17002,8 @@ function warnOnSharedConnectionIdentity(runtime, peer, identity) {
|
|
|
16829
17002
|
*/
|
|
16830
17003
|
function connectChannel(runtime, channel, options) {
|
|
16831
17004
|
if (options.carriers == null === (options.transports == null)) throw err_nice_action.fromId("conflicting_connect_options", { detail: "connectChannel requires exactly one of `carriers` or deprecated `transports`" });
|
|
17005
|
+
if (options.reconnect != null && options.keepLinkAlive != null) throw err_nice_action.fromId("conflicting_connect_options", { detail: "connectChannel: pass only `reconnect`; `keepLinkAlive` is deprecated" });
|
|
17006
|
+
if (options.heartbeat != null && options.linkKeepalive != null) throw err_nice_action.fromId("conflicting_connect_options", { detail: "connectChannel: pass only `heartbeat`; `linkKeepalive` is deprecated" });
|
|
16832
17007
|
const transports = options.carriers?.map((carrier) => ({
|
|
16833
17008
|
carrier,
|
|
16834
17009
|
secure: carrier.secure,
|
|
@@ -16995,7 +17170,8 @@ var ExchangeAcceptor = class {
|
|
|
16995
17170
|
const startedAt = Date.now();
|
|
16996
17171
|
const result = await (await this._runtime._handleActionPayloadWireFromReceiver(wire, {
|
|
16997
17172
|
receiver: this,
|
|
16998
|
-
securityLevel: request.securityLevel
|
|
17173
|
+
securityLevel: request.securityLevel,
|
|
17174
|
+
originAuthenticated: client != null && request.securityLevel !== "none"
|
|
16999
17175
|
})).waitForResultPayload();
|
|
17000
17176
|
const resultWire = result.toJsonObject();
|
|
17001
17177
|
if (report != null) {
|
|
@@ -17381,6 +17557,7 @@ function serveChannel(runtimeOrChannel, channelOrOptions, legacyOptions) {
|
|
|
17381
17557
|
verifyKeyResolver: secure.verifyKeyResolver,
|
|
17382
17558
|
securityLevel,
|
|
17383
17559
|
send: carrier.send,
|
|
17560
|
+
close: carrier.close,
|
|
17384
17561
|
defaultTimeout: options.defaultTimeout,
|
|
17385
17562
|
resolveChannel,
|
|
17386
17563
|
logger: options.logger,
|
|
@@ -17391,6 +17568,7 @@ function serveChannel(runtimeOrChannel, channelOrOptions, legacyOptions) {
|
|
|
17391
17568
|
}) : createChannelAcceptor({
|
|
17392
17569
|
createFormatMessage: channel.createCodec,
|
|
17393
17570
|
send: carrier.send,
|
|
17571
|
+
close: carrier.close,
|
|
17394
17572
|
runtime,
|
|
17395
17573
|
defaultTimeout: options.defaultTimeout,
|
|
17396
17574
|
logger: options.logger,
|
|
@@ -20500,6 +20678,21 @@ function createWriteHandle() {
|
|
|
20500
20678
|
//#endregion
|
|
20501
20679
|
//#region ../nice-realm/src/RealmClient/RealmClient.ts
|
|
20502
20680
|
enablePatches();
|
|
20681
|
+
function createStepGuard() {
|
|
20682
|
+
let failure;
|
|
20683
|
+
return {
|
|
20684
|
+
run(step) {
|
|
20685
|
+
try {
|
|
20686
|
+
step();
|
|
20687
|
+
} catch (error) {
|
|
20688
|
+
failure ??= { error };
|
|
20689
|
+
}
|
|
20690
|
+
},
|
|
20691
|
+
rethrow() {
|
|
20692
|
+
if (failure != null) throw failure.error;
|
|
20693
|
+
}
|
|
20694
|
+
};
|
|
20695
|
+
}
|
|
20503
20696
|
/** The durable-write backlog cap (§4): past this many unconfirmed reassert frames, new reassert
|
|
20504
20697
|
* writes reject loudly instead of growing memory for the length of the outage. */
|
|
20505
20698
|
const MAX_REASSERT_PENDING_FRAMES = 256;
|
|
@@ -20584,12 +20777,16 @@ function connectRealm(realm, options) {
|
|
|
20584
20777
|
if (status === next) return;
|
|
20585
20778
|
status = next;
|
|
20586
20779
|
if (next === "live") hasBeenLive = true;
|
|
20587
|
-
|
|
20588
|
-
|
|
20589
|
-
|
|
20780
|
+
const guard = createStepGuard();
|
|
20781
|
+
if (next === "detached") guard.run(rejectHydrateQueue);
|
|
20782
|
+
for (const listener of [...statusListeners]) guard.run(() => listener(next, { hasBeenLive }));
|
|
20783
|
+
guard.run(() => devtools?.onStatus?.(next, { hasBeenLive }));
|
|
20784
|
+
guard.rethrow();
|
|
20590
20785
|
};
|
|
20591
20786
|
let pending = [];
|
|
20592
20787
|
const hydrateQueue = [];
|
|
20788
|
+
/** Set from the hydrate's `confirmedVersion` until its queue drains: new writes queue behind. */
|
|
20789
|
+
let hydrating = false;
|
|
20593
20790
|
let nextSeq = 0;
|
|
20594
20791
|
let flushScheduled = false;
|
|
20595
20792
|
let projecting = false;
|
|
@@ -21075,7 +21272,7 @@ function connectRealm(realm, options) {
|
|
|
21075
21272
|
if (queued.expiryTimer != null) clearTimeout(queued.expiryTimer);
|
|
21076
21273
|
rejectUnsent(queued.controller, queued.kind, error, queued.intentName);
|
|
21077
21274
|
};
|
|
21078
|
-
const mustQueueUntilHydrate = () => confirmedVersion === -1 ||
|
|
21275
|
+
const mustQueueUntilHydrate = () => confirmedVersion === -1 || hydrating;
|
|
21079
21276
|
const queueUntilHydrate = (queuedWrite, durability) => {
|
|
21080
21277
|
const controller = createWriteHandle();
|
|
21081
21278
|
if (status === "detached") return rejectUnsent(controller, queuedWrite.kind, neverHydratedError(), queuedWrite.intentName);
|
|
@@ -21089,8 +21286,10 @@ function connectRealm(realm, options) {
|
|
|
21089
21286
|
const index = hydrateQueue.indexOf(queued);
|
|
21090
21287
|
if (index < 0) return;
|
|
21091
21288
|
hydrateQueue.splice(index, 1);
|
|
21092
|
-
|
|
21093
|
-
|
|
21289
|
+
const guard = createStepGuard();
|
|
21290
|
+
guard.run(() => rejectQueued(queued, neverHydratedError()));
|
|
21291
|
+
guard.run(notifyPending);
|
|
21292
|
+
guard.rethrow();
|
|
21094
21293
|
}, expiryMs);
|
|
21095
21294
|
unrefTimer(queued.expiryTimer);
|
|
21096
21295
|
}
|
|
@@ -21098,26 +21297,36 @@ function connectRealm(realm, options) {
|
|
|
21098
21297
|
notifyPending();
|
|
21099
21298
|
return controller.handle;
|
|
21100
21299
|
};
|
|
21101
|
-
const
|
|
21300
|
+
const runQueued = (queued) => {
|
|
21301
|
+
if (queued.expiryTimer != null) clearTimeout(queued.expiryTimer);
|
|
21302
|
+
const { controller } = queued;
|
|
21303
|
+
let sent;
|
|
21304
|
+
try {
|
|
21305
|
+
sent = queued.run();
|
|
21306
|
+
} catch (cause) {
|
|
21307
|
+
console.error(`${warnTag()} a write queued before the first hydrate threw`, cause);
|
|
21308
|
+
rejectQueued(queued, castNiceError(cause));
|
|
21309
|
+
return;
|
|
21310
|
+
}
|
|
21311
|
+
const settled = sent;
|
|
21312
|
+
settled.then(controller.confirm, () => {
|
|
21313
|
+
if (settled.error != null) controller.reject(settled.error);
|
|
21314
|
+
});
|
|
21315
|
+
};
|
|
21316
|
+
/** Runs every queued write; a throwing app callback is held by `guard` and strands nothing. */
|
|
21317
|
+
const drainHydrateQueue = (guard) => {
|
|
21102
21318
|
for (let queued = hydrateQueue.shift(); queued != null; queued = hydrateQueue.shift()) {
|
|
21103
|
-
|
|
21104
|
-
|
|
21105
|
-
let sent;
|
|
21106
|
-
try {
|
|
21107
|
-
sent = queued.run();
|
|
21108
|
-
} catch (cause) {
|
|
21109
|
-
console.error(`${warnTag()} a write queued before the first hydrate threw`, cause);
|
|
21110
|
-
rejectQueued(queued, castNiceError(cause));
|
|
21111
|
-
continue;
|
|
21112
|
-
}
|
|
21113
|
-
const settled = sent;
|
|
21114
|
-
settled.then(controller.confirm, () => {
|
|
21115
|
-
if (settled.error != null) controller.reject(settled.error);
|
|
21116
|
-
});
|
|
21319
|
+
const next = queued;
|
|
21320
|
+
guard.run(() => runQueued(next));
|
|
21117
21321
|
}
|
|
21322
|
+
guard.run(notifyPending);
|
|
21118
21323
|
};
|
|
21119
21324
|
const rejectHydrateQueue = () => {
|
|
21120
|
-
|
|
21325
|
+
if (hydrateQueue.length === 0) return;
|
|
21326
|
+
const guard = createStepGuard();
|
|
21327
|
+
for (const queued of hydrateQueue.splice(0)) guard.run(() => rejectQueued(queued, neverHydratedError()));
|
|
21328
|
+
guard.run(notifyPending);
|
|
21329
|
+
guard.rethrow();
|
|
21121
21330
|
};
|
|
21122
21331
|
const enqueueWrite = (patches, writeOptions) => {
|
|
21123
21332
|
const durability = writeOptions?.durability;
|
|
@@ -21378,15 +21587,23 @@ function connectRealm(realm, options) {
|
|
|
21378
21587
|
};
|
|
21379
21588
|
localMaxPatchesCeiling = void 0;
|
|
21380
21589
|
warnOnIdentityMismatch(frame.avatar);
|
|
21381
|
-
|
|
21382
|
-
|
|
21383
|
-
|
|
21384
|
-
|
|
21385
|
-
|
|
21386
|
-
|
|
21387
|
-
|
|
21388
|
-
|
|
21590
|
+
hydrating = true;
|
|
21591
|
+
const guard = createStepGuard();
|
|
21592
|
+
try {
|
|
21593
|
+
guard.run(() => setStatus("live"));
|
|
21594
|
+
if (helloInFlight) recordRttSample(Date.now() - helloSentAt);
|
|
21595
|
+
helloInFlight = false;
|
|
21596
|
+
if (!isFirstHydrate && realm.transient.length > 0 && options.assertOnAttach != null && !hasPendingSystemAssert()) guard.run(() => enqueueSystemAssert(confirmed));
|
|
21597
|
+
guard.run(revalidateAndResendPending);
|
|
21598
|
+
guard.run(() => project({ fullReplace: true }));
|
|
21599
|
+
const assertOnAttach = options.assertOnAttach;
|
|
21600
|
+
if (assertOnAttach != null && !hasPendingSystemAssert()) guard.run(() => applyUpdate(assertOnAttach));
|
|
21601
|
+
} finally {
|
|
21602
|
+
drainHydrateQueue(guard);
|
|
21603
|
+
hydrating = false;
|
|
21604
|
+
}
|
|
21389
21605
|
checkReownWatch();
|
|
21606
|
+
guard.rethrow();
|
|
21390
21607
|
return;
|
|
21391
21608
|
}
|
|
21392
21609
|
case REALM_FRAME_KIND.keyDict:
|
|
@@ -21784,10 +22001,12 @@ function connectRealm(realm, options) {
|
|
|
21784
22001
|
port.send(bye);
|
|
21785
22002
|
} catch {}
|
|
21786
22003
|
helloInFlight = false;
|
|
21787
|
-
|
|
22004
|
+
const guard = createStepGuard();
|
|
22005
|
+
guard.run(() => setStatus("detached"));
|
|
21788
22006
|
options.connection.release();
|
|
21789
|
-
for (const frame of pending.splice(0)) settleReject(frame, err_realm.fromId("frame_too_stale", { basisVersion: frame.basisVersion }));
|
|
21790
|
-
project();
|
|
22007
|
+
for (const frame of pending.splice(0)) guard.run(() => settleReject(frame, err_realm.fromId("frame_too_stale", { basisVersion: frame.basisVersion })));
|
|
22008
|
+
guard.run(() => project());
|
|
22009
|
+
guard.rethrow();
|
|
21791
22010
|
}
|
|
21792
22011
|
};
|
|
21793
22012
|
devtools?.handleReady?.({
|
|
@@ -22739,7 +22958,8 @@ function unwrapOptional(node) {
|
|
|
22739
22958
|
}
|
|
22740
22959
|
const OMIT = {
|
|
22741
22960
|
value: void 0,
|
|
22742
|
-
anyVisible: false
|
|
22961
|
+
anyVisible: false,
|
|
22962
|
+
structural: false
|
|
22743
22963
|
};
|
|
22744
22964
|
/** Does `path` pass through a record entry? Its containers are then data, not structure. */
|
|
22745
22965
|
function underRecordEntry(schemaRoot, path) {
|
|
@@ -22752,19 +22972,21 @@ function underRecordEntry(schemaRoot, path) {
|
|
|
22752
22972
|
function pruneNode(ctx, node, value, path, inEntry = underRecordEntry(ctx.schemaRoot, path)) {
|
|
22753
22973
|
if (value === void 0) return OMIT;
|
|
22754
22974
|
const inner = unwrapOptional(node);
|
|
22975
|
+
const required = node.kind !== "optional";
|
|
22755
22976
|
if (inner.kind === "object") {
|
|
22756
22977
|
const out = {};
|
|
22757
22978
|
let anyVisible = false;
|
|
22979
|
+
let structural = false;
|
|
22758
22980
|
for (const [key, child] of Object.entries(inner.entries)) {
|
|
22759
22981
|
const pruned = pruneNode(ctx, child, value[key], [...path, key], inEntry);
|
|
22760
|
-
if (pruned.anyVisible)
|
|
22761
|
-
|
|
22762
|
-
|
|
22763
|
-
}
|
|
22982
|
+
if (pruned.anyVisible || pruned.structural) out[key] = pruned.value;
|
|
22983
|
+
if (pruned.anyVisible) anyVisible = true;
|
|
22984
|
+
if (pruned.structural) structural = true;
|
|
22764
22985
|
}
|
|
22765
22986
|
return {
|
|
22766
22987
|
value: out,
|
|
22767
|
-
anyVisible
|
|
22988
|
+
anyVisible,
|
|
22989
|
+
structural: required && structural
|
|
22768
22990
|
};
|
|
22769
22991
|
}
|
|
22770
22992
|
if (inner.kind === "record") {
|
|
@@ -22777,17 +22999,37 @@ function pruneNode(ctx, node, value, path, inEntry = underRecordEntry(ctx.schema
|
|
|
22777
22999
|
anyVisible = true;
|
|
22778
23000
|
}
|
|
22779
23001
|
}
|
|
22780
|
-
const structural = !inEntry && ctx.trie.reachesBeneath(path);
|
|
23002
|
+
const structural = required && !inEntry && ctx.trie.reachesBeneath(path);
|
|
22781
23003
|
return {
|
|
22782
23004
|
value: out,
|
|
22783
|
-
anyVisible: anyVisible ||
|
|
23005
|
+
anyVisible: anyVisible || leafVisible(ctx, path),
|
|
23006
|
+
structural
|
|
22784
23007
|
};
|
|
22785
23008
|
}
|
|
22786
23009
|
return leafVisible(ctx, path) ? {
|
|
22787
23010
|
value,
|
|
22788
|
-
anyVisible: true
|
|
23011
|
+
anyVisible: true,
|
|
23012
|
+
structural: false
|
|
22789
23013
|
} : OMIT;
|
|
22790
23014
|
}
|
|
23015
|
+
/**
|
|
23016
|
+
* Whether the avatar holds `path`'s parent, so a structure-only patch there reveals nothing: true
|
|
23017
|
+
* unless an optional sits between the top level and `path` that neither state shows the avatar.
|
|
23018
|
+
*/
|
|
23019
|
+
function holdsParent(ctx, path, states) {
|
|
23020
|
+
for (let depth = path.length - 1; depth >= 2; depth--) {
|
|
23021
|
+
const ancestorPath = path.slice(0, depth);
|
|
23022
|
+
const ancestor = schemaNodeAtPath(ctx.schemaRoot, ancestorPath);
|
|
23023
|
+
if (ancestor?.kind !== "optional") continue;
|
|
23024
|
+
return states.some((state) => state != null && pruneNode(ctx, ancestor, getAtPath$1(state, ancestorPath), ancestorPath).anyVisible);
|
|
23025
|
+
}
|
|
23026
|
+
return true;
|
|
23027
|
+
}
|
|
23028
|
+
/** A sliced patch target ships for its visible content, or as structure inside a held parent. */
|
|
23029
|
+
function patchTargetShips(ctx, pruned, path, states) {
|
|
23030
|
+
if (pruned.anyVisible) return true;
|
|
23031
|
+
return pruned.structural && holdsParent(ctx, path, states);
|
|
23032
|
+
}
|
|
22791
23033
|
/** The avatar's sliced view of the whole state — the hydrate payload. */
|
|
22792
23034
|
function sliceStateForAvatar(ctx, state) {
|
|
22793
23035
|
const out = {};
|
|
@@ -22799,9 +23041,10 @@ function sliceStateForAvatar(ctx, state) {
|
|
|
22799
23041
|
* possibly with a pruned value (a subtree patch spanning mixed-visibility leaves sends each
|
|
22800
23042
|
* audience only its slice). `statePrev` (pre-commit) drives `remove` expansion; a replay path may
|
|
22801
23043
|
* pass `undefined` — a `remove` that can't be proven invisible is then included (removing a key
|
|
22802
|
-
* the avatar never had must be a client-side no-op).
|
|
23044
|
+
* the avatar never had must be a client-side no-op). `stateAfter` (post-commit), with `statePrev`,
|
|
23045
|
+
* decides whether the avatar holds an optional ancestor of a structure-only container patch.
|
|
22803
23046
|
*/
|
|
22804
|
-
function slicePatchForAvatar(ctx, patch, statePrev) {
|
|
23047
|
+
function slicePatchForAvatar(ctx, patch, statePrev, stateAfter) {
|
|
22805
23048
|
const path = patch.path;
|
|
22806
23049
|
const node = schemaNodeAtPath(ctx.schemaRoot, path);
|
|
22807
23050
|
if (node == null) return void 0;
|
|
@@ -22810,10 +23053,10 @@ function slicePatchForAvatar(ctx, patch, statePrev) {
|
|
|
22810
23053
|
if (patch.op === "remove") {
|
|
22811
23054
|
const prev = statePrev == null ? void 0 : getAtPath$1(statePrev, path);
|
|
22812
23055
|
if (prev === void 0) return patch;
|
|
22813
|
-
return pruneNode(ctx, node, prev, [...path])
|
|
23056
|
+
return patchTargetShips(ctx, pruneNode(ctx, node, prev, [...path]), path, [statePrev, stateAfter]) ? patch : void 0;
|
|
22814
23057
|
}
|
|
22815
23058
|
const pruned = pruneNode(ctx, node, patch.value, [...path]);
|
|
22816
|
-
if (!pruned
|
|
23059
|
+
if (!patchTargetShips(ctx, pruned, path, [statePrev, stateAfter])) return void 0;
|
|
22817
23060
|
return {
|
|
22818
23061
|
op: patch.op,
|
|
22819
23062
|
path,
|
|
@@ -23081,7 +23324,7 @@ var RealmServerEngine = class {
|
|
|
23081
23324
|
sliced.push(sliceTransientRefreshForAvatar(this._sliceCtx(avatar), patch));
|
|
23082
23325
|
continue;
|
|
23083
23326
|
}
|
|
23084
|
-
const slicedPatch = slicePatchForAvatar(this._sliceCtx(avatar), patch, void 0);
|
|
23327
|
+
const slicedPatch = slicePatchForAvatar(this._sliceCtx(avatar), patch, void 0, this._state);
|
|
23085
23328
|
if (slicedPatch != null) sliced.push(slicedPatch);
|
|
23086
23329
|
}
|
|
23087
23330
|
this._sendPatchesFrame(conn, sliced, options.lastKnownVersion, this._version);
|
|
@@ -23685,6 +23928,7 @@ var RealmServerEngine = class {
|
|
|
23685
23928
|
}
|
|
23686
23929
|
_broadcast(namePatches, statePrev, fromVersion, toVersion) {
|
|
23687
23930
|
if (this._connections.size === 0) return;
|
|
23931
|
+
const stateAfter = this._state;
|
|
23688
23932
|
const cache = /* @__PURE__ */ new Map();
|
|
23689
23933
|
for (const conn of this._connections.values()) {
|
|
23690
23934
|
const groupKey = `${viewSignatureKey(conn.avatar)}/${conn.slot}`;
|
|
@@ -23692,7 +23936,7 @@ var RealmServerEngine = class {
|
|
|
23692
23936
|
if (chunks === void 0) {
|
|
23693
23937
|
const sliced = [];
|
|
23694
23938
|
for (const patch of namePatches) {
|
|
23695
|
-
const slicedPatch = slicePatchForAvatar(this._sliceCtx(conn.avatar), patch, statePrev);
|
|
23939
|
+
const slicedPatch = slicePatchForAvatar(this._sliceCtx(conn.avatar), patch, statePrev, stateAfter);
|
|
23696
23940
|
if (slicedPatch != null) sliced.push(slicedPatch);
|
|
23697
23941
|
}
|
|
23698
23942
|
chunks = sliced.length === 0 ? null : this._encodePatchesChunked(sliced, conn.slot, fromVersion, toVersion);
|
|
@@ -24185,7 +24429,8 @@ function commanderStatePaths(dataDir, configKey) {
|
|
|
24185
24429
|
bootLogPath: join(stateDir, "daemon-boot.log"),
|
|
24186
24430
|
ingestSeqPath: join(stateDir, "ingest-seq"),
|
|
24187
24431
|
envOverridesPath: join(stateDir, "env-overrides.json"),
|
|
24188
|
-
savedFiltersPath: join(stateDir, "saved-filters.json")
|
|
24432
|
+
savedFiltersPath: join(stateDir, "saved-filters.json"),
|
|
24433
|
+
lastStartsPath: join(stateDir, "last-starts.json")
|
|
24189
24434
|
};
|
|
24190
24435
|
}
|
|
24191
24436
|
async function ensureStateDir(paths) {
|
|
@@ -24249,6 +24494,7 @@ const commanderStatusRealm = defineRealm({
|
|
|
24249
24494
|
state: t.string(),
|
|
24250
24495
|
pid: t.optional(t.number()),
|
|
24251
24496
|
startedAt: t.optional(t.number()),
|
|
24497
|
+
lastStartedAt: t.optional(t.number()),
|
|
24252
24498
|
sawOutputAt: t.optional(t.number()),
|
|
24253
24499
|
lastTask: t.optional(t.object({
|
|
24254
24500
|
outcome: t.string(),
|
|
@@ -27506,7 +27752,7 @@ async function withTimeout(ctx, run) {
|
|
|
27506
27752
|
async function main() {
|
|
27507
27753
|
const argv = process.argv.slice(2);
|
|
27508
27754
|
if (argv[0] === "daemon") {
|
|
27509
|
-
const { runCommanderDaemon } = await import("./main-
|
|
27755
|
+
const { runCommanderDaemon } = await import("./main-CWWlV2U5.mjs");
|
|
27510
27756
|
return runCommanderDaemon(argv.slice(1));
|
|
27511
27757
|
}
|
|
27512
27758
|
const parsed = parseCliArgs(argv);
|