xoxohp 1.0.3 → 1.0.4
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/index.js +31 -38
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -134,8 +134,12 @@ const path = require('path');
|
|
|
134
134
|
const yargs = require('yargs/yargs');
|
|
135
135
|
const { hideBin } = require('yargs/helpers');
|
|
136
136
|
|
|
137
|
-
//
|
|
138
|
-
const
|
|
137
|
+
// Fetch for Node.js
|
|
138
|
+
const fetch = (...args) =>
|
|
139
|
+
import('node-fetch').then(({ default: fetch }) => fetch(...args));
|
|
140
|
+
|
|
141
|
+
// 🔐 Put your OpenAI API key here or use process.env.OPENAI_API_KEY
|
|
142
|
+
const API_KEY = process.env.OPENAI_API_KEY || "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";
|
|
139
143
|
|
|
140
144
|
/**
|
|
141
145
|
* Generates a full project structure based on a prompt.
|
|
@@ -145,19 +149,20 @@ async function generateProject(prompt, directoryName) {
|
|
|
145
149
|
|
|
146
150
|
const newPrompt = `
|
|
147
151
|
You are an expert software developer and project scaffolder.
|
|
148
|
-
|
|
149
|
-
Each
|
|
150
|
-
|
|
151
|
-
|
|
152
|
+
Return a JSON array of files.
|
|
153
|
+
Each item must contain:
|
|
154
|
+
- filename
|
|
155
|
+
- code
|
|
152
156
|
|
|
153
|
-
|
|
157
|
+
Return ONLY valid JSON. No markdown.
|
|
154
158
|
|
|
155
159
|
User Prompt: "${prompt}"
|
|
156
160
|
`;
|
|
157
161
|
|
|
158
162
|
const body = {
|
|
159
163
|
model: "gpt-4.1-mini",
|
|
160
|
-
input: newPrompt
|
|
164
|
+
input: newPrompt,
|
|
165
|
+
max_output_tokens: 3000
|
|
161
166
|
};
|
|
162
167
|
|
|
163
168
|
try {
|
|
@@ -173,30 +178,22 @@ User Prompt: "${prompt}"
|
|
|
173
178
|
});
|
|
174
179
|
|
|
175
180
|
if (!response.ok) {
|
|
176
|
-
|
|
177
|
-
throw new Error(error);
|
|
181
|
+
throw new Error(await response.text());
|
|
178
182
|
}
|
|
179
183
|
|
|
180
184
|
const data = await response.json();
|
|
181
185
|
|
|
182
|
-
|
|
183
|
-
|
|
186
|
+
let responseText =
|
|
187
|
+
data.output_text ||
|
|
188
|
+
data.output?.[0]?.content?.[0]?.text ||
|
|
189
|
+
"";
|
|
184
190
|
|
|
185
|
-
// Remove accidental code fences
|
|
186
191
|
responseText = responseText
|
|
187
192
|
.replace(/^```json/, "")
|
|
188
193
|
.replace(/```$/, "")
|
|
189
194
|
.trim();
|
|
190
195
|
|
|
191
|
-
let files;
|
|
192
|
-
try {
|
|
193
|
-
files = JSON.parse(responseText);
|
|
194
|
-
if (!Array.isArray(files)) throw new Error();
|
|
195
|
-
} catch {
|
|
196
|
-
console.error("❌ Invalid JSON returned by AI:");
|
|
197
|
-
console.error(responseText);
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
196
|
+
let files = JSON.parse(responseText);
|
|
200
197
|
|
|
201
198
|
fs.mkdirSync(directoryName, { recursive: true });
|
|
202
199
|
|
|
@@ -208,33 +205,29 @@ User Prompt: "${prompt}"
|
|
|
208
205
|
|
|
209
206
|
console.log(`🎉 Project "${directoryName}" created successfully!`);
|
|
210
207
|
|
|
211
|
-
} catch (
|
|
212
|
-
console.error("❌ Error:",
|
|
208
|
+
} catch (err) {
|
|
209
|
+
console.error("❌ Error:", err.message);
|
|
213
210
|
}
|
|
214
211
|
}
|
|
215
212
|
|
|
216
|
-
//
|
|
213
|
+
// CLI
|
|
217
214
|
yargs(hideBin(process.argv))
|
|
218
215
|
.command(
|
|
219
216
|
"$0 <prompt>",
|
|
220
|
-
"
|
|
221
|
-
(
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
.option("directory", {
|
|
228
|
-
alias: "d",
|
|
229
|
-
type: "string",
|
|
230
|
-
demandOption: true
|
|
231
|
-
}),
|
|
217
|
+
"Generate a project from a prompt",
|
|
218
|
+
(y) =>
|
|
219
|
+
y.option("directory", {
|
|
220
|
+
alias: "d",
|
|
221
|
+
type: "string",
|
|
222
|
+
demandOption: true
|
|
223
|
+
}),
|
|
232
224
|
(argv) => {
|
|
233
225
|
if (!API_KEY) {
|
|
234
|
-
console.error("❌
|
|
226
|
+
console.error("❌ Set OPENAI_API_KEY first");
|
|
235
227
|
return;
|
|
236
228
|
}
|
|
237
229
|
generateProject(argv.prompt, argv.directory);
|
|
238
230
|
}
|
|
239
231
|
)
|
|
240
232
|
.parse();
|
|
233
|
+
|