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

main
ts 53 lines 1.73 KB
Raw
1 import * as Context from "effect/Context";
2 import * as Layer from "effect/Layer";
3 import type * as Stream from "effect/Stream";
4
5 export type ConnectionWakeup =
6 | "application-active"
7 | "application-active-probe"
8 | "application-active-long"
9 | "application-focused"
10 | "credentials-changed"
11 | "network-changed";
12
13 function isApplicationActiveWakeup(reason: ConnectionWakeup): boolean {
14 return (
15 reason === "application-active" ||
16 reason === "application-active-probe" ||
17 reason === "application-active-long"
18 );
19 }
20
21 export function resetsRetryBackoff(reason: ConnectionWakeup): boolean {
22 return isApplicationActiveWakeup(reason) || reason === "network-changed";
23 }
24
25 export function shouldResubscribeAfterWakeup(reason: ConnectionWakeup): boolean {
26 return isApplicationActiveWakeup(reason);
27 }
28
29 // A brief app switch (the mobile probe) does not justify listing the whole account again.
30 export function shouldRelistAccountAfterWakeup(reason: ConnectionWakeup): boolean {
31 return (
32 reason === "application-active" ||
33 reason === "application-active-long" ||
34 reason === "application-focused"
35 );
36 }
37
38 // Focus fires on every window switch; any wakeup would arm a running probe's silent-socket check.
39 export function reachesConnectionSupervisor(reason: ConnectionWakeup): boolean {
40 return reason !== "application-focused";
41 }
42
43 export class ConnectionWakeups extends Context.Service<
44 ConnectionWakeups,
45 {
46 readonly changes: Stream.Stream<ConnectionWakeup>;
47 }
48 >()("@t3tools/client-runtime/connection/wakeups/ConnectionWakeups") {}
49
50 const make = (service: ConnectionWakeups["Service"]) => ConnectionWakeups.of(service);
51
52 export const layer = (service: ConnectionWakeups["Service"]) =>
53 Layer.succeed(ConnectionWakeups, make(service));