langsmith 0.8.3 → 0.8.5

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 (57) hide show
  1. package/dist/_openapi_client/client.cjs +9 -1
  2. package/dist/_openapi_client/client.d.ts +5 -2
  3. package/dist/_openapi_client/client.js +9 -1
  4. package/dist/_openapi_client/resources/datasets/experiment-runs.d.ts +2 -2
  5. package/dist/_openapi_client/resources/index.cjs +4 -2
  6. package/dist/_openapi_client/resources/index.d.ts +2 -1
  7. package/dist/_openapi_client/resources/index.js +2 -1
  8. package/dist/_openapi_client/resources/issues.d.ts +7 -1
  9. package/dist/_openapi_client/resources/public/public.cjs +54 -0
  10. package/dist/_openapi_client/resources/public/public.d.ts +9 -0
  11. package/dist/_openapi_client/resources/public/public.js +17 -0
  12. package/dist/_openapi_client/resources/public/runs.cjs +56 -0
  13. package/dist/_openapi_client/resources/public/runs.d.ts +76 -0
  14. package/dist/_openapi_client/resources/public/runs.js +52 -0
  15. package/dist/_openapi_client/resources/runs/index.cjs +9 -0
  16. package/dist/_openapi_client/resources/runs/index.d.ts +2 -0
  17. package/dist/_openapi_client/resources/runs/index.js +4 -0
  18. package/dist/_openapi_client/resources/runs/runs.cjs +128 -0
  19. package/dist/_openapi_client/resources/runs/runs.d.ts +854 -0
  20. package/dist/_openapi_client/resources/runs/runs.js +91 -0
  21. package/dist/_openapi_client/resources/runs/share.cjs +42 -0
  22. package/dist/_openapi_client/resources/runs/share.d.ts +50 -0
  23. package/dist/_openapi_client/resources/runs/share.js +38 -0
  24. package/dist/_openapi_client/resources/runs.cjs +15 -69
  25. package/dist/_openapi_client/resources/runs.d.ts +1 -820
  26. package/dist/_openapi_client/resources/runs.js +1 -67
  27. package/dist/_openapi_client/resources/traces.d.ts +2 -2
  28. package/dist/client.cjs +47 -7
  29. package/dist/client.d.ts +17 -2
  30. package/dist/client.js +47 -7
  31. package/dist/evaluation/_runner.cjs +13 -2
  32. package/dist/evaluation/_runner.js +13 -2
  33. package/dist/evaluation/evaluate_comparative.cjs +14 -6
  34. package/dist/evaluation/evaluate_comparative.d.ts +4 -1
  35. package/dist/evaluation/evaluate_comparative.js +13 -6
  36. package/dist/index.cjs +3 -2
  37. package/dist/index.d.ts +3 -3
  38. package/dist/index.js +2 -2
  39. package/dist/run_trees.cjs +38 -10
  40. package/dist/run_trees.d.ts +3 -1
  41. package/dist/run_trees.js +38 -10
  42. package/dist/utils/constants.cjs +1 -1
  43. package/dist/utils/constants.d.ts +1 -1
  44. package/dist/utils/constants.js +1 -1
  45. package/dist/utils/jestlike/globals.cjs +11 -3
  46. package/dist/utils/jestlike/globals.js +11 -3
  47. package/dist/utils/jestlike/index.cjs +3 -0
  48. package/dist/utils/jestlike/index.js +3 -0
  49. package/dist/utils/v2_migration.cjs +56 -0
  50. package/dist/utils/v2_migration.d.ts +7 -0
  51. package/dist/utils/v2_migration.js +52 -0
  52. package/dist/uuid.cjs +22 -2
  53. package/dist/uuid.d.ts +8 -0
  54. package/dist/uuid.js +19 -0
  55. package/dist/wrappers/openai.cjs +6 -0
  56. package/dist/wrappers/openai.js +6 -0
  57. package/package.json +6 -2
@@ -46,12 +46,16 @@ function convertToDottedOrderFormat(epoch, runId, executionOrder = 1) {
46
46
  }
47
47
  const HEADER_SAFE_REPLICA_FIELDS = new Set([
48
48
  "projectName",
49
+ "primary",
49
50
  "updates",
50
51
  "reroot",
51
52
  ]);
52
53
  function filterReplicaForHeaders(replica) {
53
54
  const filtered = {};
54
55
  for (const key of Object.keys(replica)) {
56
+ if (key === "primary" && typeof replica[key] !== "boolean") {
57
+ continue;
58
+ }
55
59
  if (HEADER_SAFE_REPLICA_FIELDS.has(key)) {
56
60
  filtered[key] = replica[key];
57
61
  }
@@ -567,10 +571,10 @@ class RunTree {
567
571
  }
568
572
  }
569
573
  _remapForProject(params) {
570
- const { projectName, runtimeEnv, excludeChildRuns = true, reroot = false, distributedParentId, apiUrl, apiKey, workspaceId, } = params;
574
+ const { projectName, primary, runtimeEnv, excludeChildRuns = true, reroot = false, distributedParentId, apiUrl, apiKey, workspaceId, } = params;
571
575
  const baseRun = this._convertToCreate(this, runtimeEnv, excludeChildRuns);
572
- // Skip remapping if project name is the same
573
- if (projectName === this.project_name) {
576
+ // Preserve legacy behavior when `primary` is omitted.
577
+ if (primary === undefined && projectName === this.project_name) {
574
578
  return {
575
579
  ...baseRun,
576
580
  session_name: projectName,
@@ -643,6 +647,12 @@ class RunTree {
643
647
  }
644
648
  }
645
649
  }
650
+ if (primary) {
651
+ return {
652
+ ...baseRun,
653
+ session_name: projectName,
654
+ };
655
+ }
646
656
  // Remap IDs for the replica using nonCryptographicUuid7Deterministic
647
657
  // This ensures consistency across runs in the same replica while
648
658
  // preserving UUID7 properties (time-ordering, monotonicity)
@@ -691,9 +701,10 @@ class RunTree {
691
701
  try {
692
702
  const runtimeEnv = (0, env_js_2.getRuntimeEnvironment)();
693
703
  if (this.replicas && this.replicas.length > 0) {
694
- for (const { projectName, apiKey, apiUrl, workspaceId, reroot, client: replicaClient, } of this.replicas) {
704
+ for (const { projectName, primary, apiKey, apiUrl, workspaceId, reroot, client: replicaClient, } of this.replicas) {
695
705
  const runCreate = this._remapForProject({
696
706
  projectName: projectName ?? this.project_name,
707
+ primary,
697
708
  runtimeEnv,
698
709
  excludeChildRuns: true,
699
710
  reroot,
@@ -728,9 +739,10 @@ class RunTree {
728
739
  }
729
740
  async patchRun(options) {
730
741
  if (this.replicas && this.replicas.length > 0) {
731
- for (const { projectName, apiKey, apiUrl, workspaceId, updates, reroot, client: replicaClient, } of this.replicas) {
742
+ for (const { projectName, primary, apiKey, apiUrl, workspaceId, updates, reroot, client: replicaClient, } of this.replicas) {
732
743
  const runData = this._remapForProject({
733
744
  projectName: projectName ?? this.project_name,
745
+ primary,
734
746
  runtimeEnv: undefined,
735
747
  excludeChildRuns: true,
736
748
  reroot,
@@ -989,9 +1001,23 @@ function _getWriteReplicasFromEnv() {
989
1001
  `expected string, got ${typeof item.api_key}`);
990
1002
  continue;
991
1003
  }
1004
+ if (item.project_name !== undefined &&
1005
+ item.project_name !== null &&
1006
+ typeof item.project_name !== "string") {
1007
+ console.warn(`Invalid project_name type in LANGSMITH_RUNS_ENDPOINTS: ` +
1008
+ `expected string, got ${typeof item.project_name}`);
1009
+ continue;
1010
+ }
1011
+ if (item.primary !== undefined && typeof item.primary !== "boolean") {
1012
+ console.warn(`Invalid primary type in LANGSMITH_RUNS_ENDPOINTS: ` +
1013
+ `expected boolean, got ${typeof item.primary}`);
1014
+ continue;
1015
+ }
992
1016
  replicas.push({
993
1017
  apiUrl: item.api_url.replace(/\/$/, ""),
994
1018
  apiKey: item.api_key,
1019
+ projectName: item.project_name ?? undefined,
1020
+ primary: item.primary ?? undefined,
995
1021
  });
996
1022
  }
997
1023
  return replicas;
@@ -1031,9 +1057,8 @@ function _getWriteReplicasFromEnv() {
1031
1057
  }
1032
1058
  }
1033
1059
  function _ensureWriteReplicas(replicas) {
1034
- // If null -> fetch from env
1035
- if (replicas) {
1036
- return replicas.map((replica) => {
1060
+ const ensured = replicas
1061
+ ? replicas.map((replica) => {
1037
1062
  if (Array.isArray(replica)) {
1038
1063
  return {
1039
1064
  projectName: replica[0],
@@ -1041,9 +1066,12 @@ function _ensureWriteReplicas(replicas) {
1041
1066
  };
1042
1067
  }
1043
1068
  return replica;
1044
- });
1069
+ })
1070
+ : _getWriteReplicasFromEnv();
1071
+ if (ensured.filter((replica) => replica.primary === true).length > 1) {
1072
+ throw new Error("Only one replica can be marked as primary.");
1045
1073
  }
1046
- return _getWriteReplicasFromEnv();
1074
+ return ensured;
1047
1075
  }
1048
1076
  function _checkEndpointEnvUnset(parsed) {
1049
1077
  if (Object.keys(parsed).length > 0 &&
@@ -55,11 +55,13 @@ interface HeadersLike {
55
55
  set(name: string, value: string): void;
56
56
  }
57
57
  type ProjectReplica = [string, KVMap | undefined];
58
- type WriteReplica = {
58
+ export type WriteReplica = {
59
59
  apiUrl?: string;
60
60
  apiKey?: string;
61
61
  workspaceId?: string;
62
62
  projectName?: string;
63
+ /** Whether this replica keeps the original run IDs. */
64
+ primary?: boolean;
63
65
  updates?: KVMap | undefined;
64
66
  fromEnv?: boolean;
65
67
  reroot?: boolean;
package/dist/run_trees.js CHANGED
@@ -40,12 +40,16 @@ export function convertToDottedOrderFormat(epoch, runId, executionOrder = 1) {
40
40
  }
41
41
  const HEADER_SAFE_REPLICA_FIELDS = new Set([
42
42
  "projectName",
43
+ "primary",
43
44
  "updates",
44
45
  "reroot",
45
46
  ]);
46
47
  function filterReplicaForHeaders(replica) {
47
48
  const filtered = {};
48
49
  for (const key of Object.keys(replica)) {
50
+ if (key === "primary" && typeof replica[key] !== "boolean") {
51
+ continue;
52
+ }
49
53
  if (HEADER_SAFE_REPLICA_FIELDS.has(key)) {
50
54
  filtered[key] = replica[key];
51
55
  }
@@ -561,10 +565,10 @@ export class RunTree {
561
565
  }
562
566
  }
563
567
  _remapForProject(params) {
564
- const { projectName, runtimeEnv, excludeChildRuns = true, reroot = false, distributedParentId, apiUrl, apiKey, workspaceId, } = params;
568
+ const { projectName, primary, runtimeEnv, excludeChildRuns = true, reroot = false, distributedParentId, apiUrl, apiKey, workspaceId, } = params;
565
569
  const baseRun = this._convertToCreate(this, runtimeEnv, excludeChildRuns);
566
- // Skip remapping if project name is the same
567
- if (projectName === this.project_name) {
570
+ // Preserve legacy behavior when `primary` is omitted.
571
+ if (primary === undefined && projectName === this.project_name) {
568
572
  return {
569
573
  ...baseRun,
570
574
  session_name: projectName,
@@ -637,6 +641,12 @@ export class RunTree {
637
641
  }
638
642
  }
639
643
  }
644
+ if (primary) {
645
+ return {
646
+ ...baseRun,
647
+ session_name: projectName,
648
+ };
649
+ }
640
650
  // Remap IDs for the replica using nonCryptographicUuid7Deterministic
641
651
  // This ensures consistency across runs in the same replica while
642
652
  // preserving UUID7 properties (time-ordering, monotonicity)
@@ -685,9 +695,10 @@ export class RunTree {
685
695
  try {
686
696
  const runtimeEnv = getRuntimeEnvironment();
687
697
  if (this.replicas && this.replicas.length > 0) {
688
- for (const { projectName, apiKey, apiUrl, workspaceId, reroot, client: replicaClient, } of this.replicas) {
698
+ for (const { projectName, primary, apiKey, apiUrl, workspaceId, reroot, client: replicaClient, } of this.replicas) {
689
699
  const runCreate = this._remapForProject({
690
700
  projectName: projectName ?? this.project_name,
701
+ primary,
691
702
  runtimeEnv,
692
703
  excludeChildRuns: true,
693
704
  reroot,
@@ -722,9 +733,10 @@ export class RunTree {
722
733
  }
723
734
  async patchRun(options) {
724
735
  if (this.replicas && this.replicas.length > 0) {
725
- for (const { projectName, apiKey, apiUrl, workspaceId, updates, reroot, client: replicaClient, } of this.replicas) {
736
+ for (const { projectName, primary, apiKey, apiUrl, workspaceId, updates, reroot, client: replicaClient, } of this.replicas) {
726
737
  const runData = this._remapForProject({
727
738
  projectName: projectName ?? this.project_name,
739
+ primary,
728
740
  runtimeEnv: undefined,
729
741
  excludeChildRuns: true,
730
742
  reroot,
@@ -982,9 +994,23 @@ function _getWriteReplicasFromEnv() {
982
994
  `expected string, got ${typeof item.api_key}`);
983
995
  continue;
984
996
  }
997
+ if (item.project_name !== undefined &&
998
+ item.project_name !== null &&
999
+ typeof item.project_name !== "string") {
1000
+ console.warn(`Invalid project_name type in LANGSMITH_RUNS_ENDPOINTS: ` +
1001
+ `expected string, got ${typeof item.project_name}`);
1002
+ continue;
1003
+ }
1004
+ if (item.primary !== undefined && typeof item.primary !== "boolean") {
1005
+ console.warn(`Invalid primary type in LANGSMITH_RUNS_ENDPOINTS: ` +
1006
+ `expected boolean, got ${typeof item.primary}`);
1007
+ continue;
1008
+ }
985
1009
  replicas.push({
986
1010
  apiUrl: item.api_url.replace(/\/$/, ""),
987
1011
  apiKey: item.api_key,
1012
+ projectName: item.project_name ?? undefined,
1013
+ primary: item.primary ?? undefined,
988
1014
  });
989
1015
  }
990
1016
  return replicas;
@@ -1024,9 +1050,8 @@ function _getWriteReplicasFromEnv() {
1024
1050
  }
1025
1051
  }
1026
1052
  function _ensureWriteReplicas(replicas) {
1027
- // If null -> fetch from env
1028
- if (replicas) {
1029
- return replicas.map((replica) => {
1053
+ const ensured = replicas
1054
+ ? replicas.map((replica) => {
1030
1055
  if (Array.isArray(replica)) {
1031
1056
  return {
1032
1057
  projectName: replica[0],
@@ -1034,9 +1059,12 @@ function _ensureWriteReplicas(replicas) {
1034
1059
  };
1035
1060
  }
1036
1061
  return replica;
1037
- });
1062
+ })
1063
+ : _getWriteReplicasFromEnv();
1064
+ if (ensured.filter((replica) => replica.primary === true).length > 1) {
1065
+ throw new Error("Only one replica can be marked as primary.");
1038
1066
  }
1039
- return _getWriteReplicasFromEnv();
1067
+ return ensured;
1040
1068
  }
1041
1069
  function _checkEndpointEnvUnset(parsed) {
1042
1070
  if (Object.keys(parsed).length > 0 &&
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports._MIN_BACKEND_VERSION = void 0;
4
- exports._MIN_BACKEND_VERSION = "0.16.13rc1";
4
+ exports._MIN_BACKEND_VERSION = "0.16.14rc1";
@@ -1 +1 @@
1
- export declare const _MIN_BACKEND_VERSION = "0.16.13rc1";
1
+ export declare const _MIN_BACKEND_VERSION = "0.16.14rc1";
@@ -1 +1 @@
1
- export const _MIN_BACKEND_VERSION = "0.16.13rc1";
1
+ export const _MIN_BACKEND_VERSION = "0.16.14rc1";
@@ -30,10 +30,18 @@ function _logTestFeedback(params) {
30
30
  throw new Error("Could not log feedback to LangSmith: missing run information. Please contact us for help.");
31
31
  }
32
32
  exports.evaluatorLogFeedbackPromises.add((async () => {
33
+ if (context.project == null) {
34
+ throw new Error("Could not log feedback to LangSmith: missing project information. Please contact us for help.");
35
+ }
33
36
  await exports.syncExamplePromises.get(exampleId);
34
- await client?.logEvaluationFeedback(feedback, runTree, sourceRunId !== undefined
35
- ? { __run: { run_id: sourceRunId } }
36
- : undefined);
37
+ await client?.logEvaluationFeedback({
38
+ evaluatorResponse: feedback,
39
+ run: runTree,
40
+ projectId: context.project.id,
41
+ sourceInfo: sourceRunId !== undefined
42
+ ? { __run: { run_id: sourceRunId } }
43
+ : undefined,
44
+ });
37
45
  })());
38
46
  }
39
47
  context.onFeedbackLogged?.(feedback);
@@ -25,10 +25,18 @@ export function _logTestFeedback(params) {
25
25
  throw new Error("Could not log feedback to LangSmith: missing run information. Please contact us for help.");
26
26
  }
27
27
  evaluatorLogFeedbackPromises.add((async () => {
28
+ if (context.project == null) {
29
+ throw new Error("Could not log feedback to LangSmith: missing project information. Please contact us for help.");
30
+ }
28
31
  await syncExamplePromises.get(exampleId);
29
- await client?.logEvaluationFeedback(feedback, runTree, sourceRunId !== undefined
30
- ? { __run: { run_id: sourceRunId } }
31
- : undefined);
32
+ await client?.logEvaluationFeedback({
33
+ evaluatorResponse: feedback,
34
+ run: runTree,
35
+ projectId: context.project.id,
36
+ sourceInfo: sourceRunId !== undefined
37
+ ? { __run: { run_id: sourceRunId } }
38
+ : undefined,
39
+ });
32
40
  })());
33
41
  }
34
42
  context.onFeedbackLogged?.(feedback);
@@ -573,6 +573,9 @@ function generateWrapperFromJestlikeMethods(methods, testRunnerName) {
573
573
  const tracedFunction = (0, traceable_js_1.traceable)(async () => {
574
574
  return globals_js_1.testWrapperAsyncLocalStorageInstance.run({
575
575
  ...context,
576
+ dataset,
577
+ project,
578
+ client,
576
579
  currentExample: {
577
580
  inputs,
578
581
  outputs: referenceOutputs,
@@ -526,6 +526,9 @@ export function generateWrapperFromJestlikeMethods(methods, testRunnerName) {
526
526
  const tracedFunction = traceable(async () => {
527
527
  return testWrapperAsyncLocalStorageInstance.run({
528
528
  ...context,
529
+ dataset,
530
+ project,
531
+ client,
529
532
  currentExample: {
530
533
  inputs,
531
534
  outputs: referenceOutputs,
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.v2RunToRun = v2RunToRun;
4
+ exports.loadTracesV2 = loadTracesV2;
5
+ // Omitting selects from `/v2/runs/query` returns only the run ID.
6
+ const V2_RUN_SELECTS = [
7
+ "ID",
8
+ "NAME",
9
+ "RUN_TYPE",
10
+ "STATUS",
11
+ "START_TIME",
12
+ "END_TIME",
13
+ "INPUTS",
14
+ "OUTPUTS",
15
+ "PARENT_RUN_IDS",
16
+ "PROJECT_ID",
17
+ "TRACE_ID",
18
+ "DOTTED_ORDER",
19
+ "REFERENCE_EXAMPLE_ID",
20
+ "ERROR",
21
+ ];
22
+ function v2RunToRun(run) {
23
+ if (run.id == null || run.name == null || run.run_type == null) {
24
+ throw new Error("V2 run response is missing required fields.");
25
+ }
26
+ return {
27
+ id: run.id,
28
+ name: run.name,
29
+ run_type: run.run_type.toLowerCase(),
30
+ start_time: run.start_time,
31
+ end_time: run.end_time,
32
+ trace_id: run.trace_id,
33
+ session_id: run.project_id,
34
+ parent_run_id: run.parent_run_ids?.at(-1),
35
+ dotted_order: run.dotted_order,
36
+ reference_example_id: run.reference_example_id,
37
+ inputs: run.inputs ?? {},
38
+ outputs: run.outputs,
39
+ error: run.error ?? undefined,
40
+ status: run.status?.toLowerCase(),
41
+ };
42
+ }
43
+ async function loadTracesV2(client, project, options) {
44
+ const runs = [];
45
+ const pager = client.runs.queryV2({
46
+ project_ids: [project.id],
47
+ min_start_time: new Date(project.start_time).toISOString(),
48
+ max_start_time: new Date(project.end_time ?? Date.now()).toISOString(),
49
+ is_root: options.isRoot,
50
+ selects: V2_RUN_SELECTS,
51
+ });
52
+ for await (const run of pager) {
53
+ runs.push(v2RunToRun(run));
54
+ }
55
+ return runs;
56
+ }
@@ -0,0 +1,7 @@
1
+ import type { Run as V2Run } from "../_openapi_client/resources/runs/runs.js";
2
+ import type { Client } from "../client.js";
3
+ import type { Run, TracerSession } from "../schemas.js";
4
+ export declare function v2RunToRun(run: V2Run): Run;
5
+ export declare function loadTracesV2(client: Client, project: TracerSession, options: {
6
+ isRoot?: boolean;
7
+ }): Promise<Run[]>;
@@ -0,0 +1,52 @@
1
+ // Omitting selects from `/v2/runs/query` returns only the run ID.
2
+ const V2_RUN_SELECTS = [
3
+ "ID",
4
+ "NAME",
5
+ "RUN_TYPE",
6
+ "STATUS",
7
+ "START_TIME",
8
+ "END_TIME",
9
+ "INPUTS",
10
+ "OUTPUTS",
11
+ "PARENT_RUN_IDS",
12
+ "PROJECT_ID",
13
+ "TRACE_ID",
14
+ "DOTTED_ORDER",
15
+ "REFERENCE_EXAMPLE_ID",
16
+ "ERROR",
17
+ ];
18
+ export function v2RunToRun(run) {
19
+ if (run.id == null || run.name == null || run.run_type == null) {
20
+ throw new Error("V2 run response is missing required fields.");
21
+ }
22
+ return {
23
+ id: run.id,
24
+ name: run.name,
25
+ run_type: run.run_type.toLowerCase(),
26
+ start_time: run.start_time,
27
+ end_time: run.end_time,
28
+ trace_id: run.trace_id,
29
+ session_id: run.project_id,
30
+ parent_run_id: run.parent_run_ids?.at(-1),
31
+ dotted_order: run.dotted_order,
32
+ reference_example_id: run.reference_example_id,
33
+ inputs: run.inputs ?? {},
34
+ outputs: run.outputs,
35
+ error: run.error ?? undefined,
36
+ status: run.status?.toLowerCase(),
37
+ };
38
+ }
39
+ export async function loadTracesV2(client, project, options) {
40
+ const runs = [];
41
+ const pager = client.runs.queryV2({
42
+ project_ids: [project.id],
43
+ min_start_time: new Date(project.start_time).toISOString(),
44
+ max_start_time: new Date(project.end_time ?? Date.now()).toISOString(),
45
+ is_root: options.isRoot,
46
+ selects: V2_RUN_SELECTS,
47
+ });
48
+ for await (const run of pager) {
49
+ runs.push(v2RunToRun(run));
50
+ }
51
+ return runs;
52
+ }
package/dist/uuid.cjs CHANGED
@@ -2,12 +2,32 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.uuid7FromTime = void 0;
4
4
  exports.uuid7 = uuid7;
5
+ exports.computeRunIdForSecondaryReplica = computeRunIdForSecondaryReplica;
5
6
  const index_js_1 = require("./utils/uuid/src/index.cjs");
6
- var _uuid_js_1 = require("./utils/_uuid.cjs");
7
- Object.defineProperty(exports, "uuid7FromTime", { enumerable: true, get: function () { return _uuid_js_1.uuid7FromTime; } });
7
+ const _uuid_js_1 = require("./utils/_uuid.cjs");
8
+ var _uuid_js_2 = require("./utils/_uuid.cjs");
9
+ Object.defineProperty(exports, "uuid7FromTime", { enumerable: true, get: function () { return _uuid_js_2.uuid7FromTime; } });
8
10
  /**
9
11
  * Generate a random UUID v7 string.
10
12
  */
11
13
  function uuid7() {
12
14
  return (0, index_js_1.v7)();
13
15
  }
16
+ /**
17
+ * Compute the run ID used for a secondary tracing replica.
18
+ *
19
+ * @param runId - The original UUID v7 run ID.
20
+ * @param projectName - The secondary replica's destination project name.
21
+ * @returns The run ID used in the secondary replica destination.
22
+ */
23
+ function computeRunIdForSecondaryReplica(runId, projectName) {
24
+ if (typeof projectName !== "string" || projectName.length === 0) {
25
+ throw new Error("projectName must be a non-empty string");
26
+ }
27
+ (0, _uuid_js_1.assertUuid)(runId, "runId");
28
+ const normalizedRunId = runId.toLowerCase();
29
+ if ((0, _uuid_js_1.getUuidVersion)(normalizedRunId) !== 7) {
30
+ throw new Error("runId must be a UUID v7");
31
+ }
32
+ return (0, _uuid_js_1.nonCryptographicUuid7Deterministic)(normalizedRunId, projectName);
33
+ }
package/dist/uuid.d.ts CHANGED
@@ -3,3 +3,11 @@ export { uuid7FromTime } from "./utils/_uuid.js";
3
3
  * Generate a random UUID v7 string.
4
4
  */
5
5
  export declare function uuid7(): string;
6
+ /**
7
+ * Compute the run ID used for a secondary tracing replica.
8
+ *
9
+ * @param runId - The original UUID v7 run ID.
10
+ * @param projectName - The secondary replica's destination project name.
11
+ * @returns The run ID used in the secondary replica destination.
12
+ */
13
+ export declare function computeRunIdForSecondaryReplica(runId: string, projectName: string): string;
package/dist/uuid.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { v7 as uuidv7 } from "./utils/uuid/src/index.js";
2
+ import { assertUuid, getUuidVersion, nonCryptographicUuid7Deterministic, } from "./utils/_uuid.js";
2
3
  export { uuid7FromTime } from "./utils/_uuid.js";
3
4
  /**
4
5
  * Generate a random UUID v7 string.
@@ -6,3 +7,21 @@ export { uuid7FromTime } from "./utils/_uuid.js";
6
7
  export function uuid7() {
7
8
  return uuidv7();
8
9
  }
10
+ /**
11
+ * Compute the run ID used for a secondary tracing replica.
12
+ *
13
+ * @param runId - The original UUID v7 run ID.
14
+ * @param projectName - The secondary replica's destination project name.
15
+ * @returns The run ID used in the secondary replica destination.
16
+ */
17
+ export function computeRunIdForSecondaryReplica(runId, projectName) {
18
+ if (typeof projectName !== "string" || projectName.length === 0) {
19
+ throw new Error("projectName must be a non-empty string");
20
+ }
21
+ assertUuid(runId, "runId");
22
+ const normalizedRunId = runId.toLowerCase();
23
+ if (getUuidVersion(normalizedRunId) !== 7) {
24
+ throw new Error("runId must be a UUID v7");
25
+ }
26
+ return nonCryptographicUuid7Deterministic(normalizedRunId, projectName);
27
+ }
@@ -244,7 +244,13 @@ const getChatModelInvocationParamsFn = (provider, prepopulatedInvocationParams,
244
244
  if (useResponsesApi) {
245
245
  ls_invocation_params.use_responses_api = true;
246
246
  }
247
+ const requestMetadata = typeof params.metadata === "object" &&
248
+ params.metadata !== null &&
249
+ !Array.isArray(params.metadata)
250
+ ? params.metadata
251
+ : {};
247
252
  return {
253
+ ...requestMetadata,
248
254
  ls_provider: provider,
249
255
  ls_model_type: "chat",
250
256
  ls_model_name: params.model,
@@ -241,7 +241,13 @@ const getChatModelInvocationParamsFn = (provider, prepopulatedInvocationParams,
241
241
  if (useResponsesApi) {
242
242
  ls_invocation_params.use_responses_api = true;
243
243
  }
244
+ const requestMetadata = typeof params.metadata === "object" &&
245
+ params.metadata !== null &&
246
+ !Array.isArray(params.metadata)
247
+ ? params.metadata
248
+ : {};
244
249
  return {
250
+ ...requestMetadata,
245
251
  ls_provider: provider,
246
252
  ls_model_type: "chat",
247
253
  ls_model_name: params.model,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.8.3",
3
+ "version": "0.8.5",
4
4
  "description": "Client library to connect to the LangSmith Observability and Evaluation Platform.",
5
5
  "packageManager": "pnpm@10.33.0",
6
6
  "files": [
@@ -478,7 +478,11 @@
478
478
  "js-yaml": "^4.1.1",
479
479
  "vite": "^7.3.2",
480
480
  "form-data": "4.0.6",
481
- "langsmith": "0.6.0"
481
+ "langsmith": "0.6.0",
482
+ "@babel/core": "^7.29.7",
483
+ "esbuild": "^0.28.1",
484
+ "markdown-it": "^14.3.0",
485
+ "uuid": "^11.1.1"
482
486
  }
483
487
  },
484
488
  "browser": {