langsmith 0.8.7 → 0.8.9
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/_openapi_client/client.cjs +8 -0
- package/dist/_openapi_client/client.d.ts +3 -0
- package/dist/_openapi_client/client.js +8 -0
- package/dist/_openapi_client/resources/annotation-queues/annotation-queues.cjs +157 -0
- package/dist/_openapi_client/resources/annotation-queues/annotation-queues.d.ts +382 -0
- package/dist/_openapi_client/resources/annotation-queues/annotation-queues.js +120 -0
- package/dist/_openapi_client/resources/annotation-queues/items.cjs +84 -0
- package/dist/_openapi_client/resources/annotation-queues/items.d.ts +207 -0
- package/dist/_openapi_client/resources/annotation-queues/items.js +80 -0
- package/dist/_openapi_client/resources/annotation-queues/runs.cjs +73 -0
- package/dist/_openapi_client/resources/annotation-queues/runs.d.ts +197 -0
- package/dist/_openapi_client/resources/annotation-queues/runs.js +69 -0
- package/dist/_openapi_client/resources/datasets/experiment-runs.cjs +3 -1
- package/dist/_openapi_client/resources/datasets/experiment-runs.d.ts +2 -0
- package/dist/_openapi_client/resources/datasets/experiment-runs.js +3 -1
- package/dist/_openapi_client/resources/index.cjs +3 -1
- package/dist/_openapi_client/resources/index.d.ts +1 -0
- package/dist/_openapi_client/resources/index.js +1 -0
- package/dist/_openapi_client/resources/info.cjs +3 -1
- package/dist/_openapi_client/resources/info.d.ts +16 -22
- package/dist/_openapi_client/resources/info.js +3 -1
- package/dist/_openapi_client/resources/issues.cjs +2 -2
- package/dist/_openapi_client/resources/issues.d.ts +1 -1
- package/dist/_openapi_client/resources/issues.js +2 -2
- package/dist/_openapi_client/resources/online-evaluators.cjs +7 -7
- package/dist/_openapi_client/resources/online-evaluators.d.ts +8 -0
- package/dist/_openapi_client/resources/online-evaluators.js +7 -7
- package/dist/_openapi_client/resources/public/runs.cjs +10 -8
- package/dist/_openapi_client/resources/public/runs.d.ts +9 -7
- package/dist/_openapi_client/resources/public/runs.js +10 -8
- package/dist/_openapi_client/resources/runs/runs.cjs +14 -9
- package/dist/_openapi_client/resources/runs/runs.d.ts +20 -10
- package/dist/_openapi_client/resources/runs/runs.js +14 -9
- package/dist/_openapi_client/resources/runs/share.cjs +6 -2
- package/dist/_openapi_client/resources/runs/share.d.ts +4 -0
- package/dist/_openapi_client/resources/runs/share.js +6 -2
- package/dist/_openapi_client/resources/sandboxes/boxes.cjs +10 -10
- package/dist/_openapi_client/resources/sandboxes/boxes.d.ts +40 -0
- package/dist/_openapi_client/resources/sandboxes/boxes.js +10 -10
- package/dist/_openapi_client/resources/sandboxes/registries.cjs +5 -5
- package/dist/_openapi_client/resources/sandboxes/registries.js +5 -5
- package/dist/_openapi_client/resources/sandboxes/sandboxes.d.ts +17 -0
- package/dist/_openapi_client/resources/sandboxes/snapshots.cjs +4 -4
- package/dist/_openapi_client/resources/sandboxes/snapshots.d.ts +12 -0
- package/dist/_openapi_client/resources/sandboxes/snapshots.js +4 -4
- package/dist/_openapi_client/resources/threads.cjs +14 -11
- package/dist/_openapi_client/resources/threads.d.ts +13 -9
- package/dist/_openapi_client/resources/threads.js +14 -11
- package/dist/_openapi_client/resources/traces.cjs +8 -5
- package/dist/_openapi_client/resources/traces.d.ts +7 -4
- package/dist/_openapi_client/resources/traces.js +8 -5
- package/dist/client.cjs +318 -40
- package/dist/client.d.ts +111 -25
- package/dist/client.js +318 -40
- package/dist/evaluation/evaluate_comparative.cjs +7 -4
- package/dist/evaluation/evaluate_comparative.js +7 -4
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/sandbox/command_handle.cjs +38 -11
- package/dist/sandbox/command_handle.d.ts +1 -0
- package/dist/sandbox/command_handle.js +39 -12
- package/dist/sandbox/errors.cjs +16 -1
- package/dist/sandbox/errors.d.ts +11 -0
- package/dist/sandbox/errors.js +14 -0
- package/dist/sandbox/index.cjs +2 -1
- package/dist/sandbox/index.d.ts +1 -1
- package/dist/sandbox/index.js +1 -1
- package/dist/sandbox/sandbox.cjs +22 -4
- package/dist/sandbox/sandbox.js +24 -6
- package/dist/sandbox/ws_execute.cjs +82 -11
- package/dist/sandbox/ws_execute.d.ts +12 -2
- package/dist/sandbox/ws_execute.js +79 -11
- package/dist/utils/v2_migration.cjs +18 -0
- package/dist/utils/v2_migration.d.ts +8 -0
- package/dist/utils/v2_migration.js +16 -0
- package/dist/utils/warn.cjs +30 -4
- package/dist/utils/warn.d.ts +4 -1
- package/dist/utils/warn.js +29 -4
- package/package.json +1 -1
- package/dist/utils/constants.cjs +0 -4
- package/dist/utils/constants.d.ts +0 -1
- package/dist/utils/constants.js +0 -1
package/dist/client.cjs
CHANGED
|
@@ -46,7 +46,7 @@ const index_js_1 = require("./index.cjs");
|
|
|
46
46
|
const index_js_2 = require("./_openapi_client/index.cjs");
|
|
47
47
|
const _uuid_js_1 = require("./utils/_uuid.cjs");
|
|
48
48
|
const warn_js_1 = require("./utils/warn.cjs");
|
|
49
|
-
const
|
|
49
|
+
const v2_migration_js_1 = require("./utils/v2_migration.cjs");
|
|
50
50
|
const prompts_js_1 = require("./utils/prompts.cjs");
|
|
51
51
|
const error_js_1 = require("./utils/error.cjs");
|
|
52
52
|
const index_js_3 = require("./utils/prompt_cache/index.cjs");
|
|
@@ -161,9 +161,13 @@ function _formatFeedbackScore(score) {
|
|
|
161
161
|
}
|
|
162
162
|
return score;
|
|
163
163
|
}
|
|
164
|
-
function _checkBackendVersion(
|
|
164
|
+
function _checkBackendVersion(backendVersion, minVersion) {
|
|
165
|
+
if (!backendVersion) {
|
|
166
|
+
// /info was unreachable (or skipped): nothing to compare against.
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
165
169
|
const parse = (v) => v.split(".").map((s) => parseInt(s, 10));
|
|
166
|
-
const [maj, min, pat] = parse(
|
|
170
|
+
const [maj, min, pat] = parse(backendVersion);
|
|
167
171
|
const [rMaj, rMin, rPat] = parse(minVersion);
|
|
168
172
|
if (isNaN(maj) ||
|
|
169
173
|
isNaN(min) ||
|
|
@@ -171,13 +175,16 @@ function _checkBackendVersion(version, minVersion = constants_js_1._MIN_BACKEND_
|
|
|
171
175
|
isNaN(rMaj) ||
|
|
172
176
|
isNaN(rMin) ||
|
|
173
177
|
isNaN(rPat)) {
|
|
174
|
-
console.warn(`[LANGSMITH]: Could not parse backend version ${JSON.stringify(
|
|
178
|
+
console.warn(`[LANGSMITH]: Could not parse backend version ${JSON.stringify(backendVersion)} for compatibility check.`);
|
|
175
179
|
return;
|
|
176
180
|
}
|
|
177
181
|
if (maj < rMaj ||
|
|
178
182
|
(maj === rMaj && min < rMin) ||
|
|
179
183
|
(maj === rMaj && min === rMin && pat < rPat)) {
|
|
180
|
-
console.warn(`[LANGSMITH]: Backend version ${JSON.stringify(
|
|
184
|
+
console.warn(`[LANGSMITH]: Backend version ${JSON.stringify(backendVersion)} is older than ` +
|
|
185
|
+
`the minimum version required by this SDK (${JSON.stringify(minVersion)}). ` +
|
|
186
|
+
"Some features may not work as expected. See " +
|
|
187
|
+
"https://docs.langchain.com/langsmith/smithdb-sdk-migration");
|
|
181
188
|
}
|
|
182
189
|
}
|
|
183
190
|
exports.DEFAULT_UNCOMPRESSED_BATCH_SIZE_LIMIT_BYTES = 24 * 1024 * 1024;
|
|
@@ -186,6 +193,72 @@ exports.DEFAULT_MAX_SIZE_BYTES = 1024 * 1024 * 1024; // 1GB
|
|
|
186
193
|
const SERVER_INFO_REQUEST_TIMEOUT_MS = 10000;
|
|
187
194
|
/** Maximum number of operations to batch in a single request. */
|
|
188
195
|
const DEFAULT_BATCH_SIZE_LIMIT = 100;
|
|
196
|
+
/**
|
|
197
|
+
* Reject header names or values that could alter a request's framing.
|
|
198
|
+
*
|
|
199
|
+
* `Headers` does this for us, and does it the same way `fetch` will.
|
|
200
|
+
*/
|
|
201
|
+
function assertValidHeader(name, value) {
|
|
202
|
+
new Headers({ [name]: value });
|
|
203
|
+
}
|
|
204
|
+
/** Reject a malformed header up front, before it can reach a request. */
|
|
205
|
+
function assertValidHeaders(headers) {
|
|
206
|
+
for (const [name, value] of Object.entries(headers ?? {})) {
|
|
207
|
+
assertValidHeader(name, value);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Fold a `HeadersInit` into a plain object so it can be spread.
|
|
212
|
+
*
|
|
213
|
+
* Names are matched case-insensitively with the last value winning, keeping the
|
|
214
|
+
* first spelling seen. A plain object would instead keep both spellings, which
|
|
215
|
+
* `Headers` later joins into a `"first, second"` list rather than an override.
|
|
216
|
+
* Every name and value is validated on the way through.
|
|
217
|
+
*/
|
|
218
|
+
function normalizeHeaders(headers) {
|
|
219
|
+
if (!headers)
|
|
220
|
+
return {};
|
|
221
|
+
const entries = headers instanceof Headers
|
|
222
|
+
? [...headers.entries()]
|
|
223
|
+
: Array.isArray(headers)
|
|
224
|
+
? headers.map(([name, value]) => [name, value])
|
|
225
|
+
: Object.entries(headers);
|
|
226
|
+
const normalized = {};
|
|
227
|
+
const nameByLower = new Map();
|
|
228
|
+
for (const [name, value] of entries) {
|
|
229
|
+
assertValidHeader(name, value);
|
|
230
|
+
const lowerName = name.toLowerCase();
|
|
231
|
+
const existingName = nameByLower.get(lowerName);
|
|
232
|
+
if (existingName === undefined) {
|
|
233
|
+
nameByLower.set(lowerName, name);
|
|
234
|
+
normalized[name] = value;
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
normalized[existingName] = value;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return normalized;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Merge the caller's two header channels, then drop the `reserved` names.
|
|
244
|
+
*
|
|
245
|
+
* `overrides` wins, matched case-insensitively so a header supplied through both
|
|
246
|
+
* channels is overridden rather than turned into a `"first, second"` list.
|
|
247
|
+
*/
|
|
248
|
+
function mergeCallerHeaders(base, overrides, reserved) {
|
|
249
|
+
const merged = { ...base };
|
|
250
|
+
const nameByLower = new Map(Object.keys(merged).map((name) => [name.toLowerCase(), name]));
|
|
251
|
+
for (const [name, value] of Object.entries(overrides)) {
|
|
252
|
+
const lowerName = name.toLowerCase();
|
|
253
|
+
merged[nameByLower.get(lowerName) ?? name] = value;
|
|
254
|
+
}
|
|
255
|
+
for (const name of Object.keys(merged)) {
|
|
256
|
+
if (reserved.has(name.toLowerCase())) {
|
|
257
|
+
delete merged[name];
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return merged;
|
|
261
|
+
}
|
|
189
262
|
class AutoBatchQueue {
|
|
190
263
|
constructor(maxSizeBytes) {
|
|
191
264
|
Object.defineProperty(this, "items", {
|
|
@@ -605,13 +678,26 @@ class Client {
|
|
|
605
678
|
writable: true,
|
|
606
679
|
value: void 0
|
|
607
680
|
});
|
|
681
|
+
/** `config.fetchOptions` without its `headers`, which are merged separately. */
|
|
608
682
|
Object.defineProperty(this, "fetchOptions", {
|
|
609
683
|
enumerable: true,
|
|
610
684
|
configurable: true,
|
|
611
685
|
writable: true,
|
|
612
686
|
value: void 0
|
|
613
687
|
});
|
|
614
|
-
Object.defineProperty(this, "
|
|
688
|
+
Object.defineProperty(this, "_fetchOptionsHeaders", {
|
|
689
|
+
enumerable: true,
|
|
690
|
+
configurable: true,
|
|
691
|
+
writable: true,
|
|
692
|
+
value: {}
|
|
693
|
+
});
|
|
694
|
+
Object.defineProperty(this, "_openAPIClient", {
|
|
695
|
+
enumerable: true,
|
|
696
|
+
configurable: true,
|
|
697
|
+
writable: true,
|
|
698
|
+
value: void 0
|
|
699
|
+
});
|
|
700
|
+
Object.defineProperty(this, "_openAPIClientSignature", {
|
|
615
701
|
enumerable: true,
|
|
616
702
|
configurable: true,
|
|
617
703
|
writable: true,
|
|
@@ -648,11 +734,11 @@ class Client {
|
|
|
648
734
|
writable: true,
|
|
649
735
|
value: void 0
|
|
650
736
|
});
|
|
651
|
-
Object.defineProperty(this, "
|
|
737
|
+
Object.defineProperty(this, "_stainlessVersionsChecked", {
|
|
652
738
|
enumerable: true,
|
|
653
739
|
configurable: true,
|
|
654
740
|
writable: true,
|
|
655
|
-
value:
|
|
741
|
+
value: new Set()
|
|
656
742
|
});
|
|
657
743
|
Object.defineProperty(this, "manualFlushMode", {
|
|
658
744
|
enumerable: true,
|
|
@@ -816,8 +902,15 @@ class Client {
|
|
|
816
902
|
config.blockOnRootRunFinalization ?? this.blockOnRootRunFinalization;
|
|
817
903
|
this.batchSizeBytesLimit = config.batchSizeBytesLimit;
|
|
818
904
|
this.batchSizeLimit = config.batchSizeLimit;
|
|
819
|
-
|
|
820
|
-
this.
|
|
905
|
+
const { headers: fetchOptionsHeaders, ...fetchOptions } = config.fetchOptions || {};
|
|
906
|
+
this.fetchOptions = fetchOptions;
|
|
907
|
+
// Kept apart from `fetchOptions` so they can be merged *under* the required
|
|
908
|
+
// headers instead of replacing the whole set at each call site.
|
|
909
|
+
this._fetchOptionsHeaders = normalizeHeaders(fetchOptionsHeaders);
|
|
910
|
+
// Validated eagerly so malformed input fails at construction, but stored
|
|
911
|
+
// as given: `get headers` hands this object back to the caller.
|
|
912
|
+
assertValidHeaders(config.headers);
|
|
913
|
+
this._customHeaders = config.headers ?? {};
|
|
821
914
|
this.manualFlushMode = config.manualFlushMode ?? this.manualFlushMode;
|
|
822
915
|
this._tracingMode = (0, env_js_1.resolveTracingMode)(config.tracingMode);
|
|
823
916
|
if (this._tracingMode === "otel") {
|
|
@@ -852,8 +945,6 @@ class Client {
|
|
|
852
945
|
// Use the global singleton instance
|
|
853
946
|
this._promptCache = index_js_3.promptCacheSingleton;
|
|
854
947
|
}
|
|
855
|
-
// Initialize custom headers
|
|
856
|
-
this._customHeaders = config.headers ?? {};
|
|
857
948
|
}
|
|
858
949
|
static getDefaultClientConfig() {
|
|
859
950
|
const profileConfig = (0, profiles_js_1.loadProfileClientConfig)();
|
|
@@ -925,11 +1016,46 @@ class Client {
|
|
|
925
1016
|
return this.webUrl;
|
|
926
1017
|
}
|
|
927
1018
|
}
|
|
1019
|
+
/**
|
|
1020
|
+
* The headers this client sets from its own config, which a caller-supplied
|
|
1021
|
+
* header must not replace.
|
|
1022
|
+
*
|
|
1023
|
+
* Only what the client *actually* supplies: passing an explicit `Authorization`
|
|
1024
|
+
* or `x-api-key` header with no configured credential is a supported way to
|
|
1025
|
+
* authenticate (see `hasExplicitAuthHeader`), so those must survive.
|
|
1026
|
+
*/
|
|
1027
|
+
get _sdkControlledHeaders() {
|
|
1028
|
+
const names = new Set();
|
|
1029
|
+
if (this.apiKey !== undefined) {
|
|
1030
|
+
names.add("x-api-key");
|
|
1031
|
+
}
|
|
1032
|
+
else {
|
|
1033
|
+
const profileAuthHeader = this.profileAuth?.currentAuthHeader();
|
|
1034
|
+
if (profileAuthHeader) {
|
|
1035
|
+
names.add(profileAuthHeader.name.toLowerCase());
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
if (this.workspaceId) {
|
|
1039
|
+
names.add("x-tenant-id");
|
|
1040
|
+
}
|
|
1041
|
+
return names;
|
|
1042
|
+
}
|
|
1043
|
+
/**
|
|
1044
|
+
* Headers supplied by the caller, through either `config.headers` or
|
|
1045
|
+
* `config.fetchOptions.headers`, with the ones this SDK sets removed.
|
|
1046
|
+
*
|
|
1047
|
+
* `_customHeaders` is normalized here rather than at assignment because it is
|
|
1048
|
+
* public and mutable: `get headers` hands back the caller's own object, so its
|
|
1049
|
+
* contents can change (and can become malformed) at any point.
|
|
1050
|
+
*/
|
|
1051
|
+
get _callerHeaders() {
|
|
1052
|
+
return mergeCallerHeaders(normalizeHeaders(this._customHeaders), this._fetchOptionsHeaders, this._sdkControlledHeaders);
|
|
1053
|
+
}
|
|
928
1054
|
get _mergedHeaders() {
|
|
929
|
-
// Start with
|
|
1055
|
+
// Start with caller-supplied headers so they don't override required headers
|
|
930
1056
|
const headers = {
|
|
931
1057
|
"User-Agent": `langsmith-js/${index_js_1.__version__}`,
|
|
932
|
-
...this.
|
|
1058
|
+
...this._callerHeaders,
|
|
933
1059
|
};
|
|
934
1060
|
// Required headers that should not be overridden
|
|
935
1061
|
if (this.apiKey !== undefined) {
|
|
@@ -946,6 +1072,35 @@ class Client {
|
|
|
946
1072
|
}
|
|
947
1073
|
return headers;
|
|
948
1074
|
}
|
|
1075
|
+
/**
|
|
1076
|
+
* The auth options and caller headers to build the generated client with.
|
|
1077
|
+
*
|
|
1078
|
+
* The generated client applies `defaultHeaders` *after* its own auth headers,
|
|
1079
|
+
* so the ones this SDK sets are already dropped from `_callerHeaders` to keep
|
|
1080
|
+
* the precedence of `_mergedHeaders`, where required headers win.
|
|
1081
|
+
*/
|
|
1082
|
+
get _openAPIAuth() {
|
|
1083
|
+
const headers = { ...this._callerHeaders };
|
|
1084
|
+
// A caller may authenticate by supplying `x-api-key` themselves. The
|
|
1085
|
+
// generated client rejects that as a header (its `validateHeaders` requires
|
|
1086
|
+
// its own `apiKey` to be set), so hand it over as the `apiKey` option and
|
|
1087
|
+
// drop the header to avoid sending the same value twice.
|
|
1088
|
+
const callerApiKeyName = Object.keys(headers).find((name) => name.toLowerCase() === "x-api-key");
|
|
1089
|
+
let apiKey = this.apiKey;
|
|
1090
|
+
if (apiKey === undefined && callerApiKeyName !== undefined) {
|
|
1091
|
+
apiKey = headers[callerApiKeyName] ?? undefined;
|
|
1092
|
+
delete headers[callerApiKeyName];
|
|
1093
|
+
}
|
|
1094
|
+
if (apiKey === undefined && this.workspaceId === undefined) {
|
|
1095
|
+
// Let the wrapped `fetch` supply auth (profile auth, an explicit
|
|
1096
|
+
// `Authorization` header, or none at all).
|
|
1097
|
+
headers["X-API-Key"] = null;
|
|
1098
|
+
}
|
|
1099
|
+
return {
|
|
1100
|
+
apiKey,
|
|
1101
|
+
defaultHeaders: Object.keys(headers).length > 0 ? headers : undefined,
|
|
1102
|
+
};
|
|
1103
|
+
}
|
|
949
1104
|
/**
|
|
950
1105
|
* Get or set custom headers for the client.
|
|
951
1106
|
* Custom headers are merged with default headers (User-Agent, x-api-key, x-tenant-id).
|
|
@@ -955,24 +1110,47 @@ class Client {
|
|
|
955
1110
|
return this._customHeaders;
|
|
956
1111
|
}
|
|
957
1112
|
set headers(value) {
|
|
1113
|
+
assertValidHeaders(value);
|
|
958
1114
|
this._customHeaders = value ?? {};
|
|
959
1115
|
}
|
|
960
1116
|
_getOpenAPIBaseUrl() {
|
|
961
|
-
|
|
1117
|
+
const url = this.apiUrl.replace(/\/$/, "");
|
|
1118
|
+
for (const suffix of ["/api/v1", "/api"]) {
|
|
1119
|
+
if (url.endsWith(suffix))
|
|
1120
|
+
return url.slice(0, -suffix.length);
|
|
1121
|
+
}
|
|
1122
|
+
return url;
|
|
962
1123
|
}
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
1124
|
+
/**
|
|
1125
|
+
* The generated OpenAPI client, rebuilt whenever its auth or headers change.
|
|
1126
|
+
*
|
|
1127
|
+
* The generated client captures `defaultHeaders` and `apiKey` when it is
|
|
1128
|
+
* built, while the handwritten paths recompute `_mergedHeaders` per request.
|
|
1129
|
+
* Rebuilding on change keeps the two halves from diverging when the inputs
|
|
1130
|
+
* move underneath us — a caller mutating the object returned by
|
|
1131
|
+
* `get headers`, or a profile whose auth header only becomes available after
|
|
1132
|
+
* its token is refreshed.
|
|
1133
|
+
*/
|
|
1134
|
+
get openAPIClient() {
|
|
1135
|
+
const auth = this._openAPIAuth;
|
|
1136
|
+
const signature = JSON.stringify([auth.apiKey, auth.defaultHeaders]);
|
|
1137
|
+
if (this._openAPIClient === undefined ||
|
|
1138
|
+
this._openAPIClientSignature !== signature) {
|
|
1139
|
+
this._openAPIClientSignature = signature;
|
|
1140
|
+
this._openAPIClient = this._newOpenAPIClient(auth);
|
|
1141
|
+
}
|
|
1142
|
+
return this._openAPIClient;
|
|
1143
|
+
}
|
|
1144
|
+
_newOpenAPIClient(auth = this._openAPIAuth) {
|
|
1145
|
+
const { method: _method, body: _body, signal: _signal, ...openAPIFetchOptions } = this.fetchOptions;
|
|
968
1146
|
return new index_js_2.Langsmith({
|
|
969
|
-
apiKey:
|
|
1147
|
+
apiKey: auth.apiKey,
|
|
970
1148
|
tenantID: this.workspaceId,
|
|
971
1149
|
baseURL: this._getOpenAPIBaseUrl(),
|
|
972
1150
|
timeout: this.timeout_ms,
|
|
973
1151
|
fetch: this._fetch,
|
|
974
1152
|
fetchOptions: openAPIFetchOptions,
|
|
975
|
-
defaultHeaders,
|
|
1153
|
+
defaultHeaders: auth.defaultHeaders,
|
|
976
1154
|
});
|
|
977
1155
|
}
|
|
978
1156
|
_getPlatformEndpointPath(path) {
|
|
@@ -981,35 +1159,42 @@ class Client {
|
|
|
981
1159
|
return needsV1Prefix ? `/v1/platform/${path}` : `/platform/${path}`;
|
|
982
1160
|
}
|
|
983
1161
|
get evaluators() {
|
|
984
|
-
this._checkStainlessVersion();
|
|
1162
|
+
this._checkStainlessVersion("0.16.0");
|
|
985
1163
|
return this.openAPIClient.onlineEvaluators;
|
|
986
1164
|
}
|
|
987
1165
|
get runs() {
|
|
988
|
-
this._checkStainlessVersion();
|
|
1166
|
+
this._checkStainlessVersion("0.16.0");
|
|
989
1167
|
return this.openAPIClient.runs;
|
|
990
1168
|
}
|
|
991
1169
|
/** Access the v2 sandboxes resource (registries, snapshots, boxes). */
|
|
992
1170
|
get sandboxes() {
|
|
993
|
-
this._checkStainlessVersion();
|
|
1171
|
+
this._checkStainlessVersion("0.16.0");
|
|
994
1172
|
return this.openAPIClient.sandboxes;
|
|
995
1173
|
}
|
|
996
1174
|
/** Access the v2 datasets resource (experimentRuns, etc.). */
|
|
997
1175
|
get datasets() {
|
|
998
|
-
this._checkStainlessVersion();
|
|
1176
|
+
this._checkStainlessVersion("0.16.0");
|
|
999
1177
|
return this.openAPIClient.datasets;
|
|
1000
1178
|
}
|
|
1179
|
+
/** Access the annotation queues resource (runs, items). */
|
|
1180
|
+
get annotationQueues() {
|
|
1181
|
+
// The items endpoints landed in backend 0.16.14; the rest are older.
|
|
1182
|
+
this._checkStainlessVersion("0.16.14");
|
|
1183
|
+
return this.openAPIClient.annotationQueues;
|
|
1184
|
+
}
|
|
1001
1185
|
/** Access the threads resource (query, stats, listTraces). */
|
|
1002
1186
|
get threads() {
|
|
1003
|
-
this._checkStainlessVersion();
|
|
1187
|
+
this._checkStainlessVersion("0.16.0");
|
|
1004
1188
|
return this.openAPIClient.threads;
|
|
1005
1189
|
}
|
|
1006
1190
|
/** Access the traces resource (query, listRuns). */
|
|
1007
1191
|
get traces() {
|
|
1008
|
-
this._checkStainlessVersion();
|
|
1192
|
+
this._checkStainlessVersion("0.16.0");
|
|
1009
1193
|
return this.openAPIClient.traces;
|
|
1010
1194
|
}
|
|
1011
1195
|
/** Access the public shared-run resource. */
|
|
1012
1196
|
get public() {
|
|
1197
|
+
this._checkStainlessVersion("0.16.0");
|
|
1013
1198
|
return this.openAPIClient.public;
|
|
1014
1199
|
}
|
|
1015
1200
|
async processInputs(inputs) {
|
|
@@ -1498,15 +1683,13 @@ class Client {
|
|
|
1498
1683
|
}
|
|
1499
1684
|
return json;
|
|
1500
1685
|
}
|
|
1501
|
-
_checkStainlessVersion() {
|
|
1502
|
-
if (this.
|
|
1686
|
+
_checkStainlessVersion(minVersion) {
|
|
1687
|
+
if (this._stainlessVersionsChecked.has(minVersion))
|
|
1503
1688
|
return;
|
|
1504
|
-
this.
|
|
1689
|
+
this._stainlessVersionsChecked.add(minVersion);
|
|
1505
1690
|
this._ensureServerInfo()
|
|
1506
1691
|
.then((serverInfo) => {
|
|
1507
|
-
|
|
1508
|
-
_checkBackendVersion(serverInfo.version);
|
|
1509
|
-
}
|
|
1692
|
+
_checkBackendVersion(serverInfo?.version, minVersion);
|
|
1510
1693
|
})
|
|
1511
1694
|
.catch(() => {
|
|
1512
1695
|
// _ensureServerInfo handles and logs its own errors
|
|
@@ -1537,6 +1720,20 @@ class Client {
|
|
|
1537
1720
|
const serverInfo = await this._ensureServerInfo();
|
|
1538
1721
|
return serverInfo.instance_flags?.sdb_query_enabled === true;
|
|
1539
1722
|
}
|
|
1723
|
+
/**
|
|
1724
|
+
* Throw on SmithDB-only deployments, warn elsewhere. Call only when run-level
|
|
1725
|
+
* feedback has no sessionId.
|
|
1726
|
+
*/
|
|
1727
|
+
async _checkFeedbackSessionId() {
|
|
1728
|
+
const docs = "https://docs.langchain.com/langsmith/smithdb-sdk-migration#feedback-create";
|
|
1729
|
+
const serverInfo = await this._ensureServerInfo();
|
|
1730
|
+
if ((0, v2_migration_js_1.getQueryBackend)(serverInfo.instance_flags) === v2_migration_js_1.QueryBackend.SMITHDB_ONLY) {
|
|
1731
|
+
throw new Error(`sessionId must be provided when creating feedback for a run: this ` +
|
|
1732
|
+
`deployment cannot locate the run without it. See ${docs}`);
|
|
1733
|
+
}
|
|
1734
|
+
(0, warn_js_1.warnOnce)(`Creating feedback for a run without sessionId is deprecated and will ` +
|
|
1735
|
+
`stop working in a future release. See ${docs}`);
|
|
1736
|
+
}
|
|
1540
1737
|
async _getSettings() {
|
|
1541
1738
|
if (!this.settings) {
|
|
1542
1739
|
this.settings = this._get("/settings");
|
|
@@ -2055,7 +2252,22 @@ class Client {
|
|
|
2055
2252
|
return res;
|
|
2056
2253
|
});
|
|
2057
2254
|
}
|
|
2255
|
+
/** @deprecated Use `client.runs.retrieve()` instead. See https://docs.langchain.com/langsmith/smithdb-sdk-migration#runs-retrieve for the migration guide. Will be removed after Jan 31, 2027. */
|
|
2058
2256
|
async readRun(runId, { loadChildRuns } = { loadChildRuns: false }) {
|
|
2257
|
+
(0, warn_js_1.warnOnce)("readRun() is deprecated and will be removed after Jan 31, 2027. " +
|
|
2258
|
+
"Use client.runs.retrieve() instead. " +
|
|
2259
|
+
"See https://docs.langchain.com/langsmith/smithdb-sdk-migration#runs-retrieve for the migration guide.", { type: "DeprecationWarning", code: "LANGSMITH_DEPRECATED_READ_RUN" });
|
|
2260
|
+
return this._readRun(runId, { loadChildRuns });
|
|
2261
|
+
}
|
|
2262
|
+
/**
|
|
2263
|
+
* Fetch a run without emitting the `readRun()` deprecation warning.
|
|
2264
|
+
*
|
|
2265
|
+
* Internal callers use this so that a supported method doesn't warn about a
|
|
2266
|
+
* deprecated one the caller never invoked.
|
|
2267
|
+
*
|
|
2268
|
+
* @internal
|
|
2269
|
+
*/
|
|
2270
|
+
async _readRun(runId, { loadChildRuns } = { loadChildRuns: false }) {
|
|
2059
2271
|
(0, _uuid_js_1.assertUuid)(runId);
|
|
2060
2272
|
let run = _normalizeRunTimestamps(await this._get(`/runs/${runId}`));
|
|
2061
2273
|
if (loadChildRuns) {
|
|
@@ -2063,7 +2275,11 @@ class Client {
|
|
|
2063
2275
|
}
|
|
2064
2276
|
return run;
|
|
2065
2277
|
}
|
|
2278
|
+
/** @deprecated Use `client.runs.getURL()` instead. See https://docs.langchain.com/langsmith/smithdb-sdk-migration#runs-get-url for the migration guide. Will be removed after Jan 31, 2027. */
|
|
2066
2279
|
async getRunUrl({ runId, run, projectOpts, }) {
|
|
2280
|
+
(0, warn_js_1.warnOnce)("getRunUrl() is deprecated and will be removed after Jan 31, 2027. " +
|
|
2281
|
+
"Use client.runs.getURL() instead. " +
|
|
2282
|
+
"See https://docs.langchain.com/langsmith/smithdb-sdk-migration#runs-get-url for the migration guide.", { type: "DeprecationWarning", code: "LANGSMITH_DEPRECATED_GET_RUN_URL" });
|
|
2067
2283
|
if (run !== undefined) {
|
|
2068
2284
|
let sessionId;
|
|
2069
2285
|
if (run.session_id) {
|
|
@@ -2085,7 +2301,9 @@ class Client {
|
|
|
2085
2301
|
return `${this.getHostUrl()}/o/${tenantId}/projects/p/${sessionId}/r/${run.id}?poll=true`;
|
|
2086
2302
|
}
|
|
2087
2303
|
else if (runId !== undefined) {
|
|
2088
|
-
|
|
2304
|
+
// Via _readRun() rather than readRun() so callers don't also get a
|
|
2305
|
+
// readRun deprecation warning for a method they never called.
|
|
2306
|
+
const run_ = await this._readRun(runId);
|
|
2089
2307
|
if (!run_.app_path) {
|
|
2090
2308
|
throw new Error(`Run ${runId} has no app_path`);
|
|
2091
2309
|
}
|
|
@@ -2097,7 +2315,7 @@ class Client {
|
|
|
2097
2315
|
}
|
|
2098
2316
|
}
|
|
2099
2317
|
async _loadChildRuns(run) {
|
|
2100
|
-
const childRuns = await toArray(this.
|
|
2318
|
+
const childRuns = await toArray(this._listRuns({
|
|
2101
2319
|
isRoot: false,
|
|
2102
2320
|
projectId: run.session_id,
|
|
2103
2321
|
traceId: run.trace_id,
|
|
@@ -2130,6 +2348,7 @@ class Client {
|
|
|
2130
2348
|
}
|
|
2131
2349
|
/**
|
|
2132
2350
|
* List runs from the LangSmith server.
|
|
2351
|
+
* @deprecated Use `client.runs.query()` instead. See https://docs.langchain.com/langsmith/smithdb-sdk-migration#runs-query for the migration guide. Will be removed after Jan 31, 2027.
|
|
2133
2352
|
* @param projectId - The ID of the project to filter by.
|
|
2134
2353
|
* @param projectName - The name of the project to filter by.
|
|
2135
2354
|
* @param parentRunId - The ID of the parent run to filter by.
|
|
@@ -2211,6 +2430,20 @@ class Client {
|
|
|
2211
2430
|
* });
|
|
2212
2431
|
*/
|
|
2213
2432
|
async *listRuns(props) {
|
|
2433
|
+
(0, warn_js_1.warnOnce)("listRuns() is deprecated and will be removed after Jan 31, 2027. " +
|
|
2434
|
+
"Use client.runs.query() instead. " +
|
|
2435
|
+
"See https://docs.langchain.com/langsmith/smithdb-sdk-migration#runs-query for the migration guide.", { type: "DeprecationWarning", code: "LANGSMITH_DEPRECATED_LIST_RUNS" });
|
|
2436
|
+
yield* this._listRuns(props);
|
|
2437
|
+
}
|
|
2438
|
+
/**
|
|
2439
|
+
* List runs without emitting the `listRuns()` deprecation warning.
|
|
2440
|
+
*
|
|
2441
|
+
* Internal callers use this so that a supported method doesn't warn about a
|
|
2442
|
+
* deprecated one the caller never invoked.
|
|
2443
|
+
*
|
|
2444
|
+
* @internal
|
|
2445
|
+
*/
|
|
2446
|
+
async *_listRuns(props) {
|
|
2214
2447
|
const { projectId, projectName, parentRunId, traceId, referenceExampleId, startTime, executionOrder, isRoot, runType, error, id, query, filter, traceFilter, treeFilter, limit, select, order, } = props;
|
|
2215
2448
|
let projectIds = [];
|
|
2216
2449
|
if (projectId) {
|
|
@@ -2344,7 +2577,11 @@ class Client {
|
|
|
2344
2577
|
}
|
|
2345
2578
|
}
|
|
2346
2579
|
}
|
|
2580
|
+
/** @deprecated Use `client.threads.listTraces()` instead. See https://docs.langchain.com/langsmith/smithdb-sdk-migration#threads-list-traces for the migration guide. Will be removed after Jan 31, 2027. */
|
|
2347
2581
|
async *readThread(props) {
|
|
2582
|
+
(0, warn_js_1.warnOnce)("readThread() is deprecated and will be removed after Jan 31, 2027. " +
|
|
2583
|
+
"Use client.threads.listTraces() instead. " +
|
|
2584
|
+
"See https://docs.langchain.com/langsmith/smithdb-sdk-migration#threads-list-traces for the migration guide.", { type: "DeprecationWarning", code: "LANGSMITH_DEPRECATED_READ_THREAD" });
|
|
2348
2585
|
const { threadId, projectId, projectName, isRoot = true, limit, filter: userFilter, order = "asc", } = props;
|
|
2349
2586
|
if (!projectId && !projectName) {
|
|
2350
2587
|
throw new Error("threadId requires projectId or projectName");
|
|
@@ -2353,7 +2590,9 @@ class Client {
|
|
|
2353
2590
|
const combinedFilter = userFilter
|
|
2354
2591
|
? `and(${threadFilter}, ${userFilter})`
|
|
2355
2592
|
: threadFilter;
|
|
2356
|
-
|
|
2593
|
+
// Via _listRuns() rather than listRuns(): readThread() already warned, and it
|
|
2594
|
+
// points at threads.listTraces() rather than listRuns()'s runs.query().
|
|
2595
|
+
yield* this._listRuns({
|
|
2357
2596
|
projectId: projectId ?? undefined,
|
|
2358
2597
|
projectName: projectName ?? undefined,
|
|
2359
2598
|
isRoot,
|
|
@@ -2362,7 +2601,11 @@ class Client {
|
|
|
2362
2601
|
order,
|
|
2363
2602
|
});
|
|
2364
2603
|
}
|
|
2604
|
+
/** @deprecated Use `client.threads.query()` instead. See https://docs.langchain.com/langsmith/smithdb-sdk-migration#threads-query for the migration guide. Will be removed after Jan 31, 2027. */
|
|
2365
2605
|
async listThreads(props) {
|
|
2606
|
+
(0, warn_js_1.warnOnce)("listThreads() is deprecated and will be removed after Jan 31, 2027. " +
|
|
2607
|
+
"Use client.threads.query() instead. " +
|
|
2608
|
+
"See https://docs.langchain.com/langsmith/smithdb-sdk-migration#threads-query for the migration guide.", { type: "DeprecationWarning", code: "LANGSMITH_DEPRECATED_LIST_THREADS" });
|
|
2366
2609
|
const { projectId, projectName, limit, offset = 0, filter, startTime, isRoot = true, } = props;
|
|
2367
2610
|
if (!projectId && !projectName) {
|
|
2368
2611
|
throw new Error("Either projectId or projectName must be provided");
|
|
@@ -2512,7 +2755,11 @@ class Client {
|
|
|
2512
2755
|
const result = await response.json();
|
|
2513
2756
|
return result;
|
|
2514
2757
|
}
|
|
2758
|
+
/** @deprecated Use `client.runs.share.create()` instead. See https://docs.langchain.com/langsmith/smithdb-sdk-migration#share-and-read-public-runs for the migration guide. Will be removed after Jan 31, 2027. */
|
|
2515
2759
|
async shareRun(runId, { shareId } = {}) {
|
|
2760
|
+
(0, warn_js_1.warnOnce)("shareRun() is deprecated and will be removed after Jan 31, 2027. " +
|
|
2761
|
+
"Use client.runs.share.create() instead. " +
|
|
2762
|
+
"See https://docs.langchain.com/langsmith/smithdb-sdk-migration#share-and-read-public-runs for the migration guide.", { type: "DeprecationWarning", code: "LANGSMITH_DEPRECATED_SHARE_RUN" });
|
|
2516
2763
|
const data = {
|
|
2517
2764
|
run_id: runId,
|
|
2518
2765
|
share_token: shareId || uuid.v4(),
|
|
@@ -2536,7 +2783,11 @@ class Client {
|
|
|
2536
2783
|
}
|
|
2537
2784
|
return `${this.getHostUrl()}/public/${result["share_token"]}/r`;
|
|
2538
2785
|
}
|
|
2786
|
+
/** @deprecated Use `client.runs.share.delete()` instead. See https://docs.langchain.com/langsmith/smithdb-sdk-migration#share-and-read-public-runs for the migration guide. Will be removed after Jan 31, 2027. */
|
|
2539
2787
|
async unshareRun(runId) {
|
|
2788
|
+
(0, warn_js_1.warnOnce)("unshareRun() is deprecated and will be removed after Jan 31, 2027. " +
|
|
2789
|
+
"Use client.runs.share.delete() instead. " +
|
|
2790
|
+
"See https://docs.langchain.com/langsmith/smithdb-sdk-migration#share-and-read-public-runs for the migration guide.", { type: "DeprecationWarning", code: "LANGSMITH_DEPRECATED_UNSHARE_RUN" });
|
|
2540
2791
|
(0, _uuid_js_1.assertUuid)(runId);
|
|
2541
2792
|
await this.caller.call(async () => {
|
|
2542
2793
|
const res = await this._fetch(`${this.apiUrl}/runs/${runId}/share`, {
|
|
@@ -2549,7 +2800,14 @@ class Client {
|
|
|
2549
2800
|
return res;
|
|
2550
2801
|
});
|
|
2551
2802
|
}
|
|
2803
|
+
/** @deprecated Use `client.runs.retrieve({ selects: ["SHARE_URL"] })` instead. See https://docs.langchain.com/langsmith/smithdb-sdk-migration#share-and-read-public-runs for the migration guide. Will be removed after Jan 31, 2027. */
|
|
2552
2804
|
async readRunSharedLink(runId) {
|
|
2805
|
+
(0, warn_js_1.warnOnce)("readRunSharedLink() is deprecated and will be removed after Jan 31, 2027. " +
|
|
2806
|
+
'Use client.runs.retrieve({ selects: ["SHARE_URL"] }) instead. ' +
|
|
2807
|
+
"See https://docs.langchain.com/langsmith/smithdb-sdk-migration#share-and-read-public-runs for the migration guide.", {
|
|
2808
|
+
type: "DeprecationWarning",
|
|
2809
|
+
code: "LANGSMITH_DEPRECATED_READ_RUN_SHARED_LINK",
|
|
2810
|
+
});
|
|
2553
2811
|
(0, _uuid_js_1.assertUuid)(runId);
|
|
2554
2812
|
const response = await this.caller.call(async () => {
|
|
2555
2813
|
const res = await this._fetch(`${this.apiUrl}/runs/${runId}/share`, {
|
|
@@ -2567,7 +2825,14 @@ class Client {
|
|
|
2567
2825
|
}
|
|
2568
2826
|
return `${this.getHostUrl()}/public/${result["share_token"]}/r`;
|
|
2569
2827
|
}
|
|
2828
|
+
/** @deprecated Use `client.public.runs.query()` instead. See https://docs.langchain.com/langsmith/smithdb-sdk-migration#share-and-read-public-runs for the migration guide. Will be removed after Jan 31, 2027. */
|
|
2570
2829
|
async listSharedRuns(shareToken, { runIds, } = {}) {
|
|
2830
|
+
(0, warn_js_1.warnOnce)("listSharedRuns() is deprecated and will be removed after Jan 31, 2027. " +
|
|
2831
|
+
"Use client.public.runs.query() instead. " +
|
|
2832
|
+
"See https://docs.langchain.com/langsmith/smithdb-sdk-migration#share-and-read-public-runs for the migration guide.", {
|
|
2833
|
+
type: "DeprecationWarning",
|
|
2834
|
+
code: "LANGSMITH_DEPRECATED_LIST_SHARED_RUNS",
|
|
2835
|
+
});
|
|
2571
2836
|
const queryParams = new URLSearchParams({
|
|
2572
2837
|
share_token: shareToken,
|
|
2573
2838
|
});
|
|
@@ -3631,13 +3896,19 @@ class Client {
|
|
|
3631
3896
|
return res;
|
|
3632
3897
|
});
|
|
3633
3898
|
}
|
|
3634
|
-
async createFeedback(
|
|
3899
|
+
async createFeedback(runIdOrParams, keyArg, optionsArg) {
|
|
3900
|
+
const { runId = null, key, score, value, correction, comment, sourceInfo, feedbackSourceType = "api", sourceRunId, feedbackId, feedbackConfig, projectId, comparativeExperimentId, sessionId, startTime, extendTraceRetention, } = typeof runIdOrParams === "object" && runIdOrParams !== null
|
|
3901
|
+
? runIdOrParams
|
|
3902
|
+
: { runId: runIdOrParams, key: keyArg, ...optionsArg };
|
|
3635
3903
|
if (!runId && !projectId) {
|
|
3636
3904
|
throw new Error("One of runId or projectId must be provided");
|
|
3637
3905
|
}
|
|
3638
3906
|
if (runId && projectId) {
|
|
3639
3907
|
throw new Error("Only one of runId or projectId can be provided");
|
|
3640
3908
|
}
|
|
3909
|
+
if (runId && sessionId === undefined) {
|
|
3910
|
+
await this._checkFeedbackSessionId();
|
|
3911
|
+
}
|
|
3641
3912
|
const feedback_source = {
|
|
3642
3913
|
type: feedbackSourceType ?? "api",
|
|
3643
3914
|
metadata: sourceInfo ?? {},
|
|
@@ -4150,8 +4421,9 @@ class Client {
|
|
|
4150
4421
|
* - `RunKey[]` (preferred): each entry carries the run's full lookup key, so
|
|
4151
4422
|
* it can be located directly without a scan. Required for workspaces served
|
|
4152
4423
|
* by SmithDB; routes to `POST /runs/by-key`.
|
|
4153
|
-
* - `string[]`: a plain list of run IDs.
|
|
4154
|
-
*
|
|
4424
|
+
* - `string[]`: a plain list of run IDs. **Deprecated**: this path will be
|
|
4425
|
+
* removed after Jan 31, 2027; prefer the key form. Routes to `POST /runs`.
|
|
4426
|
+
* See https://docs.langchain.com/langsmith/smithdb-sdk-migration#annotation-queues-add-runs.
|
|
4155
4427
|
*
|
|
4156
4428
|
* If every element is a string (or the list is empty) it is treated as run
|
|
4157
4429
|
* IDs; otherwise the list is treated as `RunKey` objects.
|
|
@@ -4182,6 +4454,12 @@ class Client {
|
|
|
4182
4454
|
}));
|
|
4183
4455
|
}
|
|
4184
4456
|
else {
|
|
4457
|
+
(0, warn_js_1.warnOnce)("Passing run IDs as strings to addRunsToAnnotationQueue() is deprecated and will be removed after Jan 31, 2027. " +
|
|
4458
|
+
"Use RunKey[] instead. " +
|
|
4459
|
+
"See https://docs.langchain.com/langsmith/smithdb-sdk-migration#annotation-queues-add-runs for the migration guide.", {
|
|
4460
|
+
type: "DeprecationWarning",
|
|
4461
|
+
code: "LANGSMITH_DEPRECATED_ADD_RUNS_STRING_IDS",
|
|
4462
|
+
});
|
|
4185
4463
|
url = base;
|
|
4186
4464
|
body = JSON.stringify(runs.map((id, i) => (0, _uuid_js_1.assertUuid)(id, `runs[${i}]`).toString()));
|
|
4187
4465
|
}
|