ropilot 0.1.20 → 0.1.21
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/lib/config.js +35 -4
- package/lib/setup.js +31 -18
- package/package.json +1 -1
package/lib/config.js
CHANGED
|
@@ -71,6 +71,22 @@ export function loadProjectConfig() {
|
|
|
71
71
|
return null;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
/**
|
|
75
|
+
* Save project config
|
|
76
|
+
*/
|
|
77
|
+
export function saveProjectConfig(config) {
|
|
78
|
+
writeFileSync(PROJECT_CONFIG_FILE, JSON.stringify(config, null, 2));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Set API key in project config
|
|
83
|
+
*/
|
|
84
|
+
export function setProjectApiKey(apiKey) {
|
|
85
|
+
const config = loadProjectConfig() || {};
|
|
86
|
+
config.apiKey = apiKey;
|
|
87
|
+
saveProjectConfig(config);
|
|
88
|
+
}
|
|
89
|
+
|
|
74
90
|
/**
|
|
75
91
|
* Get the API key (project config overrides global)
|
|
76
92
|
*/
|
|
@@ -103,17 +119,32 @@ export async function showConfig() {
|
|
|
103
119
|
console.log('Ropilot Configuration');
|
|
104
120
|
console.log('=====================');
|
|
105
121
|
console.log('');
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
122
|
+
|
|
123
|
+
// Show which key is active
|
|
124
|
+
const activeKey = projectConfig?.apiKey || globalConfig.apiKey;
|
|
125
|
+
const activeSource = projectConfig?.apiKey ? '.ropilot.json (project)' : '~/.ropilot/config.json (global)';
|
|
126
|
+
|
|
127
|
+
console.log(`Active API Key: ${activeKey ? activeKey.slice(0, 20) + '...' : '(not set)'}`);
|
|
128
|
+
if (activeKey) {
|
|
129
|
+
console.log(` Source: ${activeSource}`);
|
|
130
|
+
}
|
|
110
131
|
console.log('');
|
|
111
132
|
|
|
112
133
|
if (projectConfig) {
|
|
113
134
|
console.log('Project config (.ropilot.json):');
|
|
114
135
|
console.log(` API Key: ${projectConfig.apiKey ? projectConfig.apiKey.slice(0, 20) + '...' : '(not set)'}`);
|
|
115
136
|
console.log('');
|
|
137
|
+
} else {
|
|
138
|
+
console.log('Project config (.ropilot.json): not found');
|
|
139
|
+
console.log(' Run "npx ropilot init" to create one');
|
|
140
|
+
console.log('');
|
|
116
141
|
}
|
|
117
142
|
|
|
143
|
+
console.log('Global config (~/.ropilot/config.json):');
|
|
144
|
+
console.log(` API Key: ${globalConfig.apiKey ? globalConfig.apiKey.slice(0, 20) + '...' : '(not set)'}`);
|
|
145
|
+
console.log(` Prompts Version: ${globalConfig.promptsVersion || '(not downloaded)'}`);
|
|
146
|
+
console.log(` Last Updated: ${globalConfig.lastUpdated || 'never'}`);
|
|
147
|
+
console.log('');
|
|
148
|
+
|
|
118
149
|
console.log(`Edge Server: ${EDGE_URL}`);
|
|
119
150
|
}
|
package/lib/setup.js
CHANGED
|
@@ -18,6 +18,8 @@ import {
|
|
|
18
18
|
saveGlobalConfig,
|
|
19
19
|
setApiKey,
|
|
20
20
|
getApiKey,
|
|
21
|
+
setProjectApiKey,
|
|
22
|
+
loadProjectConfig,
|
|
21
23
|
EDGE_URL
|
|
22
24
|
} from './config.js';
|
|
23
25
|
|
|
@@ -370,28 +372,35 @@ export async function init(providedApiKey = null) {
|
|
|
370
372
|
console.log('===================');
|
|
371
373
|
console.log('');
|
|
372
374
|
|
|
373
|
-
//
|
|
374
|
-
|
|
375
|
+
// Always prompt for API key (per-project config)
|
|
376
|
+
const existingKey = loadProjectConfig()?.apiKey;
|
|
377
|
+
const defaultHint = existingKey ? ` [${existingKey.slice(0, 20)}...]` : '';
|
|
375
378
|
|
|
379
|
+
console.log('To use Ropilot, you need an API key.');
|
|
380
|
+
console.log('Get one at: https://ropilot.ai');
|
|
381
|
+
console.log('');
|
|
382
|
+
|
|
383
|
+
let apiKey = providedApiKey;
|
|
376
384
|
if (!apiKey) {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
console.error('Invalid API key. Must start with "ropilot_"');
|
|
384
|
-
process.exit(1);
|
|
385
|
+
apiKey = await prompt(`Enter your API key${defaultHint}: `);
|
|
386
|
+
|
|
387
|
+
// If empty and existing key, use existing
|
|
388
|
+
if (!apiKey && existingKey) {
|
|
389
|
+
apiKey = existingKey;
|
|
390
|
+
console.log(`Using existing key: ${apiKey.slice(0, 20)}...`);
|
|
385
391
|
}
|
|
392
|
+
}
|
|
386
393
|
|
|
387
|
-
|
|
388
|
-
console.
|
|
389
|
-
|
|
390
|
-
} else {
|
|
391
|
-
console.log(`Using API key: ${apiKey.slice(0, 20)}...`);
|
|
392
|
-
console.log('');
|
|
394
|
+
if (!apiKey || !apiKey.startsWith('ropilot_')) {
|
|
395
|
+
console.error('Invalid API key. Must start with "ropilot_"');
|
|
396
|
+
process.exit(1);
|
|
393
397
|
}
|
|
394
398
|
|
|
399
|
+
// Save to project config (.ropilot.json)
|
|
400
|
+
setProjectApiKey(apiKey);
|
|
401
|
+
console.log('API key saved to .ropilot.json');
|
|
402
|
+
console.log('');
|
|
403
|
+
|
|
395
404
|
|
|
396
405
|
// Install Studio plugin
|
|
397
406
|
await installPlugin();
|
|
@@ -425,13 +434,17 @@ export async function update() {
|
|
|
425
434
|
console.log('===================');
|
|
426
435
|
console.log('');
|
|
427
436
|
|
|
428
|
-
|
|
437
|
+
// Check project config first, then global
|
|
438
|
+
const projectConfig = loadProjectConfig();
|
|
439
|
+
const apiKey = projectConfig?.apiKey || getApiKey();
|
|
440
|
+
|
|
429
441
|
if (!apiKey) {
|
|
430
442
|
console.error('No API key configured. Run "ropilot init" first.');
|
|
431
443
|
process.exit(1);
|
|
432
444
|
}
|
|
433
445
|
|
|
434
|
-
|
|
446
|
+
const source = projectConfig?.apiKey ? '.ropilot.json' : '~/.ropilot/config.json';
|
|
447
|
+
console.log(`Using API key from ${source}: ${apiKey.slice(0, 20)}...`);
|
|
435
448
|
console.log('');
|
|
436
449
|
|
|
437
450
|
// Re-install Studio plugin
|