Skip to content

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

up

Hugo Richard312ff16310e3
diff --git a/apps/api/lib/sandbox/index.ts b/apps/api/lib/sandbox/index.ts
index a899c2d..0f55e62 100644
--- a/apps/api/lib/sandbox/index.ts
+++ b/apps/api/lib/sandbox/index.ts
@@ -1,4 +1,3 @@
-// Types
export type {
ActiveSandbox,
FileContent,
@@ -9,7 +8,6 @@ export type {
SnapshotMetadata,
} from './types'
-// Session management
export {
deleteSession,
generateSessionId,
@@ -18,7 +16,6 @@ export {
touchSession,
} from './session'
-// Snapshot management
export {
getCurrentSnapshot,
getSnapshotIdOrThrow,
@@ -26,7 +23,6 @@ export {
setCurrentSnapshot,
} from './snapshot'
-// Sandbox operations
export {
createSnapshotFromRepo,
getOrCreateSandbox,
diff --git a/apps/api/lib/sandbox/manager.ts b/apps/api/lib/sandbox/manager.ts
index 1d0c1d9..bbb7929 100644
--- a/apps/api/lib/sandbox/manager.ts
+++ b/apps/api/lib/sandbox/manager.ts
@@ -167,11 +167,9 @@ export async function getOrCreateSandbox(sessionId?: string): Promise<ActiveSand
}
}
- // Get or create snapshot (auto-creates from repo if needed)
const snapshotId = await getOrCreateSnapshot()
const sandbox = await createSandboxFromSnapshot(snapshotId)
- // Create session
const newSessionId = sessionId || generateSessionId()
const session = await setSession(
newSessionId,
diff --git a/apps/api/routes/api/sandbox/read.post.ts b/apps/api/routes/api/sandbox/read.post.ts
index e682902..379c9bb 100644
--- a/apps/api/routes/api/sandbox/read.post.ts
+++ b/apps/api/routes/api/sandbox/read.post.ts
@@ -21,12 +21,10 @@ export default defineHandler(async (event) => {
log.set({ pathCount: body.paths.length, sessionId: body.sessionId })
- // Get or create sandbox
const { sandbox, sessionId } = await getOrCreateSandbox(body.sessionId)
log.set({ sandboxId: sandbox.sandboxId })
- // Read files
const files = await read(sandbox, body.paths)
log.set({ fileCount: files.length })
diff --git a/apps/api/routes/api/sync/index.post.ts b/apps/api/routes/api/sync/index.post.ts
index e773f68..0df7e6c 100644
--- a/apps/api/routes/api/sync/index.post.ts
+++ b/apps/api/routes/api/sync/index.post.ts
@@ -4,9 +4,26 @@ import { useRuntimeConfig } from 'nitro/runtime-config'
import { z } from 'zod'
import { syncDocumentation } from '~/workflows/sync-docs'
+const sourceSchema = z.object({
+ id: z.string(),
+ type: z.enum(['github', 'youtube']),
+ label: z.string(),
+ // GitHub fields
+ repo: z.string().nullable().optional(),
+ branch: z.string().nullable().optional(),
+ contentPath: z.string().nullable().optional(),
+ outputPath: z.string().nullable().optional(),
+ readmeOnly: z.boolean().nullable().optional(),
+ // YouTube fields
+ channelId: z.string().nullable().optional(),
+ handle: z.string().nullable().optional(),
+ maxVideos: z.number().nullable().optional(),
+})
+
const bodySchema = z
.object({
sourceFilter: z.string().optional(),
+ sources: z.array(sourceSchema).optional(),
})
.optional()
@@ -16,6 +33,7 @@ const bodySchema = z
*
* Body (optional):
* - sourceFilter: string - Only sync a specific source
+ * - sources: array - Sources to sync (passed from chat app DB)
*/
export default defineHandler(async (event) => {
const body = await readValidatedBody(event, data => bodySchema.parse(data))
@@ -29,6 +47,7 @@ export default defineHandler(async (event) => {
const options = {
sourceFilter: body?.sourceFilter,
+ sources: body?.sources,
}
await start(syncDocumentation, [syncConfig, options])
diff --git a/apps/api/workflows/sync-docs/steps/get-sources.ts b/apps/api/workflows/sync-docs/steps/get-sources.ts
index 0848146..8fa3ae0 100644
--- a/apps/api/workflows/sync-docs/steps/get-sources.ts
+++ b/apps/api/workflows/sync-docs/steps/get-sources.ts
@@ -1,20 +1,66 @@
import { getLogger } from '@savoir/logger'
import { FatalError } from 'workflow'
-import type { GitHubSource } from '../utils/index.js'
+import type { DBSource, GitHubSource } from '../utils/index.js'
import { getGitHubSources, getSourceById } from '../utils/index.js'
-export async function getSourcesToSync(sourceFilter?: string): Promise<GitHubSource[]> {
+/**
+ * Normalize a DB source to a GitHubSource
+ */
+function normalizeGitHubSource(source: DBSource): GitHubSource {
+ return {
+ id: source.id,
+ type: 'github',
+ label: source.label,
+ repo: source.repo || '',
+ branch: source.branch || 'main',
+ contentPath: source.contentPath || '',
+ outputPath: source.outputPath || source.id,
+ readmeOnly: source.readmeOnly ?? false,
+ additionalSyncs: [],
+ }
+}
+
+interface GetSourcesOptions {
+ sourceFilter?: string
+ /** Sources passed directly from DB */
+ sources?: DBSource[]
+}
+
+export async function getSourcesToSync(options: GetSourcesOptions = {}): Promise<GitHubSource[]> {
'use step'
const logger = getLogger()
- let sources = await getGitHubSources()
+ const { sourceFilter, sources: dbSources } = options
+
+ let sources: GitHubSource[]
+
+ // If sources are passed from DB, use them directly
+ if (dbSources && dbSources.length > 0) {
+ // Filter to GitHub sources only and normalize
+ sources = dbSources
+ .filter(s => s.type === 'github')
+ .map(normalizeGitHubSource)
+
+ logger.log('sync', `Using ${sources.length} source(s) from DB`)
+ } else {
+ // Fall back to loading from config file
+ sources = await getGitHubSources()
+ logger.log('sync', `Loaded ${sources.length} source(s) from config`)
+ }
+ // Apply filter if specified
if (sourceFilter) {
- const source = await getSourceById(sourceFilter)
- if (!source || source.type !== 'github') {
- throw new FatalError(`Source not found: ${sourceFilter}`)
+ const filteredSource = sources.find(s => s.id === sourceFilter)
+ if (!filteredSource) {
+ // Try loading from config as fallback
+ const source = await getSourceById(sourceFilter)
+ if (!source || source.type !== 'github') {
+ throw new FatalError(`Source not found: ${sourceFilter}`)
+ }
+ sources = [source as GitHubSource]
+ } else {
+ sources = [filteredSource]
}
- sources = [source as GitHubSource]
}
logger.log('sync', `Found ${sources.length} source(s) to sync`)
diff --git a/apps/api/workflows/sync-docs/steps/sandbox-sync.ts b/apps/api/workflows/sync-docs/steps/sandbox-sync.ts
index af1977c..b586c47 100644
--- a/apps/api/workflows/sync-docs/steps/sandbox-sync.ts
+++ b/apps/api/workflows/sync-docs/steps/sandbox-sync.ts
@@ -60,7 +60,6 @@ export async function syncAllSourcesInSandbox(
results.push(result)
}
- // Take snapshot
logger.log('sync', 'Taking snapshot...')
const snapshot = await sandbox.snapshot()
logger.log('sync', `Snapshot created: ${snapshot.snapshotId}`)
@@ -165,7 +164,6 @@ async function syncSource(
cwd: '/vercel/sandbox',
})
- // Count files
const countResult = await sandbox.runCommand({
cmd: 'sh',
args: ['-c', `find ${targetDir} -type f -name "*.md" -o -name "*.mdx" | wc -l`],
diff --git a/apps/api/workflows/sync-docs/utils/index.ts b/apps/api/workflows/sync-docs/utils/index.ts
index 741b5d5..c84f28b 100644
--- a/apps/api/workflows/sync-docs/utils/index.ts
+++ b/apps/api/workflows/sync-docs/utils/index.ts
@@ -10,6 +10,7 @@ export type {
SyncConfig,
SyncOptions,
PushResult,
+ DBSource,
} from '@savoir/config'
export {
diff --git a/apps/api/workflows/sync-docs/workflow.ts b/apps/api/workflows/sync-docs/workflow.ts
index 00b29cd..6754ace 100644
--- a/apps/api/workflows/sync-docs/workflow.ts
+++ b/apps/api/workflows/sync-docs/workflow.ts
@@ -33,7 +33,7 @@ export async function syncDocumentation(
): Promise<SyncWorkflowResult> {
'use workflow'
- const { sourceFilter } = options
+ const { sourceFilter, sources: dbSources } = options
const logger = getLogger()
if (!config.snapshotRepo) {
@@ -41,7 +41,7 @@ export async function syncDocumentation(
}
// Step 1: Get sources to sync
- const sources = await getSourcesToSync(sourceFilter)
+ const sources = await getSourcesToSync({ sourceFilter, sources: dbSources })
if (sources.length === 0) {
throw new FatalError('No sources to sync')
@@ -73,7 +73,6 @@ export async function syncDocumentation(
await kv.setItem(KV_KEYS.CURRENT_SNAPSHOT, metadata)
logger.log('sync', 'Snapshot metadata stored in KV')
- // Log summary
const status = failCount === 0 ? '✓' : '✗'
logger.log('sync', `${status} Done: ${successCount}/${sources.length} sources, ${totalFiles} files`)
diff --git a/apps/chat/app/components/SourceCard.vue b/apps/chat/app/components/SourceCard.vue
new file mode 100644
index 0000000..e65c3bf
--- /dev/null
+++ b/apps/chat/app/components/SourceCard.vue
@@ -0,0 +1,153 @@
+<script setup lang="ts">
+interface SourceData {
+ id: string
+ type: 'github' | 'youtube'
+ label: string
+ repo: string | null
+ branch: string | null
+ contentPath: string | null
+ outputPath: string | null
+ readmeOnly: boolean | null
+ channelId: string | null
+ handle: string | null
+ maxVideos: number | null
+}
+
+const props = defineProps<{
+ source: SourceData
+}>()
+
+const emit = defineEmits<{
+ edit: []
+ delete: []
+ sync: []
+}>()
+
+const isSyncing = ref(false)
+
+function handleSync() {
+ isSyncing.value = true
+ emit('sync')
+ setTimeout(() => {
+ isSyncing.value = false
+ }, 2000)
+}
+
+const hasBadges = computed(() => {
+ if (props.source.type === 'github') {
+ return props.source.branch || props.source.contentPath || props.source.outputPath || props.source.readmeOnly
+ }
+ return props.source.maxVideos
+})
+</script>
+
+<template>
+ <div class="group relative rounded-xl border border-default bg-default/50 hover:bg-elevated/50 transition-all duration-200 hover:shadow-sm">
+ <div class="p-4">
+ <div class="flex items-start justify-between gap-4">
+ <div class="flex items-start gap-3 min-w-0">
+ <div
+ class="flex items-center justify-center size-9 rounded-lg shrink-0 transition-colors"
+ :class="source.type === 'github'
+ ? 'bg-neutral-100 dark:bg-neutral-800/80'
+ : 'bg-red-50 dark:bg-red-950/50'"
+ >
+ <UIcon
+ :name="source.type === 'github' ? 'i-simple-icons-github' : 'i-simple-icons-youtube'"
+ class="size-4"
+ :class="source.type === 'youtube' ? 'text-red-500' : 'text-neutral-700 dark:text-neutral-300'"
+ />
+ </div>
+
+ <div class="min-w-0 pt-0.5">
+ <h3 class="font-medium text-highlighted leading-tight">{{ source.label }}</h3>
+ <p class="text-sm text-muted mt-0.5 truncate">
+ <template v-if="source.type === 'github'">
+ {{ source.repo }}
+ </template>
+ <template v-else>
+ {{ source.handle || source.channelId }}
+ </template>
+ </p>
+ </div>
+ </div>
+
+ <div class="flex items-center gap-0.5 shrink-0 opacity-0 group-hover:opacity-100 transition-opacity">
+ <UTooltip text="Sync now" :delay-open="300">
+ <UButton
+ size="xs"
+ variant="ghost"
+ color="neutral"
+ icon="i-lucide-refresh-cw"
+ :loading="isSyncing"
+ class="rounded-lg"
+ @click="handleSync"
+ />
+ </UTooltip>
+ <UTooltip text="Edit" :delay-open="300">
+ <UButton
+ size="xs"
+ variant="ghost"
+ color="neutral"
+ icon="i-lucide-pencil"
+ class="rounded-lg"
+ @click="emit('edit')"
+ />
+ </UTooltip>
+ <UTooltip text="Delete" :delay-open="300">
+ <UButton
+ size="xs"
+ variant="ghost"
+ color="error"
+ icon="i-lucide-trash-2"
+ class="rounded-lg"
+ @click="emit('delete')"
+ />
+ </UTooltip>
+ </div>
+ </div>
+
+ <div v-if="hasBadges" class="flex flex-wrap items-center gap-1.5 mt-3 pl-12">
+ <template v-if="source.type === 'github'">
+ <span
+ v-if="source.branch"
+ class="inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-xs bg-neutral-100 dark:bg-neutral-800/80 text-muted"
+ >
+ <UIcon name="i-lucide-git-branch" class="size-3" />
+ {{ source.branch }}
+ </span>
+ <span
+ v-if="source.contentPath"
+ class="inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-xs bg-neutral-100 dark:bg-neutral-800/80 text-muted"
+ >
+ <UIcon name="i-lucide-folder" class="size-3" />
+ {{ source.contentPath }}
+ </span>
+ <span
+ v-if="source.outputPath"
+ class="inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-xs bg-primary-100 dark:bg-primary-900/30 text-primary-700 dark:text-primary-300"
+ >
+ <UIcon name="i-lucide-arrow-right" class="size-3" />
+ {{ source.outputPath }}
+ </span>
+ <span
+ v-if="source.readmeOnly"
+ class="inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-xs bg-amber-100 dark:bg-amber-900/30 text-amber-700 dark:text-amber-300"
+ >
+ <UIcon name="i-lucide-file-text" class="size-3" />
+ README only
+ </span>
+ </template>
+ <template v-else>
+ <span
+ v-if="source.maxVideos"
+ class="inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-xs bg-neutral-100 dark:bg-neutral-800/80 text-muted"
+ >
+ <UIcon name="i-lucide-video" class="size-3" />
+ Max {{ source.maxVideos }} videos
+ </span>
+ </template>
+ </div>
+ </div>
+ </div>
+</template>
diff --git a/apps/chat/app/components/SourceModal.vue b/apps/chat/app/components/SourceModal.vue
new file mode 100644
index 0000000..f9a428d
--- /dev/null
+++ b/apps/chat/app/components/SourceModal.vue
@@ -0,0 +1,236 @@
+<script setup lang="ts">
+interface SourceData {
+ id: string
+ type: 'github' | 'youtube'
+ label: string
+ repo: string | null
+ branch: string | null
+ contentPath: string | null
+ outputPath: string | null
+ readmeOnly: boolean | null
+ channelId: string | null
+ handle: string | null
+ maxVideos: number | null
+}
+
+const props = defineProps<{
+ source?: SourceData | null
+}>()
+
+const emit = defineEmits<{
+ close: []
+ saved: []
+}>()
+
+const toast = useToast()
+const isSubmitting = ref(false)
+
+const isEditing = computed(() => !!props.source)
+
+const form = ref({
+ type: props.source?.type || 'github' as 'github' | 'youtube',
+ label: props.source?.label || '',
+ repo: props.source?.repo || '',
+ branch: props.source?.branch || 'main',
+ contentPath: props.source?.contentPath || '',
+ outputPath: props.source?.outputPath || '',
+ readmeOnly: props.source?.readmeOnly || false,
+ channelId: props.source?.channelId || '',
+ handle: props.source?.handle || '',
+ maxVideos: props.source?.maxVideos || 50,
+})
+
+const typeOptions = [
+ { label: 'GitHub', value: 'github', icon: 'i-simple-icons-github' },
+ { label: 'YouTube', value: 'youtube', icon: 'i-simple-icons-youtube' },
+]
+
+async function save() {
+ isSubmitting.value = true
+ try {
+ const url = isEditing.value ? `/api/sources/${props.source!.id}` : '/api/sources'
+ const method = isEditing.value ? 'PUT' : 'POST'
+
+ await $fetch(url, { method, body: form.value })
+ toast.add({
+ title: isEditing.value ? 'Source updated' : 'Source created',
+ icon: 'i-lucide-check',
+ })
+ emit('saved')
+ } catch (error: unknown) {
+ toast.add({
+ title: 'Error',
+ description: error instanceof Error ? error.message : 'Failed to save source',
+ color: 'error',
+ icon: 'i-lucide-alert-circle',
+ })
+ } finally {
+ isSubmitting.value = false
+ }
+}
+</script>
+
+<template>
+ <UModal
+ :ui="{
+ footer: 'justify-end',
+ title: 'text-base font-medium',
+ description: 'text-sm',
+ }"
+ :close="{ onClick: () => emit('close') }"
+ default-open
+ @update:open="(open: boolean) => !open && emit('close')"
+ >
+ <template #header>
+ <div>
+ <h2 class="text-base font-medium text-highlighted">{{ isEditing ? 'Edit Source' : 'Add Source' }}</h2>
+ <p class="text-sm text-muted mt-0.5">{{ isEditing ? 'Update the source configuration' : 'Configure a new content source' }}</p>
+ </div>
+ </template>
+
+ <template #body>
+ <div class="flex flex-col gap-4">
+ <div class="flex flex-col gap-1.5">
+ <label class="text-sm font-medium text-highlighted">Type</label>
+ <USelectMenu
+ v-model="form.type"
+ :items="typeOptions"
+ value-key="value"
+ :disabled="isEditing"
+ class="w-full"
+ />
+ </div>
+
+ <div class="flex flex-col gap-1.5">
+ <label class="text-sm font-medium text-highlighted">
+ Label
+ <span class="text-red-500">*</span>
+ </label>
+ <UInput v-model="form.label" placeholder="e.g. Nuxt Documentation" class="w-full" />
+ <p class="text-xs text-muted">A friendly name to identify this source</p>
+ </div>
+
+ <template v-if="form.type === 'github'">
+ <div class="border-t border-default pt-4 mt-1">
+ <p class="text-xs font-medium text-muted uppercase tracking-wide mb-4">GitHub Configuration</p>
+
+ <div class="flex flex-col gap-4">
+ <div class="flex flex-col gap-1.5">
+ <label class="text-sm font-medium text-highlighted">
+ Repository
+ <span class="text-red-500">*</span>
+ </label>
+ <UInput
+ v-model="form.repo"
+ placeholder="nuxt/nuxt"
+ icon="i-simple-icons-github"
+ class="w-full"
+ />
+ <p class="text-xs text-muted">The repository in owner/repo format</p>
+ </div>
+
+ <div class="grid grid-cols-2 gap-3">
+ <div class="flex flex-col gap-1.5">
+ <label class="text-sm font-medium text-highlighted">Branch</label>
+ <UInput
+ v-model="form.branch"
+ placeholder="main"
+ icon="i-lucide-git-branch"
+ class="w-full"
+ />
+ </div>
+ <div class="flex flex-col gap-1.5">
+ <label class="text-sm font-medium text-highlighted">Output Path</label>
+ <UInput
+ v-model="form.outputPath"
+ placeholder="nuxt"
+ icon="i-lucide-folder-output"
+ class="w-full"
+ />
+ </div>
+ </div>
+
+ <div class="flex flex-col gap-1.5">
+ <label class="text-sm font-medium text-highlighted">Content Path</label>
+ <UInput
+ v-model="form.contentPath"
+ placeholder="docs/content"
+ icon="i-lucide-folder"
+ class="w-full"
+ />
+ <p class="text-xs text-muted">Path to the documentation folder</p>
+ </div>
+
+ <div class="flex items-center justify-between py-2 px-3 rounded-lg bg-neutral-50 dark:bg-neutral-900/50">
+ <div>
+ <p class="text-sm font-medium text-highlighted">README Only</p>
+ <p class="text-xs text-muted">Only sync the README.md file</p>
+ </div>
+ <USwitch v-model="form.readmeOnly" />
+ </div>
+ </div>
+ </div>
+ </template>
+
+ <template v-if="form.type === 'youtube'">
+ <div class="border-t border-default pt-4 mt-1">
+ <p class="text-xs font-medium text-muted uppercase tracking-wide mb-4">YouTube Configuration</p>
+
+ <div class="flex flex-col gap-4">
+ <div class="flex flex-col gap-1.5">
+ <label class="text-sm font-medium text-highlighted">Channel ID</label>
+ <UInput
+ v-model="form.channelId"
+ placeholder="UCxxxxxxxxxxxxxxxxxxxxxx"
+ icon="i-simple-icons-youtube"
+ class="w-full"
+ />
+ <p class="text-xs text-muted">The unique channel identifier (starts with UC)</p>
+ </div>
+
+ <div class="flex flex-col gap-1.5">
+ <label class="text-sm font-medium text-highlighted">Handle</label>
+ <UInput
+ v-model="form.handle"
+ placeholder="@channel"
+ icon="i-lucide-at-sign"
+ class="w-full"
+ />
+ <p class="text-xs text-muted">The channel's @handle for display</p>
+ </div>
+
+ <div class="flex flex-col gap-1.5">
+ <label class="text-sm font-medium text-highlighted">Max Videos</label>
+ <UInput
+ v-model.number="form.maxVideos"
+ type="number"
+ :min="1"
+ :max="500"
+ icon="i-lucide-video"
+ class="w-full"
+ />
+ <p class="text-xs text-muted">Maximum number of videos to sync (default: 50)</p>
+ </div>
+ </div>
+ </div>
+ </template>
+ </div>
+ </template>
+
+ <template #footer>
+ <UButton
+ color="neutral"
+ variant="ghost"
+ size="sm"
+ label="Cancel"
+ @click="emit('close')"
+ />
+ <UButton
+ :label="isEditing ? 'Save Changes' : 'Create Source'"
+ size="sm"
+ :loading="isSubmitting"
+ @click="save"
+ />
+ </template>
+ </UModal>
+</template>
diff --git a/apps/chat/app/components/UserMenu.vue b/apps/chat/app/components/UserMenu.vue
index e3f14d7..2ad68a5 100644
--- a/apps/chat/app/components/UserMenu.vue
+++ b/apps/chat/app/components/UserMenu.vue
@@ -206,6 +206,11 @@ const items = computed<DropdownMenuItem[][]>(() => ([
label: 'Admin',
icon: 'i-lucide-settings',
children: [
+ {
+ label: 'Sources',
+ icon: 'i-lucide-book-open',
+ to: '/admin/sources',
+ },
{
label: 'Sync all',
icon: 'i-lucide-refresh-cw',
diff --git a/apps/chat/app/middleware/auth.ts b/apps/chat/app/middleware/auth.ts
new file mode 100644
index 0000000..16741a2
--- /dev/null
+++ b/apps/chat/app/middleware/auth.ts
@@ -0,0 +1,7 @@
+export default defineNuxtRouteMiddleware(() => {
+ const { loggedIn } = useUserSession()
+
+ if (!loggedIn.value) {
+ return navigateTo('/')
+ }
+})
diff --git a/apps/chat/app/pages/admin/sources.vue b/apps/chat/app/pages/admin/sources.vue
new file mode 100644
index 0000000..6c5668c
--- /dev/null
+++ b/apps/chat/app/pages/admin/sources.vue
@@ -0,0 +1,225 @@
+<script setup lang="ts">
+import { LazyModalConfirm } from '#components'
+
+interface SerializedSource {
+ id: string
+ type: 'github' | 'youtube'
+ label: string
+ repo: string | null
+ branch: string | null
+ contentPath: string | null
+ outputPath: string | null
+ readmeOnly: boolean | null
+ channelId: string | null
+ handle: string | null
+ maxVideos: number | null
+ createdAt: string
+ updatedAt: string
+}
+
+definePageMeta({
+ middleware: 'auth',
+})
+
+const toast = useToast()
+const overlay = useOverlay()
+
+const { data: sources, refresh } = await useFetch('/api/sources')
+
+const showAddModal = ref(false)
+const editingSource = ref<SerializedSource | null>(null)
+const isSyncingAll = ref(false)
+
+const deleteModal = overlay.create(LazyModalConfirm, {
+ destroyOnClose: true,
+})
+
+async function deleteSource(source: SerializedSource) {
+ const confirmed = await deleteModal.open({
+ title: 'Delete Source',
+ description: `Are you sure you want to delete "${source.label}"?`,
+ })
+
+ if (!confirmed) return
+
+ try {
+ await $fetch(`/api/sources/${source.id}`, { method: 'DELETE' })
+ toast.add({
+ title: 'Source deleted',
+ icon: 'i-lucide-check',
+ })
+ refresh()
+ } catch (error: unknown) {
+ toast.add({
+ title: 'Error',
+ description: error instanceof Error ? error.message : 'Failed to delete source',
+ color: 'error',
+ icon: 'i-lucide-alert-circle',
+ })
+ }
+}
+
+async function triggerSync(sourceId?: string) {
+ try {
+ if (!sourceId) {
+ isSyncingAll.value = true
+ }
+ await $fetch('/api/admin/sync', {
+ method: 'POST',
+ body: sourceId ? { sourceId } : {},
+ })
+ toast.add({
+ title: sourceId ? 'Sync started' : 'Full sync started',
+ description: 'The sync workflow has been triggered.',
+ icon: 'i-lucide-check',
+ })
+ } catch (error: unknown) {
+ toast.add({
+ title: 'Error',
+ description: error instanceof Error ? error.message : 'Failed to start sync',
+ color: 'error',
+ icon: 'i-lucide-alert-circle',
+ })
+ } finally {
+ isSyncingAll.value = false
+ }
+}
+
+function handleSaved() {
+ refresh()
+ showAddModal.value = false
+ editingSource.value = null
+}
+</script>
+
+<template>
+ <UDashboardPanel id="admin-sources">
+ <template #header>
+ <DashboardNavbar />
+ </template>
+
+ <template #body>
+ <UContainer class="py-10 max-w-3xl">
+ <div class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4 mb-10">
+ <div>
+ <h1 class="text-2xl font-semibold text-highlighted tracking-tight">Sources</h1>
+ <p class="text-muted text-sm mt-1">Manage your content sources for documentation sync</p>
+ </div>
+ <div class="flex gap-2">
+ <UButton
+ icon="i-lucide-refresh-cw"
+ color="neutral"
+ variant="outline"
+ size="sm"
+ :loading="isSyncingAll"
+ :disabled="!sources?.github?.length && !sources?.youtube?.length"
+ @click="triggerSync()"
+ >
+ Sync All
+ </UButton>
+ <UButton
+ icon="i-lucide-plus"
+ size="sm"
+ @click="showAddModal = true"
+ >
+ Add Source
+ </UButton>
+ </div>
+ </div>
+
+ <div
+ v-if="!sources?.github?.length && !sources?.youtube?.length"
+ class="flex flex-col items-center justify-center py-16 px-4"
+ >
+ <div class="flex items-center justify-center size-12 rounded-xl bg-neutral-100 dark:bg-neutral-800/80 mb-4">
+ <UIcon name="i-lucide-database" class="size-6 text-muted" />
+ </div>
+ <h3 class="text-base font-medium text-highlighted mb-1">No sources configured</h3>
+ <p class="text-sm text-muted text-center max-w-sm mb-6">
+ Add your first source to start syncing documentation from GitHub repositories or YouTube channels.
+ </p>
+ <UButton
+ icon="i-lucide-plus"
+ size="sm"
+ @click="showAddModal = true"
+ >
+ Add Source
+ </UButton>
+ </div>
+
+ <template v-else>
+ <section class="mb-8">
+ <div class="flex items-center justify-between mb-3">
+ <div class="flex items-center gap-2">
+ <UIcon name="i-simple-icons-github" class="size-4 text-muted" />
+ <h2 class="text-sm font-medium text-highlighted">GitHub Repositories</h2>
+ <span class="text-xs text-muted bg-neutral-100 dark:bg-neutral-800 px-1.5 py-0.5 rounded">
+ {{ sources?.github?.length || 0 }}
+ </span>
+ </div>
+ </div>
+
+ <div v-if="sources?.github?.length" class="space-y-2">
+ <SourceCard
+ v-for="source in sources.github"
+ :key="source.id"
+ :source
+ @edit="editingSource = source"
+ @delete="deleteSource(source)"
+ @sync="triggerSync(source.id)"
+ />
+ </div>
+ <button
+ v-else
+ class="w-full border border-dashed border-default hover:border-muted rounded-xl p-8 text-center transition-colors group"
+ @click="showAddModal = true"
+ >
+ <p class="text-sm text-muted group-hover:text-highlighted transition-colors">
+ Add a GitHub repository
+ </p>
+ </button>
+ </section>
+
+ <section>
+ <div class="flex items-center justify-between mb-3">
+ <div class="flex items-center gap-2">
+ <UIcon name="i-simple-icons-youtube" class="size-4 text-red-500" />
+ <h2 class="text-sm font-medium text-highlighted">YouTube Channels</h2>
+ <span class="text-xs text-muted bg-neutral-100 dark:bg-neutral-800 px-1.5 py-0.5 rounded">
+ {{ sources?.youtube?.length || 0 }}
+ </span>
+ </div>
+ </div>
+
+ <div v-if="sources?.youtube?.length" class="space-y-2">
+ <SourceCard
+ v-for="source in sources.youtube"
+ :key="source.id"
+ :source
+ @edit="editingSource = source"
+ @delete="deleteSource(source)"
+ @sync="triggerSync(source.id)"
+ />
+ </div>
+ <button
+ v-else
+ class="w-full border border-dashed border-default hover:border-muted rounded-xl p-8 text-center transition-colors group"
+ @click="showAddModal = true"
+ >
+ <p class="text-sm text-muted group-hover:text-highlighted transition-colors">
+ Add a YouTube channel
+ </p>
+ </button>
+ </section>
+ </template>
+ </UContainer>
+
+ <SourceModal
+ v-if="showAddModal || editingSource"
+ :source="editingSource"
+ @close="showAddModal = false; editingSource = null"
+ @saved="handleSaved"
+ />
+ </template>
+ </UDashboardPanel>
+</template>
diff --git a/apps/chat/server/api/admin/sync.post.ts b/apps/chat/server/api/admin/sync.post.ts
index 8df2637..e419d5d 100644
--- a/apps/chat/server/api/admin/sync.post.ts
+++ b/apps/chat/server/api/admin/sync.post.ts
@@ -1,16 +1,32 @@
import { createSavoir } from '@savoir/sdk'
+import { db, schema } from '@nuxthub/db'
+import { z } from 'zod'
+
+const bodySchema = z.object({
+ sourceId: z.string().optional(),
+}).optional()
/**
* POST /api/admin/sync
- * Trigger documentation sync workflow
+ * Trigger documentation sync workflow with sources from DB
*/
-export default defineEventHandler(async () => {
+export default defineEventHandler(async (event) => {
+ const body = await readValidatedBody(event, data => bodySchema.parse(data))
const { savoir: savoirConfig } = useRuntimeConfig()
+ // Get sources from DB
+ const allSources = await db.query.sources.findMany()
+
+ // Filter to specific source if requested
+ const sourcesToSync = body?.sourceId
+ ? allSources.filter(s => s.id === body.sourceId)
+ : allSources
+
const savoir = createSavoir({
apiUrl: savoirConfig.apiUrl,
apiKey: savoirConfig.apiKey || undefined,
})
- return await savoir.client.sync()
+ // Pass sources to the API
+ return await savoir.client.sync({ sources: sourcesToSync })
})
diff --git a/apps/chat/server/api/chats/[id].post.ts b/apps/chat/server/api/chats/[id].post.ts
index b14b5a4..aa88d4d 100644
--- a/apps/chat/server/api/chats/[id].post.ts
+++ b/apps/chat/server/api/chats/[id].post.ts
@@ -108,7 +108,6 @@ export default defineEventHandler(async (event) => {
apiKey: savoirConfig.apiKey || undefined,
})
- // Metrics tracking
let stepCount = 0
let toolCallCount = 0
let totalInputTokens = 0
diff --git a/apps/chat/server/api/sources/[id].delete.ts b/apps/chat/server/api/sources/[id].delete.ts
new file mode 100644
index 0000000..75cfe72
--- /dev/null
+++ b/apps/chat/server/api/sources/[id].delete.ts
@@ -0,0 +1,23 @@
+import { db, schema } from '@nuxthub/db'
+import { eq } from 'drizzle-orm'
+
+/**
+ * DELETE /api/sources/:id
+ * Delete a source
+ */
+export default defineEventHandler(async (event) => {
+ const id = getRouterParam(event, 'id')
+ if (!id) {
+ throw createError({ statusCode: 400, message: 'Missing source id' })
+ }
+
+ const [deleted] = await db.delete(schema.sources)
+ .where(eq(schema.sources.id, id))
+ .returning()
+
+ if (!deleted) {
+ throw createError({ statusCode: 404, message: 'Source not found' })
+ }
+
+ return { success: true }
+})
diff --git a/apps/chat/server/api/sources/[id].put.ts b/apps/chat/server/api/sources/[id].put.ts
new file mode 100644
index 0000000..254b6b7
--- /dev/null
+++ b/apps/chat/server/api/sources/[id].put.ts
@@ -0,0 +1,44 @@
+import { db, schema } from '@nuxthub/db'
+import { eq } from 'drizzle-orm'
+import { z } from 'zod'
+
+const bodySchema = z.object({
+ label: z.string().min(1).optional(),
+ // GitHub fields
+ repo: z.string().optional(),
+ branch: z.string().optional(),
+ contentPath: z.string().optional(),
+ outputPath: z.string().optional(),
+ readmeOnly: z.boolean().optional(),
+ // YouTube fields
+ channelId: z.string().optional(),
+ handle: z.string().optional(),
+ maxVideos: z.number().optional(),
+})
+
+/**
+ * PUT /api/sources/:id
+ * Update an existing source
+ */
+export default defineEventHandler(async (event) => {
+ const id = getRouterParam(event, 'id')
+ if (!id) {
+ throw createError({ statusCode: 400, message: 'Missing source id' })
+ }
+
+ const body = await readValidatedBody(event, bodySchema.parse)
+
+ const [source] = await db.update(schema.sources)
+ .set({
+ ...body,
+ updatedAt: new Date(),
+ })
+ .where(eq(schema.sources.id, id))
+ .returning()
+
+ if (!source) {
+ throw createError({ statusCode: 404, message: 'Source not found' })
+ }
+
+ return source
+})
diff --git a/apps/chat/server/api/sources/index.get.ts b/apps/chat/server/api/sources/index.get.ts
new file mode 100644
index 0000000..0fe7198
--- /dev/null
+++ b/apps/chat/server/api/sources/index.get.ts
@@ -0,0 +1,17 @@
+import { db, schema } from '@nuxthub/db'
+import { asc } from 'drizzle-orm'
+
+/**
+ * GET /api/sources
+ * List all sources grouped by type
+ */
+export default defineEventHandler(async () => {
+ const allSources = await db.query.sources.findMany({
+ orderBy: () => asc(schema.sources.label),
+ })
+
+ return {
+ github: allSources.filter(s => s.type === 'github'),
+ youtube: allSources.filter(s => s.type === 'youtube'),
+ }
+})
diff --git a/apps/chat/server/api/sources/index.post.ts b/apps/chat/server/api/sources/index.post.ts
new file mode 100644
index 0000000..b7152e4
--- /dev/null
+++ b/apps/chat/server/api/sources/index.post.ts
@@ -0,0 +1,45 @@
+import { db, schema } from '@nuxthub/db'
+import { z } from 'zod'
+
+const bodySchema = z.object({
+ type: z.enum(['github', 'youtube']),
+ label: z.string().min(1),
+ // GitHub fields
+ repo: z.string().optional(),
+ branch: z.string().optional().default('main'),
+ contentPath: z.string().optional(),
+ outputPath: z.string().optional(),
+ readmeOnly: z.boolean().optional().default(false),
+ // YouTube fields
+ channelId: z.string().optional(),
+ handle: z.string().optional(),
+ maxVideos: z.number().optional().default(50),
+})
+
+/**
+ * POST /api/sources
+ * Create a new source
+ */
+export default defineEventHandler(async (event) => {
+ const body = await readValidatedBody(event, bodySchema.parse)
+
+ const [source] = await db.insert(schema.sources)
+ .values({
+ id: crypto.randomUUID(),
+ type: body.type,
+ label: body.label,
+ repo: body.repo,
+ branch: body.branch,
+ contentPath: body.contentPath,
+ outputPath: body.outputPath,
+ readmeOnly: body.readmeOnly,
+ channelId: body.channelId,
+ handle: body.handle,
+ maxVideos: body.maxVideos,
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ })
+ .returning()
+
+ return source
+})
diff --git a/apps/chat/server/db/migrations/sqlite/0002_sources.sql b/apps/chat/server/db/migrations/sqlite/0002_sources.sql
new file mode 100644
index 0000000..a257b40
--- /dev/null
+++ b/apps/chat/server/db/migrations/sqlite/0002_sources.sql
@@ -0,0 +1,17 @@
+CREATE TABLE `sources` (
+ `id` text PRIMARY KEY NOT NULL,
+ `type` text NOT NULL,
+ `label` text NOT NULL,
+ `repo` text,
+ `branch` text,
+ `content_path` text,
+ `output_path` text,
+ `readme_only` integer DEFAULT false,
+ `channel_id` text,
+ `handle` text,
+ `max_videos` integer DEFAULT 50,
+ `created_at` integer NOT NULL,
+ `updated_at` integer NOT NULL
+);
+--> statement-breakpoint
+CREATE INDEX `sources_type_idx` ON `sources` (`type`);
diff --git a/apps/chat/server/db/migrations/sqlite/meta/0002_snapshot.json b/apps/chat/server/db/migrations/sqlite/meta/0002_snapshot.json
new file mode 100644
index 0000000..4a54bd2
--- /dev/null
+++ b/apps/chat/server/db/migrations/sqlite/meta/0002_snapshot.json
@@ -0,0 +1,339 @@
+{
+ "version": "6",
+ "dialect": "sqlite",
+ "id": "a1b2c3d4-5e6f-7890-abcd-ef1234567890",
+ "prevId": "8f9766e0-1f5e-480e-96de-d17fbed81edf",
+ "tables": {
+ "chats": {
+ "name": "chats",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "title": {
+ "name": "title",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "is_public": {
+ "name": "is_public",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "share_token": {
+ "name": "share_token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "chats_user_id_idx": {
+ "name": "chats_user_id_idx",
+ "columns": [
+ "user_id"
+ ],
+ "isUnique": false
+ },
+ "chats_share_token_idx": {
+ "name": "chats_share_token_idx",
+ "columns": [
+ "share_token"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "messages": {
+ "name": "messages",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "chat_id": {
+ "name": "chat_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "role": {
+ "name": "role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "parts": {
+ "name": "parts",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "messages_chat_id_idx": {
+ "name": "messages_chat_id_idx",
+ "columns": [
+ "chat_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "messages_chat_id_chats_id_fk": {
+ "name": "messages_chat_id_chats_id_fk",
+ "tableFrom": "messages",
+ "tableTo": "chats",
+ "columnsFrom": [
+ "chat_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "users": {
+ "name": "users",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "email": {
+ "name": "email",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "avatar": {
+ "name": "avatar",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "username": {
+ "name": "username",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "provider": {
+ "name": "provider",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "provider_id": {
+ "name": "provider_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "users_provider_id_idx": {
+ "name": "users_provider_id_idx",
+ "columns": [
+ "provider",
+ "provider_id"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "sources": {
+ "name": "sources",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "type": {
+ "name": "type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "label": {
+ "name": "label",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "repo": {
+ "name": "repo",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "branch": {
+ "name": "branch",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "content_path": {
+ "name": "content_path",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "output_path": {
+ "name": "output_path",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "readme_only": {
+ "name": "readme_only",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": false
+ },
+ "channel_id": {
+ "name": "channel_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "handle": {
+ "name": "handle",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "max_videos": {
+ "name": "max_videos",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": 50
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "sources_type_idx": {
+ "name": "sources_type_idx",
+ "columns": [
+ "type"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ }
+ },
+ "views": {},
+ "enums": {},
+ "_meta": {
+ "schemas": {},
+ "tables": {},
+ "columns": {}
+ },
+ "internal": {
+ "indexes": {}
+ }
+}
diff --git a/apps/chat/server/db/migrations/sqlite/meta/_journal.json b/apps/chat/server/db/migrations/sqlite/meta/_journal.json
index 9160a6d..043f1e5 100644
--- a/apps/chat/server/db/migrations/sqlite/meta/_journal.json
+++ b/apps/chat/server/db/migrations/sqlite/meta/_journal.json
@@ -15,6 +15,13 @@
"when": 1768328336583,
"tag": "0001_icy_catseye",
"breakpoints": true
+ },
+ {
+ "idx": 2,
+ "version": "6",
+ "when": 1737590400000,
+ "tag": "0002_sources",
+ "breakpoints": true
}
]
}
\ No newline at end of file
diff --git a/apps/chat/server/db/schema.ts b/apps/chat/server/db/schema.ts
index a8ff653..01ca610 100644
--- a/apps/chat/server/db/schema.ts
+++ b/apps/chat/server/db/schema.ts
@@ -54,3 +54,27 @@ export const messagesRelations = relations(messages, ({ one }) => ({
references: [chats.id]
})
}))
+
+export const sources = sqliteTable('sources', {
+ id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
+ type: text('type', { enum: ['github', 'youtube'] }).notNull(),
+
+ // Common fields
+ label: text('label').notNull(),
+
+ // GitHub fields
+ repo: text('repo'),
+ branch: text('branch'),
+ contentPath: text('content_path'),
+ outputPath: text('output_path'),
+ readmeOnly: integer('readme_only', { mode: 'boolean' }).default(false),
+
+ // YouTube fields
+ channelId: text('channel_id'),
+ handle: text('handle'),
+ maxVideos: integer('max_videos').default(50),
+
+ // Metadata
+ ...timestamps,
+ updatedAt: integer('updated_at', { mode: 'timestamp' }).notNull().$defaultFn(() => new Date()),
+}, table => [index('sources_type_idx').on(table.type)])
diff --git a/apps/chat/shared/types/db.d.ts b/apps/chat/shared/types/db.d.ts
index a4296fc..c707356 100644
--- a/apps/chat/shared/types/db.d.ts
+++ b/apps/chat/shared/types/db.d.ts
@@ -1,4 +1,5 @@
-import type { chats, messages } from '@nuxthub/db/schema'
+import type { chats, messages, sources } from '@nuxthub/db/schema'
export type Chat = typeof chats.$inferSelect
export type Message = typeof messages.$inferSelect
+export type Source = typeof sources.$inferSelect
diff --git a/packages/config/src/index.ts b/packages/config/src/index.ts
index 43fc850..08d04e3 100644
--- a/packages/config/src/index.ts
+++ b/packages/config/src/index.ts
@@ -1,7 +1,5 @@
-// Define helper
export { defineConfig } from './define'
-// Loader
export {
loadSavoirConfig,
setConfigCwd,
@@ -14,24 +12,21 @@ export {
} from './loader'
export type { LoadOptions } from './loader'
-// Types
export type {
- // Input types (for config files)
SavoirConfigInput,
GitHubSourceInput,
YouTubeSourceInput,
CustomSourceInput,
- // Normalized types (for runtime)
Source,
GitHubSource,
YouTubeSource,
CustomSource,
ContentFile,
LoadedConfig,
- // Sync types
SyncResult,
SyncConfig,
SyncOptions,
PushResult,
SnapshotConfig,
+ DBSource,
} from './types'
diff --git a/packages/config/src/types.ts b/packages/config/src/types.ts
index f0a65fe..d9107fa 100644
--- a/packages/config/src/types.ts
+++ b/packages/config/src/types.ts
@@ -110,10 +110,31 @@ export interface SyncConfig {
snapshotBranch: string
}
+/**
+ * Source passed directly from the chat app DB
+ */
+export interface DBSource {
+ id: string
+ type: 'github' | 'youtube'
+ label: string
+ // GitHub fields
+ repo?: string | null
+ branch?: string | null
+ contentPath?: string | null
+ outputPath?: string | null
+ readmeOnly?: boolean | null
+ // YouTube fields
+ channelId?: string | null
+ handle?: string | null
+ maxVideos?: number | null
+}
+
export interface SyncOptions {
reset?: boolean
push?: boolean
sourceFilter?: string
+ /** Sources passed directly from DB (takes precedence over config file) */
+ sources?: DBSource[]
}
export interface PushResult {
diff --git a/packages/sdk/src/client.ts b/packages/sdk/src/client.ts
index a203a99..843df0d 100644
--- a/packages/sdk/src/client.ts
+++ b/packages/sdk/src/client.ts
@@ -176,6 +176,8 @@ export class SavoirClient {
return await this.post<SyncResponse>('/api/sync', {
reset: options?.reset ?? false,
push: options?.push ?? true,
+ sources: options?.sources,
+ sourceFilter: options?.sourceFilter,
})
}
diff --git a/packages/sdk/src/types.ts b/packages/sdk/src/types.ts
index 3878b97..c1e2bba 100644
--- a/packages/sdk/src/types.ts
+++ b/packages/sdk/src/types.ts
@@ -63,6 +63,25 @@ export interface ApiErrorResponse {
error?: string
}
+/**
+ * Source passed for sync
+ */
+export interface SyncSource {
+ id: string
+ type: 'github' | 'youtube'
+ label: string
+ // GitHub fields
+ repo?: string | null
+ branch?: string | null
+ contentPath?: string | null
+ outputPath?: string | null
+ readmeOnly?: boolean | null
+ // YouTube fields
+ channelId?: string | null
+ handle?: string | null
+ maxVideos?: number | null
+}
+
/**
* Options for the sync operation
*/
@@ -71,6 +90,10 @@ export interface SyncOptions {
reset?: boolean
/** Push to snapshot repo after sync */
push?: boolean
+ /** Sources to sync (passed from chat app DB) */
+ sources?: SyncSource[]
+ /** Filter to sync only specific source */
+ sourceFilter?: string
}
/**