@deepagents/context 3.0.0 → 3.0.1
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/index.js
CHANGED
|
@@ -6605,15 +6605,6 @@ var DaytonaSandboxError = class extends Error {
|
|
|
6605
6605
|
this.cause = cause;
|
|
6606
6606
|
}
|
|
6607
6607
|
};
|
|
6608
|
-
var DaytonaNotAvailableError = class extends DaytonaSandboxError {
|
|
6609
|
-
constructor(cause) {
|
|
6610
|
-
super(
|
|
6611
|
-
"@daytona/sdk is not installed. Install it with: npm install @daytona/sdk",
|
|
6612
|
-
cause
|
|
6613
|
-
);
|
|
6614
|
-
this.name = "DaytonaNotAvailableError";
|
|
6615
|
-
}
|
|
6616
|
-
};
|
|
6617
6608
|
var DaytonaCreationError = class extends DaytonaSandboxError {
|
|
6618
6609
|
constructor(message2, cause) {
|
|
6619
6610
|
super(`Failed to create Daytona sandbox: ${message2}`, cause);
|
|
@@ -6626,54 +6617,56 @@ var DaytonaCommandError = class extends DaytonaSandboxError {
|
|
|
6626
6617
|
this.name = "DaytonaCommandError";
|
|
6627
6618
|
}
|
|
6628
6619
|
};
|
|
6629
|
-
async function createDaytonaSandbox(options = {}) {
|
|
6620
|
+
async function createDaytonaSandbox(client, options = {}) {
|
|
6630
6621
|
validateDaytonaOptions(options);
|
|
6631
|
-
const sdk = await
|
|
6632
|
-
let client;
|
|
6633
|
-
try {
|
|
6634
|
-
client = new sdk.Daytona(createDaytonaConfig(options));
|
|
6635
|
-
} catch (error) {
|
|
6636
|
-
throw normalizeDaytonaError(error, sdk);
|
|
6637
|
-
}
|
|
6638
|
-
const attached = options.sandboxId !== void 0;
|
|
6639
|
-
const reuseByName = !attached && options.name !== void 0;
|
|
6640
|
-
const deleteOnDispose = options.deleteOnDispose ?? (!attached && !reuseByName);
|
|
6622
|
+
const sdk = await import("@daytona/sdk");
|
|
6641
6623
|
let sandbox;
|
|
6642
6624
|
try {
|
|
6643
|
-
if (
|
|
6644
|
-
sandbox = await acquireReusedSandbox(client, options, sdk);
|
|
6645
|
-
} else if (attached) {
|
|
6625
|
+
if (options.sandboxId !== void 0) {
|
|
6646
6626
|
sandbox = await client.get(options.sandboxId);
|
|
6647
6627
|
await startIfStopped(sandbox, options);
|
|
6648
6628
|
} else {
|
|
6649
|
-
sandbox = await
|
|
6629
|
+
sandbox = await acquireReusedSandbox(client, options, sdk);
|
|
6650
6630
|
}
|
|
6651
6631
|
} catch (error) {
|
|
6652
6632
|
throw normalizeDaytonaError(error, sdk);
|
|
6653
6633
|
}
|
|
6654
6634
|
return createDaytonaSandboxMethods({
|
|
6655
|
-
client,
|
|
6656
6635
|
sandbox,
|
|
6657
|
-
commandTimeout: options.commandTimeout
|
|
6658
|
-
deleteOnDispose,
|
|
6659
|
-
deleteTimeout: options.deleteTimeout
|
|
6636
|
+
commandTimeout: options.commandTimeout
|
|
6660
6637
|
});
|
|
6661
6638
|
}
|
|
6639
|
+
var UNRECOVERABLE_SANDBOX_STATES = /* @__PURE__ */ new Set([
|
|
6640
|
+
"error",
|
|
6641
|
+
"build_failed",
|
|
6642
|
+
"destroyed"
|
|
6643
|
+
]);
|
|
6662
6644
|
async function acquireReusedSandbox(client, options, sdk) {
|
|
6645
|
+
let existing;
|
|
6663
6646
|
try {
|
|
6664
|
-
|
|
6665
|
-
await startIfStopped(sandbox, options);
|
|
6666
|
-
return sandbox;
|
|
6647
|
+
existing = await client.get(options.name);
|
|
6667
6648
|
} catch (error) {
|
|
6668
|
-
if (
|
|
6669
|
-
|
|
6649
|
+
if (error instanceof sdk.DaytonaNotFoundError) {
|
|
6650
|
+
return createSandbox(client, options);
|
|
6670
6651
|
}
|
|
6652
|
+
throw error;
|
|
6653
|
+
}
|
|
6654
|
+
if (existing.state && UNRECOVERABLE_SANDBOX_STATES.has(existing.state)) {
|
|
6655
|
+
await deleteSandboxQuietly(existing, options);
|
|
6671
6656
|
return createSandbox(client, options);
|
|
6672
6657
|
}
|
|
6658
|
+
await startIfStopped(existing, options);
|
|
6659
|
+
return existing;
|
|
6660
|
+
}
|
|
6661
|
+
async function deleteSandboxQuietly(sandbox, options) {
|
|
6662
|
+
try {
|
|
6663
|
+
await sandbox.delete(options.deleteTimeout);
|
|
6664
|
+
} catch {
|
|
6665
|
+
}
|
|
6673
6666
|
}
|
|
6674
6667
|
async function startIfStopped(sandbox, options) {
|
|
6675
6668
|
if (sandbox.state && sandbox.state !== "started") {
|
|
6676
|
-
await sandbox.start
|
|
6669
|
+
await sandbox.start(options.startTimeout ?? options.createTimeout);
|
|
6677
6670
|
}
|
|
6678
6671
|
}
|
|
6679
6672
|
function normalizeDaytonaError(error, sdk) {
|
|
@@ -6683,37 +6676,6 @@ function normalizeDaytonaError(error, sdk) {
|
|
|
6683
6676
|
}
|
|
6684
6677
|
return new DaytonaCreationError(err.message, err);
|
|
6685
6678
|
}
|
|
6686
|
-
async function importDaytonaSdk() {
|
|
6687
|
-
try {
|
|
6688
|
-
const mod = await import("@daytona/sdk");
|
|
6689
|
-
if (typeof mod.Daytona !== "function") {
|
|
6690
|
-
throw new DaytonaSandboxError(
|
|
6691
|
-
"@daytona/sdk did not export a Daytona constructor"
|
|
6692
|
-
);
|
|
6693
|
-
}
|
|
6694
|
-
return mod;
|
|
6695
|
-
} catch (error) {
|
|
6696
|
-
if (error instanceof DaytonaSandboxError) {
|
|
6697
|
-
throw error;
|
|
6698
|
-
}
|
|
6699
|
-
const err = toError(error);
|
|
6700
|
-
if (isMissingDaytonaSdk(err)) {
|
|
6701
|
-
throw new DaytonaNotAvailableError(err);
|
|
6702
|
-
}
|
|
6703
|
-
throw err;
|
|
6704
|
-
}
|
|
6705
|
-
}
|
|
6706
|
-
function createDaytonaConfig(options) {
|
|
6707
|
-
return compactObject({
|
|
6708
|
-
apiKey: options.apiKey,
|
|
6709
|
-
jwtToken: options.jwtToken,
|
|
6710
|
-
organizationId: options.organizationId,
|
|
6711
|
-
apiUrl: options.apiUrl,
|
|
6712
|
-
target: options.target,
|
|
6713
|
-
otelEnabled: options.otelEnabled,
|
|
6714
|
-
_experimental: options.experimental
|
|
6715
|
-
});
|
|
6716
|
-
}
|
|
6717
6679
|
function createSandbox(client, options) {
|
|
6718
6680
|
const base = compactObject({
|
|
6719
6681
|
name: options.name,
|
|
@@ -6745,9 +6707,7 @@ function createSandbox(client, options) {
|
|
|
6745
6707
|
...base,
|
|
6746
6708
|
snapshot: options.snapshot
|
|
6747
6709
|
});
|
|
6748
|
-
return client.create(
|
|
6749
|
-
timeout: options.createTimeout
|
|
6750
|
-
});
|
|
6710
|
+
return client.create(params, { timeout: options.createTimeout });
|
|
6751
6711
|
}
|
|
6752
6712
|
function validateDaytonaOptions(options) {
|
|
6753
6713
|
if (options.image && options.snapshot) {
|
|
@@ -6760,6 +6720,11 @@ function validateDaytonaOptions(options) {
|
|
|
6760
6720
|
'Daytona sandbox options can only include "resources" when creating from "image". The Daytona SDK does not apply resources during default or snapshot creation.'
|
|
6761
6721
|
);
|
|
6762
6722
|
}
|
|
6723
|
+
if (options.sandboxId === void 0 && options.name === void 0) {
|
|
6724
|
+
throw new DaytonaSandboxError(
|
|
6725
|
+
'Daytona sandbox options require "name" (get-or-create) or "sandboxId" (attach). An unnamed sandbox cannot be reclaimed, since dispose() does not delete it.'
|
|
6726
|
+
);
|
|
6727
|
+
}
|
|
6763
6728
|
if (!options.sandboxId) {
|
|
6764
6729
|
return;
|
|
6765
6730
|
}
|
|
@@ -6792,8 +6757,7 @@ function validateDaytonaOptions(options) {
|
|
|
6792
6757
|
}
|
|
6793
6758
|
}
|
|
6794
6759
|
function createDaytonaSandboxMethods(args) {
|
|
6795
|
-
const {
|
|
6796
|
-
let disposed = false;
|
|
6760
|
+
const { sandbox, commandTimeout } = args;
|
|
6797
6761
|
const executeCommand = async (command, options) => {
|
|
6798
6762
|
if (options?.signal?.aborted) {
|
|
6799
6763
|
return abortedCommandResult();
|
|
@@ -6876,17 +6840,6 @@ function createDaytonaSandboxMethods(args) {
|
|
|
6876
6840
|
}
|
|
6877
6841
|
},
|
|
6878
6842
|
async dispose() {
|
|
6879
|
-
if (disposed) return;
|
|
6880
|
-
disposed = true;
|
|
6881
|
-
try {
|
|
6882
|
-
if (deleteOnDispose) {
|
|
6883
|
-
if (sandbox.delete) await sandbox.delete(deleteTimeout);
|
|
6884
|
-
else if (client.delete) await client.delete(sandbox, deleteTimeout);
|
|
6885
|
-
}
|
|
6886
|
-
} finally {
|
|
6887
|
-
await client[Symbol.asyncDispose]?.().catch(() => {
|
|
6888
|
-
});
|
|
6889
|
-
}
|
|
6890
6843
|
}
|
|
6891
6844
|
};
|
|
6892
6845
|
}
|
|
@@ -7112,10 +7065,6 @@ function compactObject(input) {
|
|
|
7112
7065
|
}
|
|
7113
7066
|
return output;
|
|
7114
7067
|
}
|
|
7115
|
-
function isMissingDaytonaSdk(error) {
|
|
7116
|
-
const maybeCode = error.code;
|
|
7117
|
-
return maybeCode === "ERR_MODULE_NOT_FOUND" || maybeCode === "MODULE_NOT_FOUND" || error.message.includes("@daytona/sdk");
|
|
7118
|
-
}
|
|
7119
7068
|
function toError(error) {
|
|
7120
7069
|
return error instanceof Error ? error : new Error(String(error));
|
|
7121
7070
|
}
|
|
@@ -11677,7 +11626,6 @@ export {
|
|
|
11677
11626
|
DEFAULT_WATCH_POLLING,
|
|
11678
11627
|
DaytonaCommandError,
|
|
11679
11628
|
DaytonaCreationError,
|
|
11680
|
-
DaytonaNotAvailableError,
|
|
11681
11629
|
DaytonaSandboxError,
|
|
11682
11630
|
DockerNotAvailableError,
|
|
11683
11631
|
DockerSandboxError,
|