Skip to content

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

improve env var management

Hugo Richard3937c9e1fd16
diff --git a/apps/chat/nuxt.config.ts b/apps/chat/nuxt.config.ts
index d7c628f..b42608d 100644
--- a/apps/chat/nuxt.config.ts
+++ b/apps/chat/nuxt.config.ts
@@ -47,12 +47,20 @@ export default defineNuxtConfig({
},
runtimeConfig: {
- githubToken: process.env.GITHUB_TOKEN || '',
- githubAppId: process.env.GITHUB_APP_ID || '',
- githubAppPrivateKey: process.env.GITHUB_APP_PRIVATE_KEY || '',
- githubWebhookSecret: process.env.GITHUB_WEBHOOK_SECRET || '',
+ savoir: {
+ apiUrl: '',
+ apiKey: '',
+ },
+ github: {
+ token: '',
+ appId: '',
+ appPrivateKey: '',
+ webhookSecret: '',
+ },
public: {
- githubBotTrigger: process.env.GITHUB_BOT_TRIGGER || '@nuxt-agent'
- }
+ github: {
+ botTrigger: '@nuxt-agent',
+ },
+ },
}
})
diff --git a/apps/chat/server/api/chats/[id].post.ts b/apps/chat/server/api/chats/[id].post.ts
index 64e86bc..b14b5a4 100644
--- a/apps/chat/server/api/chats/[id].post.ts
+++ b/apps/chat/server/api/chats/[id].post.ts
@@ -102,9 +102,10 @@ export default defineEventHandler(async (event) => {
})
}
+ const { savoir: savoirConfig } = useRuntimeConfig()
const savoir = createSavoir({
- apiKey: process.env.SAVOIR_API_KEY!,
- apiUrl: import.meta.dev ? 'http://localhost:3001' : 'https://api.savoir.dev',
+ apiUrl: savoirConfig.apiUrl,
+ apiKey: savoirConfig.apiKey || undefined,
})
// Metrics tracking
diff --git a/packages/sdk/package.json b/packages/sdk/package.json
index b784a50..7c013bd 100644
--- a/packages/sdk/package.json
+++ b/packages/sdk/package.json
@@ -31,6 +31,7 @@
"prepublishOnly": "pnpm build"
},
"dependencies": {
+ "@savoir/logger": "workspace:*",
"ai": "^6.0.31",
"zod": "^4.3.5"
},
diff --git a/packages/sdk/src/client.ts b/packages/sdk/src/client.ts
index 41dc990..7bda118 100644
--- a/packages/sdk/src/client.ts
+++ b/packages/sdk/src/client.ts
@@ -4,8 +4,7 @@ import type {
SearchAndReadResponse,
} from './types'
import { NetworkError, SavoirError } from './errors'
-
-const DEFAULT_API_URL = 'https://api.savoir.dev'
+import { createError } from '@savoir/logger'
/**
* HTTP client for the Savoir API
@@ -13,11 +12,19 @@ const DEFAULT_API_URL = 'https://api.savoir.dev'
export class SavoirClient {
private readonly apiUrl: string
- private readonly apiKey: string
+ private readonly apiKey?: string
private sessionId?: string
constructor(config: SavoirConfig) {
- this.apiUrl = config.apiUrl?.replace(/\/$/, '') || DEFAULT_API_URL
+ if (!config.apiUrl) {
+ throw createError({
+ message: 'Missing apiUrl in Savoir configuration',
+ why: 'The Savoir SDK requires an API URL to connect to',
+ fix: 'Set SAVOIR_API_URL environment variable or pass apiUrl to createSavoir()',
+ })
+ }
+
+ this.apiUrl = config.apiUrl.replace(/\/$/, '')
this.apiKey = config.apiKey
this.sessionId = config.sessionId
}
@@ -45,13 +52,18 @@ export class SavoirClient {
): Promise<T> {
const url = `${this.apiUrl}${path}`
+ const headers: Record<string, string> = {
+ 'Content-Type': 'application/json',
+ }
+
+ if (this.apiKey) {
+ headers['Authorization'] = `Bearer ${this.apiKey}`
+ }
+
try {
const response = await fetch(url, {
method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': `Bearer ${this.apiKey}`,
- },
+ headers,
body: JSON.stringify({
...body,
sessionId: this.sessionId,
diff --git a/packages/sdk/src/index.ts b/packages/sdk/src/index.ts
index d7d8423..95f0666 100644
--- a/packages/sdk/src/index.ts
+++ b/packages/sdk/src/index.ts
@@ -43,8 +43,9 @@ export interface Savoir {
* import { generateText } from 'ai'
*
* const savoir = createSavoir({
- * apiKey: process.env.SAVOIR_API_KEY!,
- * sessionId: 'optional-session-id', // For sandbox reuse
+ * apiUrl: process.env.SAVOIR_API_URL!, // Required
+ * apiKey: process.env.SAVOIR_API_KEY, // Optional if API doesn't require auth
+ * sessionId: 'optional-session-id', // For sandbox reuse
* })
*
* const { text } = await generateText({
diff --git a/packages/sdk/src/types.ts b/packages/sdk/src/types.ts
index eefb02d..0ed3777 100644
--- a/packages/sdk/src/types.ts
+++ b/packages/sdk/src/types.ts
@@ -4,14 +4,14 @@
export interface SavoirConfig {
/**
* Base URL for the Savoir API
- * @default 'https://api.savoir.dev'
*/
- apiUrl?: string
+ apiUrl: string
/**
* API key for authentication
+ * Optional if the API doesn't require authentication
*/
- apiKey: string
+ apiKey?: string
/**
* Optional session ID for sandbox reuse
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 313c80d..d6fd507 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -191,6 +191,9 @@ importers:
packages/sdk:
dependencies:
+ '@savoir/logger':
+ specifier: workspace:*
+ version: link:../logger
ai:
specifier: ^6.0.31
version: 6.0.43([email protected])