Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

3.2 KB
Raw Blame
import * as React from 'react';
import { LoaderCircle } from 'lucide-react';
import { useTranslation } from 'react-i18next';

import { Button } from '@/components/ui/button';
import { AgentCard } from './AgentCard';
import { ModelHubInfoHint } from './ModelHubInfoHint';
import { foldRegionRead, type RegionRead } from './regionRead';
import type { FreshRuntimeProjection } from './runtimeLifecycle';
import type { AgentSupply, RuntimeDependency } from './types';

type GatewayModuleProps = Omit<React.ComponentProps<typeof AgentCard>, 'agents'> & {
  supply: RegionRead<AgentSupply[]>;
  runtime: FreshRuntimeProjection | null;
  runtimeSnapshot: RuntimeDependency | null;
  onRetry: () => void;
  retryDisabled?: boolean;
  retryRef?: React.Ref<HTMLButtonElement>;
  readFailureCopy?: string;
};

export const GatewayModule: React.FC<GatewayModuleProps> = ({ runtime, runtimeSnapshot, supply, onRetry, retryDisabled = false, retryRef, readFailureCopy, ...props }) => {
  const { t } = useTranslation();
  const agents = foldRegionRead<AgentSupply[], AgentSupply[] | undefined>(supply, {
    loading: () => undefined,
    ready: (data) => data,
    unread: () => undefined,
    degraded: (staleData) => staleData,
  });
  const listening = runtimeSnapshot?.status.listening;
  return (
    <section className="relative z-20 flex min-h-[420px] w-full min-w-0 flex-col self-start overflow-hidden rounded-[14px] border border-border bg-surface">
      <header className="flex h-14 shrink-0 items-center justify-between border-b border-border px-3.5">
        <span className="flex items-center gap-[7px]">
          <h2 className="text-[16px] font-bold leading-[23px] text-foreground">{t('settings.models.gateway.heading')}</h2>
          <ModelHubInfoHint label={t('settings.models.gateway.infoLabel')} content={t('settings.models.gateway.info')} className="model-hub-overview-info" />
        </span>
        {listening && <span className="model-hub-pill model-hub-fill-0a border border-border text-muted">{listening.host}:{listening.port}</span>}
      </header>
      <div className="flex-1 px-2 pb-2 pt-3">
        {supply.kind === 'loading' && agents === undefined
          ? <div className="flex h-full min-h-36 items-center justify-center"><LoaderCircle className="size-4 animate-spin text-muted" /></div>
          : supply.kind === 'unread'
            ? <div className="flex h-full min-h-36 flex-col items-center justify-center gap-3 px-4 text-center"><p className="text-[12px] text-muted">{t('settings.models.gateway.supply.unread')}</p><Button ref={retryRef} variant="outline" size="xs" disabled={retryDisabled} onClick={onRetry}>{t('settings.models.gateway.retry')}</Button></div>
            : <>
                {supply.kind === 'degraded' && supply.cause === 'read_failed' && <div className="mb-2 flex items-center justify-between gap-3 rounded-lg border border-destructive/25 bg-destructive/[0.08] px-3 py-2"><p className="text-[11px] text-destructive-ink">{readFailureCopy ?? t('settings.models.gateway.supply.unread')}</p><Button ref={retryRef} variant="outline" size="xs" disabled={retryDisabled} onClick={onRetry}>{t('settings.models.gateway.retry')}</Button></div>}
                <AgentCard agents={agents ?? []} runtime={runtime} {...props} />
              </>}
      </div>
    </section>
  );
};