@ours.network/tg-connector 1.0.1-nightly.8 → 2.0.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/dist/connector.js +347 -278
- package/package.json +4 -4
package/dist/connector.js
CHANGED
|
@@ -3328,7 +3328,7 @@ var require_constants2 = __commonJS({
|
|
|
3328
3328
|
exports.METHODS.POST
|
|
3329
3329
|
];
|
|
3330
3330
|
exports.METHOD_MAP = (0, utils_1.enumToMap)(exports.METHODS);
|
|
3331
|
-
exports.H_METHOD_MAP = Object.fromEntries(Object.entries(exports.METHODS).filter(([
|
|
3331
|
+
exports.H_METHOD_MAP = Object.fromEntries(Object.entries(exports.METHODS).filter(([k]) => k.startsWith("H")));
|
|
3332
3332
|
exports.STATUSES_HTTP = [
|
|
3333
3333
|
exports.STATUSES.CONTINUE,
|
|
3334
3334
|
exports.STATUSES.SWITCHING_PROTOCOLS,
|
|
@@ -4445,8 +4445,8 @@ var require_webidl = __commonJS({
|
|
|
4445
4445
|
message: `"${context.value}" is an invalid ${context.type}.`
|
|
4446
4446
|
});
|
|
4447
4447
|
};
|
|
4448
|
-
webidl.brandCheck = function(V2,
|
|
4449
|
-
if (!FunctionPrototypeSymbolHasInstance(
|
|
4448
|
+
webidl.brandCheck = function(V2, I3) {
|
|
4449
|
+
if (!FunctionPrototypeSymbolHasInstance(I3, V2)) {
|
|
4450
4450
|
const err = new TypeError("Illegal invocation");
|
|
4451
4451
|
err.code = "ERR_INVALID_THIS";
|
|
4452
4452
|
throw err;
|
|
@@ -4476,8 +4476,8 @@ var require_webidl = __commonJS({
|
|
|
4476
4476
|
message: "Illegal constructor"
|
|
4477
4477
|
});
|
|
4478
4478
|
};
|
|
4479
|
-
webidl.util.MakeTypeAssertion = function(
|
|
4480
|
-
return (
|
|
4479
|
+
webidl.util.MakeTypeAssertion = function(I3) {
|
|
4480
|
+
return (O2) => FunctionPrototypeSymbolHasInstance(I3, O2);
|
|
4481
4481
|
};
|
|
4482
4482
|
webidl.util.Type = function(V2) {
|
|
4483
4483
|
switch (typeof V2) {
|
|
@@ -4655,30 +4655,30 @@ var require_webidl = __commonJS({
|
|
|
4655
4655
|
};
|
|
4656
4656
|
};
|
|
4657
4657
|
webidl.recordConverter = function(keyConverter, valueConverter) {
|
|
4658
|
-
return (
|
|
4659
|
-
if (webidl.util.Type(
|
|
4658
|
+
return (O2, prefix, argument) => {
|
|
4659
|
+
if (webidl.util.Type(O2) !== OBJECT) {
|
|
4660
4660
|
throw webidl.errors.exception({
|
|
4661
4661
|
header: prefix,
|
|
4662
|
-
message: `${argument} ("${webidl.util.TypeValueToString(
|
|
4662
|
+
message: `${argument} ("${webidl.util.TypeValueToString(O2)}") is not an Object.`
|
|
4663
4663
|
});
|
|
4664
4664
|
}
|
|
4665
4665
|
const result = {};
|
|
4666
|
-
if (!types.isProxy(
|
|
4667
|
-
const keys2 = [...Object.getOwnPropertyNames(
|
|
4666
|
+
if (!types.isProxy(O2)) {
|
|
4667
|
+
const keys2 = [...Object.getOwnPropertyNames(O2), ...Object.getOwnPropertySymbols(O2)];
|
|
4668
4668
|
for (const key of keys2) {
|
|
4669
4669
|
const keyName = webidl.util.Stringify(key);
|
|
4670
4670
|
const typedKey = keyConverter(key, prefix, `Key ${keyName} in ${argument}`);
|
|
4671
|
-
const typedValue = valueConverter(
|
|
4671
|
+
const typedValue = valueConverter(O2[key], prefix, `${argument}[${keyName}]`);
|
|
4672
4672
|
result[typedKey] = typedValue;
|
|
4673
4673
|
}
|
|
4674
4674
|
return result;
|
|
4675
4675
|
}
|
|
4676
|
-
const keys = Reflect.ownKeys(
|
|
4676
|
+
const keys = Reflect.ownKeys(O2);
|
|
4677
4677
|
for (const key of keys) {
|
|
4678
|
-
const desc = Reflect.getOwnPropertyDescriptor(
|
|
4678
|
+
const desc = Reflect.getOwnPropertyDescriptor(O2, key);
|
|
4679
4679
|
if (desc?.enumerable) {
|
|
4680
4680
|
const typedKey = keyConverter(key, prefix, argument);
|
|
4681
|
-
const typedValue = valueConverter(
|
|
4681
|
+
const typedValue = valueConverter(O2[key], prefix, argument);
|
|
4682
4682
|
result[typedKey] = typedValue;
|
|
4683
4683
|
}
|
|
4684
4684
|
}
|
|
@@ -5324,11 +5324,11 @@ var require_util2 = __commonJS({
|
|
|
5324
5324
|
}
|
|
5325
5325
|
function tryUpgradeRequestToAPotentiallyTrustworthyURL(request) {
|
|
5326
5326
|
}
|
|
5327
|
-
function sameOrigin(A2,
|
|
5328
|
-
if (A2.origin ===
|
|
5327
|
+
function sameOrigin(A2, B) {
|
|
5328
|
+
if (A2.origin === B.origin && A2.origin === "null") {
|
|
5329
5329
|
return true;
|
|
5330
5330
|
}
|
|
5331
|
-
if (A2.protocol ===
|
|
5331
|
+
if (A2.protocol === B.protocol && A2.hostname === B.hostname && A2.port === B.port) {
|
|
5332
5332
|
return true;
|
|
5333
5333
|
}
|
|
5334
5334
|
return false;
|
|
@@ -6658,7 +6658,7 @@ var require_client_h1 = __commonJS({
|
|
|
6658
6658
|
* @param {number} len
|
|
6659
6659
|
* @returns {number}
|
|
6660
6660
|
*/
|
|
6661
|
-
wasm_on_url: (
|
|
6661
|
+
wasm_on_url: (p2, at2, len) => {
|
|
6662
6662
|
return 0;
|
|
6663
6663
|
},
|
|
6664
6664
|
/**
|
|
@@ -6667,8 +6667,8 @@ var require_client_h1 = __commonJS({
|
|
|
6667
6667
|
* @param {number} len
|
|
6668
6668
|
* @returns {number}
|
|
6669
6669
|
*/
|
|
6670
|
-
wasm_on_status: (
|
|
6671
|
-
assert(currentParser.ptr ===
|
|
6670
|
+
wasm_on_status: (p2, at2, len) => {
|
|
6671
|
+
assert(currentParser.ptr === p2);
|
|
6672
6672
|
const start = at2 - currentBufferPtr + currentBufferRef.byteOffset;
|
|
6673
6673
|
return currentParser.onStatus(new FastBuffer(currentBufferRef.buffer, start, len));
|
|
6674
6674
|
},
|
|
@@ -6676,8 +6676,8 @@ var require_client_h1 = __commonJS({
|
|
|
6676
6676
|
* @param {number} p
|
|
6677
6677
|
* @returns {number}
|
|
6678
6678
|
*/
|
|
6679
|
-
wasm_on_message_begin: (
|
|
6680
|
-
assert(currentParser.ptr ===
|
|
6679
|
+
wasm_on_message_begin: (p2) => {
|
|
6680
|
+
assert(currentParser.ptr === p2);
|
|
6681
6681
|
return currentParser.onMessageBegin();
|
|
6682
6682
|
},
|
|
6683
6683
|
/**
|
|
@@ -6686,8 +6686,8 @@ var require_client_h1 = __commonJS({
|
|
|
6686
6686
|
* @param {number} len
|
|
6687
6687
|
* @returns {number}
|
|
6688
6688
|
*/
|
|
6689
|
-
wasm_on_header_field: (
|
|
6690
|
-
assert(currentParser.ptr ===
|
|
6689
|
+
wasm_on_header_field: (p2, at2, len) => {
|
|
6690
|
+
assert(currentParser.ptr === p2);
|
|
6691
6691
|
const start = at2 - currentBufferPtr + currentBufferRef.byteOffset;
|
|
6692
6692
|
return currentParser.onHeaderField(new FastBuffer(currentBufferRef.buffer, start, len));
|
|
6693
6693
|
},
|
|
@@ -6697,8 +6697,8 @@ var require_client_h1 = __commonJS({
|
|
|
6697
6697
|
* @param {number} len
|
|
6698
6698
|
* @returns {number}
|
|
6699
6699
|
*/
|
|
6700
|
-
wasm_on_header_value: (
|
|
6701
|
-
assert(currentParser.ptr ===
|
|
6700
|
+
wasm_on_header_value: (p2, at2, len) => {
|
|
6701
|
+
assert(currentParser.ptr === p2);
|
|
6702
6702
|
const start = at2 - currentBufferPtr + currentBufferRef.byteOffset;
|
|
6703
6703
|
return currentParser.onHeaderValue(new FastBuffer(currentBufferRef.buffer, start, len));
|
|
6704
6704
|
},
|
|
@@ -6709,8 +6709,8 @@ var require_client_h1 = __commonJS({
|
|
|
6709
6709
|
* @param {0|1} shouldKeepAlive
|
|
6710
6710
|
* @returns {number}
|
|
6711
6711
|
*/
|
|
6712
|
-
wasm_on_headers_complete: (
|
|
6713
|
-
assert(currentParser.ptr ===
|
|
6712
|
+
wasm_on_headers_complete: (p2, statusCode, upgrade, shouldKeepAlive) => {
|
|
6713
|
+
assert(currentParser.ptr === p2);
|
|
6714
6714
|
return currentParser.onHeadersComplete(statusCode, upgrade === 1, shouldKeepAlive === 1);
|
|
6715
6715
|
},
|
|
6716
6716
|
/**
|
|
@@ -6719,8 +6719,8 @@ var require_client_h1 = __commonJS({
|
|
|
6719
6719
|
* @param {number} len
|
|
6720
6720
|
* @returns {number}
|
|
6721
6721
|
*/
|
|
6722
|
-
wasm_on_body: (
|
|
6723
|
-
assert(currentParser.ptr ===
|
|
6722
|
+
wasm_on_body: (p2, at2, len) => {
|
|
6723
|
+
assert(currentParser.ptr === p2);
|
|
6724
6724
|
const start = at2 - currentBufferPtr + currentBufferRef.byteOffset;
|
|
6725
6725
|
return currentParser.onBody(new FastBuffer(currentBufferRef.buffer, start, len));
|
|
6726
6726
|
},
|
|
@@ -6728,8 +6728,8 @@ var require_client_h1 = __commonJS({
|
|
|
6728
6728
|
* @param {number} p
|
|
6729
6729
|
* @returns {number}
|
|
6730
6730
|
*/
|
|
6731
|
-
wasm_on_message_complete: (
|
|
6732
|
-
assert(currentParser.ptr ===
|
|
6731
|
+
wasm_on_message_complete: (p2) => {
|
|
6732
|
+
assert(currentParser.ptr === p2);
|
|
6733
6733
|
return currentParser.onMessageComplete();
|
|
6734
6734
|
}
|
|
6735
6735
|
}
|
|
@@ -9584,7 +9584,7 @@ var require_balanced_pool = __commonJS({
|
|
|
9584
9584
|
return this[kClients].find((pool) => pool[kUrl].origin === upstreamOrigin && pool.closed !== true && pool.destroyed !== true);
|
|
9585
9585
|
}
|
|
9586
9586
|
get upstreams() {
|
|
9587
|
-
return this[kClients].filter((dispatcher) => dispatcher.closed !== true && dispatcher.destroyed !== true).map((
|
|
9587
|
+
return this[kClients].filter((dispatcher) => dispatcher.closed !== true && dispatcher.destroyed !== true).map((p2) => p2[kUrl].origin);
|
|
9588
9588
|
}
|
|
9589
9589
|
[kGetDispatcher]() {
|
|
9590
9590
|
if (this[kClients].length === 0) {
|
|
@@ -14623,7 +14623,7 @@ var require_redirect_handler = __commonJS({
|
|
|
14623
14623
|
}
|
|
14624
14624
|
this.dispatch = dispatch;
|
|
14625
14625
|
this.location = null;
|
|
14626
|
-
const { maxRedirections:
|
|
14626
|
+
const { maxRedirections: _, ...cleanOpts } = opts;
|
|
14627
14627
|
this.opts = cleanOpts;
|
|
14628
14628
|
this.maxRedirections = maxRedirections;
|
|
14629
14629
|
this.handler = handler;
|
|
@@ -15824,9 +15824,9 @@ var require_cache = __commonJS({
|
|
|
15824
15824
|
if (typeof store !== "object" || store === null) {
|
|
15825
15825
|
throw new TypeError(`expected type of ${name} to be a CacheStore, got ${store === null ? "null" : typeof store}`);
|
|
15826
15826
|
}
|
|
15827
|
-
for (const
|
|
15828
|
-
if (typeof store[
|
|
15829
|
-
throw new TypeError(`${name} needs to have a \`${
|
|
15827
|
+
for (const fn2 of ["get", "createWriteStream", "delete"]) {
|
|
15828
|
+
if (typeof store[fn2] !== "function") {
|
|
15829
|
+
throw new TypeError(`${name} needs to have a \`${fn2}()\` function`);
|
|
15830
15830
|
}
|
|
15831
15831
|
}
|
|
15832
15832
|
}
|
|
@@ -17138,7 +17138,7 @@ var require_cache_revalidation_handler = __commonJS({
|
|
|
17138
17138
|
this.#handler = handler;
|
|
17139
17139
|
this.#allowErrorStatusCodes = allowErrorStatusCodes;
|
|
17140
17140
|
}
|
|
17141
|
-
onRequestStart(
|
|
17141
|
+
onRequestStart(_, context) {
|
|
17142
17142
|
this.#successful = false;
|
|
17143
17143
|
this.#context = context;
|
|
17144
17144
|
}
|
|
@@ -17836,7 +17836,7 @@ var require_decompress = __commonJS({
|
|
|
17836
17836
|
return super.onResponseStart(controller, statusCode, headers, statusMessage);
|
|
17837
17837
|
}
|
|
17838
17838
|
this.#decompressors = decompressors;
|
|
17839
|
-
const { "content-encoding":
|
|
17839
|
+
const { "content-encoding": _, "content-length": __, ...newHeaders } = headers;
|
|
17840
17840
|
if (controller?.rawHeaders) {
|
|
17841
17841
|
const rawHeaders = controller.rawHeaders;
|
|
17842
17842
|
if (Array.isArray(rawHeaders)) {
|
|
@@ -19474,12 +19474,12 @@ var require_response = __commonJS({
|
|
|
19474
19474
|
...state
|
|
19475
19475
|
};
|
|
19476
19476
|
return new Proxy(response, {
|
|
19477
|
-
get(target,
|
|
19478
|
-
return
|
|
19477
|
+
get(target, p2) {
|
|
19478
|
+
return p2 in state ? state[p2] : target[p2];
|
|
19479
19479
|
},
|
|
19480
|
-
set(target,
|
|
19481
|
-
assert(!(
|
|
19482
|
-
target[
|
|
19480
|
+
set(target, p2, value) {
|
|
19481
|
+
assert(!(p2 in state));
|
|
19482
|
+
target[p2] = value;
|
|
19483
19483
|
return true;
|
|
19484
19484
|
}
|
|
19485
19485
|
});
|
|
@@ -20623,18 +20623,18 @@ var require_fetch = __commonJS({
|
|
|
20623
20623
|
}
|
|
20624
20624
|
function fetch2(input, init = void 0) {
|
|
20625
20625
|
webidl.argumentLengthCheck(arguments, 1, "globalThis.fetch");
|
|
20626
|
-
let
|
|
20626
|
+
let p2 = createDeferredPromise();
|
|
20627
20627
|
let requestObject;
|
|
20628
20628
|
try {
|
|
20629
20629
|
requestObject = new Request(input, init);
|
|
20630
20630
|
} catch (e2) {
|
|
20631
|
-
|
|
20632
|
-
return
|
|
20631
|
+
p2.reject(e2);
|
|
20632
|
+
return p2.promise;
|
|
20633
20633
|
}
|
|
20634
20634
|
const request = getRequestState(requestObject);
|
|
20635
20635
|
if (requestObject.signal.aborted) {
|
|
20636
|
-
abortFetch(
|
|
20637
|
-
return
|
|
20636
|
+
abortFetch(p2, request, null, requestObject.signal.reason, null);
|
|
20637
|
+
return p2.promise;
|
|
20638
20638
|
}
|
|
20639
20639
|
const globalObject = request.client.globalObject;
|
|
20640
20640
|
if (globalObject?.constructor?.name === "ServiceWorkerGlobalScope") {
|
|
@@ -20650,7 +20650,7 @@ var require_fetch = __commonJS({
|
|
|
20650
20650
|
assert(controller != null);
|
|
20651
20651
|
controller.abort(requestObject.signal.reason);
|
|
20652
20652
|
const realResponse = responseObject?.deref();
|
|
20653
|
-
abortFetch(
|
|
20653
|
+
abortFetch(p2, request, realResponse, requestObject.signal.reason, controller.controller);
|
|
20654
20654
|
}
|
|
20655
20655
|
);
|
|
20656
20656
|
const processResponse = (response) => {
|
|
@@ -20658,16 +20658,16 @@ var require_fetch = __commonJS({
|
|
|
20658
20658
|
return;
|
|
20659
20659
|
}
|
|
20660
20660
|
if (response.aborted) {
|
|
20661
|
-
abortFetch(
|
|
20661
|
+
abortFetch(p2, request, responseObject, controller.serializedAbortReason, controller.controller);
|
|
20662
20662
|
return;
|
|
20663
20663
|
}
|
|
20664
20664
|
if (response.type === "error") {
|
|
20665
|
-
|
|
20665
|
+
p2.reject(new TypeError("fetch failed", { cause: response.error }));
|
|
20666
20666
|
return;
|
|
20667
20667
|
}
|
|
20668
20668
|
responseObject = new WeakRef(fromInnerResponse(response, "immutable"));
|
|
20669
|
-
|
|
20670
|
-
|
|
20669
|
+
p2.resolve(responseObject.deref());
|
|
20670
|
+
p2 = null;
|
|
20671
20671
|
};
|
|
20672
20672
|
controller = fetching({
|
|
20673
20673
|
request,
|
|
@@ -20679,7 +20679,7 @@ var require_fetch = __commonJS({
|
|
|
20679
20679
|
// See https://github.com/nodejs/undici/issues/4627
|
|
20680
20680
|
requestObject
|
|
20681
20681
|
});
|
|
20682
|
-
return
|
|
20682
|
+
return p2.promise;
|
|
20683
20683
|
}
|
|
20684
20684
|
function finalizeAndReportTiming(response, initiatorType = "other") {
|
|
20685
20685
|
if (response.type === "error" && response.aborted) {
|
|
@@ -20717,9 +20717,9 @@ var require_fetch = __commonJS({
|
|
|
20717
20717
|
);
|
|
20718
20718
|
}
|
|
20719
20719
|
var markResourceTiming = performance.markResourceTiming;
|
|
20720
|
-
function abortFetch(
|
|
20721
|
-
if (
|
|
20722
|
-
|
|
20720
|
+
function abortFetch(p2, request, responseObject, error, controller) {
|
|
20721
|
+
if (p2) {
|
|
20722
|
+
p2.reject(error);
|
|
20723
20723
|
}
|
|
20724
20724
|
if (request.body?.stream != null && isReadable(request.body.stream)) {
|
|
20725
20725
|
request.body.stream.cancel(error).catch((err) => {
|
|
@@ -21666,9 +21666,9 @@ var require_util3 = __commonJS({
|
|
|
21666
21666
|
var assert = __require("node:assert");
|
|
21667
21667
|
var { URLSerializer } = require_data_url();
|
|
21668
21668
|
var { isValidHeaderName } = require_util2();
|
|
21669
|
-
function urlEquals(A2,
|
|
21669
|
+
function urlEquals(A2, B, excludeFragment = false) {
|
|
21670
21670
|
const serializedA = URLSerializer(A2, excludeFragment);
|
|
21671
|
-
const serializedB = URLSerializer(
|
|
21671
|
+
const serializedB = URLSerializer(B, excludeFragment);
|
|
21672
21672
|
return serializedA === serializedB;
|
|
21673
21673
|
}
|
|
21674
21674
|
function getFieldValues(header) {
|
|
@@ -21722,11 +21722,11 @@ var require_cache3 = __commonJS({
|
|
|
21722
21722
|
webidl.argumentLengthCheck(arguments, 1, prefix);
|
|
21723
21723
|
request = webidl.converters.RequestInfo(request);
|
|
21724
21724
|
options = webidl.converters.CacheQueryOptions(options, prefix, "options");
|
|
21725
|
-
const
|
|
21726
|
-
if (
|
|
21725
|
+
const p2 = this.#internalMatchAll(request, options, 1);
|
|
21726
|
+
if (p2.length === 0) {
|
|
21727
21727
|
return;
|
|
21728
21728
|
}
|
|
21729
|
-
return
|
|
21729
|
+
return p2[0];
|
|
21730
21730
|
}
|
|
21731
21731
|
async matchAll(request = void 0, options = {}) {
|
|
21732
21732
|
webidl.brandCheck(this, _Cache);
|
|
@@ -21817,8 +21817,8 @@ var require_cache3 = __commonJS({
|
|
|
21817
21817
|
}));
|
|
21818
21818
|
responsePromises.push(responsePromise.promise);
|
|
21819
21819
|
}
|
|
21820
|
-
const
|
|
21821
|
-
const responses = await
|
|
21820
|
+
const p2 = Promise.all(responsePromises);
|
|
21821
|
+
const responses = await p2;
|
|
21822
21822
|
const operations = [];
|
|
21823
21823
|
let index = 0;
|
|
21824
21824
|
for (const response of responses) {
|
|
@@ -22494,7 +22494,7 @@ var require_util4 = __commonJS({
|
|
|
22494
22494
|
"Nov",
|
|
22495
22495
|
"Dec"
|
|
22496
22496
|
];
|
|
22497
|
-
var IMFPaddedNumbers = Array(61).fill(0).map((
|
|
22497
|
+
var IMFPaddedNumbers = Array(61).fill(0).map((_, i) => i.toString().padStart(2, "0"));
|
|
22498
22498
|
function toIMFDate(date) {
|
|
22499
22499
|
if (typeof date === "number") {
|
|
22500
22500
|
date = new Date(date);
|
|
@@ -23739,7 +23739,7 @@ var require_receiver = __commonJS({
|
|
|
23739
23739
|
* @param {Buffer} chunk
|
|
23740
23740
|
* @param {() => void} callback
|
|
23741
23741
|
*/
|
|
23742
|
-
_write(chunk,
|
|
23742
|
+
_write(chunk, _, callback) {
|
|
23743
23743
|
this.#buffers.push(chunk);
|
|
23744
23744
|
this.#byteOffset += chunk.length;
|
|
23745
23745
|
this.#loop = true;
|
|
@@ -24241,10 +24241,10 @@ var require_websocket = __commonJS({
|
|
|
24241
24241
|
if (typeof protocols === "string") {
|
|
24242
24242
|
protocols = [protocols];
|
|
24243
24243
|
}
|
|
24244
|
-
if (protocols.length !== new Set(protocols.map((
|
|
24244
|
+
if (protocols.length !== new Set(protocols.map((p2) => p2.toLowerCase())).size) {
|
|
24245
24245
|
throw new DOMException("Invalid Sec-WebSocket-Protocol value", "SyntaxError");
|
|
24246
24246
|
}
|
|
24247
|
-
if (protocols.length > 0 && !protocols.every((
|
|
24247
|
+
if (protocols.length > 0 && !protocols.every((p2) => isValidSubprotocol(p2))) {
|
|
24248
24248
|
throw new DOMException("Invalid Sec-WebSocket-Protocol value", "SyntaxError");
|
|
24249
24249
|
}
|
|
24250
24250
|
this.#url = new URL(urlRecord.href);
|
|
@@ -24339,15 +24339,15 @@ var require_websocket = __commonJS({
|
|
|
24339
24339
|
webidl.brandCheck(this, _WebSocket);
|
|
24340
24340
|
return this.#events.open;
|
|
24341
24341
|
}
|
|
24342
|
-
set onopen(
|
|
24342
|
+
set onopen(fn2) {
|
|
24343
24343
|
webidl.brandCheck(this, _WebSocket);
|
|
24344
24344
|
if (this.#events.open) {
|
|
24345
24345
|
this.removeEventListener("open", this.#events.open);
|
|
24346
24346
|
}
|
|
24347
|
-
const listener = webidl.converters.EventHandlerNonNull(
|
|
24347
|
+
const listener = webidl.converters.EventHandlerNonNull(fn2);
|
|
24348
24348
|
if (listener !== null) {
|
|
24349
24349
|
this.addEventListener("open", listener);
|
|
24350
|
-
this.#events.open =
|
|
24350
|
+
this.#events.open = fn2;
|
|
24351
24351
|
} else {
|
|
24352
24352
|
this.#events.open = null;
|
|
24353
24353
|
}
|
|
@@ -24356,15 +24356,15 @@ var require_websocket = __commonJS({
|
|
|
24356
24356
|
webidl.brandCheck(this, _WebSocket);
|
|
24357
24357
|
return this.#events.error;
|
|
24358
24358
|
}
|
|
24359
|
-
set onerror(
|
|
24359
|
+
set onerror(fn2) {
|
|
24360
24360
|
webidl.brandCheck(this, _WebSocket);
|
|
24361
24361
|
if (this.#events.error) {
|
|
24362
24362
|
this.removeEventListener("error", this.#events.error);
|
|
24363
24363
|
}
|
|
24364
|
-
const listener = webidl.converters.EventHandlerNonNull(
|
|
24364
|
+
const listener = webidl.converters.EventHandlerNonNull(fn2);
|
|
24365
24365
|
if (listener !== null) {
|
|
24366
24366
|
this.addEventListener("error", listener);
|
|
24367
|
-
this.#events.error =
|
|
24367
|
+
this.#events.error = fn2;
|
|
24368
24368
|
} else {
|
|
24369
24369
|
this.#events.error = null;
|
|
24370
24370
|
}
|
|
@@ -24373,15 +24373,15 @@ var require_websocket = __commonJS({
|
|
|
24373
24373
|
webidl.brandCheck(this, _WebSocket);
|
|
24374
24374
|
return this.#events.close;
|
|
24375
24375
|
}
|
|
24376
|
-
set onclose(
|
|
24376
|
+
set onclose(fn2) {
|
|
24377
24377
|
webidl.brandCheck(this, _WebSocket);
|
|
24378
24378
|
if (this.#events.close) {
|
|
24379
24379
|
this.removeEventListener("close", this.#events.close);
|
|
24380
24380
|
}
|
|
24381
|
-
const listener = webidl.converters.EventHandlerNonNull(
|
|
24381
|
+
const listener = webidl.converters.EventHandlerNonNull(fn2);
|
|
24382
24382
|
if (listener !== null) {
|
|
24383
24383
|
this.addEventListener("close", listener);
|
|
24384
|
-
this.#events.close =
|
|
24384
|
+
this.#events.close = fn2;
|
|
24385
24385
|
} else {
|
|
24386
24386
|
this.#events.close = null;
|
|
24387
24387
|
}
|
|
@@ -24390,15 +24390,15 @@ var require_websocket = __commonJS({
|
|
|
24390
24390
|
webidl.brandCheck(this, _WebSocket);
|
|
24391
24391
|
return this.#events.message;
|
|
24392
24392
|
}
|
|
24393
|
-
set onmessage(
|
|
24393
|
+
set onmessage(fn2) {
|
|
24394
24394
|
webidl.brandCheck(this, _WebSocket);
|
|
24395
24395
|
if (this.#events.message) {
|
|
24396
24396
|
this.removeEventListener("message", this.#events.message);
|
|
24397
24397
|
}
|
|
24398
|
-
const listener = webidl.converters.EventHandlerNonNull(
|
|
24398
|
+
const listener = webidl.converters.EventHandlerNonNull(fn2);
|
|
24399
24399
|
if (listener !== null) {
|
|
24400
24400
|
this.addEventListener("message", listener);
|
|
24401
|
-
this.#events.message =
|
|
24401
|
+
this.#events.message = fn2;
|
|
24402
24402
|
} else {
|
|
24403
24403
|
this.#events.message = null;
|
|
24404
24404
|
}
|
|
@@ -24784,10 +24784,10 @@ var require_websocketstream = __commonJS({
|
|
|
24784
24784
|
const baseURL = environmentSettingsObject.settingsObject.baseUrl;
|
|
24785
24785
|
const urlRecord = getURLRecord(url, baseURL);
|
|
24786
24786
|
const protocols = options.protocols;
|
|
24787
|
-
if (protocols.length !== new Set(protocols.map((
|
|
24787
|
+
if (protocols.length !== new Set(protocols.map((p2) => p2.toLowerCase())).size) {
|
|
24788
24788
|
throw new DOMException("Invalid Sec-WebSocket-Protocol value", "SyntaxError");
|
|
24789
24789
|
}
|
|
24790
|
-
if (protocols.length > 0 && !protocols.every((
|
|
24790
|
+
if (protocols.length > 0 && !protocols.every((p2) => isValidSubprotocol(p2))) {
|
|
24791
24791
|
throw new DOMException("Invalid Sec-WebSocket-Protocol value", "SyntaxError");
|
|
24792
24792
|
}
|
|
24793
24793
|
this.#url = urlRecord.toString();
|
|
@@ -25578,14 +25578,14 @@ var require_eventsource = __commonJS({
|
|
|
25578
25578
|
get onopen() {
|
|
25579
25579
|
return this.#events.open;
|
|
25580
25580
|
}
|
|
25581
|
-
set onopen(
|
|
25581
|
+
set onopen(fn2) {
|
|
25582
25582
|
if (this.#events.open) {
|
|
25583
25583
|
this.removeEventListener("open", this.#events.open);
|
|
25584
25584
|
}
|
|
25585
|
-
const listener = webidl.converters.EventHandlerNonNull(
|
|
25585
|
+
const listener = webidl.converters.EventHandlerNonNull(fn2);
|
|
25586
25586
|
if (listener !== null) {
|
|
25587
25587
|
this.addEventListener("open", listener);
|
|
25588
|
-
this.#events.open =
|
|
25588
|
+
this.#events.open = fn2;
|
|
25589
25589
|
} else {
|
|
25590
25590
|
this.#events.open = null;
|
|
25591
25591
|
}
|
|
@@ -25593,14 +25593,14 @@ var require_eventsource = __commonJS({
|
|
|
25593
25593
|
get onmessage() {
|
|
25594
25594
|
return this.#events.message;
|
|
25595
25595
|
}
|
|
25596
|
-
set onmessage(
|
|
25596
|
+
set onmessage(fn2) {
|
|
25597
25597
|
if (this.#events.message) {
|
|
25598
25598
|
this.removeEventListener("message", this.#events.message);
|
|
25599
25599
|
}
|
|
25600
|
-
const listener = webidl.converters.EventHandlerNonNull(
|
|
25600
|
+
const listener = webidl.converters.EventHandlerNonNull(fn2);
|
|
25601
25601
|
if (listener !== null) {
|
|
25602
25602
|
this.addEventListener("message", listener);
|
|
25603
|
-
this.#events.message =
|
|
25603
|
+
this.#events.message = fn2;
|
|
25604
25604
|
} else {
|
|
25605
25605
|
this.#events.message = null;
|
|
25606
25606
|
}
|
|
@@ -25608,14 +25608,14 @@ var require_eventsource = __commonJS({
|
|
|
25608
25608
|
get onerror() {
|
|
25609
25609
|
return this.#events.error;
|
|
25610
25610
|
}
|
|
25611
|
-
set onerror(
|
|
25611
|
+
set onerror(fn2) {
|
|
25612
25612
|
if (this.#events.error) {
|
|
25613
25613
|
this.removeEventListener("error", this.#events.error);
|
|
25614
25614
|
}
|
|
25615
|
-
const listener = webidl.converters.EventHandlerNonNull(
|
|
25615
|
+
const listener = webidl.converters.EventHandlerNonNull(fn2);
|
|
25616
25616
|
if (listener !== null) {
|
|
25617
25617
|
this.addEventListener("error", listener);
|
|
25618
|
-
this.#events.error =
|
|
25618
|
+
this.#events.error = fn2;
|
|
25619
25619
|
} else {
|
|
25620
25620
|
this.#events.error = null;
|
|
25621
25621
|
}
|
|
@@ -25756,7 +25756,7 @@ var require_undici = __commonJS({
|
|
|
25756
25756
|
parseHeaders: util.parseHeaders,
|
|
25757
25757
|
headerNameToString: util.headerNameToString
|
|
25758
25758
|
};
|
|
25759
|
-
function makeDispatcher(
|
|
25759
|
+
function makeDispatcher(fn2) {
|
|
25760
25760
|
return (url, opts, handler) => {
|
|
25761
25761
|
if (typeof opts === "function") {
|
|
25762
25762
|
handler = opts;
|
|
@@ -25787,7 +25787,7 @@ var require_undici = __commonJS({
|
|
|
25787
25787
|
if (agent) {
|
|
25788
25788
|
throw new InvalidArgumentError("unsupported opts.agent. Did you mean opts.client?");
|
|
25789
25789
|
}
|
|
25790
|
-
return
|
|
25790
|
+
return fn2.call(dispatcher, {
|
|
25791
25791
|
...opts,
|
|
25792
25792
|
origin: url.origin,
|
|
25793
25793
|
path: url.search ? `${url.pathname}${url.search}` : url.pathname,
|
|
@@ -26053,7 +26053,7 @@ function readFileConfig() {
|
|
|
26053
26053
|
if (typeof parsed.sttBaseUrl === "string") out.sttBaseUrl = parsed.sttBaseUrl;
|
|
26054
26054
|
if (typeof parsed.sttModel === "string") out.sttModel = parsed.sttModel;
|
|
26055
26055
|
if (typeof parsed.sttLanguage === "string") out.sttLanguage = parsed.sttLanguage;
|
|
26056
|
-
if (Array.isArray(parsed.sttKinds)) out.sttKinds = parsed.sttKinds.filter((
|
|
26056
|
+
if (Array.isArray(parsed.sttKinds)) out.sttKinds = parsed.sttKinds.filter((k) => typeof k === "string");
|
|
26057
26057
|
if (typeof parsed.sttMaxBytes === "number" && Number.isFinite(parsed.sttMaxBytes)) out.sttMaxBytes = parsed.sttMaxBytes;
|
|
26058
26058
|
if (typeof parsed.sttTimeoutMs === "number" && Number.isFinite(parsed.sttTimeoutMs)) out.sttTimeoutMs = parsed.sttTimeoutMs;
|
|
26059
26059
|
if (typeof parsed.forwardVoiceAudio === "boolean") out.forwardVoiceAudio = parsed.forwardVoiceAudio;
|
|
@@ -26104,16 +26104,16 @@ function loadConfig() {
|
|
|
26104
26104
|
};
|
|
26105
26105
|
}
|
|
26106
26106
|
|
|
26107
|
-
// node_modules/@ours.network/sdk/dist/chunk-
|
|
26107
|
+
// node_modules/@ours.network/sdk/dist/chunk-GPUVPRIY.js
|
|
26108
26108
|
import * as e from "node:fs";
|
|
26109
|
-
import { randomBytes as
|
|
26110
|
-
import { dirname as
|
|
26111
|
-
import { homedir as
|
|
26112
|
-
import { resolve as
|
|
26109
|
+
import { randomBytes as O } from "node:crypto";
|
|
26110
|
+
import { dirname as y, isAbsolute as v, resolve as b } from "node:path";
|
|
26111
|
+
import { homedir as T } from "node:os";
|
|
26112
|
+
import { resolve as E, join as R, dirname as I, basename as A } from "node:path";
|
|
26113
26113
|
function u(t, o = false) {
|
|
26114
|
-
if (typeof process.geteuid != "function" || !e.constants.O_NOFOLLOW || !e.constants.O_NONBLOCK || typeof t != "string" || !
|
|
26114
|
+
if (typeof process.geteuid != "function" || !e.constants.O_NOFOLLOW || !e.constants.O_NONBLOCK || typeof t != "string" || !v(t) || b(t) !== t) throw new Error();
|
|
26115
26115
|
let s = process.geteuid(), r = [];
|
|
26116
|
-
for (let i =
|
|
26116
|
+
for (let i = y(t); r.unshift(i), i !== y(i); i = y(i)) ;
|
|
26117
26117
|
return r.map((i, l) => {
|
|
26118
26118
|
let n;
|
|
26119
26119
|
try {
|
|
@@ -26128,8 +26128,8 @@ function u(t, o = false) {
|
|
|
26128
26128
|
n = e.lstatSync(i);
|
|
26129
26129
|
}
|
|
26130
26130
|
if (!n.isDirectory() || n.uid !== 0 && n.uid !== s) throw new Error();
|
|
26131
|
-
let
|
|
26132
|
-
if (n.mode & 18 && !
|
|
26131
|
+
let a = n.uid === 0 && (n.mode & 512) !== 0;
|
|
26132
|
+
if (n.mode & 18 && !a) throw new Error();
|
|
26133
26133
|
if (l === r.length - 1 && (n.uid !== s || (n.mode & 4095) !== 448)) throw new Error();
|
|
26134
26134
|
return `${n.dev}:${n.ino}:${n.uid}:${n.gid}:${n.mode}`;
|
|
26135
26135
|
}).join("|");
|
|
@@ -26137,27 +26137,27 @@ function u(t, o = false) {
|
|
|
26137
26137
|
function m(t, o = 65536, s = false) {
|
|
26138
26138
|
let r;
|
|
26139
26139
|
try {
|
|
26140
|
-
let i = u(t), l = process.geteuid(), n = (
|
|
26141
|
-
if (!
|
|
26142
|
-
return `${
|
|
26143
|
-
},
|
|
26140
|
+
let i = u(t), l = process.geteuid(), n = (c) => {
|
|
26141
|
+
if (!c.isFile() || c.uid !== l || (c.mode & 4095) !== 384 || c.size < 1 || c.size > o) throw new Error();
|
|
26142
|
+
return `${c.dev}:${c.ino}:${c.uid}:${c.gid}:${c.mode}:${c.size}:${c.mtimeMs}:${c.ctimeMs}`;
|
|
26143
|
+
}, a = n(e.lstatSync(t));
|
|
26144
26144
|
r = e.openSync(t, e.constants.O_RDONLY | e.constants.O_NOFOLLOW | e.constants.O_NONBLOCK);
|
|
26145
26145
|
let d2 = e.fstatSync(r);
|
|
26146
|
-
if (n(d2) !==
|
|
26146
|
+
if (n(d2) !== a || u(t) !== i || n(e.lstatSync(t)) !== a) throw new Error();
|
|
26147
26147
|
let f = Buffer.alloc(d2.size);
|
|
26148
|
-
if (e.readSync(r, f, 0, f.length, 0) !== f.length || n(e.fstatSync(r)) !==
|
|
26148
|
+
if (e.readSync(r, f, 0, f.length, 0) !== f.length || n(e.fstatSync(r)) !== a || u(t) !== i || n(e.lstatSync(t)) !== a) throw new Error();
|
|
26149
26149
|
if (s) {
|
|
26150
26150
|
e.fsyncSync(r);
|
|
26151
|
-
for (let
|
|
26152
|
-
let
|
|
26151
|
+
for (let c = y(t); ; c = y(c)) {
|
|
26152
|
+
let g = e.openSync(c, e.constants.O_RDONLY | e.constants.O_DIRECTORY | e.constants.O_NOFOLLOW);
|
|
26153
26153
|
try {
|
|
26154
|
-
e.fsyncSync(
|
|
26154
|
+
e.fsyncSync(g);
|
|
26155
26155
|
} finally {
|
|
26156
|
-
e.closeSync(
|
|
26156
|
+
e.closeSync(g);
|
|
26157
26157
|
}
|
|
26158
|
-
if (
|
|
26158
|
+
if (c === y(c)) break;
|
|
26159
26159
|
}
|
|
26160
|
-
if (u(t) !== i || n(e.lstatSync(t)) !==
|
|
26160
|
+
if (u(t) !== i || n(e.lstatSync(t)) !== a) throw new Error();
|
|
26161
26161
|
}
|
|
26162
26162
|
return f;
|
|
26163
26163
|
} catch {
|
|
@@ -26166,55 +26166,55 @@ function m(t, o = 65536, s = false) {
|
|
|
26166
26166
|
r !== void 0 && e.closeSync(r);
|
|
26167
26167
|
}
|
|
26168
26168
|
}
|
|
26169
|
-
function
|
|
26169
|
+
function w(t, o) {
|
|
26170
26170
|
let s, r;
|
|
26171
26171
|
try {
|
|
26172
26172
|
try {
|
|
26173
|
-
return e.lstatSync(t), { token:
|
|
26173
|
+
return e.lstatSync(t), { token: S(t), source: "file" };
|
|
26174
26174
|
} catch (f) {
|
|
26175
26175
|
if (f.code !== "ENOENT") throw f;
|
|
26176
26176
|
}
|
|
26177
26177
|
if (!o) return null;
|
|
26178
|
-
let i = u(t, true), l =
|
|
26178
|
+
let i = u(t, true), l = O(32).toString("hex"), n = `${t}.${O(16).toString("hex")}.tmp`;
|
|
26179
26179
|
if (r = e.openSync(n, e.constants.O_WRONLY | e.constants.O_CREAT | e.constants.O_EXCL | e.constants.O_NOFOLLOW, 384), s = n, e.fchmodSync(r, 384), e.writeFileSync(r, `${l}
|
|
26180
26180
|
`), e.fsyncSync(r), e.closeSync(r), r = void 0, u(t) !== i) throw new Error();
|
|
26181
|
-
let
|
|
26181
|
+
let a = "generated";
|
|
26182
26182
|
try {
|
|
26183
26183
|
e.linkSync(s, t);
|
|
26184
26184
|
} catch (f) {
|
|
26185
26185
|
if (f.code !== "EEXIST") throw f;
|
|
26186
|
-
|
|
26186
|
+
a = "file";
|
|
26187
26187
|
}
|
|
26188
26188
|
e.unlinkSync(s), s = void 0;
|
|
26189
|
-
let d2 = e.openSync(
|
|
26189
|
+
let d2 = e.openSync(y(t), e.constants.O_RDONLY | e.constants.O_DIRECTORY | e.constants.O_NOFOLLOW);
|
|
26190
26190
|
try {
|
|
26191
26191
|
e.fsyncSync(d2);
|
|
26192
26192
|
} finally {
|
|
26193
26193
|
e.closeSync(d2);
|
|
26194
26194
|
}
|
|
26195
|
-
return { token:
|
|
26195
|
+
return { token: S(t), source: a };
|
|
26196
26196
|
} catch {
|
|
26197
26197
|
throw new Error("Credential publication or reuse failed; no in-memory fallback or automatic repair");
|
|
26198
26198
|
} finally {
|
|
26199
26199
|
r !== void 0 && e.closeSync(r), s !== void 0 && e.unlinkSync(s);
|
|
26200
26200
|
}
|
|
26201
26201
|
}
|
|
26202
|
-
function
|
|
26202
|
+
function S(t) {
|
|
26203
26203
|
let o = m(t, 4096).toString("utf8");
|
|
26204
26204
|
if (!/^[\x21-\x7e]+(?:\r?\n)?$/.test(o)) throw new Error("Credential file contains an invalid token");
|
|
26205
26205
|
return o.trimEnd();
|
|
26206
26206
|
}
|
|
26207
|
-
var
|
|
26208
|
-
var
|
|
26209
|
-
var
|
|
26207
|
+
var L = 100 * 1024 * 1024;
|
|
26208
|
+
var K = { brokerUrl: "wss://broker1.ours.network", port: 3050, stateDir: E(T(), ".ours"), gcIntervalMs: 36e5, historyMaxBytes: L, apiVisibility: "owner", apiAuthMode: "legacy" };
|
|
26209
|
+
var $ = "daemon-token";
|
|
26210
26210
|
|
|
26211
|
-
// node_modules/@ours.network/sdk/dist/chunk-
|
|
26212
|
-
import { homedir as
|
|
26213
|
-
import { isAbsolute as
|
|
26214
|
-
import { randomBytes as
|
|
26215
|
-
import { readFileSync as
|
|
26216
|
-
import { homedir as
|
|
26217
|
-
import { join as
|
|
26211
|
+
// node_modules/@ours.network/sdk/dist/chunk-XMDIJ6DK.js
|
|
26212
|
+
import { homedir as Te } from "node:os";
|
|
26213
|
+
import { isAbsolute as Oe, join as Se, resolve as ue } from "node:path";
|
|
26214
|
+
import { randomBytes as W } from "node:crypto";
|
|
26215
|
+
import { readFileSync as xe } from "node:fs";
|
|
26216
|
+
import { homedir as Ne } from "node:os";
|
|
26217
|
+
import { join as J, resolve as H } from "node:path";
|
|
26218
26218
|
var d = class extends Error {
|
|
26219
26219
|
constructor(n, r, i) {
|
|
26220
26220
|
super(r);
|
|
@@ -26223,8 +26223,8 @@ var d = class extends Error {
|
|
|
26223
26223
|
this.name = "OursError";
|
|
26224
26224
|
}
|
|
26225
26225
|
};
|
|
26226
|
-
var
|
|
26227
|
-
function
|
|
26226
|
+
var V = () => new d("INVALID_OBSERVATION", "Terminal observation must match this external owner instance and contain valid process evidence.");
|
|
26227
|
+
function w2(e2) {
|
|
26228
26228
|
if (typeof e2 != "string" || /[\s\\#]/.test(e2) || !/^https?:\/\//i.test(e2)) throw new Error("Daemon endpoint must be an HTTP or HTTPS URL without credentials or fragment");
|
|
26229
26229
|
let t;
|
|
26230
26230
|
try {
|
|
@@ -26235,7 +26235,7 @@ function y(e2) {
|
|
|
26235
26235
|
if (t.username || t.password || t.hash) throw new Error("Daemon endpoint cannot contain credentials or fragment");
|
|
26236
26236
|
return t.origin + t.pathname.replace(/\/+$/, "") + t.search;
|
|
26237
26237
|
}
|
|
26238
|
-
function
|
|
26238
|
+
function p(e2, t) {
|
|
26239
26239
|
if (!t.startsWith("/") || t.startsWith("//") || t.includes("#")) throw new Error("Invalid daemon route");
|
|
26240
26240
|
let n = new URL(e2), r = new URL(t, "http://daemon.invalid");
|
|
26241
26241
|
if (n.pathname = n.pathname.replace(/\/+$/, "") + r.pathname, r.search) {
|
|
@@ -26244,7 +26244,7 @@ function u2(e2, t) {
|
|
|
26244
26244
|
}
|
|
26245
26245
|
return n.href;
|
|
26246
26246
|
}
|
|
26247
|
-
function
|
|
26247
|
+
function D(e2) {
|
|
26248
26248
|
try {
|
|
26249
26249
|
let t = new URL(e2);
|
|
26250
26250
|
return t.origin + t.pathname;
|
|
@@ -26252,7 +26252,7 @@ function R2(e2) {
|
|
|
26252
26252
|
return "<invalid daemon endpoint>";
|
|
26253
26253
|
}
|
|
26254
26254
|
}
|
|
26255
|
-
async function
|
|
26255
|
+
async function C(e2) {
|
|
26256
26256
|
let t = e2.body?.getReader();
|
|
26257
26257
|
if (!t) throw new Error("Missing daemon response");
|
|
26258
26258
|
let n = [], r = 0;
|
|
@@ -26269,38 +26269,38 @@ async function F(e2) {
|
|
|
26269
26269
|
});
|
|
26270
26270
|
}
|
|
26271
26271
|
}
|
|
26272
|
-
function
|
|
26272
|
+
function L2(e2, t) {
|
|
26273
26273
|
let n = (o) => o !== null && typeof o == "object" && !Array.isArray(o), r = (o, s) => Object.keys(o).length === s.length && Object.keys(o).every((a) => s.includes(a)), i = (o) => typeof o == "string" && o.trim().length > 0 && o.length <= 1024;
|
|
26274
|
-
if (!n(e2) || !r(e2, ["ownerInstanceId", "reason", "observedAt", "process"]) || !t || e2.ownerInstanceId !== t || e2.reason !== "process-exit" && e2.reason !== "session-end" || !Number.isSafeInteger(e2.observedAt) || Number(e2.observedAt) < 0 || !n(e2.process) || !r(e2.process, ["pid", "bootId", "startId", "domain"]) || !Number.isSafeInteger(e2.process.pid) || Number(e2.process.pid) < 1 || !i(e2.process.bootId) || !i(e2.process.startId) || !i(e2.process.domain)) throw
|
|
26274
|
+
if (!n(e2) || !r(e2, ["ownerInstanceId", "reason", "observedAt", "process"]) || !t || e2.ownerInstanceId !== t || e2.reason !== "process-exit" && e2.reason !== "session-end" || !Number.isSafeInteger(e2.observedAt) || Number(e2.observedAt) < 0 || !n(e2.process) || !r(e2.process, ["pid", "bootId", "startId", "domain"]) || !Number.isSafeInteger(e2.process.pid) || Number(e2.process.pid) < 1 || !i(e2.process.bootId) || !i(e2.process.startId) || !i(e2.process.domain)) throw V();
|
|
26275
26275
|
}
|
|
26276
|
-
var
|
|
26277
|
-
var
|
|
26278
|
-
function
|
|
26279
|
-
if (!
|
|
26276
|
+
var I2 = (e2) => typeof e2 == "string" && e2.length > 0;
|
|
26277
|
+
var G = (e2) => ({ event: "sync_required", reason: "legacy_or_malformed_event", source_event: e2 });
|
|
26278
|
+
function ce(e2) {
|
|
26279
|
+
if (!I2(e2.event)) return G("unknown");
|
|
26280
26280
|
if (e2.event === "contact_removed") {
|
|
26281
26281
|
let t = /^[0-9A-F]{64}$/;
|
|
26282
|
-
return typeof e2.cid != "string" || !t.test(e2.cid) || typeof e2.identity_cid != "string" || !t.test(e2.identity_cid) || e2.by !== "local" && e2.by !== "peer" ?
|
|
26282
|
+
return typeof e2.cid != "string" || !t.test(e2.cid) || typeof e2.identity_cid != "string" || !t.test(e2.identity_cid) || e2.by !== "local" && e2.by !== "peer" ? G("contact_removed") : { event: "contact_removed", identity_cid: e2.identity_cid, cid: e2.cid, by: e2.by };
|
|
26283
26283
|
}
|
|
26284
|
-
if (e2.event === "message_received") return !
|
|
26284
|
+
if (e2.event === "message_received") return !I2(e2.sender_id) || !I2(e2.sender_name) || !I2(e2.msg_id) || !I2(e2.wire_id) || !I2(e2.date) ? G("message_received") : { event: "message_received", sender_id: e2.sender_id, sender_name: e2.sender_name, from: I2(e2.from) ? e2.from : e2.sender_name, msg_id: e2.msg_id, wire_id: e2.wire_id, date: e2.date };
|
|
26285
26285
|
if (e2.event === "receipt_received") {
|
|
26286
26286
|
let t = e2.kind, n = e2.wire_ids;
|
|
26287
|
-
return !
|
|
26287
|
+
return !I2(e2.sender_id) || t !== "delivered" && t !== "read" || !Array.isArray(n) || n.length === 0 || !n.every(I2) ? G("receipt_received") : { event: "receipt_received", sender_id: e2.sender_id, kind: t, wire_ids: [...n], date: I2(e2.date) ? e2.date : (/* @__PURE__ */ new Date()).toISOString() };
|
|
26288
26288
|
}
|
|
26289
26289
|
return e2;
|
|
26290
26290
|
}
|
|
26291
|
-
var
|
|
26291
|
+
var _e = { event: () => {
|
|
26292
26292
|
}, notification: () => {
|
|
26293
26293
|
} };
|
|
26294
|
-
var
|
|
26295
|
-
function
|
|
26294
|
+
var Ht = { ..._e };
|
|
26295
|
+
function z(e2, t = /* @__PURE__ */ new Set()) {
|
|
26296
26296
|
if (e2 === null || typeof e2 == "string" || typeof e2 == "boolean") return true;
|
|
26297
26297
|
if (typeof e2 == "number") return Number.isFinite(e2);
|
|
26298
26298
|
if (typeof e2 != "object" || t.has(e2)) return false;
|
|
26299
26299
|
t.add(e2);
|
|
26300
|
-
let n = Array.isArray(e2) ? e2.every((r) =>
|
|
26300
|
+
let n = Array.isArray(e2) ? e2.every((r) => z(r, t)) : Object.getPrototypeOf(e2) === Object.prototype && Object.values(e2).every((r) => z(r, t));
|
|
26301
26301
|
return t.delete(e2), n;
|
|
26302
26302
|
}
|
|
26303
|
-
var
|
|
26303
|
+
var F = class {
|
|
26304
26304
|
base;
|
|
26305
26305
|
leaseToken;
|
|
26306
26306
|
sessionMode;
|
|
@@ -26308,7 +26308,7 @@ var x = class {
|
|
|
26308
26308
|
explicitApiToken;
|
|
26309
26309
|
credentialPath;
|
|
26310
26310
|
get apiToken() {
|
|
26311
|
-
return this.credentialPath === void 0 ? this.explicitApiToken :
|
|
26311
|
+
return this.credentialPath === void 0 ? this.explicitApiToken : S(this.credentialPath);
|
|
26312
26312
|
}
|
|
26313
26313
|
fetchImpl;
|
|
26314
26314
|
commandHandlers = /* @__PURE__ */ new Map();
|
|
@@ -26316,12 +26316,12 @@ var x = class {
|
|
|
26316
26316
|
if (t.credentialPath !== void 0 && t.apiToken !== void 0) throw new Error("Credential path cannot be combined with an explicit API token");
|
|
26317
26317
|
if ("serverCertificate" in t && t.serverCertificate !== void 0) throw new Error("Custom serverCertificate is not supported; HTTPS uses Node certificate trust, including NODE_EXTRA_CA_CERTS");
|
|
26318
26318
|
if (new URL(t.url).protocol !== "http:" && new URL(t.url).protocol !== "https:") throw new Error("Client requires an HTTP or HTTPS daemon endpoint");
|
|
26319
|
-
if (this.base =
|
|
26319
|
+
if (this.base = w2(t.url), this.sessionMode = t.sessionMode ?? "local", this.sessionMode !== "local" && this.sessionMode !== "external") throw new Error("Invalid sessionMode");
|
|
26320
26320
|
if (this.sessionMode === "external" && !t.leaseToken) throw new Error("External ownership requires a stable caller-supplied leaseToken");
|
|
26321
26321
|
this.leaseToken = t.leaseToken, this.clientPid = t.clientPid ?? process.pid, this.explicitApiToken = t.apiToken, this.credentialPath = t.credentialPath;
|
|
26322
26322
|
let n = t.fetch ?? globalThis.fetch;
|
|
26323
26323
|
this.fetchImpl = (r, i) => {
|
|
26324
|
-
let o = String(r) ===
|
|
26324
|
+
let o = String(r) === p(this.base, "/api/v1/releaseLease"), s = [i?.signal, o ? t.requestSignal ? AbortSignal.timeout(5e3) : void 0 : t.requestSignal].filter((a) => a != null);
|
|
26325
26325
|
return n(r, { ...i, ...s.length ? { signal: AbortSignal.any(s) } : {} });
|
|
26326
26326
|
};
|
|
26327
26327
|
}
|
|
@@ -26332,17 +26332,17 @@ var x = class {
|
|
|
26332
26332
|
return { "x-ours-session-mode": this.sessionMode, "x-ours-lease-token": this.leaseToken, "x-ours-client-pid": String(this.clientPid), ...n ? { "x-ours-api-token": n } : {}, ...t };
|
|
26333
26333
|
}
|
|
26334
26334
|
async post(t, n, r = false) {
|
|
26335
|
-
let i = await this.fetchImpl(
|
|
26335
|
+
let i = await this.fetchImpl(p(this.base, `/api/v1/${t}`), { redirect: "error", method: "POST", headers: this.headers({ "content-type": "application/json" }), body: JSON.stringify(n ?? {}), ...r ? { signal: AbortSignal.timeout(5e3) } : {} }), o;
|
|
26336
26336
|
try {
|
|
26337
|
-
r ? o = await
|
|
26337
|
+
r ? o = await C(i) : o = await i.json();
|
|
26338
26338
|
} catch {
|
|
26339
26339
|
throw new Error(`${t}: the daemon returned a non-JSON response (HTTP ${i.status})`);
|
|
26340
26340
|
}
|
|
26341
26341
|
if (o && typeof o == "object" && !Array.isArray(o) && "error" in o) {
|
|
26342
26342
|
let s = o.error, a = s !== null && typeof s == "object" && "code" in s && "message" in s;
|
|
26343
26343
|
if (i.status === 400 && a) {
|
|
26344
|
-
let { code: l, message:
|
|
26345
|
-
throw new d(l,
|
|
26344
|
+
let { code: l, message: f, details: m2 } = s;
|
|
26345
|
+
throw new d(l, f, m2);
|
|
26346
26346
|
}
|
|
26347
26347
|
let c = a ? s.message : String(s);
|
|
26348
26348
|
throw new Error(`${t}: ${c} (HTTP ${i.status})`);
|
|
@@ -26351,7 +26351,7 @@ var x = class {
|
|
|
26351
26351
|
return o;
|
|
26352
26352
|
}
|
|
26353
26353
|
async get(t, n) {
|
|
26354
|
-
let r = await this.fetchImpl(
|
|
26354
|
+
let r = await this.fetchImpl(p(this.base, t), { redirect: "error", headers: n ? this.headers() : {} }), i;
|
|
26355
26355
|
try {
|
|
26356
26356
|
i = await r.json();
|
|
26357
26357
|
} catch {
|
|
@@ -26361,6 +26361,63 @@ var x = class {
|
|
|
26361
26361
|
if (!r.ok) throw new Error(`GET ${t}: the daemon returned HTTP ${r.status} with no error field`);
|
|
26362
26362
|
return i;
|
|
26363
26363
|
}
|
|
26364
|
+
async resourcePosition(t, n) {
|
|
26365
|
+
let r = await this.fetchImpl(p(this.base, `/identities/${encodeURIComponent(t)}/resource-events?position=1`), { redirect: "error", headers: this.headers(), signal: n.signal });
|
|
26366
|
+
if (!r.ok) throw new U(r.status);
|
|
26367
|
+
let i = await C(r);
|
|
26368
|
+
return le(i), i;
|
|
26369
|
+
}
|
|
26370
|
+
async *resourceEvents(t, n) {
|
|
26371
|
+
if (n.expectedGeneration === void 0 != (n.after === void 0) || n.after !== void 0 && (!Number.isSafeInteger(n.after) || n.after < 0)) throw new Error("expectedGeneration and a nonnegative safe after position are required together");
|
|
26372
|
+
let r = new AbortController(), i = AbortSignal.any([n.signal, r.signal]), o, s = 0, a = (y2) => {
|
|
26373
|
+
s = Date.now() + y2, clearTimeout(o), o = setTimeout(() => r.abort(new Error("Resource source coverage deadline expired")), y2), o.unref?.();
|
|
26374
|
+
}, c = () => {
|
|
26375
|
+
if (i.aborted) throw i.reason;
|
|
26376
|
+
if (Date.now() >= s) throw new Error("Resource source coverage deadline expired");
|
|
26377
|
+
}, l, f, m2 = () => (l && !f && (f = l.cancel(i.reason).catch(() => {
|
|
26378
|
+
})), f), g = () => {
|
|
26379
|
+
m2();
|
|
26380
|
+
};
|
|
26381
|
+
try {
|
|
26382
|
+
a(1e4);
|
|
26383
|
+
let y2 = new URLSearchParams();
|
|
26384
|
+
n.after !== void 0 && (y2.set("after", String(n.after)), y2.set("expectedGeneration", n.expectedGeneration));
|
|
26385
|
+
let h = await this.fetchImpl(p(this.base, `/identities/${encodeURIComponent(t)}/resource-events?${y2}`), { redirect: "error", headers: this.headers({ accept: "text/event-stream" }), signal: i });
|
|
26386
|
+
if (i.aborted) throw h.body?.cancel(), i.reason;
|
|
26387
|
+
if (!h.ok) throw new U(h.status);
|
|
26388
|
+
if (!h.body || !h.headers.get("content-type")?.startsWith("text/event-stream")) throw new Error("Invalid resource stream response");
|
|
26389
|
+
l = h.body.getReader(), i.addEventListener("abort", g, { once: true }), i.aborted && g();
|
|
26390
|
+
let T2 = new TextDecoder("utf-8", { fatal: true }), v2 = "", b2 = 0, _ = false, R2, O2 = -1;
|
|
26391
|
+
for (; ; ) {
|
|
26392
|
+
let { value: ie, done: be } = await l.read();
|
|
26393
|
+
if (c(), be) throw new Error("Resource stream ended before disposal");
|
|
26394
|
+
if (b2 += ie.byteLength, b2 > 8 * 1024 * 1024) throw new Error("Resource live input exceeds limit");
|
|
26395
|
+
for (v2 += T2.decode(ie, { stream: true }); ; ) {
|
|
26396
|
+
c();
|
|
26397
|
+
let N = /\r?\n\r?\n/.exec(v2);
|
|
26398
|
+
if (!N) break;
|
|
26399
|
+
let j = v2.slice(0, N.index);
|
|
26400
|
+
if (v2 = v2.slice(N.index + N[0].length), b2 -= Buffer.byteLength(j) + Buffer.byteLength(N[0]), Buffer.byteLength(j) > 512 * 1024) throw new Error("Resource frame exceeds limit");
|
|
26401
|
+
let oe = j.split(/\r?\n/).filter((k) => k.startsWith("data:")).map((k) => k.slice(5).trimStart()).join(`
|
|
26402
|
+
`);
|
|
26403
|
+
if (!oe) continue;
|
|
26404
|
+
let A2 = JSON.parse(oe);
|
|
26405
|
+
if (c(), j.split(/\r?\n/).some((k) => k === "event: auth_required")) throw new U(401);
|
|
26406
|
+
le(A2);
|
|
26407
|
+
let K2 = A2.kind;
|
|
26408
|
+
if (!["ready", "committed", "coverage", "resync"].includes(K2)) throw new Error("Invalid resource frame kind");
|
|
26409
|
+
if (R2 !== void 0 && (A2.producerGeneration !== R2 || A2.position < O2)) throw new Error("Resource stream continuity changed");
|
|
26410
|
+
if (R2 = A2.producerGeneration, O2 = A2.position, K2 === "ready") _ = true, a(45e3);
|
|
26411
|
+
else if (_) a(45e3);
|
|
26412
|
+
else if (K2 !== "resync") throw new Error("Resource mutation before ready");
|
|
26413
|
+
yield A2, c();
|
|
26414
|
+
}
|
|
26415
|
+
if (Buffer.byteLength(v2) > 512 * 1024) throw new Error("Resource frame exceeds limit");
|
|
26416
|
+
}
|
|
26417
|
+
} finally {
|
|
26418
|
+
clearTimeout(o), r.abort(), i.removeEventListener("abort", g), await m2(), l?.releaseLock();
|
|
26419
|
+
}
|
|
26420
|
+
}
|
|
26364
26421
|
createIdentity(t) {
|
|
26365
26422
|
return this.post("createIdentity", t);
|
|
26366
26423
|
}
|
|
@@ -26391,8 +26448,8 @@ var x = class {
|
|
|
26391
26448
|
async releaseLease(t = {}) {
|
|
26392
26449
|
let n = t?.observation;
|
|
26393
26450
|
if (n !== void 0) {
|
|
26394
|
-
if (this.sessionMode !== "external") throw
|
|
26395
|
-
|
|
26451
|
+
if (this.sessionMode !== "external") throw V();
|
|
26452
|
+
L2(n, this.leaseToken);
|
|
26396
26453
|
}
|
|
26397
26454
|
let r = await this.post("releaseLease", t, n !== void 0);
|
|
26398
26455
|
if (n !== void 0) {
|
|
@@ -26487,11 +26544,11 @@ var x = class {
|
|
|
26487
26544
|
try {
|
|
26488
26545
|
let c = JSON.parse(s.body);
|
|
26489
26546
|
if (!c || typeof c != "object" || Array.isArray(c) || Object.keys(c).length !== 2 || typeof c.command != "string" || !("arguments" in c)) throw new Error("invalid command payload");
|
|
26490
|
-
let l = c,
|
|
26491
|
-
if (!
|
|
26492
|
-
let
|
|
26493
|
-
if (!
|
|
26494
|
-
a = { ok: true, result:
|
|
26547
|
+
let l = c, f = l.command, m2 = this.commandHandlers.get(f);
|
|
26548
|
+
if (!m2) throw new Error("handler not registered");
|
|
26549
|
+
let g = Object.freeze({ sender_cid: s.from.id, sender_name: s.from.name, request_wire_id: s.wire_id }), y2 = await m2(l.arguments, g);
|
|
26550
|
+
if (!z(y2)) throw new Error("handler returned a non-JSON value");
|
|
26551
|
+
a = { ok: true, result: y2 };
|
|
26495
26552
|
} catch {
|
|
26496
26553
|
}
|
|
26497
26554
|
await this.post("sendCommandResult", { contact: s.from.id, reply_to_wire_id: s.wire_id, outcome: a });
|
|
@@ -26538,7 +26595,7 @@ var x = class {
|
|
|
26538
26595
|
return this.get("/history-storage", true);
|
|
26539
26596
|
}
|
|
26540
26597
|
async readNotificationPage(t, n = {}) {
|
|
26541
|
-
let r = "/identities/" + encodeURIComponent(t) + "/notifications", i = n.kinds?.length ? "&kinds=" + encodeURIComponent(n.kinds.join(",")) : "", o = n.requestTimeoutMs === void 0 ? n.signal : AbortSignal.any([...n.signal ? [n.signal] : [], AbortSignal.timeout(n.requestTimeoutMs)]), s = await this.fetchImpl(
|
|
26598
|
+
let r = "/identities/" + encodeURIComponent(t) + "/notifications", i = n.kinds?.length ? "&kinds=" + encodeURIComponent(n.kinds.join(",")) : "", o = n.requestTimeoutMs === void 0 ? n.signal : AbortSignal.any([...n.signal ? [n.signal] : [], AbortSignal.timeout(n.requestTimeoutMs)]), s = await this.fetchImpl(p(this.base, r + "?since=" + encodeURIComponent(String(n.since ?? "tip")) + i), { redirect: "error", headers: this.headers(), signal: o }), a;
|
|
26542
26599
|
try {
|
|
26543
26600
|
a = await s.json();
|
|
26544
26601
|
} catch {
|
|
@@ -26555,7 +26612,7 @@ var x = class {
|
|
|
26555
26612
|
for (; !n.signal?.aborted; ) {
|
|
26556
26613
|
let s;
|
|
26557
26614
|
try {
|
|
26558
|
-
let a = await this.fetchImpl(
|
|
26615
|
+
let a = await this.fetchImpl(p(this.base, `${i}?since=${r}${o}`), { redirect: "error", headers: this.headers(), signal: n.requestTimeoutMs === void 0 ? n.signal : AbortSignal.any([...n.signal ? [n.signal] : [], AbortSignal.timeout(n.requestTimeoutMs)]) });
|
|
26559
26616
|
try {
|
|
26560
26617
|
s = await a.json();
|
|
26561
26618
|
} catch {
|
|
@@ -26567,11 +26624,11 @@ var x = class {
|
|
|
26567
26624
|
}
|
|
26568
26625
|
if ("error" in s) throw new Error(`watchNotifications(${t}): ${s.error}`);
|
|
26569
26626
|
r = s.cursor;
|
|
26570
|
-
for (let a of s.events) yield
|
|
26627
|
+
for (let a of s.events) yield ce(a && typeof a == "object" ? a : {});
|
|
26571
26628
|
}
|
|
26572
26629
|
}
|
|
26573
26630
|
async fetchFile(t) {
|
|
26574
|
-
let n = await this.fetchImpl(
|
|
26631
|
+
let n = await this.fetchImpl(p(this.base, `/files/${encodeURIComponent(t)}`), { redirect: "error", headers: this.headers() });
|
|
26575
26632
|
if (!n.ok) {
|
|
26576
26633
|
let r = `HTTP ${n.status}`;
|
|
26577
26634
|
try {
|
|
@@ -26584,7 +26641,7 @@ var x = class {
|
|
|
26584
26641
|
return new Uint8Array(await n.arrayBuffer());
|
|
26585
26642
|
}
|
|
26586
26643
|
async openFile(t) {
|
|
26587
|
-
let n = await this.fetchImpl(
|
|
26644
|
+
let n = await this.fetchImpl(p(this.base, `/files/${encodeURIComponent(t)}`), { redirect: "error", headers: this.headers() });
|
|
26588
26645
|
if (!n.ok) {
|
|
26589
26646
|
let r = `HTTP ${n.status}`;
|
|
26590
26647
|
try {
|
|
@@ -26600,7 +26657,7 @@ var x = class {
|
|
|
26600
26657
|
async uploadFile(t, n) {
|
|
26601
26658
|
let r = t instanceof Uint8Array ? t.byteLength : n.size;
|
|
26602
26659
|
if (r === void 0) throw new Error("uploadFile: `size` is required when the body is a stream (the route needs Content-Length)");
|
|
26603
|
-
let i = await this.fetchImpl(
|
|
26660
|
+
let i = await this.fetchImpl(p(this.base, "/files/upload"), { redirect: "error", method: "POST", headers: { ...this.headers(), "x-ours-filename": encodeURIComponent(n.filename), "Content-Type": n.mime || "application/octet-stream", "Content-Length": String(r) }, body: t, ...t instanceof Uint8Array ? {} : { duplex: "half" } });
|
|
26604
26661
|
if (!i.ok) {
|
|
26605
26662
|
let o = `HTTP ${i.status}`;
|
|
26606
26663
|
try {
|
|
@@ -26613,21 +26670,33 @@ var x = class {
|
|
|
26613
26670
|
return await i.json();
|
|
26614
26671
|
}
|
|
26615
26672
|
};
|
|
26616
|
-
var
|
|
26673
|
+
var U = class extends Error {
|
|
26674
|
+
constructor(n) {
|
|
26675
|
+
super(`Resource stream HTTP ${n}${n === 401 ? ": unauthorized" : ""}`);
|
|
26676
|
+
this.status = n;
|
|
26677
|
+
this.name = "ResourceStreamError";
|
|
26678
|
+
}
|
|
26679
|
+
};
|
|
26680
|
+
function le(e2) {
|
|
26681
|
+
if (!e2 || typeof e2 != "object") throw new Error("Invalid resource source position");
|
|
26682
|
+
let t = e2;
|
|
26683
|
+
if (t.protocolVersion !== 1 || typeof t.producerGeneration != "string" || !t.producerGeneration || !Number.isSafeInteger(t.position) || t.position < 0) throw new Error("Invalid resource source position");
|
|
26684
|
+
}
|
|
26685
|
+
var x = class extends Error {
|
|
26617
26686
|
constructor(t) {
|
|
26618
26687
|
super(`Invalid gateway client profile: ${t}. Configure ~/.ours-client/profile.json with ours-install client; no local service fallback is permitted.`), this.name = "ClientProfileError";
|
|
26619
26688
|
}
|
|
26620
26689
|
};
|
|
26621
|
-
function
|
|
26690
|
+
function Re(e2 = process.env) {
|
|
26622
26691
|
if (e2.OURS_CONFIG !== void 0) {
|
|
26623
|
-
if (!e2.OURS_CONFIG.trim()) throw new
|
|
26624
|
-
return
|
|
26692
|
+
if (!e2.OURS_CONFIG.trim()) throw new x("OURS_CONFIG must name a client profile");
|
|
26693
|
+
return ue(e2.OURS_CONFIG);
|
|
26625
26694
|
}
|
|
26626
|
-
return
|
|
26695
|
+
return Se(e2.HOME || Te(), ".ours-client", "profile.json");
|
|
26627
26696
|
}
|
|
26628
|
-
function
|
|
26697
|
+
function Ae(e2) {
|
|
26629
26698
|
let t = (o) => {
|
|
26630
|
-
throw new
|
|
26699
|
+
throw new x(o);
|
|
26631
26700
|
};
|
|
26632
26701
|
if (!e2 || typeof e2 != "object" || Array.isArray(e2)) return t("expected a JSON object");
|
|
26633
26702
|
let n = e2;
|
|
@@ -26635,202 +26704,202 @@ function we(e2) {
|
|
|
26635
26704
|
if (typeof n.serverUrl != "string" || !n.serverUrl || /[\s\\?#]/.test(n.serverUrl)) return t("serverUrl must be an HTTP or HTTPS gateway base URL without credentials, query or fragment");
|
|
26636
26705
|
let r;
|
|
26637
26706
|
try {
|
|
26638
|
-
r =
|
|
26707
|
+
r = w2(n.serverUrl);
|
|
26639
26708
|
} catch {
|
|
26640
26709
|
return t("serverUrl must be a safe HTTP or HTTPS gateway base URL");
|
|
26641
26710
|
}
|
|
26642
26711
|
let i = r + "/daemon";
|
|
26643
26712
|
if (n.endpoint !== void 0) try {
|
|
26644
|
-
if (typeof n.endpoint != "string" ||
|
|
26713
|
+
if (typeof n.endpoint != "string" || w2(n.endpoint) !== i) return t("endpoint must equal serverUrl/daemon; remove stale endpoint overrides");
|
|
26645
26714
|
} catch {
|
|
26646
26715
|
return t("endpoint must equal serverUrl/daemon");
|
|
26647
26716
|
}
|
|
26648
|
-
return typeof n.expectedInstanceId != "string" || !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(n.expectedInstanceId) ? t("expectedInstanceId must be a lowercase UUID") : typeof n.credentialPath != "string" || !
|
|
26717
|
+
return typeof n.expectedInstanceId != "string" || !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(n.expectedInstanceId) ? t("expectedInstanceId must be a lowercase UUID") : typeof n.credentialPath != "string" || !Oe(n.credentialPath) || ue(n.credentialPath) !== n.credentialPath ? t("credentialPath must be an absolute normalized path") : Object.freeze({ serverUrl: r, endpoint: i, expectedInstanceId: n.expectedInstanceId, credentialPath: n.credentialPath });
|
|
26649
26718
|
}
|
|
26650
|
-
function
|
|
26651
|
-
let t =
|
|
26719
|
+
function pe(e2 = process.env) {
|
|
26720
|
+
let t = Re(e2), n;
|
|
26652
26721
|
try {
|
|
26653
26722
|
n = JSON.parse(m(t).toString("utf8"));
|
|
26654
26723
|
} catch {
|
|
26655
|
-
throw new
|
|
26724
|
+
throw new x("selected profile is missing, invalid JSON or unsafe; require a 0700 directory and a 0600 regular file");
|
|
26656
26725
|
}
|
|
26657
|
-
let r =
|
|
26658
|
-
if (["OURS_PORT", "OURS_STATE_DIR", "OURS_API_TOKEN", "OURS_DAEMON_ID", "OURS_DAEMON_URL", "OURS_DAEMON_CREDENTIAL_PATH"].some((o) => e2[o]?.trim())) throw new
|
|
26726
|
+
let r = Ae(n);
|
|
26727
|
+
if (["OURS_PORT", "OURS_STATE_DIR", "OURS_API_TOKEN", "OURS_DAEMON_ID", "OURS_DAEMON_URL", "OURS_DAEMON_CREDENTIAL_PATH"].some((o) => e2[o]?.trim())) throw new x("remove legacy OURS_PORT/STATE_DIR/API_TOKEN/DAEMON_ID/DAEMON_URL/DAEMON_CREDENTIAL_PATH environment selectors");
|
|
26659
26728
|
return Object.freeze({ ...r, configPath: t });
|
|
26660
26729
|
}
|
|
26661
|
-
var
|
|
26730
|
+
var u2 = class extends Error {
|
|
26662
26731
|
constructor(n, r) {
|
|
26663
26732
|
super(r);
|
|
26664
26733
|
this.code = n;
|
|
26665
26734
|
this.name = "DaemonSelectionError";
|
|
26666
26735
|
}
|
|
26667
26736
|
};
|
|
26668
|
-
var
|
|
26737
|
+
var Y = class extends u2 {
|
|
26669
26738
|
constructor(n, r, i = {}) {
|
|
26670
|
-
super("DAEMON_UNAVAILABLE", `no ours daemon is running at ${
|
|
26739
|
+
super("DAEMON_UNAVAILABLE", `no ours daemon is running at ${D(n)} for state directory ${JSON.stringify(r)}. Install the daemon with \`npm install --global @ours.network/daemon\`, then start the shared daemon with \`ours-daemon start\` or install/start its per-user service through \`ours-daemon install-service\`. SDK applications attach to the shared daemon and do not start an embedded daemon.`);
|
|
26671
26740
|
this.endpoint = n;
|
|
26672
26741
|
this.stateDir = r;
|
|
26673
26742
|
this.name = "DaemonUnavailableError", i.cause !== void 0 && (this.cause = i.cause);
|
|
26674
26743
|
}
|
|
26675
26744
|
};
|
|
26676
|
-
var
|
|
26677
|
-
var
|
|
26678
|
-
var
|
|
26679
|
-
var
|
|
26680
|
-
function
|
|
26745
|
+
var me = K.port;
|
|
26746
|
+
var X = $;
|
|
26747
|
+
var ke = ".ours";
|
|
26748
|
+
var Pe = ["explicit", "environment", "config-file"];
|
|
26749
|
+
function De(e2 = {}) {
|
|
26681
26750
|
let t = e2.env ?? process.env;
|
|
26682
|
-
if (t.OURS_TLS_CERT !== void 0 || t.OURS_TLS_KEY !== void 0) throw new
|
|
26683
|
-
if (e2.endpoint !== void 0 && new URL(e2.endpoint).protocol !== "http:" && new URL(e2.endpoint).protocol !== "https:") throw new
|
|
26684
|
-
let n = e2.readTextFile ?? ((
|
|
26685
|
-
if (i !== void 0) throw new
|
|
26751
|
+
if (t.OURS_TLS_CERT !== void 0 || t.OURS_TLS_KEY !== void 0) throw new u2("INCOHERENT_SELECTION", "Daemon TLS is not supported in V1; remove OURS_TLS_CERT/OURS_TLS_KEY and explicitly configure HTTP");
|
|
26752
|
+
if (e2.endpoint !== void 0 && new URL(e2.endpoint).protocol !== "http:" && new URL(e2.endpoint).protocol !== "https:") throw new u2("INCOHERENT_SELECTION", "Client requires an HTTP or HTTPS daemon endpoint");
|
|
26753
|
+
let n = e2.readTextFile ?? ((y2) => xe(y2, "utf8")), r = e2.homeDir ?? Ne(), i = M2(t, "OURS_INSTANCE");
|
|
26754
|
+
if (i !== void 0) throw new u2("INCOHERENT_SELECTION", `OURS_INSTANCE=${JSON.stringify(i)} is set, but named daemon instances are not implemented. Select the daemon with an explicit endpoint/port option or with OURS_PORT, and unset OURS_INSTANCE.`);
|
|
26686
26755
|
if (e2.stateDir !== void 0 && e2.expectStateDir !== void 0) {
|
|
26687
|
-
let
|
|
26688
|
-
if (
|
|
26756
|
+
let y2 = H(e2.stateDir), h = H(e2.expectStateDir);
|
|
26757
|
+
if (y2 !== h) throw new u2("INCOHERENT_SELECTION", `stateDir ${JSON.stringify(y2)} and expectStateDir ${JSON.stringify(h)} name different directories. The state directory decides which token is read; the expected one decides which daemon that token may be sent to. Reconcile them, or pass only one.`);
|
|
26689
26758
|
}
|
|
26690
|
-
let o =
|
|
26691
|
-
|
|
26692
|
-
let
|
|
26693
|
-
return { baseUrl:
|
|
26759
|
+
let o = $e(e2.configPath, M2(t, "OURS_CONFIG")), s = o ? Ue(o.value, n) : {}, a = fe(e2.port, Fe(M2(t, "OURS_PORT")), s.port, me), c = fe(e2.stateDir ?? e2.expectStateDir, M2(t, "OURS_STATE_DIR"), s.stateDir, J(r, ke)), l = { value: H(c.value), source: c.source }, f = e2.endpoint !== void 0 ? { value: w2(e2.endpoint), source: "explicit" } : { value: `http://127.0.0.1:${a.value}`, source: a.source }, m2 = M2(t, "OURS_API_TOKEN");
|
|
26760
|
+
Ce({ endpointSelected: e2.endpoint !== void 0 || a.source !== "default", endpointSource: f.source, stateDirIntentional: Pe.includes(l.source), stateDirSource: l.source, hasExplicitToken: e2.token !== void 0 && e2.token !== "", hasEnvToken: m2 !== void 0, requireExplicitSelection: e2.requireExplicitSelection === true, portSource: a.source });
|
|
26761
|
+
let g = Le(e2.token, m2, s, l, e2.readTextFile);
|
|
26762
|
+
return { baseUrl: f, port: a, stateDir: l, expectStateDir: e2.expectStateDir !== void 0 ? H(e2.expectStateDir) : l.value, ...g ? { token: g } : {}, ...o ? { configPath: o } : {} };
|
|
26694
26763
|
}
|
|
26695
|
-
function
|
|
26764
|
+
function un(e2) {
|
|
26696
26765
|
return { baseUrl: e2.baseUrl.value, baseUrlSource: e2.baseUrl.source, port: e2.port.value, portSource: e2.port.source, stateDir: e2.stateDir.value, stateDirSource: e2.stateDir.source, expectStateDir: e2.expectStateDir, tokenSource: e2.token?.source ?? "none", configPath: e2.configPath?.value ?? null };
|
|
26697
26766
|
}
|
|
26698
|
-
function
|
|
26767
|
+
function Ce(e2) {
|
|
26699
26768
|
if (e2.requireExplicitSelection) {
|
|
26700
|
-
if (e2.endpointSource === "default" && e2.portSource === "default") throw
|
|
26701
|
-
if (!e2.stateDirIntentional) throw
|
|
26769
|
+
if (e2.endpointSource === "default" && e2.portSource === "default") throw $2(`requireExplicitSelection is set, but no daemon was selected. Pass endpoint/port, set OURS_PORT, or point OURS_CONFIG at a config file. Refusing the built-in default 127.0.0.1:${me}.`);
|
|
26770
|
+
if (!e2.stateDirIntentional) throw $2("requireExplicitSelection is set, but the state directory is the built-in default. Every auth-affecting field must be chosen deliberately: pass stateDir or expectStateDir, set OURS_STATE_DIR, or name a config file. Refusing before reading any token or opening any socket.");
|
|
26702
26771
|
}
|
|
26703
|
-
if (e2.endpointSelected && !e2.stateDirIntentional) throw
|
|
26704
|
-
if (e2.hasEnvToken && !e2.stateDirIntentional) throw
|
|
26705
|
-
if (e2.hasExplicitToken && !e2.stateDirIntentional) throw
|
|
26772
|
+
if (e2.endpointSelected && !e2.stateDirIntentional) throw $2(`the endpoint was selected (source: ${e2.endpointSource}) but the state directory is the built-in default. A daemon's API token belongs to one state directory, so reading the default token and sending it to a separately chosen endpoint would disclose a credential to it. Select the state directory too: stateDir, expectStateDir, OURS_STATE_DIR, or one config file. An explicit token alone is not enough \u2014 without an expected state directory there is nothing to assert the endpoint against before the token is sent.`);
|
|
26773
|
+
if (e2.hasEnvToken && !e2.stateDirIntentional) throw $2("OURS_API_TOKEN is set, but the state directory is the built-in default. An environment token is process-wide and authenticates to every daemon it is offered to, so it requires an explicitly expected state directory: pass stateDir or expectStateDir, or set OURS_STATE_DIR.");
|
|
26774
|
+
if (e2.hasExplicitToken && !e2.stateDirIntentional) throw $2("an explicit token was given, but the state directory is the built-in default, so there would be nothing to assert the daemon against before the token is sent. Pass expectStateDir (or stateDir) naming the state directory that token belongs to.");
|
|
26706
26775
|
}
|
|
26707
|
-
function
|
|
26708
|
-
return new
|
|
26776
|
+
function $2(e2) {
|
|
26777
|
+
return new u2("INCOHERENT_SELECTION", e2);
|
|
26709
26778
|
}
|
|
26710
|
-
function
|
|
26779
|
+
function Le(e2, t, n, r, i) {
|
|
26711
26780
|
if (e2 !== void 0 && e2 !== "") return { value: e2, source: "explicit" };
|
|
26712
26781
|
if (t !== void 0) return { value: t, source: "environment" };
|
|
26713
26782
|
let o = n.apiToken?.trim();
|
|
26714
26783
|
if (o) return { value: o, source: "config-file" };
|
|
26715
26784
|
if (i === void 0) {
|
|
26716
|
-
let s =
|
|
26785
|
+
let s = w(J(r.value, X), false);
|
|
26717
26786
|
return s ? { value: s.token, source: "token-file" } : void 0;
|
|
26718
26787
|
}
|
|
26719
26788
|
try {
|
|
26720
|
-
let s = i(
|
|
26789
|
+
let s = i(J(r.value, X)).trim();
|
|
26721
26790
|
if (s) return { value: s, source: "token-file" };
|
|
26722
26791
|
} catch {
|
|
26723
26792
|
}
|
|
26724
26793
|
}
|
|
26725
|
-
function
|
|
26794
|
+
function Ue(e2, t) {
|
|
26726
26795
|
let n;
|
|
26727
26796
|
try {
|
|
26728
26797
|
n = t(e2);
|
|
26729
26798
|
} catch {
|
|
26730
|
-
throw new
|
|
26799
|
+
throw new u2("CONFIG_UNREADABLE", `the daemon config file ${JSON.stringify(e2)} could not be read.`);
|
|
26731
26800
|
}
|
|
26732
26801
|
let r;
|
|
26733
26802
|
try {
|
|
26734
26803
|
r = JSON.parse(n);
|
|
26735
26804
|
} catch {
|
|
26736
|
-
throw new
|
|
26805
|
+
throw new u2("CONFIG_INVALID", `the daemon config file ${JSON.stringify(e2)} is not valid JSON.`);
|
|
26737
26806
|
}
|
|
26738
|
-
if (r === null || typeof r != "object" || Array.isArray(r)) throw new
|
|
26807
|
+
if (r === null || typeof r != "object" || Array.isArray(r)) throw new u2("CONFIG_INVALID", `the daemon config file ${JSON.stringify(e2)} is not a JSON object.`);
|
|
26739
26808
|
let i = r, o = {}, s = i.port;
|
|
26740
26809
|
if (s !== void 0) {
|
|
26741
|
-
if (typeof s != "number" || !Number.isInteger(s) || s < 1 || s > 65535) throw new
|
|
26810
|
+
if (typeof s != "number" || !Number.isInteger(s) || s < 1 || s > 65535) throw new u2("CONFIG_INVALID", `the daemon config file ${JSON.stringify(e2)} declares an invalid port; expected an integer 1-65535.`);
|
|
26742
26811
|
o.port = s;
|
|
26743
26812
|
}
|
|
26744
26813
|
let a = i.stateDir;
|
|
26745
26814
|
if (a !== void 0) {
|
|
26746
|
-
if (typeof a != "string" || a.trim() === "") throw new
|
|
26815
|
+
if (typeof a != "string" || a.trim() === "") throw new u2("CONFIG_INVALID", `the daemon config file ${JSON.stringify(e2)} declares an invalid stateDir; expected a non-empty string.`);
|
|
26747
26816
|
o.stateDir = a;
|
|
26748
26817
|
}
|
|
26749
26818
|
let c = i.apiToken;
|
|
26750
26819
|
if (c !== void 0) {
|
|
26751
|
-
if (typeof c != "string" || c.trim() === "") throw new
|
|
26820
|
+
if (typeof c != "string" || c.trim() === "") throw new u2("CONFIG_INVALID", `the daemon config file ${JSON.stringify(e2)} declares an invalid apiToken; expected a non-empty string.`);
|
|
26752
26821
|
o.apiToken = c;
|
|
26753
26822
|
}
|
|
26754
26823
|
let l = i.apiVisibility;
|
|
26755
26824
|
if (l !== void 0) {
|
|
26756
|
-
if (l !== "owner" && l !== "shared" && l !== "open") throw new
|
|
26825
|
+
if (l !== "owner" && l !== "shared" && l !== "open") throw new u2("CONFIG_INVALID", `the daemon config file ${JSON.stringify(e2)} declares an unknown apiVisibility ${JSON.stringify(l)}; expected "owner", "shared" or "open".`);
|
|
26757
26826
|
o.apiVisibility = l;
|
|
26758
26827
|
}
|
|
26759
26828
|
return o;
|
|
26760
26829
|
}
|
|
26761
|
-
function
|
|
26830
|
+
function M2(e2, t) {
|
|
26762
26831
|
let n = e2[t];
|
|
26763
26832
|
if (n === void 0) return;
|
|
26764
26833
|
let r = n.trim();
|
|
26765
26834
|
return r === "" ? void 0 : r;
|
|
26766
26835
|
}
|
|
26767
|
-
function
|
|
26836
|
+
function Fe(e2) {
|
|
26768
26837
|
if (e2 === void 0) return;
|
|
26769
26838
|
let t = Number.parseInt(e2, 10);
|
|
26770
|
-
if (!Number.isInteger(t) || t < 1 || t > 65535) throw new
|
|
26839
|
+
if (!Number.isInteger(t) || t < 1 || t > 65535) throw new u2("INCOHERENT_SELECTION", `OURS_PORT=${JSON.stringify(e2)} is not a TCP port between 1 and 65535.`);
|
|
26771
26840
|
return t;
|
|
26772
26841
|
}
|
|
26773
|
-
function
|
|
26842
|
+
function fe(e2, t, n, r) {
|
|
26774
26843
|
return e2 !== void 0 ? { value: e2, source: "explicit" } : t !== void 0 ? { value: t, source: "environment" } : n !== void 0 ? { value: n, source: "config-file" } : { value: r, source: "default" };
|
|
26775
26844
|
}
|
|
26776
|
-
function
|
|
26845
|
+
function $e(e2, t) {
|
|
26777
26846
|
if (e2 !== void 0) return { value: e2, source: "explicit" };
|
|
26778
26847
|
if (t !== void 0) return { value: t, source: "environment" };
|
|
26779
26848
|
}
|
|
26780
|
-
async function
|
|
26849
|
+
async function Me(e2, t = {}) {
|
|
26781
26850
|
let n = t.fetch ?? globalThis.fetch, r = new AbortController(), i = setTimeout(() => r.abort(), t.timeoutMs ?? 5e3), o;
|
|
26782
26851
|
try {
|
|
26783
|
-
let a = await n(
|
|
26784
|
-
if (!a.ok) throw new
|
|
26852
|
+
let a = await n(p(e2.baseUrl.value, "/state-dir"), { signal: r.signal, redirect: "error" });
|
|
26853
|
+
if (!a.ok) throw new u2("INCOHERENT_SELECTION", `${D(p(e2.baseUrl.value, "/state-dir"))} answered HTTP ${a.status}, so the daemon at that address could not be identified. Refusing to send a credential to it.`);
|
|
26785
26854
|
o = await a.json();
|
|
26786
26855
|
} catch (a) {
|
|
26787
|
-
throw a instanceof
|
|
26856
|
+
throw a instanceof u2 ? a : new Y(e2.baseUrl.value, e2.expectStateDir, { cause: a });
|
|
26788
26857
|
} finally {
|
|
26789
26858
|
clearTimeout(i);
|
|
26790
26859
|
}
|
|
26791
|
-
let s = typeof o.stateDir == "string" ?
|
|
26792
|
-
if (s === null) throw new
|
|
26793
|
-
if (s !== e2.expectStateDir) throw new
|
|
26860
|
+
let s = typeof o.stateDir == "string" ? H(o.stateDir) : null;
|
|
26861
|
+
if (s === null) throw new u2("INCOHERENT_SELECTION", `${D(p(e2.baseUrl.value, "/state-dir"))} did not report a state directory, so this is not an ours daemon or not one this client understands. Refusing to send a credential to it.`);
|
|
26862
|
+
if (s !== e2.expectStateDir) throw new u2("INCOHERENT_SELECTION", `the daemon at ${D(e2.baseUrl.value)} owns state directory ${JSON.stringify(s)}, but this selection expects ${JSON.stringify(e2.expectStateDir)}. The token belongs to the expected directory, so it is NOT being sent. Point the endpoint and the state directory at the same daemon.`);
|
|
26794
26863
|
}
|
|
26795
|
-
async function
|
|
26864
|
+
async function Q(e2 = {}) {
|
|
26796
26865
|
if (e2.endpoint === void 0 && e2.port === void 0 && e2.stateDir === void 0 && e2.expectStateDir === void 0) {
|
|
26797
|
-
let
|
|
26798
|
-
return
|
|
26866
|
+
let g = pe({ ...e2.env ?? process.env, ...e2.configPath === void 0 ? {} : { OURS_CONFIG: e2.configPath } });
|
|
26867
|
+
return Q({ ...e2, endpoint: g.endpoint, expectedInstanceId: g.expectedInstanceId, credentialPath: g.credentialPath, sessionMode: "external", leaseToken: e2.leaseToken ?? W(32).toString("hex"), env: {} });
|
|
26799
26868
|
}
|
|
26800
26869
|
if ("serverCertificate" in e2 && e2.serverCertificate !== void 0) throw new Error("Custom serverCertificate is not supported; HTTPS uses Node certificate trust, including NODE_EXTRA_CA_CERTS");
|
|
26801
26870
|
let t = e2.env ?? process.env;
|
|
26802
26871
|
if (t.OURS_TLS_CERT !== void 0 || t.OURS_TLS_KEY !== void 0) throw new Error("Daemon TLS is not supported in V1; remove OURS_TLS_CERT/OURS_TLS_KEY and explicitly configure HTTP");
|
|
26803
|
-
let { leaseToken: n, clientPid: r, sessionMode: i = "local", fetch: o, requestSignal: s, expectedInstanceId: a, requiredCapabilities: c, credentialPath: l, ...
|
|
26872
|
+
let { leaseToken: n, clientPid: r, sessionMode: i = "local", fetch: o, requestSignal: s, expectedInstanceId: a, requiredCapabilities: c, credentialPath: l, ...f } = e2;
|
|
26804
26873
|
if (i !== "local" && i !== "external") throw new Error("Invalid sessionMode");
|
|
26805
26874
|
if (i === "external") {
|
|
26806
26875
|
if (a === void 0) throw new Error("External ownership requires explicit daemon identity");
|
|
26807
26876
|
if (typeof n != "string" || !n.trim()) throw new Error("External ownership requires a stable caller-supplied leaseToken");
|
|
26808
26877
|
}
|
|
26809
|
-
if (l !== void 0 && (a === void 0 ||
|
|
26878
|
+
if (l !== void 0 && (a === void 0 || f.token !== void 0)) throw new Error("Credential path requires explicit daemon identity and cannot be combined with a token");
|
|
26810
26879
|
if (a !== void 0) {
|
|
26811
|
-
let { endpoint:
|
|
26812
|
-
if (!
|
|
26880
|
+
let { endpoint: g, token: y2 } = f;
|
|
26881
|
+
if (!g) throw new Error("Instance selection requires an explicit endpoint");
|
|
26813
26882
|
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(a)) throw new Error("Expected daemon instance must be a lowercase UUID");
|
|
26814
26883
|
if (o !== void 0) throw new Error("Instance selection cannot use an injected fetch");
|
|
26815
|
-
let
|
|
26884
|
+
let h = w2(g);
|
|
26816
26885
|
if (c !== void 0 && !Array.isArray(c)) throw new Error("Instance selection requires a nonempty capability list");
|
|
26817
|
-
let
|
|
26818
|
-
if (!
|
|
26819
|
-
if (i === "external")
|
|
26820
|
-
else if (
|
|
26886
|
+
let T2 = [...c ?? ["external-sessions-v1"]];
|
|
26887
|
+
if (!T2.length || T2.some((b2) => typeof b2 != "string" || !b2.trim())) throw new Error("Instance selection requires a nonempty capability list");
|
|
26888
|
+
if (i === "external") T2.includes("external-sessions-v1") || T2.push("external-sessions-v1");
|
|
26889
|
+
else if (T2.includes("external-sessions-v1")) throw new Error("External capabilities require explicit sessionMode: external; refusing local-mode fallback");
|
|
26821
26890
|
{
|
|
26822
|
-
let b2 = await globalThis.fetch(
|
|
26823
|
-
if (!b2.ok || !
|
|
26824
|
-
let
|
|
26825
|
-
if (!Array.isArray(
|
|
26891
|
+
let b2 = await globalThis.fetch(p(h, "/selection"), { signal: s ? AbortSignal.any([s, AbortSignal.timeout(5e3)]) : AbortSignal.timeout(5e3), redirect: "error" }), _ = await C(b2);
|
|
26892
|
+
if (!b2.ok || !_ || Object.keys(_).length !== 3 || Object.keys(_).some((O2) => !["schema", "instanceId", "capabilities"].includes(O2)) || _.schema !== 1 || _.instanceId !== a) throw new Error("Daemon instance selection metadata is absent, incompatible or mismatched");
|
|
26893
|
+
let R2 = _.capabilities;
|
|
26894
|
+
if (!Array.isArray(R2) || R2.some((O2) => typeof O2 != "string") || T2.some((O2) => !R2.includes(O2))) throw new Error("Daemon does not support the required capabilities; refusing local-mode fallback");
|
|
26826
26895
|
}
|
|
26827
|
-
let
|
|
26828
|
-
if (typeof
|
|
26829
|
-
return new
|
|
26896
|
+
let v2 = l === void 0 ? y2 : S(l);
|
|
26897
|
+
if (typeof v2 != "string" || !v2.trim()) throw new Error("Instance selection requires an explicit API token after daemon verification");
|
|
26898
|
+
return new F({ url: h, sessionMode: i, requestSignal: s, ...l === void 0 ? { apiToken: v2 } : { credentialPath: l }, leaseToken: n ?? W(32).toString("hex"), clientPid: r });
|
|
26830
26899
|
}
|
|
26831
26900
|
if (c !== void 0) throw new Error("Capability selection requires an expected daemon instance");
|
|
26832
|
-
let
|
|
26833
|
-
return await
|
|
26901
|
+
let m2 = De(f);
|
|
26902
|
+
return await Me(m2, { fetch: o }), new F({ url: m2.baseUrl.value, leaseToken: n ?? W(32).toString("hex"), clientPid: r, ...m2.token?.source === "token-file" && f.readTextFile === void 0 ? { credentialPath: J(m2.expectStateDir, X) } : { apiToken: m2.token?.value }, fetch: o, requestSignal: s });
|
|
26834
26903
|
}
|
|
26835
26904
|
|
|
26836
26905
|
// src/telegram.ts
|
|
@@ -26914,13 +26983,13 @@ ${raw}
|
|
|
26914
26983
|
function renderRange(text2, ents, start, end) {
|
|
26915
26984
|
let out = "";
|
|
26916
26985
|
let i = start;
|
|
26917
|
-
let
|
|
26918
|
-
while (
|
|
26919
|
-
const e2 = ents[
|
|
26986
|
+
let k = 0;
|
|
26987
|
+
while (k < ents.length) {
|
|
26988
|
+
const e2 = ents[k];
|
|
26920
26989
|
const eStart = Math.max(e2.start, start);
|
|
26921
26990
|
const eEnd = Math.min(e2.end, end);
|
|
26922
26991
|
if (eEnd <= i) {
|
|
26923
|
-
|
|
26992
|
+
k += 1;
|
|
26924
26993
|
continue;
|
|
26925
26994
|
}
|
|
26926
26995
|
if (eStart > i) {
|
|
@@ -26928,7 +26997,7 @@ function renderRange(text2, ents, start, end) {
|
|
|
26928
26997
|
i = eStart;
|
|
26929
26998
|
}
|
|
26930
26999
|
const kids = [];
|
|
26931
|
-
let j =
|
|
27000
|
+
let j = k + 1;
|
|
26932
27001
|
while (j < ents.length && ents[j].start < eEnd) {
|
|
26933
27002
|
kids.push(ents[j]);
|
|
26934
27003
|
j += 1;
|
|
@@ -26937,7 +27006,7 @@ function renderRange(text2, ents, start, end) {
|
|
|
26937
27006
|
const verbatim = e2.type === "code" || e2.type === "pre";
|
|
26938
27007
|
out += wrapEntity(e2, verbatim ? raw : renderRange(text2, kids, eStart, eEnd), raw);
|
|
26939
27008
|
i = eEnd;
|
|
26940
|
-
|
|
27009
|
+
k = j;
|
|
26941
27010
|
}
|
|
26942
27011
|
if (i < end) out += text2.slice(i, end);
|
|
26943
27012
|
return out;
|
|
@@ -27981,8 +28050,8 @@ function pruneRows(messages, nowMs, retentionDays = RETENTION_DAYS, maxRows = MA
|
|
|
27981
28050
|
}
|
|
27982
28051
|
const keys = Object.keys(messages);
|
|
27983
28052
|
if (keys.length > maxRows) {
|
|
27984
|
-
keys.sort((a, b2) => Date.parse(messages[a].createdAt) - Date.parse(messages[b2].createdAt)).slice(0, keys.length - maxRows).forEach((
|
|
27985
|
-
delete messages[
|
|
28053
|
+
keys.sort((a, b2) => Date.parse(messages[a].createdAt) - Date.parse(messages[b2].createdAt)).slice(0, keys.length - maxRows).forEach((k) => {
|
|
28054
|
+
delete messages[k];
|
|
27986
28055
|
removed += 1;
|
|
27987
28056
|
});
|
|
27988
28057
|
}
|
|
@@ -28014,17 +28083,17 @@ function parseMapFile(raw, nowMs) {
|
|
|
28014
28083
|
return out;
|
|
28015
28084
|
}
|
|
28016
28085
|
if (!parsed || typeof parsed !== "object") return out;
|
|
28017
|
-
const
|
|
28018
|
-
if (
|
|
28019
|
-
for (const [wireId, v2] of Object.entries(
|
|
28086
|
+
const p2 = parsed;
|
|
28087
|
+
if (p2.messages && typeof p2.messages === "object") {
|
|
28088
|
+
for (const [wireId, v2] of Object.entries(p2.messages)) {
|
|
28020
28089
|
if (!wireId) continue;
|
|
28021
28090
|
const row = validRow(v2);
|
|
28022
28091
|
if (row) out.messages[wireId] = row;
|
|
28023
28092
|
}
|
|
28024
28093
|
}
|
|
28025
28094
|
const now = new Date(nowMs).toISOString();
|
|
28026
|
-
if (
|
|
28027
|
-
for (const [cid, v2] of Object.entries(
|
|
28095
|
+
if (p2.settings && typeof p2.settings === "object") {
|
|
28096
|
+
for (const [cid, v2] of Object.entries(p2.settings)) {
|
|
28028
28097
|
if (cid) out.settings[cid] = normalizeSettings(v2, now);
|
|
28029
28098
|
}
|
|
28030
28099
|
}
|
|
@@ -28266,11 +28335,11 @@ function daemonSelectionOptions() {
|
|
|
28266
28335
|
}
|
|
28267
28336
|
async function attachToDaemon() {
|
|
28268
28337
|
const options = daemonSelectionOptions();
|
|
28269
|
-
const legacy = options.expectedInstanceId ? null :
|
|
28270
|
-
const client = await
|
|
28338
|
+
const legacy = options.expectedInstanceId ? null : De(options);
|
|
28339
|
+
const client = await Q({ ...options, leaseToken: randomBytes(24).toString("hex") });
|
|
28271
28340
|
try {
|
|
28272
28341
|
daemonIdentityNames = new Set((await client.identities()).map((row) => row.name));
|
|
28273
|
-
log(`attached to daemon ${JSON.stringify(legacy ?
|
|
28342
|
+
log(`attached to daemon ${JSON.stringify(legacy ? un(legacy) : {
|
|
28274
28343
|
endpoint: CONFIG.daemonUrl,
|
|
28275
28344
|
instanceId: CONFIG.daemonInstanceId
|
|
28276
28345
|
})}`);
|
|
@@ -28281,7 +28350,7 @@ async function attachToDaemon() {
|
|
|
28281
28350
|
}
|
|
28282
28351
|
async function clientFor(cfg) {
|
|
28283
28352
|
if (!daemon) throw new Error("not attached to a daemon yet");
|
|
28284
|
-
return
|
|
28353
|
+
return Q({ ...daemonSelectionOptions(), leaseToken: cfg.leaseToken });
|
|
28285
28354
|
}
|
|
28286
28355
|
var connections = /* @__PURE__ */ new Map();
|
|
28287
28356
|
var bots = /* @__PURE__ */ new Map();
|
|
@@ -28384,7 +28453,7 @@ function registerRoute(conn) {
|
|
|
28384
28453
|
return null;
|
|
28385
28454
|
}
|
|
28386
28455
|
function unregisterRoute(conn) {
|
|
28387
|
-
for (const [
|
|
28456
|
+
for (const [k, v2] of conn.bot.exact) if (v2 === conn) conn.bot.exact.delete(k);
|
|
28388
28457
|
if (conn.bot.catchAll === conn) conn.bot.catchAll = null;
|
|
28389
28458
|
}
|
|
28390
28459
|
function routeSlotConflict(bot, chatId, threadId) {
|