feat: chat api

This commit is contained in:
Acbox
2026-01-28 15:15:57 +08:00
parent 0711b1f086
commit 39215309da
26 changed files with 673 additions and 1873 deletions
+10
View File
@@ -130,3 +130,13 @@ CREATE TABLE IF NOT EXISTS lifecycle_events (
CREATE INDEX IF NOT EXISTS idx_lifecycle_events_container_id ON lifecycle_events(container_id);
CREATE INDEX IF NOT EXISTS idx_lifecycle_events_event_type ON lifecycle_events(event_type);
CREATE TABLE IF NOT EXISTS history (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
messages JSONB NOT NULL,
timestamp TIMESTAMPTZ NOT NULL,
"user" UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_history_user ON history("user");
CREATE INDEX IF NOT EXISTS idx_history_timestamp ON history(timestamp);
+11
View File
@@ -0,0 +1,11 @@
-- name: CreateHistory :one
INSERT INTO history (messages, timestamp, "user")
VALUES ($1, $2, $3)
RETURNING id, messages, timestamp, "user";
-- name: ListHistoryByUserSince :many
SELECT id, messages, timestamp, "user"
FROM history
WHERE "user" = $1 AND timestamp >= $2
ORDER BY timestamp ASC;