pairai 0.2.1 → 0.2.2
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/package.json +1 -1
- package/pairai.ts +50 -16
package/package.json
CHANGED
package/pairai.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* pairai CLI — connect AI agents via the pairai hub
|
|
4
4
|
*
|
|
5
5
|
* Commands:
|
|
6
|
-
* npx pairai setup "Agent Name" [--hub URL] [--provider claude|gemini] [--global]
|
|
6
|
+
* npx pairai setup "Agent Name" [--hub URL] [--provider claude|gemini] [--global] [--force]
|
|
7
7
|
* npx pairai serve [--provider claude|gemini]
|
|
8
8
|
* npx pairai upgrade — update to latest version (preserves keys and config)
|
|
9
9
|
* npx pairai version — show current version
|
|
@@ -93,16 +93,41 @@ if (command === "setup") {
|
|
|
93
93
|
const hubIdx = rest.indexOf("--hub");
|
|
94
94
|
const hubUrl = hubIdx !== -1 ? rest.splice(hubIdx, 2)[1] : "https://pairai.pro";
|
|
95
95
|
const providerIdx = rest.indexOf("--provider");
|
|
96
|
-
const
|
|
96
|
+
const providerArg = providerIdx !== -1 ? rest.splice(providerIdx, 2)[1] : undefined;
|
|
97
|
+
if (providerArg && providerArg !== "claude" && providerArg !== "gemini") {
|
|
98
|
+
console.error(` Unknown provider "${providerArg}". Must be "claude" or "gemini".`);
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
const provider = providerArg ?? detectProvider();
|
|
97
102
|
const globalIdx = rest.indexOf("--global");
|
|
98
103
|
const useGlobal = globalIdx !== -1 ? (rest.splice(globalIdx, 1), true) : false;
|
|
99
104
|
const agentName = rest.find((a) => !a.startsWith("--"));
|
|
100
105
|
|
|
106
|
+
const forceIdx = rest.indexOf("--force");
|
|
107
|
+
const useForce = forceIdx !== -1 ? (rest.splice(forceIdx, 1), true) : false;
|
|
101
108
|
if (!agentName) {
|
|
102
|
-
console.error('Usage: npx pairai setup "Agent Name" [--hub URL] [--provider claude|gemini] [--global]');
|
|
109
|
+
console.error('Usage: npx pairai setup "Agent Name" [--hub URL] [--provider claude|gemini] [--global] [--force]');
|
|
103
110
|
process.exit(1);
|
|
104
111
|
}
|
|
105
112
|
|
|
113
|
+
// Check for existing config to avoid accidental overwrites
|
|
114
|
+
const existingConfigPath = provider === "gemini"
|
|
115
|
+
? join(useGlobal ? join(homedir(), ".gemini") : join(process.cwd(), ".gemini"), "settings.json")
|
|
116
|
+
: join(process.cwd(), ".mcp.json");
|
|
117
|
+
const mcpKey = provider === "gemini" ? "pairai" : "pairai-channel";
|
|
118
|
+
if (!useForce && existsSync(existingConfigPath)) {
|
|
119
|
+
try {
|
|
120
|
+
const existing = JSON.parse(readFileSync(existingConfigPath, "utf-8"));
|
|
121
|
+
const servers = existing.mcpServers ?? {};
|
|
122
|
+
if (servers[mcpKey]) {
|
|
123
|
+
console.error(`\n pairai is already configured in ${existingConfigPath}`);
|
|
124
|
+
console.error(` Running setup again would overwrite the existing API key and config.`);
|
|
125
|
+
console.error(`\n To force a fresh setup, run: npx pairai setup "${agentName}" --force\n`);
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
128
|
+
} catch {}
|
|
129
|
+
}
|
|
130
|
+
|
|
106
131
|
console.log(`\n Registering "${agentName}" on ${hubUrl}...\n`);
|
|
107
132
|
|
|
108
133
|
console.log(" Generating RSA-4096 keypair...");
|
|
@@ -133,18 +158,22 @@ if (command === "setup") {
|
|
|
133
158
|
const keyPath = join(keyDir, `${id}.pem`);
|
|
134
159
|
writeFileSync(keyPath, privateKey, { mode: 0o600 });
|
|
135
160
|
console.log(` Private key: ${keyPath}`);
|
|
161
|
+
const lines = [
|
|
162
|
+
"BACK UP YOUR PRIVATE KEY",
|
|
163
|
+
"",
|
|
164
|
+
keyPath,
|
|
165
|
+
"",
|
|
166
|
+
"This key is stored only on your machine.",
|
|
167
|
+
"The hub never sees it. If lost, you must re-register",
|
|
168
|
+
"and re-pair — all encrypted history becomes unreadable.",
|
|
169
|
+
"",
|
|
170
|
+
"Copy it to a password manager or secure backup now.",
|
|
171
|
+
];
|
|
172
|
+
const w = Math.max(...lines.map((l) => l.length)) + 2;
|
|
136
173
|
console.log();
|
|
137
|
-
console.log(`
|
|
138
|
-
console.log(` │
|
|
139
|
-
console.log(`
|
|
140
|
-
console.log(` │ ${keyPath.padEnd(56)}│`);
|
|
141
|
-
console.log(` │ │`);
|
|
142
|
-
console.log(` │ This key is stored only on your machine. │`);
|
|
143
|
-
console.log(` │ The hub never sees it. If lost, you must re-register │`);
|
|
144
|
-
console.log(` │ and re-pair — all encrypted history becomes unreadable. │`);
|
|
145
|
-
console.log(` │ │`);
|
|
146
|
-
console.log(` │ Copy it to a password manager or secure backup now. │`);
|
|
147
|
-
console.log(` └──────────────────────────────────────────────────────────┘`);
|
|
174
|
+
console.log(` ┌${"─".repeat(w + 2)}┐`);
|
|
175
|
+
for (const l of lines) console.log(` │ ${l.padEnd(w)}│`);
|
|
176
|
+
console.log(` └${"─".repeat(w + 2)}┘`);
|
|
148
177
|
console.log();
|
|
149
178
|
|
|
150
179
|
if (provider === "gemini") {
|
|
@@ -213,7 +242,7 @@ if (command === "setup") {
|
|
|
213
242
|
if (command !== "serve") {
|
|
214
243
|
console.error(`pairai v${VERSION}\n`);
|
|
215
244
|
console.error("Usage:");
|
|
216
|
-
console.error(' npx pairai setup "Agent Name" [--hub URL] [--provider claude|gemini] [--global]');
|
|
245
|
+
console.error(' npx pairai setup "Agent Name" [--hub URL] [--provider claude|gemini] [--global] [--force]');
|
|
217
246
|
console.error(" npx pairai serve [--provider claude|gemini]");
|
|
218
247
|
console.error(" npx pairai upgrade — update to latest version");
|
|
219
248
|
console.error(" npx pairai version — show current version");
|
|
@@ -226,7 +255,12 @@ const { ListToolsRequestSchema, CallToolRequestSchema } = await import("@modelco
|
|
|
226
255
|
|
|
227
256
|
const serveArgs = args.slice(1);
|
|
228
257
|
const serveProviderIdx = serveArgs.indexOf("--provider");
|
|
229
|
-
const
|
|
258
|
+
const serveProviderArg = serveProviderIdx !== -1 ? serveArgs[serveProviderIdx + 1] : undefined;
|
|
259
|
+
if (serveProviderArg && serveProviderArg !== "claude" && serveProviderArg !== "gemini") {
|
|
260
|
+
console.error(` Unknown provider "${serveProviderArg}". Must be "claude" or "gemini".`);
|
|
261
|
+
process.exit(1);
|
|
262
|
+
}
|
|
263
|
+
const serveProvider = serveProviderArg ?? "claude";
|
|
230
264
|
|
|
231
265
|
const HUB_URL = process.env.PAIRAI_HUB_URL ?? process.env.PAIRAI_URL ?? "https://pairai.pro";
|
|
232
266
|
const API_KEY = process.env.PAIRAI_AGENT_CRED ?? process.env.PAIRAI_API_KEY;
|