All files / src/apps/user/pages/settings Data.tsx

78.57% Statements 11/14
68.75% Branches 11/16
71.42% Functions 5/7
78.57% Lines 11/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182                                  2x 8x 8x   4x   8x 8x   2x 1x         8x                                                                                                                           24x                                                                                         2x                                                                                    
import React from "react";
import { useMutation, useQuery } from "@tanstack/react-query";
import { Download } from "lucide-react";
import SubPage from "@/components/page/SubPage/SubPage";
import { SkeletonLines } from "@/components/detail";
import { dataRegionMeta, type Model } from "@/objects/Model";
import { APP_EMAILS, APP_ROUTES } from "@/routes/const";
import { QUERY_KEYS } from "@/services/query_keys";
import { useApiHandler } from "@/services/useApiHandler";
import {
  OUTSIDE_SERVICES,
  SERVICE_LIST_REQUEST,
  STORAGE_LOCATION,
  providersInUse,
} from "./platformFacts";
import { InfoRow, SettingsSection, SettingsTabs } from "./SettingsTabs";
 
const Data: React.FC = () => {
  const { getApiHandler } = useApiHandler();
  const { data: models, isLoading } = useQuery<Model[]>({
    queryKey: [QUERY_KEYS.GET.MODELS],
    queryFn: () => getApiHandler().model_router.list() as Promise<Model[]>,
  });
  const providers = providersInUse(models ?? []);
  const exportData = useMutation({
    mutationFn: async () => {
      if (!(await getApiHandler().user_router.downloadExport())) {
        throw new Error("export failed");
      }
    },
  });
 
  return (
    <SubPage
      title="Data"
      links={[<SettingsTabs key="tabs" active="data" />]}
    >
      <div className="max-w-xl space-y-6">
        <SettingsSection
          title="Where your data is stored"
          description="Your account, conversations, knowledge, files and search indexes are stored on CHAIN-R's servers."
        >
          <InfoRow label="Stored in" value={STORAGE_LOCATION} />
          <InfoRow label="In transit" value="Encrypted" />
        </SettingsSection>
 
        <SettingsSection
          title="Model providers"
          description="A prompt — and the text of knowledge you add, to index and search it — goes only to the service that runs the model handling it, which processes it in the region shown."
        >
          {isLoading ? (
            <div className="px-5 py-4">
              <SkeletonLines count={3} />
            </div>
          ) : providers.length === 0 ? (
            <InfoRow label="No models are available" />
          ) : (
            providers.map((p) => (
              <InfoRow
                key={p.name}
                label={p.name}
                description={p.note}
                value={
                  <span className="inline-flex flex-wrap justify-end gap-1">
                    {p.regions.map((region) => {
                      const meta = dataRegionMeta(region);
                      return meta ? (
                        <span
                          key={region}
                          className={`text-xs px-2 py-0.5 rounded-full border ${meta.pill}`}
                        >
                          {meta.label}
                        </span>
                      ) : (
                        <span
                          key={region ?? "none"}
                          className="text-xs text-gray-400 dark:text-gray-500"
                        >
                          Region not declared
                        </span>
                      );
                    })}
                  </span>
                }
              />
            ))
          )}
        </SettingsSection>
 
        <SettingsSection
          title="Other services"
          description="What else leaves CHAIN-R, and for what."
        >
          {OUTSIDE_SERVICES.map((s) => (
            <InfoRow key={s.purpose} label={s.purpose} description={s.receives} />
          ))}
          <InfoRow
            label="The services we use"
            description="The full list of the services we use, and what each one receives, is available on request."
            value={
              <a
                href={`mailto:${APP_EMAILS.help}?subject=${encodeURIComponent(SERVICE_LIST_REQUEST)}`}
                className="text-sm text-indigo-600 dark:text-indigo-400 hover:underline"
              >
                Request the list
              </a>
            }
          />
        </SettingsSection>
 
        <SettingsSection
          title="Retention"
          description="How long CHAIN-R keeps what you create."
        >
          <InfoRow
            label="Your content"
            description="Kept while your account is active. Delete a conversation, knowledge source or any other resource from its page."
            value="Until you delete it"
          />
          <InfoRow
            label="Edit history"
            description="Every change to a resource is versioned, and the history is kept after the resource is deleted. It is the audit trail."
          />
        </SettingsSection>
 
        <SettingsSection
          title="Export or delete your data"
          description="Your rights to a copy of your data and to its deletion are set out in the Privacy Policy."
        >
          <InfoRow
            label="Download your data"
            description={
              exportData.isError
                ? "Your export could not be built. Try again, or email us if it keeps failing."
                : "A zip of everything you own: your account, agents, conversations, knowledge and the files you uploaded, rules, evaluations, dashboards, usage, edit history, and what agents remember. Credentials are left out."
            }
            value={
              <button
                type="button"
                onClick={() => exportData.mutate()}
                disabled={exportData.isPending}
                aria-busy={exportData.isPending}
                className="inline-flex items-center gap-2 px-3 py-1.5 rounded-lg border border-gray-300 dark:border-gray-600 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700 disabled:opacity-60 disabled:cursor-wait transition-colors"
              >
                <Download className="size-3.5" />
                {exportData.isPending ? "Preparing…" : "Download"}
              </button>
            }
          />
          <InfoRow
            label="Delete your account"
            description={
              <>
                Not self-service yet. To have your account and data deleted,
                email{" "}
                <a
                  href={`mailto:${APP_EMAILS.help}`}
                  className="underline hover:text-gray-700 dark:hover:text-gray-300"
                >
                  {APP_EMAILS.help}
                </a>
                . See the{" "}
                <a
                  href={APP_ROUTES.LEGAL.privacy_policy}
                  target="_blank"
                  rel="noopener noreferrer"
                  className="underline hover:text-gray-700 dark:hover:text-gray-300"
                >
                  Privacy Policy
                </a>
                .
              </>
            }
          />
        </SettingsSection>
      </div>
    </SubPage>
  );
};
 
export default Data;