clawmoney 0.17.0 → 0.17.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/commands/setup.js +81 -6
- package/package.json +1 -1
package/dist/commands/setup.js
CHANGED
|
@@ -57,15 +57,90 @@ export async function setupCommand() {
|
|
|
57
57
|
catch {
|
|
58
58
|
// Fall through — if the check fails, we still try registering.
|
|
59
59
|
}
|
|
60
|
+
// Existing ACTIVE agent → login path: send OTP, verify, rotate key.
|
|
61
|
+
// This is the "I already registered on another machine / lost my api_key"
|
|
62
|
+
// flow — no new claim link needed.
|
|
60
63
|
if (existingStatus === 'ACTIVE') {
|
|
61
|
-
agentSpinner.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
agentSpinner.info('Existing agent found. Sending login code to your email...');
|
|
65
|
+
try {
|
|
66
|
+
const loginResp = await apiPost('/api/v1/claw-agents/login', { email });
|
|
67
|
+
if (!loginResp.ok) {
|
|
68
|
+
console.error(chalk.red(JSON.stringify(loginResp.data)));
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
console.error(chalk.red(err.message));
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const otp = await prompt(chalk.cyan('? ') + 'Enter the 6-digit code from your email: ');
|
|
77
|
+
if (!otp || !/^\d{4,8}$/.test(otp.trim())) {
|
|
78
|
+
console.log(chalk.red('Invalid code.'));
|
|
66
79
|
return;
|
|
67
80
|
}
|
|
68
|
-
|
|
81
|
+
const verifySpinner = ora('Verifying code...').start();
|
|
82
|
+
let loginData;
|
|
83
|
+
try {
|
|
84
|
+
const verifyResp = await apiPost('/api/v1/claw-agents/login/verify', { email, otp: otp.trim() });
|
|
85
|
+
if (!verifyResp.ok) {
|
|
86
|
+
verifySpinner.fail('Verification failed');
|
|
87
|
+
console.error(chalk.red(JSON.stringify(verifyResp.data)));
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
loginData = verifyResp.data;
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
verifySpinner.fail('Verification failed');
|
|
94
|
+
console.error(chalk.red(err.message));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
verifySpinner.succeed('Logged in');
|
|
98
|
+
// Persist api_key immediately so nothing is lost if wallet provision hiccups.
|
|
99
|
+
saveConfig({
|
|
100
|
+
api_key: loginData.api_key,
|
|
101
|
+
agent_id: loginData.agent_id,
|
|
102
|
+
agent_slug: loginData.agent_slug,
|
|
103
|
+
email,
|
|
104
|
+
wallet_address: loginData.agent?.wallet_address ?? undefined,
|
|
105
|
+
});
|
|
106
|
+
// Ensure a CDP wallet exists for this agent. Older ACTIVE agents
|
|
107
|
+
// predating the CDP flow have wallet_address=null; hitting the
|
|
108
|
+
// balance endpoint triggers _ensure_agent_wallet on the backend.
|
|
109
|
+
let walletAddress = loginData.agent?.wallet_address ?? '';
|
|
110
|
+
if (!walletAddress) {
|
|
111
|
+
const walletSpinner = ora('Provisioning CDP wallet...').start();
|
|
112
|
+
try {
|
|
113
|
+
const balResp = await apiGet('/api/v1/claw-agents/me/wallet/balance?asset=usdc', loginData.api_key);
|
|
114
|
+
if (balResp.ok && balResp.data?.address) {
|
|
115
|
+
walletAddress = balResp.data.address;
|
|
116
|
+
saveConfig({ wallet_address: walletAddress });
|
|
117
|
+
walletSpinner.succeed(`Wallet ready: ${walletAddress}`);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
walletSpinner.warn('Wallet not yet available — will be created on first use.');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch (err) {
|
|
124
|
+
walletSpinner.warn(`Wallet provisioning deferred: ${err.message}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// Summary.
|
|
128
|
+
console.log('');
|
|
129
|
+
console.log(chalk.green.bold(' Setup complete!'));
|
|
130
|
+
console.log('');
|
|
131
|
+
console.log(chalk.dim(` Agent ID: ${loginData.agent_id}`));
|
|
132
|
+
console.log(chalk.dim(` Agent Slug: ${loginData.agent_slug}`));
|
|
133
|
+
if (walletAddress) {
|
|
134
|
+
console.log(chalk.dim(` Wallet: ${walletAddress}`));
|
|
135
|
+
console.log(chalk.dim(` Custody: Coinbase CDP Server Wallet`));
|
|
136
|
+
}
|
|
137
|
+
console.log(chalk.dim(` Config: ${getConfigPath()}`));
|
|
138
|
+
console.log('');
|
|
139
|
+
console.log(` Next steps:`);
|
|
140
|
+
console.log(` ${chalk.cyan('clawmoney wallet balance')} Check your wallet balance`);
|
|
141
|
+
console.log(` ${chalk.cyan('clawmoney browse')} Browse available tasks`);
|
|
142
|
+
console.log('');
|
|
143
|
+
return;
|
|
69
144
|
}
|
|
70
145
|
// Step 3: Register agent (or re-send claim link for an UNCLAIMED agent).
|
|
71
146
|
// The backend generates the anonymous slug from email hash; we never send a name.
|