langsmith 0.0.33 → 0.0.35

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 CHANGED
@@ -285,6 +285,20 @@ 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 envVars = await (0, env_js_1.getLangChainEnvVars)();
291
+ const envDict = {
292
+ ...env,
293
+ ...envVars,
294
+ };
295
+ // Pretty print
296
+ const maxKeyLength = Math.max(...Object.keys(envDict).map((key) => key.length));
297
+ console.info("LangChain Environment:");
298
+ for (const [key, value] of Object.entries(envDict)) {
299
+ console.info(`${key.padEnd(maxKeyLength)}: ${value}`);
300
+ }
301
+ }
288
302
  }
289
303
  const startCommand = new commander_1.Command("start")
290
304
  .description("Start the LangSmith server")
@@ -338,10 +352,17 @@ const statusCommand = new commander_1.Command("status")
338
352
  const smith = await SmithCommand.create();
339
353
  await smith.status();
340
354
  });
355
+ const envCommand = new commander_1.Command("env")
356
+ .description("Get relevant environment information for the LangSmith server")
357
+ .action(async () => {
358
+ const smith = await SmithCommand.create();
359
+ await smith.env();
360
+ });
341
361
  program
342
362
  .description("Manage the LangSmith server")
343
363
  .addCommand(startCommand)
344
364
  .addCommand(stopCommand)
345
365
  .addCommand(pullCommand)
346
- .addCommand(statusCommand);
366
+ .addCommand(statusCommand)
367
+ .addCommand(envCommand);
347
368
  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 { 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,20 @@ 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 envVars = await getLangChainEnvVars();
265
+ const envDict = {
266
+ ...env,
267
+ ...envVars,
268
+ };
269
+ // Pretty print
270
+ const maxKeyLength = Math.max(...Object.keys(envDict).map((key) => key.length));
271
+ console.info("LangChain Environment:");
272
+ for (const [key, value] of Object.entries(envDict)) {
273
+ console.info(`${key.padEnd(maxKeyLength)}: ${value}`);
274
+ }
275
+ }
262
276
  }
263
277
  const startCommand = new Command("start")
264
278
  .description("Start the LangSmith server")
@@ -312,10 +326,17 @@ const statusCommand = new Command("status")
312
326
  const smith = await SmithCommand.create();
313
327
  await smith.status();
314
328
  });
329
+ const envCommand = new Command("env")
330
+ .description("Get relevant environment information for the LangSmith server")
331
+ .action(async () => {
332
+ const smith = await SmithCommand.create();
333
+ await smith.env();
334
+ });
315
335
  program
316
336
  .description("Manage the LangSmith server")
317
337
  .addCommand(startCommand)
318
338
  .addCommand(stopCommand)
319
339
  .addCommand(pullCommand)
320
- .addCommand(statusCommand);
340
+ .addCommand(statusCommand)
341
+ .addCommand(envCommand);
321
342
  program.parse(process.argv);
package/dist/cli/main.ts CHANGED
@@ -3,7 +3,11 @@ 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 {
7
+ getLangChainEnvVars,
8
+ getRuntimeEnvironment,
9
+ setEnvironmentVariable,
10
+ } from "../utils/env.js";
7
11
  import { spawn } from "child_process";
8
12
 
9
13
  const currentFileName = __filename;
@@ -287,6 +291,23 @@ class SmithCommand {
287
291
  console.info("The LangSmith server is not running.");
288
292
  }
289
293
  }
294
+
295
+ async env() {
296
+ const env = await getRuntimeEnvironment();
297
+ const envVars = await getLangChainEnvVars();
298
+ const envDict = {
299
+ ...env,
300
+ ...envVars,
301
+ };
302
+ // Pretty print
303
+ const maxKeyLength = Math.max(
304
+ ...Object.keys(envDict).map((key) => key.length)
305
+ );
306
+ console.info("LangChain Environment:");
307
+ for (const [key, value] of Object.entries(envDict)) {
308
+ console.info(`${key.padEnd(maxKeyLength)}: ${value}`);
309
+ }
310
+ }
290
311
  }
291
312
 
292
313
  const startCommand = new Command("start")
@@ -357,11 +378,19 @@ const statusCommand = new Command("status")
357
378
  await smith.status();
358
379
  });
359
380
 
381
+ const envCommand = new Command("env")
382
+ .description("Get relevant environment information for the LangSmith server")
383
+ .action(async () => {
384
+ const smith = await SmithCommand.create();
385
+ await smith.env();
386
+ });
387
+
360
388
  program
361
389
  .description("Manage the LangSmith server")
362
390
  .addCommand(startCommand)
363
391
  .addCommand(stopCommand)
364
392
  .addCommand(pullCommand)
365
- .addCommand(statusCommand);
393
+ .addCommand(statusCommand)
394
+ .addCommand(envCommand);
366
395
 
367
396
  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: "MODEL",
695
+ feedbackSourceType: "model",
674
696
  });
675
697
  }
676
- async createFeedback(runId, key, { score, value, correction, comment, sourceInfo, feedbackSourceType = "API", sourceRunId, }) {
677
- let feedback_source;
678
- if (feedbackSourceType === "API") {
679
- feedback_source = { type: "api", metadata: sourceInfo ?? {} };
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?: "API" | "MODEL";
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: "MODEL",
669
+ feedbackSourceType: "model",
648
670
  });
649
671
  }
650
- async createFeedback(runId, key, { score, value, correction, comment, sourceInfo, feedbackSourceType = "API", sourceRunId, }) {
651
- let feedback_source;
652
- if (feedbackSourceType === "API") {
653
- feedback_source = { type: "api", metadata: sourceInfo ?? {} };
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
  }
@@ -1,6 +1,6 @@
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.getRuntimeEnvironment = exports.getEnv = exports.isNode = exports.isDeno = exports.isJsDom = exports.isWebWorker = exports.isBrowser = void 0;
4
4
  const isBrowser = () => typeof window !== "undefined" && typeof window.document !== "undefined";
5
5
  exports.isBrowser = isBrowser;
6
6
  const isWebWorker = () => typeof globalThis === "object" &&
@@ -59,6 +59,62 @@ async function getRuntimeEnvironment() {
59
59
  return runtimeEnvironment;
60
60
  }
61
61
  exports.getRuntimeEnvironment = getRuntimeEnvironment;
62
+ /**
63
+ * Retrieves the LangChain-specific environment variables from the current runtime environment.
64
+ * Sensitive keys (containing the word "key") have their values redacted for security.
65
+ *
66
+ * @returns {Record<string, string>}
67
+ * - A record of LangChain-specific environment variables.
68
+ */
69
+ function getLangChainEnvVars() {
70
+ const allEnvVars = getEnvironmentVariables() || {};
71
+ const envVars = {};
72
+ for (const [key, value] of Object.entries(allEnvVars)) {
73
+ if (key.startsWith("LANGCHAIN_") && typeof value === "string") {
74
+ envVars[key] = value;
75
+ }
76
+ }
77
+ for (const key in envVars) {
78
+ if (key.toLowerCase().includes("key") && typeof envVars[key] === "string") {
79
+ const value = envVars[key];
80
+ envVars[key] =
81
+ value.slice(0, 2) + "*".repeat(value.length - 4) + value.slice(-2);
82
+ }
83
+ }
84
+ return envVars;
85
+ }
86
+ exports.getLangChainEnvVars = getLangChainEnvVars;
87
+ /**
88
+ * Retrieves the environment variables from the current runtime environment.
89
+ *
90
+ * This function is designed to operate in a variety of JS environments,
91
+ * including Node.js, Deno, browsers, etc.
92
+ *
93
+ * @returns {Record<string, string> | undefined}
94
+ * - A record of environment variables if available.
95
+ * - `undefined` if the environment does not support or allows access to environment variables.
96
+ */
97
+ function getEnvironmentVariables() {
98
+ try {
99
+ // Check for Node.js environment
100
+ // eslint-disable-next-line no-process-env
101
+ if (typeof process !== "undefined" && process.env) {
102
+ // eslint-disable-next-line no-process-env
103
+ Object.entries(process.env).reduce((acc, [key, value]) => {
104
+ acc[key] = String(value);
105
+ return acc;
106
+ }, {});
107
+ }
108
+ // For browsers and other environments, we may not have direct access to env variables
109
+ // Return undefined or any other fallback as required.
110
+ return undefined;
111
+ }
112
+ catch (e) {
113
+ // Catch any errors that might occur while trying to access environment variables
114
+ return undefined;
115
+ }
116
+ }
117
+ exports.getEnvironmentVariables = getEnvironmentVariables;
62
118
  function getEnvironmentVariable(name) {
63
119
  // Certain Deno setups will throw an error if you try to access environment variables
64
120
  // https://github.com/hwchase17/langchainjs/issues/1412
@@ -18,6 +18,25 @@ export type RuntimeEnvironment = {
18
18
  runtimeVersion?: string;
19
19
  };
20
20
  export declare function getRuntimeEnvironment(): Promise<RuntimeEnvironment>;
21
+ /**
22
+ * Retrieves the LangChain-specific environment variables from the current runtime environment.
23
+ * Sensitive keys (containing the word "key") have their values redacted for security.
24
+ *
25
+ * @returns {Record<string, string>}
26
+ * - A record of LangChain-specific environment variables.
27
+ */
28
+ export declare function getLangChainEnvVars(): Record<string, string>;
29
+ /**
30
+ * Retrieves the environment variables from the current runtime environment.
31
+ *
32
+ * This function is designed to operate in a variety of JS environments,
33
+ * including Node.js, Deno, browsers, etc.
34
+ *
35
+ * @returns {Record<string, string> | undefined}
36
+ * - A record of environment variables if available.
37
+ * - `undefined` if the environment does not support or allows access to environment variables.
38
+ */
39
+ export declare function getEnvironmentVariables(): Record<string, string> | undefined;
21
40
  export declare function getEnvironmentVariable(name: string): string | undefined;
22
41
  export declare function setEnvironmentVariable(name: string, value: string): void;
23
42
  interface ICommitSHAs {
package/dist/utils/env.js CHANGED
@@ -49,6 +49,60 @@ export async function getRuntimeEnvironment() {
49
49
  }
50
50
  return runtimeEnvironment;
51
51
  }
52
+ /**
53
+ * Retrieves the LangChain-specific environment variables from the current runtime environment.
54
+ * Sensitive keys (containing the word "key") have their values redacted for security.
55
+ *
56
+ * @returns {Record<string, string>}
57
+ * - A record of LangChain-specific environment variables.
58
+ */
59
+ export function getLangChainEnvVars() {
60
+ const allEnvVars = getEnvironmentVariables() || {};
61
+ const envVars = {};
62
+ for (const [key, value] of Object.entries(allEnvVars)) {
63
+ if (key.startsWith("LANGCHAIN_") && typeof value === "string") {
64
+ envVars[key] = value;
65
+ }
66
+ }
67
+ for (const key in envVars) {
68
+ if (key.toLowerCase().includes("key") && typeof envVars[key] === "string") {
69
+ const value = envVars[key];
70
+ envVars[key] =
71
+ value.slice(0, 2) + "*".repeat(value.length - 4) + value.slice(-2);
72
+ }
73
+ }
74
+ return envVars;
75
+ }
76
+ /**
77
+ * Retrieves the environment variables from the current runtime environment.
78
+ *
79
+ * This function is designed to operate in a variety of JS environments,
80
+ * including Node.js, Deno, browsers, etc.
81
+ *
82
+ * @returns {Record<string, string> | undefined}
83
+ * - A record of environment variables if available.
84
+ * - `undefined` if the environment does not support or allows access to environment variables.
85
+ */
86
+ export function getEnvironmentVariables() {
87
+ try {
88
+ // Check for Node.js environment
89
+ // eslint-disable-next-line no-process-env
90
+ if (typeof process !== "undefined" && process.env) {
91
+ // eslint-disable-next-line no-process-env
92
+ Object.entries(process.env).reduce((acc, [key, value]) => {
93
+ acc[key] = String(value);
94
+ return acc;
95
+ }, {});
96
+ }
97
+ // For browsers and other environments, we may not have direct access to env variables
98
+ // Return undefined or any other fallback as required.
99
+ return undefined;
100
+ }
101
+ catch (e) {
102
+ // Catch any errors that might occur while trying to access environment variables
103
+ return undefined;
104
+ }
105
+ }
52
106
  export function getEnvironmentVariable(name) {
53
107
  // Certain Deno setups will throw an error if you try to access environment variables
54
108
  // https://github.com/hwchase17/langchainjs/issues/1412
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.0.33",
3
+ "version": "0.0.35",
4
4
  "description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.",
5
5
  "files": [
6
6
  "dist/",