Spaces:
Sleeping
Sleeping
Download src/schemas/task.py from arimatch1/crewhub-worker: direct link, hf CLI and curl.
- Browser
- Download file 4.83 kB
-
https://huggingface.co/spaces/arimatch1/crewhub-worker/resolve/main/src/schemas/task.py
- Command line
-
hf download hf://spaces/arimatch1/crewhub-worker/src/schemas/task.py
-
curl -L -o task.py https://huggingface.co/spaces/arimatch1/crewhub-worker/resolve/main/src/schemas/task.py
4.83 kB
| # Copyright (c) 2026 CrewHub. All rights reserved. | |
| # Proprietary and confidential. See LICENSE for details. | |
| from enum import Enum | |
| from uuid import UUID | |
| from datetime import datetime | |
| from typing import Optional | |
| from pydantic import BaseModel, ConfigDict, Field, model_validator | |
| class TaskStatus(str, Enum): | |
| submitted = "submitted" | |
| pending_approval = "pending_approval" | |
| pending_payment = "pending_payment" | |
| working = "working" | |
| input_required = "input_required" | |
| completed = "completed" | |
| failed = "failed" | |
| canceled = "canceled" | |
| rejected = "rejected" | |
| class PaymentMethod(str, Enum): | |
| credits = "credits" | |
| x402 = "x402" | |
| class MessagePart(BaseModel): | |
| type: str = Field(max_length=50, pattern=r"^[a-z][a-z0-9_]*$") # text, file, data | |
| content: Optional[str] = Field(None, max_length=100_000) | |
| text: Optional[str] = Field(None, max_length=100_000, exclude=True) | |
| data: Optional[dict] = None | |
| mime_type: Optional[str] = Field(None, max_length=100) | |
| def _accept_text_field(cls, values): | |
| """Accept A2A-spec 'text' field as alias for 'content'.""" | |
| if isinstance(values, dict): | |
| if values.get("text") and not values.get("content"): | |
| values["content"] = values["text"] | |
| return values | |
| class TaskMessage(BaseModel): | |
| role: str = Field(max_length=50, pattern=r"^[a-z][a-z0-9_]*$") | |
| parts: list[MessagePart] = Field(max_length=100) | |
| class UIComponent(BaseModel): | |
| """A2UI rich component — rendered by the frontend instead of plain markdown. | |
| Supported types: table, chart, code_block, diff, image, form, calendar. | |
| """ | |
| type: str = Field(max_length=50) # table, chart, code_block, diff, image, form, calendar | |
| title: Optional[str] = Field(None, max_length=255) | |
| data: dict = Field(default_factory=dict) | |
| metadata: dict = Field(default_factory=dict) | |
| class Artifact(BaseModel): | |
| name: Optional[str] = Field(None, max_length=255) | |
| parts: list[MessagePart] = Field(max_length=100) | |
| metadata: dict = Field(default_factory=dict, max_length=50) | |
| ui_components: list[UIComponent] = Field(default_factory=list, max_length=20) | |
| class TaskCreate(BaseModel): | |
| provider_agent_id: UUID | |
| skill_id: str = Field(max_length=255) | |
| messages: list[TaskMessage] = Field(max_length=50) | |
| max_credits: Optional[float] = Field(None, ge=0, le=100_000) | |
| tier: Optional[str] = Field(None, max_length=50, description="Pricing tier name (e.g. 'free', 'pro')") | |
| payment_method: PaymentMethod = PaymentMethod.credits | |
| validate_match: bool = Field(False, description="If true, check message-skill alignment and return a warning if mismatched") | |
| confirmed: bool = Field(False, description="If true, bypass high-cost approval check") | |
| # Delegation tracking (set by frontend when using auto-delegation) | |
| parent_task_id: Optional[UUID] = None | |
| suggested_agent_id: Optional[UUID] = None | |
| suggestion_confidence: Optional[float] = Field(None, ge=0, le=1) | |
| # AP2: Idempotency — prevents duplicate task creation on retries | |
| idempotency_key: Optional[str] = Field( | |
| None, max_length=64, | |
| description="Client-provided key for idempotent task creation. " | |
| "If a task with this key already exists for this user, " | |
| "the existing task is returned instead of creating a new one." | |
| ) | |
| class TaskResponse(BaseModel): | |
| model_config = ConfigDict(from_attributes=True) | |
| id: UUID | |
| client_agent_id: Optional[UUID] = None | |
| provider_agent_id: Optional[UUID] = None | |
| provider_agent_name: Optional[str] = None | |
| skill_id: Optional[str | UUID] = None | |
| skill_name: Optional[str] = None | |
| status: TaskStatus | |
| messages: list[TaskMessage] | |
| artifacts: list[Artifact] | |
| credits_quoted: Optional[float] = 0 | |
| credits_charged: Optional[float] = 0 | |
| latency_ms: Optional[int] = None | |
| client_rating: Optional[float] = None | |
| payment_method: str = "credits" | |
| x402_receipt: Optional[dict] = None | |
| status_history: list[dict] = [] | |
| quality_score: Optional[float] = None | |
| eval_model: Optional[str] = None | |
| eval_relevance: Optional[float] = None | |
| eval_completeness: Optional[float] = None | |
| eval_coherence: Optional[float] = None | |
| delegation_warning: Optional[str] = None | |
| delegation_depth: int = 0 | |
| parent_task_id: Optional[UUID] = None | |
| suggested_agent_id: Optional[UUID] = None | |
| suggestion_confidence: Optional[float] = None | |
| idempotency_key: Optional[str] = None | |
| created_at: datetime | |
| completed_at: Optional[datetime] = None | |
| class TaskRating(BaseModel): | |
| score: float = Field(ge=1, le=5) | |
| comment: str = Field("", max_length=2000) | |
| class TaskListResponse(BaseModel): | |
| tasks: list[TaskResponse] | |
| total: int | |