langsmith 0.8.12 → 0.10.0

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.
Files changed (56) hide show
  1. package/dist/_openapi_client/client.cjs +1 -1
  2. package/dist/_openapi_client/client.d.ts +2 -2
  3. package/dist/_openapi_client/client.js +1 -1
  4. package/dist/_openapi_client/internal/detect-platform.cjs +1 -1
  5. package/dist/_openapi_client/internal/detect-platform.js +1 -1
  6. package/dist/_openapi_client/resources/annotation-queues/annotation-queues.d.ts +1 -0
  7. package/dist/_openapi_client/resources/index.d.ts +1 -1
  8. package/dist/_openapi_client/resources/issues.cjs +1 -1
  9. package/dist/_openapi_client/resources/issues.d.ts +18 -1
  10. package/dist/_openapi_client/resources/issues.js +1 -1
  11. package/dist/_openapi_client/resources/online-evaluators.d.ts +2 -2
  12. package/dist/_openapi_client/resources/sandboxes/boxes.cjs +20 -3
  13. package/dist/_openapi_client/resources/sandboxes/boxes.d.ts +40 -9
  14. package/dist/_openapi_client/resources/sandboxes/boxes.js +20 -3
  15. package/dist/_openapi_client/resources/sandboxes/sandboxes.d.ts +46 -3
  16. package/dist/_openapi_client/resources/sandboxes/snapshots.cjs +6 -2
  17. package/dist/_openapi_client/resources/sandboxes/snapshots.d.ts +16 -6
  18. package/dist/_openapi_client/resources/sandboxes/snapshots.js +6 -2
  19. package/dist/client.cjs +56 -83
  20. package/dist/client.d.ts +16 -14
  21. package/dist/client.js +56 -83
  22. package/dist/env.cjs +14 -1
  23. package/dist/env.d.ts +9 -0
  24. package/dist/env.js +12 -0
  25. package/dist/evaluation/evaluate_comparative.cjs +2 -0
  26. package/dist/evaluation/evaluate_comparative.js +2 -0
  27. package/dist/experimental/vercel/telemetry.cjs +19 -6
  28. package/dist/experimental/vercel/telemetry.js +17 -4
  29. package/dist/index.cjs +1 -1
  30. package/dist/index.d.ts +1 -1
  31. package/dist/index.js +1 -1
  32. package/dist/run_trees.cjs +19 -2
  33. package/dist/run_trees.d.ts +12 -0
  34. package/dist/run_trees.js +19 -2
  35. package/dist/schemas.d.ts +2 -0
  36. package/dist/singletons/constants.cjs +7 -1
  37. package/dist/singletons/constants.d.ts +3 -0
  38. package/dist/singletons/constants.js +5 -0
  39. package/dist/traceable.cjs +46 -15
  40. package/dist/traceable.js +48 -17
  41. package/dist/utils/_uuid.cjs +11 -19
  42. package/dist/utils/_uuid.d.ts +7 -7
  43. package/dist/utils/_uuid.js +11 -19
  44. package/dist/utils/env.cjs +18 -7
  45. package/dist/utils/env.js +18 -7
  46. package/dist/utils/redaction.cjs +38 -0
  47. package/dist/utils/redaction.d.ts +10 -0
  48. package/dist/utils/redaction.js +33 -0
  49. package/dist/utils/sampling.cjs +34 -0
  50. package/dist/utils/sampling.d.ts +10 -0
  51. package/dist/utils/sampling.js +30 -0
  52. package/dist/wrappers/anthropic.cjs +21 -24
  53. package/dist/wrappers/anthropic.js +21 -24
  54. package/dist/wrappers/openai_agents.cjs +2 -1
  55. package/dist/wrappers/openai_agents.js +2 -1
  56. package/package.json +1 -1
package/dist/client.cjs CHANGED
@@ -45,6 +45,7 @@ const env_js_1 = require("./utils/env.cjs");
45
45
  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
+ const sampling_js_1 = require("./utils/sampling.cjs");
48
49
  const warn_js_1 = require("./utils/warn.cjs");
49
50
  const v2_migration_js_1 = require("./utils/v2_migration.cjs");
50
51
  const prompts_js_1 = require("./utils/prompts.cjs");
@@ -636,12 +637,6 @@ class Client {
636
637
  writable: true,
637
638
  value: void 0
638
639
  });
639
- Object.defineProperty(this, "filteredPostUuids", {
640
- enumerable: true,
641
- configurable: true,
642
- writable: true,
643
- value: new Set()
644
- });
645
640
  Object.defineProperty(this, "autoBatchTracing", {
646
641
  enumerable: true,
647
642
  configurable: true,
@@ -1074,14 +1069,23 @@ class Client {
1074
1069
  return headers;
1075
1070
  }
1076
1071
  /**
1077
- * The auth options and caller headers to build the generated client with.
1072
+ * The options to build the generated client with: its auth, and the headers
1073
+ * it should send on every request.
1078
1074
  *
1079
1075
  * The generated client applies `defaultHeaders` *after* its own auth headers,
1080
1076
  * so the ones this SDK sets are already dropped from `_callerHeaders` to keep
1081
1077
  * the precedence of `_mergedHeaders`, where required headers win.
1082
1078
  */
1083
- get _openAPIAuth() {
1079
+ get _openAPIClientOptions() {
1084
1080
  const headers = { ...this._callerHeaders };
1081
+ // Without this the generated client falls back to its own
1082
+ // `Langsmith/JS <generated version>`, so the same client would identify
1083
+ // itself two different ways depending on which path a call takes. A
1084
+ // caller-supplied one still wins, matched case-insensitively so the header
1085
+ // is not sent twice.
1086
+ if (!Object.keys(headers).some((name) => name.toLowerCase() === "user-agent")) {
1087
+ headers["User-Agent"] = `langsmith-js/${index_js_1.__version__}`;
1088
+ }
1085
1089
  // A caller may authenticate by supplying `x-api-key` themselves. The
1086
1090
  // generated client rejects that as a header (its `validateHeaders` requires
1087
1091
  // its own `apiKey` to be set), so hand it over as the `apiKey` option and
@@ -1133,25 +1137,25 @@ class Client {
1133
1137
  * its token is refreshed.
1134
1138
  */
1135
1139
  get openAPIClient() {
1136
- const auth = this._openAPIAuth;
1137
- const signature = JSON.stringify([auth.apiKey, auth.defaultHeaders]);
1140
+ const options = this._openAPIClientOptions;
1141
+ const signature = JSON.stringify([options.apiKey, options.defaultHeaders]);
1138
1142
  if (this._openAPIClient === undefined ||
1139
1143
  this._openAPIClientSignature !== signature) {
1140
1144
  this._openAPIClientSignature = signature;
1141
- this._openAPIClient = this._newOpenAPIClient(auth);
1145
+ this._openAPIClient = this._newOpenAPIClient(options);
1142
1146
  }
1143
1147
  return this._openAPIClient;
1144
1148
  }
1145
- _newOpenAPIClient(auth = this._openAPIAuth) {
1149
+ _newOpenAPIClient(options = this._openAPIClientOptions) {
1146
1150
  const { method: _method, body: _body, signal: _signal, ...openAPIFetchOptions } = this.fetchOptions;
1147
1151
  return new index_js_2.Langsmith({
1148
- apiKey: auth.apiKey,
1152
+ apiKey: options.apiKey,
1149
1153
  tenantID: this.workspaceId,
1150
1154
  baseURL: this._getOpenAPIBaseUrl(),
1151
1155
  timeout: this.timeout_ms,
1152
1156
  fetch: this._fetch,
1153
1157
  fetchOptions: openAPIFetchOptions,
1154
- defaultHeaders: auth.defaultHeaders,
1158
+ defaultHeaders: options.defaultHeaders,
1155
1159
  });
1156
1160
  }
1157
1161
  _getPlatformEndpointPath(path) {
@@ -1379,53 +1383,14 @@ class Client {
1379
1383
  }
1380
1384
  }
1381
1385
  // Allows mocking for tests
1382
- _shouldSample() {
1383
- if (this.tracingSampleRate === undefined) {
1384
- return true;
1385
- }
1386
- return Math.random() < this.tracingSampleRate;
1386
+ _shouldSample(identifier) {
1387
+ return (0, sampling_js_1.isSampledById)(identifier, this.tracingSampleRate);
1387
1388
  }
1388
- _filterForSampling(runs, patch = false) {
1389
- if (this.tracingSampleRate === undefined) {
1390
- return runs;
1391
- }
1392
- if (patch) {
1393
- const sampled = [];
1394
- for (const run of runs) {
1395
- if (!this.filteredPostUuids.has(run.trace_id)) {
1396
- sampled.push(run);
1397
- }
1398
- else if (run.id === run.trace_id) {
1399
- this.filteredPostUuids.delete(run.trace_id);
1400
- }
1401
- }
1402
- return sampled;
1403
- }
1404
- else {
1405
- // For new runs, sample at trace level to maintain consistency
1406
- const sampled = [];
1407
- for (const run of runs) {
1408
- const traceId = run.trace_id ?? run.id;
1409
- // If we've already made a decision about this trace, follow it
1410
- if (this.filteredPostUuids.has(traceId)) {
1411
- continue;
1412
- }
1413
- // For new traces, apply sampling
1414
- if (run.id === traceId) {
1415
- if (this._shouldSample()) {
1416
- sampled.push(run);
1417
- }
1418
- else {
1419
- this.filteredPostUuids.add(traceId);
1420
- }
1421
- }
1422
- else {
1423
- // Child runs follow their trace's sampling decision
1424
- sampled.push(run);
1425
- }
1426
- }
1427
- return sampled;
1428
- }
1389
+ _filterForSampling(runs) {
1390
+ // updateRun() may omit trace_id; dotted order's first segment is the root.
1391
+ return runs.filter((run) => this._shouldSample(run.trace_id ??
1392
+ run.dotted_order?.split(".", 1)[0].split("Z")[1] ??
1393
+ run.id));
1429
1394
  }
1430
1395
  async _getBatchSizeLimitBytes() {
1431
1396
  const serverInfo = await this._ensureServerInfo();
@@ -1748,7 +1713,7 @@ class Client {
1748
1713
  * feedback has no sessionId.
1749
1714
  */
1750
1715
  async _checkFeedbackSessionId() {
1751
- const docs = "https://docs.langchain.com/langsmith/smithdb-sdk-migration#feedback-create";
1716
+ const docs = "https://docs.langchain.com/langsmith/smithdb-sdk-migration-feedback#feedback-create";
1752
1717
  const serverInfo = await this._ensureServerInfo();
1753
1718
  if ((0, v2_migration_js_1.getQueryBackend)(serverInfo.instance_flags) === v2_migration_js_1.QueryBackend.SMITHDB_ONLY) {
1754
1719
  throw new Error(`sessionId must be provided when creating feedback for a run: this ` +
@@ -2217,7 +2182,7 @@ class Client {
2217
2182
  }
2218
2183
  // TODO: Untangle types
2219
2184
  const data = { ...run, id: runId };
2220
- if (!this._filterForSampling([data], true).length) {
2185
+ if (!this._filterForSampling([data]).length) {
2221
2186
  return;
2222
2187
  }
2223
2188
  if (this.autoBatchTracing &&
@@ -2275,11 +2240,11 @@ class Client {
2275
2240
  return res;
2276
2241
  });
2277
2242
  }
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. */
2243
+ /** @deprecated Use `client.runs.retrieve()` instead. See https://docs.langchain.com/langsmith/smithdb-sdk-migration-runs#runs-retrieve for the migration guide. Will be removed after Jan 31, 2027. */
2279
2244
  async readRun(runId, { loadChildRuns } = { loadChildRuns: false }) {
2280
2245
  (0, warn_js_1.warnOnce)("readRun() is deprecated and will be removed after Jan 31, 2027. " +
2281
2246
  "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" });
2247
+ "See https://docs.langchain.com/langsmith/smithdb-sdk-migration-runs#runs-retrieve for the migration guide.", { type: "DeprecationWarning", code: "LANGSMITH_DEPRECATED_READ_RUN" });
2283
2248
  return this._readRun(runId, { loadChildRuns });
2284
2249
  }
2285
2250
  /**
@@ -2298,11 +2263,11 @@ class Client {
2298
2263
  }
2299
2264
  return run;
2300
2265
  }
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. */
2266
+ /** @deprecated Use `client.runs.getURL()` instead. See https://docs.langchain.com/langsmith/smithdb-sdk-migration-runs#runs-get-url for the migration guide. Will be removed after Jan 31, 2027. */
2302
2267
  async getRunUrl({ runId, run, projectOpts, }) {
2303
2268
  (0, warn_js_1.warnOnce)("getRunUrl() is deprecated and will be removed after Jan 31, 2027. " +
2304
2269
  "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" });
2270
+ "See https://docs.langchain.com/langsmith/smithdb-sdk-migration-runs#runs-get-url for the migration guide.", { type: "DeprecationWarning", code: "LANGSMITH_DEPRECATED_GET_RUN_URL" });
2306
2271
  if (run !== undefined) {
2307
2272
  let sessionId;
2308
2273
  if (run.session_id) {
@@ -2371,7 +2336,7 @@ class Client {
2371
2336
  }
2372
2337
  /**
2373
2338
  * 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.
2339
+ * @deprecated Use `client.runs.query()` instead. See https://docs.langchain.com/langsmith/smithdb-sdk-migration-query-runs#runs-query for the migration guide. Will be removed after Jan 31, 2027.
2375
2340
  * @param projectId - The ID of the project to filter by.
2376
2341
  * @param projectName - The name of the project to filter by.
2377
2342
  * @param parentRunId - The ID of the parent run to filter by.
@@ -2455,7 +2420,7 @@ class Client {
2455
2420
  async *listRuns(props) {
2456
2421
  (0, warn_js_1.warnOnce)("listRuns() is deprecated and will be removed after Jan 31, 2027. " +
2457
2422
  "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" });
2423
+ "See https://docs.langchain.com/langsmith/smithdb-sdk-migration-query-runs#runs-query for the migration guide.", { type: "DeprecationWarning", code: "LANGSMITH_DEPRECATED_LIST_RUNS" });
2459
2424
  yield* this._listRuns(props);
2460
2425
  }
2461
2426
  /**
@@ -2600,11 +2565,11 @@ class Client {
2600
2565
  }
2601
2566
  }
2602
2567
  }
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. */
2568
+ /** @deprecated Use `client.threads.listTraces()` instead. See https://docs.langchain.com/langsmith/smithdb-sdk-migration-threads#threads-list-traces for the migration guide. Will be removed after Jan 31, 2027. */
2604
2569
  async *readThread(props) {
2605
2570
  (0, warn_js_1.warnOnce)("readThread() is deprecated and will be removed after Jan 31, 2027. " +
2606
2571
  "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" });
2572
+ "See https://docs.langchain.com/langsmith/smithdb-sdk-migration-threads#threads-list-traces for the migration guide.", { type: "DeprecationWarning", code: "LANGSMITH_DEPRECATED_READ_THREAD" });
2608
2573
  const { threadId, projectId, projectName, isRoot = true, limit, filter: userFilter, order = "asc", } = props;
2609
2574
  if (!projectId && !projectName) {
2610
2575
  throw new Error("threadId requires projectId or projectName");
@@ -2624,11 +2589,11 @@ class Client {
2624
2589
  order,
2625
2590
  });
2626
2591
  }
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. */
2592
+ /** @deprecated Use `client.threads.query()` instead. See https://docs.langchain.com/langsmith/smithdb-sdk-migration-threads#threads-query for the migration guide. Will be removed after Jan 31, 2027. */
2628
2593
  async listThreads(props) {
2629
2594
  (0, warn_js_1.warnOnce)("listThreads() is deprecated and will be removed after Jan 31, 2027. " +
2630
2595
  "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" });
2596
+ "See https://docs.langchain.com/langsmith/smithdb-sdk-migration-threads#threads-query for the migration guide.", { type: "DeprecationWarning", code: "LANGSMITH_DEPRECATED_LIST_THREADS" });
2632
2597
  const { projectId, projectName, limit, offset = 0, filter, startTime, isRoot = true, } = props;
2633
2598
  if (!projectId && !projectName) {
2634
2599
  throw new Error("Either projectId or projectName must be provided");
@@ -2778,11 +2743,11 @@ class Client {
2778
2743
  const result = await response.json();
2779
2744
  return result;
2780
2745
  }
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. */
2746
+ /** @deprecated Use `client.runs.share.create()` instead. See https://docs.langchain.com/langsmith/smithdb-sdk-migration-feedback#share-and-read-public-runs for the migration guide. Will be removed after Jan 31, 2027. */
2782
2747
  async shareRun(runId, { shareId } = {}) {
2783
2748
  (0, warn_js_1.warnOnce)("shareRun() is deprecated and will be removed after Jan 31, 2027. " +
2784
2749
  "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" });
2750
+ "See https://docs.langchain.com/langsmith/smithdb-sdk-migration-feedback#share-and-read-public-runs for the migration guide.", { type: "DeprecationWarning", code: "LANGSMITH_DEPRECATED_SHARE_RUN" });
2786
2751
  const data = {
2787
2752
  run_id: runId,
2788
2753
  share_token: shareId || uuid.v4(),
@@ -2806,11 +2771,11 @@ class Client {
2806
2771
  }
2807
2772
  return `${this.getHostUrl()}/public/${result["share_token"]}/r`;
2808
2773
  }
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. */
2774
+ /** @deprecated Use `client.runs.share.delete()` instead. See https://docs.langchain.com/langsmith/smithdb-sdk-migration-feedback#share-and-read-public-runs for the migration guide. Will be removed after Jan 31, 2027. */
2810
2775
  async unshareRun(runId) {
2811
2776
  (0, warn_js_1.warnOnce)("unshareRun() is deprecated and will be removed after Jan 31, 2027. " +
2812
2777
  "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" });
2778
+ "See https://docs.langchain.com/langsmith/smithdb-sdk-migration-feedback#share-and-read-public-runs for the migration guide.", { type: "DeprecationWarning", code: "LANGSMITH_DEPRECATED_UNSHARE_RUN" });
2814
2779
  (0, _uuid_js_1.assertUuid)(runId);
2815
2780
  await this.caller.call(async () => {
2816
2781
  const res = await this._fetch(`${this.apiUrl}/runs/${runId}/share`, {
@@ -2823,11 +2788,11 @@ class Client {
2823
2788
  return res;
2824
2789
  });
2825
2790
  }
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. */
2791
+ /** @deprecated Use `client.runs.retrieve({ selects: ["SHARE_URL"] })` instead. See https://docs.langchain.com/langsmith/smithdb-sdk-migration-feedback#share-and-read-public-runs for the migration guide. Will be removed after Jan 31, 2027. */
2827
2792
  async readRunSharedLink(runId) {
2828
2793
  (0, warn_js_1.warnOnce)("readRunSharedLink() is deprecated and will be removed after Jan 31, 2027. " +
2829
2794
  '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.", {
2795
+ "See https://docs.langchain.com/langsmith/smithdb-sdk-migration-feedback#share-and-read-public-runs for the migration guide.", {
2831
2796
  type: "DeprecationWarning",
2832
2797
  code: "LANGSMITH_DEPRECATED_READ_RUN_SHARED_LINK",
2833
2798
  });
@@ -2848,11 +2813,11 @@ class Client {
2848
2813
  }
2849
2814
  return `${this.getHostUrl()}/public/${result["share_token"]}/r`;
2850
2815
  }
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. */
2816
+ /** @deprecated Use `client.public.runs.query()` instead. See https://docs.langchain.com/langsmith/smithdb-sdk-migration-feedback#share-and-read-public-runs for the migration guide. Will be removed after Jan 31, 2027. */
2852
2817
  async listSharedRuns(shareToken, { runIds, } = {}) {
2853
2818
  (0, warn_js_1.warnOnce)("listSharedRuns() is deprecated and will be removed after Jan 31, 2027. " +
2854
2819
  "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.", {
2820
+ "See https://docs.langchain.com/langsmith/smithdb-sdk-migration-feedback#share-and-read-public-runs for the migration guide.", {
2856
2821
  type: "DeprecationWarning",
2857
2822
  code: "LANGSMITH_DEPRECATED_LIST_SHARED_RUNS",
2858
2823
  });
@@ -3926,7 +3891,7 @@ class Client {
3926
3891
  });
3927
3892
  }
3928
3893
  async createFeedback(runIdOrParams, keyArg, optionsArg) {
3929
- const { runId = null, key, score, value, correction, comment, sourceInfo, feedbackSourceType = "api", sourceRunId, feedbackId, feedbackConfig, projectId, comparativeExperimentId, sessionId, startTime, extendTraceRetention, } = typeof runIdOrParams === "object" && runIdOrParams !== null
3894
+ const { runId = null, key, score, value, correction, comment, sourceInfo, feedbackSourceType = "api", sourceRunId, feedbackId, feedbackConfig, projectId, traceId, comparativeExperimentId, sessionId, startTime, extendTraceRetention, } = typeof runIdOrParams === "object" && runIdOrParams !== null
3930
3895
  ? runIdOrParams
3931
3896
  : { runId: runIdOrParams, key: keyArg, ...optionsArg };
3932
3897
  if (!runId && !projectId) {
@@ -3954,6 +3919,7 @@ class Client {
3954
3919
  const feedback = {
3955
3920
  id: feedbackId ?? uuid.v7(),
3956
3921
  run_id: runId,
3922
+ trace_id: traceId,
3957
3923
  key,
3958
3924
  score: _formatFeedbackScore(score),
3959
3925
  value,
@@ -3966,6 +3932,10 @@ class Client {
3966
3932
  start_time: startTime,
3967
3933
  extend_trace_retention: extendTraceRetention,
3968
3934
  };
3935
+ const samplingId = traceId ?? runId;
3936
+ if (samplingId != null && !this._shouldSample(samplingId)) {
3937
+ return feedback;
3938
+ }
3969
3939
  const body = JSON.stringify(feedback);
3970
3940
  const url = `${this.apiUrl}/feedback`;
3971
3941
  await this.caller.call(async () => {
@@ -4187,6 +4157,9 @@ class Client {
4187
4157
  feedbackSourceType: "model",
4188
4158
  sessionId: run?.session_id ?? sessionId,
4189
4159
  startTime: run?.start_time,
4160
+ // If an evaluator result targets a different run, we can't
4161
+ // guarantee to know its trace ID.
4162
+ traceId: runId_ === run?.id ? run?.trace_id : undefined,
4190
4163
  }));
4191
4164
  }
4192
4165
  return [evalResults, feedbacks];
@@ -4452,7 +4425,7 @@ class Client {
4452
4425
  * by SmithDB; routes to `POST /runs/by-key`.
4453
4426
  * - `string[]`: a plain list of run IDs. **Deprecated**: this path will be
4454
4427
  * 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.
4428
+ * See https://docs.langchain.com/langsmith/smithdb-sdk-migration-feedback#annotation-queues-add-runs.
4456
4429
  *
4457
4430
  * If every element is a string (or the list is empty) it is treated as run
4458
4431
  * IDs; otherwise the list is treated as `RunKey` objects.
@@ -4485,7 +4458,7 @@ class Client {
4485
4458
  else {
4486
4459
  (0, warn_js_1.warnOnce)("Passing run IDs as strings to addRunsToAnnotationQueue() is deprecated and will be removed after Jan 31, 2027. " +
4487
4460
  "Use RunKey[] instead. " +
4488
- "See https://docs.langchain.com/langsmith/smithdb-sdk-migration#annotation-queues-add-runs for the migration guide.", {
4461
+ "See https://docs.langchain.com/langsmith/smithdb-sdk-migration-feedback#annotation-queues-add-runs for the migration guide.", {
4489
4462
  type: "DeprecationWarning",
4490
4463
  code: "LANGSMITH_DEPRECATED_ADD_RUNS_STRING_IDS",
4491
4464
  });
package/dist/client.d.ts CHANGED
@@ -348,6 +348,8 @@ export type CreateFeedbackOptions = {
348
348
  feedbackConfig?: FeedbackConfig;
349
349
  sourceRunId?: string;
350
350
  feedbackId?: string;
351
+ /** The trace the run belongs to. Omit for a root run. */
352
+ traceId?: string;
351
353
  comparativeExperimentId?: string;
352
354
  /**
353
355
  * The run's start time, ISO string or epoch ms. Better performance if provided.
@@ -363,7 +365,7 @@ export type CreateFeedbackLegacyOptions = Omit<CreateFeedbackOptions, "key"> & {
363
365
  /**
364
366
  * The session (project) ID of the run. Required for run-level feedback;
365
367
  * omitting it is deprecated. See
366
- * https://docs.langchain.com/langsmith/smithdb-sdk-migration#feedback-create
368
+ * https://docs.langchain.com/langsmith/smithdb-sdk-migration-feedback#feedback-create
367
369
  */
368
370
  sessionId?: string;
369
371
  /** The project (or experiment) to provide feedback on, for session-level feedback. */
@@ -495,7 +497,6 @@ export declare class Client implements LangSmithTracingClientInterface {
495
497
  private anonymizer?;
496
498
  private omitTracedRuntimeInfo?;
497
499
  private tracingSampleRate?;
498
- private filteredPostUuids;
499
500
  private autoBatchTracing;
500
501
  private autoBatchQueue;
501
502
  private autoBatchTimeout;
@@ -579,13 +580,14 @@ export declare class Client implements LangSmithTracingClientInterface {
579
580
  private get _callerHeaders();
580
581
  private get _mergedHeaders();
581
582
  /**
582
- * The auth options and caller headers to build the generated client with.
583
+ * The options to build the generated client with: its auth, and the headers
584
+ * it should send on every request.
583
585
  *
584
586
  * The generated client applies `defaultHeaders` *after* its own auth headers,
585
587
  * so the ones this SDK sets are already dropped from `_callerHeaders` to keep
586
588
  * the precedence of `_mergedHeaders`, where required headers win.
587
589
  */
588
- private get _openAPIAuth();
590
+ private get _openAPIClientOptions();
589
591
  /**
590
592
  * Get or set custom headers for the client.
591
593
  * Custom headers are merged with default headers (User-Agent, x-api-key, x-tenant-id).
@@ -730,11 +732,11 @@ export declare class Client implements LangSmithTracingClientInterface {
730
732
  apiUrl?: string;
731
733
  workspaceId?: string;
732
734
  }): Promise<void>;
733
- /** @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. */
735
+ /** @deprecated Use `client.runs.retrieve()` instead. See https://docs.langchain.com/langsmith/smithdb-sdk-migration-runs#runs-retrieve for the migration guide. Will be removed after Jan 31, 2027. */
734
736
  readRun(runId: string, { loadChildRuns }?: {
735
737
  loadChildRuns: boolean;
736
738
  }): Promise<Run>;
737
- /** @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. */
739
+ /** @deprecated Use `client.runs.getURL()` instead. See https://docs.langchain.com/langsmith/smithdb-sdk-migration-runs#runs-get-url for the migration guide. Will be removed after Jan 31, 2027. */
738
740
  getRunUrl({ runId, run, projectOpts, }: {
739
741
  runId?: string;
740
742
  run?: Run;
@@ -743,7 +745,7 @@ export declare class Client implements LangSmithTracingClientInterface {
743
745
  private _loadChildRuns;
744
746
  /**
745
747
  * List runs from the LangSmith server.
746
- * @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.
748
+ * @deprecated Use `client.runs.query()` instead. See https://docs.langchain.com/langsmith/smithdb-sdk-migration-query-runs#runs-query for the migration guide. Will be removed after Jan 31, 2027.
747
749
  * @param projectId - The ID of the project to filter by.
748
750
  * @param projectName - The name of the project to filter by.
749
751
  * @param parentRunId - The ID of the parent run to filter by.
@@ -826,9 +828,9 @@ export declare class Client implements LangSmithTracingClientInterface {
826
828
  */
827
829
  listRuns(props: ListRunsParams): AsyncIterable<Run>;
828
830
  listGroupRuns(props: GroupRunsParams): AsyncIterable<Thread>;
829
- /** @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. */
831
+ /** @deprecated Use `client.threads.listTraces()` instead. See https://docs.langchain.com/langsmith/smithdb-sdk-migration-threads#threads-list-traces for the migration guide. Will be removed after Jan 31, 2027. */
830
832
  readThread(props: ReadThreadParams): AsyncIterable<Run>;
831
- /** @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. */
833
+ /** @deprecated Use `client.threads.query()` instead. See https://docs.langchain.com/langsmith/smithdb-sdk-migration-threads#threads-query for the migration guide. Will be removed after Jan 31, 2027. */
832
834
  listThreads(props: ListThreadsParams): Promise<ListThreadsItem[]>;
833
835
  getRunStats({ id, trace, parentRun, runType, projectNames, projectIds, referenceExampleIds, startTime, endTime, error, query, filter, traceFilter, treeFilter, isRoot, dataSourceType, }: {
834
836
  id?: string[];
@@ -848,15 +850,15 @@ export declare class Client implements LangSmithTracingClientInterface {
848
850
  isRoot?: boolean;
849
851
  dataSourceType?: string;
850
852
  }): Promise<any>;
851
- /** @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. */
853
+ /** @deprecated Use `client.runs.share.create()` instead. See https://docs.langchain.com/langsmith/smithdb-sdk-migration-feedback#share-and-read-public-runs for the migration guide. Will be removed after Jan 31, 2027. */
852
854
  shareRun(runId: string, { shareId }?: {
853
855
  shareId?: string;
854
856
  }): Promise<string>;
855
- /** @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. */
857
+ /** @deprecated Use `client.runs.share.delete()` instead. See https://docs.langchain.com/langsmith/smithdb-sdk-migration-feedback#share-and-read-public-runs for the migration guide. Will be removed after Jan 31, 2027. */
856
858
  unshareRun(runId: string): Promise<void>;
857
- /** @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. */
859
+ /** @deprecated Use `client.runs.retrieve({ selects: ["SHARE_URL"] })` instead. See https://docs.langchain.com/langsmith/smithdb-sdk-migration-feedback#share-and-read-public-runs for the migration guide. Will be removed after Jan 31, 2027. */
858
860
  readRunSharedLink(runId: string): Promise<string | undefined>;
859
- /** @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. */
861
+ /** @deprecated Use `client.public.runs.query()` instead. See https://docs.langchain.com/langsmith/smithdb-sdk-migration-feedback#share-and-read-public-runs for the migration guide. Will be removed after Jan 31, 2027. */
860
862
  listSharedRuns(shareToken: string, { runIds, }?: {
861
863
  runIds?: string[];
862
864
  }): Promise<Run[]>;
@@ -1251,7 +1253,7 @@ export declare class Client implements LangSmithTracingClientInterface {
1251
1253
  * by SmithDB; routes to `POST /runs/by-key`.
1252
1254
  * - `string[]`: a plain list of run IDs. **Deprecated**: this path will be
1253
1255
  * removed after Jan 31, 2027; prefer the key form. Routes to `POST /runs`.
1254
- * See https://docs.langchain.com/langsmith/smithdb-sdk-migration#annotation-queues-add-runs.
1256
+ * See https://docs.langchain.com/langsmith/smithdb-sdk-migration-feedback#annotation-queues-add-runs.
1255
1257
  *
1256
1258
  * If every element is a string (or the list is empty) it is treated as run
1257
1259
  * IDs; otherwise the list is treated as `RunKey` objects.