@deepagents/context 2.3.0 → 3.0.0
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/browser.js +20 -3
- package/dist/browser.js.map +2 -2
- package/dist/index.js +97 -37
- package/dist/index.js.map +4 -4
- package/dist/lib/agent.d.ts.map +1 -1
- package/dist/lib/fragments.d.ts +0 -13
- package/dist/lib/fragments.d.ts.map +1 -1
- package/dist/lib/sandbox/daytona-sandbox.d.ts +9 -0
- package/dist/lib/sandbox/daytona-sandbox.d.ts.map +1 -1
- package/dist/lib/sandbox/file-events.d.ts.map +1 -1
- package/dist/lib/sandbox/gcs.d.ts +35 -0
- package/dist/lib/sandbox/gcs.d.ts.map +1 -0
- package/dist/lib/sandbox/index.d.ts +1 -0
- package/dist/lib/sandbox/index.d.ts.map +1 -1
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -188,18 +188,35 @@ function fragment(name, ...children) {
|
|
|
188
188
|
data: children
|
|
189
189
|
};
|
|
190
190
|
}
|
|
191
|
+
function withoutDuplicateReasoningParts(message2) {
|
|
192
|
+
const seenReasoningItemIds = /* @__PURE__ */ new Set();
|
|
193
|
+
let dropped = false;
|
|
194
|
+
const parts = message2.parts.filter((part) => {
|
|
195
|
+
if (part.type !== "reasoning") return true;
|
|
196
|
+
const itemId = part.providerMetadata?.openai?.itemId;
|
|
197
|
+
if (typeof itemId !== "string") return true;
|
|
198
|
+
if (seenReasoningItemIds.has(itemId)) {
|
|
199
|
+
dropped = true;
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
seenReasoningItemIds.add(itemId);
|
|
203
|
+
return true;
|
|
204
|
+
});
|
|
205
|
+
return dropped ? { ...message2, parts } : message2;
|
|
206
|
+
}
|
|
191
207
|
function assistant(message2) {
|
|
208
|
+
const normalized = withoutDuplicateReasoningParts(message2);
|
|
192
209
|
return {
|
|
193
|
-
id:
|
|
210
|
+
id: normalized.id,
|
|
194
211
|
name: "assistant",
|
|
195
212
|
type: "message",
|
|
196
213
|
persist: true,
|
|
197
214
|
codec: {
|
|
198
215
|
decode() {
|
|
199
|
-
return
|
|
216
|
+
return normalized;
|
|
200
217
|
},
|
|
201
218
|
encode() {
|
|
202
|
-
return
|
|
219
|
+
return normalized;
|
|
203
220
|
}
|
|
204
221
|
}
|
|
205
222
|
};
|
|
@@ -1614,7 +1631,8 @@ var Agent = class _Agent {
|
|
|
1614
1631
|
model: this.#options.model,
|
|
1615
1632
|
system: systemPrompt,
|
|
1616
1633
|
messages: await convertToModelMessages(messages, {
|
|
1617
|
-
ignoreIncompleteToolCalls: true
|
|
1634
|
+
ignoreIncompleteToolCalls: true,
|
|
1635
|
+
tools: this.tools
|
|
1618
1636
|
}),
|
|
1619
1637
|
stopWhen: stepCountIs(200),
|
|
1620
1638
|
tools: this.tools,
|
|
@@ -1688,7 +1706,8 @@ var Agent = class _Agent {
|
|
|
1688
1706
|
model,
|
|
1689
1707
|
system: systemPrompt,
|
|
1690
1708
|
messages: await convertToModelMessages(messages, {
|
|
1691
|
-
ignoreIncompleteToolCalls: true
|
|
1709
|
+
ignoreIncompleteToolCalls: true,
|
|
1710
|
+
tools: this.tools
|
|
1692
1711
|
}),
|
|
1693
1712
|
experimental_repairToolCall: createRepairToolCall(
|
|
1694
1713
|
model,
|
|
@@ -1963,7 +1982,8 @@ function structuredOutput(options) {
|
|
|
1963
1982
|
model: options.model,
|
|
1964
1983
|
system: systemPrompt,
|
|
1965
1984
|
messages: await convertToModelMessages(messages, {
|
|
1966
|
-
ignoreIncompleteToolCalls: true
|
|
1985
|
+
ignoreIncompleteToolCalls: true,
|
|
1986
|
+
tools: options.tools
|
|
1967
1987
|
}),
|
|
1968
1988
|
stopWhen: stepCountIs(200),
|
|
1969
1989
|
experimental_repairToolCall: createRepairToolCall(
|
|
@@ -1998,7 +2018,8 @@ function structuredOutput(options) {
|
|
|
1998
2018
|
config?.abortSignal
|
|
1999
2019
|
),
|
|
2000
2020
|
messages: await convertToModelMessages(messages, {
|
|
2001
|
-
ignoreIncompleteToolCalls: true
|
|
2021
|
+
ignoreIncompleteToolCalls: true,
|
|
2022
|
+
tools: options.tools
|
|
2002
2023
|
}),
|
|
2003
2024
|
stopWhen: stepCountIs(200),
|
|
2004
2025
|
experimental_transform: config?.transform ?? smoothStream(),
|
|
@@ -6109,7 +6130,7 @@ async function snapshot(execute, destination) {
|
|
|
6109
6130
|
const probe = await execute(`[ -d ${shellQuote(destination)} ]`);
|
|
6110
6131
|
if (probe.exitCode !== 0) return /* @__PURE__ */ new Map();
|
|
6111
6132
|
const list = await execute(
|
|
6112
|
-
`find ${shellQuote(destination)} -type f -
|
|
6133
|
+
`find ${shellQuote(destination)} -type f -exec sha256sum {} +`
|
|
6113
6134
|
);
|
|
6114
6135
|
if (list.exitCode !== 0) {
|
|
6115
6136
|
throw new SnapshotFailedError(
|
|
@@ -6574,11 +6595,9 @@ function resolveRealCwd(ctx) {
|
|
|
6574
6595
|
// packages/context/src/lib/sandbox/daytona-sandbox.ts
|
|
6575
6596
|
import "bash-tool";
|
|
6576
6597
|
import { randomUUID } from "node:crypto";
|
|
6577
|
-
import { createRequire } from "node:module";
|
|
6578
6598
|
var DAYTONA_DEFAULT_DESTINATION = "/home/daytona";
|
|
6579
6599
|
var DAYTONA_EXIT_POLL_INTERVAL_MS = 250;
|
|
6580
6600
|
var DAYTONA_EXIT_POLL_TIMEOUT_MS = 3e4;
|
|
6581
|
-
var requireOptional = createRequire(import.meta.url);
|
|
6582
6601
|
var DaytonaSandboxError = class extends Error {
|
|
6583
6602
|
constructor(message2, cause) {
|
|
6584
6603
|
super(message2);
|
|
@@ -6609,28 +6628,28 @@ var DaytonaCommandError = class extends DaytonaSandboxError {
|
|
|
6609
6628
|
};
|
|
6610
6629
|
async function createDaytonaSandbox(options = {}) {
|
|
6611
6630
|
validateDaytonaOptions(options);
|
|
6612
|
-
const
|
|
6631
|
+
const sdk = await importDaytonaSdk();
|
|
6613
6632
|
let client;
|
|
6614
6633
|
try {
|
|
6615
|
-
client = new Daytona(createDaytonaConfig(options));
|
|
6634
|
+
client = new sdk.Daytona(createDaytonaConfig(options));
|
|
6616
6635
|
} catch (error) {
|
|
6617
|
-
|
|
6618
|
-
throw new DaytonaCreationError(err.message, err);
|
|
6636
|
+
throw normalizeDaytonaError(error, sdk);
|
|
6619
6637
|
}
|
|
6620
6638
|
const attached = options.sandboxId !== void 0;
|
|
6621
|
-
const
|
|
6639
|
+
const reuseByName = !attached && options.name !== void 0;
|
|
6640
|
+
const deleteOnDispose = options.deleteOnDispose ?? (!attached && !reuseByName);
|
|
6622
6641
|
let sandbox;
|
|
6623
6642
|
try {
|
|
6624
|
-
|
|
6625
|
-
|
|
6626
|
-
|
|
6627
|
-
|
|
6628
|
-
|
|
6629
|
-
|
|
6643
|
+
if (reuseByName) {
|
|
6644
|
+
sandbox = await acquireReusedSandbox(client, options, sdk);
|
|
6645
|
+
} else if (attached) {
|
|
6646
|
+
sandbox = await client.get(options.sandboxId);
|
|
6647
|
+
await startIfStopped(sandbox, options);
|
|
6648
|
+
} else {
|
|
6649
|
+
sandbox = await createSandbox(client, options);
|
|
6630
6650
|
}
|
|
6631
6651
|
} catch (error) {
|
|
6632
|
-
|
|
6633
|
-
throw new DaytonaCreationError(err.message, err);
|
|
6652
|
+
throw normalizeDaytonaError(error, sdk);
|
|
6634
6653
|
}
|
|
6635
6654
|
return createDaytonaSandboxMethods({
|
|
6636
6655
|
client,
|
|
@@ -6640,15 +6659,39 @@ async function createDaytonaSandbox(options = {}) {
|
|
|
6640
6659
|
deleteTimeout: options.deleteTimeout
|
|
6641
6660
|
});
|
|
6642
6661
|
}
|
|
6662
|
+
async function acquireReusedSandbox(client, options, sdk) {
|
|
6663
|
+
try {
|
|
6664
|
+
const sandbox = await client.get(options.name);
|
|
6665
|
+
await startIfStopped(sandbox, options);
|
|
6666
|
+
return sandbox;
|
|
6667
|
+
} catch (error) {
|
|
6668
|
+
if (!(error instanceof sdk.DaytonaNotFoundError)) {
|
|
6669
|
+
throw error;
|
|
6670
|
+
}
|
|
6671
|
+
return createSandbox(client, options);
|
|
6672
|
+
}
|
|
6673
|
+
}
|
|
6674
|
+
async function startIfStopped(sandbox, options) {
|
|
6675
|
+
if (sandbox.state && sandbox.state !== "started") {
|
|
6676
|
+
await sandbox.start?.(options.startTimeout ?? options.createTimeout);
|
|
6677
|
+
}
|
|
6678
|
+
}
|
|
6679
|
+
function normalizeDaytonaError(error, sdk) {
|
|
6680
|
+
const err = toError(error);
|
|
6681
|
+
if (err instanceof sdk.DaytonaError) {
|
|
6682
|
+
return err;
|
|
6683
|
+
}
|
|
6684
|
+
return new DaytonaCreationError(err.message, err);
|
|
6685
|
+
}
|
|
6643
6686
|
async function importDaytonaSdk() {
|
|
6644
6687
|
try {
|
|
6645
|
-
const mod =
|
|
6688
|
+
const mod = await import("@daytona/sdk");
|
|
6646
6689
|
if (typeof mod.Daytona !== "function") {
|
|
6647
6690
|
throw new DaytonaSandboxError(
|
|
6648
6691
|
"@daytona/sdk did not export a Daytona constructor"
|
|
6649
6692
|
);
|
|
6650
6693
|
}
|
|
6651
|
-
return
|
|
6694
|
+
return mod;
|
|
6652
6695
|
} catch (error) {
|
|
6653
6696
|
if (error instanceof DaytonaSandboxError) {
|
|
6654
6697
|
throw error;
|
|
@@ -6671,7 +6714,7 @@ function createDaytonaConfig(options) {
|
|
|
6671
6714
|
_experimental: options.experimental
|
|
6672
6715
|
});
|
|
6673
6716
|
}
|
|
6674
|
-
function
|
|
6717
|
+
function createSandbox(client, options) {
|
|
6675
6718
|
const base = compactObject({
|
|
6676
6719
|
name: options.name,
|
|
6677
6720
|
user: options.user,
|
|
@@ -6687,18 +6730,24 @@ function createDaytonaParams(options) {
|
|
|
6687
6730
|
networkAllowList: options.networkAllowList,
|
|
6688
6731
|
ephemeral: options.ephemeral
|
|
6689
6732
|
});
|
|
6690
|
-
if (options.image) {
|
|
6691
|
-
|
|
6733
|
+
if (options.image !== void 0) {
|
|
6734
|
+
const params2 = compactObject({
|
|
6692
6735
|
...base,
|
|
6693
6736
|
image: options.image,
|
|
6694
6737
|
resources: options.resources
|
|
6695
6738
|
});
|
|
6739
|
+
return client.create(params2, {
|
|
6740
|
+
timeout: options.createTimeout,
|
|
6741
|
+
onSnapshotCreateLogs: options.onSnapshotCreateLogs
|
|
6742
|
+
});
|
|
6696
6743
|
}
|
|
6697
6744
|
const params = compactObject({
|
|
6698
6745
|
...base,
|
|
6699
6746
|
snapshot: options.snapshot
|
|
6700
6747
|
});
|
|
6701
|
-
return Object.keys(params).length > 0 ? params : void 0
|
|
6748
|
+
return client.create(Object.keys(params).length > 0 ? params : void 0, {
|
|
6749
|
+
timeout: options.createTimeout
|
|
6750
|
+
});
|
|
6702
6751
|
}
|
|
6703
6752
|
function validateDaytonaOptions(options) {
|
|
6704
6753
|
if (options.image && options.snapshot) {
|
|
@@ -8023,6 +8072,16 @@ async function useSandbox(options, fn) {
|
|
|
8023
8072
|
}
|
|
8024
8073
|
}
|
|
8025
8074
|
|
|
8075
|
+
// packages/context/src/lib/sandbox/gcs.ts
|
|
8076
|
+
function gcs(options) {
|
|
8077
|
+
return {
|
|
8078
|
+
type: "bind",
|
|
8079
|
+
hostPath: options.hostPath,
|
|
8080
|
+
containerPath: options.mountPath,
|
|
8081
|
+
readOnly: options.readOnly ?? false
|
|
8082
|
+
};
|
|
8083
|
+
}
|
|
8084
|
+
|
|
8026
8085
|
// packages/context/src/lib/sandbox/installers/package-manager.ts
|
|
8027
8086
|
var PackageInstaller = class extends Installer {
|
|
8028
8087
|
kind;
|
|
@@ -8486,7 +8545,7 @@ function soul() {
|
|
|
8486
8545
|
}
|
|
8487
8546
|
|
|
8488
8547
|
// packages/context/src/lib/store/postgres.store.ts
|
|
8489
|
-
import { createRequire
|
|
8548
|
+
import { createRequire } from "node:module";
|
|
8490
8549
|
|
|
8491
8550
|
// packages/context/src/lib/store/ddl.postgres.ts
|
|
8492
8551
|
function storeDDL(schema) {
|
|
@@ -8598,7 +8657,7 @@ var PostgresContextStore = class _PostgresContextStore extends ContextStore {
|
|
|
8598
8657
|
}
|
|
8599
8658
|
static #requirePg() {
|
|
8600
8659
|
try {
|
|
8601
|
-
const require2 =
|
|
8660
|
+
const require2 = createRequire(import.meta.url);
|
|
8602
8661
|
return require2("pg");
|
|
8603
8662
|
} catch {
|
|
8604
8663
|
throw new Error(
|
|
@@ -9194,7 +9253,7 @@ var PostgresContextStore = class _PostgresContextStore extends ContextStore {
|
|
|
9194
9253
|
};
|
|
9195
9254
|
|
|
9196
9255
|
// packages/context/src/lib/store/sqlserver.store.ts
|
|
9197
|
-
import { createRequire as
|
|
9256
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
9198
9257
|
|
|
9199
9258
|
// packages/context/src/lib/store/ddl.sqlserver.ts
|
|
9200
9259
|
function storeDDL2(schema) {
|
|
@@ -9336,7 +9395,7 @@ var SqlServerContextStore = class _SqlServerContextStore extends ContextStore {
|
|
|
9336
9395
|
}
|
|
9337
9396
|
static #requireMssql() {
|
|
9338
9397
|
try {
|
|
9339
|
-
const require2 =
|
|
9398
|
+
const require2 = createRequire2(import.meta.url);
|
|
9340
9399
|
return require2("mssql");
|
|
9341
9400
|
} catch {
|
|
9342
9401
|
throw new Error(
|
|
@@ -10326,7 +10385,7 @@ function asStaticWordPartText(parts, options = {}) {
|
|
|
10326
10385
|
}
|
|
10327
10386
|
|
|
10328
10387
|
// packages/context/src/lib/stream/postgres-notify-change-source.ts
|
|
10329
|
-
import { createRequire as
|
|
10388
|
+
import { createRequire as createRequire3 } from "node:module";
|
|
10330
10389
|
|
|
10331
10390
|
// packages/context/src/lib/stream/ddl.stream.postgres-notify.ts
|
|
10332
10391
|
var DEFAULT_POSTGRES_STREAM_CHANGES_CHANNEL = "deepagents_stream_changes";
|
|
@@ -10428,7 +10487,7 @@ var PostgresNotifyChangeSource = class _PostgresNotifyChangeSource {
|
|
|
10428
10487
|
}
|
|
10429
10488
|
static #requirePg() {
|
|
10430
10489
|
try {
|
|
10431
|
-
const require2 =
|
|
10490
|
+
const require2 = createRequire3(import.meta.url);
|
|
10432
10491
|
return require2("pg");
|
|
10433
10492
|
} catch {
|
|
10434
10493
|
throw new Error(
|
|
@@ -10683,7 +10742,7 @@ function assertIdentifier(value, label) {
|
|
|
10683
10742
|
}
|
|
10684
10743
|
|
|
10685
10744
|
// packages/context/src/lib/stream/postgres.stream-store.ts
|
|
10686
|
-
import { createRequire as
|
|
10745
|
+
import { createRequire as createRequire4 } from "node:module";
|
|
10687
10746
|
|
|
10688
10747
|
// packages/context/src/lib/stream/ddl.stream.postgres.ts
|
|
10689
10748
|
function postgresStreamDDL(schema) {
|
|
@@ -10757,7 +10816,7 @@ var PostgresStreamStore = class _PostgresStreamStore extends StreamStore {
|
|
|
10757
10816
|
}
|
|
10758
10817
|
static #requirePg() {
|
|
10759
10818
|
try {
|
|
10760
|
-
const require2 =
|
|
10819
|
+
const require2 = createRequire4(import.meta.url);
|
|
10761
10820
|
return require2("pg");
|
|
10762
10821
|
} catch {
|
|
10763
10822
|
throw new Error(
|
|
@@ -11723,6 +11782,7 @@ export {
|
|
|
11723
11782
|
firstN,
|
|
11724
11783
|
fragment,
|
|
11725
11784
|
fromFragment,
|
|
11785
|
+
gcs,
|
|
11726
11786
|
getFragmentData,
|
|
11727
11787
|
getLocaleFromMessage,
|
|
11728
11788
|
getModelsRegistry,
|