gopidesupavan commented on code in PR #63081:
URL: https://github.com/apache/airflow/pull/63081#discussion_r2901678120


##########
providers/common/ai/src/airflow/providers/common/ai/plugins/www/src/main.tsx:
##########
@@ -0,0 +1,59 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { StrictMode, type FC } from "react";
+import { createRoot } from "react-dom/client";
+
+import { ChatPage } from "src/components/ChatPage";
+import { NoSession } from "src/components/NoSession";
+
+export type PluginComponentProps = object;
+
+/**
+ * Main plugin component.
+ *
+ * Reads dag_id / run_id / task_id from the URL search params injected by
+ * the Airflow external_views iframe.  If parameters are missing it shows
+ * the "no session" fallback.
+ */
+const PluginComponent: FC<PluginComponentProps> = () => {
+  const params = new URLSearchParams(globalThis.location.search);
+  const dagId = params.get("dag_id") ?? "";
+  const runId = (params.get("run_id") ?? "").replace(/ /g, "+");

Review Comment:
   Core UI seemed to have an issue with the iframe: 
https://github.com/apache/airflow/pull/63081/changes#diff-88add5debbebdac6e545be3bd3f6c62d350b55223a903562aaa8c6527aff9597R41
   . I’ve updated it now, but that change can’t be used for AF 3.1. So I’ll 
keep this check as it is, and I’ve removed the replace option from the Plugin 
API.



##########
providers/common/ai/src/airflow/providers/common/ai/plugins/www/src/components/ChatPage.tsx:
##########
@@ -0,0 +1,290 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import {
+  type FC,
+  type KeyboardEvent,
+  useCallback,
+  useEffect,
+  useRef,
+  useState,
+} from "react";
+
+import { MessageBubble } from "src/components/MessageBubble";
+import { NoSession } from "src/components/NoSession";
+import { useSession } from "src/hooks/useSession";
+
+import styles from "./ChatPage.module.css";
+
+interface ChatPageProps {
+  dagId: string;
+  runId: string;
+  taskId: string;
+  mapIndex: number;
+}
+
+type ConfirmAction = "approve" | "reject" | null;
+
+const STATUS_BADGE: Record<string, { cls: string; label: string }> = {
+  pending_review: { cls: styles.badgePending!, label: "Pending Review" },
+  approved: { cls: styles.badgeApproved!, label: "Approved" },
+  rejected: { cls: styles.badgeRejected!, label: "Rejected" },
+  changes_requested: { cls: styles.badgeChanges!, label: "Regenerating..." },
+};
+
+export const ChatPage: FC<ChatPageProps> = ({ dagId, runId, taskId, mapIndex 
}) => {
+  const { session, error, loading, taskActive, sendFeedback, approve, reject } 
=
+    useSession(dagId, runId, taskId, mapIndex);
+
+  const [feedbackText, setFeedbackText] = useState("");
+  const [confirmAction, setConfirmAction] = useState<ConfirmAction>(null);
+  const [toast, setToast] = useState<{ msg: string; ok: boolean } | 
null>(null);
+  const chatRef = useRef<HTMLDivElement>(null);
+  const textareaRef = useRef<HTMLTextAreaElement>(null);
+
+  useEffect(() => {
+    if (chatRef.current) {
+      chatRef.current.scrollTop = chatRef.current.scrollHeight;
+    }
+  }, [session?.conversation]);
+
+  useEffect(() => {
+    if (toast) {
+      const t = setTimeout(() => setToast(null), 3000);
+      return () => clearTimeout(t);
+    }
+  }, [toast]);
+
+  const autoResize = useCallback(() => {
+    const ta = textareaRef.current;
+    if (ta) {
+      ta.style.height = "auto";
+      ta.style.height = `${ta.scrollHeight}px`;
+    }
+  }, []);
+
+  const handleSend = useCallback(async () => {
+    const text = feedbackText.trim();
+    if (!text) return;
+    try {
+      await sendFeedback(text);
+      setFeedbackText("");
+      setToast({ msg: "Feedback sent", ok: true });
+    } catch (err) {
+      setToast({ msg: err instanceof Error ? err.message : "Error", ok: false 
});
+    }
+  }, [feedbackText, sendFeedback]);
+
+  const handleKeyDown = useCallback(
+    (e: KeyboardEvent) => {
+      if (e.ctrlKey && e.key === "Enter") {
+        void handleSend();
+      }
+    },
+    [handleSend],
+  );
+
+  const execConfirm = useCallback(async () => {
+    const action = confirmAction;
+    setConfirmAction(null);
+    try {
+      if (action === "approve") {
+        await approve();
+        setToast({ msg: "Approved", ok: true });
+      } else if (action === "reject") {
+        await reject();
+        setToast({ msg: "Rejected", ok: true });
+      }
+    } catch (err) {
+      setToast({ msg: err instanceof Error ? err.message : "Error", ok: false 
});
+    }
+  }, [confirmAction, approve, reject]);
+
+  if (loading) {
+    return (
+      <div className={styles.placeholder}>
+        <div className={styles.placeholderCard}>
+          <div className={styles.spinner} />
+          <h2 className={styles.placeholderHeading}>Connecting to session</h2>
+          <p className={styles.placeholderDesc}>
+            Looking up the HITL review session for this task...
+          </p>
+        </div>
+      </div>
+    );

Review Comment:
   updated 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to