Files
insights/products/ai_observability/frontend/aiObservabilitySessionFeedbackLogic.ts
zeekay 1b367e2b62 chore: rebase the tree onto upstream master
The tree was a debranded snapshot of upstream taken around 2026-02-20, and
upstream has moved about five months since. This replaces it with upstream
master, mechanically re-derived: bin/debrand does the rename, and the
pipeline and squashed migrations are restored from the shipped tree.

Not a merge. The previous import replaced the tree wholesale in a single
commit, so there is no shared content history to merge against. Reproducing
the rename on the new tree is what actually converges.

What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints,
compose files, LLM.md, and insights/migrations. The squashed initial
migration is load-bearing — the live database records it by name, so
upstream's ~918 individual migrations cannot come back.

Nine products are dropped as unreferenced. Twenty-one more that we do not run
are kept anyway because the core app still imports them; unpicking those is a
refactor and does not belong in a rebase.

This base does not build yet, and the reasons are not in the rename:
upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against
our 4.2, and the dependency manifests still name upstream packages that we
republish under our own names. Those are decisions, not renames.
2026-08-01 15:44:40 -07:00

195 lines
6.5 KiB
TypeScript

import { MakeLogicType, actions, afterMount, kea, key, listeners, path, props, reducers } from 'kea'
import api from 'lib/api'
import { InsightsQLQuery, NodeKind } from '~/queries/schema/schema-general'
export interface SessionFeedback {
rating: string
triggerType: string
traceId: string | null
timestamp: string
}
export interface SessionSupportTicket {
ticketId: string
traceId: string | null
timestamp: string
}
export interface SessionFeedbackLogicProps {
sessionId: string
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface aiObservabilitySessionFeedbackLogicValues {
feedbackLoading: boolean
sessionFeedback: SessionFeedback[]
sessionSupportTickets: SessionSupportTicket[]
supportTicketsLoading: boolean
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface aiObservabilitySessionFeedbackLogicActions {
loadSessionFeedback: () => {
value: true
}
loadSessionFeedbackFailure: () => {
value: true
}
loadSessionFeedbackSuccess: (feedback: SessionFeedback[]) => {
feedback: SessionFeedback[]
}
loadSessionSupportTickets: () => {
value: true
}
loadSessionSupportTicketsFailure: () => {
value: true
}
loadSessionSupportTicketsSuccess: (tickets: SessionSupportTicket[]) => {
tickets: SessionSupportTicket[]
}
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface aiObservabilitySessionFeedbackLogicMeta {
key: string
}
export type aiObservabilitySessionFeedbackLogicType = MakeLogicType<
aiObservabilitySessionFeedbackLogicValues,
aiObservabilitySessionFeedbackLogicActions,
SessionFeedbackLogicProps,
aiObservabilitySessionFeedbackLogicMeta
>
export const aiObservabilitySessionFeedbackLogic = kea<aiObservabilitySessionFeedbackLogicType>([
path(['scenes', 'ai-observability', 'aiObservabilitySessionFeedbackLogic']),
props({} as SessionFeedbackLogicProps),
key((props) => props.sessionId),
actions({
loadSessionFeedback: true,
loadSessionFeedbackSuccess: (feedback: SessionFeedback[]) => ({ feedback }),
loadSessionFeedbackFailure: true,
loadSessionSupportTickets: true,
loadSessionSupportTicketsSuccess: (tickets: SessionSupportTicket[]) => ({ tickets }),
loadSessionSupportTicketsFailure: true,
}),
reducers({
sessionFeedback: [
[] as SessionFeedback[],
{
loadSessionFeedbackSuccess: (_, { feedback }) => feedback,
loadSessionFeedbackFailure: () => [],
},
],
feedbackLoading: [
false,
{
loadSessionFeedback: () => true,
loadSessionFeedbackSuccess: () => false,
loadSessionFeedbackFailure: () => false,
},
],
sessionSupportTickets: [
[] as SessionSupportTicket[],
{
loadSessionSupportTicketsSuccess: (_, { tickets }) => tickets,
loadSessionSupportTicketsFailure: () => [],
},
],
supportTicketsLoading: [
false,
{
loadSessionSupportTickets: () => true,
loadSessionSupportTicketsSuccess: () => false,
loadSessionSupportTicketsFailure: () => false,
},
],
}),
listeners(({ actions, props }) => ({
loadSessionFeedback: async () => {
const { sessionId } = props
if (!sessionId) {
actions.loadSessionFeedbackFailure()
return
}
const feedbackQuery: InsightsQLQuery = {
kind: NodeKind.InsightsQLQuery,
query: `
SELECT
properties.$ai_metric_value as rating,
properties.feedback_trigger_type as trigger_type,
properties.$ai_trace_id as trace_id,
timestamp
FROM events
WHERE event = '$ai_metric'
AND properties.$ai_metric_name = 'feedback'
AND properties.$ai_session_id = {sessionId}
ORDER BY timestamp DESC
`,
values: { sessionId },
}
try {
const response = await api.query(feedbackQuery)
const feedback: SessionFeedback[] = (response.results || []).map((row: any[]) => ({
rating: row[0] || '',
triggerType: row[1] || '',
traceId: row[2] || null,
timestamp: row[3] || '',
}))
actions.loadSessionFeedbackSuccess(feedback)
} catch (error) {
console.error('Error loading session feedback:', error)
actions.loadSessionFeedbackFailure()
}
},
loadSessionSupportTickets: async () => {
const { sessionId } = props
if (!sessionId) {
actions.loadSessionSupportTicketsFailure()
return
}
const ticketsQuery: InsightsQLQuery = {
kind: NodeKind.InsightsQLQuery,
query: `
SELECT
properties.$ai_support_ticket_id as ticket_id,
properties.$ai_trace_id as trace_id,
timestamp
FROM events
WHERE event = 'insights_ai_support_ticket_created'
AND properties.$ai_conversation_id = {sessionId}
ORDER BY timestamp DESC
`,
values: { sessionId },
}
try {
const response = await api.query(ticketsQuery)
const tickets: SessionSupportTicket[] = (response.results || []).map((row: any[]) => ({
ticketId: row[0] || '',
traceId: row[1] || null,
timestamp: row[2] || '',
}))
actions.loadSessionSupportTicketsSuccess(tickets)
} catch (error) {
console.error('Error loading session support tickets:', error)
actions.loadSessionSupportTicketsFailure()
}
},
})),
afterMount(({ actions }) => {
actions.loadSessionFeedback()
actions.loadSessionSupportTickets()
}),
])