Open source file-system and knowledge based agent template. Build AI agents that stay up to date with your knowledge base
feat: files as sources
Hugo Richard89d07daac288
diff --git a/apps/app/app/components/SourceCard.vue b/apps/app/app/components/SourceCard.vueindex 7b8057c..fa3885c 100644--- a/apps/app/app/components/SourceCard.vue+++ b/apps/app/app/components/SourceCard.vue@@ -3,7 +3,7 @@ import { useTimeoutFn } from '@vueuse/core'interface SourceData {id: string- type: 'github' | 'youtube'+ type: 'github' | 'youtube' | 'file'label: stringrepo: string | nullbranch: string | null@@ -50,6 +50,7 @@ const sourceUrl = computed(() => {const sourceIdentifier = computed(() => {if (props.source.type === 'github') return props.source.repo+ if (props.source.type === 'file') return 'Uploaded files'return props.source.handle || props.source.channelId})</script>@@ -106,7 +107,7 @@ const sourceIdentifier = computed(() => {README only</div></template>- <template v-else>+ <template v-else-if="source.type === 'youtube'"><divv-if="source.maxVideos"class="inline-flex items-center gap-1 h-[22px] px-2 rounded-md text-[11px] font-medium text-muted bg-muted"@@ -115,6 +116,14 @@ const sourceIdentifier = computed(() => {{{ source.maxVideos }} videos max</div></template>+ <template v-else-if="source.type === 'file'">+ <UTooltip v-if="source.outputPath" text="Output folder in snapshot" :delay-open="200">+ <div class="inline-flex items-center gap-1 h-[22px] px-2 rounded-md text-[11px] font-medium text-muted bg-muted">+ <UIcon name="i-lucide-folder-output" class="size-3 opacity-60" />+ {{ source.outputPath }}+ </div>+ </UTooltip>+ </template></div></div>diff --git a/apps/app/app/components/SourceModal.vue b/apps/app/app/components/SourceModal.vueindex 3a45f79..a8ea5ad 100644--- a/apps/app/app/components/SourceModal.vue+++ b/apps/app/app/components/SourceModal.vue@@ -1,7 +1,11 @@<script setup lang="ts">+type SourceType = 'github' | 'youtube' | 'file'++const ALLOWED_EXTENSIONS = ['.md', '.mdx', '.txt', '.yml', '.yaml', '.json']+interface SourceData {id: string- type: 'github' | 'youtube'+ type: SourceTypelabel: stringrepo: string | nullbranch: string | null@@ -13,8 +17,14 @@ interface SourceData {maxVideos: number | null}+interface PendingFile {+ file: File+ id: string+}+const props = defineProps<{source?: SourceData | null+ defaultType?: SourceType}>()const emit = defineEmits<{@@ -29,13 +39,18 @@ const isSubmitting = ref(false)const isEditing = computed(() => !!props.source)const form = ref({- type: props.source?.type || 'github' as 'github' | 'youtube',+ type: (props.source?.type || props.defaultType || 'github') as SourceType,label: props.source?.label || '',repo: props.source?.repo || '',branch: props.source?.branch || 'main',contentPath: props.source?.contentPath || '',outputPath: props.source?.outputPath || '',- basePath: props.source?.type === 'youtube' ? '/youtube' : '/docs',+ basePath: (() => {+ const type = props.source?.type || props.defaultType || 'github'+ if (type === 'youtube') return '/youtube'+ if (type === 'file') return '/files'+ return '/docs'+ })(),readmeOnly: props.source?.readmeOnly || false,channelId: props.source?.channelId || '',handle: props.source?.handle || '',@@ -45,6 +60,7 @@ const form = ref({const typeOptions = [{ label: 'GitHub Repository', value: 'github', icon: 'i-simple-icons-github' },{ label: 'YouTube Channel', value: 'youtube', icon: 'i-simple-icons-youtube' },+ { label: 'File Upload', value: 'file', icon: 'i-lucide-file-text' },]function slugify(text: string): string {@@ -62,16 +78,90 @@ const effectiveOutputPath = computed(() => {return form.value.outputPath || outputFolderFromLabel.value})+const defaultBasePath = computed(() => {+ if (form.value.type === 'youtube') return '/youtube'+ if (form.value.type === 'file') return '/files'+ return '/docs'+})+const snapshotPreviewPath = computed(() => {- const base = form.value.basePath || (form.value.type === 'youtube' ? '/youtube' : '/docs')+ const base = form.value.basePath || defaultBasePath.valueconst folder = effectiveOutputPath.value || 'folder-name'return `${base}/${folder}/`})watch(() => form.value.type, (newType) => {- form.value.basePath = newType === 'youtube' ? '/youtube' : '/docs'+ if (newType === 'youtube') form.value.basePath = '/youtube'+ else if (newType === 'file') form.value.basePath = '/files'+ else form.value.basePath = '/docs'})+// File upload state+const pendingFiles = ref<PendingFile[]>([])+const isDraggingOver = ref(false)+const fileInputRef = ref<HTMLInputElement | null>(null)++function isAllowedFile(filename: string): boolean {+ return ALLOWED_EXTENSIONS.some(ext => filename.toLowerCase().endsWith(ext))+}++function addFiles(fileList: FileList | File[]) {+ const newFiles = Array.from(fileList).filter((file) => {+ if (!isAllowedFile(file.name)) {+ toast.add({ title: `${file.name} skipped`, description: `Only ${ALLOWED_EXTENSIONS.join(', ')} files are accepted`, icon: 'i-lucide-alert-triangle', color: 'warning' })+ return false+ }+ if (pendingFiles.value.some(pf => pf.file.name === file.name)) {+ return false+ }+ return true+ })++ pendingFiles.value = [+ ...pendingFiles.value,+ ...newFiles.map(file => ({ file, id: crypto.randomUUID() })),+ ]+}++function removePendingFile(id: string) {+ pendingFiles.value = pendingFiles.value.filter(f => f.id !== id)+}++function onDrop(e: DragEvent) {+ isDraggingOver.value = false+ if (e.dataTransfer?.files) {+ addFiles(e.dataTransfer.files)+ }+}++function onFileInput(e: Event) {+ const input = e.target as HTMLInputElement+ if (input.files) {+ addFiles(input.files)+ input.value = ''+ }+}++function formatFileSize(bytes: number): string {+ if (bytes < 1024) return `${bytes} B`+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`+}++async function uploadFilesToSource(sourceId: string) {+ if (pendingFiles.value.length === 0) return++ const formData = new FormData()+ for (const pf of pendingFiles.value) {+ formData.append('files', pf.file)+ }++ await $fetch(`/api/sources/${sourceId}/files`, {+ method: 'PUT',+ body: formData,+ })+}+async function save() {isSubmitting.value = truetry {@@ -83,7 +173,13 @@ async function save() {outputPath: form.value.outputPath || outputFolderFromLabel.value,}- await $fetch(url, { method, body })+ const result = await $fetch<{ id: string }>(url, { method, body })++ if (form.value.type === 'file' && pendingFiles.value.length > 0) {+ const sourceId = isEditing.value ? props.source!.id : result.id+ await uploadFilesToSource(sourceId)+ }+toast.add({title: isEditing.value ? 'Source updated' : 'Source created',icon: 'i-lucide-check',@@ -278,6 +374,60 @@ async function save() {</div></div></template>++ <template v-if="form.type === 'file'">+ <div+ class="relative rounded-lg border-2 border-dashed transition-colors p-6"+ :class="isDraggingOver ? 'border-primary bg-primary/5' : 'border-default hover:border-muted'"+ @dragover.prevent="isDraggingOver = true"+ @dragleave.prevent="isDraggingOver = false"+ @drop.prevent="onDrop"+ >+ <input+ ref="fileInputRef"+ type="file"+ :accept="ALLOWED_EXTENSIONS.join(',')"+ multiple+ class="hidden"+ @change="onFileInput"+ >+ <div class="flex flex-col items-center gap-2 text-center">+ <div class="size-10 rounded-lg bg-elevated flex items-center justify-center">+ <UIcon name="i-lucide-upload" class="size-5 text-muted" />+ </div>+ <div>+ <p class="text-sm font-medium text-highlighted">+ Drop files here or+ <button type="button" class="text-primary hover:underline" @click="fileInputRef?.click()">+ browse+ </button>+ </p>+ <p class="text-xs text-muted mt-1">+ {{ ALLOWED_EXTENSIONS.join(', ') }} files up to 8MB+ </p>+ </div>+ </div>+ </div>++ <div v-if="pendingFiles.length > 0" class="flex flex-col gap-1">+ <div+ v-for="pf in pendingFiles"+ :key="pf.id"+ class="flex items-center gap-3 px-3 py-2 rounded-lg bg-elevated/50"+ >+ <UIcon name="i-lucide-file-text" class="size-4 text-muted shrink-0" />+ <span class="text-sm text-highlighted truncate flex-1">{{ pf.file.name }}</span>+ <span class="text-xs text-muted shrink-0">{{ formatFileSize(pf.file.size) }}</span>+ <UButton+ icon="i-lucide-x"+ color="neutral"+ variant="ghost"+ size="xs"+ @click="removePendingFile(pf.id)"+ />+ </div>+ </div>+ </template></div></div></template>diff --git a/apps/app/app/pages/admin/index.vue b/apps/app/app/pages/admin/index.vueindex b255f97..fccb470 100644--- a/apps/app/app/pages/admin/index.vue+++ b/apps/app/app/pages/admin/index.vue@@ -10,7 +10,7 @@ const ITEMS_PER_PAGE = 5interface SerializedSource {id: string- type: 'github' | 'youtube'+ type: 'github' | 'youtube' | 'file'label: stringrepo: string | nullbranch: string | null@@ -39,15 +39,15 @@ watch(sources, (v) => {})const editingSource = ref<SerializedSource | null>(null)+const showNewFileModal = ref(false)const isSyncingAll = ref(false)const searchQuery = ref('')const githubPage = ref(1)const youtubePage = ref(1)+const filePage = ref(1)-const deleteModal = overlay.create(LazyModalConfirm, {- destroyOnClose: true,-})+const deleteModal = overlay.create(LazyModalConfirm)const needsSync = computed(() => {if (!sources.value?.lastSyncAt) return true@@ -75,6 +75,7 @@ function filterSources(sourceList: SerializedSource[] | undefined) {const filteredGithubSources = computed(() => filterSources(sources.value?.github?.sources as SerializedSource[] | undefined))const filteredYoutubeSources = computed(() => filterSources(sources.value?.youtube?.sources as SerializedSource[] | undefined))+const filteredFileSources = computed(() => filterSources(sources.value?.file?.sources as SerializedSource[] | undefined))const paginatedGithubSources = computed(() => {const start = (githubPage.value - 1) * ITEMS_PER_PAGE@@ -86,9 +87,15 @@ const paginatedYoutubeSources = computed(() => {return filteredYoutubeSources.value.slice(start, start + ITEMS_PER_PAGE)})+const paginatedFileSources = computed(() => {+ const start = (filePage.value - 1) * ITEMS_PER_PAGE+ return filteredFileSources.value.slice(start, start + ITEMS_PER_PAGE)+})+watch(searchQuery, () => {githubPage.value = 1youtubePage.value = 1+ filePage.value = 1})async function deleteSource(source: SerializedSource) {@@ -114,6 +121,11 @@ async function deleteSource(source: SerializedSource) {sources: sources.value.youtube.sources.filter(s => s.id !== source.id),count: source.type === 'youtube' ? sources.value.youtube.count - 1 : sources.value.youtube.count,},+ file: {+ ...sources.value.file,+ sources: sources.value.file.sources.filter(s => s.id !== source.id),+ count: source.type === 'file' ? sources.value.file.count - 1 : sources.value.file.count,+ },}}@@ -151,10 +163,11 @@ async function triggerSync(sourceId?: string) {function handleSaved() {editingSource.value = null+ showNewFileModal.value = falserefresh()}-const hasSources = computed(() => (sources.value?.github?.count || 0) + (sources.value?.youtube?.count || 0) > 0)+const hasSources = computed(() => (sources.value?.github?.count || 0) + (sources.value?.youtube?.count || 0) + (sources.value?.file?.count || 0) > 0)</script><template>@@ -164,7 +177,7 @@ const hasSources = computed(() => (sources.value?.github?.count || 0) + (sourcesSources</h1><p class="text-sm text-muted max-w-lg">- Sources are knowledge bases that give the AI context. Connect GitHub repositories for documentation or YouTube channels for video transcripts.+ Sources are knowledge bases that give the AI context. Connect GitHub repositories, YouTube channels, or upload files directly.</p></header>@@ -389,6 +402,57 @@ const hasSources = computed(() => (sources.value?.github?.count || 0) + (sourcesAdd a YouTube channel</UButton></section>++ <section>+ <div class="flex items-center justify-between mb-3">+ <p class="text-[10px] text-muted font-pixel tracking-wide uppercase">+ Uploaded Files+ </p>+ <p v-if="filteredFileSources.length" class="text-xs text-muted">+ {{ filteredFileSources.length }} {{ filteredFileSources.length === 1 ? 'source' : 'sources' }}+ </p>+ </div>++ <template v-if="filteredFileSources.length">+ <div class="rounded-lg border border-default divide-y divide-default overflow-hidden">+ <div v-for="source in paginatedFileSources" :key="source.id" class="px-4 hover:bg-elevated/50 transition-colors">+ <SourceCard+ :source+ @edit="editingSource = source"+ @delete="deleteSource(source)"+ @sync="triggerSync(source.id)"+ />+ </div>+ </div>+ <div v-if="filteredFileSources.length > ITEMS_PER_PAGE" class="flex justify-center mt-4">+ <UPagination+ v-model:page="filePage"+ :items-per-page="ITEMS_PER_PAGE"+ :total="filteredFileSources.length"+ :sibling-count="1"+ show-edges+ size="sm"+ />+ </div>+ </template>+ <template v-else-if="sources?.file?.count && searchQuery">+ <div class="py-8 text-center border border-dashed border-default rounded-lg">+ <p class="text-sm text-muted">+ No file sources match your search+ </p>+ </div>+ </template>+ <UButton+ v-else+ color="neutral"+ variant="ghost"+ class="w-full h-14 border border-dashed border-default hover:border-muted"+ icon="i-lucide-plus"+ @click="showNewFileModal = true"+ >+ Upload files+ </UButton>+ </section></div><SourceModal@@ -397,6 +461,13 @@ const hasSources = computed(() => (sources.value?.github?.count || 0) + (sources@close="editingSource = null"@saved="handleSaved"/>++ <SourceModal+ v-if="showNewFileModal"+ default-type="file"+ @close="showNewFileModal = false"+ @saved="handleSaved"+ /></template></div></template>diff --git a/apps/app/app/pages/admin/new.vue b/apps/app/app/pages/admin/new.vueindex 90198c7..2357092 100644--- a/apps/app/app/pages/admin/new.vue+++ b/apps/app/app/pages/admin/new.vue@@ -10,10 +10,15 @@ interface PendingFile {type: 'image' | 'config'}+interface SourceFiles {+ file: File+ id: string+}+interface ExtractedSource {id: stringdata: {- type: 'github' | 'youtube'+ type: 'github' | 'youtube' | 'file'label: stringrepo: stringbranch: string@@ -26,10 +31,12 @@ interface ExtractedSource {maxVideos: number}confidence: number+ uploadFiles?: SourceFiles[]}const CONFIG_EXTENSIONS = ['.ts', '.js', '.json', '.yml', '.yaml', '.toml']const CONFIG_ACCEPT = CONFIG_EXTENSIONS.join(',')+const SOURCE_FILE_EXTENSIONS = ['.md', '.mdx', '.txt', '.yml', '.yaml', '.json']const router = useRouter()const route = useRoute()@@ -39,8 +46,8 @@ const { showError } = useErrorToast()const { data: sourcesData } = useLazyFetch('/api/sources')const youtubeEnabled = computed(() => sourcesData.value?.youtubeEnabled ?? false)-const requestedType = route.query.type === 'youtube' ? 'youtube' : 'github'-const initialType = (requestedType === 'youtube' && !youtubeEnabled.value ? 'github' : requestedType) as 'github' | 'youtube'+const requestedType = (['youtube', 'file'].includes(route.query.type as string) ? route.query.type : 'github') as 'github' | 'youtube' | 'file'+const initialType = (requestedType === 'youtube' && !youtubeEnabled.value ? 'github' : requestedType) as 'github' | 'youtube' | 'file'const isSubmitting = ref(false)const isExtracting = ref(false)@@ -57,7 +64,7 @@ const sources = ref<ExtractedSource[]>([branch: 'main',contentPath: '',outputPath: '',- basePath: initialType === 'youtube' ? '/youtube' : '/docs',+ basePath: initialType === 'youtube' ? '/youtube' : initialType === 'file' ? '/files' : '/docs',readmeOnly: false,channelId: '',handle: '',@@ -75,14 +82,15 @@ watch(pendingFiles, (files) => {})function createSourceData(item?: SourceOcrItem) {+ const type = (item?.type || 'github') as 'github' | 'youtube' | 'file'return {- type: (item?.type || 'github') as 'github' | 'youtube',+ type,label: item?.label || '',repo: item?.repo || '',branch: item?.branch || 'main',contentPath: item?.contentPath || '',outputPath: '',- basePath: item?.type === 'youtube' ? '/youtube' : '/docs',+ basePath: type === 'youtube' ? '/youtube' : type === 'file' ? '/files' : '/docs',readmeOnly: false,channelId: item?.channelId || '',handle: item?.handle || '',@@ -248,6 +256,9 @@ function isSourceEmpty(source: ExtractedSource): boolean {if (d.type === 'github') {return !d.label && !d.repo && !d.contentPath}+ if (d.type === 'file') {+ return !d.label && (!source.uploadFiles || source.uploadFiles.length === 0)+ }return !d.label && !d.channelId && !d.handle}@@ -284,11 +295,39 @@ function getEffectiveOutputPath(source: ExtractedSource) {}function getSnapshotPreview(source: ExtractedSource) {- const base = source.data.basePath || (source.data.type === 'youtube' ? '/youtube' : '/docs')+ const { type } = source.data+ const base = source.data.basePath || (type === 'youtube' ? '/youtube' : type === 'file' ? '/files' : '/docs')const folder = getEffectiveOutputPath(source) || 'folder-name'return `${base}/${folder}/`}+function isAllowedSourceFile(filename: string): boolean {+ return SOURCE_FILE_EXTENSIONS.some(ext => filename.toLowerCase().endsWith(ext))+}++function addSourceFiles(source: ExtractedSource, fileList: FileList | File[]) {+ const existing = source.uploadFiles || []+ const newFiles = Array.from(fileList).filter((file) => {+ if (!isAllowedSourceFile(file.name)) return false+ if (existing.some(f => f.file.name === file.name)) return false+ return true+ })+ source.uploadFiles = [+ ...existing,+ ...newFiles.map(file => ({ file, id: crypto.randomUUID() })),+ ]+}++function removeSourceFile(source: ExtractedSource, fileId: string) {+ source.uploadFiles = (source.uploadFiles || []).filter(f => f.id !== fileId)+}++function formatFileSize(bytes: number): string {+ if (bytes < 1024) return `${bytes} B`+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`+}+function getFileIcon(file: PendingFile) {if (file.type === 'image') return 'i-lucide-image'const ext = file.file.name.split('.').pop()?.toLowerCase()@@ -316,13 +355,25 @@ async function saveAll() {for (const source of validSources) {try {- await $fetch('/api/sources', {+ const result = await $fetch<{ id: string }>('/api/sources', {method: 'POST',body: {...source.data,outputPath: getEffectiveOutputPath(source),},})++ if (source.data.type === 'file' && source.uploadFiles && source.uploadFiles.length > 0) {+ const formData = new FormData()+ for (const sf of source.uploadFiles) {+ formData.append('files', sf.file)+ }+ await $fetch(`/api/sources/${result.id}/files`, {+ method: 'PUT',+ body: formData,+ })+ }+created++} catch (error) {toast.add({@@ -352,12 +403,14 @@ async function saveAll() {}const typeOptions = computed(() => {- const options = [{ label: 'GitHub', value: 'github', icon: 'i-simple-icons-github' },]+ const options = [{ label: 'GitHub', value: 'github', icon: 'i-simple-icons-github' }]if (youtubeEnabled.value) {options.push({ label: 'YouTube', value: 'youtube', icon: 'i-simple-icons-youtube' })}+ options.push({ label: 'File Upload', value: 'file', icon: 'i-lucide-file-text' })+return options})@@ -372,7 +425,7 @@ const validSourcesCount = computed(() => sources.value.filter(s => s.data.label)Add Sources</h1><p class="text-sm text-muted">- Sources provide context to the AI. Connect your GitHub docs{{ youtubeEnabled ? ' or YouTube channels' : '' }}.+ Sources provide context to the AI. Connect your GitHub docs{{ youtubeEnabled ? ', YouTube channels,' : '' }} or upload files.</p></header>@@ -495,7 +548,7 @@ const validSourcesCount = computed(() => sources.value.filter(s => s.data.label):items="typeOptions"value-key="value"size="sm"- @update:model-value="source.data.basePath = $event === 'youtube' ? '/youtube' : '/docs'"+ @update:model-value="source.data.basePath = $event === 'youtube' ? '/youtube' : $event === 'file' ? '/files' : '/docs'"/><div class="col-span-2"><UInput@@ -543,7 +596,7 @@ const validSourcesCount = computed(() => sources.value.filter(s => s.data.label)</div></template>- <template v-else>+ <template v-else-if="source.data.type === 'youtube'"><div class="grid grid-cols-2 gap-2"><UInputv-model="source.data.channelId"@@ -562,6 +615,55 @@ const validSourcesCount = computed(() => sources.value.filter(s => s.data.label)</div></template>+ <template v-else-if="source.data.type === 'file'">+ <div+ class="relative p-4 border border-dashed rounded-md transition-colors cursor-pointer"+ :class="[+ isDragging ? 'border-neutral-900 bg-neutral-900/5 dark:border-white dark:bg-white/5' : 'border-default hover:border-muted hover:bg-elevated/30',+ ]"+ @click="($refs[`fileInput-${source.id}`] as HTMLInputElement)?.click()"+ @drop.prevent="isDragging = false; addSourceFiles(source, $event.dataTransfer?.files || [])"+ @dragover.prevent="isDragging = true"+ @dragleave.self="isDragging = false"+ >+ <input+ :ref="`fileInput-${source.id}`"+ type="file"+ :accept="SOURCE_FILE_EXTENSIONS.join(',')"+ multiple+ class="hidden"+ @change="addSourceFiles(source, ($event.target as HTMLInputElement).files || []); ($event.target as HTMLInputElement).value = ''"+ >+ <div class="text-center">+ <UIcon name="i-lucide-upload" class="size-4 text-muted mx-auto mb-1" aria-hidden="true" />+ <p class="text-xs text-muted">+ Drop .md, .mdx, .txt, .yml, .json files here+ </p>+ </div>+ </div>++ <div v-if="source.uploadFiles?.length" class="space-y-1 mt-2">+ <div+ v-for="sf in source.uploadFiles"+ :key="sf.id"+ class="flex items-center justify-between gap-2 px-2 py-1 rounded bg-elevated text-xs"+ >+ <div class="flex items-center gap-1.5 min-w-0">+ <UIcon name="i-lucide-file-text" class="size-3 text-muted shrink-0" aria-hidden="true" />+ <span class="truncate text-highlighted">{{ sf.file.name }}</span>+ <span class="text-muted shrink-0">{{ formatFileSize(sf.file.size) }}</span>+ </div>+ <button+ class="text-muted hover:text-error transition-colors shrink-0"+ aria-label="Remove file"+ @click.stop="removeSourceFile(source, sf.id)"+ >+ <UIcon name="i-lucide-x" class="size-3" aria-hidden="true" />+ </button>+ </div>+ </div>+ </template>+<div class="flex items-center gap-1.5 text-xs text-muted pt-1"><UIcon name="i-lucide-folder-output" class="size-3" aria-hidden="true" /><span>Output:</span>diff --git a/apps/app/server/api/sources/[id].delete.ts b/apps/app/server/api/sources/[id].delete.tsindex 6fff25d..b2fd1bc 100644--- a/apps/app/server/api/sources/[id].delete.ts+++ b/apps/app/server/api/sources/[id].delete.ts@@ -1,3 +1,4 @@+import { blob } from 'hub:blob'import { db, schema } from '@nuxthub/db'import { eq } from 'drizzle-orm'import { z } from 'zod'@@ -25,5 +26,13 @@ export default defineEventHandler(async (event) => {throw createError({ statusCode: 404, message: 'Source not found', data: { why: 'No source exists with this ID', fix: 'Verify the source ID from the sources list' } })}+ if (deleted.type === 'file') {+ const prefix = `sources/${id}/`+ const { blobs } = await blob.list({ prefix })+ if (blobs.length > 0) {+ await blob.del(blobs.map(b => b.pathname))+ }+ }+return { success: true }})diff --git a/apps/app/server/api/sources/[id]/files.delete.ts b/apps/app/server/api/sources/[id]/files.delete.tsnew file mode 100644index 0000000..e712bf3--- /dev/null+++ b/apps/app/server/api/sources/[id]/files.delete.ts@@ -0,0 +1,45 @@+import { blob } from 'hub:blob'+import { db, schema } from '@nuxthub/db'+import { eq } from 'drizzle-orm'+import { z } from 'zod'++const paramsSchema = z.object({+ id: z.string().min(1, 'Missing source ID'),+})++const bodySchema = z.object({+ pathname: z.string().min(1, 'Missing file pathname'),+})++/**+ * DELETE /api/sources/:id/files+ * Delete a specific file from a file source's blob storage.+ */+export default defineEventHandler(async (event) => {+ const requestLog = useLogger(event)+ await requireAdmin(event)+ const { id } = await getValidatedRouterParams(event, paramsSchema.parse)+ const { pathname } = await readValidatedBody(event, bodySchema.parse)++ const source = await db.query.sources.findFirst({+ where: () => eq(schema.sources.id, id),+ })++ if (!source) {+ throw createError({ statusCode: 404, message: 'Source not found' })+ }++ if (source.type !== 'file') {+ throw createError({ statusCode: 400, message: 'Source is not a file source' })+ }++ if (!pathname.startsWith(`sources/${id}/`)) {+ throw createError({ statusCode: 403, message: 'File does not belong to this source' })+ }++ await blob.del(pathname)++ requestLog.set({ sourceId: id, deletedFile: pathname })++ return { success: true }+})diff --git a/apps/app/server/api/sources/[id]/files.get.ts b/apps/app/server/api/sources/[id]/files.get.tsnew file mode 100644index 0000000..695e7e0--- /dev/null+++ b/apps/app/server/api/sources/[id]/files.get.ts@@ -0,0 +1,42 @@+import { blob } from 'hub:blob'+import { db, schema } from '@nuxthub/db'+import { eq } from 'drizzle-orm'+import { z } from 'zod'++const paramsSchema = z.object({+ id: z.string().min(1, 'Missing source ID'),+})++/**+ * GET /api/sources/:id/files+ * List files for a file source from blob storage.+ * Returns empty list after sync (blob is cleaned up post-sync).+ */+export default defineEventHandler(async (event) => {+ await requireAdmin(event)+ const { id } = await getValidatedRouterParams(event, paramsSchema.parse)++ const source = await db.query.sources.findFirst({+ where: () => eq(schema.sources.id, id),+ })++ if (!source) {+ throw createError({ statusCode: 404, message: 'Source not found' })+ }++ if (source.type !== 'file') {+ throw createError({ statusCode: 400, message: 'Source is not a file source' })+ }++ const prefix = `sources/${id}/`+ const { blobs } = await blob.list({ prefix })++ const files = blobs.map(b => ({+ pathname: b.pathname,+ filename: b.pathname.replace(prefix, ''),+ size: b.size,+ uploadedAt: b.uploadedAt,+ }))++ return { files }+})diff --git a/apps/app/server/api/sources/[id]/files.put.ts b/apps/app/server/api/sources/[id]/files.put.tsnew file mode 100644index 0000000..252b571--- /dev/null+++ b/apps/app/server/api/sources/[id]/files.put.ts@@ -0,0 +1,74 @@+import { blob } from 'hub:blob'+import { db, schema } from '@nuxthub/db'+import { eq } from 'drizzle-orm'+import { z } from 'zod'++const ALLOWED_EXTENSIONS = ['.md', '.mdx', '.txt', '.yml', '.yaml', '.json']+const MAX_FILE_SIZE = 8 * 1024 * 1024++const paramsSchema = z.object({+ id: z.string().min(1, 'Missing source ID'),+})++function isAllowedFile(filename: string): boolean {+ return ALLOWED_EXTENSIONS.some(ext => filename.toLowerCase().endsWith(ext))+}++/**+ * PUT /api/sources/:id/files+ * Upload files to a file source (admin only).+ * Files are stored in blob at `sources/{sourceId}/{filename}`.+ */+export default defineEventHandler(async (event) => {+ const requestLog = useLogger(event)+ await requireAdmin(event)+ const { id } = await getValidatedRouterParams(event, paramsSchema.parse)++ const source = await db.query.sources.findFirst({+ where: () => eq(schema.sources.id, id),+ })++ if (!source) {+ throw createError({ statusCode: 404, message: 'Source not found' })+ }++ if (source.type !== 'file') {+ throw createError({ statusCode: 400, message: 'Source is not a file source' })+ }++ const formData = await readMultipartFormData(event)+ if (!formData || formData.length === 0) {+ throw createError({ statusCode: 400, message: 'No files provided' })+ }++ const fileFields = formData.filter(f => f.name === 'files' && f.filename && f.data)+ if (fileFields.length === 0) {+ throw createError({ statusCode: 400, message: 'No files in form data' })+ }++ const results = []++ for (const field of fileFields) {+ const filename = field.filename!++ if (!isAllowedFile(filename)) {+ results.push({ filename, error: `File type not allowed. Accepted: ${ALLOWED_EXTENSIONS.join(', ')}` })+ continue+ }++ if (field.data.length > MAX_FILE_SIZE) {+ results.push({ filename, error: 'File exceeds 8MB limit' })+ continue+ }++ const pathname = `sources/${id}/${filename}`+ const contentType = field.type || 'text/plain'++ await blob.put(pathname, field.data, { contentType })+ results.push({ filename, pathname, size: field.data.length })+ }++ requestLog.set({ sourceId: id, filesUploaded: results.filter(r => !('error' in r)).length })++ return { files: results }+})diff --git a/apps/app/server/api/sources/index.get.ts b/apps/app/server/api/sources/index.get.tsindex 4f739aa..a3d395d 100644--- a/apps/app/server/api/sources/index.get.ts+++ b/apps/app/server/api/sources/index.get.ts@@ -22,12 +22,13 @@ export default defineEventHandler(async () => {const github = allSources.filter(s => s.type === 'github')const youtube = hasYouTubeApiKey ? allSources.filter(s => s.type === 'youtube') : []+ const file = allSources.filter(s => s.type === 'file')const snapshotRepo = snapshotConfig.snapshotRepo || nullconst snapshotBranch = snapshotConfig.snapshotBranch || 'main'return {- total: github.length + youtube.length,+ total: github.length + youtube.length + file.length,lastSyncAt,youtubeEnabled: hasYouTubeApiKey,snapshotRepo,@@ -41,5 +42,9 @@ export default defineEventHandler(async () => {count: youtube.length,sources: youtube,},+ file: {+ count: file.length,+ sources: file,+ },}})diff --git a/apps/app/server/api/sources/index.post.ts b/apps/app/server/api/sources/index.post.tsindex cbe9a6b..ad0bd7d 100644--- a/apps/app/server/api/sources/index.post.ts+++ b/apps/app/server/api/sources/index.post.ts@@ -2,7 +2,7 @@ import { db, schema } from '@nuxthub/db'import { z } from 'zod'const bodySchema = z.object({- type: z.enum(['github', 'youtube']),+ type: z.enum(['github', 'youtube', 'file']),label: z.string().min(1),basePath: z.string().optional().default('/docs'),repo: z.string().optional(),diff --git a/apps/app/server/api/sync/[source].post.ts b/apps/app/server/api/sync/[source].post.tsindex e73d923..1134764 100644--- a/apps/app/server/api/sync/[source].post.ts+++ b/apps/app/server/api/sync/[source].post.ts@@ -1,9 +1,11 @@+import { blob } from 'hub:blob'import { start } from 'workflow/api'import { z } from 'zod'import { eq } from 'drizzle-orm'import { db, schema } from '@nuxthub/db'import { syncDocumentation } from '../../workflows/sync-docs'import type { Source } from '../../workflows/sync-docs'+import type { FileSourceEntry } from '../../workflows/sync-docs/types'import { getSnapshotRepoConfig } from '../../utils/sandbox/snapshot-config'const paramsSchema = z.object({@@ -47,8 +49,34 @@ export default defineEventHandler(async (event) => {outputPath: dbSource.outputPath || dbSource.id,readmeOnly: dbSource.readmeOnly ?? false,}+ } else if (dbSource.type === 'file') {+ const prefix = `sources/${dbSource.id}/`+ const { blobs } = await blob.list({ prefix })++ const files: FileSourceEntry[] = []+ for (const blobItem of blobs) {+ const response = await blob.get(blobItem.pathname)+ if (response) {+ files.push({+ filename: blobItem.pathname.replace(prefix, ''),+ content: await response.text(),+ })+ }+ }++ if (blobs.length > 0) {+ await blob.del(blobs.map(b => b.pathname))+ }++ source = {+ id: dbSource.id,+ type: 'file',+ label: dbSource.label,+ basePath: dbSource.basePath || '/files',+ outputPath: dbSource.outputPath || dbSource.id,+ files,+ }} else {- // YouTube sourcesource = {id: dbSource.id,type: 'youtube',diff --git a/apps/app/server/api/sync/index.post.ts b/apps/app/server/api/sync/index.post.tsindex 464194a..8380a9f 100644--- a/apps/app/server/api/sync/index.post.ts+++ b/apps/app/server/api/sync/index.post.ts@@ -1,9 +1,11 @@+import { blob } from 'hub:blob'import { kv } from '@nuxthub/kv'import { start } from 'workflow/api'import { z } from 'zod'import { db } from '@nuxthub/db'import { syncDocumentation } from '../../workflows/sync-docs'import type { Source } from '../../workflows/sync-docs'+import type { FileSourceEntry } from '../../workflows/sync-docs/types'import { KV_KEYS } from '../../utils/sandbox/types'import { getSnapshotRepoConfig } from '../../utils/sandbox/snapshot-config'@@ -31,7 +33,7 @@ export default defineEventHandler(async (event) => {const dbSources = await db.query.sources.findMany()- let sources: Source[] = dbSources.map((s): Source => {+ let sources: Source[] = await Promise.all(dbSources.map(async (s): Promise<Source> => {if (s.type === 'github') {return {id: s.id,@@ -46,7 +48,36 @@ export default defineEventHandler(async (event) => {}}- // YouTube source+ if (s.type === 'file') {+ const prefix = `sources/${s.id}/`+ const { blobs } = await blob.list({ prefix })++ const files: FileSourceEntry[] = []+ for (const blobItem of blobs) {+ const response = await blob.get(blobItem.pathname)+ if (response) {+ files.push({+ filename: blobItem.pathname.replace(prefix, ''),+ content: await response.text(),+ })+ }+ }++ // Clean up blob — content is now embedded in the workflow payload+ if (blobs.length > 0) {+ await blob.del(blobs.map(b => b.pathname))+ }++ return {+ id: s.id,+ type: 'file' as const,+ label: s.label,+ basePath: s.basePath || '/files',+ outputPath: s.outputPath || s.id,+ files,+ }+ }+return {id: s.id,type: 'youtube' as const,@@ -57,7 +88,7 @@ export default defineEventHandler(async (event) => {maxVideos: s.maxVideos || 50,outputPath: s.outputPath || s.id,}- })+ }))if (body?.sourceFilter) {sources = sources.filter(s => s.id === body.sourceFilter)diff --git a/apps/app/server/db/migrations/postgresql/0002_elite_absorbing_man.sql b/apps/app/server/db/migrations/postgresql/0002_elite_absorbing_man.sqlnew file mode 100644index 0000000..092e6fc--- /dev/null+++ b/apps/app/server/db/migrations/postgresql/0002_elite_absorbing_man.sql@@ -0,0 +1,9 @@+ALTER TABLE "apikey" DROP CONSTRAINT "apikey_userId_user_id_fk";+--> statement-breakpoint+DROP INDEX "apikey_userId_idx";--> statement-breakpoint+ALTER TABLE "apikey" ALTER COLUMN "configId" SET DEFAULT 'default';--> statement-breakpoint+ALTER TABLE "apikey" ALTER COLUMN "configId" SET NOT NULL;--> statement-breakpoint+ALTER TABLE "apikey" ALTER COLUMN "referenceId" SET NOT NULL;--> statement-breakpoint+CREATE INDEX "apikey_configId_idx" ON "apikey" USING btree ("configId");--> statement-breakpoint+CREATE INDEX "apikey_referenceId_idx" ON "apikey" USING btree ("referenceId");--> statement-breakpoint+ALTER TABLE "apikey" DROP COLUMN "userId";\ No newline at end of filediff --git a/apps/app/server/db/migrations/postgresql/meta/0000_snapshot.json b/apps/app/server/db/migrations/postgresql/meta/0000_snapshot.jsonindex a36d46b..122e4c2 100644--- a/apps/app/server/db/migrations/postgresql/meta/0000_snapshot.json+++ b/apps/app/server/db/migrations/postgresql/meta/0000_snapshot.json@@ -363,7 +363,19 @@"name": "userId","type": "text","primaryKey": false,- "notNull": true+ "notNull": false+ },+ "configId": {+ "name": "configId",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "referenceId": {+ "name": "referenceId",+ "type": "text",+ "primaryKey": false,+ "notNull": false},"refillInterval": {"name": "refillInterval",diff --git a/apps/app/server/db/migrations/postgresql/meta/0001_snapshot.json b/apps/app/server/db/migrations/postgresql/meta/0001_snapshot.jsonnew file mode 100644index 0000000..52d1810--- /dev/null+++ b/apps/app/server/db/migrations/postgresql/meta/0001_snapshot.json@@ -0,0 +1,1445 @@+{+ "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",+ "prevId": "c465a693-296d-46d6-9d12-004b73774991",+ "version": "7",+ "dialect": "postgresql",+ "tables": {+ "public.account": {+ "name": "account",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "accountId": {+ "name": "accountId",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "providerId": {+ "name": "providerId",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "accessToken": {+ "name": "accessToken",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "refreshToken": {+ "name": "refreshToken",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "idToken": {+ "name": "idToken",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "accessTokenExpiresAt": {+ "name": "accessTokenExpiresAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": false+ },+ "refreshTokenExpiresAt": {+ "name": "refreshTokenExpiresAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": false+ },+ "scope": {+ "name": "scope",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "password": {+ "name": "password",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updatedAt": {+ "name": "updatedAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true+ }+ },+ "indexes": {+ "account_userId_idx": {+ "name": "account_userId_idx",+ "columns": [+ {+ "expression": "userId",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "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": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.agent_config": {+ "name": "agent_config",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'default'"+ },+ "additional_prompt": {+ "name": "additional_prompt",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "response_style": {+ "name": "response_style",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "default": "'concise'"+ },+ "language": {+ "name": "language",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "default": "'en'"+ },+ "default_model": {+ "name": "default_model",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "max_steps_multiplier": {+ "name": "max_steps_multiplier",+ "type": "real",+ "primaryKey": false,+ "notNull": false,+ "default": 1+ },+ "temperature": {+ "name": "temperature",+ "type": "real",+ "primaryKey": false,+ "notNull": false,+ "default": 0.7+ },+ "search_instructions": {+ "name": "search_instructions",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "citation_format": {+ "name": "citation_format",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "default": "'inline'"+ },+ "is_active": {+ "name": "is_active",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": true+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.api_usage": {+ "name": "api_usage",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "source": {+ "name": "source",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "source_id": {+ "name": "source_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "model": {+ "name": "model",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "input_tokens": {+ "name": "input_tokens",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "output_tokens": {+ "name": "output_tokens",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "duration_ms": {+ "name": "duration_ms",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "metadata": {+ "name": "metadata",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "api_usage_source_idx": {+ "name": "api_usage_source_idx",+ "columns": [+ {+ "expression": "source",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "api_usage_created_at_idx": {+ "name": "api_usage_created_at_idx",+ "columns": [+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.apikey": {+ "name": "apikey",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "start": {+ "name": "start",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "prefix": {+ "name": "prefix",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "key": {+ "name": "key",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "configId": {+ "name": "configId",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "referenceId": {+ "name": "referenceId",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "refillInterval": {+ "name": "refillInterval",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "refillAmount": {+ "name": "refillAmount",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "lastRefillAt": {+ "name": "lastRefillAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": false+ },+ "enabled": {+ "name": "enabled",+ "type": "boolean",+ "primaryKey": false,+ "notNull": false,+ "default": true+ },+ "rateLimitEnabled": {+ "name": "rateLimitEnabled",+ "type": "boolean",+ "primaryKey": false,+ "notNull": false,+ "default": true+ },+ "rateLimitTimeWindow": {+ "name": "rateLimitTimeWindow",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "default": 86400000+ },+ "rateLimitMax": {+ "name": "rateLimitMax",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "default": 10+ },+ "requestCount": {+ "name": "requestCount",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "default": 0+ },+ "remaining": {+ "name": "remaining",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "lastRequest": {+ "name": "lastRequest",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": false+ },+ "expiresAt": {+ "name": "expiresAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true+ },+ "updatedAt": {+ "name": "updatedAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true+ },+ "permissions": {+ "name": "permissions",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "metadata": {+ "name": "metadata",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ }+ },+ "indexes": {+ "apikey_key_idx": {+ "name": "apikey_key_idx",+ "columns": [+ {+ "expression": "key",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "apikey_userId_idx": {+ "name": "apikey_userId_idx",+ "columns": [+ {+ "expression": "userId",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "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": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.chats": {+ "name": "chats",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "mode": {+ "name": "mode",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'chat'"+ },+ "is_public": {+ "name": "is_public",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "share_token": {+ "name": "share_token",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "chats_user_id_idx": {+ "name": "chats_user_id_idx",+ "columns": [+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "chats_share_token_idx": {+ "name": "chats_share_token_idx",+ "columns": [+ {+ "expression": "share_token",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.evlog_events": {+ "name": "evlog_events",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "timestamp": {+ "name": "timestamp",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "level": {+ "name": "level",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "service": {+ "name": "service",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "environment": {+ "name": "environment",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "method": {+ "name": "method",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "path": {+ "name": "path",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "status": {+ "name": "status",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "duration_ms": {+ "name": "duration_ms",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "request_id": {+ "name": "request_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "source": {+ "name": "source",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "error": {+ "name": "error",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "data": {+ "name": "data",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ }+ },+ "indexes": {+ "evlog_events_timestamp_idx": {+ "name": "evlog_events_timestamp_idx",+ "columns": [+ {+ "expression": "timestamp",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "evlog_events_level_idx": {+ "name": "evlog_events_level_idx",+ "columns": [+ {+ "expression": "level",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "evlog_events_service_idx": {+ "name": "evlog_events_service_idx",+ "columns": [+ {+ "expression": "service",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "evlog_events_status_idx": {+ "name": "evlog_events_status_idx",+ "columns": [+ {+ "expression": "status",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "evlog_events_request_id_idx": {+ "name": "evlog_events_request_id_idx",+ "columns": [+ {+ "expression": "request_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "evlog_events_created_at_idx": {+ "name": "evlog_events_created_at_idx",+ "columns": [+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.messages": {+ "name": "messages",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "chat_id": {+ "name": "chat_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "role": {+ "name": "role",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "parts": {+ "name": "parts",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "feedback": {+ "name": "feedback",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "model": {+ "name": "model",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "input_tokens": {+ "name": "input_tokens",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "output_tokens": {+ "name": "output_tokens",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "duration_ms": {+ "name": "duration_ms",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "source": {+ "name": "source",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "default": "'web'"+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "messages_chat_id_idx": {+ "name": "messages_chat_id_idx",+ "columns": [+ {+ "expression": "chat_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "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": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.session": {+ "name": "session",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "expiresAt": {+ "name": "expiresAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true+ },+ "token": {+ "name": "token",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "createdAt": {+ "name": "createdAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updatedAt": {+ "name": "updatedAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true+ },+ "ipAddress": {+ "name": "ipAddress",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "userAgent": {+ "name": "userAgent",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "impersonatedBy": {+ "name": "impersonatedBy",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ }+ },+ "indexes": {+ "session_userId_idx": {+ "name": "session_userId_idx",+ "columns": [+ {+ "expression": "userId",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "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": {+ "session_token_unique": {+ "name": "session_token_unique",+ "nullsNotDistinct": false,+ "columns": [+ "token"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.sources": {+ "name": "sources",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "type": {+ "name": "type",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "label": {+ "name": "label",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "base_path": {+ "name": "base_path",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "default": "'/docs'"+ },+ "repo": {+ "name": "repo",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "branch": {+ "name": "branch",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "content_path": {+ "name": "content_path",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "output_path": {+ "name": "output_path",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "readme_only": {+ "name": "readme_only",+ "type": "boolean",+ "primaryKey": false,+ "notNull": false,+ "default": false+ },+ "channel_id": {+ "name": "channel_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "handle": {+ "name": "handle",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "max_videos": {+ "name": "max_videos",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "default": 50+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "sources_type_idx": {+ "name": "sources_type_idx",+ "columns": [+ {+ "expression": "type",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.usage_stats": {+ "name": "usage_stats",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "date": {+ "name": "date",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "source": {+ "name": "source",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'web'"+ },+ "model": {+ "name": "model",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "message_count": {+ "name": "message_count",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "total_input_tokens": {+ "name": "total_input_tokens",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "total_output_tokens": {+ "name": "total_output_tokens",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "total_duration_ms": {+ "name": "total_duration_ms",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "usage_stats_date_idx": {+ "name": "usage_stats_date_idx",+ "columns": [+ {+ "expression": "date",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "usage_stats_date_user_source_model_idx": {+ "name": "usage_stats_date_user_source_model_idx",+ "columns": [+ {+ "expression": "date",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "source",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "model",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.user": {+ "name": "user",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "email": {+ "name": "email",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "emailVerified": {+ "name": "emailVerified",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "image": {+ "name": "image",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updatedAt": {+ "name": "updatedAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "role": {+ "name": "role",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "banned": {+ "name": "banned",+ "type": "boolean",+ "primaryKey": false,+ "notNull": false,+ "default": false+ },+ "banReason": {+ "name": "banReason",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "banExpires": {+ "name": "banExpires",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": false+ },+ "username": {+ "name": "username",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "user_email_unique": {+ "name": "user_email_unique",+ "nullsNotDistinct": false,+ "columns": [+ "email"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.verification": {+ "name": "verification",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "identifier": {+ "name": "identifier",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "value": {+ "name": "value",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "expiresAt": {+ "name": "expiresAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true+ },+ "createdAt": {+ "name": "createdAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updatedAt": {+ "name": "updatedAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "verification_identifier_idx": {+ "name": "verification_identifier_idx",+ "columns": [+ {+ "expression": "identifier",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ }+ },+ "enums": {},+ "schemas": {},+ "sequences": {},+ "roles": {},+ "policies": {},+ "views": {},+ "_meta": {+ "columns": {},+ "schemas": {},+ "tables": {}+ }+}\ No newline at end of filediff --git a/apps/app/server/db/migrations/postgresql/meta/0002_snapshot.json b/apps/app/server/db/migrations/postgresql/meta/0002_snapshot.jsonnew file mode 100644index 0000000..196c716--- /dev/null+++ b/apps/app/server/db/migrations/postgresql/meta/0002_snapshot.json@@ -0,0 +1,1441 @@+{+ "id": "457ef60e-1eb0-4590-b1d4-a08b849d4c70",+ "prevId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",+ "version": "7",+ "dialect": "postgresql",+ "tables": {+ "public.account": {+ "name": "account",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "accountId": {+ "name": "accountId",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "providerId": {+ "name": "providerId",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "accessToken": {+ "name": "accessToken",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "refreshToken": {+ "name": "refreshToken",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "idToken": {+ "name": "idToken",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "accessTokenExpiresAt": {+ "name": "accessTokenExpiresAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": false+ },+ "refreshTokenExpiresAt": {+ "name": "refreshTokenExpiresAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": false+ },+ "scope": {+ "name": "scope",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "password": {+ "name": "password",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updatedAt": {+ "name": "updatedAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true+ }+ },+ "indexes": {+ "account_userId_idx": {+ "name": "account_userId_idx",+ "columns": [+ {+ "expression": "userId",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "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": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.agent_config": {+ "name": "agent_config",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'default'"+ },+ "additional_prompt": {+ "name": "additional_prompt",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "response_style": {+ "name": "response_style",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "default": "'concise'"+ },+ "language": {+ "name": "language",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "default": "'en'"+ },+ "default_model": {+ "name": "default_model",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "max_steps_multiplier": {+ "name": "max_steps_multiplier",+ "type": "real",+ "primaryKey": false,+ "notNull": false,+ "default": 1+ },+ "temperature": {+ "name": "temperature",+ "type": "real",+ "primaryKey": false,+ "notNull": false,+ "default": 0.7+ },+ "search_instructions": {+ "name": "search_instructions",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "citation_format": {+ "name": "citation_format",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "default": "'inline'"+ },+ "is_active": {+ "name": "is_active",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": true+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.api_usage": {+ "name": "api_usage",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "source": {+ "name": "source",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "source_id": {+ "name": "source_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "model": {+ "name": "model",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "input_tokens": {+ "name": "input_tokens",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "output_tokens": {+ "name": "output_tokens",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "duration_ms": {+ "name": "duration_ms",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "metadata": {+ "name": "metadata",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "api_usage_source_idx": {+ "name": "api_usage_source_idx",+ "columns": [+ {+ "expression": "source",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "api_usage_created_at_idx": {+ "name": "api_usage_created_at_idx",+ "columns": [+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.apikey": {+ "name": "apikey",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "configId": {+ "name": "configId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'default'"+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "start": {+ "name": "start",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "referenceId": {+ "name": "referenceId",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "prefix": {+ "name": "prefix",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "key": {+ "name": "key",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "refillInterval": {+ "name": "refillInterval",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "refillAmount": {+ "name": "refillAmount",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "lastRefillAt": {+ "name": "lastRefillAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": false+ },+ "enabled": {+ "name": "enabled",+ "type": "boolean",+ "primaryKey": false,+ "notNull": false,+ "default": true+ },+ "rateLimitEnabled": {+ "name": "rateLimitEnabled",+ "type": "boolean",+ "primaryKey": false,+ "notNull": false,+ "default": true+ },+ "rateLimitTimeWindow": {+ "name": "rateLimitTimeWindow",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "default": 86400000+ },+ "rateLimitMax": {+ "name": "rateLimitMax",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "default": 10+ },+ "requestCount": {+ "name": "requestCount",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "default": 0+ },+ "remaining": {+ "name": "remaining",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "lastRequest": {+ "name": "lastRequest",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": false+ },+ "expiresAt": {+ "name": "expiresAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true+ },+ "updatedAt": {+ "name": "updatedAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true+ },+ "permissions": {+ "name": "permissions",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "metadata": {+ "name": "metadata",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ }+ },+ "indexes": {+ "apikey_configId_idx": {+ "name": "apikey_configId_idx",+ "columns": [+ {+ "expression": "configId",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "apikey_referenceId_idx": {+ "name": "apikey_referenceId_idx",+ "columns": [+ {+ "expression": "referenceId",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "apikey_key_idx": {+ "name": "apikey_key_idx",+ "columns": [+ {+ "expression": "key",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.chats": {+ "name": "chats",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "mode": {+ "name": "mode",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'chat'"+ },+ "is_public": {+ "name": "is_public",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "share_token": {+ "name": "share_token",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "chats_user_id_idx": {+ "name": "chats_user_id_idx",+ "columns": [+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "chats_share_token_idx": {+ "name": "chats_share_token_idx",+ "columns": [+ {+ "expression": "share_token",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.evlog_events": {+ "name": "evlog_events",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "timestamp": {+ "name": "timestamp",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "level": {+ "name": "level",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "service": {+ "name": "service",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "environment": {+ "name": "environment",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "method": {+ "name": "method",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "path": {+ "name": "path",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "status": {+ "name": "status",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "duration_ms": {+ "name": "duration_ms",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "request_id": {+ "name": "request_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "source": {+ "name": "source",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "error": {+ "name": "error",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "data": {+ "name": "data",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "created_at": {+ "name": "created_at",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ }+ },+ "indexes": {+ "evlog_events_timestamp_idx": {+ "name": "evlog_events_timestamp_idx",+ "columns": [+ {+ "expression": "timestamp",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "evlog_events_level_idx": {+ "name": "evlog_events_level_idx",+ "columns": [+ {+ "expression": "level",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "evlog_events_service_idx": {+ "name": "evlog_events_service_idx",+ "columns": [+ {+ "expression": "service",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "evlog_events_status_idx": {+ "name": "evlog_events_status_idx",+ "columns": [+ {+ "expression": "status",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "evlog_events_request_id_idx": {+ "name": "evlog_events_request_id_idx",+ "columns": [+ {+ "expression": "request_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "evlog_events_created_at_idx": {+ "name": "evlog_events_created_at_idx",+ "columns": [+ {+ "expression": "created_at",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.messages": {+ "name": "messages",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "chat_id": {+ "name": "chat_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "role": {+ "name": "role",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "parts": {+ "name": "parts",+ "type": "jsonb",+ "primaryKey": false,+ "notNull": false+ },+ "feedback": {+ "name": "feedback",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "model": {+ "name": "model",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "input_tokens": {+ "name": "input_tokens",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "output_tokens": {+ "name": "output_tokens",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "duration_ms": {+ "name": "duration_ms",+ "type": "integer",+ "primaryKey": false,+ "notNull": false+ },+ "source": {+ "name": "source",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "default": "'web'"+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "messages_chat_id_idx": {+ "name": "messages_chat_id_idx",+ "columns": [+ {+ "expression": "chat_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "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": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.session": {+ "name": "session",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "expiresAt": {+ "name": "expiresAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true+ },+ "token": {+ "name": "token",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "createdAt": {+ "name": "createdAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updatedAt": {+ "name": "updatedAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true+ },+ "ipAddress": {+ "name": "ipAddress",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "userAgent": {+ "name": "userAgent",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "impersonatedBy": {+ "name": "impersonatedBy",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ }+ },+ "indexes": {+ "session_userId_idx": {+ "name": "session_userId_idx",+ "columns": [+ {+ "expression": "userId",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "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": {+ "session_token_unique": {+ "name": "session_token_unique",+ "nullsNotDistinct": false,+ "columns": [+ "token"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.sources": {+ "name": "sources",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "type": {+ "name": "type",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "label": {+ "name": "label",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "base_path": {+ "name": "base_path",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "default": "'/docs'"+ },+ "repo": {+ "name": "repo",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "branch": {+ "name": "branch",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "content_path": {+ "name": "content_path",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "output_path": {+ "name": "output_path",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "readme_only": {+ "name": "readme_only",+ "type": "boolean",+ "primaryKey": false,+ "notNull": false,+ "default": false+ },+ "channel_id": {+ "name": "channel_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "handle": {+ "name": "handle",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "max_videos": {+ "name": "max_videos",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "default": 50+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "sources_type_idx": {+ "name": "sources_type_idx",+ "columns": [+ {+ "expression": "type",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.usage_stats": {+ "name": "usage_stats",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "date": {+ "name": "date",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "user_id": {+ "name": "user_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "source": {+ "name": "source",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "default": "'web'"+ },+ "model": {+ "name": "model",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "message_count": {+ "name": "message_count",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "total_input_tokens": {+ "name": "total_input_tokens",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "total_output_tokens": {+ "name": "total_output_tokens",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "total_duration_ms": {+ "name": "total_duration_ms",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "default": 0+ },+ "created_at": {+ "name": "created_at",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "usage_stats_date_idx": {+ "name": "usage_stats_date_idx",+ "columns": [+ {+ "expression": "date",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ },+ "usage_stats_date_user_source_model_idx": {+ "name": "usage_stats_date_user_source_model_idx",+ "columns": [+ {+ "expression": "date",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "user_id",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "source",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ },+ {+ "expression": "model",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": true,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.user": {+ "name": "user",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "email": {+ "name": "email",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "emailVerified": {+ "name": "emailVerified",+ "type": "boolean",+ "primaryKey": false,+ "notNull": true,+ "default": false+ },+ "image": {+ "name": "image",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updatedAt": {+ "name": "updatedAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "role": {+ "name": "role",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "banned": {+ "name": "banned",+ "type": "boolean",+ "primaryKey": false,+ "notNull": false,+ "default": false+ },+ "banReason": {+ "name": "banReason",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ },+ "banExpires": {+ "name": "banExpires",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": false+ },+ "username": {+ "name": "username",+ "type": "text",+ "primaryKey": false,+ "notNull": false+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {+ "user_email_unique": {+ "name": "user_email_unique",+ "nullsNotDistinct": false,+ "columns": [+ "email"+ ]+ }+ },+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ },+ "public.verification": {+ "name": "verification",+ "schema": "",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true+ },+ "identifier": {+ "name": "identifier",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "value": {+ "name": "value",+ "type": "text",+ "primaryKey": false,+ "notNull": true+ },+ "expiresAt": {+ "name": "expiresAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true+ },+ "createdAt": {+ "name": "createdAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ },+ "updatedAt": {+ "name": "updatedAt",+ "type": "timestamp",+ "primaryKey": false,+ "notNull": true,+ "default": "now()"+ }+ },+ "indexes": {+ "verification_identifier_idx": {+ "name": "verification_identifier_idx",+ "columns": [+ {+ "expression": "identifier",+ "isExpression": false,+ "asc": true,+ "nulls": "last"+ }+ ],+ "isUnique": false,+ "concurrently": false,+ "method": "btree",+ "with": {}+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "policies": {},+ "checkConstraints": {},+ "isRLSEnabled": false+ }+ },+ "enums": {},+ "schemas": {},+ "sequences": {},+ "roles": {},+ "policies": {},+ "views": {},+ "_meta": {+ "columns": {},+ "schemas": {},+ "tables": {}+ }+}\ No newline at end of filediff --git a/apps/app/server/db/migrations/postgresql/meta/_journal.json b/apps/app/server/db/migrations/postgresql/meta/_journal.jsonindex a909ce8..eaa4f62 100644--- a/apps/app/server/db/migrations/postgresql/meta/_journal.json+++ b/apps/app/server/db/migrations/postgresql/meta/_journal.json@@ -8,6 +8,20 @@"when": 1771342025247,"tag": "0000_wild_vin_gonzales","breakpoints": true+ },+ {+ "idx": 1,+ "version": "7",+ "when": 1771342025248,+ "tag": "0001_apikey_v2",+ "breakpoints": true+ },+ {+ "idx": 2,+ "version": "7",+ "when": 1774121656018,+ "tag": "0002_elite_absorbing_man",+ "breakpoints": true}]}\ No newline at end of filediff --git a/apps/app/server/db/schema.ts b/apps/app/server/db/schema.tsindex 8d2c1c9..d6fc90e 100644--- a/apps/app/server/db/schema.ts+++ b/apps/app/server/db/schema.ts@@ -47,7 +47,7 @@ export const messagesRelations = relations(messages, ({ one }) => ({export const sources = pgTable('sources', {id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),- type: text('type', { enum: ['github', 'youtube'] }).notNull(),+ type: text('type', { enum: ['github', 'youtube', 'file'] }).notNull(),label: text('label').notNull(),basePath: text('base_path').default('/docs'),repo: text('repo'),diff --git a/apps/app/server/utils/sandbox/git.ts b/apps/app/server/utils/sandbox/git.tsindex fab6cb2..22ac1ca 100644--- a/apps/app/server/utils/sandbox/git.ts+++ b/apps/app/server/utils/sandbox/git.ts@@ -136,7 +136,7 @@ export async function pushChanges(return { success: true, hasChanges: false }}- await addFiles(sandbox, 'docs/')+ await addFiles(sandbox, '.')await commit(sandbox, options.commitMessage)await push(sandbox, options.repoUrl, options.branch)diff --git a/apps/app/server/utils/sandbox/source-sync.ts b/apps/app/server/utils/sandbox/source-sync.tsindex 1d07214..bd357b8 100644--- a/apps/app/server/utils/sandbox/source-sync.ts+++ b/apps/app/server/utils/sandbox/source-sync.ts@@ -2,7 +2,7 @@ import type { Sandbox } from '@vercel/sandbox'import { createError, log } from 'evlog'import { youtube } from '@googleapis/youtube'import { YoutubeTranscript } from 'youtube-transcript'-import type { GitHubSource, Source, SyncSourceResult, YouTubeSource } from '../../workflows/sync-docs/types'+import type { FileSource, GitHubSource, Source, SyncSourceResult, YouTubeSource } from '../../workflows/sync-docs/types'interface YouTubeVideo {id: string@@ -355,6 +355,108 @@ function slugify(text: string): string {.slice(0, 50)}+/** Writes pre-loaded file contents to sandbox */+export async function syncFileSource(+ sandbox: Sandbox,+ source: FileSource,+): Promise<SyncSourceResult> {+ const basePath = source.basePath || '/files'+ const outputPath = source.outputPath || source.id+ const targetDir = `/vercel/sandbox${basePath}/${outputPath}`++ try {+ log.info('sync', `Starting file sync for "${source.label}"`)++ await sandbox.runCommand({+ cmd: 'mkdir',+ args: ['-p', targetDir],+ cwd: '/vercel/sandbox',+ })++ if (source.files.length === 0) {+ log.info('sync', `No files provided for "${source.label}"`)+ return { sourceId: source.id, label: source.label, success: true, fileCount: 0 }+ }++ let fileCount = 0++ for (const entry of source.files) {+ try {+ const filepath = `${targetDir}/${entry.filename}`++ await sandbox.runCommand({+ cmd: 'sh',+ args: ['-c', `cat > '${filepath}' << 'EOFMARKER'\n${entry.content}\nEOFMARKER`],+ cwd: '/vercel/sandbox',+ })++ fileCount+++ } catch (error) {+ const errorMessage = error instanceof Error ? error.message : String(error)+ log.warn('sync', `Failed to sync file ${entry.filename}: ${errorMessage}`)+ }+ }++ log.info('sync', `File sync completed for "${source.label}": ${fileCount} files`)++ return { sourceId: source.id, label: source.label, success: true, fileCount }+ } catch (error) {+ const errorMessage = error instanceof Error ? error.message : String(error)+ log.error('sync', `File sync failed for "${source.label}": ${errorMessage}`)+ return { sourceId: source.id, label: source.label, success: false, fileCount: 0, error: errorMessage }+ }+}++/** Removes directories in the sandbox that don't belong to any active source */+export async function cleanupStaleSources(+ sandbox: Sandbox,+ sources: Source[],+): Promise<string[]> {+ const expectedDirs = new Map<string, Set<string>>()++ for (const source of sources) {+ const basePath = source.basePath || (source.type === 'youtube' ? '/youtube' : source.type === 'file' ? '/files' : '/docs')+ const outputPath = source.outputPath || source.id+ if (!expectedDirs.has(basePath)) {+ expectedDirs.set(basePath, new Set())+ }+ expectedDirs.get(basePath)!.add(outputPath)+ }++ const removed: string[] = []+ const basePaths = new Set(['/docs', '/files', '/youtube', ...expectedDirs.keys()])++ for (const basePath of basePaths) {+ const fullBase = `/vercel/sandbox${basePath}`+ const result = await sandbox.runCommand({+ cmd: 'sh',+ args: ['-c', `[ -d '${fullBase}' ] && ls -1 '${fullBase}' || true`],+ cwd: '/vercel/sandbox',+ })++ const output = (await result.stdout()).trim()+ if (!output) continue++ const existingDirs = output.split('\n').filter(Boolean)+ const expected = expectedDirs.get(basePath) || new Set()++ for (const dir of existingDirs) {+ if (!expected.has(dir)) {+ const staleDir = `${fullBase}/${dir}`+ log.info('sync', `Removing stale source directory: ${staleDir}`)+ await sandbox.runCommand({+ cmd: 'rm',+ args: ['-rf', staleDir],+ cwd: '/vercel/sandbox',+ })+ removed.push(`${basePath}/${dir}`)+ }+ }+ }++ return removed+}+/** Syncs all sources sequentially, returns array of results */export async function syncSources(sandbox: Sandbox,@@ -380,6 +482,8 @@ export async function syncSources(} else {result = await syncYouTubeSource(sandbox, source, config.youtubeApiKey)}+ } else if (source.type === 'file') {+ result = await syncFileSource(sandbox, source)} else {const unknownSource = source as Sourceresult = {diff --git a/apps/app/server/workflows/sync-docs/steps/cleanup-stale.ts b/apps/app/server/workflows/sync-docs/steps/cleanup-stale.tsnew file mode 100644index 0000000..adc1751--- /dev/null+++ b/apps/app/server/workflows/sync-docs/steps/cleanup-stale.ts@@ -0,0 +1,37 @@+/**+ * Step: Cleanup Stale Sources+ *+ * Removes directories from the sandbox that belong to sources+ * that have been deleted since the last sync.+ */++import { getStepMetadata } from 'workflow'+import { log } from 'evlog'+import { Sandbox } from '@vercel/sandbox'+import type { Source } from '../types'+import { cleanupStaleSources } from '../../../utils/sandbox/source-sync'++export interface CleanupStaleResult {+ removed: string[]+}++export async function stepCleanupStale(+ sandboxId: string,+ sources: Source[],+): Promise<CleanupStaleResult> {+ 'use step'++ const { stepId } = getStepMetadata()+ log.info('sync', `[${stepId}] Cleaning up stale source directories`)++ const sandbox = await Sandbox.get({ sandboxId })+ const removed = await cleanupStaleSources(sandbox, sources)++ if (removed.length > 0) {+ log.info('sync', `[${stepId}] Removed ${removed.length} stale directories: ${removed.join(', ')}`)+ } else {+ log.info('sync', `[${stepId}] No stale directories found`)+ }++ return { removed }+}diff --git a/apps/app/server/workflows/sync-docs/steps/index.ts b/apps/app/server/workflows/sync-docs/steps/index.tsindex 53adb75..4f89624 100644--- a/apps/app/server/workflows/sync-docs/steps/index.ts+++ b/apps/app/server/workflows/sync-docs/steps/index.ts@@ -5,6 +5,9 @@export { stepCreateSandbox } from './create-sandbox'export type { CreateSandboxResult } from './create-sandbox'+export { stepCleanupStale } from './cleanup-stale'+export type { CleanupStaleResult } from './cleanup-stale'+export { stepSyncSource } from './sync-source'export { stepPushChanges } from './push-changes'diff --git a/apps/app/server/workflows/sync-docs/steps/sync-source.ts b/apps/app/server/workflows/sync-docs/steps/sync-source.tsindex 0542cb6..7c15158 100644--- a/apps/app/server/workflows/sync-docs/steps/sync-source.ts+++ b/apps/app/server/workflows/sync-docs/steps/sync-source.ts@@ -9,7 +9,7 @@ import { getStepMetadata, RetryableError } from 'workflow'import { log } from 'evlog'import { Sandbox } from '@vercel/sandbox'import type { Source, SyncSourceResult } from '../types'-import { syncGitHubSource, syncYouTubeSource } from '../../../utils/sandbox/source-sync'+import { syncFileSource, syncGitHubSource, syncYouTubeSource } from '../../../utils/sandbox/source-sync'export async function stepSyncSource(sandboxId: string,@@ -40,8 +40,9 @@ export async function stepSyncSource(} else {result = await syncYouTubeSource(sandbox, source, config.youtubeApiKey)}+ } else if (source.type === 'file') {+ result = await syncFileSource(sandbox, source)} else {- // This branch handles future source types - cast to Source for accessconst unknownSource = source as Sourceresult = {sourceId: unknownSource.id,diff --git a/apps/app/server/workflows/sync-docs/types.ts b/apps/app/server/workflows/sync-docs/types.tsindex f9141f6..6927273 100644--- a/apps/app/server/workflows/sync-docs/types.ts+++ b/apps/app/server/workflows/sync-docs/types.ts@@ -32,7 +32,21 @@ export interface YouTubeSource {outputPath: string}-export type Source = GitHubSource | YouTubeSource+export interface FileSourceEntry {+ filename: string+ content: string+}++export interface FileSource {+ id: string+ type: 'file'+ label: string+ basePath: string+ outputPath: string+ files: FileSourceEntry[]+}++export type Source = GitHubSource | YouTubeSource | FileSourceexport interface SyncSourceResult {sourceId: stringdiff --git a/apps/app/server/workflows/sync-docs/workflow.ts b/apps/app/server/workflows/sync-docs/workflow.tsindex f9a71c3..ae443fb 100644--- a/apps/app/server/workflows/sync-docs/workflow.ts+++ b/apps/app/server/workflows/sync-docs/workflow.ts@@ -7,9 +7,10 @@* This workflow is composed of granular steps for better retry semantics* and observability:* 1. Create sandbox from git repository- * 2. Sync each source (parallel execution)- * 3. Push changes to git- * 4. Take snapshot+ * 2. Cleanup stale source directories (from deleted sources)+ * 3. Sync each source (parallel execution)+ * 4. Push changes to git+ * 5. Take snapshot*/import { FatalError } from 'workflow'@@ -17,6 +18,7 @@ import { log } from 'evlog'import type { Source, SyncConfig, SyncResult, SyncSourceResult } from './types'import {stepCreateSandbox,+ stepCleanupStale,stepSyncSource,stepPushChanges,stepTakeSnapshot,@@ -53,7 +55,10 @@ export async function syncDocumentation(// Step 1: Create sandboxconst { sandboxId } = await stepCreateSandbox(config)- // Step 2: Sync all sources in parallel+ // Step 2: Remove directories from deleted sources+ await stepCleanupStale(sandboxId, filteredSources)++ // Step 3: Sync all sources in parallel// Each source is its own step for granular retry and observabilityconst results = await Promise.all(filteredSources.map(source =>@@ -64,7 +69,7 @@ export async function syncDocumentation(),)- // Step 3: Push changes to git+ // Step 4: Push changes to gitawait stepPushChanges(sandboxId,{@@ -75,7 +80,7 @@ export async function syncDocumentation(results,)- // Step 4: Take snapshot+ // Step 5: Take snapshotconst { snapshotId } = await stepTakeSnapshot(sandboxId)// Compute summary