langsmith 0.10.7 → 0.10.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/dist/_openapi_client/client.cjs +26 -2
  2. package/dist/_openapi_client/client.d.ts +15 -6
  3. package/dist/_openapi_client/client.js +27 -3
  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/items.cjs +13 -6
  7. package/dist/_openapi_client/resources/annotation-queues/items.d.ts +33 -8
  8. package/dist/_openapi_client/resources/annotation-queues/items.js +13 -6
  9. package/dist/_openapi_client/resources/datasets/datasets.cjs +9 -0
  10. package/dist/_openapi_client/resources/datasets/datasets.d.ts +4 -0
  11. package/dist/_openapi_client/resources/datasets/datasets.js +9 -0
  12. package/dist/_openapi_client/resources/datasets/examples.cjs +26 -0
  13. package/dist/_openapi_client/resources/datasets/examples.d.ts +23 -0
  14. package/dist/_openapi_client/resources/datasets/examples.js +22 -0
  15. package/dist/_openapi_client/resources/fleet/fleet.cjs +54 -0
  16. package/dist/_openapi_client/resources/fleet/fleet.d.ts +9 -0
  17. package/dist/_openapi_client/resources/fleet/fleet.js +17 -0
  18. package/dist/_openapi_client/resources/fleet/threads.cjs +18 -0
  19. package/dist/_openapi_client/resources/fleet/threads.d.ts +19 -0
  20. package/dist/_openapi_client/resources/fleet/threads.js +14 -0
  21. package/dist/_openapi_client/resources/index.cjs +8 -2
  22. package/dist/_openapi_client/resources/index.d.ts +6 -3
  23. package/dist/_openapi_client/resources/index.js +5 -2
  24. package/dist/_openapi_client/resources/info.d.ts +6 -0
  25. package/dist/_openapi_client/resources/issues.cjs +2 -2
  26. package/dist/_openapi_client/resources/issues.d.ts +188 -4
  27. package/dist/_openapi_client/resources/issues.js +2 -2
  28. package/dist/_openapi_client/resources/online-evaluators.cjs +7 -4
  29. package/dist/_openapi_client/resources/online-evaluators.d.ts +63 -4
  30. package/dist/_openapi_client/resources/online-evaluators.js +7 -4
  31. package/dist/_openapi_client/resources/product-feedback.cjs +33 -0
  32. package/dist/_openapi_client/resources/product-feedback.d.ts +77 -0
  33. package/dist/_openapi_client/resources/product-feedback.js +29 -0
  34. package/dist/_openapi_client/resources/runs/runs.d.ts +26 -16
  35. package/dist/_openapi_client/resources/sandboxes/boxes.cjs +44 -4
  36. package/dist/_openapi_client/resources/sandboxes/boxes.d.ts +256 -21
  37. package/dist/_openapi_client/resources/sandboxes/boxes.js +44 -4
  38. package/dist/_openapi_client/resources/sandboxes/registries.d.ts +10 -2
  39. package/dist/_openapi_client/resources/sandboxes/sandboxes.cjs +13 -0
  40. package/dist/_openapi_client/resources/sandboxes/sandboxes.d.ts +169 -14
  41. package/dist/_openapi_client/resources/sandboxes/sandboxes.js +13 -0
  42. package/dist/_openapi_client/resources/sandboxes/snapshots.cjs +10 -6
  43. package/dist/_openapi_client/resources/sandboxes/snapshots.d.ts +37 -6
  44. package/dist/_openapi_client/resources/sandboxes/snapshots.js +10 -6
  45. package/dist/_openapi_client/resources/sessions.cjs +23 -0
  46. package/dist/_openapi_client/resources/sessions.d.ts +732 -0
  47. package/dist/_openapi_client/resources/sessions.js +19 -0
  48. package/dist/_openapi_client/resources/threads/index.cjs +9 -0
  49. package/dist/_openapi_client/resources/threads/index.d.ts +2 -0
  50. package/dist/_openapi_client/resources/threads/index.js +4 -0
  51. package/dist/_openapi_client/resources/threads/share.cjs +61 -0
  52. package/dist/_openapi_client/resources/threads/share.d.ts +71 -0
  53. package/dist/_openapi_client/resources/threads/share.js +57 -0
  54. package/dist/_openapi_client/resources/threads/threads.cjs +143 -0
  55. package/dist/_openapi_client/resources/threads/threads.d.ts +973 -0
  56. package/dist/_openapi_client/resources/threads/threads.js +106 -0
  57. package/dist/_openapi_client/resources/threads.cjs +15 -67
  58. package/dist/_openapi_client/resources/threads.d.ts +1 -709
  59. package/dist/_openapi_client/resources/threads.js +1 -65
  60. package/dist/_openapi_client/resources/traces.d.ts +7 -1
  61. package/dist/_openapi_client/version.cjs +1 -1
  62. package/dist/_openapi_client/version.js +1 -1
  63. package/dist/address.cjs +176 -99
  64. package/dist/address.d.ts +63 -8
  65. package/dist/address.js +170 -90
  66. package/dist/anonymizer/index.cjs +1 -1
  67. package/dist/anonymizer/index.js +1 -1
  68. package/dist/client.cjs +39 -19
  69. package/dist/client.d.ts +20 -4
  70. package/dist/client.js +34 -14
  71. package/dist/experimental/otel/exporter.cjs +21 -4
  72. package/dist/experimental/otel/exporter.d.ts +4 -2
  73. package/dist/experimental/otel/exporter.js +21 -4
  74. package/dist/index.cjs +5 -2
  75. package/dist/index.d.ts +2 -2
  76. package/dist/index.js +2 -2
  77. package/dist/run_trees.cjs +26 -43
  78. package/dist/run_trees.d.ts +4 -4
  79. package/dist/run_trees.js +23 -40
  80. package/dist/sandbox/client.cjs +33 -4
  81. package/dist/sandbox/client.d.ts +4 -0
  82. package/dist/sandbox/client.js +34 -5
  83. package/dist/sandbox/command_handle.cjs +8 -0
  84. package/dist/sandbox/command_handle.js +8 -0
  85. package/dist/sandbox/sandbox.cjs +7 -0
  86. package/dist/sandbox/sandbox.js +7 -0
  87. package/dist/sandbox/service_url.cjs +9 -1
  88. package/dist/sandbox/service_url.d.ts +2 -1
  89. package/dist/sandbox/service_url.js +9 -1
  90. package/dist/sandbox/tracing.cjs +13 -0
  91. package/dist/sandbox/tracing.d.ts +1 -0
  92. package/dist/sandbox/tracing.js +10 -0
  93. package/dist/schemas.d.ts +3 -3
  94. package/dist/traceable.cjs +5 -4
  95. package/dist/traceable.js +4 -3
  96. package/dist/utils/{agent_addressing.cjs → addressing.cjs} +22 -23
  97. package/dist/utils/{agent_addressing.d.ts → addressing.d.ts} +5 -8
  98. package/dist/utils/{agent_addressing.js → addressing.js} +23 -23
  99. package/dist/utils/env.cjs +6 -4
  100. package/dist/utils/env.js +6 -4
  101. package/package.json +1 -1
@@ -39,6 +39,7 @@ const constants = __importStar(require("./constants.cjs"));
39
39
  const env_js_1 = require("../../env.cjs");
40
40
  const env_js_2 = require("../../utils/env.cjs");
41
41
  const vercel_js_1 = require("../../utils/vercel.cjs");
42
+ const warn_js_1 = require("../../utils/warn.cjs");
42
43
  /**
43
44
  * Convert headers string in format "name=value,name2=value2" to object
44
45
  */
@@ -60,8 +61,10 @@ function parseHeadersString(headersStr) {
60
61
  *
61
62
  * This exporter automatically configures itself with LangSmith endpoints and API keys,
62
63
  * based on your LANGSMITH_API_KEY and LANGSMITH_PROJECT environment variables.
63
- * Will also respect OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_OTLP_HEADERS environment
64
- * variables if set.
64
+ * OTEL_EXPORTER_OTLP_TRACES_ENDPOINT is a full traces URL and takes precedence over
65
+ * OTEL_EXPORTER_OTLP_ENDPOINT, a base URL to which /v1/traces is appended unless
66
+ * it already ends in /traces for compatibility.
67
+ * Also respects OTEL_EXPORTER_OTLP_HEADERS if set.
65
68
  *
66
69
  * @param config - Optional configuration object that accepts all OTLPTraceExporter parameters.
67
70
  * If not provided, uses default LangSmith configuration:
@@ -74,8 +77,22 @@ class LangSmithOTLPTraceExporter extends exporter_trace_otlp_proto_1.OTLPTraceEx
74
77
  const defaultLsEndpoint = (0, env_js_2.getLangSmithEnvironmentVariable)("ENDPOINT") ||
75
78
  "https://api.smith.langchain.com";
76
79
  const defaultBaseUrl = defaultLsEndpoint.replace(/\/$/, "");
77
- const defaultUrl = (0, env_js_2.getEnvironmentVariable)("OTEL_EXPORTER_OTLP_ENDPOINT") ??
78
- `${defaultBaseUrl}/otel/v1/traces`;
80
+ const baseEndpoint = (0, env_js_2.getEnvironmentVariable)("OTEL_EXPORTER_OTLP_ENDPOINT") ||
81
+ `${defaultBaseUrl}/otel`;
82
+ const defaultUrl = (0, env_js_2.getEnvironmentVariable)("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT") ||
83
+ (baseEndpoint.endsWith("/traces")
84
+ ? baseEndpoint
85
+ : `${baseEndpoint.replace(/\/$/, "")}/v1/traces`);
86
+ if (config?.url === undefined &&
87
+ !(0, env_js_2.getEnvironmentVariable)("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT") &&
88
+ baseEndpoint.endsWith("/traces")) {
89
+ (0, warn_js_1.warnOnce)("LangSmith now treats OTEL_EXPORTER_OTLP_ENDPOINT as a base URL and " +
90
+ "appends /v1/traces. Your value ends in /traces, so it is being " +
91
+ "preserved unchanged for compatibility. This fallback will be " +
92
+ "removed in the v1 release of the SDK. Move this full URL to " +
93
+ "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT to use standard OpenTelemetry " +
94
+ "configuration.");
95
+ }
79
96
  // Configure headers with API key and project if available
80
97
  let headers = config?.headers;
81
98
  if (headers === undefined) {
@@ -43,8 +43,10 @@ export type LangSmithOTLPTraceExporterConfig = ConstructorParameters<typeof OTLP
43
43
  *
44
44
  * This exporter automatically configures itself with LangSmith endpoints and API keys,
45
45
  * based on your LANGSMITH_API_KEY and LANGSMITH_PROJECT environment variables.
46
- * Will also respect OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_OTLP_HEADERS environment
47
- * variables if set.
46
+ * OTEL_EXPORTER_OTLP_TRACES_ENDPOINT is a full traces URL and takes precedence over
47
+ * OTEL_EXPORTER_OTLP_ENDPOINT, a base URL to which /v1/traces is appended unless
48
+ * it already ends in /traces for compatibility.
49
+ * Also respects OTEL_EXPORTER_OTLP_HEADERS if set.
48
50
  *
49
51
  * @param config - Optional configuration object that accepts all OTLPTraceExporter parameters.
50
52
  * If not provided, uses default LangSmith configuration:
@@ -3,6 +3,7 @@ import * as constants from "./constants.js";
3
3
  import { isEnvTracingEnabled } from "../../env.js";
4
4
  import { getEnvironmentVariable, getLangSmithEnvironmentVariable, } from "../../utils/env.js";
5
5
  import { extractUsageMetadata } from "../../utils/vercel.js";
6
+ import { warnOnce } from "../../utils/warn.js";
6
7
  /**
7
8
  * Convert headers string in format "name=value,name2=value2" to object
8
9
  */
@@ -24,8 +25,10 @@ function parseHeadersString(headersStr) {
24
25
  *
25
26
  * This exporter automatically configures itself with LangSmith endpoints and API keys,
26
27
  * based on your LANGSMITH_API_KEY and LANGSMITH_PROJECT environment variables.
27
- * Will also respect OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_OTLP_HEADERS environment
28
- * variables if set.
28
+ * OTEL_EXPORTER_OTLP_TRACES_ENDPOINT is a full traces URL and takes precedence over
29
+ * OTEL_EXPORTER_OTLP_ENDPOINT, a base URL to which /v1/traces is appended unless
30
+ * it already ends in /traces for compatibility.
31
+ * Also respects OTEL_EXPORTER_OTLP_HEADERS if set.
29
32
  *
30
33
  * @param config - Optional configuration object that accepts all OTLPTraceExporter parameters.
31
34
  * If not provided, uses default LangSmith configuration:
@@ -38,8 +41,22 @@ export class LangSmithOTLPTraceExporter extends OTLPTraceExporter {
38
41
  const defaultLsEndpoint = getLangSmithEnvironmentVariable("ENDPOINT") ||
39
42
  "https://api.smith.langchain.com";
40
43
  const defaultBaseUrl = defaultLsEndpoint.replace(/\/$/, "");
41
- const defaultUrl = getEnvironmentVariable("OTEL_EXPORTER_OTLP_ENDPOINT") ??
42
- `${defaultBaseUrl}/otel/v1/traces`;
44
+ const baseEndpoint = getEnvironmentVariable("OTEL_EXPORTER_OTLP_ENDPOINT") ||
45
+ `${defaultBaseUrl}/otel`;
46
+ const defaultUrl = getEnvironmentVariable("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT") ||
47
+ (baseEndpoint.endsWith("/traces")
48
+ ? baseEndpoint
49
+ : `${baseEndpoint.replace(/\/$/, "")}/v1/traces`);
50
+ if (config?.url === undefined &&
51
+ !getEnvironmentVariable("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT") &&
52
+ baseEndpoint.endsWith("/traces")) {
53
+ warnOnce("LangSmith now treats OTEL_EXPORTER_OTLP_ENDPOINT as a base URL and " +
54
+ "appends /v1/traces. Your value ends in /traces, so it is being " +
55
+ "preserved unchanged for compatibility. This fallback will be " +
56
+ "removed in the v1 release of the SDK. Move this full URL to " +
57
+ "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT to use standard OpenTelemetry " +
58
+ "configuration.");
59
+ }
43
60
  // Configure headers with API key and project if available
44
61
  let headers = config?.headers;
45
62
  if (headers === undefined) {
package/dist/index.cjs CHANGED
@@ -1,11 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LS_MESSAGE_VIEW_EXCLUDE = exports.__version__ = exports.InternalServerError = exports.RateLimitError = exports.UnprocessableEntityError = exports.ConflictError = exports.NotFoundError = exports.PermissionDeniedError = exports.AuthenticationError = exports.BadRequestError = exports.APIConnectionTimeoutError = exports.APIConnectionError = exports.APIUserAbortError = exports.APIError = exports.LangsmithError = exports.promptCacheSingleton = exports.configureGlobalPromptCache = exports.PromptCache = exports.Cache = exports.isTracingEnabled = exports.uuid7FromTime = exports.uuid7 = exports.computeRunIdForSecondaryReplica = exports.getDefaultProjectName = exports.overrideFetchImplementation = exports.EnvAddressError = exports.RunTree = exports.Client = void 0;
3
+ exports.LS_MESSAGE_VIEW_EXCLUDE = exports.__version__ = exports.InternalServerError = exports.RateLimitError = exports.UnprocessableEntityError = exports.ConflictError = exports.NotFoundError = exports.PermissionDeniedError = exports.AuthenticationError = exports.BadRequestError = exports.APIConnectionTimeoutError = exports.APIConnectionError = exports.APIUserAbortError = exports.APIError = exports.LangsmithError = exports.promptCacheSingleton = exports.configureGlobalPromptCache = exports.PromptCache = exports.Cache = exports.isTracingEnabled = exports.uuid7FromTime = exports.uuid7 = exports.computeRunIdForSecondaryReplica = exports.getDefaultProjectName = exports.overrideFetchImplementation = exports.EnvAddressError = exports.EvaluatorAddress = exports.ExperimentAddress = exports.AgentAddress = exports.RunTree = exports.Client = void 0;
4
4
  var client_js_1 = require("./client.cjs");
5
5
  Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_js_1.Client; } });
6
6
  var run_trees_js_1 = require("./run_trees.cjs");
7
7
  Object.defineProperty(exports, "RunTree", { enumerable: true, get: function () { return run_trees_js_1.RunTree; } });
8
8
  var address_js_1 = require("./address.cjs");
9
+ Object.defineProperty(exports, "AgentAddress", { enumerable: true, get: function () { return address_js_1.AgentAddress; } });
10
+ Object.defineProperty(exports, "ExperimentAddress", { enumerable: true, get: function () { return address_js_1.ExperimentAddress; } });
11
+ Object.defineProperty(exports, "EvaluatorAddress", { enumerable: true, get: function () { return address_js_1.EvaluatorAddress; } });
9
12
  Object.defineProperty(exports, "EnvAddressError", { enumerable: true, get: function () { return address_js_1.EnvAddressError; } });
10
13
  var fetch_js_1 = require("./singletons/fetch.cjs");
11
14
  Object.defineProperty(exports, "overrideFetchImplementation", { enumerable: true, get: function () { return fetch_js_1.overrideFetchImplementation; } });
@@ -37,6 +40,6 @@ Object.defineProperty(exports, "UnprocessableEntityError", { enumerable: true, g
37
40
  Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return error_js_1.RateLimitError; } });
38
41
  Object.defineProperty(exports, "InternalServerError", { enumerable: true, get: function () { return error_js_1.InternalServerError; } });
39
42
  // Update using pnpm bump-version
40
- exports.__version__ = "0.10.7";
43
+ exports.__version__ = "0.10.9";
41
44
  // Metadata key to hide a traced run from LangSmith's Messages View.
42
45
  exports.LS_MESSAGE_VIEW_EXCLUDE = "ls_message_view_exclude";
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  export { Client, type ClientConfig, type LangSmithTracingClientInterface, } from "./client.js";
2
2
  export type { Dataset, Example, TracerSession, Run, Feedback, FeedbackConfigSchema, RetrieverOutput, } from "./schemas.js";
3
3
  export { RunTree, type RunTreeConfig, type WriteReplica } from "./run_trees.js";
4
- export { type Address, EnvAddressError } from "./address.js";
4
+ export { AgentAddress, ExperimentAddress, EvaluatorAddress, type Address, type ApiAddress, type Environment, EnvAddressError, } from "./address.js";
5
5
  export { overrideFetchImplementation } from "./singletons/fetch.js";
6
6
  export { getDefaultProjectName } from "./utils/project.js";
7
7
  export { computeRunIdForSecondaryReplica, uuid7, uuid7FromTime, } from "./uuid.js";
8
8
  export { isTracingEnabled } from "./utils/guard.js";
9
9
  export { Cache, PromptCache, type CacheConfig, type CacheMetrics, configureGlobalPromptCache, promptCacheSingleton, } from "./utils/prompt_cache/index.js";
10
10
  export { LangsmithError, APIError, APIUserAbortError, APIConnectionError, APIConnectionTimeoutError, BadRequestError, AuthenticationError, PermissionDeniedError, NotFoundError, ConflictError, UnprocessableEntityError, RateLimitError, InternalServerError, } from "./_openapi_client/core/error.js";
11
- export declare const __version__ = "0.10.7";
11
+ export declare const __version__ = "0.10.9";
12
12
  export declare const LS_MESSAGE_VIEW_EXCLUDE: "ls_message_view_exclude";
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export { Client, } from "./client.js";
2
2
  export { RunTree } from "./run_trees.js";
3
- export { EnvAddressError } from "./address.js";
3
+ export { AgentAddress, ExperimentAddress, EvaluatorAddress, EnvAddressError, } from "./address.js";
4
4
  export { overrideFetchImplementation } from "./singletons/fetch.js";
5
5
  export { getDefaultProjectName } from "./utils/project.js";
6
6
  export { computeRunIdForSecondaryReplica, uuid7, uuid7FromTime, } from "./uuid.js";
@@ -8,6 +8,6 @@ export { isTracingEnabled } from "./utils/guard.js";
8
8
  export { Cache, PromptCache, configureGlobalPromptCache, promptCacheSingleton, } from "./utils/prompt_cache/index.js";
9
9
  export { LangsmithError, APIError, APIUserAbortError, APIConnectionError, APIConnectionTimeoutError, BadRequestError, AuthenticationError, PermissionDeniedError, NotFoundError, ConflictError, UnprocessableEntityError, RateLimitError, InternalServerError, } from "./_openapi_client/core/error.js";
10
10
  // Update using pnpm bump-version
11
- export const __version__ = "0.10.7";
11
+ export const __version__ = "0.10.9";
12
12
  // Metadata key to hide a traced run from LangSmith's Messages View.
13
13
  export const LS_MESSAGE_VIEW_EXCLUDE = "ls_message_view_exclude";
@@ -14,7 +14,7 @@ const env_js_3 = require("./utils/env.cjs");
14
14
  const warn_js_1 = require("./utils/warn.cjs");
15
15
  const _uuid_js_1 = require("./utils/_uuid.cjs");
16
16
  const index_js_1 = require("./utils/uuid/src/index.cjs");
17
- const agent_addressing_js_1 = require("./utils/agent_addressing.cjs");
17
+ const addressing_js_1 = require("./utils/addressing.cjs");
18
18
  const address_js_1 = require("./address.cjs");
19
19
  const TIMESTAMP_LENGTH = 36;
20
20
  // DNS namespace for UUID v5 (same as Python's uuid.NAMESPACE_DNS)
@@ -50,29 +50,17 @@ const HEADER_SAFE_REPLICA_FIELDS = new Set([
50
50
  "primary",
51
51
  "updates",
52
52
  "reroot",
53
- ...(0, address_js_1.wireKeys)(),
53
+ "address",
54
54
  ]);
55
- // URL-encoded JSON of the address's wire fields.
56
- const LANGSMITH_ADDRESS = "langsmith-address";
57
- /** Pops the address wire keys off untrusted `values`; never throws. */
58
- function takeHeaderAddress(values) {
59
- const wire = {};
60
- for (const key of (0, address_js_1.wireKeys)()) {
61
- if (key in values) {
62
- wire[key] = values[key];
63
- delete values[key];
64
- }
65
- }
55
+ /** Rebuilds an untrusted header address; `undefined` if unusable. */
56
+ function addressFromHeader(value) {
66
57
  try {
67
- return {
68
- named: Object.keys(wire).length > 0,
69
- address: (0, address_js_1.fromWire)(wire),
70
- };
58
+ return address_js_1.AgentAddress._fromLrn(value);
71
59
  }
72
60
  catch {
73
61
  // Values are untrusted, so not logged.
74
- console.warn("Ignoring an invalid address in a `baggage` header.");
75
- return { named: true };
62
+ console.warn("Ignoring an unusable address in a `baggage` header.");
63
+ return undefined;
76
64
  }
77
65
  }
78
66
  function filterReplicaForHeaders(replica) {
@@ -147,17 +135,8 @@ class Baggage {
147
135
  else if (key === "langsmith-project") {
148
136
  project_name = value;
149
137
  }
150
- else if (key === LANGSMITH_ADDRESS) {
151
- let parsed;
152
- try {
153
- parsed = JSON.parse(value);
154
- }
155
- catch {
156
- parsed = undefined;
157
- }
158
- if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
159
- address = takeHeaderAddress({ ...parsed }).address;
160
- }
138
+ else if (key === "langsmith-address") {
139
+ address = addressFromHeader(value);
161
140
  }
162
141
  else if (key === "langsmith-replicas") {
163
142
  const parsed = JSON.parse(value);
@@ -166,13 +145,17 @@ class Baggage {
166
145
  return [replica];
167
146
  }
168
147
  const filtered = filterReplicaForHeaders(replica);
169
- const { named, address } = takeHeaderAddress(filtered);
148
+ const raw = filtered.address;
149
+ delete filtered.address;
170
150
  // A project wins over an address; a replica with an invalid
171
151
  // address and no project is dropped.
172
- if (filtered.projectName || !named) {
152
+ if (filtered.projectName || raw == null) {
173
153
  return [filtered];
174
154
  }
175
- return address ? [{ ...filtered, address }] : [];
155
+ const replicaAddress = addressFromHeader(raw);
156
+ return replicaAddress
157
+ ? [{ ...filtered, address: replicaAddress }]
158
+ : [];
176
159
  });
177
160
  }
178
161
  }
@@ -190,7 +173,7 @@ class Baggage {
190
173
  items.push(`langsmith-project=${encodeURIComponent(this.project_name)}`);
191
174
  }
192
175
  if (this.address) {
193
- items.push(`${LANGSMITH_ADDRESS}=${encodeURIComponent(JSON.stringify((0, address_js_1.toWire)(this.address)))}`);
176
+ items.push(`langsmith-address=${encodeURIComponent(this.address._toLrn())}`);
194
177
  }
195
178
  return items.join(",");
196
179
  }
@@ -440,23 +423,23 @@ class RunTree {
440
423
  }
441
424
  /** Falls back to the env; a bad env leaves the run untraced. */
442
425
  _resolveAddressing(config) {
443
- const address = (0, agent_addressing_js_1.checkAddress)(config.address);
426
+ const address = (0, address_js_1.ensureAgent)(config.address);
444
427
  const project = config.project_name || undefined;
445
- (0, agent_addressing_js_1.rejectConflicting)(project, address);
428
+ (0, addressing_js_1.rejectConflicting)(project, address);
446
429
  if (project || address) {
447
430
  this.project_name = project;
448
431
  this.address = address;
449
432
  return;
450
433
  }
451
434
  try {
452
- [this.project_name, this.address] = (0, agent_addressing_js_1.resolveFromEnv)();
435
+ [this.project_name, this.address] = (0, addressing_js_1.resolveFromEnv)();
453
436
  }
454
437
  catch (e) {
455
438
  if (!(e instanceof address_js_1.EnvAddressError)) {
456
439
  throw e;
457
440
  }
458
441
  if ((0, env_js_1.isEnvTracingEnabled)(this.tracingEnabled)) {
459
- (0, agent_addressing_js_1.logUntraced)(e);
442
+ (0, addressing_js_1.logUntraced)(e);
460
443
  }
461
444
  this.project_name = undefined;
462
445
  this.address = undefined;
@@ -666,9 +649,9 @@ class RunTree {
666
649
  }
667
650
  /** A replica naming neither inherits the run tree's destination. */
668
651
  _replicaAddressing(replica) {
669
- const address = (0, agent_addressing_js_1.checkAddress)(replica.address);
652
+ const address = (0, address_js_1.ensureAgent)(replica.address);
670
653
  if (replica.projectName != null) {
671
- (0, agent_addressing_js_1.rejectConflicting)(replica.projectName, address);
654
+ (0, addressing_js_1.rejectConflicting)(replica.projectName, address);
672
655
  return [replica.projectName, undefined];
673
656
  }
674
657
  if (address) {
@@ -683,14 +666,14 @@ class RunTree {
683
666
  if (primary === undefined &&
684
667
  !this.replicas?.some((r) => r.primary === true) &&
685
668
  projectName === this.project_name &&
686
- (0, address_js_1.sameAddress)(address, this.address)) {
669
+ address?._toLrn() === this.address?._toLrn()) {
687
670
  return {
688
671
  ...baseRun,
689
672
  session_name: projectName,
690
673
  address,
691
674
  };
692
675
  }
693
- const seed = projectName ?? (address ? (0, address_js_1.seed)(address) : undefined) ?? "agent//";
676
+ const seed = projectName ?? address?._toLrn() ?? "agent//";
694
677
  // Apply reroot logic before ID remapping
695
678
  if (reroot) {
696
679
  if (distributedParentId) {
@@ -1211,7 +1194,7 @@ function _ensureWriteReplicas(replicas) {
1211
1194
  updates: replica[1],
1212
1195
  };
1213
1196
  }
1214
- const address = (0, agent_addressing_js_1.checkAddress)(replica.address);
1197
+ const address = (0, address_js_1.ensureAgent)(replica.address);
1215
1198
  return address ? { ...replica, address } : replica;
1216
1199
  })
1217
1200
  : _getWriteReplicasFromEnv();
@@ -1,6 +1,6 @@
1
1
  import { Client } from "./client.js";
2
2
  import { Attachments, BaseRun, KVMap, RunCreate } from "./schemas.js";
3
- import { type Address } from "./address.js";
3
+ import { AgentAddress } from "./address.js";
4
4
  export declare function convertToDottedOrderFormat(epoch: number, runId: string, executionOrder?: number): {
5
5
  dottedOrder: string;
6
6
  microsecondPrecisionDatestring: string;
@@ -11,7 +11,7 @@ export interface RunTreeConfig {
11
11
  id?: string;
12
12
  project_name?: string;
13
13
  /** (beta) Send the run to this address instead of a project. */
14
- address?: Address;
14
+ address?: AgentAddress;
15
15
  parent_run?: RunTree;
16
16
  parent_run_id?: string;
17
17
  child_runs?: RunTree[];
@@ -64,7 +64,7 @@ export type WriteReplica = {
64
64
  workspaceId?: string;
65
65
  projectName?: string;
66
66
  /** (beta) Send the replica to this address instead of a project. */
67
- address?: Address;
67
+ address?: AgentAddress;
68
68
  /** Whether this replica keeps the original run IDs. */
69
69
  primary?: boolean;
70
70
  updates?: KVMap | undefined;
@@ -87,7 +87,7 @@ export declare class RunTree implements BaseRun {
87
87
  /** Unset for a run sent to an `address`. */
88
88
  project_name?: string;
89
89
  /** (beta) Set instead of `project_name` for an addressed run. */
90
- address?: Address;
90
+ address?: AgentAddress;
91
91
  parent_run?: RunTree;
92
92
  parent_run_id?: string;
93
93
  child_runs: RunTree[];
package/dist/run_trees.js CHANGED
@@ -8,8 +8,8 @@ import { getLangSmithEnvironmentVariable } from "./utils/env.js";
8
8
  import { warnOnce } from "./utils/warn.js";
9
9
  import { uuid7FromTime, nonCryptographicUuid7Deterministic, } from "./utils/_uuid.js";
10
10
  import { v5 as uuidv5 } from "./utils/uuid/src/index.js";
11
- import { checkAddress, logUntraced, rejectConflicting, resolveFromEnv, } from "./utils/agent_addressing.js";
12
- import { EnvAddressError, fromWire, sameAddress, seed as addressSeed, toWire, wireKeys, } from "./address.js";
11
+ import { logUntraced, rejectConflicting, resolveFromEnv, } from "./utils/addressing.js";
12
+ import { AgentAddress, EnvAddressError, ensureAgent } from "./address.js";
13
13
  const TIMESTAMP_LENGTH = 36;
14
14
  // DNS namespace for UUID v5 (same as Python's uuid.NAMESPACE_DNS)
15
15
  const UUID_NAMESPACE_DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
@@ -44,29 +44,17 @@ const HEADER_SAFE_REPLICA_FIELDS = new Set([
44
44
  "primary",
45
45
  "updates",
46
46
  "reroot",
47
- ...wireKeys(),
47
+ "address",
48
48
  ]);
49
- // URL-encoded JSON of the address's wire fields.
50
- const LANGSMITH_ADDRESS = "langsmith-address";
51
- /** Pops the address wire keys off untrusted `values`; never throws. */
52
- function takeHeaderAddress(values) {
53
- const wire = {};
54
- for (const key of wireKeys()) {
55
- if (key in values) {
56
- wire[key] = values[key];
57
- delete values[key];
58
- }
59
- }
49
+ /** Rebuilds an untrusted header address; `undefined` if unusable. */
50
+ function addressFromHeader(value) {
60
51
  try {
61
- return {
62
- named: Object.keys(wire).length > 0,
63
- address: fromWire(wire),
64
- };
52
+ return AgentAddress._fromLrn(value);
65
53
  }
66
54
  catch {
67
55
  // Values are untrusted, so not logged.
68
- console.warn("Ignoring an invalid address in a `baggage` header.");
69
- return { named: true };
56
+ console.warn("Ignoring an unusable address in a `baggage` header.");
57
+ return undefined;
70
58
  }
71
59
  }
72
60
  function filterReplicaForHeaders(replica) {
@@ -141,17 +129,8 @@ class Baggage {
141
129
  else if (key === "langsmith-project") {
142
130
  project_name = value;
143
131
  }
144
- else if (key === LANGSMITH_ADDRESS) {
145
- let parsed;
146
- try {
147
- parsed = JSON.parse(value);
148
- }
149
- catch {
150
- parsed = undefined;
151
- }
152
- if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
153
- address = takeHeaderAddress({ ...parsed }).address;
154
- }
132
+ else if (key === "langsmith-address") {
133
+ address = addressFromHeader(value);
155
134
  }
156
135
  else if (key === "langsmith-replicas") {
157
136
  const parsed = JSON.parse(value);
@@ -160,13 +139,17 @@ class Baggage {
160
139
  return [replica];
161
140
  }
162
141
  const filtered = filterReplicaForHeaders(replica);
163
- const { named, address } = takeHeaderAddress(filtered);
142
+ const raw = filtered.address;
143
+ delete filtered.address;
164
144
  // A project wins over an address; a replica with an invalid
165
145
  // address and no project is dropped.
166
- if (filtered.projectName || !named) {
146
+ if (filtered.projectName || raw == null) {
167
147
  return [filtered];
168
148
  }
169
- return address ? [{ ...filtered, address }] : [];
149
+ const replicaAddress = addressFromHeader(raw);
150
+ return replicaAddress
151
+ ? [{ ...filtered, address: replicaAddress }]
152
+ : [];
170
153
  });
171
154
  }
172
155
  }
@@ -184,7 +167,7 @@ class Baggage {
184
167
  items.push(`langsmith-project=${encodeURIComponent(this.project_name)}`);
185
168
  }
186
169
  if (this.address) {
187
- items.push(`${LANGSMITH_ADDRESS}=${encodeURIComponent(JSON.stringify(toWire(this.address)))}`);
170
+ items.push(`langsmith-address=${encodeURIComponent(this.address._toLrn())}`);
188
171
  }
189
172
  return items.join(",");
190
173
  }
@@ -434,7 +417,7 @@ export class RunTree {
434
417
  }
435
418
  /** Falls back to the env; a bad env leaves the run untraced. */
436
419
  _resolveAddressing(config) {
437
- const address = checkAddress(config.address);
420
+ const address = ensureAgent(config.address);
438
421
  const project = config.project_name || undefined;
439
422
  rejectConflicting(project, address);
440
423
  if (project || address) {
@@ -660,7 +643,7 @@ export class RunTree {
660
643
  }
661
644
  /** A replica naming neither inherits the run tree's destination. */
662
645
  _replicaAddressing(replica) {
663
- const address = checkAddress(replica.address);
646
+ const address = ensureAgent(replica.address);
664
647
  if (replica.projectName != null) {
665
648
  rejectConflicting(replica.projectName, address);
666
649
  return [replica.projectName, undefined];
@@ -677,14 +660,14 @@ export class RunTree {
677
660
  if (primary === undefined &&
678
661
  !this.replicas?.some((r) => r.primary === true) &&
679
662
  projectName === this.project_name &&
680
- sameAddress(address, this.address)) {
663
+ address?._toLrn() === this.address?._toLrn()) {
681
664
  return {
682
665
  ...baseRun,
683
666
  session_name: projectName,
684
667
  address,
685
668
  };
686
669
  }
687
- const seed = projectName ?? (address ? addressSeed(address) : undefined) ?? "agent//";
670
+ const seed = projectName ?? address?._toLrn() ?? "agent//";
688
671
  // Apply reroot logic before ID remapping
689
672
  if (reroot) {
690
673
  if (distributedParentId) {
@@ -1204,7 +1187,7 @@ function _ensureWriteReplicas(replicas) {
1204
1187
  updates: replica[1],
1205
1188
  };
1206
1189
  }
1207
- const address = checkAddress(replica.address);
1190
+ const address = ensureAgent(replica.address);
1208
1191
  return address ? { ...replica, address } : replica;
1209
1192
  })
1210
1193
  : _getWriteReplicasFromEnv();
@@ -15,6 +15,7 @@ const errors_js_1 = require("./errors.cjs");
15
15
  const helpers_js_1 = require("./helpers.cjs");
16
16
  const mounts_js_1 = require("./mounts.cjs");
17
17
  const index_js_2 = require("../utils/uuid/src/index.cjs");
18
+ const tracing_js_1 = require("./tracing.cjs");
18
19
  /**
19
20
  * Sleep that can be interrupted by an AbortSignal.
20
21
  * Resolves after `ms` milliseconds or rejects immediately if the signal fires.
@@ -305,6 +306,12 @@ class SandboxClient {
305
306
  writable: true,
306
307
  value: void 0
307
308
  });
309
+ Object.defineProperty(this, "_sandboxIds", {
310
+ enumerable: true,
311
+ configurable: true,
312
+ writable: true,
313
+ value: new Map()
314
+ });
308
315
  this._baseUrl = (config.apiEndpoint ?? getDefaultApiEndpoint()).replace(/\/$/, "");
309
316
  this._apiKey = config.apiKey ?? getDefaultApiKey();
310
317
  this._defaultHeaders = { ...(config.headers ?? {}) };
@@ -398,6 +405,25 @@ class SandboxClient {
398
405
  getDefaultHeaders() {
399
406
  return { ...this._defaultHeaders };
400
407
  }
408
+ _traceSandbox(name) {
409
+ const id = this._sandboxIds.get(name) ?? ((0, index_js_2.validate)(name) ? name : undefined);
410
+ (0, tracing_js_1.addSandboxMetadata)(id);
411
+ return id;
412
+ }
413
+ _sandboxFromData(data) {
414
+ if (data.id)
415
+ this._sandboxIds.set(data.name, data.id);
416
+ (0, tracing_js_1.addSandboxMetadata)(data.id);
417
+ return new sandbox_js_1.Sandbox(data, this);
418
+ }
419
+ _forgetSandbox(name) {
420
+ const id = this._sandboxIds.get(name) ?? name;
421
+ for (const [cachedName, cachedId] of this._sandboxIds) {
422
+ if (cachedName === name || cachedId === id) {
423
+ this._sandboxIds.delete(cachedName);
424
+ }
425
+ }
426
+ }
401
427
  /**
402
428
  * JSON POST helper. Sends JSON body, checks response status,
403
429
  * and returns the Response for further processing.
@@ -406,6 +432,7 @@ class SandboxClient {
406
432
  * @internal
407
433
  */
408
434
  _boxUrl(name, ...segments) {
435
+ this._traceSandbox(name);
409
436
  const suffix = segments.length ? `/${segments.join("/")}` : "";
410
437
  return `${this._baseUrl}/boxes/${encodeURIComponent(name)}${suffix}`;
411
438
  }
@@ -454,7 +481,7 @@ class SandboxClient {
454
481
  return new service_url_js_1.ServiceUrl(data, () => this.serviceUrl(name, {
455
482
  port,
456
483
  expiresInSeconds,
457
- }));
484
+ }), this._traceSandbox(name));
458
485
  }
459
486
  async _postJson(url, body, options) {
460
487
  const response = await this._fetch(url, {
@@ -534,7 +561,7 @@ class SandboxClient {
534
561
  await (0, helpers_js_1.handleSandboxCreationError)(response);
535
562
  }
536
563
  const data = (await response.json());
537
- return new sandbox_js_1.Sandbox(data, this);
564
+ return this._sandboxFromData(data);
538
565
  }
539
566
  /**
540
567
  * Get a Sandbox by name.
@@ -555,7 +582,7 @@ class SandboxClient {
555
582
  await (0, helpers_js_1.handleClientHttpError)(response);
556
583
  }
557
584
  const data = (await response.json());
558
- return new sandbox_js_1.Sandbox(data, this);
585
+ return this._sandboxFromData(data);
559
586
  }
560
587
  /**
561
588
  * List all Sandboxes.
@@ -625,7 +652,8 @@ class SandboxClient {
625
652
  await (0, helpers_js_1.handleClientHttpError)(response);
626
653
  }
627
654
  const data = (await response.json());
628
- return new sandbox_js_1.Sandbox(data, this);
655
+ this._forgetSandbox(name);
656
+ return this._sandboxFromData(data);
629
657
  }
630
658
  /**
631
659
  * Delete a Sandbox.
@@ -642,6 +670,7 @@ class SandboxClient {
642
670
  }
643
671
  await (0, helpers_js_1.handleClientHttpError)(response);
644
672
  }
673
+ this._forgetSandbox(name);
645
674
  }
646
675
  /**
647
676
  * Get the provisioning status of a sandbox.
@@ -40,6 +40,7 @@ export declare class SandboxClient {
40
40
  private _fetchImpl;
41
41
  private _caller;
42
42
  private _registriesClient?;
43
+ private _sandboxIds;
43
44
  constructor(config?: SandboxClientConfig);
44
45
  private _apiRoot;
45
46
  /**
@@ -65,6 +66,9 @@ export declare class SandboxClient {
65
66
  * ```
66
67
  */
67
68
  get registries(): Registries;
69
+ private _traceSandbox;
70
+ private _sandboxFromData;
71
+ private _forgetSandbox;
68
72
  /**
69
73
  * Generate an authenticated URL for an HTTP service running in a sandbox.
70
74
  *