Spaces:
Sleeping
Sleeping
File size: 1,877 Bytes
caf8059 5ca3c16 caf8059 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | """Trusted server configuration. Never accepted in model or run API payloads."""
from typing import Literal
from pydantic import Field, model_validator
from src.modules.skill.domain.models import Contract
class HttpCase(Contract):
path: str = Field(pattern=r'^/[A-Za-z0-9_/?=&.%+-]{0,240}$')
method: Literal['GET', 'POST'] = 'GET'
body: dict | None = None
headers: dict[str, str] = Field(default_factory=dict, max_length=4)
status: int = Field(ge=100, le=599)
expected_json: dict
check: Literal['exact','nonempty-list'] = Field(default='exact',exclude_if=lambda value:value=='exact')
class SandboxConfig(Contract):
image: str = Field(pattern=r'^[a-zA-Z0-9][a-zA-Z0-9./:_-]*@sha256:[a-f0-9]{64}$')
skill_ids: list[str] = Field(min_length=1, max_length=3)
api_contract: str = Field(min_length=1, max_length=4000)
main_class: str = Field(default='demo.App', pattern=r'^[a-zA-Z][a-zA-Z0-9_]*(\.[a-zA-Z][a-zA-Z0-9_]*)*$')
port: int = Field(default=8080, ge=1024, le=65535)
lease_seconds: int = Field(default=300, ge=30, le=900)
command_seconds: int = Field(default=60, ge=1, le=120)
tests: list[HttpCase] = Field(min_length=1, max_length=40)
health: HttpCase
dependency_profile: Literal['jdk', 'pdfbox-3.0.8'] = 'jdk'
dependency_sha512: str | None = None
@model_validator(mode='after')
def paths(self):
from src.modules.execution.pdf_dependency import PROFILE, SHA512
if (self.dependency_profile == 'jdk' and self.dependency_sha512 is not None
or self.dependency_profile == PROFILE and self.dependency_sha512 != SHA512):
raise ValueError('UNAPPROVED_DEPENDENCY_PROFILE')
if any(c.path.startswith('//') or '..' in c.path or '%' in c.path for c in [*self.tests, self.health]):
raise ValueError('UNSAFE_PROBE_PATH')
return self
|