langfuse-core
Advanced tools
Comparing version 2.6.0 to 2.6.2-alpha.0
'use strict'; | ||
var mustache = require('mustache'); | ||
var langfuseCore = require('langfuse-core'); | ||
@@ -87,2 +88,32 @@ exports.LangfusePersistedProperty = void 0; | ||
} | ||
function configLangfuseSDK(params) { | ||
if (!params) { | ||
params = {}; | ||
} | ||
const { | ||
publicKey, | ||
secretKey, | ||
...coreOptions | ||
} = params; | ||
// check environment variables if values not provided | ||
const finalPublicKey = publicKey ?? getEnv("LANGFUSE_PUBLIC_KEY"); | ||
const finalSecretKey = secretKey ?? getEnv("LANGFUSE_SECRET_KEY"); | ||
const finalBaseUrl = coreOptions.baseUrl ?? getEnv("LANGFUSE_BASEURL"); | ||
const finalCoreOptions = { | ||
...coreOptions, | ||
baseUrl: finalBaseUrl | ||
}; | ||
// check required parameters | ||
if (!finalPublicKey) { | ||
console.error("publicKey is required, but was not provided"); | ||
} | ||
if (!finalSecretKey) { | ||
console.error("secretKey is required, but was not provided"); | ||
} | ||
return { | ||
publicKey: finalPublicKey, | ||
secretKey: finalSecretKey, | ||
...finalCoreOptions | ||
}; | ||
} | ||
@@ -92,2 +123,3 @@ var utils = /*#__PURE__*/Object.freeze({ | ||
assert: assert, | ||
configLangfuseSDK: configLangfuseSDK, | ||
currentISOTime: currentISOTime, | ||
@@ -195,4 +227,3 @@ currentTimestamp: currentTimestamp, | ||
...options | ||
} = params; | ||
assert(publicKey, "You must pass your Langfuse project's api public key."); | ||
} = langfuseCore.utils.configLangfuseSDK(params); | ||
this.publicKey = publicKey; | ||
@@ -477,4 +508,6 @@ this.secretKey = secretKey; | ||
"X-Langfuse-Sdk-Variant": this.getLibraryId(), | ||
"X-Langfuse-Public-Key": this.publicKey, | ||
...this.constructAuthorizationHeader(this.publicKey, this.secretKey) | ||
...(this.publicKey ? { | ||
"X-Langfuse-Public-Key": this.publicKey | ||
} : undefined), | ||
...(this.publicKey ? this.constructAuthorizationHeader(this.publicKey, this.secretKey) : undefined) | ||
}, | ||
@@ -577,4 +610,4 @@ body: p.body | ||
constructor(params) { | ||
assert(params.publicKey, "You must pass your Langfuse project's api public key."); | ||
assert(params.secretKey, "You must pass your Langfuse project's api secret key."); | ||
assert(params?.publicKey, "You must pass your Langfuse project's api public key."); | ||
assert(params?.secretKey, "You must pass your Langfuse project's api secret key."); | ||
super(params); | ||
@@ -581,0 +614,0 @@ this._promptCache = new LangfusePromptCache(); |
@@ -1395,5 +1395,11 @@ /// <reference types="node" /> | ||
declare function getEnv<T = string>(key: string): T | undefined; | ||
interface Params extends LangfuseCoreOptions { | ||
publicKey?: string; | ||
secretKey?: string; | ||
} | ||
declare function configLangfuseSDK(params?: Params): Params; | ||
type utils_d_RetriableOptions = RetriableOptions; | ||
declare const utils_d_assert: typeof assert; | ||
declare const utils_d_configLangfuseSDK: typeof configLangfuseSDK; | ||
declare const utils_d_currentISOTime: typeof currentISOTime; | ||
@@ -1410,2 +1416,3 @@ declare const utils_d_currentTimestamp: typeof currentTimestamp; | ||
utils_d_assert as assert, | ||
utils_d_configLangfuseSDK as configLangfuseSDK, | ||
utils_d_currentISOTime as currentISOTime, | ||
@@ -1458,4 +1465,4 @@ utils_d_currentTimestamp as currentTimestamp, | ||
abstract setPersistedProperty<T>(key: LangfusePersistedProperty, value: T | null): void; | ||
constructor(params: { | ||
publicKey: string; | ||
constructor(params?: { | ||
publicKey?: string; | ||
secretKey?: string; | ||
@@ -1505,3 +1512,3 @@ } & LangfuseCoreOptions); | ||
constructor(params: { | ||
publicKey: string; | ||
publicKey?: string; | ||
} & LangfuseCoreOptions); | ||
@@ -1512,5 +1519,5 @@ score(body: CreateLangfuseScoreBody): Promise<this>; | ||
private _promptCache; | ||
constructor(params: { | ||
publicKey: string; | ||
secretKey: string; | ||
constructor(params?: { | ||
publicKey?: string; | ||
secretKey?: string; | ||
} & LangfuseCoreOptions); | ||
@@ -1517,0 +1524,0 @@ trace(body?: CreateLangfuseTraceBody): LangfuseTraceClient; |
{ | ||
"name": "langfuse-core", | ||
"version": "2.6.0", | ||
"version": "2.6.2-alpha.0", | ||
"engines": { | ||
@@ -40,3 +40,3 @@ "node": ">=18" | ||
}, | ||
"gitHead": "5cd24ecb99106368eec611579ff95084601e06cc" | ||
"gitHead": "4a75e27d510d5766f472fa890eda43b7806050c3" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
306588
3357
2