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.

4.6 KB
Raw Blame
import * as React from 'react';
import { Info } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { getBackendUiMeta } from '@/lib/agentBackends';

import { GuardGapList } from './GuardGapList';
import type { RouteHopRef, SupplyGap } from './types';

/**
 * What a guarded mutation would take with it.
 *
 * The two arrays travel together because the guard reports them together, the
 * confirmation shows both, and the forced retry echoes both: a caller holding
 * them apart can echo one without the other, which claims a confirmation the
 * user was never shown. Named here, beside the body that renders them, so a
 * surface that has to CARRY a plan before showing it uses the same shape.
 */
export type GuardPlan = { hops: RouteHopRef[]; gaps: SupplyGap[] };

/**
 * What a caller can show BEFORE the guard has spoken.
 *
 * `gaps: null` is 「nobody has said」, and it is not `[]`. Whether a removal
 * strands an Agent is the guard's answer — it depends on supply this client
 * cannot see — so a client that answers `[]` on its own has told the user
 * 「another source is available」 during the one confirmation that matters, on no
 * authority at all. A picture says which hops it can see and stays silent about
 * the rest; only a `GuardPlan`, whose halves both come from the server, may
 * carry a statement about interruption.
 */
export type GuardPicture = Omit<GuardPlan, 'gaps'> & { gaps: SupplyGap[] | null };

/** The shared evidence body for every guarded Model Hub mutation and its result. */
export const GuardImpact: React.FC<GuardPicture & {
  committed?: boolean;
  /**
   * Source id → that Source's own name, for the callers that can resolve one.
   *
   * A hop goes THROUGH a supplier, and 「no hidden mappings」 means the
   * confirmation says which — otherwise a user forcing a removal reads which
   * position disappears without reading whose it was. Only a caller holding the
   * page's Sources can answer that, so it is asked for rather than looked up
   * here, and an id it cannot name leaves the row exactly as it was: a raw
   * `src_…` in front of the model would name nothing while looking like it did.
   */
  sourceNames?: Readonly<Record<string, string>>;
}> = ({ hops, gaps, committed = false, sourceNames }) => {
  const { t } = useTranslation();
  return (
    <>
      {hops.length > 0 && (
        <>
          <div className="model-hub-guard-label">
            <p>{t(committed ? 'settings.models.guard.result.label' : 'settings.models.guard.label')}</p>
            <span>{t('settings.models.guard.count', { count: hops.length })}</span>
          </div>
          <div className="model-hub-guard-list">
            {hops.map((hop) => {
              const source = sourceNames?.[hop.source_id];
              return (
                <div
                  key={`${hop.backend}:${hop.menu_model}:${hop.position}:${hop.source_id}:${hop.model_id}`}
                  className="model-hub-guard-hop"
                >
                  <span className="min-w-0 flex-1">
                    <strong>
                      {getBackendUiMeta(hop.backend).label} · {hop.menu_model}
                    </strong>
                    {/* The supplier and the model it serves, in the Agent card's
                        own mapping copy rather than a second string that would
                        say the same thing: one mapping reads one way wherever
                        the Model Hub shows it. */}
                    <span>{source ? t('settings.models.gateway.row.current', { source, model: hop.model_id }) : hop.model_id} · {t('settings.models.guard.hop.position', { n: hop.position })}</span>
                  </span>
                </div>
              );
            })}
          </div>
        </>
      )}
      {/* Both of these are statements ABOUT the gaps — the list names them, and
          the hint below warns when there are any — so an unstated gap list
          renders neither: 「interrupt」 would invent a consequence. No gaps
          reads as nothing to warn about, so it says nothing either. The hops above are unaffected; they are what the
          caller does know. */}
      {gaps !== null && (
        <>
          <GuardGapList
            gaps={gaps}
            labelKey={committed ? 'settings.models.guard.result.gapLabel' : undefined}
          />
          {gaps.length > 0 && (
            <p className="model-hub-guard-hint text-destructive-ink">
              <Info aria-hidden />
              {t(`settings.models.guard.${committed ? 'result.' : ''}hint.interrupt`)}
            </p>
          )}
        </>
      )}
    </>
  );
};