mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
Some checks failed
bot-nix-hashes / hash (blacksmith-4vcpu-ubuntu-2404, x86_64-linux) (push) Waiting to run
bot-nix-hashes / hash (blacksmith-4vcpu-ubuntu-2404-arm, aarch64-linux) (push) Waiting to run
bot-nix-hashes / hash (macos-latest, aarch64-darwin) (push) Waiting to run
bot-nix-hashes / compute (push) Blocked by required conditions
bot-nix-hashes / publish (push) Blocked by required conditions
check-nix / nix-eval (push) Waiting to run
check-test / affected packages (push) Waiting to run
check-test / unit (linux) (push) Waiting to run
check-test / unit (windows) (push) Waiting to run
check-test / build (linux) (push) Waiting to run
check-test / build (windows) (push) Waiting to run
check-test / e2e (, ) (push) Blocked by required conditions
check-test / e2e (linux) (push) Blocked by required conditions
check-test / e2e (windows) (push) Blocked by required conditions
check / typecheck (push) Waiting to run
deploy-files / deploy (push) Waiting to run
deploy-site / deploy (push) Waiting to run
deploy / deploy (push) Waiting to run
bot-docs-locale / sync-locales (push) Has been cancelled
Process daemon / Miri (callback ownership) (push) Has been cancelled
Process daemon / Core (macos-15) (push) Has been cancelled
Process daemon / Core (ubuntu-22.04) (push) Has been cancelled
Process daemon / Windows (arm64) (push) Has been cancelled
Process daemon / Windows (x64) (push) Has been cancelled
28 lines
1.1 KiB
TypeScript
28 lines
1.1 KiB
TypeScript
import { Schema } from "effect"
|
|
import type { Snapshot } from "./vm/snapshot/snapshot.js"
|
|
|
|
/**
|
|
* A suspend that failed, leaving the run running: `running` names each host call that blocked it by its key and its
|
|
* path (`tools.x.y`, `search`, or an extension function's path such as `fetch`). Empty when the state couldn't be
|
|
* saved or was too large.
|
|
*/
|
|
export class SuspendError extends Schema.TaggedError<SuspendError>()("SuspendError", {
|
|
message: Schema.String,
|
|
running: Schema.Array(Schema.Struct({ key: Schema.String, path: Schema.String })),
|
|
}) {}
|
|
|
|
export class SnapshotError extends Error {
|
|
override readonly name = "SnapshotError"
|
|
}
|
|
|
|
/** A snapshot as bytes: UTF-8 JSON. */
|
|
export const toBytes = (snapshot: Snapshot): Uint8Array => new TextEncoder().encode(JSON.stringify(snapshot))
|
|
|
|
/** Reads bytes `toBytes` wrote; `restore` checks what they hold. */
|
|
export const fromBytes = (bytes: Uint8Array): unknown => {
|
|
try {
|
|
return JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes))
|
|
} catch (error) {
|
|
throw new SnapshotError(`Invalid snapshot: the bytes are not UTF-8 JSON (${String(error)}).`)
|
|
}
|
|
}
|