- Added a new method to fetch blueprints from the API, improving data retrieval for site structures. - Updated the WizardPage component to include a progress modal for better user feedback during site structure generation. - Refactored state management in builderStore to track structure generation tasks, enhancing the overall user experience. - Replaced SyncIcon with RefreshCw in integration components for a more consistent iconography. - Improved the site structure generation prompt in utils.py to provide clearer instructions for AI-driven site architecture.
87 lines
2.5 KiB
TypeScript
87 lines
2.5 KiB
TypeScript
import axios from 'axios';
|
|
import type {
|
|
BuilderFormData,
|
|
PageBlueprint,
|
|
SiteBlueprint,
|
|
SiteStructure,
|
|
} from '../types/siteBuilder';
|
|
|
|
const API_ROOT = import.meta.env.VITE_API_URL ?? 'http://localhost:8010/api';
|
|
const BASE_PATH = `${API_ROOT}/v1/site-builder`;
|
|
|
|
const client = axios.create({
|
|
baseURL: BASE_PATH,
|
|
withCredentials: true,
|
|
});
|
|
|
|
export interface CreateBlueprintPayload {
|
|
name: string;
|
|
description?: string;
|
|
site_id: number;
|
|
sector_id: number;
|
|
hosting_type: BuilderFormData['hostingType'];
|
|
config_json: Record<string, unknown>;
|
|
}
|
|
|
|
export interface GenerateStructurePayload {
|
|
business_brief: string;
|
|
objectives: string[];
|
|
style: BuilderFormData['style'];
|
|
metadata?: Record<string, unknown>;
|
|
}
|
|
|
|
export const builderApi = {
|
|
async getBlueprint(blueprintId: number): Promise<SiteBlueprint> {
|
|
const res = await client.get(`/blueprints/${blueprintId}/`);
|
|
return res.data;
|
|
},
|
|
async listBlueprints(): Promise<SiteBlueprint[]> {
|
|
const res = await client.get('/blueprints/');
|
|
if (Array.isArray(res.data?.results)) {
|
|
return res.data.results as SiteBlueprint[];
|
|
}
|
|
return Array.isArray(res.data) ? res.data : [];
|
|
},
|
|
|
|
async createBlueprint(payload: CreateBlueprintPayload): Promise<SiteBlueprint> {
|
|
const res = await client.post('/blueprints/', payload);
|
|
return res.data;
|
|
},
|
|
|
|
async generateStructure(
|
|
blueprintId: number,
|
|
payload: GenerateStructurePayload,
|
|
): Promise<{ task_id?: string; success?: boolean; structure?: SiteStructure }> {
|
|
const res = await client.post(`/blueprints/${blueprintId}/generate_structure/`, payload);
|
|
return res.data;
|
|
},
|
|
|
|
async listPages(blueprintId: number): Promise<PageBlueprint[]> {
|
|
const res = await client.get(`/pages/?site_blueprint=${blueprintId}`);
|
|
return Array.isArray(res.data?.results) ? res.data.results : res.data;
|
|
},
|
|
|
|
async generateAllPages(
|
|
blueprintId: number,
|
|
options?: { pageIds?: number[]; force?: boolean },
|
|
): Promise<{ success: boolean; pages_queued: number; task_ids: number[]; celery_task_id?: string }> {
|
|
const res = await client.post(`/blueprints/${blueprintId}/generate_all_pages/`, {
|
|
page_ids: options?.pageIds,
|
|
force: options?.force || false,
|
|
});
|
|
return res.data?.data || res.data;
|
|
},
|
|
|
|
async createTasksForPages(
|
|
blueprintId: number,
|
|
pageIds?: number[],
|
|
): Promise<{ tasks: unknown[]; count: number }> {
|
|
const res = await client.post(`/blueprints/${blueprintId}/create_tasks/`, {
|
|
page_ids: pageIds,
|
|
});
|
|
return res.data?.data || res.data;
|
|
},
|
|
};
|
|
|
|
|