Open source file-system and knowledge based agent template. Build AI agents that stay up to date with your knowledge base
improve users admin and make AI_GATEWAY_KEY optional
Hugo Richard08bdb262bb35
diff --git a/README.md b/README.mdindex 3440850..6ab0780 100644--- a/README.md+++ b/README.md@@ -14,7 +14,7 @@</p><p align="center">- <a href="https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fvercel-labs%2Fknowledge-agent-template&env=BETTER_AUTH_SECRET,GITHUB_CLIENT_ID,GITHUB_CLIENT_SECRET,AI_GATEWAY_API_KEY&envDescription=BETTER_AUTH_SECRET%3A%20run%20openssl%20rand%20-hex%2032%20%7C%20GITHUB_CLIENT_ID%20%2B%20SECRET%3A%20create%20a%20GitHub%20App%20at%20github.com%2Fsettings%2Fapps%2Fnew%20%7C%20AI_GATEWAY_API_KEY%3A%20create%20a%20gateway%20at%20vercel.com%2F~%2Fai&envLink=https%3A%2F%2Fgithub.com%2Fvercel-labs%2Fknowledge-agent-template%2Fblob%2Fmain%2Fdocs%2FENVIRONMENT.md&project-name=knowledge-agent&repository-name=knowledge-agent"><img src="https://vercel.com/button" alt="Deploy with Vercel" /></a>+ <a href="https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fvercel-labs%2Fknowledge-agent-template&env=BETTER_AUTH_SECRET,GITHUB_CLIENT_ID,GITHUB_CLIENT_SECRET&envDescription=BETTER_AUTH_SECRET%3A%20run%20openssl%20rand%20-hex%2032%20%7C%20GITHUB_CLIENT_ID%20%2B%20SECRET%3A%20create%20a%20GitHub%20App%20at%20github.com%2Fsettings%2Fapps%2Fnew&envLink=https%3A%2F%2Fgithub.com%2Fvercel-labs%2Fknowledge-agent-template%2Fblob%2Fmain%2Fdocs%2FENVIRONMENT.md&project-name=knowledge-agent&repository-name=knowledge-agent"><img src="https://vercel.com/button" alt="Deploy with Vercel" /></a></p>---@@ -120,7 +120,7 @@ console.log(text)### Deploy to Vercel-[](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fvercel-labs%2Fknowledge-agent-template&env=BETTER_AUTH_SECRET,GITHUB_CLIENT_ID,GITHUB_CLIENT_SECRET,AI_GATEWAY_API_KEY&envDescription=BETTER_AUTH_SECRET%3A%20run%20openssl%20rand%20-hex%2032%20%7C%20GITHUB_CLIENT_ID%20%2B%20SECRET%3A%20create%20a%20GitHub%20App%20at%20github.com%2Fsettings%2Fapps%2Fnew%20%7C%20AI_GATEWAY_API_KEY%3A%20create%20a%20gateway%20at%20vercel.com%2F~%2Fai&envLink=https%3A%2F%2Fgithub.com%2Fvercel-labs%2Fknowledge-agent-template%2Fblob%2Fmain%2Fdocs%2FENVIRONMENT.md&project-name=knowledge-agent&repository-name=knowledge-agent)+[](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fvercel-labs%2Fknowledge-agent-template&env=BETTER_AUTH_SECRET,GITHUB_CLIENT_ID,GITHUB_CLIENT_SECRET&envDescription=BETTER_AUTH_SECRET%3A%20run%20openssl%20rand%20-hex%2032%20%7C%20GITHUB_CLIENT_ID%20%2B%20SECRET%3A%20create%20a%20GitHub%20App%20at%20github.com%2Fsettings%2Fapps%2Fnew&envLink=https%3A%2F%2Fgithub.com%2Fvercel-labs%2Fknowledge-agent-template%2Fblob%2Fmain%2Fdocs%2FENVIRONMENT.md&project-name=knowledge-agent&repository-name=knowledge-agent)### Self-hosting@@ -148,8 +148,8 @@ BETTER_AUTH_SECRET=your-secret # Secret for signing sessions/tokensGITHUB_CLIENT_ID=... # GitHub OAuth app client IDGITHUB_CLIENT_SECRET=... # GitHub OAuth app client secret-# AI-AI_GATEWAY_API_KEY=... # Vercel AI Gateway API key+# AI (optional — only needed for local dev, Vercel uses OIDC automatically)+# AI_GATEWAY_API_KEY=... # Vercel AI Gateway API key# Sandbox# NUXT_GITHUB_SNAPSHOT_REPO=org/repo # Optional default (can be set from admin sandbox UI)diff --git a/apps/app/.env.example b/apps/app/.env.exampleindex b547455..b38aca6 100644--- a/apps/app/.env.example+++ b/apps/app/.env.example@@ -12,7 +12,7 @@ GITHUB_CLIENT_SECRET= # GitHub OAuth app client secret# --- AI -----------------------------------------------------------------------AI_GATEWAY_API_KEY= # Vercel AI Gateway API key+# AI_GATEWAY_API_KEY= # Vercel AI Gateway API key (only needed for local dev, Vercel uses OIDC)# --- Sandbox & Sync ----------------------------------------------------------diff --git a/apps/app/app/app.config.ts b/apps/app/app/app.config.tsindex 3743eed..ab815e9 100644--- a/apps/app/app/app.config.ts+++ b/apps/app/app/app.config.ts@@ -4,7 +4,7 @@ export default defineAppConfig({description: 'Open source file-system and knowledge based agent template.',icon: 'i-simple-icons-vercel',repoUrl: 'https://github.com/vercel-labs/knowledge-agent-template',- deployUrl: 'https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fvercel-labs%2Fknowledge-agent-template&env=BETTER_AUTH_SECRET,GITHUB_CLIENT_ID,GITHUB_CLIENT_SECRET,AI_GATEWAY_API_KEY&envDescription=BETTER_AUTH_SECRET%3A%20run%20openssl%20rand%20-hex%2032%20%7C%20GITHUB_CLIENT_ID%20%2B%20SECRET%3A%20create%20a%20GitHub%20App%20at%20github.com%2Fsettings%2Fapps%2Fnew%20%7C%20AI_GATEWAY_API_KEY%3A%20create%20a%20gateway%20at%20vercel.com%2F~%2Fai&envLink=https%3A%2F%2Fgithub.com%2Fvercel-labs%2Fknowledge-agent-template%2Fblob%2Fmain%2Fdocs%2FENVIRONMENT.md&project-name=knowledge-agent&repository-name=knowledge-agent',+ deployUrl: 'https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fvercel-labs%2Fknowledge-agent-template&env=BETTER_AUTH_SECRET,GITHUB_CLIENT_ID,GITHUB_CLIENT_SECRET&envDescription=BETTER_AUTH_SECRET%3A%20run%20openssl%20rand%20-hex%2032%20%7C%20GITHUB_CLIENT_ID%20%2B%20SECRET%3A%20create%20a%20GitHub%20App%20at%20github.com%2Fsettings%2Fapps%2Fnew&envLink=https%3A%2F%2Fgithub.com%2Fvercel-labs%2Fknowledge-agent-template%2Fblob%2Fmain%2Fdocs%2FENVIRONMENT.md&project-name=knowledge-agent&repository-name=knowledge-agent',},ui: {colors: {diff --git a/apps/app/app/content/docs/getting-started.md b/apps/app/app/content/docs/getting-started.mdindex 6474231..31cbfb9 100644--- a/apps/app/app/content/docs/getting-started.md+++ b/apps/app/app/content/docs/getting-started.md@@ -15,7 +15,7 @@ cp apps/app/.env.example apps/app/.env| `BETTER_AUTH_SECRET` | Secret used to sign sessions and tokens. See [Better Auth docs](https://www.better-auth.com/docs/installation#set-environment-variables). || `GITHUB_CLIENT_ID` | GitHub App client ID (used for OAuth login). See [GitHub App Setup](#github-app-setup) below. || `GITHUB_CLIENT_SECRET` | GitHub App client secret |-| `AI_GATEWAY_API_KEY` | [Vercel AI Gateway](https://ai-sdk.dev) API key |+| `AI_GATEWAY_API_KEY` | [Vercel AI Gateway](https://ai-sdk.dev) API key (optional on Vercel — OIDC handles auth automatically, only needed for local dev) |`NUXT_GITHUB_SNAPSHOT_REPO` and `NUXT_GITHUB_TOKEN` are optional. You can configure the snapshot repository in the admin sandbox UI after startup, and the app uses a GitHub App installation access token automatically when app credentials are configured.diff --git a/apps/app/app/pages/admin/users.vue b/apps/app/app/pages/admin/users.vueindex 3c72a3f..eb54320 100644--- a/apps/app/app/pages/admin/users.vue+++ b/apps/app/app/pages/admin/users.vue@@ -1,4 +1,7 @@<script setup lang="ts">+import { getPaginationRowModel, getSortedRowModel } from '@tanstack/vue-table'+import type { TableColumn } from '@nuxt/ui'+useSeoMeta({ title: 'Users - Admin' })type UserRole = 'user' | 'admin'@@ -19,46 +22,75 @@ const toast = useToast()const { showError } = useErrorToast()const { user: currentUser } = useUserSession()-const searchQuery = ref('')-const roleFilter = ref<'all' | UserRole>('all')+const table = useTemplateRef('table')const savingUserId = ref<string | null>(null)-const draftRoles = ref<Record<string, UserRole>>({})+const deletingUserId = ref<string | null>(null)+const userToDelete = ref<AdminUserRow | null>(null)-const roleOptions = [- { label: 'User', value: 'user' },- { label: 'Admin', value: 'admin' },-]+const globalFilter = ref('')+const sorting = ref([{ id: 'createdAt', desc: true }])+const pagination = ref({ pageIndex: 0, pageSize: 10 })++const deleteModalOpen = computed({+ get: () => userToDelete.value !== null,+ set: (v: boolean) => { if (!v) userToDelete.value = null },+})-const filterOptions = [- { label: 'All roles', value: 'all' },- { label: 'Admins', value: 'admin' },- { label: 'Users', value: 'user' },+const columns: TableColumn<AdminUserRow>[] = [+ {+ accessorKey: 'name',+ header: 'User',+ enableSorting: true,+ filterFn: (row, _columnId, filterValue) => {+ const q = (filterValue as string).toLowerCase()+ const name = row.original.name?.toLowerCase() ?? ''+ const email = row.original.email?.toLowerCase() ?? ''+ return name.includes(q) || email.includes(q)+ },+ },+ {+ accessorKey: 'chatCount',+ header: 'Chats',+ enableSorting: true,+ meta: { class: { th: 'text-right w-20', td: 'text-right' } },+ },+ {+ accessorKey: 'messageCount',+ header: 'Msgs',+ enableSorting: true,+ meta: { class: { th: 'text-right w-20', td: 'text-right' } },+ },+ {+ accessorKey: 'lastSeenAt',+ header: 'Last active',+ enableSorting: true,+ meta: { class: { th: 'w-28' } },+ },+ {+ accessorKey: 'role',+ header: 'Role',+ meta: { class: { th: 'w-24' } },+ },+ {+ accessorKey: 'actions',+ header: '',+ meta: { class: { th: 'w-10' } },+ },]const { data: users, refresh, status } = useLazyFetch<AdminUserRow[]>('/api/admin/users')-watch(users, (rows) => {- if (!rows) return- draftRoles.value = Object.fromEntries(rows.map(row => [row.id, row.role]))-}, { immediate: true })+const totalUsers = computed(() => users.value?.length ?? 0)+const adminCount = computed(() => users.value?.filter(u => u.role === 'admin').length ?? 0)+const activeCount = computed(() => users.value?.filter(u => u.lastSeenAt !== null).length ?? 0)-const filteredUsers = computed(() => {- if (!users.value) return []+const filteredRowCount = computed(() =>+ table.value?.tableApi?.getFilteredRowModel().rows.length ?? 0,+)- const query = searchQuery.value.trim().toLowerCase()-- return users.value.filter((user) => {- if (roleFilter.value !== 'all' && user.role !== roleFilter.value) {- return false- }-- if (!query) return true-- const name = user.name?.toLowerCase() ?? ''- const email = user.email?.toLowerCase() ?? ''- return name.includes(query) || email.includes(query)- })-})+const pageCount = computed(() =>+ table.value?.tableApi?.getPageCount() ?? 0,+)function formatDate(date: string | null): string {if (!date) return 'Never'@@ -69,18 +101,47 @@ function isCurrentUser(userId: string): boolean {return currentUser.value?.id === userId}-async function saveRole(row: AdminUserRow) {- const nextRole = draftRoles.value[row.id]- if (!nextRole || nextRole === row.role) return+function getRowActions(row: AdminUserRow) {+ if (isCurrentUser(row.id)) return []+ return [[{+ label: 'Delete user',+ icon: 'i-lucide-trash-2',+ color: 'error' as const,+ onSelect: () => { userToDelete.value = row },+ }]]+}++async function deleteUser() {+ const row = userToDelete.value+ if (!row) return- if (isCurrentUser(row.id) && nextRole !== 'admin') {+ deletingUserId.value = row.id+ try {+ await $fetch(`/api/admin/users/${row.id}`, { method: 'DELETE' })+ userToDelete.value = null+ await refresh()+ toast.add({+ title: 'User deleted',+ description: `${row.name || row.email || 'User'} has been deleted.`,+ icon: 'i-lucide-check',+ })+ } catch (e) {+ showError(e, { fallback: 'Failed to delete user' })+ } finally {+ deletingUserId.value = null+ }+}++async function changeRole(row: AdminUserRow, newRole: UserRole) {+ if (newRole === row.role) return++ if (isCurrentUser(row.id)) {toast.add({title: 'Not allowed',- description: 'You cannot remove your own admin role.',+ description: 'You cannot change your own role.',color: 'error',icon: 'i-lucide-alert-circle',})- draftRoles.value[row.id] = row.rolereturn}@@ -88,7 +149,7 @@ async function saveRole(row: AdminUserRow) {try {await $fetch(`/api/admin/users/${row.id}`, {method: 'PATCH',- body: { role: nextRole },+ body: { role: newRole },})await refresh()toast.add({@@ -96,7 +157,6 @@ async function saveRole(row: AdminUserRow) {icon: 'i-lucide-check',})} catch (e) {- draftRoles.value[row.id] = row.roleshowError(e, { fallback: 'Failed to update role' })} finally {savingUserId.value = null@@ -106,151 +166,221 @@ async function saveRole(row: AdminUserRow) {<template><div class="px-6 py-8 max-w-4xl mx-auto w-full">- <header class="mb-8">- <h1 class="text-lg font-medium text-highlighted mb-1 font-pixel tracking-wide">- Users- </h1>- <p class="text-sm text-muted max-w-lg">- Manage user access and roles across the platform.- </p>+ <header class="mb-6">+ <div class="flex items-center justify-between gap-4">+ <div>+ <h1 class="text-lg font-medium text-highlighted mb-1 font-pixel tracking-wide">+ Users+ </h1>+ <p class="text-sm text-muted max-w-lg">+ Manage user access and roles across the platform.+ </p>+ </div>+ <UTooltip text="Refresh data">+ <UButton+ icon="i-lucide-refresh-cw"+ color="neutral"+ variant="ghost"+ size="xs"+ :loading="status === 'pending'"+ @click="refresh()"+ />+ </UTooltip>+ </div></header>- <div class="flex flex-col gap-6">- <section>- <h2 class="text-[10px] text-muted uppercase tracking-wide mb-3 font-pixel">+ <div class="grid grid-cols-3 gap-4 mb-6">+ <div class="rounded-lg border border-default bg-elevated/50 p-4">+ <p class="text-xs text-muted mb-1">+ Total Users+ </p>+ <p class="text-2xl font-semibold text-highlighted tabular-nums">+ {{ totalUsers }}+ </p>+ </div>+ <div class="rounded-lg border border-default bg-elevated/50 p-4">+ <p class="text-xs text-muted mb-1">+ Admins+ </p>+ <p class="text-2xl font-semibold text-highlighted tabular-nums">+ {{ adminCount }}+ </p>+ </div>+ <div class="rounded-lg border border-default bg-elevated/50 p-4">+ <p class="text-xs text-muted mb-1">+ Active+ </p>+ <p class="text-2xl font-semibold text-highlighted tabular-nums">+ {{ activeCount }}+ </p>+ </div>+ </div>++ <section>+ <div class="flex items-center justify-between mb-3">+ <h2 class="text-[10px] text-muted uppercase tracking-wide font-pixel">Directory</h2>+ <p v-if="filteredRowCount && globalFilter" class="text-xs text-muted">+ {{ filteredRowCount }} result{{ filteredRowCount !== 1 ? 's' : '' }}+ </p>+ </div>- <div class="rounded-lg border border-default p-3 mb-3">- <div class="flex flex-wrap items-center gap-2">- <UInput- v-model="searchQuery"- icon="i-lucide-search"- placeholder="Search by name or email"- size="xs"- class="w-full sm:w-72"- />- <USelect- v-model="roleFilter"- :items="filterOptions"- value-key="value"+ <UInput+ v-model="globalFilter"+ icon="i-lucide-search"+ placeholder="Search users..."+ size="xs"+ class="mb-3 max-w-xs"+ />++ <UTable+ ref="table"+ :data="users ?? []"+ :columns="columns"+ :loading="status === 'pending' && !users"+ v-model:global-filter="globalFilter"+ :global-filter-options="{ filterFn: 'custom' }"+ v-model:sorting="sorting"+ :sorting-options="{ getSortedRowModel: getSortedRowModel() }"+ v-model:pagination="pagination"+ :pagination-options="{ getPaginationRowModel: getPaginationRowModel() }"+ >+ <template #name-cell="{ row }">+ <div class="flex items-center gap-2.5 min-w-0">+ <UAvatar :src="row.original.image || undefined" :alt="row.original.name || row.original.email || undefined" size="xs" />+ <div class="min-w-0">+ <div class="flex items-center gap-1.5">+ <p class="text-highlighted truncate text-xs">+ {{ row.original.name || 'Unnamed user' }}+ </p>+ <UBadge+ v-if="isCurrentUser(row.original.id)"+ label="You"+ size="xs"+ color="neutral"+ variant="subtle"+ />+ </div>+ <p class="text-[11px] text-muted truncate">+ {{ row.original.email || 'No email' }}+ </p>+ </div>+ </div>+ </template>++ <template #chatCount-cell="{ row }">+ <span class="text-muted tabular-nums text-xs">{{ row.original.chatCount }}</span>+ </template>++ <template #messageCount-cell="{ row }">+ <span class="text-muted tabular-nums text-xs">{{ row.original.messageCount }}</span>+ </template>++ <template #lastSeenAt-cell="{ row }">+ <span class="text-muted text-xs">{{ formatDate(row.original.lastSeenAt) }}</span>+ </template>++ <template #role-cell="{ row }">+ <UDropdownMenu+ :items="[+ [+ { label: 'User', icon: 'i-lucide-user', onSelect: () => changeRole(row.original, 'user'), disabled: row.original.role === 'user' },+ { label: 'Admin', icon: 'i-lucide-shield', onSelect: () => changeRole(row.original, 'admin'), disabled: row.original.role === 'admin' },+ ],+ ]"+ :disabled="isCurrentUser(row.original.id) || savingUserId === row.original.id"+ >+ <UButtonsize="xs"- class="w-36"- />+ variant="ghost"+ color="neutral"+ :loading="savingUserId === row.original.id"+ :disabled="isCurrentUser(row.original.id)"+ trailing-icon="i-lucide-chevron-down"+ class="w-22"+ >+ <UIcon :name="row.original.role === 'admin' ? 'i-lucide-shield' : 'i-lucide-user'" class="size-3 text-muted" />+ <span class="capitalize text-xs">{{ row.original.role }}</span>+ </UButton>+ </UDropdownMenu>+ </template>++ <template #actions-cell="{ row }">+ <UDropdownMenu+ v-if="!isCurrentUser(row.original.id)"+ :items="getRowActions(row.original)"+ ><UButton+ icon="i-lucide-ellipsis"color="neutral"variant="ghost"- icon="i-lucide-refresh-cw"size="xs"- :loading="status === 'pending'"- @click="refresh()"- >- Refresh- </UButton>+ />+ </UDropdownMenu>+ </template>++ <template #empty>+ <div class="py-8 text-center">+ <p class="text-sm text-muted">+ {{ globalFilter ? 'No users match your search.' : 'No users found.' }}+ </p></div>- </div>+ </template>+ </UTable>- <div class="rounded-lg border border-default overflow-hidden">- <div v-if="status === 'pending' && !users" 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-8 rounded-full" />- <div>- <USkeleton class="h-4 w-32 mb-1" />- <USkeleton class="h-3 w-48" />- </div>- </div>- <USkeleton class="h-8 w-36 rounded-md" />+ <div v-if="pageCount > 1" class="flex items-center justify-between mt-3 px-1">+ <p class="text-xs text-muted">+ {{ filteredRowCount }} user{{ filteredRowCount !== 1 ? 's' : '' }}+ </p>+ <UPagination+ :page="(pagination.pageIndex || 0) + 1"+ :items-per-page="pagination.pageSize"+ :total="filteredRowCount"+ size="xs"+ @update:page="(p: number) => pagination = { ...pagination, pageIndex: p - 1 }"+ />+ </div>+ </section>++ <UModal v-model:open="deleteModalOpen">+ <template #content>+ <div class="p-6">+ <div class="flex items-center gap-3 mb-4">+ <div class="size-10 rounded-lg bg-error/10 flex items-center justify-center">+ <UIcon name="i-lucide-triangle-alert" class="size-5 text-error" />+ </div>+ <div>+ <h3 class="text-sm font-medium text-highlighted">+ Delete user+ </h3>+ <p class="text-xs text-muted">+ This action cannot be undone.+ </p></div></div>-- <table v-else-if="filteredUsers.length > 0" class="w-full text-sm">- <thead class="bg-elevated/50 border-b border-default">- <tr class="text-xs text-muted">- <th class="text-left font-medium px-4 py-2.5">- User- </th>- <th class="text-right font-medium px-3 py-2.5">- Chats- </th>- <th class="text-right font-medium px-3 py-2.5">- Messages- </th>- <th class="text-left font-medium px-3 py-2.5">- Last active- </th>- <th class="text-left font-medium px-4 py-2.5">- Role- </th>- </tr>- </thead>- <tbody class="divide-y divide-default">- <tr- v-for="row in filteredUsers"- :key="row.id"- class="hover:bg-elevated/30"- >- <td class="px-4 py-2.5">- <div class="flex items-center gap-3 min-w-0">- <UAvatar :src="row.image || undefined" :alt="row.name || row.email || undefined" size="xs" />- <div class="min-w-0">- <div class="flex items-center gap-2">- <p class="text-highlighted truncate">- {{ row.name || 'Unnamed user' }}- </p>- <UBadge- v-if="isCurrentUser(row.id)"- label="You"- size="xs"- color="neutral"- variant="subtle"- />- </div>- <p class="text-xs text-muted truncate">- {{ row.email || 'No email' }} · Joined {{ formatDate(row.createdAt) }}- </p>- </div>- </div>- </td>- <td class="px-3 py-2.5 text-right text-muted tabular-nums">- {{ row.chatCount.toLocaleString() }}- </td>- <td class="px-3 py-2.5 text-right text-muted tabular-nums">- {{ row.messageCount.toLocaleString() }}- </td>- <td class="px-3 py-2.5 text-muted">- {{ formatDate(row.lastSeenAt) }}- </td>- <td class="px-4 py-2.5">- <div class="flex items-center gap-2">- <USelect- v-model="draftRoles[row.id]"- :items="roleOptions"- value-key="value"- class="w-28"- size="xs"- :disabled="savingUserId === row.id || isCurrentUser(row.id)"- />- <UButton- label="Save"- size="xs"- :disabled="draftRoles[row.id] === row.role || isCurrentUser(row.id)"- :loading="savingUserId === row.id"- @click="saveRole(row)"- />- </div>- </td>- </tr>- </tbody>- </table>-- <div v-else class="px-4 py-10 text-center">- <p class="text-sm text-muted">- No users match your current filters.- </p>+ <p class="text-sm text-muted mb-6">+ Are you sure you want to delete <span class="font-medium text-highlighted">{{ userToDelete?.name || userToDelete?.email || 'this user' }}</span>?+ All their chats and messages will be permanently removed.+ </p>+ <div class="flex justify-end gap-2">+ <UButton+ label="Cancel"+ color="neutral"+ variant="ghost"+ size="sm"+ @click="userToDelete = null"+ />+ <UButton+ label="Delete"+ color="error"+ size="sm"+ :loading="deletingUserId === userToDelete?.id"+ @click="deleteUser()"+ /></div></div>- </section>- </div>+ </template>+ </UModal></div></template>diff --git a/apps/app/server/api/admin/users/[id].delete.ts b/apps/app/server/api/admin/users/[id].delete.tsnew file mode 100644index 0000000..36a210b--- /dev/null+++ b/apps/app/server/api/admin/users/[id].delete.ts@@ -0,0 +1,37 @@+import { db, schema } from '@nuxthub/db'+import { eq } from 'drizzle-orm'++export default defineEventHandler(async (event) => {+ const requestLog = useLogger(event)+ const { user: currentUser } = await requireAdmin(event)++ const id = getRouterParam(event, 'id')+ if (!id) {+ throw createError({ statusCode: 400, message: 'Missing user ID', data: { why: 'The user ID parameter is required in the URL', fix: 'Include the user ID in the request URL: /api/admin/users/:id' } })+ }++ requestLog.set({ adminUserId: currentUser.id, targetUserId: id })++ if (id === currentUser.id) {+ throw createError({ statusCode: 400, message: 'You cannot delete your own account', data: { why: 'Deleting your own account would lock you out', fix: 'Ask another admin to delete your account instead' } })+ }++ const [existingUser] = await db+ .select({ id: schema.user.id })+ .from(schema.user)+ .where(eq(schema.user.id, id))+ .limit(1)++ if (!existingUser) {+ throw createError({ statusCode: 404, message: 'User not found', data: { why: 'No user exists with this ID', fix: 'Verify the user ID from the users list' } })+ }++ // Delete chats first (no FK cascade from chats to user)+ // Messages cascade from chats via FK onDelete: cascade+ await db.delete(schema.chats).where(eq(schema.chats.userId, id))++ // Delete user (sessions, accounts, apikeys cascade via FK)+ await db.delete(schema.user).where(eq(schema.user.id, id))++ return { deleted: true }+})diff --git a/apps/app/server/api/chats/[id].post.ts b/apps/app/server/api/chats/[id].post.tsindex caaa3e1..3910877 100644--- a/apps/app/server/api/chats/[id].post.ts+++ b/apps/app/server/api/chats/[id].post.ts@@ -83,8 +83,6 @@ export default defineEventHandler(async (event) => {})}- const config = useRuntimeConfig() as any-let stepCount = 0let toolCallCount = 0let totalInputTokens = 0@@ -102,7 +100,6 @@ export default defineEventHandler(async (event) => {const cookie = getHeader(event, 'cookie')const savoir = createSavoir({apiUrl: getRequestURL(event).origin,- apiKey: config.savoir?.apiKey || undefined,headers: cookie ? { cookie } : undefined,sessionId: existingSessionId || undefined,})@@ -160,7 +157,6 @@ export default defineEventHandler(async (event) => {tools: savoir.tools,getAgentConfig,messages,- apiKey: config.savoir?.apiKey ?? '',defaultModel: model,requestId,onRouted: ({ routerConfig, agentConfig, effectiveModel: routedModel, effectiveMaxSteps }) => {@@ -187,7 +183,6 @@ export default defineEventHandler(async (event) => {firstMessage: messages[0],chatId: id as string,requestId,- apiKey: config.savoir?.apiKey ?? '',}): nulldiff --git a/apps/app/server/utils/chat/generate-title.ts b/apps/app/server/utils/chat/generate-title.tsindex dc67449..2e83983 100644--- a/apps/app/server/utils/chat/generate-title.ts+++ b/apps/app/server/utils/chat/generate-title.ts@@ -10,7 +10,8 @@ interface GenerateTitleOptions {firstMessage: UIMessagechatId: stringrequestId: string- apiKey: string+ /** AI Gateway API key. Optional — falls back to OIDC on Vercel or AI_GATEWAY_API_KEY env var. */+ apiKey?: string}/**@@ -20,7 +21,7 @@ interface GenerateTitleOptions {*/export async function generateTitle({ firstMessage, chatId, requestId, apiKey }: GenerateTitleOptions): Promise<string | null> {try {- const gateway = createGateway({ apiKey })+ const gateway = createGateway(apiKey ? { apiKey } : undefined)const { text: title } = await generateText({model: gateway(ROUTER_MODEL),system: `Generate a short chat title (max 30 chars) from the user's message.diff --git a/apps/app/server/utils/model-pricing.ts b/apps/app/server/utils/model-pricing.tsindex 78e60c2..69e7e92 100644--- a/apps/app/server/utils/model-pricing.ts+++ b/apps/app/server/utils/model-pricing.ts@@ -8,10 +8,9 @@ interface ModelPricing {type PricingRecord = Record<string, ModelPricing>export const getModelPricingMap = defineCachedFunction(- async (): Promise<PricingRecord> => {+ async (apiKey?: string): Promise<PricingRecord> => {try {- const config = useRuntimeConfig() as any- const gateway = createGateway({ apiKey: config.savoir?.apiKey })+ const gateway = createGateway(apiKey ? { apiKey } : undefined)const { models } = await gateway.getAvailableModels()const pricing: PricingRecord = {}diff --git a/docs/ENVIRONMENT.md b/docs/ENVIRONMENT.mdindex df11912..eade8f0 100644--- a/docs/ENVIRONMENT.md+++ b/docs/ENVIRONMENT.md@@ -15,9 +15,8 @@ cp apps/app/.env.example apps/app/.env| `BETTER_AUTH_SECRET` | Run `openssl rand -hex 32` in your terminal || `GITHUB_CLIENT_ID` | From your [GitHub App settings](https://github.com/settings/apps) → Client ID || `GITHUB_CLIENT_SECRET` | From your [GitHub App settings](https://github.com/settings/apps) → Generate a client secret |-| `AI_GATEWAY_API_KEY` | From the [Vercel AI Gateway dashboard](https://vercel.com/~/ai) → Create Gateway → Copy API key |-These four variables are all you need to run the app locally. Everything else is optional.+These three variables are all you need to deploy to Vercel. For **local development**, you also need `AI_GATEWAY_API_KEY` (see [AI](#ai) below). Everything else is optional.## Authentication@@ -51,10 +50,12 @@ Session encryption password. Auto-generated if not set.## AI-### `AI_GATEWAY_API_KEY` (required)+### `AI_GATEWAY_API_KEY` (optional — required for local dev only)API key for [Vercel AI Gateway](https://vercel.com/docs/ai-gateway) (used by `@ai-sdk/gateway` to route to any AI model).+On **Vercel deployments**, this is not needed — the project automatically authenticates via the platform's OIDC token. You only need to set this for **local development**.+1. Go to the [Vercel AI dashboard](https://vercel.com/~/ai)2. Create a new Gateway (or use an existing one)3. Copy the API key → `AI_GATEWAY_API_KEY`diff --git a/packages/agent/src/agents/source.ts b/packages/agent/src/agents/source.tsindex 3ef207d..e8e72a4 100644--- a/packages/agent/src/agents/source.ts+++ b/packages/agent/src/agents/source.ts@@ -15,7 +15,8 @@ export interface SourceAgentOptions {tools: Record<string, unknown>getAgentConfig: () => Promise<AgentConfigData>messages: UIMessage[]- apiKey: string+ /** AI Gateway API key. Optional — falls back to OIDC on Vercel or AI_GATEWAY_API_KEY env var. */+ apiKey?: stringrequestId?: string/** Falls back to agentConfig.defaultModel then DEFAULT_MODEL */defaultModel?: stringdiff --git a/packages/agent/src/router/route-question.ts b/packages/agent/src/router/route-question.tsindex 0da0fec..faa3086 100644--- a/packages/agent/src/router/route-question.ts+++ b/packages/agent/src/router/route-question.ts@@ -20,9 +20,9 @@ function extractQuestionFromMessages(messages: UIMessage[]): string {export async function routeQuestion(messages: UIMessage[],requestId: string,- apiKey: string,+ apiKey?: string,): Promise<AgentConfig> {- const gateway = createGateway({ apiKey })+ const gateway = createGateway(apiKey ? { apiKey } : undefined)const question = extractQuestionFromMessages(messages)if (!question) {