33 lines
1.3 KiB
Python
33 lines
1.3 KiB
Python
|
|
"""
|
||
|
|
Tool call tracking model for Claude Code sessions.
|
||
|
|
"""
|
||
|
|
|
||
|
|
from datetime import datetime
|
||
|
|
from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey, Boolean
|
||
|
|
from sqlalchemy.orm import relationship
|
||
|
|
|
||
|
|
from app.models.base import Base
|
||
|
|
|
||
|
|
|
||
|
|
class ToolCall(Base):
|
||
|
|
"""
|
||
|
|
Tracks individual tool calls made during Claude Code sessions.
|
||
|
|
|
||
|
|
This helps analyze which tools are used most frequently and their success rates.
|
||
|
|
"""
|
||
|
|
__tablename__ = "tool_calls"
|
||
|
|
|
||
|
|
id = Column(Integer, primary_key=True, index=True)
|
||
|
|
session_id = Column(String, ForeignKey("sessions.id"), nullable=False, index=True)
|
||
|
|
tool_name = Column(String(100), nullable=False, index=True)
|
||
|
|
parameters = Column(Text, nullable=True) # JSON string of tool parameters
|
||
|
|
result_status = Column(String(20), nullable=True, index=True) # success, error, timeout
|
||
|
|
error_message = Column(Text, nullable=True)
|
||
|
|
execution_time_ms = Column(Integer, nullable=True) # Tool execution time in milliseconds
|
||
|
|
timestamp = Column(DateTime, nullable=False, default=datetime.utcnow, index=True)
|
||
|
|
|
||
|
|
# Relationships
|
||
|
|
session = relationship("Session", back_populates="tool_calls")
|
||
|
|
|
||
|
|
def __repr__(self):
|
||
|
|
return f"<ToolCall(id={self.id}, tool={self.tool_name}, session={self.session_id})>"
|