Files
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

183 lines
5.9 KiB
TypeScript

import { MakeLogicType, actions, afterMount, beforeUnmount, connect, kea, listeners, path, reducers } from 'kea'
import { loaders } from 'kea-loaders'
import { router } from 'kea-router'
import { toast } from '@hanzo/elements'
import { projectLogic } from 'scenes/projectLogic'
import { urls } from 'scenes/urls'
import { streamlitAppsCreate, streamlitAppsDestroy, streamlitAppsList } from './generated/api'
import type { AppContractApi, AppSummaryContractApi } from './generated/api.schemas'
const LIST_POLL_INTERVAL_MS = 10_000
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface streamlitAppsLogicValues {
currentProjectId: number | null // projectLogic
streamlitApps: AppSummaryContractApi[]
streamlitAppsLoading: boolean
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface streamlitAppsLogicActions {
createStreamlitApp: ({ name, description }: { description?: string; name: string }) => {
name: string
description?: string
}
createStreamlitAppFailure: (
error: string,
errorObject?: any
) => {
error: string
errorObject?: any
}
createStreamlitAppSuccess: (
streamlitApps: AppSummaryContractApi[],
payload?: {
name: string
description?: string
}
) => {
streamlitApps: AppSummaryContractApi[]
payload?: {
name: string
description?: string
}
}
deleteStreamlitApp: ({ shortId }: { shortId: string }) => {
shortId: string
}
deleteStreamlitAppFailure: (
error: string,
errorObject?: any
) => {
error: string
errorObject?: any
}
deleteStreamlitAppSuccess: (
streamlitApps: AppSummaryContractApi[],
payload?: {
shortId: string
}
) => {
streamlitApps: AppSummaryContractApi[]
payload?: {
shortId: string
}
}
loadStreamlitApps: () => any
loadStreamlitAppsFailure: (
error: string,
errorObject?: any
) => {
error: string
errorObject?: any
}
loadStreamlitAppsSuccess: (
streamlitApps: AppSummaryContractApi[],
payload?: any
) => {
streamlitApps: AppSummaryContractApi[]
payload?: any
}
startListPolling: () => {
value: true
}
stopListPolling: () => {
value: true
}
updateStreamlitApp: (app: AppContractApi | AppSummaryContractApi) => {
app: AppContractApi | AppSummaryContractApi
}
}
export type streamlitAppsLogicType = MakeLogicType<streamlitAppsLogicValues, streamlitAppsLogicActions>
export const streamlitAppsLogic = kea<streamlitAppsLogicType>([
path(['products', 'streamlit_apps', 'frontend', 'streamlitAppsLogic']),
connect(() => ({
values: [projectLogic, ['currentProjectId']],
})),
actions({
updateStreamlitApp: (app: AppContractApi | AppSummaryContractApi) => ({ app }),
startListPolling: true,
stopListPolling: true,
}),
loaders(({ values }) => ({
streamlitApps: [
[] as AppSummaryContractApi[],
{
loadStreamlitApps: async () => {
const response = await streamlitAppsList(String(values.currentProjectId))
return response.results
},
createStreamlitApp: async ({ name, description }: { name: string; description?: string }) => {
const newApp = await streamlitAppsCreate(String(values.currentProjectId), { name, description })
toast.success('App created')
router.actions.push(urls.streamlitAppEdit(newApp.short_id))
return [...values.streamlitApps, newApp]
},
deleteStreamlitApp: async ({ shortId }: { shortId: string }) => {
await streamlitAppsDestroy(String(values.currentProjectId), shortId)
toast.success('App deleted')
return values.streamlitApps.filter((a) => a.short_id !== shortId)
},
},
],
})),
reducers({
streamlitApps: {
updateStreamlitApp: (state, { app }) =>
state.map((a) => (a.short_id === app.short_id ? { ...a, ...app } : a)),
},
}),
listeners(({ actions, cache }) => ({
startListPolling: () => {
// Idempotent — timers stack otherwise on re-fire.
if (cache.listPollTimer) {
clearInterval(cache.listPollTimer)
}
cache.listPollTimer = setInterval(() => {
if (typeof document !== 'undefined' && document.visibilityState === 'hidden') {
return
}
actions.loadStreamlitApps()
}, LIST_POLL_INTERVAL_MS)
},
stopListPolling: () => {
if (cache.listPollTimer) {
clearInterval(cache.listPollTimer)
cache.listPollTimer = null
}
},
})),
afterMount(({ actions, cache }) => {
actions.loadStreamlitApps()
actions.startListPolling()
// Refetch on tab focus so returning users don't sit on stale state for a poll interval.
if (typeof document !== 'undefined') {
cache.visibilityHandler = (): void => {
if (document.visibilityState === 'visible') {
actions.loadStreamlitApps()
}
}
document.addEventListener('visibilitychange', cache.visibilityHandler)
}
}),
beforeUnmount(({ actions, cache }) => {
actions.stopListPolling()
if (typeof document !== 'undefined' && cache.visibilityHandler) {
document.removeEventListener('visibilitychange', cache.visibilityHandler)
cache.visibilityHandler = null
}
}),
])