Files
2025-10-02 20:13:20 -04:00

178 lines
7.2 KiB
Python

# coding: utf-8
"""
goose-server
An AI agent
The version of the OpenAPI document: 1.9.0
Contact: ai-oss-tools@block.xyz
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
""" # noqa: E501
from __future__ import annotations
import pprint
import re # noqa: F401
import json
from datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from goose_api.models.message import Message
from goose_api.models.recipe import Recipe
from typing import Optional, Set
from typing_extensions import Self
class Session(BaseModel):
"""
Session
""" # noqa: E501
accumulated_input_tokens: Optional[StrictInt] = None
accumulated_output_tokens: Optional[StrictInt] = None
accumulated_total_tokens: Optional[StrictInt] = None
conversation: Optional[List[Message]] = None
created_at: datetime
description: StrictStr
extension_data: Dict[str, Any] = Field(description="Extension data containing all extension states Keys are in format \"extension_name.version\" (e.g., \"todo.v0\")")
id: StrictStr
input_tokens: Optional[StrictInt] = None
message_count: Annotated[int, Field(strict=True, ge=0)]
output_tokens: Optional[StrictInt] = None
recipe: Optional[Recipe] = None
schedule_id: Optional[StrictStr] = None
total_tokens: Optional[StrictInt] = None
updated_at: datetime
working_dir: StrictStr
__properties: ClassVar[List[str]] = ["accumulated_input_tokens", "accumulated_output_tokens", "accumulated_total_tokens", "conversation", "created_at", "description", "extension_data", "id", "input_tokens", "message_count", "output_tokens", "recipe", "schedule_id", "total_tokens", "updated_at", "working_dir"]
model_config = ConfigDict(
populate_by_name=True,
validate_assignment=True,
protected_namespaces=(),
)
def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.model_dump(by_alias=True))
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
return json.dumps(self.to_dict())
@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
"""Create an instance of Session from a JSON string"""
return cls.from_dict(json.loads(json_str))
def to_dict(self) -> Dict[str, Any]:
"""Return the dictionary representation of the model using alias.
This has the following differences from calling pydantic's
`self.model_dump(by_alias=True)`:
* `None` is only added to the output dict for nullable fields that
were set at model initialization. Other fields with value `None`
are ignored.
"""
excluded_fields: Set[str] = set([
])
_dict = self.model_dump(
by_alias=True,
exclude=excluded_fields,
exclude_none=True,
)
# override the default output from pydantic by calling `to_dict()` of each item in conversation (list)
_items = []
if self.conversation:
for _item_conversation in self.conversation:
if _item_conversation:
_items.append(_item_conversation.to_dict())
_dict['conversation'] = _items
# override the default output from pydantic by calling `to_dict()` of recipe
if self.recipe:
_dict['recipe'] = self.recipe.to_dict()
# set to None if accumulated_input_tokens (nullable) is None
# and model_fields_set contains the field
if self.accumulated_input_tokens is None and "accumulated_input_tokens" in self.model_fields_set:
_dict['accumulated_input_tokens'] = None
# set to None if accumulated_output_tokens (nullable) is None
# and model_fields_set contains the field
if self.accumulated_output_tokens is None and "accumulated_output_tokens" in self.model_fields_set:
_dict['accumulated_output_tokens'] = None
# set to None if accumulated_total_tokens (nullable) is None
# and model_fields_set contains the field
if self.accumulated_total_tokens is None and "accumulated_total_tokens" in self.model_fields_set:
_dict['accumulated_total_tokens'] = None
# set to None if conversation (nullable) is None
# and model_fields_set contains the field
if self.conversation is None and "conversation" in self.model_fields_set:
_dict['conversation'] = None
# set to None if input_tokens (nullable) is None
# and model_fields_set contains the field
if self.input_tokens is None and "input_tokens" in self.model_fields_set:
_dict['input_tokens'] = None
# set to None if output_tokens (nullable) is None
# and model_fields_set contains the field
if self.output_tokens is None and "output_tokens" in self.model_fields_set:
_dict['output_tokens'] = None
# set to None if recipe (nullable) is None
# and model_fields_set contains the field
if self.recipe is None and "recipe" in self.model_fields_set:
_dict['recipe'] = None
# set to None if schedule_id (nullable) is None
# and model_fields_set contains the field
if self.schedule_id is None and "schedule_id" in self.model_fields_set:
_dict['schedule_id'] = None
# set to None if total_tokens (nullable) is None
# and model_fields_set contains the field
if self.total_tokens is None and "total_tokens" in self.model_fields_set:
_dict['total_tokens'] = None
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of Session from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return cls.model_validate(obj)
_obj = cls.model_validate({
"accumulated_input_tokens": obj.get("accumulated_input_tokens"),
"accumulated_output_tokens": obj.get("accumulated_output_tokens"),
"accumulated_total_tokens": obj.get("accumulated_total_tokens"),
"conversation": [Message.from_dict(_item) for _item in obj["conversation"]] if obj.get("conversation") is not None else None,
"created_at": obj.get("created_at"),
"description": obj.get("description"),
"extension_data": obj.get("extension_data"),
"id": obj.get("id"),
"input_tokens": obj.get("input_tokens"),
"message_count": obj.get("message_count"),
"output_tokens": obj.get("output_tokens"),
"recipe": Recipe.from_dict(obj["recipe"]) if obj.get("recipe") is not None else None,
"schedule_id": obj.get("schedule_id"),
"total_tokens": obj.get("total_tokens"),
"updated_at": obj.get("updated_at"),
"working_dir": obj.get("working_dir")
})
return _obj