akhaliq HF Staff commited on
Commit
da59e40
Β·
1 Parent(s): fe566fd
frontend/src/app/page.tsx CHANGED
@@ -159,56 +159,55 @@ export default function Home() {
159
 
160
  const handleDeploy = async () => {
161
  if (!generatedCode) {
162
- alert('No code to deploy! Generate some code first.');
163
  return;
164
  }
165
 
166
  // Determine if we're updating an existing space or creating a new one
167
  let existingRepoId = currentRepoId;
168
- let actionMessage = 'Deploy';
169
 
170
  // If we have a current repo, check if user owns it
171
  if (currentRepoId && username) {
172
  const ownsSpace = currentRepoId.startsWith(`${username}/`);
173
  if (ownsSpace) {
174
- actionMessage = 'Update';
175
- const confirmUpdate = confirm(`Update existing space: ${currentRepoId}?`);
176
- if (!confirmUpdate) {
177
- existingRepoId = null; // Create new space instead
178
- actionMessage = 'Deploy';
179
- }
180
  } else {
181
  // User doesn't own the imported space, create a new one
182
  existingRepoId = null;
183
- actionMessage = 'Deploy';
184
  }
 
 
185
  }
186
 
187
- // Only prompt for space name if creating new space
188
- let spaceName = undefined;
189
- if (!existingRepoId) {
190
- const input = prompt('Enter HuggingFace Space name (or leave empty for auto-generated):');
191
- if (input === null) return; // User cancelled
192
- spaceName = input || undefined;
193
- }
194
 
195
  try {
196
- console.log('[Deploy] Deploying with params:', {
197
- language: selectedLanguage,
198
- space_name: spaceName,
199
- existing_repo_id: existingRepoId,
200
- currentRepoId: currentRepoId,
201
- username: username,
202
- code_length: generatedCode.length
203
- });
204
 
205
- const response = await apiClient.deploy({
206
  code: generatedCode,
207
  space_name: spaceName,
208
  language: selectedLanguage,
209
  existing_repo_id: existingRepoId || undefined,
210
  commit_message: existingRepoId ? 'Update via AnyCoder' : undefined,
211
- });
 
 
 
 
 
 
 
212
 
213
  if (response.success) {
214
  // Update current repo ID if we got one back
@@ -229,7 +228,7 @@ export default function Home() {
229
  role: 'assistant',
230
  content: existingRepoId
231
  ? `βœ… Updated space: ${response.space_url}`
232
- : `βœ… Deployed to: ${response.space_url}`,
233
  timestamp: new Date().toISOString(),
234
  };
235
  setMessages((prev) => [...prev, deployMessage]);
@@ -243,7 +242,7 @@ export default function Home() {
243
  ? 'πŸš€ Opening HuggingFace Spaces creation page...\nPlease complete the space setup in the new tab.'
244
  : existingRepoId
245
  ? `βœ… Updated successfully!\n\nOpening: ${response.space_url}`
246
- : `βœ… Deployed successfully!\n\nOpening: ${response.space_url}`;
247
  alert(message);
248
  } else {
249
  alert(`Deployment failed: ${response.message}`);
@@ -261,7 +260,12 @@ export default function Home() {
261
  };
262
 
263
  const handleImport = (code: string, language: Language, importUrl?: string) => {
264
- console.log('[Import] Importing project:', { language, importUrl, username });
 
 
 
 
 
265
  setGeneratedCode(code);
266
  setSelectedLanguage(language);
267
 
@@ -269,17 +273,30 @@ export default function Home() {
269
  if (importUrl) {
270
  const spaceMatch = importUrl.match(/huggingface\.co\/spaces\/([^\/\s\)]+\/[^\/\s\)]+)/);
271
  console.log('[Import] Regex match result:', spaceMatch);
 
272
  if (spaceMatch) {
273
  const importedRepoId = spaceMatch[1];
274
- console.log('[Import] Extracted repo_id:', importedRepoId, 'Username:', username);
 
 
 
 
 
 
 
 
275
  // Only set as current repo if user owns it
276
  if (username && importedRepoId.startsWith(`${username}/`)) {
277
  setCurrentRepoId(importedRepoId);
278
- console.log('[Import] βœ… Set current repo to:', importedRepoId);
279
  } else {
280
  // User doesn't own the imported space, clear current repo
281
  setCurrentRepoId(null);
282
- console.log('[Import] ⚠️ User does not own imported space:', importedRepoId, '(username:', username, ')');
 
 
 
 
283
  }
284
  } else {
285
  console.log('[Import] ⚠️ Could not extract repo_id from URL:', importUrl);
@@ -288,6 +305,8 @@ export default function Home() {
288
  console.log('[Import] No import URL provided');
289
  }
290
 
 
 
291
  // Add messages that include the imported code so LLM can see it
292
  const userMessage: Message = {
293
  role: 'user',
@@ -299,7 +318,7 @@ export default function Home() {
299
 
300
  const assistantMessage: Message = {
301
  role: 'assistant',
302
- content: `βœ… I've loaded your ${language} project. The code is now in the editor. You can ask me to:\n\nβ€’ Modify existing features\nβ€’ Add new functionality\nβ€’ Fix bugs or improve code\nβ€’ Explain how it works\nβ€’ Deploy it to HuggingFace Spaces\n\nWhat would you like me to help you with?`,
303
  timestamp: new Date().toISOString(),
304
  };
305
 
 
159
 
160
  const handleDeploy = async () => {
161
  if (!generatedCode) {
162
+ alert('No code to publish! Generate some code first.');
163
  return;
164
  }
165
 
166
  // Determine if we're updating an existing space or creating a new one
167
  let existingRepoId = currentRepoId;
 
168
 
169
  // If we have a current repo, check if user owns it
170
  if (currentRepoId && username) {
171
  const ownsSpace = currentRepoId.startsWith(`${username}/`);
172
  if (ownsSpace) {
173
+ // Update existing space without asking
174
+ console.log('[Deploy] Updating existing space:', currentRepoId);
 
 
 
 
175
  } else {
176
  // User doesn't own the imported space, create a new one
177
  existingRepoId = null;
178
+ console.log('[Deploy] Creating new space (user does not own imported space)');
179
  }
180
+ } else {
181
+ console.log('[Deploy] Creating new space (no current repo)');
182
  }
183
 
184
+ // Auto-generate space name (never prompt user)
185
+ let spaceName = undefined; // undefined = backend will auto-generate
 
 
 
 
 
186
 
187
  try {
188
+ console.log('[Deploy] ========== DEPLOY START ==========');
189
+ console.log('[Deploy] Current username:', username);
190
+ console.log('[Deploy] Current repo ID (state):', currentRepoId);
191
+ console.log('[Deploy] Existing repo ID (var):', existingRepoId);
192
+ console.log('[Deploy] Space name:', spaceName);
193
+ console.log('[Deploy] Language:', selectedLanguage);
194
+ console.log('[Deploy] Code length:', generatedCode.length);
195
+ console.log('[Deploy] ========================================');
196
 
197
+ const deployRequest = {
198
  code: generatedCode,
199
  space_name: spaceName,
200
  language: selectedLanguage,
201
  existing_repo_id: existingRepoId || undefined,
202
  commit_message: existingRepoId ? 'Update via AnyCoder' : undefined,
203
+ };
204
+
205
+ console.log('[Deploy] πŸš€ Sending request to backend:', JSON.stringify({
206
+ ...deployRequest,
207
+ code: `${deployRequest.code.substring(0, 100)}... (${deployRequest.code.length} chars)`
208
+ }, null, 2));
209
+
210
+ const response = await apiClient.deploy(deployRequest);
211
 
212
  if (response.success) {
213
  // Update current repo ID if we got one back
 
228
  role: 'assistant',
229
  content: existingRepoId
230
  ? `βœ… Updated space: ${response.space_url}`
231
+ : `βœ… Published to: ${response.space_url}`,
232
  timestamp: new Date().toISOString(),
233
  };
234
  setMessages((prev) => [...prev, deployMessage]);
 
242
  ? 'πŸš€ Opening HuggingFace Spaces creation page...\nPlease complete the space setup in the new tab.'
243
  : existingRepoId
244
  ? `βœ… Updated successfully!\n\nOpening: ${response.space_url}`
245
+ : `βœ… Published successfully!\n\nOpening: ${response.space_url}`;
246
  alert(message);
247
  } else {
248
  alert(`Deployment failed: ${response.message}`);
 
260
  };
261
 
262
  const handleImport = (code: string, language: Language, importUrl?: string) => {
263
+ console.log('[Import] ========== IMPORT START ==========');
264
+ console.log('[Import] Language:', language);
265
+ console.log('[Import] Import URL:', importUrl);
266
+ console.log('[Import] Current username:', username);
267
+ console.log('[Import] Current repo before import:', currentRepoId);
268
+
269
  setGeneratedCode(code);
270
  setSelectedLanguage(language);
271
 
 
273
  if (importUrl) {
274
  const spaceMatch = importUrl.match(/huggingface\.co\/spaces\/([^\/\s\)]+\/[^\/\s\)]+)/);
275
  console.log('[Import] Regex match result:', spaceMatch);
276
+
277
  if (spaceMatch) {
278
  const importedRepoId = spaceMatch[1];
279
+ const importedUsername = importedRepoId.split('/')[0];
280
+
281
+ console.log('[Import] ========================================');
282
+ console.log('[Import] Extracted repo_id:', importedRepoId);
283
+ console.log('[Import] Imported username:', importedUsername);
284
+ console.log('[Import] Logged-in username:', username);
285
+ console.log('[Import] Ownership check:', importedUsername === username);
286
+ console.log('[Import] ========================================');
287
+
288
  // Only set as current repo if user owns it
289
  if (username && importedRepoId.startsWith(`${username}/`)) {
290
  setCurrentRepoId(importedRepoId);
291
+ console.log('[Import] βœ…βœ…βœ… SETTING currentRepoId to:', importedRepoId);
292
  } else {
293
  // User doesn't own the imported space, clear current repo
294
  setCurrentRepoId(null);
295
+ if (!username) {
296
+ console.log('[Import] ⚠️⚠️⚠️ USERNAME IS NULL - Cannot set repo ownership!');
297
+ } else {
298
+ console.log('[Import] ⚠️ User does not own imported space:', importedRepoId, '(username:', username, ')');
299
+ }
300
  }
301
  } else {
302
  console.log('[Import] ⚠️ Could not extract repo_id from URL:', importUrl);
 
305
  console.log('[Import] No import URL provided');
306
  }
307
 
308
+ console.log('[Import] ========== IMPORT END ==========');
309
+
310
  // Add messages that include the imported code so LLM can see it
311
  const userMessage: Message = {
312
  role: 'user',
 
318
 
319
  const assistantMessage: Message = {
320
  role: 'assistant',
321
+ content: `βœ… I've loaded your ${language} project. The code is now in the editor. You can ask me to:\n\nβ€’ Modify existing features\nβ€’ Add new functionality\nβ€’ Fix bugs or improve code\nβ€’ Explain how it works\nβ€’ Publish it to HuggingFace Spaces\n\nWhat would you like me to help you with?`,
322
  timestamp: new Date().toISOString(),
323
  };
324
 
frontend/src/components/ControlPanel.tsx CHANGED
@@ -176,7 +176,7 @@ export default function ControlPanel({
176
  className="w-full px-4 py-3.5 bg-[#007aff] text-white text-sm rounded-xl hover:bg-[#0051d5] disabled:opacity-50 disabled:cursor-not-allowed transition-all font-semibold flex items-center justify-center space-x-2 shadow-md active:scale-95"
177
  >
178
  <span>πŸš€</span>
179
- <span>Deploy</span>
180
  </button>
181
  <button
182
  onClick={onClear}
@@ -195,7 +195,7 @@ export default function ControlPanel({
195
  <li>β€’ Import projects from HF/GitHub</li>
196
  <li>β€’ Be specific in your requirements</li>
197
  <li>β€’ Try different AI models</li>
198
- <li>β€’ Deploy to HF Spaces</li>
199
  </ul>
200
  </div>
201
 
 
176
  className="w-full px-4 py-3.5 bg-[#007aff] text-white text-sm rounded-xl hover:bg-[#0051d5] disabled:opacity-50 disabled:cursor-not-allowed transition-all font-semibold flex items-center justify-center space-x-2 shadow-md active:scale-95"
177
  >
178
  <span>πŸš€</span>
179
+ <span>Publish</span>
180
  </button>
181
  <button
182
  onClick={onClear}
 
195
  <li>β€’ Import projects from HF/GitHub</li>
196
  <li>β€’ Be specific in your requirements</li>
197
  <li>β€’ Try different AI models</li>
198
+ <li>β€’ Publish to HF Spaces</li>
199
  </ul>
200
  </div>
201