alink-cli 0.8.5 → 0.8.7
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/README.md +38 -31
- package/dist/bin.mjs +123 -6
- package/dist/bin.mjs.map +1 -1
- package/dist/daemon.js +33 -3
- package/package.json +1 -1
package/dist/daemon.js
CHANGED
|
@@ -24275,7 +24275,7 @@ async function pairForCredential() {
|
|
|
24275
24275
|
});
|
|
24276
24276
|
try {
|
|
24277
24277
|
persistCredential(token);
|
|
24278
|
-
console.log(`[daemon] \u5DF2\u7ED1\u5B9A\u5230\u4F60\u7684\u8D26\u53F7 \u2014\u2014 \u51ED\u8BC1\u5DF2\u4FDD\u5B58\u5230 ${CREDENTIAL_FILE}\uFF080600\uFF09\uFF0C\u4E4B\u540E\u88F8\u8DD1
|
|
24278
|
+
console.log(`[daemon] \u5DF2\u7ED1\u5B9A\u5230\u4F60\u7684\u8D26\u53F7 \u2014\u2014 \u51ED\u8BC1\u5DF2\u4FDD\u5B58\u5230 ${CREDENTIAL_FILE}\uFF080600\uFF09\uFF0C\u4E4B\u540E\u88F8\u8DD1 alink-cli \u76F4\u63A5\u590D\u7528\u3002`);
|
|
24279
24279
|
} catch (err) {
|
|
24280
24280
|
console.error(
|
|
24281
24281
|
`[daemon] \u51ED\u8BC1\u5199\u5165 ${CREDENTIAL_FILE} \u5931\u8D25\uFF08${err instanceof Error ? err.message : err}\uFF09\u2014\u2014 \u672C\u6B21\u4ECD\u53EF\u7528\uFF0C\u4F46\u4E0B\u6B21\u542F\u52A8\u9700\u8981\u91CD\u65B0\u914D\u5BF9\u3002`
|
|
@@ -24357,6 +24357,30 @@ function webLink(hub, token) {
|
|
|
24357
24357
|
u.search = `?token=${encodeURIComponent(token)}`;
|
|
24358
24358
|
return u.toString();
|
|
24359
24359
|
}
|
|
24360
|
+
function hubHttpUrl(hub) {
|
|
24361
|
+
if (PUBLIC_BASE) return PUBLIC_BASE.replace(/\/$/, "");
|
|
24362
|
+
const u = new URL(hub);
|
|
24363
|
+
u.protocol = u.protocol === "wss:" ? "https:" : "http:";
|
|
24364
|
+
u.pathname = "";
|
|
24365
|
+
u.search = "";
|
|
24366
|
+
return u.toString().replace(/\/$/, "");
|
|
24367
|
+
}
|
|
24368
|
+
async function uploadEnckey(hub, machineToken, machineId, enckey) {
|
|
24369
|
+
const url3 = `${hubHttpUrl(hub)}/api/machines/${encodeURIComponent(machineId)}/enckey`;
|
|
24370
|
+
const response = await fetch(url3, {
|
|
24371
|
+
method: "POST",
|
|
24372
|
+
headers: {
|
|
24373
|
+
"Content-Type": "application/json",
|
|
24374
|
+
"X-Requested-With": "agentlink",
|
|
24375
|
+
Authorization: `Bearer ${machineToken}`
|
|
24376
|
+
},
|
|
24377
|
+
body: JSON.stringify({ enckey })
|
|
24378
|
+
});
|
|
24379
|
+
if (!response.ok) {
|
|
24380
|
+
const body = await response.text().catch(() => "");
|
|
24381
|
+
throw new Error(`enckey upload failed: ${response.status} ${body.slice(0, 200)}`);
|
|
24382
|
+
}
|
|
24383
|
+
}
|
|
24360
24384
|
async function probeVersion(bin) {
|
|
24361
24385
|
const out = await captureCommand(bin, ["--version"], 3e3);
|
|
24362
24386
|
const first = out?.trim().split("\n")[0]?.trim();
|
|
@@ -24743,7 +24767,7 @@ function connect2() {
|
|
|
24743
24767
|
if (msg.type === "error" && msg.error === "unsupported_version") {
|
|
24744
24768
|
clearTimeout(helloTimer);
|
|
24745
24769
|
const supported = Array.isArray(msg.supported) ? msg.supported.join(", ") : "?";
|
|
24746
|
-
console.error(`[daemon] the hub rejected this connection: it only speaks protocol version(s) ${supported}, this daemon offers v${PROTOCOL_VERSION2}. Upgrade the older side (
|
|
24770
|
+
console.error(`[daemon] the hub rejected this connection: it only speaks protocol version(s) ${supported}, this daemon offers v${PROTOCOL_VERSION2}. Upgrade the older side (npm install -g alink-cli@latest / npm install -g agentlink-hub@latest).`);
|
|
24747
24771
|
process.exit(1);
|
|
24748
24772
|
}
|
|
24749
24773
|
if (msg.type === "hello") {
|
|
@@ -24760,6 +24784,12 @@ function connect2() {
|
|
|
24760
24784
|
send(ws, { type: "register", hostname: hostname3(), daemonVersion: ownVersion(), dirs: DIRS, home: homedir6(), agents, e2e: CRED.enckey !== void 0 });
|
|
24761
24785
|
console.log(`[daemon] registered. Waiting for work pushed from the hub...`);
|
|
24762
24786
|
writeStatus("connected");
|
|
24787
|
+
if (CRED.multi && CRED.machineId && ENCKEY) {
|
|
24788
|
+
uploadEnckey(HUB, TOKEN, CRED.machineId, ENCKEY).then(
|
|
24789
|
+
() => console.log(`[daemon] enckey uploaded to hub for cross-device recovery`),
|
|
24790
|
+
(err) => console.error(`[daemon] enckey upload failed: ${err instanceof Error ? err.message : err}`)
|
|
24791
|
+
);
|
|
24792
|
+
}
|
|
24763
24793
|
if (printedLink) return;
|
|
24764
24794
|
printedLink = true;
|
|
24765
24795
|
if (CRED.multi) {
|
|
@@ -24835,7 +24865,7 @@ function connect2() {
|
|
|
24835
24865
|
process.exit(0);
|
|
24836
24866
|
}
|
|
24837
24867
|
if (code === 4408) {
|
|
24838
|
-
console.error(`[daemon] signed off from your AgentLink app (close 4408). The saved credential is untouched \u2014 run \`
|
|
24868
|
+
console.error(`[daemon] signed off from your AgentLink app (close 4408). The saved credential is untouched \u2014 run \`alink-cli\` to reconnect.`);
|
|
24839
24869
|
process.exit(0);
|
|
24840
24870
|
}
|
|
24841
24871
|
if (code === 4401) {
|
package/package.json
CHANGED