Files
Dorod-Sky/skyvern/forge/sdk/schemas/task_v2.py

134 lines
4.1 KiB
Python
Raw Normal View History

2024-12-07 12:22:11 -08:00
from datetime import datetime
from enum import StrEnum
2024-12-27 09:04:09 -08:00
from typing import Any
2024-12-07 12:22:11 -08:00
2025-01-15 09:59:18 -08:00
from pydantic import BaseModel, ConfigDict, Field, field_validator
2024-12-19 17:26:08 -08:00
from skyvern.schemas.runs import ProxyLocation
from skyvern.utils.url_validators import validate_url
2024-12-19 17:26:08 -08:00
DEFAULT_WORKFLOW_TITLE = "New Workflow"
2024-12-07 12:22:11 -08:00
class TaskV2Status(StrEnum):
2024-12-07 12:22:11 -08:00
created = "created"
queued = "queued"
running = "running"
failed = "failed"
terminated = "terminated"
canceled = "canceled"
timed_out = "timed_out"
completed = "completed"
2025-02-19 00:58:48 +08:00
def is_final(self) -> bool:
return self in [self.failed, self.terminated, self.canceled, self.timed_out, self.completed]
2024-12-07 12:22:11 -08:00
class TaskV2(BaseModel):
2025-01-15 09:59:18 -08:00
model_config = ConfigDict(from_attributes=True, populate_by_name=True)
2024-12-07 12:22:11 -08:00
2025-01-15 09:59:18 -08:00
observer_cruise_id: str = Field(alias="task_id")
status: TaskV2Status
2024-12-07 12:22:11 -08:00
organization_id: str | None = None
workflow_run_id: str | None = None
workflow_id: str | None = None
workflow_permanent_id: str | None = None
prompt: str | None = None
2025-01-14 13:21:08 -08:00
url: str | None = None
2025-01-10 14:59:53 -08:00
summary: str | None = None
output: dict[str, Any] | list | str | None = None
2025-01-14 13:21:08 -08:00
totp_verification_url: str | None = None
totp_identifier: str | None = None
proxy_location: ProxyLocation | None = None
webhook_callback_url: str | None = None
extracted_information_schema: dict | list | str | None = None
error_code_mapping: dict | None = None
2024-12-07 12:22:11 -08:00
created_at: datetime
modified_at: datetime
2025-01-14 13:21:08 -08:00
@field_validator("url", "webhook_callback_url", "totp_verification_url")
@classmethod
def validate_urls(cls, url: str | None) -> str | None:
if url is None:
return None
return validate_url(url)
2024-12-07 12:22:11 -08:00
class ThoughtType(StrEnum):
2024-12-27 09:04:09 -08:00
plan = "plan"
metadata = "metadata"
user_goal_check = "user_goal_check"
internal_plan = "internal_plan"
class ThoughtScenario(StrEnum):
2024-12-27 09:04:09 -08:00
generate_plan = "generate_plan"
user_goal_check = "user_goal_check"
2025-01-10 14:59:53 -08:00
summarization = "summarization"
2024-12-27 09:04:09 -08:00
generate_metadata = "generate_metadata"
extract_loop_values = "extract_loop_values"
generate_task_in_loop = "generate_task_in_loop"
generate_task = "generate_general_task"
class Thought(BaseModel):
2025-01-15 09:59:18 -08:00
model_config = ConfigDict(from_attributes=True, populate_by_name=True)
2025-01-15 09:59:18 -08:00
observer_thought_id: str = Field(alias="thought_id")
observer_cruise_id: str = Field(alias="task_id")
2024-12-07 12:22:11 -08:00
organization_id: str | None = None
workflow_run_id: str | None = None
workflow_run_block_id: str | None = None
workflow_id: str | None = None
workflow_permanent_id: str | None = None
2024-12-07 12:22:11 -08:00
user_input: str | None = None
observation: str | None = None
thought: str | None = None
answer: str | None = None
observer_thought_type: ThoughtType | None = Field(alias="thought_type", default=ThoughtType.plan)
observer_thought_scenario: ThoughtScenario | None = Field(alias="thought_scenario", default=None)
2024-12-27 09:04:09 -08:00
output: dict[str, Any] | None = None
input_token_count: int | None = None
output_token_count: int | None = None
reasoning_token_count: int | None = None
cached_token_count: int | None = None
thought_cost: float | None = None
2024-12-07 12:22:11 -08:00
created_at: datetime
modified_at: datetime
2024-12-19 17:26:08 -08:00
class TaskV2Metadata(BaseModel):
2024-12-19 17:26:08 -08:00
url: str
workflow_title: str = DEFAULT_WORKFLOW_TITLE
@field_validator("url")
@classmethod
def validate_urls(cls, v: str | None) -> str | None:
if v is None:
return None
return validate_url(v)
class TaskV2Request(BaseModel):
2024-12-19 17:26:08 -08:00
user_prompt: str
url: str | None = None
browser_session_id: str | None = None
webhook_callback_url: str | None = None
totp_verification_url: str | None = None
totp_identifier: str | None = None
2025-01-24 16:21:26 +08:00
proxy_location: ProxyLocation | None = None
publish_workflow: bool = False
extracted_information_schema: dict | list | str | None = None
error_code_mapping: dict[str, str] | None = None
@field_validator("url", "webhook_callback_url", "totp_verification_url")
@classmethod
def validate_urls(cls, url: str | None) -> str | None:
if url is None:
return None
return validate_url(url)