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

Function extractFacetsFromAPI

src/commands/insights.ts:1007–1061  ·  view source on GitHub ↗
(
  log: LogOption,
  sessionId: string,
)

Source from the content-addressed store, hash-verified

1005}
1006
1007async function extractFacetsFromAPI(
1008 log: LogOption,
1009 sessionId: string,
1010): Promise<SessionFacets | null> {
1011 try {
1012 // Use summarization for long transcripts
1013 const transcript = await formatTranscriptWithSummarization(log)
1014
1015 // Build prompt asking for JSON directly (no tool use)
1016 const jsonPrompt = `${FACET_EXTRACTION_PROMPT}${transcript}
1017
1018RESPOND WITH ONLY A VALID JSON OBJECT matching this schema:
1019{
1020 "underlying_goal": "What the user fundamentally wanted to achieve",
1021 "goal_categories": {"category_name": count, ...},
1022 "outcome": "fully_achieved|mostly_achieved|partially_achieved|not_achieved|unclear_from_transcript",
1023 "user_satisfaction_counts": {"level": count, ...},
1024 "claude_helpfulness": "unhelpful|slightly_helpful|moderately_helpful|very_helpful|essential",
1025 "session_type": "single_task|multi_task|iterative_refinement|exploration|quick_question",
1026 "friction_counts": {"friction_type": count, ...},
1027 "friction_detail": "One sentence describing friction or empty",
1028 "primary_success": "none|fast_accurate_search|correct_code_edits|good_explanations|proactive_help|multi_file_changes|good_debugging",
1029 "brief_summary": "One sentence: what user wanted and whether they got it"
1030}`
1031
1032 const result = await queryWithModel({
1033 systemPrompt: asSystemPrompt([]),
1034 userPrompt: jsonPrompt,
1035 signal: new AbortController().signal,
1036 options: {
1037 model: getAnalysisModel(),
1038 querySource: 'insights',
1039 agents: [],
1040 isNonInteractiveSession: true,
1041 hasAppendSystemPrompt: false,
1042 mcpTools: [],
1043 maxOutputTokensOverride: 4096,
1044 },
1045 })
1046
1047 const text = extractTextContent(result.message.content)
1048
1049 // Parse JSON from response
1050 const jsonMatch = text.match(/\{[\s\S]*\}/)
1051 if (!jsonMatch) return null
1052
1053 const parsed: unknown = jsonParse(jsonMatch[0])
1054 if (!isValidSessionFacets(parsed)) return null
1055 const facets: SessionFacets = { ...parsed, session_id: sessionId }
1056 return facets
1057 } catch (err) {
1058 logError(new Error(`Facet extraction failed: ${toError(err).message}`))
1059 return null
1060 }
1061}
1062
1063/**
1064 * Detects multi-sessioning (using multiple NCode sessions concurrently).

Callers 1

generateUsageReportFunction · 0.85

Calls 9

queryWithModelFunction · 0.85
asSystemPromptFunction · 0.85
getAnalysisModelFunction · 0.85
extractTextContentFunction · 0.85
jsonParseFunction · 0.85
isValidSessionFacetsFunction · 0.85
logErrorFunction · 0.50
toErrorFunction · 0.50

Tested by

no test coverage detected