langsmith 0.6.0 → 0.6.1

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 CHANGED
@@ -49,6 +49,7 @@ const error_js_1 = require("./utils/error.cjs");
49
49
  const index_js_2 = require("./utils/prompt_cache/index.cjs");
50
50
  const fsUtils = __importStar(require("./utils/fs.cjs"));
51
51
  const fetch_js_1 = require("./singletons/fetch.cjs");
52
+ const profiles_js_1 = require("./utils/profiles.cjs");
52
53
  const index_js_3 = require("./utils/fast-safe-stringify/index.cjs");
53
54
  const serialize_worker_js_1 = require("./utils/serialize_worker.cjs");
54
55
  function assertPullPublicPromptAllowed(promptIdentifier, dangerouslyPullPublicPrompt) {
@@ -163,7 +164,6 @@ exports.DEFAULT_MAX_SIZE_BYTES = 1024 * 1024 * 1024; // 1GB
163
164
  const SERVER_INFO_REQUEST_TIMEOUT_MS = 10000;
164
165
  /** Maximum number of operations to batch in a single request. */
165
166
  const DEFAULT_BATCH_SIZE_LIMIT = 100;
166
- const DEFAULT_API_URL = "https://api.smith.langchain.com";
167
167
  class AutoBatchQueue {
168
168
  constructor(maxSizeBytes) {
169
169
  Object.defineProperty(this, "items", {
@@ -268,7 +268,139 @@ class Client {
268
268
  return this._tracingMode;
269
269
  }
270
270
  get _fetch() {
271
- return this.fetchImplementation || (0, fetch_js_1._getFetchImplementation)(this.debug);
271
+ const fetchImplementation = this.fetchImplementation || (0, fetch_js_1._getFetchImplementation)(this.debug);
272
+ return (async (input, init) => {
273
+ let authHeader;
274
+ const profileManagedAuthorization = this.getProfileManagedAuthorizationHeader(init);
275
+ if (this.apiKey !== undefined) {
276
+ authHeader = { name: "x-api-key", value: `${this.apiKey}` };
277
+ }
278
+ else if (!this.hasExplicitAuthHeader(init, profileManagedAuthorization)) {
279
+ authHeader = await this.profileAuth?.getAuthHeader(fetchImplementation, init?.signal);
280
+ }
281
+ return fetchImplementation(input, this.applyCurrentAuthHeaders(init, authHeader, profileManagedAuthorization));
282
+ });
283
+ }
284
+ getProfileManagedAuthorizationHeader(init) {
285
+ if (!init?.headers || !this.profileAuth) {
286
+ return undefined;
287
+ }
288
+ const authorization = new Headers(init.headers).get("Authorization");
289
+ if (!(0, profiles_js_1.hasValue)(authorization)) {
290
+ return undefined;
291
+ }
292
+ return this.profileAuth.isProfileAuthorizationHeader(authorization ?? "")
293
+ ? (authorization ?? undefined)
294
+ : undefined;
295
+ }
296
+ isProfileManagedAuthorizationHeader(value, profileManagedAuthorization) {
297
+ return (value === profileManagedAuthorization ||
298
+ this.profileAuth?.isProfileAuthorizationHeader(value) === true);
299
+ }
300
+ hasExplicitAuthHeader(init, profileManagedAuthorization) {
301
+ if (!init?.headers) {
302
+ return false;
303
+ }
304
+ const headers = new Headers(init.headers);
305
+ if ((0, profiles_js_1.hasValue)(headers.get("x-api-key"))) {
306
+ return true;
307
+ }
308
+ const authorization = headers.get("Authorization");
309
+ if (!(0, profiles_js_1.hasValue)(authorization)) {
310
+ return false;
311
+ }
312
+ return !this.isProfileManagedAuthorizationHeader(authorization ?? "", profileManagedAuthorization);
313
+ }
314
+ applyCurrentAuthHeaders(init, authHeader, profileManagedAuthorization) {
315
+ if (!authHeader) {
316
+ return init;
317
+ }
318
+ const applyAuth = (headers) => {
319
+ if (this.apiKey !== undefined && authHeader.name === "x-api-key") {
320
+ headers.delete("Authorization");
321
+ if (!headers.has("x-api-key")) {
322
+ headers.set("x-api-key", authHeader.value);
323
+ }
324
+ return headers;
325
+ }
326
+ if (authHeader.name === "Authorization") {
327
+ if ((0, profiles_js_1.hasValue)(headers.get("x-api-key"))) {
328
+ return headers;
329
+ }
330
+ const authorization = headers.get("Authorization");
331
+ if ((0, profiles_js_1.hasValue)(authorization) &&
332
+ !this.isProfileManagedAuthorizationHeader(authorization ?? "", profileManagedAuthorization)) {
333
+ return headers;
334
+ }
335
+ headers.set("Authorization", authHeader.value);
336
+ return headers;
337
+ }
338
+ const authorization = headers.get("Authorization");
339
+ if ((0, profiles_js_1.hasValue)(authorization) &&
340
+ !this.isProfileManagedAuthorizationHeader(authorization ?? "", profileManagedAuthorization)) {
341
+ return headers;
342
+ }
343
+ if ((0, profiles_js_1.hasValue)(authorization)) {
344
+ headers.delete("Authorization");
345
+ }
346
+ if (!headers.has("x-api-key")) {
347
+ headers.set("x-api-key", authHeader.value);
348
+ }
349
+ return headers;
350
+ };
351
+ if (!init) {
352
+ return {
353
+ headers: { [authHeader.name]: authHeader.value },
354
+ };
355
+ }
356
+ if (init.headers instanceof Headers) {
357
+ return { ...init, headers: applyAuth(new Headers(init.headers)) };
358
+ }
359
+ if (Array.isArray(init.headers)) {
360
+ return { ...init, headers: applyAuth(new Headers(init.headers)) };
361
+ }
362
+ const headers = {
363
+ ...(init.headers ?? {}),
364
+ };
365
+ const getHeaderKey = (name) => Object.keys(headers).find((key) => key.toLowerCase() === name);
366
+ const getHeader = (name) => {
367
+ const key = getHeaderKey(name);
368
+ return key ? headers[key] : undefined;
369
+ };
370
+ const hasApiKey = (0, profiles_js_1.hasValue)(getHeader("x-api-key"));
371
+ const authorization = getHeader("authorization");
372
+ const hasExplicitAuthorization = (0, profiles_js_1.hasValue)(authorization) &&
373
+ !this.isProfileManagedAuthorizationHeader(authorization ?? "", profileManagedAuthorization);
374
+ if (this.apiKey !== undefined && authHeader.name === "x-api-key") {
375
+ const authorizationKey = getHeaderKey("authorization");
376
+ if (authorizationKey) {
377
+ delete headers[authorizationKey];
378
+ }
379
+ if (!hasApiKey) {
380
+ headers["x-api-key"] = authHeader.value;
381
+ }
382
+ return { ...init, headers };
383
+ }
384
+ if (authHeader.name === "Authorization") {
385
+ if (!hasApiKey && !hasExplicitAuthorization) {
386
+ const authorizationKey = getHeaderKey("authorization");
387
+ if (authorizationKey && authorizationKey !== "Authorization") {
388
+ delete headers[authorizationKey];
389
+ }
390
+ headers.Authorization = authHeader.value;
391
+ }
392
+ return { ...init, headers };
393
+ }
394
+ if (!hasExplicitAuthorization) {
395
+ const authorizationKey = getHeaderKey("authorization");
396
+ if (authorizationKey) {
397
+ delete headers[authorizationKey];
398
+ }
399
+ if (!hasApiKey) {
400
+ headers["x-api-key"] = authHeader.value;
401
+ }
402
+ }
403
+ return { ...init, headers };
272
404
  }
273
405
  /**
274
406
  * Serialize a payload for tracing, optionally offloading the work to a
@@ -533,6 +665,12 @@ class Client {
533
665
  writable: true,
534
666
  value: void 0
535
667
  });
668
+ Object.defineProperty(this, "profileAuth", {
669
+ enumerable: true,
670
+ configurable: true,
671
+ writable: true,
672
+ value: void 0
673
+ });
536
674
  Object.defineProperty(this, "multipartStreamingDisabled", {
537
675
  enumerable: true,
538
676
  configurable: true,
@@ -581,12 +719,15 @@ class Client {
581
719
  if (this.apiUrl.endsWith("/")) {
582
720
  this.apiUrl = this.apiUrl.slice(0, -1);
583
721
  }
584
- this.apiKey = trimQuotes(config.apiKey ?? defaultConfig.apiKey);
722
+ const configuredApiKey = trimQuotes(config.apiKey ?? defaultConfig.apiKey);
723
+ this.apiKey = (0, profiles_js_1.hasValue)(configuredApiKey) ? configuredApiKey : undefined;
724
+ this.profileAuth =
725
+ this.apiKey !== undefined ? undefined : defaultConfig.profileAuth;
585
726
  this.webUrl = trimQuotes(config.webUrl ?? defaultConfig.webUrl);
586
727
  if (this.webUrl?.endsWith("/")) {
587
728
  this.webUrl = this.webUrl.slice(0, -1);
588
729
  }
589
- this.workspaceId = trimQuotes(config.workspaceId ?? (0, env_js_1.getLangSmithEnvironmentVariable)("WORKSPACE_ID"));
730
+ this.workspaceId = trimQuotes(config.workspaceId ?? defaultConfig.workspaceId);
590
731
  this.timeout_ms = config.timeout_ms ?? 90_000;
591
732
  this.caller = new async_caller_js_1.AsyncCaller({
592
733
  ...(config.callerOptions ?? {}),
@@ -671,18 +812,31 @@ class Client {
671
812
  this._customHeaders = config.headers ?? {};
672
813
  }
673
814
  static getDefaultClientConfig() {
674
- const apiKey = (0, env_js_1.getLangSmithEnvironmentVariable)("API_KEY");
675
- const apiUrl = (0, env_js_1.getLangSmithEnvironmentVariable)("ENDPOINT") ?? DEFAULT_API_URL;
815
+ const profileConfig = (0, profiles_js_1.loadProfileClientConfig)();
816
+ const envApiKey = (0, env_js_1.getLangSmithEnvironmentVariable)("API_KEY");
817
+ const envApiUrl = (0, env_js_1.getLangSmithEnvironmentVariable)("ENDPOINT");
818
+ const envWorkspaceId = (0, env_js_1.getLangSmithEnvironmentVariable)("WORKSPACE_ID");
819
+ const envAuthSet = (0, profiles_js_1.hasValue)(envApiKey);
820
+ const apiUrl = envApiUrl ?? profileConfig.apiUrl ?? profiles_js_1.DEFAULT_API_URL;
821
+ const workspaceId = envWorkspaceId ?? profileConfig.workspaceId;
676
822
  const hideInputs = (0, env_js_1.getLangSmithEnvironmentVariable)("HIDE_INPUTS") === "true";
677
823
  const hideOutputs = (0, env_js_1.getLangSmithEnvironmentVariable)("HIDE_OUTPUTS") === "true";
678
824
  const hideMetadata = (0, env_js_1.getLangSmithEnvironmentVariable)("HIDE_METADATA") === "true";
679
825
  return {
680
826
  apiUrl: apiUrl,
681
- apiKey: apiKey,
827
+ apiKey: envApiKey,
682
828
  webUrl: undefined,
683
829
  hideInputs: hideInputs,
684
830
  hideOutputs: hideOutputs,
685
831
  hideMetadata: hideMetadata,
832
+ workspaceId: workspaceId,
833
+ oauthAccessToken: !envAuthSet
834
+ ? profileConfig.oauthAccessToken
835
+ : undefined,
836
+ oauthRefreshToken: !envAuthSet
837
+ ? profileConfig.oauthRefreshToken
838
+ : undefined,
839
+ profileAuth: !envAuthSet ? profileConfig.profileAuth : undefined,
686
840
  };
687
841
  }
688
842
  getHostUrl() {
@@ -734,9 +888,15 @@ class Client {
734
888
  ...this._customHeaders,
735
889
  };
736
890
  // Required headers that should not be overridden
737
- if (this.apiKey) {
891
+ if (this.apiKey !== undefined) {
738
892
  headers["x-api-key"] = `${this.apiKey}`;
739
893
  }
894
+ else {
895
+ const profileAuthHeader = this.profileAuth?.currentAuthHeader();
896
+ if (profileAuthHeader) {
897
+ headers[profileAuthHeader.name] = profileAuthHeader.value;
898
+ }
899
+ }
740
900
  if (this.workspaceId) {
741
901
  headers["x-tenant-id"] = this.workspaceId;
742
902
  }
@@ -1640,7 +1800,7 @@ class Client {
1640
1800
  // if stream fails, fallback to buffered body
1641
1801
  if ((!this.multipartStreamingDisabled || streamedAttempt) &&
1642
1802
  res.status === 422 &&
1643
- (options?.apiUrl ?? this.apiUrl) !== DEFAULT_API_URL) {
1803
+ (options?.apiUrl ?? this.apiUrl) !== profiles_js_1.DEFAULT_API_URL) {
1644
1804
  console.warn(`Streaming multipart upload to ${options?.apiUrl ?? this.apiUrl}/runs/multipart failed. ` +
1645
1805
  `This usually means the host does not support chunked uploads. ` +
1646
1806
  `Retrying with a buffered upload for operation "${context}".`);
package/dist/client.d.ts CHANGED
@@ -4,6 +4,7 @@ import { ComparativeExperiment, DataType, Dataset, DatasetDiffInfo, DatasetShare
4
4
  import { type TracingMode } from "./utils/env.js";
5
5
  import { EvaluationResult, EvaluationResults } from "./evaluation/evaluator.js";
6
6
  import { PromptCache } from "./utils/prompt_cache/index.js";
7
+ import { ProfileAuth } from "./utils/profiles.js";
7
8
  export interface ClientConfig {
8
9
  apiUrl?: string;
9
10
  apiKey?: string;
@@ -281,6 +282,18 @@ interface UploadCSVParams {
281
282
  dataType?: DataType;
282
283
  name?: string;
283
284
  }
285
+ type DefaultClientConfig = {
286
+ apiUrl: string;
287
+ apiKey?: string;
288
+ webUrl?: string;
289
+ hideInputs?: boolean;
290
+ hideOutputs?: boolean;
291
+ hideMetadata?: boolean;
292
+ workspaceId?: string;
293
+ oauthAccessToken?: string;
294
+ oauthRefreshToken?: string;
295
+ profileAuth?: ProfileAuth;
296
+ };
284
297
  interface CreateRunParams {
285
298
  name: string;
286
299
  inputs: KVMap;
@@ -439,7 +452,12 @@ export declare class Client implements LangSmithTracingClientInterface {
439
452
  private fetchImplementation?;
440
453
  private cachedLSEnvVarsForMetadata?;
441
454
  private _promptCache?;
455
+ private profileAuth?;
442
456
  private get _fetch();
457
+ private getProfileManagedAuthorizationHeader;
458
+ private isProfileManagedAuthorizationHeader;
459
+ private hasExplicitAuthHeader;
460
+ private applyCurrentAuthHeaders;
443
461
  /**
444
462
  * Serialize a payload for tracing, optionally offloading the work to a
445
463
  * Node worker thread when the runtime supports worker_threads.
@@ -464,14 +482,7 @@ export declare class Client implements LangSmithTracingClientInterface {
464
482
  private _customHeaders;
465
483
  debug: boolean;
466
484
  constructor(config?: ClientConfig);
467
- static getDefaultClientConfig(): {
468
- apiUrl: string;
469
- apiKey?: string;
470
- webUrl?: string;
471
- hideInputs?: boolean;
472
- hideOutputs?: boolean;
473
- hideMetadata?: boolean;
474
- };
485
+ static getDefaultClientConfig(): DefaultClientConfig;
475
486
  getHostUrl(): string;
476
487
  private get _mergedHeaders();
477
488
  /**
package/dist/client.js CHANGED
@@ -12,6 +12,7 @@ import { raiseForStatus, isLangSmithNotFoundError, isLangSmithConflictError, } f
12
12
  import { promptCacheSingleton, } from "./utils/prompt_cache/index.js";
13
13
  import * as fsUtils from "./utils/fs.js";
14
14
  import { _shouldStreamForGlobalFetchImplementation, _getFetchImplementation, } from "./singletons/fetch.js";
15
+ import { DEFAULT_API_URL, hasValue, loadProfileClientConfig, } from "./utils/profiles.js";
15
16
  import { serialize as serializePayloadForTracing, estimateSerializedSize, } from "./utils/fast-safe-stringify/index.js";
16
17
  import { getSharedSerializeWorker, hasLargeString, } from "./utils/serialize_worker.js";
17
18
  function assertPullPublicPromptAllowed(promptIdentifier, dangerouslyPullPublicPrompt) {
@@ -126,7 +127,6 @@ export const DEFAULT_MAX_SIZE_BYTES = 1024 * 1024 * 1024; // 1GB
126
127
  const SERVER_INFO_REQUEST_TIMEOUT_MS = 10000;
127
128
  /** Maximum number of operations to batch in a single request. */
128
129
  const DEFAULT_BATCH_SIZE_LIMIT = 100;
129
- const DEFAULT_API_URL = "https://api.smith.langchain.com";
130
130
  export class AutoBatchQueue {
131
131
  constructor(maxSizeBytes) {
132
132
  Object.defineProperty(this, "items", {
@@ -230,7 +230,139 @@ export class Client {
230
230
  return this._tracingMode;
231
231
  }
232
232
  get _fetch() {
233
- return this.fetchImplementation || _getFetchImplementation(this.debug);
233
+ const fetchImplementation = this.fetchImplementation || _getFetchImplementation(this.debug);
234
+ return (async (input, init) => {
235
+ let authHeader;
236
+ const profileManagedAuthorization = this.getProfileManagedAuthorizationHeader(init);
237
+ if (this.apiKey !== undefined) {
238
+ authHeader = { name: "x-api-key", value: `${this.apiKey}` };
239
+ }
240
+ else if (!this.hasExplicitAuthHeader(init, profileManagedAuthorization)) {
241
+ authHeader = await this.profileAuth?.getAuthHeader(fetchImplementation, init?.signal);
242
+ }
243
+ return fetchImplementation(input, this.applyCurrentAuthHeaders(init, authHeader, profileManagedAuthorization));
244
+ });
245
+ }
246
+ getProfileManagedAuthorizationHeader(init) {
247
+ if (!init?.headers || !this.profileAuth) {
248
+ return undefined;
249
+ }
250
+ const authorization = new Headers(init.headers).get("Authorization");
251
+ if (!hasValue(authorization)) {
252
+ return undefined;
253
+ }
254
+ return this.profileAuth.isProfileAuthorizationHeader(authorization ?? "")
255
+ ? (authorization ?? undefined)
256
+ : undefined;
257
+ }
258
+ isProfileManagedAuthorizationHeader(value, profileManagedAuthorization) {
259
+ return (value === profileManagedAuthorization ||
260
+ this.profileAuth?.isProfileAuthorizationHeader(value) === true);
261
+ }
262
+ hasExplicitAuthHeader(init, profileManagedAuthorization) {
263
+ if (!init?.headers) {
264
+ return false;
265
+ }
266
+ const headers = new Headers(init.headers);
267
+ if (hasValue(headers.get("x-api-key"))) {
268
+ return true;
269
+ }
270
+ const authorization = headers.get("Authorization");
271
+ if (!hasValue(authorization)) {
272
+ return false;
273
+ }
274
+ return !this.isProfileManagedAuthorizationHeader(authorization ?? "", profileManagedAuthorization);
275
+ }
276
+ applyCurrentAuthHeaders(init, authHeader, profileManagedAuthorization) {
277
+ if (!authHeader) {
278
+ return init;
279
+ }
280
+ const applyAuth = (headers) => {
281
+ if (this.apiKey !== undefined && authHeader.name === "x-api-key") {
282
+ headers.delete("Authorization");
283
+ if (!headers.has("x-api-key")) {
284
+ headers.set("x-api-key", authHeader.value);
285
+ }
286
+ return headers;
287
+ }
288
+ if (authHeader.name === "Authorization") {
289
+ if (hasValue(headers.get("x-api-key"))) {
290
+ return headers;
291
+ }
292
+ const authorization = headers.get("Authorization");
293
+ if (hasValue(authorization) &&
294
+ !this.isProfileManagedAuthorizationHeader(authorization ?? "", profileManagedAuthorization)) {
295
+ return headers;
296
+ }
297
+ headers.set("Authorization", authHeader.value);
298
+ return headers;
299
+ }
300
+ const authorization = headers.get("Authorization");
301
+ if (hasValue(authorization) &&
302
+ !this.isProfileManagedAuthorizationHeader(authorization ?? "", profileManagedAuthorization)) {
303
+ return headers;
304
+ }
305
+ if (hasValue(authorization)) {
306
+ headers.delete("Authorization");
307
+ }
308
+ if (!headers.has("x-api-key")) {
309
+ headers.set("x-api-key", authHeader.value);
310
+ }
311
+ return headers;
312
+ };
313
+ if (!init) {
314
+ return {
315
+ headers: { [authHeader.name]: authHeader.value },
316
+ };
317
+ }
318
+ if (init.headers instanceof Headers) {
319
+ return { ...init, headers: applyAuth(new Headers(init.headers)) };
320
+ }
321
+ if (Array.isArray(init.headers)) {
322
+ return { ...init, headers: applyAuth(new Headers(init.headers)) };
323
+ }
324
+ const headers = {
325
+ ...(init.headers ?? {}),
326
+ };
327
+ const getHeaderKey = (name) => Object.keys(headers).find((key) => key.toLowerCase() === name);
328
+ const getHeader = (name) => {
329
+ const key = getHeaderKey(name);
330
+ return key ? headers[key] : undefined;
331
+ };
332
+ const hasApiKey = hasValue(getHeader("x-api-key"));
333
+ const authorization = getHeader("authorization");
334
+ const hasExplicitAuthorization = hasValue(authorization) &&
335
+ !this.isProfileManagedAuthorizationHeader(authorization ?? "", profileManagedAuthorization);
336
+ if (this.apiKey !== undefined && authHeader.name === "x-api-key") {
337
+ const authorizationKey = getHeaderKey("authorization");
338
+ if (authorizationKey) {
339
+ delete headers[authorizationKey];
340
+ }
341
+ if (!hasApiKey) {
342
+ headers["x-api-key"] = authHeader.value;
343
+ }
344
+ return { ...init, headers };
345
+ }
346
+ if (authHeader.name === "Authorization") {
347
+ if (!hasApiKey && !hasExplicitAuthorization) {
348
+ const authorizationKey = getHeaderKey("authorization");
349
+ if (authorizationKey && authorizationKey !== "Authorization") {
350
+ delete headers[authorizationKey];
351
+ }
352
+ headers.Authorization = authHeader.value;
353
+ }
354
+ return { ...init, headers };
355
+ }
356
+ if (!hasExplicitAuthorization) {
357
+ const authorizationKey = getHeaderKey("authorization");
358
+ if (authorizationKey) {
359
+ delete headers[authorizationKey];
360
+ }
361
+ if (!hasApiKey) {
362
+ headers["x-api-key"] = authHeader.value;
363
+ }
364
+ }
365
+ return { ...init, headers };
234
366
  }
235
367
  /**
236
368
  * Serialize a payload for tracing, optionally offloading the work to a
@@ -495,6 +627,12 @@ export class Client {
495
627
  writable: true,
496
628
  value: void 0
497
629
  });
630
+ Object.defineProperty(this, "profileAuth", {
631
+ enumerable: true,
632
+ configurable: true,
633
+ writable: true,
634
+ value: void 0
635
+ });
498
636
  Object.defineProperty(this, "multipartStreamingDisabled", {
499
637
  enumerable: true,
500
638
  configurable: true,
@@ -543,12 +681,15 @@ export class Client {
543
681
  if (this.apiUrl.endsWith("/")) {
544
682
  this.apiUrl = this.apiUrl.slice(0, -1);
545
683
  }
546
- this.apiKey = trimQuotes(config.apiKey ?? defaultConfig.apiKey);
684
+ const configuredApiKey = trimQuotes(config.apiKey ?? defaultConfig.apiKey);
685
+ this.apiKey = hasValue(configuredApiKey) ? configuredApiKey : undefined;
686
+ this.profileAuth =
687
+ this.apiKey !== undefined ? undefined : defaultConfig.profileAuth;
547
688
  this.webUrl = trimQuotes(config.webUrl ?? defaultConfig.webUrl);
548
689
  if (this.webUrl?.endsWith("/")) {
549
690
  this.webUrl = this.webUrl.slice(0, -1);
550
691
  }
551
- this.workspaceId = trimQuotes(config.workspaceId ?? getLangSmithEnvironmentVariable("WORKSPACE_ID"));
692
+ this.workspaceId = trimQuotes(config.workspaceId ?? defaultConfig.workspaceId);
552
693
  this.timeout_ms = config.timeout_ms ?? 90_000;
553
694
  this.caller = new AsyncCaller({
554
695
  ...(config.callerOptions ?? {}),
@@ -633,18 +774,31 @@ export class Client {
633
774
  this._customHeaders = config.headers ?? {};
634
775
  }
635
776
  static getDefaultClientConfig() {
636
- const apiKey = getLangSmithEnvironmentVariable("API_KEY");
637
- const apiUrl = getLangSmithEnvironmentVariable("ENDPOINT") ?? DEFAULT_API_URL;
777
+ const profileConfig = loadProfileClientConfig();
778
+ const envApiKey = getLangSmithEnvironmentVariable("API_KEY");
779
+ const envApiUrl = getLangSmithEnvironmentVariable("ENDPOINT");
780
+ const envWorkspaceId = getLangSmithEnvironmentVariable("WORKSPACE_ID");
781
+ const envAuthSet = hasValue(envApiKey);
782
+ const apiUrl = envApiUrl ?? profileConfig.apiUrl ?? DEFAULT_API_URL;
783
+ const workspaceId = envWorkspaceId ?? profileConfig.workspaceId;
638
784
  const hideInputs = getLangSmithEnvironmentVariable("HIDE_INPUTS") === "true";
639
785
  const hideOutputs = getLangSmithEnvironmentVariable("HIDE_OUTPUTS") === "true";
640
786
  const hideMetadata = getLangSmithEnvironmentVariable("HIDE_METADATA") === "true";
641
787
  return {
642
788
  apiUrl: apiUrl,
643
- apiKey: apiKey,
789
+ apiKey: envApiKey,
644
790
  webUrl: undefined,
645
791
  hideInputs: hideInputs,
646
792
  hideOutputs: hideOutputs,
647
793
  hideMetadata: hideMetadata,
794
+ workspaceId: workspaceId,
795
+ oauthAccessToken: !envAuthSet
796
+ ? profileConfig.oauthAccessToken
797
+ : undefined,
798
+ oauthRefreshToken: !envAuthSet
799
+ ? profileConfig.oauthRefreshToken
800
+ : undefined,
801
+ profileAuth: !envAuthSet ? profileConfig.profileAuth : undefined,
648
802
  };
649
803
  }
650
804
  getHostUrl() {
@@ -696,9 +850,15 @@ export class Client {
696
850
  ...this._customHeaders,
697
851
  };
698
852
  // Required headers that should not be overridden
699
- if (this.apiKey) {
853
+ if (this.apiKey !== undefined) {
700
854
  headers["x-api-key"] = `${this.apiKey}`;
701
855
  }
856
+ else {
857
+ const profileAuthHeader = this.profileAuth?.currentAuthHeader();
858
+ if (profileAuthHeader) {
859
+ headers[profileAuthHeader.name] = profileAuthHeader.value;
860
+ }
861
+ }
702
862
  if (this.workspaceId) {
703
863
  headers["x-tenant-id"] = this.workspaceId;
704
864
  }
package/dist/index.cjs CHANGED
@@ -18,4 +18,4 @@ Object.defineProperty(exports, "PromptCache", { enumerable: true, get: function
18
18
  Object.defineProperty(exports, "configureGlobalPromptCache", { enumerable: true, get: function () { return index_js_1.configureGlobalPromptCache; } });
19
19
  Object.defineProperty(exports, "promptCacheSingleton", { enumerable: true, get: function () { return index_js_1.promptCacheSingleton; } });
20
20
  // Update using pnpm bump-version
21
- exports.__version__ = "0.6.0";
21
+ exports.__version__ = "0.6.1";
package/dist/index.d.ts CHANGED
@@ -5,4 +5,4 @@ export { overrideFetchImplementation } from "./singletons/fetch.js";
5
5
  export { getDefaultProjectName } from "./utils/project.js";
6
6
  export { uuid7, uuid7FromTime } from "./uuid.js";
7
7
  export { Cache, PromptCache, type CacheConfig, type CacheMetrics, configureGlobalPromptCache, promptCacheSingleton, } from "./utils/prompt_cache/index.js";
8
- export declare const __version__ = "0.6.0";
8
+ export declare const __version__ = "0.6.1";
package/dist/index.js CHANGED
@@ -5,4 +5,4 @@ export { getDefaultProjectName } from "./utils/project.js";
5
5
  export { uuid7, uuid7FromTime } from "./uuid.js";
6
6
  export { Cache, PromptCache, configureGlobalPromptCache, promptCacheSingleton, } from "./utils/prompt_cache/index.js";
7
7
  // Update using pnpm bump-version
8
- export const __version__ = "0.6.0";
8
+ export const __version__ = "0.6.1";
@@ -94,6 +94,7 @@ function getLangSmithEnvVarsMetadata() {
94
94
  "LANGSMITH_API_KEY",
95
95
  "LANGSMITH_ENDPOINT",
96
96
  "LANGSMITH_TRACING_V2",
97
+ "LANGSMITH_CONFIG_FILE",
97
98
  "LANGSMITH_PROJECT",
98
99
  "LANGSMITH_SESSION",
99
100
  ];
package/dist/utils/env.js CHANGED
@@ -76,6 +76,7 @@ export function getLangSmithEnvVarsMetadata() {
76
76
  "LANGSMITH_API_KEY",
77
77
  "LANGSMITH_ENDPOINT",
78
78
  "LANGSMITH_TRACING_V2",
79
+ "LANGSMITH_CONFIG_FILE",
79
80
  "LANGSMITH_PROJECT",
80
81
  "LANGSMITH_SESSION",
81
82
  ];