Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

2.8 KB
Raw Blame
"use client";

import { toast, useFeatureState } from "@/features/appshell";
import { useSettingsWindow } from "../lib/window-context";
import { Plus } from "lucide-react";
import { Button } from "@/components/ui/button";
import { SettingsBlock } from "@/features/shell-settings";
import { CustomProviderForm } from "./custom-provider-form";
import { OAuthConnect } from "./oauth-connect";
import { ProviderList, type ConnectedProvider } from "./provider-list";

// The provider-management block below the active-provider config: OAuth sign-in,
// add-a-custom-endpoint, and the connected-provider list with delete. `reload`
// re-fetches /api/config in the parent after any change.
export function ProviderManage({
  providers,
  selected,
  reload,
}: {
  providers: ConnectedProvider[];
  selected: string;
  reload: () => void;
}) {
  const { winId, setSensitiveDirty } = useSettingsWindow();
  const [showAdd, setShowAdd] = useFeatureState(winId, "provider-form-open", false);
  const [key, setKey] = useFeatureState(winId, "provider-key", "", { sensitive: true });
  const [json, setJson] = useFeatureState(winId, "provider-json", "", { sensitive: true });
  const [submitting] = useFeatureState(winId, "provider-submitting", false);
  const toggleForm = () => {
    if (showAdd && submitting) return void toast("Wait for the provider request to finish before closing the form.");
    if (showAdd && (key || json) && !window.confirm("Discard the unsaved API key or JSON?")) return;
    if (showAdd) { setKey(""); setJson(""); setSensitiveDirty(false); }
    setShowAdd(!showAdd);
  };
  return (
    <>
      <SettingsBlock>
        <OAuthConnect onConnected={reload} />
      </SettingsBlock>

      <SettingsBlock>
        <Button
          variant="ghost"
          size="sm"
          aria-expanded={showAdd}
          aria-controls="custom-provider-form"
          className="text-muted-foreground [@media(pointer:coarse)]:min-h-[44px]"
          onClick={toggleForm}
        >
          <Plus className={`size-3.5 transition-transform ${showAdd ? "rotate-45" : ""}`} />
          {showAdd ? "Close custom provider form" : "Add custom provider"}
        </Button>
        {showAdd ? (
          <div id="custom-provider-form" className="mt-2">
            <CustomProviderForm
              onAdded={() => {
                setShowAdd(false);
                reload();
              }}
            />
          </div>
        ) : (
          <p className="mt-1 text-xs text-muted-foreground">
            Any OpenAI-compatible or Anthropic-Messages endpoint: paste its base URL and key,
            then Discover to pull in the model ids it serves.
          </p>
        )}
      </SettingsBlock>

      {providers.length > 0 && (
        <SettingsBlock>
          <ProviderList providers={providers} selected={selected} onChanged={reload} />
        </SettingsBlock>
      )}
    </>
  );
}