mycomesh-consumer 0.1.43 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mycomesh-consumer",
3
- "version": "0.1.43",
3
+ "version": "0.1.45",
4
4
  "description": "Native Node.js MycoMesh Consumer and OpenAI-compatible request CLI.",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -85,6 +85,9 @@ 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;
90
+ const RELAY_HEALTH_RETRY_DELAY_MS = 250;
88
91
 
89
92
  const DEFAULT_NETWORK = Object.freeze({
90
93
  chain_id: DEFAULT_CHAIN_ID,
@@ -580,7 +583,7 @@ export class NativeConsumerState {
580
583
  this.maxFeeUnits = options.maxFeeUnits || Number(env.MYCOMESH_V8_MAX_FEE_UNITS || DEFAULT_MAX_FEE_UNITS);
581
584
  if (!Number.isSafeInteger(this.maxFeeUnits) || this.maxFeeUnits <= 0) throw new Error("max fee must be a positive integer");
582
585
  this.timeoutMs = options.timeoutMs ?? Number(env.MYCOMESH_V8_REQUEST_TIMEOUT_SECONDS || 300) * 1000;
583
- this.healthTimeoutMs = options.healthTimeoutMs ?? Number(env.MYCOMESH_V8_HEALTH_TIMEOUT_SECONDS || 5) * 1000;
586
+ this.healthTimeoutMs = options.healthTimeoutMs ?? Number(env.MYCOMESH_V8_HEALTH_TIMEOUT_SECONDS || 10) * 1000;
584
587
  this.network = parseNetworkConfig(options.networkConfig || env.MYCOMESH_CONSUMER_NETWORK_CONFIG);
585
588
  if (env.MYCOMESH_CONSUMER_SETTLEMENT_RPC_URLS) {
586
589
  this.network.rpc_urls = String(env.MYCOMESH_CONSUMER_SETTLEMENT_RPC_URLS).split(",").map((item) => item.trim()).filter(Boolean);
@@ -895,15 +898,26 @@ export class NativeConsumerState {
895
898
 
896
899
  async relayHealth(relayUrl, refresh = false) {
897
900
  const cached = this.healthCache.get(relayUrl);
898
- if (cached && !refresh && Date.now() - cached.at < 5000) return cached.payload;
901
+ const cacheAge = cached ? Date.now() - cached.at : Infinity;
902
+ if (cached && !refresh && cacheAge < RELAY_HEALTH_CACHE_MS) return cached.payload;
899
903
  const request = { dispatcher: this.dispatcher, headers: { accept: "application/json" } };
900
- let response = await fetchWithTimeout(`${relayUrl}/health`, request, this.healthTimeoutMs);
901
- let payload = await readJsonResponse(response);
902
- if (!response.ok || !payload?.v8) {
903
- response = await fetchWithTimeout(`${relayUrl}/relay/health`, request, this.healthTimeoutMs);
904
- payload = await readJsonResponse(response);
904
+ let payload;
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) {
918
+ if (cached && cacheAge < RELAY_HEALTH_STALE_MS) return cached.payload;
919
+ throw lastError || new Error(`Relay health is unavailable for ${relayUrl}`);
905
920
  }
906
- if (!response.ok || payload?.ok !== true) throw new Error(`Relay health is invalid for ${relayUrl}`);
907
921
  const v8 = payload.v8;
908
922
  if (!v8 || v8.enabled !== true || Number(v8.providers || 0) <= 0) throw new Error(`Relay has no live Settlement V8 Provider: ${relayUrl}`);
909
923
  this.healthCache.set(relayUrl, { at: Date.now(), payload });
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.43";
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",