Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
aa57984
build: added missing dependency
utin-francis-peter Oct 11, 2024
0481e76
chore: updated Query and WidgetProps interface with source property
utin-francis-peter Oct 14, 2024
848beb1
chore: corrected typo in var declaration
utin-francis-peter Oct 14, 2024
62802eb
chore: styled component styles for sources, added showSources prop to…
utin-francis-peter Oct 14, 2024
bd66d0a
Merge branch 'main' of https://github.com/utin-francis-peter/DocsGPT …
utin-francis-peter Oct 14, 2024
f8d65b8
chore: wrapped the base component with ThemeProvider at the root leve…
utin-francis-peter Oct 28, 2024
656f4da
feat: rendering of response source
utin-francis-peter Oct 28, 2024
991a38d
Merge branch 'main' of https://github.com/utin-francis-peter/DocsGPT …
utin-francis-peter Oct 28, 2024
1a9f47b
chore: modified query sources and removed tooltip
utin-francis-peter Nov 4, 2024
0784823
Merge branch 'main' of https://github.com/utin-francis-peter/DocsGPT …
utin-francis-peter Nov 4, 2024
3e87d83
chore: adjusted spacing in source bubble
utin-francis-peter Nov 5, 2024
1a8f895
feat: query sources in widget
utin-francis-peter Nov 9, 2024
42e2c78
Merge branch 'main' of https://github.com/utin-francis-peter/DocsGPT …
utin-francis-peter Nov 10, 2024
97916bf
chore: returned themes cofig into DocsGPTWidget component
utin-francis-peter Nov 10, 2024
25feab9
chore: removed unused import
utin-francis-peter Nov 10, 2024
a7aae3f
style: minor adjustments in border-radius and spacings
utin-francis-peter Nov 10, 2024
6f83bd8
Merge branch 'main' into feat/sources-in-react-widget
utin-francis-peter Nov 11, 2024
ba59042
Merge branch 'main' into feat/sources-in-react-widget
utin-francis-peter Nov 17, 2024
2c8a294
feat: better sources scroll management
utin-francis-peter Nov 17, 2024
7d0445c
Merge branch 'main' into feat/sources-in-react-widget
ManishMadan2882 Feb 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions extensions/react-widget/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
},
"dependencies": {
"@babel/plugin-transform-flow-strip-types": "^7.23.3",
"@bpmn-io/snarkdown": "^2.2.0",
"@parcel/resolver-glob": "^2.12.0",
"@parcel/transformer-svg-react": "^2.12.0",
"@parcel/transformer-typescript-tsc": "^2.12.0",
Expand Down
128 changes: 128 additions & 0 deletions extensions/react-widget/src/components/QuerySources.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import {Query} from "../types/index"
import styled from 'styled-components';
import { ExternalLinkIcon } from '@radix-ui/react-icons'
import { useEffect, useMemo, useState } from "react";


const SourcesWrapper = styled.div`
margin: 4px;
display: flex;
flex-direction: column;
overflow: hidden;
`

const SourcesGrid = styled.div`
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 0.5rem;
max-width: 90vw;
overflow-x: scroll;

@media(min-width: 768px){
max-width: 70vw;
}
`

const SourceItem = styled.div`
cursor: pointer;
display: flex;
flex-direction: column;
justify-content: space-between;
border-radius: 6px;
background-color: ${props =>props.theme.secondary.bg};
padding-left: 12px;
padding-right: 12px;
color:${props => props.theme.text};
transform: background-color .2s, color .2s;

&:hover{
background-color: ${props => props.theme.primary.bg};
color: ${props => props.theme.primary.text};
}
`

const SourceLink = styled.div<{$hasExternalSource: boolean}>`
display: flex;
flex-direction: row;
align-items: center;
gap: 0.375rem;
text-decoration: ${({$hasExternalSource}) => ($hasExternalSource? "underline": "none")};
text-underline-offset: 2px;
`

const SourceLinkText = styled.p`
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
font-size: 0.75rem;
line-height: 1rem;
`

const OtherSources = styled.button`
cursor: pointer;
background: transparent;
color: #8860DB;
border: none;
outline: none;
margin-top: 0.5rem;
align-self: flex-start;
`

type TQuerySources = {
sources: Pick<Query, "sources">["sources"],
}

const QuerySources = ({sources}:TQuerySources) => {
const [showAllSources, setShowAllSources] = useState(false)

const visibleSources = useMemo(() => {
if(!sources) return [];

return showAllSources? sources : sources.slice(0, 3)
}, [sources, showAllSources])

const handleToggleShowAll = () => {
setShowAllSources(prev => !prev)
}

if(!sources || sources.length === 0){
return null;
}

return (
<SourcesWrapper>
<SourcesGrid>
{visibleSources?.map((source, index) => (
<SourceItem
key={index}
>
<SourceLink
$hasExternalSource={!!source.source && source.source !== "local"}
onClick={() =>
source.source && source.source !== 'local'
? window.open(source.source, '_blank', 'noopener,noreferrer')
: null
}
>
<ExternalLinkIcon />
<SourceLinkText title={source.source && source.source !== 'local' ? source.source : source.title}>
{source.source && source.source !== 'local' ? source.source : source.title}
</SourceLinkText>
</SourceLink>
</SourceItem>
))}
</SourcesGrid>

{
sources.length > 3 && (
<OtherSources onClick={handleToggleShowAll}>{
showAllSources ? `Show less` : `+ ${sources.length - 3} more`
}</OtherSources>

)
}
</SourcesWrapper>
)
}

export default QuerySources
3 changes: 2 additions & 1 deletion extensions/react-widget/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

//development
import { createRoot } from "react-dom/client";
import { App } from "./App";
import React from "react";
const container = document.getElementById("app") as HTMLElement;
const root = createRoot(container)
root.render(<App />);
root.render(<App />);
8 changes: 6 additions & 2 deletions extensions/react-widget/src/requests/streamingApi.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { FEEDBACK } from "@/types";

interface HistoryItem {
prompt: string;
response?: string;
}

interface FetchAnswerStreamingProps {
question?: string;
apiKey?: string;
Expand All @@ -12,12 +14,14 @@ interface FetchAnswerStreamingProps {
apiHost?: string;
onEvent?: (event: MessageEvent) => void;
}

interface FeedbackPayload {
question: string;
answer: string;
apikey: string;
feedback: FEEDBACK;
}

export function fetchAnswerStreaming({
question = '',
apiKey = '',
Expand Down Expand Up @@ -46,7 +50,7 @@ export function fetchAnswerStreaming({

const reader = response.body.getReader();
const decoder = new TextDecoder('utf-8');
let counterrr = 0;
let counter = 0;
const processStream = ({
done,
value,
Expand All @@ -56,7 +60,7 @@ export function fetchAnswerStreaming({
return;
}

counterrr += 1;
counter += 1;

const chunk = decoder.decode(value);

Expand Down
11 changes: 9 additions & 2 deletions extensions/react-widget/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
export type MESSAGE_TYPE = 'QUESTION' | 'ANSWER' | 'ERROR';

export type Status = 'idle' | 'loading' | 'failed';

export type FEEDBACK = 'LIKE' | 'DISLIKE';

export type THEME = 'light' | 'dark';

export interface Query {
prompt: string;
response?: string;
feedback?: FEEDBACK;
error?: string;
sources?: { title: string; text: string }[];
sources?: { title: string; text: string, source:string }[];
conversationId?: string | null;
title?: string | null;
}

export interface WidgetProps {
apiHost?: string;
apiKey?: string;
Expand All @@ -32,6 +37,8 @@ export interface WidgetProps {
buttonText?:string;
buttonBg?:string;
collectFeedback?:boolean;
deafultOpen?: boolean;
showSources?: boolean
defaultOpen?: boolean;
}
export interface WidgetCoreProps extends WidgetProps {
Expand All @@ -54,4 +61,4 @@ export interface Result {
text:string;
title:string;
source:string;
}
}