@agentvalet/register 0.4.9 → 0.4.11
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/index.js +50 -76
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -448,55 +448,6 @@ function parseEnvFile(content) {
|
|
|
448
448
|
}
|
|
449
449
|
return result;
|
|
450
450
|
}
|
|
451
|
-
function resolveAgent(envFile = ".env.agentvalet") {
|
|
452
|
-
let agentId;
|
|
453
|
-
let ownerId;
|
|
454
|
-
let apiUrl = "https://api.agentvalet.ai";
|
|
455
|
-
let keyPath;
|
|
456
|
-
const envPath = resolve2(envFile);
|
|
457
|
-
if (existsSync2(envPath)) {
|
|
458
|
-
try {
|
|
459
|
-
const vars = parseEnvFile(readFileSync2(envPath, "utf-8"));
|
|
460
|
-
agentId = vars["AGENTVALET_AGENT_ID"];
|
|
461
|
-
ownerId = vars["AGENTVALET_OWNER_ID"];
|
|
462
|
-
apiUrl = vars["AGENTVALET_API_URL"] ?? apiUrl;
|
|
463
|
-
keyPath = vars["AGENTVALET_PRIVATE_KEY_PATH"];
|
|
464
|
-
} catch {
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
if (!agentId || !ownerId || !keyPath) {
|
|
468
|
-
const localConfigPath = join(process.cwd(), ".agentvalet", "config.json");
|
|
469
|
-
if (existsSync2(localConfigPath)) {
|
|
470
|
-
try {
|
|
471
|
-
const local = JSON.parse(readFileSync2(localConfigPath, "utf-8"));
|
|
472
|
-
agentId = agentId ?? local["agent_id"];
|
|
473
|
-
apiUrl = local["proxy_url"] ?? apiUrl;
|
|
474
|
-
keyPath = keyPath ?? join(process.cwd(), ".agentvalet", "agent.key");
|
|
475
|
-
} catch {
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
try {
|
|
479
|
-
const global = getStoredConfig();
|
|
480
|
-
if (!ownerId) ownerId = global.ownerId ?? void 0;
|
|
481
|
-
} catch {
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
if (!agentId || !ownerId || !keyPath) {
|
|
485
|
-
try {
|
|
486
|
-
const global = getStoredConfig();
|
|
487
|
-
agentId = agentId ?? global.lastAgentId ?? void 0;
|
|
488
|
-
ownerId = ownerId ?? global.ownerId ?? void 0;
|
|
489
|
-
keyPath = keyPath ?? global.lastKeyPath ?? void 0;
|
|
490
|
-
apiUrl = global.proxyUrl ?? apiUrl;
|
|
491
|
-
} catch {
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
if (!agentId || !ownerId || !keyPath) {
|
|
495
|
-
process.stderr.write(NO_AGENT_MSG + "\n");
|
|
496
|
-
process.exit(1);
|
|
497
|
-
}
|
|
498
|
-
return { agentId, ownerId, keyPath, apiUrl };
|
|
499
|
-
}
|
|
500
451
|
function tryResolveAgent(envFile = ".env.agentvalet") {
|
|
501
452
|
let agentId;
|
|
502
453
|
let ownerId;
|
|
@@ -586,7 +537,12 @@ async function runRefresh(options) {
|
|
|
586
537
|
} catch {
|
|
587
538
|
}
|
|
588
539
|
}
|
|
589
|
-
const
|
|
540
|
+
const creds = tryResolveAgent(options.envFile);
|
|
541
|
+
if (!creds || !existsSync3(resolve3(creds.keyPath))) {
|
|
542
|
+
console.error(" \u2717 No agent registered.\n Run the following command first to register an agent in this directory:\n\n npx @agentvalet/register\n");
|
|
543
|
+
process.exit(1);
|
|
544
|
+
}
|
|
545
|
+
const { agentId, ownerId, keyPath, apiUrl } = creds;
|
|
590
546
|
let privateKeyPem;
|
|
591
547
|
try {
|
|
592
548
|
privateKeyPem = readFileSync3(keyPath, "utf-8");
|
|
@@ -1663,6 +1619,7 @@ function cleanLocally() {
|
|
|
1663
1619
|
}
|
|
1664
1620
|
console.log(chalk11.green(" \u2713 Cleaned CLAUDE.md, .mcp.json, .claude/settings.local.json"));
|
|
1665
1621
|
}
|
|
1622
|
+
var SSE_READ_TIMEOUT_MS = 25e3;
|
|
1666
1623
|
async function pollForApproval(apiUrl, revocationToken, timeoutMs) {
|
|
1667
1624
|
const streamUrl = `${apiUrl}/v1/revoke-request/stream/${revocationToken}`;
|
|
1668
1625
|
const deadline = Date.now() + timeoutMs;
|
|
@@ -1675,47 +1632,64 @@ async function pollForApproval(apiUrl, revocationToken, timeoutMs) {
|
|
|
1675
1632
|
}
|
|
1676
1633
|
}
|
|
1677
1634
|
function connect() {
|
|
1678
|
-
if (Date.now() > deadline) {
|
|
1635
|
+
if (settled || Date.now() > deadline) {
|
|
1679
1636
|
done("timeout");
|
|
1680
1637
|
return;
|
|
1681
1638
|
}
|
|
1682
|
-
|
|
1639
|
+
const controller = new AbortController();
|
|
1640
|
+
let readTimer = setTimeout(() => controller.abort(), SSE_READ_TIMEOUT_MS);
|
|
1641
|
+
function resetReadTimer() {
|
|
1642
|
+
clearTimeout(readTimer);
|
|
1643
|
+
readTimer = setTimeout(() => controller.abort(), SSE_READ_TIMEOUT_MS);
|
|
1644
|
+
}
|
|
1645
|
+
fetch(streamUrl, { signal: controller.signal, headers: { Accept: "text/event-stream" } }).then(async (res) => {
|
|
1683
1646
|
if (!res.ok || !res.body) {
|
|
1684
|
-
|
|
1647
|
+
clearTimeout(readTimer);
|
|
1648
|
+
if (!settled) setTimeout(connect, 3e3);
|
|
1685
1649
|
return;
|
|
1686
1650
|
}
|
|
1687
1651
|
const reader = res.body.getReader();
|
|
1688
1652
|
const decoder = new TextDecoder();
|
|
1689
1653
|
let buf = "";
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
if (
|
|
1701
|
-
|
|
1702
|
-
|
|
1654
|
+
try {
|
|
1655
|
+
while (true) {
|
|
1656
|
+
const { done: streamDone, value } = await reader.read();
|
|
1657
|
+
resetReadTimer();
|
|
1658
|
+
if (streamDone) break;
|
|
1659
|
+
buf += decoder.decode(value, { stream: true });
|
|
1660
|
+
const lines = buf.split("\n");
|
|
1661
|
+
buf = lines.pop() ?? "";
|
|
1662
|
+
for (const line of lines) {
|
|
1663
|
+
if (line.startsWith(":")) continue;
|
|
1664
|
+
if (!line.startsWith("data: ")) continue;
|
|
1665
|
+
try {
|
|
1666
|
+
const evt = JSON.parse(line.slice(6));
|
|
1667
|
+
if (evt.status === "approved") {
|
|
1668
|
+
clearTimeout(readTimer);
|
|
1669
|
+
done("approved");
|
|
1670
|
+
return;
|
|
1671
|
+
}
|
|
1672
|
+
if (evt.status === "rejected") {
|
|
1673
|
+
clearTimeout(readTimer);
|
|
1674
|
+
done("rejected");
|
|
1675
|
+
return;
|
|
1676
|
+
}
|
|
1677
|
+
if (evt.status === "timeout") {
|
|
1678
|
+
clearTimeout(readTimer);
|
|
1679
|
+
done("timeout");
|
|
1680
|
+
return;
|
|
1681
|
+
}
|
|
1682
|
+
} catch {
|
|
1703
1683
|
}
|
|
1704
|
-
if (evt.status === "rejected") {
|
|
1705
|
-
done("rejected");
|
|
1706
|
-
return;
|
|
1707
|
-
}
|
|
1708
|
-
if (evt.status === "timeout") {
|
|
1709
|
-
done("timeout");
|
|
1710
|
-
return;
|
|
1711
|
-
}
|
|
1712
|
-
} catch {
|
|
1713
1684
|
}
|
|
1714
1685
|
}
|
|
1686
|
+
} finally {
|
|
1687
|
+
clearTimeout(readTimer);
|
|
1715
1688
|
}
|
|
1716
1689
|
if (!settled) setTimeout(connect, 1e3);
|
|
1717
1690
|
}).catch(() => {
|
|
1718
|
-
|
|
1691
|
+
clearTimeout(readTimer);
|
|
1692
|
+
if (!settled) setTimeout(connect, 1e3);
|
|
1719
1693
|
});
|
|
1720
1694
|
}
|
|
1721
1695
|
connect();
|