"""Mock OpenAI-compatible LLM server for E2E tests. Serves OpenAI-compatible endpoints for chat completions and model listing. Supports both streaming and non-streaming responses, plus function calling via TOOL_CALL_PATTERNS. """ import argparse import asyncio import json import re import time import uuid from aiohttp import web CANNED_RESPONSES = [ (re.compile(r"hello|hi|hey", re.IGNORECASE), "Hello! How can I help you today?"), (re.compile(r"2\s*\+\s*2|two plus two", re.IGNORECASE), "The answer is 4."), (re.compile(r"skill|install", re.IGNORECASE), "I can help you with skills management."), (re.compile(r"html.?test|injection.?test", re.IGNORECASE), 'Here is some content: and ' ' and end of content.'), ] DEFAULT_RESPONSE = "I understand your request." TOOL_CALL_PATTERNS = [ (re.compile(r"echo (.+)", re.IGNORECASE), "echo", lambda m: {"message": m.group(1)}), ( re.compile(r"make approval post (?P