- harness/es.py: append-only event store + проекции (образец — кооп-портал) - harness/levels.py: уровни 1с/1м/1ч/1д, контекст ∝ масштабу - harness/scheduler.py: уровневые потоки, идемпотентные тики, absorbed-стабы - harness/isolated_runner.py + _llm_worker.py: LLM-тик в сабпроцессе (глобальный asyncio-рантайм Strands не переживает 2+ create_harness) - cli.py: init/task/tasks/status/events + requeue (написан самим минутным агентом) - 9router: отдельный ключ sk-simbiot, модель auto (glm-5.3 первым)
43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
"""Base classes and interfaces for MCPServer resources."""
|
|
|
|
import abc
|
|
from typing import Any
|
|
|
|
from mcp_types import Annotations, Icon
|
|
from pydantic import (
|
|
BaseModel,
|
|
ConfigDict,
|
|
Field,
|
|
ValidationInfo,
|
|
field_validator,
|
|
)
|
|
|
|
|
|
class Resource(BaseModel, abc.ABC):
|
|
"""Base class for all resources."""
|
|
|
|
model_config = ConfigDict(validate_default=True, extra="forbid")
|
|
|
|
uri: str = Field(default=..., description="URI of the resource")
|
|
name: str | None = Field(description="Name of the resource", default=None)
|
|
title: str | None = Field(description="Human-readable title of the resource", default=None)
|
|
description: str | None = Field(description="Description of the resource", default=None)
|
|
mime_type: str = Field(default="text/plain", description="MIME type of the resource content")
|
|
icons: list[Icon] | None = Field(default=None, description="Optional list of icons for this resource")
|
|
annotations: Annotations | None = Field(default=None, description="Optional annotations for the resource")
|
|
meta: dict[str, Any] | None = Field(default=None, description="Optional metadata for this resource")
|
|
|
|
@field_validator("name", mode="before")
|
|
@classmethod
|
|
def set_default_name(cls, name: str | None, info: ValidationInfo) -> str:
|
|
"""Set default name from URI if not provided."""
|
|
if name:
|
|
return name
|
|
if uri := info.data.get("uri"):
|
|
return str(uri)
|
|
raise ValueError("Either name or uri must be provided")
|
|
|
|
@abc.abstractmethod
|
|
async def read(self) -> str | bytes:
|
|
"""Read the resource content."""
|
|
pass # pragma: no cover
|