xoxohp 1.0.4 → 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 +38 -91
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -128,106 +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 fs = require('fs');
|
|
133
|
-
const path = require('path');
|
|
134
|
-
const yargs = require('yargs/yargs');
|
|
135
|
-
const { hideBin } = require('yargs/helpers');
|
|
136
|
-
|
|
137
|
-
// Fetch for Node.js
|
|
138
136
|
const fetch = (...args) =>
|
|
139
|
-
|
|
137
|
+
import("node-fetch").then(({ default: fetch }) => fetch(...args));
|
|
140
138
|
|
|
141
|
-
|
|
142
|
-
const API_KEY = process.env.OPENAI_API_KEY || "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";
|
|
139
|
+
const API_KEY = "sk-REPLACE_Wsk-proj-5C2jXi-puM9lM9wBlm4njzPxEpdPrIv840zAYfcVdhEZqes1ZrXht8mmJv_KraMV8N4B49gDbcT3BlbkFJyUcZobGhM7KXL80Cmueh3X-ZyPmNA_fY2tCUknWEGbHPSpkGco0vzVBdZCPzgp8vjp8X_OyfgAITH_YOUR_NEW_KEY";
|
|
143
140
|
|
|
144
|
-
/**
|
|
145
|
-
* Generates a full project structure based on a prompt.
|
|
146
|
-
*/
|
|
147
141
|
async function generateProject(prompt, directoryName) {
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
input: newPrompt,
|
|
165
|
-
max_output_tokens: 3000
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
try {
|
|
169
|
-
console.log("Generating project...");
|
|
170
|
-
|
|
171
|
-
const response = await fetch(url, {
|
|
172
|
-
method: "POST",
|
|
173
|
-
headers: {
|
|
174
|
-
"Authorization": `Bearer ${API_KEY}`,
|
|
175
|
-
"Content-Type": "application/json"
|
|
176
|
-
},
|
|
177
|
-
body: JSON.stringify(body)
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
if (!response.ok) {
|
|
181
|
-
throw new Error(await response.text());
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const data = await response.json();
|
|
185
|
-
|
|
186
|
-
let responseText =
|
|
187
|
-
data.output_text ||
|
|
188
|
-
data.output?.[0]?.content?.[0]?.text ||
|
|
189
|
-
"";
|
|
190
|
-
|
|
191
|
-
responseText = responseText
|
|
192
|
-
.replace(/^```json/, "")
|
|
193
|
-
.replace(/```$/, "")
|
|
194
|
-
.trim();
|
|
195
|
-
|
|
196
|
-
let files = JSON.parse(responseText);
|
|
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
|
+
}
|
|
197
158
|
|
|
198
|
-
|
|
159
|
+
const data = await response.json();
|
|
199
160
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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
|
+
}
|
|
204
167
|
}
|
|
168
|
+
}
|
|
205
169
|
|
|
206
|
-
|
|
170
|
+
const files = JSON.parse(responseText);
|
|
207
171
|
|
|
208
|
-
|
|
209
|
-
|
|
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);
|
|
210
177
|
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// CLI
|
|
214
|
-
yargs(hideBin(process.argv))
|
|
215
|
-
.command(
|
|
216
|
-
"$0 <prompt>",
|
|
217
|
-
"Generate a project from a prompt",
|
|
218
|
-
(y) =>
|
|
219
|
-
y.option("directory", {
|
|
220
|
-
alias: "d",
|
|
221
|
-
type: "string",
|
|
222
|
-
demandOption: true
|
|
223
|
-
}),
|
|
224
|
-
(argv) => {
|
|
225
|
-
if (!API_KEY) {
|
|
226
|
-
console.error("❌ Set OPENAI_API_KEY first");
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
generateProject(argv.prompt, argv.directory);
|
|
230
|
-
}
|
|
231
|
-
)
|
|
232
|
-
.parse();
|
|
233
178
|
|
|
179
|
+
console.log("🎉 Project created successfully!");
|
|
180
|
+
}
|