Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

3.4 KB
Raw Blame
import { useQuery } from '@tanstack/react-query';
import { observer } from 'mobx-react-lite';
import { AgentInstructionsSection } from '@renderer/features/locations/components/main-panel/agent-instructions-section';
import { SectionLabel } from '@renderer/features/locations/components/main-panel/agent-page-section';
import { AddressingPolicySettingsSection } from '@renderer/features/locations/components/settings-view/sections/addressing-policy-settings-section';
import { AgentAdvancedSettingsSection } from '@renderer/features/locations/components/settings-view/sections/agent-advanced-settings-section';
import { CanManageAgentsSettingsSection } from '@renderer/features/locations/components/settings-view/sections/can-manage-agents-settings-section';
import { PermissionSettingsSection } from '@renderer/features/locations/components/settings-view/sections/permission-settings-section';
import { ProviderSignInSettingsSection } from '@renderer/features/locations/components/settings-view/sections/provider-sign-in-settings-section';
import { ServiceGrantsSettingsSection } from '@renderer/features/locations/components/settings-view/sections/service-grants-settings-section';
import { useLocalAgentTab } from '@renderer/features/locations/hooks/use-local-agent-tab';
import { agentsStore } from '@renderer/features/locations/stores/agents-store';
import {
  asMounted,
  getLocationStore,
} from '@renderer/features/locations/stores/location-selectors';
import { rpc } from '@renderer/lib/ipc';
import { useParams } from '@renderer/lib/layout/navigation-provider';
import { Spinner } from '@renderer/lib/ui/spinner';

export const SettingsPanel = observer(function SettingsPanel() {
  const {
    params: { locationId, agentName },
  } = useParams('location');
  const mounted = asMounted(getLocationStore(locationId));
  // With a Connections tab, the agent's grants are there and not here.
  const { tabs } = useLocalAgentTab(agentsStore.agentAtLocation(locationId, agentName));

  // Resolve the specific agent the page is scoped to (by its definition name),
  // so its settings render through the normal per-agent sections. Switch Console has
  // no main/subagent split — every agent gets the same settings (CHOO-1440).
  const { data: agents } = useQuery({
    queryKey: ['location-agents', locationId],
    queryFn: () => rpc.agents.getAgents(locationId),
  });

  if (!mounted) {
    return (
      <div className="flex items-center justify-center py-10">
        <Spinner />
      </div>
    );
  }

  const agent = agentName ? (agents ?? []).find((a) => a.name === agentName) : (agents ?? [])[0];
  const agentId = agent?.id;

  return (
    <div className="flex flex-col gap-10">
      <AgentInstructionsSection locationId={locationId} agentId={agentId} />
      <section className="flex flex-col gap-6">
        <SectionLabel>General</SectionLabel>
        <ProviderSignInSettingsSection locationId={locationId} agentId={agentId} />
        <PermissionSettingsSection locationId={locationId} agentId={agentId} />
        <AddressingPolicySettingsSection locationId={locationId} agentId={agentId} />
        <CanManageAgentsSettingsSection locationId={locationId} agentId={agentId} />
        {tabs === null && (
          <ServiceGrantsSettingsSection locationId={locationId} agentId={agentId} />
        )}
      </section>
      <AgentAdvancedSettingsSection locationId={locationId} agentId={agentId} />
    </div>
  );
});