feat: heartbeat (#108)

* feat: heartbeat

* feat: independent heartbeat model
This commit is contained in:
Acbox Liu
2026-02-24 19:25:02 +08:00
committed by Ran
parent a9680587c6
commit 2f38662d4d
47 changed files with 2276 additions and 43 deletions
+18
View File
@@ -128,6 +128,10 @@ CREATE TABLE IF NOT EXISTS bots (
memory_model_id UUID REFERENCES models(id) ON DELETE SET NULL,
embedding_model_id UUID REFERENCES models(id) ON DELETE SET NULL,
search_provider_id UUID REFERENCES search_providers(id) ON DELETE SET NULL,
heartbeat_enabled BOOLEAN NOT NULL DEFAULT false,
heartbeat_interval INTEGER NOT NULL DEFAULT 30,
heartbeat_prompt TEXT NOT NULL DEFAULT '',
heartbeat_model_id UUID REFERENCES models(id) ON DELETE SET NULL,
metadata JSONB NOT NULL DEFAULT '{}'::jsonb,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
@@ -408,3 +412,17 @@ CREATE TABLE IF NOT EXISTS bot_inbox (
CREATE INDEX IF NOT EXISTS idx_bot_inbox_bot_unread ON bot_inbox(bot_id, created_at DESC) WHERE is_read = FALSE;
CREATE INDEX IF NOT EXISTS idx_bot_inbox_bot_created ON bot_inbox(bot_id, created_at DESC);
-- bot_heartbeat_logs: structured execution records for periodic heartbeat checks.
CREATE TABLE IF NOT EXISTS bot_heartbeat_logs (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
bot_id UUID NOT NULL REFERENCES bots(id) ON DELETE CASCADE,
status TEXT NOT NULL DEFAULT 'ok' CHECK (status IN ('ok', 'alert', 'error')),
result_text TEXT NOT NULL DEFAULT '',
error_message TEXT NOT NULL DEFAULT '',
usage JSONB,
started_at TIMESTAMPTZ NOT NULL DEFAULT now(),
completed_at TIMESTAMPTZ
);
CREATE INDEX IF NOT EXISTS idx_heartbeat_logs_bot_started ON bot_heartbeat_logs(bot_id, started_at DESC);