mycomesh-consumer 0.1.36 → 0.1.38
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 +6 -26
- package/src/consumer.mjs +1 -1
package/package.json
CHANGED
package/src/consumer-runtime.mjs
CHANGED
|
@@ -84,7 +84,6 @@ 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_READY_TIMEOUT_MS = 90_000;
|
|
88
87
|
|
|
89
88
|
const DEFAULT_NETWORK = Object.freeze({
|
|
90
89
|
chain_id: DEFAULT_CHAIN_ID,
|
|
@@ -596,7 +595,6 @@ export class NativeConsumerState {
|
|
|
596
595
|
this.paymentAddress = paymentKeyAddress(this.paymentKey);
|
|
597
596
|
this.tunnelCommand = options.tunnelCommand || env.MYCOMESH_CONSUMER_TUNNEL_COMMAND || "cloudflared";
|
|
598
597
|
this.tunnelSpawn = options.tunnelSpawn || defaultSpawn;
|
|
599
|
-
this.tunnelProbe = options.tunnelProbe || waitForTunnelReady;
|
|
600
598
|
this.share = null;
|
|
601
599
|
}
|
|
602
600
|
|
|
@@ -803,8 +801,6 @@ export class NativeConsumerState {
|
|
|
803
801
|
share.process = child;
|
|
804
802
|
const publicUrl = await waitForTunnelUrl(child);
|
|
805
803
|
if (this.share !== share) throw new Error("temporary share was cancelled");
|
|
806
|
-
await this.tunnelProbe(publicUrl, apiKey, this.dispatcher);
|
|
807
|
-
if (this.share !== share) throw new Error("temporary share was cancelled");
|
|
808
804
|
share.baseUrl = `${publicUrl.replace(/\/+$/, "")}/v1`;
|
|
809
805
|
share.timer = setTimeout(() => { void this.stopShare(); }, minutes * 60 * 1000);
|
|
810
806
|
share.timer.unref?.();
|
|
@@ -1038,6 +1034,8 @@ function writeJson(response, status, value, headers = {}) {
|
|
|
1038
1034
|
function waitForTunnelUrl(child) {
|
|
1039
1035
|
return new Promise((resolve, reject) => {
|
|
1040
1036
|
let output = "";
|
|
1037
|
+
let publicUrl = "";
|
|
1038
|
+
let connected = false;
|
|
1041
1039
|
const finish = (error, url) => {
|
|
1042
1040
|
clearTimeout(timer);
|
|
1043
1041
|
child.removeListener("error", onError);
|
|
@@ -1049,7 +1047,9 @@ function waitForTunnelUrl(child) {
|
|
|
1049
1047
|
const onData = (chunk) => {
|
|
1050
1048
|
output = `${output}${String(chunk)}`.slice(-16_384);
|
|
1051
1049
|
const match = output.match(/https:\/\/[a-z0-9-]+\.trycloudflare\.com/i);
|
|
1052
|
-
if (match)
|
|
1050
|
+
if (match) publicUrl = match[0];
|
|
1051
|
+
if (/Registered tunnel connection/i.test(output)) connected = true;
|
|
1052
|
+
if (publicUrl && connected) finish(null, publicUrl);
|
|
1053
1053
|
};
|
|
1054
1054
|
const onError = (error) => finish(new Error(`could not start cloudflared: ${error.message}`));
|
|
1055
1055
|
const onExit = (code) => finish(new Error(`cloudflared exited before publishing a URL (${code ?? "signal"})`));
|
|
@@ -1064,26 +1064,6 @@ function waitForTunnelUrl(child) {
|
|
|
1064
1064
|
});
|
|
1065
1065
|
}
|
|
1066
1066
|
|
|
1067
|
-
async function waitForTunnelReady(publicUrl, apiKey, dispatcher) {
|
|
1068
|
-
const deadline = Date.now() + TUNNEL_READY_TIMEOUT_MS;
|
|
1069
|
-
let lastError;
|
|
1070
|
-
while (Date.now() < deadline) {
|
|
1071
|
-
try {
|
|
1072
|
-
const response = await fetchWithTimeout(`${publicUrl.replace(/\/+$/, "")}/v1/health`, {
|
|
1073
|
-
headers: { authorization: `Bearer ${apiKey}` },
|
|
1074
|
-
dispatcher,
|
|
1075
|
-
}, Math.min(3000, deadline - Date.now()));
|
|
1076
|
-
const payload = await readJsonResponse(response);
|
|
1077
|
-
if (response.ok && payload.protocol === "mycomesh-temporary-share/v1") return;
|
|
1078
|
-
lastError = new Error(`HTTP ${response.status}`);
|
|
1079
|
-
} catch (error) {
|
|
1080
|
-
lastError = error;
|
|
1081
|
-
}
|
|
1082
|
-
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
1083
|
-
}
|
|
1084
|
-
throw new Error(`temporary HTTPS URL was not reachable: ${lastError?.message || "timed out"}`);
|
|
1085
|
-
}
|
|
1086
|
-
|
|
1087
1067
|
async function handleInference(state, request, response, path, alphaSearchQuery, shareOnly = false) {
|
|
1088
1068
|
const authorization = String(request.headers.authorization || "");
|
|
1089
1069
|
if (!state.authorizeBearer(authorization, { shareOnly })) {
|
|
@@ -1371,7 +1351,7 @@ $('register').onclick=()=>showPlan('register_key',true);$('topup').onclick=()=>s
|
|
|
1371
1351
|
$('rotate').onclick=async()=>{try{await requireWallet();const oldAddress=state.key.address;const pending=await api('/v1/mycomesh/local/key/prepare',{method:'POST',headers:{authorization:'Bearer '+state.credentials.api_key}});const plan=await api('/v1/mycomesh/local/transactions',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify({action:'register_key',wallet})});await sendPlan(plan);let activated;for(let i=0;i<8&&!activated;i++){try{activated=await api('/v1/mycomesh/local/key/activate',{method:'POST',headers:{authorization:'Bearer '+state.credentials.api_key,'content-type':'application/json'},body:JSON.stringify({wallet})})}catch(error){if(i===7)throw error;await new Promise(resolve=>setTimeout(resolve,1800))}}const revoke=await api('/v1/mycomesh/local/transactions',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify({action:'revoke_key',wallet,key_address:oldAddress})});await sendPlan(revoke);$('plan').textContent=JSON.stringify({pending,activated,revoke},null,2);await load()}catch(error){$('plan').textContent=error.message}};
|
|
1372
1352
|
$('shareStart').onclick=async()=>{const button=$('shareStart');button.disabled=true;button.textContent='Starting...';try{const v=await api('/v1/mycomesh/local/share/start',{method:'POST',headers:{authorization:'Bearer '+state.credentials.api_key,'content-type':'application/json'},body:JSON.stringify({minutes:Number($('shareMinutes').value)})});state.share=v.share;render()}catch(error){$('shareExpiry').textContent=error.message}finally{button.disabled=false;button.textContent='Start sharing'}};
|
|
1373
1353
|
$('shareStop').onclick=async()=>{try{const v=await api('/v1/mycomesh/local/share/stop',{method:'POST',headers:{authorization:'Bearer '+state.credentials.api_key}});state.share=v.share;render()}catch(error){$('shareExpiry').textContent=error.message}};
|
|
1374
|
-
$('shareCopy').onclick=()=>navigator.clipboard?.writeText("export OPENAI_BASE_URL='"+$('shareUrl').textContent+"'
|
|
1354
|
+
$('shareCopy').onclick=()=>navigator.clipboard?.writeText("export OPENAI_BASE_URL='"+$('shareUrl').textContent+"'\\nexport OPENAI_API_KEY='"+$('shareKey').textContent+"'");
|
|
1375
1355
|
load().catch(error=>$('plan').textContent=error.message);
|
|
1376
1356
|
</script></body></html>`;
|
|
1377
1357
|
}
|
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.38";
|
|
15
15
|
export const API_COMMANDS = new Set(["health", "models", "responses", "chat"]);
|
|
16
16
|
const API_VALUE_OPTIONS = new Set([
|
|
17
17
|
"--base-url",
|