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.
Files changed (2) hide show
  1. package/index.js +40 -100
  2. 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 fs = require('fs');
133
- const path = require('path');
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
- // ⚠️ PUT YOUR *NEW* OPENAI API KEY HERE
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 url = "https://api.openai.com/v1/responses";
145
-
146
- const newPrompt = `
147
- You are an expert software developer and project scaffolder.
148
- Based on the user's prompt, generate a complete file structure as a JSON array.
149
- Each object in the array must have two keys:
150
- 1. "filename": (string) The full relative path for the file
151
- 2. "code": (string) The complete code for that file
152
-
153
- Only return the raw JSON array. No markdown. No explanations.
154
-
155
- User Prompt: "${prompt}"
156
- `;
157
-
158
- const body = {
159
- model: "gpt-4.1-mini",
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
- fs.mkdirSync(directoryName, { recursive: true });
159
+ const data = await response.json();
202
160
 
203
- for (const file of files) {
204
- const filePath = path.join(directoryName, file.filename);
205
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
206
- fs.writeFileSync(filePath, file.code);
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
- console.log(`🎉 Project "${directoryName}" created successfully!`);
170
+ const files = JSON.parse(responseText);
210
171
 
211
- } catch (error) {
212
- console.error("❌ Error:", error.message);
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
- // --- CLI ---
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xoxohp",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "main": "index.js",
5
5
  "bin":{
6
6
  "xoxohp":"./index.js"