@deepagents/context 2.4.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/README.md +5 -0
- package/dist/index.js +65 -89
- package/dist/index.js.map +3 -3
- package/dist/lib/sandbox/daytona-sandbox.d.ts +11 -14
- package/dist/lib/sandbox/daytona-sandbox.d.ts.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -35,6 +35,11 @@ See the docs for the full API surface:
|
|
|
35
35
|
|
|
36
36
|
- [Sandbox](https://januarylabs.github.io/deepagents/docs/context/sandbox)
|
|
37
37
|
- [Subcommand Builders](https://januarylabs.github.io/deepagents/docs/context/subcommand)
|
|
38
|
+
- [GCS Cloud Storage Volumes](https://januarylabs.github.io/deepagents/docs/context/recipes/gcs-cloud-storage)
|
|
39
|
+
|
|
40
|
+
For same-host Linux Docker daemons, `gcs({ hostPath, mountPath })` provides a
|
|
41
|
+
typed bind-volume helper over a host `gcsfuse` mount. For remote daemons, keep
|
|
42
|
+
cloud wiring in the daemon/plugin layer and attach the resulting named volume.
|
|
38
43
|
|
|
39
44
|
## Basic Usage
|
|
40
45
|
|
package/dist/index.js
CHANGED
|
@@ -6595,11 +6595,9 @@ function resolveRealCwd(ctx) {
|
|
|
6595
6595
|
// packages/context/src/lib/sandbox/daytona-sandbox.ts
|
|
6596
6596
|
import "bash-tool";
|
|
6597
6597
|
import { randomUUID } from "node:crypto";
|
|
6598
|
-
import { createRequire } from "node:module";
|
|
6599
6598
|
var DAYTONA_DEFAULT_DESTINATION = "/home/daytona";
|
|
6600
6599
|
var DAYTONA_EXIT_POLL_INTERVAL_MS = 250;
|
|
6601
6600
|
var DAYTONA_EXIT_POLL_TIMEOUT_MS = 3e4;
|
|
6602
|
-
var requireOptional = createRequire(import.meta.url);
|
|
6603
6601
|
var DaytonaSandboxError = class extends Error {
|
|
6604
6602
|
constructor(message2, cause) {
|
|
6605
6603
|
super(message2);
|
|
@@ -6607,15 +6605,6 @@ var DaytonaSandboxError = class extends Error {
|
|
|
6607
6605
|
this.cause = cause;
|
|
6608
6606
|
}
|
|
6609
6607
|
};
|
|
6610
|
-
var DaytonaNotAvailableError = class extends DaytonaSandboxError {
|
|
6611
|
-
constructor(cause) {
|
|
6612
|
-
super(
|
|
6613
|
-
"@daytona/sdk is not installed. Install it with: npm install @daytona/sdk",
|
|
6614
|
-
cause
|
|
6615
|
-
);
|
|
6616
|
-
this.name = "DaytonaNotAvailableError";
|
|
6617
|
-
}
|
|
6618
|
-
};
|
|
6619
6608
|
var DaytonaCreationError = class extends DaytonaSandboxError {
|
|
6620
6609
|
constructor(message2, cause) {
|
|
6621
6610
|
super(`Failed to create Daytona sandbox: ${message2}`, cause);
|
|
@@ -6628,71 +6617,66 @@ var DaytonaCommandError = class extends DaytonaSandboxError {
|
|
|
6628
6617
|
this.name = "DaytonaCommandError";
|
|
6629
6618
|
}
|
|
6630
6619
|
};
|
|
6631
|
-
async function createDaytonaSandbox(options = {}) {
|
|
6620
|
+
async function createDaytonaSandbox(client, options = {}) {
|
|
6632
6621
|
validateDaytonaOptions(options);
|
|
6633
|
-
const
|
|
6634
|
-
let client;
|
|
6635
|
-
try {
|
|
6636
|
-
client = new Daytona(createDaytonaConfig(options));
|
|
6637
|
-
} catch (error) {
|
|
6638
|
-
const err = toError(error);
|
|
6639
|
-
throw new DaytonaCreationError(err.message, err);
|
|
6640
|
-
}
|
|
6641
|
-
const attached = options.sandboxId !== void 0;
|
|
6642
|
-
const deleteOnDispose = options.deleteOnDispose ?? !attached;
|
|
6622
|
+
const sdk = await import("@daytona/sdk");
|
|
6643
6623
|
let sandbox;
|
|
6644
6624
|
try {
|
|
6645
|
-
|
|
6646
|
-
|
|
6647
|
-
|
|
6648
|
-
}
|
|
6649
|
-
|
|
6650
|
-
await sandbox.start?.(options.startTimeout ?? options.createTimeout);
|
|
6625
|
+
if (options.sandboxId !== void 0) {
|
|
6626
|
+
sandbox = await client.get(options.sandboxId);
|
|
6627
|
+
await startIfStopped(sandbox, options);
|
|
6628
|
+
} else {
|
|
6629
|
+
sandbox = await acquireReusedSandbox(client, options, sdk);
|
|
6651
6630
|
}
|
|
6652
6631
|
} catch (error) {
|
|
6653
|
-
|
|
6654
|
-
throw new DaytonaCreationError(err.message, err);
|
|
6632
|
+
throw normalizeDaytonaError(error, sdk);
|
|
6655
6633
|
}
|
|
6656
6634
|
return createDaytonaSandboxMethods({
|
|
6657
|
-
client,
|
|
6658
6635
|
sandbox,
|
|
6659
|
-
commandTimeout: options.commandTimeout
|
|
6660
|
-
deleteOnDispose,
|
|
6661
|
-
deleteTimeout: options.deleteTimeout
|
|
6636
|
+
commandTimeout: options.commandTimeout
|
|
6662
6637
|
});
|
|
6663
6638
|
}
|
|
6664
|
-
|
|
6639
|
+
var UNRECOVERABLE_SANDBOX_STATES = /* @__PURE__ */ new Set([
|
|
6640
|
+
"error",
|
|
6641
|
+
"build_failed",
|
|
6642
|
+
"destroyed"
|
|
6643
|
+
]);
|
|
6644
|
+
async function acquireReusedSandbox(client, options, sdk) {
|
|
6645
|
+
let existing;
|
|
6665
6646
|
try {
|
|
6666
|
-
|
|
6667
|
-
if (typeof mod.Daytona !== "function") {
|
|
6668
|
-
throw new DaytonaSandboxError(
|
|
6669
|
-
"@daytona/sdk did not export a Daytona constructor"
|
|
6670
|
-
);
|
|
6671
|
-
}
|
|
6672
|
-
return { Daytona: mod.Daytona };
|
|
6647
|
+
existing = await client.get(options.name);
|
|
6673
6648
|
} catch (error) {
|
|
6674
|
-
if (error instanceof
|
|
6675
|
-
|
|
6676
|
-
}
|
|
6677
|
-
const err = toError(error);
|
|
6678
|
-
if (isMissingDaytonaSdk(err)) {
|
|
6679
|
-
throw new DaytonaNotAvailableError(err);
|
|
6649
|
+
if (error instanceof sdk.DaytonaNotFoundError) {
|
|
6650
|
+
return createSandbox(client, options);
|
|
6680
6651
|
}
|
|
6681
|
-
throw
|
|
6652
|
+
throw error;
|
|
6653
|
+
}
|
|
6654
|
+
if (existing.state && UNRECOVERABLE_SANDBOX_STATES.has(existing.state)) {
|
|
6655
|
+
await deleteSandboxQuietly(existing, options);
|
|
6656
|
+
return createSandbox(client, options);
|
|
6682
6657
|
}
|
|
6658
|
+
await startIfStopped(existing, options);
|
|
6659
|
+
return existing;
|
|
6683
6660
|
}
|
|
6684
|
-
function
|
|
6685
|
-
|
|
6686
|
-
|
|
6687
|
-
|
|
6688
|
-
|
|
6689
|
-
apiUrl: options.apiUrl,
|
|
6690
|
-
target: options.target,
|
|
6691
|
-
otelEnabled: options.otelEnabled,
|
|
6692
|
-
_experimental: options.experimental
|
|
6693
|
-
});
|
|
6661
|
+
async function deleteSandboxQuietly(sandbox, options) {
|
|
6662
|
+
try {
|
|
6663
|
+
await sandbox.delete(options.deleteTimeout);
|
|
6664
|
+
} catch {
|
|
6665
|
+
}
|
|
6694
6666
|
}
|
|
6695
|
-
function
|
|
6667
|
+
async function startIfStopped(sandbox, options) {
|
|
6668
|
+
if (sandbox.state && sandbox.state !== "started") {
|
|
6669
|
+
await sandbox.start(options.startTimeout ?? options.createTimeout);
|
|
6670
|
+
}
|
|
6671
|
+
}
|
|
6672
|
+
function normalizeDaytonaError(error, sdk) {
|
|
6673
|
+
const err = toError(error);
|
|
6674
|
+
if (err instanceof sdk.DaytonaError) {
|
|
6675
|
+
return err;
|
|
6676
|
+
}
|
|
6677
|
+
return new DaytonaCreationError(err.message, err);
|
|
6678
|
+
}
|
|
6679
|
+
function createSandbox(client, options) {
|
|
6696
6680
|
const base = compactObject({
|
|
6697
6681
|
name: options.name,
|
|
6698
6682
|
user: options.user,
|
|
@@ -6708,18 +6692,22 @@ function createDaytonaParams(options) {
|
|
|
6708
6692
|
networkAllowList: options.networkAllowList,
|
|
6709
6693
|
ephemeral: options.ephemeral
|
|
6710
6694
|
});
|
|
6711
|
-
if (options.image) {
|
|
6712
|
-
|
|
6695
|
+
if (options.image !== void 0) {
|
|
6696
|
+
const params2 = compactObject({
|
|
6713
6697
|
...base,
|
|
6714
6698
|
image: options.image,
|
|
6715
6699
|
resources: options.resources
|
|
6716
6700
|
});
|
|
6701
|
+
return client.create(params2, {
|
|
6702
|
+
timeout: options.createTimeout,
|
|
6703
|
+
onSnapshotCreateLogs: options.onSnapshotCreateLogs
|
|
6704
|
+
});
|
|
6717
6705
|
}
|
|
6718
6706
|
const params = compactObject({
|
|
6719
6707
|
...base,
|
|
6720
6708
|
snapshot: options.snapshot
|
|
6721
6709
|
});
|
|
6722
|
-
return
|
|
6710
|
+
return client.create(params, { timeout: options.createTimeout });
|
|
6723
6711
|
}
|
|
6724
6712
|
function validateDaytonaOptions(options) {
|
|
6725
6713
|
if (options.image && options.snapshot) {
|
|
@@ -6732,6 +6720,11 @@ function validateDaytonaOptions(options) {
|
|
|
6732
6720
|
'Daytona sandbox options can only include "resources" when creating from "image". The Daytona SDK does not apply resources during default or snapshot creation.'
|
|
6733
6721
|
);
|
|
6734
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
|
+
}
|
|
6735
6728
|
if (!options.sandboxId) {
|
|
6736
6729
|
return;
|
|
6737
6730
|
}
|
|
@@ -6764,8 +6757,7 @@ function validateDaytonaOptions(options) {
|
|
|
6764
6757
|
}
|
|
6765
6758
|
}
|
|
6766
6759
|
function createDaytonaSandboxMethods(args) {
|
|
6767
|
-
const {
|
|
6768
|
-
let disposed = false;
|
|
6760
|
+
const { sandbox, commandTimeout } = args;
|
|
6769
6761
|
const executeCommand = async (command, options) => {
|
|
6770
6762
|
if (options?.signal?.aborted) {
|
|
6771
6763
|
return abortedCommandResult();
|
|
@@ -6848,17 +6840,6 @@ function createDaytonaSandboxMethods(args) {
|
|
|
6848
6840
|
}
|
|
6849
6841
|
},
|
|
6850
6842
|
async dispose() {
|
|
6851
|
-
if (disposed) return;
|
|
6852
|
-
disposed = true;
|
|
6853
|
-
try {
|
|
6854
|
-
if (deleteOnDispose) {
|
|
6855
|
-
if (sandbox.delete) await sandbox.delete(deleteTimeout);
|
|
6856
|
-
else if (client.delete) await client.delete(sandbox, deleteTimeout);
|
|
6857
|
-
}
|
|
6858
|
-
} finally {
|
|
6859
|
-
await client[Symbol.asyncDispose]?.().catch(() => {
|
|
6860
|
-
});
|
|
6861
|
-
}
|
|
6862
6843
|
}
|
|
6863
6844
|
};
|
|
6864
6845
|
}
|
|
@@ -7084,10 +7065,6 @@ function compactObject(input) {
|
|
|
7084
7065
|
}
|
|
7085
7066
|
return output;
|
|
7086
7067
|
}
|
|
7087
|
-
function isMissingDaytonaSdk(error) {
|
|
7088
|
-
const maybeCode = error.code;
|
|
7089
|
-
return maybeCode === "ERR_MODULE_NOT_FOUND" || maybeCode === "MODULE_NOT_FOUND" || error.message.includes("@daytona/sdk");
|
|
7090
|
-
}
|
|
7091
7068
|
function toError(error) {
|
|
7092
7069
|
return error instanceof Error ? error : new Error(String(error));
|
|
7093
7070
|
}
|
|
@@ -8517,7 +8494,7 @@ function soul() {
|
|
|
8517
8494
|
}
|
|
8518
8495
|
|
|
8519
8496
|
// packages/context/src/lib/store/postgres.store.ts
|
|
8520
|
-
import { createRequire
|
|
8497
|
+
import { createRequire } from "node:module";
|
|
8521
8498
|
|
|
8522
8499
|
// packages/context/src/lib/store/ddl.postgres.ts
|
|
8523
8500
|
function storeDDL(schema) {
|
|
@@ -8629,7 +8606,7 @@ var PostgresContextStore = class _PostgresContextStore extends ContextStore {
|
|
|
8629
8606
|
}
|
|
8630
8607
|
static #requirePg() {
|
|
8631
8608
|
try {
|
|
8632
|
-
const require2 =
|
|
8609
|
+
const require2 = createRequire(import.meta.url);
|
|
8633
8610
|
return require2("pg");
|
|
8634
8611
|
} catch {
|
|
8635
8612
|
throw new Error(
|
|
@@ -9225,7 +9202,7 @@ var PostgresContextStore = class _PostgresContextStore extends ContextStore {
|
|
|
9225
9202
|
};
|
|
9226
9203
|
|
|
9227
9204
|
// packages/context/src/lib/store/sqlserver.store.ts
|
|
9228
|
-
import { createRequire as
|
|
9205
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
9229
9206
|
|
|
9230
9207
|
// packages/context/src/lib/store/ddl.sqlserver.ts
|
|
9231
9208
|
function storeDDL2(schema) {
|
|
@@ -9367,7 +9344,7 @@ var SqlServerContextStore = class _SqlServerContextStore extends ContextStore {
|
|
|
9367
9344
|
}
|
|
9368
9345
|
static #requireMssql() {
|
|
9369
9346
|
try {
|
|
9370
|
-
const require2 =
|
|
9347
|
+
const require2 = createRequire2(import.meta.url);
|
|
9371
9348
|
return require2("mssql");
|
|
9372
9349
|
} catch {
|
|
9373
9350
|
throw new Error(
|
|
@@ -10357,7 +10334,7 @@ function asStaticWordPartText(parts, options = {}) {
|
|
|
10357
10334
|
}
|
|
10358
10335
|
|
|
10359
10336
|
// packages/context/src/lib/stream/postgres-notify-change-source.ts
|
|
10360
|
-
import { createRequire as
|
|
10337
|
+
import { createRequire as createRequire3 } from "node:module";
|
|
10361
10338
|
|
|
10362
10339
|
// packages/context/src/lib/stream/ddl.stream.postgres-notify.ts
|
|
10363
10340
|
var DEFAULT_POSTGRES_STREAM_CHANGES_CHANNEL = "deepagents_stream_changes";
|
|
@@ -10459,7 +10436,7 @@ var PostgresNotifyChangeSource = class _PostgresNotifyChangeSource {
|
|
|
10459
10436
|
}
|
|
10460
10437
|
static #requirePg() {
|
|
10461
10438
|
try {
|
|
10462
|
-
const require2 =
|
|
10439
|
+
const require2 = createRequire3(import.meta.url);
|
|
10463
10440
|
return require2("pg");
|
|
10464
10441
|
} catch {
|
|
10465
10442
|
throw new Error(
|
|
@@ -10714,7 +10691,7 @@ function assertIdentifier(value, label) {
|
|
|
10714
10691
|
}
|
|
10715
10692
|
|
|
10716
10693
|
// packages/context/src/lib/stream/postgres.stream-store.ts
|
|
10717
|
-
import { createRequire as
|
|
10694
|
+
import { createRequire as createRequire4 } from "node:module";
|
|
10718
10695
|
|
|
10719
10696
|
// packages/context/src/lib/stream/ddl.stream.postgres.ts
|
|
10720
10697
|
function postgresStreamDDL(schema) {
|
|
@@ -10788,7 +10765,7 @@ var PostgresStreamStore = class _PostgresStreamStore extends StreamStore {
|
|
|
10788
10765
|
}
|
|
10789
10766
|
static #requirePg() {
|
|
10790
10767
|
try {
|
|
10791
|
-
const require2 =
|
|
10768
|
+
const require2 = createRequire4(import.meta.url);
|
|
10792
10769
|
return require2("pg");
|
|
10793
10770
|
} catch {
|
|
10794
10771
|
throw new Error(
|
|
@@ -11649,7 +11626,6 @@ export {
|
|
|
11649
11626
|
DEFAULT_WATCH_POLLING,
|
|
11650
11627
|
DaytonaCommandError,
|
|
11651
11628
|
DaytonaCreationError,
|
|
11652
|
-
DaytonaNotAvailableError,
|
|
11653
11629
|
DaytonaSandboxError,
|
|
11654
11630
|
DockerNotAvailableError,
|
|
11655
11631
|
DockerSandboxError,
|