( section: InsightSection, dataContext: string, )
| 1570 | } |
| 1571 | |
| 1572 | async function generateSectionInsight( |
| 1573 | section: InsightSection, |
| 1574 | dataContext: string, |
| 1575 | ): Promise<{ name: string; result: unknown }> { |
| 1576 | try { |
| 1577 | const result = await queryWithModel({ |
| 1578 | systemPrompt: asSystemPrompt([]), |
| 1579 | userPrompt: section.prompt + '\n\nDATA:\n' + dataContext, |
| 1580 | signal: new AbortController().signal, |
| 1581 | options: { |
| 1582 | model: getInsightsModel(), |
| 1583 | querySource: 'insights', |
| 1584 | agents: [], |
| 1585 | isNonInteractiveSession: true, |
| 1586 | hasAppendSystemPrompt: false, |
| 1587 | mcpTools: [], |
| 1588 | maxOutputTokensOverride: section.maxTokens, |
| 1589 | }, |
| 1590 | }) |
| 1591 | |
| 1592 | const text = extractTextContent(result.message.content) |
| 1593 | |
| 1594 | if (text) { |
| 1595 | // Parse JSON from response |
| 1596 | const jsonMatch = text.match(/\{[\s\S]*\}/) |
| 1597 | if (jsonMatch) { |
| 1598 | try { |
| 1599 | return { name: section.name, result: jsonParse(jsonMatch[0]) } |
| 1600 | } catch { |
| 1601 | return { name: section.name, result: null } |
| 1602 | } |
| 1603 | } |
| 1604 | } |
| 1605 | return { name: section.name, result: null } |
| 1606 | } catch (err) { |
| 1607 | logError(new Error(`${section.name} failed: ${toError(err).message}`)) |
| 1608 | return { name: section.name, result: null } |
| 1609 | } |
| 1610 | } |
| 1611 | |
| 1612 | async function generateParallelInsights( |
| 1613 | data: AggregatedData, |
no test coverage detected