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.
- package/dist/_openapi_client/client.cjs +26 -2
- package/dist/_openapi_client/client.d.ts +15 -6
- package/dist/_openapi_client/client.js +27 -3
- package/dist/_openapi_client/internal/detect-platform.cjs +1 -1
- package/dist/_openapi_client/internal/detect-platform.js +1 -1
- package/dist/_openapi_client/resources/annotation-queues/items.cjs +13 -6
- package/dist/_openapi_client/resources/annotation-queues/items.d.ts +33 -8
- package/dist/_openapi_client/resources/annotation-queues/items.js +13 -6
- package/dist/_openapi_client/resources/datasets/datasets.cjs +9 -0
- package/dist/_openapi_client/resources/datasets/datasets.d.ts +4 -0
- package/dist/_openapi_client/resources/datasets/datasets.js +9 -0
- package/dist/_openapi_client/resources/datasets/examples.cjs +26 -0
- package/dist/_openapi_client/resources/datasets/examples.d.ts +23 -0
- package/dist/_openapi_client/resources/datasets/examples.js +22 -0
- package/dist/_openapi_client/resources/fleet/fleet.cjs +54 -0
- package/dist/_openapi_client/resources/fleet/fleet.d.ts +9 -0
- package/dist/_openapi_client/resources/fleet/fleet.js +17 -0
- package/dist/_openapi_client/resources/fleet/threads.cjs +18 -0
- package/dist/_openapi_client/resources/fleet/threads.d.ts +19 -0
- package/dist/_openapi_client/resources/fleet/threads.js +14 -0
- package/dist/_openapi_client/resources/index.cjs +8 -2
- package/dist/_openapi_client/resources/index.d.ts +6 -3
- package/dist/_openapi_client/resources/index.js +5 -2
- package/dist/_openapi_client/resources/info.d.ts +6 -0
- package/dist/_openapi_client/resources/issues.cjs +2 -2
- package/dist/_openapi_client/resources/issues.d.ts +188 -4
- package/dist/_openapi_client/resources/issues.js +2 -2
- package/dist/_openapi_client/resources/online-evaluators.cjs +7 -4
- package/dist/_openapi_client/resources/online-evaluators.d.ts +63 -4
- package/dist/_openapi_client/resources/online-evaluators.js +7 -4
- package/dist/_openapi_client/resources/product-feedback.cjs +33 -0
- package/dist/_openapi_client/resources/product-feedback.d.ts +77 -0
- package/dist/_openapi_client/resources/product-feedback.js +29 -0
- package/dist/_openapi_client/resources/runs/runs.d.ts +26 -16
- package/dist/_openapi_client/resources/sandboxes/boxes.cjs +44 -4
- package/dist/_openapi_client/resources/sandboxes/boxes.d.ts +256 -21
- package/dist/_openapi_client/resources/sandboxes/boxes.js +44 -4
- package/dist/_openapi_client/resources/sandboxes/registries.d.ts +10 -2
- package/dist/_openapi_client/resources/sandboxes/sandboxes.cjs +13 -0
- package/dist/_openapi_client/resources/sandboxes/sandboxes.d.ts +169 -14
- package/dist/_openapi_client/resources/sandboxes/sandboxes.js +13 -0
- package/dist/_openapi_client/resources/sandboxes/snapshots.cjs +10 -6
- package/dist/_openapi_client/resources/sandboxes/snapshots.d.ts +37 -6
- package/dist/_openapi_client/resources/sandboxes/snapshots.js +10 -6
- package/dist/_openapi_client/resources/sessions.cjs +23 -0
- package/dist/_openapi_client/resources/sessions.d.ts +732 -0
- package/dist/_openapi_client/resources/sessions.js +19 -0
- package/dist/_openapi_client/resources/threads/index.cjs +9 -0
- package/dist/_openapi_client/resources/threads/index.d.ts +2 -0
- package/dist/_openapi_client/resources/threads/index.js +4 -0
- package/dist/_openapi_client/resources/threads/share.cjs +61 -0
- package/dist/_openapi_client/resources/threads/share.d.ts +71 -0
- package/dist/_openapi_client/resources/threads/share.js +57 -0
- package/dist/_openapi_client/resources/threads/threads.cjs +143 -0
- package/dist/_openapi_client/resources/threads/threads.d.ts +973 -0
- package/dist/_openapi_client/resources/threads/threads.js +106 -0
- package/dist/_openapi_client/resources/threads.cjs +15 -67
- package/dist/_openapi_client/resources/threads.d.ts +1 -709
- package/dist/_openapi_client/resources/threads.js +1 -65
- package/dist/_openapi_client/resources/traces.d.ts +7 -1
- package/dist/_openapi_client/version.cjs +1 -1
- package/dist/_openapi_client/version.js +1 -1
- package/dist/address.cjs +176 -99
- package/dist/address.d.ts +63 -8
- package/dist/address.js +170 -90
- package/dist/anonymizer/index.cjs +1 -1
- package/dist/anonymizer/index.js +1 -1
- package/dist/client.cjs +39 -19
- package/dist/client.d.ts +20 -4
- package/dist/client.js +34 -14
- package/dist/experimental/otel/exporter.cjs +21 -4
- package/dist/experimental/otel/exporter.d.ts +4 -2
- package/dist/experimental/otel/exporter.js +21 -4
- package/dist/index.cjs +5 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/run_trees.cjs +26 -43
- package/dist/run_trees.d.ts +4 -4
- package/dist/run_trees.js +23 -40
- package/dist/sandbox/client.cjs +33 -4
- package/dist/sandbox/client.d.ts +4 -0
- package/dist/sandbox/client.js +34 -5
- package/dist/sandbox/command_handle.cjs +8 -0
- package/dist/sandbox/command_handle.js +8 -0
- package/dist/sandbox/sandbox.cjs +7 -0
- package/dist/sandbox/sandbox.js +7 -0
- package/dist/sandbox/service_url.cjs +9 -1
- package/dist/sandbox/service_url.d.ts +2 -1
- package/dist/sandbox/service_url.js +9 -1
- package/dist/sandbox/tracing.cjs +13 -0
- package/dist/sandbox/tracing.d.ts +1 -0
- package/dist/sandbox/tracing.js +10 -0
- package/dist/schemas.d.ts +3 -3
- package/dist/traceable.cjs +5 -4
- package/dist/traceable.js +4 -3
- package/dist/utils/{agent_addressing.cjs → addressing.cjs} +22 -23
- package/dist/utils/{agent_addressing.d.ts → addressing.d.ts} +5 -8
- package/dist/utils/{agent_addressing.js → addressing.js} +23 -23
- package/dist/utils/env.cjs +6 -4
- package/dist/utils/env.js +6 -4
- package/package.json +1 -1
package/dist/sandbox/client.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
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;
|
package/dist/sandbox/sandbox.cjs
CHANGED
|
@@ -8,6 +8,7 @@ const uuid_js_1 = require("../uuid.cjs");
|
|
|
8
8
|
const errors_js_1 = require("./errors.cjs");
|
|
9
9
|
const helpers_js_1 = require("./helpers.cjs");
|
|
10
10
|
const command_handle_js_1 = require("./command_handle.cjs");
|
|
11
|
+
const tracing_js_1 = require("./tracing.cjs");
|
|
11
12
|
const ws_execute_js_1 = require("./ws_execute.cjs");
|
|
12
13
|
/**
|
|
13
14
|
* Represents an active sandbox for running commands and file operations.
|
|
@@ -195,6 +196,7 @@ class Sandbox {
|
|
|
195
196
|
* @throws LangSmithDataplaneNotConfiguredError if dataplane_url is not configured.
|
|
196
197
|
*/
|
|
197
198
|
requireDataplaneUrl() {
|
|
199
|
+
(0, tracing_js_1.addSandboxMetadata)(this.id);
|
|
198
200
|
if (!this.dataplane_url) {
|
|
199
201
|
throw new errors_js_1.LangSmithDataplaneNotConfiguredError(`Sandbox '${this.name}' does not have a dataplane_url configured. ` +
|
|
200
202
|
"Runtime operations require a dataplane URL.");
|
|
@@ -593,6 +595,7 @@ class Sandbox {
|
|
|
593
595
|
* ```
|
|
594
596
|
*/
|
|
595
597
|
async generateDownloadURL(path, options = {}) {
|
|
598
|
+
(0, tracing_js_1.addSandboxMetadata)(this.id);
|
|
596
599
|
return this._client.generateDownloadURL(this.name, path, options);
|
|
597
600
|
}
|
|
598
601
|
/**
|
|
@@ -609,6 +612,7 @@ class Sandbox {
|
|
|
609
612
|
* ```
|
|
610
613
|
*/
|
|
611
614
|
async delete() {
|
|
615
|
+
(0, tracing_js_1.addSandboxMetadata)(this.id);
|
|
612
616
|
await this._client.deleteSandbox(this.name);
|
|
613
617
|
}
|
|
614
618
|
/**
|
|
@@ -619,6 +623,7 @@ class Sandbox {
|
|
|
619
623
|
* @param timeout - Timeout in seconds when waiting for ready. Default: 120.
|
|
620
624
|
*/
|
|
621
625
|
async start(options = {}) {
|
|
626
|
+
(0, tracing_js_1.addSandboxMetadata)(this.id);
|
|
622
627
|
const refreshed = await this._client.startSandbox(this.name, options);
|
|
623
628
|
this.status = refreshed.status;
|
|
624
629
|
this.dataplane_url = refreshed.dataplane_url;
|
|
@@ -627,6 +632,7 @@ class Sandbox {
|
|
|
627
632
|
* Stop a running sandbox (preserves sandbox files for later restart).
|
|
628
633
|
*/
|
|
629
634
|
async stop() {
|
|
635
|
+
(0, tracing_js_1.addSandboxMetadata)(this.id);
|
|
630
636
|
await this._client.stopSandbox(this.name);
|
|
631
637
|
// dataplane_url stays set: it is stable across stop/start and a request on
|
|
632
638
|
// it resumes the sandbox.
|
|
@@ -640,6 +646,7 @@ class Sandbox {
|
|
|
640
646
|
* @returns Snapshot in "ready" status.
|
|
641
647
|
*/
|
|
642
648
|
async captureSnapshot(name, options = {}) {
|
|
649
|
+
(0, tracing_js_1.addSandboxMetadata)(this.id);
|
|
643
650
|
return this._client.captureSnapshot(this.name, name, options);
|
|
644
651
|
}
|
|
645
652
|
}
|
package/dist/sandbox/sandbox.js
CHANGED
|
@@ -5,6 +5,7 @@ import { uuid7 } from "../uuid.js";
|
|
|
5
5
|
import { LangSmithDataplaneNotConfiguredError, LangSmithSandboxRetryableConnectionError, LangSmithStreamEndedBeforeStartedError, } from "./errors.js";
|
|
6
6
|
import { assertRunConfigNotCombined, buildRangeHeader, fileChunkFromResponse, fileStatFromResponse, handleFileHttpError, handleSandboxHttpError, resolveCloseInput, } from "./helpers.js";
|
|
7
7
|
import { CommandHandle } from "./command_handle.js";
|
|
8
|
+
import { addSandboxMetadata } from "./tracing.js";
|
|
8
9
|
import { connectDeadline, isWsAvailable, openTimeoutFor, reconnectWsStream, remainingBudget, runWsStream, } from "./ws_execute.js";
|
|
9
10
|
/**
|
|
10
11
|
* Represents an active sandbox for running commands and file operations.
|
|
@@ -192,6 +193,7 @@ export class Sandbox {
|
|
|
192
193
|
* @throws LangSmithDataplaneNotConfiguredError if dataplane_url is not configured.
|
|
193
194
|
*/
|
|
194
195
|
requireDataplaneUrl() {
|
|
196
|
+
addSandboxMetadata(this.id);
|
|
195
197
|
if (!this.dataplane_url) {
|
|
196
198
|
throw new LangSmithDataplaneNotConfiguredError(`Sandbox '${this.name}' does not have a dataplane_url configured. ` +
|
|
197
199
|
"Runtime operations require a dataplane URL.");
|
|
@@ -590,6 +592,7 @@ export class Sandbox {
|
|
|
590
592
|
* ```
|
|
591
593
|
*/
|
|
592
594
|
async generateDownloadURL(path, options = {}) {
|
|
595
|
+
addSandboxMetadata(this.id);
|
|
593
596
|
return this._client.generateDownloadURL(this.name, path, options);
|
|
594
597
|
}
|
|
595
598
|
/**
|
|
@@ -606,6 +609,7 @@ export class Sandbox {
|
|
|
606
609
|
* ```
|
|
607
610
|
*/
|
|
608
611
|
async delete() {
|
|
612
|
+
addSandboxMetadata(this.id);
|
|
609
613
|
await this._client.deleteSandbox(this.name);
|
|
610
614
|
}
|
|
611
615
|
/**
|
|
@@ -616,6 +620,7 @@ export class Sandbox {
|
|
|
616
620
|
* @param timeout - Timeout in seconds when waiting for ready. Default: 120.
|
|
617
621
|
*/
|
|
618
622
|
async start(options = {}) {
|
|
623
|
+
addSandboxMetadata(this.id);
|
|
619
624
|
const refreshed = await this._client.startSandbox(this.name, options);
|
|
620
625
|
this.status = refreshed.status;
|
|
621
626
|
this.dataplane_url = refreshed.dataplane_url;
|
|
@@ -624,6 +629,7 @@ export class Sandbox {
|
|
|
624
629
|
* Stop a running sandbox (preserves sandbox files for later restart).
|
|
625
630
|
*/
|
|
626
631
|
async stop() {
|
|
632
|
+
addSandboxMetadata(this.id);
|
|
627
633
|
await this._client.stopSandbox(this.name);
|
|
628
634
|
// dataplane_url stays set: it is stable across stop/start and a request on
|
|
629
635
|
// it resumes the sandbox.
|
|
@@ -637,6 +643,7 @@ export class Sandbox {
|
|
|
637
643
|
* @returns Snapshot in "ready" status.
|
|
638
644
|
*/
|
|
639
645
|
async captureSnapshot(name, options = {}) {
|
|
646
|
+
addSandboxMetadata(this.id);
|
|
640
647
|
return this._client.captureSnapshot(this.name, name, options);
|
|
641
648
|
}
|
|
642
649
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ServiceLoginUrl = exports.ServiceUrl = exports.SERVICE_TOKEN_HEADER = void 0;
|
|
4
|
+
const tracing_js_1 = require("./tracing.cjs");
|
|
4
5
|
/** Header the sandbox router reads the minted service token from. */
|
|
5
6
|
exports.SERVICE_TOKEN_HEADER = "X-Langsmith-Sandbox-Service-Token";
|
|
6
7
|
/** Refresh this many seconds before the token actually expires. */
|
|
@@ -11,7 +12,13 @@ const REFRESH_MARGIN_SECONDS = 60;
|
|
|
11
12
|
* Accessors are async because a refresh is a network call.
|
|
12
13
|
*/
|
|
13
14
|
class ServiceUrl {
|
|
14
|
-
constructor(data, refresher) {
|
|
15
|
+
constructor(data, refresher, _sandboxId) {
|
|
16
|
+
Object.defineProperty(this, "_sandboxId", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
writable: true,
|
|
20
|
+
value: _sandboxId
|
|
21
|
+
});
|
|
15
22
|
Object.defineProperty(this, "_browserUrl", {
|
|
16
23
|
enumerable: true,
|
|
17
24
|
configurable: true,
|
|
@@ -87,6 +94,7 @@ class ServiceUrl {
|
|
|
87
94
|
}
|
|
88
95
|
/** Fetch a path on the service with the token header injected. */
|
|
89
96
|
async fetch(path = "/", init = {}) {
|
|
97
|
+
(0, tracing_js_1.addSandboxMetadata)(this._sandboxId);
|
|
90
98
|
const base = (await this.serviceUrl()).replace(/\/+$/, "");
|
|
91
99
|
const url = `${base}/${path.replace(/^\/+/, "")}`;
|
|
92
100
|
const headers = new Headers(init.headers);
|
|
@@ -15,12 +15,13 @@ export interface ServiceUrlData {
|
|
|
15
15
|
* Accessors are async because a refresh is a network call.
|
|
16
16
|
*/
|
|
17
17
|
export declare class ServiceUrl {
|
|
18
|
+
private readonly _sandboxId?;
|
|
18
19
|
private _browserUrl;
|
|
19
20
|
private _serviceUrl;
|
|
20
21
|
private _token;
|
|
21
22
|
private _expiresAt;
|
|
22
23
|
private readonly _refresher?;
|
|
23
|
-
constructor(data: ServiceUrlData, refresher?: () => Promise<ServiceUrl
|
|
24
|
+
constructor(data: ServiceUrlData, refresher?: () => Promise<ServiceUrl>, _sandboxId?: string | undefined);
|
|
24
25
|
private _shouldRefresh;
|
|
25
26
|
private _maybeRefresh;
|
|
26
27
|
/** The signed token, refreshed if near expiry. */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { addSandboxMetadata } from "./tracing.js";
|
|
1
2
|
/** Header the sandbox router reads the minted service token from. */
|
|
2
3
|
export const SERVICE_TOKEN_HEADER = "X-Langsmith-Sandbox-Service-Token";
|
|
3
4
|
/** Refresh this many seconds before the token actually expires. */
|
|
@@ -8,7 +9,13 @@ const REFRESH_MARGIN_SECONDS = 60;
|
|
|
8
9
|
* Accessors are async because a refresh is a network call.
|
|
9
10
|
*/
|
|
10
11
|
export class ServiceUrl {
|
|
11
|
-
constructor(data, refresher) {
|
|
12
|
+
constructor(data, refresher, _sandboxId) {
|
|
13
|
+
Object.defineProperty(this, "_sandboxId", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value: _sandboxId
|
|
18
|
+
});
|
|
12
19
|
Object.defineProperty(this, "_browserUrl", {
|
|
13
20
|
enumerable: true,
|
|
14
21
|
configurable: true,
|
|
@@ -84,6 +91,7 @@ export class ServiceUrl {
|
|
|
84
91
|
}
|
|
85
92
|
/** Fetch a path on the service with the token header injected. */
|
|
86
93
|
async fetch(path = "/", init = {}) {
|
|
94
|
+
addSandboxMetadata(this._sandboxId);
|
|
87
95
|
const base = (await this.serviceUrl()).replace(/\/+$/, "");
|
|
88
96
|
const url = `${base}/${path.replace(/^\/+/, "")}`;
|
|
89
97
|
const headers = new Headers(init.headers);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addSandboxMetadata = addSandboxMetadata;
|
|
4
|
+
const run_trees_js_1 = require("../run_trees.cjs");
|
|
5
|
+
const traceable_js_1 = require("../singletons/traceable.cjs");
|
|
6
|
+
function addSandboxMetadata(sandboxId) {
|
|
7
|
+
if (!sandboxId)
|
|
8
|
+
return;
|
|
9
|
+
const run = (0, traceable_js_1.getCurrentRunTree)(true);
|
|
10
|
+
if ((0, run_trees_js_1.isRunTree)(run)) {
|
|
11
|
+
run.metadata = { sandbox_id: sandboxId };
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function addSandboxMetadata(sandboxId?: string): void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isRunTree } from "../run_trees.js";
|
|
2
|
+
import { getCurrentRunTree } from "../singletons/traceable.js";
|
|
3
|
+
export function addSandboxMetadata(sandboxId) {
|
|
4
|
+
if (!sandboxId)
|
|
5
|
+
return;
|
|
6
|
+
const run = getCurrentRunTree(true);
|
|
7
|
+
if (isRunTree(run)) {
|
|
8
|
+
run.metadata = { sandbox_id: sandboxId };
|
|
9
|
+
}
|
|
10
|
+
}
|
package/dist/schemas.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AgentAddress } from "./address.js";
|
|
2
2
|
export interface TracerSession {
|
|
3
3
|
tenant_id: string;
|
|
4
4
|
id: string;
|
|
@@ -150,7 +150,7 @@ export interface RunCreate extends BaseRun {
|
|
|
150
150
|
revision_id?: string;
|
|
151
151
|
child_runs?: this[];
|
|
152
152
|
session_name?: string;
|
|
153
|
-
address?:
|
|
153
|
+
address?: AgentAddress;
|
|
154
154
|
}
|
|
155
155
|
export interface RunUpdate {
|
|
156
156
|
id?: string;
|
|
@@ -169,7 +169,7 @@ export interface RunUpdate {
|
|
|
169
169
|
events?: KVMap[];
|
|
170
170
|
session_id?: string;
|
|
171
171
|
session_name?: string;
|
|
172
|
-
address?:
|
|
172
|
+
address?: AgentAddress;
|
|
173
173
|
/** Unique ID assigned to every run within this nested trace. **/
|
|
174
174
|
trace_id?: string;
|
|
175
175
|
/**
|
package/dist/traceable.cjs
CHANGED
|
@@ -9,7 +9,8 @@ const traceable_js_1 = require("./singletons/traceable.cjs");
|
|
|
9
9
|
const constants_js_1 = require("./singletons/constants.cjs");
|
|
10
10
|
const asserts_js_1 = require("./utils/asserts.cjs");
|
|
11
11
|
const index_js_1 = require("./index.cjs");
|
|
12
|
-
const
|
|
12
|
+
const address_js_1 = require("./address.cjs");
|
|
13
|
+
const addressing_js_1 = require("./utils/addressing.cjs");
|
|
13
14
|
const otel_js_1 = require("./singletons/otel.cjs");
|
|
14
15
|
const utils_js_1 = require("./experimental/otel/utils.cjs");
|
|
15
16
|
const constants_js_2 = require("./experimental/otel/constants.cjs");
|
|
@@ -473,8 +474,8 @@ const convertSerializableArg = (arg, options) => {
|
|
|
473
474
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
474
475
|
function traceable(wrappedFunc, config) {
|
|
475
476
|
const { aggregator, argsConfigPath, __finalTracedIteratorKey, processInputs, processOutputs, extractAttachments, on_start, ...runTreeConfig } = config ?? {};
|
|
476
|
-
runTreeConfig.address = (0,
|
|
477
|
-
(0,
|
|
477
|
+
runTreeConfig.address = (0, address_js_1.ensureAgent)(runTreeConfig.address);
|
|
478
|
+
(0, addressing_js_1.rejectConflicting)(runTreeConfig.project_name, runTreeConfig.address);
|
|
478
479
|
const processInputsFn = processInputs ?? ((x) => x);
|
|
479
480
|
const processOutputsFn = processOutputs ?? ((x) => x);
|
|
480
481
|
const extractAttachmentsFn = extractAttachments ?? ((...x) => [undefined, runInputsToMap(x)]);
|
|
@@ -526,7 +527,7 @@ function traceable(wrappedFunc, config) {
|
|
|
526
527
|
runtimeConfig = undefined;
|
|
527
528
|
}
|
|
528
529
|
// Runtime config outranks decorator config, whichever mode each names.
|
|
529
|
-
[ensuredConfig.project_name, ensuredConfig.address] = (0,
|
|
530
|
+
[ensuredConfig.project_name, ensuredConfig.address] = (0, addressing_js_1.firstNamed)([runtimeConfig?.project_name, (0, address_js_1.ensureAgent)(runtimeConfig?.address)], [runTreeConfig.project_name, (0, address_js_1.ensureAgent)(runTreeConfig.address)]);
|
|
530
531
|
let runEndedPromiseResolver;
|
|
531
532
|
const runEndedPromise = new Promise((resolve) => {
|
|
532
533
|
runEndedPromiseResolver = resolve;
|
package/dist/traceable.js
CHANGED
|
@@ -5,7 +5,8 @@ import { ROOT, AsyncLocalStorageProviderSingleton, getCurrentRunTree, } from "./
|
|
|
5
5
|
import { _LC_CHILD_RUN_END_PROMISES_KEY, _LC_CONTEXT_VARIABLES_KEY, _PROCESSING_FAILED_KEY, _processingFailed, } from "./singletons/constants.js";
|
|
6
6
|
import { isKVMap, isReadableStream, isAsyncIterable, isIteratorLike, isThenable, isGenerator, isPromiseMethod, } from "./utils/asserts.js";
|
|
7
7
|
import { __version__ } from "./index.js";
|
|
8
|
-
import {
|
|
8
|
+
import { ensureAgent } from "./address.js";
|
|
9
|
+
import { firstNamed, rejectConflicting } from "./utils/addressing.js";
|
|
9
10
|
import { getOTELTrace, getOTELContext } from "./singletons/otel.js";
|
|
10
11
|
import { getUuidFromOtelSpanId } from "./experimental/otel/utils.js";
|
|
11
12
|
import { LANGSMITH_REFERENCE_EXAMPLE_ID, LANGSMITH_SESSION_NAME, LANGSMITH_TRACEABLE, } from "./experimental/otel/constants.js";
|
|
@@ -469,7 +470,7 @@ const convertSerializableArg = (arg, options) => {
|
|
|
469
470
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
470
471
|
export function traceable(wrappedFunc, config) {
|
|
471
472
|
const { aggregator, argsConfigPath, __finalTracedIteratorKey, processInputs, processOutputs, extractAttachments, on_start, ...runTreeConfig } = config ?? {};
|
|
472
|
-
runTreeConfig.address =
|
|
473
|
+
runTreeConfig.address = ensureAgent(runTreeConfig.address);
|
|
473
474
|
rejectConflicting(runTreeConfig.project_name, runTreeConfig.address);
|
|
474
475
|
const processInputsFn = processInputs ?? ((x) => x);
|
|
475
476
|
const processOutputsFn = processOutputs ?? ((x) => x);
|
|
@@ -522,7 +523,7 @@ export function traceable(wrappedFunc, config) {
|
|
|
522
523
|
runtimeConfig = undefined;
|
|
523
524
|
}
|
|
524
525
|
// Runtime config outranks decorator config, whichever mode each names.
|
|
525
|
-
[ensuredConfig.project_name, ensuredConfig.address] = firstNamed([runtimeConfig?.project_name, runtimeConfig?.address], [runTreeConfig.project_name, runTreeConfig.address]);
|
|
526
|
+
[ensuredConfig.project_name, ensuredConfig.address] = firstNamed([runtimeConfig?.project_name, ensureAgent(runtimeConfig?.address)], [runTreeConfig.project_name, ensureAgent(runTreeConfig.address)]);
|
|
526
527
|
let runEndedPromiseResolver;
|
|
527
528
|
const runEndedPromise = new Promise((resolve) => {
|
|
528
529
|
runEndedPromiseResolver = resolve;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkAddress = checkAddress;
|
|
4
3
|
exports.rejectConflicting = rejectConflicting;
|
|
5
4
|
exports.firstNamed = firstNamed;
|
|
6
5
|
exports.resolveFromEnv = resolveFromEnv;
|
|
@@ -10,19 +9,10 @@ exports.applyToPayload = applyToPayload;
|
|
|
10
9
|
const address_js_1 = require("../address.cjs");
|
|
11
10
|
const env_js_1 = require("./env.cjs");
|
|
12
11
|
const warn_js_1 = require("./warn.cjs");
|
|
13
|
-
function isRendered(value) {
|
|
14
|
-
return (value != null &&
|
|
15
|
-
typeof value === "object" &&
|
|
16
|
-
"kind" in value);
|
|
17
|
-
}
|
|
18
|
-
/** Validate an address at an entry point; the SDK carries the frozen copy. */
|
|
19
|
-
function checkAddress(address) {
|
|
20
|
-
return address == null ? undefined : (0, address_js_1.normalizeAddress)(address);
|
|
21
|
-
}
|
|
22
12
|
function rejectConflicting(project, address) {
|
|
23
13
|
if (project && address) {
|
|
24
14
|
throw new Error(`A run is sent to a project (${JSON.stringify(project)}) or to an ` +
|
|
25
|
-
|
|
15
|
+
"address, not both.");
|
|
26
16
|
}
|
|
27
17
|
}
|
|
28
18
|
/** The highest level naming a project or an address, whichever it names. */
|
|
@@ -46,7 +36,7 @@ function getEnvProject() {
|
|
|
46
36
|
*/
|
|
47
37
|
function resolveFromEnv() {
|
|
48
38
|
const project = getEnvProject();
|
|
49
|
-
const address =
|
|
39
|
+
const address = address_js_1.AgentAddress.fromEnv();
|
|
50
40
|
if (project && address) {
|
|
51
41
|
throw new address_js_1.EnvAddressError("LANGSMITH_AGENT_* and a project are both set in the environment.");
|
|
52
42
|
}
|
|
@@ -69,30 +59,39 @@ function warnOnEnv() {
|
|
|
69
59
|
}
|
|
70
60
|
}
|
|
71
61
|
/**
|
|
72
|
-
*
|
|
73
|
-
* naming no project takes the env address.
|
|
74
|
-
* re-prepared when batched) are left alone.
|
|
62
|
+
* Put the run's address in its payload field, in its wire form.
|
|
63
|
+
* Without one, a create naming no project takes the env address.
|
|
75
64
|
*
|
|
76
65
|
* @throws {EnvAddressError} If the env names half an address.
|
|
77
66
|
*/
|
|
78
67
|
function applyToPayload(run, { update = false } = {}) {
|
|
79
68
|
const payload = run;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
69
|
+
let address;
|
|
70
|
+
if (typeof payload.address === "string") {
|
|
71
|
+
// Wire data already applied: a queued run is applied again when its batch
|
|
72
|
+
// is sent. It is parsed again, so a malformed one cannot fail the whole
|
|
73
|
+
// batch in the backend.
|
|
74
|
+
try {
|
|
75
|
+
address = address_js_1.AgentAddress._fromLrn(payload.address);
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
throw new Error("The run's `address` is not a valid agent address.");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
address = (0, address_js_1.ensureAgent)(payload.address);
|
|
85
83
|
}
|
|
84
|
+
delete payload.address;
|
|
86
85
|
const namedProject = payload.session_id != null || payload.session_name != null;
|
|
87
|
-
if (!address && !update && !namedProject
|
|
88
|
-
address =
|
|
86
|
+
if (!address && !update && !namedProject) {
|
|
87
|
+
address = address_js_1.AgentAddress.fromEnv();
|
|
89
88
|
}
|
|
90
89
|
if (!address) {
|
|
91
90
|
return;
|
|
92
91
|
}
|
|
93
92
|
(0, warn_js_1.warnOnce)("Sending runs to an `address` is in beta and enabled per workspace; a " +
|
|
94
93
|
"workspace without it rejects the runs.");
|
|
95
|
-
|
|
94
|
+
payload.address = address._toLrn();
|
|
96
95
|
if (!namedProject) {
|
|
97
96
|
delete payload.session_name;
|
|
98
97
|
delete payload.session_id;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AgentAddress, EnvAddressError } from "../address.js";
|
|
2
2
|
/** One precedence level: the `[project, address]` it names. */
|
|
3
|
-
export type Tier = [string | undefined,
|
|
4
|
-
/** Validate an address at an entry point; the SDK carries the frozen copy. */
|
|
5
|
-
export declare function checkAddress(address: unknown): Readonly<Address> | undefined;
|
|
3
|
+
export type Tier = [string | undefined, AgentAddress | undefined];
|
|
6
4
|
export declare function rejectConflicting(project: unknown, address: unknown): void;
|
|
7
5
|
/** The highest level naming a project or an address, whichever it names. */
|
|
8
6
|
export declare function firstNamed(...tiers: Tier[]): Tier;
|
|
@@ -15,14 +13,13 @@ export declare function logUntraced(error: EnvAddressError): void;
|
|
|
15
13
|
/** Warn once, at client construction, if the env can't address runs. */
|
|
16
14
|
export declare function warnOnEnv(): void;
|
|
17
15
|
/**
|
|
18
|
-
*
|
|
19
|
-
* naming no project takes the env address.
|
|
20
|
-
* re-prepared when batched) are left alone.
|
|
16
|
+
* Put the run's address in its payload field, in its wire form.
|
|
17
|
+
* Without one, a create naming no project takes the env address.
|
|
21
18
|
*
|
|
22
19
|
* @throws {EnvAddressError} If the env names half an address.
|
|
23
20
|
*/
|
|
24
21
|
export declare function applyToPayload(run: {
|
|
25
|
-
address?:
|
|
22
|
+
address?: AgentAddress;
|
|
26
23
|
session_id?: string;
|
|
27
24
|
session_name?: string;
|
|
28
25
|
}, { update }?: {
|