weazel/houseai-modularizer
0
1```javascript2// API communication functions3import { CONFIG } from './config.js';4 5// Fetch health status6export async function fetchHealthStatus() {7 try {8 const response = await fetch(`${CONFIG.API_BASE_URL}/health`, {9 method: 'GET',10 headers: {11 'Content-Type': 'application/json'12 }13 });14 15 if (!response.ok) {16 throw new Error(`HTTP error! status: ${response.status}`);17 }18 19 return await response.json();20 } catch (error) {21 throw new Error(`Failed to fetch health status: ${error.message}`);22 }23}24 25// Send message to API26export async function sendMessageToAPI(message, conversationId) {27 try {28 const response = await fetch(`${CONFIG.API_BASE_URL}/chat`, {29 method: 'POST',30 headers: {31 'Content-Type': 'application/json'32 },33 body: JSON.stringify({34 message: message,35 conversation_id: conversationId,36 model: CONFIG.DEFAULT_MODEL37 })38 });39 40 if (!response.ok) {41 throw new Error(`HTTP error! status: ${response.status}`);42 }43 44 return await response.json();45 } catch (error) {46 throw new Error(`Failed to send message: ${error.message}`);47 }48}49 50// Fetch changelog51export async function fetchChangelog() {52 try {53 const response = await fetch(`${CONFIG.API_BASE_URL}/changelog`, {54 method: 'GET',55 headers: {56 'Content-Type': 'application/json'57 }58 });59 60 if (!response.ok) {61 throw new Error(`HTTP error! status: ${response.status}`);62 }63 64 return await response.json();65 } catch (error) {66 throw new Error(`Failed to fetch changelog: ${error.message}`);67 }68}69```