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

main
ts 26 lines 760 Bytes
Raw
1 // Guarded dynamic import of `cloudflare:workers` (the same trick waku's own
2 // adapter uses) so modules also load outside a Cloudflare environment.
3 const DO_NOT_BUNDLE = "";
4
5 export interface CounterStub {
6 get(): Promise<number>;
7 increment(): Promise<number>;
8 }
9
10 export interface CounterNamespace {
11 getByName(name: string): CounterStub;
12 }
13
14 export async function readEnv(): Promise<Record<string, unknown>> {
15 try {
16 const mod = await import(/* @vite-ignore */ DO_NOT_BUNDLE + "cloudflare:workers");
17 return mod.env as Record<string, unknown>;
18 } catch {
19 return {};
20 }
21 }
22
23 export async function counterNamespace(): Promise<CounterNamespace | undefined> {
24 const env = await readEnv();
25 return env.COUNTER as CounterNamespace | undefined;
26 }