| 1 |
import { fetchWithTimeout } from '@auto-launch/functions/helpers'; |
| 2 |
import { AI_HOST } from '@constants'; |
| 3 |
import { reqDataBasics } from '@shared/lib/data'; |
| 4 |
|
| 5 |
// Any non-1 answer, bad status, or network failure resolves to 0 |
| 6 |
export const getExtendifyCodeRecommendation = async (description) => { |
| 7 |
const response = await fetchWithTimeout( |
| 8 |
`${AI_HOST}/api/launch-decisions/code-recommendation`, |
| 9 |
{ |
| 10 |
method: 'POST', |
| 11 |
headers: { 'Content-Type': 'application/json' }, |
| 12 |
body: JSON.stringify({ ...reqDataBasics, description }), |
| 13 |
}, |
| 14 |
) |
| 15 |
.then((res) => res.ok && res.json()) |
| 16 |
.catch(() => null); |
| 17 |
return response?.recommend === 1 ? 1 : 0; |
| 18 |
}; |
| 19 |
|
| 20 |
export const buildExtendifyCodeLink = (link, { description, title } = {}) => { |
| 21 |
if (!link) return ''; |
| 22 |
const prompt = [title, description] |
| 23 |
.map((part) => part?.trim()) |
| 24 |
.filter(Boolean) |
| 25 |
.join(' — '); |
| 26 |
return link.replace(/\{DESCRIPTION\}/g, encodeURIComponent(prompt)); |
| 27 |
}; |
| 28 |
|