import { apiClient } from "./client"; export interface ConfigProfile { id: string; user_id: string; name: string; description: string | null; project_id: string | null; tool_type_id: string | null; env_vars: Record; runtime_hints: Record; mounts: ConfigProfileMount[]; git_mounts: GitMount[]; files: Record; is_default: boolean; includes: ConfigProfileInclude[]; created_at: string; updated_at: string; } export interface ConfigProfileMount { target: string; mode: "ro" | "rw"; files: Record; } export interface GitMountMapping { source_path: string; target_path: string; } export interface GitMount { remote_url: string; branch?: string; mappings: GitMountMapping[]; // Legacy fields (for backward compatibility when reading old data) source_path?: string; target_path?: string; } export interface ConfigProfileInclude { id: string; included_profile_id: string; order_index: number; } export interface ResolvedProfile { profile_id: string; profile_name: string; env_vars: Record; runtime_hints: Record; mounts: ResolvedMount[]; git_mounts: GitMount[]; files: Record; overrides: { env_vars: Record; runtime_hints: Record; files: Record; mounts: Record; }; included_profiles: Array<{ id: string; name: string }>; } export interface ResolvedMount { target: string; mode: "ro" | "rw"; files: Record; overridden_files: Record; } export interface CreateConfigProfileRequest { name: string; description?: string; project_id?: string; tool_type_id?: string; env_vars?: Record; runtime_hints?: Record; mounts?: ConfigProfileMount[]; git_mounts?: GitMount[]; files?: Record; is_default?: boolean; } export interface UpdateConfigProfileRequest { name?: string; description?: string; project_id?: string; tool_type_id?: string; env_vars?: Record; runtime_hints?: Record; mounts?: ConfigProfileMount[]; git_mounts?: GitMount[]; files?: Record; is_default?: boolean; } export interface UpdateIncludesRequest { includes: string[]; } export const listConfigProfiles = async ( projectId?: string, toolTypeId?: string, ): Promise => { const response = await apiClient.get("/config-profiles", { params: { project_id: projectId, tool_type_id: toolTypeId }, }); return response.data; }; export const getConfigProfile = async (id: string): Promise => { const response = await apiClient.get(`/config-profiles/${id}`); return response.data; }; export const createConfigProfile = async ( data: CreateConfigProfileRequest, ): Promise => { const response = await apiClient.post( "/config-profiles", data, ); return response.data; }; export const updateConfigProfile = async ( id: string, data: UpdateConfigProfileRequest, ): Promise => { const response = await apiClient.put( `/config-profiles/${id}`, data, ); return response.data; }; export const deleteConfigProfile = async (id: string): Promise => { await apiClient.delete(`/config-profiles/${id}`); }; export const updateProfileIncludes = async ( id: string, data: UpdateIncludesRequest, ): Promise => { const response = await apiClient.put( `/config-profiles/${id}/includes`, data, ); return response.data; }; export const previewConfigProfile = async ( id: string, ): Promise => { const response = await apiClient.get( `/config-profiles/${id}/preview`, ); return response.data; }; export const resolveDefaultProfile = async ( projectId: string, toolTypeId: string, ): Promise<{ profile_id: string | null; profile_name: string | null }> => { const response = await apiClient.get("/config-profiles/defaults/resolve", { params: { project_id: projectId, tool_type_id: toolTypeId }, }); return response.data; }; export interface ValidateGitUrlResponse { valid: boolean; suggested_url?: string; branches?: string[]; default_branch?: string; error?: string; error_code?: string; } export const validateGitUrl = async ( url: string, sshKeyId?: string, ): Promise => { const response = await apiClient.post( "/config-profiles/validate-git-url", { url, ssh_key_id: sshKeyId }, ); return response.data; };