akhaliq HF Staff commited on
Commit
8f21cf3
·
1 Parent(s): a03bf38
backend_api.py CHANGED
@@ -196,6 +196,7 @@ class CodeGenerationRequest(BaseModel):
196
  provider: str = "auto"
197
  history: List[List[str]] = []
198
  agent_mode: bool = False
 
199
 
200
 
201
  class DeploymentRequest(BaseModel):
@@ -881,13 +882,15 @@ async def generate_code(
881
  print(f"[Auto-Deploy] - History items: {len(history_list)}")
882
  print(f"[Auto-Deploy] - Username: {auth.username}")
883
  print(f"[Auto-Deploy] - Code length: {len(generated_code)}")
 
884
 
885
- # Deploy the code
886
  success, message, space_url = deploy_to_huggingface_space(
887
  code=generated_code,
888
  language=language,
889
  token=auth.token,
890
  username=auth.username,
 
891
  history=history_list
892
  )
893
 
 
196
  provider: str = "auto"
197
  history: List[List[str]] = []
198
  agent_mode: bool = False
199
+ existing_repo_id: Optional[str] = None # For auto-deploy to update existing space
200
 
201
 
202
  class DeploymentRequest(BaseModel):
 
882
  print(f"[Auto-Deploy] - History items: {len(history_list)}")
883
  print(f"[Auto-Deploy] - Username: {auth.username}")
884
  print(f"[Auto-Deploy] - Code length: {len(generated_code)}")
885
+ print(f"[Auto-Deploy] - Existing repo ID from request: {request.existing_repo_id}")
886
 
887
+ # Deploy the code (update existing space if provided)
888
  success, message, space_url = deploy_to_huggingface_space(
889
  code=generated_code,
890
  language=language,
891
  token=auth.token,
892
  username=auth.username,
893
+ existing_repo_id=request.existing_repo_id, # Use duplicated/imported space
894
  history=history_list
895
  )
896
 
frontend/src/app/page.tsx CHANGED
@@ -285,6 +285,7 @@ export default function Home() {
285
  provider: 'auto',
286
  history: messages.map((m) => [m.role, m.content]),
287
  agent_mode: false,
 
288
  };
289
 
290
  const assistantMessage: Message = {
 
285
  provider: 'auto',
286
  history: messages.map((m) => [m.role, m.content]),
287
  agent_mode: false,
288
+ existing_repo_id: currentRepoId || undefined, // Pass duplicated/imported space ID for auto-deploy
289
  };
290
 
291
  const assistantMessage: Message = {
frontend/src/components/LandingPage.tsx CHANGED
@@ -257,13 +257,14 @@ export default function LandingPage({
257
  const duplicateResult = await apiClient.duplicateSpace(fromSpaceId);
258
 
259
  if (duplicateResult.success) {
260
- // Show success message with link to duplicated space
261
- alert(`✅ Space duplicated successfully!\n\nView your space: ${duplicateResult.space_url}`);
262
-
263
  // Also load the code in the editor
264
  const importResult = await apiClient.importProject(importUrl);
265
  if (importResult.status === 'success' && onImport && importResult.code) {
 
266
  onImport(importResult.code, importResult.language || 'html', duplicateResult.space_url);
 
 
 
267
  }
268
 
269
  setShowImportDialog(false);
 
257
  const duplicateResult = await apiClient.duplicateSpace(fromSpaceId);
258
 
259
  if (duplicateResult.success) {
 
 
 
260
  // Also load the code in the editor
261
  const importResult = await apiClient.importProject(importUrl);
262
  if (importResult.status === 'success' && onImport && importResult.code) {
263
+ // Pass the duplicated space URL so it's tracked for future deployments
264
  onImport(importResult.code, importResult.language || 'html', duplicateResult.space_url);
265
+
266
+ // Show success message with link to duplicated space
267
+ alert(`✅ Space duplicated successfully!\n\nYour space: ${duplicateResult.space_url}\n\nThe code has been loaded in the editor. Any changes you deploy will update this duplicated space.`);
268
  }
269
 
270
  setShowImportDialog(false);
frontend/src/types/index.ts CHANGED
@@ -19,6 +19,7 @@ export interface CodeGenerationRequest {
19
  provider: string;
20
  history: string[][];
21
  agent_mode: boolean;
 
22
  }
23
 
24
  export interface CodeGenerationResponse {
 
19
  provider: string;
20
  history: string[][];
21
  agent_mode: boolean;
22
+ existing_repo_id?: string; // For auto-deploy to update existing space
23
  }
24
 
25
  export interface CodeGenerationResponse {