langsmith 0.3.72 → 0.3.73
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.cjs +12 -4
- package/dist/client.d.ts +2 -1
- package/dist/client.js +13 -5
- package/dist/evaluation/_runner.cjs +1 -1
- package/dist/evaluation/_runner.js +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/utils/env.cjs +31 -52
- package/dist/utils/env.d.ts +7 -18
- package/dist/utils/env.js +29 -49
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -48,9 +48,9 @@ const prompts_js_1 = require("./utils/prompts.cjs");
|
|
|
48
48
|
const error_js_1 = require("./utils/error.cjs");
|
|
49
49
|
const fetch_js_1 = require("./singletons/fetch.cjs");
|
|
50
50
|
const index_js_2 = require("./utils/fast-safe-stringify/index.cjs");
|
|
51
|
-
function mergeRuntimeEnvIntoRun(run) {
|
|
51
|
+
function mergeRuntimeEnvIntoRun(run, cachedEnvVars) {
|
|
52
52
|
const runtimeEnv = (0, env_js_1.getRuntimeEnvironment)();
|
|
53
|
-
const envVars = (0, env_js_1.
|
|
53
|
+
const envVars = cachedEnvVars ?? (0, env_js_1.getLangSmithEnvVarsMetadata)();
|
|
54
54
|
const extra = run.extra ?? {};
|
|
55
55
|
const metadata = extra.metadata;
|
|
56
56
|
run.extra = {
|
|
@@ -376,6 +376,12 @@ class Client {
|
|
|
376
376
|
writable: true,
|
|
377
377
|
value: void 0
|
|
378
378
|
});
|
|
379
|
+
Object.defineProperty(this, "cachedLSEnvVarsForMetadata", {
|
|
380
|
+
enumerable: true,
|
|
381
|
+
configurable: true,
|
|
382
|
+
writable: true,
|
|
383
|
+
value: void 0
|
|
384
|
+
});
|
|
379
385
|
Object.defineProperty(this, "multipartStreamingDisabled", {
|
|
380
386
|
enumerable: true,
|
|
381
387
|
configurable: true,
|
|
@@ -434,6 +440,8 @@ class Client {
|
|
|
434
440
|
if ((0, env_js_1.getOtelEnabled)()) {
|
|
435
441
|
this.langSmithToOTELTranslator = new translator_js_1.LangSmithToOTELTranslator();
|
|
436
442
|
}
|
|
443
|
+
// Cache metadata env vars once during construction to avoid repeatedly scanning process.env
|
|
444
|
+
this.cachedLSEnvVarsForMetadata = (0, env_js_1.getLangSmithEnvVarsMetadata)();
|
|
437
445
|
}
|
|
438
446
|
static getDefaultClientConfig() {
|
|
439
447
|
const apiKey = (0, env_js_1.getLangSmithEnvironmentVariable)("API_KEY");
|
|
@@ -781,7 +789,7 @@ class Client {
|
|
|
781
789
|
async processRunOperation(item) {
|
|
782
790
|
clearTimeout(this.autoBatchTimeout);
|
|
783
791
|
this.autoBatchTimeout = undefined;
|
|
784
|
-
item.item = mergeRuntimeEnvIntoRun(item.item);
|
|
792
|
+
item.item = mergeRuntimeEnvIntoRun(item.item, this.cachedLSEnvVarsForMetadata);
|
|
785
793
|
const itemPromise = this.autoBatchQueue.push(item);
|
|
786
794
|
if (this.manualFlushMode) {
|
|
787
795
|
// Rely on manual flushing in serverless environments
|
|
@@ -903,7 +911,7 @@ class Client {
|
|
|
903
911
|
}).catch(console.error);
|
|
904
912
|
return;
|
|
905
913
|
}
|
|
906
|
-
const mergedRunCreateParam = mergeRuntimeEnvIntoRun(runCreate);
|
|
914
|
+
const mergedRunCreateParam = mergeRuntimeEnvIntoRun(runCreate, this.cachedLSEnvVarsForMetadata);
|
|
907
915
|
if (options?.apiKey !== undefined) {
|
|
908
916
|
headers["x-api-key"] = options.apiKey;
|
|
909
917
|
}
|
package/dist/client.d.ts
CHANGED
|
@@ -271,7 +271,7 @@ type Thread = {
|
|
|
271
271
|
last_outputs: string;
|
|
272
272
|
last_error: string | null;
|
|
273
273
|
};
|
|
274
|
-
export declare function mergeRuntimeEnvIntoRun<T extends RunCreate | RunUpdate>(run: T): T;
|
|
274
|
+
export declare function mergeRuntimeEnvIntoRun<T extends RunCreate | RunUpdate>(run: T, cachedEnvVars?: Record<string, string>): T;
|
|
275
275
|
export declare class AutoBatchQueue {
|
|
276
276
|
items: {
|
|
277
277
|
action: "create" | "update";
|
|
@@ -329,6 +329,7 @@ export declare class Client implements LangSmithTracingClientInterface {
|
|
|
329
329
|
private manualFlushMode;
|
|
330
330
|
private langSmithToOTELTranslator?;
|
|
331
331
|
private fetchImplementation?;
|
|
332
|
+
private cachedLSEnvVarsForMetadata?;
|
|
332
333
|
private get _fetch();
|
|
333
334
|
private multipartStreamingDisabled;
|
|
334
335
|
debug: boolean;
|
package/dist/client.js
CHANGED
|
@@ -3,7 +3,7 @@ import { LangSmithToOTELTranslator, } from "./experimental/otel/translator.js";
|
|
|
3
3
|
import { getDefaultOTLPTracerComponents, getOTELTrace, getOTELContext, } from "./singletons/otel.js";
|
|
4
4
|
import { AsyncCaller } from "./utils/async_caller.js";
|
|
5
5
|
import { convertLangChainMessageToExample, isLangChainMessage, } from "./utils/messages.js";
|
|
6
|
-
import { getEnvironmentVariable,
|
|
6
|
+
import { getEnvironmentVariable, getLangSmithEnvVarsMetadata, getLangSmithEnvironmentVariable, getRuntimeEnvironment, getOtelEnabled, getEnv, } from "./utils/env.js";
|
|
7
7
|
import { __version__ } from "./index.js";
|
|
8
8
|
import { assertUuid } from "./utils/_uuid.js";
|
|
9
9
|
import { warnOnce } from "./utils/warn.js";
|
|
@@ -11,9 +11,9 @@ import { parsePromptIdentifier } from "./utils/prompts.js";
|
|
|
11
11
|
import { raiseForStatus } from "./utils/error.js";
|
|
12
12
|
import { _globalFetchImplementationIsNodeFetch, _getFetchImplementation, } from "./singletons/fetch.js";
|
|
13
13
|
import { serialize as serializePayloadForTracing } from "./utils/fast-safe-stringify/index.js";
|
|
14
|
-
export function mergeRuntimeEnvIntoRun(run) {
|
|
14
|
+
export function mergeRuntimeEnvIntoRun(run, cachedEnvVars) {
|
|
15
15
|
const runtimeEnv = getRuntimeEnvironment();
|
|
16
|
-
const envVars =
|
|
16
|
+
const envVars = cachedEnvVars ?? getLangSmithEnvVarsMetadata();
|
|
17
17
|
const extra = run.extra ?? {};
|
|
18
18
|
const metadata = extra.metadata;
|
|
19
19
|
run.extra = {
|
|
@@ -338,6 +338,12 @@ export class Client {
|
|
|
338
338
|
writable: true,
|
|
339
339
|
value: void 0
|
|
340
340
|
});
|
|
341
|
+
Object.defineProperty(this, "cachedLSEnvVarsForMetadata", {
|
|
342
|
+
enumerable: true,
|
|
343
|
+
configurable: true,
|
|
344
|
+
writable: true,
|
|
345
|
+
value: void 0
|
|
346
|
+
});
|
|
341
347
|
Object.defineProperty(this, "multipartStreamingDisabled", {
|
|
342
348
|
enumerable: true,
|
|
343
349
|
configurable: true,
|
|
@@ -396,6 +402,8 @@ export class Client {
|
|
|
396
402
|
if (getOtelEnabled()) {
|
|
397
403
|
this.langSmithToOTELTranslator = new LangSmithToOTELTranslator();
|
|
398
404
|
}
|
|
405
|
+
// Cache metadata env vars once during construction to avoid repeatedly scanning process.env
|
|
406
|
+
this.cachedLSEnvVarsForMetadata = getLangSmithEnvVarsMetadata();
|
|
399
407
|
}
|
|
400
408
|
static getDefaultClientConfig() {
|
|
401
409
|
const apiKey = getLangSmithEnvironmentVariable("API_KEY");
|
|
@@ -743,7 +751,7 @@ export class Client {
|
|
|
743
751
|
async processRunOperation(item) {
|
|
744
752
|
clearTimeout(this.autoBatchTimeout);
|
|
745
753
|
this.autoBatchTimeout = undefined;
|
|
746
|
-
item.item = mergeRuntimeEnvIntoRun(item.item);
|
|
754
|
+
item.item = mergeRuntimeEnvIntoRun(item.item, this.cachedLSEnvVarsForMetadata);
|
|
747
755
|
const itemPromise = this.autoBatchQueue.push(item);
|
|
748
756
|
if (this.manualFlushMode) {
|
|
749
757
|
// Rely on manual flushing in serverless environments
|
|
@@ -865,7 +873,7 @@ export class Client {
|
|
|
865
873
|
}).catch(console.error);
|
|
866
874
|
return;
|
|
867
875
|
}
|
|
868
|
-
const mergedRunCreateParam = mergeRuntimeEnvIntoRun(runCreate);
|
|
876
|
+
const mergedRunCreateParam = mergeRuntimeEnvIntoRun(runCreate, this.cachedLSEnvVarsForMetadata);
|
|
869
877
|
if (options?.apiKey !== undefined) {
|
|
870
878
|
headers["x-api-key"] = options.apiKey;
|
|
871
879
|
}
|
|
@@ -195,7 +195,7 @@ class _ExperimentManager {
|
|
|
195
195
|
let metadata = args.metadata || {};
|
|
196
196
|
if (!("revision_id" in metadata)) {
|
|
197
197
|
metadata = {
|
|
198
|
-
revision_id: (0, env_js_1.
|
|
198
|
+
revision_id: (0, env_js_1.getLangSmithEnvVarsMetadata)().revision_id,
|
|
199
199
|
...metadata,
|
|
200
200
|
};
|
|
201
201
|
}
|
|
@@ -4,7 +4,7 @@ import { getDefaultRevisionId, getGitInfo } from "../utils/_git.js";
|
|
|
4
4
|
import { assertUuid } from "../utils/_uuid.js";
|
|
5
5
|
import { AsyncCaller } from "../utils/async_caller.js";
|
|
6
6
|
import { atee } from "../utils/atee.js";
|
|
7
|
-
import {
|
|
7
|
+
import { getLangSmithEnvVarsMetadata } from "../utils/env.js";
|
|
8
8
|
import { printErrorStackTrace } from "../utils/error.js";
|
|
9
9
|
import { randomName } from "./_random_name.js";
|
|
10
10
|
import { runEvaluator, } from "./evaluator.js";
|
|
@@ -191,7 +191,7 @@ export class _ExperimentManager {
|
|
|
191
191
|
let metadata = args.metadata || {};
|
|
192
192
|
if (!("revision_id" in metadata)) {
|
|
193
193
|
metadata = {
|
|
194
|
-
revision_id:
|
|
194
|
+
revision_id: getLangSmithEnvVarsMetadata().revision_id,
|
|
195
195
|
...metadata,
|
|
196
196
|
};
|
|
197
197
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -10,4 +10,4 @@ Object.defineProperty(exports, "overrideFetchImplementation", { enumerable: true
|
|
|
10
10
|
var project_js_1 = require("./utils/project.cjs");
|
|
11
11
|
Object.defineProperty(exports, "getDefaultProjectName", { enumerable: true, get: function () { return project_js_1.getDefaultProjectName; } });
|
|
12
12
|
// Update using yarn bump-version
|
|
13
|
-
exports.__version__ = "0.3.
|
|
13
|
+
exports.__version__ = "0.3.73";
|
package/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ export type { Dataset, Example, TracerSession, Run, Feedback, RetrieverOutput, }
|
|
|
3
3
|
export { RunTree, type RunTreeConfig } from "./run_trees.js";
|
|
4
4
|
export { overrideFetchImplementation } from "./singletons/fetch.js";
|
|
5
5
|
export { getDefaultProjectName } from "./utils/project.js";
|
|
6
|
-
export declare const __version__ = "0.3.
|
|
6
|
+
export declare const __version__ = "0.3.73";
|
package/dist/index.js
CHANGED
|
@@ -3,4 +3,4 @@ export { RunTree } from "./run_trees.js";
|
|
|
3
3
|
export { overrideFetchImplementation } from "./singletons/fetch.js";
|
|
4
4
|
export { getDefaultProjectName } from "./utils/project.js";
|
|
5
5
|
// Update using yarn bump-version
|
|
6
|
-
export const __version__ = "0.3.
|
|
6
|
+
export const __version__ = "0.3.73";
|
package/dist/utils/env.cjs
CHANGED
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getEnv = exports.isNode = exports.isDeno = exports.isJsDom = exports.isWebWorker = exports.isBrowser = void 0;
|
|
4
4
|
exports.getRuntimeEnvironment = getRuntimeEnvironment;
|
|
5
|
-
exports.
|
|
6
|
-
exports.
|
|
7
|
-
exports.getEnvironmentVariables = getEnvironmentVariables;
|
|
5
|
+
exports.getLangSmithEnvVarsMetadata = getLangSmithEnvVarsMetadata;
|
|
6
|
+
exports.getLangSmithEnvironmentVariables = getLangSmithEnvironmentVariables;
|
|
8
7
|
exports.getEnvironmentVariable = getEnvironmentVariable;
|
|
9
8
|
exports.getLangSmithEnvironmentVariable = getLangSmithEnvironmentVariable;
|
|
10
9
|
exports.setEnvironmentVariable = setEnvironmentVariable;
|
|
@@ -77,40 +76,13 @@ function getRuntimeEnvironment() {
|
|
|
77
76
|
return runtimeEnvironment;
|
|
78
77
|
}
|
|
79
78
|
/**
|
|
80
|
-
* Retrieves the
|
|
81
|
-
* Sensitive keys (containing the word "key", "token", or "secret") have their values redacted for security.
|
|
79
|
+
* Retrieves the LangSmith-specific metadata from the current runtime environment.
|
|
82
80
|
*
|
|
83
81
|
* @returns {Record<string, string>}
|
|
84
|
-
* - A record of
|
|
82
|
+
* - A record of LangSmith-specific metadata environment variables.
|
|
85
83
|
*/
|
|
86
|
-
function
|
|
87
|
-
const allEnvVars =
|
|
88
|
-
const envVars = {};
|
|
89
|
-
for (const [key, value] of Object.entries(allEnvVars)) {
|
|
90
|
-
if (key.startsWith("LANGCHAIN_") && typeof value === "string") {
|
|
91
|
-
envVars[key] = value;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
for (const key in envVars) {
|
|
95
|
-
if ((key.toLowerCase().includes("key") ||
|
|
96
|
-
key.toLowerCase().includes("secret") ||
|
|
97
|
-
key.toLowerCase().includes("token")) &&
|
|
98
|
-
typeof envVars[key] === "string") {
|
|
99
|
-
const value = envVars[key];
|
|
100
|
-
envVars[key] =
|
|
101
|
-
value.slice(0, 2) + "*".repeat(value.length - 4) + value.slice(-2);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return envVars;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Retrieves the LangChain-specific metadata from the current runtime environment.
|
|
108
|
-
*
|
|
109
|
-
* @returns {Record<string, string>}
|
|
110
|
-
* - A record of LangChain-specific metadata environment variables.
|
|
111
|
-
*/
|
|
112
|
-
function getLangChainEnvVarsMetadata() {
|
|
113
|
-
const allEnvVars = getEnvironmentVariables() || {};
|
|
84
|
+
function getLangSmithEnvVarsMetadata() {
|
|
85
|
+
const allEnvVars = getLangSmithEnvironmentVariables();
|
|
114
86
|
const envVars = {};
|
|
115
87
|
const excluded = [
|
|
116
88
|
"LANGCHAIN_API_KEY",
|
|
@@ -125,8 +97,7 @@ function getLangChainEnvVarsMetadata() {
|
|
|
125
97
|
"LANGSMITH_SESSION",
|
|
126
98
|
];
|
|
127
99
|
for (const [key, value] of Object.entries(allEnvVars)) {
|
|
128
|
-
if (
|
|
129
|
-
typeof value === "string" &&
|
|
100
|
+
if (typeof value === "string" &&
|
|
130
101
|
!excluded.includes(key) &&
|
|
131
102
|
!key.toLowerCase().includes("key") &&
|
|
132
103
|
!key.toLowerCase().includes("secret") &&
|
|
@@ -142,34 +113,42 @@ function getLangChainEnvVarsMetadata() {
|
|
|
142
113
|
return envVars;
|
|
143
114
|
}
|
|
144
115
|
/**
|
|
145
|
-
* Retrieves the environment variables from the current runtime environment.
|
|
146
|
-
*
|
|
147
|
-
* This function is designed to operate in a variety of JS environments,
|
|
148
|
-
* including Node.js, Deno, browsers, etc.
|
|
116
|
+
* Retrieves only the LangChain/LangSmith-prefixed environment variables from the current runtime environment.
|
|
117
|
+
* This is more efficient than copying all environment variables.
|
|
149
118
|
*
|
|
150
|
-
* @returns {Record<string, string>
|
|
151
|
-
* - A record of environment variables
|
|
152
|
-
* - `undefined` if the environment does not support or allows access to environment variables.
|
|
119
|
+
* @returns {Record<string, string>}
|
|
120
|
+
* - A record of LangChain/LangSmith environment variables.
|
|
153
121
|
*/
|
|
154
|
-
function
|
|
122
|
+
function getLangSmithEnvironmentVariables() {
|
|
123
|
+
const envVars = {};
|
|
155
124
|
try {
|
|
156
125
|
// Check for Node.js environment
|
|
157
126
|
// eslint-disable-next-line no-process-env
|
|
158
127
|
if (typeof process !== "undefined" && process.env) {
|
|
159
128
|
// eslint-disable-next-line no-process-env
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
129
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
130
|
+
if ((key.startsWith("LANGCHAIN_") || key.startsWith("LANGSMITH_")) &&
|
|
131
|
+
value != null) {
|
|
132
|
+
if ((key.toLowerCase().includes("key") ||
|
|
133
|
+
key.toLowerCase().includes("secret") ||
|
|
134
|
+
key.toLowerCase().includes("token")) &&
|
|
135
|
+
typeof value === "string") {
|
|
136
|
+
envVars[key] =
|
|
137
|
+
value.slice(0, 2) +
|
|
138
|
+
"*".repeat(value.length - 4) +
|
|
139
|
+
value.slice(-2);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
envVars[key] = value;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
164
146
|
}
|
|
165
|
-
// For browsers and other environments, we may not have direct access to env variables
|
|
166
|
-
// Return undefined or any other fallback as required.
|
|
167
|
-
return undefined;
|
|
168
147
|
}
|
|
169
148
|
catch (e) {
|
|
170
149
|
// Catch any errors that might occur while trying to access environment variables
|
|
171
|
-
return undefined;
|
|
172
150
|
}
|
|
151
|
+
return envVars;
|
|
173
152
|
}
|
|
174
153
|
function getEnvironmentVariable(name) {
|
|
175
154
|
// Certain Deno setups will throw an error if you try to access environment variables
|
package/dist/utils/env.d.ts
CHANGED
|
@@ -21,31 +21,20 @@ export type RuntimeEnvironment = {
|
|
|
21
21
|
};
|
|
22
22
|
export declare function getRuntimeEnvironment(): RuntimeEnvironment;
|
|
23
23
|
/**
|
|
24
|
-
* Retrieves the
|
|
25
|
-
* Sensitive keys (containing the word "key", "token", or "secret") have their values redacted for security.
|
|
24
|
+
* Retrieves the LangSmith-specific metadata from the current runtime environment.
|
|
26
25
|
*
|
|
27
26
|
* @returns {Record<string, string>}
|
|
28
|
-
* - A record of
|
|
27
|
+
* - A record of LangSmith-specific metadata environment variables.
|
|
29
28
|
*/
|
|
30
|
-
export declare function
|
|
29
|
+
export declare function getLangSmithEnvVarsMetadata(): Record<string, string>;
|
|
31
30
|
/**
|
|
32
|
-
* Retrieves the LangChain-
|
|
31
|
+
* Retrieves only the LangChain/LangSmith-prefixed environment variables from the current runtime environment.
|
|
32
|
+
* This is more efficient than copying all environment variables.
|
|
33
33
|
*
|
|
34
34
|
* @returns {Record<string, string>}
|
|
35
|
-
* - A record of LangChain
|
|
35
|
+
* - A record of LangChain/LangSmith environment variables.
|
|
36
36
|
*/
|
|
37
|
-
export declare function
|
|
38
|
-
/**
|
|
39
|
-
* Retrieves the environment variables from the current runtime environment.
|
|
40
|
-
*
|
|
41
|
-
* This function is designed to operate in a variety of JS environments,
|
|
42
|
-
* including Node.js, Deno, browsers, etc.
|
|
43
|
-
*
|
|
44
|
-
* @returns {Record<string, string> | undefined}
|
|
45
|
-
* - A record of environment variables if available.
|
|
46
|
-
* - `undefined` if the environment does not support or allows access to environment variables.
|
|
47
|
-
*/
|
|
48
|
-
export declare function getEnvironmentVariables(): Record<string, string> | undefined;
|
|
37
|
+
export declare function getLangSmithEnvironmentVariables(): Record<string, string>;
|
|
49
38
|
export declare function getEnvironmentVariable(name: string): string | undefined;
|
|
50
39
|
export declare function getLangSmithEnvironmentVariable(name: string): string | undefined;
|
|
51
40
|
export declare function setEnvironmentVariable(name: string, value: string): void;
|
package/dist/utils/env.js
CHANGED
|
@@ -59,40 +59,13 @@ export function getRuntimeEnvironment() {
|
|
|
59
59
|
return runtimeEnvironment;
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
-
* Retrieves the
|
|
63
|
-
* Sensitive keys (containing the word "key", "token", or "secret") have their values redacted for security.
|
|
62
|
+
* Retrieves the LangSmith-specific metadata from the current runtime environment.
|
|
64
63
|
*
|
|
65
64
|
* @returns {Record<string, string>}
|
|
66
|
-
* - A record of
|
|
65
|
+
* - A record of LangSmith-specific metadata environment variables.
|
|
67
66
|
*/
|
|
68
|
-
export function
|
|
69
|
-
const allEnvVars =
|
|
70
|
-
const envVars = {};
|
|
71
|
-
for (const [key, value] of Object.entries(allEnvVars)) {
|
|
72
|
-
if (key.startsWith("LANGCHAIN_") && typeof value === "string") {
|
|
73
|
-
envVars[key] = value;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
for (const key in envVars) {
|
|
77
|
-
if ((key.toLowerCase().includes("key") ||
|
|
78
|
-
key.toLowerCase().includes("secret") ||
|
|
79
|
-
key.toLowerCase().includes("token")) &&
|
|
80
|
-
typeof envVars[key] === "string") {
|
|
81
|
-
const value = envVars[key];
|
|
82
|
-
envVars[key] =
|
|
83
|
-
value.slice(0, 2) + "*".repeat(value.length - 4) + value.slice(-2);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return envVars;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Retrieves the LangChain-specific metadata from the current runtime environment.
|
|
90
|
-
*
|
|
91
|
-
* @returns {Record<string, string>}
|
|
92
|
-
* - A record of LangChain-specific metadata environment variables.
|
|
93
|
-
*/
|
|
94
|
-
export function getLangChainEnvVarsMetadata() {
|
|
95
|
-
const allEnvVars = getEnvironmentVariables() || {};
|
|
67
|
+
export function getLangSmithEnvVarsMetadata() {
|
|
68
|
+
const allEnvVars = getLangSmithEnvironmentVariables();
|
|
96
69
|
const envVars = {};
|
|
97
70
|
const excluded = [
|
|
98
71
|
"LANGCHAIN_API_KEY",
|
|
@@ -107,8 +80,7 @@ export function getLangChainEnvVarsMetadata() {
|
|
|
107
80
|
"LANGSMITH_SESSION",
|
|
108
81
|
];
|
|
109
82
|
for (const [key, value] of Object.entries(allEnvVars)) {
|
|
110
|
-
if (
|
|
111
|
-
typeof value === "string" &&
|
|
83
|
+
if (typeof value === "string" &&
|
|
112
84
|
!excluded.includes(key) &&
|
|
113
85
|
!key.toLowerCase().includes("key") &&
|
|
114
86
|
!key.toLowerCase().includes("secret") &&
|
|
@@ -124,34 +96,42 @@ export function getLangChainEnvVarsMetadata() {
|
|
|
124
96
|
return envVars;
|
|
125
97
|
}
|
|
126
98
|
/**
|
|
127
|
-
* Retrieves the environment variables from the current runtime environment.
|
|
128
|
-
*
|
|
129
|
-
* This function is designed to operate in a variety of JS environments,
|
|
130
|
-
* including Node.js, Deno, browsers, etc.
|
|
99
|
+
* Retrieves only the LangChain/LangSmith-prefixed environment variables from the current runtime environment.
|
|
100
|
+
* This is more efficient than copying all environment variables.
|
|
131
101
|
*
|
|
132
|
-
* @returns {Record<string, string>
|
|
133
|
-
* - A record of environment variables
|
|
134
|
-
* - `undefined` if the environment does not support or allows access to environment variables.
|
|
102
|
+
* @returns {Record<string, string>}
|
|
103
|
+
* - A record of LangChain/LangSmith environment variables.
|
|
135
104
|
*/
|
|
136
|
-
export function
|
|
105
|
+
export function getLangSmithEnvironmentVariables() {
|
|
106
|
+
const envVars = {};
|
|
137
107
|
try {
|
|
138
108
|
// Check for Node.js environment
|
|
139
109
|
// eslint-disable-next-line no-process-env
|
|
140
110
|
if (typeof process !== "undefined" && process.env) {
|
|
141
111
|
// eslint-disable-next-line no-process-env
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
112
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
113
|
+
if ((key.startsWith("LANGCHAIN_") || key.startsWith("LANGSMITH_")) &&
|
|
114
|
+
value != null) {
|
|
115
|
+
if ((key.toLowerCase().includes("key") ||
|
|
116
|
+
key.toLowerCase().includes("secret") ||
|
|
117
|
+
key.toLowerCase().includes("token")) &&
|
|
118
|
+
typeof value === "string") {
|
|
119
|
+
envVars[key] =
|
|
120
|
+
value.slice(0, 2) +
|
|
121
|
+
"*".repeat(value.length - 4) +
|
|
122
|
+
value.slice(-2);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
envVars[key] = value;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
146
129
|
}
|
|
147
|
-
// For browsers and other environments, we may not have direct access to env variables
|
|
148
|
-
// Return undefined or any other fallback as required.
|
|
149
|
-
return undefined;
|
|
150
130
|
}
|
|
151
131
|
catch (e) {
|
|
152
132
|
// Catch any errors that might occur while trying to access environment variables
|
|
153
|
-
return undefined;
|
|
154
133
|
}
|
|
134
|
+
return envVars;
|
|
155
135
|
}
|
|
156
136
|
export function getEnvironmentVariable(name) {
|
|
157
137
|
// Certain Deno setups will throw an error if you try to access environment variables
|