mycomesh-consumer 0.1.44 → 0.1.45
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/package.json +1 -1
- package/src/consumer-runtime.mjs +16 -7
- package/src/consumer.mjs +1 -1
package/package.json
CHANGED
package/src/consumer-runtime.mjs
CHANGED
|
@@ -87,6 +87,7 @@ const TUNNEL_START_TIMEOUT_MS = 30_000;
|
|
|
87
87
|
const TUNNEL_STOP_TIMEOUT_MS = 2_000;
|
|
88
88
|
const RELAY_HEALTH_CACHE_MS = 30_000;
|
|
89
89
|
const RELAY_HEALTH_STALE_MS = 10 * 60_000;
|
|
90
|
+
const RELAY_HEALTH_RETRY_DELAY_MS = 250;
|
|
90
91
|
|
|
91
92
|
const DEFAULT_NETWORK = Object.freeze({
|
|
92
93
|
chain_id: DEFAULT_CHAIN_ID,
|
|
@@ -582,7 +583,7 @@ export class NativeConsumerState {
|
|
|
582
583
|
this.maxFeeUnits = options.maxFeeUnits || Number(env.MYCOMESH_V8_MAX_FEE_UNITS || DEFAULT_MAX_FEE_UNITS);
|
|
583
584
|
if (!Number.isSafeInteger(this.maxFeeUnits) || this.maxFeeUnits <= 0) throw new Error("max fee must be a positive integer");
|
|
584
585
|
this.timeoutMs = options.timeoutMs ?? Number(env.MYCOMESH_V8_REQUEST_TIMEOUT_SECONDS || 300) * 1000;
|
|
585
|
-
this.healthTimeoutMs = options.healthTimeoutMs ?? Number(env.MYCOMESH_V8_HEALTH_TIMEOUT_SECONDS ||
|
|
586
|
+
this.healthTimeoutMs = options.healthTimeoutMs ?? Number(env.MYCOMESH_V8_HEALTH_TIMEOUT_SECONDS || 10) * 1000;
|
|
586
587
|
this.network = parseNetworkConfig(options.networkConfig || env.MYCOMESH_CONSUMER_NETWORK_CONFIG);
|
|
587
588
|
if (env.MYCOMESH_CONSUMER_SETTLEMENT_RPC_URLS) {
|
|
588
589
|
this.network.rpc_urls = String(env.MYCOMESH_CONSUMER_SETTLEMENT_RPC_URLS).split(",").map((item) => item.trim()).filter(Boolean);
|
|
@@ -901,13 +902,21 @@ export class NativeConsumerState {
|
|
|
901
902
|
if (cached && !refresh && cacheAge < RELAY_HEALTH_CACHE_MS) return cached.payload;
|
|
902
903
|
const request = { dispatcher: this.dispatcher, headers: { accept: "application/json" } };
|
|
903
904
|
let payload;
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
905
|
+
let lastError;
|
|
906
|
+
for (let attempt = 0; attempt < 2 && !payload; attempt += 1) {
|
|
907
|
+
try {
|
|
908
|
+
const response = await fetchWithTimeout(`${relayUrl}/relay/health`, request, this.healthTimeoutMs);
|
|
909
|
+
payload = await readJsonResponse(response);
|
|
910
|
+
if (!response.ok || payload?.ok !== true) throw new Error(`Relay health is invalid for ${relayUrl}`);
|
|
911
|
+
} catch (error) {
|
|
912
|
+
lastError = error;
|
|
913
|
+
payload = undefined;
|
|
914
|
+
if (attempt === 0) await new Promise((resolve) => setTimeout(resolve, RELAY_HEALTH_RETRY_DELAY_MS));
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
if (!payload) {
|
|
909
918
|
if (cached && cacheAge < RELAY_HEALTH_STALE_MS) return cached.payload;
|
|
910
|
-
throw
|
|
919
|
+
throw lastError || new Error(`Relay health is unavailable for ${relayUrl}`);
|
|
911
920
|
}
|
|
912
921
|
const v8 = payload.v8;
|
|
913
922
|
if (!v8 || v8.enabled !== true || Number(v8.providers || 0) <= 0) throw new Error(`Relay has no live Settlement V8 Provider: ${relayUrl}`);
|
package/src/consumer.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
createConsumerServer,
|
|
12
12
|
} from "./consumer-runtime.mjs";
|
|
13
13
|
|
|
14
|
-
export const CONSUMER_RELEASE_VERSION = "0.1.
|
|
14
|
+
export const CONSUMER_RELEASE_VERSION = "0.1.45";
|
|
15
15
|
export const API_COMMANDS = new Set(["health", "models", "responses", "chat"]);
|
|
16
16
|
const API_VALUE_OPTIONS = new Set([
|
|
17
17
|
"--base-url",
|