Skip to content

Commit

Permalink
fix: auto open from pre-auth workflow if first message contains authU…
Browse files Browse the repository at this point in the history
…RL (#1718)
  • Loading branch information
ivyjeong13 authored Feb 11, 2025
1 parent 7e743e4 commit cf61ef9
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions ui/admin/app/components/agent/shared/ToolAuthenticationDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CheckIcon, CircleAlert } from "lucide-react";
import { useEffect, useMemo, useState } from "react";
import { useCallback, useEffect, useMemo, useState } from "react";

import { useToolReference } from "~/components/agent/ToolEntry";
import { PromptAuthForm } from "~/components/chat/Message";
Expand Down Expand Up @@ -41,8 +41,9 @@ export function ToolAuthenticationDialog({
};

const [map, setMap] = useState<Record<number, ItemState>>({});
const updateItem = (id: number, state: Partial<ItemState>) =>
const updateItem = useCallback((id: number, state: Partial<ItemState>) => {
setMap((prev) => ({ ...prev, [id]: { ...prev[id], ...state } }));
}, []);

const messages = useMemo(
() => _messages.filter((m) => m.prompt || m.error || m.text === "DONE"),
Expand All @@ -62,6 +63,17 @@ export function ToolAuthenticationDialog({

const done = messages.at(-1)?.text === "DONE";

useEffect(() => {
if (messages.length === 1) {
const message = messages.at(0);
const authURL = message?.prompt?.metadata?.authURL;
if (authURL) {
window.open(authURL);
updateItem(0, { isLoading: true });
}
}
}, [messages, updateItem]);

return (
<Dialog open={!!threadId} onOpenChange={onComplete}>
<DialogContent className="max-h-[80vh] p-0">
Expand Down

0 comments on commit cf61ef9

Please sign in to comment.