The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type { |
| 2 | CheckpointInfo as FlyCheckpoint, |
| 3 | CreateCheckpointError, |
| 4 | GetCheckpointError, |
| 5 | ListCheckpointsError, |
| 6 | RestoreCheckpointError, |
| 7 | StreamEvent, |
| 8 | } from "@distilled.cloud/fly-io/sprites"; |
| 9 | import * as Binding from "alchemy/Binding"; |
| 10 | import type { RuntimeContext } from "alchemy/RuntimeContext"; |
| 11 | import type * as Effect from "effect/Effect"; |
| 12 | import type { Sprite } from "./Sprite.ts"; |
| 13 | |
| 14 | export interface CheckpointClient { |
| 15 | /** |
| 16 | * Create a checkpoint of the Sprite filesystem. Returns NDJSON |
| 17 | * progress events. The checkpoint id is in a `complete` event. |
| 18 | */ |
| 19 | create: (options?: { |
| 20 | comment?: string; |
| 21 | }) => Effect.Effect<ReadonlyArray<StreamEvent>, CreateCheckpointError, RuntimeContext>; |
| 22 | /** List checkpoints on the Sprite. */ |
| 23 | list: () => Effect.Effect<ReadonlyArray<FlyCheckpoint>, ListCheckpointsError, RuntimeContext>; |
| 24 | /** Get one checkpoint by id (`v1`, `v2`, …). */ |
| 25 | get: (checkpointId: string) => Effect.Effect<FlyCheckpoint, GetCheckpointError, RuntimeContext>; |
| 26 | /** |
| 27 | * Restore the Sprite filesystem to a checkpoint. Destructive. |
| 28 | * Returns NDJSON progress events. |
| 29 | */ |
| 30 | restore: ( |
| 31 | checkpointId: string, |
| 32 | ) => Effect.Effect<ReadonlyArray<StreamEvent>, RestoreCheckpointError, RuntimeContext>; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Checkpoint and restore a {@link Sprite} filesystem. |
| 37 | * |
| 38 | * |
| 39 | * ### Create a checkpoint |
| 40 | * Bind the client in init. Provide {@link CheckpointHttp}. |
| 41 | * |
| 42 | * **Example:** Create |
| 43 | * ```typescript |
| 44 | * const checkpoint = yield* Fly.Checkpoint(Box); |
| 45 | * yield* checkpoint.create({ comment: "before deploy" }); |
| 46 | * ``` |
| 47 | * |
| 48 | * ### Restore |
| 49 | * Restore rewinds the filesystem. Running processes stop. |
| 50 | * |
| 51 | * **Example:** Restore v1 |
| 52 | * ```typescript |
| 53 | * yield* checkpoint.restore("v1"); |
| 54 | * ``` |
| 55 | * |
| 56 | * :::caution[Restore is destructive] |
| 57 | * The Sprite disk goes back to that checkpoint. Later writes are gone. |
| 58 | * ::: |
| 59 | * |
| 60 | * @binding |
| 61 | * @product Sprite |
| 62 | */ |
| 63 | export interface Checkpoint extends Binding.Service< |
| 64 | Checkpoint, |
| 65 | "Fly.Checkpoint", |
| 66 | (sprite: Sprite) => Effect.Effect<CheckpointClient> |
| 67 | > {} |
| 68 | |
| 69 | export const Checkpoint = Binding.Service<Checkpoint>("Fly.Checkpoint"); |