Skip to content

Commit

Permalink
[front/components/actions/retrieval] - refactor: transition utils to …
Browse files Browse the repository at this point in the history
…TSX and integrate icons

 - Renamed `utils.ts` to `utils.tsx` to support JSX syntax
 - Replaced citation type with icon component in `makeDocumentCitation` function

[front/components/markdown] - feature: create citationIconMap to map icon types to components

 - Added a new `citationIconMap` that maps citation types to corresponding SVG components
 - Updated `MarkdownCitation` interface to use React JSX elements for icons instead of citation type strings
  • Loading branch information
JulesBelveze committed Dec 15, 2024
1 parent c4d765e commit e02dab4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import {
} from "@dust-tt/types";

import type { MarkdownCitation } from "@app/components/markdown/MarkdownCitation";
import { citationIconMap } from "@app/components/markdown/MarkdownCitation";

export function makeDocumentCitation(
document: RetrievalDocumentType
): MarkdownCitation {
const IconComponent =
citationIconMap[getProviderFromRetrievedDocument(document)];
return {
href: document.sourceUrl ?? undefined,
title: getTitleFromRetrievedDocument(document),
type: getProviderFromRetrievedDocument(document),
icon: <IconComponent />,
};
}

Expand Down
34 changes: 33 additions & 1 deletion front/components/markdown/MarkdownCitation.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
import {
ConfluenceLogo,
DocumentTextStrokeIcon,
DriveLogo,
GithubLogo,
ImageStrokeIcon,
IntercomLogo,
MicrosoftLogo,
NotionLogo,
SlackLogo,
SnowflakeLogo,
ZendeskLogo,
} from "@dust-tt/sparkle";
import type { SVGProps } from "react";

const CITATION_ICONS = [
"confluence",
"document",
Expand All @@ -14,9 +29,26 @@ const CITATION_ICONS = [

export type CitationIconType = (typeof CITATION_ICONS)[number];

export const citationIconMap: Record<
CitationIconType,
(props: SVGProps<SVGSVGElement>) => React.JSX.Element
> = {
confluence: ConfluenceLogo,
document: DocumentTextStrokeIcon,
github: GithubLogo,
google_drive: DriveLogo,
intercom: IntercomLogo,
microsoft: MicrosoftLogo,
zendesk: ZendeskLogo,
notion: NotionLogo,
slack: SlackLogo,
image: ImageStrokeIcon,
snowflake: SnowflakeLogo,
};

export interface MarkdownCitation {
description?: string;
href?: string;
title: string;
type: CitationIconType;
icon: React.JSX.Element;
}

0 comments on commit e02dab4

Please sign in to comment.