Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

6.1 KB
Raw Blame
import { Suspense } from 'react';
import { useLocation, useParams, Navigate } from 'react-router';
import { Cpu } from 'lucide-react';
import { getSectionNavTabForPath } from '../../../server/lib/navManifest.js';
import PageHeader from '../components/PageHeader';
import PageSkeleton from '../components/ui/PageSkeleton';
import ModelsTabsHeader, { ModelsSectionLayout, TABS } from '../components/models/ModelsTabsHeader';
import { NAV_PRESENTATION } from '../lib/navPresentation.js';
import Image3dRuntimes from '../components/models/Image3dRuntimes';
import ModelStatusTab from '../components/models/ModelStatusTab';
import SubscriptionsTab from '../components/models/SubscriptionsTab';
import CodeReviewersTab from '../components/settings/CodeReviewersTab';
import EmbeddingsTab from '../components/settings/EmbeddingsTab';
import LocalModelAssessments from '../components/settings/LocalModelAssessments.jsx';
import { LocalLlmTab } from '../components/settings/LocalLlmTab';
import LocalLlmRuntimesView from '../components/settings/LocalLlmRuntimesView.jsx';
import { lazyWithReload } from '../utils/lazyWithReload';

// The media-model panels moved in from the Media Gen tabs were each their own route
// chunk before the move (#4728) — keep them split, or landing on Performance
// downloads the whole LoRA manager and HF-cache browser to render an
// assessments table. The small always-on tabs above stay static.
const Loras = lazyWithReload(() => import('./Loras'));
const MediaModels = lazyWithReload(() => import('./MediaModels'));

/**
 * Models — the top-level home for everything about the models this machine runs.
 *
 * The section started as three tabs carved out of `/settings/local-llm`, and now
 * covers every KIND of model an install manages (#4728), not just text:
 *
 *   - **3D** — image-to-3D runtime install/repair (TRELLIS.2, Pixal3D).
 *   - **Code Reviewers** — the review-loop chain and its model/effort pins.
 *   - **Decision Classifiers** — Jev integrations and local Laya-MLX experiments.
 *   - **Embeddings** — the embedding model backing pgvector search.
 *   - **LLMs** — the model-library and abuse-guard sub-routes (the weights).
 *   - **Runtimes** — the local model servers, their lifecycle and downloads.
 *   - **LoRAs** — installed image/video adapters.
 *   - **Media** — image/video checkpoints and the Hugging Face cache.
 *   - **Performance** — measured assessments and launch-tuning comparison.
 *   - **Providers** — configured AI provider connections and model catalogs.
 *   - **Status** — residency plus the downloaded-model inventory.
 *   - **Subscriptions** — which paid plans are on, their tier, price and spend.
 *   - **Usage** — provider quota and PortOS AI usage accounting.
 *
 * What deliberately stayed OUT is output rather than weights: Three.js Models is
 * a gallery of generated meshes, and `/3d` is the render flow that consumes the
 * runtimes listed here. Audio models stayed in the Music studio too — their
 * picker is not separable from the generate form. Design record:
 * `docs/plans/2026-08-21-models-navigation.md`.
 *
 * `?tab` is a route param, not local state, so every one is deep-linkable and
 * reachable from ⌘K and voice (`client/src/AGENTS.md`).
 */
const TAB_CONTENT = {
  comparison: lazyWithReload(() => import('../components/models/ModelComparison')),
  '3d': Image3dRuntimes,
  'code-reviewers': CodeReviewersTab,
  'decision-classifiers': lazyWithReload(() => import('../components/models/DecisionClassifiers')),
  embeddings: EmbeddingsTab,
  fallbacks: lazyWithReload(() => import('../components/models/ProviderFallbacks')),
  llms: LocalLlmTab,
  'llms-runtimes': LocalLlmRuntimesView,
  loras: Loras,
  media: MediaModels,
  performance: LocalModelAssessments,
  status: ModelStatusTab,
  subscriptions: SubscriptionsTab,
};

export default function Models({ fixedTab, fixedRecordId } = {}) {
  const params = useParams();
  const { pathname } = useLocation();
  const tab = fixedTab || params.tab;
  const recordId = fixedRecordId || params.recordId;
  const taskView = params.taskView || params.view || (fixedTab === 'performance' && params.assessmentKey ? 'results' : undefined);
  if (tab === 'training') return <Navigate to="/settings/data-maintenance" replace />;
  if (tab === 'llms' && recordId === 'jev') return <Navigate to={`/models/decision-classifiers/jev${taskView ? '/' + taskView : ''}`} replace />;
  // An unknown slug lands on LLMs rather than rendering a blank page, matching
  // the section's default destination in App and the primary navigation.
  //
  // OWN-property lookup, not plain indexing: the slug comes straight off the URL,
  // so `/models/constructor` (or `toString`, `__proto__`) would otherwise resolve
  // to an Object.prototype member, read as a valid tab, and get rendered as a
  // component. Same reason `unavailableReasonLabel` guards its map.
  const activeTab = tab && Object.hasOwn(TAB_CONTENT, tab) ? tab : null;
  if (!activeTab) return <Navigate to="/models/llms" replace />;

  const TabContent = TAB_CONTENT[activeTab];
  // The shell names the destination you are on (Code Reviewers, Performance),
  // matching the section navigator. "Models" stays the area, not the page title.
  // A task view under that destination keeps the destination name; the page's
  // own task row names the view.
  const destination = getSectionNavTabForPath('Models', pathname)
    || TABS.find((item) => item.id === activeTab);
  const DestinationIcon = NAV_PRESENTATION[destination?.to]?.icon || Cpu;

  return (
    <ModelsSectionLayout activeTab={activeTab}>
      <PageHeader icon={DestinationIcon} title={destination?.label || 'Models'} />

      <ModelsTabsHeader activeTab={activeTab} />

      <div className="flex-1 min-w-0 overflow-auto p-4">
        {/* Local boundary rather than the App-level one: a lazy tab must not blank
            the section header and tab bar while its chunk loads. */}
        <Suspense fallback={<PageSkeleton header="none" label="Loading models section" cards={3} sidebar={false} />}>
          <TabContent view={recordId} taskView={taskView} assessmentKey={params.assessmentKey} />
        </Suspense>
      </div>
    </ModelsSectionLayout>
  );
}