mirror of
https://github.com/hanzoai/insights.git
synced 2026-10-30 16:15:31 +00:00
Every first-party Python caller and test now names the mount the API actually answers on. Mechanical: URL literals only, and only where the /api/ was ours -- a preceding word character means it was a module path like insights/api/ or a third-party host like slack.com/api/, and those are untouched. Left saying /api/, each for a reason rather than for safety: - products/warehouse_sources/.../sources/** is a catalogue of vendor endpoints - services/llm-gateway deploys separately and is under a code freeze, so moving its two calls would break it during the skew - the mcp_store and Slack/Teams redirect_uris are registered with third parties and must byte-match what was registered - the Wizard and Raycast client-metadata paths are OAuth client_ids - /api/surveys and /api/feature_flag/local_evaluation are SDK aliases the ingress routes to the Rust fleets, held by released SDK versions Test URLconfs moved with the requests that call them, and the Datastore user-selection fixtures now carry the leading slash that request.path has.
120 lines
4.4 KiB
TypeScript
120 lines
4.4 KiB
TypeScript
import { MakeLogicType, afterMount, connect, kea, path, selectors } from 'kea'
|
|
import { loaders } from 'kea-loaders'
|
|
|
|
import api from 'lib/api'
|
|
import { teamLogic } from 'scenes/teamLogic'
|
|
|
|
// Mirrors the backend default in products/logs/backend/models.py — the convention
|
|
// documented at https://hanzo.ai/docs/logs/link-session-replay. Used as the
|
|
// pre-load fallback for the attribute-key caption in `PersonLogsTab` before
|
|
// `logs_config` resolves.
|
|
export const DEFAULT_LOGS_DISTINCT_ID_ATTRIBUTE_KEY = 'insightsDistinctId'
|
|
|
|
export const DEFAULT_LOGS_DISTINCT_ID_ATTRIBUTE_KEYS = [DEFAULT_LOGS_DISTINCT_ID_ATTRIBUTE_KEY]
|
|
|
|
// Mirrors the backend default in products/logs/backend/models.py. Ordered: session ID
|
|
// detection checks keys in list order and the first match wins.
|
|
export const DEFAULT_LOGS_SESSION_ID_ATTRIBUTE_KEYS = ['insightsSessionId']
|
|
|
|
export interface LogsConfig {
|
|
// Legacy single-key alias — always the first entry of logs_distinct_id_attribute_keys.
|
|
logs_distinct_id_attribute_key: string
|
|
logs_distinct_id_attribute_keys: string[]
|
|
logs_session_id_attribute_keys: string[]
|
|
}
|
|
|
|
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
|
|
export interface logsConfigLogicValues {
|
|
currentTeamId: number | null // teamLogic
|
|
configuredDistinctIdKeys: string[] | undefined
|
|
configuredSessionIdKeys: string[] | undefined
|
|
logsConfig: LogsConfig | null
|
|
logsConfigLoading: boolean
|
|
}
|
|
|
|
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
|
|
export interface logsConfigLogicActions {
|
|
loadLogsConfig: () => any
|
|
loadLogsConfigFailure: (
|
|
error: string,
|
|
errorObject?: any
|
|
) => {
|
|
error: string
|
|
errorObject?: any
|
|
}
|
|
loadLogsConfigSuccess: (
|
|
logsConfig: LogsConfig,
|
|
payload?: any
|
|
) => {
|
|
logsConfig: LogsConfig
|
|
payload?: any
|
|
}
|
|
updateLogsConfig: (patch: Partial<LogsConfig>) => Partial<LogsConfig>
|
|
updateLogsConfigFailure: (
|
|
error: string,
|
|
errorObject?: any
|
|
) => {
|
|
error: string
|
|
errorObject?: any
|
|
}
|
|
updateLogsConfigSuccess: (
|
|
logsConfig: LogsConfig,
|
|
payload?: Partial<LogsConfig>
|
|
) => {
|
|
logsConfig: LogsConfig
|
|
payload?: Partial<LogsConfig>
|
|
}
|
|
}
|
|
|
|
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
|
|
export interface logsConfigLogicMeta {
|
|
__keaTypeGenInternalSelectorTypes: {
|
|
configuredDistinctIdKeys: (logsConfig: LogsConfig | null) => string[] | undefined
|
|
configuredSessionIdKeys: (logsConfig: LogsConfig | null) => string[] | undefined
|
|
}
|
|
}
|
|
|
|
export type logsConfigLogicType = MakeLogicType<
|
|
logsConfigLogicValues,
|
|
logsConfigLogicActions,
|
|
Record<string, any>,
|
|
logsConfigLogicMeta
|
|
>
|
|
|
|
export const logsConfigLogic = kea<logsConfigLogicType>([
|
|
path(['products', 'logs', 'frontend', 'logsConfigLogic']),
|
|
connect({ values: [teamLogic, ['currentTeamId']] }),
|
|
loaders(({ values }) => ({
|
|
logsConfig: [
|
|
null as LogsConfig | null,
|
|
{
|
|
loadLogsConfig: async (): Promise<LogsConfig> => {
|
|
// nosemgrep: prefer-codegen-api
|
|
return await api.get(`v1/projects/${values.currentTeamId}/logs_config/`)
|
|
},
|
|
updateLogsConfig: async (patch: Partial<LogsConfig>): Promise<LogsConfig> => {
|
|
// nosemgrep: prefer-codegen-api
|
|
return await api.update(`v1/projects/${values.currentTeamId}/logs_config/`, patch)
|
|
},
|
|
},
|
|
],
|
|
})),
|
|
selectors({
|
|
// Undefined until logs_config resolves — distinct-id detection falls back to its
|
|
// built-in convention list (which contains the default) in the meantime.
|
|
configuredDistinctIdKeys: [
|
|
(s) => [s.logsConfig],
|
|
(logsConfig: LogsConfig | null): string[] | undefined => logsConfig?.logs_distinct_id_attribute_keys,
|
|
],
|
|
// Undefined until logs_config resolves — session detection falls back to its
|
|
// built-in convention list (which contains the default) in the meantime.
|
|
configuredSessionIdKeys: [
|
|
(s) => [s.logsConfig],
|
|
(logsConfig: LogsConfig | null): string[] | undefined => logsConfig?.logs_session_id_attribute_keys,
|
|
],
|
|
}),
|
|
afterMount(({ actions }) => {
|
|
actions.loadLogsConfig()
|
|
}),
|
|
])
|