diff --git a/packages/langbase/src/common/request.ts b/packages/langbase/src/common/request.ts index 35d2106..548413d 100644 --- a/packages/langbase/src/common/request.ts +++ b/packages/langbase/src/common/request.ts @@ -1,6 +1,7 @@ import {Headers} from './../../types'; // Ensure this import is correct import {APIConnectionError, APIError} from './errors'; import {Stream} from './stream'; +import 'dotenv/config'; interface RequestOptions { endpoint: string; @@ -14,6 +15,7 @@ interface RequestConfig { apiKey: string; baseUrl: string; timeout?: number; + id?: string; } interface SendOptions extends RequestOptions { @@ -34,9 +36,11 @@ interface HandleGenerateResponseParams { export class Request { private config: RequestConfig; + private demo: string = ''; constructor(config: RequestConfig) { this.config = config; + this.demo = process.env.LB_DEMO || ''; } // Main send function @@ -82,6 +86,8 @@ export class Request { return { 'Content-Type': 'application/json', Authorization: `Bearer ${this.config.apiKey}`, + 'lb-meta-external-user-id': this.config.id || '', + 'lb-demo-id': this.demo, ...headers, }; } diff --git a/packages/langbase/src/pipes/pipes.ts b/packages/langbase/src/pipes/pipes.ts index f2db0df..e0a2a9b 100644 --- a/packages/langbase/src/pipes/pipes.ts +++ b/packages/langbase/src/pipes/pipes.ts @@ -97,6 +97,7 @@ export interface StreamChunk { export interface PipeOptions { apiKey: string; baseUrl?: string; + id?: string; } export class Pipe { @@ -104,7 +105,11 @@ export class Pipe { constructor(options: PipeOptions) { const baseUrl = 'https://api.langbase.com'; - this.request = new Request({apiKey: options.apiKey, baseUrl}); + this.request = new Request({ + baseUrl, + id: options.id, + apiKey: options.apiKey, + }); } async generateText(options: GenerateOptions): Promise { diff --git a/turbo.json b/turbo.json index cedb898..efd9504 100644 --- a/turbo.json +++ b/turbo.json @@ -28,7 +28,8 @@ "ASSISTANT_ID", "INKEEP_API_KEY", "INKEEP_INTEGRATION_ID", - "VERCEL_URL" + "VERCEL_URL", + "LB_DEMO" ], "outputs": [ "dist/**",