Add token and context window tracking

This commit is contained in:
Azat
2026-02-02 23:28:40 +01:00
parent b77da51d58
commit 52ad820926
2 changed files with 79 additions and 5 deletions

View File

@@ -12,6 +12,7 @@ install_deps() {
command -v socat &>/dev/null || needed="$needed socat"
command -v jq &>/dev/null || needed="$needed jq"
command -v sqlite3 &>/dev/null || needed="$needed sqlite3"
command -v bc &>/dev/null || needed="$needed bc"
if [ -n "$needed" ]; then
echo "Installing dependencies:$needed"
@@ -63,6 +64,10 @@ CREATE TABLE IF NOT EXISTS conversations (
instance_id TEXT,
started_at TEXT DEFAULT CURRENT_TIMESTAMP,
status TEXT DEFAULT 'active',
tokens_in INTEGER DEFAULT 0,
tokens_out INTEGER DEFAULT 0,
total_tokens INTEGER DEFAULT 0,
max_context INTEGER DEFAULT 200000,
FOREIGN KEY (instance_id) REFERENCES instances(id)
);
@@ -72,6 +77,7 @@ CREATE TABLE IF NOT EXISTS messages (
role TEXT,
content TEXT,
tool_calls TEXT,
tokens INTEGER DEFAULT 0,
timestamp TEXT DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (conversation_id) REFERENCES conversations(id)
);