@upstash/box 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Upstash, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,226 @@
1
+ # @upstash/box
2
+
3
+ TypeScript SDK for [Upstash Box](https://upstash.com/docs/box) — create sandboxed AI coding agents with streaming, structured output, file I/O, git operations, and snapshots.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @upstash/box
9
+ ```
10
+
11
+ ## Quick start
12
+
13
+ ```ts
14
+ import { Box, Runtime, ClaudeCode } from "@upstash/box";
15
+
16
+ const box = await Box.create({
17
+ runtime: Runtime.Node,
18
+ agent: {
19
+ model: ClaudeCode.Sonnet_4_5,
20
+ apiKey: process.env.CLAUDE_KEY!,
21
+ },
22
+ });
23
+
24
+ const run = await box.agent.run({
25
+ prompt: "Create a hello world Express server",
26
+ onStream: (chunk) => process.stdout.write(chunk),
27
+ });
28
+
29
+ console.log(await run.result());
30
+ await box.delete();
31
+ ```
32
+
33
+ ## Authentication
34
+
35
+ Pass `apiKey` in the config or set the `UPSTASH_BOX_API_KEY` environment variable.
36
+
37
+ ## API
38
+
39
+ ### Static methods
40
+
41
+ #### `Box.create(config: BoxConfig): Promise<Box>`
42
+
43
+ Create a new sandboxed box.
44
+
45
+ ```ts
46
+ const box = await Box.create({
47
+ apiKey: "abx_...", // or set UPSTASH_BOX_API_KEY
48
+ runtime: Runtime.Node, // node, python, golang, ruby, rust
49
+ agent: {
50
+ model: ClaudeCode.Sonnet_4_5,
51
+ apiKey: process.env.CLAUDE_KEY!,
52
+ },
53
+ git: { token: process.env.GITHUB_TOKEN! },
54
+ env: { NODE_ENV: "production" },
55
+ timeout: 600000,
56
+ debug: false,
57
+ });
58
+ ```
59
+
60
+ #### `Box.get(boxId: string, options?: BoxGetOptions): Promise<Box>`
61
+
62
+ Reconnect to an existing box by ID.
63
+
64
+ ```ts
65
+ const box = await Box.get("box_abc123");
66
+ ```
67
+
68
+ #### `Box.list(options?: ListOptions): Promise<BoxData[]>`
69
+
70
+ List all boxes for the authenticated user.
71
+
72
+ ```ts
73
+ const boxes = await Box.list();
74
+ ```
75
+
76
+ #### `Box.fromSnapshot(snapshotId: string, config: BoxConfig): Promise<Box>`
77
+
78
+ Create a new box from a saved snapshot.
79
+
80
+ ```ts
81
+ const box = await Box.fromSnapshot("snap_abc123", {
82
+ agent: { model: ClaudeCode.Sonnet_4_5, apiKey: process.env.CLAUDE_KEY! },
83
+ });
84
+ ```
85
+
86
+ ### Agent
87
+
88
+ #### `box.agent.run(options: RunOptions): Promise<Run>`
89
+
90
+ Run the AI agent with a prompt. Supports streaming, structured output with Zod schemas, timeouts, retries, tool use callbacks, and webhooks.
91
+
92
+ ```ts
93
+ // Streaming
94
+ const run = await box.agent.run({
95
+ prompt: "Fix the bug in auth.ts",
96
+ onStream: (chunk) => process.stdout.write(chunk),
97
+ });
98
+
99
+ // Structured output
100
+ import { z } from "zod";
101
+
102
+ const schema = z.object({
103
+ name: z.string(),
104
+ score: z.number(),
105
+ });
106
+
107
+ const run = await box.agent.run({
108
+ prompt: "Analyze this candidate",
109
+ responseSchema: schema,
110
+ });
111
+ const result = await run.result(); // typed as { name: string, score: number }
112
+ ```
113
+
114
+ #### `box.exec(command: string): Promise<Run>`
115
+
116
+ Execute a shell command in the box.
117
+
118
+ ```ts
119
+ const run = await box.exec("node index.js");
120
+ console.log(await run.result());
121
+ ```
122
+
123
+ ### Files
124
+
125
+ ```ts
126
+ await box.files.write({ path: "hello.txt", content: "Hello!" });
127
+ const content = await box.files.read("hello.txt");
128
+ const entries = await box.files.list(".");
129
+ await box.files.upload([{ path: "./local.txt", destination: "remote.txt" }]);
130
+ await box.files.download({ path: "output/" });
131
+ ```
132
+
133
+ ### Git
134
+
135
+ ```ts
136
+ await box.git.clone({ repo: "https://github.com/user/repo", branch: "main" });
137
+ const diff = await box.git.diff();
138
+ const status = await box.git.status();
139
+ await box.git.commit({ message: "feat: add feature" });
140
+ await box.git.push({ branch: "main" });
141
+ const pr = await box.git.createPR({ title: "New feature", body: "Description" });
142
+ ```
143
+
144
+ ### Lifecycle
145
+
146
+ ```ts
147
+ await box.stop(); // Pause (preserves state)
148
+ await box.start(); // Resume
149
+ await box.delete(); // Permanent delete
150
+ const { status } = await box.getStatus();
151
+ ```
152
+
153
+ ### Snapshots
154
+
155
+ ```ts
156
+ const snapshot = await box.snapshot({ name: "checkpoint-1" });
157
+ const snapshots = await box.listSnapshots();
158
+ await box.deleteSnapshot(snapshot.id);
159
+ ```
160
+
161
+ ### Run object
162
+
163
+ Every `agent.run()` and `exec()` call returns a `Run` object:
164
+
165
+ ```ts
166
+ const run = await box.agent.run({ prompt: "..." });
167
+
168
+ run.id; // Run ID
169
+ await run.result(); // Final output (typed if schema provided)
170
+ await run.status(); // "running" | "completed" | "failed" | "cancelled"
171
+ await run.cost(); // { tokens, computeMs, totalUsd }
172
+ await run.cancel(); // Abort
173
+ await run.logs(); // Filtered log entries
174
+
175
+ for await (const chunk of run.stream()) {
176
+ process.stdout.write(chunk);
177
+ }
178
+ ```
179
+
180
+ ## Models
181
+
182
+ ### Claude Code
183
+
184
+ | Enum | Value |
185
+ |------|-------|
186
+ | `ClaudeCode.Opus_4_5` | `claude/opus_4_5` |
187
+ | `ClaudeCode.Opus_4_6` | `claude/opus_4_6` |
188
+ | `ClaudeCode.Sonnet_4` | `claude/sonnet_4` |
189
+ | `ClaudeCode.Sonnet_4_5` | `claude/sonnet_4_5` |
190
+ | `ClaudeCode.Haiku_4_5` | `claude/haiku_4_5` |
191
+
192
+ ### OpenAI Codex
193
+
194
+ | Enum | Value |
195
+ |------|-------|
196
+ | `OpenAICodex.GPT_5_3_Codex` | `openai/gpt-5.3-codex` |
197
+ | `OpenAICodex.GPT_5_3_Codex_Spark` | `openai/gpt-5.3-codex-spark` |
198
+ | `OpenAICodex.GPT_5_2_Codex` | `openai/gpt-5.2-codex` |
199
+ | `OpenAICodex.GPT_5_1_Codex_Max` | `openai/gpt-5.1-codex-max` |
200
+
201
+ ## Runtimes
202
+
203
+ | Enum | Value |
204
+ |------|-------|
205
+ | `Runtime.Node` | `node` |
206
+ | `Runtime.Python` | `python` |
207
+ | `Runtime.Golang` | `golang` |
208
+ | `Runtime.Ruby` | `ruby` |
209
+ | `Runtime.Rust` | `rust` |
210
+
211
+ ## Examples
212
+
213
+ See the [`examples/`](./examples) directory for complete working examples:
214
+
215
+ - `basic.ts` — Create a box, run an agent, read output
216
+ - `streaming.ts` — Parallel boxes with structured output (Zod)
217
+ - `file-upload.ts` — Upload local files into the box
218
+ - `git-pr.ts` — Clone a repo, make changes, create a PR
219
+ - `snapshot-restore.ts` — Save and restore workspace state
220
+ - `webhook.ts` — Fire-and-forget with webhook callbacks
221
+ - `multi-runtime.ts` — Run across different runtimes
222
+ - `mcp-skills.ts` — Attach MCP servers to a box
223
+
224
+ ## License
225
+
226
+ MIT
@@ -0,0 +1,25 @@
1
+ import { vi } from "vitest";
2
+ import { Box } from "../client.js";
3
+ import type { BoxData } from "../types.js";
4
+ export declare const TEST_CONFIG: {
5
+ readonly apiKey: "test-api-key";
6
+ readonly baseUrl: "https://test.api.example.com";
7
+ readonly agent: {
8
+ readonly model: "claude/sonnet_4_5";
9
+ readonly apiKey: "test-agent-key";
10
+ };
11
+ };
12
+ export declare const TEST_BOX_DATA: BoxData;
13
+ export declare function mockResponse(body: unknown, status?: number): Response;
14
+ export declare function mockSSEResponse(events: Array<{
15
+ event: string;
16
+ data: unknown;
17
+ }>): Response;
18
+ /**
19
+ * Creates a real Box instance by mocking the fetch for Box.get().
20
+ */
21
+ export declare function createTestBox(overrides?: Partial<BoxData>): Promise<{
22
+ box: Box;
23
+ fetchMock: ReturnType<typeof vi.fn>;
24
+ }>;
25
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/__tests__/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,eAAO,MAAM,WAAW;;;;;;;CAId,CAAC;AAEX,eAAO,MAAM,aAAa,EAAE,OAO3B,CAAC;AAEF,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,SAAM,GAAG,QAAQ,CAoBlE;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,KAAK,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,GAAG,QAAQ,CA8BzF;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,SAAS,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAC3B,OAAO,CAAC;IAAE,GAAG,EAAE,GAAG,CAAC;IAAC,SAAS,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAA;CAAE,CAAC,CAS5D"}
@@ -0,0 +1,80 @@
1
+ import { vi } from "vitest";
2
+ import { Box } from "../client.js";
3
+ export const TEST_CONFIG = {
4
+ apiKey: "test-api-key",
5
+ baseUrl: "https://test.api.example.com",
6
+ agent: { model: "claude/sonnet_4_5", apiKey: "test-agent-key" },
7
+ };
8
+ export const TEST_BOX_DATA = {
9
+ id: "box-123",
10
+ model: "claude/sonnet_4_5",
11
+ runtime: "node",
12
+ status: "running",
13
+ created_at: "2025-01-01T00:00:00Z",
14
+ updated_at: "2025-01-01T00:00:00Z",
15
+ };
16
+ export function mockResponse(body, status = 200) {
17
+ const json = JSON.stringify(body);
18
+ return {
19
+ ok: status >= 200 && status < 300,
20
+ status,
21
+ statusText: status === 200 ? "OK" : "Error",
22
+ headers: new Headers({ "content-type": "application/json" }),
23
+ json: () => Promise.resolve(body),
24
+ text: () => Promise.resolve(json),
25
+ body: null,
26
+ bodyUsed: false,
27
+ arrayBuffer: () => Promise.resolve(new ArrayBuffer(0)),
28
+ blob: () => Promise.resolve(new Blob()),
29
+ formData: () => Promise.resolve(new FormData()),
30
+ clone: () => mockResponse(body, status),
31
+ redirected: false,
32
+ type: "basic",
33
+ url: "",
34
+ bytes: () => Promise.resolve(new Uint8Array()),
35
+ };
36
+ }
37
+ export function mockSSEResponse(events) {
38
+ const lines = events
39
+ .map((e) => `event: ${e.event}\ndata: ${JSON.stringify(e.data)}\n\n`)
40
+ .join("");
41
+ const encoder = new TextEncoder();
42
+ const stream = new ReadableStream({
43
+ start(controller) {
44
+ controller.enqueue(encoder.encode(lines));
45
+ controller.close();
46
+ },
47
+ });
48
+ return {
49
+ ok: true,
50
+ status: 200,
51
+ statusText: "OK",
52
+ headers: new Headers({ "content-type": "text/event-stream" }),
53
+ json: () => Promise.reject(new Error("SSE response")),
54
+ text: () => Promise.resolve(lines),
55
+ body: stream,
56
+ bodyUsed: false,
57
+ arrayBuffer: () => Promise.resolve(new ArrayBuffer(0)),
58
+ blob: () => Promise.resolve(new Blob()),
59
+ formData: () => Promise.resolve(new FormData()),
60
+ clone: () => mockSSEResponse(events),
61
+ redirected: false,
62
+ type: "basic",
63
+ url: "",
64
+ bytes: () => Promise.resolve(new Uint8Array()),
65
+ };
66
+ }
67
+ /**
68
+ * Creates a real Box instance by mocking the fetch for Box.get().
69
+ */
70
+ export async function createTestBox(overrides) {
71
+ const data = { ...TEST_BOX_DATA, ...overrides };
72
+ const fetchMock = vi.fn().mockResolvedValueOnce(mockResponse(data));
73
+ vi.stubGlobal("fetch", fetchMock);
74
+ const box = await Box.get(data.id, {
75
+ apiKey: TEST_CONFIG.apiKey,
76
+ baseUrl: TEST_CONFIG.baseUrl,
77
+ });
78
+ return { box, fetchMock };
79
+ }
80
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/__tests__/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAGnC,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,MAAM,EAAE,cAAc;IACtB,OAAO,EAAE,8BAA8B;IACvC,KAAK,EAAE,EAAE,KAAK,EAAE,mBAAmB,EAAE,MAAM,EAAE,gBAAgB,EAAE;CACvD,CAAC;AAEX,MAAM,CAAC,MAAM,aAAa,GAAY;IACpC,EAAE,EAAE,SAAS;IACb,KAAK,EAAE,mBAAmB;IAC1B,OAAO,EAAE,MAAM;IACf,MAAM,EAAE,SAAS;IACjB,UAAU,EAAE,sBAAsB;IAClC,UAAU,EAAE,sBAAsB;CACnC,CAAC;AAEF,MAAM,UAAU,YAAY,CAAC,IAAa,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UAAU,aAAa,CACjC,SAA4B;IAE5B,MAAM,IAAI,GAAG,EAAE,GAAG,aAAa,EAAE,GAAG,SAAS,EAAE,CAAC;IAChD,MAAM,SAAS,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,qBAAqB,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;IACpE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAClC,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE;QACjC,MAAM,EAAE,WAAW,CAAC,MAAM;QAC1B,OAAO,EAAE,WAAW,CAAC,OAAO;KAC7B,CAAC,CAAC;IACH,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,229 @@
1
+ import type { BoxConfig, BoxData, BoxGetOptions, BoxRunData, ListOptions, RunOptions, StreamOptions, RunStatus, RunCost, RunLog, SchemaLike, FileEntry, GitCloneOptions, GitPROptions, GitCommitResult, PullRequest, LogEntry, UploadFileEntry, Snapshot } from "./types.js";
2
+ /**
3
+ * Error thrown by the Box SDK
4
+ */
5
+ export declare class BoxError extends Error {
6
+ statusCode?: number | undefined;
7
+ constructor(message: string, statusCode?: number | undefined);
8
+ }
9
+ /**
10
+ * A run represents a single agent or shell execution.
11
+ * Returned by box.agent.run() and box.exec().
12
+ */
13
+ export declare class Run<T = string> {
14
+ readonly type: "agent" | "shell";
15
+ /** @internal */
16
+ _id: string;
17
+ /** @internal */
18
+ _result: T | null;
19
+ /** @internal */
20
+ _status: RunStatus;
21
+ /** @internal */
22
+ _inputTokens: number;
23
+ /** @internal */
24
+ _outputTokens: number;
25
+ /** @internal */
26
+ _computeMs: number;
27
+ /** @internal */
28
+ _box: Box;
29
+ /** @internal */
30
+ _abortController?: AbortController;
31
+ /** @internal */
32
+ _startTime: number;
33
+ /** The run ID. Initially a local UUID, replaced by backend run_id from run_start event. */
34
+ get id(): string;
35
+ /** @internal */
36
+ constructor(box: Box, type: "agent" | "shell", id?: string);
37
+ /**
38
+ * Get the current run status. Polls the backend for the latest status if the run may still be active.
39
+ */
40
+ status(): Promise<RunStatus>;
41
+ /**
42
+ * Get the run result. Returns the typed output when responseSchema was provided.
43
+ */
44
+ result(): Promise<T>;
45
+ /**
46
+ * Get token usage and cost information. Fetches from backend when available.
47
+ */
48
+ cost(): Promise<RunCost>;
49
+ /**
50
+ * Cancel a running execution.
51
+ */
52
+ cancel(): Promise<void>;
53
+ /**
54
+ * Retrieve logs for this run.
55
+ */
56
+ logs(): Promise<RunLog[]>;
57
+ }
58
+ /**
59
+ * A sandboxed AI coding environment.
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * import { Box, Runtime, ClaudeCode } from "@upstash/box";
64
+ *
65
+ * const box = await Box.create({
66
+ * runtime: Runtime.Node,
67
+ * agent: { model: ClaudeCode.Sonnet_4_5, apiKey: process.env.CLAUDE_KEY! },
68
+ * });
69
+ *
70
+ * // Non-streaming
71
+ * const run = await box.agent.run({ prompt: "Fix the bug in auth.ts" });
72
+ * console.log(await run.result());
73
+ *
74
+ * // Streaming
75
+ * for await (const chunk of box.agent.stream({ prompt: "Add tests" })) {
76
+ * process.stdout.write(chunk);
77
+ * }
78
+ *
79
+ * await box.delete();
80
+ * ```
81
+ */
82
+ export declare class Box {
83
+ readonly id: string;
84
+ /** Agent operations namespace */
85
+ readonly agent: {
86
+ run<T>(options: RunOptions<T> & {
87
+ responseSchema: SchemaLike<T>;
88
+ }): Promise<Run<T>>;
89
+ run(options: RunOptions): Promise<Run<string>>;
90
+ stream(options: StreamOptions): AsyncGenerator<string>;
91
+ };
92
+ /** File operations namespace */
93
+ readonly files: {
94
+ read: (path: string) => Promise<string>;
95
+ write: (options: {
96
+ path: string;
97
+ content: string;
98
+ }) => Promise<void>;
99
+ list: (path?: string) => Promise<FileEntry[]>;
100
+ upload: (files: UploadFileEntry[]) => Promise<void>;
101
+ download: (options?: {
102
+ path?: string;
103
+ }) => Promise<void>;
104
+ };
105
+ /** Git operations namespace */
106
+ readonly git: {
107
+ clone: (options: GitCloneOptions) => Promise<void>;
108
+ diff: () => Promise<string>;
109
+ status: () => Promise<string>;
110
+ commit: (options: {
111
+ message: string;
112
+ }) => Promise<GitCommitResult>;
113
+ push: (options?: {
114
+ branch?: string;
115
+ }) => Promise<void>;
116
+ createPR: (options: GitPROptions) => Promise<PullRequest>;
117
+ };
118
+ private _baseUrl;
119
+ private _headers;
120
+ private _timeout;
121
+ private _debug;
122
+ private _gitToken?;
123
+ private _isAgentConfigured;
124
+ private constructor();
125
+ /**
126
+ * Create a new sandboxed box.
127
+ */
128
+ static create(config: BoxConfig): Promise<Box>;
129
+ /**
130
+ * List all boxes for the authenticated user.
131
+ */
132
+ static list(options?: ListOptions): Promise<BoxData[]>;
133
+ /**
134
+ * Get an existing box by ID.
135
+ */
136
+ static get(boxId: string, options?: BoxGetOptions): Promise<Box>;
137
+ /** @internal */
138
+ _run<T>(options: RunOptions<T>): Promise<Run<T | string>>;
139
+ private _runWithRetries;
140
+ private _executeRun;
141
+ /** @internal */
142
+ _stream(options: StreamOptions): AsyncGenerator<string>;
143
+ private _processStreamEvent;
144
+ /**
145
+ * Execute an OS-level command in the box.
146
+ *
147
+ * @example
148
+ * ```ts
149
+ * const run = await box.exec("node /work/index.js");
150
+ * console.log(await run.result());
151
+ * console.log(await run.status()); // "completed"
152
+ * ```
153
+ */
154
+ exec(command: string): Promise<Run<string>>;
155
+ private static readonly WORKSPACE;
156
+ private _resolvePath;
157
+ private _readFile;
158
+ private _writeFile;
159
+ private _listFiles;
160
+ private _uploadFiles;
161
+ private _downloadFiles;
162
+ /**
163
+ * Get the current box status.
164
+ */
165
+ getStatus(): Promise<{
166
+ status: string;
167
+ }>;
168
+ /**
169
+ * Stop the box (release compute, preserve state).
170
+ */
171
+ stop(): Promise<void>;
172
+ /**
173
+ * Start a stopped box.
174
+ */
175
+ start(): Promise<void>;
176
+ /**
177
+ * Delete this box permanently.
178
+ */
179
+ delete(): Promise<void>;
180
+ /**
181
+ * Save workspace state as a snapshot for later restore.
182
+ * Creates the snapshot asynchronously and polls until ready.
183
+ */
184
+ snapshot(options: {
185
+ name: string;
186
+ }): Promise<Snapshot>;
187
+ /**
188
+ * List all snapshots for this box.
189
+ */
190
+ listSnapshots(): Promise<Snapshot[]>;
191
+ /**
192
+ * Delete a snapshot.
193
+ */
194
+ deleteSnapshot(snapshotId: string): Promise<void>;
195
+ /**
196
+ * Create a new box from a saved snapshot.
197
+ */
198
+ static fromSnapshot(snapshotId: string, config: BoxConfig): Promise<Box>;
199
+ /**
200
+ * Get structured logs for this box.
201
+ */
202
+ logs(options?: {
203
+ offset?: number;
204
+ limit?: number;
205
+ }): Promise<LogEntry[]>;
206
+ /**
207
+ * List all runs for this box, newest first.
208
+ */
209
+ listRuns(): Promise<BoxRunData[]>;
210
+ private log;
211
+ /** @internal */
212
+ _request<T>(method: string, path: string, options?: {
213
+ body?: unknown;
214
+ timeout?: number;
215
+ }): Promise<T>;
216
+ private _gitClone;
217
+ private _gitDiff;
218
+ private _gitStatus;
219
+ private _gitCommit;
220
+ private _gitPush;
221
+ private _gitCreatePR;
222
+ }
223
+ /** @internal */
224
+ export declare function extractSchemaShape(schema: SchemaLike<unknown>): string | null;
225
+ /** @internal */
226
+ export declare function zodTypeToExample(field: unknown): string;
227
+ /** @internal */
228
+ export declare function parseErrorResponse(response: Response): Promise<string>;
229
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,SAAS,EACT,OAAO,EACP,aAAa,EACb,UAAU,EACV,WAAW,EACX,UAAU,EACV,aAAa,EAEb,SAAS,EACT,OAAO,EACP,MAAM,EACN,UAAU,EAKV,SAAS,EACT,eAAe,EACf,YAAY,EACZ,eAAe,EACf,WAAW,EACX,QAAQ,EACR,eAAe,EACf,QAAQ,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