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.
Files changed (2) hide show
  1. package/index.js +38 -91
  2. 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
- import('node-fetch').then(({ default: fetch }) => fetch(...args));
137
+ import("node-fetch").then(({ default: fetch }) => fetch(...args));
140
138
 
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
+ 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 url = "https://api.openai.com/v1/responses";
149
-
150
- const newPrompt = `
151
- You are an expert software developer and project scaffolder.
152
- Return a JSON array of files.
153
- Each item must contain:
154
- - filename
155
- - code
156
-
157
- Return ONLY valid JSON. No markdown.
158
-
159
- User Prompt: "${prompt}"
160
- `;
161
-
162
- const body = {
163
- model: "gpt-4.1-mini",
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
- fs.mkdirSync(directoryName, { recursive: true });
159
+ const data = await response.json();
199
160
 
200
- for (const file of files) {
201
- const filePath = path.join(directoryName, file.filename);
202
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
203
- 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
+ }
204
167
  }
168
+ }
205
169
 
206
- console.log(`🎉 Project "${directoryName}" created successfully!`);
170
+ const files = JSON.parse(responseText);
207
171
 
208
- } catch (err) {
209
- console.error("❌ Error:", err.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);
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xoxohp",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "main": "index.js",
5
5
  "bin":{
6
6
  "xoxohp":"./index.js"