mycomesh-consumer 0.1.43 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mycomesh-consumer",
3
- "version": "0.1.43",
3
+ "version": "0.1.44",
4
4
  "description": "Native Node.js MycoMesh Consumer and OpenAI-compatible request CLI.",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -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,
@@ -895,15 +897,18 @@ export class NativeConsumerState {
895
897
 
896
898
  async relayHealth(relayUrl, refresh = false) {
897
899
  const cached = this.healthCache.get(relayUrl);
898
- if (cached && !refresh && Date.now() - cached.at < 5000) return cached.payload;
900
+ const cacheAge = cached ? Date.now() - cached.at : Infinity;
901
+ if (cached && !refresh && cacheAge < RELAY_HEALTH_CACHE_MS) return cached.payload;
899
902
  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);
903
+ let payload;
904
+ try {
905
+ const response = await fetchWithTimeout(`${relayUrl}/relay/health`, request, this.healthTimeoutMs);
904
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;
905
911
  }
906
- if (!response.ok || payload?.ok !== true) throw new Error(`Relay health is invalid for ${relayUrl}`);
907
912
  const v8 = payload.v8;
908
913
  if (!v8 || v8.enabled !== true || Number(v8.providers || 0) <= 0) throw new Error(`Relay has no live Settlement V8 Provider: ${relayUrl}`);
909
914
  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.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",