using Microsoft.Agents.AI; using Microsoft.Extensions.AI; using OpenAI; using System.ClientModel; /// /// Factory for the Open-Ended Generative UI (minimal) demo agent. /// /// The simplest possible example that exercises the open-ended generative /// UI pipeline. All the interesting work happens outside the agent: /// /// - The CopilotKit runtime's openGenerativeUI flag (see /// src/app/api/copilotkit-ogui/route.ts) auto-injects the /// frontend-registered generateSandboxedUi tool. The LLM sees it /// via the normal AG-UI flow. /// - When the LLM calls generateSandboxedUi, the runtime's /// OpenGenerativeUIMiddleware converts the streaming tool call /// into open-generative-ui activity events that the built-in /// renderer mounts inside a sandboxed iframe. /// /// This is the minimal variant: no sandbox functions, no app-side tools. /// The agent simply asks the LLM to design and emit a single-shot /// sandboxed UI. The "advanced" sibling () /// builds on this with sandbox-to-host function calling via /// openGenerativeUI.sandboxFunctions. /// public class OpenGenUiAgentFactory { private const string DefaultOpenAiEndpoint = "https://models.inference.ai.azure.com"; private const string SystemPrompt = @"You are a UI-generating assistant for an Open Generative UI demo focused on intricate, educational visualisations (3D axes / rotations, neural-network activations, sorting-algorithm walkthroughs, Fourier series, wave interference, planetary orbits, etc.). On every user turn you MUST call the `generateSandboxedUi` frontend tool exactly once. Design a visually polished, self-contained HTML + CSS + SVG widget that *teaches* the requested concept. The frontend injects a detailed ""design skill"" as agent context describing the palette, typography, labelling, and motion conventions expected — follow it closely. Key invariants: - Use inline SVG (or ) for geometric content, not stacks of
s. - Every axis is labelled; every colour-coded series has a legend. - Prefer CSS @keyframes / transitions over setInterval; loop cyclical concepts with animation-iteration-count: infinite. - Motion must teach — animate the actual step of the concept, not decoration. - No fetch / XHR / localStorage — the sandbox has no same-origin access. Output order: - `initialHeight` (typically 480-560 for visualisations) first. - A short `placeholderMessages` array (2-3 lines describing the build). - `css` (complete). - `html` (streams live — keep it tidy). CDN