create-identity 0.1.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 +143 -23
- package/package.json +4 -2
package/dist/index.js
CHANGED
|
@@ -3,30 +3,150 @@ import { spawnSync } from 'node:child_process';
|
|
|
3
3
|
import { existsSync } from 'node:fs';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
5
|
import { join } from 'node:path';
|
|
6
|
+
import { createInterface } from 'node:readline';
|
|
6
7
|
const ASP_DIR = join(homedir(), '.asp');
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
const MANIFEST_PATH = join(ASP_DIR, 'manifest.yaml');
|
|
9
|
+
function ask(question) {
|
|
10
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
11
|
+
return new Promise((resolve) => {
|
|
12
|
+
rl.question(question, (answer) => { rl.close(); resolve(answer.trim()); });
|
|
13
|
+
});
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
+
}
|
|
19
26
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
console.log('\n
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
async function main() {
|
|
28
|
+
const args = process.argv.slice(2);
|
|
29
|
+
const selfHost = args.includes('--self-host');
|
|
30
|
+
const provider = args.find((a) => a.startsWith('--provider='))?.split('=')[1]
|
|
31
|
+
|| (args.includes('--provider') ? args[args.indexOf('--provider') + 1] : null);
|
|
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' });
|
|
42
|
+
}
|
|
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`);
|
|
112
|
+
}
|
|
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`);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
console.log(` Warning: Could not follow ${display}\n`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
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');
|
|
132
|
+
}
|
|
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;
|
|
141
|
+
}
|
|
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`);
|
|
32
148
|
}
|
|
149
|
+
main().catch((err) => {
|
|
150
|
+
console.error(err);
|
|
151
|
+
process.exit(1);
|
|
152
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-identity",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Create your agent-native identity in one command",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": "./dist/index.js",
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"build": "tsc"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"asp-protocol": "^0.
|
|
11
|
+
"asp-protocol": "^0.2.0",
|
|
12
|
+
"js-yaml": "^4.1.1"
|
|
12
13
|
},
|
|
13
14
|
"files": [
|
|
14
15
|
"dist/",
|
|
@@ -27,6 +28,7 @@
|
|
|
27
28
|
],
|
|
28
29
|
"license": "MIT",
|
|
29
30
|
"devDependencies": {
|
|
31
|
+
"@types/js-yaml": "^4.0.9",
|
|
30
32
|
"@types/node": "^25.3.3",
|
|
31
33
|
"typescript": "^5.9.3"
|
|
32
34
|
}
|