@agentvalet/register 0.5.0 → 0.5.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.
Files changed (2) hide show
  1. package/dist/index.js +12 -77
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -874,9 +874,18 @@ async function callCliAuth(body) {
874
874
  },
875
875
  body: JSON.stringify(body)
876
876
  });
877
- const json = await res.json();
878
- if (!res.ok) throw new Error(json.error ?? `HTTP ${res.status}`);
879
- return json;
877
+ const text = await res.text();
878
+ let json = null;
879
+ try {
880
+ json = text ? JSON.parse(text) : null;
881
+ } catch {
882
+ }
883
+ if (!res.ok) {
884
+ const err = json?.error ?? text ?? `HTTP ${res.status}`;
885
+ const detail = json?.detail ?? "";
886
+ throw new Error(detail ? `${err}: ${detail}` : err);
887
+ }
888
+ return json ?? {};
880
889
  }
881
890
  async function browserLogin() {
882
891
  const state = crypto.randomUUID();
@@ -964,30 +973,6 @@ async function registerAgent2(params, apiKey) {
964
973
  clearTimeout(timeout);
965
974
  }
966
975
  }
967
- async function getAccount(apiKey) {
968
- const controller = new AbortController();
969
- const timeout = setTimeout(() => controller.abort(), 1e4);
970
- try {
971
- const response = await fetch(`${FUNCTIONS_URL2}/cli-account`, {
972
- headers: {
973
- ...baseHeaders,
974
- "Authorization": `Bearer ${apiKey}`
975
- },
976
- signal: controller.signal
977
- });
978
- if (!response.ok) {
979
- const error = await response.json().catch(() => ({}));
980
- throw new Error(`Failed to fetch account: ${response.status} ${error.error ?? ""}`);
981
- }
982
- return response.json();
983
- } catch (err) {
984
- clearTimeout(timeout);
985
- if (err?.name === "AbortError") throw new Error("Request timed out \u2014 is the AgentValet API reachable?");
986
- throw err;
987
- } finally {
988
- clearTimeout(timeout);
989
- }
990
- }
991
976
 
992
977
  // src/config/local.ts
993
978
  import { mkdir as mkdir2, writeFile as writeFile2, appendFile, readFile } from "fs/promises";
@@ -1418,23 +1403,6 @@ async function runOnboard(opts = {}) {
1418
1403
  await registerAgentFlow(stored.cliToken, stored.ownerId, scope);
1419
1404
  return;
1420
1405
  }
1421
- const { authMethod } = await prompts3({
1422
- type: "select",
1423
- name: "authMethod",
1424
- message: "How would you like to sign in?",
1425
- choices: [
1426
- { title: "Sign in with your browser (opens app.agentvalet.ai)", value: "browser" },
1427
- { title: "Paste Owner ID from app.agentvalet.ai/settings", value: "ownerid" }
1428
- ],
1429
- hint: "No account yet? Visit app.agentvalet.ai to sign up first"
1430
- });
1431
- if (authMethod === void 0) {
1432
- process.exit(0);
1433
- }
1434
- if (authMethod === "ownerid") {
1435
- await ownerIdFlow(scope);
1436
- return;
1437
- }
1438
1406
  let credentials;
1439
1407
  try {
1440
1408
  credentials = await browserLogin();
@@ -1454,39 +1422,6 @@ async function runOnboard(opts = {}) {
1454
1422
  });
1455
1423
  await registerAgentFlow(credentials.cliToken, credentials.ownerId, scope);
1456
1424
  }
1457
- async function ownerIdFlow(scope) {
1458
- console.log("");
1459
- console.log(chalk7.dim(" Find your Owner ID at: ") + chalk7.cyan.underline("https://app.agentvalet.ai/settings"));
1460
- console.log("");
1461
- const { ownerId } = await prompts3({
1462
- type: "text",
1463
- name: "ownerId",
1464
- message: "Paste your Owner ID:",
1465
- validate: (v) => v.trim().length > 10 || "Owner ID looks too short"
1466
- });
1467
- if (ownerId === void 0) {
1468
- process.exit(0);
1469
- }
1470
- const spinner = ora(" Verifying Owner ID...").start();
1471
- let account;
1472
- try {
1473
- account = await getAccount(ownerId.trim());
1474
- spinner.succeed(` Account verified \u2014 plan: ${chalk7.bold(account.plan)}`);
1475
- } catch (err) {
1476
- spinner.fail(` Could not verify Owner ID: ${err.message}`);
1477
- console.log(chalk7.dim(" Make sure you copied the full Owner ID from app.agentvalet.ai/settings"));
1478
- process.exit(1);
1479
- }
1480
- saveConfig({
1481
- apiKey: account.owner_id,
1482
- ownerId: account.owner_id,
1483
- orgId: account.org_id,
1484
- proxyUrl: "https://api.agentvalet.ai",
1485
- email: account.email ?? "",
1486
- cliToken: account.cli_token
1487
- });
1488
- await registerAgentFlow(account.cli_token, account.owner_id, scope);
1489
- }
1490
1425
  async function registerAgentFlow(apiKey, ownerId, scope = "user") {
1491
1426
  const hostname = os3.hostname().split(".")[0];
1492
1427
  const dirName = process.cwd().split("/").pop() ?? process.cwd().split("\\").pop() ?? "agent";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentvalet/register",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Self-register AI agents with AgentValet",
5
5
  "type": "module",
6
6
  "bin": {