feat: add AI idea placement triage
This commit is contained in:
@@ -2,6 +2,7 @@ import express from 'express'
|
||||
import path from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { checkBackendHealth, fetchStoredAppState, persistAppState } from './appwriteBackend.mjs'
|
||||
import { triageIdea } from './aiTriage.mjs'
|
||||
|
||||
const app = express()
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
@@ -45,6 +46,25 @@ app.put('/api/state', async (req, res) => {
|
||||
}
|
||||
})
|
||||
|
||||
app.post('/api/ai/triage-idea', async (req, res) => {
|
||||
const rawIdea = req.body?.raw_idea
|
||||
if (typeof rawIdea !== 'string' || !rawIdea.trim()) {
|
||||
res.status(400).json({ ok: false, error: 'raw_idea is required.' })
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const recommendation = await triageIdea({
|
||||
rawIdea,
|
||||
optionalContext: typeof req.body?.optional_context === 'string' ? req.body.optional_context : '',
|
||||
appContext: req.body?.app_context && typeof req.body.app_context === 'object' ? req.body.app_context : {},
|
||||
})
|
||||
res.json({ ok: true, provider: process.env.BUILDPULSE_AI_PROVIDER || 'gemini', recommendation })
|
||||
} catch (error) {
|
||||
res.status(502).json({ ok: false, error: error?.message || 'AI triage failed.' })
|
||||
}
|
||||
})
|
||||
|
||||
app.use(express.static(distDir))
|
||||
|
||||
app.get('/{*path}', (_req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user