Open source file-system and knowledge based agent template. Build AI agents that stay up to date with your knowledge base
overall improvements
Hugo Richard39598c77ac5e
diff --git a/apps/chat/.nuxtrc b/apps/chat/.nuxtrcindex f04c5e5..18ce1ca 100644--- a/apps/chat/.nuxtrc+++ b/apps/chat/.nuxtrc@@ -1,2 +1,2 @@setups.@onmax/nuxt-better-auth="0.0.2-alpha.21"-setups.@evlog/nuxthub="1.0.0"\ No newline at end of file+setups.@evlog/nuxthub="1.1.0"\ No newline at end of filediff --git a/apps/chat/app/components/ToolCallItem.vue b/apps/chat/app/components/ToolCallItem.vueindex 41b77cd..dcb0d8d 100644--- a/apps/chat/app/components/ToolCallItem.vue+++ b/apps/chat/app/components/ToolCallItem.vue@@ -22,9 +22,9 @@ const fullLabel = computed(() => {|| (args?.command ? [args.command as string] : undefined)|| (firstResultCmd?.title ? [firstResultCmd.title] : firstResultCmd?.command ? [firstResultCmd.command] : [])- if (toolName === 'search_web') {+ if (toolName === 'web_search') {const query = args?.query || '...'- return state === 'loading' ? `Web search: "${query}"` : `Web search: "${query}"`+ return `Web search: "${query}"`}if (toolName === 'search_and_read') {diff --git a/apps/chat/app/pages/admin/new.vue b/apps/chat/app/pages/admin/new.vueindex 3d03ce6..494581b 100644--- a/apps/chat/app/pages/admin/new.vue+++ b/apps/chat/app/pages/admin/new.vue@@ -179,11 +179,17 @@ async function extractAll() {}) as { sources: SourceOcrItem[] }for (const item of result.sources) {- sources.value.push({- id: crypto.randomUUID(),- data: createSourceData(item),- confidence: item.confidence,- })+ const emptySlot = sources.value.find(s => isSourceEmpty(s))+ if (emptySlot) {+ Object.assign(emptySlot.data, createSourceData(item))+ emptySlot.confidence = item.confidence+ } else {+ sources.value.push({+ id: crypto.randomUUID(),+ data: createSourceData(item),+ confidence: item.confidence,+ })+ }}pendingFiles.value.forEach(f => f.previewUrl && URL.revokeObjectURL(f.previewUrl))@@ -237,7 +243,29 @@ function handleFileSelect(event: Event) {}}+function isSourceEmpty(source: ExtractedSource): boolean {+ const d = source.data+ if (d.type === 'github') {+ return !d.label && !d.repo && !d.contentPath+ }+ return !d.label && !d.channelId && !d.handle+}++function resetSource(source: ExtractedSource) {+ const type = source.data.type+ Object.assign(source.data, createSourceData({ type } as SourceOcrItem))+ source.confidence = 1+}+function removeSource(id: string) {+ const source = sources.value.find(s => s.id === id)+ if (!source) return++ if (!isSourceEmpty(source)) {+ resetSource(source)+ return+ }+if (sources.value.length > 1) {sources.value = sources.value.filter(s => s.id !== id)}@@ -479,6 +507,7 @@ const validSourcesCount = computed(() => sources.value.filter(s => s.data.label)</div></div><button+ tabindex="-1"class="text-muted hover:text-error transition-colors p-1"aria-label="Delete source"@click="removeSource(source.id)"diff --git a/apps/chat/nuxt.config.ts b/apps/chat/nuxt.config.tsindex 805258b..62b3512 100644--- a/apps/chat/nuxt.config.ts+++ b/apps/chat/nuxt.config.ts@@ -123,8 +123,6 @@ export default defineNuxtConfig({'/api/webhooks/**': { isr: false, cache: false },// Admin pages are behind auth'/admin/**': { auth: { user: { role: 'admin' } } },- // Admin API routes should never be cached- '/api/admin/**': { isr: false, cache: false },},runtimeConfig: {diff --git a/bun.lock b/bun.lockindex 5e93bc0..20b62b8 100644--- a/bun.lock+++ b/bun.lock@@ -69,9 +69,8 @@"name": "@savoir/agent","version": "0.1.0","dependencies": {- "@ai-sdk/anthropic": "^3.0.45","@ai-sdk/gateway": "^3.0.45",- "@ai-sdk/google": "^3.0.29",+ "@ai-sdk/openai": "^3.0.30","ai": "^6.0.85","evlog": "^1.9.0","zod": "^4.3.6",@@ -112,11 +111,9 @@"minimatch": "^10.0.1",},"packages": {- "@ai-sdk/anthropic": ["@ai-sdk/[email protected]", "", { "dependencies": { "@ai-sdk/provider": "3.0.8", "@ai-sdk/provider-utils": "4.0.15" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-bpIS3RakSsaUhCRTIvL9bcVNeeUMDXWbndpYdXNeMJIIPcElTcvwktvla+JxIfbeK1AdQjB8ggYVChepeXPGwQ=="],-"@ai-sdk/gateway": ["@ai-sdk/[email protected]", "", { "dependencies": { "@ai-sdk/provider": "3.0.8", "@ai-sdk/provider-utils": "4.0.15", "@vercel/oidc": "3.1.0" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-zH1UbNRjG5woOXXFOrVCZraqZuFTtmPvLardMGcgLkzpxKV0U3tAGoyWKSZ862H+eBJfI/Hf2yj/zzGJcCkycg=="],- "@ai-sdk/google": ["@ai-sdk/[email protected]", "", { "dependencies": { "@ai-sdk/provider": "3.0.8", "@ai-sdk/provider-utils": "4.0.15" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-x0hcU10AA+i1ZUQHloGD5qXWsB+Y8qnxlmFUef6Ly4rB53MGVbQExkI9nOKiCO3mu2TGiiNoQMeKWSeQVLfRUA=="],+ "@ai-sdk/openai": ["@ai-sdk/[email protected]", "", { "dependencies": { "@ai-sdk/provider": "3.0.8", "@ai-sdk/provider-utils": "4.0.15" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-YDht3t7TDyWKP+JYZp20VuYqSjyF2brHYh47GGFDUPf2wZiqNQ263ecL+quar2bP3GZ3BeQA8f0m2B7UwLPR+g=="],"@ai-sdk/provider": ["@ai-sdk/[email protected]", "", { "dependencies": { "json-schema": "^0.4.0" } }, "sha512-oGMAgGoQdBXbZqNG0Ze56CHjDZ1IDYOwGYxYjO5KLSlz5HiNQ9udIXsPZ61VWaHGZ5XW/jyjmr6t2xz2jGVwbQ=="],diff --git a/packages/agent/package.json b/packages/agent/package.jsonindex a3271cb..c6a7611 100644--- a/packages/agent/package.json+++ b/packages/agent/package.json@@ -24,9 +24,8 @@"lint:fix": "eslint . --fix"},"dependencies": {- "@ai-sdk/anthropic": "^3.0.45","@ai-sdk/gateway": "^3.0.45",- "@ai-sdk/google": "^3.0.29",+ "@ai-sdk/openai": "^3.0.30","ai": "^6.0.85","evlog": "^1.9.0","zod": "^4.3.6"diff --git a/packages/agent/src/agents/base.ts b/packages/agent/src/agents/base.tsindex 4d6f848..ae65451 100644--- a/packages/agent/src/agents/base.ts+++ b/packages/agent/src/agents/base.ts@@ -5,7 +5,7 @@ import { compactContext } from '../core/context'import { callOptionsSchema } from '../core/schemas'import { sanitizeToolCallInputs } from '../core/sanitize'import { countConsecutiveToolSteps, shouldForceTextOnlyStep } from '../core/policy'-import { getSearchTools } from '../tools/model-config'+import { webSearchTool } from '../tools/web-search'import type { AgentCallOptions, AgentExecutionContext, CreateAgentOptions } from '../types'export function createAgent({@@ -54,7 +54,7 @@ export function createAgent({...settings,model: effectiveModel,instructions: buildPrompt(routerConfig, agentConfig),- tools: { ...tools, ...getSearchTools(effectiveModel) },+ tools: { ...tools, web_search: webSearchTool },stopWhen: stepCountIs(effectiveMaxSteps),experimental_context: executionContext,}diff --git a/packages/agent/src/agents/source.ts b/packages/agent/src/agents/source.tsindex f58862b..63885fa 100644--- a/packages/agent/src/agents/source.ts+++ b/packages/agent/src/agents/source.ts@@ -8,7 +8,7 @@ import { compactContext } from '../core/context'import { callOptionsSchema } from '../core/schemas'import { sanitizeToolCallInputs } from '../core/sanitize'import { countConsecutiveToolSteps, shouldForceTextOnlyStep } from '../core/policy'-import { getSearchTools } from '../tools/model-config'+import { webSearchTool } from '../tools/web-search'import type { AgentConfigData, AgentCallOptions, AgentExecutionContext, RoutingResult } from '../types'export interface SourceAgentOptions {@@ -71,7 +71,7 @@ export function createSourceAgent({...settings,model: effectiveModel,instructions: applyComplexity(buildChatSystemPrompt(agentConfig), routerConfig),- tools: { ...tools, ...getSearchTools(effectiveModel) },+ tools: { ...tools, web_search: webSearchTool },stopWhen: stepCountIs(effectiveMaxSteps),experimental_context: executionContext,}diff --git a/packages/agent/src/index.ts b/packages/agent/src/index.tsindex f38f52b..9f44c5b 100644--- a/packages/agent/src/index.ts+++ b/packages/agent/src/index.ts@@ -1,5 +1,5 @@// Tools-export { getSearchTools } from './tools/model-config'+export { webSearchTool } from './tools/web-search'// Agentsexport { createSourceAgent } from './agents/source'diff --git a/packages/agent/src/tools/model-config.ts b/packages/agent/src/tools/model-config.tsdeleted file mode 100644index bcc3caa..0000000--- a/packages/agent/src/tools/model-config.ts+++ /dev/null@@ -1,19 +0,0 @@-import { anthropic } from '@ai-sdk/anthropic'-import { google } from '@ai-sdk/google'--/**- * Returns provider-native search tools for the given model.- * These are provider-defined tools executed server-side by the provider.- */-export function getSearchTools(modelId: string): Record<string, unknown> {- const [provider] = modelId.split('/')-- switch (provider) {- case 'anthropic':- return { web_search: anthropic.tools.webSearch_20250305() }- case 'google':- return { google_search: google.tools.googleSearch({}) }- default:- return {}- }-}diff --git a/packages/agent/src/tools/web-search.perplexity.ts b/packages/agent/src/tools/web-search.perplexity.tsnew file mode 100644index 0000000..8be5b17--- /dev/null+++ b/packages/agent/src/tools/web-search.perplexity.ts@@ -0,0 +1,65 @@+import { generateText, tool } from 'ai'+import { createGateway } from '@ai-sdk/gateway'+import { z } from 'zod'++const gateway = createGateway()++export const webSearchTool = tool({+ description: 'Search the web for up-to-date information. Use when you need current data, recent events, or facts not available in the documentation.',+ inputSchema: z.object({+ query: z.string().describe('The search query'),+ }),+ execute: async function* ({ query }, { abortSignal }) {+ yield { status: 'loading' as const }+ const start = Date.now()++ try {+ const { text, sources } = await generateText({+ model: gateway('perplexity/sonar'),+ prompt: query,+ abortSignal,+ })++ const urlSources = sources+ ?.filter(s => s.sourceType === 'url')+ .map(s => ({ title: s.title, url: (s as Extract<typeof s, { sourceType: 'url' }>).url }))+ ?? []++ const sourcesPreview = urlSources.map(s => `${s.title || s.url}\n ${s.url}`).join('\n')++ yield {+ status: 'done' as const,+ durationMs: Date.now() - start,+ text,+ sources: urlSources,+ commands: [+ {+ title: `Web search: "${query}"`,+ command: '',+ stdout: sourcesPreview || text.slice(0, 500),+ stderr: '',+ exitCode: 0,+ success: true,+ },+ ],+ }+ } catch (error) {+ yield {+ status: 'done' as const,+ durationMs: Date.now() - start,+ text: '',+ sources: [],+ commands: [+ {+ title: `Web search: "${query}"`,+ command: '',+ stdout: '',+ stderr: error instanceof Error ? error.message : 'Search failed',+ exitCode: 1,+ success: false,+ },+ ],+ }+ }+ },+})diff --git a/packages/agent/src/tools/web-search.ts b/packages/agent/src/tools/web-search.tsnew file mode 100644index 0000000..0a198dd--- /dev/null+++ b/packages/agent/src/tools/web-search.ts@@ -0,0 +1,68 @@+import { generateText, tool } from 'ai'+import { createGateway } from '@ai-sdk/gateway'+import { openai } from '@ai-sdk/openai'+import { z } from 'zod'++const gateway = createGateway()++export const webSearchTool = tool({+ description: 'Search the web for up-to-date information. Use when you need current data, recent events, or facts not available in the documentation.',+ inputSchema: z.object({+ query: z.string().describe('The search query'),+ }),+ execute: async function* ({ query }, { abortSignal }) {+ yield { status: 'loading' as const }+ const start = Date.now()++ try {+ const { text, sources } = await generateText({+ model: gateway('openai/gpt-5-chat'),+ tools: { web_search: openai.tools.webSearch() } as Parameters<typeof generateText>[0]['tools'],+ toolChoice: { type: 'tool', toolName: 'web_search' },+ prompt: query,+ abortSignal,+ })++ const urlSources = sources+ ?.filter(s => s.sourceType === 'url')+ .map(s => ({ title: s.title, url: (s as Extract<typeof s, { sourceType: 'url' }>).url }))+ ?? []++ const sourcesPreview = urlSources.map(s => `${s.title || s.url}\n ${s.url}`).join('\n')++ yield {+ status: 'done' as const,+ durationMs: Date.now() - start,+ text,+ sources: urlSources,+ commands: [+ {+ title: `Web search: "${query}"`,+ command: '',+ stdout: sourcesPreview || text.slice(0, 500),+ stderr: '',+ exitCode: 0,+ success: true,+ },+ ],+ }+ } catch (error) {+ yield {+ status: 'done' as const,+ durationMs: Date.now() - start,+ text: '',+ sources: [],+ commands: [+ {+ title: `Web search: "${query}"`,+ command: '',+ stdout: '',+ stderr: error instanceof Error ? error.message : 'Search failed',+ exitCode: 1,+ success: false,+ },+ ],+ }+ }+ },+})