prompt-forge-studio-cli 1.0.0 → 1.0.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 +3 -2
- package/src/api.js +54 -23
- package/src/auth.js +7 -16
- package/src/studio.js +3 -9
- package/test-project/README.md +0 -9
- package/test-project/forge.config.json +0 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prompt-forge-studio-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Professional terminal-native prompt engineering studio",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"figlet": "^1.10.0",
|
|
21
21
|
"gradient-string": "^3.0.0",
|
|
22
22
|
"inquirer": "^8.2.7",
|
|
23
|
-
"ora": "^5.4.1"
|
|
23
|
+
"ora": "^5.4.1",
|
|
24
|
+
"prompt-forge-studio-cli": "^1.0.0"
|
|
24
25
|
}
|
|
25
26
|
}
|
package/src/api.js
CHANGED
|
@@ -3,36 +3,67 @@ const { getHealthStatus } = require('./health');
|
|
|
3
3
|
const { requireAuth } = require('./auth');
|
|
4
4
|
const chalk = require('chalk');
|
|
5
5
|
|
|
6
|
-
//
|
|
6
|
+
// Real AI responses based on prompt input using Prompt Forge API
|
|
7
7
|
async function generateResponse(prompt, model) {
|
|
8
|
-
const spinner = ora(`Generating response with ${chalk.cyan(model)}...`).start();
|
|
8
|
+
const spinner = ora(`Generating response with ${chalk.cyan(model)} via Prompt Forge...`).start();
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
try {
|
|
11
|
+
const auth = await requireAuth();
|
|
12
|
+
const apiKey = auth.promptforge;
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
throw new Error('Provider connection timeout');
|
|
18
|
-
}
|
|
14
|
+
if (!apiKey) {
|
|
15
|
+
throw new Error('Prompt Forge API Key is missing. Run `:key` to set it.');
|
|
16
|
+
}
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
// Send request to your local or deployed Prompt Forge instance
|
|
19
|
+
// Assuming user runs local for now, but usually they'd specify a host.
|
|
20
|
+
// We'll default to 127.0.0.1 instead of localhost to bypass Node's IPv6 resolution delay on Windows.
|
|
21
|
+
const { getConfig } = require('./config');
|
|
22
|
+
const config = getConfig() || {};
|
|
23
|
+
const baseUrl = config.host || 'http://127.0.0.1:3000';
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
const payload = { prompt };
|
|
26
|
+
if (model) {
|
|
27
|
+
payload.model = model;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const response = await fetch(`${baseUrl}/api/v1/cli`, {
|
|
31
|
+
method: 'POST',
|
|
32
|
+
headers: {
|
|
33
|
+
'Content-Type': 'application/json',
|
|
34
|
+
'x-api-key': apiKey
|
|
35
|
+
},
|
|
36
|
+
body: JSON.stringify(payload)
|
|
37
|
+
});
|
|
28
38
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
model,
|
|
33
|
-
latency
|
|
39
|
+
if (!response.ok) {
|
|
40
|
+
const errData = await response.json().catch(() => ({}));
|
|
41
|
+
throw new Error(errData.error || errData.message || `API Error: ${response.status}`);
|
|
34
42
|
}
|
|
35
|
-
|
|
43
|
+
|
|
44
|
+
const data = await response.json();
|
|
45
|
+
|
|
46
|
+
if (!data.success) {
|
|
47
|
+
throw new Error(data.error || 'Failed to generate content');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
spinner.succeed(`Received response from ${chalk.cyan(data.meta?.model || model)} using Prompt Forge API in ${data.meta?.latency_ms || '?'}ms`);
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
text: data.data,
|
|
54
|
+
metadata: {
|
|
55
|
+
model: data.meta?.model || model,
|
|
56
|
+
latency: data.meta?.latency_ms,
|
|
57
|
+
tokensInput: data.meta?.tokens_input,
|
|
58
|
+
tokensOutput: data.meta?.tokens_output,
|
|
59
|
+
costMicroUsd: data.meta?.cost_micro_usd
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
} catch (error) {
|
|
64
|
+
spinner.fail(`Failed to get response`);
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
36
67
|
}
|
|
37
68
|
|
|
38
69
|
async function executeWithFailover(prompt, primaryModel, autoFailover) {
|
package/src/auth.js
CHANGED
|
@@ -25,38 +25,29 @@ function getAuth() {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
function setAuth(
|
|
28
|
+
function setAuth(key) {
|
|
29
29
|
ensureForgeHomeDir();
|
|
30
30
|
const currentAuth = getAuth();
|
|
31
|
-
currentAuth[
|
|
31
|
+
currentAuth['promptforge'] = key;
|
|
32
32
|
fs.writeFileSync(AUTH_FILE, JSON.stringify(currentAuth, null, 2), { mode: 0o600 });
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
async function requireAuth() {
|
|
36
36
|
const auth = getAuth();
|
|
37
|
-
if (
|
|
38
|
-
console.log(chalk.yellow('\nNo API
|
|
39
|
-
|
|
40
|
-
const { provider } = await inquirer.prompt([
|
|
41
|
-
{
|
|
42
|
-
type: 'list',
|
|
43
|
-
name: 'provider',
|
|
44
|
-
message: 'Select an AI provider to configure:',
|
|
45
|
-
choices: ['openai', 'anthropic', 'gemini']
|
|
46
|
-
}
|
|
47
|
-
]);
|
|
37
|
+
if (!auth.promptforge) {
|
|
38
|
+
console.log(chalk.yellow('\nNo Prompt Forge API key found. Let\'s get you authenticated.'));
|
|
48
39
|
|
|
49
40
|
const { key } = await inquirer.prompt([
|
|
50
41
|
{
|
|
51
42
|
type: 'password',
|
|
52
43
|
name: 'key',
|
|
53
|
-
message: `Enter your
|
|
44
|
+
message: `Enter your Prompt Forge API Key:`,
|
|
54
45
|
mask: '*'
|
|
55
46
|
}
|
|
56
47
|
]);
|
|
57
48
|
|
|
58
|
-
setAuth(
|
|
59
|
-
console.log(chalk.green('\n✔ API key saved securely locally.'));
|
|
49
|
+
setAuth(key);
|
|
50
|
+
console.log(chalk.green('\n✔ Prompt Forge API key saved securely locally.'));
|
|
60
51
|
return getAuth();
|
|
61
52
|
}
|
|
62
53
|
return auth;
|
package/src/studio.js
CHANGED
|
@@ -81,20 +81,14 @@ async function handleCommand(input) {
|
|
|
81
81
|
break;
|
|
82
82
|
|
|
83
83
|
case ':key':
|
|
84
|
-
const { provider } = await inquirer.prompt([{
|
|
85
|
-
type: 'list',
|
|
86
|
-
name: 'provider',
|
|
87
|
-
message: 'Which provider to configure?',
|
|
88
|
-
choices: AVAILABLE_MODELS.map(m => m === 'gpt-4o' ? 'openai' : (m === 'claude' ? 'anthropic' : 'gemini'))
|
|
89
|
-
}]);
|
|
90
84
|
const { key } = await inquirer.prompt([{
|
|
91
85
|
type: 'password',
|
|
92
86
|
name: 'key',
|
|
93
|
-
message: `Enter new
|
|
87
|
+
message: `Enter new Prompt Forge API Key:`,
|
|
94
88
|
mask: '*'
|
|
95
89
|
}]);
|
|
96
|
-
setAuth(
|
|
97
|
-
showInfoBox(`Key updated
|
|
90
|
+
setAuth(key);
|
|
91
|
+
showInfoBox(`Prompt Forge API Key updated.`);
|
|
98
92
|
break;
|
|
99
93
|
|
|
100
94
|
default:
|
package/test-project/README.md
DELETED