22 lines
637 B
Python
22 lines
637 B
Python
from __future__ import annotations
|
|
|
|
from sqlalchemy import select
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.models.tool_call import ToolCall
|
|
|
|
|
|
class ToolCallRepository:
|
|
def __init__(self, db: Session) -> None:
|
|
self.db = db
|
|
|
|
def add(self, tool_call: ToolCall) -> ToolCall:
|
|
self.db.add(tool_call)
|
|
self.db.commit()
|
|
self.db.refresh(tool_call)
|
|
return tool_call
|
|
|
|
def list_by_task_id(self, task_id: str) -> list[ToolCall]:
|
|
statement = select(ToolCall).where(ToolCall.task_id == task_id).order_by(ToolCall.started_at.asc())
|
|
return list(self.db.execute(statement).scalars())
|