feat: wire Nitro API to Go, real staffing plan and train proxy

- Replace mock Nitro routes with server-side proxies to the Go API
- /plan reads Go /api/staffing; local assumption edits are a labeled preview
- /simulate reads base and scenario staffing from Go instead of local multipliers
- Route train upload and scenario POST through Nitro with server-only credentials
- Keep NUXT_PUBLIC_USE_MOCK=1 as an explicit dev fallback only
- Match Go's global-peak flat schedule and add a captured Go parity fixture
- Run the web runtime as numeric UID/GID 10001:10001
- Add make check, Gitea CI workflow and a proxy smoke script
This commit is contained in:
Noel Sabia committed 2026-11-14 06:13:00 +01:00
1 parent e8d141ca43
commit b33e6ff001
33 files changed
+1147 -317

No files matched your search

+40 -23
View File
@@ -6,7 +6,6 @@ interface TrainResponse {
status: string
model: 'small' | 'forecast'
submitted_at: string
mock?: boolean
}
interface TrainJob {
@@ -44,70 +43,87 @@ const statusColor = computed(() => {
}
})
function apiErrorMessage(error: unknown, fallback: string): string {
const data = (
error as {
data?: { error?: { message?: string }; message?: string; statusMessage?: string }
}
)?.data
return data?.error?.message ?? data?.message ?? data?.statusMessage ?? fallback
}
function stopPolling() {
if (pollTimer) clearInterval(pollTimer)
pollTimer = undefined
polling.value = false
}
async function poll(jobId: string) {
stopPolling()
polling.value = true
let attempts = 0
pollTimer = setInterval(async () => {
attempts += 1
try {
const result = await $fetch<TrainJob>(`/api/train/${jobId}`)
const result = await $fetch<TrainJob>(`/api/train/${encodeURIComponent(jobId)}`)
job.value = result
if (result.status === 'succeeded' || result.status === 'failed') {
clearInterval(pollTimer)
polling.value = false
}
} catch {
if (attempts >= 12) {
clearInterval(pollTimer)
polling.value = false
errorMessage.value = 'Could not read the mock training job status.'
if (result.status === 'succeeded' || result.status === 'failed') stopPolling()
} catch (error) {
if (attempts >= 30) {
stopPolling()
errorMessage.value = apiErrorMessage(error, 'Could not read the training job status.')
}
}
}, 700)
}, 1000)
}
async function submit() {
errorMessage.value = ''
job.value = null
if (!file.value) {
errorMessage.value = 'Choose a CSV file first.'
return
}
submitting.value = true
try {
const formData = new FormData()
formData.append('model', model.value)
if (file.value) formData.append('file', file.value)
formData.append('file', file.value)
const response = await $fetch<TrainResponse>('/api/train', { method: 'POST', body: formData })
await poll(response.job_id)
} catch {
errorMessage.value = 'Training submission failed. The mock endpoint expects a CSV or model selection.'
} catch (error) {
errorMessage.value = apiErrorMessage(
error,
'Training submission failed. Check the Go API and its FastAPI training upstream.',
)
} finally {
submitting.value = false
}
}
onBeforeUnmount(() => {
if (pollTimer) clearInterval(pollTimer)
})
onBeforeUnmount(stopPolling)
</script>
<template>
<OnyxCard>
<div class="card-header">
<OnyxHeadline is="h3">Train new data</OnyxHeadline>
<OnyxBadge color="warning" density="compact">P1 mock</OnyxBadge>
<OnyxBadge color="info" density="compact">Server proxy</OnyxBadge>
</div>
<p class="small muted" style="margin-top: 0">
Posts to the mock <code>/api/train</code> contract. Replace the Nitro route with the Go endpoint when it
exists; the form shape stays the same.
Uploads through Nitro to Go <code>/api/train</code>. The control credentials stay in the Node process and are
never sent to the browser.
</p>
<form class="form-grid" @submit.prevent="submit">
<OnyxFileUpload
v-model="file"
label="Training CSV"
message="Optional in the mock."
message="Challenge CSV schema. Required."
:accept="['text/csv']"
max-size="50MiB"
/>
<p class="small muted" style="margin: 0">The real endpoint expects the challenge CSV schema.</p>
<OnyxSelect
v-model="model"
label="Model"
@@ -122,6 +138,7 @@ onBeforeUnmount(() => {
:loading="submitting || polling"
/>
<span v-if="submitting" class="small muted">Submitting…</span>
<span v-else-if="polling" class="small muted">Training job running…</span>
</div>
</form>