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.

3.5 KB
Raw Blame
"use client";

import { useEffect, useRef, useState } from "react";
import { Button } from "@/components/ui/button";
import { syncIntegrationFrameTokens } from "./frame-theme";
import { ComposioSessionPanel } from "./composio-session-panel";

/** Preserve transfer/setup deep links without putting private capabilities in React state. */
export function managerLocation(search: string, hash = "") {
  const transfer = new URLSearchParams(search).get("transfer") === "1";
  return "/integrations/manager" + (transfer ? "?transfer=1" : "") + hash;
}

export default function IntegrationsApp() {
  const frame = useRef<HTMLIFrameElement>(null);
  const [status, setStatus] = useState<"loading" | "ready" | "error">("loading");
  const [retry, setRetry] = useState(0);
  const [owner, setOwner] = useState<string | null>(null);
  useEffect(() => {
    const target = frame.current;
    if (!target) return;
    const onReady = (event: MessageEvent) => {
      if (event.source !== target.contentWindow || event.origin !== window.location.origin) return;
      if (event.data?.type === "mso:integrations-selection") {
        setOwner(typeof event.data.user === "string" ? event.data.user : null);
        return;
      }
      if (event.data?.type !== "mso:integrations-ready") return;
      syncIntegrationFrameTokens(target);
      setStatus("ready");
    };
    window.addEventListener("message", onReady);
    target.src = managerLocation(window.location.search, window.location.hash);
    if (window.location.hash) window.history.replaceState(window.history.state, "", window.location.pathname + window.location.search);
    const timer = window.setTimeout(() => setStatus(current => current === "loading" ? "error" : current), 15000);
    let animation = 0;
    const sync = () => {
      window.cancelAnimationFrame(animation);
      animation = window.requestAnimationFrame(() => syncIntegrationFrameTokens(target));
    };
    const observer = new MutationObserver(sync);
    observer.observe(document.documentElement, { attributes: true, attributeFilter: ["class", "style", "data-theme", "data-shell"] });
    observer.observe(document.head, { childList: true, subtree: true, characterData: true });
    const scheme = window.matchMedia("(prefers-color-scheme: dark)");
    scheme.addEventListener("change", sync);
    sync();
    return () => {
      window.removeEventListener("message", onReady);
      window.clearTimeout(timer);
      window.cancelAnimationFrame(animation);
      observer.disconnect();
      scheme.removeEventListener("change", sync);
    };
  }, [retry]);
  return (
    <section className="flex h-full min-h-0 flex-col bg-background" aria-label="Integrations">
      {status !== "ready" && <div className="flex items-center justify-between gap-3 border-b p-3">
        <p role={status === "error" ? "alert" : "status"} className="text-sm text-muted-foreground">
          {status === "error" ? "The connection manager did not finish loading." : "Opening the native connection manager…"}
        </p>
        {status === "error" && <Button variant="secondary" onClick={() => { setStatus("loading"); setRetry(n => n + 1); }}>Retry</Button>}
      </div>}
      <ComposioSessionPanel key={owner ?? "none"} owner={owner} />
      <iframe ref={frame} title="MSO native Integrations manager" className="min-h-0 w-full flex-1 border-0"
        referrerPolicy="no-referrer" onLoad={() => { if (frame.current?.contentDocument?.querySelector(".integration.manager")) { syncIntegrationFrameTokens(frame.current); setStatus("ready"); } }}
        onError={() => setStatus("error")} />
    </section>
  );
}