Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

2.9 KB
Raw Blame
import { Component, Suspense, lazy, type ErrorInfo, type ReactNode } from "react";
import { AlertTriangle, RotateCcw } from "lucide-react";
import { translate, useLocaleChunk } from "@/i18n";
import { useIdeSidePanelStore } from "@/store/ideSidePanel";
import { VerseLoadingScreen } from "@/components/society/verse/VerseLoadingScreen";
import { VerseHostMount } from "@/components/verseHost/VerseHostMount";

// The ship is a WebGL scene with its own chunk: nothing of it loads until
// someone opens this tab.
const VerseStage = lazy(() => import("@/components/society/verse/VerseStage").then((m) => ({ default: m.VerseStage })));

/** Keeps a failed scene inside the tab instead of taking the IDE down with it. */
class OfficeTabBoundary extends Component<{ children: ReactNode }, { failed: boolean }> {
  state = { failed: false };

  static getDerivedStateFromError(): { failed: boolean } {
    return { failed: true };
  }

  componentDidCatch(error: unknown, info: ErrorInfo) {
    console.error("IDE office tab crashed", { error, componentStack: info.componentStack });
  }

  render() {
    if (!this.state.failed) return this.props.children;
    return (
      <div data-testid="ide-office-tab-failed" className="flex h-full min-h-0 flex-col items-center justify-center gap-3 p-6 text-center">
        <AlertTriangle className="h-5 w-5 text-destructive" aria-hidden />
        <p className="text-sm text-muted-foreground">{translate("ide_side_panel.office.failed")}</p>
        <button
          type="button"
          onClick={() => this.setState({ failed: false })}
          className="inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1 text-sm text-foreground hover:bg-secondary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
        >
          <RotateCcw className="h-3.5 w-3.5" aria-hidden />
          {translate("ide_side_panel.office.retry")}
        </button>
      </div>
    );
  }
}

/**
 * The ship's engineering deck, inside the IDE's side panel.
 *
 * Every running coding-agent pane is a technician at a terminal here; its
 * record opens that pane in the grid next to it. The ship's "open the crew
 * list" action has no list in the IDE, so it brings the Agents tab forward.
 */
export function OfficeTab() {
  const ready = useLocaleChunk("society");
  const openTab = useIdeSidePanelStore((state) => state.openTab);
  return (
    <div data-testid="ide-office-tab" className="relative h-full min-h-0 w-full">
      <OfficeTabBoundary>
        {ready && (
          <Suspense fallback={<div className="relative h-full w-full"><VerseLoadingScreen /></div>}>
            <VerseStage initialDeck="engineering" compact onOpenLedger={() => openTab("agents")} />
          </Suspense>
        )}
      </OfficeTabBoundary>
      {/* The Unreal Verse launcher (WP17), behind verse.unreal_preview until the deletion PR. */}
      <VerseHostMount />
    </div>
  );
}