Skip to content

Commit

Permalink
fix: Update agent and publish URL showing correctly based on aliasAss…
Browse files Browse the repository at this point in the history
…igned
  • Loading branch information
ivyjeong13 committed Nov 26, 2024
1 parent 82e7db2 commit 475d953
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
11 changes: 10 additions & 1 deletion ui/admin/app/components/agent/Agent.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LibraryIcon, PlusIcon, WrenchIcon } from "lucide-react";
import { useCallback, useState } from "react";
import { useCallback, useEffect, useState } from "react";

import { Agent as AgentType } from "~/lib/model/agents";
import { cn } from "~/lib/utils";
Expand Down Expand Up @@ -27,6 +27,15 @@ export function Agent({ className, onRefresh }: AgentProps) {

const [agentUpdates, setAgentUpdates] = useState(agent);

useEffect(() => {
if (agent.id === agentUpdates.id) {
setAgentUpdates({
...agentUpdates,
aliasAssigned: agent.aliasAssigned ?? false,
});
}
}, [agent]);

Check warning on line 37 in ui/admin/app/components/agent/Agent.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'agentUpdates'. Either include it or remove the dependency array. You can also do a functional update 'setAgentUpdates(a => ...)' if you only need 'agentUpdates' in the 'setAgentUpdates' call

const partialSetAgent = useCallback(
(changes: Partial<typeof agent>) => {
const updatedAgent = { ...agent, ...agentUpdates, ...changes };
Expand Down
2 changes: 1 addition & 1 deletion ui/admin/app/components/agent/AgentContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function AgentProvider({
<AgentContext.Provider
value={{
agentId,
agent,
agent: getAgent.data ?? agent,
updateAgent: updateAgent.execute,
isUpdating: updateAgent.isLoading,
lastUpdated,
Expand Down
14 changes: 7 additions & 7 deletions ui/admin/app/components/agent/AgentPublishStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function AgentPublishStatus({
() => AssistantApiService.getAssistants()
);

const refAgent = useMemo(() => {
const refAssistant = useMemo(() => {
if (!getAssistants.data) return null;

return getAssistants.data.find(({ id }) => id === agent.alias);
Expand All @@ -53,14 +53,14 @@ export function AgentPublishStatus({
function renderAgentRef() {
if (!agent.alias) return <div />;

if (refAgent && refAgent.id !== agent.id) {
if (refAssistant && refAssistant.entityID !== agent.id) {
const route =
refAgent.type === "agent"
refAssistant.type === "agent"
? $path("/agents/:agent", {
agent: refAgent.entityID,
agent: refAssistant.entityID,
})
: $path("/workflows/:workflow", {
workflow: refAgent.entityID,
workflow: refAssistant.entityID,
});

return (
Expand All @@ -72,13 +72,13 @@ export function AgentPublishStatus({

<TypographySmall className="pb-0 text-muted-foreground">
<span className="min-w-fit">
Ref name <b>{refAgent.id}</b> used by{" "}
Ref name <b>{refAssistant.id}</b> used by{" "}
</span>
<Link
className="text-accent-foreground underline"
to={route}
>
{refAgent.name}
{refAssistant.name}
</Link>
</TypographySmall>
</div>
Expand Down

0 comments on commit 475d953

Please sign in to comment.