langsmith 0.10.5 → 0.10.7

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.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AI_SDK_TOOL_OPERATIONS = exports.AI_SDK_LLM_OPERATIONS = exports.GEN_AI_CHOICE = exports.GEN_AI_ASSISTANT_MESSAGE = exports.GEN_AI_USER_MESSAGE = exports.GEN_AI_SYSTEM_MESSAGE = exports.LANGSMITH_TRACEABLE_PARENT_OTEL_SPAN_ID = exports.LANGSMITH_IS_ROOT = exports.LANGSMITH_TRACEABLE = exports.LANGSMITH_REFERENCE_EXAMPLE_ID = exports.LANGSMITH_USAGE_METADATA = exports.LANGSMITH_PARENT_RUN_ID = exports.LANGSMITH_DOTTED_ORDER = exports.LANGSMITH_TRACE_ID = exports.LANGSMITH_RUN_ID = exports.LANGSMITH_REQUEST_HEADERS = exports.LANGSMITH_REQUEST_STREAMING = exports.LANGSMITH_RUNTIME = exports.LANGSMITH_TAGS = exports.LANGSMITH_METADATA = exports.LANGSMITH_NAME = exports.LANGSMITH_RUN_TYPE = exports.LANGSMITH_SESSION_NAME = exports.LANGSMITH_SESSION_ID = exports.GEN_AI_USAGE_OUTPUT_TOKEN_DETAILS = exports.GEN_AI_USAGE_INPUT_TOKEN_DETAILS = exports.GEN_AI_RESPONSE_SYSTEM_FINGERPRINT = exports.GEN_AI_RESPONSE_SERVICE_TIER = exports.GEN_AI_RESPONSE_ID = exports.GEN_AI_SERIALIZED_DOC = exports.GEN_AI_SERIALIZED_SIGNATURE = exports.GEN_AI_SERIALIZED_NAME = exports.GEN_AI_REQUEST_EXTRA_BODY = exports.GEN_AI_REQUEST_EXTRA_QUERY = exports.GENAI_COMPLETION = exports.GENAI_PROMPT = exports.GEN_AI_RESPONSE_FINISH_REASONS = exports.GEN_AI_REQUEST_PRESENCE_PENALTY = exports.GEN_AI_REQUEST_FREQUENCY_PENALTY = exports.GEN_AI_REQUEST_TOP_P = exports.GEN_AI_REQUEST_TEMPERATURE = exports.GEN_AI_REQUEST_MAX_TOKENS = exports.GEN_AI_USAGE_TOTAL_TOKENS = exports.GEN_AI_USAGE_OUTPUT_TOKENS = exports.GEN_AI_USAGE_INPUT_TOKENS = exports.GEN_AI_RESPONSE_MODEL = exports.GEN_AI_REQUEST_MODEL = exports.GEN_AI_SYSTEM = exports.GEN_AI_OPERATION_NAME = void 0;
3
+ exports.GEN_AI_CHOICE = exports.GEN_AI_ASSISTANT_MESSAGE = exports.GEN_AI_USER_MESSAGE = exports.GEN_AI_SYSTEM_MESSAGE = exports.LANGSMITH_TRACEABLE_PARENT_OTEL_SPAN_ID = exports.LANGSMITH_IS_ROOT = exports.LANGSMITH_TRACEABLE = exports.LANGSMITH_REFERENCE_EXAMPLE_ID = exports.LANGSMITH_USAGE_METADATA = exports.LANGSMITH_PARENT_RUN_ID = exports.LANGSMITH_DOTTED_ORDER = exports.LANGSMITH_TRACE_ID = exports.LANGSMITH_RUN_ID = exports.LANGSMITH_REQUEST_HEADERS = exports.LANGSMITH_REQUEST_STREAMING = exports.LANGSMITH_RUNTIME = exports.LANGSMITH_TAGS = exports.LANGSMITH_METADATA = exports.LANGSMITH_NAME = exports.LANGSMITH_RUN_TYPE = exports.LANGSMITH_SESSION_NAME = exports.LANGSMITH_SESSION_ID = exports.GEN_AI_USAGE_OUTPUT_TOKEN_DETAILS = exports.GEN_AI_USAGE_INPUT_TOKEN_DETAILS = exports.GEN_AI_RESPONSE_SYSTEM_FINGERPRINT = exports.GEN_AI_RESPONSE_SERVICE_TIER = exports.GEN_AI_TOOL_DEFINITIONS = exports.GEN_AI_TOOL_CALL_ID = exports.GEN_AI_TOOL_NAME = exports.GEN_AI_RESPONSE_ID = exports.GEN_AI_SERIALIZED_DOC = exports.GEN_AI_SERIALIZED_SIGNATURE = exports.GEN_AI_SERIALIZED_NAME = exports.GEN_AI_REQUEST_EXTRA_BODY = exports.GEN_AI_REQUEST_EXTRA_QUERY = exports.GENAI_COMPLETION = exports.GENAI_PROMPT = exports.GEN_AI_RESPONSE_FINISH_REASONS = exports.GEN_AI_REQUEST_PRESENCE_PENALTY = exports.GEN_AI_REQUEST_FREQUENCY_PENALTY = exports.GEN_AI_REQUEST_TOP_P = exports.GEN_AI_REQUEST_TEMPERATURE = exports.GEN_AI_REQUEST_MAX_TOKENS = exports.GEN_AI_USAGE_TOTAL_TOKENS = exports.GEN_AI_USAGE_OUTPUT_TOKENS = exports.GEN_AI_USAGE_INPUT_TOKENS = exports.GEN_AI_RESPONSE_MODEL = exports.GEN_AI_REQUEST_MODEL = exports.GEN_AI_SYSTEM = exports.GEN_AI_OPERATION_NAME = void 0;
4
+ exports.AI_SDK_TOOL_OPERATIONS = exports.AI_SDK_LLM_OPERATIONS = void 0;
4
5
  // OpenTelemetry GenAI semantic convention attribute names
5
6
  exports.GEN_AI_OPERATION_NAME = "gen_ai.operation.name";
6
7
  exports.GEN_AI_SYSTEM = "gen_ai.system";
@@ -23,6 +24,9 @@ exports.GEN_AI_SERIALIZED_NAME = "gen_ai.serialized.name";
23
24
  exports.GEN_AI_SERIALIZED_SIGNATURE = "gen_ai.serialized.signature";
24
25
  exports.GEN_AI_SERIALIZED_DOC = "gen_ai.serialized.doc";
25
26
  exports.GEN_AI_RESPONSE_ID = "gen_ai.response.id";
27
+ exports.GEN_AI_TOOL_NAME = "gen_ai.tool.name";
28
+ exports.GEN_AI_TOOL_CALL_ID = "gen_ai.tool.call.id";
29
+ exports.GEN_AI_TOOL_DEFINITIONS = "gen_ai.tool.definitions";
26
30
  exports.GEN_AI_RESPONSE_SERVICE_TIER = "gen_ai.response.service_tier";
27
31
  exports.GEN_AI_RESPONSE_SYSTEM_FINGERPRINT = "gen_ai.response.system_fingerprint";
28
32
  exports.GEN_AI_USAGE_INPUT_TOKEN_DETAILS = "gen_ai.usage.input_token_details";
@@ -19,6 +19,9 @@ export declare const GEN_AI_SERIALIZED_NAME = "gen_ai.serialized.name";
19
19
  export declare const GEN_AI_SERIALIZED_SIGNATURE = "gen_ai.serialized.signature";
20
20
  export declare const GEN_AI_SERIALIZED_DOC = "gen_ai.serialized.doc";
21
21
  export declare const GEN_AI_RESPONSE_ID = "gen_ai.response.id";
22
+ export declare const GEN_AI_TOOL_NAME = "gen_ai.tool.name";
23
+ export declare const GEN_AI_TOOL_CALL_ID = "gen_ai.tool.call.id";
24
+ export declare const GEN_AI_TOOL_DEFINITIONS = "gen_ai.tool.definitions";
22
25
  export declare const GEN_AI_RESPONSE_SERVICE_TIER = "gen_ai.response.service_tier";
23
26
  export declare const GEN_AI_RESPONSE_SYSTEM_FINGERPRINT = "gen_ai.response.system_fingerprint";
24
27
  export declare const GEN_AI_USAGE_INPUT_TOKEN_DETAILS = "gen_ai.usage.input_token_details";
@@ -20,6 +20,9 @@ export const GEN_AI_SERIALIZED_NAME = "gen_ai.serialized.name";
20
20
  export const GEN_AI_SERIALIZED_SIGNATURE = "gen_ai.serialized.signature";
21
21
  export const GEN_AI_SERIALIZED_DOC = "gen_ai.serialized.doc";
22
22
  export const GEN_AI_RESPONSE_ID = "gen_ai.response.id";
23
+ export const GEN_AI_TOOL_NAME = "gen_ai.tool.name";
24
+ export const GEN_AI_TOOL_CALL_ID = "gen_ai.tool.call.id";
25
+ export const GEN_AI_TOOL_DEFINITIONS = "gen_ai.tool.definitions";
23
26
  export const GEN_AI_RESPONSE_SERVICE_TIER = "gen_ai.response.service_tier";
24
27
  export const GEN_AI_RESPONSE_SYSTEM_FINGERPRINT = "gen_ai.response.system_fingerprint";
25
28
  export const GEN_AI_USAGE_INPUT_TOKEN_DETAILS = "gen_ai.usage.input_token_details";
@@ -203,6 +203,16 @@ class LangSmithToOTELTranslator {
203
203
  }
204
204
  // Set other parameters from invocation_params
205
205
  this.setInvocationParameters(span, runInfo);
206
+ if ("run_type" in runInfo && runInfo.run_type === "tool") {
207
+ if ("name" in runInfo && runInfo.name) {
208
+ span.setAttribute(constants.GEN_AI_TOOL_NAME, runInfo.name);
209
+ }
210
+ // Match Python: prefer extra.tool_call_id over metadata.tool_call_id.
211
+ const toolCallId = runInfo.extra?.tool_call_id || runInfo.extra?.metadata?.tool_call_id;
212
+ if (toolCallId != null) {
213
+ span.setAttribute(constants.GEN_AI_TOOL_CALL_ID, String(toolCallId));
214
+ }
215
+ }
206
216
  // Set metadata and tags if available
207
217
  const metadata = runInfo.extra?.metadata || {};
208
218
  for (const [key, value] of Object.entries(metadata)) {
@@ -289,6 +299,10 @@ class LangSmithToOTELTranslator {
289
299
  span.setAttribute(constants.GEN_AI_SYSTEM, system);
290
300
  }
291
301
  setInvocationParameters(span, runInfo) {
302
+ const tools = runInfo.extra?.invocation_params?.tools;
303
+ if (Array.isArray(tools) && tools.length > 0) {
304
+ span.setAttribute(constants.GEN_AI_TOOL_DEFINITIONS, JSON.stringify(tools));
305
+ }
292
306
  if (!runInfo.extra?.metadata?.invocation_params) {
293
307
  return;
294
308
  }
@@ -167,6 +167,16 @@ export class LangSmithToOTELTranslator {
167
167
  }
168
168
  // Set other parameters from invocation_params
169
169
  this.setInvocationParameters(span, runInfo);
170
+ if ("run_type" in runInfo && runInfo.run_type === "tool") {
171
+ if ("name" in runInfo && runInfo.name) {
172
+ span.setAttribute(constants.GEN_AI_TOOL_NAME, runInfo.name);
173
+ }
174
+ // Match Python: prefer extra.tool_call_id over metadata.tool_call_id.
175
+ const toolCallId = runInfo.extra?.tool_call_id || runInfo.extra?.metadata?.tool_call_id;
176
+ if (toolCallId != null) {
177
+ span.setAttribute(constants.GEN_AI_TOOL_CALL_ID, String(toolCallId));
178
+ }
179
+ }
170
180
  // Set metadata and tags if available
171
181
  const metadata = runInfo.extra?.metadata || {};
172
182
  for (const [key, value] of Object.entries(metadata)) {
@@ -253,6 +263,10 @@ export class LangSmithToOTELTranslator {
253
263
  span.setAttribute(constants.GEN_AI_SYSTEM, system);
254
264
  }
255
265
  setInvocationParameters(span, runInfo) {
266
+ const tools = runInfo.extra?.invocation_params?.tools;
267
+ if (Array.isArray(tools) && tools.length > 0) {
268
+ span.setAttribute(constants.GEN_AI_TOOL_DEFINITIONS, JSON.stringify(tools));
269
+ }
256
270
  if (!runInfo.extra?.metadata?.invocation_params) {
257
271
  return;
258
272
  }
package/dist/index.cjs CHANGED
@@ -1,10 +1,12 @@
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.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.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
+ var address_js_1 = require("./address.cjs");
9
+ Object.defineProperty(exports, "EnvAddressError", { enumerable: true, get: function () { return address_js_1.EnvAddressError; } });
8
10
  var fetch_js_1 = require("./singletons/fetch.cjs");
9
11
  Object.defineProperty(exports, "overrideFetchImplementation", { enumerable: true, get: function () { return fetch_js_1.overrideFetchImplementation; } });
10
12
  var project_js_1 = require("./utils/project.cjs");
@@ -35,6 +37,6 @@ Object.defineProperty(exports, "UnprocessableEntityError", { enumerable: true, g
35
37
  Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return error_js_1.RateLimitError; } });
36
38
  Object.defineProperty(exports, "InternalServerError", { enumerable: true, get: function () { return error_js_1.InternalServerError; } });
37
39
  // Update using pnpm bump-version
38
- exports.__version__ = "0.10.5";
40
+ exports.__version__ = "0.10.7";
39
41
  // Metadata key to hide a traced run from LangSmith's Messages View.
40
42
  exports.LS_MESSAGE_VIEW_EXCLUDE = "ls_message_view_exclude";
package/dist/index.d.ts CHANGED
@@ -1,11 +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
5
  export { overrideFetchImplementation } from "./singletons/fetch.js";
5
6
  export { getDefaultProjectName } from "./utils/project.js";
6
7
  export { computeRunIdForSecondaryReplica, uuid7, uuid7FromTime, } from "./uuid.js";
7
8
  export { isTracingEnabled } from "./utils/guard.js";
8
9
  export { Cache, PromptCache, type CacheConfig, type CacheMetrics, configureGlobalPromptCache, promptCacheSingleton, } from "./utils/prompt_cache/index.js";
9
10
  export { LangsmithError, APIError, APIUserAbortError, APIConnectionError, APIConnectionTimeoutError, BadRequestError, AuthenticationError, PermissionDeniedError, NotFoundError, ConflictError, UnprocessableEntityError, RateLimitError, InternalServerError, } from "./_openapi_client/core/error.js";
10
- export declare const __version__ = "0.10.5";
11
+ export declare const __version__ = "0.10.7";
11
12
  export declare const LS_MESSAGE_VIEW_EXCLUDE: "ls_message_view_exclude";
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export { Client, } from "./client.js";
2
2
  export { RunTree } from "./run_trees.js";
3
+ export { EnvAddressError } from "./address.js";
3
4
  export { overrideFetchImplementation } from "./singletons/fetch.js";
4
5
  export { getDefaultProjectName } from "./utils/project.js";
5
6
  export { computeRunIdForSecondaryReplica, uuid7, uuid7FromTime, } from "./uuid.js";
@@ -7,6 +8,6 @@ export { isTracingEnabled } from "./utils/guard.js";
7
8
  export { Cache, PromptCache, configureGlobalPromptCache, promptCacheSingleton, } from "./utils/prompt_cache/index.js";
8
9
  export { LangsmithError, APIError, APIUserAbortError, APIConnectionError, APIConnectionTimeoutError, BadRequestError, AuthenticationError, PermissionDeniedError, NotFoundError, ConflictError, UnprocessableEntityError, RateLimitError, InternalServerError, } from "./_openapi_client/core/error.js";
9
10
  // Update using pnpm bump-version
10
- export const __version__ = "0.10.5";
11
+ export const __version__ = "0.10.7";
11
12
  // Metadata key to hide a traced run from LangSmith's Messages View.
12
13
  export const LS_MESSAGE_VIEW_EXCLUDE = "ls_message_view_exclude";
@@ -10,11 +10,12 @@ const error_js_1 = require("./utils/error.cjs");
10
10
  const constants_js_1 = require("./singletons/constants.cjs");
11
11
  const context_vars_js_1 = require("./utils/context_vars.cjs");
12
12
  const env_js_2 = require("./utils/env.cjs");
13
- const project_js_1 = require("./utils/project.cjs");
14
13
  const env_js_3 = require("./utils/env.cjs");
15
14
  const warn_js_1 = require("./utils/warn.cjs");
16
15
  const _uuid_js_1 = require("./utils/_uuid.cjs");
17
16
  const index_js_1 = require("./utils/uuid/src/index.cjs");
17
+ const agent_addressing_js_1 = require("./utils/agent_addressing.cjs");
18
+ const address_js_1 = require("./address.cjs");
18
19
  const TIMESTAMP_LENGTH = 36;
19
20
  // DNS namespace for UUID v5 (same as Python's uuid.NAMESPACE_DNS)
20
21
  const UUID_NAMESPACE_DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
@@ -49,7 +50,31 @@ const HEADER_SAFE_REPLICA_FIELDS = new Set([
49
50
  "primary",
50
51
  "updates",
51
52
  "reroot",
53
+ ...(0, address_js_1.wireKeys)(),
52
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
+ }
66
+ try {
67
+ return {
68
+ named: Object.keys(wire).length > 0,
69
+ address: (0, address_js_1.fromWire)(wire),
70
+ };
71
+ }
72
+ catch {
73
+ // Values are untrusted, so not logged.
74
+ console.warn("Ignoring an invalid address in a `baggage` header.");
75
+ return { named: true };
76
+ }
77
+ }
53
78
  function filterReplicaForHeaders(replica) {
54
79
  const filtered = {};
55
80
  for (const key of Object.keys(replica)) {
@@ -66,7 +91,7 @@ function filterReplicaForHeaders(replica) {
66
91
  * Baggage header information
67
92
  */
68
93
  class Baggage {
69
- constructor(metadata, tags, project_name, replicas) {
94
+ constructor(metadata, tags, project_name, replicas, address) {
70
95
  Object.defineProperty(this, "metadata", {
71
96
  enumerable: true,
72
97
  configurable: true,
@@ -91,10 +116,17 @@ class Baggage {
91
116
  writable: true,
92
117
  value: void 0
93
118
  });
119
+ Object.defineProperty(this, "address", {
120
+ enumerable: true,
121
+ configurable: true,
122
+ writable: true,
123
+ value: void 0
124
+ });
94
125
  this.metadata = metadata;
95
126
  this.tags = tags;
96
127
  this.project_name = project_name;
97
128
  this.replicas = replicas;
129
+ this.address = address;
98
130
  }
99
131
  static fromHeader(value) {
100
132
  const items = value.split(",");
@@ -102,6 +134,7 @@ class Baggage {
102
134
  let tags = [];
103
135
  let project_name;
104
136
  let replicas;
137
+ let address;
105
138
  for (const item of items) {
106
139
  const [key, uriValue] = item.split("=");
107
140
  const value = decodeURIComponent(uriValue);
@@ -114,17 +147,36 @@ class Baggage {
114
147
  else if (key === "langsmith-project") {
115
148
  project_name = value;
116
149
  }
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
+ }
161
+ }
117
162
  else if (key === "langsmith-replicas") {
118
163
  const parsed = JSON.parse(value);
119
- replicas = parsed.map((replica) => {
164
+ replicas = parsed.flatMap((replica) => {
120
165
  if (Array.isArray(replica)) {
121
- return replica;
166
+ return [replica];
122
167
  }
123
- return filterReplicaForHeaders(replica);
168
+ const filtered = filterReplicaForHeaders(replica);
169
+ const { named, address } = takeHeaderAddress(filtered);
170
+ // A project wins over an address; a replica with an invalid
171
+ // address and no project is dropped.
172
+ if (filtered.projectName || !named) {
173
+ return [filtered];
174
+ }
175
+ return address ? [{ ...filtered, address }] : [];
124
176
  });
125
177
  }
126
178
  }
127
- return new Baggage(metadata, tags, project_name, replicas);
179
+ return new Baggage(metadata, tags, project_name, replicas, address);
128
180
  }
129
181
  toHeader() {
130
182
  const items = [];
@@ -137,6 +189,9 @@ class Baggage {
137
189
  if (this.project_name) {
138
190
  items.push(`langsmith-project=${encodeURIComponent(this.project_name)}`);
139
191
  }
192
+ if (this.address) {
193
+ items.push(`${LANGSMITH_ADDRESS}=${encodeURIComponent(JSON.stringify((0, address_js_1.toWire)(this.address)))}`);
194
+ }
140
195
  return items.join(",");
141
196
  }
142
197
  }
@@ -164,12 +219,20 @@ class RunTree {
164
219
  writable: true,
165
220
  value: void 0
166
221
  });
222
+ /** Unset for a run sent to an `address`. */
167
223
  Object.defineProperty(this, "project_name", {
168
224
  enumerable: true,
169
225
  configurable: true,
170
226
  writable: true,
171
227
  value: void 0
172
228
  });
229
+ /** (beta) Set instead of `project_name` for an addressed run. */
230
+ Object.defineProperty(this, "address", {
231
+ enumerable: true,
232
+ configurable: true,
233
+ writable: true,
234
+ value: void 0
235
+ });
173
236
  Object.defineProperty(this, "parent_run", {
174
237
  enumerable: true,
175
238
  configurable: true,
@@ -344,6 +407,7 @@ class RunTree {
344
407
  delete config.id;
345
408
  }
346
409
  Object.assign(this, { ...defaultConfig, ...config, client });
410
+ this._resolveAddressing(config);
347
411
  this.execution_order ??= 1;
348
412
  this.child_execution_order ??= 1;
349
413
  // Generate serialized start time for ID generation
@@ -374,6 +438,31 @@ class RunTree {
374
438
  }
375
439
  }
376
440
  }
441
+ /** Falls back to the env; a bad env leaves the run untraced. */
442
+ _resolveAddressing(config) {
443
+ const address = (0, agent_addressing_js_1.checkAddress)(config.address);
444
+ const project = config.project_name || undefined;
445
+ (0, agent_addressing_js_1.rejectConflicting)(project, address);
446
+ if (project || address) {
447
+ this.project_name = project;
448
+ this.address = address;
449
+ return;
450
+ }
451
+ try {
452
+ [this.project_name, this.address] = (0, agent_addressing_js_1.resolveFromEnv)();
453
+ }
454
+ catch (e) {
455
+ if (!(e instanceof address_js_1.EnvAddressError)) {
456
+ throw e;
457
+ }
458
+ if ((0, env_js_1.isEnvTracingEnabled)(this.tracingEnabled)) {
459
+ (0, agent_addressing_js_1.logUntraced)(e);
460
+ }
461
+ this.project_name = undefined;
462
+ this.address = undefined;
463
+ this.tracingEnabled = false;
464
+ }
465
+ }
377
466
  set metadata(metadata) {
378
467
  this.extra = {
379
468
  ...this.extra,
@@ -390,7 +479,6 @@ class RunTree {
390
479
  const start_time = Date.now();
391
480
  return {
392
481
  run_type: "chain",
393
- project_name: (0, project_js_1.getDefaultProjectName)(),
394
482
  child_runs: [],
395
483
  api_url: (0, env_js_2.getEnvironmentVariable)("LANGCHAIN_ENDPOINT") ?? "http://localhost:1984",
396
484
  api_key: (0, env_js_2.getEnvironmentVariable)("LANGCHAIN_API_KEY"),
@@ -420,6 +508,7 @@ class RunTree {
420
508
  ...config,
421
509
  parent_run: this,
422
510
  project_name: this.project_name,
511
+ address: this.address,
423
512
  replicas: childReplicas,
424
513
  client: this.client,
425
514
  tracingEnabled: this.tracingEnabled,
@@ -518,6 +607,7 @@ class RunTree {
518
607
  inputs: run.inputs,
519
608
  outputs: run.outputs,
520
609
  session_name: run.project_name,
610
+ address: run.address,
521
611
  child_runs: child_runs,
522
612
  parent_run_id: parent_run_id,
523
613
  trace_id: run.trace_id,
@@ -574,16 +664,33 @@ class RunTree {
574
664
  child._setReplicaTraceRoot(replicaKey, traceRootId);
575
665
  }
576
666
  }
667
+ /** A replica naming neither inherits the run tree's destination. */
668
+ _replicaAddressing(replica) {
669
+ const address = (0, agent_addressing_js_1.checkAddress)(replica.address);
670
+ if (replica.projectName != null) {
671
+ (0, agent_addressing_js_1.rejectConflicting)(replica.projectName, address);
672
+ return [replica.projectName, undefined];
673
+ }
674
+ if (address) {
675
+ return [undefined, address];
676
+ }
677
+ return [this.project_name, this.address];
678
+ }
577
679
  _remapForProject(params) {
578
- const { projectName, primary, runtimeEnv, excludeChildRuns = true, reroot = false, distributedParentId, apiUrl, apiKey, workspaceId, } = params;
680
+ const { projectName, address, primary, runtimeEnv, excludeChildRuns = true, reroot = false, distributedParentId, apiUrl, apiKey, workspaceId, } = params;
579
681
  const baseRun = this._convertToCreate(this, runtimeEnv, excludeChildRuns);
580
- // Preserve legacy behavior when `primary` is omitted.
581
- if (primary === undefined && projectName === this.project_name) {
682
+ // Preserve legacy behavior when `primary` is omitted, unless another replica is primary.
683
+ if (primary === undefined &&
684
+ !this.replicas?.some((r) => r.primary === true) &&
685
+ projectName === this.project_name &&
686
+ (0, address_js_1.sameAddress)(address, this.address)) {
582
687
  return {
583
688
  ...baseRun,
584
689
  session_name: projectName,
690
+ address,
585
691
  };
586
692
  }
693
+ const seed = projectName ?? (address ? (0, address_js_1.seed)(address) : undefined) ?? "agent//";
587
694
  // Apply reroot logic before ID remapping
588
695
  if (reroot) {
589
696
  if (distributedParentId) {
@@ -607,7 +714,7 @@ class RunTree {
607
714
  // Store this run's original ID in context vars so descendants know the new trace root
608
715
  // We store the original ID (before remapping) so it can be found in dotted_order
609
716
  const replicaKey = getReplicaKey({
610
- projectName,
717
+ projectName: seed,
611
718
  apiUrl,
612
719
  apiKey,
613
720
  workspaceId,
@@ -620,7 +727,7 @@ class RunTree {
620
727
  if (!reroot) {
621
728
  const replicaTraceRoots = (0, context_vars_js_1.getContextVar)(this, constants_js_1._REPLICA_TRACE_ROOTS_KEY) ?? {};
622
729
  const replicaKey = getReplicaKey({
623
- projectName,
730
+ projectName: seed,
624
731
  apiUrl,
625
732
  apiKey,
626
733
  workspaceId,
@@ -655,17 +762,18 @@ class RunTree {
655
762
  return {
656
763
  ...baseRun,
657
764
  session_name: projectName,
765
+ address,
658
766
  };
659
767
  }
660
768
  // Remap IDs for the replica using nonCryptographicUuid7Deterministic
661
769
  // This ensures consistency across runs in the same replica while
662
770
  // preserving UUID7 properties (time-ordering, monotonicity)
663
771
  const oldId = baseRun.id;
664
- const newId = (0, _uuid_js_1.nonCryptographicUuid7Deterministic)(oldId, projectName);
772
+ const newId = (0, _uuid_js_1.nonCryptographicUuid7Deterministic)(oldId, seed);
665
773
  // Remap trace_id
666
774
  let newTraceId;
667
775
  if (baseRun.trace_id) {
668
- newTraceId = (0, _uuid_js_1.nonCryptographicUuid7Deterministic)(baseRun.trace_id, projectName);
776
+ newTraceId = (0, _uuid_js_1.nonCryptographicUuid7Deterministic)(baseRun.trace_id, seed);
669
777
  }
670
778
  else {
671
779
  newTraceId = newId;
@@ -673,7 +781,7 @@ class RunTree {
673
781
  // Remap parent_run_id
674
782
  let newParentId;
675
783
  if (baseRun.parent_run_id) {
676
- newParentId = (0, _uuid_js_1.nonCryptographicUuid7Deterministic)(baseRun.parent_run_id, projectName);
784
+ newParentId = (0, _uuid_js_1.nonCryptographicUuid7Deterministic)(baseRun.parent_run_id, seed);
677
785
  }
678
786
  // Remap dotted_order segments
679
787
  let newDottedOrder;
@@ -682,7 +790,7 @@ class RunTree {
682
790
  const remappedSegs = segs.map((seg) => {
683
791
  // Extract the UUID from the segment (last TIMESTAMP_LENGTH characters)
684
792
  const segId = seg.slice(-TIMESTAMP_LENGTH);
685
- const remappedId = (0, _uuid_js_1.nonCryptographicUuid7Deterministic)(segId, projectName);
793
+ const remappedId = (0, _uuid_js_1.nonCryptographicUuid7Deterministic)(segId, seed);
686
794
  // Replace the UUID part while keeping the timestamp prefix
687
795
  return seg.slice(0, -TIMESTAMP_LENGTH) + remappedId;
688
796
  });
@@ -695,6 +803,7 @@ class RunTree {
695
803
  parent_run_id: newParentId,
696
804
  dotted_order: newDottedOrder,
697
805
  session_name: projectName,
806
+ address,
698
807
  };
699
808
  }
700
809
  async postRun(excludeChildRuns = true) {
@@ -705,9 +814,12 @@ class RunTree {
705
814
  try {
706
815
  const runtimeEnv = (0, env_js_2.getRuntimeEnvironment)();
707
816
  if (this.replicas && this.replicas.length > 0) {
708
- for (const { projectName, primary, apiKey, apiUrl, workspaceId, reroot, client: replicaClient, } of this.replicas) {
817
+ for (const replica of this.replicas) {
818
+ const { primary, apiKey, apiUrl, workspaceId, reroot, client: replicaClient, } = replica;
819
+ const [projectName, address] = this._replicaAddressing(replica);
709
820
  const runCreate = this._remapForProject({
710
- projectName: projectName ?? this.project_name,
821
+ projectName,
822
+ address,
711
823
  primary,
712
824
  runtimeEnv,
713
825
  excludeChildRuns: true,
@@ -756,9 +868,12 @@ class RunTree {
756
868
  async patchRun(options) {
757
869
  const excludeInputs = options?.excludeInputs ?? getExcludeInputsOnPatch();
758
870
  if (this.replicas && this.replicas.length > 0) {
759
- for (const { projectName, primary, apiKey, apiUrl, workspaceId, updates, reroot, client: replicaClient, } of this.replicas) {
871
+ for (const replica of this.replicas) {
872
+ const { primary, apiKey, apiUrl, workspaceId, updates, reroot, client: replicaClient, } = replica;
873
+ const [projectName, address] = this._replicaAddressing(replica);
760
874
  const runData = this._remapForProject({
761
- projectName: projectName ?? this.project_name,
875
+ projectName,
876
+ address,
762
877
  primary,
763
878
  runtimeEnv: undefined,
764
879
  excludeChildRuns: true,
@@ -777,6 +892,7 @@ class RunTree {
777
892
  error: runData.error,
778
893
  parent_run_id: runData.parent_run_id,
779
894
  session_name: runData.session_name,
895
+ address: runData.address,
780
896
  reference_example_id: runData.reference_example_id,
781
897
  end_time: runData.end_time,
782
898
  dotted_order: runData.dotted_order,
@@ -819,6 +935,7 @@ class RunTree {
819
935
  tags: this.tags,
820
936
  attachments: this.attachments,
821
937
  session_name: this.project_name,
938
+ address: this.address,
822
939
  };
823
940
  // Important that inputs is not a key in the run update
824
941
  // if excluded because it will overwrite the run create if the
@@ -879,7 +996,7 @@ class RunTree {
879
996
  ...props,
880
997
  client,
881
998
  tracingEnabled,
882
- project_name: projectName,
999
+ project_name: props.address ? undefined : projectName,
883
1000
  });
884
1001
  }
885
1002
  const parentRunTree = new RunTree({
@@ -934,7 +1051,19 @@ class RunTree {
934
1051
  const baggage = Baggage.fromHeader(rawHeaders["baggage"]);
935
1052
  config.metadata = baggage.metadata;
936
1053
  config.tags = baggage.tags;
937
- config.project_name = baggage.project_name;
1054
+ if (baggage.project_name && baggage.address) {
1055
+ console.warn("Ignoring a `baggage` header that names both a project and an address.");
1056
+ return undefined;
1057
+ }
1058
+ // The header's destination outranks the caller's.
1059
+ if (baggage.project_name) {
1060
+ config.project_name = baggage.project_name;
1061
+ delete config.address;
1062
+ }
1063
+ else if (baggage.address) {
1064
+ config.address = baggage.address;
1065
+ delete config.project_name;
1066
+ }
938
1067
  config.replicas = baggage.replicas;
939
1068
  }
940
1069
  const runTree = new RunTree(config);
@@ -945,7 +1074,7 @@ class RunTree {
945
1074
  toHeaders(headers) {
946
1075
  const result = {
947
1076
  "langsmith-trace": this.dotted_order,
948
- baggage: new Baggage(this.extra?.metadata, this.tags, this.project_name, this.replicas).toHeader(),
1077
+ baggage: new Baggage(this.extra?.metadata, this.tags, this.project_name, this.replicas, this.address).toHeader(),
949
1078
  };
950
1079
  if (headers) {
951
1080
  for (const [key, value] of Object.entries(result)) {
@@ -1082,7 +1211,8 @@ function _ensureWriteReplicas(replicas) {
1082
1211
  updates: replica[1],
1083
1212
  };
1084
1213
  }
1085
- return replica;
1214
+ const address = (0, agent_addressing_js_1.checkAddress)(replica.address);
1215
+ return address ? { ...replica, address } : replica;
1086
1216
  })
1087
1217
  : _getWriteReplicasFromEnv();
1088
1218
  if (ensured.filter((replica) => replica.primary === true).length > 1) {
@@ -1,5 +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
4
  export declare function convertToDottedOrderFormat(epoch: number, runId: string, executionOrder?: number): {
4
5
  dottedOrder: string;
5
6
  microsecondPrecisionDatestring: string;
@@ -9,6 +10,8 @@ export interface RunTreeConfig {
9
10
  run_type?: string;
10
11
  id?: string;
11
12
  project_name?: string;
13
+ /** (beta) Send the run to this address instead of a project. */
14
+ address?: Address;
12
15
  parent_run?: RunTree;
13
16
  parent_run_id?: string;
14
17
  child_runs?: RunTree[];
@@ -60,6 +63,8 @@ export type WriteReplica = {
60
63
  apiKey?: string;
61
64
  workspaceId?: string;
62
65
  projectName?: string;
66
+ /** (beta) Send the replica to this address instead of a project. */
67
+ address?: Address;
63
68
  /** Whether this replica keeps the original run IDs. */
64
69
  primary?: boolean;
65
70
  updates?: KVMap | undefined;
@@ -79,7 +84,10 @@ export declare class RunTree implements BaseRun {
79
84
  id: string;
80
85
  name: RunTreeConfig["name"];
81
86
  run_type: string;
82
- project_name: string;
87
+ /** Unset for a run sent to an `address`. */
88
+ project_name?: string;
89
+ /** (beta) Set instead of `project_name` for an addressed run. */
90
+ address?: Address;
83
91
  parent_run?: RunTree;
84
92
  parent_run_id?: string;
85
93
  child_runs: RunTree[];
@@ -114,6 +122,8 @@ export declare class RunTree implements BaseRun {
114
122
  */
115
123
  private _serialized_start_time;
116
124
  constructor(originalConfig: RunTreeConfig | RunTree);
125
+ /** Falls back to the env; a bad env leaves the run untraced. */
126
+ private _resolveAddressing;
117
127
  set metadata(metadata: KVMap);
118
128
  get metadata(): KVMap;
119
129
  private static getDefaultConfig;
@@ -123,6 +133,8 @@ export declare class RunTree implements BaseRun {
123
133
  private _convertToCreate;
124
134
  private _sliceParentId;
125
135
  private _setReplicaTraceRoot;
136
+ /** A replica naming neither inherits the run tree's destination. */
137
+ private _replicaAddressing;
126
138
  private _remapForProject;
127
139
  postRun(excludeChildRuns?: boolean): Promise<void>;
128
140
  /**