Files
Artemis-Eapil/apps/admin_console/services/model_service.py
T
somew1nd 9a5aaf99b7 feat: introduce MCP server, cross-platform runtime, and Showcase UI reorganization
- Showcase UI Reorganization:
  * Move web UI dashboard from root directory into apps/showcase_ui/ for cleaner project structure
  * Add 'artemis ui' CLI command (artemis/interfaces/cli/commands/ui.py) and launcher scripts for the interactive showcase console
- Standalone MCP Server & Notifiers (mcp_server/):
  * Implement dedicated MCP server package with mobile automation tools (device_state, inspect_trace, task_manager, task_runner)
  * Add multi-channel notifiers (AgentAPI, Desktop notifications, Webhooks, File output, and Composite routing)
  * Introduce background task runner and trace store for autonomous mobile execution monitoring
- Cross-Platform Runtime & Toolchain Support:
  * Add artemis/platform/ with OS-specific implementations for Linux, macOS (Darwin), and Windows
  * Add artemis/runtime/supervisor.py for resilient process and agent runtime supervision
  * Add artemis/toolchain/ with dependency resolution and SDK descriptors
  * Add cross-platform launcher scripts (start.sh, start.bat) and installer scripts (scripts/install_deps.*)
- Core Enhancements & Diagnostics:
  * Enhance coordinate normalization, OCR API fallback, and perception pipeline
  * Add credential validation (credentials_validator.py) and system diagnostics
  * Update bilingual documentation (README.md, README_CN.md) and architecture diagrams
- Test Suite Expansion:
  * Add integration tests for cloud gateway, remote ADB, and Artemis login
  * Add unit tests covering core diagnostics, platform detection, toolchain, credentials validator, optional OCR, and MCP tools
2026-08-18 13:59:27 -07:00

135 lines
5.0 KiB
Python

# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
from typing import Any
class ModelService:
"""Service handling model profile detection and metadata formatting."""
@staticmethod
def get_active_model_info(profile: str | None = None) -> dict[str, str]:
if profile:
p_lower = str(profile).lower()
if "pro" in p_lower:
return {
"name": "Pro",
"id": "gemini-3.7-pro",
"provider": "google",
}
elif "flash" in p_lower:
return {
"name": "Flash",
"id": "gemini-3.7-flash",
"provider": "google",
}
model_name = "Flash"
model_id = "gemini-3.7-flash"
provider = "google"
try:
from artemis.config import parse_llm_config
llm_cfg = parse_llm_config()
if llm_cfg and llm_cfg.operator:
op_model = str(llm_cfg.operator.model).lower()
provider = str(llm_cfg.operator.provider)
model_id = llm_cfg.operator.model
if "pro" in op_model:
model_name = "Pro"
elif "flash" in op_model:
model_name = "Flash"
else:
model_name = llm_cfg.operator.model.capitalize()
except Exception:
pass
return {"name": model_name, "id": model_id, "provider": provider}
@staticmethod
def resolve_session_profile(
row_dict: dict[str, Any],
llm_trace_payloads: list[str] | None = None,
running_profile: str | None = None,
agent_names: list[str] | None = None,
) -> str | None:
sess_profile = None
d_info_raw = row_dict.get("device_info")
if d_info_raw:
try:
d_info = json.loads(d_info_raw) if isinstance(d_info_raw, str) else d_info_raw
if isinstance(d_info, dict):
p = d_info.get("profile")
if p:
p_str = str(p).lower()
if "pro" in p_str:
return "pro"
elif "flash" in p_str:
return "flash"
except Exception:
pass
if (row_dict.get("status") == "running") and running_profile:
p_str = str(running_profile).lower()
if "pro" in p_str:
return "pro"
elif "flash" in p_str:
return "flash"
# Check Agent/Trace names - the most definitive indicator of architecture
if agent_names:
agent_names_lower = [str(a).lower() for a in agent_names]
if any(
name in ("planner", "validator", "summarizer", "operator", "checker", "diagnoser")
for name in agent_names_lower
):
return "pro"
if any("flashrunner" in name for name in agent_names_lower):
return "flash"
# Check LLM traces for agent name or model overrides
if llm_trace_payloads:
for tr_payload in llm_trace_payloads:
if tr_payload:
try:
p_obj = (
json.loads(tr_payload) if isinstance(tr_payload, str) else tr_payload
)
if isinstance(p_obj, dict):
agent_name = str(p_obj.get("agent") or p_obj.get("name") or "").lower()
if "flashrunner" in agent_name:
return "flash"
if any(
x in agent_name
for x in ("planner", "validator", "operator", "checker")
):
return "pro"
m_str = str(p_obj.get("model") or p_obj.get("model_name") or "").lower()
if (
"gemini-3.7-pro" in m_str
or "gemini-3.6-pro" in m_str
or "gemini-1.5-pro" in m_str
or "gpt-4" in m_str
or "claude" in m_str
):
return "pro"
except Exception:
pass
return None
model_service = ModelService()