Skip to content

A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.

828 B
Raw Blame
import { formatNumber } from "@homarr/common";

interface AssistantConnectionStateInput {
  connectionConfigured: boolean;
  destinationChanged: boolean;
  providerRequiresApiKey: boolean;
  apiKeyConfigured: boolean;
}

export const getAssistantConnectionState = ({
  connectionConfigured,
  destinationChanged,
  providerRequiresApiKey,
  apiKeyConfigured,
}: AssistantConnectionStateInput) => {
  const hasStoredApiKey = apiKeyConfigured && !destinationChanged;
  const credentialsMissing = providerRequiresApiKey && !hasStoredApiKey;
  const connectionPending = !connectionConfigured || destinationChanged || credentialsMissing;

  return {
    hasStoredApiKey,
    connectionPending,
    connectionReady: !connectionPending,
  };
};

export const formatAssistantContextWindow = (tokens: number) => formatNumber(tokens, 0);