@agentvalet/register 0.3.9 → 0.4.1

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 +106 -47
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -193,7 +193,7 @@ async function saveOutput(opts) {
193
193
  // src/commands/refresh.ts
194
194
  import { readFileSync as readFileSync2, writeFileSync as writeFileSync2, existsSync as existsSync2, mkdirSync, statSync } from "fs";
195
195
  import { createSign, createPrivateKey } from "crypto";
196
- import { dirname as dirname2, resolve as resolve2 } from "path";
196
+ import { dirname as dirname2, resolve as resolve2, join } from "path";
197
197
 
198
198
  // src/lib/skill-writer.ts
199
199
  import { existsSync, writeFileSync } from "fs";
@@ -332,6 +332,24 @@ To refresh this file: \`agentvalet-register refresh\`
332
332
  `;
333
333
  }
334
334
 
335
+ // src/config/store.ts
336
+ import Conf from "conf";
337
+ var store = new Conf({
338
+ projectName: "agentvalet"
339
+ });
340
+ function getStoredConfig() {
341
+ return store.store;
342
+ }
343
+ function saveConfig(config) {
344
+ store.set(config);
345
+ }
346
+ function clearConfig() {
347
+ store.clear();
348
+ }
349
+ function isAuthenticated() {
350
+ return !!store.get("apiKey");
351
+ }
352
+
335
353
  // src/commands/refresh.ts
336
354
  var CLAUDE_START = "<!-- agentvalet:start -->";
337
355
  var CLAUDE_END = "<!-- agentvalet:end -->";
@@ -385,20 +403,44 @@ async function runRefresh(options) {
385
403
  } catch {
386
404
  }
387
405
  }
406
+ let agentId;
407
+ let ownerId;
408
+ let apiUrl = "https://api.agentvalet.ai";
409
+ let keyPath;
388
410
  const envPath = resolve2(options.envFile);
389
- let envVars;
390
- try {
391
- envVars = parseEnvFile(readFileSync2(envPath, "utf-8"));
392
- } catch {
393
- throw new Error(`Cannot read env file: ${envPath}
394
- Run 'agentvalet-register' first to create it.`);
411
+ if (existsSync2(envPath)) {
412
+ try {
413
+ const envVars = parseEnvFile(readFileSync2(envPath, "utf-8"));
414
+ agentId = envVars["AGENTVALET_AGENT_ID"];
415
+ ownerId = envVars["AGENTVALET_OWNER_ID"];
416
+ apiUrl = envVars["AGENTVALET_API_URL"] ?? apiUrl;
417
+ keyPath = envVars["AGENTVALET_PRIVATE_KEY_PATH"];
418
+ } catch {
419
+ }
395
420
  }
396
- const agentId = envVars["AGENTVALET_AGENT_ID"];
397
- const ownerId = envVars["AGENTVALET_OWNER_ID"];
398
- const apiUrl = envVars["AGENTVALET_API_URL"] ?? "https://api.agentvalet.ai";
399
- const keyPath = envVars["AGENTVALET_PRIVATE_KEY_PATH"];
400
421
  if (!agentId || !ownerId || !keyPath) {
401
- throw new Error(`Env file is missing required keys (AGENTVALET_AGENT_ID, AGENTVALET_OWNER_ID, AGENTVALET_PRIVATE_KEY_PATH)`);
422
+ const localConfigPath = join(process.cwd(), ".agentvalet", "config.json");
423
+ if (existsSync2(localConfigPath)) {
424
+ try {
425
+ const local = JSON.parse(readFileSync2(localConfigPath, "utf-8"));
426
+ agentId = agentId ?? local["agent_id"];
427
+ apiUrl = local["proxy_url"] ?? apiUrl;
428
+ keyPath = keyPath ?? join(process.cwd(), ".agentvalet", "agent.key");
429
+ } catch {
430
+ }
431
+ }
432
+ if (!ownerId) {
433
+ try {
434
+ ownerId = getStoredConfig().ownerId ?? void 0;
435
+ } catch {
436
+ }
437
+ }
438
+ }
439
+ if (!agentId || !ownerId || !keyPath) {
440
+ throw new Error(
441
+ `Cannot find agent credentials.
442
+ Run 'npx @agentvalet/register' in this directory first.`
443
+ );
402
444
  }
403
445
  let privateKeyPem;
404
446
  try {
@@ -498,22 +540,43 @@ function ensureMcpJson() {
498
540
  }
499
541
  const servers = mcpConfig.mcpServers ?? {};
500
542
  if (servers["agent-authority"]) return;
543
+ let agentId;
544
+ let ownerId;
545
+ let apiUrl = "https://api.agentvalet.ai";
546
+ let keyPath;
501
547
  const envPath = resolve2(".env.agentvalet");
502
- if (!existsSync2(envPath)) return;
503
- let envVars;
504
- try {
505
- envVars = parseEnvFile(readFileSync2(envPath, "utf-8"));
506
- } catch {
507
- return;
548
+ if (existsSync2(envPath)) {
549
+ try {
550
+ const envVars = parseEnvFile(readFileSync2(envPath, "utf-8"));
551
+ agentId = envVars["AGENTVALET_AGENT_ID"];
552
+ ownerId = envVars["AGENTVALET_OWNER_ID"];
553
+ apiUrl = envVars["AGENTVALET_API_URL"] ?? apiUrl;
554
+ keyPath = envVars["AGENTVALET_PRIVATE_KEY_PATH"];
555
+ } catch {
556
+ }
557
+ }
558
+ if (!agentId || !keyPath) {
559
+ const localConfigPath = join(process.cwd(), ".agentvalet", "config.json");
560
+ if (existsSync2(localConfigPath)) {
561
+ try {
562
+ const local = JSON.parse(readFileSync2(localConfigPath, "utf-8"));
563
+ agentId = agentId ?? local["agent_id"];
564
+ apiUrl = local["proxy_url"] ?? apiUrl;
565
+ keyPath = keyPath ?? join(process.cwd(), ".agentvalet", "agent.key");
566
+ } catch {
567
+ }
568
+ }
569
+ if (!ownerId) {
570
+ try {
571
+ ownerId = getStoredConfig().ownerId ?? void 0;
572
+ } catch {
573
+ }
574
+ }
508
575
  }
509
- const agentId = envVars["AGENTVALET_AGENT_ID"];
510
- const ownerId = envVars["AGENTVALET_OWNER_ID"];
511
- const apiUrl = envVars["AGENTVALET_API_URL"] ?? "https://api.agentvalet.ai";
512
- const keyPath = envVars["AGENTVALET_PRIVATE_KEY_PATH"];
513
576
  if (!agentId || !ownerId || !keyPath) return;
514
577
  servers["agent-authority"] = {
515
578
  command: "npx",
516
- args: ["-y", "@agentvalet/register@0.2.2", "mcp-server"],
579
+ args: ["-y", "@agentvalet/register", "mcp-server"],
517
580
  env: {
518
581
  AGENT_ID: agentId,
519
582
  OWNER_ID: ownerId,
@@ -667,24 +730,6 @@ async function getAccount(apiKey) {
667
730
  }
668
731
  }
669
732
 
670
- // src/config/store.ts
671
- import Conf from "conf";
672
- var store = new Conf({
673
- projectName: "agentvalet"
674
- });
675
- function getStoredConfig() {
676
- return store.store;
677
- }
678
- function saveConfig(config) {
679
- store.set(config);
680
- }
681
- function clearConfig() {
682
- store.clear();
683
- }
684
- function isAuthenticated() {
685
- return !!store.get("apiKey");
686
- }
687
-
688
733
  // src/config/local.ts
689
734
  import { mkdir as mkdir2, writeFile as writeFile2, appendFile, readFile } from "fs/promises";
690
735
  import path2 from "path";
@@ -938,6 +983,7 @@ async function frameworkSetupConsent(detected) {
938
983
  // src/commands/onboard.ts
939
984
  import os3 from "os";
940
985
  import path6 from "path";
986
+ import { writeFile as writeFile5 } from "fs/promises";
941
987
  async function runOnboard() {
942
988
  console.log("");
943
989
  console.log(chalk6.bold(" AgentValet \u2014 Agent Registration"));
@@ -1107,11 +1153,13 @@ async function registerAgentFlow(apiKey, ownerId) {
1107
1153
  spinner.fail(` Registration failed: ${err.message}`);
1108
1154
  process.exit(1);
1109
1155
  }
1156
+ const keyPath = path6.join(process.cwd(), ".agentvalet", "agent.key");
1157
+ const proxyUrl = getStoredConfig().proxyUrl;
1110
1158
  try {
1111
1159
  await writeLocalConfig({
1112
1160
  agentId: agent.agent_id,
1113
1161
  agentName: agent.agent_name,
1114
- proxyUrl: getStoredConfig().proxyUrl,
1162
+ proxyUrl,
1115
1163
  privateKeyPem: agent.private_key_pem
1116
1164
  });
1117
1165
  } catch (err) {
@@ -1119,6 +1167,17 @@ async function registerAgentFlow(apiKey, ownerId) {
1119
1167
  console.log(chalk6.dim(" Agent was registered \u2014 run again to save config locally."));
1120
1168
  process.exit(1);
1121
1169
  }
1170
+ try {
1171
+ const envContent = [
1172
+ "# AgentValet \u2014 generated by agentvalet-register",
1173
+ `AGENTVALET_AGENT_ID=${agent.agent_id}`,
1174
+ `AGENTVALET_OWNER_ID=${ownerId}`,
1175
+ `AGENTVALET_API_URL=${proxyUrl}`,
1176
+ `AGENTVALET_PRIVATE_KEY_PATH=${keyPath}`
1177
+ ].join("\n") + "\n";
1178
+ await writeFile5(path6.join(process.cwd(), ".env.agentvalet"), envContent, { encoding: "utf8", mode: 384 });
1179
+ } catch {
1180
+ }
1122
1181
  const detected = detectFrameworks();
1123
1182
  const shouldSetup = await frameworkSetupConsent(detected);
1124
1183
  if (shouldSetup) {
@@ -1128,8 +1187,8 @@ async function registerAgentFlow(apiKey, ownerId) {
1128
1187
  const ideResults = await writeIdeConfigs({
1129
1188
  agentId: agent.agent_id,
1130
1189
  ownerId,
1131
- proxyUrl: getStoredConfig().proxyUrl,
1132
- keyPath: path6.join(process.cwd(), ".agentvalet", "agent.key"),
1190
+ proxyUrl,
1191
+ keyPath,
1133
1192
  detected
1134
1193
  });
1135
1194
  for (const r of ideResults) {
@@ -1138,8 +1197,8 @@ async function registerAgentFlow(apiKey, ownerId) {
1138
1197
  const globalResults = await writeGlobalFrameworkConfigs({
1139
1198
  agentId: agent.agent_id,
1140
1199
  ownerId,
1141
- proxyUrl: getStoredConfig().proxyUrl,
1142
- keyPath: path6.join(process.cwd(), ".agentvalet", "agent.key")
1200
+ proxyUrl,
1201
+ keyPath
1143
1202
  });
1144
1203
  for (const r of globalResults) {
1145
1204
  console.log(chalk6.green(` \u2713 ${r}`));
@@ -1192,7 +1251,7 @@ function collectScope(value, previous) {
1192
1251
  return [...previous, value];
1193
1252
  }
1194
1253
  var program = new Command();
1195
- program.name("agentvalet-register").description("Self-register an AI agent with AgentValet").version("0.3.9").option("--owner <uuid>", "Owner ID (or set AGENTVALET_OWNER env var)").option("--name <name>", "Agent name").option("--description <desc>", "Agent description").option("--scope <platform:scope>", "Requested scope, repeatable", collectScope, []).option("--api-url <url>", "AgentValet API base URL", "https://api.agentvalet.ai").option("--output <path>", "Path to write .env file", "./.env.agentvalet").option("--key-path <path>", "Path to write private key", "./agentvalet.key").option("--json", "Machine-readable JSON output").option("--no-wait", "Register only, do not wait for approval").option("--timeout <seconds>", "Approval wait timeout in seconds", "300").action(async (opts) => {
1254
+ program.name("agentvalet-register").description("Self-register an AI agent with AgentValet").version("0.4.1").option("--owner <uuid>", "Owner ID (or set AGENTVALET_OWNER env var)").option("--name <name>", "Agent name").option("--description <desc>", "Agent description").option("--scope <platform:scope>", "Requested scope, repeatable", collectScope, []).option("--api-url <url>", "AgentValet API base URL", "https://api.agentvalet.ai").option("--output <path>", "Path to write .env file", "./.env.agentvalet").option("--key-path <path>", "Path to write private key", "./agentvalet.key").option("--json", "Machine-readable JSON output").option("--no-wait", "Register only, do not wait for approval").option("--timeout <seconds>", "Approval wait timeout in seconds", "300").action(async (opts) => {
1196
1255
  const isJson = !!opts.json;
1197
1256
  let ownerId = opts.owner ?? process.env.AGENTVALET_OWNER ?? "";
1198
1257
  let agentName = opts.name ?? "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentvalet/register",
3
- "version": "0.3.9",
3
+ "version": "0.4.1",
4
4
  "description": "Self-register AI agents with AgentValet",
5
5
  "type": "module",
6
6
  "bin": {