""" title: GitHub Copilot Official SDK Pipe author: Fu-Jie author_url: https://github.com/Fu-Jie/awesome-openwebui funding_url: https://github.com/open-webui openwebui_id: ce96f7b4-12fc-4ac3-9a01-875713e69359 description: Integrate GitHub Copilot SDK. Supports dynamic models, multi-turn conversation, streaming, multimodal input, infinite sessions, and frontend debug logging. version: 0.5.1 requirements: github-copilot-sdk==0.1.23 """ import os import re import json import base64 import tempfile import asyncio import logging import shutil import subprocess import hashlib import aiohttp from pathlib import Path from typing import Optional, Union, AsyncGenerator, List, Any, Dict, Literal, Tuple from types import SimpleNamespace from pydantic import BaseModel, Field, create_model # Import copilot SDK modules from copilot import CopilotClient, define_tool # Import Tool Server Connections and Tool System from OpenWebUI Config from open_webui.config import ( PERSISTENT_CONFIG_REGISTRY, TOOL_SERVER_CONNECTIONS, ) from open_webui.utils.tools import get_tools as get_openwebui_tools, get_builtin_tools from open_webui.models.tools import Tools from open_webui.models.users import Users # Setup logger logger = logging.getLogger(__name__) FORMATTING_GUIDELINES = ( "\n\n[Environment & Capabilities Context]\n" "You are an AI assistant operating within a specific, high-capability environment. Understanding your context is crucial for optimal decision-making.\n" "\n" "**System Environment:**\n" "- **Platform**: You are running inside a Linux containerized environment hosted within **OpenWebUI**.\n" "- **Core Engine**: You are powered by the **GitHub Copilot SDK** and interact via the **GitHub Copilot CLI**.\n" "- **Access**: You have direct access to the **OpenWebUI source code**. You can read, analyze, and reference the internal implementation of the platform you are running on via file operations or tools.\n" "- **FileSystem Access**: You are running as **root**. You have **READ access to the entire container file system** (including system files). However, you should **ONLY WRITE** to your designated persistent workspace directory.\n" "- **Native Python Environment**: You are running in a **rich Python environment** that already includes all OpenWebUI dependencies. You can natively import and use these installed libraries (e.g., for data processing, utility functions) without installing anything new.\n" "- **Package Management**: Only if you need **additional** libraries, you should **create a virtual environment** within your workspace and install them there. Do NOT mess with the global pip.\n" "- **Network**: You have internet access and can interact with external APIs if provided with the necessary tools (e.g., Web Search, MCP Servers).\n" "\n" "**Interface Capabilities (OpenWebUI):**\n" "- **Rich Web UI**: You are NOT limited to a simple terminal or text-only responses. You are rendering in a modern web browser.\n" "- **Visual Rendering**: You can and should use advanced visual elements to explain concepts clearly.\n" "- **Interactive Scripting**: You can often run Python scripts directly to perform calculations, data analysis, or automate tasks if the environment supports it/tools are available.\n" "- **Built-in Tools Integration**: OpenWebUI provides native tools for direct interaction with its internal services. For example, tools like `create_note`, `get_notes`, or `manage_memories` interact directly with the platform's database. Use these tools to persistently manage user data and system state.\n" "\n" "**Formatting & Presentation Directives:**\n" "1. **Markdown & Multimedia**:\n" " - Use **bold**, *italics*, lists, and **Markdown tables** (standard format, never use HTML tables) liberally to structure your answer.\n" " - **Mermaid Diagrams**: For flowcharts, sequence diagrams, or architecture logic, ALWAYS use the standard ```mermaid code block. Do NOT use other formats.\n" " - **LaTeX Math**: Use standard LaTeX formatting for mathematical expressions.\n" "\n" "2. **Images & Files**:\n" " - If a tool generated an image or file, you **MUST** embed it directly using `![caption](url)`.\n" " - Do NOT simply provide a text link unless explicitly asked.\n" "\n" "3. **Interactive HTML/JS**:\n" " - You can output standalone HTML/JS/CSS code blocks. OpenWebUI will render them as interactive widgets in an iframe.\n" " - **IMPORTANT**: Combine all HTML, CSS (in `