deepagentsdk 0.12.0 → 0.14.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.
Files changed (37) hide show
  1. package/dist/adapters/elements/index.cjs +478 -288
  2. package/dist/adapters/elements/index.cjs.map +1 -1
  3. package/dist/adapters/elements/index.d.cts +107 -172
  4. package/dist/adapters/elements/index.d.mts +107 -172
  5. package/dist/adapters/elements/index.mjs +471 -284
  6. package/dist/adapters/elements/index.mjs.map +1 -1
  7. package/dist/{types-4g9UvXal.d.mts → agent-D0bKkNI-.d.mts} +352 -3
  8. package/dist/{types-IulnvhFg.d.cts → agent-DwAj5emJ.d.cts} +352 -3
  9. package/dist/{chunk-CbDLau6x.cjs → chunk-C5azi7Hr.cjs} +33 -0
  10. package/dist/cli/index.cjs +12 -12
  11. package/dist/cli/index.cjs.map +1 -1
  12. package/dist/cli/index.mjs +2 -2
  13. package/dist/cli/index.mjs.map +1 -1
  14. package/dist/{agent-Cuks-Idh.cjs → file-saver-BYPKakT4.cjs} +799 -205
  15. package/dist/file-saver-BYPKakT4.cjs.map +1 -0
  16. package/dist/{agent-CrH-He58.mjs → file-saver-Hj5so3dV.mjs} +793 -199
  17. package/dist/file-saver-Hj5so3dV.mjs.map +1 -0
  18. package/dist/index.cjs +83 -73
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +5 -353
  21. package/dist/index.d.mts +5 -353
  22. package/dist/index.mjs +13 -3
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/{load-B6CA5js_.mjs → load-BBYEnMwz.mjs} +1 -1
  25. package/dist/{load-B6CA5js_.mjs.map → load-BBYEnMwz.mjs.map} +1 -1
  26. package/dist/{load-94gjHorc.mjs → load-BDxe6Cet.mjs} +1 -1
  27. package/dist/{load-79a2H4m0.cjs → load-BrRAKlO6.cjs} +2 -2
  28. package/dist/{load-79a2H4m0.cjs.map → load-BrRAKlO6.cjs.map} +1 -1
  29. package/dist/load-DqllBbDc.cjs +4 -0
  30. package/package.json +1 -1
  31. package/dist/agent-CrH-He58.mjs.map +0 -1
  32. package/dist/agent-Cuks-Idh.cjs.map +0 -1
  33. package/dist/file-saver-BJCqMIb5.mjs +0 -655
  34. package/dist/file-saver-BJCqMIb5.mjs.map +0 -1
  35. package/dist/file-saver-C6O2LAvg.cjs +0 -679
  36. package/dist/file-saver-C6O2LAvg.cjs.map +0 -1
  37. package/dist/load-C2qVmZMp.cjs +0 -3
@@ -1,655 +0,0 @@
1
- import { $ as SYSTEM_REMINDER_FILE_EMPTY, Q as STRING_NOT_FOUND, Z as FILE_NOT_FOUND, mt as DEFAULT_READ_LIMIT } from "./agent-CrH-He58.mjs";
2
- import { spawn } from "child_process";
3
- import { anthropic } from "@ai-sdk/anthropic";
4
- import { openai } from "@ai-sdk/openai";
5
- import { existsSync, mkdirSync, readFileSync, readdirSync, unlinkSync, writeFileSync } from "node:fs";
6
- import { join } from "node:path";
7
-
8
- //#region src/backends/sandbox.ts
9
- /**
10
- * Encode string to base64 for safe shell transmission.
11
- */
12
- function toBase64(str) {
13
- return Buffer.from(str, "utf-8").toString("base64");
14
- }
15
- /**
16
- * Build a Node.js script command with embedded base64 arguments.
17
- * This avoids shell argument parsing issues by embedding values directly in the script.
18
- */
19
- function buildNodeScript(script, args) {
20
- let result = script;
21
- for (const [key, value] of Object.entries(args)) result = result.replace(new RegExp(`__${key}__`, "g"), value);
22
- return `node -e '${result}'`;
23
- }
24
- /**
25
- * Abstract base class for sandbox backends.
26
- *
27
- * Implements all file operations using shell commands via execute().
28
- * Subclasses only need to implement execute() and id.
29
- *
30
- * @example Creating a custom sandbox backend
31
- * ```typescript
32
- * class MyCloudSandbox extends BaseSandbox {
33
- * readonly id = 'my-cloud-123';
34
- *
35
- * async execute(command: string): Promise<ExecuteResponse> {
36
- * // Call your cloud provider's API
37
- * const result = await myCloudApi.runCommand(command);
38
- * return {
39
- * output: result.stdout + result.stderr,
40
- * exitCode: result.exitCode,
41
- * truncated: false,
42
- * };
43
- * }
44
- * }
45
- * ```
46
- */
47
- var BaseSandbox = class {
48
- /**
49
- * List files and directories in a path.
50
- */
51
- async lsInfo(path) {
52
- const pathB64 = toBase64(path);
53
- const result = await this.execute(buildNodeScript(`
54
- const fs = require("fs");
55
- const path = require("path");
56
-
57
- const dirPath = Buffer.from("__PATH__", "base64").toString("utf-8");
58
-
59
- try {
60
- const entries = fs.readdirSync(dirPath, { withFileTypes: true });
61
- for (const entry of entries) {
62
- const fullPath = path.join(dirPath, entry.name);
63
- try {
64
- const stat = fs.statSync(fullPath);
65
- console.log(JSON.stringify({
66
- path: entry.name,
67
- is_dir: entry.isDirectory(),
68
- size: stat.size,
69
- modified_at: stat.mtime.toISOString()
70
- }));
71
- } catch (e) {}
72
- }
73
- } catch (e) {}
74
- `, { PATH: pathB64 }));
75
- const infos = [];
76
- for (const line of result.output.trim().split("\n")) {
77
- if (!line) continue;
78
- try {
79
- const data = JSON.parse(line);
80
- infos.push({
81
- path: data.path,
82
- is_dir: data.is_dir,
83
- size: data.size,
84
- modified_at: data.modified_at
85
- });
86
- } catch {}
87
- }
88
- return infos;
89
- }
90
- /**
91
- * Read file content with line numbers.
92
- */
93
- async read(filePath, offset = 0, limit = DEFAULT_READ_LIMIT) {
94
- const pathB64 = toBase64(filePath);
95
- const script = `
96
- const fs = require("fs");
97
- const filePath = Buffer.from("__PATH__", "base64").toString("utf-8");
98
- const offset = __OFFSET__;
99
- const limit = __LIMIT__;
100
-
101
- if (!fs.existsSync(filePath)) {
102
- console.error("Error: File not found");
103
- process.exit(1);
104
- }
105
-
106
- const stat = fs.statSync(filePath);
107
- if (stat.size === 0) {
108
- console.log("${SYSTEM_REMINDER_FILE_EMPTY}");
109
- process.exit(0);
110
- }
111
-
112
- const content = fs.readFileSync(filePath, "utf-8");
113
- const lines = content.split("\\n");
114
- const selected = lines.slice(offset, offset + limit);
115
-
116
- for (let i = 0; i < selected.length; i++) {
117
- const lineNum = (offset + i + 1).toString().padStart(6, " ");
118
- console.log(lineNum + "\\t" + selected[i]);
119
- }
120
- `;
121
- const result = await this.execute(buildNodeScript(script, {
122
- PATH: pathB64,
123
- OFFSET: String(offset),
124
- LIMIT: String(limit)
125
- }));
126
- if (result.exitCode !== 0) {
127
- if (result.output.includes("Error: File not found")) return FILE_NOT_FOUND(filePath);
128
- return result.output.trim();
129
- }
130
- return result.output.trimEnd();
131
- }
132
- /**
133
- * Read raw file data.
134
- */
135
- async readRaw(filePath) {
136
- const pathB64 = toBase64(filePath);
137
- const result = await this.execute(buildNodeScript(`
138
- const fs = require("fs");
139
- const filePath = Buffer.from("__PATH__", "base64").toString("utf-8");
140
-
141
- if (!fs.existsSync(filePath)) {
142
- console.error("Error: File not found");
143
- process.exit(1);
144
- }
145
-
146
- const stat = fs.statSync(filePath);
147
- const content = fs.readFileSync(filePath, "utf-8");
148
-
149
- console.log(JSON.stringify({
150
- content: content.split("\\n"),
151
- created_at: stat.birthtime.toISOString(),
152
- modified_at: stat.mtime.toISOString()
153
- }));
154
- `, { PATH: pathB64 }));
155
- if (result.exitCode !== 0) throw new Error(`File '${filePath}' not found`);
156
- try {
157
- const data = JSON.parse(result.output.trim());
158
- return {
159
- content: data.content,
160
- created_at: data.created_at,
161
- modified_at: data.modified_at
162
- };
163
- } catch {
164
- throw new Error(`Failed to parse file data for '${filePath}'`);
165
- }
166
- }
167
- /**
168
- * Write content to a new file.
169
- */
170
- async write(filePath, content) {
171
- const pathB64 = toBase64(filePath);
172
- const contentB64 = toBase64(content);
173
- const result = await this.execute(buildNodeScript(`
174
- const fs = require("fs");
175
- const path = require("path");
176
-
177
- const filePath = Buffer.from("__PATH__", "base64").toString("utf-8");
178
- const content = Buffer.from("__CONTENT__", "base64").toString("utf-8");
179
-
180
- if (fs.existsSync(filePath)) {
181
- console.error("Error: File already exists");
182
- process.exit(1);
183
- }
184
-
185
- const dir = path.dirname(filePath);
186
- if (dir && dir !== ".") {
187
- fs.mkdirSync(dir, { recursive: true });
188
- }
189
-
190
- fs.writeFileSync(filePath, content, "utf-8");
191
- `, {
192
- PATH: pathB64,
193
- CONTENT: contentB64
194
- }));
195
- if (result.exitCode !== 0) {
196
- if (result.output.includes("already exists")) return {
197
- success: false,
198
- error: `Cannot write to ${filePath} because it already exists. Read and then make an edit, or write to a new path.`
199
- };
200
- return {
201
- success: false,
202
- error: result.output.trim() || `Failed to write '${filePath}'`
203
- };
204
- }
205
- return {
206
- success: true,
207
- path: filePath
208
- };
209
- }
210
- /**
211
- * Edit a file by replacing string occurrences.
212
- */
213
- async edit(filePath, oldString, newString, replaceAll = false) {
214
- const pathB64 = toBase64(filePath);
215
- const oldB64 = toBase64(oldString);
216
- const newB64 = toBase64(newString);
217
- const result = await this.execute(buildNodeScript(`
218
- const fs = require("fs");
219
-
220
- const filePath = Buffer.from("__PATH__", "base64").toString("utf-8");
221
- const oldStr = Buffer.from("__OLD__", "base64").toString("utf-8");
222
- const newStr = Buffer.from("__NEW__", "base64").toString("utf-8");
223
- const replaceAll = __REPLACE_ALL__;
224
-
225
- if (!fs.existsSync(filePath)) {
226
- console.error("Error: File not found");
227
- process.exit(1);
228
- }
229
-
230
- let content = fs.readFileSync(filePath, "utf-8");
231
- const count = content.split(oldStr).length - 1;
232
-
233
- if (count === 0) {
234
- process.exit(2);
235
- }
236
- if (count > 1 && !replaceAll) {
237
- process.exit(3);
238
- }
239
-
240
- if (replaceAll) {
241
- content = content.split(oldStr).join(newStr);
242
- } else {
243
- content = content.replace(oldStr, newStr);
244
- }
245
-
246
- fs.writeFileSync(filePath, content, "utf-8");
247
- console.log(count);
248
- `, {
249
- PATH: pathB64,
250
- OLD: oldB64,
251
- NEW: newB64,
252
- REPLACE_ALL: String(replaceAll)
253
- }));
254
- if (result.exitCode === 1) return {
255
- success: false,
256
- error: FILE_NOT_FOUND(filePath)
257
- };
258
- if (result.exitCode === 2) return {
259
- success: false,
260
- error: STRING_NOT_FOUND(filePath, oldString)
261
- };
262
- if (result.exitCode === 3) return {
263
- success: false,
264
- error: `Error: String '${oldString}' appears multiple times. Use replaceAll=true to replace all occurrences.`
265
- };
266
- return {
267
- success: true,
268
- path: filePath,
269
- occurrences: parseInt(result.output.trim(), 10) || 1
270
- };
271
- }
272
- /**
273
- * Search for pattern in files.
274
- */
275
- async grepRaw(pattern, path = "/", glob = null) {
276
- const patternB64 = toBase64(pattern);
277
- const pathB64 = toBase64(path);
278
- const globB64 = glob ? toBase64(glob) : toBase64("**/*");
279
- const result = await this.execute(buildNodeScript(`
280
- const fs = require("fs");
281
- const path = require("path");
282
-
283
- const pattern = Buffer.from("__PATTERN__", "base64").toString("utf-8");
284
- const basePath = Buffer.from("__PATH__", "base64").toString("utf-8");
285
- const fileGlob = Buffer.from("__GLOB__", "base64").toString("utf-8");
286
-
287
- function walkDir(dir, baseDir) {
288
- const results = [];
289
- try {
290
- const entries = fs.readdirSync(dir, { withFileTypes: true });
291
- for (const entry of entries) {
292
- const fullPath = path.join(dir, entry.name);
293
- const relativePath = path.relative(baseDir, fullPath);
294
-
295
- if (entry.isDirectory()) {
296
- results.push(...walkDir(fullPath, baseDir));
297
- } else {
298
- results.push(relativePath);
299
- }
300
- }
301
- } catch (e) {}
302
- return results;
303
- }
304
-
305
- function matchGlob(filepath, pattern) {
306
- if (!pattern || pattern === "**/*") return true;
307
- const regex = pattern
308
- .replace(/\\./g, "\\\\.")
309
- .replace(/\\*\\*/g, "<<<GLOBSTAR>>>")
310
- .replace(/\\*/g, "[^/]*")
311
- .replace(/<<<GLOBSTAR>>>/g, ".*")
312
- .replace(/\\?/g, ".");
313
- return new RegExp("^" + regex + "$").test(filepath);
314
- }
315
-
316
- const allFiles = walkDir(basePath, basePath);
317
- const files = allFiles.filter(f => matchGlob(f, fileGlob)).sort();
318
-
319
- for (const file of files) {
320
- try {
321
- const fullPath = path.join(basePath, file);
322
- const content = fs.readFileSync(fullPath, "utf-8");
323
- const lines = content.split("\\n");
324
-
325
- for (let i = 0; i < lines.length; i++) {
326
- if (lines[i].includes(pattern)) {
327
- console.log(JSON.stringify({
328
- path: file,
329
- line: i + 1,
330
- text: lines[i]
331
- }));
332
- }
333
- }
334
- } catch (e) {}
335
- }
336
- `, {
337
- PATTERN: patternB64,
338
- PATH: pathB64,
339
- GLOB: globB64
340
- }));
341
- const matches = [];
342
- for (const line of result.output.trim().split("\n")) {
343
- if (!line) continue;
344
- try {
345
- const data = JSON.parse(line);
346
- matches.push({
347
- path: data.path,
348
- line: data.line,
349
- text: data.text
350
- });
351
- } catch {}
352
- }
353
- return matches;
354
- }
355
- /**
356
- * Find files matching glob pattern.
357
- */
358
- async globInfo(pattern, path = "/") {
359
- const pathB64 = toBase64(path);
360
- const patternB64 = toBase64(pattern);
361
- const result = await this.execute(buildNodeScript(`
362
- const fs = require("fs");
363
- const path = require("path");
364
-
365
- const basePath = Buffer.from("__PATH__", "base64").toString("utf-8");
366
- const pattern = Buffer.from("__PATTERN__", "base64").toString("utf-8");
367
-
368
- function walkDir(dir, baseDir) {
369
- const results = [];
370
- try {
371
- const entries = fs.readdirSync(dir, { withFileTypes: true });
372
- for (const entry of entries) {
373
- const fullPath = path.join(dir, entry.name);
374
- const relativePath = path.relative(baseDir, fullPath);
375
-
376
- if (entry.isDirectory()) {
377
- results.push(...walkDir(fullPath, baseDir));
378
- } else {
379
- results.push(relativePath);
380
- }
381
- }
382
- } catch (e) {}
383
- return results;
384
- }
385
-
386
- function matchGlob(filepath, pattern) {
387
- const regex = pattern
388
- .replace(/\\./g, "\\\\.")
389
- .replace(/\\*\\*/g, "<<<GLOBSTAR>>>")
390
- .replace(/\\*/g, "[^/]*")
391
- .replace(/<<<GLOBSTAR>>>/g, ".*")
392
- .replace(/\\?/g, ".");
393
- return new RegExp("^" + regex + "$").test(filepath);
394
- }
395
-
396
- const allFiles = walkDir(basePath, basePath);
397
- const matches = allFiles.filter(f => matchGlob(f, pattern)).sort();
398
-
399
- for (const m of matches) {
400
- try {
401
- const fullPath = path.join(basePath, m);
402
- const stat = fs.statSync(fullPath);
403
- console.log(JSON.stringify({
404
- path: m,
405
- is_dir: stat.isDirectory(),
406
- size: stat.size,
407
- modified_at: stat.mtime.toISOString()
408
- }));
409
- } catch (e) {}
410
- }
411
- `, {
412
- PATH: pathB64,
413
- PATTERN: patternB64
414
- }));
415
- const infos = [];
416
- for (const line of result.output.trim().split("\n")) {
417
- if (!line) continue;
418
- try {
419
- const data = JSON.parse(line);
420
- infos.push({
421
- path: data.path,
422
- is_dir: data.is_dir,
423
- size: data.size,
424
- modified_at: data.modified_at
425
- });
426
- } catch {}
427
- }
428
- return infos;
429
- }
430
- };
431
-
432
- //#endregion
433
- //#region src/backends/local-sandbox.ts
434
- /**
435
- * LocalSandbox: Execute commands locally using child_process.
436
- *
437
- * Useful for local development and testing without cloud sandboxes.
438
- * All file operations are inherited from BaseSandbox and executed
439
- * via shell commands in the local filesystem.
440
- */
441
- /**
442
- * Local sandbox that executes commands using Node.js child_process.
443
- *
444
- * All commands are executed in a bash shell with the specified working directory.
445
- * Inherits all file operations (read, write, edit, ls, grep, glob) from BaseSandbox.
446
- *
447
- * @example Basic usage
448
- * ```typescript
449
- * import { LocalSandbox } from 'deepagentsdk';
450
- *
451
- * const sandbox = new LocalSandbox({ cwd: './workspace' });
452
- *
453
- * // Execute commands
454
- * const result = await sandbox.execute('ls -la');
455
- * console.log(result.output);
456
- *
457
- * // File operations
458
- * await sandbox.write('./src/index.ts', 'console.log("hello")');
459
- * const content = await sandbox.read('./src/index.ts');
460
- * ```
461
- *
462
- * @example With timeout and environment
463
- * ```typescript
464
- * const sandbox = new LocalSandbox({
465
- * cwd: './workspace',
466
- * timeout: 60000, // 60 seconds
467
- * env: {
468
- * NODE_ENV: 'development',
469
- * DEBUG: '*',
470
- * },
471
- * });
472
- * ```
473
- *
474
- * @example Error handling
475
- * ```typescript
476
- * const result = await sandbox.execute('npm test');
477
- * if (result.exitCode !== 0) {
478
- * console.error('Tests failed:', result.output);
479
- * }
480
- * ```
481
- */
482
- var LocalSandbox = class extends BaseSandbox {
483
- cwd;
484
- timeout;
485
- env;
486
- maxOutputSize;
487
- _id;
488
- /**
489
- * Create a new LocalSandbox instance.
490
- *
491
- * @param options - Configuration options for the sandbox
492
- */
493
- constructor(options = {}) {
494
- super();
495
- this.cwd = options.cwd || process.cwd();
496
- this.timeout = options.timeout || 3e4;
497
- this.env = options.env || {};
498
- this.maxOutputSize = options.maxOutputSize || 1024 * 1024;
499
- this._id = `local-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
500
- }
501
- /**
502
- * Unique identifier for this sandbox instance.
503
- * Format: `local-{timestamp}-{random}`
504
- */
505
- get id() {
506
- return this._id;
507
- }
508
- /**
509
- * Execute a shell command in the local filesystem.
510
- *
511
- * Commands are executed using bash with the configured working directory
512
- * and environment variables. Output is captured from both stdout and stderr.
513
- *
514
- * @param command - Shell command to execute
515
- * @returns ExecuteResponse with output, exit code, and truncation status
516
- *
517
- * @example
518
- * ```typescript
519
- * const result = await sandbox.execute('echo "Hello" && ls -la');
520
- * console.log(result.output);
521
- * console.log('Exit code:', result.exitCode);
522
- * ```
523
- */
524
- async execute(command) {
525
- return new Promise((resolve) => {
526
- const child = spawn("bash", ["-c", command], {
527
- cwd: this.cwd,
528
- env: {
529
- ...process.env,
530
- ...this.env
531
- },
532
- timeout: this.timeout
533
- });
534
- let output = "";
535
- let truncated = false;
536
- child.stdout.on("data", (data) => {
537
- if (output.length < this.maxOutputSize) output += data.toString();
538
- else truncated = true;
539
- });
540
- child.stderr.on("data", (data) => {
541
- if (output.length < this.maxOutputSize) output += data.toString();
542
- else truncated = true;
543
- });
544
- child.on("close", (code) => {
545
- resolve({
546
- output,
547
- exitCode: code,
548
- truncated
549
- });
550
- });
551
- child.on("error", (err) => {
552
- resolve({
553
- output: `Error: ${err.message}`,
554
- exitCode: 1,
555
- truncated: false
556
- });
557
- });
558
- });
559
- }
560
- };
561
-
562
- //#endregion
563
- //#region src/utils/model-parser.ts
564
- /**
565
- * Utility to parse model strings into LanguageModel instances.
566
- * Provides backward compatibility for CLI and other string-based model specifications.
567
- */
568
- /**
569
- * Parse a model string into a LanguageModel instance.
570
- *
571
- * Supports formats like:
572
- * - "anthropic/claude-sonnet-4-20250514"
573
- * - "openai/gpt-4o"
574
- * - "claude-sonnet-4-20250514" (defaults to Anthropic)
575
- *
576
- * @param modelString - The model string to parse
577
- * @returns A LanguageModel instance
578
- *
579
- * @example
580
- * ```typescript
581
- * const model = parseModelString("anthropic/claude-sonnet-4-20250514");
582
- * const agent = createDeepAgent({ model });
583
- * ```
584
- */
585
- function parseModelString(modelString) {
586
- const [provider, modelName] = modelString.split("/");
587
- if (provider === "anthropic") return anthropic(modelName || "claude-sonnet-4-20250514");
588
- else if (provider === "openai") return openai(modelName || "gpt-5-mini");
589
- return anthropic(modelString);
590
- }
591
-
592
- //#endregion
593
- //#region src/checkpointer/file-saver.ts
594
- /**
595
- * File-based checkpoint saver for local development.
596
- */
597
- /**
598
- * File-based checkpoint saver.
599
- *
600
- * Stores checkpoints as JSON files in a directory. Each thread gets
601
- * its own file named `{threadId}.json`.
602
- *
603
- * @example
604
- * ```typescript
605
- * const saver = new FileSaver({ dir: './.checkpoints' });
606
- * const agent = createDeepAgent({
607
- * model: anthropic('claude-sonnet-4-20250514'),
608
- * checkpointer: saver,
609
- * });
610
- * ```
611
- */
612
- var FileSaver = class {
613
- dir;
614
- constructor(options) {
615
- this.dir = options.dir;
616
- if (!existsSync(this.dir)) mkdirSync(this.dir, { recursive: true });
617
- }
618
- getFilePath(threadId) {
619
- const safeId = threadId.replace(/[^a-zA-Z0-9_-]/g, "_");
620
- return join(this.dir, `${safeId}.json`);
621
- }
622
- async save(checkpoint) {
623
- const filePath = this.getFilePath(checkpoint.threadId);
624
- const data = {
625
- ...checkpoint,
626
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
627
- };
628
- writeFileSync(filePath, JSON.stringify(data, null, 2), "utf-8");
629
- }
630
- async load(threadId) {
631
- const filePath = this.getFilePath(threadId);
632
- if (!existsSync(filePath)) return;
633
- try {
634
- const content = readFileSync(filePath, "utf-8");
635
- return JSON.parse(content);
636
- } catch {
637
- return;
638
- }
639
- }
640
- async list() {
641
- if (!existsSync(this.dir)) return [];
642
- return readdirSync(this.dir).filter((f) => f.endsWith(".json")).map((f) => f.replace(".json", ""));
643
- }
644
- async delete(threadId) {
645
- const filePath = this.getFilePath(threadId);
646
- if (existsSync(filePath)) unlinkSync(filePath);
647
- }
648
- async exists(threadId) {
649
- return existsSync(this.getFilePath(threadId));
650
- }
651
- };
652
-
653
- //#endregion
654
- export { BaseSandbox as i, parseModelString as n, LocalSandbox as r, FileSaver as t };
655
- //# sourceMappingURL=file-saver-BJCqMIb5.mjs.map