sandlot 0.1.2 → 0.1.4
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 +138 -408
- package/dist/build-emitter.d.ts +31 -13
- package/dist/build-emitter.d.ts.map +1 -1
- package/dist/builder.d.ts +370 -0
- package/dist/builder.d.ts.map +1 -0
- package/dist/bundler.d.ts +6 -2
- package/dist/bundler.d.ts.map +1 -1
- package/dist/commands/compile.d.ts +13 -0
- package/dist/commands/compile.d.ts.map +1 -0
- package/dist/commands/index.d.ts +17 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/packages.d.ts +17 -0
- package/dist/commands/packages.d.ts.map +1 -0
- package/dist/commands/run.d.ts +40 -0
- package/dist/commands/run.d.ts.map +1 -0
- package/dist/commands/types.d.ts +141 -0
- package/dist/commands/types.d.ts.map +1 -0
- package/dist/fs.d.ts +53 -49
- package/dist/fs.d.ts.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +300 -511
- package/dist/internal.js +161 -171
- package/dist/runner.d.ts +314 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/sandbox-manager.d.ts +45 -21
- package/dist/sandbox-manager.d.ts.map +1 -1
- package/dist/sandbox.d.ts +144 -62
- package/dist/sandbox.d.ts.map +1 -1
- package/dist/shared-modules.d.ts +22 -3
- package/dist/shared-modules.d.ts.map +1 -1
- package/dist/shared-resources.d.ts +0 -3
- package/dist/shared-resources.d.ts.map +1 -1
- package/dist/ts-libs.d.ts +7 -20
- package/dist/ts-libs.d.ts.map +1 -1
- package/dist/typechecker.d.ts +1 -1
- package/package.json +5 -5
- package/src/build-emitter.ts +32 -29
- package/src/builder.ts +498 -0
- package/src/bundler.ts +76 -55
- package/src/commands/compile.ts +236 -0
- package/src/commands/index.ts +51 -0
- package/src/commands/packages.ts +154 -0
- package/src/commands/run.ts +245 -0
- package/src/commands/types.ts +172 -0
- package/src/fs.ts +82 -221
- package/src/index.ts +17 -12
- package/src/sandbox.ts +219 -149
- package/src/shared-modules.ts +74 -4
- package/src/shared-resources.ts +0 -3
- package/src/ts-libs.ts +19 -121
- package/src/typechecker.ts +1 -1
- package/dist/react.d.ts +0 -159
- package/dist/react.d.ts.map +0 -1
- package/dist/react.js +0 -149
- package/src/commands.ts +0 -733
- package/src/sandbox-manager.ts +0 -409
package/dist/build-emitter.d.ts
CHANGED
|
@@ -1,29 +1,47 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Build event emitter for sandbox environments.
|
|
3
3
|
*
|
|
4
|
-
* Simple typed event emitter for build results.
|
|
5
|
-
*
|
|
4
|
+
* Simple typed event emitter for successful build results.
|
|
5
|
+
* Used internally by the sandbox to notify listeners when a build succeeds.
|
|
6
6
|
*/
|
|
7
|
-
import type {
|
|
7
|
+
import type { BuildOutput } from "./commands/types";
|
|
8
8
|
/**
|
|
9
9
|
* Simple typed event emitter for build results.
|
|
10
|
-
*
|
|
10
|
+
*
|
|
11
|
+
* Only emits on successful builds—build failures are communicated via
|
|
12
|
+
* the bash command's exit code and stderr.
|
|
13
|
+
*
|
|
14
|
+
* For most use cases, prefer using `createBuilder()` which handles
|
|
15
|
+
* build result capture automatically.
|
|
11
16
|
*/
|
|
12
17
|
export declare class BuildEmitter {
|
|
13
18
|
private listeners;
|
|
14
|
-
private lastResult;
|
|
15
19
|
/**
|
|
16
|
-
* Emit a build result to all listeners
|
|
20
|
+
* Emit a build result to all listeners.
|
|
21
|
+
* Called internally when a build command succeeds.
|
|
17
22
|
*/
|
|
18
|
-
emit: (result:
|
|
23
|
+
emit: (result: BuildOutput) => Promise<void>;
|
|
19
24
|
/**
|
|
20
25
|
* Subscribe to build events. Returns an unsubscribe function.
|
|
26
|
+
*
|
|
27
|
+
* The callback is invoked each time a build succeeds, receiving
|
|
28
|
+
* the BuildOutput with the bundle and loaded module.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* let lastBuild: BuildOutput | null = null;
|
|
33
|
+
* const unsubscribe = sandbox.onBuild((result) => {
|
|
34
|
+
* lastBuild = result;
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* await sandbox.bash.exec('build /src/index.ts');
|
|
38
|
+
* unsubscribe();
|
|
39
|
+
*
|
|
40
|
+
* if (lastBuild) {
|
|
41
|
+
* const App = lastBuild.module.App as React.ComponentType;
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
21
44
|
*/
|
|
22
|
-
on(callback: (result:
|
|
23
|
-
/**
|
|
24
|
-
* Get the last build result, or wait for the next one if none exists.
|
|
25
|
-
* Clears the cached result after returning, so subsequent calls wait for new builds.
|
|
26
|
-
*/
|
|
27
|
-
waitFor(): Promise<BundleResult>;
|
|
45
|
+
on(callback: (result: BuildOutput) => void | Promise<void>): () => void;
|
|
28
46
|
}
|
|
29
47
|
//# sourceMappingURL=build-emitter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-emitter.d.ts","sourceRoot":"","sources":["../src/build-emitter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"build-emitter.d.ts","sourceRoot":"","sources":["../src/build-emitter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;;;;;;;GAQG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,SAAS,CAA4D;IAE7E;;;OAGG;IACH,IAAI,GAAU,QAAQ,WAAW,KAAG,OAAO,CAAC,IAAI,CAAC,CAS/C;IAEF;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,EAAE,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI;CAMxE"}
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-level builder for sandbox-based agent workflows.
|
|
3
|
+
*
|
|
4
|
+
* Provides a simple API that handles sandbox creation, build result capture,
|
|
5
|
+
* validation, and timeout/cancellation—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
|
+
* Result of running a builder.
|
|
11
|
+
*
|
|
12
|
+
* @typeParam T - The return type of the build function
|
|
13
|
+
* @typeParam M - The type of the validated module (defaults to Record<string, unknown>)
|
|
14
|
+
*/
|
|
15
|
+
export interface BuildResult<T, M = Record<string, unknown>> {
|
|
16
|
+
/**
|
|
17
|
+
* Whatever the `build` function returned, or `undefined` if it threw.
|
|
18
|
+
*/
|
|
19
|
+
result: T | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* The error thrown by the `build` function, or `null` if it succeeded.
|
|
22
|
+
*
|
|
23
|
+
* When an error occurs, the bundle and module may still be available
|
|
24
|
+
* if a build succeeded before the error was thrown.
|
|
25
|
+
*/
|
|
26
|
+
error: Error | null;
|
|
27
|
+
/**
|
|
28
|
+
* The last successful build result, or null if no build succeeded.
|
|
29
|
+
*
|
|
30
|
+
* This captures the bundle from any successful `build` command executed
|
|
31
|
+
* during the run. If multiple builds succeed, this contains the last one.
|
|
32
|
+
*
|
|
33
|
+
* **Important**: This is available even if the `build` function threw an error,
|
|
34
|
+
* as long as a build succeeded before the error occurred.
|
|
35
|
+
*/
|
|
36
|
+
bundle: BundleResult | null;
|
|
37
|
+
/**
|
|
38
|
+
* The loaded module exports, or null if no bundle was produced.
|
|
39
|
+
*
|
|
40
|
+
* When a build succeeds, the bundle is automatically loaded. If a `validate`
|
|
41
|
+
* function was provided, the module is passed through it and the result is
|
|
42
|
+
* available here with the validated type.
|
|
43
|
+
*
|
|
44
|
+
* @example Without validation
|
|
45
|
+
* ```ts
|
|
46
|
+
* const result = await runAgent("Create a counter");
|
|
47
|
+
* result.module // Record<string, unknown> | null
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @example With validation
|
|
51
|
+
* ```ts
|
|
52
|
+
* const result = await runAgent("Create a counter", {
|
|
53
|
+
* validate: (mod) => ({ App: mod.App as React.ComponentType }),
|
|
54
|
+
* });
|
|
55
|
+
* result.module // { App: React.ComponentType } | null
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
module: M | null;
|
|
59
|
+
/**
|
|
60
|
+
* The sandbox that was used.
|
|
61
|
+
*
|
|
62
|
+
* Useful when the builder created an ephemeral sandbox—you can inspect
|
|
63
|
+
* its state, save it, or reuse it for another build.
|
|
64
|
+
*/
|
|
65
|
+
sandbox: Sandbox;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Options passed when calling the builder function.
|
|
69
|
+
*
|
|
70
|
+
* @typeParam M - The type returned by the validate function (if provided)
|
|
71
|
+
*/
|
|
72
|
+
export interface BuildCallOptions<M = Record<string, unknown>> {
|
|
73
|
+
/**
|
|
74
|
+
* Validation function for the built module.
|
|
75
|
+
*
|
|
76
|
+
* When provided, this function runs as part of the build command—after
|
|
77
|
+
* bundling and loading, but before the build is considered successful.
|
|
78
|
+
* If validation throws, the build fails and the agent sees the error,
|
|
79
|
+
* giving it a chance to fix the code and try again.
|
|
80
|
+
*
|
|
81
|
+
* The return type determines the type of `result.module`.
|
|
82
|
+
*
|
|
83
|
+
* @example Simple validation
|
|
84
|
+
* ```ts
|
|
85
|
+
* const result = await runAgent("Create a counter", {
|
|
86
|
+
* validate: (mod) => {
|
|
87
|
+
* if (typeof mod.App !== 'function') {
|
|
88
|
+
* throw new Error("Module must export an App component");
|
|
89
|
+
* }
|
|
90
|
+
* return { App: mod.App as React.ComponentType };
|
|
91
|
+
* },
|
|
92
|
+
* });
|
|
93
|
+
* // If validation fails, agent sees: "Build failed: Validation error."
|
|
94
|
+
* // Agent can fix the code and try again
|
|
95
|
+
* result.module?.App // React.ComponentType (after successful build)
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @example With Zod
|
|
99
|
+
* ```ts
|
|
100
|
+
* import { z } from 'zod';
|
|
101
|
+
*
|
|
102
|
+
* const CounterSchema = z.object({
|
|
103
|
+
* App: z.custom<React.ComponentType>((v) => typeof v === 'function'),
|
|
104
|
+
* initialCount: z.number().optional(),
|
|
105
|
+
* });
|
|
106
|
+
*
|
|
107
|
+
* const result = await runAgent("Create a counter", {
|
|
108
|
+
* validate: (mod) => CounterSchema.parse(mod),
|
|
109
|
+
* });
|
|
110
|
+
* result.module?.App // React.ComponentType
|
|
111
|
+
* result.module?.initialCount // number | undefined
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
validate?: (module: Record<string, unknown>) => M;
|
|
115
|
+
/**
|
|
116
|
+
* Maximum time in milliseconds for the build to complete.
|
|
117
|
+
*
|
|
118
|
+
* If the timeout is exceeded, the build is aborted and an error is thrown.
|
|
119
|
+
* The agent's partial work may still be available in the sandbox.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* const result = await runAgent("Create a complex dashboard", {
|
|
124
|
+
* timeout: 300_000, // 5 minutes
|
|
125
|
+
* });
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
timeout?: number;
|
|
129
|
+
/**
|
|
130
|
+
* AbortSignal for cancelling the build.
|
|
131
|
+
*
|
|
132
|
+
* If the signal is aborted, the build stops and an error is thrown.
|
|
133
|
+
* Useful for user-initiated cancellation or external timeout management.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* const controller = new AbortController();
|
|
138
|
+
*
|
|
139
|
+
* // Start the build
|
|
140
|
+
* const promise = runAgent("Create a counter", {
|
|
141
|
+
* signal: controller.signal,
|
|
142
|
+
* });
|
|
143
|
+
*
|
|
144
|
+
* // Cancel after 10 seconds
|
|
145
|
+
* setTimeout(() => controller.abort(), 10_000);
|
|
146
|
+
*
|
|
147
|
+
* try {
|
|
148
|
+
* const result = await promise;
|
|
149
|
+
* } catch (err) {
|
|
150
|
+
* if (err.name === 'AbortError') {
|
|
151
|
+
* console.log('Build was cancelled');
|
|
152
|
+
* }
|
|
153
|
+
* }
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
signal?: AbortSignal;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Options for creating a reusable builder function.
|
|
160
|
+
*/
|
|
161
|
+
export interface CreateBuilderOptions<T> {
|
|
162
|
+
/**
|
|
163
|
+
* Existing sandbox to reuse across all calls.
|
|
164
|
+
*
|
|
165
|
+
* When provided, the same sandbox is used for every call to the returned
|
|
166
|
+
* builder function. Files and state persist between runs—useful for
|
|
167
|
+
* iterative workflows where you want to build on previous work.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* const sandbox = await createSandbox({
|
|
172
|
+
* initialFiles: { '/src/utils.ts': 'export const PI = 3.14;' },
|
|
173
|
+
* });
|
|
174
|
+
*
|
|
175
|
+
* const runAgent = createBuilder({
|
|
176
|
+
* sandbox, // Reused across all calls
|
|
177
|
+
* build: async (sb, prompt) => myAgent.run(sb, prompt),
|
|
178
|
+
* });
|
|
179
|
+
*
|
|
180
|
+
* await runAgent("Create a circle component"); // Uses existing utils.ts
|
|
181
|
+
* await runAgent("Add a square component"); // Still has circle + utils
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
sandbox?: Sandbox;
|
|
185
|
+
/**
|
|
186
|
+
* Options for creating fresh sandboxes (only used if `sandbox` is not provided).
|
|
187
|
+
*
|
|
188
|
+
* Each call to the returned builder function creates a new sandbox with
|
|
189
|
+
* these options. Use this when you want isolated runs.
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```ts
|
|
193
|
+
* const runAgent = createBuilder({
|
|
194
|
+
* sandboxOptions: {
|
|
195
|
+
* sharedModules: ['react', 'react-dom/client'],
|
|
196
|
+
* },
|
|
197
|
+
* build: async (sandbox, prompt) => myAgent.run(sandbox, prompt),
|
|
198
|
+
* });
|
|
199
|
+
*
|
|
200
|
+
* // Each call gets a fresh sandbox
|
|
201
|
+
* await runAgent("Create a counter"); // Fresh sandbox
|
|
202
|
+
* await runAgent("Create a todo list"); // Another fresh sandbox
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
sandboxOptions?: SandboxOptions;
|
|
206
|
+
/**
|
|
207
|
+
* The function to build with the sandbox and prompt.
|
|
208
|
+
*
|
|
209
|
+
* This receives the sandbox and the prompt string, and should return
|
|
210
|
+
* whatever result your agent produces.
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```ts
|
|
214
|
+
* const runAgent = createBuilder({
|
|
215
|
+
* build: async (sandbox, prompt) => {
|
|
216
|
+
* const agent = new MyAgent({
|
|
217
|
+
* tools: { bash: sandbox.bash.exec },
|
|
218
|
+
* });
|
|
219
|
+
* return agent.run(prompt);
|
|
220
|
+
* },
|
|
221
|
+
* });
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
build: (sandbox: Sandbox, prompt: string) => Promise<T>;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* The builder function returned by `createBuilder`.
|
|
228
|
+
*
|
|
229
|
+
* Can be called with just a prompt, or with options including validation,
|
|
230
|
+
* timeout, and abort signal.
|
|
231
|
+
*/
|
|
232
|
+
export interface BuilderFn<T> {
|
|
233
|
+
/**
|
|
234
|
+
* Run the builder with a prompt (no options).
|
|
235
|
+
* Module will be typed as `Record<string, unknown>`.
|
|
236
|
+
*/
|
|
237
|
+
(prompt: string): Promise<BuildResult<T>>;
|
|
238
|
+
/**
|
|
239
|
+
* Run the builder with a prompt and options.
|
|
240
|
+
* If `validate` is provided, module will be typed based on its return type.
|
|
241
|
+
*/
|
|
242
|
+
<M = Record<string, unknown>>(prompt: string, options: BuildCallOptions<M>): Promise<BuildResult<T, M>>;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Create a reusable builder function for running prompts in a sandbox.
|
|
246
|
+
*
|
|
247
|
+
* This is the main API for sandlot. Define your agent logic once, then call
|
|
248
|
+
* the returned function with different prompts. Each call:
|
|
249
|
+
*
|
|
250
|
+
* 1. Creates a sandbox (or uses one you provide)
|
|
251
|
+
* 2. Sets up build result capture
|
|
252
|
+
* 3. Runs your build function with the prompt
|
|
253
|
+
* 4. Returns everything: your result, the bundle, the module, and the sandbox
|
|
254
|
+
*
|
|
255
|
+
* **Sandbox behavior:**
|
|
256
|
+
* - If you provide `sandbox`: The same sandbox is reused for every call
|
|
257
|
+
* (files persist, good for iteration)
|
|
258
|
+
* - If you provide `sandboxOptions` (or nothing): A fresh sandbox is created
|
|
259
|
+
* for each call (isolated runs)
|
|
260
|
+
*
|
|
261
|
+
* **Validation behavior:**
|
|
262
|
+
* When you provide a `validate` function, it runs as part of the build command.
|
|
263
|
+
* If validation fails, the build fails and the agent sees the error—giving it
|
|
264
|
+
* a chance to fix the code and try again. This is more powerful than post-hoc
|
|
265
|
+
* validation because the agent can iterate on validation errors.
|
|
266
|
+
*
|
|
267
|
+
* @example Basic usage
|
|
268
|
+
* ```ts
|
|
269
|
+
* import { createBuilder } from 'sandlot';
|
|
270
|
+
*
|
|
271
|
+
* const runAgent = createBuilder({
|
|
272
|
+
* sandboxOptions: { sharedModules: ['react', 'react-dom/client'] },
|
|
273
|
+
* build: async (sandbox, prompt) => {
|
|
274
|
+
* const agent = new MyAgent({ tools: { bash: sandbox.bash.exec } });
|
|
275
|
+
* return agent.run(prompt);
|
|
276
|
+
* },
|
|
277
|
+
* });
|
|
278
|
+
*
|
|
279
|
+
* // Use it multiple times with different prompts
|
|
280
|
+
* const result1 = await runAgent("Create a counter component");
|
|
281
|
+
* const result2 = await runAgent("Create a todo list");
|
|
282
|
+
*
|
|
283
|
+
* if (result1.module?.App) {
|
|
284
|
+
* const Counter = result1.module.App as React.ComponentType;
|
|
285
|
+
* }
|
|
286
|
+
* ```
|
|
287
|
+
*
|
|
288
|
+
* @example With validation (agent can fix validation errors)
|
|
289
|
+
* ```ts
|
|
290
|
+
* const runAgent = createBuilder({
|
|
291
|
+
* sandboxOptions: { sharedModules: ['react'] },
|
|
292
|
+
* build: async (sandbox, prompt) => myAgent.run(sandbox, prompt),
|
|
293
|
+
* });
|
|
294
|
+
*
|
|
295
|
+
* // Validation runs during build - agent sees errors and can fix them
|
|
296
|
+
* const counter = await runAgent("Create a counter", {
|
|
297
|
+
* validate: (mod) => {
|
|
298
|
+
* if (typeof mod.App !== 'function') {
|
|
299
|
+
* throw new Error("Must export an App component");
|
|
300
|
+
* }
|
|
301
|
+
* return { App: mod.App as React.ComponentType };
|
|
302
|
+
* },
|
|
303
|
+
* });
|
|
304
|
+
* // If agent's first attempt fails validation, it sees:
|
|
305
|
+
* // "Build failed: Validation error. Must export an App component"
|
|
306
|
+
* // Agent can then fix the code and run build again
|
|
307
|
+
* ```
|
|
308
|
+
*
|
|
309
|
+
* @example With Zod validation
|
|
310
|
+
* ```ts
|
|
311
|
+
* import { z } from 'zod';
|
|
312
|
+
*
|
|
313
|
+
* const CounterSchema = z.object({
|
|
314
|
+
* App: z.custom<React.ComponentType>((v) => typeof v === 'function'),
|
|
315
|
+
* initialCount: z.number().default(0),
|
|
316
|
+
* });
|
|
317
|
+
*
|
|
318
|
+
* const result = await runAgent("Create a counter", {
|
|
319
|
+
* validate: (mod) => CounterSchema.parse(mod),
|
|
320
|
+
* });
|
|
321
|
+
* // result.module is fully typed from Zod inference
|
|
322
|
+
* ```
|
|
323
|
+
*
|
|
324
|
+
* @example Iterative workflow with shared sandbox
|
|
325
|
+
* ```ts
|
|
326
|
+
* const sandbox = await createSandbox();
|
|
327
|
+
*
|
|
328
|
+
* const runAgent = createBuilder({
|
|
329
|
+
* sandbox, // Same sandbox for all calls
|
|
330
|
+
* build: async (sb, prompt) => myAgent.run(sb, prompt),
|
|
331
|
+
* });
|
|
332
|
+
*
|
|
333
|
+
* // First prompt creates initial component
|
|
334
|
+
* await runAgent("Create a button component");
|
|
335
|
+
*
|
|
336
|
+
* // Second prompt can build on the first
|
|
337
|
+
* await runAgent("Add a click counter to the button");
|
|
338
|
+
* ```
|
|
339
|
+
*
|
|
340
|
+
* @example With timeout
|
|
341
|
+
* ```ts
|
|
342
|
+
* // Complex tasks get more time
|
|
343
|
+
* const result = await runAgent("Create a full dashboard with charts", {
|
|
344
|
+
* timeout: 300_000, // 5 minutes
|
|
345
|
+
* });
|
|
346
|
+
* ```
|
|
347
|
+
*
|
|
348
|
+
* @example With abort signal for cancellation
|
|
349
|
+
* ```ts
|
|
350
|
+
* const controller = new AbortController();
|
|
351
|
+
*
|
|
352
|
+
* // Start the build
|
|
353
|
+
* const promise = runAgent("Create a counter", {
|
|
354
|
+
* signal: controller.signal,
|
|
355
|
+
* });
|
|
356
|
+
*
|
|
357
|
+
* // User clicks cancel button
|
|
358
|
+
* cancelButton.onclick = () => controller.abort();
|
|
359
|
+
*
|
|
360
|
+
* try {
|
|
361
|
+
* const result = await promise;
|
|
362
|
+
* } catch (err) {
|
|
363
|
+
* if (err.name === 'AbortError') {
|
|
364
|
+
* console.log('Build was cancelled by user');
|
|
365
|
+
* }
|
|
366
|
+
* }
|
|
367
|
+
* ```
|
|
368
|
+
*/
|
|
369
|
+
export declare function createBuilder<T>(options: CreateBuilderOptions<T>): BuilderFn<T>;
|
|
370
|
+
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAiB,KAAK,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAG9C;;;;;GAKG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACzD;;OAEG;IACH,MAAM,EAAE,CAAC,GAAG,SAAS,CAAC;IAEtB;;;;;OAKG;IACH,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAEpB;;;;;;;;OAQG;IACH,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAE5B;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC;IAEjB;;;;;OAKG;IACH,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwCG;IACH,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IAElD;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB,CAAC,CAAC;IACrC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;IAEhC;;;;;;;;;;;;;;;;;OAiBG;IACH,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;CACzD;AAED;;;;;GAKG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC;IAC1B;;;OAGG;IACH,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAE1C;;;OAGG;IACH,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;CACzG;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4HG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAiH/E"}
|
package/dist/bundler.d.ts
CHANGED
|
@@ -88,8 +88,12 @@ export interface BundleResult {
|
|
|
88
88
|
includedFiles: string[];
|
|
89
89
|
}
|
|
90
90
|
/**
|
|
91
|
-
* Initialize esbuild
|
|
91
|
+
* Initialize esbuild. Called automatically on first bundle.
|
|
92
92
|
* Can be called explicitly to pre-warm.
|
|
93
|
+
*
|
|
94
|
+
* In browser environments, this loads and initializes esbuild-wasm.
|
|
95
|
+
* In server environments (Node.js, Bun, Deno), this loads native esbuild
|
|
96
|
+
* which doesn't require WASM initialization.
|
|
93
97
|
*/
|
|
94
98
|
export declare function initBundler(): Promise<void>;
|
|
95
99
|
/**
|
|
@@ -97,7 +101,7 @@ export declare function initBundler(): Promise<void>;
|
|
|
97
101
|
*
|
|
98
102
|
* @example
|
|
99
103
|
* ```ts
|
|
100
|
-
* const fs =
|
|
104
|
+
* const fs = Filesystem.create({
|
|
101
105
|
* initialFiles: {
|
|
102
106
|
* "/src/index.ts": "export const hello = 'world';",
|
|
103
107
|
* "/src/utils.ts": "export function add(a: number, b: number) { return a + b; }",
|
package/dist/bundler.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundler.d.ts","sourceRoot":"","sources":["../src/bundler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,KAAK,YAAY,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"bundler.d.ts","sourceRoot":"","sources":["../src/bundler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,KAAK,YAAY,MAAM,cAAc,CAAC;AAuDlD;;;;;;;;;GASG;AACH,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,UAAU,GAAG,QAAQ,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,EAAE,EAAE,WAAW,CAAC;IAEhB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAEpB;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;IAE5B;;;;;;;;OAQG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IAEzB;;OAEG;IACH,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,CAAC;IAEhC;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,QAAQ,EAAE,YAAY,CAAC,OAAO,EAAE,CAAC;IAEjC;;OAEG;IACH,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB;AAsCD;;;;;;;GAOG;AACH,wBAAsB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAsBjD;AA+ND;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CA+D1E;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAIzE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,eAAe,CAAC,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,CAAC,CAAC,CAOrF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compile-related commands: tsc and build
|
|
3
|
+
*/
|
|
4
|
+
import { type CommandDeps } from "./types";
|
|
5
|
+
/**
|
|
6
|
+
* Create the `tsc` command for type checking
|
|
7
|
+
*/
|
|
8
|
+
export declare function createTscCommand(deps: CommandDeps): import("just-bash/browser").Command;
|
|
9
|
+
/**
|
|
10
|
+
* Create the `build` command for bundling (with automatic type checking)
|
|
11
|
+
*/
|
|
12
|
+
export declare function createBuildCommand(deps: CommandDeps): import("just-bash/browser").Command;
|
|
13
|
+
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/commands/compile.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,EAAE,KAAK,WAAW,EAAyB,MAAM,SAAS,CAAC;AAElE;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,uCA4DjD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,WAAW,uCA6JnD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command factories for sandbox bash environments.
|
|
3
|
+
*
|
|
4
|
+
* Pure factories that create commands for type checking, bundling,
|
|
5
|
+
* package management, and code execution.
|
|
6
|
+
* No global state - all dependencies are passed in explicitly.
|
|
7
|
+
*/
|
|
8
|
+
export { type CommandDeps, type BuildOutput, type ValidateFn, type RunContext, type RunOptions, type RunResult, formatEsbuildMessages, } from "./types";
|
|
9
|
+
export { createTscCommand, createBuildCommand } from "./compile";
|
|
10
|
+
export { createInstallCommand, createUninstallCommand, createListCommand, } from "./packages";
|
|
11
|
+
export { createRunCommand } from "./run";
|
|
12
|
+
import type { CommandDeps } from "./types";
|
|
13
|
+
/**
|
|
14
|
+
* Create all default sandbox commands
|
|
15
|
+
*/
|
|
16
|
+
export declare function createDefaultCommands(deps: CommandDeps): import("just-bash/browser").Command[];
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,SAAS,EACd,qBAAqB,GACtB,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAGjE,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAGzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAK3C;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,WAAW,yCAStD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package management commands: install, uninstall, list
|
|
3
|
+
*/
|
|
4
|
+
import type { CommandDeps } from "./types";
|
|
5
|
+
/**
|
|
6
|
+
* Create the `install` command for adding packages from npm
|
|
7
|
+
*/
|
|
8
|
+
export declare function createInstallCommand(deps: CommandDeps): import("just-bash/browser").Command;
|
|
9
|
+
/**
|
|
10
|
+
* Create the `uninstall` command for removing packages
|
|
11
|
+
*/
|
|
12
|
+
export declare function createUninstallCommand(deps: CommandDeps): import("just-bash/browser").Command;
|
|
13
|
+
/**
|
|
14
|
+
* Create the `list` command (alias: `ls`) for showing installed packages
|
|
15
|
+
*/
|
|
16
|
+
export declare function createListCommand(deps: CommandDeps): import("just-bash/browser").Command;
|
|
17
|
+
//# sourceMappingURL=packages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"packages.d.ts","sourceRoot":"","sources":["../../src/commands/packages.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,WAAW,uCAoDrD;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,WAAW,uCA+CvD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,WAAW,uCAiClD"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run command for executing code in the sandbox.
|
|
3
|
+
*/
|
|
4
|
+
import type { CommandDeps } from "./types";
|
|
5
|
+
/**
|
|
6
|
+
* Create the `run` command for executing code in the sandbox.
|
|
7
|
+
*
|
|
8
|
+
* The run command:
|
|
9
|
+
* 1. Builds the entry point (with type checking by default)
|
|
10
|
+
* 2. Dynamically imports the bundle
|
|
11
|
+
* 3. If a `main` export exists, calls it with a RunContext
|
|
12
|
+
* 4. Captures all console output (log, warn, error)
|
|
13
|
+
* 5. Returns the captured output and any return value from main()
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
* run [entry] [--skip-typecheck|-s] [--timeout|-t <ms>] [-- args...]
|
|
17
|
+
*
|
|
18
|
+
* Code can be written in two styles:
|
|
19
|
+
*
|
|
20
|
+
* 1. Script style (top-level code, runs on import):
|
|
21
|
+
* ```ts
|
|
22
|
+
* console.log("Hello from script!");
|
|
23
|
+
* const result = 2 + 2;
|
|
24
|
+
* console.log("Result:", result);
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* 2. Main function style (with context access):
|
|
28
|
+
* ```ts
|
|
29
|
+
* import type { RunContext } from "sandlot";
|
|
30
|
+
*
|
|
31
|
+
* export async function main(ctx: RunContext) {
|
|
32
|
+
* ctx.log("Reading file...");
|
|
33
|
+
* const content = await ctx.fs.readFile("/data/input.txt");
|
|
34
|
+
* ctx.log("Content:", content);
|
|
35
|
+
* return { success: true };
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function createRunCommand(deps: CommandDeps): import("just-bash/browser").Command;
|
|
40
|
+
//# sourceMappingURL=run.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/commands/run.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,KAAK,EAAE,WAAW,EAAc,MAAM,SAAS,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,uCAwMjD"}
|