@lightningai/sdk 2026.5.12 → 2026.5.21
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 +90 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/lightning_cloud/openapi/SandboxesService.d.ts +119 -1
- package/dist/lightning_cloud/openapi/SandboxesService.d.ts.map +1 -1
- package/dist/lightning_cloud/openapi/SandboxesService.js +158 -0
- package/dist/lightning_cloud/openapi/SandboxesService.js.map +1 -1
- package/dist/lightning_cloud/openapi/data-contracts.d.ts +214 -0
- package/dist/lightning_cloud/openapi/data-contracts.d.ts.map +1 -1
- package/dist/process.d.ts +115 -0
- package/dist/process.d.ts.map +1 -0
- package/dist/process.js +254 -0
- package/dist/process.js.map +1 -0
- package/dist/pty.d.ts +121 -0
- package/dist/pty.d.ts.map +1 -0
- package/dist/pty.js +264 -0
- package/dist/pty.js.map +1 -0
- package/dist/sandbox.d.ts +17 -0
- package/dist/sandbox.d.ts.map +1 -1
- package/dist/sandbox.js +29 -0
- package/dist/sandbox.js.map +1 -1
- package/dist/types.d.ts +67 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -2,6 +2,22 @@ export interface SandboxesServiceCreateSandboxDirectoryBody {
|
|
|
2
2
|
organizationId?: string;
|
|
3
3
|
path?: string;
|
|
4
4
|
}
|
|
5
|
+
export interface SandboxesServiceCreateSandboxSnapshotBody {
|
|
6
|
+
organizationId?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Optional expiration in milliseconds. When unset, the platform default applies.
|
|
9
|
+
* Use 0 to request no expiration.
|
|
10
|
+
* @format uint64
|
|
11
|
+
*/
|
|
12
|
+
expiration?: string;
|
|
13
|
+
/** Optional tar exclude override for this snapshot. When unset, the platform default applies. */
|
|
14
|
+
excludes?: string[];
|
|
15
|
+
/**
|
|
16
|
+
* project_id is required: snapshots are stored in the cluster bucket
|
|
17
|
+
* under the project's prefix and authorization is project-scoped.
|
|
18
|
+
*/
|
|
19
|
+
projectId?: string;
|
|
20
|
+
}
|
|
5
21
|
export interface SandboxesServiceExtendSandboxTimeoutBody {
|
|
6
22
|
organizationId?: string;
|
|
7
23
|
/**
|
|
@@ -10,6 +26,43 @@ export interface SandboxesServiceExtendSandboxTimeoutBody {
|
|
|
10
26
|
*/
|
|
11
27
|
timeout?: string;
|
|
12
28
|
}
|
|
29
|
+
export interface SandboxesServiceFinalizeSandboxSnapshotBody {
|
|
30
|
+
organizationId?: string;
|
|
31
|
+
/**
|
|
32
|
+
* sha256 digest of the manifest body the agent just PUT to
|
|
33
|
+
* object_key. Lets the controlplane verify it's actually there
|
|
34
|
+
* before flipping the row to "ready".
|
|
35
|
+
*/
|
|
36
|
+
manifestSha256?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Total logical size of the snapshot — sum of all unique blob
|
|
39
|
+
* sizes plus the manifest body. Surfaced in the row's size_bytes
|
|
40
|
+
* for billing/display.
|
|
41
|
+
* @format uint64
|
|
42
|
+
*/
|
|
43
|
+
sizeBytes?: string;
|
|
44
|
+
/**
|
|
45
|
+
* rootfs digest the snapshot was captured against; persisted on
|
|
46
|
+
* the row so restore-compatibility check doesn't have to fetch
|
|
47
|
+
* and parse the manifest.
|
|
48
|
+
*/
|
|
49
|
+
rootfsDigest?: string;
|
|
50
|
+
}
|
|
51
|
+
export interface SandboxesServiceGetSandboxSnapshotBlobDownloadUrlsBody {
|
|
52
|
+
organizationId?: string;
|
|
53
|
+
sha256Digests?: string[];
|
|
54
|
+
}
|
|
55
|
+
export interface SandboxesServiceGetSandboxSnapshotBlobUploadUrlsBody {
|
|
56
|
+
organizationId?: string;
|
|
57
|
+
/**
|
|
58
|
+
* sha256 hex digests of the unique blobs the caller wants to upload.
|
|
59
|
+
* The server checks each against the cluster blob store; missing
|
|
60
|
+
* ones get presigned URLs returned in `upload_urls`, present ones
|
|
61
|
+
* are echoed in `existing_digests` so the caller skips them.
|
|
62
|
+
* Empty list rejected.
|
|
63
|
+
*/
|
|
64
|
+
sha256Digests?: string[];
|
|
65
|
+
}
|
|
13
66
|
export interface SandboxesServiceRunSandboxCommandBody {
|
|
14
67
|
organizationId?: string;
|
|
15
68
|
command?: string;
|
|
@@ -19,6 +72,28 @@ export interface SandboxesServiceRunSandboxCommandBody {
|
|
|
19
72
|
env?: Record<string, string>;
|
|
20
73
|
sudo?: boolean;
|
|
21
74
|
}
|
|
75
|
+
export interface SandboxesServiceStopSandboxBody {
|
|
76
|
+
organizationId?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Optional project the auto-snapshot is written under for persistent
|
|
79
|
+
* sandboxes. When unset, the controlplane falls back to the project the
|
|
80
|
+
* sandbox was originally created in (recorded on the underlying server
|
|
81
|
+
* row). Ignored for non-persistent sandboxes (no snapshot is taken in
|
|
82
|
+
* that case).
|
|
83
|
+
*/
|
|
84
|
+
projectId?: string;
|
|
85
|
+
}
|
|
86
|
+
export interface SandboxesServiceUpdateSandboxBody {
|
|
87
|
+
organizationId?: string;
|
|
88
|
+
/**
|
|
89
|
+
* When true, resume a previously stopped persistent sandbox from
|
|
90
|
+
* its most recent auto-snapshot. The sandbox id is preserved. The
|
|
91
|
+
* call is a no-op (returns the current Sandbox) when the sandbox
|
|
92
|
+
* is already running. Returns an error when the sandbox is not
|
|
93
|
+
* persistent or has no resumable auto-snapshot.
|
|
94
|
+
*/
|
|
95
|
+
resume?: boolean;
|
|
96
|
+
}
|
|
22
97
|
export interface SandboxesServiceWriteSandboxFileBody {
|
|
23
98
|
organizationId?: string;
|
|
24
99
|
path?: string;
|
|
@@ -197,8 +272,33 @@ export interface V1CreateSandboxRequest {
|
|
|
197
272
|
* network policy.
|
|
198
273
|
*/
|
|
199
274
|
networkPolicy?: V1NetworkPolicy;
|
|
275
|
+
snapshotId?: string;
|
|
276
|
+
/**
|
|
277
|
+
* Whether the sandbox persists its state across restarts via automatic
|
|
278
|
+
* snapshots. Defaults to true.
|
|
279
|
+
*
|
|
280
|
+
* When true, the controlplane automatically snapshots the sandbox on idle,
|
|
281
|
+
* sleep, or eviction, and transparently restores it (via the FUSE
|
|
282
|
+
* snapshot/restore path; see sandbox_fuse_snapshot_restore.md) the next
|
|
283
|
+
* time the sandbox id is accessed. This makes the sandbox id a durable
|
|
284
|
+
* handle suitable for long-lived workflow orchestration that may pause
|
|
285
|
+
* across step boundaries.
|
|
286
|
+
*
|
|
287
|
+
* When false, the sandbox is best-effort ephemeral: state is lost on
|
|
288
|
+
* stop, idle reclaim, or host reschedule.
|
|
289
|
+
*/
|
|
290
|
+
persistent?: boolean;
|
|
291
|
+
/**
|
|
292
|
+
* Project the sandbox is owned by. Recommended for persistent
|
|
293
|
+
* sandboxes — the controlplane needs a project to scope the
|
|
294
|
+
* auto-snapshot bucket prefix on idle eviction and on later
|
|
295
|
+
* StopSandbox calls without an explicit project_id. Optional for
|
|
296
|
+
* non-persistent sandboxes (no auto-snapshot is taken).
|
|
297
|
+
*/
|
|
298
|
+
projectId?: string;
|
|
200
299
|
}
|
|
201
300
|
export type V1DeleteSandboxResponse = object;
|
|
301
|
+
export type V1DeleteSandboxSnapshotResponse = object;
|
|
202
302
|
export type V1ExtendSandboxTimeoutResponse = object;
|
|
203
303
|
export interface V1GetSandboxCommandLogsResponse {
|
|
204
304
|
logs?: V1LogMessage[];
|
|
@@ -213,7 +313,26 @@ export interface V1GetSandboxCommandResponse {
|
|
|
213
313
|
export interface V1GetSandboxFileResponse {
|
|
214
314
|
content?: string;
|
|
215
315
|
}
|
|
316
|
+
export interface V1GetSandboxSnapshotBlobDownloadUrlsResponse {
|
|
317
|
+
downloadUrls?: V1SandboxSnapshotBlobDownloadUrl[];
|
|
318
|
+
}
|
|
319
|
+
export interface V1GetSandboxSnapshotBlobUploadUrlsResponse {
|
|
320
|
+
/** Presigned PUT URL per blob the caller still needs to upload. */
|
|
321
|
+
uploadUrls?: V1SandboxSnapshotBlobUploadUrl[];
|
|
322
|
+
/**
|
|
323
|
+
* sha256 digests already present in the cluster bucket. Caller
|
|
324
|
+
* skips upload for these.
|
|
325
|
+
*/
|
|
326
|
+
existingDigests?: string[];
|
|
327
|
+
}
|
|
216
328
|
export type V1KillSandboxCommandResponse = object;
|
|
329
|
+
export interface V1ListSandboxSnapshotsResponse {
|
|
330
|
+
snapshots?: V1SandboxSnapshot[];
|
|
331
|
+
nextPageToken?: string;
|
|
332
|
+
previousPageToken?: string;
|
|
333
|
+
/** @format int64 */
|
|
334
|
+
totalSize?: string;
|
|
335
|
+
}
|
|
217
336
|
export interface V1ListSandboxesResponse {
|
|
218
337
|
sandboxes?: V1Sandbox[];
|
|
219
338
|
nextPageToken?: string;
|
|
@@ -266,6 +385,17 @@ export interface V1Sandbox {
|
|
|
266
385
|
clusterId?: string;
|
|
267
386
|
instanceType?: string;
|
|
268
387
|
spot?: boolean;
|
|
388
|
+
/**
|
|
389
|
+
* Lifecycle status of the sandbox. In addition to the underlying
|
|
390
|
+
* server states (running, stopping, stopped, error, ...) the
|
|
391
|
+
* controlplane surfaces:
|
|
392
|
+
* - "paused": the sandbox is a persistent sandbox whose server
|
|
393
|
+
* row no longer exists, but whose auto-snapshot does.
|
|
394
|
+
* ListSandboxes and GetSandbox synthesise a Sandbox
|
|
395
|
+
* from the most recent auto-snapshot so the sandbox
|
|
396
|
+
* id keeps appearing in user-facing surfaces while it
|
|
397
|
+
* is hibernated. Resume via UpdateSandbox(resume=true).
|
|
398
|
+
*/
|
|
269
399
|
status?: string;
|
|
270
400
|
cloudspaceId?: string;
|
|
271
401
|
ports?: string[];
|
|
@@ -274,6 +404,90 @@ export interface V1Sandbox {
|
|
|
274
404
|
createdAt?: string;
|
|
275
405
|
/** @format date-time */
|
|
276
406
|
updatedAt?: string;
|
|
407
|
+
/**
|
|
408
|
+
* Mirrors CreateSandboxRequest.persistent. Reflects the durability
|
|
409
|
+
* setting the sandbox was created with. See
|
|
410
|
+
* sandbox_fuse_snapshot_restore.md for the lifecycle.
|
|
411
|
+
*/
|
|
412
|
+
persistent?: boolean;
|
|
413
|
+
}
|
|
414
|
+
export interface V1SandboxSnapshot {
|
|
415
|
+
id?: string;
|
|
416
|
+
organizationId?: string;
|
|
417
|
+
projectId?: string;
|
|
418
|
+
sourceSandboxId?: string;
|
|
419
|
+
/**
|
|
420
|
+
* status transitions on the controlplane:
|
|
421
|
+
* - "saving": row created, agent capture + S3 upload in progress.
|
|
422
|
+
* - "ready": tarball lives in object storage; restorable.
|
|
423
|
+
* - "failed": capture or upload failed; not restorable.
|
|
424
|
+
* Only "ready" snapshots may be used to create a new sandbox.
|
|
425
|
+
*/
|
|
426
|
+
status?: string;
|
|
427
|
+
/** @format uint64 */
|
|
428
|
+
sizeBytes?: string;
|
|
429
|
+
/** @format date-time */
|
|
430
|
+
createdAt?: string;
|
|
431
|
+
/** @format date-time */
|
|
432
|
+
updatedAt?: string;
|
|
433
|
+
/** @format date-time */
|
|
434
|
+
expiresAt?: string;
|
|
435
|
+
runtime?: string;
|
|
436
|
+
runtimeImage?: string;
|
|
437
|
+
rootfsDigest?: string;
|
|
438
|
+
tarExcludes?: string[];
|
|
439
|
+
/**
|
|
440
|
+
* True when this snapshot was auto-captured by the controlplane
|
|
441
|
+
* because its source sandbox was created with `persistent = true`
|
|
442
|
+
* and was stopped (via StopSandbox or idle/eviction). Auto-snapshots
|
|
443
|
+
* represent the durable state of a paused persistent sandbox: one
|
|
444
|
+
* current auto-snapshot per sandbox id, rotated in place on each
|
|
445
|
+
* capture. A persistent sandbox is resumed from its auto-snapshot
|
|
446
|
+
* via UpdateSandbox(resume=true), which preserves the sandbox id.
|
|
447
|
+
*
|
|
448
|
+
* User-initiated snapshots created via CreateSandboxSnapshot have
|
|
449
|
+
* this field set to false, and `source_sandbox_id` may point at a
|
|
450
|
+
* sandbox that has since been deleted.
|
|
451
|
+
*/
|
|
452
|
+
sourceSandboxPersistent?: boolean;
|
|
453
|
+
/**
|
|
454
|
+
* The source sandbox's instance type at capture time, in the form
|
|
455
|
+
* the controlplane persisted on `Server.Spec.InstanceType` (i.e. the
|
|
456
|
+
* post-translation sandbox-pool slug such as "cpu-sandbox-4").
|
|
457
|
+
* Replayed verbatim by UpdateSandbox(resume=true) so the resumed
|
|
458
|
+
* sandbox comes back with the same CPU / memory / disk shape as the
|
|
459
|
+
* original. Best-effort: empty for snapshots captured before this
|
|
460
|
+
* field landed; the resume path then falls back to a default.
|
|
461
|
+
*/
|
|
462
|
+
sourceSandboxInstanceType?: string;
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* SandboxSnapshotBlobDownloadUrl pairs a sha256 with its presigned GET
|
|
466
|
+
* URL. One per requested digest, in request order.
|
|
467
|
+
*/
|
|
468
|
+
export interface V1SandboxSnapshotBlobDownloadUrl {
|
|
469
|
+
sha256?: string;
|
|
470
|
+
url?: string;
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* SandboxSnapshotBlobUploadUrl pairs a sha256 digest with the presigned
|
|
474
|
+
* PUT URL the agent uses to push that blob. Digests are echoed back so
|
|
475
|
+
* the agent doesn't need to maintain its own index-to-URL mapping when
|
|
476
|
+
* it issues a batched request.
|
|
477
|
+
*/
|
|
478
|
+
export interface V1SandboxSnapshotBlobUploadUrl {
|
|
479
|
+
sha256?: string;
|
|
480
|
+
url?: string;
|
|
481
|
+
}
|
|
482
|
+
export interface V1StopSandboxResponse {
|
|
483
|
+
/**
|
|
484
|
+
* For sandboxes created with `persistent = true`, the id of the
|
|
485
|
+
* auto-snapshot the controlplane captured before stopping the
|
|
486
|
+
* server. Subsequent UpdateSandbox(resume=true) calls against the
|
|
487
|
+
* sandbox id will resume from this snapshot. Empty when the
|
|
488
|
+
* sandbox is non-persistent (no snapshot is taken in that case).
|
|
489
|
+
*/
|
|
490
|
+
autoSnapshotId?: string;
|
|
277
491
|
}
|
|
278
492
|
export type V1WriteSandboxFileResponse = object;
|
|
279
493
|
//# sourceMappingURL=data-contracts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-contracts.d.ts","sourceRoot":"","sources":["../../../src/lightning_cloud/openapi/data-contracts.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,0CAA0C;IACzD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,wCAAwC;IACvD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,qCAAqC;IACpD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,oCAAoC;IACnD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmFG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,SAAS;IACxB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,OAAO,CAAC,EAAE,WAAW,EAAE,CAAC;CACzB;AAED,MAAM,MAAM,gCAAgC,GAAG,MAAM,CAAC;AAEtD,MAAM,WAAW,sBAAsB;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,aAAa,CAAC,EAAE,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"data-contracts.d.ts","sourceRoot":"","sources":["../../../src/lightning_cloud/openapi/data-contracts.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,0CAA0C;IACzD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,yCAAyC;IACxD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iGAAiG;IACjG,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,wCAAwC;IACvD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,2CAA2C;IAC1D,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;OAKG;IACH,SAAS,CAAC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tB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB;;;;;;;;;;;;OAYG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC;;;;;;;;OAQG;IACH,yBAAyB,CAAC,EAAE,MAAM,CAAC;CACpC;AAED;;;GAGG;AACH,MAAM,WAAW,gCAAgC;IAC/C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;;GAKG;AACH,MAAM,WAAW,8BAA8B;IAC7C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,qBAAqB;IACpC;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,MAAM,0BAA0B,GAAG,MAAM,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { Command } from "./command.js";
|
|
2
|
+
import { PtyHandle } from "./pty.js";
|
|
3
|
+
import type { PtyConnectOpts, PtyCreateOpts, PtySessionInfo, RunCommandOpts } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Runtime context the `Sandbox` passes into a `SandboxProcess` so that
|
|
6
|
+
* the PTY namespace can build URLs, authenticate, and shell out to
|
|
7
|
+
* `runCommand` for session bookkeeping without importing the `Sandbox`
|
|
8
|
+
* class directly (avoids a circular dependency).
|
|
9
|
+
*
|
|
10
|
+
* Internal — not part of the public API surface.
|
|
11
|
+
*/
|
|
12
|
+
export interface SandboxProcessContext {
|
|
13
|
+
sandboxId: string;
|
|
14
|
+
organizationId: string;
|
|
15
|
+
/**
|
|
16
|
+
* Returns the resolved API key. Mirrors the lazy lookup used by the
|
|
17
|
+
* REST request helpers so that `Sandbox.configure` calls made after
|
|
18
|
+
* the sandbox object was created are still honored.
|
|
19
|
+
*/
|
|
20
|
+
getApiKey(): string;
|
|
21
|
+
/** Returns the resolved base URL (with no trailing slash). */
|
|
22
|
+
getBaseUrl(): string;
|
|
23
|
+
/** Forwards to `Sandbox.runCommand`. */
|
|
24
|
+
runCommand(opts: RunCommandOpts): Promise<Command>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* `sandbox.process` — interactive shell sessions on a sandbox.
|
|
28
|
+
*
|
|
29
|
+
* Mirrors the Daytona PTY surface so existing code shaped around it
|
|
30
|
+
* ports over with mechanical changes only. Under the hood, every method
|
|
31
|
+
* either opens a WebSocket against the controlplane's
|
|
32
|
+
* `/v1/clusters/{clusterId}/machines/{sandboxId}/attach` endpoint (which
|
|
33
|
+
* is bridged to the in-sandbox SSH server at port 2222) or shells out to
|
|
34
|
+
* `screen` via the existing `runCommand` REST API for session
|
|
35
|
+
* bookkeeping.
|
|
36
|
+
*
|
|
37
|
+
* Within a single SDK process every method works against a local
|
|
38
|
+
* registry. Cross-process session persistence (i.e. `connectPty` from
|
|
39
|
+
* a fresh process to a session created elsewhere) requires the sandbox
|
|
40
|
+
* runtime image to ship `screen` and the gliderlabs SSH login shell to
|
|
41
|
+
* honor `LAI_TERM_SESSION_NAME` / `LAI_TERM_RESTORE` — both of which
|
|
42
|
+
* are tracked as a follow-up to this initial parity work.
|
|
43
|
+
*/
|
|
44
|
+
export declare class SandboxProcess {
|
|
45
|
+
private readonly ctx;
|
|
46
|
+
/**
|
|
47
|
+
* Live handles bound to this `SandboxProcess`, keyed by their
|
|
48
|
+
* caller-chosen session name. Used by `connectPty` /
|
|
49
|
+
* `getPtySessionInfo` / `killPtySession` / `resizePtySession` to find
|
|
50
|
+
* an existing session before falling back to `screen -ls` over
|
|
51
|
+
* `runCommand`.
|
|
52
|
+
*/
|
|
53
|
+
private readonly handles;
|
|
54
|
+
constructor(ctx: SandboxProcessContext);
|
|
55
|
+
/**
|
|
56
|
+
* Create a new PTY session on the sandbox.
|
|
57
|
+
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* const pty = await sandbox.process.createPty({
|
|
60
|
+
* sessionName: "build",
|
|
61
|
+
* clusterId: sandbox.clusterId,
|
|
62
|
+
* cols: 120,
|
|
63
|
+
* rows: 30,
|
|
64
|
+
* onData: (chunk) => process.stdout.write(chunk),
|
|
65
|
+
* });
|
|
66
|
+
* await pty.waitForConnection();
|
|
67
|
+
* await pty.sendInput("npm test\n");
|
|
68
|
+
* const result = await pty.wait();
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
createPty(opts: PtyCreateOpts): Promise<PtyHandle>;
|
|
72
|
+
/**
|
|
73
|
+
* Reattach to a PTY session that was previously created by `createPty`.
|
|
74
|
+
*
|
|
75
|
+
* ```ts
|
|
76
|
+
* const pty = await sandbox.process.connectPty("build", sandbox.clusterId, {
|
|
77
|
+
* onData: (chunk) => process.stdout.write(chunk),
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
connectPty(sessionName: string, clusterId: string, opts?: PtyConnectOpts): Promise<PtyHandle>;
|
|
82
|
+
/**
|
|
83
|
+
* List PTY sessions on the sandbox. Implemented as a `screen -ls`
|
|
84
|
+
* call via {@link runCommand} so no new server endpoint is required.
|
|
85
|
+
* Returns the union of locally-tracked handles and remote `screen`
|
|
86
|
+
* sessions; locally-tracked handles include live `cols`/`rows`.
|
|
87
|
+
*/
|
|
88
|
+
listPtySessions(): Promise<PtySessionInfo[]>;
|
|
89
|
+
/**
|
|
90
|
+
* Look up a single PTY session.
|
|
91
|
+
*
|
|
92
|
+
* ```ts
|
|
93
|
+
* const info = await sandbox.process.getPtySessionInfo("build");
|
|
94
|
+
* console.log(info.active);
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
getPtySessionInfo(id: string): Promise<PtySessionInfo>;
|
|
98
|
+
/**
|
|
99
|
+
* Forcefully terminate a PTY session. Closes any live `PtyHandle` for
|
|
100
|
+
* the session within this SDK process and runs
|
|
101
|
+
* `screen -X -S {id} quit` on the sandbox so the remote screen
|
|
102
|
+
* session (when present) is also torn down.
|
|
103
|
+
*/
|
|
104
|
+
killPtySession(id: string): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Resize the terminal of an active PTY session. Requires the session
|
|
107
|
+
* to be currently attached in this SDK process; the existing wire
|
|
108
|
+
* protocol carries resize as a JSON control frame on the open
|
|
109
|
+
* WebSocket and offers no out-of-band REST equivalent.
|
|
110
|
+
*/
|
|
111
|
+
resizePtySession(id: string, cols: number, rows: number): Promise<PtySessionInfo>;
|
|
112
|
+
/** Internal: builds the WebSocket URL and opens the connection. */
|
|
113
|
+
private openPty;
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=process.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../src/process.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,cAAc,EACd,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB;;;;;;;GAOG;AACH,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,SAAS,IAAI,MAAM,CAAC;IACpB,8DAA8D;IAC9D,UAAU,IAAI,MAAM,CAAC;IACrB,wCAAwC;IACxC,UAAU,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACpD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAwB;IAE5C;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgC;gBAE5C,GAAG,EAAE,qBAAqB;IAItC;;;;;;;;;;;;;;;OAeG;IACG,SAAS,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,SAAS,CAAC;IAIxD;;;;;;;;OAQG;IACG,UAAU,CACd,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE,cAAc,GACpB,OAAO,CAAC,SAAS,CAAC;IASrB;;;;;OAKG;IACG,eAAe,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IA+BlD;;;;;;;OAOG;IACG,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAS5D;;;;;OAKG;IACG,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB/C;;;;;OAKG;IACG,gBAAgB,CACpB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,cAAc,CAAC;IAU1B,mEAAmE;YACrD,OAAO;CAmEtB"}
|
package/dist/process.js
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { PtyHandle } from "./pty.js";
|
|
2
|
+
/**
|
|
3
|
+
* `sandbox.process` — interactive shell sessions on a sandbox.
|
|
4
|
+
*
|
|
5
|
+
* Mirrors the Daytona PTY surface so existing code shaped around it
|
|
6
|
+
* ports over with mechanical changes only. Under the hood, every method
|
|
7
|
+
* either opens a WebSocket against the controlplane's
|
|
8
|
+
* `/v1/clusters/{clusterId}/machines/{sandboxId}/attach` endpoint (which
|
|
9
|
+
* is bridged to the in-sandbox SSH server at port 2222) or shells out to
|
|
10
|
+
* `screen` via the existing `runCommand` REST API for session
|
|
11
|
+
* bookkeeping.
|
|
12
|
+
*
|
|
13
|
+
* Within a single SDK process every method works against a local
|
|
14
|
+
* registry. Cross-process session persistence (i.e. `connectPty` from
|
|
15
|
+
* a fresh process to a session created elsewhere) requires the sandbox
|
|
16
|
+
* runtime image to ship `screen` and the gliderlabs SSH login shell to
|
|
17
|
+
* honor `LAI_TERM_SESSION_NAME` / `LAI_TERM_RESTORE` — both of which
|
|
18
|
+
* are tracked as a follow-up to this initial parity work.
|
|
19
|
+
*/
|
|
20
|
+
export class SandboxProcess {
|
|
21
|
+
ctx;
|
|
22
|
+
/**
|
|
23
|
+
* Live handles bound to this `SandboxProcess`, keyed by their
|
|
24
|
+
* caller-chosen session name. Used by `connectPty` /
|
|
25
|
+
* `getPtySessionInfo` / `killPtySession` / `resizePtySession` to find
|
|
26
|
+
* an existing session before falling back to `screen -ls` over
|
|
27
|
+
* `runCommand`.
|
|
28
|
+
*/
|
|
29
|
+
handles = new Map();
|
|
30
|
+
constructor(ctx) {
|
|
31
|
+
this.ctx = ctx;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Create a new PTY session on the sandbox.
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* const pty = await sandbox.process.createPty({
|
|
38
|
+
* sessionName: "build",
|
|
39
|
+
* clusterId: sandbox.clusterId,
|
|
40
|
+
* cols: 120,
|
|
41
|
+
* rows: 30,
|
|
42
|
+
* onData: (chunk) => process.stdout.write(chunk),
|
|
43
|
+
* });
|
|
44
|
+
* await pty.waitForConnection();
|
|
45
|
+
* await pty.sendInput("npm test\n");
|
|
46
|
+
* const result = await pty.wait();
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
async createPty(opts) {
|
|
50
|
+
return this.openPty({ ...opts, restore: false });
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Reattach to a PTY session that was previously created by `createPty`.
|
|
54
|
+
*
|
|
55
|
+
* ```ts
|
|
56
|
+
* const pty = await sandbox.process.connectPty("build", sandbox.clusterId, {
|
|
57
|
+
* onData: (chunk) => process.stdout.write(chunk),
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
async connectPty(sessionName, clusterId, opts) {
|
|
62
|
+
return this.openPty({
|
|
63
|
+
sessionName,
|
|
64
|
+
clusterId,
|
|
65
|
+
onData: opts?.onData,
|
|
66
|
+
restore: true,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* List PTY sessions on the sandbox. Implemented as a `screen -ls`
|
|
71
|
+
* call via {@link runCommand} so no new server endpoint is required.
|
|
72
|
+
* Returns the union of locally-tracked handles and remote `screen`
|
|
73
|
+
* sessions; locally-tracked handles include live `cols`/`rows`.
|
|
74
|
+
*/
|
|
75
|
+
async listPtySessions() {
|
|
76
|
+
let remote = [];
|
|
77
|
+
try {
|
|
78
|
+
const result = await this.ctx.runCommand({
|
|
79
|
+
cmd: "screen",
|
|
80
|
+
args: ["-ls"],
|
|
81
|
+
});
|
|
82
|
+
remote = parseScreenList(result.output);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
// `screen -ls` exits non-zero when there are no sessions; the SDK
|
|
86
|
+
// treats that as an empty list rather than an error.
|
|
87
|
+
}
|
|
88
|
+
const merged = new Map();
|
|
89
|
+
for (const info of remote)
|
|
90
|
+
merged.set(info.id, info);
|
|
91
|
+
for (const [id, handle] of this.handles) {
|
|
92
|
+
const existing = merged.get(id);
|
|
93
|
+
const size = handle.size;
|
|
94
|
+
merged.set(id, {
|
|
95
|
+
id,
|
|
96
|
+
active: handle.isConnected(),
|
|
97
|
+
cols: size.cols,
|
|
98
|
+
rows: size.rows,
|
|
99
|
+
cwd: existing?.cwd,
|
|
100
|
+
createdAt: existing?.createdAt,
|
|
101
|
+
processId: existing?.processId,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return Array.from(merged.values());
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Look up a single PTY session.
|
|
108
|
+
*
|
|
109
|
+
* ```ts
|
|
110
|
+
* const info = await sandbox.process.getPtySessionInfo("build");
|
|
111
|
+
* console.log(info.active);
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
async getPtySessionInfo(id) {
|
|
115
|
+
const sessions = await this.listPtySessions();
|
|
116
|
+
const found = sessions.find((s) => s.id === id);
|
|
117
|
+
if (!found) {
|
|
118
|
+
throw new Error(`PTY session "${id}" not found`);
|
|
119
|
+
}
|
|
120
|
+
return found;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Forcefully terminate a PTY session. Closes any live `PtyHandle` for
|
|
124
|
+
* the session within this SDK process and runs
|
|
125
|
+
* `screen -X -S {id} quit` on the sandbox so the remote screen
|
|
126
|
+
* session (when present) is also torn down.
|
|
127
|
+
*/
|
|
128
|
+
async killPtySession(id) {
|
|
129
|
+
const handle = this.handles.get(id);
|
|
130
|
+
if (handle) {
|
|
131
|
+
await handle.kill();
|
|
132
|
+
this.handles.delete(id);
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
await this.ctx.runCommand({
|
|
136
|
+
cmd: "screen",
|
|
137
|
+
args: ["-X", "-S", id, "quit"],
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
// No remote session existed, or `screen` is not in the runtime
|
|
142
|
+
// image — either way, the local handle (if any) has been killed.
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Resize the terminal of an active PTY session. Requires the session
|
|
147
|
+
* to be currently attached in this SDK process; the existing wire
|
|
148
|
+
* protocol carries resize as a JSON control frame on the open
|
|
149
|
+
* WebSocket and offers no out-of-band REST equivalent.
|
|
150
|
+
*/
|
|
151
|
+
async resizePtySession(id, cols, rows) {
|
|
152
|
+
const handle = this.handles.get(id);
|
|
153
|
+
if (!handle || !handle.isConnected()) {
|
|
154
|
+
throw new Error(`PTY session "${id}" is not attached in this process; resize requires an active connection`);
|
|
155
|
+
}
|
|
156
|
+
return handle.resize(cols, rows);
|
|
157
|
+
}
|
|
158
|
+
/** Internal: builds the WebSocket URL and opens the connection. */
|
|
159
|
+
async openPty(args) {
|
|
160
|
+
const cols = args.cols ?? 80;
|
|
161
|
+
const rows = args.rows ?? 24;
|
|
162
|
+
const url = new URL(`${this.ctx.getBaseUrl()}/v1/clusters/${encodeURIComponent(args.clusterId)}/machines/${encodeURIComponent(this.ctx.sandboxId)}/attach`);
|
|
163
|
+
// Switch http(s) -> ws(s).
|
|
164
|
+
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
165
|
+
url.searchParams.set("sessionName", args.sessionName ? args.sessionName : "main-session");
|
|
166
|
+
url.searchParams.set("cols", String(cols));
|
|
167
|
+
url.searchParams.set("rows", String(rows));
|
|
168
|
+
if (args.restore)
|
|
169
|
+
url.searchParams.set("restore", "true");
|
|
170
|
+
const headers = {
|
|
171
|
+
Authorization: `Bearer ${this.ctx.getApiKey()}`,
|
|
172
|
+
};
|
|
173
|
+
if (this.ctx.organizationId) {
|
|
174
|
+
headers["X-Lightning-Organization-Id"] = this.ctx.organizationId;
|
|
175
|
+
}
|
|
176
|
+
const wsCtor = globalThis.WebSocket;
|
|
177
|
+
if (!wsCtor) {
|
|
178
|
+
throw new Error("Native WebSocket is not available; @lightningai/sdk requires Node 22+ for PTY support");
|
|
179
|
+
}
|
|
180
|
+
// Node's native WebSocket constructor accepts a `headers` option in the
|
|
181
|
+
// second argument as of Node 22; the DOM lib types it as `protocols`,
|
|
182
|
+
// so we cast to bypass the lib mismatch without pulling in `@types/ws`.
|
|
183
|
+
const ws = new wsCtor(url.toString(), { headers });
|
|
184
|
+
const initialInput = buildInitialInput(args.cwd, args.envs);
|
|
185
|
+
const handle = new PtyHandle({
|
|
186
|
+
id: args.sessionName,
|
|
187
|
+
ws,
|
|
188
|
+
cols,
|
|
189
|
+
rows,
|
|
190
|
+
onData: args.onData,
|
|
191
|
+
initialInput,
|
|
192
|
+
});
|
|
193
|
+
// Track in the local registry; remove when the session closes so a
|
|
194
|
+
// subsequent createPty with the same sessionName doesn't see a stale entry.
|
|
195
|
+
this.handles.set(args.sessionName, handle);
|
|
196
|
+
handle.wait().finally(() => {
|
|
197
|
+
const current = this.handles.get(args.sessionName);
|
|
198
|
+
if (current === handle)
|
|
199
|
+
this.handles.delete(args.sessionName);
|
|
200
|
+
});
|
|
201
|
+
return handle;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Build the lines that should be flushed to the shell right after the
|
|
206
|
+
* WebSocket opens — `export X=Y` for each env var followed by an
|
|
207
|
+
* optional `cd $cwd && clear`. Mirrors the Daytona convention so users
|
|
208
|
+
* see a clean prompt at the requested directory.
|
|
209
|
+
*/
|
|
210
|
+
function buildInitialInput(cwd, envs) {
|
|
211
|
+
const lines = [];
|
|
212
|
+
if (envs) {
|
|
213
|
+
for (const [k, v] of Object.entries(envs)) {
|
|
214
|
+
lines.push(`export ${k}=${shellQuote(v)}\n`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (cwd) {
|
|
218
|
+
lines.push(`cd ${shellQuote(cwd)} && clear\n`);
|
|
219
|
+
}
|
|
220
|
+
return lines;
|
|
221
|
+
}
|
|
222
|
+
/** Single-quote a value for safe inclusion in a POSIX shell command. */
|
|
223
|
+
function shellQuote(value) {
|
|
224
|
+
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Parse the (text) output of `screen -ls`. The format looks like:
|
|
228
|
+
*
|
|
229
|
+
* There is a screen on:
|
|
230
|
+
* 12345.build (Detached)
|
|
231
|
+
* 1 Socket in /run/screen/S-root.
|
|
232
|
+
*
|
|
233
|
+
* We extract the part after the first `.` (the user-supplied session
|
|
234
|
+
* name) and infer `active` from the `(Attached)` / `(Detached)` tag.
|
|
235
|
+
*/
|
|
236
|
+
function parseScreenList(output) {
|
|
237
|
+
const sessions = [];
|
|
238
|
+
for (const rawLine of output.split("\n")) {
|
|
239
|
+
const line = rawLine.trim();
|
|
240
|
+
// Lines starting with a digit and a dot are session entries;
|
|
241
|
+
// everything else is header / footer noise.
|
|
242
|
+
const match = line.match(/^(\d+)\.([^\s]+)\s*\((Attached|Detached)\)/);
|
|
243
|
+
if (!match)
|
|
244
|
+
continue;
|
|
245
|
+
const [, pid, name, state] = match;
|
|
246
|
+
sessions.push({
|
|
247
|
+
id: name,
|
|
248
|
+
active: state === "Attached",
|
|
249
|
+
processId: Number(pid),
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
return sessions;
|
|
253
|
+
}
|
|
254
|
+
//# sourceMappingURL=process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.js","sourceRoot":"","sources":["../src/process.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AA+BrC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,cAAc;IACR,GAAG,CAAwB;IAE5C;;;;;;OAMG;IACc,OAAO,GAAG,IAAI,GAAG,EAAqB,CAAC;IAExD,YAAY,GAA0B;QACpC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,KAAK,CAAC,SAAS,CAAC,IAAmB;QACjC,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;IACnD,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,UAAU,CACd,WAAmB,EACnB,SAAiB,EACjB,IAAqB;QAErB,OAAO,IAAI,CAAC,OAAO,CAAC;YAClB,WAAW;YACX,SAAS;YACT,MAAM,EAAE,IAAI,EAAE,MAAM;YACpB,OAAO,EAAE,IAAI;SACd,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,eAAe;QACnB,IAAI,MAAM,GAAqB,EAAE,CAAC;QAClC,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC;gBACvC,GAAG,EAAE,QAAQ;gBACb,IAAI,EAAE,CAAC,KAAK,CAAC;aACd,CAAC,CAAC;YACH,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC1C,CAAC;QAAC,MA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