@agentvalet/register 0.1.0 → 0.1.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.
- package/dist/index.js +24 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -80,8 +80,20 @@ import { fetch as fetch2 } from "undici";
|
|
|
80
80
|
async function waitForApproval(apiUrl, token, timeoutMs, onTick) {
|
|
81
81
|
const deadline = Date.now() + timeoutMs;
|
|
82
82
|
const sseResult = await trySSE(apiUrl, token, Math.min(3e4, timeoutMs), onTick);
|
|
83
|
-
if (sseResult) return sseResult;
|
|
84
|
-
|
|
83
|
+
if (sseResult) return enrichWithKey(apiUrl, token, sseResult);
|
|
84
|
+
const pollResult = await poll(apiUrl, token, deadline, onTick);
|
|
85
|
+
return enrichWithKey(apiUrl, token, pollResult);
|
|
86
|
+
}
|
|
87
|
+
async function enrichWithKey(apiUrl, token, result) {
|
|
88
|
+
if (result.status !== "approved") return result;
|
|
89
|
+
try {
|
|
90
|
+
const res = await fetch2(`${apiUrl}/v1/register/claim-key/${token}`);
|
|
91
|
+
if (!res.ok) return result;
|
|
92
|
+
const json = await res.json();
|
|
93
|
+
return { ...result, privateKey: json.private_key ?? "" };
|
|
94
|
+
} catch {
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
85
97
|
}
|
|
86
98
|
async function trySSE(apiUrl, token, windowMs, onTick) {
|
|
87
99
|
const controller = new AbortController();
|
|
@@ -163,7 +175,7 @@ async function saveOutput(opts) {
|
|
|
163
175
|
const envPath = resolve(opts.envFilePath);
|
|
164
176
|
await mkdir(dirname(keyPath), { recursive: true });
|
|
165
177
|
await mkdir(dirname(envPath), { recursive: true });
|
|
166
|
-
await writeFile(keyPath,
|
|
178
|
+
await writeFile(keyPath, opts.privateKey, { mode: 384 });
|
|
167
179
|
const envContent = [
|
|
168
180
|
`# AgentValet \u2014 generated by agentvalet-register`,
|
|
169
181
|
`AGENTVALET_AGENT_ID=${opts.agentId}`,
|
|
@@ -275,12 +287,13 @@ Approve at: https://agentvalet.ai/registrations
|
|
|
275
287
|
}
|
|
276
288
|
process.exit(2);
|
|
277
289
|
}
|
|
278
|
-
const { agentId } = result;
|
|
290
|
+
const { agentId, privateKey } = result;
|
|
279
291
|
let keyPath;
|
|
280
292
|
let envPath;
|
|
281
293
|
try {
|
|
282
294
|
({ keyPath, envPath } = await saveOutput({
|
|
283
295
|
agentId,
|
|
296
|
+
privateKey: privateKey ?? "",
|
|
284
297
|
apiUrl: opts.apiUrl,
|
|
285
298
|
keyFilePath: opts.keyPath,
|
|
286
299
|
envFilePath: opts.output
|
|
@@ -290,12 +303,17 @@ Approve at: https://agentvalet.ai/registrations
|
|
|
290
303
|
console.error(isJson ? JSON.stringify({ error: msg }) : chalk2.red(`Failed to save output: ${msg}`));
|
|
291
304
|
process.exit(3);
|
|
292
305
|
}
|
|
306
|
+
const keyWritten = !!privateKey;
|
|
293
307
|
if (isJson) {
|
|
294
|
-
console.log(JSON.stringify({ status: "approved", agentId, keyPath, envPath }));
|
|
308
|
+
console.log(JSON.stringify({ status: "approved", agentId, keyPath: keyWritten ? keyPath : null, envPath }));
|
|
295
309
|
} else {
|
|
296
310
|
console.log(chalk2.green(`
|
|
297
311
|
Approved! Agent ID: ${agentId}`));
|
|
298
|
-
|
|
312
|
+
if (keyWritten) {
|
|
313
|
+
console.log(chalk2.gray(`Key: ${keyPath}`));
|
|
314
|
+
} else {
|
|
315
|
+
console.log(chalk2.yellow(`Key: not written \u2014 copy it from the dashboard and paste into ${keyPath}`));
|
|
316
|
+
}
|
|
299
317
|
console.log(chalk2.gray(`Env file: ${envPath}`));
|
|
300
318
|
console.log(`
|
|
301
319
|
Source the env file before calling any tool:`);
|