Skip to content

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

update arch

Hugo Richardb4618206c9f2
diff --git a/apps/chat/server/api/chats/[id].post.ts b/apps/chat/server/api/chats/[id].post.ts
index 68cd6d9..2a56400 100644
--- a/apps/chat/server/api/chats/[id].post.ts
+++ b/apps/chat/server/api/chats/[id].post.ts
@@ -4,7 +4,7 @@ import { db, schema } from '@nuxthub/db'
import { and, eq } from 'drizzle-orm'
import { createSavoir } from '@savoir/sdk'
import { log, useLogger } from 'evlog'
-import { generateTitle } from '../../utils/generate-title'
+import { generateTitle } from '../../utils/chat/generate-title'
const SYSTEM_PROMPT = `You are an AI assistant specialized in the Nuxt/Nitro ecosystem.
diff --git a/apps/chat/server/api/sandbox/read.post.ts b/apps/chat/server/api/sandbox/read.post.ts
index 2401a70..1416970 100644
--- a/apps/chat/server/api/sandbox/read.post.ts
+++ b/apps/chat/server/api/sandbox/read.post.ts
@@ -1,6 +1,6 @@
import { z } from 'zod'
import { useLogger } from 'evlog'
-import { getOrCreateSandbox, read } from '../../lib/sandbox'
+import { getOrCreateSandbox, read } from '../../utils/sandbox/manager'
const bodySchema = z.object({
paths: z.array(z.string().min(1)).min(1).max(50),
diff --git a/apps/chat/server/api/sandbox/search-and-read.post.ts b/apps/chat/server/api/sandbox/search-and-read.post.ts
index 161b7f1..665da6c 100644
--- a/apps/chat/server/api/sandbox/search-and-read.post.ts
+++ b/apps/chat/server/api/sandbox/search-and-read.post.ts
@@ -1,6 +1,6 @@
import { z } from 'zod'
import { useLogger } from 'evlog'
-import { getOrCreateSandbox, searchAndRead } from '../../lib/sandbox'
+import { getOrCreateSandbox, searchAndRead } from '../../utils/sandbox/manager'
const bodySchema = z.object({
query: z.string({ error: 'query is required - provide a search term like "useAsyncData" or "middleware"' }).min(1, 'query cannot be empty').max(500),
diff --git a/apps/chat/server/lib/sandbox/index.ts b/apps/chat/server/lib/sandbox/index.ts
deleted file mode 100644
index 24a2851..0000000
--- a/apps/chat/server/lib/sandbox/index.ts
+++ /dev/null
@@ -1,48 +0,0 @@
-export type {
- ActiveSandbox,
- FileContent,
- SandboxManagerConfig,
- SandboxSession,
- SearchAndReadResult,
- SearchResult,
- SnapshotMetadata,
-} from './types'
-
-export {
- deleteSession,
- generateSessionId,
- getSession,
- setSession,
- touchSession,
-} from './session'
-
-export {
- getCurrentSnapshot,
- getSnapshotIdOrThrow,
- hasSnapshot,
- setCurrentSnapshot,
-} from './snapshot'
-
-export {
- createSnapshotFromRepo,
- getOrCreateSandbox,
- read,
- search,
- searchAndRead,
-} from './manager'
-
-export { createGitSource, createSandbox, generateAuthRepoUrl } from './context'
-
-export type { GitConfig, GitPushOptions, GitPushResult } from './git'
-export {
- addFiles,
- checkoutBranch,
- commit,
- configureGit,
- generateCommitMessage,
- hasChanges,
- push,
- pushChanges,
-} from './git'
-
-export { syncGitHubSource, syncSources } from './source-sync'
diff --git a/apps/chat/server/utils/generate-title.ts b/apps/chat/server/utils/chat/generate-title.ts
similarity index 100%
rename from apps/chat/server/utils/generate-title.ts
rename to apps/chat/server/utils/chat/generate-title.ts
diff --git a/apps/chat/server/lib/sandbox/context.ts b/apps/chat/server/utils/sandbox/context.ts
similarity index 100%
rename from apps/chat/server/lib/sandbox/context.ts
rename to apps/chat/server/utils/sandbox/context.ts
diff --git a/apps/chat/server/lib/sandbox/git.ts b/apps/chat/server/utils/sandbox/git.ts
similarity index 100%
rename from apps/chat/server/lib/sandbox/git.ts
rename to apps/chat/server/utils/sandbox/git.ts
diff --git a/apps/chat/server/lib/sandbox/manager.ts b/apps/chat/server/utils/sandbox/manager.ts
similarity index 95%
rename from apps/chat/server/lib/sandbox/manager.ts
rename to apps/chat/server/utils/sandbox/manager.ts
index 0f498ad..7720cdd 100644
--- a/apps/chat/server/lib/sandbox/manager.ts
+++ b/apps/chat/server/utils/sandbox/manager.ts
@@ -2,7 +2,7 @@ import { Sandbox } from '@vercel/sandbox'
import { createError, log } from 'evlog'
import type { ActiveSandbox, FileContent, SearchAndReadResult, SearchResult, SandboxManagerConfig, SnapshotMetadata } from './types'
import { getCurrentSnapshot, setCurrentSnapshot } from './snapshot'
-import { deleteSession, generateSessionId, getSession, setSession, touchSession } from './session'
+import { deleteSandboxSession, generateSessionId, getSandboxSession, setSandboxSession, touchSandboxSession } from './session'
const DEFAULT_SESSION_TTL_MS = 30 * 60 * 1000 // 30 minutes
const SANDBOX_TIMEOUT_MS = 5 * 60 * 1000 // 5 minutes
@@ -137,17 +137,17 @@ export async function getOrCreateSandbox(sessionId?: string): Promise<ActiveSand
// If session ID provided, try to get existing sandbox
if (sessionId) {
- const session = await getSession(sessionId)
+ const session = await getSandboxSession(sessionId)
if (session) {
const sandbox = await getSandboxById(session.sandboxId)
if (sandbox) {
const reuseMs = Date.now() - startTime
log.info('sandbox', `Reusing sandbox ${sandbox.sandboxId} for session ${sessionId} (${reuseMs}ms)`)
- await touchSession(sessionId, config.sessionTtlMs)
+ await touchSandboxSession(sessionId, config.sessionTtlMs)
return { sandbox, session, sessionId }
}
// Sandbox no longer available, clean up session
- await deleteSession(sessionId)
+ await deleteSandboxSession(sessionId)
}
}
@@ -155,7 +155,7 @@ export async function getOrCreateSandbox(sessionId?: string): Promise<ActiveSand
const sandbox = await createSandboxFromSnapshot(snapshotId)
const newSessionId = sessionId || generateSessionId()
- const session = await setSession(
+ const session = await setSandboxSession(
newSessionId,
{
sandboxId: sandbox.sandboxId,
diff --git a/apps/chat/server/lib/sandbox/session.ts b/apps/chat/server/utils/sandbox/session.ts
similarity index 83%
rename from apps/chat/server/lib/sandbox/session.ts
rename to apps/chat/server/utils/sandbox/session.ts
index 0bc7560..e01472a 100644
--- a/apps/chat/server/lib/sandbox/session.ts
+++ b/apps/chat/server/utils/sandbox/session.ts
@@ -5,7 +5,7 @@ import { KV_KEYS } from './types'
const DEFAULT_SESSION_TTL_MS = 30 * 60 * 1000 // 30 minutes
/** Returns session if exists and not expired, null otherwise */
-export async function getSession(sessionId: string): Promise<SandboxSession | null> {
+export async function getSandboxSession(sessionId: string): Promise<SandboxSession | null> {
const session = await kv.get<SandboxSession>(KV_KEYS.session(sessionId))
if (!session) {
@@ -21,7 +21,7 @@ export async function getSession(sessionId: string): Promise<SandboxSession | nu
}
/** Creates or updates session with TTL, returns full session with timestamps */
-export async function setSession(
+export async function setSandboxSession(
sessionId: string,
session: Omit<SandboxSession, 'lastAccessedAt' | 'expiresAt'>,
ttlMs: number = DEFAULT_SESSION_TTL_MS,
@@ -39,11 +39,11 @@ export async function setSession(
}
/** Refreshes session expiration time, returns updated session or null if not found */
-export async function touchSession(
+export async function touchSandboxSession(
sessionId: string,
ttlMs: number = DEFAULT_SESSION_TTL_MS,
): Promise<SandboxSession | null> {
- const session = await getSession(sessionId)
+ const session = await getSandboxSession(sessionId)
if (!session) {
return null
}
@@ -57,7 +57,7 @@ export async function touchSession(
}
/** Deletes session from storage */
-export async function deleteSession(sessionId: string): Promise<void> {
+export async function deleteSandboxSession(sessionId: string): Promise<void> {
await kv.del(KV_KEYS.session(sessionId))
}
diff --git a/apps/chat/server/lib/sandbox/snapshot.ts b/apps/chat/server/utils/sandbox/snapshot.ts
similarity index 100%
rename from apps/chat/server/lib/sandbox/snapshot.ts
rename to apps/chat/server/utils/sandbox/snapshot.ts
diff --git a/apps/chat/server/lib/sandbox/source-sync.ts b/apps/chat/server/utils/sandbox/source-sync.ts
similarity index 93%
rename from apps/chat/server/lib/sandbox/source-sync.ts
rename to apps/chat/server/utils/sandbox/source-sync.ts
index 178b732..e4ba675 100644
--- a/apps/chat/server/lib/sandbox/source-sync.ts
+++ b/apps/chat/server/utils/sandbox/source-sync.ts
@@ -20,14 +20,14 @@ export async function syncGitHubSource(
if (source.readmeOnly) {
const fileCount = await syncReadmeOnly(sandbox, source, targetDir)
- return { sourceId: source.id, success: true, fileCount }
+ return { sourceId: source.id, label: source.label, success: true, fileCount }
}
const fileCount = await syncFullRepository(sandbox, source, targetDir)
- return { sourceId: source.id, success: true, fileCount }
+ return { sourceId: source.id, label: source.label, success: true, fileCount }
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error)
- return { sourceId: source.id, success: false, fileCount: 0, error: errorMessage }
+ return { sourceId: source.id, label: source.label, success: false, fileCount: 0, error: errorMessage }
}
}
diff --git a/apps/chat/server/lib/sandbox/types.ts b/apps/chat/server/utils/sandbox/types.ts
similarity index 100%
rename from apps/chat/server/lib/sandbox/types.ts
rename to apps/chat/server/utils/sandbox/types.ts
diff --git a/apps/chat/server/workflows/create-snapshot/steps/create-and-snapshot.ts b/apps/chat/server/workflows/create-snapshot/steps/create-and-snapshot.ts
index c794f93..456baed 100644
--- a/apps/chat/server/workflows/create-snapshot/steps/create-and-snapshot.ts
+++ b/apps/chat/server/workflows/create-snapshot/steps/create-and-snapshot.ts
@@ -2,7 +2,7 @@
import { log } from 'evlog'
import type { SnapshotConfig } from '../types'
-import { createSandbox } from '../../../lib/sandbox/context'
+import { createSandbox } from '../../../utils/sandbox/context'
export interface SnapshotResult {
snapshotId: string
diff --git a/apps/chat/server/workflows/sync-docs/steps/sync-all.ts b/apps/chat/server/workflows/sync-docs/steps/sync-all.ts
index 52d64db..dc66234 100644
--- a/apps/chat/server/workflows/sync-docs/steps/sync-all.ts
+++ b/apps/chat/server/workflows/sync-docs/steps/sync-all.ts
@@ -2,9 +2,9 @@
import { log } from 'evlog'
import type { GitHubSource, SyncConfig, SyncSourceResult } from '../types'
-import { createSandbox, generateAuthRepoUrl } from '../../../lib/sandbox/context'
-import { syncSources } from '../../../lib/sandbox/source-sync'
-import { pushChanges, generateCommitMessage } from '../../../lib/sandbox/git'
+import { createSandbox, generateAuthRepoUrl } from '../../../utils/sandbox/context'
+import { syncSources } from '../../../utils/sandbox/source-sync'
+import { pushChanges, generateCommitMessage } from '../../../utils/sandbox/git'
export interface SyncAllResult {
snapshotId: string
@@ -26,9 +26,9 @@ export async function stepSyncAll(
for (const result of results) {
if (result.success) {
- log.info('sync', `${result.sourceId}: synced ${result.fileCount} files`)
+ log.info('sync', `${result.label}: synced ${result.fileCount} files`)
} else {
- log.error('sync', `${result.sourceId}: failed - ${result.error}`)
+ log.error('sync', `${result.label}: failed - ${result.error}`)
}
}
diff --git a/apps/chat/server/workflows/sync-docs/types.ts b/apps/chat/server/workflows/sync-docs/types.ts
index b7d8ec5..3d10eeb 100644
--- a/apps/chat/server/workflows/sync-docs/types.ts
+++ b/apps/chat/server/workflows/sync-docs/types.ts
@@ -22,6 +22,7 @@ export interface GitHubSource {
export interface SyncSourceResult {
sourceId: string
+ label: string
success: boolean
fileCount: number
error?: string