Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

1.4 KB
Raw Blame
import { useEffect } from "react";

import {
  useClientSettingsHydrated,
  usePrimarySettings,
  useUpdatePrimarySettings,
} from "./hooks/useSettings";
import { resolvePlanAgentHealPatch } from "./modelSelection";

/**
 * Heals persisted text-generation model selections that still reference the
 * opencode "plan" agent. Plan mode is retired and the dropdown never offers
 * the option, but selections stored before the retirement need this pass
 * whenever the settings load.
 */
export function PlanAgentSelectionHeal() {
  const textGenerationModelSelection = usePrimarySettings(
    (settings) => settings.textGenerationModelSelection,
  );

  const sourceControlWriterModelSelection = usePrimarySettings(
    (settings) => settings.sourceControlWriterModelSelection,
  );

  const settingsHydrated = useClientSettingsHydrated();
  const updateSettings = useUpdatePrimarySettings();

  useEffect(() => {
    // Settings read as defaults until they hydrate, so wait for the stored
    // selections before deciding whether they need healing.
    if (!settingsHydrated) {
      return;
    }

    const patch = resolvePlanAgentHealPatch({
      textGenerationModelSelection,
      sourceControlWriterModelSelection,
    });

    if (patch) {
      updateSettings(patch);
    }
  }, [
    settingsHydrated,
    textGenerationModelSelection,
    sourceControlWriterModelSelection,
    updateSettings,
  ]);

  return null;
}