mycomesh-consumer 0.1.39 → 0.1.41
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 +48 -11
- package/src/consumer.mjs +1 -1
package/package.json
CHANGED
package/src/consumer-runtime.mjs
CHANGED
|
@@ -84,6 +84,7 @@ const RESPONSES_REQUEST_OPTION_FIELDS = new Set([
|
|
|
84
84
|
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
|
+
const TUNNEL_STOP_TIMEOUT_MS = 2_000;
|
|
87
88
|
|
|
88
89
|
const DEFAULT_NETWORK = Object.freeze({
|
|
89
90
|
chain_id: DEFAULT_CHAIN_ID,
|
|
@@ -792,18 +793,30 @@ export class NativeConsumerState {
|
|
|
792
793
|
};
|
|
793
794
|
this.share = share;
|
|
794
795
|
try {
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
796
|
+
let publicUrl;
|
|
797
|
+
let lastError;
|
|
798
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
799
|
+
const child = this.tunnelSpawn(
|
|
800
|
+
this.tunnelCommand,
|
|
801
|
+
["tunnel", "--no-autoupdate", "--url", `http://127.0.0.1:${address.port}`],
|
|
802
|
+
{ stdio: ["ignore", "pipe", "pipe"] },
|
|
803
|
+
);
|
|
804
|
+
share.process = child;
|
|
805
|
+
try {
|
|
806
|
+
publicUrl = await waitForTunnelUrl(child);
|
|
807
|
+
break;
|
|
808
|
+
} catch (error) {
|
|
809
|
+
lastError = error;
|
|
810
|
+
if (this.share !== share || attempt === 1) throw error;
|
|
811
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
if (!publicUrl) throw lastError || new Error("cloudflared did not publish a URL");
|
|
802
815
|
if (this.share !== share) throw new Error("temporary share was cancelled");
|
|
803
816
|
share.baseUrl = `${publicUrl.replace(/\/+$/, "")}/v1`;
|
|
804
817
|
share.timer = setTimeout(() => { void this.stopShare(); }, minutes * 60 * 1000);
|
|
805
818
|
share.timer.unref?.();
|
|
806
|
-
|
|
819
|
+
share.process?.once("exit", () => { if (this.share === share) void this.stopShare(); });
|
|
807
820
|
return this.sharePayload();
|
|
808
821
|
} catch (error) {
|
|
809
822
|
await this.stopShare();
|
|
@@ -816,7 +829,7 @@ export class NativeConsumerState {
|
|
|
816
829
|
this.share = null;
|
|
817
830
|
if (!share) return { active: false };
|
|
818
831
|
if (share.timer) clearTimeout(share.timer);
|
|
819
|
-
|
|
832
|
+
await stopTunnelProcess(share.process);
|
|
820
833
|
await share.runtime?.close();
|
|
821
834
|
return { active: false };
|
|
822
835
|
}
|
|
@@ -1035,6 +1048,7 @@ function waitForTunnelUrl(child) {
|
|
|
1035
1048
|
let output = "";
|
|
1036
1049
|
let publicUrl = "";
|
|
1037
1050
|
let connected = false;
|
|
1051
|
+
const diagnostics = () => output.trim().replace(/\s+/g, " ").slice(-1000);
|
|
1038
1052
|
const finish = (error, url) => {
|
|
1039
1053
|
clearTimeout(timer);
|
|
1040
1054
|
child.removeListener("error", onError);
|
|
@@ -1051,9 +1065,15 @@ function waitForTunnelUrl(child) {
|
|
|
1051
1065
|
if (publicUrl && connected) finish(null, publicUrl);
|
|
1052
1066
|
};
|
|
1053
1067
|
const onError = (error) => finish(new Error(`could not start cloudflared: ${error.message}`));
|
|
1054
|
-
const onExit = (code) =>
|
|
1068
|
+
const onExit = (code) => {
|
|
1069
|
+
const detail = diagnostics();
|
|
1070
|
+
finish(new Error(`cloudflared exited before publishing a URL (${code ?? "signal"})${detail ? `: ${detail}` : ""}`));
|
|
1071
|
+
};
|
|
1055
1072
|
const timer = setTimeout(
|
|
1056
|
-
() =>
|
|
1073
|
+
() => {
|
|
1074
|
+
const detail = diagnostics();
|
|
1075
|
+
finish(new Error(`timed out waiting for the temporary HTTPS URL${detail ? `: ${detail}` : ""}`));
|
|
1076
|
+
},
|
|
1057
1077
|
TUNNEL_START_TIMEOUT_MS,
|
|
1058
1078
|
);
|
|
1059
1079
|
child.once("error", onError);
|
|
@@ -1063,6 +1083,23 @@ function waitForTunnelUrl(child) {
|
|
|
1063
1083
|
});
|
|
1064
1084
|
}
|
|
1065
1085
|
|
|
1086
|
+
async function stopTunnelProcess(child) {
|
|
1087
|
+
if (!child || child.exitCode !== null) return;
|
|
1088
|
+
await new Promise((resolve) => {
|
|
1089
|
+
let settled = false;
|
|
1090
|
+
const finish = () => {
|
|
1091
|
+
if (settled) return;
|
|
1092
|
+
settled = true;
|
|
1093
|
+
clearTimeout(timer);
|
|
1094
|
+
child.removeListener("exit", finish);
|
|
1095
|
+
resolve();
|
|
1096
|
+
};
|
|
1097
|
+
const timer = setTimeout(finish, TUNNEL_STOP_TIMEOUT_MS);
|
|
1098
|
+
child.once("exit", finish);
|
|
1099
|
+
try { child.kill("SIGTERM"); } catch { finish(); }
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1066
1103
|
async function handleInference(state, request, response, path, alphaSearchQuery, shareOnly = false) {
|
|
1067
1104
|
const authorization = String(request.headers.authorization || "");
|
|
1068
1105
|
if (!state.authorizeBearer(authorization, { shareOnly })) {
|
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.41";
|
|
15
15
|
export const API_COMMANDS = new Set(["health", "models", "responses", "chat"]);
|
|
16
16
|
const API_VALUE_OPTIONS = new Set([
|
|
17
17
|
"--base-url",
|