chore: align infrastructure with server
This commit is contained in:
@@ -31,11 +31,16 @@ export default defineEventHandler(async (event) => {
|
||||
orderBy: { updatedAt: 'desc' }
|
||||
})
|
||||
|
||||
const totalCount = await prisma.canvas.count()
|
||||
|
||||
const canvases = canvasList.map(c => ({
|
||||
...c,
|
||||
nodeCount: Array.isArray(c.nodes) ? (c.nodes as any[]).length : 0,
|
||||
nodes: undefined
|
||||
}))
|
||||
|
||||
return {
|
||||
canvases: canvasList.map(c => ({
|
||||
...c,
|
||||
nodeCount: Array.isArray(c.nodes) ? (c.nodes as any[]).length : 0,
|
||||
nodes: undefined
|
||||
}))
|
||||
canvases,
|
||||
totalCount
|
||||
}
|
||||
})
|
||||
|
||||
@@ -8,6 +8,8 @@ export default defineEventHandler(async (event) => {
|
||||
const body = await readBody(event)
|
||||
const { canvasId, context } = body
|
||||
|
||||
console.log(`[Execute] nodeId=${nodeId} canvasId=${canvasId} userId=${user.id}`)
|
||||
|
||||
if (!nodeId || !canvasId) {
|
||||
throw createError({ statusCode: 400, message: 'Node ID and Canvas ID are required' })
|
||||
}
|
||||
@@ -17,6 +19,8 @@ export default defineEventHandler(async (event) => {
|
||||
where: { id: canvasId }
|
||||
})
|
||||
|
||||
console.log(`[Execute] Canvas found: ${!!canvas}, nodes count: ${(canvas?.nodes as any[])?.length}`)
|
||||
|
||||
if (!canvas) {
|
||||
throw createError({ statusCode: 404, message: 'Canvas not found' })
|
||||
}
|
||||
@@ -30,11 +34,14 @@ export default defineEventHandler(async (event) => {
|
||||
const nodes = (canvas.nodes as any[]) || []
|
||||
const nodeIdx = nodes.findIndex(n => n.id === nodeId)
|
||||
|
||||
console.log(`[Execute] Node found at index: ${nodeIdx}`)
|
||||
|
||||
if (nodeIdx === -1) {
|
||||
throw createError({ statusCode: 404, message: 'Node not found in canvas' })
|
||||
throw createError({ statusCode: 404, message: `Node ${nodeId} not found in canvas ${canvasId}` })
|
||||
}
|
||||
|
||||
const node = nodes[nodeIdx]
|
||||
console.log(`[Execute] Node type: ${node.type}`)
|
||||
|
||||
try {
|
||||
let result = ''
|
||||
@@ -42,15 +49,17 @@ export default defineEventHandler(async (event) => {
|
||||
if (node.type === 'ai') {
|
||||
// Формируем промпт с учетом контекста от соседей
|
||||
let fullPrompt = node.prompt || node.text || 'Analyze the provided context.'
|
||||
|
||||
|
||||
if (context && context.length > 0) {
|
||||
const contextText = context.map((c: any) => `[Node ${c.id}]: ${c.text}`).join('\n\n')
|
||||
fullPrompt = `CONTEXT INFORMATION:\n${contextText}\n\nUSER REQUEST/INSTRUCTION:\n${fullPrompt}`
|
||||
}
|
||||
|
||||
console.log(`[AI Execute] Generating response with context for node ${nodeId}...`)
|
||||
result = await generateAIResponse(fullPrompt)
|
||||
|
||||
// Модель можно задать прямо в узле: node.model = 'qwen_coder' | 'llama' | 'gemma' | 'laguna' | 'nemotron'
|
||||
const model = node.model || undefined
|
||||
console.log(`[AI Execute] model=${model || 'default'} nodeId=${nodeId}`)
|
||||
result = await generateAIResponse(fullPrompt, 'You are a helpful assistant.', model)
|
||||
|
||||
// Сохраняем результат в текст узла
|
||||
nodes[nodeIdx].text = result
|
||||
|
||||
|
||||
Reference in New Issue
Block a user