MCPcopy Create free account
hub / github.com/Noumena-Network/code / generateSectionInsight

Function generateSectionInsight

src/commands/insights.ts:1578–1616  ·  view source on GitHub ↗
(
  section: InsightSection,
  dataContext: string,
)

Source from the content-addressed store, hash-verified

1576}
1577
1578async 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
1618async function generateParallelInsights(
1619 data: AggregatedData,

Callers 1

generateParallelInsightsFunction · 0.85

Calls 7

queryWithModelFunction · 0.85
asSystemPromptFunction · 0.85
getInsightsModelFunction · 0.85
extractTextContentFunction · 0.85
jsonParseFunction · 0.85
logErrorFunction · 0.50
toErrorFunction · 0.50

Tested by

no test coverage detected