@agentvalet/register 0.4.14 → 0.4.15
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 +100 -130
- package/package.json +9 -10
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
} from "./chunk-2EFPJNYK.js";
|
|
10
10
|
|
|
11
11
|
// src/index.ts
|
|
12
|
-
import { createRequire } from "module";
|
|
12
|
+
import { createRequire as createRequire2 } from "module";
|
|
13
13
|
import { Command as Command5 } from "commander";
|
|
14
14
|
import chalk12 from "chalk";
|
|
15
15
|
|
|
@@ -840,97 +840,108 @@ import chalk7 from "chalk";
|
|
|
840
840
|
import ora from "ora";
|
|
841
841
|
import prompts3 from "prompts";
|
|
842
842
|
|
|
843
|
-
// src/auth/
|
|
844
|
-
import {
|
|
843
|
+
// src/auth/browser-flow.ts
|
|
844
|
+
import { createServer } from "http";
|
|
845
|
+
import { createRequire } from "module";
|
|
845
846
|
import open from "open";
|
|
846
847
|
import chalk4 from "chalk";
|
|
847
|
-
var
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
848
|
+
var _require = createRequire(import.meta.url);
|
|
849
|
+
var FUNCTIONS_URL = "https://jmodblrolfoavrxqgbps.supabase.co/functions/v1";
|
|
850
|
+
var SUPABASE_ANON_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imptb2RibHJvbGZvYXZyeHFnYnBzIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzQwODIzNzYsImV4cCI6MjA4OTY1ODM3Nn0.xQQiYHXbDsHyiTd5TsAfXtNWBUGkT4eO7Ew9UH8n6UE";
|
|
851
|
+
var APP_URL = "https://app.agentvalet.ai";
|
|
852
|
+
var CALLBACK_TIMEOUT_MS = 12e4;
|
|
853
|
+
async function findFreePort() {
|
|
854
|
+
return new Promise((resolve4, reject) => {
|
|
855
|
+
const server = createServer();
|
|
856
|
+
server.listen(0, "127.0.0.1", () => {
|
|
857
|
+
const addr = server.address();
|
|
858
|
+
if (!addr || typeof addr === "string") {
|
|
859
|
+
reject(new Error("Could not bind port"));
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
const port = addr.port;
|
|
863
|
+
server.close(() => resolve4(port));
|
|
864
|
+
});
|
|
865
|
+
server.on("error", reject);
|
|
865
866
|
});
|
|
866
|
-
const tokenAuth = await auth({ type: "oauth" });
|
|
867
|
-
return {
|
|
868
|
-
token: tokenAuth.token,
|
|
869
|
-
scopes: tokenAuth.scopes ?? []
|
|
870
|
-
};
|
|
871
867
|
}
|
|
872
|
-
async function
|
|
873
|
-
const
|
|
868
|
+
async function callCliAuth(body) {
|
|
869
|
+
const res = await fetch(`${FUNCTIONS_URL}/cli-auth`, {
|
|
870
|
+
method: "POST",
|
|
874
871
|
headers: {
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
}
|
|
872
|
+
"Content-Type": "application/json",
|
|
873
|
+
"apikey": SUPABASE_ANON_KEY
|
|
874
|
+
},
|
|
875
|
+
body: JSON.stringify(body)
|
|
878
876
|
});
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
877
|
+
const json = await res.json();
|
|
878
|
+
if (!res.ok) throw new Error(json.error ?? `HTTP ${res.status}`);
|
|
879
|
+
return json;
|
|
880
|
+
}
|
|
881
|
+
async function browserLogin() {
|
|
882
|
+
const state = crypto.randomUUID();
|
|
883
|
+
const port = await findFreePort();
|
|
884
|
+
await callCliAuth({ action: "init", state, port });
|
|
885
|
+
const codePromise = new Promise((resolve4, reject) => {
|
|
886
|
+
const server = createServer((req, res) => {
|
|
887
|
+
const url = new URL(req.url ?? "/", `http://127.0.0.1:${port}`);
|
|
888
|
+
if (url.pathname !== "/callback") {
|
|
889
|
+
res.writeHead(404);
|
|
890
|
+
res.end();
|
|
891
|
+
return;
|
|
888
892
|
}
|
|
893
|
+
const code2 = url.searchParams.get("code");
|
|
894
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
895
|
+
res.end(
|
|
896
|
+
"<!doctype html><html><head><title>AgentValet CLI</title><style>body{font-family:system-ui,sans-serif;display:flex;align-items:center;justify-content:center;min-height:100vh;margin:0;background:#060e1a;color:rgba(255,255,255,.87)}h2{margin:0 0 8px}p{margin:0;color:rgba(255,255,255,.45);font-size:14px}</style></head><body><div style='text-align:center'><h2 style='color:#34c97b'>✓ Authorized</h2><p>You can close this tab and return to your terminal.</p></div></body></html>"
|
|
897
|
+
);
|
|
898
|
+
server.close();
|
|
899
|
+
if (code2) resolve4(code2);
|
|
900
|
+
else reject(new Error("No code in callback URL"));
|
|
889
901
|
});
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
902
|
+
server.listen(port, "127.0.0.1");
|
|
903
|
+
server.on("error", (err) => reject(err));
|
|
904
|
+
setTimeout(() => {
|
|
905
|
+
server.close();
|
|
906
|
+
reject(new Error("Timed out waiting for browser authorization (2 min)"));
|
|
907
|
+
}, CALLBACK_TIMEOUT_MS);
|
|
908
|
+
});
|
|
909
|
+
const authUrl = `${APP_URL}/cli-auth?state=${state}&port=${port}`;
|
|
910
|
+
console.log(chalk4.dim(`
|
|
911
|
+
Opening browser to authorize...`));
|
|
912
|
+
console.log(chalk4.dim(` URL: ${authUrl}
|
|
913
|
+
`));
|
|
914
|
+
await open(authUrl).catch(() => {
|
|
915
|
+
console.log(chalk4.yellow(` Could not open browser automatically.`));
|
|
916
|
+
console.log(chalk4.yellow(` Please open this URL in your browser:
|
|
917
|
+
`));
|
|
918
|
+
console.log(` ${authUrl}
|
|
919
|
+
`);
|
|
920
|
+
});
|
|
921
|
+
const code = await codePromise;
|
|
922
|
+
const result = await callCliAuth({ action: "exchange", state, code });
|
|
923
|
+
return {
|
|
924
|
+
ownerId: result.owner_id,
|
|
925
|
+
orgId: result.org_id ?? null,
|
|
926
|
+
cliToken: result.cli_token,
|
|
927
|
+
email: result.email ?? null,
|
|
928
|
+
proxyUrl: result.proxy_url ?? "https://api.agentvalet.ai"
|
|
929
|
+
};
|
|
896
930
|
}
|
|
897
931
|
|
|
898
932
|
// src/api/agentvalet.ts
|
|
899
933
|
var SUPABASE_URL = "https://jmodblrolfoavrxqgbps.supabase.co";
|
|
900
|
-
var
|
|
901
|
-
var
|
|
934
|
+
var SUPABASE_ANON_KEY2 = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imptb2RibHJvbGZvYXZyeHFnYnBzIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzQwODIzNzYsImV4cCI6MjA4OTY1ODM3Nn0.xQQiYHXbDsHyiTd5TsAfXtNWBUGkT4eO7Ew9UH8n6UE";
|
|
935
|
+
var FUNCTIONS_URL2 = `${SUPABASE_URL}/functions/v1`;
|
|
902
936
|
var baseHeaders = {
|
|
903
937
|
"Content-Type": "application/json",
|
|
904
|
-
"apikey":
|
|
938
|
+
"apikey": SUPABASE_ANON_KEY2
|
|
905
939
|
};
|
|
906
|
-
async function createOrFindAccount(params) {
|
|
907
|
-
const controller = new AbortController();
|
|
908
|
-
const timeout = setTimeout(() => controller.abort(), 1e4);
|
|
909
|
-
try {
|
|
910
|
-
const response = await fetch(`${FUNCTIONS_URL}/cli-account`, {
|
|
911
|
-
method: "POST",
|
|
912
|
-
headers: baseHeaders,
|
|
913
|
-
body: JSON.stringify(params),
|
|
914
|
-
signal: controller.signal
|
|
915
|
-
});
|
|
916
|
-
if (!response.ok) {
|
|
917
|
-
const error = await response.json().catch(() => ({}));
|
|
918
|
-
throw new Error(`Account setup failed: ${response.status} ${error.error ?? ""}`);
|
|
919
|
-
}
|
|
920
|
-
return response.json();
|
|
921
|
-
} catch (err) {
|
|
922
|
-
clearTimeout(timeout);
|
|
923
|
-
if (err?.name === "AbortError") throw new Error("Request timed out \u2014 is the AgentValet API reachable?");
|
|
924
|
-
throw err;
|
|
925
|
-
} finally {
|
|
926
|
-
clearTimeout(timeout);
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
940
|
async function registerAgent2(params, apiKey) {
|
|
930
941
|
const controller = new AbortController();
|
|
931
942
|
const timeout = setTimeout(() => controller.abort(), 1e4);
|
|
932
943
|
try {
|
|
933
|
-
const response = await fetch(`${
|
|
944
|
+
const response = await fetch(`${FUNCTIONS_URL2}/cli-register-agent`, {
|
|
934
945
|
method: "POST",
|
|
935
946
|
headers: {
|
|
936
947
|
...baseHeaders,
|
|
@@ -956,7 +967,7 @@ async function getAccount(apiKey) {
|
|
|
956
967
|
const controller = new AbortController();
|
|
957
968
|
const timeout = setTimeout(() => controller.abort(), 1e4);
|
|
958
969
|
try {
|
|
959
|
-
const response = await fetch(`${
|
|
970
|
+
const response = await fetch(`${FUNCTIONS_URL2}/cli-account`, {
|
|
960
971
|
headers: {
|
|
961
972
|
...baseHeaders,
|
|
962
973
|
"Authorization": `Bearer ${apiKey}`
|
|
@@ -1343,10 +1354,10 @@ async function runOnboard() {
|
|
|
1343
1354
|
name: "authMethod",
|
|
1344
1355
|
message: "How would you like to sign in?",
|
|
1345
1356
|
choices: [
|
|
1346
|
-
{ title: "Sign in with
|
|
1357
|
+
{ title: "Sign in with your browser (opens app.agentvalet.ai)", value: "browser" },
|
|
1347
1358
|
{ title: "Paste Owner ID from app.agentvalet.ai/settings", value: "ownerid" }
|
|
1348
1359
|
],
|
|
1349
|
-
hint: "No
|
|
1360
|
+
hint: "No account yet? Visit app.agentvalet.ai to sign up first"
|
|
1350
1361
|
});
|
|
1351
1362
|
if (authMethod === void 0) {
|
|
1352
1363
|
process.exit(0);
|
|
@@ -1355,65 +1366,24 @@ async function runOnboard() {
|
|
|
1355
1366
|
await ownerIdFlow();
|
|
1356
1367
|
return;
|
|
1357
1368
|
}
|
|
1358
|
-
let
|
|
1359
|
-
let githubToken;
|
|
1369
|
+
let credentials;
|
|
1360
1370
|
try {
|
|
1361
|
-
|
|
1362
|
-
githubToken = result.token;
|
|
1371
|
+
credentials = await browserLogin();
|
|
1363
1372
|
} catch (err) {
|
|
1364
|
-
console.error(chalk7.red(`
|
|
1365
|
-
|
|
1366
|
-
}
|
|
1367
|
-
spinner = ora(" Fetching your GitHub profile...").start();
|
|
1368
|
-
let githubUser;
|
|
1369
|
-
try {
|
|
1370
|
-
githubUser = await getGitHubUser(githubToken);
|
|
1371
|
-
spinner.succeed(` GitHub: ${chalk7.bold("@" + githubUser.login)}`);
|
|
1372
|
-
} catch (err) {
|
|
1373
|
-
spinner.fail(` Failed to fetch GitHub profile: ${err.message}`);
|
|
1374
|
-
process.exit(1);
|
|
1375
|
-
}
|
|
1376
|
-
if (!githubUser.email) {
|
|
1377
|
-
const { email } = await prompts3({
|
|
1378
|
-
type: "text",
|
|
1379
|
-
name: "email",
|
|
1380
|
-
message: "Your email address (not visible on GitHub):",
|
|
1381
|
-
validate: (v) => v.includes("@") || "Please enter a valid email"
|
|
1382
|
-
});
|
|
1383
|
-
if (email === void 0) {
|
|
1384
|
-
process.exit(0);
|
|
1385
|
-
}
|
|
1386
|
-
githubUser.email = email;
|
|
1387
|
-
}
|
|
1388
|
-
spinner = ora(" Setting up your AgentValet account...").start();
|
|
1389
|
-
let account;
|
|
1390
|
-
try {
|
|
1391
|
-
account = await createOrFindAccount({
|
|
1392
|
-
github_token: githubToken,
|
|
1393
|
-
github_username: githubUser.login,
|
|
1394
|
-
email: githubUser.email,
|
|
1395
|
-
display_name: githubUser.name ?? githubUser.login,
|
|
1396
|
-
avatar_url: githubUser.avatar_url
|
|
1397
|
-
});
|
|
1398
|
-
if (account.is_new_account) {
|
|
1399
|
-
spinner.succeed(" AgentValet account created");
|
|
1400
|
-
} else {
|
|
1401
|
-
spinner.succeed(" Existing AgentValet account found");
|
|
1402
|
-
}
|
|
1403
|
-
} catch (err) {
|
|
1404
|
-
spinner.fail(` Account setup failed: ${err.message}`);
|
|
1373
|
+
console.error(chalk7.red(`
|
|
1374
|
+
\u2717 Authentication failed: ${err.message}`));
|
|
1405
1375
|
process.exit(1);
|
|
1406
1376
|
}
|
|
1377
|
+
console.log(chalk7.green(` \u2713 Signed in${credentials.email ? " as " + chalk7.bold(credentials.email) : ""}`));
|
|
1407
1378
|
saveConfig({
|
|
1408
|
-
apiKey:
|
|
1409
|
-
ownerId:
|
|
1410
|
-
orgId:
|
|
1411
|
-
proxyUrl:
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
cliToken: account.cli_token
|
|
1379
|
+
apiKey: credentials.ownerId,
|
|
1380
|
+
ownerId: credentials.ownerId,
|
|
1381
|
+
orgId: credentials.orgId ?? void 0,
|
|
1382
|
+
proxyUrl: credentials.proxyUrl,
|
|
1383
|
+
email: credentials.email ?? "",
|
|
1384
|
+
cliToken: credentials.cliToken
|
|
1415
1385
|
});
|
|
1416
|
-
await registerAgentFlow(
|
|
1386
|
+
await registerAgentFlow(credentials.cliToken, credentials.ownerId);
|
|
1417
1387
|
}
|
|
1418
1388
|
async function ownerIdFlow() {
|
|
1419
1389
|
console.log("");
|
|
@@ -2013,7 +1983,7 @@ function uninstallCommand() {
|
|
|
2013
1983
|
}
|
|
2014
1984
|
|
|
2015
1985
|
// src/index.ts
|
|
2016
|
-
var require2 =
|
|
1986
|
+
var require2 = createRequire2(import.meta.url);
|
|
2017
1987
|
var { version } = require2("../package.json");
|
|
2018
1988
|
function collectScope(value, previous) {
|
|
2019
1989
|
return [...previous, value];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentvalet/register",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.15",
|
|
4
4
|
"description": "Self-register AI agents with AgentValet",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -10,13 +10,6 @@
|
|
|
10
10
|
"dist",
|
|
11
11
|
"README.md"
|
|
12
12
|
],
|
|
13
|
-
"scripts": {
|
|
14
|
-
"build": "tsup src/index.ts --format esm --dts --clean --shims",
|
|
15
|
-
"dev": "tsx src/index.ts",
|
|
16
|
-
"test": "vitest run",
|
|
17
|
-
"typecheck": "tsc --noEmit",
|
|
18
|
-
"prepublishOnly": "pnpm build"
|
|
19
|
-
},
|
|
20
13
|
"dependencies": {
|
|
21
14
|
"@agentvalet/mcp-server": "*",
|
|
22
15
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
@@ -55,5 +48,11 @@
|
|
|
55
48
|
"valet",
|
|
56
49
|
"agentvalet"
|
|
57
50
|
],
|
|
58
|
-
"license": "MIT"
|
|
59
|
-
|
|
51
|
+
"license": "MIT",
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "tsup src/index.ts --format esm --dts --clean --shims",
|
|
54
|
+
"dev": "tsx src/index.ts",
|
|
55
|
+
"test": "vitest run",
|
|
56
|
+
"typecheck": "tsc --noEmit"
|
|
57
|
+
}
|
|
58
|
+
}
|