langsmith 0.0.33 → 0.0.34
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/cli/main.cjs +24 -1
- package/dist/cli/main.js +25 -2
- package/dist/cli/main.ts +34 -2
- package/dist/client.cjs +39 -13
- package/dist/client.d.ts +5 -2
- package/dist/client.js +39 -13
- package/dist/utils/env.cjs +101 -1
- package/dist/utils/env.d.ts +24 -0
- package/dist/utils/env.js +97 -0
- package/package.json +1 -1
package/dist/cli/main.cjs
CHANGED
|
@@ -285,6 +285,22 @@ class SmithCommand {
|
|
|
285
285
|
console.info("The LangSmith server is not running.");
|
|
286
286
|
}
|
|
287
287
|
}
|
|
288
|
+
async env() {
|
|
289
|
+
const env = await (0, env_js_1.getRuntimeEnvironment)();
|
|
290
|
+
const dockerEnv = await (0, env_js_1.getDockerEnvironment)();
|
|
291
|
+
const envVars = await (0, env_js_1.getLangChainEnvVars)();
|
|
292
|
+
const envDict = {
|
|
293
|
+
...env,
|
|
294
|
+
...dockerEnv,
|
|
295
|
+
...envVars,
|
|
296
|
+
};
|
|
297
|
+
// Pretty print
|
|
298
|
+
const maxKeyLength = Math.max(...Object.keys(envDict).map((key) => key.length));
|
|
299
|
+
console.info("LangChain Environment:");
|
|
300
|
+
for (const [key, value] of Object.entries(envDict)) {
|
|
301
|
+
console.info(`${key.padEnd(maxKeyLength)}: ${value}`);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
288
304
|
}
|
|
289
305
|
const startCommand = new commander_1.Command("start")
|
|
290
306
|
.description("Start the LangSmith server")
|
|
@@ -338,10 +354,17 @@ const statusCommand = new commander_1.Command("status")
|
|
|
338
354
|
const smith = await SmithCommand.create();
|
|
339
355
|
await smith.status();
|
|
340
356
|
});
|
|
357
|
+
const envCommand = new commander_1.Command("env")
|
|
358
|
+
.description("Get relevant environment information for the LangSmith server")
|
|
359
|
+
.action(async () => {
|
|
360
|
+
const smith = await SmithCommand.create();
|
|
361
|
+
await smith.env();
|
|
362
|
+
});
|
|
341
363
|
program
|
|
342
364
|
.description("Manage the LangSmith server")
|
|
343
365
|
.addCommand(startCommand)
|
|
344
366
|
.addCommand(stopCommand)
|
|
345
367
|
.addCommand(pullCommand)
|
|
346
|
-
.addCommand(statusCommand)
|
|
368
|
+
.addCommand(statusCommand)
|
|
369
|
+
.addCommand(envCommand);
|
|
347
370
|
program.parse(process.argv);
|
package/dist/cli/main.js
CHANGED
|
@@ -3,7 +3,7 @@ import * as path from "path";
|
|
|
3
3
|
import * as util from "util";
|
|
4
4
|
import { Command } from "commander";
|
|
5
5
|
import * as child_process from "child_process";
|
|
6
|
-
import { setEnvironmentVariable } from "../utils/env.js";
|
|
6
|
+
import { getDockerEnvironment, getLangChainEnvVars, getRuntimeEnvironment, setEnvironmentVariable, } from "../utils/env.js";
|
|
7
7
|
import { spawn } from "child_process";
|
|
8
8
|
const currentFileName = __filename;
|
|
9
9
|
const currentDirName = __dirname;
|
|
@@ -259,6 +259,22 @@ class SmithCommand {
|
|
|
259
259
|
console.info("The LangSmith server is not running.");
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
|
+
async env() {
|
|
263
|
+
const env = await getRuntimeEnvironment();
|
|
264
|
+
const dockerEnv = await getDockerEnvironment();
|
|
265
|
+
const envVars = await getLangChainEnvVars();
|
|
266
|
+
const envDict = {
|
|
267
|
+
...env,
|
|
268
|
+
...dockerEnv,
|
|
269
|
+
...envVars,
|
|
270
|
+
};
|
|
271
|
+
// Pretty print
|
|
272
|
+
const maxKeyLength = Math.max(...Object.keys(envDict).map((key) => key.length));
|
|
273
|
+
console.info("LangChain Environment:");
|
|
274
|
+
for (const [key, value] of Object.entries(envDict)) {
|
|
275
|
+
console.info(`${key.padEnd(maxKeyLength)}: ${value}`);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
262
278
|
}
|
|
263
279
|
const startCommand = new Command("start")
|
|
264
280
|
.description("Start the LangSmith server")
|
|
@@ -312,10 +328,17 @@ const statusCommand = new Command("status")
|
|
|
312
328
|
const smith = await SmithCommand.create();
|
|
313
329
|
await smith.status();
|
|
314
330
|
});
|
|
331
|
+
const envCommand = new Command("env")
|
|
332
|
+
.description("Get relevant environment information for the LangSmith server")
|
|
333
|
+
.action(async () => {
|
|
334
|
+
const smith = await SmithCommand.create();
|
|
335
|
+
await smith.env();
|
|
336
|
+
});
|
|
315
337
|
program
|
|
316
338
|
.description("Manage the LangSmith server")
|
|
317
339
|
.addCommand(startCommand)
|
|
318
340
|
.addCommand(stopCommand)
|
|
319
341
|
.addCommand(pullCommand)
|
|
320
|
-
.addCommand(statusCommand)
|
|
342
|
+
.addCommand(statusCommand)
|
|
343
|
+
.addCommand(envCommand);
|
|
321
344
|
program.parse(process.argv);
|
package/dist/cli/main.ts
CHANGED
|
@@ -3,7 +3,12 @@ import * as path from "path";
|
|
|
3
3
|
import * as util from "util";
|
|
4
4
|
import { Command } from "commander";
|
|
5
5
|
import * as child_process from "child_process";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
getDockerEnvironment,
|
|
8
|
+
getLangChainEnvVars,
|
|
9
|
+
getRuntimeEnvironment,
|
|
10
|
+
setEnvironmentVariable,
|
|
11
|
+
} from "../utils/env.js";
|
|
7
12
|
import { spawn } from "child_process";
|
|
8
13
|
|
|
9
14
|
const currentFileName = __filename;
|
|
@@ -287,6 +292,25 @@ class SmithCommand {
|
|
|
287
292
|
console.info("The LangSmith server is not running.");
|
|
288
293
|
}
|
|
289
294
|
}
|
|
295
|
+
|
|
296
|
+
async env() {
|
|
297
|
+
const env = await getRuntimeEnvironment();
|
|
298
|
+
const dockerEnv = await getDockerEnvironment();
|
|
299
|
+
const envVars = await getLangChainEnvVars();
|
|
300
|
+
const envDict = {
|
|
301
|
+
...env,
|
|
302
|
+
...dockerEnv,
|
|
303
|
+
...envVars,
|
|
304
|
+
};
|
|
305
|
+
// Pretty print
|
|
306
|
+
const maxKeyLength = Math.max(
|
|
307
|
+
...Object.keys(envDict).map((key) => key.length)
|
|
308
|
+
);
|
|
309
|
+
console.info("LangChain Environment:");
|
|
310
|
+
for (const [key, value] of Object.entries(envDict)) {
|
|
311
|
+
console.info(`${key.padEnd(maxKeyLength)}: ${value}`);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
290
314
|
}
|
|
291
315
|
|
|
292
316
|
const startCommand = new Command("start")
|
|
@@ -357,11 +381,19 @@ const statusCommand = new Command("status")
|
|
|
357
381
|
await smith.status();
|
|
358
382
|
});
|
|
359
383
|
|
|
384
|
+
const envCommand = new Command("env")
|
|
385
|
+
.description("Get relevant environment information for the LangSmith server")
|
|
386
|
+
.action(async () => {
|
|
387
|
+
const smith = await SmithCommand.create();
|
|
388
|
+
await smith.env();
|
|
389
|
+
});
|
|
390
|
+
|
|
360
391
|
program
|
|
361
392
|
.description("Manage the LangSmith server")
|
|
362
393
|
.addCommand(startCommand)
|
|
363
394
|
.addCommand(stopCommand)
|
|
364
395
|
.addCommand(pullCommand)
|
|
365
|
-
.addCommand(statusCommand)
|
|
396
|
+
.addCommand(statusCommand)
|
|
397
|
+
.addCommand(envCommand);
|
|
366
398
|
|
|
367
399
|
program.parse(process.argv);
|
package/dist/client.cjs
CHANGED
|
@@ -57,6 +57,18 @@ function trimQuotes(str) {
|
|
|
57
57
|
.replace(/^"(.*)"$/, "$1")
|
|
58
58
|
.replace(/^'(.*)'$/, "$1");
|
|
59
59
|
}
|
|
60
|
+
function hideInputs(inputs) {
|
|
61
|
+
if ((0, env_js_1.getEnvironmentVariable)("LANGCHAIN_HIDE_INPUTS") === "true") {
|
|
62
|
+
return {};
|
|
63
|
+
}
|
|
64
|
+
return inputs;
|
|
65
|
+
}
|
|
66
|
+
function hideOutputs(outputs) {
|
|
67
|
+
if ((0, env_js_1.getEnvironmentVariable)("LANGCHAIN_HIDE_OUTPUTS") === "true") {
|
|
68
|
+
return {};
|
|
69
|
+
}
|
|
70
|
+
return outputs;
|
|
71
|
+
}
|
|
60
72
|
class Client {
|
|
61
73
|
constructor(config = {}) {
|
|
62
74
|
Object.defineProperty(this, "apiKey", {
|
|
@@ -179,6 +191,10 @@ class Client {
|
|
|
179
191
|
},
|
|
180
192
|
},
|
|
181
193
|
};
|
|
194
|
+
runCreate.inputs = hideInputs(runCreate.inputs);
|
|
195
|
+
if (runCreate.outputs) {
|
|
196
|
+
runCreate.outputs = hideOutputs(runCreate.outputs);
|
|
197
|
+
}
|
|
182
198
|
const response = await this.caller.call(fetch, `${this.apiUrl}/runs`, {
|
|
183
199
|
method: "POST",
|
|
184
200
|
headers,
|
|
@@ -188,6 +204,12 @@ class Client {
|
|
|
188
204
|
await raiseForStatus(response, "create run");
|
|
189
205
|
}
|
|
190
206
|
async updateRun(runId, run) {
|
|
207
|
+
if (run.inputs) {
|
|
208
|
+
run.inputs = hideInputs(run.inputs);
|
|
209
|
+
}
|
|
210
|
+
if (run.outputs) {
|
|
211
|
+
run.outputs = hideOutputs(run.outputs);
|
|
212
|
+
}
|
|
191
213
|
const headers = { ...this.headers, "Content-Type": "application/json" };
|
|
192
214
|
const response = await this.caller.call(fetch, `${this.apiUrl}/runs/${runId}`, {
|
|
193
215
|
method: "PATCH",
|
|
@@ -670,20 +692,14 @@ class Client {
|
|
|
670
692
|
comment: feedbackResult.comment,
|
|
671
693
|
correction: feedbackResult.correction,
|
|
672
694
|
sourceInfo: sourceInfo_,
|
|
673
|
-
feedbackSourceType: "
|
|
695
|
+
feedbackSourceType: "model",
|
|
674
696
|
});
|
|
675
697
|
}
|
|
676
|
-
async createFeedback(runId, key, { score, value, correction, comment, sourceInfo, feedbackSourceType = "
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
}
|
|
681
|
-
else if (feedbackSourceType === "MODEL") {
|
|
682
|
-
feedback_source = { type: "model", metadata: sourceInfo ?? {} };
|
|
683
|
-
}
|
|
684
|
-
else {
|
|
685
|
-
throw new Error(`Unknown feedback source type ${feedbackSourceType}`);
|
|
686
|
-
}
|
|
698
|
+
async createFeedback(runId, key, { score, value, correction, comment, sourceInfo, feedbackSourceType = "api", sourceRunId, }) {
|
|
699
|
+
const feedback_source = {
|
|
700
|
+
type: feedbackSourceType ?? "api",
|
|
701
|
+
metadata: sourceInfo ?? {},
|
|
702
|
+
};
|
|
687
703
|
if (sourceRunId !== undefined &&
|
|
688
704
|
feedback_source?.metadata !== undefined &&
|
|
689
705
|
!feedback_source.metadata["__run"]) {
|
|
@@ -750,11 +766,21 @@ class Client {
|
|
|
750
766
|
}
|
|
751
767
|
await response.json();
|
|
752
768
|
}
|
|
753
|
-
async *listFeedback({ runIds, } = {}) {
|
|
769
|
+
async *listFeedback({ runIds, feedbackKeys, feedbackSourceTypes, } = {}) {
|
|
754
770
|
const queryParams = new URLSearchParams();
|
|
755
771
|
if (runIds) {
|
|
756
772
|
queryParams.append("run", runIds.join(","));
|
|
757
773
|
}
|
|
774
|
+
if (feedbackKeys) {
|
|
775
|
+
for (const key of feedbackKeys) {
|
|
776
|
+
queryParams.append("key", key);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
if (feedbackSourceTypes) {
|
|
780
|
+
for (const type of feedbackSourceTypes) {
|
|
781
|
+
queryParams.append("source", type);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
758
784
|
for await (const feedbacks of this._getPaginated("/feedback", queryParams)) {
|
|
759
785
|
yield* feedbacks;
|
|
760
786
|
}
|
package/dist/client.d.ts
CHANGED
|
@@ -48,6 +48,7 @@ interface CreateRunParams {
|
|
|
48
48
|
parent_run_id?: string;
|
|
49
49
|
project_name?: string;
|
|
50
50
|
}
|
|
51
|
+
export type FeedbackSourceType = "model" | "api" | "app";
|
|
51
52
|
export declare class Client {
|
|
52
53
|
private apiKey?;
|
|
53
54
|
private apiUrl;
|
|
@@ -142,7 +143,7 @@ export declare class Client {
|
|
|
142
143
|
correction?: object;
|
|
143
144
|
comment?: string;
|
|
144
145
|
sourceInfo?: object;
|
|
145
|
-
feedbackSourceType?:
|
|
146
|
+
feedbackSourceType?: FeedbackSourceType;
|
|
146
147
|
sourceRunId?: string;
|
|
147
148
|
}): Promise<Feedback>;
|
|
148
149
|
updateFeedback(feedbackId: string, { score, value, correction, comment, }: {
|
|
@@ -153,8 +154,10 @@ export declare class Client {
|
|
|
153
154
|
}): Promise<Feedback>;
|
|
154
155
|
readFeedback(feedbackId: string): Promise<Feedback>;
|
|
155
156
|
deleteFeedback(feedbackId: string): Promise<void>;
|
|
156
|
-
listFeedback({ runIds, }?: {
|
|
157
|
+
listFeedback({ runIds, feedbackKeys, feedbackSourceTypes, }?: {
|
|
157
158
|
runIds?: string[];
|
|
159
|
+
feedbackKeys?: string[];
|
|
160
|
+
feedbackSourceTypes?: FeedbackSourceType[];
|
|
158
161
|
}): AsyncIterable<Feedback>;
|
|
159
162
|
}
|
|
160
163
|
export {};
|
package/dist/client.js
CHANGED
|
@@ -31,6 +31,18 @@ function trimQuotes(str) {
|
|
|
31
31
|
.replace(/^"(.*)"$/, "$1")
|
|
32
32
|
.replace(/^'(.*)'$/, "$1");
|
|
33
33
|
}
|
|
34
|
+
function hideInputs(inputs) {
|
|
35
|
+
if (getEnvironmentVariable("LANGCHAIN_HIDE_INPUTS") === "true") {
|
|
36
|
+
return {};
|
|
37
|
+
}
|
|
38
|
+
return inputs;
|
|
39
|
+
}
|
|
40
|
+
function hideOutputs(outputs) {
|
|
41
|
+
if (getEnvironmentVariable("LANGCHAIN_HIDE_OUTPUTS") === "true") {
|
|
42
|
+
return {};
|
|
43
|
+
}
|
|
44
|
+
return outputs;
|
|
45
|
+
}
|
|
34
46
|
export class Client {
|
|
35
47
|
constructor(config = {}) {
|
|
36
48
|
Object.defineProperty(this, "apiKey", {
|
|
@@ -153,6 +165,10 @@ export class Client {
|
|
|
153
165
|
},
|
|
154
166
|
},
|
|
155
167
|
};
|
|
168
|
+
runCreate.inputs = hideInputs(runCreate.inputs);
|
|
169
|
+
if (runCreate.outputs) {
|
|
170
|
+
runCreate.outputs = hideOutputs(runCreate.outputs);
|
|
171
|
+
}
|
|
156
172
|
const response = await this.caller.call(fetch, `${this.apiUrl}/runs`, {
|
|
157
173
|
method: "POST",
|
|
158
174
|
headers,
|
|
@@ -162,6 +178,12 @@ export class Client {
|
|
|
162
178
|
await raiseForStatus(response, "create run");
|
|
163
179
|
}
|
|
164
180
|
async updateRun(runId, run) {
|
|
181
|
+
if (run.inputs) {
|
|
182
|
+
run.inputs = hideInputs(run.inputs);
|
|
183
|
+
}
|
|
184
|
+
if (run.outputs) {
|
|
185
|
+
run.outputs = hideOutputs(run.outputs);
|
|
186
|
+
}
|
|
165
187
|
const headers = { ...this.headers, "Content-Type": "application/json" };
|
|
166
188
|
const response = await this.caller.call(fetch, `${this.apiUrl}/runs/${runId}`, {
|
|
167
189
|
method: "PATCH",
|
|
@@ -644,20 +666,14 @@ export class Client {
|
|
|
644
666
|
comment: feedbackResult.comment,
|
|
645
667
|
correction: feedbackResult.correction,
|
|
646
668
|
sourceInfo: sourceInfo_,
|
|
647
|
-
feedbackSourceType: "
|
|
669
|
+
feedbackSourceType: "model",
|
|
648
670
|
});
|
|
649
671
|
}
|
|
650
|
-
async createFeedback(runId, key, { score, value, correction, comment, sourceInfo, feedbackSourceType = "
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
}
|
|
655
|
-
else if (feedbackSourceType === "MODEL") {
|
|
656
|
-
feedback_source = { type: "model", metadata: sourceInfo ?? {} };
|
|
657
|
-
}
|
|
658
|
-
else {
|
|
659
|
-
throw new Error(`Unknown feedback source type ${feedbackSourceType}`);
|
|
660
|
-
}
|
|
672
|
+
async createFeedback(runId, key, { score, value, correction, comment, sourceInfo, feedbackSourceType = "api", sourceRunId, }) {
|
|
673
|
+
const feedback_source = {
|
|
674
|
+
type: feedbackSourceType ?? "api",
|
|
675
|
+
metadata: sourceInfo ?? {},
|
|
676
|
+
};
|
|
661
677
|
if (sourceRunId !== undefined &&
|
|
662
678
|
feedback_source?.metadata !== undefined &&
|
|
663
679
|
!feedback_source.metadata["__run"]) {
|
|
@@ -724,11 +740,21 @@ export class Client {
|
|
|
724
740
|
}
|
|
725
741
|
await response.json();
|
|
726
742
|
}
|
|
727
|
-
async *listFeedback({ runIds, } = {}) {
|
|
743
|
+
async *listFeedback({ runIds, feedbackKeys, feedbackSourceTypes, } = {}) {
|
|
728
744
|
const queryParams = new URLSearchParams();
|
|
729
745
|
if (runIds) {
|
|
730
746
|
queryParams.append("run", runIds.join(","));
|
|
731
747
|
}
|
|
748
|
+
if (feedbackKeys) {
|
|
749
|
+
for (const key of feedbackKeys) {
|
|
750
|
+
queryParams.append("key", key);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
if (feedbackSourceTypes) {
|
|
754
|
+
for (const type of feedbackSourceTypes) {
|
|
755
|
+
queryParams.append("source", type);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
732
758
|
for await (const feedbacks of this._getPaginated("/feedback", queryParams)) {
|
|
733
759
|
yield* feedbacks;
|
|
734
760
|
}
|
package/dist/utils/env.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getShas = exports.setEnvironmentVariable = exports.getEnvironmentVariable = exports.getRuntimeEnvironment = exports.getEnv = exports.isNode = exports.isDeno = exports.isJsDom = exports.isWebWorker = exports.isBrowser = void 0;
|
|
3
|
+
exports.getShas = exports.setEnvironmentVariable = exports.getEnvironmentVariable = exports.getEnvironmentVariables = exports.getLangChainEnvVars = exports.getDockerEnvironment = exports.getRuntimeEnvironment = exports.getEnv = exports.isNode = exports.isDeno = exports.isJsDom = exports.isWebWorker = exports.isBrowser = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
4
5
|
const isBrowser = () => typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
5
6
|
exports.isBrowser = isBrowser;
|
|
6
7
|
const isWebWorker = () => typeof globalThis === "object" &&
|
|
@@ -59,6 +60,105 @@ async function getRuntimeEnvironment() {
|
|
|
59
60
|
return runtimeEnvironment;
|
|
60
61
|
}
|
|
61
62
|
exports.getRuntimeEnvironment = getRuntimeEnvironment;
|
|
63
|
+
async function getDockerEnvironment() {
|
|
64
|
+
const getDockerVersion = () => new Promise((resolve) => {
|
|
65
|
+
(0, child_process_1.exec)("docker --version", (error, stdout) => {
|
|
66
|
+
if (error) {
|
|
67
|
+
resolve(undefined);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
resolve(stdout.trim());
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
const getDockerComposeCommand = () => new Promise((resolve) => {
|
|
75
|
+
(0, child_process_1.exec)("which docker-compose", (error, stdout) => {
|
|
76
|
+
if (error) {
|
|
77
|
+
resolve(undefined);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
resolve(stdout.trim());
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
const getDockerComposeVersion = () => new Promise((resolve) => {
|
|
85
|
+
(0, child_process_1.exec)("docker-compose --version", (error, stdout) => {
|
|
86
|
+
if (error) {
|
|
87
|
+
resolve(undefined);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
resolve(stdout.trim());
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
const [dockerVersion, dockerComposeCommand, dockerComposeVersion] = await Promise.all([
|
|
95
|
+
getDockerVersion(),
|
|
96
|
+
getDockerComposeCommand(),
|
|
97
|
+
getDockerComposeVersion(),
|
|
98
|
+
]);
|
|
99
|
+
return {
|
|
100
|
+
dockerVersion,
|
|
101
|
+
dockerComposeCommand,
|
|
102
|
+
dockerComposeVersion,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
exports.getDockerEnvironment = getDockerEnvironment;
|
|
106
|
+
/**
|
|
107
|
+
* Retrieves the LangChain-specific environment variables from the current runtime environment.
|
|
108
|
+
* Sensitive keys (containing the word "key") have their values redacted for security.
|
|
109
|
+
*
|
|
110
|
+
* @returns {Record<string, string>}
|
|
111
|
+
* - A record of LangChain-specific environment variables.
|
|
112
|
+
*/
|
|
113
|
+
function getLangChainEnvVars() {
|
|
114
|
+
const allEnvVars = getEnvironmentVariables() || {};
|
|
115
|
+
const envVars = {};
|
|
116
|
+
for (const [key, value] of Object.entries(allEnvVars)) {
|
|
117
|
+
if (key.startsWith("LANGCHAIN_") && typeof value === "string") {
|
|
118
|
+
envVars[key] = value;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
for (const key in envVars) {
|
|
122
|
+
if (key.toLowerCase().includes("key") && typeof envVars[key] === "string") {
|
|
123
|
+
const value = envVars[key];
|
|
124
|
+
envVars[key] =
|
|
125
|
+
value.slice(0, 2) + "*".repeat(value.length - 4) + value.slice(-2);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return envVars;
|
|
129
|
+
}
|
|
130
|
+
exports.getLangChainEnvVars = getLangChainEnvVars;
|
|
131
|
+
/**
|
|
132
|
+
* Retrieves the environment variables from the current runtime environment.
|
|
133
|
+
*
|
|
134
|
+
* This function is designed to operate in a variety of JS environments,
|
|
135
|
+
* including Node.js, Deno, browsers, etc.
|
|
136
|
+
*
|
|
137
|
+
* @returns {Record<string, string> | undefined}
|
|
138
|
+
* - A record of environment variables if available.
|
|
139
|
+
* - `undefined` if the environment does not support or allows access to environment variables.
|
|
140
|
+
*/
|
|
141
|
+
function getEnvironmentVariables() {
|
|
142
|
+
try {
|
|
143
|
+
// Check for Node.js environment
|
|
144
|
+
// eslint-disable-next-line no-process-env
|
|
145
|
+
if (typeof process !== "undefined" && process.env) {
|
|
146
|
+
// eslint-disable-next-line no-process-env
|
|
147
|
+
Object.entries(process.env).reduce((acc, [key, value]) => {
|
|
148
|
+
acc[key] = String(value);
|
|
149
|
+
return acc;
|
|
150
|
+
}, {});
|
|
151
|
+
}
|
|
152
|
+
// For browsers and other environments, we may not have direct access to env variables
|
|
153
|
+
// Return undefined or any other fallback as required.
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
catch (e) {
|
|
157
|
+
// Catch any errors that might occur while trying to access environment variables
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
exports.getEnvironmentVariables = getEnvironmentVariables;
|
|
62
162
|
function getEnvironmentVariable(name) {
|
|
63
163
|
// Certain Deno setups will throw an error if you try to access environment variables
|
|
64
164
|
// https://github.com/hwchase17/langchainjs/issues/1412
|
package/dist/utils/env.d.ts
CHANGED
|
@@ -18,6 +18,30 @@ export type RuntimeEnvironment = {
|
|
|
18
18
|
runtimeVersion?: string;
|
|
19
19
|
};
|
|
20
20
|
export declare function getRuntimeEnvironment(): Promise<RuntimeEnvironment>;
|
|
21
|
+
export declare function getDockerEnvironment(): Promise<{
|
|
22
|
+
dockerVersion: string | undefined;
|
|
23
|
+
dockerComposeCommand: string | undefined;
|
|
24
|
+
dockerComposeVersion: string | undefined;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Retrieves the LangChain-specific environment variables from the current runtime environment.
|
|
28
|
+
* Sensitive keys (containing the word "key") have their values redacted for security.
|
|
29
|
+
*
|
|
30
|
+
* @returns {Record<string, string>}
|
|
31
|
+
* - A record of LangChain-specific environment variables.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getLangChainEnvVars(): Record<string, string>;
|
|
34
|
+
/**
|
|
35
|
+
* Retrieves the environment variables from the current runtime environment.
|
|
36
|
+
*
|
|
37
|
+
* This function is designed to operate in a variety of JS environments,
|
|
38
|
+
* including Node.js, Deno, browsers, etc.
|
|
39
|
+
*
|
|
40
|
+
* @returns {Record<string, string> | undefined}
|
|
41
|
+
* - A record of environment variables if available.
|
|
42
|
+
* - `undefined` if the environment does not support or allows access to environment variables.
|
|
43
|
+
*/
|
|
44
|
+
export declare function getEnvironmentVariables(): Record<string, string> | undefined;
|
|
21
45
|
export declare function getEnvironmentVariable(name: string): string | undefined;
|
|
22
46
|
export declare function setEnvironmentVariable(name: string, value: string): void;
|
|
23
47
|
interface ICommitSHAs {
|
package/dist/utils/env.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { exec } from "child_process";
|
|
1
2
|
export const isBrowser = () => typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
2
3
|
export const isWebWorker = () => typeof globalThis === "object" &&
|
|
3
4
|
globalThis.constructor &&
|
|
@@ -49,6 +50,102 @@ export async function getRuntimeEnvironment() {
|
|
|
49
50
|
}
|
|
50
51
|
return runtimeEnvironment;
|
|
51
52
|
}
|
|
53
|
+
export async function getDockerEnvironment() {
|
|
54
|
+
const getDockerVersion = () => new Promise((resolve) => {
|
|
55
|
+
exec("docker --version", (error, stdout) => {
|
|
56
|
+
if (error) {
|
|
57
|
+
resolve(undefined);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
resolve(stdout.trim());
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
const getDockerComposeCommand = () => new Promise((resolve) => {
|
|
65
|
+
exec("which docker-compose", (error, stdout) => {
|
|
66
|
+
if (error) {
|
|
67
|
+
resolve(undefined);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
resolve(stdout.trim());
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
const getDockerComposeVersion = () => new Promise((resolve) => {
|
|
75
|
+
exec("docker-compose --version", (error, stdout) => {
|
|
76
|
+
if (error) {
|
|
77
|
+
resolve(undefined);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
resolve(stdout.trim());
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
const [dockerVersion, dockerComposeCommand, dockerComposeVersion] = await Promise.all([
|
|
85
|
+
getDockerVersion(),
|
|
86
|
+
getDockerComposeCommand(),
|
|
87
|
+
getDockerComposeVersion(),
|
|
88
|
+
]);
|
|
89
|
+
return {
|
|
90
|
+
dockerVersion,
|
|
91
|
+
dockerComposeCommand,
|
|
92
|
+
dockerComposeVersion,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Retrieves the LangChain-specific environment variables from the current runtime environment.
|
|
97
|
+
* Sensitive keys (containing the word "key") have their values redacted for security.
|
|
98
|
+
*
|
|
99
|
+
* @returns {Record<string, string>}
|
|
100
|
+
* - A record of LangChain-specific environment variables.
|
|
101
|
+
*/
|
|
102
|
+
export function getLangChainEnvVars() {
|
|
103
|
+
const allEnvVars = getEnvironmentVariables() || {};
|
|
104
|
+
const envVars = {};
|
|
105
|
+
for (const [key, value] of Object.entries(allEnvVars)) {
|
|
106
|
+
if (key.startsWith("LANGCHAIN_") && typeof value === "string") {
|
|
107
|
+
envVars[key] = value;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
for (const key in envVars) {
|
|
111
|
+
if (key.toLowerCase().includes("key") && typeof envVars[key] === "string") {
|
|
112
|
+
const value = envVars[key];
|
|
113
|
+
envVars[key] =
|
|
114
|
+
value.slice(0, 2) + "*".repeat(value.length - 4) + value.slice(-2);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return envVars;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Retrieves the environment variables from the current runtime environment.
|
|
121
|
+
*
|
|
122
|
+
* This function is designed to operate in a variety of JS environments,
|
|
123
|
+
* including Node.js, Deno, browsers, etc.
|
|
124
|
+
*
|
|
125
|
+
* @returns {Record<string, string> | undefined}
|
|
126
|
+
* - A record of environment variables if available.
|
|
127
|
+
* - `undefined` if the environment does not support or allows access to environment variables.
|
|
128
|
+
*/
|
|
129
|
+
export function getEnvironmentVariables() {
|
|
130
|
+
try {
|
|
131
|
+
// Check for Node.js environment
|
|
132
|
+
// eslint-disable-next-line no-process-env
|
|
133
|
+
if (typeof process !== "undefined" && process.env) {
|
|
134
|
+
// eslint-disable-next-line no-process-env
|
|
135
|
+
Object.entries(process.env).reduce((acc, [key, value]) => {
|
|
136
|
+
acc[key] = String(value);
|
|
137
|
+
return acc;
|
|
138
|
+
}, {});
|
|
139
|
+
}
|
|
140
|
+
// For browsers and other environments, we may not have direct access to env variables
|
|
141
|
+
// Return undefined or any other fallback as required.
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
catch (e) {
|
|
145
|
+
// Catch any errors that might occur while trying to access environment variables
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
52
149
|
export function getEnvironmentVariable(name) {
|
|
53
150
|
// Certain Deno setups will throw an error if you try to access environment variables
|
|
54
151
|
// https://github.com/hwchase17/langchainjs/issues/1412
|