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.
Files changed (2) hide show
  1. package/index.js +31 -38
  2. 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
- // ⚠️ PUT YOUR *NEW* OPENAI API KEY HERE
138
- const API_KEY = "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";
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
- 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
+ Return a JSON array of files.
153
+ Each item must contain:
154
+ - filename
155
+ - code
152
156
 
153
- Only return the raw JSON array. No markdown. No explanations.
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
- const error = await response.text();
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
- // OpenAI response text
183
- let responseText = data.output_text;
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 (error) {
212
- console.error("❌ Error:", error.message);
208
+ } catch (err) {
209
+ console.error("❌ Error:", err.message);
213
210
  }
214
211
  }
215
212
 
216
- // --- CLI ---
213
+ // CLI
217
214
  yargs(hideBin(process.argv))
218
215
  .command(
219
216
  "$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
- }),
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("❌ Missing OpenAI API key");
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
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xoxohp",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "main": "index.js",
5
5
  "bin":{
6
6
  "xoxohp":"./index.js"