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: add admin system (#7)

Hugob1c41eb0860a
diff --git a/apps/chat/app/components/UserMenu.vue b/apps/chat/app/components/UserMenu.vue
index 8729756..91c8baf 100644
--- a/apps/chat/app/components/UserMenu.vue
+++ b/apps/chat/app/components/UserMenu.vue
@@ -9,6 +9,7 @@ defineProps<{
const colorMode = useColorMode()
const appConfig = useAppConfig()
const { user, clear } = useUserSession()
+const { isAdmin } = useAdmin()
const toast = useToast()
const colors = ['red', 'orange', 'amber', 'yellow', 'lime', 'green', 'emerald', 'teal', 'cyan', 'sky', 'blue', 'indigo', 'violet', 'purple', 'fuchsia', 'pink', 'rose']
@@ -67,179 +68,187 @@ async function triggerSnapshot() {
}
}
-const items = computed<DropdownMenuItem[][]>(() => ([
- [
- {
- type: 'label',
- label: user.value?.name || user.value?.username,
- avatar: {
- src: user.value?.avatar,
- alt: user.value?.name || user.value?.username
+const items = computed<DropdownMenuItem[][]>(() => {
+ const baseItems: DropdownMenuItem[][] = [
+ [
+ {
+ type: 'label',
+ label: user.value?.name || user.value?.username,
+ avatar: {
+ src: user.value?.avatar,
+ alt: user.value?.name || user.value?.username
+ }
}
- }
- ], [
- {
- label: 'Theme',
- icon: 'i-lucide-palette',
- children: [
- {
- label: 'Primary',
- slot: 'chip',
- chip: appConfig.ui.colors.primary,
- content: {
- align: 'center',
- collisionPadding: 16
- },
- children: colors.map(color => ({
- label: color,
- chip: color,
+ ], [
+ {
+ label: 'Theme',
+ icon: 'i-lucide-palette',
+ children: [
+ {
+ label: 'Primary',
slot: 'chip',
- checked: appConfig.ui.colors.primary === color,
+ chip: appConfig.ui.colors.primary,
+ content: {
+ align: 'center',
+ collisionPadding: 16
+ },
+ children: colors.map(color => ({
+ label: color,
+ chip: color,
+ slot: 'chip',
+ checked: appConfig.ui.colors.primary === color,
+ type: 'checkbox',
+ onSelect: (e: Event) => {
+ e.preventDefault()
+
+ appConfig.ui.colors.primary = color
+ }
+ }))
+ }, {
+ label: 'Neutral',
+ slot: 'chip',
+ chip: appConfig.ui.colors.neutral === 'neutral' ? 'old-neutral' : appConfig.ui.colors.neutral,
+ content: {
+ align: 'end',
+ collisionPadding: 16
+ },
+ children: neutrals.map(color => ({
+ label: color,
+ chip: color === 'neutral' ? 'old-neutral' : color,
+ slot: 'chip',
+ type: 'checkbox',
+ checked: appConfig.ui.colors.neutral === color,
+ onSelect: (e: Event) => {
+ e.preventDefault()
+
+ appConfig.ui.colors.neutral = color
+ }
+ }))
+ }
+ ]
+ }, {
+ label: 'Appearance',
+ icon: 'i-lucide-sun-moon',
+ children: [
+ {
+ label: 'Light',
+ icon: 'i-lucide-sun',
type: 'checkbox',
+ checked: colorMode.value === 'light',
onSelect: (e: Event) => {
e.preventDefault()
- appConfig.ui.colors.primary = color
+ colorMode.preference = 'light'
}
- }))
- }, {
- label: 'Neutral',
- slot: 'chip',
- chip: appConfig.ui.colors.neutral === 'neutral' ? 'old-neutral' : appConfig.ui.colors.neutral,
- content: {
- align: 'end',
- collisionPadding: 16
- },
- children: neutrals.map(color => ({
- label: color,
- chip: color === 'neutral' ? 'old-neutral' : color,
- slot: 'chip',
+ }, {
+ label: 'Dark',
+ icon: 'i-lucide-moon',
type: 'checkbox',
- checked: appConfig.ui.colors.neutral === color,
- onSelect: (e: Event) => {
+ checked: colorMode.value === 'dark',
+ onUpdateChecked(checked: boolean) {
+ if (checked) {
+ colorMode.preference = 'dark'
+ }
+ },
+ onSelect(e: Event) {
e.preventDefault()
-
- appConfig.ui.colors.neutral = color
}
- }))
- }
- ]
- }, {
- label: 'Appearance',
- icon: 'i-lucide-sun-moon',
- children: [
- {
- label: 'Light',
- icon: 'i-lucide-sun',
- type: 'checkbox',
- checked: colorMode.value === 'light',
- onSelect: (e: Event) => {
- e.preventDefault()
-
- colorMode.preference = 'light'
}
- }, {
- label: 'Dark',
- icon: 'i-lucide-moon',
- type: 'checkbox',
- checked: colorMode.value === 'dark',
- onUpdateChecked(checked: boolean) {
- if (checked) {
- colorMode.preference = 'dark'
- }
- },
- onSelect(e: Event) {
- e.preventDefault()
+ ]
+ }
+ ], [
+ {
+ label: 'Templates',
+ icon: 'i-lucide-layout-template',
+ children: [
+ {
+ label: 'Starter',
+ to: 'https://starter-template.nuxt.dev/'
+ }, {
+ label: 'Landing',
+ to: 'https://landing-template.nuxt.dev/'
+ }, {
+ label: 'Docs',
+ to: 'https://docs-template.nuxt.dev/'
+ }, {
+ label: 'SaaS',
+ to: 'https://saas-template.nuxt.dev/'
+ }, {
+ label: 'Dashboard',
+ to: 'https://dashboard-template.nuxt.dev/'
+ }, {
+ label: 'Chat',
+ to: 'https://chat-template.nuxt.dev/',
+ color: 'primary',
+ checked: true,
+ type: 'checkbox'
+ }, {
+ label: 'Portfolio',
+ to: 'https://portfolio-template.nuxt.dev/'
+ }, {
+ label: 'Changelog',
+ to: 'https://changelog-template.nuxt.dev/'
}
- }
- ]
- }
- ], [
- {
- label: 'Templates',
- icon: 'i-lucide-layout-template',
- children: [
- {
- label: 'Starter',
- to: 'https://starter-template.nuxt.dev/'
- }, {
- label: 'Landing',
- to: 'https://landing-template.nuxt.dev/'
- }, {
- label: 'Docs',
- to: 'https://docs-template.nuxt.dev/'
- }, {
- label: 'SaaS',
- to: 'https://saas-template.nuxt.dev/'
- }, {
- label: 'Dashboard',
- to: 'https://dashboard-template.nuxt.dev/'
- }, {
- label: 'Chat',
- to: 'https://chat-template.nuxt.dev/',
- color: 'primary',
- checked: true,
- type: 'checkbox'
- }, {
- label: 'Portfolio',
- to: 'https://portfolio-template.nuxt.dev/'
- }, {
- label: 'Changelog',
- to: 'https://changelog-template.nuxt.dev/'
- }
- ]
- }
- ], [
- {
- label: 'Documentation',
- icon: 'i-lucide-book-open',
- to: 'https://ui.nuxt.com/docs/getting-started/installation/nuxt',
- target: '_blank'
- }, {
- label: 'GitHub repository',
- icon: 'i-simple-icons-github',
- to: 'https://github.com/nuxt-ui-templates/chat',
- target: '_blank'
- }
- ], [
- {
- label: 'Admin',
- icon: 'i-lucide-settings',
- children: [
- {
- label: 'Sources',
- icon: 'i-lucide-book-open',
- to: '/admin/sources',
- },
- {
- label: 'Sync all',
- icon: 'i-lucide-refresh-cw',
- onSelect: triggerSync,
- },
- {
- label: 'Sync source',
- icon: 'i-lucide-git-branch',
- children: sources.value ? [
- ...sources.value.github.sources.map((source: GitHubSource) => ({
- label: source.label,
- icon: 'i-simple-icons-github',
- onSelect: () => triggerSyncSource(source.id, source.label),
- })),
- ...sources.value.youtube.sources.map((source: YouTubeSource) => ({
- label: source.label,
- icon: 'i-simple-icons-youtube',
- onSelect: () => triggerSyncSource(source.id, source.label),
- })),
- ] : [{ label: 'Loading...', disabled: true }],
- },
- {
- label: 'Create snapshot',
- icon: 'i-lucide-camera',
- onSelect: triggerSnapshot,
- },
- ],
- },
- ], [
+ ]
+ }
+ ], [
+ {
+ label: 'Documentation',
+ icon: 'i-lucide-book-open',
+ to: 'https://ui.nuxt.com/docs/getting-started/installation/nuxt',
+ target: '_blank'
+ }, {
+ label: 'GitHub repository',
+ icon: 'i-simple-icons-github',
+ to: 'https://github.com/nuxt-ui-templates/chat',
+ target: '_blank'
+ }
+ ]
+ ]
+
+ if (isAdmin.value) {
+ baseItems.push([
+ {
+ label: 'Admin',
+ icon: 'i-lucide-settings',
+ children: [
+ {
+ label: 'Sources',
+ icon: 'i-lucide-book-open',
+ to: '/admin/sources',
+ },
+ {
+ label: 'Sync all',
+ icon: 'i-lucide-refresh-cw',
+ onSelect: triggerSync,
+ },
+ {
+ label: 'Sync source',
+ icon: 'i-lucide-git-branch',
+ children: sources.value ? [
+ ...sources.value.github.sources.map((source: GitHubSource) => ({
+ label: source.label,
+ icon: 'i-simple-icons-github',
+ onSelect: () => triggerSyncSource(source.id, source.label),
+ })),
+ ...sources.value.youtube.sources.map((source: YouTubeSource) => ({
+ label: source.label,
+ icon: 'i-simple-icons-youtube',
+ onSelect: () => triggerSyncSource(source.id, source.label),
+ })),
+ ] : [{ label: 'Loading...', disabled: true }],
+ },
+ {
+ label: 'Create snapshot',
+ icon: 'i-lucide-camera',
+ onSelect: triggerSnapshot,
+ },
+ ],
+ },
+ ])
+ }
+
+ baseItems.push([
{
label: 'Log out',
icon: 'i-lucide-log-out',
@@ -248,8 +257,10 @@ const items = computed<DropdownMenuItem[][]>(() => ([
navigateTo('/')
}
}
- ]
-]))
+ ])
+
+ return baseItems
+})
</script>
<template>
diff --git a/apps/chat/app/composables/useAdmin.ts b/apps/chat/app/composables/useAdmin.ts
new file mode 100644
index 0000000..d702a74
--- /dev/null
+++ b/apps/chat/app/composables/useAdmin.ts
@@ -0,0 +1,5 @@
+export function useAdmin() {
+ const { user } = useUserSession()
+ const isAdmin = computed(() => user.value?.role === 'admin')
+ return { isAdmin }
+}
diff --git a/apps/chat/app/layouts/admin.vue b/apps/chat/app/layouts/admin.vue
new file mode 100644
index 0000000..a048024
--- /dev/null
+++ b/apps/chat/app/layouts/admin.vue
@@ -0,0 +1,64 @@
+<script setup lang="ts">
+const { user, clear } = useUserSession()
+
+const navItems = [{ label: 'Sources', to: '/admin/sources', icon: 'i-lucide-book-open' },]
+</script>
+
+<template>
+ <div class="min-h-screen bg-default">
+ <header class="sticky top-0 z-50 border-b border-default bg-elevated/80 backdrop-blur-sm">
+ <div class="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8">
+ <div class="flex items-center justify-between h-14">
+ <div class="flex items-center gap-4">
+ <NuxtLink to="/" class="flex items-center gap-2">
+ <Logo class="h-7 w-auto" />
+ <span class="font-semibold text-highlighted">Admin</span>
+ </NuxtLink>
+
+ <nav class="flex items-center gap-1 ml-4">
+ <NuxtLink
+ v-for="item in navItems"
+ :key="item.to"
+ :to="item.to"
+ class="px-3 py-1.5 text-sm font-medium rounded-md transition-colors"
+ :class="$route.path.startsWith(item.to) ? 'bg-elevated text-highlighted' : 'text-muted hover:text-highlighted hover:bg-elevated/50'"
+ >
+ {{ item.label }}
+ </NuxtLink>
+ </nav>
+ </div>
+
+ <div class="flex items-center gap-3">
+ <UButton
+ to="/"
+ color="neutral"
+ variant="ghost"
+ size="sm"
+ icon="i-lucide-arrow-left"
+ >
+ Back to Chat
+ </UButton>
+
+ <UDropdownMenu
+ :items="[
+ [{ type: 'label', label: user?.name || user?.username, avatar: { src: user?.avatar } }],
+ [{ label: 'Log out', icon: 'i-lucide-log-out', onSelect: () => { clear(); navigateTo('/') } }]
+ ]"
+ >
+ <UAvatar
+ :src="user?.avatar"
+ :alt="user?.name || user?.username"
+ size="sm"
+ class="cursor-pointer"
+ />
+ </UDropdownMenu>
+ </div>
+ </div>
+ </div>
+ </header>
+
+ <main>
+ <slot />
+ </main>
+ </div>
+</template>
diff --git a/apps/chat/app/middleware/admin.ts b/apps/chat/app/middleware/admin.ts
new file mode 100644
index 0000000..0c4f489
--- /dev/null
+++ b/apps/chat/app/middleware/admin.ts
@@ -0,0 +1,6 @@
+export default defineNuxtRouteMiddleware(() => {
+ const { user, loggedIn } = useUserSession()
+ if (!loggedIn.value || user.value?.role !== 'admin') {
+ return navigateTo('/')
+ }
+})
diff --git a/apps/chat/app/pages/admin/sources/index.vue b/apps/chat/app/pages/admin/sources/index.vue
index 4a14c0a..455ab0b 100644
--- a/apps/chat/app/pages/admin/sources/index.vue
+++ b/apps/chat/app/pages/admin/sources/index.vue
@@ -18,7 +18,8 @@ interface SerializedSource {
}
definePageMeta({
- middleware: 'auth',
+ layout: 'admin',
+ middleware: 'admin',
})
const toast = useToast()
@@ -89,139 +90,131 @@ function handleSaved() {
</script>
<template>
- <UDashboardPanel id="admin-sources">
- <template #header>
- <DashboardNavbar />
- </template>
-
- <template #body>
- <UContainer class="py-10 max-w-xl">
- <header class="mb-10">
- <div class="flex items-center justify-between">
- <h1 class="text-lg font-semibold text-highlighted">
- Sources
- </h1>
- <div class="flex items-center gap-1.5">
- <UButton
- v-if="sources?.github?.count || sources?.youtube?.count"
- icon="i-lucide-refresh-cw"
- color="neutral"
- variant="ghost"
- size="xs"
- :loading="isSyncingAll"
- @click="triggerSync()"
- >
- Sync All
- </UButton>
- <UButton
- icon="i-lucide-plus"
- size="xs"
- to="/admin/sources/new"
- >
- Add
- </UButton>
- </div>
- </div>
- <p class="text-[13px] text-muted mt-1">
- Configure sources for documentation sync
- </p>
- </header>
-
- <div
- v-if="!sources?.github?.count && !sources?.youtube?.count"
- class="flex flex-col items-center py-16 border border-dashed border-default rounded-xl"
- >
- <div class="size-10 rounded-lg bg-muted flex items-center justify-center mb-3">
- <UIcon name="i-lucide-layers" class="size-5 text-muted" />
- </div>
- <p class="text-sm font-medium text-highlighted mb-1">
- No sources yet
- </p>
- <p class="text-[13px] text-muted mb-4">
- Add a source to get started
- </p>
+ <UContainer class="py-10 max-w-xl">
+ <header class="mb-10">
+ <div class="flex items-center justify-between">
+ <h1 class="text-lg font-semibold text-highlighted">
+ Sources
+ </h1>
+ <div class="flex items-center gap-1.5">
+ <UButton
+ v-if="sources?.github?.count || sources?.youtube?.count"
+ icon="i-lucide-refresh-cw"
+ color="neutral"
+ variant="ghost"
+ size="xs"
+ :loading="isSyncingAll"
+ @click="triggerSync()"
+ >
+ Sync All
+ </UButton>
<UButton
icon="i-lucide-plus"
- size="sm"
+ size="xs"
to="/admin/sources/new"
>
- Add Source
+ Add
</UButton>
</div>
+ </div>
+ <p class="text-[13px] text-muted mt-1">
+ Configure sources for documentation sync
+ </p>
+ </header>
+
+ <div
+ v-if="!sources?.github?.count && !sources?.youtube?.count"
+ class="flex flex-col items-center py-16 border border-dashed border-default rounded-xl"
+ >
+ <div class="size-10 rounded-lg bg-muted flex items-center justify-center mb-3">
+ <UIcon name="i-lucide-layers" class="size-5 text-muted" />
+ </div>
+ <p class="text-sm font-medium text-highlighted mb-1">
+ No sources yet
+ </p>
+ <p class="text-[13px] text-muted mb-4">
+ Add a source to get started
+ </p>
+ <UButton
+ icon="i-lucide-plus"
+ size="sm"
+ to="/admin/sources/new"
+ >
+ Add Source
+ </UButton>
+ </div>
+
+ <div v-else class="space-y-8">
+ <section>
+ <header class="flex items-center gap-2 mb-2">
+ <UIcon name="i-simple-icons-github" class="size-4 text-muted" />
+ <h2 class="text-[13px] font-medium text-muted">
+ GitHub
+ </h2>
+ <span class="text-[13px] text-muted/60">{{ sources?.github?.count || 0 }}</span>
+ </header>
- <div v-else class="space-y-8">
- <section>
- <header class="flex items-center gap-2 mb-2">
- <UIcon name="i-simple-icons-github" class="size-4 text-muted" />
- <h2 class="text-[13px] font-medium text-muted">
- GitHub
- </h2>
- <span class="text-[13px] text-muted/60">{{ sources?.github?.count || 0 }}</span>
- </header>
-
- <div
- v-if="sources?.github?.count"
- class="rounded-lg border border-default bg-default divide-y divide-default"
- >
- <div v-for="source in sources.github.sources" :key="source.id" class="px-4">
- <SourceCard
- :source
- @edit="editingSource = source"
- @delete="deleteSource(source)"
- @sync="triggerSync(source.id)"
- />
- </div>
- </div>
- <UButton
- v-else
- variant="ghost"
- class="w-full h-24 rounded-lg border border-dashed border-default hover:border-muted"
- to="/admin/sources/new"
- >
- <span class="text-[13px] text-muted">Add a repository</span>
- </UButton>
- </section>
-
- <section>
- <header class="flex items-center gap-2 mb-2">
- <UIcon name="i-simple-icons-youtube" class="size-4 text-red-500" />
- <h2 class="text-[13px] font-medium text-muted">
- YouTube
- </h2>
- <span class="text-[13px] text-muted/60">{{ sources?.youtube?.count || 0 }}</span>
- </header>
-
- <div
- v-if="sources?.youtube?.count"
- class="rounded-lg border border-default bg-default divide-y divide-default"
- >
- <div v-for="source in sources.youtube.sources" :key="source.id" class="px-4">
- <SourceCard
- :source
- @edit="editingSource = source"
- @delete="deleteSource(source)"
- @sync="triggerSync(source.id)"
- />
- </div>
- </div>
- <UButton
- v-else
- variant="ghost"
- class="w-full h-24 rounded-lg border border-dashed border-default hover:border-muted"
- to="/admin/sources/new"
- >
- <span class="text-[13px] text-muted">Add a channel</span>
- </UButton>
- </section>
+ <div
+ v-if="sources?.github?.count"
+ class="rounded-lg border border-default bg-default divide-y divide-default"
+ >
+ <div v-for="source in sources.github.sources" :key="source.id" class="px-4">
+ <SourceCard
+ :source
+ @edit="editingSource = source"
+ @delete="deleteSource(source)"
+ @sync="triggerSync(source.id)"
+ />
+ </div>
+ </div>
+ <UButton
+ v-else
+ variant="ghost"
+ class="w-full h-24 rounded-lg border border-dashed border-default hover:border-muted"
+ to="/admin/sources/new"
+ >
+ <span class="text-[13px] text-muted">Add a repository</span>
+ </UButton>
+ </section>
+
+ <section>
+ <header class="flex items-center gap-2 mb-2">
+ <UIcon name="i-simple-icons-youtube" class="size-4 text-red-500" />
+ <h2 class="text-[13px] font-medium text-muted">
+ YouTube
+ </h2>
+ <span class="text-[13px] text-muted/60">{{ sources?.youtube?.count || 0 }}</span>
+ </header>
+
+ <div
+ v-if="sources?.youtube?.count"
+ class="rounded-lg border border-default bg-default divide-y divide-default"
+ >
+ <div v-for="source in sources.youtube.sources" :key="source.id" class="px-4">
+ <SourceCard
+ :source
+ @edit="editingSource = source"
+ @delete="deleteSource(source)"
+ @sync="triggerSync(source.id)"
+ />
+ </div>
</div>
- </UContainer>
-
- <SourceModal
- v-if="editingSource"
- :source="editingSource"
- @close="editingSource = null"
- @saved="handleSaved"
- />
- </template>
- </UDashboardPanel>
+ <UButton
+ v-else
+ variant="ghost"
+ class="w-full h-24 rounded-lg border border-dashed border-default hover:border-muted"
+ to="/admin/sources/new"
+ >
+ <span class="text-[13px] text-muted">Add a channel</span>
+ </UButton>
+ </section>
+ </div>
+ </UContainer>
+
+ <SourceModal
+ v-if="editingSource"
+ :source="editingSource"
+ @close="editingSource = null"
+ @saved="handleSaved"
+ />
</template>
diff --git a/apps/chat/app/pages/admin/sources/new.vue b/apps/chat/app/pages/admin/sources/new.vue
index c66eb6c..34d159f 100644
--- a/apps/chat/app/pages/admin/sources/new.vue
+++ b/apps/chat/app/pages/admin/sources/new.vue
@@ -30,7 +30,8 @@ const CONFIG_EXTENSIONS = ['.ts', '.js', '.json', '.yml', '.yaml', '.toml']
const CONFIG_ACCEPT = CONFIG_EXTENSIONS.join(',')
definePageMeta({
- middleware: 'auth',
+ layout: 'admin',
+ middleware: 'admin',
})
const router = useRouter()
@@ -296,261 +297,253 @@ const hasValidSources = computed(() => sources.value.some(s => s.data.label))
</script>
<template>
- <UDashboardPanel id="admin-sources-new">
- <template #header>
- <DashboardNavbar />
- </template>
-
- <template #body>
- <UContainer class="py-10 max-w-3xl">
- <header class="mb-8">
- <div class="flex items-center gap-3 mb-1">
- <UButton
- icon="i-lucide-arrow-left"
- color="neutral"
- variant="ghost"
- size="xs"
- to="/admin/sources"
+ <UContainer class="py-10 max-w-3xl">
+ <header class="mb-8">
+ <div class="flex items-center gap-3 mb-1">
+ <UButton
+ icon="i-lucide-arrow-left"
+ color="neutral"
+ variant="ghost"
+ size="xs"
+ to="/admin/sources"
+ />
+ <h1 class="text-lg font-semibold text-highlighted">
+ Add Sources
+ </h1>
+ </div>
+ <p class="text-[13px] text-muted ml-9">
+ Upload screenshots or config files to auto-extract sources
+ </p>
+ </header>
+
+ <div class="space-y-6">
+ <!-- Drop Zone -->
+ <div
+ class="relative p-8 border-2 border-dashed rounded-xl transition-all cursor-pointer"
+ :class="[
+ isDragging ? 'border-primary bg-primary/5 scale-[1.02]' : 'border-default hover:border-muted hover:bg-muted/5',
+ ]"
+ @drop="handleDrop"
+ @dragover="handleDragOver"
+ @dragleave="handleDragLeave"
+ @click="fileInputRef?.click()"
+ >
+ <input
+ ref="fileInputRef"
+ type="file"
+ :accept="`image/*,${CONFIG_ACCEPT}`"
+ multiple
+ class="hidden"
+ @change="handleFileSelect"
+ >
+
+ <div class="text-center">
+ <div class="size-14 rounded-xl bg-muted/50 flex items-center justify-center mx-auto mb-4">
+ <UIcon
+ :name="isDragging ? 'i-lucide-download' : 'i-lucide-files'"
+ class="size-7 text-muted transition-transform"
+ :class="{ 'scale-110': isDragging }"
/>
- <h1 class="text-lg font-semibold text-highlighted">
- Add Sources
- </h1>
</div>
- <p class="text-[13px] text-muted ml-9">
- Upload screenshots or config files to auto-extract sources
+ <p class="text-sm font-medium text-highlighted mb-1">
+ Drop files here
</p>
- </header>
+ <p class="text-xs text-muted">
+ Screenshots, .ts, .json, .yml, .yaml
+ </p>
+ </div>
+ </div>
+
+ <!-- Pending Files -->
+ <div v-if="pendingFiles.length > 0" class="space-y-3">
+ <div class="flex items-center justify-between">
+ <h2 class="text-sm font-medium text-highlighted">
+ Files to extract ({{ pendingFiles.length }})
+ </h2>
+ <UButton
+ icon="i-lucide-sparkles"
+ size="xs"
+ :loading="isExtracting"
+ @click="extractAll"
+ >
+ Extract sources
+ </UButton>
+ </div>
- <div class="space-y-6">
- <!-- Drop Zone -->
+ <div class="flex flex-wrap gap-2">
<div
- class="relative p-8 border-2 border-dashed rounded-xl transition-all cursor-pointer"
- :class="[
- isDragging ? 'border-primary bg-primary/5 scale-[1.02]' : 'border-default hover:border-muted hover:bg-muted/5',
- ]"
- @drop="handleDrop"
- @dragover="handleDragOver"
- @dragleave="handleDragLeave"
- @click="fileInputRef?.click()"
+ v-for="item in pendingFiles"
+ :key="item.id"
+ class="relative group"
>
- <input
- ref="fileInputRef"
- type="file"
- :accept="`image/*,${CONFIG_ACCEPT}`"
- multiple
- class="hidden"
- @change="handleFileSelect"
+ <div
+ v-if="item.type === 'image'"
+ class="w-20 h-14 rounded-lg border border-default overflow-hidden"
>
-
- <div class="text-center">
- <div class="size-14 rounded-xl bg-muted/50 flex items-center justify-center mx-auto mb-4">
- <UIcon
- :name="isDragging ? 'i-lucide-download' : 'i-lucide-files'"
- class="size-7 text-muted transition-transform"
- :class="{ 'scale-110': isDragging }"
- />
- </div>
- <p class="text-sm font-medium text-highlighted mb-1">
- Drop files here
- </p>
- <p class="text-xs text-muted">
- Screenshots, .ts, .json, .yml, .yaml
- </p>
- </div>
- </div>
-
- <!-- Pending Files -->
- <div v-if="pendingFiles.length > 0" class="space-y-3">
- <div class="flex items-center justify-between">
- <h2 class="text-sm font-medium text-highlighted">
- Files to extract ({{ pendingFiles.length }})
- </h2>
- <UButton
- icon="i-lucide-sparkles"
- size="xs"
- :loading="isExtracting"
- @click="extractAll"
+ <img
+ :src="item.previewUrl"
+ :alt="item.file.name"
+ class="w-full h-full object-cover"
>
- Extract sources
- </UButton>
</div>
+ <div
+ v-else
+ class="w-20 h-14 rounded-lg border border-default bg-muted/30 flex flex-col items-center justify-center gap-1"
+ >
+ <UIcon :name="getFileIcon(item)" class="size-5 text-muted" />
+ <span class="text-[10px] text-muted truncate max-w-16 px-1">{{ item.file.name }}</span>
+ </div>
+ <button
+ class="absolute -top-1.5 -right-1.5 size-5 rounded-full bg-error text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity"
+ @click.stop="removeFile(item.id)"
+ >
+ <UIcon name="i-lucide-x" class="size-3" />
+ </button>
+ </div>
+ </div>
+ </div>
+
+ <!-- Extracted Sources -->
+ <div v-if="sources.length > 0" class="space-y-4">
+ <div class="flex items-center justify-between">
+ <h2 class="text-sm font-medium text-highlighted">
+ Sources ({{ sources.length }})
+ </h2>
+ <UButton
+ icon="i-lucide-plus"
+ size="xs"
+ color="neutral"
+ variant="ghost"
+ @click="addManualSource"
+ >
+ Add manually
+ </UButton>
+ </div>
- <div class="flex flex-wrap gap-2">
- <div
- v-for="item in pendingFiles"
- :key="item.id"
- class="relative group"
- >
- <div
- v-if="item.type === 'image'"
- class="w-20 h-14 rounded-lg border border-default overflow-hidden"
- >
- <img
- :src="item.previewUrl"
- :alt="item.file.name"
- class="w-full h-full object-cover"
- >
+ <div class="space-y-3">
+ <div
+ v-for="source in sources"
+ :key="source.id"
+ class="p-4 rounded-xl border border-default bg-default/50"
+ >
+ <div class="flex items-start gap-4 mb-3">
+ <div class="flex-1 min-w-0">
+ <div v-if="source.confidence < 1" class="text-xs text-muted mb-2">
+ {{ Math.round(source.confidence * 100) }}% confidence
</div>
- <div
- v-else
- class="w-20 h-14 rounded-lg border border-default bg-muted/30 flex flex-col items-center justify-center gap-1"
- >
- <UIcon :name="getFileIcon(item)" class="size-5 text-muted" />
- <span class="text-[10px] text-muted truncate max-w-16 px-1">{{ item.file.name }}</span>
+
+ <div class="grid grid-cols-3 gap-3">
+ <USelectMenu
+ v-model="source.data.type"
+ :items="typeOptions"
+ value-key="value"
+ size="sm"
+ @update:model-value="source.data.basePath = $event === 'youtube' ? '/youtube' : '/docs'"
+ />
+ <div class="col-span-2">
+ <UInput
+ v-model="source.data.label"
+ placeholder="Label (e.g. Nuxt)"
+ size="sm"
+ />
+ </div>
</div>
- <button
- class="absolute -top-1.5 -right-1.5 size-5 rounded-full bg-error text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity"
- @click.stop="removeFile(item.id)"
- >
- <UIcon name="i-lucide-x" class="size-3" />
- </button>
</div>
- </div>
- </div>
- <!-- Extracted Sources -->
- <div v-if="sources.length > 0" class="space-y-4">
- <div class="flex items-center justify-between">
- <h2 class="text-sm font-medium text-highlighted">
- Sources ({{ sources.length }})
- </h2>
<UButton
- icon="i-lucide-plus"
- size="xs"
+ icon="i-lucide-x"
color="neutral"
variant="ghost"
- @click="addManualSource"
- >
- Add manually
- </UButton>
+ size="xs"
+ @click="removeSource(source.id)"
+ />
</div>
<div class="space-y-3">
- <div
- v-for="source in sources"
- :key="source.id"
- class="p-4 rounded-xl border border-default bg-default/50"
- >
- <div class="flex items-start gap-4 mb-3">
- <div class="flex-1 min-w-0">
- <div v-if="source.confidence < 1" class="text-xs text-muted mb-2">
- {{ Math.round(source.confidence * 100) }}% confidence
- </div>
-
- <div class="grid grid-cols-3 gap-3">
- <USelectMenu
- v-model="source.data.type"
- :items="typeOptions"
- value-key="value"
- size="sm"
- @update:model-value="source.data.basePath = $event === 'youtube' ? '/youtube' : '/docs'"
- />
- <div class="col-span-2">
- <UInput
- v-model="source.data.label"
- placeholder="Label (e.g. Nuxt)"
- size="sm"
- />
- </div>
- </div>
- </div>
-
- <UButton
- icon="i-lucide-x"
- color="neutral"
- variant="ghost"
- size="xs"
- @click="removeSource(source.id)"
+ <template v-if="source.data.type === 'github'">
+ <div class="grid grid-cols-3 gap-3">
+ <UInput
+ v-model="source.data.repo"
+ placeholder="owner/repo"
+ size="sm"
+ icon="i-simple-icons-github"
+ />
+ <UInput
+ v-model="source.data.branch"
+ placeholder="main"
+ size="sm"
+ icon="i-lucide-git-branch"
+ />
+ <UInput
+ v-model="source.data.contentPath"
+ placeholder="docs/content"
+ size="sm"
+ icon="i-lucide-folder-open"
/>
</div>
-
- <div class="space-y-3">
- <template v-if="source.data.type === 'github'">
- <div class="grid grid-cols-3 gap-3">
- <UInput
- v-model="source.data.repo"
- placeholder="owner/repo"
- size="sm"
- icon="i-simple-icons-github"
- />
- <UInput
- v-model="source.data.branch"
- placeholder="main"
- size="sm"
- icon="i-lucide-git-branch"
- />
- <UInput
- v-model="source.data.contentPath"
- placeholder="docs/content"
- size="sm"
- icon="i-lucide-folder-open"
- />
- </div>
- </template>
-
- <template v-else>
- <div class="grid grid-cols-2 gap-3">
- <UInput
- v-model="source.data.channelId"
- placeholder="UCxxxx..."
- size="sm"
- icon="i-simple-icons-youtube"
- />
- <UInput
- v-model="source.data.handle"
- placeholder="@handle"
- size="sm"
- icon="i-lucide-at-sign"
- />
- </div>
- </template>
-
- <div class="flex items-center gap-2 text-xs text-muted">
- <UIcon name="i-lucide-package" class="size-3.5" />
- <span>Snapshot:</span>
- <code class="text-highlighted font-mono">{{ getSnapshotPreview(source) }}</code>
- </div>
+ </template>
+
+ <template v-else>
+ <div class="grid grid-cols-2 gap-3">
+ <UInput
+ v-model="source.data.channelId"
+ placeholder="UCxxxx..."
+ size="sm"
+ icon="i-simple-icons-youtube"
+ />
+ <UInput
+ v-model="source.data.handle"
+ placeholder="@handle"
+ size="sm"
+ icon="i-lucide-at-sign"
+ />
</div>
+ </template>
+
+ <div class="flex items-center gap-2 text-xs text-muted">
+ <UIcon name="i-lucide-package" class="size-3.5" />
+ <span>Snapshot:</span>
+ <code class="text-highlighted font-mono">{{ getSnapshotPreview(source) }}</code>
</div>
</div>
</div>
-
- <!-- Empty state -->
- <div
- v-if="sources.length === 0 && pendingFiles.length === 0"
- class="text-center py-8"
- >
- <p class="text-sm text-muted mb-3">
- No sources yet
- </p>
- <UButton
- icon="i-lucide-plus"
- size="sm"
- color="neutral"
- variant="outline"
- @click="addManualSource"
- >
- Add manually
- </UButton>
- </div>
-
- <!-- Actions -->
- <div class="flex justify-end gap-3 pt-4 border-t border-default">
- <UButton
- color="neutral"
- variant="ghost"
- label="Cancel"
- to="/admin/sources"
- />
- <UButton
- :label="`Create ${sources.filter(s => s.data.label).length} Source${sources.filter(s => s.data.label).length !== 1 ? 's' : ''}`"
- :loading="isSubmitting"
- :disabled="!hasValidSources || isExtracting"
- @click="saveAll"
- />
- </div>
</div>
- </UContainer>
- </template>
- </UDashboardPanel>
+ </div>
+
+ <!-- Empty state -->
+ <div
+ v-if="sources.length === 0 && pendingFiles.length === 0"
+ class="text-center py-8"
+ >
+ <p class="text-sm text-muted mb-3">
+ No sources yet
+ </p>
+ <UButton
+ icon="i-lucide-plus"
+ size="sm"
+ color="neutral"
+ variant="outline"
+ @click="addManualSource"
+ >
+ Add manually
+ </UButton>
+ </div>
+
+ <!-- Actions -->
+ <div class="flex justify-end gap-3 pt-4 border-t border-default">
+ <UButton
+ color="neutral"
+ variant="ghost"
+ label="Cancel"
+ to="/admin/sources"
+ />
+ <UButton
+ :label="`Create ${sources.filter(s => s.data.label).length} Source${sources.filter(s => s.data.label).length !== 1 ? 's' : ''}`"
+ :loading="isSubmitting"
+ :disabled="!hasValidSources || isExtracting"
+ @click="saveAll"
+ />
+ </div>
+ </div>
+ </UContainer>
</template>
diff --git a/apps/chat/nuxt.config.ts b/apps/chat/nuxt.config.ts
index 01c0aa6..ffede01 100644
--- a/apps/chat/nuxt.config.ts
+++ b/apps/chat/nuxt.config.ts
@@ -56,6 +56,8 @@ export default defineNuxtConfig({
},
runtimeConfig: {
+ // Admin users (comma-separated GitHub emails or usernames)
+ adminUsers: '',
// Savoir SDK config
savoir: {
apiKey: '',
diff --git a/apps/chat/package.json b/apps/chat/package.json
index 5bd5a60..d0a2e5b 100644
--- a/apps/chat/package.json
+++ b/apps/chat/package.json
@@ -39,6 +39,7 @@
"nuxt": "^4.3.0",
"nuxt-auth-utils": "^0.5.27",
"pathe": "^2.0.3",
+ "sharp": "^0.34.5",
"shiki-stream": "^0.1.4",
"workflow": "4.0.1-beta.50",
"zod": "^4.3.6"
diff --git a/apps/chat/server/api/sources/[id].delete.ts b/apps/chat/server/api/sources/[id].delete.ts
index 75cfe72..c0922ef 100644
--- a/apps/chat/server/api/sources/[id].delete.ts
+++ b/apps/chat/server/api/sources/[id].delete.ts
@@ -3,9 +3,10 @@ import { eq } from 'drizzle-orm'
/**
* DELETE /api/sources/:id
- * Delete a source
+ * Delete a source (admin only)
*/
export default defineEventHandler(async (event) => {
+ await requireAdmin(event)
const id = getRouterParam(event, 'id')
if (!id) {
throw createError({ statusCode: 400, message: 'Missing source id' })
diff --git a/apps/chat/server/api/sources/index.post.ts b/apps/chat/server/api/sources/index.post.ts
index dca30b4..2798b89 100644
--- a/apps/chat/server/api/sources/index.post.ts
+++ b/apps/chat/server/api/sources/index.post.ts
@@ -20,9 +20,10 @@ const bodySchema = z.object({
/**
* POST /api/sources
- * Create a new source
+ * Create a new source (admin only)
*/
export default defineEventHandler(async (event) => {
+ await requireAdmin(event)
const body = await readValidatedBody(event, bodySchema.parse)
const [source] = await db.insert(schema.sources)
diff --git a/apps/chat/server/api/sync/[source].post.ts b/apps/chat/server/api/sync/[source].post.ts
index 0df9522..d021a7a 100644
--- a/apps/chat/server/api/sync/[source].post.ts
+++ b/apps/chat/server/api/sync/[source].post.ts
@@ -9,9 +9,10 @@ const paramsSchema = z.object({
/**
* POST /api/sync/:source
- * Sync a specific source using Vercel Sandbox.
+ * Sync a specific source using Vercel Sandbox (admin only).
*/
export default defineEventHandler(async (event) => {
+ await requireAdmin(event)
const { source: sourceId } = await getValidatedRouterParams(event, paramsSchema.parse)
const config = useRuntimeConfig()
diff --git a/apps/chat/server/api/sync/index.post.ts b/apps/chat/server/api/sync/index.post.ts
index 5ead29f..8c481ce 100644
--- a/apps/chat/server/api/sync/index.post.ts
+++ b/apps/chat/server/api/sync/index.post.ts
@@ -11,12 +11,13 @@ const bodySchema = z
/**
* POST /api/sync
- * Sync all sources using Vercel Sandbox.
+ * Sync all sources using Vercel Sandbox (admin only).
*
* Body (optional):
* - sourceFilter: string - Only sync a specific source
*/
export default defineEventHandler(async (event) => {
+ await requireAdmin(event)
const body = await readValidatedBody(event, data => bodySchema.parse(data))
const config = useRuntimeConfig()
diff --git a/apps/chat/server/db/migrations/sqlite/0000_amusing_ozymandias.sql b/apps/chat/server/db/migrations/sqlite/0000_steady_magdalene.sql
similarity index 56%
rename from apps/chat/server/db/migrations/sqlite/0000_amusing_ozymandias.sql
rename to apps/chat/server/db/migrations/sqlite/0000_steady_magdalene.sql
index 9b2cbb9..9a91015 100644
--- a/apps/chat/server/db/migrations/sqlite/0000_amusing_ozymandias.sql
+++ b/apps/chat/server/db/migrations/sqlite/0000_steady_magdalene.sql
@@ -2,10 +2,13 @@ CREATE TABLE `chats` (
`id` text PRIMARY KEY NOT NULL,
`title` text,
`user_id` text NOT NULL,
+ `is_public` integer DEFAULT false NOT NULL,
+ `share_token` text,
`created_at` integer NOT NULL
);
--> statement-breakpoint
CREATE INDEX `chats_user_id_idx` ON `chats` (`user_id`);--> statement-breakpoint
+CREATE UNIQUE INDEX `chats_share_token_idx` ON `chats` (`share_token`);--> statement-breakpoint
CREATE TABLE `messages` (
`id` text PRIMARY KEY NOT NULL,
`chat_id` text NOT NULL,
@@ -16,6 +19,24 @@ CREATE TABLE `messages` (
);
--> statement-breakpoint
CREATE INDEX `messages_chat_id_idx` ON `messages` (`chat_id`);--> statement-breakpoint
+CREATE TABLE `sources` (
+ `id` text PRIMARY KEY NOT NULL,
+ `type` text NOT NULL,
+ `label` text NOT NULL,
+ `base_path` text DEFAULT '/docs',
+ `repo` text,
+ `branch` text,
+ `content_path` text,
+ `output_path` text,
+ `readme_only` integer DEFAULT false,
+ `channel_id` text,
+ `handle` text,
+ `max_videos` integer DEFAULT 50,
+ `created_at` integer NOT NULL,
+ `updated_at` integer NOT NULL
+);
+--> statement-breakpoint
+CREATE INDEX `sources_type_idx` ON `sources` (`type`);--> statement-breakpoint
CREATE TABLE `users` (
`id` text PRIMARY KEY NOT NULL,
`email` text NOT NULL,
@@ -24,6 +45,7 @@ CREATE TABLE `users` (
`username` text NOT NULL,
`provider` text NOT NULL,
`provider_id` text NOT NULL,
+ `role` text DEFAULT 'user' NOT NULL,
`created_at` integer NOT NULL
);
--> statement-breakpoint
diff --git a/apps/chat/server/db/migrations/sqlite/0001_icy_catseye.sql b/apps/chat/server/db/migrations/sqlite/0001_icy_catseye.sql
deleted file mode 100644
index 809f974..0000000
--- a/apps/chat/server/db/migrations/sqlite/0001_icy_catseye.sql
+++ /dev/null
@@ -1,3 +0,0 @@
-ALTER TABLE `chats` ADD `is_public` integer DEFAULT false NOT NULL;--> statement-breakpoint
-ALTER TABLE `chats` ADD `share_token` text;--> statement-breakpoint
-CREATE UNIQUE INDEX `chats_share_token_idx` ON `chats` (`share_token`);
\ No newline at end of file
diff --git a/apps/chat/server/db/migrations/sqlite/0002_sources.sql b/apps/chat/server/db/migrations/sqlite/0002_sources.sql
deleted file mode 100644
index a257b40..0000000
--- a/apps/chat/server/db/migrations/sqlite/0002_sources.sql
+++ /dev/null
@@ -1,17 +0,0 @@
-CREATE TABLE `sources` (
- `id` text PRIMARY KEY NOT NULL,
- `type` text NOT NULL,
- `label` text NOT NULL,
- `repo` text,
- `branch` text,
- `content_path` text,
- `output_path` text,
- `readme_only` integer DEFAULT false,
- `channel_id` text,
- `handle` text,
- `max_videos` integer DEFAULT 50,
- `created_at` integer NOT NULL,
- `updated_at` integer NOT NULL
-);
---> statement-breakpoint
-CREATE INDEX `sources_type_idx` ON `sources` (`type`);
diff --git a/apps/chat/server/db/migrations/sqlite/0003_base_path.sql b/apps/chat/server/db/migrations/sqlite/0003_base_path.sql
deleted file mode 100644
index 3ae0122..0000000
--- a/apps/chat/server/db/migrations/sqlite/0003_base_path.sql
+++ /dev/null
@@ -1,2 +0,0 @@
--- Add basePath column to sources table
-ALTER TABLE sources ADD COLUMN base_path TEXT DEFAULT '/docs';
diff --git a/apps/chat/server/db/migrations/sqlite/meta/0000_snapshot.json b/apps/chat/server/db/migrations/sqlite/meta/0000_snapshot.json
index c13d188..d0c4afe 100644
--- a/apps/chat/server/db/migrations/sqlite/meta/0000_snapshot.json
+++ b/apps/chat/server/db/migrations/sqlite/meta/0000_snapshot.json
@@ -1,7 +1,7 @@
{
"version": "6",
"dialect": "sqlite",
- "id": "68d5da0a-1951-4b77-8928-52099b08b27e",
+ "id": "6813eb3d-c05b-4506-b750-ae137da56780",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"chats": {
@@ -28,6 +28,21 @@
"notNull": true,
"autoincrement": false
},
+ "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",
@@ -43,6 +58,13 @@
"user_id"
],
"isUnique": false
+ },
+ "chats_share_token_idx": {
+ "name": "chats_share_token_idx",
+ "columns": [
+ "share_token"
+ ],
+ "isUnique": true
}
},
"foreignKeys": {},
@@ -117,6 +139,125 @@
"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": {}
+ },
"users": {
"name": "users",
"columns": {
@@ -169,6 +310,14 @@
"notNull": true,
"autoincrement": false
},
+ "role": {
+ "name": "role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'user'"
+ },
"created_at": {
"name": "created_at",
"type": "integer",
diff --git a/apps/chat/server/db/migrations/sqlite/meta/0001_snapshot.json b/apps/chat/server/db/migrations/sqlite/meta/0001_snapshot.json
deleted file mode 100644
index e9e18f8..0000000
--- a/apps/chat/server/db/migrations/sqlite/meta/0001_snapshot.json
+++ /dev/null
@@ -1,228 +0,0 @@
-{
- "version": "6",
- "dialect": "sqlite",
- "id": "8f9766e0-1f5e-480e-96de-d17fbed81edf",
- "prevId": "68d5da0a-1951-4b77-8928-52099b08b27e",
- "tables": {
- "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
- },
- "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
- },
- "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": {}
- },
- "users": {
- "name": "users",
- "columns": {
- "id": {
- "name": "id",
- "type": "text",
- "primaryKey": true,
- "notNull": true,
- "autoincrement": false
- },
- "email": {
- "name": "email",
- "type": "text",
- "primaryKey": false,
- "notNull": true,
- "autoincrement": false
- },
- "name": {
- "name": "name",
- "type": "text",
- "primaryKey": false,
- "notNull": true,
- "autoincrement": false
- },
- "avatar": {
- "name": "avatar",
- "type": "text",
- "primaryKey": false,
- "notNull": true,
- "autoincrement": false
- },
- "username": {
- "name": "username",
- "type": "text",
- "primaryKey": false,
- "notNull": true,
- "autoincrement": false
- },
- "provider": {
- "name": "provider",
- "type": "text",
- "primaryKey": false,
- "notNull": true,
- "autoincrement": false
- },
- "provider_id": {
- "name": "provider_id",
- "type": "text",
- "primaryKey": false,
- "notNull": true,
- "autoincrement": false
- },
- "created_at": {
- "name": "created_at",
- "type": "integer",
- "primaryKey": false,
- "notNull": true,
- "autoincrement": false
- }
- },
- "indexes": {
- "users_provider_id_idx": {
- "name": "users_provider_id_idx",
- "columns": [
- "provider",
- "provider_id"
- ],
- "isUnique": true
- }
- },
- "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/0002_snapshot.json b/apps/chat/server/db/migrations/sqlite/meta/0002_snapshot.json
deleted file mode 100644
index 4a54bd2..0000000
--- a/apps/chat/server/db/migrations/sqlite/meta/0002_snapshot.json
+++ /dev/null
@@ -1,339 +0,0 @@
-{
- "version": "6",
- "dialect": "sqlite",
- "id": "a1b2c3d4-5e6f-7890-abcd-ef1234567890",
- "prevId": "8f9766e0-1f5e-480e-96de-d17fbed81edf",
- "tables": {
- "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
- },
- "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
- },
- "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": {}
- },
- "users": {
- "name": "users",
- "columns": {
- "id": {
- "name": "id",
- "type": "text",
- "primaryKey": true,
- "notNull": true,
- "autoincrement": false
- },
- "email": {
- "name": "email",
- "type": "text",
- "primaryKey": false,
- "notNull": true,
- "autoincrement": false
- },
- "name": {
- "name": "name",
- "type": "text",
- "primaryKey": false,
- "notNull": true,
- "autoincrement": false
- },
- "avatar": {
- "name": "avatar",
- "type": "text",
- "primaryKey": false,
- "notNull": true,
- "autoincrement": false
- },
- "username": {
- "name": "username",
- "type": "text",
- "primaryKey": false,
- "notNull": true,
- "autoincrement": false
- },
- "provider": {
- "name": "provider",
- "type": "text",
- "primaryKey": false,
- "notNull": true,
- "autoincrement": false
- },
- "provider_id": {
- "name": "provider_id",
- "type": "text",
- "primaryKey": false,
- "notNull": true,
- "autoincrement": false
- },
- "created_at": {
- "name": "created_at",
- "type": "integer",
- "primaryKey": false,
- "notNull": true,
- "autoincrement": false
- }
- },
- "indexes": {
- "users_provider_id_idx": {
- "name": "users_provider_id_idx",
- "columns": [
- "provider",
- "provider_id"
- ],
- "isUnique": true
- }
- },
- "foreignKeys": {},
- "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
- },
- "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": {}
- }
- },
- "views": {},
- "enums": {},
- "_meta": {
- "schemas": {},
- "tables": {},
- "columns": {}
- },
- "internal": {
- "indexes": {}
- }
-}
diff --git a/apps/chat/server/db/migrations/sqlite/meta/_journal.json b/apps/chat/server/db/migrations/sqlite/meta/_journal.json
index 6167ab7..ec0fba9 100644
--- a/apps/chat/server/db/migrations/sqlite/meta/_journal.json
+++ b/apps/chat/server/db/migrations/sqlite/meta/_journal.json
@@ -5,29 +5,8 @@
{
"idx": 0,
"version": "6",
- "when": 1762072892319,
- "tag": "0000_amusing_ozymandias",
- "breakpoints": true
- },
- {
- "idx": 1,
- "version": "6",
- "when": 1768328336583,
- "tag": "0001_icy_catseye",
- "breakpoints": true
- },
- {
- "idx": 2,
- "version": "6",
- "when": 1737590400000,
- "tag": "0002_sources",
- "breakpoints": true
- },
- {
- "idx": 3,
- "version": "6",
- "when": 1737676800000,
- "tag": "0003_base_path",
+ "when": 1769440810870,
+ "tag": "0000_steady_magdalene",
"breakpoints": true
}
]
diff --git a/apps/chat/server/db/schema.ts b/apps/chat/server/db/schema.ts
index ea5531a..c683887 100644
--- a/apps/chat/server/db/schema.ts
+++ b/apps/chat/server/db/schema.ts
@@ -13,6 +13,7 @@ export const users = sqliteTable('users', {
username: text('username').notNull(),
provider: text('provider').notNull(), // 'github'
providerId: text('provider_id').notNull(),
+ role: text('role', { enum: ['user', 'admin'] }).notNull().default('user'),
...timestamps
}, table => [uniqueIndex('users_provider_id_idx').on(table.provider, table.providerId)])
diff --git a/apps/chat/server/routes/auth/github.get.ts b/apps/chat/server/routes/auth/github.get.ts
index d4f2c6e..6a9c25e 100644
--- a/apps/chat/server/routes/auth/github.get.ts
+++ b/apps/chat/server/routes/auth/github.get.ts
@@ -1,6 +1,12 @@
import { db, schema } from '@nuxthub/db'
import { eq, and } from 'drizzle-orm'
+function isAdminUser(email: string, username: string): boolean {
+ const config = useRuntimeConfig()
+ const adminUsers = config.adminUsers?.split(',').map(s => s.trim().toLowerCase()).filter(Boolean) || []
+ return adminUsers.includes(email.toLowerCase()) || adminUsers.includes(username.toLowerCase())
+}
+
export default defineOAuthGitHubEventHandler({
async onSuccess(event, { user: ghUser }) {
const session = await getUserSession(event)
@@ -21,16 +27,26 @@ export default defineOAuthGitHubEventHandler({
.where(eq(schema.chats.userId, session.user.id))
}
+ // Update role if it changed
+ const newRole = isAdminUser(existingUser.email, existingUser.username) ? 'admin' : 'user'
+ if (existingUser.role !== newRole) {
+ await db.update(schema.users)
+ .set({ role: newRole })
+ .where(eq(schema.users.id, existingUser.id))
+ existingUser.role = newRole
+ }
+
await setUserSession(event, { user: existingUser })
} else {
- // Create new user
+ const role = isAdminUser(ghUser.email || '', ghUser.login) ? 'admin' : 'user'
const [newUser] = await db.insert(schema.users).values({
email: ghUser.email || '',
name: ghUser.name || ghUser.login,
avatar: ghUser.avatar_url,
username: ghUser.login,
provider: 'github',
- providerId: String(ghUser.id)
+ providerId: String(ghUser.id),
+ role,
}).returning()
// Migrate anonymous chats to new user
diff --git a/apps/chat/server/utils/admin.ts b/apps/chat/server/utils/admin.ts
new file mode 100644
index 0000000..68468aa
--- /dev/null
+++ b/apps/chat/server/utils/admin.ts
@@ -0,0 +1,9 @@
+import type { H3Event } from 'h3'
+
+export async function requireAdmin(event: H3Event) {
+ const session = await getUserSession(event)
+ if (!session.user || session.user.role !== 'admin') {
+ throw createError({ statusCode: 403, message: 'Admin access required' })
+ }
+ return session
+}
diff --git a/apps/chat/shared/types/auth.d.ts b/apps/chat/shared/types/auth.d.ts
index 1508294..5bc176b 100644
--- a/apps/chat/shared/types/auth.d.ts
+++ b/apps/chat/shared/types/auth.d.ts
@@ -8,6 +8,7 @@ declare module '#auth-utils' {
username: string
provider: 'github'
providerId: number
+ role: 'user' | 'admin'
}
}
diff --git a/bun.lock b/bun.lock
index 5bad2fc..bf0a1a4 100644
--- a/bun.lock
+++ b/bun.lock
@@ -33,6 +33,7 @@
"nuxt": "^4.3.0",
"nuxt-auth-utils": "^0.5.27",
"pathe": "^2.0.3",
+ "sharp": "^0.34.5",
"shiki-stream": "^0.1.4",
"workflow": "4.0.1-beta.50",
"zod": "^4.3.6",