import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query" import { createFileRoute } from "@tanstack/react-router" import { Package } from "lucide-react" import { useState } from "react" import { type ApiError, ModulesService } from "@/client" import { InfoTip } from "@/components/Flow/SidePanel" import { Button } from "@/components/ui/button" import useAuth from "@/hooks/useAuth" import useCustomToast from "@/hooks/useCustomToast" import { handleError } from "@/utils" export const Route = createFileRoute("/_layout/modules")({ component: Modules, head: () => ({ meta: [ { title: "Modules - Fluksio", }, ], }), }) const modulesKey = ["modules"] const SECTION = "text-xs font-medium uppercase tracking-[0.5px] text-muted-foreground" function Modules() { const { data } = useQuery({ queryKey: modulesKey, queryFn: () => ModulesService.readModules(), }) const queryClient = useQueryClient() const { showSuccessToast, showErrorToast } = useCustomToast() // A package runs its own code on install, so installing is a superuser's. const { user } = useAuth() const mayInstall = Boolean(user?.is_superuser) // Null until the field is touched, so what is stored shows through until // someone actually starts editing it. const [draft, setDraft] = useState(null) const [output, setOutput] = useState("") const apply = useMutation({ mutationFn: (requirements: string) => ModulesService.applyModules({ requestBody: { requirements } }), onSuccess: (result) => { showSuccessToast("Modules installed") setOutput(result.output ?? "") setDraft(null) queryClient.invalidateQueries({ queryKey: modulesKey }) }, onError: (error: ApiError) => { // The 400 detail is uv's own output — several lines of resolver // reasoning, which belongs in the pane rather than in a toast. const detail = (error.body as { detail?: string } | undefined)?.detail if (detail) { setOutput(detail) showErrorToast("Those requirements could not be installed") } else { handleError.call(showErrorToast, error) } }, }) const stored = data?.requirements ?? "" const requirements = draft ?? stored const packages = data?.packages ?? [] const dirty = requirements !== stored // Fluksio was installed into an environment somebody else made, and node // code runs on it. Installing from here would mean `uv pip sync`, which // holds a venv to exactly one list — and would uninstall their work. const adopted = data?.adopted ?? false return (

Modules

{adopted ? "Fluksio was installed into an environment you already had, so that is the one your nodes run on. Change it with pip or uv rather than from here." : "Packages install into an environment of their own, separate from the engine's, so a version pinned here is the one your code gets. The list is kept with your flows, so a rebuilt deployment installs the same set again."}

The Python packages your function nodes can import.

{adopted ? null : !mayInstall ? (

Only a superuser can install packages.

) : (

Requirements