| 137 | } |
| 138 | |
| 139 | export async function getSkillQuestions( |
| 140 | libraries: Array<{ id: string; name: string }>, |
| 141 | motivation: string, |
| 142 | accessToken?: string |
| 143 | ): Promise<SkillQuestionsResponse> { |
| 144 | const headers: Record<string, string> = { "Content-Type": "application/json" }; |
| 145 | if (accessToken) { |
| 146 | headers["Authorization"] = `Bearer ${accessToken}`; |
| 147 | } |
| 148 | |
| 149 | const response = await fetch(`${baseUrl}/api/v2/skills/questions`, { |
| 150 | method: "POST", |
| 151 | headers, |
| 152 | body: JSON.stringify({ libraries, motivation }), |
| 153 | }); |
| 154 | |
| 155 | if (!response.ok) { |
| 156 | const errorData = await response.json().catch(() => ({})); |
| 157 | return { |
| 158 | questions: [], |
| 159 | error: (errorData as { message?: string }).message || `HTTP error ${response.status}`, |
| 160 | }; |
| 161 | } |
| 162 | |
| 163 | return (await response.json()) as SkillQuestionsResponse; |
| 164 | } |
| 165 | |
| 166 | export async function generateSkillStructured( |
| 167 | input: StructuredGenerateInput, |