sandlot 0.1.4 → 0.2.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.
Files changed (115) hide show
  1. package/dist/browser/bundler.d.ts +68 -0
  2. package/dist/browser/bundler.d.ts.map +1 -0
  3. package/dist/browser/executor.d.ts +46 -0
  4. package/dist/browser/executor.d.ts.map +1 -0
  5. package/dist/browser/index.d.ts +9 -0
  6. package/dist/browser/index.d.ts.map +1 -0
  7. package/dist/browser/index.js +2690 -0
  8. package/dist/browser/preset.d.ts +63 -0
  9. package/dist/browser/preset.d.ts.map +1 -0
  10. package/dist/commands/index.d.ts +20 -11
  11. package/dist/commands/index.d.ts.map +1 -1
  12. package/dist/commands/types.d.ts +37 -130
  13. package/dist/commands/types.d.ts.map +1 -1
  14. package/dist/core/bundler-utils.d.ts +142 -0
  15. package/dist/core/bundler-utils.d.ts.map +1 -0
  16. package/dist/core/esm-types-resolver.d.ts +125 -0
  17. package/dist/core/esm-types-resolver.d.ts.map +1 -0
  18. package/dist/core/executor.d.ts +35 -0
  19. package/dist/core/executor.d.ts.map +1 -0
  20. package/dist/{fs.d.ts → core/fs.d.ts} +27 -29
  21. package/dist/core/fs.d.ts.map +1 -0
  22. package/dist/core/sandbox.d.ts +30 -0
  23. package/dist/core/sandbox.d.ts.map +1 -0
  24. package/dist/core/sandlot.d.ts +30 -0
  25. package/dist/core/sandlot.d.ts.map +1 -0
  26. package/dist/core/shared-module-registry.d.ts +46 -0
  27. package/dist/core/shared-module-registry.d.ts.map +1 -0
  28. package/dist/core/typechecker.d.ts +60 -0
  29. package/dist/core/typechecker.d.ts.map +1 -0
  30. package/dist/index.d.ts +11 -16
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +1398 -2010
  33. package/dist/node/bundler.d.ts +48 -0
  34. package/dist/node/bundler.d.ts.map +1 -0
  35. package/dist/node/executor.d.ts +48 -0
  36. package/dist/node/executor.d.ts.map +1 -0
  37. package/dist/node/index.d.ts +9 -0
  38. package/dist/node/index.d.ts.map +1 -0
  39. package/dist/node/index.js +2644 -0
  40. package/dist/node/preset.d.ts +62 -0
  41. package/dist/node/preset.d.ts.map +1 -0
  42. package/dist/types.d.ts +528 -0
  43. package/dist/types.d.ts.map +1 -0
  44. package/package.json +16 -6
  45. package/src/browser/bundler.ts +294 -0
  46. package/src/browser/executor.ts +71 -0
  47. package/src/browser/index.ts +57 -0
  48. package/src/browser/preset.ts +179 -0
  49. package/src/commands/index.ts +498 -37
  50. package/src/commands/types.ts +117 -145
  51. package/src/core/bundler-utils.ts +630 -0
  52. package/src/core/esm-types-resolver.ts +432 -0
  53. package/src/core/executor.ts +161 -0
  54. package/src/{fs.ts → core/fs.ts} +59 -37
  55. package/src/core/sandbox.ts +624 -0
  56. package/src/core/sandlot.ts +77 -0
  57. package/src/core/shared-module-registry.ts +138 -0
  58. package/src/core/typechecker.ts +609 -0
  59. package/src/index.ts +106 -139
  60. package/src/node/bundler.ts +194 -0
  61. package/src/node/executor.ts +87 -0
  62. package/src/node/index.ts +39 -0
  63. package/src/node/preset.ts +178 -0
  64. package/src/types.ts +672 -0
  65. package/README.md +0 -243
  66. package/dist/build-emitter.d.ts +0 -47
  67. package/dist/build-emitter.d.ts.map +0 -1
  68. package/dist/builder.d.ts +0 -370
  69. package/dist/builder.d.ts.map +0 -1
  70. package/dist/bundler.d.ts +0 -152
  71. package/dist/bundler.d.ts.map +0 -1
  72. package/dist/commands/compile.d.ts +0 -13
  73. package/dist/commands/compile.d.ts.map +0 -1
  74. package/dist/commands/packages.d.ts +0 -17
  75. package/dist/commands/packages.d.ts.map +0 -1
  76. package/dist/commands/run.d.ts +0 -40
  77. package/dist/commands/run.d.ts.map +0 -1
  78. package/dist/commands.d.ts +0 -179
  79. package/dist/commands.d.ts.map +0 -1
  80. package/dist/fs.d.ts.map +0 -1
  81. package/dist/internal.d.ts +0 -79
  82. package/dist/internal.d.ts.map +0 -1
  83. package/dist/internal.js +0 -1942
  84. package/dist/loader.d.ts +0 -164
  85. package/dist/loader.d.ts.map +0 -1
  86. package/dist/packages.d.ts +0 -199
  87. package/dist/packages.d.ts.map +0 -1
  88. package/dist/runner.d.ts +0 -314
  89. package/dist/runner.d.ts.map +0 -1
  90. package/dist/sandbox-manager.d.ts +0 -261
  91. package/dist/sandbox-manager.d.ts.map +0 -1
  92. package/dist/sandbox.d.ts +0 -267
  93. package/dist/sandbox.d.ts.map +0 -1
  94. package/dist/shared-modules.d.ts +0 -148
  95. package/dist/shared-modules.d.ts.map +0 -1
  96. package/dist/shared-resources.d.ts +0 -102
  97. package/dist/shared-resources.d.ts.map +0 -1
  98. package/dist/ts-libs.d.ts +0 -85
  99. package/dist/ts-libs.d.ts.map +0 -1
  100. package/dist/typechecker.d.ts +0 -127
  101. package/dist/typechecker.d.ts.map +0 -1
  102. package/src/build-emitter.ts +0 -64
  103. package/src/builder.ts +0 -498
  104. package/src/bundler.ts +0 -575
  105. package/src/commands/compile.ts +0 -236
  106. package/src/commands/packages.ts +0 -154
  107. package/src/commands/run.ts +0 -245
  108. package/src/internal.ts +0 -119
  109. package/src/loader.ts +0 -229
  110. package/src/packages.ts +0 -936
  111. package/src/sandbox.ts +0 -398
  112. package/src/shared-modules.ts +0 -280
  113. package/src/shared-resources.ts +0 -166
  114. package/src/ts-libs.ts +0 -218
  115. package/src/typechecker.ts +0 -635
package/dist/loader.d.ts DELETED
@@ -1,164 +0,0 @@
1
- /**
2
- * Module loader utilities for Sandlot bundles.
3
- *
4
- * Takes a BundleResult and turns it into usable JavaScript exports.
5
- * No external dependencies - just the basics for loading compiled code.
6
- *
7
- * @example
8
- * ```ts
9
- * // Capture the bundle via onBuild callback
10
- * let buildResult: BundleResult | null = null;
11
- * const unsubscribe = sandbox.onBuild((result) => {
12
- * buildResult = result;
13
- * });
14
- *
15
- * const cmd = await sandbox.bash.exec("build /src/index.ts");
16
- * if (cmd.exitCode === 0 && buildResult) {
17
- * // Load all exports
18
- * const module = await loadModule<{ add: (a: number, b: number) => number }>(buildResult);
19
- * console.log(module.add(1, 2)); // 3
20
- *
21
- * // Load a specific export
22
- * const add = await loadExport<(a: number, b: number) => number>(buildResult, "add");
23
- * console.log(add(1, 2)); // 3
24
- * }
25
- * unsubscribe();
26
- * ```
27
- */
28
- import type { BundleResult } from "./bundler";
29
- /**
30
- * Error thrown when loading a module fails
31
- */
32
- export declare class ModuleLoadError extends Error {
33
- constructor(message: string, cause?: unknown);
34
- }
35
- /**
36
- * Error thrown when an expected export is not found
37
- */
38
- export declare class ExportNotFoundError extends Error {
39
- readonly exportName: string;
40
- readonly availableExports: string[];
41
- constructor(exportName: string, availableExports: string[]);
42
- }
43
- /**
44
- * Create a blob URL for a bundle that can be dynamically imported.
45
- * Remember to call `revokeModuleUrl()` when done to free memory.
46
- *
47
- * @param result - The bundle result from a successful build
48
- * @returns A blob URL that can be passed to `import()`
49
- *
50
- * @example
51
- * ```ts
52
- * const url = createModuleUrl(buildResult);
53
- * try {
54
- * const module = await import(url);
55
- * console.log(module.default);
56
- * } finally {
57
- * revokeModuleUrl(url);
58
- * }
59
- * ```
60
- */
61
- export declare function createModuleUrl(result: BundleResult): string;
62
- /**
63
- * Revoke a blob URL created by `createModuleUrl()`.
64
- * This frees the memory associated with the blob.
65
- *
66
- * @param url - The blob URL to revoke
67
- */
68
- export declare function revokeModuleUrl(url: string): void;
69
- /**
70
- * Load all exports from a bundle result.
71
- *
72
- * @typeParam T - The expected shape of the module's exports
73
- * @param result - The bundle result from a successful build
74
- * @returns A promise that resolves to the module's exports
75
- * @throws {ModuleLoadError} If the module fails to load
76
- *
77
- * @example
78
- * ```ts
79
- * interface MyModule {
80
- * add: (a: number, b: number) => number;
81
- * multiply: (a: number, b: number) => number;
82
- * }
83
- *
84
- * const module = await loadModule<MyModule>(buildResult);
85
- * console.log(module.add(2, 3)); // 5
86
- * console.log(module.multiply(2, 3)); // 6
87
- * ```
88
- */
89
- export declare function loadModule<T = Record<string, unknown>>(result: BundleResult): Promise<T>;
90
- /**
91
- * Load a specific named export from a bundle result.
92
- *
93
- * @typeParam T - The expected type of the export
94
- * @param result - The bundle result from a successful build
95
- * @param exportName - The name of the export to retrieve (use "default" for default export)
96
- * @returns A promise that resolves to the export's value
97
- * @throws {ModuleLoadError} If the module fails to load
98
- * @throws {ExportNotFoundError} If the export doesn't exist
99
- *
100
- * @example
101
- * ```ts
102
- * // Load a named export
103
- * const add = await loadExport<(a: number, b: number) => number>(
104
- * buildResult,
105
- * "add"
106
- * );
107
- * console.log(add(2, 3)); // 5
108
- *
109
- * // Load the default export
110
- * const Calculator = await loadExport<typeof Calculator>(
111
- * buildResult,
112
- * "default"
113
- * );
114
- * ```
115
- */
116
- export declare function loadExport<T = unknown>(result: BundleResult, exportName?: string): Promise<T>;
117
- /**
118
- * Load the default export from a bundle result.
119
- * Convenience wrapper around `loadExport(result, "default")`.
120
- *
121
- * @typeParam T - The expected type of the default export
122
- * @param result - The bundle result from a successful build
123
- * @returns A promise that resolves to the default export
124
- * @throws {ModuleLoadError} If the module fails to load
125
- * @throws {ExportNotFoundError} If there is no default export
126
- *
127
- * @example
128
- * ```ts
129
- * // For a module that does: export default function add(a, b) { return a + b; }
130
- * const add = await loadDefault<(a: number, b: number) => number>(buildResult);
131
- * console.log(add(2, 3)); // 5
132
- * ```
133
- */
134
- export declare function loadDefault<T = unknown>(result: BundleResult): Promise<T>;
135
- /**
136
- * Get a list of export names from a bundle result.
137
- * Useful for introspection or debugging.
138
- *
139
- * @param result - The bundle result from a successful build
140
- * @returns A promise that resolves to an array of export names
141
- *
142
- * @example
143
- * ```ts
144
- * const exports = await getExportNames(buildResult);
145
- * console.log(exports); // ["add", "multiply", "default"]
146
- * ```
147
- */
148
- export declare function getExportNames(result: BundleResult): Promise<string[]>;
149
- /**
150
- * Check if a bundle has a specific export.
151
- *
152
- * @param result - The bundle result from a successful build
153
- * @param exportName - The name of the export to check for
154
- * @returns A promise that resolves to true if the export exists
155
- *
156
- * @example
157
- * ```ts
158
- * if (await hasExport(buildResult, "add")) {
159
- * const add = await loadExport(buildResult, "add");
160
- * }
161
- * ```
162
- */
163
- export declare function hasExport(result: BundleResult, exportName: string): Promise<boolean>;
164
- //# sourceMappingURL=loader.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9C;;GAEG;AACH,qBAAa,eAAgB,SAAQ,KAAK;gBAC5B,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAI7C;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;aAE1B,UAAU,EAAE,MAAM;aAClB,gBAAgB,EAAE,MAAM,EAAE;gBAD1B,UAAU,EAAE,MAAM,EAClB,gBAAgB,EAAE,MAAM,EAAE;CAQ7C;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAG5D;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEjD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,UAAU,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC1D,MAAM,EAAE,YAAY,GACnB,OAAO,CAAC,CAAC,CAAC,CAcZ;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,UAAU,CAAC,CAAC,GAAG,OAAO,EAC1C,MAAM,EAAE,YAAY,EACpB,UAAU,GAAE,MAAkB,GAC7B,OAAO,CAAC,CAAC,CAAC,CAWZ;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,WAAW,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,CAAC,CAAC,CAE/E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,cAAc,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAG5E;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,SAAS,CAC7B,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,OAAO,CAAC,CAGlB"}
@@ -1,199 +0,0 @@
1
- /**
2
- * Package management for sandbox environments.
3
- *
4
- * Provides npm-like package installation using esm.sh CDN:
5
- * - Fetches TypeScript type definitions for editor/typecheck support
6
- * - Stores installed versions in package.json
7
- * - Resolves bare imports to CDN URLs at bundle time
8
- * - Supports @types/* packages (fetches package content as types)
9
- * - Supports subpath exports (react-dom/client, react/jsx-runtime)
10
- *
11
- * @example
12
- * ```ts
13
- * // Install a package
14
- * const result = await installPackage(fs, "react");
15
- * // result: { name: "react", version: "18.2.0", typesInstalled: true }
16
- *
17
- * // Get installed packages
18
- * const manifest = await getPackageManifest(fs);
19
- * // manifest.dependencies: { "react": "18.2.0" }
20
- *
21
- * // Resolve import to CDN URL
22
- * const url = resolveToEsmUrl("react", "18.2.0");
23
- * // url: "https://esm.sh/react@18.2.0"
24
- * ```
25
- */
26
- import type { IFileSystem } from "just-bash/browser";
27
- /**
28
- * Package manifest (subset of package.json)
29
- */
30
- export interface PackageManifest {
31
- dependencies: Record<string, string>;
32
- }
33
- /**
34
- * Cache for storing fetched type definitions.
35
- * Used to avoid redundant network fetches when multiple sandboxes
36
- * install the same packages.
37
- */
38
- export interface TypesCache {
39
- /**
40
- * Get cached type definitions for a package version.
41
- * Returns null if not cached.
42
- */
43
- get(name: string, version: string): Map<string, string> | null;
44
- /**
45
- * Store type definitions in the cache.
46
- */
47
- set(name: string, version: string, types: Map<string, string>): void;
48
- /**
49
- * Check if a package version is cached.
50
- */
51
- has(name: string, version: string): boolean;
52
- /**
53
- * Remove a package version from the cache.
54
- */
55
- delete(name: string, version: string): boolean;
56
- /**
57
- * Clear all cached entries.
58
- */
59
- clear(): void;
60
- }
61
- /**
62
- * In-memory implementation of TypesCache.
63
- * Suitable for sharing across multiple sandboxes within a session.
64
- */
65
- export declare class InMemoryTypesCache implements TypesCache {
66
- private cache;
67
- private key;
68
- get(name: string, version: string): Map<string, string> | null;
69
- set(name: string, version: string, types: Map<string, string>): void;
70
- has(name: string, version: string): boolean;
71
- delete(name: string, version: string): boolean;
72
- clear(): void;
73
- /**
74
- * Get the number of cached packages (for diagnostics).
75
- */
76
- get size(): number;
77
- }
78
- /**
79
- * Result of installing a package
80
- */
81
- export interface InstallResult {
82
- /** Package name */
83
- name: string;
84
- /** Resolved version */
85
- version: string;
86
- /** Whether type definitions were installed */
87
- typesInstalled: boolean;
88
- /** Number of type definition files installed */
89
- typeFilesCount: number;
90
- /** Error message if types failed (but package still usable) */
91
- typesError?: string;
92
- /** Whether types were loaded from cache */
93
- fromCache?: boolean;
94
- }
95
- /**
96
- * Options for installing a package
97
- */
98
- export interface InstallOptions {
99
- /**
100
- * Cache to use for storing/retrieving type definitions.
101
- * When provided, avoids redundant network fetches for packages
102
- * that have already been installed in other sandboxes.
103
- */
104
- cache?: TypesCache;
105
- }
106
- /**
107
- * Parse package specifier into name and version
108
- * Examples:
109
- * "react" -> { name: "react", version: undefined }
110
- * "react@18" -> { name: "react", version: "18" }
111
- * "@tanstack/react-query@5" -> { name: "@tanstack/react-query", version: "5" }
112
- */
113
- export declare function parsePackageSpec(spec: string): {
114
- name: string;
115
- version?: string;
116
- };
117
- /**
118
- * Read the package manifest from the filesystem
119
- */
120
- export declare function getPackageManifest(fs: IFileSystem): Promise<PackageManifest>;
121
- /**
122
- * Install a package from npm via esm.sh
123
- *
124
- * This fetches type definitions and stores them in the virtual filesystem,
125
- * then updates package.json with the installed version.
126
- *
127
- * Special handling:
128
- * - @types/* packages: Fetches package content directly as types
129
- * - Known packages (react, react-dom): Auto-fetches subpath types
130
- *
131
- * @param fs - The virtual filesystem
132
- * @param packageSpec - Package name with optional version (e.g., "react", "lodash@4")
133
- * @returns Install result with version and type info
134
- *
135
- * @example
136
- * ```ts
137
- * // Install latest version
138
- * await installPackage(fs, "react");
139
- *
140
- * // Install specific version
141
- * await installPackage(fs, "lodash@4.17.21");
142
- *
143
- * // Install scoped package
144
- * await installPackage(fs, "@tanstack/react-query@5");
145
- *
146
- * // Install @types package
147
- * await installPackage(fs, "@types/lodash");
148
- * ```
149
- */
150
- export declare function installPackage(fs: IFileSystem, packageSpec: string, options?: InstallOptions): Promise<InstallResult>;
151
- /**
152
- * Uninstall a package
153
- *
154
- * Removes the package from package.json and deletes type definitions.
155
- */
156
- export declare function uninstallPackage(fs: IFileSystem, packageName: string): Promise<boolean>;
157
- /**
158
- * Resolve a bare import to an esm.sh URL
159
- *
160
- * @param importPath - The import path (e.g., "react", "lodash/debounce")
161
- * @param installedPackages - Map of package name to version
162
- * @returns The CDN URL, or null if package not installed
163
- *
164
- * @example
165
- * ```ts
166
- * const packages = { "react": "18.2.0", "lodash-es": "4.17.21" };
167
- *
168
- * resolveToEsmUrl("react", packages);
169
- * // "https://esm.sh/react@18.2.0"
170
- *
171
- * resolveToEsmUrl("lodash-es/debounce", packages);
172
- * // "https://esm.sh/lodash-es@4.17.21/debounce"
173
- *
174
- * resolveToEsmUrl("unknown", packages);
175
- * // null
176
- * ```
177
- */
178
- export declare function resolveToEsmUrl(importPath: string, installedPackages: Record<string, string>): string | null;
179
- /**
180
- * Parse an import path into package name and subpath
181
- *
182
- * @example
183
- * parseImportPath("react") // { packageName: "react", subpath: undefined }
184
- * parseImportPath("lodash/debounce") // { packageName: "lodash", subpath: "debounce" }
185
- * parseImportPath("@tanstack/react-query") // { packageName: "@tanstack/react-query", subpath: undefined }
186
- * parseImportPath("@tanstack/react-query/devtools") // { packageName: "@tanstack/react-query", subpath: "devtools" }
187
- */
188
- export declare function parseImportPath(importPath: string): {
189
- packageName: string;
190
- subpath?: string;
191
- };
192
- /**
193
- * List all installed packages
194
- */
195
- export declare function listPackages(fs: IFileSystem): Promise<Array<{
196
- name: string;
197
- version: string;
198
- }>>;
199
- //# sourceMappingURL=packages.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"packages.d.ts","sourceRoot":"","sources":["../src/packages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAgBrD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC;AAED;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB;;;OAGG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;IAE/D;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;IAErE;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;IAE5C;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;IAE/C;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;CACf;AAED;;;GAGG;AACH,qBAAa,kBAAmB,YAAW,UAAU;IACnD,OAAO,CAAC,KAAK,CAA0C;IAEvD,OAAO,CAAC,GAAG;IAIX,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;IAI9D,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,MAA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D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,MAAM,EAClB,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACxC,MAAM,GAAG,IAAI,CAWf;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG;IACnD,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAsBA;AAED;;GAEG;AACH,wBAAsB,YAAY,CAChC,EAAE,EAAE,WAAW,GACd,OAAO,CAAC,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,CAMnD"}
package/dist/runner.d.ts DELETED
@@ -1,314 +0,0 @@
1
- /**
2
- * High-level runner for sandbox-based agent workflows.
3
- *
4
- * Provides simple wrappers that handle sandbox creation and build result capture,
5
- * letting the caller focus on their agent logic.
6
- */
7
- import { type Sandbox, type SandboxOptions } from "./sandbox";
8
- import type { BundleResult } from "./bundler";
9
- /**
10
- * Options for building with a sandbox (one-off usage).
11
- */
12
- export interface BuildWithSandboxOptions<T> {
13
- /**
14
- * Existing sandbox to use. If not provided, a new sandbox is created.
15
- *
16
- * Use this when you want to:
17
- * - Reuse a sandbox across multiple builds
18
- * - Pre-configure the sandbox with specific files or settings
19
- * - Share a sandbox between different operations
20
- *
21
- * @example
22
- * ```ts
23
- * const sandbox = await createSandbox({
24
- * initialFiles: { '/src/index.ts': 'export const x = 1;' },
25
- * });
26
- *
27
- * const result = await buildWithSandbox({
28
- * sandbox,
29
- * build: async (sb) => { ... },
30
- * });
31
- * ```
32
- */
33
- sandbox?: Sandbox;
34
- /**
35
- * Options for creating a new sandbox (only used if `sandbox` is not provided).
36
- *
37
- * @example
38
- * ```ts
39
- * const result = await buildWithSandbox({
40
- * sandboxOptions: {
41
- * initialFiles: { '/src/index.ts': 'export const x = 1;' },
42
- * sharedModules: ['react', 'react-dom/client'],
43
- * },
44
- * build: async (sandbox) => { ... },
45
- * });
46
- * ```
47
- */
48
- sandboxOptions?: SandboxOptions;
49
- /**
50
- * The function to run with the sandbox.
51
- *
52
- * This receives the sandbox and can do anything with it—run bash commands,
53
- * write files, execute an agent loop, etc.
54
- *
55
- * The return value becomes `result` in the output.
56
- *
57
- * @example
58
- * ```ts
59
- * const { result, bundle } = await buildWithSandbox({
60
- * build: async (sandbox) => {
61
- * await sandbox.bash.exec('echo "hello" > /test.txt');
62
- * const buildResult = await sandbox.bash.exec('build /src/index.ts');
63
- * return { buildExitCode: buildResult.exitCode };
64
- * },
65
- * });
66
- * ```
67
- */
68
- build: (sandbox: Sandbox) => Promise<T>;
69
- }
70
- /**
71
- * Result of building with a sandbox.
72
- */
73
- export interface BuildResult<T> {
74
- /**
75
- * Whatever the `build` function returned, or `undefined` if it threw.
76
- */
77
- result: T | undefined;
78
- /**
79
- * The error thrown by the `build` function, or `null` if it succeeded.
80
- *
81
- * When an error occurs, the bundle and module may still be available
82
- * if a build succeeded before the error was thrown.
83
- */
84
- error: Error | null;
85
- /**
86
- * The last successful build result, or null if no build succeeded.
87
- *
88
- * This captures the bundle from any successful `build` command executed
89
- * during the run. If multiple builds succeed, this contains the last one.
90
- *
91
- * **Important**: This is available even if the `build` function threw an error,
92
- * as long as a build succeeded before the error occurred.
93
- */
94
- bundle: BundleResult | null;
95
- /**
96
- * The loaded module exports, or null if no bundle or loading failed.
97
- *
98
- * When a build succeeds, the bundle is automatically loaded and the
99
- * exports are available here. Use type assertions or runtime checks
100
- * to access specific exports.
101
- *
102
- * @example
103
- * ```ts
104
- * const run = await buildWithSandbox({ build: myAgent });
105
- *
106
- * if (run.module) {
107
- * const App = run.module.App as React.ComponentType;
108
- * return <App />;
109
- * }
110
- * ```
111
- */
112
- module: Record<string, unknown> | null;
113
- /**
114
- * Error that occurred while loading the module, or null if loading succeeded.
115
- *
116
- * This is separate from `error` (agent error) to distinguish:
117
- * - Agent failed → `error` is set, `module` may still be available
118
- * - Agent succeeded but load failed → `moduleError` is set
119
- * - No bundle produced → both `module` and `moduleError` are null
120
- */
121
- moduleError: Error | null;
122
- /**
123
- * The sandbox that was used.
124
- *
125
- * Useful when the wrapper created an ephemeral sandbox—you can inspect
126
- * its state, save it, or reuse it for another build.
127
- */
128
- sandbox: Sandbox;
129
- }
130
- /**
131
- * Build with a sandbox, automatically capturing build results.
132
- *
133
- * This is the recommended way to use sandlot for one-off builds. It:
134
- * 1. Creates a sandbox (or uses one you provide)
135
- * 2. Sets up build result capture
136
- * 3. Runs your function
137
- * 4. Returns everything: your result, the bundle (if any), and the sandbox
138
- *
139
- * For reusable agent workflows, see `createBuilder()` which wraps this
140
- * function and adds prompt support.
141
- *
142
- * The caller handles their own timeout/cancellation logic—this wrapper
143
- * stays minimal and doesn't impose opinions on error handling.
144
- *
145
- * @example Basic usage with an agent
146
- * ```ts
147
- * import { buildWithSandbox } from 'sandlot';
148
- *
149
- * const run = await buildWithSandbox({
150
- * build: async (sandbox) => {
151
- * const agent = new MyAgent({
152
- * tools: {
153
- * bash: (command: string) => sandbox.bash.exec(command),
154
- * },
155
- * });
156
- *
157
- * return agent.run('Create a React component that shows "Hello"');
158
- * },
159
- * });
160
- *
161
- * // Module is auto-loaded if build succeeded
162
- * if (run.module) {
163
- * const App = run.module.App as React.ComponentType;
164
- * return <App />;
165
- * }
166
- * ```
167
- *
168
- * @example Handling all failure modes
169
- * ```ts
170
- * const run = await buildWithSandbox({
171
- * build: async (sandbox) => myAgent.run('...'),
172
- * });
173
- *
174
- * // Check what happened
175
- * if (run.error) {
176
- * console.log('Agent failed:', run.error.message);
177
- * }
178
- * if (run.moduleError) {
179
- * console.log('Module failed to load:', run.moduleError.message);
180
- * }
181
- *
182
- * // Module available even if agent errored (if build succeeded first)
183
- * if (run.module) {
184
- * const App = run.module.App as React.ComponentType;
185
- * return <App />;
186
- * }
187
- *
188
- * // No module - check why
189
- * if (!run.bundle) {
190
- * console.log('No build was produced');
191
- * }
192
- * ```
193
- */
194
- export declare function buildWithSandbox<T>(options: BuildWithSandboxOptions<T>): Promise<BuildResult<T>>;
195
- /**
196
- * Options for creating a reusable builder function.
197
- */
198
- export interface CreateBuilderOptions<T> {
199
- /**
200
- * Existing sandbox to reuse across all calls.
201
- *
202
- * When provided, the same sandbox is used for every call to the returned
203
- * builder function. Files and state persist between runs—useful for
204
- * iterative workflows where you want to build on previous work.
205
- *
206
- * @example
207
- * ```ts
208
- * const sandbox = await createSandbox({
209
- * initialFiles: { '/src/utils.ts': 'export const PI = 3.14;' },
210
- * });
211
- *
212
- * const runAgent = createBuilder({
213
- * sandbox, // Reused across all calls
214
- * build: async (sb, prompt) => myAgent.run(sb, prompt),
215
- * });
216
- *
217
- * await runAgent("Create a circle component"); // Uses existing utils.ts
218
- * await runAgent("Add a square component"); // Still has circle + utils
219
- * ```
220
- */
221
- sandbox?: Sandbox;
222
- /**
223
- * Options for creating fresh sandboxes (only used if `sandbox` is not provided).
224
- *
225
- * Each call to the returned builder function creates a new sandbox with
226
- * these options. Use this when you want isolated runs.
227
- *
228
- * @example
229
- * ```ts
230
- * const runAgent = createBuilder({
231
- * sandboxOptions: {
232
- * sharedModules: ['react', 'react-dom/client'],
233
- * },
234
- * build: async (sandbox, prompt) => myAgent.run(sandbox, prompt),
235
- * });
236
- *
237
- * // Each call gets a fresh sandbox
238
- * await runAgent("Create a counter"); // Fresh sandbox
239
- * await runAgent("Create a todo list"); // Another fresh sandbox
240
- * ```
241
- */
242
- sandboxOptions?: SandboxOptions;
243
- /**
244
- * The function to build with the sandbox and prompt.
245
- *
246
- * This receives the sandbox and the prompt string, and should return
247
- * whatever result your agent produces.
248
- *
249
- * @example
250
- * ```ts
251
- * const runAgent = createBuilder({
252
- * build: async (sandbox, prompt) => {
253
- * const agent = new MyAgent({
254
- * tools: { bash: sandbox.bash.exec },
255
- * });
256
- * return agent.run(prompt);
257
- * },
258
- * });
259
- * ```
260
- */
261
- build: (sandbox: Sandbox, prompt: string) => Promise<T>;
262
- }
263
- /**
264
- * Create a reusable builder function for running prompts in a sandbox.
265
- *
266
- * This wraps `buildWithSandbox()` to create a convenient function that
267
- * just takes a prompt. Define your agent logic once, then call it with
268
- * different prompts.
269
- *
270
- * **Sandbox behavior:**
271
- * - If you provide `sandbox`: The same sandbox is reused for every call
272
- * (files persist, good for iteration)
273
- * - If you provide `sandboxOptions` (or nothing): A fresh sandbox is created
274
- * for each call (isolated runs)
275
- *
276
- * @example Basic usage
277
- * ```ts
278
- * import { createBuilder } from 'sandlot';
279
- *
280
- * const runAgent = createBuilder({
281
- * sandboxOptions: { sharedModules: ['react', 'react-dom/client'] },
282
- * build: async (sandbox, prompt) => {
283
- * const agent = new MyAgent({ tools: { bash: sandbox.bash.exec } });
284
- * return agent.run(prompt);
285
- * },
286
- * });
287
- *
288
- * // Use it multiple times with different prompts
289
- * const result1 = await runAgent("Create a counter component");
290
- * const result2 = await runAgent("Create a todo list");
291
- *
292
- * if (result1.module?.App) {
293
- * const Counter = result1.module.App as React.ComponentType;
294
- * }
295
- * ```
296
- *
297
- * @example Iterative workflow with shared sandbox
298
- * ```ts
299
- * const sandbox = await createSandbox();
300
- *
301
- * const runAgent = createBuilder({
302
- * sandbox, // Same sandbox for all calls
303
- * build: async (sb, prompt) => myAgent.run(sb, prompt),
304
- * });
305
- *
306
- * // First prompt creates initial component
307
- * await runAgent("Create a button component");
308
- *
309
- * // Second prompt can build on the first
310
- * await runAgent("Add a click counter to the button");
311
- * ```
312
- */
313
- export declare function createBuilder<T>(options: CreateBuilderOptions<T>): (prompt: string) => Promise<BuildResult<T>>;
314
- //# sourceMappingURL=runner.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAiB,KAAK,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAC7E,OAAO,KAAK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