Skip to content

Commit ba584c1

Browse files
FisherXZclaude
andcommitted
fix(js-sdk): forward name param and expose names in createSnapshot
Adds SnapshotCreateOpts with an optional name field, threads it through to the POST body, and adds names[] to SnapshotInfo so callers can create named snapshots and read back their assigned aliases. Also fixes SnapshotPaginator.nextItems() which had the same names omission. Fixes #1249 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 8d83482 commit ba584c1

2 files changed

Lines changed: 31 additions & 4 deletions

File tree

packages/js-sdk/src/sandbox/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import {
2020
SandboxListOpts,
2121
SandboxPaginator,
2222
SandboxBetaCreateOpts,
23-
SandboxApiOpts,
2423
SnapshotListOpts,
24+
SnapshotCreateOpts,
2525
SnapshotInfo,
2626
SnapshotPaginator,
2727
} from './sandboxApi'
@@ -621,7 +621,7 @@ export class Sandbox extends SandboxApi {
621621
* const newSandbox = await Sandbox.create(snapshot.snapshotId)
622622
* ```
623623
*/
624-
async createSnapshot(opts?: SandboxApiOpts): Promise<SnapshotInfo> {
624+
async createSnapshot(opts?: SnapshotCreateOpts): Promise<SnapshotInfo> {
625625
return await SandboxApi.createSnapshot(
626626
this.sandboxId,
627627
this.resolveApiOpts(opts)

packages/js-sdk/src/sandbox/sandboxApi.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,22 @@ export interface SnapshotListOpts extends SandboxApiOpts {
267267
nextToken?: string
268268
}
269269

270+
/**
271+
* Options for creating a snapshot.
272+
*/
273+
export interface SnapshotCreateOpts extends SandboxApiOpts {
274+
/**
275+
* Optional human-readable name for the snapshot template.
276+
*
277+
* If a snapshot template with this name already exists, a new build will be
278+
* assigned to the existing template instead of creating a new one.
279+
*
280+
* The name must be unique within your team. Once assigned, the snapshot can
281+
* be used with {@link Sandbox.create} via `team-slug/name`.
282+
*/
283+
name?: string
284+
}
285+
270286
/**
271287
* Information about a snapshot.
272288
*/
@@ -276,6 +292,13 @@ export interface SnapshotInfo {
276292
* Can be used with Sandbox.create() to create a new sandbox from this snapshot.
277293
*/
278294
snapshotId: string
295+
296+
/**
297+
* Full namespaced names assigned to this snapshot (e.g. `["team-slug/my-snapshot:default"]`).
298+
* Present when the snapshot was created with a `name` option.
299+
* Use any entry with {@link Sandbox.create} to start a sandbox from this snapshot by name.
300+
*/
301+
names: string[]
279302
}
280303

281304
/**
@@ -687,7 +710,7 @@ export class SandboxApi {
687710
*/
688711
static async createSnapshot(
689712
sandboxId: string,
690-
opts?: SandboxApiOpts
713+
opts?: SnapshotCreateOpts
691714
): Promise<SnapshotInfo> {
692715
const config = new ConnectionConfig(opts)
693716
const client = new ApiClient(config)
@@ -698,7 +721,9 @@ export class SandboxApi {
698721
sandboxID: sandboxId,
699722
},
700723
},
701-
body: {},
724+
body: {
725+
...(opts?.name && { name: opts.name }),
726+
},
702727
signal: config.getSignal(opts?.requestTimeoutMs),
703728
})
704729

@@ -713,6 +738,7 @@ export class SandboxApi {
713738

714739
return {
715740
snapshotId: res.data!.snapshotID,
741+
names: res.data!.names,
716742
}
717743
}
718744

@@ -1038,6 +1064,7 @@ export class SnapshotPaginator extends BasePaginator<SnapshotInfo> {
10381064
return (res.data ?? []).map(
10391065
(snapshot: components['schemas']['SnapshotInfo']) => ({
10401066
snapshotId: snapshot.snapshotID,
1067+
names: snapshot.names,
10411068
})
10421069
)
10431070
}

0 commit comments

Comments
 (0)