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