mycomesh-consumer 0.1.42 → 0.1.44
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 +14 -7
- package/src/consumer.mjs +1 -1
package/package.json
CHANGED
package/src/consumer-runtime.mjs
CHANGED
|
@@ -85,6 +85,8 @@ const RESPONSES_LOCAL_OPTION_FIELDS = new Set(["stream", "stream_options"]);
|
|
|
85
85
|
const MAX_SHARE_MINUTES = 24 * 60;
|
|
86
86
|
const TUNNEL_START_TIMEOUT_MS = 30_000;
|
|
87
87
|
const TUNNEL_STOP_TIMEOUT_MS = 2_000;
|
|
88
|
+
const RELAY_HEALTH_CACHE_MS = 30_000;
|
|
89
|
+
const RELAY_HEALTH_STALE_MS = 10 * 60_000;
|
|
88
90
|
|
|
89
91
|
const DEFAULT_NETWORK = Object.freeze({
|
|
90
92
|
chain_id: DEFAULT_CHAIN_ID,
|
|
@@ -807,6 +809,8 @@ export class NativeConsumerState {
|
|
|
807
809
|
break;
|
|
808
810
|
} catch (error) {
|
|
809
811
|
lastError = error;
|
|
812
|
+
await stopTunnelProcess(child);
|
|
813
|
+
if (share.process === child) share.process = null;
|
|
810
814
|
if (this.share !== share || attempt === 1) throw error;
|
|
811
815
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
812
816
|
}
|
|
@@ -893,15 +897,18 @@ export class NativeConsumerState {
|
|
|
893
897
|
|
|
894
898
|
async relayHealth(relayUrl, refresh = false) {
|
|
895
899
|
const cached = this.healthCache.get(relayUrl);
|
|
896
|
-
|
|
900
|
+
const cacheAge = cached ? Date.now() - cached.at : Infinity;
|
|
901
|
+
if (cached && !refresh && cacheAge < RELAY_HEALTH_CACHE_MS) return cached.payload;
|
|
897
902
|
const request = { dispatcher: this.dispatcher, headers: { accept: "application/json" } };
|
|
898
|
-
let
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
response = await fetchWithTimeout(`${relayUrl}/relay/health`, request, this.healthTimeoutMs);
|
|
903
|
+
let payload;
|
|
904
|
+
try {
|
|
905
|
+
const response = await fetchWithTimeout(`${relayUrl}/relay/health`, request, this.healthTimeoutMs);
|
|
902
906
|
payload = await readJsonResponse(response);
|
|
907
|
+
if (!response.ok || payload?.ok !== true) throw new Error(`Relay health is invalid for ${relayUrl}`);
|
|
908
|
+
} catch (error) {
|
|
909
|
+
if (cached && cacheAge < RELAY_HEALTH_STALE_MS) return cached.payload;
|
|
910
|
+
throw error;
|
|
903
911
|
}
|
|
904
|
-
if (!response.ok || payload?.ok !== true) throw new Error(`Relay health is invalid for ${relayUrl}`);
|
|
905
912
|
const v8 = payload.v8;
|
|
906
913
|
if (!v8 || v8.enabled !== true || Number(v8.providers || 0) <= 0) throw new Error(`Relay has no live Settlement V8 Provider: ${relayUrl}`);
|
|
907
914
|
this.healthCache.set(relayUrl, { at: Date.now(), payload });
|
|
@@ -1084,7 +1091,7 @@ function waitForTunnelUrl(child) {
|
|
|
1084
1091
|
}
|
|
1085
1092
|
|
|
1086
1093
|
async function stopTunnelProcess(child) {
|
|
1087
|
-
if (!child || child.exitCode !== null) return;
|
|
1094
|
+
if (!child || child.exitCode !== null || child.signalCode != null) return;
|
|
1088
1095
|
await new Promise((resolve) => {
|
|
1089
1096
|
let settled = false;
|
|
1090
1097
|
const finish = () => {
|
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.44";
|
|
15
15
|
export const API_COMMANDS = new Set(["health", "models", "responses", "chat"]);
|
|
16
16
|
const API_VALUE_OPTIONS = new Set([
|
|
17
17
|
"--base-url",
|