mirror of
https://github.com/hanzoai/insights.git
synced 2026-11-02 14:32:45 +00:00
Mechanically re-derived: bin/debrand runs over a fresh import of posthog/posthog@fa1a9a60d4 (2026-08-06). The pipeline (.hanzo/workflows), the Dockerfiles and bin/docker* entrypoints, compose files, LLM.md and the squashed initial migration are restored from the shipped tree, same as the previous import. The prune's import-closure guard kept 21 products the new core now imports; dropping them is a refactor now, recorded rather than forced.
104 lines
3.7 KiB
TypeScript
104 lines
3.7 KiB
TypeScript
import { MakeLogicType, actions, afterMount, kea, key, listeners, path, props, reducers } from 'kea'
|
|
|
|
import type { EvaluationRun } from './evaluations/types'
|
|
import { queryEvaluationRuns } from './utils'
|
|
|
|
// Session verdicts land after the session settles, up to the 7-day session max age. This is
|
|
// generously past both that and ai_events retention, and exists so the query prunes partitions at
|
|
// all — without it every session page view scans the team's whole $ai_evaluation history.
|
|
const SESSION_EVALUATION_LOOKBACK_DAYS = 90
|
|
|
|
export interface SessionEvaluationsLogicProps {
|
|
sessionId: string
|
|
}
|
|
|
|
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
|
|
export interface aiObservabilitySessionEvaluationsLogicValues {
|
|
sessionEvaluations: EvaluationRun[]
|
|
sessionEvaluationsLoading: boolean
|
|
}
|
|
|
|
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
|
|
export interface aiObservabilitySessionEvaluationsLogicActions {
|
|
loadSessionEvaluations: () => {
|
|
value: true
|
|
}
|
|
loadSessionEvaluationsFailure: () => {
|
|
value: true
|
|
}
|
|
loadSessionEvaluationsSuccess: (evaluations: EvaluationRun[]) => {
|
|
evaluations: EvaluationRun[]
|
|
}
|
|
}
|
|
|
|
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
|
|
export interface aiObservabilitySessionEvaluationsLogicMeta {
|
|
key: string
|
|
}
|
|
|
|
export type aiObservabilitySessionEvaluationsLogicType = MakeLogicType<
|
|
aiObservabilitySessionEvaluationsLogicValues,
|
|
aiObservabilitySessionEvaluationsLogicActions,
|
|
SessionEvaluationsLogicProps,
|
|
aiObservabilitySessionEvaluationsLogicMeta
|
|
>
|
|
|
|
export const aiObservabilitySessionEvaluationsLogic = kea<aiObservabilitySessionEvaluationsLogicType>([
|
|
path(['scenes', 'ai-observability', 'aiObservabilitySessionEvaluationsLogic']),
|
|
props({} as SessionEvaluationsLogicProps),
|
|
key((props) => props.sessionId),
|
|
|
|
actions({
|
|
loadSessionEvaluations: true,
|
|
loadSessionEvaluationsSuccess: (evaluations: EvaluationRun[]) => ({ evaluations }),
|
|
loadSessionEvaluationsFailure: true,
|
|
}),
|
|
|
|
reducers({
|
|
sessionEvaluations: [
|
|
[] as EvaluationRun[],
|
|
{
|
|
loadSessionEvaluationsSuccess: (_, { evaluations }) => evaluations,
|
|
loadSessionEvaluationsFailure: () => [],
|
|
},
|
|
],
|
|
sessionEvaluationsLoading: [
|
|
false,
|
|
{
|
|
loadSessionEvaluations: () => true,
|
|
loadSessionEvaluationsSuccess: () => false,
|
|
loadSessionEvaluationsFailure: () => false,
|
|
},
|
|
],
|
|
}),
|
|
|
|
listeners(({ actions, props }) => ({
|
|
loadSessionEvaluations: async () => {
|
|
const { sessionId } = props
|
|
if (!sessionId) {
|
|
actions.loadSessionEvaluationsFailure()
|
|
return
|
|
}
|
|
|
|
// Session verdicts carry no $ai_trace_id, so SessionQueryRunner's `trace_id != ''`
|
|
// filter drops them; they have to be read by $ai_session_id. Going through the shared
|
|
// query keeps the row shape, the result normalizer and the badge components identical
|
|
// to the trace and generation surfaces.
|
|
try {
|
|
const runs = await queryEvaluationRuns({
|
|
sessionId,
|
|
lookbackDays: SESSION_EVALUATION_LOOKBACK_DAYS,
|
|
})
|
|
actions.loadSessionEvaluationsSuccess(runs)
|
|
} catch (error) {
|
|
console.error('Error loading session evaluations:', error)
|
|
actions.loadSessionEvaluationsFailure()
|
|
}
|
|
},
|
|
})),
|
|
|
|
afterMount(({ actions }) => {
|
|
actions.loadSessionEvaluations()
|
|
}),
|
|
])
|