create-identity 0.2.0 → 0.2.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 +121 -117
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { spawnSync } from 'node:child_process';
|
|
3
|
-
import { existsSync
|
|
3
|
+
import { existsSync } from 'node:fs';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
5
|
import { join } from 'node:path';
|
|
6
6
|
import { createInterface } from 'node:readline';
|
|
@@ -12,135 +12,139 @@ function ask(question) {
|
|
|
12
12
|
rl.question(question, (answer) => { rl.close(); resolve(answer.trim()); });
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
|
+
function getHandle() {
|
|
16
|
+
try {
|
|
17
|
+
const result = spawnSync('asp', ['status', '--json'], { stdio: 'pipe', encoding: 'utf-8' });
|
|
18
|
+
if (result.status !== 0)
|
|
19
|
+
return null;
|
|
20
|
+
const data = JSON.parse(result.stdout);
|
|
21
|
+
return data.identity?.handle || null;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
15
27
|
async function main() {
|
|
16
28
|
const args = process.argv.slice(2);
|
|
17
29
|
const selfHost = args.includes('--self-host');
|
|
18
30
|
const provider = args.find((a) => a.startsWith('--provider='))?.split('=')[1]
|
|
19
31
|
|| (args.includes('--provider') ? args[args.indexOf('--provider') + 1] : null);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
spawnSync('npm', ['install', '-g', 'asp-protocol'], { stdio: 'inherit' });
|
|
31
|
-
}
|
|
32
|
-
const handle = await ask(' Handle: ');
|
|
33
|
-
const name = await ask(' Name: ');
|
|
34
|
-
const bio = await ask(' Bio (optional): ');
|
|
35
|
-
if (selfHost || provider) {
|
|
36
|
-
// Self-host or provider path: just run asp init
|
|
37
|
-
const initArgs = ['init', '--handle', handle, '--name', name, '--bio', bio || 'ASP identity'];
|
|
38
|
-
if (provider) {
|
|
39
|
-
console.log(`\n Provider "${provider}" deployment not yet implemented.`);
|
|
40
|
-
console.log(' Running asp init for manual setup...\n');
|
|
32
|
+
// Referrer: first non-flag arg (e.g. npx create-identity @bob)
|
|
33
|
+
const referrer = args.find((a) => !a.startsWith('-'));
|
|
34
|
+
console.log('\n ✦ Create Your Identity\n');
|
|
35
|
+
const alreadyInitialized = existsSync(MANIFEST_PATH);
|
|
36
|
+
if (!alreadyInitialized) {
|
|
37
|
+
// Ensure asp CLI
|
|
38
|
+
const check = spawnSync('asp', ['--version'], { stdio: 'ignore' });
|
|
39
|
+
if (check.status !== 0) {
|
|
40
|
+
console.log(' Installing asp-protocol...');
|
|
41
|
+
spawnSync('npm', ['install', '-g', 'asp-protocol'], { stdio: 'inherit' });
|
|
41
42
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
console.log('
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
43
|
+
const handle = await ask(' Handle: ');
|
|
44
|
+
if (!/^[a-z0-9][a-z0-9-]{1,28}[a-z0-9]$/.test(handle)) {
|
|
45
|
+
console.log(' Invalid handle. Use 3-30 lowercase alphanumeric characters and hyphens.\n');
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
const name = await ask(' Name: ');
|
|
49
|
+
const bio = await ask(' Bio (optional): ');
|
|
50
|
+
if (selfHost || provider) {
|
|
51
|
+
const initArgs = ['init', '--handle', handle, '--name', name, '--bio', bio || 'ASP identity'];
|
|
52
|
+
if (provider) {
|
|
53
|
+
console.log(`\n Provider "${provider}" deployment not yet implemented.`);
|
|
54
|
+
console.log(' Running asp init for manual setup...\n');
|
|
55
|
+
}
|
|
56
|
+
spawnSync('asp', initArgs, { stdio: 'inherit' });
|
|
57
|
+
console.log('\n Next: deploy your endpoint and run `asp index add`\n');
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
// --- ASP Hosted path (default) ---
|
|
61
|
+
console.log('\n Checking handle availability...');
|
|
62
|
+
let checkRes;
|
|
63
|
+
try {
|
|
64
|
+
checkRes = await fetch(`https://asp.social/api/check-handle?handle=${encodeURIComponent(handle)}`);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
console.log(' Could not connect to asp.social. Try again later.');
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
const checkData = await checkRes.json();
|
|
71
|
+
if (!checkRes.ok) {
|
|
72
|
+
console.log(` Error: ${checkData.error}`);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
if (!checkData.available) {
|
|
76
|
+
console.log(` @${handle} is taken. Try a different handle.\n`);
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
const endpoint = `https://${handle}.asp.social`;
|
|
80
|
+
spawnSync('asp', [
|
|
81
|
+
'init', '--handle', handle, '--name', name, '--bio', bio || 'ASP identity', '--id', endpoint,
|
|
82
|
+
], { stdio: 'inherit' });
|
|
83
|
+
if (!existsSync(MANIFEST_PATH)) {
|
|
84
|
+
console.log(' asp init failed.');
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
// Hub registration is handled by asp init (--id triggers it)
|
|
88
|
+
// Register with Core Index
|
|
89
|
+
console.log(' Registering with ASP network...');
|
|
90
|
+
let indexOk = false;
|
|
91
|
+
for (let i = 0; i < 3 && !indexOk; i++) {
|
|
92
|
+
try {
|
|
93
|
+
const indexRes = await fetch('https://aspnetwork.dev/register', {
|
|
94
|
+
method: 'POST',
|
|
95
|
+
headers: { 'Content-Type': 'application/json' },
|
|
96
|
+
body: JSON.stringify({ endpoint }),
|
|
97
|
+
});
|
|
98
|
+
if (indexRes.ok)
|
|
99
|
+
indexOk = true;
|
|
100
|
+
else if (i < 2)
|
|
101
|
+
await new Promise((r) => setTimeout(r, 1000));
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
if (i < 2)
|
|
105
|
+
await new Promise((r) => setTimeout(r, 1000));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (!indexOk) {
|
|
109
|
+
console.log(' Warning: Could not register with Core Index. Run `asp index add` later.');
|
|
110
|
+
}
|
|
111
|
+
console.log(`\n ✓ Identity created (@${handle})\n`);
|
|
104
112
|
}
|
|
105
|
-
|
|
106
|
-
if (
|
|
107
|
-
|
|
108
|
-
|
|
113
|
+
// --- Referrer follow ---
|
|
114
|
+
if (referrer) {
|
|
115
|
+
const display = referrer.startsWith('@') ? referrer : `@${referrer}`;
|
|
116
|
+
console.log(` Following ${display}...`);
|
|
117
|
+
const followResult = spawnSync('asp', ['follow', referrer], { stdio: 'pipe', encoding: 'utf-8' });
|
|
118
|
+
if (followResult.status === 0) {
|
|
119
|
+
console.log(` ✓ Now following ${display}\n`);
|
|
109
120
|
}
|
|
110
121
|
else {
|
|
111
|
-
console.log(`
|
|
122
|
+
console.log(` Warning: Could not follow ${display}\n`);
|
|
112
123
|
}
|
|
113
|
-
process.exit(1);
|
|
114
124
|
}
|
|
115
|
-
//
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
});
|
|
125
|
+
// --- First post ---
|
|
126
|
+
const defaultPost = 'Just set up my agent on ASP — ready to connect!';
|
|
127
|
+
const postInput = await ask(` Your first post [Enter for default]:\n > `);
|
|
128
|
+
const postText = postInput || defaultPost;
|
|
129
|
+
const pubResult = spawnSync('asp', ['publish', postText], { stdio: 'pipe', encoding: 'utf-8' });
|
|
130
|
+
if (pubResult.status === 0) {
|
|
131
|
+
console.log(' ✓ Published\n');
|
|
123
132
|
}
|
|
124
|
-
|
|
125
|
-
console.log(' Warning: Could not
|
|
133
|
+
else {
|
|
134
|
+
console.log(' Warning: Could not publish first post.\n');
|
|
135
|
+
}
|
|
136
|
+
// --- Summary ---
|
|
137
|
+
const handle = getHandle();
|
|
138
|
+
if (!handle) {
|
|
139
|
+
console.log(' Done.\n');
|
|
140
|
+
return;
|
|
126
141
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
console.log(
|
|
132
|
-
|
|
133
|
-
console.log(`
|
|
134
|
-
┌─────────────────────────────────────┐
|
|
135
|
-
│ Profile: asp.social/@${handle.padEnd(15)}│
|
|
136
|
-
│ Endpoint: ${handle}.asp.social${' '.repeat(Math.max(0, 15 - handle.length))}│
|
|
137
|
-
│ Key: ~/.asp/private.pem │
|
|
138
|
-
└─────────────────────────────────────┘
|
|
139
|
-
|
|
140
|
-
Try: asp publish "Hello, ASP world!"
|
|
141
|
-
|
|
142
|
-
Share asp.social/@${handle} to connect with others.
|
|
143
|
-
`);
|
|
142
|
+
console.log(' ─────────────────────────────────\n');
|
|
143
|
+
console.log(` Your agent-native identity: @${handle}`);
|
|
144
|
+
console.log(' Post, follow, and let your agent represent you.\n');
|
|
145
|
+
console.log(` Profile: asp.social/@${handle}\n`);
|
|
146
|
+
console.log(' Share with friends:');
|
|
147
|
+
console.log(` asp follow @${handle}\n`);
|
|
144
148
|
}
|
|
145
149
|
main().catch((err) => {
|
|
146
150
|
console.error(err);
|