-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feedbacks for builders #9110
Merged
Merged
Feedbacks for builders #9110
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
3e46609
Add info/feedback tab
albandum 6261f66
Committing performance preview
albandum 153f771
Skeleton is here, need to bring the configurations history endpoint
overmode c53813d
Merge branch 'main' into alban/feedbacks-builder-ui-sparkle
overmode 412c157
Now fetching config history, added conv button need a way to get the …
overmode f48174c
Can get conversationsId in the feedback card
overmode f88e5ee
Fixed link, reordered feedbacks
overmode 5274870
Applied Pr comments
overmode dcb2e7c
Auth done in endpoint
overmode 4deddff
Modified feedback popover to be more transpoarent
overmode 849fe4b
Using fetchByModelId
overmode 143ebcf
Use spinner instead of ? avatar
overmode 1c0a48b
Now auto-scrolling to messages, fixed tab resetting to info
overmode d287999
Fixed sparkle referencing local repo in package.json
overmode 4bf8b1c
Merge branch 'main' into alban/feedbacks-builder-ui-sparkle
overmode f49ef7c
Conversation will be shared: warning
overmode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,42 @@ | ||
import { | ||
Avatar, | ||
Button, | ||
ContentMessage, | ||
ElementModal, | ||
HandThumbDownIcon, | ||
HandThumbUpIcon, | ||
InformationCircleIcon, | ||
Page, | ||
Spinner, | ||
Tabs, | ||
TabsContent, | ||
TabsList, | ||
TabsTrigger, | ||
} from "@dust-tt/sparkle"; | ||
import type { AgentConfigurationScope, WorkspaceType } from "@dust-tt/types"; | ||
import { useCallback, useState } from "react"; | ||
import type { | ||
AgentConfigurationScope, | ||
LightAgentConfigurationType, | ||
LightWorkspaceType, | ||
WorkspaceType, | ||
} from "@dust-tt/types"; | ||
import { ExternalLinkIcon } from "lucide-react"; | ||
import { useCallback, useMemo, useState } from "react"; | ||
|
||
import { AssistantDetailsButtonBar } from "@app/components/assistant/AssistantDetailsButtonBar"; | ||
import { AssistantActionsSection } from "@app/components/assistant/details/AssistantActionsSection"; | ||
import { AssistantUsageSection } from "@app/components/assistant/details/AssistantUsageSection"; | ||
import { ReadOnlyTextArea } from "@app/components/assistant/ReadOnlyTextArea"; | ||
import { SharingDropdown } from "@app/components/assistant_builder/Sharing"; | ||
import type { AgentMessageFeedbackType } from "@app/lib/api/assistant/feedback"; | ||
import { | ||
useAgentConfiguration, | ||
useAgentConfigurationFeedbacks, | ||
useAgentConfigurationHistory, | ||
useUpdateAgentScope, | ||
} from "@app/lib/swr/assistants"; | ||
import { classNames } from "@app/lib/utils"; | ||
import { useFeedbackConversation } from "@app/lib/swr/feedbacks"; | ||
import { useUserDetails } from "@app/lib/swr/user"; | ||
import { classNames, timeAgoFrom } from "@app/lib/utils"; | ||
|
||
type AssistantDetailsProps = { | ||
owner: WorkspaceType; | ||
|
@@ -55,7 +74,7 @@ export function AssistantDetails({ | |
return <></>; | ||
} | ||
|
||
const DescriptionSection = () => ( | ||
const TopSection = () => ( | ||
<div className="flex flex-col gap-5"> | ||
<div className="flex flex-col gap-3 sm:flex-row"> | ||
<Avatar | ||
|
@@ -82,6 +101,30 @@ export function AssistantDetails({ | |
)} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
|
||
const TabsSection = () => ( | ||
<Tabs defaultValue="info"> | ||
<TabsList> | ||
<TabsTrigger value="info" label="Info" icon={InformationCircleIcon} /> | ||
<TabsTrigger | ||
value="performance" | ||
label="Performance" | ||
icon={HandThumbUpIcon} | ||
/> | ||
</TabsList> | ||
<TabsContent value="info"> | ||
<InfoSection /> | ||
</TabsContent> | ||
<TabsContent value="performance"> | ||
<FeedbacksSection /> | ||
</TabsContent> | ||
</Tabs> | ||
); | ||
|
||
const InfoSection = () => ( | ||
<div className="mt-2 flex flex-col gap-5"> | ||
{agentConfiguration.status === "active" && ( | ||
<AssistantDetailsButtonBar | ||
owner={owner} | ||
|
@@ -108,6 +151,11 @@ export function AssistantDetails({ | |
owner={owner} | ||
/> | ||
<Page.Separator /> | ||
<AssistantActionsSection | ||
agentConfiguration={agentConfiguration} | ||
owner={owner} | ||
/> | ||
<InstructionsSection /> | ||
</div> | ||
); | ||
|
||
|
@@ -121,6 +169,70 @@ export function AssistantDetails({ | |
"This assistant has no instructions." | ||
); | ||
|
||
const FeedbacksSection = () => { | ||
const { | ||
agentConfigurationFeedbacks, | ||
isAgentConfigurationFeedbacksLoading, | ||
} = useAgentConfigurationFeedbacks({ | ||
workspaceId: owner.sId, | ||
agentConfigurationId: assistantId ?? "", | ||
}); | ||
|
||
const sortedFeedbacks = useMemo(() => { | ||
if (!agentConfigurationFeedbacks) { | ||
return null; | ||
} | ||
return agentConfigurationFeedbacks.sort( | ||
(a, b) => | ||
new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime() | ||
); | ||
}, [agentConfigurationFeedbacks]); | ||
|
||
const { agentConfigurationHistory, isAgentConfigurationHistoryLoading } = | ||
useAgentConfigurationHistory({ | ||
workspaceId: owner.sId, | ||
agentConfigurationId: assistantId || "", | ||
disabled: !assistantId, | ||
}); | ||
|
||
return isAgentConfigurationFeedbacksLoading || | ||
isAgentConfigurationHistoryLoading ? ( | ||
<Spinner /> | ||
) : ( | ||
<div> | ||
{!sortedFeedbacks || sortedFeedbacks.length === 0 || !assistantId ? ( | ||
<div className="mt-3 text-sm text-element-900">No feedbacks.</div> | ||
) : ( | ||
<div className="mt-3"> | ||
<AgentConfigurationVersionHeader | ||
agentConfiguration={agentConfiguration} | ||
agentConfigurationVersion={agentConfiguration.version} | ||
isLatestVersion={true} | ||
/> | ||
{sortedFeedbacks.map((feedback, index) => ( | ||
<div key={feedback.id}> | ||
{index > 0 && | ||
feedback.agentConfigurationVersion !== | ||
sortedFeedbacks[index - 1].agentConfigurationVersion && ( | ||
<AgentConfigurationVersionHeader | ||
agentConfiguration={agentConfigurationHistory?.find( | ||
(c) => c.version === feedback.agentConfigurationVersion | ||
)} | ||
agentConfigurationVersion={ | ||
feedback.agentConfigurationVersion | ||
} | ||
isLatestVersion={false} | ||
/> | ||
)} | ||
<FeedbackCard owner={owner} feedback={feedback} /> | ||
</div> | ||
))} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
return ( | ||
<ElementModal | ||
openOnElement={agentConfiguration} | ||
|
@@ -130,13 +242,111 @@ export function AssistantDetails({ | |
variant="side-sm" | ||
> | ||
<div className="flex flex-col gap-5 pt-6 text-sm text-foreground"> | ||
<DescriptionSection /> | ||
<AssistantActionsSection | ||
agentConfiguration={agentConfiguration} | ||
owner={owner} | ||
/> | ||
<InstructionsSection /> | ||
<TopSection /> | ||
<TabsSection /> | ||
</div> | ||
</ElementModal> | ||
); | ||
} | ||
|
||
function AgentConfigurationVersionHeader({ | ||
agentConfigurationVersion, | ||
agentConfiguration, | ||
isLatestVersion, | ||
}: { | ||
agentConfigurationVersion: number; | ||
agentConfiguration: LightAgentConfigurationType | undefined; | ||
isLatestVersion: boolean; | ||
}) { | ||
const getAgentConfigurationVersionString = useCallback( | ||
(config: LightAgentConfigurationType) => { | ||
return isLatestVersion | ||
? "Latest Version" | ||
: !config.versionCreatedAt | ||
? `v${config.version}` | ||
: new Date(config.versionCreatedAt).toLocaleDateString("en-US", { | ||
year: "numeric", | ||
month: "long", | ||
day: "numeric", | ||
}); | ||
}, | ||
[isLatestVersion] | ||
); | ||
|
||
return ( | ||
<div className="flex items-center gap-2"> | ||
<Page.H variant="h6"> | ||
{agentConfiguration | ||
? getAgentConfigurationVersionString(agentConfiguration) | ||
: `v${agentConfigurationVersion}`} | ||
</Page.H> | ||
</div> | ||
); | ||
} | ||
|
||
function FeedbackCard({ | ||
owner, | ||
feedback, | ||
}: { | ||
owner: LightWorkspaceType; | ||
feedback: AgentMessageFeedbackType; | ||
}) { | ||
const { userDetails } = useUserDetails(feedback.userId); | ||
const { conversationId } = useFeedbackConversation({ | ||
workspaceId: owner.sId, | ||
feedbackId: feedback.id.toString(), | ||
}); | ||
const conversationUrl = `${process.env.NEXT_PUBLIC_DUST_CLIENT_FACING_URL}/w/${owner.sId}/assistant/${conversationId}`; | ||
|
||
return ( | ||
<ContentMessage variant="slate" className="my-2"> | ||
<div className="justify-content-around mb-3 flex items-center gap-2"> | ||
<div className="flex w-full items-center gap-2"> | ||
<Avatar | ||
size="xs" | ||
visual={userDetails?.image || undefined} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: was more thinking something around
|
||
name={userDetails?.firstName || "?"} | ||
/> | ||
{userDetails?.firstName} {userDetails?.lastName} | ||
</div> | ||
<div className="flex-shrink-0 text-xs text-muted-foreground"> | ||
{timeAgoFrom( | ||
feedback.createdAt instanceof Date | ||
? feedback.createdAt.getTime() | ||
: new Date(feedback.createdAt).getTime(), | ||
{ | ||
useLongFormat: true, | ||
} | ||
)}{" "} | ||
ago | ||
</div> | ||
</div> | ||
<div className="flex items-center gap-2"> | ||
<div className="flex-grow">{feedback.content}</div> | ||
<div className="flex-shrink-0"> | ||
{feedback.thumbDirection === "up" ? ( | ||
<button className="rounded bg-sky-200 p-2"> | ||
<HandThumbUpIcon /> | ||
</button> | ||
) : ( | ||
<button className="rounded bg-warning-200 p-2"> | ||
<HandThumbDownIcon /> | ||
</button> | ||
)} | ||
</div> | ||
</div> | ||
{conversationId && ( | ||
<div className="mt-2"> | ||
<Button | ||
variant="outline" | ||
size="xs" | ||
href={conversationUrl} | ||
label="Conversation" | ||
icon={ExternalLinkIcon} | ||
target="_blank" | ||
/> | ||
</div> | ||
)} | ||
</ContentMessage> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Image will break if userDetails.image === null, display it conditionally 👍 (my fault haha)