Skip to content

Open source file-system and knowledge based agent template. Build AI agents that stay up to date with your knowledge base

feat: use api key for sdk auth

Hugo Richard0a8dac8cf5ba
diff --git a/apps/chat/app/auth.config.ts b/apps/chat/app/auth.config.ts
index 7875fa8..2df2e6c 100644
--- a/apps/chat/app/auth.config.ts
+++ b/apps/chat/app/auth.config.ts
@@ -1,6 +1,6 @@
import { defineClientAuth } from '@onmax/nuxt-better-auth/config'
-import { adminClient } from 'better-auth/client/plugins'
+import { adminClient, apiKeyClient } from 'better-auth/client/plugins'
export default defineClientAuth({
- plugins: [adminClient()],
+ plugins: [adminClient(), apiKeyClient()],
})
diff --git a/apps/chat/app/layouts/default.vue b/apps/chat/app/layouts/default.vue
index 31fdfbc..14444c9 100644
--- a/apps/chat/app/layouts/default.vue
+++ b/apps/chat/app/layouts/default.vue
@@ -87,6 +87,7 @@ const adminNavigation = [
{ label: 'System', type: 'label' as const },
{ label: 'Sandbox', icon: 'i-lucide-box', to: '/admin/sandbox' },
{ label: 'Statistics', icon: 'i-lucide-bar-chart-3', to: '/admin/stats' },
+ { label: 'API Keys', icon: 'i-lucide-key', to: '/admin/api-keys' },
],
]
diff --git a/apps/chat/app/pages/admin/api-keys.vue b/apps/chat/app/pages/admin/api-keys.vue
new file mode 100644
index 0000000..d04c399
--- /dev/null
+++ b/apps/chat/app/pages/admin/api-keys.vue
@@ -0,0 +1,195 @@
+<script setup lang="ts">
+import { LazyModalConfirm } from '#components'
+
+interface ApiKeyRow {
+ id: string
+ name: string | null
+ prefix: string | null
+ start: string | null
+ userId: string
+ enabled: boolean
+ expiresAt: string | null
+ createdAt: string
+ userName: string | null
+ userEmail: string | null
+ userImage: string | null
+ userRole: string | null
+}
+
+const toast = useToast()
+const overlay = useOverlay()
+
+const { data: keys, refresh, status } = useLazyFetch<ApiKeyRow[]>('/api/admin/api-keys')
+
+const isCreating = ref(false)
+const newKeyName = ref('')
+const revealedKey = ref<string | null>(null)
+
+const deleteModal = overlay.create(LazyModalConfirm, {
+ props: {
+ title: 'Revoke API key',
+ description: 'Are you sure you want to revoke this API key? Any applications using it will lose access immediately.',
+ },
+})
+
+async function createAdminKey() {
+ isCreating.value = true
+ try {
+ const result = await $fetch('/api/admin/api-keys', {
+ method: 'POST',
+ body: { name: newKeyName.value.trim() || undefined },
+ })
+ revealedKey.value = (result as any).key ?? null
+ newKeyName.value = ''
+ await refresh()
+ toast.add({ title: 'Admin API key created', icon: 'i-lucide-check' })
+ } catch (e: any) {
+ toast.add({ title: 'Error', description: e?.data?.message || e?.message || 'Failed to create API key', color: 'error', icon: 'i-lucide-alert-circle' })
+ } finally {
+ isCreating.value = false
+ }
+}
+
+async function revokeKey(id: string) {
+ const instance = deleteModal.open()
+ const confirmed = await instance.result
+ if (!confirmed) return
+
+ try {
+ await $fetch(`/api/admin/api-keys/${id}`, { method: 'DELETE' })
+ await refresh()
+ toast.add({ title: 'API key revoked', icon: 'i-lucide-check' })
+ } catch (e: any) {
+ toast.add({ title: 'Error', description: e?.data?.message || e?.message || 'Failed to revoke API key', color: 'error', icon: 'i-lucide-alert-circle' })
+ }
+}
+
+function copyKey(key: string) {
+ navigator.clipboard.writeText(key)
+ toast.add({ title: 'Copied to clipboard', icon: 'i-lucide-clipboard-check' })
+}
+</script>
+
+<template>
+ <div class="px-6 py-8 max-w-2xl mx-auto w-full">
+ <header class="mb-8">
+ <h1 class="text-lg font-medium text-highlighted mb-1 font-pixel tracking-wide">
+ API Keys
+ </h1>
+ <p class="text-sm text-muted max-w-lg">
+ Manage all API keys across the platform. Create admin-level keys for bots and services.
+ </p>
+ </header>
+
+ <div class="space-y-6">
+ <!-- Revealed key banner -->
+ <div v-if="revealedKey" class="rounded-lg border border-primary/30 bg-primary/5 p-4">
+ <div class="flex items-center gap-2 mb-2">
+ <UIcon name="i-lucide-alert-triangle" class="size-4 text-primary" />
+ <p class="text-sm font-medium text-highlighted">
+ Save your API key now
+ </p>
+ </div>
+ <p class="text-xs text-muted mb-3">
+ This key will only be shown once. Copy it now and store it securely.
+ </p>
+ <div class="flex items-center gap-2">
+ <code class="flex-1 text-xs bg-elevated px-3 py-2 rounded-md font-mono break-all">{{ revealedKey }}</code>
+ <UButton
+ icon="i-lucide-copy"
+ color="neutral"
+ variant="ghost"
+ size="xs"
+ @click="copyKey(revealedKey!)"
+ />
+ </div>
+ <div class="mt-3">
+ <UButton
+ label="Done"
+ size="xs"
+ @click="revealedKey = null"
+ />
+ </div>
+ </div>
+
+ <!-- Create admin key -->
+ <section>
+ <h2 class="text-[10px] text-muted uppercase tracking-wide mb-3 font-pixel">
+ Create admin key
+ </h2>
+ <div class="rounded-lg border border-default">
+ <form class="flex items-center gap-3 px-4 py-3" @submit.prevent="createAdminKey">
+ <UInput
+ v-model="newKeyName"
+ placeholder="Key name (e.g. GitHub Bot)"
+ class="flex-1"
+ />
+ <UButton
+ type="submit"
+ :loading="isCreating"
+ size="xs"
+ >
+ Create admin key
+ </UButton>
+ </form>
+ </div>
+ </section>
+
+ <!-- All keys -->
+ <section>
+ <h2 class="text-[10px] text-muted uppercase tracking-wide mb-3 font-pixel">
+ All keys
+ </h2>
+ <div class="rounded-lg border border-default divide-y divide-default">
+ <div v-if="status === 'pending'" class="px-4 py-3.5">
+ <div v-for="i in 3" :key="i" class="flex items-center justify-between" :class="i > 1 && 'mt-3 pt-3 border-t border-default'">
+ <div class="flex items-center gap-3">
+ <USkeleton class="size-7 rounded-full" />
+ <div>
+ <USkeleton class="h-4 w-32 mb-1" />
+ <USkeleton class="h-3 w-48" />
+ </div>
+ </div>
+ <USkeleton class="h-8 w-16 rounded-md" />
+ </div>
+ </div>
+ <template v-else-if="keys?.length">
+ <div
+ v-for="key in keys"
+ :key="key.id"
+ class="flex items-center justify-between gap-4 px-4 py-3"
+ >
+ <div class="flex items-center gap-3 min-w-0">
+ <UAvatar :src="key.userImage || undefined" :alt="key.userName || undefined" size="xs" />
+ <div class="min-w-0">
+ <div class="flex items-center gap-2">
+ <p class="text-sm text-highlighted font-medium truncate">
+ {{ key.name || 'Unnamed key' }}
+ </p>
+ <UBadge v-if="key.userRole === 'admin'" label="Admin" size="xs" color="primary" variant="subtle" />
+ <UBadge v-if="!key.enabled" label="Disabled" size="xs" color="neutral" variant="subtle" />
+ </div>
+ <p class="text-xs text-muted truncate">
+ {{ key.userName || key.userEmail }} · {{ key.start ? `${key.start}...` : 'sk_...' }} · {{ new Date(key.createdAt).toLocaleDateString() }}
+ </p>
+ </div>
+ </div>
+ <UButton
+ label="Revoke"
+ color="error"
+ variant="ghost"
+ size="xs"
+ @click="revokeKey(key.id)"
+ />
+ </div>
+ </template>
+ <div v-else class="px-4 py-8 text-center">
+ <p class="text-sm text-muted">
+ No API keys have been created yet.
+ </p>
+ </div>
+ </div>
+ </section>
+ </div>
+ </div>
+</template>
diff --git a/apps/chat/app/pages/settings.vue b/apps/chat/app/pages/settings.vue
index 1d6f4ea..8f62b8b 100644
--- a/apps/chat/app/pages/settings.vue
+++ b/apps/chat/app/pages/settings.vue
@@ -1,350 +1,3 @@
-<script setup lang="ts">
-import { LazyModalConfirm } from '#components'
-
-definePageMeta({ auth: 'user' })
-
-const toast = useToast()
-const overlay = useOverlay()
-const { client, user, session, signOut, fetchSession } = useUserSession()
-
-// Profile
-const nameInput = ref(user.value?.name ?? '')
-const isSavingProfile = ref(false)
-
-watch(user, (u) => {
- if (u) nameInput.value = u.name ?? ''
-})
-
-async function saveProfile() {
- isSavingProfile.value = true
- try {
- await client!.updateUser({ name: nameInput.value })
- await fetchSession({ force: true })
- toast.add({ title: 'Profile updated', icon: 'i-lucide-check' })
- } catch (e: any) {
- toast.add({ title: 'Error', description: e?.data?.message || e?.message || 'Failed to update profile', color: 'error', icon: 'i-lucide-alert-circle' })
- } finally {
- isSavingProfile.value = false
- }
-}
-
-// Security
-const currentPassword = ref('')
-const newPassword = ref('')
-const isChangingPassword = ref(false)
-
-async function changePassword() {
- isChangingPassword.value = true
- try {
- await client!.changePassword({ currentPassword: currentPassword.value, newPassword: newPassword.value })
- currentPassword.value = ''
- newPassword.value = ''
- toast.add({ title: 'Password changed', icon: 'i-lucide-check' })
- } catch (e: any) {
- toast.add({ title: 'Error', description: e?.data?.message || e?.message || 'Failed to change password', color: 'error', icon: 'i-lucide-alert-circle' })
- } finally {
- isChangingPassword.value = false
- }
-}
-
-// Connected accounts
-const { data: accounts, refresh: refreshAccounts, status: accountsStatus } = useLazyAsyncData('user-accounts', () => client!.listAccounts())
-const isLinkingGithub = ref(false)
-const isUnlinking = ref(false)
-
-const hasGithub = computed(() => accounts.value?.data?.some((a: any) => a.providerId === 'github'))
-const hasPassword = computed(() => accounts.value?.data?.some((a: any) => a.providerId === 'credential'))
-const accountCount = computed(() => accounts.value?.data?.length ?? 0)
-
-async function linkGithub() {
- isLinkingGithub.value = true
- try {
- await client!.linkSocial({ provider: 'github' })
- } catch (e: any) {
- toast.add({ title: 'Error', description: e?.data?.message || e?.message || 'Failed to link GitHub', color: 'error', icon: 'i-lucide-alert-circle' })
- isLinkingGithub.value = false
- }
-}
-
-async function unlinkGithub() {
- isUnlinking.value = true
- try {
- await client!.unlinkAccount({ providerId: 'github' })
- await refreshAccounts()
- toast.add({ title: 'GitHub account unlinked', icon: 'i-lucide-check' })
- } catch (e: any) {
- toast.add({ title: 'Error', description: e?.data?.message || e?.message || 'Failed to unlink account', color: 'error', icon: 'i-lucide-alert-circle' })
- } finally {
- isUnlinking.value = false
- }
-}
-
-// Sessions
-const { data: sessions, refresh: refreshSessions, status: sessionsStatus } = useLazyAsyncData('user-sessions', () => client!.listSessions())
-const revokingSession = ref<string | null>(null)
-const isRevokingAll = ref(false)
-
-async function revokeSession(token: string) {
- revokingSession.value = token
- try {
- await client!.revokeSession({ token })
- await refreshSessions()
- toast.add({ title: 'Session revoked', icon: 'i-lucide-check' })
- } catch (e: any) {
- toast.add({ title: 'Error', description: e?.data?.message || e?.message || 'Failed to revoke session', color: 'error', icon: 'i-lucide-alert-circle' })
- } finally {
- revokingSession.value = null
- }
-}
-
-async function revokeOtherSessions() {
- isRevokingAll.value = true
- try {
- await client!.revokeOtherSessions()
- await refreshSessions()
- toast.add({ title: 'Other sessions revoked', icon: 'i-lucide-check' })
- } catch (e: any) {
- toast.add({ title: 'Error', description: e?.data?.message || e?.message || 'Failed to revoke sessions', color: 'error', icon: 'i-lucide-alert-circle' })
- } finally {
- isRevokingAll.value = false
- }
-}
-
-// Delete account
-const deleteAccountModal = overlay.create(LazyModalConfirm, {
- props: {
- title: 'Delete account',
- description: 'Are you sure you want to delete your account? All your data will be permanently removed. This cannot be undone.',
- },
-})
-const isDeletingAccount = ref(false)
-
-async function deleteAccount() {
- const instance = deleteAccountModal.open()
- const confirmed = await instance.result
- if (!confirmed) return
-
- isDeletingAccount.value = true
- try {
- await client!.deleteUser()
- await signOut()
- navigateTo('/login')
- } catch (e: any) {
- toast.add({ title: 'Error', description: e?.data?.message || e?.message || 'Failed to delete account', color: 'error', icon: 'i-lucide-alert-circle' })
- isDeletingAccount.value = false
- }
-}
-</script>
-
<template>
- <div class="px-6 py-8 max-w-2xl mx-auto w-full">
- <header class="mb-8">
- <h1 class="text-lg font-medium text-highlighted mb-1 font-pixel tracking-wide">
- Settings
- </h1>
- <p class="text-sm text-muted max-w-lg">
- Manage your profile, security, and connected accounts.
- </p>
- </header>
-
- <div class="space-y-8">
- <section>
- <h2 class="text-[10px] text-muted uppercase tracking-wide mb-3 font-pixel">
- Profile
- </h2>
- <div class="rounded-lg border border-default divide-y divide-default">
- <div class="flex items-center gap-4 px-4 py-3">
- <UAvatar :src="user?.image || undefined" :alt="user?.name ?? user?.username ?? undefined" size="lg" />
- <div class="min-w-0">
- <p class="text-sm text-highlighted font-medium truncate">
- {{ user?.name ?? user?.username }}
- </p>
- <p class="text-xs text-muted truncate">
- {{ user?.email ?? `@${user?.username}` }}
- </p>
- </div>
- </div>
- <form class="flex items-center justify-between gap-4 px-4 py-3" @submit.prevent="saveProfile">
- <div class="flex-1 min-w-0">
- <p class="text-sm text-highlighted mb-1">
- Display name
- </p>
- <UInput
- v-model="nameInput"
- placeholder="Your name"
- class="w-full max-w-xs"
- />
- </div>
- <UButton
- type="submit"
- :loading="isSavingProfile"
- size="xs"
- >
- Save
- </UButton>
- </form>
- </div>
- </section>
-
- <section v-if="hasPassword">
- <h2 class="text-[10px] text-muted uppercase tracking-wide mb-3 font-pixel">
- Security
- </h2>
- <div class="rounded-lg border border-default divide-y divide-default">
- <form class="px-4 py-3 space-y-3" @submit.prevent="changePassword">
- <p class="text-sm text-highlighted">
- Change password
- </p>
- <UInput
- v-model="currentPassword"
- type="password"
- placeholder="Current password"
- required
- class="w-full max-w-xs"
- />
- <UInput
- v-model="newPassword"
- type="password"
- placeholder="New password"
- required
- class="w-full max-w-xs"
- />
- <UButton
- type="submit"
- :loading="isChangingPassword"
- size="xs"
- >
- Change password
- </UButton>
- </form>
- </div>
- </section>
-
- <section>
- <h2 class="text-[10px] text-muted uppercase tracking-wide mb-3 font-pixel">
- Connected accounts
- </h2>
- <div class="rounded-lg border border-default divide-y divide-default">
- <div v-if="accountsStatus === 'pending'" class="flex items-center justify-between px-4 py-3.5">
- <div>
- <USkeleton class="h-4 w-28 mb-1" />
- <USkeleton class="h-3 w-48" />
- </div>
- <USkeleton class="h-8 w-20 rounded-md" />
- </div>
- <div v-else class="flex items-center justify-between gap-4 px-4 py-3">
- <div class="flex items-center gap-3">
- <UIcon name="i-simple-icons-github" class="size-5 text-highlighted" />
- <div>
- <p class="text-sm text-highlighted">
- GitHub
- </p>
- <p class="text-xs text-muted">
- {{ hasGithub ? 'Connected' : 'Not connected' }}
- </p>
- </div>
- </div>
- <UButton
- v-if="hasGithub"
- label="Unlink"
- color="neutral"
- variant="ghost"
- size="xs"
- :loading="isUnlinking"
- :disabled="accountCount <= 1"
- @click="unlinkGithub"
- />
- <UButton
- v-else
- label="Link"
- size="xs"
- :loading="isLinkingGithub"
- @click="linkGithub"
- />
- </div>
- </div>
- </section>
-
- <section>
- <h2 class="text-[10px] text-muted uppercase tracking-wide mb-3 font-pixel">
- Active sessions
- </h2>
- <div class="rounded-lg border border-default divide-y divide-default">
- <div v-if="sessionsStatus === 'pending'" class="px-4 py-3.5">
- <div v-for="i in 2" :key="i" class="flex items-center justify-between" :class="i > 1 && 'mt-3 pt-3 border-t border-default'">
- <div>
- <USkeleton class="h-4 w-32 mb-1" />
- <USkeleton class="h-3 w-48" />
- </div>
- <USkeleton class="h-8 w-16 rounded-md" />
- </div>
- </div>
- <template v-else>
- <div
- v-for="s in sessions?.data"
- :key="s.token"
- class="flex items-center justify-between gap-4 px-4 py-3"
- >
- <div class="min-w-0">
- <div class="flex items-center gap-2">
- <p class="text-sm text-highlighted truncate">
- {{ s.userAgent || 'Unknown device' }}
- </p>
- <UBadge v-if="s.token === session?.token" label="Current" size="xs" variant="subtle" />
- </div>
- <p class="text-xs text-muted">
- {{ s.ipAddress || 'Unknown IP' }} · Last active {{ new Date(s.updatedAt).toLocaleDateString() }}
- </p>
- </div>
- <UButton
- v-if="s.token !== session?.token"
- label="Revoke"
- color="neutral"
- variant="ghost"
- size="xs"
- :loading="revokingSession === s.token"
- @click="revokeSession(s.token)"
- />
- </div>
- </template>
- <div v-if="(sessions?.data?.length ?? 0) > 1" class="px-4 py-3">
- <UButton
- label="Revoke all other sessions"
- color="neutral"
- variant="ghost"
- size="xs"
- :loading="isRevokingAll"
- @click="revokeOtherSessions"
- />
- </div>
- </div>
- </section>
-
- <section>
- <h2 class="text-[10px] text-muted uppercase tracking-wide mb-3 font-pixel">
- Danger zone
- </h2>
- <div class="rounded-lg border border-error/30 bg-linear-to-br from-transparent to-error/10 divide-y divide-default">
- <div class="flex items-center justify-between gap-4 px-4 py-3">
- <div>
- <p class="text-sm text-highlighted">
- Delete account
- </p>
- <p class="text-xs text-muted">
- Permanently delete your account and all associated data.
- </p>
- </div>
- <UButton
- label="Delete account"
- color="error"
- variant="soft"
- size="xs"
- :loading="isDeletingAccount"
- @click="deleteAccount"
- />
- </div>
- </div>
- </section>
- </div>
- </div>
+ <NuxtPage />
</template>
diff --git a/apps/chat/app/pages/settings/api-keys.vue b/apps/chat/app/pages/settings/api-keys.vue
new file mode 100644
index 0000000..acdb353
--- /dev/null
+++ b/apps/chat/app/pages/settings/api-keys.vue
@@ -0,0 +1,186 @@
+<script setup lang="ts">
+import { LazyModalConfirm } from '#components'
+
+definePageMeta({ auth: 'user' })
+
+const toast = useToast()
+const overlay = useOverlay()
+const { client } = useUserSession()
+
+const { data: keys, refresh, status } = useLazyAsyncData('user-api-keys', () => client!.apiKey.list())
+
+const isCreating = ref(false)
+const newKeyName = ref('')
+const revealedKey = ref<string | null>(null)
+
+const deleteModal = overlay.create(LazyModalConfirm, {
+ props: {
+ title: 'Revoke API key',
+ description: 'Are you sure you want to revoke this API key? Any applications using it will lose access immediately.',
+ },
+})
+
+async function createKey() {
+ if (!newKeyName.value.trim()) return
+ isCreating.value = true
+ try {
+ const result = await client!.apiKey.create({ name: newKeyName.value.trim(), prefix: 'sk' })
+ revealedKey.value = result.data?.key ?? null
+ newKeyName.value = ''
+ await refresh()
+ toast.add({ title: 'API key created', icon: 'i-lucide-check' })
+ } catch (e: any) {
+ toast.add({ title: 'Error', description: e?.data?.message || e?.message || 'Failed to create API key', color: 'error', icon: 'i-lucide-alert-circle' })
+ } finally {
+ isCreating.value = false
+ }
+}
+
+async function revokeKey(keyId: string) {
+ const instance = deleteModal.open()
+ const confirmed = await instance.result
+ if (!confirmed) return
+
+ try {
+ await client!.apiKey.delete({ keyId })
+ await refresh()
+ toast.add({ title: 'API key revoked', icon: 'i-lucide-check' })
+ } catch (e: any) {
+ toast.add({ title: 'Error', description: e?.data?.message || e?.message || 'Failed to revoke API key', color: 'error', icon: 'i-lucide-alert-circle' })
+ }
+}
+
+function copyKey(key: string) {
+ navigator.clipboard.writeText(key)
+ toast.add({ title: 'Copied to clipboard', icon: 'i-lucide-clipboard-check' })
+}
+</script>
+
+<template>
+ <div class="px-6 py-8 max-w-2xl mx-auto w-full">
+ <header class="mb-8">
+ <div class="flex items-center gap-2 mb-1">
+ <UButton
+ icon="i-lucide-arrow-left"
+ variant="ghost"
+ color="neutral"
+ size="xs"
+ to="/settings"
+ />
+ <h1 class="text-lg font-medium text-highlighted font-pixel tracking-wide">
+ API Keys
+ </h1>
+ </div>
+ <p class="text-sm text-muted max-w-lg">
+ Create personal API keys to authenticate with the Savoir SDK.
+ </p>
+ </header>
+
+ <div class="space-y-6">
+ <!-- Revealed key banner -->
+ <div v-if="revealedKey" class="rounded-lg border border-primary/30 bg-primary/5 p-4">
+ <div class="flex items-center gap-2 mb-2">
+ <UIcon name="i-lucide-alert-triangle" class="size-4 text-primary" />
+ <p class="text-sm font-medium text-highlighted">
+ Save your API key now
+ </p>
+ </div>
+ <p class="text-xs text-muted mb-3">
+ This key will only be shown once. Copy it now and store it securely.
+ </p>
+ <div class="flex items-center gap-2">
+ <code class="flex-1 text-xs bg-elevated px-3 py-2 rounded-md font-mono break-all">{{ revealedKey }}</code>
+ <UButton
+ icon="i-lucide-copy"
+ color="neutral"
+ variant="ghost"
+ size="xs"
+ @click="copyKey(revealedKey!)"
+ />
+ </div>
+ <div class="mt-3">
+ <UButton
+ label="Done"
+ size="xs"
+ @click="revealedKey = null"
+ />
+ </div>
+ </div>
+
+ <!-- Create form -->
+ <section>
+ <h2 class="text-[10px] text-muted uppercase tracking-wide mb-3 font-pixel">
+ Create a new key
+ </h2>
+ <div class="rounded-lg border border-default">
+ <form class="flex items-center gap-3 px-4 py-3" @submit.prevent="createKey">
+ <UInput
+ v-model="newKeyName"
+ placeholder="Key name (e.g. My App)"
+ class="flex-1"
+ required
+ />
+ <UButton
+ type="submit"
+ :loading="isCreating"
+ size="xs"
+ :disabled="!newKeyName.trim()"
+ >
+ Create key
+ </UButton>
+ </form>
+ </div>
+ </section>
+
+ <!-- Keys list -->
+ <section>
+ <h2 class="text-[10px] text-muted uppercase tracking-wide mb-3 font-pixel">
+ Your keys
+ </h2>
+ <div class="rounded-lg border border-default divide-y divide-default">
+ <div v-if="status === 'pending'" class="px-4 py-3.5">
+ <div v-for="i in 2" :key="i" class="flex items-center justify-between" :class="i > 1 && 'mt-3 pt-3 border-t border-default'">
+ <div>
+ <USkeleton class="h-4 w-32 mb-1" />
+ <USkeleton class="h-3 w-48" />
+ </div>
+ <USkeleton class="h-8 w-16 rounded-md" />
+ </div>
+ </div>
+ <template v-else-if="keys?.data?.length">
+ <div
+ v-for="key in keys.data"
+ :key="key.id"
+ class="flex items-center justify-between gap-4 px-4 py-3"
+ >
+ <div class="min-w-0">
+ <div class="flex items-center gap-2">
+ <p class="text-sm text-highlighted font-medium truncate">
+ {{ key.name || 'Unnamed key' }}
+ </p>
+ <UBadge v-if="!key.enabled" label="Disabled" size="xs" color="neutral" variant="subtle" />
+ </div>
+ <p class="text-xs text-muted">
+ {{ key.start ? `${key.start}...` : 'sk_...' }} · Created {{ new Date(key.createdAt).toLocaleDateString() }}
+ <template v-if="key.expiresAt"> · Expires {{ new Date(key.expiresAt).toLocaleDateString() }}</template>
+ </p>
+ </div>
+ <UButton
+ label="Revoke"
+ color="error"
+ variant="ghost"
+ size="xs"
+ @click="revokeKey(key.id)"
+ />
+ </div>
+ </template>
+ <div v-else class="px-4 py-8 text-center">
+ <p class="text-sm text-muted">
+ No API keys yet. Create one to get started.
+ </p>
+ </div>
+ </div>
+ </section>
+ </div>
+ </div>
+</template>
diff --git a/apps/chat/app/pages/settings/index.vue b/apps/chat/app/pages/settings/index.vue
new file mode 100644
index 0000000..a55afbb
--- /dev/null
+++ b/apps/chat/app/pages/settings/index.vue
@@ -0,0 +1,372 @@
+<script setup lang="ts">
+import { LazyModalConfirm } from '#components'
+
+definePageMeta({ auth: 'user' })
+
+const toast = useToast()
+const overlay = useOverlay()
+const { client, user, session, signOut, fetchSession } = useUserSession()
+
+// Profile
+const nameInput = ref(user.value?.name ?? '')
+const isSavingProfile = ref(false)
+
+watch(user, (u) => {
+ if (u) nameInput.value = u.name ?? ''
+})
+
+async function saveProfile() {
+ isSavingProfile.value = true
+ try {
+ await client!.updateUser({ name: nameInput.value })
+ await fetchSession({ force: true })
+ toast.add({ title: 'Profile updated', icon: 'i-lucide-check' })
+ } catch (e: any) {
+ toast.add({ title: 'Error', description: e?.data?.message || e?.message || 'Failed to update profile', color: 'error', icon: 'i-lucide-alert-circle' })
+ } finally {
+ isSavingProfile.value = false
+ }
+}
+
+// Security
+const currentPassword = ref('')
+const newPassword = ref('')
+const isChangingPassword = ref(false)
+
+async function changePassword() {
+ isChangingPassword.value = true
+ try {
+ await client!.changePassword({ currentPassword: currentPassword.value, newPassword: newPassword.value })
+ currentPassword.value = ''
+ newPassword.value = ''
+ toast.add({ title: 'Password changed', icon: 'i-lucide-check' })
+ } catch (e: any) {
+ toast.add({ title: 'Error', description: e?.data?.message || e?.message || 'Failed to change password', color: 'error', icon: 'i-lucide-alert-circle' })
+ } finally {
+ isChangingPassword.value = false
+ }
+}
+
+// Connected accounts
+const { data: accounts, refresh: refreshAccounts, status: accountsStatus } = useLazyAsyncData('user-accounts', () => client!.listAccounts())
+const isLinkingGithub = ref(false)
+const isUnlinking = ref(false)
+
+const hasGithub = computed(() => accounts.value?.data?.some((a: any) => a.providerId === 'github'))
+const hasPassword = computed(() => accounts.value?.data?.some((a: any) => a.providerId === 'credential'))
+const accountCount = computed(() => accounts.value?.data?.length ?? 0)
+
+async function linkGithub() {
+ isLinkingGithub.value = true
+ try {
+ await client!.linkSocial({ provider: 'github' })
+ } catch (e: any) {
+ toast.add({ title: 'Error', description: e?.data?.message || e?.message || 'Failed to link GitHub', color: 'error', icon: 'i-lucide-alert-circle' })
+ isLinkingGithub.value = false
+ }
+}
+
+async function unlinkGithub() {
+ isUnlinking.value = true
+ try {
+ await client!.unlinkAccount({ providerId: 'github' })
+ await refreshAccounts()
+ toast.add({ title: 'GitHub account unlinked', icon: 'i-lucide-check' })
+ } catch (e: any) {
+ toast.add({ title: 'Error', description: e?.data?.message || e?.message || 'Failed to unlink account', color: 'error', icon: 'i-lucide-alert-circle' })
+ } finally {
+ isUnlinking.value = false
+ }
+}
+
+// Sessions
+const { data: sessions, refresh: refreshSessions, status: sessionsStatus } = useLazyAsyncData('user-sessions', () => client!.listSessions())
+const revokingSession = ref<string | null>(null)
+const isRevokingAll = ref(false)
+
+async function revokeSession(token: string) {
+ revokingSession.value = token
+ try {
+ await client!.revokeSession({ token })
+ await refreshSessions()
+ toast.add({ title: 'Session revoked', icon: 'i-lucide-check' })
+ } catch (e: any) {
+ toast.add({ title: 'Error', description: e?.data?.message || e?.message || 'Failed to revoke session', color: 'error', icon: 'i-lucide-alert-circle' })
+ } finally {
+ revokingSession.value = null
+ }
+}
+
+async function revokeOtherSessions() {
+ isRevokingAll.value = true
+ try {
+ await client!.revokeOtherSessions()
+ await refreshSessions()
+ toast.add({ title: 'Other sessions revoked', icon: 'i-lucide-check' })
+ } catch (e: any) {
+ toast.add({ title: 'Error', description: e?.data?.message || e?.message || 'Failed to revoke sessions', color: 'error', icon: 'i-lucide-alert-circle' })
+ } finally {
+ isRevokingAll.value = false
+ }
+}
+
+// Delete account
+const deleteAccountModal = overlay.create(LazyModalConfirm, {
+ props: {
+ title: 'Delete account',
+ description: 'Are you sure you want to delete your account? All your data will be permanently removed. This cannot be undone.',
+ },
+})
+const isDeletingAccount = ref(false)
+
+async function deleteAccount() {
+ const instance = deleteAccountModal.open()
+ const confirmed = await instance.result
+ if (!confirmed) return
+
+ isDeletingAccount.value = true
+ try {
+ await client!.deleteUser()
+ await signOut()
+ navigateTo('/login')
+ } catch (e: any) {
+ toast.add({ title: 'Error', description: e?.data?.message || e?.message || 'Failed to delete account', color: 'error', icon: 'i-lucide-alert-circle' })
+ isDeletingAccount.value = false
+ }
+}
+</script>
+
+<template>
+ <div class="px-6 py-8 max-w-2xl mx-auto w-full">
+ <header class="mb-8">
+ <h1 class="text-lg font-medium text-highlighted mb-1 font-pixel tracking-wide">
+ Settings
+ </h1>
+ <p class="text-sm text-muted max-w-lg">
+ Manage your profile, security, and connected accounts.
+ </p>
+ </header>
+
+ <div class="space-y-8">
+ <section>
+ <h2 class="text-[10px] text-muted uppercase tracking-wide mb-3 font-pixel">
+ Profile
+ </h2>
+ <div class="rounded-lg border border-default divide-y divide-default">
+ <div class="flex items-center gap-4 px-4 py-3">
+ <UAvatar :src="user?.image || undefined" :alt="user?.name ?? user?.username ?? undefined" size="lg" />
+ <div class="min-w-0">
+ <p class="text-sm text-highlighted font-medium truncate">
+ {{ user?.name ?? user?.username }}
+ </p>
+ <p class="text-xs text-muted truncate">
+ {{ user?.email ?? `@${user?.username}` }}
+ </p>
+ </div>
+ </div>
+ <form class="flex items-center justify-between gap-4 px-4 py-3" @submit.prevent="saveProfile">
+ <div class="flex-1 min-w-0">
+ <p class="text-sm text-highlighted mb-1">
+ Display name
+ </p>
+ <UInput
+ v-model="nameInput"
+ placeholder="Your name"
+ class="w-full max-w-xs"
+ />
+ </div>
+ <UButton
+ type="submit"
+ :loading="isSavingProfile"
+ size="xs"
+ >
+ Save
+ </UButton>
+ </form>
+ </div>
+ </section>
+
+ <section v-if="hasPassword">
+ <h2 class="text-[10px] text-muted uppercase tracking-wide mb-3 font-pixel">
+ Security
+ </h2>
+ <div class="rounded-lg border border-default divide-y divide-default">
+ <form class="px-4 py-3 space-y-3" @submit.prevent="changePassword">
+ <p class="text-sm text-highlighted">
+ Change password
+ </p>
+ <UInput
+ v-model="currentPassword"
+ type="password"
+ placeholder="Current password"
+ required
+ class="w-full max-w-xs"
+ />
+ <UInput
+ v-model="newPassword"
+ type="password"
+ placeholder="New password"
+ required
+ class="w-full max-w-xs"
+ />
+ <UButton
+ type="submit"
+ :loading="isChangingPassword"
+ size="xs"
+ >
+ Change password
+ </UButton>
+ </form>
+ </div>
+ </section>
+
+ <section>
+ <h2 class="text-[10px] text-muted uppercase tracking-wide mb-3 font-pixel">
+ Connected accounts
+ </h2>
+ <div class="rounded-lg border border-default divide-y divide-default">
+ <div v-if="accountsStatus === 'pending'" class="flex items-center justify-between px-4 py-3.5">
+ <div>
+ <USkeleton class="h-4 w-28 mb-1" />
+ <USkeleton class="h-3 w-48" />
+ </div>
+ <USkeleton class="h-8 w-20 rounded-md" />
+ </div>
+ <div v-else class="flex items-center justify-between gap-4 px-4 py-3">
+ <div class="flex items-center gap-3">
+ <UIcon name="i-simple-icons-github" class="size-5 text-highlighted" />
+ <div>
+ <p class="text-sm text-highlighted">
+ GitHub
+ </p>
+ <p class="text-xs text-muted">
+ {{ hasGithub ? 'Connected' : 'Not connected' }}
+ </p>
+ </div>
+ </div>
+ <UButton
+ v-if="hasGithub"
+ label="Unlink"
+ color="neutral"
+ variant="ghost"
+ size="xs"
+ :loading="isUnlinking"
+ :disabled="accountCount <= 1"
+ @click="unlinkGithub"
+ />
+ <UButton
+ v-else
+ label="Link"
+ size="xs"
+ :loading="isLinkingGithub"
+ @click="linkGithub"
+ />
+ </div>
+ </div>
+ </section>
+
+ <section>
+ <h2 class="text-[10px] text-muted uppercase tracking-wide mb-3 font-pixel">
+ Active sessions
+ </h2>
+ <div class="rounded-lg border border-default divide-y divide-default">
+ <div v-if="sessionsStatus === 'pending'" class="px-4 py-3.5">
+ <div v-for="i in 2" :key="i" class="flex items-center justify-between" :class="i > 1 && 'mt-3 pt-3 border-t border-default'">
+ <div>
+ <USkeleton class="h-4 w-32 mb-1" />
+ <USkeleton class="h-3 w-48" />
+ </div>
+ <USkeleton class="h-8 w-16 rounded-md" />
+ </div>
+ </div>
+ <template v-else>
+ <div
+ v-for="s in sessions?.data"
+ :key="s.token"
+ class="flex items-center justify-between gap-4 px-4 py-3"
+ >
+ <div class="min-w-0">
+ <div class="flex items-center gap-2">
+ <p class="text-sm text-highlighted truncate">
+ {{ s.userAgent || 'Unknown device' }}
+ </p>
+ <UBadge v-if="s.token === session?.token" label="Current" size="xs" variant="subtle" />
+ </div>
+ <p class="text-xs text-muted">
+ {{ s.ipAddress || 'Unknown IP' }} · Last active {{ new Date(s.updatedAt).toLocaleDateString() }}
+ </p>
+ </div>
+ <UButton
+ v-if="s.token !== session?.token"
+ label="Revoke"
+ color="neutral"
+ variant="ghost"
+ size="xs"
+ :loading="revokingSession === s.token"
+ @click="revokeSession(s.token)"
+ />
+ </div>
+ </template>
+ <div v-if="(sessions?.data?.length ?? 0) > 1" class="px-4 py-3">
+ <UButton
+ label="Revoke all other sessions"
+ color="neutral"
+ variant="ghost"
+ size="xs"
+ :loading="isRevokingAll"
+ @click="revokeOtherSessions"
+ />
+ </div>
+ </div>
+ </section>
+
+ <section>
+ <h2 class="text-[10px] text-muted uppercase tracking-wide mb-3 font-pixel">
+ Developer
+ </h2>
+ <div class="rounded-lg border border-default divide-y divide-default">
+ <NuxtLink to="/settings/api-keys" class="flex items-center justify-between gap-4 px-4 py-3 hover:bg-elevated/50 transition-colors">
+ <div class="flex items-center gap-3">
+ <UIcon name="i-lucide-key" class="size-5 text-highlighted" />
+ <div>
+ <p class="text-sm text-highlighted">
+ API Keys
+ </p>
+ <p class="text-xs text-muted">
+ Manage your personal API keys for SDK access.
+ </p>
+ </div>
+ </div>
+ <UIcon name="i-lucide-chevron-right" class="size-4 text-muted" />
+ </NuxtLink>
+ </div>
+ </section>
+
+ <section>
+ <h2 class="text-[10px] text-muted uppercase tracking-wide mb-3 font-pixel">
+ Danger zone
+ </h2>
+ <div class="rounded-lg border border-error/30 bg-linear-to-br from-transparent to-error/10 divide-y divide-default">
+ <div class="flex items-center justify-between gap-4 px-4 py-3">
+ <div>
+ <p class="text-sm text-highlighted">
+ Delete account
+ </p>
+ <p class="text-xs text-muted">
+ Permanently delete your account and all associated data.
+ </p>
+ </div>
+ <UButton
+ label="Delete account"
+ color="error"
+ variant="soft"
+ size="xs"
+ :loading="isDeletingAccount"
+ @click="deleteAccount"
+ />
+ </div>
+ </div>
+ </section>
+ </div>
+ </div>
+</template>
diff --git a/apps/chat/nuxt.config.ts b/apps/chat/nuxt.config.ts
index 412167d..d0d7350 100644
--- a/apps/chat/nuxt.config.ts
+++ b/apps/chat/nuxt.config.ts
@@ -98,7 +98,6 @@ export default defineNuxtConfig({
// Savoir SDK config
savoir: {
apiKey: '',
- secretKey: '',
},
// GitHub config
github: {
diff --git a/apps/chat/server/api/admin/api-keys.get.ts b/apps/chat/server/api/admin/api-keys.get.ts
new file mode 100644
index 0000000..a2cc6ab
--- /dev/null
+++ b/apps/chat/server/api/admin/api-keys.get.ts
@@ -0,0 +1,25 @@
+import { db, schema } from '@nuxthub/db'
+import { desc, eq } from 'drizzle-orm'
+
+export default defineEventHandler(async (event) => {
+ await requireAdmin(event)
+
+ return db
+ .select({
+ id: schema.apikey.id,
+ name: schema.apikey.name,
+ prefix: schema.apikey.prefix,
+ start: schema.apikey.start,
+ userId: schema.apikey.userId,
+ enabled: schema.apikey.enabled,
+ expiresAt: schema.apikey.expiresAt,
+ createdAt: schema.apikey.createdAt,
+ userName: schema.user.name,
+ userEmail: schema.user.email,
+ userImage: schema.user.image,
+ userRole: schema.user.role,
+ })
+ .from(schema.apikey)
+ .leftJoin(schema.user, eq(schema.user.id, schema.apikey.userId))
+ .orderBy(desc(schema.apikey.createdAt))
+})
diff --git a/apps/chat/server/api/admin/api-keys.post.ts b/apps/chat/server/api/admin/api-keys.post.ts
new file mode 100644
index 0000000..b5e74e4
--- /dev/null
+++ b/apps/chat/server/api/admin/api-keys.post.ts
@@ -0,0 +1,21 @@
+import { z } from 'zod'
+
+const bodySchema = z.object({
+ name: z.string().min(1).max(100).optional(),
+})
+
+export default defineEventHandler(async (event) => {
+ const { user } = await requireAdmin(event)
+ const body = await readValidatedBody(event, bodySchema.parse)
+
+ const auth = serverAuth(event)
+ const result = await auth.api.createApiKey({
+ body: {
+ name: body.name || 'Admin key',
+ prefix: 'sk',
+ userId: user.id,
+ },
+ })
+
+ return result
+})
diff --git a/apps/chat/server/api/admin/api-keys/[id].delete.ts b/apps/chat/server/api/admin/api-keys/[id].delete.ts
new file mode 100644
index 0000000..360395e
--- /dev/null
+++ b/apps/chat/server/api/admin/api-keys/[id].delete.ts
@@ -0,0 +1,15 @@
+import { db } from '@nuxthub/db'
+import { sql } from 'drizzle-orm'
+
+export default defineEventHandler(async (event) => {
+ await requireAdmin(event)
+
+ const id = getRouterParam(event, 'id')
+ if (!id) {
+ throw createError({ statusCode: 400, message: 'Missing API key ID' })
+ }
+
+ await db.run(sql`DELETE FROM "apikey" WHERE id = ${id}`)
+
+ return { deleted: true }
+})
diff --git a/apps/chat/server/api/agent-config/public.get.ts b/apps/chat/server/api/agent-config/public.get.ts
index 4e18b4a..3a147ef 100644
--- a/apps/chat/server/api/agent-config/public.get.ts
+++ b/apps/chat/server/api/agent-config/public.get.ts
@@ -8,21 +8,6 @@ import { getAgentConfig } from '../../utils/agent-config'
* the current agent configuration via the SDK.
*/
export default defineEventHandler(async (event) => {
- // Validate API key (similar to sandbox routes)
- const config = useRuntimeConfig()
- const secretKey = config.savoirSecretKey
-
- if (secretKey) {
- const authHeader = getHeader(event, 'Authorization')
- const apiKey = authHeader?.replace('Bearer ', '')
-
- if (!apiKey || apiKey !== secretKey) {
- throw createError({
- statusCode: 401,
- message: 'Invalid or missing API key',
- })
- }
- }
-
+ await requireUserSession(event)
return await getAgentConfig()
})
diff --git a/apps/chat/server/api/sandbox/shell.post.ts b/apps/chat/server/api/sandbox/shell.post.ts
index 6b6ef31..5bbe42e 100644
--- a/apps/chat/server/api/sandbox/shell.post.ts
+++ b/apps/chat/server/api/sandbox/shell.post.ts
@@ -59,6 +59,7 @@ interface CommandResult {
}
export default defineEventHandler(async (event) => {
+ await requireUserSession(event)
const requestLog = useLogger(event)
const body = await readValidatedBody(event, bodySchema.parse)
diff --git a/apps/chat/server/api/stats/usage.post.ts b/apps/chat/server/api/stats/usage.post.ts
index 19eb52d..3752113 100644
--- a/apps/chat/server/api/stats/usage.post.ts
+++ b/apps/chat/server/api/stats/usage.post.ts
@@ -32,6 +32,7 @@ const usageSchema = z.object({
* ```
*/
export default defineEventHandler(async (event) => {
+ await requireUserSession(event)
const body = await readValidatedBody(event, usageSchema.parse)
const usage = await db.insert(schema.apiUsage).values({
diff --git a/apps/chat/server/auth.config.ts b/apps/chat/server/auth.config.ts
index 73af467..496f498 100644
--- a/apps/chat/server/auth.config.ts
+++ b/apps/chat/server/auth.config.ts
@@ -1,4 +1,4 @@
-import { admin } from 'better-auth/plugins'
+import { admin, apiKey } from 'better-auth/plugins'
import { sql } from 'drizzle-orm'
export default defineServerAuth(({ runtimeConfig, db }) => {
@@ -25,7 +25,19 @@ export default defineServerAuth(({ runtimeConfig, db }) => {
username: { type: 'string' as const, required: false },
},
},
- plugins: [admin()],
+ plugins: [
+ admin(),
+ apiKey({
+ enableSessionForAPIKeys: true,
+ customAPIKeyGetter: (ctx) => {
+ const xApiKey = ctx.headers?.get('x-api-key')
+ if (xApiKey) return xApiKey
+ const authHeader = ctx.headers?.get('authorization')
+ if (authHeader?.startsWith('Bearer ')) return authHeader.slice(7)
+ return null
+ },
+ }),
+ ],
databaseHooks: {
user: {
create: {
diff --git a/apps/chat/server/db/migrations/sqlite/0001_daffy_masque.sql b/apps/chat/server/db/migrations/sqlite/0001_daffy_masque.sql
new file mode 100644
index 0000000..82ef13f
--- /dev/null
+++ b/apps/chat/server/db/migrations/sqlite/0001_daffy_masque.sql
@@ -0,0 +1,27 @@
+CREATE TABLE `apikey` (
+ `id` text PRIMARY KEY NOT NULL,
+ `name` text,
+ `start` text,
+ `prefix` text,
+ `key` text NOT NULL,
+ `userId` text NOT NULL,
+ `refillInterval` integer,
+ `refillAmount` integer,
+ `lastRefillAt` integer,
+ `enabled` integer DEFAULT true,
+ `rateLimitEnabled` integer DEFAULT true,
+ `rateLimitTimeWindow` integer DEFAULT 86400000,
+ `rateLimitMax` integer DEFAULT 10,
+ `requestCount` integer DEFAULT 0,
+ `remaining` integer,
+ `lastRequest` integer,
+ `expiresAt` integer,
+ `createdAt` integer NOT NULL,
+ `updatedAt` integer NOT NULL,
+ `permissions` text,
+ `metadata` text,
+ FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade
+);
+--> statement-breakpoint
+CREATE INDEX `apikey_key_idx` ON `apikey` (`key`);--> statement-breakpoint
+CREATE INDEX `apikey_userId_idx` ON `apikey` (`userId`);
\ No newline at end of file
diff --git a/apps/chat/server/db/migrations/sqlite/meta/0001_snapshot.json b/apps/chat/server/db/migrations/sqlite/meta/0001_snapshot.json
new file mode 100644
index 0000000..a885a95
--- /dev/null
+++ b/apps/chat/server/db/migrations/sqlite/meta/0001_snapshot.json
@@ -0,0 +1,1208 @@
+{
+ "version": "6",
+ "dialect": "sqlite",
+ "id": "ce1f8c3c-0849-4c19-9b34-af730ea67769",
+ "prevId": "9298492f-be45-45e8-8808-1812cb1254a3",
+ "tables": {
+ "account": {
+ "name": "account",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "accountId": {
+ "name": "accountId",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "providerId": {
+ "name": "providerId",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "userId": {
+ "name": "userId",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "accessToken": {
+ "name": "accessToken",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "refreshToken": {
+ "name": "refreshToken",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "idToken": {
+ "name": "idToken",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "accessTokenExpiresAt": {
+ "name": "accessTokenExpiresAt",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "refreshTokenExpiresAt": {
+ "name": "refreshTokenExpiresAt",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "scope": {
+ "name": "scope",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "password": {
+ "name": "password",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "createdAt": {
+ "name": "createdAt",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(cast(unixepoch('subsecond') * 1000 as integer))"
+ },
+ "updatedAt": {
+ "name": "updatedAt",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "account_userId_idx": {
+ "name": "account_userId_idx",
+ "columns": [
+ "userId"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "account_userId_user_id_fk": {
+ "name": "account_userId_user_id_fk",
+ "tableFrom": "account",
+ "tableTo": "user",
+ "columnsFrom": [
+ "userId"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "agent_config": {
+ "name": "agent_config",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'default'"
+ },
+ "additional_prompt": {
+ "name": "additional_prompt",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "response_style": {
+ "name": "response_style",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "'concise'"
+ },
+ "language": {
+ "name": "language",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "'en'"
+ },
+ "default_model": {
+ "name": "default_model",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "max_steps_multiplier": {
+ "name": "max_steps_multiplier",
+ "type": "real",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": 1
+ },
+ "temperature": {
+ "name": "temperature",
+ "type": "real",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": 0.7
+ },
+ "search_instructions": {
+ "name": "search_instructions",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "citation_format": {
+ "name": "citation_format",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "'inline'"
+ },
+ "is_active": {
+ "name": "is_active",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "api_usage": {
+ "name": "api_usage",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "source": {
+ "name": "source",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "source_id": {
+ "name": "source_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "model": {
+ "name": "model",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "input_tokens": {
+ "name": "input_tokens",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "output_tokens": {
+ "name": "output_tokens",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "duration_ms": {
+ "name": "duration_ms",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "metadata": {
+ "name": "metadata",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "api_usage_source_idx": {
+ "name": "api_usage_source_idx",
+ "columns": [
+ "source"
+ ],
+ "isUnique": false
+ },
+ "api_usage_created_at_idx": {
+ "name": "api_usage_created_at_idx",
+ "columns": [
+ "created_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "apikey": {
+ "name": "apikey",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "start": {
+ "name": "start",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "prefix": {
+ "name": "prefix",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "key": {
+ "name": "key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "userId": {
+ "name": "userId",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "refillInterval": {
+ "name": "refillInterval",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "refillAmount": {
+ "name": "refillAmount",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "lastRefillAt": {
+ "name": "lastRefillAt",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "enabled": {
+ "name": "enabled",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": true
+ },
+ "rateLimitEnabled": {
+ "name": "rateLimitEnabled",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": true
+ },
+ "rateLimitTimeWindow": {
+ "name": "rateLimitTimeWindow",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": 86400000
+ },
+ "rateLimitMax": {
+ "name": "rateLimitMax",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": 10
+ },
+ "requestCount": {
+ "name": "requestCount",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": 0
+ },
+ "remaining": {
+ "name": "remaining",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "lastRequest": {
+ "name": "lastRequest",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "expiresAt": {
+ "name": "expiresAt",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "createdAt": {
+ "name": "createdAt",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updatedAt": {
+ "name": "updatedAt",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "permissions": {
+ "name": "permissions",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "metadata": {
+ "name": "metadata",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "apikey_key_idx": {
+ "name": "apikey_key_idx",
+ "columns": [
+ "key"
+ ],
+ "isUnique": false
+ },
+ "apikey_userId_idx": {
+ "name": "apikey_userId_idx",
+ "columns": [
+ "userId"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "apikey_userId_user_id_fk": {
+ "name": "apikey_userId_user_id_fk",
+ "tableFrom": "apikey",
+ "tableTo": "user",
+ "columnsFrom": [
+ "userId"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "chats": {
+ "name": "chats",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "title": {
+ "name": "title",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "mode": {
+ "name": "mode",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'chat'"
+ },
+ "is_public": {
+ "name": "is_public",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "share_token": {
+ "name": "share_token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "chats_user_id_idx": {
+ "name": "chats_user_id_idx",
+ "columns": [
+ "user_id"
+ ],
+ "isUnique": false
+ },
+ "chats_share_token_idx": {
+ "name": "chats_share_token_idx",
+ "columns": [
+ "share_token"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "messages": {
+ "name": "messages",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "chat_id": {
+ "name": "chat_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "role": {
+ "name": "role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "parts": {
+ "name": "parts",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "feedback": {
+ "name": "feedback",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "model": {
+ "name": "model",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "input_tokens": {
+ "name": "input_tokens",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "output_tokens": {
+ "name": "output_tokens",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "duration_ms": {
+ "name": "duration_ms",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "source": {
+ "name": "source",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "'web'"
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "messages_chat_id_idx": {
+ "name": "messages_chat_id_idx",
+ "columns": [
+ "chat_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "messages_chat_id_chats_id_fk": {
+ "name": "messages_chat_id_chats_id_fk",
+ "tableFrom": "messages",
+ "tableTo": "chats",
+ "columnsFrom": [
+ "chat_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "session": {
+ "name": "session",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "expiresAt": {
+ "name": "expiresAt",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "token": {
+ "name": "token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "createdAt": {
+ "name": "createdAt",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(cast(unixepoch('subsecond') * 1000 as integer))"
+ },
+ "updatedAt": {
+ "name": "updatedAt",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "ipAddress": {
+ "name": "ipAddress",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "userAgent": {
+ "name": "userAgent",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "userId": {
+ "name": "userId",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "impersonatedBy": {
+ "name": "impersonatedBy",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "session_token_unique": {
+ "name": "session_token_unique",
+ "columns": [
+ "token"
+ ],
+ "isUnique": true
+ },
+ "session_userId_idx": {
+ "name": "session_userId_idx",
+ "columns": [
+ "userId"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "session_userId_user_id_fk": {
+ "name": "session_userId_user_id_fk",
+ "tableFrom": "session",
+ "tableTo": "user",
+ "columnsFrom": [
+ "userId"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "sources": {
+ "name": "sources",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "type": {
+ "name": "type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "label": {
+ "name": "label",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "base_path": {
+ "name": "base_path",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "'/docs'"
+ },
+ "repo": {
+ "name": "repo",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "branch": {
+ "name": "branch",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "content_path": {
+ "name": "content_path",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "output_path": {
+ "name": "output_path",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "readme_only": {
+ "name": "readme_only",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": false
+ },
+ "channel_id": {
+ "name": "channel_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "handle": {
+ "name": "handle",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "max_videos": {
+ "name": "max_videos",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": 50
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "sources_type_idx": {
+ "name": "sources_type_idx",
+ "columns": [
+ "type"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "usage_stats": {
+ "name": "usage_stats",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "date": {
+ "name": "date",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "source": {
+ "name": "source",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'web'"
+ },
+ "model": {
+ "name": "model",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "message_count": {
+ "name": "message_count",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "total_input_tokens": {
+ "name": "total_input_tokens",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "total_output_tokens": {
+ "name": "total_output_tokens",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "total_duration_ms": {
+ "name": "total_duration_ms",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "usage_stats_date_idx": {
+ "name": "usage_stats_date_idx",
+ "columns": [
+ "date"
+ ],
+ "isUnique": false
+ },
+ "usage_stats_date_user_source_model_idx": {
+ "name": "usage_stats_date_user_source_model_idx",
+ "columns": [
+ "date",
+ "user_id",
+ "source",
+ "model"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "user": {
+ "name": "user",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "email": {
+ "name": "email",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "emailVerified": {
+ "name": "emailVerified",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "image": {
+ "name": "image",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "createdAt": {
+ "name": "createdAt",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(cast(unixepoch('subsecond') * 1000 as integer))"
+ },
+ "updatedAt": {
+ "name": "updatedAt",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(cast(unixepoch('subsecond') * 1000 as integer))"
+ },
+ "role": {
+ "name": "role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "banned": {
+ "name": "banned",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": false
+ },
+ "banReason": {
+ "name": "banReason",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "banExpires": {
+ "name": "banExpires",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "username": {
+ "name": "username",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "user_email_unique": {
+ "name": "user_email_unique",
+ "columns": [
+ "email"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "verification": {
+ "name": "verification",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "identifier": {
+ "name": "identifier",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "value": {
+ "name": "value",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "expiresAt": {
+ "name": "expiresAt",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "createdAt": {
+ "name": "createdAt",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(cast(unixepoch('subsecond') * 1000 as integer))"
+ },
+ "updatedAt": {
+ "name": "updatedAt",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "(cast(unixepoch('subsecond') * 1000 as integer))"
+ }
+ },
+ "indexes": {
+ "verification_identifier_idx": {
+ "name": "verification_identifier_idx",
+ "columns": [
+ "identifier"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ }
+ },
+ "views": {},
+ "enums": {},
+ "_meta": {
+ "schemas": {},
+ "tables": {},
+ "columns": {}
+ },
+ "internal": {
+ "indexes": {}
+ }
+}
\ No newline at end of file
diff --git a/apps/chat/server/db/migrations/sqlite/meta/_journal.json b/apps/chat/server/db/migrations/sqlite/meta/_journal.json
index aec043f..0607982 100644
--- a/apps/chat/server/db/migrations/sqlite/meta/_journal.json
+++ b/apps/chat/server/db/migrations/sqlite/meta/_journal.json
@@ -8,6 +8,13 @@
"when": 1770820891486,
"tag": "0000_tense_maginty",
"breakpoints": true
+ },
+ {
+ "idx": 1,
+ "version": "6",
+ "when": 1770830814679,
+ "tag": "0001_daffy_masque",
+ "breakpoints": true
}
]
}
\ No newline at end of file
diff --git a/apps/chat/server/middleware/api-auth.ts b/apps/chat/server/middleware/api-auth.ts
deleted file mode 100644
index 74d45ac..0000000
--- a/apps/chat/server/middleware/api-auth.ts
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * Optional API key authentication middleware
- *
- * Only enforces authentication if SAVOIR_SECRET_KEY is set.
- * If not set, all requests are allowed (useful for development).
- *
- * Protects:
- * - /api/sync/*
- * - /api/sandbox/*
- *
- * Expected header: Authorization: Bearer <api-key>
- */
-export default defineEventHandler((event) => {
- const path = getRequestURL(event).pathname
-
- if (!path.startsWith('/api/sync') && !path.startsWith('/api/sandbox')) {
- return
- }
-
- const config = useRuntimeConfig()
- const secretKey = config.savoirSecretKey
-
- if (!secretKey) {
- return
- }
-
- const authHeader = getHeader(event, 'Authorization')
- const apiKey = authHeader?.replace('Bearer ', '')
-
- if (!apiKey || apiKey !== secretKey) {
- throw createError({
- statusCode: 401,
- message: 'Invalid or missing API key',
- })
- }
-})
diff --git a/packages/sdk/src/types.ts b/packages/sdk/src/types.ts
index e50cac8..4ebb2c2 100644
--- a/packages/sdk/src/types.ts
+++ b/packages/sdk/src/types.ts
@@ -1,7 +1,7 @@
export interface SavoirConfig {
/** Base URL of your Savoir API (e.g., 'https://chat.example.com') */
apiUrl: string
- /** API key for authentication. Required if the API has SAVOIR_SECRET_KEY configured. */
+ /** API key for authentication. Create one from the admin panel (/admin/api-keys) or user settings (/settings/api-keys). */
apiKey?: string
/** Reuse an existing sandbox session instead of creating a new one. */
sessionId?: string