mirror of
https://github.com/eigent-ai/eigent.git
synced 2026-05-23 12:44:45 +00:00
Some checks are pending
Pre-commit / pre-commit (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
CodeQL Advanced / Analyze (python) (push) Waiting to run
Test / Run Python Tests (push) Waiting to run
67 lines
1.9 KiB
Python
67 lines
1.9 KiB
Python
# ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
# ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
|
|
|
|
import json
|
|
from typing import Any
|
|
|
|
from pydantic import BaseModel, field_validator
|
|
from sqlmodel import JSON, Field
|
|
|
|
from app.model.abstract.model import AbstractModel, DefaultTimes
|
|
|
|
|
|
class ChatStep(AbstractModel, DefaultTimes, table=True):
|
|
id: int = Field(default=None, primary_key=True)
|
|
task_id: str = Field(index=True)
|
|
step: str
|
|
data: str = Field(sa_type=JSON)
|
|
timestamp: float | None = Field(default=None, nullable=True)
|
|
|
|
@field_validator("data", mode="before")
|
|
@classmethod
|
|
def serialize_data(cls, v):
|
|
if isinstance(v, (dict, list)):
|
|
return json.dumps(v, ensure_ascii=False)
|
|
return v
|
|
|
|
@field_validator("data", mode="after")
|
|
@classmethod
|
|
def deserialize_data(cls, v):
|
|
if isinstance(v, str):
|
|
try:
|
|
return json.loads(v)
|
|
except Exception:
|
|
return v
|
|
return v
|
|
|
|
|
|
class ChatStepIn(BaseModel):
|
|
task_id: str
|
|
step: str
|
|
data: Any
|
|
timestamp: float | None = None
|
|
|
|
|
|
class ChatStepOut(BaseModel):
|
|
id: int
|
|
task_id: str
|
|
step: str
|
|
data: Any
|
|
timestamp: float | None = None
|
|
|
|
|
|
class ChatStepUpdate(BaseModel):
|
|
step: str | None = None
|
|
data: Any | None = None
|
|
timestamp: float | None = None
|