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


##########
providers/common/ai/src/airflow/providers/common/ai/plugins/hitl_review.py:
##########
@@ -0,0 +1,530 @@
+# 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.
+
+from __future__ import annotations
+
+import logging
+from pathlib import Path
+from typing import Annotated
+
+from fastapi import Depends, FastAPI, HTTPException, Query
+from fastapi.responses import HTMLResponse
+from fastapi.staticfiles import StaticFiles
+from sqlalchemy import select
+from sqlalchemy.orm import Session
+
+from airflow.models.taskinstance import TaskInstance as TI
+from airflow.models.xcom import XComModel
+from airflow.plugins_manager import AirflowPlugin
+from airflow.providers.common.ai.utils.hitl_review import (
+    XCOM_AGENT_OUTPUT_PREFIX,
+    XCOM_AGENT_SESSION,
+    XCOM_HUMAN_ACTION,
+    XCOM_HUMAN_FEEDBACK_PREFIX,
+    AgentSessionData,
+    HITLReviewResponse,
+    HumanActionData,
+    HumanFeedbackRequest,
+    SessionStatus,
+)
+from airflow.utils.session import create_session
+
+log = logging.getLogger(__name__)
+
+_PLUGIN_PREFIX = "/hitl-review"
+
+
+def _get_session():
+    with create_session(scoped=False) as session:
+        yield session
+
+
+SessionDep = Annotated[Session, Depends(_get_session, scope="function")]
+
+
+def _get_map_index(q: str = Query("-1", alias="map_index")) -> int:
+    """Parse map_index query; use -1 when placeholder unreplaced (e.g. 
``{MAP_INDEX}``) or invalid."""
+    try:
+        return int(q)
+    except (ValueError, TypeError):
+        return -1
+
+
+MapIndexDep = Annotated[int, Depends(_get_map_index)]
+
+
+def _read_xcom(session: Session, *, dag_id: str, run_id: str, task_id: str, 
map_index: int = -1, key: str):
+    """Read a single XCom value from the database."""
+    row = session.scalars(
+        XComModel.get_many(
+            run_id=run_id,
+            key=key,
+            dag_ids=dag_id,
+            task_ids=task_id,
+            map_indexes=map_index,
+            limit=1,
+        )
+    ).first()
+    if row is None:
+        return None
+    return XComModel.deserialize_value(row)
+
+
+def _read_xcom_by_prefix(

Review Comment:
   updated with checking `SimpleNamespace` does this better?



-- 
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