@fengye404/termpilot 0.2.1 → 0.2.2
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/dist/cli.js +15 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -712,11 +712,10 @@ async function fetchJson(input, init, message) {
|
|
|
712
712
|
lastError = error;
|
|
713
713
|
continue;
|
|
714
714
|
}
|
|
715
|
-
const payload = await readJsonOrThrow(response, message);
|
|
716
715
|
if (process.env.TERMPILOT_RELAY_URL !== candidate.relayUrl) {
|
|
717
716
|
process.env.TERMPILOT_RELAY_URL = candidate.relayUrl;
|
|
718
717
|
}
|
|
719
|
-
return
|
|
718
|
+
return readJsonOrThrow(response, message);
|
|
720
719
|
}
|
|
721
720
|
const detail = lastError instanceof Error ? lastError.message : "\u672A\u77E5\u7F51\u7EDC\u9519\u8BEF";
|
|
722
721
|
throw new Error(`${message}: \u65E0\u6CD5\u8FDE\u63A5 relay (${lastOrigin})\uFF0C${detail}`);
|
|
@@ -996,8 +995,9 @@ function applyAgentConfig(config) {
|
|
|
996
995
|
function persistMigratedRelayUrl(deviceId) {
|
|
997
996
|
const migratedRelayUrl = process.env.TERMPILOT_RELAY_URL?.trim();
|
|
998
997
|
if (!migratedRelayUrl) {
|
|
999
|
-
return;
|
|
998
|
+
return false;
|
|
1000
999
|
}
|
|
1000
|
+
let changed = false;
|
|
1001
1001
|
const saved = loadAgentConfig();
|
|
1002
1002
|
if (saved && saved.deviceId === deviceId && saved.relayUrl !== migratedRelayUrl) {
|
|
1003
1003
|
saveAgentConfig({
|
|
@@ -1005,6 +1005,7 @@ function persistMigratedRelayUrl(deviceId) {
|
|
|
1005
1005
|
deviceId
|
|
1006
1006
|
});
|
|
1007
1007
|
console.log(`\u5DF2\u81EA\u52A8\u66F4\u65B0 relay \u5730\u5740\u4E3A: ${migratedRelayUrl}`);
|
|
1008
|
+
changed = true;
|
|
1008
1009
|
}
|
|
1009
1010
|
const runtime = loadAgentRuntime();
|
|
1010
1011
|
if (runtime && runtime.deviceId === deviceId && runtime.relayUrl !== migratedRelayUrl) {
|
|
@@ -1012,7 +1013,9 @@ function persistMigratedRelayUrl(deviceId) {
|
|
|
1012
1013
|
...runtime,
|
|
1013
1014
|
relayUrl: migratedRelayUrl
|
|
1014
1015
|
});
|
|
1016
|
+
changed = true;
|
|
1015
1017
|
}
|
|
1018
|
+
return changed;
|
|
1016
1019
|
}
|
|
1017
1020
|
function printRuntimeStatus(runtime = readRuntimeStatus().runtime) {
|
|
1018
1021
|
if (!runtime) {
|
|
@@ -1061,6 +1064,7 @@ async function waitForPairingCode(deviceId) {
|
|
|
1061
1064
|
return payload;
|
|
1062
1065
|
} catch (error) {
|
|
1063
1066
|
lastError = error;
|
|
1067
|
+
persistMigratedRelayUrl(deviceId);
|
|
1064
1068
|
await delay2(500);
|
|
1065
1069
|
}
|
|
1066
1070
|
}
|
|
@@ -1096,6 +1100,14 @@ async function runStart(argv) {
|
|
|
1096
1100
|
if (pairing) {
|
|
1097
1101
|
console.log(`\u914D\u5BF9\u7801: ${pairing.pairingCode}`);
|
|
1098
1102
|
console.log(`\u6709\u6548\u671F\u81F3: ${pairing.expiresAt}`);
|
|
1103
|
+
} else {
|
|
1104
|
+
const migrated = loadAgentConfig();
|
|
1105
|
+
if (migrated && migrated.deviceId === deviceId && migrated.relayUrl !== existing.runtime.relayUrl) {
|
|
1106
|
+
console.log("\u68C0\u6D4B\u5230\u540E\u53F0 agent \u4ECD\u5728\u4F7F\u7528\u65E7 relay \u5730\u5740\uFF0C\u6B63\u5728\u81EA\u52A8\u91CD\u542F\u540E\u91CD\u8BD5\u3002");
|
|
1107
|
+
await runStop();
|
|
1108
|
+
await runStart(argv);
|
|
1109
|
+
return;
|
|
1110
|
+
}
|
|
1099
1111
|
}
|
|
1100
1112
|
} else {
|
|
1101
1113
|
console.log("\u5982\u9700\u91CD\u65B0\u7ED9\u624B\u673A\u914D\u5BF9\uFF0C\u8BF7\u6267\u884C\uFF1Atermpilot agent --pair");
|