Skip to content

Commit

Permalink
Add ingestion as a "Source" for the FE + improve typing (#2312)
Browse files Browse the repository at this point in the history
  • Loading branch information
Weves authored Sep 3, 2024
1 parent fb95398 commit 5da6d79
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 55 deletions.
49 changes: 26 additions & 23 deletions web/src/app/admin/connectors/[connector]/AddConnectorPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import AdvancedFormPage from "./pages/Advanced";
import DynamicConnectionForm from "./pages/DynamicConnectorCreationForm";
import CreateCredential from "@/components/credentials/actions/CreateCredential";
import ModifyCredential from "@/components/credentials/actions/ModifyCredential";
import { ValidSources } from "@/lib/types";
import { ConfigurableSources, ValidSources } from "@/lib/types";
import { Credential, credentialTemplates } from "@/lib/connectors/credentials";
import {
ConnectionConfiguration,
Expand Down Expand Up @@ -54,7 +54,7 @@ export type AdvancedConfigFinal = {
export default function AddConnector({
connector,
}: {
connector: ValidSources;
connector: ConfigurableSources;
}) {
const [currentCredential, setCurrentCredential] =
useState<Credential<any> | null>(null);
Expand Down Expand Up @@ -195,7 +195,7 @@ export default function AddConnector({
};

// google sites-specific handling
if (connector == "google_site") {
if (connector == "google_sites") {
const response = await submitGoogleSite(
selectedFiles,
formValues?.base_url,
Expand Down Expand Up @@ -443,26 +443,29 @@ export default function AddConnector({
</button>
)}

{!(connector == "google_drive") && createConnectorToggle && (
<Modal
className="max-w-3xl rounded-lg"
onOutsideClick={() => setCreateConnectorToggle(false)}
>
<>
<Title className="mb-2 text-lg">
Create a {getSourceDisplayName(connector)} credential
</Title>
<CreateCredential
close
refresh={refresh}
sourceType={connector}
setPopup={setPopup}
onSwitch={onSwap}
onClose={() => setCreateConnectorToggle(false)}
/>
</>
</Modal>
)}
{/* NOTE: connector will never be google_drive, since the ternary above will
prevent that, but still keeping this here for safety in case the above changes. */}
{(connector as ValidSources) !== "google_drive" &&
createConnectorToggle && (
<Modal
className="max-w-3xl rounded-lg"
onOutsideClick={() => setCreateConnectorToggle(false)}
>
<>
<Title className="mb-2 text-lg">
Create a {getSourceDisplayName(connector)} credential
</Title>
<CreateCredential
close
refresh={refresh}
sourceType={connector}
setPopup={setPopup}
onSwitch={onSwap}
onClose={() => setCreateConnectorToggle(false)}
/>
</>
</Modal>
)}
</Card>
<div className="mt-4 flex w-full justify-end">
<button
Expand Down
10 changes: 7 additions & 3 deletions web/src/app/admin/connectors/[connector]/ConnectorWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
"use client";

import { ValidSources } from "@/lib/types";
import { ConfigurableSources, ValidSources } from "@/lib/types";
import AddConnector from "./AddConnectorPage";
import { FormProvider } from "@/components/context/FormContext";
import Sidebar from "./Sidebar";
import { HeaderTitle } from "@/components/header/HeaderTitle";
import { Button } from "@tremor/react";
import { isValidSource } from "@/lib/sources";

export default function ConnectorWrapper({ connector }: { connector: string }) {
export default function ConnectorWrapper({
connector,
}: {
connector: ConfigurableSources;
}) {
return (
<FormProvider connector={connector}>
<div className="flex justify-center w-full h-full">
Expand All @@ -28,7 +32,7 @@ export default function ConnectorWrapper({ connector }: { connector: string }) {
</Button>
</div>
) : (
<AddConnector connector={connector as ValidSources} />
<AddConnector connector={connector} />
)}
</div>
</div>
Expand Down
7 changes: 6 additions & 1 deletion web/src/app/admin/connectors/[connector]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { ConfigurableSources } from "@/lib/types";
import ConnectorWrapper from "./ConnectorWrapper";

export default async function Page({
params,
}: {
params: { connector: string };
}) {
return <ConnectorWrapper connector={params.connector.replace("-", "_")} />;
return (
<ConnectorWrapper
connector={params.connector.replace("-", "_") as ConfigurableSources}
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,10 @@ export function CCPairIndexingStatusTable({
</Button>
</div>
{sortedSources
.filter((source) => source != "not_applicable")
.filter(
(source) =>
source != "not_applicable" && source != "ingestion_api"
)
.map((source, ind) => {
const sourceMatches = source
.toLowerCase()
Expand Down
25 changes: 2 additions & 23 deletions web/src/app/chat/ChatIntro.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,9 @@
import { getSourceMetadataForSources, listSourceMetadata } from "@/lib/sources";
import { getSourceMetadataForSources } from "@/lib/sources";
import { ValidSources } from "@/lib/types";
import Image from "next/image";
import { Persona } from "../admin/assistants/interfaces";
import { Divider } from "@tremor/react";
import { FiBookmark, FiCpu, FiInfo, FiX, FiZoomIn } from "react-icons/fi";
import { FiBookmark, FiInfo } from "react-icons/fi";
import { HoverPopup } from "@/components/HoverPopup";
import { Modal } from "@/components/Modal";
import { useState } from "react";
import { Logo } from "@/components/Logo";

const MAX_PERSONAS_TO_DISPLAY = 4;

function HelperItemDisplay({
title,
description,
}: {
title: string;
description: string;
}) {
return (
<div className="cursor-pointer hover:bg-hover-light border border-border rounded py-2 px-4">
<div className="text-emphasis font-bold text-lg flex">{title}</div>
<div className="text-sm">{description}</div>
</div>
);
}

export function ChatIntro({
availableSources,
Expand Down
7 changes: 5 additions & 2 deletions web/src/lib/connectors/connectors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ValidInputTypes, ValidSources } from "../types";
import { ConfigurableSources, ValidInputTypes, ValidSources } from "../types";

export type InputType =
| "list"
Expand Down Expand Up @@ -76,7 +76,10 @@ export interface ConnectionConfiguration {
overrideDefaultFreq?: number;
}

export const connectorConfigs: Record<ValidSources, ConnectionConfiguration> = {
export const connectorConfigs: Record<
ConfigurableSources,
ConnectionConfiguration
> = {
web: {
description: "Configure Web connector",
values: [
Expand Down
1 change: 1 addition & 0 deletions web/src/lib/connectors/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ export const credentialTemplates: Record<ValidSources, any> = {
mediawiki: null,
web: null,
not_applicable: null,
ingestion_api: null,

// NOTE: These are Special Cases
google_drive: { google_drive_tokens: "" } as GoogleDriveCredentialJson,
Expand Down
11 changes: 10 additions & 1 deletion web/src/lib/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ const SOURCE_METADATA_MAP: SourceMap = {
category: SourceCategory.Storage,
docs: "https://docs.danswer.dev/connectors/google_storage",
},
ingestion_api: {
icon: GlobeIcon,
displayName: "Ingestion",
category: SourceCategory.Other,
},
// currently used for the Internet Search tool docs, which is why
// a globe is used
not_applicable: {
Expand Down Expand Up @@ -302,8 +307,12 @@ export function getSourceMetadata(sourceType: ValidSources): SourceMetadata {
}

export function listSourceMetadata(): SourceMetadata[] {
/* This gives back all the viewable / common sources, primarily for
display in the Add Connector page */
const entries = Object.entries(SOURCE_METADATA_MAP)
.filter(([source, _]) => source !== "not_applicable")
.filter(
([source, _]) => source !== "not_applicable" && source != "ingestion_api"
)
.map(([source, metadata]) => {
return fillSourceMetadata(metadata, source as ValidSources);
});
Expand Down
8 changes: 7 additions & 1 deletion web/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ const validSources = [
"google_cloud_storage",
"oci_storage",
"not_applicable",
];
"ingestion_api",
] as const;

export type ValidSources = (typeof validSources)[number];
// The valid sources that are actually valid to select in the UI
export type ConfigurableSources = Exclude<
ValidSources,
"not_applicable" | "ingestion_api"
>;

0 comments on commit 5da6d79

Please sign in to comment.