langsmith 0.10.8 → 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 (98) 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 +160 -59
  64. package/dist/address.d.ts +59 -26
  65. package/dist/address.js +154 -55
  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/index.cjs +5 -3
  72. package/dist/index.d.ts +2 -2
  73. package/dist/index.js +2 -2
  74. package/dist/run_trees.cjs +18 -21
  75. package/dist/run_trees.d.ts +4 -4
  76. package/dist/run_trees.js +15 -18
  77. package/dist/sandbox/client.cjs +33 -4
  78. package/dist/sandbox/client.d.ts +4 -0
  79. package/dist/sandbox/client.js +34 -5
  80. package/dist/sandbox/command_handle.cjs +8 -0
  81. package/dist/sandbox/command_handle.js +8 -0
  82. package/dist/sandbox/sandbox.cjs +7 -0
  83. package/dist/sandbox/sandbox.js +7 -0
  84. package/dist/sandbox/service_url.cjs +9 -1
  85. package/dist/sandbox/service_url.d.ts +2 -1
  86. package/dist/sandbox/service_url.js +9 -1
  87. package/dist/sandbox/tracing.cjs +13 -0
  88. package/dist/sandbox/tracing.d.ts +1 -0
  89. package/dist/sandbox/tracing.js +10 -0
  90. package/dist/schemas.d.ts +3 -3
  91. package/dist/traceable.cjs +5 -4
  92. package/dist/traceable.js +4 -3
  93. package/dist/utils/{agent_addressing.cjs → addressing.cjs} +20 -11
  94. package/dist/utils/{agent_addressing.d.ts → addressing.d.ts} +4 -6
  95. package/dist/utils/{agent_addressing.js → addressing.js} +21 -11
  96. package/dist/utils/env.cjs +6 -4
  97. package/dist/utils/env.js +6 -4
  98. package/package.json +1 -1
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 { address, type Address, type Environment, 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.8";
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 { address, 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.8";
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)
@@ -52,15 +52,10 @@ const HEADER_SAFE_REPLICA_FIELDS = new Set([
52
52
  "reroot",
53
53
  "address",
54
54
  ]);
55
- // The address string, URL-encoded.
56
- const LANGSMITH_ADDRESS = "langsmith-address";
57
- /** Validates an untrusted header address; `undefined` if unusable. */
55
+ /** Rebuilds an untrusted header address; `undefined` if unusable. */
58
56
  function addressFromHeader(value) {
59
- if (value == null) {
60
- return undefined;
61
- }
62
57
  try {
63
- return (0, address_js_1.parse)(value);
58
+ return address_js_1.AgentAddress._fromLrn(value);
64
59
  }
65
60
  catch {
66
61
  // Values are untrusted, so not logged.
@@ -140,7 +135,7 @@ class Baggage {
140
135
  else if (key === "langsmith-project") {
141
136
  project_name = value;
142
137
  }
143
- else if (key === LANGSMITH_ADDRESS) {
138
+ else if (key === "langsmith-address") {
144
139
  address = addressFromHeader(value);
145
140
  }
146
141
  else if (key === "langsmith-replicas") {
@@ -152,13 +147,15 @@ class Baggage {
152
147
  const filtered = filterReplicaForHeaders(replica);
153
148
  const raw = filtered.address;
154
149
  delete filtered.address;
155
- const address = addressFromHeader(raw);
156
150
  // A project wins over an address; a replica with an invalid
157
151
  // address and no project is dropped.
158
152
  if (filtered.projectName || raw == null) {
159
153
  return [filtered];
160
154
  }
161
- return address ? [{ ...filtered, address }] : [];
155
+ const replicaAddress = addressFromHeader(raw);
156
+ return replicaAddress
157
+ ? [{ ...filtered, address: replicaAddress }]
158
+ : [];
162
159
  });
163
160
  }
164
161
  }
@@ -176,7 +173,7 @@ class Baggage {
176
173
  items.push(`langsmith-project=${encodeURIComponent(this.project_name)}`);
177
174
  }
178
175
  if (this.address) {
179
- items.push(`${LANGSMITH_ADDRESS}=${encodeURIComponent(this.address)}`);
176
+ items.push(`langsmith-address=${encodeURIComponent(this.address._toLrn())}`);
180
177
  }
181
178
  return items.join(",");
182
179
  }
@@ -426,23 +423,23 @@ class RunTree {
426
423
  }
427
424
  /** Falls back to the env; a bad env leaves the run untraced. */
428
425
  _resolveAddressing(config) {
429
- const address = (0, agent_addressing_js_1.checkAddress)(config.address);
426
+ const address = (0, address_js_1.ensureAgent)(config.address);
430
427
  const project = config.project_name || undefined;
431
- (0, agent_addressing_js_1.rejectConflicting)(project, address);
428
+ (0, addressing_js_1.rejectConflicting)(project, address);
432
429
  if (project || address) {
433
430
  this.project_name = project;
434
431
  this.address = address;
435
432
  return;
436
433
  }
437
434
  try {
438
- [this.project_name, this.address] = (0, agent_addressing_js_1.resolveFromEnv)();
435
+ [this.project_name, this.address] = (0, addressing_js_1.resolveFromEnv)();
439
436
  }
440
437
  catch (e) {
441
438
  if (!(e instanceof address_js_1.EnvAddressError)) {
442
439
  throw e;
443
440
  }
444
441
  if ((0, env_js_1.isEnvTracingEnabled)(this.tracingEnabled)) {
445
- (0, agent_addressing_js_1.logUntraced)(e);
442
+ (0, addressing_js_1.logUntraced)(e);
446
443
  }
447
444
  this.project_name = undefined;
448
445
  this.address = undefined;
@@ -652,9 +649,9 @@ class RunTree {
652
649
  }
653
650
  /** A replica naming neither inherits the run tree's destination. */
654
651
  _replicaAddressing(replica) {
655
- const address = (0, agent_addressing_js_1.checkAddress)(replica.address);
652
+ const address = (0, address_js_1.ensureAgent)(replica.address);
656
653
  if (replica.projectName != null) {
657
- (0, agent_addressing_js_1.rejectConflicting)(replica.projectName, address);
654
+ (0, addressing_js_1.rejectConflicting)(replica.projectName, address);
658
655
  return [replica.projectName, undefined];
659
656
  }
660
657
  if (address) {
@@ -669,14 +666,14 @@ class RunTree {
669
666
  if (primary === undefined &&
670
667
  !this.replicas?.some((r) => r.primary === true) &&
671
668
  projectName === this.project_name &&
672
- address === this.address) {
669
+ address?._toLrn() === this.address?._toLrn()) {
673
670
  return {
674
671
  ...baseRun,
675
672
  session_name: projectName,
676
673
  address,
677
674
  };
678
675
  }
679
- const seed = projectName ?? address ?? "agent//";
676
+ const seed = projectName ?? address?._toLrn() ?? "agent//";
680
677
  // Apply reroot logic before ID remapping
681
678
  if (reroot) {
682
679
  if (distributedParentId) {
@@ -1197,7 +1194,7 @@ function _ensureWriteReplicas(replicas) {
1197
1194
  updates: replica[1],
1198
1195
  };
1199
1196
  }
1200
- const address = (0, agent_addressing_js_1.checkAddress)(replica.address);
1197
+ const address = (0, address_js_1.ensureAgent)(replica.address);
1201
1198
  return address ? { ...replica, address } : replica;
1202
1199
  })
1203
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, parse as parseAddress, } 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";
@@ -46,15 +46,10 @@ const HEADER_SAFE_REPLICA_FIELDS = new Set([
46
46
  "reroot",
47
47
  "address",
48
48
  ]);
49
- // The address string, URL-encoded.
50
- const LANGSMITH_ADDRESS = "langsmith-address";
51
- /** Validates an untrusted header address; `undefined` if unusable. */
49
+ /** Rebuilds an untrusted header address; `undefined` if unusable. */
52
50
  function addressFromHeader(value) {
53
- if (value == null) {
54
- return undefined;
55
- }
56
51
  try {
57
- return parseAddress(value);
52
+ return AgentAddress._fromLrn(value);
58
53
  }
59
54
  catch {
60
55
  // Values are untrusted, so not logged.
@@ -134,7 +129,7 @@ class Baggage {
134
129
  else if (key === "langsmith-project") {
135
130
  project_name = value;
136
131
  }
137
- else if (key === LANGSMITH_ADDRESS) {
132
+ else if (key === "langsmith-address") {
138
133
  address = addressFromHeader(value);
139
134
  }
140
135
  else if (key === "langsmith-replicas") {
@@ -146,13 +141,15 @@ class Baggage {
146
141
  const filtered = filterReplicaForHeaders(replica);
147
142
  const raw = filtered.address;
148
143
  delete filtered.address;
149
- const address = addressFromHeader(raw);
150
144
  // A project wins over an address; a replica with an invalid
151
145
  // address and no project is dropped.
152
146
  if (filtered.projectName || raw == null) {
153
147
  return [filtered];
154
148
  }
155
- return address ? [{ ...filtered, address }] : [];
149
+ const replicaAddress = addressFromHeader(raw);
150
+ return replicaAddress
151
+ ? [{ ...filtered, address: replicaAddress }]
152
+ : [];
156
153
  });
157
154
  }
158
155
  }
@@ -170,7 +167,7 @@ class Baggage {
170
167
  items.push(`langsmith-project=${encodeURIComponent(this.project_name)}`);
171
168
  }
172
169
  if (this.address) {
173
- items.push(`${LANGSMITH_ADDRESS}=${encodeURIComponent(this.address)}`);
170
+ items.push(`langsmith-address=${encodeURIComponent(this.address._toLrn())}`);
174
171
  }
175
172
  return items.join(",");
176
173
  }
@@ -420,7 +417,7 @@ export class RunTree {
420
417
  }
421
418
  /** Falls back to the env; a bad env leaves the run untraced. */
422
419
  _resolveAddressing(config) {
423
- const address = checkAddress(config.address);
420
+ const address = ensureAgent(config.address);
424
421
  const project = config.project_name || undefined;
425
422
  rejectConflicting(project, address);
426
423
  if (project || address) {
@@ -646,7 +643,7 @@ export class RunTree {
646
643
  }
647
644
  /** A replica naming neither inherits the run tree's destination. */
648
645
  _replicaAddressing(replica) {
649
- const address = checkAddress(replica.address);
646
+ const address = ensureAgent(replica.address);
650
647
  if (replica.projectName != null) {
651
648
  rejectConflicting(replica.projectName, address);
652
649
  return [replica.projectName, undefined];
@@ -663,14 +660,14 @@ export class RunTree {
663
660
  if (primary === undefined &&
664
661
  !this.replicas?.some((r) => r.primary === true) &&
665
662
  projectName === this.project_name &&
666
- address === this.address) {
663
+ address?._toLrn() === this.address?._toLrn()) {
667
664
  return {
668
665
  ...baseRun,
669
666
  session_name: projectName,
670
667
  address,
671
668
  };
672
669
  }
673
- const seed = projectName ?? address ?? "agent//";
670
+ const seed = projectName ?? address?._toLrn() ?? "agent//";
674
671
  // Apply reroot logic before ID remapping
675
672
  if (reroot) {
676
673
  if (distributedParentId) {
@@ -1190,7 +1187,7 @@ function _ensureWriteReplicas(replicas) {
1190
1187
  updates: replica[1],
1191
1188
  };
1192
1189
  }
1193
- const address = checkAddress(replica.address);
1190
+ const address = ensureAgent(replica.address);
1194
1191
  return address ? { ...replica, address } : replica;
1195
1192
  })
1196
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
  *
@@ -11,7 +11,8 @@ import { Sandbox } from "./sandbox.js";
11
11
  import { LangSmithResourceCreationError, LangSmithResourceNameConflictError, LangSmithResourceNotFoundError, LangSmithResourceTimeoutError, LangSmithSandboxAPIError, LangSmithValidationError, } from "./errors.js";
12
12
  import { handleClientHttpError, handleSandboxCreationError, throwIfNotReady, validateTtl, } from "./helpers.js";
13
13
  import { validateMountConfigProxyConfig } from "./mounts.js";
14
- import { v4 as uuidv4 } from "../utils/uuid/src/index.js";
14
+ import { v4 as uuidv4, validate as isUuid } from "../utils/uuid/src/index.js";
15
+ import { addSandboxMetadata } from "./tracing.js";
15
16
  /**
16
17
  * Sleep that can be interrupted by an AbortSignal.
17
18
  * Resolves after `ms` milliseconds or rejects immediately if the signal fires.
@@ -302,6 +303,12 @@ export class SandboxClient {
302
303
  writable: true,
303
304
  value: void 0
304
305
  });
306
+ Object.defineProperty(this, "_sandboxIds", {
307
+ enumerable: true,
308
+ configurable: true,
309
+ writable: true,
310
+ value: new Map()
311
+ });
305
312
  this._baseUrl = (config.apiEndpoint ?? getDefaultApiEndpoint()).replace(/\/$/, "");
306
313
  this._apiKey = config.apiKey ?? getDefaultApiKey();
307
314
  this._defaultHeaders = { ...(config.headers ?? {}) };
@@ -395,6 +402,25 @@ export class SandboxClient {
395
402
  getDefaultHeaders() {
396
403
  return { ...this._defaultHeaders };
397
404
  }
405
+ _traceSandbox(name) {
406
+ const id = this._sandboxIds.get(name) ?? (isUuid(name) ? name : undefined);
407
+ addSandboxMetadata(id);
408
+ return id;
409
+ }
410
+ _sandboxFromData(data) {
411
+ if (data.id)
412
+ this._sandboxIds.set(data.name, data.id);
413
+ addSandboxMetadata(data.id);
414
+ return new Sandbox(data, this);
415
+ }
416
+ _forgetSandbox(name) {
417
+ const id = this._sandboxIds.get(name) ?? name;
418
+ for (const [cachedName, cachedId] of this._sandboxIds) {
419
+ if (cachedName === name || cachedId === id) {
420
+ this._sandboxIds.delete(cachedName);
421
+ }
422
+ }
423
+ }
398
424
  /**
399
425
  * JSON POST helper. Sends JSON body, checks response status,
400
426
  * and returns the Response for further processing.
@@ -403,6 +429,7 @@ export class SandboxClient {
403
429
  * @internal
404
430
  */
405
431
  _boxUrl(name, ...segments) {
432
+ this._traceSandbox(name);
406
433
  const suffix = segments.length ? `/${segments.join("/")}` : "";
407
434
  return `${this._baseUrl}/boxes/${encodeURIComponent(name)}${suffix}`;
408
435
  }
@@ -451,7 +478,7 @@ export class SandboxClient {
451
478
  return new ServiceUrl(data, () => this.serviceUrl(name, {
452
479
  port,
453
480
  expiresInSeconds,
454
- }));
481
+ }), this._traceSandbox(name));
455
482
  }
456
483
  async _postJson(url, body, options) {
457
484
  const response = await this._fetch(url, {
@@ -531,7 +558,7 @@ export class SandboxClient {
531
558
  await handleSandboxCreationError(response);
532
559
  }
533
560
  const data = (await response.json());
534
- return new Sandbox(data, this);
561
+ return this._sandboxFromData(data);
535
562
  }
536
563
  /**
537
564
  * Get a Sandbox by name.
@@ -552,7 +579,7 @@ export class SandboxClient {
552
579
  await handleClientHttpError(response);
553
580
  }
554
581
  const data = (await response.json());
555
- return new Sandbox(data, this);
582
+ return this._sandboxFromData(data);
556
583
  }
557
584
  /**
558
585
  * List all Sandboxes.
@@ -622,7 +649,8 @@ export class SandboxClient {
622
649
  await handleClientHttpError(response);
623
650
  }
624
651
  const data = (await response.json());
625
- return new Sandbox(data, this);
652
+ this._forgetSandbox(name);
653
+ return this._sandboxFromData(data);
626
654
  }
627
655
  /**
628
656
  * Delete a Sandbox.
@@ -639,6 +667,7 @@ export class SandboxClient {
639
667
  }
640
668
  await handleClientHttpError(response);
641
669
  }
670
+ this._forgetSandbox(name);
642
671
  }
643
672
  /**
644
673
  * Get the provisioning status of a sandbox.
@@ -7,6 +7,7 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.CommandHandle = void 0;
10
+ const tracing_js_1 = require("./tracing.cjs");
10
11
  const errors_js_1 = require("./errors.cjs");
11
12
  /**
12
13
  * Whether a 'started' frame proves *this* command was reattached to.
@@ -205,6 +206,7 @@ class CommandHandle {
205
206
  * The final execution result. Drains the stream if not already exhausted.
206
207
  */
207
208
  get result() {
209
+ (0, tracing_js_1.addSandboxMetadata)(this._sandbox.id);
208
210
  return this._getResult();
209
211
  }
210
212
  async _getResult() {
@@ -268,6 +270,7 @@ class CommandHandle {
268
270
  * - After kill(): no reconnect, error propagates
269
271
  */
270
272
  async *[Symbol.asyncIterator]() {
273
+ (0, tracing_js_1.addSandboxMetadata)(this._sandbox.id);
271
274
  this._reconnectAttempts = 0;
272
275
  while (true) {
273
276
  try {
@@ -283,6 +286,8 @@ class CommandHandle {
283
286
  chunk.offset + new TextEncoder().encode(chunk.data).length;
284
287
  this._onStderr?.(chunk.data);
285
288
  }
289
+ // Each resumption runs in the consumer's current context.
290
+ (0, tracing_js_1.addSandboxMetadata)(this._sandbox.id);
286
291
  yield chunk;
287
292
  }
288
293
  return; // Stream ended normally (exit message received)
@@ -325,6 +330,7 @@ class CommandHandle {
325
330
  * subsequently yield an exit message with a non-zero exit code.
326
331
  */
327
332
  kill() {
333
+ (0, tracing_js_1.addSandboxMetadata)(this._sandbox.id);
328
334
  if (this._control) {
329
335
  this._control.sendKill();
330
336
  }
@@ -333,6 +339,7 @@ class CommandHandle {
333
339
  * Write data to the command's stdin.
334
340
  */
335
341
  sendInput(data) {
342
+ (0, tracing_js_1.addSandboxMetadata)(this._sandbox.id);
336
343
  if (this._stdinClosed) {
337
344
  throw new errors_js_1.LangSmithSandboxOperationError("stdin is closed for this command. Non-PTY commands close stdin by " +
338
345
  "default so a command that reads it sees EOF instead of hanging; " +
@@ -350,6 +357,7 @@ class CommandHandle {
350
357
  * EOT byte (0x04) with {@link sendInput} instead.
351
358
  */
352
359
  closeInput() {
360
+ (0, tracing_js_1.addSandboxMetadata)(this._sandbox.id);
353
361
  if (this._pty || this._stdinClosed)
354
362
  return;
355
363
  this._stdinClosed = true;
@@ -4,6 +4,7 @@
4
4
  *
5
5
  * Port of Python's AsyncCommandHandle to TypeScript.
6
6
  */
7
+ import { addSandboxMetadata } from "./tracing.js";
7
8
  import { LangSmithSandboxConnectionError, LangSmithSandboxServerReloadError, LangSmithSandboxOperationError, LangSmithStreamEndedBeforeStartedError, } from "./errors.js";
8
9
  /**
9
10
  * Whether a 'started' frame proves *this* command was reattached to.
@@ -202,6 +203,7 @@ export class CommandHandle {
202
203
  * The final execution result. Drains the stream if not already exhausted.
203
204
  */
204
205
  get result() {
206
+ addSandboxMetadata(this._sandbox.id);
205
207
  return this._getResult();
206
208
  }
207
209
  async _getResult() {
@@ -265,6 +267,7 @@ export class CommandHandle {
265
267
  * - After kill(): no reconnect, error propagates
266
268
  */
267
269
  async *[Symbol.asyncIterator]() {
270
+ addSandboxMetadata(this._sandbox.id);
268
271
  this._reconnectAttempts = 0;
269
272
  while (true) {
270
273
  try {
@@ -280,6 +283,8 @@ export class CommandHandle {
280
283
  chunk.offset + new TextEncoder().encode(chunk.data).length;
281
284
  this._onStderr?.(chunk.data);
282
285
  }
286
+ // Each resumption runs in the consumer's current context.
287
+ addSandboxMetadata(this._sandbox.id);
283
288
  yield chunk;
284
289
  }
285
290
  return; // Stream ended normally (exit message received)
@@ -322,6 +327,7 @@ export class CommandHandle {
322
327
  * subsequently yield an exit message with a non-zero exit code.
323
328
  */
324
329
  kill() {
330
+ addSandboxMetadata(this._sandbox.id);
325
331
  if (this._control) {
326
332
  this._control.sendKill();
327
333
  }
@@ -330,6 +336,7 @@ export class CommandHandle {
330
336
  * Write data to the command's stdin.
331
337
  */
332
338
  sendInput(data) {
339
+ addSandboxMetadata(this._sandbox.id);
333
340
  if (this._stdinClosed) {
334
341
  throw new LangSmithSandboxOperationError("stdin is closed for this command. Non-PTY commands close stdin by " +
335
342
  "default so a command that reads it sees EOF instead of hanging; " +
@@ -347,6 +354,7 @@ export class CommandHandle {
347
354
  * EOT byte (0x04) with {@link sendInput} instead.
348
355
  */
349
356
  closeInput() {
357
+ addSandboxMetadata(this._sandbox.id);
350
358
  if (this._pty || this._stdinClosed)
351
359
  return;
352
360
  this._stdinClosed = true;