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

main
ts 39 lines 1.44 KB
Raw
1 import type { EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection";
2 import type { AssetUrlState as SharedAssetUrlState } from "@t3tools/client-runtime/state/assets";
3
4 export type AssetUrlFailureReason = "disconnected" | "failed" | "missing-file-access";
5
6 export type AssetUrlState =
7 | { readonly _tag: "Loading" }
8 | { readonly _tag: "Failure"; readonly reason: AssetUrlFailureReason }
9 | Extract<SharedAssetUrlState, { readonly _tag: "Success" }>;
10
11 export function deriveAssetUrlState(input: {
12 readonly connectionPhase: EnvironmentConnectionPhase;
13 readonly shared: SharedAssetUrlState;
14 }): AssetUrlState {
15 if (
16 input.connectionPhase === "offline" ||
17 input.connectionPhase === "reconnecting" ||
18 input.connectionPhase === "error" ||
19 input.connectionPhase === "unsupported"
20 ) {
21 return { _tag: "Failure", reason: "disconnected" };
22 }
23 if (input.shared._tag === "Success") {
24 return input.shared;
25 }
26 switch (input.connectionPhase) {
27 // available means idle before dialing. A query failure there means disconnected, not missing file.
28 case "available":
29 return input.shared._tag === "Failure"
30 ? { _tag: "Failure", reason: "disconnected" }
31 : { _tag: "Loading" };
32 case "connecting":
33 return { _tag: "Loading" };
34 case "connected":
35 return input.shared._tag === "Failure"
36 ? { _tag: "Failure", reason: input.shared.reason ?? "failed" }
37 : { _tag: "Loading" };
38 }
39 }