langsmith 0.5.8 → 0.5.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/experimental/sandbox/client.cjs +66 -4
- package/dist/experimental/sandbox/client.d.ts +33 -1
- package/dist/experimental/sandbox/client.js +67 -5
- package/dist/experimental/sandbox/errors.cjs +38 -2
- package/dist/experimental/sandbox/errors.d.ts +15 -0
- package/dist/experimental/sandbox/errors.js +36 -1
- package/dist/experimental/sandbox/index.cjs +3 -1
- package/dist/experimental/sandbox/index.d.ts +2 -2
- package/dist/experimental/sandbox/index.js +2 -0
- package/dist/experimental/sandbox/sandbox.cjs +21 -0
- package/dist/experimental/sandbox/sandbox.d.ts +5 -0
- package/dist/experimental/sandbox/sandbox.js +22 -1
- package/dist/experimental/sandbox/types.d.ts +33 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/run_trees.cjs +10 -3
- package/dist/run_trees.js +10 -3
- package/package.json +1 -1
|
@@ -530,21 +530,24 @@ class SandboxClient {
|
|
|
530
530
|
* ```
|
|
531
531
|
*/
|
|
532
532
|
async createSandbox(templateName, options = {}) {
|
|
533
|
-
const { name, timeout = 30 } = options;
|
|
533
|
+
const { name, timeout = 30, waitForReady = true } = options;
|
|
534
534
|
const url = `${this._baseUrl}/boxes`;
|
|
535
535
|
const payload = {
|
|
536
536
|
template_name: templateName,
|
|
537
|
-
wait_for_ready:
|
|
538
|
-
timeout,
|
|
537
|
+
wait_for_ready: waitForReady,
|
|
539
538
|
};
|
|
539
|
+
if (waitForReady) {
|
|
540
|
+
payload.timeout = timeout;
|
|
541
|
+
}
|
|
540
542
|
if (name) {
|
|
541
543
|
payload.name = name;
|
|
542
544
|
}
|
|
545
|
+
const httpTimeout = waitForReady ? (timeout + 30) * 1000 : 30 * 1000;
|
|
543
546
|
const response = await this._fetch(url, {
|
|
544
547
|
method: "POST",
|
|
545
548
|
headers: { "Content-Type": "application/json" },
|
|
546
549
|
body: JSON.stringify(payload),
|
|
547
|
-
signal: AbortSignal.timeout(
|
|
550
|
+
signal: AbortSignal.timeout(httpTimeout),
|
|
548
551
|
});
|
|
549
552
|
if (!response.ok) {
|
|
550
553
|
await (0, helpers_js_1.handleSandboxCreationError)(response);
|
|
@@ -635,5 +638,64 @@ class SandboxClient {
|
|
|
635
638
|
await (0, helpers_js_1.handleClientHttpError)(response);
|
|
636
639
|
}
|
|
637
640
|
}
|
|
641
|
+
/**
|
|
642
|
+
* Get the provisioning status of a sandbox.
|
|
643
|
+
*
|
|
644
|
+
* This is a lightweight endpoint designed for polling during async creation.
|
|
645
|
+
* Use this instead of getSandbox() when you only need the status.
|
|
646
|
+
*
|
|
647
|
+
* @param name - Sandbox name.
|
|
648
|
+
* @returns ResourceStatus with status and optional status_message.
|
|
649
|
+
* @throws LangSmithResourceNotFoundError if sandbox not found.
|
|
650
|
+
*/
|
|
651
|
+
async getSandboxStatus(name) {
|
|
652
|
+
const url = `${this._baseUrl}/boxes/${encodeURIComponent(name)}/status`;
|
|
653
|
+
const response = await this._fetch(url);
|
|
654
|
+
if (!response.ok) {
|
|
655
|
+
if (response.status === 404) {
|
|
656
|
+
throw new errors_js_1.LangSmithResourceNotFoundError(`Sandbox '${name}' not found`, "sandbox");
|
|
657
|
+
}
|
|
658
|
+
await (0, helpers_js_1.handleClientHttpError)(response);
|
|
659
|
+
}
|
|
660
|
+
return (await response.json());
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* Wait for a sandbox to become ready.
|
|
664
|
+
*
|
|
665
|
+
* Polls getSandboxStatus() until the sandbox reaches "ready" or "failed" status,
|
|
666
|
+
* then returns the full Sandbox object.
|
|
667
|
+
*
|
|
668
|
+
* @param name - Sandbox name.
|
|
669
|
+
* @param options - Polling options (timeout, pollInterval).
|
|
670
|
+
* @returns Ready Sandbox.
|
|
671
|
+
* @throws LangSmithResourceCreationError if sandbox status becomes "failed".
|
|
672
|
+
* @throws LangSmithResourceTimeoutError if timeout expires while still provisioning.
|
|
673
|
+
* @throws LangSmithResourceNotFoundError if sandbox not found.
|
|
674
|
+
*
|
|
675
|
+
* @example
|
|
676
|
+
* ```typescript
|
|
677
|
+
* const sandbox = await client.createSandbox("python-sandbox", { waitForReady: false });
|
|
678
|
+
* // ... do other work ...
|
|
679
|
+
* const readySandbox = await client.waitForSandbox(sandbox.name);
|
|
680
|
+
* ```
|
|
681
|
+
*/
|
|
682
|
+
async waitForSandbox(name, options = {}) {
|
|
683
|
+
const { timeout = 120, pollInterval = 1.0 } = options;
|
|
684
|
+
const deadline = Date.now() + timeout * 1000;
|
|
685
|
+
let lastStatus = "provisioning";
|
|
686
|
+
while (Date.now() < deadline) {
|
|
687
|
+
const statusResult = await this.getSandboxStatus(name);
|
|
688
|
+
lastStatus = statusResult.status;
|
|
689
|
+
if (statusResult.status === "ready") {
|
|
690
|
+
return this.getSandbox(name);
|
|
691
|
+
}
|
|
692
|
+
if (statusResult.status === "failed") {
|
|
693
|
+
throw new errors_js_1.LangSmithResourceCreationError(statusResult.status_message ?? `Sandbox '${name}' creation failed`, "sandbox");
|
|
694
|
+
}
|
|
695
|
+
// Wait before polling again
|
|
696
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval * 1000));
|
|
697
|
+
}
|
|
698
|
+
throw new errors_js_1.LangSmithResourceTimeoutError(`Sandbox '${name}' did not become ready within ${timeout}s`, "sandbox", lastStatus);
|
|
699
|
+
}
|
|
638
700
|
}
|
|
639
701
|
exports.SandboxClient = SandboxClient;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Main SandboxClient class for interacting with the sandbox server API.
|
|
3
3
|
*/
|
|
4
|
-
import type { CreatePoolOptions, CreateSandboxOptions, CreateTemplateOptions, CreateVolumeOptions, Pool, SandboxClientConfig, SandboxTemplate, UpdatePoolOptions, UpdateTemplateOptions, UpdateVolumeOptions, Volume } from "./types.js";
|
|
4
|
+
import type { CreatePoolOptions, CreateSandboxOptions, CreateTemplateOptions, CreateVolumeOptions, Pool, ResourceStatus, SandboxClientConfig, SandboxTemplate, UpdatePoolOptions, UpdateTemplateOptions, UpdateVolumeOptions, Volume, WaitForSandboxOptions } from "./types.js";
|
|
5
5
|
import { Sandbox } from "./sandbox.js";
|
|
6
6
|
/**
|
|
7
7
|
* Client for interacting with the Sandbox Server API.
|
|
@@ -237,4 +237,36 @@ export declare class SandboxClient {
|
|
|
237
237
|
* @throws LangSmithResourceNotFoundError if sandbox not found.
|
|
238
238
|
*/
|
|
239
239
|
deleteSandbox(name: string): Promise<void>;
|
|
240
|
+
/**
|
|
241
|
+
* Get the provisioning status of a sandbox.
|
|
242
|
+
*
|
|
243
|
+
* This is a lightweight endpoint designed for polling during async creation.
|
|
244
|
+
* Use this instead of getSandbox() when you only need the status.
|
|
245
|
+
*
|
|
246
|
+
* @param name - Sandbox name.
|
|
247
|
+
* @returns ResourceStatus with status and optional status_message.
|
|
248
|
+
* @throws LangSmithResourceNotFoundError if sandbox not found.
|
|
249
|
+
*/
|
|
250
|
+
getSandboxStatus(name: string): Promise<ResourceStatus>;
|
|
251
|
+
/**
|
|
252
|
+
* Wait for a sandbox to become ready.
|
|
253
|
+
*
|
|
254
|
+
* Polls getSandboxStatus() until the sandbox reaches "ready" or "failed" status,
|
|
255
|
+
* then returns the full Sandbox object.
|
|
256
|
+
*
|
|
257
|
+
* @param name - Sandbox name.
|
|
258
|
+
* @param options - Polling options (timeout, pollInterval).
|
|
259
|
+
* @returns Ready Sandbox.
|
|
260
|
+
* @throws LangSmithResourceCreationError if sandbox status becomes "failed".
|
|
261
|
+
* @throws LangSmithResourceTimeoutError if timeout expires while still provisioning.
|
|
262
|
+
* @throws LangSmithResourceNotFoundError if sandbox not found.
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```typescript
|
|
266
|
+
* const sandbox = await client.createSandbox("python-sandbox", { waitForReady: false });
|
|
267
|
+
* // ... do other work ...
|
|
268
|
+
* const readySandbox = await client.waitForSandbox(sandbox.name);
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
waitForSandbox(name: string, options?: WaitForSandboxOptions): Promise<Sandbox>;
|
|
240
272
|
}
|
|
@@ -5,7 +5,7 @@ import { getLangSmithEnvironmentVariable } from "../../utils/env.js";
|
|
|
5
5
|
import { _getFetchImplementation } from "../../singletons/fetch.js";
|
|
6
6
|
import { AsyncCaller } from "../../utils/async_caller.js";
|
|
7
7
|
import { Sandbox } from "./sandbox.js";
|
|
8
|
-
import { LangSmithResourceNameConflictError, LangSmithResourceNotFoundError, LangSmithSandboxAPIError, } from "./errors.js";
|
|
8
|
+
import { LangSmithResourceCreationError, LangSmithResourceNameConflictError, LangSmithResourceNotFoundError, LangSmithResourceTimeoutError, LangSmithSandboxAPIError, } from "./errors.js";
|
|
9
9
|
import { handleClientHttpError, handleConflictError, handlePoolError, handleResourceInUseError, handleSandboxCreationError, handleVolumeCreationError, } from "./helpers.js";
|
|
10
10
|
/**
|
|
11
11
|
* Get the default sandbox API endpoint from environment.
|
|
@@ -527,21 +527,24 @@ export class SandboxClient {
|
|
|
527
527
|
* ```
|
|
528
528
|
*/
|
|
529
529
|
async createSandbox(templateName, options = {}) {
|
|
530
|
-
const { name, timeout = 30 } = options;
|
|
530
|
+
const { name, timeout = 30, waitForReady = true } = options;
|
|
531
531
|
const url = `${this._baseUrl}/boxes`;
|
|
532
532
|
const payload = {
|
|
533
533
|
template_name: templateName,
|
|
534
|
-
wait_for_ready:
|
|
535
|
-
timeout,
|
|
534
|
+
wait_for_ready: waitForReady,
|
|
536
535
|
};
|
|
536
|
+
if (waitForReady) {
|
|
537
|
+
payload.timeout = timeout;
|
|
538
|
+
}
|
|
537
539
|
if (name) {
|
|
538
540
|
payload.name = name;
|
|
539
541
|
}
|
|
542
|
+
const httpTimeout = waitForReady ? (timeout + 30) * 1000 : 30 * 1000;
|
|
540
543
|
const response = await this._fetch(url, {
|
|
541
544
|
method: "POST",
|
|
542
545
|
headers: { "Content-Type": "application/json" },
|
|
543
546
|
body: JSON.stringify(payload),
|
|
544
|
-
signal: AbortSignal.timeout(
|
|
547
|
+
signal: AbortSignal.timeout(httpTimeout),
|
|
545
548
|
});
|
|
546
549
|
if (!response.ok) {
|
|
547
550
|
await handleSandboxCreationError(response);
|
|
@@ -632,4 +635,63 @@ export class SandboxClient {
|
|
|
632
635
|
await handleClientHttpError(response);
|
|
633
636
|
}
|
|
634
637
|
}
|
|
638
|
+
/**
|
|
639
|
+
* Get the provisioning status of a sandbox.
|
|
640
|
+
*
|
|
641
|
+
* This is a lightweight endpoint designed for polling during async creation.
|
|
642
|
+
* Use this instead of getSandbox() when you only need the status.
|
|
643
|
+
*
|
|
644
|
+
* @param name - Sandbox name.
|
|
645
|
+
* @returns ResourceStatus with status and optional status_message.
|
|
646
|
+
* @throws LangSmithResourceNotFoundError if sandbox not found.
|
|
647
|
+
*/
|
|
648
|
+
async getSandboxStatus(name) {
|
|
649
|
+
const url = `${this._baseUrl}/boxes/${encodeURIComponent(name)}/status`;
|
|
650
|
+
const response = await this._fetch(url);
|
|
651
|
+
if (!response.ok) {
|
|
652
|
+
if (response.status === 404) {
|
|
653
|
+
throw new LangSmithResourceNotFoundError(`Sandbox '${name}' not found`, "sandbox");
|
|
654
|
+
}
|
|
655
|
+
await handleClientHttpError(response);
|
|
656
|
+
}
|
|
657
|
+
return (await response.json());
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Wait for a sandbox to become ready.
|
|
661
|
+
*
|
|
662
|
+
* Polls getSandboxStatus() until the sandbox reaches "ready" or "failed" status,
|
|
663
|
+
* then returns the full Sandbox object.
|
|
664
|
+
*
|
|
665
|
+
* @param name - Sandbox name.
|
|
666
|
+
* @param options - Polling options (timeout, pollInterval).
|
|
667
|
+
* @returns Ready Sandbox.
|
|
668
|
+
* @throws LangSmithResourceCreationError if sandbox status becomes "failed".
|
|
669
|
+
* @throws LangSmithResourceTimeoutError if timeout expires while still provisioning.
|
|
670
|
+
* @throws LangSmithResourceNotFoundError if sandbox not found.
|
|
671
|
+
*
|
|
672
|
+
* @example
|
|
673
|
+
* ```typescript
|
|
674
|
+
* const sandbox = await client.createSandbox("python-sandbox", { waitForReady: false });
|
|
675
|
+
* // ... do other work ...
|
|
676
|
+
* const readySandbox = await client.waitForSandbox(sandbox.name);
|
|
677
|
+
* ```
|
|
678
|
+
*/
|
|
679
|
+
async waitForSandbox(name, options = {}) {
|
|
680
|
+
const { timeout = 120, pollInterval = 1.0 } = options;
|
|
681
|
+
const deadline = Date.now() + timeout * 1000;
|
|
682
|
+
let lastStatus = "provisioning";
|
|
683
|
+
while (Date.now() < deadline) {
|
|
684
|
+
const statusResult = await this.getSandboxStatus(name);
|
|
685
|
+
lastStatus = statusResult.status;
|
|
686
|
+
if (statusResult.status === "ready") {
|
|
687
|
+
return this.getSandbox(name);
|
|
688
|
+
}
|
|
689
|
+
if (statusResult.status === "failed") {
|
|
690
|
+
throw new LangSmithResourceCreationError(statusResult.status_message ?? `Sandbox '${name}' creation failed`, "sandbox");
|
|
691
|
+
}
|
|
692
|
+
// Wait before polling again
|
|
693
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval * 1000));
|
|
694
|
+
}
|
|
695
|
+
throw new LangSmithResourceTimeoutError(`Sandbox '${name}' did not become ready within ${timeout}s`, "sandbox", lastStatus);
|
|
696
|
+
}
|
|
635
697
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* properties for specific handling when needed.
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.LangSmithSandboxOperationError = exports.LangSmithSandboxNotReadyError = exports.LangSmithDataplaneNotConfiguredError = exports.LangSmithSandboxCreationError = exports.LangSmithQuotaExceededError = exports.LangSmithValidationError = exports.LangSmithResourceNameConflictError = exports.LangSmithResourceAlreadyExistsError = exports.LangSmithResourceInUseError = exports.LangSmithResourceTimeoutError = exports.LangSmithResourceNotFoundError = exports.LangSmithSandboxConnectionError = exports.LangSmithSandboxAuthenticationError = exports.LangSmithSandboxAPIError = exports.LangSmithSandboxError = void 0;
|
|
10
|
+
exports.LangSmithSandboxOperationError = exports.LangSmithSandboxNotReadyError = exports.LangSmithDataplaneNotConfiguredError = exports.LangSmithSandboxCreationError = exports.LangSmithResourceCreationError = exports.LangSmithQuotaExceededError = exports.LangSmithValidationError = exports.LangSmithResourceNameConflictError = exports.LangSmithResourceAlreadyExistsError = exports.LangSmithResourceInUseError = exports.LangSmithResourceTimeoutError = exports.LangSmithResourceNotFoundError = exports.LangSmithSandboxConnectionError = exports.LangSmithSandboxAuthenticationError = exports.LangSmithSandboxAPIError = exports.LangSmithSandboxError = void 0;
|
|
11
11
|
/**
|
|
12
12
|
* Base exception for sandbox client errors.
|
|
13
13
|
*/
|
|
@@ -215,8 +215,44 @@ class LangSmithQuotaExceededError extends LangSmithSandboxError {
|
|
|
215
215
|
}
|
|
216
216
|
exports.LangSmithQuotaExceededError = LangSmithQuotaExceededError;
|
|
217
217
|
// =============================================================================
|
|
218
|
-
//
|
|
218
|
+
// Resource Creation Errors
|
|
219
219
|
// =============================================================================
|
|
220
|
+
/**
|
|
221
|
+
* Raised when resource provisioning fails (general-purpose).
|
|
222
|
+
*/
|
|
223
|
+
class LangSmithResourceCreationError extends LangSmithSandboxError {
|
|
224
|
+
constructor(message, resourceType, errorType) {
|
|
225
|
+
super(message);
|
|
226
|
+
/**
|
|
227
|
+
* Type of resource that failed (e.g., "sandbox", "volume").
|
|
228
|
+
*/
|
|
229
|
+
Object.defineProperty(this, "resourceType", {
|
|
230
|
+
enumerable: true,
|
|
231
|
+
configurable: true,
|
|
232
|
+
writable: true,
|
|
233
|
+
value: void 0
|
|
234
|
+
});
|
|
235
|
+
/**
|
|
236
|
+
* Machine-readable error type (ImagePull, CrashLoop, SandboxConfig, Unschedulable).
|
|
237
|
+
*/
|
|
238
|
+
Object.defineProperty(this, "errorType", {
|
|
239
|
+
enumerable: true,
|
|
240
|
+
configurable: true,
|
|
241
|
+
writable: true,
|
|
242
|
+
value: void 0
|
|
243
|
+
});
|
|
244
|
+
this.name = "LangSmithResourceCreationError";
|
|
245
|
+
this.resourceType = resourceType;
|
|
246
|
+
this.errorType = errorType;
|
|
247
|
+
}
|
|
248
|
+
toString() {
|
|
249
|
+
if (this.errorType) {
|
|
250
|
+
return `${super.toString()} [${this.errorType}]`;
|
|
251
|
+
}
|
|
252
|
+
return super.toString();
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
exports.LangSmithResourceCreationError = LangSmithResourceCreationError;
|
|
220
256
|
/**
|
|
221
257
|
* Raised when sandbox creation fails.
|
|
222
258
|
*/
|
|
@@ -92,6 +92,21 @@ export declare class LangSmithQuotaExceededError extends LangSmithSandboxError {
|
|
|
92
92
|
quotaType?: string;
|
|
93
93
|
constructor(message: string, quotaType?: string);
|
|
94
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Raised when resource provisioning fails (general-purpose).
|
|
97
|
+
*/
|
|
98
|
+
export declare class LangSmithResourceCreationError extends LangSmithSandboxError {
|
|
99
|
+
/**
|
|
100
|
+
* Type of resource that failed (e.g., "sandbox", "volume").
|
|
101
|
+
*/
|
|
102
|
+
resourceType?: string;
|
|
103
|
+
/**
|
|
104
|
+
* Machine-readable error type (ImagePull, CrashLoop, SandboxConfig, Unschedulable).
|
|
105
|
+
*/
|
|
106
|
+
errorType?: string;
|
|
107
|
+
constructor(message: string, resourceType?: string, errorType?: string);
|
|
108
|
+
toString(): string;
|
|
109
|
+
}
|
|
95
110
|
/**
|
|
96
111
|
* Raised when sandbox creation fails.
|
|
97
112
|
*/
|
|
@@ -201,8 +201,43 @@ export class LangSmithQuotaExceededError extends LangSmithSandboxError {
|
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
203
|
// =============================================================================
|
|
204
|
-
//
|
|
204
|
+
// Resource Creation Errors
|
|
205
205
|
// =============================================================================
|
|
206
|
+
/**
|
|
207
|
+
* Raised when resource provisioning fails (general-purpose).
|
|
208
|
+
*/
|
|
209
|
+
export class LangSmithResourceCreationError extends LangSmithSandboxError {
|
|
210
|
+
constructor(message, resourceType, errorType) {
|
|
211
|
+
super(message);
|
|
212
|
+
/**
|
|
213
|
+
* Type of resource that failed (e.g., "sandbox", "volume").
|
|
214
|
+
*/
|
|
215
|
+
Object.defineProperty(this, "resourceType", {
|
|
216
|
+
enumerable: true,
|
|
217
|
+
configurable: true,
|
|
218
|
+
writable: true,
|
|
219
|
+
value: void 0
|
|
220
|
+
});
|
|
221
|
+
/**
|
|
222
|
+
* Machine-readable error type (ImagePull, CrashLoop, SandboxConfig, Unschedulable).
|
|
223
|
+
*/
|
|
224
|
+
Object.defineProperty(this, "errorType", {
|
|
225
|
+
enumerable: true,
|
|
226
|
+
configurable: true,
|
|
227
|
+
writable: true,
|
|
228
|
+
value: void 0
|
|
229
|
+
});
|
|
230
|
+
this.name = "LangSmithResourceCreationError";
|
|
231
|
+
this.resourceType = resourceType;
|
|
232
|
+
this.errorType = errorType;
|
|
233
|
+
}
|
|
234
|
+
toString() {
|
|
235
|
+
if (this.errorType) {
|
|
236
|
+
return `${super.toString()} [${this.errorType}]`;
|
|
237
|
+
}
|
|
238
|
+
return super.toString();
|
|
239
|
+
}
|
|
240
|
+
}
|
|
206
241
|
/**
|
|
207
242
|
* Raised when sandbox creation fails.
|
|
208
243
|
*/
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* @packageDocumentation
|
|
25
25
|
*/
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.LangSmithDataplaneNotConfiguredError = exports.LangSmithSandboxOperationError = exports.LangSmithSandboxNotReadyError = exports.LangSmithSandboxCreationError = exports.LangSmithQuotaExceededError = exports.LangSmithValidationError = exports.LangSmithResourceNameConflictError = exports.LangSmithResourceAlreadyExistsError = exports.LangSmithResourceInUseError = exports.LangSmithResourceTimeoutError = exports.LangSmithResourceNotFoundError = exports.LangSmithSandboxConnectionError = exports.LangSmithSandboxAuthenticationError = exports.LangSmithSandboxAPIError = exports.LangSmithSandboxError = exports.Sandbox = exports.SandboxClient = void 0;
|
|
27
|
+
exports.LangSmithDataplaneNotConfiguredError = exports.LangSmithSandboxOperationError = exports.LangSmithSandboxNotReadyError = exports.LangSmithSandboxCreationError = exports.LangSmithResourceCreationError = exports.LangSmithQuotaExceededError = exports.LangSmithValidationError = exports.LangSmithResourceNameConflictError = exports.LangSmithResourceAlreadyExistsError = exports.LangSmithResourceInUseError = exports.LangSmithResourceTimeoutError = exports.LangSmithResourceNotFoundError = exports.LangSmithSandboxConnectionError = exports.LangSmithSandboxAuthenticationError = exports.LangSmithSandboxAPIError = exports.LangSmithSandboxError = exports.Sandbox = exports.SandboxClient = void 0;
|
|
28
28
|
// Emit warning on import (alpha feature)
|
|
29
29
|
console.warn("langsmith/experimental/sandbox is in alpha. " +
|
|
30
30
|
"This feature is experimental, and breaking changes are expected.");
|
|
@@ -49,6 +49,8 @@ Object.defineProperty(exports, "LangSmithResourceNameConflictError", { enumerabl
|
|
|
49
49
|
// Validation and quota errors
|
|
50
50
|
Object.defineProperty(exports, "LangSmithValidationError", { enumerable: true, get: function () { return errors_js_1.LangSmithValidationError; } });
|
|
51
51
|
Object.defineProperty(exports, "LangSmithQuotaExceededError", { enumerable: true, get: function () { return errors_js_1.LangSmithQuotaExceededError; } });
|
|
52
|
+
// Resource creation errors
|
|
53
|
+
Object.defineProperty(exports, "LangSmithResourceCreationError", { enumerable: true, get: function () { return errors_js_1.LangSmithResourceCreationError; } });
|
|
52
54
|
// Sandbox-specific errors
|
|
53
55
|
Object.defineProperty(exports, "LangSmithSandboxCreationError", { enumerable: true, get: function () { return errors_js_1.LangSmithSandboxCreationError; } });
|
|
54
56
|
Object.defineProperty(exports, "LangSmithSandboxNotReadyError", { enumerable: true, get: function () { return errors_js_1.LangSmithSandboxNotReadyError; } });
|
|
@@ -24,5 +24,5 @@
|
|
|
24
24
|
*/
|
|
25
25
|
export { SandboxClient } from "./client.js";
|
|
26
26
|
export { Sandbox } from "./sandbox.js";
|
|
27
|
-
export type { ExecutionResult, ResourceSpec, VolumeMountSpec, Volume, SandboxTemplate, Pool, SandboxData, SandboxClientConfig, RunOptions, CreateSandboxOptions, CreateVolumeOptions, CreateTemplateOptions, UpdateTemplateOptions, CreatePoolOptions, UpdateVolumeOptions, UpdatePoolOptions, } from "./types.js";
|
|
28
|
-
export { LangSmithSandboxError, LangSmithSandboxAPIError, LangSmithSandboxAuthenticationError, LangSmithSandboxConnectionError, LangSmithResourceNotFoundError, LangSmithResourceTimeoutError, LangSmithResourceInUseError, LangSmithResourceAlreadyExistsError, LangSmithResourceNameConflictError, LangSmithValidationError, LangSmithQuotaExceededError, LangSmithSandboxCreationError, LangSmithSandboxNotReadyError, LangSmithSandboxOperationError, LangSmithDataplaneNotConfiguredError, } from "./errors.js";
|
|
27
|
+
export type { ExecutionResult, ResourceSpec, ResourceStatus, VolumeMountSpec, Volume, SandboxTemplate, Pool, SandboxData, SandboxClientConfig, RunOptions, CreateSandboxOptions, WaitForSandboxOptions, CreateVolumeOptions, CreateTemplateOptions, UpdateTemplateOptions, CreatePoolOptions, UpdateVolumeOptions, UpdatePoolOptions, } from "./types.js";
|
|
28
|
+
export { LangSmithSandboxError, LangSmithSandboxAPIError, LangSmithSandboxAuthenticationError, LangSmithSandboxConnectionError, LangSmithResourceNotFoundError, LangSmithResourceTimeoutError, LangSmithResourceInUseError, LangSmithResourceAlreadyExistsError, LangSmithResourceNameConflictError, LangSmithValidationError, LangSmithQuotaExceededError, LangSmithResourceCreationError, LangSmithSandboxCreationError, LangSmithSandboxNotReadyError, LangSmithSandboxOperationError, LangSmithDataplaneNotConfiguredError, } from "./errors.js";
|
|
@@ -36,5 +36,7 @@ LangSmithSandboxError, LangSmithSandboxAPIError, LangSmithSandboxAuthenticationE
|
|
|
36
36
|
LangSmithResourceNotFoundError, LangSmithResourceTimeoutError, LangSmithResourceInUseError, LangSmithResourceAlreadyExistsError, LangSmithResourceNameConflictError,
|
|
37
37
|
// Validation and quota errors
|
|
38
38
|
LangSmithValidationError, LangSmithQuotaExceededError,
|
|
39
|
+
// Resource creation errors
|
|
40
|
+
LangSmithResourceCreationError,
|
|
39
41
|
// Sandbox-specific errors
|
|
40
42
|
LangSmithSandboxCreationError, LangSmithSandboxNotReadyError, LangSmithSandboxOperationError, LangSmithDataplaneNotConfiguredError, } from "./errors.js";
|
|
@@ -48,6 +48,20 @@ class Sandbox {
|
|
|
48
48
|
writable: true,
|
|
49
49
|
value: void 0
|
|
50
50
|
});
|
|
51
|
+
/** Provisioning status ("provisioning", "ready", "failed"). */
|
|
52
|
+
Object.defineProperty(this, "status", {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
configurable: true,
|
|
55
|
+
writable: true,
|
|
56
|
+
value: void 0
|
|
57
|
+
});
|
|
58
|
+
/** Human-readable status message (e.g., error details when failed). */
|
|
59
|
+
Object.defineProperty(this, "status_message", {
|
|
60
|
+
enumerable: true,
|
|
61
|
+
configurable: true,
|
|
62
|
+
writable: true,
|
|
63
|
+
value: void 0
|
|
64
|
+
});
|
|
51
65
|
/** Unique identifier (UUID). Remains constant even if name changes. */
|
|
52
66
|
Object.defineProperty(this, "id", {
|
|
53
67
|
enumerable: true,
|
|
@@ -78,6 +92,8 @@ class Sandbox {
|
|
|
78
92
|
this.name = data.name;
|
|
79
93
|
this.template_name = data.template_name;
|
|
80
94
|
this.dataplane_url = data.dataplane_url;
|
|
95
|
+
this.status = data.status;
|
|
96
|
+
this.status_message = data.status_message;
|
|
81
97
|
this.id = data.id;
|
|
82
98
|
this.created_at = data.created_at;
|
|
83
99
|
this.updated_at = data.updated_at;
|
|
@@ -85,9 +101,14 @@ class Sandbox {
|
|
|
85
101
|
}
|
|
86
102
|
/**
|
|
87
103
|
* Validate and return the dataplane URL.
|
|
104
|
+
* @throws LangSmithSandboxNotReadyError if sandbox status is not "ready".
|
|
88
105
|
* @throws LangSmithDataplaneNotConfiguredError if dataplane_url is not configured.
|
|
89
106
|
*/
|
|
90
107
|
requireDataplaneUrl() {
|
|
108
|
+
if (this.status && this.status !== "ready") {
|
|
109
|
+
throw new errors_js_1.LangSmithSandboxNotReadyError(`Sandbox '${this.name}' is not ready (status: ${this.status}). ` +
|
|
110
|
+
"Use waitForSandbox() to wait for the sandbox to become ready.");
|
|
111
|
+
}
|
|
91
112
|
if (!this.dataplane_url) {
|
|
92
113
|
throw new errors_js_1.LangSmithDataplaneNotConfiguredError(`Sandbox '${this.name}' does not have a dataplane_url configured. ` +
|
|
93
114
|
"Runtime operations require a dataplane URL.");
|
|
@@ -27,6 +27,10 @@ export declare class Sandbox {
|
|
|
27
27
|
readonly template_name: string;
|
|
28
28
|
/** URL for data plane operations (file I/O, command execution). */
|
|
29
29
|
readonly dataplane_url?: string;
|
|
30
|
+
/** Provisioning status ("provisioning", "ready", "failed"). */
|
|
31
|
+
readonly status?: string;
|
|
32
|
+
/** Human-readable status message (e.g., error details when failed). */
|
|
33
|
+
readonly status_message?: string;
|
|
30
34
|
/** Unique identifier (UUID). Remains constant even if name changes. */
|
|
31
35
|
readonly id?: string;
|
|
32
36
|
/** Timestamp when the sandbox was created. */
|
|
@@ -36,6 +40,7 @@ export declare class Sandbox {
|
|
|
36
40
|
private _client;
|
|
37
41
|
/**
|
|
38
42
|
* Validate and return the dataplane URL.
|
|
43
|
+
* @throws LangSmithSandboxNotReadyError if sandbox status is not "ready".
|
|
39
44
|
* @throws LangSmithDataplaneNotConfiguredError if dataplane_url is not configured.
|
|
40
45
|
*/
|
|
41
46
|
private requireDataplaneUrl;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Sandbox class for interacting with a specific sandbox instance.
|
|
3
3
|
*/
|
|
4
|
-
import { LangSmithDataplaneNotConfiguredError } from "./errors.js";
|
|
4
|
+
import { LangSmithDataplaneNotConfiguredError, LangSmithSandboxNotReadyError, } from "./errors.js";
|
|
5
5
|
import { handleSandboxHttpError } from "./helpers.js";
|
|
6
6
|
/**
|
|
7
7
|
* Represents an active sandbox for running commands and file operations.
|
|
@@ -45,6 +45,20 @@ export class Sandbox {
|
|
|
45
45
|
writable: true,
|
|
46
46
|
value: void 0
|
|
47
47
|
});
|
|
48
|
+
/** Provisioning status ("provisioning", "ready", "failed"). */
|
|
49
|
+
Object.defineProperty(this, "status", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
configurable: true,
|
|
52
|
+
writable: true,
|
|
53
|
+
value: void 0
|
|
54
|
+
});
|
|
55
|
+
/** Human-readable status message (e.g., error details when failed). */
|
|
56
|
+
Object.defineProperty(this, "status_message", {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
configurable: true,
|
|
59
|
+
writable: true,
|
|
60
|
+
value: void 0
|
|
61
|
+
});
|
|
48
62
|
/** Unique identifier (UUID). Remains constant even if name changes. */
|
|
49
63
|
Object.defineProperty(this, "id", {
|
|
50
64
|
enumerable: true,
|
|
@@ -75,6 +89,8 @@ export class Sandbox {
|
|
|
75
89
|
this.name = data.name;
|
|
76
90
|
this.template_name = data.template_name;
|
|
77
91
|
this.dataplane_url = data.dataplane_url;
|
|
92
|
+
this.status = data.status;
|
|
93
|
+
this.status_message = data.status_message;
|
|
78
94
|
this.id = data.id;
|
|
79
95
|
this.created_at = data.created_at;
|
|
80
96
|
this.updated_at = data.updated_at;
|
|
@@ -82,9 +98,14 @@ export class Sandbox {
|
|
|
82
98
|
}
|
|
83
99
|
/**
|
|
84
100
|
* Validate and return the dataplane URL.
|
|
101
|
+
* @throws LangSmithSandboxNotReadyError if sandbox status is not "ready".
|
|
85
102
|
* @throws LangSmithDataplaneNotConfiguredError if dataplane_url is not configured.
|
|
86
103
|
*/
|
|
87
104
|
requireDataplaneUrl() {
|
|
105
|
+
if (this.status && this.status !== "ready") {
|
|
106
|
+
throw new LangSmithSandboxNotReadyError(`Sandbox '${this.name}' is not ready (status: ${this.status}). ` +
|
|
107
|
+
"Use waitForSandbox() to wait for the sandbox to become ready.");
|
|
108
|
+
}
|
|
88
109
|
if (!this.dataplane_url) {
|
|
89
110
|
throw new LangSmithDataplaneNotConfiguredError(`Sandbox '${this.name}' does not have a dataplane_url configured. ` +
|
|
90
111
|
"Runtime operations require a dataplane URL.");
|
|
@@ -64,6 +64,15 @@ export interface Pool {
|
|
|
64
64
|
created_at?: string;
|
|
65
65
|
updated_at?: string;
|
|
66
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Lightweight provisioning status for any async-created resource.
|
|
69
|
+
*/
|
|
70
|
+
export interface ResourceStatus {
|
|
71
|
+
/** One of "provisioning", "ready", "failed". */
|
|
72
|
+
status: string;
|
|
73
|
+
/** Human-readable details when failed. */
|
|
74
|
+
status_message?: string;
|
|
75
|
+
}
|
|
67
76
|
/**
|
|
68
77
|
* Data representing a sandbox instance from the API.
|
|
69
78
|
*/
|
|
@@ -72,6 +81,8 @@ export interface SandboxData {
|
|
|
72
81
|
name: string;
|
|
73
82
|
template_name: string;
|
|
74
83
|
dataplane_url?: string;
|
|
84
|
+
status?: string;
|
|
85
|
+
status_message?: string;
|
|
75
86
|
created_at?: string;
|
|
76
87
|
updated_at?: string;
|
|
77
88
|
}
|
|
@@ -137,6 +148,28 @@ export interface CreateSandboxOptions {
|
|
|
137
148
|
* Timeout in seconds when waiting for ready.
|
|
138
149
|
*/
|
|
139
150
|
timeout?: number;
|
|
151
|
+
/**
|
|
152
|
+
* Whether to wait for the sandbox to be ready before returning.
|
|
153
|
+
* When false, returns immediately with status "provisioning".
|
|
154
|
+
* Use getSandboxStatus() or waitForSandbox() to poll for readiness.
|
|
155
|
+
* Default: true.
|
|
156
|
+
*/
|
|
157
|
+
waitForReady?: boolean;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Options for waiting for a sandbox to become ready.
|
|
161
|
+
*/
|
|
162
|
+
export interface WaitForSandboxOptions {
|
|
163
|
+
/**
|
|
164
|
+
* Maximum time in seconds to wait for the sandbox to become ready.
|
|
165
|
+
* Default: 120.
|
|
166
|
+
*/
|
|
167
|
+
timeout?: number;
|
|
168
|
+
/**
|
|
169
|
+
* Time in seconds between status polls.
|
|
170
|
+
* Default: 1.0.
|
|
171
|
+
*/
|
|
172
|
+
pollInterval?: number;
|
|
140
173
|
}
|
|
141
174
|
/**
|
|
142
175
|
* Options for creating a volume.
|
package/dist/index.cjs
CHANGED
|
@@ -18,4 +18,4 @@ Object.defineProperty(exports, "PromptCache", { enumerable: true, get: function
|
|
|
18
18
|
Object.defineProperty(exports, "configureGlobalPromptCache", { enumerable: true, get: function () { return index_js_1.configureGlobalPromptCache; } });
|
|
19
19
|
Object.defineProperty(exports, "promptCacheSingleton", { enumerable: true, get: function () { return index_js_1.promptCacheSingleton; } });
|
|
20
20
|
// Update using yarn bump-version
|
|
21
|
-
exports.__version__ = "0.5.
|
|
21
|
+
exports.__version__ = "0.5.9";
|
package/dist/index.d.ts
CHANGED
|
@@ -5,4 +5,4 @@ export { overrideFetchImplementation } from "./singletons/fetch.js";
|
|
|
5
5
|
export { getDefaultProjectName } from "./utils/project.js";
|
|
6
6
|
export { uuid7, uuid7FromTime } from "./uuid.js";
|
|
7
7
|
export { Cache, PromptCache, type CacheConfig, type CacheMetrics, configureGlobalPromptCache, promptCacheSingleton, } from "./utils/prompt_cache/index.js";
|
|
8
|
-
export declare const __version__ = "0.5.
|
|
8
|
+
export declare const __version__ = "0.5.9";
|
package/dist/index.js
CHANGED
|
@@ -5,4 +5,4 @@ export { getDefaultProjectName } from "./utils/project.js";
|
|
|
5
5
|
export { uuid7, uuid7FromTime } from "./uuid.js";
|
|
6
6
|
export { Cache, PromptCache, configureGlobalPromptCache, promptCacheSingleton, } from "./utils/prompt_cache/index.js";
|
|
7
7
|
// Update using yarn bump-version
|
|
8
|
-
export const __version__ = "0.5.
|
|
8
|
+
export const __version__ = "0.5.9";
|
package/dist/run_trees.cjs
CHANGED
|
@@ -418,6 +418,15 @@ class RunTree {
|
|
|
418
418
|
execution_order: child_execution_order,
|
|
419
419
|
child_execution_order: child_execution_order,
|
|
420
420
|
});
|
|
421
|
+
// Propagate all parent metadata; child metadata takes precedence.
|
|
422
|
+
const parentMeta = this.extra?.metadata ?? {};
|
|
423
|
+
const childMeta = child.extra?.metadata ?? {};
|
|
424
|
+
if (Object.keys(parentMeta).length > 0) {
|
|
425
|
+
child.extra = {
|
|
426
|
+
...child.extra,
|
|
427
|
+
metadata: { ...parentMeta, ...childMeta },
|
|
428
|
+
};
|
|
429
|
+
}
|
|
421
430
|
// Copy context vars over into the new run tree.
|
|
422
431
|
if (constants_js_1._LC_CONTEXT_VARIABLES_KEY in this) {
|
|
423
432
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -480,14 +489,12 @@ class RunTree {
|
|
|
480
489
|
}
|
|
481
490
|
}
|
|
482
491
|
}
|
|
492
|
+
const parent_run_id = run.parent_run?.id ?? run.parent_run_id;
|
|
483
493
|
let child_runs;
|
|
484
|
-
let parent_run_id;
|
|
485
494
|
if (!excludeChildRuns) {
|
|
486
495
|
child_runs = run.child_runs.map((child_run) => this._convertToCreate(child_run, runtimeEnv, excludeChildRuns));
|
|
487
|
-
parent_run_id = undefined;
|
|
488
496
|
}
|
|
489
497
|
else {
|
|
490
|
-
parent_run_id = run.parent_run?.id ?? run.parent_run_id;
|
|
491
498
|
child_runs = [];
|
|
492
499
|
}
|
|
493
500
|
return {
|
package/dist/run_trees.js
CHANGED
|
@@ -412,6 +412,15 @@ export class RunTree {
|
|
|
412
412
|
execution_order: child_execution_order,
|
|
413
413
|
child_execution_order: child_execution_order,
|
|
414
414
|
});
|
|
415
|
+
// Propagate all parent metadata; child metadata takes precedence.
|
|
416
|
+
const parentMeta = this.extra?.metadata ?? {};
|
|
417
|
+
const childMeta = child.extra?.metadata ?? {};
|
|
418
|
+
if (Object.keys(parentMeta).length > 0) {
|
|
419
|
+
child.extra = {
|
|
420
|
+
...child.extra,
|
|
421
|
+
metadata: { ...parentMeta, ...childMeta },
|
|
422
|
+
};
|
|
423
|
+
}
|
|
415
424
|
// Copy context vars over into the new run tree.
|
|
416
425
|
if (_LC_CONTEXT_VARIABLES_KEY in this) {
|
|
417
426
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -474,14 +483,12 @@ export class RunTree {
|
|
|
474
483
|
}
|
|
475
484
|
}
|
|
476
485
|
}
|
|
486
|
+
const parent_run_id = run.parent_run?.id ?? run.parent_run_id;
|
|
477
487
|
let child_runs;
|
|
478
|
-
let parent_run_id;
|
|
479
488
|
if (!excludeChildRuns) {
|
|
480
489
|
child_runs = run.child_runs.map((child_run) => this._convertToCreate(child_run, runtimeEnv, excludeChildRuns));
|
|
481
|
-
parent_run_id = undefined;
|
|
482
490
|
}
|
|
483
491
|
else {
|
|
484
|
-
parent_run_id = run.parent_run?.id ?? run.parent_run_id;
|
|
485
492
|
child_runs = [];
|
|
486
493
|
}
|
|
487
494
|
return {
|