Use Claude Code, Codex, VSCode, Pi, and OpenCode (and 6 other harnesses) for free (1.3B+ free tokens) from your terminal, app, IDE, or phone, and now from the browser with native browser sessions (multi-harness + multi-model) like OpenClaw (voice supported + ToS friendly)
Python
Added mocking for suggestion mode and file path extraction
Alishahryar181d41fb6d56f
diff --git a/.env.example b/.env.exampleindex 44c3f979..f0fdf114 100644--- a/.env.example+++ b/.env.example@@ -9,6 +9,8 @@ ALLOWED_DIR=""FAST_PREFIX_DETECTION=trueENABLE_NETWORK_PROBE_MOCK=trueENABLE_TITLE_GENERATION_SKIP=true+ENABLE_SUGGESTION_MODE_SKIP=true+ENABLE_FILEPATH_EXTRACTION_MOCK=true# Telegram Configdiff --git a/api/request_utils.py b/api/request_utils.pyindex 5c5e5790..ba63b3bf 100644--- a/api/request_utils.py+++ b/api/request_utils.py@@ -175,6 +175,170 @@ def is_prefix_detection_request(request_data: MessagesRequest) -> Tuple[bool, streturn False, ""+def is_suggestion_mode_request(request_data: MessagesRequest) -> bool:+ """Check if this is a suggestion mode request.++ Suggestion mode requests contain "[SUGGESTION MODE:" in the user's message,+ used for auto-suggesting what the user might type next.++ Args:+ request_data: The incoming request data++ Returns:+ True if this is a suggestion mode request+ """+ for msg in request_data.messages:+ if msg.role == "user":+ content = msg.content+ target = "[SUGGESTION MODE:"+ if isinstance(content, str) and target in content:+ return True+ elif isinstance(content, list):+ for block in content:+ text = getattr(block, "text", "")+ if text and isinstance(text, str) and target in text:+ return True+ return False+++def is_filepath_extraction_request(+ request_data: MessagesRequest,+) -> Tuple[bool, str, str]:+ """Check if this is a filepath extraction request.++ Filepath extraction requests have a single user message with+ "Command:" and "Output:" sections, asking to extract file paths+ from command output.++ Args:+ request_data: The incoming request data++ Returns:+ Tuple of (is_filepath_request, command, output)+ """+ # Must be single message, no tools+ if len(request_data.messages) != 1 or request_data.messages[0].role != "user":+ return False, "", ""+ if request_data.tools:+ return False, "", ""++ msg = request_data.messages[0]+ content = ""+ if isinstance(msg.content, str):+ content = msg.content+ elif isinstance(msg.content, list):+ for block in msg.content:+ text = getattr(block, "text", "")+ if text and isinstance(text, str):+ content += text++ # Must have Command: and Output: markers+ if "Command:" not in content or "Output:" not in content:+ return False, "", ""++ # Must ask for filepath extraction+ if "filepaths" not in content.lower() and "<filepaths>" not in content.lower():+ return False, "", ""++ try:+ # Extract command and output+ cmd_start = content.find("Command:") + len("Command:")+ output_marker = content.find("Output:", cmd_start)+ if output_marker == -1:+ return False, "", ""++ command = content[cmd_start:output_marker].strip()+ output = content[output_marker + len("Output:") :].strip()++ # Clean up output - stop at next section marker if present+ for marker in ["<", "\n\n"]:+ if marker in output:+ output = output.split(marker)[0].strip()++ return True, command, output+ except Exception:+ return False, "", ""+++def extract_filepaths_from_command(command: str, output: str) -> str:+ """Extract file paths from a command locally without API call.++ Determines if the command reads file contents and extracts paths accordingly.+ Commands like ls/dir/find just list files, so return empty.+ Commands like cat/head/tail actually read contents, so extract the file path.++ Args:+ command: The shell command that was executed+ output: The command's output++ Returns:+ Filepath extraction result in <filepaths> format+ """+ import shlex++ # Commands that just list files (don't read contents)+ listing_commands = {"ls", "dir", "find", "tree", "pwd", "cd", "mkdir", "rmdir", "rm"}++ # Commands that read file contents+ reading_commands = {"cat", "head", "tail", "less", "more", "bat", "type"}++ try:+ parts = shlex.split(command)+ if not parts:+ return "<filepaths>\n</filepaths>"++ # Get base command (handle paths like /bin/cat)+ base_cmd = parts[0].split("/")[-1].split("\\")[-1].lower()++ # Listing commands - return empty+ if base_cmd in listing_commands:+ return "<filepaths>\n</filepaths>"++ # Reading commands - extract file arguments+ if base_cmd in reading_commands:+ filepaths = []+ for part in parts[1:]:+ # Skip flags+ if part.startswith("-"):+ continue+ # This is likely a file path+ filepaths.append(part)++ if filepaths:+ paths_str = "\n".join(filepaths)+ return f"<filepaths>\n{paths_str}\n</filepaths>"+ return "<filepaths>\n</filepaths>"++ # grep with file argument+ if base_cmd == "grep":+ filepaths = []+ skip_next = False+ for i, part in enumerate(parts[1:], 1):+ if skip_next:+ skip_next = False+ continue+ # Skip flags and their arguments+ if part.startswith("-"):+ # Flags that take an argument+ if part in {"-e", "-f", "-m", "-A", "-B", "-C"}:+ skip_next = True+ continue+ # First non-flag is pattern, rest are files+ if i > 1: # Skip the pattern+ filepaths.append(part)++ if filepaths:+ paths_str = "\n".join(filepaths)+ return f"<filepaths>\n{paths_str}\n</filepaths>"+ return "<filepaths>\n</filepaths>"++ # Default - return empty for unknown commands+ return "<filepaths>\n</filepaths>"++ except Exception:+ return "<filepaths>\n</filepaths>"++def get_token_count(messages: List,system: Optional[Union[str, List]] = None,diff --git a/api/routes.py b/api/routes.pyindex b2c9453a..c94e1263 100644--- a/api/routes.py+++ b/api/routes.py@@ -18,7 +18,10 @@ from .request_utils import (is_quota_check_request,is_title_generation_request,is_prefix_detection_request,+ is_suggestion_mode_request,+ is_filepath_extraction_request,extract_command_prefix,+ extract_filepaths_from_command,get_token_count,)from config.settings import Settings@@ -83,6 +86,35 @@ async def create_message(usage=Usage(input_tokens=100, output_tokens=5),)+ # Optimization: Skip suggestion mode requests+ if settings.enable_suggestion_mode_skip and is_suggestion_mode_request(+ request_data+ ):+ logger.info("Optimization: Skipped suggestion mode request")+ return MessagesResponse(+ id=f"msg_{uuid.uuid4()}",+ model=request_data.model,+ role="assistant",+ content=[{"type": "text", "text": ""}],+ stop_reason="end_turn",+ usage=Usage(input_tokens=100, output_tokens=1),+ )++ # Optimization: Mock filepath extraction requests+ if settings.enable_filepath_extraction_mock:+ is_fp, cmd, output = is_filepath_extraction_request(request_data)+ if is_fp:+ filepaths = extract_filepaths_from_command(cmd, output)+ logger.info("Optimization: Mocked filepath extraction")+ return MessagesResponse(+ id=f"msg_{uuid.uuid4()}",+ model=request_data.model,+ role="assistant",+ content=[{"type": "text", "text": filepaths}],+ stop_reason="end_turn",+ usage=Usage(input_tokens=100, output_tokens=10),+ )+request_id = f"req_{uuid.uuid4().hex[:12]}"log_request_compact(logger, request_id, request_data)diff --git a/config/settings.py b/config/settings.pyindex 8d89ea2c..ff72d535 100644--- a/config/settings.py+++ b/config/settings.py@@ -32,6 +32,8 @@ class Settings(BaseSettings):# ==================== Optimizations ====================enable_network_probe_mock: bool = Trueenable_title_generation_skip: bool = True+ enable_suggestion_mode_skip: bool = True+ enable_filepath_extraction_mock: bool = True# ==================== NIM Core Parameters ====================nvidia_nim_temperature: float = 1.0