langsmith 0.8.8 → 0.8.10
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/resources/annotation-queues/annotation-queues.cjs +10 -0
- package/dist/_openapi_client/resources/annotation-queues/annotation-queues.d.ts +10 -0
- package/dist/_openapi_client/resources/annotation-queues/annotation-queues.js +10 -0
- package/dist/_openapi_client/resources/annotation-queues/runs.cjs +13 -1
- package/dist/_openapi_client/resources/annotation-queues/runs.d.ts +13 -1
- package/dist/_openapi_client/resources/annotation-queues/runs.js +13 -1
- package/dist/_openapi_client/resources/datasets/experiment-runs.cjs +2 -0
- package/dist/_openapi_client/resources/datasets/experiment-runs.d.ts +2 -0
- package/dist/_openapi_client/resources/datasets/experiment-runs.js +2 -0
- package/dist/_openapi_client/resources/issues.d.ts +1 -1
- package/dist/_openapi_client/resources/public/runs.cjs +9 -7
- package/dist/_openapi_client/resources/public/runs.d.ts +8 -6
- package/dist/_openapi_client/resources/public/runs.js +9 -7
- package/dist/_openapi_client/resources/runs/runs.cjs +11 -6
- package/dist/_openapi_client/resources/runs/runs.d.ts +11 -6
- package/dist/_openapi_client/resources/runs/runs.js +11 -6
- package/dist/_openapi_client/resources/runs/share.cjs +4 -0
- package/dist/_openapi_client/resources/runs/share.d.ts +4 -0
- package/dist/_openapi_client/resources/runs/share.js +4 -0
- package/dist/_openapi_client/resources/threads.cjs +11 -8
- package/dist/_openapi_client/resources/threads.d.ts +11 -8
- package/dist/_openapi_client/resources/threads.js +11 -8
- package/dist/_openapi_client/resources/traces.cjs +6 -3
- package/dist/_openapi_client/resources/traces.d.ts +6 -3
- package/dist/_openapi_client/resources/traces.js +6 -3
- package/dist/client.cjs +295 -24
- package/dist/client.d.ts +63 -9
- package/dist/client.js +295 -24
- package/dist/evaluation/evaluate_comparative.cjs +7 -4
- package/dist/evaluation/evaluate_comparative.js +7 -4
- package/dist/experimental/vercel/_agent_type.cjs +30 -0
- package/dist/experimental/vercel/_agent_type.d.ts +5 -0
- package/dist/experimental/vercel/_agent_type.js +26 -0
- package/dist/experimental/vercel/telemetry.cjs +2 -7
- package/dist/experimental/vercel/telemetry.js +2 -7
- package/dist/experimental/vercel/wrap.cjs +5 -11
- package/dist/experimental/vercel/wrap.js +6 -12
- 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 +34 -7
- package/dist/sandbox/command_handle.d.ts +1 -0
- package/dist/sandbox/command_handle.js +34 -7
- package/dist/sandbox/ws_execute.cjs +7 -3
- package/dist/sandbox/ws_execute.d.ts +4 -2
- package/dist/sandbox/ws_execute.js +7 -3
- package/dist/utils/_git.cjs +28 -1
- package/dist/utils/_git.js +28 -1
- package/dist/utils/ls_agent_type.cjs +31 -0
- package/dist/utils/ls_agent_type.d.ts +9 -0
- package/dist/utils/ls_agent_type.js +25 -0
- package/dist/utils/profiles.cjs +125 -1
- package/dist/utils/profiles.d.ts +6 -0
- package/dist/utils/profiles.js +124 -1
- 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/dist/wrappers/openai.cjs +4 -0
- package/dist/wrappers/openai.js +4 -0
- package/dist/wrappers/openai_agents.cjs +15 -12
- package/dist/wrappers/openai_agents.js +15 -12
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -46,6 +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 v2_migration_js_1 = require("./utils/v2_migration.cjs");
|
|
49
50
|
const prompts_js_1 = require("./utils/prompts.cjs");
|
|
50
51
|
const error_js_1 = require("./utils/error.cjs");
|
|
51
52
|
const index_js_3 = require("./utils/prompt_cache/index.cjs");
|
|
@@ -192,6 +193,72 @@ exports.DEFAULT_MAX_SIZE_BYTES = 1024 * 1024 * 1024; // 1GB
|
|
|
192
193
|
const SERVER_INFO_REQUEST_TIMEOUT_MS = 10000;
|
|
193
194
|
/** Maximum number of operations to batch in a single request. */
|
|
194
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
|
+
}
|
|
195
262
|
class AutoBatchQueue {
|
|
196
263
|
constructor(maxSizeBytes) {
|
|
197
264
|
Object.defineProperty(this, "items", {
|
|
@@ -611,13 +678,26 @@ class Client {
|
|
|
611
678
|
writable: true,
|
|
612
679
|
value: void 0
|
|
613
680
|
});
|
|
681
|
+
/** `config.fetchOptions` without its `headers`, which are merged separately. */
|
|
614
682
|
Object.defineProperty(this, "fetchOptions", {
|
|
615
683
|
enumerable: true,
|
|
616
684
|
configurable: true,
|
|
617
685
|
writable: true,
|
|
618
686
|
value: void 0
|
|
619
687
|
});
|
|
620
|
-
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", {
|
|
621
701
|
enumerable: true,
|
|
622
702
|
configurable: true,
|
|
623
703
|
writable: true,
|
|
@@ -813,7 +893,8 @@ class Client {
|
|
|
813
893
|
config.hideInputs ?? config.anonymizer ?? defaultConfig.hideInputs;
|
|
814
894
|
this.hideOutputs =
|
|
815
895
|
config.hideOutputs ?? config.anonymizer ?? defaultConfig.hideOutputs;
|
|
816
|
-
this.hideMetadata =
|
|
896
|
+
this.hideMetadata =
|
|
897
|
+
config.hideMetadata ?? config.anonymizer ?? defaultConfig.hideMetadata;
|
|
817
898
|
this.anonymizer = config.anonymizer;
|
|
818
899
|
this.omitTracedRuntimeInfo = config.omitTracedRuntimeInfo ?? false;
|
|
819
900
|
this.autoBatchTracing = config.autoBatchTracing ?? this.autoBatchTracing;
|
|
@@ -822,8 +903,15 @@ class Client {
|
|
|
822
903
|
config.blockOnRootRunFinalization ?? this.blockOnRootRunFinalization;
|
|
823
904
|
this.batchSizeBytesLimit = config.batchSizeBytesLimit;
|
|
824
905
|
this.batchSizeLimit = config.batchSizeLimit;
|
|
825
|
-
|
|
826
|
-
this.
|
|
906
|
+
const { headers: fetchOptionsHeaders, ...fetchOptions } = config.fetchOptions || {};
|
|
907
|
+
this.fetchOptions = fetchOptions;
|
|
908
|
+
// Kept apart from `fetchOptions` so they can be merged *under* the required
|
|
909
|
+
// headers instead of replacing the whole set at each call site.
|
|
910
|
+
this._fetchOptionsHeaders = normalizeHeaders(fetchOptionsHeaders);
|
|
911
|
+
// Validated eagerly so malformed input fails at construction, but stored
|
|
912
|
+
// as given: `get headers` hands this object back to the caller.
|
|
913
|
+
assertValidHeaders(config.headers);
|
|
914
|
+
this._customHeaders = config.headers ?? {};
|
|
827
915
|
this.manualFlushMode = config.manualFlushMode ?? this.manualFlushMode;
|
|
828
916
|
this._tracingMode = (0, env_js_1.resolveTracingMode)(config.tracingMode);
|
|
829
917
|
if (this._tracingMode === "otel") {
|
|
@@ -858,8 +946,6 @@ class Client {
|
|
|
858
946
|
// Use the global singleton instance
|
|
859
947
|
this._promptCache = index_js_3.promptCacheSingleton;
|
|
860
948
|
}
|
|
861
|
-
// Initialize custom headers
|
|
862
|
-
this._customHeaders = config.headers ?? {};
|
|
863
949
|
}
|
|
864
950
|
static getDefaultClientConfig() {
|
|
865
951
|
const profileConfig = (0, profiles_js_1.loadProfileClientConfig)();
|
|
@@ -931,11 +1017,46 @@ class Client {
|
|
|
931
1017
|
return this.webUrl;
|
|
932
1018
|
}
|
|
933
1019
|
}
|
|
1020
|
+
/**
|
|
1021
|
+
* The headers this client sets from its own config, which a caller-supplied
|
|
1022
|
+
* header must not replace.
|
|
1023
|
+
*
|
|
1024
|
+
* Only what the client *actually* supplies: passing an explicit `Authorization`
|
|
1025
|
+
* or `x-api-key` header with no configured credential is a supported way to
|
|
1026
|
+
* authenticate (see `hasExplicitAuthHeader`), so those must survive.
|
|
1027
|
+
*/
|
|
1028
|
+
get _sdkControlledHeaders() {
|
|
1029
|
+
const names = new Set();
|
|
1030
|
+
if (this.apiKey !== undefined) {
|
|
1031
|
+
names.add("x-api-key");
|
|
1032
|
+
}
|
|
1033
|
+
else {
|
|
1034
|
+
const profileAuthHeader = this.profileAuth?.currentAuthHeader();
|
|
1035
|
+
if (profileAuthHeader) {
|
|
1036
|
+
names.add(profileAuthHeader.name.toLowerCase());
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
if (this.workspaceId) {
|
|
1040
|
+
names.add("x-tenant-id");
|
|
1041
|
+
}
|
|
1042
|
+
return names;
|
|
1043
|
+
}
|
|
1044
|
+
/**
|
|
1045
|
+
* Headers supplied by the caller, through either `config.headers` or
|
|
1046
|
+
* `config.fetchOptions.headers`, with the ones this SDK sets removed.
|
|
1047
|
+
*
|
|
1048
|
+
* `_customHeaders` is normalized here rather than at assignment because it is
|
|
1049
|
+
* public and mutable: `get headers` hands back the caller's own object, so its
|
|
1050
|
+
* contents can change (and can become malformed) at any point.
|
|
1051
|
+
*/
|
|
1052
|
+
get _callerHeaders() {
|
|
1053
|
+
return mergeCallerHeaders(normalizeHeaders(this._customHeaders), this._fetchOptionsHeaders, this._sdkControlledHeaders);
|
|
1054
|
+
}
|
|
934
1055
|
get _mergedHeaders() {
|
|
935
|
-
// Start with
|
|
1056
|
+
// Start with caller-supplied headers so they don't override required headers
|
|
936
1057
|
const headers = {
|
|
937
1058
|
"User-Agent": `langsmith-js/${index_js_1.__version__}`,
|
|
938
|
-
...this.
|
|
1059
|
+
...this._callerHeaders,
|
|
939
1060
|
};
|
|
940
1061
|
// Required headers that should not be overridden
|
|
941
1062
|
if (this.apiKey !== undefined) {
|
|
@@ -952,6 +1073,35 @@ class Client {
|
|
|
952
1073
|
}
|
|
953
1074
|
return headers;
|
|
954
1075
|
}
|
|
1076
|
+
/**
|
|
1077
|
+
* The auth options and caller headers to build the generated client with.
|
|
1078
|
+
*
|
|
1079
|
+
* The generated client applies `defaultHeaders` *after* its own auth headers,
|
|
1080
|
+
* so the ones this SDK sets are already dropped from `_callerHeaders` to keep
|
|
1081
|
+
* the precedence of `_mergedHeaders`, where required headers win.
|
|
1082
|
+
*/
|
|
1083
|
+
get _openAPIAuth() {
|
|
1084
|
+
const headers = { ...this._callerHeaders };
|
|
1085
|
+
// A caller may authenticate by supplying `x-api-key` themselves. The
|
|
1086
|
+
// generated client rejects that as a header (its `validateHeaders` requires
|
|
1087
|
+
// its own `apiKey` to be set), so hand it over as the `apiKey` option and
|
|
1088
|
+
// drop the header to avoid sending the same value twice.
|
|
1089
|
+
const callerApiKeyName = Object.keys(headers).find((name) => name.toLowerCase() === "x-api-key");
|
|
1090
|
+
let apiKey = this.apiKey;
|
|
1091
|
+
if (apiKey === undefined && callerApiKeyName !== undefined) {
|
|
1092
|
+
apiKey = headers[callerApiKeyName] ?? undefined;
|
|
1093
|
+
delete headers[callerApiKeyName];
|
|
1094
|
+
}
|
|
1095
|
+
if (apiKey === undefined && this.workspaceId === undefined) {
|
|
1096
|
+
// Let the wrapped `fetch` supply auth (profile auth, an explicit
|
|
1097
|
+
// `Authorization` header, or none at all).
|
|
1098
|
+
headers["X-API-Key"] = null;
|
|
1099
|
+
}
|
|
1100
|
+
return {
|
|
1101
|
+
apiKey,
|
|
1102
|
+
defaultHeaders: Object.keys(headers).length > 0 ? headers : undefined,
|
|
1103
|
+
};
|
|
1104
|
+
}
|
|
955
1105
|
/**
|
|
956
1106
|
* Get or set custom headers for the client.
|
|
957
1107
|
* Custom headers are merged with default headers (User-Agent, x-api-key, x-tenant-id).
|
|
@@ -961,6 +1111,7 @@ class Client {
|
|
|
961
1111
|
return this._customHeaders;
|
|
962
1112
|
}
|
|
963
1113
|
set headers(value) {
|
|
1114
|
+
assertValidHeaders(value);
|
|
964
1115
|
this._customHeaders = value ?? {};
|
|
965
1116
|
}
|
|
966
1117
|
_getOpenAPIBaseUrl() {
|
|
@@ -971,19 +1122,36 @@ class Client {
|
|
|
971
1122
|
}
|
|
972
1123
|
return url;
|
|
973
1124
|
}
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
1125
|
+
/**
|
|
1126
|
+
* The generated OpenAPI client, rebuilt whenever its auth or headers change.
|
|
1127
|
+
*
|
|
1128
|
+
* The generated client captures `defaultHeaders` and `apiKey` when it is
|
|
1129
|
+
* built, while the handwritten paths recompute `_mergedHeaders` per request.
|
|
1130
|
+
* Rebuilding on change keeps the two halves from diverging when the inputs
|
|
1131
|
+
* move underneath us — a caller mutating the object returned by
|
|
1132
|
+
* `get headers`, or a profile whose auth header only becomes available after
|
|
1133
|
+
* its token is refreshed.
|
|
1134
|
+
*/
|
|
1135
|
+
get openAPIClient() {
|
|
1136
|
+
const auth = this._openAPIAuth;
|
|
1137
|
+
const signature = JSON.stringify([auth.apiKey, auth.defaultHeaders]);
|
|
1138
|
+
if (this._openAPIClient === undefined ||
|
|
1139
|
+
this._openAPIClientSignature !== signature) {
|
|
1140
|
+
this._openAPIClientSignature = signature;
|
|
1141
|
+
this._openAPIClient = this._newOpenAPIClient(auth);
|
|
1142
|
+
}
|
|
1143
|
+
return this._openAPIClient;
|
|
1144
|
+
}
|
|
1145
|
+
_newOpenAPIClient(auth = this._openAPIAuth) {
|
|
1146
|
+
const { method: _method, body: _body, signal: _signal, ...openAPIFetchOptions } = this.fetchOptions;
|
|
979
1147
|
return new index_js_2.Langsmith({
|
|
980
|
-
apiKey:
|
|
1148
|
+
apiKey: auth.apiKey,
|
|
981
1149
|
tenantID: this.workspaceId,
|
|
982
1150
|
baseURL: this._getOpenAPIBaseUrl(),
|
|
983
1151
|
timeout: this.timeout_ms,
|
|
984
1152
|
fetch: this._fetch,
|
|
985
1153
|
fetchOptions: openAPIFetchOptions,
|
|
986
|
-
defaultHeaders,
|
|
1154
|
+
defaultHeaders: auth.defaultHeaders,
|
|
987
1155
|
});
|
|
988
1156
|
}
|
|
989
1157
|
_getPlatformEndpointPath(path) {
|
|
@@ -1388,6 +1556,9 @@ class Client {
|
|
|
1388
1556
|
const batchSizeBytes = batch.reduce((sum, item) => sum + (item.size ?? 0), 0);
|
|
1389
1557
|
try {
|
|
1390
1558
|
if (this.langSmithToOTELTranslator !== undefined) {
|
|
1559
|
+
for (const item of batch) {
|
|
1560
|
+
item.item = await this._maskRunMetadata(item.item);
|
|
1561
|
+
}
|
|
1391
1562
|
this._sendBatchToOTELTranslator(batch);
|
|
1392
1563
|
}
|
|
1393
1564
|
else {
|
|
@@ -1468,6 +1639,25 @@ class Client {
|
|
|
1468
1639
|
this.langSmithToOTELTranslator.exportBatch(operations, otelContextMap);
|
|
1469
1640
|
}
|
|
1470
1641
|
}
|
|
1642
|
+
async _maskRunMetadata(run) {
|
|
1643
|
+
if (run.extra?.metadata == null) {
|
|
1644
|
+
return run;
|
|
1645
|
+
}
|
|
1646
|
+
return {
|
|
1647
|
+
...run,
|
|
1648
|
+
extra: {
|
|
1649
|
+
...run.extra,
|
|
1650
|
+
metadata: await this.processMetadata(run.extra.metadata),
|
|
1651
|
+
},
|
|
1652
|
+
};
|
|
1653
|
+
}
|
|
1654
|
+
async _mergeRuntimeEnvAndMaskMetadata(run) {
|
|
1655
|
+
const merged = mergeRuntimeEnvIntoRun(run, this.cachedLSEnvVarsForMetadata, this.omitTracedRuntimeInfo);
|
|
1656
|
+
if (this.omitTracedRuntimeInfo) {
|
|
1657
|
+
return merged;
|
|
1658
|
+
}
|
|
1659
|
+
return this._maskRunMetadata(merged);
|
|
1660
|
+
}
|
|
1471
1661
|
async processRunOperation(item) {
|
|
1472
1662
|
clearTimeout(this.autoBatchTimeout);
|
|
1473
1663
|
this.autoBatchTimeout = undefined;
|
|
@@ -1560,7 +1750,7 @@ class Client {
|
|
|
1560
1750
|
async _checkFeedbackSessionId() {
|
|
1561
1751
|
const docs = "https://docs.langchain.com/langsmith/smithdb-sdk-migration#feedback-create";
|
|
1562
1752
|
const serverInfo = await this._ensureServerInfo();
|
|
1563
|
-
if (serverInfo.instance_flags
|
|
1753
|
+
if ((0, v2_migration_js_1.getQueryBackend)(serverInfo.instance_flags) === v2_migration_js_1.QueryBackend.SMITHDB_ONLY) {
|
|
1564
1754
|
throw new Error(`sessionId must be provided when creating feedback for a run: this ` +
|
|
1565
1755
|
`deployment cannot locate the run without it. See ${docs}`);
|
|
1566
1756
|
}
|
|
@@ -1624,7 +1814,7 @@ class Client {
|
|
|
1624
1814
|
}).catch(console.error);
|
|
1625
1815
|
return;
|
|
1626
1816
|
}
|
|
1627
|
-
const mergedRunCreateParam =
|
|
1817
|
+
const mergedRunCreateParam = await this._mergeRuntimeEnvAndMaskMetadata(runCreate);
|
|
1628
1818
|
if (options?.apiKey !== undefined) {
|
|
1629
1819
|
headers["x-api-key"] = options.apiKey;
|
|
1630
1820
|
}
|
|
@@ -2085,7 +2275,22 @@ class Client {
|
|
|
2085
2275
|
return res;
|
|
2086
2276
|
});
|
|
2087
2277
|
}
|
|
2278
|
+
/** @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. */
|
|
2088
2279
|
async readRun(runId, { loadChildRuns } = { loadChildRuns: false }) {
|
|
2280
|
+
(0, warn_js_1.warnOnce)("readRun() is deprecated and will be removed after Jan 31, 2027. " +
|
|
2281
|
+
"Use client.runs.retrieve() instead. " +
|
|
2282
|
+
"See https://docs.langchain.com/langsmith/smithdb-sdk-migration#runs-retrieve for the migration guide.", { type: "DeprecationWarning", code: "LANGSMITH_DEPRECATED_READ_RUN" });
|
|
2283
|
+
return this._readRun(runId, { loadChildRuns });
|
|
2284
|
+
}
|
|
2285
|
+
/**
|
|
2286
|
+
* Fetch a run without emitting the `readRun()` deprecation warning.
|
|
2287
|
+
*
|
|
2288
|
+
* Internal callers use this so that a supported method doesn't warn about a
|
|
2289
|
+
* deprecated one the caller never invoked.
|
|
2290
|
+
*
|
|
2291
|
+
* @internal
|
|
2292
|
+
*/
|
|
2293
|
+
async _readRun(runId, { loadChildRuns } = { loadChildRuns: false }) {
|
|
2089
2294
|
(0, _uuid_js_1.assertUuid)(runId);
|
|
2090
2295
|
let run = _normalizeRunTimestamps(await this._get(`/runs/${runId}`));
|
|
2091
2296
|
if (loadChildRuns) {
|
|
@@ -2093,7 +2298,11 @@ class Client {
|
|
|
2093
2298
|
}
|
|
2094
2299
|
return run;
|
|
2095
2300
|
}
|
|
2301
|
+
/** @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. */
|
|
2096
2302
|
async getRunUrl({ runId, run, projectOpts, }) {
|
|
2303
|
+
(0, warn_js_1.warnOnce)("getRunUrl() is deprecated and will be removed after Jan 31, 2027. " +
|
|
2304
|
+
"Use client.runs.getURL() instead. " +
|
|
2305
|
+
"See https://docs.langchain.com/langsmith/smithdb-sdk-migration#runs-get-url for the migration guide.", { type: "DeprecationWarning", code: "LANGSMITH_DEPRECATED_GET_RUN_URL" });
|
|
2097
2306
|
if (run !== undefined) {
|
|
2098
2307
|
let sessionId;
|
|
2099
2308
|
if (run.session_id) {
|
|
@@ -2115,7 +2324,9 @@ class Client {
|
|
|
2115
2324
|
return `${this.getHostUrl()}/o/${tenantId}/projects/p/${sessionId}/r/${run.id}?poll=true`;
|
|
2116
2325
|
}
|
|
2117
2326
|
else if (runId !== undefined) {
|
|
2118
|
-
|
|
2327
|
+
// Via _readRun() rather than readRun() so callers don't also get a
|
|
2328
|
+
// readRun deprecation warning for a method they never called.
|
|
2329
|
+
const run_ = await this._readRun(runId);
|
|
2119
2330
|
if (!run_.app_path) {
|
|
2120
2331
|
throw new Error(`Run ${runId} has no app_path`);
|
|
2121
2332
|
}
|
|
@@ -2127,7 +2338,7 @@ class Client {
|
|
|
2127
2338
|
}
|
|
2128
2339
|
}
|
|
2129
2340
|
async _loadChildRuns(run) {
|
|
2130
|
-
const childRuns = await toArray(this.
|
|
2341
|
+
const childRuns = await toArray(this._listRuns({
|
|
2131
2342
|
isRoot: false,
|
|
2132
2343
|
projectId: run.session_id,
|
|
2133
2344
|
traceId: run.trace_id,
|
|
@@ -2160,6 +2371,7 @@ class Client {
|
|
|
2160
2371
|
}
|
|
2161
2372
|
/**
|
|
2162
2373
|
* List runs from the LangSmith server.
|
|
2374
|
+
* @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.
|
|
2163
2375
|
* @param projectId - The ID of the project to filter by.
|
|
2164
2376
|
* @param projectName - The name of the project to filter by.
|
|
2165
2377
|
* @param parentRunId - The ID of the parent run to filter by.
|
|
@@ -2241,6 +2453,20 @@ class Client {
|
|
|
2241
2453
|
* });
|
|
2242
2454
|
*/
|
|
2243
2455
|
async *listRuns(props) {
|
|
2456
|
+
(0, warn_js_1.warnOnce)("listRuns() is deprecated and will be removed after Jan 31, 2027. " +
|
|
2457
|
+
"Use client.runs.query() instead. " +
|
|
2458
|
+
"See https://docs.langchain.com/langsmith/smithdb-sdk-migration#runs-query for the migration guide.", { type: "DeprecationWarning", code: "LANGSMITH_DEPRECATED_LIST_RUNS" });
|
|
2459
|
+
yield* this._listRuns(props);
|
|
2460
|
+
}
|
|
2461
|
+
/**
|
|
2462
|
+
* List runs without emitting the `listRuns()` deprecation warning.
|
|
2463
|
+
*
|
|
2464
|
+
* Internal callers use this so that a supported method doesn't warn about a
|
|
2465
|
+
* deprecated one the caller never invoked.
|
|
2466
|
+
*
|
|
2467
|
+
* @internal
|
|
2468
|
+
*/
|
|
2469
|
+
async *_listRuns(props) {
|
|
2244
2470
|
const { projectId, projectName, parentRunId, traceId, referenceExampleId, startTime, executionOrder, isRoot, runType, error, id, query, filter, traceFilter, treeFilter, limit, select, order, } = props;
|
|
2245
2471
|
let projectIds = [];
|
|
2246
2472
|
if (projectId) {
|
|
@@ -2374,7 +2600,11 @@ class Client {
|
|
|
2374
2600
|
}
|
|
2375
2601
|
}
|
|
2376
2602
|
}
|
|
2603
|
+
/** @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. */
|
|
2377
2604
|
async *readThread(props) {
|
|
2605
|
+
(0, warn_js_1.warnOnce)("readThread() is deprecated and will be removed after Jan 31, 2027. " +
|
|
2606
|
+
"Use client.threads.listTraces() instead. " +
|
|
2607
|
+
"See https://docs.langchain.com/langsmith/smithdb-sdk-migration#threads-list-traces for the migration guide.", { type: "DeprecationWarning", code: "LANGSMITH_DEPRECATED_READ_THREAD" });
|
|
2378
2608
|
const { threadId, projectId, projectName, isRoot = true, limit, filter: userFilter, order = "asc", } = props;
|
|
2379
2609
|
if (!projectId && !projectName) {
|
|
2380
2610
|
throw new Error("threadId requires projectId or projectName");
|
|
@@ -2383,7 +2613,9 @@ class Client {
|
|
|
2383
2613
|
const combinedFilter = userFilter
|
|
2384
2614
|
? `and(${threadFilter}, ${userFilter})`
|
|
2385
2615
|
: threadFilter;
|
|
2386
|
-
|
|
2616
|
+
// Via _listRuns() rather than listRuns(): readThread() already warned, and it
|
|
2617
|
+
// points at threads.listTraces() rather than listRuns()'s runs.query().
|
|
2618
|
+
yield* this._listRuns({
|
|
2387
2619
|
projectId: projectId ?? undefined,
|
|
2388
2620
|
projectName: projectName ?? undefined,
|
|
2389
2621
|
isRoot,
|
|
@@ -2392,7 +2624,11 @@ class Client {
|
|
|
2392
2624
|
order,
|
|
2393
2625
|
});
|
|
2394
2626
|
}
|
|
2627
|
+
/** @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. */
|
|
2395
2628
|
async listThreads(props) {
|
|
2629
|
+
(0, warn_js_1.warnOnce)("listThreads() is deprecated and will be removed after Jan 31, 2027. " +
|
|
2630
|
+
"Use client.threads.query() instead. " +
|
|
2631
|
+
"See https://docs.langchain.com/langsmith/smithdb-sdk-migration#threads-query for the migration guide.", { type: "DeprecationWarning", code: "LANGSMITH_DEPRECATED_LIST_THREADS" });
|
|
2396
2632
|
const { projectId, projectName, limit, offset = 0, filter, startTime, isRoot = true, } = props;
|
|
2397
2633
|
if (!projectId && !projectName) {
|
|
2398
2634
|
throw new Error("Either projectId or projectName must be provided");
|
|
@@ -2542,7 +2778,11 @@ class Client {
|
|
|
2542
2778
|
const result = await response.json();
|
|
2543
2779
|
return result;
|
|
2544
2780
|
}
|
|
2781
|
+
/** @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. */
|
|
2545
2782
|
async shareRun(runId, { shareId } = {}) {
|
|
2783
|
+
(0, warn_js_1.warnOnce)("shareRun() is deprecated and will be removed after Jan 31, 2027. " +
|
|
2784
|
+
"Use client.runs.share.create() instead. " +
|
|
2785
|
+
"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" });
|
|
2546
2786
|
const data = {
|
|
2547
2787
|
run_id: runId,
|
|
2548
2788
|
share_token: shareId || uuid.v4(),
|
|
@@ -2566,7 +2806,11 @@ class Client {
|
|
|
2566
2806
|
}
|
|
2567
2807
|
return `${this.getHostUrl()}/public/${result["share_token"]}/r`;
|
|
2568
2808
|
}
|
|
2809
|
+
/** @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. */
|
|
2569
2810
|
async unshareRun(runId) {
|
|
2811
|
+
(0, warn_js_1.warnOnce)("unshareRun() is deprecated and will be removed after Jan 31, 2027. " +
|
|
2812
|
+
"Use client.runs.share.delete() instead. " +
|
|
2813
|
+
"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" });
|
|
2570
2814
|
(0, _uuid_js_1.assertUuid)(runId);
|
|
2571
2815
|
await this.caller.call(async () => {
|
|
2572
2816
|
const res = await this._fetch(`${this.apiUrl}/runs/${runId}/share`, {
|
|
@@ -2579,7 +2823,14 @@ class Client {
|
|
|
2579
2823
|
return res;
|
|
2580
2824
|
});
|
|
2581
2825
|
}
|
|
2826
|
+
/** @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. */
|
|
2582
2827
|
async readRunSharedLink(runId) {
|
|
2828
|
+
(0, warn_js_1.warnOnce)("readRunSharedLink() is deprecated and will be removed after Jan 31, 2027. " +
|
|
2829
|
+
'Use client.runs.retrieve({ selects: ["SHARE_URL"] }) instead. ' +
|
|
2830
|
+
"See https://docs.langchain.com/langsmith/smithdb-sdk-migration#share-and-read-public-runs for the migration guide.", {
|
|
2831
|
+
type: "DeprecationWarning",
|
|
2832
|
+
code: "LANGSMITH_DEPRECATED_READ_RUN_SHARED_LINK",
|
|
2833
|
+
});
|
|
2583
2834
|
(0, _uuid_js_1.assertUuid)(runId);
|
|
2584
2835
|
const response = await this.caller.call(async () => {
|
|
2585
2836
|
const res = await this._fetch(`${this.apiUrl}/runs/${runId}/share`, {
|
|
@@ -2597,7 +2848,14 @@ class Client {
|
|
|
2597
2848
|
}
|
|
2598
2849
|
return `${this.getHostUrl()}/public/${result["share_token"]}/r`;
|
|
2599
2850
|
}
|
|
2851
|
+
/** @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. */
|
|
2600
2852
|
async listSharedRuns(shareToken, { runIds, } = {}) {
|
|
2853
|
+
(0, warn_js_1.warnOnce)("listSharedRuns() is deprecated and will be removed after Jan 31, 2027. " +
|
|
2854
|
+
"Use client.public.runs.query() instead. " +
|
|
2855
|
+
"See https://docs.langchain.com/langsmith/smithdb-sdk-migration#share-and-read-public-runs for the migration guide.", {
|
|
2856
|
+
type: "DeprecationWarning",
|
|
2857
|
+
code: "LANGSMITH_DEPRECATED_LIST_SHARED_RUNS",
|
|
2858
|
+
});
|
|
2601
2859
|
const queryParams = new URLSearchParams({
|
|
2602
2860
|
share_token: shareToken,
|
|
2603
2861
|
});
|
|
@@ -2745,7 +3003,7 @@ class Client {
|
|
|
2745
3003
|
_hostUrl: this.getHostUrl(),
|
|
2746
3004
|
}));
|
|
2747
3005
|
}
|
|
2748
|
-
async createProject({ projectName, description = null, metadata = null, upsert = false, projectExtra = null, referenceDatasetId = null, numExamples = null, numRepetitions = null, evaluatorKeys = null, }) {
|
|
3006
|
+
async createProject({ projectName, description = null, metadata = null, upsert = false, projectExtra = null, referenceDatasetId = null, numExamples = null, numRepetitions = null, evaluatorKeys = null, tagValueIds = null, }) {
|
|
2749
3007
|
const upsert_ = upsert ? `?upsert=true` : "";
|
|
2750
3008
|
const endpoint = `${this.apiUrl}/sessions${upsert_}`;
|
|
2751
3009
|
const extra = projectExtra || {};
|
|
@@ -2769,6 +3027,9 @@ class Client {
|
|
|
2769
3027
|
if (evaluatorKeys != null && evaluatorKeys.length > 0) {
|
|
2770
3028
|
body["evaluator_keys"] = evaluatorKeys;
|
|
2771
3029
|
}
|
|
3030
|
+
if (tagValueIds !== null) {
|
|
3031
|
+
body["tag_value_ids"] = tagValueIds;
|
|
3032
|
+
}
|
|
2772
3033
|
const serializedBody = JSON.stringify(body);
|
|
2773
3034
|
const response = await this.caller.call(async () => {
|
|
2774
3035
|
const res = await this._fetch(endpoint, {
|
|
@@ -3012,7 +3273,7 @@ class Client {
|
|
|
3012
3273
|
const result = await response.json();
|
|
3013
3274
|
return result;
|
|
3014
3275
|
}
|
|
3015
|
-
async createDataset(name, { description, dataType, inputsSchema, outputsSchema, metadata, } = {}) {
|
|
3276
|
+
async createDataset(name, { description, dataType, inputsSchema, outputsSchema, metadata, tagValueIds, } = {}) {
|
|
3016
3277
|
const body = {
|
|
3017
3278
|
name,
|
|
3018
3279
|
description,
|
|
@@ -3027,6 +3288,9 @@ class Client {
|
|
|
3027
3288
|
if (outputsSchema) {
|
|
3028
3289
|
body.outputs_schema_definition = outputsSchema;
|
|
3029
3290
|
}
|
|
3291
|
+
if (tagValueIds !== undefined) {
|
|
3292
|
+
body.tag_value_ids = tagValueIds;
|
|
3293
|
+
}
|
|
3030
3294
|
const serializedBody = JSON.stringify(body);
|
|
3031
3295
|
const response = await this.caller.call(async () => {
|
|
3032
3296
|
const res = await this._fetch(`${this.apiUrl}/datasets`, {
|
|
@@ -4186,8 +4450,9 @@ class Client {
|
|
|
4186
4450
|
* - `RunKey[]` (preferred): each entry carries the run's full lookup key, so
|
|
4187
4451
|
* it can be located directly without a scan. Required for workspaces served
|
|
4188
4452
|
* by SmithDB; routes to `POST /runs/by-key`.
|
|
4189
|
-
* - `string[]`: a plain list of run IDs.
|
|
4190
|
-
*
|
|
4453
|
+
* - `string[]`: a plain list of run IDs. **Deprecated**: this path will be
|
|
4454
|
+
* removed after Jan 31, 2027; prefer the key form. Routes to `POST /runs`.
|
|
4455
|
+
* See https://docs.langchain.com/langsmith/smithdb-sdk-migration#annotation-queues-add-runs.
|
|
4191
4456
|
*
|
|
4192
4457
|
* If every element is a string (or the list is empty) it is treated as run
|
|
4193
4458
|
* IDs; otherwise the list is treated as `RunKey` objects.
|
|
@@ -4218,6 +4483,12 @@ class Client {
|
|
|
4218
4483
|
}));
|
|
4219
4484
|
}
|
|
4220
4485
|
else {
|
|
4486
|
+
(0, warn_js_1.warnOnce)("Passing run IDs as strings to addRunsToAnnotationQueue() is deprecated and will be removed after Jan 31, 2027. " +
|
|
4487
|
+
"Use RunKey[] instead. " +
|
|
4488
|
+
"See https://docs.langchain.com/langsmith/smithdb-sdk-migration#annotation-queues-add-runs for the migration guide.", {
|
|
4489
|
+
type: "DeprecationWarning",
|
|
4490
|
+
code: "LANGSMITH_DEPRECATED_ADD_RUNS_STRING_IDS",
|
|
4491
|
+
});
|
|
4221
4492
|
url = base;
|
|
4222
4493
|
body = JSON.stringify(runs.map((id, i) => (0, _uuid_js_1.assertUuid)(id, `runs[${i}]`).toString()));
|
|
4223
4494
|
}
|