The best way to control Claude Code, Codex and more from any computer or phone

main
ts 61 lines 2.14 KB
Raw
1 import type { RuntimeContext } from "alchemy/RuntimeContext";
2 /** Transport-independent input and scoped, opaque push transactions. */
3 import * as Effect from "effect/Effect";
4 import type * as Fiber from "effect/Fiber";
5 import type * as Result from "effect/Result";
6 import type { ObjectType } from "./Protocol/ObjectCodec.ts";
7 import { StoreError } from "./Protocol/Store.ts";
8 import type { CommitPushResult, RefCommand, RepoMetaData } from "./RepoObject.ts";
9 import type { StreamingFeeder } from "./Store/StreamingSource.ts";
10
11 /** A proposed ref change. Zero old/new OIDs mean creation/deletion. */
12 export type RefUpdate = RefCommand;
13
14 /** Decoded commands and a streaming pack. Use the HTTP decoder or Push.fromStream to construct inputs. */
15 export interface PushInput {
16 readonly updates: ReadonlyArray<RefUpdate>;
17 readonly atomic: boolean;
18 }
19
20 /** @internal The decoder and engine share this state; applications see PushInput. */
21 export interface IncomingState {
22 readonly feeder: StreamingFeeder;
23 readonly receiving: Fiber.Fiber<Result.Result<{ readonly total: number }, StoreError>>;
24 readonly packStart: number;
25 readonly declaredBytes: number | undefined;
26 active: boolean;
27 claimed: boolean;
28 }
29
30 /** @internal */
31 export const incomingStates = new WeakMap<PushInput, IncomingState>();
32
33 /** A staged push, usable only within the scope that prepared it. */
34 export interface PreparedPush {
35 readonly repo: RepoMetaData;
36 readonly updates: ReadonlyArray<RefUpdate>;
37 /** Read an incoming or existing object, bounded to 1 MiB by default. */
38 readonly readObject: (
39 oid: string,
40 maxBytes?: number,
41 ) => Effect.Effect<
42 { readonly type: ObjectType; readonly content: Uint8Array } | undefined,
43 StoreError,
44 RuntimeContext
45 >;
46 }
47
48 /** @internal */
49 export const preparedStates = new WeakMap<
50 PreparedPush,
51 {
52 readonly owner: object;
53 readonly commit: Effect.Effect<CommitPushResult, StoreError, RuntimeContext>;
54 }
55 >();
56
57 /** A transaction/input was already consumed, escaped its scope, or belongs to another engine. */
58 export const invalidPush = () =>
59 StoreError.make({
60 reason: "push is no longer active or belongs to another engine",
61 });