Skip to content

Commit 6a20981

Browse files
teams init
1 parent 7c4a25a commit 6a20981

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

src/frontend/src/api/config.tsx

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,52 @@ export function headerBuilder(headers?: Record<string, string>): Record<string,
130130
...(headers ? headers : {})
131131
};
132132
}
133+
134+
/**
135+
* Initialize team on the backend - takes about 20 seconds
136+
* @returns Promise with team initialization response
137+
*/
138+
export async function initializeTeam(): Promise<{
139+
status: string;
140+
team_id: string;
141+
}> {
142+
const apiUrl = getApiUrl();
143+
if (!apiUrl) {
144+
throw new Error('API URL not configured');
145+
}
146+
147+
const headers = headerBuilder({
148+
'Content-Type': 'application/json',
149+
});
150+
151+
console.log('initializeTeam: Starting team initialization...');
152+
153+
try {
154+
const response = await fetch(`${apiUrl}/init_team`, {
155+
method: 'GET',
156+
headers,
157+
});
158+
159+
if (!response.ok) {
160+
const errorText = await response.text();
161+
throw new Error(errorText || `HTTP error! status: ${response.status}`);
162+
}
163+
164+
const data = await response.json();
165+
console.log('initializeTeam: Team initialization completed:', data);
166+
167+
// Validate the expected response format
168+
if (data.status !== 'Request started successfully' || !data.team_id) {
169+
throw new Error('Invalid response format from init_team endpoint');
170+
}
171+
172+
return data;
173+
} catch (error) {
174+
console.error('initializeTeam: Error initializing team:', error);
175+
throw error;
176+
}
177+
}
178+
133179
export const toBoolean = (value: any): boolean => {
134180
if (typeof value !== 'string') {
135181
return false;
@@ -145,5 +191,6 @@ export default {
145191
setEnvData,
146192
config,
147193
USER_ID,
148-
API_URL
194+
API_URL,
195+
initializeTeam
149196
};

0 commit comments

Comments
 (0)