langsmith 0.5.26 → 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 +213 -27
- package/dist/client.d.ts +59 -11
- package/dist/client.js +212 -26
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/utils/env.cjs +1 -0
- package/dist/utils/env.js +1 -0
- package/dist/utils/profiles.cjs +292 -0
- package/dist/utils/profiles.d.ts +48 -0
- package/dist/utils/profiles.js +253 -0
- package/dist/utils/serialize_worker.cjs +1 -2
- package/dist/utils/serialize_worker.d.ts +1 -2
- package/dist/utils/serialize_worker.js +1 -2
- package/package.json +1 -14
- package/dist/experimental/opencode/index.cjs +0 -36
- package/dist/experimental/opencode/index.d.ts +0 -3
- package/dist/experimental/opencode/index.js +0 -32
- package/dist/experimental/opencode/tracer.cjs +0 -389
- package/dist/experimental/opencode/tracer.d.ts +0 -30
- package/dist/experimental/opencode/tracer.js +0 -385
- package/experimental/opencode.cjs +0 -1
- package/experimental/opencode.d.cts +0 -1
- package/experimental/opencode.d.ts +0 -1
- package/experimental/opencode.js +0 -1
package/dist/client.cjs
CHANGED
|
@@ -49,8 +49,15 @@ 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");
|
|
55
|
+
function assertPullPublicPromptAllowed(promptIdentifier, dangerouslyPullPublicPrompt) {
|
|
56
|
+
const [owner] = (0, prompts_js_1.parseHubIdentifier)(promptIdentifier);
|
|
57
|
+
if (owner !== "-" && !dangerouslyPullPublicPrompt) {
|
|
58
|
+
throw new Error("Pulling a public prompt by owner/name is disabled by default because prompts may contain untrusted serialized LangChain objects. If you trust this prompt, set `dangerouslyPullPublicPrompt: true` to acknowledge the risk.");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
54
61
|
/**
|
|
55
62
|
* Catches timestamps without a timezone suffix.
|
|
56
63
|
*/
|
|
@@ -157,7 +164,6 @@ exports.DEFAULT_MAX_SIZE_BYTES = 1024 * 1024 * 1024; // 1GB
|
|
|
157
164
|
const SERVER_INFO_REQUEST_TIMEOUT_MS = 10000;
|
|
158
165
|
/** Maximum number of operations to batch in a single request. */
|
|
159
166
|
const DEFAULT_BATCH_SIZE_LIMIT = 100;
|
|
160
|
-
const DEFAULT_API_URL = "https://api.smith.langchain.com";
|
|
161
167
|
class AutoBatchQueue {
|
|
162
168
|
constructor(maxSizeBytes) {
|
|
163
169
|
Object.defineProperty(this, "items", {
|
|
@@ -190,19 +196,11 @@ class AutoBatchQueue {
|
|
|
190
196
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/Promise
|
|
191
197
|
itemPromiseResolve = resolve;
|
|
192
198
|
});
|
|
193
|
-
//
|
|
194
|
-
//
|
|
195
|
-
//
|
|
196
|
-
//
|
|
197
|
-
|
|
198
|
-
// structural estimate instead. The estimate is only used for soft
|
|
199
|
-
// memory accounting (queue size limit and downstream async caller
|
|
200
|
-
// memory tracking), never for anything correctness-critical -- the
|
|
201
|
-
// real serialization still happens later, off the hot path, when the
|
|
202
|
-
// batch is assembled for sending.
|
|
203
|
-
const size = (0, env_js_1.getLangSmithEnvironmentVariable)("PERF_OPTIMIZATION") === "true"
|
|
204
|
-
? (0, index_js_3.estimateSerializedSize)(item.item).size
|
|
205
|
-
: (0, index_js_3.serialize)(item.item, `Serializing run with id: ${item.item.id}`).length;
|
|
199
|
+
// Use a cheap structural estimate for soft memory accounting (queue size
|
|
200
|
+
// limit and downstream async caller memory tracking). The exact
|
|
201
|
+
// serialization still happens later, off the hot path, when the batch is
|
|
202
|
+
// assembled for sending.
|
|
203
|
+
const size = (0, index_js_3.estimateSerializedSize)(item.item).size;
|
|
206
204
|
// Check if adding this item would exceed the size limit
|
|
207
205
|
// Allow the run if the queue is empty (to support large single traces)
|
|
208
206
|
if (this.sizeBytes + size > this.maxSizeBytes && this.items.length > 0) {
|
|
@@ -270,15 +268,145 @@ class Client {
|
|
|
270
268
|
return this._tracingMode;
|
|
271
269
|
}
|
|
272
270
|
get _fetch() {
|
|
273
|
-
|
|
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 };
|
|
274
404
|
}
|
|
275
405
|
/**
|
|
276
406
|
* Serialize a payload for tracing, optionally offloading the work to a
|
|
277
|
-
* Node worker thread when
|
|
278
|
-
* supports worker_threads.
|
|
407
|
+
* Node worker thread when the runtime supports worker_threads.
|
|
279
408
|
*
|
|
280
409
|
* Falls back to synchronous serialization when:
|
|
281
|
-
* - the perf flag is off
|
|
282
410
|
* - manualFlushMode is enabled (serverless: worker boot cost > benefit)
|
|
283
411
|
* - worker_threads is unavailable (non-Node runtimes)
|
|
284
412
|
* - the payload contains values that can't be structured-cloned across
|
|
@@ -294,8 +422,7 @@ class Client {
|
|
|
294
422
|
});
|
|
295
423
|
}
|
|
296
424
|
async _serializeBody(payload, errorContext) {
|
|
297
|
-
|
|
298
|
-
if (!perfOptIn || this.manualFlushMode) {
|
|
425
|
+
if (this.manualFlushMode) {
|
|
299
426
|
return (0, index_js_3.serialize)(payload, errorContext);
|
|
300
427
|
}
|
|
301
428
|
// Shape-aware gate: worker offload pays for itself only when the
|
|
@@ -538,6 +665,12 @@ class Client {
|
|
|
538
665
|
writable: true,
|
|
539
666
|
value: void 0
|
|
540
667
|
});
|
|
668
|
+
Object.defineProperty(this, "profileAuth", {
|
|
669
|
+
enumerable: true,
|
|
670
|
+
configurable: true,
|
|
671
|
+
writable: true,
|
|
672
|
+
value: void 0
|
|
673
|
+
});
|
|
541
674
|
Object.defineProperty(this, "multipartStreamingDisabled", {
|
|
542
675
|
enumerable: true,
|
|
543
676
|
configurable: true,
|
|
@@ -586,12 +719,15 @@ class Client {
|
|
|
586
719
|
if (this.apiUrl.endsWith("/")) {
|
|
587
720
|
this.apiUrl = this.apiUrl.slice(0, -1);
|
|
588
721
|
}
|
|
589
|
-
|
|
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;
|
|
590
726
|
this.webUrl = trimQuotes(config.webUrl ?? defaultConfig.webUrl);
|
|
591
727
|
if (this.webUrl?.endsWith("/")) {
|
|
592
728
|
this.webUrl = this.webUrl.slice(0, -1);
|
|
593
729
|
}
|
|
594
|
-
this.workspaceId = trimQuotes(config.workspaceId ??
|
|
730
|
+
this.workspaceId = trimQuotes(config.workspaceId ?? defaultConfig.workspaceId);
|
|
595
731
|
this.timeout_ms = config.timeout_ms ?? 90_000;
|
|
596
732
|
this.caller = new async_caller_js_1.AsyncCaller({
|
|
597
733
|
...(config.callerOptions ?? {}),
|
|
@@ -676,18 +812,31 @@ class Client {
|
|
|
676
812
|
this._customHeaders = config.headers ?? {};
|
|
677
813
|
}
|
|
678
814
|
static getDefaultClientConfig() {
|
|
679
|
-
const
|
|
680
|
-
const
|
|
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;
|
|
681
822
|
const hideInputs = (0, env_js_1.getLangSmithEnvironmentVariable)("HIDE_INPUTS") === "true";
|
|
682
823
|
const hideOutputs = (0, env_js_1.getLangSmithEnvironmentVariable)("HIDE_OUTPUTS") === "true";
|
|
683
824
|
const hideMetadata = (0, env_js_1.getLangSmithEnvironmentVariable)("HIDE_METADATA") === "true";
|
|
684
825
|
return {
|
|
685
826
|
apiUrl: apiUrl,
|
|
686
|
-
apiKey:
|
|
827
|
+
apiKey: envApiKey,
|
|
687
828
|
webUrl: undefined,
|
|
688
829
|
hideInputs: hideInputs,
|
|
689
830
|
hideOutputs: hideOutputs,
|
|
690
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,
|
|
691
840
|
};
|
|
692
841
|
}
|
|
693
842
|
getHostUrl() {
|
|
@@ -739,9 +888,15 @@ class Client {
|
|
|
739
888
|
...this._customHeaders,
|
|
740
889
|
};
|
|
741
890
|
// Required headers that should not be overridden
|
|
742
|
-
if (this.apiKey) {
|
|
891
|
+
if (this.apiKey !== undefined) {
|
|
743
892
|
headers["x-api-key"] = `${this.apiKey}`;
|
|
744
893
|
}
|
|
894
|
+
else {
|
|
895
|
+
const profileAuthHeader = this.profileAuth?.currentAuthHeader();
|
|
896
|
+
if (profileAuthHeader) {
|
|
897
|
+
headers[profileAuthHeader.name] = profileAuthHeader.value;
|
|
898
|
+
}
|
|
899
|
+
}
|
|
745
900
|
if (this.workspaceId) {
|
|
746
901
|
headers["x-tenant-id"] = this.workspaceId;
|
|
747
902
|
}
|
|
@@ -1645,7 +1800,7 @@ class Client {
|
|
|
1645
1800
|
// if stream fails, fallback to buffered body
|
|
1646
1801
|
if ((!this.multipartStreamingDisabled || streamedAttempt) &&
|
|
1647
1802
|
res.status === 422 &&
|
|
1648
|
-
(options?.apiUrl ?? this.apiUrl) !== DEFAULT_API_URL) {
|
|
1803
|
+
(options?.apiUrl ?? this.apiUrl) !== profiles_js_1.DEFAULT_API_URL) {
|
|
1649
1804
|
console.warn(`Streaming multipart upload to ${options?.apiUrl ?? this.apiUrl}/runs/multipart failed. ` +
|
|
1650
1805
|
`This usually means the host does not support chunked uploads. ` +
|
|
1651
1806
|
`Retrying with a buffered upload for operation "${context}".`);
|
|
@@ -4498,7 +4653,24 @@ class Client {
|
|
|
4498
4653
|
hub_model_provider: result.model_provider,
|
|
4499
4654
|
};
|
|
4500
4655
|
}
|
|
4656
|
+
/**
|
|
4657
|
+
* Pull a prompt commit from the LangSmith API.
|
|
4658
|
+
*
|
|
4659
|
+
* Public prompts referenced by owner/name cross a trust boundary because the
|
|
4660
|
+
* prompt manifest may contain serialized LangChain objects and configuration
|
|
4661
|
+
* that affect runtime behavior. For example, a prompt can intentionally
|
|
4662
|
+
* configure a model with a custom base URL, headers, model name, or other
|
|
4663
|
+
* constructor arguments. These are supported features, but they also mean the
|
|
4664
|
+
* prompt contents should be treated as executable configuration rather than
|
|
4665
|
+
* plain text.
|
|
4666
|
+
*
|
|
4667
|
+
* Set `dangerouslyPullPublicPrompt: true` only after reviewing and trusting
|
|
4668
|
+
* the prompt contents, not merely the publishing account. Prompts from your
|
|
4669
|
+
* own or your organization's account can still be unsafe if that account or
|
|
4670
|
+
* prompt was compromised.
|
|
4671
|
+
*/
|
|
4501
4672
|
async pullPromptCommit(promptIdentifier, options) {
|
|
4673
|
+
assertPullPublicPromptAllowed(promptIdentifier, options?.dangerouslyPullPublicPrompt);
|
|
4502
4674
|
// Check cache first if not skipped
|
|
4503
4675
|
const refreshFunc = this._fetchPromptFromApi.bind(this, promptIdentifier, options);
|
|
4504
4676
|
if (!options?.skipCache && this._promptCache) {
|
|
@@ -4518,12 +4690,26 @@ class Client {
|
|
|
4518
4690
|
/**
|
|
4519
4691
|
* This method should not be used directly, use `import { pull } from "langchain/hub"` instead.
|
|
4520
4692
|
* Using this method directly returns the JSON string of the prompt rather than a LangChain object.
|
|
4693
|
+
*
|
|
4694
|
+
* Public prompts referenced by owner/name cross a trust boundary because the
|
|
4695
|
+
* prompt manifest may contain serialized LangChain objects and configuration
|
|
4696
|
+
* that affect runtime behavior. For example, a prompt can intentionally
|
|
4697
|
+
* configure a model with a custom base URL, headers, model name, or other
|
|
4698
|
+
* constructor arguments. These are supported features, but they also mean the
|
|
4699
|
+
* prompt contents should be treated as executable configuration rather than
|
|
4700
|
+
* plain text.
|
|
4701
|
+
*
|
|
4702
|
+
* Set `dangerouslyPullPublicPrompt: true` only after reviewing and trusting
|
|
4703
|
+
* the prompt contents, not merely the publishing account. Prompts from your
|
|
4704
|
+
* own or your organization's account can still be unsafe if that account or
|
|
4705
|
+
* prompt was compromised.
|
|
4521
4706
|
* @private
|
|
4522
4707
|
*/
|
|
4523
4708
|
async _pullPrompt(promptIdentifier, options) {
|
|
4524
4709
|
const promptObject = await this.pullPromptCommit(promptIdentifier, {
|
|
4525
4710
|
includeModel: options?.includeModel,
|
|
4526
4711
|
skipCache: options?.skipCache,
|
|
4712
|
+
dangerouslyPullPublicPrompt: options?.dangerouslyPullPublicPrompt,
|
|
4527
4713
|
});
|
|
4528
4714
|
const prompt = JSON.stringify(promptObject.manifest);
|
|
4529
4715
|
return prompt;
|
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,14 +452,17 @@ 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
|
-
* Node worker thread when
|
|
446
|
-
* supports worker_threads.
|
|
463
|
+
* Node worker thread when the runtime supports worker_threads.
|
|
447
464
|
*
|
|
448
465
|
* Falls back to synchronous serialization when:
|
|
449
|
-
* - the perf flag is off
|
|
450
466
|
* - manualFlushMode is enabled (serverless: worker boot cost > benefit)
|
|
451
467
|
* - worker_threads is unavailable (non-Node runtimes)
|
|
452
468
|
* - the payload contains values that can't be structured-cloned across
|
|
@@ -466,14 +482,7 @@ export declare class Client implements LangSmithTracingClientInterface {
|
|
|
466
482
|
private _customHeaders;
|
|
467
483
|
debug: boolean;
|
|
468
484
|
constructor(config?: ClientConfig);
|
|
469
|
-
static getDefaultClientConfig():
|
|
470
|
-
apiUrl: string;
|
|
471
|
-
apiKey?: string;
|
|
472
|
-
webUrl?: string;
|
|
473
|
-
hideInputs?: boolean;
|
|
474
|
-
hideOutputs?: boolean;
|
|
475
|
-
hideMetadata?: boolean;
|
|
476
|
-
};
|
|
485
|
+
static getDefaultClientConfig(): DefaultClientConfig;
|
|
477
486
|
getHostUrl(): string;
|
|
478
487
|
private get _mergedHeaders();
|
|
479
488
|
/**
|
|
@@ -1322,18 +1331,57 @@ export declare class Client implements LangSmithTracingClientInterface {
|
|
|
1322
1331
|
* Fetch a prompt commit directly from the API (bypassing cache).
|
|
1323
1332
|
*/
|
|
1324
1333
|
private _fetchPromptFromApi;
|
|
1334
|
+
/**
|
|
1335
|
+
* Pull a prompt commit from the LangSmith API.
|
|
1336
|
+
*
|
|
1337
|
+
* Public prompts referenced by owner/name cross a trust boundary because the
|
|
1338
|
+
* prompt manifest may contain serialized LangChain objects and configuration
|
|
1339
|
+
* that affect runtime behavior. For example, a prompt can intentionally
|
|
1340
|
+
* configure a model with a custom base URL, headers, model name, or other
|
|
1341
|
+
* constructor arguments. These are supported features, but they also mean the
|
|
1342
|
+
* prompt contents should be treated as executable configuration rather than
|
|
1343
|
+
* plain text.
|
|
1344
|
+
*
|
|
1345
|
+
* Set `dangerouslyPullPublicPrompt: true` only after reviewing and trusting
|
|
1346
|
+
* the prompt contents, not merely the publishing account. Prompts from your
|
|
1347
|
+
* own or your organization's account can still be unsafe if that account or
|
|
1348
|
+
* prompt was compromised.
|
|
1349
|
+
*/
|
|
1325
1350
|
pullPromptCommit(promptIdentifier: string, options?: {
|
|
1326
1351
|
includeModel?: boolean;
|
|
1327
1352
|
skipCache?: boolean;
|
|
1353
|
+
/**
|
|
1354
|
+
* Set to `true` to allow pulling a public prompt by owner/name, for
|
|
1355
|
+
* example `username/promptname`. Defaults to `false`.
|
|
1356
|
+
*/
|
|
1357
|
+
dangerouslyPullPublicPrompt?: boolean;
|
|
1328
1358
|
}): Promise<PromptCommit>;
|
|
1329
1359
|
/**
|
|
1330
1360
|
* This method should not be used directly, use `import { pull } from "langchain/hub"` instead.
|
|
1331
1361
|
* Using this method directly returns the JSON string of the prompt rather than a LangChain object.
|
|
1362
|
+
*
|
|
1363
|
+
* Public prompts referenced by owner/name cross a trust boundary because the
|
|
1364
|
+
* prompt manifest may contain serialized LangChain objects and configuration
|
|
1365
|
+
* that affect runtime behavior. For example, a prompt can intentionally
|
|
1366
|
+
* configure a model with a custom base URL, headers, model name, or other
|
|
1367
|
+
* constructor arguments. These are supported features, but they also mean the
|
|
1368
|
+
* prompt contents should be treated as executable configuration rather than
|
|
1369
|
+
* plain text.
|
|
1370
|
+
*
|
|
1371
|
+
* Set `dangerouslyPullPublicPrompt: true` only after reviewing and trusting
|
|
1372
|
+
* the prompt contents, not merely the publishing account. Prompts from your
|
|
1373
|
+
* own or your organization's account can still be unsafe if that account or
|
|
1374
|
+
* prompt was compromised.
|
|
1332
1375
|
* @private
|
|
1333
1376
|
*/
|
|
1334
1377
|
_pullPrompt(promptIdentifier: string, options?: {
|
|
1335
1378
|
includeModel?: boolean;
|
|
1336
1379
|
skipCache?: boolean;
|
|
1380
|
+
/**
|
|
1381
|
+
* Set to `true` to allow pulling a public prompt by owner/name, for
|
|
1382
|
+
* example `username/promptname`. Defaults to `false`.
|
|
1383
|
+
*/
|
|
1384
|
+
dangerouslyPullPublicPrompt?: boolean;
|
|
1337
1385
|
}): Promise<any>;
|
|
1338
1386
|
pushPrompt(promptIdentifier: string, options?: {
|
|
1339
1387
|
object?: any;
|