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.

3.5 KB
Raw Blame
/**
 * "Runs on" — where an agent's work executes: this computer, or one of the
 * machines connected in the Computers section (a VPS, a local VM). The value
 * is a computer id; "" means this computer. Shared by the create dialog and
 * the agent's spec sheet so the two can never offer different choices.
 */
import { Monitor, Server } from "lucide-react";
import { Combobox } from "@/components/ui/combobox";
import { useComputers } from "@/hooks/useComputers";
import { useT } from "@/i18n";
import { cn } from "@/lib/utils";
import { useEventStore } from "@/store/events";
import type { Computer } from "@/lib/computersApi";

function Dot({ computer }: { computer: Computer }) {
  const status = computer.health.status;
  return (
    <span className="relative inline-flex h-4 w-4 items-center justify-center" aria-hidden>
      <Server className="h-3.5 w-3.5 text-muted-foreground" />
      <span
        className={cn(
          "absolute -bottom-0.5 -right-0.5 h-1.5 w-1.5 rounded-full",
          status === "online" ? "bg-success" : status === "unknown" ? "bg-foreground-faint" : "bg-warning",
        )}
      />
    </span>
  );
}

export function ComputerPicker({
  value,
  onChange,
  labelClass,
  layout = "field",
  testId = "society-computer-picker",
}: {
  value: string;
  onChange: (computerId: string) => void;
  labelClass?: string;
  /** "row": a pane card line, label left and a quiet picker right, the hint below. */
  layout?: "field" | "row";
  testId?: string;
}) {
  const t = useT();
  const computers = useComputers();
  const setActiveSection = useEventStore((s) => s.setActiveSection);
  // A switched-off computer is not offered, unless it is the one already chosen.
  const rows = (computers.data ?? []).filter((c) => c.enabled !== false || c.id === value);
  const chosen = rows.find((c) => c.id === value);

  const row = layout === "row";
  return (
    <div data-testid={testId}>
      <div className={row ? "ap-line" : undefined}>
      <span className={row ? "ap-line-label" : labelClass}>{t("society.create.runs_on")}</span>
      <span className={row ? "ml-auto min-w-0 shrink-0" : undefined}>
      <Combobox
        value={value}
        groups={[
          {
            id: "computers",
            options: [
              {
                value: "",
                label: t("society.create.runs_on_here"),
                icon: <Monitor className="h-3.5 w-3.5 text-muted-foreground" />,
              },
              ...rows.map((c) => ({
                value: c.id,
                label: c.name,
                hint: `${c.username}@${c.host}`,
                icon: <Dot computer={c} />,
              })),
            ],
          },
        ]}
        onChange={onChange}
        ariaLabel={t("society.create.runs_on")}
        className={row ? "ap-pick" : undefined}
        triggerIcon={!row}
        triggerHint={!row}
      />
      </span>
      </div>
      <p className={row ? "ap-hint ap-line-hint" : "mt-1 text-xs text-muted-foreground"}>
        {chosen
          ? chosen.health.status === "online"
            ? t("society.create.runs_on_remote_hint")
            : t("society.create.runs_on_offline_hint")
          : t("society.create.runs_on_here_hint")}{" "}
        {rows.length === 0 && (
          <button
            type="button"
            onClick={() => setActiveSection("computers")}
            className="text-accent underline-offset-4 hover:underline"
          >
            {t("society.create.runs_on_connect")}
          </button>
        )}
      </p>
    </div>
  );
}