langfuse-core
Advanced tools
Comparing version 2.6.2-alpha.0 to 2.7.0
'use strict'; | ||
var mustache = require('mustache'); | ||
var langfuseCore = require('langfuse-core'); | ||
@@ -88,3 +87,3 @@ exports.LangfusePersistedProperty = void 0; | ||
} | ||
function configLangfuseSDK(params) { | ||
function configLangfuseSDK(params, secretRequired = true) { | ||
if (!params) { | ||
@@ -100,3 +99,3 @@ params = {}; | ||
const finalPublicKey = publicKey ?? getEnv("LANGFUSE_PUBLIC_KEY"); | ||
const finalSecretKey = secretKey ?? getEnv("LANGFUSE_SECRET_KEY"); | ||
const finalSecretKey = secretRequired ? secretKey ?? getEnv("LANGFUSE_SECRET_KEY") : undefined; | ||
const finalBaseUrl = coreOptions.baseUrl ?? getEnv("LANGFUSE_BASEURL"); | ||
@@ -109,10 +108,12 @@ const finalCoreOptions = { | ||
if (!finalPublicKey) { | ||
console.error("publicKey is required, but was not provided"); | ||
console.error("publicKey is required, but was not provided. It can be provided as an argument or as an environment variable LANGFUSE_PUBLIC_KEY."); | ||
} | ||
if (!finalSecretKey) { | ||
console.error("secretKey is required, but was not provided"); | ||
if (!finalSecretKey && secretRequired) { | ||
console.error("secretKey is required, but was not provided. It can be provided as an argument or as an environment variable LANGFUSE_SECRET_KEY."); | ||
} | ||
return { | ||
publicKey: finalPublicKey, | ||
secretKey: finalSecretKey, | ||
...(secretRequired ? { | ||
secretKey: finalSecretKey | ||
} : undefined), | ||
...finalCoreOptions | ||
@@ -228,3 +229,4 @@ }; | ||
...options | ||
} = langfuseCore.utils.configLangfuseSDK(params); | ||
} = params; | ||
assert(publicKey, "You must pass your Langfuse project's api public key."); | ||
this.publicKey = publicKey; | ||
@@ -362,3 +364,3 @@ this.secretKey = secretKey; | ||
async _getDataset(name) { | ||
return this.fetch(`${this.baseUrl}/api/public/datasets/${name}`, this.getFetchOptions({ | ||
return this.fetch(`${this.baseUrl}/api/public/datasets/${name}`, this._getFetchOptions({ | ||
method: "GET" | ||
@@ -368,3 +370,3 @@ })).then(res => res.json()); | ||
async getDatasetRun(params) { | ||
return this.fetch(`${this.baseUrl}/api/public/datasets/${params.datasetName}/runs/${params.runName}`, this.getFetchOptions({ | ||
return this.fetch(`${this.baseUrl}/api/public/datasets/${params.datasetName}/runs/${params.runName}`, this._getFetchOptions({ | ||
method: "GET" | ||
@@ -374,3 +376,3 @@ })).then(res => res.json()); | ||
async createDatasetRunItem(body) { | ||
return this.fetch(`${this.baseUrl}/api/public/dataset-run-items`, this.getFetchOptions({ | ||
return this.fetch(`${this.baseUrl}/api/public/dataset-run-items`, this._getFetchOptions({ | ||
method: "POST", | ||
@@ -384,3 +386,3 @@ body: JSON.stringify(body) | ||
}; | ||
return this.fetch(`${this.baseUrl}/api/public/datasets`, this.getFetchOptions({ | ||
return this.fetch(`${this.baseUrl}/api/public/datasets`, this._getFetchOptions({ | ||
method: "POST", | ||
@@ -396,3 +398,3 @@ body: JSON.stringify(body) | ||
async createDatasetItem(body) { | ||
return this.fetch(`${this.baseUrl}/api/public/dataset-items`, this.getFetchOptions({ | ||
return this.fetch(`${this.baseUrl}/api/public/dataset-items`, this._getFetchOptions({ | ||
method: "POST", | ||
@@ -403,3 +405,3 @@ body: JSON.stringify(body) | ||
async getDatasetItem(id) { | ||
return this.fetch(`${this.baseUrl}/api/public/dataset-items/${id}`, this.getFetchOptions({ | ||
return this.fetch(`${this.baseUrl}/api/public/dataset-items/${id}`, this._getFetchOptions({ | ||
method: "GET" | ||
@@ -416,3 +418,3 @@ })).then(res => res.json()); | ||
async createPromptStateless(body) { | ||
return this.fetch(`${this.baseUrl}/api/public/prompts`, this.getFetchOptions({ | ||
return this.fetch(`${this.baseUrl}/api/public/prompts`, this._getFetchOptions({ | ||
method: "POST", | ||
@@ -424,3 +426,3 @@ body: JSON.stringify(body) | ||
const url = `${this.baseUrl}/api/public/prompts?name=${name}` + (version ? `&version=${version}` : ""); | ||
return this.fetch(url, this.getFetchOptions({ | ||
return this.fetch(url, this._getFetchOptions({ | ||
method: "GET" | ||
@@ -499,3 +501,3 @@ })).then(async res => { | ||
const url = `${this.baseUrl}/api/public/ingestion`; | ||
const fetchOptions = this.getFetchOptions({ | ||
const fetchOptions = this._getFetchOptions({ | ||
method: "POST", | ||
@@ -510,3 +512,3 @@ body: payload | ||
} | ||
getFetchOptions(p) { | ||
_getFetchOptions(p) { | ||
const fetchOptions = { | ||
@@ -519,6 +521,4 @@ method: p.method, | ||
"X-Langfuse-Sdk-Variant": this.getLibraryId(), | ||
...(this.publicKey ? { | ||
"X-Langfuse-Public-Key": this.publicKey | ||
} : undefined), | ||
...(this.publicKey ? this.constructAuthorizationHeader(this.publicKey, this.secretKey) : undefined) | ||
"X-Langfuse-Public-Key": this.publicKey, | ||
...this.constructAuthorizationHeader(this.publicKey, this.secretKey) | ||
}, | ||
@@ -621,4 +621,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); | ||
@@ -625,0 +625,0 @@ this._promptCache = new LangfusePromptCache(); |
@@ -109,3 +109,3 @@ /// <reference types="node" /> | ||
TraceWithFullDetails: WithRequired<{ | ||
observations: components["schemas"]["Observation"][]; | ||
observations: components["schemas"]["ObservationsView"][]; | ||
scores: components["schemas"]["Score"][]; | ||
@@ -150,2 +150,18 @@ } & components["schemas"]["Trace"], "observations" | "scores">; | ||
}; | ||
/** ObservationsView */ | ||
ObservationsView: { | ||
modelId?: string | null; | ||
/** Format: double */ | ||
inputPrice?: number | null; | ||
/** Format: double */ | ||
outputPrice?: number | null; | ||
/** Format: double */ | ||
totalPrice?: number | null; | ||
/** Format: double */ | ||
calculatedInputCost?: number | null; | ||
/** Format: double */ | ||
calculatedOutputCost?: number | null; | ||
/** Format: double */ | ||
calculatedTotalCost?: number | null; | ||
} & components["schemas"]["Observation"]; | ||
/** Usage */ | ||
@@ -227,3 +243,3 @@ Usage: { | ||
*/ | ||
ModelUsageUnit: "CHARACTERS" | "TOKENS"; | ||
ModelUsageUnit: "CHARACTERS" | "TOKENS" | "MILLISECONDS" | "SECONDS" | "IMAGES"; | ||
/** | ||
@@ -491,2 +507,7 @@ * ObservationLevel | ||
}; | ||
/** ObservationsViews */ | ||
ObservationsViews: { | ||
data: components["schemas"]["ObservationsView"][]; | ||
meta: components["schemas"]["utilsMetaResponse"]; | ||
}; | ||
/** Projects */ | ||
@@ -890,3 +911,3 @@ Projects: { | ||
content: { | ||
"application/json": components["schemas"]["Observation"]; | ||
"application/json": components["schemas"]["ObservationsView"]; | ||
}; | ||
@@ -937,3 +958,3 @@ }; | ||
content: { | ||
"application/json": components["schemas"]["Observations"]; | ||
"application/json": components["schemas"]["ObservationsViews"]; | ||
}; | ||
@@ -1401,7 +1422,7 @@ }; | ||
declare function getEnv<T = string>(key: string): T | undefined; | ||
interface Params extends LangfuseCoreOptions { | ||
type Params = LangfuseCoreOptions & { | ||
publicKey?: string; | ||
secretKey?: string; | ||
} | ||
declare function configLangfuseSDK(params?: Params): Params; | ||
}; | ||
declare function configLangfuseSDK(params?: Params, secretRequired?: boolean): Params; | ||
@@ -1470,4 +1491,4 @@ type utils_d_RetriableOptions = RetriableOptions; | ||
abstract setPersistedProperty<T>(key: LangfusePersistedProperty, value: T | null): void; | ||
constructor(params?: { | ||
publicKey?: string; | ||
constructor(params: { | ||
publicKey: string; | ||
secretKey?: string; | ||
@@ -1508,3 +1529,6 @@ } & LangfuseCoreOptions); | ||
flush(callback?: (err?: any, data?: any) => void): void; | ||
private getFetchOptions; | ||
_getFetchOptions(p: { | ||
method: LangfuseFetchOptions["method"]; | ||
body?: LangfuseFetchOptions["body"]; | ||
}): LangfuseFetchOptions; | ||
private constructAuthorizationHeader; | ||
@@ -1518,3 +1542,3 @@ private fetchWithRetry; | ||
constructor(params: { | ||
publicKey?: string; | ||
publicKey: string; | ||
} & LangfuseCoreOptions); | ||
@@ -1525,5 +1549,5 @@ score(body: CreateLangfuseScoreBody): Promise<this>; | ||
private _promptCache; | ||
constructor(params?: { | ||
publicKey?: string; | ||
secretKey?: string; | ||
constructor(params: { | ||
publicKey: string; | ||
secretKey: string; | ||
} & LangfuseCoreOptions); | ||
@@ -1530,0 +1554,0 @@ trace(body?: CreateLangfuseTraceBody): LangfuseTraceClient; |
{ | ||
"name": "langfuse-core", | ||
"version": "2.6.2-alpha.0", | ||
"version": "2.7.0", | ||
"engines": { | ||
@@ -40,3 +40,3 @@ "node": ">=18" | ||
}, | ||
"gitHead": "4a75e27d510d5766f472fa890eda43b7806050c3" | ||
"gitHead": "6504c659bdcae644bc32ba28d4826b255618097c" | ||
} |
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
309643
3381
1