Files
loki/drizzle/0081_user_model_keys.sql
Cato 20f4cebf65 feat(settings): power Loki with your own model — paste a key, get your best model (#921)
* wip: user_model_keys table + ai-kit 1.17.0

* wip: chat runs on the user's own model

* wip: settings API + screen for the user's own model

* wip: budget refusal offers your own model; tests

* fix: narrow userId for the own-model path; document BYOK_SEAL_SECRET

* fix(demo): the shared demo account may not store a model key

* fix(settings): deep links no longer cause a hydration mismatch
2026-09-25 09:55:40 -07:00

27 lines
1.2 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- Migration: user_model_keys — the model a user brings to power Loki.
--
-- WHY THIS EXISTS
-- Loki's own chat ran only on the shared, rationed free chain: when the day's
-- budget ran out a user was told to wait, and there was no way to say "use my
-- Anthropic / OpenAI / OpenRouter / … key instead". This stores that choice:
-- a vendor from ai-kit's closed list, the model picked there, and the key.
--
-- THE KEY IS STORED SEALED (ai-kit/seal: AES-256-GCM, scrypt-derived from the
-- app's BYOK_SEAL_SECRET, `iv:tag:ciphertext`). The database alone cannot read
-- it, no API ever returns it, and `key_hint` ("…abcd") is the only part shown.
-- One row per user; removing the user removes the key.
--
-- Hand-written, like 0073–0080: drizzle/meta's snapshot stops at 0072, so
-- `drizzle-kit generate` diffs against a stale picture and asks whether this
-- table is a rename of beacon_sessions.
CREATE TABLE IF NOT EXISTS user_model_keys (
user_id uuid PRIMARY KEY REFERENCES users(id) ON DELETE CASCADE,
vendor text NOT NULL,
model text NOT NULL,
sealed_key text NOT NULL,
key_hint text NOT NULL,
verified_at timestamptz NOT NULL,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now()
);