diff --git a/src/api/routes.py b/src/api/routes.py index 4ed4ac9..646cb09 100644 --- a/src/api/routes.py +++ b/src/api/routes.py @@ -18,13 +18,15 @@ from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator from azure.ai.projects.models import AgentVersionObject, AgentReference from openai.types.conversations.message import Message -from openai.types.responses import Response, ResponseOutputText, ResponseOutputMessage, ResponseInputText, ResponseInputMessageItem +from openai.types.responses import ResponseOutputMessage from openai.types.conversations import Conversation -from openai.types.responses.response_output_text import AnnotationFileCitation from azure.ai.projects.aio import AIProjectClient -from openai.types.responses import ResponseTextDeltaEvent, ResponseCompletedEvent, ResponseTextDoneEvent, ResponseCreatedEvent, ResponseOutputItemDoneEvent +from util import encode_project_resource_id + +from urllib.parse import quote + from openai import AsyncOpenAI @@ -289,7 +291,13 @@ async def history( async def get_chat_agent( agent: AgentVersionObject = Depends(get_agent_version_obj), ): - return JSONResponse(content={"name": agent.name, "metadata": agent.metadata}) + wsid = os.environ.get("AZURE_EXISTING_AIPROJECT_RESOURCE_ID") + agent_id = os.environ.get("AZURE_EXISTING_AGENT_ID") + agent_name = agent_id.split(":")[0] + agent_version = agent_id.split(":")[1] + agent_playground_url = f"https://ai.azure.com/nextgen/r/{encode_project_resource_id(wsid)}/build/agents/{quote(agent_name)}/build?version={agent_version}" + return JSONResponse(content={"name": agent.name, "metadata": agent.metadata, "agentPlaygroundUrl": agent_playground_url}) + @router.post("/chat") async def chat( @@ -338,40 +346,3 @@ async def chat( response.set_cookie("conversation_id", conversation_id) response.set_cookie("agent_id", agent_id) return response - -def read_file(path: str) -> str: - with open(path, 'r') as file: - return file.read() - -@router.get("/config/azure") -async def get_azure_config(_ = auth_dependency): - """Get Azure configuration for frontend use""" - try: - subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "") - tenant_id = os.environ.get("AZURE_TENANT_ID", "") - resource_group = os.environ.get("AZURE_RESOURCE_GROUP", "") - ai_project_resource_id = os.environ.get("AZURE_EXISTING_AIPROJECT_RESOURCE_ID", "") - - # Extract resource name and project name from the resource ID - # Format: /subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.CognitiveServices/accounts/{resource}/projects/{project} - resource_name = "" - project_name = "" - - if ai_project_resource_id: - parts = ai_project_resource_id.split("/") - if len(parts) >= 8: - resource_name = parts[8] # accounts/{resource_name} - if len(parts) >= 10: - project_name = parts[10] # projects/{project_name} - - return JSONResponse({ - "subscriptionId": subscription_id, - "tenantId": tenant_id, - "resourceGroup": resource_group, - "resourceName": resource_name, - "projectName": project_name, - "wsid": ai_project_resource_id - }) - except Exception as e: - logger.error(f"Error getting Azure config: {e}") - raise HTTPException(status_code=500, detail="Failed to get Azure configuration") \ No newline at end of file diff --git a/src/frontend/src/components/App.tsx b/src/frontend/src/components/App.tsx index 38ba98c..796cb84 100644 --- a/src/frontend/src/components/App.tsx +++ b/src/frontend/src/components/App.tsx @@ -14,6 +14,7 @@ const App: React.FC = () => { metadata: { logo: "robot", }, + agentPlaygroundUrl: "", }); // Fetch agent details when component mounts @@ -52,6 +53,7 @@ const App: React.FC = () => { metadata: { logo: "robot", }, + agentPlaygroundUrl: "", }); } } catch (error) { @@ -67,6 +69,7 @@ const App: React.FC = () => { metadata: { logo: "robot", }, + agentPlaygroundUrl: "", }); } }; diff --git a/src/frontend/src/components/agents/AgentPreview.tsx b/src/frontend/src/components/agents/AgentPreview.tsx index 07ea759..10e17f9 100644 --- a/src/frontend/src/components/agents/AgentPreview.tsx +++ b/src/frontend/src/components/agents/AgentPreview.tsx @@ -15,8 +15,7 @@ import { AgentPreviewChatBot } from "./AgentPreviewChatBot"; import { MenuButton } from "../core/MenuButton/MenuButton"; import { IChatItem } from "./chatbot/types"; import { Waves } from "./Waves"; -/* temporarily disable BuiltWithBadge */ -// import { BuiltWithBadge } from "./BuiltWithBadge"; +import { BuiltWithBadge } from "./BuiltWithBadge"; import styles from "./AgentPreview.module.css"; @@ -39,6 +38,7 @@ interface IAgent { }; metadata?: Record; response_format?: "auto" | string; + agentPlaygroundUrl: string; } interface IAgentPreviewProps { @@ -601,8 +601,11 @@ export function AgentPreview({ agentDetails }: IAgentPreviewProps): ReactNode { )} - {/* temporarily disable BuiltWithBadge */} - {/* */} + {agentDetails.agentPlaygroundUrl && agentDetails.agentPlaygroundUrl.length > 0 ? ( + + ) : ( + <> + )} {/* Settings Panel */} diff --git a/src/frontend/src/components/agents/BuiltWithBadge.tsx b/src/frontend/src/components/agents/BuiltWithBadge.tsx index 0f478b1..b709e1a 100644 --- a/src/frontend/src/components/agents/BuiltWithBadge.tsx +++ b/src/frontend/src/components/agents/BuiltWithBadge.tsx @@ -1,4 +1,4 @@ -import { ReactNode, useEffect, useState } from "react"; +import { ReactNode } from "react"; import { Caption1Strong } from "@fluentui/react-components"; import { ArrowRight16Filled } from "@fluentui/react-icons"; import clsx from "clsx"; @@ -6,50 +6,16 @@ import clsx from "clsx"; import { AIFoundryLogo } from "../icons/AIFoundryLogo"; import styles from "./BuiltWithBadge.module.css"; -interface AzureConfig { - subscriptionId: string; - tenantId: string; - resourceGroup: string; - resourceName: string; - projectName: string; - wsid: string; -} - export function BuiltWithBadge({ className, + agentPlaygroundUrl }: { className?: string; + agentPlaygroundUrl?: string; }): ReactNode { - const [azureConfig, setAzureConfig] = useState(null); - - useEffect(() => { - const fetchAzureConfig = async () => { - try { - const response = await fetch("/config/azure"); - if (response.ok) { - const config = await response.json(); - setAzureConfig(config); - } else { - console.error("Failed to fetch Azure configuration"); - } - } catch (error) { - console.error("Error fetching Azure configuration:", error); - } - }; - - fetchAzureConfig(); - }, []); const handleClick = () => { - if (azureConfig) { - const { wsid, tenantId } = azureConfig; - const azureAiUrl = `https://ai.azure.com/resource/agentsList?wsid=${encodeURIComponent( - wsid - )}&tid=${tenantId}`; - window.open(azureAiUrl, "_blank"); - } else { - console.log("Azure configuration not available"); - } + window.open(agentPlaygroundUrl, "_blank"); }; return (