xoxohp 1.0.3 → 1.0.5
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 +40 -100
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -128,113 +128,53 @@
|
|
|
128
128
|
|
|
129
129
|
|
|
130
130
|
// #!/usr/bin/env node
|
|
131
|
+
const fs = require("fs");
|
|
132
|
+
const path = require("path");
|
|
133
|
+
const yargs = require("yargs/yargs");
|
|
134
|
+
const { hideBin } = require("yargs/helpers");
|
|
131
135
|
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
const yargs = require('yargs/yargs');
|
|
135
|
-
const { hideBin } = require('yargs/helpers');
|
|
136
|
+
const fetch = (...args) =>
|
|
137
|
+
import("node-fetch").then(({ default: fetch }) => fetch(...args));
|
|
136
138
|
|
|
137
|
-
|
|
138
|
-
const API_KEY = "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";
|
|
139
|
+
const API_KEY = "sk-REPLACE_Wsk-proj-5C2jXi-puM9lM9wBlm4njzPxEpdPrIv840zAYfcVdhEZqes1ZrXht8mmJv_KraMV8N4B49gDbcT3BlbkFJyUcZobGhM7KXL80Cmueh3X-ZyPmNA_fY2tCUknWEGbHPSpkGco0vzVBdZCPzgp8vjp8X_OyfgAITH_YOUR_NEW_KEY";
|
|
139
140
|
|
|
140
|
-
/**
|
|
141
|
-
* Generates a full project structure based on a prompt.
|
|
142
|
-
*/
|
|
143
141
|
async function generateProject(prompt, directoryName) {
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
input: newPrompt
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
try {
|
|
164
|
-
console.log("Generating project...");
|
|
165
|
-
|
|
166
|
-
const response = await fetch(url, {
|
|
167
|
-
method: "POST",
|
|
168
|
-
headers: {
|
|
169
|
-
"Authorization": `Bearer ${API_KEY}`,
|
|
170
|
-
"Content-Type": "application/json"
|
|
171
|
-
},
|
|
172
|
-
body: JSON.stringify(body)
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
if (!response.ok) {
|
|
176
|
-
const error = await response.text();
|
|
177
|
-
throw new Error(error);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const data = await response.json();
|
|
181
|
-
|
|
182
|
-
// OpenAI response text
|
|
183
|
-
let responseText = data.output_text;
|
|
184
|
-
|
|
185
|
-
// Remove accidental code fences
|
|
186
|
-
responseText = responseText
|
|
187
|
-
.replace(/^```json/, "")
|
|
188
|
-
.replace(/```$/, "")
|
|
189
|
-
.trim();
|
|
190
|
-
|
|
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
|
-
}
|
|
142
|
+
const response = await fetch("https://api.openai.com/v1/responses", {
|
|
143
|
+
method: "POST",
|
|
144
|
+
headers: {
|
|
145
|
+
"Authorization": `Bearer ${API_KEY}`,
|
|
146
|
+
"Content-Type": "application/json"
|
|
147
|
+
},
|
|
148
|
+
body: JSON.stringify({
|
|
149
|
+
model: "gpt-4.1-mini",
|
|
150
|
+
input: `Return ONLY a JSON array.\nPrompt: ${prompt}`
|
|
151
|
+
})
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
if (!response.ok) {
|
|
155
|
+
console.error(await response.text());
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
200
158
|
|
|
201
|
-
|
|
159
|
+
const data = await response.json();
|
|
202
160
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
161
|
+
let responseText = "";
|
|
162
|
+
for (const item of data.output) {
|
|
163
|
+
if (item.type === "message") {
|
|
164
|
+
for (const c of item.content) {
|
|
165
|
+
if (c.type === "output_text") responseText += c.text;
|
|
166
|
+
}
|
|
207
167
|
}
|
|
168
|
+
}
|
|
208
169
|
|
|
209
|
-
|
|
170
|
+
const files = JSON.parse(responseText);
|
|
210
171
|
|
|
211
|
-
|
|
212
|
-
|
|
172
|
+
fs.mkdirSync(directoryName, { recursive: true });
|
|
173
|
+
for (const f of files) {
|
|
174
|
+
const filePath = path.join(directoryName, f.filename);
|
|
175
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
176
|
+
fs.writeFileSync(filePath, f.code);
|
|
213
177
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
yargs(hideBin(process.argv))
|
|
218
|
-
.command(
|
|
219
|
-
"$0 <prompt>",
|
|
220
|
-
"Generates a full project structure from a text prompt.",
|
|
221
|
-
(yargs) =>
|
|
222
|
-
yargs
|
|
223
|
-
.positional("prompt", {
|
|
224
|
-
describe: "Project description",
|
|
225
|
-
type: "string"
|
|
226
|
-
})
|
|
227
|
-
.option("directory", {
|
|
228
|
-
alias: "d",
|
|
229
|
-
type: "string",
|
|
230
|
-
demandOption: true
|
|
231
|
-
}),
|
|
232
|
-
(argv) => {
|
|
233
|
-
if (!API_KEY) {
|
|
234
|
-
console.error("❌ Missing OpenAI API key");
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
generateProject(argv.prompt, argv.directory);
|
|
238
|
-
}
|
|
239
|
-
)
|
|
240
|
-
.parse();
|
|
178
|
+
|
|
179
|
+
console.log("🎉 Project created successfully!");
|
|
180
|
+
}
|